Two-dimensional matrix for phase amplitude amplification (source code)

= Two-dimensional matrix for phase amplitude amplification
{title2=$Q=-[I+(e^{i\phi}-1)|\psi\rangle\langle\psi|]\operatorname{diag}(e^{i\theta},1)$}

If the state-preparation unitary sends $|0\rangle$ to $|\psi\rangle=\sin\chi|g\rangle+\cos\chi|b\rangle$, use the orthonormal good/bad basis. The marked-space phase is diagonal there, and conjugating a phase on $|0\rangle$ gives the rank-one phase in the displayed formula. Their product is unitary. An arbitrary preparation unitary not sending zero to this state need not preserve this particular two-dimensional subspace. Matrices in unnormalized good/bad vectors must not be described as unitary in the ordinary Euclidean <inner product>.