-- Mathlib/MeasureTheory/Integral/SetIntegral.lean
theorem Filter.Tendsto.integral_sub_linear_isLittleO_ae
    {μ : Measure X} {l : Filter X} [l.IsMeasurablyGenerated] {f : X → E} {b : E}
    (h : Tendsto f (l ⊓ ae μ) (𝓝 b)) (hfm : StronglyMeasurableAtFilter f l μ)
    (hμ : μ.FiniteAtFilter l) {s : ι → Set X} {li : Filter ι} (hs : Tendsto s li l.smallSets)
    (m : ι → ℝ := fun i => (μ (s i)).toReal)
    (hsμ : (fun i => (μ (s i)).toReal) =ᶠ[li] m

Proof state:
case h
X : Type u_1
E : Type u_3
inst✝⁴ : MeasurableSpace X
ι : Type u_5
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure X
l : Filter X
inst✝ : l.IsMeasurablyGenerated
f : X → E
b : E
h : Tendsto f (l ⊓ ae μ) (𝓝 b)
hfm : StronglyMeasurableAtFilter f l μ
hμ : μ.FiniteAtFilter l
s : ι → Set X
li : Filter ι
hs : Tendsto s li l.smallSets
m : optParam (ι → ℝ) fun i => (μ (s i)).toReal
hsμ : autoParam ((fun i => (μ (s i)).toReal) =ᶠ[li] m) _auto✝
ε : ℝ
ε₀ : 0 < ε
this : ∀ᶠ (s : Set X) in l.smallSets, ∀ᵐ (x : X) ∂μ, x ∈ s → f x ∈ closedBall b ε
⊢ ∀ (a : Set X),
    μ a < ⊤ →
      IntegrableOn f a μ →
        AEStronglyMeasurable f (μ.restrict a) →
          (∀ᵐ (x : X) ∂μ, x ∈ a → ‖f x - b‖ ≤ ε) → ‖∫ (x : X) in a, f x ∂μ - (μ a).toReal • b‖ ≤ ε * ‖(μ a).toReal‖

Tactic:
intro s hμs h_integrable hfm h_norm

Result:
case h
X : Type u_1
E : Type u_3
inst✝⁴ : MeasurableSpace X
ι : Type u_5
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure X
l : Filter X
inst✝ : l.IsMeasurablyGenerated
f : X → E
b : E
h : Tendsto f (l ⊓ ae μ) (𝓝 b)
hfm✝ : StronglyMeasurableAtFilter f l μ
hμ : μ.FiniteAtFilter l
s✝ : ι → Set X
li : Filter ι
hs : Tendsto s✝ li l.smallSets
m : optParam (ι → ℝ) fun i => (μ (s✝ i)).toReal
hsμ : autoParam ((fun i => (μ (s✝ i)).toReal) =ᶠ[li] m) _auto✝
ε : ℝ
ε₀ : 0 < ε
this : ∀ᶠ (s : Set X) in l.smallSets, ∀ᵐ (x : X) ∂μ, x ∈ s → f x ∈ closedBall b ε
s : Set X
hμs : μ s < ⊤
h_integrable : IntegrableOn f s μ
hfm : AEStronglyMeasurable f (μ.restrict s)
h_norm : ∀ᵐ (x : X) ∂μ, x ∈ s → ‖f x - b‖ ≤ ε
⊢ ‖∫ (x : X) in s, f x ∂μ - (μ s).toReal • b‖ ≤ ε * ‖(μ s).toReal‖

Proof state:
case h
X : Type u_1
E : Type u_3
inst✝⁴ : MeasurableSpace X
ι : Type u_5
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure X
l : Filter X
inst✝ : l.IsMeasurablyGenerated
f : X → E
b : E
h : Tendsto f (l ⊓ ae μ) (𝓝 b)
hfm✝ : StronglyMeasurableAtFilter f l μ
hμ : μ.FiniteAtFilter l
s✝ : ι → Set X
li : Filter ι
hs : Tendsto s✝ li l.smallSets
m : optParam (ι → ℝ) fun i => (μ (s✝ i)).toReal
hsμ : autoParam ((fun i => (μ (s✝ i)).toReal) =ᶠ[li] m) _auto✝
ε : ℝ
ε₀ : 0 < ε
this : ∀ᶠ (s : Set X) in l.smallSets, ∀ᵐ (x : X) ∂μ, x ∈ s → f x ∈ closedBall b ε
s : Set X
hμs : μ s < ⊤
h_integrable : IntegrableOn f s μ
hfm : AEStronglyMeasurable f (μ.restrict s)
h_norm : ∀ᵐ (x : X) ∂μ, x ∈ s → ‖f x - b‖ ≤ ε
⊢ ‖∫ (a : X) in s, f a - b ∂μ‖ ≤ ε * (μ s).toReal

Tactic:
exact norm_setIntegral_le_of_norm_le_const_ae' hμs h_norm (hfm.sub aestronglyMeasurable_const)

Result:
no goals

Proof state:
X : Type u_1
E : Type u_3
inst✝⁴ : MeasurableSpace X
ι : Type u_5
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure X
l : Filter X
inst✝ : l.IsMeasurablyGenerated
f : X → E
b : E
h : Tendsto f (l ⊓ ae μ) (𝓝 b)
hfm : StronglyMeasurableAtFilter f l μ
hμ : μ.FiniteAtFilter l
s : ι → Set X
li : Filter ι
hs : Tendsto s li l.smallSets
m : optParam (ι → ℝ) fun i => (μ (s i)).toReal
hsμ : autoParam ((fun i => (μ (s i)).toReal) =ᶠ[li] m) _auto✝
⊢ (fun s => ∫ (x : X) in s, f x ∂μ - (μ s).toReal • b) =o[l.smallSets] fun s => (μ s).toReal

Tactic:
refine isLittleO_iff.2 fun ε ε₀ => ?_

Result:
X : Type u_1
E : Type u_3
inst✝⁴ : MeasurableSpace X
ι : Type u_5
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure X
l : Filter X
inst✝ : l.IsMeasurablyGenerated
f : X → E
b : E
h : Tendsto f (l ⊓ ae μ) (𝓝 b)
hfm : StronglyMeasurableAtFilter f l μ
hμ : μ.FiniteAtFilter l
s : ι → Set X
li : Filter ι
hs : Tendsto s li l.smallSets
m : optParam (ι → ℝ) fun i => (μ (s i)).toReal
hsμ : autoParam ((fun i => (μ (s i)).toReal) =ᶠ[li] m) _auto✝
ε : ℝ
ε₀ : 0 < ε
⊢ ∀ᶠ (x : Set X) in l.smallSets, ‖∫ (x : X) in x, f x ∂μ - (μ x).toReal • b‖ ≤ ε * ‖(μ x).toReal‖

Proof state:
case h
X : Type u_1
E : Type u_3
inst✝⁴ : MeasurableSpace X
ι : Type u_5
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure X
l : Filter X
inst✝ : l.IsMeasurablyGenerated
f : X → E
b : E
h : Tendsto f (l ⊓ ae μ) (𝓝 b)
hfm✝ : StronglyMeasurableAtFilter f l μ
hμ : μ.FiniteAtFilter l
s✝ : ι → Set X
li : Filter ι
hs : Tendsto s✝ li l.smallSets
m : optParam (ι → ℝ) fun i => (μ (s✝ i)).toReal
hsμ : autoParam ((fun i => (μ (s✝ i)).toReal) =ᶠ[li] m) _auto✝
ε : ℝ
ε₀ : 0 < ε
this : ∀ᶠ (s : Set X) in l.smallSets, ∀ᵐ (x : X) ∂μ, x ∈ s → f x ∈ closedBall b ε
s : Set X
hμs : μ s < ⊤
h_integrable : IntegrableOn f s μ
hfm : AEStronglyMeasurable f (μ.restrict s)
h_norm : ∀ᵐ (x : X) ∂μ, x ∈ s → ‖f x - b‖ ≤ ε
⊢ ‖∫ (x : X) in s, f x ∂μ - (μ s).toReal • b‖ ≤ ε * ‖(μ s).toReal‖

Tactic:
rw [← setIntegral_const, ← integral_sub h_integrable (integrableOn_const.2 <| Or.inr hμs),
  Real.norm_eq_abs, abs_of_nonneg ENNReal.toReal_nonneg]

Result:
case h
X : Type u_1
E : Type u_3
inst✝⁴ : MeasurableSpace X
ι : Type u_5
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure X
l : Filter X
inst✝ : l.IsMeasurablyGenerated
f : X → E
b : E
h : Tendsto f (l ⊓ ae μ) (𝓝 b)
hfm✝ : StronglyMeasurableAtFilter f l μ
hμ : μ.FiniteAtFilter l
s✝ : ι → Set X
li : Filter ι
hs : Tendsto s✝ li l.smallSets
m : optParam (ι → ℝ) fun i => (μ (s✝ i)).toReal
hsμ : autoParam ((fun i => (μ (s✝ i)).toReal) =ᶠ[li] m) _auto✝
ε : ℝ
ε₀ : 0 < ε
this : ∀ᶠ (s : Set X) in l.smallSets, ∀ᵐ (x : X) ∂μ, x ∈ s → f x ∈ closedBall b ε
s : Set X
hμs : μ s < ⊤
h_integrable : IntegrableOn f s μ
hfm : AEStronglyMeasurable f (μ.restrict s)
h_norm : ∀ᵐ (x : X) ∂μ, x ∈ s → ‖f x - b‖ ≤ ε
⊢ ‖∫ (a : X) in s, f a - b ∂μ‖ ≤ ε * (μ s).toReal

Proof state:
X : Type u_1
E : Type u_3
inst✝⁴ : MeasurableSpace X
ι : Type u_5
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure X
l : Filter X
inst✝ : l.IsMeasurablyGenerated
f : X → E
b : E
h : Tendsto f (l ⊓ ae μ) (𝓝 b)
hfm : StronglyMeasurableAtFilter f l μ
hμ : μ.FiniteAtFilter l
s : ι → Set X
li : Filter ι
hs : Tendsto s li l.smallSets
m : optParam (ι → ℝ) fun i => (μ (s i)).toReal
hsμ : autoParam ((fun i => (μ (s i)).toReal) =ᶠ[li] m) _auto✝
ε : ℝ
ε₀ : 0 < ε
⊢ ∀ᶠ (x : Set X) in l.smallSets, ‖∫ (x : X) in x, f x ∂μ - (μ x).toReal • b‖ ≤ ε * ‖(μ x).toReal‖

Tactic:
have : ∀ᶠ s in l.smallSets, ∀ᵐ x ∂μ, x ∈ s → f x ∈ closedBall b ε :=
  eventually_smallSets_eventually.2 (h.eventually <| closedBall_mem_nhds _ ε₀)

Result:
X : Type u_1
E : Type u_3
inst✝⁴ : MeasurableSpace X
ι : Type u_5
inst✝³ : NormedAddCommGroup E
inst✝² : NormedSpace ℝ E
inst✝¹ : CompleteSpace E
μ : Measure X
l : Filter X
inst✝ : l.IsMeasurablyGenerated
f : X → E
b : E
h : Tendsto f (l ⊓ ae μ) (𝓝 b)
hfm : StronglyMeasurableAtFilter f l μ
hμ : μ.FiniteAtFilter l
s : ι → Set X
li : Filter ι
hs : Tendsto s li l.smallSets
m : optParam (ι → ℝ) fun i => (μ (s i)).toReal
hsμ : autoParam ((fun i => (μ (s i)).toReal) =ᶠ[li] m) _auto✝
ε : ℝ
ε₀ : 0 < ε
this : ∀ᶠ (s : Set X) in l.smallSets, ∀ᵐ (x : X) ∂μ, x ∈ s → f x ∈ closedBall b ε
⊢ ∀ᶠ (x : Set X) in l.smallSets, ‖∫ (x : X) in x, f x ∂μ - (μ x).toReal • b‖ ≤ ε * ‖(μ x).toReal‖