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.
Inmathematics,modular arithmetic is a system ofarithmetic operations forintegers, other than the usual ones from elementary arithmetic, where numbers "wrap around" when reaching a certain value, called themodulus. The modern approach tonumber theory using modular arithmetic was developed byCarl Friedrich Gauss in his bookDisquisitiones Arithmeticae, published in 1801.[1]
A familiar example of modular arithmetic is the hour hand on a12-hour clock. If the hour hand points to 7 now, then 8 hours later it will point to 3. Ordinary addition would result in7 + 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 iscongruent 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).
Given anintegerm ≥ 1, called amodulus, two integersa andb are said to becongruent modulom, ifm is adivisor of their difference; that is, if there is an integerk such that
The parentheses mean that(modm) applies to the entire equation, not just to the right-hand side (here,b).
This notation is not to be confused with the notationb modm (without parentheses), which refers to the remainder ofb when divided bym, known as themodulo operation: that is,b modm denotes the unique integerr such that0 ≤r <m andr ≡b (modm). Indeed, the expressionb modm does not appear in the statementa ≡b (modm), since it is parsed as
The congruence relation may be rewritten as
a =k m +b,
explicitly showing its relationship withEuclidean division. However, theb here need not be the remainder in the division ofa bym. Rather,a ≡b (modm) asserts thata andb have the sameremainder when divided bym. That is,
a =p m +r,
b =q m +r,
where0 ≤r <m is the common remainder. We recover the previous relation (a −b =k m) by subtracting these two expressions and settingk =p −q.
Because the congruence modulom is defined by thedivisibility bym and because−1 is aunit in the ring of integers, a number is divisible by−m exactly if it is divisible bym.This means that every non-zero integerm may be taken as a modulus.
Existence: There exists an integer denoteda−1 such thataa−1 ≡ 1 (modm) if and only ifa is coprime withm. This integera−1 is called amodular multiplicative inverse ofa modulom.
Ifa ≡b (modm) anda−1 exists, thena−1 ≡b−1 (modm) (compatibility with multiplicative inverse, and, ifa =b, uniqueness modulom).
Ifax ≡b (modm) anda is coprime tom, then the solution to this linear congruence is given byx ≡a−1b (modm).
In particular, ifp is a prime number, thena is coprime withp for everya such that0 <a <p; thus a multiplicative inverse exists for alla that is not congruent to zero modulop.
A simple consequence of Fermat's little theorem is that ifp is prime, thena−1 ≡ap−2 (modp) is the multiplicative inverse of0 <a <p. More generally, from Euler's theorem, ifa andm are coprime, thena−1 ≡aφ(m)−1 (modm). Hence, ifax ≡1 (modm), thenx ≡aφ(m)−1 (modm).
Another simple consequence is that ifa ≡b (modφ(m)), whereφ is Euler's totient function, thenka ≡kb (modm) providedk iscoprime withm.
Chinese remainder theorem: For anya,b and coprimem,n, there exists a uniquex (modmn) such thatx ≡a (modm) andx ≡b (modn). In fact,x ≡b mn−1m +a nm−1n (modmn) wheremn−1 is the inverse ofm modulon andnm−1 is the inverse ofn modulom.
Lagrange's theorem: Ifp is prime andf (x) =a0xd + ... +ad is apolynomial with integer coefficients such thatp is not a divisor ofa0, then the congruencef (x) ≡ 0 (modp) has at mostd non-congruent solutions.
Primitive root modulom: A numberg is a primitive root modulom if, for every integera coprime tom, there is an integerk such thatgk ≡a (modm). A primitive root modulom exists if and only ifm is equal to2, 4,pk or 2pk, wherep is an odd prime number andk is a positive integer. If a primitive root modulom exists, then there are exactlyφ(φ(m)) such primitive roots, whereφ is the Euler's totient function.
Quadratic residue: An integera is a quadratic residue modulom, if there exists an integerx such thatx2 ≡a (modm).Euler's criterion asserts that, ifp is an odd prime, anda is not a multiple ofp, thena is a quadratic residue modulop if and only if
The congruence relation is anequivalence relation. Theequivalence class modulom of an integera is the set of all integers of the forma +k m, wherek is any integer. It is called thecongruence class orresidue class ofa modulo m, and may be denoted(a modm), or asa or[a] when the modulusm is known from the context.
Each residue class modulo m contains exactly one integer in the range. Thus, these integers arerepresentatives of their respective residue classes.
It is generally easier to work with integers than sets of integers; that is, the representatives most often considered, rather than their residue classes.
Consequently,(a modm) denotes generally the unique integerr such that0 ≤r <m andr ≡a (modm); it is called theresidue ofa modulo m.
In particular,(a modm) = (b modm) is equivalent toa ≡b (modm), and this explains why "=" is often used instead of "≡" in this context.
Each residue class modulom may be represented by any one of its members, although we usually represent each residue class by the smallest nonnegative integer which belongs to that class[3] (since this is the proper remainder which results from division). Any two members of different residue classes modulom are incongruent modulom. Furthermore, every integer belongs to one and only one residue class modulom.[4]
The set of integers{0, 1, 2, ...,m − 1} is called theleast residue system modulom. Any set ofm integers, no two of which are congruent modulom, is called acomplete residue system modulom.
The least residue system is a complete residue system, and a complete residue system is simply a set containing precisely onerepresentative of each residue class modulom.[5] For example, the least residue system modulo4 is{0, 1, 2, 3}. Some other complete residue systems modulo4 include:
{1, 2, 3, 4}
{13, 14, 15, 16}
{−2, −1, 0, 1}
{−13, 4, 17, 18}
{−5, 0, 6, 21}
{27, 32, 37, 42}
Some sets that arenot complete residue systems modulo 4 are:
{−5, 0, 6, 22}, since6 is congruent to22 modulo4.
{5, 15}, since a complete residue system modulo4 must have exactly4 incongruent residue classes.
Given theEuler's totient functionφ(m), any set ofφ(m) integers that arerelatively prime tom and mutually incongruent under modulusm is called areduced residue system modulom.[6] The set{5, 15} from above, for example, is an instance of a reduced residue system modulo 4.
In the context of this paragraph, the modulusm is almost always taken as positive.
The set of allcongruence classes modulom is aring called thering of integers modulom, and is denoted,, or.[7] The ring is fundamental to various branches of mathematics (see§ Applications below).(In some parts ofnumber theory the notation is avoided because it can be confused with the set ofm-adic integers.)
Addition, subtraction, and multiplication are defined on by the following rules:
The properties given before imply that, with these operations, is acommutative ring. For example, in the ring, one has
as in the arithmetic for the 24-hour clock.
The notation is used because this ring is thequotient ring of by theideal, the set formed by all multiples ofm, that is, all numbersk m with
Under addition, is acyclic group. All finite cyclic groups are isomorphic with for somem.[8]
The ring of integers modulom is afield; that is, every nonzero element has amultiplicative inverse, if and only ifm isprime. Ifm =pk is aprime power withk > 1, there exists a unique (up to isomorphism) finite field withm elements, which isnot isomorphic to, which fails to be a field because it haszero-divisors.
A very practical application is to calculate checksums within serial number identifiers. For example,International Standard Book Number (ISBN) uses modulo 11 (for 10-digit ISBN) or modulo 10 (for 13-digit ISBN) arithmetic for error detection. Likewise,International Bank Account Numbers (IBANs) use modulo 97 arithmetic to spot user input errors in bank account numbers. In chemistry, the last digit of theCAS registry number (a unique identifying number for each chemical compound) is acheck digit, which is calculated by taking the last digit of the first two parts of the CAS registry number times 1, the previous digit times 2, the previous digit times 3 etc., adding all these up and computing the sum modulo 10.
In computer science, modular arithmetic is often applied inbitwise operations and other operations involving fixed-width, cyclicdata structures. The modulo operation, as implemented in manyprogramming languages andcalculators, is an application of modular arithmetic that is often used in this context. The logical operatorXOR sums 2 bits, modulo 2.
The use oflong division to turn a fraction into arepeating decimal in any baseb is equivalent to modular multiplication ofb modulo the denominator. For example, for decimal,b = 10.
In music, arithmetic modulo 12 is used in the consideration of the system oftwelve-tone equal temperament, whereoctave andenharmonic equivalency occurs (that is, pitches in a 1:2 or 2:1 ratio are equivalent, and C-sharp is considered the same as D-flat).
The method ofcasting out nines offers a quick check of decimal arithmetic computations performed by hand. It is based on modular arithmetic modulo 9, and specifically on the crucial property that 10 ≡ 1 (mod 9).
Arithmetic modulo 7 is used in algorithms that determine the day of the week for a given date. In particular,Zeller's congruence and theDoomsday algorithm make heavy use of modulo-7 arithmetic.
More generally, modular arithmetic also has application in disciplines such aspolitics (for example,apportionment),economics (for example,game theory) and other areas of thesocial sciences, whereproportional division and allocation of resources plays a central part of the analysis.
Since modular arithmetic has such a wide range of applications, it is important to know how hard it is to solve a system of congruences. A linear system of congruences can be solved inpolynomial time with a form ofGaussian elimination, for details seelinear congruence theorem. Algorithms, such asMontgomery reduction, also exist to allow simple arithmetic operations, such as multiplication andexponentiation modulo m, to be performed efficiently on large numbers.
Apostol, Tom M. (1976),Introduction to analytic number theory, Undergraduate Texts in Mathematics, New York-Heidelberg: Springer-Verlag,ISBN978-0-387-90163-3,MR0434929,Zbl0335.10001. See in particular chapters 5 and 6 for a review of basic modular arithmetic.