poly_fit

std.linalg.poly_fit · Level L4

The least-squares polynomial of degree p − 1 through the points (xᵢ, yᵢ), p the length of k (only its length is read), coefficients highest degree first. NumPy's np.polyfit: the columns of the Vandermonde matrix are scaled to unit norm, the scaled system is solved by QR (lstsq), and the scaling is undone. Scaling does not change the solution, only the conditioning.

c = argmin ‖V·c − y‖, Vᵢⱼ = xᵢ^(p−1−j)

Signature

poly_fit(x: f64[p+r], y: f64[p+r], k: f64[p]) → f64[p]

Structure

The function as NOVA stores it: one box per input, operation and output, and arrows that carry values. A double border marks another library function this one runs — called once, or by Scan once per element; select it to open that function.

xf64[p+r]kf64[p]yf64[p+r]vandermondeVMultiplyV2ReduceSumssSqrtscaleReshapesrDivideVslstsqcsDivideccf64[p]
  • input
  • operation
  • constant
  • call
  • output

Verification

  • Signature proven by NOVA’s shape solver, for every size.
  • Agrees with the reference np.polyfit(x, y, p − 1) to 80 digits (100-digit arithmetic), on all 40 test cases.
  • All 151 float64 results inside the running error bound; the closest uses 1% of it.
  • Interpreter and NumPy backend return bit-identical results.
  • At float32 too: the 40 test cases rounded to float32, and 32 of them inside the running error bound at u = 2⁻²⁴; the closest uses <1% of it. Uncertified, too ill-conditioned at float32 for a finite bound: 8.
Accuracy in detail
correctly rounded (the float64 nearest the exact value)
3%
bit-equal to the NumPy formula in float64
12%
largest error, in units in the last place
460

Large ulp counts appear where a result is tiny next to the numbers it is computed from (after cancellation, for example), so one unit in the last place is tiny too; the absolute error is still inside the bound. Results within their own error of zero are not counted.

Note

Verified on the Chebyshev points of [−1, 1], where the scaled Vandermonde matrix's condition number stays below 200 up to degree 7. The oracle bounds QR through RᵀR = AᵀA, which costs a cube of that condition number, so for clustered or widely spread points it refuses the triangular solve rather than give a bound that might not hold: points at random in [−1, 1] already reach a condition number of 3·10⁴ at degree 7. NOVA's result there is still what LAPACK-style QR gives; only the certificate is missing.

Identity

Calls
Called by
—
sha256:9cd47b4a0338a55fcefbc1615ecf5a058f6af39c686d6568a966fc7cd874ae36

The semantic hash of the graph. It changes when the program changes, and never when only its documentation does.

Control handle

Symbol
Ω:std.linalg.poly_fit · Ω:poly_fit
Pins
sha256:72b048432accb04964d2ad79df7cb063d648810444ac30869bc56fd6b79d03a5this graph and the 3 it reaches through calls
Evidence
sha256:66f37eb10bfdeca98457197b2e79b14cdee7a6a8b2c16a96265265645a5dd908the hash of its verification record
Needs
no capability: a pure function

Through NOVA’s control layer, the symbol launches this function only while the program still matches what it pins: a change to this graph, or to any graph it reaches, needs a migration first.

ΣEML 2026

Efficient New Language — a high-density semantic overlay for humans and AI agents.

This site’s demos run on the real EML toolchain, in your browser.

© 2026 EveMissLab (一言諾科技有限公司) / Neo.K. All rights reserved.