x^g for g ≥ 1 by binary powering, using only multiplication:
gap powers never need an identity element (pow1 x 0 is x, unused).
Equations
- Hex.SparsePoly.pow1 x 0 = x
- Hex.SparsePoly.pow1 x 1 = x
- Hex.SparsePoly.pow1 x g.succ.succ = if (g + 2) % 2 = 1 then Hex.SparsePoly.pow1 (x * x) ((g + 2) / 2) * x else Hex.SparsePoly.pow1 (x * x) ((g + 2) / 2)
Instances For
a * x^g, using only multiplication: g = 0 is the identity
application and multiplies nothing.
Equations
- Hex.SparsePoly.mulPow a x 0 = a
- Hex.SparsePoly.mulPow a x g.succ = a * Hex.SparsePoly.pow1 x (g + 1)
Instances For
Gap-Horner worker: the value of an ascending term list at x,
relative to a base exponent, with each bracket closed by one gap power.
evalShifted x l b is Σ cᵢ · x^(eᵢ − b) bracketed as
(c₀ + (c₁ + …) · x^(e₁−e₀)) · x^(e₀−b).
Equations
- Hex.SparsePoly.evalShifted x [] x✝ = 0
- Hex.SparsePoly.evalShifted x ((e, c) :: rest) x✝ = Hex.SparsePoly.mulPow (c + Hex.SparsePoly.evalShifted x rest e) x (e - x✝)
Instances For
Evaluate at x by Horner over the exponent gaps: writing m for
the term count and n for the degree, m additions and
O(m · log(n/m + 1)) multiplications, against DensePoly's O(n).
Equations
- s.eval x = Hex.SparsePoly.evalShifted x s.terms.toList 0
Instances For
Powers of the square are even powers.
The positive binary powering computes the semiring power.
The gap multiplier computes multiplication by the power.
The gap-Horner worker computes the exponent-shifted term sum.
Gap Horner agrees with dense Horner. Lean.Grind.Semiring and not
CommRing: both run in the same orientation and the gap form only
skips the zero coefficients, so no coefficient is commuted past a power
of x.
The formal derivative: c · x^e maps to (e : R) · c · x^(e−1),
the e = 0 term is dropped, and — the invariant hazard — a coefficient
(e : R) * c that vanishes (every exponent divisible by p over
ZMod64 p) drops its term rather than storing a zero.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Coefficient law for the derivative.
Substitute x^k for x: multiply every exponent by k. For
k ≥ 1 the map is strictly monotone, so the terms, their order, and
their coefficients are unchanged and the cost is O(t). For k = 0
every term lands on exponent 0, so the result is the combined
constant, which can vanish; that case is a canonicalisation to perform,
not an input to reject.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Coefficient law for the sparse substitution, positive case: the
coefficient moves from e to k · e untouched.
One step of the substScale walk: the power of a for the next
exponent, from the power at the previous one (none encodes a^0, so
no identity element is needed).
Equations
Instances For
Walk the ascending terms scaling each coefficient by the
accumulated power of a, dropping the products that vanish: the worker
for substScale.
Equations
Instances For
The walk emits a canonical list.
Scale the argument: c · x^e maps to (c · a^e) · x^e, with the
powers of a computed from the exponent gaps as eval computes its
powers of x. Exponents are unchanged; coefficients can vanish when
a is a zero divisor or zero, so the zero filter applies.
Equations
- s.substScale a = Hex.SparsePoly.ofCanonicalList (Hex.SparsePoly.substScaleGo a 0 none s.terms.toList) ⋯ ⋯
Instances For
p^g for g ≥ 1 by binary powering over mul, with no identity
needed: the gap powers of compose are always positive.
Equations
Instances For
Substitute t for x in s: Σ cₑ · t^e in increasing exponent,
with the powers of t obtained by binary powering from the exponent
gaps. The cost is the sum of the multiplication costs over this
schedule, not a function of the output size. A caller wanting f(x^k)
must use substPow, never this.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Substitute t for the variable of s: one fold of composeStep over the terms, carrying the running power of t across each exponent gap.
Instances For
The derivative transports through the dense conversion.
The derivative is additive.
The product rule, by transport through the dense derivative.
Powers at added exponents multiply, on the polynomials themselves.
Powers of the square are even powers, on the polynomials themselves.
The positive binary powering over mul computes the power.
Evaluation is additive, by transport.
Evaluation is multiplicative, by transport.
Evaluating a monomial multiplies its coefficient by the power.
Constants evaluate to their value.
One evaluates to 1.
Zero evaluates to 0.
Evaluation respects powers.
The value the compose walk carries for t^prev (none encodes
t^0 so that no identity element is needed at the [Add R] [Mul R]
signature).
Equations
Instances For
compose as the plain power-sum fold over the stored terms:
the characterisation everything below transports through.
Powers transport to the dense iterated product.
The substitution transports: composing then converting is converting then composing.
Powers of a monomial are monomials.
Constants scale monomials by scaling their coefficient.
The fast path and the general path agree: what lets the cyclotomic
adapter use substPow and reason with compose.
Substitution then evaluation is evaluation at the evaluation.
Evaluating the exponent substitution is evaluating at the power.
The exponent substitution transports to dense composition with the unit monomial.
Coefficient law for substScale: each coefficient is scaled
by the power of the argument at its exponent.
Argument scaling is composition with the degree-one monomial
a · x: the sparse fast path and the general path agree.
The scaling substitution transports to dense composition with the degree-one monomial.