-
Notifications
You must be signed in to change notification settings - Fork 0
/
BetaRepr.v
2826 lines (2785 loc) · 125 KB
/
BetaRepr.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
(** We prove that Gödel's beta function is represented by an arithmetic formula.
This is a work in progress, complete proofs can be found in this library
https://github.com/coq-community/hydra-battles *)
Require Import Numbers.NaryFunctions.
Require Import ZArith.
Require Import ZArith.Znumtheory.
Require Import Arith.Compare_dec.
Require Import PeanoNat.
Require Import EnumSeqNat.
Require Import Formulas.
Require Import IsFreeForSubst.
Require Import Proofs.
Require Import ProofTactics.
Require Import HeytingModel.
Require Import PeanoAxioms.
Require Import Substitutions.
Require Import HeytingRepresentation.
Require Import ChineseRemainder.
Lemma NatDivDef : forall (i j k : nat),
IsProved IsWeakHeytingAxiom
(Limplies
(Land (PAle (PAmult (PAnat k) (PAnat j)) (PAnat i))
(PAle (PAsucc (PAnat i))
(PAmult (PAsucc (PAnat k)) (PAnat j))))
(Leq (PAnat k) (PAnat (i / j)))).
Proof.
intros i j k.
apply PushHypothesis.
destruct (le_lt_dec (k*j) i).
- apply DropHypothesis.
unfold PAle, PAmult.
rewrite IsLproposition_rel2, IsLterm_op2, IsLterm_PAnat, IsLterm_PAnat.
apply IsLterm_PAnat.
destruct (le_lt_dec (S i) (S k * j)).
+ apply DropHypothesis.
unfold PAle, PAmult, PAsucc.
rewrite IsLproposition_rel2, IsLterm_op2, IsLterm_PAnat, IsLterm_op1.
rewrite IsLterm_op1, IsLterm_PAnat, IsLterm_PAnat. reflexivity.
replace (i / j)%nat with k. apply LeqRefl, IsLterm_PAnat.
apply Nat.le_antisymm.
apply (Nat.div_le_mono (k*j) i j) in l.
rewrite Nat.div_mul in l. exact l.
intro abs. rewrite abs, Nat.mul_0_r in l0. inversion l0.
intro abs. rewrite abs, Nat.mul_0_r in l0. inversion l0.
rewrite Nat.mul_comm in l0.
apply (Nat.div_lt_upper_bound i j (S k)) in l0.
apply le_S_n, l0.
intro abs. rewrite abs, Nat.mul_0_l in l0. inversion l0.
+ pose proof (PAlt_not_le _ _ l0).
apply (LimpliesTrans _ _ (PAle (PAsucc (PAnat i)) (PAnat (S k * j)))).
pose proof (LeqElim_rel2 IsWeakHeytingAxiom 1
(PAsucc (PAnat i)) (PAsucc (PAnat i))
(PAmult (PAsucc (PAnat k)) (PAnat j))
(PAnat (S k * j))).
apply LandElim1 in H0. exact H0.
apply LeqRefl. unfold PAsucc. rewrite IsLterm_op1. apply IsLterm_PAnat.
exact (PAmult_normalize (S k) j).
apply FalseElim_impl. exact H.
rewrite IsLproposition_eq, IsLterm_PAnat, IsLterm_PAnat. reflexivity.
- pose proof (PAlt_not_le _ _ l).
apply (LimpliesTrans _ _ (PAle (PAnat (k * j)) (PAnat i))).
pose proof (LeqElim_rel2 IsWeakHeytingAxiom 1
(PAmult (PAnat k) (PAnat j))
(PAnat (k * j))
(PAnat i) (PAnat i)).
apply LandElim1 in H0. exact H0.
exact (PAmult_normalize k j).
apply LeqRefl. apply IsLterm_PAnat.
apply FalseElim_impl. exact H.
unfold PAle, PAsucc, PAmult.
reduce_islproposition.
do 4 rewrite IsLterm_PAnat. reflexivity.
Qed.
Lemma NatDivCorrect : forall (i j : nat),
IsProved IsWeakHeytingAxiom
(Lor (Land (Leq (PAnat (i / j)) PAzero) (Leq (PAnat j) PAzero))
(Land (PAle (PAmult (PAnat (i / j)) (PAnat j)) (PAnat i))
(PAle (PAsucc (PAnat i))
(PAmult (PAsucc (PAnat (i / j))) (PAnat j))))).
Proof.
intros. destruct j.
- apply LorIntro1. 2: apply LandIntro; apply LeqRefl, IsLterm_const.
unfold PAle.
rewrite IsLproposition_and, IsLproposition_rel2, IsLproposition_rel2.
simpl. unfold PAmult, PAsucc, PAzero.
rewrite IsLterm_PAnat, IsLterm_op2, IsLterm_op2, IsLterm_op1, IsLterm_op1.
rewrite IsLterm_PAnat, IsLterm_const. reflexivity.
- apply LorIntro2.
rewrite IsLproposition_and, IsLproposition_eq, IsLproposition_eq.
unfold PAzero.
rewrite IsLterm_PAnat, IsLterm_PAnat, IsLterm_const. reflexivity.
apply LandIntro.
+ pose proof (LeqElim_rel2 IsWeakHeytingAxiom 1 _ _ _ _
(PAmult_normalize (i/S j) (S j))
(LeqRefl _ (PAnat i) (IsLterm_PAnat _))) as H.
apply LandElim2 in H.
apply (LimpliesElim _ _ _ H). clear H.
apply PAle_normalize.
rewrite Nat.mul_comm. apply (Nat.mul_div_le). discriminate.
+ pose proof (LeqElim_rel2 IsWeakHeytingAxiom 1
_ _
(PAmult (PAnat (S (i / S j))) (PAnat (S j)))
(PAnat ((S (i / S j)) * (S j)))
(LeqRefl _ _ (IsLterm_PAnat (S i)))).
apply LandElim2 in H.
2: apply PAmult_normalize.
apply (LimpliesElim _ _ _ H). clear H.
apply PAle_normalize.
rewrite Nat.mul_comm.
apply (Nat.mul_succ_div_gt i (S j)). discriminate.
Qed.
Lemma DivisionRepresented : FunctionRepresented 2 Nat.div.
Proof.
assert (forall i j,
IsLterm i = true ->
IsLterm j = true ->
IsLproposition
(Land (PAle (Lvar 2) i)
(Lor (Land (Leq (Lvar 2) PAzero) (Leq j PAzero))
(Land (PAle (PAmult (Lvar 2) j) i)
(PAle (PAsucc i) (PAmult (PAsucc (Lvar 2)) j)))))
= true) as hypprop.
{ intros. unfold PAle, PAmult, PAsucc.
rewrite IsLproposition_and, IsLproposition_or, IsLproposition_and.
rewrite IsLproposition_eq, IsLproposition_eq, IsLproposition_and.
rewrite IsLproposition_rel2, IsLproposition_rel2, IsLproposition_rel2.
rewrite IsLterm_op2, IsLterm_op2, IsLterm_op1, IsLterm_op1, H, H0.
unfold PAzero. rewrite IsLterm_var, IsLterm_const. reflexivity. }
(* X2 = X0 / X1 *)
apply (Build_FunctionRepresented 2
_ (Land (PAle (Lvar 2) (Lvar 0))
(Lor (Land (Leq (Lvar 2) PAzero) (Leq (Lvar 1) PAzero))
(Land (PAle (PAmult (Lvar 2) (Lvar 1)) (Lvar 0))
(PAle (PAsucc (Lvar 0))
(PAmult (PAsucc (Lvar 2)) (Lvar 1))))))).
- intro args. simpl. rewrite CoordTailNat.
remember (CoordNat args 0) as i.
remember (CoordNat args 1) as j.
apply LforallIntro.
reduce_subst; simpl.
rewrite SubstTerm_PAzero. do 6 rewrite Subst_PAle.
reduce_subst; simpl.
reduce_subst; simpl.
rewrite SubstTerm_PAnat. do 4 rewrite SubstTerm_PAmult.
do 4 rewrite SubstTerm_PAsucc.
reduce_subst; simpl. rewrite SubstTerm_PAnat.
reduce_subst; simpl.
apply LandIntro.
+ apply PushHypothesis, LforallBounded.
rewrite IsLproposition_implies.
specialize (hypprop (PAnat i) (PAnat j) (IsLterm_PAnat _) (IsLterm_PAnat _)).
rewrite IsLproposition_and in hypprop.
apply andb_prop in hypprop. destruct hypprop.
rewrite H0.
rewrite IsLproposition_eq, IsLterm_var, IsLterm_PAnat. reflexivity.
intros k H.
reduce_subst; simpl.
rewrite Subst_PAle, Subst_PAle, SubstTerm_PAzero, SubstTerm_PAnat.
rewrite SubstTerm_PAmult, SubstTerm_PAsucc, SubstTerm_PAmult.
do 3 rewrite SubstTerm_PAnat. rewrite SubstTerm_PAsucc.
reduce_subst; simpl.
apply LorElim. destruct j.
apply LandElim1_impl.
rewrite IsLproposition_eq, IsLterm_PAnat. apply IsLterm_PAnat.
unfold PAzero. rewrite IsLproposition_eq, IsLterm_PAnat, IsLterm_const.
reflexivity.
apply (LimpliesTrans _ _ (Leq (PAnat (S j)) PAzero)).
apply LandElim2_impl.
rewrite IsLproposition_eq, IsLterm_PAnat. apply IsLterm_const.
rewrite IsLproposition_eq, IsLterm_PAnat. apply IsLterm_const.
apply FalseElim_impl.
pose proof IsProvedAx1 as H0.
apply (LforallElim _ _ _ (PAnat j)) in H0.
rewrite Subst_not, Subst_eq, SubstTerm_PAsucc, SubstTerm_var in H0.
rewrite SubstTerm_PAzero in H0. exact H0.
apply IsLterm_PAnat.
apply IsFreeForSubst_PAnat.
rewrite IsLproposition_not, IsLproposition_eq.
unfold PAsucc, PAzero. rewrite IsLterm_op1, IsLterm_var, IsLterm_const.
reflexivity.
rewrite IsLproposition_eq, IsLterm_PAnat, IsLterm_PAnat. reflexivity.
apply NatDivDef.
+ apply LeqElimSubstVarPAnat.
apply hypprop.
apply IsLterm_PAnat. apply IsLterm_PAnat.
unfold PAle, PAmult, PAsucc.
reduce_subst; simpl.
rewrite SubstTerm_PAnat.
rewrite SubstTerm_PAnat.
apply LandIntro. apply PAle_normalize.
destruct j. apply Nat.le_0_l.
apply Nat.div_le_upper_bound. discriminate.
rewrite <- (Nat.mul_1_l i) at 1.
apply Nat.mul_le_mono_nonneg_r. apply Nat.le_0_l. apply le_n_S, Nat.le_0_l.
rewrite SubstTerm_PAzero.
exact (NatDivCorrect i j).
- apply hypprop. apply IsLterm_var. apply IsLterm_var.
- intros. unfold PAle, PAzero, PAmult, PAsucc, Leq.
rewrite VarOccursFreeInFormula_and, VarOccursFreeInFormula_rel2.
rewrite VarOccursInTerm_var, VarOccursInTerm_var.
rewrite VarOccursFreeInFormula_or, VarOccursFreeInFormula_and.
rewrite VarOccursFreeInFormula_rel2, VarOccursFreeInFormula_rel2.
rewrite VarOccursFreeInFormula_and, VarOccursFreeInFormula_rel2.
rewrite VarOccursFreeInFormula_rel2, VarOccursInTerm_op1.
rewrite VarOccursInTerm_op2, VarOccursInTerm_op2, VarOccursInTerm_op1.
rewrite VarOccursInTerm_var, VarOccursInTerm_var, VarOccursInTerm_const.
rewrite VarOccursInTerm_var.
destruct v. inversion H. simpl. apply le_S_n in H.
destruct v. inversion H. simpl. apply le_S_n in H.
destruct v. inversion H. reflexivity.
Qed.
Lemma NatSubDef : forall (i j k : nat),
(k <= i)%nat
-> IsProved IsWeakHeytingAxiom
(Limplies
(Lor (Land (Leq (PAnat k) PAzero) (PAle (PAnat i) (PAnat j)))
(Leq (PAplus (PAnat k) (PAnat j)) (PAnat i)))
(Leq (PAnat k) (PAnat (i - j)))).
Proof.
intros i j k klei.
apply LorElim.
- apply PushHypothesis.
assert (IsLproposition (Limplies (PAle (PAnat i) (PAnat j))
(Leq (Lvar 0) (PAnat (i - j)))) = true)
as hypprop.
{ unfold PAle.
rewrite IsLproposition_implies, IsLproposition_rel2, IsLproposition_eq.
rewrite IsLterm_PAnat, IsLterm_PAnat, IsLterm_var, IsLterm_PAnat.
reflexivity. }
pose proof (LeqElim IsWeakHeytingAxiom
(Limplies (PAle (PAnat i) (PAnat j))
(Leq (Lvar 0) (PAnat (i - j))))
PAzero (PAnat k) 0) as H.
rewrite Subst_implies, Subst_implies, Subst_PAle, Subst_PAle in H.
rewrite SubstTerm_PAnat, SubstTerm_PAnat, SubstTerm_PAnat, SubstTerm_PAnat in H.
rewrite Subst_eq, SubstTerm_var, SubstTerm_PAnat in H; simpl in H.
rewrite Subst_eq, SubstTerm_var, SubstTerm_PAnat in H; simpl in H.
apply (LimpliesTrans _ _ (Leq PAzero (PAnat k))).
apply LeqSym_impl. apply IsLterm_PAnat. apply IsLterm_const.
apply (RemoveRedundantHypothesis
_ _
(Limplies (PAle (PAnat i) (PAnat j)) (Leq PAzero (PAnat (i - j))))
(Limplies (PAle (PAnat i) (PAnat j)) (Leq (PAnat k) (PAnat (i - j)))))
in H.
apply H. exact hypprop.
apply IsLterm_const. apply IsLterm_PAnat.
apply (IsFreeForSubst_PAnat 0). exact hypprop.
apply IsFreeForSubst_PAnat. exact hypprop.
apply DropHypothesis.
unfold PAzero. rewrite IsLproposition_eq, IsLterm_const, IsLterm_PAnat.
reflexivity.
destruct (le_lt_dec i j).
apply Nat.sub_0_le in l. rewrite l.
apply DropHypothesis, LeqRefl, IsLterm_const.
unfold PAle. rewrite IsLproposition_rel2, IsLterm_PAnat, IsLterm_PAnat.
reflexivity.
apply FalseElim_impl.
exact (PAlt_not_le _ _ l).
unfold PAzero. rewrite IsLproposition_eq, IsLterm_const, IsLterm_PAnat.
reflexivity.
- (* i = k + j *)
pose proof (Nat.add_sub_eq_l i j k).
apply (LimpliesTrans _ _ (Leq (PAnat (k+j)) (PAnat i))).
pose proof (LeqElim_rel2 IsWeakHeytingAxiom 0
(PAplus (PAnat k) (PAnat j)) (PAnat (k + j))
(PAnat i) (PAnat i)).
apply LandElim1 in H0. exact H0.
apply PAplus_normalize. apply LeqRefl. apply IsLterm_PAnat.
destruct (Nat.eq_dec (k+j) i).
subst i.
apply DropHypothesis.
rewrite IsLproposition_eq, IsLterm_PAnat. reflexivity.
rewrite H. apply LeqRefl. apply IsLterm_PAnat.
rewrite Nat.add_comm. reflexivity.
apply FalseElim_impl.
destruct (Nat.lt_trichotomy i (k+j)).
exact (PAlt_not_eq _ _ H0). destruct H0.
rewrite H0 in n. exfalso. apply n. reflexivity.
pose proof (PAlt_not_eq _ _ H0).
apply NotByContradiction.
apply (LimpliesTrans _ _ (Leq (PAnat i) (PAnat (k + j)))).
apply LeqSym_impl. apply IsLterm_PAnat. apply IsLterm_PAnat.
apply FalseElim_impl. exact H1.
rewrite IsLproposition_not, IsLproposition_eq, IsLterm_PAnat, IsLterm_PAnat.
reflexivity.
rewrite IsLproposition_eq, IsLterm_PAnat, IsLterm_PAnat. reflexivity.
Qed.
Lemma NatSubCorrect : forall (i j : nat),
IsProved IsWeakHeytingAxiom
(Lor (Land (Leq (PAnat (i - j)) PAzero) (PAle (PAnat i) (PAnat j)))
(Leq (PAplus (PAnat (i - j)) (PAnat j)) (PAnat i))).
Proof.
intros i j. destruct (le_lt_dec i j).
- apply LorIntro1.
unfold PAle, PAplus, PAsucc.
rewrite IsLproposition_eq, IsLterm_op2.
rewrite IsLterm_PAnat, IsLterm_PAnat, IsLterm_PAnat. reflexivity.
apply LandIntro.
apply Nat.sub_0_le in l. rewrite l. apply LeqRefl, IsLterm_const.
apply PAle_normalize, l.
- apply LorIntro2.
unfold PAzero, PAle.
rewrite IsLproposition_and, IsLproposition_eq, IsLproposition_rel2.
rewrite IsLterm_PAnat, IsLterm_PAnat, IsLterm_PAnat, IsLterm_const.
reflexivity.
pose proof (LeqElim_rel2 IsWeakHeytingAxiom 0 _ _ _ _
(PAplus_normalize (i-j) j)
(LeqRefl _ (PAnat i) (IsLterm_PAnat _))) as H0.
apply LandElim2 in H0.
apply (LimpliesElim _ _ _ H0); clear H0.
rewrite Nat.sub_add.
apply LeqRefl, IsLterm_PAnat.
apply Nat.lt_le_incl, l.
Qed.
Lemma SubtractionRepresented : FunctionRepresented 2 Nat.sub.
Proof.
assert (forall i j,
IsLterm i = true ->
IsLterm j = true ->
IsLproposition
(Land (PAle (Lvar 2) i)
(Lor (Land (Leq (Lvar 2) PAzero) (PAle i j))
(Leq (PAplus (Lvar 2) j) i)))
= true) as hypprop.
{ intros. unfold PAle, PAplus, PAsucc, PAzero.
rewrite IsLproposition_and, IsLproposition_or, IsLproposition_and.
rewrite IsLproposition_rel2, IsLproposition_eq, IsLproposition_rel2.
rewrite IsLproposition_eq, IsLterm_op2, IsLterm_var, IsLterm_const, H, H0.
reflexivity. }
(* X2 = X0 - X1 *)
apply (Build_FunctionRepresented 2
_ (Land (PAle (Lvar 2) (Lvar 0))
(Lor (Land (Leq (Lvar 2) PAzero) (PAle (Lvar 0) (Lvar 1)))
(Leq (PAplus (Lvar 2) (Lvar 1)) (Lvar 0))))).
- intro args. simpl. rewrite CoordTailNat.
remember (CoordNat args 0) as i.
remember (CoordNat args 1) as j.
apply LforallIntro.
rewrite Subst_and, Subst_or, Subst_and, Subst_or, Subst_and.
rewrite Subst_and, Subst_eq, SubstTerm_PAzero.
rewrite Subst_PAle, SubstTerm_var, SubstTerm_var; simpl.
rewrite Subst_PAle, SubstTerm_var; simpl.
rewrite Subst_eq, SubstTerm_var, SubstTerm_PAzero; simpl.
rewrite Subst_PAle, Subst_eq, Subst_PAle; simpl.
rewrite SubstTerm_var, Subst_eq, SubstTerm_var; simpl.
rewrite SubstTerm_var, SubstTerm_PAplus; simpl.
rewrite SubstTerm_var, SubstTerm_var; simpl.
rewrite SubstTerm_PAplus, SubstTerm_var; simpl.
rewrite SubstTerm_PAnat.
apply LandIntro.
+ apply PushHypothesis, LforallBounded.
rewrite IsLproposition_implies.
specialize (hypprop (PAnat i) (PAnat j) (IsLterm_PAnat _) (IsLterm_PAnat _)).
rewrite IsLproposition_and in hypprop.
apply andb_prop in hypprop. destruct hypprop. rewrite H0.
rewrite IsLproposition_eq, IsLterm_var, IsLterm_PAnat. reflexivity.
intros k H.
rewrite Subst_implies, Subst_or, Subst_and, Subst_eq, Subst_eq.
rewrite Subst_eq, SubstTerm_var, SubstTerm_PAnat, SubstTerm_PAnat; simpl.
rewrite Subst_PAle, SubstTerm_PAzero, SubstTerm_PAnat, SubstTerm_PAnat.
rewrite SubstTerm_PAplus, SubstTerm_var, SubstTerm_PAnat; simpl.
apply NatSubDef, H.
+ apply LeqElimSubstVarPAnat. apply hypprop.
apply IsLterm_PAnat. apply IsLterm_PAnat.
rewrite Subst_and, Subst_or, Subst_and, Subst_PAle, Subst_PAle.
rewrite Subst_eq, Subst_eq, SubstTerm_PAzero, SubstTerm_var; simpl.
rewrite SubstTerm_PAnat, SubstTerm_PAnat, SubstTerm_PAplus, SubstTerm_var; simpl.
rewrite SubstTerm_PAnat.
apply LandIntro. apply PAle_normalize.
apply Nat.le_sub_l. apply NatSubCorrect.
- apply hypprop. apply IsLterm_var. apply IsLterm_var.
- intros. unfold PAle, PAzero, PAplus, PAsucc, Leq.
rewrite VarOccursFreeInFormula_and, VarOccursFreeInFormula_rel2.
rewrite VarOccursInTerm_var, VarOccursInTerm_var.
rewrite VarOccursFreeInFormula_or, VarOccursFreeInFormula_and.
rewrite VarOccursFreeInFormula_rel2, VarOccursFreeInFormula_rel2.
rewrite VarOccursFreeInFormula_rel2.
rewrite VarOccursInTerm_var, VarOccursInTerm_var, VarOccursInTerm_const.
rewrite VarOccursInTerm_var, VarOccursInTerm_op2, VarOccursInTerm_var.
rewrite VarOccursInTerm_var.
destruct v. inversion H. simpl. apply le_S_n in H.
destruct v. inversion H. simpl. apply le_S_n in H.
destruct v. inversion H. reflexivity.
Qed.
Lemma PredRepresented : FunctionRepresented 1 Nat.pred.
Proof.
apply (FunctionRepresented_1_ext (fun n : nat => n - 1)%nat).
apply ComposeRepr_21. exact SubtractionRepresented.
apply (proj_represented 1 0); auto.
apply (ConstantRepresented 1).
intro n. rewrite Nat.sub_1_r. reflexivity.
Qed.
Lemma mod_repr : FunctionRepresented 2 Nat.modulo.
Proof.
assert (forall i j : nat, i - (i/j)*j = i mod j)%nat as moddef.
{ intros. pose proof (Nat.div_mod_eq i j) as H.
rewrite Nat.mul_comm in H.
symmetry in H. exact (Nat.add_sub_eq_l i ((i/j)*j) (i mod j) H). }
refine (FunctionRepresented_2_ext _ _ _ moddef). clear moddef.
apply ComposeRepr_22.
exact SubtractionRepresented.
apply (proj_represented 2 0). auto.
apply ComposeRepr_22.
exact MultiplicationRepresented.
exact DivisionRepresented.
apply (proj_represented 2 1). auto.
Qed.
Definition godel_beta (s t i : nat) : nat := s mod ((i+1)*t+1).
Lemma beta_repr : FunctionRepresented 3 godel_beta.
Proof.
unfold godel_beta.
apply ComposeRepr_23.
apply mod_repr.
apply (proj_represented 3 0). auto.
apply ComposeRepr_23.
apply AdditionRepresented.
apply ComposeRepr_23.
apply MultiplicationRepresented.
apply ComposeRepr_23.
apply AdditionRepresented.
apply (proj_represented 3 2). apply Nat.le_refl.
apply (ConstantRepresented 1 3).
apply (proj_represented 3 1). auto.
apply (ConstantRepresented 1 3).
Qed.
(* We add a minimalist clause to beta_repr so that it better represents beta
for possibly non-standard inputs, when the output is standard. *)
Definition beta_prop_min : nat :=
let m := MaxVar beta_repr in
(Land beta_repr
(Lforall (S m) (Limplies (PAle (PAsucc (Lvar (S m))) (Lvar 3))
(Lnot (Subst (Lvar (S m)) 3 beta_repr))))).
Lemma beta_representation_unique
: FormulaRepresents 3 godel_beta beta_prop_min.
Proof.
unfold beta_prop_min.
pose (MaxVar beta_repr) as m. fold m.
intro args. simpl.
do 3 rewrite Subst_and.
pose proof (fr_rep _ _ beta_repr args) as beta_rep.
apply LforallElimIdemVar in beta_rep.
apply LforallIntro, LandIntro.
- (* The new representation is syntactically stronger than beta_repr,
so the first implication is trivial. *)
apply LandElim1 in beta_rep.
refine (LimpliesTrans _ _ _ _ _ beta_rep). clear beta_rep.
apply LandElim1_impl.
apply SubstIsLproposition.
apply SubstIsLproposition.
apply SubstIsLproposition.
apply fr_propprop.
apply IsLterm_PAnat. apply IsLterm_PAnat. apply IsLterm_PAnat.
apply SubstIsLproposition.
apply SubstIsLproposition.
apply SubstIsLproposition.
unfold PAle, PAsucc. reduce_islproposition.
apply SubstIsLproposition. apply fr_propprop.
apply IsLterm_var. apply IsLterm_PAnat.
apply IsLterm_PAnat. apply IsLterm_PAnat.
- (* Now the converse, we first clear the beta_repr clause. *)
apply LandIntroHyp.
apply LandElim2 in beta_rep. exact beta_rep.
(* And we are left to prove than no number lower than godel_beta i j k
satisfies beta_repr. LforallBounded_lt will pull the hypothesis in
the meta-theory. *)
do 3 rewrite CoordTailNat.
simpl in beta_rep.
do 3 rewrite CoordTailNat in beta_rep.
remember (CoordNat args 0) as i.
remember (CoordNat args 1) as j.
remember (CoordNat args 2) as k.
(* Replace Lvar 3 by godel_beta i j k *)
apply LeqElimSubstVarPAnat.
apply SubstIsLproposition.
apply SubstIsLproposition.
apply SubstIsLproposition.
unfold PAle, PAsucc. reduce_islproposition.
apply SubstIsLproposition. apply fr_propprop.
apply IsLterm_var. apply IsLterm_PAnat.
apply IsLterm_PAnat. apply IsLterm_PAnat.
(* Pull the bounded Lforall (S m) into the meta, as a new hypothesis
H0 : a < godel_beta i j k *)
assert (3 <= m)%nat.
{ destruct (le_lt_dec 3 (MaxVar beta_repr)). exact l. exfalso.
pose proof (MaxVarDoesNotOccurFree beta_repr (fr_propprop _ _ beta_repr) 3 l).
pose proof (fr_freevar _ _ beta_repr).
rewrite H0 in H. discriminate H. }
assert (m =? 0 = false)%nat as m0.
{ apply Nat.eqb_neq. intro abs. rewrite abs in H. inversion H. }
assert (m =? 1 = false)%nat as m1.
{ apply Nat.eqb_neq. intro abs. rewrite abs in H.
apply le_S_n in H. inversion H. }
assert (m =? 2 = false)%nat as m2.
{ apply Nat.eqb_neq. intro abs. rewrite abs in H.
apply le_S_n, le_S_n in H. inversion H. }
rewrite Subst_forall; simpl.
rewrite Subst_forall; simpl; rewrite m0.
rewrite Subst_forall; simpl; rewrite m1.
rewrite Subst_forall; simpl; rewrite m2.
do 4 rewrite Subst_implies.
do 4 rewrite Subst_PAle, SubstTerm_PAsucc.
reduce_subst; simpl. rewrite SubstTerm_var. simpl. rewrite m1.
do 2 rewrite SubstTerm_var. simpl.
rewrite SubstTerm_var. simpl. rewrite m0.
rewrite SubstTerm_var. simpl.
rewrite SubstTerm_var. simpl. rewrite m2.
apply LforallIntro.
apply LforallBounded_lt.
rewrite IsLproposition_not.
apply SubstIsLproposition.
apply SubstIsLproposition.
apply SubstIsLproposition.
apply SubstIsLproposition.
apply SubstIsLproposition.
apply fr_propprop. apply IsLterm_var.
apply IsLterm_PAnat. apply IsLterm_PAnat.
apply IsLterm_PAnat. apply IsLterm_PAnat.
intros a H0.
(* Finish by showing that a cannot satisfy beta_repr,
otherwise it would be equal to godel_beta i j k. *)
rewrite Subst_not.
rewrite (SubstSubstDiffCommutes _ 2 3).
rewrite (SubstSubstDiffCommutes _ 1 3).
rewrite (SubstSubstDiffCommutes _ 0 3).
rewrite SubstSubstIdem, SubstTerm_var. simpl. rewrite m2.
rewrite SubstSubstNested, SubstTerm_var, Nat.eqb_refl.
+ apply NotByContradiction.
apply (LforallIntro _ _ 3) in beta_rep.
apply (LforallElim _ _ _ (PAnat a)) in beta_rep.
rewrite Subst_equiv, Subst_eq, SubstTerm_var in beta_rep.
rewrite SubstTerm_PAnat in beta_rep. simpl in beta_rep.
apply LandElim1 in beta_rep.
apply (LimpliesTrans _ _ _ _ beta_rep). clear beta_rep.
apply (LimpliesTrans _ _ (Leq (PAnat (godel_beta i j k)) (PAnat a))).
apply LeqSym_impl. apply IsLterm_PAnat. apply IsLterm_PAnat.
apply FalseElim_impl.
apply PAlt_not_eq, H0.
rewrite IsLproposition_not.
apply SubstIsLproposition.
apply SubstIsLproposition.
apply SubstIsLproposition.
apply SubstIsLproposition.
apply fr_propprop.
apply IsLterm_PAnat. apply IsLterm_PAnat. apply IsLterm_PAnat.
apply IsLterm_PAnat. apply IsLterm_PAnat.
apply IsFreeForSubst_PAnat.
rewrite IsLproposition_equiv, SubstIsLproposition.
rewrite IsLproposition_eq, IsLterm_var, IsLterm_PAnat. reflexivity.
apply SubstIsLproposition.
apply SubstIsLproposition.
apply fr_propprop.
apply IsLterm_PAnat. apply IsLterm_PAnat. apply IsLterm_PAnat.
+ apply SubstIsLproposition.
apply SubstIsLproposition.
apply SubstIsLproposition.
apply fr_propprop.
apply IsLterm_PAnat. apply IsLterm_PAnat. apply IsLterm_PAnat.
+ rewrite VarOccursFreeInFormula_SubstDiff, VarOccursFreeInFormula_SubstDiff.
rewrite VarOccursFreeInFormula_SubstDiff.
apply MaxVarDoesNotOccurFree. apply fr_propprop.
apply Nat.le_refl. apply fr_propprop.
apply Nat.eqb_neq. exact m1.
apply PAnat_closed.
apply SubstIsLproposition. apply fr_propprop. apply IsLterm_PAnat.
apply Nat.eqb_neq. exact m0.
apply PAnat_closed.
apply SubstIsLproposition.
apply SubstIsLproposition.
apply fr_propprop. apply IsLterm_PAnat. apply IsLterm_PAnat.
discriminate. apply PAnat_closed.
+ apply MaxVarFreeSubst_var.
apply SubstIsLproposition.
apply SubstIsLproposition.
apply SubstIsLproposition.
apply fr_propprop.
apply IsLterm_PAnat. apply IsLterm_PAnat. apply IsLterm_PAnat.
apply le_n_S.
apply (Nat.le_trans _ _ _ (MaxVar_Subst _ _ _)).
rewrite MaxVarTerm_PAnat. simpl.
apply (Nat.le_trans _ _ _ (MaxVar_Subst _ _ _)).
rewrite MaxVarTerm_PAnat. simpl.
apply (Nat.le_trans _ _ _ (MaxVar_Subst _ _ _)).
rewrite MaxVarTerm_PAnat. apply Nat.le_refl.
+ discriminate.
+ apply PAnat_closed.
+ rewrite VarOccursInTerm_var, Nat.eqb_sym. reflexivity.
+ discriminate.
+ apply PAnat_closed.
+ rewrite VarOccursInTerm_var, Nat.eqb_sym. exact m0.
+ discriminate.
+ apply PAnat_closed.
+ rewrite VarOccursInTerm_var, Nat.eqb_sym. exact m1.
Qed.
Lemma beta_prop_min_IsLprop : IsLproposition beta_prop_min = true.
Proof.
unfold beta_prop_min.
unfold PAle, PAsucc.
reduce_islproposition.
rewrite fr_propprop, SubstIsLproposition.
reflexivity. apply fr_propprop. apply IsLterm_var.
Qed.
Lemma beta_prop_min_vars :
forall v:nat, (3 < v)%nat -> VarOccursFreeInFormula v beta_prop_min = false.
Proof.
intros. unfold beta_prop_min.
rewrite VarOccursFreeInFormula_and, fr_vars. 2: exact H.
rewrite VarOccursFreeInFormula_forall.
destruct (v =? S (MaxVar beta_repr))%nat eqn:des. reflexivity.
simpl. unfold PAle, PAsucc.
rewrite VarOccursFreeInFormula_implies, VarOccursFreeInFormula_rel2.
rewrite VarOccursInTerm_op1, VarOccursInTerm_var, des, VarOccursInTerm_var.
simpl. rewrite VarOccursFreeInFormula_not, VarOccursFreeInFormula_SubstDiff.
rewrite fr_vars, Bool.orb_false_r.
apply Nat.eqb_neq. intro abs. rewrite abs in H. exact (Nat.lt_irrefl _ H).
exact H. apply fr_propprop. intro abs. rewrite abs in H. exact (Nat.lt_irrefl _ H).
rewrite VarOccursInTerm_var. exact des.
Qed.
Lemma beta_repr_uniq :
{ repr : FunctionRepresented 3 godel_beta
| forall n:nat, IsProved IsWeakHeytingAxiom
(Lforall 0 (Lforall 1 (Lforall 2
(Limplies (Land (Subst (PAnat n) 3 repr) repr)
(Leq (PAnat n) (Lvar 3)))))) }.
Proof.
exists (Build_FunctionRepresented
3 _ _ beta_representation_unique
beta_prop_min_IsLprop beta_prop_min_vars).
simpl.
assert (3 <= MaxVar beta_repr)%nat as m3.
{ destruct (le_lt_dec 3%nat (MaxVar beta_repr)). exact l.
pose proof (MaxVarDoesNotOccurFree beta_repr (fr_propprop _ _ beta_repr) 3 l).
pose proof (fr_freevar _ _ beta_repr).
rewrite H0 in H. discriminate H. }
assert (S (MaxVar beta_repr) =? 3 = false)%nat as m2.
{ apply Nat.eqb_neq. intro abs. inversion abs. rewrite H0 in m3.
exact (Nat.lt_irrefl _ m3). }
intros n.
apply LforallIntro, LforallIntro, LforallIntro.
refine (LimpliesElim _ _ _ _ (PAnat_le_lt_total (S n) (Lvar 3) (IsLterm_var 3))).
apply LorElim.
- (* PAle (PAnat (S n)) (Lvar 3) *)
apply PullHypothesis.
apply (LimpliesTrans _ _ (Land (Subst (PAnat n) 3 beta_repr)
(Lnot (Subst (PAnat n) 3 beta_repr)))).
apply LandIntroHyp.
apply DropFirstHypothesis.
unfold PAle. reduce_islproposition. rewrite IsLterm_PAnat. reflexivity.
apply DropSecondHypothesis.
exact beta_prop_min_IsLprop.
unfold beta_prop_min. rewrite Subst_and.
apply LandElim1_impl.
apply SubstIsLproposition. apply fr_propprop. apply IsLterm_PAnat.
pose proof beta_prop_min_IsLprop. unfold beta_prop_min in H.
rewrite IsLproposition_and in H. apply andb_prop in H.
destruct H as [_ H].
apply SubstIsLproposition. exact H. apply IsLterm_PAnat.
apply (LimpliesTrans _ _ (Land (PAle (PAnat (S n)) (Lvar 3)) beta_prop_min)).
apply LandIntroHyp.
apply DropSecondHypothesis.
rewrite IsLproposition_and, SubstIsLproposition.
exact beta_prop_min_IsLprop. exact beta_prop_min_IsLprop.
apply IsLterm_PAnat.
apply LimpliesRefl. unfold PAle.
rewrite IsLproposition_rel2, IsLterm_PAnat. apply IsLterm_var.
apply DropFirstHypothesis. unfold PAle.
rewrite IsLproposition_rel2, IsLterm_PAnat. apply IsLterm_var.
apply LandElim2_impl.
apply SubstIsLproposition. exact beta_prop_min_IsLprop.
apply IsLterm_PAnat. exact beta_prop_min_IsLprop.
unfold beta_prop_min.
apply (LimpliesTrans _ _ (Land (PAle (PAnat (S n)) (Lvar 3))
(Subst (PAnat n) (S (MaxVar beta_repr))
(Limplies (PAle (PAsucc (Lvar (S (MaxVar beta_repr)))) (Lvar 3))
(Lnot (Subst (Lvar (S (MaxVar beta_repr))) 3 beta_repr)))))).
apply LandIntroHyp.
apply LandElim1_impl.
unfold PAle. rewrite IsLproposition_rel2, IsLterm_PAnat.
apply IsLterm_var.
unfold PAle, PAsucc. reduce_islproposition.
rewrite fr_propprop. apply SubstIsLproposition. apply fr_propprop.
apply IsLterm_var.
apply DropFirstHypothesis.
unfold PAle. rewrite IsLproposition_rel2, IsLterm_PAnat.
apply IsLterm_var.
apply DropFirstHypothesis. apply fr_propprop.
apply LforallElim_impl.
unfold PAle, PAsucc. reduce_islproposition.
apply SubstIsLproposition. apply fr_propprop.
apply IsLterm_var. apply IsLterm_PAnat.
unfold PAle.
rewrite IsFreeForSubst_implies, IsFreeForSubst_rel2.
apply IsFreeForSubst_PAnat.
rewrite IsLproposition_not. apply SubstIsLproposition.
apply fr_propprop. apply IsLterm_var.
rewrite Subst_implies, Subst_PAle, SubstTerm_PAsucc, SubstTerm_var, Nat.eqb_refl.
rewrite SubstTerm_var, Nat.eqb_sym, m2, Subst_not, SubstSubstNested.
rewrite SubstTerm_var, Nat.eqb_refl.
apply CommuteHypotheses.
apply PushHypothesis. apply LimpliesRefl.
unfold PAle. reduce_islproposition.
rewrite IsLterm_PAnat, SubstIsLproposition. reflexivity.
apply fr_propprop. apply IsLterm_PAnat. apply fr_propprop.
apply MaxVarDoesNotOccurFree. apply fr_propprop. apply Nat.le_refl.
apply MaxVarFreeSubst_var. apply fr_propprop. apply Nat.le_refl.
apply PushHypothesis, IsProvedPropAx, Ax5IsPropAx, Ax5IsAx5.
apply SubstIsLproposition. apply fr_propprop. apply IsLterm_PAnat.
rewrite IsLproposition_eq, IsLterm_PAnat. apply IsLterm_var.
- apply (LimpliesTrans _ _ (PAle (Lvar 3) (PAnat n))).
pose proof (PAle_decr (PAnat n) (IsLterm_PAnat n)).
apply (LforallIntro _ _ 0) in H.
apply (LforallElim _ _ _ (Lvar 3)) in H.
rewrite Subst_implies, Subst_PAle, SubstTerm_PAsucc, SubstTerm_var in H.
simpl in H. rewrite SubstTerm_PAsucc, SubstTerm_PAnat, Subst_PAle in H.
rewrite SubstTerm_var, SubstTerm_PAnat in H. exact H.
apply IsLterm_var.
unfold PAle.
rewrite IsFreeForSubst_implies, IsFreeForSubst_rel2, IsFreeForSubst_rel2.
reflexivity.
apply LforallBounded.
rewrite IsLproposition_implies, IsLproposition_and, SubstIsLproposition.
rewrite beta_prop_min_IsLprop, IsLproposition_eq, IsLterm_PAnat.
apply IsLterm_var. apply beta_prop_min_IsLprop. apply IsLterm_PAnat.
intros j jlen.
rewrite Subst_implies, Subst_and, SubstSubstIdem, SubstTerm_PAnat.
rewrite Subst_eq, SubstTerm_PAnat, SubstTerm_var. simpl.
destruct (Nat.lt_trichotomy j n). clear jlen.
apply (LimpliesTrans _ _ (Land (Subst (PAnat j) 3 beta_repr)
(Lnot (Subst (PAnat j) 3 beta_repr)))).
apply LandIntroHyp.
apply DropFirstHypothesis.
apply SubstIsLproposition. apply beta_prop_min_IsLprop.
apply IsLterm_PAnat.
unfold beta_prop_min. rewrite Subst_and.
apply LandElim1_impl.
apply SubstIsLproposition. apply fr_propprop. apply IsLterm_PAnat.
pose proof beta_prop_min_IsLprop. unfold beta_prop_min in H0.
rewrite IsLproposition_and in H0. apply andb_prop in H0.
destruct H0 as [_ H0].
apply SubstIsLproposition. exact H0. apply IsLterm_PAnat.
apply DropSecondHypothesis.
apply SubstIsLproposition. apply beta_prop_min_IsLprop.
apply IsLterm_PAnat.
unfold beta_prop_min.
rewrite Subst_and, Subst_forall.
rewrite m2.
rewrite Subst_implies, Subst_PAle, SubstTerm_PAsucc, SubstTerm_var.
rewrite m2, SubstTerm_var, Subst_not, SubstSubstIdem. simpl.
rewrite SubstTerm_var, m2.
apply DropFirstHypothesis.
apply SubstIsLproposition. apply fr_propprop. apply IsLterm_PAnat.
refine (LimpliesTrans _ _ _ _ (LforallElim_impl _ _ _ (PAnat j) _ _ _) _).
unfold PAle, PAsucc. reduce_islproposition.
rewrite IsLterm_PAnat. apply SubstIsLproposition.
apply fr_propprop. apply IsLterm_var. apply IsLterm_PAnat.
apply IsFreeForSubst_PAnat.
unfold PAle, PAsucc. reduce_islproposition.
rewrite IsLterm_PAnat. apply SubstIsLproposition.
apply fr_propprop. apply IsLterm_var.
rewrite Subst_implies, Subst_PAle, SubstTerm_PAsucc, SubstTerm_var.
rewrite Nat.eqb_refl, SubstTerm_PAnat, Subst_not, SubstSubstNested.
rewrite SubstTerm_var, Nat.eqb_refl.
apply LimpliesElim_impl.
rewrite IsLproposition_not. apply SubstIsLproposition.
apply fr_propprop. apply IsLterm_PAnat.
apply (PAle_normalize (S j) n H).
apply fr_propprop.
apply MaxVarDoesNotOccurFree. apply fr_propprop. apply Nat.le_refl.
apply MaxVarFreeSubst_var. apply fr_propprop. apply Nat.le_refl.
apply PushHypothesis.
apply IsProvedPropAx, Ax5IsPropAx, Ax5IsAx5.
apply SubstIsLproposition. apply fr_propprop. apply IsLterm_PAnat.
rewrite IsLproposition_eq, IsLterm_PAnat. apply IsLterm_PAnat.
destruct H.
subst j. apply DropHypothesis.
rewrite IsLproposition_and, SubstIsLproposition. reflexivity.
apply beta_prop_min_IsLprop. apply IsLterm_PAnat.
apply LeqRefl. apply IsLterm_PAnat.
exfalso. apply (Nat.lt_irrefl n). exact (Nat.lt_le_trans _ _ _ H jlen).
Qed.
(* Show that the modulos inside the beta function are pairwise coprime. *)
Lemma BetaRelPrime : forall (i j : Z) (m : nat),
0 < i < j
-> j <= Z.of_nat m
-> rel_prime (i*Z.of_nat (fact m)+1) (j*Z.of_nat (fact m)+1).
Proof.
intros. constructor.
exists (i*Z.of_nat (fact m)+1). rewrite Z.mul_1_r. reflexivity.
exists (j*Z.of_nat (fact m)+1). rewrite Z.mul_1_r. reflexivity.
intros r H1 H2.
assert ((r | (j-i)*Z.of_nat (fact m))).
{ destruct H1, H2. exists (x0-x).
rewrite Z.mul_sub_distr_r.
rewrite Z.mul_sub_distr_r.
rewrite <- H2, <- H1. ring. }
rewrite Z.mul_comm in H3.
apply Gauss in H3.
- apply Zdivide_Zabs_l.
assert (0 < j - i) as jipos by apply Z.lt_0_sub, H.
pose proof (Zdivide_bounds _ _ H3) as rle.
assert ((Z.abs r | Z.of_nat (fact m))).
apply ZdivideFact.
split. destruct r. exfalso.
destruct H3. rewrite Z.mul_0_r in H3.
rewrite H3 in jipos. inversion jipos.
reflexivity. reflexivity.
apply (Z.le_trans _ (Z.abs (j-i))). apply rle.
intro abs. rewrite abs in jipos. inversion jipos.
rewrite Z.abs_eq.
apply (Z.le_trans _ j).
apply Z.le_sub_nonneg. apply Z.lt_le_incl, H. exact H0.
apply Z.lt_le_incl, jipos.
apply Zdivide_Zabs_inv_l in H1.
destruct H4, H1. rewrite H4 in H1.
exists (x0 - i*x).
rewrite Z.mul_sub_distr_r, <- H1. ring.
- apply bezout_rel_prime.
destruct H1 as [x H1].
apply (Bezout_intro _ _ _ x (-i)).
rewrite <- H1. ring.
Qed.
Fixpoint MaxSeq (n l : nat) {struct l} : nat :=
match l with
| O => O (* neutral for Nat.max *)
| S k => Nat.max (CoordNat n 0) (MaxSeq (TailNat n) k)
end.
Lemma CoordLeMaxSeq : forall l i n,
(i < l)%nat
-> (CoordNat n i <= MaxSeq n l)%nat.
Proof.
induction l.
- intros. inversion H.
- intros. simpl.
destruct i. apply Nat.le_max_l.
rewrite <- CoordTailNat.
apply le_S_n in H.
exact (Nat.le_trans _ _ _ (IHl _ _ H) (Nat.le_max_r _ _)).
Qed.
Lemma fact_le_id : forall n:nat, (n <= fact n)%nat.
Proof.
induction n.
- apply le_S, Nat.le_refl.
- rewrite <- (Nat.mul_1_r (S n)) at 1.
change (fact (S n)) with ((S n) * fact n)%nat.
apply Nat.mul_le_mono_nonneg_l. apply Nat.le_0_l.
apply lt_O_fact.
Qed.
(* The other encoding of sequences, by the beta function.
Beta is simple enough to be represented by a direct arithmetic formula,
but it is not injective so it cannot replace CoordNat. Beta is
sufficient to prove that recursive definitions like CoordNat are represented. *)
Lemma BetaSeq : forall n:nat, exists (s:nat),
forall i:nat, (i < LengthNat n)%nat
-> godel_beta s (fact (MaxSeq (ConsNat (LengthNat n) n) (S (LengthNat n)))) i
= CoordNat n i.
Proof.
intro n.
pose (fact (MaxSeq (ConsNat (LengthNat n) n) (S (LengthNat n)))) as t.
pose (MapNat (fun i => (i+1)*t+1)%nat (RangeNat 0 (LengthNat n))) as modulos.
assert (LengthNat modulos = LengthNat n) as moduloslen.
{ unfold modulos. rewrite LengthMapNat, LengthRangeNat. reflexivity. }
destruct (ChineseRemainder modulos n) as [s H].
- exact moduloslen.
- intros i H. unfold modulos.
rewrite CoordMapNat, CoordRangeNat. simpl.
apply (Nat.le_lt_trans _ t).
refine (Nat.le_trans _ _ _ _ (fact_le_id _)).
rewrite <- (CoordConsTailNat i n (LengthNat n)).
apply CoordLeMaxSeq. apply le_n_S.
rewrite moduloslen in H. exact H.
rewrite <- (Nat.add_comm 1). apply le_n_S.
rewrite <- (Nat.mul_1_l t) at 1.
apply Nat.mul_le_mono_nonneg_r. apply Nat.le_0_l.
rewrite Nat.add_comm. apply le_n_S, Nat.le_0_l.
rewrite <- moduloslen. exact H.
rewrite LengthRangeNat, <- moduloslen. exact H.
- intros i j H. unfold modulos.
rewrite moduloslen in H.
rewrite CoordMapNat, CoordMapNat, CoordRangeNat, CoordRangeNat.
simpl.
rewrite Nat2Z.inj_add, Nat2Z.inj_add. simpl.
rewrite Nat2Z.inj_mul, Nat2Z.inj_mul.
apply BetaRelPrime.
split. apply (Nat2Z.inj_lt 0).
rewrite Nat.add_comm. apply le_n_S, Nat.le_0_l.
apply Nat2Z.inj_lt. rewrite (Nat.add_comm i), (Nat.add_comm j).
apply le_n_S, H.
apply Nat2Z.inj_le. simpl. rewrite CoordConsHeadNat.
refine (Nat.le_trans _ _ _ _ (Nat.le_max_l _ _)).
rewrite Nat.add_comm. apply H. apply H.
exact (Nat.lt_trans _ _ _ (proj1 H) (proj2 H)).
rewrite LengthRangeNat. apply H.
rewrite LengthRangeNat.
exact (Nat.lt_trans _ _ _ (proj1 H) (proj2 H)).
- exists s. intros i H0. unfold godel_beta.
rewrite moduloslen in H.
specialize (H i H0). unfold modulos in H.
rewrite CoordMapNat, CoordRangeNat in H. exact H.
exact H0. rewrite LengthRangeNat. exact H0.
Qed.
(* This proposition asserts the existence of a finite sequence
beta(s,t,0), ..., beta(s,t,k) such as
beta(s,t,0) = init and ... beta(s,t,1+i) = u(i, beta(s,t,i)).
We take s = Lvar m and t = Lvar (1+m).
It represents function nat_rec (fun _ => nat) init u
= (fix F (k : nat) : nat := match k with
| O => init
| S p => u p (F p)
end) *)
Definition betast (m : nat) : nat
:= Subst (Lvar (1+m)) 1 (Subst (Lvar m) 0 (proj1_sig beta_repr_uniq)).
Definition beta_rec_body (m uprop bound : nat) :=
(Lforall (2+m) (Limplies (PAle (PAsucc (Lvar (2+m))) bound)
(Lexists (3+m) (Lexists (4+m)
(* X3+m = beta(s,t,X2+m) is the recursive computation.
X4+m = beta(s,t,1+X2+m) is the next value. *)
(Land (Subst (Lvar (3+m)) 3 (Subst (Lvar (2+m)) 2 (betast m)))
(Land (Subst (Lvar (4+m)) 3 (Subst (PAsucc (Lvar (2+m))) 2 (betast m)))
(Subst (Lvar (4+m)) 2 (Subst (Lvar (3+m)) 1
(Subst (Lvar (2+m)) 0 uprop))))))))).
Definition nat_rec_representation (uprop : nat) : nat :=
let m := S (Nat.max (MaxVar (proj1_sig beta_repr_uniq)) (MaxVar uprop)) in
Lexists m (Lexists (1+m) (* the s,t that define the beta-sequence *)
(Land (Land
(Lexists (2+m) (* beta(s,t,0) = X0 *)
(Land (Leq (Lvar (2+m)) (Lvar 0))
(Subst (Lvar (2+m)) 3 (Subst PAzero 2 (betast m)))))
(beta_rec_body m uprop (Lvar 1)))
(Lexists (2+m) (Lexists (3+m) (* beta(s,t,X1) = X2 *)
(Land (Leq (Lvar (2+m)) (Lvar 1))
(Land (Leq (Lvar (3+m)) (Lvar 2))
(Subst (Lvar (3+m)) 3 (Subst (Lvar (2+m)) 2 (betast m))))))))).
Lemma betast_IsLprop : forall m, IsLproposition (betast m) = true.
Proof.
intros.
apply SubstIsLproposition.
apply SubstIsLproposition.
apply fr_propprop. apply IsLterm_var. apply IsLterm_var.
Qed.
Lemma betast_vars : forall m v,
(0 <> m)%nat
-> (v <= 1)%nat -> VarOccursFreeInFormula v (betast m) = false.
Proof.
intros m v H H0. unfold betast.
destruct v.
- apply VarOccursFreeInFormula_SubstClosed.
apply VarOccursFreeInFormula_SubstIdem.
apply fr_propprop.
rewrite VarOccursInTerm_var. apply Nat.eqb_neq, H.
apply VarOccursInTerm_var.
- destruct v. apply VarOccursFreeInFormula_SubstIdem.
apply SubstIsLproposition. apply fr_propprop.
apply IsLterm_var.
rewrite VarOccursInTerm_var. simpl.
destruct m. exfalso. apply H. reflexivity. reflexivity.
exfalso. apply le_S_n in H0. inversion H0.
Qed.
Lemma MaxVar_betast : forall m,
(MaxVar (betast m) <= Nat.max (S m) (MaxVar (proj1_sig beta_repr_uniq)))%nat.
Proof.
intro m.
apply (Nat.le_trans _ _ _ (MaxVar_Subst _ _ _)).
apply Nat.max_lub. rewrite MaxVarTerm_var. apply Nat.le_max_l.
apply (Nat.le_trans _ _ _ (MaxVar_Subst _ _ _)).
apply Nat.max_lub. rewrite MaxVarTerm_var.
apply (Nat.le_trans _ (S m)). apply le_S, Nat.le_refl.
apply Nat.le_max_l. apply Nat.le_max_r.
Qed.
Lemma betast_SubstSubst : forall m s t,
(MaxVar (proj1_sig beta_repr_uniq) < m)%nat
-> (2 <= m)%nat
-> Subst (PAnat t) (S m) (Subst (PAnat s) m (betast m))