# Finding the coefficients of a sum

Suppose I have the following expression:

p[l_] := 1 + ((1 - q) p)/q Sum[(p (2 - p))^k/q^k, {k, 0, l}]


or

$$p(\ell)=1+\dfrac{(1-q)p}{q}\sum_{k=0}^{k=\ell}\dfrac{p^k(2-p)^k}{q^k}$$

Is there a way to get a general formula for the coefficients of its monomial expansion when $$\ell$$ is an arbitrary integer?

• I don't think it's a good idea to use the symbol p for two different things (function name and variable). – Roman May 7 at 17:34

## 2 Answers

Is this what you're looking for:

SeriesCoefficient[p[l], {l, 0, n}] //TeXForm


$$\begin{cases} p \left(\frac{1}{q}-1\right)+1 & n=0 \\ -\frac{(p-2) p^2 (q-1) (\log (-(p-2) p)-\log (q))^n}{q n! \left(p^2-2 p+q\right)} & n>0 \end{cases}$$

• With v12, if p[l] is full simplified prior to evaluating SeriesCoefficient, i.e., SeriesCoefficient[p[l]//FullSimplify, {l, 0, n}], the result for n == 0 is wrong. Do you know why this happens? This does not happen with v11.3. – Bob Hanlon May 7 at 18:18
• I agree, I think it's worth reporting the issue to support! – Carl Woll May 7 at 20:06
• Reported to Tech Support (CASE:4257770). – Bob Hanlon May 7 at 21:59

Replacing $$(2-p)^k$$ by a multinomial and rearranging terms gives

pp[l_] := 1 + (1 - q)/q *
Sum[(-1)^(s-k-1)*2^(2k+1-s)*Binomial[k, 2k+1-s] * p^s/q^k,
{k, 0, l}, {s, k + 1, 2 k + 1}]


check:

Table[p[l] == pp[l], {l, 0, 10}] // FullSimplify
(* {True, True, True, True, True, True, True, True, True, True, True} *)