@@ -9,6 +9,7 @@ import Mathlib.Tactic.ExtendDoc
99import Mathlib.Tactic.Lemma
1010import Mathlib.Tactic.SplitIfs
1111import Mathlib.Tactic.TypeStar
12+ import Mathlib.Tactic.ToDual
1213
1314/-!
1415# Orders
@@ -43,6 +44,9 @@ class Preorder (α : Type*) extends LE α, LT α where
4344 lt := fun a b => a ≤ b ∧ ¬b ≤ a
4445 lt_iff_le_not_ge : ∀ a b : α, a < b ↔ a ≤ b ∧ ¬b ≤ a := by intros; rfl
4546
47+ attribute [to_dual self (reorder := 3 5, 6 7)] Preorder.le_trans
48+ attribute [to_dual self (reorder := 3 4)] Preorder.lt_iff_le_not_ge
49+
4650instance [Preorder α] : Std.LawfulOrderLT α where
4751 lt_iff := Preorder.lt_iff_le_not_ge
4852
@@ -61,79 +65,92 @@ variable [Preorder α] {a b c : α}
6165lemma le_rfl : a ≤ a := le_refl a
6266
6367/-- The relation `≤` on a preorder is transitive. -/
64- lemma le_trans : a ≤ b → b ≤ c → a ≤ c := Preorder.le_trans _ _ _
68+ @[to_dual ge_trans] lemma le_trans : a ≤ b → b ≤ c → a ≤ c := Preorder.le_trans _ _ _
6569
70+ @[to_dual self (reorder := 3 4)]
6671lemma lt_iff_le_not_ge : a < b ↔ a ≤ b ∧ ¬b ≤ a := Preorder.lt_iff_le_not_ge _ _
6772
6873@[deprecated (since := "2025-05-11")] alias lt_iff_le_not_le := lt_iff_le_not_ge
6974
75+ @[to_dual self (reorder := 3 4)]
7076lemma lt_of_le_not_ge (hab : a ≤ b) (hba : ¬ b ≤ a) : a < b := lt_iff_le_not_ge.2 ⟨hab, hba⟩
7177
7278@[deprecated (since := "2025-05-11")] alias lt_of_le_not_le := lt_of_le_not_ge
7379
80+ @[to_dual ge_of_eq]
7481lemma le_of_eq (hab : a = b) : a ≤ b := by rw [hab]
82+ @[to_dual self (reorder := 3 4)]
7583lemma le_of_lt (hab : a < b) : a ≤ b := (lt_iff_le_not_ge.1 hab).1
84+ @[to_dual self (reorder := 3 4)]
7685lemma not_le_of_gt (hab : a < b) : ¬ b ≤ a := (lt_iff_le_not_ge.1 hab).2
86+ @[to_dual self (reorder := 3 4)]
7787lemma not_lt_of_ge (hab : a ≤ b) : ¬ b < a := imp_not_comm.1 not_le_of_gt hab
7888
7989@[deprecated (since := "2025-05-11")] alias not_le_of_lt := not_le_of_gt
8090@[deprecated (since := "2025-05-11")] alias not_lt_of_le := not_lt_of_ge
8191
82- alias LT.lt.not_ge := not_le_of_gt
83- alias LE.le.not_gt := not_lt_of_ge
92+ @[to_dual self (reorder := 3 4)] alias LT.lt.not_ge := not_le_of_gt
93+ @[to_dual self (reorder := 3 4)] alias LE.le.not_gt := not_lt_of_ge
8494
8595@[deprecated (since := "2025-06-07")] alias LT.lt.not_le := LT.lt.not_ge
8696@[deprecated (since := "2025-06-07")] alias LE.le.not_lt := LE.le.not_gt
8797
88-
89- lemma ge_trans : b ≤ a → c ≤ b → c ≤ a := fun h₁ h₂ => le_trans h₂ h₁
90-
91- lemma lt_irrefl (a : α) : ¬a < a := fun h ↦ not_le_of_gt h le_rfl
98+ @[to_dual self] lemma lt_irrefl (a : α) : ¬a < a := fun h ↦ not_le_of_gt h le_rfl
9299
93100@[deprecated (since := "2025-06-07")] alias gt_irrefl := lt_irrefl
94101
102+ @[to_dual lt_of_lt_of_le']
95103lemma lt_of_lt_of_le (hab : a < b) (hbc : b ≤ c) : a < c :=
96104 lt_of_le_not_ge (le_trans (le_of_lt hab) hbc) fun hca ↦ not_le_of_gt hab (le_trans hbc hca)
97105
106+ @[to_dual lt_of_le_of_lt']
98107lemma lt_of_le_of_lt (hab : a ≤ b) (hbc : b < c) : a < c :=
99108 lt_of_le_not_ge (le_trans hab (le_of_lt hbc)) fun hca ↦ not_le_of_gt hbc (le_trans hca hab)
100109
101- lemma lt_of_lt_of_le' : b < a → c ≤ b → c < a := flip lt_of_le_of_lt
102- lemma lt_of_le_of_lt' : b ≤ a → c < b → c < a := flip lt_of_lt_of_le
103-
104110@[deprecated (since := "2025-06-07")] alias gt_of_gt_of_ge := lt_of_lt_of_le'
105111@[deprecated (since := "2025-06-07")] alias gt_of_ge_of_gt := lt_of_le_of_lt'
106112
113+ @[to_dual gt_trans]
107114lemma lt_trans : a < b → b < c → a < c := fun h₁ h₂ => lt_of_lt_of_le h₁ (le_of_lt h₂)
108- lemma gt_trans : b < a → c < b → c < a := flip lt_trans
109115
116+ @[to_dual ne_of_gt]
110117lemma ne_of_lt (h : a < b) : a ≠ b := fun he => absurd h (he ▸ lt_irrefl a)
111- lemma ne_of_gt (h : b < a) : a ≠ b := fun he => absurd h (he ▸ lt_irrefl a)
118+ @[to_dual self (reorder := 3 4)]
112119lemma lt_asymm (h : a < b) : ¬b < a := fun h1 : b < a => lt_irrefl a (lt_trans h h1)
113120
121+ @[to_dual self (reorder := 3 4)]
114122alias not_lt_of_gt := lt_asymm
115-
116123@[deprecated (since := "2025-05-11")] alias not_lt_of_lt := not_lt_of_gt
117124
125+ @[to_dual le_of_lt_or_eq']
118126lemma le_of_lt_or_eq (h : a < b ∨ a = b) : a ≤ b := h.elim le_of_lt le_of_eq
127+ @[to_dual le_of_eq_or_lt']
119128lemma le_of_eq_or_lt (h : a = b ∨ a < b) : a ≤ b := h.elim le_of_eq le_of_lt
120129
121- instance : @Trans α α α LE.le LE.le LE.le := ⟨le_trans⟩
122- instance : @Trans α α α LT.lt LT.lt LT.lt := ⟨lt_trans⟩
123- instance : @Trans α α α LT.lt LE.le LT.lt := ⟨lt_of_lt_of_le⟩
124- instance : @Trans α α α LE.le LT.lt LT.lt := ⟨lt_of_le_of_lt⟩
125- instance : @Trans α α α GE.ge GE.ge GE.ge := ⟨ge_trans⟩
126- instance : @Trans α α α GT.gt GT.gt GT.gt := ⟨gt_trans⟩
127- instance : @Trans α α α GT.gt GE.ge GT.gt := ⟨lt_of_lt_of_le'⟩
128- instance : @Trans α α α GE.ge GT.gt GT.gt := ⟨lt_of_le_of_lt'⟩
130+ instance instTransLE : @Trans α α α LE.le LE.le LE.le := ⟨le_trans⟩
131+ instance instTransLT : @Trans α α α LT.lt LT.lt LT.lt := ⟨lt_trans⟩
132+ instance instTransLTLE : @Trans α α α LT.lt LE.le LT.lt := ⟨lt_of_lt_of_le⟩
133+ instance instTransLELT : @Trans α α α LE.le LT.lt LT.lt := ⟨lt_of_le_of_lt⟩
134+ -- we have to express the following 4 instances in terms of `≥` instead of flipping the arguments
135+ -- to `≤`, because otherwise `calc` gets confused.
136+ @[to_dual existing instTransLE]
137+ instance instTransGE : @Trans α α α GE.ge GE.ge GE.ge := ⟨ge_trans⟩
138+ @[to_dual existing instTransLT]
139+ instance instTransGT : @Trans α α α GT.gt GT.gt GT.gt := ⟨gt_trans⟩
140+ @[to_dual existing instTransLTLE]
141+ instance instTransGTGE : @Trans α α α GT.gt GE.ge GT.gt := ⟨lt_of_lt_of_le'⟩
142+ @[to_dual existing instTransLELT]
143+ instance instTransGEGT : @Trans α α α GE.ge GT.gt GT.gt := ⟨lt_of_le_of_lt'⟩
129144
130145/-- `<` is decidable if `≤` is. -/
146+ @[to_dual decidableGTOfDecidableGE /-- `<` is decidable if `≤` is. -/]
131147def decidableLTOfDecidableLE [DecidableLE α] : DecidableLT α :=
132148 fun _ _ => decidable_of_iff _ lt_iff_le_not_ge.symm
133149
134150/-- `WCovBy a b` means that `a = b` or `b` covers `a`.
135151This means that `a ≤ b` and there is no element in between. This is denoted `a ⩿ b`.
136152-/
153+ @[to_dual self (reorder := 3 4)]
137154def WCovBy (a b : α) : Prop :=
138155 a ≤ b ∧ ∀ ⦃c⦄, a < c → ¬c < b
139156
@@ -142,6 +159,7 @@ infixl:50 " ⩿ " => WCovBy
142159
143160/-- `CovBy a b` means that `b` covers `a`. This means that `a < b` and there is no element in
144161between. This is denoted `a ⋖ b`. -/
162+ @[to_dual self (reorder := 3 4)]
145163def CovBy {α : Type *} [LT α] (a b : α) : Prop :=
146164 a < b ∧ ∀ ⦃c⦄, a < c → ¬c < b
147165
@@ -160,38 +178,49 @@ section PartialOrder
160178class PartialOrder (α : Type *) extends Preorder α where
161179 le_antisymm : ∀ a b : α, a ≤ b → b ≤ a → a = b
162180
181+ attribute [to_dual self (reorder := 5 6)] PartialOrder.le_antisymm
182+
163183instance [PartialOrder α] : Std.IsPartialOrder α where
164184 le_antisymm := PartialOrder.le_antisymm
165185
166186variable [PartialOrder α] {a b : α}
167187
188+ @[to_dual ge_antisymm]
168189lemma le_antisymm : a ≤ b → b ≤ a → a = b := PartialOrder.le_antisymm _ _
169190
191+ @[to_dual eq_of_ge_of_le]
170192alias eq_of_le_of_ge := le_antisymm
171193
172194@[deprecated (since := "2025-06-07")] alias eq_of_le_of_le := eq_of_le_of_ge
173195
196+ @[to_dual ge_antisymm_iff]
174197lemma le_antisymm_iff : a = b ↔ a ≤ b ∧ b ≤ a :=
175198 ⟨fun e => ⟨le_of_eq e, le_of_eq e.symm⟩, fun ⟨h1, h2⟩ => le_antisymm h1 h2⟩
176199
200+ @[to_dual lt_of_le_of_ne']
177201lemma lt_of_le_of_ne : a ≤ b → a ≠ b → a < b := fun h₁ h₂ =>
178202 lt_of_le_not_ge h₁ <| mt (le_antisymm h₁) h₂
179203
180204/-- Equality is decidable if `≤` is. -/
205+ @[to_dual decidableEqofDecidableGE /-- Equality is decidable if `≤` is. -/]
181206def decidableEqOfDecidableLE [DecidableLE α] : DecidableEq α
182207 | a, b =>
183208 if hab : a ≤ b then
184209 if hba : b ≤ a then isTrue (le_antisymm hab hba) else isFalse fun heq => hba (heq ▸ le_refl _)
185210 else isFalse fun heq => hab (heq ▸ le_refl _)
186211
187212-- See Note [decidable namespace]
213+ @[to_dual Decidable.lt_or_eq_of_le']
188214protected lemma Decidable.lt_or_eq_of_le [DecidableLE α] (hab : a ≤ b) : a < b ∨ a = b :=
189215 if hba : b ≤ a then Or.inr (le_antisymm hab hba) else Or.inl (lt_of_le_not_ge hab hba)
190216
217+ @[to_dual Decidable.le_iff_lt_or_eq']
191218protected lemma Decidable.le_iff_lt_or_eq [DecidableLE α] : a ≤ b ↔ a < b ∨ a = b :=
192219 ⟨Decidable.lt_or_eq_of_le, le_of_lt_or_eq⟩
193220
221+ @[to_dual lt_or_eq_of_le']
194222lemma lt_or_eq_of_le : a ≤ b → a < b ∨ a = b := open scoped Classical in Decidable.lt_or_eq_of_le
223+ @[to_dual le_iff_lt_or_eq']
195224lemma le_iff_lt_or_eq : a ≤ b ↔ a < b ∨ a = b := open scoped Classical in Decidable.le_iff_lt_or_eq
196225
197226end PartialOrder
0 commit comments