NLA-lib Explorer

Rounding and finite-precision arithmetic

Arithmetic contracts specify how decoded word operations differ from ideal operations. Scalar roundoff, vector reductions, matrix applications, and range restrictions contribute different error terms; a numerical theorem states which combination it needs.

Definition (Relative error and absolute error floor). A typical scalar error contract has the form

|\widehat z-z|\le u|z|+\eta,

where u is a relative-error parameter and \eta is an absolute-error floor. Setting \eta=0 is an additional choice, not a consequence of relative accuracy. Dot products with cancellation and matrix-vector products need their own accumulation bounds.

Copy link

Background

Results

Theorem (Backward error of forward substitution).

[Higham2002, Theorem 8.5], from [Higham2002, Lemma 8.4], with the factor of [CarsonMaShao2026, (3)]: under the standard model with 0 \le u < 1, if every diagonal entry t_{ii} (i < n) is nonzero, a trace \hat{x} of forward substitution solves a nearby system exactly: for some \Delta t_{ij} with \lvert \Delta t_{ij} \rvert \le \gamma_n \lvert t_{ij} \rvert (j \le i < n), \gamma_n = (1 - u)^{-n} - 1, \sum_{j \le i} (t_{ij} + \Delta t_{ij})\,\hat{x}_j = b_i \qquad (i < n)\,.

Lean statement and details
NLAlib.Computation.IsSubstTrace.exists_sum_add_mul_eq {u : ℝ} {n : ℕ} {t : ℕ → ℕ → ℝ} {b x : ℕ → ℝ}
  (h : Computation.IsSubstTrace (fun x ↦ Computation.RelErr u) t b n x) (hdiag : ∀ i < n, t i i ≠ 0)
  (hu : 0 ≤ u) (hu1 : u < 1) :
  ∃ Δ,
    (∀ i < n, ∀ j ≤ i, |Δ i j| ≤ Computation.roundingFactor n u * |t i j|) ∧
      ∀ i < n, ∑ j ∈ Finset.range (i + 1), (t i j + Δ i j) * x j = b i

Full source on GitHub

Copy link

Theorem (Backward error of an inner product).

[Higham2002, §3.1], (3.4) there, with the factor of [CarsonMaShao2026, (3)]: under the standard model with unit roundoff 0 \le u < 1, the result s_n of a trace of recursive accumulation is the exact inner product of slightly perturbed data, s_n = \sum_{k<n} x_k y_k (1 + \eta_k)\,, \qquad \lvert \eta_k \rvert \le \gamma_n = (1 - u)^{-n} - 1\,, with no condition on nu.

Lean statement and details
NLAlib.Computation.IsDotTrace.exists_eq_sum_mul_one_add {u : ℝ} {n : ℕ} {x y s : ℕ → ℝ}
  (h : Computation.IsDotTrace (fun x ↦ Computation.RelErr u) x y n s) (hu : 0 ≤ u) (hu1 : u < 1) :
  ∃ η,
    (∀ k < n, |η k| ≤ Computation.roundingFactor n u) ∧
      s n = ∑ k ∈ Finset.range n, x k * y k * (1 + η k)

Full source on GitHub

Copy link

Theorem (Forward error of an inner product).

[Higham2002, §3.1], (3.5) there, with the factor of [CarsonMaShao2026, (3)]: under the standard model with 0 \le u < 1, \Bigl\lvert \sum_{k<n} x_k y_k - s_n \Bigr\rvert \le \gamma_n \sum_{k<n} \lvert x_k \rvert \lvert y_k \rvert\,, \qquad \gamma_n = (1 - u)^{-n} - 1\,.

Lean statement and details
NLAlib.Computation.IsDotTrace.abs_sum_mul_sub_le {u : ℝ} {n : ℕ} {x y s : ℕ → ℝ}
  (h : Computation.IsDotTrace (fun x ↦ Computation.RelErr u) x y n s) (hu : 0 ≤ u) (hu1 : u < 1) :
  |∑ k ∈ Finset.range n, x k * y k - s n| ≤
    Computation.roundingFactor n u * ∑ k ∈ Finset.range n, |x k| * |y k|

Full source on GitHub

Copy link

Formal definitions

Used by algorithms

Broader topics