Suppose we have complex number $z=a+i b$, where $a$ and $b$ are variables.

Now, if we want real part of $z$, then in mathematica we use Re[z] command. But this command is not working (because $a$ and $b$ are not fixed real numbers).

Re[expr] is left unevaluated if expr is not a numeric quantity. (https://reference.wolfram.com/language/ref/Re.html)

How do we get Re[z]$=a$ as solution?

  • 3
    $\begingroup$ See "Properties & Relations" in the documentation for Re. It shows various uses of ComplexExpand with respect to Re. $\endgroup$ – Michael E2 Jan 25 at 16:56
z = a + I b;


Hope that helps.

  • $\begingroup$ But what is the difference between ComplexExpand[Re[z]] and Re[ComplexExpand[z]]?? $\endgroup$ – Goldy Jan 25 at 15:17
  • $\begingroup$ Command ComplexExpand[Re[z]] gives me correct result, but Re[ComplexExpand[z]] is not working $\endgroup$ – Goldy Jan 25 at 15:18
  • 1
    $\begingroup$ ComplexExpand[z] has not got any work to do. If you try ComplexExpand[z^2] then it does do some work. Have a good look at the documentation. What would you expect it to do? $\endgroup$ – Hugh Jan 25 at 15:23

The rewrite rules behind ComplexExpand assume all undefined symbols in the expression are real.


is just




first gets rewritten as


and no further rewrite is possible because Re has no rule for this case. But ComplexExpand inspects the structure of the expression it's given. It recognizes that it can rewrite Re[z] as z.

Mathematica is a language for rewriting mathematical expressions based on recognizing their structure. Sometimes those rewrites seem to act like "commands", but it is misleading to think of them that way.


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