For some reason Mathematica does not properly simplify this expression:
In[7]:= FullSimplify[ArcTan[-Re[x + z], y], (x | y | z) \[Element] Reals]
Out[7]= ArcTan[-Re[x + z], y]
Obviously, if x
and z
are real, then so is x+z
, so Re[x + z]
should be replaced by x + z
. Strangely enough, dropping any small part of the input fixes the problem, here are some examples.
No minus sign:
In[8]:= FullSimplify[ ArcTan[Re[x + z], y], (x | y | z) \[Element] Reals]
Out[8]= ArcTan[x + z, y]
No z
:
In[9]:= FullSimplify[ArcTan[-Re[x], y], (x | y | z) \[Element] Reals]
Out[9]= ArcTan[-x, y]
No y
:
In[10]:= FullSimplify[ArcTan[-Re[x + z]], (x | y | z) \[Element] Reals]
Out[10]= -ArcTan[x + z]
Of course I can just drop the Re
function manually, but this is just a small fragment of the actual expression I'm trying to simplify, and I would like to avoid going though the whole expression looking for this specific pattern.
Anyone knows how to fix this? Is this a bug or what? (I'm using version 8.0.4.0)
Answer
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]
Comments
Post a Comment