/
Basic.lean
1321 lines (989 loc) · 46.1 KB
/
Basic.lean
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) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Mario Carneiro
! This file was ported from Lean 3 source module order.basic
! leanprover-community/mathlib commit d4f69d96f3532729da8ebb763f4bc26fcf640f06
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathlib.Data.Prod.Basic
import Mathlib.Data.Subtype
import Mathlib.Tactic.Classical
import Mathlib.Tactic.Convert
import Mathlib.Tactic.Inhabit
import Mathlib.Tactic.SimpRw
import Mathlib.Tactic.Spread
/-!
# Basic definitions about `≤` and `<`
This file proves basic results about orders, provides extensive dot notation, defines useful order
classes and allows to transfer order instances.
## Type synonyms
* `OrderDual α` : A type synonym reversing the meaning of all inequalities, with notation `αᵒᵈ`.
* `AsLinearOrder α`: A type synonym to promote `PartialOrder α` to `LinearOrder α` using
`IsTotal α (≤)`.
### Transfering orders
- `Order.Preimage`, `Preorder.lift`: Transfers a (pre)order on `β` to an order on `α`
using a function `f : α → β`.
- `PartialOrder.lift`, `LinearOrder.lift`: Transfers a partial (resp., linear) order on `β` to a
partial (resp., linear) order on `α` using an injective function `f`.
### Extra class
* `HasSup`: type class for the `⊔` notation
* `HasInf`: type class for the `⊓` notation
* `HasCompl`: type class for the `ᶜ` notation
* `DenselyOrdered`: An order with no gap, i.e. for any two elements `a < b` there exists `c` such
that `a < c < b`.
## Notes
`≤` and `<` are highly favored over `≥` and `>` in mathlib. The reason is that we can formulate all
lemmas using `≤`/`<`, and `rw` has trouble unifying `≤` and `≥`. Hence choosing one direction spares
us useless duplication. This is enforced by a linter. See Note [nolint_ge] for more infos.
Dot notation is particularly useful on `≤` (`LE.le`) and `<` (`LT.lt`). To that end, we
provide many aliases to dot notation-less lemmas. For example, `le_trans` is aliased with
`LE.le.trans` and can be used to construct `hab.trans hbc : a ≤ c` when `hab : a ≤ b`,
`hbc : b ≤ c`, `lt_of_le_of_lt` is aliased as `LE.le.trans_lt` and can be used to construct
`hab.trans hbc : a < c` when `hab : a ≤ b`, `hbc : b < c`.
## TODO
- expand module docs
- automatic construction of dual definitions / theorems
## Tags
preorder, order, partial order, poset, linear order, chain
-/
open Function
universe u v w
variable {ι : Type _} {α : Type u} {β : Type v} {γ : Type w} {π : ι → Type _} {r : α → α → Prop}
section Preorder
variable [Preorder α] {a b c : α}
theorem le_trans' : b ≤ c → a ≤ b → a ≤ c :=
flip le_trans
#align le_trans' le_trans'
theorem lt_trans' : b < c → a < b → a < c :=
flip lt_trans
#align lt_trans' lt_trans'
theorem lt_of_le_of_lt' : b ≤ c → a < b → a < c :=
flip lt_of_lt_of_le
#align lt_of_le_of_lt' lt_of_le_of_lt'
theorem lt_of_lt_of_le' : b < c → a ≤ b → a < c :=
flip lt_of_le_of_lt
#align lt_of_lt_of_le' lt_of_lt_of_le'
end Preorder
section PartialOrder
variable [PartialOrder α] {a b : α}
theorem ge_antisymm : a ≤ b → b ≤ a → b = a :=
flip le_antisymm
#align ge_antisymm ge_antisymm
theorem lt_of_le_of_ne' : a ≤ b → b ≠ a → a < b := fun h₁ h₂ ↦ lt_of_le_of_ne h₁ h₂.symm
#align lt_of_le_of_ne' lt_of_le_of_ne'
theorem Ne.lt_of_le : a ≠ b → a ≤ b → a < b :=
flip lt_of_le_of_ne
#align ne.lt_of_le Ne.lt_of_le
theorem Ne.lt_of_le' : b ≠ a → a ≤ b → a < b :=
flip lt_of_le_of_ne'
#align ne.lt_of_le' Ne.lt_of_le'
end PartialOrder
attribute [simp] le_refl
attribute [ext] LE
alias le_trans ← LE.le.trans
alias le_trans' ← LE.le.trans'
alias lt_of_le_of_lt ← LE.le.trans_lt
alias lt_of_le_of_lt' ← LE.le.trans_lt'
alias le_antisymm ← LE.le.antisymm
alias ge_antisymm ← LE.le.antisymm'
alias lt_of_le_of_ne ← LE.le.lt_of_ne
alias lt_of_le_of_ne' ← LE.le.lt_of_ne'
alias lt_of_le_not_le ← LE.le.lt_of_not_le
alias lt_or_eq_of_le ← LE.le.lt_or_eq
alias Decidable.lt_or_eq_of_le ← LE.le.lt_or_eq_dec
alias le_of_lt ← LT.lt.le
alias lt_trans ← LT.lt.trans
alias lt_trans' ← LT.lt.trans'
alias lt_of_lt_of_le ← LT.lt.trans_le
alias lt_of_lt_of_le' ← LT.lt.trans_le'
alias ne_of_lt ← LT.lt.ne
#align has_lt.lt.ne LT.lt.ne
alias lt_asymm ← LT.lt.asymm LT.lt.not_lt
alias le_of_eq ← Eq.le
-- Porting note: no `decidable_classical` linter
-- attribute [nolint decidable_classical] LE.le.lt_or_eq_dec
section
variable [Preorder α] {a b c : α}
/-- A version of `le_refl` where the argument is implicit -/
theorem le_rfl : a ≤ a :=
le_refl a
#align le_rfl le_rfl
@[simp]
theorem lt_self_iff_false (x : α) : x < x ↔ False :=
⟨lt_irrefl x, False.elim⟩
#align lt_self_iff_false lt_self_iff_false
theorem le_of_le_of_eq (hab : a ≤ b) (hbc : b = c) : a ≤ c :=
hab.trans hbc.le
#align le_of_le_of_eq le_of_le_of_eq
theorem le_of_eq_of_le (hab : a = b) (hbc : b ≤ c) : a ≤ c :=
hab.le.trans hbc
#align le_of_eq_of_le le_of_eq_of_le
theorem lt_of_lt_of_eq (hab : a < b) (hbc : b = c) : a < c :=
hab.trans_le hbc.le
#align lt_of_lt_of_eq lt_of_lt_of_eq
theorem lt_of_eq_of_lt (hab : a = b) (hbc : b < c) : a < c :=
hab.le.trans_lt hbc
#align lt_of_eq_of_lt lt_of_eq_of_lt
theorem le_of_le_of_eq' : b ≤ c → a = b → a ≤ c :=
flip le_of_eq_of_le
#align le_of_le_of_eq' le_of_le_of_eq'
theorem le_of_eq_of_le' : b = c → a ≤ b → a ≤ c :=
flip le_of_le_of_eq
#align le_of_eq_of_le' le_of_eq_of_le'
theorem lt_of_lt_of_eq' : b < c → a = b → a < c :=
flip lt_of_eq_of_lt
#align lt_of_lt_of_eq' lt_of_lt_of_eq'
theorem lt_of_eq_of_lt' : b = c → a < b → a < c :=
flip lt_of_lt_of_eq
#align lt_of_eq_of_lt' lt_of_eq_of_lt'
alias le_of_le_of_eq ← LE.le.trans_eq
alias le_of_le_of_eq' ← LE.le.trans_eq'
alias lt_of_lt_of_eq ← LT.lt.trans_eq
alias lt_of_lt_of_eq' ← LT.lt.trans_eq'
alias le_of_eq_of_le ← Eq.trans_le
alias le_of_eq_of_le' ← Eq.trans_ge
alias lt_of_eq_of_lt ← Eq.trans_lt
alias lt_of_eq_of_lt' ← Eq.trans_gt
end
namespace Eq
variable [Preorder α] {x y z : α}
/-- If `x = y` then `y ≤ x`. Note: this lemma uses `y ≤ x` instead of `x ≥ y`, because `le` is used
almost exclusively in mathlib. -/
protected theorem ge (h : x = y) : y ≤ x :=
h.symm.le
#align eq.ge Eq.ge
theorem not_lt (h : x = y) : ¬x < y := fun h' ↦ h'.ne h
#align eq.not_lt Eq.not_lt
theorem not_gt (h : x = y) : ¬y < x :=
h.symm.not_lt
#align eq.not_gt Eq.not_gt
end Eq
namespace LE.le
-- see Note [nolint_ge]
-- Porting note: linter not found @[nolint ge_or_gt]
protected theorem ge [LE α] {x y : α} (h : x ≤ y) : y ≥ x :=
h
#align has_le.le.ge LE.le.ge
section PartialOrder
variable [PartialOrder α] {a b : α}
theorem lt_iff_ne (h : a ≤ b) : a < b ↔ a ≠ b :=
⟨fun h ↦ h.ne, h.lt_of_ne⟩
#align has_le.le.lt_iff_ne LE.le.lt_iff_ne
theorem gt_iff_ne (h : a ≤ b) : a < b ↔ b ≠ a :=
⟨fun h ↦ h.ne.symm, h.lt_of_ne'⟩
#align has_le.le.gt_iff_ne LE.le.gt_iff_ne
theorem not_lt_iff_eq (h : a ≤ b) : ¬a < b ↔ a = b :=
h.lt_iff_ne.not_left
#align has_le.le.not_lt_iff_eq LE.le.not_lt_iff_eq
theorem not_gt_iff_eq (h : a ≤ b) : ¬a < b ↔ b = a :=
h.gt_iff_ne.not_left
#align has_le.le.not_gt_iff_eq LE.le.not_gt_iff_eq
theorem le_iff_eq (h : a ≤ b) : b ≤ a ↔ b = a :=
⟨fun h' ↦ h'.antisymm h, Eq.le⟩
#align has_le.le.le_iff_eq LE.le.le_iff_eq
theorem ge_iff_eq (h : a ≤ b) : b ≤ a ↔ a = b :=
⟨h.antisymm, Eq.ge⟩
#align has_le.le.ge_iff_eq LE.le.ge_iff_eq
end PartialOrder
theorem lt_or_le [LinearOrder α] {a b : α} (h : a ≤ b) (c : α) : a < c ∨ c ≤ b :=
((lt_or_ge a c).imp id) fun hc ↦ le_trans hc h
#align has_le.le.lt_or_le LE.le.lt_or_le
theorem le_or_lt [LinearOrder α] {a b : α} (h : a ≤ b) (c : α) : a ≤ c ∨ c < b :=
((le_or_gt a c).imp id) fun hc ↦ lt_of_lt_of_le hc h
#align has_le.le.le_or_lt LE.le.le_or_lt
theorem le_or_le [LinearOrder α] {a b : α} (h : a ≤ b) (c : α) : a ≤ c ∨ c ≤ b :=
(h.le_or_lt c).elim Or.inl fun h ↦ Or.inr <| le_of_lt h
#align has_le.le.le_or_le LE.le.le_or_le
end LE.le
namespace LT.lt
-- see Note [nolint_ge]
-- Porting note: linter not found @[nolint ge_or_gt]
protected theorem gt [LT α] {x y : α} (h : x < y) : y > x :=
h
#align has_lt.lt.gt LT.lt.gt
protected theorem false [Preorder α] {x : α} : x < x → False :=
lt_irrefl x
#align has_lt.lt.false LT.lt.false
theorem ne' [Preorder α] {x y : α} (h : x < y) : y ≠ x :=
h.ne.symm
#align has_lt.lt.ne' LT.lt.ne'
theorem lt_or_lt [LinearOrder α] {x y : α} (h : x < y) (z : α) : x < z ∨ z < y :=
(lt_or_ge z y).elim Or.inr fun hz ↦ Or.inl <| h.trans_le hz
#align has_lt.lt.lt_or_lt LT.lt.lt_or_lt
end LT.lt
-- see Note [nolint_ge]
-- Porting note: linter not found @[nolint ge_or_gt]
protected theorem GE.ge.le [LE α] {x y : α} (h : x ≥ y) : y ≤ x :=
h
#align ge.le GE.ge.le
-- see Note [nolint_ge]
-- Porting note: linter not found @[nolint ge_or_gt]
protected theorem GT.gt.lt [LT α] {x y : α} (h : x > y) : y < x :=
h
#align gt.lt GT.gt.lt
-- see Note [nolint_ge]
-- Porting note: linter not found @[nolint ge_or_gt]
theorem ge_of_eq [Preorder α] {a b : α} (h : a = b) : a ≥ b :=
h.ge
#align ge_of_eq ge_of_eq
-- see Note [nolint_ge]
-- Porting note: linter not found @[nolint ge_or_gt]
@[simp]
theorem ge_iff_le [LE α] {a b : α} : a ≥ b ↔ b ≤ a :=
Iff.rfl
#align ge_iff_le ge_iff_le
-- see Note [nolint_ge]
-- Porting note: linter not found @[nolint ge_or_gt]
@[simp]
theorem gt_iff_lt [LT α] {a b : α} : a > b ↔ b < a :=
Iff.rfl
#align gt_iff_lt gt_iff_lt
theorem not_le_of_lt [Preorder α] {a b : α} (h : a < b) : ¬b ≤ a :=
(le_not_le_of_lt h).right
#align not_le_of_lt not_le_of_lt
alias not_le_of_lt ← LT.lt.not_le
theorem not_lt_of_le [Preorder α] {a b : α} (h : a ≤ b) : ¬b < a := fun hba ↦ hba.not_le h
#align not_lt_of_le not_lt_of_le
alias not_lt_of_le ← LE.le.not_lt
theorem ne_of_not_le [Preorder α] {a b : α} (h : ¬a ≤ b) : a ≠ b := fun hab ↦ h (le_of_eq hab)
#align ne_of_not_le ne_of_not_le
-- See Note [decidable namespace]
protected theorem Decidable.le_iff_eq_or_lt [PartialOrder α] [@DecidableRel α (· ≤ ·)] {a b : α} :
a ≤ b ↔ a = b ∨ a < b :=
Decidable.le_iff_lt_or_eq.trans or_comm
#align decidable.le_iff_eq_or_lt Decidable.le_iff_eq_or_lt
theorem le_iff_eq_or_lt [PartialOrder α] {a b : α} : a ≤ b ↔ a = b ∨ a < b :=
le_iff_lt_or_eq.trans or_comm
#align le_iff_eq_or_lt le_iff_eq_or_lt
theorem lt_iff_le_and_ne [PartialOrder α] {a b : α} : a < b ↔ a ≤ b ∧ a ≠ b :=
⟨fun h ↦ ⟨le_of_lt h, ne_of_lt h⟩, fun ⟨h1, h2⟩ ↦ h1.lt_of_ne h2⟩
#align lt_iff_le_and_ne lt_iff_le_and_ne
-- See Note [decidable namespace]
protected theorem Decidable.eq_iff_le_not_lt [PartialOrder α] [@DecidableRel α (· ≤ ·)] {a b : α} :
a = b ↔ a ≤ b ∧ ¬a < b :=
⟨fun h ↦ ⟨h.le, h ▸ lt_irrefl _⟩, fun ⟨h₁, h₂⟩ ↦
h₁.antisymm <| Decidable.by_contradiction fun h₃ ↦ h₂ (h₁.lt_of_not_le h₃)⟩
#align decidable.eq_iff_le_not_lt Decidable.eq_iff_le_not_lt
theorem eq_iff_le_not_lt [PartialOrder α] {a b : α} : a = b ↔ a ≤ b ∧ ¬a < b :=
haveI := Classical.dec
Decidable.eq_iff_le_not_lt
#align eq_iff_le_not_lt eq_iff_le_not_lt
theorem eq_or_lt_of_le [PartialOrder α] {a b : α} (h : a ≤ b) : a = b ∨ a < b :=
h.lt_or_eq.symm
#align eq_or_lt_of_le eq_or_lt_of_le
theorem eq_or_gt_of_le [PartialOrder α] {a b : α} (h : a ≤ b) : b = a ∨ a < b :=
h.lt_or_eq.symm.imp Eq.symm id
#align eq_or_gt_of_le eq_or_gt_of_le
alias Decidable.eq_or_lt_of_le ← LE.le.eq_or_lt_dec
alias eq_or_lt_of_le ← LE.le.eq_or_lt
alias eq_or_gt_of_le ← LE.le.eq_or_gt
-- Porting note: no `decidable_classical` linter
-- attribute [nolint decidable_classical] LE.le.eq_or_lt_dec
theorem eq_of_le_of_not_lt [PartialOrder α] {a b : α} (hab : a ≤ b) (hba : ¬a < b) : a = b :=
hab.eq_or_lt.resolve_right hba
#align eq_of_le_of_not_lt eq_of_le_of_not_lt
theorem eq_of_ge_of_not_gt [PartialOrder α] {a b : α} (hab : a ≤ b) (hba : ¬a < b) : b = a :=
(hab.eq_or_lt.resolve_right hba).symm
#align eq_of_ge_of_not_gt eq_of_ge_of_not_gt
alias eq_of_le_of_not_lt ← LE.le.eq_of_not_lt
alias eq_of_ge_of_not_gt ← LE.le.eq_of_not_gt
theorem Ne.le_iff_lt [PartialOrder α] {a b : α} (h : a ≠ b) : a ≤ b ↔ a < b :=
⟨fun h' ↦ lt_of_le_of_ne h' h, fun h ↦ h.le⟩
#align ne.le_iff_lt Ne.le_iff_lt
theorem Ne.not_le_or_not_le [PartialOrder α] {a b : α} (h : a ≠ b) : ¬a ≤ b ∨ ¬b ≤ a :=
not_and_or.1 <| le_antisymm_iff.not.1 h
#align ne.not_le_or_not_le Ne.not_le_or_not_le
-- See Note [decidable namespace]
protected theorem Decidable.ne_iff_lt_iff_le [PartialOrder α] [DecidableEq α] {a b : α} :
(a ≠ b ↔ a < b) ↔ a ≤ b :=
⟨fun h ↦ Decidable.byCases le_of_eq (le_of_lt ∘ h.mp), fun h ↦ ⟨lt_of_le_of_ne h, ne_of_lt⟩⟩
#align decidable.ne_iff_lt_iff_le Decidable.ne_iff_lt_iff_le
@[simp]
theorem ne_iff_lt_iff_le [PartialOrder α] {a b : α} : (a ≠ b ↔ a < b) ↔ a ≤ b :=
haveI := Classical.dec
Decidable.ne_iff_lt_iff_le
#align ne_iff_lt_iff_le ne_iff_lt_iff_le
-- Variant of `min_def` with the branches reversed.
theorem min_def' [LinearOrder α] (a b : α) : min a b = if b ≤ a then b else a := by
rw [min_def]
rcases lt_trichotomy a b with (lt | eq | gt)
· rw [if_pos lt.le, if_neg (not_le.mpr lt)]
· rw [if_pos eq.le, if_pos eq.ge, eq]
· rw [if_neg (not_le.mpr gt.gt), if_pos gt.le]
#align min_def' min_def'
-- Variant of `min_def` with the branches reversed.
-- This is sometimes useful as it used to be the default.
theorem max_def' [LinearOrder α] (a b : α) : max a b = if b ≤ a then a else b := by
rw [max_def]
rcases lt_trichotomy a b with (lt | eq | gt)
· rw [if_pos lt.le, if_neg (not_le.mpr lt)]
· rw [if_pos eq.le, if_pos eq.ge, eq]
· rw [if_neg (not_le.mpr gt.gt), if_pos gt.le]
#align max_def' max_def'
theorem lt_of_not_le [LinearOrder α] {a b : α} (h : ¬b ≤ a) : a < b :=
((le_total _ _).resolve_right h).lt_of_not_le h
#align lt_of_not_le lt_of_not_le
theorem lt_iff_not_le [LinearOrder α] {x y : α} : x < y ↔ ¬y ≤ x :=
⟨not_le_of_lt, lt_of_not_le⟩
#align lt_iff_not_le lt_iff_not_le
theorem Ne.lt_or_lt [LinearOrder α] {x y : α} (h : x ≠ y) : x < y ∨ y < x :=
lt_or_gt_of_ne h
#align ne.lt_or_lt Ne.lt_or_lt
/-- A version of `ne_iff_lt_or_gt` with LHS and RHS reversed. -/
@[simp]
theorem lt_or_lt_iff_ne [LinearOrder α] {x y : α} : x < y ∨ y < x ↔ x ≠ y :=
ne_iff_lt_or_gt.symm
#align lt_or_lt_iff_ne lt_or_lt_iff_ne
theorem not_lt_iff_eq_or_lt [LinearOrder α] {a b : α} : ¬a < b ↔ a = b ∨ b < a :=
not_lt.trans <| Decidable.le_iff_eq_or_lt.trans <| or_congr eq_comm Iff.rfl
#align not_lt_iff_eq_or_lt not_lt_iff_eq_or_lt
theorem exists_ge_of_linear [LinearOrder α] (a b : α) : ∃ c, a ≤ c ∧ b ≤ c :=
match le_total a b with
| Or.inl h => ⟨_, h, le_rfl⟩
| Or.inr h => ⟨_, le_rfl, h⟩
#align exists_ge_of_linear exists_ge_of_linear
theorem lt_imp_lt_of_le_imp_le {β} [LinearOrder α] [Preorder β] {a b : α} {c d : β}
(H : a ≤ b → c ≤ d) (h : d < c) : b < a :=
lt_of_not_le fun h' ↦ (H h').not_lt h
#align lt_imp_lt_of_le_imp_le lt_imp_lt_of_le_imp_le
theorem le_imp_le_iff_lt_imp_lt {β} [LinearOrder α] [LinearOrder β] {a b : α} {c d : β} :
a ≤ b → c ≤ d ↔ d < c → b < a :=
⟨lt_imp_lt_of_le_imp_le, le_imp_le_of_lt_imp_lt⟩
#align le_imp_le_iff_lt_imp_lt le_imp_le_iff_lt_imp_lt
theorem lt_iff_lt_of_le_iff_le' {β} [Preorder α] [Preorder β] {a b : α} {c d : β}
(H : a ≤ b ↔ c ≤ d) (H' : b ≤ a ↔ d ≤ c) : b < a ↔ d < c :=
lt_iff_le_not_le.trans <| (and_congr H' (not_congr H)).trans lt_iff_le_not_le.symm
#align lt_iff_lt_of_le_iff_le' lt_iff_lt_of_le_iff_le'
theorem lt_iff_lt_of_le_iff_le {β} [LinearOrder α] [LinearOrder β] {a b : α} {c d : β}
(H : a ≤ b ↔ c ≤ d) : b < a ↔ d < c :=
not_le.symm.trans <| (not_congr H).trans <| not_le
#align lt_iff_lt_of_le_iff_le lt_iff_lt_of_le_iff_le
theorem le_iff_le_iff_lt_iff_lt {β} [LinearOrder α] [LinearOrder β] {a b : α} {c d : β} :
(a ≤ b ↔ c ≤ d) ↔ (b < a ↔ d < c) :=
⟨lt_iff_lt_of_le_iff_le, fun H ↦ not_lt.symm.trans <| (not_congr H).trans <| not_lt⟩
#align le_iff_le_iff_lt_iff_lt le_iff_le_iff_lt_iff_lt
theorem eq_of_forall_le_iff [PartialOrder α] {a b : α} (H : ∀ c, c ≤ a ↔ c ≤ b) : a = b :=
((H _).1 le_rfl).antisymm ((H _).2 le_rfl)
#align eq_of_forall_le_iff eq_of_forall_le_iff
theorem le_of_forall_le [Preorder α] {a b : α} (H : ∀ c, c ≤ a → c ≤ b) : a ≤ b :=
H _ le_rfl
#align le_of_forall_le le_of_forall_le
theorem le_of_forall_le' [Preorder α] {a b : α} (H : ∀ c, a ≤ c → b ≤ c) : b ≤ a :=
H _ le_rfl
#align le_of_forall_le' le_of_forall_le'
theorem le_of_forall_lt [LinearOrder α] {a b : α} (H : ∀ c, c < a → c < b) : a ≤ b :=
le_of_not_lt fun h ↦ lt_irrefl _ (H _ h)
#align le_of_forall_lt le_of_forall_lt
theorem forall_lt_iff_le [LinearOrder α] {a b : α} : (∀ ⦃c⦄, c < a → c < b) ↔ a ≤ b :=
⟨le_of_forall_lt, fun h _ hca ↦ lt_of_lt_of_le hca h⟩
#align forall_lt_iff_le forall_lt_iff_le
theorem le_of_forall_lt' [LinearOrder α] {a b : α} (H : ∀ c, a < c → b < c) : b ≤ a :=
le_of_not_lt fun h ↦ lt_irrefl _ (H _ h)
#align le_of_forall_lt' le_of_forall_lt'
theorem forall_lt_iff_le' [LinearOrder α] {a b : α} : (∀ ⦃c⦄, a < c → b < c) ↔ b ≤ a :=
⟨le_of_forall_lt', fun h _ hac ↦ lt_of_le_of_lt h hac⟩
#align forall_lt_iff_le' forall_lt_iff_le'
theorem eq_of_forall_ge_iff [PartialOrder α] {a b : α} (H : ∀ c, a ≤ c ↔ b ≤ c) : a = b :=
((H _).2 le_rfl).antisymm ((H _).1 le_rfl)
#align eq_of_forall_ge_iff eq_of_forall_ge_iff
theorem eq_of_forall_lt_iff [LinearOrder α] {a b : α} (h : ∀ c, c < a ↔ c < b) : a = b :=
(le_of_forall_lt fun _ ↦ (h _).1).antisymm <| le_of_forall_lt fun _ ↦ (h _).2
#align eq_of_forall_lt_iff eq_of_forall_lt_iff
theorem eq_of_forall_gt_iff [LinearOrder α] {a b : α} (h : ∀ c, a < c ↔ b < c) : a = b :=
(le_of_forall_lt' fun _ ↦ (h _).2).antisymm <| le_of_forall_lt' fun _ ↦ (h _).1
#align eq_of_forall_gt_iff eq_of_forall_gt_iff
/-- A symmetric relation implies two values are equal, when it implies they're less-equal. -/
theorem rel_imp_eq_of_rel_imp_le [PartialOrder β] (r : α → α → Prop) [IsSymm α r] {f : α → β}
(h : ∀ a b, r a b → f a ≤ f b) {a b : α} : r a b → f a = f b := fun hab ↦
le_antisymm (h a b hab) (h b a <| symm hab)
#align rel_imp_eq_of_rel_imp_le rel_imp_eq_of_rel_imp_le
/-- monotonicity of `≤` with respect to `→` -/
theorem le_implies_le_of_le_of_le {a b c d : α} [Preorder α] (hca : c ≤ a) (hbd : b ≤ d) :
a ≤ b → c ≤ d :=
fun hab ↦ (hca.trans hab).trans hbd
#align le_implies_le_of_le_of_le le_implies_le_of_le_of_le
section PartialOrder
variable [PartialOrder α]
/-- To prove commutativity of a binary operation `○`, we only to check `a ○ b ≤ b ○ a` for all `a`,
`b`. -/
theorem commutative_of_le {f : β → β → α} (comm : ∀ a b, f a b ≤ f b a) : ∀ a b, f a b = f b a :=
fun _ _ ↦ (comm _ _).antisymm <| comm _ _
#align commutative_of_le commutative_of_le
/-- To prove associativity of a commutative binary operation `○`, we only to check
`(a ○ b) ○ c ≤ a ○ (b ○ c)` for all `a`, `b`, `c`. -/
theorem associative_of_commutative_of_le {f : α → α → α} (comm : Commutative f)
(assoc : ∀ a b c, f (f a b) c ≤ f a (f b c)) : Associative f := fun a b c ↦
le_antisymm (assoc _ _ _) <| by
rw [comm, comm b, comm _ c, comm a]
exact assoc _ _ _
#align associative_of_commutative_of_le associative_of_commutative_of_le
end PartialOrder
@[ext]
theorem Preorder.toLE_injective {α : Type _} : Function.Injective (@Preorder.toLE α) :=
fun A B h ↦ match A, B with
| { lt := A_lt, lt_iff_le_not_le := A_iff, .. },
{ lt := B_lt, lt_iff_le_not_le := B_iff, .. } => by
cases h
have : A_lt = B_lt := by
funext a b
show (LT.mk A_lt).lt a b = (LT.mk B_lt).lt a b
rw [A_iff, B_iff]
cases this
congr
#align preorder.to_has_le_injective Preorder.toLE_injective
@[ext]
theorem PartialOrder.toPreorder_injective {α : Type _} :
Function.Injective (@PartialOrder.toPreorder α) := fun A B h ↦ by
cases A
cases B
cases h
congr
#align partial_order.to_preorder_injective PartialOrder.toPreorder_injective
@[ext]
theorem LinearOrder.toPartialOrder_injective {α : Type _} :
Function.Injective (@LinearOrder.toPartialOrder α) :=
fun A B h ↦ match A, B with
| { le := A_le, lt := A_lt, decidable_le := A_decidable_le,
min := A_min, max := A_max, min_def := A_min_def, max_def := A_max_def, .. },
{ le := B_le, lt := B_lt, decidable_le := B_decidable_le,
min := B_min, max := B_max, min_def := B_min_def, max_def := B_max_def, .. } => by
cases h
obtain rfl : A_decidable_le = B_decidable_le := Subsingleton.elim _ _
have : A_min = B_min := by
funext a b
exact (A_min_def _ _).trans (B_min_def _ _).symm
cases this
have : A_max = B_max := by
funext a b
exact (A_max_def _ _).trans (B_max_def _ _).symm
cases this
congr <;> exact Subsingleton.elim _ _
#align linear_order.to_partial_order_injective LinearOrder.toPartialOrder_injective
theorem Preorder.ext {α} {A B : Preorder α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) : A = B := by
ext x y
exact H x y
#align preorder.ext Preorder.ext
theorem PartialOrder.ext {α} {A B : PartialOrder α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) : A = B := by
ext x y
exact H x y
#align partial_order.ext PartialOrder.ext
theorem LinearOrder.ext {α} {A B : LinearOrder α}
(H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) : A = B := by
ext x y
exact H x y
#align linear_order.ext LinearOrder.ext
/-- Given a relation `R` on `β` and a function `f : α → β`, the preimage relation on `α` is defined
by `x ≤ y ↔ f x ≤ f y`. It is the unique relation on `α` making `f` a `RelEmbedding` (assuming `f`
is injective). -/
@[simp]
def Order.Preimage {α β} (f : α → β) (s : β → β → Prop) (x y : α) : Prop :=
s (f x) (f y)
#align order.preimage Order.Preimage
@[inherit_doc]
infixl:80 " ⁻¹'o " => Order.Preimage
/-- The preimage of a decidable order is decidable. -/
instance Order.Preimage.decidable {α β} (f : α → β) (s : β → β → Prop) [H : DecidableRel s] :
DecidableRel (f ⁻¹'o s) := fun _ _ ↦ H _ _
#align order.preimage.decidable Order.Preimage.decidable
/-! ### Order dual -/
/-- Type synonym to equip a type with the dual order: `≤` means `≥` and `<` means `>`. `αᵒᵈ` is
notation for `OrderDual α`. -/
def OrderDual (α : Type _) : Type _ :=
α
#align order_dual OrderDual
@[inherit_doc]
notation:max α "ᵒᵈ" => OrderDual α
namespace OrderDual
instance (α : Type _) [h : Nonempty α] : Nonempty αᵒᵈ :=
h
instance (α : Type _) [h : Subsingleton α] : Subsingleton αᵒᵈ :=
h
instance (α : Type _) [LE α] : LE αᵒᵈ :=
⟨fun x y : α ↦ y ≤ x⟩
instance (α : Type _) [LT α] : LT αᵒᵈ :=
⟨fun x y : α ↦ y < x⟩
instance preorder (α : Type _) [Preorder α] : Preorder αᵒᵈ where
le_refl := fun _ ↦ le_refl _
le_trans := fun _ _ _ hab hbc ↦ hbc.trans hab
lt_iff_le_not_le := fun _ _ ↦ lt_iff_le_not_le
instance partialOrder (α : Type _) [PartialOrder α] : PartialOrder αᵒᵈ where
__ := inferInstanceAs (Preorder αᵒᵈ)
le_antisymm := fun a b hab hba ↦ @le_antisymm α _ a b hba hab
instance linearOrder (α : Type _) [LinearOrder α] : LinearOrder αᵒᵈ where
__ := inferInstanceAs (PartialOrder αᵒᵈ)
le_total := λ a b : α => le_total b a
max := fun a b ↦ (min a b : α)
min := fun a b ↦ (max a b : α)
min_def := fun a b ↦ show (max .. : α) = _ by rw [max_comm, max_def]; rfl
max_def := fun a b ↦ show (min .. : α) = _ by rw [min_comm, min_def]; rfl
decidable_le := (inferInstance : DecidableRel (λ a b : α => b ≤ a))
decidable_lt := (inferInstance : DecidableRel (λ a b : α => b < a))
#align order_dual.linear_order OrderDual.linearOrder
instance : ∀ [Inhabited α], Inhabited αᵒᵈ := λ [x: Inhabited α] => x
theorem Preorder.dual_dual (α : Type _) [H : Preorder α] : OrderDual.preorder αᵒᵈ = H :=
Preorder.ext fun _ _ ↦ Iff.rfl
#align order_dual.preorder.dual_dual OrderDual.Preorder.dual_dual
theorem partialOrder.dual_dual (α : Type _) [H : PartialOrder α] : OrderDual.partialOrder αᵒᵈ = H :=
PartialOrder.ext fun _ _ ↦ Iff.rfl
#align order_dual.partial_order.dual_dual OrderDual.partialOrder.dual_dual
theorem linearOrder.dual_dual (α : Type _) [H : LinearOrder α] : OrderDual.linearOrder αᵒᵈ = H :=
LinearOrder.ext fun _ _ ↦ Iff.rfl
#align order_dual.linear_order.dual_dual OrderDual.linearOrder.dual_dual
end OrderDual
/-! ### `HasCompl` -/
/-- Set / lattice complement -/
@[notation_class]
class HasCompl (α : Type _) where
/-- Set / lattice complement -/
compl : α → α
#align has_compl HasCompl
export HasCompl (compl)
@[inherit_doc]
postfix:999 "ᶜ" => compl
instance Prop.hasCompl : HasCompl Prop :=
⟨Not⟩
#align Prop.has_compl Prop.hasCompl
instance Pi.hasCompl {ι : Type u} {α : ι → Type v} [∀ i, HasCompl (α i)] : HasCompl (∀ i, α i) :=
⟨fun x i ↦ x iᶜ⟩
#align pi.has_compl Pi.hasCompl
theorem Pi.compl_def {ι : Type u} {α : ι → Type v} [∀ i, HasCompl (α i)] (x : ∀ i, α i) :
xᶜ = fun i ↦ x iᶜ :=
rfl
#align pi.compl_def Pi.compl_def
@[simp]
theorem Pi.compl_apply {ι : Type u} {α : ι → Type v} [∀ i, HasCompl (α i)] (x : ∀ i, α i) (i : ι) :
(xᶜ) i = x iᶜ :=
rfl
#align pi.compl_apply Pi.compl_apply
instance IsIrrefl.compl (r) [IsIrrefl α r] : IsRefl α (rᶜ) :=
⟨@irrefl α r _⟩
#align is_irrefl.compl IsIrrefl.compl
instance IsRefl.compl (r) [IsRefl α r] : IsIrrefl α (rᶜ) :=
⟨fun a ↦ not_not_intro (refl a)⟩
#align is_refl.compl IsRefl.compl
/-! ### Order instances on the function space -/
instance Pi.hasLe {ι : Type u} {α : ι → Type v} [∀ i, LE (α i)] :
LE (∀ i, α i) where le x y := ∀ i, x i ≤ y i
#align pi.has_le Pi.hasLe
theorem Pi.le_def {ι : Type u} {α : ι → Type v} [∀ i, LE (α i)] {x y : ∀ i, α i} :
x ≤ y ↔ ∀ i, x i ≤ y i :=
Iff.rfl
#align pi.le_def Pi.le_def
instance Pi.preorder {ι : Type u} {α : ι → Type v} [∀ i, Preorder (α i)] : Preorder (∀ i, α i) where
__ := inferInstanceAs (LE (∀ i, α i))
le_refl := fun a i ↦ le_refl (a i)
le_trans := fun a b c h₁ h₂ i ↦ le_trans (h₁ i) (h₂ i)
#align pi.preorder Pi.preorder
theorem Pi.lt_def {ι : Type u} {α : ι → Type v} [∀ i, Preorder (α i)] {x y : ∀ i, α i} :
x < y ↔ x ≤ y ∧ ∃ i, x i < y i := by
simp (config := { contextual := true }) [lt_iff_le_not_le, Pi.le_def]
#align pi.lt_def Pi.lt_def
instance Pi.partialOrder [∀ i, PartialOrder (π i)] : PartialOrder (∀ i, π i) where
__ := Pi.preorder
le_antisymm := fun _ _ h1 h2 ↦ funext fun b ↦ (h1 b).antisymm (h2 b)
#align pi.partial_order Pi.partialOrder
section Pi
/-- A function `a` is strongly less than a function `b` if `a i < b i` for all `i`. -/
def StrongLT [∀ i, LT (π i)] (a b : ∀ i, π i) : Prop :=
∀ i, a i < b i
#align strong_lt StrongLT
@[inherit_doc]
local infixl:50 " ≺ " => StrongLT
variable [∀ i, Preorder (π i)] {a b c : ∀ i, π i}
theorem le_of_strongLT (h : a ≺ b) : a ≤ b := fun _ ↦ (h _).le
#align le_of_strong_lt le_of_strongLT
theorem lt_of_strongLT [Nonempty ι] (h : a ≺ b) : a < b := by
inhabit ι
exact Pi.lt_def.2 ⟨le_of_strongLT h, default, h _⟩
#align lt_of_strong_lt lt_of_strongLT
theorem strongLT_of_strongLT_of_le (hab : a ≺ b) (hbc : b ≤ c) : a ≺ c := fun _ ↦
(hab _).trans_le <| hbc _
#align strong_lt_of_strong_lt_of_le strongLT_of_strongLT_of_le
theorem strongLT_of_le_of_strongLT (hab : a ≤ b) (hbc : b ≺ c) : a ≺ c := fun _ ↦
(hab _).trans_lt <| hbc _
#align strong_lt_of_le_of_strong_lt strongLT_of_le_of_strongLT
alias le_of_strongLT ← StrongLT.le
alias lt_of_strongLT ← StrongLT.lt
alias strongLT_of_strongLT_of_le ← StrongLT.trans_le
alias strongLT_of_le_of_strongLT ← LE.le.trans_strongLT
end Pi
section Function
variable [DecidableEq ι] [∀ i, Preorder (π i)] {x y : ∀ i, π i} {i : ι} {a b : π i}
theorem le_update_iff : x ≤ Function.update y i a ↔ x i ≤ a ∧ ∀ (j) (_ : j ≠ i), x j ≤ y j :=
Function.forall_update_iff _ fun j z ↦ x j ≤ z
#align le_update_iff le_update_iff
theorem update_le_iff : Function.update x i a ≤ y ↔ a ≤ y i ∧ ∀ (j) (_ : j ≠ i), x j ≤ y j :=
Function.forall_update_iff _ fun j z ↦ z ≤ y j
#align update_le_iff update_le_iff
theorem update_le_update_iff :
Function.update x i a ≤ Function.update y i b ↔ a ≤ b ∧ ∀ (j) (_ : j ≠ i), x j ≤ y j := by
simp (config := { contextual := true }) [update_le_iff]
#align update_le_update_iff update_le_update_iff
@[simp]
theorem le_update_self_iff : x ≤ update x i a ↔ x i ≤ a := by simp [le_update_iff]
#align le_update_self_iff le_update_self_iff
@[simp]
theorem update_le_self_iff : update x i a ≤ x ↔ a ≤ x i := by simp [update_le_iff]
#align update_le_self_iff update_le_self_iff
@[simp]
theorem lt_update_self_iff : x < update x i a ↔ x i < a := by simp [lt_iff_le_not_le]
#align lt_update_self_iff lt_update_self_iff
@[simp]
theorem update_lt_self_iff : update x i a < x ↔ a < x i := by simp [lt_iff_le_not_le]
#align update_lt_self_iff update_lt_self_iff
end Function
instance Pi.sdiff {ι : Type u} {α : ι → Type v} [∀ i, SDiff (α i)] : SDiff (∀ i, α i) :=
⟨fun x y i ↦ x i \ y i⟩
#align pi.has_sdiff Pi.sdiff
theorem Pi.sdiff_def {ι : Type u} {α : ι → Type v} [∀ i, SDiff (α i)] (x y : ∀ i, α i) :
x \ y = fun i ↦ x i \ y i :=
rfl
#align pi.sdiff_def Pi.sdiff_def
@[simp]
theorem Pi.sdiff_apply {ι : Type u} {α : ι → Type v} [∀ i, SDiff (α i)] (x y : ∀ i, α i) (i : ι) :
(x \ y) i = x i \ y i :=
rfl
#align pi.sdiff_apply Pi.sdiff_apply
namespace Function
variable [Preorder α] [Nonempty β] {a b : α}
@[simp]
theorem const_le_const : const β a ≤ const β b ↔ a ≤ b := by simp [Pi.le_def]
#align function.const_le_const Function.const_le_const
@[simp]
theorem const_lt_const : const β a < const β b ↔ a < b := by simpa [Pi.lt_def] using le_of_lt
#align function.const_lt_const Function.const_lt_const
end Function
/-! ### `min`/`max` recursors -/
section MinMaxRec
variable [LinearOrder α] {p : α → Prop} {x y : α}
theorem min_rec (hx : x ≤ y → p x) (hy : y ≤ x → p y) : p (min x y) :=
(le_total x y).rec (fun h ↦ (min_eq_left h).symm.subst (hx h)) fun h ↦
(min_eq_right h).symm.subst (hy h)
#align min_rec min_rec
theorem max_rec (hx : y ≤ x → p x) (hy : x ≤ y → p y) : p (max x y) :=
@min_rec αᵒᵈ _ _ _ _ hx hy
#align max_rec max_rec
theorem min_rec' (p : α → Prop) (hx : p x) (hy : p y) : p (min x y) :=
min_rec (fun _ ↦ hx) fun _ ↦ hy
#align min_rec' min_rec'
theorem max_rec' (p : α → Prop) (hx : p x) (hy : p y) : p (max x y) :=
max_rec (fun _ ↦ hx) fun _ ↦ hy
#align max_rec' max_rec'
theorem min_def_lt (x y : α) : min x y = if x < y then x else y := by
rw [min_comm, min_def, ← ite_not]
simp only [not_le]
#align min_def_lt min_def_lt
theorem max_def_lt (x y : α) : max x y = if x < y then y else x := by
rw [max_comm, max_def, ← ite_not]
simp only [not_le]
#align max_def_lt max_def_lt
end MinMaxRec
/-! ### `HasSup` and `HasInf` -/
/-- Typeclass for the `⊔` (`\lub`) notation -/
@[notation_class, ext]
class HasSup (α : Type u) where
/-- Least upper bound (`\lub` notation) -/
sup : α → α → α
#align has_sup HasSup
/-- Typeclass for the `⊓` (`\glb`) notation -/
@[notation_class, ext]
class HasInf (α : Type u) where
/-- Greatest lower bound (`\glb` notation) -/
inf : α → α → α
#align has_inf HasInf
@[inherit_doc]
infixl:68 " ⊔ " => HasSup.sup
@[inherit_doc]
infixl:69 " ⊓ " => HasInf.inf
/-! ### Lifts of order instances -/
/-- Transfer a `Preorder` on `β` to a `Preorder` on `α` using a function `f : α → β`.
See note [reducible non-instances]. -/
@[reducible]
def Preorder.lift {α β} [Preorder β] (f : α → β) : Preorder α where
le x y := f x ≤ f y
le_refl _ := le_rfl
le_trans _ _ _ := _root_.le_trans
lt x y := f x < f y
lt_iff_le_not_le _ _ := _root_.lt_iff_le_not_le
#align preorder.lift Preorder.lift
/-- Transfer a `PartialOrder` on `β` to a `PartialOrder` on `α` using an injective
function `f : α → β`. See note [reducible non-instances]. -/
@[reducible]
def PartialOrder.lift {α β} [PartialOrder β] (f : α → β) (inj : Injective f) : PartialOrder α :=
{ Preorder.lift f with le_antisymm := fun _ _ h₁ h₂ ↦ inj (h₁.antisymm h₂) }
#align partial_order.lift PartialOrder.lift
/-- Transfer a `LinearOrder` on `β` to a `LinearOrder` on `α` using an injective
function `f : α → β`. This version takes `[HasSup α]` and `[HasInf α]` as arguments, then uses
them for `max` and `min` fields. See `LinearOrder.lift'` for a version that autogenerates `min` and
`max` fields. See note [reducible non-instances]. -/
@[reducible]
def LinearOrder.lift {α β} [LinearOrder β] [HasSup α] [HasInf α] (f : α → β) (inj : Injective f)
(hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y)) (hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y)) :
LinearOrder α :=
{ PartialOrder.lift f inj with
le_total := fun x y ↦ le_total (f x) (f y)
decidable_le := fun x y ↦ (inferInstance : Decidable (f x ≤ f y))
decidable_lt := fun x y ↦ (inferInstance : Decidable (f x < f y))
decidable_eq := fun x y ↦ decidable_of_iff (f x = f y) inj.eq_iff
min := (· ⊓ ·)
max := (· ⊔ ·)
min_def := by
intros x y
apply inj
rw [apply_ite f]
exact (hinf _ _).trans (min_def _ _)
max_def := by