-
Notifications
You must be signed in to change notification settings - Fork 0
/
fundamental.v
3964 lines (3720 loc) · 83.7 KB
/
fundamental.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
From Coq Require Import ssreflect ssrfun ssrbool.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Require Export Coq.Classes.Init.
Require Import Coq.Program.Basics.
Require Import Coq.Program.Tactics.
Require Import Coq.Relations.Relation_Definitions.
Require Import Coq.Logic.JMeq.
Require Import Coq.Init.Specif.
Require Import Coq.Classes.SetoidClass.
Require Import Coq.Logic.FinFun.
Require Import FunInd.
Require Import Coq.Arith.Div2.
Require Import Coq.Arith.PeanoNat.
Require Import Coq.Init.Nat.
Require Import Coq.Arith.Wf_nat.
Require Import Coq.Vectors.Fin.
Require Import Coq.Lists.Streams.
Require Import Coq.Lists.Streams.
Notation "x ** y" := (prod x y) (at level 90, left associativity) : type_scope.
Notation "H ´ 1" := (fst H) (at level 10, left associativity).
Notation "H ´ 2" := (snd H) (at level 10, left associativity).
Require Import Coq.Lists.List.
Require Import Coq.Arith.Compare_dec.
Require Import Coq.Init.Nat.
Require Import Psatz.
Definition divisible (x : nat) (a : nat) := {b : nat | a * b = x}.
Definition indivisible (x : nat) (a : nat) := divisible x a -> False.
Definition prime (x : nat) := {y & y <> x ** y <> 1 ** divisible x y} -> False.
Definition composite (x : nat) := prime x -> False.
Axiom div_2 : forall (x : nat), {y & y.1 >= 2 /\ y.2 >= 2 /\ y.1 * y.2 = x}.
Inductive Totally {A : Type} :=
|Total : A -> Totally
|Partial : Totally.
Fixpoint div' x y z c {struct z} :=
match z with
| 0 => Partial
| S y' => if (x =? c*y) then Total c else (div' x y y' (S c))
end.
Fixpoint div2' x y z {struct z} :=
match z with
| 0 => Partial
| S y' => if (x =? y'*y) then Total y' else (div2' x y y')
end.
Definition div (x y : nat) := div' x y x 1.
Definition div2 (x y : nat) := div2' x y (S x).
Export ListNotations.
Fixpoint get_factors x z :=
match z with
|0 => []
|S n => match (div2 x (S n)) with
| Total _ => cons (S n) (get_factors x n)
| Partial => get_factors x n
end
end.
Definition prime_dec (x : nat) : bool := length (get_factors x x) =? 2.
Theorem sum_less : forall y z x, S y + S z = x -> S y <= x /\ S z <= x.
intros;lia.
Qed.
Definition strong_relation : forall x, {h | x <= h}.
intros.
by exists x.
Defined.
Theorem div_less : forall x y z, S y * S z = x -> S y <= x /\ S z <= x.
intro.
destruct(strong_relation x).
move => H'.
destruct H'.
induction x0.
intros.
destruct x.
inversion H.
inversion l.
intros.
lia.
intros.
have : forall y z, S y <= S y * S z.
intros.
induction y.
simpl.
destruct z0.
auto.
auto with arith.
lia.
move => H1.
subst.
constructor.
apply : H1.
rewrite PeanoNat.Nat.mul_comm.
apply : H1.
Qed.
Definition _1_prime_not_prime : ~ (prime 1 \/ ~ prime 1).
Admitted.
Definition _2prime : prime 2.
move => H.
destruct H.
destruct p.
destruct p.
destruct x.
destruct d.
inversion e.
destruct d.
destruct x.
intuition.
destruct x.
intuition.
destruct x0.
rewrite PeanoNat.Nat.mul_0_r in e.
inversion e.
destruct (div_less e).
inversion H.
inversion H2.
inversion H4.
Qed.
Definition isPartial {A} (x : @Totally A) :=
match x with
|Total _ => False
|Partial => True
end.
Definition isTotal {A} (x : @Totally A) :=
match x with
|Total _ => True
|Partial => False
end.
Definition proj_total {A} {x : @Totally A} : isTotal x -> A :=
match x as c return isTotal c -> A with
|Total y => fun _ => y
|Partial => fun (v : False) => match v with end
end.
Theorem ind_by_2 (P : nat -> Prop) (H : P 2) (H1 : forall x, P (S (S (S x)))) : forall x, x >= 2 -> P x.
move => x I.
elim/@ind_0_1_SS : x I.
move => H'; inversion H'.
move => H'; inversion H'; inversion H2.
intros.
destruct n.
exact H.
apply : H1.
Defined.
Theorem dif_eq : forall x y, x <> y -> x =? y = false.
intros.
elim/@nat_double_ind : x/y H.
intros.
destruct n.
intuition.
trivial.
intros.
trivial.
intros.
have : forall n m, S n <> S m -> n <> m.
intros.
lia.
move => H2.
exact (H (H2 _ _ H0)).
Qed.
Theorem reflexivity_div : forall x, x > 0 -> isTotal (div x x).
case.
intros.
inversion H.
intros.
unfold div.
unfold div'.
rewrite Nat.mul_1_l.
by rewrite Nat.eqb_refl.
Qed.
Theorem mult_discrimate : forall x y c, y > S x -> ~ c * y = S x.
intros.
move => H'.
destruct c.
inversion H'.
destruct y.
by rewrite Nat.mul_comm in H'.
destruct (div_less H').
lia.
Qed.
Theorem discr0 : forall x y, 0 = x * y -> x = 0 \/ y = 0.
intros.
destruct x.
by left.
right.
by destruct y.
Qed.
Theorem discrS : forall x y z, S z = x * y -> x > 0 /\ y > 0.
intros.
destruct x.
inversion H.
destruct y.
rewrite Nat.mul_comm in H.
inversion H.
auto with arith.
Qed.
Theorem eq_rel : forall x y, x =? y = true -> x = y.
intros.
elim/@nat_double_ind : x/y H.
intros; by destruct n.
intros; inversion H.
intros; auto.
Qed.
Theorem eq_rel_false : forall x y, x =? y = false -> x <> y.
intros.
elim/@nat_double_ind : x/y H.
intros; by destruct n.
intros; auto.
intros; auto.
Qed.
Theorem false_eq_rel : forall x y, x <> y -> x =? y = false.
intros.
elim/@nat_double_ind : x/y H.
intros; by destruct n.
intros; auto.
intros; auto.
Qed.
Theorem refl_nat_dec : forall x, x =? x.
intros.
by induction x.
Qed.
Theorem symm_nat_dec : forall x y b, x =? y = b -> y =? x = b.
intros.
destruct b.
rewrite (eq_rel H).
by apply : refl_nat_dec.
pose (eq_rel_false H).
remember (y =? x).
destruct b.
pose (eq_rel (eq_sym Heqb)).
intuition.
trivial.
Qed.
Theorem le_dec : forall x y, x <=? y = true -> x <= y.
intros.
elim/@nat_double_ind : x/y H.
intros.
auto with arith.
intros.
inversion H.
intros.
apply : le_n_S.
by apply : H.
Qed.
Theorem dec_le : forall x y, x <= y -> x <=? y = true.
intros.
elim/@nat_double_ind : x/y H.
intros.
auto with arith.
intros.
inversion H.
intros.
apply le_S_n in H0.
by apply : H.
Qed.
Theorem le_dec_false : forall x y, x <=? y = false -> y <= x.
intros.
elim/@nat_double_ind : x/y H.
intros.
destruct n.
auto with arith.
inversion H.
intros.
auto with arith.
intros.
apply : le_n_S.
by apply : H.
Qed.
Theorem partially_between_le : forall x y z, y > S x -> isPartial (div2' (S x) y z).
intros.
generalize dependent y.
generalize dependent z.
induction z.
intros.
by simpl.
intros.
unfold div2'.
pose (@mult_discrimate _ _ z H).
have : S x <> z * y.
auto.
move => e.
rewrite (dif_eq e).
by apply : IHz.
Qed.
Require Import Coq.Logic.FinFun.
Theorem injection_plus : forall z, Injective (fun x => z+x).
unfold Injective.
elim.
easy.
intros.
apply : H.
simpl in H0.
by inversion H0.
Qed.
Theorem ant_mul : forall z x y, x * S z = y * S z -> z * x = z * y.
intros.
elim/@nat_double_ind : x/y H.
intros.
destruct n.
trivial.
inversion H.
intros.
inversion H.
intros.
lia.
Qed.
Theorem injective_mult : forall z, Injective (fun x => (S z)*x).
intros.
unfold Injective.
intros.
replace (S z * x) with (x * S z).
replace (S z * y) with (y * S z).
elim/@nat_double_ind : x/y H.
intros.
destruct n.
trivial.
rewrite Nat.mul_comm in H.
inversion H.
intros.
symmetry in H; rewrite Nat.mul_comm in H.
inversion H.
intros.
lia.
auto with arith.
auto with arith.
Qed.
Ltac Symmetry_Op H := rewrite Nat.mul_comm in H; symmetry in H; rewrite Nat.mul_comm in H; symmetry in H.
Theorem induction_div_to_definition : forall x y z, isTotal (div2' (S x) y z) -> divisible (S x) y.
intros.
generalize dependent x.
generalize dependent y.
induction z.
intros.
inversion H.
intros.
unfold div2' in H.
destruct (Nat.eq_dec (S x) (z * y)).
exists z.
by rewrite Nat.mul_comm in e.
rewrite (dif_eq n) in H.
apply : IHz.
exact H.
Qed.
Theorem divisor_le : forall x y z (H : isTotal (div2' (S x) y z)),
proj_total H < z.
intros.
generalize dependent x.
generalize dependent y.
induction z.
intros.
inversion H.
intros.
remember ( (div2' (S x) y (S z))).
destruct t.
unfold div2' in Heqt.
destruct (S x =? z * y).
move : H.
rewrite Heqt.
auto with arith.
move : H.
rewrite Heqt.
move => H.
pose (IHz _ _ H).
auto with arith.
inversion H.
Qed.
Theorem divisor_le' : forall x y z (H : isTotal (div2' x (S y) z)),
x < (S y)*z.
intros.
generalize dependent x.
generalize dependent y.
induction z.
intros.
inversion H.
intros.
unfold div2' in H.
remember (x =? z * S y).
destruct b.
rewrite (eq_rel (eq_sym Heqb)).
lia.
pose (IHz _ _ H).
lia.
Qed.
Theorem divisor_uniquess_ind : forall x y z (H : isTotal (div2' (S x) y z)),
div2' (S x) y z = div2' (S x) y (S z).
intros.
generalize dependent x.
generalize dependent y.
induction z.
intros.
inversion H.
intros.
unfold div2'.
destruct z.
simpl.
inversion H.
destruct y.
simpl.
rewrite Nat.mul_comm.
by simpl.
simpl.
remember (x =? y + z * S y).
remember (x =? y + S (y + z * S y)).
destruct b.
destruct b0.
pose (eq_rel (eq_sym Heqb)).
pose (eq_rel (eq_sym Heqb0)).
move : e.
rewrite e0.
move => H'.
lia.
trivial.
destruct b0.
pose (divisor_le' H).
pose (eq_rel (eq_sym Heqb0)).
move : l.
rewrite e.
move => H'.
simpl in H'.
lia.
trivial.
Qed.
Theorem divisor_uniquess : forall x y z z' (H : isTotal (div2' (S x) y z)), z <= z' ->
div2' (S x) y z = div2' (S x) y z'.
intros.
have : forall x z y n, isTotal(div2' (S x) y z) -> isTotal(div2' (S x) y (z + n)).
intros.
assert(forall y z x, isTotal(div2' (S x) y z) -> isTotal(div2' (S x) y (S z))).
intros.
induction z1.
inversion H2.
unfold div2'.
destruct (S x1 =? S z1 * y1).
constructor.
apply : H2.
induction n.
by rewrite <- plus_n_O.
rewrite <- Plus.plus_Snm_nSm.
apply : H2.
apply : IHn.
move => H2.
have : z' = z + (z' - z).
lia.
move => H'.
rewrite H'.
clear H'.
generalize dependent (z' - z).
clear H0.
generalize dependent H.
induction n.
by rewrite <- plus_n_O.
rewrite IHn.
rewrite <- Plus.plus_Snm_nSm.
apply : divisor_uniquess_ind.
apply : H2.
exact H.
Qed.
Theorem definition_div_to_induction' : forall x y (H : divisible (S x) y), isTotal (div2' (S x) y (S (proj1_sig H))).
intros.
destruct H.
generalize dependent x.
generalize dependent y.
induction x0.
intros; simpl.
rewrite Nat.mul_comm in e.
inversion e.
intros.
simpl.
rewrite Nat.mul_comm in e.
simpl in e.
rewrite e.
by rewrite refl_nat_dec.
Qed.
Theorem definition_div_to_induction : forall x y, divisible (S x) y -> isTotal (div2 (S x) y).
intros.
pose (definition_div_to_induction' H).
have : S (sval H) <= S (S x).
destruct H.
simpl.
destruct x0.
auto with arith.
destruct y.
inversion e.
destruct (div_less e).
auto with arith.
move => H'.
unfold div2.
by rewrite <- (divisor_uniquess i H').
Qed.
Theorem definition_div_to_false_ind : forall x y, isPartial (div2 (S x) y) -> indivisible (S x) y.
intros.
move => HI.
have : forall x y, isPartial (div2 (S x) y) -> ~ isTotal(div2 (S x) y).
move => H'.
intros.
destruct (div2 (S H') y0).
inversion H0.
move => H2.
inversion H2.
move => H'.
destruct (H' x y H).
clear H'.
by apply : definition_div_to_induction.
Qed.
Theorem definition_div_to_false_ind' : forall x y, indivisible (S x) y -> isPartial (div2 (S x) y).
intros.
have : forall x y, ~ isTotal(div2 (S x) y) -> isPartial (div2 (S x) y).
move => H'.
intros.
destruct (div2 (S H') y0).
by contradiction H0.
easy.
move => H'.
apply : H'.
move => H'.
by pose(induction_div_to_definition H').
Qed.
Theorem Decibility_division : forall x y, divisible (S x) y + {indivisible (S x) y}.
intros.
set (div2 (S x) y).
remember (div2 (S x) y).
destruct t0.
left.
apply : (@induction_div_to_definition _ _ (S (S x))).
unfold div2 in Heqt0.
by destruct (div2' (S x) y (S (S x))).
right.
apply : definition_div_to_false_ind.
by destruct (div2 (S x) y).
Qed.
Theorem list_factors_inhabited : forall x z h, In h (get_factors x z) -> divisible x h.
intros.
destruct x.
by exists 0.
apply : (@induction_div_to_definition _ _ (S (S x))).
induction z.
inversion H.
simpl in H.
set (div2 (S x) (S z)).
remember (div2 (S x) (S z)).
destruct t0.
simpl in H.
destruct H.
assert(isTotal (div2 (S x) (S z))).
by rewrite <- Heqt0.
rewrite <- H.
by [].
by apply : IHz.
by apply : IHz.
Qed.
Theorem le_factors_inhabited : forall x z h, h <= z -> divisible (S x) h -> In h (get_factors (S x) z) .
intros.
generalize dependent x.
generalize dependent h.
induction z.
intros.
destruct h.
destruct H0.
inversion e.
inversion H.
intros.
simpl.
remember (div2 (S x) (S z)).
destruct t.
simpl.
inversion H.
by left.
subst.
right.
by apply : IHz.
assert(isPartial (div2 (S x) (S z))).
destruct (div2 (S x) (S z)).
inversion Heqt.
easy.
pose (definition_div_to_false_ind H1).
inversion H.
subst.
easy.
by apply : IHz.
Qed.
Theorem all_factors_inhabits : forall x h, divisible (S x) h -> In h (get_factors (S x) (S x)).
intros.
destruct H.
destruct h.
inversion e.
destruct x0.
rewrite Nat.mul_comm in e.
inversion e.
apply : le_factors_inhabited.
by destruct (div_less e).
by exists (S x0).
Qed.
Theorem all_indivisibles_not_inhabits : forall x h, ~ In h (get_factors (S x) (S x)) -> indivisible (S x) h.
intros.
move => H'.
by pose (all_factors_inhabits H').
Qed.
Theorem le_factors_inhabited' : forall x z h, In h (get_factors (S x) z) -> divisible (S x) h.
intros.
apply : (@induction_div_to_definition _ _ (S (S x))).
induction z.
inversion H.
simpl in H.
remember (div2 (S x) (S z)).
destruct t.
unfold div2 in Heqt.
destruct H.
rewrite <- H.
by rewrite <- Heqt.
by apply : IHz.
by apply : IHz.
Qed.
Theorem itself_1_factor : forall x, In (S x) (get_factors (S x) (S x)) /\ In 1 (get_factors (S x) (S x)).
intros.
assert(divisible (S x) 1).
exists (S x).
auto with arith.
assert(divisible (S x) (S x)).
exists 1.
auto with arith.
constructor.
by apply : all_factors_inhabits.
by apply : all_factors_inhabits.
Qed.
Theorem _2_minimuim_factors : forall x, 2 <= length (get_factors (S (S x)) (S (S x))).
intros.
pose (itself_1_factor (S x)).
destruct a.
destruct ((get_factors (S (S x)) (S (S x)))).
inversion H.
destruct l.
inversion H.
inversion H0.
lia.
easy.
easy.
simpl; auto with arith.
Qed.
Fixpoint nth_list {A} (xs : list A) n : n < length xs -> A.
refine (match n as c return (c < length xs -> A) with
|0 => _
|S n => _
end).
move => H.
destruct xs.
assert(~ 0 < 0).
auto with arith.
destruct(H0 H).
exact a.
move => H.
exact (nth_list A xs n (Nat.lt_succ_l _ _ H)).
Defined.
Theorem nth_list_uniquess_index : forall {A} (xs : list A) n (H : n < length xs) (H1 : n < length xs),
nth_list H = nth_list H1.
intros.
generalize dependent xs.
induction n.
intros.
destruct xs.
inversion H.
trivial.
intros.
destruct xs.
inversion H.
simpl.
apply : IHn.
Qed.
Theorem uniquess_2factors :
forall x, length (get_factors (S (S x)) (S (S x))) = 2 -> forall y,
divisible (S (S x)) y -> y = 1 \/ y = (S (S x)).
(* this proof was made in a brutal manual way, for sure there is a more fancy way to prove
just generalizing the proof, but idk the generalized proof might be necessary for our work *)
intros.
pose(@all_indivisibles_not_inhabits (S x)).
destruct (itself_1_factor (S x)).
pose(le_factors_inhabited' H1).
pose(le_factors_inhabited' H2).
move : i d d0.
destruct (get_factors (S (S x)) (S (S x))).
inversion H.
have : forall (y : nat) k h, y <> k /\ y <> h -> ~ In y [k; h].
intros.
move => H4.
destruct H3.
destruct H4.
subst.
intuition.
destruct H5.
destruct H4.
auto.
inversion H4.
move => brute_theorem.
destruct l.
inversion H.
intros.
destruct l.
assert([n;n0] = [1; S (S x)] \/ [n; n0] = [S (S x); 1]).
destruct H1.
destruct H2.
subst.
inversion H2.
destruct H2.
subst.
by right.
destruct H2.
destruct H2.
destruct H1.
subst.
by left.
destruct H1.
destruct H1.
destruct H2.
subst.
inversion H2.
destruct H2.
destruct H1.
destruct H3.
injection H3.
intros; subst.
destruct (Nat.eq_dec 1 y).
by left.
destruct (Nat.eq_dec y (S (S x))).
by right.
destruct (((i _ (brute_theorem _ _ _ (conj (Nat.Private_Tac.neq_sym n) n0)))) H0).
injection H3.
intros; subst.
destruct (Nat.eq_dec 1 y).
by left.
destruct (Nat.eq_dec y (S (S x))).
by right.
destruct ((i _ (brute_theorem _ _ _ (conj n0 (Nat.Private_Tac.neq_sym n)))) H0).
inversion H.
Qed.
Theorem prime_correspondence : forall x, prime_dec (S (S x)) = true -> prime (S (S x)).
intros.
unfold prime_dec in H.
move => H'.
destruct H'.
destruct p.
destruct p.
destruct (uniquess_2factors (eq_rel H) d).
intuition.
intuition.
Qed.
Fixpoint prop_list {A}
(P : A -> A -> Prop) (v : list A) {struct v} : Prop.
intros.
destruct v.
exact True.
refine (_ (prop_list _ P v)).
destruct v.
exact (fun H => P a a).
refine (fun H => P a a0 /\ H).
Defined.
Fixpoint strong_prop_list {A}
(P : A -> A -> Prop) (v : list A) {struct v} : Prop.
intros.
destruct v.
exact True.
refine (_ (strong_prop_list _ P v)).
destruct v.
exact (fun H => True).
refine (fun H => P a a0 /\ H).
Defined.
Definition descending := fun v => prop_list (fun x y => y <= x) v.
Definition strong_descending := fun v => strong_prop_list (fun x y => y < x) v.
Theorem le_factors : forall z h x, In h (get_factors x z) -> h <= z.
elim.
intros.
inversion H.
intros.
pose(H h x).
unfold get_factors in H0.
remember (div2 x (S n)).
destruct t.
destruct H0.
by subst.
pose (l H0).
auto with arith.
pose (l H0).
auto with arith.
Qed.
Theorem factors_descending : forall x z, descending (get_factors x z).
intros.
induction z.
intros.
easy.
intros.
destruct z.
simpl.
by destruct (div2 x 1).
simpl in *.
move : IHz.
remember (div2 x (S (S z))).
remember (div2 x (S z)).
intros.
destruct t.
destruct t0.
constructor.
auto with arith.
exact IHz.
unfold descending.
simpl.
remember (get_factors x z ).
destruct l.
auto with arith.
constructor.
assert(In n0 (get_factors x z)).
destruct (get_factors x z).
inversion Heql.
simpl.
left.
inversion Heql.
auto.
pose (le_factors H).
auto with arith.
exact IHz.
assumption.
Qed.
Theorem factors_descending' : forall x z, strong_descending (get_factors x z).
intros.
induction z.
intros.
easy.
intros.
destruct z.
simpl.
by destruct (div2 x 1).
simpl in *.
move : IHz.
remember (div2 x (S (S z))).
remember (div2 x (S z)).
intros.
destruct t.
destruct t0.
constructor.
auto with arith.
exact IHz.
unfold descending.
simpl.
remember (get_factors x z ).
destruct l.
auto with arith.
constructor.
assert(In n0 (get_factors x z)).
destruct (get_factors x z).
inversion Heql.
simpl.
left.
inversion Heql.
auto.
pose (le_factors H).
auto with arith.
exact IHz.
assumption.
Qed.
Theorem strong_distinction_succ : forall x y z, strong_descending x -> S y < length x ->
nth (S y) x z < nth y x z.
intros.
unfold strong_descending in H.
generalize dependent x.
generalize dependent z.
induction y.
intros.
destruct x.
inversion H0.
destruct x.
inversion H0.
inversion H2.
simpl in *.
lia.
intros.
destruct x.
inversion H0.
simpl.
assert (strong_prop_list (fun x : nat => lt^~ x) x).
destruct x.
by constructor.
by destruct H.
simpl in H0.
apply : (IHy z x H1 (le_S_n _ _ H0)).
Qed.
Theorem strong_distinction : forall a b z x, strong_descending x -> a < b -> b < length x ->
nth b x z < nth a x z.
elim.
intros.
generalize dependent x.
induction b.
inversion H0.
intros.
destruct b.
by apply : strong_distinction_succ.
assert(S b < length x) by lia.
pose (IHb (Nat.lt_0_succ _) x H H2).
rewrite <- l.
by apply : strong_distinction_succ.
intros.
destruct b.
inversion H1.
assert(n < b) by lia.
assert(b < length x) by lia.
destruct x.
inversion H2.
simpl.
assert(strong_descending x).
destruct x.
trivial.
destruct H0.
done.
simpl in H4.
destruct b.
inversion H1.
inversion H7.
simpl in H2.
assert(S b < length x) by lia.
exact (H (S b) z x H5 H3 H6).
Qed.
Theorem nth_In : forall {A} (xs : list A) n z, n < length xs -> In (nth n xs z) xs.
move => T; elim.
intros.
inversion H.
intros.
simpl in H0.
destruct n.
by left.
right.
apply : H.