12.4 Logic gates
Source: Ideas from Computational Physics (Landau, Páez, Bordeianu), §12.4. Rewritten in original wording. Continues 12.3b. Next: 12.4b.
Classical computers combine logic gates on bits. Quantum computers use unitary gates on qubits (probability-preserving). This lesson starts with classical wiring labs (NodeLab, same canvas as schema design / digital logic), then maps to 1-, 2-, and 3-qubit quantum gates.
Classical gates (warm-up)
Six basics: AND, NAND, NOT, OR, NOR, XOR. Truth tables define outputs. A half-adder uses XOR for the sum bit and AND for the carry.
Lab: XOR from the deck
Build — “exactly one input is 1.” Drag XOR (or compose from AND/OR/NAND), wire A and B into it, connect to Y. Check runs the full truth table.
Lab: half-adder carry
Carry bit . Use an AND gate.
1-qubit quantum gates
Unitary preserves norms.
| Gate | Matrix / action |
|---|---|
| X (NOT) | , flips |
| Y | |
| Z | , |
| H | , , |
| (phase / P) | |
| S, T | , |
| Bloch rotations | |
| Measure | Not unitary — collapses to classical bits |
Bloch checks: H takes to ; a phase on that state yields ; X (or up to global phase) flips .
2-qubit gates
- SWAP: .
- Controlled-: .
- CNOT: control 0 → target unchanged; control 1 → flip target. .
- CZ: flips the sign of only.
Entanglement via gates
Hadamard then CNOT on builds the Bell state . Pick / and the two-step recipe among lookalikes.
Lab: wire the Bell recipe
Connect start → H → CNOT → Bell out (field-to-field, same wiring checker as schema design).
3-qubit gates
Three-qubit basis states are tensor products
eight of them: . In the computational ordering used here, is the unit vector with a in the seventh slot (0-based index ), and is index . Gates on this space are unitaries.
Toffoli / CCNOT extends CNOT: flip the target (third qubit) if and only if both controls are :
and leave every other basis ket unchanged. (Equivalently: the matrix swaps rows/columns and .) That is the quantum analogue of a classical AND on the controls driving an XOR into the target — the building block for reversible adders in the next lesson.
Lab: wire Toffoli controls → flip
Connect controls → Toffoli → target out (schema-style wiring).
Takeaway
| Classical | Quantum |
|---|---|
| AND / XOR / … | Unitary |
| Half-adder | CNOT / CZ / SWAP |
| — | H+CNOT → Bell |
| — | Toffoli on 3 qubits |
Logic / quantum gates
1 / 4A half-adder’s sum bit is…
Pick an answer to see if you are right.
Next: 12.4b Gate labs · then 12.5 Cirq circuits.