2
$\begingroup$

When I take the imaginary part of a complex number times a function, I get the answer I was expecting,

Refine[Im[(1+I) Cos[x], Element[x,Reals]]
-> Cos[x]

but if I include a sum,

Refine[Im[(1 + I) Cos[x] + (1 + I) Sin[x]], Element[x, Reals]]
-> Im[(1 + I) Cos[x] + (1 + I) Sin[x]]

It seems that I have to move the Im function inside the sum by hand,

Refine[Map[Im, (1 + I) Cos[x] + (1 + I) Sin[x]], Element[x, Reals]]
-> Cos[x] + Sin[x]

Why is this? I can't think of a situation when this is not the right thing to do. I'm using version 9.0.0.0.

$\endgroup$
  • $\begingroup$ What is the question? Why doesn't Mathematica do this? Or how do we work round it? $\endgroup$ – mikado Jul 3 '17 at 20:46
3
$\begingroup$

Have a look at ComplexExpand

Refine[Im[(1 + I) Cos[x] + (1 + I) Sin[x]], Element[x, Reals]] // ComplexExpand

Cos[x] + Sin[x]

or use Simplify instead of Refine:

Simplify[Im[(1 + I) Cos[x] + (1 + I) Sin[x]], Element[x, Reals]]

Cos[x] + Sin[x]

$\endgroup$
  • $\begingroup$ Thanks for your answer. I'm still wondering why Mathematica doesn't do this by default. In other words, is there some situation in which doing the Map above gives a wrong answer? $\endgroup$ – Rodney Price Jul 3 '17 at 21:05
  • $\begingroup$ @RodneyPrice. It is probably because doing such transformations by default costs extra processor time, time which is then wasted because the result isn't final and further computations obviate the extra work $\endgroup$ – m_goldberg Jul 3 '17 at 23:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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