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.
 A: A short cut or two:
$$(1-z)^4(1+z)^5=(1-z^2)^4(1+z)=(1-4z^2+\cdots)(1+z)=1+z-4z^2+\cdots$$
and
$$(1-z)^6(1+z)^3=(1-z^2)^3(1-z)^3=(1-3z^2+\cdots)(1-3z+3z^2-z^3)
=1-3z+0z^2+\cdots$$
etc.
A: Notice that the coefficient of $z^2$ in $(a+bz+cz^2+\cdots)(d+ez+fz^2+\cdots)$ is $af+be+cd$.
After expansion of the powers,
$$1+9z+36z^2+\cdots+\\
3(1-4z+6z^2-\cdots)(1+5z+10z^2+\cdots)+\\
(1-6z+15z^2-\cdots)(1+3z+3z^2+\cdots)
$$
Which gives
$$\frac{36+3(10-20+6)+(3-18+15)}8=\frac{24}8.$$

Using Lord Shark the Unknown's shortcuts, and the rule $(a+bz+cz^2+\cdots)(d+ez^2+\cdots)$ that gives $ae+cd$,
$$1+9z+36z^2+\cdots+\\
3(1-4z^2+\cdots)(1+z)+\\
(1-3z^2+\cdots)(1-3z+3z^2+\cdots)
$$
Now
$$\frac{36+3(-4)+(3-3)}8=\frac{24}8.$$

Using a CAS,
$$\frac{5z^9+9z^8+24z^7+80z^6+138z^5+138z^4+80z^3+24z^2+9z+5}8.$$
A: We can work this out by establishing a general formula for
$$(1-z)^m(1+z)^n=(1-mz+\frac{m(m-1)}2-\cdots)(1+nz+\frac{n(n-1)}2z^2+\cdots).$$
The $z^2$ term has the coefficient
$$\frac{m(m-1)}2-mn+\frac{n(n-1)}2=\frac{(m-n)^2-(m+n)}2.$$
Hence,
$$9,0\to 36\\4,5\to-4,\\6,3\to0$$ and the solution is
$$\frac{36-3\cdot4}8.$$
A: 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.
