Proofs: Special number field sieve
These are the human proofs of Special number field sieve, at full length.
Correctness of the special number field sieve full
This proof shows: correctness, termination.
Let be an odd integer, let be monic of odd prime degree , and let be an integer with . Write , and represent each element by its coefficients on . After line L1 the implementation replaces by , which keeps ; we use the reduced from then on. We prove that the output is always or a proper factor of , that every subset that reaches line L9 gives a congruence of squares, and that the algorithm stops. We do not prove that a proper factor is found; that part is a heuristic. We also prove the two facts about special polynomials that the page uses, and at the end that the driver factorize returns the prime factorization.
Lemma 1 (the special polynomial). Let , , and be integers, , , and . Then and . So for every divisor of .
Proof. By the definition of the ceiling, , so and . Then . If , then .
Lemma 2 (the homomorphism). There is a ring homomorphism with , and for every of degree below .
Proof. Evaluation at followed by reduction modulo is a ring homomorphism . It maps to , so it maps the ideal to , and it factors through . The value on the class of is .
Only is used; is not needed, and neither is the irreducibility of . This is the one place where the special sieve differs from the general one, whose polynomial satisfies .
Lemma 3 (integer roots and algebraic factors). integer_roots(f) returns exactly the integer roots of when . For each integer root , divides , so a value returned by line L1 is a proper factor of . If with an odd prime and , then is reducible over if and only if it has an integer root.
Proof. If and , then , so , and since . Every divisor of is or for some with , and the function tests and for each of them by exact evaluation. So it returns every integer root and nothing else. For an integer root , with monic, by division by the monic ; so and . Any gcd with divides , and line L1 returns it only if it is strictly between and .
For the last claim, an integer root gives the factor , and , so is reducible. Conversely, let with be reducible over , and let be a complex root, so . Let be the minimal polynomial of over , of degree with . The roots of are with , and divides , so the roots of are of them. Their product is for some , and it is times the constant term of , so is rational, and since . As , . Since is prime and , there are integers with . Then is rational and . So is the -th power of a rational number, and since is an integer, of an integer (a rational root of a monic integer polynomial is an integer, by the argument of the first paragraph). Then .
So for the special polynomials of the driver, the check of line L1 removes every reducible case; the example with , and gives .
Lemma 4 (exact products). The functions mulmod with no modulus and product_in_order compute products in exactly.
Proof. mulmod forms the product of the two polynomials in , of degree at most . For down to it subtracts , which does not change the class modulo . Since is monic, this sets the coefficient of to and changes only lower coefficients. After the loop the degree is below , so the result is the representative of . product_in_order multiplies pairs level by level; multiplication in a commutative ring is associative and commutative, so the result is the product of all the elements.
Lemma 5 (the rational square). Let be a set of relations whose vectors of line L5 add to modulo , and let be the sum over of the exponents of in . Then with , and the value of line L7 satisfies .
Proof. Each relation has , which line L4 checks by trial division. The rational prefilter of the implementation only skips points; it never adds a point that fails this check. The product over of the signs is , where is the number of negative ; bit of the vectors is that sign, so is even and the product is positive. The bits for the rational primes are the exponents modulo , so every is even. Hence . Line L7 computes times modulo .
Lemma 6 (the algebraic square). If line L8 returns , then in , where .
Proof. The implementation computes exactly by Lemma 4, and algebraic_sqrt returns a candidate only after the test mulmod(delta, delta, f) == gamma, an exact product by Lemma 4. Otherwise it returns None, and line L8 goes on to the next subset.
Lemma 7 (the congruence of squares). If a subset reaches line L9, then .
Proof. By Lemma 5, . By Lemma 2, and , since has degree . Line L8 sets . By Lemma 6 and Lemma 2, in . So .
Lemma 8 (the output). snfs returns or an integer with and , or raises ValueError when .
Proof. Line L1 raises the error exactly when . The returns with a value other than are these. Line L1 returns only if it lies strictly between and . The trial division returns a prime with only if , and otherwise. The test of and line L9 return a gcd only if it lies strictly between and . A gcd with divides . Every other exit returns .
When comes from line L9, Lemma 7 explains why it is a factor: , and is proper exactly when modulo some but not all prime power factors of .
Lemma 9 (inert primes and the square root modulo ). Let be an odd prime with such that is_inert(f, p) is true. Then is irreducible modulo , is a field with elements, and . For , satisfies if and only if is a square in . Moreover, if and , then has a root modulo , so is not inert.
Proof. The test says that has no root modulo and . The second condition means that divides in . That polynomial is the product of all monic irreducible polynomials over of degree dividing , each once. So every irreducible factor of has degree or , since is prime. There is no root, so no factor of degree , and is irreducible of degree . Hence is a field with elements. Since and is odd, , so is an integer.
is cyclic of order , so is a square if and only if . Now . The value is or , and its cube is the same value. So exactly when is a square.
For the last claim, if then has the root . Otherwise , and since is prime, . Then is injective on the cyclic group of order , hence onto, and on it is . So is a -th power modulo , and is a root.
Lemma 9 explains why line L8 finds the square root when it exists, and why inert_prime only succeeds at primes for the special polynomials. Correctness does not depend on it, since Lemma 6 checks the result.
Lemma 10 (Newton's step). Let be an odd modulus, and let in satisfy . Then satisfies .
Proof. Write with . Then , where is invertible since is odd, and
Both and are modulo .
Lemma 11 (the vector of a relation is defined). For a relation and a prime that divides , , and the pair is in the algebraic factor base.
Proof. Modulo , , since . If and , then , so , against . So , and with , , so and is one of the pairs of line L2.
Lemma 12 (termination). snfs stops on every input.
Proof. integer_roots loops up to . The trial division and the search for an inert prime run over finite ranges (at most candidates for the inert prime), and if none is found the function returns . If an inert prime is found, then is irreducible modulo by Lemma 9, so it is irreducible over (a factorization over gives one over with monic factors, by Gauss's lemma, and it reduces to a factorization modulo ). Then the loop of line L2 for the characters stops: the discriminant of is not , since an irreducible polynomial over has distinct roots, and by Schur's theorem infinitely many primes divide some value with ; for such , is a simple root, so . So enough characters exist, and the search reaches them. The sieve runs over at most lines of points. Trial division of a nonzero integer by finitely many primes stops. The elimination is a loop over the rows, and each inner loop clears the top bit of or stops, so it runs at most as many times as has binary digits. The dependency loop is finite. In algebraic_sqrt, the modulus is squared at each step and the loop stops when it passes a fixed bound.
Theorem. snfs stops and returns either or a proper factor of . When it returns a proper factor from line L9, it has found and with .
Proof. Lemmas 12, 8 and 7.
The driver. factorize(n) returns the prime factors of with multiplicity, in order, provided that is_probable_prime is correct on the numbers it sees. That holds for all numbers below , where the strong test to the prime bases up to is a proof of primality.
Proof. special_form returns with or nothing, and the polynomials of degrees and come from Lemma 1, so for each of them modulo every divisor of .
The trial division divides out the primes below in increasing order. If it stops because for the remaining , then has no prime factor below , so is or a prime. Otherwise has no prime factor below . The invariant of the stack is this: the product of the output and of the stack equals the input, every output entry is prime, and every stack entry divides the original and has no prime factor below . It holds at the start. A popped that is is dropped. A popped with is prime, because a composite with no prime factor below is at least . A popped that passes is_probable_prime is prime by the assumption. Otherwise is composite and odd, and _split(m) returns a proper factor :
- A perfect power with gives and .
_splitkeeps a special polynomial only if , which it tests, sosnfsnever raises. A returned strictly between and is a proper factor.- The base- polynomial of
select_polynomialsatisfies , so as well. The choice and order of the polynomials, byvalue_size, only affect the speed. Every value returned fromsnfsis accepted only if it lies strictly between and , and it divides by the Theorem. - The last resort finds the least odd with , which exists and is below because is odd and composite with no prime factor below .
Each of these loops is finite: at most polynomials, bounds each, and snfs stops by Lemma 12. Then and both divide , so they divide and have no prime factor below , and their product is . The invariant holds after each step. Each split replaces by two numbers greater than whose product is , so the total number of prime factors counted with multiplicity bounds the number of splits, and the loop stops. When the stack is empty, the output is a list of primes whose product is the input, and sorting puts it in order.