Fast Polynomial Evaluation — Chain Compiler
thomasahle.com- Category
- Developer Tools
- Rank
- No. 3212Tools index
Previous survey · No. 3079 ·
- Pricing
- Free
- Type
- TOOL
- Use case
- Research & Education
- Interfaces
- Web
- GitHub
- 30 stars
- Date
About
A browser-based tool that compiles a degree-n polynomial into an evaluation chain requiring roughly n/2 multiplications instead of the n needed by Horner's method, using rational coefficient preprocessing over fields like ℚ, ℝ, ℂ, Mersenne primes, or binary fields. Output can be rendered as math notation, C code, or a circuit, useful for function approximation and cryptographic or coding-theory applications.
What it does
A polynomial compiler that trades a one-time rewrite of the coefficients for fewer products at evaluation time. You enter a polynomial and pick an arithmetic setting; it returns a short sequence of products and sums, shown as formulas, compilable C or a circuit graph, beside classical schemes such as Horner and Estrin on the same input. The rewrite is exact and needs only a few divisions and a small triangular solve, so no root finding is involved. Behind the web page sit a research paper, a Python reference implementation and machine-checked Lean proofs.
Why it's ranked here
The claim behind it is a research result, and the repository backs it with more than prose. Any monic polynomial of degree n, over characteristic zero or a prime field larger than n, evaluates with half the degree, rounded down, plus one multiplication, which answers a question Rabin and Winograd left open. The main bound is formalized in Lean 4 with Mathlib, and a GitHub Actions job rebuilds the proofs on every push and pull request. The code is MIT licensed and the generated C is released under the no-attribution 0BSD license, so output can go straight into a product.
What's good
Every decoding claim ships with an explicit inverse rather than a numerical solver: the project's stated policy rejects sampled tests and Jacobian checks as proof of bijectivity. The Python tool verifies each decode by re-expanding the result and refuses a mismatch, and a self-test round-trips encoding and decoding up to a chosen degree. The hashing angle is concrete: drawing the chain's parameters uniformly equals drawing a uniformly random monic polynomial, which gives n-wise independence. The paper reports hashing speedups over Horner of 1.84x on an Apple M2 Pro and 2.15x on an Intel Xeon at nine-wise independence.
Tradeoffs
The schedules are exact, and the paper states that in floating point they are numerically unstable, because the rewritten constants for an arbitrary polynomial are large and cancel. That limits real-number use, the case function approximation cares about most. Additions climb to as many as 2n, against roughly n for Rabin and Winograd's scheme. Even degrees cost one multiplication more than the algebraic optimum. Characteristic two, the setting of binary-field hashing, has fixed constructions only for odd degrees up to 25, Lean checks cover degrees 5 to 16, and a uniform construction is listed as open. The Python reference does not handle characteristic two.
How to use it well
Best fit: hashing or coding-theory code over prime fields or binary fields, where arithmetic is exact and multiplications dominate the cost. Compile the polynomial, download the C benchmark bundle and run it on the target machine, since the project warns that timings depend on architecture and compiler. Hardware binary-field kernels need x86-64 with PCLMULQDQ or ARM64 with PMULL. For approximating functions in double precision, stay with Horner or Estrin unless you have measured the error on your inputs. Researchers can script the compiler from Python or recheck the proofs with one Lake build.
Technical notes+
tools/poly_schedule.py compiles a concrete coefficient vector into a PolynomialChain of MulGate entries whose AffineForm inputs allow only integer wire coefficients, so no scalar multiply hides inside a linear form; Horner appears only as the --check reference evaluator. tools/polychain.py implements the paper's recursive decoder (even lift, P3/P5/P7 bases, the 4k+1 family, the 8k+3 and 8k+7 steps), defaults to GF(2^61-1) or exact Fraction arithmetic, verifies every decode by re-expansion, and raises NotImplementedError for characteristic 2. Field.sqrt in poly_schedule.py is implemented only for GF(2). FastPoly/PaperMain.lean packages the main bound as the MainArrangementsChecked structure with of_charZero and of_charP constructors. lakefile.lean requires Mathlib, and .github/workflows/lean_action_ci.yml runs leanprover/lean-action on push and pull_request. char2/README.md lists one certificate script per odd degree from 5 to 25.
Observed
- License
- MIT for the repository; generated C under 0BSD
- Interfaces
- Browser compiler with no build step, Python command-line tools, Lean 4 library
- Formal proofs
- Lean 4 formalization built with Lake on Mathlib
- Multiplication bound
- floor(n/2)+1 multiplications for monic degree n, characteristic zero or above n
- Numerical stability
- Unstable in floating point; intended for exact or modular arithmetic
- Hardware targets
- Binary-field C kernels for x86-64 PCLMULQDQ or AArch64 PMULL
- Python reference fields
- Odd prime fields and exact rationals; characteristic 2 not supported
- Continuous integration
- GitHub Actions runs the Lean build on push and pull request
Read from README.md, LICENSE, lakefile.lean, FastPoly/ROADMAP.md, FastPoly/PaperMain.lean, tools/polychain.py, tools/poly_schedule.py, char2/README.md, sections/introduction.tex, sections/main_theorem.tex, .github/workflows/lean_action_ci.yml.
What it can do
Compile a degree-n polynomial into an evaluation chain requiring approximately n/2 multiplications
Degree-n polynomial with rational coefficients → Optimized evaluation chain
Render the computed evaluation chain as mathematical notation
Evaluation chain → Math notation
Generate C code implementing the evaluation chain
Evaluation chain → C code
Generate a circuit representation of the evaluation chain
Evaluation chain → Circuit diagram
Preprocess polynomial coefficients over different fields (ℚ, ℝ, ℂ, Mersenne primes, binary fields)
Polynomial coefficients and field choice → Preprocessed coefficients for evaluation chain construction
Tags
Comments (0)
No comments yet
Editorially curated, with community endorsements as a secondary signal. Corrections welcome.