Counterintuitive result for FullSimplify of expressions with Re

Posted 10 years ago
4917 Views
|
6 Replies
|
21 Total Likes
|
 In[1]:= FullSimplify[Re[x + y], {x, y} \[Element] Reals] Out[1]= x + y In[2]:= FullSimplify[-2 Re[x + y], {x, y} \[Element] Reals] Out[2]= -2 (x + y) In[3]:= FullSimplify[-Re[x + y], {x, y} \[Element] Reals] Out[3]= -Re[x + y] Why doesn't the last one remove Re?
6 Replies
Sort By:
Posted 10 years ago
 A ComplexityFunction based on the StringLength of the expression (perhaps with heads reduced to a single character) might be a more intuitive measure of complexity.
Posted 10 years ago
 Make Re[] more expensive:FullSimplify[-Re[x + y], {x, y} \[Element] Reals, ComplexityFunction -> Function[{e}, If[MatchQ[e, _Re], 1, 0]]]
Posted 10 years ago
 Arnoud +1 - this is exactly what I wanted to ask about - "how do we make it work" ;)
Posted 10 years ago
 Don't you think that the result of calculations shouldn't depend on aspects of the implementation and in particular, FullSimplify[-Re[x + y], {x, y} ? Reals]  returning -Re[x + y] should be considered as a bug and fixed?
Posted 10 years ago
 This is because -(x+y) turns into -x-y (= -1*x + -1*y), while -2(x+y) remains as is.
Posted 10 years ago
 Based on LeafCount, -(x+y) is actually less simple than -Re[x + y]. With the 2 multiplier, the Re-free expression has smaller LeafCount. In[1]:= LeafCount[-2 (x + y) ] Out[1]= 5 In[2]:= LeafCount[-2 Re[x + y]] Out[2]= 6 In[3]:= LeafCount[-Re[x + y]] Out[3]= 6 In[4]:= LeafCount[-(x + y) ] Out[4]= 7