Number theory with proofs attached
From a first course to algebraic number theory: primes that come with a certificate, congruences and reciprocity, Diophantine equations, p-adic numbers, elliptic curves, and the arithmetic of number fields.
What is here
Every phase of the plan is built: primes with certificates, factoring, arithmetic functions, congruences, reciprocity and sums of squares; linear and Pell equations, continued fractions and binary quadratic forms; p-adic numbers; elliptic curves over the rationals and over finite fields, with the factoring method and the primality certificates built on them; rings of integers of number fields, prime ideals, class groups and unit groups; and the analytic side, with exact prime counts, Dirichlet characters, and values of zeta and L functions.
A first program
import { isPrime, provePrime, verifyCertificate, factor, formatFactors, jacobiSteps, twoSquaresAll, pellSolutions, classGroup, padic, ellipticCurve } from "@ratmath/numtheory";
isPrime(2n ** 61n - 1n); // true, proven: Baillie–PSW has no exceptions below 2^64
const r = provePrime(2n ** 127n - 1n); // a Pocklington certificate, a tree of smaller primes
verifyCertificate(r.certificate); // { valid: true }, by a checker that shares no code with the search
formatFactors(factor(2n ** 64n + 1n)); // "274177 · 67280421310721"
jacobiSteps(1001, 9907).value; // -1, with every reciprocity step written out
twoSquaresAll(325); // [[18n, 1n], [17n, 6n], [15n, 10n]]
pellSolutions(2, 7).solutions(4); // [[3n, 1n], [5n, 3n], [13n, 9n], [27n, 19n]]
classGroup(-3299).structure; // [3n, 9n]: the class group is C3 × C9
padic(-1, 5n).sqrt().toString(12); // "…223032431212": i in the 5-adic integers
formatFactors(factor(2n ** 128n + 1n)); // "59649589127497217 · 5704689200685129054721", by the elliptic curve method
isPrime(10n ** 60n + 7n); // true: an elliptic curve certificate, checked by the same verifier
ellipticCurve([-43, 166]).torsion().structure; // [7]: y² = x³ − 43x + 166 has a rational point of order 7
ringOfIntegers([-8n, -2n, -1n, 1n]).describePrime(2).primes.length; // 3: in Dedekind's cubic, 2 splits completely
String(idealClassGroup([-65n, 0n, 0n, 1n])); // "class group of Q(α), α a root of x³ − 65: C3 × C6, h = 18", proven
unitGroup([-2n, 0n, 0n, 1n]).fundamentalUnits; // [1 + α + α²]: the fundamental unit of Q(∛2), proven fundamental
primePi(10n ** 12n); // 37607912018n, by Meissel's formula
zetaValue(3).compactedDecimalInterval(); // "1.202056903159594285[38:41]": an interval that contains ζ(3)
lValueExact(kroneckerCharacter(-23), 0); // 3: the class number of Q(√−23), as an L-value
Four ideas
A proof, or a refusal. "Prime" means proven: below 2⁶⁴ by a test known to have no exceptions there, above it by a certificate (from the factors of n − 1, or from an elliptic curve) that an independent verifier checks. When no certificate can be found, isPrime refuses and says why, rather than guessing. A composite comes with a factor or a witness. See Primes and certificates.
Every "no" has a reason. A congruence with no solution names the gcd that blocks it, a number that is not a sum of two squares names the prime, two forms that are not equivalent name their different reduced forms, and an equivalence comes with the matrix that proves it.
Certified without hypotheses. Class groups and unit groups are usually computed fast under the generalised Riemann hypothesis and checked separately, if at all. Here the check is part of the answer: Minkowski's bound for the generators, and a saturation argument with a proven lower bound on regulators for the relations. Values of zeta and L functions come as intervals with rational endpoints. See Class groups and Zeta and L values.
Exact at any size, lazily where it must be. Everything is BigInt and Core Rational arithmetic. p-adic numbers have infinitely many digits, so they are rules that compute as many as asked, exactly; what digits alone cannot decide, such as whether a number is exactly zero, is reported as unknown. See p-adic numbers.
The plan, completed
From the library roadmap.
| Phase | Contents | |
|---|---|---|
| 1 | Primes with certificates, arithmetic functions, congruences, reciprocity, sums of squares, re-exports | built |
| 2 | Diophantine equations and binary quadratic forms | built |
| 3 | p-adic numbers | built |
| 4 | Elliptic curves; ECM and curve-based certificates | built |
| 5 | Integral bases, discriminants, prime ideal factorisation | built |
| 6 | Class groups and unit groups | built |
| 7 | π(x), characters, ζ and L values | built |
It builds on Core and algebraic (the modular kernel and the algebraic numbers that continued fractions expand); continued fractions, Pell's equation and the Chinese remainder theorem moved here from algebraic.
@ratmath/numtheory and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.