3

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.

Rodney Price
  • 283
  • 1
  • 7

1 Answers1

3

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]

Ray Shadow
  • 7,816
  • 1
  • 16
  • 44
eldo
  • 67,911
  • 5
  • 60
  • 168
  • 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? – Rodney Price Jul 03 '17 at 21:05
  • @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 – m_goldberg Jul 03 '17 at 23:37