<s>[INST] Computing the coefficient of the term of a certain degree in a polynomial Given the polynomial
${1\over8}((1+z)^9 + 3(1-z)^4(1+z)^5 + (1-z)^6(1+z)^3)$
(which is the weight enumerator of a code)
how do I find out the coefficient of $z^2$?
The solution given is ${1 \over 8}(36-12+0) = 3$.
I got $36$ for the $z^2$ coefficient of $(1+z)^9$ using the Binomial Theorem, but I don't know how to get $-12$ for the $z^2$ coefficient of $3(1-z)^4(1+z)^5$. By using the Binomial Theorem separately on $(1-z)^4$ and $(1+z)^5$ I get the following two polynomials, repsectively:
$z^4-4z^3+6z^2-4z+1$
$z^5+5z^4+10z^3+10z^2+5z+1$
I am unsure what to do next, or even if this is going in the right direction.
 [/INST] It is convenient to use the coefficient of operator $[z^k]$ to denote the coefficient of $z^k$. This way we can write for instance
\begin{align*}
[z^k](1+z)^n=\binom{n}{k}\tag{1}
\end{align*}

We obtain
  \begin{align*}
\color{blue}{[z^2]}&\color{blue}{\frac{1}{8}\left((1+z)^9+3(1-z)^4(1+z)^5+(1-z)^6(1+z)^3\right)}\\
&=\frac{1}{8}\left([z^2](1+z)^9+3[z^2](1-z)^4(1+z)^5+[z^2](1-z)^6(1+z)^3\right)\tag{2}\\
&=\frac{1}{8}\left\{\binom{9}{2}+3\left(\binom{4}{0}[z^2]-\binom{4}{1}[z^1]+\binom{4}{2}[z^0]\right)(1+z)^5\right.\\
&\qquad \qquad\qquad \left.+\left(\binom{6}{0}[z^2]-\binom{6}{1}[z^1]+\binom{6}{2}[z^0]\right)(1+z)^3\right\}\tag{3}\\
&=\frac{1}{8}\left\{\binom{9}{2}+3\left(\binom{4}{0}\binom{5}{2}-\binom{4}{1}\binom{5}{1}+\binom{4}{2}\binom{5}{0}\right)\right.\\
&\qquad\qquad\qquad\left.+\left(\binom{6}{0}\binom{3}{2}-\binom{6}{1}\binom{3}{1}+\binom{6}{2}\binom{3}{0}\right)\right\}\tag{4}\\
&=\frac{1}{8}\left(36+3\left(10-20+6\right)+\left(3-18+15\right)\right)\\
&\,\,\color{blue}{=\frac{1}{8}\left(36-12+0\right)}\\
&\,\,\color{blue}{=3}
\end{align*}
  and the claim follows.

Comment:


*

*In (2) we use the linearity of the coefficient of operator.

*In (3) we select the coefficient of $z^2$ in $(1+z)^9$ and we again use the linearity of the coefficient of operator together with the rule $[z^{p-q}]A(z)=[z^p]z^qA(z)$.

*In (4) we select the coefficient of $z^k, k=0,1,2$ accordingly.
</s>