# Re[z] Command [closed]

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?

• See "Properties & Relations" in the documentation for Re. It shows various uses of ComplexExpand with respect to Re. – Michael E2 Jan 25 at 16:56

z = a + I b;
ComplexExpand[Re[z]]


a

Hope that helps.

• But what is the difference between ComplexExpand[Re[z]] and Re[ComplexExpand[z]]?? – Goldy Jan 25 at 15:17
• Command ComplexExpand[Re[z]] gives me correct result, but Re[ComplexExpand[z]] is not working – Goldy Jan 25 at 15:18
• 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? – Hugh Jan 25 at 15:23

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

ComplexExpand[z]


is just

z


Thus,

Re[ComplexExpand[z]]


first gets rewritten as

Re[z]


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.