# Mathematica not simplifying square root expressions even with assumptions

I have the following expression:

expr=(Sqrt[2]r Sqrt[(4+r^2) (2+r (r+Sqrt[4+r^2]))])/(4+r (r+Sqrt[4+r^2]))


Then

FullSimplify[expr, r > 0]


just returns the expression. However

Plot[expr, {r, 0, 10}]


shows that it is just r in disguise. Is there any way I can tell Mathematica to be smarter? Which tricks should I use in cases like that above?

• Since you ask: "how can I tell Mathematica to be smarter?" I have to ask, prior to plotting the function, did you have any insight into what the answer should be? Admittedly, I've only given it a cursory inspection, but I would not have guessed that it is equal to r. The reason I ask is Mathematica is a tool, like any other, and while it may see things you don't, there is no guarantee for any given problem that will be true. Since your insight led you to plot it, what must hold true in the expression for expr == r to be true? How would you demonstrate that? – rcollyer Dec 12 '12 at 14:41
• For what it's worth FullSimplify[expr == r, r > 0] returns True. – Mr.Wizard Dec 12 '12 at 15:07
• Well, it came from first doing SingularValueDecomposition of a matrix and then trying to check it back. Instead of r, as in the original matrix, I have found this complicated expression. So, my guess is it should be r. But then I want to do other things with my decomposition and I would like Mathematica to simplify my expressions automatically. Telling Mathematica that r>0 is evidently not enough. The only thing that can help is probably spotting possible simplifications with an eye, checking them, then making rules as suggested in one of the comments below. – arkajad Dec 12 '12 at 15:21

I guess that the following shows that expr is $\pm r$:

FullSimplify[expr^2 , Assumptions -> Element[r, Reals]]
(* Out: r^2 *)


And then this shows that it's got to be $r$.

Series[expr, {r, 0, 10}]
(* Out: r + O[r]^11 *)

• Series[expr, {r, 0, 10}] This trick may be helpful for other similar expressions that appear in my rather lengthy matrix. – arkajad Dec 12 '12 at 15:25
• @arkajad Yes - it's a nice trick to find out what your expression should be. Sometimes, that makes it simpler to prove what you want! – Mark McClure Dec 12 '12 at 15:27

Sometimes Mathematica doesn't do simplifications because it's not making any implied assumptions of whether the numbers involved are complex or not. If you plot your expression you can see that it's not equal to r for all complex numbers, only on the line r>0. That being said, I'm not sure exactly what is needed to coax Simplify into returning this, when you are in fact telling it to only consider this line.

 Table[Plot3D[plane@(exp /. r -> x + I y), {x, -10, 10}, {y, -10, 10},
AxesLabel -> {"Re", "Im"}],  {plane, {Re, Im}}, {exp, {expr, r}}] // GraphicsGrid


The closest to I can get is to call

 Reduce[y == expr && r > 0, r, Reals]

y > 0 && r == Sqrt[y^2]

 Simplify[Sqrt[y^2], y > 0]


y

• Hey not bad - +1 – Mark McClure Dec 12 '12 at 15:08
• So there is no way to tell Mathematica that all square roots in a particular expression involving only real number variables should be understood as positive square roots? – arkajad Dec 12 '12 at 15:33
• And while Wolfram has grudgingly added in version 9 a new function CubeRoot for the real-valued cube-root, it has not done a similar thing for square-root. – murray Dec 12 '12 at 16:48
• @murray doesn't Surd[x,2] fit that description? Or am I misunderstanding you. – jVincent Dec 12 '12 at 16:55
• @jVincent: You didn't misunderstand; I just forgot about the new-in-9 Surd, which of course generalizes the new CubeRoot. Still, would adding a new SquareRoot alongside CubeRoot be a bad idea? (Perhaps too easily confused with Sqrt, whereas there is/was no such thing already as Curt. – murray Dec 12 '12 at 23:14

FullSimplify[expr^2, Assumptions->{r > 0}]
(* r^2 *)


Another way is to define an ad hoc rule :

myRule = 2 + r (r + Sqrt[4 + r^2]) -> 1/2 (r + Sqrt[4 + r^2])^2 ;

FullSimplify[expr /. myRule, r > 0]
(* r *)

• A point of note, the second parameter of Simplify and FullSimplify is for assumptions, although your form does work. – rcollyer Dec 12 '12 at 14:42
• Thanks. But the point is that I have extracted my expression from a larger expression. When I have just one separate expression, your trick may help indeed. But it is not so simple to go through the output and look which part of it can possibly be simplified to such a degree as in my example. Shouldn't it be a part of the simplification algorithms? – arkajad Dec 12 '12 at 15:03
• @rcollyer However, assumptions in the second argument and assumptions in an option are different. If the second argument, they override any existing assumptions. As an option, they append to any existing assumptions (from \$Assumptions, and external Assuming, etc.). – Itai Seggev Dec 13 '12 at 23:06
• @ItaiSeggev I had never looked that deeply, thanks. – rcollyer Dec 14 '12 at 0:50