import Mathlib
import FoML


open MeasureTheory ProbabilityTheory Real

open scoped ENNReal

theorem extracted_formal_statement_66.{u_1, w, u} {Ω : Type u} [inst : MeasurableSpace Ω] {Z : Type w} {n : ℕ}
  {ι : Type u_1} {f : ι → Z → ℝ} {μ : Measure Ω} [inst_1 : IsProbabilityMeasure μ] {X : Ω → Z} [inst_2 : Nonempty ι]
  [inst_3 : Countable ι] (hf : ∀ (i : ι), Measurable (f i ∘ X)) {b : ℝ} (hf' : ∀ (i : ι) (z : Z), |f i z| ≤ b)
  (ω : Fin n → Ω) (hp : ∀ (i : ι) (j : Fin n), Integrable (fun a => f i (X (a j))) (Measure.pi fun x => μ))
  (hq : ∀ (ω : Fin n → Ω) (k : Fin n), BddAbove (Set.range fun i => f i (X (ω k))))
  (hq' : ∀ (ω : Fin n → Ω) (k : Fin n), BddBelow (Set.range fun i => f i (X (ω k))))
  (hq0 : ∀ (ω x : Fin n → Ω) (k : Fin n), BddAbove (Set.range fun i => f i (X (ω k)) - f i (X (x k))))
  (hq1_1 : ∀ (ω x : Fin n → Ω), BddAbove (Set.range fun i => ∑ k, (f i (X (ω k)) - f i (X (x k)))))
  (hq2 : ∀ (ω x : Fin n → Ω) (k : Fin n), BddBelow (Set.range fun i => f i (X (ω k)) - f i (X (x k))))
  (hq3 : ∀ (ω x : Fin n → Ω), BddBelow (Set.range fun i => ∑ k, (f i (X (ω k)) - f i (X (x k)))))
  (hq1 : ∀ (ω x : Fin n → Ω), BddAbove (Set.range fun i => |∑ k, (f i (X (ω k)) - f i (X (x k)))|)) (C : ℝ)
  (hr0 : ∀ (ω : Fin n → Ω) (k : Fin n), ∀ y ∈ Set.range fun i => f i (X (ω k)), y ≤ C) (D : ℝ)
  (hr1 : ∀ (ω : Fin n → Ω) (k : Fin n), ∀ y ∈ Set.range fun i => f i (X (ω k)), D ≤ y) (a : ι)
  (hr2 : ∀ (x : Fin n → Ω), |∑ k, (f a (X (ω k)) - f a (X (x k)))| ≤ ↑n * (C - D)) :
  Integrable (fun a_1 => ∑ k, (f a (X (ω k)) - f a (X (a_1 k)))) (Measure.pi fun x => μ) := sorry

Tactic state before:
case hf.hf
Ω : Type u
inst✝³ : MeasurableSpace Ω
Z : Type w
n : ℕ
ι : Type u_1
f : ι → Z → ℝ
μ : Measure Ω
inst✝² : IsProbabilityMeasure μ
X : Ω → Z
inst✝¹ : Nonempty ι
inst✝ : Countable ι
hf : ∀ (i : ι), Measurable (f i ∘ X)
b : ℝ
hf' : ∀ (i : ι) (z : Z), |f i z| ≤ b
ω : Fin n → Ω
hp : ∀ (i : ι) (j : Fin n), Integrable (fun a => f i (X (a j))) (Measure.pi fun x => μ)
hq : ∀ (ω : Fin n → Ω) (k : Fin n), BddAbove (Set.range fun i => f i (X (ω k)))
hq' : ∀ (ω : Fin n → Ω) (k : Fin n), BddBelow (Set.range fun i => f i (X (ω k)))
hq0 : ∀ (ω x : Fin n → Ω) (k : Fin n), BddAbove (Set.range fun i => f i (X (ω k)) - f i (X (x k)))
hq1✝ : ∀ (ω x : Fin n → Ω), BddAbove (Set.range fun i => ∑ k, (f i (X (ω k)) - f i (X (x k))))
hq2 : ∀ (ω x : Fin n → Ω) (k : Fin n), BddBelow (Set.range fun i => f i (X (ω k)) - f i (X (x k)))
hq3 : ∀ (ω x : Fin n → Ω), BddBelow (Set.range fun i => ∑ k, (f i (X (ω k)) - f i (X (x k))))
hq1 : ∀ (ω x : Fin n → Ω), BddAbove (Set.range fun i => |∑ k, (f i (X (ω k)) - f i (X (x k)))|)
C : ℝ
hr0 : ∀ (ω : Fin n → Ω) (k : Fin n), ∀ y ∈ Set.range fun i => f i (X (ω k)), y ≤ C
D : ℝ
hr1 : ∀ (ω : Fin n → Ω) (k : Fin n), ∀ y ∈ Set.range fun i => f i (X (ω k)), D ≤ y
a : ι
hr2 : ∀ (x : Fin n → Ω), |∑ k, (f a (X (ω k)) - f a (X (x k)))| ≤ ↑n * (C - D)
⊢ Integrable (fun a_1 => ∑ k, (f a (X (ω k)) - f a (X (a_1 k)))) (Measure.pi fun x => μ)

Tactic:
apply Integrable.of_mem_Icc
    ·
  refine Finset.aemeasurable_sum Finset.univ ?_
  intro i hi
  refine AEMeasurable.sub ?_ ?_
  exact aemeasurable_const
  exact Integrable.aemeasurable (hp a i)
    ·
  filter_upwards
  intro a_1
  constructor
  have g : ∑ k : Fin n, (-b - b) ≤ ∑ k : Fin n, (f a (X (ω k)) - f a (X (a_1 k))) :=
    by
    refine Finset.sum_le_sum ?_
    intro i hi
    have q : -b ≤ f a (X (ω i)) := neg_le_of_abs_le (hf' a (X (ω i)))
    have q' : f a (X (a_1 i)) ≤ b := le_of_max_le_left (hf' a (X (a_1 i)))
    linarith
  to_theorem
    exact
      g
        have g' : ∑ k : Fin n, (f a (X (ω k)) - f a (X (a_1 k))) ≤ ∑ k : Fin n, (b + b) :=
      by
      apply Finset.sum_le_sum
      intro i hi
      have q : f a (X (ω i)) ≤ b := le_of_max_le_left (hf' a (X (ω i)))
      have q' : -b ≤ f a (X (a_1 i)) := neg_le_of_abs_le (hf' a (X (a_1 i)))
      linarith exact g'

Tactic state after: