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 .)
It's also possible to convert a system to a linear Diophantine equation.
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:
If I apply this formula to the coefficient matrix for the system, I get
The inverse of 3 mod 7 is 5, since .
All I have to do is multiply both sides of the equation on the left by the inverse of the coefficient matrix:
The solution is
You can also solve this equation using Cramer's rule, or by row reduction. You can even use basic algebra, though it's a little tedious. Solve the first equation for one of the variables:
Substitute this into the second equation:
Plugging this back into the x-equation gives .
In some cases, you can convert a system to a linear Diophantine equation, which we already know how to solve.
Example. Solve the following system over :
Note, however, that the first equation is 4 times the second:
So it suffices to solve
This is equivalent to the Diophantine equation
Let . This gives
The general solution is
z is just a helper variable, so ignore it. Using the w-equation, I have
The general solution is
Recall that the original system was mod 7:
Note that this is a parametrized solution. You could also do this problem by row reduction.
Example. Solve
As before, multiplying the second equation by 4 gives
But the two equations now imply " ", and this contradiction implies that the system has no solutions.
Example. Solve
With a system this large, 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
As noted above, it's possible to do a lot of linear algebra mod n. Here's an example.
Example. Compute the inverse mod 3 of the matrix
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. So, for instance, if you try apply the standard matrix inversion algorithm to find the inverse, you'll find that it won't work.
Copyright 2019 by Bruce Ikenaga