1
(************************************************************************)
2
(* v * The Coq Proof Assistant / The Coq Development Team *)
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
4
(* \VV/ **************************************************************)
5
(* // * This file is distributed under the terms of the *)
6
(* * GNU Lesser General Public License Version 2.1 *)
7
(************************************************************************)
9
(* $Id: Rtauto.v 7639 2005-12-02 10:01:15Z gregoire $ *)
13
Require Export Bintree.
15
Unset Boxed Definitions.
17
Ltac caseq t := generalize (refl_equal t); pattern t at -1; case t.
18
Ltac clean:=try (simpl;congruence).
21
Atom : positive -> form
22
| Arrow : form -> form -> form
24
| Conjunct : form -> form -> form
25
| Disjunct : form -> form -> form.
27
Notation "[ n ]":=(Atom n).
28
Notation "A =>> B":= (Arrow A B) (at level 59, right associativity).
30
Notation "A //\\ B" := (Conjunct A B) (at level 57, left associativity).
31
Notation "A \\// B" := (Disjunct A B) (at level 58, left associativity).
33
Definition ctx := Store form.
35
Fixpoint pos_eq (m n:positive) {struct m} :bool :=
37
xI mm => match n with xI nn => pos_eq mm nn | _ => false end
38
| xO mm => match n with xO nn => pos_eq mm nn | _ => false end
39
| xH => match n with xH => true | _ => false end
42
Theorem pos_eq_refl : forall m n, pos_eq m n = true -> m = n.
43
induction m;simpl;destruct n;congruence ||
44
(intro e;apply f_equal with positive;auto).
47
Fixpoint form_eq (p q:form) {struct p} :bool :=
49
Atom m => match q with Atom n => pos_eq m n | _ => false end
52
Arrow q1 q2 => form_eq p1 q1 && form_eq p2 q2
54
| Bot => match q with Bot => true | _ => false end
57
Conjunct q1 q2 => form_eq p1 q1 && form_eq p2 q2
62
Disjunct q1 q2 => form_eq p1 q1 && form_eq p2 q2
67
Theorem form_eq_refl: forall p q, form_eq p q = true -> p = q.
68
induction p;destruct q;simpl;clean.
69
intro h;generalize (pos_eq_refl _ _ h);congruence.
70
caseq (form_eq p1 q1);clean.
71
intros e1 e2;generalize (IHp1 _ e1) (IHp2 _ e2);congruence.
72
caseq (form_eq p1 q1);clean.
73
intros e1 e2;generalize (IHp1 _ e1) (IHp2 _ e2);congruence.
74
caseq (form_eq p1 q1);clean.
75
intros e1 e2;generalize (IHp1 _ e1) (IHp2 _ e2);congruence.
78
Implicit Arguments form_eq_refl [p q].
82
Variable env:Store Prop.
84
Fixpoint interp_form (f:form): Prop :=
86
[n]=> match get n env with PNone => True | PSome P => P end
87
| A =>> B => (interp_form A) -> (interp_form B)
89
| A //\\ B => (interp_form A) /\ (interp_form B)
90
| A \\// B => (interp_form A) \/ (interp_form B)
93
Notation "[[ A ]]" := (interp_form A).
95
Fixpoint interp_ctx (hyps:ctx) (F:Full hyps) (G:Prop) {struct F} : Prop :=
98
| F_push H hyps0 F0 => interp_ctx hyps0 F0 ([[H]] -> G)
101
Require Export BinPos.
103
Ltac wipe := intros;simpl;constructor.
106
forall hyps F (A:Prop),
108
(interp_ctx hyps F A).
109
induction F;intros A H;simpl;auto.
113
forall hyps F (A B:Prop),
115
(interp_ctx hyps F A) ->
116
(interp_ctx hyps F B).
117
induction F;intros A B H;simpl;auto.
122
forall hyps F (A B C:Prop),
124
(interp_ctx hyps F A) ->
125
(interp_ctx hyps F B) ->
126
(interp_ctx hyps F C).
127
induction F;intros A B C H;simpl;auto.
132
forall hyps F (A B C D:Prop),
133
(A -> B -> C -> D) ->
134
(interp_ctx hyps F A) ->
135
(interp_ctx hyps F B) ->
136
(interp_ctx hyps F C) ->
137
(interp_ctx hyps F D).
138
induction F;intros A B C D H;simpl;auto.
142
Lemma weaken : forall hyps F f G,
143
(interp_ctx hyps F G) ->
144
(interp_ctx (hyps\f) (F_push f hyps F) G).
145
induction F;simpl;intros;auto.
146
apply compose1 with ([[a]]-> G);auto.
149
Theorem project_In : forall hyps F g,
151
interp_ctx hyps F [[g]].
154
intros g H;destruct H.
155
subst;apply compose0;simpl;trivial.
156
apply compose1 with [[g]];auto.
159
Theorem project : forall hyps F p g,
160
get p hyps = PSome g->
161
interp_ctx hyps F [[g]].
162
intros hyps F p g e; apply project_In.
163
apply get_In with p;assumption.
166
Implicit Arguments project [hyps p g].
168
Inductive proof:Set :=
169
Ax : positive -> proof
170
| I_Arrow : proof -> proof
171
| E_Arrow : positive -> positive -> proof -> proof
172
| D_Arrow : positive -> proof -> proof -> proof
173
| E_False : positive -> proof
174
| I_And: proof -> proof -> proof
175
| E_And: positive -> proof -> proof
176
| D_And: positive -> proof -> proof
177
| I_Or_l: proof -> proof
178
| I_Or_r: proof -> proof
179
| E_Or: positive -> proof -> proof -> proof
180
| D_Or: positive -> proof -> proof
181
| Cut: form -> proof -> proof -> proof.
183
Notation "hyps \ A" := (push A hyps) (at level 72,left associativity).
185
Fixpoint check_proof (hyps:ctx) (gl:form) (P:proof) {struct P}: bool :=
188
match get i hyps with
189
PSome F => form_eq F gl
194
A =>> B => check_proof (hyps \ A) B p
198
match get i hyps,get j hyps with
199
PSome A,PSome (B =>>C) =>
200
form_eq A B && check_proof (hyps \ C) (gl) p
204
match get i hyps with
205
PSome ((A =>>B)=>>C) =>
206
(check_proof ( hyps \ B =>> C \ A) B p1) && (check_proof (hyps \ C) gl p2)
210
match get i hyps with
217
check_proof hyps A p1 && check_proof hyps B p2
221
match get i hyps with
222
PSome (A //\\ B) => check_proof (hyps \ A \ B) gl p
226
match get i hyps with
227
PSome (A //\\ B =>> C) => check_proof (hyps \ A=>>B=>>C) gl p
232
(A \\// B) => check_proof hyps A p
237
(A \\// B) => check_proof hyps B p
241
match get i hyps with
243
check_proof (hyps \ A) gl p1 && check_proof (hyps \ B) gl p2
247
match get i hyps with
248
PSome (A \\// B =>> C) =>
249
(check_proof (hyps \ A=>>C \ B=>>C) gl p)
253
check_proof hyps A p1 && check_proof (hyps \ A) gl p2
256
Theorem interp_proof:
258
check_proof hyps gl p = true -> interp_ctx hyps F [[gl]].
260
induction p;intros hyps F gl.
264
simpl;caseq (get p hyps);clean.
265
intros f nth_f e;rewrite <- (form_eq_refl e).
266
apply project with p;trivial.
268
(* Cas Arrow_Intro *)
272
change (interp_ctx (hyps\gl1) (F_push gl1 hyps F) [[gl2]]).
273
apply IHp;try constructor;trivial.
277
simpl check_proof;caseq (get p hyps);clean.
278
intros f ef;caseq (get p0 hyps);clean.
279
intros f0 ef0;destruct f0;clean.
280
caseq (form_eq f f0_1);clean.
281
simpl;intros e check_p1.
282
generalize (project F ef) (project F ef0)
283
(IHp (hyps \ f0_2) (F_push f0_2 hyps F) gl check_p1);
284
clear check_p1 IHp p p0 p1 ef ef0.
287
rewrite (form_eq_refl e).
290
(* cas Arrow_Destruct *)
292
simpl;caseq (get p1 hyps);clean.
293
intros f ef;destruct f;clean.
295
caseq (check_proof (hyps \ f1_2 =>> f2 \ f1_1) f1_2 p2);clean.
296
intros check_p1 check_p2.
297
generalize (project F ef)
298
(IHp1 (hyps \ f1_2 =>> f2 \ f1_1)
299
(F_push f1_1 (hyps \ f1_2 =>> f2)
300
(F_push (f1_2 =>> f2) hyps F)) f1_2 check_p1)
301
(IHp2 (hyps \ f2) (F_push f2 hyps F) gl check_p2).
302
simpl;apply compose3;auto.
306
simpl;caseq (get p hyps);clean.
307
intros f ef;destruct f;clean.
308
intros _; generalize (project F ef).
309
apply compose1;apply False_ind.
313
simpl;destruct gl;clean.
314
caseq (check_proof hyps gl1 p1);clean.
315
intros Hp1 Hp2;generalize (IHp1 hyps F gl1 Hp1) (IHp2 hyps F gl2 Hp2).
316
apply compose2 ;simpl;auto.
320
simpl;caseq (get p hyps);clean.
321
intros f ef;destruct f;clean.
322
intro check_p;generalize (project F ef)
323
(IHp (hyps \ f1 \ f2) (F_push f2 (hyps \ f1) (F_push f1 hyps F)) gl check_p).
324
simpl;apply compose2;intros [h1 h2];auto.
326
(* cas And_Destruct *)
328
simpl;caseq (get p hyps);clean.
329
intros f ef;destruct f;clean.
331
intro H;generalize (project F ef)
332
(IHp (hyps \ f1_1 =>> f1_2 =>> f2)
333
(F_push (f1_1 =>> f1_2 =>> f2) hyps F) gl H);clear H;simpl.
336
(* cas Or_Intro_left *)
339
intro Hp;generalize (IHp hyps F gl1 Hp).
340
apply compose1;simpl;auto.
342
(* cas Or_Intro_right *)
345
intro Hp;generalize (IHp hyps F gl2 Hp).
346
apply compose1;simpl;auto.
350
simpl;caseq (get p1 hyps);clean.
351
intros f ef;destruct f;clean.
352
caseq (check_proof (hyps \ f1) gl p2);clean.
353
intros check_p1 check_p2;generalize (project F ef)
354
(IHp1 (hyps \ f1) (F_push f1 hyps F) gl check_p1)
355
(IHp2 (hyps \ f2) (F_push f2 hyps F) gl check_p2);
356
simpl;apply compose3;simpl;intro h;destruct h;auto.
358
(* cas Or_Destruct *)
360
simpl;caseq (get p hyps);clean.
361
intros f ef;destruct f;clean.
363
intro check_p0;generalize (project F ef)
364
(IHp (hyps \ f1_1 =>> f2 \ f1_2 =>> f2)
365
(F_push (f1_2 =>> f2) (hyps \ f1_1 =>> f2)
366
(F_push (f1_1 =>> f2) hyps F)) gl check_p0);simpl.
371
simpl;caseq (check_proof hyps f p1);clean.
372
intros check_p1 check_p2;
373
generalize (IHp1 hyps F f check_p1)
374
(IHp2 (hyps\f) (F_push f hyps F) gl check_p2);
375
simpl; apply compose2;auto.
378
Theorem Reflect: forall gl prf, if check_proof empty gl prf then [[gl]] else True.
379
intros gl prf;caseq (check_proof empty gl prf);intro check_prf.
380
change (interp_ctx empty F_empty [[gl]]) ;
381
apply interp_proof with prf;assumption.
388
(* A small example *)
389
Parameters A B C D:Prop.
390
Theorem toto:A /\ (B \/ C) -> (A /\ B) \/ (A /\ C).
391
exact (Reflect (empty \ A \ B \ C)
392
([1] //\\ ([2] \\// [3]) =>> [1] //\\ [2] \\// [1] //\\ [3])
393
(I_Arrow (E_And 1 (E_Or 3
394
(I_Or_l (I_And (Ax 2) (Ax 4)))
395
(I_Or_r (I_And (Ax 2) (Ax 4))))))).