ApasScript.

Polynomials

subst

Replaces a variable with an expression, everywhere it occurs free.

freeVars

The free variables of an expression, sorted.

polyDivide

Polynomial long division: the quotient and remainder.

syntheticDivide

Synthetic division by x - c, its table as it is written: coefficients (the dividend's, highest power first, a 0 for each missing power), products (c times the number before, one under each coefficient after the first), results (the bottom row: each coefficient plus the product under it), and the quotient and remainder the bottom row gives.

polyGcd

The monic greatest common divisor of two polynomials. Works up to degree 7000; so does every function here that reads a polynomial written with a power.

resultant

The resultant of two polynomials: zero exactly when they share a root. With one free parameter among the coefficients the answer is a polynomial in it: resultant(x^2 + p*x + 1, x^2 + x + p) is p^3 - 3*p + 2, and solve(resultant(x^2 + p*x + 1, x^2 + x + p) = 0, p) finds the p for which the two share a root. When the letters leave the variable unclear, name it third: resultant(f, g, x). Coefficients may be whole numbers, fractions, radicals (sqrt(2)) or decimals, and the polynomial may be given as its coefficient list, highest power first ([1, 0, -3, 1] is x^3 - 3x + 1).

polyDegree

The degree of a polynomial.

polyCoeff

The coefficient of x^k in a polynomial.

coeff

The coefficient of x^k in a polynomial, as polyCoeff with the variable named: coeff(expand((1 + x)*(1 + x^2)*(1 + x^3)), x, 3) is 2.

symSum

The exact sum of an expression over an integer range of an index (at most 10,000 terms); sum(term, k, a, b) is the same, and takes a letter as the upper bound too. A total that would run past 400 digits is refused and fsum(term, k, a, b) named, which adds in doubles.

fsum

The sum of an expression over an integer range of an index, worked in doubles: for the long sums whose exact value would run to hundreds of digits (sum() refuses one past 400 digits and names fsum). Each term is exact where it can be; the terms are added with compensation. Up to a million terms. fsum(1/k^2, k, 1, 100000) is 1.644924067.

symProduct

The exact product of an expression over an integer range of an index.

geometricSum

The sum of an infinite geometric series a + a*r + a*r^2 + ..., only when |r| < 1.

exactSin

The exact value of sin at a whole number of degrees, when one exists; none otherwise. Exact values combine exactly in products, powers, quotients and sums (exactSin(60)^2 is 3/4), and float() or decimal() gives the decimal.

exactCos

The exact value of cos at a whole number of degrees, when one exists; none otherwise.

exactTan

The exact value of tan at a whole number of degrees; none where it is undefined or not exact.

polyDerivative

The derivative of a polynomial in one variable.

signChanges

Number of sign changes in the coefficients of a polynomial (zeros skipped), highest power first.

descartesPositive

Descartes' rule: the most positive roots a polynomial can have (its sign changes); the true number is this or less by an even number. Coefficients may be whole numbers, fractions, radicals (sqrt(2)) or decimals, and the polynomial may be given as its coefficient list, highest power first ([1, 0, -3, 1] is x^3 - 3x + 1).

descartesNegative

Descartes' rule for negative roots: the sign changes of p(-x). Coefficients may be whole numbers, fractions, radicals (sqrt(2)) or decimals, and the polynomial may be given as its coefficient list, highest power first ([1, 0, -3, 1] is x^3 - 3x + 1).

countRealRoots

Number of distinct real roots of a polynomial, by Sturm's theorem; with lo and hi, the number in the interval (lo, hi]. Coefficients may be whole numbers, fractions, radicals (sqrt(2)) or decimals, and the polynomial may be given as its coefficient list, highest power first ([1, 0, -3, 1] is x^3 - 3x + 1). Degree 12 and beyond works (the arithmetic moves to big rationals): countRealRoots(x^12 - 1) is 2, countRealRoots(x^3 - 1.5*x + 0.2) is 3.

vieta

The list [e1, e2, ..., en] of sums of products of the roots taken 1, 2, ... n at a time (signs included), from the coefficients. Coefficients may be whole numbers, fractions, radicals (sqrt(2)) or decimals, and the polynomial may be given as its coefficient list, highest power first ([1, 0, -3, 1] is x^3 - 3x + 1). vieta([1, 0, -3, 1]) is [0, -3, -1].

powerSums

The sum of the k-th powers of the roots (Newton's identities), repeated roots counted; k = 0 gives the degree. Coefficients may be whole numbers, fractions, radicals (sqrt(2)) or decimals, and the polynomial may be given as its coefficient list, highest power first ([1, 0, -3, 1] is x^3 - 3x + 1).

polyFromRoots

The monic polynomial with the given rational roots.

transformRoots

The monic polynomial whose roots are f(r) for each root r of p, with f a polynomial: f = 2*x + 3 gives roots 2r+3, f = x^2 gives r^2; transformRoots(x^2 - 3*x + 2, 2*x + 1) is x^2 - 8*x + 15 (roots 3 and 5). Coefficients may be whole numbers, fractions, radicals (sqrt(2)) or decimals, and the polynomial may be given as its coefficient list, highest power first ([1, 0, -3, 1] is x^3 - 3x + 1).

reciprocalRoots

The monic polynomial whose roots are 1/r for the roots r of p (no root may be 0). Coefficients may be whole numbers, fractions, radicals (sqrt(2)) or decimals, and the polynomial may be given as its coefficient list, highest power first ([1, 0, -3, 1] is x^3 - 3x + 1).

polyDiscriminant

The discriminant of a polynomial (degree up to about 15): zero exactly when there is a repeated root; for the quadratic ax^2+bx+c it is b^2-4ac. (`discriminant` is for conics.) With one free parameter among the coefficients the answer is a polynomial in it: polyDiscriminant(x^3 - 3*x + p) is -27*p^2 + 108, and solve(polyDiscriminant(x^3 - 3*x + p) = 0, p) is [-2, 2], the p with a repeated root; the variable may be named second, polyDiscriminant(poly, x). Coefficients may be whole numbers, fractions, radicals (sqrt(2)) or decimals, and the polynomial may be given as its coefficient list, highest power first ([1, 0, -3, 1] is x^3 - 3x + 1).

eisenstein

True when Eisenstein's criterion holds for the prime p (fractions cleared first): p does not divide the leading coefficient, divides all the others, and p^2 does not divide the constant.

isIrreducible

True when a polynomial cannot be factored over the rationals. Decided by Eisenstein (also after x -> x + s) or Kronecker's search for a factor; a polynomial with huge values is refused rather than guessed.

lagrangeBasis

The Lagrange basis polynomial l_i(x) for the points xs, counted from i = 0: 1 at xs[i], 0 at the other points.

lagrangePoly

The polynomial of least degree through the points (xs[i], ys[i]), exact.