Thursday, March 3, 2011

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?

From stackoverflow
  • 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).

  • w:

    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 CaseInsentiveitveString {
    ...
     // broken
     @Override public boolean equals(Object o) {
      if (o instance of CaseInsentiveitveString)
       return s.equalsIgnoreCase(
        ((CaseInsentiveitveString) o).s);
      if (o instanceof String) // One-way interoperability!
       return s.equalsIgnoreCase((String) o);
      return false;
     }
    ... 
    
    }
    

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

  • You could have two statements that have the same truth value (equivalent) or two statements that are the same (equality). As well the "equal sign with three bars" can also mean "is defined as."

    Mitch Wheat : I always read 3 bars as 'equivalent to'. I would use ':=' to mean 'defined as'.
  • Take it outside the realm of programming.

    • (31) equal -- (having the same quantity, value, or measure as another; "on equal terms"; "all men are equal before the law")

    • equivalent, tantamount -- (being essentially equal to something; "it was as good as gold"; "a wish that was equivalent to a command"; "his statement was tantamount to an admission of guilt"

    At least in my dictionary, 'equivelance' means its a good-enough subsitute for the original, but not necessarily identical, and likewise 'equality' conveys complete identical.

    null == 0   # true , null is equivelant to 0 ( in php ) 
    null === 0  # false, null is not equal to 0 ( in php )
    

    ( Some people use ≈ to represent nonidentical values instead )

  • 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.

  • The difference resides above all in the level at which the two concepts are introduced. '≡' is a symbol of formal logic where, given two propositions a and b, a ≡ b means (a => b AND b => a).

    '=' is instead the typical example of an equivalence relation on a set, and presumes at least a theory of sets. When one defines a particular set, usually he provides it with a suitable notion of equality, which comes in the form of an equivalence relation and uses the symbol '='. For example, when you define the set Q of the rational numbers, you define equality a/b = c/d (where a/b and c/d are rational) if and only if ad = bc (where ad and bc are integers, the notion of equality for integers having already been defined elsewhere).

    Sometimes you will find the informal notation f(x) ≡ g(x), where f and g are functions: It means that f and g have the same domain and that f(x) = g(x) for each x in such domain (this is again an equivalence relation). Finally, sometimes you find ≡ (or ~) as a generic symbol to denote an equivalence relation.

  • Equality really is a special kind of equivalence relation, in fact. Consider what it means to say:

    0.9999999999999999... = 1
    

    That suggests that equality is just an equivalence relation on "string numbers" (which are defined more formally as functions from Z -> {0,...,9}). And we can see from this case, the equivalence classes are not even singletons.

  • 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.)


    PS: HTML rendering bug! The following table shows up nicely in the preview but doesn't render as a table after I submit it.

    Mathematicians   Computer scientists = == ≡ =
    Stephen Brown : This is over a year late, but I found this post useful. Thanks!

0 comments:

Post a Comment