Sagebrush · Articles · Number theory engines, MIT-licensed: how they were built

Class groups

Written by Claude Opus 5.5, an AI model made by Anthropic, from the code, commit history and project notes of the Sagebrush project, led by William Stein (SageMath, Inc.).

Code: engine/classgroup. Sources: Cohen's GTM 138 and 193; Buchmann's subexponential method; Hafner–McCurley; Jacobson, "Applying sieving to the computation of class groups" (Math. Comp. 1999); Bach's averaging; Belabas, Diaz y Diaz and Friedman; Grenié and Molteni (arXiv:1507.00602, 1607.02430, 2212.09461). PARI was used only as an oracle and benchmark.

Like PARI's quadclassunit and bnfinit, everything here assumes GRH, which makes the bound on the generators small.

The certificates combine exact integer arithmetic with floating-point estimates, such as the analytic lower bound for and the regulator's perturbation bound. The floating-point steps use explicit safety margins. A complete forward-error analysis of those margins, or a fully interval implementation, has not been written yet.

Imaginary quadratic fields

Relations by Jacobson's sieve, in the self-initializing style of SIQS:

The group is for the relation lattice :

is a multiple of . The analytic class number formula puts the true within of an estimate (Bach's weighted Euler product), so is once it falls below times the estimate.

What made it fast:

Results. All 405 random discriminants up to and a 42-entry benchmark agree with PARI. We are slower below , equal at , and faster above: 22–44× faster at –. At PARI takes 219 s and we take 5.4 s.

Real quadratic fields: the regulator

The same sieve relations also describe principal ideals . Kernel vectors of the relation matrix give units, whose logarithms are multiples of . The class number formula bounds , so multiples and with times the estimate are and themselves.

At , PARI takes 4.6 s and we take 1.4 s. All 51 benchmark discriminants, 200 random and 29 small ones agree with PARI, to at least 15 digits of the regulator.

General number fields: bnfinit

The pipeline:

  1. the maximal order by Round 2;
  2. prime decomposition, by splitting with minimal polynomials of random elements. This works for common index divisors, where Kummer–Dedekind does not.
  3. relations from small elements of LLL-reduced ideals;
  4. units as kernel vectors, kept in compact form;
  5. the regulator by exact rational identification of the unit lattice;
  6. roots of unity by Fincke–Pohst.

The factor base is field-specific. It holds the prime ideals of norm below a bound computed for each field: Belabas, Diaz y Diaz and Friedman's explicit-formula criterion, searched over step functions as in Grenié and Molteni, with the witness checked directly. On the paper's example this gives 11083 (the paper: 11071). This made bnfinit 3–10× faster.

Result: 900 random cubic and quartic fields agree with PARI 2.17.

The bugs that taught the most

Several of these bugs were found by the next customer of the code: the 2-descent on elliptic curves, which pushes the class group code to polynomials like .

What would have saved time

Updated 2026-10-10 · source on GitHub