0
$\begingroup$

This question already has an answer here:

How do I tell Mathematica that a variable is a real number. I searched for this question here and in Google and nothing that was suggested seems to work for me. I must be missing something. My code is below, any help will be greatly appreciated.

Note: I restarted the kernel before executing this code.

The function Re does not work properly because it does not know x is a real number.
In[1]:= Re[x + I y]
Out[1]= -Im[y] + Re[x]

This does not work:
In[2]:= $Assumptions = {x \[Element] Reals, y \[Element] Reals};
Re[x + I y]
Out[3]= -Im[y] + Re[x]

This does not work either:
In[4]:= x > 0; y > 0;
Re[x + I y]
Out[5]= -Im[y] + Re[x]

And neither does this:
In[6]:= x = x2^2; y = y2^2;
Re[x + I y]
Out[7]= -Im[y2^2] + Re[x2^2]
$\endgroup$

marked as duplicate by Kuba Jan 19 '18 at 6:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3
$\begingroup$

1. See the function ComplexExpand

ComplexExpand[Re[x + I y]]

gives

x

2. Also you can try Refine combined with Element:

Refine[Re[x + I y], Element[x, Reals]]
(*x - Im[y]*)
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.