-
Notifications
You must be signed in to change notification settings - Fork 0
/
Proofs.v
1621 lines (1529 loc) · 56.5 KB
/
Proofs.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(** Encoding of proofs by natural numbers.
The proofs are formalized in the style of Hilbert, as a list of formulas
that imply one another.
The axioms are represented by a characteristic function IsAxiom : nat -> bool,
which incites to consider computable sets of axioms. We believe those are
the only reasonable sets of axioms, so that mathematical proofs can be
mechanically checked. If one wants non-computable sets of axioms, one therefore
has to pose extra meta-axioms in Coq. For example, Henkin's proof of Gödel's
completeness theorem considers saturated sets of axioms, and it is known that
Henkin's proof requires Markov's principle.
Function IsProof will only assume constructive logic, because the excluded
middle axiom schema can be added via IsAxiom, as is done in the file
PeanoAxioms.v, to pass from Heyting arithmetic to Peano arithmetic. *)
Require Import ConstructiveEpsilon.
Require Import PeanoNat.
Require Import Arith.Wf_nat.
Require Import Arith.Compare_dec.
Require Import EnumSeqNat.
Require Import Formulas.
Require Import Substitutions.
Require Import IsFreeForSubst.
(* This rule is maybe redundant, because there are also the 4 quantifier rules
Lforall/Lexists intro/elim. *)
Definition IsIndependenceOfPremise (prop : nat) : bool :=
IsLproposition prop
&& IsLimplies prop
&& IsLforall (CoordNat prop 1)
&& IsLimplies (CoordNat (CoordNat prop 1) 2)
&& IsLimplies (CoordNat prop 2)
&& IsLforall (CoordNat (CoordNat prop 2) 2)
&& Nat.eqb (CoordNat (CoordNat (CoordNat prop 1) 2) 1)
(CoordNat (CoordNat prop 2) 1)
&& Nat.eqb (CoordNat (CoordNat (CoordNat prop 1) 2) 2)
(CoordNat (CoordNat (CoordNat prop 2) 2) 2)
&& Nat.eqb (CoordNat (CoordNat prop 1) 1)
(CoordNat (CoordNat (CoordNat prop 2) 2) 1)
&& negb (VarOccursFreeInFormula (CoordNat (CoordNat prop 1) 1)
(CoordNat (CoordNat prop 2) 1)).
(* This is the Lforall introduction rule. It is weaker than taking
Limplies prop (Lforall n prop)
as axioms, because it only applies to previously proved props
(as usual for inference rules). The Limplies above is not satisfied
in the standard model of arithmetic. *)
Definition IsGeneralization (prop proof : nat) : bool :=
IsLforall prop
&& FindNat proof (CoordNat prop 2) (LengthNat proof).
(* Search proof for an implication ending in prop, and then search proof again
for the hypothesis of that implication. Tail recursive. *)
Fixpoint IsModusPonensLoop (prop proof last : nat) : bool :=
match last with
| 0 => false
| S k => (IsLimplies (CoordNat proof k)
&& Nat.eqb prop (CoordNat (CoordNat proof k) 2)
&& FindNat proof (CoordNat (CoordNat proof k) 1) (LengthNat proof))
|| IsModusPonensLoop prop proof k
end.
Definition IsModusPonens (prop proof : nat) : bool :=
IsModusPonensLoop prop proof (LengthNat proof).
Lemma IsModusPonens_true : forall prop proof last,
prod (IsModusPonensLoop prop proof last = true
-> { n : nat | n < last
/\ IsLimplies (CoordNat proof n) = true
/\ prop = CoordNat (CoordNat proof n) 2
/\ FindNat proof (CoordNat (CoordNat proof n) 1) (LengthNat proof)
= true })
({ n : nat | n < last
/\ IsLimplies (CoordNat proof n) = true
/\ prop = CoordNat (CoordNat proof n) 2
/\ FindNat proof (CoordNat (CoordNat proof n) 1) (LengthNat proof)
= true }
-> IsModusPonensLoop prop proof last = true).
Proof.
split.
- induction last.
intros H. discriminate.
intros H. simpl in H.
destruct (IsModusPonensLoop prop proof last).
+ specialize (IHlast eq_refl) as [n [H0 H1]].
exists n. split. apply le_S, H0. exact H1.
+ clear IHlast. rewrite Bool.orb_false_r in H.
exists last. split. apply Nat.le_refl.
apply andb_prop in H. destruct H.
apply andb_prop in H. destruct H.
split. exact H. split.
apply Nat.eqb_eq in H1. exact H1. exact H0.
- induction last.
intros [n [H _]]. inversion H.
intros [n [H H0]]. simpl.
apply Nat.le_succ_r in H. destruct H.
+ rewrite IHlast. rewrite Bool.orb_true_r. reflexivity.
exists n. split. exact H. exact H0.
+ clear IHlast. inversion H. subst n.
apply Bool.orb_true_intro. left.
apply andb_true_intro. split.
apply andb_true_intro. split.
apply H0. apply Nat.eqb_eq, H0. apply H0.
Qed.
Lemma DoubleParamDecr : forall fg i j,
0 < LengthNat (diagY fg)
-> diagMerge (CoordNat (diagX fg) i) (CoordNat (diagY fg) j) < fg.
Proof.
intros.
rewrite <- (diagSplitMergeId fg) at 3.
apply diagMergeIncrLt. apply CoordLe.
apply CoordLower. apply LengthPositive, H.
Qed.
(* Precondition: there exists a term t such as g = Subst t v f.
Compute that term t. *)
Fixpoint FindSubstTermTermLoop (v tu i : nat)
(rec : forall y : nat, y < tu -> nat) : nat :=
match i with
| 0 => 0
| 1 => 0
| 2 => 0
| S k => let t := diagX tu in
let u := diagY tu in
match le_lt_dec (LengthNat u) 0 with
| left _ => 0
| right l =>
if VarOccursInTerm v (CoordNat t k)
then rec (diagMerge (CoordNat t k) (CoordNat u k))
(DoubleParamDecr tu _ _ l)
else FindSubstTermTermLoop v tu k rec
end
end.
Definition FindSubstTermTermRec (v tu : nat) (rec : forall y : nat, y < tu -> nat) : nat :=
let t := diagX tu in
let u := diagY tu in
match CoordNat t 0 with
| LvarHead => if Nat.eqb (CoordNat t 1) v then u else 0
| LopHead => if (Nat.eqb (CoordNat u 0) LopHead
&& Nat.eqb (CoordNat t 1) (CoordNat u 1)
&& Nat.eqb (LengthNat t) (LengthNat u))%bool then
FindSubstTermTermLoop v tu (LengthNat t) rec
else 0
| _ => 0
end.
Definition FindSubstTermTerm (v t u : nat) : nat
:= Fix lt_wf (fun _ => nat) (FindSubstTermTermRec v) (diagMerge t u).
Lemma FindSubstTermTerm_step : forall v t u,
FindSubstTermTerm v t u
= FindSubstTermTermRec v (diagMerge t u)
(fun (y : nat) (_ : y < diagMerge t u) =>
Fix lt_wf (fun _ => nat) (FindSubstTermTermRec v) y).
Proof.
intros.
unfold FindSubstTermTerm.
rewrite Fix_eq. reflexivity.
intros. unfold FindSubstTermTermRec.
replace (FindSubstTermTermLoop v x (LengthNat (diagX x)) f)
with (FindSubstTermTermLoop v x (LengthNat (diagX x)) g).
reflexivity.
generalize (LengthNat (diagX x)) as n.
induction n. reflexivity.
simpl. destruct n. reflexivity.
destruct n. reflexivity.
destruct (le_lt_dec (LengthNat (diagY x)) 0). reflexivity.
destruct (VarOccursInTerm v (CoordNat (diagX x) (S (S n)))).
rewrite H. reflexivity. rewrite IHn. reflexivity.
Qed.
Lemma FindSubstTermTerm_var : forall v k u,
FindSubstTermTerm v (Lvar k) u = if Nat.eqb k v then u else 0.
Proof.
intros.
rewrite FindSubstTermTerm_step.
unfold FindSubstTermTermRec; rewrite diagXMergeId, diagYMergeId.
unfold Lvar at 1. rewrite CoordConsHeadNat.
unfold Lvar.
rewrite CoordConsTailNat, CoordConsHeadNat. reflexivity.
Qed.
Lemma FindSubstTermTerm_zero : forall v t, FindSubstTermTerm v t 0 = 0.
Proof.
intros v t.
rewrite FindSubstTermTerm_step.
unfold FindSubstTermTermRec.
rewrite diagXMergeId, diagYMergeId.
destruct (CoordNat t 0). reflexivity.
destruct n. reflexivity.
destruct n. reflexivity.
destruct n. reflexivity.
destruct n. reflexivity.
destruct n. reflexivity.
destruct n. reflexivity.
destruct n. reflexivity.
destruct n. reflexivity.
destruct n. 2: reflexivity.
destruct (CoordNat t 1 =? v); reflexivity.
Qed.
Lemma FindSubstTermTermLoop_true : forall i j v t u,
j < pred (pred i)
-> VarOccursInTerm v (CoordNat t (S (S j))) = true
-> { k:nat | k < pred (pred i)
/\ VarOccursInTerm v (CoordNat t (S (S k))) = true
/\ FindSubstTermTermLoop
v (diagMerge t u) i
(fun (y : nat) (_ : y < diagMerge t u) =>
Fix lt_wf (fun _ => nat) (FindSubstTermTermRec v) y)
= FindSubstTermTerm v (CoordNat t (S (S k))) (CoordNat u (S (S k))) }.
Proof.
induction i.
- intros. exfalso. inversion H.
- intros. simpl.
destruct i. exfalso. inversion H.
destruct i. exfalso. inversion H.
destruct (VarOccursInTerm v (CoordNat t (S (S i)))) eqn:des.
+ exists i. split.
apply Nat.le_refl.
split. exact des.
rewrite diagXMergeId, diagYMergeId.
rewrite des.
destruct (le_lt_dec (LengthNat u) 0).
2: reflexivity.
rewrite (CoordNatAboveLength _ u).
symmetry. apply FindSubstTermTerm_zero.
inversion l. rewrite H2. apply le_0_n.
+ simpl in H.
destruct (IHi j v t u) as [x [a b]]. simpl.
apply Nat.le_succ_r in H.
destruct H. exact H. exfalso. inversion H.
rewrite H2 in H0.
rewrite H0 in des. discriminate des. exact H0.
exists x. split. apply le_S, a.
split. apply b.
rewrite diagXMergeId, diagYMergeId.
destruct (le_lt_dec (LengthNat u) 0).
rewrite (CoordNatAboveLength _ u).
symmetry. apply FindSubstTermTerm_zero.
inversion l. rewrite H2. apply le_0_n.
destruct (VarOccursInTerm v (CoordNat t (S (S i)))).
discriminate des. apply b.
Qed.
Lemma FindSubstTermTerm_op : forall v o args u,
FindSubstTermTerm v (Lop o args) u
= if (Nat.eqb (CoordNat u 0) LopHead
&& Nat.eqb o (CoordNat u 1)
&& Nat.eqb (2 + LengthNat args) (LengthNat u))%bool then
FindSubstTermTermLoop v (diagMerge (Lop o args) u)
(2 + LengthNat args)
(fun (y : nat) (_ : y < diagMerge _ u) =>
Fix lt_wf (fun _ => nat) (FindSubstTermTermRec v) y)
else 0.
Proof.
intros. rewrite FindSubstTermTerm_step.
unfold FindSubstTermTermRec; rewrite diagXMergeId, diagYMergeId.
unfold Lop at 1; rewrite CoordConsHeadNat.
unfold Lop at 1; rewrite CoordConsTailNat, CoordConsHeadNat.
rewrite LengthLop. reflexivity.
Qed.
(*
Lemma FindSubstTermTerm_varoccur : forall v t u,
match FindSubstTermTerm v t u with
| 0 => True
| S _ => VarOccursInTerm v t = true
end.
Proof.
intro v.
apply (Fix lt_wf (fun t => forall u : nat,
match FindSubstTermTerm v t u with
| 0 => True
| S _ => VarOccursInTerm v t = true
end)).
intros t IHt u.
rewrite FindSubstTermTerm_step. unfold FindSubstTermTermRec.
rewrite diagXMergeId, diagYMergeId.
destruct (CoordNat t 0) eqn:headT. trivial.
destruct n. trivial.
destruct n. trivial.
destruct n. trivial.
destruct n. trivial.
destruct n. trivial.
destruct n. trivial.
destruct n. trivial.
destruct n.
rewrite headT.
shelve.
destruct n. 2: trivial.
destruct (CoordNat t 1 =? v) eqn:des. 2: trivial.
destruct u. trivial.
unfold VarOccursInTerm.
rewrite SubstTerm_step.
unfold TreeFoldNatRec.
destruct (le_lt_dec (LengthNat t) 0).
exfalso. rewrite CoordNatAboveLength in headT.
discriminate headT. exact l.
unfold SubstTermRec. rewrite headT.
rewrite des. simpl.
destruct t.
exfalso. discriminate headT.
reflexivity.
Qed.
*)
Fixpoint FindSubstTermLoop (v f g l : nat) : nat :=
match l with
| 0 => 0
| S k => if VarOccursInTerm v (CoordNat f k)
then FindSubstTermTerm v (CoordNat f k) (CoordNat g k)
else FindSubstTermLoop v f g k
end.
Definition FindSubstTermRec (v fg : nat) (rec : forall y : nat, y < fg -> nat) : nat :=
let f := diagX fg in
let g := diagY fg in
match le_lt_dec (LengthNat g) 0 with
| left _ => 0
| right l =>
if Nat.eqb (CoordNat f 0) (CoordNat g 0) then
match CoordNat f 0 with
| LnotHead => rec (diagMerge (CoordNat f 1) (CoordNat g 1))
(DoubleParamDecr fg 1 1 l)
| LimpliesHead
| LorHead
| LandHead => if VarOccursFreeInFormula v (CoordNat f 1)
then rec (diagMerge (CoordNat f 1) (CoordNat g 1))
(DoubleParamDecr fg 1 1 l)
else rec (diagMerge (CoordNat f 2) (CoordNat g 2))
(DoubleParamDecr fg _ _ l)
| LforallHead
| LexistsHead => if (Nat.eqb (CoordNat f 1) (CoordNat g 1)
&& negb (Nat.eqb (CoordNat f 1) v))%bool then
(* If Xv is quantified, there will be no substitutions for it *)
rec (diagMerge (CoordNat f 2) (CoordNat g 2))
(DoubleParamDecr fg _ _ l)
else 0
| LrelHead => if (Nat.eqb (CoordNat f 1) (CoordNat g 1)
&& Nat.eqb (LengthNat f) (LengthNat g))%bool then
FindSubstTermLoop v (TailNat (TailNat f))
(TailNat (TailNat g)) (LengthNat f - 2)
else 0
| _ => 0
end
else 0
end.
Definition FindSubstTerm (v f g : nat) : nat
:= Fix lt_wf (fun _ => nat) (FindSubstTermRec v) (diagMerge f g).
Lemma FindSubstTerm_step : forall v f g,
FindSubstTerm v f g
= FindSubstTermRec v (diagMerge f g)
(fun (y : nat) (_ : y < diagMerge f g) =>
Fix lt_wf (fun _ => nat) (FindSubstTermRec v) y).
Proof.
intros.
unfold FindSubstTerm.
rewrite Fix_eq. reflexivity.
intros. unfold FindSubstTermRec.
destruct (le_lt_dec (LengthNat (diagY x)) 0). reflexivity.
unfold FindSubstTermRec.
simpl. rewrite H, H. reflexivity.
Qed.
Lemma FindSubstTermLoop_true : forall (l j v f g : nat),
j < l
-> VarOccursInTerm v (CoordNat f j) = true
-> { k:nat | k < l
/\ VarOccursInTerm v (CoordNat f k) = true
/\ (FindSubstTermLoop v f g l
= FindSubstTermTerm v (CoordNat f k) (CoordNat g k)) }.
Proof.
induction l.
- intros. exfalso. inversion H.
- intros. simpl.
destruct (VarOccursInTerm v (CoordNat f l)) eqn:des.
+ exists l. split. apply Nat.le_refl.
split. exact des. reflexivity.
+ assert (j < l).
{ apply Nat.le_succ_r in H. destruct H. exact H. exfalso.
inversion H.
rewrite H2 in H0. rewrite H0 in des. discriminate des. }
destruct (IHl _ v f g H1 H0) as [k IHk].
exists k. split. apply le_S, IHk.
split. apply IHk. apply IHk.
Qed.
Lemma FindSubstTermTerm_true : forall t v u,
IsLterm u = true
-> VarOccursInTerm v u = true
-> FindSubstTermTerm v u (SubstTerm t v u) = t.
Proof.
intros t v.
apply (Lterm_rect (fun u =>
VarOccursInTerm v u = true
-> FindSubstTermTerm v u (SubstTerm t v u) = t)).
- (* Lvar *)
intros. rewrite SubstTerm_var.
rewrite VarOccursInTerm_var in H.
rewrite Nat.eqb_sym, H.
rewrite FindSubstTermTerm_var, Nat.eqb_sym, H. reflexivity.
- (* Lop *)
intros.
apply VarOccursInTerm_opHead in H.
destruct H as [j occur].
rewrite SubstTerm_op.
rewrite FindSubstTermTerm_op.
rewrite LengthLop, LengthMapNat, Nat.eqb_refl, Bool.andb_true_r.
unfold Lop at 1.
rewrite CoordConsHeadNat, Nat.eqb_refl, Bool.andb_true_l.
unfold Lop at 1.
rewrite CoordConsTailNat, CoordConsHeadNat.
rewrite Nat.eqb_refl.
destruct (FindSubstTermTermLoop_true
(LengthNat (Lop o terms)) j v (Lop o terms)
(Lop o (MapNat (SubstTerm t v) terms)))
as [k [H0 [H1 H2]]].
apply occur. apply occur.
rewrite LengthLop in H2.
replace (MapNat (fun i : nat => SubstTerm t v (CoordNat (Lop o terms) i))
(RangeNat 2 (LengthNat terms)))
with (MapNat (SubstTerm t v) terms).
rewrite H2. clear H2.
rewrite LengthLop in H0.
rewrite CoordNat_op, CoordNat_op, CoordMapNat.
apply IHterms.
exact H0.
rewrite CoordNat_op in H1. exact H1. exact H0.
apply TruncatedEqNat.
rewrite LengthMapNat, LengthMapNat, LengthRangeNat. reflexivity.
rewrite LengthMapNat, LengthMapNat.
rewrite MapNatTruncated, MapNatTruncated. reflexivity.
intros k0 H. rewrite LengthMapNat in H.
rewrite CoordMapNat, CoordMapNat, CoordRangeNat, (CoordNat_op _ _ k0).
reflexivity. exact H. rewrite LengthRangeNat. exact H. exact H.
unfold Lop. rewrite CoordConsHeadNat. reflexivity.
change 2 with (2+0). rewrite LengthLop.
apply Nat.add_le_mono_l, le_0_n.
rewrite LengthLop. simpl. unfold Lop.
rewrite TailConsNat, TailConsNat. exact termsTrunc.
Qed.
Lemma FindSubstTerm_not : forall v f g,
FindSubstTerm v (Lnot f) (Lnot g) = FindSubstTerm v f g.
Proof.
intros.
rewrite FindSubstTerm_step.
unfold FindSubstTermRec at 1; rewrite diagXMergeId, diagYMergeId.
destruct (le_lt_dec (LengthNat (Lnot g)) 0).
exfalso. rewrite LengthLnot in l. inversion l.
unfold Lnot at 1 2 3.
rewrite CoordConsHeadNat, CoordConsHeadNat. simpl.
unfold Lnot.
rewrite CoordConsTailNat, CoordConsHeadNat.
rewrite CoordConsTailNat, CoordConsHeadNat. reflexivity.
Qed.
Lemma FindSubstTerm_implies : forall v f g h k,
FindSubstTerm v (Limplies f g) (Limplies h k)
= (if VarOccursFreeInFormula v f
then FindSubstTerm v f h else FindSubstTerm v g k).
Proof.
intros.
rewrite FindSubstTerm_step.
unfold FindSubstTermRec at 1; rewrite diagXMergeId, diagYMergeId.
destruct (le_lt_dec (LengthNat (Limplies h k)) 0).
exfalso. rewrite LengthLimplies in l. inversion l.
unfold Limplies at 1 2 3.
rewrite CoordConsHeadNat, CoordConsHeadNat. simpl.
unfold Limplies.
rewrite CoordConsTailNat, CoordConsHeadNat.
rewrite CoordConsTailNat, CoordConsHeadNat.
rewrite CoordConsTailNat, CoordConsTailNat, CoordConsHeadNat.
rewrite CoordConsTailNat, CoordConsTailNat, CoordConsHeadNat.
reflexivity.
Qed.
Lemma FindSubstTerm_or : forall v f g h k,
FindSubstTerm v (Lor f g) (Lor h k)
= (if VarOccursFreeInFormula v f
then FindSubstTerm v f h else FindSubstTerm v g k).
Proof.
intros.
rewrite FindSubstTerm_step.
unfold FindSubstTermRec at 1; rewrite diagXMergeId, diagYMergeId.
destruct (le_lt_dec (LengthNat (Lor h k)) 0).
exfalso. rewrite LengthLor in l. inversion l.
unfold Lor at 1 2 3.
rewrite CoordConsHeadNat, CoordConsHeadNat. simpl.
unfold Lor.
rewrite CoordConsTailNat, CoordConsHeadNat.
rewrite CoordConsTailNat, CoordConsHeadNat.
rewrite CoordConsTailNat, CoordConsTailNat, CoordConsHeadNat.
rewrite CoordConsTailNat, CoordConsTailNat, CoordConsHeadNat.
reflexivity.
Qed.
Lemma FindSubstTerm_and : forall v f g h k,
FindSubstTerm v (Land f g) (Land h k)
= (if VarOccursFreeInFormula v f
then FindSubstTerm v f h else FindSubstTerm v g k).
Proof.
intros.
rewrite FindSubstTerm_step.
unfold FindSubstTermRec at 1; rewrite diagXMergeId, diagYMergeId.
destruct (le_lt_dec (LengthNat (Land h k)) 0).
exfalso. rewrite LengthLand in l. inversion l.
unfold Land at 1 2 3.
rewrite CoordConsHeadNat, CoordConsHeadNat. simpl.
unfold Land.
rewrite CoordConsTailNat, CoordConsHeadNat.
rewrite CoordConsTailNat, CoordConsHeadNat.
rewrite CoordConsTailNat, CoordConsTailNat, CoordConsHeadNat.
rewrite CoordConsTailNat, CoordConsTailNat, CoordConsHeadNat.
reflexivity.
Qed.
Lemma FindSubstTerm_forall : forall v w f g,
FindSubstTerm v (Lforall w f) (Lforall w g)
= (if w =? v then 0 else FindSubstTerm v f g).
Proof.
intros.
rewrite FindSubstTerm_step.
unfold FindSubstTermRec at 1; rewrite diagXMergeId, diagYMergeId.
destruct (le_lt_dec (LengthNat (Lforall w g)) 0).
exfalso. rewrite LengthLforall in l. inversion l.
unfold Lforall at 1 2 3.
rewrite CoordConsHeadNat, CoordConsHeadNat. simpl.
unfold Lforall.
rewrite CoordConsTailNat, CoordConsHeadNat.
rewrite CoordConsTailNat, CoordConsHeadNat.
rewrite CoordConsTailNat, CoordConsTailNat, CoordConsHeadNat.
rewrite CoordConsTailNat, CoordConsTailNat, CoordConsHeadNat.
rewrite Nat.eqb_refl. simpl.
destruct (w =? v); reflexivity.
Qed.
Lemma FindSubstTerm_exists : forall v w f g,
FindSubstTerm v (Lexists w f) (Lexists w g)
= (if w =? v then 0 else FindSubstTerm v f g).
Proof.
intros.
rewrite FindSubstTerm_step.
unfold FindSubstTermRec at 1; rewrite diagXMergeId, diagYMergeId.
destruct (le_lt_dec (LengthNat (Lexists w g)) 0).
exfalso. rewrite LengthLexists in l. inversion l.
unfold Lexists at 1 2 3.
rewrite CoordConsHeadNat, CoordConsHeadNat. simpl.
unfold Lexists.
rewrite CoordConsTailNat, CoordConsHeadNat.
rewrite CoordConsTailNat, CoordConsHeadNat.
rewrite CoordConsTailNat, CoordConsTailNat, CoordConsHeadNat.
rewrite CoordConsTailNat, CoordConsTailNat, CoordConsHeadNat.
rewrite Nat.eqb_refl. simpl.
destruct (w =? v); reflexivity.
Qed.
Lemma FindSubstTerm_rel : forall v r terms r2 terms2,
FindSubstTerm v (Lrel r terms) (Lrel r2 terms2)
= (if ((r =? r2) && (LengthNat terms =? LengthNat terms2))%bool
then FindSubstTermLoop v terms terms2 (LengthNat terms)
else 0).
Proof.
intros.
rewrite FindSubstTerm_step.
unfold FindSubstTermRec at 1; rewrite diagXMergeId, diagYMergeId.
destruct (le_lt_dec (LengthNat (Lrel r2 terms2)) 0).
exfalso. rewrite LengthLrel in l. inversion l.
unfold Lrel at 1 2 3.
rewrite CoordConsHeadNat, CoordConsHeadNat. simpl.
unfold Lrel.
rewrite CoordConsTailNat, CoordConsHeadNat.
rewrite CoordConsTailNat, CoordConsHeadNat.
rewrite TailConsNat, TailConsNat.
rewrite TailConsNat, TailConsNat.
rewrite LengthConsNat, LengthConsNat.
rewrite LengthConsNat, LengthConsNat.
simpl.
rewrite Nat.sub_0_r. reflexivity.
Qed.
Lemma FindSubstTerm_true : forall prop,
IsLproposition prop = true
-> forall t v, VarOccursFreeInFormula v prop = true
-> FindSubstTerm v prop (Subst t v prop) = t.
Proof.
apply (Lproposition_rect (fun prop => forall t v,
VarOccursFreeInFormula v prop = true
-> FindSubstTerm v prop (Subst t v prop) = t)).
- (* Lrel *)
intros.
rewrite Subst_rel, FindSubstTerm_rel, Nat.eqb_refl.
rewrite LengthMapNat, Nat.eqb_refl. simpl.
apply VarOccursFreeInFormula_rel in H.
destruct H as [j [H H0]].
pose proof (FindSubstTermLoop_true
(LengthNat terms) j v terms
(MapNat (SubstTerm t v) terms)
H H0) as [k H3].
destruct H3, H2.
rewrite H3, CoordMapNat. 2: exact H1.
apply FindSubstTermTerm_true. apply elemterms, H1. exact H2.
exact termsTrunc.
- (* Lnot *)
intros.
rewrite VarOccursFreeInFormula_not in H.
rewrite Subst_not, FindSubstTerm_not. apply IHprop, H.
- (* Limplies *)
intros.
rewrite Subst_implies, FindSubstTerm_implies.
rewrite VarOccursFreeInFormula_implies in H.
destruct (VarOccursFreeInFormula v g) eqn:des.
apply IHg. exact des.
apply IHh. exact H.
- (* Lor *)
intros.
rewrite Subst_or, FindSubstTerm_or.
rewrite VarOccursFreeInFormula_or in H.
destruct (VarOccursFreeInFormula v g) eqn:des.
apply IHg. exact des.
apply IHh. exact H.
- (* Land *)
intros.
rewrite Subst_and, FindSubstTerm_and.
rewrite VarOccursFreeInFormula_and in H.
destruct (VarOccursFreeInFormula v g) eqn:des.
apply IHg. exact des.
apply IHh. exact H.
- (* Lforall *)
intros.
rewrite VarOccursFreeInFormula_forall in H.
apply andb_prop in H. destruct H.
rewrite Subst_forall, FindSubstTerm_forall.
rewrite Nat.eqb_sym. destruct (v0 =? v). discriminate H.
apply IHprop, H0.
- (* Lexists *)
intros.
rewrite VarOccursFreeInFormula_exists in H.
apply andb_prop in H. destruct H.
rewrite Subst_exists, FindSubstTerm_exists.
rewrite Nat.eqb_sym. destruct (v0 =? v). discriminate H.
apply IHprop, H0.
Qed.
(* In the specialization rule, we choose to forbid the capture of variables,
so that the theorem (forall x, exists y, not(x = y)) does not specialize
into the absurdity (exists y, not(y = y)).
This gathers the Lforall elimination and Lexists introduction rules. *)
Definition IsSpecialization (prop : nat) : bool :=
IsLproposition prop (* This prevents the substitution of t := FindSubstTerm = 0
for a free variable. When there is no substitution,
it is simply the erasure of the forall quantifier,
which is the same as substituting the variable for itself. *)
&& IsLimplies prop
&& ((IsLforall (CoordNat prop 1)
&& let t := FindSubstTerm (CoordNat (CoordNat prop 1) 1)
(CoordNat (CoordNat prop 1) 2)
(CoordNat prop 2) in
IsFreeForSubst t (CoordNat (CoordNat prop 1) 1)
(CoordNat (CoordNat prop 1) 2)
&& Nat.eqb (CoordNat prop 2)
(Subst t (CoordNat (CoordNat prop 1) 1)
(CoordNat (CoordNat prop 1) 2)))
|| (IsLexists (CoordNat prop 2)
&& let t := FindSubstTerm (CoordNat (CoordNat prop 2) 1)
(CoordNat (CoordNat prop 2) 2)
(CoordNat prop 1) in
IsFreeForSubst t (CoordNat (CoordNat prop 2) 1)
(CoordNat (CoordNat prop 2) 2)
&& Nat.eqb (CoordNat prop 1)
(Subst t (CoordNat (CoordNat prop 2) 1)
(CoordNat (CoordNat prop 2) 2)))).
(* Propositional axiom schema of weakening
X1 -> (X2 -> X1) *)
Definition IsPropAx1 (f : nat) : bool :=
IsLproposition f
&& IsLimplies f
&& IsLimplies (CoordNat f 2)
&& Nat.eqb (CoordNat f 1) (CoordNat (CoordNat f 2) 2).
(* Propositional axiom schema of modus ponens with a hypothesis X1
(X1 -> (X2 -> X3)) -> ((X1 -> X2) -> (X1 -> X3)). *)
Definition IsPropAx2 (f : nat) : bool :=
IsLproposition f
&& IsLimplies f
&& IsLimplies (CoordNat f 1)
&& IsLimplies (CoordNat (CoordNat f 1) 2)
&& IsLimplies (CoordNat f 2)
&& IsLimplies (CoordNat (CoordNat f 2) 1)
&& IsLimplies (CoordNat (CoordNat f 2) 2)
&& Nat.eqb (CoordNat (CoordNat f 1) 1)
(CoordNat (CoordNat (CoordNat f 2) 1) 1)
&& Nat.eqb (CoordNat (CoordNat f 1) 1)
(CoordNat (CoordNat (CoordNat f 2) 2) 1)
&& Nat.eqb (CoordNat (CoordNat (CoordNat f 1) 2) 1)
(CoordNat (CoordNat (CoordNat f 2) 1) 2)
&& Nat.eqb (CoordNat (CoordNat (CoordNat f 1) 2) 2)
(CoordNat (CoordNat (CoordNat f 2) 2) 2).
(* Propositional axiom schema LnotIntro
(X1 -> X2) -> ((X1 -> ~X2) -> ~X1) *)
Definition IsPropAx3 (f : nat) : bool :=
IsLproposition f
&& IsLimplies f
&& IsLimplies (CoordNat f 1)
&& IsLimplies (CoordNat f 2)
&& IsLimplies (CoordNat (CoordNat f 2) 1)
&& IsLnot (CoordNat (CoordNat f 2) 2)
&& IsLnot (CoordNat (CoordNat (CoordNat f 2) 1) 2)
&& Nat.eqb (CoordNat (CoordNat f 1) 1) (* X1 *)
(CoordNat (CoordNat (CoordNat f 2) 1) 1)
&& Nat.eqb (CoordNat (CoordNat f 1) 1) (* X1 *)
(CoordNat (CoordNat (CoordNat f 2) 2) 1)
&& Nat.eqb (CoordNat (CoordNat f 1) 2) (* X2 *)
(CoordNat (CoordNat (CoordNat (CoordNat f 2) 1) 2) 1).
(* IsPropAx4 is the classical logic axiom : ~~X -> X.
We postpone it to remain constructive here. *)
(* Propositional axiom schema ex falso quodlibet, or LnotElim
X1 -> (~X1 -> X2) *)
Definition IsPropAx5 (f : nat) : bool :=
IsLproposition f
&& IsLimplies f
&& IsLimplies (CoordNat f 2)
&& IsLnot (CoordNat (CoordNat f 2) 1)
&& Nat.eqb (CoordNat f 1)
(CoordNat (CoordNat (CoordNat f 2) 1) 1).
(* Propositional axiom schema LandIntro
X1 -> (X2 -> (X1 /\ X2)) *)
Definition IsPropAx6 (f : nat) : bool :=
IsLproposition f
&& IsLimplies f
&& IsLimplies (CoordNat f 2)
&& IsLand (CoordNat (CoordNat f 2) 2)
&& Nat.eqb (CoordNat f 1)
(CoordNat (CoordNat (CoordNat f 2) 2) 1)
&& Nat.eqb (CoordNat (CoordNat f 2) 1)
(CoordNat (CoordNat (CoordNat f 2) 2) 2).
(* Propositional axiom schema LandElim1
(X1 /\ X2) -> X1 *)
Definition IsPropAx7 (f : nat) : bool :=
IsLproposition f
&& IsLimplies f
&& IsLand (CoordNat f 1)
&& Nat.eqb (CoordNat (CoordNat f 1) 1) (CoordNat f 2).
(* Propositional axiom schema LandElim2
(X1 /\ X2) -> X2 *)
Definition IsPropAx8 (f : nat) : bool :=
IsLproposition f
&& IsLimplies f
&& IsLand (CoordNat f 1)
&& Nat.eqb (CoordNat (CoordNat f 1) 2) (CoordNat f 2).
(* Propositional axiom schema LorIntro1
X1 -> (X1 \/ X2) *)
Definition IsPropAx9 (f : nat) : bool :=
IsLproposition f
&& IsLimplies f
&& IsLor (CoordNat f 2)
&& Nat.eqb (CoordNat f 1) (CoordNat (CoordNat f 2) 1).
(* Propositional axiom schema LorIntro2
X2 -> (X1 \/ X2) *)
Definition IsPropAx10 (f : nat) : bool :=
IsLproposition f
&& IsLimplies f
&& IsLor (CoordNat f 2)
&& Nat.eqb (CoordNat f 1) (CoordNat (CoordNat f 2) 2).
(* Propositional axiom schema LorElim
(X1 -> X3) -> ((X2 -> X3) -> ((X1 \/ X2) -> X3)) *)
Definition IsPropAx11 (f : nat) : bool :=
IsLproposition f
&& IsLimplies f
&& IsLimplies (CoordNat f 1)
&& IsLimplies (CoordNat f 2)
&& IsLimplies (CoordNat (CoordNat f 2) 1)
&& IsLimplies (CoordNat (CoordNat f 2) 2)
&& IsLor (CoordNat (CoordNat (CoordNat f 2) 2) 1)
&& Nat.eqb (CoordNat (CoordNat f 1) 1) (* X1 *)
(CoordNat (CoordNat (CoordNat (CoordNat f 2) 2) 1) 1)
&& Nat.eqb (CoordNat (CoordNat (CoordNat f 2) 1) 1) (* X2 *)
(CoordNat (CoordNat (CoordNat (CoordNat f 2) 2) 1) 2)
&& Nat.eqb (CoordNat (CoordNat f 1) 2) (* X3 *)
(CoordNat (CoordNat (CoordNat f 2) 1) 2)
&& Nat.eqb (CoordNat (CoordNat f 1) 2) (* X3 *)
(CoordNat (CoordNat (CoordNat f 2) 2) 2).
Definition IsPropositionalAxiom (f : nat) : bool :=
IsPropAx1 f
|| IsPropAx2 f
|| IsPropAx3 f
|| IsPropAx5 f
|| IsPropAx6 f
|| IsPropAx7 f
|| IsPropAx8 f
|| IsPropAx9 f
|| IsPropAx10 f
|| IsPropAx11 f.
Lemma Ax1IsPropAx : forall f, IsPropAx1 f = true -> IsPropositionalAxiom f = true.
Proof.
intros. unfold IsPropositionalAxiom.
do 9 (apply Bool.orb_true_intro; left).
exact H.
Qed.
Lemma Ax1IsAx1 : forall f g,
IsLproposition f = true
-> IsLproposition g = true
-> IsPropAx1 (Limplies f (Limplies g f)) = true.
Proof.
intros.
apply andb_true_intro. split.
apply andb_true_intro. split.
apply andb_true_intro. split.
rewrite IsLproposition_implies.
apply andb_true_intro. split. exact H.
rewrite IsLproposition_implies.
apply andb_true_intro. split. exact H0. exact H.
apply LimpliesIsImplies.
rewrite CoordNat_implies_2.
apply LimpliesIsImplies.
rewrite CoordNat_implies_1.
rewrite CoordNat_implies_2, CoordNat_implies_2.
apply Nat.eqb_refl.
Qed.
Lemma Ax2IsPropAx : forall f, IsPropAx2 f = true -> IsPropositionalAxiom f = true.
Proof.
intros. unfold IsPropositionalAxiom.
do 8 (apply Bool.orb_true_intro; left).
apply Bool.orb_true_intro; right.
exact H.
Qed.
Lemma Ax2IsAx2 : forall f g h,
IsLproposition f = true
-> IsLproposition g = true
-> IsLproposition h = true
-> IsPropAx2 (Limplies (Limplies f (Limplies g h))
(Limplies (Limplies f g) (Limplies f h))) = true.
Proof.
intros.
apply andb_true_intro. split.
apply andb_true_intro. split.
apply andb_true_intro. split.
apply andb_true_intro. split.
apply andb_true_intro. split.
apply andb_true_intro. split.
apply andb_true_intro. split.
apply andb_true_intro. split.
apply andb_true_intro. split.
apply andb_true_intro. split.
rewrite IsLproposition_implies.
apply andb_true_intro. split.
rewrite IsLproposition_implies.
apply andb_true_intro. split. exact H.
rewrite IsLproposition_implies.
apply andb_true_intro. split. exact H0. exact H1.
rewrite IsLproposition_implies.
apply andb_true_intro. split.
rewrite IsLproposition_implies.
apply andb_true_intro. split. exact H. exact H0.
rewrite IsLproposition_implies.
apply andb_true_intro. split. exact H. exact H1.
apply LimpliesIsImplies.
rewrite CoordNat_implies_1.
apply LimpliesIsImplies.
rewrite CoordNat_implies_1, CoordNat_implies_2.
apply LimpliesIsImplies.
rewrite CoordNat_implies_2.
apply LimpliesIsImplies.
rewrite CoordNat_implies_2, CoordNat_implies_1.
apply LimpliesIsImplies.
rewrite CoordNat_implies_2, CoordNat_implies_2.
apply LimpliesIsImplies.
rewrite CoordNat_implies_1, CoordNat_implies_1.
rewrite CoordNat_implies_2, CoordNat_implies_1, CoordNat_implies_1.
apply Nat.eqb_refl.
rewrite CoordNat_implies_1, CoordNat_implies_1.
rewrite CoordNat_implies_2, CoordNat_implies_2, CoordNat_implies_1.
apply Nat.eqb_refl.
rewrite CoordNat_implies_1, CoordNat_implies_2.
rewrite CoordNat_implies_1, CoordNat_implies_2, CoordNat_implies_1.
rewrite CoordNat_implies_2.
apply Nat.eqb_refl.
rewrite CoordNat_implies_1, CoordNat_implies_2.
rewrite CoordNat_implies_2, CoordNat_implies_2.
rewrite CoordNat_implies_2, CoordNat_implies_2.
apply Nat.eqb_refl.
Qed.
Lemma Ax3IsPropAx : forall f, IsPropAx3 f = true -> IsPropositionalAxiom f = true.
Proof.
intros. unfold IsPropositionalAxiom.
do 7 (apply Bool.orb_true_intro; left).
apply Bool.orb_true_intro; right.
exact H.
Qed.
Lemma Ax3IsAx3 : forall f g,
IsLproposition f = true
-> IsLproposition g = true
-> IsPropAx3 (Limplies (Limplies f g)
(Limplies (Limplies f (Lnot g)) (Lnot f))) = true.
Proof.
intros.
unfold IsPropAx3; rewrite CoordNat_implies_2, CoordNat_implies_1.
rewrite CoordNat_implies_2, CoordNat_implies_1.
rewrite CoordNat_implies_2, CoordNat_implies_1.
rewrite CoordNat_implies_2, CoordNat_implies_1.
rewrite CoordNat_not_1, CoordNat_not_1.
rewrite Nat.eqb_refl, Nat.eqb_refl.
do 4 rewrite LimpliesIsImplies.
rewrite LnotIsNot, LnotIsNot.
do 4 rewrite IsLproposition_implies.
rewrite IsLproposition_not, IsLproposition_not, H, H0.
reflexivity.
Qed.
Lemma Ax5IsPropAx : forall f, IsPropAx5 f = true -> IsPropositionalAxiom f = true.
Proof.
intros. unfold IsPropositionalAxiom.
do 6 (apply Bool.orb_true_intro; left).
apply Bool.orb_true_intro. right.
exact H.
Qed.
Lemma Ax5IsAx5 : forall f g : nat,
IsLproposition f = true
-> IsLproposition g = true
-> IsPropAx5 (Limplies f (Limplies (Lnot f) g)) = true.
Proof.
intros. unfold IsPropAx5.
rewrite CoordNat_implies_1, CoordNat_implies_2, CoordNat_implies_1.
rewrite CoordNat_not_1.
rewrite LimpliesIsImplies, LimpliesIsImplies, LnotIsNot, Nat.eqb_refl.
rewrite IsLproposition_implies, IsLproposition_implies, IsLproposition_not.
rewrite H, H0. reflexivity.
Qed.
Lemma Ax6IsPropAx : forall f, IsPropAx6 f = true -> IsPropositionalAxiom f = true.
Proof.
intros. unfold IsPropositionalAxiom.
do 5 (apply Bool.orb_true_intro; left).
apply Bool.orb_true_intro. right.
exact H.
Qed.
Lemma Ax6IsAx6 : forall f g : nat,
IsLproposition f = true
-> IsLproposition g = true
-> IsPropAx6 (Limplies f (Limplies g (Land f g))) = true.
Proof.
intros.
apply andb_true_intro. split.
apply andb_true_intro. split.
apply andb_true_intro. split.
apply andb_true_intro. split.
apply andb_true_intro. split.
rewrite IsLproposition_implies.
apply andb_true_intro. split. exact H.
rewrite IsLproposition_implies.
apply andb_true_intro. split. exact H0.
rewrite IsLproposition_and.
apply andb_true_intro. split. exact H. exact H0.
apply LimpliesIsImplies.
rewrite CoordNat_implies_2. apply LimpliesIsImplies.
rewrite CoordNat_implies_2, CoordNat_implies_2. apply LandIsAnd.
rewrite CoordNat_implies_1, CoordNat_implies_2.
rewrite CoordNat_implies_2, CoordNat_and_1.
apply Nat.eqb_refl.
rewrite CoordNat_implies_2, CoordNat_implies_2.
rewrite CoordNat_implies_1, CoordNat_and_2.
apply Nat.eqb_refl.
Qed.
Lemma Ax7IsPropAx : forall f, IsPropAx7 f = true -> IsPropositionalAxiom f = true.
Proof.
intros. unfold IsPropositionalAxiom.
do 4 (apply Bool.orb_true_intro; left).
apply Bool.orb_true_intro. right.
exact H.
Qed.
Lemma Ax7IsAx7 : forall f g : nat,
IsLproposition f = true
-> IsLproposition g = true
-> IsPropAx7 (Limplies (Land f g) f) = true.