NLA-lib Explorer

Newton–Schulz sign iteration

Use a polynomial iteration to approximate a matrix sign function.

Implementation guides

Definition

Definition (Newton–Schulz sign iteration). Scale a Hermitian matrix to obtain an initial iterate \mathbf{X}_0, then apply

\mathbf{X}_{j+1}=\tfrac12\mathbf{X}_j(3\mathbf{I}-\mathbf{X}_j^2).

The scalar polynomial has fixed points at -1, 0, and 1. Approximating the matrix sign requires a suitable initial scale and a spectral gap away from zero. A capped implementation returns a defined iterate even when its numerical convergence conditions have not been established.

Copy link

Results

Theorem (Accuracy of the Newton–Schulz sign algorithm).

(Theorem 2.6): under the arithmetic contract NLAlib.FloatMachine.IsArithAccurate u \tau \Omega with product constant \mu, \mu(n) \ge 0, u \ge 0, 0 \le \tau, 2n\tau \le 1 and 9(n + 1) \le \Omega, let the stored \mathbf{A} have Hermitian decoding (written \mathbf{A}) with \|\mathbf{A}\|_2 \le b and every eigenvalue of modulus at least a > 0, for stored b and \varepsilon with 0 < \varepsilon \le 1/2 (decoded values). With N_0 = N(a/(2b), \varepsilon/(16n)) (NLAlib.newtonSchulzSteps), if 640\, n^{3/2}\,(8 + \mu(n))\,(N_0 + 1)\,u \le \frac{a}{b}\,\varepsilon and the step limit is at least N_0, then \|\operatorname{sign}(\mathbf{A}) - \mathsf{newtonSchulzSign}(\mathbf{A}, \varepsilon, b)\|_2 \le \varepsilon \,, \mathsf{newtonSchulzSign} the algorithm NLAlib.newtonSchulzSign. [Shah2024, Theorem 2.6], there with u \le (a/b)\varepsilon/(4\max(N n\mu_g(n, 1.1), n^2)), N = N(a/b, \varepsilon/(8n)) and the contour bound of Lemma 2.2; here the perturbation bound is dimension-free and the factor n^{3/2} comes from the Hermitian rounding and the stopping test.

Lean statement and details
NLAlib.FloatMachine.IsArithAccurate.specNorm_cfc_sign_sub_decodeMatrix_newtonSchulzSign_le.{u_1}
  {F : Type u_1} {M : FloatMachine F ℝ ℂ} {dec : F → ℝ} {u τ Ω : ℝ} {μ : ℕ → ℝ} {n : ℕ}
  (hM : M.IsArithAccurate dec u τ Ω μ) (hμ : 0 ≤ μ n) (hu₀ : 0 ≤ u) (hτ₀ : 0 ≤ τ)
  (hτ : τ * (2 * ↑n) ≤ 1) (hΩ : 9 * (↑n + 1) ≤ Ω) {A : Matrix (Fin n) (Fin n) (F × F)}
  (hA : (decodeMatrix dec A).IsHermitian) {a : ℝ} {b ε : F} (ha : 0 < a)
  (hspec : ∀ x ∈ spectrum ℝ (decodeMatrix dec A), a ≤ |x|)
  (hb : specNorm (decodeMatrix dec A) ≤ dec b) (hε : 0 < dec ε) (hε₁ : dec ε ≤ 1 / 2)
  (hu :
    640 * ↑n * √↑n * (8 + μ n) * (newtonSchulzSteps (a / (2 * dec b)) (dec ε / (16 * ↑n)) + 1) * u ≤
      a / dec b * dec ε)
  {N : ℕ} (hN : newtonSchulzSteps (a / (2 * dec b)) (dec ε / (16 * ↑n)) ≤ ↑N) :
  specNorm (cfc Real.sign (decodeMatrix dec A) - decodeMatrix dec (newtonSchulzSign M ε b N A)) ≤
    dec ε

Full source on GitHub

Copy link

Theorem (Convergence of the perturbed Newton–Schulz iteration).

(Lemma 2.5): if 0 < \varepsilon \le 3/80, 10u \le \varepsilon, x_0 \ne 0 with 20u \le \lvert x_0 \rvert \le 3/2, and \lvert x_{k+1} - g(x_k) \rvert \le u for every k, then for every natural N \ge N(x_0, \varepsilon) (NLAlib.newtonSchulzSteps), \lvert 1 - x_N^2 \rvert \le \varepsilon \,. [Shah2024, Lemma 2.5]; there x_0 \ne 0 is implicit in u > 0.

Lean statement and details
NLAlib.abs_one_sub_sq_le_of_newtonSchulzSteps_le {u ε : ℝ} {x : ℕ → ℝ} (hε : 0 < ε)
  (hε₁ : 10 * u ≤ ε) (hε₂ : ε ≤ 3 / 80) (h₀ : 0 < |x 0|) (h₂₀ : 20 * u ≤ |x 0|)
  (hx₀ : |x 0| ≤ 3 / 2) (hstep : ∀ (k : ℕ), |x (k + 1) - newtonSchulz (x k)| ≤ u) {N : ℕ}
  (hN : newtonSchulzSteps (x 0) ε ≤ ↑N) : |1 - x N ^ 2| ≤ ε

Full source on GitHub

Copy link

Theorem (Quadratic decrease of the defect under perturbation).

(Lemma 2.4, first part): if 20\lvert \xi \rvert \le \lvert x \rvert \le 1 - \sqrt{10\lvert \xi \rvert}, then \lvert 1 - (g(x) + \xi)^2 \rvert \le \lvert 1 - x^2 \rvert^2 \,. [Shah2024, Lemma 2.4].

Lean statement and details
NLAlib.abs_one_sub_newtonSchulz_add_sq_le {x ξ : ℝ} (h₁ : 20 * |ξ| ≤ |x|)
  (h₂ : |x| ≤ 1 - √(10 * |ξ|)) : |1 - (newtonSchulz x + ξ) ^ 2| ≤ |1 - x ^ 2| ^ 2

Full source on GitHub

Copy link

Theorem (The defect bound with an additive error).

(Lemma 2.4, second part): if \lvert x \rvert \le \sqrt2 and \lvert \xi \rvert \le 1, then \lvert 1 - (g(x) + \xi)^2 \rvert \le \lvert 1 - x^2 \rvert^2 + 4\lvert \xi \rvert \,. [Shah2024, Lemma 2.4].

Lean statement and details
NLAlib.abs_one_sub_newtonSchulz_add_sq_le_add {x ξ : ℝ} (hx : |x| ≤ √2) (hξ : |ξ| ≤ 1) :
  |1 - (newtonSchulz x + ξ) ^ 2| ≤ |1 - x ^ 2| ^ 2 + 4 * |ξ|

Full source on GitHub

Copy link

Theorem (The perturbed Newton–Schulz step keeps the sign).

(Lemma 2.3, first part): if \lvert \xi \rvert \le u and u < \lvert x \rvert < \sqrt3 - (\sqrt3 - 1)u, then g(x) + \xi has the sign of x, that is x(g(x) + \xi) > 0. [Shah2024, Lemma 2.3], there with u \le 3/16, not needed here.

Lean statement and details
NLAlib.mul_newtonSchulz_add_pos {u x ξ : ℝ} (hξ : |ξ| ≤ u) (hux : u < |x|)
  (hx : |x| < √3 - (√3 - 1) * u) : 0 < x * (newtonSchulz x + ξ)

Full source on GitHub

Copy link

Theorem (The perturbed Newton–Schulz step does not decrease the modulus).

(Lemma 2.3, second part): if \lvert \xi \rvert \le u and \tfrac83 u \le \lvert x \rvert \le 1 - \tfrac83 u, then \lvert x \rvert \le \lvert g(x) + \xi \rvert. [Shah2024, Lemma 2.3].

Lean statement and details
NLAlib.abs_le_abs_newtonSchulz_add {u x ξ : ℝ} (hξ : |ξ| ≤ u) (h₁ : 8 / 3 * u ≤ |x|)
  (h₂ : |x| ≤ 1 - 8 / 3 * u) : |x| ≤ |newtonSchulz x + ξ|

Full source on GitHub

Copy link

Theorem (One rounded Newton–Schulz step).

(Lemma 2.1): under the arithmetic contract NLAlib.FloatMachine.IsArithAccurate u \tau \Omega with product constant \mu, \mu(n) \ge 0, u \ge 0, u(8 + \mu(n)) \le 1/10, 0 \le \tau, 2n\tau \le 1 and \Omega \ge 9, every stored \mathbf{A} whose decoding (still written \mathbf{A}) is Hermitian with \|\mathbf{A}\|_2 \le 11/10 satisfies \Bigl\|\tfrac12\mathbf{A}(3\mathbf{I} - \mathbf{A}^2) - \tilde g(\mathbf{A})\Bigr\|_2 \le 4\sqrt n\,(8 + \mu(n))\,u \,, \tilde g the decoded rounded step NLAlib.newtonSchulzRounded (constants 3 and 4 computed by the machine's conversion). [Shah2024, Lemma 2.1], there \tfrac12(7 + (6 + \mu)a^2)a\,u for \|\mathbf{A}\|_2 \le a without the Hermitian part; the factor \sqrt n is the cost of storing the result exactly Hermitian, and the statement is for the regime a \le 11/10 of the iteration.

Lean statement and details
NLAlib.FloatMachine.IsArithAccurate.specNorm_sub_decodeMatrix_newtonSchulzRounded_le.{u_4}
  {F : Type u_4} {M : FloatMachine F ℝ ℂ} {dec : F → ℝ} {u τ Ω : ℝ} {μ : ℕ → ℝ} {n : ℕ}
  (hM : M.IsArithAccurate dec u τ Ω μ) (hμ : 0 ≤ μ n) (hu₀ : 0 ≤ u) (hu : u * (8 + μ n) ≤ 1 / 10)
  (hτ₀ : 0 ≤ τ) (hτ : τ * (2 * ↑n) ≤ 1) (hΩ : 9 ≤ Ω) {A : Matrix (Fin n) (Fin n) (F × F)}
  (hA : (decodeMatrix dec A).IsHermitian) (hA₁ : specNorm (decodeMatrix dec A) ≤ 11 / 10) :
  specNorm
      (2⁻¹ • (decodeMatrix dec A * (3 • 1 - decodeMatrix dec A * decodeMatrix dec A)) -
        decodeMatrix dec (newtonSchulzRounded M A)) ≤
    4 * √↑n * (8 + μ n) * u

Full source on GitHub

Copy link

Theorem (Singular directions of the inverse-free polar iteration).

The kth matrix iterate acts by the kth iterate of the real cubic on each supplied singular coordinate. [Higham2008, §8.3].

Lean statement and details
NLAlib.IsSVD.polarSchulzIterate_eq.{u_1, u_2, u_3, u_4} {𝕜 : Type u_1} {m : Type u_2} {n : Type u_3}
  {r : Type u_4} [RCLike 𝕜] [Fintype m] [Fintype n] [Fintype r] [DecidableEq n] [DecidableEq r]
  {A : Matrix m n 𝕜} {U : Matrix m r 𝕜} {V : Matrix n r 𝕜} {σ : r → ℝ} (h : IsSVD A U σ V) (k : ℕ) :
  polarSchulzIterate A k = (U * diagonal fun i ↦ ↑(newtonSchulz^[k] (σ i))) * Vᴴ

Full source on GitHub

Copy link

Used by other algorithms

Mathematical background

Appears under these tasks