Home

> urticator.net
  Search

  About This Site
> Domains
  Glue
  Stories

  Computers
  Driving
  Games
  Humor
  Law
> Math
  Numbers
  Science

  Continued Fractions
  Game Theory (Section)
> Group Theory
  Probability
  Miscellaneous

  A Theorem on Finite Abelian Groups
  The Structure of Zn
  How to Compute Inverses in Un
> How to Solve Simultaneous Congruences

How to Solve Simultaneous Congruences

I already explained how to solve simultaneous congruences in An Example. The first part of that explanation is flawless.

Suppose we're trying to solve a set of congruences

x ≡ ai mod mi,

where the factors mi are relatively prime. If we can find a set of numbers Gi that satisfy

Gi ≡ δij mod mj,

then the solution x can be obtained by adding up appropriate multiples.

x = sum ( ai Gi )

(I don't know an official name for the numbers Gi, so I used the letter “G” because they remind me of Green's functions.)

The second part is OK, I guess. It explains how to find the numbers Gi, but it does it in prose, by example, and as a result it feels nebulous, like there's nothing there for my mind to grab on to. Nowadays I'd rather see the results in a table, like so, even though there's almost no interaction between the rows.

min/min/miviGi
mod nmod mimod mimod n
199991176993
2770311703
37513322211286

Here (and in An Example) the number n is the product of all the moduli mi, in this case 18981. The solution x is defined modulo n.

Now let's look at the columns one by one.

  1. We already know all about mi.
  2. Since n is the product of all the moduli, n/mi is the product of all the other moduli. So, although it looks like division, which in group theory is always suspect, it's really just multiplication. (Also, that multiplication of other moduli is the interaction between rows that I was thinking of.)

    We'll use n/mi to construct Gi and x, so it's appropriate to regard it as a number mod n. And, since it's positive and less than n, it's conveniently pre-normalized into the range [0,n).

  3. Next we regard n/mi as a number mod mi. It's not necessary to normalize it into the range [0,mi), but I like to.
  4. Next we compute the inverse of n/mi mod mi. Let's call that vi. It's not necessary to normalize it into the range [0,mi), but the new algorithm does that automatically.
  5. Finally, we regard vi as a number mod n and take the product of columns 2 and 4 to get the Green's function Gi. If vi was normalized, then the result will be too, since (n/mi)vi = n(vi/mi).

What about the case where the moduli mi aren't relatively prime? In practice, I haven't run into it, so I guess it's not particularly useful, but it's easy to understand, so sure, let's take a quick look. The key lies two essays before An Example, in the first paragraph of The Structure of Un. For each i, we can break the original congruence modulo mi into congruences modulo the prime power factors of mi. Then, whenever a prime occurs in more than one congruence, the congruence with the largest exponent will win, and the rest will be either redundant or incompatible. For example, if we know that x ≡ 5 mod 8, then x ≡ 1 mod 4 is redundant but x ≡ 2 mod 4 is incompatible.

New topic! Remember the formula for the solution x?

x = sum ( ai Gi )

Here's an interesting special case. If the parameters ai are identically 1, then the solution is just the sum of the Green's functions. However, the solution is also obviously just 1. Therefore, we have the following result.

sum ( Gi ) ≡ 1 mod n

When computing a table, we can use that result either as a shortcut to get the last Green's function or as a checksum at the end.

Here's another interesting special case. If there are three congruences, and the parameters ai are some permutation of −1, 0, and 1, then the solution is the difference of two Green's functions. Let's consider the six possible permutations and differences all at once. Of the six differences, three are positive, and of the three, the two smallest always add up to the third. The reason for that is easy to understand. If for example G3 > G2 > G1, then

(G3 − G1) = (G3 − G2) + (G2 − G1).

Of course, in modular arithmetic nothing is greater than or less than anything else, and as a result nothing is positive or negative. However, the identity above is still valid, and in fact there are five others just like it that are now equally valid.

Now, here's the strange part. Suppose we normalize the six differences into the range [0,n) and ignore the fact that we shouldn't compare them. The two smallest may not be the same as before, but they still always add up to another difference! Sadly, I don't know any elegant way to prove that. We just have to look at cases, eliminate some, and observe that the rest are covered by the six identities. For example, if G3 − G2 is the smallest difference, then G3 − G1 can't be the next smallest, because

(G2 − G1) = (G3 − G1) − (G3 − G2) < (G3 − G1).

Finally, let's take a quick look at the simultaneous congruences that appeared in the thread Number Maze.

In The Next Block I ran into the second special case, but I solved it with an ad hoc method. For comparison, here's the table of Green's functions for n = 231. As expected, the positive differences are 55, 56, and 111.

min/min/miviGi
mod nmod mimod mimod n
37722154
7335399
11211010210

In Odds and Ends there were actually two layers of simultaneous congruences. In the first layer there were two instances of the second special case (plus some easier problems). Here's the table of Green's functions for n = 663. As expected, the positive differences are 169, 170, and 339.

min/min/miviGi
mod nmod mimod mimod n
322122442
13511212612
173957273

And here's the table of Green's functions for n = 665. As expected, the positive differences are 20, 56, and 76.

min/min/miviGi
mod nmod mimod mimod n
513332266
79542190
1935166210

In the second layer there were a bunch of simultaneous congruences based on the same moduli. They weren't special cases, though, so I was forced to break out the Green's functions. So, the results in this table aren't new.

min/min/miviGi
mod nmod mimod mimod n
6631103903322220780
166440895−1−1−440895
665110058−3322220116

Here I left everything unnormalized, partly for consistency with the previous results and partly for clarity. Since n = 73188570, the normalized form of −440895 would be 72747675, a completely unhelpful number.

 

  See Also

@ November (2024)