Column Vectors in Code
The mathematical object at the heart of quantum computing is the state vector — a column of complex numbers that encodes everything the theory predicts about a qubit. When the simulator runs your circuit it hands back exactly this column, so knowing how to read it turns abstract algebra into something you can inspect and reason about directly.
The column vector for one qubit
A single qubit lives in a two-dimensional complex vector space. Its state is written
where are the amplitudes and normalization requires . The two basis states are the simplest cases:
The simulator stores this column as a JavaScript array indexed by basis state. For a
one-qubit circuit the array has two entries: index 0 holds the amplitude for
and index 1 holds for .
Mapping array positions to basis strings
The index into the amplitude array is the decimal value of the binary basis string. For two qubits the array has four entries:
| index | basis state | binary string |
|------:|:-----------:|:-------------:|
| 0 | | "00" |
| 1 | | "01" |
| 2 | | "10" |
| 3 | | "11" |
This convention means that qubit 0 is the most significant bit: the leftmost character in the binary string corresponds to qubit 0, and the rightmost to the last qubit. After running your circuit you can read off any amplitude by looking at the array element whose index matches the decimal value of the basis label you care about.
From amplitudes to probabilities
Each amplitude is a complex number, but the Born rule maps it to a real, non-negative probability:
where is the amplitude at array position . For example, if the simulator returns the state you immediately know and , regardless of the complex phase.
Try it
Prepare the qubit in the state. Look at the State Vector panel after running:
the amplitude array should read [0, 1], meaning all probability sits at index 1 (the
basis state).
After the grader passes, try changing your circuit to c.h(0) and re-running: you will see
— two equal amplitudes, each with magnitude
and probability .
Sign in on the full site to ask questions and join the discussion.