Translating Circuits to Math
Every quantum circuit has an equivalent mathematical description: a unitary matrix that maps input states to output states. Being able to derive that matrix from the diagram is one of the most useful skills in quantum computing — it lets you predict outputs without running a simulator, spot gate identities, and debug circuits by inspection.
Each gate is a matrix; composition is multiplication
A single-qubit gate is a unitary matrix. The familiar Pauli and Hadamard matrices are:
When a circuit applies gate first and then gate , the combined operation is — matrix multiplication with the later gate on the left. For three gates applied in order , , , the total unitary is .
A worked example:
Let us derive the unitary for the three-gate sequence , , . First compute :
Now multiply on the left by :
The circuit is exactly the gate. This makes geometric sense on the Bloch sphere: swaps the - and -axes, so a flip about the -axis (which is what does) becomes, after swapping axes back with , a flip about the -axis — and that is precisely .
Why unitarity matters
Every physically valid quantum operation must be unitary: . Unitarity preserves the total probability (the norm of the state vector) and guarantees reversibility — you can always undo a unitary by applying . For the example above, (it is its own inverse), so , confirming reversibility.
Try it
Implement the circuit , whose unitary is . The grader compares the full unitary of your circuit, so returning an empty circuit will not pass.
After running, open the Unitary tab to see the resulting matrix: it should be diagonal with entries and , exactly matching .
Sign in on the full site to ask questions and join the discussion.