star-polyfit 0.1.0
Least-squares polynomial, correctly rounded
Public state: Released & Verified. The registry label is RELEASED. What the states mean →
Apache-2.0 Released & Verified single file
Summary
Least-squares polynomial of degree 0 to 10, weighted or not: the normal equations are formed and solved in exact rational arithmetic and each coefficient is rounded once, so conditioning costs no digit; exact evaluation and exact residual sum of squares; NIST Wampler1 reproduced exactly; every coefficient of 161 problems equal to SymPy's exact solution.
Run in your browser
Edit the code and press Run (or Ctrl+Enter). Python runs in your browser with this package's published code. The first run downloads Python once (about 12 MB).
Runs in the browser: all 43 tests pass in the browser's Python (Pyodide 314.0.7, Python 3.14.2), measured on 20 October 2026.
Use it on your computer
No account and no GitHub needed. Download, then install with one command:
- Install file · star_polyfit-0.1.0-py3-none-any.whl 3 kB
- Single file — copy it alongside your code · star_polyfit.py 5 kB
- Source code (.zip) 23 kB
python -m pip install star_polyfit-0.1.0-py3-none-any.whlIn Python: import star_polyfit
Cite it, and its bill of materials
For a paper, a report or a supplier file: the citation in two formats, and the software bill of materials (SBOM) in the two standard formats, with the fingerprint of the wheel.
@software{cavazzini_star_polyfit_0_1_0,
author = {Cavazzini, Andrea},
title = {{star-polyfit}: Least-squares polynomial, correctly rounded},
version = {0.1.0},
year = {2026},
url = {https://andrea07072000.github.io/S.T.A.R.-/software/star_polyfit/},
note = {Apache-2.0. Source: https://github.com/Andrea07072000/S.T.A.R.-, commit dc09f61d}
}
For developers
Install directly from the public repository:
python -m pip install "star-polyfit @ git+https://github.com/Andrea07072000/S.T.A.R.-.git@dc09f61dcee098d518f070d6a23a8815defc1109#subdirectory=packages/star_polyfit"
Technical sheet
Requirements
- R1
polyfit(xs, ys, degree, weights=None)returns the coefficients, lowest power first, of the polynomial that minimises the sum of w (y - p(x))².polyval(coefficients, x)evaluates a polynomial;residual_sum(xs, ys, coefficients, weights=None)returns the weighted sum of squared residuals. - R2 The normal equations are formed and solved in exact rational arithmetic on the floats given, and each result is rounded once: the conditioning of the problem costs no digit.
polyvalandresidual_sumare exact sums rounded once as well. - R3 Measured on 161 problems (120 well conditioned, 40 badly conditioned, and the NIST dataset Wampler1): every coefficient equals the exact rational solution of SymPy rounded to a float and the QR solution of mpmath at 120 digits. NumPy agrees within 1e-9 on the well-conditioned problems; on the badly conditioned ones (x in [1000, 1001], x = 1e6 + k) its coefficients share no digit with the exact ones (the numbers are in the evidence file).
- R4 Every function returns floats or raises
ValueError: a degree that is not an integer from 0 to 10, data that are not lists or tuples of finite real numbers within 1e100 (booleans refused), different lengths, negative weights, fewer distinct x with a positive weight than degree + 1, a result too large for a float.
Limits (what is not claimed)
Exact coefficients are not a good model: a high-degree fit of noisy data oscillates, and the exact coefficients of a badly conditioned problem change a lot when the data change a little; the float nearest to each coefficient is still only a float, and evaluating the fitted polynomial in ordinary float arithmetic far from the origin can lose every digit (use polyval, or centre the data). No standard errors, no covariance matrix, no orthogonal polynomials, no automatic choice of the degree, no robust fitting. Exact arithmetic is slow: about a second for 2000 points at degree 10 on a laptop. "Nearest float" refers to the floats passed in, not to the decimal numbers you may have meant.
Release gate
Computed by the registry from the result files, with the same function that decides RELEASED.
- Mutation score, latest measure of each module (needs at least 0.850)
- star_polyfit.py 0.933 (2026-10-07)
- Independent implementations written by others (needs 2)
- mpmath.qr_solve at 120 digits, numpy.polynomial.polynomial.polyfit, SymPy exact rationals (LU on the normal equations)
- Result
- Released & Verified
Evidence in the registry
| Check | Status | Recorded | What was observed |
|---|---|---|---|
| Clean install from the release tag | VERIFIED | 2026-10-07 | pytest outside the tree: 43 passed in 0.42s |
| Unit tests | VERIFIED | 2026-10-07 | 43 passed in 0.60s |
| Review | VERIFIED | 2026-10-07 | Requirements, interface, units, data provenance, dependency surface and failure behaviour reviewed |
| Review | VERIFIED | 2026-10-07 | Re-running the cross-check gives a byte-identical evidence file |
| Reference value | VERIFIED | 2026-10-07 | polyfit(range 0..20, y, 5) = (1.0, 1.0, 1.0, 1.0, 1.0, 1.0); residual_sum = 0.0 (suite: 43 passed in 0.60s) |
| Cross-check with independent libraries | VERIFIED | 2026-10-07 | star_polyfit returns the float nearest to each exact least-squares coefficient of the data as given, for degree 0 to 10, weighted or not, whatever the conditioning |
| Benchmark | VERIFIED | 2026-10-07 | largest difference from the exact solution: 0.0; NumPy on problems with x in [1000, 1001] or x = 1e6 + k: up to 1.0e+00 relative |
Fingerprints (SHA-256)
| star_polyfit-0.1.0-py3-none-any.whl | 923f41d89a6a9b3ca518b4a8445acf054540994623add6ab24e1eb564067a425 |
| star_polyfit.py | 06546fdd6df439b32b38da7c47bacd00216407af317f25f0d0e1784605f0f566 |
| star_polyfit-0.1.0-source.zip | 5f6e6e1fb9b23bf1a1d5ebb4e81cb6e6b8bba8d4eee8fe05be44aac1178ff47c |
