CompPoly has several distinct polynomial representations. Picking the right one is usually the first architectural decision in a change.
| Surface | Main type(s) | Best for | Main entrypoints |
|---|---|---|---|
| Univariate | CPolynomial.Raw R, CPolynomial R, QuotientCPolynomial R |
Canonical coefficient-sequence arithmetic, quotient reasoning, interpolation | CompPoly/Univariate/README.md, CompPoly/Univariate/Basic.lean, CompPoly/Univariate/ToPoly.lean |
| Multivariate | CMvPolynomial n R |
Sparse computable multivariate operations and MvPolynomial interop |
CompPoly/Multivariate/CMvPolynomial.lean, CompPoly/Multivariate/Operations.lean, CompPoly/Multivariate/MvPolyEquiv.lean |
| Multilinear | CMlPolynomial R n, CMlPolynomialEval R n |
Boolean-hypercube evaluation form, basis conversion, multilinear extensions | CompPoly/Multilinear/Basic.lean, CompPoly/Multilinear/Equiv.lean |
| Field extensions | Extension.Ext P |
Computable F[X]/f arithmetic for challenge fields, f an arbitrary monic modulus |
CompPoly/Fields/Extension.lean, docs/wiki/field-extensions.md |
| Bivariate | CBivariate R |
Specialized two-variable APIs and R[X][Y] transport |
CompPoly/Bivariate/README.md, CompPoly/Bivariate/Basic.lean, CompPoly/Bivariate/ToPoly.lean, CompPoly/ToMathlib/Polynomial/BivariateDegree.lean, CompPoly/ToMathlib/Polynomial/BivariateWeightedDegree.lean, CompPoly/ToMathlib/Polynomial/BivariateMultiplicity.lean |
| Dense matrices | DenseMatrix F |
Row-major matrices over a field: Gauss-Jordan reduction and homogeneous kernels | CompPoly/LinearAlgebra/README.md, CompPoly/LinearAlgebra/Dense/Basic.lean |
| Polynomial matrices | PolynomialMatrix F, PolynomialRow F |
Rows of univariate polynomials, shifted degrees, and shifted row reduction | CompPoly/LinearAlgebra/README.md, CompPoly/LinearAlgebra/PolynomialMatrix/Basic.lean |
The univariate stack distinguishes between three closely related views:
CPolynomial.Raw Ris the array-backed representation where trailing zeros are allowed.CPolynomial Ris the canonical trimmed representation.QuotientCPolynomial Ris the quotient model that packages coefficient-wise equivalence on raw arrays.
Use Raw when implementation detail matters, CPolynomial for normal user-facing
work, and QuotientCPolynomial when quotient reasoning is the cleanest proof
boundary.
The main bridge to Mathlib lives in:
../../CompPoly/Univariate/ToPoly/Core.lean../../CompPoly/Univariate/ToPoly/Equiv.lean../../CompPoly/Univariate/ToPoly/Degree.lean
For interpolation work, also read:
../../CompPoly/Univariate/Lagrange.leanfor the baseline interpolation surface and correctness statements.../../CompPoly/Univariate/Barycentric.leanfor repeated-query barycentric evaluation over a fixed node set with precomputed barycentric weights.
For root-of-unity NTT work:
../../CompPoly/Univariate/NTT/Domain.leancontains the shared domain type, fitting-domain helpers, and natural-order input loaders.../../CompPoly/Univariate/NTT/Evaluation.leanand../../CompPoly/Univariate/NTT/Interpolation.leanstate the bridge theorems connecting forward/inverse NTTs to evaluation and Lagrange interpolation.../../CompPoly/Univariate/NTT/FastMul.leanexposes the shared specification and baseline multiplication surface.../../CompPoly/Univariate/NTTFast/Plan.leanis the optimized planned implementation surface. TheNTTFast/Evaluation.leanandNTTFast/Interpolation.leanbridge files prove the planned transforms agree with the sharedNTTevaluation and interpolation specifications.
CMvPolynomial n R is the sparse computable multivariate surface highlighted in the
root README. It is the right place for:
- computable monomial-based operations,
- evaluation and substitution APIs,
- variable renaming and restriction,
- support and degree queries,
- transport to Mathlib
MvPolynomial (Fin n) R.
The main split is:
../../CompPoly/Multivariate/CMvPolynomial.leanfor core type-level definitions,../../CompPoly/Multivariate/Operations.leanfor the higher-level operation surface,../../CompPoly/Multivariate/MvPolyEquiv/for ring instances and bridge lemmas.
The multilinear stack is easy to miss if you only read the old top-level summary. It already has two distinct computable forms:
CMlPolynomial R nfor monomial-basis coefficients,CMlPolynomialEval R nfor evaluation values on{0,1}^n.
These are both represented as vectors of length 2 ^ n, with little-endian indexing.
That design is described directly in
../../CompPoly/Multilinear/Basic.lean.
Use this area for:
- Boolean-hypercube evaluation form,
- zeta / Mobius style basis transforms,
- multilinear-extension equivalences,
- fast multilinear pathways that do not fit the sparse
CMvPolynomialAPI.
CBivariate R is the specialized CPolynomial (CPolynomial R) layer. Use it when
the problem is truly two-variable and a dedicated API is clearer than treating the
code as generic multivariate syntax.
The key files are:
../../CompPoly/Bivariate/Basic.lean../../CompPoly/Bivariate/ToPoly.lean../../CompPoly/ToMathlib/Polynomial/BivariateDegree.lean../../CompPoly/ToMathlib/Polynomial/BivariateWeightedDegree.lean../../CompPoly/ToMathlib/Polynomial/BivariateMultiplicity.lean../../CompPoly/Bivariate/README.md
When the task is "prove the computable thing agrees with Mathlib", start in the bridge layer rather than the implementation file:
- Univariate bridge:
Univariate/ToPoly/* - Multivariate bridge:
Multivariate/MvPolyEquiv/* - Bivariate bridge:
Bivariate/ToPoly.leanplusToMathlib/Polynomial/BivariateDegree.lean,ToMathlib/Polynomial/BivariateWeightedDegree.lean, andToMathlib/Polynomial/BivariateMultiplicity.lean - Multilinear bridge:
Multilinear/Equiv.lean - Supporting upstream-facing lemmas:
ToMathlib/*
The local ToMathlib subtree is especially useful when a proof needs a helper lemma
that conceptually belongs between CompPoly and Mathlib rather than inside one
specific polynomial representation.
- If you need canonical coefficient arrays and interpolation, start with
CPolynomial; for repeated interpolation queries over a fixed domain, also inspectUnivariate/Barycentric.lean. - If you need sparse multivariate monomials or
MvPolynomialequivalence, start withCMvPolynomial. - If you need Boolean-cube evaluation data or multilinear transforms, start with
CMlPolynomialorCMlPolynomialEval. - If the API is naturally two-variable and you want
X/Y-specific operations, start withCBivariate. - If you need to solve a linear system or reduce a matrix rather than manipulate a
polynomial, start with
DenseMatrixorPolynomialMatrix. These areArray-backed and carry no shape invariant in the type; there is no bridge to Mathlib'sMatrix.
CompPoly/LinearAlgebra/ is the one family here with no Mathlib bridge layer, by
design: it exists to run, and its correctness statements are phrased against
row-span and pivot-shape predicates defined locally (RowSpan, PivotColumnsShaped)
rather than transported to Matrix. Both layers ship a direct definition and a
faster variant proved equal to it — rrefInPlace_eq for dense matrices,
muldersStorjohannReduceFast_eq for polynomial ones — so proofs go against the
direct version and executable code calls the fast one. See
../../CompPoly/LinearAlgebra/README.md.
Reed-Solomon codewords are not a separate representation — they are arrays of field
elements produced by evaluating a CPolynomial on a domain — but the decoders are a
substantial surface spanning Univariate/ReedSolomon/, Bivariate/GuruswamiSudan/,
Univariate/Roots/, and LinearAlgebra/. They are documented together in
coding-theory.md.
CompPoly.Extension.Ext P is a fixed-length dense representation, unlike the
polynomial surfaces above: Vector F P.d, where P : ExtensionParams F carries the
degree d, the lower coefficients of the monic modulus f, and the base-field
cardinality q as a type index. Binomials X^d - W are the ergonomic special case,
entered through BinomialParams.toExtensionParams.
The bridge is
../../CompPoly/Fields/Extension/Bridge.lean,
which maps into AdjoinRoot P.poly and proves the map bijective, and
../../CompPoly/Fields/Extension/Field.lean,
which yields Ext P ≃+* AdjoinRoot P.poly.
Because the representation has a fixed length, the degree bound is structural and no
degree-bound invariant is carried; this subtree is independent of the CPolynomial stack
and imports none of CompPoly/Univariate/. See
field-extensions.md for the full architecture, including why the
ring and field instances must be built by hand rather than transported.