import Mathlib
import Optlib


open Set InnerProductSpace Topology Filter InnerProduct

open scoped Pointwise

theorem extracted_formal_statement_58.{u_3, u_2, u_1} {E₁ : Type u_1} {E₂ : Type u_2} {F : Type u_3}
  [inst : NormedAddCommGroup E₁] [inst_1 : InnerProductSpace ℝ E₁] [inst_2 : FiniteDimensional ℝ E₁]
  [inst_3 : NormedAddCommGroup E₂] [inst_4 : InnerProductSpace ℝ E₂] [inst_5 : FiniteDimensional ℝ E₂]
  [inst_6 : NormedAddCommGroup F] [inst_7 : InnerProductSpace ℝ F] [inst_8 : FiniteDimensional ℝ F]
  {admm : ADMM E₁ E₂ F} {admm_kkt : Existance_of_kkt admm} [inst_9 : Setting E₁ E₂ F admm admm_kkt]
  (htau : 1 < ADMM.τ E₁ E₂ F) (n : ℕ+) :
  let x_diff := ADMM.x₂ E₁ F (↑n + 1) - ADMM.x₂ E₁ F ↑n;
  let r_n := (OptProblem.A₁ E₂) (ADMM.x₁ E₂ F ↑n) + (OptProblem.A₂ E₁) (ADMM.x₂ E₁ F ↑n) - OptProblem.b E₁ E₂;
  2 * M (n + 1) = (ADMM.τ E₁ E₂ F - 1) * ADMM.ρ E₁ E₂ F * (-2 * ⟪(OptProblem.A₂ E₁) x_diff, r_n⟫_ℝ) →
    2 * M (n + 1) ≤
        (ADMM.τ E₁ E₂ F ^ 2 - ADMM.τ E₁ E₂ F) * ADMM.ρ E₁ E₂ F * ‖(OptProblem.A₂ E₁) x_diff‖ ^ 2 +
          (1 - 1 / ADMM.τ E₁ E₂ F) * ADMM.ρ E₁ E₂ F * ‖r_n‖ ^ 2 →
      (ADMM.τ E₁ E₂ F - 1) * ADMM.ρ E₁ E₂ F * (-2 * ⟪(OptProblem.A₂ E₁) x_diff, r_n⟫_ℝ) ≤
        (ADMM.τ E₁ E₂ F ^ 2 - ADMM.τ E₁ E₂ F) * ADMM.ρ E₁ E₂ F * ‖(OptProblem.A₂ E₁) x_diff‖ ^ 2 +
          (1 - 1 / ADMM.τ E₁ E₂ F) * ADMM.ρ E₁ E₂ F * ‖r_n‖ ^ 2 := sorry

Tactic state before:
E₁ : Type u_1
E₂ : Type u_2
F : Type u_3
inst✝⁹ : NormedAddCommGroup E₁
inst✝⁸ : InnerProductSpace ℝ E₁
inst✝⁷ : FiniteDimensional ℝ E₁
inst✝⁶ : NormedAddCommGroup E₂
inst✝⁵ : InnerProductSpace ℝ E₂
inst✝⁴ : FiniteDimensional ℝ E₂
inst✝³ : NormedAddCommGroup F
inst✝² : InnerProductSpace ℝ F
inst✝¹ : FiniteDimensional ℝ F
admm : ADMM E₁ E₂ F
admm_kkt : Existance_of_kkt admm
inst✝ : Setting E₁ E₂ F admm admm_kkt
htau : 1 < ADMM.τ E₁ E₂ F
n : ℕ+
x_diff : E₂ := ADMM.x₂ E₁ F (↑n + 1) - ADMM.x₂ E₁ F ↑n
r_n : F := (OptProblem.A₁ E₂) (ADMM.x₁ E₂ F ↑n) + (OptProblem.A₂ E₁) (ADMM.x₂ E₁ F ↑n) - OptProblem.b E₁ E₂
r_n_1 : F :=
  (OptProblem.A₁ E₂) (ADMM.x₁ E₂ F (↑n + 1)) + (OptProblem.A₂ E₁) (ADMM.x₂ E₁ F (↑n + 1)) - OptProblem.b E₁ E₂
e_sum : F := (OptProblem.A₁ E₂) (e₁ ↑n) + (OptProblem.A₂ E₁) (e₂ ↑n)
e_sum_1 : F := (OptProblem.A₁ E₂) (e₁ (↑n + 1)) + (OptProblem.A₂ E₁) (e₂ (↑n + 1))
a₁ : ℝ := 1 / (ADMM.τ E₁ E₂ F * ADMM.ρ E₁ E₂ F) * ‖ey ↑n‖ ^ 2
a₂ : ℝ := 1 / (ADMM.τ E₁ E₂ F * ADMM.ρ E₁ E₂ F) * ‖ey (↑n + 1)‖ ^ 2
b₁ : ℝ := ADMM.ρ E₁ E₂ F * ‖(OptProblem.A₂ E₁) (e₂ ↑n)‖ ^ 2
b₂ : ℝ := ADMM.ρ E₁ E₂ F * ‖(OptProblem.A₂ E₁) (e₂ (↑n + 1))‖ ^ 2
c₁ : ℝ := (1 - 1 / ADMM.τ E₁ E₂ F) * ADMM.ρ E₁ E₂ F * ‖e_sum‖ ^ 2
c₂ : ℝ := (1 - 1 / ADMM.τ E₁ E₂ F) * ADMM.ρ E₁ E₂ F * ‖e_sum_1‖ ^ 2
d₁ : ℝ := (1 + ADMM.τ E₁ E₂ F - ADMM.τ E₁ E₂ F ^ 2) * ADMM.ρ E₁ E₂ F * ‖(OptProblem.A₂ E₁) x_diff‖ ^ 2
d₂ : ℝ := (1 + 1 / ADMM.τ E₁ E₂ F - ADMM.τ E₁ E₂ F) * ADMM.ρ E₁ E₂ F * ‖r_n_1‖ ^ 2
h1 : 2 * M (n + 1) = (ADMM.τ E₁ E₂ F - 1) * ADMM.ρ E₁ E₂ F * (-2 * ⟪(OptProblem.A₂ E₁) x_diff, r_n⟫_ℝ)
⊢ 2 * M (n + 1) ≤
    (ADMM.τ E₁ E₂ F ^ 2 - ADMM.τ E₁ E₂ F) * ADMM.ρ E₁ E₂ F * ‖(OptProblem.A₂ E₁) x_diff‖ ^ 2 +
      (1 - 1 / ADMM.τ E₁ E₂ F) * ADMM.ρ E₁ E₂ F * ‖r_n‖ ^ 2

Tactic:
rw [h1]
    have h2 :
  (τ - 1) * ρ * (-2 * (inner (A₂ x_diff) (r_n))) ≤
    (τ - 1) * ρ * (τ * ‖A₂ x_diff‖ ^ 2 + 1 / τ * ‖A₁ (x₁ n) + A₂ (x₂ n) - b‖ ^ 2) :=
  by
  have iequ : -2 * (inner (A₂ x_diff) (r_n)) ≤ τ * ‖A₂ x_diff‖ ^ 2 + (1 / τ) * ‖r_n‖ ^ 2 := by simp only [x_diff, r_n];
    apply basic_inequ₂
  have cpos : (τ - 1) * ρ ≥ 0 := by
    apply mul_nonneg_iff.2
    left; constructor; · linarith
    · linarith [admm.hrho]
  apply mul_le_mul_of_nonneg_left iequ cpos
    have h3 :
  (τ - 1) * ρ * (τ * ‖A₂ x_diff‖ ^ 2 + 1 / τ * ‖A₁ (x₁ n) + A₂ (x₂ n) - b‖ ^ 2) =
    (τ ^ 2 - τ) * ρ * ‖A₂ x_diff‖ ^ 2 + (1 - 1 / τ) * ρ * ‖r_n‖ ^ 2 :=
  by
  to_theorem
    rw [mul_add ((τ - 1) * ρ), ← mul_assoc, ←
      mul_assoc]rw [mul_comm (τ - 1) ρ, mul_assoc ρ,
      mul_assoc ρ (τ - 1)]rw [sub_mul τ 1 τ, sub_mul τ 1 (1 / τ), mul_comm ρ, mul_comm ρ]
  rw [pow_two τ, one_mul, mul_one_div_cancel (by linarith [htau]), one_mul]

Tactic state after:
[E₁ : Type u_1
 E₂ : Type u_2
 F : Type u_3
 inst✝⁹ : NormedAddCommGroup E₁
 inst✝⁸ : InnerProductSpace ℝ E₁
 inst✝⁷ : FiniteDimensional ℝ E₁
 inst✝⁶ : NormedAddCommGroup E₂
 inst✝⁵ : InnerProductSpace ℝ E₂
 inst✝⁴ : FiniteDimensional ℝ E₂
 inst✝³ : NormedAddCommGroup F
 inst✝² : InnerProductSpace ℝ F
 inst✝¹ : FiniteDimensional ℝ F
 admm : ADMM E₁ E₂ F
 admm_kkt : Existance_of_kkt admm
 inst✝ : Setting E₁ E₂ F admm admm_kkt
 htau : 1 < ADMM.τ E₁ E₂ F
 n : ℕ+
 x_diff : E₂ := ADMM.x₂ E₁ F (↑n + 1) - ADMM.x₂ E₁ F ↑n
 r_n : F := (OptProblem.A₁ E₂) (ADMM.x₁ E₂ F ↑n) + (OptProblem.A₂ E₁) (ADMM.x₂ E₁ F ↑n) - OptProblem.b E₁ E₂
 r_n_1 : F :=
   (OptProblem.A₁ E₂) (ADMM.x₁ E₂ F (↑n + 1)) + (OptProblem.A₂ E₁) (ADMM.x₂ E₁ F (↑n + 1)) - OptProblem.b E₁ E₂
 e_sum : F := (OptProblem.A₁ E₂) (e₁ ↑n) + (OptProblem.A₂ E₁) (e₂ ↑n)
 e_sum_1 : F := (OptProblem.A₁ E₂) (e₁ (↑n + 1)) + (OptProblem.A₂ E₁) (e₂ (↑n + 1))
 a₁ : ℝ := 1 / (ADMM.τ E₁ E₂ F * ADMM.ρ E₁ E₂ F) * ‖ey ↑n‖ ^ 2
 a₂ : ℝ := 1 / (ADMM.τ E₁ E₂ F * ADMM.ρ E₁ E₂ F) * ‖ey (↑n + 1)‖ ^ 2
 b₁ : ℝ := ADMM.ρ E₁ E₂ F * ‖(OptProblem.A₂ E₁) (e₂ ↑n)‖ ^ 2
 b₂ : ℝ := ADMM.ρ E₁ E₂ F * ‖(OptProblem.A₂ E₁) (e₂ (↑n + 1))‖ ^ 2
 c₁ : ℝ := (1 - 1 / ADMM.τ E₁ E₂ F) * ADMM.ρ E₁ E₂ F * ‖e_sum‖ ^ 2
 c₂ : ℝ := (1 - 1 / ADMM.τ E₁ E₂ F) * ADMM.ρ E₁ E₂ F * ‖e_sum_1‖ ^ 2
 d₁ : ℝ := (1 + ADMM.τ E₁ E₂ F - ADMM.τ E₁ E₂ F ^ 2) * ADMM.ρ E₁ E₂ F * ‖(OptProblem.A₂ E₁) x_diff‖ ^ 2
 d₂ : ℝ := (1 + 1 / ADMM.τ E₁ E₂ F - ADMM.τ E₁ E₂ F) * ADMM.ρ E₁ E₂ F * ‖r_n_1‖ ^ 2
 h1 : 2 * M (n + 1) = (ADMM.τ E₁ E₂ F - 1) * ADMM.ρ E₁ E₂ F * (-2 * ⟪(OptProblem.A₂ E₁) x_diff, r_n⟫_ℝ)
 h2 :
   (ADMM.τ E₁ E₂ F - 1) * ADMM.ρ E₁ E₂ F * (-2 * ⟪(OptProblem.A₂ E₁) x_diff, r_n⟫_ℝ) ≤
     (ADMM.τ E₁ E₂ F - 1) * ADMM.ρ E₁ E₂ F *
       (ADMM.τ E₁ E₂ F * ‖(OptProblem.A₂ E₁) x_diff‖ ^ 2 +
         1 / ADMM.τ E₁ E₂ F *
           ‖(OptProblem.A₁ E₂) (ADMM.x₁ E₂ F ↑n) + (OptProblem.A₂ E₁) (ADMM.x₂ E₁ F ↑n) - OptProblem.b E₁ E₂‖ ^ 2)
 h3 :
   (ADMM.τ E₁ E₂ F - 1) * ADMM.ρ E₁ E₂ F *
       (ADMM.τ E₁ E₂ F * ‖(OptProblem.A₂ E₁) x_diff‖ ^ 2 +
         1 / ADMM.τ E₁ E₂ F *
           ‖(OptProblem.A₁ E₂) (ADMM.x₁ E₂ F ↑n) + (OptProblem.A₂ E₁) (ADMM.x₂ E₁ F ↑n) - OptProblem.b E₁ E₂‖ ^ 2) =
     (ADMM.τ E₁ E₂ F ^ 2 - ADMM.τ E₁ E₂ F) * ADMM.ρ E₁ E₂ F * ‖(OptProblem.A₂ E₁) x_diff‖ ^ 2 +
       (1 - 1 / ADMM.τ E₁ E₂ F) * ADMM.ρ E₁ E₂ F * ‖r_n‖ ^ 2
 ⊢ (ADMM.τ E₁ E₂ F - 1) * ADMM.ρ E₁ E₂ F * (-2 * ⟪(OptProblem.A₂ E₁) x_diff, r_n⟫_ℝ) ≤
     (ADMM.τ E₁ E₂ F ^ 2 - ADMM.τ E₁ E₂ F) * ADMM.ρ E₁ E₂ F * ‖(OptProblem.A₂ E₁) x_diff‖ ^ 2 +
       (1 - 1 / ADMM.τ E₁ E₂ F) * ADMM.ρ E₁ E₂ F * ‖r_n‖ ^ 2]