-- Module: Mathlib.Probability.StrongLaw
Goal:
Ω : Type u_1
inst : MeasureSpace Ω
inst_1 : IsProbabilityMeasure.{u_1} (α := Ω) (m0 := MeasureSpace.toMeasurableSpace) ℙ
X : ℕ → Ω → ℝ
hint : @Integrable _ _ _ _ MeasureSpace.toMeasurableSpace (X 0) ℙ
hindep : Pairwise ((fun (f g : Ω → ℝ) ↦ f ⟂ᵢ g) on X)
hident : ∀ (i : ℕ), IdentDistrib (X i) (X 0) ℙ ℙ
hnonneg : ∀ (i : ℕ) (ω : Ω), 0 ≤ X i ω
c : ℝ
c_one : 1 < c
ε : ℝ
εpos : 0 < ε
c_pos : 0 < c
hX : ∀ (i : ℕ), AEStronglyMeasurable (m₀ := MeasureSpace.toMeasurableSpace) (X i) ℙ
A : ∀ (i : ℝ), StronglyMeasurable ((Set.Ioc (-i) i).indicator id)
Y : (n : ℕ) → Ω → ℝ := fun (n : ℕ) ↦ truncation (X n) (↑n : ℝ)
S : (n : ℕ) → Ω → ℝ := fun (n : ℕ) ↦ ∑ i ∈ range n, Y i
hS : S = fun (n : ℕ) ↦ ∑ i ∈ range n, Y i
u : ℕ → ℕ := fun (n : ℕ) ↦ ⌊c ^ n⌋₊
u_mono : Monotone u
I1 :
  ∀ (K : ℕ),
    ∑ j ∈ range K,
        (HPow.hPow (α := ℝ) (β := ℕ) (↑j : ℝ) 2)⁻¹ * variance (mΩ := MeasureSpace.toMeasurableSpace) (Y j) ℙ ≤
      HMul.hMul (α := ℝ) 2 (@integral _ _ _ _ MeasureSpace.toMeasurableSpace ℙ fun (a : Ω) ↦ X 0 a)
C : ℝ :=
  HPow.hPow (β := ℕ) c 5 * HPow.hPow (β := ℕ) (c - 1)⁻¹ 3 *
    HMul.hMul (α := ℝ) 2 (@integral _ _ _ _ MeasureSpace.toMeasurableSpace ℙ fun (a : Ω) ↦ X 0 a)
I2 :
  ∀ (N : ℕ),
    ∑ i ∈ range N,
        (HPow.hPow (α := ℝ) (β := ℕ) (↑(u i) : ℝ) 2)⁻¹ * variance (mΩ := MeasureSpace.toMeasurableSpace) (S (u i)) ℙ ≤
      C
N : ℕ
i :
  LE.le (α := ℝ≥0∞)
    (∑ i ∈ range N,
      ((ℙ : Measure Ω) : (a : Set Ω) → ℝ≥0∞)
        {ω : Ω |
          (↑(u i) : ℝ) * ε ≤ |S (u i) ω - @integral _ _ _ _ MeasureSpace.toMeasurableSpace ℙ fun (a : Ω) ↦ S (u i) a|})
    (∑ i ∈ range N,
      ENNReal.ofReal
        (variance (mΩ := MeasureSpace.toMeasurableSpace) (S (u i)) ℙ / HPow.hPow (β := ℕ) ((↑(u i) : ℝ) * ε) 2))
i₁ :
  ∑ i ∈ range N,
      ENNReal.ofReal
        (variance (mΩ := MeasureSpace.toMeasurableSpace) (S (u i)) ℙ / HPow.hPow (β := ℕ) ((↑(u i) : ℝ) * ε) 2) =
    ENNReal.ofReal
      (∑ i ∈ range N,
        variance (mΩ := MeasureSpace.toMeasurableSpace) (S (u i)) ℙ / HPow.hPow (β := ℕ) ((↑(u i) : ℝ) * ε) 2)
i₂ :
  ENNReal.ofReal
      (∑ i ∈ range N,
        variance (mΩ := MeasureSpace.toMeasurableSpace) (S (u i)) ℙ / HPow.hPow (β := ℕ) ((↑(u i) : ℝ) * ε) 2) ≤
    ENNReal.ofReal (HPow.hPow (β := ℕ) ε⁻¹ 2 * C)
⊢ ∑ i ∈ range N,
      ((ℙ : Measure Ω) : (a : Set Ω) → ℝ≥0∞)
        {ω : Ω |
          (↑(u i) : ℝ) * ε ≤ |S (u i) ω - @integral _ _ _ _ MeasureSpace.toMeasurableSpace ℙ fun (a : Ω) ↦ S (u i) a|} ≤
    ENNReal.ofReal (HPow.hPow (β := ℕ) ε⁻¹ 2 * C)

Tactic:
calc
      ∑ i ∈ range N, ℙ {ω | (u i * ε : ℝ) ≤ |S (u i) ω - 𝔼[S (u i)]|} ≤
          ∑ i ∈ range N, ENNReal.ofReal (Var[S (u i)] / (u i * ε) ^ 2) := by
        gcongr with i _
        apply meas_ge_le_variance_div_sq
        · exact memLp_finsetSum' _ fun j _ => (hident j).aestronglyMeasurable_fst.memLp_truncation
        · apply mul_pos (Nat.cast_pos.2 _) εpos
          refine zero_lt_one.trans_le ?_
          apply Nat.le_floor
          rw [Nat.cast_one]
          apply one_le_pow₀ c_one.le
      _ = ENNReal.ofReal (∑ i ∈ range N, Var[S (u i)] / (u i * ε) ^ 2) := by
        rw [ENNReal.ofReal_sum_of_nonneg fun i _ => ?_]
        exact div_nonneg (variance_nonneg _ _) (sq_nonneg _)
      _ ≤ ENNReal.ofReal (ε⁻¹ ^ 2 * C) := by
        apply ENNReal.ofReal_le_ofReal
        simp_rw [div_eq_inv_mul, ← inv_pow, mul_inv, mul_comm _ (ε⁻¹), mul_pow, mul_assoc,
          ← mul_sum]
        gcongr
        simpa only [inv_pow] using I2 N

Premises used: HMul.hMul, ENNReal.ofReal, HDiv.hDiv, ProbabilityTheory.variance, Nat.cast, Finset.range, Inv.inv, HPow.hPow, MeasureTheory.MeasureSpace.volume, OfNat.ofNat, Finset.sum