Proofs: Distinct-degree factorization
These are the human proofs of Distinct-degree factorization, at full length.
DISTINCT-DEGREE returns the products of the irreducible factors of each degree full
This proof shows: correctness.
Let be a prime, , and monic and square-free of degree . Write with distinct monic irreducible .
Lemma 1 (Frobenius). Let be monic irreducible of degree and . Then if and only if .
Proof. is a field with elements, and generates it over . The map is a ring homomorphism of , since in characteristic , and it fixes by Fermat's little theorem. The nonzero elements form a group of order , so for all , that is, . For , the polynomial has at most roots in , so . Hence has order exactly as an element of the group of automorphisms of . A ring homomorphism that fixes and fixes every polynomial expression in , which is all of . So if and only if , if and only if .
Lemma 2. For and a monic square-free whose irreducible factors all have degree at least , is the product of the irreducible factors of of degree exactly .
Proof. The polynomial has derivative , so it is square-free. Each irreducible factor of divides exactly when , by Lemma 1. As is square-free, the gcd is the product of the factors of with . Since , means .
Invariant. Before the test at line L2, with the current (the number of completed iterations):
- is the product of the with ;
- and (or when );
- the output so far is the list of pairs , , with , where is the product of the of degree .
Initialization. With , contains all factors, which have degree at least , , and the output is empty.
Maintenance. Line L3 sets ; now is the product of the factors of degree at least and . Line L4 gives . Since , line L5 computes , which by Lemma 2 is the product of the factors of degree . If , line L6 outputs and removes these factors from , so becomes the product of the factors of degree at least ; since the new divides the old one, is still . If , there are no factors of degree and is already the product of those of degree at least . So the invariant holds again.
Termination. Every iteration increases , and the loop stops when , which happens for at the latest. So there are at most iterations.
The rest. When the loop stops, every factor of has degree at least by part 1, and . If had two or more factors, would be at least . So or is irreducible of degree . In the second case is the only factor of of its degree, so , and line L7 outputs . Together with part 3, the output lists every exactly once, in increasing order of .