|q⟩ Bad Qubits

beginner · Programming · Controlled Gates: CNOT, CZ, SWAP

The Controlled-Z Gate

The controlled-Z gate (CZ) multiplies the amplitude of ∣11⟩|11\rangle by −1-1 and leaves all other basis states unchanged:

CZ ∣00⟩=∣00⟩,CZ ∣01⟩=∣01⟩,CZ ∣10⟩=∣10⟩,CZ ∣11⟩=−∣11⟩.\text{CZ}\,|00\rangle = |00\rangle, \quad \text{CZ}\,|01\rangle = |01\rangle, \quad \text{CZ}\,|10\rangle = |10\rangle, \quad \text{CZ}\,|11\rangle = -|11\rangle.

In matrix form, with the two-qubit computational basis ordered ∣00⟩,∣01⟩,∣10⟩,∣11⟩|00\rangle, |01\rangle, |10\rangle, |11\rangle:

CZ=(100001000010000−1).\text{CZ} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{pmatrix}.

Symmetry: no control, no target

Look at the matrix — it is diagonal. Because a diagonal matrix is symmetric, swapping the role of the two qubits gives exactly the same gate. There is no physical difference between calling qubit 0 the "control" and qubit 1 the "target": CZ(q0q_0, q1q_1) = CZ(q1q_1, q0q_0). This symmetry sets CZ apart from CNOT, which has a definite control and a definite target.

Formally, CZ is the tensor product of ZZ conditioned on the other qubit being ∣1⟩|1\rangle:

CZ=∣0⟩⟨0∣⊗I  +  ∣1⟩⟨1∣⊗Z,\text{CZ} = |0\rangle\langle 0| \otimes I \;+\; |1\rangle\langle 1| \otimes Z,

but because ZZ also leaves ∣0⟩|0\rangle unchanged and flips the sign of ∣1⟩|1\rangle, you could equally write I⊗∣0⟩⟨0∣+Z⊗∣1⟩⟨1∣I \otimes |0\rangle\langle 0| + Z \otimes |1\rangle\langle 1| — the same matrix.

Phase kicks and relative phases

When CZ acts on a product state ∣+⟩∣1⟩|{+}\rangle|1\rangle, the phase it introduces is relative, not global, and therefore physically observable:

∣+⟩∣1⟩=12(∣01⟩+∣11⟩)  →  CZ  12(∣01⟩−∣11⟩).|{+}\rangle|1\rangle = \frac{1}{\sqrt{2}}\bigl(|01\rangle + |11\rangle\bigr) \;\xrightarrow{\;\text{CZ}\;} \frac{1}{\sqrt{2}}\bigl(|01\rangle - |11\rangle\bigr).

The ∣01⟩|01\rangle amplitude is untouched (one qubit is ∣0⟩|0\rangle so CZ does nothing), while the ∣11⟩|11\rangle amplitude picks up the −1-1 phase. The resulting state is a superposition with a minus sign — a different quantum state from the input that a later Hadamard or interference experiment could distinguish.

Try it

Prepare qubit 0 in ∣+⟩|{+}\rangle and qubit 1 in ∣1⟩|1\rangle, then apply CZ. Observe how the sign of the ∣11⟩|11\rangle component flips while the ∣01⟩|01\rangle component is unchanged.

Run your code to see the quantum state.

After running, check the amplitude of ∣11⟩|11\rangle in the statevector panel: it should be −12≈−0.707-\tfrac{1}{\sqrt{2}} \approx -0.707, confirming the phase kick.

Sign in on the full site to ask questions and join the discussion.