Solution (source code)

= Solution

Let $\Pi_G$ be the <orthogonal projection> onto $G$. The two <reflection operators> are
$$
I_{|\psi\rangle}=I-2|\psi\rangle\langle\psi|,
\qquad
I_G=I-2\Pi_G.
$$
The first fixes the hyperplane $|\psi\rangle^\perp$ and changes the sign of $|\psi\rangle$; the second fixes $G^\perp$ and changes the sign of $G$.

Write the normalized projections of $|\psi\rangle$ as
$$
|\psi\rangle=\sin\theta|g\rangle+\cos\theta|b\rangle,
\qquad
|g\rangle\in G,
\quad |b\rangle\in G^\perp.
$$
The <amplitude amplification theorem> states that for
$$
R=I_{|\psi\rangle}I_G
$$
one has, up to the irrelevant global sign $(-1)^k$,
$$
\boxed{R^k|\psi\rangle
=(-1)^k\left[
\sin((2k+1)\theta)|g\rangle
+\cos((2k+1)\theta)|b\rangle
\right]}.
$$
Thus every iteration increases the angle toward the good axis by $2\theta$ until the first overshoot.

For the proof, the plane $\operatorname{span}\{|g\rangle,|b\rangle\}$ is invariant. In its ordered basis,
$$
I_G=\begin{pmatrix}-1&0\\0&1\end{pmatrix},
\qquad
I_{|\psi\rangle}
=\begin{pmatrix}
\cos2\theta&-\sin2\theta\\
-\sin2\theta&-\cos2\theta
\end{pmatrix}.
$$
Their product is a planar rotation through $2\theta$ together with an overall sign. Applying that matrix $k$ times proves the formula, while components orthogonal to this plane never enter the initial state.