Class groups
The class group measures how far a ring of integers is from unique factorisation. Its elements are the ideals up to multiplication by a number; it is finite; it is trivial exactly when every ideal is principal. Here it is computed with a proof, not a heuristic.
The group
Two ideals are in the same class when one is the other times a field element. Classes multiply, the principal ideals are the identity class, and the resulting group is finite. Its order is the class number .
import { NumberField, idealClassGroup, ringOfIntegers } from "@ratmath/numtheory";
const K = NumberField.quadratic(-5);
const cl = idealClassGroup(K);
cl.h; // 2n
cl.structure; // [2n]: a cyclic group of order 2
cl.generators; // [(2, 1 + √(-5))], as an Ideal
cl.proven; // true
const O = ringOfIntegers(K);
const [P2] = O.primesAbove(2);
const [P3] = O.primesAbove(3);
cl.classOf(P2); // [1n]: the non-trivial class
cl.isPrincipal(P2); // { principal: false, generator: null }
cl.isPrincipal(P2.toIdeal().mul(P3));
// { principal: true, generator: 1 + √(-5) }
structure lists invariant factors : the group is , with one generator ideal for each. classOf gives the exponents of an ideal's class on those generators.
const C = idealClassGroup([-65n, 0n, 0n, 1n]); // Q(∛65)
String(C); // "class group of Q(α), α a root of x³ − 65: C3 × C6, h = 18"
C.structure; // [3n, 6n]
const [T] = C.order.primesAbove(2);
C.classOf(T); // [1n, 5n]
C.orderOf(T); // 6n
String(C.isPrincipal(T.toIdeal().pow(6)).generator); // "49 + 24α − 9α²"
Minkowski's bound
Geometry of numbers shows that every class contains an ideal of norm at most
So the prime ideals of norm up to generate the class group, and there are finitely many. For the bound is 2.8: the single prime above 2 generates everything, and it is not principal because has no solution. That is the whole computation by hand.
minkowskiBound(NumberField.quadratic(-5)); // 2n
minkowskiBound(NumberField.quadratic(-163)); // 8n: and 2, 3, 5, 7 are all inert, so h = 1
minkowskiBound([-65n, 0n, 0n, 1n]); // 95n
C.factorBase.length; // 44 prime ideals above the primes up to 95
Relations
Call the generating primes . An element whose norm has only small prime factors gives a relation: means in the class group. The relations form a lattice , and
where is the lattice of all relations. The library searches short vectors of and of the primes themselves for elements with smooth norm, reduces the lattice they span, and reads off the Smith normal form. If the lattice found is , its index is a multiple of : relations can be missing, never wrong.
Certifying the answer
Systems such as PARI and Sage compute class groups quickly by assuming the generalised Riemann hypothesis, and offer a separate certification step. Here the certification is part of the answer, and no hypothesis is used.
The kernel of the relations gives units, with regulator (see Units). Let be the group generated by all relation elements and the roots of unity. Inside the group of all numbers supported on , the index of is
A prime divides this index exactly when some element of is an -th power in without being an -th power in . That can be refuted: reduce modulo a prime ideal of degree 1 with ; raising to the power gives a homomorphism , which kills every true -th power. Once as many independent such maps are found as the dimension of , no hidden -th power exists.
- For each prime dividing , this test is run on .
- Any other prime can only divide . Friedman proved that the regulator of every number field is at least , so , and for the primes up to that bound the same test is run on the units.
When every test passes, and . A test that fails says more than no: it names a product of the generators that every map takes for an -th power. The library takes the -th root of that product in the field (numerically at each embedding, then checked exactly), adds the root to the relation elements, and runs the computation again. The certificate counts these under rootsTaken.
C.certificate;
// { method: "saturation", minkowskiBound: 95n, relations: 68, regulatorLowerBound: 0.2052,
// unitIndexBound: 18, classNumberPrimes: [2, 3], primesChecked: 7, rootsTaken: 0 }
// the first relations found for Q(⁴√30) give 8; the test at 2 fails, and a square root brings it to 4
idealClassGroup([-30n, 0n, 0n, 0n, 1n], { certify: false }).h; // 8n, marked proven: false
idealClassGroup([-30n, 0n, 0n, 0n, 1n]).h; // 4n, proven
Options: certify: false skips the proof (the result then has proven: false, and the true class number divides the one shown); maxBound (default 2000) refuses fields whose Minkowski bound is larger, since the number of primes grows with it; maxIndexPrime caps the primes tested. A cubic field with Minkowski bound near 100 takes about half a second; bound 1500 takes ten.
Quadratic fields and forms
For a quadratic field the classes of ideals correspond to classes of binary quadratic forms of the same discriminant, and there the class number is found by listing reduced forms, with no search. Quadratic fields are certified that way: the relation computation has to agree with the count of forms. For a real quadratic field, forms give the narrow class number, which is twice the class number when the fundamental unit has norm .
const R = idealClassGroup(NumberField.quadratic(79));
R.h; // 3n
R.certificate.narrowClassNumber; // 6n: the fundamental unit 80 + 9√79 has norm +1
const F = NumberField.quadratic(-23);
const I = formToIdeal([2, 1, 3], F); // the form 2x² + xy + 3y² as an ideal
String(I); // "(2, 3/2 + (1/2)√(-23))"
idealClassGroup(F).orderOf(I); // 3n
For imaginary quadratic fields the class number is also a special value of an L-function, when : see Zeta and L values.
@ratmath/numtheory and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.