|q⟩ Bad Qubits

beginner · Programming · Single-Qubit Gates II: H, S, T & Phase

Creating |+⟩ and |−⟩ with H

Two of the most useful states in quantum computing are the X-basis states ∣+⟩|+\rangle and ∣−⟩|-\rangle. Both are equal superpositions of ∣0⟩|0\rangle and ∣1⟩|1\rangle, differing only in the relative sign between the two amplitudes:

∣+⟩=12(∣0⟩+∣1⟩),∣−⟩=12(∣0⟩−∣1⟩).|+\rangle = \frac{1}{\sqrt{2}}\bigl(|0\rangle + |1\rangle\bigr), \qquad |-\rangle = \frac{1}{\sqrt{2}}\bigl(|0\rangle - |1\rangle\bigr).

On the Bloch sphere, ∣+⟩|+\rangle sits on the +x+x axis and ∣−⟩|-\rangle on the −x-x axis — both halfway between the two poles.

Producing them with H

The Hadamard gate HH is defined by its action on the computational-basis states:

H∣0⟩=12(∣0⟩+∣1⟩)=∣+⟩,H∣1⟩=12(∣0⟩−∣1⟩)=∣−⟩.H|0\rangle = \frac{1}{\sqrt{2}}\bigl(|0\rangle + |1\rangle\bigr) = |+\rangle, \qquad H|1\rangle = \frac{1}{\sqrt{2}}\bigl(|0\rangle - |1\rangle\bigr) = |-\rangle.

You can verify this directly from the matrix:

H=12(111−1).H = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}.

Multiply HH by the column vector for ∣0⟩=(10)|0\rangle = \binom{1}{0}:

H∣0⟩=12(11)=12∣0⟩+12∣1⟩=∣+⟩.✓H|0\rangle = \frac{1}{\sqrt{2}}\begin{pmatrix}1\\1\end{pmatrix} = \frac{1}{\sqrt{2}}|0\rangle + \frac{1}{\sqrt{2}}|1\rangle = |+\rangle. \checkmark

Multiply by ∣1⟩=(01)|1\rangle = \binom{0}{1}:

H∣1⟩=12(1−1)=12∣0⟩−12∣1⟩=∣−⟩.✓H|1\rangle = \frac{1}{\sqrt{2}}\begin{pmatrix}1\\-1\end{pmatrix} = \frac{1}{\sqrt{2}}|0\rangle - \frac{1}{\sqrt{2}}|1\rangle = |-\rangle. \checkmark

Both results are normalized: each amplitude has magnitude 12\tfrac{1}{\sqrt{2}}, so the squared magnitudes sum to (12)2+(12)2=1\left(\tfrac{1}{\sqrt{2}}\right)^2 + \left(\tfrac{1}{\sqrt{2}}\right)^2 = 1.

Why these states matter

The states ∣+⟩|+\rangle and ∣−⟩|-\rangle appear throughout quantum algorithms. Interference is most powerful when a qubit is in a superposition, and HH is the standard way to create one from a definite input. Grover's algorithm, quantum Fourier transforms, and many error-correction gadgets all start by producing ∣+⟩|+\rangle with a Hadamard on ∣0⟩|0\rangle.

Try it

The circuit starts in ∣0⟩|0\rangle. Apply HH to produce ∣+⟩|+\rangle and return the circuit. The grader compares the full state vector, so the amplitudes must match 12≈0.707\tfrac{1}{\sqrt{2}} \approx 0.707 for both ∣0⟩|0\rangle and ∣1⟩|1\rangle with no relative phase difference.

Run your code to see the quantum state.

After running, check the State vector panel: you should see two equal real amplitudes of +12+\tfrac{1}{\sqrt{2}} and the Bloch vector pointing along +x+x.

Sign in on the full site to ask questions and join the discussion.