Remark. Equivalence classes and canonical representatives [00E4]
The previous theorem was a bit more work to prove, but it is an extremely useful characterization of modular equivalence.
In general, suppose we have a relation \sim on a set A, and a function c : A \to B such that a \sim b if and only if c(a) = c(b). This means that \sim is automatically an equivalence relation, and we say that the function c computes a canonical representative for each equivalence class of \sim . (Technically, the equivalence relation \sim is known as the kernel of the function c.) From a computational point of view, this is fantastic: given any two elements a,b \in A, we can easily check whether they are equivalent, simply by computing c(a) and c(b) and checking whether the resulting representatives are equal.
Many of the equivalence relations we have studied can be characterized in this way.
- For example, the relation on words by length (where two English words are related if they have the same number of letters) is of course characterized by the \mathit {length} function.
- Case-insensitive equality can be characterized by the function that returns the all-lowercase version of a string (or, alternatively, all-uppercase): two strings are equivalent iff their all-lowercase versions are equal. Of course, this is exactly how case-insensitive comparison is usually implemented.
- The equivalence that relates lists with the same elements but different orders can be characterized by sorting: two lists are equivalent iff their sorted versions are equal.
- Finally, the previous theorem shows that \equiv _m is likewise characterized by canonical representatives for each equivalence class: given some a \in Z, the canonical representative for a is a \mathbin {\mathbf {mod}} m, and the theorem indeed says that two numbers a and b are equivalent modulo m if and only if a \mathbin {\mathbf {mod}} m = b \mathbin {\mathbf {mod}} m. For example, one of the equivalence classes of \equiv _4 is \{\dotsm -7, -3, 1, 5, 9, 13, \dots \}, and 1 is the canonical representative of this equivalence class: any two numbers in this equivalence class result in 1 when we compute their remainder modulo 4. For example, -3 \mathbin {\mathbf {mod}} 4 = 1, 5 \mathbin {\mathbf {mod}} 4 = 1, 9 \mathbin {\mathbf {mod}} 4 = 1, and so on.
Note, however, that not all equivalence relations can be characterized in this way! For example, \leftrightarrow is an equivalence relation on propositions, but there is no function f we can use to compute whether P \leftrightarrow Q just by checking whether f(P) = f(Q); in general it can be difficult to figure out whether P \leftrightarrow Q.