This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

← Posts

demoAINumerics

The error of a linear solve follows the condition number

Gaussian elimination with partial pivoting solves Hilbert systems whose exact solution is all ones. From to 12 the condition number grows from 524 to , and the error grows with it, staying between 0.005 and 0.18 times , while the residual stays under . In least squares, fitting a degree-11 polynomial to 40 points, Householder QR is off by (about ), and the normal equations, which square , by 0.18.

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

Every computed answer here is compared with an exact one. The Hilbert systems are scaled to have integer entries, so the system stored in the computer is the exact system and its solution is exactly all ones; the Python reference confirms it by solving in rational arithmetic with fractions. The exact condition numbers come from mpmath at 80 digits, and numpy's linalg.cond agrees with them to through . The reference, posts/refs/the-error-follows-the-condition-number.py, also repeats every solve in Python in the same order of operations (output beside it).

Conditioning

The condition number , the ratio of the largest to the smallest singular value, bounds how much a relative change in or can change the solution of : by up to times as much. Rounding a number to double precision changes it, relative to its size, by at most half of (machine epsilon, the gap between 1 and the next double), so no method can promise better than about .

A method is backward stable if its answer is the exact solution of a nearby system, one whose data differ from and by a few relative. Its residual is then a few relative to , and its error is about . Gaussian elimination with partial pivoting (GEPP) behaves this way in practice. So a small residual says the method did its job, and it says nothing about the error when is large.

The Hilbert matrix is the standard ill-conditioned example; grows about 32 times with each row added. Multiplying by makes every entry an integer below , stored exactly, with the same . The right side is a sum of integers, also exact.

The condition number has to be computed too, and it runs into the same limit. eig_sym finds the smallest eigenvalue to within about times the largest, so comes out with a relative error below : at and 4.4% at , where numpy's cond is off by 1.6%. The tests use the exact values.

Printed

KAPPA_H: [524.057, 15513.7, 476607, 1.49511e+07, 4.75367e+08, 1.52576e+10, 4.93155e+11, 1.60261e+13, 5.23168e+14, 1.63718e+16]
ERR_H: [5.32907e-15, 6.14619e-13, 5.39802e-12, 8.73202e-11, 1.01546e-08, 3.53386e-07, 1.16269e-06, 4.71144e-05, 0.000606493, 0.186783]
[0.0457966, 0.178422, 0.0510074, 0.0263028, 0.0962036, 0.104309, 0.0106179, 0.0132399, 0.00522089, 0.0513806]
[0.145455, 0.0731429, 0.177963, 0.361869, 0.490979, 0.368027, 0.242017, 0.295255, 0.572452, 0.306599]
[-1.11022e-15, 1.53433e-13, 1.39466e-12, -2.25156e-10, -2.66265e-09, -6.24517e-08, 3.398e-07, -1.1648e-05, 0.000191199, -0.0443871]
kappa_growth: 31.7398
entry_max: 5354228880
Hilbert systems, n=3 to 12: error against κ10⁻¹⁵10⁻¹⁰10⁻⁵10⁰10⁴10⁸10¹²10¹⁶condition number κmax |x - 1|
κϵGEPP errorresidual / (|A| |x|)

Tests 6 of 6 pass

  • kappa grows about 32 times with each row added, from n = 3 to 12 (passes)
  • every scaled Hilbert entry is a whole number below 2^53, so it is stored exactly (passes)
  • eig_sym's kappa is within kappa eps of the exact one at every n: 4.4% off at n = 12 (passes)
  • the errors are the Python reference's, n = 3, 8 and 12 (passes)
  • the error is between 0.005 and 0.18 times kappa eps at every n from 3 to 12 (passes)
  • the residual stays under one eps relative to |A| |x|, at every n (passes)

In least squares the method sets the condition number

A least-squares fit asks for the that minimizes for a tall matrix . Here is the Vandermonde matrix of a polynomial fit, , at points , and the data are , so the coefficients sought are all ones.

The normal equations are the textbook route: a square system, solved here with the same elimination. But , so the error is about . Householder QR multiplies by reflections , each of which zeroes one column below the diagonal, until is upper triangular, . Reflections are orthogonal and change no lengths, so the problem becomes with , and the error is about .

The data are rounded when they are formed, which moves the exact least-squares answer of the stored problem slightly away from all ones. The Python reference computes that answer in rational arithmetic: it is at most from ones (at degree 13), a small part of the errors below. The singular values for come from one-sided Jacobi (lib/svd).

Printed

KAPPA_V: [116.326, 632.323, 3482.97, 19382.9, 108842, 616409, 3.52067e+06, 2.02844e+07, 1.17939e+08, 6.92379e+08, 4.10677e+09]
ERR_QR: [1.63203e-14, 1.39888e-14, 4.25215e-13, 3.67817e-13, 5.2357e-12, 5.16687e-12, 1.07436e-10, 1.48329e-09, 3.55007e-09, 3.11683e-08, 4.13773e-07]
ERR_NE: [8.01137e-13, 2.07155e-11, 5.62091e-10, 3.28893e-09, 7.27971e-08, 5.17588e-06, 0.000525759, 0.0054425, 0.175128, 4.10628, 5.60189]
[0.631844, 0.0996326, 0.549818, 0.0854617, 0.21664, 0.0377501, 0.137431, 0.329323, 0.135562, 0.202735, 0.453755]
[0.266631, 0.233334, 0.208673, 0.0394253, 0.0276748, 0.0613487, 0.191028, 0.0595709, 0.0567022, 0.0385763, 0.00149587]
[2.22045e-16, 3.55271e-15, -6.21725e-15, 1.23457e-13, -2.79665e-13, 3.54827e-13, -4.3453e-12, -3.56981e-11, 4.07849e-10, -2.29108e-09, 1.63511e-08]
Fitting degree 3 to 13 at 40 points: coefficient error against κ(V)10⁻¹⁵10⁻¹⁰10⁻⁵10⁰10²10⁴10⁶10⁸10¹⁰condition number of Vmax |c - 1|
κϵκ2ϵHouseholder QRnormal equations

Tests 5 of 5 pass

  • one-sided Jacobi's kappa(V) is within 0.05 kappa eps (or 1e-14) of the exact one at every degree: 1.6e-8 at degree 13 (passes)
  • at degree 11, QR is off by 3.55e-9 and the normal equations by 0.175, as in the Python reference (passes)
  • QR's error is below kappa eps at every degree (passes)
  • the normal equations' error is 0.025 to 0.27 times kappa^2 eps up to degree 12 (passes)
  • from degree 4 on it is 1300 to 1.4e8 times QR's (passes)

Checked when the site was built: 11 of 11 tests passed, in 0.48 s. Download 2026-09-25-the-error-follows-the-condition-number.viv