-- 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:
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✝
this : (fun s => ∫ (x : X) in s, f x ∂μ - (μ s).toReal • b) =o[l.smallSets] fun s => (μ s).toReal
a : ι
ha : (fun i => (μ (s i)).toReal) a = m a
⊢ ((fun s => ∫ (x : X) in s, f x ∂μ - (μ s).toReal • b) ∘ s) a = (fun i => ∫ (x : X) in s i, f x ∂μ - m i • b) a

Tactic:
dsimp only [Function.comp_apply] at ha ⊢

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✝
this : (fun s => ∫ (x : X) in s, f x ∂μ - (μ s).toReal • b) =o[l.smallSets] fun s => (μ s).toReal
a : ι
ha : (μ (s a)).toReal = m a
⊢ ∫ (x : X) in s a, f x ∂μ - (μ (s a)).toReal • b = ∫ (x : X) in s a, f x ∂μ - m a • b

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 ∈ closedBall b ε) →
            ‖∫ (x : X) in a, f x ∂μ - (μ a).toReal • b‖ ≤ ε * ‖(μ a).toReal‖

Tactic:
simp only [mem_closedBall, dist_eq_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 ε
⊢ ∀ (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‖

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✝
this : (fun s => ∫ (x : X) in s, f x ∂μ - (μ s).toReal • b) =o[l.smallSets] fun s => (μ s).toReal
a : ι
ha : (μ (s a)).toReal = m a
⊢ ∫ (x : X) in s a, f x ∂μ - (μ (s a)).toReal • b = ∫ (x : X) in s a, f x ∂μ - m a • b

Tactic:
rw [ha]

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 i => ∫ (x : X) in s i, f x ∂μ - m i • b) =o[li] m

Tactic:
suffices
    (fun s => (∫ x in s, f x ∂μ) - (μ s).toReal • b) =o[l.smallSets] fun s => (μ s).toReal from
  (this.comp_tendsto hs).congr'
    (hsμ.mono fun a ha => by dsimp only [Function.comp_apply] at ha ⊢; rw [ha]) hsμ

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✝
⊢ (fun s => ∫ (x : X) in s, f x ∂μ - (μ s).toReal • b) =o[l.smallSets] fun s => (μ 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 < ε
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‖

Tactic:
filter_upwards [hμ.eventually, (hμ.integrableAtFilter_of_tendsto_ae hfm h).eventually,
  hfm.eventually, this]

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 ε
⊢ ∀ (a : Set X),
    μ a < ⊤ →
      IntegrableOn f a μ →
        AEStronglyMeasurable f (μ.restrict a) →
          (∀ᵐ (x : X) ∂μ, x ∈ a → f x ∈ closedBall b ε) →
            ‖∫ (x : X) in a, f x ∂μ - (μ a).toReal • b‖ ≤ ε * ‖(μ a).toReal‖