Quadratic integer rings
Adjoin a square root to the whole numbers and arithmetic changes. Sometimes primes still factor uniquely; sometimes 6 factors in two different ways. Ideals repair the damage, and the class group measures it.
The rings
Let be a square-free whole number other than 1. The quadratic integers for are the numbers with whole numbers, where
(The halves are allowed in the second case because then satisfies , with whole-number coefficients.) They form a ring, the ring of integers of the field . For it is the Gaussian integers , and for the Eisenstein integers.
The conjugate of is , and the norm is the product of the two, a whole number:
import { quadraticRing, gaussianIntegers } from "@ratmath/structures";
const K = quadraticRing(-5);
String(K); // "Z[√−5]"
const a = K.sqrt(1, 1); // 1 + √−5
String(a.mul(a)); // "−4 + 2√−5"
a.norm(); // 6n
String(a.conj()); // "1 − √−5"
String(quadraticRing(5).omega); // "(1 + √5)/2": the golden ratio
Units
An element is a unit exactly when its norm is . For there are only finitely many: , except the four powers of when and the six sixth roots of unity when . For there are infinitely many, all of the form for one fundamental unit . Finding it is solving Pell's equation (or ), and the continued fraction of does it. The fundamental unit can be surprisingly large.
String(quadraticRing(2).fundamentalUnit); // "1 + √2", norm −1
String(quadraticRing(7).fundamentalUnit); // "8 + 3√7": 8² − 7·3² = 1
String(quadraticRing(61).fundamentalUnit); // "(39 + 5√61)/2"
String(quadraticRing(94).fundamentalUnit); // "2143295 + 221064√94"
gaussianIntegers().units.list.map(String); // ["1", "i", "−1", "−i"]
Division with remainder
In the Gaussian integers one can divide with a remainder of smaller norm: compute the exact quotient in and round both coordinates. So Euclid's algorithm works, greatest common divisors exist, and factorisation into primes is unique, exactly as for whole numbers. The same holds in a handful of other rings (for example ), called norm-Euclidean.
const G = gaussianIntegers();
const { quotient, remainder } = G.divmod(G.of(27, 23), G.of(8, 1));
[String(quotient), String(remainder)]; // ["4 + 2i", "−3 + 3i"]: norm 18 is less than 65
String(G.gcd(G.of(11, 3), G.of(1, 8)).gcd); // "2 + i"
const f = G.factor(2210);
f.factors.map(({ prime, exponent }) => `${prime}${exponent > 1 ? "^" + exponent : ""}`);
// ["1 + i^2", "2 − i", "2 + i", "3 + 2i", "3 − 2i", "4 − i", "4 + i"]: 2210 = 2·5·13·17
A whole-number prime behaves in one of three ways in the ring. It can stay prime (inert), become a product of two different primes (split), or become the square of a prime, up to a unit (ramified). In : 2 ramifies, primes split (that is Fermat's theorem that such a prime is a sum of two squares), and primes are inert.
When unique factorisation fails
An element is irreducible when it is not a product of two non-units. It is prime when it cannot divide a product without dividing a factor. For whole numbers these are the same thing. In they are not:
All four factors are irreducible, since their norms are 4, 9, 6, 6 and no element has norm 2 or 3 ( never equals 2 or 3). But none is prime: 2 divides the product on the right without dividing either factor. So 6 has two genuinely different factorisations.
K.factorizations(6).map((f) => f.factors.map(String));
// [["2", "3"], ["1 + √−5", "1 − √−5"]]
K.isIrreducible(2); // true
K.isPrimeElement(2); // false
K.elementsOfNorm(2); // []
K.isUFD; // false
Ideals put it right
Kummer and Dedekind's repair: factor ideals, not elements. In these rings every nonzero ideal is a product of prime ideals in exactly one way. The two factorisations of 6 are two ways of grouping the same four prime ideals:
with and . None of is generated by a single element, which is why they were invisible among the numbers.
const p = K.ideal(2, a); // (2, 1 + √−5)
const q = K.ideal(3, a);
p.norm; // 2n: the quotient by p has 2 elements
p.isPrime(); // true
p.isPrincipal(); // false
String(p.mul(p)); // "(2)"
String(p.mul(q)); // "(1 + √−5)"
String(p.mul(q).generator()); // "1 + √−5"
K.ideal(6).factor().map(({ prime, exponent }) => `${prime}^${exponent}`);
// ["(2, 1 + √−5)^2", "(3, 2 + √−5)^1", "(3, 1 + √−5)^1"]
K.splitting(7).kind; // "split"
The class group
How badly does unique factorisation fail? Call two ideals equivalent when one is the other multiplied by a number of the field. The classes form a finite abelian group under multiplication, the class group, and its size is the class number. The principal ideals are the identity class, so
The class group is computable because every class contains an ideal of norm at most the Minkowski bound ( for an imaginary ring and for a real one, where is the discriminant). So it is enough to look at the primes above the small whole-number primes and work out which products are principal.
K.classNumber(); // 2
p.isEquivalentTo(q); // true: both are in the one non-principal class
quadraticRing(-23).classGroup().text; // "C3"
quadraticRing(-65).classGroup().text; // "C2 × C4"
quadraticRing(10).classNumber(); // 2: 6 = 2·3 = (4 + √10)(4 − √10)
[-1, -2, -3, -7, -11, -19, -43, -67, -163].map((d) => quadraticRing(d).classNumber());
// all 1, and by the Baker–Heegner–Stark theorem no other negative d has class number 1
quadraticRing(-19).isPID; // true, although
quadraticRing(-19).isNormEuclidean; // false
Class groups are found by listing ideals up to the Minkowski bound and testing which are principal, which suits discriminants up to a few thousand. Whether there are infinitely many real quadratic rings of class number 1 is an open problem.
@ratmath/structures and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.