This repository was archived by the owner on Jun 17, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathorder.lean
More file actions
1217 lines (1074 loc) · 37.8 KB
/
Copy pathorder.lean
File metadata and controls
1217 lines (1074 loc) · 37.8 KB
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
/-
Copyright (c) 2015 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Robert Y. Lewis
The real numbers, constructed as equivalence classes of Cauchy sequences of rationals.
This construction follows Bishop and Bridges (1985).
To do:
o Rename things and possibly make theorems private
-/
import data.real.basic data.rat data.nat
open rat nat eq pnat
local postfix `⁻¹` := pnat.inv
local attribute real.real_has_zero [instance] [priority real.prio]
local attribute real.real_has_one [instance] [priority real.prio]
namespace rat_seq
definition pos (s : seq) := ∃ n : ℕ+, n⁻¹ < (s n)
definition nonneg (s : seq) := ∀ n : ℕ+, -(n⁻¹) ≤ s n
theorem sub_sub_comm (a b c : ℚ) : a - b - c = a - c - b :=
by rewrite [+sub_eq_add_neg, add.assoc, {-b+_}add.comm, -add.assoc]
theorem bdd_away_of_pos {s : seq} (Hs : regular s) (H : pos s) :
∃ N : ℕ+, ∀ n : ℕ+, n ≥ N → (s n) ≥ N⁻¹ :=
begin
cases H with [n, Hn],
cases sep_by_inv Hn with [N, HN],
existsi N,
intro m Hm,
have Habs : abs (s m - s n) ≥ s n - s m, by rewrite abs_sub; apply le_abs_self,
have Habs' : s m + abs (s m - s n) ≥ s n, from (iff.mpr (le_add_iff_sub_left_le _ _ _)) Habs,
have HN' : N⁻¹ + N⁻¹ ≤ s n - n⁻¹, begin
rewrite sub_eq_add_neg,
apply iff.mpr (le_add_iff_sub_right_le _ _ _),
rewrite [sub_neg_eq_add, add.comm, -add.assoc],
apply le_of_lt HN
end,
rewrite add.comm at Habs',
have Hin : s m ≥ N⁻¹, from calc
s m ≥ s n - abs (s m - s n) : (iff.mp (le_add_iff_sub_left_le _ _ _)) Habs'
... ≥ s n - (m⁻¹ + n⁻¹) : sub_le_sub_left !Hs
... = s n - m⁻¹ - n⁻¹ : by rewrite sub_add_eq_sub_sub
... = s n - n⁻¹ - m⁻¹ : by rewrite sub_sub_comm
... ≥ s n - n⁻¹ - N⁻¹ : sub_le_sub_left (inv_ge_of_le Hm)
... ≥ N⁻¹ + N⁻¹ - N⁻¹ : sub_le_sub_right HN'
... = N⁻¹ : by rewrite add_sub_cancel,
apply Hin
end
theorem pos_of_bdd_away {s : seq} (H : ∃ N : ℕ+, ∀ n : ℕ+, n ≥ N → (s n) ≥ N⁻¹) : pos s :=
begin
cases H with [N, HN],
existsi (N + pone),
apply lt_of_lt_of_le,
apply inv_add_lt_left,
apply HN,
apply le_of_lt,
apply lt_add_left
end
theorem bdd_within_of_nonneg {s : seq} (Hs : regular s) (H : nonneg s) :
∀ n : ℕ+, ∃ N : ℕ+, ∀ m : ℕ+, m ≥ N → s m ≥ -n⁻¹ :=
begin
intros,
existsi n,
intro m Hm,
apply le.trans,
apply neg_le_neg,
apply inv_ge_of_le,
apply Hm,
apply H
end
theorem nonneg_of_bdd_within {s : seq} (Hs : regular s)
(H : ∀n : ℕ+, ∃ N : ℕ+, ∀ m : ℕ+, m ≥ N → s m ≥ -n⁻¹) : nonneg s :=
begin
rewrite ↑nonneg,
intro k,
apply ge_of_forall_ge_sub,
intro ε Hε,
cases H (pceil ((2) / ε)) with [N, HN],
apply le.trans,
rotate 1,
apply sub_le_of_abs_sub_le_left,
apply Hs,
apply (max (pceil ((2)/ε)) N),
rewrite [+sub_eq_add_neg, neg_add, {_ + (-k⁻¹ + _)}add.comm, *add.assoc],
apply rat.add_le_add_left,
apply le.trans,
rotate 1,
apply add_le_add,
rotate 1,
apply HN (max (pceil ((2)/ε)) N) !le_max_right,
rotate_right 1,
apply neg_le_neg,
apply inv_ge_of_le,
apply le_max_left,
rewrite -neg_add,
apply neg_le_neg,
apply le.trans,
apply add_le_add,
repeat (apply inv_pceil_div;
apply add_pos;
repeat apply zero_lt_one;
exact Hε),
rewrite [add_halves],
apply rat.le_refl
end
theorem pos_of_pos_equiv {s t : seq} (Hs : regular s) (Heq : s ≡ t) (Hp : pos s) : pos t :=
begin
cases (bdd_away_of_pos Hs Hp) with [N, HN],
existsi 2 * 2 * N,
apply lt_of_lt_of_le,
rotate 1,
apply sub_le_of_abs_sub_le_right,
apply Heq,
have Hs4 : N⁻¹ ≤ s (2 * 2 * N), from HN _ (!pnat.mul_le_mul_left),
apply lt_of_lt_of_le,
rotate 1,
rewrite sub_eq_add_neg,
apply iff.mpr !add_le_add_right_iff,
apply Hs4,
rewrite [*pnat.mul_assoc, pnat.add_halves, -(pnat.add_halves N), -sub_eq_add_neg, add_sub_cancel],
apply inv_two_mul_lt_inv
end
theorem nonneg_of_nonneg_equiv {s t : seq} (Hs : regular s) (Ht : regular t) (Heq : s ≡ t)
(Hp : nonneg s) : nonneg t :=
begin
apply nonneg_of_bdd_within,
apply Ht,
intros,
cases bdd_within_of_nonneg Hs Hp (2 * 2 * n) with [Ns, HNs],
existsi max Ns (2 * 2 * n),
intro m Hm,
apply le.trans,
rotate 1,
apply sub_le_of_abs_sub_le_right,
apply Heq,
apply le.trans,
rotate 1,
apply sub_le_sub_right,
apply HNs,
apply le.trans,
rotate 1,
apply Hm,
rotate_right 1,
apply le_max_left,
have Hms : m⁻¹ ≤ (2 * 2 * n)⁻¹, begin
apply inv_ge_of_le,
apply le.trans,
rotate 1,
apply Hm;
apply le_max_right
end,
have Hms' : m⁻¹ + m⁻¹ ≤ (2 * 2 * n)⁻¹ + (2 * 2 * n)⁻¹, from add_le_add Hms Hms,
apply le.trans,
rotate 1,
apply sub_le_sub_left,
apply Hms',
rewrite [*pnat.mul_assoc, pnat.add_halves, -neg_sub, -pnat.add_halves n, sub_neg_eq_add],
apply neg_le_neg,
apply add_le_add_left,
apply inv_two_mul_le_inv
end
definition s_le (a b : seq) := nonneg (sadd b (sneg a))
definition s_lt (a b : seq) := pos (sadd b (sneg a))
theorem zero_nonneg : nonneg zero :=
begin
intros,
apply neg_nonpos_of_nonneg,
apply rat.le_of_lt,
apply pnat.inv_pos
end
theorem s_zero_lt_one : s_lt zero one :=
begin
rewrite [↑s_lt, ↑zero, ↑sadd, ↑sneg, ↑one, neg_zero, add_zero, ↑pos],
existsi 2,
apply inv_lt_one_of_gt,
apply one_lt_two
end
protected theorem le_refl {s : seq} (Hs : regular s) : s_le s s :=
begin
apply nonneg_of_nonneg_equiv,
rotate 2,
apply equiv.symm,
apply neg_s_cancel s Hs,
apply zero_nonneg,
apply zero_is_reg,
apply reg_add_reg Hs (reg_neg_reg Hs)
end
theorem s_nonneg_of_pos {s : seq} (Hs : regular s) (H : pos s) : nonneg s :=
begin
apply nonneg_of_bdd_within,
apply Hs,
intros,
cases bdd_away_of_pos Hs H with [N, HN],
existsi N,
intro m Hm,
apply le.trans,
rotate 1,
apply HN,
apply Hm,
apply le.trans,
rotate 1,
apply rat.le_of_lt,
apply pnat.inv_pos,
rewrite -neg_zero,
apply neg_le_neg,
apply rat.le_of_lt,
apply pnat.inv_pos
end
theorem s_le_of_s_lt {s t : seq} (Hs : regular s) (Ht : regular t) (H : s_lt s t) : s_le s t :=
begin
rewrite [↑s_le, ↑s_lt at *],
apply s_nonneg_of_pos,
repeat (apply reg_add_reg | apply reg_neg_reg | assumption)
end
theorem s_neg_add_eq_s_add_neg (s t : seq) : sneg (sadd s t) ≡ sadd (sneg s) (sneg t) :=
begin
rewrite [↑equiv, ↑sadd, ↑sneg],
intros,
rewrite [neg_add, sub_self, abs_zero],
apply add_invs_nonneg
end
theorem equiv_cancel_middle {s t u : seq} (Hs : regular s) (Ht : regular t)
(Hu : regular u) : sadd (sadd u t) (sneg (sadd u s)) ≡ sadd t (sneg s) :=
begin
note Hz := zero_is_reg,
apply equiv.trans,
rotate 3,
apply add_well_defined,
rotate 4,
apply s_add_comm,
apply s_neg_add_eq_s_add_neg,
apply equiv.trans,
rotate 3,
apply s_add_assoc,
rotate 2,
apply add_well_defined,
rotate 4,
apply equiv.refl,
apply equiv.trans,
rotate 4,
apply equiv.refl,
rotate_right 1,
apply equiv.trans,
rotate 3,
apply equiv.symm,
apply s_add_assoc,
rotate 2,
apply equiv.trans,
rotate 4,
apply s_zero_add,
rotate_right 1,
apply add_well_defined,
rotate 4,
apply neg_s_cancel,
rotate 1,
apply equiv.refl,
repeat (apply reg_add_reg | apply reg_neg_reg | assumption)
end
protected theorem add_le_add_of_le_right {s t : seq} (Hs : regular s) (Ht : regular t)
(Lst : s_le s t) : ∀ u : seq, regular u → s_le (sadd u s) (sadd u t) :=
begin
intro u Hu,
rewrite [↑s_le at *],
apply nonneg_of_nonneg_equiv,
rotate 2,
apply equiv.symm,
apply equiv_cancel_middle,
repeat (apply reg_add_reg | apply reg_neg_reg | assumption)
end
theorem s_add_lt_add_left {s t : seq} (Hs : regular s) (Ht : regular t) (Hst : s_lt s t) {u : seq}
(Hu : regular u) : s_lt (sadd u s) (sadd u t) :=
begin
rewrite ↑s_lt at *,
apply pos_of_pos_equiv,
rotate 1,
apply equiv.symm,
apply equiv_cancel_middle,
repeat (apply reg_add_reg | apply reg_neg_reg | assumption)
end
protected theorem add_nonneg_of_nonneg {s t : seq} (Hs : nonneg s) (Ht : nonneg t) :
nonneg (sadd s t) :=
begin
intros,
rewrite [-pnat.add_halves, neg_add],
apply add_le_add,
apply Hs,
apply Ht
end
protected theorem le_trans {s t u : seq} (Hs : regular s) (Ht : regular t) (Hu : regular u)
(Lst : s_le s t) (Ltu : s_le t u) : s_le s u :=
begin
rewrite ↑s_le at *,
note Rz := zero_is_reg,
have Hsum : nonneg (sadd (sadd u (sneg t)) (sadd t (sneg s))),
from rat_seq.add_nonneg_of_nonneg Ltu Lst,
have H' : nonneg (sadd (sadd u (sadd (sneg t) t)) (sneg s)), begin
apply nonneg_of_nonneg_equiv,
rotate 2,
apply add_well_defined,
rotate 4,
apply s_add_assoc,
repeat (apply reg_add_reg | apply reg_neg_reg | assumption),
apply equiv.refl,
apply nonneg_of_nonneg_equiv,
rotate 2,
apply equiv.symm,
apply s_add_assoc,
rotate 2,
repeat (apply reg_add_reg | apply reg_neg_reg | assumption)
end,
have H'' : sadd (sadd u (sadd (sneg t) t)) (sneg s) ≡ sadd u (sneg s), begin
apply add_well_defined,
rotate 4,
apply equiv.trans,
rotate 3,
apply add_well_defined,
rotate 4,
apply equiv.refl,
apply s_neg_cancel,
rotate 1,
apply s_add_zero,
rotate 1,
apply equiv.refl,
repeat (apply reg_add_reg | apply reg_neg_reg | assumption)
end,
apply nonneg_of_nonneg_equiv,
rotate 2,
apply H'',
apply H',
repeat (apply reg_add_reg | apply reg_neg_reg | assumption)
end
theorem equiv_of_le_of_ge {s t : seq} (Hs : regular s) (Ht : regular t) (Lst : s_le s t)
(Lts : s_le t s) : s ≡ t :=
begin
apply equiv_of_diff_equiv_zero,
rotate 2,
rewrite [↑s_le at *, ↑nonneg at *, ↑equiv, ↑sadd at *, ↑sneg at *],
intros,
rewrite [↑zero, sub_zero],
apply abs_le_of_le_of_neg_le,
apply le_of_neg_le_neg,
rewrite [2 neg_add, neg_neg],
apply rat.le_trans,
apply neg_add_neg_le_neg_of_pos,
apply pnat.inv_pos,
rewrite add.comm,
apply Lst,
apply le_of_neg_le_neg,
rewrite [neg_add, neg_neg],
apply rat.le_trans,
apply neg_add_neg_le_neg_of_pos,
apply pnat.inv_pos,
apply Lts,
repeat assumption
end
definition sep (s t : seq) := s_lt s t ∨ s_lt t s
local infix `≢` : 50 := sep
theorem le_and_sep_of_lt {s t : seq} (Hs : regular s) (Ht : regular t) (Lst : s_lt s t) :
s_le s t ∧ sep s t :=
begin
apply and.intro,
intros,
cases Lst with [N, HN],
let Rns := reg_neg_reg Hs,
let Rtns := reg_add_reg Ht Rns,
note Habs := sub_le_of_abs_sub_le_right (Rtns N n),
rewrite [sub_add_eq_sub_sub at Habs],
exact (calc
sadd t (sneg s) n ≥ sadd t (sneg s) N - N⁻¹ - n⁻¹ : Habs
... ≥ 0 - n⁻¹: begin
apply sub_le_sub_right,
apply rat.le_of_lt,
apply (iff.mpr (sub_pos_iff_lt _ _)),
apply HN
end
... = -n⁻¹ : by rewrite zero_sub),
exact or.inl Lst
end
theorem lt_of_le_and_sep {s t : seq} (Hs : regular s) (Ht : regular t) (H : s_le s t ∧ sep s t) :
s_lt s t :=
begin
note Le := and.left H,
cases and.right H with [P, Hlt],
exact P,
rewrite [↑s_le at Le, ↑nonneg at Le, ↑s_lt at Hlt, ↑pos at Hlt],
apply exists.elim Hlt,
intro N HN,
let LeN := Le N,
note HN' := (iff.mpr !neg_lt_neg_iff_lt) HN,
rewrite [↑sadd at HN', ↑sneg at HN', neg_add at HN', neg_neg at HN', add.comm at HN'],
let HN'' := not_le_of_gt HN',
apply absurd LeN HN''
end
theorem lt_iff_le_and_sep {s t : seq} (Hs : regular s) (Ht : regular t) :
s_lt s t ↔ s_le s t ∧ sep s t :=
iff.intro (le_and_sep_of_lt Hs Ht) (lt_of_le_and_sep Hs Ht)
theorem s_neg_zero : sneg zero ≡ zero :=
begin
rewrite ↑[sneg, zero, equiv],
intros,
rewrite [sub_zero, abs_neg, abs_zero],
apply add_invs_nonneg
end
theorem s_sub_zero {s : seq} (Hs : regular s) : sadd s (sneg zero) ≡ s :=
begin
apply equiv.trans,
rotate 3,
apply add_well_defined,
rotate 4,
apply equiv.refl,
apply s_neg_zero,
apply s_add_zero,
repeat (assumption | apply reg_add_reg | apply reg_neg_reg | apply zero_is_reg)
end
theorem s_pos_of_gt_zero {s : seq} (Hs : regular s) (Hgz : s_lt zero s) : pos s :=
begin
rewrite [↑s_lt at *],
apply pos_of_pos_equiv,
rotate 1,
apply s_sub_zero,
repeat (assumption | apply reg_add_reg | apply reg_neg_reg),
apply zero_is_reg
end
theorem s_gt_zero_of_pos {s : seq} (Hs : regular s) (Hp : pos s) : s_lt zero s :=
begin
rewrite ↑s_lt,
apply pos_of_pos_equiv,
rotate 1,
apply equiv.symm,
apply s_sub_zero,
repeat assumption
end
theorem s_nonneg_of_ge_zero {s : seq} (Hs : regular s) (Hgz : s_le zero s) : nonneg s :=
begin
rewrite ↑s_le at *,
apply nonneg_of_nonneg_equiv,
rotate 2,
apply s_sub_zero,
repeat (assumption | apply reg_add_reg | apply reg_neg_reg | apply zero_is_reg)
end
theorem s_ge_zero_of_nonneg {s : seq} (Hs : regular s) (Hn : nonneg s) : s_le zero s :=
begin
rewrite ↑s_le,
apply nonneg_of_nonneg_equiv,
rotate 2,
apply equiv.symm,
apply s_sub_zero,
repeat (assumption | apply reg_add_reg | apply reg_neg_reg | apply zero_is_reg)
end
theorem s_mul_pos_of_pos {s t : seq} (Hs : regular s) (Ht : regular t) (Hps : pos s)
(Hpt : pos t) : pos (smul s t) :=
begin
rewrite [↑pos at *],
cases bdd_away_of_pos Hs Hps with [Ns, HNs],
cases bdd_away_of_pos Ht Hpt with [Nt, HNt],
existsi 2 * max Ns Nt * max Ns Nt,
rewrite ↑smul,
apply lt_of_lt_of_le,
rotate 1,
apply mul_le_mul,
apply HNs,
apply le.trans,
apply le_max_left Ns Nt,
rewrite -pnat.mul_assoc,
apply pnat.mul_le_mul_left,
apply HNt,
apply le.trans,
apply le_max_right Ns Nt,
rewrite -pnat.mul_assoc,
apply pnat.mul_le_mul_left,
apply rat.le_of_lt,
apply pnat.inv_pos,
apply rat.le_trans,
rotate 1,
apply HNs,
apply le.trans,
apply le_max_left Ns Nt,
rewrite -pnat.mul_assoc,
apply pnat.mul_le_mul_left,
rewrite pnat.inv_mul_eq_mul_inv,
apply mul_lt_mul,
rewrite [pnat.inv_mul_eq_mul_inv, -one_mul Ns⁻¹],
apply mul_lt_mul,
apply inv_lt_one_of_gt,
apply dec_trivial,
apply inv_ge_of_le,
apply le_max_left,
apply pnat.inv_pos,
apply rat.le_of_lt zero_lt_one,
apply inv_ge_of_le,
apply le_max_right,
apply pnat.inv_pos,
repeat (apply le_of_lt; apply pnat.inv_pos)
end
theorem s_mul_gt_zero_of_gt_zero {s t : seq} (Hs : regular s) (Ht : regular t)
(Hzs : s_lt zero s) (Hzt : s_lt zero t) : s_lt zero (smul s t) :=
s_gt_zero_of_pos
(reg_mul_reg Hs Ht)
(s_mul_pos_of_pos Hs Ht (s_pos_of_gt_zero Hs Hzs) (s_pos_of_gt_zero Ht Hzt))
theorem le_of_lt_or_equiv {s t : seq} (Hs : regular s) (Ht : regular t)
(Hor : (s_lt s t) ∨ (s ≡ t)) : s_le s t :=
or.elim Hor
(begin
intro Hlt,
apply s_le_of_s_lt Hs Ht Hlt
end)
(begin
intro Heq,
rewrite ↑s_le,
apply nonneg_of_nonneg_equiv,
rotate 3,
apply zero_nonneg,
apply zero_is_reg,
apply reg_add_reg Ht (reg_neg_reg Hs),
apply equiv.symm,
apply diff_equiv_zero_of_equiv,
rotate 2,
apply equiv.symm,
apply Heq,
repeat assumption
end)
theorem s_zero_mul {s : seq} : smul s zero ≡ zero :=
begin
rewrite [↑equiv, ↑smul, ↑zero],
intros,
rewrite [mul_zero, sub_zero, abs_zero],
apply add_invs_nonneg
end
theorem s_mul_nonneg_of_pos_of_zero {s t : seq} (Hs : regular s) (Ht : regular t)
(Hps : pos s) (Hpt : zero ≡ t) : nonneg (smul s t) :=
begin
apply nonneg_of_nonneg_equiv,
rotate 2,
apply mul_well_defined,
rotate 4,
apply equiv.refl,
apply Hpt,
apply nonneg_of_nonneg_equiv,
rotate 2,
apply equiv.symm,
apply s_zero_mul,
apply zero_nonneg,
repeat (assumption | apply reg_mul_reg | apply zero_is_reg)
end
theorem s_mul_nonneg_of_nonneg {s t : seq} (Hs : regular s) (Ht : regular t)
(Hps : nonneg s) (Hpt : nonneg t) : nonneg (smul s t) :=
begin
intro n,
rewrite ↑smul,
apply rat.le_by_cases 0 (s (((K₂ s t) * 2) * n)),
intro Hsp,
apply rat.le_by_cases 0 (t (((K₂ s t) * 2) * n)),
intro Htp,
apply rat.le_trans,
rotate 1,
apply rat.mul_nonneg Hsp Htp,
rotate_right 1,
apply le_of_lt,
apply neg_neg_of_pos,
apply pnat.inv_pos,
intro Htn,
apply rat.le_trans,
rotate 1,
apply mul_le_mul_of_nonpos_right,
apply rat.le_trans,
apply le_abs_self,
apply canon_2_bound_left s t Hs,
apply Htn,
rotate_right 1,
apply rat.le_trans,
rotate 1,
apply mul_le_mul_of_nonneg_left,
apply Hpt,
apply le_of_lt,
apply rat_of_pnat_is_pos,
rotate 1,
rewrite -neg_mul_eq_mul_neg,
apply neg_le_neg,
rewrite [*pnat.mul_assoc, pnat.inv_mul_eq_mul_inv, -mul.assoc, pnat.inv_cancel_left, one_mul],
apply inv_ge_of_le,
apply pnat.mul_le_mul_left,
intro Hsn,
apply rat.le_by_cases 0 (t (((K₂ s t) * 2) * n)),
intro Htp,
apply rat.le_trans,
rotate 1,
apply mul_le_mul_of_nonpos_left,
apply rat.le_trans,
apply le_abs_self,
apply canon_2_bound_right s t Ht,
apply Hsn,
rotate_right 1,
apply rat.le_trans,
rotate 1,
apply mul_le_mul_of_nonneg_right,
apply Hps,
apply le_of_lt,
apply rat_of_pnat_is_pos,
rotate 1,
rewrite -neg_mul_eq_neg_mul,
apply neg_le_neg,
rewrite [+pnat.mul_assoc, pnat.inv_mul_eq_mul_inv, mul.comm, -mul.assoc, pnat.inv_cancel_left,
one_mul],
apply inv_ge_of_le,
apply pnat.mul_le_mul_left,
intro Htn,
apply le.trans,
rotate 1,
apply mul_nonneg_of_nonpos_of_nonpos,
apply Hsn,
apply Htn,
apply le_of_lt,
apply neg_neg_of_pos,
apply pnat.inv_pos
end
theorem s_mul_ge_zero_of_ge_zero {s t : seq} (Hs : regular s) (Ht : regular t)
(Hzs : s_le zero s) (Hzt : s_le zero t) : s_le zero (smul s t) :=
begin
note Hzs' := s_nonneg_of_ge_zero Hs Hzs,
note Htz' := s_nonneg_of_ge_zero Ht Hzt,
apply s_ge_zero_of_nonneg,
rotate 1,
apply s_mul_nonneg_of_nonneg,
repeat assumption,
apply reg_mul_reg Hs Ht
end
protected theorem not_lt_self (s : seq) : ¬ s_lt s s :=
begin
intro Hlt,
rewrite [↑s_lt at Hlt, ↑pos at Hlt],
apply exists.elim Hlt,
intro n Hn, esimp at Hn,
rewrite [↑sadd at Hn,↑sneg at Hn, -sub_eq_add_neg at Hn, sub_self at Hn],
apply absurd Hn (not_lt_of_ge (rat.le_of_lt !pnat.inv_pos))
end
theorem not_sep_self (s : seq) : ¬ s ≢ s :=
begin
intro Hsep,
rewrite ↑sep at Hsep,
let Hsep' := (iff.mp !or_self) Hsep,
apply absurd Hsep' (!rat_seq.not_lt_self)
end
theorem le_well_defined {s t u v : seq} (Hs : regular s) (Ht : regular t) (Hu : regular u)
(Hv : regular v) (Hsu : s ≡ u) (Htv : t ≡ v) : s_le s t ↔ s_le u v :=
iff.intro
(begin
intro Hle,
rewrite [↑s_le at *],
apply nonneg_of_nonneg_equiv,
rotate 2,
apply add_well_defined,
rotate 4,
apply Htv,
apply neg_well_defined,
apply Hsu,
apply Hle,
repeat (apply reg_add_reg | apply reg_neg_reg | assumption)
end)
(begin
intro Hle,
rewrite [↑s_le at *],
apply nonneg_of_nonneg_equiv,
rotate 2,
apply add_well_defined,
rotate 4,
apply equiv.symm, apply Htv,
apply neg_well_defined,
apply equiv.symm, apply Hsu,
apply Hle,
repeat (apply reg_add_reg | apply reg_neg_reg | assumption)
end)
theorem lt_well_defined {s t u v : seq} (Hs : regular s) (Ht : regular t) (Hu : regular u)
(Hv : regular v) (Hsu : s ≡ u) (Htv : t ≡ v) : s_lt s t ↔ s_lt u v :=
iff.intro
(begin
intro Hle,
rewrite [↑s_lt at *],
apply pos_of_pos_equiv,
rotate 1,
apply add_well_defined,
rotate 4,
apply Htv,
apply neg_well_defined,
apply Hsu,
apply Hle,
repeat (apply reg_add_reg | apply reg_neg_reg | assumption)
end)
(begin
intro Hle,
rewrite [↑s_lt at *],
apply pos_of_pos_equiv,
rotate 1,
apply add_well_defined,
rotate 4,
apply equiv.symm, apply Htv,
apply neg_well_defined,
apply equiv.symm, apply Hsu,
apply Hle,
repeat (apply reg_add_reg | apply reg_neg_reg | assumption)
end)
theorem sep_well_defined {s t u v : seq} (Hs : regular s) (Ht : regular t) (Hu : regular u)
(Hv : regular v) (Hsu : s ≡ u) (Htv : t ≡ v) : s ≢ t ↔ u ≢ v :=
begin
rewrite ↑sep,
apply iff.intro,
intro Hor,
apply or.elim Hor,
intro Hlt,
apply or.inl,
apply iff.mp (lt_well_defined Hs Ht Hu Hv Hsu Htv),
assumption,
intro Hlt,
apply or.inr,
apply iff.mp (lt_well_defined Ht Hs Hv Hu Htv Hsu),
assumption,
intro Hor,
apply or.elim Hor,
intro Hlt,
apply or.inl,
apply iff.mpr (lt_well_defined Hs Ht Hu Hv Hsu Htv),
assumption,
intro Hlt,
apply or.inr,
apply iff.mpr (lt_well_defined Ht Hs Hv Hu Htv Hsu),
assumption
end
theorem s_lt_of_lt_of_le {s t u : seq} (Hs : regular s) (Ht : regular t) (Hu : regular u)
(Hst : s_lt s t) (Htu : s_le t u) : s_lt s u :=
begin
let Rtns := reg_add_reg Ht (reg_neg_reg Hs),
let Runt := reg_add_reg Hu (reg_neg_reg Ht),
have Hcan : ∀ m, sadd u (sneg s) m = (sadd t (sneg s)) m + (sadd u (sneg t)) m, begin
intro m,
rewrite [↑sadd, ↑sneg, -*sub_eq_add_neg, -sub_eq_sub_add_sub]
end,
rewrite [↑s_lt at *, ↑s_le at *],
cases bdd_away_of_pos Rtns Hst with [Nt, HNt],
cases bdd_within_of_nonneg Runt Htu (2 * Nt) with [Nu, HNu],
apply pos_of_bdd_away,
existsi max (2 * Nt) Nu,
intro n Hn,
rewrite Hcan,
apply rat.le_trans,
rotate 1,
apply add_le_add,
apply HNt,
apply le.trans,
apply pnat.mul_le_mul_left 2,
apply le.trans,
rotate 1,
apply Hn,
rotate_right 1,
apply le_max_left,
apply HNu,
apply le.trans,
rotate 1,
apply Hn,
rotate_right 1,
apply le_max_right,
rewrite [-pnat.add_halves Nt, -sub_eq_add_neg, add_sub_cancel],
apply inv_ge_of_le,
apply le_max_left
end
theorem s_lt_of_le_of_lt {s t u : seq} (Hs : regular s) (Ht : regular t) (Hu : regular u)
(Hst : s_le s t) (Htu : s_lt t u) : s_lt s u :=
begin
let Rtns := reg_add_reg Ht (reg_neg_reg Hs),
let Runt := reg_add_reg Hu (reg_neg_reg Ht),
have Hcan : ∀ m, sadd u (sneg s) m = (sadd t (sneg s)) m + (sadd u (sneg t)) m, begin
intro m,
rewrite [↑sadd, ↑sneg, -*sub_eq_add_neg, -sub_eq_sub_add_sub]
end,
rewrite [↑s_lt at *, ↑s_le at *],
cases bdd_away_of_pos Runt Htu with [Nu, HNu],
cases bdd_within_of_nonneg Rtns Hst (2 * Nu) with [Nt, HNt],
apply pos_of_bdd_away,
existsi max (2 * Nu) Nt,
intro n Hn,
rewrite Hcan,
apply rat.le_trans,
rotate 1,
apply add_le_add,
apply HNt,
apply le.trans,
rotate 1,
apply Hn,
rotate_right 1,
apply le_max_right,
apply HNu,
apply le.trans,
apply pnat.mul_le_mul_left 2,
apply le.trans,
rotate 1,
apply Hn,
rotate_right 1,
apply le_max_left,
rewrite [-pnat.add_halves Nu, neg_add_cancel_left],
apply inv_ge_of_le,
apply le_max_left
end
theorem le_of_le_reprs {s t : seq} (Hs : regular s) (Ht : regular t)
(Hle : ∀ n : ℕ+, s_le s (const (t n))) : s_le s t :=
by intro m; apply Hle (2 * m) m
theorem le_of_reprs_le {s t : seq} (Hs : regular s) (Ht : regular t)
(Hle : ∀ n : ℕ+, s_le (const (t n)) s) : s_le t s :=
by intro m; apply Hle (2 * m) m
-----------------------------
-- of_rat theorems
theorem const_le_const_of_le {a b : ℚ} (H : a ≤ b) : s_le (const a) (const b) :=
begin
rewrite [↑s_le, ↑nonneg],
intro n,
rewrite [↑sadd, ↑sneg, ↑const],
apply le.trans,
apply neg_nonpos_of_nonneg,
apply rat.le_of_lt,
apply pnat.inv_pos,
apply iff.mpr !sub_nonneg_iff_le,
apply H
end
theorem le_of_const_le_const {a b : ℚ} (H : s_le (const a) (const b)) : a ≤ b :=
begin
rewrite [↑s_le at H, ↑nonneg at H, ↑sadd at H, ↑sneg at H, ↑const at H],
apply iff.mp !sub_nonneg_iff_le,
apply nonneg_of_ge_neg_invs _ H
end
theorem nat_inv_lt_rat {a : ℚ} (H : a > 0) : ∃ n : ℕ+, n⁻¹ < a :=
begin
existsi (pceil (1 / (a / (2)))),
apply lt_of_le_of_lt,
rotate 1,
apply div_two_lt_of_pos H,
rewrite -(one_div_one_div (a / (1 + 1))),
apply pceil_helper,
apply le.refl,
apply one_div_pos_of_pos,
apply div_pos_of_pos_of_pos H dec_trivial
end
theorem const_lt_const_of_lt {a b : ℚ} (H : a < b) : s_lt (const a) (const b) :=
begin
rewrite [↑s_lt, ↑pos, ↑sadd, ↑sneg, ↑const],
apply nat_inv_lt_rat,
apply (iff.mpr !sub_pos_iff_lt H)
end
theorem lt_of_const_lt_const {a b : ℚ} (H : s_lt (const a) (const b)) : a < b :=
begin
rewrite [↑s_lt at H, ↑pos at H, ↑const at H, ↑sadd at H, ↑sneg at H],
cases H with [n, Hn],
apply (iff.mp !sub_pos_iff_lt),
apply lt.trans,
rotate 1,
exact Hn,
apply pnat.inv_pos
end
theorem s_le_of_le_pointwise {s t : seq} (Hs : regular s) (Ht : regular t)
(H : ∀ n : ℕ+, s n ≤ t n) : s_le s t :=
begin
rewrite [↑s_le, ↑nonneg, ↑sadd, ↑sneg],
intros,
apply le.trans,
apply iff.mpr !neg_nonpos_iff_nonneg,
apply le_of_lt,
apply pnat.inv_pos,
apply iff.mpr !sub_nonneg_iff_le,
apply H
end
-------- lift to reg_seqs
definition r_lt (s t : reg_seq) := s_lt (reg_seq.sq s) (reg_seq.sq t)
definition r_le (s t : reg_seq) := s_le (reg_seq.sq s) (reg_seq.sq t)
definition r_sep (s t : reg_seq) := sep (reg_seq.sq s) (reg_seq.sq t)
theorem r_le_well_defined (s t u v : reg_seq) (Hsu : requiv s u) (Htv : requiv t v)
: r_le s t = r_le u v :=
propext (le_well_defined (reg_seq.is_reg s) (reg_seq.is_reg t) (reg_seq.is_reg u)
(reg_seq.is_reg v) Hsu Htv)
theorem r_lt_well_defined (s t u v : reg_seq) (Hsu : requiv s u) (Htv : requiv t v)
: r_lt s t = r_lt u v :=
propext (lt_well_defined (reg_seq.is_reg s) (reg_seq.is_reg t) (reg_seq.is_reg u)
(reg_seq.is_reg v) Hsu Htv)
theorem r_sep_well_defined (s t u v : reg_seq) (Hsu : requiv s u) (Htv : requiv t v)
: r_sep s t = r_sep u v :=
propext (sep_well_defined (reg_seq.is_reg s) (reg_seq.is_reg t) (reg_seq.is_reg u)
(reg_seq.is_reg v) Hsu Htv)
theorem r_le.refl (s : reg_seq) : r_le s s := rat_seq.le_refl (reg_seq.is_reg s)
theorem r_le.trans {s t u : reg_seq} (Hst : r_le s t) (Htu : r_le t u) : r_le s u :=
rat_seq.le_trans (reg_seq.is_reg s) (reg_seq.is_reg t) (reg_seq.is_reg u) Hst Htu
theorem r_equiv_of_le_of_ge {s t : reg_seq} (Hs : r_le s t) (Hu : r_le t s) :
requiv s t :=
equiv_of_le_of_ge (reg_seq.is_reg s) (reg_seq.is_reg t) Hs Hu
theorem r_lt_iff_le_and_sep (s t : reg_seq) : r_lt s t ↔ r_le s t ∧ r_sep s t :=
lt_iff_le_and_sep (reg_seq.is_reg s) (reg_seq.is_reg t)
theorem r_add_le_add_of_le_right {s t : reg_seq} (H : r_le s t) (u : reg_seq) :
r_le (u + s) (u + t) :=
rat_seq.add_le_add_of_le_right (reg_seq.is_reg s) (reg_seq.is_reg t) H
(reg_seq.sq u) (reg_seq.is_reg u)
theorem r_add_le_add_of_le_right_var (s t u : reg_seq) (H : r_le s t) :
r_le (u + s) (u + t) := r_add_le_add_of_le_right H u
theorem r_mul_pos_of_pos {s t : reg_seq} (Hs : r_lt r_zero s) (Ht : r_lt r_zero t) :
r_lt r_zero (s * t) :=
s_mul_gt_zero_of_gt_zero (reg_seq.is_reg s) (reg_seq.is_reg t) Hs Ht
theorem r_mul_nonneg_of_nonneg {s t : reg_seq} (Hs : r_le r_zero s) (Ht : r_le r_zero t) :
r_le r_zero (s * t) :=
s_mul_ge_zero_of_ge_zero (reg_seq.is_reg s) (reg_seq.is_reg t) Hs Ht
theorem r_not_lt_self (s : reg_seq) : ¬ r_lt s s :=
rat_seq.not_lt_self (reg_seq.sq s)
theorem r_not_sep_self (s : reg_seq) : ¬ r_sep s s :=
not_sep_self (reg_seq.sq s)
theorem r_le_of_lt {s t : reg_seq} (H : r_lt s t) : r_le s t :=
s_le_of_s_lt (reg_seq.is_reg s) (reg_seq.is_reg t) H
theorem r_lt_of_le_of_lt {s t u : reg_seq} (Hst : r_le s t) (Htu : r_lt t u) : r_lt s u :=
s_lt_of_le_of_lt (reg_seq.is_reg s) (reg_seq.is_reg t) (reg_seq.is_reg u) Hst Htu
theorem r_lt_of_lt_of_le {s t u : reg_seq} (Hst : r_lt s t) (Htu : r_le t u) : r_lt s u :=
s_lt_of_lt_of_le (reg_seq.is_reg s) (reg_seq.is_reg t) (reg_seq.is_reg u) Hst Htu
theorem r_add_lt_add_left (s t : reg_seq) (H : r_lt s t) (u : reg_seq) : r_lt (u + s) (u + t) :=
s_add_lt_add_left (reg_seq.is_reg s) (reg_seq.is_reg t) H (reg_seq.is_reg u)
theorem r_add_lt_add_left_var (s t u : reg_seq) (H : r_lt s t) : r_lt (u + s) (u + t) :=
r_add_lt_add_left s t H u
theorem r_zero_lt_one : r_lt r_zero r_one := s_zero_lt_one
theorem r_le_of_lt_or_eq (s t : reg_seq) (H : r_lt s t ∨ requiv s t) : r_le s t :=
le_of_lt_or_equiv (reg_seq.is_reg s) (reg_seq.is_reg t) H
theorem r_const_le_const_of_le {a b : ℚ} (H : a ≤ b) : r_le (r_const a) (r_const b) :=
const_le_const_of_le H