Modular Arithmetic - Remainders

Remainders

The notion of modular arithmetic is related to that of the remainder in division. The operation of finding the remainder is sometimes referred to as the modulo operation and we may see 2 = 14 (mod 12). The difference is in the use of congruency, indicated by "≡", and equality indicated by "=". Equality implies specifically the "common residue", the least non-negative member of an equivalence class. When working with modular arithmetic, each equivalence class is usually represented by its common residue, for example 38 ≡ 2 (mod 12) which can be found using long division. It follows that, while it is correct to say 38 ≡ 14 (mod 12), and 2 ≡ 14 (mod 12), it is incorrect to say 38 = 14 (mod 12) (with "=" rather than "≡").

The difference is clearest when dividing a negative number, since in that case remainders are negative. Hence to express the remainder we would have to write −5 ≡ −17 (mod 12), rather than 7 = −17 (mod 12), since equivalence can only be said of common residues with the same sign.

In computer science, it is the remainder operator that is usually indicated by either "%" (e.g. in C, Java, Javascript, Perl and Python) or "mod" (e.g. in Pascal, BASIC, SQL, Haskell), with exceptions (e.g. Excel). These operators are commonly pronounced as "mod", but it is specifically a remainder that is computed (since in C++ a negative number will be returned if the first argument is negative, and in Python a negative number will be returned if the second argument is negative). The function modulo instead of mod, like 38 ≡ 14 (modulo 12) is sometimes used to indicate the common residue rather than a remainder (e.g. in Ruby). For details of the specific operations defined in different languages, see the modulo operation page.

Parentheses are sometimes dropped from the expression, e.g. 38 ≡ 14 mod 12 or 2 = 14 mod 12, or placed around the divisor e.g. 38 ≡ 14 mod (12). Notation such as 38(mod 12) has also been observed, but is ambiguous without contextual clarification.

Read more about this topic:  Modular Arithmetic