# Simplification of algebraic expression

I found an entry of a matrix from two different methods using mathematica. Which are given as;

g/(Sqrt Sqrt[1 + g^2 - Sqrt[1 + g^2]])


and

1/Sqrt[2 + (2 - 2 Sqrt[1 + g^2])/g^2].


Logically these expression should be same, and they simplify to same result when i do it on paper. But when i plot these expressions for {g,-5,5}, it gives different plots on mathematica. What is happening?

• Sqrt[g^2] is not equal to g, when g is negative. – bbgodfrey Jan 18 '15 at 16:44
• @bbgodfrey, but these should reduce to single simplified form? – Usman Jan 18 '15 at 17:07
• @Usman All you need you could find here: Simplifying expressions with square roots – Artes Jan 18 '15 at 17:15
• @Usman, No. Sqrt[g^2] is a Mathematica function equal to g for g > 0 and to -g for g < 0. To go from your first expression to your second involves multiplying the first function by Sqrt[g^2]/g, which is not equal to one for negative g. – bbgodfrey Jan 18 '15 at 17:18
• The two plots are exactly the same for g>0 but not for g<0, as per bbgodfrey's comment. – Stelios Jan 18 '15 at 17:21

These are two simplifications of the same second expression with different ConplexityFunction used:

 Simplify[1/Sqrt[2 + (2 - 2 Sqrt[1 + g^2])/g^2], g > 0]

Simplify[1/Sqrt[2 + (2 - 2 Sqrt[1 + g^2])/g^2], g > 0,
ComplexityFunction -> (StringLength[ToString[#]] &)]


yielding the following:

(*  1/Sqrt[2 + (2 - 2 Sqrt[1 + g^2])/g^2]  *)
(*  g/(Sqrt Sqrt[1 + g^2 - Sqrt[1 + g^2]])  *)


Have fun!