# How to simplify to form without imaginary unit

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?

Edit:

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))

• Look at ComplexExpand. Otherwise please provide a sample problem. Dec 17, 2013 at 14:01
• I provided the expression I'm trying to simplify. Dec 17, 2013 at 14:12
• 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. Dec 17, 2013 at 14:44
• @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). Dec 17, 2013 at 15:24
• 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.
– Hbar
Dec 18, 2013 at 6:07

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[
ComplexExpand@Im[u]/ComplexExpand@Re[u]
];
f2 = f1 /. Arg[x_] :> modify[x];
result = FullSimplify[FunctionExpand@Simplify[f2]]


Not very elegant, but will work with simple roots.

• 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? Dec 19, 2013 at 9:14
• 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. Dec 19, 2013 at 9:27