The nonnegative gcd of the coefficients of an integer polynomial.
Kernel-facing specification: one fold over the reference coefficient list.
Compiled code runs the Array.foldl loop contentNatImpl via the @[csimp]
proof contentNat_eq_impl.
Equations
- p.contentNat = List.foldl (fun (acc : Nat) (coeff : Int) => acc.gcd coeff.natAbs) 0 p.toList
Instances For
Runtime implementation of contentNat: a direct Array.foldl with no
intermediate list (value-equal to contentNat by contentNat_eq_impl,
registered @[csimp]).
Equations
- p.contentNatImpl = Array.foldl (fun (acc : Nat) (coeff : Int) => acc.gcd coeff.natAbs) 0 p.toArray
Instances For
The reference contentNat and the Array.foldl runtime loop agree.
Register the Array.foldl loop as the compiled implementation of
contentNat.
The integer content of a polynomial. This is always nonnegative.
Equations
- p.content = Int.ofNat p.contentNat
Instances For
The primitive part obtained by dividing every coefficient by the content.
Kernel-facing specification: one map over the reference coefficient list.
Compiled code runs the Array.map pass primitivePartImpl via the @[csimp]
proof primitivePart_eq_impl.
Equations
- p.primitivePart = if p.contentNat = 0 then 0 else have c := Int.ofNat p.contentNat; Hex.DensePoly.ofList (List.map (fun (coeff : Int) => coeff / c) p.toList)
Instances For
Runtime implementation of primitivePart: one Array.map pass over the
stored coefficients (value-equal to primitivePart by
primitivePart_eq_impl, registered @[csimp]).
Equations
- p.primitivePartImpl = if p.contentNatImpl = 0 then 0 else have c := Int.ofNat p.contentNatImpl; Hex.DensePoly.ofCoeffs (Array.map (fun (coeff : Int) => coeff / c) p.toArray)
Instances For
The reference primitivePart and the Array.map runtime pass agree.
Register the Array.map pass as the compiled implementation of
primitivePart.
Scalar annihilator for primitive integer polynomials: if d divides every
coefficient of a * p and p is primitive (content one), then d already
divides a.
Scaling the primitive part by the content reconstructs the original integer polynomial.
Scaling the zero integer polynomial by -1 is still zero.
The zero integer polynomial has content zero.
If an integer polynomial has zero content, its primitive part is zero.
A polynomial whose content is 1 equals its primitive part.
The primitive part of a polynomial with nonzero content has content 1.