Raw Computable Univariate Polynomials #
Core definitions for array-backed computable univariate polynomials.
A type analogous to Polynomial that supports computable operations. This is defined to be a
wrapper around Array.
For example, the Array #[1,2,3] represents the polynomial 1 + 2x + 3x^2.
Two arrays may represent the same polynomial via zero-padding,
for example #[1,2,3] = #[1,2,3,0,0,0,...].
Equations
Instances For
Construct a CPolynomial.Raw from an array of coefficients.
Equations
- CompPoly.CPolynomial.Raw.mk coeffs = coeffs
Instances For
The coefficient of X^i in the polynomial. Returns 0 if i is out of bounds.
Equations
- p.coeff i = Array.getD p i 0
Instances For
Construct a monomial c * X^n as a CPolynomial.Raw R.
The result is an array with n zeros followed by c.
For example, monomial 2 3 = #[0, 0, 3] represents 3 * X^2.
Note: If c = 0, this returns #[] (the zero polynomial).
Equations
- CompPoly.CPolynomial.Raw.monomial n c = if c = 0 then #[] else CompPoly.CPolynomial.Raw.mk (Array.replicate n 0 ++ #[c])
Instances For
Return the index of the last non-zero coefficient of a CPolynomial.Raw
Equations
- p.lastNonzero = Array.findIdxRev? (fun (x : R) => x != 0) p
Instances For
Remove trailing zeroes from a CPolynomial.Raw.
Requires BEq to check if the coefficients are zero.
Equations
- p.trim = match p.lastNonzero with | none => #[] | some i => Array.extract p 0 (↑i + 1)
Instances For
Return the degree of a CPolynomial.Raw.
Instances For
Natural number degree of a CPolynomial.Raw.
Returns the degree as a natural number. For the zero polynomial, returns 0.
This matches Mathlib's Polynomial.natDegree API.
Equations
- p.natDegree = match p.lastNonzero with | none => 0 | some i => ↑i
Instances For
Return the leading coefficient of a CPolynomial.Raw as the last coefficient
of the trimmed array, or 0 if the trimmed array is empty.
Equations
- p.leadingCoeff = Array.getLastD p.trim 0
Instances For
Semantic canonicality for raw coefficient arrays: a polynomial is canonical iff its
last stored coefficient, when present, is nonzero. This invariant is independent of any
particular BEq instance.
Equations
- p.IsCanonical = ∀ (hp : Array.size p > 0), Array.getLast p hp ≠ 0
Instances For
If all coefficients are zero, lastNonzero is none.
If there is a non-zero coefficient, lastNonzero is some.
lastNonzero returns the largest index with a non-zero coefficient.
The property that an index is the last non-zero coefficient.
Equations
Instances For
The last non-zero index is unique.
Characterization of lastNonzero via lastNonzeroProp.
eliminator for p.lastNonzero, e.g. use with the induction tactic as follows:
induction p using lastNonzero_induct with
| case1 p h_none h_all_zero => ...
| case2 p k h_some h_nonzero h_max => ...
eliminator for p.trim; use with the induction tactic as follows:
induction p using induct with
| case1 p h_empty h_all_zero => ...
| case2 p k h_extract h_nonzero h_max => ...
Non-dependent canonicality criterion using getLastD.