theorem extracted_formal_statement_13 {n m : ℕ+} {b : Fin ↑m → ℝ} {A : Matrix (Fin ↑m) (Fin ↑n) ℝ}
  (x : EuclideanSpace ℝ (Fin ↑n)) :
  let f := fun x => 1 / 2 * A *ᵥ x ⬝ᵥ A *ᵥ x;
  let f' := fun x => Aᵀ *ᵥ A *ᵥ x;
  HasGradientAt f (f' x) x →
    let h := fun x => b ⬝ᵥ A *ᵥ x;
    let h' := fun x => Aᵀ *ᵥ b;
    HasGradientAt h (h' x) x →
      ∀ (z : EuclideanSpace ℝ (Fin ↑n)),
        2⁻¹ * (A *ᵥ z ⬝ᵥ A *ᵥ z - b ⬝ᵥ A *ᵥ z - (A *ᵥ z ⬝ᵥ b - b ⬝ᵥ b)) =
          2⁻¹ * A *ᵥ z ⬝ᵥ A *ᵥ z - b ⬝ᵥ A *ᵥ z + 2⁻¹ * b ⬝ᵥ b := sorry

State before:
case h
n m : ℕ+
b : Fin ↑m → ℝ
A : Matrix (Fin ↑m) (Fin ↑n) ℝ
x : EuclideanSpace ℝ (Fin ↑n)
f : EuclideanSpace ℝ (Fin ↑n) → ℝ := fun x => 1 / 2 * A *ᵥ x ⬝ᵥ A *ᵥ x
f' : EuclideanSpace ℝ (Fin ↑n) → Fin ↑n → ℝ := fun x => Aᵀ *ᵥ A *ᵥ x
fgradient : HasGradientAt f (f' x) x
h : EuclideanSpace ℝ (Fin ↑n) → ℝ := fun x => b ⬝ᵥ A *ᵥ x
h' : EuclideanSpace ℝ (Fin ↑n) → Fin ↑n → ℝ := fun x => Aᵀ *ᵥ b
hgradient : HasGradientAt h (h' x) x
φ : EuclideanSpace ℝ (Fin ↑n) → ℝ := fun x => 1 / 2 * ‖A *ᵥ x - b‖ ^ 2
φ' : EuclideanSpace ℝ (Fin ↑n) → Fin ↑n → ℝ := fun x => Aᵀ *ᵥ (A *ᵥ x - b)
z : EuclideanSpace ℝ (Fin ↑n)
⊢ 2⁻¹ * (A *ᵥ z ⬝ᵥ A *ᵥ z - b ⬝ᵥ A *ᵥ z - (A *ᵥ z ⬝ᵥ b - b ⬝ᵥ b)) = 2⁻¹ * A *ᵥ z ⬝ᵥ A *ᵥ z - b ⬝ᵥ A *ᵥ z + 2⁻¹ * b ⬝ᵥ b

Tactic: rw [← sub_add, dotProduct_comm _ b, sub_sub, ← two_mul, mul_add, mul_sub, ← mul_assoc]
    rw [inv_mul_cancel₀, one_mul]
    simp

State after:

Relevant lemmas:
two_mul : ∀ {α : Type u} [inst : NonAssocSemiring α] (n : α), 2 * n = n + n
dotProduct_comm : ∀ {m : Type u_2} {α : Type v} [inst : Fintype m] [inst_1 : AddCommMonoid α] [inst_2 : CommMagma α]
  (v w : m → α), v ⬝ᵥ w = w ⬝ᵥ v
sub_add : ∀ {α : Type u_1} [inst : SubtractionCommMonoid α] (a b c : α), a - b + c = a - (b - c)
mul_sub : ∀ {α : Type u} [inst : NonUnitalNonAssocRing α] (a b c : α), a * (b - c) = a * b - a * c
mul_add : ∀ {R : Type v} [inst : Mul R] [inst_1 : Add R] [inst_2 : LeftDistribClass R] (a b c : R),
  a * (b + c) = a * b + a * c
sub_sub : ∀ {α : Type u_1} [inst : SubtractionCommMonoid α] (a b c : α), a - b - c = a - (b + c)
mul_assoc : ∀ {G : Type u_1} [inst : Semigroup G] (a b c : G), a * b * c = a * (b * c)
one_mul : ∀ {M : Type u} [inst : MulOneClass M] (a : M), 1 * a = a
inv_mul_cancel₀ : ∀ {G₀ : Type u_3} [inst : GroupWithZero G₀] {a : G₀}, a ≠ 0 → a⁻¹ * a = 1