What is the difference between equality and equivalence?
Asked Answered
L

10

40

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?

Linolinocut answered 23/11, 2008 at 0:9 Comment(3)
I'd love to leave the snarky answer "equality == equivalence", but that evaluates to false, so I know it would just get down-voted into oblivion. :)Bettinabettine
Smalltalk distinguishes between those 2: Equivalence (==) is the test of whether two objects are the same object. Equality (=) is the test of whether two objects represent the same component. (Source: Smalltalk-80 Bluebook, page 96, Comparing Objects)Sunday
This is a great question, but I think it's too general - I would have to be tackled for mathematics and formal logic separately, then for every programming language that distinguishes between the two... And sometimes they call it differently, for example "equality" and "identity" or something. E.g. for C++ - reddit.com/r/cpp_questions/comments/47k4gj/… - equivalence has no "operator" in the language, but it is a concept of being neither < nor > in some ordering (built-in or custom). A useful term for sorting stability and such behaviors of algorithms.Mithridate
T
20

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.

Tinytinya answered 23/11, 2008 at 0:17 Comment(0)
O
18

I take your question to be about math notation rather than programming. The triple equal sign you refer to can be written &equiv; 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.)

Oberammergau answered 2/12, 2008 at 5:39 Comment(3)
"a ≡ b" is NOT used for "a is defined to be b" --- not in mathematics. "≡" means "identically equal to", for example "f(x) ≡ 0" means that the equality "f(x) = 0" holds for any x. For comparison, "f(x) = 0" is an equation, one could find its solutions...Varicocele
The notation listed under "computer scienctists" is NOT common in computer science in general. It is only used in programming languages.Ambages
−1. The only true answer to what ≡ means is: “Go and look what the definition in your case says.” It can mean far too many different things. A text that uses it and does not explain it is incorrect.Detection
C
15

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.

Commonly answered 23/11, 2008 at 0:29 Comment(1)
+1 This is a good pragmatic description for programmers. Equality means "a is b". Equivalence means "a is like b".Chook
G
8

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

Gloriole answered 23/11, 2008 at 0:17 Comment(0)
C
8

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.

Chantay answered 1/8, 2012 at 9:10 Comment(0)
R
4

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 )

Roxanneroxburgh answered 23/11, 2008 at 0:28 Comment(0)
T
4

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.

Transatlantic answered 23/11, 2008 at 1:30 Comment(0)
D
4

The first problem is, what equality and equivalence mean in this case? Essentially, contexts are quite free to define these terms.

The general tenor I got from various definitions is: For values called equal, it should make no difference which one you read from.

The grossest example that violates this expectation is C++: x and y are said to be equal if x == y evaluates to true, and x and y are said to be equivalent if !(x < y) && !(y < x). Even apart from user-defined overloads of these operators, for floating-point numbers (float, double) those are not the same: All NaN values are equivalent to each other (in fact, equivalent to everything), but not equal to anything including themselves, and the values -0.0 and +0.0 compare equal (and equivalent) although you can distinguish them if you’re clever.

In a lot of cases, you’d need better terms to convey your intent precisely. Given two variables x and y,

  • identity or “the same” for expressing that there is only one object and x and y refer to it. Any change done through x is inadvertantly observable through y and vice versa. In Java, reference type variables are checked for identity using ==, in C# using the ReferenceEquals method. In C++, if x and y are references, std::addressof(x) == std::addressof(y) will do (whereas &x == &y will work most of the time, but & can be customized for user-defined types).
  • bitwise or structure equality for expressing that the internal representations of x and y are the same. Notice that bitwise equality breaks down when objects can reference (parts of) themselves internally. To get the intended meaning, the notion has to be refined in such cases to say: Structured the same. In D, bitwise equality is checked via is and C offers memcmp. I know of no language that has built-in structure equality testing.
  • indistinguishability or substitutability for expressing that values cannot be distinguished (through their public interface): If a function f takes two parameters and x and y are indistinguishable, the calls f(x, y), f(x, x), and f(y, y) always return indistinguishable values – unless f checks for identity (see bullet point above) directly or maybe by mutating the parameters. An example could be two search-trees that happen to contain indistinguishable elements, but the internal trees are layed-out differently. The internal tree layout is an implementation detail that normally cannot be observed through its public methods.
    This is also called Leibniz-equality after Gottfried Wilhelm Leibniz who defined equality as the lack of differences.
  • equivalence for expressing that objects represent values considered essentially the same from some abstract reasoning. For an example for distinguishable equivalent values, observe that floating-point numbers have a negative zero -0.0 distinct from +0.0, and e.g. sign(1/x) is different for -0.0 and +0.0. Equivalence for floating-point numbers is checked using == in many languages with C-like syntax (aka. Algol syntax). Most object-oriented languages check equivalence of objects using an equals (or similarly named) method. C# has the IEquatable<T> interface to designate that the class has a standard/canonical/default equivalence relation defined on it. In Java, one overrides the equals method every class inherits from Object.

As you can see, the notions become increasingly vague. Checking for identity is something most languages can express. Identity and bitwise equality usually cannot be hooked by the programmer as the notions are independent from interpretations. There was a C++20 proposal, which ended up being rejected, that would have introduced the last two notions as strong† and weak equality†. († Not online anymore, 404.) The original paper is here.

There are languages without mutation, primarily functional languages like Haskell. The difference between equality and equivalence there is less of an issue and tilts to the mathematical use of those words. (In math, generally speaking, (recursively defined) sequences are used instead of re-assignments.)

Everything C has, is also available to C++ and any language that can use C functionality. Everything said about C# is true for Visual Basic .NET and probably all languages built on the .NET framework. Analogously, Java represents the JRE languages that also include Kotlin and Scala.

If you just want stupid definitions without wisdom: An equivalence relation is a reflexive, symmetrical, and transitive binary relation on a set. Equality then is the intersection of all those equivalence relations.

Detection answered 12/4, 2022 at 14:10 Comment(2)
"Equality then is the intersection of all those equivalence relations." Better to call that identity, because some people use the word equality to include equivalence relations. And the formal set theoretic definition for equivalence relation is not 'stupid', it's quite elegant for set theoretic purposes, e.g. 'everything is a set'.Ferule
By ‘stupid’, I meant that the paragraph puts facts that you can put on a presentation slide, but it includes no rationale, no explanation and not even a motivating example.Detection
E
2

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

Ewen answered 23/11, 2008 at 0:22 Comment(1)
I always read 3 bars as 'equivalent to'. I would use ':=' to mean 'defined as'.Trencherman
J
2

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.

Joleenjolene answered 23/11, 2008 at 1:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.