# How can I get Mathematica to simplify this i * sqrt expression

In[11]:= FullSimplify[I Sqrt[-1 + w^2], Element[w, Reals],
Assumptions -> 0 <= w <= 1]

Out[11]= I Sqrt[-1 + w^2]


Is it possible to have Mathematica simplify this to:

-Sqrt[1 - w^2]


I can of course do this manually, but this is part of a much larger expression that I want to simplify for all pieces to be real.

• There's a lot of steps to cover here. But most importantly: What you want it to simplify to isn't equal to the original expression. Because of branch cuts. To see this, put in a test value for w into both and see that they have opposite sign. – Searke Mar 28 '16 at 14:41
• I don't follow your comment, on the interval of w from 0 to 1 as in the simplify assumptions above, they have the same sign. – ddd Apr 21 '16 at 14:07

I should start by pointing out that these aren't equal:

I Sqrt[-1 + w^2]

-Sqrt[1 - w^2]


Test them with a specific value. The problem isn't that you are reasoning about them wrong, the problem is that there's a complex branch cut and you're interpreting it differently. Either way, I'll work with this expression instead to avoid ambiguity.

Abs[I Sqrt[-1 + w^2]]


"Simplifying" isn't a well defined operation. Mathematica uses the leaf count of the parsed expression to determine how complicated something is and then searches for "simpler" expressions. See LeafCount for more information. Both of your expressions have the same leaf count so Mathematica considers them equivalently complex.

It is possible to change this behavior using the option ComplexityFunction. See the documentation for examples of how it is used. Below is basically just the documentation adapted for your purposes:

(* Penalize all instances of "I" in an expression *)
myComplexityFunction[e_] := 100 Count[e, I, {0, Infinity}] + LeafCount[e]

(* Simplify with this penalty *)
FullSimplify[Abs[I Sqrt[-1 + w^2]], Assumptions -> 1/2 < w <= 1,
ComplexityFunction -> myComplexityFunction]

Sqrt[Abs[-1 + w^2]]

expr = I Sqrt[-1 + w^2];


Using a Rule

expr2 = I Sqrt[-1 + w^2] /. Sqrt[x_] -> I*Sqrt[-x]

(*  -Sqrt[1 - w^2]  *)


On the specified interval, 0 <= w <= 1

expr == expr2 /. w -> RandomReal[]

(*  True  *)

Plot[{expr, expr2}, {w, 0, 1},
PlotStyle -> {
Directive[Blue, AbsoluteDashing[{10, 5}]],
Directive[Red, AbsoluteDashing[{5, 10}]]},
PlotLegends -> "Expressions"]


Or, on the broader interval, -1 <= w <= 1

Plot[{expr, expr2}, {w, -1, 1},
PlotStyle -> {
Directive[Blue, AbsoluteDashing[{10, 5}]],
Directive[Red, AbsoluteDashing[{5, 10}]]},
PlotLegends -> "Expressions"]