Difference between revisions of "Modular arithmetic"
(→Introductory) |
(→Arithmetic Modulo n) |
||
Line 5: | Line 5: | ||
== Arithmetic Modulo n == | == Arithmetic Modulo n == | ||
+ | |||
+ | === 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: | 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: | ||
Line 16: | Line 19: | ||
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. | 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> | ||
=== Useful Facts === | === Useful Facts === | ||
Line 52: | Line 59: | ||
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. | 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 == | == Intermediate == |
Revision as of 01:32, 27 June 2006
Modular arithmetic is a special type of arithmetic that involves only integers. Given integers , , and , with , we say that is congruent to modulo , or (mod ), if the difference is divisible by .
For a given positive integer , the relation (mod ) is an equivalence relation on the set of integers. This relation gives rise to an algebraic structure called the integers modulo (usually known as "the integers mod ," or for short). This structure gives us a useful tool for solving a wide range of number-theoretic problems, including finding solutions to Diophantine equations, testing whether certain large numbers are prime, and even some problems in cryptology.
Contents
Arithmetic Modulo n
The Integers Modulo n
The relation (mod ) allows us to divide the set of integers into sets of equivalent elements. For example, if , then the integers are divided into the following sets:
Notice that if we pick two numbers and from the same set, then and differ by a multiple of , and therefore (mod ).
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 refers to the set containing ; that is, the set of all integer multiples of . The symbol refers to the second set listed above, and the third. The symbol refers to the same set as , and so on.
Instead of thinking of the objects , , and 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 , or . More generally, if is a positive integer, then we can define
Useful Facts
Consider four integers and a positive integer such that and . In modular arithmetic, the following identities hold:
- Addition: .
- Subtraction: .
- Multiplication: .
- Division: , where is a positive integer that divides and .
- Exponentiation: where is a positive integer.
Examples
Computation of Powers Mod n
The "exponentiation" property given above allows us to perform rapid calculations modulo . Consider, for example, the problem
What are the tens and units digits of ?
We could (in theory) solve this problem by trying to compute , 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 . In other words, all of the information we need can be found using arithmetic mod .
By writing down the first few powers of , we see that (mod ). So for any positive integer , we have (mod ). In particular, we can write
(mod ).
By the "multiplication" property above, then, it follows that
(mod ).
Therefore, by the definition of congruence, differs from by a multiple of . Since both integers are positive, this means that they share the same tens and units digits. Those digits are and , respectively.
Intermediate
Divisibility Tests
Modular arithmetic is the basis for several well-known divisibility tests. Consider, for example, the test for divisibility by :
Let be a positive integer. Then is divisible by if and only if the sum of the base-ten digits of is divisible by .
Arithmetic mod can be used to give an easy proof of this criterion:
Suppose that the base-ten representation of is
,
where is a digit for each . Then the numerical value of is given by
.
Now we know that, since , we have (mod ). So by the "exponentiation" property above, we have (mod ) for every .
Therefore, by repeated uses of the "addition" and "multiplication" properties, we can write
(mod ).
Therefore, we have
(mod ).
That is, differs from the sum of its digits by a multiple of . It follows, then, that is a multiple of if and only if the sum of its digits is a multiple of .
A virtually identical argument shows that a positive integer is divisible by if and only if the sum of its base-ten digits is divisible by . We can also use the technique shown above to devise a test for divisibility by .
Topics
See also
Miscellany
The binary operation "mod"
Related to the concept of congruence, mod is the binary operation mod , which is used often in computer programming.
Recall that, by the Division Algorithm, given any two integers and , with , we can find integers and , with , such that . The number is called the quotient, and the number is called the remainder. The operation mod returns the value of the remainder . For example:
mod , since .
mod , since .
mod , since .
Observe that if mod , then we also have (mod ).