Search

Search papers and lessons

Quantum Gate

Level 3 · 11 min read

A quantum gate is a unitary matrix that changes a qubit's amplitudes in a reversible, length-preserving way, so a circuit of gates computes without losing total probability.

On this page

  • Colour = topic mix
  • Linear algebra
  • Discrete math
  • Calculus
  • Quantum physics
  • ReadReady to readNot yet

TL;DR

A quantum gate is an operation on one or more qubits that changes their state. For a single qubit it is a 2-by-2 unitary matrix that multiplies the column of amplitudes. Because the matrix is unitary, the gate keeps the total probability at 1 and can always be undone. A quantum circuit is a sequence of gates, and running a computation means choosing which gates to apply, in which order.

Builds on: Qubit, Unitary Operator · Leads to: Quantum Measurement, Tensor Product

Where it's used

Quantum processors. Superconducting and trapped-ion quantum computers are controlled by pulses that implement gates such as the Hadamard, the X gate and rotations by chosen angles. A program is compiled into a list of these gates, and each gate is applied to named qubits.

Quantum algorithms. Search and factoring algorithms are circuits of gates followed by a measurement. The Hadamard gate creates equal superpositions over many inputs, and the other gates steer amplitudes so that wrong answers cancel and right answers gain weight.

Quantum communication and error correction. Protocols that send qubits over fibre, and codes that protect them from noise, are built from gates that encode and decode information. Each encoding step is a unitary, so the information is moved around, not lost.

How it works

Start with the qubit in the state (0.6,0.8)(0.6, 0.8), meaning amplitude 0.6 on ∣0⟩|0\rangle and 0.8 on ∣1⟩|1\rangle. Apply two gates to it: the X gate, which swaps the two amplitudes, and the Z gate, which flips the sign of the ∣1⟩|1\rangle amplitude.

  1. Start. The state is (0.6,0.8)(0.6, 0.8). Its probabilities are 0.360.36 for 0 and 0.640.64 for 1. Check: 0.36+0.64=10.36 + 0.64 = 1.

  2. Apply X. The X gate is the matrix X=(0110)X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}. The new top entry is 0⋅0.6+1⋅0.8=0.80 \cdot 0.6 + 1 \cdot 0.8 = 0.8, and the new bottom entry is 1⋅0.6+0⋅0.8=0.61 \cdot 0.6 + 0 \cdot 0.8 = 0.6. The state is (0.8,0.6)(0.8, 0.6). Check: 0.64+0.36=10.64 + 0.36 = 1, so no probability was lost.

  3. Read the probabilities after X. Now 0 has probability 0.640.64 and 1 has 0.360.36. The gate exchanged the two outcomes. Check: the probabilities are the old ones in reverse order.

  4. Apply X again. Applying XX to (0.8,0.6)(0.8, 0.6) gives (0.6,0.8)(0.6, 0.8), the original state. Check: XX applied twice is the identity, so X undoes itself.

  5. Apply Z to the original state. The Z gate, one of the Pauli matrices, is Z=(100−1)Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}. It keeps the top entry and negates the bottom one, giving (0.6,−0.8)(0.6, -0.8). Check: the squared sizes are still 0.360.36 and 0.640.64.

  6. Name what happened. X moved amplitude between the two basis states, and changed the probabilities. Z changed only a sign, so the probabilities in this basis did not move. Both are gates because both are unitary: they preserve 0.36+0.64=10.36 + 0.64 = 1 at every step.

flowchart LR
  S[State: amplitudes a, b] --> G[Gate: 2 by 2 unitary matrix]
  G --> T[New state: amplitudes a', b']
  T --> M[Measure: probabilities are squared sizes]

The next plot shows a gate that is not a swap or a sign flip, but a rotation by a chosen angle θ\theta. Its matrix is Ry(θ)=(cos⁡(θ/2)−sin⁡(θ/2)sin⁡(θ/2)cos⁡(θ/2))R_y(\theta) = \begin{pmatrix} \cos(\theta/2) & -\sin(\theta/2) \\ \sin(\theta/2) & \cos(\theta/2) \end{pmatrix} (derived in the math section). Applied to ∣0⟩|0\rangle, it gives probability sin⁡2(θ/2)\sin^2(\theta/2) of reading 1.

00.511.522.5300.20.40.60.81θ (rotation angle, radians)probability
  • P(measure 1) after the rotation
  • P(measure 0)
The rotation by θ = π/3 (60 degrees) gives probability one quarter of reading 1. At θ = π the state has flipped completely.

The math

Definition: Single-qubit gate

A single-qubit gate is a 2×22 \times 2 complex matrix UU with U†U=IU^\dagger U = I, where U†U^\dagger is the conjugate transpose (see Unitary Operator). It acts on a qubit state ∣ψ⟩=α∣0⟩+β∣1⟩|\psi\rangle = \alpha|0\rangle + \beta|1\rangle by U∣ψ⟩U|\psi\rangle, computed as the matrix times the column (α,β)(\alpha, \beta).

Step 2 in symbols: the action on amplitudes

Write U=(u00u01u10u11)U = \begin{pmatrix} u_{00} & u_{01} \\ u_{10} & u_{11} \end{pmatrix}. Then

U(αβ)=(u00α+u01βu10α+u11β).U \begin{pmatrix} \alpha \\ \beta \end{pmatrix} = \begin{pmatrix} u_{00}\alpha + u_{01}\beta \\ u_{10}\alpha + u_{11}\beta \end{pmatrix}.

Each new amplitude is a weighted sum of the old ones, and the weights are the entries of the row. For XX, u00=u11=0u_{00} = u_{11} = 0 and u01=u10=1u_{01} = u_{10} = 1, so the two amplitudes swap. Step 2 of the walkthrough is this formula with α=0.6\alpha = 0.6 and β=0.8\beta = 0.8.

Step 4 in symbols: why X is its own inverse

Compute X2=(0110)(0110)=(1001)=IX^2 = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} = I. Since U†U=IU^\dagger U = I and XX is real and symmetric, X†=XX^\dagger = X, so X−1=XX^{-1} = X.

Step 5 in symbols: probabilities are unchanged by a phase

Z multiplies the ∣1⟩|1\rangle amplitude by −1-1. A probability is the squared size, and ∣−β∣2=∣β∣2|-\beta|^2 = |\beta|^2, so the outcome probabilities do not change in this basis. A sign is a phase, and phases matter only when a later gate or a measurement in another basis can see them.

Composing gates

If gate UU acts first and then gate VV, the total effect is the single matrix VUVU, with the later gate on the left. The order matters, because matrix multiplication does not commute in general.

The rotation

The gate Ry(θ)=(cos⁡(θ/2)−sin⁡(θ/2)sin⁡(θ/2)cos⁡(θ/2))R_y(\theta) = \begin{pmatrix} \cos(\theta/2) & -\sin(\theta/2) \\ \sin(\theta/2) & \cos(\theta/2) \end{pmatrix}, built from cosine and sine, is real and orthogonal, so it is unitary. Applied to ∣0⟩=(1,0)|0\rangle = (1, 0), it gives (cos⁡(θ/2),sin⁡(θ/2))(\cos(\theta/2), \sin(\theta/2)). The probability of 1 is therefore sin⁡2(θ/2)\sin^2(\theta/2), which is the curve in the plot.

Worked examples

Example
1. Two X gates make no change

Take the state (α,β)=(1,0)(\alpha, \beta) = (1, 0), which is the basis state ∣0⟩|0\rangle.

  1. Apply X: (0⋅1+1⋅0,1⋅1+0⋅0)=(0,1)(0 \cdot 1 + 1 \cdot 0, 1 \cdot 1 + 0 \cdot 0) = (0, 1). The state is now ∣1⟩|1\rangle.
  2. Apply X again: (0⋅0+1⋅1,1⋅0+0⋅1)=(1,0)(0 \cdot 0 + 1 \cdot 1, 1 \cdot 0 + 0 \cdot 1) = (1, 0). The state is back to ∣0⟩|0\rangle.
  3. Check: X2=IX^2 = I, so two X gates equal no gate.

Answer: X turns ∣0⟩|0\rangle into ∣1⟩|1\rangle, and a second X turns it back. This is the quantum version of the NOT operation on a classical bit, and the reversibility is exact.

Example
2. Hadamard, then Z, then Hadamard

Let H=12(111−1)H = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}, and start from ∣0⟩=(1,0)|0\rangle = (1, 0).

  1. Apply H: H∣0⟩=12(1,1)H|0\rangle = \frac{1}{\sqrt{2}}(1, 1). This is the equal superposition ∣+⟩|+\rangle.
  2. Apply Z, which negates the bottom entry: 12(1,−1)\frac{1}{\sqrt{2}}(1, -1). This is ∣−⟩|-\rangle. Check: Z changed no probability, both still 12\frac{1}{2}.
  3. Apply H again. The top entry is 12(1⋅1+1⋅(−1))=0\frac{1}{2}(1 \cdot 1 + 1 \cdot (-1)) = 0.
  4. The bottom entry is 12(1⋅1+(−1)(−1))=12⋅2=1\frac{1}{2}(1 \cdot 1 + (-1)(-1)) = \frac{1}{2} \cdot 2 = 1.
  5. The result is (0,1)(0, 1), which is ∣1⟩|1\rangle.

Answer: the composite HZHHZH turns ∣0⟩|0\rangle into ∣1⟩|1\rangle. A gate that only changes a sign, Z, became a bit flip once it was sandwiched between two Hadamards. This is the key trick of changing basis in quantum computing.

Example
3. A rotation by 60 degrees, realistic case

This example uses the rotation Ry(θ)R_y(\theta) with θ=π/3\theta = \pi/3, which is 60 degrees on the Bloch sphere. The example is a model of a calibrated pulse, not a measured device.

  1. Half the angle: θ/2=π/6\theta/2 = \pi/6, which is 30 degrees.
  2. cos⁡(π/6)=32≈0.866\cos(\pi/6) = \frac{\sqrt{3}}{2} \approx 0.866 and sin⁡(π/6)=12=0.5\sin(\pi/6) = \frac{1}{2} = 0.5.
  3. Apply to ∣0⟩|0\rangle: the new state is (0.866,0.5)(0.866, 0.5).
  4. Check the length: 0.8662+0.52=0.75+0.25=10.866^2 + 0.5^2 = 0.75 + 0.25 = 1.
  5. Probability of reading 1: 0.52=0.250.5^2 = 0.25. Probability of reading 0: 0.750.75.
  6. Interpretation: a rotation by 60 degrees on the sphere leaves 25 percent of the probability on 1. A rotation by 180 degrees, θ=π\theta = \pi, would put all of it there.
  7. Try it: what is the probability of reading 1 after a rotation by 120 degrees, θ=2π/3\theta = 2\pi/3?

Answer: θ/2=π/3\theta/2 = \pi/3, so sin⁡2(π/3)=(3/2)2=0.75\sin^2(\pi/3) = (\sqrt{3}/2)^2 = 0.75. The probability of reading 1 is 75 percent.

Common mistakes and tradeoffs

It is tempting to think that a gate can look at its input and copy it. In fact every gate is unitary, and no unitary can copy an unknown qubit, as the No-Cloning Theorem says. A gate can only transform the state it is given.

It is tempting to think that the order of gates does not matter. In fact the total effect is the product of matrices, and the product depends on the order. The matrices XZXZ and ZXZX differ by a sign: XZ=(0−110)XZ = \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix} and ZX=(01−10)ZX = \begin{pmatrix} 0 & 1 \\ -1 & 0 \end{pmatrix}. Since XZ=−ZXXZ = -ZX, and a minus sign on the whole state is a global phase, the two orders act the same on one qubit. With more qubits or other gates the order can matter, so check it.

It is tempting to think that gates are reversible because they are fancy. In fact the reason is simpler: unitarity gives an inverse, U−1=U†U^{-1} = U^\dagger, so every gate can be run backwards. Measurement is different, because it is not unitary and destroys information.

It is tempting to think that a gate that changes only phases has no effect. In fact the effect appears when another gate or a measurement in a different basis looks at the phase, as the HZH example showed.

SituationProblemBetter choice
Many gates in a row on noisy hardwareEach gate adds error, and the error accumulatesFewer gates, or error correction
Needing to reverse a computationMeasurement destroys informationKeep the circuit unitary until the end
Only a classical bit is neededA quantum gate adds cost for no gainA classical gate

When to use it. Use a quantum gate when the computation must be reversible on a qubit, and when you want to steer amplitudes so that interference helps.

When not to. Do not use gates to model a noisy open system; there you need channels, not unitaries.

History

The idea of a reversible computing step predates quantum computers. In the 1970s, Charles Bennett showed that reversible classical logic can compute anything, which made the reversible gate a natural building block.

David Deutsch described quantum circuits built from gates in the late 1980s. Later work showed that a small set of one-qubit gates together with one two-qubit gate can approximate any unitary on any number of qubits.

The gate model caught on because it gave a standard language for quantum algorithms and for hardware. Most current quantum computers are programmed in it.

Recap

  • A single-qubit gate is a 2-by-2 unitary matrix that multiplies the amplitude column.
  • Unitarity keeps total probability at 1 and makes every gate reversible, with inverse U†U^\dagger.
  • X swaps amplitudes, Z flips a sign, and H creates equal superpositions from ∣0⟩|0\rangle.
  • A circuit is a product of gate matrices, applied in order, with the later gate on the left.
  • Read Quantum Measurement to see how the final state becomes a classical outcome, and Tensor Product to see how gates act on several qubits.

Check yourself

QuestionRecall: what property of a unitary matrix guarantees that a gate keeps total probability at 1?Show answer

Unitarity means U†U=IU^\dagger U = I, so ∥Uψ∥2=ψ†U†Uψ=ψ†ψ=∥ψ∥2\|U\psi\|^2 = \psi^\dagger U^\dagger U \psi = \psi^\dagger \psi = \|\psi\|^2. The length of the state is preserved, so the squared amplitudes still sum to 1.

QuestionComputation: the state is (0.6,0.8)(0.6, 0.8). What is the probability of reading 0 after the gate ZZ is applied?Show answer

Z gives (0.6,−0.8)(0.6, -0.8). The probability of 0 is 0.62=0.360.6^2 = 0.36. The sign of −0.8-0.8 does not change its squared size, so the answer is 0.360.36, the same as before the gate.

QuestionWhy: why does the sandwich HZHHZH act as a bit flip, even though Z alone does not change any probability in the computational basis?Show answer

H turns the computational basis into the ∣+⟩|+\rangle, ∣−⟩|-\rangle basis. In that basis Z swaps ∣+⟩|+\rangle and ∣−⟩|-\rangle, which is a flip between two states. Changing basis with H and then back again turns that swap into a flip of ∣0⟩|0\rangle and ∣1⟩|1\rangle.

QuestionApplied: a circuit applies a rotation Ry(θ)R_y(\theta) to ∣0⟩|0\rangle with θ=π/2\theta = \pi/2, and then measures. What is the probability of reading 1?Show answer

Half the angle is π/4\pi/4, and sin⁡2(π/4)=(2/2)2=1/2\sin^2(\pi/4) = (\sqrt{2}/2)^2 = 1/2. The probability of reading 1 is one half, the same as an unbiased coin.

Sources

Quantum Gate — explained simply · ungoon.me