Difference between revisions of "Modular arithmetic"

(Arithmetic Modulo n)
 
(13 intermediate revisions by 3 users not shown)
Line 1: Line 1:
'''Modular arithmetic''' is a special type of arithmetic that involves only [[integers]].  Given integers <math>a</math>, <math>b</math>, and <math>n</math>, with <math>n > 0</math>, we say that <math>a</math> is ''congruent to'' <math>b</math> ''modulo'' <math>n</math>, or <math>a \equiv b</math> (mod <math>n</math>), if the difference <math>{a - b}</math> is divisible by <math>n</math>.
+
'''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/Introduction|Introduction to modular arithmetic]]
 +
* [[Intermediate modular arithmetic]]
 +
* [[Olympiad modular arithmetic]]
  
For a given positive integer <math>n</math>, the relation <math>a \equiv b</math> (mod <math>n</math>) is an [[equivalence relation]] on the set of integers.  This relation gives rise to an algebraic structure called '''the integers modulo <math>n</math>''' (usually known as "the integers mod <math>n</math>," or <math>\mathbb{Z}_n</math> for short).  This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to [[Diophantine equation|Diophantine equations]], testing whether certain large numbers are prime, and even some problems in cryptology.
 
  
 +
== 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]].
 +
==== Classes ====
 +
* [http://www.artofproblemsolving.com/Classes/AoPS_C_ClassesS.php#begnum AoPS Introduction to Number Theory Course]
  
== Arithmetic Modulo n ==
+
=== Intermediate Resources ===
 +
* [http://www.artofproblemsolving.com/Resources/Papers/SatoNT.pdf Number Theory Problems and Notes] by [[Naoki Sato]].
  
=== Useful Facts ===
+
=== Olympiad Resources ===
 
+
* [http://www.artofproblemsolving.com/Resources/Papers/SatoNT.pdf Number Theory Problems and Notes] by [[Naoki Sato]].
Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{m}</math> such that <math>a\equiv b\pmod {m}</math> and <math>c\equiv d\pmod {m}</math>. In modular arithmetic, the following [[identity | identities]] hold:
 
 
 
* Addition: <math>a+c\equiv b+d\pmod {m}</math>.
 
* Subtraction: <math>a-c\equiv b-d\pmod {m}</math>.
 
* Multiplication: <math>ac\equiv bd\pmod {m}</math>.
 
* Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}</math>, where <math>e</math> is a positive integer that divides <math>{a}</math> and <math>b</math>.
 
* Exponentiation: <math>a^e\equiv b^e\pmod {m}</math> where <math>e</math> is a positive integer.
 
 
 
==== Examples ====
 
 
 
* <math>{7}\equiv {1} \pmod {2}</math>
 
 
 
* <math>49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}</math>
 
 
 
* <math>7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}</math>
 
 
 
=== The Integers Modulo n ===
 
 
 
The relation <math>a \equiv b</math> (mod <math>n</math>) allows us to divide the set of integers into sets of equivalent elements.  For example, if <math>n = 3</math>, then the integers are divided into the following sets:
 
 
 
<math>\{ \ldots, -6, -3, 0, 3, 6, \ldots \}</math>
 
 
 
<math>\{ \ldots, -5, -2, 1, 4, 7, \ldots \}</math>
 
 
 
<math>\{ \ldots, -4, -1, 2, 5, 8, \ldots \}</math>
 
 
 
Notice that if we pick two numbers <math>a</math> and <math>b</math> from the same set, then <math>a</math> and <math>b</math> differ by a multiple of <math>3</math>, and therefore <math>a \equiv b</math> (mod <math>3</math>).
 
 
 
We sometimes refer to one of the sets above by choosing an element from the set, and putting a bar over it.  For example, the symbol <math>\overline{0}</math> refers to the set containing <math>0</math>; that is, the set of all integer multiples of <math>3</math>.  The symbol <math>\overline{1}</math> refers to the second set listed above, and <math>\overline{2}</math> the third.  The symbol <math>\overline{3}</math> refers to the same set as <math>\overline{0}</math>, and so on.
 
 
 
Instead of thinking of the objects <math>\overline{0}</math>, <math>\overline{1}</math>, and <math>\overline{2}</math> as sets, we can treat them as algebraic objects -- like numbers -- with their own operations of addition and multiplication.  Together, these objects form '''the integers modulo <math>3</math>,''' or <math>\mathbb{Z}_3</math>.  More generally, if <math>n</math> is a positive integer, then we can define
 
 
 
<math>\mathbb{Z}_n = \{\overline{0}, \overline{1}, \overline{2}, \ldots, \overline{n-1} \}</math>,
 
 
 
where for each <math>k</math>, <math>\overline{k}</math> is defined by
 
 
 
<math>\overline{k} = \{ m \in \mathbb{Z} \mbox{ such that } m \equiv k \pmod{n} \}.</math>
 
 
 
=== Addition, Subtraction, and Multiplication Mod n ===
 
 
 
We define addition, subtraction, and multiplication in <math>\mathbb{Z}_n</math> according to the following rules:
 
 
 
<math>\overline{a} + \overline{b} = \overline{a+b}</math> for all <math>a, b \in \mathbb{Z}</math>.  (Addition)
 
 
 
<math>\overline{a} - \overline{b} = \overline{a-b}</math> for all <math>a, b \in \mathbb{Z}</math>.  (Subtraction)
 
 
 
<math>\overline{a} \cdot \overline{b} = \overline{ab}</math> for all <math>a, b \in \mathbb{Z}</math>.  (Multiplication)
 
 
 
So for example, if <math>n = 7</math>, then we have
 
 
 
<math>\overline{3} + \overline{2} = \overline{3+2} = \overline{5}</math>
 
 
 
<math>\overline{4} + \overline{4} = \overline{4+4} = \overline{8} = \overline{1}</math>
 
 
 
<math>\overline{4} \cdot \overline{3} = \overline{4 \cdot 3} = \overline{12} = \overline{5}</math>
 
 
 
<math>\overline{6} \cdot \overline{6} = \overline{6 \cdot 6} = \overline{36} = \overline{1}</math>
 
 
 
Notice that, in each case, we reduce to an answer of the form <math>\overline{k}</math>, where <math>0 \leq k < 7</math>.  We do this for two reasons:  to keep possible future calculations as manageable as possible, and to emphasize the point that each expression takes one of only seven (or in general, <math>n</math>) possible values.  (Some people find it useful to reduce an answer such as <math>\overline{5}</math> to <math>\overline{-2}</math>, which is negative but has a smaller absolute value.)
 
 
 
==== 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>.
 
 
 
By writing down the first few powers of <math>7</math>, 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.
 
 
 
== Intermediate ==
 
 
 
=== Divisibility Tests ===
 
 
 
Modular arithmetic is the basis for several well-known divisibility tests.  Consider, for example, the test for divisibility by <math>9</math>:
 
 
 
''Let <math>N</math> be a positive integer.  Then <math>N</math> is divisible by <math>9</math> if and only if the sum of the base-ten digits of <math>N</math> is divisible by <math>9</math>.''
 
 
 
Arithmetic mod <math>9</math> can be used to give an easy proof of this criterion:
 
 
 
Suppose that the base-ten representation of <math>N</math> is
 
 
 
<math>N = a_k a_{k-1} \cdots a_2 a_1 a_0</math>,
 
 
 
where <math>a_i</math> is a digit for each <math>i</math>. Then the numerical value of <math>N</math> is given by
 
 
 
<math>N = a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0</math>.
 
 
 
Now we know that, since <math>10 - 1 = 9</math>, we have <math>10 \equiv 1</math> (mod <math>9</math>). So by the "exponentiation" property above, we have <math>10^j \equiv 1^j \equiv 1</math> (mod <math>9</math>) for every <math>j</math>.
 
 
 
Therefore, by repeated uses of the "addition" and "multiplication" properties, we can write
 
 
 
<math>a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0 \equiv a_k \cdot 1 + a_{k-1} \cdot 1 + \cdots + a_1 \cdot 1 + a_0 \cdot 1</math> (mod <math>9</math>).
 
 
 
Therefore, we have
 
 
 
<math>N \equiv a_k + a_{k-1} + \cdots + a_1 + a_0</math> (mod <math>9</math>).
 
 
 
That is, <math>N</math> differs from the sum of its digits by a multiple of <math>9</math>.  It follows, then, that <math>N</math> is a multiple of <math>9</math> if and only if the sum of its digits is a multiple of <math>9</math>.
 
 
 
A virtually identical argument shows that a positive integer is divisible by <math>3</math> if and only if the sum of its base-ten digits is divisible by <math>3</math>.  We can also use the technique shown above to devise a test for divisibility by <math>11</math>.
 
 
 
=== Topics ===
 
* [[Fermat's Little Theorem]]
 
* [[Euler's Totient Theorem]]
 
* [[Phi function]]
 
 
 
=== See also ===
 
 
 
* [[Number theory]]
 
* [[Quadratic residues]]
 
 
 
== Miscellany ==
 
 
 
=== The binary operation "mod" ===
 
 
 
Related to the concept of congruence, mod <math>n</math> is the binary operation '''<math>a</math> mod <math>n</math>''', which is used often in computer programming.
 
 
 
Recall that, by the [[Division Algorithm]], given any two integers <math>a</math> and <math>n</math>, with <math>n > 0</math>, we can find integers <math>q</math> and <math>r</math>, with <math>0 \leq r < n </math>, such that <math>a = nq + r</math>.  The number <math>q</math> is called the ''quotient'', and the number <math>r</math> is called the ''remainder''.  The operation ''<math>a</math> mod <math>n</math>'' returns the value of the remainder <math>r</math>.  For example:
 
 
 
<math>15</math> mod <math>6 = 3</math>, since <math>15 = 6 \cdot 2 + 3</math>.
 
 
 
<math>35</math> mod <math>7 = 0</math>, since <math>35 = 7 \cdot 5 + 0</math>.
 
 
 
<math>-10</math> mod <math>8 = 6</math>, since <math>-10 = 8 \cdot -2 + 6</math>.
 
 
 
Observe that if <math>a</math> mod <math>n = r</math>, then we also have <math>a \equiv r</math> (mod <math>n</math>).
 

Latest revision as of 19: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