Difference between revisions of "Modular arithmetic"

(Arithmetic Modulo n)
(The Integers Modulo n)
Line 22: Line 22:
 
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
 
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>
+
<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>
  
 
=== Useful Facts ===
 
=== Useful Facts ===

Revision as of 01:35, 27 June 2006

Modular arithmetic is a special type of arithmetic that involves only integers. Given integers $a$, $b$, and $n$, with $n > 0$, we say that $a$ is congruent to $b$ modulo $n$, or $a \equiv b$ (mod $n$), if the difference ${a - b}$ is divisible by $n$.

For a given positive integer $n$, the relation $a \equiv b$ (mod $n$) is an equivalence relation on the set of integers. This relation gives rise to an algebraic structure called the integers modulo $n$ (usually known as "the integers mod $n$," or $\mathbb{Z}_n$ 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.


Arithmetic Modulo n

The Integers Modulo n

The relation $a \equiv b$ (mod $n$) allows us to divide the set of integers into sets of equivalent elements. For example, if $n = 3$, then the integers are divided into the following sets:

$\{ \ldots, -6, -3, 0, 3, 6, \ldots \}$

$\{ \ldots, -5, -2, 1, 4, 7, \ldots \}$

$\{ \ldots, -4, -1, 2, 5, 8, \ldots \}$

Notice that if we pick two numbers $a$ and $b$ from the same set, then $a$ and $b$ differ by a multiple of $3$, and therefore $a \equiv b$ (mod $3$).

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 $\overline{0}$ refers to the set containing $0$; that is, the set of all integer multiples of $3$. The symbol $\overline{1}$ refers to the second set listed above, and $\overline{2}$ the third. The symbol $\overline{3}$ refers to the same set as $\overline{0}$, and so on.

Instead of thinking of the objects $\overline{0}$, $\overline{1}$, and $\overline{2}$ 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 $3$, or $\mathbb{Z}_3$. More generally, if $n$ is a positive integer, then we can define

$\mathbb{Z}_n = \{\overline{0}, \overline{1}, \overline{2}, \ldots, \overline{n-1} \}$,

where for each $k$, $\overline{k}$ is defined by

$\overline{k} = \{ m \in \mathbb{Z} \mbox{ such that } m \equiv k \pmod{n} \}.$

Useful Facts

Consider four integers ${a},{b},{c},{d}$ and a positive integer ${m}$ such that $a\equiv b\pmod {m}$ and $c\equiv d\pmod {m}$. In modular arithmetic, the following identities hold:

  • Addition: $a+c\equiv b+d\pmod {m}$.
  • Subtraction: $a-c\equiv b-d\pmod {m}$.
  • Multiplication: $ac\equiv bd\pmod {m}$.
  • Division: $\frac{a}{e}\equiv \frac{b}{e}\pmod {\frac{m}{\gcd(m,e)}}$, where $e$ is a positive integer that divides ${a}$ and $b$.
  • Exponentiation: $a^e\equiv b^e\pmod {m}$ where $e$ is a positive integer.

Examples

  • ${7}\equiv {1} \pmod {2}$
  • $49^2\equiv 7^4\equiv (1)^4\equiv 1 \pmod {6}$
  • $7a\equiv 14\pmod {49}\implies a\equiv 2\pmod {7}$

Computation of Powers Mod n

The "exponentiation" property given above allows us to perform rapid calculations modulo $n$. Consider, for example, the problem

What are the tens and units digits of $7^{1942}$?

We could (in theory) solve this problem by trying to compute $7^{1942}$, 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 $100$. In other words, all of the information we need can be found using arithmetic mod $100$.

By writing down the first few powers of $7$, we see that $7^4 = 2401 \equiv 1$ (mod $100$). So for any positive integer $k$, we have $7^{4k} = (7^4)^k \equiv 1^k \equiv 1$ (mod $100$). In particular, we can write

$7^{1940} = 7^{4 \cdot 485} \equiv 1$ (mod $100$).

By the "multiplication" property above, then, it follows that

$7^{1942} = 7^{1940} \cdot 7^2 \equiv 1 \cdot 7^2 \equiv 49$ (mod $100$).

Therefore, by the definition of congruence, $7^{1942}$ differs from $49$ by a multiple of $100$. Since both integers are positive, this means that they share the same tens and units digits. Those digits are $4$ and $9$, respectively.

Intermediate

Divisibility Tests

Modular arithmetic is the basis for several well-known divisibility tests. Consider, for example, the test for divisibility by $9$:

Let $N$ be a positive integer. Then $N$ is divisible by $9$ if and only if the sum of the base-ten digits of $N$ is divisible by $9$.

Arithmetic mod $9$ can be used to give an easy proof of this criterion:

Suppose that the base-ten representation of $N$ is

$N = a_k a_{k-1} \cdots a_2 a_1 a_0$,

where $a_i$ is a digit for each $i$. Then the numerical value of $N$ is given by

$N = a_k \cdot 10^k + a_{k-1} \cdot 10^{k-1} + \cdots + a_1 \cdot 10^1 + a_0 \cdot 10^0$.

Now we know that, since $10 - 1 = 9$, we have $10 \equiv 1$ (mod $9$). So by the "exponentiation" property above, we have $10^j \equiv 1^j \equiv 1$ (mod $9$) for every $j$.

Therefore, by repeated uses of the "addition" and "multiplication" properties, we can write

$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$ (mod $9$).

Therefore, we have

$N \equiv a_k + a_{k-1} + \cdots + a_1 + a_0$ (mod $9$).

That is, $N$ differs from the sum of its digits by a multiple of $9$. It follows, then, that $N$ is a multiple of $9$ if and only if the sum of its digits is a multiple of $9$.

A virtually identical argument shows that a positive integer is divisible by $3$ if and only if the sum of its base-ten digits is divisible by $3$. We can also use the technique shown above to devise a test for divisibility by $11$.

Topics

See also

Miscellany

The binary operation "mod"

Related to the concept of congruence, mod $n$ is the binary operation $a$ mod $n$, which is used often in computer programming.

Recall that, by the Division Algorithm, given any two integers $a$ and $n$, with $n > 0$, we can find integers $q$ and $r$, with $0 \leq r < n$, such that $a = nq + r$. The number $q$ is called the quotient, and the number $r$ is called the remainder. The operation $a$ mod $n$ returns the value of the remainder $r$. For example:

$15$ mod $6 = 3$, since $15 = 6 \cdot 2 + 3$.

$35$ mod $7 = 0$, since $35 = 7 \cdot 5 + 0$.

$-10$ mod $8 = 6$, since $-10 = 8 \cdot -2 + 6$.

Observe that if $a$ mod $n = r$, then we also have $a \equiv r$ (mod $n$).