# What is the proper way to verify that two expressions are equal?

First of all, it appears to me that

$$\left|\frac{1}{x} + x^2\right| = \frac{|1 + x^3|}{|x|}$$

is true.

I don't know why, but my attempt to verify it in Mathematica failed.

In:= Abs[1/x + x^2] === Abs[1 + x^3]/Abs[x]
Out= False


It's weird because Mathematica is unable to find a counterexample.

In:= FindInstance[Abs[1/x + x^2] != Abs[1 + x^3]/Abs[x], x, Complexes]
Out= {}


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

• Sorry, but no ForAll[x, Abs[1/x + x^2] == Abs[1 + x^3]/Abs[x]] // Resolve send False – mlpo Dec 15 '13 at 1:40
• @mlpo Strange, it returns True in version 7. What version are you using? – Mr.Wizard Dec 15 '13 at 1:43
• @Mr.Wizard Windows 8 Mathematica 9.01 False – Alex Dec 15 '13 at 1:46
• @mlpo Okay, I think I have an explanation for that behavior. If x is zero we have an indeterminate expression; I think later versions may recognize this while v7 does not? In that sense your equivalence is actually false, yet that is not the result you wanted. – Mr.Wizard Dec 15 '13 at 1:46
• 9.0.1, but I found the problem, when x = 0. Try with ForAll[x, x != 0, Abs[1/x + x^2] == Abs[1 + x^3]/Abs[x]] // Resolve – mlpo Dec 15 '13 at 1:47

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!