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


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?

  • $\begingroup$ 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? $\endgroup$ – rcollyer Dec 12 '12 at 14:41
  • $\begingroup$ For what it's worth FullSimplify[expr == r, r > 0] returns True. $\endgroup$ – Mr.Wizard Dec 12 '12 at 15:07
  • $\begingroup$ 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. $\endgroup$ – 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 *)
| improve this answer | |
  • $\begingroup$ Series[expr, {r, 0, 10}] This trick may be helpful for other similar expressions that appear in my rather lengthy matrix. $\endgroup$ – arkajad Dec 12 '12 at 15:25
  • $\begingroup$ @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! $\endgroup$ – 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

Plot of the imaginary and real plane values of the expressions compared

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]


| improve this answer | |
  • $\begingroup$ Hey not bad - +1 $\endgroup$ – Mark McClure Dec 12 '12 at 15:08
  • $\begingroup$ 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? $\endgroup$ – arkajad Dec 12 '12 at 15:33
  • $\begingroup$ 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. $\endgroup$ – murray Dec 12 '12 at 16:48
  • $\begingroup$ @murray doesn't Surd[x,2] fit that description? Or am I misunderstanding you. $\endgroup$ – jVincent Dec 12 '12 at 16:55
  • $\begingroup$ @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. $\endgroup$ – murray Dec 12 '12 at 23:14

Is this helpful ?

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 *)
| improve this answer | |
  • $\begingroup$ A point of note, the second parameter of Simplify and FullSimplify is for assumptions, although your form does work. $\endgroup$ – rcollyer Dec 12 '12 at 14:42
  • $\begingroup$ 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? $\endgroup$ – arkajad Dec 12 '12 at 15:03
  • $\begingroup$ @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.). $\endgroup$ – Itai Seggev Dec 13 '12 at 23:06
  • $\begingroup$ @ItaiSeggev I had never looked that deeply, thanks. $\endgroup$ – rcollyer Dec 14 '12 at 0:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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