QuantumCore

Lesson 21 · 75 min · core

Controlled Gates: CNOT, CZ, SWAP

Loading progress…

A controlled gate applies a single-qubit unitary UU to a target qubit exactly when the control qubit is ∣1⟩\lvert1\rangle: C-U=∣0⟩⟨0∣⊗I+∣1⟩⟨1∣⊗UC\text{-}U=\lvert0\rangle\langle0\rvert\otimes I+\lvert1\rangle\langle1\rvert\otimes U. This lesson proves that C-UC\text{-}U is unitary, shows that CZ=diag(1,1,1,−1)\mathrm{CZ}=\mathrm{diag}(1,1,1,-1) is symmetric in its two qubits, converts CZ\mathrm{CZ} into CNOT\mathrm{CNOT} with two Hadamards, reverses the direction of a CNOT with four Hadamards, builds SWAP from three CNOTs, explains phase kickback CNOT∣x⟩∣−⟩=(−1)x∣x⟩∣−⟩\mathrm{CNOT}\lvert x\rangle\lvert-\rangle=(-1)^x\lvert x\rangle\lvert-\rangle, and constructs an arbitrary controlled-UU from two CNOTs and single-qubit gates through the ABCABC decomposition U=eiαAXBXCU=e^{i\alpha}AXBXC with ABC=IABC=I.

Prerequisites: Rotation Gates & ZYZ Euler Decomposition, Tensor (Kronecker) Products

Objectives and key results
  • Write a controlled-UU gate in projector form ∣0⟩⟨0∣⊗I+∣1⟩⟨1∣⊗U\lvert0\rangle\langle0\rvert\otimes I+\lvert1\rangle\langle1\rvert\otimes U and in block form (I00U)\begin{pmatrix}I&0\\0&U\end{pmatrix}, and prove that it is unitary using only projector algebra.

  • Prove that CZ\mathrm{CZ} is symmetric in control and target and derive CNOT=(I⊗H) CZ (I⊗H)\mathrm{CNOT}=(I\otimes H)\,\mathrm{CZ}\,(I\otimes H) from HZH=XHZH=X.

  • Exchange the roles of control and target with (H⊗H) CNOT01 (H⊗H)=CNOT10(H\otimes H)\,\mathrm{CNOT}_{01}\,(H\otimes H)=\mathrm{CNOT}_{10}.

  • Prove SWAP=CNOT01CNOT10CNOT01\mathrm{SWAP}=\mathrm{CNOT}_{01}\mathrm{CNOT}_{10}\mathrm{CNOT}_{01} on basis states and extend it to all states by linearity.

  • Compute the phase kickback CNOT∣x⟩∣−⟩=(−1)x∣x⟩∣−⟩\mathrm{CNOT}\lvert x\rangle\lvert-\rangle=(-1)^x\lvert x\rangle\lvert-\rangle and its generalisation to eigenvectors of UU.

  • Build any controlled single-qubit gate from two CNOTs and single-qubit rotations with the ABCABC construction, verifying ABC=IABC=I and AXBXC=RZ(β)RY(γ)RZ(δ)AXBXC=R_Z(\beta)R_Y(\gamma)R_Z(\delta) step by step.

formula · Controlled-U
C-U=∣0⟩⟨0∣⊗I+∣1⟩⟨1∣⊗U=(I00U),(C-U)†(C-U)=I⊗IC\text{-}U=\lvert0\rangle\langle0\rvert\otimes I+\lvert1\rangle\langle1\rvert\otimes U=\begin{pmatrix}I&0\\0&U\end{pmatrix},\qquad(C\text{-}U)^\dagger(C\text{-}U)=I\otimes I
identity · CZ and CNOT
CZ=diag(1,1,1,−1),CZ∣a,b⟩=(−1)ab∣a,b⟩,CNOT=(I⊗H) CZ (I⊗H)\mathrm{CZ}=\mathrm{diag}(1,1,1,-1),\qquad\mathrm{CZ}\lvert a,b\rangle=(-1)^{ab}\lvert a,b\rangle,\qquad\mathrm{CNOT}=(I\otimes H)\,\mathrm{CZ}\,(I\otimes H)
identity · Reversed CNOT
(H⊗H) CNOT01 (H⊗H)=CNOT10,CNOT10∣a,b⟩=∣a⊕b,b⟩(H\otimes H)\,\mathrm{CNOT}_{01}\,(H\otimes H)=\mathrm{CNOT}_{10},\qquad\mathrm{CNOT}_{10}\lvert a,b\rangle=\lvert a\oplus b,b\rangle
identity · SWAP from CNOTs
SWAP=CNOT01 CNOT10 CNOT01,∣a,b⟩↦∣a,a⊕b⟩↦∣b,a⊕b⟩↦∣b,a⟩\mathrm{SWAP}=\mathrm{CNOT}_{01}\,\mathrm{CNOT}_{10}\,\mathrm{CNOT}_{01},\qquad\lvert a,b\rangle\mapsto\lvert a,a\oplus b\rangle\mapsto\lvert b,a\oplus b\rangle\mapsto\lvert b,a\rangle
identity · Phase kickback
CNOT∣x⟩∣−⟩=(−1)x∣x⟩∣−⟩,U∣u⟩=eiφ∣u⟩ ⇒ C-U∣x⟩∣u⟩=eixφ∣x⟩∣u⟩\mathrm{CNOT}\lvert x\rangle\lvert-\rangle=(-1)^x\lvert x\rangle\lvert-\rangle,\qquad U\lvert u\rangle=e^{i\varphi}\lvert u\rangle\ \Rightarrow\ C\text{-}U\lvert x\rangle\lvert u\rangle=e^{ix\varphi}\lvert x\rangle\lvert u\rangle
theorem · ABC construction
U=eiαAXBXC,ABC=I,A=RZ(β)RY(γ2),B=RY(−γ2)RZ(−δ+β2),C=RZ(δ−β2)U=e^{i\alpha}AXBXC,\quad ABC=I,\quad A=R_Z(\beta)R_Y(\tfrac\gamma2),\quad B=R_Y(-\tfrac\gamma2)R_Z(-\tfrac{\delta+\beta}2),\quad C=R_Z(\tfrac{\delta-\beta}2)

Controlled-U in block form#

So far every gate acted on one qubit. A controlled gate makes the action on one qubit (the target) depend on the computational-basis value of another qubit (the control). Throughout, qubit 0 is the most significant bit, so ∣a,b⟩=∣a⟩⊗∣b⟩\lvert a,b\rangle=\lvert a\rangle\otimes\lvert b\rangle with aa on qubit 0 and bb on qubit 1 has index 2a+b2a+b, and the basis order is ∣00⟩,∣01⟩,∣10⟩,∣11⟩\lvert00\rangle,\lvert01\rangle,\lvert10\rangle,\lvert11\rangle. We write P0=∣0⟩⟨0∣P_0=\lvert0\rangle\langle0\rvert and P1=∣1⟩⟨1∣P_1=\lvert1\rangle\langle1\rvert for the two computational-basis projectors, and CNOTct\mathrm{CNOT}_{ct} for the CNOT with control cc and target tt; plain CNOT\mathrm{CNOT} means CNOT01\mathrm{CNOT}_{01}.

Definition

Controlled-U gate

For a single-qubit unitary UU, the controlled-UU gate with control qubit 0 and target qubit 1 is the two-qubit operator C-U=P0⊗I+P1⊗U=∣0⟩⟨0∣⊗I+∣1⟩⟨1∣⊗UC\text{-}U=P_0\otimes I+P_1\otimes U=\lvert0\rangle\langle0\rvert\otimes I+\lvert1\rangle\langle1\rvert\otimes U. It leaves ∣0⟩∣ψ⟩\lvert0\rangle\lvert\psi\rangle unchanged and maps ∣1⟩∣ψ⟩\lvert1\rangle\lvert\psi\rangle to ∣1⟩U∣ψ⟩\lvert1\rangle U\lvert\psi\rangle. The special cases U=XU=X and U=ZU=Z are the controlled-NOT CNOT=C-X\mathrm{CNOT}=C\text{-}X and the controlled-ZZ CZ=C-Z\mathrm{CZ}=C\text{-}Z.

Derivation

Block form of C-UC\text{-}U

  1. Step 1:
    P0=∣0⟩⟨0∣=(10)(10)=(1000),P1=∣1⟩⟨1∣=(01)(01)=(0001)P_0=\lvert0\rangle\langle0\rvert=\begin{pmatrix}1\\0\end{pmatrix}\begin{pmatrix}1&0\end{pmatrix}=\begin{pmatrix}1&0\\0&0\end{pmatrix},\qquad P_1=\lvert1\rangle\langle1\rvert=\begin{pmatrix}0\\1\end{pmatrix}\begin{pmatrix}0&1\end{pmatrix}=\begin{pmatrix}0&0\\0&1\end{pmatrix}
    An outer product ∣u⟩⟨v∣\lvert u\rangle\langle v\rvert is the column ∣u⟩\lvert u\rangle times the row ⟨v∣\langle v\rvert.
  2. Step 2:
    A⊗B=(a00Ba01Ba10Ba11B) ⇒ P0⊗I=(I000),P1⊗U=(000U)A\otimes B=\begin{pmatrix}a_{00}B&a_{01}B\\a_{10}B&a_{11}B\end{pmatrix}\ \Rightarrow\ P_0\otimes I=\begin{pmatrix}I&0\\0&0\end{pmatrix},\qquad P_1\otimes U=\begin{pmatrix}0&0\\0&U\end{pmatrix}
    The Kronecker product places a copy of BB, scaled by ajka_{jk}, in block (j,k)(j,k); here each block is 2×22\times2 and 00 denotes the 2×22\times2 zero block.
  3. Step 3:
    C-U=(I00U)=(1000010000u00u0100u10u11)C\text{-}U=\begin{pmatrix}I&0\\0&U\end{pmatrix}=\begin{pmatrix}1&0&0&0\\0&1&0&0\\0&0&u_{00}&u_{01}\\0&0&u_{10}&u_{11}\end{pmatrix}
    Add the two block matrices. With qubit 0 as the most significant bit, the upper-left block acts on ∣00⟩,∣01⟩\lvert00\rangle,\lvert01\rangle (control 00) and the lower-right block on ∣10⟩,∣11⟩\lvert10\rangle,\lvert11\rangle (control 11).
  4. Step 4:
    C-U ∣0⟩∣ψ⟩=P0∣0⟩⊗∣ψ⟩+P1∣0⟩⊗U∣ψ⟩=∣0⟩∣ψ⟩+0=∣0⟩∣ψ⟩C\text{-}U\,\lvert0\rangle\lvert\psi\rangle=P_0\lvert0\rangle\otimes\lvert\psi\rangle+P_1\lvert0\rangle\otimes U\lvert\psi\rangle=\lvert0\rangle\lvert\psi\rangle+0=\lvert0\rangle\lvert\psi\rangle
    Apply (A⊗B)(∣u⟩⊗∣v⟩)=A∣u⟩⊗B∣v⟩(A\otimes B)(\lvert u\rangle\otimes\lvert v\rangle)=A\lvert u\rangle\otimes B\lvert v\rangle to each term, with P0∣0⟩=∣0⟩P_0\lvert0\rangle=\lvert0\rangle and P1∣0⟩=∣1⟩⟨1∣0⟩=0P_1\lvert0\rangle=\lvert1\rangle\langle1\vert0\rangle=0.
  5. Step 5:
    C-U ∣1⟩∣ψ⟩=P0∣1⟩⊗∣ψ⟩+P1∣1⟩⊗U∣ψ⟩=0+∣1⟩⊗U∣ψ⟩C\text{-}U\,\lvert1\rangle\lvert\psi\rangle=P_0\lvert1\rangle\otimes\lvert\psi\rangle+P_1\lvert1\rangle\otimes U\lvert\psi\rangle=0+\lvert1\rangle\otimes U\lvert\psi\rangle
    Now P0∣1⟩=0P_0\lvert1\rangle=0 and P1∣1⟩=∣1⟩P_1\lvert1\rangle=\lvert1\rangle: the target receives UU exactly when the control is ∣1⟩\lvert1\rangle. Compactly, C-U∣a⟩∣ψ⟩=∣a⟩Ua∣ψ⟩C\text{-}U\lvert a\rangle\lvert\psi\rangle=\lvert a\rangle U^a\lvert\psi\rangle for a∈{0,1}a\in\{0,1\}.

Result

C-U=P0⊗I+P1⊗U=(I00U),C-U∣a⟩∣ψ⟩=∣a⟩ Ua∣ψ⟩\boxed{C\text{-}U=P_0\otimes I+P_1\otimes U=\begin{pmatrix}I&0\\0&U\end{pmatrix},\qquad C\text{-}U\lvert a\rangle\lvert\psi\rangle=\lvert a\rangle\,U^a\lvert\psi\rangle}
Proposition

C-UC\text{-}U is unitary

If UU is a unitary 2×22\times2 matrix, then C-U=P0⊗I+P1⊗UC\text{-}U=P_0\otimes I+P_1\otimes U is a unitary 4×44\times4 matrix, and its inverse is (C-U)−1=(C-U)†=C-(U†)(C\text{-}U)^{-1}=(C\text{-}U)^\dagger=C\text{-}(U^\dagger).

Proof (7 steps)
  1. Step 1:
    (C-U)†=P0†⊗I†+P1†⊗U†=P0⊗I+P1⊗U†(C\text{-}U)^\dagger=P_0^\dagger\otimes I^\dagger+P_1^\dagger\otimes U^\dagger=P_0\otimes I+P_1\otimes U^\dagger
    The adjoint is additive and satisfies (A⊗B)†=A†⊗B†(A\otimes B)^\dagger=A^\dagger\otimes B^\dagger; the projectors Pj=∣j⟩⟨j∣P_j=\lvert j\rangle\langle j\rvert and II are Hermitian.
  2. Step 2:
    PjPk=∣j⟩⟨j∣k⟩⟨k∣=δjk∣j⟩⟨k∣=δjkPj,P0+P1=IP_jP_k=\lvert j\rangle\langle j\vert k\rangle\langle k\rvert=\delta_{jk}\lvert j\rangle\langle k\rvert=\delta_{jk}P_j,\qquad P_0+P_1=I
    Orthonormality ⟨j∣k⟩=δjk\langle j\vert k\rangle=\delta_{jk} of the computational basis gives P02=P0P_0^2=P_0, P12=P1P_1^2=P_1, P0P1=P1P0=0P_0P_1=P_1P_0=0; completeness gives P0+P1=IP_0+P_1=I.
  3. Step 3:
    (C-U)†(C-U)=(P0⊗I+P1⊗U†)(P0⊗I+P1⊗U)(C\text{-}U)^\dagger(C\text{-}U)=(P_0\otimes I+P_1\otimes U^\dagger)(P_0\otimes I+P_1\otimes U)
    Substitute the adjoint from the first line.
  4. Step 4:
    =P0P0⊗I I+P0P1⊗I U+P1P0⊗U†I+P1P1⊗U†U=P_0P_0\otimes I\,I+P_0P_1\otimes I\,U+P_1P_0\otimes U^\dagger I+P_1P_1\otimes U^\dagger U
    Expand the product of two sums into four terms and apply the mixed-product rule (A⊗B)(C⊗D)=AC⊗BD(A\otimes B)(C\otimes D)=AC\otimes BD to each.
  5. Step 5:
    =P0⊗I+0+0+P1⊗I=P_0\otimes I+0+0+P_1\otimes I
    P0P0=P0P_0P_0=P_0, P0P1=P1P0=0P_0P_1=P_1P_0=0, P1P1=P1P_1P_1=P_1, and U†U=IU^\dagger U=I because UU is unitary. The cross terms vanish because the two branches act on orthogonal control states.
  6. Step 6:
    =(P0+P1)⊗I=I⊗I=I4=(P_0+P_1)\otimes I=I\otimes I=I_4
    The tensor product is bilinear, and P0+P1=IP_0+P_1=I.
  7. Step 7:
    (C-U)(C-U)†=P0⊗I+P1⊗UU†=I4,(C-U)†=P0⊗I+P1⊗U†=C-(U†)(C\text{-}U)(C\text{-}U)^\dagger=P_0\otimes I+P_1\otimes UU^\dagger=I_4,\qquad(C\text{-}U)^\dagger=P_0\otimes I+P_1\otimes U^\dagger=C\text{-}(U^\dagger)
    The same expansion in the opposite order uses UU†=IUU^\dagger=I. Both products are the identity, so C-UC\text{-}U is unitary and its inverse is the controlled-U†U^\dagger.

∎

CNOT=(I00X)=(1000010000010010)\mathrm{CNOT}=\begin{pmatrix}I&0\\0&X\end{pmatrix}=\begin{pmatrix}1&0&0&0\\0&1&0&0\\0&0&0&1\\0&0&1&0\end{pmatrix}
CNOT = C-X (control 0, target 1)4×4

Unitary verified: U†U=IU^\dagger U = I (max deviation 0.0e+0)

CZ=(I00Z)=(100001000010000−1)\mathrm{CZ}=\begin{pmatrix}I&0\\0&Z\end{pmatrix}=\begin{pmatrix}1&0&0&0\\0&1&0&0\\0&0&1&0\\0&0&0&-1\end{pmatrix}
CZ = C-Z4×4

Unitary verified: U†U=IU^\dagger U = I (max deviation 0.0e+0)

Derivation

CNOT\mathrm{CNOT} and CZ\mathrm{CZ} on basis states

  1. Step 1:
    Xa∣b⟩=∣a⊕b⟩,a,b∈{0,1}X^a\lvert b\rangle=\lvert a\oplus b\rangle,\qquad a,b\in\{0,1\}
    For a=0a=0, X0=IX^0=I and 0⊕b=b0\oplus b=b; for a=1a=1, X∣0⟩=∣1⟩X\lvert0\rangle=\lvert1\rangle and X∣1⟩=∣0⟩X\lvert1\rangle=\lvert0\rangle, i.e. X∣b⟩=∣1⊕b⟩X\lvert b\rangle=\lvert1\oplus b\rangle. Here ⊕\oplus is addition modulo 22 (XOR).
  2. Step 2:
    CNOT∣a,b⟩=∣a⟩ Xa∣b⟩=∣a, a⊕b⟩\mathrm{CNOT}\lvert a,b\rangle=\lvert a\rangle\,X^a\lvert b\rangle=\lvert a,\,a\oplus b\rangle
    Use C-U∣a⟩∣ψ⟩=∣a⟩Ua∣ψ⟩C\text{-}U\lvert a\rangle\lvert\psi\rangle=\lvert a\rangle U^a\lvert\psi\rangle with U=XU=X: the target bit is XORed with the control bit.
  3. Step 3:
    ∣00⟩↦∣00⟩,∣01⟩↦∣01⟩,∣10⟩↦∣11⟩,∣11⟩↦∣10⟩\lvert00\rangle\mapsto\lvert00\rangle,\quad\lvert01\rangle\mapsto\lvert01\rangle,\quad\lvert10\rangle\mapsto\lvert11\rangle,\quad\lvert11\rangle\mapsto\lvert10\rangle
    The four cases of the previous line. Column kk of the matrix is the image of basis state kk, which reproduces the permutation matrix shown above.
  4. Step 4:
    Za∣b⟩=(−1)ab∣b⟩Z^a\lvert b\rangle=(-1)^{ab}\lvert b\rangle
    Z∣b⟩=(−1)b∣b⟩Z\lvert b\rangle=(-1)^b\lvert b\rangle, so Za∣b⟩=(−1)ab∣b⟩Z^a\lvert b\rangle=(-1)^{ab}\lvert b\rangle for a∈{0,1}a\in\{0,1\}.
  5. Step 5:
    CZ∣a,b⟩=∣a⟩ Za∣b⟩=(−1)ab∣a,b⟩\mathrm{CZ}\lvert a,b\rangle=\lvert a\rangle\,Z^a\lvert b\rangle=(-1)^{ab}\lvert a,b\rangle
    The same rule with U=ZU=Z: only ∣11⟩\lvert11\rangle, where ab=1ab=1, acquires the sign −1-1, which is the diagonal (1,1,1,−1)(1,1,1,-1).

Result

CNOT∣a,b⟩=∣a,a⊕b⟩,CZ∣a,b⟩=(−1)ab∣a,b⟩\boxed{\mathrm{CNOT}\lvert a,b\rangle=\lvert a,a\oplus b\rangle,\qquad\mathrm{CZ}\lvert a,b\rangle=(-1)^{ab}\lvert a,b\rangle}

Circuit · 2 qubits

Quantum circuit on 2 qubitsX on q0; X on q1 controlled by q0q0q1X

Preparing ∣10⟩\lvert10\rangle with XX on qubit 0 and then applying CNOT01\mathrm{CNOT}_{01} gives ∣1,1⊕0⟩=∣11⟩\lvert1,1\oplus0\rangle=\lvert11\rangle: the statevector panel shows amplitude 11 on index 33.

∣ψ⟩=1∣11⟩\lvert\psi\rangle = 1\lvert 11\rangle

A CNOT on a superposed control. Basis inputs only exercise the truth table. Move the slider of the statevector view below through the circuit HH on qubit 0, then CNOT01\mathrm{CNOT}_{01}: position k=0k=0 shows the input, k=1k=1 the state after the Hadamard and k=2k=2 the output, with the gates applied so far highlighted in the diagram. Predict the three amplitude columns from the derivation first; all amplitudes stay real and non-negative, so every nonzero amplitude has phase 00.

Derivation

The state after each operation of H0H_0, CNOT01\mathrm{CNOT}_{01}

  1. Step 1:
    k=0:∣00⟩ ↔ (1,0,0,0)Tk=0:\quad\lvert00\rangle\ \leftrightarrow\ (1,0,0,0)^{\mathsf T}
    Every qubit starts in ∣0⟩\lvert0\rangle; amplitudes are listed in the order ∣00⟩,∣01⟩,∣10⟩,∣11⟩\lvert00\rangle,\lvert01\rangle,\lvert10\rangle,\lvert11\rangle.
  2. Step 2:
    k=1:(H⊗I)∣00⟩=12(∣0⟩+∣1⟩)⊗∣0⟩=12(∣00⟩+∣10⟩) ↔ (12,0,12,0)Tk=1:\quad(H\otimes I)\lvert00\rangle=\tfrac1{\sqrt2}\big(\lvert0\rangle+\lvert1\rangle\big)\otimes\lvert0\rangle=\tfrac1{\sqrt2}\big(\lvert00\rangle+\lvert10\rangle\big)\ \leftrightarrow\ \big(\tfrac1{\sqrt2},0,\tfrac1{\sqrt2},0\big)^{\mathsf T}
    HH acts on qubit 0, the most significant bit, so the weight moves to indices 00 and 22.
  3. Step 3:
    k=2:CNOT 12(∣00⟩+∣10⟩)=12(∣00⟩+∣11⟩) ↔ (12,0,0,12)Tk=2:\quad\mathrm{CNOT}\,\tfrac1{\sqrt2}\big(\lvert00\rangle+\lvert10\rangle\big)=\tfrac1{\sqrt2}\big(\lvert00\rangle+\lvert11\rangle\big)\ \leftrightarrow\ \big(\tfrac1{\sqrt2},0,0,\tfrac1{\sqrt2}\big)^{\mathsf T}
    Linearity with CNOT∣00⟩=∣00⟩\mathrm{CNOT}\lvert00\rangle=\lvert00\rangle and CNOT∣10⟩=∣11⟩\mathrm{CNOT}\lvert10\rangle=\lvert11\rangle: the branch with control 11 flips its target, the other is left alone.
  4. Step 4:
    (a∣0⟩+b∣1⟩)⊗(c∣0⟩+d∣1⟩)=ac∣00⟩+ad∣01⟩+bc∣10⟩+bd∣11⟩(a\lvert0\rangle+b\lvert1\rangle)\otimes(c\lvert0\rangle+d\lvert1\rangle)=ac\lvert00\rangle+ad\lvert01\rangle+bc\lvert10\rangle+bd\lvert11\rangle
    A product state would need ad=bc=0ad=bc=0 while ac=bd=12ac=bd=\tfrac1{\sqrt2}; but ad=0ad=0 forces a=0a=0 (then ac=0ac=0) or d=0d=0 (then bd=0bd=0). The output is therefore not a product state: it is entangled, the Bell state ∣Φ+⟩\lvert\Phi^+\rangle of the next lesson.

Result

∣00⟩ ↦H0 12(∣00⟩+∣10⟩) ↦CNOT01 12(∣00⟩+∣11⟩)\boxed{\lvert00\rangle\ \xmapsto{H_0}\ \tfrac1{\sqrt2}\big(\lvert00\rangle+\lvert10\rangle\big)\ \xmapsto{\mathrm{CNOT}_{01}}\ \tfrac1{\sqrt2}\big(\lvert00\rangle+\lvert11\rangle\big)}

Quick check

Which state is CNOT01∣11⟩\mathrm{CNOT}_{01}\lvert11\rangle?

Select one answer

CZ is symmetric; CNOT from CZ#

Proposition

CZ\mathrm{CZ} does not distinguish control from target

CZ=P0⊗I+P1⊗Z=I⊗P0+Z⊗P1=diag(1,1,1,−1)\mathrm{CZ}=P_0\otimes I+P_1\otimes Z=I\otimes P_0+Z\otimes P_1=\mathrm{diag}(1,1,1,-1). Hence the controlled-ZZ with control 0 and target 1 equals the controlled-ZZ with control 1 and target 0, and SWAP CZ SWAP=CZ\mathrm{SWAP}\,\mathrm{CZ}\,\mathrm{SWAP}=\mathrm{CZ}.

Proof (5 steps)
  1. Step 1:
    P0⊗I=diag(1,1,0,0),P1⊗Z=diag(0,0,1,−1)P_0\otimes I=\mathrm{diag}(1,1,0,0),\qquad P_1\otimes Z=\mathrm{diag}(0,0,1,-1)
    Kronecker products of diagonal matrices are diagonal: diag(p0,p1)⊗diag(q0,q1)=diag(p0q0,p0q1,p1q0,p1q1)\mathrm{diag}(p_0,p_1)\otimes\mathrm{diag}(q_0,q_1)=\mathrm{diag}(p_0q_0,p_0q_1,p_1q_0,p_1q_1), with P0=diag(1,0)P_0=\mathrm{diag}(1,0), P1=diag(0,1)P_1=\mathrm{diag}(0,1), Z=diag(1,−1)Z=\mathrm{diag}(1,-1).
  2. Step 2:
    P0⊗I+P1⊗Z=diag(1,1,1,−1)P_0\otimes I+P_1\otimes Z=\mathrm{diag}(1,1,1,-1)
    Add the two diagonals entry by entry.
  3. Step 3:
    I⊗P0=diag(1,0,1,0),Z⊗P1=diag(0,1,0,−1)I\otimes P_0=\mathrm{diag}(1,0,1,0),\qquad Z\otimes P_1=\mathrm{diag}(0,1,0,-1)
    The same rule with the factors in the other order: diag(1,1)⊗diag(1,0)\mathrm{diag}(1,1)\otimes\mathrm{diag}(1,0) and diag(1,−1)⊗diag(0,1)\mathrm{diag}(1,-1)\otimes\mathrm{diag}(0,1).
  4. Step 4:
    I⊗P0+Z⊗P1=diag(1,1,1,−1)=CZI\otimes P_0+Z\otimes P_1=\mathrm{diag}(1,1,1,-1)=\mathrm{CZ}
    Add the diagonals. The operator I⊗P0+Z⊗P1I\otimes P_0+Z\otimes P_1 is, by definition, the controlled-ZZ with control on qubit 1 and target on qubit 0, so both orientations give the same matrix.
  5. Step 5:
    SWAP CZ SWAP∣a,b⟩=SWAP CZ∣b,a⟩=(−1)ba SWAP∣b,a⟩=(−1)ab∣a,b⟩=CZ∣a,b⟩\mathrm{SWAP}\,\mathrm{CZ}\,\mathrm{SWAP}\lvert a,b\rangle=\mathrm{SWAP}\,\mathrm{CZ}\lvert b,a\rangle=(-1)^{ba}\,\mathrm{SWAP}\lvert b,a\rangle=(-1)^{ab}\lvert a,b\rangle=\mathrm{CZ}\lvert a,b\rangle
    Equivalent formulation with basis labels: SWAP∣a,b⟩=∣b,a⟩\mathrm{SWAP}\lvert a,b\rangle=\lvert b,a\rangle, CZ∣a,b⟩=(−1)ab∣a,b⟩\mathrm{CZ}\lvert a,b\rangle=(-1)^{ab}\lvert a,b\rangle, and ba=abba=ab. The two operators agree on a basis, hence everywhere by linearity.

∎

The matrix display below prints CZ\mathrm{CZ} with its rows and columns labelled ∣00⟩,∣01⟩,∣10⟩,∣11⟩\lvert00\rangle,\lvert01\rangle,\lvert10\rangle,\lvert11\rangle (qubit 0 first) and lists its properties. A real diagonal matrix with entries ±1\pm1 is Hermitian and unitary at once; its trace is 1+1+1−1=21+1+1-1=2, its determinant 1⋅1⋅1⋅(−1)=−11\cdot1\cdot1\cdot(-1)=-1, and its eigenvalues are the diagonal entries −1,1,1,1-1,1,1,1, with the single −1-1 eigenvector ∣11⟩\lvert11\rangle. Nothing in this list refers to which qubit is the control, which is the symmetry just proved.

Derivation

CNOT=(I⊗H) CZ (I⊗H)\mathrm{CNOT}=(I\otimes H)\,\mathrm{CZ}\,(I\otimes H), block by block

  1. Step 1:
    I⊗H=(H00H)=12(11001−1000011001−1)I\otimes H=\begin{pmatrix}H&0\\0&H\end{pmatrix}=\frac1{\sqrt2}\begin{pmatrix}1&1&0&0\\1&-1&0&0\\0&0&1&1\\0&0&1&-1\end{pmatrix}
    The Kronecker product I⊗HI\otimes H has 1⋅H1\cdot H in both diagonal blocks and 0⋅H0\cdot H off the diagonal.
  2. Step 2:
    (I⊗H) CZ (I⊗H)=(H00H)(I00Z)(H00H)=(HIH00HZH)(I\otimes H)\,\mathrm{CZ}\,(I\otimes H)=\begin{pmatrix}H&0\\0&H\end{pmatrix}\begin{pmatrix}I&0\\0&Z\end{pmatrix}\begin{pmatrix}H&0\\0&H\end{pmatrix}=\begin{pmatrix}HIH&0\\0&HZH\end{pmatrix}
    Block-diagonal matrices multiply block by block: the (0,0)(0,0) block is H⋅I⋅HH\cdot I\cdot H and the (1,1)(1,1) block is H⋅Z⋅HH\cdot Z\cdot H; every off-diagonal block contains a factor 00.
  3. Step 3:
    HIH=H2=I,HZH=XHIH=H^2=I,\qquad HZH=X
    Both identities were proved in the Hadamard lesson: H2=IH^2=I follows from {X,Z}=0\{X,Z\}=0, and HZH=12(X+Z)Z(X+Z)=12(I−iY)(X+Z)=XHZH=\tfrac12(X+Z)Z(X+Z)=\tfrac12(I-iY)(X+Z)=X.
  4. Step 4:
    (I⊗H) CZ (I⊗H)=(I00X)=CNOT(I\otimes H)\,\mathrm{CZ}\,(I\otimes H)=\begin{pmatrix}I&0\\0&X\end{pmatrix}=\mathrm{CNOT}
    Insert the two blocks; this is the block form of C-XC\text{-}X.
  5. Step 5:
    CZ (I⊗H)=12(11001−100001100−11),12(111−1)⋅12(11−11)=12(0220)=X\mathrm{CZ}\,(I\otimes H)=\frac1{\sqrt2}\begin{pmatrix}1&1&0&0\\1&-1&0&0\\0&0&1&1\\0&0&-1&1\end{pmatrix},\qquad\frac1{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}\cdot\frac1{\sqrt2}\begin{pmatrix}1&1\\-1&1\end{pmatrix}=\frac12\begin{pmatrix}0&2\\2&0\end{pmatrix}=X
    Entry-level check of the lower-right block: left multiplication by the diagonal CZ\mathrm{CZ} negates the last row of I⊗HI\otimes H; then HH times the block ZH=12(11−11)ZH=\tfrac1{\sqrt2}\begin{pmatrix}1&1\\-1&1\end{pmatrix} gives 12(1−11+11+11−1)=X\tfrac12\begin{pmatrix}1-1&1+1\\1+1&1-1\end{pmatrix}=X. The upper-left block is H⋅H=IH\cdot H=I.
  6. Step 6:
    (I⊗H)(P0⊗I+P1⊗Z)(I⊗H)=P0⊗HIH+P1⊗HZH=P0⊗I+P1⊗X(I\otimes H)(P_0\otimes I+P_1\otimes Z)(I\otimes H)=P_0\otimes HIH+P_1\otimes HZH=P_0\otimes I+P_1\otimes X
    The same computation in projector form, using the mixed-product rule: conjugating the target of a controlled gate conjugates UU, C-U↦C-(VUV†)C\text{-}U\mapsto C\text{-}(VUV^\dagger) for V=H=H†V=H=H^\dagger.
  7. Step 7:
    (I⊗H) CNOT (I⊗H)=(I⊗H)2 CZ (I⊗H)2=CZ(I\otimes H)\,\mathrm{CNOT}\,(I\otimes H)=(I\otimes H)^2\,\mathrm{CZ}\,(I\otimes H)^2=\mathrm{CZ}
    Conversely, multiply both sides of CNOT=(I⊗H)CZ(I⊗H)\mathrm{CNOT}=(I\otimes H)\mathrm{CZ}(I\otimes H) by I⊗HI\otimes H on the left and right, and use (I⊗H)2=I⊗H2=I4(I\otimes H)^2=I\otimes H^2=I_4.

Result

CNOT=(I⊗H) CZ (I⊗H),CZ=(I⊗H) CNOT (I⊗H)\boxed{\mathrm{CNOT}=(I\otimes H)\,\mathrm{CZ}\,(I\otimes H),\qquad\mathrm{CZ}=(I\otimes H)\,\mathrm{CNOT}\,(I\otimes H)}

Circuit · 2 qubits

Quantum circuit on 2 qubitsH on q1; Z on q1 controlled by q0; H on q1q0q1HH

The sandwich HH on qubit 1, CZ\mathrm{CZ}, HH on qubit 1. The unitary panel shows exactly the CNOT permutation matrix, with no global phase: the target Hadamards turn the phase flip ZZ into the bit flip XX.

U=(1000010000010010)U = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix}

Quick check

Which circuit implements CZ\mathrm{CZ} exactly, using one CNOT01\mathrm{CNOT}_{01}?

Select one answer

Exchanging control and target#

The CNOT with control on qubit 1 and target on qubit 0 is CNOT10=I⊗P0+X⊗P1\mathrm{CNOT}_{10}=I\otimes P_0+X\otimes P_1: on basis states CNOT10∣a,b⟩=Xb∣a⟩⊗∣b⟩=∣a⊕b, b⟩\mathrm{CNOT}_{10}\lvert a,b\rangle=X^b\lvert a\rangle\otimes\lvert b\rangle=\lvert a\oplus b,\,b\rangle. Its columns are the images ∣00⟩↦∣00⟩\lvert00\rangle\mapsto\lvert00\rangle, ∣01⟩↦∣11⟩\lvert01\rangle\mapsto\lvert11\rangle, ∣10⟩↦∣10⟩\lvert10\rangle\mapsto\lvert10\rangle, ∣11⟩↦∣01⟩\lvert11\rangle\mapsto\lvert01\rangle. On hardware with a fixed CNOT direction the reversed gate is obtained from the forward one by Hadamards on both qubits.

CNOT10=I⊗P0+X⊗P1=(1000000100100100)\mathrm{CNOT}_{10}=I\otimes P_0+X\otimes P_1=\begin{pmatrix}1&0&0&0\\0&0&0&1\\0&0&1&0\\0&1&0&0\end{pmatrix}
CNOT10 (control 1, target 0)4×4

Unitary verified: U†U=IU^\dagger U = I (max deviation 0.0e+0)

Proposition

Reversing a CNOT with four Hadamards

(H⊗H) CNOT01 (H⊗H)=CNOT10(H\otimes H)\,\mathrm{CNOT}_{01}\,(H\otimes H)=\mathrm{CNOT}_{10}. In the Hadamard basis {∣+⟩,∣−⟩}\{\lvert+\rangle,\lvert-\rangle\} the roles of control and target are exchanged.

Proof (6 steps)
  1. Step 1:
    H⊗H=(H⊗I)(I⊗H)=(I⊗H)(H⊗I)H\otimes H=(H\otimes I)(I\otimes H)=(I\otimes H)(H\otimes I)
    Mixed-product rule: (H⊗I)(I⊗H)=HI⊗IH=H⊗H(H\otimes I)(I\otimes H)=HI\otimes IH=H\otimes H, and likewise in the other order. Gates on different qubits commute.
  2. Step 2:
    (H⊗H) CNOT01 (H⊗H)=(H⊗I)(I⊗H) (I⊗H) CZ (I⊗H) (I⊗H)(H⊗I)(H\otimes H)\,\mathrm{CNOT}_{01}\,(H\otimes H)=(H\otimes I)(I\otimes H)\,(I\otimes H)\,\mathrm{CZ}\,(I\otimes H)\,(I\otimes H)(H\otimes I)
    Substitute CNOT01=(I⊗H)CZ(I⊗H)\mathrm{CNOT}_{01}=(I\otimes H)\mathrm{CZ}(I\otimes H) from the previous section, and split the outer H⊗HH\otimes H as in the first line (left factor (H⊗I)(I⊗H)(H\otimes I)(I\otimes H), right factor (I⊗H)(H⊗I)(I\otimes H)(H\otimes I)).
  3. Step 3:
    =(H⊗I) CZ (H⊗I)=(H\otimes I)\,\mathrm{CZ}\,(H\otimes I)
    (I⊗H)(I⊗H)=I⊗H2=I4(I\otimes H)(I\otimes H)=I\otimes H^2=I_4 on both sides of CZ\mathrm{CZ}.
  4. Step 4:
    =(H⊗I)(I⊗P0+Z⊗P1)(H⊗I)=HIH⊗P0+HZH⊗P1=(H\otimes I)(I\otimes P_0+Z\otimes P_1)(H\otimes I)=HIH\otimes P_0+HZH\otimes P_1
    Use the symmetric form CZ=I⊗P0+Z⊗P1\mathrm{CZ}=I\otimes P_0+Z\otimes P_1 proved above, then the mixed-product rule on each term.
  5. Step 5:
    =I⊗P0+X⊗P1=CNOT10=I\otimes P_0+X\otimes P_1=\mathrm{CNOT}_{10}
    H2=IH^2=I and HZH=XHZH=X. The result applies XX to qubit 0 exactly when qubit 1 is ∣1⟩\lvert1\rangle.
  6. Step 6:
    (H⊗H) CNOT01 (H⊗H) ∣01⟩=CNOT10∣01⟩=∣0⊕1, 1⟩=∣11⟩(H\otimes H)\,\mathrm{CNOT}_{01}\,(H\otimes H)\,\lvert01\rangle=\mathrm{CNOT}_{10}\lvert01\rangle=\lvert0\oplus1,\,1\rangle=\lvert11\rangle
    Spot check on a basis state with a=0a=0, b=1b=1: the target qubit 0 is flipped because the control qubit 1 is set, matching the second column of the CNOT10\mathrm{CNOT}_{10} matrix.

∎

Circuit · 2 qubits

Quantum circuit on 2 qubitsH on q0; H on q1; X on q1 controlled by q0; H on q0; H on q1q0q1HHHH

H⊗HH\otimes H, then CNOT01\mathrm{CNOT}_{01}, then H⊗HH\otimes H. The unitary panel shows the CNOT10\mathrm{CNOT}_{10} permutation matrix (columns ∣01⟩↔∣11⟩\lvert01\rangle\leftrightarrow\lvert11\rangle exchanged), exactly and with no global phase.

U=(1000000100100100)U = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \end{pmatrix}

The display below computes the unitary of the one-gate circuit CNOT10\mathrm{CNOT}_{10} directly with the simulator and prints it with basis labels. Read its columns: ∣01⟩↦∣11⟩\lvert01\rangle\mapsto\lvert11\rangle and ∣11⟩↦∣01⟩\lvert11\rangle\mapsto\lvert01\rangle, while ∣00⟩\lvert00\rangle and ∣10⟩\lvert10\rangle are fixed. Its properties coincide with those of CNOT01\mathrm{CNOT}_{01}: Hermitian and unitary, trace 22 (two fixed basis states), determinant −1-1 (a permutation matrix of a single transposition), eigenvalues −1,1,1,1-1,1,1,1. The −1-1 eigenvector is ∣−⟩⊗∣1⟩=12(∣01⟩−∣11⟩)\lvert-\rangle\otimes\lvert1\rangle=\tfrac1{\sqrt2}(\lvert01\rangle-\lvert11\rangle): target qubit 0 in ∣−⟩\lvert-\rangle, control qubit 1 in ∣1⟩\lvert1\rangle, a first glimpse of the phase kickback below.

SWAP from three CNOTs#

Definition

SWAP gate

The SWAP gate exchanges the states of two qubits: SWAP∣a,b⟩=∣b,a⟩\mathrm{SWAP}\lvert a,b\rangle=\lvert b,a\rangle for a,b∈{0,1}a,b\in\{0,1\}, extended linearly, so that SWAP(∣φ⟩⊗∣χ⟩)=∣χ⟩⊗∣φ⟩\mathrm{SWAP}(\lvert\varphi\rangle\otimes\lvert\chi\rangle)=\lvert\chi\rangle\otimes\lvert\varphi\rangle for all single-qubit states. It fixes ∣00⟩\lvert00\rangle and ∣11⟩\lvert11\rangle and exchanges ∣01⟩↔∣10⟩\lvert01\rangle\leftrightarrow\lvert10\rangle.

SWAP=∣00⟩⟨00∣+∣01⟩⟨10∣+∣10⟩⟨01∣+∣11⟩⟨11∣=(1000001001000001)\mathrm{SWAP}=\lvert00\rangle\langle00\rvert+\lvert01\rangle\langle10\rvert+\lvert10\rangle\langle01\rvert+\lvert11\rangle\langle11\rvert=\begin{pmatrix}1&0&0&0\\0&0&1&0\\0&1&0&0\\0&0&0&1\end{pmatrix}
SWAP4×4

Unitary verified: U†U=IU^\dagger U = I (max deviation 0.0e+0)

Theorem

SWAP=CNOT01 CNOT10 CNOT01\mathrm{SWAP}=\mathrm{CNOT}_{01}\,\mathrm{CNOT}_{10}\,\mathrm{CNOT}_{01}

Applying CNOT01\mathrm{CNOT}_{01}, then CNOT10\mathrm{CNOT}_{10}, then CNOT01\mathrm{CNOT}_{01} implements the SWAP gate exactly: M=CNOT01CNOT10CNOT01M=\mathrm{CNOT}_{01}\mathrm{CNOT}_{10}\mathrm{CNOT}_{01} satisfies M∣ψ⟩=SWAP∣ψ⟩M\lvert\psi\rangle=\mathrm{SWAP}\lvert\psi\rangle for every two-qubit state ∣ψ⟩\lvert\psi\rangle.

Proof (7 steps)
  1. Step 1:
    x⊕x=0,x⊕0=x,x⊕y=y⊕x,(x⊕y)⊕z=x⊕(y⊕z)x\oplus x=0,\qquad x\oplus0=x,\qquad x\oplus y=y\oplus x,\qquad(x\oplus y)\oplus z=x\oplus(y\oplus z)
    Addition modulo 22 on {0,1}\{0,1\} is commutative and associative, 00 is neutral, and every bit is its own inverse.
  2. Step 2:
    CNOT01∣a,b⟩=∣a, a⊕b⟩\mathrm{CNOT}_{01}\lvert a,b\rangle=\lvert a,\,a\oplus b\rangle
    First gate: control qubit 0, target qubit 1.
  3. Step 3:
    CNOT10∣a, a⊕b⟩=∣a⊕(a⊕b), a⊕b⟩=∣b, a⊕b⟩\mathrm{CNOT}_{10}\lvert a,\,a\oplus b\rangle=\lvert a\oplus(a\oplus b),\,a\oplus b\rangle=\lvert b,\,a\oplus b\rangle
    Second gate: control qubit 1 (value a⊕ba\oplus b), target qubit 0, so qubit 0 becomes (a⊕b)⊕a(a\oplus b)\oplus a; by associativity and a⊕a=0a\oplus a=0 this is 0⊕b=b0\oplus b=b.
  4. Step 4:
    CNOT01∣b, a⊕b⟩=∣b, b⊕(a⊕b)⟩=∣b,a⟩\mathrm{CNOT}_{01}\lvert b,\,a\oplus b\rangle=\lvert b,\,b\oplus(a\oplus b)\rangle=\lvert b,a\rangle
    Third gate: control qubit 0 (now bb), target qubit 1, which becomes b⊕a⊕b=a⊕(b⊕b)=ab\oplus a\oplus b=a\oplus(b\oplus b)=a.
  5. Step 5:
    M∣a,b⟩=∣b,a⟩=SWAP∣a,b⟩for all a,b∈{0,1}M\lvert a,b\rangle=\lvert b,a\rangle=\mathrm{SWAP}\lvert a,b\rangle\quad\text{for all }a,b\in\{0,1\}
    The operator for the wire order CNOT01;CNOT10;CNOT01\mathrm{CNOT}_{01};\mathrm{CNOT}_{10};\mathrm{CNOT}_{01} is the product M=CNOT01CNOT10CNOT01M=\mathrm{CNOT}_{01}\mathrm{CNOT}_{10}\mathrm{CNOT}_{01} (the first gate acts first); the three lines above evaluate it on every basis state.
  6. Step 6:
    M∣ψ⟩=M∑a,bcab∣a,b⟩=∑a,bcabM∣a,b⟩=∑a,bcab∣b,a⟩=SWAP∣ψ⟩M\lvert\psi\rangle=M\textstyle\sum_{a,b}c_{ab}\lvert a,b\rangle=\sum_{a,b}c_{ab}M\lvert a,b\rangle=\sum_{a,b}c_{ab}\lvert b,a\rangle=\mathrm{SWAP}\lvert\psi\rangle
    Every two-qubit state is a linear combination ∣ψ⟩=∑a,bcab∣a,b⟩\lvert\psi\rangle=\sum_{a,b}c_{ab}\lvert a,b\rangle; both MM and SWAP\mathrm{SWAP} are linear and agree on the basis, so they agree everywhere: M=SWAPM=\mathrm{SWAP}.
  7. Step 7:
    SWAP(∣φ⟩⊗∣χ⟩)=∑a,bφaχb∣b,a⟩=(∑bχb∣b⟩)⊗(∑aφa∣a⟩)=∣χ⟩⊗∣φ⟩\mathrm{SWAP}(\lvert\varphi\rangle\otimes\lvert\chi\rangle)=\textstyle\sum_{a,b}\varphi_a\chi_b\lvert b,a\rangle=\Big(\sum_b\chi_b\lvert b\rangle\Big)\otimes\Big(\sum_a\varphi_a\lvert a\rangle\Big)=\lvert\chi\rangle\otimes\lvert\varphi\rangle
    For a product state ∣φ⟩⊗∣χ⟩=∑a,bφaχb∣a,b⟩\lvert\varphi\rangle\otimes\lvert\chi\rangle=\sum_{a,b}\varphi_a\chi_b\lvert a,b\rangle, regrouping the sum by bilinearity of ⊗\otimes shows that superpositions, not only basis labels, are exchanged.

∎

Derivation

The three CNOTs on the four basis states

  1. Step 1:
    ∣00⟩↦CNOT01∣00⟩↦CNOT10∣00⟩↦CNOT01∣00⟩\lvert00\rangle\xmapsto{\mathrm{CNOT}_{01}}\lvert00\rangle\xmapsto{\mathrm{CNOT}_{10}}\lvert00\rangle\xmapsto{\mathrm{CNOT}_{01}}\lvert00\rangle
    Every control is 00, so nothing happens.
  2. Step 2:
    ∣01⟩↦CNOT01∣01⟩↦CNOT10∣11⟩↦CNOT01∣10⟩\lvert01\rangle\xmapsto{\mathrm{CNOT}_{01}}\lvert01\rangle\xmapsto{\mathrm{CNOT}_{10}}\lvert11\rangle\xmapsto{\mathrm{CNOT}_{01}}\lvert10\rangle
    The first control (qubit 0) is 00; then qubit 1 is 11 and flips qubit 0; then qubit 0 is 11 and flips qubit 1.
  3. Step 3:
    ∣10⟩↦CNOT01∣11⟩↦CNOT10∣01⟩↦CNOT01∣01⟩\lvert10\rangle\xmapsto{\mathrm{CNOT}_{01}}\lvert11\rangle\xmapsto{\mathrm{CNOT}_{10}}\lvert01\rangle\xmapsto{\mathrm{CNOT}_{01}}\lvert01\rangle
    Qubit 0 is 11 and flips qubit 1; then qubit 1 is 11 and flips qubit 0 back to 00; finally qubit 0 is 00, so the last CNOT does nothing.
  4. Step 4:
    ∣11⟩↦CNOT01∣10⟩↦CNOT10∣10⟩↦CNOT01∣11⟩\lvert11\rangle\xmapsto{\mathrm{CNOT}_{01}}\lvert10\rangle\xmapsto{\mathrm{CNOT}_{10}}\lvert10\rangle\xmapsto{\mathrm{CNOT}_{01}}\lvert11\rangle
    Qubit 1 is flipped to 00; then the control qubit 1 is 00; finally qubit 0 is 11 and flips qubit 1 back to 11.

Result

∣00⟩↦∣00⟩,∣01⟩↦∣10⟩,∣10⟩↦∣01⟩,∣11⟩↦∣11⟩\boxed{\lvert00\rangle\mapsto\lvert00\rangle,\quad\lvert01\rangle\mapsto\lvert10\rangle,\quad\lvert10\rangle\mapsto\lvert01\rangle,\quad\lvert11\rangle\mapsto\lvert11\rangle}

Circuit · 2 qubits

Quantum circuit on 2 qubitsX on q1 controlled by q0; X on q0 controlled by q1; X on q1 controlled by q0q0q1

Three alternating CNOTs. The unitary panel shows the SWAP permutation matrix exactly: rows and columns ∣01⟩\lvert01\rangle and ∣10⟩\lvert10\rangle exchanged.

U=(1000001001000001)U = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}

Circuit · 2 qubits

Quantum circuit on 2 qubitsX on q0; X on q1 controlled by q0; X on q0 controlled by q1; X on q1 controlled by q0q0q1X

Preparing ∣10⟩\lvert10\rangle and applying the three CNOTs moves the excitation to qubit 1: the output is ∣01⟩\lvert01\rangle, amplitude 11 on index 11.

∣ψ⟩=1∣01⟩\lvert\psi\rangle = 1\lvert 01\rangle

Quick check

What does the two-gate circuit CNOT01\mathrm{CNOT}_{01} followed by CNOT10\mathrm{CNOT}_{10} implement?

Select one answer

Phase kickback#

Proposition

Phase kickback

For x∈{0,1}x\in\{0,1\}, CNOT∣x⟩∣−⟩=(−1)x∣x⟩∣−⟩\mathrm{CNOT}\lvert x\rangle\lvert-\rangle=(-1)^x\lvert x\rangle\lvert-\rangle with ∣−⟩=12(∣0⟩−∣1⟩)\lvert-\rangle=\tfrac1{\sqrt2}(\lvert0\rangle-\lvert1\rangle). More generally, if U∣u⟩=eiφ∣u⟩U\lvert u\rangle=e^{i\varphi}\lvert u\rangle, then C-U∣x⟩∣u⟩=eixφ∣x⟩∣u⟩C\text{-}U\lvert x\rangle\lvert u\rangle=e^{ix\varphi}\lvert x\rangle\lvert u\rangle: the target is unchanged and the eigenvalue phase is attached to the control.

Proof (6 steps)
  1. Step 1:
    X∣−⟩=12(X∣0⟩−X∣1⟩)=12(∣1⟩−∣0⟩)=−∣−⟩X\lvert-\rangle=\tfrac1{\sqrt2}\big(X\lvert0\rangle-X\lvert1\rangle\big)=\tfrac1{\sqrt2}\big(\lvert1\rangle-\lvert0\rangle\big)=-\lvert-\rangle
    XX is linear and exchanges ∣0⟩\lvert0\rangle and ∣1⟩\lvert1\rangle; so ∣−⟩\lvert-\rangle is an eigenvector of XX with eigenvalue −1-1.
  2. Step 2:
    CNOT(∣x⟩⊗∣−⟩)=∣x⟩⊗Xx∣−⟩\mathrm{CNOT}\big(\lvert x\rangle\otimes\lvert-\rangle\big)=\lvert x\rangle\otimes X^x\lvert-\rangle
    Block-form rule C-U∣a⟩∣ψ⟩=∣a⟩Ua∣ψ⟩C\text{-}U\lvert a\rangle\lvert\psi\rangle=\lvert a\rangle U^a\lvert\psi\rangle with U=XU=X and ∣ψ⟩=∣−⟩\lvert\psi\rangle=\lvert-\rangle.
  3. Step 3:
    Xx∣−⟩=(−1)x∣−⟩X^x\lvert-\rangle=(-1)^x\lvert-\rangle
    For x=0x=0, X0=IX^0=I; for x=1x=1, the first line.
  4. Step 4:
    CNOT∣x⟩∣−⟩=∣x⟩⊗(−1)x∣−⟩=(−1)x∣x⟩∣−⟩\mathrm{CNOT}\lvert x\rangle\lvert-\rangle=\lvert x\rangle\otimes(-1)^x\lvert-\rangle=(-1)^x\lvert x\rangle\lvert-\rangle
    A scalar can be moved across the tensor product: u⊗(cv)=c(u⊗v)=(cu)⊗vu\otimes(cv)=c(u\otimes v)=(cu)\otimes v. The sign can be read as belonging to the control.
  5. Step 5:
    CNOT∣1⟩∣−⟩=12(CNOT∣10⟩−CNOT∣11⟩)=12(∣11⟩−∣10⟩)=−∣1⟩∣−⟩\mathrm{CNOT}\lvert1\rangle\lvert-\rangle=\tfrac1{\sqrt2}\big(\mathrm{CNOT}\lvert10\rangle-\mathrm{CNOT}\lvert11\rangle\big)=\tfrac1{\sqrt2}\big(\lvert11\rangle-\lvert10\rangle\big)=-\lvert1\rangle\lvert-\rangle
    Direct check of the case x=1x=1 with the basis table ∣10⟩↦∣11⟩\lvert10\rangle\mapsto\lvert11\rangle, ∣11⟩↦∣10⟩\lvert11\rangle\mapsto\lvert10\rangle.
  6. Step 6:
    C-U∣x⟩∣u⟩=∣x⟩⊗Ux∣u⟩=∣x⟩⊗eixφ∣u⟩=eixφ∣x⟩∣u⟩C\text{-}U\lvert x\rangle\lvert u\rangle=\lvert x\rangle\otimes U^x\lvert u\rangle=\lvert x\rangle\otimes e^{ix\varphi}\lvert u\rangle=e^{ix\varphi}\lvert x\rangle\lvert u\rangle
    The same three steps for any controlled-UU and eigenvector U∣u⟩=eiφ∣u⟩U\lvert u\rangle=e^{i\varphi}\lvert u\rangle, using Ux∣u⟩=eixφ∣u⟩U^x\lvert u\rangle=e^{ix\varphi}\lvert u\rangle. The CNOT case is U=XU=X, ∣u⟩=∣−⟩\lvert u\rangle=\lvert-\rangle, eiφ=−1e^{i\varphi}=-1.

∎

Derivation

CNOT∣+⟩∣−⟩=∣−⟩∣−⟩\mathrm{CNOT}\lvert+\rangle\lvert-\rangle=\lvert-\rangle\lvert-\rangle

  1. Step 1:
    ∣+⟩∣−⟩=12(∣0⟩+∣1⟩)⊗12(∣0⟩−∣1⟩)=12(∣00⟩−∣01⟩+∣10⟩−∣11⟩)\lvert+\rangle\lvert-\rangle=\tfrac1{\sqrt2}(\lvert0\rangle+\lvert1\rangle)\otimes\tfrac1{\sqrt2}(\lvert0\rangle-\lvert1\rangle)=\tfrac12\big(\lvert00\rangle-\lvert01\rangle+\lvert10\rangle-\lvert11\rangle\big)
    Expand the tensor product by bilinearity; the amplitude vector is 12(1,−1,1,−1)T\tfrac12(1,-1,1,-1)^T.
  2. Step 2:
    CNOT∣+⟩∣−⟩=12(∣00⟩−∣01⟩+∣11⟩−∣10⟩)\mathrm{CNOT}\lvert+\rangle\lvert-\rangle=\tfrac12\big(\lvert00\rangle-\lvert01\rangle+\lvert11\rangle-\lvert10\rangle\big)
    Apply CNOT\mathrm{CNOT} term by term: ∣00⟩\lvert00\rangle and ∣01⟩\lvert01\rangle are unchanged, ∣10⟩↦∣11⟩\lvert10\rangle\mapsto\lvert11\rangle and ∣11⟩↦∣10⟩\lvert11\rangle\mapsto\lvert10\rangle.
  3. Step 3:
    =12(∣00⟩−∣01⟩−∣10⟩+∣11⟩)=12(∣0⟩−∣1⟩)⊗12(∣0⟩−∣1⟩)=∣−⟩∣−⟩=\tfrac12\big(\lvert00\rangle-\lvert01\rangle-\lvert10\rangle+\lvert11\rangle\big)=\tfrac1{\sqrt2}(\lvert0\rangle-\lvert1\rangle)\otimes\tfrac1{\sqrt2}(\lvert0\rangle-\lvert1\rangle)=\lvert-\rangle\lvert-\rangle
    Reorder the terms by index; the coefficients 12(1,−1,−1,1)\tfrac12(1,-1,-1,1) factor as 12(1,−1)⊗12(1,−1)\tfrac1{\sqrt2}(1,-1)\otimes\tfrac1{\sqrt2}(1,-1).
  4. Step 4:
    CNOT∣+⟩∣−⟩=12(CNOT∣0⟩∣−⟩+CNOT∣1⟩∣−⟩)=12(∣0⟩−∣1⟩)∣−⟩=∣−⟩∣−⟩\mathrm{CNOT}\lvert+\rangle\lvert-\rangle=\tfrac1{\sqrt2}\big(\mathrm{CNOT}\lvert0\rangle\lvert-\rangle+\mathrm{CNOT}\lvert1\rangle\lvert-\rangle\big)=\tfrac1{\sqrt2}\big(\lvert0\rangle-\lvert1\rangle\big)\lvert-\rangle=\lvert-\rangle\lvert-\rangle
    The same result from the kickback proposition and linearity: the ∣1⟩\lvert1\rangle branch picks up (−1)1(-1)^1.
  5. Step 5:
    CNOT(∣+⟩⊗∣−⟩)=(Z∣+⟩)⊗∣−⟩,Z∣+⟩=12(∣0⟩−∣1⟩)=∣−⟩\mathrm{CNOT}\big(\lvert+\rangle\otimes\lvert-\rangle\big)=\big(Z\lvert+\rangle\big)\otimes\lvert-\rangle,\qquad Z\lvert+\rangle=\tfrac1{\sqrt2}\big(\lvert0\rangle-\lvert1\rangle\big)=\lvert-\rangle
    The target qubit is untouched, while the control has been flipped in the XX basis, exactly as if ZZ had acted on it. This is the reversed-CNOT theorem seen on one input.

Result

CNOT∣+⟩∣−⟩=∣−⟩∣−⟩=12(∣00⟩−∣01⟩−∣10⟩+∣11⟩)\boxed{\mathrm{CNOT}\lvert+\rangle\lvert-\rangle=\lvert-\rangle\lvert-\rangle=\tfrac12\big(\lvert00\rangle-\lvert01\rangle-\lvert10\rangle+\lvert11\rangle\big)}

Circuit · 2 qubits

Quantum circuit on 2 qubitsH on q0; X on q1; H on q1; X on q1 controlled by q0q0q1HXH

HH on qubit 0 and XX then HH on qubit 1 prepare ∣+⟩∣−⟩\lvert+\rangle\lvert-\rangle; the CNOT then outputs ∣−⟩∣−⟩\lvert-\rangle\lvert-\rangle, with amplitudes (12,−12,−12,12)(\tfrac12,-\tfrac12,-\tfrac12,\tfrac12) on ∣00⟩,∣01⟩,∣10⟩,∣11⟩\lvert00\rangle,\lvert01\rangle,\lvert10\rangle,\lvert11\rangle.

∣ψ⟩=12∣00⟩−12∣01⟩−12∣10⟩+12∣11⟩\lvert\psi\rangle = \tfrac{1}{2}\lvert 00\rangle - \tfrac{1}{2}\lvert 01\rangle - \tfrac{1}{2}\lvert 10\rangle + \tfrac{1}{2}\lvert 11\rangle

Quick check

After CNOT\mathrm{CNOT} acts on ∣+⟩∣−⟩\lvert+\rangle\lvert-\rangle, what is the amplitude of ∣10⟩\lvert10\rangle? Give a decimal.

tolerance ±0.001

Any controlled-U from two CNOTs#

The ZYZ decomposition from the rotation-gates lesson writes every single-qubit unitary as U=eiαRZ(β)RY(γ)RZ(δ)U=e^{i\alpha}R_Z(\beta)R_Y(\gamma)R_Z(\delta) with real α,β,γ,δ\alpha,\beta,\gamma,\delta, where RP(θ)=e−iθP/2=cos⁡θ2 I−isin⁡θ2 PR_P(\theta)=e^{-i\theta P/2}=\cos\tfrac\theta2\,I-i\sin\tfrac\theta2\,P. Two facts about rotations are used repeatedly below: rotations about the same axis add, RP(a)RP(b)=RP(a+b)R_P(a)R_P(b)=R_P(a+b), because e−iaP/2e^{-iaP/2} and e−ibP/2e^{-ibP/2} are exponentials of commuting matrices; and RP(0)=IR_P(0)=I. The construction that follows, due to Barenco et al., builds C-UC\text{-}U from two CNOTs, single-qubit gates on the target, and one phase gate on the control.

Lemma

XRY(θ)X=RY(−θ)XR_Y(\theta)X=R_Y(-\theta) and XRZ(θ)X=RZ(−θ)XR_Z(\theta)X=R_Z(-\theta)

For every real θ\theta, conjugation by XX reverses rotations about the yy and zz axes: XRY(θ)X=RY(−θ)XR_Y(\theta)X=R_Y(-\theta) and XRZ(θ)X=RZ(−θ)XR_Z(\theta)X=R_Z(-\theta).

Proof (6 steps)
  1. Step 1:
    XYX=X(YX)=X(−iZ)=−i XZ=−i(−iY)=−YXYX=X(YX)=X(-iZ)=-i\,XZ=-i(-iY)=-Y
    Pauli products YX=−iZYX=-iZ and XZ=−iYXZ=-iY, and (−i)(−i)=i2=−1(-i)(-i)=i^2=-1.
  2. Step 2:
    XZX=X(ZX)=X(iY)=i XY=i(iZ)=−ZXZX=X(ZX)=X(iY)=i\,XY=i(iZ)=-Z
    Pauli products ZX=iYZX=iY and XY=iZXY=iZ, and i⋅i=−1i\cdot i=-1.
  3. Step 3:
    XRY(θ)X=X(cos⁡θ2 I−isin⁡θ2 Y)X=cos⁡θ2 X2−isin⁡θ2 XYX=cos⁡θ2 I+isin⁡θ2 YXR_Y(\theta)X=X\big(\cos\tfrac\theta2\,I-i\sin\tfrac\theta2\,Y\big)X=\cos\tfrac\theta2\,X^2-i\sin\tfrac\theta2\,XYX=\cos\tfrac\theta2\,I+i\sin\tfrac\theta2\,Y
    Conjugation is linear; X2=IX^2=I and XYX=−YXYX=-Y from the first line.
  4. Step 4:
    =cos⁡(−θ2)I−isin⁡(−θ2)Y=RY(−θ)=\cos\big(-\tfrac\theta2\big)I-i\sin\big(-\tfrac\theta2\big)Y=R_Y(-\theta)
    Cosine is even and sine is odd: cos⁡(−t)=cos⁡t\cos(-t)=\cos t, sin⁡(−t)=−sin⁡t\sin(-t)=-\sin t.
  5. Step 5:
    XRZ(θ)X=cos⁡θ2 I−isin⁡θ2 XZX=cos⁡θ2 I+isin⁡θ2 Z=RZ(−θ)XR_Z(\theta)X=\cos\tfrac\theta2\,I-i\sin\tfrac\theta2\,XZX=\cos\tfrac\theta2\,I+i\sin\tfrac\theta2\,Z=R_Z(-\theta)
    The same two steps with XZX=−ZXZX=-Z.
  6. Step 6:
    XRZ(θ)X=(0110)(e−iθ/200eiθ/2)(0110)=(eiθ/200e−iθ/2)=RZ(−θ)XR_Z(\theta)X=\begin{pmatrix}0&1\\1&0\end{pmatrix}\begin{pmatrix}e^{-i\theta/2}&0\\0&e^{i\theta/2}\end{pmatrix}\begin{pmatrix}0&1\\1&0\end{pmatrix}=\begin{pmatrix}e^{i\theta/2}&0\\0&e^{-i\theta/2}\end{pmatrix}=R_Z(-\theta)
    Matrix check: conjugating a diagonal matrix by XX exchanges its two diagonal entries.

∎

Theorem

The ABCABC decomposition

Let U=eiαRZ(β)RY(γ)RZ(δ)U=e^{i\alpha}R_Z(\beta)R_Y(\gamma)R_Z(\delta). Define A=RZ(β)RY(γ2)A=R_Z(\beta)R_Y(\tfrac\gamma2), B=RY(−γ2)RZ(−δ+β2)B=R_Y(-\tfrac\gamma2)R_Z(-\tfrac{\delta+\beta}2) and C=RZ(δ−β2)C=R_Z(\tfrac{\delta-\beta}2). Then ABC=IABC=I and U=eiαAXBXCU=e^{i\alpha}AXBXC.

Proof (7 steps)
  1. Step 1:
    ABC=RZ(β)RY(γ2) RY(−γ2)RZ(−δ+β2) RZ(δ−β2)ABC=R_Z(\beta)R_Y(\tfrac\gamma2)\,R_Y(-\tfrac\gamma2)R_Z(-\tfrac{\delta+\beta}2)\,R_Z(\tfrac{\delta-\beta}2)
    Write out the three definitions in order.
  2. Step 2:
    =RZ(β) RY(0) RZ(−δ+β2+δ−β2)=RZ(β) RZ(−β)=R_Z(\beta)\,R_Y(0)\,R_Z\big(-\tfrac{\delta+\beta}2+\tfrac{\delta-\beta}2\big)=R_Z(\beta)\,R_Z(-\beta)
    Adjacent rotations about the same axis add: γ2−γ2=0\tfrac\gamma2-\tfrac\gamma2=0 gives RY(0)=IR_Y(0)=I, and −δ+β2+δ−β2=−δ−β+δ−β2=−β-\tfrac{\delta+\beta}2+\tfrac{\delta-\beta}2=\tfrac{-\delta-\beta+\delta-\beta}2=-\beta.
  3. Step 3:
    =RZ(β−β)=RZ(0)=I=R_Z(\beta-\beta)=R_Z(0)=I
    Add the two zz angles once more.
  4. Step 4:
    XBX=X RY(−γ2) X X RZ(−δ+β2) X=RY(γ2) RZ(δ+β2)XBX=X\,R_Y(-\tfrac\gamma2)\,X\,X\,R_Z(-\tfrac{\delta+\beta}2)\,X=R_Y(\tfrac\gamma2)\,R_Z(\tfrac{\delta+\beta}2)
    Insert X2=IX^2=I between the two factors of BB, then apply the lemma to each: XRY(−γ2)X=RY(γ2)XR_Y(-\tfrac\gamma2)X=R_Y(\tfrac\gamma2) and XRZ(−δ+β2)X=RZ(δ+β2)XR_Z(-\tfrac{\delta+\beta}2)X=R_Z(\tfrac{\delta+\beta}2).
  5. Step 5:
    AXBXC=RZ(β)RY(γ2)⋅RY(γ2)RZ(δ+β2)⋅RZ(δ−β2)AXBXC=R_Z(\beta)R_Y(\tfrac\gamma2)\cdot R_Y(\tfrac\gamma2)R_Z(\tfrac{\delta+\beta}2)\cdot R_Z(\tfrac{\delta-\beta}2)
    Substitute AA, the previous line for XBXXBX, and CC.
  6. Step 6:
    =RZ(β) RY(γ2+γ2) RZ(δ+β2+δ−β2)=RZ(β)RY(γ)RZ(δ)=R_Z(\beta)\,R_Y\big(\tfrac\gamma2+\tfrac\gamma2\big)\,R_Z\big(\tfrac{\delta+\beta}2+\tfrac{\delta-\beta}2\big)=R_Z(\beta)R_Y(\gamma)R_Z(\delta)
    Add adjacent same-axis angles: γ2+γ2=γ\tfrac\gamma2+\tfrac\gamma2=\gamma and δ+β+δ−β2=δ\tfrac{\delta+\beta+\delta-\beta}2=\delta.
  7. Step 7:
    eiαAXBXC=eiαRZ(β)RY(γ)RZ(δ)=Ue^{i\alpha}AXBXC=e^{i\alpha}R_Z(\beta)R_Y(\gamma)R_Z(\delta)=U
    Multiply by the scalar eiαe^{i\alpha} and compare with the ZYZ form of UU.

∎

Corollary

Controlled-UU from two CNOTs

With A,B,CA,B,C as in the theorem, the circuit that applies CC to the target, then CNOT01\mathrm{CNOT}_{01}, then BB to the target, then CNOT01\mathrm{CNOT}_{01}, then AA to the target, together with the phase gate P(α)=diag(1,eiα)P(\alpha)=\mathrm{diag}(1,e^{i\alpha}) on the control, implements C-UC\text{-}U exactly.

Proof (6 steps)
  1. Step 1:
    W=(P(α)⊗I)(I⊗A) CNOT (I⊗B) CNOT (I⊗C)W=(P(\alpha)\otimes I)(I\otimes A)\,\mathrm{CNOT}\,(I\otimes B)\,\mathrm{CNOT}\,(I\otimes C)
    The operator is the product of the gates in reverse wire order. P(α)P(\alpha) acts on the control only and is diagonal there, so it commutes with both CNOTs and may be placed anywhere on the control wire.
  2. Step 2:
    (I⊗A)(P0⊗I+P1⊗X)(I⊗B)=P0⊗AB+P1⊗AXB(I\otimes A)(P_0\otimes I+P_1\otimes X)(I\otimes B)=P_0\otimes AB+P_1\otimes AXB
    Insert CNOT=P0⊗I+P1⊗X\mathrm{CNOT}=P_0\otimes I+P_1\otimes X and use the mixed-product rule on each term: (I⊗A)(Pj⊗Xj)(I⊗B)=Pj⊗AXjB(I\otimes A)(P_j\otimes X^j)(I\otimes B)=P_j\otimes AX^jB.
  3. Step 3:
    (P0⊗AB+P1⊗AXB)(P0⊗I+P1⊗X)(I⊗C)=P0⊗ABC+P1⊗AXBXC(P_0\otimes AB+P_1\otimes AXB)(P_0\otimes I+P_1\otimes X)(I\otimes C)=P_0\otimes ABC+P_1\otimes AXBXC
    Expand the product: the cross terms contain P0P1=P1P0=0P_0P_1=P_1P_0=0 and vanish, while P0P0=P0P_0P_0=P_0 and P1P1=P1P_1P_1=P_1; the last factor appends CC to both branches.
  4. Step 4:
    =P0⊗I+P1⊗AXBXC=P_0\otimes I+P_1\otimes AXBXC
    The theorem gives ABC=IABC=I: when the control is ∣0⟩\lvert0\rangle the target sees CC, then BB, then AA, whose product is the identity.
  5. Step 5:
    W=(P(α)⊗I)(P0⊗I+P1⊗AXBXC)=P0⊗I+eiαP1⊗AXBXCW=(P(\alpha)\otimes I)(P_0\otimes I+P_1\otimes AXBXC)=P_0\otimes I+e^{i\alpha}P_1\otimes AXBXC
    P(α)P0=P0P(\alpha)P_0=P_0 and P(α)P1=eiαP1P(\alpha)P_1=e^{i\alpha}P_1, because P(α)P(\alpha) is diagonal with entries 11 and eiαe^{i\alpha}.
  6. Step 6:
    =P0⊗I+P1⊗U=C-U=P_0\otimes I+P_1\otimes U=C\text{-}U
    The theorem gives eiαAXBXC=Ue^{i\alpha}AXBXC=U. Without P(α)P(\alpha) the circuit would implement C-(e−iαU)C\text{-}(e^{-i\alpha}U), which differs from C-UC\text{-}U by a relative, observable phase between the two control branches.

∎

Derivation

Worked example: controlled-HH

  1. Step 1:
    H=eiπ/2RY(π2)RZ(π)=eiπ/2RZ(0)RY(π2)RZ(π) ⇒ α=π2, β=0, γ=π2, δ=πH=e^{i\pi/2}R_Y(\tfrac\pi2)R_Z(\pi)=e^{i\pi/2}R_Z(0)R_Y(\tfrac\pi2)R_Z(\pi)\ \Rightarrow\ \alpha=\tfrac\pi2,\ \beta=0,\ \gamma=\tfrac\pi2,\ \delta=\pi
    The Hadamard lesson computed RY(π2)RZ(π)=−iHR_Y(\tfrac\pi2)R_Z(\pi)=-iH, so H=iRY(π2)RZ(π)H=iR_Y(\tfrac\pi2)R_Z(\pi); inserting RZ(0)=IR_Z(0)=I puts it in ZYZ form.
  2. Step 2:
    A=RZ(0)RY(π4)=RY(π4),B=RY(−π4)RZ(−π2),C=RZ(π2)A=R_Z(0)R_Y(\tfrac\pi4)=R_Y(\tfrac\pi4),\qquad B=R_Y(-\tfrac\pi4)R_Z(-\tfrac\pi2),\qquad C=R_Z(\tfrac\pi2)
    Substitute into the definitions: γ2=π4\tfrac\gamma2=\tfrac\pi4, −δ+β2=−π2-\tfrac{\delta+\beta}2=-\tfrac\pi2, δ−β2=π2\tfrac{\delta-\beta}2=\tfrac\pi2.
  3. Step 3:
    ABC=RY(π4)RY(−π4) RZ(−π2)RZ(π2)=RY(0)RZ(0)=IABC=R_Y(\tfrac\pi4)R_Y(-\tfrac\pi4)\,R_Z(-\tfrac\pi2)R_Z(\tfrac\pi2)=R_Y(0)R_Z(0)=I
    Add the same-axis angles.
  4. Step 4:
    AXBXC=RY(π4) RY(π4)RZ(π2) RZ(π2)=RY(π2)RZ(π)=−i2(111−1)=−iHAXBXC=R_Y(\tfrac\pi4)\,R_Y(\tfrac\pi4)R_Z(\tfrac\pi2)\,R_Z(\tfrac\pi2)=R_Y(\tfrac\pi2)R_Z(\pi)=-\frac{i}{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}=-iH
    The lemma turns XBXXBX into RY(π4)RZ(π2)R_Y(\tfrac\pi4)R_Z(\tfrac\pi2); then add the angles and use the matrix product from the Hadamard lesson.
  5. Step 5:
    eiπ/2AXBXC=i⋅(−iH)=H,P(π2)=(100i)=Se^{i\pi/2}AXBXC=i\cdot(-iH)=H,\qquad P(\tfrac\pi2)=\begin{pmatrix}1&0\\0&i\end{pmatrix}=S
    The control phase gate for α=π2\alpha=\tfrac\pi2 is the SS gate; without it the circuit would give C-(−iH)C\text{-}(-iH).
  6. Step 6:
    C-H=(100001000012120012−12)C\text{-}H=\begin{pmatrix}1&0&0&0\\0&1&0&0\\0&0&\frac1{\sqrt2}&\frac1{\sqrt2}\\0&0&\frac1{\sqrt2}&-\frac1{\sqrt2}\end{pmatrix}
    The circuit RZ(π2)R_Z(\tfrac\pi2); CNOT\mathrm{CNOT}; RZ(−π2)R_Z(-\tfrac\pi2), RY(−π4)R_Y(-\tfrac\pi4); CNOT\mathrm{CNOT}; RY(π4)R_Y(\tfrac\pi4) on the target, with SS on the control, has block form (I00H)\begin{pmatrix}I&0\\0&H\end{pmatrix} by the corollary. On the wire BB is applied as RZ(−π2)R_Z(-\tfrac\pi2) first, because B=RY(−π4)RZ(−π2)B=R_Y(-\tfrac\pi4)R_Z(-\tfrac\pi2).

Result

C-H=(S⊗I)(I⊗A) CNOT (I⊗B) CNOT (I⊗C),A=RY(π4), B=RY(−π4)RZ(−π2), C=RZ(π2)\boxed{C\text{-}H=(S\otimes I)(I\otimes A)\,\mathrm{CNOT}\,(I\otimes B)\,\mathrm{CNOT}\,(I\otimes C),\quad A=R_Y(\tfrac\pi4),\ B=R_Y(-\tfrac\pi4)R_Z(-\tfrac\pi2),\ C=R_Z(\tfrac\pi2)}

Circuit · 2 qubits

Quantum circuit on 2 qubitsRZ(π/2) on q1; X on q1 controlled by q0; RZ(-π/2) on q1; RY(-π/4) on q1; X on q1 controlled by q0; RY(π/4) on q1; P(π/2) on q0q0q1RZ(π/2)RZ(-π/2)RY(-π/4)RY(π/4)P(π/2)

The ABCABC circuit for controlled-HH. The unitary panel shows (I00H)\begin{pmatrix}I&0\\0&H\end{pmatrix} exactly: the identity block confirms ABC=IABC=I, and the lower-right block confirms eiπ/2AXBXC=He^{i\pi/2}AXBXC=H.

U=(100001000012120012−12)U = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \tfrac{1}{\sqrt{2}} & \tfrac{1}{\sqrt{2}} \\ 0 & 0 & \tfrac{1}{\sqrt{2}} & -\tfrac{1}{\sqrt{2}} \end{pmatrix}

Quick check

How many CNOT gates does the ABCABC construction use to implement an arbitrary controlled single-qubit gate C-UC\text{-}U?

tolerance ±1e-9

Numerical verification and lab#

The script below rebuilds the identities of this lesson from the simulator's matrices and checks them entry by entry to 10−1210^{-12}: the projector form of CNOT, the CZ-to-CNOT conversion, the reversed CNOT, the three-CNOT SWAP, and the ABCABC construction for the sample angles β=0.3\beta=0.3, γ=1.1\gamma=1.1, δ=−0.7\delta=-0.7. It also evaluates the process fidelity ∣Tr(SWAP†V)∣/4=12\lvert\mathrm{Tr}(\mathrm{SWAP}^\dagger V)\rvert/4=\tfrac12 of the two-CNOT circuit V=CNOT10CNOT01V=\mathrm{CNOT}_{10}\mathrm{CNOT}_{01}, which the lab uses as a diagnostic.

TypeScriptrunnable
import { HADAMARD, I2, PAULI_X, SWAP_GATE, circuitUnitary, matrix, ryMatrix, rzMatrix } from '@/lib/quantum-simulator';

const tol = 1e-12;
const P0 = matrix.fromRows([[1, 0], [0, 0]]);
const P1 = matrix.fromRows([[0, 0], [0, 1]]);
// Engine unitaries of single two-qubit gates (qubit 0 = control = most significant bit)
const CNOT = circuitUnitary({ version: 1, numQubits: 2, numClbits: 0, ops: [{ kind: 'gate', gate: 'CNOT', targets: [0, 1] }] });
const CZ = circuitUnitary({ version: 1, numQubits: 2, numClbits: 0, ops: [{ kind: 'gate', gate: 'CZ', targets: [0, 1] }] });

// Block form C-U = |0><0| (x) I + |1><1| (x) U
console.log('CNOT = P0 x I + P1 x X :', matrix.approxEqual(matrix.add(matrix.kron(P0, I2), matrix.kron(P1, PAULI_X)), CNOT, tol));
console.log('CNOT is unitary        :', matrix.isUnitary(CNOT, tol));

// CNOT from CZ, and the reversed CNOT
const IH = matrix.kron(I2, HADAMARD);
const HH = matrix.kron(HADAMARD, HADAMARD);
const CNOT10 = matrix.add(matrix.kron(I2, P0), matrix.kron(PAULI_X, P1));
console.log('(I x H) CZ (I x H) = CNOT     :', matrix.approxEqual(matrix.mulAll(IH, CZ, IH), CNOT, tol));
console.log('(H x H) CNOT (H x H) = CNOT10 :', matrix.approxEqual(matrix.mulAll(HH, CNOT, HH), CNOT10, tol));

// SWAP from three CNOTs, and the two-CNOT near miss
console.log('CNOT CNOT10 CNOT = SWAP :', matrix.approxEqual(matrix.mulAll(CNOT, CNOT10, CNOT), SWAP_GATE, tol));
const V = matrix.mul(CNOT10, CNOT);
const tr = matrix.trace(matrix.mul(matrix.adjoint(SWAP_GATE), V));
console.log('two CNOTs: |Tr(SWAP^dag V)| / 4 =', (Math.hypot(tr.re, tr.im) / 4).toFixed(4));

// ABC construction for beta = 0.3, gamma = 1.1, delta = -0.7
const beta = 0.3, gamma = 1.1, delta = -0.7;
const A = matrix.mul(rzMatrix(beta), ryMatrix(gamma / 2));
const B = matrix.mul(ryMatrix(-gamma / 2), rzMatrix(-(delta + beta) / 2));
const C = rzMatrix((delta - beta) / 2);
const zyz = matrix.mulAll(rzMatrix(beta), ryMatrix(gamma), rzMatrix(delta));
console.log('ABC = I                   :', matrix.approxEqual(matrix.mulAll(A, B, C), I2, tol));
console.log('AXBXC = RZ(b) RY(g) RZ(d) :', matrix.approxEqual(matrix.mulAll(A, PAULI_X, B, PAULI_X, C), zyz, tol));

Expected output

CNOT = P0 x I + P1 x X : true
CNOT is unitary        : true
(I x H) CZ (I x H) = CNOT     : true
(H x H) CNOT (H x H) = CNOT10 : true
CNOT CNOT10 CNOT = SWAP : true
two CNOTs: |Tr(SWAP^dag V)| / 4 = 0.5000
ABC = I                   : true
AXBXC = RZ(b) RY(g) RZ(d) : true

References

  1. M. A. Nielsen and I. L. Chuang, Quantum Computation and Quantum Information, 10th anniversary ed., Cambridge University Press (2010), §4.3 (controlled operations, Corollary 4.2 and the CNOT identities of Exercises 4.17 and 4.20).doi:10.1017/CBO9780511976667
  2. A. Barenco, C. H. Bennett, R. Cleve, D. P. DiVincenzo, N. Margolus, P. Shor, T. Sleator, J. A. Smolin and H. Weinfurter, Elementary gates for quantum computation, Physical Review A 52, 3457–3467 (1995).doi:10.1103/PhysRevA.52.3457

Hands-on labs

  • SWAP from three CNOTs

    1 step · auto-graded

    Build the two-qubit SWAP gate, which exchanges the states of the two wires, using only CNOT gates and at most three of them.

    Open lab