Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
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
add comment

3 Answers

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]

y

share|improve this answer
    
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
add comment

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 *)
share|improve this answer
    
Series[expr, {r, 0, 10}] –  arkajad Dec 12 '12 at 15:23
    
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
add comment

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 *)
share|improve this answer
    
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
    
Thank you, I didn't know. –  b.gatessucks Dec 12 '12 at 14:44
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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