Part II. Mathematical Core · Chapter 9
Vectors, Bases, and Amplitudes
A statevector is not the state — it is the state's coordinates in a basis somebody chose, and half of all beginner quantum bugs live in the gap between those two things. This chapter closes that gap for good, with one state written two ways as the proof.
In this chapter 8 sections
Reader question. How can the same quantum state have different coordinate vectors without becoming a different physical state?
A state is an abstract vector; a basis supplies coordinates. Changing basis transforms the coordinate list while preserving normalization and inner-product predictions, so basis order and convention are part of every serialized statevector.
- This chapter does not cover arbitrary spectral decompositions or infinite-dimensional spaces.
- It does not treat an SDK's printed coordinate order as universal.
A vector before its coordinates
Separate the abstract state from a chosen ordered basis.
A quantum state vector is not merely a list of numbers. It is a list of coordinates relative to a basis; a chosen set of reference states; and changing the basis changes every number in the list while the physical state stays exactly what it was. Confusing the coordinates with the state is the root error this chapter exists to prevent.
The computational basis for one qubit is and . A state then has the coordinate vector : the amplitudes are the coordinates, one per basis state. Probabilities arrive only later, through the Born rule, after someone names a measurement basis.
This is why Part I could speak loosely and stay correct: every time a chapter said "the amplitude of ," it was naming a coordinate against the computational basis. From here on, the naming becomes your job.
Evidence boundary. Vectors are abstract elements and coordinate lists depend on an ordered basis. [John Watrous] [Michael A. Nielsen]
Two rules for a usable basis
Establish spanning and linear independence in two dimensions.
First, normalization: . A coordinate list that fails this is not a quantum state, no matter how suggestive it looks; it is a scaling error waiting to contaminate a calculation. Check it before using a state, and again after constructing one.
Second, the Born rule, applied per basis: the probability of outcome is the squared magnitude of the amplitude on basis state . The rule is identical in every basis; what changes is the coordinate list you feed it. To measure in a different basis, re-express the state in that basis first, then square. Chapter 5's two-basis experiment is exactly this procedure, run twice on one state.
Evidence boundary. Orthonormal basis changes preserve norms and inner products. [John Watrous] [John Preskill]
Change coordinates without changing predictions
Derive computational-to-Hadamard basis coefficients.
A basis change alters coordinates and operators together. If columns of B are the new orthonormal basis vectors, the new coordinate vector is B-dagger psi and an operator becomes B-dagger A B. Computing a probability in mixed conventions is a category error: it describes neither representation consistently. Round-tripping B(B-dagger psi)=psi and preserving the norm are the two cheap checks.
Evidence boundary. Multi-qubit statevector interpretation depends on a declared basis ordering convention. [Michael A. Nielsen] [openqasm3]
Notation contract: Ordered basis B=(|0>,|1>); coordinate column [ψ]_B; basis-change matrix columns declared; multi-qubit order explicit.
Ordering is a data contract
Show how |01> and |10> swaps create plausible but wrong output.
A basis is a serialization scheme for state. Two systems with different ordering conventions encode the same abstract object differently, and quantum SDKs make concrete choices; basis ordering, qubit endianness, memory layout; that you cannot debug around without knowing. Reading another framework's statevector dump without checking its convention is parsing a file without its spec.
Statevector simulation itself is direct: store a complex array indexed by basis states, apply gates as matrix multiplications. What is not direct is readout; measurement samples according to squared magnitudes, and printing the array is a simulator privilege real hardware never grants. Keep the two mental APIs separate: the array for computation, the samples for answers.
The professional habit is three labels written before every calculation: basis, ordering, normalization status. It looks slow for one qubit. At eight qubits, with someone else's SDK and a deadline, it is the difference between a bug you find in a minute and one you find in a review.
Serialize a state safely
Define labels, endianness, and normalization checks.
A serialized statevector needs an explicit qubit order, basis order, numeric type, and tolerance. This book lists |q0 q1 ...> with q0 as the most significant displayed bit. A consumer may store a different index order, but conversion must be tested on asymmetric states such as |01>, not only |00> or symmetric Bell states that conceal a reversal.
Basis conversion and endianness harness
| Field | Reader-visible record |
|---|---|
| Format | Small library plus fixtures for one- and two-qubit basis/order changes |
| Verification | Round-trip tests recover the original abstract vector, preserve norms/inner products, and detect a deliberately swapped basis. |
| Availability | Source-embedded acceptance record; no separate download is claimed |
{
"artifact": "Basis conversion and endianness harness",
"format": "Small library plus fixtures for one- and two-qubit basis/order changes",
"acceptance_test": "Round-trip tests recover the original abstract vector, preserve norms/inner products, and detect a deliberately swapped basis.",
"publication_state": "source-embedded contract and worked fixture"
}Executable reference fixture
Run with Python 3.11 or later. The final assertion is the chapter-level pass condition for this small instance.
import math
def inner(left, right):
if len(left) != len(right):
raise ValueError("vectors must have equal dimension")
return sum(a.conjugate() * b for a, b in zip(left, right))
def coordinates(vector, basis):
if len(basis) != len(vector) or any(len(column) != len(vector) for column in basis):
raise ValueError("basis dimension mismatch")
return tuple(inner(column, vector) for column in basis)
def reconstruct(values, basis):
return tuple(sum(values[column] * basis[column][row] for column in range(len(values)))
for row in range(len(values)))
def reverse_bits(index, qubits):
output = 0
for _ in range(qubits):
output = (output << 1) | (index & 1)
index >>= 1
return output
def change_endianness(vector):
size = len(vector)
qubits = size.bit_length() - 1
if 1 << qubits != size:
raise ValueError("state dimension must be a power of two")
output = [0j] * size
for index, amplitude in enumerate(vector):
output[reverse_bits(index, qubits)] = amplitude
return tuple(output)
scale = math.sqrt(0.5)
x_basis = ((scale, scale), (scale, -scale))
states = ((1, 0), (0, 1), (scale, 1j * scale), (0.6, -0.8j))
max_roundtrip_error = 0.0
for state in states:
values = coordinates(state, x_basis)
recovered = reconstruct(values, x_basis)
max_roundtrip_error = max(max_roundtrip_error, *(abs(a - b) for a, b in zip(state, recovered)))
assert abs(inner(state, state) - inner(values, values)) < 1e-12
assert max_roundtrip_error < 1e-12
for left, right in zip(states, reversed(states)):
converted_left = coordinates(left, x_basis)
converted_right = coordinates(right, x_basis)
assert abs(inner(left, right) - inner(converted_left, converted_right)) < 1e-12
ordered_states = ((0, 1, 0, 0),
(0, 0, scale, 1j * scale),
tuple(complex(index, -index) for index in range(8)))
for state in ordered_states:
assert change_endianness(change_endianness(state)) == state
changed = change_endianness(state)
assert abs(inner(state, state) - inner(changed, changed)) < 1e-12
ket_01_msb = (0, 1, 0, 0)
ket_01_lsb = change_endianness(ket_01_msb)
assert ket_01_msb != ket_01_lsb and ket_01_lsb == (0, 0, 1, 0)
bad_dimension_rejected = False
try:
change_endianness((1, 0, 0))
except ValueError:
bad_dimension_rejected = True
assert bad_dimension_rejected
print(f"PASS: 09 basis/endianness harness round-trips {len(states) + len(ordered_states)} states; max coordinate error={max_roundtrip_error:.2e}, swapped |01> coordinate vector={ket_01_lsb}")
Scope boundary
- This chapter does not cover arbitrary spectral decompositions or infinite-dimensional spaces.
- It does not treat an SDK's printed coordinate order as universal.
Depth commitment. One abstract/coordinate distinction, one basis transform, and one endianness fixture.
Practice problem
Express in the basis and round-trip it to computational coordinates.
- Deliverable
- Both coordinate vectors, the change-of-basis matrix, and norm checks.
- Pass condition
- A fixture applies the basis matrix and its adjoint and recovers the original vector within tolerance.
Verification record
Expected solution form. Stepwise coordinate derivation plus round-trip test.
Model answer. The coefficients are c+=(1+i)/2 and c-=(1-i)/2. Substituting |+>=(|0>+|1>)/sqrt(2) and |->=(|0>-|1>)/sqrt(2) recovers (|0>+i|1>)/sqrt(2), and both coordinate vectors have norm one.
Model result and check. CI checks both directions, norm preservation, and the submitted basis labels.
Acceptance test. A fixture applies the basis matrix and its adjoint and recovers the original vector within tolerance.
Companion work
Artifacts for this chapter
These entries resolve to checked-in local source. Commands are reproduced exactly from the chapter manifest, and source-embedded fixtures are exported as direct downloads.
executable derivation
Basis conversion and endianness harness
Reproduce or test
python3 tools/validate_briefs.py --briefs data/editorial_briefs_00_35.json --from 0 --through 35 --check-rewritten-sources --execute-artifacts
Provenance
Sources and review
- John Watrous. The Theory of Quantum Information. Cambridge University Press / University of Waterloo. 2018textbook
- Michael A. Nielsen and Isaac L. Chuang. Quantum Computation and Quantum Information. Cambridge University Press. 2010textbook
- John Preskill. Lecture Notes for Physics 219: Quantum Computation. California Institute of Technology. 2018graduate lecture notes
- OpenQASM Technical Steering Committee. OpenQASM 3 specification. Linux Foundation Joint Development Foundation. 2026official technical specification
The load-bearing claims in the chapter are mapped inline to this registered source set. A citation supports only the bounded claim beside it.