Algorithm Search⌘K

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 det⁡A\det A for every n×nn \times n integer matrix AA. Notation is as on the main page: aia_i is row ii of AA, H=⌊∏i∥ai∥2⌋H = \lfloor \prod_i \|a_i\|_2 \rfloor, and the primes p1,p2,…p_1, p_2, \ldots of the list are distinct.

The bound. By Hadamard's inequality, ∣det⁡A∣≤∏i∥ai∥2|\det A| \le \prod_i \|a_i\|_2. Since det⁡A\det A is an integer, ∣det⁡A∣≤⌊∏i∥ai∥2⌋=H|\det A| \le \lfloor \prod_i \|a_i\|_2 \rfloor = H. The integer square root of the integer ∏i∥ai∥22\prod_i \|a_i\|_2^2 equals HH, because ⌊N⌋\lfloor \sqrt{N} \rfloor is the largest integer whose square is at most NN.

Lemma 1. For every prime pp, line L5 returns det⁡A mod p\det A \bmod p.

Proof. The map Z→Z/pZ\mathbb{Z} \to \mathbb{Z}/p\mathbb{Z} is a ring homomorphism, and det⁡A=∑σsgn⁡(σ)∏iaiσ(i)\det A = \sum_\sigma \operatorname{sgn}(\sigma) \prod_i a_{i \sigma(i)} is a polynomial with integer coefficients in the entries, so det⁡(A mod p)=(det⁡A) mod p\det (A \bmod p) = (\det A) \bmod p. Since pp is prime, Z/pZ\mathbb{Z}/p\mathbb{Z} is a field, and Gaussian elimination with row swaps computes the determinant of a matrix over a field: each swap multiplies the determinant by −1-1, 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 00. □\square

Invariant. At each test of line L4, MM is the product of the primes used so far, and 0≤r<M0 \le r < M with r≡det⁡A(modM)r \equiv \det A \pmod M.

Initialization. Before the first test, M=1M = 1 and r=0r = 0, and every integer is congruent to 00 modulo 11.

Maintenance. Let pp be the next prime. It differs from the primes in MM, so gcd⁡(M,p)=1\gcd(M, p) = 1 and M−1 mod pM^{-1} \bmod p exists. Let d=det⁡A mod pd = \det A \bmod p by Lemma 1, t=(d−r)M−1 mod pt = (d - r) M^{-1} \bmod p with 0≤t≤p−10 \le t \le p - 1, and r′=r+Mtr' = r + M t. Then r′≡r≡det⁡A(modM)r' \equiv r \equiv \det A \pmod M, and r′≡r+(d−r)=d≡det⁡A(modp)r' \equiv r + (d - r) = d \equiv \det A \pmod p. Since MM and pp are coprime, r′≡det⁡A(modMp)r' \equiv \det A \pmod {M p}. Finally 0≤r′≤(M−1)+M(p−1)=Mp−10 \le r' \le (M - 1) + M (p - 1) = M p - 1. So the invariant holds for M′=MpM' = M p and r′r'.

Termination. Each pass multiplies MM by a prime, so after kk passes M≥2kM \ge 2^k, and the condition M≤2HM \le 2H fails after at most ⌊log⁡2(2H)⌋+1\lfloor \log_2 (2H) \rfloor + 1 passes. The list of primes never runs out because there are infinitely many primes. For n=0n = 0, line L1 returns 11, the determinant of the empty matrix.

Conclusion. At the exit M>2HM > 2H, 0≤r<M0 \le r < M and r≡det⁡A(modM)r \equiv \det A \pmod M. Let D=det⁡AD = \det A, so ∣D∣≤H≤(M−1)/2|D| \le H \le (M - 1)/2.

  • If D≥0D \ge 0, then D<MD < M and D≡rD \equiv r, so r=Dr = D. Also D≤(M−1)/2D \le (M - 1)/2 gives D≤⌊M/2⌋D \le \lfloor M/2 \rfloor, so line L8 leaves rr unchanged and returns DD.
  • If D<0D < 0, then D+MD + M lies in [0,M)[0, M) and is congruent to rr, so r=D+M≥M−(M−1)/2=(M+1)/2>⌊M/2⌋r = D + M \ge M - (M - 1)/2 = (M + 1)/2 > \lfloor M/2 \rfloor. Line L8 replaces rr by r−M=Dr - M = D.

In both cases the algorithm returns det⁡A\det A. ■\blacksquare

Back to Multimodular determinant