Skip to main content

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 Y=A⊕BY=A\oplus B — “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 C=A⋅BC=A\cdot B. Use an AND gate.

1-qubit quantum gates​

Unitary U∣ψin⟩=∣ψout⟩U|\psi_{\mathrm{in}}\rangle=|\psi_{\mathrm{out}}\rangle preserves norms.

GateMatrix / action
X (NOT)[0110]\begin{bmatrix}0&1\\1&0\end{bmatrix}, flips ∥0⟩↔∥1⟩\|0\rangle\leftrightarrow\|1\rangle
Y[0−ii0]\begin{bmatrix}0&-i\\i&0\end{bmatrix}
Z[100−1]\begin{bmatrix}1&0\\0&-1\end{bmatrix}, Z∥z⟩=(−1)z∥z⟩Z\|z\rangle=(-1)^z\|z\rangle
H12[111−1]\frac1{\sqrt2}\begin{bmatrix}1&1\\1&-1\end{bmatrix}, ∥0⟩↦∥+⟩\|0\rangle\mapsto\|+\rangle, ∥1⟩↦∥−⟩\|1\rangle\mapsto\|-\rangle
RφR_\varphi (phase / P)diag(1,eiφ)\mathrm{diag}(1,e^{i\varphi})
S, TRπ/2R_{\pi/2}, Rπ/4R_{\pi/4}
Rx,Ry,RzR_x,R_y,R_ze−iασ/2e^{-i\alpha\sigma/2} Bloch rotations
MeasureNot unitary — collapses to classical bits

Bloch checks: H takes ∥0⟩\|0\rangle to (∥0⟩+∥1⟩)/2(\|0\rangle+\|1\rangle)/\sqrt2; a π/2\pi/2 phase on that state yields (∥0⟩+i∥1⟩)/2(\|0\rangle+i\|1\rangle)/\sqrt2; X (or Rx(π)R_x(\pi) up to global phase) flips ∥0⟩→∥1⟩\|0\rangle\to\|1\rangle.

2-qubit gates​

  • SWAP: ∥01⟩↔∥10⟩\|01\rangle\leftrightarrow\|10\rangle.
  • Controlled-UU: CU∣c⟩∣t⟩=∣c⟩Uc∣t⟩CU|c\rangle|t\rangle=|c\rangle U^c|t\rangle.
  • CNOT: control 0 → target unchanged; control 1 → flip target. CNOT∣10⟩=∣11⟩\mathrm{CNOT}|10\rangle=|11\rangle.
  • CZ: flips the sign of ∥11⟩\|11\rangle only.

Entanglement via gates​

Figure 12.2 — H then CNOT → Bell |β₀₀⟩.

Hadamard then CNOT on ∣00⟩|00\rangle builds the Bell state ∣β00⟩|\beta_{00}\rangle. Pick H∣0⟩H|0\rangle/H∣1⟩H|1\rangle 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

∣ijk⟩=∣i⟩⊗∣j⟩⊗∣k⟩,|ijk\rangle=|i\rangle\otimes|j\rangle\otimes|k\rangle,

eight of them: ∣000⟩,…,∣111⟩|000\rangle,\ldots,|111\rangle. In the computational ordering used here, ∣110⟩|110\rangle is the unit vector with a 11 in the seventh slot (0-based index 66), and ∣111⟩|111\rangle is index 77. Gates on this space are 8×88\times 8 unitaries.

Toffoli / CCNOT extends CNOT: flip the target (third qubit) if and only if both controls are ∣1⟩|1\rangle:

T∣110⟩=∣111⟩,T∣111⟩=∣110⟩,T|110\rangle=|111\rangle,\qquad T|111\rangle=|110\rangle,

and leave every other basis ket unchanged. (Equivalently: the 8×88\times 8 matrix swaps rows/columns 66 and 77.) 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​

ClassicalQuantum
AND / XOR / …Unitary X,Y,Z,H,Rφ,…X,Y,Z,H,R_\varphi,\ldots
Half-adderCNOT / CZ / SWAP
—H+CNOT → Bell
—Toffoli on 3 qubits
Quiz

Logic / quantum gates

1 / 4

A 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.