= (equals sign)
Tests if two objects are equal.
Syntax
-
x = y-
xandyare any objects
-
Description
If x and y are any two objects, then x = y returns true iff x and y are exactly equal. The subtleties are as follows:
-
Objects are compared as mathematical entities in the sense that datatype differences not relevant to the objects’ mathematical identities are ignored. For instance, the integer
5is equal to the rational number5/2 + 5/2, the real number5.0, and the complex number5 + i − i. -
Numbers, vectors, and matrices are always treated as different objects. For instance, the number
5is not equal to the matrix❨❨5❩❩, and the vector❨1, 2, 3❩is not equal to the single-column matrix❨❨1❩, ❨2❩, ❨3❩❩. -
Floating-point numbers are *not* compared with epsilons. For instance,
sin(π)may not equal0. To compare objects with epsilon, use the≈operator instead. -
A boolean is not equal to any non-boolean object (such as a string or a number). For instance,
falseis not equal to any of"",0, or"false". -
A string is not equal to any non-string object that it may be parsed to. For instance,
"5"is not equal to5. -
Two kernel function objects are equal if they refer to the same actual kernel function implementation, even if they are accessed using two different synonyms. For instance,
lengthis equal tocardinality. In addition, if you assignc ≔ cardinalitythencwill also equal any oflengthorcardinality. -
Two user-defined functions are equal if and only if they have identical abstract syntax trees. For instance, while
(n ↦ n^2) = (k ↦ k^2)istrue,(n ↦ n^2) = (k ↦ sqr(2))isfalse.
The = operator is implemented by the equals function.
Examples
1 + 1 = 2
true