import Mathlib
import FoML


open MeasureTheory ProbabilityTheory

theorem extracted_formal_statement_101.{u_2, u_1} {Ω : Type u_1} [inst : MeasurableSpace Ω] {μ : Measure Ω}
  [inst_1 : IsProbabilityMeasure μ] {𝓧 : Type u_2} {m𝓧 : MeasurableSpace 𝓧} [hnonempty𝓧 : Nonempty 𝓧] {m : ℕ}
  {X' : Ω → 𝓧} (hX'' : Measurable X') {f' : (Fin m → 𝓧) → ℝ} {c' : Fin m → ℝ}
  (hfι : ∀ (i : Fin m) (x : Fin m → 𝓧) (x' : 𝓧), |f' x - f' (Function.update x i x')| ≤ c' i)
  (hf'' : StronglyMeasurable f') {ε : ℝ} (hε : ε ≥ 0) {t : ℝ} (ht : t ≥ 0) (ht' : t * ∑ i, c' i ^ 2 ≤ 1)
  (hX''' : ∀ (i : Fin m), Measurable fun ω => X' (ω i)) :
  let Y := fun k Xk =>
    ∫ (x : Fin m → Ω), (fun ω => f' fun i => if h : ↑i < ↑k then Xk ⟨↑i, h⟩ else X' (ω i)) x ∂Measure.pi fun x => μ;
  let A := fun k Xk =>
    ⨅ x,
      ∫ (x_1 : Fin m → Ω),
        (fun ω => f' fun i => if h : ↑i < ↑k then Xk ⟨↑i, h⟩ else if ↑i = ↑k then x else X' (ω i))
          x_1 ∂Measure.pi fun x => μ;
  let B := fun k Xk =>
    ⨆ x,
      ∫ (x_1 : Fin m → Ω),
        (fun ω => f' fun i => if h : ↑i < ↑k then Xk ⟨↑i, h⟩ else if ↑i = ↑k then x else X' (ω i))
          x_1 ∂Measure.pi fun x => μ;
  (∀ (k : Fin m) (Xk : Fin ↑k → 𝓧) (x : 𝓧),
      Y k.succ (Fin.snoc Xk x) =
        ∫ (x_1 : Fin m → Ω),
          (fun ω => f' fun i => if h : ↑i < ↑k then Xk ⟨↑i, h⟩ else if ↑i = ↑k then x else X' (ω i))
            x_1 ∂Measure.pi fun x => μ) →
    ∀ (x₀ : 𝓧),
      let bdf := |f' fun x => x₀| + ∑ i, c' i;
      (∀ (xi : Fin m → 𝓧), |f' xi| ≤ bdf) →
        (∀ (k : Fin m) (Xk : Fin ↑k → 𝓧) (x : 𝓧),
            Integrable (fun a => f' fun i => if h : ↑i < ↑k then Xk ⟨↑i, h⟩ else if ↑i = ↑k then x else X' (a i))
              (Measure.pi fun x => μ)) →
          (∀ (k : Fin m) (Xk : Fin ↑k → 𝓧) (x : 𝓧), A k Xk ≤ Y k.succ (Fin.snoc Xk x)) →
            (∀ (k : Fin m) (Xk : Fin ↑k → 𝓧),
                𝓧 →
                  BddAbove
                    (Set.range fun x =>
                      ∫ (a : Fin m → Ω),
                        (fun ω => f' fun i => if h : ↑i < ↑k then Xk ⟨↑i, h⟩ else if ↑i = ↑k then x else X' (ω i))
                          a ∂Measure.pi fun x => μ)) →
              (∀ (k : Fin m) (Xk : Fin ↑k → 𝓧) (x : 𝓧), B k Xk ≥ Y k.succ (Fin.snoc Xk x)) →
                (∀ (k : Fin m) (Xk : Fin ↑k → 𝓧), B k Xk ≤ A k Xk + c' k) →
                  (∀ (k : Fin m) (Xk : Fin ↑k → 𝓧),
                      (∫ (ω : Fin m → Ω), Y k.succ (Fin.snoc Xk (X' (ω k))) ∂Measure.pi fun x => μ) = Y k.castSucc Xk) →
                    (∀ (k : Fin m.succ), Measurable (Y k)) →
                      (∀ (k : Fin m.succ) (Xk : Fin ↑k → 𝓧), |Y k Xk| ≤ bdf) →
                        let V := fun k Xk ω => Y k.succ (Fin.snoc Xk (X' (ω k))) - Y k.castSucc Xk;
                        let t'' := 4 * ε * t;
                        t'' ≥ 0 →
                          (∀ (k : Fin m) (Xk : Fin ↑k → 𝓧),
                              (∫ (ω : Fin m → Ω), Real.exp (t'' * V k Xk ω) ∂Measure.pi fun x => μ) ≤
                                Real.exp (t'' ^ 2 * c' k ^ 2 / 8)) →
                            let E := Y 0 fun x => x₀;
                            (∀ (k : ℕ) (h : k ≤ m),
                                Integrable
                                  (fun x =>
                                    Real.exp
                                      (t'' * ((Y ⟨k, Nat.lt_add_one_of_le h⟩ fun i => X' (x (Fin.castLE h i))) - E)))
                                  (Measure.pi fun x => μ)) →
                              (∀ (k : ℕ) (h : k ≤ m),
                                  (∫ (ω : Fin m → Ω),
                                      Real.exp
                                        (t'' *
                                          ((Y ⟨k, Nat.lt_add_one_of_le h⟩ fun i => X' (ω (Fin.castLE h i))) -
                                            E)) ∂Measure.pi fun x => μ) ≤
                                    Real.exp ((t'' ^ 2 * ∑ i, c' (Fin.castLE h i) ^ 2) / 8)) →
                                (∫ (ω : Fin m → Ω),
                                      Real.exp
                                        (t'' *
                                          ((f' fun i => X' (ω i)) -
                                            ∫ (x : Fin m → Ω),
                                              f' fun i => X' (x i) ∂Measure.pi fun x => μ)) ∂Measure.pi fun x => μ) ≤
                                    Real.exp ((t'' ^ 2 * ∑ x, c' x ^ 2) / 8) →
                                  Integrable
                                      (fun x =>
                                        Real.exp
                                          (t'' *
                                            ((f' fun i => X' (x i)) -
                                              ∫ (x : Fin m → Ω), f' fun i => X' (x i) ∂Measure.pi fun x => μ)))
                                      (Measure.pi fun x => μ) →
                                    ((Measure.pi fun x => μ) fun ω =>
                                          (f' (X' ∘ ω) -
                                              ∫ (x : Fin m → Ω), (fun ω => f' (X' ∘ ω)) x ∂Measure.pi fun x => μ) ≥
                                            ε).toReal ≤
                                      Real.exp (-2 * ε ^ 2 * t) := sorry

Tactic state before:
Ω : Type u_1
inst✝¹ : MeasurableSpace Ω
μ : Measure Ω
inst✝ : IsProbabilityMeasure μ
𝓧 : Type u_2
m𝓧 : MeasurableSpace 𝓧
hnonempty𝓧 : Nonempty 𝓧
m : ℕ
X' : Ω → 𝓧
hX'' : Measurable X'
f' : (Fin m → 𝓧) → ℝ
c' : Fin m → ℝ
hfι : ∀ (i : Fin m) (x : Fin m → 𝓧) (x' : 𝓧), |f' x - f' (Function.update x i x')| ≤ c' i
hf'' : StronglyMeasurable f'
ε : ℝ
hε : ε ≥ 0
t : ℝ
ht : t ≥ 0
ht' : t * ∑ i, c' i ^ 2 ≤ 1
hX''' : ∀ (i : Fin m), Measurable fun ω => X' (ω i)
Y : (k : Fin m.succ) → (Fin ↑k → 𝓧) → ℝ :=
  fun k Xk =>
    ∫ (x : Fin m → Ω), (fun ω => f' fun i => if h : ↑i < ↑k then Xk ⟨↑i, h⟩ else X' (ω i)) x ∂Measure.pi fun x => μ
A : (k : Fin m) → (Fin ↑k → 𝓧) → ℝ :=
  fun k Xk =>
    ⨅ x,
      ∫ (x_1 : Fin m → Ω),
        (fun ω => f' fun i => if h : ↑i < ↑k then Xk ⟨↑i, h⟩ else if ↑i = ↑k then x else X' (ω i))
          x_1 ∂Measure.pi fun x => μ
B : (k : Fin m) → (Fin ↑k → 𝓧) → ℝ :=
  fun k Xk =>
    ⨆ x,
      ∫ (x_1 : Fin m → Ω),
        (fun ω => f' fun i => if h : ↑i < ↑k then Xk ⟨↑i, h⟩ else if ↑i = ↑k then x else X' (ω i))
          x_1 ∂Measure.pi fun x => μ
AB_rw :
  ∀ (k : Fin m) (Xk : Fin ↑k → 𝓧) (x : 𝓧),
    Y k.succ (Fin.snoc Xk x) =
      ∫ (x_1 : Fin m → Ω),
        (fun ω => f' fun i => if h : ↑i < ↑k then Xk ⟨↑i, h⟩ else if ↑i = ↑k then x else X' (ω i))
          x_1 ∂Measure.pi fun x => μ
x₀ : 𝓧
bdf : ℝ := |f' fun x => x₀| + ∑ i, c' i
hfbdd : ∀ (xi : Fin m → 𝓧), |f' xi| ≤ bdf
hintegrableAB :
  ∀ (k : Fin m) (Xk : Fin ↑k → 𝓧) (x : 𝓧),
    Integrable (fun a => f' fun i => if h : ↑i < ↑k then Xk ⟨↑i, h⟩ else if ↑i = ↑k then x else X' (a i))
      (Measure.pi fun x => μ)
hAY : ∀ (k : Fin m) (Xk : Fin ↑k → 𝓧) (x : 𝓧), A k Xk ≤ Y k.succ (Fin.snoc Xk x)
hBddAbove :
  ∀ (k : Fin m) (Xk : Fin ↑k → 𝓧),
    𝓧 →
      BddAbove
        (Set.range fun x =>
          ∫ (a : Fin m → Ω),
            (fun ω => f' fun i => if h : ↑i < ↑k then Xk ⟨↑i, h⟩ else if ↑i = ↑k then x else X' (ω i))
              a ∂Measure.pi fun x => μ)
hYB : ∀ (k : Fin m) (Xk : Fin ↑k → 𝓧) (x : 𝓧), B k Xk ≥ Y k.succ (Fin.snoc Xk x)
hAB : ∀ (k : Fin m) (Xk : Fin ↑k → 𝓧), B k Xk ≤ A k Xk + c' k
hmartigale :
  ∀ (k : Fin m) (Xk : Fin ↑k → 𝓧),
    (∫ (ω : Fin m → Ω), Y k.succ (Fin.snoc Xk (X' (ω k))) ∂Measure.pi fun x => μ) = Y k.castSucc Xk
hmeasurableY : ∀ (k : Fin m.succ), Measurable (Y k)
hYbdd : ∀ (k : Fin m.succ) (Xk : Fin ↑k → 𝓧), |Y k Xk| ≤ bdf
V : (k : Fin m) → (Fin ↑k → 𝓧) → (Fin m → Ω) → ℝ := fun k Xk ω => Y k.succ (Fin.snoc Xk (X' (ω k))) - Y k.castSucc Xk
t'' : ℝ := 4 * ε * t
ht'' : t'' ≥ 0
hhoefdding :
  ∀ (k : Fin m) (Xk : Fin ↑k → 𝓧),
    (∫ (ω : Fin m → Ω), Real.exp (t'' * V k Xk ω) ∂Measure.pi fun x => μ) ≤ Real.exp (t'' ^ 2 * c' k ^ 2 / 8)
E : ℝ := Y 0 fun x => x₀
hintegrablelefts :
  ∀ (k : ℕ) (h : k ≤ m),
    Integrable (fun x => Real.exp (t'' * ((Y ⟨k, ⋯⟩ fun i => X' (x (Fin.castLE h i))) - E))) (Measure.pi fun x => μ)
heqind :
  ∀ (k : ℕ) (h : k ≤ m),
    (∫ (ω : Fin m → Ω), Real.exp (t'' * ((Y ⟨k, ⋯⟩ fun i => X' (ω (Fin.castLE h i))) - E)) ∂Measure.pi fun x => μ) ≤
      Real.exp ((t'' ^ 2 * ∑ i, c' (Fin.castLE h i) ^ 2) / 8)
this :
  (∫ (ω : Fin m → Ω),
      Real.exp
        (t'' *
          ((f' fun i => X' (ω i)) -
            ∫ (x : Fin m → Ω), f' fun i => X' (x i) ∂Measure.pi fun x => μ)) ∂Measure.pi fun x => μ) ≤
    Real.exp ((t'' ^ 2 * ∑ x, c' x ^ 2) / 8)
hintegrable :
  Integrable
    (fun x =>
      Real.exp (t'' * ((f' fun i => X' (x i)) - ∫ (x : Fin m → Ω), f' fun i => X' (x i) ∂Measure.pi fun x => μ)))
    (Measure.pi fun x => μ)
⊢ ((Measure.pi fun x => μ) fun ω =>
        (f' (X' ∘ ω) - ∫ (x : Fin m → Ω), (fun ω => f' (X' ∘ ω)) x ∂Measure.pi fun x => μ) ≥ ε).toReal ≤
    Real.exp (-2 * ε ^ 2 * t)

Tactic:
apply (ProbabilityTheory.measure_ge_le_exp_mul_mgf ε ht'' hintegrable).trans
    dsimp only [mgf]
    calc
  _ ≤ Real.exp (-t'' * ε) * Real.exp ((t'' ^ 2 * ∑ x : Fin m, c' x ^ 2) / 8) :=
    by
    apply mul_le_mul_of_nonneg_left this
    apply Real.exp_nonneg
  _ ≤ _ :=
    by
    to_theorem
      rw [←
        Real.exp_add]apply
        Real.exp_monotone simp only [neg_mul, neg_add_le_iff_le_add, le_add_neg_iff_add_le, t'', E, Y, V]
    calc
      _ = 2 * ε ^ 2 * t * (t * ∑ x : Fin m, c' x ^ 2) + 2 * ε ^ 2 * t := by ring
      _ ≤ 2 * ε ^ 2 * t * 1 + 2 * ε ^ 2 * t :=
        by
        to_theorem apply add_le_add_right apply mul_le_mul_of_nonneg_left ht' apply mul_nonneg _ ht
        norm_num
        exact sq_nonneg ε
      _ = _ := by ring

Tactic state after: