import Mathlib
import FoML


open MeasureTheory ProbabilityTheory Real

open scoped ENNReal

theorem extracted_formal_statement_21.{u_1, w, u} {Ω : Type u} [inst : MeasurableSpace Ω] {Z : Type w} {n : ℕ}
  {ι : Type u_1} {f : ι → Z → ℝ} {μ : Measure Ω} [inst_1 : IsProbabilityMeasure μ] [inst_2 : Countable ι] {X : Ω → Z}
  (hf : ∀ (i : ι), Measurable (f i ∘ X)) {b : ℝ} (hb : 0 ≤ b) (hf' : ∀ (i : ι) (z : Z), |f i z| ≤ b)
  (ω : Fin n → Ω × Ω) :
  (2 ^ n)⁻¹ * |∑ σ, ⨆ i, |∑ k, ↑↑(σ k) * (f i (X (ω k).1) - f i (X (ω k).2))|| ≤ ↑n * (b + b) := sorry

Tactic state before:
case h
Ω : Type u
inst✝² : MeasurableSpace Ω
Z : Type w
n : ℕ
ι : Type u_1
f : ι → Z → ℝ
μ : Measure Ω
inst✝¹ : IsProbabilityMeasure μ
inst✝ : Countable ι
X : Ω → Z
hf : ∀ (i : ι), Measurable (f i ∘ X)
b : ℝ
hb : 0 ≤ b
hf' : ∀ (i : ι) (z : Z), |f i z| ≤ b
ω : Fin n → Ω × Ω
ω₁ : Fin n → Ω := fun k => (ω k).1
ω₂ : Fin n → Ω := fun k => (ω k).2
⊢ (2 ^ n)⁻¹ * |∑ σ, ⨆ i, |∑ k, ↑↑(σ k) * (f i (X (ω k).1) - f i (X (ω k).2))|| ≤ ↑n * (b + b)

Tactic:
rw [inv_mul_le_iff₀' (by simp)]
    rw [mul_comm (↑n * (b + b))]
    calc
  _ ≤ ∑ σ : Signs n, |⨆ i, (|∑ k : Fin n, ↑↑(σ k) * (f i (X (ω k).1) - f i (X (ω k).2))|)| := by
    apply Finset.abs_sum_le_sum_abs
  _ ≤ ∑ σ : Signs n, ⨆ i, |(|∑ k : Fin n, ↑↑(σ k) * (f i (X (ω k).1) - f i (X (ω k).2))|)| :=
    by
    to_theorem apply Finset.sum_le_sum intro σ _ simp only [Int.reduceNeg, abs_abs]
    to_theorem apply Eq.le simp only [Int.reduceNeg, abs_eq_self]by_cases h : Nonempty ι
    · apply le_ciSup_of_le _ (Classical.choice h)
      · simp
      · apply bdd_above_aux3 hf'
    · simp only [not_nonempty_iff] at h
      simp
  _ ≤ ∑ σ : Signs n, ⨆ i, ∑ k : Fin n, |↑↑(σ k) * (f i (X (ω k).1) - f i (X (ω k).2))| :=
    by
    to_theorem apply Finset.sum_le_sum intro σ _ apply ciSup_mono
    · apply bdd_above_aux30 X hf' ω σ
    · intro i
      simp only [Int.reduceNeg, abs_abs]
      apply Finset.abs_sum_le_sum_abs
  _ ≤ ∑ σ : Signs n, ⨆ i, ∑ k : Fin n, |(f i (X (ω k).1) - f i (X (ω k).2))| := by
    conv in fun σ : Signs n ↦ _ =>
      ext σ
      conv in fun i ↦ _ =>
        ext i
        conv in fun k ↦ _ =>
          ext k
          rw [abs_mul]
          simp
  _ ≤ ∑ σ : Signs n, ⨆ i, ∑ k : Fin n, (|f i (X (ω k).1)| + |f i (X (ω k).2)|) :=
    by
    to_theorem apply Finset.sum_le_sum intro σ _ apply ciSup_mono
    · apply bdd_above_aux300 X hf' ω
    · intro i
      to_theorem apply Finset.sum_le_sum intro k _ exact abs_sub (f i (X (ω k).1)) (f i (X (ω k).2))
  _ ≤ _ :=
    by
    to_theorem
      simp only [Finset.sum_const, Finset.card_univ, Signs.card, nsmul_eq_mul, Nat.cast_pow, Nat.cast_ofNat,
        Nat.ofNat_pos, pow_pos,
        mul_le_mul_left]by_cases h : Nonempty ι·
        apply ciSup_le
        intro i
        suffices ∑ k : Fin n, (|f i (X (ω k).1)| + |f i (X (ω k).2)|) ≤ ∑ k : Fin n, (b + b) from
          by
          to_theorem
            apply
              le_trans this
                _
                  apply
              le_of_eq simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, smul_add, nsmul_eq_mul]
          ring
        apply Finset.sum_le_sum fun k _ ↦ add_le_add (hf' i (X (ω k).1)) (hf' i (X (ω k).2))
    · simp only [not_nonempty_iff] at h
      to_theorem simp only [iSup_of_isEmpty]apply mul_nonneg (Nat.cast_nonneg n)exact Left.add_nonneg hb hb

Tactic state after: