# Mathematica not recognizing expressions are real

I see no problem with following calculation.

Refine[ComplexExpand[b I /(a + b I)], {Element[a, Reals], Element[b, Reals]}]

(I a b)/(a^2 + b^2) + b^2/(a^2 + b^2)


The real and imaginary parts are nicely separated.

However, the next calculations are confusing to me. Please explain how I get the output. Should I get

b^2/(a^2 + b^2)


as I declared a and b are real?

Refine[
Re[(I a b)/(a^2 + b^2) + b^2/(a^2 + b^2)], {Element[a, Reals], Element[b, Reals]}]

-a b Im[1/(a^2 + b^2)] + b^2 Re[1/(a^2 + b^2)]


## 1 Answer

You must also tell Mathematica that a^2 + b^2 is not zero.

Refine[
Re[(I a b)/(a^2 + b^2) + b^2/(a^2 + b^2)], {a, b} ∈ Reals && a^2 + b^2 > 0]

b^2/(a^2 + b^2)

• If a^2 +b^2 is zero, the outputs are also not valid. The 'ComplexExpand[]' function behave as I expected. The 'Re[]' function seems weird to me, still. The 'Im[1/(a^2 + b^2)]' is always zero if a and b are real provided nonzero a^2 +b^2 . – Cookie Monster Jul 3 '18 at 7:50