Modular arithmetic

Computation modulo a fixed integer From Wikipedia, the free encyclopedia

Modular arithmetic

In mathematics, modular arithmetic is a system of arithmetic operations for integers, other than the usual ones from elementary arithmetic, where numbers "wrap around" when reaching a certain value, called the modulus. The modern approach to modular arithmetic was developed by Carl Friedrich Gauss in his book Disquisitiones Arithmeticae, published in 1801.

Thumb
Time-keeping on this clock uses arithmetic modulo 12. Adding 4 hours to 9 o'clock gives 1 o'clock, since 13 is congruent to 1 modulo 12.

A familiar example of modular arithmetic is the hour hand on a 12-hour clock. If the hour hand points to 7 now, then 8 hours later it will point to 3. Ordinary addition would result in 7 + 8 = 15, but 15 reads as 3 on the clock face. This is because the hour hand makes one rotation every 12 hours and the hour number starts over when the hour hand passes 12. We say that 15 is congruent to 3 modulo 12, written 15 3 (mod 12), so that 7 + 8 3 (mod 12).

Similarly, if one starts at 12 and waits 8 hours, the hour hand will be at 8. If one instead waited twice as long, 16 hours, the hour hand would be on 4. This can be written as 2 × 8 4 (mod 12). Note that after a wait of exactly 12 hours, the hour hand will always be right where it was before, so 12 acts the same as zero, thus 12 0 (mod 12).

Congruence

Summarize
Perspective

Given an integer m ≥ 1, called a modulus, two integers a and b are said to be congruent modulo m, if m is a divisor of their difference; that is, if there is an integer k such that

ab = k m.

Congruence modulo m is a congruence relation, meaning that it is an equivalence relation that is compatible with addition, subtraction, and multiplication. Congruence modulo m is denoted by

ab (mod m).

The parentheses mean that (mod m) applies to the entire equation, not just to the right-hand side (here, b).

This notation is not to be confused with the notation b mod m (without parentheses), which refers to the remainder of b when divided by m, known as the modulo operation: that is, b mod m denotes the unique integer r such that 0 ≤ r < m and rb (mod m).

The congruence relation may be rewritten as

a = k m + b,

explicitly showing its relationship with Euclidean division. However, the b here need not be the remainder in the division of a by m. Rather, ab (mod m) asserts that a and b have the same remainder when divided by m. That is,

a = p m + r,
b = q m + r,

where 0 ≤ r < m is the common remainder. We recover the previous relation (ab = k m) by subtracting these two expressions and setting k = pq.

Because the congruence modulo m is defined by the divisibility by m and because −1 is a unit in the ring of integers, a number is divisible by m exactly if it is divisible by m. This means that every non-zero integer m may be taken as modulus.

Examples

In modulus 12, one can assert that:

38 ≡ 14 (mod 12)

because the difference is 38 − 14 = 24 = 2 × 12, a multiple of 12. Equivalently, 38 and 14 have the same remainder 2 when divided by 12.

The definition of congruence also applies to negative values. For example:

Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.