Equal

lhs==rhs

returns True if lhs and rhs are identical.

Details

  • lhs==rhs is used to represent a symbolic equation, to be manipulated using functions like Solve.
  • lhs==rhs returns True if lhs and rhs are ordinary identical expressions.
  • lhs==rhs returns False if lhs and rhs are determined to be unequal by comparisons between numbers or other raw data, such as strings.
  • Approximate numbers with machine precision or higher are considered equal if they differ in at most their last seven binary digits (roughly their last two decimal digits).
  • For numbers below machine precision, the required tolerance is reduced in proportion to the precision of the numbers.
  • 2==2. gives True.
  • e1==e2==e3 gives True if all the ei are equal.
  • Equal[e] gives True.
  • For exact numeric quantities, Equal internally uses numerical approximations to establish inequality. This process can be affected by the setting of the global variable $MaxExtraPrecision.
  • Equal remains unevaluated when lhs or rhs contains objects such as Indeterminate and Overflow.
  • In StandardForm and InputForm, lhs==rhs can be input as lhs\[Equal]rhs or lhsrhs.
  • It can also be input as \[LongEqual] or lhsrhs.
  • In TraditionalForm, lhs==rhs is output as lhsrhs.

Background & Context

  • Equal[expr1,expr2] returns True if expr1 and expr2 are numerically equal, False if they are unequal and unevaluated if equality cannot be established. For example, Equal[(1+Sqrt[5])/2,GoldenRatio] returns True, Equal[1,2] returns False and Equal[1,a] returns unevaluated. Equal[expr1,expr2] may be input using double equal signs as expr1==expr2 or using the \[Equal] character as expr1expr2. The multiple-argument form Equal[expr1,expr2,], which may also be input as expr1==expr2, returns True if all expressions expri are numerically equal, False if at least two are not equal and unevaluated otherwise. The single-argument form Equal[expr] returns True (as, slightly paradoxically, does the single-argument form Unequal[expr]).
  • Numbers with machine precision (MachinePrecision) or greater are considered equal if they differ in at most their last seven binary digits. Equality for numbers below machine precision is established based on agreement to within the precision of the lowest precision number. For example, 1.01`2==1 returns True, while 1.01`3==1 returns False. For exact numeric quantities, Equal uses numerical approximations to establish inequality, which can be affected by the value of the global variable $MaxExtraPrecision.
  • Equal is related to a number of other symbols. Set[expr1,expr2] (which may be input using the "single equals" syntax expr1=expr2) evaluates expr2 and assigns the result to be the value of expr1, while SameQ[expr1,expr2] (which may be input using the "triple equals" syntax expr1===expr2) returns True if expr1 and expr2 are identical and otherwise returns False. In contrast to Equal, SameQ differentiates between different representations of numbers; for example, SameQ[1,1.] and SameQ[1.,1.+0.I] both return False. The behavior of SameQ also differs from that of Equal in that SameQ always evaluates to True or False, whereas Equal may remain unevaluated in cases where equality cannot be resolved. Unequal (which may be input as expr1!=expr2 is the converse of Equal. Equal also has an operator form EqualTo. The Boolean logic analog of Equal is Equivalent.
  • PossibleZeroQ can be used to indicate if a given expression has value in some cases where Equal returns unevaluated. For example, Equal[Erf[Log[4]+2Log[Sin[Pi/8]]]-Erf[Log[2-Sqrt[2]]],0] returns evaluated, while calling PossibleZeroQ on its first argument returns True (together with an informative message indicating that a zero value could not be rigorously established). Symbolic simplifiers like Simplify, FullSimplify and RootReduce can sometimes also be used to rigorously establish equality (including in the example just given) when Equal cannot.

Examples

open allclose all

Basic Examples  (2)

Test equality:

In[1]:=
Click for copyable input
Out[1]=

Represent an equation:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

Scope  (12)

Properties & Relations  (6)

Possible Issues  (5)

See Also

SameQ  Unequal  EqualTo  Equivalent  AsymptoticEqual  AsymptoticEquivalent  KroneckerDelta  PossibleZeroQ  Order  Element  Reduce  Simplify  BinaryDistance  TwoWayRule

Tutorials

Introduced in 1988
(1.0)
| Updated in 2007
(6.0)