I have an integral that I compute with Mathematica and as a result I get a seemingly complex expression (i.e. the expression contains the imaginary unit, $i$, at some places). However, if I try to numerically compute the values of this expression at some values of my variables, I notice that in fact the value of the result is always real (for real values of variables); the imaginary parts cancel out in a right way to make the result real. This is also evident from the fact that the expression is a solution to a physical problem that is supposed to give a real solution.

How do I make Mathematica simplify the expression so that it doesn't contain any imaginary units anymore?


The expression I'm trying to simplify is:

$$\frac{\sqrt{1-\frac{2}{-i x+y+1}}}{x+i (y-1)}+\frac{\sqrt{1-\frac{2}{i x+y+1}}}{x-i (y-1)}$$

In Mathematica form:

Sqrt[1 - 2/(1 - I x + y)]/(x + I (-1 + y)) + Sqrt[1 - 2/(1 + I x + y)]/(x - I (-1 + y))
  • $\begingroup$ Look at ComplexExpand. Otherwise please provide a sample problem. $\endgroup$
    – Mr.Wizard
    Dec 17, 2013 at 14:01
  • 1
    $\begingroup$ I provided the expression I'm trying to simplify. $\endgroup$
    – Echows
    Dec 17, 2013 at 14:12
  • 1
    $\begingroup$ You can't simplify your expression to another one explicitly real without appropriate assumptions. Try e.g. With[{x = -1, y = -1}, FullSimplify[ Sqrt[(1 - 2/(-I x + y + 1))/(x + I (y - 1))] + Sqrt[( 1 - 2/(I x + y + 1))/(x - I (y - 1))]]] which yields 2 I. This post shows how one could approach similar problems Simplifying expressions with square roots. $\endgroup$
    – Artes
    Dec 17, 2013 at 14:44
  • 3
    $\begingroup$ @Artes -- you've got the square root in the wrong place. The OPs function is f[x_, y_] := Sqrt[(1 - 2/(-I x + y + 1))]/(x + I (y - 1)) + Sqrt[(1 - 2/(I x + y + 1))]/(x - I (y - 1)) which is real-valued (at least at -1,-1). $\endgroup$
    – bill s
    Dec 17, 2013 at 15:24
  • $\begingroup$ The expression reduces to: $$ \sqrt{2} \, \text{sign}(x) \frac{ \sqrt{ \left(x^2+(y-1)^2\right) \left( 1 + x^2 - y^2 + \sqrt{ 2 \left( x^2-1 \right) y^2 + \left( x^2+1 \right)^2 + y^4 } \right) } }{ \left( x^2+(y-1)^2 \right) \sqrt{x^2+y^2+2 y+1} } $$ but I cannot find an easy way to get Mathematica to produce it. $\endgroup$
    – Hbar
    Dec 18, 2013 at 6:07

1 Answer 1


The problem with simplifying things with square roots is remaining in the branch while assuming that $\sqrt{a} \sqrt{b} = \sqrt{ a b}$. Getting this right usually requires analyzing the possible values of $a$ and $b$. For your expression, ComplexExpand gives just a few simple Args to deal with, making it possible to finish the problem with a substitution.

f = Sqrt[1 - 2/(1 - I x + y)]/(x + I (-1 + y)) + 
   Sqrt[1 - 2/(1 + I x + y)]/(x - I (-1 + y));
f1 = ComplexExpand[f];
modify[u_] := ArcTan@FullSimplify[
f2 = f1 /. Arg[x_] :> modify[x];
result = FullSimplify[FunctionExpand@Simplify[f2]]

Not very elegant, but will work with simple roots.

  • $\begingroup$ It seems to work... almost. When I plot the expression I get as a result it looks like it differs from the original expression for arguments $|y|,|x|<1$. I don't really understand what this does, though. I guess my Mathematica knowledge is lacking. What does @ and :> do? $\endgroup$
    – Echows
    Dec 19, 2013 at 9:14
  • $\begingroup$ Nevermind, I figured out your code. I still have to figure out how to repair the wrong result for certain arguments. It probably has something to do with choosing the wrong branch of arctan or something. $\endgroup$
    – Echows
    Dec 19, 2013 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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