Raw Univariate Polynomial Operations #
Operations and evaluation lemmas for raw computable univariate polynomials.
Evaluates a CPolynomial.Raw at x : S using a ring homomorphism f : R →+* S.
Computes f(a₀) + f(a₁) * x + f(a₂) * x² + ... where aᵢ are the coefficients.
TODO: define an efficient version of this with caching
Equations
- CompPoly.CPolynomial.Raw.eval₂ f x p = Array.foldl (fun (acc : S) (x_1 : R × ℕ) => match x_1 with | (a, i) => acc + f a * x ^ i) 0 (Array.zipIdx p)
Instances For
Evaluates a CPolynomial.Raw at a given value
Equations
Instances For
Raw addition: pointwise sum of coefficient arrays (padded to equal length).
The result may have trailing zeros and should be trimmed for canonical form.
Equations
- p.addRaw q = match Array.matchSize p q 0 with | (p', q') => CompPoly.CPolynomial.Raw.mk (Array.zipWith (fun (x1 x2 : R) => x1 + x2) p' q')
Instances For
Scalar multiplication: multiplies each coefficient by r.
Equations
- CompPoly.CPolynomial.Raw.smul r p = CompPoly.CPolynomial.Raw.mk (Array.map (fun (a : R) => r * a) p)
Instances For
Raw scalar multiplication by a natural number (may have trailing zeros).
Equations
- CompPoly.CPolynomial.Raw.nsmulRaw n p = CompPoly.CPolynomial.Raw.mk (Array.map (fun (a : R) => ↑n * a) p)
Instances For
Scalar multiplication of CPolynomial.Raw by a natural number, with result trimmed.
Equations
Instances For
Multiplication by X^i: shifts coefficients right by i positions (prepends i zeros).
Equations
Instances For
Multiplication of a CPolynomial.Raw by X, reduces to mulPowX 1.
Equations
Instances For
Exponentiation of a CPolynomial.Raw by a natural number n via repeated multiplication.
This is the specification; powBySq is the efficient O(log n) implementation.
Instances For
Exponentiation via repeated squaring: $ O(\log n) $ multiplications instead of $ O(n) $.
For $ n > 0 $, computes $ p ^ n $ by recursing on $ n / 2 $:
- If $ n $ is even: $ (p ^ {n/2})^2 $
- If $ n $ is odd: $ p \cdot (p ^ {n/2})^2 $
Equations
Instances For
Equations
Equations
Equations
Equations
Equations
Equations
- CompPoly.CPolynomial.Raw.instNatCast = { natCast := fun (n : ℕ) => CompPoly.CPolynomial.Raw.C ↑n }
Upper bound on degree: size - 1 if non-empty, ⊥ if empty.
Equations
- p.degreeBound = match Array.size p with | 0 => ⊥ | n.succ => ↑n
Instances For
Pseudo-division by X: removes the constant term and shifts remaining coefficients left.
Equations
- p.divX = Array.extract p 1
Instances For
Equations
Equations
- CompPoly.CPolynomial.Raw.instIntCast = { intCast := fun (n : ℤ) => CompPoly.CPolynomial.Raw.C ↑n }
Erase the coefficient at index n: same as p except coeff n = 0, then trimmed.
Equations
- CompPoly.CPolynomial.Raw.erase n p = p - CompPoly.CPolynomial.Raw.monomial n (p.coeff n)