Skip to main content

Module polynomial

Module polynomial 

Source
Expand description

Polynomials of one variable. A polynomial is the slice of its coefficients in ascending order, so c stands for c[0] + c[1]x + c[2]x² + …. Trailing zero coefficients don’t count towards the degree. evaluate therefore never multiplies an infinite x by one of them. from_roots, derivative, value and factored check for an interrupt between roots, or between groups of BETWEEN_CHECKS coefficients or roots, and return its error as soon as they get one, as linalg::exact’s functions do. A call too short for a second group makes no check, so evaluating a short polynomial at each of many points costs no checks.

Functions§

decode
The value of each cell of bases.len() digits in digits, in the mixed radix of bases, as APL’s ⊥ gives it: Horner’s rule, with each step’s own base. The first base is never used. integer::decode gives i64s, checked for overflow.
derivative
The derivative of the polynomial c. It checks for an interrupt between groups of BETWEEN_CHECKS coefficients.
encode
The digits of each of values in the mixed radix of bases, as APL’s ⊤ gives them: each value’s digits together, the most significant first. residue(b, v) is v’s residue by the base b, which for a base of 0 is v, so a base of 0 takes all of what remains as its digit. integer::encode gives i64s, checked for overflow.
evaluate
Appends to out the value of the polynomial c at each item of x, by Horner’s rule. An f16 polynomial computes in f32 and rounds each result once.
factored
The value at x of m times the product of x - r over the roots r. It checks for an interrupt between groups of BETWEEN_CHECKS roots.
fit
The polynomial of degree degree that fits the points (x[i], y[i]) by least squares, which lstsq solves in f64. Where fewer than degree + 1 distinct points fix the polynomial, it’s the fit whose coefficients have the least norm. Panics if x and y differ in length.
from_roots
The polynomial m times the product of x - r over the roots r. It checks for an interrupt between roots.
roots
The roots of the polynomial c, as the eigenvalues of its companion matrix, computed in f64 by eigenvalues, sorted by real part, then imaginary part. Real coefficients take the real solver, so a real root has an imaginary part of exactly 0. None when the eigenvalue solver doesn’t converge.
trimmed
c without its trailing zeros.
value
The value of the polynomial c at x, by Horner’s rule, for any T with the field operations, such as an exact rational. evaluate computes the values of a float polynomial at many points at once. It checks for an interrupt between groups of BETWEEN_CHECKS coefficients.