import Mathlib
import Optlib


open Filter Topology Set InnerProductSpace Finset

open Finset

theorem extracted_formal_statement_10.{u_1} {E : Type u_1} [inst : NormedAddCommGroup E] [inst_1 : InnerProductSpace ℝ E]
  {f : E → ℝ} (xm x₀ : E) {alg : subgradient_method f x₀} (hm : IsMinOn f Set.univ xm)
  (ha'' :
    ∀ (s : Set ℝ) (x : ℝ),
      (∀ (b : ℝ), x ≤ b → b ∈ s) → ∃ a, ∀ (b : ℕ), a ≤ b → (Finset.range (b + 1)).sum (subgradient_method.a f x₀) ∈ s)
  (s : Set ℝ)
  (ha' :
    ∀ (s x : Set ℝ),
      x ⊆ s →
        (∀ x_1 ∈ x, ∃ ε, 0 < ε ∧ Metric.ball x_1 ε ⊆ x) →
          0 ∈ x → ∃ a, ∀ (b : ℕ), a ≤ b → subgradient_method.a f x₀ b ∈ s)
  (t : Set ℝ) (hs₁ : t ⊆ s) (hs₂ : ∀ x ∈ t, ∃ ε, 0 < ε ∧ Metric.ball x ε ⊆ t) (hs₀ : 0 ∈ t) (ε : ℝ) (εpos : 0 < ε)
  (hs₂₀ : Metric.ball 0 ε ⊆ t) (a₁ : ℕ)
  (ha₁ : ∀ (b : ℕ), a₁ ≤ b → ‖x₀ - xm‖ ^ 2 / (2 * (Finset.range (b + 1)).sum (subgradient_method.a f x₀)) < ε / 2)
  (a₂ : ℕ)
  (ha₂ :
    ∀ (b : ℕ),
      a₂ ≤ b →
        (↑(subgradient_method.G f x₀) ^ 2 * ∑ i ∈ Finset.range (b + 1), subgradient_method.a f x₀ i ^ 2) /
            (2 * (Finset.range (b + 1)).sum (subgradient_method.a f x₀)) <
          ε / 2)
  (b : ℕ) (hb : a₁ ⊔ a₂ ≤ b) (hba₁ : b ≥ a₁) (hba₂ : b ≥ a₂)
  (h_original_goal : sInf {x | ∃ i < b + 1, f (subgradient_method.x f x₀ i) = x} - f xm ∈ s) :
  sInf {x | ∃ i < b + 1, f (subgradient_method.x f x₀ i) = x} - f xm < ε := sorry

Tactic state before:
case h
E : Type u_1
inst✝¹ : NormedAddCommGroup E
inst✝ : InnerProductSpace ℝ E
f : E → ℝ
xm x₀ : E
alg : subgradient_method f x₀
hm : IsMinOn f Set.univ xm
ha'' :
  ∀ (s : Set ℝ) (x : ℝ),
    (∀ (b : ℝ), x ≤ b → b ∈ s) → ∃ a, ∀ (b : ℕ), a ≤ b → (Finset.range (b + 1)).sum (subgradient_method.a f x₀) ∈ s
s : Set ℝ
ha' :
  ∀ (s x : Set ℝ),
    x ⊆ s →
      (∀ x_1 ∈ x, ∃ ε, 0 < ε ∧ Metric.ball x_1 ε ⊆ x) → 0 ∈ x → ∃ a, ∀ (b : ℕ), a ≤ b → subgradient_method.a f x₀ b ∈ s
t : Set ℝ
hs₁ : t ⊆ s
hs₂ : ∀ x ∈ t, ∃ ε, 0 < ε ∧ Metric.ball x ε ⊆ t
hs₀ : 0 ∈ t
ε : ℝ
εpos : 0 < ε
hs₂₀ : Metric.ball 0 ε ⊆ t
a₁ : ℕ
ha₁ : ∀ (b : ℕ), a₁ ≤ b → ‖x₀ - xm‖ ^ 2 / (2 * (Finset.range (b + 1)).sum (subgradient_method.a f x₀)) < ε / 2
a₂ : ℕ
ha₂ :
  ∀ (b : ℕ),
    a₂ ≤ b →
      (↑(subgradient_method.G f x₀) ^ 2 * ∑ i ∈ Finset.range (b + 1), subgradient_method.a f x₀ i ^ 2) /
          (2 * (Finset.range (b + 1)).sum (subgradient_method.a f x₀)) <
        ε / 2
b : ℕ
hb : a₁ ⊔ a₂ ≤ b
hba₁ : b ≥ a₁
hba₂ : b ≥ a₂
⊢ sInf {x | ∃ i < b + 1, f (subgradient_method.x f x₀ i) = x} - f xm ∈ s

Tactic:
apply hs₁
    apply hs₂₀
    simp
    have hne : sInf {x | ∃ i < b + 1, f (alg.x i) = x} - f xm ≥ 0 :=
  by
  have heq :
    (Set.range fun (x : Finset.range (b + 1)) => f (alg.x x)) = {x | ∃ i ∈ Finset.range (b + 1), f (alg.x i) = x} := by
    simp [Set.ext_iff]
  have hneb : Nonempty (Finset.range (b + 1)) := by simp; use 0; apply Nat.succ_pos b
  apply le_sub_right_of_add_le
  simp
  apply le_csInf
  · simp at heq; rw [← heq]; apply Set.range_nonempty
  · intro b hb; simp at hb
    rcases hb with ⟨i, _, hb₂⟩
    rw [← hb₂]; simp [isMinOn_univ_iff] at hm
    rcases hm (alg.x i) with hmi
    apply hmi
    rw [(abs_of_nonneg hne)]

Tactic state after:
[case h.a.a
 E : Type u_1
 inst✝¹ : NormedAddCommGroup E
 inst✝ : InnerProductSpace ℝ E
 f : E → ℝ
 xm x₀ : E
 alg : subgradient_method f x₀
 hm : IsMinOn f Set.univ xm
 ha'' :
   ∀ (s : Set ℝ) (x : ℝ),
     (∀ (b : ℝ), x ≤ b → b ∈ s) → ∃ a, ∀ (b : ℕ), a ≤ b → (Finset.range (b + 1)).sum (subgradient_method.a f x₀) ∈ s
 s : Set ℝ
 ha' :
   ∀ (s x : Set ℝ),
     x ⊆ s →
       (∀ x_1 ∈ x, ∃ ε, 0 < ε ∧ Metric.ball x_1 ε ⊆ x) → 0 ∈ x → ∃ a, ∀ (b : ℕ), a ≤ b → subgradient_method.a f x₀ b ∈ s
 t : Set ℝ
 hs₁ : t ⊆ s
 hs₂ : ∀ x ∈ t, ∃ ε, 0 < ε ∧ Metric.ball x ε ⊆ t
 hs₀ : 0 ∈ t
 ε : ℝ
 εpos : 0 < ε
 hs₂₀ : Metric.ball 0 ε ⊆ t
 a₁ : ℕ
 ha₁ : ∀ (b : ℕ), a₁ ≤ b → ‖x₀ - xm‖ ^ 2 / (2 * (Finset.range (b + 1)).sum (subgradient_method.a f x₀)) < ε / 2
 a₂ : ℕ
 ha₂ :
   ∀ (b : ℕ),
     a₂ ≤ b →
       (↑(subgradient_method.G f x₀) ^ 2 * ∑ i ∈ Finset.range (b + 1), subgradient_method.a f x₀ i ^ 2) /
           (2 * (Finset.range (b + 1)).sum (subgradient_method.a f x₀)) <
         ε / 2
 b : ℕ
 hb : a₁ ⊔ a₂ ≤ b
 hba₁ : b ≥ a₁
 hba₂ : b ≥ a₂
 hne : sInf {x | ∃ i < b + 1, f (subgradient_method.x f x₀ i) = x} - f xm ≥ 0
 ⊢ sInf {x | ∃ i < b + 1, f (subgradient_method.x f x₀ i) = x} - f xm < ε]