A table comprehension is a tabular view of the values generated by a quantum-state expression. For an n-qubit state, each row associates an outcome k, where 0 ≤ k < 2^n, with its amplitude and derived quantities. This turns a state vector into a developer-friendly structure for inspection and simulation. section 4.2.2
Inspecting an eight-entry state
After validating an eight-amplitude state with prepare_state, a basic table can be generated with `[[k, state[k]] for k in range(len(state))]`. Each row contains an outcome index and its complex amplitude. An expanded comprehension adds direction in degrees, magnitude, and probability: `abs(state[k])` gives magnitude, while `abs(state[k]) ** 2` gives outcome probability. For example, outcome 5 has amplitude approximately 0.58403 − 0.6318i, magnitude 0.86038, direction −47.25°, and probability 0.74026. section 4.2.2
Use table comprehensions to:
- Display outcome indices alongside amplitudes in a simulator. section 4.2.2
- Convert amplitudes into probabilities and directions using squared magnitude and atan2. section 4.2.2
- Reconstruct amplitudes from probabilities and directions with square roots, cosine, and sine. section 4.2.2
- Compare amplitude pairs before and after applying a single-qubit gate to a target qubit. section 4.3.1
Figure 4.9 The amplitudes of an n-qubit quantum state with outcomes 0 ≤ k < 2n
Browse the n-qubit amplitude layout to connect outcome indices with the rows generated by a table comprehension. section 4.2.2
