Tensor Structure of Operations
When you have a register of qubits, applying a single-qubit gate to qubit means tensoring with identity on every other qubit. For a three-qubit register the full operator is
Writing out those matrices by hand would be tedious — so quantum programming frameworks handle the tensor product automatically. You simply call the gate and name the qubit.
The -qubit state space
An -qubit register lives in the tensor-product space , which has dimension . The computational basis consists of all -bit strings . For three qubits the eight basis states are .
The state vector tracks one complex amplitude for each basis state, so a three-qubit register needs amplitudes.
Applying a gate to one qubit
Suppose the register starts in and you apply only to qubit 0:
Expanding into the eight-dimensional basis (qubit 0 is most significant in this platform):
Now add an gate on qubit 2 at the same time (independent gates commute when they act on different qubits):
What the simulator does
Every time you call c.h(0), the simulator constructs the operator
and multiplies it into the state vector. It then does the same for
c.x(2) with . You never write the big matrix — the library builds it
from the qubit index and the known gate.
This is the core idea behind all quantum programming frameworks: gate calls become tensor-product operators applied to the full state vector.
Try it
Start from (a three-qubit register). Apply to qubit 0 and to qubit 2, leaving qubit 1 untouched. The grader checks the final state vector.
After running, you should see nonzero amplitudes only on and , each with magnitude .
Sign in on the full site to ask questions and join the discussion.