I would like to compute the coefficient in front of $n^p$ for a polynomial expansion.

I wrote the following code:

f[n_, q1_, q2_] := (n^q1 + (n + 1)^q1)* (n^q2 + (n + 1)^q2)

SeriesCoefficient[f[n, q1, q2], {n, 0, p}, 
 Assumptions -> {Element[q1, Integers] && q1 >= 0, 
   Element[q2, Integers] && q2 >= 0 }]

However, Mathematica is unable to return a result. Why?

I would expect an expression that consists of binomial coefficients (I can do it by hand, it is not very complicated, thus I wonder why Mathematica cannot).

  • $\begingroup$ Because your question can't be answered with the given information. We don't know how p relates to q1 and q2. There is no problem if they are specific given integers. $\endgroup$
    – Somos
    Jul 10 '19 at 17:06
  • $\begingroup$ @Somos $p$ is the coefficient in front of $n^p$. I think the question makes sense: if $p>q1+q2$ then the coefficient would be $0$ but if $0 \leq p \leq q1+q2$ I expect to have an answer (mathematica could give me a conditional answer). $\endgroup$
    – StarBucK
    Jul 10 '19 at 17:08
  • $\begingroup$ Well, you have a point. The code SeriesCoefficient[(n + 1)^q, {n, 0, p}] returns a conditional result but SeriesCoefficient[n^q + (n + 1)^q, {n, 0, p}] returns unchanged. $\endgroup$
    – Somos
    Jul 10 '19 at 17:13
  • $\begingroup$ You can get Mathematica to do much of what you want but you'll have to write your own rules (mathematica.stackexchange.com/questions/142077/…) and use the Inactive[Sum] function (mathematica.stackexchange.com/questions/7886/…). $\endgroup$
    – JimB
    Jul 11 '19 at 15:15
  • $\begingroup$ When integers are used in place of the variables, your formula gives the desired result. The general result will be very complicated and it's not even clear that it might be useful to you. Consider when $0 \leq p \leq q_1+q_2$. There will be potentially multiple terms with some of which will depend on whether $0 \leq p \leq Min(q_1,q_2)$. In other words, the general result will include a bunch of terms in a Piecewise structure. Is that what you need? It won't be a single binomial coefficient. $\endgroup$
    – JimB
    Jul 11 '19 at 17:52

You can recast your expression as:

e = (1+(1+1/n)^q1) (1+(1+1/n)^q2) n^(q1+q2);

Then, the coefficient you're interested in is:

coeff[k_] = SeriesCoefficient[(1+(1+1/n)^q1) (1+(1+1/n)^q2), {n, Infinity, -k + q1 + q2}]

Unfortunately, there seems to be a bug with the above SeriesCoefficient call. So, instead, I will introduce a scaling parameter s:

coeff[k_] = SeriesCoefficient[(1 + (1 + s/n)^q1) (1 + (1 + s/n)^q2), {s, 0, -k + q1 + q2}] /. n->1;
coeff[k] //TeXForm

$\begin{cases} \binom{\text{q1}}{-k+\text{q1}+\text{q2}}+\binom{\text{q2}}{-k+\text{q1}+\text{q2}}+\binom{\text{q1}+\text{q2}}{-k+\text{q1}+\text{q2}} & -k+\text{q1}+\text{q2}>0 \\ 4 & -k+\text{q1}+\text{q2}=0 \end{cases}$

Let's check:

q1 = 5;
q2 = 7;
Series[e, {n, 0, 12}] //TeXForm

$1+12 n+66 n^2+220 n^3+495 n^4+793 n^5+931 n^6+814 n^7+535 n^8+265 n^9+97 n^{10}+24 n^{11}+4 n^{12}+O\left(n^{13}\right)$

Using coeff;

Table[coeff[k], {k, 0, 12}]

{1, 12, 66, 220, 495, 793, 931, 814, 535, 265, 97, 24, 4}

  • 1
    $\begingroup$ Very good. But how did you know to recast the equation? Or how would us mortals ever guess at that? (Not to mention the introduction of the scaling parameter. That's appears to be voodoo.) $\endgroup$
    – JimB
    Jul 12 '19 at 3:12

Every computer algebra system has its limits. The Mathematica code

SeriesCoefficient[n^q, {n, 0, p}]

returns the input unchanged. It should have returned

Piecewise[{{1, p == q}}]

or some equivalent result, but that is not its current behavior. This is the key reason why you did not get the answer you expected from Mathematica.

You could send a suggestion to change its behavior to Wolfram Research.

  • $\begingroup$ Thank you for your answer. I think with respect to this kind of question Mathematica is then quite limited. Because for example the code: $SeriesCoefficient[n^(q1 + 1)*(n + 1)^q2, {n, 0, q1 + q2 + 1}, Assumptions -> {Element[q1, Integers] && q1 >= 0, Element[q2, Integers] && q2 >= 0}]$ doesn't give me an answer. But it shouldn't be complicated to get (it is just an expansion with binomial coefficients + identification). My remark is actually more a hope that there is a way to do it with mathematica that I don't know $\endgroup$
    – StarBucK
    Jul 11 '19 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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