Skip to content

Commit e8eb83f

Browse files
committed
chore: generalise results about x ^ n = ⊤ to WithTop (#24339)
And mark them simp
1 parent dffc587 commit e8eb83f

File tree

10 files changed

+46
-33
lines changed

10 files changed

+46
-33
lines changed

Mathlib/Algebra/Order/Ring/WithTop.lean

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ instance instSemigroupWithZero [SemigroupWithZero α] [NoZeroDivisors α] :
139139
simp only [← coe_mul, mul_assoc]
140140

141141
section MonoidWithZero
142-
variable [MonoidWithZero α] [NoZeroDivisors α] [Nontrivial α]
142+
variable [MonoidWithZero α] [NoZeroDivisors α] [Nontrivial α] {x : WithTop α} {n : ℕ}
143143

144144
instance instMonoidWithZero : MonoidWithZero (WithTop α) where
145145
__ := instMulZeroOneClass
@@ -153,9 +153,19 @@ instance instMonoidWithZero : MonoidWithZero (WithTop α) where
153153

154154
@[simp, norm_cast] lemma coe_pow (a : α) (n : ℕ) : (↑(a ^ n) : WithTop α) = a ^ n := rfl
155155

156-
theorem top_pow {n : ℕ} (n_pos : 0 < n) : (⊤ : WithTop α) ^ n = ⊤ :=
157-
Nat.le_induction (pow_one _) (fun m _ hm => by rw [pow_succ, hm, top_mul_top]) _
158-
(Nat.succ_le_of_lt n_pos)
156+
@[simp] lemma top_pow : ∀ {n : ℕ}, n ≠ 0 → (⊤ : WithTop α) ^ n = ⊤ | _ + 1, _ => rfl
157+
158+
@[simp] lemma pow_eq_top_iff : x ^ n = ⊤ ↔ x = ⊤ ∧ n ≠ 0 := by
159+
induction x <;> cases n <;> simp [← coe_pow]
160+
161+
lemma pow_ne_top_iff : x ^ n ≠ ⊤ ↔ x ≠ ⊤ ∨ n = 0 := by simp [pow_eq_top_iff, or_iff_not_imp_left]
162+
163+
@[simp] lemma pow_lt_top_iff [Preorder α] : x ^ n < ⊤ ↔ x < ⊤ ∨ n = 0 := by
164+
simp_rw [WithTop.lt_top_iff_ne_top, pow_ne_top_iff]
165+
166+
lemma eq_top_of_pow (n : ℕ) (hx : x ^ n = ⊤) : x = ⊤ := (pow_eq_top_iff.1 hx).1
167+
lemma pow_ne_top (hx : x ≠ ⊤) : x ^ n ≠ ⊤ := pow_ne_top_iff.2 <| .inl hx
168+
lemma pow_lt_top [Preorder α] (hx : x < ⊤) : x ^ n < ⊤ := pow_lt_top_iff.2 <| .inl hx
159169

160170
end MonoidWithZero
161171

Mathlib/Analysis/SpecialFunctions/Log/ENNRealLog.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ theorem log_pow {x : ℝ≥0∞} {n : ℕ} : log (x ^ n) = n * log x := by
169169
· simp [n_zero, pow_zero x]
170170
rcases ENNReal.trichotomy x with (rfl | rfl | x_real)
171171
· rw [zero_pow n_pos.ne', log_zero, EReal.mul_bot_of_pos (Nat.cast_pos'.2 n_pos)]
172-
· rw [ENNReal.top_pow n_pos, log_top, EReal.mul_top_of_pos (Nat.cast_pos'.2 n_pos)]
172+
· rw [ENNReal.top_pow n_pos.ne', log_top, EReal.mul_top_of_pos (Nat.cast_pos'.2 n_pos)]
173173
· replace x_real := ENNReal.toReal_pos_iff.1 x_real
174174
simp only [log, pow_eq_zero_iff', x_real.1.ne', false_and, ↓reduceIte, pow_eq_top_iff,
175175
x_real.2.ne, toReal_pow, Real.log_pow, EReal.coe_mul, EReal.coe_coe_eq_natCast]

Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ theorem rpow_mul (x : ℝ≥0∞) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := by
620620
@[simp, norm_cast]
621621
theorem rpow_natCast (x : ℝ≥0∞) (n : ℕ) : x ^ (n : ℝ) = x ^ n := by
622622
cases x
623-
· cases n <;> simp [top_rpow_of_pos (Nat.cast_add_one_pos _), top_pow (Nat.succ_pos _)]
623+
· cases n <;> simp [top_rpow_of_pos (Nat.cast_add_one_pos _), top_pow (Nat.succ_ne_zero _)]
624624
· simp [← coe_rpow_of_nonneg _ (Nat.cast_nonneg n)]
625625

626626
@[simp]

Mathlib/Data/ENNReal/Inv.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ theorem zpow_pos (ha : a ≠ 0) (h'a : a ≠ ∞) (n : ℤ) : 0 < a ^ n := by
631631

632632
theorem zpow_lt_top (ha : a ≠ 0) (h'a : a ≠ ∞) (n : ℤ) : a ^ n < ∞ := by
633633
cases n
634-
· simpa using ENNReal.pow_lt_top h'a.lt_top _
634+
· simpa using ENNReal.pow_lt_top h'a.lt_top
635635
· simp only [ENNReal.pow_pos ha.bot_lt, zpow_negSucc, inv_lt_top]
636636

637637
theorem exists_mem_Ico_zpow {x y : ℝ≥0∞} (hx : x ≠ 0) (h'x : x ≠ ∞) (hy : 1 < y) (h'y : y ≠ ⊤) :

Mathlib/Data/ENNReal/Operations.lean

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ end OperationsAndOrder
141141

142142
section OperationsAndInfty
143143

144-
variable {α : Type*}
144+
variable {α : Type*} {n : ℕ}
145145

146146
@[simp] theorem add_eq_top : a + b = ∞ ↔ a = ∞ ∨ b = ∞ := WithTop.add_eq_top
147147

@@ -186,9 +186,6 @@ theorem top_mul' : ∞ * a = if a = 0 then 0 else ∞ := by convert WithTop.top_
186186

187187
theorem top_mul_top : ∞ * ∞ = ∞ := WithTop.top_mul_top
188188

189-
-- TODO: assume `n ≠ 0` instead of `0 < n`
190-
theorem top_pow {n : ℕ} (n_pos : 0 < n) : (∞ : ℝ≥0∞) ^ n = ∞ := WithTop.top_pow n_pos
191-
192189
theorem mul_eq_top : a * b = ∞ ↔ a ≠ 0 ∧ b = ∞ ∨ a = ∞ ∧ b ≠ 0 :=
193190
WithTop.mul_eq_top_iff
194191

@@ -223,22 +220,20 @@ theorem mul_pos_iff : 0 < a * b ↔ 0 < a ∧ 0 < b :=
223220
theorem mul_pos (ha : a ≠ 0) (hb : b ≠ 0) : 0 < a * b :=
224221
mul_pos_iff.2 ⟨pos_iff_ne_zero.2 ha, pos_iff_ne_zero.2 hb⟩
225222

226-
-- TODO: generalize to `WithTop`
227-
@[simp] theorem pow_eq_top_iff {n : ℕ} : a ^ n = ∞ ↔ a = ∞ ∧ n ≠ 0 := by
228-
rcases n.eq_zero_or_pos with rfl | (hn : 0 < n)
229-
· simp
230-
· induction a
231-
· simp only [Ne, hn.ne', top_pow hn, not_false_eq_true, and_self]
232-
· simp only [← coe_pow, coe_ne_top, false_and]
223+
@[simp] lemma top_pow {n : ℕ} (hn : n ≠ 0) : (∞ : ℝ≥0∞) ^ n = ∞ := WithTop.top_pow hn
224+
225+
@[simp] lemma pow_eq_top_iff : a ^ n = ∞ ↔ a = ∞ ∧ n ≠ 0 := WithTop.pow_eq_top_iff
226+
227+
lemma pow_ne_top_iff : a ^ n ≠ ∞ ↔ a ≠ ∞ ∨ n = 0 := WithTop.pow_ne_top_iff
228+
229+
@[simp] lemma pow_lt_top_iff : a ^ n < ∞ ↔ a < ∞ ∨ n = 0 := WithTop.pow_lt_top_iff
233230

234-
theorem pow_eq_top (n : ℕ) (h : a ^ n = ∞) : a = ∞ :=
235-
(pow_eq_top_iff.1 h).1
231+
lemma eq_top_of_pow (n : ℕ) (ha : a ^ n = ∞) : a = ∞ := WithTop.eq_top_of_pow n ha
236232

237-
theorem pow_ne_top (h : a ≠ ∞) {n : ℕ} : a ^ n ≠ ∞ :=
238-
mt (pow_eq_top n) h
233+
@[deprecated (since := "2025-04-24")] alias pow_eq_top := eq_top_of_pow
239234

240-
theorem pow_lt_top : a < ∞ → ∀ n : ℕ, a ^ n < ∞ := by
241-
simpa only [lt_top_iff_ne_top] using pow_ne_top
235+
lemma pow_ne_top (ha : a ≠ ∞) : a ^ n ∞ := WithTop.pow_ne_top ha
236+
lemma pow_lt_top (ha : a < ∞) : a ^ n < ∞ := WithTop.pow_lt_top ha
242237

243238
end OperationsAndInfty
244239

Mathlib/Data/ENat/Basic.lean

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,15 @@ theorem mul_top' : m * ⊤ = if m = 0 then 0 else ⊤ := WithTop.mul_top' m
9393
/-- A version of `top_mul` where the RHS is stated as an `ite` -/
9494
theorem top_mul' : ⊤ * m = if m = 0 then 0 else ⊤ := WithTop.top_mul' m
9595

96-
theorem top_pow {n : ℕ} (n_pos : 0 < n) : (⊤ : ℕ∞) ^ n = ⊤ := WithTop.top_pow n_pos
96+
@[simp] lemma top_pow {n : ℕ} (hn : n ≠ 0) : (⊤ : ℕ∞) ^ n = ⊤ := WithTop.top_pow hn
97+
98+
@[simp] lemma pow_eq_top_iff {n : ℕ} : a ^ n = ⊤ ↔ a = ⊤ ∧ n ≠ 0 := WithTop.pow_eq_top_iff
99+
100+
lemma pow_ne_top_iff {n : ℕ} : a ^ n ≠ ⊤ ↔ a ≠ ⊤ ∨ n = 0 := WithTop.pow_ne_top_iff
101+
102+
@[simp] lemma pow_lt_top_iff {n : ℕ} : a ^ n < ⊤ ↔ a < ⊤ ∨ n = 0 := WithTop.pow_lt_top_iff
103+
104+
lemma eq_top_of_pow (n : ℕ) (ha : a ^ n = ⊤) : a = ⊤ := WithTop.eq_top_of_pow n ha
97105

98106
/-- Convert a `ℕ∞` to a `ℕ` using a proof that it is not infinite. -/
99107
def lift (x : ℕ∞) (h : x < ⊤) : ℕ := WithTop.untop x (WithTop.lt_top_iff_ne_top.mp h)

Mathlib/Dynamics/TopologicalEntropy/CoverEntropy.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,10 @@ lemma coverMincard_mul_le_pow {T : X → X} {F : Set X} (F_inv : MapsTo T F F) {
299299
coverMincard T F (U ○ U) (m * n) ≤ coverMincard T F U m ^ n := by
300300
rcases F.eq_empty_or_nonempty with rfl | F_nonempty
301301
· rw [coverMincard_empty]; exact zero_le _
302-
rcases n.eq_zero_or_pos with rfl | n_pos
302+
obtain rfl | hn := eq_or_ne n 0
303303
· rw [mul_zero, coverMincard_zero T F_nonempty (U ○ U), pow_zero]
304304
rcases eq_top_or_lt_top (coverMincard T F U m) with h | h
305-
· exact h ▸ (le_top (α := ℕ∞)).trans_eq (ENat.top_pow n_pos).symm
305+
· simp [*]
306306
· obtain ⟨s, s_cover, s_coverMincard⟩ := (coverMincard_finite_iff T F U m).1 h
307307
obtain ⟨t, t_cover, t_sn⟩ := s_cover.iterate_le_pow F_inv U_symm n
308308
rw [← s_coverMincard]

Mathlib/MeasureTheory/Measure/Hausdorff.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ instance isAddHaarMeasure_hausdorffMeasure {E : Type*}
965965
rw [← e.symm_image_image K]
966966
apply lt_of_le_of_lt <| e.symm.lipschitz.hausdorffMeasure_image_le (by simp) (e '' K)
967967
rw [ENNReal.rpow_natCast]
968-
exact ENNReal.mul_lt_top (ENNReal.pow_lt_top ENNReal.coe_lt_top _) this
968+
exact ENNReal.mul_lt_top (ENNReal.pow_lt_top ENNReal.coe_lt_top) this
969969
conv_lhs => congr; congr; rw [← Fintype.card_fin (finrank ℝ E)]
970970
rw [hausdorffMeasure_pi_real]
971971
exact (hK.image e.continuous).measure_lt_top

Mathlib/NumberTheory/NumberField/CanonicalEmbedding/ConvexBody.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,9 @@ theorem volume_fundamentalDomain_fractionalIdealLatticeBasis :
461461

462462
theorem minkowskiBound_lt_top : minkowskiBound K I < ⊤ := by
463463
classical
464-
refine ENNReal.mul_lt_top ?_ ?_
465-
· exact (fundamentalDomain_isBounded _).measure_lt_top
466-
· exact ENNReal.pow_lt_top (lt_top_iff_ne_top.mpr ENNReal.ofNat_ne_top) _
464+
-- FIXME: Make `finiteness` work here
465+
exact ENNReal.mul_lt_top (fundamentalDomain_isBounded _).measure_lt_top <|
466+
ENNReal.pow_lt_top ENNReal.ofNat_lt_top
467467

468468
theorem minkowskiBound_pos : 0 < minkowskiBound K I := by
469469
classical

Mathlib/Probability/Variance.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ It is set to `0` if `X` has infinite variance. -/
7979
scoped notation "Var[" X "]" => Var[X; MeasureTheory.MeasureSpace.volume]
8080

8181
theorem evariance_lt_top [IsFiniteMeasure μ] (hX : MemLp X 2 μ) : evariance X μ < ∞ := by
82-
have := ENNReal.pow_lt_top (hX.sub <| memLp_const <| μ[X]).2 2
82+
have := ENNReal.pow_lt_top (hX.sub <| memLp_const <| μ[X]).2 (n := 2)
8383
rw [eLpNorm_eq_lintegral_rpow_enorm two_ne_zero ENNReal.ofNat_ne_top, ← ENNReal.rpow_two] at this
8484
simp only [ENNReal.toReal_ofNat, Pi.sub_apply, ENNReal.toReal_one, one_div] at this
8585
rw [← ENNReal.rpow_mul, inv_mul_cancel₀ (two_ne_zero : (2 : ℝ) ≠ 0), ENNReal.rpow_one] at this
@@ -137,7 +137,7 @@ theorem evariance_eq_lintegral_ofReal :
137137

138138
lemma variance_eq_integral (hX : AEMeasurable X μ) : Var[X; μ] = ∫ ω, (X ω - μ[X]) ^ 2 ∂μ := by
139139
simp [variance, evariance, toReal_enorm, ← integral_toReal ((hX.sub_const _).enorm.pow_const _) <|
140-
.of_forall fun _ ↦ ENNReal.pow_lt_top enorm_lt_top _]
140+
.of_forall fun _ ↦ ENNReal.pow_lt_top enorm_lt_top]
141141

142142
lemma variance_of_integral_eq_zero (hX : AEMeasurable X μ) (hXint : μ[X] = 0) :
143143
variance X μ = ∫ ω, X ω ^ 2 ∂μ := by

0 commit comments

Comments
 (0)