Reference

Everything in the library

Every export of @ratmath/algebraic. Polynomials are coefficient arrays, constant term first; rationals inside the library are [n, d] BigInt pairs, and results meant for you are Core Rationals.

FunctionWhat it does
Making numbers
fromRational(x)A rational (number, BigInt, string like "3/4" or "0.1", Core Rational, [n, d]) as an AlgebraicReal.
roots(p, { complex })All roots of an integer or rational polynomial as a list of { value, multiplicity }: real ones ascending as AlgebraicReal, then (with complex: true) the others as ComplexAlgebraic. Each on its minimal polynomial.
realRoots(p)Shorthand for roots(p).
complex(x, y)x + iy from real parts (rationals or AlgebraicReals).
I()The imaginary unit, root of x² + 1 with positive imaginary part.
fromQuadratic(p, q, d, r)(p + q√d)/r as an exact AlgebraicReal.
new AlgebraicReal(poly, lo, hi)The unique root of a square-free integer polynomial in the open interval (lo, hi) (pairs [n, d]).
new ComplexAlgebraic(poly, re, im)The unique root in a certified box re × im.
Arithmetic
add(a, b), sub, mul, divExact arithmetic by resultants; results are put on their minimal polynomials.
neg(a), inv(a)Negation and reciprocal (reversed coefficients).
pow(a, k)Integer power, k may be negative.
nthRoot(a, n)Positive real root of a positive real; real root of a negative real for odd n; principal (largest real part) root otherwise.
sqrt(a)Principal square root: √a, i√(−a), or the root with positive real part.
abs(a), norm(a)|a| and |a|² as exact real algebraic numbers.
re(a), im(a), conjugate(a)Real and imaginary parts and conjugate, exactly.
sign(a), compare(a, b)−1, 0 or 1 for reals, decided exactly.
equals(a, b), isZero(a)Exact equality, real or complex.
isReal(a), isComplex(a)Which kind of number.
minimalPolynomial(a), simplify(a)The minimal polynomial (primitive integer, constant first); the same number re-expressed on it.
rationalOf(a)[n, d] when a is rational, else null.
MAX_DEGREE64: the largest degree a result's polynomial may have.
Reading a number
format(a, { digits })Exact readable form when cheap: fraction, (p + q√d)/r, nested radical, pure roots such as ∛2 or 1 + 2⁵√3, a + bi; else certified digits ending in …
a.toString(digits)AlgebraicReal: digits with the last one certain to one unit (exact for rationals). ComplexAlgebraic: exact a + bi for degree 2, else digits for each part.
a.refine(bits)Shrink the isolating interval or box below 2⁻ᵇⁱᵗˢ.
a.interval(bits)AlgebraicReal: [lo, hi] as Core Rationals.
a.box(bits)ComplexAlgebraic: { re: [lo, hi], im: [lo, hi] } as Core Rationals.
a.toRational(), a.isRationalThe exact value when rational (decided exactly), else null.
a.toNumber(), a.toNumbers()Nearest double; { re, im } for complex.
a.poly, a.lo, a.hi, a.re, a.imThe defining polynomial and the current enclosure.
Angles and roots of unity
cosPi(r), sinPi(r), tanPi(r)cos(πr), sin(πr), tan(πr) for rational r, exactly (denominators up to 1000).
rootOfUnity(n, k = 1)e^(2πik/n), exactly.
rootsOfUnity(n)All n of them, k = 0 … n − 1.
cyclotomic(n)The cyclotomic polynomial Φₙ.
cosMinimal(n)The minimal polynomial of cos(2π/n).
chebyshevT(n)The Chebyshev polynomial Tₙ.
Recognition
recognize(x, { maxDegree, margin })Guess an algebraic number from a decimal string or interval; { value, poly, degree, height, digitsUsed, digitsNeeded } or null.
lll(rows, delta)LLL-reduce a basis of integer vectors (exact rational Gram–Schmidt).
Factoring
factor(p){ content, factors: [{ factor, multiplicity }] } over the integers, each factor primitive and irreducible (Zassenhaus).
isIrreducible(p)True when p is irreducible over Q.
factorModP(p, prime)Irreducible factors of a square-free polynomial over F_p (Cantor–Zassenhaus).
squareFree(p)Yun's square-free factorisation [{ factor, multiplicity }].
Polynomial toolkit
resultant(p, q)Res(p, q) as a Core Rational.
discriminant(p)The discriminant as a Core Rational.
countRoots(p, a, b)Distinct real roots in (a, b] (Sturm); a, b default to ±∞.
interpolate(points)The least-degree polynomial through [[x, y], …].
partialFractions(num, den){ polynomial, terms: [{ factor, power, numerator }] }.
polys.add, sub, mul, divmodArithmetic over Q; divmod returns { quotient, remainder }.
polys.gcd, gcdExtMonic gcd; { gcd, s, t } with s·p + t·q = gcd.
polys.evaluate, compose, derivativep(x) at a rational, p(q(x)), p′.
polys.fromRoots, toInteger, formatMonic polynomial with given rational roots; primitive integer form; human-readable text.
isolate(p), countRealRoots(p)Isolating intervals and the number of real roots of a square-free integer polynomial.
simplestBetween(a, b)The fraction with the smallest denominator in [a, b] (pairs).
Galois groups
galoisGroup(p)Degree ≤ 7: { degree, name, order, label, solvable, discriminant, discriminantIsSquare }; reducible input gives { reducible, factors }.
galoisAction(p)Irreducible, degree ≤ 7. The group as permutations of the numbered roots: roots, group (a PermGroup), name, label, order, solvable, conjugation, orbitsOnPairs, orbitsOnTriples.
a.permutations()Every element in cycle notation, counted from 1.
a.fixedField(H)H is a PermGroup or cycle strings. { degree, polynomial, generator, substitution?, normal }: the minimal polynomial of a sum of products of roots that generates the field H fixes.
a.correspondence({ maxDegree = 60 })One row per subgroup class: { subgroup, order, index, conjugates, normal, field, above }.
a.frobenius(count = 200){ primes, patterns: [{ type, elements, expected, primes, observed, first }] }: factor degrees modulo primes against the cycle types of the group.
a.derivedSeries()Orders of G ⊇ G′ ⊇ G″ ⊇ …; reaches 1 exactly when the roots are expressible by radicals.
new PermGroup(generators, n)Also PermGroup.symmetric(n), .alternating(n), .from(["(1 2 3)"], n). elements, order, has, contains, orbits, orbitsOnSets(k), cycleTypes, subgroup, conjugate, isNormal, cosets, derivedSubgroup, derivedSeries, isSolvable, subgroups, subgroupClasses.
cycleString(p), fromCycles(text, n), cycleType(p)Cycle notation for a permutation given as the array of images of 0 … n−1.
Continued fractions
Moved to @ratmath/numtheory, with Pell equations and fundamental units.
Number fields
new NumberField(minpoly, { name, root })Q(α) for an irreducible polynomial; root picks the embedding (index, or "positive").
NumberField.quadratic(d), NumberField.gaussian()Q(√d) and Q(i).
K.of(x), K.gen, K.zero, K.oneElements from a rational or a coefficient list in α.
g.add, sub, mul, div, inv, pow, negField arithmetic (polynomials mod m, inverses by extended Euclid).
g.norm(), g.trace()Field norm and trace as Core Rationals.
g.equals, isZero, coefficients, toRationalComparison and coefficient access.
K.factor(p){ unit, factors: [{ factor, multiplicity }] }: a polynomial with coefficients in K factored into irreducibles over K (Trager's method). Also factorOver(K, p).
K.roots(p)The roots of p that lie in K, with multiplicities.
K.extend(g, { name }){ field, embed, root }: K(β) for a root β of g, irreducible over K, as a new NumberField; embed carries elements of K over.
NumberField.containing([a, b, …]){ field, elements }: one field holding several exact numbers, each as an element. Also fieldContaining.
NumberField.splitting(p){ field, roots, degree }: the splitting field of a rational polynomial with every root as an element. Also splittingField.
g.toAlgebraic()The exact AlgebraicReal or ComplexAlgebraic through the field's embedding.
K.add(a, b), K.mul, …, K.signField-object interface for field-generic algorithms.
Finite fields
primeField(p)F_p: { zero, one, add, sub, mul, div, neg, inv, pow, sign, equals, from, order, primitive, log, sqrt, elements, format, size }.
galoisField(p, k, modulus)GF(pᵏ), elements as k coefficients; also gen, modulus, order, primitive, log, elements, format.
isProbablePrime(n)Baillie–PSW: trial division, a strong test to base 2 and a strong Lucas test. Proven below 2⁶⁴; no composite that passes is known. Takes a BigInt or an integer Number.
Number theory
factorInteger(n)[{ prime, exponent }] by trial division and Pollard rho.
modPow(a, e, m), modInverse(a, m)Powers and inverses mod m.
jacobi(a, n)Jacobi (Legendre) symbol.
sqrtMod(a, p)Square root mod an odd prime (Tonelli–Shanks), or null.
primitiveRoot(p), multiplicativeOrder(a, n)Least primitive root; order of a unit.
discreteLogMod(g, h, p)Least x with gˣ ≡ h (baby-step giant-step), or null.
totient(n)Euler φ.
nt.egcd, nt.discreteLog, nt.orderInExtended gcd; generic BSGS and order finding for any group.
Lower level
poly, qpoly, intervalNamespaces: integer polynomials and Sturm sequences, rational polynomials, interval arithmetic and the Krawczyk operator (also subpath exports @ratmath/algebraic/poly, /qpoly, /interval, /complex, /q).
certifyComplexRoots(p, count)Certified boxes for the non-real roots of a square-free integer polynomial.

Expression language used on these pages

The demos and Explore read expressions: numbers (exact, so 0.1 is 1/10), i, the variable x for polynomials, + − * / ^ (fractional powers are principal roots), implicit multiplication (2x, 3i), √, and name = expr to keep a value.

Try itEdit the code and run it with @ratmath/algebraic and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs