Difference between revisions of "Modular arithmetic/Intermediate"
(Moved "a word of caution" to its proper home.) |
m (→Arithmetic Modulo m) |
||
(17 intermediate revisions by 10 users not shown) | |||
Line 9: | Line 9: | ||
=== Useful Facts === | === Useful Facts === | ||
− | Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{ | + | Consider four integers <math>{a},{b},{c},{d}</math> and a positive integer <math>{n}</math> such that <math>a\equiv b\pmod {n}</math> and <math>c\equiv d\pmod {n}</math>. In modular arithmetic, the following [[identity | identities]] hold: |
− | * Addition: <math>a+c\equiv b+d\pmod { | + | * Addition: <math>a+c\equiv b+d\pmod {n}</math>. |
− | * Subtraction: <math>a-c\equiv b-d\pmod { | + | * Subtraction: <math>a-c\equiv b-d\pmod {n}</math>. |
− | * Multiplication: <math>ac\equiv bd\pmod { | + | * Multiplication: <math>ac\equiv bd\pmod {n}</math>. |
− | * Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{ | + | * Division: <math>\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{n}{\gcd(n,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 { | + | * Exponentiation: <math>a^e\equiv b^e\pmod {n}</math> where <math>e</math> is a positive integer. |
For examples, see [[Introduction to modular arithmetic]]. | For examples, see [[Introduction to modular arithmetic]]. | ||
Line 22: | Line 22: | ||
=== The Integers Modulo n === | === The Integers Modulo n === | ||
− | The relation <math>a \equiv b | + | The relation <math>a \equiv b \pmod{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, -6, -3, 0, 3, 6, \ldots \}</math> | ||
Line 30: | Line 30: | ||
<math>\{ \ldots, -4, -1, 2, 5, 8, \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 | + | 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 \pmod{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. | 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. | ||
Line 123: | Line 123: | ||
The following topics expand on the flexible nature of modular arithmetic as a problem solving tool: | The following topics expand on the flexible nature of modular arithmetic as a problem solving tool: | ||
* [[Fermat's Little Theorem]] | * [[Fermat's Little Theorem]] | ||
+ | * [[Euler's Totient Function]] | ||
* [[Euler's Totient Theorem]] | * [[Euler's Totient Theorem]] | ||
− | * [[ | + | * [[Chicken McNugget Theorem]] |
− | + | == Miscellaneous == | |
− | |||
− | == | ||
=== The binary operation "mod" === | === The binary operation "mod" === | ||
Line 157: | Line 156: | ||
<math>E=e_1e_2e_3e_4e_5e_6e_7e_8e_9</math>, | <math>E=e_1e_2e_3e_4e_5e_6e_7e_8e_9</math>, | ||
− | another nine-digit positive integer with the property that each digit | + | another nine-digit positive integer with the property that each digit <math>e_i</math> when substituted for <math>d_i</math> makes the |
modified D divisible by 7. Let | modified D divisible by 7. Let | ||
<math>F=f_1f_2f_3f_4f_5f_6f_7f_8f_9</math> be a third nine-digit positive integer with the same relation to E as E has to D. | <math>F=f_1f_2f_3f_4f_5f_6f_7f_8f_9</math> be a third nine-digit positive integer with the same relation to E as E has to D. | ||
− | Prove that every <math> | + | Prove that every <math>d_i - f_i</math> is divisible by 7. |
Line 171: | Line 170: | ||
Since '''10=3 mod 7''', and since it holds that if '''a=b mod c''' then <math>a^n=b^n</math> '''mod c''', then D can be expressed much more simply mod 7; that is, | Since '''10=3 mod 7''', and since it holds that if '''a=b mod c''' then <math>a^n=b^n</math> '''mod c''', then D can be expressed much more simply mod 7; that is, | ||
− | <math>D= | + | <math>D= 2d_1 +3d_2 +1d_3 -2d_4 -3d_5 -d_6 +2d_7 +3d_8 +d_9 </math>= '''x mod 7'''. |
Each number in E must make the modified D equal 0 mod 7, so for each <math>d_i</math>, <math>e_i = \frac{x+7k}{c}-d_i</math>, where c is the coefficient of <math>d_i</math> | Each number in E must make the modified D equal 0 mod 7, so for each <math>d_i</math>, <math>e_i = \frac{x+7k}{c}-d_i</math>, where c is the coefficient of <math>d_i</math> | ||
Line 180: | Line 179: | ||
Then <math>E= 2e_1 +3e_2 +1e_3 -2e_4 -3e_5 -e_6 +2e_7 +3e_8 +e_9</math> '''mod 7''' can be expressed | Then <math>E= 2e_1 +3e_2 +1e_3 -2e_4 -3e_5 -e_6 +2e_7 +3e_8 +e_9</math> '''mod 7''' can be expressed | ||
<math>E= (x-2d_1)+(x-3d_2)+(x-d_3)+...+(x-d_9) = (9x)-D</math> '''mod 7 = (9x)- x = 8x = x mod 7'''. | <math>E= (x-2d_1)+(x-3d_2)+(x-d_3)+...+(x-d_9) = (9x)-D</math> '''mod 7 = (9x)- x = 8x = x mod 7'''. | ||
− | ( | + | (Note that the 7s, which do not change the mod value, have been eliminated.) |
Each number in F must make the modified E equal '''0 mod 7''', so for each <math>e_i</math>, <math>f_i = \frac{x+7k_2}{c_i} -e_i = \frac{x+7k_2}{c_i} - (\frac{x+7k_1}{c_i} -d_i)</math>. | Each number in F must make the modified E equal '''0 mod 7''', so for each <math>e_i</math>, <math>f_i = \frac{x+7k_2}{c_i} -e_i = \frac{x+7k_2}{c_i} - (\frac{x+7k_1}{c_i} -d_i)</math>. | ||
Line 191: | Line 190: | ||
Let <math>A=\frac{k_2-k_1}{c_i}</math> then <math>d_i - f_i =</math> '''7A mod 7 = 0 mod 7''' for all <math>(d_i,f_i)</math>, QED. | Let <math>A=\frac{k_2-k_1}{c_i}</math> then <math>d_i - f_i =</math> '''7A mod 7 = 0 mod 7''' for all <math>(d_i,f_i)</math>, QED. | ||
− | |||
− | |||
== Resources == | == Resources == | ||
Line 203: | Line 200: | ||
* [[Introduction to modular arithmetic]] | * [[Introduction to modular arithmetic]] | ||
* [[Olympiad modular arithmetic]] | * [[Olympiad modular arithmetic]] | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | [[Category:Intermediate Mathematics Topics]] |
Latest revision as of 18:01, 29 October 2021
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
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.
For examples, see Introduction to modular arithmetic.
The Integers Modulo n
The relation 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
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
,
where for each , is defined by
Addition, Subtraction, and Multiplication Mod n
We define addition, subtraction, and multiplication in according to the following rules:
for all . (Addition)
for all . (Subtraction)
for all . (Multiplication)
So for example, if , then we have
Notice that, in each case, we reduce to an answer of the form , where . 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, ) possible values. (Some people find it useful to reduce an answer such as to , which is negative but has a smaller absolute value.)
A Word of Caution
Because of the way we define operations in , it is important to check that these operations are well-defined. This is because each of the sets that make up contains many different numbers, and therefore has many different names. For example, observe that in , we have and . It is reasonable to expect that if we perform the addition , we should get the same answer as if we compute , since we are simply using different names for the same objects. Indeed, the first addition yields the sum , 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.
Algebraic Properties of the Integers Mod n
The integers modulo form an algebraic structure called a ring -- a structure in which we can add, subtract, and multiply elements.
Anyone who has taken a high school algebra class is familiar with several examples of rings, including the ring of integers, the ring of rational numbers, and the ring of real numbers. The ring has some algebraic features that make it quite different from the more familiar rings listed above.
First of all, notice that if we choose a nonzero element of , and add copies of this element, we get
,
since is a multiple of . So it is possible to add several copies of a nonzero element of and get zero. This phenomenon, which is called torsion, does not occur in the reals, the rationals, or the integers.
Another curious feature of is that a polynomial over can have a number of roots greater than its degree. Consider, for example, the polynomial congruence
.
We might be tempted to solve this congruence by factoring the expression on the left:
.
Indeed, this factorization yields two solutions to the congruence: , and . (Note that two values of that are congruent modulo are considered the same solution.)
However, since , the original congruence is equivalent to
.
This time, factoring the expression on the left yields
.
And we find that there are two more solutions! The values and both solve the congruence. So our congruence has at least four solutions -- two more than we might expect based on the degree of the polynomial.
Why do the "rules" of algebra that work so well for the real numbers seem to fail in ? To understand this, let's take a closer look at the congruence
.
If we were solving this as an equation over the reals, we would immediately conclude that either must be zero, or must be zero in order for the product to equal zero. However, this is not the case in ! It is possible to multiply two nonzero elements of and get zero. For example, we have
But wait! Suppose we take a close look at this last product, and we set and . Then we have -- another of the solutions of our congruence! (One can check that the other two factorizations don't lead to any valid solutions; however, there are many other factorizations of zero that need to be checked.)
In the ring of real numbers, it is a well-known fact that if , then or . For this reason, we call the ring of real numbers a domain. However, a similar fact does not apply in general in ; therefore, is not in general a domain.
Topics
The following topics expand on the flexible nature of modular arithmetic as a problem solving tool:
Miscellaneous
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 ).
An example exercise with modular arithmetic:
Problem:
Let
be a nine-digit positive integer (each digit not necessarily distinct). Consider
,
another nine-digit positive integer with the property that each digit when substituted for makes the modified D divisible by 7. Let
be a third nine-digit positive integer with the same relation to E as E has to D.
Prove that every is divisible by 7.
Solution:
Any positive integer can be expressed .
Since 10=3 mod 7, and since it holds that if a=b mod c then mod c, then D can be expressed much more simply mod 7; that is, = x mod 7.
Each number in E must make the modified D equal 0 mod 7, so for each , , where c is the coefficient of and k is an element of {-2,-1,0,1,2}. The patient reader should feel free to verify that this makes D = 0 mod 7.
In terms of terms, then, we find each .
Then mod 7 can be expressed mod 7 = (9x)- x = 8x = x mod 7. (Note that the 7s, which do not change the mod value, have been eliminated.)
Each number in F must make the modified E equal 0 mod 7, so for each , .
By design and selection of k, all are integers, and is always an integer because it is the difference of two integers.
is a member of the set {1, 2, 3}. Since no divides 7, 7 may be factored and is the product of two integers.
Let then 7A mod 7 = 0 mod 7 for all , QED.
Resources