perf(univariate): optimize eval and pow backends#190
perf(univariate): optimize eval and pow backends#190eliasjudin wants to merge 2 commits intoVerified-zkEVM:masterfrom
Conversation
Replace the univariate evaluation backend with Horner evaluation, move Raw.pow to exponentiation by squaring with the lawful raw theorem surface, and update the downstream bridges and regression tests that preserve the canonical API behavior. Co-authored-by: Aristotle (Harmonic) <aristotle-harmonic@harmonic.fun>
🤖 Gemini PR SummaryAlgorithmic OptimizationsOptimizes the univariate polynomial library by replacing naive implementations with asymptotically more efficient algorithms while preserving the existing public API.
Refactoring and Proof ArchitectureUpdates the library's proof architecture to accommodate the new computational backends:
Testing and ValidationExpands the test suite to verify the performance optimizations and ensure algebraic correctness:
Statistics
Lean Declarations ✏️ **Removed:** 5 declaration(s)
✏️ **Added:** 14 declaration(s)
✏️ **Affected:** 6 declaration(s) (line number changed)
🎨 **Style Guide Adherence**There are 24 violations of the style guide. They are grouped by rule below:
📄 **Per-File Summaries**
Last updated: 2026-04-08 12:31 UTC. |
Normalize proof formatting, lambda notation, and instance style in the univariate eval/pow lane while preserving the accepted Horner and fast-power implementation.
There was a problem hiding this comment.
hey @eliasjudin , thank you for this PR! this is definitely something that we want, sorry for the delay as I've been traveling. We've recently merged #199 that adds Horner's method. this PR makes the swap - can you merge in the main branch into this?
to be clear - from main we want eval₂ => eval₂Naive and eval₂Horner => eval₂ as you have it here
| /- | ||
| `eval₂` equals the list sum of mapped `zipIdx` pairs. | ||
| -/ | ||
| theorem eval₂_eq_list_sum (f : R →+* S) (x : S) (p : CPolynomial.Raw R) : |
There was a problem hiding this comment.
I think this theorem is covered in eval₂_eq_eval₂_naive (and currently on main as eval₂_eq_eval₂Horner) and unused anywhere else - may not need it?
Summary
Optimize the univariate evaluation and power backends by:
eval/eval₂entrypoints;toPoly, quotient, and bivariate bridge theorems needed by the canonical API.This PR adds proofs autoformalised by @Aristotle-Harmonic.
Motivation
The univariate layer previously evaluated raw polynomials through explicit sums of powers and powered raw polynomials through repeated multiplication. Those definitions were semantically correct but asymptotically wasteful, and Phase 2 called for moving both surfaces to the standard Horner/squaring backends without changing the public canonical behavior.
Mathematical content
For evaluation, the new backend proves that the Horner fold agrees with the previous sum-of-powers semantics and transports that equality through the existing
toPolybridge, canonicalCPolynomialAPI, and the bivariatetoPolybridge.For powers, the public raw backend is replaced by exponentiation by squaring. The raw proof layer is updated at the mathematically correct lawful boundary, with lawful raw power theorems identifying the fast backend with repeated multiplication and preserving the canonical semiring behavior on
CPolynomialandQuotientCPolynomial.The PR also adds univariate regression tests covering zero, constant, monomial, trailing-zero, and nontrivial evaluation cases, together with canonical power regressions through the existing univariate test surface.
Testing
./scripts/lint-style.sh CompPoly/Univariate/Raw/Ops.lean CompPoly/Univariate/Raw/Proofs.lean CompPoly/Univariate/Basic.lean CompPoly/Univariate/Quotient/Core.lean CompPoly/Univariate/ToPoly/Core.lean CompPoly/Univariate/ToPoly/Impl.lean CompPoly/Bivariate/ToPoly.lean tests/CompPolyTests/Univariate/Basic.lean tests/CompPolyTests/Univariate/Eval.lean tests/CompPolyTests.leanlake buildlake testrg -n "sorry|admit|axiom|unsafe" CompPoly.lean CompPoly/**/*.lean tests/**/*.leanRefs #186
Co-authored-by: Aristotle (Harmonic) aristotle-harmonic@harmonic.fun