Solution (source code)

= Solution
{c}

Use the conventional <phase gate> $P_\varphi=\operatorname{diag}(1,e^{i\varphi})$ in <computational basis> order $0,1$. The single-qubit <Hadamard gate> and the successive <quantum states> are
$$
\boxed{H=\frac1{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix},}
\qquad
|0\rangle\xrightarrow{H}\frac{|0\rangle+|1\rangle}{\sqrt2}
\xrightarrow{P_\varphi}\frac{|0\rangle+e^{i\varphi}|1\rangle}{\sqrt2}.
$$
The final <Hadamard gate> recombines the two components, giving
$$
\boxed{|\psi_{\rm out}\rangle=
\frac{1+e^{i\varphi}}2|0\rangle+\frac{1-e^{i\varphi}}2|1\rangle
=e^{i\varphi/2}\left(\cos\frac\varphi2|0\rangle-i\sin\frac\varphi2|1\rangle\right).}
$$
The leading factor in the last expression is a <global phase>. The <Born rule> therefore yields
$$
\boxed{P_0(\varphi)=\left|\frac{1+e^{i\varphi}}2\right|^2
=\frac{1+\cos\varphi}{2}=\cos^2\frac\varphi2.}
$$
At $\varphi=0$ the output is certainly zero, whereas at $\varphi=\pi$ it is certainly one. The <phase gate> changes no intermediate outcome <probabilities>; the final <Hadamard gate> converts a relative <quantum phase> into an observable <quantum interference> fringe.