Elliptic curve certificates
A Pocklington certificate needs the factorisation of , and for most large primes that is out of reach. An elliptic curve gives a second chance, and a third, and as many as needed: any curve modulo whose number of points has a large prime factor will do. This is how primes of hundreds of digits are proven in practice.
The theorem
Let be prime to 6, a curve modulo , and a point on it. Suppose with prime and
Then is prime (Goldwasser and Kilian, 1986). The reason is short. If had a prime factor , then modulo the point would have order exactly in . But that group has at most elements, by Hasse's theorem. So the certificate is the curve, the point, and , together with a certificate for , which is about the size of : a chain that descends until Pocklington or trial division finishes it.
import { provePrime, verifyCertificate, isPrime } from "@ratmath/numtheory";
const n = 10n ** 60n + 7n;
const r = provePrime(n);
r.certificate.kind; // "elliptic"
r.certificate.discriminant; // -7
r.certificate.m; // 1000000000000000000000000000002000000000000000000000000000008n
r.certificate.q; // 26641539363749891267808119193147605196373n, a 41-digit prime
r.certificate.certificate.kind; // "pocklington": q − 1 could be factored far enough
verifyCertificate(r.certificate); // { valid: true }
provePrime(n, { elliptic: false }).reason; // "only 55 of the 200 bits of n − 1 could be factored and certified (a third are needed)"
isPrime(2n ** 255n - 19n); // true: n − 1 = 2² · 3 · 65147 · (a 71-digit prime), and that prime is certified with curves
Where the curve comes from
Goldwasser and Kilian picked random curves and counted their points with Schoof's algorithm, which is far too slow to do many times. Atkin and Morain turned it around: build a curve whose number of points is known in advance.
If for a negative discriminant , then there are curves modulo with exactly and points: those with complex multiplication by . Their j-invariants are the roots modulo of the Hilbert class polynomial . For the example above, , so works with , and happens to be times a prime. The search runs through discriminants in order, solves by Cornacchia's algorithm, and keeps a candidate when small factors can be stripped from it to leave a large enough probable prime.
Class polynomials
import { classPolynomial, classNumber } from "@ratmath/numtheory";
classPolynomial(-7); // [3375n, 1n]: x + 3375, so j = −3375 = −15³
classPolynomial(-163); // [262537412640768000n, 1n]: j = −640320³
classPolynomial(-23); // [12771880859375n, -5151296875n, 3491750n, 1n]
classNumber(-23); // 3n: the degree of H_D is the class number
, the product over the reduced forms of discriminant (see Quadratic forms) with . The j-function is evaluated from its definition in fixed-point complex arithmetic with enough digits, and the product, which must have whole coefficients, is rounded and the rounding checked. The famous near-integer is this in miniature: is a whole number while is tiny.
What has to be trusted
Very little. The class polynomial is computed numerically, square roots modulo assume is prime, and the search takes shortcuts. None of that matters for soundness: all of it only serves to find a curve and a point, and the certificate is then checked by the independent verifier, which knows nothing about complex multiplication. It checks that the point is on the curve, that the discriminant of the curve is a unit modulo , the size of , the certificate of , and the two multiplications. Its curve arithmetic uses plain affine coordinates and insists that every divisor is a unit modulo , so each step is a true group operation modulo every prime factor of at once; a shortcut through projective coordinates would not have that property. A mistake in the search can only mean that no certificate is found.
The tests attack the verifier directly: they build composite numbers , curves and points whose orders modulo both primes are known, and offer every prime factor of the order as . All are rejected.
How far it goes
Discriminants up to 5000 with class number up to 12 are tried by default (options maxDiscriminant, maxClassNumber). Primes of 60 digits take a fraction of a second, 150 digits a couple of seconds, 230 digits under ten seconds. The search can fail, and then provePrime says so and isPrime refuses, as before.
@ratmath/numtheory and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.