# Compare 2 expressions with variables

I want to check if two expressions are equivalent with Mathematica. For example, is $$2 x + 4 + 2$$ equivalent to $$2 (x + 2 + 1)$$. I tried the === operator, which I expected to return True in both examples.

In[]:= 2 x + 4 + 2 === 2 (x + 2 + 1)
Out[]:= False

In[]:= 2 x + 4 + 2 === x + 6 + x
Out[]:= True


I also tried == operator, which just returned the whole expression for one example and True for the other.

In[]:= 2 x + 4 + 2 == 2 (x + 2 + 1)
Out[]:= 6 + 2 x == 2 (3 + x)

In[]:= 2 x + 4 + 2 == x + 6 + x
Out[]:= True


So my question is there another operator/function that determines whether or not two expressions are equivalent.

• Try Simplify[2 x + 4 + 2 == 2 (x + 2 + 1)]. Do not use ===; that's for structural identity. Your two expressions are identical in meaning, but not in structure, if that makes sense to you. Commented Jun 2, 2020 at 18:59
• Sadly Simplify doesn't always fit my needs. For example: Simplify[8/15 x Sqrt[x Sqrt[x^(3/2)]]] and Simplify[x^(15/8)/(15/8)] do not return the same result although the expressions are equivalent. Commented Jun 2, 2020 at 19:14
• PossibleZeroQ can be useful for this. Commented Jun 2, 2020 at 19:19
• @NejcJezersek No they are not for some complex values. You can find a counterexample: FindInstance[8/15 x Sqrt[x Sqrt[x^(3/2)]] != x^(15/8)/(15/8), x] which returns {{x -> -(28/5) + (79 I)/5}} as an example of a value for which the two expressions are different. Alternatively, you can Simplify the difference of the two and see if it reduces to $0$. Commented Jun 2, 2020 at 19:21
• @MarcoB thank you; FindInstance[ 8/15 x Sqrt[x Sqrt[x^(3/2)]] != x^(15/7)/(15/8), x, Reals] with domain specified does the job for me. Commented Jun 2, 2020 at 19:35