# How to convert an expression a + b*Sqrt[c] to a simpler format?

Example: we have the following expansions:

 Table[Expand[(1 + Sqrt)^k], {k, 1, 6}]

(* {1 + Sqrt, 3 + 2 Sqrt, 7 + 5 Sqrt, 17 + 12 Sqrt, 41 + 29 Sqrt, 99 + 70 Sqrt} *)


Or, the powers of GoldenRatio:

  Table[Expand[((1 + Sqrt)/2)^k], {k, 1, 6}]

(* {1/2 + Sqrt/2, 3/2 + Sqrt/2, 2 + Sqrt, 7/2 + (3 Sqrt)/2, 11/2 + (5 Sqrt)/2, 9 + 4 Sqrt} *)


My questions are:

How to convert an expression 99 + 70 Sqrt back to (1 + Sqrt)^6 ?

How to convert (11 + 5*Sqrt)/2 back to GoldenRatio^5 ?

In general, how to factor a + b*Sqrt[c] to a power format (if it exists) ?

UPDATE: Thanks to all for the inspiration!

My problem is to solve

  a + b*Sqrt[c] == (r + s*Sqrt[c])^k


where r, s and k are unknown and all variables are integer.

Unfortunately I get from

  Solve[(99 + 70 Sqrt) == Expand[(r + s*Sqrt)^k] && k > 0, {r, s, k}, Integers]


an error message: "This system cannot be solved with the methods available to Solve."

Of course, brute force method over integers is possible, but has anybody an idea, how to solve this equation in integers, for example some additional options in the "Solve[]" statement ?

However, brute force is not good method for simplification of

  11880235445948416 + 2206039924408320*Sqrt


Here's an approach that works when the field norm is not $\pm 1$. Unfortunately both of your examples have norm $-1$, but maybe the following approach can be extended to this case.

AlgebraicNumberNorm /@ {1 + Sqrt, (1 + Sqrt)/2}

(* {-1, -1} *)


When an algebraic number is a power of $k$, the absolute value of its norm is also a power of $k$.

So, we can factor the norm over the integers. If it's not a perfect power, we know the algebraic number is not a perfect power. Otherwise, we can test the divisors of the exponent. Since $1$ is a perfect power for any exponent, this approach won't work.

Consider the example:

η = 1472 - 640 I Sqrt;


Here's its norm:

norm = AlgebraicNumberNorm[η]

(* 2985984 *)

FactorInteger[Abs[norm]]

(* {{2, 12}, {3, 6}} *)


We see norm is a power of $6$, so $\eta$ could be a power of $6$, $3$, $2$, or $1$.

cands = Reverse[Divisors];


Now we select the largest $k$ such that a Galois conjugate of $\eta^{1/k}$ has degree $2$:

algebraicDegree[η_] := Exponent[MinimalPolynomial[η, x], x]

kthPowerQ[η_][k_] :=
Min[algebraicDegree[# η^(1/k)]& /@ Exp[2Range[k]π I/k]] == 2

k = SelectFirst[cands, kthPowerQ[η]]

(* 6 *)


Factor to see $1472 - 640i\sqrt{2} = (2 + 2i\sqrt{2}\,)^6$:

base = SelectFirst[Exp[2Range[k]π I/k] η^(1/k), algebraicDegree[#] == 2&];

RootReduce[base]^k

(* (2 + 2 I Sqrt)^6 *)

• This solution is best! We have 11880235445948416 + 2206039924408320*Sqrt = (7 + 3*Sqrt)^12 Nov 28, 2017 at 18:14
• Can you please explain how your method work. Can it be used to simplify expressions with cubic roots? Nov 29, 2017 at 7:32
expr = Table[(1 + Sqrt)^k, {k, 1, 6}];

LeafCount /@ expr

(* {7, 9, 9, 9, 9, 9} *)

expr2 = Table[Expand[(1 + Sqrt)^k], {k, 1, 6}];

LeafCount /@ expr2

(* {7, 9, 9, 9, 9, 9} *)


Since the LeafCount is the same for the expressions, you would need to use a custom ComplexityFunction to favor the desired form with Simplify or FullSimplify. However, if you know the desired form

expr3 = (99 + 70 Sqrt);

expr3a = (a + Sqrt)^n /. NMinimize[{Abs[expr3 - (a + Sqrt)^n],
Element[{a, n}, Integers], n > 1}, {a, n}][] // Quiet

(* (1 + Sqrt)^6 *)

expr3b = (a + b Sqrt)^n /. NMinimize[{Abs[expr3 - (a + b Sqrt)^n],
Element[{a, b, n}, Integers], n > 1}, {a, b, n}][] // Quiet

(* (3 + 2*Sqrt)^3 *)


Verifying

expr3 == expr3a == expr3b // Simplify

(* True *)

expr4 = (11 + 5*Sqrt)/2;

expr4a = a*GoldenRatio^n /. NMinimize[{Abs[expr4 - (a*GoldenRatio^n)],
Element[{a, n}, Integers], n > 1}, {a, n}][] // Quiet

(* GoldenRatio^5 *)

expr4b = (a + b*GoldenRatio)^n /.
NMinimize[{Abs[expr4 - (a + b*GoldenRatio)^n],
Element[{a, b, n}, Integers], n > 1}, {a, b, n}][] // Quiet

(* GoldenRatio^5 *)


Verifying

expr4 == expr4a == expr4b // Simplify

(* True *)

• This method is possible, but verification is necessary, because from 98 + 70 Sqrt I get same result, which is incorrect. Nov 28, 2017 at 17:11