internal API
Purpose
Luna-Flow/luna-poly/internal holds helpers shared by the implementation packages. This page documents the contract the representations rely on. The reasoning is in the internal design.
Importing
MoonBit restricts an internal package to importers inside the same module, so only packages of luna-poly can write
import {
"Luna-Flow/luna-poly/internal",
}
Code outside luna-poly cannot call it.
Powers
pow_nat
Computes for a natural exponent by binary exponentiation, starting from the unit one.
pub fn[A : Mul] pow_nat(A, UInt, one~ : A) -> A
pow_nat(a, 0, one=u)returnsu, whateverais; this is how everypow(0)in the library returns one, including for zero.- It performs squarings and at most one further multiplication per set bit of , so at most calls of
*. - It needs only an associative
*for whichoneis a left unit; it does not need commutativity, because every factor it multiplies is a power ofa.
It is used for polynomial powers (DensePolynomial::pow, TermPolynomial::pow, SparsePolynomial::pow) and for coefficient powers during evaluation and substitution.
// Inside luna-poly only:
let p = @internal.pow_nat(base, 5U, one=DensePolynomial::one())