Proofs: Multimodular determinant
These are the human proofs of Multimodular determinant, at full length.
Correctness of the multimodular determinant full
This proof shows: correctness, termination.
We prove that MULTIMODULAR-DET returns for every integer matrix . Notation is as on the main page: is row of , , and the primes of the list are distinct.
The bound. By Hadamard's inequality, . Since is an integer, . The integer square root of the integer equals , because is the largest integer whose square is at most .
Lemma 1. For every prime , line L5 returns .
Proof. The map is a ring homomorphism, and is a polynomial with integer coefficients in the entries, so . Since is prime, is a field, and Gaussian elimination with row swaps computes the determinant of a matrix over a field: each swap multiplies the determinant by , adding a multiple of the pivot row to another row does not change it, and the determinant of the final triangular matrix is the product of its diagonal; if no nonzero pivot exists in some column, the columns up to it are dependent and the determinant is .
Invariant. At each test of line L4, is the product of the primes used so far, and with .
Initialization. Before the first test, and , and every integer is congruent to modulo .
Maintenance. Let be the next prime. It differs from the primes in , so and exists. Let by Lemma 1, with , and . Then , and . Since and are coprime, . Finally . So the invariant holds for and .
Termination. Each pass multiplies by a prime, so after passes , and the condition fails after at most passes. The list of primes never runs out because there are infinitely many primes. For , line L1 returns , the determinant of the empty matrix.
Conclusion. At the exit , and . Let , so .
- If , then and , so . Also gives , so line L8 leaves unchanged and returns .
- If , then lies in and is congruent to , so . Line L8 replaces by .
In both cases the algorithm returns .