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 indigits, in the mixed radix ofbases, as APL’s⊥gives it: Horner’s rule, with each step’s own base. The first base is never used.integer::decodegivesi64s, checked for overflow. - derivative
- The derivative of the polynomial
c. It checks for an interrupt between groups ofBETWEEN_CHECKScoefficients. - encode
- The digits of each of
valuesin the mixed radix ofbases, as APL’s⊤gives them: each value’s digits together, the most significant first.residue(b, v)isv’s residue by the baseb, which for a base of 0 isv, so a base of 0 takes all of what remains as its digit.integer::encodegivesi64s, checked for overflow. - evaluate
- Appends to
outthe value of the polynomialcat each item ofx, by Horner’s rule. An f16 polynomial computes in f32 and rounds each result once. - factored
- The value at
xofmtimes the product ofx - rover the rootsr. It checks for an interrupt between groups ofBETWEEN_CHECKSroots. - fit
- The polynomial of degree
degreethat fits the points(x[i], y[i])by least squares, whichlstsqsolves in f64. Where fewer thandegree + 1distinct points fix the polynomial, it’s the fit whose coefficients have the least norm. Panics ifxandydiffer in length. - from_
roots - The polynomial
mtimes the product ofx - rover the rootsr. It checks for an interrupt between roots. - roots
- The roots of the polynomial
c, as the eigenvalues of its companion matrix, computed in f64 byeigenvalues, sorted by real part, then imaginary part. Real coefficients take the real solver, so a real root has an imaginary part of exactly 0.Nonewhen the eigenvalue solver doesn’t converge. - trimmed
cwithout its trailing zeros.- value
- The value of the polynomial
catx, by Horner’s rule, for anyTwith the field operations, such as an exact rational.evaluatecomputes the values of a float polynomial at many points at once. It checks for an interrupt between groups ofBETWEEN_CHECKScoefficients.