Why doesn't FullSimplify drop the Re function from an expression known to be real?
The problem is due to Mathematica thinking that the version with the Re[]
is actually simpler. This is because the default complexity function is more or less LeafCount[]
, and
In[332]:= ArcTan[-Re[x+z],y]//FullForm
Out[332]//FullForm= ArcTan[Times[-1,Re[Plus[x,z]]],y]
whereas
In[334]:= ArcTan[-x-z,y]//FullForm
Out[334]//FullForm= ArcTan[Plus[Times[-1,x],Times[-1,z]],y]
Here is a function that counts leaves without penalizing negation:
In[382]:= f3[e_]:=(LeafCount[e]-2Count[e,Times[-1,_],{0,Infinity}])
{LeafCount[x],LeafCount[-x],f3[x],f3[-x]}
Out[383]= {1,3,1,1}
If you tell mathematica to simplify using this complexity function then you get the expected result:
FullSimplify[ArcTan[-Re[x+z],y],(x|y|z)\[Element]Reals,ComplexityFunction->f3]
Out[375]= ArcTan[-x-z,y]
I think this is a bug.
Close enough expressions yield better results, e.g.
FullSimplify[
ArcTan[ -# Re[x + z], y], (x | y | z) \[Element] Reals
] ===
ArcTan[ -# (x + z), y] & /@
{ 1.0, 1, Sqrt[1.], Exp[0.], 1 - 0., 2, a}
{True, False, True, True, True, True, True}
The problem seems to be specific for a factor -1
before Re[x + z]
, other factors appear to give what we would expect. If there is ArcTan[-a Re[x + z], y]
in the expression it works well. It should be noted that the same issue comes with Simplify
and that the problem has nothing to do with ArcTan
, because :
(FullSimplify[-# Re[x + z], (x | y | z) \[Element] Reals]
=== -# (x + z)) & /@
{ 1.0, 1, Sqrt[1.], Exp[0.], 1 - 0., 2, a}
{True, False, True, True, True, True, True}
To fix the problem you could use e.g. Refine
instead of FullSimplify
,
Refine[ ArcTan[ -Re[x + z], y], (x | y | z) \[Element] Reals]
ArcTan[-x - z, y]
Edit
Another way to deal with similar expressions wolud be hiding a minus
sign into
Re
, e.g.
Re[-(x + z)]
instead of -Re[x + z]
.
Sometimes a more flexible way would be some kind of replacement, i.e. setting
ArcTan[-a Re[x + z], y]]
wherever in expr
one finds ArcTan[- Re[x + z], y]]
and then expr /. a->1
FullSimplify[ ArcTan[ -a Re[x + z], y], (x | y | z) \[Element] Reals] /. a -> 1
FullSimplify[ArcTan[ Re[-(x + z)], y], (x | y | z) \[Element] Reals]
ArcTan[-x - z, y] ArcTan[-x - z, y]