# Expressing $x_{1} ^ n + x_{2}^ n$, where $x_{1}$ and $x_{2}$ are the roots of $ax^2 +bx+c=0$

The roots $x_{1}$ and $x_{2}$ of

$$ax^{2}+bx+c=0$$

satisfy

$$x_{1}+x_{2}=\frac{-b}{a}$$ and $$x_{1}x_{2}=\frac{c}{a}$$

I need Mathematica to give me $x_{1} ^ n + x_{2}^ n$ for any $n$; that is:

$${x_{1}}^{2}+{x_{2}}^{2}=(x_{1}+x_{2})^{2} -2x_{1}x_{2} = \frac{b^2-2ac}{a^2}$$

$${x_{1}}^{3}+{x_{2}}^{3}=(x_{1}+x_{2})\left ( (x_{1}+x_{2})^{2}-3x_{1}x_{2} \right )=\frac{3abc-b^3}{a^3}$$

$$\dots$$

edit: $${x_{1}}^{2}+{x_{2}}^{2}=\underset{\text{I also need this in all cases}}{{(x_{1}+x_{2})^{2} -2x_{1}x_{2}}} = \frac{b^2-2ac}{a^2}$$

I need $x_{1} ^ n + x_{2}^ n$ for any $n$ In terms of (Or as a function of) $$x_{1}+x_{2}$$ and $$x_{1}x_{2}$$

• {x1, x2} = x /. Solve[a x^2 + b x + c == 0, x]; f[n_] := Together@FullSimplify[x1^n + x2^n]; f – corey979 Jan 24 '17 at 0:13
• Thanks,I need the final structure in terms of x1 and x2 also for each case, not just the final result – zeros Jan 24 '17 at 0:28

SymmetricReduction is a good tool for this:

First @ SymmetricReduction[x1^2+x2^2,{x1,x2}, {-b/a, c/a}]
First @ SymmetricReduction[x1^3+x2^3,{x1,x2}, {-b/a, c/a}]
First @ SymmetricReduction[x1^4+x2^4,{x1,x2}, {-b/a, c/a}]

b^2/a^2-(2 c)/a
-(b^3/a^3)+(3 b c)/a^2
b^4/a^4-(4 b^2 c)/a^3+(2 c^2)/a^2

• Thanks , I need the final structure in terms of x1 and x2 also for each case, not just the final result – zeros Jan 24 '17 at 0:28
• First @ SymmetricReduction[x1^4+x2^4, {x1, x2}] ? – Carl Woll Jan 24 '17 at 0:35
• Watch what I edited – zeros Jan 24 '17 at 2:45
• @zeros, and as Carl already said, First @ SymmetricReduction[x1^3 + x2^3, {x1, x2}] already displays the symmetric form explicitly; what is missing there? – J. M.'s technical difficulties Jan 24 '17 at 2:49
• ok, ok ,ok , Run in a new notebook and work thanks – zeros Jan 24 '17 at 4:20

Recalling the relationship between sums of powers and linear recurrence relations, here is how one can use LinearRecurrence[] to generate the required expressions:

LinearRecurrence[{-b/a, -c/a}, {2, -b/a}, 5] // Simplify
{2, -b/a, (b^2 - 2 a c)/a^2, -(b^3 - 3 a b c)/a^3, (b^4 - 4 a b^2 c + 2 a^2 c^2)/a^4}


Using Inactivate[] on the symmetric polynomials involved yields the expressions for the power sums in terms of symmetric polynomials of the roots:

LinearRecurrence[{Inactivate[x1 + x2], -Inactivate[x1 x2]},
{2, Inactivate[x1 + x2]}, 5] // Simplify // Activate

{2, x1 + x2, -2 x1 x2 + (x1 + x2)^2, -3 x1 x2 (x1 + x2) + (x1 + x2)^3,
2 x1^2 x2^2 - 4 x1 x2 (x1 + x2)^2 + (x1 + x2)^4}


Carl has already mentioned SymmetricReduction[] and its convenient third argument, if you're looking to explicitly display the Newton-Girard formulae. If you'll look at that last link, you'll see that a nice linear equation is satisfied between power sums and symmetric polynomials; you might want to try formulating this in terms of LinearSolve[].

• Watch what I edited – zeros Jan 24 '17 at 2:46

One can obtan this as the solution to a certain recurrence equation. Call the nth term f[n], and the roots x1 and x2. Then

f[n] = (x1+x2)^n =
(x1+x2)*(x1^(n-1)+x2^(n-1)) - (x1*x2^(n-1)+x2*x1^(n-1)) =
(x1+x2)*(x1^(n-1)+x2^(n-1)) - x1*x2*(x1^(n-2)+x2^(n-2)) =
f*f[n-1] - x1*x2*f[n-2]


Now suppose we make the quadratic monic, so it is x^2-b*x+c (the negative for the linear term coefficient is from expanding (x-x1)*(x-x2) and getting x^2-(x+x2)*x+x1*x2). With this convention, we have f==b and we also require that f==2 (which is the sum of the roots to the zeroth power).

rtpowersums =
RSolveValue[{f[n] == b*f[n - 1] - c*f[n - 2], f == b, f == 2},
f[n], n]

(* Out= 2^-n ((b - Sqrt[b^2 - 4 c])^n + (b + Sqrt[b^2 - 4 c])^n) *)


Quick test for case where roots are 2 and 3:

tt = Table[Expand[rtpowersums], {n, 1, 5}]
tt /. {b -> 5, c -> 6}

(* Out= {b, b^2 - 2 c, b^3 - 3 b c, b^4 - 4 b^2 c + 2 c^2,
b^5 - 5 b^3 c + 5 b c^2}

Out= {5, 13, 35, 97, 275} *)

Table[2^n + 3^n, {n, 5}]

(* Out= {5, 13, 35, 97, 275} *)


It's seem the RootSum is your after,of course,it just show the result.

RootSum[a #^2 + b # + c &, #^1 &] // FullSimplify
RootSum[a #^2 + b # + c &, #^2 &] // FullSimplify
RootSum[a #^2 + b # + c &, #^3 &] // FullSimplify
RootSum[a #^2 + b # + c &, #^4 &] // FullSimplify 