Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Algebraeon — Exact Algebra

Algebraeon is koto-calc’s exact-algebra toolkit. It keeps mathematical values as integers, reduced fractions, algebraic roots, and symbolic structures rather than silently rounding them to floating-point approximations. That means you can factor large integers, compare algebraic numbers, invert rational matrices, and calculate in finite fields without losing information.

Start here, then go deeper: the Full Reference documents every available constructor, method, and module-level function.

Import the types you need from the built-in algebraeon module:

from algebraeon import N, Z, Q, Zn, Poly, Mat, Alg

Naming convention

Basic number domains use their ASCII mathematical symbols: N for natural numbers, Z for integers, and Q for rationals. Zn(n) denotes the residue ring ℤ/nℤ. Other structures use descriptive PascalCase names or established acronyms such as Poly, Mat, FF, and CF.

For compatibility with 0.1 scripts, NN, ZZ, and ZZn remain aliases for N, Z, and Zn; values created through an alias still have the canonical runtime type name.

The exact-algebra toolbox

Type or familyWhat it does
NArbitrary-precision natural numbers, with primes, factorization, divisors, and combinatorics.
ZArbitrary-precision signed integers and integer number theory.
QReduced rational numbers, so values such as 1/3 stay exact.
QSqrtElements of quadratic fields Q(sqrt(d)), including exact conjugates, norms, and inverses.
AlgExact real algebraic numbers represented as isolated roots of polynomials.
ComplexAlgExact complex algebraic numbers, including polynomial roots and the imaginary unit.
CFFinite and periodic continued fractions, convergents, and exact rational values.
FFPrime and extension finite fields GF(p^k) with exact field arithmetic.
Ideal / ZnIdeals of the integers and residue rings such as Z/12Z.
PolyUnivariate polynomials over Z or Q, with evaluation, gcd, derivatives, and factorization.
MultiPolySymbolic multivariate integer polynomials with evaluation and symmetric-polynomial tools.
PolyQuotExact number fields presented as quotient rings Q[x]/(f).
MatInteger and rational matrices with determinants, exact inverses, and LLL reduction.
PermPermutations with composition, inverses, signs, and cycle decomposition.
GroupFinite groups represented by multiplication tables, with standard constructors.
QuatHamilton quaternions over the rationals, with conjugate, norm, and inverse.
Stirling numbersExact first- and second-kind Stirling numbers via N and Z.

A quick tour

Each example below is ready to paste into a koto-calc script or REPL.

Fractions stay fractions

from algebraeon import Q

third = Q(1, 3)
print third + Q(1, 6) # 1/2

There is no intermediate binary floating-point value: the result is the reduced fraction 1/2.

Factor arbitrary-precision integers

from algebraeon import N

print N(12345).factor() # [(3, 1), (5, 1), (823, 1)]

Work with an exact square root

from algebraeon import Alg, Q

sqrt2 = Alg([-2, 0, 1])[1]
print sqrt2.min_poly() # -2 + x^2
print sqrt2 > Q(7, 5) # true

sqrt2 is stored as an isolated root of x^2 - 2. Its usual display, 1.414213562, is only a readable approximation; the minimal polynomial and comparisons remain exact.

Factor polynomials

Coefficients are listed from the constant term upwards, so the polynomial below is 6 - 5x + x^2.

from algebraeon import Poly

f = Poly([6, -5, 1])
print f.factor() # [(-2 + x, 1), (-3 + x, 1)]

Invert a matrix without rounding

from algebraeon import Mat

m = Mat([[1, 2], [3, 4]])
print m.inverse()     # [[-2, 1], [3/2, -1/2]]
print m.inverse() * m # [[1, 0], [0, 1]]

Explore a finite group

from algebraeon import Group

c4 = Group.cyclic(4)
print c4          # C4 (size 4)
print c4.order(1) # 4

Group also constructs dihedral, symmetric, alternating, Klein four, and quaternion groups, all backed by finite multiplication tables.

Calculate in a finite field

from algebraeon import FF

gf7 = FF(7)
x = gf7.of(3)
print x.inverse()     # 5
print x * x.inverse() # 1

Prime fields are only the beginning: FF(p, k) constructs extension fields using Algebraeon’s Conway-polynomial database.

Where to go next

The Algebraeon Full Reference contains detailed type signatures and validated examples for the complete API. You can also read about the underlying Rust library on the Algebraeon crate page.