l3lab/ntp-mathlib huggingface dataset:
/-- **Vitali-Carathéodory Theorem**: given an integrable real function `f`, there exists an
integrable function `g > f` which is lower semicontinuous, with integral arbitrarily close
to that of `f`. This function has to be `EReal`-valued in general. -/
theorem exists_lt_lowerSemicontinuous_integral_lt [SigmaFinite μ] (f : α → ℝ) (hf : Integrable f μ)
    {ε : ℝ} (εpos : 0 < ε) :
    ∃ g : α → EReal,
      (∀ x, (f x : EReal) < g x) ∧
      LowerSemicontinuous g ∧
      Integrable (fun x => EReal.toReal (g x)) μ ∧
      (∀ᵐ x ∂μ, g x < ⊤) ∧ (∫ x, EReal.toReal (g x) ∂μ) < (∫ x, f x ∂μ) + ε := by
  let δ : ℝ≥0 := ⟨ε / 2, (half_pos εpos).le⟩
  have δpos : 0 < δ := half_pos εpos
  let fp : α → ℝ≥0 := fun x => Real.toNNReal (f x)
  have int_fp : Integrable (fun x => (fp x : ℝ)) μ := hf.real_toNNReal
  rcases exists_lt_lowerSemicontinuous_integral_gt_nnreal fp int_fp δpos with
    ⟨gp, fp_lt_gp, gpcont, gp_lt_top, gp_integrable, gpint⟩
  let fm : α → ℝ≥0 := fun x => Real.toNNReal (-f x)
  have int_fm : Integrable (fun x => (fm x : ℝ)) μ := hf.neg.real_toNNReal
  rcases exists_upperSemicontinuous_le_integral_le fm int_fm δpos with
    ⟨gm, gm_le_fm, gmcont, gm_integrable, gmint⟩
  let g : α → EReal := fun x => (gp x : EReal) - gm x
  have ae_g : ∀ᵐ x ∂μ, (g x).toReal = (gp x : EReal).toReal - (gm x : EReal).toReal := by
    filter_upwards [gp_lt_top] with _ hx
    

Proof state:
case h
α : Type u_1
inst✝⁴ : TopologicalSpace α
inst✝³ : MeasurableSpace α
inst✝² : BorelSpace α
μ : Measure α
inst✝¹ : WeaklyRegular μ
inst✝ : SigmaFinite μ
f : α → ℝ
hf : Integrable f
ε : ℝ
εpos : 0 < ε
δ : ℝ≥0 := { val := ε / 2, property := (_ : 0 ≤ ε / 2) }
δpos : 0 < δ
fp : α → ℝ≥0 := fun x => Real.toNNReal (f x)
int_fp : Integrable fun x => ↑(fp x)
gp : α → ℝ≥0∞
fp_lt_gp : ∀ (x : α), ↑(fp x) < gp x
gpcont : LowerSemicontinuous gp
gp_lt_top : ∀ᵐ (x : α) ∂μ, gp x < ⊤
gp_integrable : Integrable fun x => ENNReal.toReal (gp x)
gpint : ∫ (x : α), ENNReal.toReal (gp x) ∂μ < ∫ (x : α), ↑(fp x) ∂μ + (fun a => ↑a) δ
fm : α → ℝ≥0 := fun x => Real.toNNReal (-f x)
int_fm : Integrable fun x => ↑(fm x)
gm : α → ℝ≥0
gm_le_fm : ∀ (x : α), gm x ≤ fm x
gmcont : UpperSemicontinuous gm
gm_integrable : Integrable fun x => ↑(gm x)
gmint : ∫ (x : α), ↑(fm x) ∂μ - (fun a => ↑a) δ ≤ ∫ (x : α), ↑(gm x) ∂μ
g : α → EReal := fun x => ↑(gp x) - ↑↑(gm x)
a✝ : α
hx : gp a✝ < ⊤
⊢ EReal.toReal (g a✝) = EReal.toReal ↑(gp a✝) - EReal.toReal ↑↑(gm a✝)

Next tactic:
rw [EReal.toReal_sub]
/-- **Vitali-Carathéodory Theorem**: given an integrable real function `f`, there exists an
integrable function `g > f` which is lower semicontinuous, with integral arbitrarily close
to that of `f`. This function has to be `EReal`-valued in general. -/
theorem exists_lt_lowerSemicontinuous_integral_lt [SigmaFinite μ] (f : α → ℝ) (hf : Integrable f μ)
    {ε : ℝ} (εpos : 0 < ε) :
    ∃ g : α → EReal,
      (∀ x, (f x : EReal) < g x) ∧
      LowerSemicontinuous g ∧
      Integrable (fun x => EReal.toReal (g x)) μ ∧
      (∀ᵐ x ∂μ, g x < ⊤) ∧ (∫ x, EReal.toReal (g x) ∂μ) < (∫ x, f x ∂μ) + ε := by
  let δ : ℝ≥0 := ⟨ε / 2, (half_pos εpos).le⟩
  have δpos : 0 < δ := half_pos εpos
  let fp : α → ℝ≥0 := fun x => Real.toNNReal (f x)
  have int_fp : Integrable (fun x => (fp x : ℝ)) μ := hf.real_toNNReal
  rcases exists_lt_lowerSemicontinuous_integral_gt_nnreal fp int_fp δpos with
    ⟨gp, fp_lt_gp, gpcont, gp_lt_top, gp_integrable, gpint⟩
  let fm : α → ℝ≥0 := fun x => Real.toNNReal (-f x)
  have int_fm : Integrable (fun x => (fm x : ℝ)) μ := hf.neg.real_toNNReal
  rcases exists_upperSemicontinuous_le_integral_le fm int_fm δpos with
    ⟨gm, gm_le_fm, gmcont, gm_integrable, gmint⟩
  let g : α → EReal := fun x => (gp x : EReal) - gm x
  have ae_g : ∀ᵐ x ∂μ, (g x).toReal = (gp x : EReal).toReal - (gm x : EReal).toReal := by
    filter_upwards [gp_lt_top] with _ hx
    rw [EReal.toReal_sub] <;> 

Proof state:
case h.hx
α : Type u_1
inst✝⁴ : TopologicalSpace α
inst✝³ : MeasurableSpace α
inst✝² : BorelSpace α
μ : Measure α
inst✝¹ : WeaklyRegular μ
inst✝ : SigmaFinite μ
f : α → ℝ
hf : Integrable f
ε : ℝ
εpos : 0 < ε
δ : ℝ≥0 := { val := ε / 2, property := (_ : 0 ≤ ε / 2) }
δpos : 0 < δ
fp : α → ℝ≥0 := fun x => Real.toNNReal (f x)
int_fp : Integrable fun x => ↑(fp x)
gp : α → ℝ≥0∞
fp_lt_gp : ∀ (x : α), ↑(fp x) < gp x
gpcont : LowerSemicontinuous gp
gp_lt_top : ∀ᵐ (x : α) ∂μ, gp x < ⊤
gp_integrable : Integrable fun x => ENNReal.toReal (gp x)
gpint : ∫ (x : α), ENNReal.toReal (gp x) ∂μ < ∫ (x : α), ↑(fp x) ∂μ + (fun a => ↑a) δ
fm : α → ℝ≥0 := fun x => Real.toNNReal (-f x)
int_fm : Integrable fun x => ↑(fm x)
gm : α → ℝ≥0
gm_le_fm : ∀ (x : α), gm x ≤ fm x
gmcont : UpperSemicontinuous gm
gm_integrable : Integrable fun x => ↑(gm x)
gmint : ∫ (x : α), ↑(fm x) ∂μ - (fun a => ↑a) δ ≤ ∫ (x : α), ↑(gm x) ∂μ
g : α → EReal := fun x => ↑(gp x) - ↑↑(gm x)
a✝ : α
hx : gp a✝ < ⊤
⊢ ↑(gp a✝) ≠ ⊤

Next tactic:
simp [hx.ne]
/-- **Vitali-Carathéodory Theorem**: given an integrable real function `f`, there exists an
integrable function `g > f` which is lower semicontinuous, with integral arbitrarily close
to that of `f`. This function has to be `EReal`-valued in general. -/
theorem exists_lt_lowerSemicontinuous_integral_lt [SigmaFinite μ] (f : α → ℝ) (hf : Integrable f μ)
    {ε : ℝ} (εpos : 0 < ε) :
    ∃ g : α → EReal,
      (∀ x, (f x : EReal) < g x) ∧
      LowerSemicontinuous g ∧
      Integrable (fun x => EReal.toReal (g x)) μ ∧
      (∀ᵐ x ∂μ, g x < ⊤) ∧ (∫ x, EReal.toReal (g x) ∂μ) < (∫ x, f x ∂μ) + ε := by
  let δ : ℝ≥0 := ⟨ε / 2, (half_pos εpos).le⟩
  have δpos : 0 < δ := half_pos εpos
  let fp : α → ℝ≥0 := fun x => Real.toNNReal (f x)
  have int_fp : Integrable (fun x => (fp x : ℝ)) μ := hf.real_toNNReal
  rcases exists_lt_lowerSemicontinuous_integral_gt_nnreal fp int_fp δpos with
    ⟨gp, fp_lt_gp, gpcont, gp_lt_top, gp_integrable, gpint⟩
  let fm : α → ℝ≥0 := fun x => Real.toNNReal (-f x)
  have int_fm : Integrable (fun x => (fm x : ℝ)) μ := hf.neg.real_toNNReal
  rcases exists_upperSemicontinuous_le_integral_le fm int_fm δpos with
    ⟨gm, gm_le_fm, gmcont, gm_integrable, gmint⟩
  let g : α → EReal := fun x => (gp x : EReal) - gm x
  have ae_g : ∀ᵐ x ∂μ, (g x).toReal = (gp x : EReal).toReal - (gm x : EReal).toReal := by
    filter_upwards [gp_lt_top] with _ hx
    rw [EReal.toReal_sub] <;> 

Proof state:
case h.h'x
α : Type u_1
inst✝⁴ : TopologicalSpace α
inst✝³ : MeasurableSpace α
inst✝² : BorelSpace α
μ : Measure α
inst✝¹ : WeaklyRegular μ
inst✝ : SigmaFinite μ
f : α → ℝ
hf : Integrable f
ε : ℝ
εpos : 0 < ε
δ : ℝ≥0 := { val := ε / 2, property := (_ : 0 ≤ ε / 2) }
δpos : 0 < δ
fp : α → ℝ≥0 := fun x => Real.toNNReal (f x)
int_fp : Integrable fun x => ↑(fp x)
gp : α → ℝ≥0∞
fp_lt_gp : ∀ (x : α), ↑(fp x) < gp x
gpcont : LowerSemicontinuous gp
gp_lt_top : ∀ᵐ (x : α) ∂μ, gp x < ⊤
gp_integrable : Integrable fun x => ENNReal.toReal (gp x)
gpint : ∫ (x : α), ENNReal.toReal (gp x) ∂μ < ∫ (x : α), ↑(fp x) ∂μ + (fun a => ↑a) δ
fm : α → ℝ≥0 := fun x => Real.toNNReal (-f x)
int_fm : Integrable fun x => ↑(fm x)
gm : α → ℝ≥0
gm_le_fm : ∀ (x : α), gm x ≤ fm x
gmcont : UpperSemicontinuous gm
gm_integrable : Integrable fun x => ↑(gm x)
gmint : ∫ (x : α), ↑(fm x) ∂μ - (fun a => ↑a) δ ≤ ∫ (x : α), ↑(gm x) ∂μ
g : α → EReal := fun x => ↑(gp x) - ↑↑(gm x)
a✝ : α
hx : gp a✝ < ⊤
⊢ ↑(gp a✝) ≠ ⊥

Next tactic:
simp [hx.ne]
/-- **Vitali-Carathéodory Theorem**: given an integrable real function `f`, there exists an
integrable function `g > f` which is lower semicontinuous, with integral arbitrarily close
to that of `f`. This function has to be `EReal`-valued in general. -/
theorem exists_lt_lowerSemicontinuous_integral_lt [SigmaFinite μ] (f : α → ℝ) (hf : Integrable f μ)
    {ε : ℝ} (εpos : 0 < ε) :
    ∃ g : α → EReal,
      (∀ x, (f x : EReal) < g x) ∧
      LowerSemicontinuous g ∧
      Integrable (fun x => EReal.toReal (g x)) μ ∧
      (∀ᵐ x ∂μ, g x < ⊤) ∧ (∫ x, EReal.toReal (g x) ∂μ) < (∫ x, f x ∂μ) + ε := by
  let δ : ℝ≥0 := ⟨ε / 2, (half_pos εpos).le⟩
  have δpos : 0 < δ := half_pos εpos
  let fp : α → ℝ≥0 := fun x => Real.toNNReal (f x)
  have int_fp : Integrable (fun x => (fp x : ℝ)) μ := hf.real_toNNReal
  rcases exists_lt_lowerSemicontinuous_integral_gt_nnreal fp int_fp δpos with
    ⟨gp, fp_lt_gp, gpcont, gp_lt_top, gp_integrable, gpint⟩
  let fm : α → ℝ≥0 := fun x => Real.toNNReal (-f x)
  have int_fm : Integrable (fun x => (fm x : ℝ)) μ := hf.neg.real_toNNReal
  rcases exists_upperSemicontinuous_le_integral_le fm int_fm δpos with
    ⟨gm, gm_le_fm, gmcont, gm_integrable, gmint⟩
  let g : α → EReal := fun x => (gp x : EReal) - gm x
  have ae_g : ∀ᵐ x ∂μ, (g x).toReal = (gp x : EReal).toReal - (gm x : EReal).toReal := by
    filter_upwards [gp_lt_top] with _ hx
    rw [EReal.toReal_sub] <;> 

Proof state:
case h.hy
α : Type u_1
inst✝⁴ : TopologicalSpace α
inst✝³ : MeasurableSpace α
inst✝² : BorelSpace α
μ : Measure α
inst✝¹ : WeaklyRegular μ
inst✝ : SigmaFinite μ
f : α → ℝ
hf : Integrable f
ε : ℝ
εpos : 0 < ε
δ : ℝ≥0 := { val := ε / 2, property := (_ : 0 ≤ ε / 2) }
δpos : 0 < δ
fp : α → ℝ≥0 := fun x => Real.toNNReal (f x)
int_fp : Integrable fun x => ↑(fp x)
gp : α → ℝ≥0∞
fp_lt_gp : ∀ (x : α), ↑(fp x) < gp x
gpcont : LowerSemicontinuous gp
gp_lt_top : ∀ᵐ (x : α) ∂μ, gp x < ⊤
gp_integrable : Integrable fun x => ENNReal.toReal (gp x)
gpint : ∫ (x : α), ENNReal.toReal (gp x) ∂μ < ∫ (x : α), ↑(fp x) ∂μ + (fun a => ↑a) δ
fm : α → ℝ≥0 := fun x => Real.toNNReal (-f x)
int_fm : Integrable fun x => ↑(fm x)
gm : α → ℝ≥0
gm_le_fm : ∀ (x : α), gm x ≤ fm x
gmcont : UpperSemicontinuous gm
gm_integrable : Integrable fun x => ↑(gm x)
gmint : ∫ (x : α), ↑(fm x) ∂μ - (fun a => ↑a) δ ≤ ∫ (x : α), ↑(gm x) ∂μ
g : α → EReal := fun x => ↑(gp x) - ↑↑(gm x)
a✝ : α
hx : gp a✝ < ⊤
⊢ ↑↑(gm a✝) ≠ ⊤

Next tactic:
simp [hx.ne]
/-- **Vitali-Carathéodory Theorem**: given an integrable real function `f`, there exists an
integrable function `g > f` which is lower semicontinuous, with integral arbitrarily close
to that of `f`. This function has to be `EReal`-valued in general. -/
theorem exists_lt_lowerSemicontinuous_integral_lt [SigmaFinite μ] (f : α → ℝ) (hf : Integrable f μ)
    {ε : ℝ} (εpos : 0 < ε) :
    ∃ g : α → EReal,
      (∀ x, (f x : EReal) < g x) ∧
      LowerSemicontinuous g ∧
      Integrable (fun x => EReal.toReal (g x)) μ ∧
      (∀ᵐ x ∂μ, g x < ⊤) ∧ (∫ x, EReal.toReal (g x) ∂μ) < (∫ x, f x ∂μ) + ε := by
  let δ : ℝ≥0 := ⟨ε / 2, (half_pos εpos).le⟩
  have δpos : 0 < δ := half_pos εpos
  let fp : α → ℝ≥0 := fun x => Real.toNNReal (f x)
  have int_fp : Integrable (fun x => (fp x : ℝ)) μ := hf.real_toNNReal
  rcases exists_lt_lowerSemicontinuous_integral_gt_nnreal fp int_fp δpos with
    ⟨gp, fp_lt_gp, gpcont, gp_lt_top, gp_integrable, gpint⟩
  let fm : α → ℝ≥0 := fun x => Real.toNNReal (-f x)
  have int_fm : Integrable (fun x => (fm x : ℝ)) μ := hf.neg.real_toNNReal
  rcases exists_upperSemicontinuous_le_integral_le fm int_fm δpos with
    ⟨gm, gm_le_fm, gmcont, gm_integrable, gmint⟩
  let g : α → EReal := fun x => (gp x : EReal) - gm x
  have ae_g : ∀ᵐ x ∂μ, (g x).toReal = (gp x : EReal).toReal - (gm x : EReal).toReal := by
    filter_upwards [gp_lt_top] with _ hx
    rw [EReal.toReal_sub] <;> 

Proof state:
case h.h'y
α : Type u_1
inst✝⁴ : TopologicalSpace α
inst✝³ : MeasurableSpace α
inst✝² : BorelSpace α
μ : Measure α
inst✝¹ : WeaklyRegular μ
inst✝ : SigmaFinite μ
f : α → ℝ
hf : Integrable f
ε : ℝ
εpos : 0 < ε
δ : ℝ≥0 := { val := ε / 2, property := (_ : 0 ≤ ε / 2) }
δpos : 0 < δ
fp : α → ℝ≥0 := fun x => Real.toNNReal (f x)
int_fp : Integrable fun x => ↑(fp x)
gp : α → ℝ≥0∞
fp_lt_gp : ∀ (x : α), ↑(fp x) < gp x
gpcont : LowerSemicontinuous gp
gp_lt_top : ∀ᵐ (x : α) ∂μ, gp x < ⊤
gp_integrable : Integrable fun x => ENNReal.toReal (gp x)
gpint : ∫ (x : α), ENNReal.toReal (gp x) ∂μ < ∫ (x : α), ↑(fp x) ∂μ + (fun a => ↑a) δ
fm : α → ℝ≥0 := fun x => Real.toNNReal (-f x)
int_fm : Integrable fun x => ↑(fm x)
gm : α → ℝ≥0
gm_le_fm : ∀ (x : α), gm x ≤ fm x
gmcont : UpperSemicontinuous gm
gm_integrable : Integrable fun x => ↑(gm x)
gmint : ∫ (x : α), ↑(fm x) ∂μ - (fun a => ↑a) δ ≤ ∫ (x : α), ↑(gm x) ∂μ
g : α → EReal := fun x => ↑(gp x) - ↑↑(gm x)
a✝ : α
hx : gp a✝ < ⊤
⊢ ↑↑(gm a✝) ≠ ⊥

Next tactic:
simp [hx.ne]
/-- **Vitali-Carathéodory Theorem**: given an integrable real function `f`, there exists an
integrable function `g > f` which is lower semicontinuous, with integral arbitrarily close
to that of `f`. This function has to be `EReal`-valued in general. -/
theorem exists_lt_lowerSemicontinuous_integral_lt [SigmaFinite μ] (f : α → ℝ) (hf : Integrable f μ)
    {ε : ℝ} (εpos : 0 < ε) :
    ∃ g : α → EReal,
      (∀ x, (f x : EReal) < g x) ∧
      LowerSemicontinuous g ∧
      Integrable (fun x => EReal.toReal (g x)) μ ∧
      (∀ᵐ x ∂μ, g x < ⊤) ∧ (∫ x, EReal.toReal (g x) ∂μ) < (∫ x, f x ∂μ) + ε := by
  let δ : ℝ≥0 := ⟨ε / 2, (half_pos εpos).le⟩
  have δpos : 0 < δ := half_pos εpos
  let fp : α → ℝ≥0 := fun x => Real.toNNReal (f x)
  have int_fp : Integrable (fun x => (fp x : ℝ)) μ := hf.real_toNNReal
  rcases exists_lt_lowerSemicontinuous_integral_gt_nnreal fp int_fp δpos with
    ⟨gp, fp_lt_gp, gpcont, gp_lt_top, gp_integrable, gpint⟩
  let fm : α → ℝ≥0 := fun x => Real.toNNReal (-f x)
  have int_fm : Integrable (fun x => (fm x : ℝ)) μ := hf.neg.real_toNNReal
  rcases exists_upperSemicontinuous_le_integral_le fm int_fm δpos with
    ⟨gm, gm_le_fm, gmcont, gm_integrable, gmint⟩
  let g : α → EReal := fun x => (gp x : EReal) - gm x
  have ae_g : ∀ᵐ x ∂μ, (g x).toReal = (gp x : EReal).toReal - (gm x : EReal).toReal := by
    filter_upwards [gp_lt_top] with _ hx
    rw [EReal.toReal_sub] <;> simp [hx.ne]
  

Proof state:
case intro.intro.intro.intro.intro.intro.intro.intro.intro
α : Type u_1
inst✝⁴ : TopologicalSpace α
inst✝³ : MeasurableSpace α
inst✝² : BorelSpace α
μ : Measure α
inst✝¹ : WeaklyRegular μ
inst✝ : SigmaFinite μ
f : α → ℝ
hf : Integrable f
ε : ℝ
εpos : 0 < ε
δ : ℝ≥0 := { val := ε / 2, property := (_ : 0 ≤ ε / 2) }
δpos : 0 < δ
fp : α → ℝ≥0 := fun x => Real.toNNReal (f x)
int_fp : Integrable fun x => ↑(fp x)
gp : α → ℝ≥0∞
fp_lt_gp : ∀ (x : α), ↑(fp x) < gp x
gpcont : LowerSemicontinuous gp
gp_lt_top : ∀ᵐ (x : α) ∂μ, gp x < ⊤
gp_integrable : Integrable fun x => ENNReal.toReal (gp x)
gpint : ∫ (x : α), ENNReal.toReal (gp x) ∂μ < ∫ (x : α), ↑(fp x) ∂μ + (fun a => ↑a) δ
fm : α → ℝ≥0 := fun x => Real.toNNReal (-f x)
int_fm : Integrable fun x => ↑(fm x)
gm : α → ℝ≥0
gm_le_fm : ∀ (x : α), gm x ≤ fm x
gmcont : UpperSemicontinuous gm
gm_integrable : Integrable fun x => ↑(gm x)
gmint : ∫ (x : α), ↑(fm x) ∂μ - (fun a => ↑a) δ ≤ ∫ (x : α), ↑(gm x) ∂μ
g : α → EReal := fun x => ↑(gp x) - ↑↑(gm x)
ae_g : ∀ᵐ (x : α) ∂μ, EReal.toReal (g x) = EReal.toReal ↑(gp x) - EReal.toReal ↑↑(gm x)
⊢ ∃ g,
    (∀ (x : α), ↑(f x) < g x) ∧
      LowerSemicontinuous g ∧
        (Integrable fun x => EReal.toReal (g x)) ∧
          (∀ᵐ (x : α) ∂μ, g x < ⊤) ∧ ∫ (x : α), EReal.toReal (g x) ∂μ < ∫ (x : α), f x ∂μ + ε

Next tactic:
refine' ⟨g, ?lt, ?lsc, ?int, ?aelt, ?intlt⟩
/-- **Vitali-Carathéodory Theorem**: given an integrable real function `f`, there exists an
integrable function `g > f` which is lower semicontinuous, with integral arbitrarily close
to that of `f`. This function has to be `EReal`-valued in general. -/
theorem exists_lt_lowerSemicontinuous_integral_lt [SigmaFinite μ] (f : α → ℝ) (hf : Integrable f μ)
    {ε : ℝ} (εpos : 0 < ε) :
    ∃ g : α → EReal,
      (∀ x, (f x : EReal) < g x) ∧
      LowerSemicontinuous g ∧
      Integrable (fun x => EReal.toReal (g x)) μ ∧
      (∀ᵐ x ∂μ, g x < ⊤) ∧ (∫ x, EReal.toReal (g x) ∂μ) < (∫ x, f x ∂μ) + ε := by
  let δ : ℝ≥0 := ⟨ε / 2, (half_pos εpos).le⟩
  have δpos : 0 < δ := half_pos εpos
  let fp : α → ℝ≥0 := fun x => Real.toNNReal (f x)
  have int_fp : Integrable (fun x => (fp x : ℝ)) μ := hf.real_toNNReal
  rcases exists_lt_lowerSemicontinuous_integral_gt_nnreal fp int_fp δpos with
    ⟨gp, fp_lt_gp, gpcont, gp_lt_top, gp_integrable, gpint⟩
  let fm : α → ℝ≥0 := fun x => Real.toNNReal (-f x)
  have int_fm : Integrable (fun x => (fm x : ℝ)) μ := hf.neg.real_toNNReal
  rcases exists_upperSemicontinuous_le_integral_le fm int_fm δpos with
    ⟨gm, gm_le_fm, gmcont, gm_integrable, gmint⟩
  let g : α → EReal := fun x => (gp x : EReal) - gm x
  have ae_g : ∀ᵐ x ∂μ, (g x).toReal = (gp x : EReal).toReal - (gm x : EReal).toReal := by
    filter_upwards [gp_lt_top] with _ hx
    rw [EReal.toReal_sub] <;> simp [hx.ne]
  refine' ⟨g, ?lt, ?lsc, ?int, ?aelt, ?intlt⟩
  

Proof state:
α : Type u_1
inst✝⁴ : TopologicalSpace α
inst✝³ : MeasurableSpace α
inst✝² : BorelSpace α
μ : Measure α
inst✝¹ : WeaklyRegular μ
inst✝ : SigmaFinite μ
f : α → ℝ
hf : Integrable f
ε : ℝ
εpos : 0 < ε
δ : ℝ≥0 := { val := ε / 2, property := (_ : 0 ≤ ε / 2) }
δpos : 0 < δ
fp : α → ℝ≥0 := fun x => Real.toNNReal (f x)
int_fp : Integrable fun x => ↑(fp x)
gp : α → ℝ≥0∞
fp_lt_gp : ∀ (x : α), ↑(fp x) < gp x
gpcont : LowerSemicontinuous gp
gp_lt_top : ∀ᵐ (x : α) ∂μ, gp x < ⊤
gp_integrable : Integrable fun x => ENNReal.toReal (gp x)
gpint : ∫ (x : α), ENNReal.toReal (gp x) ∂μ < ∫ (x : α), ↑(fp x) ∂μ + (fun a => ↑a) δ
fm : α → ℝ≥0 := fun x => Real.toNNReal (-f x)
int_fm : Integrable fun x => ↑(fm x)
gm : α → ℝ≥0
gm_le_fm : ∀ (x : α), gm x ≤ fm x
gmcont : UpperSemicontinuous gm
gm_integrable : Integrable fun x => ↑(gm x)
gmint : ∫ (x : α), ↑(fm x) ∂μ - (fun a => ↑a) δ ≤ ∫ (x : α), ↑(gm x) ∂μ
g : α → EReal := fun x => ↑(gp x) - ↑↑(gm x)
ae_g : ∀ᵐ (x : α) ∂μ, EReal.toReal (g x) = EReal.toReal ↑(gp x) - EReal.toReal ↑↑(gm x)
⊢ Integrable fun x => EReal.toReal (g x)

Next tactic:
case int =>
    show Integrable (fun x => EReal.toReal (g x)) μ
    rw [integrable_congr ae_g]
    convert gp_integrable.sub gm_integrable
    simp
/-- **Vitali-Carathéodory Theorem**: given an integrable real function `f`, there exists an
integrable function `g > f` which is lower semicontinuous, with integral arbitrarily close
to that of `f`. This function has to be `EReal`-valued in general. -/
theorem exists_lt_lowerSemicontinuous_integral_lt [SigmaFinite μ] (f : α → ℝ) (hf : Integrable f μ)
    {ε : ℝ} (εpos : 0 < ε) :
    ∃ g : α → EReal,
      (∀ x, (f x : EReal) < g x) ∧
      LowerSemicontinuous g ∧
      Integrable (fun x => EReal.toReal (g x)) μ ∧
      (∀ᵐ x ∂μ, g x < ⊤) ∧ (∫ x, EReal.toReal (g x) ∂μ) < (∫ x, f x ∂μ) + ε := by
  let δ : ℝ≥0 := ⟨ε / 2, (half_pos εpos).le⟩
  have δpos : 0 < δ := half_pos εpos
  let fp : α → ℝ≥0 := fun x => Real.toNNReal (f x)
  have int_fp : Integrable (fun x => (fp x : ℝ)) μ := hf.real_toNNReal
  rcases exists_lt_lowerSemicontinuous_integral_gt_nnreal fp int_fp δpos with
    ⟨gp, fp_lt_gp, gpcont, gp_lt_top, gp_integrable, gpint⟩
  let fm : α → ℝ≥0 := fun x => Real.toNNReal (-f x)
  have int_fm : Integrable (fun x => (fm x : ℝ)) μ := hf.neg.real_toNNReal
  rcases exists_upperSemicontinuous_le_integral_le fm int_fm δpos with
    ⟨gm, gm_le_fm, gmcont, gm_integrable, gmint⟩
  let g : α → EReal := fun x => (gp x : EReal) - gm x
  have ae_g : ∀ᵐ x ∂μ, (g x).toReal = (gp x : EReal).toReal - (gm x : EReal).toReal := by
    filter_upwards [gp_lt_top] with _ hx
    rw [EReal.toReal_sub] <;> simp [hx.ne]
  refine' ⟨g, ?lt, ?lsc, ?int, ?aelt, ?intlt⟩
  case int =>
    

Proof state:
α : Type u_1
inst✝⁴ : TopologicalSpace α
inst✝³ : MeasurableSpace α
inst✝² : BorelSpace α
μ : Measure α
inst✝¹ : WeaklyRegular μ
inst✝ : SigmaFinite μ
f : α → ℝ
hf : Integrable f
ε : ℝ
εpos : 0 < ε
δ : ℝ≥0 := { val := ε / 2, property := (_ : 0 ≤ ε / 2) }
δpos : 0 < δ
fp : α → ℝ≥0 := fun x => Real.toNNReal (f x)
int_fp : Integrable fun x => ↑(fp x)
gp : α → ℝ≥0∞
fp_lt_gp : ∀ (x : α), ↑(fp x) < gp x
gpcont : LowerSemicontinuous gp
gp_lt_top : ∀ᵐ (x : α) ∂μ, gp x < ⊤
gp_integrable : Integrable fun x => ENNReal.toReal (gp x)
gpint : ∫ (x : α), ENNReal.toReal (gp x) ∂μ < ∫ (x : α), ↑(fp x) ∂μ + (fun a => ↑a) δ
fm : α → ℝ≥0 := fun x => Real.toNNReal (-f x)
int_fm : Integrable fun x => ↑(fm x)
gm : α → ℝ≥0
gm_le_fm : ∀ (x : α), gm x ≤ fm x
gmcont : UpperSemicontinuous gm
gm_integrable : Integrable fun x => ↑(gm x)
gmint : ∫ (x : α), ↑(fm x) ∂μ - (fun a => ↑a) δ ≤ ∫ (x : α), ↑(gm x) ∂μ
g : α → EReal := fun x => ↑(gp x) - ↑↑(gm x)
ae_g : ∀ᵐ (x : α) ∂μ, EReal.toReal (g x) = EReal.toReal ↑(gp x) - EReal.toReal ↑↑(gm x)
⊢ Integrable fun x => EReal.toReal (g x)

Next tactic:
show Integrable (fun x => EReal.toReal (g x)) μ
/-- **Vitali-Carathéodory Theorem**: given an integrable real function `f`, there exists an
integrable function `g > f` which is lower semicontinuous, with integral arbitrarily close
to that of `f`. This function has to be `EReal`-valued in general. -/
theorem exists_lt_lowerSemicontinuous_integral_lt [SigmaFinite μ] (f : α → ℝ) (hf : Integrable f μ)
    {ε : ℝ} (εpos : 0 < ε) :
    ∃ g : α → EReal,
      (∀ x, (f x : EReal) < g x) ∧
      LowerSemicontinuous g ∧
      Integrable (fun x => EReal.toReal (g x)) μ ∧
      (∀ᵐ x ∂μ, g x < ⊤) ∧ (∫ x, EReal.toReal (g x) ∂μ) < (∫ x, f x ∂μ) + ε := by
  let δ : ℝ≥0 := ⟨ε / 2, (half_pos εpos).le⟩
  have δpos : 0 < δ := half_pos εpos
  let fp : α → ℝ≥0 := fun x => Real.toNNReal (f x)
  have int_fp : Integrable (fun x => (fp x : ℝ)) μ := hf.real_toNNReal
  rcases exists_lt_lowerSemicontinuous_integral_gt_nnreal fp int_fp δpos with
    ⟨gp, fp_lt_gp, gpcont, gp_lt_top, gp_integrable, gpint⟩
  let fm : α → ℝ≥0 := fun x => Real.toNNReal (-f x)
  have int_fm : Integrable (fun x => (fm x : ℝ)) μ := hf.neg.real_toNNReal
  rcases exists_upperSemicontinuous_le_integral_le fm int_fm δpos with
    ⟨gm, gm_le_fm, gmcont, gm_integrable, gmint⟩
  let g : α → EReal := fun x => (gp x : EReal) - gm x
  have ae_g : ∀ᵐ x ∂μ, (g x).toReal = (gp x : EReal).toReal - (gm x : EReal).toReal := by
    filter_upwards [gp_lt_top] with _ hx
    rw [EReal.toReal_sub] <;> simp [hx.ne]
  refine' ⟨g, ?lt, ?lsc, ?int, ?aelt, ?intlt⟩
  case int =>
    show Integrable (fun x => EReal.toReal (g x)) μ
    

Proof state:
α : Type u_1
inst✝⁴ : TopologicalSpace α
inst✝³ : MeasurableSpace α
inst✝² : BorelSpace α
μ : Measure α
inst✝¹ : WeaklyRegular μ
inst✝ : SigmaFinite μ
f : α → ℝ
hf : Integrable f
ε : ℝ
εpos : 0 < ε
δ : ℝ≥0 := { val := ε / 2, property := (_ : 0 ≤ ε / 2) }
δpos : 0 < δ
fp : α → ℝ≥0 := fun x => Real.toNNReal (f x)
int_fp : Integrable fun x => ↑(fp x)
gp : α → ℝ≥0∞
fp_lt_gp : ∀ (x : α), ↑(fp x) < gp x
gpcont : LowerSemicontinuous gp
gp_lt_top : ∀ᵐ (x : α) ∂μ, gp x < ⊤
gp_integrable : Integrable fun x => ENNReal.toReal (gp x)
gpint : ∫ (x : α), ENNReal.toReal (gp x) ∂μ < ∫ (x : α), ↑(fp x) ∂μ + (fun a => ↑a) δ
fm : α → ℝ≥0 := fun x => Real.toNNReal (-f x)
int_fm : Integrable fun x => ↑(fm x)
gm : α → ℝ≥0
gm_le_fm : ∀ (x : α), gm x ≤ fm x
gmcont : UpperSemicontinuous gm
gm_integrable : Integrable fun x => ↑(gm x)
gmint : ∫ (x : α), ↑(fm x) ∂μ - (fun a => ↑a) δ ≤ ∫ (x : α), ↑(gm x) ∂μ
g : α → EReal := fun x => ↑(gp x) - ↑↑(gm x)
ae_g : ∀ᵐ (x : α) ∂μ, EReal.toReal (g x) = EReal.toReal ↑(gp x) - EReal.toReal ↑↑(gm x)
⊢ Integrable fun x => EReal.toReal (g x)

Next tactic:
rw [integrable_congr ae_g]