What is the difference between equality and equivalence?

39,230

Solution 1

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.

Solution 2

I take your question to be about math notation rather than programming. The triple equal sign you refer to can be written ≡ in HTML or \equiv in LaTeX.

a ≡ b most commonly means "a is defined to be b" or "let a be equal to b".

So 2+2=4 but φ ≡ (1+sqrt(5))/2.

Here's a handy equivalence table:

Mathematicians      Computer scientists
--------------      -------------------
      =                      ==
      ≡                      =

(The other answers about equivalence relations are correct too but I don't think those are as common. There's also a ≡ b (mod m) which is pronounced "a is congruent to b, mod m" and in programmer parlance would be expressed as mod(a,m) == mod(b,m). In other words, a and b are equal after mod'ing by m.)

Solution 3

A lot of languages distinguish between equality of the objects and equality of the values of those objects.

Ruby for example has 3 different ways to test equality. The first, equal?, compares two variables to see if they point to the same instance. This is equivalent in a C-style language of doing a check to see if 2 pointers refer to the same address. The second method, ==, tests value equality. So 3 == 3.0 would be true in this case. The third, eql?, compares both value and class type.

Lisp also has different concepts of equality depending on what you're trying to test.

Solution 4

In languages that I have seen that differentiate between equality and equivalence, equality usually means the type and value are the same while equivalence means that just the values are the same. For example:

int i = 3;
double d = 3.0;

i and d would be have an equivalence relationship since they represent the same value but not equality since they have different types. Other languages may have different ideas of equivalence (such as whether two variables represent the same object).

Solution 5

The answers above are right / partially right but they don't explain what the difference is exactly. In theoretical computer science (and probably in other branches of maths) it has to do with quantification over free variables of the logical equation (that is when we use the two notations at once).

For me the best ways to understand the difference is:

  1. By definition
    A ≡ B
    means
    For all possible values of free variables in A and B, A = B

    or

    A ≡ B <=> [A = B]

  2. By example
    x=2x
    iff (in fact iff is the same as ≡)
    x=0

    x ≡ 2x
    iff (because it is not the case that x = 2x for all possible values of x)
    False

I hope it helps

Edit:

Another thing that came to my head is the definitions of the two.

A = B is defined as A <= B and A >= B, where <= (smaller equal, not implies) can be any ordering relation

A ≡ B is defined as A <=> B (iff, if and only if, implies both sides), worth noting that implication is also an ordering relation and so it is possible (but less precise and often confusing) to use = instead of ≡.

I guess the conclusion is that when you see =, then you have to figure out the authors intention based on the context.

Share:
39,230
Tristan Havelick
Author by

Tristan Havelick

I'm a full-stack web software engineer My professional work currently centers around Python/React/PHP but in the past I've done a lot of Ruby and ASP/ASP.Net/C# stuff. I know a little of a ton of languages, and I'm currently honing managerial skills as well as getting better with front end tech.

Updated on October 24, 2020

Comments

  • Tristan Havelick
    Tristan Havelick over 3 years

    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?