-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIsProof_repr.v
3477 lines (3403 loc) · 133 KB
/
IsProof_repr.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
Require Import PeanoNat.
Require Import Numbers.NaryFunctions.
Require Import Arith.Wf_nat.
Require Import EnumSeqNat.
Require Import Formulas.
Require Import Substitutions.
Require Import IsFreeForSubst.
Require Import Proofs.
Require Import PeanoAxioms.
Require Import HeytingModel.
Require Import HeytingRepresentation.
Require Import BoolRepresented.
Require Import BetaRepr.
Require Import EnumSeqNat_repr.
Lemma Lnot_repr : FunctionRepresented 1 Lnot.
Proof.
unfold Lnot.
apply ComposeRepr_21.
exact ConsNat_repr.
apply (ConstantRepresented 1).
apply ComposeRepr_21.
exact ConsNat_repr.
apply (proj_represented 1 0); auto.
apply (ConstantRepresented 0).
Qed.
Lemma Land_repr : FunctionRepresented 2 Land.
Proof.
unfold Land.
apply ComposeRepr_22.
exact ConsNat_repr.
apply (ConstantRepresented LandHead).
apply ComposeRepr_22.
exact ConsNat_repr.
apply (proj_represented 2 0); auto.
apply ComposeRepr_22.
exact ConsNat_repr.
apply (proj_represented 2 1); auto.
apply (ConstantRepresented 0).
Qed.
Lemma Lor_repr : FunctionRepresented 2 Lor.
Proof.
unfold Lor.
apply ComposeRepr_22.
exact ConsNat_repr.
apply (ConstantRepresented LorHead).
apply ComposeRepr_22.
exact ConsNat_repr.
apply (proj_represented 2 0); auto.
apply ComposeRepr_22.
exact ConsNat_repr.
apply (proj_represented 2 1); auto.
apply (ConstantRepresented 0).
Qed.
Lemma Limplies_repr : FunctionRepresented 2 Limplies.
Proof.
unfold Limplies.
apply ComposeRepr_22.
exact ConsNat_repr.
apply (ConstantRepresented LimpliesHead).
apply ComposeRepr_22.
exact ConsNat_repr.
apply (proj_represented 2 0); auto.
apply ComposeRepr_22.
exact ConsNat_repr.
apply (proj_represented 2 1); auto.
apply (ConstantRepresented 0).
Qed.
Lemma Lop_repr : FunctionRepresented 2 Lop.
Proof.
unfold Lop.
apply ComposeRepr_22.
exact ConsNat_repr.
apply (ConstantRepresented LopHead).
exact ConsNat_repr.
Qed.
Lemma Lop1_repr : FunctionRepresented 2 Lop1.
Proof.
unfold Lop1.
apply ComposeRepr_22. exact Lop_repr.
apply (proj_represented 2 0); auto.
apply ComposeRepr_22. exact ConsNat_repr.
apply (proj_represented 2 1); auto.
apply (ConstantRepresented 0).
Qed.
Lemma Lop2_repr : FunctionRepresented 3 Lop2.
Proof.
unfold Lop2.
apply ComposeRepr_23. exact Lop_repr.
apply (proj_represented 3 0); auto.
apply ComposeRepr_23. exact ConsNat_repr.
apply (proj_represented 3 1); auto.
apply ComposeRepr_23. exact ConsNat_repr.
apply (proj_represented 3 2); auto.
apply (ConstantRepresented 0).
Qed.
Lemma Lrel_repr : FunctionRepresented 2 Lrel.
Proof.
unfold Lrel.
apply ComposeRepr_22.
exact ConsNat_repr.
apply (ConstantRepresented LrelHead).
exact ConsNat_repr.
Qed.
Lemma Lrel2_repr : FunctionRepresented 3 Lrel2.
Proof.
unfold Lrel2.
apply ComposeRepr_23. exact Lrel_repr.
apply (proj_represented 3 0); auto.
apply ComposeRepr_23. exact ConsNat_repr.
apply (proj_represented 3 1); auto.
apply ComposeRepr_23. exact ConsNat_repr.
apply (proj_represented 3 2); auto.
apply (ConstantRepresented 0).
Qed.
Lemma Leq_repr : FunctionRepresented 2 Leq.
Proof.
unfold Leq.
apply ComposeRepr_32. exact Lrel2_repr.
apply (ConstantRepresented 0).
apply (proj_represented 2 0); auto.
apply (proj_represented 2 1); auto.
Qed.
Lemma Lvar_repr : FunctionRepresented 1 Lvar.
Proof.
unfold Lvar.
apply ComposeRepr_21.
exact ConsNat_repr.
apply (ConstantRepresented LvarHead).
apply ComposeRepr_21.
exact ConsNat_repr.
apply (proj_represented 1 0); auto.
apply (ConstantRepresented 0).
Qed.
Lemma Lexists_repr : FunctionRepresented 2 Lexists.
Proof.
unfold Lexists.
apply ComposeRepr_22.
exact ConsNat_repr.
apply (ConstantRepresented LexistsHead).
apply ComposeRepr_22.
exact ConsNat_repr.
apply (proj_represented 2 0); auto.
apply ComposeRepr_22.
exact ConsNat_repr.
apply (proj_represented 2 1); auto.
apply (ConstantRepresented 0).
Qed.
Lemma Lforall_repr : FunctionRepresented 2 Lforall.
Proof.
unfold Lforall.
apply ComposeRepr_22.
exact ConsNat_repr.
apply (ConstantRepresented LforallHead).
apply ComposeRepr_22.
exact ConsNat_repr.
apply (proj_represented 2 0); auto.
apply ComposeRepr_22.
exact ConsNat_repr.
apply (proj_represented 2 1); auto.
apply (ConstantRepresented 0).
Qed.
Lemma IsLvar_repr : FunctionRepresentedBool 1 IsLvar.
Proof.
unfold IsLvar.
apply (EqbRepresented 1).
apply (proj_represented 1 0); auto.
apply ComposeRepr_11.
apply ComposeRepr_21. exact ConsNat_repr.
apply (ConstantRepresented LvarHead).
apply (proj_represented 1 0); auto.
apply ComposeRepr_21. exact ConsNat_repr.
apply ComposeRepr_21. exact CoordNat_repr.
apply (proj_represented 1 0); auto.
apply (ConstantRepresented 1).
apply (ConstantRepresented 0).
Qed.
Lemma IsLnot_repr : FunctionRepresentedBool 1 IsLnot.
Proof.
apply (EqbRepresented 1).
apply (proj_represented 1 0); apply Nat.le_refl.
apply ComposeRepr_11.
apply ComposeRepr_21. exact ConsNat_repr.
apply (ConstantRepresented 1).
apply (proj_represented 1 0); apply Nat.le_refl.
apply ComposeRepr_21. exact ConsNat_repr.
apply ComposeRepr_21. exact CoordNat_repr.
apply (proj_represented 1 0); apply Nat.le_refl.
apply (ConstantRepresented 1).
apply (ConstantRepresented 0).
Qed.
Lemma IsLimplies_repr : FunctionRepresentedBool 1 IsLimplies.
Proof.
apply (EqbRepresented 1).
apply (proj_represented 1 0); apply Nat.le_refl.
apply ComposeRepr_11.
apply ComposeRepr_21. exact ConsNat_repr.
apply (ConstantRepresented 2).
apply (proj_represented 1 0); apply Nat.le_refl.
apply ComposeRepr_21. exact ConsNat_repr.
apply ComposeRepr_21. exact CoordNat_repr.
apply (proj_represented 1 0); apply Nat.le_refl.
apply (ConstantRepresented 1).
apply ComposeRepr_21. exact ConsNat_repr.
apply ComposeRepr_21. exact CoordNat_repr.
apply (proj_represented 1 0); apply Nat.le_refl.
apply (ConstantRepresented 2).
apply (ConstantRepresented 0).
Qed.
Lemma IsLor_repr : FunctionRepresentedBool 1 IsLor.
Proof.
apply (EqbRepresented 1).
apply (proj_represented 1 0); apply Nat.le_refl.
apply ComposeRepr_11.
apply ComposeRepr_21. exact ConsNat_repr.
apply (ConstantRepresented LorHead).
apply (proj_represented 1 0); apply Nat.le_refl.
apply ComposeRepr_21. exact ConsNat_repr.
apply ComposeRepr_21. exact CoordNat_repr.
apply (proj_represented 1 0); apply Nat.le_refl.
apply (ConstantRepresented 1).
apply ComposeRepr_21. exact ConsNat_repr.
apply ComposeRepr_21. exact CoordNat_repr.
apply (proj_represented 1 0); apply Nat.le_refl.
apply (ConstantRepresented 2).
apply (ConstantRepresented 0).
Qed.
Lemma IsLand_repr : FunctionRepresentedBool 1 IsLand.
Proof.
apply (EqbRepresented 1).
apply (proj_represented 1 0); apply Nat.le_refl.
apply ComposeRepr_11.
apply ComposeRepr_21. exact ConsNat_repr.
apply (ConstantRepresented LandHead).
apply (proj_represented 1 0); apply Nat.le_refl.
apply ComposeRepr_21. exact ConsNat_repr.
apply ComposeRepr_21. exact CoordNat_repr.
apply (proj_represented 1 0); apply Nat.le_refl.
apply (ConstantRepresented 1).
apply ComposeRepr_21. exact ConsNat_repr.
apply ComposeRepr_21. exact CoordNat_repr.
apply (proj_represented 1 0); apply Nat.le_refl.
apply (ConstantRepresented 2).
apply (ConstantRepresented 0).
Qed.
Lemma IsLforall_repr : FunctionRepresentedBool 1 IsLforall.
Proof.
apply (EqbRepresented 1).
apply (proj_represented 1 0); apply Nat.le_refl.
apply ComposeRepr_11.
apply ComposeRepr_21. exact ConsNat_repr.
apply (ConstantRepresented LforallHead).
apply (proj_represented 1 0); apply Nat.le_refl.
apply ComposeRepr_21. exact ConsNat_repr.
apply ComposeRepr_21. exact CoordNat_repr.
apply (proj_represented 1 0); apply Nat.le_refl.
apply (ConstantRepresented 1).
apply ComposeRepr_21. exact ConsNat_repr.
apply ComposeRepr_21. exact CoordNat_repr.
apply (proj_represented 1 0); apply Nat.le_refl.
apply (ConstantRepresented 2).
apply (ConstantRepresented 0).
Qed.
Lemma IsLexists_repr : FunctionRepresentedBool 1 IsLexists.
Proof.
apply (EqbRepresented 1).
apply (proj_represented 1 0); apply Nat.le_refl.
apply ComposeRepr_11.
apply ComposeRepr_21. exact ConsNat_repr.
apply (ConstantRepresented LexistsHead).
apply (proj_represented 1 0); apply Nat.le_refl.
apply ComposeRepr_21. exact ConsNat_repr.
apply ComposeRepr_21. exact CoordNat_repr.
apply (proj_represented 1 0); apply Nat.le_refl.
apply (ConstantRepresented 1).
apply ComposeRepr_21. exact ConsNat_repr.
apply ComposeRepr_21. exact CoordNat_repr.
apply (proj_represented 1 0); apply Nat.le_refl.
apply (ConstantRepresented 2).
apply (ConstantRepresented 0).
Qed.
Lemma IsLrel_repr : FunctionRepresentedBool 1 IsLrel.
Proof.
apply (EqbRepresented 1).
apply (proj_represented 1 0); apply Nat.le_refl.
apply ComposeRepr_11.
apply ComposeRepr_21. exact ConsNat_repr.
apply (ConstantRepresented LrelHead).
apply (proj_represented 1 0); apply Nat.le_refl.
apply ComposeRepr_21. exact ConsNat_repr.
apply ComposeRepr_21. exact CoordNat_repr.
apply (proj_represented 1 0); apply Nat.le_refl.
apply (ConstantRepresented 1).
apply ComposeRepr_11; exact TailNat_repr.
Qed.
Lemma IsLopTerm_repr : FunctionRepresentedBool 2
(fun term previousValues : nat =>
IsLopTerm term (LengthNat term)
(fun i : nat => CoordNat previousValues i =? 1)).
Proof.
apply (FunctionRepresentedBool_ext
2 (fun term previousValues =>
Nat.leb 2 (LengthNat term)
&& AndNat (NthTailNat previousValues 2) (LengthNat term - 2))%bool).
- apply (AndRepresented 2 (fun term _ => Nat.leb 2 (LengthNat term))
(fun term p => AndNat (NthTailNat p 2) (LengthNat term - 2))).
apply (LebRepresented 2 (fun _ _ => 2) (fun t _ => LengthNat t)).
apply (ConstantRepresented 2).
apply ComposeRepr_12. exact LengthNat_repr.
apply (proj_represented 2 0); auto.
apply (ComposeRepr_22 (fun t p => if AndNat t p then 1 else 0)).
exact AndNat_repr.
apply ComposeRepr_12. exact TailNat_repr.
apply ComposeRepr_12. exact TailNat_repr.
apply (proj_represented 2 1); auto.
apply ComposeRepr_22. exact SubtractionRepresented.
apply ComposeRepr_12. exact LengthNat_repr.
apply (proj_represented 2 0); auto.
apply (ConstantRepresented 2).
- intros [term [previousValues n0]].
unfold nuncurry. clear n0.
destruct (Nat.leb 2 (LengthNat term)) eqn:des.
+ apply Nat.leb_le in des. simpl.
assert (forall i j : bool, ((i = true) <-> (j = true)) -> i = j).
{ intros. destruct i,j; try reflexivity.
destruct H. symmetry. apply H. reflexivity.
apply H. reflexivity. }
apply H. clear H. rewrite AndNat_spec.
rewrite IsLopTerm_spec.
split.
intros H. split. exact des. split. exact des.
intros j H0. apply Nat.eqb_eq. specialize (H (j-2)).
destruct H0. destruct j. exfalso; inversion H0.
destruct j. exfalso. apply le_S_n in H0. inversion H0.
simpl in H. rewrite Nat.sub_0_r in H.
rewrite CoordTailNat, CoordTailNat in H. apply H.
destruct (LengthNat term). inversion H1.
destruct n. apply le_S_n in H1. inversion H1.
simpl. rewrite Nat.sub_0_r. apply le_S_n, le_S_n in H1. exact H1.
intros [_ [_ H]] k H0.
rewrite CoordTailNat, CoordTailNat.
apply Nat.eqb_eq, H. split.
apply le_n_S, le_n_S, le_0_n.
destruct (LengthNat term). inversion H0.
destruct n. simpl in H0. inversion H0.
simpl in H0. rewrite Nat.sub_0_r in H0.
apply le_n_S, le_n_S. exact H0.
+ simpl. destruct (LengthNat term). reflexivity.
destruct n. reflexivity.
exfalso. discriminate des.
Qed.
Lemma IsLterm_repr : FunctionRepresentedBool 1 IsLterm.
Proof.
apply TreeFoldNatBool_repr.
unfold IsLtermRec.
apply (FunctionRepresentedBool_ext
2 (fun n previousValues : nat =>
if CoordNat n 0 =? LopHead then
(IsLopTerm n (LengthNat n)
(fun i : nat => CoordNat previousValues i =? 1) &&
(NthTailNat n (LengthNat n) =? 0))%bool
else if CoordNat n 0 =? LvarHead then
IsLvar n
else false)).
apply (IfRepresentedBool 2 (fun i j => CoordNat i 0 =? LopHead)).
apply (EqbRepresented 2).
apply ComposeRepr_22. exact CoordNat_repr.
apply (proj_represented 2 0); auto.
apply (ConstantRepresented 0).
apply (ConstantRepresented 8).
apply (IfRepresentedBool 2
(fun currentStep previousValues : nat =>
IsLopTerm currentStep (LengthNat currentStep)
(fun i : nat => CoordNat previousValues i =? 1))
(fun currentStep previousValues => NthTailNat currentStep (LengthNat currentStep) =? 0)).
exact IsLopTerm_repr.
apply (EqbRepresented 2 (fun currentStep _ : nat => NthTailNat currentStep (LengthNat currentStep))).
apply ComposeRepr_22. exact NthTailNat_repr.
apply (proj_represented 2 0); auto.
apply ComposeRepr_12. exact LengthNat_repr.
apply (proj_represented 2 0); auto.
apply (ConstantRepresented 0).
apply (ConstantRepresented 0).
apply (IfRepresentedBool 2 (fun currentStep _ : nat => CoordNat currentStep 0 =? 9)
(fun currentStep _ => IsLvar currentStep)).
apply (EqbRepresented 2).
apply ComposeRepr_22. exact CoordNat_repr.
apply (proj_represented 2 0); auto.
apply (ConstantRepresented 0).
apply (ConstantRepresented 9).
unfold FunctionRepresentedBool. simpl.
apply (ComposeRepr_12 (fun a => if IsLvar a then 1 else 0)).
exact IsLvar_repr.
apply (proj_represented 2 0); auto.
apply (ConstantRepresented 0).
intros. destruct x, n0. simpl.
destruct (CoordNat n 0). reflexivity. clear n1.
destruct n2. reflexivity.
destruct n2. reflexivity.
destruct n2. reflexivity.
destruct n2. reflexivity.
destruct n2. reflexivity.
destruct n2. reflexivity.
destruct n2. reflexivity.
destruct n2. reflexivity.
destruct n2. reflexivity.
reflexivity.
intros i r s H. unfold IsLtermRec.
destruct (CoordNat i 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.
2: destruct n; reflexivity.
destruct (NthTailNat i (LengthNat i) =? 0).
2: rewrite Bool.andb_false_r, Bool.andb_false_r; reflexivity.
rewrite Bool.andb_true_r, Bool.andb_true_r.
pose proof (IsLopTerm_spec (LengthNat i) i r).
pose proof (IsLopTerm_spec (LengthNat i) i s).
destruct (IsLopTerm i (LengthNat i) r).
symmetry. apply H1.
destruct H0 as [H0 _]. specialize (H0 eq_refl) as [H0 H2].
split. exact H0. split. exact H0.
intros j H3. rewrite <- H. apply H2, H3. apply H3.
destruct (IsLopTerm i (LengthNat i) s). 2: reflexivity.
apply H0.
destruct H1 as [H1 _]. specialize (H1 eq_refl) as [H1 H2].
split. exact H1. split. exact H1.
intros j H3. rewrite H. apply H2, H3. apply H3.
Qed.
Lemma IsLproposition_repr : FunctionRepresentedBool 1 IsLproposition.
Proof.
apply TreeFoldNatBool_repr.
- unfold IsLpropositionRec.
apply (FunctionRepresentedBool_ext
2 (fun n p : nat =>
if CoordNat n 0 =? LnotHead then
IsLnot n && (CoordNat p 1 =? 1)
else if CoordNat n 0 =? LimpliesHead then
IsLimplies n && (CoordNat p 1 =? 1)
&& (CoordNat p 2 =? 1)
else if CoordNat n 0 =? LorHead then
IsLor n && (CoordNat p 1 =? 1)
&& (CoordNat p 2 =? 1)
else if CoordNat n 0 =? LandHead then
IsLand n && (CoordNat p 1 =? 1)
&& (CoordNat p 2 =? 1)
else if CoordNat n 0 =? LforallHead then
IsLforall n && (CoordNat p 2 =? 1)
else if CoordNat n 0 =? LexistsHead then
IsLexists n && (CoordNat p 2 =? 1)
else if CoordNat n 0 =? LrelHead then
IsLrel n && IsLterm (Lop 0 (TailNat (TailNat n)))
else
false)%bool).
+ apply (IfRepresentedBool 2 (fun n _ => CoordNat n 0 =? 1)
(fun n p => IsLnot n && (CoordNat p 1 =? 1)))%bool.
apply (EqbRepresented 2).
apply ComposeRepr_22. exact CoordNat_repr.
apply (proj_represented 2 0); auto.
apply (ConstantRepresented 0).
apply (ConstantRepresented 1).
apply (AndRepresented 2 (fun n _ => IsLnot n) (fun _ p => CoordNat p 1 =? 1)).
apply (ComposeRepr_12 (fun n => if IsLnot n then 1 else 0)).
exact IsLnot_repr.
apply (proj_represented 2 0); auto.
apply (EqbRepresented 2).
apply ComposeRepr_22. exact CoordNat_repr.
apply (proj_represented 2 1); auto.
apply (ConstantRepresented 1).
apply (ConstantRepresented 1).
apply (IfRepresentedBool 2 (fun n _ => CoordNat n 0 =? 2)
(fun n p => (IsLimplies n && (CoordNat p 1 =? 1) && (CoordNat p 2 =? 1))))%bool.
apply (EqbRepresented 2).
apply ComposeRepr_22. exact CoordNat_repr.
apply (proj_represented 2 0); auto.
apply (ConstantRepresented 0).
apply (ConstantRepresented 2).
apply (AndRepresented 2 (fun n p => IsLimplies n && (CoordNat p 1 =? 1))
(fun n p => CoordNat p 2 =? 1))%bool.
apply (AndRepresented 2 (fun n p => IsLimplies n)
(fun n p => CoordNat p 1 =? 1)).
apply (ComposeRepr_12 (fun n => if IsLimplies n then 1 else 0)).
exact IsLimplies_repr.
apply (proj_represented 2 0); auto.
apply (EqbRepresented 2).
apply ComposeRepr_22. exact CoordNat_repr.
apply (proj_represented 2 1); auto.
apply (ConstantRepresented 1).
apply (ConstantRepresented 1).
apply (EqbRepresented 2).
apply ComposeRepr_22. exact CoordNat_repr.
apply (proj_represented 2 1); auto.
apply (ConstantRepresented 2).
apply (ConstantRepresented 1).
apply (IfRepresentedBool 2 (fun n _ => CoordNat n 0 =? LorHead)
(fun n p => (IsLor n && (CoordNat p 1 =? 1) && (CoordNat p 2 =? 1))))%bool.
apply (EqbRepresented 2).
apply ComposeRepr_22. exact CoordNat_repr.
apply (proj_represented 2 0); auto.
apply (ConstantRepresented 0).
apply (ConstantRepresented LorHead).
apply (AndRepresented 2 (fun n p => IsLor n && (CoordNat p 1 =? 1))
(fun n p => CoordNat p 2 =? 1))%bool.
apply (AndRepresented 2 (fun n p => IsLor n)
(fun n p => CoordNat p 1 =? 1)).
apply (ComposeRepr_12 (fun n => if IsLor n then 1 else 0)).
exact IsLor_repr.
apply (proj_represented 2 0); auto.
apply (EqbRepresented 2).
apply ComposeRepr_22. exact CoordNat_repr.
apply (proj_represented 2 1); auto.
apply (ConstantRepresented 1).
apply (ConstantRepresented 1).
apply (EqbRepresented 2).
apply ComposeRepr_22. exact CoordNat_repr.
apply (proj_represented 2 1); auto.
apply (ConstantRepresented 2).
apply (ConstantRepresented 1).
apply (IfRepresentedBool 2 (fun n _ => CoordNat n 0 =? LandHead)
(fun n p => (IsLand n && (CoordNat p 1 =? 1) && (CoordNat p 2 =? 1))))%bool.
apply (EqbRepresented 2).
apply ComposeRepr_22. exact CoordNat_repr.
apply (proj_represented 2 0); auto.
apply (ConstantRepresented 0).
apply (ConstantRepresented LandHead).
apply (AndRepresented 2 (fun n p => IsLand n && (CoordNat p 1 =? 1))
(fun n p => CoordNat p 2 =? 1))%bool.
apply (AndRepresented 2 (fun n p => IsLand n)
(fun n p => CoordNat p 1 =? 1)).
apply (ComposeRepr_12 (fun n => if IsLand n then 1 else 0)).
exact IsLand_repr.
apply (proj_represented 2 0); auto.
apply (EqbRepresented 2).
apply ComposeRepr_22. exact CoordNat_repr.
apply (proj_represented 2 1); auto.
apply (ConstantRepresented 1).
apply (ConstantRepresented 1).
apply (EqbRepresented 2).
apply ComposeRepr_22. exact CoordNat_repr.
apply (proj_represented 2 1); auto.
apply (ConstantRepresented 2).
apply (ConstantRepresented 1).
apply (IfRepresentedBool 2 (fun n _ => CoordNat n 0 =? LforallHead)
(fun n p => (IsLforall n && (CoordNat p 2 =? 1))))%bool.
apply (EqbRepresented 2).
apply ComposeRepr_22. exact CoordNat_repr.
apply (proj_represented 2 0); auto.
apply (ConstantRepresented 0).
apply (ConstantRepresented LforallHead).
apply (AndRepresented 2 (fun n p => IsLforall n)
(fun n p => CoordNat p 2 =? 1))%bool.
apply (ComposeRepr_12 (fun n => if IsLforall n then 1 else 0)).
exact IsLforall_repr.
apply (proj_represented 2 0); auto.
apply (EqbRepresented 2).
apply ComposeRepr_22. exact CoordNat_repr.
apply (proj_represented 2 1); auto.
apply (ConstantRepresented 2).
apply (ConstantRepresented 1).
apply (IfRepresentedBool 2 (fun n _ => CoordNat n 0 =? LexistsHead)
(fun n p => (IsLexists n && (CoordNat p 2 =? 1))))%bool.
apply (EqbRepresented 2).
apply ComposeRepr_22. exact CoordNat_repr.
apply (proj_represented 2 0); auto.
apply (ConstantRepresented 0).
apply (ConstantRepresented LexistsHead).
apply (AndRepresented 2 (fun n p => IsLexists n)
(fun n p => CoordNat p 2 =? 1))%bool.
apply (ComposeRepr_12 (fun n => if IsLexists n then 1 else 0)).
exact IsLexists_repr.
apply (proj_represented 2 0); auto.
apply (EqbRepresented 2).
apply ComposeRepr_22. exact CoordNat_repr.
apply (proj_represented 2 1); auto.
apply (ConstantRepresented 2).
apply (ConstantRepresented 1).
apply (IfRepresentedBool 2 (fun n _ => CoordNat n 0 =? LrelHead)
(fun n p => (IsLrel n && IsLterm (Lop 0 (TailNat (TailNat n))))))%bool.
apply (EqbRepresented 2).
apply ComposeRepr_22. exact CoordNat_repr.
apply (proj_represented 2 0); auto.
apply (ConstantRepresented 0).
apply (ConstantRepresented LrelHead).
apply (AndRepresented 2 (fun n p => IsLrel n)
(fun n p => IsLterm (Lop 0 (TailNat (TailNat n)))))%bool.
apply (ComposeRepr_12 (fun n => if IsLrel n then 1 else 0)).
exact IsLrel_repr.
apply (proj_represented 2 0); auto.
apply (ComposeRepr_12 (fun n => if IsLterm n then 1 else 0)).
exact IsLterm_repr.
apply ComposeRepr_22.
exact Lop_repr.
apply (ConstantRepresented 0).
apply ComposeRepr_12. exact TailNat_repr.
apply ComposeRepr_12. exact TailNat_repr.
apply (proj_represented 2 0); auto.
apply (ConstantRepresented 0).
+ intros [n [p n0]]. simpl. clear n0.
destruct (CoordNat n 0) eqn:des. reflexivity.
destruct n0. reflexivity.
destruct n0. reflexivity.
destruct n0. reflexivity.
destruct n0. reflexivity.
destruct n0. reflexivity.
destruct n0. reflexivity.
destruct n0; reflexivity.
- intros. unfold IsLpropositionRec.
destruct (CoordNat n 0) eqn:des. reflexivity.
destruct n0.
destruct (IsLnot n) eqn:isnot. 2: reflexivity.
rewrite H. reflexivity.
apply Nat.eqb_eq in isnot.
rewrite isnot, LengthLnot. apply Nat.le_refl.
destruct n0.
destruct (IsLimplies n) eqn:isimplies. 2: reflexivity.
apply Nat.eqb_eq in isimplies.
rewrite H, H. reflexivity.
rewrite isimplies, LengthLimplies. apply Nat.le_refl.
rewrite isimplies, LengthLimplies. auto.
destruct n0.
destruct (IsLor n) eqn:isimplies. 2: reflexivity.
apply Nat.eqb_eq in isimplies.
rewrite H, H. reflexivity.
rewrite isimplies, LengthLor. apply Nat.le_refl.
rewrite isimplies, LengthLor. auto.
destruct n0.
destruct (IsLand n) eqn:isimplies. 2: reflexivity.
apply Nat.eqb_eq in isimplies.
rewrite H, H. reflexivity.
rewrite isimplies, LengthLand. apply Nat.le_refl.
rewrite isimplies, LengthLand. auto.
destruct n0.
destruct (IsLforall n) eqn:isimplies. 2: reflexivity.
apply Nat.eqb_eq in isimplies.
rewrite H. reflexivity.
rewrite isimplies, LengthLforall. apply Nat.le_refl.
destruct n0.
destruct (IsLexists n) eqn:isimplies. 2: reflexivity.
apply Nat.eqb_eq in isimplies.
rewrite H. reflexivity.
rewrite isimplies, LengthLexists. apply Nat.le_refl.
destruct n0; reflexivity.
Qed.
Lemma RangeNat_repr : FunctionRepresented 2 RangeNat.
Proof.
pose (fun start currentStep val
=> ConcatNat val (ConsNat (currentStep+start) NilNat)) as f.
apply (FunctionRepresented_2_ext (fun start => nat_rec (fun _ => nat) NilNat (f start))).
- apply (ComposeRepr_32 (fun param init => nat_rec (fun _ => nat) init (f param))).
apply nat_rec_param_repr.
unfold f.
apply ComposeRepr_23. exact ConcatNat_repr.
apply (proj_represented 3 2); auto.
apply ComposeRepr_23. exact ConsNat_repr.
apply ComposeRepr_23. exact AdditionRepresented.
apply (proj_represented 3 1); auto.
apply (proj_represented 3 0); auto.
apply (ConstantRepresented 0).
apply (proj_represented 2 0); auto.
apply (ConstantRepresented 0).
apply (proj_represented 2 1); auto.
- intro start. induction k. reflexivity.
simpl. rewrite IHk. clear IHk.
unfold f.
apply TruncatedEqNat.
rewrite LengthConcatNat, LengthRangeNat, LengthConsNat, LengthConsNat.
rewrite LengthRangeNat, Nat.add_comm. reflexivity.
rewrite LengthConcatNat, NthTailConcatNat.
rewrite LengthConsNat, LengthConsNat, LengthRangeNat.
change (LengthNat NilNat) with 0.
simpl. rewrite TailConsNat, TailConsNat.
rewrite RangeNatTruncated. reflexivity.
intros i H.
rewrite LengthConcatNat, LengthRangeNat, LengthConsNat in H.
rewrite Nat.add_comm in H.
change (LengthNat NilNat) with 0 in H. simpl in H.
change (ConsNat start (RangeNat (S start) k)) with (RangeNat start (S k)).
apply Nat.le_succ_r in H. destruct H.
rewrite CoordConcatNatFirst.
rewrite CoordRangeNat, CoordRangeNat. reflexivity.
apply le_n_S. apply (Nat.le_trans _ (S i)).
apply le_S, Nat.le_refl. exact H. exact H.
rewrite LengthRangeNat. exact H.
inversion H. subst k.
replace i with (0+LengthNat (RangeNat start i)) at 3.
rewrite CoordConcatNatSecond.
rewrite CoordConsHeadNat, CoordRangeNat, Nat.add_comm. reflexivity.
apply Nat.le_refl. rewrite LengthRangeNat. reflexivity.
Qed.
Lemma SubstLopTerm_repr : FunctionRepresented 2
(fun n previousValues : nat =>
Lop (CoordNat n 1)
(MapNat (CoordNat previousValues) (RangeNat 2 (LengthNat n - 2)))).
Proof.
apply ComposeRepr_22. exact Lop_repr.
apply ComposeRepr_22. exact CoordNat_repr.
apply (proj_represented 2 0); auto.
apply (ConstantRepresented 1).
apply (ComposeRepr_22 (fun n => MapNat (CoordNat n))
(fun u v => v)
(fun u v => RangeNat 2 (LengthNat u - 2))).
apply MapNat_repr. exact CoordNat_repr.
apply (proj_represented 2 1). auto.
apply ComposeRepr_22. exact RangeNat_repr.
apply (ConstantRepresented 2).
apply ComposeRepr_22. exact SubtractionRepresented.
apply ComposeRepr_12. exact LengthNat_repr.
apply (proj_represented 2 0). auto.
apply (ConstantRepresented 2).
Qed.
Lemma SubstTerm_repr : FunctionRepresented 3 SubstTerm.
Proof.
apply (FunctionRepresented_3_ext
(@ncompose 2 3
(fun param => TreeFoldNat (SubstTermRec (diagX param) (diagY param)) O)
(fun k => match k with
| O => fun u v f => diagMerge u v
| _ => fun u v f => f
end))).
- apply ComposeRepr_n.
apply TreeFoldNat_repr_2.
+ unfold SubstTermRec.
apply (FunctionRepresented_3_ext
(fun param n previousValues =>
if CoordNat n 0 =? LopHead then
Lop (CoordNat n 1)
(MapNat (CoordNat previousValues) (RangeNat 2 (LengthNat n - 2)))
else if CoordNat n 0 =? LvarHead then
if CoordNat n 1 =? diagY param then diagX param else n
else 0)).
apply (IfRepresented 3 (fun param n previousValues => CoordNat n 0 =? LopHead)
(fun _ n previousValues => Lop (CoordNat n 1)
(MapNat (CoordNat previousValues) (RangeNat 2 (LengthNat n - 2))))).
apply (EqbRepresented 3).
apply ComposeRepr_23. exact CoordNat_repr.
apply (proj_represented 3 1); auto.
apply (ConstantRepresented 0).
apply (ConstantRepresented LopHead).
apply (ComposeRepr_23
(fun n previousValues : nat =>
Lop (CoordNat n 1)
(MapNat (CoordNat previousValues) (RangeNat 2 (LengthNat n - 2))))).
exact SubstLopTerm_repr.
apply (proj_represented 3 1); auto.
apply (proj_represented 3 2); auto.
apply (IfRepresented 3 (fun param n _ => CoordNat n 0 =? LvarHead)).
apply (EqbRepresented 3).
apply ComposeRepr_23. exact CoordNat_repr.
apply (proj_represented 3 1); auto.
apply (ConstantRepresented 0).
apply (ConstantRepresented LvarHead).
apply (IfRepresented 3 (fun param n _ => CoordNat n 1 =? diagY param)).
apply (EqbRepresented 3).
apply ComposeRepr_23. exact CoordNat_repr.
apply (proj_represented 3 1); auto.
apply (ConstantRepresented 1).
apply ComposeRepr_13. exact diagY_repr.
apply (proj_represented 3 0); auto.
apply ComposeRepr_13. exact diagX_repr.
apply (proj_represented 3 0); auto.
apply (proj_represented 3 1); auto.
apply (ConstantRepresented 0).
intros i j k. simpl.
destruct (CoordNat j 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. reflexivity.
reflexivity.
+ intros. unfold SubstTermRec.
destruct (CoordNat n 0). reflexivity.
destruct n0. reflexivity.
destruct n0. reflexivity.
destruct n0. reflexivity.
destruct n0. reflexivity.
destruct n0. reflexivity.
destruct n0. reflexivity.
destruct n0. reflexivity.
destruct n0. 2: reflexivity.
apply f_equal.
apply MapNatExt. intros. rewrite LengthRangeNat in H0.
rewrite H. reflexivity.
rewrite CoordRangeNat. 2: exact H0.
destruct (LengthNat n). simpl in H0. inversion H0.
destruct n0. simpl in H0. inversion H0.
simpl. simpl in H0. rewrite Nat.sub_0_r in H0.
apply le_n_S, le_n_S. exact H0.
+ intros [|k].
apply ComposeRepr_23. exact diagMerge_repr.
apply (proj_represented 3 0); auto.
apply (proj_represented 3 1); auto.
apply (proj_represented 3 2); auto.
- intros u v t. simpl. rewrite diagYMergeId, diagXMergeId. reflexivity.
Qed.
Lemma strangeDiag_repr : forall v : nat,
FunctionRepresented 3
(fun i j k : nat => diagY (CoordNat k (diagMerge i (CoordNat j v)))).
Proof.
intro v.
apply ComposeRepr_13. exact diagY_repr.
apply ComposeRepr_23. exact CoordNat_repr.
apply (proj_represented 3 2); auto.
apply ComposeRepr_23. exact diagMerge_repr.
apply (proj_represented 3 0); auto.
apply ComposeRepr_23. exact CoordNat_repr.
apply (proj_represented 3 1); auto.
apply (ConstantRepresented v).
Qed.
Lemma SubstTerms_repr : FunctionRepresented 3 (fun i j k => MapNat (SubstTerm i j) k).
Proof.
apply (FunctionRepresented_3_ext
(@ncompose 2 3
(fun i_j k => MapNat (SubstTerm (diagX i_j) (diagY i_j)) k)
(fun k => match k with
| O => fun i j k => diagMerge i j
| _ => fun i j k => k
end))).
- apply ComposeRepr_n.
apply MapNat_repr.
apply ComposeRepr_32. exact SubstTerm_repr.
apply ComposeRepr_12. exact diagX_repr.
apply (proj_represented 2 0); auto.
apply ComposeRepr_12. exact diagY_repr.
apply (proj_represented 2 0); auto.
apply (proj_represented 2 1); auto.
intros [|k].
apply ComposeRepr_23. exact diagMerge_repr.
apply (proj_represented 3 0); auto.
apply (proj_represented 3 1); auto.
apply (proj_represented 3 2); auto.
- intros. simpl. rewrite diagXMergeId, diagYMergeId. reflexivity.
Qed.
Lemma Subst_repr : FunctionRepresented 3 Subst.
Proof.
apply (FunctionRepresented_3_ext
(@ncompose 2 3
(fun param => TreeFoldNat (SubstRec (diagX param) (diagY param)) O)
(fun k => match k with
| O => fun u v f => diagMerge u v
| _ => fun u v f => f
end))).
2: intros u v t; simpl; rewrite diagYMergeId, diagXMergeId; reflexivity.
apply ComposeRepr_n.
apply TreeFoldNat_repr_2_ill_formed.
- unfold SubstRec.
apply (FunctionRepresented_3_ext
(fun param n k =>
if CoordNat n 0 =? LnotHead then
Lnot (diagY (CoordNat k (diagMerge param (CoordNat n 1))))
else if CoordNat n 0 =? LimpliesHead then
Limplies (diagY (CoordNat k (diagMerge param (CoordNat n 1))))
(diagY (CoordNat k (diagMerge param (CoordNat n 2))))
else if CoordNat n 0 =? LorHead then
Lor (diagY (CoordNat k (diagMerge param (CoordNat n 1))))
(diagY (CoordNat k (diagMerge param (CoordNat n 2))))
else if CoordNat n 0 =? LandHead then
Land (diagY (CoordNat k (diagMerge param (CoordNat n 1))))
(diagY (CoordNat k (diagMerge param (CoordNat n 2))))
else if CoordNat n 0 =? LforallHead then
Lforall (CoordNat n 1)
(if CoordNat n 1 =? diagY param
then CoordNat n 2
else diagY (CoordNat k (diagMerge param (CoordNat n 2))))
else if CoordNat n 0 =? LexistsHead then
Lexists (CoordNat n 1)
(if CoordNat n 1 =? diagY param
then CoordNat n 2
else diagY (CoordNat k (diagMerge param (CoordNat n 2))))
else if CoordNat n 0 =? LrelHead then
Lrel (CoordNat n 1)
(MapNat (SubstTerm (diagX param) (diagY param)) (TailNat (TailNat n)))
else 0)).
apply (IfRepresented 3 (fun p n pr => CoordNat n 0 =? LnotHead)).
apply (EqbRepresented 3).
apply ComposeRepr_23. exact CoordNat_repr.
apply (proj_represented 3 1); auto.
apply (ConstantRepresented 0).
apply (ConstantRepresented 1).
apply ComposeRepr_23. exact ConsNat_repr.
apply (ConstantRepresented 1).
apply ComposeRepr_23. exact ConsNat_repr.
apply strangeDiag_repr.
apply (ConstantRepresented 0).
apply (IfRepresented 3 (fun p n pr => CoordNat n 0 =? LimpliesHead)).
apply (EqbRepresented 3).
apply ComposeRepr_23. exact CoordNat_repr.
apply (proj_represented 3 1); auto.
apply (ConstantRepresented 0).
apply (ConstantRepresented 2).
apply ComposeRepr_23. exact ConsNat_repr.
apply (ConstantRepresented 2).
apply ComposeRepr_23. exact ConsNat_repr.
apply strangeDiag_repr.
apply ComposeRepr_23. exact ConsNat_repr.
apply strangeDiag_repr.
apply (ConstantRepresented 0).
apply (IfRepresented 3 (fun p n pr => CoordNat n 0 =? LorHead)).
apply (EqbRepresented 3).
apply ComposeRepr_23. exact CoordNat_repr.
apply (proj_represented 3 1); auto.
apply (ConstantRepresented 0).
apply (ConstantRepresented 3).
apply ComposeRepr_23. exact ConsNat_repr.
apply (ConstantRepresented 3).
apply ComposeRepr_23. exact ConsNat_repr.
apply strangeDiag_repr.
apply ComposeRepr_23. exact ConsNat_repr.
apply strangeDiag_repr.
apply (ConstantRepresented 0).
apply (IfRepresented 3 (fun p n pr => CoordNat n 0 =? LandHead)).
apply (EqbRepresented 3).
apply ComposeRepr_23. exact CoordNat_repr.
apply (proj_represented 3 1); auto.
apply (ConstantRepresented 0).
apply (ConstantRepresented 4).
apply ComposeRepr_23. exact ConsNat_repr.
apply (ConstantRepresented 4).
apply ComposeRepr_23. exact ConsNat_repr.
apply strangeDiag_repr.
apply ComposeRepr_23. exact ConsNat_repr.
apply strangeDiag_repr.
apply (ConstantRepresented 0).
apply (IfRepresented 3 (fun p n pr => CoordNat n 0 =? LforallHead)).
apply (EqbRepresented 3).
apply ComposeRepr_23. exact CoordNat_repr.
apply (proj_represented 3 1); auto.
apply (ConstantRepresented 0).
apply (ConstantRepresented 5).
apply ComposeRepr_23. exact ConsNat_repr.
apply (ConstantRepresented 5).
apply ComposeRepr_23. exact ConsNat_repr.
apply ComposeRepr_23. exact CoordNat_repr.
apply (proj_represented 3 1); auto.
apply (ConstantRepresented 1).
apply ComposeRepr_23. exact ConsNat_repr.
apply (IfRepresented 3 (fun i j k => CoordNat j 1 =? diagY i)).
apply (EqbRepresented 3).
apply ComposeRepr_23. exact CoordNat_repr.
apply (proj_represented 3 1); auto.
apply (ConstantRepresented 1).
apply ComposeRepr_13. exact diagY_repr.
apply (proj_represented 3 0); auto.
apply ComposeRepr_23. exact CoordNat_repr.
apply (proj_represented 3 1); auto.
apply (ConstantRepresented 2).
apply strangeDiag_repr.
apply (ConstantRepresented 0).
apply (IfRepresented 3 (fun p n pr => CoordNat n 0 =? LexistsHead)).
apply (EqbRepresented 3).
apply ComposeRepr_23. exact CoordNat_repr.
apply (proj_represented 3 1); auto.
apply (ConstantRepresented 0).
apply (ConstantRepresented 6).
apply ComposeRepr_23. exact ConsNat_repr.
apply (ConstantRepresented 6).
apply ComposeRepr_23. exact ConsNat_repr.
apply ComposeRepr_23. exact CoordNat_repr.
apply (proj_represented 3 1); auto.
apply (ConstantRepresented 1).
apply ComposeRepr_23. exact ConsNat_repr.
apply (IfRepresented 3 (fun i j k => CoordNat j 1 =? diagY i)).