|q⟩ Bad Qubits

beginner · Programming · The Qubit State Vector & Dirac Notation

Changing Basis

The computational basis {0,1}\{|0\rangle, |1\rangle\} is not the only valid basis for a qubit. Any pair of orthonormal states spans the same space, so a state that looks simple in one basis can look like an equal superposition in another. Choosing the right basis often makes a calculation — or an algorithm — far more transparent.

The X basis (Hadamard basis)

A second natural basis is built from the two equal-superposition states introduced in the previous lesson:

+=12(0+1),=12(01).|+\rangle = \frac{1}{\sqrt{2}}\big(|0\rangle + |1\rangle\big), \qquad |-\rangle = \frac{1}{\sqrt{2}}\big(|0\rangle - |1\rangle\big).

These are orthonormal — you can check directly that +=0\langle +|-\rangle = 0 and ++==1\langle +|+\rangle = \langle -|-\rangle = 1 — so they form a valid basis called the X basis (or Hadamard basis). The Pauli-XX operator has +|+\rangle and |-\rangle as its eigenvectors with eigenvalues +1+1 and 1-1, respectively, which is why the name sticks.

Rewriting states across bases

Every state ψ|\psi\rangle can be expanded in either basis. To find the X-basis coefficients of a computational-basis state, express 0|0\rangle and 1|1\rangle in terms of +|+\rangle and |-\rangle. Adding and subtracting the definitions above gives

0=12(++),1=12(+).|0\rangle = \frac{1}{\sqrt{2}}\big(|+\rangle + |-\rangle\big), \qquad |1\rangle = \frac{1}{\sqrt{2}}\big(|+\rangle - |-\rangle\big).

So 1|1\rangle in the X basis is an equal superposition of +|+\rangle and |-\rangle with opposite signs. More generally, for any state ψ=α0+β1|\psi\rangle = \alpha|0\rangle + \beta|1\rangle, the X-basis expansion is

ψ=α+β2++αβ2.|\psi\rangle = \frac{\alpha + \beta}{\sqrt{2}}|+\rangle + \frac{\alpha - \beta}{\sqrt{2}}|-\rangle.

Preparing an X-basis state in a circuit

To prepare +|+\rangle or |-\rangle starting from 0|0\rangle, you use HH (and an optional XX flip beforehand). Concretely:

H0=+,H1=H(X0)=.H|0\rangle = |+\rangle, \qquad H|1\rangle = H\bigl(X|0\rangle\bigr) = |-\rangle.

The state |-\rangle lives entirely in the X basis: it is the 1-1 eigenstate of XX, so measuring in the X basis would give a definite outcome. Measuring in the Z basis instead gives outcome 0 or 1 with equal probability 12\frac{1}{2}, because the Z-basis amplitudes both have magnitude 12\frac{1}{\sqrt{2}}.

Try it

Starting from 0|0\rangle, prepare the X-basis state |-\rangle. You will need two gates. The grader checks the full state vector, so leaving the qubit in 0|0\rangle will not pass.

Run your code to see the quantum state.

After running, the State Vector panel should show amplitudes +0.707\approx +0.707 on 0|0\rangle and 0.707\approx -0.707 on 1|1\rangle — that is 120121=\frac{1}{\sqrt{2}}|0\rangle - \frac{1}{\sqrt{2}}|1\rangle = |-\rangle.

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