In pure mathematics, modular arithmetic is one of the foundations of
number theory, touching on almost every aspect of its study, and it is also used extensively in
group theory,
ring theory,
knot theory, and
abstract algebra. In applied mathematics, it is used in
computer algebra,
cryptography,
computer science,
chemistry and the
visual and
musical arts. 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 the
CAS registry number (a unique identifying number for each chemical compound) is a
check 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 cryptography, modular arithmetic directly underpins
public key systems such as
RSA and
Diffie–Hellman, and provides
finite fields which underlie
elliptic curves, and is used in a variety of
symmetric key algorithms including
Advanced Encryption Standard (AES),
International Data Encryption Algorithm (IDEA), and
RC4. RSA and Diffie–Hellman use
modular exponentiation. In computer algebra, modular arithmetic is commonly used to limit the size of integer coefficients in intermediate calculations and data. It is used in
polynomial factorization, a problem for which all known efficient algorithms use modular arithmetic. It is used by the most efficient implementations of
polynomial greatest common divisor, exact
linear algebra and
Gröbner basis algorithms over the integers and the rational numbers. As posted on
Fidonet in the 1980s and archived at
Rosetta Code, modular arithmetic was used to disprove
Euler's sum of powers conjecture on a
Sinclair QL microcomputer using just one-fourth of the integer precision used by a
CDC 6600 supercomputer to disprove it two decades earlier via a
brute force search. In computer science, modular arithmetic is often applied in
bitwise operations and other operations involving fixed-width, cyclic
data structures. The modulo operation, as implemented in many
programming languages and
calculators, is an application of modular arithmetic that is often used in this context. The logical operator
XOR sums 2 bits, modulo 2. The use of
long division to turn a fraction into a
repeating decimal in any base
b is equivalent to modular multiplication of
b modulo the denominator. For example, for decimal,
b = 10. In music, arithmetic modulo 12 is used in the consideration of the system of
twelve-tone equal temperament, where
octave and
enharmonic 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 of
casting 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 the
Doomsday algorithm make heavy use of modulo-7 arithmetic. More generally, modular arithmetic also has application in disciplines such as
politics (for example,
apportionment),
economics (for example,
game theory) and other areas of the
social sciences, where
proportional division and allocation of resources plays a central part of the analysis. == Computational complexity ==