Calculate sum with binomials using generating functions How would you calculate this sum using generating functions? I have tried a lot of things but cannot seem to get the right solution which should even contain $\sqrt{π}$
$$\sum_{k=0}^n (-1)^k \binom{n}{k}^2$$
 A: A slight  variation of the   theme.  It  is convenient to use the coefficient   of operator $[x^n]$ to denote the coefficient of $x^n$. This way we can write for instance
\begin{align*}
[x^k](1+x)^n=\binom{n}{k}\tag{1}
\end{align*}

We obtain
  \begin{align*}
\color{blue}{\sum_{k=0}^n\binom{n}{k}^2(-1)^k}
&=\sum_{k=0}^n\binom{n}{k}(-1)^k\binom{n}{n-k}\tag{2}\\
&=\sum_{k=0}^n\binom{n}{k}(-1)^k[x^{n-k}](1+x)^n\tag{3}\\
&=[x^n](1+x)^n\sum_{k=0}^n\binom{n}{k}(-x)^k\tag{4}\\
&=[x^n](1+x)^n(1-x)^n\tag{5}\\
&=[x^n](1-x^2)^n\\
&\,\,\color{blue}{=(-1)^{n/2}\binom{n}{\frac{n}{2}}[n\equiv0 \operatorname{mod}  2]}\tag{6}
\end{align*}

Comment:


*

*In (2) we use the binomial identity $\binom{p}{q}=\binom{p}{p-q}$.

*In (3) we apply  the coefficient of   operator  according   to (1).

*In (4)  we  apply the rule $[x^{p-q}]A(x)=[x^p]x^qA(x)$.

*In (5) we apply the binomial theorem.

*In (6) we select the coefficient of $[x^n]$ using Iverson brackets.
A: Recall that the coefficients of the product of polynomials (or power series) is given by the convolution of the coefficients of each series:  $$\left(\sum_{k=0}^\infty a_k x^k \right)\left(\sum_{k=0}^\infty b_k x^k \right) = \sum_{n=0}^\infty \left(\sum_{k=0}^n a_k b_{n-k}\right) x^n$$
Thus since $\binom{n}{k} = \binom{n}{n-k}$,
\begin{align*}
\sum_{k=0}^n (-1)^k \binom{n}{k}^2  = \sum_{k=0}^n (-1)^k \binom{n}{k}  \binom{n}{n-k} 
\end{align*}
is the coefficient of $x^n$ in $$\left(\sum_{k=0}^n (-1)^k \binom{n}{k} x^k\right) \left(\sum_{k=0}^n \binom{n}{k} x^k\right) = (1-x)^n(1+x)^n = (1-x^2)^n = \sum_{k=0}^n \binom{n}{k} (-x^2)^k$$
which is $0$ if $n$ is odd, otherwise $\binom{n}{n/2}(-1)^{n/2}$, corresponding to the $k = n/2$ term in the above sum.
A: A tricky one. Remember that $\binom{n}{k} = \binom{n}{n - k}$, so:
$\begin{equation*}
   \sum_k (-1)^k \binom{n}{k}^2
     = \sum_k (-1)^k \binom{n}{k} \binom{n}{n - k}
\end{equation*}$
This is a convolution,
we can write it as the coefficient of $z^n$ in the product:
$\begin{align*}
   [z^n] \left( \sum_k \binom{n}{k} (-1)^k z^k \right)
            \cdot \left( \sum_k \binom{n}{k} z^k \right)
     &= [z^n] (1 - z)^n (1 + z)^n \\
     &= [z^n] (1 - z^2)^n \\
     &= \begin{cases}
           (-1)^{n/2} \binom{n}{n / 2} & n \text{ even} \\
           0                & n \text{ odd}
        \end{cases}
\end{align*}$
