In my research project, I'm working with the following polynomial $$p(x) = 1 + 2x + 3x^2 + \ldots + nx^{n-1} + nx^n + nx^{n+1} + (n-1)x^{n+2} + (n-2)x^{n+3} + \ldots + 2x^{2n-1} + x^{2n}$$ or $$nx^n +\sum_{i=0}^{n-1}(i+1)x^{2n-i}+(i+1)x^i.$$ Now I would like this to be recognized as a polynomial by Mathematica, so I tried expanding it out with Expand[Sum[(i + 1) x^(2 n - i) + (i + 1) x^i, {i, 0, n - 1}] + n x^n]. That, however, computes the actual sum of the series, and it is no longer a polynomial.

So how do I make Mathematica just treat the sum "as is" so it is recognized as a polynomial? (Ultimately, I'm trying to determine if $p$ has roots of multiplicity $> 1$.)

  • 1
    $\begingroup$ I am not sure what you mean. What output do you expect to get? Does Total@Table[(i + 1) x^(2 n - i) + (i + 1) x^i, {i, 0, n - 1}] + n x^n do what you expect for any integer n>0? $\endgroup$
    – Somos
    Jul 10, 2023 at 23:32
  • $\begingroup$ Sorry for not being more clear — I use Mathematica very infrequently. I just want the polynomial above to "stay" a polynomial. I do not want Mathematica to evaluate it into a closed form result because after that I wish to take the resultant of $p$ and its reciprocal polynomial $p'$. The command you suggested returns an iterator does not have appropriate bounds error. $\endgroup$
    – wol
    Jul 10, 2023 at 23:40
  • 1
    $\begingroup$ Again, exactly what output do you expect to get? For any specific integer n>0 the code I gave produces a polynomial expression in x. Does using Defer[] help? As in Defer@Sum[(i + 1) x^(2 n - i) + (i + 1) x^i, {i, 0, n - 1}] + n x^n? $\endgroup$
    – Somos
    Jul 10, 2023 at 23:42
  • 1
    $\begingroup$ Well, ... is not a Mathematica expression. If that is what you want, then no Computer Algebra System can help you with this. $\endgroup$
    – Somos
    Jul 10, 2023 at 23:56
  • 2
    $\begingroup$ It seems that when n is even, -1 is a repeated root, and otherwise there are no repeated roots. $\endgroup$
    – Carl Woll
    Jul 11, 2023 at 14:07

2 Answers 2


Your question is about a polynomial

p[n_] := n*x^n + Sum[ (i+1)*x^(2*n-i) + (i+1)*x^i, {i, 0, n-1}];
(* ((-1 + x^n)*(-1 + x^(2 + n)))/(-1 + x)^2 *)

which Mathematica is able to partially factor.

For any integer $\,n>0\,$ the polynomial $\,x^n-1\,$ has $\,n\,$ roots being all the $n$-th roots of unity. Thus it factors into $\,n\,$ linear factors, one for each $n$-th root of unity.

If $\,n>0\,$ is an integer then $\,x-1\,$ is a factor of $\,x^n-1\,$ because $1$ is a $n$-th root of unity. If $\,n>0\,$ is an even integer then $\,x+1\,$ is also a factor because $-1$ is also a $n$-th root of unity. In both cases, all other factors are complex conjugate pairs.

Now we define the polynomial $$ p_n := \frac{(x^n-1)(x^{n+2}-1)}{(x-1)^2}. $$ If $\,n>0 \,$ is even, then $\,n+2\,$ is also even which implies that $\,(x+1)^2\,$ is a factor of $\,p_n.\,$ If $\,n>0\,$ is odd, then $\,p_n\,$ has no real factors, only complex conjugate factors.

Your ultimate question

(Ultimately, I'm trying to determine if p has roots of multiplicity >1.)

has the answer yes if and only if $n$ is even.

Your penultimate question

So how do I make Mathematica just treat the sum "as is" so it is recognized as a polynomial?

is not possible. For example, you may think that x^n-1 and x^n+1 are both polynomials and therefore you could try to evaluate Resultant[x^n+1,x^n-1,x]. The error message you get

... Resultant::poly2: 1+x^n is not a well-formed polynomial in x.

is because a polynomial in x for this purpose must have a degree which evaluates to an explicit integer and n is a symbol with no value and does not evaluate to an explicit integer.

What does work is something such as

Resultant[x^3 + b, x^2 + a, x]
(* a^3 + b^2 *)

The automatic Simplify is using the trivial school algebra formula

     Sum[x^i,{i,0,n}]== (x^(n+1)-1)/(x-1)
     Sum[(i+1)x^i ,{i,0,n} ] == D[Sum[x^(i+1),{i,0,n}],x]

and represents it in the shortest form.

Your first term may stay evaluated but un-simplified for any integer n as

   p[x_, n_] :=Append[ Plus @@ Array[ # x^# &, n],\[Ellipsis]]

   p[x, 3]

$$ x+ 2 x^2 + 3 x^3 +\ldots$$

Here the dots prevent evaluations. You can freeze expressions in a preferred form by Inactivate for manipulations or by HoldForm for printing purposes.

  • $\begingroup$ Unfortunately, this does not really answer the question asked, but nice try. $\endgroup$
    – Somos
    Jul 11, 2023 at 21:54
  • $\begingroup$ Fortuntely, such questions about trying to prevent a CAS doing its job, demand some fantasy. $\endgroup$
    – Roland F
    Jul 12, 2023 at 7:46

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.