Symmetric polynomials
A polynomial that does not change when its variables are shuffled can always be rewritten using just a few building blocks. That is why you can know the sum of the squares of the roots of an equation without solving it.
The building blocks
A polynomial in is symmetric when every permutation of the variables leaves it unchanged. The elementary symmetric polynomials are
so is the sum of all products of different variables. They are exactly the coefficients that appear when a product of linear factors is multiplied out (Vieta's formulas):
Two other families are the power sums and the complete homogeneous polynomials , the sum of all monomials of degree .
The fundamental theorem
Every symmetric polynomial is a polynomial in , in exactly one way. The proof is an algorithm, and it is the one the library runs.
Order the monomials lexicographically. Because is symmetric, its leading monomial has (otherwise a permutation of it would be larger). The product
has the same leading monomial. Subtract the right multiple of it from : what is left is symmetric with a smaller leading monomial. Repeat until nothing is left.
For : the leading monomial is , matched by . The difference is . So .
import { ring, elementary, powerSum, completeHomogeneous, isSymmetric, toElementary } from "@ratmath/structures";
const R = ring("x, y, z");
String(elementary(R, 2)); // "xy + xz + yz"
String(powerSum(R, 3)); // "x³ + y³ + z³"
isSymmetric(R.poly("x^2 y + y^2 z + z^2 x")); // false: only cyclic shifts fix it
const { polynomial, ring: E } = toElementary(powerSum(R, 3));
String(polynomial); // "e1³ − 3e1·e2 + 3e3"
E.vars; // ["e1", "e2", "e3"]
// substituting the elementary polynomials back recovers the original
polynomial.compose([elementary(R, 1), elementary(R, 2), elementary(R, 3)]).equals(powerSum(R, 3)); // true
Roots without solving
If are the roots of , Vieta's formulas give . Any symmetric expression in the roots is then a polynomial in the coefficients. The roots of have , , , so the sum of their cubes is . (The roots are 1, −2 and 3, and indeed .)
The formulas for power sums are Newton's identities, and the discriminant is the symmetric polynomial written in the coefficients. The same theorem is the starting point of Galois theory: the symmetric functions of the roots are the ones that lie in the base field.
@ratmath/structures and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.