<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] 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.$$
</s>