-- Mathlib/Probability/StrongLaw.lean
theorem strong_law_aux3 :
    (fun n => 𝔼[∑ i ∈ range n, truncation (X i) i] - n * 𝔼[X 0]) =o[atTop] ((↑) : ℕ → ℝ)

Proof state:
Ω : Type u_1
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : ℕ → Ω → ℝ
hint : Integrable (X 0) ℙ
hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) ℙ ℙ
⊢ (fun n => (∫ (a : Ω), (∑ i ∈ range n, truncation (X i) ↑i) a) - ↑n * ∫ (a : Ω), X 0 a) =o[atTop] Nat.cast

Tactic:
have A : Tendsto (fun i => 𝔼[truncation (X i) i]) atTop (𝓝 𝔼[X 0]) := by
  convert (tendsto_integral_truncation hint).comp tendsto_natCast_atTop_atTop using 1
  ext i
  exact (hident i).truncation.integral_eq

Result:
Ω : Type u_1
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : ℕ → Ω → ℝ
hint : Integrable (X 0) ℙ
hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) ℙ ℙ
A : Tendsto (fun i => ∫ (a : Ω), truncation (X i) (↑i) a) atTop (𝓝 (∫ (a : Ω), X 0 a))
⊢ (fun n => (∫ (a : Ω), (∑ i ∈ range n, truncation (X i) ↑i) a) - ↑n * ∫ (a : Ω), X 0 a) =o[atTop] Nat.cast

Proof state:
case h.e'_3
Ω : Type u_1
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : ℕ → Ω → ℝ
hint : Integrable (X 0) ℙ
hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) ℙ ℙ
⊢ (fun i => ∫ (a : Ω), truncation (X i) (↑i) a) = (fun A => ∫ (x : Ω), truncation (X 0) A x) ∘ Nat.cast

Tactic:
ext i

Result:
case h.e'_3.h
Ω : Type u_1
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : ℕ → Ω → ℝ
hint : Integrable (X 0) ℙ
hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) ℙ ℙ
i : ℕ
⊢ ∫ (a : Ω), truncation (X i) (↑i) a = ((fun A => ∫ (x : Ω), truncation (X 0) A x) ∘ Nat.cast) i

Proof state:
Ω : Type u_1
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : ℕ → Ω → ℝ
hint : Integrable (X 0) ℙ
hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) ℙ ℙ
A : Tendsto (fun i => ∫ (a : Ω), truncation (X i) (↑i) a) atTop (𝓝 (∫ (a : Ω), X 0 a))
n i : ℕ
x✝ : i ∈ range n
⊢ Integrable (truncation (X i) ↑i) ℙ

Tactic:
exact ((hident i).symm.integrable_snd hint).1.integrable_truncation

Result:
no goals

Proof state:
case h.e'_7.h
Ω : Type u_1
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : ℕ → Ω → ℝ
hint : Integrable (X 0) ℙ
hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) ℙ ℙ
A : Tendsto (fun i => ∫ (a : Ω), truncation (X i) (↑i) a) atTop (𝓝 (∫ (a : Ω), X 0 a))
n : ℕ
⊢ ∫ (a : Ω), ∑ c ∈ range n, truncation (X c) (↑c) a = ∑ x ∈ range n, ∫ (a : Ω), truncation (X x) (↑x) a

Tactic:
rw [integral_finset_sum _ fun i _ => ?_]

Result:
Ω : Type u_1
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : ℕ → Ω → ℝ
hint : Integrable (X 0) ℙ
hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) ℙ ℙ
A : Tendsto (fun i => ∫ (a : Ω), truncation (X i) (↑i) a) atTop (𝓝 (∫ (a : Ω), X 0 a))
n i : ℕ
x✝ : i ∈ range n
⊢ Integrable (truncation (X i) ↑i) ℙ

Proof state:
case h.e'_3.h
Ω : Type u_1
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : ℕ → Ω → ℝ
hint : Integrable (X 0) ℙ
hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) ℙ ℙ
i : ℕ
⊢ ∫ (a : Ω), truncation (X i) (↑i) a = ((fun A => ∫ (x : Ω), truncation (X 0) A x) ∘ Nat.cast) i

Tactic:
exact (hident i).truncation.integral_eq

Result:
no goals

Proof state:
case h.e'_7.h
Ω : Type u_1
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : ℕ → Ω → ℝ
hint : Integrable (X 0) ℙ
hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) ℙ ℙ
A : Tendsto (fun i => ∫ (a : Ω), truncation (X i) (↑i) a) atTop (𝓝 (∫ (a : Ω), X 0 a))
n : ℕ
⊢ (∫ (a : Ω), (∑ i ∈ range n, truncation (X i) ↑i) a) - ↑n * ∫ (a : Ω), X 0 a =
    ∑ i ∈ range n, ((∫ (a : Ω), truncation (X i) (↑i) a) - ∫ (a : Ω), X 0 a)

Tactic:
simp only [sum_sub_distrib, sum_const, card_range, nsmul_eq_mul, sum_apply, sub_left_inj]

Result:
case h.e'_7.h
Ω : Type u_1
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : ℕ → Ω → ℝ
hint : Integrable (X 0) ℙ
hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) ℙ ℙ
A : Tendsto (fun i => ∫ (a : Ω), truncation (X i) (↑i) a) atTop (𝓝 (∫ (a : Ω), X 0 a))
n : ℕ
⊢ ∫ (a : Ω), ∑ c ∈ range n, truncation (X c) (↑c) a = ∑ x ∈ range n, ∫ (a : Ω), truncation (X x) (↑x) a

Proof state:
Ω : Type u_1
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : ℕ → Ω → ℝ
hint : Integrable (X 0) ℙ
hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) ℙ ℙ
A : Tendsto (fun i => ∫ (a : Ω), truncation (X i) (↑i) a) atTop (𝓝 (∫ (a : Ω), X 0 a))
⊢ (fun n => (∫ (a : Ω), (∑ i ∈ range n, truncation (X i) ↑i) a) - ↑n * ∫ (a : Ω), X 0 a) =o[atTop] Nat.cast

Tactic:
convert Asymptotics.isLittleO_sum_range_of_tendsto_zero (tendsto_sub_nhds_zero_iff.2 A) using 1

Result:
case h.e'_7
Ω : Type u_1
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : ℕ → Ω → ℝ
hint : Integrable (X 0) ℙ
hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) ℙ ℙ
A : Tendsto (fun i => ∫ (a : Ω), truncation (X i) (↑i) a) atTop (𝓝 (∫ (a : Ω), X 0 a))
⊢ (fun n => (∫ (a : Ω), (∑ i ∈ range n, truncation (X i) ↑i) a) - ↑n * ∫ (a : Ω), X 0 a) = fun n =>
    ∑ i ∈ range n, ((∫ (a : Ω), truncation (X i) (↑i) a) - ∫ (a : Ω), X 0 a)

Proof state:
case h.e'_7
Ω : Type u_1
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : ℕ → Ω → ℝ
hint : Integrable (X 0) ℙ
hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) ℙ ℙ
A : Tendsto (fun i => ∫ (a : Ω), truncation (X i) (↑i) a) atTop (𝓝 (∫ (a : Ω), X 0 a))
⊢ (fun n => (∫ (a : Ω), (∑ i ∈ range n, truncation (X i) ↑i) a) - ↑n * ∫ (a : Ω), X 0 a) = fun n =>
    ∑ i ∈ range n, ((∫ (a : Ω), truncation (X i) (↑i) a) - ∫ (a : Ω), X 0 a)

Tactic:
ext1 n

Result:
case h.e'_7.h
Ω : Type u_1
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : ℕ → Ω → ℝ
hint : Integrable (X 0) ℙ
hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) ℙ ℙ
A : Tendsto (fun i => ∫ (a : Ω), truncation (X i) (↑i) a) atTop (𝓝 (∫ (a : Ω), X 0 a))
n : ℕ
⊢ (∫ (a : Ω), (∑ i ∈ range n, truncation (X i) ↑i) a) - ↑n * ∫ (a : Ω), X 0 a =
    ∑ i ∈ range n, ((∫ (a : Ω), truncation (X i) (↑i) a) - ∫ (a : Ω), X 0 a)

Proof state:
Ω : Type u_1
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : ℕ → Ω → ℝ
hint : Integrable (X 0) ℙ
hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) ℙ ℙ
⊢ Tendsto (fun i => ∫ (a : Ω), truncation (X i) (↑i) a) atTop (𝓝 (∫ (a : Ω), X 0 a))

Tactic:
convert (tendsto_integral_truncation hint).comp tendsto_natCast_atTop_atTop using 1

Result:
case h.e'_3
Ω : Type u_1
inst✝¹ : MeasureSpace Ω
inst✝ : IsProbabilityMeasure ℙ
X : ℕ → Ω → ℝ
hint : Integrable (X 0) ℙ
hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) ℙ ℙ
⊢ (fun i => ∫ (a : Ω), truncation (X i) (↑i) a) = (fun A => ∫ (x : Ω), truncation (X 0) A x) ∘ Nat.cast