Group Abstract Group Abstract

Message Boards Message Boards

0
|
91 Views
|
6 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Why can't we find real and imaginary parts using Assuming?

Posted 2 days ago

Why don't I get a result based on the assumptions?

In[616]:= Assuming[{x \[Element] Reals, y \[Element] Reals}, 
 Re[x + \[ImaginaryJ] y - 1/(x + \[ImaginaryJ] y)]]

Out[616]= -Im[y] + Re[x - 1/(x + I y)]
POSTED BY: Ernst Huijer
6 Replies

The main tool for this is ComplexExpand.

POSTED BY: Gianluca Gorni
Posted 2 days ago

As has been pointed out, the expected way to treat expressions as if all variables are real is to use ComplexExpand. And while I cannot read the mind of Wolfram developers, it seems to me that Re is not intended to deal with arbitrary expressions (beyond just applying some obvious identities). It is specifically intended to give you the real value of an expression with head Complex. I think one could reasonably disagree with that, but I think my interpretation is a reasonable interpretation of the documentation.

As for wanting to have "purely real expressions", there is a very literal sense in which that is just impossible in Mathematica (without you writing your own custom functions, that is), because expressions have no type (in the "strongly typed" sense used to describe some languages in the software industry). It is largely up to the user of Mathematica to "protect" the semantic meaning of the expressions they want to use.

POSTED BY: Eric Rimbey

Yes, it looks inconsistent. The output that we would expect

x - x/(x^2 + y^2)

has the same LeafCount as

x - Re[1/(x + I y)]

so that FullSimplify probably finds them equally simple, and I don't know how the choice is done. The task of rewriting an expression in exactly the form we wish is often tricky.

POSTED BY: Gianluca Gorni

It seems that Re does not use the assumptions:

In[57]:= Assuming[{x \[Element] Reals}, Re[x]]

Out[57]= Re[x]

For you purpose you can use ComplexExpand:

ComplexExpand[Re[x + I y - 1/(x + I y)]]

I am surprised by the output of the following:

Assuming[{x \[Element] Reals, y \[Element] Reals},
 FullSimplify[ReIm[x + I y - 1/(x + I y)]]]

It may be a matter of LeafCount.

POSTED BY: Gianluca Gorni

Seems like a bug or deficiency. We often want to have purely real expressions. There should be a way to force that.

POSTED BY: Ernst Huijer
{x - Re[1/(x + I y)], y (1 + 1/(x^2 + y^2))}

is what I get. Not very consistent.

POSTED BY: Ernst Huijer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard