Binary quadratic forms
ax² + bxy + cy², with whole coefficients. Gauss sorted them into classes under changes of variable, found that the classes of one discriminant form a group, and so opened the road to class groups of number fields.
Forms, discriminants and equivalence
The form has discriminant . A matrix of determinant 1 changes variables, , keeping and the set of values. Forms related that way are properly equivalent, and represent the same numbers.
import { form, equivalent, reducedForms, classNumber, classGroup, compose, represent, representations } from "@ratmath/numtheory";
const f = form(10, 34, 29);
f.discriminant; // -4n
const { form: g, matrix } = f.reduce();
String(g); // "x² + y²"
matrix; // [[-2n, 5n], [1n, -3n]]: f ∘ matrix = g, checked exactly
equivalent([1, 0, 5], [2, 2, 3]);
// { equivalent: false, reason: "they reduce to different forms, x² + 5y² and 2x² + 2xy + 3y²" }
Reduction
A positive definite form (, ) is reduced when , with if either inequality is an equality. Every class contains exactly one reduced form (Lagrange, Gauss), found by alternately swapping and shifting by multiples of . Since forces , there are finitely many, and counting them gives the class number .
reducedForms(-23).map(String); // ["x² + xy + 6y²", "2x² − xy + 3y²", "2x² + xy + 3y²"]
classNumber(-23); // 3n
classNumber(-163); // 1n: the largest of Heegner's nine
For the form is indefinite and a class contains several reduced forms, arranged in a cycle by Gauss's operator ; the class is identified by its cycle. Then is the narrow class number, which counts and separately when no unit of norm links them.
form(1, 0, -14).cycle().map(String); // ["x² + 6xy − 5y²", "−5x² + 4xy + 2y²", "2x² + 4xy − 5y²", "−5x² + 6xy + y²"]
classNumber(12); // 2n: x² − 3y² and its negative are different classes
The class group
Gauss defined a composition of primitive forms of the same discriminant, under which the classes form a finite abelian group: the identity is the class of the principal form , the inverse of is . Composition here follows Shanks's formulas (Cohen's Algorithm 5.4.7) and reduces the result. classGroup also finds the structure as a product of cyclic groups.
const G = classGroup(-84);
G.h; // 4n
G.forms.map(String); // ["x² + 21y²", "2x² + 2xy + 11y²", "3x² + 7y²", "5x² + 4xy + 5y²"]
G.structure; // [2n, 2n]: every class has order 2, Euler's idoneal numbers
classGroup(-56).structure; // [4n]: cyclic
classGroup(-3299).structure; // [3n, 9n]
String(compose([2, 1, 3], [2, 1, 3])); // "2x² − xy + 3y²": in h(−23) = 3, the square is the inverse
The class numbers are checked in the tests against Dirichlet's class number formula for every fundamental down to −1500.
Representations
A positive definite form takes each value finitely often: from , . For any , properly represents exactly when is equivalent to some with , and the first column of the equivalence matrix is then the representation.
representations([1, 1, 6], 8); // [[-2n, 1n], [-1n, -1n], [1n, 1n], [2n, -1n]]
represent([1, 0, -2], 7); // [-3n, 1n]: 9 − 2 = 7
represent([1, 0, 5], 9); // [2n, -1n]: 4 + 5 = 9
@ratmath/numtheory and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.