Quantum gates and circuit composition
Build reversible transformations with a small gate vocabulary.
1. Core idea
The X gate swaps computational basis states; Z changes a relative sign; H mixes amplitudes. Gates compose right to left in matrix notation, while circuit diagrams are usually read from left to right. Measurement is not itself a reversible gate.
2. Mathematical foundation
The notation describes a precise relationship among states, transformations or probabilities. Identify each symbol, check the dimensions of the objects, and distinguish amplitudes from the probabilities produced by a measurement.
3. Worked example
4. Reasoning flow
- Define the initial register and its basis states.
- Apply the transformations in their intended order.
- Track amplitude magnitudes and relative phases.
- Measure in the basis that reveals the desired property.
- Interpret the result and check the resource assumptions.
Qiskit implementation
Run this standalone Python script with Qiskit installed. It uses exact statevector simulation rather than noisy hardware shots.
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
qc = QuantumCircuit(1)
qc.h(0) # split amplitude equally
qc.z(0) # introduce a relative minus sign
qc.h(0) # interfere the two paths
print(qc.draw())
print(Statevector.from_instruction(qc).probabilities_dict())
# Expected: {'1': 1.0}
Download runnable Python5. Check your understanding
Practice question
Calculate HZH|0⟩ and explain why it equals X|0⟩.
6. What to watch out for
Ideal-state calculations assume perfect gates and measurements. When assessing an algorithm, separate its mathematical guarantee from the cost of building oracles, preparing inputs, repeating experiments and correcting physical noise.