Search code examples
mathcomputer-sciencesymbols

What is the difference between equality and equivalence?


I've read a few instances in reading mathematics and computer science that use the equivalence symbol , (basically an '=' with three lines) and it always makes sense to me to read this as if it were equality. What is the difference between these two concepts?


Solution

  • Wikipedia: Equivalence relation:

    In mathematics, an equivalence relation is a binary relation between two elements of a set which groups them together as being "equivalent" in some way. Let a, b, and c be arbitrary elements of some set X. Then "a ~ b" or "a ≡ b" denotes that a is equivalent to b.

    An equivalence relation "~" is reflexive, symmetric, and transitive.

    In other words, = is just an instance of equivalence relation.

    Edit: This seemingly simple criteria of being reflexive, symmetric, and transitive are not always trivial. See Bloch's Effective Java 2nd ed p. 35 for example,

    public final class CaseInsensitiveString {
    ...
        // broken
        @Override public boolean equals(Object o) {
            if (o instance of CaseInsensitiveString)
                return s.equalsIgnoreCase(
                    ((CaseInsensitiveString) o).s);
            if (o instanceof String) // One-way interoperability!
                return s.equalsIgnoreCase((String) o);
            return false;
        }  
    }
    

    The above equals implementation breaks the symmetry because CaseInsensitiveString knows about String class, but the String class doesn't know about CaseInsensitiveString.