Skip to content

Commit

Permalink
feat: Make the coercion ℝ≥0 → ℝ≥0∞ commute defeqly with nsmul and…
Browse files Browse the repository at this point in the history
… `pow` (#10225)

by tweaking the definition of the `AddMonoid` and `MonoidWithZero` instances for `WithTop`. Also unprotect `ENNReal.coe_injective` and rename `ENNReal.coe_eq_coe → ENNReal.coe_inj`.

From LeanAPAP
  • Loading branch information
YaelDillies committed Feb 6, 2024
1 parent cc31307 commit 0174e78
Show file tree
Hide file tree
Showing 25 changed files with 309 additions and 241 deletions.
18 changes: 12 additions & 6 deletions Mathlib/Algebra/Order/Monoid/WithTop.lean
Expand Up @@ -332,8 +332,18 @@ instance addZeroClass [AddZeroClass α] : AddZeroClass (WithTop α) :=
section AddMonoid
variable [AddMonoid α]

instance addMonoid : AddMonoid (WithTop α) :=
{ WithTop.addSemigroup, WithTop.addZeroClass with }
instance addMonoid : AddMonoid (WithTop α) where
__ := WithTop.addSemigroup
__ := WithTop.addZeroClass
nsmul n a := match a, n with
| (a : α), n => ↑(n • a)
| ⊤, 0 => 0
| ⊤, _n + 1 => ⊤
nsmul_zero a := by cases a <;> simp [zero_nsmul]
nsmul_succ n a := by
cases a <;> cases n <;> simp [succ_nsmul, coe_add, some_eq_coe, none_eq_top]

@[simp, norm_cast] lemma coe_nsmul (a : α) (n : ℕ) : ↑(n • a) = n • (a : WithTop α) := rfl

/-- Coercion from `α` to `WithTop α` as an `AddMonoidHom`. -/
def addHom : α →+ WithTop α where
Expand All @@ -345,10 +355,6 @@ def addHom : α →+ WithTop α where
@[simp, norm_cast] lemma coe_addHom : ⇑(addHom : α →+ WithTop α) = WithTop.some := rfl
#align with_top.coe_coe_add_hom WithTop.coe_addHom

@[simp, norm_cast]
lemma coe_nsmul (a : α) (n : ℕ) : ↑(n • a) = n • (a : WithTop α) :=
(addHom : α →+ WithTop α).map_nsmul _ _

end AddMonoid

instance addCommMonoid [AddCommMonoid α] : AddCommMonoid (WithTop α) :=
Expand Down
302 changes: 157 additions & 145 deletions Mathlib/Algebra/Order/Ring/WithTop.lean

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Mathlib/AlgebraicGeometry/EllipticCurve/Group.lean
Expand Up @@ -500,12 +500,12 @@ lemma degree_norm_smul_basis [IsDomain R] (p q : R[X]) :
· convert (degree_sub_eq_right_of_degree_lt <| (degree_sub_le _ _).trans_lt <|
max_lt_iff.mpr ⟨hdp.trans_lt _, hdpq.trans_lt _⟩).trans
(max_eq_right_of_lt _).symm <;> rw [hdq] <;>
exact WithBot.coe_lt_coe.mpr <| by linarith only [hpq]
exact WithBot.coe_lt_coe.mpr <| by dsimp; linarith only [hpq]
· rw [sub_sub]
convert (degree_sub_eq_left_of_degree_lt <| (degree_add_le _ _).trans_lt <|
max_lt_iff.mpr ⟨hdpq.trans_lt _, hdq.trans_lt _⟩).trans
(max_eq_left_of_lt _).symm <;> rw [hdp] <;>
exact WithBot.coe_lt_coe.mpr <| by linarith only [hpq]
exact WithBot.coe_lt_coe.mpr <| by dsimp; linarith only [hpq]
#align weierstrass_curve.coordinate_ring.degree_norm_smul_basis WeierstrassCurve.Affine.CoordinateRing.degree_norm_smul_basis

variable {W}
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/Analysis/MeanInequalities.lean
Expand Up @@ -762,7 +762,7 @@ theorem inner_le_Lp_mul_Lq (hpq : p.IsConjugateExponent q) :
le_of_lt hpq.symm.pos, le_of_lt hpq.symm.one_div_pos] at this
convert this using 1 <;> [skip; congr 2] <;> [skip; skip; simp; skip; simp] <;>
· refine Finset.sum_congr rfl fun i hi => ?_
simp [H'.1 i hi, H'.2 i hi, -WithZero.coe_mul, WithTop.coe_mul.symm]
simp [H'.1 i hi, H'.2 i hi, -WithZero.coe_mul]
#align ennreal.inner_le_Lp_mul_Lq ENNReal.inner_le_Lp_mul_Lq

/-- For `1 ≤ p`, the `p`-th power of the sum of `f i` is bounded above by a constant times the
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/Analysis/MeanInequalitiesPow.lean
Expand Up @@ -274,7 +274,7 @@ theorem rpow_arith_mean_le_arith_mean_rpow (w z : ι → ℝ≥0∞) (hw' : ∑
refine' sum_congr rfl fun i hi => (coe_toNNReal _).symm
refine' (lt_top_of_sum_ne_top _ hi).ne
exact hw'.symm ▸ ENNReal.one_ne_top
rwa [← coe_eq_coe, ← h_sum_nnreal]
rwa [← coe_inj, ← h_sum_nnreal]
#align ennreal.rpow_arith_mean_le_arith_mean_rpow ENNReal.rpow_arith_mean_le_arith_mean_rpow

/-- Weighted generalized mean inequality, version for two elements of `ℝ≥0∞` and real
Expand Down
3 changes: 2 additions & 1 deletion Mathlib/Analysis/NormedSpace/Spectrum.lean
Expand Up @@ -178,7 +178,8 @@ theorem spectralRadius_le_pow_nnnorm_pow_one_div (a : A) (n : ℕ) :
have hn : 0 < ((n + 1 : ℕ) : ℝ) := mod_cast Nat.succ_pos'
convert monotone_rpow_of_nonneg (one_div_pos.mpr hn).le nnnorm_pow_le using 1
all_goals dsimp
erw [coe_pow, ← rpow_nat_cast, ← rpow_mul, mul_one_div_cancel hn.ne', rpow_one]
rw [one_div, pow_rpow_inv_natCast]
positivity
rw [Nat.cast_succ, ENNReal.coe_mul_rpow]
#align spectrum.spectral_radius_le_pow_nnnorm_pow_one_div spectrum.spectralRadius_le_pow_nnnorm_pow_one_div

Expand Down
2 changes: 1 addition & 1 deletion Mathlib/Analysis/NormedSpace/Star/GelfandDuality.lean
Expand Up @@ -160,7 +160,7 @@ theorem gelfandTransform_isometry : Isometry (gelfandTransform ℂ A) := by
unfold spectralRadius; rw [spectrum.gelfandTransform_eq]
rw [map_mul, (IsSelfAdjoint.star_mul_self a).spectralRadius_eq_nnnorm, gelfandTransform_map_star,
(IsSelfAdjoint.star_mul_self (gelfandTransform ℂ A a)).spectralRadius_eq_nnnorm] at this
simp only [ENNReal.coe_eq_coe, CstarRing.nnnorm_star_mul_self, ← sq] at this
simp only [ENNReal.coe_inj, CstarRing.nnnorm_star_mul_self, ← sq] at this
simpa only [Function.comp_apply, NNReal.sqrt_sq] using
congr_arg (((↑) : ℝ≥0 → ℝ) ∘ ⇑NNReal.sqrt) this
#align gelfand_transform_isometry gelfandTransform_isometry
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/Analysis/SpecialFunctions/Pow/Asymptotics.lean
Expand Up @@ -302,7 +302,7 @@ theorem isLittleO_rpow_exp_pos_mul_atTop (s : ℝ) {b : ℝ} (hb : 0 < b) :
/-- `x ^ k = o(exp(b * x))` as `x → ∞` for any integer `k` and positive `b`. -/
theorem isLittleO_zpow_exp_pos_mul_atTop (k : ℤ) {b : ℝ} (hb : 0 < b) :
(fun x : ℝ => x ^ k) =o[atTop] fun x => exp (b * x) := by
simpa only [rpow_int_cast] using isLittleO_rpow_exp_pos_mul_atTop k hb
simpa only [Real.rpow_int_cast] using isLittleO_rpow_exp_pos_mul_atTop k hb
#align is_o_zpow_exp_pos_mul_at_top isLittleO_zpow_exp_pos_mul_atTop

/-- `x ^ k = o(exp(b * x))` as `x → ∞` for any natural `k` and positive `b`. -/
Expand Down
41 changes: 34 additions & 7 deletions Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean
Expand Up @@ -22,7 +22,7 @@ noncomputable section

open Classical Real NNReal ENNReal BigOperators ComplexConjugate

open Finset Set
open Finset Function Set

namespace NNReal

Expand Down Expand Up @@ -559,6 +559,11 @@ lemma rpow_ofNat (x : ℝ≥0∞) (n : ℕ) [n.AtLeastTwo] :
x ^ (no_index (OfNat.ofNat n) : ℝ) = x ^ (OfNat.ofNat n) :=
rpow_nat_cast x n

@[simp, norm_cast]
lemma rpow_int_cast (x : ℝ≥0∞) (n : ℤ) : x ^ (n : ℝ) = x ^ n := by
cases n <;> simp only [Int.ofNat_eq_coe, Int.cast_ofNat, rpow_nat_cast, zpow_coe_nat,
Int.cast_negSucc, rpow_neg, zpow_negSucc]

theorem rpow_two (x : ℝ≥0∞) : x ^ (2 : ℝ) = x ^ 2 := rpow_ofNat x 2
#align ennreal.rpow_two ENNReal.rpow_two

Expand Down Expand Up @@ -842,7 +847,7 @@ theorem toReal_rpow (x : ℝ≥0∞) (z : ℝ) : x.toReal ^ z = (x ^ z).toReal :
theorem ofReal_rpow_of_pos {x p : ℝ} (hx_pos : 0 < x) :
ENNReal.ofReal x ^ p = ENNReal.ofReal (x ^ p) := by
simp_rw [ENNReal.ofReal]
rw [coe_rpow_of_ne_zero, coe_eq_coe, Real.toNNReal_rpow_of_nonneg hx_pos.le]
rw [coe_rpow_of_ne_zero, coe_inj, Real.toNNReal_rpow_of_nonneg hx_pos.le]
simp [hx_pos]
#align ennreal.of_real_rpow_of_pos ENNReal.ofReal_rpow_of_pos

Expand All @@ -858,14 +863,36 @@ theorem ofReal_rpow_of_nonneg {x p : ℝ} (hx_nonneg : 0 ≤ x) (hp_nonneg : 0
exact ofReal_rpow_of_pos (hx_nonneg.lt_of_ne hx0.symm)
#align ennreal.of_real_rpow_of_nonneg ENNReal.ofReal_rpow_of_nonneg

theorem rpow_left_injective {x : ℝ} (hx : x ≠ 0) : Function.Injective fun y : ℝ≥0∞ => y ^ x := by
intro y z hyz
dsimp only at hyz
rw [← rpow_one y, ← rpow_one z, ← _root_.mul_inv_cancel hx, rpow_mul, rpow_mul, hyz]
@[simp] lemma rpow_rpow_inv {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0∞) : (x ^ y) ^ y⁻¹ = x := by
rw [← rpow_mul, mul_inv_cancel hy, rpow_one]

@[simp] lemma rpow_inv_rpow {y : ℝ} (hy : y ≠ 0) (x : ℝ≥0∞) : (x ^ y⁻¹) ^ y = x := by
rw [← rpow_mul, inv_mul_cancel hy, rpow_one]

lemma pow_rpow_inv_natCast {n : ℕ} (hn : n ≠ 0) (x : ℝ≥0∞) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by
rw [← rpow_nat_cast, ← rpow_mul, mul_inv_cancel (by positivity), rpow_one]

lemma rpow_inv_natCast_pow {n : ℕ} (hn : n ≠ 0) (x : ℝ≥0∞) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by
rw [← rpow_nat_cast, ← rpow_mul, inv_mul_cancel (by positivity), rpow_one]

lemma rpow_natCast_mul (x : ℝ≥0∞) (n : ℕ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by
rw [rpow_mul, rpow_nat_cast]

lemma rpow_mul_natCast (x : ℝ≥0∞) (y : ℝ) (n : ℕ) : x ^ (y * n) = (x ^ y) ^ n := by
rw [rpow_mul, rpow_nat_cast]

lemma rpow_intCast_mul (x : ℝ≥0∞) (n : ℤ) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by
rw [rpow_mul, rpow_int_cast]

lemma rpow_mul_intCast (x : ℝ≥0∞) (y : ℝ) (n : ℤ) : x ^ (y * n) = (x ^ y) ^ n := by
rw [rpow_mul, rpow_int_cast]

lemma rpow_left_injective {x : ℝ} (hx : x ≠ 0) : Injective fun y : ℝ≥0∞ ↦ y ^ x :=
HasLeftInverse.injective ⟨fun y ↦ y ^ x⁻¹, rpow_rpow_inv hx⟩
#align ennreal.rpow_left_injective ENNReal.rpow_left_injective

theorem rpow_left_surjective {x : ℝ} (hx : x ≠ 0) : Function.Surjective fun y : ℝ≥0∞ => y ^ x :=
fun y => ⟨y ^ x⁻¹, by simp_rw [← rpow_mul, _root_.inv_mul_cancel hx, rpow_one]
HasRightInverse.surjective ⟨fun y y ^ x⁻¹, rpow_inv_rpow hx
#align ennreal.rpow_left_surjective ENNReal.rpow_left_surjective

theorem rpow_left_bijective {x : ℝ} (hx : x ≠ 0) : Function.Bijective fun y : ℝ≥0∞ => y ^ x :=
Expand Down
39 changes: 23 additions & 16 deletions Mathlib/Data/ENNReal/Basic.lean
Expand Up @@ -90,7 +90,8 @@ context, or if we have `(f : α → ℝ≥0∞) (hf : ∀ x, f x ≠ ∞)`.
-/


open Set BigOperators NNReal
open Function Set NNReal
open scoped BigOperators

variable {α : Type*}

Expand Down Expand Up @@ -176,7 +177,12 @@ instance canLift : CanLift ℝ≥0∞ ℝ≥0 ofNNReal (· ≠ ∞) := WithTop.c

@[simp] theorem some_eq_coe' (a : ℝ≥0) : (WithTop.some a : ℝ≥0∞) = (↑a : ℝ≥0∞) := rfl

protected theorem coe_injective : Function.Injective ((↑) : ℝ≥0 → ℝ≥0∞) := WithTop.coe_injective
lemma coe_injective : Injective ((↑) : ℝ≥0 → ℝ≥0∞) := WithTop.coe_injective

@[simp, norm_cast] lemma coe_inj : (p : ℝ≥0∞) = q ↔ p = q := coe_injective.eq_iff
#align ennreal.coe_eq_coe ENNReal.coe_inj

lemma coe_ne_coe : (p : ℝ≥0∞) ≠ q ↔ p ≠ q := coe_inj.not

theorem range_coe' : range ofNNReal = Iio ∞ := WithTop.range_coe
theorem range_coe : range ofNNReal = {∞}ᶜ := (isCompl_range_some_none ℝ≥0).symm.compl_eq.symm
Expand Down Expand Up @@ -368,9 +374,6 @@ theorem toReal_ofReal_eq_iff {a : ℝ} : (ENNReal.ofReal a).toReal = a ↔ 0 ≤

@[simp] theorem zero_lt_top : 0 < ∞ := coe_lt_top

@[simp, norm_cast] theorem coe_eq_coe : (↑r : ℝ≥0∞) = ↑q ↔ r = q := WithTop.coe_eq_coe
#align ennreal.coe_eq_coe ENNReal.coe_eq_coe

@[simp, norm_cast] theorem coe_le_coe : (↑r : ℝ≥0∞) ≤ ↑q ↔ r ≤ q := WithTop.coe_le_coe
#align ennreal.coe_le_coe ENNReal.coe_le_coe

Expand All @@ -390,32 +393,36 @@ theorem coe_mono : Monotone ofNNReal := fun _ _ => coe_le_coe.2

theorem coe_strictMono : StrictMono ofNNReal := fun _ _ => coe_lt_coe.2

@[simp, norm_cast] theorem coe_eq_zero : (↑r : ℝ≥0∞) = 0 ↔ r = 0 := coe_eq_coe
@[simp, norm_cast] theorem coe_eq_zero : (↑r : ℝ≥0∞) = 0 ↔ r = 0 := coe_inj
#align ennreal.coe_eq_zero ENNReal.coe_eq_zero

@[simp, norm_cast] theorem zero_eq_coe : 0 = (↑r : ℝ≥0∞) ↔ 0 = r := coe_eq_coe
@[simp, norm_cast] theorem zero_eq_coe : 0 = (↑r : ℝ≥0∞) ↔ 0 = r := coe_inj
#align ennreal.zero_eq_coe ENNReal.zero_eq_coe

@[simp, norm_cast] theorem coe_eq_one : (↑r : ℝ≥0∞) = 1 ↔ r = 1 := coe_eq_coe
@[simp, norm_cast] theorem coe_eq_one : (↑r : ℝ≥0∞) = 1 ↔ r = 1 := coe_inj
#align ennreal.coe_eq_one ENNReal.coe_eq_one

@[simp, norm_cast] theorem one_eq_coe : 1 = (↑r : ℝ≥0∞) ↔ 1 = r := coe_eq_coe
@[simp, norm_cast] theorem one_eq_coe : 1 = (↑r : ℝ≥0∞) ↔ 1 = r := coe_inj
#align ennreal.one_eq_coe ENNReal.one_eq_coe

@[simp, norm_cast] theorem coe_pos : 0 < (r : ℝ≥0∞) ↔ 0 < r := coe_lt_coe
#align ennreal.coe_pos ENNReal.coe_pos

theorem coe_ne_zero : (r : ℝ≥0∞) ≠ 0 ↔ r ≠ 0 := not_congr coe_eq_coe
theorem coe_ne_zero : (r : ℝ≥0∞) ≠ 0 ↔ r ≠ 0 := coe_eq_zero.not
#align ennreal.coe_ne_zero ENNReal.coe_ne_zero

@[simp, norm_cast] theorem coe_add : ↑(r + p) = (r : ℝ≥0∞) + p := WithTop.coe_add _ _
lemma coe_ne_one : (r : ℝ≥0∞) ≠ 1 ↔ r ≠ 1 := coe_eq_one.not

@[simp, norm_cast] lemma coe_add (x y : ℝ≥0) : (↑(x + y) : ℝ≥0∞) = x + y := rfl
#align ennreal.coe_add ENNReal.coe_add

@[simp, norm_cast]
theorem coe_mul : ↑(r * p) = (r : ℝ≥0∞) * p :=
WithTop.coe_mul
@[simp, norm_cast] lemma coe_mul (x y : ℝ≥0) : (↑(x * y) : ℝ≥0∞) = x * y := rfl
#align ennreal.coe_mul ENNReal.coe_mul

@[norm_cast] lemma coe_nsmul (n : ℕ) (x : ℝ≥0) : (↑(n • x) : ℝ≥0∞) = n • x := rfl

@[simp, norm_cast] lemma coe_pow (x : ℝ≥0) (n : ℕ) : (↑(x ^ n) : ℝ≥0∞) = x ^ n := rfl

#noalign ennreal.coe_bit0
#noalign ennreal.coe_bit1

Expand Down Expand Up @@ -513,9 +520,9 @@ theorem iSup_ennreal {α : Type*} [CompleteLattice α] {f : ℝ≥0∞ → α} :
def ofNNRealHom : ℝ≥0 →+* ℝ≥0where
toFun := some
map_one' := coe_one
map_mul' _ _ := coe_mul
map_mul' _ _ := coe_mul _ _
map_zero' := coe_zero
map_add' _ _ := coe_add
map_add' _ _ := coe_add _ _
#align ennreal.of_nnreal_hom ENNReal.ofNNRealHom

@[simp] theorem coe_ofNNRealHom : ⇑ofNNRealHom = some := rfl
Expand Down
8 changes: 5 additions & 3 deletions Mathlib/Data/ENNReal/Inv.lean
Expand Up @@ -78,7 +78,7 @@ theorem div_zero (h : a ≠ 0) : a / 0 = ∞ := by simp [div_eq_mul_inv, h]

instance : DivInvOneMonoid ℝ≥0∞ :=
{ inferInstanceAs (DivInvMonoid ℝ≥0∞) with
inv_one := by simpa only [coe_inv one_ne_zero, coe_one] using coe_eq_coe.2 inv_one }
inv_one := by simpa only [coe_inv one_ne_zero, coe_one] using coe_inj.2 inv_one }

protected theorem inv_pow : ∀ {a : ℝ≥0∞} {n : ℕ}, (a ^ n)⁻¹ = a⁻¹ ^ n
| _, 0 => by simp only [pow_zero, inv_one]
Expand Down Expand Up @@ -122,6 +122,8 @@ instance : InvolutiveInv ℝ≥0∞ where
inv_inv a := by
by_cases a = 0 <;> cases a <;> simp_all [none_eq_top, some_eq_coe, -coe_inv, (coe_inv _).symm]

@[simp] protected lemma inv_eq_one : a⁻¹ = 1 ↔ a = 1 := by rw [← inv_inj, inv_inv, inv_one]

@[simp] theorem inv_eq_top : a⁻¹ = ∞ ↔ a = 0 := inv_zero ▸ inv_inj
#align ennreal.inv_eq_top ENNReal.inv_eq_top

Expand Down Expand Up @@ -589,14 +591,14 @@ theorem coe_zpow (hr : r ≠ 0) (n : ℤ) : (↑(r ^ n) : ℝ≥0∞) = (r : ℝ

theorem zpow_pos (ha : a ≠ 0) (h'a : a ≠ ∞) (n : ℤ) : 0 < a ^ n := by
cases n
· exact ENNReal.pow_pos ha.bot_lt _
· simpa using ENNReal.pow_pos ha.bot_lt _
· simp only [h'a, pow_eq_top_iff, zpow_negSucc, Ne.def, not_false, ENNReal.inv_pos, false_and,
not_false_eq_true]
#align ennreal.zpow_pos ENNReal.zpow_pos

theorem zpow_lt_top (ha : a ≠ 0) (h'a : a ≠ ∞) (n : ℤ) : a ^ n < ∞ := by
cases n
· exact ENNReal.pow_lt_top h'a.lt_top _
· simpa using ENNReal.pow_lt_top h'a.lt_top _
· simp only [ENNReal.pow_pos ha.bot_lt, zpow_negSucc, inv_lt_top]
#align ennreal.zpow_lt_top ENNReal.zpow_lt_top

Expand Down
13 changes: 4 additions & 9 deletions Mathlib/Data/ENNReal/Operations.lean
Expand Up @@ -37,7 +37,6 @@ theorem mul_lt_mul (ac : a < c) (bd : b < d) : a * b < c * d := by
norm_cast at *
calc
↑(a * b) < ↑(a' * b') := coe_lt_coe.2 (mul_lt_mul₀ aa' bb')
_ = ↑a' * ↑b' := coe_mul
_ ≤ c * d := mul_le_mul' a'c.le b'd.le
#align ennreal.mul_lt_mul ENNReal.mul_lt_mul

Expand All @@ -53,7 +52,8 @@ theorem mul_right_mono : Monotone (· * a) := fun _ _ h => mul_le_mul' h le_rfl
theorem pow_strictMono : ∀ {n : ℕ}, n ≠ 0 → StrictMono fun x : ℝ≥0∞ => x ^ n
| 0, h => absurd rfl h
| 1, _ => by simpa only [pow_one] using strictMono_id
| (n + 1 + 1), _ => fun x y h => mul_lt_mul h (pow_strictMono n.succ_ne_zero h)
| n + 2, _ => fun x y h ↦ by
simp_rw [pow_succ _ (n + 1)]; exact mul_lt_mul h (pow_strictMono n.succ_ne_zero h)
#align ennreal.pow_strict_mono ENNReal.pow_strictMono

@[gcongr] protected theorem pow_lt_pow_left (h : a < b) {n : ℕ} (hn : n ≠ 0) :
Expand Down Expand Up @@ -183,11 +183,6 @@ section OperationsAndInfty

variable {α : Type*}

@[simp, norm_cast]
theorem coe_pow (n : ℕ) : (↑(r ^ n) : ℝ≥0∞) = (r : ℝ≥0∞) ^ n :=
ofNNRealHom.map_pow r n
#align ennreal.coe_pow ENNReal.coe_pow

@[simp] theorem add_eq_top : a + b = ∞ ↔ a = ∞ ∨ b = ∞ := WithTop.add_eq_top
#align ennreal.add_eq_top ENNReal.add_eq_top

Expand Down Expand Up @@ -514,7 +509,7 @@ theorem lt_top_of_sum_ne_top {s : Finset α} {f : α → ℝ≥0∞} (h : ∑ x
infinity -/
theorem toNNReal_sum {s : Finset α} {f : α → ℝ≥0∞} (hf : ∀ a ∈ s, f a ≠ ∞) :
ENNReal.toNNReal (∑ a in s, f a) = ∑ a in s, ENNReal.toNNReal (f a) := by
rw [← coe_eq_coe, coe_toNNReal, coe_finset_sum, sum_congr rfl]
rw [← coe_inj, coe_toNNReal, coe_finset_sum, sum_congr rfl]
· intro x hx
exact (coe_toNNReal (hf x hx)).symm
· exact (sum_lt_top hf).ne
Expand All @@ -529,7 +524,7 @@ theorem toReal_sum {s : Finset α} {f : α → ℝ≥0∞} (hf : ∀ a ∈ s, f

theorem ofReal_sum_of_nonneg {s : Finset α} {f : α → ℝ} (hf : ∀ i, i ∈ s → 0 ≤ f i) :
ENNReal.ofReal (∑ i in s, f i) = ∑ i in s, ENNReal.ofReal (f i) := by
simp_rw [ENNReal.ofReal, ← coe_finset_sum, coe_eq_coe]
simp_rw [ENNReal.ofReal, ← coe_finset_sum, coe_inj]
exact Real.toNNReal_sum_of_nonneg hf
#align ennreal.of_real_sum_of_nonneg ENNReal.ofReal_sum_of_nonneg

Expand Down
14 changes: 7 additions & 7 deletions Mathlib/Data/ENNReal/Real.lean
Expand Up @@ -64,7 +64,7 @@ theorem toReal_add_le : (a + b).toReal ≤ a.toReal + b.toReal :=

theorem ofReal_add {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) :
ENNReal.ofReal (p + q) = ENNReal.ofReal p + ENNReal.ofReal q := by
rw [ENNReal.ofReal, ENNReal.ofReal, ENNReal.ofReal, ← coe_add, coe_eq_coe,
rw [ENNReal.ofReal, ENNReal.ofReal, ENNReal.ofReal, ← coe_add, coe_inj,
Real.toNNReal_add hp hq]
#align ennreal.of_real_add ENNReal.ofReal_add

Expand Down Expand Up @@ -195,7 +195,7 @@ lemma ofReal_lt_ofReal_iff' {p q : ℝ} : ENNReal.ofReal p < .ofReal q ↔ p < q
@[simp]
theorem ofReal_eq_ofReal_iff {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) :
ENNReal.ofReal p = ENNReal.ofReal q ↔ p = q := by
rw [ENNReal.ofReal, ENNReal.ofReal, coe_eq_coe, Real.toNNReal_eq_toNNReal_iff hp hq]
rw [ENNReal.ofReal, ENNReal.ofReal, coe_inj, Real.toNNReal_eq_toNNReal_iff hp hq]
#align ennreal.of_real_eq_of_real_iff ENNReal.ofReal_eq_ofReal_iff

@[simp]
Expand Down Expand Up @@ -277,11 +277,11 @@ lemma ofNat_lt_ofReal {n : ℕ} [n.AtLeastTwo] {r : ℝ} :

@[simp]
lemma ofReal_eq_nat_cast {r : ℝ} {n : ℕ} (h : n ≠ 0) : ENNReal.ofReal r = n ↔ r = n :=
ENNReal.coe_eq_coe.trans <| Real.toNNReal_eq_nat_cast h
ENNReal.coe_inj.trans <| Real.toNNReal_eq_nat_cast h

@[simp]
lemma ofReal_eq_one {r : ℝ} : ENNReal.ofReal r = 1 ↔ r = 1 :=
ENNReal.coe_eq_coe.trans Real.toNNReal_eq_one
ENNReal.coe_inj.trans Real.toNNReal_eq_one

@[simp]
lemma ofReal_eq_ofNat {r : ℝ} {n : ℕ} [h : n.AtLeastTwo] :
Expand Down Expand Up @@ -351,7 +351,7 @@ theorem ofReal_nsmul {x : ℝ} {n : ℕ} : ENNReal.ofReal (n • x) = n • ENNR
#align ennreal.of_real_nsmul ENNReal.ofReal_nsmul

theorem ofReal_inv_of_pos {x : ℝ} (hx : 0 < x) : (ENNReal.ofReal x)⁻¹ = ENNReal.ofReal x⁻¹ := by
rw [ENNReal.ofReal, ENNReal.ofReal, ← @coe_inv (Real.toNNReal x) (by simp [hx]), coe_eq_coe,
rw [ENNReal.ofReal, ENNReal.ofReal, ← @coe_inv (Real.toNNReal x) (by simp [hx]), coe_inj,
← Real.toNNReal_inv]
#align ennreal.of_real_inv_of_pos ENNReal.ofReal_inv_of_pos

Expand Down Expand Up @@ -437,7 +437,7 @@ theorem toReal_top_mul (a : ℝ≥0∞) : ENNReal.toReal (∞ * a) = 0 := by
theorem toReal_eq_toReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toReal = b.toReal ↔ a = b := by
lift a to ℝ≥0 using ha
lift b to ℝ≥0 using hb
simp only [coe_eq_coe, NNReal.coe_eq, coe_toReal]
simp only [coe_inj, NNReal.coe_eq, coe_toReal]
#align ennreal.to_real_eq_to_real ENNReal.toReal_eq_toReal

theorem toReal_smul (r : ℝ≥0) (s : ℝ≥0∞) : (r • s).toReal = r • s.toReal := by
Expand Down Expand Up @@ -498,7 +498,7 @@ theorem toReal_div (a b : ℝ≥0∞) : (a / b).toReal = a.toReal / b.toReal :=

theorem ofReal_prod_of_nonneg {α : Type*} {s : Finset α} {f : α → ℝ} (hf : ∀ i, i ∈ s → 0 ≤ f i) :
ENNReal.ofReal (∏ i in s, f i) = ∏ i in s, ENNReal.ofReal (f i) := by
simp_rw [ENNReal.ofReal, ← coe_finset_prod, coe_eq_coe]
simp_rw [ENNReal.ofReal, ← coe_finset_prod, coe_inj]
exact Real.toNNReal_prod_of_nonneg hf
#align ennreal.of_real_prod_of_nonneg ENNReal.ofReal_prod_of_nonneg

Expand Down

0 comments on commit 0174e78

Please sign in to comment.