# Can Mathematica point out why it thinks two symbolic expressions are different?

SameQ checks to see if symbolic expressions are the same. There are some caveats, as pointed out by the answers to:

Consider the following two expressions:

s = ((ax-bx)^2+(ay-by)^2) Abs[ay bx-ax by-ay px+by px+ax py-bx py] > 0 ||
((ax-bx)^2+(ay-by)^2) ((ax-bx) (bx-px)+(ay-by) (by-py)) > 0 ||
((ax-bx)^2+(ay-by)^2) (ax^2+ay^2+bx px-ax (bx+px)+by py-ay (by+py)) < 0

t = ((ax-bx)^2+(ay-by)^2) Abs[ay bx-ax by-ay px+by px+ax py-bx py] > 0 ||
((ax-bx)^2+(ay-by)^2) (ax^2+ay^2+bx px-ax (bx+px)+by py-ay (by+py)) < 0 ||
((ax-bx)^2+(ay-by)^2) ((ax-bx) (bx-px)+(ay-by) (by-py)) > 0


On Mathematica 9:

In[47]:= s == t
Out[47]= (((ax-bx)^2+(ay-by)^2) Abs[ay bx-ax by-ay px+by px+ax py-bx py] > 0 ||
((ax-bx)^2+(ay-by)^2) ((ax-bx) (bx-px)+(ay-by) (by-py)) > 0 ||
((ax-bx)^2+(ay-by)^2) (ax^2+ay^2+bx px-ax (bx+px)+by py-ay (by+py)) < 0) ==
(((ax-bx)^2+(ay-by)^2) Abs[ay bx-ax by-ay px+by px+ax py-bx py] > 0 ||
((ax-bx)^2+(ay-by)^2) (ax^2+ay^2+bx px-ax (bx+px)+by py-ay (by+py)) < 0 ||
((ax-bx)^2+(ay-by)^2) ((ax-bx) (bx-px)+(ay-by) (by-py)) > 0)

In[48]:= s === t
Out[48]= False

In[49]:= Assuming[{ax, bx, px, ay, by, py} \[Element] Reals, s === t]
Out[49]= False

In[50]:= Assuming[{ax, bx, px, ay, by, py} \[Element] Reals, FullSimplify[s === t]]
Out[50]= False


Can I get Mathematica to identify where it thinks the statements are different?

• It's the ordering,of course-. Try Sort[t] == Sort[s] Commented Sep 25, 2015 at 3:00
• @belisarius Sort::normal: Nonatomic expression expected at position 1 in Sort[t] Commented Sep 25, 2015 at 3:18
• Well, it works here. Please restart your Mathematica and try again. Just in case, I'm also using v9 Commented Sep 25, 2015 at 3:35
• Are you sure you want SameQ and not Equal? SameQ tests for structural equality of two data structures, and has nothing to do with mathematics. Assuming, Simplify, etc. have absolutely no effect on it because those functions are for symbolic mathematics. SameQ is purely for programming. If two things don't look exactly the same according to FullForm, then they are different for SameQ. Commented Sep 25, 2015 at 7:21

Module[{cf = ColorData[97], $color = 1}, style["", c_] := Style[Overscript[Overscript["", \[OverBracket]], c], {Darker@cf[c], Bold}]; style[str_, c_] := Style[Overscript[Overscript[str, \[OverBracket]], c], {Darker@cf[c], Bold}]; join[{Row[{}], Row[{}]}, next_String] := ($color = 1;{Row[{next}], Row[{next}]});
join[{Row[{}], Row[{}]}, {next1_String, next2_String}] := ($color = 1;{Row[{next1}], Row[{next2}]}); join[{s1_Row, s2_Row}, next_String] := {Row[{s1, next}], Row[{s2, next}]}; join[{s1_Row, s2_Row}, {next1_String, next2_String}] := With[{c =$color++}, {Row[{s1, style[next1, c]}], Row[{s2, style[next2, c]}]}];