# How can I compare two equations in Mathematica , to check whether they are mathematically same or not?

Let's say expr1= Sin x expr2 = e^x -e^-x/2j

Now we know they are the same mathematically, how will I come to know expr1=expr2 and they are the same?

Let's say I have these two equations and have code as these

FullSimplify[
(ComplexExpand[#1,
TargetFunctions ->
{Re, Im}] & )[
Abs[1 + (I*2*Pi)/
(E^((-I)*2*Pi) -
E^((-I)*2*Pi*\[Lambda]))]^2]]


and then we have

(ComplexExpand[#1,
TargetFunctions ->
{Re, Im}] & )[
Abs[1 + (I*2*Pi)/
(E^((-I)*2*Pi) -
E^((-I)*2*Pi*\[Lambda]))]^2]


Both of them yield different answers but can I check whether they are the same or not?

• Did you already try FullSimplify[expr1 == expr2]? (Incorporate variable assumptions with Assuming[] whenever applicable.) Jan 28, 2021 at 11:27
• FullSimplify[expr1 == expr2] I did it now, but this gave expr-2's answer? How would I come to know both answers of expr1 == expr2 @J.M. Jan 28, 2021 at 11:33
• Using your simpler example: FullSimplify[Sin[x] == (Exp[I x] - Exp[-I x])/(2 I)]. The True result implies that the equation is indeed true for all complex values of x. Jan 28, 2021 at 11:44
• One other simple way is to simplify the difference between these two expressions. If they are identical, the simplification will return zero. Jan 28, 2021 at 13:08
• @good_omen92 It gives True for me. Maybe try restarting your kernel? Jan 28, 2021 at 13:50

## 2 Answers

In many cases it is easier to show the difference is zero.

expr1 = FullSimplify[(ComplexExpand[#1,
TargetFunctions -> {Re, Im}] &)[
Abs[1 + (I*2*Pi)/(E^((-I)*2*Pi) - E^((-I)*2*Pi*\[Lambda]))]^2]];

expr2 = (ComplexExpand[#1, TargetFunctions -> {Re, Im}] &)[
Abs[1 + (I*2*Pi)/(E^((-I)*2*Pi) - E^((-I)*2*Pi*\[Lambda]))]^2];

expr1 - expr2 // Together // Simplify

(*   0   *)

• I divide two-equations manually and solved the same equation by Mathematica, and let's say both are correct, FullSimplify[expr1 == expr2] yields a true? – Does that makes sense? @Akku Feb 4, 2021 at 10:18

There is no way to get a definitive answer to whether two expression are equivalent. It is an undecidable problem.

To let Mathematica do its best to find out, use PossibleZeroQ on their difference.

You can also use FullSimplify[expr1 == expr2, assumptions] which (a bit more usefully) can give True or False (meaning a certain result), or return the input (meaning "I don't know").

• I was going to suggest PossibleZeroQ. Another thing to try is FindInstance[...!=0] to see if zero-equality can be disproved by counterexample. Jan 28, 2021 at 14:34
• I divide two-equations manually and solved the same equation by Mathematica, and let's say both are correct, FullSimplify[expr1 == expr2] yields a true? Feb 4, 2021 at 9:02