Qubit Playground: interactive Bloch sphere simulator
Apply gates to a single qubit, watch the state vector move, and measure it until the statistics settle.
What is a qubit?
A classical bit is either 0 or 1. A qubit is described by two complex numbers, α and β, written
α|0⟩ + β|1⟩. The only constraint is that |α|² + |β|² = 1. Those squared magnitudes are
the probabilities of reading 0 or 1 if you measure in the computational basis, so the constraint just says the
probabilities add to one. A qubit is not "0 and 1 at the same time", and it is not a bit whose value you happen
not to know yet. It is a vector, and the phases of α and β — not just their sizes — determine how it behaves when
you apply further gates. That extra structure is what makes interference possible, and interference is where
quantum algorithms get their leverage.
What is the Bloch sphere?
Two complex numbers have four real parameters. Normalisation removes one, and multiplying the whole state by a
phase e^{iγ} changes nothing you can measure, which removes another. Two are left, so every pure
single-qubit state can be written cos(θ/2)|0⟩ + e^{iφ} sin(θ/2)|1⟩ and drawn as a point on a sphere.
The north pole is |0⟩ and the south pole is |1⟩; the equator holds the even superpositions, with |+⟩ and |−⟩ on the
x axis and |+i⟩ and |−i⟩ on the y axis. Polar angle θ sets the measurement probabilities; azimuth φ is the relative
phase. In this simulator the amplitudes are the source of truth and the sphere coordinates are derived from them,
never the other way round.
What do quantum gates do?
A single-qubit gate is a 2×2 unitary matrix multiplying the amplitude vector. Unitary means it preserves total probability, which geometrically means it rotates the Bloch sphere rigidly — no stretching, no collapsing. X, Y and Z are half-turns about the three axes. H is a half-turn about the diagonal axis halfway between x and z, which is why it swaps |0⟩ with |+⟩. S and T are partial turns about the z axis, by 90° and 45°, adding phase without touching the measurement probabilities. Rx, Ry and Rz let you turn by any angle you like. Gates are reversible: every one of them has an inverse, and running a circuit backwards undoes it exactly.
What happens when you measure?
Measurement in the Z basis returns 0 with probability |α|² and 1 with probability |β|², and afterwards the state
really is |0⟩ or |1⟩ — the rest of the amplitude is gone, and repeating the measurement gives the same answer. A
single shot therefore tells you very little. To learn what state you had, you have to prepare it again and measure
again, many times; the shot histogram here converges to the dashed theoretical lines at a rate around
1/√N, so ten thousand shots pins a probability down to roughly one part in a hundred. You can also
measure along x or y instead, which asks a different question of the same state and generally gives a different
distribution.
Why does H·H return to |0⟩?
Apply H to |0⟩ and you get (|0⟩ + |1⟩)/√2 — a 50/50 measurement. Apply H again and you get |0⟩ back
with certainty. If H were a randomiser, a second application would leave you at 50/50, not back where you started.
What actually happens is that the two paths to |1⟩ arrive with opposite signs and cancel, while the two paths to
|0⟩ arrive with the same sign and add. That is interference, and it needs the signs — the phases — that a
probability alone cannot carry. It is the single clearest reason a qubit is not a coin: run lesson 3 and watch the
arrow travel out to the equator and back rather than smearing into randomness.