l3lab/ntp-mathlib huggingface dataset:
/-- The conditional expectation of the indicator of a function over an `m`-measurable set with
respect to the σ-algebra `m` is a.e. equal to the indicator of the conditional expectation. -/
theorem condexp_indicator (hf_int : Integrable f μ) (hs : MeasurableSet[m] s) :
    μ[s.indicator f|m] =ᵐ[μ] s.indicator (μ[f|m]) := by
  by_cases hm : m ≤ m0
  swap; · simp_rw [condexp_of_not_le hm, Set.indicator_zero']; rfl
  by_cases hμm : SigmaFinite (μ.trim hm)
  swap; · simp_rw [condexp_of_not_sigmaFinite hm hμm, Set.indicator_zero']; rfl
  haveI : SigmaFinite (μ.trim hm) := hμm
  -- use `have` to perform what should be the first calc step because of an error I don't
  -- understand
  have : s.indicator (μ[f|m]) =ᵐ[μ] s.indicator (μ[s.indicator f + sᶜ.indicator f|m]) := by
    rw [Set.indicator_self_add_compl s f]
  refine' (this.trans _).symm
  calc
    s.indicator (μ[s.indicator f + sᶜ.indicator f|m]) =ᵐ[μ]
        s.indicator (μ[s.indicator f|m] + μ[sᶜ.indicator f|m]) := by
      have : μ[s.indicator f + sᶜ.indicator f|m] =ᵐ[μ] μ[s.indicator f|m] + μ[sᶜ.indicator f|m] :=
        condexp_add (hf_int.indicator (hm _ hs)) (hf_int.indicator (hm _ hs.compl))
      filter_upwards [this] with x hx
      classical rw [Set.indicator_apply, Set.indicator_apply, hx]
    _ = s.indicator (μ[s.indicator f|m]) + s.indicator (μ[sᶜ.indicator f|m]) :=
      (s.indicator_add' _ _)
    _ =ᵐ[μ] s.indicator (μ[s.indicator f|m]) +
        s.indicator (sᶜ.indicator (μ[sᶜ.indicator f|m])) := by
      refine' Filter.EventuallyEq.rfl.add _
      have : sᶜ.indicator (μ[sᶜ.indicator f|m]) =ᵐ[μ] μ[sᶜ.indicator f|m] := by
        refine' (condexp_indicator_aux hs.compl _).symm.trans _
        · exact indicator_ae_eq_restrict_compl (hm _ hs.compl)
        · rw [Set.indicator_indicator, Set.inter_self]
      filter_upwards [this] with x hx
      by_cases hxs : x ∈ s
      · simp only [hx, hxs, Set.indicator_of_mem]
      · simp only [hxs, Set.indicator_of_not_mem, not_false_iff]
    _ =ᵐ[μ] s.indicator (μ[s.indicator f|m]) := by
      rw [Set.indicator_indicator, Set.inter_compl_self, Set.indicator_empty', add_zero]
    _ =ᵐ[μ] μ[s.indicator f|m] := by
      refine' (condexp_indicator_aux hs _).symm.trans _
      · 

Proof state:
case refine'_1
α : Type u_1
𝕜 : Type u_2
E : Type u_3
m m0 : MeasurableSpace α
inst✝² : NormedAddCommGroup E
inst✝¹ : NormedSpace ℝ E
inst✝ : CompleteSpace E
μ : Measure α
f : α → E
s : Set α
hf_int : Integrable f
hs : MeasurableSet s
hm : m ≤ m0
hμm this✝ : SigmaFinite (Measure.trim μ hm)
this : Set.indicator s (μ[f|m]) =ᵐ[μ] Set.indicator s (μ[Set.indicator s f + Set.indicator sᶜ f|m])
⊢ Set.indicator s f =ᵐ[Measure.restrict μ sᶜ] 0

Next tactic:
exact indicator_ae_eq_restrict_compl (hm _ hs)
/-- The conditional expectation of the indicator of a function over an `m`-measurable set with
respect to the σ-algebra `m` is a.e. equal to the indicator of the conditional expectation. -/
theorem condexp_indicator (hf_int : Integrable f μ) (hs : MeasurableSet[m] s) :
    μ[s.indicator f|m] =ᵐ[μ] s.indicator (μ[f|m]) := by
  by_cases hm : m ≤ m0
  swap; · simp_rw [condexp_of_not_le hm, Set.indicator_zero']; rfl
  by_cases hμm : SigmaFinite (μ.trim hm)
  swap; · simp_rw [condexp_of_not_sigmaFinite hm hμm, Set.indicator_zero']; rfl
  haveI : SigmaFinite (μ.trim hm) := hμm
  -- use `have` to perform what should be the first calc step because of an error I don't
  -- understand
  have : s.indicator (μ[f|m]) =ᵐ[μ] s.indicator (μ[s.indicator f + sᶜ.indicator f|m]) := by
    rw [Set.indicator_self_add_compl s f]
  refine' (this.trans _).symm
  calc
    s.indicator (μ[s.indicator f + sᶜ.indicator f|m]) =ᵐ[μ]
        s.indicator (μ[s.indicator f|m] + μ[sᶜ.indicator f|m]) := by
      have : μ[s.indicator f + sᶜ.indicator f|m] =ᵐ[μ] μ[s.indicator f|m] + μ[sᶜ.indicator f|m] :=
        condexp_add (hf_int.indicator (hm _ hs)) (hf_int.indicator (hm _ hs.compl))
      filter_upwards [this] with x hx
      classical rw [Set.indicator_apply, Set.indicator_apply, hx]
    _ = s.indicator (μ[s.indicator f|m]) + s.indicator (μ[sᶜ.indicator f|m]) :=
      (s.indicator_add' _ _)
    _ =ᵐ[μ] s.indicator (μ[s.indicator f|m]) +
        s.indicator (sᶜ.indicator (μ[sᶜ.indicator f|m])) := by
      refine' Filter.EventuallyEq.rfl.add _
      have : sᶜ.indicator (μ[sᶜ.indicator f|m]) =ᵐ[μ] μ[sᶜ.indicator f|m] := by
        refine' (condexp_indicator_aux hs.compl _).symm.trans _
        · exact indicator_ae_eq_restrict_compl (hm _ hs.compl)
        · rw [Set.indicator_indicator, Set.inter_self]
      filter_upwards [this] with x hx
      by_cases hxs : x ∈ s
      · simp only [hx, hxs, Set.indicator_of_mem]
      · simp only [hxs, Set.indicator_of_not_mem, not_false_iff]
    _ =ᵐ[μ] s.indicator (μ[s.indicator f|m]) := by
      rw [Set.indicator_indicator, Set.inter_compl_self, Set.indicator_empty', add_zero]
    _ =ᵐ[μ] μ[s.indicator f|m] := by
      refine' (condexp_indicator_aux hs _).symm.trans _
      · exact indicator_ae_eq_restrict_compl (hm _ hs)
      · 

Proof state:
case refine'_2
α : Type u_1
𝕜 : Type u_2
E : Type u_3
m m0 : MeasurableSpace α
inst✝² : NormedAddCommGroup E
inst✝¹ : NormedSpace ℝ E
inst✝ : CompleteSpace E
μ : Measure α
f : α → E
s : Set α
hf_int : Integrable f
hs : MeasurableSet s
hm : m ≤ m0
hμm this✝ : SigmaFinite (Measure.trim μ hm)
this : Set.indicator s (μ[f|m]) =ᵐ[μ] Set.indicator s (μ[Set.indicator s f + Set.indicator sᶜ f|m])
⊢ μ[Set.indicator s (Set.indicator s f)|m] =ᵐ[μ] μ[Set.indicator s f|m]

Next tactic:
rw [Set.indicator_indicator, Set.inter_self]
theorem condexp_restrict_ae_eq_restrict (hm : m ≤ m0) [SigmaFinite (μ.trim hm)]
    (hs_m : MeasurableSet[m] s) (hf_int : Integrable f μ) :
    (μ.restrict s)[f|m] =ᵐ[μ.restrict s] μ[f|m] := by
  

Proof state:
α : Type u_1
𝕜 : Type u_2
E : Type u_3
m m0 : MeasurableSpace α
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure α
f : α → E
s : Set α
hm : m ≤ m0
inst✝ : SigmaFinite (Measure.trim μ hm)
hs_m : MeasurableSet s
hf_int : Integrable f
⊢ Measure.restrict μ s[f|m] =ᵐ[Measure.restrict μ s] μ[f|m]

Next tactic:
have : SigmaFinite ((μ.restrict s).trim hm) := by rw [← restrict_trim hm _ hs_m]; infer_instance
theorem condexp_restrict_ae_eq_restrict (hm : m ≤ m0) [SigmaFinite (μ.trim hm)]
    (hs_m : MeasurableSet[m] s) (hf_int : Integrable f μ) :
    (μ.restrict s)[f|m] =ᵐ[μ.restrict s] μ[f|m] := by
  have : SigmaFinite ((μ.restrict s).trim hm) := by 

Proof state:
α : Type u_1
𝕜 : Type u_2
E : Type u_3
m m0 : MeasurableSpace α
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure α
f : α → E
s : Set α
hm : m ≤ m0
inst✝ : SigmaFinite (Measure.trim μ hm)
hs_m : MeasurableSet s
hf_int : Integrable f
⊢ SigmaFinite (Measure.trim (Measure.restrict μ s) hm)

Next tactic:
rw [← restrict_trim hm _ hs_m]
theorem condexp_restrict_ae_eq_restrict (hm : m ≤ m0) [SigmaFinite (μ.trim hm)]
    (hs_m : MeasurableSet[m] s) (hf_int : Integrable f μ) :
    (μ.restrict s)[f|m] =ᵐ[μ.restrict s] μ[f|m] := by
  have : SigmaFinite ((μ.restrict s).trim hm) := by rw [← restrict_trim hm _ hs_m]; 

Proof state:
α : Type u_1
𝕜 : Type u_2
E : Type u_3
m m0 : MeasurableSpace α
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure α
f : α → E
s : Set α
hm : m ≤ m0
inst✝ : SigmaFinite (Measure.trim μ hm)
hs_m : MeasurableSet s
hf_int : Integrable f
⊢ SigmaFinite (Measure.restrict (Measure.trim μ hm) s)

Next tactic:
infer_instance
theorem condexp_restrict_ae_eq_restrict (hm : m ≤ m0) [SigmaFinite (μ.trim hm)]
    (hs_m : MeasurableSet[m] s) (hf_int : Integrable f μ) :
    (μ.restrict s)[f|m] =ᵐ[μ.restrict s] μ[f|m] := by
  have : SigmaFinite ((μ.restrict s).trim hm) := by rw [← restrict_trim hm _ hs_m]; infer_instance
  

Proof state:
α : Type u_1
𝕜 : Type u_2
E : Type u_3
m m0 : MeasurableSpace α
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure α
f : α → E
s : Set α
hm : m ≤ m0
inst✝ : SigmaFinite (Measure.trim μ hm)
hs_m : MeasurableSet s
hf_int : Integrable f
this : SigmaFinite (Measure.trim (Measure.restrict μ s) hm)
⊢ Measure.restrict μ s[f|m] =ᵐ[Measure.restrict μ s] μ[f|m]

Next tactic:
rw [ae_eq_restrict_iff_indicator_ae_eq (hm _ hs_m)]
theorem condexp_restrict_ae_eq_restrict (hm : m ≤ m0) [SigmaFinite (μ.trim hm)]
    (hs_m : MeasurableSet[m] s) (hf_int : Integrable f μ) :
    (μ.restrict s)[f|m] =ᵐ[μ.restrict s] μ[f|m] := by
  have : SigmaFinite ((μ.restrict s).trim hm) := by rw [← restrict_trim hm _ hs_m]; infer_instance
  rw [ae_eq_restrict_iff_indicator_ae_eq (hm _ hs_m)]
  

Proof state:
α : Type u_1
𝕜 : Type u_2
E : Type u_3
m m0 : MeasurableSpace α
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure α
f : α → E
s : Set α
hm : m ≤ m0
inst✝ : SigmaFinite (Measure.trim μ hm)
hs_m : MeasurableSet s
hf_int : Integrable f
this : SigmaFinite (Measure.trim (Measure.restrict μ s) hm)
⊢ Set.indicator s (Measure.restrict μ s[f|m]) =ᵐ[μ] Set.indicator s (μ[f|m])

Next tactic:
refine' EventuallyEq.trans _ (condexp_indicator hf_int hs_m)
theorem condexp_restrict_ae_eq_restrict (hm : m ≤ m0) [SigmaFinite (μ.trim hm)]
    (hs_m : MeasurableSet[m] s) (hf_int : Integrable f μ) :
    (μ.restrict s)[f|m] =ᵐ[μ.restrict s] μ[f|m] := by
  have : SigmaFinite ((μ.restrict s).trim hm) := by rw [← restrict_trim hm _ hs_m]; infer_instance
  rw [ae_eq_restrict_iff_indicator_ae_eq (hm _ hs_m)]
  refine' EventuallyEq.trans _ (condexp_indicator hf_int hs_m)
  

Proof state:
α : Type u_1
𝕜 : Type u_2
E : Type u_3
m m0 : MeasurableSpace α
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure α
f : α → E
s : Set α
hm : m ≤ m0
inst✝ : SigmaFinite (Measure.trim μ hm)
hs_m : MeasurableSet s
hf_int : Integrable f
this : SigmaFinite (Measure.trim (Measure.restrict μ s) hm)
⊢ Set.indicator s (Measure.restrict μ s[f|m]) =ᵐ[μ] μ[Set.indicator s f|m]

Next tactic:
refine' ae_eq_condexp_of_forall_set_integral_eq hm (hf_int.indicator (hm _ hs_m)) _ _ _
theorem condexp_restrict_ae_eq_restrict (hm : m ≤ m0) [SigmaFinite (μ.trim hm)]
    (hs_m : MeasurableSet[m] s) (hf_int : Integrable f μ) :
    (μ.restrict s)[f|m] =ᵐ[μ.restrict s] μ[f|m] := by
  have : SigmaFinite ((μ.restrict s).trim hm) := by rw [← restrict_trim hm _ hs_m]; infer_instance
  rw [ae_eq_restrict_iff_indicator_ae_eq (hm _ hs_m)]
  refine' EventuallyEq.trans _ (condexp_indicator hf_int hs_m)
  refine' ae_eq_condexp_of_forall_set_integral_eq hm (hf_int.indicator (hm _ hs_m)) _ _ _
  · 

Proof state:
case refine'_1
α : Type u_1
𝕜 : Type u_2
E : Type u_3
m m0 : MeasurableSpace α
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure α
f : α → E
s : Set α
hm : m ≤ m0
inst✝ : SigmaFinite (Measure.trim μ hm)
hs_m : MeasurableSet s
hf_int : Integrable f
this : SigmaFinite (Measure.trim (Measure.restrict μ s) hm)
⊢ ∀ (s_1 : Set α), MeasurableSet s_1 → ↑↑μ s_1 < ⊤ → IntegrableOn (Set.indicator s (Measure.restrict μ s[f|m])) s_1

Next tactic:
intro t ht _
theorem condexp_restrict_ae_eq_restrict (hm : m ≤ m0) [SigmaFinite (μ.trim hm)]
    (hs_m : MeasurableSet[m] s) (hf_int : Integrable f μ) :
    (μ.restrict s)[f|m] =ᵐ[μ.restrict s] μ[f|m] := by
  have : SigmaFinite ((μ.restrict s).trim hm) := by rw [← restrict_trim hm _ hs_m]; infer_instance
  rw [ae_eq_restrict_iff_indicator_ae_eq (hm _ hs_m)]
  refine' EventuallyEq.trans _ (condexp_indicator hf_int hs_m)
  refine' ae_eq_condexp_of_forall_set_integral_eq hm (hf_int.indicator (hm _ hs_m)) _ _ _
  · intro t ht _
    

Proof state:
case refine'_1
α : Type u_1
𝕜 : Type u_2
E : Type u_3
m m0 : MeasurableSpace α
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure α
f : α → E
s : Set α
hm : m ≤ m0
inst✝ : SigmaFinite (Measure.trim μ hm)
hs_m : MeasurableSet s
hf_int : Integrable f
this : SigmaFinite (Measure.trim (Measure.restrict μ s) hm)
t : Set α
ht : MeasurableSet t
a✝ : ↑↑μ t < ⊤
⊢ IntegrableOn (Set.indicator s (Measure.restrict μ s[f|m])) t

Next tactic:
rw [← integrable_indicator_iff (hm _ ht), Set.indicator_indicator, Set.inter_comm, ←
      Set.indicator_indicator]
theorem condexp_restrict_ae_eq_restrict (hm : m ≤ m0) [SigmaFinite (μ.trim hm)]
    (hs_m : MeasurableSet[m] s) (hf_int : Integrable f μ) :
    (μ.restrict s)[f|m] =ᵐ[μ.restrict s] μ[f|m] := by
  have : SigmaFinite ((μ.restrict s).trim hm) := by rw [← restrict_trim hm _ hs_m]; infer_instance
  rw [ae_eq_restrict_iff_indicator_ae_eq (hm _ hs_m)]
  refine' EventuallyEq.trans _ (condexp_indicator hf_int hs_m)
  refine' ae_eq_condexp_of_forall_set_integral_eq hm (hf_int.indicator (hm _ hs_m)) _ _ _
  · intro t ht _
    rw [← integrable_indicator_iff (hm _ ht), Set.indicator_indicator, Set.inter_comm, ←
      Set.indicator_indicator]
    

Proof state:
case refine'_1
α : Type u_1
𝕜 : Type u_2
E : Type u_3
m m0 : MeasurableSpace α
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure α
f : α → E
s : Set α
hm : m ≤ m0
inst✝ : SigmaFinite (Measure.trim μ hm)
hs_m : MeasurableSet s
hf_int : Integrable f
this : SigmaFinite (Measure.trim (Measure.restrict μ s) hm)
t : Set α
ht : MeasurableSet t
a✝ : ↑↑μ t < ⊤
⊢ Integrable (Set.indicator s (Set.indicator t (Measure.restrict μ s[f|m])))

Next tactic:
suffices h_int_restrict : Integrable (t.indicator ((μ.restrict s)[f|m])) (μ.restrict s)
theorem condexp_restrict_ae_eq_restrict (hm : m ≤ m0) [SigmaFinite (μ.trim hm)]
    (hs_m : MeasurableSet[m] s) (hf_int : Integrable f μ) :
    (μ.restrict s)[f|m] =ᵐ[μ.restrict s] μ[f|m] := by
  have : SigmaFinite ((μ.restrict s).trim hm) := by rw [← restrict_trim hm _ hs_m]; infer_instance
  rw [ae_eq_restrict_iff_indicator_ae_eq (hm _ hs_m)]
  refine' EventuallyEq.trans _ (condexp_indicator hf_int hs_m)
  refine' ae_eq_condexp_of_forall_set_integral_eq hm (hf_int.indicator (hm _ hs_m)) _ _ _
  · intro t ht _
    rw [← integrable_indicator_iff (hm _ ht), Set.indicator_indicator, Set.inter_comm, ←
      Set.indicator_indicator]
    suffices h_int_restrict : Integrable (t.indicator ((μ.restrict s)[f|m])) (μ.restrict s)
    · 

Proof state:
case refine'_1
α : Type u_1
𝕜 : Type u_2
E : Type u_3
m m0 : MeasurableSpace α
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure α
f : α → E
s : Set α
hm : m ≤ m0
inst✝ : SigmaFinite (Measure.trim μ hm)
hs_m : MeasurableSet s
hf_int : Integrable f
this : SigmaFinite (Measure.trim (Measure.restrict μ s) hm)
t : Set α
ht : MeasurableSet t
a✝ : ↑↑μ t < ⊤
h_int_restrict : Integrable (Set.indicator t (Measure.restrict μ s[f|m]))
⊢ Integrable (Set.indicator s (Set.indicator t (Measure.restrict μ s[f|m])))

Next tactic:
rw [integrable_indicator_iff (hm _ hs_m), IntegrableOn]
theorem condexp_restrict_ae_eq_restrict (hm : m ≤ m0) [SigmaFinite (μ.trim hm)]
    (hs_m : MeasurableSet[m] s) (hf_int : Integrable f μ) :
    (μ.restrict s)[f|m] =ᵐ[μ.restrict s] μ[f|m] := by
  have : SigmaFinite ((μ.restrict s).trim hm) := by rw [← restrict_trim hm _ hs_m]; infer_instance
  rw [ae_eq_restrict_iff_indicator_ae_eq (hm _ hs_m)]
  refine' EventuallyEq.trans _ (condexp_indicator hf_int hs_m)
  refine' ae_eq_condexp_of_forall_set_integral_eq hm (hf_int.indicator (hm _ hs_m)) _ _ _
  · intro t ht _
    rw [← integrable_indicator_iff (hm _ ht), Set.indicator_indicator, Set.inter_comm, ←
      Set.indicator_indicator]
    suffices h_int_restrict : Integrable (t.indicator ((μ.restrict s)[f|m])) (μ.restrict s)
    · rw [integrable_indicator_iff (hm _ hs_m), IntegrableOn]
      

Proof state:
case refine'_1
α : Type u_1
𝕜 : Type u_2
E : Type u_3
m m0 : MeasurableSpace α
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure α
f : α → E
s : Set α
hm : m ≤ m0
inst✝ : SigmaFinite (Measure.trim μ hm)
hs_m : MeasurableSet s
hf_int : Integrable f
this : SigmaFinite (Measure.trim (Measure.restrict μ s) hm)
t : Set α
ht : MeasurableSet t
a✝ : ↑↑μ t < ⊤
h_int_restrict : Integrable (Set.indicator t (Measure.restrict μ s[f|m]))
⊢ Integrable (Set.indicator t (Measure.restrict μ s[f|m]))

Next tactic:
rw [integrable_indicator_iff (hm _ ht), IntegrableOn] at h_int_restrict ⊢
theorem condexp_restrict_ae_eq_restrict (hm : m ≤ m0) [SigmaFinite (μ.trim hm)]
    (hs_m : MeasurableSet[m] s) (hf_int : Integrable f μ) :
    (μ.restrict s)[f|m] =ᵐ[μ.restrict s] μ[f|m] := by
  have : SigmaFinite ((μ.restrict s).trim hm) := by rw [← restrict_trim hm _ hs_m]; infer_instance
  rw [ae_eq_restrict_iff_indicator_ae_eq (hm _ hs_m)]
  refine' EventuallyEq.trans _ (condexp_indicator hf_int hs_m)
  refine' ae_eq_condexp_of_forall_set_integral_eq hm (hf_int.indicator (hm _ hs_m)) _ _ _
  · intro t ht _
    rw [← integrable_indicator_iff (hm _ ht), Set.indicator_indicator, Set.inter_comm, ←
      Set.indicator_indicator]
    suffices h_int_restrict : Integrable (t.indicator ((μ.restrict s)[f|m])) (μ.restrict s)
    · rw [integrable_indicator_iff (hm _ hs_m), IntegrableOn]
      rw [integrable_indicator_iff (hm _ ht), IntegrableOn] at h_int_restrict ⊢
      

Proof state:
case refine'_1
α : Type u_1
𝕜 : Type u_2
E : Type u_3
m m0 : MeasurableSpace α
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure α
f : α → E
s : Set α
hm : m ≤ m0
inst✝ : SigmaFinite (Measure.trim μ hm)
hs_m : MeasurableSet s
hf_int : Integrable f
this : SigmaFinite (Measure.trim (Measure.restrict μ s) hm)
t : Set α
ht : MeasurableSet t
a✝ : ↑↑μ t < ⊤
h_int_restrict : Integrable (Measure.restrict μ s[f|m])
⊢ Integrable (Measure.restrict μ s[f|m])

Next tactic:
exact h_int_restrict
theorem condexp_restrict_ae_eq_restrict (hm : m ≤ m0) [SigmaFinite (μ.trim hm)]
    (hs_m : MeasurableSet[m] s) (hf_int : Integrable f μ) :
    (μ.restrict s)[f|m] =ᵐ[μ.restrict s] μ[f|m] := by
  have : SigmaFinite ((μ.restrict s).trim hm) := by rw [← restrict_trim hm _ hs_m]; infer_instance
  rw [ae_eq_restrict_iff_indicator_ae_eq (hm _ hs_m)]
  refine' EventuallyEq.trans _ (condexp_indicator hf_int hs_m)
  refine' ae_eq_condexp_of_forall_set_integral_eq hm (hf_int.indicator (hm _ hs_m)) _ _ _
  · intro t ht _
    rw [← integrable_indicator_iff (hm _ ht), Set.indicator_indicator, Set.inter_comm, ←
      Set.indicator_indicator]
    suffices h_int_restrict : Integrable (t.indicator ((μ.restrict s)[f|m])) (μ.restrict s)
    · rw [integrable_indicator_iff (hm _ hs_m), IntegrableOn]
      rw [integrable_indicator_iff (hm _ ht), IntegrableOn] at h_int_restrict ⊢
      exact h_int_restrict
    

Proof state:
case h_int_restrict
α : Type u_1
𝕜 : Type u_2
E : Type u_3
m m0 : MeasurableSpace α
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure α
f : α → E
s : Set α
hm : m ≤ m0
inst✝ : SigmaFinite (Measure.trim μ hm)
hs_m : MeasurableSet s
hf_int : Integrable f
this : SigmaFinite (Measure.trim (Measure.restrict μ s) hm)
t : Set α
ht : MeasurableSet t
a✝ : ↑↑μ t < ⊤
⊢ Integrable (Set.indicator t (Measure.restrict μ s[f|m]))

Next tactic:
exact integrable_condexp.indicator (hm _ ht)
theorem condexp_restrict_ae_eq_restrict (hm : m ≤ m0) [SigmaFinite (μ.trim hm)]
    (hs_m : MeasurableSet[m] s) (hf_int : Integrable f μ) :
    (μ.restrict s)[f|m] =ᵐ[μ.restrict s] μ[f|m] := by
  have : SigmaFinite ((μ.restrict s).trim hm) := by rw [← restrict_trim hm _ hs_m]; infer_instance
  rw [ae_eq_restrict_iff_indicator_ae_eq (hm _ hs_m)]
  refine' EventuallyEq.trans _ (condexp_indicator hf_int hs_m)
  refine' ae_eq_condexp_of_forall_set_integral_eq hm (hf_int.indicator (hm _ hs_m)) _ _ _
  · intro t ht _
    rw [← integrable_indicator_iff (hm _ ht), Set.indicator_indicator, Set.inter_comm, ←
      Set.indicator_indicator]
    suffices h_int_restrict : Integrable (t.indicator ((μ.restrict s)[f|m])) (μ.restrict s)
    · rw [integrable_indicator_iff (hm _ hs_m), IntegrableOn]
      rw [integrable_indicator_iff (hm _ ht), IntegrableOn] at h_int_restrict ⊢
      exact h_int_restrict
    exact integrable_condexp.indicator (hm _ ht)
  · 

Proof state:
case refine'_2
α : Type u_1
𝕜 : Type u_2
E : Type u_3
m m0 : MeasurableSpace α
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure α
f : α → E
s : Set α
hm : m ≤ m0
inst✝ : SigmaFinite (Measure.trim μ hm)
hs_m : MeasurableSet s
hf_int : Integrable f
this : SigmaFinite (Measure.trim (Measure.restrict μ s) hm)
⊢ ∀ (s_1 : Set α),
    MeasurableSet s_1 →
      ↑↑μ s_1 < ⊤ →
        ∫ (x : α) in s_1, Set.indicator s (Measure.restrict μ s[f|m]) x ∂μ = ∫ (x : α) in s_1, Set.indicator s f x ∂μ

Next tactic:
intro t ht _
theorem condexp_restrict_ae_eq_restrict (hm : m ≤ m0) [SigmaFinite (μ.trim hm)]
    (hs_m : MeasurableSet[m] s) (hf_int : Integrable f μ) :
    (μ.restrict s)[f|m] =ᵐ[μ.restrict s] μ[f|m] := by
  have : SigmaFinite ((μ.restrict s).trim hm) := by rw [← restrict_trim hm _ hs_m]; infer_instance
  rw [ae_eq_restrict_iff_indicator_ae_eq (hm _ hs_m)]
  refine' EventuallyEq.trans _ (condexp_indicator hf_int hs_m)
  refine' ae_eq_condexp_of_forall_set_integral_eq hm (hf_int.indicator (hm _ hs_m)) _ _ _
  · intro t ht _
    rw [← integrable_indicator_iff (hm _ ht), Set.indicator_indicator, Set.inter_comm, ←
      Set.indicator_indicator]
    suffices h_int_restrict : Integrable (t.indicator ((μ.restrict s)[f|m])) (μ.restrict s)
    · rw [integrable_indicator_iff (hm _ hs_m), IntegrableOn]
      rw [integrable_indicator_iff (hm _ ht), IntegrableOn] at h_int_restrict ⊢
      exact h_int_restrict
    exact integrable_condexp.indicator (hm _ ht)
  · intro t ht _
    

Proof state:
case refine'_2
α : Type u_1
𝕜 : Type u_2
E : Type u_3
m m0 : MeasurableSpace α
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure α
f : α → E
s : Set α
hm : m ≤ m0
inst✝ : SigmaFinite (Measure.trim μ hm)
hs_m : MeasurableSet s
hf_int : Integrable f
this : SigmaFinite (Measure.trim (Measure.restrict μ s) hm)
t : Set α
ht : MeasurableSet t
a✝ : ↑↑μ t < ⊤
⊢ ∫ (x : α) in t, Set.indicator s (Measure.restrict μ s[f|m]) x ∂μ = ∫ (x : α) in t, Set.indicator s f x ∂μ

Next tactic:
calc
      ∫ x in t, s.indicator ((μ.restrict s)[f|m]) x ∂μ =
          ∫ x in t, ((μ.restrict s)[f|m]) x ∂μ.restrict s := by
        rw [integral_indicator (hm _ hs_m), Measure.restrict_restrict (hm _ hs_m),
          Measure.restrict_restrict (hm _ ht), Set.inter_comm]
      _ = ∫ x in t, f x ∂μ.restrict s := (set_integral_condexp hm hf_int.integrableOn ht)
      _ = ∫ x in t, s.indicator f x ∂μ := by
        rw [integral_indicator (hm _ hs_m), Measure.restrict_restrict (hm _ hs_m),
          Measure.restrict_restrict (hm _ ht), Set.inter_comm]
theorem condexp_restrict_ae_eq_restrict (hm : m ≤ m0) [SigmaFinite (μ.trim hm)]
    (hs_m : MeasurableSet[m] s) (hf_int : Integrable f μ) :
    (μ.restrict s)[f|m] =ᵐ[μ.restrict s] μ[f|m] := by
  have : SigmaFinite ((μ.restrict s).trim hm) := by rw [← restrict_trim hm _ hs_m]; infer_instance
  rw [ae_eq_restrict_iff_indicator_ae_eq (hm _ hs_m)]
  refine' EventuallyEq.trans _ (condexp_indicator hf_int hs_m)
  refine' ae_eq_condexp_of_forall_set_integral_eq hm (hf_int.indicator (hm _ hs_m)) _ _ _
  · intro t ht _
    rw [← integrable_indicator_iff (hm _ ht), Set.indicator_indicator, Set.inter_comm, ←
      Set.indicator_indicator]
    suffices h_int_restrict : Integrable (t.indicator ((μ.restrict s)[f|m])) (μ.restrict s)
    · rw [integrable_indicator_iff (hm _ hs_m), IntegrableOn]
      rw [integrable_indicator_iff (hm _ ht), IntegrableOn] at h_int_restrict ⊢
      exact h_int_restrict
    exact integrable_condexp.indicator (hm _ ht)
  · intro t ht _
    calc
      ∫ x in t, s.indicator ((μ.restrict s)[f|m]) x ∂μ =
          ∫ x in t, ((μ.restrict s)[f|m]) x ∂μ.restrict s := by
        

Proof state:
α : Type u_1
𝕜 : Type u_2
E : Type u_3
m m0 : MeasurableSpace α
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure α
f : α → E
s : Set α
hm : m ≤ m0
inst✝ : SigmaFinite (Measure.trim μ hm)
hs_m : MeasurableSet s
hf_int : Integrable f
this : SigmaFinite (Measure.trim (Measure.restrict μ s) hm)
t : Set α
ht : MeasurableSet t
a✝ : ↑↑μ t < ⊤
⊢ ∫ (x : α) in t, Set.indicator s (Measure.restrict μ s[f|m]) x ∂μ =
    ∫ (x : α) in t, (Measure.restrict μ s[f|m]) x ∂Measure.restrict μ s

Next tactic:
rw [integral_indicator (hm _ hs_m), Measure.restrict_restrict (hm _ hs_m),
          Measure.restrict_restrict (hm _ ht), Set.inter_comm]