NLA-lib Explorer

Randomized, finite precision

Implementation of Hermitian spectral bisection (Shah)

Diagonalize a stored Hermitian matrix \mathbf{A}\in\mathbb{C}^{n\times n} by splitting its spectrum, solving the smaller problems, and assembling a basis \mathbf{U} and real values \mathbf{d}. This implementation follows Shah's randomized spectral-bisection method.

The precision bound grows logarithmically in dimension, inverse error tolerance, and inverse failure probability.

Implementation guides

Algorithm

Definition (Stored spectral bisection). Supply a radius bound R_0, tolerance \varepsilon, precision parameter \beta, depth budget L, sign-iteration cap c, and a random tape. Store complex entries as adjacent real and imaginary words.

  1. Store the root matrix and parameters in the root arena.
  2. At each downward level, draw n uniform words and 4n^2 Gaussian words.
  3. For each active node, read its matrix \mathbf{A}, radius R, tolerance, and depth counter \ell.
  4. For a singleton, store the identity basis and its real diagonal value.
  5. For a sufficiently small spectral window, store the identity basis and zero values.
  6. Otherwise, choose a sampled shift of scale R/\ell.
  7. Apply capped Newton–Schulz sign iteration to the shifted matrix, obtaining \mathbf{B}.
  8. Form \mathbf{P}_+=(\mathbf{B}+\mathbf{I})/2 and \mathbf{P}_-=-(\mathbf{B}-\mathbf{I})/2.
  9. Estimate the positive rank by rounding the computed trace of \mathbf{P}_+ and clamping it to the node dimension.
  10. If the rank is zero or the full dimension, store the corresponding shifted child.
  11. Otherwise, project Gaussian samples and apply QR to obtain \mathbf{Q}_+ and \mathbf{Q}_-.
  12. Compress the node matrix onto these bases and store the two shifted children.
  13. At the depth boundary, store identity bases and zero values.
  14. Traverse upward, combining child bases and restoring the eigenvalue shifts.
  15. Copy the root basis and values to the output buffers, then release scratch storage.

Each instruction uses the supplied arithmetic. In particular, one-half and the trace are computed with word operations. Reaching an iteration or depth cap produces a defined output; accuracy needs the assumptions below.

Lean statement and details
NLAlib.SpectralBisection.bisectionProgram {Op Tst : Type} [Ops.Has Ops.ScalarOp Op]
  [Ops.Has Ops.IndexOp Op] [Ops.Has Ops.SampleOp Op] [Ops.Has Ops.MatrixOp Op]
  [Ops.Has Ops.IdxTst Tst] [Ops.Has Ops.CmpTst Tst] : Ops.Program Op Tst 3 4

Full source on GitHub

Copy link

Model of arithmetic

All statements on this page are for

Floating-point machine, Shah's contract

Definitions of the arithmetic models

The dense word model supplies scalar arithmetic and decoding, matrix multiplication, full QR, comparisons, bounded integer conversions, and explicit random draws. Scalar transformations, copies, control flow, and allocation are counted separately. This is a parameterized arithmetic model; a concrete floating-point format must establish the primitive accuracy and range assumptions.

Matrix multiplication and QR have supplied work and workspace costs. The bounds below count abstract scalar cells, rather than bytes. Complex matrix entries occupy two cells.

Operations and Storage

Write T(k) for a monotone, superadditive bound on a matrix primitive whose largest dimension is k. Require this bound for every primitive shape, including zero dimensions. Let \mathcal{H}(n,L,c) denote the static program budget with matrix-kernel work set to zero: it includes scalar arithmetic, sampling, literals, queries, addressing, control flow, frames, and allocation.

Theorem (Work and sequential span). For n\ge2, with exact decoding of natural literals through \max(n,4) and the stated primitive cost contracts, both total work and sequential span are at most

\mathcal{H}(n,L,c)+(L+1)(2c+11)T(n).

At a node of dimension k, splitting costs at most (2c+9)T(k) in matrix work and reconstruction at most 2T(k). Disjoint node slots and superadditivity bound their sum at each level by the root-size term. The scalar budget \mathcal{H} remains conservative.

Lean statement and details
NLAlib.SpectralBisection.certifies_work {K : Type} [Inhabited K] (M : Ops.Machine K) (dec : K → ℝ)
  (mm : MatMulMap (K × K)) (qr : QRMap (K × K)) (domain : (Fin 3 → ℕ) → Prop)
  (admitted : ∃ d, domain d) (matrixWork matrixWorkspace : Ops.MatrixOp → List ℕ → ℕ) (T : ℕ → ℕ)
  (hLit : ∀ (d : Fin 3 → ℕ), domain d → Ops.IsExactNatLit dec M (max (d 0) 4))
  (hN : ∀ (d : Fin 3 → ℕ), domain d → 2 ≤ d 0) (hT : Monotone T)
  (hadd : ∀ (i j : ℕ), T i + T j ≤ T (i + j))
  (hMatrix : ∀ (o : Ops.MatrixOp) (ds : List ℕ), matrixWork o ds ≤ T (List.foldr max 0 ds)) :
  SpectralBisection.bisectionProgram.Certifies
    (Ops.Dense.functionalModel (SpectralBisection.problem domain admitted) M dec
      (Ops.EntryCodec.pair K) (fun {l m n} ↦ mm) (fun {m n} ↦ qr)
      (Ops.Dense.resources matrixWork matrixWorkspace))
    (SpectralBisection.workSpecification M dec (fun {l m n} ↦ mm) (fun {m n} ↦ qr) domain admitted
      matrixWorkspace T)

Full source on GitHub

Copy link

This work bound uses the supplied primitive costs. Counting bit operations additionally requires bit costs for scalar arithmetic, matrix multiplication, QR, and sampling; the precision requirement below specifies how accurately those primitives must operate.

Let E(n) be the maximum workspace cost of multiplication and QR over all call dimensions at most n; no monotonicity of workspace is required.

Theorem (Scratch storage). For n\ge2, peak scratch capacity is at most

6n^2L+32n^2+4nL+7n+2L+24+E(n).

The bound includes the arenas and nested scratch allocations. It is independent of the sign-iteration cap c.

Lean statement and details
NLAlib.SpectralBisection.staticPeak_workspaceEnvelope_le
  (matrixWork matrixWorkspace : Ops.MatrixOp → List ℕ → ℕ) (d : Fin 3 → ℕ) (hn : 2 ≤ d 0) :
  Ops.staticPeak (Ops.Dense.resources matrixWork matrixWorkspace) SpectralBisection.bisectionProgram
      d ≤
    6 * (d 0 * d 0) * d 1 + 32 * (d 0 * d 0) + 4 * d 0 * d 1 + 7 * d 0 + 2 * d 1 + 24 +
      Ops.MatrixOp.workspaceEnvelope matrixWorkspace (d 0)

Full source on GitHub

Copy link

Theorem (Resident storage). For n\ge2, including the supplied input, parameter, and output buffers, total resident capacity is at most

6n^2L+36n^2+4nL+8n+2L+27+E(n).

The supplied buffers contribute 4n^2+n+3 cells.

Lean statement and details
NLAlib.SpectralBisection.initialBytes_add_staticPeak_workspaceEnvelope_le {K : Type} [Inhabited K]
  {domain : (Fin 3 → ℕ) → Prop} {admitted : ∃ d, domain d}
  (matrixWork matrixWorkspace : Ops.MatrixOp → List ℕ → ℕ) (d : Fin 3 → ℕ)
  (x : (SpectralBisection.problem domain admitted).Input d) (hn : 2 ≤ d 0) :
  (SpectralBisection.problem domain admitted).initialBytes d x +
      Ops.staticPeak (Ops.Dense.resources matrixWork matrixWorkspace)
        SpectralBisection.bisectionProgram d ≤
    6 * (d 0 * d 0) * d 1 + 36 * (d 0 * d 0) + 4 * d 0 * d 1 + 8 * d 0 + 2 * d 1 + 27 +
      Ops.MatrixOp.workspaceEnvelope matrixWorkspace (d 0)

Full source on GitHub

Copy link

Accuracy

Theorem (Execution agrees with the word algorithm). Under the primitive contracts, readable inputs, sufficient separated output capacity, and exact bounded dimension literals, the solver terminates and stores exactly the basis and values returned by the mathematical word algorithm with the same arithmetic and random tape. It consumes exactly

(L+1)(n+4n^2)

random words and releases its scoped scratch storage. This correspondence does not require a numerical-success assumption.

Lean statement and details
NLAlib.SpectralBisection.bisectionRoutine_meets {K Op Tst : Type} [Inhabited K]
  [Ops.Has Ops.ScalarOp Op] [Ops.Has Ops.IndexOp Op] [Ops.Has Ops.SampleOp Op]
  [Ops.Has Ops.MatrixOp Op] [Ops.Has Ops.CmpTst Tst] [Ops.Has Ops.IdxTst Tst] (M : Ops.Machine K)
  (dec : K → ℝ) (mm : MatMulMap (K × K)) (qr : QRMap (K × K)) (R0 eps beta : K) {n : ℕ}
  (A : Matrix (Fin n) (Fin n) (K × K)) {I : Ops.Interp Op Tst K} (hS : Ops.IsScalar M I)
  (hL : Ops.IsIndexLit M I) (hC : Ops.IsCmp dec I)
  (hMM : Ops.IsMatrixMul (Ops.EntryCodec.pair K) (fun {l m n} ↦ mm) I)
  (hQR : Ops.IsMatrixQR (Ops.EntryCodec.pair K) (fun {m n} ↦ qr) I) (hQ : Ops.IsToNat dec I)
  (hSample : Ops.IsSample I) :
  SpectralBisection.bisectionRoutine.Meets I
    (SpectralBisection.bisectionSpec M dec (fun {l m n} ↦ mm) (fun {m n} ↦ qr) R0 eps beta A)

Full source on GitHub

Copy link

Theorem (Precision in bits). Let \mathbf{A}\in\mathbb{C}^{n\times n} be Hermitian, with n\ge1 and \|\mathbf{A}\|_2\le R_0, where R_0>0. Given an accuracy target 0<\varepsilon\le2^{-15} and failure probability 0<\theta\le1, write

\Lambda=\log_2\frac1\varepsilon+\log_2\frac1\theta+\log_2 n.

For arithmetic with unit roundoff u=2^{-p}, the numerical reference has the accuracy guarantee below if

p\ge\log_2\frac1\varepsilon+\frac32\log_2\frac1\theta+\frac72\log_2 n+4\log_2\Lambda+24.

Use depth L=\lceil\log_2(1/\varepsilon)\rceil+5, sign-iteration cap c\ge\lceil4\Lambda\rceil, and a stored parameter satisfying

\frac{\varepsilon\sqrt\theta}{2048(n\Lambda)^{3/2}}\le\beta\le\frac{\varepsilon\sqrt\theta}{1024(n\Lambda)^{3/2}}.

The arithmetic must meet the primitive accuracy contracts with \mu_{\mathrm{MM}}(d)=\mu_{\mathrm{QR}}(d)=2d and c_{\mathrm{N}}=\sqrt2. Its absolute-error floor \tau\ge0 and range \Omega must satisfy

300n^3\tau\le\varepsilon\theta\min(R_0,1),\qquad64(R_0+n+\Lambda)\le\Omega.

With independent node samples having the prescribed uniform/Gaussian law and the theorem's sampler measurability assumptions, the reference output satisfies

\|\mathbf{A}-\mathbf{U}\operatorname{diag}(\mathbf{d})\mathbf{U}^{\mathsf{H}}\|_2\le2\varepsilon R_0,

(1-\varepsilon/3)^2\mathbf{I}\preceq\mathbf{U}^{\mathsf{H}}\mathbf{U}\preceq(1+\varepsilon/3)^2\mathbf{I}

with probability at least 1-\theta. Thus sufficient precision grows logarithmically with dimension, inverse tolerance, and inverse failure probability. For example, n=1000, \varepsilon=2^{-15} and \theta=1/100 require 104 bits by this bound, giving a success probability of at least 99\% under the stated assumptions.

Lean statement and details
NLAlib.FloatMachine.IsAccurate.measureReal_not_isApproxDiagonalization_eigh_bisectionDepth_le_of_logb_le_of_hasLaw_eighSampleLaw.{u_1,
    u_2}
  {F : Type u_1} {M : FloatMachine F ℝ ℂ} {dec : F → ℝ} {u τ Ω : ℝ}
  (hM : M.IsAccurate dec u τ Ω (fun d ↦ 2 * ↑d) (fun d ↦ 2 * ↑d) √2)
  (hunifm : ∀ (c z : F), MeasurableSet (M.unif c ⁻¹' {z}))
  (hunifc : ∀ (c : F), (Set.range (M.unif c)).Countable)
  (hnormalm : ∀ (z : F × F), MeasurableSet (M.normal ⁻¹' {z}))
  (hnormalc : (Set.range M.normal).Countable) {n : ℕ} (hn : 1 ≤ n)
  {A : Matrix (Fin n) (Fin n) (F × F)} (hA : (decodeMatrix dec A).IsHermitian) {R₀ ε β : F} {θ : ℝ}
  (hR₀ : specNorm (decodeMatrix dec A) ≤ dec R₀) (hR₀pos : 0 < dec R₀) (hε : 0 < dec ε)
  (hε₁ : dec ε ≤ 2⁻¹ ^ 15) (hθ : 0 < θ) (hθ₁ : θ ≤ 1) {Λ : ℝ}
  (hΛ : Λ = Real.logb 2 (dec ε)⁻¹ + Real.logb 2 θ⁻¹ + Real.logb 2 ↑n)
  (hβ : dec ε * √θ / (2048 * (↑n * Λ) * √(↑n * Λ)) ≤ dec β)
  (hβ' : dec β ≤ dec ε * √θ / (1024 * (↑n * Λ) * √(↑n * Λ)))
  (hbits :
    Real.logb 2 (dec ε)⁻¹ + 3 / 2 * Real.logb 2 θ⁻¹ + 7 / 2 * Real.logb 2 ↑n + 4 * Real.logb 2 Λ +
        24 ≤
      Real.logb 2 u⁻¹)
  {signFuel : ℕ} (hfuel : 4 * Λ ≤ ↑signFuel) (hτ₀ : 0 ≤ τ)
  (hτ : 300 * ↑n ^ 3 * τ ≤ dec ε * θ * min (dec R₀) 1) (hΩ : 64 * (dec R₀ + ↑n + Λ) ≤ Ω)
  {Ω' : Type u_2} {mΩ' : MeasurableSpace Ω'} {μ : Measure Ω'}
  {ζ : List Bool → Ω' → EighSample ℝ ℂ n} (hind : iIndepFun ζ μ)
  (hlaw : ∀ (a : List Bool), HasLaw (ζ a) (eighSampleLaw n) μ) :
  μ.real
      {ω |
        ¬IsApproxDiagonalization (decodeMatrix dec A)
            (decodeMatrix dec (eigh M signFuel (bisectionDepth (dec ε)) A R₀ ε β fun a ↦ ζ a ω).1)
            (fun i ↦ dec ((eigh M signFuel (bisectionDepth (dec ε)) A R₀ ε β fun a ↦ ζ a ω).2 i))
            (2 * dec ε * dec R₀) (dec ε / 3)} ≤
    θ

Full source on GitHub

Copy link

The precision theorem concerns the numerical reference. The next theorem transfers a reference guarantee to the stored-word execution when its arithmetic and random tape realize those assumptions.

Theorem (Accuracy transfers to the stored output). Suppose the numerical reference returns an approximate diagonalization with error parameters \eta=2\varepsilon R_0 and \kappa=\varepsilon/3, except on a tape event of probability at most \theta. For a probability tape law, the certified execution satisfies its functional and resource specification and stores \mathbf{U},\mathbf{d} with

\|\mathbf{A}-\mathbf{U}\operatorname{diag}(\mathbf{d})\mathbf{U}^{\mathsf{H}}\|_2\le 2\varepsilon R_0,

(1-\varepsilon/3)^2\mathbf{I}\preceq\mathbf{U}^{\mathsf{H}}\mathbf{U}\preceq(1+\varepsilon/3)^2\mathbf{I},

with probability at least 1-\theta. Here the matrices and parameters denote decoded stored words.

The failure event includes execution failure, any resource-bound violation, and incorrect numerical output. Establishing the reference premise separately requires Hermitian input, a valid radius bound, sufficient precision, depth and sign-iteration cap, and the stated sampler and tape-law assumptions. This transfer theorem does not by itself establish those numerical hypotheses.

Lean statement and details
NLAlib.SpectralBisection.measureReal_not_accepts_le_of_wordSpecification {K : Type} [Inhabited K]
  (M : Ops.Machine K) (dec : K → ℝ) (mm : MatMulMap (K × K)) (qr : QRMap (K × K))
  {domain : (Fin 3 → ℕ) → Prop} {admitted : ∃ d, domain d}
  (budget : (Fin 3 → ℕ) → Ops.Count (Ops.DenseOp ⊕ Ops.Bookkeeping) (Ops.CmpTst ⊕ Ops.IdxTst))
  (scratch work span memory : (Fin 3 → ℕ) → ℕ)
  {model :
    Ops.AccessModel Ops.DenseOp (Ops.CmpTst ⊕ Ops.IdxTst)
      (SpectralBisection.problem domain admitted)}
  (algorithm :
    Ops.Algorithm model
      (SpectralBisection.wordSpecification M dec (fun {l m n} ↦ mm) (fun {m n} ↦ qr) domain admitted
        budget scratch work span memory))
  {d : Fin 3 → ℕ} (hd : domain d) (x : (SpectralBisection.problem domain admitted).Input d)
  (I : Ops.Interp Ops.DenseOp (Ops.CmpTst ⊕ Ops.IdxTst) K) (hI : model.contracts d x I)
  {Omega : Type} [MeasurableSpace Omega] (P : Measure Omega) [IsFiniteMeasure P]
  (tape : Omega → Ops.Tape K) {theta : ℝ}
  (hReference :
    P.real
        {omega |
          ¬IsApproxDiagonalization (decodeMatrix dec (SpectralBisection.inputMatrix d x))
              (decodeMatrix dec
                (SpectralBisection.inputResult M dec (fun {l m n} ↦ mm) (fun {m n} ↦ qr) d x
                    (tape omega)).1)
              (fun i ↦
                dec
                  ((SpectralBisection.inputResult M dec (fun {l m n} ↦ mm) (fun {m n} ↦ qr) d x
                        (tape omega)).2
                    i))
              (2 * dec ((↑x).1.2 1) * dec ((↑x).1.2 0)) (dec ((↑x).1.2 1) / 3)} ≤
      theta) :
  P.real
      {omega |
        ¬(SpectralBisection.wordSpecification M dec (fun {l m n} ↦ mm) (fun {m n} ↦ qr) domain
                admitted budget scratch work span memory).Accepts
            algorithm.program I model.resources (tape omega) d x fun c m ↦
            (SpectralBisection.wordSpecification M dec (fun {l m n} ↦ mm) (fun {m n} ↦ qr) domain
                    admitted budget scratch work span memory).good
                d x (tape omega) c m ∧
              SpectralBisection.StoresApproxDiagonalization dec (SpectralBisection.inputMatrix d x)
                (2 * dec ((↑x).1.2 1) * dec ((↑x).1.2 0)) (dec ((↑x).1.2 1) / 3) (2, 0) (3, 0) m} ≤
    theta

Full source on GitHub

Copy link

The last theorem states the work as an explicit polynomial and combines it with the accuracy guarantee, with the precision hypotheses stated for the machine itself.

Theorem (Operation count and accuracy on one event). Let \mathbf{A}\in\mathbb{C}^{n\times n}, n\ge2, be Hermitian with \|\mathbf{A}\|_2\le R, stored as n^2 pairs of words, with a tolerance 0<\varepsilon\le2^{-15}, a parameter \beta>0, a depth L\ge\lceil\log_2\varepsilon^{-1}\rceil+5 and a sign-iteration cap c of at least newtonSchulzSteps. Matrix multiplication and QR are primitives whose declared cost at order j is at most T(j), with T monotone and superadditive. Arithmetic is a floating-point machine accurate with unit roundoff u (FloatMachine.IsAccurate), natural literals up to \max(n,4) are exact, and the tape holds independent uniform and standard Gaussian draws, rounded to machine words. Let 0<\theta\le1. The Lean statement gives the conditions that make u small relative to \theta\beta and \beta, and those on \beta, the absolute-error floor and the range.

Then, for every interpretation of the primitives that meets the model, with probability at least 1-\theta over the tape the run succeeds, its work and its span are at most

(L+1)\,c\,(362n^3+146n^2+222n)+L\,(1587n^3+760n^2+2429n+305)+1599n^3+818n^2+2509n+680+(L+1)(2c+11)\,T(n),

its scratch and memory are within the bounds of its specification, and it stores \mathbf{U} and a real vector \mathbf{d} with

\|\mathbf{A}-\mathbf{U}\operatorname{diag}(\mathbf{d})\mathbf{U}^{\mathsf{H}}\|_2\le2\varepsilon R,\qquad(1-\varepsilon/3)^2\mathbf{I}\preceq\mathbf{U}^{\mathsf{H}}\mathbf{U}\preceq(1+\varepsilon/3)^2\mathbf{I}.

The last term of the work is the matrix work; the others count the instructions that are not matrix operations. The success of the run and its resource bounds hold on every tape; only the accuracy of the output is probabilistic.

Lean statement and details

Random tape

NLAlib.SpectralBisection.measureReal_not_accepts_countedSpecification_le {K : Type} [Inhabited K]
  [MeasurableSpace K] [MeasurableSingletonClass K] {domain : (Fin 3 → ℕ) → Prop}
  {admitted : ∃ d, domain d} (M : Ops.Machine K) (dec : K → ℝ) (mm : MatMulMap (K × K))
  (qr : QRMap (K × K)) (matrixWork matrixWorkspace : Ops.MatrixOp → List ℕ → ℕ) (T : ℕ → ℕ)
  (hLit : ∀ (d : Fin 3 → ℕ), domain d → Ops.IsExactNatLit dec M (max (d 0) 4))
  (hN : ∀ (d : Fin 3 → ℕ), domain d → 2 ≤ d 0) (hT : Monotone T)
  (hadd : ∀ (i j : ℕ), T i + T j ≤ T (i + j))
  (hMatrix : ∀ (o : Ops.MatrixOp) (ds : List ℕ), matrixWork o ds ≤ T (List.foldr max 0 ds))
  (roundUnif roundGaussian : ℝ → K) {u floor bound cN : ℝ} {muM muQ : ℕ → ℝ}
  (hAcc :
    (M.toFloatMachine dec (fun {l m n} ↦ mm) (fun {m n} ↦ qr) (M.uniformSample roundUnif)
          (M.normalSample roundGaussian)).IsAccurate
      dec u floor bound muM muQ cN)
  (hUnif : Measurable roundUnif) (hGaussian : Measurable roundGaussian)
  (hUnifRange : (Set.range roundUnif).Countable)
  (hGaussianRange : (Set.range roundGaussian).Countable) (hMuM : Monotone muM) (hMuQ : Monotone muQ)
  (hMuM0 : 0 ≤ muM 0) (hMuQ0 : 0 ≤ muQ 0) (hCN : 0 ≤ cN) {d : Fin 3 → ℕ} (hd : domain d)
  (x : (SpectralBisection.problem domain admitted).Input d)
  (hA : (decodeMatrix dec (SpectralBisection.inputMatrix d x)).IsHermitian) {theta : ℝ}
  (hRadius :
    specNorm (decodeMatrix dec (SpectralBisection.inputMatrix d x)) ≤
      SpectralBisection.inputRadius dec x)
  (hRadiusPos : 0 < SpectralBisection.inputRadius dec x)
  (hEps : 0 < SpectralBisection.inputTolerance dec x)
  (hEpsMax : SpectralBisection.inputTolerance dec x ≤ 2⁻¹ ^ 15) (hTheta : 0 < theta)
  (hThetaMax : theta ≤ 1) (hDepth : bisectionDepth (SpectralBisection.inputTolerance dec x) ≤ d 1)
  (hBeta : 0 < SpectralBisection.inputBeta dec x)
  (hBetaMax :
    SpectralBisection.inputBeta dec x ≤
      (↑(d 1) - 1) ^ 2 * SpectralBisection.inputTolerance dec x * √theta /
        (52 * ↑(d 1) ^ 2 * (2 * ↑(d 1) - 1) *
            √(↑(d 0) * min (↑(d 0)) (↑(d 1) + 1) * min (↑(d 0)) (rexp 1)) *
          (2 * √2 * √↑(d 0) + √(Real.log (96 * ↑(d 0) * min (↑(d 0)) (↑(d 1) + 1) / theta)))))
  {steps : ℝ}
  (hSteps :
    steps =
      newtonSchulzSteps (theta / (12 * ↑(d 0) * ↑(d 1) * (↑(d 1) + 1)))
        (SpectralBisection.inputBeta dec x / (16 * ↑(d 0))))
  (hSign :
    146 * ↑(d 0) * ↑(d 1) * (↑(d 1) + 1) * (4 * muM (d 0) + 10 + 10 * √↑(d 0)) * u ≤
      theta * SpectralBisection.inputBeta dec x)
  (hStop :
    2048 * (↑(d 0) + steps + 1) * (4 * muM (d 0) + 10 + 10 * √↑(d 0)) * u ≤
      SpectralBisection.inputBeta dec x)
  (hDeflate :
    16 * (4 * muQ (d 0) + 4 * √↑(d 0) * (cN + 1) + 2 * muM (d 0) + 1) * u ≤
      SpectralBisection.inputBeta dec x)
  (hFuel : steps ≤ ↑(d 2)) (hFloorNonneg : 0 ≤ floor)
  (hFloor :
    floor * (100 * ↑(d 0) * √↑(d 0)) ≤
      min (√(theta / (8 * ↑(d 0) * min (↑(d 0)) (↑(d 1) + 1))))
        (SpectralBisection.inputTolerance dec x * min (SpectralBisection.inputRadius dec x) 1))
  (hBound :
    16 *
        (2 * SpectralBisection.inputRadius dec x + ↑(d 0) + 2 * ↑(d 1) + 2 * √2 * √↑(d 0) +
          √(Real.log (96 * ↑(d 0) * min (↑(d 0)) (↑(d 1) + 1) / theta))) ≤
      bound)
  (I : Ops.Interp Ops.DenseOp (Ops.CmpTst ⊕ Ops.IdxTst) K)
  (hI :
    (Ops.Dense.functionalModel (SpectralBisection.problem domain admitted) M dec
          (Ops.EntryCodec.pair K) (fun {l m n} ↦ mm) (fun {m n} ↦ qr)
          (Ops.Dense.resources matrixWork matrixWorkspace)).contracts
      d x I)
  {Omega : Type} [MeasurableSpace Omega] {P : Measure Omega} [IsFiniteMeasure P]
  {law : ℕ → Measure ℝ} {ideal : Omega → Ops.Tape ℝ} (hTape : Ops.IsTapeLaw law P ideal)
  (hStream :
    ∀ (dist : Computation.Dist), law (SpectralBisection.distributionStream dist) = dist.law) :
  P.real
      {omega |
        ¬(SpectralBisection.countedSpecification M dec (fun {l m n} ↦ mm) (fun {m n} ↦ qr) domain
                admitted matrixWorkspace T).Accepts
            SpectralBisection.bisectionProgram I (Ops.Dense.resources matrixWork matrixWorkspace)
            (SpectralBisection.roundTape roundUnif roundGaussian (ideal omega)) d x fun x_1 m ↦
            SpectralBisection.StoresApproxDiagonalization dec (SpectralBisection.inputMatrix d x)
              (2 * SpectralBisection.inputTolerance dec x * SpectralBisection.inputRadius dec x)
              (SpectralBisection.inputTolerance dec x / 3) (2, 0) (3, 0) m} ≤
    theta

Full source on GitHub

Copy link

Further numerical results

Theorem (Hermitian diagonalization in linear precision).

(Theorem 4.2): let the machine meet NLAlib.FloatMachine.IsAccurate u \tau \Omega (constants \mu_{\mathrm{MM}}, \mu_{\mathrm{QR}}, c_{\mathrm N}), with \mu_{\mathrm{MM}}, \mu_{\mathrm{QR}} monotone and nonnegative, c_{\mathrm N} \ge 0, and the samplers with measurable fibres and countable ranges. Let the stored n \times n input \mathbf{A}, n \ge 1, have Hermitian decoding with \|\mathbf{A}\|_2 \le R_0, for stored R_0 > 0, \varepsilon, \beta (decoded values) with 0 < \varepsilon \le 2^{-15}, 0 < \theta \le 1, a depth counter \ell \ge NLAlib.bisectionDepth \varepsilon, m = \min(n, \ell + 1), \nu = 4\mu_{\mathrm{MM}}(n) + 10 + 10\sqrt n, and the precomputed accuracy 0 < \beta \le \hat\beta = \frac{(\ell - 1)^2\,\varepsilon\sqrt\theta}{52\,\ell^2(2\ell - 1) \sqrt{n m \min(n, e)}\,\hat T} \,, \qquad \hat T = 2\sqrt2\sqrt n + \sqrt{\log(96nm/\theta)} \,, N_* = N(\theta/(12n\ell(\ell + 1)), \beta/(16n)) (NLAlib.newtonSchulzSteps). If 146n\ell(\ell + 1)\nu u \le \theta\beta (the sign function), 2048(n + N_* + 1)\nu u \le \beta (the stopping test), 16(4\mu_{\mathrm{QR}}(n) + 4\sqrt n(c_{\mathrm N} + 1) + 2\mu_{\mathrm{MM}}(n) + 1)u \le \beta (deflation), the sign step limit is at least N_*, 0 \le \tau, 100n^{3/2}\tau \le \min(\sqrt{\theta/(8nm)}, \varepsilon\min(R_0, 1)), 16(2R_0 + n + 2\ell + \hat T) \le \Omega, and the node samples \zeta_a are independent, each of law NLAlib.eighSampleLaw n, then \mathbb{P}\bigl[\mathsf{eigh}(\mathbf{A}, \varepsilon, \theta) \text{ is not an approximate diagonalization with residual } 2\varepsilon R_0 \text{ and } \mathbf{U} \text{ within } \varepsilon/3 \text{ of unitary}\bigr] \le \theta \,, \mathsf{eigh} the decoded output of NLAlib.eigh. [Shah2024, Theorem 4.2], there with R_0 = \|\mathbf{A}\|_2, node-dependent accuracies, other constants (here the Event I charge of a node is proportional to its size and Event II uses the smallest-singular-value tail \min(r^2, e r)x^2), and an operation count (not formalized); the bit count is NLAlib.FloatMachine.IsAccurate.measureReal_not_isApproxDiagonalization_eigh_le_of_logb_le_of_hasLaw_eighSampleLaw.

Lean statement and details
NLAlib.FloatMachine.IsAccurate.measureReal_not_isApproxDiagonalization_eigh_le_of_hasLaw_eighSampleLaw.{u_1,
    u_2}
  {F : Type u_1} {M : FloatMachine F ℝ ℂ} {dec : F → ℝ} {u τ Ω cN : ℝ} {μM μQ : ℕ → ℝ}
  (hM : M.IsAccurate dec u τ Ω μM μQ cN) (hunifm : ∀ (c z : F), MeasurableSet (M.unif c ⁻¹' {z}))
  (hunifc : ∀ (c : F), (Set.range (M.unif c)).Countable)
  (hnormalm : ∀ (z : F × F), MeasurableSet (M.normal ⁻¹' {z}))
  (hnormalc : (Set.range M.normal).Countable) (hμM : Monotone μM) (hμQ : Monotone μQ)
  (hμM₀ : 0 ≤ μM 0) (hμQ₀ : 0 ≤ μQ 0) (hcN : 0 ≤ cN) {n : ℕ} (hn : 1 ≤ n)
  {A : Matrix (Fin n) (Fin n) (F × F)} (hA : (decodeMatrix dec A).IsHermitian) {R₀ ε β : F} {θ : ℝ}
  (hR₀ : specNorm (decodeMatrix dec A) ≤ dec R₀) (hR₀pos : 0 < dec R₀) (hε : 0 < dec ε)
  (hε₁ : dec ε ≤ 2⁻¹ ^ 15) (hθ : 0 < θ) (hθ₁ : θ ≤ 1) {ℓ : ℕ} (hℓ : bisectionDepth (dec ε) ≤ ℓ)
  (hβ : 0 < dec β)
  (hβle :
    dec β ≤
      (↑ℓ - 1) ^ 2 * dec ε * √θ /
        (52 * ↑ℓ ^ 2 * (2 * ↑ℓ - 1) * √(↑n * min (↑n) (↑ℓ + 1) * min (↑n) (rexp 1)) *
          (2 * √2 * √↑n + √(Real.log (96 * ↑n * min (↑n) (↑ℓ + 1) / θ)))))
  {Nst : ℝ} (hN : Nst = newtonSchulzSteps (θ / (12 * ↑n * ↑ℓ * (↑ℓ + 1))) (dec β / (16 * ↑n)))
  (husign : 146 * ↑n * ↑ℓ * (↑ℓ + 1) * (4 * μM n + 10 + 10 * √↑n) * u ≤ θ * dec β)
  (hustop : 2048 * (↑n + Nst + 1) * (4 * μM n + 10 + 10 * √↑n) * u ≤ dec β)
  (hudefl : 16 * (4 * μQ n + 4 * √↑n * (cN + 1) + 2 * μM n + 1) * u ≤ dec β) {signFuel : ℕ}
  (hfuel : Nst ≤ ↑signFuel) (hτ₀ : 0 ≤ τ)
  (hτ : τ * (100 * ↑n * √↑n) ≤ min (√(θ / (8 * ↑n * min (↑n) (↑ℓ + 1)))) (dec ε * min (dec R₀) 1))
  (hΩ :
    16 * (2 * dec R₀ + ↑n + 2 * ↑ℓ + 2 * √2 * √↑n + √(Real.log (96 * ↑n * min (↑n) (↑ℓ + 1) / θ))) ≤
      Ω)
  {Ω' : Type u_2} {mΩ' : MeasurableSpace Ω'} {μ : Measure Ω'}
  {ζ : List Bool → Ω' → EighSample ℝ ℂ n} (hind : iIndepFun ζ μ)
  (hlaw : ∀ (a : List Bool), HasLaw (ζ a) (eighSampleLaw n) μ) :
  μ.real
      {ω |
        ¬IsApproxDiagonalization (decodeMatrix dec A)
            (decodeMatrix dec (eigh M signFuel ℓ A R₀ ε β fun a ↦ ζ a ω).1)
            (fun i ↦ dec ((eigh M signFuel ℓ A R₀ ε β fun a ↦ ζ a ω).2 i)) (2 * dec ε * dec R₀)
            (dec ε / 3)} ≤
    θ

Full source on GitHub

Copy link

Theorem (The bit count of Hermitian diagonalization).

(Theorem 4.2, in bits): let the machine meet NLAlib.FloatMachine.IsAccurate with u > 0, monotone \mu_{\mathrm{MM}}, \mu_{\mathrm{QR}} \ge 0, c_{\mathrm N} \ge 0 and samplers with measurable fibres and countable ranges; let the stored n \times n input \mathbf{A}, n \ge 1, be Hermitian with \|\mathbf{A}\|_2 \le R_0, R_0 > 0, 0 < \varepsilon \le 2^{-15}, 0 < \theta \le 1 and \ell \ge NLAlib.bisectionDepth \varepsilon; let m = \min(n, \ell + 1), \nu = 4\mu_{\mathrm{MM}}(n) + 10 + 10\sqrt n, N_* = NLAlib.newtonSchulzSteps (\theta/(12n\ell(\ell + 1)))\,(\beta/(16n)) be at most the step limit, the floor 0 \le \tau with 100n^{3/2}\tau \le \min(\sqrt{\theta/(8nm)}, \varepsilon\min(R_0, 1)), the range 16(2R_0 + n + 2\ell + \hat T) \le \Omega, the ideal samples of the nodes independent with law NLAlib.eighSampleLaw n, the accuracy within 1 + 2^{-6} of its bound, \hat\beta/(1 + 2^{-6}) \le \beta \le \hat\beta = (\ell - 1)^2\varepsilon\sqrt\theta/ (52\ell^2(2\ell - 1)\sqrt{nm\min(n, e)}\,\hat T), and \begin{aligned}\log_2\frac1u \ge{}& \log_2\frac1\varepsilon + \frac32\log_2\frac1\theta + \log_2\bigl(n(4\mu_{\mathrm{MM}}(n) + 10 + 10\sqrt n)\bigr) + \tfrac12\log_2\bigl(n\min(n, \ell + 1)\min(n, e)\bigr) \\ &+ \log_2\hat T + \log_2(\ell(\ell + 1)) + \log_2\frac{\ell^2(2\ell - 1)}{(\ell - 1)^2} + 13 \,,\end{aligned} \hat T = 2\sqrt2\sqrt n + \sqrt{\log(96n\min(n, \ell + 1)/\theta)}, together with the condition \log_2(1/u) \ge \log_2(1/\beta) + \log_2(2048(n + N_* + 1)\nu + 16(4\mu_{\mathrm{QR}}(n) + 4\sqrt n(c_{\mathrm N} + 1) + 2\mu_{\mathrm{MM}}(n) + 1)), the probability that \mathsf{eigh}(\mathbf{A}, \varepsilon, \theta), the decoded output of NLAlib.eigh, is not an approximate diagonalization with residual 2\varepsilon R_0 and singular values within \varepsilon/3 of 1 is at most \theta. This is \log_2(1/\varepsilon) + \tfrac32\log_2(1/\theta) + O(\log n + \log\log(1/\varepsilon)) bits, with the polynomial factor n^{2.5}\max(\mu_{\mathrm{MM}}, \sqrt n) for n \le \ell; at \mu_{\mathrm{MM}} = \mu_{\mathrm{QR}} = 1, c_{\mathrm N} = \sqrt2, \ell = \lceil\log_2(1/\varepsilon)\rceil + 5 it asks for 49.1, 58.6, 74.9 and 105.4 bits at (n, \varepsilon, \theta) = (1, 2^{-15}, 1), (10, 2^{-15}, 1), (1000, 2^{-15}, 1), (1000, 2^{-40}, 1/2). [Shah2024, Theorem 4.2], there \log_2(1/\varepsilon) + \log_2\max(n^{1.5}\mu_{\mathrm{QR}}, n^2c_{\mathrm N}, n^{4.5}\mu_{\mathrm{MM}}) + 2\log_2\log_2(1/\varepsilon) + 1.5\log_2(1/\theta) + \log_2\log_2(n\log_2(1/\varepsilon)/\theta) + 23 (48.3, 63.6, 94.5, 124.0 bits at the same points); the third power of \ell comes from the corrected shift-avoidance probability.

Lean statement and details
NLAlib.FloatMachine.IsAccurate.measureReal_not_isApproxDiagonalization_eigh_le_of_logb_le_of_hasLaw_eighSampleLaw.{u_1,
    u_2}
  {F : Type u_1} {M : FloatMachine F ℝ ℂ} {dec : F → ℝ} {u τ Ω cN : ℝ} {μM μQ : ℕ → ℝ}
  (hM : M.IsAccurate dec u τ Ω μM μQ cN) (hunifm : ∀ (c z : F), MeasurableSet (M.unif c ⁻¹' {z}))
  (hunifc : ∀ (c : F), (Set.range (M.unif c)).Countable)
  (hnormalm : ∀ (z : F × F), MeasurableSet (M.normal ⁻¹' {z}))
  (hnormalc : (Set.range M.normal).Countable) (hμM : Monotone μM) (hμQ : Monotone μQ)
  (hμM₀ : 0 ≤ μM 0) (hμQ₀ : 0 ≤ μQ 0) (hcN : 0 ≤ cN) {n : ℕ} (hn : 1 ≤ n)
  {A : Matrix (Fin n) (Fin n) (F × F)} (hA : (decodeMatrix dec A).IsHermitian) {R₀ ε β : F} {θ : ℝ}
  (hR₀ : specNorm (decodeMatrix dec A) ≤ dec R₀) (hR₀pos : 0 < dec R₀) (hε : 0 < dec ε)
  (hε₁ : dec ε ≤ 2⁻¹ ^ 15) (hθ : 0 < θ) (hθ₁ : θ ≤ 1) {ℓ : ℕ} (hℓ : bisectionDepth (dec ε) ≤ ℓ)
  (hβ : 0 < dec β)
  (hβle :
    dec β ≤
      (↑ℓ - 1) ^ 2 * dec ε * √θ /
        (52 * ↑ℓ ^ 2 * (2 * ↑ℓ - 1) * √(↑n * min (↑n) (↑ℓ + 1) * min (↑n) (rexp 1)) *
          (2 * √2 * √↑n + √(Real.log (96 * ↑n * min (↑n) (↑ℓ + 1) / θ)))))
  (hβge :
    (↑ℓ - 1) ^ 2 * dec ε * √θ /
          (52 * ↑ℓ ^ 2 * (2 * ↑ℓ - 1) * √(↑n * min (↑n) (↑ℓ + 1) * min (↑n) (rexp 1)) *
            (2 * √2 * √↑n + √(Real.log (96 * ↑n * min (↑n) (↑ℓ + 1) / θ)))) /
        (1 + 2⁻¹ ^ 6) ≤
      dec β)
  {Nst : ℝ} (hN : Nst = newtonSchulzSteps (θ / (12 * ↑n * ↑ℓ * (↑ℓ + 1))) (dec β / (16 * ↑n)))
  (hu : 0 < u)
  (hbits :
    Real.logb 2 (dec ε)⁻¹ + 3 / 2 * Real.logb 2 θ⁻¹ +
                  Real.logb 2 (↑n * (4 * μM n + 10 + 10 * √↑n)) +
                1 / 2 * Real.logb 2 (↑n * min (↑n) (↑ℓ + 1) * min (↑n) (rexp 1)) +
              Real.logb 2 (2 * √2 * √↑n + √(Real.log (96 * ↑n * min (↑n) (↑ℓ + 1) / θ))) +
            Real.logb 2 (↑ℓ * (↑ℓ + 1)) +
          Real.logb 2 (↑ℓ ^ 2 * (2 * ↑ℓ - 1) / (↑ℓ - 1) ^ 2) +
        13 ≤
      Real.logb 2 u⁻¹)
  (hbits' :
    Real.logb 2 (dec β)⁻¹ +
        Real.logb 2
          (2048 * (↑n + Nst + 1) * (4 * μM n + 10 + 10 * √↑n) +
            16 * (4 * μQ n + 4 * √↑n * (cN + 1) + 2 * μM n + 1)) ≤
      Real.logb 2 u⁻¹)
  {signFuel : ℕ} (hfuel : Nst ≤ ↑signFuel) (hτ₀ : 0 ≤ τ)
  (hτ : τ * (100 * ↑n * √↑n) ≤ min (√(θ / (8 * ↑n * min (↑n) (↑ℓ + 1)))) (dec ε * min (dec R₀) 1))
  (hΩ :
    16 * (2 * dec R₀ + ↑n + 2 * ↑ℓ + 2 * √2 * √↑n + √(Real.log (96 * ↑n * min (↑n) (↑ℓ + 1) / θ))) ≤
      Ω)
  {Ω' : Type u_2} {mΩ' : MeasurableSpace Ω'} {μ : Measure Ω'}
  {ζ : List Bool → Ω' → EighSample ℝ ℂ n} (hind : iIndepFun ζ μ)
  (hlaw : ∀ (a : List Bool), HasLaw (ζ a) (eighSampleLaw n) μ) :
  μ.real
      {ω |
        ¬IsApproxDiagonalization (decodeMatrix dec A)
            (decodeMatrix dec (eigh M signFuel ℓ A R₀ ε β fun a ↦ ζ a ω).1)
            (fun i ↦ dec ((eigh M signFuel ℓ A R₀ ε β fun a ↦ ζ a ω).2 i)) (2 * dec ε * dec R₀)
            (dec ε / 3)} ≤
    θ

Full source on GitHub

Copy link

Mathematical method