= (equals sign)
Tests if two objects are equal.
Syntax
-
x = y
-
x
andy
are 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
5
is 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
5
is 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,
false
is 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,
length
is equal tocardinality
. In addition, if you assignc ≔ cardinality
thenc
will also equal any oflength
orcardinality
. -
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