Theorem: MeasureTheory.exists_upperSemicontinuous_le_lintegral_le
File: Mathlib/MeasureTheory/Integral/VitaliCaratheodory.lean

tactic: obtain ⟨fs, fs_le_f, int_fs⟩ :
  ∃ fs : α →ₛ ℝ≥0, (∀ x, fs x ≤ f x) ∧ (∫⁻ x, f x ∂μ) ≤ (∫⁻ x, fs x ∂μ) + ε / 2 := by
  have aux := ENNReal.lt_add_right int_f (ENNReal.half_pos ε0).ne'
  conv_rhs at aux => rw [lintegral_eq_nnreal (fun x => (f x : ℝ≥0∞)) μ]
  erw [ENNReal.biSup_add] at aux  <;> [skip; exact ⟨0, fun x => by simp⟩]
  simp only [lt_iSup_iff] at aux
  rcases aux with ⟨fs, fs_le_f, int_fs⟩
  refine' ⟨fs, fun x => by simpa only [ENNReal.coe_le_coe] using fs_le_f x, _⟩
  convert int_fs.le
  rw [← SimpleFunc.lintegral_eq_lintegral]
  rfl
state_before: α : Type u_1
inst✝³ : TopologicalSpace α
inst✝² : MeasurableSpace α
inst✝¹ : BorelSpace α
μ : Measure α
inst✝ : WeaklyRegular μ
f : α → ℝ≥0
int_f : (∫⁻ (x : α), ↑(f x) ∂μ) ≠ ⊤
ε : ℝ≥0∞
ε0 : ε ≠ 0
⊢ ∃ g, (∀ (x : α), g x ≤ f x) ∧ UpperSemicontinuous g ∧ (∫⁻ (x : α), ↑(f x) ∂μ) ≤ (∫⁻ (x : α), ↑(g x) ∂μ) + ε

tactic: have int_fs_lt_top : (∫⁻ x, fs x ∂μ) ≠ ∞ := by
  refine' ne_top_of_le_ne_top int_f (lintegral_mono fun x => _)
  simpa only [ENNReal.coe_le_coe] using fs_le_f x
state_before: case intro.intro
α : Type u_1
inst✝³ : TopologicalSpace α
inst✝² : MeasurableSpace α
inst✝¹ : BorelSpace α
μ : Measure α
inst✝ : WeaklyRegular μ
f : α → ℝ≥0
int_f : (∫⁻ (x : α), ↑(f x) ∂μ) ≠ ⊤
ε : ℝ≥0∞
ε0 : ε ≠ 0
fs : α →ₛ ℝ≥0
fs_le_f : ∀ (x : α), ↑fs x ≤ f x
int_fs : (∫⁻ (x : α), ↑(f x) ∂μ) ≤ (∫⁻ (x : α), ↑(↑fs x) ∂μ) + ε / 2
⊢ ∃ g, (∀ (x : α), g x ≤ f x) ∧ UpperSemicontinuous g ∧ (∫⁻ (x : α), ↑(f x) ∂μ) ≤ (∫⁻ (x : α), ↑(g x) ∂μ) + ε

tactic: obtain ⟨g, g_le_fs, gcont, gint⟩ :
  ∃ g : α → ℝ≥0,
    (∀ x, g x ≤ fs x) ∧ UpperSemicontinuous g ∧ (∫⁻ x, fs x ∂μ) ≤ (∫⁻ x, g x ∂μ) + ε / 2 :=
  fs.exists_upperSemicontinuous_le_lintegral_le int_fs_lt_top (ENNReal.half_pos ε0).ne'
state_before: case intro.intro
α : Type u_1
inst✝³ : TopologicalSpace α
inst✝² : MeasurableSpace α
inst✝¹ : BorelSpace α
μ : Measure α
inst✝ : WeaklyRegular μ
f : α → ℝ≥0
int_f : (∫⁻ (x : α), ↑(f x) ∂μ) ≠ ⊤
ε : ℝ≥0∞
ε0 : ε ≠ 0
fs : α →ₛ ℝ≥0
fs_le_f : ∀ (x : α), ↑fs x ≤ f x
int_fs : (∫⁻ (x : α), ↑(f x) ∂μ) ≤ (∫⁻ (x : α), ↑(↑fs x) ∂μ) + ε / 2
int_fs_lt_top : (∫⁻ (x : α), ↑(↑fs x) ∂μ) ≠ ⊤
⊢ ∃ g, (∀ (x : α), g x ≤ f x) ∧ UpperSemicontinuous g ∧ (∫⁻ (x : α), ↑(f x) ∂μ) ≤ (∫⁻ (x : α), ↑(g x) ∂μ) + ε

tactic: refine' ⟨g, fun x => (g_le_fs x).trans (fs_le_f x), gcont, _⟩
state_before: case intro.intro.intro.intro.intro
α : Type u_1
inst✝³ : TopologicalSpace α
inst✝² : MeasurableSpace α
inst✝¹ : BorelSpace α
μ : Measure α
inst✝ : WeaklyRegular μ
f : α → ℝ≥0
int_f : (∫⁻ (x : α), ↑(f x) ∂μ) ≠ ⊤
ε : ℝ≥0∞
ε0 : ε ≠ 0
fs : α →ₛ ℝ≥0
fs_le_f : ∀ (x : α), ↑fs x ≤ f x
int_fs : (∫⁻ (x : α), ↑(f x) ∂μ) ≤ (∫⁻ (x : α), ↑(↑fs x) ∂μ) + ε / 2
int_fs_lt_top : (∫⁻ (x : α), ↑(↑fs x) ∂μ) ≠ ⊤
g : α → ℝ≥0
g_le_fs : ∀ (x : α), g x ≤ ↑fs x
gcont : UpperSemicontinuous g
gint : (∫⁻ (x : α), ↑(↑fs x) ∂μ) ≤ (∫⁻ (x : α), ↑(g x) ∂μ) + ε / 2
⊢ ∃ g, (∀ (x : α), g x ≤ f x) ∧ UpperSemicontinuous g ∧ (∫⁻ (x : α), ↑(f x) ∂μ) ≤ (∫⁻ (x : α), ↑(g x) ∂μ) + ε

tactic: calc
  (∫⁻ x, f x ∂μ) ≤ (∫⁻ x, fs x ∂μ) + ε / 2 := int_fs
  _ ≤ (∫⁻ x, g x ∂μ) + ε / 2 + ε / 2 := (add_le_add gint le_rfl)
  _ = (∫⁻ x, g x ∂μ) + ε := by rw [add_assoc, ENNReal.add_halves]
state_before: case intro.intro.intro.intro.intro
α : Type u_1
inst✝³ : TopologicalSpace α
inst✝² : MeasurableSpace α
inst✝¹ : BorelSpace α
μ : Measure α
inst✝ : WeaklyRegular μ
f : α → ℝ≥0
int_f : (∫⁻ (x : α), ↑(f x) ∂μ) ≠ ⊤
ε : ℝ≥0∞
ε0 : ε ≠ 0
fs : α →ₛ ℝ≥0
fs_le_f : ∀ (x : α), ↑fs x ≤ f x
int_fs : (∫⁻ (x : α), ↑(f x) ∂μ) ≤ (∫⁻ (x : α), ↑(↑fs x) ∂μ) + ε / 2
int_fs_lt_top : (∫⁻ (x : α), ↑(↑fs x) ∂μ) ≠ ⊤
g : α → ℝ≥0
g_le_fs : ∀ (x : α), g x ≤ ↑fs x
gcont : UpperSemicontinuous g
gint : (∫⁻ (x : α), ↑(↑fs x) ∂μ) ≤ (∫⁻ (x : α), ↑(g x) ∂μ) + ε / 2
⊢ (∫⁻ (x : α), ↑(f x) ∂μ) ≤ (∫⁻ (x : α), ↑(g x) ∂μ) + ε

tactic: have aux := ENNReal.lt_add_right int_f (ENNReal.half_pos ε0).ne'
state_before: α : Type u_1
inst✝³ : TopologicalSpace α
inst✝² : MeasurableSpace α
inst✝¹ : BorelSpace α
μ : Measure α
inst✝ : WeaklyRegular μ
f : α → ℝ≥0
int_f : (∫⁻ (x : α), ↑(f x) ∂μ) ≠ ⊤
ε : ℝ≥0∞
ε0 : ε ≠ 0
⊢ ∃ fs, (∀ (x : α), ↑fs x ≤ f x) ∧ (∫⁻ (x : α), ↑(f x) ∂μ) ≤ (∫⁻ (x : α), ↑(↑fs x) ∂μ) + ε / 2

tactic: conv_rhs at aux => rw [lintegral_eq_nnreal (fun x => (f x : ℝ≥0∞)) μ]
state_before: α : Type u_1
inst✝³ : TopologicalSpace α
inst✝² : MeasurableSpace α
inst✝¹ : BorelSpace α
μ : Measure α
inst✝ : WeaklyRegular μ
f : α → ℝ≥0
int_f : (∫⁻ (x : α), ↑(f x) ∂μ) ≠ ⊤
ε : ℝ≥0∞
ε0 : ε ≠ 0
aux : (∫⁻ (x : α), ↑(f x) ∂μ) < (∫⁻ (x : α), ↑(f x) ∂μ) + ε / 2
⊢ ∃ fs, (∀ (x : α), ↑fs x ≤ f x) ∧ (∫⁻ (x : α), ↑(f x) ∂μ) ≤ (∫⁻ (x : α), ↑(↑fs x) ∂μ) + ε / 2

tactic: erw [ENNReal.biSup_add] at aux  <;> [skip; exact ⟨0, fun x => by simp⟩]
state_before: α : Type u_1
inst✝³ : TopologicalSpace α
inst✝² : MeasurableSpace α
inst✝¹ : BorelSpace α
μ : Measure α
inst✝ : WeaklyRegular μ
f : α → ℝ≥0
int_f : (∫⁻ (x : α), ↑(f x) ∂μ) ≠ ⊤
ε : ℝ≥0∞
ε0 : ε ≠ 0
aux :
  (∫⁻ (x : α), ↑(f x) ∂μ) <
    (⨆ (φ : α →ₛ ℝ≥0) (_ : ∀ (x : α), ↑(↑φ x) ≤ ↑(f x)), SimpleFunc.lintegral (SimpleFunc.map ENNReal.some φ) μ) + ε / 2
⊢ ∃ fs, (∀ (x : α), ↑fs x ≤ f x) ∧ (∫⁻ (x : α), ↑(f x) ∂μ) ≤ (∫⁻ (x : α), ↑(↑fs x) ∂μ) + ε / 2

tactic: simp only [lt_iSup_iff] at aux
state_before: α : Type u_1
inst✝³ : TopologicalSpace α
inst✝² : MeasurableSpace α
inst✝¹ : BorelSpace α
μ : Measure α
inst✝ : WeaklyRegular μ
f : α → ℝ≥0
int_f : (∫⁻ (x : α), ↑(f x) ∂μ) ≠ ⊤
ε : ℝ≥0∞
ε0 : ε ≠ 0
aux :
  (∫⁻ (x : α), ↑(f x) ∂μ) <
    ⨆ (i : α →ₛ ℝ≥0) (_ : i ∈ fun φ => ∀ (x : α), ↑(↑φ x) ≤ ↑(f x)),
      SimpleFunc.lintegral (SimpleFunc.map ENNReal.some i) μ + ε / 2
⊢ ∃ fs, (∀ (x : α), ↑fs x ≤ f x) ∧ (∫⁻ (x : α), ↑(f x) ∂μ) ≤ (∫⁻ (x : α), ↑(↑fs x) ∂μ) + ε / 2

tactic: rcases aux with ⟨fs, fs_le_f, int_fs⟩
state_before: α : Type u_1
inst✝³ : TopologicalSpace α
inst✝² : MeasurableSpace α
inst✝¹ : BorelSpace α
μ : Measure α
inst✝ : WeaklyRegular μ
f : α → ℝ≥0
int_f : (∫⁻ (x : α), ↑(f x) ∂μ) ≠ ⊤
ε : ℝ≥0∞
ε0 : ε ≠ 0
aux : ∃ i i_1, (∫⁻ (x : α), ↑(f x) ∂μ) < SimpleFunc.lintegral (SimpleFunc.map ENNReal.some i) μ + ε / 2
⊢ ∃ fs, (∀ (x : α), ↑fs x ≤ f x) ∧ (∫⁻ (x : α), ↑(f x) ∂μ) ≤ (∫⁻ (x : α), ↑(↑fs x) ∂μ) + ε / 2

tactic: refine' ⟨fs, fun x => by simpa only [ENNReal.coe_le_coe] using fs_le_f x, _⟩
state_before: case intro.intro
α : Type u_1
inst✝³ : TopologicalSpace α
inst✝² : MeasurableSpace α
inst✝¹ : BorelSpace α
μ : Measure α
inst✝ : WeaklyRegular μ
f : α → ℝ≥0
int_f : (∫⁻ (x : α), ↑(f x) ∂μ) ≠ ⊤
ε : ℝ≥0∞
ε0 : ε ≠ 0
fs : α →ₛ ℝ≥0
fs_le_f : fs ∈ fun φ => ∀ (x : α), ↑(↑φ x) ≤ ↑(f x)
int_fs : (∫⁻ (x : α), ↑(f x) ∂μ) < SimpleFunc.lintegral (SimpleFunc.map ENNReal.some fs) μ + ε / 2
⊢ ∃ fs, (∀ (x : α), ↑fs x ≤ f x) ∧ (∫⁻ (x : α), ↑(f x) ∂μ) ≤ (∫⁻ (x : α), ↑(↑fs x) ∂μ) + ε / 2

tactic: convert int_fs.le
state_before: case intro.intro
α : Type u_1
inst✝³ : TopologicalSpace α
inst✝² : MeasurableSpace α
inst✝¹ : BorelSpace α
μ : Measure α
inst✝ : WeaklyRegular μ
f : α → ℝ≥0
int_f : (∫⁻ (x : α), ↑(f x) ∂μ) ≠ ⊤
ε : ℝ≥0∞
ε0 : ε ≠ 0
fs : α →ₛ ℝ≥0
fs_le_f : fs ∈ fun φ => ∀ (x : α), ↑(↑φ x) ≤ ↑(f x)
int_fs : (∫⁻ (x : α), ↑(f x) ∂μ) < SimpleFunc.lintegral (SimpleFunc.map ENNReal.some fs) μ + ε / 2
⊢ (∫⁻ (x : α), ↑(f x) ∂μ) ≤ (∫⁻ (x : α), ↑(↑fs x) ∂μ) + ε / 2

tactic: rw [← SimpleFunc.lintegral_eq_lintegral]
state_before: case h.e'_4.h.e'_5
α : Type u_1
inst✝³ : TopologicalSpace α
inst✝² : MeasurableSpace α
inst✝¹ : BorelSpace α
μ : Measure α
inst✝ : WeaklyRegular μ
f : α → ℝ≥0
int_f : (∫⁻ (x : α), ↑(f x) ∂μ) ≠ ⊤
ε : ℝ≥0∞
ε0 : ε ≠ 0
fs : α →ₛ ℝ≥0
fs_le_f : fs ∈ fun φ => ∀ (x : α), ↑(↑φ x) ≤ ↑(f x)
int_fs : (∫⁻ (x : α), ↑(f x) ∂μ) < SimpleFunc.lintegral (SimpleFunc.map ENNReal.some fs) μ + ε / 2
⊢ (∫⁻ (x : α), ↑(↑fs x) ∂μ) = SimpleFunc.lintegral (SimpleFunc.map ENNReal.some fs) μ

tactic: rfl
state_before: case h.e'_4.h.e'_5
α : Type u_1
inst✝³ : TopologicalSpace α
inst✝² : MeasurableSpace α
inst✝¹ : BorelSpace α
μ : Measure α
inst✝ : WeaklyRegular μ
f : α → ℝ≥0
int_f : (∫⁻ (x : α), ↑(f x) ∂μ) ≠ ⊤
ε : ℝ≥0∞
ε0 : ε ≠ 0
fs : α →ₛ ℝ≥0
fs_le_f : fs ∈ fun φ => ∀ (x : α), ↑(↑φ x) ≤ ↑(f x)
int_fs : (∫⁻ (x : α), ↑(f x) ∂μ) < SimpleFunc.lintegral (SimpleFunc.map ENNReal.some fs) μ + ε / 2
⊢ (∫⁻ (x : α), ↑(↑fs x) ∂μ) = ∫⁻ (a : α), ↑(SimpleFunc.map ENNReal.some fs) a ∂μ

tactic: simp
state_before: α : Type u_1
inst✝³ : TopologicalSpace α
inst✝² : MeasurableSpace α
inst✝¹ : BorelSpace α
μ : Measure α
inst✝ : WeaklyRegular μ
f : α → ℝ≥0
int_f : (∫⁻ (x : α), ↑(f x) ∂μ) ≠ ⊤
ε : ℝ≥0∞
ε0 : ε ≠ 0
aux :
  (∫⁻ (x : α), ↑(f x) ∂μ) <
    (⨆ (φ : α →ₛ ℝ≥0) (_ : ∀ (x : α), ↑(↑φ x) ≤ ↑(f x)), SimpleFunc.lintegral (SimpleFunc.map ENNReal.some φ) μ) + ε / 2
x : α
⊢ ↑(↑0 x) ≤ ↑(f x)

tactic: simpa only [ENNReal.coe_le_coe] using fs_le_f x
state_before: α : Type u_1
inst✝³ : TopologicalSpace α
inst✝² : MeasurableSpace α
inst✝¹ : BorelSpace α
μ : Measure α
inst✝ : WeaklyRegular μ
f : α → ℝ≥0
int_f : (∫⁻ (x : α), ↑(f x) ∂μ) ≠ ⊤
ε : ℝ≥0∞
ε0 : ε ≠ 0
fs : α →ₛ ℝ≥0
fs_le_f : fs ∈ fun φ => ∀ (x : α), ↑(↑φ x) ≤ ↑(f x)
int_fs : (∫⁻ (x : α), ↑(f x) ∂μ) < SimpleFunc.lintegral (SimpleFunc.map ENNReal.some fs) μ + ε / 2
x : α
⊢ ↑fs x ≤ f x

tactic: refine' ne_top_of_le_ne_top int_f (lintegral_mono fun x => _)
state_before: α : Type u_1
inst✝³ : TopologicalSpace α
inst✝² : MeasurableSpace α
inst✝¹ : BorelSpace α
μ : Measure α
inst✝ : WeaklyRegular μ
f : α → ℝ≥0
int_f : (∫⁻ (x : α), ↑(f x) ∂μ) ≠ ⊤
ε : ℝ≥0∞
ε0 : ε ≠ 0
fs : α →ₛ ℝ≥0
fs_le_f : ∀ (x : α), ↑fs x ≤ f x
int_fs : (∫⁻ (x : α), ↑(f x) ∂μ) ≤ (∫⁻ (x : α), ↑(↑fs x) ∂μ) + ε / 2
⊢ (∫⁻ (x : α), ↑(↑fs x) ∂μ) ≠ ⊤

tactic: simpa only [ENNReal.coe_le_coe] using fs_le_f x
state_before: α : Type u_1
inst✝³ : TopologicalSpace α
inst✝² : MeasurableSpace α
inst✝¹ : BorelSpace α
μ : Measure α
inst✝ : WeaklyRegular μ
f : α → ℝ≥0
int_f : (∫⁻ (x : α), ↑(f x) ∂μ) ≠ ⊤
ε : ℝ≥0∞
ε0 : ε ≠ 0
fs : α →ₛ ℝ≥0
fs_le_f : ∀ (x : α), ↑fs x ≤ f x
int_fs : (∫⁻ (x : α), ↑(f x) ∂μ) ≤ (∫⁻ (x : α), ↑(↑fs x) ∂μ) + ε / 2
x : α
⊢ ↑(↑fs x) ≤ ↑(f x)

tactic: rw [add_assoc, ENNReal.add_halves]
state_before: α : Type u_1
inst✝³ : TopologicalSpace α
inst✝² : MeasurableSpace α
inst✝¹ : BorelSpace α
μ : Measure α
inst✝ : WeaklyRegular μ
f : α → ℝ≥0
int_f : (∫⁻ (x : α), ↑(f x) ∂μ) ≠ ⊤
ε : ℝ≥0∞
ε0 : ε ≠ 0
fs : α →ₛ ℝ≥0
fs_le_f : ∀ (x : α), ↑fs x ≤ f x
int_fs : (∫⁻ (x : α), ↑(f x) ∂μ) ≤ (∫⁻ (x : α), ↑(↑fs x) ∂μ) + ε / 2
int_fs_lt_top : (∫⁻ (x : α), ↑(↑fs x) ∂μ) ≠ ⊤
g : α → ℝ≥0
g_le_fs : ∀ (x : α), g x ≤ ↑fs x
gcont : UpperSemicontinuous g
gint : (∫⁻ (x : α), ↑(↑fs x) ∂μ) ≤ (∫⁻ (x : α), ↑(g x) ∂μ) + ε / 2
⊢ (∫⁻ (x : α), ↑(g x) ∂μ) + ε / 2 + ε / 2 = (∫⁻ (x : α), ↑(g x) ∂μ) + ε