Skip to content

Commit

Permalink
chore(Data/Real/ENNReal): rename some to ofNNReal (#8276)
Browse files Browse the repository at this point in the history
The `some` name feels like an implementation detail.
  • Loading branch information
eric-wieser committed Nov 9, 2023
1 parent f19e98e commit 4dd5ba0
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
40 changes: 20 additions & 20 deletions Mathlib/Data/Real/ENNReal.lean
Expand Up @@ -136,15 +136,15 @@ noncomputable instance : Unique (AddUnits ℝ≥0∞) where
instance : Inhabited ℝ≥0∞ := ⟨0

/-- Coercion from `ℝ≥0` to `ℝ≥0∞`. -/
@[coe, match_pattern] def some : ℝ≥0 → ℝ≥0∞ := WithTop.some
@[coe, match_pattern] def ofNNReal : ℝ≥0 → ℝ≥0∞ := WithTop.some

instance : Coe ℝ≥0 ℝ≥0∞ := ⟨some
instance : Coe ℝ≥0 ℝ≥0∞ := ⟨ofNNReal

/-- A version of `WithTop.recTopCoe` that uses `ENNReal.some`. -/
/-- A version of `WithTop.recTopCoe` that uses `ENNReal.ofNNReal`. -/
def recTopCoe {C : ℝ≥0∞ → Sort*} (top : C ∞) (coe : ∀ x : ℝ≥0, C x) (x : ℝ≥0∞) : C x :=
WithTop.recTopCoe top coe x

instance canLift : CanLift ℝ≥0∞ ℝ≥0 some (· ≠ ∞) := WithTop.canLift
instance canLift : CanLift ℝ≥0∞ ℝ≥0 ofNNReal (· ≠ ∞) := WithTop.canLift
#align ennreal.can_lift ENNReal.canLift

@[simp] theorem none_eq_top : (none : ℝ≥0∞) = ∞ := rfl
Expand All @@ -157,8 +157,8 @@ instance canLift : CanLift ℝ≥0∞ ℝ≥0 some (· ≠ ∞) := WithTop.canLi

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

theorem range_coe' : range some = Iio ∞ := WithTop.range_coe
theorem range_coe : range some = {∞}ᶜ := (isCompl_range_some_none ℝ≥0).symm.compl_eq.symm
theorem range_coe' : range ofNNReal = Iio ∞ := WithTop.range_coe
theorem range_coe : range ofNNReal = {∞}ᶜ := (isCompl_range_some_none ℝ≥0).symm.compl_eq.symm

/-- `toNNReal x` returns `x` if it is real, otherwise 0. -/
protected def toNNReal : ℝ≥0∞ → ℝ≥0 := WithTop.untop' 0
Expand All @@ -178,7 +178,7 @@ theorem toNNReal_coe : (r : ℝ≥0∞).toNNReal = r := rfl

@[simp]
theorem coe_toNNReal : ∀ {a : ℝ≥0∞}, a ≠ ∞ → ↑a.toNNReal = a
| some _, _ => rfl
| ofNNReal _, _ => rfl
| ⊤, h => (h rfl).elim
#align ennreal.coe_to_nnreal ENNReal.coe_toNNReal

Expand All @@ -196,16 +196,16 @@ theorem toReal_ofReal' {r : ℝ} : (ENNReal.ofReal r).toReal = max r 0 := rfl
#align ennreal.to_real_of_real' ENNReal.toReal_ofReal'

theorem coe_toNNReal_le_self : ∀ {a : ℝ≥0∞}, ↑a.toNNReal ≤ a
| some r => by rw [toNNReal_coe]
| none => le_top
| ofNNReal r => by rw [toNNReal_coe]
| => le_top
#align ennreal.coe_to_nnreal_le_self ENNReal.coe_toNNReal_le_self

theorem coe_nnreal_eq (r : ℝ≥0) : (r : ℝ≥0∞) = ENNReal.ofReal r := by
rw [ENNReal.ofReal, Real.toNNReal_coe]
#align ennreal.coe_nnreal_eq ENNReal.coe_nnreal_eq

theorem ofReal_eq_coe_nnreal {x : ℝ} (h : 0 ≤ x) :
ENNReal.ofReal x = some ⟨x, h⟩ :=
ENNReal.ofReal x = ofNNReal ⟨x, h⟩ :=
(coe_nnreal_eq ⟨x, h⟩).symm
#align ennreal.of_real_eq_coe_nnreal ENNReal.ofReal_eq_coe_nnreal

Expand Down Expand Up @@ -360,10 +360,10 @@ attribute [gcongr] ENNReal.coe_le_coe_of_le
alias ⟨_, coe_lt_coe_of_le⟩ := coe_lt_coe
attribute [gcongr] ENNReal.coe_lt_coe_of_le

theorem coe_mono : Monotone some := fun _ _ => coe_le_coe.2
theorem coe_mono : Monotone ofNNReal := fun _ _ => coe_le_coe.2
#align ennreal.coe_mono ENNReal.coe_mono

theorem coe_strictMono : StrictMono some := fun _ _ => coe_lt_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
#align ennreal.coe_eq_zero ENNReal.coe_eq_zero
Expand Down Expand Up @@ -938,11 +938,11 @@ theorem iInter_Ioi_coe_nat : ⋂ n : ℕ, Ioi (n : ℝ≥0∞) = {∞} := by
#align ennreal.add_lt_add ENNReal.add_lt_add

@[simp, norm_cast]
theorem coe_min : ((min r p : ℝ≥0) : ℝ≥0∞) = min (r : ℝ≥0∞) p := rfl
theorem coe_min (r p : ℝ≥0) : ((min r p : ℝ≥0) : ℝ≥0∞) = min (r : ℝ≥0∞) p := rfl
#align ennreal.coe_min ENNReal.coe_min

@[simp, norm_cast]
theorem coe_max : ((max r p : ℝ≥0) : ℝ≥0∞) = max (r : ℝ≥0∞) p := rfl
theorem coe_max (r p : ℝ≥0) : ((max r p : ℝ≥0) : ℝ≥0∞) = max (r : ℝ≥0∞) p := rfl
#align ennreal.coe_max ENNReal.coe_max

theorem le_of_top_imp_top_of_toNNReal_le {a b : ℝ≥0∞} (h : a = ⊤ → b = ⊤)
Expand Down Expand Up @@ -981,7 +981,7 @@ theorem coe_iInf {ι : Sort*} [Nonempty ι] (f : ι → ℝ≥0) : (↑(iInf f)
#align ennreal.coe_infi ENNReal.coe_iInf

theorem coe_mem_upperBounds {s : Set ℝ≥0} :
↑r ∈ upperBounds (some '' s) ↔ r ∈ upperBounds s := by
↑r ∈ upperBounds (ofNNReal '' s) ↔ r ∈ upperBounds s := by
simp (config := { contextual := true }) [upperBounds, ball_image_iff, -mem_image, *]
#align ennreal.coe_mem_upper_bounds ENNReal.coe_mem_upperBounds

Expand Down Expand Up @@ -2680,11 +2680,11 @@ def evalENNRealOfReal : PositivityExt where eval {_ _} _zα _pα e := do
| .positive pa => pure (.positive (q(Iff.mpr (@ENNReal.ofReal_pos $a) $pa) : Expr))
| _ => pure .none

/-- Extension for the `positivity` tactic: `ENNReal.some`. -/
@[positivity ENNReal.some _]
def evalENNRealSome : PositivityExt where eval {_ _} _zα _pα e := do
let (.app (f : Q(NNReal → ENNReal)) (a : Q(NNReal))) ← whnfR e | throwError "not ENNReal.some"
guard <|← withDefault <| withNewMCtxDepth <| isDefEq f q(ENNReal.some)
/-- Extension for the `positivity` tactic: `ENNReal.ofNNReal`. -/
@[positivity ENNReal.ofNNReal _]
def evalENNRealOfNNReal : PositivityExt where eval {_ _} _zα _pα e := do
let (.app (f : Q(NNReal → ENNReal)) (a : Q(NNReal))) ← whnfR e | throwError "not ENNReal.ofNNReal"
guard <|← withDefault <| withNewMCtxDepth <| isDefEq f q(ENNReal.ofNNReal)
let zα' ← synthInstanceQ (q(Zero NNReal) : Q(Type))
let pα' ← synthInstanceQ (q(PartialOrder NNReal) : Q(Type))
let ra ← core zα' pα' a
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/MeasureTheory/Function/L1Space.lean
Expand Up @@ -266,7 +266,7 @@ theorem hasFiniteIntegral_norm_iff (f : α → β) :
theorem hasFiniteIntegral_toReal_of_lintegral_ne_top {f : α → ℝ≥0∞} (hf : (∫⁻ x, f x ∂μ) ≠ ∞) :
HasFiniteIntegral (fun x => (f x).toReal) μ := by
have :
∀ x, (‖(f x).toReal‖₊ : ℝ≥0∞) = ENNReal.some ⟨(f x).toReal, ENNReal.toReal_nonneg⟩ := by
∀ x, (‖(f x).toReal‖₊ : ℝ≥0∞) = ENNReal.ofNNReal ⟨(f x).toReal, ENNReal.toReal_nonneg⟩ := by
intro x
rw [Real.nnnorm_of_nonneg]
simp_rw [HasFiniteIntegral, this]
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/MeasureTheory/Integral/Lebesgue.lean
Expand Up @@ -480,7 +480,7 @@ theorem exists_pos_set_lintegral_lt_of_measure_lt {f : α → ℝ≥0∞} (h :
rw [← SimpleFunc.add_lintegral, ← SimpleFunc.map_add @ENNReal.coe_add]
refine' SimpleFunc.lintegral_mono (fun x => _) le_rfl
simp only [add_tsub_eq_max, le_max_right, coe_map, Function.comp_apply, SimpleFunc.coe_add,
SimpleFunc.coe_sub, Pi.add_apply, Pi.sub_apply, WithTop.coe_max (φ x) (ψ x), ENNReal.some]
SimpleFunc.coe_sub, Pi.add_apply, Pi.sub_apply, ENNReal.coe_max (φ x) (ψ x)]
_ ≤ (map (↑) φ).lintegral (μ.restrict s) + ε₁ := by
refine' add_le_add le_rfl (le_trans _ (hφ _ hψ).le)
exact SimpleFunc.lintegral_mono le_rfl Measure.restrict_le_self
Expand Down
4 changes: 2 additions & 2 deletions Mathlib/Probability/Variance.lean
Expand Up @@ -272,8 +272,8 @@ theorem meas_ge_le_evariance_div_sq {X : Ω → ℝ} (hX : AEStronglyMeasurable
simp only [Pi.sub_apply, ENNReal.coe_le_coe, ← Real.norm_eq_abs, ← coe_nnnorm,
NNReal.coe_le_coe, ENNReal.ofReal_coe_nnreal]
· rw [snorm_eq_lintegral_rpow_nnnorm two_ne_zero ENNReal.two_ne_top]
simp only [show ENNReal.some (c ^ 2) = (ENNReal.some c) ^ 2 by norm_cast, coe_two, one_div,
Pi.sub_apply]
simp only [show ENNReal.ofNNReal (c ^ 2) = (ENNReal.ofNNReal c) ^ 2 by norm_cast, coe_two,
one_div, Pi.sub_apply]
rw [div_eq_mul_inv, ENNReal.inv_pow, mul_comm, ENNReal.rpow_two]
congr
simp_rw [← ENNReal.rpow_mul, inv_mul_cancel (two_ne_zero : (2 : ℝ) ≠ 0), ENNReal.rpow_two,
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/Topology/Instances/ENNReal.lean
Expand Up @@ -349,7 +349,7 @@ protected theorem tendsto_mul (ha : a ≠ 0 ∨ b ≠ ⊤) (hb : b ≠ 0 ∨ a
| top =>
simp only [ne_eq, or_false] at ha
simpa [(· ∘ ·), mul_comm, mul_top ha]
using (ht a ha).comp (continuous_swap.tendsto (some a, ⊤))
using (ht a ha).comp (continuous_swap.tendsto (ofNNReal a, ⊤))
| coe b =>
simp only [nhds_coe_coe, ← coe_mul, tendsto_coe, tendsto_map'_iff, (· ∘ ·), tendsto_mul]
#align ennreal.tendsto_mul ENNReal.tendsto_mul
Expand Down
2 changes: 1 addition & 1 deletion Mathlib/Topology/MetricSpace/PseudoMetric.lean
Expand Up @@ -115,7 +115,7 @@ class PseudoMetricSpace (α : Type u) extends Dist α : Type u where
dist_self : ∀ x : α, dist x x = 0
dist_comm : ∀ x y : α, dist x y = dist y x
dist_triangle : ∀ x y z : α, dist x z ≤ dist x y + dist y z
edist : α → α → ℝ≥0∞ := fun x y => ENNReal.some ⟨dist x y, dist_nonneg' _ ‹_› ‹_› ‹_›⟩
edist : α → α → ℝ≥0∞ := fun x y => ENNReal.ofNNReal ⟨dist x y, dist_nonneg' _ ‹_› ‹_› ‹_›⟩
edist_dist : ∀ x y : α, edist x y = ENNReal.ofReal (dist x y) -- porting note: todo: add := by _
toUniformSpace : UniformSpace α := .ofDist dist dist_self dist_comm dist_triangle
uniformity_dist : 𝓤 α = ⨅ ε > 0, 𝓟 { p : α × α | dist p.1 p.2 < ε } := by intros; rfl
Expand Down

0 comments on commit 4dd5ba0

Please sign in to comment.