l3lab/ntp-mathlib huggingface dataset:
/-- A sigma-finite measure is absolutely continuous with respect to some finite measure. -/
theorem exists_absolutelyContinuous_isFiniteMeasure {m : MeasurableSpace α} (μ : Measure α)
    [SigmaFinite μ] : ∃ ν : Measure α, IsFiniteMeasure ν ∧ μ ≪ ν := by
  obtain ⟨g, gpos, gmeas, hg⟩ :
    ∃ g : α → ℝ≥0, (∀ x : α, 0 < g x) ∧ Measurable g ∧ ∫⁻ x : α, ↑(g x) ∂μ < 1 :=
    exists_pos_lintegral_lt_of_sigmaFinite μ one_ne_zero
  refine' ⟨μ.withDensity fun x => g x, isFiniteMeasure_withDensity hg.ne_top, _⟩
  have : μ = (μ.withDensity fun x => g x).withDensity fun x => (g x)⁻¹ := by
    have A : ((fun x : α => (g x : ℝ≥0∞)) * fun x : α => (g x : ℝ≥0∞)⁻¹) = 1 := by
      ext1 x
      exact ENNReal.mul_inv_cancel (ENNReal.coe_ne_zero.2 (gpos x).ne') ENNReal.coe_ne_top
    rw [← withDensity_mul _ gmeas.coe_nnreal_ennreal gmeas.coe_nnreal_ennreal.inv, A,
      withDensity_one]
  

Proof state:
case intro.intro.intro
α : Type u_1
m0 : MeasurableSpace α
μ✝ : Measure α
m : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
g : α → ℝ≥0
gpos : ∀ (x : α), 0 < g x
gmeas : Measurable g
hg : ∫⁻ (x : α), ↑(g x) ∂μ < 1
this : μ = withDensity (withDensity μ fun x => ↑(g x)) fun x => (↑(g x))⁻¹
⊢ μ ≪ withDensity μ fun x => ↑(g x)

Next tactic:
nth_rw 1 [this]
/-- A sigma-finite measure is absolutely continuous with respect to some finite measure. -/
theorem exists_absolutelyContinuous_isFiniteMeasure {m : MeasurableSpace α} (μ : Measure α)
    [SigmaFinite μ] : ∃ ν : Measure α, IsFiniteMeasure ν ∧ μ ≪ ν := by
  obtain ⟨g, gpos, gmeas, hg⟩ :
    ∃ g : α → ℝ≥0, (∀ x : α, 0 < g x) ∧ Measurable g ∧ ∫⁻ x : α, ↑(g x) ∂μ < 1 :=
    exists_pos_lintegral_lt_of_sigmaFinite μ one_ne_zero
  refine' ⟨μ.withDensity fun x => g x, isFiniteMeasure_withDensity hg.ne_top, _⟩
  have : μ = (μ.withDensity fun x => g x).withDensity fun x => (g x)⁻¹ := by
    have A : ((fun x : α => (g x : ℝ≥0∞)) * fun x : α => (g x : ℝ≥0∞)⁻¹) = 1 := by
      ext1 x
      exact ENNReal.mul_inv_cancel (ENNReal.coe_ne_zero.2 (gpos x).ne') ENNReal.coe_ne_top
    rw [← withDensity_mul _ gmeas.coe_nnreal_ennreal gmeas.coe_nnreal_ennreal.inv, A,
      withDensity_one]
  nth_rw 1 [this]
  

Proof state:
case intro.intro.intro
α : Type u_1
m0 : MeasurableSpace α
μ✝ : Measure α
m : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
g : α → ℝ≥0
gpos : ∀ (x : α), 0 < g x
gmeas : Measurable g
hg : ∫⁻ (x : α), ↑(g x) ∂μ < 1
this : μ = withDensity (withDensity μ fun x => ↑(g x)) fun x => (↑(g x))⁻¹
⊢ (withDensity (withDensity μ fun x => ↑(g x)) fun x => (↑(g x))⁻¹) ≪ withDensity μ fun x => ↑(g x)

Next tactic:
exact withDensity_absolutelyContinuous _ _
lemma SigmaFinite.withDensity [SigmaFinite μ] {f : α → ℝ≥0} (hf : AEMeasurable f μ) :
    SigmaFinite (μ.withDensity (fun x ↦ f x)) := by
  

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0
hf : AEMeasurable f
⊢ SigmaFinite (Measure.withDensity μ fun x => ↑(f x))

Next tactic:
have h : (fun x ↦ (f x : ℝ≥0∞)) =ᵐ[μ] fun x ↦ ((hf.mk f x : ℝ≥0) : ℝ≥0∞) := by
    filter_upwards [hf.ae_eq_mk] with x hx using by rw [hx]
lemma SigmaFinite.withDensity [SigmaFinite μ] {f : α → ℝ≥0} (hf : AEMeasurable f μ) :
    SigmaFinite (μ.withDensity (fun x ↦ f x)) := by
  have h : (fun x ↦ (f x : ℝ≥0∞)) =ᵐ[μ] fun x ↦ ((hf.mk f x : ℝ≥0) : ℝ≥0∞) := by
    

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0
hf : AEMeasurable f
⊢ (fun x => ↑(f x)) =ᶠ[ae μ] fun x => ↑(AEMeasurable.mk f hf x)

Next tactic:
filter_upwards [hf.ae_eq_mk] with x hx using by rw [hx]
lemma SigmaFinite.withDensity [SigmaFinite μ] {f : α → ℝ≥0} (hf : AEMeasurable f μ) :
    SigmaFinite (μ.withDensity (fun x ↦ f x)) := by
  have h : (fun x ↦ (f x : ℝ≥0∞)) =ᵐ[μ] fun x ↦ ((hf.mk f x : ℝ≥0) : ℝ≥0∞) := by
    filter_upwards [hf.ae_eq_mk] with x hx using by 

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0
hf : AEMeasurable f
x : α
hx : f x = AEMeasurable.mk f hf x
⊢ ↑(f x) = ↑(AEMeasurable.mk f hf x)

Next tactic:
rw [hx]
lemma SigmaFinite.withDensity [SigmaFinite μ] {f : α → ℝ≥0} (hf : AEMeasurable f μ) :
    SigmaFinite (μ.withDensity (fun x ↦ f x)) := by
  have h : (fun x ↦ (f x : ℝ≥0∞)) =ᵐ[μ] fun x ↦ ((hf.mk f x : ℝ≥0) : ℝ≥0∞) := by
    filter_upwards [hf.ae_eq_mk] with x hx using by rw [hx]
  

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0
hf : AEMeasurable f
h : (fun x => ↑(f x)) =ᶠ[ae μ] fun x => ↑(AEMeasurable.mk f hf x)
⊢ SigmaFinite (Measure.withDensity μ fun x => ↑(f x))

Next tactic:
rw [withDensity_congr_ae h]
lemma SigmaFinite.withDensity [SigmaFinite μ] {f : α → ℝ≥0} (hf : AEMeasurable f μ) :
    SigmaFinite (μ.withDensity (fun x ↦ f x)) := by
  have h : (fun x ↦ (f x : ℝ≥0∞)) =ᵐ[μ] fun x ↦ ((hf.mk f x : ℝ≥0) : ℝ≥0∞) := by
    filter_upwards [hf.ae_eq_mk] with x hx using by rw [hx]
  rw [withDensity_congr_ae h]
  

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0
hf : AEMeasurable f
h : (fun x => ↑(f x)) =ᶠ[ae μ] fun x => ↑(AEMeasurable.mk f hf x)
⊢ SigmaFinite (Measure.withDensity μ fun x => ↑(AEMeasurable.mk f hf x))

Next tactic:
obtain ⟨s, hs, h⟩ := exists_spanning_measurableSet_le
    hf.measurable_mk μ
lemma SigmaFinite.withDensity [SigmaFinite μ] {f : α → ℝ≥0} (hf : AEMeasurable f μ) :
    SigmaFinite (μ.withDensity (fun x ↦ f x)) := by
  have h : (fun x ↦ (f x : ℝ≥0∞)) =ᵐ[μ] fun x ↦ ((hf.mk f x : ℝ≥0) : ℝ≥0∞) := by
    filter_upwards [hf.ae_eq_mk] with x hx using by rw [hx]
  rw [withDensity_congr_ae h]
  obtain ⟨s, hs, h⟩ := exists_spanning_measurableSet_le
    hf.measurable_mk μ
  

Proof state:
case intro.intro
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0
hf : AEMeasurable f
h✝ : (fun x => ↑(f x)) =ᶠ[ae μ] fun x => ↑(AEMeasurable.mk f hf x)
s : ℕ → Set α
hs : ∀ (n : ℕ), MeasurableSet (s n) ∧ ↑↑μ (s n) < ⊤ ∧ ∀ x ∈ s n, AEMeasurable.mk f hf x ≤ ↑n
h : ⋃ i, s i = univ
⊢ SigmaFinite (Measure.withDensity μ fun x => ↑(AEMeasurable.mk f hf x))

Next tactic:
constructor
lemma SigmaFinite.withDensity [SigmaFinite μ] {f : α → ℝ≥0} (hf : AEMeasurable f μ) :
    SigmaFinite (μ.withDensity (fun x ↦ f x)) := by
  have h : (fun x ↦ (f x : ℝ≥0∞)) =ᵐ[μ] fun x ↦ ((hf.mk f x : ℝ≥0) : ℝ≥0∞) := by
    filter_upwards [hf.ae_eq_mk] with x hx using by rw [hx]
  rw [withDensity_congr_ae h]
  obtain ⟨s, hs, h⟩ := exists_spanning_measurableSet_le
    hf.measurable_mk μ
  constructor
  

Proof state:
case intro.intro.out'
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0
hf : AEMeasurable f
h✝ : (fun x => ↑(f x)) =ᶠ[ae μ] fun x => ↑(AEMeasurable.mk f hf x)
s : ℕ → Set α
hs : ∀ (n : ℕ), MeasurableSet (s n) ∧ ↑↑μ (s n) < ⊤ ∧ ∀ x ∈ s n, AEMeasurable.mk f hf x ≤ ↑n
h : ⋃ i, s i = univ
⊢ Nonempty (FiniteSpanningSetsIn (Measure.withDensity μ fun x => ↑(AEMeasurable.mk f hf x)) univ)

Next tactic:
refine ⟨s, by simp, fun i ↦ ?_, h⟩
lemma SigmaFinite.withDensity [SigmaFinite μ] {f : α → ℝ≥0} (hf : AEMeasurable f μ) :
    SigmaFinite (μ.withDensity (fun x ↦ f x)) := by
  have h : (fun x ↦ (f x : ℝ≥0∞)) =ᵐ[μ] fun x ↦ ((hf.mk f x : ℝ≥0) : ℝ≥0∞) := by
    filter_upwards [hf.ae_eq_mk] with x hx using by rw [hx]
  rw [withDensity_congr_ae h]
  obtain ⟨s, hs, h⟩ := exists_spanning_measurableSet_le
    hf.measurable_mk μ
  constructor
  refine ⟨s, by 

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0
hf : AEMeasurable f
h✝ : (fun x => ↑(f x)) =ᶠ[ae μ] fun x => ↑(AEMeasurable.mk f hf x)
s : ℕ → Set α
hs : ∀ (n : ℕ), MeasurableSet (s n) ∧ ↑↑μ (s n) < ⊤ ∧ ∀ x ∈ s n, AEMeasurable.mk f hf x ≤ ↑n
h : ⋃ i, s i = univ
⊢ ∀ (i : ℕ), s i ∈ univ

Next tactic:
simp
lemma SigmaFinite.withDensity [SigmaFinite μ] {f : α → ℝ≥0} (hf : AEMeasurable f μ) :
    SigmaFinite (μ.withDensity (fun x ↦ f x)) := by
  have h : (fun x ↦ (f x : ℝ≥0∞)) =ᵐ[μ] fun x ↦ ((hf.mk f x : ℝ≥0) : ℝ≥0∞) := by
    filter_upwards [hf.ae_eq_mk] with x hx using by rw [hx]
  rw [withDensity_congr_ae h]
  obtain ⟨s, hs, h⟩ := exists_spanning_measurableSet_le
    hf.measurable_mk μ
  constructor
  refine ⟨s, by simp, fun i ↦ ?_, h⟩
  

Proof state:
case intro.intro.out'
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0
hf : AEMeasurable f
h✝ : (fun x => ↑(f x)) =ᶠ[ae μ] fun x => ↑(AEMeasurable.mk f hf x)
s : ℕ → Set α
hs : ∀ (n : ℕ), MeasurableSet (s n) ∧ ↑↑μ (s n) < ⊤ ∧ ∀ x ∈ s n, AEMeasurable.mk f hf x ≤ ↑n
h : ⋃ i, s i = univ
i : ℕ
⊢ ↑↑(Measure.withDensity μ fun x => ↑(AEMeasurable.mk f hf x)) (s i) < ⊤

Next tactic:
rw [withDensity_apply _ (hs i).1]
lemma SigmaFinite.withDensity [SigmaFinite μ] {f : α → ℝ≥0} (hf : AEMeasurable f μ) :
    SigmaFinite (μ.withDensity (fun x ↦ f x)) := by
  have h : (fun x ↦ (f x : ℝ≥0∞)) =ᵐ[μ] fun x ↦ ((hf.mk f x : ℝ≥0) : ℝ≥0∞) := by
    filter_upwards [hf.ae_eq_mk] with x hx using by rw [hx]
  rw [withDensity_congr_ae h]
  obtain ⟨s, hs, h⟩ := exists_spanning_measurableSet_le
    hf.measurable_mk μ
  constructor
  refine ⟨s, by simp, fun i ↦ ?_, h⟩
  rw [withDensity_apply _ (hs i).1]
  

Proof state:
case intro.intro.out'
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0
hf : AEMeasurable f
h✝ : (fun x => ↑(f x)) =ᶠ[ae μ] fun x => ↑(AEMeasurable.mk f hf x)
s : ℕ → Set α
hs : ∀ (n : ℕ), MeasurableSet (s n) ∧ ↑↑μ (s n) < ⊤ ∧ ∀ x ∈ s n, AEMeasurable.mk f hf x ≤ ↑n
h : ⋃ i, s i = univ
i : ℕ
⊢ ∫⁻ (a : α) in s i, ↑(AEMeasurable.mk f hf a) ∂μ < ⊤

Next tactic:
calc ∫⁻ a in s i, ((hf.mk f a : ℝ≥0) : ℝ≥0∞) ∂μ
    ≤ ∫⁻ _ in s i, i ∂μ := by
        refine set_lintegral_mono hf.measurable_mk.coe_nnreal_ennreal
          measurable_const (fun x hxs ↦ ?_)
        norm_cast
        exact (hs i).2.2 x hxs
  _ = i * μ (s i) := by rw [set_lintegral_const]
  _ < ⊤ := ENNReal.mul_lt_top (by simp) (hs i).2.1.ne
lemma SigmaFinite.withDensity [SigmaFinite μ] {f : α → ℝ≥0} (hf : AEMeasurable f μ) :
    SigmaFinite (μ.withDensity (fun x ↦ f x)) := by
  have h : (fun x ↦ (f x : ℝ≥0∞)) =ᵐ[μ] fun x ↦ ((hf.mk f x : ℝ≥0) : ℝ≥0∞) := by
    filter_upwards [hf.ae_eq_mk] with x hx using by rw [hx]
  rw [withDensity_congr_ae h]
  obtain ⟨s, hs, h⟩ := exists_spanning_measurableSet_le
    hf.measurable_mk μ
  constructor
  refine ⟨s, by simp, fun i ↦ ?_, h⟩
  rw [withDensity_apply _ (hs i).1]
  calc ∫⁻ a in s i, ((hf.mk f a : ℝ≥0) : ℝ≥0∞) ∂μ
    ≤ ∫⁻ _ in s i, i ∂μ := by
        

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0
hf : AEMeasurable f
h✝ : (fun x => ↑(f x)) =ᶠ[ae μ] fun x => ↑(AEMeasurable.mk f hf x)
s : ℕ → Set α
hs : ∀ (n : ℕ), MeasurableSet (s n) ∧ ↑↑μ (s n) < ⊤ ∧ ∀ x ∈ s n, AEMeasurable.mk f hf x ≤ ↑n
h : ⋃ i, s i = univ
i : ℕ
⊢ ∫⁻ (a : α) in s i, ↑(AEMeasurable.mk f hf a) ∂μ ≤ ∫⁻ (x : α) in s i, ↑i ∂μ

Next tactic:
refine set_lintegral_mono hf.measurable_mk.coe_nnreal_ennreal
          measurable_const (fun x hxs ↦ ?_)
lemma SigmaFinite.withDensity [SigmaFinite μ] {f : α → ℝ≥0} (hf : AEMeasurable f μ) :
    SigmaFinite (μ.withDensity (fun x ↦ f x)) := by
  have h : (fun x ↦ (f x : ℝ≥0∞)) =ᵐ[μ] fun x ↦ ((hf.mk f x : ℝ≥0) : ℝ≥0∞) := by
    filter_upwards [hf.ae_eq_mk] with x hx using by rw [hx]
  rw [withDensity_congr_ae h]
  obtain ⟨s, hs, h⟩ := exists_spanning_measurableSet_le
    hf.measurable_mk μ
  constructor
  refine ⟨s, by simp, fun i ↦ ?_, h⟩
  rw [withDensity_apply _ (hs i).1]
  calc ∫⁻ a in s i, ((hf.mk f a : ℝ≥0) : ℝ≥0∞) ∂μ
    ≤ ∫⁻ _ in s i, i ∂μ := by
        refine set_lintegral_mono hf.measurable_mk.coe_nnreal_ennreal
          measurable_const (fun x hxs ↦ ?_)
        

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0
hf : AEMeasurable f
h✝ : (fun x => ↑(f x)) =ᶠ[ae μ] fun x => ↑(AEMeasurable.mk f hf x)
s : ℕ → Set α
hs : ∀ (n : ℕ), MeasurableSet (s n) ∧ ↑↑μ (s n) < ⊤ ∧ ∀ x ∈ s n, AEMeasurable.mk f hf x ≤ ↑n
h : ⋃ i, s i = univ
i : ℕ
x : α
hxs : x ∈ s i
⊢ ↑(AEMeasurable.mk f hf x) ≤ ↑i

Next tactic:
norm_cast
lemma SigmaFinite.withDensity [SigmaFinite μ] {f : α → ℝ≥0} (hf : AEMeasurable f μ) :
    SigmaFinite (μ.withDensity (fun x ↦ f x)) := by
  have h : (fun x ↦ (f x : ℝ≥0∞)) =ᵐ[μ] fun x ↦ ((hf.mk f x : ℝ≥0) : ℝ≥0∞) := by
    filter_upwards [hf.ae_eq_mk] with x hx using by rw [hx]
  rw [withDensity_congr_ae h]
  obtain ⟨s, hs, h⟩ := exists_spanning_measurableSet_le
    hf.measurable_mk μ
  constructor
  refine ⟨s, by simp, fun i ↦ ?_, h⟩
  rw [withDensity_apply _ (hs i).1]
  calc ∫⁻ a in s i, ((hf.mk f a : ℝ≥0) : ℝ≥0∞) ∂μ
    ≤ ∫⁻ _ in s i, i ∂μ := by
        refine set_lintegral_mono hf.measurable_mk.coe_nnreal_ennreal
          measurable_const (fun x hxs ↦ ?_)
        norm_cast
        

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0
hf : AEMeasurable f
h✝ : (fun x => ↑(f x)) =ᶠ[ae μ] fun x => ↑(AEMeasurable.mk f hf x)
s : ℕ → Set α
hs : ∀ (n : ℕ), MeasurableSet (s n) ∧ ↑↑μ (s n) < ⊤ ∧ ∀ x ∈ s n, AEMeasurable.mk f hf x ≤ ↑n
h : ⋃ i, s i = univ
i : ℕ
x : α
hxs : x ∈ s i
⊢ AEMeasurable.mk f hf x ≤ ↑i

Next tactic:
exact (hs i).2.2 x hxs
lemma SigmaFinite.withDensity [SigmaFinite μ] {f : α → ℝ≥0} (hf : AEMeasurable f μ) :
    SigmaFinite (μ.withDensity (fun x ↦ f x)) := by
  have h : (fun x ↦ (f x : ℝ≥0∞)) =ᵐ[μ] fun x ↦ ((hf.mk f x : ℝ≥0) : ℝ≥0∞) := by
    filter_upwards [hf.ae_eq_mk] with x hx using by rw [hx]
  rw [withDensity_congr_ae h]
  obtain ⟨s, hs, h⟩ := exists_spanning_measurableSet_le
    hf.measurable_mk μ
  constructor
  refine ⟨s, by simp, fun i ↦ ?_, h⟩
  rw [withDensity_apply _ (hs i).1]
  calc ∫⁻ a in s i, ((hf.mk f a : ℝ≥0) : ℝ≥0∞) ∂μ
    ≤ ∫⁻ _ in s i, i ∂μ := by
        refine set_lintegral_mono hf.measurable_mk.coe_nnreal_ennreal
          measurable_const (fun x hxs ↦ ?_)
        norm_cast
        exact (hs i).2.2 x hxs
  _ = i * μ (s i) := by 

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0
hf : AEMeasurable f
h✝ : (fun x => ↑(f x)) =ᶠ[ae μ] fun x => ↑(AEMeasurable.mk f hf x)
s : ℕ → Set α
hs : ∀ (n : ℕ), MeasurableSet (s n) ∧ ↑↑μ (s n) < ⊤ ∧ ∀ x ∈ s n, AEMeasurable.mk f hf x ≤ ↑n
h : ⋃ i, s i = univ
i : ℕ
⊢ ∫⁻ (x : α) in s i, ↑i ∂μ = ↑i * ↑↑μ (s i)

Next tactic:
rw [set_lintegral_const]
lemma SigmaFinite.withDensity [SigmaFinite μ] {f : α → ℝ≥0} (hf : AEMeasurable f μ) :
    SigmaFinite (μ.withDensity (fun x ↦ f x)) := by
  have h : (fun x ↦ (f x : ℝ≥0∞)) =ᵐ[μ] fun x ↦ ((hf.mk f x : ℝ≥0) : ℝ≥0∞) := by
    filter_upwards [hf.ae_eq_mk] with x hx using by rw [hx]
  rw [withDensity_congr_ae h]
  obtain ⟨s, hs, h⟩ := exists_spanning_measurableSet_le
    hf.measurable_mk μ
  constructor
  refine ⟨s, by simp, fun i ↦ ?_, h⟩
  rw [withDensity_apply _ (hs i).1]
  calc ∫⁻ a in s i, ((hf.mk f a : ℝ≥0) : ℝ≥0∞) ∂μ
    ≤ ∫⁻ _ in s i, i ∂μ := by
        refine set_lintegral_mono hf.measurable_mk.coe_nnreal_ennreal
          measurable_const (fun x hxs ↦ ?_)
        norm_cast
        exact (hs i).2.2 x hxs
  _ = i * μ (s i) := by rw [set_lintegral_const]
  _ < ⊤ := ENNReal.mul_lt_top (by 

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0
hf : AEMeasurable f
h✝ : (fun x => ↑(f x)) =ᶠ[ae μ] fun x => ↑(AEMeasurable.mk f hf x)
s : ℕ → Set α
hs : ∀ (n : ℕ), MeasurableSet (s n) ∧ ↑↑μ (s n) < ⊤ ∧ ∀ x ∈ s n, AEMeasurable.mk f hf x ≤ ↑n
h : ⋃ i, s i = univ
i : ℕ
⊢ ↑i ≠ ⊤

Next tactic:
simp
lemma SigmaFinite.withDensity_of_ne_top' [SigmaFinite μ] {f : α → ℝ≥0∞}
    (hf : AEMeasurable f μ) (hf_ne_top : ∀ x, f x ≠ ∞) :
    SigmaFinite (μ.withDensity f) := by
  

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0∞
hf : AEMeasurable f
hf_ne_top : ∀ (x : α), f x ≠ ⊤
⊢ SigmaFinite (Measure.withDensity μ f)

Next tactic:
lift f to (α → ℝ≥0) using hf_ne_top
lemma SigmaFinite.withDensity_of_ne_top' [SigmaFinite μ] {f : α → ℝ≥0∞}
    (hf : AEMeasurable f μ) (hf_ne_top : ∀ x, f x ≠ ∞) :
    SigmaFinite (μ.withDensity f) := by
  lift f to (α → ℝ≥0) using hf_ne_top
  

Proof state:
case intro
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0
hf : AEMeasurable fun i => ↑(f i)
⊢ SigmaFinite (Measure.withDensity μ fun i => ↑(f i))

Next tactic:
rw [aemeasurable_coe_nnreal_ennreal_iff] at hf
lemma SigmaFinite.withDensity_of_ne_top' [SigmaFinite μ] {f : α → ℝ≥0∞}
    (hf : AEMeasurable f μ) (hf_ne_top : ∀ x, f x ≠ ∞) :
    SigmaFinite (μ.withDensity f) := by
  lift f to (α → ℝ≥0) using hf_ne_top
  rw [aemeasurable_coe_nnreal_ennreal_iff] at hf
  

Proof state:
case intro
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0
hf : AEMeasurable fun i => f i
⊢ SigmaFinite (Measure.withDensity μ fun i => ↑(f i))

Next tactic:
exact SigmaFinite.withDensity hf
lemma SigmaFinite.withDensity_of_ne_top [SigmaFinite μ] {f : α → ℝ≥0∞}
    (hf : AEMeasurable f μ) (hf_ne_top : ∀ᵐ x ∂μ, f x ≠ ∞) :
    SigmaFinite (μ.withDensity f) := by
  

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0∞
hf : AEMeasurable f
hf_ne_top : ∀ᵐ (x : α) ∂μ, f x ≠ ⊤
⊢ SigmaFinite (Measure.withDensity μ f)

Next tactic:
let f' := fun x ↦ if f x = ∞ then 0 else f x
lemma SigmaFinite.withDensity_of_ne_top [SigmaFinite μ] {f : α → ℝ≥0∞}
    (hf : AEMeasurable f μ) (hf_ne_top : ∀ᵐ x ∂μ, f x ≠ ∞) :
    SigmaFinite (μ.withDensity f) := by
  let f' := fun x ↦ if f x = ∞ then 0 else f x
  

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0∞
hf : AEMeasurable f
hf_ne_top : ∀ᵐ (x : α) ∂μ, f x ≠ ⊤
f' : α → ℝ≥0∞ := fun x => if f x = ⊤ then 0 else f x
⊢ SigmaFinite (Measure.withDensity μ f)

Next tactic:
have hff' : f =ᵐ[μ] f' := by filter_upwards [hf_ne_top] with x hx using by simp [hx]
lemma SigmaFinite.withDensity_of_ne_top [SigmaFinite μ] {f : α → ℝ≥0∞}
    (hf : AEMeasurable f μ) (hf_ne_top : ∀ᵐ x ∂μ, f x ≠ ∞) :
    SigmaFinite (μ.withDensity f) := by
  let f' := fun x ↦ if f x = ∞ then 0 else f x
  have hff' : f =ᵐ[μ] f' := by 

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0∞
hf : AEMeasurable f
hf_ne_top : ∀ᵐ (x : α) ∂μ, f x ≠ ⊤
f' : α → ℝ≥0∞ := fun x => if f x = ⊤ then 0 else f x
⊢ f =ᶠ[ae μ] f'

Next tactic:
filter_upwards [hf_ne_top] with x hx using by simp [hx]
lemma SigmaFinite.withDensity_of_ne_top [SigmaFinite μ] {f : α → ℝ≥0∞}
    (hf : AEMeasurable f μ) (hf_ne_top : ∀ᵐ x ∂μ, f x ≠ ∞) :
    SigmaFinite (μ.withDensity f) := by
  let f' := fun x ↦ if f x = ∞ then 0 else f x
  have hff' : f =ᵐ[μ] f' := by filter_upwards [hf_ne_top] with x hx using by 

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0∞
hf : AEMeasurable f
hf_ne_top : ∀ᵐ (x : α) ∂μ, f x ≠ ⊤
f' : α → ℝ≥0∞ := fun x => if f x = ⊤ then 0 else f x
x : α
hx : f x ≠ ⊤
⊢ f x = f' x

Next tactic:
simp [hx]
lemma SigmaFinite.withDensity_of_ne_top [SigmaFinite μ] {f : α → ℝ≥0∞}
    (hf : AEMeasurable f μ) (hf_ne_top : ∀ᵐ x ∂μ, f x ≠ ∞) :
    SigmaFinite (μ.withDensity f) := by
  let f' := fun x ↦ if f x = ∞ then 0 else f x
  have hff' : f =ᵐ[μ] f' := by filter_upwards [hf_ne_top] with x hx using by simp [hx]
  

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0∞
hf : AEMeasurable f
hf_ne_top : ∀ᵐ (x : α) ∂μ, f x ≠ ⊤
f' : α → ℝ≥0∞ := fun x => if f x = ⊤ then 0 else f x
hff' : f =ᶠ[ae μ] f'
⊢ SigmaFinite (Measure.withDensity μ f)

Next tactic:
have hf'_ne_top : ∀ x, f' x ≠ ∞ := fun x ↦ by by_cases hfx : f x = ∞ <;> simp [hfx]
lemma SigmaFinite.withDensity_of_ne_top [SigmaFinite μ] {f : α → ℝ≥0∞}
    (hf : AEMeasurable f μ) (hf_ne_top : ∀ᵐ x ∂μ, f x ≠ ∞) :
    SigmaFinite (μ.withDensity f) := by
  let f' := fun x ↦ if f x = ∞ then 0 else f x
  have hff' : f =ᵐ[μ] f' := by filter_upwards [hf_ne_top] with x hx using by simp [hx]
  have hf'_ne_top : ∀ x, f' x ≠ ∞ := fun x ↦ by 

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0∞
hf : AEMeasurable f
hf_ne_top : ∀ᵐ (x : α) ∂μ, f x ≠ ⊤
f' : α → ℝ≥0∞ := fun x => if f x = ⊤ then 0 else f x
hff' : f =ᶠ[ae μ] f'
x : α
⊢ f' x ≠ ⊤

Next tactic:
by_cases hfx : f x = ∞
lemma SigmaFinite.withDensity_of_ne_top [SigmaFinite μ] {f : α → ℝ≥0∞}
    (hf : AEMeasurable f μ) (hf_ne_top : ∀ᵐ x ∂μ, f x ≠ ∞) :
    SigmaFinite (μ.withDensity f) := by
  let f' := fun x ↦ if f x = ∞ then 0 else f x
  have hff' : f =ᵐ[μ] f' := by filter_upwards [hf_ne_top] with x hx using by simp [hx]
  have hf'_ne_top : ∀ x, f' x ≠ ∞ := fun x ↦ by by_cases hfx : f x = ∞ <;> 

Proof state:
case pos
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0∞
hf : AEMeasurable f
hf_ne_top : ∀ᵐ (x : α) ∂μ, f x ≠ ⊤
f' : α → ℝ≥0∞ := fun x => if f x = ⊤ then 0 else f x
hff' : f =ᶠ[ae μ] f'
x : α
hfx : f x = ⊤
⊢ f' x ≠ ⊤

Next tactic:
simp [hfx]
lemma SigmaFinite.withDensity_of_ne_top [SigmaFinite μ] {f : α → ℝ≥0∞}
    (hf : AEMeasurable f μ) (hf_ne_top : ∀ᵐ x ∂μ, f x ≠ ∞) :
    SigmaFinite (μ.withDensity f) := by
  let f' := fun x ↦ if f x = ∞ then 0 else f x
  have hff' : f =ᵐ[μ] f' := by filter_upwards [hf_ne_top] with x hx using by simp [hx]
  have hf'_ne_top : ∀ x, f' x ≠ ∞ := fun x ↦ by by_cases hfx : f x = ∞ <;> 

Proof state:
case neg
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0∞
hf : AEMeasurable f
hf_ne_top : ∀ᵐ (x : α) ∂μ, f x ≠ ⊤
f' : α → ℝ≥0∞ := fun x => if f x = ⊤ then 0 else f x
hff' : f =ᶠ[ae μ] f'
x : α
hfx : ¬f x = ⊤
⊢ f' x ≠ ⊤

Next tactic:
simp [hfx]
lemma SigmaFinite.withDensity_of_ne_top [SigmaFinite μ] {f : α → ℝ≥0∞}
    (hf : AEMeasurable f μ) (hf_ne_top : ∀ᵐ x ∂μ, f x ≠ ∞) :
    SigmaFinite (μ.withDensity f) := by
  let f' := fun x ↦ if f x = ∞ then 0 else f x
  have hff' : f =ᵐ[μ] f' := by filter_upwards [hf_ne_top] with x hx using by simp [hx]
  have hf'_ne_top : ∀ x, f' x ≠ ∞ := fun x ↦ by by_cases hfx : f x = ∞ <;> simp [hfx]
  

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0∞
hf : AEMeasurable f
hf_ne_top : ∀ᵐ (x : α) ∂μ, f x ≠ ⊤
f' : α → ℝ≥0∞ := fun x => if f x = ⊤ then 0 else f x
hff' : f =ᶠ[ae μ] f'
hf'_ne_top : ∀ (x : α), f' x ≠ ⊤
⊢ SigmaFinite (Measure.withDensity μ f)

Next tactic:
rw [withDensity_congr_ae hff']
lemma SigmaFinite.withDensity_of_ne_top [SigmaFinite μ] {f : α → ℝ≥0∞}
    (hf : AEMeasurable f μ) (hf_ne_top : ∀ᵐ x ∂μ, f x ≠ ∞) :
    SigmaFinite (μ.withDensity f) := by
  let f' := fun x ↦ if f x = ∞ then 0 else f x
  have hff' : f =ᵐ[μ] f' := by filter_upwards [hf_ne_top] with x hx using by simp [hx]
  have hf'_ne_top : ∀ x, f' x ≠ ∞ := fun x ↦ by by_cases hfx : f x = ∞ <;> simp [hfx]
  rw [withDensity_congr_ae hff']
  

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ≥0∞
hf : AEMeasurable f
hf_ne_top : ∀ᵐ (x : α) ∂μ, f x ≠ ⊤
f' : α → ℝ≥0∞ := fun x => if f x = ⊤ then 0 else f x
hff' : f =ᶠ[ae μ] f'
hf'_ne_top : ∀ (x : α), f' x ≠ ⊤
⊢ SigmaFinite (Measure.withDensity μ f')

Next tactic:
exact SigmaFinite.withDensity_of_ne_top' (hf.congr hff') hf'_ne_top
lemma SigmaFinite.withDensity_ofReal [SigmaFinite μ] {f : α → ℝ} (hf : AEMeasurable f μ) :
    SigmaFinite (μ.withDensity (fun x ↦ ENNReal.ofReal (f x))) := by
  

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ
hf : AEMeasurable f
⊢ SigmaFinite (Measure.withDensity μ fun x => ENNReal.ofReal (f x))

Next tactic:
refine SigmaFinite.withDensity_of_ne_top hf.ennreal_ofReal (ae_of_all _ (by simp))
lemma SigmaFinite.withDensity_ofReal [SigmaFinite μ] {f : α → ℝ} (hf : AEMeasurable f μ) :
    SigmaFinite (μ.withDensity (fun x ↦ ENNReal.ofReal (f x))) := by
  refine SigmaFinite.withDensity_of_ne_top hf.ennreal_ofReal (ae_of_all _ (by 

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝ : SigmaFinite μ
f : α → ℝ
hf : AEMeasurable f
⊢ ∀ (a : α), ENNReal.ofReal (f a) ≠ ⊤

Next tactic:
simp
lemma IsLocallyFiniteMeasure.withDensity_coe {f : α → ℝ≥0} (hf : Continuous f) :
    IsLocallyFiniteMeasure (μ.withDensity fun x ↦ f x) := by
  

Proof state:
α : Type u_1
m0 : MeasurableSpace α
μ : Measure α
inst✝² : TopologicalSpace α
inst✝¹ : OpensMeasurableSpace α
inst✝ : IsLocallyFiniteMeasure μ
f : α → ℝ≥0
hf : Continuous f
⊢ IsLocallyFiniteMeasure (withDensity μ fun x => ↑(f x))

Next tactic:
refine ⟨fun x ↦ ?_⟩