What is the difference between equality and equiva

2019-01-21 19:47发布

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?

9条回答
beautiful°
2楼-- · 2019-01-21 20:02

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.

查看更多
Fickle 薄情
3楼-- · 2019-01-21 20:02

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

查看更多
女痞
4楼-- · 2019-01-21 20:05

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 )

查看更多
Explosion°爆炸
5楼-- · 2019-01-21 20:15

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.

查看更多
Root(大扎)
6楼-- · 2019-01-21 20:15

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.

查看更多
贪生不怕死
7楼-- · 2019-01-21 20:16

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

查看更多
登录 后发表回答