Solution (source code)

= Solution

The group average
$$
\Pi_G=\frac1{|G|}\sum_{P\in G}P
$$
is Hermitian. In its square, every $R\in G$ occurs exactly $|G|$ times among products $PQ$, and therefore $\Pi_G^2=\Pi_G$. Moreover $g\Pi_G=\Pi_G$ for every $g\in G$, so its image lies in the <stabilizer subspace> $V_G$, while $\Pi_G|\psi\rangle=|\psi\rangle$ for every $|\psi\rangle\in V_G$. Thus $\Pi_G$ is the <orthogonal projector> onto $V_G$. If $g_1,\ldots,g_l$ are independent generators, expanding the product chooses each element of $G$ exactly once and gives the <stabilizer-projector formula>
$$
\boxed{\Pi_G=\prod_{i=1}^l\frac{I+g_i}{2}}.
$$