l3lab/ntp-mathlib huggingface dataset:
/-- Normalize a finite measure so that it becomes a probability measure, i.e., divide by the
total mass. -/
def normalize : ProbabilityMeasure Ω :=
  if zero : μ.mass = 0 then ⟨Measure.dirac ‹Nonempty Ω›.some, Measure.dirac.isProbabilityMeasure⟩
  else
    { val := ↑(μ.mass⁻¹ • μ)
      property := by
        refine' ⟨_⟩
        -- porting note: paying the price that this isn't `simp` lemma now.
        

Proof state:
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
zero : ¬mass μ = 0
⊢ ↑↑↑((mass μ)⁻¹ • μ) univ = 1

Next tactic:
rw [FiniteMeasure.toMeasure_smul]
/-- Normalize a finite measure so that it becomes a probability measure, i.e., divide by the
total mass. -/
def normalize : ProbabilityMeasure Ω :=
  if zero : μ.mass = 0 then ⟨Measure.dirac ‹Nonempty Ω›.some, Measure.dirac.isProbabilityMeasure⟩
  else
    { val := ↑(μ.mass⁻¹ • μ)
      property := by
        refine' ⟨_⟩
        -- porting note: paying the price that this isn't `simp` lemma now.
        rw [FiniteMeasure.toMeasure_smul]
        

Proof state:
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
zero : ¬mass μ = 0
⊢ ↑↑((mass μ)⁻¹ • ↑μ) univ = 1

Next tactic:
simp only [Measure.smul_toOuterMeasure, OuterMeasure.coe_smul, Pi.smul_apply,
          Measure.nnreal_smul_coe_apply, ne_eq, mass_zero_iff, ENNReal.coe_inv zero, ennreal_mass]
/-- Normalize a finite measure so that it becomes a probability measure, i.e., divide by the
total mass. -/
def normalize : ProbabilityMeasure Ω :=
  if zero : μ.mass = 0 then ⟨Measure.dirac ‹Nonempty Ω›.some, Measure.dirac.isProbabilityMeasure⟩
  else
    { val := ↑(μ.mass⁻¹ • μ)
      property := by
        refine' ⟨_⟩
        -- porting note: paying the price that this isn't `simp` lemma now.
        rw [FiniteMeasure.toMeasure_smul]
        simp only [Measure.smul_toOuterMeasure, OuterMeasure.coe_smul, Pi.smul_apply,
          Measure.nnreal_smul_coe_apply, ne_eq, mass_zero_iff, ENNReal.coe_inv zero, ennreal_mass]
        

Proof state:
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
zero : ¬mass μ = 0
⊢ (↑↑↑μ univ)⁻¹ * ↑↑↑μ univ = 1

Next tactic:
rw [← Ne.def, ← ENNReal.coe_ne_zero, ennreal_mass] at zero
/-- Normalize a finite measure so that it becomes a probability measure, i.e., divide by the
total mass. -/
def normalize : ProbabilityMeasure Ω :=
  if zero : μ.mass = 0 then ⟨Measure.dirac ‹Nonempty Ω›.some, Measure.dirac.isProbabilityMeasure⟩
  else
    { val := ↑(μ.mass⁻¹ • μ)
      property := by
        refine' ⟨_⟩
        -- porting note: paying the price that this isn't `simp` lemma now.
        rw [FiniteMeasure.toMeasure_smul]
        simp only [Measure.smul_toOuterMeasure, OuterMeasure.coe_smul, Pi.smul_apply,
          Measure.nnreal_smul_coe_apply, ne_eq, mass_zero_iff, ENNReal.coe_inv zero, ennreal_mass]
        rw [← Ne.def, ← ENNReal.coe_ne_zero, ennreal_mass] at zero
        

Proof state:
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
zero : ↑↑↑μ univ ≠ 0
⊢ (↑↑↑μ univ)⁻¹ * ↑↑↑μ univ = 1

Next tactic:
exact ENNReal.inv_mul_cancel zero μ.prop.measure_univ_lt_top.ne
@[simp]
theorem self_eq_mass_mul_normalize (s : Set Ω) : μ s = μ.mass * μ.normalize s := by
  

Proof state:
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
s : Set Ω
⊢ (fun s => ENNReal.toNNReal (↑↑↑μ s)) s = mass μ * (fun s => ENNReal.toNNReal (↑↑↑(normalize μ) s)) s

Next tactic:
obtain rfl | h := eq_or_ne μ 0
@[simp]
theorem self_eq_mass_mul_normalize (s : Set Ω) : μ s = μ.mass * μ.normalize s := by
  obtain rfl | h := eq_or_ne μ 0
  · 

Proof state:
case inl
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
s : Set Ω
⊢ (fun s => ENNReal.toNNReal (↑↑↑0 s)) s = mass 0 * (fun s => ENNReal.toNNReal (↑↑↑(normalize 0) s)) s

Next tactic:
simp only [zero_mass, coeFn_zero, Pi.zero_apply, zero_mul]
@[simp]
theorem self_eq_mass_mul_normalize (s : Set Ω) : μ s = μ.mass * μ.normalize s := by
  obtain rfl | h := eq_or_ne μ 0
  · simp only [zero_mass, coeFn_zero, Pi.zero_apply, zero_mul]
    

Proof state:
case inl
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
s : Set Ω
⊢ ENNReal.toNNReal (↑↑↑0 s) = 0

Next tactic:
rfl
@[simp]
theorem self_eq_mass_mul_normalize (s : Set Ω) : μ s = μ.mass * μ.normalize s := by
  obtain rfl | h := eq_or_ne μ 0
  · simp only [zero_mass, coeFn_zero, Pi.zero_apply, zero_mul]
    rfl
  

Proof state:
case inr
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
s : Set Ω
h : μ ≠ 0
⊢ (fun s => ENNReal.toNNReal (↑↑↑μ s)) s = mass μ * (fun s => ENNReal.toNNReal (↑↑↑(normalize μ) s)) s

Next tactic:
have mass_nonzero : μ.mass ≠ 0 := by rwa [μ.mass_nonzero_iff]
@[simp]
theorem self_eq_mass_mul_normalize (s : Set Ω) : μ s = μ.mass * μ.normalize s := by
  obtain rfl | h := eq_or_ne μ 0
  · simp only [zero_mass, coeFn_zero, Pi.zero_apply, zero_mul]
    rfl
  have mass_nonzero : μ.mass ≠ 0 := by 

Proof state:
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
s : Set Ω
h : μ ≠ 0
⊢ mass μ ≠ 0

Next tactic:
rwa [μ.mass_nonzero_iff]
@[simp]
theorem self_eq_mass_mul_normalize (s : Set Ω) : μ s = μ.mass * μ.normalize s := by
  obtain rfl | h := eq_or_ne μ 0
  · simp only [zero_mass, coeFn_zero, Pi.zero_apply, zero_mul]
    rfl
  have mass_nonzero : μ.mass ≠ 0 := by rwa [μ.mass_nonzero_iff]
  

Proof state:
case inr
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
s : Set Ω
h : μ ≠ 0
mass_nonzero : mass μ ≠ 0
⊢ (fun s => ENNReal.toNNReal (↑↑↑μ s)) s = mass μ * (fun s => ENNReal.toNNReal (↑↑↑(normalize μ) s)) s

Next tactic:
simp only [normalize, dif_neg mass_nonzero]
@[simp]
theorem self_eq_mass_mul_normalize (s : Set Ω) : μ s = μ.mass * μ.normalize s := by
  obtain rfl | h := eq_or_ne μ 0
  · simp only [zero_mass, coeFn_zero, Pi.zero_apply, zero_mul]
    rfl
  have mass_nonzero : μ.mass ≠ 0 := by rwa [μ.mass_nonzero_iff]
  simp only [normalize, dif_neg mass_nonzero]
  

Proof state:
case inr
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
s : Set Ω
h : μ ≠ 0
mass_nonzero : mass μ ≠ 0
⊢ ENNReal.toNNReal (↑↑↑μ s) =
    mass μ *
      ENNReal.toNNReal (↑↑↑{ val := ↑((mass μ)⁻¹ • μ), property := (_ : IsProbabilityMeasure ↑((mass μ)⁻¹ • μ)) } s)

Next tactic:
change μ s = mass μ * ((mass μ)⁻¹ • μ) s
@[simp]
theorem self_eq_mass_mul_normalize (s : Set Ω) : μ s = μ.mass * μ.normalize s := by
  obtain rfl | h := eq_or_ne μ 0
  · simp only [zero_mass, coeFn_zero, Pi.zero_apply, zero_mul]
    rfl
  have mass_nonzero : μ.mass ≠ 0 := by rwa [μ.mass_nonzero_iff]
  simp only [normalize, dif_neg mass_nonzero]
  change μ s = mass μ * ((mass μ)⁻¹ • μ) s
  -- porting note: this `change` is a hack, but I had trouble coming up with something better
  

Proof state:
case inr
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
s : Set Ω
h : μ ≠ 0
mass_nonzero : mass μ ≠ 0
⊢ (fun s => ENNReal.toNNReal (↑↑↑μ s)) s = mass μ * (fun s => ENNReal.toNNReal (↑↑↑((mass μ)⁻¹ • μ) s)) s

Next tactic:
simp only [toMeasure_smul, Measure.smul_toOuterMeasure, OuterMeasure.coe_smul, Pi.smul_apply,
    Measure.nnreal_smul_coe_apply, ne_eq, mass_zero_iff, ENNReal.toNNReal_mul, ENNReal.toNNReal_coe,
    mul_inv_cancel_left₀ mass_nonzero]
theorem self_eq_mass_smul_normalize : μ = μ.mass • μ.normalize.toFiniteMeasure := by
  

Proof state:
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
⊢ μ = mass μ • ProbabilityMeasure.toFiniteMeasure (normalize μ)

Next tactic:
apply eq_of_forall_apply_eq
theorem self_eq_mass_smul_normalize : μ = μ.mass • μ.normalize.toFiniteMeasure := by
  apply eq_of_forall_apply_eq
  

Proof state:
case h
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
⊢ ∀ (s : Set Ω),
    MeasurableSet s →
      (fun s => ENNReal.toNNReal (↑↑↑μ s)) s =
        (fun s => ENNReal.toNNReal (↑↑↑(mass μ • ProbabilityMeasure.toFiniteMeasure (normalize μ)) s)) s

Next tactic:
intro s _s_mble
theorem self_eq_mass_smul_normalize : μ = μ.mass • μ.normalize.toFiniteMeasure := by
  apply eq_of_forall_apply_eq
  intro s _s_mble
  

Proof state:
case h
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
s : Set Ω
_s_mble : MeasurableSet s
⊢ (fun s => ENNReal.toNNReal (↑↑↑μ s)) s =
    (fun s => ENNReal.toNNReal (↑↑↑(mass μ • ProbabilityMeasure.toFiniteMeasure (normalize μ)) s)) s

Next tactic:
rw [μ.self_eq_mass_mul_normalize s, coeFn_smul_apply, smul_eq_mul,
    ProbabilityMeasure.coeFn_comp_toFiniteMeasure_eq_coeFn]
theorem normalize_eq_of_nonzero (nonzero : μ ≠ 0) (s : Set Ω) : μ.normalize s = μ.mass⁻¹ * μ s := by
  

Proof state:
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
nonzero : μ ≠ 0
s : Set Ω
⊢ (fun s => ENNReal.toNNReal (↑↑↑(normalize μ) s)) s = (mass μ)⁻¹ * (fun s => ENNReal.toNNReal (↑↑↑μ s)) s

Next tactic:
simp only [μ.self_eq_mass_mul_normalize, μ.mass_nonzero_iff.mpr nonzero, inv_mul_cancel_left₀,
    Ne.def, not_false_iff]
theorem normalize_eq_inv_mass_smul_of_nonzero (nonzero : μ ≠ 0) :
    μ.normalize.toFiniteMeasure = μ.mass⁻¹ • μ := by
  

Proof state:
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
nonzero : μ ≠ 0
⊢ ProbabilityMeasure.toFiniteMeasure (normalize μ) = (mass μ)⁻¹ • μ

Next tactic:
nth_rw 3 [μ.self_eq_mass_smul_normalize]
theorem normalize_eq_inv_mass_smul_of_nonzero (nonzero : μ ≠ 0) :
    μ.normalize.toFiniteMeasure = μ.mass⁻¹ • μ := by
  nth_rw 3 [μ.self_eq_mass_smul_normalize]
  

Proof state:
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
nonzero : μ ≠ 0
⊢ ProbabilityMeasure.toFiniteMeasure (normalize μ) =
    (mass μ)⁻¹ • mass μ • ProbabilityMeasure.toFiniteMeasure (normalize μ)

Next tactic:
rw [← smul_assoc]
theorem normalize_eq_inv_mass_smul_of_nonzero (nonzero : μ ≠ 0) :
    μ.normalize.toFiniteMeasure = μ.mass⁻¹ • μ := by
  nth_rw 3 [μ.self_eq_mass_smul_normalize]
  rw [← smul_assoc]
  

Proof state:
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
nonzero : μ ≠ 0
⊢ ProbabilityMeasure.toFiniteMeasure (normalize μ) =
    ((mass μ)⁻¹ • mass μ) • ProbabilityMeasure.toFiniteMeasure (normalize μ)

Next tactic:
simp only [μ.mass_nonzero_iff.mpr nonzero, Algebra.id.smul_eq_mul, inv_mul_cancel, Ne.def,
    not_false_iff, one_smul]
theorem toMeasure_normalize_eq_of_nonzero (nonzero : μ ≠ 0) :
    (μ.normalize : Measure Ω) = μ.mass⁻¹ • μ := by
  

Proof state:
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
nonzero : μ ≠ 0
⊢ ↑(normalize μ) = (mass μ)⁻¹ • ↑μ

Next tactic:
ext1 s _s_mble
theorem toMeasure_normalize_eq_of_nonzero (nonzero : μ ≠ 0) :
    (μ.normalize : Measure Ω) = μ.mass⁻¹ • μ := by
  ext1 s _s_mble
  

Proof state:
case h
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
nonzero : μ ≠ 0
s : Set Ω
_s_mble : MeasurableSet s
⊢ ↑↑↑(normalize μ) s = ↑↑((mass μ)⁻¹ • ↑μ) s

Next tactic:
rw [← μ.normalize.ennreal_coeFn_eq_coeFn_toMeasure s, μ.normalize_eq_of_nonzero nonzero s,
    ENNReal.coe_mul, ennreal_coeFn_eq_coeFn_toMeasure]
theorem toMeasure_normalize_eq_of_nonzero (nonzero : μ ≠ 0) :
    (μ.normalize : Measure Ω) = μ.mass⁻¹ • μ := by
  ext1 s _s_mble
  rw [← μ.normalize.ennreal_coeFn_eq_coeFn_toMeasure s, μ.normalize_eq_of_nonzero nonzero s,
    ENNReal.coe_mul, ennreal_coeFn_eq_coeFn_toMeasure]
  

Proof state:
case h
Ω : Type u_1
inst✝ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
nonzero : μ ≠ 0
s : Set Ω
_s_mble : MeasurableSet s
⊢ ↑(mass μ)⁻¹ * ↑↑↑μ s = ↑↑((mass μ)⁻¹ • ↑μ) s

Next tactic:
exact Measure.coe_nnreal_smul_apply _ _ _
@[simp]
theorem _root_.ProbabilityMeasure.toFiniteMeasure_normalize_eq_self {m0 : MeasurableSpace Ω}
    (μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure.normalize = μ := by
  

Proof state:
Ω : Type u_1
inst✝ : Nonempty Ω
m0✝ : MeasurableSpace Ω
μ✝ : FiniteMeasure Ω
m0 : MeasurableSpace Ω
μ : ProbabilityMeasure Ω
⊢ normalize (ProbabilityMeasure.toFiniteMeasure μ) = μ

Next tactic:
apply ProbabilityMeasure.eq_of_forall_apply_eq
@[simp]
theorem _root_.ProbabilityMeasure.toFiniteMeasure_normalize_eq_self {m0 : MeasurableSpace Ω}
    (μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure.normalize = μ := by
  apply ProbabilityMeasure.eq_of_forall_apply_eq
  

Proof state:
case h
Ω : Type u_1
inst✝ : Nonempty Ω
m0✝ : MeasurableSpace Ω
μ✝ : FiniteMeasure Ω
m0 : MeasurableSpace Ω
μ : ProbabilityMeasure Ω
⊢ ∀ (s : Set Ω),
    MeasurableSet s →
      (fun s => ENNReal.toNNReal (↑↑↑(normalize (ProbabilityMeasure.toFiniteMeasure μ)) s)) s =
        (fun s => ENNReal.toNNReal (↑↑↑μ s)) s

Next tactic:
intro s _s_mble
@[simp]
theorem _root_.ProbabilityMeasure.toFiniteMeasure_normalize_eq_self {m0 : MeasurableSpace Ω}
    (μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure.normalize = μ := by
  apply ProbabilityMeasure.eq_of_forall_apply_eq
  intro s _s_mble
  

Proof state:
case h
Ω : Type u_1
inst✝ : Nonempty Ω
m0✝ : MeasurableSpace Ω
μ✝ : FiniteMeasure Ω
m0 : MeasurableSpace Ω
μ : ProbabilityMeasure Ω
s : Set Ω
_s_mble : MeasurableSet s
⊢ (fun s => ENNReal.toNNReal (↑↑↑(normalize (ProbabilityMeasure.toFiniteMeasure μ)) s)) s =
    (fun s => ENNReal.toNNReal (↑↑↑μ s)) s

Next tactic:
rw [μ.toFiniteMeasure.normalize_eq_of_nonzero μ.toFiniteMeasure_nonzero s]
@[simp]
theorem _root_.ProbabilityMeasure.toFiniteMeasure_normalize_eq_self {m0 : MeasurableSpace Ω}
    (μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure.normalize = μ := by
  apply ProbabilityMeasure.eq_of_forall_apply_eq
  intro s _s_mble
  rw [μ.toFiniteMeasure.normalize_eq_of_nonzero μ.toFiniteMeasure_nonzero s]
  

Proof state:
case h
Ω : Type u_1
inst✝ : Nonempty Ω
m0✝ : MeasurableSpace Ω
μ✝ : FiniteMeasure Ω
m0 : MeasurableSpace Ω
μ : ProbabilityMeasure Ω
s : Set Ω
_s_mble : MeasurableSet s
⊢ (mass (ProbabilityMeasure.toFiniteMeasure μ))⁻¹ *
      (fun s => ENNReal.toNNReal (↑↑↑(ProbabilityMeasure.toFiniteMeasure μ) s)) s =
    (fun s => ENNReal.toNNReal (↑↑↑μ s)) s

Next tactic:
simp only [ProbabilityMeasure.mass_toFiniteMeasure, inv_one, one_mul]
@[simp]
theorem _root_.ProbabilityMeasure.toFiniteMeasure_normalize_eq_self {m0 : MeasurableSpace Ω}
    (μ : ProbabilityMeasure Ω) : μ.toFiniteMeasure.normalize = μ := by
  apply ProbabilityMeasure.eq_of_forall_apply_eq
  intro s _s_mble
  rw [μ.toFiniteMeasure.normalize_eq_of_nonzero μ.toFiniteMeasure_nonzero s]
  simp only [ProbabilityMeasure.mass_toFiniteMeasure, inv_one, one_mul]
  

Proof state:
case h
Ω : Type u_1
inst✝ : Nonempty Ω
m0✝ : MeasurableSpace Ω
μ✝ : FiniteMeasure Ω
m0 : MeasurableSpace Ω
μ : ProbabilityMeasure Ω
s : Set Ω
_s_mble : MeasurableSet s
⊢ ENNReal.toNNReal (↑↑↑(ProbabilityMeasure.toFiniteMeasure μ) s) = ENNReal.toNNReal (↑↑↑μ s)

Next tactic:
congr
/-- Averaging with respect to a finite measure is the same as integrating against
`MeasureTheory.FiniteMeasure.normalize`. -/
theorem average_eq_integral_normalize {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
    (nonzero : μ ≠ 0) (f : Ω → E) :
    average (μ : Measure Ω) f = ∫ ω, f ω ∂(μ.normalize : Measure Ω) := by
  

Proof state:
Ω : Type u_1
inst✝² : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
E : Type u_2
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace ℝ E
nonzero : μ ≠ 0
f : Ω → E
⊢ average (↑μ) f = ∫ (ω : Ω), f ω ∂↑(normalize μ)

Next tactic:
rw [μ.toMeasure_normalize_eq_of_nonzero nonzero, average]
/-- Averaging with respect to a finite measure is the same as integrating against
`MeasureTheory.FiniteMeasure.normalize`. -/
theorem average_eq_integral_normalize {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
    (nonzero : μ ≠ 0) (f : Ω → E) :
    average (μ : Measure Ω) f = ∫ ω, f ω ∂(μ.normalize : Measure Ω) := by
  rw [μ.toMeasure_normalize_eq_of_nonzero nonzero, average]
  

Proof state:
Ω : Type u_1
inst✝² : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
E : Type u_2
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace ℝ E
nonzero : μ ≠ 0
f : Ω → E
⊢ ∫ (x : Ω), f x ∂(↑↑↑μ univ)⁻¹ • ↑μ = ∫ (ω : Ω), f ω ∂(mass μ)⁻¹ • ↑μ

Next tactic:
congr
/-- Averaging with respect to a finite measure is the same as integrating against
`MeasureTheory.FiniteMeasure.normalize`. -/
theorem average_eq_integral_normalize {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
    (nonzero : μ ≠ 0) (f : Ω → E) :
    average (μ : Measure Ω) f = ∫ ω, f ω ∂(μ.normalize : Measure Ω) := by
  rw [μ.toMeasure_normalize_eq_of_nonzero nonzero, average]
  congr
  

Proof state:
case e_μ.e_a
Ω : Type u_1
inst✝² : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
E : Type u_2
inst✝¹ : NormedAddCommGroup E
inst✝ : NormedSpace ℝ E
nonzero : μ ≠ 0
f : Ω → E
⊢ (↑↑↑μ univ)⁻¹ = ↑(RingHom.toMonoidWithZeroHom ENNReal.ofNNRealHom) (mass μ)⁻¹

Next tactic:
simp [ENNReal.coe_inv (μ.mass_nonzero_iff.mpr nonzero), ennreal_mass]
theorem testAgainstNN_eq_mass_mul (f : Ω →ᵇ ℝ≥0) :
    μ.testAgainstNN f = μ.mass * μ.normalize.toFiniteMeasure.testAgainstNN f := by
  

Proof state:
Ω : Type u_1
inst✝¹ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
inst✝ : TopologicalSpace Ω
f : Ω →ᵇ ℝ≥0
⊢ testAgainstNN μ f = mass μ * testAgainstNN (ProbabilityMeasure.toFiniteMeasure (normalize μ)) f

Next tactic:
nth_rw 1 [μ.self_eq_mass_smul_normalize]
theorem testAgainstNN_eq_mass_mul (f : Ω →ᵇ ℝ≥0) :
    μ.testAgainstNN f = μ.mass * μ.normalize.toFiniteMeasure.testAgainstNN f := by
  nth_rw 1 [μ.self_eq_mass_smul_normalize]
  

Proof state:
Ω : Type u_1
inst✝¹ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
inst✝ : TopologicalSpace Ω
f : Ω →ᵇ ℝ≥0
⊢ testAgainstNN (mass μ • ProbabilityMeasure.toFiniteMeasure (normalize μ)) f =
    mass μ * testAgainstNN (ProbabilityMeasure.toFiniteMeasure (normalize μ)) f

Next tactic:
rw [μ.normalize.toFiniteMeasure.smul_testAgainstNN_apply μ.mass f, smul_eq_mul]
theorem normalize_testAgainstNN (nonzero : μ ≠ 0) (f : Ω →ᵇ ℝ≥0) :
    μ.normalize.toFiniteMeasure.testAgainstNN f = μ.mass⁻¹ * μ.testAgainstNN f := by
  

Proof state:
Ω : Type u_1
inst✝¹ : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
inst✝ : TopologicalSpace Ω
nonzero : μ ≠ 0
f : Ω →ᵇ ℝ≥0
⊢ testAgainstNN (ProbabilityMeasure.toFiniteMeasure (normalize μ)) f = (mass μ)⁻¹ * testAgainstNN μ f

Next tactic:
simp [μ.testAgainstNN_eq_mass_mul, inv_mul_cancel_left₀ <| μ.mass_nonzero_iff.mpr nonzero]
theorem tendsto_testAgainstNN_of_tendsto_normalize_testAgainstNN_of_tendsto_mass {γ : Type*}
    {F : Filter γ} {μs : γ → FiniteMeasure Ω}
    (μs_lim : Tendsto (fun i => (μs i).normalize) F (𝓝 μ.normalize))
    (mass_lim : Tendsto (fun i => (μs i).mass) F (𝓝 μ.mass)) (f : Ω →ᵇ ℝ≥0) :
    Tendsto (fun i => (μs i).testAgainstNN f) F (𝓝 (μ.testAgainstNN f)) := by
  

Proof state:
Ω : Type u_1
inst✝² : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
inst✝¹ : TopologicalSpace Ω
inst✝ : OpensMeasurableSpace Ω
γ : Type u_2
F : Filter γ
μs : γ → FiniteMeasure Ω
μs_lim : Tendsto (fun i => normalize (μs i)) F (𝓝 (normalize μ))
mass_lim : Tendsto (fun i => mass (μs i)) F (𝓝 (mass μ))
f : Ω →ᵇ ℝ≥0
⊢ Tendsto (fun i => testAgainstNN (μs i) f) F (𝓝 (testAgainstNN μ f))

Next tactic:
by_cases h_mass : μ.mass = 0
theorem tendsto_testAgainstNN_of_tendsto_normalize_testAgainstNN_of_tendsto_mass {γ : Type*}
    {F : Filter γ} {μs : γ → FiniteMeasure Ω}
    (μs_lim : Tendsto (fun i => (μs i).normalize) F (𝓝 μ.normalize))
    (mass_lim : Tendsto (fun i => (μs i).mass) F (𝓝 μ.mass)) (f : Ω →ᵇ ℝ≥0) :
    Tendsto (fun i => (μs i).testAgainstNN f) F (𝓝 (μ.testAgainstNN f)) := by
  by_cases h_mass : μ.mass = 0
  · 

Proof state:
case pos
Ω : Type u_1
inst✝² : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
inst✝¹ : TopologicalSpace Ω
inst✝ : OpensMeasurableSpace Ω
γ : Type u_2
F : Filter γ
μs : γ → FiniteMeasure Ω
μs_lim : Tendsto (fun i => normalize (μs i)) F (𝓝 (normalize μ))
mass_lim : Tendsto (fun i => mass (μs i)) F (𝓝 (mass μ))
f : Ω →ᵇ ℝ≥0
h_mass : mass μ = 0
⊢ Tendsto (fun i => testAgainstNN (μs i) f) F (𝓝 (testAgainstNN μ f))

Next tactic:
simp only [μ.mass_zero_iff.mp h_mass, zero_testAgainstNN_apply, zero_mass,
      eq_self_iff_true] at *
theorem tendsto_testAgainstNN_of_tendsto_normalize_testAgainstNN_of_tendsto_mass {γ : Type*}
    {F : Filter γ} {μs : γ → FiniteMeasure Ω}
    (μs_lim : Tendsto (fun i => (μs i).normalize) F (𝓝 μ.normalize))
    (mass_lim : Tendsto (fun i => (μs i).mass) F (𝓝 μ.mass)) (f : Ω →ᵇ ℝ≥0) :
    Tendsto (fun i => (μs i).testAgainstNN f) F (𝓝 (μ.testAgainstNN f)) := by
  by_cases h_mass : μ.mass = 0
  · simp only [μ.mass_zero_iff.mp h_mass, zero_testAgainstNN_apply, zero_mass,
      eq_self_iff_true] at *
    

Proof state:
case pos
Ω : Type u_1
inst✝² : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
inst✝¹ : TopologicalSpace Ω
inst✝ : OpensMeasurableSpace Ω
γ : Type u_2
F : Filter γ
μs : γ → FiniteMeasure Ω
f : Ω →ᵇ ℝ≥0
μs_lim : Tendsto (fun i => normalize (μs i)) F (𝓝 (normalize 0))
mass_lim : Tendsto (fun i => mass (μs i)) F (𝓝 0)
h_mass : True
⊢ Tendsto (fun i => testAgainstNN (μs i) f) F (𝓝 0)

Next tactic:
exact tendsto_zero_testAgainstNN_of_tendsto_zero_mass mass_lim f
theorem tendsto_testAgainstNN_of_tendsto_normalize_testAgainstNN_of_tendsto_mass {γ : Type*}
    {F : Filter γ} {μs : γ → FiniteMeasure Ω}
    (μs_lim : Tendsto (fun i => (μs i).normalize) F (𝓝 μ.normalize))
    (mass_lim : Tendsto (fun i => (μs i).mass) F (𝓝 μ.mass)) (f : Ω →ᵇ ℝ≥0) :
    Tendsto (fun i => (μs i).testAgainstNN f) F (𝓝 (μ.testAgainstNN f)) := by
  by_cases h_mass : μ.mass = 0
  · simp only [μ.mass_zero_iff.mp h_mass, zero_testAgainstNN_apply, zero_mass,
      eq_self_iff_true] at *
    exact tendsto_zero_testAgainstNN_of_tendsto_zero_mass mass_lim f
  

Proof state:
case neg
Ω : Type u_1
inst✝² : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
inst✝¹ : TopologicalSpace Ω
inst✝ : OpensMeasurableSpace Ω
γ : Type u_2
F : Filter γ
μs : γ → FiniteMeasure Ω
μs_lim : Tendsto (fun i => normalize (μs i)) F (𝓝 (normalize μ))
mass_lim : Tendsto (fun i => mass (μs i)) F (𝓝 (mass μ))
f : Ω →ᵇ ℝ≥0
h_mass : ¬mass μ = 0
⊢ Tendsto (fun i => testAgainstNN (μs i) f) F (𝓝 (testAgainstNN μ f))

Next tactic:
simp_rw [fun i => (μs i).testAgainstNN_eq_mass_mul f, μ.testAgainstNN_eq_mass_mul f]
theorem tendsto_testAgainstNN_of_tendsto_normalize_testAgainstNN_of_tendsto_mass {γ : Type*}
    {F : Filter γ} {μs : γ → FiniteMeasure Ω}
    (μs_lim : Tendsto (fun i => (μs i).normalize) F (𝓝 μ.normalize))
    (mass_lim : Tendsto (fun i => (μs i).mass) F (𝓝 μ.mass)) (f : Ω →ᵇ ℝ≥0) :
    Tendsto (fun i => (μs i).testAgainstNN f) F (𝓝 (μ.testAgainstNN f)) := by
  by_cases h_mass : μ.mass = 0
  · simp only [μ.mass_zero_iff.mp h_mass, zero_testAgainstNN_apply, zero_mass,
      eq_self_iff_true] at *
    exact tendsto_zero_testAgainstNN_of_tendsto_zero_mass mass_lim f
  simp_rw [fun i => (μs i).testAgainstNN_eq_mass_mul f, μ.testAgainstNN_eq_mass_mul f]
  

Proof state:
case neg
Ω : Type u_1
inst✝² : Nonempty Ω
m0 : MeasurableSpace Ω
μ : FiniteMeasure Ω
inst✝¹ : TopologicalSpace Ω
inst✝ : OpensMeasurableSpace Ω
γ : Type u_2
F : Filter γ
μs : γ → FiniteMeasure Ω
μs_lim : Tendsto (fun i => normalize (μs i)) F (𝓝 (normalize μ))
mass_lim : Tendsto (fun i => mass (μs i)) F (𝓝 (mass μ))
f : Ω →ᵇ ℝ≥0
h_mass : ¬mass μ = 0
⊢ Tendsto (fun i => mass (μs i) * testAgainstNN (ProbabilityMeasure.toFiniteMeasure (normalize (μs i))) f) F
    (𝓝 (mass μ * testAgainstNN (ProbabilityMeasure.toFiniteMeasure (normalize μ)) f))

Next tactic:
rw [ProbabilityMeasure.tendsto_nhds_iff_toFiniteMeasure_tendsto_nhds] at μs_lim