Processing math: 100%
Skip to main content

Section 5.4 Using the Chinese Remainder Theorem

We will here present a completely constructive proof of the CRT (Theorem 5.3.2). That is, we will not just prove it can be done, we will show how to get a solution to a given system of linear congruences.

Keep in mind that this is a procedure that works. It may have a number of steps, but its power is not to be underestimated. After some careful examples, we'll see some other uses.

Subsection 5.4.1 Constructing simultaneous solutions

Remember that we are trying to solve the system of equations x≑ai (mod ni). It is important to confirm that all ni are coprime in pairs (or that the set of moduli is mutually coprime, Definition 2.4.8). Then the following steps will lead to a solution. You will find basically this proof in any text; I use the notation in [C.2.1], while that in [C.2.4] basically uses the letter m instead of n.

  1. First, let's call the product of the moduli n1n2β‹―nk=N.

  2. Take the quotient N/ni and call it ci. It's sort of a β€œcomplement” to the ith modulus within the big product N.

  3. Now find the inverse of each ci modulo ni. That is, for each i, find a solution di such that

    cidi≑1 (mod ni)

    Notice that this is possible. You can't find an inverse modulo any old thing! But in this case, ci is the product of a bunch of numbers, all of which are coprime to ni, so it is also coprime to ni, as required.

  4. For each i, multiply the three numbers aiβ‹…ciβ‹…di.

  5. Now we evaluate each of these products (indexed by i) modulo the various nj. That looks bad, but most things cancel because each cj is divisible by ni (except for ci itself).

    • When iβ‰ j, the product modulo ni is thus

      ajcjdj≑0 (mod ni).
    • Otherwise we can use the definition of inverse, and the product is

      aicidi≑aiβ‹…1≑ai (mod ni)
  6. Now add all these products together to get our final answer,

    x=a1c1d1+a2c2d2+β‹―+akckdk.

    For each ni, we can do the sum modulo ni too; the previous step shows this sum is

    x≑0+0+β‹―+ai+β‹―+0 (mod ni).

    So this is definitely a solution.

  7. Any other solution xβ€² has to still fulfill x′≑ai≑x (mod ni), so ni∣xβ€²βˆ’x for all moduli ni. Since all ni are relatively prime to each other, N∣xβ€²βˆ’x too (if a∣c and b∣c and gcd(a,b)=1, then ab∣c). So x′≑x (mod N), which means x is the only solution modulo N!

Clearly this needs an example.

Example 5.4.1. A first CRT example.

Let's look at how to solve our original system from Question 5.3.1 using this method. First we write our simultaneous congruences:

  • x≑1 (mod 5)

  • x≑2 (mod 6)

  • x≑3 (mod 7)

We'll follow along with each of the steps in Sage. First, I'll make sure I know all my initial constants (printing them to verify).

Next, I'll put down all the ci, the complements to the moduli, so to speak. Remember, ci=N/ni.

Now we need to solve for the inverse of each ci modulo ni. One could do this by hand. For instance,

42d1≑2d1≑1 (mod 5) yielding d1=3, since 2β‹…3=6≑1 (mod 5).

But that is best done on homework for careful practice; in the text, we might as well use the power of Sage.

Now I'll create each of the big product numbers, as well as their sum.

Of course, we don't recognize 836 as our answer. But:

Sage note 5.4.2. Printing it out.

When using Sage cells, you might not want only the things in the last line returned to you as output. You can use the print function to get them to print out, as we have done in the preceding example 5.4.1.

This is actually capability in Python itself, not just Sage, so if you have previous experience with Python (or perhaps other languages), it is very important to note print() is a function. That means means the thing to be printed must be in parentheses, such as print(3). Previously (in Sage versions previous to 9.0, and anything else based on Python 2) syntax such as print 3 was allowed, and experienced Sage users may need some time to adjust. If you are new to Sage, no worries!

Example 5.4.3.

Let's try some more interesting moduli for an example to do on your own. Can you follow the template?

  • x≑1 (mod 6)

  • x≑11 (mod 35)

  • x≑3 (mod 11)

Sage can also approach this in a similar way, as we saw earlier.

Subsection 5.4.2 A theoretical but highly important use of CRT

The following proposition is an example of one of the many useful things we can do with the CRT.

As a result, any question about a congruence is really a question about several congruences, but with smaller moduli (indeed, simpler moduli in a specific sense; see Proposition 6.5.1 for a strong statement of this). We will use this fact again and again in the remainder of the text, and it is a huge reason why the Chinese Remainder Theorem is so intensely powerful.