l3lab/ntp-mathlib huggingface dataset:
/-- Continuous linear map sending a function of `Lp F p μ` to the same function in
`Lp F p (μ.restrict s)`. -/
def LpToLpRestrictCLM (μ : Measure α) (p : ℝ≥0∞) [hp : Fact (1 ≤ p)] (s : Set α) :
    Lp F p μ →L[𝕜] Lp F p (μ.restrict s) :=
  @LinearMap.mkContinuous 𝕜 𝕜 (Lp F p μ) (Lp F p (μ.restrict s)) _ _ _ _ _ _ (RingHom.id 𝕜)
    ⟨⟨fun f => Memℒp.toLp f ((Lp.memℒp f).restrict s), fun f g => Lp_toLp_restrict_add f g s⟩,
      fun c f => Lp_toLp_restrict_smul c f s⟩
    1 (by intro f; rw [one_mul]; 

Proof state:
α : Type u_1
β : Type u_2
E : Type u_3
F : Type u_4
inst✝⁴ : MeasurableSpace α
inst✝³ : NormedAddCommGroup E
𝕜 : Type u_5
inst✝² : NormedField 𝕜
inst✝¹ : NormedAddCommGroup F
inst✝ : NormedSpace 𝕜 F
p✝ : ℝ≥0∞
μ✝ μ : Measure α
p : ℝ≥0∞
hp : Fact (1 ≤ p)
s : Set α
f : ↥(Lp F p)
⊢ ‖{
          toAddHom :=
            { toFun := fun f => Memℒp.toLp ↑↑f (_ : Memℒp (↑↑f) p),
              map_add' :=
                (_ :
                  ∀ (f g : ↥(Lp F p)),
                    Memℒp.toLp ↑↑(f + g) (_ : Memℒp (↑↑(f + g)) p) =
                      Memℒp.toLp ↑↑f (_ : Memℒp (↑↑f) p) + Memℒp.toLp ↑↑g (_ : Memℒp (↑↑g) p)) },
          map_smul' :=
            (_ :
              ∀ (c : 𝕜) (f : ↥(Lp F p)),
                Memℒp.toLp ↑↑(c • f) (_ : Memℒp (↑↑(c • f)) p) = c • Memℒp.toLp ↑↑f (_ : Memℒp (↑↑f) p)) }
        f‖ ≤
    ‖f‖

Next tactic:
exact norm_Lp_toLp_restrict_le s f
@[continuity]
theorem continuous_set_integral [NormedSpace ℝ E] (s : Set α) :
    Continuous fun f : α →₁[μ] E => ∫ x in s, f x ∂μ := by
  

Proof state:
α : Type u_1
β : Type u_2
E : Type u_3
F : Type u_4
inst✝⁵ : MeasurableSpace α
inst✝⁴ : NormedAddCommGroup E
𝕜 : Type u_5
inst✝³ : NormedField 𝕜
inst✝² : NormedAddCommGroup F
inst✝¹ : NormedSpace 𝕜 F
p : ℝ≥0∞
μ : Measure α
inst✝ : NormedSpace ℝ E
s : Set α
⊢ Continuous fun f => ∫ (x : α) in s, ↑↑f x ∂μ

Next tactic:
haveI : Fact ((1 : ℝ≥0∞) ≤ 1) := ⟨le_rfl⟩
@[continuity]
theorem continuous_set_integral [NormedSpace ℝ E] (s : Set α) :
    Continuous fun f : α →₁[μ] E => ∫ x in s, f x ∂μ := by
  haveI : Fact ((1 : ℝ≥0∞) ≤ 1) := ⟨le_rfl⟩
  

Proof state:
α : Type u_1
β : Type u_2
E : Type u_3
F : Type u_4
inst✝⁵ : MeasurableSpace α
inst✝⁴ : NormedAddCommGroup E
𝕜 : Type u_5
inst✝³ : NormedField 𝕜
inst✝² : NormedAddCommGroup F
inst✝¹ : NormedSpace 𝕜 F
p : ℝ≥0∞
μ : Measure α
inst✝ : NormedSpace ℝ E
s : Set α
this : Fact (1 ≤ 1)
⊢ Continuous fun f => ∫ (x : α) in s, ↑↑f x ∂μ

Next tactic:
have h_comp :
    (fun f : α →₁[μ] E => ∫ x in s, f x ∂μ) =
      integral (μ.restrict s) ∘ fun f => LpToLpRestrictCLM α E ℝ μ 1 s f := by
    ext1 f
    rw [Function.comp_apply, integral_congr_ae (LpToLpRestrictCLM_coeFn ℝ s f)]
@[continuity]
theorem continuous_set_integral [NormedSpace ℝ E] (s : Set α) :
    Continuous fun f : α →₁[μ] E => ∫ x in s, f x ∂μ := by
  haveI : Fact ((1 : ℝ≥0∞) ≤ 1) := ⟨le_rfl⟩
  have h_comp :
    (fun f : α →₁[μ] E => ∫ x in s, f x ∂μ) =
      integral (μ.restrict s) ∘ fun f => LpToLpRestrictCLM α E ℝ μ 1 s f := by
    

Proof state:
α : Type u_1
β : Type u_2
E : Type u_3
F : Type u_4
inst✝⁵ : MeasurableSpace α
inst✝⁴ : NormedAddCommGroup E
𝕜 : Type u_5
inst✝³ : NormedField 𝕜
inst✝² : NormedAddCommGroup F
inst✝¹ : NormedSpace 𝕜 F
p : ℝ≥0∞
μ : Measure α
inst✝ : NormedSpace ℝ E
s : Set α
this : Fact (1 ≤ 1)
⊢ (fun f => ∫ (x : α) in s, ↑↑f x ∂μ) = integral (Measure.restrict μ s) ∘ fun f => ↑↑((LpToLpRestrictCLM α E ℝ μ 1 s) f)

Next tactic:
ext1 f
@[continuity]
theorem continuous_set_integral [NormedSpace ℝ E] (s : Set α) :
    Continuous fun f : α →₁[μ] E => ∫ x in s, f x ∂μ := by
  haveI : Fact ((1 : ℝ≥0∞) ≤ 1) := ⟨le_rfl⟩
  have h_comp :
    (fun f : α →₁[μ] E => ∫ x in s, f x ∂μ) =
      integral (μ.restrict s) ∘ fun f => LpToLpRestrictCLM α E ℝ μ 1 s f := by
    ext1 f
    

Proof state:
case h
α : Type u_1
β : Type u_2
E : Type u_3
F : Type u_4
inst✝⁵ : MeasurableSpace α
inst✝⁴ : NormedAddCommGroup E
𝕜 : Type u_5
inst✝³ : NormedField 𝕜
inst✝² : NormedAddCommGroup F
inst✝¹ : NormedSpace 𝕜 F
p : ℝ≥0∞
μ : Measure α
inst✝ : NormedSpace ℝ E
s : Set α
this : Fact (1 ≤ 1)
f : ↥(Lp E 1)
⊢ ∫ (x : α) in s, ↑↑f x ∂μ = (integral (Measure.restrict μ s) ∘ fun f => ↑↑((LpToLpRestrictCLM α E ℝ μ 1 s) f)) f

Next tactic:
rw [Function.comp_apply, integral_congr_ae (LpToLpRestrictCLM_coeFn ℝ s f)]
@[continuity]
theorem continuous_set_integral [NormedSpace ℝ E] (s : Set α) :
    Continuous fun f : α →₁[μ] E => ∫ x in s, f x ∂μ := by
  haveI : Fact ((1 : ℝ≥0∞) ≤ 1) := ⟨le_rfl⟩
  have h_comp :
    (fun f : α →₁[μ] E => ∫ x in s, f x ∂μ) =
      integral (μ.restrict s) ∘ fun f => LpToLpRestrictCLM α E ℝ μ 1 s f := by
    ext1 f
    rw [Function.comp_apply, integral_congr_ae (LpToLpRestrictCLM_coeFn ℝ s f)]
  

Proof state:
α : Type u_1
β : Type u_2
E : Type u_3
F : Type u_4
inst✝⁵ : MeasurableSpace α
inst✝⁴ : NormedAddCommGroup E
𝕜 : Type u_5
inst✝³ : NormedField 𝕜
inst✝² : NormedAddCommGroup F
inst✝¹ : NormedSpace 𝕜 F
p : ℝ≥0∞
μ : Measure α
inst✝ : NormedSpace ℝ E
s : Set α
this : Fact (1 ≤ 1)
h_comp :
  (fun f => ∫ (x : α) in s, ↑↑f x ∂μ) = integral (Measure.restrict μ s) ∘ fun f => ↑↑((LpToLpRestrictCLM α E ℝ μ 1 s) f)
⊢ Continuous fun f => ∫ (x : α) in s, ↑↑f x ∂μ

Next tactic:
rw [h_comp]
@[continuity]
theorem continuous_set_integral [NormedSpace ℝ E] (s : Set α) :
    Continuous fun f : α →₁[μ] E => ∫ x in s, f x ∂μ := by
  haveI : Fact ((1 : ℝ≥0∞) ≤ 1) := ⟨le_rfl⟩
  have h_comp :
    (fun f : α →₁[μ] E => ∫ x in s, f x ∂μ) =
      integral (μ.restrict s) ∘ fun f => LpToLpRestrictCLM α E ℝ μ 1 s f := by
    ext1 f
    rw [Function.comp_apply, integral_congr_ae (LpToLpRestrictCLM_coeFn ℝ s f)]
  rw [h_comp]
  

Proof state:
α : Type u_1
β : Type u_2
E : Type u_3
F : Type u_4
inst✝⁵ : MeasurableSpace α
inst✝⁴ : NormedAddCommGroup E
𝕜 : Type u_5
inst✝³ : NormedField 𝕜
inst✝² : NormedAddCommGroup F
inst✝¹ : NormedSpace 𝕜 F
p : ℝ≥0∞
μ : Measure α
inst✝ : NormedSpace ℝ E
s : Set α
this : Fact (1 ≤ 1)
h_comp :
  (fun f => ∫ (x : α) in s, ↑↑f x ∂μ) = integral (Measure.restrict μ s) ∘ fun f => ↑↑((LpToLpRestrictCLM α E ℝ μ 1 s) f)
⊢ Continuous (integral (Measure.restrict μ s) ∘ fun f => ↑↑((LpToLpRestrictCLM α E ℝ μ 1 s) f))

Next tactic:
exact continuous_integral.comp (LpToLpRestrictCLM α E ℝ μ 1 s).continuous
/-- Fundamental theorem of calculus for set integrals:
if `μ` is a measure that is finite at a filter `l` and
`f` is a measurable function that has a finite limit `b` at `l ⊓ μ.ae`, then
`∫ x in s i, f x ∂μ = μ (s i) • b + o(μ (s i))` at a filter `li` provided that
`s i` tends to `l.smallSets` along `li`.
Since `μ (s i)` is an `ℝ≥0∞` number, we use `(μ (s i)).toReal` in the actual statement.

Often there is a good formula for `(μ (s i)).toReal`, so the formalization can take an optional
argument `m` with this formula and a proof of `(fun i => (μ (s i)).toReal) =ᶠ[li] m`. Without these
arguments, `m i = (μ (s i)).toReal` is used in the output. -/
theorem Filter.Tendsto.integral_sub_linear_isLittleO_ae [NormedSpace ℝ E] [CompleteSpace E]
    {μ : Measure α} {l : Filter α} [l.IsMeasurablyGenerated] {f : α → E} {b : E}
    (h : Tendsto f (l ⊓ μ.ae) (𝓝 b)) (hfm : StronglyMeasurableAtFilter f l μ)
    (hμ : μ.FiniteAtFilter l) {s : ι → Set α} {li : Filter ι} (hs : Tendsto s li l.smallSets)
    (m : ι → ℝ := fun i => (μ (s i)).toReal)
    (hsμ : (fun i => (μ (s i)).toReal) =ᶠ[li] m := by rfl) :
    (fun i => (∫ x in s i, f x ∂μ) - m i • b) =o[li] m := by
  

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

Next 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μ
/-- Fundamental theorem of calculus for set integrals:
if `μ` is a measure that is finite at a filter `l` and
`f` is a measurable function that has a finite limit `b` at `l ⊓ μ.ae`, then
`∫ x in s i, f x ∂μ = μ (s i) • b + o(μ (s i))` at a filter `li` provided that
`s i` tends to `l.smallSets` along `li`.
Since `μ (s i)` is an `ℝ≥0∞` number, we use `(μ (s i)).toReal` in the actual statement.

Often there is a good formula for `(μ (s i)).toReal`, so the formalization can take an optional
argument `m` with this formula and a proof of `(fun i => (μ (s i)).toReal) =ᶠ[li] m`. Without these
arguments, `m i = (μ (s i)).toReal` is used in the output. -/
theorem Filter.Tendsto.integral_sub_linear_isLittleO_ae [NormedSpace ℝ E] [CompleteSpace E]
    {μ : Measure α} {l : Filter α} [l.IsMeasurablyGenerated] {f : α → E} {b : E}
    (h : Tendsto f (l ⊓ μ.ae) (𝓝 b)) (hfm : StronglyMeasurableAtFilter f l μ)
    (hμ : μ.FiniteAtFilter l) {s : ι → Set α} {li : Filter ι} (hs : Tendsto s li l.smallSets)
    (m : ι → ℝ := fun i => (μ (s i)).toReal)
    (hsμ : (fun i => (μ (s i)).toReal) =ᶠ[li] m := by rfl) :
    (fun i => (∫ x in s i, f x ∂μ) - m i • b) =o[li] m := by
  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 

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

Next tactic:
dsimp only [Function.comp_apply] at ha ⊢
/-- Fundamental theorem of calculus for set integrals:
if `μ` is a measure that is finite at a filter `l` and
`f` is a measurable function that has a finite limit `b` at `l ⊓ μ.ae`, then
`∫ x in s i, f x ∂μ = μ (s i) • b + o(μ (s i))` at a filter `li` provided that
`s i` tends to `l.smallSets` along `li`.
Since `μ (s i)` is an `ℝ≥0∞` number, we use `(μ (s i)).toReal` in the actual statement.

Often there is a good formula for `(μ (s i)).toReal`, so the formalization can take an optional
argument `m` with this formula and a proof of `(fun i => (μ (s i)).toReal) =ᶠ[li] m`. Without these
arguments, `m i = (μ (s i)).toReal` is used in the output. -/
theorem Filter.Tendsto.integral_sub_linear_isLittleO_ae [NormedSpace ℝ E] [CompleteSpace E]
    {μ : Measure α} {l : Filter α} [l.IsMeasurablyGenerated] {f : α → E} {b : E}
    (h : Tendsto f (l ⊓ μ.ae) (𝓝 b)) (hfm : StronglyMeasurableAtFilter f l μ)
    (hμ : μ.FiniteAtFilter l) {s : ι → Set α} {li : Filter ι} (hs : Tendsto s li l.smallSets)
    (m : ι → ℝ := fun i => (μ (s i)).toReal)
    (hsμ : (fun i => (μ (s i)).toReal) =ᶠ[li] m := by rfl) :
    (fun i => (∫ x in s i, f x ∂μ) - m i • b) =o[li] m := by
  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 ⊢; 

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

Next tactic:
rw [ha]
/-- Fundamental theorem of calculus for set integrals:
if `μ` is a measure that is finite at a filter `l` and
`f` is a measurable function that has a finite limit `b` at `l ⊓ μ.ae`, then
`∫ x in s i, f x ∂μ = μ (s i) • b + o(μ (s i))` at a filter `li` provided that
`s i` tends to `l.smallSets` along `li`.
Since `μ (s i)` is an `ℝ≥0∞` number, we use `(μ (s i)).toReal` in the actual statement.

Often there is a good formula for `(μ (s i)).toReal`, so the formalization can take an optional
argument `m` with this formula and a proof of `(fun i => (μ (s i)).toReal) =ᶠ[li] m`. Without these
arguments, `m i = (μ (s i)).toReal` is used in the output. -/
theorem Filter.Tendsto.integral_sub_linear_isLittleO_ae [NormedSpace ℝ E] [CompleteSpace E]
    {μ : Measure α} {l : Filter α} [l.IsMeasurablyGenerated] {f : α → E} {b : E}
    (h : Tendsto f (l ⊓ μ.ae) (𝓝 b)) (hfm : StronglyMeasurableAtFilter f l μ)
    (hμ : μ.FiniteAtFilter l) {s : ι → Set α} {li : Filter ι} (hs : Tendsto s li l.smallSets)
    (m : ι → ℝ := fun i => (μ (s i)).toReal)
    (hsμ : (fun i => (μ (s i)).toReal) =ᶠ[li] m := by rfl) :
    (fun i => (∫ x in s i, f x ∂μ) - m i • b) =o[li] m := by
  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μ
  

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

Next tactic:
refine' isLittleO_iff.2 fun ε ε₀ => _
/-- Fundamental theorem of calculus for set integrals:
if `μ` is a measure that is finite at a filter `l` and
`f` is a measurable function that has a finite limit `b` at `l ⊓ μ.ae`, then
`∫ x in s i, f x ∂μ = μ (s i) • b + o(μ (s i))` at a filter `li` provided that
`s i` tends to `l.smallSets` along `li`.
Since `μ (s i)` is an `ℝ≥0∞` number, we use `(μ (s i)).toReal` in the actual statement.

Often there is a good formula for `(μ (s i)).toReal`, so the formalization can take an optional
argument `m` with this formula and a proof of `(fun i => (μ (s i)).toReal) =ᶠ[li] m`. Without these
arguments, `m i = (μ (s i)).toReal` is used in the output. -/
theorem Filter.Tendsto.integral_sub_linear_isLittleO_ae [NormedSpace ℝ E] [CompleteSpace E]
    {μ : Measure α} {l : Filter α} [l.IsMeasurablyGenerated] {f : α → E} {b : E}
    (h : Tendsto f (l ⊓ μ.ae) (𝓝 b)) (hfm : StronglyMeasurableAtFilter f l μ)
    (hμ : μ.FiniteAtFilter l) {s : ι → Set α} {li : Filter ι} (hs : Tendsto s li l.smallSets)
    (m : ι → ℝ := fun i => (μ (s i)).toReal)
    (hsμ : (fun i => (μ (s i)).toReal) =ᶠ[li] m := by rfl) :
    (fun i => (∫ x in s i, f x ∂μ) - m i • b) =o[li] m := by
  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μ
  refine' isLittleO_iff.2 fun ε ε₀ => _
  

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

Next tactic:
have : ∀ᶠ s in l.smallSets, ∀ᶠ x in μ.ae, x ∈ s → f x ∈ closedBall b ε :=
    eventually_smallSets_eventually.2 (h.eventually <| closedBall_mem_nhds _ ε₀)
/-- Fundamental theorem of calculus for set integrals:
if `μ` is a measure that is finite at a filter `l` and
`f` is a measurable function that has a finite limit `b` at `l ⊓ μ.ae`, then
`∫ x in s i, f x ∂μ = μ (s i) • b + o(μ (s i))` at a filter `li` provided that
`s i` tends to `l.smallSets` along `li`.
Since `μ (s i)` is an `ℝ≥0∞` number, we use `(μ (s i)).toReal` in the actual statement.

Often there is a good formula for `(μ (s i)).toReal`, so the formalization can take an optional
argument `m` with this formula and a proof of `(fun i => (μ (s i)).toReal) =ᶠ[li] m`. Without these
arguments, `m i = (μ (s i)).toReal` is used in the output. -/
theorem Filter.Tendsto.integral_sub_linear_isLittleO_ae [NormedSpace ℝ E] [CompleteSpace E]
    {μ : Measure α} {l : Filter α} [l.IsMeasurablyGenerated] {f : α → E} {b : E}
    (h : Tendsto f (l ⊓ μ.ae) (𝓝 b)) (hfm : StronglyMeasurableAtFilter f l μ)
    (hμ : μ.FiniteAtFilter l) {s : ι → Set α} {li : Filter ι} (hs : Tendsto s li l.smallSets)
    (m : ι → ℝ := fun i => (μ (s i)).toReal)
    (hsμ : (fun i => (μ (s i)).toReal) =ᶠ[li] m := by rfl) :
    (fun i => (∫ x in s i, f x ∂μ) - m i • b) =o[li] m := by
  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μ
  refine' isLittleO_iff.2 fun ε ε₀ => _
  have : ∀ᶠ s in l.smallSets, ∀ᶠ x in μ.ae, x ∈ s → f x ∈ closedBall b ε :=
    eventually_smallSets_eventually.2 (h.eventually <| closedBall_mem_nhds _ ε₀)
  

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

Next tactic:
filter_upwards [hμ.eventually, (hμ.integrableAtFilter_of_tendsto_ae hfm h).eventually,
    hfm.eventually, this]
/-- Fundamental theorem of calculus for set integrals:
if `μ` is a measure that is finite at a filter `l` and
`f` is a measurable function that has a finite limit `b` at `l ⊓ μ.ae`, then
`∫ x in s i, f x ∂μ = μ (s i) • b + o(μ (s i))` at a filter `li` provided that
`s i` tends to `l.smallSets` along `li`.
Since `μ (s i)` is an `ℝ≥0∞` number, we use `(μ (s i)).toReal` in the actual statement.

Often there is a good formula for `(μ (s i)).toReal`, so the formalization can take an optional
argument `m` with this formula and a proof of `(fun i => (μ (s i)).toReal) =ᶠ[li] m`. Without these
arguments, `m i = (μ (s i)).toReal` is used in the output. -/
theorem Filter.Tendsto.integral_sub_linear_isLittleO_ae [NormedSpace ℝ E] [CompleteSpace E]
    {μ : Measure α} {l : Filter α} [l.IsMeasurablyGenerated] {f : α → E} {b : E}
    (h : Tendsto f (l ⊓ μ.ae) (𝓝 b)) (hfm : StronglyMeasurableAtFilter f l μ)
    (hμ : μ.FiniteAtFilter l) {s : ι → Set α} {li : Filter ι} (hs : Tendsto s li l.smallSets)
    (m : ι → ℝ := fun i => (μ (s i)).toReal)
    (hsμ : (fun i => (μ (s i)).toReal) =ᶠ[li] m := by rfl) :
    (fun i => (∫ x in s i, f x ∂μ) - m i • b) =o[li] m := by
  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μ
  refine' isLittleO_iff.2 fun ε ε₀ => _
  have : ∀ᶠ s in l.smallSets, ∀ᶠ x in μ.ae, x ∈ s → f x ∈ closedBall b ε :=
    eventually_smallSets_eventually.2 (h.eventually <| closedBall_mem_nhds _ ε₀)
  filter_upwards [hμ.eventually, (hμ.integrableAtFilter_of_tendsto_ae hfm h).eventually,
    hfm.eventually, this]
  

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

Next tactic:
simp only [mem_closedBall, dist_eq_norm]