What is the proper way to verify that two expressions are equal?
You are using SameQ
which does a direct structural comparison rather than a mathematical one. Since the expressions are not exactly the same it returns False
. Try Equal
:
FullSimplify[Abs[1/x + x^2] == Abs[1 + x^3]/Abs[x]]
True
FullSimplify
is needed for nontrivial comparisons; without it Mathematica will return the equality as given if it is not trivially equivalent.
You can also use ForAll
and Resolve
which I think is sometimes faster (no example at hand):
ForAll[x, x != 0, Abs[1/x + x^2] == Abs[1 + x^3]/Abs[x]] // Resolve
True
Answer
Given two symbolic expressions a
and b
in Mathematica, the way to check equivalence is:
True === FullSimplify[a == b]
Explanation
The FullSimplify
function is a thorough symbolic restructuring command that will be most likely to reduce two equivalent symbolic expressions to True
.
The ===
operator will call SameQ
, which will return True
if both operands are exactly equivalent without any manipulation and False
otherwise.
The reason for adding the True ===
can be seen with an example.
a = d/2;
b = 4c;
FullSimplify[a == b]
8c == d
That's not what we want though, and if we put this output in an If
statement it will not work correctly. Since we want the only possible outputs to be True
or False
, we write:
a = d/2;
b = 4c;
True === FullSimplify[a == b]
False
Yay!