NLA-lib Explorer

Arithmetic models

An algorithm specifies which operations are performed. An arithmetic model specifies what each operation may return. These choices are separate from the storage format, matrix-access model, and resource charges.

The library states a model as hypotheses of a theorem or certificate: a property of the scalar machine, and contracts for the vector and matrix operations that the program calls. The pages mark a statement with the facts that its Lean signature or the library's certificate record establishes, and search filters on them. A statement without a mark has no established fact; it is not thereby exact or deterministic.

Definition (Exact arithmetic). Every scalar operation of the machine returns the exact value: literals, addition, subtraction, multiplication, division by a nonzero number, negation, and the square root of a nonnegative number (Ops.ExactModel). In an exact operation model, dot products, vector updates, and matrix–vector products are exact as well.

A correspondence theorem on an implementation page then identifies the stored output with the mathematical method. For CG, the recurrence agrees with mathematical CG, so classical convergence and finite-termination results apply under their matrix assumptions.

Copy link

Definition (Standard rounding). Standard rounding is the standard model of rounded arithmetic with unit roundoff u (Ops.StdModel). A scalar machine is in it when each operation returns its exact result with relative error at most u:

|\widehat{a\circ \mathbf{b}}-a\circ \mathbf{b}|\le u\,|a\circ \mathbf{b}|,\qquad\circ\in\{+,-,\times,/\},

with division only by a nonzero number, and likewise for literals and for the square root of a nonnegative number. Negation is exact. There is no overflow and no underflow. Exact arithmetic is the case u=0.

The model constrains the scalar operations only. A program whose only primitives are scalar operations and comparisons, such as the stored scalar programs of CG and Lanczos, needs nothing else. A program that calls vector or matrix operations also needs their contracts, as in the next two definitions.

Copy link

Definition (Relative-error BLAS + matvec). The implementation supplies error coefficients rather than a particular reduction order. The dot-product contract is

|\widehat{\langle\mathbf{x},\mathbf{y}\rangle}-\langle\mathbf{x},\mathbf{y}\rangle| \le d_n\sum_{i=1}^n |\mathbf{x}_i y_i|.

This scales with the sum of absolute products, not with the absolute value of the dot product; the distinction matters when there is cancellation.

A scaled vector addition satisfies

|\widehat z_i-(y_i+\alpha \mathbf{x}_i)|\le e_a(|y_i|+|\alpha \mathbf{x}_i|),

and matrix–vector multiplication satisfies

\|\widehat{\mathbf{A}\mathbf{v}}-\mathbf{A}\mathbf{v}\|_2 \le e_m\|\mathbf{A}\|_2\|\mathbf{v}\|_2.

The library's matrix–vector contract has an absolute allowance \delta in place of e_m\|\mathbf{A}\|_2; the CG theorems take \delta=e_m\|\mathbf{A}\|_2.

Scalar arithmetic has unit roundoff u. Copies and decoded comparisons are exact. The solver theorem requires the supplied coefficients to satisfy its accuracy budget.

Copy link

Definition (Sequential summation in standard rounding). The standard-rounding model of the solver pages sums sequentially. Scalar operations obey standard rounding with unit roundoff u. A sum of n terms accumulated in order has the error coefficient (1+u)^{n-1}-1 (Ops.Blas.seqSumErr), and a dot product, which forms rounded products and sums them, has

d_n=(1+u)^n-1

(Ops.Blas.seq.err). The same profile supplies the vector-update bounds. All vector lengths are admitted. Matvec error is supplied separately; this model does not assume exact matvecs.

The library also has pairwise summation (Ops.Blas.pairwise.err). It improves the sum coefficient to (1+u)^{\lceil\log_2 n\rceil}-1 (Ops.Blas.pairSumErr), so that d_n=(1+u)^{\lceil\log_2 n\rceil+1}-1. It needs the depth condition \lceil\log_2 n\rceil<\mathrm{depth} (Nat.clog 2 n < depth) and declares a different workspace for the vector operations. The solver theorems are stated for either scheme; the pages present the sequential one. Pairwise summation specifies the reduction order; it does not by itself certify parallel execution.

Copy link

Definition (Accuracy budgets). For the abstract relative-error CG theorem, choose a nonnegative allowance E with

u,d_n,e_a,e_m\le E\le10^{-2}.

The named standard profiles use a stricter envelope (Ops.Standard.Accuracy), which the CG and Lanczos operation budgets share:

\begin{gathered}0\le E\le10^{-2},\qquad e_m,e_a\le E,\\ u,d_n,e_{\mathrm{scal}}\le E/16.\end{gathered}

Here e_{\mathrm{scal}} bounds componentwise vector division. Each solver theorem also has its own assumptions, such as the spectral and iteration-window assumptions of CG, stated on its implementation page.

Copy link

Access, randomness and work are not arithmetic. They are marked separately, and a statement can carry several of these facts.

Definition (Uniform model and oracle). An operation model is uniform (Ops.AccessModel.Uniform) when the contracts of its primitives and queries do not depend on the sizes or on the input. No primitive is then an oracle for the problem data: the program reaches its input through the stored buffers. A uniform model can still call kernels, which are primitives with their own contracts and with work supplied by the caller.

A matrix–vector product that is a primitive with a contract for a given operator is an oracle: the operator is semantic data of the model, not entries that the program reads.

Copy link

Definition (Random tape). A tape holds, at each position, one entry of each stream of draws. Under a tape law (Ops.IsTapeLaw) all entries are independent, and an entry of a stream has the distribution of that stream. A statement under a tape law is a statement about a probability over the tape.

Copy link

Definition (Closed and manifest work). A certificate bounds the work and the span of its program. The bound is closed when it does not mention the static count of a program, and manifest when it is stated through the program's own syntax. A closed bound can still be a parameter that a hypothesis of the certificate constrains.

Copy link

Open ordinary CG

Open ordinary Lanczos

Computational-model theory