0
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ 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) $\endgroup$ – Szabolcs Oct 26 '19 at 11:53
  • 1
    $\begingroup$ Another possibility is Assuming[a∈Reals && b∈Reals, Re[f[a+b I]]//FullSimplify] $\endgroup$ – yarchik Oct 26 '19 at 12:04
1
$\begingroup$

$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;

f[z_] := z^2 + 3 z - 2

g = f[a + b I];

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 *)
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – mf67 Oct 26 '19 at 17:09
  • $\begingroup$ @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. $\endgroup$ – Bob Hanlon Oct 27 '19 at 2:56

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.