Hadamard gate (source code)

= Hadamard gate
{c}
{title2=$H$}

The <Hadamard gate> is the <unitary operator>
$$
H=\frac1{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix},\qquad H^2=I,
$$
where $I$ is the <identity operator>. It maps the <computational basis> to the <Hadamard basis>:
$$
|0\rangle\mapsto\frac{|0\rangle+|1\rangle}{\sqrt2},
\qquad
|1\rangle\mapsto\frac{|0\rangle-|1\rangle}{\sqrt2}.
$$

These outputs have equal <computational-basis measurement> probabilities, but their relative <quantum phase> differs. Applying another <Hadamard gate> sends them to different definite outputs. Calling this gate a classical coin toss would discard precisely the information that makes this possible. https://quantum.cloud.ibm.com/learning/en/courses/basics-of-quantum-information/single-systems/quantum-information[Watrous, IBM Quantum Learning, unitary operations on qubits]{ref}.

Starting from $|0\rangle$, compare two <quantum circuits>, reading matrix products from right to left:
$$
HH|0\rangle=|0\rangle,\qquad HZH|0\rangle=|1\rangle.
$$
Here $Z$ is the <Pauli Z gate>. After the first <Hadamard gate>, the <probability amplitudes> are $(1/\sqrt2,1/\sqrt2)$. Inserting $Z$ changes them to $(1/\sqrt2,-1/\sqrt2)$ without changing their squared magnitudes. At the final gate, the contributions to output zero cancel and those to output one add. Without $Z$, cancellation occurs at output one instead. This is controlled <interference>, with the <quantum phase> determining which answer emerges.

The same calculation works for any <phase gate> $P_\phi=\operatorname{diag}(1,e^{i\phi})$:
$$
HP_\phi H|0\rangle=\frac{1+e^{i\phi}}2|0\rangle+\frac{1-e^{i\phi}}2|1\rangle,
\qquad P(1)=\sin^2(\phi/2),\quad P(0)=\cos^2(\phi/2).
$$
For example, $\phi=\pi/3$ gives $P(1)=1/4$, while $\phi=\pi/2$ gives $P(1)=1/2$. The output-one amplitude at $\phi=\pi/2$ is $(1-i)/2$: its two complex contributions add before the <Born rule> is applied. A <phase gate> alone leaves the populations unchanged; recombination converts its relative <quantum phase> into observable <probabilities>.

\Image[/hadamard-interference.png]
{title=Hadamard interference: a relative phase changes output probabilities through complex amplitude addition; the dotted circle traces the output-one amplitude as the phase varies}

If <quantum decoherence> completely removes the <computational basis> coherence between the gates, the intermediate <density matrix> becomes $I/2$. Both the <phase gate> and final <Hadamard gate> leave $I/2$ unchanged, so $P(1)=1/2$ for every $\phi$. The disappearing fringe explains why preserving <quantum coherence> matters: it enables the gate sequence to carry phase information into the final measurement.