What is the difference between equality and equivalence?

后端 未结 9 737
难免孤独
难免孤独 2020-12-13 07:08

I\'ve read a few instances in reading mathematics and computer science that use the equivalence symbol , (basically an \'=\' with three lines)

相关标签:
9条回答
  • 2020-12-13 07:16

    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.

    0 讨论(0)
  • 2020-12-13 07:16

    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.

    0 讨论(0)
  • 2020-12-13 07:17

    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 )

    0 讨论(0)
  • 2020-12-13 07:23

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

    0 讨论(0)
  • 2020-12-13 07:29

    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.

    0 讨论(0)
  • 2020-12-13 07:33

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

    0 讨论(0)
提交回复
热议问题