Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 7507876

Browse files
committed
feat(data/real/ereal): coe : ℝ → ereal is strictly monotone (#16607)
and golf existing lemmas with it. Also delete `ereal.bot_lt_top` and friends in terms of the more general `bot_lt_top`.
1 parent ccf8aa0 commit 7507876

File tree

2 files changed

+63
-46
lines changed

2 files changed

+63
-46
lines changed

src/data/real/ereal.lean

Lines changed: 62 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ open function
5353
open_locale ennreal nnreal
5454

5555
/-- ereal : The type `[-∞, ∞]` -/
56-
@[derive [has_top, comm_monoid_with_zero, nontrivial,
56+
@[derive [has_top, comm_monoid_with_zero, nontrivial, add_monoid,
5757
has_Sup, has_Inf, complete_linear_order, linear_ordered_add_comm_monoid_with_top]]
5858
def ereal := with_top (with_bot ℝ)
5959

@@ -66,9 +66,6 @@ namespace ereal
6666
-- TODO: Provide explicitly, otherwise it is inferred noncomputably from `complete_linear_order`
6767
instance : has_bot ereal := ⟨some ⊥⟩
6868

69-
@[simp] lemma bot_lt_top : (⊥ : ereal) < ⊤ := with_top.coe_lt_top _
70-
@[simp] lemma bot_ne_top : (⊥ : ereal) ≠ ⊤ := bot_lt_top.ne
71-
7269
instance : has_coe ℝ ereal := ⟨real.to_ereal⟩
7370

7471
lemma coe_strict_mono : strict_mono (coe : ℝ → ereal) :=
@@ -157,10 +154,18 @@ by { apply with_top.coe_lt_coe.2, exact with_bot.bot_lt_coe _ }
157154

158155
@[simp] lemma top_ne_zero : (⊤ : ereal) ≠ 0 := (coe_ne_top 0).symm
159156

160-
@[simp, norm_cast] lemma coe_add (x y : ℝ) : ((x + y : ℝ) : ereal) = (x : ereal) + (y : ereal) :=
161-
rfl
162-
163157
@[simp, norm_cast] lemma coe_zero : ((0 : ℝ) : ereal) = 0 := rfl
158+
@[simp, norm_cast] lemma coe_one : ((1 : ℝ) : ereal) = 1 := rfl
159+
@[simp, norm_cast] lemma coe_add (x y : ℝ) : (↑(x + y) : ereal) = x + y := rfl
160+
@[simp, norm_cast] lemma coe_mul (x y : ℝ) : (↑(x * y) : ereal) = x * y :=
161+
(with_top.coe_eq_coe.2 with_bot.coe_mul).trans with_top.coe_mul
162+
@[norm_cast] lemma coe_nsmul (n : ℕ) (x : ℝ) : (↑(n • x) : ereal) = n • x :=
163+
map_nsmul (⟨coe, coe_zero, coe_add⟩ : ℝ →+ ereal) _ _
164+
@[simp, norm_cast] lemma coe_pow (x : ℝ) (n : ℕ) : (↑(x ^ n) : ereal) = x ^ n :=
165+
map_pow (⟨coe, coe_one, coe_mul⟩ : ℝ →* ereal) _ _
166+
167+
@[simp, norm_cast] lemma coe_bit0 (x : ℝ) : (↑(bit0 x) : ereal) = bit0 x := rfl
168+
@[simp, norm_cast] lemma coe_bit1 (x : ℝ) : (↑(bit1 x) : ereal) = bit1 x := rfl
164169

165170
@[simp, norm_cast] lemma coe_eq_zero {x : ℝ} : (x : ereal) = 0 ↔ x = 0 := ereal.coe_eq_coe_iff
166171
@[simp, norm_cast] lemma coe_eq_one {x : ℝ} : (x : ereal) = 1 ↔ x = 1 := ereal.coe_eq_coe_iff
@@ -249,25 +254,28 @@ lemma coe_nnreal_ne_top (x : ℝ≥0) : ((x : ℝ≥0∞) : ereal) ≠ ⊤ := de
249254

250255
@[simp] lemma coe_nnreal_lt_top (x : ℝ≥0) : ((x : ℝ≥0∞) : ereal) < ⊤ := dec_trivial
251256

252-
@[simp, norm_cast] lemma coe_ennreal_le_coe_ennreal_iff : ∀ {x y : ℝ≥0∞},
253-
(x : ereal) ≤ (y : ereal) ↔ x ≤ y
254-
| x ⊤ := by simp
255-
| ⊤ (some y) := by simp
256-
| (some x) (some y) := by simp [coe_nnreal_eq_coe_real]
257-
258-
@[simp, norm_cast] lemma coe_ennreal_lt_coe_ennreal_iff : ∀ {x y : ℝ≥0∞},
259-
(x : ereal) < (y : ereal) ↔ x < y
257+
lemma coe_ennreal_strict_mono : strict_mono (coe : ℝ≥0∞ → ereal)
260258
| ⊤ ⊤ := by simp
261259
| (some x) ⊤ := by simp
262260
| ⊤ (some y) := by simp
263261
| (some x) (some y) := by simp [coe_nnreal_eq_coe_real]
264262

265-
@[simp, norm_cast] lemma coe_ennreal_eq_coe_ennreal_iff : ∀ {x y : ℝ≥0∞},
266-
(x : ereal) = (y : ereal) ↔ x = y
267-
| ⊤ ⊤ := by simp
268-
| (some x) ⊤ := by simp
269-
| ⊤ (some y) := by simp [(coe_nnreal_lt_top y).ne']
270-
| (some x) (some y) := by simp [coe_nnreal_eq_coe_real]
263+
lemma coe_ennreal_injective : injective (coe : ℝ≥0∞ → ereal) := coe_ennreal_strict_mono.injective
264+
265+
@[simp, norm_cast] lemma coe_ennreal_le_coe_ennreal_iff {x y : ℝ≥0∞} :
266+
(x : ereal) ≤ (y : ereal) ↔ x ≤ y :=
267+
coe_ennreal_strict_mono.le_iff_le
268+
269+
@[simp, norm_cast] lemma coe_ennreal_lt_coe_ennreal_iff {x y : ℝ≥0∞} :
270+
(x : ereal) < (y : ereal) ↔ x < y :=
271+
coe_ennreal_strict_mono.lt_iff_lt
272+
273+
@[simp, norm_cast] lemma coe_ennreal_eq_coe_ennreal_iff {x y : ℝ≥0∞} :
274+
(x : ereal) = (y : ereal) ↔ x = y :=
275+
coe_ennreal_injective.eq_iff
276+
277+
lemma coe_ennreal_ne_coe_ennreal_iff {x y : ℝ≥0∞} : (x : ereal) ≠ (y : ereal) ↔ x ≠ y :=
278+
coe_ennreal_injective.ne_iff
271279

272280
@[simp, norm_cast] lemma coe_ennreal_eq_zero {x : ℝ≥0∞} : (x : ereal) = 0 ↔ x = 0 :=
273281
by rw [←coe_ennreal_eq_coe_ennreal_iff, coe_ennreal_zero]
@@ -296,6 +304,21 @@ by rw [←coe_ennreal_zero, coe_ennreal_lt_coe_ennreal_iff]
296304
| x ⊤ := by simp
297305
| (some x) (some y) := rfl
298306

307+
@[simp, norm_cast] lemma coe_ennreal_mul : ∀ (x y : ℝ≥0∞), ((x * y : ℝ≥0∞) : ereal) = x * y
308+
| ⊤ y := by { rw ennreal.top_mul, split_ifs; simp [h] }
309+
| x ⊤ := by { rw ennreal.mul_top, split_ifs; simp [h] }
310+
| (some x) (some y) := by simp [←ennreal.coe_mul, coe_nnreal_eq_coe_real]
311+
312+
@[norm_cast] lemma coe_ennreal_nsmul (n : ℕ) (x : ℝ≥0∞) : (↑(n • x) : ereal) = n • x :=
313+
map_nsmul (⟨coe, coe_ennreal_zero, coe_ennreal_add⟩ : ℝ≥0∞ →+ ereal) _ _
314+
315+
@[simp, norm_cast] lemma coe_ennreal_pow (x : ℝ≥0∞) (n : ℕ) : (↑(x ^ n) : ereal) = x ^ n :=
316+
map_pow (⟨coe, coe_ennreal_one, coe_ennreal_mul⟩ : ℝ≥0∞ →* ereal) _ _
317+
318+
@[simp, norm_cast] lemma coe_ennreal_bit0 (x : ℝ≥0∞) : (↑(bit0 x) : ereal) = bit0 x :=
319+
coe_ennreal_add _ _
320+
@[simp, norm_cast] lemma coe_ennreal_bit1 (x : ℝ≥0∞) : (↑(bit1 x) : ereal) = bit1 x :=
321+
by simp_rw [bit1, coe_ennreal_add, coe_ennreal_bit0, coe_ennreal_one]
299322

300323
/-! ### Order -/
301324

@@ -401,11 +424,20 @@ protected def neg : ereal → ereal
401424

402425
instance : has_neg ereal := ⟨ereal.neg⟩
403426

427+
instance : sub_neg_zero_monoid ereal :=
428+
{ neg_zero := by { change ((-0 : ℝ) : ereal) = 0, simp },
429+
..ereal.add_monoid, ..ereal.has_neg }
430+
404431
@[norm_cast] protected lemma neg_def (x : ℝ) : ((-x : ℝ) : ereal) = -x := rfl
405432

406433
@[simp] lemma neg_top : - (⊤ : ereal) = ⊥ := rfl
407434
@[simp] lemma neg_bot : - (⊥ : ereal) = ⊤ := rfl
408435

436+
@[simp, norm_cast] lemma coe_neg (x : ℝ) : (↑(-x) : ereal) = -x := rfl
437+
@[simp, norm_cast] lemma coe_sub (x y : ℝ) : (↑(x - y) : ereal) = x - y := rfl
438+
@[norm_cast] lemma coe_zsmul (n : ℤ) (x : ℝ) : (↑(n • x) : ereal) = n • x :=
439+
map_zsmul' (⟨coe, coe_zero, coe_add⟩ : ℝ →+ ereal) coe_neg _ _
440+
409441
instance : has_involutive_neg ereal :=
410442
{ neg := has_neg.neg,
411443
neg_neg := λ a, match a with
@@ -419,14 +451,14 @@ instance : has_involutive_neg ereal :=
419451
| ⊥ := by simp
420452
| (x : ℝ) := rfl
421453

422-
@[simp] lemma neg_eg_top_iff {x : ereal} : - x = ⊤ ↔ x = ⊥ :=
454+
@[simp] lemma neg_eq_top_iff {x : ereal} : - x = ⊤ ↔ x = ⊥ :=
423455
by { rw neg_eq_iff_neg_eq, simp [eq_comm] }
424456

425-
@[simp] lemma neg_eg_bot_iff {x : ereal} : - x = ⊥ ↔ x = ⊤ :=
457+
@[simp] lemma neg_eq_bot_iff {x : ereal} : - x = ⊥ ↔ x = ⊤ :=
426458
by { rw neg_eq_iff_neg_eq, simp [eq_comm] }
427459

428-
@[simp] lemma neg_eg_zero_iff {x : ereal} : - x = 0 ↔ x = 0 :=
429-
by { rw neg_eq_iff_neg_eq, change ((-0 : ℝ) : ereal) = _ ↔ _, simp [eq_comm] }
460+
@[simp] lemma neg_eq_zero_iff {x : ereal} : - x = 0 ↔ x = 0 :=
461+
by { rw neg_eq_iff_neg_eq, simp [eq_comm] }
430462

431463
/-- if `-a ≤ b` then `-b ≤ a` on `ereal`. -/
432464
protected theorem neg_le_of_neg_le : ∀ {a b : ereal} (h : -a ≤ b), -b ≤ a
@@ -448,8 +480,6 @@ by rwa [←neg_neg b, ereal.neg_le, neg_neg]
448480
@[simp] lemma neg_le_neg_iff {a b : ereal} : - a ≤ - b ↔ b ≤ a :=
449481
by conv_lhs { rw [ereal.neg_le, neg_neg] }
450482

451-
@[simp, norm_cast] lemma coe_neg (x : ℝ) : ((- x : ℝ) : ereal) = - (x : ereal) := rfl
452-
453483
/-- Negation as an order reversing isomorphism on `ereal`. -/
454484
def neg_order_iso : ereal ≃o erealᵒᵈ :=
455485
{ to_fun := λ x, order_dual.to_dual (-x),
@@ -468,19 +498,13 @@ end
468498
lemma neg_lt_iff_neg_lt {a b : ereal} : -a < b ↔ -b < a :=
469499
⟨λ h, ereal.neg_lt_of_neg_lt h, λ h, ereal.neg_lt_of_neg_lt h⟩
470500

471-
/-! ### Subtraction -/
501+
/-!
502+
### Subtraction
472503
473-
/-- Subtraction on `ereal`, defined by `x - y = x + (-y)`. Since addition is badly behaved at some
504+
Subtraction on `ereal` is defined by `x - y = x + (-y)`. Since addition is badly behaved at some
474505
points, so is subtraction. There is no standard algebraic typeclass involving subtraction that is
475-
registered on `ereal`, beyond `sub_neg_zero_monoid`, because of this bad behavior. -/
476-
protected noncomputable def sub (x y : ereal) : ereal := x + (-y)
477-
478-
noncomputable instance : has_sub ereal := ⟨ereal.sub⟩
479-
480-
noncomputable instance : sub_neg_zero_monoid ereal :=
481-
{ neg_zero := by { change ((-0 : ℝ) : ereal) = 0, simp },
482-
..(infer_instance : add_monoid ereal),
483-
..ereal.has_neg }
506+
registered on `ereal`, beyond `sub_neg_zero_monoid`, because of this bad behavior.
507+
-/
484508

485509
@[simp] lemma top_sub (x : ereal) : ⊤ - x = ⊤ := top_add x
486510
@[simp] lemma sub_bot (x : ereal) : x - ⊥ = ⊤ := add_top x
@@ -489,8 +513,6 @@ noncomputable instance : sub_neg_zero_monoid ereal :=
489513
@[simp] lemma bot_sub_coe (x : ℝ) : (⊥ : ereal) - x = ⊥ := rfl
490514
@[simp] lemma coe_sub_bot (x : ℝ) : (x : ereal) - ⊤ = ⊥ := rfl
491515

492-
@[simp] lemma zero_sub (x : ereal) : 0 - x = - x := by { change 0 + (-x) = - x, simp }
493-
494516
lemma sub_le_sub {x y z t : ereal} (h : x ≤ y) (h' : t ≤ z) : x - z ≤ y - t :=
495517
add_le_add h (neg_le_neg_iff.2 h')
496518

@@ -525,11 +547,6 @@ end
525547

526548
/-! ### Multiplication -/
527549

528-
@[simp] lemma coe_one : ((1 : ℝ) : ereal) = 1 := rfl
529-
530-
@[simp, norm_cast] lemma coe_mul (x y : ℝ) : ((x * y : ℝ) : ereal) = (x : ereal) * (y : ereal) :=
531-
eq.trans (with_bot.coe_eq_coe.mpr with_bot.coe_mul) with_top.coe_mul
532-
533550
@[simp] lemma mul_top (x : ereal) (h : x ≠ 0) : x * ⊤ = ⊤ := with_top.mul_top h
534551
@[simp] lemma top_mul (x : ereal) (h : x ≠ 0) : ⊤ * x = ⊤ := with_top.top_mul h
535552

src/topology/instances/ereal.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ begin
259259
assume r,
260260
rw eventually_prod_iff,
261261
refine ⟨λ z, ((r - (a - 1): ℝ) : ereal) < z, Ioi_mem_nhds (coe_lt_top _),
262-
λ z, ((a - 1 : ℝ) : ereal) < z, Ioi_mem_nhds (by simp [zero_lt_one]),
262+
λ z, ((a - 1 : ℝ) : ereal) < z, Ioi_mem_nhds (by simp [-ereal.coe_sub]),
263263
λ x hx y hy, _⟩,
264264
dsimp,
265265
convert add_lt_add hx hy,

0 commit comments

Comments
 (0)