Skip to content

Commit d2abc00

Browse files
committed
refactor: define < on WithBot/WithTop as an inductive predicate (#30848)
Follow up to #19668, where I did the same for `LE` but forgot to do it for `LT`.
1 parent 0529f21 commit d2abc00

File tree

5 files changed

+52
-39
lines changed

5 files changed

+52
-39
lines changed

Mathlib/Algebra/Order/GroupWithZero/Canonical.lean

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,18 @@ variable [LT α] {x y : WithZero α} {a b : α}
284284
/-- The order on `WithZero α`, defined by `⊥ < ↑a` and `a < b → ↑a < ↑b`. -/
285285
instance (priority := 10) instLT : LT (WithZero α) := WithBot.instLT
286286

287-
lemma lt_def : x < y ↔ ∃ b : α, y = ↑b ∧ ∀ a : α, x = ↑a → a < b := WithBot.lt_def
287+
lemma lt_def : x < y ↔ x = 0 ∧ (∃ b : α, y = b) ∨ ∃ a b : α, a < b ∧ x = ↑a ∧ y = ↑b :=
288+
WithBot.lt_def
289+
290+
lemma lt_iff_exists : x < y ↔ ∃ b : α, y = ↑b ∧ ∀ a : α, x = ↑a → a < b := WithBot.lt_iff_exists
288291

289292
@[simp, norm_cast] lemma coe_lt_coe : (a : WithZero α) < b ↔ a < b := by simp [lt_def]
290293
@[simp] lemma zero_lt_coe (a : α) : 0 < (a : WithZero α) := by simp [lt_def]
291294
@[simp] protected lemma not_lt_zero (a : WithZero α) : ¬a < 0 := by simp [lt_def]
292295

293296
lemma lt_iff_exists_coe : x < y ↔ ∃ b : α, y = b ∧ x < b := WithBot.lt_iff_exists_coe
294297

295-
lemma lt_coe_iff : x < b ↔ ∀ a : α, x = a → a < b := by simp [lt_def]
298+
lemma lt_coe_iff : x < b ↔ ∀ a : α, x = a → a < b := WithBot.lt_coe_iff
296299

297300
/-- A version of `pos_iff_ne_zero` for `WithZero` that only requires `LT α`,
298301
not `PartialOrder α`. -/

Mathlib/Analysis/Analytic/OfScalars.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ theorem ofScalars_radius_eq_zero_of_tendsto [NormOneClass E]
268268
rw [← coe_zero, coe_le_coe]
269269
have := FormalMultilinearSeries.summable_norm_mul_pow _ hr
270270
contrapose! this
271-
apply not_summable_of_ratio_norm_eventually_ge ENNReal.one_lt_two
271+
refine not_summable_of_ratio_norm_eventually_ge (r := 2) (by simp) ?_ ?_
272272
· contrapose! hc
273273
apply not_tendsto_atTop_of_tendsto_nhds (a:=0)
274274
rw [not_frequently] at hc

Mathlib/Analysis/Oscillation.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ theorem uniform_oscillationWithin (comp : IsCompact K) (hK : ∀ x ∈ K, oscill
125125
intro r' hr'
126126
grw [← hn₂, ← image_subset_iff.2 hr, hr']
127127
by_cases r_top : r = ⊤
128-
· use 1, one_pos, 2, ENNReal.one_lt_two, this 2 (by simp only [r_top, le_top])
128+
· exact ⟨1, one_pos, 2, by simp, this 2 (by simp only [r_top, le_top])
129129
· obtain ⟨r', hr'⟩ := exists_between (toReal_pos (ne_of_gt r0) r_top)
130130
use r', hr'.1, r.toReal, hr'.2, this r.toReal ofReal_toReal_le
131131
have S_antitone : ∀ (r₁ r₂ : ℝ), r₁ ≤ r₂ → S r₂ ⊆ S r₁ :=

Mathlib/Order/WithBot.lean

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -247,16 +247,17 @@ section LE
247247

248248
variable [LE α] {x y : WithBot α}
249249

250-
/-- The order on `WithBot α`, defined by `⊥ ≤ ⊥`, `⊥ ≤ ↑a` and `a ≤ b → ↑a ≤ ↑b`.
251-
252-
Equivalently, `x ≤ y` can be defined as `∀ a : α, x = ↑a → ∃ b : α, y = ↑b ∧ a ≤ b`,
253-
see `le_if_forall`. The definition as an inductive predicate is preferred since it
254-
cannot be accidentally unfolded too far. -/
250+
/-- Auxiliary definition for the order on `WithBot`. -/
255251
@[mk_iff le_def_aux]
256252
protected inductive LE : WithBot α → WithBot α → Prop
257253
| protected bot_le (x : WithBot α) : WithBot.LE ⊥ x
258254
| protected coe_le_coe {a b : α} : a ≤ b → WithBot.LE a b
259255

256+
/-- The order on `WithBot α`, defined by `⊥ ≤ y` and `a ≤ b → ↑a ≤ ↑b`.
257+
258+
Equivalently, `x ≤ y` can be defined as `∀ a : α, x = ↑a → ∃ b : α, y = ↑b ∧ a ≤ b`,
259+
see `le_iff_forall`. The definition as an inductive predicate is preferred since it
260+
cannot be accidentally unfolded too far. -/
260261
instance (priority := 10) instLE : LE (WithBot α) where le := WithBot.LE
261262

262263
lemma le_def : x ≤ y ↔ x = ⊥ ∨ ∃ a b : α, a ≤ b ∧ x = a ∧ y = b := le_def_aux ..
@@ -303,28 +304,32 @@ section LT
303304

304305
variable [LT α] {x y : WithBot α}
305306

307+
/-- Auxiliary definition for the order on `WithBot`. -/
308+
@[mk_iff lt_def_aux]
309+
protected inductive LT : WithBot α → WithBot α → Prop
310+
| protected bot_lt (b : α) : WithBot.LT ⊥ b
311+
| protected coe_lt_coe {a b : α} : a < b → WithBot.LT a b
312+
306313
/-- The order on `WithBot α`, defined by `⊥ < ↑a` and `a < b → ↑a < ↑b`.
307314
308-
Equivalently, `x y` can be defined as ` b : α, y = ↑v → ∃ a : α, x = ↑a a b`,
309-
see `le_if_forall`. The definition as an inductive predicate is preferred since it
315+
Equivalently, `x < y` can be defined as ` b : α, y = ↑b ∧ ∀ a : α, x = ↑a a < b`,
316+
see `lt_iff_exists`. The definition as an inductive predicate is preferred since it
310317
cannot be accidentally unfolded too far. -/
311-
instance (priority := 10) instLT : LT (WithBot α) where
312-
lt
313-
| ⊥, ⊥ => False
314-
| (a : α), ⊥ => False
315-
| ⊥, (b : α) => True
316-
| (a : α), (b : α) => a < b
318+
instance (priority := 10) instLT : LT (WithBot α) where lt := WithBot.LT
319+
320+
lemma lt_def : x < y ↔ (x = ⊥ ∧ ∃ b : α, y = b) ∨ ∃ a b : α, a < b ∧ x = a ∧ y = b :=
321+
(lt_def_aux ..).trans <| by simp
317322

318-
lemma lt_def : x < y ↔ ∃ b : α, y = ↑b ∧ ∀ a : α, x = ↑a → a < b := by
319-
cases x <;> cases y <;> simp [LT.lt]
323+
lemma lt_iff_exists : x < y ↔ ∃ b : α, y = ↑b ∧ ∀ a : α, x = ↑a → a < b := by
324+
cases x <;> cases y <;> simp [lt_def]
320325

321326
@[simp, norm_cast] lemma coe_lt_coe : (a : WithBot α) < b ↔ a < b := by simp [lt_def]
322327
@[simp] lemma bot_lt_coe (a : α) : ⊥ < (a : WithBot α) := by simp [lt_def]
323328
@[simp] protected lemma not_lt_bot (a : WithBot α) : ¬a < ⊥ := by simp [lt_def]
324329

325330
lemma lt_iff_exists_coe : x < y ↔ ∃ b : α, y = b ∧ x < b := by cases y <;> simp
326331

327-
lemma lt_coe_iff : x < b ↔ ∀ a : α, x = a → a < b := by simp [lt_def]
332+
lemma lt_coe_iff : x < b ↔ ∀ a : α, x = a → a < b := by simp [lt_iff_exists]
328333

329334
/-- A version of `bot_lt_iff_ne_bot` for `WithBot` that only requires `LT α`, not
330335
`PartialOrder α`. -/
@@ -827,7 +832,11 @@ section LE
827832

828833
variable [LE α] {x y : WithTop α}
829834

830-
/-- The order on `WithTop α`, defined by `⊤ ≤ ⊤`, `↑a ≤ ⊤` and `a ≤ b → ↑a ≤ ↑b`. -/
835+
/-- The order on `WithTop α`, defined by `x ≤ ⊤` and `a ≤ b → ↑a ≤ ↑b`.
836+
837+
Equivalently, `x ≤ y` can be defined as `∀ b : α, y = ↑b → ∃ a : α, x = ↑a ∧ a ≤ b`,
838+
see `le_iff_forall`. The definition as an inductive predicate is preferred since it
839+
cannot be accidentally unfolded too far. -/
831840
instance (priority := 10) instLE : LE (WithTop α) where le a b := WithBot.LE (α := αᵒᵈ) b a
832841

833842
lemma le_def : x ≤ y ↔ y = ⊤ ∨ ∃ a b : α, a ≤ b ∧ x = a ∧ y = b :=
@@ -896,25 +905,27 @@ section LT
896905

897906
variable [LT α] {x y : WithTop α}
898907

899-
/-- The order on `WithTop α`, defined by `↑a < ⊤` and `a < b → ↑a < ↑b`. -/
900-
instance (priority := 10) instLT : LT (WithTop α) where
901-
-- We match on `b, a` rather than `a, b` to keep the defeq with `WithBot.instLT (α := αᵒᵈ)`
902-
lt a b := match b, a with
903-
| ⊤, ⊤ => False
904-
| (b : α), ⊤ => False
905-
| ⊤, (a : α) => True
906-
| (b : α), (a : α) => a < b
908+
/-- The order on `WithTop α`, defined by `↑a < ⊤` and `a < b → ↑a < ↑b`.
909+
910+
Equivalently, `x < y` can be defined as `∃ a : α, x = ↑a ∧ ∀ b : α, y = ↑b → a < b`,
911+
see `le_if_forall`. The definition as an inductive predicate is preferred since it
912+
cannot be accidentally unfolded too far. -/
913+
instance (priority := 10) instLT : LT (WithTop α) where lt a b := WithBot.LT (α := αᵒᵈ) b a
914+
915+
lemma lt_def : x < y ↔ (∃ a : α, x = ↑a) ∧ y = ⊤ ∨ ∃ a b : α, a < b ∧ x = ↑a ∧ y = ↑b :=
916+
WithBot.lt_def.trans <| or_congr and_comm <| exists_swap.trans <|
917+
exists₂_congr fun _ _ ↦ and_congr_right' and_comm
907918

908-
lemma lt_def : x < y ↔ ∃ a : α, x = ↑a ∧ ∀ b : α, y = ↑b → a < b := by
909-
cases x <;> cases y <;> simp [LT.lt]
919+
lemma lt_iff_exists : x < y ↔ ∃ a : α, x = ↑a ∧ ∀ b : α, y = ↑b → a < b := by
920+
cases x <;> cases y <;> simp [lt_def]
910921

911922
@[simp, norm_cast] lemma coe_lt_coe : (a : WithTop α) < b ↔ a < b := by simp [lt_def]
912923
@[simp] lemma coe_lt_top (a : α) : (a : WithTop α) < ⊤ := by simp [lt_def]
913924
@[simp] protected lemma not_top_lt (a : WithTop α) : ¬⊤ < a := by simp [lt_def]
914925

915926
lemma lt_iff_exists_coe : x < y ↔ ∃ a : α, x = a ∧ a < y := by cases x <;> simp
916927

917-
lemma coe_lt_iff : a < y ↔ ∀ b : α, y = b → a < b := by simp [lt_def]
928+
lemma coe_lt_iff : a < y ↔ ∀ b : α, y = b → a < b := by simp [lt_iff_exists]
918929

919930
/-- A version of `lt_top_iff_ne_top` for `WithTop` that only requires `LT α`, not
920931
`PartialOrder α`. -/

Mathlib/RingTheory/PowerBasis.lean

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,12 @@ theorem mem_span_pow {x y : S} {d : ℕ} (hd : d ≠ 0) :
108108
∃ f : R[X], f.natDegree < d ∧ y = aeval x f := by
109109
rw [mem_span_pow']
110110
constructor <;>
111-
· rintro ⟨f, h, hy⟩
112-
refine ⟨f, ?_, hy⟩
113-
by_cases hf : f = 0
114-
· simp only [hf, natDegree_zero, degree_zero] at h ⊢
115-
first | exact lt_of_le_of_ne (Nat.zero_le d) hd.symm | exact WithBot.bot_lt_coe d
116-
simp_all only [degree_eq_natDegree hf]
117-
· exact WithBot.coe_lt_coe.1 h
111+
· rintro ⟨f, h, hy⟩
112+
refine ⟨f, ?_, hy⟩
113+
by_cases hf : f = 0
114+
· simp only [hf, natDegree_zero, degree_zero] at h ⊢
115+
first | exact lt_of_le_of_ne (Nat.zero_le d) hd.symm | exact WithBot.bot_lt_coe d
116+
simpa [degree_eq_natDegree hf] using h
118117

119118
theorem dim_ne_zero [Nontrivial S] (pb : PowerBasis R S) : pb.dim ≠ 0 := fun h =>
120119
not_nonempty_iff.mpr (h.symm ▸ Fin.isEmpty : IsEmpty (Fin pb.dim)) pb.basis.index_nonempty

0 commit comments

Comments
 (0)