Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132930 views
License: OTHER
Kernel:
%%html <link href="http://mathbook.pugetsound.edu/beta/mathbook-content.css" rel="stylesheet" type="text/css" /> <link href="https://aimath.org/mathbook/mathbook-add-on.css" rel="stylesheet" type="text/css" /> <style>.subtitle {font-size:medium; display:block}</style> <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,400italic,600,600italic" rel="stylesheet" type="text/css" /> <link href="https://fonts.googleapis.com/css?family=Inconsolata:400,700&subset=latin,latin-ext" rel="stylesheet" type="text/css" /><!-- Hide this cell. --> <script> var cell = $(".container .cell").eq(0), ia = cell.find(".input_area") if (cell.find(".toggle-button").length == 0) { ia.after( $('<button class="toggle-button">Toggle hidden code</button>').click( function (){ ia.toggle() } ) ) ia.hide() } </script>

Important: to view this notebook properly you will need to execute the cell above, which assumes you have an Internet connection. It should already be selected, or place your cursor anywhere above to select. Then press the "Run" button in the menu bar above (the right-pointing arrowhead), or press Shift-Enter on your keyboard.

ParseError: KaTeX parse error: \newcommand{\lt} attempting to redefine \lt; use \renewcommand

Section16.5An Application to Software Design

The Chinese Remainder Theorem is a result from elementary number theory about the solution of systems of simultaneous congruences. The Chinese mathematician Sun-tsï wrote about the theorem in the first century A.D. This theorem has some interesting consequences in the design of software for parallel processors.

Lemma16.41

Let mm and nn be positive integers such that gcd(m,n)=1.\gcd( m, n) = 1\text{.} Then for a,bZa, b \in {\mathbb Z} the system

xa(modm)xb(modn)\begin{align*} x & \equiv a \pmod{m}\\ x & \equiv b \pmod{n} \end{align*}

has a solution. If x1x_1 and x2x_2 are two solutions of the system, then x1x2(modmn).x_1 \equiv x_2 \pmod{mn}\text{.}

Proof

The equation xa(modm)x \equiv a \pmod{m} has a solution since a+kma + km satisfies the equation for all kZ.k \in {\mathbb Z}\text{.} We must show that there exists an integer k1k_1 such that

a+k1mb(modn).\begin{equation*} a + k_1 m \equiv b \pmod{n}. \end{equation*}

This is equivalent to showing that

k1m(ba)(modn)\begin{equation*} k_1 m \equiv (b-a) \pmod{n} \end{equation*}

has a solution for k1.k_1\text{.} Since mm and nn are relatively prime, there exist integers ss and tt such that ms+nt=1.ms + nt = 1\text{.} Consequently,

(ba)ms=(ba)(ba)nt,\begin{equation*} (b-a) ms = (b-a) -(b-a) nt, \end{equation*}

or

[(ba)s]m(ba)(modn).\begin{equation*} [(b-a)s]m \equiv (b-a) \pmod{n}. \end{equation*}

Now let k1=(ba)s.k_1 = (b-a)s\text{.}

To show that any two solutions are congruent modulo mn,mn\text{,} let c1c_1 and c2c_2 be two solutions of the system. That is,

cia(modm)cib(modn)\begin{align*} c_i & \equiv a \pmod{m}\\ c_i & \equiv b \pmod{n} \end{align*}

for i=1,2.i = 1, 2\text{.} Then

c2c1(modm)c2c1(modn).\begin{align*} c_2 & \equiv c_1 \pmod{m}\\ c_2 & \equiv c_1 \pmod{n}. \end{align*}

Therefore, both mm and nn divide c1c2.c_1 - c_2\text{.} Consequently, c2c1(modmn).c_2 \equiv c_1 \pmod{mn}\text{.}

Example16.42

Let us solve the system

x3(mod4)x4(mod5).\begin{align*} x & \equiv 3 \pmod{4}\\ x & \equiv 4 \pmod{5}. \end{align*}

Using the Euclidean algorithm, we can find integers ss and tt such that 4s+5t=1.4s + 5t = 1\text{.} Two such integers are s=4s = 4 and t=3.t = -3\text{.} Consequently,

x=a+k1m=3+4k1=3+4[(54)4]=19.\begin{equation*} x = a + k_1 m = 3 + 4k_1 = 3 + 4[(5 - 4)4] = 19. \end{equation*}
Theorem16.43Chinese Remainder Theorem

Let n1,n2,,nkn_1, n_2, \ldots, n_k be positive integers such that gcd(ni,nj)=1\gcd(n_i, n_j) = 1 for ij.i \neq j\text{.} Then for any integers a1,,ak,a_1, \ldots, a_k\text{,} the system

xa1(modn1)xa2(modn2)xak(modnk)\begin{align*} x & \equiv a_1 \pmod{n_1}\\ x & \equiv a_2 \pmod{n_2}\\ & \vdots \\ x & \equiv a_k \pmod{n_k} \end{align*}

has a solution. Furthermore, any two solutions of the system are congruent modulo n1n2nk.n_1 n_2 \cdots n_k\text{.}

Proof

We will use mathematical induction on the number of equations in the system. If there are k=2k= 2 equations, then the theorem is true by Lemma 16.41. Now suppose that the result is true for a system of kk equations or less and that we wish to find a solution of

xa1(modn1)xa2(modn2)xak+1(modnk+1).\begin{align*} x & \equiv a_1 \pmod{n_1}\\ x & \equiv a_2 \pmod{n_2}\\ & \vdots \\ x & \equiv a_{k+1} \pmod{n_{k+1}}. \end{align*}

Considering the first kk equations, there exists a solution that is unique modulo n1nk,n_1 \cdots n_k\text{,} say a.a\text{.} Since n1nkn_1 \cdots n_k and nk+1n_{k+1} are relatively prime, the system

xa(modn1nk)xak+1(modnk+1)\begin{align*} x & \equiv a \pmod{n_1 \cdots n_k }\\ x & \equiv a_{k+1} \pmod{n_{k+1}} \end{align*}

has a solution that is unique modulo n1nk+1n_1 \ldots n_{k+1} by the lemma.

Example16.44

Let us solve the system

x3(mod4)x4(mod5)x1(mod9)x5(mod7).\begin{align*} x & \equiv 3 \pmod{4}\\ x & \equiv 4 \pmod{5}\\ x & \equiv 1 \pmod{9}\\ x & \equiv 5 \pmod{7}. \end{align*}

From Example 16.42 we know that 19 is a solution of the first two congruences and any other solution of the system is congruent to 19(mod20).19 \pmod{20}\text{.} Hence, we can reduce the system to a system of three congruences:

x19(mod20)x1(mod9)x5(mod7).\begin{align*} x & \equiv 19 \pmod{20}\\ x & \equiv 1 \pmod{9}\\ x & \equiv 5 \pmod{7}. \end{align*}

Solving the next two equations, we can reduce the system to

x19(mod180)x5(mod7).\begin{align*} x & \equiv 19 \pmod{180}\\ x & \equiv 5 \pmod{7}. \end{align*}

Solving this last system, we find that 19 is a solution for the system that is unique up to modulo 1260.

One interesting application of the Chinese Remainder Theorem in the design of computer software is that the theorem allows us to break up a calculation involving large integers into several less formidable calculations. A computer will handle integer calculations only up to a certain size due to the size of its processor chip, which is usually a 32 or 64-bit processor chip. For example, the largest integer available on a computer with a 64-bit processor chip is

2631=9,223,372,036,854,775,807.\begin{equation*} 2^{63} - 1 = \text{9,223,372,036,854,775,807}. \end{equation*}

Larger processors such as 128 or 256-bit have been proposed or are under development. There is even talk of a 512-bit processor chip. The largest integer that such a chip could store with be 25111,2^{511} - 1\text{,} which would be a 154 digit number. However, we would need to deal with much larger numbers to break sophisticated encryption schemes.

Special software is required for calculations involving larger integers which cannot be added directly by the machine. By using the Chinese Remainder Theorem we can break down large integer additions and multiplications into calculations that the computer can handle directly. This is especially useful on parallel processing computers which have the ability to run several programs concurrently.

Most computers have a single central processing unit (CPU) containing one processor chip and can only add two numbers at a time. To add a list of ten numbers, the CPU must do nine additions in sequence. However, a parallel processing computer has more than one CPU. A computer with 10 CPUs, for example, can perform 10 different additions at the same time. If we can take a large integer and break it down into parts, sending each part to a different CPU, then by performing several additions or multiplications simultaneously on those parts, we can work with an integer that the computer would not be able to handle as a whole.

Example16.45

Suppose that we wish to multiply 2134 by 1531. We will use the integers 95, 97, 98, and 99 because they are relatively prime. We can break down each integer into four parts:

213444(mod95)21340(mod97)213476(mod98)213455(mod99)\begin{align*} 2134 & \equiv 44 \pmod{95}\\ 2134 & \equiv 0 \pmod{97}\\ 2134 & \equiv 76 \pmod{98}\\ 2134 & \equiv 55 \pmod{99} \end{align*}

and

153111(mod95)153176(mod97)153161(mod98)153146(mod99).\begin{align*} 1531 & \equiv 11 \pmod{95}\\ 1531 & \equiv 76 \pmod{97}\\ 1531 & \equiv 61 \pmod{98}\\ 1531 & \equiv 46 \pmod{99}. \end{align*}

Multiplying the corresponding equations, we obtain

2134153144119(mod95)213415310760(mod97)21341531766130(mod98)21341531554655(mod99).\begin{align*} 2134 \cdot 1531 & \equiv 44 \cdot 11 \equiv 9 \pmod{95}\\ 2134 \cdot 1531 & \equiv 0 \cdot 76 \equiv 0 \pmod{97}\\ 2134 \cdot 1531 & \equiv 76 \cdot 61 \equiv 30 \pmod{98}\\ 2134 \cdot 1531 & \equiv 55 \cdot 46 \equiv 55 \pmod{99}. \end{align*}

Each of these four computations can be sent to a different processor if our computer has several CPUs. By the above calculation, we know that 213415312134 \cdot 1531 is a solution of the system

x9(mod95)x0(mod97)x30(mod98)x55(mod99).\begin{align*} x & \equiv 9 \pmod{95}\\ x & \equiv 0 \pmod{97}\\ x & \equiv 30 \pmod{98}\\ x & \equiv 55 \pmod{99}. \end{align*}

The Chinese Remainder Theorem tells us that solutions are unique up to modulo 95979899=89,403,930.95 \cdot 97 \cdot 98 \cdot 99 = \text{89,403,930}\text{.} Solving this system of congruences for xx tells us that 21341531=3,267,154.2134 \cdot 1531 = \text{3,267,154}\text{.}

The conversion of the computation into the four subcomputations will take some computing time. In addition, solving the system of congruences can also take considerable time. However, if we have many computations to be performed on a particular set of numbers, it makes sense to transform the problem as we have done above and to perform the necessary calculations simultaneously.