l3lab/ntp-mathlib huggingface dataset:
theorem variance_smul' {A : Type*} [CommSemiring A] [Algebra A ℝ] (c : A) (X : Ω → ℝ)
    (μ : Measure Ω) : variance (c • X) μ = c ^ 2 • variance X μ := by
  convert variance_smul (algebraMap A ℝ c) X μ using 1
  · 

Proof state:
case h.e'_2
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ✝ : Measure Ω
A : Type u_2
inst✝¹ : CommSemiring A
inst✝ : Algebra A ℝ
c : A
X : Ω → ℝ
μ : Measure Ω
⊢ variance (c • X) μ = variance ((algebraMap A ℝ) c • X) μ

Next tactic:
congr
theorem variance_smul' {A : Type*} [CommSemiring A] [Algebra A ℝ] (c : A) (X : Ω → ℝ)
    (μ : Measure Ω) : variance (c • X) μ = c ^ 2 • variance X μ := by
  convert variance_smul (algebraMap A ℝ c) X μ using 1
  · congr; 

Proof state:
case h.e'_2.e_X
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ✝ : Measure Ω
A : Type u_2
inst✝¹ : CommSemiring A
inst✝ : Algebra A ℝ
c : A
X : Ω → ℝ
μ : Measure Ω
⊢ c • X = (algebraMap A ℝ) c • X

Next tactic:
simp only [algebraMap_smul]
theorem variance_smul' {A : Type*} [CommSemiring A] [Algebra A ℝ] (c : A) (X : Ω → ℝ)
    (μ : Measure Ω) : variance (c • X) μ = c ^ 2 • variance X μ := by
  convert variance_smul (algebraMap A ℝ c) X μ using 1
  · congr; simp only [algebraMap_smul]
  · 

Proof state:
case h.e'_3
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ✝ : Measure Ω
A : Type u_2
inst✝¹ : CommSemiring A
inst✝ : Algebra A ℝ
c : A
X : Ω → ℝ
μ : Measure Ω
⊢ c ^ 2 • variance X μ = (algebraMap A ℝ) c ^ 2 * variance X μ

Next tactic:
simp only [Algebra.smul_def, map_pow]
theorem variance_def' [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ} (hX : Memℒp X 2) :
    Var[X] = 𝔼[X ^ 2] - 𝔼[X] ^ 2 := by
  

Proof state:
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hX : Memℒp X 2
⊢ variance X ℙ = (∫ (a : Ω), (X ^ 2) a) - (∫ (a : Ω), X a) ^ 2

Next tactic:
rw [hX.variance_eq, sub_sq', integral_sub', integral_add']
theorem variance_def' [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ} (hX : Memℒp X 2) :
    Var[X] = 𝔼[X ^ 2] - 𝔼[X] ^ 2 := by
  rw [hX.variance_eq, sub_sq', integral_sub', integral_add']; 

Proof state:
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hX : Memℒp X 2
⊢ ((∫ (a : Ω), (X ^ 2) a) + ∫ (a : Ω), ((fun x => ∫ (x : Ω), X x) ^ 2) a) -
      ∫ (a : Ω), (2 * X * fun x => ∫ (x : Ω), X x) a =
    (∫ (a : Ω), (X ^ 2) a) - (∫ (a : Ω), X a) ^ 2
case hf
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hX : Memℒp X 2
⊢ Integrable (X ^ 2)
case hg
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hX : Memℒp X 2
⊢ Integrable ((fun x => ∫ (x : Ω), X x) ^ 2)
case hf
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hX : Memℒp X 2
⊢ Integrable (X ^ 2 + (fun x => ∫ (x : Ω), X x) ^ 2)
case hg
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hX : Memℒp X 2
⊢ Integrable (2 * X * fun x => ∫ (x : Ω), X x)

Next tactic:
rotate_left
theorem variance_def' [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ} (hX : Memℒp X 2) :
    Var[X] = 𝔼[X ^ 2] - 𝔼[X] ^ 2 := by
  rw [hX.variance_eq, sub_sq', integral_sub', integral_add']; rotate_left
  · 

Proof state:
case hf
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hX : Memℒp X 2
⊢ Integrable (X ^ 2)

Next tactic:
exact hX.integrable_sq
theorem variance_def' [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ} (hX : Memℒp X 2) :
    Var[X] = 𝔼[X ^ 2] - 𝔼[X] ^ 2 := by
  rw [hX.variance_eq, sub_sq', integral_sub', integral_add']; rotate_left
  · exact hX.integrable_sq
  · 

Proof state:
case hg
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hX : Memℒp X 2
⊢ Integrable ((fun x => ∫ (x : Ω), X x) ^ 2)

Next tactic:
convert @integrable_const Ω ℝ (_) ℙ _ _ (𝔼[X] ^ 2)
theorem variance_def' [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ} (hX : Memℒp X 2) :
    Var[X] = 𝔼[X ^ 2] - 𝔼[X] ^ 2 := by
  rw [hX.variance_eq, sub_sq', integral_sub', integral_add']; rotate_left
  · exact hX.integrable_sq
  · convert @integrable_const Ω ℝ (_) ℙ _ _ (𝔼[X] ^ 2)
  · 

Proof state:
case hf
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hX : Memℒp X 2
⊢ Integrable (X ^ 2 + (fun x => ∫ (x : Ω), X x) ^ 2)

Next tactic:
apply hX.integrable_sq.add
theorem variance_def' [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ} (hX : Memℒp X 2) :
    Var[X] = 𝔼[X ^ 2] - 𝔼[X] ^ 2 := by
  rw [hX.variance_eq, sub_sq', integral_sub', integral_add']; rotate_left
  · exact hX.integrable_sq
  · convert @integrable_const Ω ℝ (_) ℙ _ _ (𝔼[X] ^ 2)
  · apply hX.integrable_sq.add
    

Proof state:
case hf
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hX : Memℒp X 2
⊢ Integrable ((fun x => ∫ (x : Ω), X x) ^ 2)

Next tactic:
convert @integrable_const Ω ℝ (_) ℙ _ _ (𝔼[X] ^ 2)
theorem variance_def' [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ} (hX : Memℒp X 2) :
    Var[X] = 𝔼[X ^ 2] - 𝔼[X] ^ 2 := by
  rw [hX.variance_eq, sub_sq', integral_sub', integral_add']; rotate_left
  · exact hX.integrable_sq
  · convert @integrable_const Ω ℝ (_) ℙ _ _ (𝔼[X] ^ 2)
  · apply hX.integrable_sq.add
    convert @integrable_const Ω ℝ (_) ℙ _ _ (𝔼[X] ^ 2)
  · 

Proof state:
case hg
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hX : Memℒp X 2
⊢ Integrable (2 * X * fun x => ∫ (x : Ω), X x)

Next tactic:
exact ((hX.integrable one_le_two).const_mul 2).mul_const' _
theorem variance_def' [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ} (hX : Memℒp X 2) :
    Var[X] = 𝔼[X ^ 2] - 𝔼[X] ^ 2 := by
  rw [hX.variance_eq, sub_sq', integral_sub', integral_add']; rotate_left
  · exact hX.integrable_sq
  · convert @integrable_const Ω ℝ (_) ℙ _ _ (𝔼[X] ^ 2)
  · apply hX.integrable_sq.add
    convert @integrable_const Ω ℝ (_) ℙ _ _ (𝔼[X] ^ 2)
  · exact ((hX.integrable one_le_two).const_mul 2).mul_const' _
  

Proof state:
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hX : Memℒp X 2
⊢ ((∫ (a : Ω), (X ^ 2) a) + ∫ (a : Ω), ((fun x => ∫ (x : Ω), X x) ^ 2) a) -
      ∫ (a : Ω), (2 * X * fun x => ∫ (x : Ω), X x) a =
    (∫ (a : Ω), (X ^ 2) a) - (∫ (a : Ω), X a) ^ 2

Next tactic:
simp only [Pi.pow_apply, integral_const, measure_univ, ENNReal.one_toReal, smul_eq_mul, one_mul,
    Pi.mul_apply, Pi.ofNat_apply, Nat.cast_ofNat, integral_mul_right, integral_mul_left]
theorem variance_def' [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ} (hX : Memℒp X 2) :
    Var[X] = 𝔼[X ^ 2] - 𝔼[X] ^ 2 := by
  rw [hX.variance_eq, sub_sq', integral_sub', integral_add']; rotate_left
  · exact hX.integrable_sq
  · convert @integrable_const Ω ℝ (_) ℙ _ _ (𝔼[X] ^ 2)
  · apply hX.integrable_sq.add
    convert @integrable_const Ω ℝ (_) ℙ _ _ (𝔼[X] ^ 2)
  · exact ((hX.integrable one_le_two).const_mul 2).mul_const' _
  simp only [Pi.pow_apply, integral_const, measure_univ, ENNReal.one_toReal, smul_eq_mul, one_mul,
    Pi.mul_apply, Pi.ofNat_apply, Nat.cast_ofNat, integral_mul_right, integral_mul_left]
  

Proof state:
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hX : Memℒp X 2
⊢ (∫ (a : Ω), X a ^ 2) + (∫ (x : Ω), X x) ^ 2 - (2 * ∫ (x : Ω), X x) * ∫ (x : Ω), X x =
    (∫ (a : Ω), X a ^ 2) - (∫ (x : Ω), X x) ^ 2

Next tactic:
ring
theorem variance_le_expectation_sq [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ}
    (hm : AEStronglyMeasurable X ℙ) : Var[X] ≤ 𝔼[X ^ 2] := by
  

Proof state:
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
⊢ variance X ℙ ≤ ∫ (a : Ω), (X ^ 2) a

Next tactic:
by_cases hX : Memℒp X 2
theorem variance_le_expectation_sq [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ}
    (hm : AEStronglyMeasurable X ℙ) : Var[X] ≤ 𝔼[X ^ 2] := by
  by_cases hX : Memℒp X 2
  · 

Proof state:
case pos
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : Memℒp X 2
⊢ variance X ℙ ≤ ∫ (a : Ω), (X ^ 2) a

Next tactic:
rw [variance_def' hX]
theorem variance_le_expectation_sq [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ}
    (hm : AEStronglyMeasurable X ℙ) : Var[X] ≤ 𝔼[X ^ 2] := by
  by_cases hX : Memℒp X 2
  · rw [variance_def' hX]
    

Proof state:
case pos
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : Memℒp X 2
⊢ (∫ (a : Ω), (X ^ 2) a) - (∫ (a : Ω), X a) ^ 2 ≤ ∫ (a : Ω), (X ^ 2) a

Next tactic:
simp only [sq_nonneg, sub_le_self_iff]
theorem variance_le_expectation_sq [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ}
    (hm : AEStronglyMeasurable X ℙ) : Var[X] ≤ 𝔼[X ^ 2] := by
  by_cases hX : Memℒp X 2
  · rw [variance_def' hX]
    simp only [sq_nonneg, sub_le_self_iff]
  

Proof state:
case neg
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : ¬Memℒp X 2
⊢ variance X ℙ ≤ ∫ (a : Ω), (X ^ 2) a

Next tactic:
rw [variance, evariance_eq_lintegral_ofReal, ← integral_eq_lintegral_of_nonneg_ae]
theorem variance_le_expectation_sq [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ}
    (hm : AEStronglyMeasurable X ℙ) : Var[X] ≤ 𝔼[X ^ 2] := by
  by_cases hX : Memℒp X 2
  · rw [variance_def' hX]
    simp only [sq_nonneg, sub_le_self_iff]
  rw [variance, evariance_eq_lintegral_ofReal, ← integral_eq_lintegral_of_nonneg_ae]
  

Proof state:
case neg
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : ¬Memℒp X 2
⊢ ∫ (a : Ω), (X a - ∫ (x : Ω), X x) ^ 2 ≤ ∫ (a : Ω), (X ^ 2) a
case neg.hf
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : ¬Memℒp X 2
⊢ 0 ≤ᵐ[ℙ] fun ω => (X ω - ∫ (x : Ω), X x) ^ 2
case neg.hfm
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : ¬Memℒp X 2
⊢ AEStronglyMeasurable (fun ω => (X ω - ∫ (x : Ω), X x) ^ 2) ℙ

Next tactic:
by_cases hint : Integrable X
theorem variance_le_expectation_sq [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ}
    (hm : AEStronglyMeasurable X ℙ) : Var[X] ≤ 𝔼[X ^ 2] := by
  by_cases hX : Memℒp X 2
  · rw [variance_def' hX]
    simp only [sq_nonneg, sub_le_self_iff]
  rw [variance, evariance_eq_lintegral_ofReal, ← integral_eq_lintegral_of_nonneg_ae]
  by_cases hint : Integrable X; 

Proof state:
case pos
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : ¬Memℒp X 2
hint : Integrable X
⊢ ∫ (a : Ω), (X a - ∫ (x : Ω), X x) ^ 2 ≤ ∫ (a : Ω), (X ^ 2) a
case neg
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : ¬Memℒp X 2
hint : ¬Integrable X
⊢ ∫ (a : Ω), (X a - ∫ (x : Ω), X x) ^ 2 ≤ ∫ (a : Ω), (X ^ 2) a
case neg.hf
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : ¬Memℒp X 2
⊢ 0 ≤ᵐ[ℙ] fun ω => (X ω - ∫ (x : Ω), X x) ^ 2
case neg.hfm
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : ¬Memℒp X 2
⊢ AEStronglyMeasurable (fun ω => (X ω - ∫ (x : Ω), X x) ^ 2) ℙ

Next tactic:
swap
theorem variance_le_expectation_sq [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ}
    (hm : AEStronglyMeasurable X ℙ) : Var[X] ≤ 𝔼[X ^ 2] := by
  by_cases hX : Memℒp X 2
  · rw [variance_def' hX]
    simp only [sq_nonneg, sub_le_self_iff]
  rw [variance, evariance_eq_lintegral_ofReal, ← integral_eq_lintegral_of_nonneg_ae]
  by_cases hint : Integrable X; swap
  · 

Proof state:
case neg
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : ¬Memℒp X 2
hint : ¬Integrable X
⊢ ∫ (a : Ω), (X a - ∫ (x : Ω), X x) ^ 2 ≤ ∫ (a : Ω), (X ^ 2) a

Next tactic:
simp only [integral_undef hint, Pi.pow_apply, Pi.sub_apply, sub_zero]
theorem variance_le_expectation_sq [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ}
    (hm : AEStronglyMeasurable X ℙ) : Var[X] ≤ 𝔼[X ^ 2] := by
  by_cases hX : Memℒp X 2
  · rw [variance_def' hX]
    simp only [sq_nonneg, sub_le_self_iff]
  rw [variance, evariance_eq_lintegral_ofReal, ← integral_eq_lintegral_of_nonneg_ae]
  by_cases hint : Integrable X; swap
  · simp only [integral_undef hint, Pi.pow_apply, Pi.sub_apply, sub_zero]
    

Proof state:
case neg
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : ¬Memℒp X 2
hint : ¬Integrable X
⊢ ∫ (a : Ω), X a ^ 2 ≤ ∫ (a : Ω), X a ^ 2

Next tactic:
exact le_rfl
theorem variance_le_expectation_sq [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ}
    (hm : AEStronglyMeasurable X ℙ) : Var[X] ≤ 𝔼[X ^ 2] := by
  by_cases hX : Memℒp X 2
  · rw [variance_def' hX]
    simp only [sq_nonneg, sub_le_self_iff]
  rw [variance, evariance_eq_lintegral_ofReal, ← integral_eq_lintegral_of_nonneg_ae]
  by_cases hint : Integrable X; swap
  · simp only [integral_undef hint, Pi.pow_apply, Pi.sub_apply, sub_zero]
    exact le_rfl
  · 

Proof state:
case pos
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : ¬Memℒp X 2
hint : Integrable X
⊢ ∫ (a : Ω), (X a - ∫ (x : Ω), X x) ^ 2 ≤ ∫ (a : Ω), (X ^ 2) a

Next tactic:
rw [integral_undef]
theorem variance_le_expectation_sq [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ}
    (hm : AEStronglyMeasurable X ℙ) : Var[X] ≤ 𝔼[X ^ 2] := by
  by_cases hX : Memℒp X 2
  · rw [variance_def' hX]
    simp only [sq_nonneg, sub_le_self_iff]
  rw [variance, evariance_eq_lintegral_ofReal, ← integral_eq_lintegral_of_nonneg_ae]
  by_cases hint : Integrable X; swap
  · simp only [integral_undef hint, Pi.pow_apply, Pi.sub_apply, sub_zero]
    exact le_rfl
  · rw [integral_undef]
    · 

Proof state:
case pos
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : ¬Memℒp X 2
hint : Integrable X
⊢ 0 ≤ ∫ (a : Ω), (X ^ 2) a

Next tactic:
exact integral_nonneg fun a => sq_nonneg _
theorem variance_le_expectation_sq [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ}
    (hm : AEStronglyMeasurable X ℙ) : Var[X] ≤ 𝔼[X ^ 2] := by
  by_cases hX : Memℒp X 2
  · rw [variance_def' hX]
    simp only [sq_nonneg, sub_le_self_iff]
  rw [variance, evariance_eq_lintegral_ofReal, ← integral_eq_lintegral_of_nonneg_ae]
  by_cases hint : Integrable X; swap
  · simp only [integral_undef hint, Pi.pow_apply, Pi.sub_apply, sub_zero]
    exact le_rfl
  · rw [integral_undef]
    · exact integral_nonneg fun a => sq_nonneg _
    · 

Proof state:
case pos
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : ¬Memℒp X 2
hint : Integrable X
⊢ ¬Integrable fun a => (X a - ∫ (x : Ω), X x) ^ 2

Next tactic:
intro h
theorem variance_le_expectation_sq [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ}
    (hm : AEStronglyMeasurable X ℙ) : Var[X] ≤ 𝔼[X ^ 2] := by
  by_cases hX : Memℒp X 2
  · rw [variance_def' hX]
    simp only [sq_nonneg, sub_le_self_iff]
  rw [variance, evariance_eq_lintegral_ofReal, ← integral_eq_lintegral_of_nonneg_ae]
  by_cases hint : Integrable X; swap
  · simp only [integral_undef hint, Pi.pow_apply, Pi.sub_apply, sub_zero]
    exact le_rfl
  · rw [integral_undef]
    · exact integral_nonneg fun a => sq_nonneg _
    · intro h
      

Proof state:
case pos
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : ¬Memℒp X 2
hint : Integrable X
h : Integrable fun a => (X a - ∫ (x : Ω), X x) ^ 2
⊢ False

Next tactic:
have A : Memℒp (X - fun ω : Ω => 𝔼[X]) 2 ℙ :=
        (memℒp_two_iff_integrable_sq (hint.aestronglyMeasurable.sub aestronglyMeasurable_const)).2 h
theorem variance_le_expectation_sq [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ}
    (hm : AEStronglyMeasurable X ℙ) : Var[X] ≤ 𝔼[X ^ 2] := by
  by_cases hX : Memℒp X 2
  · rw [variance_def' hX]
    simp only [sq_nonneg, sub_le_self_iff]
  rw [variance, evariance_eq_lintegral_ofReal, ← integral_eq_lintegral_of_nonneg_ae]
  by_cases hint : Integrable X; swap
  · simp only [integral_undef hint, Pi.pow_apply, Pi.sub_apply, sub_zero]
    exact le_rfl
  · rw [integral_undef]
    · exact integral_nonneg fun a => sq_nonneg _
    · intro h
      have A : Memℒp (X - fun ω : Ω => 𝔼[X]) 2 ℙ :=
        (memℒp_two_iff_integrable_sq (hint.aestronglyMeasurable.sub aestronglyMeasurable_const)).2 h
      

Proof state:
case pos
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : ¬Memℒp X 2
hint : Integrable X
h : Integrable fun a => (X a - ∫ (x : Ω), X x) ^ 2
A : Memℒp (X - fun ω => ∫ (a : Ω), X a) 2
⊢ False

Next tactic:
have B : Memℒp (fun _ : Ω => 𝔼[X]) 2 ℙ := memℒp_const _
theorem variance_le_expectation_sq [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ}
    (hm : AEStronglyMeasurable X ℙ) : Var[X] ≤ 𝔼[X ^ 2] := by
  by_cases hX : Memℒp X 2
  · rw [variance_def' hX]
    simp only [sq_nonneg, sub_le_self_iff]
  rw [variance, evariance_eq_lintegral_ofReal, ← integral_eq_lintegral_of_nonneg_ae]
  by_cases hint : Integrable X; swap
  · simp only [integral_undef hint, Pi.pow_apply, Pi.sub_apply, sub_zero]
    exact le_rfl
  · rw [integral_undef]
    · exact integral_nonneg fun a => sq_nonneg _
    · intro h
      have A : Memℒp (X - fun ω : Ω => 𝔼[X]) 2 ℙ :=
        (memℒp_two_iff_integrable_sq (hint.aestronglyMeasurable.sub aestronglyMeasurable_const)).2 h
      have B : Memℒp (fun _ : Ω => 𝔼[X]) 2 ℙ := memℒp_const _
      

Proof state:
case pos
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : ¬Memℒp X 2
hint : Integrable X
h : Integrable fun a => (X a - ∫ (x : Ω), X x) ^ 2
A : Memℒp (X - fun ω => ∫ (a : Ω), X a) 2
B : Memℒp (fun x => ∫ (a : Ω), X a) 2
⊢ False

Next tactic:
apply hX
theorem variance_le_expectation_sq [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ}
    (hm : AEStronglyMeasurable X ℙ) : Var[X] ≤ 𝔼[X ^ 2] := by
  by_cases hX : Memℒp X 2
  · rw [variance_def' hX]
    simp only [sq_nonneg, sub_le_self_iff]
  rw [variance, evariance_eq_lintegral_ofReal, ← integral_eq_lintegral_of_nonneg_ae]
  by_cases hint : Integrable X; swap
  · simp only [integral_undef hint, Pi.pow_apply, Pi.sub_apply, sub_zero]
    exact le_rfl
  · rw [integral_undef]
    · exact integral_nonneg fun a => sq_nonneg _
    · intro h
      have A : Memℒp (X - fun ω : Ω => 𝔼[X]) 2 ℙ :=
        (memℒp_two_iff_integrable_sq (hint.aestronglyMeasurable.sub aestronglyMeasurable_const)).2 h
      have B : Memℒp (fun _ : Ω => 𝔼[X]) 2 ℙ := memℒp_const _
      apply hX
      

Proof state:
case pos
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : ¬Memℒp X 2
hint : Integrable X
h : Integrable fun a => (X a - ∫ (x : Ω), X x) ^ 2
A : Memℒp (X - fun ω => ∫ (a : Ω), X a) 2
B : Memℒp (fun x => ∫ (a : Ω), X a) 2
⊢ Memℒp X 2

Next tactic:
convert A.add B
theorem variance_le_expectation_sq [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ}
    (hm : AEStronglyMeasurable X ℙ) : Var[X] ≤ 𝔼[X ^ 2] := by
  by_cases hX : Memℒp X 2
  · rw [variance_def' hX]
    simp only [sq_nonneg, sub_le_self_iff]
  rw [variance, evariance_eq_lintegral_ofReal, ← integral_eq_lintegral_of_nonneg_ae]
  by_cases hint : Integrable X; swap
  · simp only [integral_undef hint, Pi.pow_apply, Pi.sub_apply, sub_zero]
    exact le_rfl
  · rw [integral_undef]
    · exact integral_nonneg fun a => sq_nonneg _
    · intro h
      have A : Memℒp (X - fun ω : Ω => 𝔼[X]) 2 ℙ :=
        (memℒp_two_iff_integrable_sq (hint.aestronglyMeasurable.sub aestronglyMeasurable_const)).2 h
      have B : Memℒp (fun _ : Ω => 𝔼[X]) 2 ℙ := memℒp_const _
      apply hX
      convert A.add B
      

Proof state:
case h.e'_5
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : ¬Memℒp X 2
hint : Integrable X
h : Integrable fun a => (X a - ∫ (x : Ω), X x) ^ 2
A : Memℒp (X - fun ω => ∫ (a : Ω), X a) 2
B : Memℒp (fun x => ∫ (a : Ω), X a) 2
⊢ X = (X - fun ω => ∫ (a : Ω), X a) + fun x => ∫ (a : Ω), X a

Next tactic:
simp
theorem variance_le_expectation_sq [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ}
    (hm : AEStronglyMeasurable X ℙ) : Var[X] ≤ 𝔼[X ^ 2] := by
  by_cases hX : Memℒp X 2
  · rw [variance_def' hX]
    simp only [sq_nonneg, sub_le_self_iff]
  rw [variance, evariance_eq_lintegral_ofReal, ← integral_eq_lintegral_of_nonneg_ae]
  by_cases hint : Integrable X; swap
  · simp only [integral_undef hint, Pi.pow_apply, Pi.sub_apply, sub_zero]
    exact le_rfl
  · rw [integral_undef]
    · exact integral_nonneg fun a => sq_nonneg _
    · intro h
      have A : Memℒp (X - fun ω : Ω => 𝔼[X]) 2 ℙ :=
        (memℒp_two_iff_integrable_sq (hint.aestronglyMeasurable.sub aestronglyMeasurable_const)).2 h
      have B : Memℒp (fun _ : Ω => 𝔼[X]) 2 ℙ := memℒp_const _
      apply hX
      convert A.add B
      simp
  · 

Proof state:
case neg.hf
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : ¬Memℒp X 2
⊢ 0 ≤ᵐ[ℙ] fun ω => (X ω - ∫ (x : Ω), X x) ^ 2

Next tactic:
exact @ae_of_all _ (_) _ _ fun x => sq_nonneg _
theorem variance_le_expectation_sq [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ}
    (hm : AEStronglyMeasurable X ℙ) : Var[X] ≤ 𝔼[X ^ 2] := by
  by_cases hX : Memℒp X 2
  · rw [variance_def' hX]
    simp only [sq_nonneg, sub_le_self_iff]
  rw [variance, evariance_eq_lintegral_ofReal, ← integral_eq_lintegral_of_nonneg_ae]
  by_cases hint : Integrable X; swap
  · simp only [integral_undef hint, Pi.pow_apply, Pi.sub_apply, sub_zero]
    exact le_rfl
  · rw [integral_undef]
    · exact integral_nonneg fun a => sq_nonneg _
    · intro h
      have A : Memℒp (X - fun ω : Ω => 𝔼[X]) 2 ℙ :=
        (memℒp_two_iff_integrable_sq (hint.aestronglyMeasurable.sub aestronglyMeasurable_const)).2 h
      have B : Memℒp (fun _ : Ω => 𝔼[X]) 2 ℙ := memℒp_const _
      apply hX
      convert A.add B
      simp
  · exact @ae_of_all _ (_) _ _ fun x => sq_nonneg _
  · 

Proof state:
case neg.hfm
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hm : AEStronglyMeasurable X ℙ
hX : ¬Memℒp X 2
⊢ AEStronglyMeasurable (fun ω => (X ω - ∫ (x : Ω), X x) ^ 2) ℙ

Next tactic:
exact (AEMeasurable.pow_const (hm.aemeasurable.sub_const _) _).aestronglyMeasurable
theorem evariance_def' [@IsProbabilityMeasure Ω _ ℙ] {X : Ω → ℝ} (hX : AEStronglyMeasurable X ℙ) :
    eVar[X] = (∫⁻ ω, (‖X ω‖₊ ^ 2 :)) - ENNReal.ofReal (𝔼[X] ^ 2) := by
  

Proof state:
Ω : Type u_1
m : MeasurableSpace Ω
X✝ : Ω → ℝ
μ : Measure Ω
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : Ω → ℝ
hX : AEStronglyMeasurable X ℙ
⊢ evariance X ℙ = (∫⁻ (ω : Ω), ↑(‖X ω‖₊ ^ 2)) - ENNReal.ofReal ((∫ (a : Ω), X a) ^ 2)

Next tactic:
by_cases hℒ : Memℒp X 2