Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I try to evaluate Re[Sqrt[z]], for some values of Mathematica fails to evaluate it.

For example,

Re[Sqrt[2 + I*x]]`

Re[Sqrt[2 + I x]]

How can I get the real number in Sqrt[complex number]?

share|improve this question
possible duplicate of Complex number operations: telling Mathematica variables are real – Szabolcs Mar 5 '13 at 16:55
Concerning those voting for the duplicate: could you indicate how that would produce the solution $\sqrt{1+\sqrt{1+\left(x/2\right)^2}}$? (I had to manually derive this.) – whuber Mar 5 '13 at 17:10
It may be of interest that, in V9, the predictive UI, after returning Re[Sqrt[2 + I*x]] unevaluated, suggests 'ComplexExpand. If you accept the suggestion, _Mathematica_ then returns (4 + x^2)^(1/4) Cos[1/2 Arg[2 + I x]]`. – m_goldberg Mar 5 '13 at 17:45
up vote 4 down vote accepted

Try playing with this:

ComplexExpand[Re[Sqrt[y + I x]], TargetFunctions -> {Re, Im}]

(x^2 + y^2)^(1/4) Cos[1/2 ArcTan[y, x]]

ComplexExpand[Re[Sqrt[2 + I 5]], TargetFunctions -> {Re, Im}] //TrigToExp //FullSimplify

Sqrt[1/2 (2 + Sqrt[29])]

The function ComplexExpand is quite intelligent. For example, you can have mixed variables - ones that you know are real and those that may be complex. Here how it can derive a nice formula:

ComplexExpand[Re[Sqrt[(2 + I x)/a]], a, TargetFunctions -> {Re, Im}] //
    TrigToExp // FullSimplify // TraditionalForm

enter image description here

share|improve this answer

Given that there is a universal algebraic solution, we should not be satisfied with trigonometric expressions.

The simplest, most direct way I have found to obtain the real part of the root of $x + i y$ begins with the inverse of the square root, suggesting we would like the $u$ part of this solution:

Solve[(u + I v)^2 - (x + I y), {u, v}, Reals] (* Does not succeed *)

Unfortunately Mathematica complains about the presence of imaginary values when real solutions are sought. So we have to force a separation into real and imaginary parts:

u /. #& /@ Solve[ComplexExpand@Through[And[Re[#]==0&, Im[#]==0&][(u+I v)^2-(x+I y)]], {u, v}]

We get four solutions, of which two are evidently imaginary, leaving

$$u = \pm\frac{\sqrt{\sqrt{x^2+y^2}+x}}{\sqrt{2}}$$

as the two real solutions, as expected. (You could specify Reals as an argument to Solve, which will return just the two real solutions--but in the form of Root objects. They take some further manipulation to put into this nice form.)

This technique generalizes in an obvious way to more complicated inverse functions than mere square roots.

share|improve this answer
+1 - why mathematica can't do this more simply has baffled me before. – gpap Mar 15 '13 at 11:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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