Message Boards Message Boards

4
|
5795 Views
|
6 Replies
|
21 Total Likes
View groups...
Share
Share this post:

Counterintuitive result for FullSimplify of expressions with Re

Posted 11 years ago
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?
POSTED BY: Andy Ross
6 Replies
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 BY: Sjoerd de Vries
Make Re[] more expensive:

FullSimplify[-Re[x + y], {x, y} \[Element] Reals,
ComplexityFunction -> Function[{e}, If[MatchQ[e, _Re], 1, 0]]]
POSTED BY: Arnoud Buzing
Arnoud +1 - this is exactly what I wanted to ask about - "how do we make it work" ;)
POSTED BY: Vitaliy Kaurov
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 BY: Dmitry Podkopaev
This is because -(x+y) turns into -x-y (= -1*x + -1*y), while -2(x+y) remains as is.
POSTED BY: Brett Champion
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
POSTED BY: Vitaliy Kaurov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract