import Mathlib
import Optlib


open Set Bornology Filter BigOperators Topology BCD

open BCD

theorem extracted_formal_statement_255.{u_2, u_1} {E : Type u_1} {F : Type u_2} [inst : NormedAddCommGroup E]
  [inst_1 : InnerProductSpace ℝ E] [inst_2 : CompleteSpace E] [inst_3 : NormedAddCommGroup F]
  [inst_4 : InnerProductSpace ℝ F] [inst_5 : CompleteSpace F] {f : E → ℝ} {g : F → ℝ} {H : WithLp 2 (E × F) → ℝ}
  {x0 : E} {y0 : F} {l : NNReal} {alg : BCD f g H l x0 y0} [inst_6 : ProperSpace E] [inst_7 : ProperSpace F] (γ : ℝ)
  (hγ : γ > 1) (ck : ∀ (k : ℕ), alg.c k = 1 / (γ * ↑l)) (dk : ∀ (k : ℕ), alg.d k = 1 / (γ * ↑l))
  (bd : Bornology.IsBounded (z '' univ)) (hψ : KL_function ψ) (lbdψ : BddBelow (ψ '' univ)) (z_ : WithLp 2 (E × F))
  (left : z_ ∈ closure (z '' univ)) (α : ℕ → ℕ) (monoa : StrictMono α) (conv : Tendsto (fun n => z (α n)) atTop (𝓝 z_))
  (ρ1 : ℝ) (ρ1pos : ρ1 > 0)
  (suff_des : ρ1 = (γ - 1) * ↑l ∧ ∀ (k : ℕ), ρ1 / 2 * ‖z (k + 1) - z k‖ ^ 2 ≤ ψ (z k) - ψ (z (k + 1)))
  (z_in : z_ ∈ limit_set z) (final : ∀ (m : ℕ), ∃ n, m ≤ α n)
  (psiconv : Tendsto (fun n => ψ (z (α n))) atTop (𝓝 (ψ z_))) (monopsi : ∀ (m n : ℕ), ψ (z (m + n)) ≤ ψ (z m))
  (h : ∀ (n : ℕ), ψ (z (α n)) > ψ z_) (L1 : ∀ η > 0, ∃ l1, ∀ k ≥ l1, ψ z_ < ψ (z k) ∧ ψ (z k) < ψ z_ + η)
  (L2 : ∀ ε > 0, ∃ l2, ∀ k > l2, (EMetric.infEdist (z k) (limit_set z)).toReal < ε)
  (wklpt : ∀ z0 ∈ limit_set z, KL_point ψ z0) (cons : is_constant_on ψ (limit_set z)) (η : ℝ) (left_1 : η ∈ Ioi 0)
  (φ : ℝ → ℝ) (hφ : φ ∈ desingularizing_function η) (LL : ℕ)
  (ieq :
    ∀ n > LL,
      (ψ z_ < ψ (z n) ∧ ψ (z n) < ψ z_ + η) ∧
        ENNReal.ofReal (deriv φ (ψ (z n) - ψ z_)) * EMetric.infEdist 0 (subdifferential ψ (z n)) ≥ 1) :
  let a := fun n => φ (ψ (z (n + LL + 1)) - ψ z_);
  let c := fun n => ‖z (n + LL + 1) - z (n + LL)‖;
  let sum := fun n => ∑ k ∈ Finset.range n, ‖z (k + 1) - z k‖;
  (∀ (n : ℕ), ψ (z (n + LL + 1)) - ψ z_ ∈ Ioo 0 η) →
    ∀ ρ > 0,
      (∀ (k : ℕ), ∃ dΨ ∈ f_subdifferential ψ (z (k + 1)), ‖dΨ‖ ≤ ρ * ‖z (k + 1) - z k‖) →
        let C := ρ / (ρ1 / 2);
        0 ≤ C →
          (∀ (n : ℕ), 0 < a n) →
            (∀ (n : ℕ), 2 * c (n + 1) ≤ c n + C * (a n - a (n + 1))) →
              (∀ (n : ℕ), (Finset.range (n + 1)).sum c ≤ 2 * c 0 + C * a 0) →
                (∀ (n : ℕ), sum (n + 1) = sum n + ‖z (n + 1) - z n‖) →
                  (∀ (n : ℕ), sum (n + LL + 1) = sum (n + LL) + c n) →
                    sum LL + (Finset.range (0 + 1)).sum c = sum (0 + LL + 1) →
                      sum LL + (Finset.range (0 + 1)).sum c = sum (0 + LL) + c 0 := sorry

Tactic state before:
case zero
E : Type u_1
F : Type u_2
inst✝⁷ : NormedAddCommGroup E
inst✝⁶ : InnerProductSpace ℝ E
inst✝⁵ : CompleteSpace E
inst✝⁴ : NormedAddCommGroup F
inst✝³ : InnerProductSpace ℝ F
inst✝² : CompleteSpace F
f : E → ℝ
g : F → ℝ
H : WithLp 2 (E × F) → ℝ
x0 : E
y0 : F
l : NNReal
alg : BCD f g H l x0 y0
inst✝¹ : ProperSpace E
inst✝ : ProperSpace F
γ : ℝ
hγ : γ > 1
ck : ∀ (k : ℕ), alg.c k = 1 / (γ * ↑l)
dk : ∀ (k : ℕ), alg.d k = 1 / (γ * ↑l)
bd : Bornology.IsBounded (z '' univ)
hψ : KL_function ψ
lbdψ : BddBelow (ψ '' univ)
z_ : WithLp 2 (E × F)
left✝² : z_ ∈ closure (z '' univ)
α : ℕ → ℕ
monoa : StrictMono α
conv : Tendsto (fun n => z (α n)) atTop (𝓝 z_)
ρ1 : ℝ
ρ1pos : ρ1 > 0
suff_des : ρ1 = (γ - 1) * ↑l ∧ ∀ (k : ℕ), ρ1 / 2 * ‖z (k + 1) - z k‖ ^ 2 ≤ ψ (z k) - ψ (z (k + 1))
z_in : z_ ∈ limit_set z
final : ∀ (m : ℕ), ∃ n, m ≤ α n
psiconv : Tendsto (fun n => ψ (z (α n))) atTop (𝓝 (ψ z_))
monopsi : ∀ (m n : ℕ), ψ (z (m + n)) ≤ ψ (z m)
h : ∀ (n : ℕ), ψ (z (α n)) > ψ z_
L1 : ∀ η > 0, ∃ l1, ∀ k ≥ l1, ψ z_ < ψ (z k) ∧ ψ (z k) < ψ z_ + η
L2 : ∀ ε > 0, ∃ l2, ∀ k > l2, (EMetric.infEdist (z k) (limit_set z)).toReal < ε
wklpt : ∀ z0 ∈ limit_set z, KL_point ψ z0
cons : is_constant_on ψ (limit_set z)
ε : ℝ
left✝¹ : ε ∈ Ioi 0
η : ℝ
left✝ : η ∈ Ioi 0
φ : ℝ → ℝ
hφ : φ ∈ desingularizing_function η
LL : ℕ
ieq :
  ∀ n > LL,
    (ψ z_ < ψ (z n) ∧ ψ (z n) < ψ z_ + η) ∧
      ENNReal.ofReal (deriv φ (ψ (z n) - ψ z_)) * EMetric.infEdist 0 (subdifferential ψ (z n)) ≥ 1
a : ℕ → ℝ := fun n => φ (ψ (z (n + LL + 1)) - ψ z_)
b : ℕ → ℝ := fun n => ψ (z (n + LL + 1)) - ψ (z (n + 1 + LL + 1))
c : ℕ → ℝ := fun n => ‖z (n + LL + 1) - z (n + LL)‖
d : ℕ → ℝ := fun n => deriv φ (ψ (z (n + LL + 1)) - ψ z_)
sum : ℕ → ℝ := fun n => ∑ k ∈ Finset.range n, ‖z (k + 1) - z k‖
hlin : ∀ (n : ℕ), ψ (z (n + LL + 1)) - ψ z_ ∈ Ioo 0 η
ρ : ℝ
ρpos : ρ > 0
hsgub : ∀ (k : ℕ), ∃ dΨ ∈ f_subdifferential ψ (z (k + 1)), ‖dΨ‖ ≤ ρ * ‖z (k + 1) - z k‖
C : ℝ := ρ / (ρ1 / 2)
hnnegC : 0 ≤ C
hposa : ∀ (n : ℕ), 0 < a n
hbd : ∀ (n : ℕ), 2 * c (n + 1) ≤ c n + C * (a n - a (n + 1))
hbd' : ∀ (n : ℕ), (Finset.range (n + 1)).sum c ≤ 2 * c 0 + C * a 0
hs : ∀ (n : ℕ), sum (n + 1) = sum n + ‖z (n + 1) - z n‖
hc : ∀ (n : ℕ), sum (n + LL + 1) = sum (n + LL) + c n
⊢ sum LL + (Finset.range (0 + 1)).sum c = sum (0 + LL + 1)

Tactic:
rw [hc 0]

Tactic state after:
[case zero
 E : Type u_1
 F : Type u_2
 inst✝⁷ : NormedAddCommGroup E
 inst✝⁶ : InnerProductSpace ℝ E
 inst✝⁵ : CompleteSpace E
 inst✝⁴ : NormedAddCommGroup F
 inst✝³ : InnerProductSpace ℝ F
 inst✝² : CompleteSpace F
 f : E → ℝ
 g : F → ℝ
 H : WithLp 2 (E × F) → ℝ
 x0 : E
 y0 : F
 l : NNReal
 alg : BCD f g H l x0 y0
 inst✝¹ : ProperSpace E
 inst✝ : ProperSpace F
 γ : ℝ
 hγ : γ > 1
 ck : ∀ (k : ℕ), alg.c k = 1 / (γ * ↑l)
 dk : ∀ (k : ℕ), alg.d k = 1 / (γ * ↑l)
 bd : Bornology.IsBounded (z '' univ)
 hψ : KL_function ψ
 lbdψ : BddBelow (ψ '' univ)
 z_ : WithLp 2 (E × F)
 left✝² : z_ ∈ closure (z '' univ)
 α : ℕ → ℕ
 monoa : StrictMono α
 conv : Tendsto (fun n => z (α n)) atTop (𝓝 z_)
 ρ1 : ℝ
 ρ1pos : ρ1 > 0
 suff_des : ρ1 = (γ - 1) * ↑l ∧ ∀ (k : ℕ), ρ1 / 2 * ‖z (k + 1) - z k‖ ^ 2 ≤ ψ (z k) - ψ (z (k + 1))
 z_in : z_ ∈ limit_set z
 final : ∀ (m : ℕ), ∃ n, m ≤ α n
 psiconv : Tendsto (fun n => ψ (z (α n))) atTop (𝓝 (ψ z_))
 monopsi : ∀ (m n : ℕ), ψ (z (m + n)) ≤ ψ (z m)
 h : ∀ (n : ℕ), ψ (z (α n)) > ψ z_
 L1 : ∀ η > 0, ∃ l1, ∀ k ≥ l1, ψ z_ < ψ (z k) ∧ ψ (z k) < ψ z_ + η
 L2 : ∀ ε > 0, ∃ l2, ∀ k > l2, (EMetric.infEdist (z k) (limit_set z)).toReal < ε
 wklpt : ∀ z0 ∈ limit_set z, KL_point ψ z0
 cons : is_constant_on ψ (limit_set z)
 ε : ℝ
 left✝¹ : ε ∈ Ioi 0
 η : ℝ
 left✝ : η ∈ Ioi 0
 φ : ℝ → ℝ
 hφ : φ ∈ desingularizing_function η
 LL : ℕ
 ieq :
   ∀ n > LL,
     (ψ z_ < ψ (z n) ∧ ψ (z n) < ψ z_ + η) ∧
       ENNReal.ofReal (deriv φ (ψ (z n) - ψ z_)) * EMetric.infEdist 0 (subdifferential ψ (z n)) ≥ 1
 a : ℕ → ℝ := fun n => φ (ψ (z (n + LL + 1)) - ψ z_)
 b : ℕ → ℝ := fun n => ψ (z (n + LL + 1)) - ψ (z (n + 1 + LL + 1))
 c : ℕ → ℝ := fun n => ‖z (n + LL + 1) - z (n + LL)‖
 d : ℕ → ℝ := fun n => deriv φ (ψ (z (n + LL + 1)) - ψ z_)
 sum : ℕ → ℝ := fun n => ∑ k ∈ Finset.range n, ‖z (k + 1) - z k‖
 hlin : ∀ (n : ℕ), ψ (z (n + LL + 1)) - ψ z_ ∈ Ioo 0 η
 ρ : ℝ
 ρpos : ρ > 0
 hsgub : ∀ (k : ℕ), ∃ dΨ ∈ f_subdifferential ψ (z (k + 1)), ‖dΨ‖ ≤ ρ * ‖z (k + 1) - z k‖
 C : ℝ := ρ / (ρ1 / 2)
 hnnegC : 0 ≤ C
 hposa : ∀ (n : ℕ), 0 < a n
 hbd : ∀ (n : ℕ), 2 * c (n + 1) ≤ c n + C * (a n - a (n + 1))
 hbd' : ∀ (n : ℕ), (Finset.range (n + 1)).sum c ≤ 2 * c 0 + C * a 0
 hs : ∀ (n : ℕ), sum (n + 1) = sum n + ‖z (n + 1) - z n‖
 hc : ∀ (n : ℕ), sum (n + LL + 1) = sum (n + LL) + c n
 ⊢ sum LL + (Finset.range (0 + 1)).sum c = sum (0 + LL) + c 0]