l3lab/ntp-mathlib huggingface dataset:
theorem isProbabilityMeasure {X : Ω → E} {s : Set E} (hns : μ s ≠ 0) (hnt : μ s ≠ ∞)
    (hu : IsUniform X s ℙ μ) : IsProbabilityMeasure ℙ :=
  ⟨by
    have : X ⁻¹' Set.univ = Set.univ := by simp only [Set.preimage_univ]
    

Proof state:
Ω : Type u_1
E : Type u_2
inst✝ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → E
s : Set E
hns : ↑↑μ s ≠ 0
hnt : ↑↑μ s ≠ ⊤
hu : IsUniform X s ℙ
this : X ⁻¹' Set.univ = Set.univ
⊢ ↑↑ℙ Set.univ = 1

Next tactic:
rw [← this, hu.measure_preimage hns hnt MeasurableSet.univ, Set.inter_univ,
      ENNReal.div_self hns hnt]
theorem hasPDF {X : Ω → E} {s : Set E} (hms : MeasurableSet s) (hns : μ s ≠ 0) (hnt : μ s ≠ ∞)
    (hu : IsUniform X s ℙ μ) : HasPDF X ℙ μ := by
  

Proof state:
Ω : Type u_1
E : Type u_2
inst✝ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → E
s : Set E
hms : MeasurableSet s
hns : ↑↑μ s ≠ 0
hnt : ↑↑μ s ≠ ⊤
hu : IsUniform X s ℙ
⊢ HasPDF X ℙ

Next tactic:
apply hasPDF_of_map_eq_withDensity (hu.aemeasurable hns hnt) (s.indicator ((μ s)⁻¹ • 1)) <|
    (measurable_one.aemeasurable.const_smul (μ s)⁻¹).indicator hms
theorem hasPDF {X : Ω → E} {s : Set E} (hms : MeasurableSet s) (hns : μ s ≠ 0) (hnt : μ s ≠ ∞)
    (hu : IsUniform X s ℙ μ) : HasPDF X ℙ μ := by
  apply hasPDF_of_map_eq_withDensity (hu.aemeasurable hns hnt) (s.indicator ((μ s)⁻¹ • 1)) <|
    (measurable_one.aemeasurable.const_smul (μ s)⁻¹).indicator hms
  

Proof state:
Ω : Type u_1
E : Type u_2
inst✝ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → E
s : Set E
hms : MeasurableSet s
hns : ↑↑μ s ≠ 0
hnt : ↑↑μ s ≠ ⊤
hu : IsUniform X s ℙ
⊢ map X ℙ = withDensity μ (Set.indicator s ((↑↑μ s)⁻¹ • 1))

Next tactic:
rw [hu, withDensity_indicator hms, withDensity_smul _ measurable_one, withDensity_one]
theorem hasPDF₀ {X : Ω → E} {s : Set E} (hms : NullMeasurableSet s μ) (hns : μ s ≠ 0)
    (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) : HasPDF X ℙ μ := by
  

Proof state:
Ω : Type u_1
E : Type u_2
inst✝ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → E
s : Set E
hms : NullMeasurableSet s
hns : ↑↑μ s ≠ 0
hnt : ↑↑μ s ≠ ⊤
hu : IsUniform X s ℙ
⊢ HasPDF X ℙ

Next tactic:
have hms' := measurableSet_toMeasurable μ s
theorem hasPDF₀ {X : Ω → E} {s : Set E} (hms : NullMeasurableSet s μ) (hns : μ s ≠ 0)
    (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) : HasPDF X ℙ μ := by
  have hms' := measurableSet_toMeasurable μ s
  

Proof state:
Ω : Type u_1
E : Type u_2
inst✝ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → E
s : Set E
hms : NullMeasurableSet s
hns : ↑↑μ s ≠ 0
hnt : ↑↑μ s ≠ ⊤
hu : IsUniform X s ℙ
hms' : MeasurableSet (toMeasurable μ s)
⊢ HasPDF X ℙ

Next tactic:
apply hasPDF (m := m) (ℙ := ℙ) (μ := μ) hms'
    (measure_toMeasurable s ▸ hns) (measure_toMeasurable s ▸ hnt) _
theorem hasPDF₀ {X : Ω → E} {s : Set E} (hms : NullMeasurableSet s μ) (hns : μ s ≠ 0)
    (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) : HasPDF X ℙ μ := by
  have hms' := measurableSet_toMeasurable μ s
  apply hasPDF (m := m) (ℙ := ℙ) (μ := μ) hms'
    (measure_toMeasurable s ▸ hns) (measure_toMeasurable s ▸ hnt) _
  

Proof state:
Ω : Type u_1
E : Type u_2
inst✝ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → E
s : Set E
hms : NullMeasurableSet s
hns : ↑↑μ s ≠ 0
hnt : ↑↑μ s ≠ ⊤
hu : IsUniform X s ℙ
hms' : MeasurableSet (toMeasurable μ s)
⊢ IsUniform X (toMeasurable μ s) ℙ

Next tactic:
unfold IsUniform
theorem hasPDF₀ {X : Ω → E} {s : Set E} (hms : NullMeasurableSet s μ) (hns : μ s ≠ 0)
    (hnt : μ s ≠ ∞) (hu : IsUniform X s ℙ μ) : HasPDF X ℙ μ := by
  have hms' := measurableSet_toMeasurable μ s
  apply hasPDF (m := m) (ℙ := ℙ) (μ := μ) hms'
    (measure_toMeasurable s ▸ hns) (measure_toMeasurable s ▸ hnt) _
  unfold IsUniform
  

Proof state:
Ω : Type u_1
E : Type u_2
inst✝ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → E
s : Set E
hms : NullMeasurableSet s
hns : ↑↑μ s ≠ 0
hnt : ↑↑μ s ≠ ⊤
hu : IsUniform X s ℙ
hms' : MeasurableSet (toMeasurable μ s)
⊢ map X ℙ = (↑↑μ (toMeasurable μ s))⁻¹ • restrict μ (toMeasurable μ s)

Next tactic:
rw [measure_toMeasurable, restrict_congr_set hms.toMeasurable_ae_eq, hu]
theorem pdf_eq {X : Ω → E} {s : Set E} (hms : MeasurableSet s) (hns : μ s ≠ 0) (hnt : μ s ≠ ∞)
    (hu : IsUniform X s ℙ μ) : pdf X ℙ μ =ᵐ[μ] s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) := by
  

Proof state:
Ω : Type u_1
E : Type u_2
inst✝ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → E
s : Set E
hms : MeasurableSet s
hns : ↑↑μ s ≠ 0
hnt : ↑↑μ s ≠ ⊤
hu : IsUniform X s ℙ
⊢ pdf X ℙ =ᶠ[ae μ] Set.indicator s ((↑↑μ s)⁻¹ • 1)

Next tactic:
have : HasPDF X ℙ μ := hasPDF hms hns hnt hu
theorem pdf_eq {X : Ω → E} {s : Set E} (hms : MeasurableSet s) (hns : μ s ≠ 0) (hnt : μ s ≠ ∞)
    (hu : IsUniform X s ℙ μ) : pdf X ℙ μ =ᵐ[μ] s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) := by
  have : HasPDF X ℙ μ := hasPDF hms hns hnt hu
  

Proof state:
Ω : Type u_1
E : Type u_2
inst✝ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → E
s : Set E
hms : MeasurableSet s
hns : ↑↑μ s ≠ 0
hnt : ↑↑μ s ≠ ⊤
hu : IsUniform X s ℙ
this : HasPDF X ℙ
⊢ pdf X ℙ =ᶠ[ae μ] Set.indicator s ((↑↑μ s)⁻¹ • 1)

Next tactic:
have : IsProbabilityMeasure ℙ := isProbabilityMeasure hns hnt hu
theorem pdf_eq {X : Ω → E} {s : Set E} (hms : MeasurableSet s) (hns : μ s ≠ 0) (hnt : μ s ≠ ∞)
    (hu : IsUniform X s ℙ μ) : pdf X ℙ μ =ᵐ[μ] s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) := by
  have : HasPDF X ℙ μ := hasPDF hms hns hnt hu
  have : IsProbabilityMeasure ℙ := isProbabilityMeasure hns hnt hu
  

Proof state:
Ω : Type u_1
E : Type u_2
inst✝ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → E
s : Set E
hms : MeasurableSet s
hns : ↑↑μ s ≠ 0
hnt : ↑↑μ s ≠ ⊤
hu : IsUniform X s ℙ
this✝ : HasPDF X ℙ
this : IsProbabilityMeasure ℙ
⊢ pdf X ℙ =ᶠ[ae μ] Set.indicator s ((↑↑μ s)⁻¹ • 1)

Next tactic:
apply (eq_of_map_eq_withDensity _ _).mp
theorem pdf_eq {X : Ω → E} {s : Set E} (hms : MeasurableSet s) (hns : μ s ≠ 0) (hnt : μ s ≠ ∞)
    (hu : IsUniform X s ℙ μ) : pdf X ℙ μ =ᵐ[μ] s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) := by
  have : HasPDF X ℙ μ := hasPDF hms hns hnt hu
  have : IsProbabilityMeasure ℙ := isProbabilityMeasure hns hnt hu
  apply (eq_of_map_eq_withDensity _ _).mp
  · 

Proof state:
Ω : Type u_1
E : Type u_2
inst✝ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → E
s : Set E
hms : MeasurableSet s
hns : ↑↑μ s ≠ 0
hnt : ↑↑μ s ≠ ⊤
hu : IsUniform X s ℙ
this✝ : HasPDF X ℙ
this : IsProbabilityMeasure ℙ
⊢ map X ℙ = withDensity μ (Set.indicator s ((↑↑μ s)⁻¹ • 1))

Next tactic:
rw [hu, withDensity_indicator hms, withDensity_smul _ measurable_one, withDensity_one]
theorem pdf_eq {X : Ω → E} {s : Set E} (hms : MeasurableSet s) (hns : μ s ≠ 0) (hnt : μ s ≠ ∞)
    (hu : IsUniform X s ℙ μ) : pdf X ℙ μ =ᵐ[μ] s.indicator ((μ s)⁻¹ • (1 : E → ℝ≥0∞)) := by
  have : HasPDF X ℙ μ := hasPDF hms hns hnt hu
  have : IsProbabilityMeasure ℙ := isProbabilityMeasure hns hnt hu
  apply (eq_of_map_eq_withDensity _ _).mp
  · rw [hu, withDensity_indicator hms, withDensity_smul _ measurable_one, withDensity_one]
  · 

Proof state:
Ω : Type u_1
E : Type u_2
inst✝ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → E
s : Set E
hms : MeasurableSet s
hns : ↑↑μ s ≠ 0
hnt : ↑↑μ s ≠ ⊤
hu : IsUniform X s ℙ
this✝ : HasPDF X ℙ
this : IsProbabilityMeasure ℙ
⊢ AEMeasurable (Set.indicator s ((↑↑μ s)⁻¹ • 1))

Next tactic:
exact (measurable_one.aemeasurable.const_smul (μ s)⁻¹).indicator hms
theorem mul_pdf_integrable [IsFiniteMeasure ℙ] (hcs : IsCompact s) (huX : IsUniform X s ℙ) :
    Integrable fun x : ℝ => x * (pdf X ℙ volume x).toReal := by
  

Proof state:
Ω : Type u_1
E : Type u_2
inst✝¹ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → ℝ
s : Set ℝ
hms : MeasurableSet s
hns : ↑↑volume s ≠ 0
hnt : ↑↑volume s ≠ ⊤
inst✝ : IsFiniteMeasure ℙ
hcs : IsCompact s
huX : IsUniform X s ℙ
⊢ Integrable fun x => x * ENNReal.toReal (pdf X ℙ x)

Next tactic:
constructor
theorem mul_pdf_integrable [IsFiniteMeasure ℙ] (hcs : IsCompact s) (huX : IsUniform X s ℙ) :
    Integrable fun x : ℝ => x * (pdf X ℙ volume x).toReal := by
  constructor -- porting note: `refine` was failing, don't know why
  · 

Proof state:
case left
Ω : Type u_1
E : Type u_2
inst✝¹ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → ℝ
s : Set ℝ
hms : MeasurableSet s
hns : ↑↑volume s ≠ 0
hnt : ↑↑volume s ≠ ⊤
inst✝ : IsFiniteMeasure ℙ
hcs : IsCompact s
huX : IsUniform X s ℙ
⊢ AEStronglyMeasurable (fun x => x * ENNReal.toReal (pdf X ℙ x)) volume

Next tactic:
exact aestronglyMeasurable_id.mul
      (measurable_pdf X ℙ).aemeasurable.ennreal_toReal.aestronglyMeasurable
theorem mul_pdf_integrable [IsFiniteMeasure ℙ] (hcs : IsCompact s) (huX : IsUniform X s ℙ) :
    Integrable fun x : ℝ => x * (pdf X ℙ volume x).toReal := by
  constructor -- porting note: `refine` was failing, don't know why
  · exact aestronglyMeasurable_id.mul
      (measurable_pdf X ℙ).aemeasurable.ennreal_toReal.aestronglyMeasurable
  

Proof state:
case right
Ω : Type u_1
E : Type u_2
inst✝¹ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → ℝ
s : Set ℝ
hms : MeasurableSet s
hns : ↑↑volume s ≠ 0
hnt : ↑↑volume s ≠ ⊤
inst✝ : IsFiniteMeasure ℙ
hcs : IsCompact s
huX : IsUniform X s ℙ
⊢ HasFiniteIntegral fun x => x * ENNReal.toReal (pdf X ℙ x)

Next tactic:
refine' hasFiniteIntegral_mul (pdf_eq hms hns hnt huX) _
theorem mul_pdf_integrable [IsFiniteMeasure ℙ] (hcs : IsCompact s) (huX : IsUniform X s ℙ) :
    Integrable fun x : ℝ => x * (pdf X ℙ volume x).toReal := by
  constructor -- porting note: `refine` was failing, don't know why
  · exact aestronglyMeasurable_id.mul
      (measurable_pdf X ℙ).aemeasurable.ennreal_toReal.aestronglyMeasurable
  refine' hasFiniteIntegral_mul (pdf_eq hms hns hnt huX) _
  

Proof state:
case right
Ω : Type u_1
E : Type u_2
inst✝¹ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → ℝ
s : Set ℝ
hms : MeasurableSet s
hns : ↑↑volume s ≠ 0
hnt : ↑↑volume s ≠ ⊤
inst✝ : IsFiniteMeasure ℙ
hcs : IsCompact s
huX : IsUniform X s ℙ
⊢ ∫⁻ (x : ℝ), ↑‖x‖₊ * Set.indicator s ((↑↑volume s)⁻¹ • 1) x ≠ ⊤

Next tactic:
set ind := (volume s)⁻¹ • (1 : ℝ → ℝ≥0∞)
theorem mul_pdf_integrable [IsFiniteMeasure ℙ] (hcs : IsCompact s) (huX : IsUniform X s ℙ) :
    Integrable fun x : ℝ => x * (pdf X ℙ volume x).toReal := by
  constructor -- porting note: `refine` was failing, don't know why
  · exact aestronglyMeasurable_id.mul
      (measurable_pdf X ℙ).aemeasurable.ennreal_toReal.aestronglyMeasurable
  refine' hasFiniteIntegral_mul (pdf_eq hms hns hnt huX) _
  set ind := (volume s)⁻¹ • (1 : ℝ → ℝ≥0∞)
  

Proof state:
case right
Ω : Type u_1
E : Type u_2
inst✝¹ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → ℝ
s : Set ℝ
hms : MeasurableSet s
hns : ↑↑volume s ≠ 0
hnt : ↑↑volume s ≠ ⊤
inst✝ : IsFiniteMeasure ℙ
hcs : IsCompact s
huX : IsUniform X s ℙ
ind : ℝ → ℝ≥0∞ := (↑↑volume s)⁻¹ • 1
⊢ ∫⁻ (x : ℝ), ↑‖x‖₊ * Set.indicator s ind x ≠ ⊤

Next tactic:
have : ∀ x, ↑‖x‖₊ * s.indicator ind x = s.indicator (fun x => ‖x‖₊ * ind x) x := fun x =>
    (s.indicator_mul_right (fun x => ↑‖x‖₊) ind).symm
theorem mul_pdf_integrable [IsFiniteMeasure ℙ] (hcs : IsCompact s) (huX : IsUniform X s ℙ) :
    Integrable fun x : ℝ => x * (pdf X ℙ volume x).toReal := by
  constructor -- porting note: `refine` was failing, don't know why
  · exact aestronglyMeasurable_id.mul
      (measurable_pdf X ℙ).aemeasurable.ennreal_toReal.aestronglyMeasurable
  refine' hasFiniteIntegral_mul (pdf_eq hms hns hnt huX) _
  set ind := (volume s)⁻¹ • (1 : ℝ → ℝ≥0∞)
  have : ∀ x, ↑‖x‖₊ * s.indicator ind x = s.indicator (fun x => ‖x‖₊ * ind x) x := fun x =>
    (s.indicator_mul_right (fun x => ↑‖x‖₊) ind).symm
  

Proof state:
case right
Ω : Type u_1
E : Type u_2
inst✝¹ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → ℝ
s : Set ℝ
hms : MeasurableSet s
hns : ↑↑volume s ≠ 0
hnt : ↑↑volume s ≠ ⊤
inst✝ : IsFiniteMeasure ℙ
hcs : IsCompact s
huX : IsUniform X s ℙ
ind : ℝ → ℝ≥0∞ := (↑↑volume s)⁻¹ • 1
this : ∀ (x : ℝ), ↑‖x‖₊ * Set.indicator s ind x = Set.indicator s (fun x => ↑‖x‖₊ * ind x) x
⊢ ∫⁻ (x : ℝ), ↑‖x‖₊ * Set.indicator s ind x ≠ ⊤

Next tactic:
simp only [this, lintegral_indicator _ hms, mul_one, Algebra.id.smul_eq_mul, Pi.one_apply,
    Pi.smul_apply]
theorem mul_pdf_integrable [IsFiniteMeasure ℙ] (hcs : IsCompact s) (huX : IsUniform X s ℙ) :
    Integrable fun x : ℝ => x * (pdf X ℙ volume x).toReal := by
  constructor -- porting note: `refine` was failing, don't know why
  · exact aestronglyMeasurable_id.mul
      (measurable_pdf X ℙ).aemeasurable.ennreal_toReal.aestronglyMeasurable
  refine' hasFiniteIntegral_mul (pdf_eq hms hns hnt huX) _
  set ind := (volume s)⁻¹ • (1 : ℝ → ℝ≥0∞)
  have : ∀ x, ↑‖x‖₊ * s.indicator ind x = s.indicator (fun x => ‖x‖₊ * ind x) x := fun x =>
    (s.indicator_mul_right (fun x => ↑‖x‖₊) ind).symm
  simp only [this, lintegral_indicator _ hms, mul_one, Algebra.id.smul_eq_mul, Pi.one_apply,
    Pi.smul_apply]
  

Proof state:
case right
Ω : Type u_1
E : Type u_2
inst✝¹ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → ℝ
s : Set ℝ
hms : MeasurableSet s
hns : ↑↑volume s ≠ 0
hnt : ↑↑volume s ≠ ⊤
inst✝ : IsFiniteMeasure ℙ
hcs : IsCompact s
huX : IsUniform X s ℙ
ind : ℝ → ℝ≥0∞ := (↑↑volume s)⁻¹ • 1
this : ∀ (x : ℝ), ↑‖x‖₊ * Set.indicator s ind x = Set.indicator s (fun x => ↑‖x‖₊ * ind x) x
⊢ ∫⁻ (x : ℝ) in s, ↑‖x‖₊ * (↑↑volume s)⁻¹ ∂volume ≠ ⊤

Next tactic:
rw [lintegral_mul_const _ measurable_nnnorm.coe_nnreal_ennreal]
theorem mul_pdf_integrable [IsFiniteMeasure ℙ] (hcs : IsCompact s) (huX : IsUniform X s ℙ) :
    Integrable fun x : ℝ => x * (pdf X ℙ volume x).toReal := by
  constructor -- porting note: `refine` was failing, don't know why
  · exact aestronglyMeasurable_id.mul
      (measurable_pdf X ℙ).aemeasurable.ennreal_toReal.aestronglyMeasurable
  refine' hasFiniteIntegral_mul (pdf_eq hms hns hnt huX) _
  set ind := (volume s)⁻¹ • (1 : ℝ → ℝ≥0∞)
  have : ∀ x, ↑‖x‖₊ * s.indicator ind x = s.indicator (fun x => ‖x‖₊ * ind x) x := fun x =>
    (s.indicator_mul_right (fun x => ↑‖x‖₊) ind).symm
  simp only [this, lintegral_indicator _ hms, mul_one, Algebra.id.smul_eq_mul, Pi.one_apply,
    Pi.smul_apply]
  rw [lintegral_mul_const _ measurable_nnnorm.coe_nnreal_ennreal]
  

Proof state:
case right
Ω : Type u_1
E : Type u_2
inst✝¹ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → ℝ
s : Set ℝ
hms : MeasurableSet s
hns : ↑↑volume s ≠ 0
hnt : ↑↑volume s ≠ ⊤
inst✝ : IsFiniteMeasure ℙ
hcs : IsCompact s
huX : IsUniform X s ℙ
ind : ℝ → ℝ≥0∞ := (↑↑volume s)⁻¹ • 1
this : ∀ (x : ℝ), ↑‖x‖₊ * Set.indicator s ind x = Set.indicator s (fun x => ↑‖x‖₊ * ind x) x
⊢ (∫⁻ (a : ℝ) in s, ↑‖a‖₊ ∂volume) * (↑↑volume s)⁻¹ ≠ ⊤

Next tactic:
refine' (ENNReal.mul_lt_top (set_lintegral_lt_top_of_isCompact hnt hcs continuous_nnnorm).ne
    (ENNReal.inv_lt_top.2 (pos_iff_ne_zero.mpr hns)).ne).ne
/-- A real uniform random variable `X` with support `s` has expectation
`(λ s)⁻¹ * ∫ x in s, x ∂λ` where `λ` is the Lebesgue measure. -/
theorem integral_eq (huX : IsUniform X s ℙ) :
    ∫ x, X x ∂ℙ = (volume s)⁻¹.toReal * ∫ x in s, x := by
  

Proof state:
Ω : Type u_1
E : Type u_2
inst✝ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → ℝ
s : Set ℝ
hms : MeasurableSet s
hns : ↑↑volume s ≠ 0
hnt : ↑↑volume s ≠ ⊤
huX : IsUniform X s ℙ
⊢ ∫ (x : Ω), X x ∂ℙ = ENNReal.toReal (↑↑volume s)⁻¹ * ∫ (x : ℝ) in s, x

Next tactic:
haveI := hasPDF hms hns hnt huX
/-- A real uniform random variable `X` with support `s` has expectation
`(λ s)⁻¹ * ∫ x in s, x ∂λ` where `λ` is the Lebesgue measure. -/
theorem integral_eq (huX : IsUniform X s ℙ) :
    ∫ x, X x ∂ℙ = (volume s)⁻¹.toReal * ∫ x in s, x := by
  haveI := hasPDF hms hns hnt huX
  

Proof state:
Ω : Type u_1
E : Type u_2
inst✝ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → ℝ
s : Set ℝ
hms : MeasurableSet s
hns : ↑↑volume s ≠ 0
hnt : ↑↑volume s ≠ ⊤
huX : IsUniform X s ℙ
this : HasPDF X ℙ
⊢ ∫ (x : Ω), X x ∂ℙ = ENNReal.toReal (↑↑volume s)⁻¹ * ∫ (x : ℝ) in s, x

Next tactic:
haveI := huX.isProbabilityMeasure hns hnt
/-- A real uniform random variable `X` with support `s` has expectation
`(λ s)⁻¹ * ∫ x in s, x ∂λ` where `λ` is the Lebesgue measure. -/
theorem integral_eq (huX : IsUniform X s ℙ) :
    ∫ x, X x ∂ℙ = (volume s)⁻¹.toReal * ∫ x in s, x := by
  haveI := hasPDF hms hns hnt huX
  haveI := huX.isProbabilityMeasure hns hnt
  

Proof state:
Ω : Type u_1
E : Type u_2
inst✝ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → ℝ
s : Set ℝ
hms : MeasurableSet s
hns : ↑↑volume s ≠ 0
hnt : ↑↑volume s ≠ ⊤
huX : IsUniform X s ℙ
this✝ : HasPDF X ℙ
this : IsProbabilityMeasure ℙ
⊢ ∫ (x : Ω), X x ∂ℙ = ENNReal.toReal (↑↑volume s)⁻¹ * ∫ (x : ℝ) in s, x

Next tactic:
rw [← integral_mul_eq_integral]
/-- A real uniform random variable `X` with support `s` has expectation
`(λ s)⁻¹ * ∫ x in s, x ∂λ` where `λ` is the Lebesgue measure. -/
theorem integral_eq (huX : IsUniform X s ℙ) :
    ∫ x, X x ∂ℙ = (volume s)⁻¹.toReal * ∫ x in s, x := by
  haveI := hasPDF hms hns hnt huX
  haveI := huX.isProbabilityMeasure hns hnt
  rw [← integral_mul_eq_integral]
  

Proof state:
Ω : Type u_1
E : Type u_2
inst✝ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → ℝ
s : Set ℝ
hms : MeasurableSet s
hns : ↑↑volume s ≠ 0
hnt : ↑↑volume s ≠ ⊤
huX : IsUniform X s ℙ
this✝ : HasPDF X ℙ
this : IsProbabilityMeasure ℙ
⊢ ∫ (x : ℝ), x * ENNReal.toReal (pdf (fun x => X x) ℙ x) = ENNReal.toReal (↑↑volume s)⁻¹ * ∫ (x : ℝ) in s, x

Next tactic:
rw [integral_congr_ae (Filter.EventuallyEq.mul (ae_eq_refl _) (pdf_toReal_ae_eq hms hns hnt huX))]
/-- A real uniform random variable `X` with support `s` has expectation
`(λ s)⁻¹ * ∫ x in s, x ∂λ` where `λ` is the Lebesgue measure. -/
theorem integral_eq (huX : IsUniform X s ℙ) :
    ∫ x, X x ∂ℙ = (volume s)⁻¹.toReal * ∫ x in s, x := by
  haveI := hasPDF hms hns hnt huX
  haveI := huX.isProbabilityMeasure hns hnt
  rw [← integral_mul_eq_integral]
  rw [integral_congr_ae (Filter.EventuallyEq.mul (ae_eq_refl _) (pdf_toReal_ae_eq hms hns hnt huX))]
  

Proof state:
Ω : Type u_1
E : Type u_2
inst✝ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → ℝ
s : Set ℝ
hms : MeasurableSet s
hns : ↑↑volume s ≠ 0
hnt : ↑↑volume s ≠ ⊤
huX : IsUniform X s ℙ
this✝ : HasPDF X ℙ
this : IsProbabilityMeasure ℙ
⊢ ∫ (a : ℝ), a * ENNReal.toReal (Set.indicator s ((↑↑volume s)⁻¹ • 1) a) ∂volume =
    ENNReal.toReal (↑↑volume s)⁻¹ * ∫ (x : ℝ) in s, x

Next tactic:
have :
    ∀ x,
      x * (s.indicator ((volume s)⁻¹ • (1 : ℝ → ℝ≥0∞)) x).toReal =
        x * s.indicator ((volume s)⁻¹.toReal • (1 : ℝ → ℝ)) x := by
    refine' fun x => congr_arg (x * ·) _
    by_cases hx : x ∈ s
    · simp [Set.indicator_of_mem hx]
    · simp [Set.indicator_of_not_mem hx]
/-- A real uniform random variable `X` with support `s` has expectation
`(λ s)⁻¹ * ∫ x in s, x ∂λ` where `λ` is the Lebesgue measure. -/
theorem integral_eq (huX : IsUniform X s ℙ) :
    ∫ x, X x ∂ℙ = (volume s)⁻¹.toReal * ∫ x in s, x := by
  haveI := hasPDF hms hns hnt huX
  haveI := huX.isProbabilityMeasure hns hnt
  rw [← integral_mul_eq_integral]
  rw [integral_congr_ae (Filter.EventuallyEq.mul (ae_eq_refl _) (pdf_toReal_ae_eq hms hns hnt huX))]
  have :
    ∀ x,
      x * (s.indicator ((volume s)⁻¹ • (1 : ℝ → ℝ≥0∞)) x).toReal =
        x * s.indicator ((volume s)⁻¹.toReal • (1 : ℝ → ℝ)) x := by
    

Proof state:
Ω : Type u_1
E : Type u_2
inst✝ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → ℝ
s : Set ℝ
hms : MeasurableSet s
hns : ↑↑volume s ≠ 0
hnt : ↑↑volume s ≠ ⊤
huX : IsUniform X s ℙ
this✝ : HasPDF X ℙ
this : IsProbabilityMeasure ℙ
⊢ ∀ (x : ℝ),
    x * ENNReal.toReal (Set.indicator s ((↑↑volume s)⁻¹ • 1) x) =
      x * Set.indicator s (ENNReal.toReal (↑↑volume s)⁻¹ • 1) x

Next tactic:
refine' fun x => congr_arg (x * ·) _
/-- A real uniform random variable `X` with support `s` has expectation
`(λ s)⁻¹ * ∫ x in s, x ∂λ` where `λ` is the Lebesgue measure. -/
theorem integral_eq (huX : IsUniform X s ℙ) :
    ∫ x, X x ∂ℙ = (volume s)⁻¹.toReal * ∫ x in s, x := by
  haveI := hasPDF hms hns hnt huX
  haveI := huX.isProbabilityMeasure hns hnt
  rw [← integral_mul_eq_integral]
  rw [integral_congr_ae (Filter.EventuallyEq.mul (ae_eq_refl _) (pdf_toReal_ae_eq hms hns hnt huX))]
  have :
    ∀ x,
      x * (s.indicator ((volume s)⁻¹ • (1 : ℝ → ℝ≥0∞)) x).toReal =
        x * s.indicator ((volume s)⁻¹.toReal • (1 : ℝ → ℝ)) x := by
    refine' fun x => congr_arg (x * ·) _
    

Proof state:
Ω : Type u_1
E : Type u_2
inst✝ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → ℝ
s : Set ℝ
hms : MeasurableSet s
hns : ↑↑volume s ≠ 0
hnt : ↑↑volume s ≠ ⊤
huX : IsUniform X s ℙ
this✝ : HasPDF X ℙ
this : IsProbabilityMeasure ℙ
x : ℝ
⊢ ENNReal.toReal (Set.indicator s ((↑↑volume s)⁻¹ • 1) x) = Set.indicator s (ENNReal.toReal (↑↑volume s)⁻¹ • 1) x

Next tactic:
by_cases hx : x ∈ s
/-- A real uniform random variable `X` with support `s` has expectation
`(λ s)⁻¹ * ∫ x in s, x ∂λ` where `λ` is the Lebesgue measure. -/
theorem integral_eq (huX : IsUniform X s ℙ) :
    ∫ x, X x ∂ℙ = (volume s)⁻¹.toReal * ∫ x in s, x := by
  haveI := hasPDF hms hns hnt huX
  haveI := huX.isProbabilityMeasure hns hnt
  rw [← integral_mul_eq_integral]
  rw [integral_congr_ae (Filter.EventuallyEq.mul (ae_eq_refl _) (pdf_toReal_ae_eq hms hns hnt huX))]
  have :
    ∀ x,
      x * (s.indicator ((volume s)⁻¹ • (1 : ℝ → ℝ≥0∞)) x).toReal =
        x * s.indicator ((volume s)⁻¹.toReal • (1 : ℝ → ℝ)) x := by
    refine' fun x => congr_arg (x * ·) _
    by_cases hx : x ∈ s
    · 

Proof state:
case pos
Ω : Type u_1
E : Type u_2
inst✝ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → ℝ
s : Set ℝ
hms : MeasurableSet s
hns : ↑↑volume s ≠ 0
hnt : ↑↑volume s ≠ ⊤
huX : IsUniform X s ℙ
this✝ : HasPDF X ℙ
this : IsProbabilityMeasure ℙ
x : ℝ
hx : x ∈ s
⊢ ENNReal.toReal (Set.indicator s ((↑↑volume s)⁻¹ • 1) x) = Set.indicator s (ENNReal.toReal (↑↑volume s)⁻¹ • 1) x

Next tactic:
simp [Set.indicator_of_mem hx]
/-- A real uniform random variable `X` with support `s` has expectation
`(λ s)⁻¹ * ∫ x in s, x ∂λ` where `λ` is the Lebesgue measure. -/
theorem integral_eq (huX : IsUniform X s ℙ) :
    ∫ x, X x ∂ℙ = (volume s)⁻¹.toReal * ∫ x in s, x := by
  haveI := hasPDF hms hns hnt huX
  haveI := huX.isProbabilityMeasure hns hnt
  rw [← integral_mul_eq_integral]
  rw [integral_congr_ae (Filter.EventuallyEq.mul (ae_eq_refl _) (pdf_toReal_ae_eq hms hns hnt huX))]
  have :
    ∀ x,
      x * (s.indicator ((volume s)⁻¹ • (1 : ℝ → ℝ≥0∞)) x).toReal =
        x * s.indicator ((volume s)⁻¹.toReal • (1 : ℝ → ℝ)) x := by
    refine' fun x => congr_arg (x * ·) _
    by_cases hx : x ∈ s
    · simp [Set.indicator_of_mem hx]
    · 

Proof state:
case neg
Ω : Type u_1
E : Type u_2
inst✝ : MeasurableSpace E
m : MeasurableSpace Ω
ℙ : Measure Ω
μ : Measure E
X : Ω → ℝ
s : Set ℝ
hms : MeasurableSet s
hns : ↑↑volume s ≠ 0
hnt : ↑↑volume s ≠ ⊤
huX : IsUniform X s ℙ
this✝ : HasPDF X ℙ
this : IsProbabilityMeasure ℙ
x : ℝ
hx : x ∉ s
⊢ ENNReal.toReal (Set.indicator s ((↑↑volume s)⁻¹ • 1) x) = Set.indicator s (ENNReal.toReal (↑↑volume s)⁻¹ • 1) x

Next tactic:
simp [Set.indicator_of_not_mem hx]