Systems of linear congruences can be solved using methods from linear algebra: Matrix inversion, Cramer's rule, or row reduction. In case the modulus is prime, everything you know from linear algebra goes over to systems of linear congruences. (The reason is the is a field, for p prime, and linear algebra works fine over any field --- not just and .)
I will stick to prime moduli for simplicity. I'll assume that you know some linear algebra, even if you haven't seen it done with modular arithmetic.
In the first example, I'll use the well-known fact that a matrix is invertible if and only if its determinant is nonzero.
Example. Solve
Write the system in matrix form:
The determinant of the coefficient matrix is . In particular, it's nonzero mod 7, so the system has a solution. For a system, it's easiest to use the formula for inverting a matrix:
All I have to do is multiply both sides of the equation on the left by the inverse of the coefficient matrix:
Recall that . The inverse of 3 mod 7 is 5, since . This explains the 5 in the second line.
The solution is
Example. Solve
In this case, it's better to use row reduction.
The solution is
Example. Solve
I'll do this by row reduction:
The equations are
There are multiple solutions --- in fact, since there is one free variable (z), there will be 5 distinct solutions mod 5. As is customary when a system has multiple solutions, I'll write the solution in parametric form.
Set . Then , so (by adding to both sides). Likewise, , so . The solution is
Example. This example has little to do with solving congruences; it's presented to point out that you can work with matrices using modular arithmetic pretty much as usual. I'll compute the inverse mod 3 of the matrix
To do this, tack on a copy of the identity matrix, then row reduce the resulting matrix. When the block on the left becomes the identity, the block on the right will have turned into .
Thus,
Example. Is the following matrix invertible mod 6?
When the modulus is not prime, results from linear algebra must be used with care. In this case, I'd like to use the determinant to tell whether the matrix is invertible.
Normally, a nonzero determinant means that the matrix is invertible. However, mod n the criterion is that the determinant must be relatively prime to n. Since , the matrix is not invertible. If you try to apply a standard matrix inversion algorithm to find the inverse, you'll find that it won't work.
Send comments about this page to: bikenaga@marauder.millersville.edu.
Last updated:
Millersville University Home Page
Copyright 2008 by Bruce Ikenaga