# Real value of a complex expression

Why is the following lines not correct?

Clear[a, b]
a \[Element] Reals;
b \[Element] Reals;
f[z_] := z^2 + 3 z - 2
g = f[a + b I] // Expand
Re[g]


The output includes Im and Re. I've read other questions but the recommendations did not work, like

$Assumptions = a \[Element] Reals && b \[Element] Reals  TIA. • 1. Use ComplexExpand (there is certainly a duplicate for this somewhere) 2. a \[Element] Reals does not declare a to be real the same way that a == 1 does not assign 1 to a. 3. $Assumptions only affects functions that have an Assumptions option (so no Expand or Re) – Szabolcs Oct 26 '19 at 11:53
• Another possibility is Assuming[a∈Reals && b∈Reals, Re[f[a+b I]]//FullSimplify] – yarchik Oct 26 '19 at 12:04

$Assumptions is only used by functions that have the option Assumptions, e.g., Simplify, FullSimplify, Refine, Integrate. Options[#, Assumptions] & /@ {Simplify, FullSimplify, Refine, Integrate} (* {{Assumptions :> $$Assumptions}, {Assumptions :> Assumptions}, {Assumptions :> Assumptions}, {Assumptions :>$$Assumptions}} *) Clear[a, b]$Assumptions = a \[Element] Reals && b \[Element] Reals;

Then to use $Assumptions Re[g // Expand] // Simplify (* -2 + 3 a + a^2 - b^2 *)  Or if you do not expand g first Re[g] // FullSimplify (* -2 + a (3 + a) - b^2 *)  • That is interesting, but why does the last command 'fail' when$f(z)$is changed to$f(z)=z^4 + 3 z - 2\$? The first seems to work well. – mf67 Oct 26 '19 at 17:09
• @mf67 - simplification of expressions is complicated. You will often have to try different approaches. For f[z_] := z^4 + 3 z - 2, Re[g] // ComplexExpand works well. – Bob Hanlon Oct 27 '19 at 2:56