26
$\begingroup$

I want

$\left\{\frac{1}{1+\sqrt{2}-\sqrt{3}},\sqrt{5-2 \sqrt{6}},\sqrt{4+\sqrt{15}}\right\}$

to be simplified to

$\left\{\frac{1}{4} \left(2+\sqrt{2}+\sqrt{6}\right), \sqrt{3}-\sqrt{2}, \frac{1}{2} \left(\sqrt{6}+\sqrt{10}\right)\right\}$

But I haven't been able to get that result with Mathematica. How could I get it?

$\endgroup$
3
  • $\begingroup$ You get an immediate answer with FullSimplify[1/(1 + Sqrt[2] - Sqrt[3])] which doesn't coincide with yours. Is this acceptable ? $\endgroup$ Dec 7, 2012 at 13:38
  • 1
    $\begingroup$ Er.I wouldn't like nested radical. $\endgroup$
    – chyanog
    Dec 7, 2012 at 13:51
  • 1
    $\begingroup$ By what measure is the first expression in your output simpler than the first expression in your input? It does not include a nested radical as do the other two. $\endgroup$
    – Mr.Wizard
    Dec 7, 2012 at 15:14

3 Answers 3

28
$\begingroup$

There is a literature on denesting radicals. Not really my strength. In cases where you know (or suspect) the specific radicals that should appear in the result you can use a Groebner basis computation to recast your algebraic value via a minimal polynomial. Then factor over the extension defined by those radicals, solve, and pick the solution that is numerically correct (the others being algebraic conjugates). I illustrate with that first example.

rootpoly = 
 GroebnerBasis[{x*xrecip - 1, xrecip - (1 + y - z), y^2 - 2, z^2 - 3},
    x, {xrecip, y, z}][[1]]

(* -1 + 4*x + 4*x^2 - 16*x^3 + 8*x^4 *)

fax = 
 Select[FactorList[rootpoly, Extension -> {Sqrt[2], Sqrt[3]}][[All, 
    1]], ! FreeQ[#, x] &]

(* {2 + Sqrt[2] + Sqrt[6] - 4*x, -2 - Sqrt[2] + Sqrt[6] + 4*x, 
   2 - Sqrt[2] + Sqrt[6] - 4*x, -2 + Sqrt[2] + Sqrt[6] + 4*x} *)

candidates = Flatten[Map[x /. Solve[# == 0, x] &, fax]];
First[Select[candidates, (N[#] == 1/(1 + Sqrt[2] - Sqrt[3])) &]]

(* (1/4)*(2 + Sqrt[2] + Sqrt[6]) *)

If you are more familiar with manipulating algebraic numbers than you are with Groebner bases, here is a better way to get that defining polynomial.

RootReduce[1/(1 + Sqrt[2] - Sqrt[3])][[1]][x]

(* Out[35]= -1 + 4 x + 4 x^2 - 16 x^3 + 8 x^4 *)

--- edit ---

I will show this in a way that is more automated, in terms of deciding what to use in the extension for factoring. The idea is to allow roots of all factors of all integers that appear in the nested radical.

val = Sqrt[4 + Sqrt[15]];
rootpoly = RootReduce[val][[1]][x]

(* 1 - 8 x^2 + x^4 *)

ints = 
 Flatten[Map[FactorInteger, Cases[val, _Integer, -1]][[All, All, 1]]]

(* {2, 3, 5} *)

fax = 
 Select[FactorList[rootpoly, Extension -> Sqrt[ints]][[All, 1]], ! 
    FreeQ[#, x] &]

(* {Sqrt[6] + Sqrt[10] - 2 x, Sqrt[6] - Sqrt[10] + 2 x, 
 Sqrt[6] - Sqrt[10] - 2 x, Sqrt[6] + Sqrt[10] + 2 x} *)

candidates = Flatten[Map[x /. Solve[# == 0, x] &, fax]];
First[Select[candidates, (N[#] == val) &]]

(* 1/2 (Sqrt[6] + Sqrt[10] *)

--- end edit ---

$\endgroup$
5
  • $\begingroup$ How would this be used for Sqrt[4 + Sqrt[15]]? $\endgroup$
    – Mr.Wizard
    Dec 7, 2012 at 16:42
  • $\begingroup$ @Mr.Wizard See edit. $\endgroup$ Dec 7, 2012 at 18:49
  • 1
    $\begingroup$ Very excellently! $\endgroup$
    – chyanog
    Dec 8, 2012 at 13:04
  • 1
    $\begingroup$ Any reason for doing RootReduce[root][[1]][x] instead of MinimalPolynomial[root, x]? $\endgroup$
    – Greg Hurst
    Jul 15, 2018 at 17:07
  • $\begingroup$ @ChipHurst Probably not. This was so long ago I don't recall the details. Like whether I knew about MinimalPolynomial. $\endgroup$ Jul 16, 2018 at 15:54
5
$\begingroup$

Mathematica uses a ComplexityFunction to measure how 'simple' an expression is. According to the documentation:

ComplexityFunction counts the subexpressions and digits of integers

What we need to do is create a ComplexityFunction that considers the expressions you desire to be very cheap. Depth works for your middle expression

f[x_] := Depth[x];
FullSimplify[{1/(1 + Sqrt[2] - Sqrt[3]), Sqrt[5 - 2*Sqrt[6]], 
  Sqrt[4 + Sqrt[15]]}, ComplexityFunction -> f]

gives

enter image description here

Sadly, the expression you want has the same depth as the expression you started with

Depth[Sqrt[4 + Sqrt[15]]]

4

 Depth[1/2 (Sqrt[6] + Sqrt[10])]

 4

I'm afraid that I couldn't find anything that would Simplify that final expression.

$\endgroup$
2
  • 3
    $\begingroup$ The complexity function is not the problem as one can hack together one that scores the outputs lower than the inputs. However there doesn't seem to be an automatic transformation that produces this result so one will need to introduce a new TransformationFunctions function. $\endgroup$
    – Mr.Wizard
    Dec 7, 2012 at 15:23
  • $\begingroup$ So I have realised since writing the above. Thanks for the extra info. $\endgroup$ Dec 7, 2012 at 15:25
2
$\begingroup$

Input#1:

a + b == (Sqrt[x] + Sqrt[y])^2 == x + y + 2 Sqrt[x*y];
Solve[{x + y == a, 4 x*y == b^2}, {x, y}]
(*
{{x -> 1/2 (a - Sqrt[a^2 - b^2]), y -> 1/2 (a + Sqrt[a^2 - b^2])}, 
{x -> 1/2 (a + Sqrt[a^2 - b^2]), 
y -> 1/2 (a - Sqrt[a^2 - b^2])}}*)

Define function:

f[a_, b_] := 
 Simplify[Sqrt[1/2 (a - Sqrt[a^2 - b^2])] + 
 Sqrt[1/2 (a + Sqrt[a^2 - b^2])]]

Input#2:

f[5, 2 Sqrt[6]]
f[4, Sqrt[15]]

Output#2:

Sqrt[2] + Sqrt[3]
Sqrt[3/2] + Sqrt[5/2]

The Simplify of 1/(1 + Sqrt[2] - Sqrt[3])

Expand[(1 + Sqrt[2] - Sqrt[3]) (1 + Sqrt[2] + Sqrt[3])]
(*2 Sqrt[2]*)
FullSimplify[(Sqrt[2] + 1 + Sqrt[3])/(2 Sqrt[2])]
(*1/4 (2 + Sqrt[2] + Sqrt[6])*)

Picture: The simplify of 1/(b + Sqrt[a] - Sqrt[c])

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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