Difference between revisions of "Modular arithmetic"

 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]].  Since modular arithmetic is such a broadly useful tool in [[number theory]], we divide its explanations into several levels:
 
'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]].  Since modular arithmetic is such a broadly useful tool in [[number theory]], we divide its explanations into several levels:
* [[Introduction to modular arithmetic]]
+
* [[Modular arithmetic/Introduction|Introduction to modular arithmetic]]
 
* [[Intermediate modular arithmetic]]
 
* [[Intermediate modular arithmetic]]
 
* [[Olympiad modular arithmetic]]
 
* [[Olympiad modular arithmetic]]
Line 7: Line 7:
 
== Resources ==
 
== Resources ==
 
=== Introductory Resources ===
 
=== Introductory Resources ===
 +
==== Books ====
 
* The AoPS [http://www.artofproblemsolving.com/Books/AoPS_B_Item.php?page_id=10 Introduction to Number Theory] by [[Mathew Crawford]].
 
* The AoPS [http://www.artofproblemsolving.com/Books/AoPS_B_Item.php?page_id=10 Introduction to Number Theory] by [[Mathew Crawford]].
 +
==== Classes ====
 +
* [http://www.artofproblemsolving.com/Classes/AoPS_C_ClassesS.php#begnum AoPS Introduction to Number Theory Course]
  
 +
=== Intermediate Resources ===
 +
* [http://www.artofproblemsolving.com/Resources/Papers/SatoNT.pdf Number Theory Problems and Notes] by [[Naoki Sato]].
  
 
+
=== Olympiad Resources ===
 
+
* [http://www.artofproblemsolving.com/Resources/Papers/SatoNT.pdf Number Theory Problems and Notes] by [[Naoki Sato]].
==== The Natural Appeal of Modular Arithmetic ====
 
 
 
Observe that we use modular arithmetic even when solving some of the most basic, everyday problems.  For example:
 
 
 
''Cody is cramming for an exam that will be held at 2 PM.  It is the morning of the day of the exam, and Cody did not get any sleep during the night.  He knows that it will take him exactly one hour to get to school from the time he wakes up, and he insists upon getting at least five hours of sleep.  At what time in the morning should Cody stop studying and go to sleep?''
 
 
 
We know that the hours of the day are numbered from <math>1</math> to <math>12</math>, with hours having the same number if and only if they are a multiple of <math>12</math> hours apart. So we can use subtraction mod <math>12</math> to answer this question.
 
 
 
We know that since Cody needs five hours of sleep plus one hour to get to school, he must stop studying six hours before the exam.  We can find out what time this is by performing the subtraction
 
 
 
<math>\overline{2} - \overline{6} = \overline{-4} = \overline{8}.</math>
 
 
 
So Cody must quit studying at 8 AM.
 
 
 
Of course, we are able to perform calculations like this routinely without a formal understanding of modular arithmetic.  One reason for this is that the way we keep time gives us a natural model for addition and subtraction in <math>\mathbb{Z}_n</math>:  a "number circle."  Just as we model addition and subtraction by moving along a number line, we can model addition and subtraction mod <math>n</math> by moving along the circumference of a circle. Even though most of us never learn about modular arithmetic in school, we master this computational model at a very early age.
 
 
 
 
 
==== A Word of Caution ====
 
 
 
Because of the way we define operations in <math>\mathbb{Z}_n</math>, it is important to check that these operations are well-defined.  This is because each of the sets that make up <math>\mathbb{Z}_n</math> contains many different numbers, and therefore has many different names.  For example, observe that in <math>\mathbb{Z}_7</math>, we have <math>\overline{1} = \overline{8}</math> and <math>\overline{2} = \overline{9}</math>.  It is reasonable to expect that if we perform the addition <math>\overline{8} + \overline{9}</math>, we should get the same answer as if we compute <math>\overline{1} + \overline{2}</math>, since we are simply using different names for the same objects.  Indeed, the first addition yields the sum <math>\overline{17} = \overline{3}</math>, which is the same as the result of the second addition.
 
 
 
The "Useful Facts" above are the key to understanding why our operations yield the same results even when we use different names for the same sets.  The task of checking that an operation or function is well-defined, is one of the most important basic techniques in [[abstract algebra]].
 
 
 
 
 
=== Computation of Powers Mod n ===
 
 
 
The "exponentiation" property given above allows us to perform rapid calculations modulo <math>n</math>.  Consider, for example, the problem
 
 
 
''What are the tens and units digits of <math>7^{1942}</math>?''
 
 
 
We could (in theory) solve this problem by trying to compute <math>7^{1942}</math>, but this would be extremely time-consuming.  Moreover, it would give us much more information than we need.  Since we want only the tens and units digits of the number in question, it suffices to find the remainder when the number is divided by <math>100</math>.  In other words, all of the information we need can be found using arithmetic mod <math>100</math>.
 
 
 
We begin by writing down the first few powers of <math>\overline{7}</math>:
 
 
 
<math>\overline{7}, \overline{49}, \overline{43}, \overline{1}, \overline{7}, \overline{49}, \overline{43}, \overline{1}, \ldots</math>
 
 
 
A pattern emerges!  We see that <math>7^4 = 2401 \equiv 1</math> (mod <math>100</math>).  So for any positive integer <math>k</math>, we have <math>7^{4k} = (7^4)^k \equiv 1^k \equiv 1</math> (mod <math>100</math>).  In particular, we can write
 
 
 
<math>7^{1940} = 7^{4 \cdot 485} \equiv 1</math> (mod <math>100</math>).
 
 
 
By the "multiplication" property above, then, it follows that
 
 
 
<math>7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49</math> (mod <math>100</math>).
 
 
 
Therefore, by the definition of congruence, <math>7^{1942}</math> differs from <math>49</math> by a multiple of <math>100</math>.  Since both integers are positive, this means that they share the same tens and units digits.  Those digits are <math>4</math> and <math>9</math>, respectively.
 
 
 
 
 
==== A General Algorithm ====
 
 
 
In the example above, we were fortunate to find a power of <math>7</math> -- namely, <math>7^4</math> -- that is congruent to <math>1</math> mod <math>100</math>.  What if we aren't this lucky?  Suppose we want to solve the following problem:
 
 
 
''What are the tens and units digits of <math>13^{404}</math>?''
 
 
 
Again, we will solve this problem by computing <math>\overline{13}^{404}</math> modulo <math>100</math>.  The first few powers of <math>\overline{13}</math> are
 
 
 
<math>\overline{13}, \overline{69}, \overline{97}, \overline{61}, \overline{93}, \ldots</math>
 
 
 
This time, no pattern jumps out at us.  Is there a way we can find the <math>404^{th}</math> power of <math>\overline{13}</math> without taking this list all the way out to the <math>404^{th}</math> term -- or even without patiently waiting for the list to yield a pattern?
 
 
 
Suppose we condense the list we started above; and instead of writing down all powers of <math>\overline{13}</math>, we write only the powers <math>\overline{13}^k</math>, where <math>k</math> is a power of <math>2</math>.  We have
 
 
 
<math>\overline{13}^1 = \overline{13}</math>
 
 
 
<math>\overline{13}^2 = \overline{69}</math>
 
 
 
<math>\overline{13}^4 = \overline{69}^2 = \overline{61}</math>
 
 
 
<math>\overline{13}^8 = \overline{61}^2 = \overline{21}</math>
 
 
 
<math>\overline{13}^{16} = \overline{21}^2 = \overline{41}</math>
 
 
 
<math>\overline{13}^{32} = \overline{41}^2 = \overline{81}</math>
 
 
 
<math>\overline{13}^{64} = \overline{81}^2 = \overline{61}</math>
 
 
 
<math>\overline{13}^{128} = \overline{61}^2 = \overline{21}</math>
 
 
 
<math>\overline{13}^{256} = \overline{21}^2 = \overline{41}</math>
 
 
 
(Observe that this process yields a pattern of its own, if we carry it out far enough!)
 
 
 
Now, observe that, like any positive integer, <math>404</math> can be written as a sum of powers of two:
 
 
 
<math>404 = 256 + 128 + 16 + 4</math>
 
 
 
We can now use this powers-of-two expansion to compute <math>\overline{13}^{404}</math>:
 
 
 
<math>\overline{13}^{404} = \overline{13}^{256} \cdot \overline{13}^{128} \cdot \overline{13}^{16} \cdot \overline{13}^4 = \overline{41} \cdot \overline{21} \cdot \overline{41} \cdot \overline{61} = \overline{61}.</math>
 
 
 
So the tens and units digits of <math>13^{404}</math> are <math>6</math> and <math>1</math>, respectively.
 
 
 
We can use this method to compute <math>M^e</math> modulo <math>n</math>, for any integers <math>M</math> and <math>e</math>, with <math>e > 0</math>.  The beauty of this algorithm is that the process takes, at most, approximately <math>2 \log_2 e</math> steps -- at most <math>\log_2 e</math> steps to compute the values <math>\overline{M}^k</math> for <math>k</math> a power of two less than <math>e</math>, and at most <math>\log_2 e</math> steps to multiply the appropriate powers of <math>\overline{M}</math> according to the binary representation of <math>e</math>.
 
 
 
This method can be further refined using [[Euler's Totient Theorem]].
 
 
 
 
 
 
 
 
 
=== See also ===
 
 
 
* [[Number theory]]
 
* [[Quadratic residues]]
 

Latest revision as of 20:38, 19 July 2006

Modular arithmetic is a special type of arithmetic that involves only integers. Since modular arithmetic is such a broadly useful tool in number theory, we divide its explanations into several levels:


Resources

Introductory Resources

Books

Classes

Intermediate Resources

Olympiad Resources