Skip to content

Commit 3c02b3a

Browse files
committed
chore(EReal): clean up instances (leanprover-community#37300)
This PR uses `deriving` to generate most instances on `EReal`. Previously, there was a diamond because the `Top` instance was declared only after the `CompleteLinearOrder` instance, meaning there were two `Top` instances that weren't defeq in `reducible_and_instances`.
1 parent 2badb0c commit 3c02b3a

4 files changed

Lines changed: 6 additions & 54 deletions

File tree

Mathlib/Data/EReal/Basic.lean

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,41 +32,16 @@ noncomputable section
3232

3333
/-- The type of extended real numbers `[-∞, ∞]`, constructed as `WithBot (WithTop ℝ)`. -/
3434
def EReal := WithBot (WithTop ℝ)
35-
deriving Bot, Zero, One, Nontrivial, AddMonoid, PartialOrder, AddCommMonoid
36-
37-
instance : ZeroLEOneClass EReal := inferInstanceAs (ZeroLEOneClass (WithBot (WithTop ℝ)))
38-
instance : SupSet EReal := inferInstanceAs (SupSet (WithBot (WithTop ℝ)))
39-
instance : InfSet EReal := inferInstanceAs (InfSet (WithBot (WithTop ℝ)))
40-
41-
instance : CompleteLinearOrder EReal :=
42-
inferInstanceAs (CompleteLinearOrder (WithBot (WithTop ℝ)))
43-
44-
instance : LinearOrder EReal :=
45-
inferInstanceAs (LinearOrder (WithBot (WithTop ℝ)))
46-
47-
instance : IsOrderedAddMonoid EReal :=
48-
inferInstanceAs (IsOrderedAddMonoid (WithBot (WithTop ℝ)))
49-
50-
instance : AddCommMonoidWithOne EReal :=
51-
inferInstanceAs (AddCommMonoidWithOne (WithBot (WithTop ℝ)))
52-
53-
instance : DenselyOrdered EReal :=
54-
inferInstanceAs (DenselyOrdered (WithBot (WithTop ℝ)))
55-
56-
instance : CharZero EReal := inferInstanceAs (CharZero (WithBot (WithTop ℝ)))
35+
deriving Nontrivial,
36+
Zero, One, AddMonoid, AddCommMonoid, AddCommMonoidWithOne, CharZero,
37+
Top, Bot, SupSet, InfSet, PartialOrder, LinearOrder, CompleteLinearOrder, DenselyOrdered,
38+
ZeroLEOneClass, IsOrderedAddMonoid
5739

5840
/-- The canonical inclusion from reals to ereals. Registered as a coercion. -/
5941
@[coe] def Real.toEReal : ℝ → EReal := WithBot.some ∘ WithTop.some
6042

6143
namespace EReal
6244

63-
-- things unify with `WithBot.decidableLT` later if we don't provide this explicitly.
64-
instance decidableLT : DecidableLT EReal :=
65-
WithBot.decidableLT
66-
67-
-- TODO: Provide explicitly, otherwise it is inferred noncomputably from `CompleteLinearOrder`
68-
instance : Top EReal := ⟨WithBot.some ⊤⟩
69-
7045
instance : Coe ℝ EReal := ⟨Real.toEReal⟩
7146

7247
theorem coe_strictMono : StrictMono Real.toEReal :=
@@ -383,7 +358,6 @@ lemma toReal_pos {x : EReal} (hx : 0 < x) (h'x : x ≠ ⊤) : 0 < x.toReal := by
383358
lift x to ℝ using by aesop
384359
simpa using hx
385360

386-
set_option backward.isDefEq.respectTransparency false in
387361
lemma toReal_neg {x : EReal} (hx : x < 0) (h'x : x ≠ ⊥) : x.toReal < 0 := by
388362
lift x to ℝ using by aesop
389363
simpa using hx
@@ -398,7 +372,6 @@ lemma toReal_neg {x : EReal} (hx : x < 0) (h'x : x ≠ ⊥) : x.toReal < 0 := by
398372
use (x : EReal)
399373
simpa using hx
400374

401-
set_option backward.isDefEq.respectTransparency false in
402375
@[simp] lemma toReal_image_Ioo_bot_zero : toReal '' (Ioo ⊥ 0) = Iio 0 := by
403376
ext x
404377
constructor
@@ -424,7 +397,6 @@ theorem le_coe_toReal {x : EReal} (h : x ≠ ⊤) : x ≤ x.toReal := by
424397
· simp only [h', bot_le]
425398
· simp only [le_refl, coe_toReal h h']
426399

427-
set_option backward.isDefEq.respectTransparency false in
428400
theorem coe_toReal_le {x : EReal} (h : x ≠ ⊥) : ↑x.toReal ≤ x := by
429401
by_cases h' : x = ⊤
430402
· simp only [h', le_top]
@@ -515,10 +487,9 @@ lemma preimage_coe_Ioi (x : ℝ) : Real.toEReal ⁻¹' Ioi x = Ioi x := by
515487
refine preimage_comp.trans ?_
516488
simp only [WithBot.preimage_coe_Ioi, WithTop.preimage_coe_Ioi]
517489

518-
set_option backward.isDefEq.respectTransparency false in
519490
@[simp]
520491
lemma preimage_coe_Ioi_bot : Real.toEReal ⁻¹' Ioi ⊥ = univ := by
521-
change (WithBot.some ∘ WithTop.some) ⁻¹' (Ioi ) = _
492+
change ((WithBot.some ∘ WithTop.some) ⁻¹' (Ioi (⊥ : WithBot (WithTop ℝ))) : Set ℝ) = _
522493
refine preimage_comp.trans ?_
523494
simp only [WithBot.preimage_coe_Ioi_bot, preimage_univ]
524495

@@ -534,10 +505,9 @@ lemma preimage_coe_Iio (y : ℝ) : Real.toEReal ⁻¹' Iio y = Iio y := by
534505
refine preimage_comp.trans ?_
535506
simp only [WithBot.preimage_coe_Iio, WithTop.preimage_coe_Iio]
536507

537-
set_option backward.isDefEq.respectTransparency false in
538508
@[simp]
539509
lemma preimage_coe_Iio_top : Real.toEReal ⁻¹' Iio ⊤ = univ := by
540-
change (WithBot.some ∘ WithTop.some) ⁻¹' (Iio (WithBot.some )) = _
510+
change (WithBot.some ∘ WithTop.some) ⁻¹' (Iio (WithBot.some (⊤ : WithTop ℝ))) = _
541511
refine preimage_comp.trans ?_
542512
simp only [WithBot.preimage_coe_Iio, WithTop.preimage_coe_Iio_top]
543513

@@ -741,7 +711,6 @@ lemma toENNReal_of_nonpos {x : EReal} (hx : x ≤ 0) : x.toENNReal = 0 := by
741711
lemma toENNReal_bot : (⊥ : EReal).toENNReal = 0 := toENNReal_of_nonpos bot_le
742712
lemma toENNReal_zero : (0 : EReal).toENNReal = 0 := toENNReal_of_nonpos le_rfl
743713

744-
set_option backward.isDefEq.respectTransparency false in
745714
lemma toENNReal_eq_zero_iff {x : EReal} : x.toENNReal = 0 ↔ x ≤ 0 := by
746715
induction x <;> simp [toENNReal]
747716

@@ -786,7 +755,6 @@ lemma toENNReal_eq_toENNReal {x y : EReal} (hx : 0 ≤ x) (hy : 0 ≤ y) :
786755
x.toENNReal = y.toENNReal ↔ x = y := by
787756
induction x <;> induction y <;> simp_all
788757

789-
set_option backward.isDefEq.respectTransparency false in
790758
lemma toENNReal_le_toENNReal {x y : EReal} (h : x ≤ y) : x.toENNReal ≤ y.toENNReal := by
791759
induction x
792760
· simp

Mathlib/Data/EReal/Inv.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,6 @@ private lemma exists_lt_mul_right_of_nonneg (ha : 0 ≤ a) (hc : 0 ≤ c) (h : c
493493
simp_rw [mul_comm a] at h ⊢
494494
exact exists_lt_mul_left_of_nonneg hb.le hc h
495495

496-
set_option backward.isDefEq.respectTransparency false in
497496
private lemma exists_mul_left_lt (h₁ : a ≠ 0 ∨ b ≠ ⊤) (h₂ : a ≠ ⊤ ∨ 0 < b) (hc : a * b < c) :
498497
∃ a' ∈ Ioo a ⊤, a' * b < c := by
499498
rcases eq_top_or_lt_top a with rfl | a_top

Mathlib/Data/EReal/Operations.lean

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ lemma toENNReal_add_le {x y : EReal} : (x + y).toENNReal ≤ x.toENNReal + y.toE
127127
induction x <;> induction y <;> try {· simp}
128128
exact ENNReal.ofReal_add_le
129129

130-
set_option backward.isDefEq.respectTransparency false in
131130
theorem addLECancellable_coe (x : ℝ) : AddLECancellable (x : EReal)
132131
| _, ⊤, _ => le_top
133132
| ⊥, _, _ => bot_le
@@ -150,7 +149,6 @@ theorem add_lt_add {x y z t : EReal} (h1 : x < y) (h2 : z < t) : x + z < y + t :
150149
calc (x : EReal) + z < x + t := add_lt_add_left_coe h2 _
151150
_ ≤ y + t := by gcongr
152151

153-
set_option backward.isDefEq.respectTransparency false in
154152
theorem add_lt_add_of_lt_of_le' {x y z t : EReal} (h : x < y) (h' : z ≤ t) (hbot : t ≠ ⊥)
155153
(htop : t = ⊤ → z = ⊤ → x = ⊥) : x + z < y + t := by
156154
rcases h'.eq_or_lt with (rfl | hlt)
@@ -372,20 +370,16 @@ lemma sub_self {x : EReal} (h_top : x ≠ ⊤) (h_bot : x ≠ ⊥) : x - x = 0 :
372370
lemma sub_self_le_zero {x : EReal} : x - x ≤ 0 := by
373371
cases x <;> simp
374372

375-
set_option backward.isDefEq.respectTransparency false in
376373
lemma sub_nonneg {x y : EReal} (h_top : x ≠ ⊤ ∨ y ≠ ⊤) (h_bot : x ≠ ⊥ ∨ y ≠ ⊥) :
377374
0 ≤ x - y ↔ y ≤ x := by
378375
cases x <;> cases y <;> simp_all [← EReal.coe_sub]
379376

380-
set_option backward.isDefEq.respectTransparency false in
381377
lemma sub_nonpos {x y : EReal} : x - y ≤ 0 ↔ x ≤ y := by
382378
cases x <;> cases y <;> simp [← EReal.coe_sub]
383379

384-
set_option backward.isDefEq.respectTransparency false in
385380
lemma sub_pos {x y : EReal} : 0 < x - y ↔ y < x := by
386381
cases x <;> cases y <;> simp [← EReal.coe_sub]
387382

388-
set_option backward.isDefEq.respectTransparency false in
389383
lemma sub_neg {x y : EReal} (h_top : x ≠ ⊤ ∨ y ≠ ⊤) (h_bot : x ≠ ⊥ ∨ y ≠ ⊥) :
390384
x - y < 0 ↔ x < y := by
391385
cases x <;> cases y <;> simp_all [← EReal.coe_sub]
@@ -442,7 +436,6 @@ lemma sub_add_cancel_right {a : EReal} {b : Real} : b - (a + b) = -a := by
442436
lemma sub_add_cancel_left {a : EReal} {b : Real} : b - (b + a) = -a := by
443437
rw [add_comm, sub_add_cancel_right]
444438

445-
set_option backward.isDefEq.respectTransparency false in
446439
lemma le_sub_iff_add_le {a b c : EReal} (hb : b ≠ ⊥ ∨ c ≠ ⊥) (ht : b ≠ ⊤ ∨ c ≠ ⊤) :
447440
a ≤ c - b ↔ a + b ≤ c := by
448441
induction b with
@@ -637,7 +630,6 @@ instance : NoZeroDivisors EReal where
637630
· rcases lt_or_gt_of_ne h.2 with (h | h)
638631
<;> simp [EReal.top_mul_of_pos, EReal.top_mul_of_neg, h]
639632

640-
set_option backward.isDefEq.respectTransparency false in
641633
lemma mul_pos_iff {a b : EReal} : 0 < a * b ↔ 0 < a ∧ 0 < b ∨ a < 0 ∧ b < 0 := by
642634
induction a, b using EReal.induction₂_symm with
643635
| symm h => simp [EReal.mul_comm, h, and_comm]
@@ -724,7 +716,6 @@ lemma mul_nonpos_iff {a b : EReal} : a * b ≤ 0 ↔ 0 ≤ a ∧ b ≤ 0 ∨ a
724716
nth_rw 1 [← neg_zero]
725717
rw [EReal.le_neg, ← mul_neg, mul_nonneg_iff, EReal.neg_le, EReal.le_neg, neg_zero]
726718

727-
set_option backward.isDefEq.respectTransparency false in
728719
lemma mul_eq_top (a b : EReal) :
729720
a * b = ⊤ ↔ (a = ⊥ ∧ b < 0) ∨ (a < 0 ∧ b = ⊥) ∨ (a = ⊤ ∧ 0 < b) ∨ (0 < a ∧ b = ⊤) := by
730721
induction a, b using EReal.induction₂_symm with

Mathlib/Topology/Instances/EReal/Lemmas.lean

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ theorem continuous_coe_ennreal_iff {f : α → ℝ≥0∞} :
100100

101101
/-! ### Neighborhoods of infinity -/
102102

103-
set_option backward.isDefEq.respectTransparency false in
104103
theorem nhds_top : 𝓝 (⊤ : EReal) = ⨅ (a) (_ : a ≠ ⊤), 𝓟 (Ioi a) :=
105104
nhds_top_order.trans <| by simp only [lt_top_iff_ne_top]
106105

@@ -138,7 +137,6 @@ theorem tendsto_nhds_bot_iff_real {α : Type*} {m : α → EReal} {f : Filter α
138137
Tendsto m f (𝓝 ⊥) ↔ ∀ x : ℝ, ∀ᶠ a in f, m a < x :=
139138
nhds_bot_basis.tendsto_right_iff.trans <| by simp only [true_implies, mem_Iio]
140139

141-
set_option backward.isDefEq.respectTransparency false in
142140
lemma nhdsWithin_top : 𝓝[≠] (⊤ : EReal) = (atTop).map Real.toEReal := by
143141
apply (nhdsWithin_hasBasis nhds_top_basis_Ici _).ext (atTop_basis.map Real.toEReal)
144142
· simp only [EReal.image_coe_Ici, true_and]
@@ -152,7 +150,6 @@ lemma nhdsWithin_top : 𝓝[≠] (⊤ : EReal) = (atTop).map Real.toEReal := by
152150
refine fun x ↦ ⟨x, ⟨EReal.coe_lt_top x, fun x ⟨(h1 : _ ≤ x), h2⟩ ↦ ?_⟩⟩
153151
simp [h1, Ne.lt_top' fun a ↦ h2 a.symm]
154152

155-
set_option backward.isDefEq.respectTransparency false in
156153
lemma nhdsWithin_bot : 𝓝[≠] (⊥ : EReal) = (atBot).map Real.toEReal := by
157154
apply (nhdsWithin_hasBasis nhds_bot_basis_Iic _).ext (atBot_basis.map Real.toEReal)
158155
· simp only [EReal.image_coe_Iic,
@@ -288,7 +285,6 @@ lemma limsup_add_bot_of_ne_top (h : limsup u f = ⊥) (h' : limsup v f ≠ ⊤)
288285
· rw [h]; exact .inl bot_ne_top
289286
· rw [h, bot_add]
290287

291-
set_option backward.isDefEq.respectTransparency false in
292288
lemma limsup_add_le_of_le {a b : EReal} (ha : limsup u f < a) (hb : limsup v f ≤ b) :
293289
limsup (u + v) f ≤ a + b := by
294290
rcases eq_top_or_lt_top b with rfl | h
@@ -299,7 +295,6 @@ lemma liminf_add_gt_of_gt {a b : EReal} (ha : a < liminf u f) (hb : b < liminf v
299295
a + b < liminf (u + v) f :=
300296
(add_lt_add ha hb).trans_le le_liminf_add
301297

302-
set_option backward.isDefEq.respectTransparency false in
303298
lemma liminf_add_top_of_ne_bot (h : liminf u f = ⊤) (h' : liminf v f ≠ ⊥) :
304299
liminf (u + v) f = ⊤ := by
305300
apply top_le_iff.1 (le_trans _ le_liminf_add)
@@ -333,7 +328,6 @@ theorem liminf_const_mul_of_nonpos_of_ne_bot [NeBot f] {c : EReal} (h₁ : c ≤
333328
simpa [neg_mul, ← Pi.neg_def, limsup_neg] using
334329
limsup_const_mul_of_nonneg_of_ne_top (c := -c) (by aesop) (by aesop)
335330

336-
set_option backward.isDefEq.respectTransparency false in
337331
lemma le_limsup_mul (hu : ∃ᶠ x in f, 0 ≤ u x) (hv : 0 ≤ᶠ[f] v) :
338332
limsup u f * liminf v f ≤ limsup (u * v) f := by
339333
rcases f.eq_or_neBot with rfl | _

0 commit comments

Comments
 (0)