Multilinear Polynomials #
This file defines computable representations of multilinear polynomials.
The first representation is by their coefficients, and the second representation is by their
evaluations over the Boolean hypercube {0,1}^n. Both representations are defined as Vectors of
length 2^n, where n is the number of variables. We will define operations on these
representations, and prove equivalence between them, and with the standard Mathlib definition of
multilinear polynomials, which is the type R⦃≤ 1⦄[X Fin n] (notation for
MvPolynomial.restrictDegree (Fin n) R 1).
TODOs #
- The abstract zeta formula for
monoToLagrange - A naive
O(4^n)zeta specmonoToLagrangeSpecmirroringlagrangeToMonoSpec, plus equivalencemonoToLagrange = monoToLagrangeSpec
CMlPolynomial n R is the type of multilinear polynomials in n variables over a ring R.
It is represented by its monomial coefficients as a Vector of length 2^n.
The indexing is little-endian (i.e. the least significant bit is the first bit).
Instances For
Instances For
CMlPolynomialEval n R is the type of multilinear polynomials in n variables over a ring R.
It is represented by its evaluations over the Boolean hypercube {0,1}^n,
i.e. Lagrange basis coefficients.
The indexing is little-endian (i.e. the least significant bit is the first bit).
Instances For
Instances For
Conform a list of coefficients to a CMlPolynomial with a given number of variables.
May either pad with zeros or truncate.
Instances For
Instances For
Add two CMlPolynomials
Instances For
Negation of a CMlPolynomial
Instances For
Scalar multiplication of a CMlPolynomial
Instances For
Scalar multiplication of a CMlPolynomial by a natural number
Instances For
Scalar multiplication of a CMlPolynomial by an integer
Instances For
Instances For
The i-th element of monomialBasis w is the product of w[j] if the j-th bit of i is 1,
and 1 if the j-th bit of i is 0.
Instances For
Evaluate a CMlPolynomial at a point
Instances For
Instances For
Conform a list of coefficients to a CMlPolynomialEval with a given number of variables.
May either pad with zeros or truncate.
Instances For
Instances For
Add two CMlPolynomialEvals
Instances For
Negation of a CMlPolynomialEval
Instances For
Scalar multiplication of a CMlPolynomialEval
Instances For
Scalar multiplication of a CMlPolynomialEval by a natural number
Instances For
Scalar multiplication of a CMlPolynomialEval by an integer
Instances For
Lagrange (hypercube) basis at point w.
Returns the length-2^n vector v such that for any x ∈ {0,1}^n, letting
i = ∑_{j=0}^{n-1} x_j · 2^j (little‑endian indexing), we have
v[i] = ∏_{j < n} (x_j · w[j] + (1 - x_j) · (1 - w[j])).
Equivalently, for i : Fin (2^n),
v[i] = ∏_{j < n}, (if the j-th bit of i is 1 then w[j] else 1 - w[j]).
Instances For
The i-th element of lagrangeBasis w is the product of w[j] if the j-th bit of i is 1,
and 1 - w[j] if the j-th bit of i is 0.
Map a ring homomorphism over a CMlPolynomialEval
Instances For
Evaluate a CMlPolynomialEval at a point
Instances For
Evaluate a CMlPolynomialEval at a point using a ring homomorphism
Instances For
One level of the zeta‑transform (coefficient to evaluation).
Processes the j-th variable by folding the "partner" index (with bit j cleared) into
every index that has bit j set. At output index i:
$$ (\text{monoToLagrangeLevel}\ j\ v)[i] \ =\ \begin{cases} v[i] + v[i - 2^j] & \text{if bit } j \text{ of } i \text{ is } 1 \\ v[i] & \text{otherwise} \end{cases} $$
After applying every level 0, 1, …, n-1 the resulting entry at i is
$\sum_{j \subseteq i} p[j]$ (bitwise subset), which is the hypercube evaluation at the
Boolean point encoded by i. Cost per level: $O(2^n)$ additions, so the full transform
is $O(n \cdot 2^n)$.
The stride is $2^j$, the distance between indices that differ only in bit j.
Instances For
Full zeta transform: coefficients → evaluations.
Applies monoToLagrangeLevel 0, 1, …, n-1 in that order via foldl. The resulting entry
at each index i : Fin (2 ^ n) is $\sum_{j \subseteq i} p[j]$ (the classical zeta
transform on the Boolean lattice).
Complexity: $O(n \cdot 2^n)$ additions — this is the butterfly form. Contrast with
the naive monoToLagrangeSpec which is $O(4^n)$.
Instances For
One level of the inverse zeta‑transform / Möbius transform (evaluation to coefficient).
Processes the j-th variable by subtracting the partner entry (bit j cleared) from
every index that has bit j set. At output index i:
$$ (\text{lagrangeToMonoLevel}\ j\ v)[i] \ =\ \begin{cases} v[i] - v[i - 2^j] & \text{if bit } j \text{ of } i \text{ is } 1 \\ v[i] & \text{otherwise} \end{cases} $$
Each level is the exact inverse of monoToLagrangeLevel j (see
lagrangeToMonoLevel_monoToLagrangeLevel_id).
The stride is $2^j$.
Instances For
Full inverse / Möbius transform: evaluations → coefficients.
Applies lagrangeToMonoLevel (n-1), (n-2), …, 0 via foldr. The resulting entry at
each index i : Fin (2 ^ n) is the inclusion-exclusion sum
$\sum_{j \subseteq i} (-1)^{\mathrm{popCount}(i) - \mathrm{popCount}(j)} \cdot p[j]$ —
see lagrangeToMono_eq_lagrangeToMonoSpec.
Complexity: $O(n \cdot 2^n)$ additions/subtractions. Contrast with the naive
lagrangeToMonoSpec which is $O(4^n)$.
Instances For
The $O(4^n)$ inclusion-exclusion specification for the Möbius transform.
For each output index i, this sums over all indices j that are bitwise subsets of i
(i &&& j = j), with sign
$(-1)^{\mathrm{popCount}(i) - \mathrm{popCount}(j)}$:
$$ (\text{lagrangeToMonoSpec}\ p)[i] = \sum_{j \subseteq i} (-1)^{\mathrm{popCount}(i) - \mathrm{popCount}(j)} \cdot p[j]. $$
Provable equivalent to the fast lagrangeToMono — see lagrangeToMono_eq_lagrangeToMonoSpec.
Instances For
The $O(4^n)$ specification for the zeta transform (the mirror of
lagrangeToMonoSpec).
For each output index i, this sums p[j] over every index j that is a bitwise subset
of i (i &&& j = j):
$$ (\text{monoToLagrangeSpec}\ p)[i]\ =\ \sum_{j \subseteq i} p[j]. $$
Provable equivalent to the fast monoToLagrange — see monoToLagrange_eq_monoToLagrangeSpec.
Instances For
Generates a list of indices representing a range of bit positions [l, r] in increasing order.
Used for optimized recursive transforms that operate on segments of variables.
Returns a list containing l, l+1, ..., r.
The result is used to fold over dimensions in monoToLagrangeSegment and lagrangeToMonoSegment.
Instances For
Performs the zeta-transform (coefficient to evaluation) on a segment of dimensions from l to r.
Iteratively applies monoToLagrangeLevel for each dimension in the range.
0 ≤ l ≤ r < n.
Instances For
Performs the inverse zeta-transform (evaluation to coefficient) on a segment of dimensions
from l to r.
Iteratively applies lagrangeToMonoLevel for each dimension in the range (in reverse order).
0 ≤ l ≤ r < n.
Instances For
The equivalence between the monomial basis representation (CMlPolynomial)
and the Lagrange basis representation (CMlPolynomialEval) of a multilinear polynomial.
The forward map is monoToLagrange (zeta transform) and the inverse is lagrangeToMono
(inverse zeta transform/Mobius transform).
Instances For
#eval Tests #
This section contains tests to verify the functionality of multilinear polynomial operations.