Skip to Content
Quantum Gates

Quantum Gates

Quantum gates are reversible transformations applied to qubits. Mathematically they are represented by unitary matrices, which preserve the norm and therefore the total probability of a quantum state. Gates may act on a single qubit or on multiple qubits simultaneously. The Quantum Simulator  implements most operations below directly; the notes identify equivalent parameterized gates when there is no separate button.

These are the fundamental building blocks of quantum circuits, allowing us to manipulate qubits and create complex quantum states. Each gate corresponds to a unitary operation that transforms the state of one or more qubits. The following sections describe common single‑qubit and multi‑qubit gates, their matrix representations, and their effects on qubit states.

Single-Qubit Gates

GateMatrixDescription
X[0110]\begin{bmatrix}0&1\\1&0\end{bmatrix}Bit flip analogous to the classical NOT. Rotates the Bloch vector by π\pi about the X‑axis.
Y[0ii0]\begin{bmatrix}0&-i\\i&0\end{bmatrix}Combined bit and phase flip. Rotates by π\pi about the Y‑axis.
Z[1001]\begin{bmatrix}1&0\\0&-1\end{bmatrix}Phase flip. Rotates by π\pi about the Z‑axis, negating the amplitude of 1\lvert 1\rangle.
H12[1111]\tfrac{1}{\sqrt{2}}\begin{bmatrix}1&1\\1&-1\end{bmatrix}Creates superposition. A π\pi rotation about the diagonal axis (X+Z)/2(X+Z)/\sqrt{2}, which exchanges the X‑ and Z‑axes of the sphere.
S[100i]\begin{bmatrix}1&0\\0&i\end{bmatrix}Adds relative phase π/2\pi/2; equivalent up to global phase to a π/2\pi/2 rotation about Z. Satisfies S2=ZS^2 = Z.
T[100eiπ/4]\begin{bmatrix}1&0\\0&e^{i\pi/4}\end{bmatrix}Adds relative phase π/4\pi/4; equivalent up to global phase to a π/4\pi/4 rotation about Z. Satisfies T2=ST^2 = S.

Each of these gates is a rotation of the Bloch sphere by a fixed angle about a fixed axis. Useful identities to keep in mind are X2=Y2=Z2=H2=IX^2=Y^2=Z^2=H^2=I, HXH=ZHXH = Z, HZH=XHZH = X and XY=iZXY = iZ.

QSim has no separate S or T button. Use RZ with angle π/2\pi/2 for S or π/4\pi/4 for T; each implementation differs from the named phase gate only by an unobservable global phase.

Rotation gates provide arbitrary rotations around the Bloch sphere axes:

Rx(θ)=eiθX/2,Ry(θ)=eiθY/2,Rz(θ)=eiθZ/2.R_x(\theta) = e^{-i\theta X/2}, \quad R_y(\theta) = e^{-i\theta Y/2}, \quad R_z(\theta) = e^{-i\theta Z/2}.

These gates rotate the Bloch vector by an angle θ\theta around the specified axis. For example, Rx(π)R_x(\pi) flips the qubit state (it equals iX-iX, which differs from X only by an unobservable global phase), while Ry(π/2)R_y(\pi/2) maps |0⟩ to the equal superposition (0+1)/2(|0\rangle+|1\rangle)/\sqrt{2}.

Expanding eiθP/2=cosθ2Iisinθ2Pe^{-i\theta P/2} = \cos\frac{\theta}{2}I - i\sin\frac{\theta}{2}P for a Pauli matrix PP gives the explicit matrices:

Rx(θ)=[cosθ2isinθ2isinθ2cosθ2],Ry(θ)=[cosθ2sinθ2sinθ2cosθ2],Rz(θ)=[eiθ/200eiθ/2].R_x(\theta) = \begin{bmatrix}\cos\frac{\theta}{2} & -i\sin\frac{\theta}{2}\\-i\sin\frac{\theta}{2} & \cos\frac{\theta}{2}\end{bmatrix}, \quad R_y(\theta) = \begin{bmatrix}\cos\frac{\theta}{2} & -\sin\frac{\theta}{2}\\\sin\frac{\theta}{2} & \cos\frac{\theta}{2}\end{bmatrix}, \quad R_z(\theta) = \begin{bmatrix}e^{-i\theta/2} & 0\\0 & e^{i\theta/2}\end{bmatrix}.

RzR_z is diagonal because it only adds a relative phase between |0⟩ and |1⟩; it does not change computational-basis probabilities when applied immediately before measurement. It is closely related to the phase gate P(θ)=[100eiθ]P(\theta)=\begin{bmatrix}1&0\\0&e^{i\theta}\end{bmatrix}, since P(θ)=eiθ/2Rz(θ)P(\theta) = e^{i\theta/2}R_z(\theta). The two differ only by a global phase. With this convention S=P(π/2)S = P(\pi/2) and T=P(π/4)T = P(\pi/4).

The Hadamard gate is particularly important because it turns a basis state into a superposition, which is how a register is spread over all inputs at the start of an algorithm. It rotates the state vector from the north pole (representing |0⟩) to the equator, and applying it a second time brings the qubit back to |0⟩: the two routes to |1⟩ arrive with opposite signs and cancel. That cancellation is interference in its simplest form, and it is why H2=IH^2 = I.

The single‑qubit gates listed above can be combined to create more complex operations. For example, the Hadamard gate H can be built from rotations about the Y and Z axes:

H=eiπ/2Ry(π/2)Rz(π)=eiπ/2Rz(π/2)Rx(π/2)Rz(π/2).H = e^{i\pi/2}\,R_y(\pi/2)\,R_z(\pi) = e^{i\pi/2}\,R_z(\pi/2)\,R_x(\pi/2)\,R_z(\pi/2).

The leading factor eiπ/2=ie^{i\pi/2}=i is a global phase, so on hardware H and Ry(π/2)Rz(π)R_y(\pi/2)R_z(\pi) are indistinguishable. Note that the rightmost factor is applied first, matching the order in which the gates appear on a circuit diagram read left to right.

Any single‑qubit unitary can be decomposed into a sequence of these rotations. A convenient form uses Euler angles

U=eiαRz(β)Ry(γ)Rz(δ),U = e^{i\alpha}R_z(\beta)R_y(\gamma)R_z(\delta),

where the global phase eiαe^{i\alpha} has no observable effect. This decomposition underlies many quantum compilation techniques.

Single‑qubit gates act on one qubit line at a time, so no sequence of them can create entanglement from a product state. Creating entanglement requires a suitable interaction between qubits, such as a CNOT applied to a control in superposition. The Quantum Simulator lets you place single-qubit gates on any line, run the circuit and inspect the resulting Bloch vector.

Multi-Qubit Gates

  • CNOT: Flips the target qubit when the control qubit is |1⟩ in the computational basis.
  • CZ: Multiplies the |11⟩ basis component by 1-1.
  • Swap: Exchanges the states of two qubits.
  • Toffoli (CCNOT): A two‑control CNOT; Toffoli gates together with suitable ancillas can implement arbitrary classical reversible computation.
  • Controlled‑Phase: Multiplies the |11⟩ component by a specified phase in the two-qubit case; multiply controlled versions phase the all-ones component.

QSim exposes controlled phase as CP. Setting its angle to π\pi implements CZ exactly, so a separate CZ button is unnecessary.

Multi‑qubit gates operate jointly on two or more qubits. Some, including CNOT and CZ, can generate entanglement from suitable product inputs; others, such as SWAP, cannot. A gate on nn qubits is a 2n×2n2^n\times2^n unitary acting on the joint state. An entangling gate maps at least one product input to an entangled output. Every entangling gate is non-product, but not every non-product gate is entangling.

Ordering the two‑qubit basis as 00,01,10,11|00\rangle,|01\rangle,|10\rangle,|11\rangle with qubit 0 as the leftmost (most significant) bit, the common two‑qubit gates are:

CNOT=[1000010000010010],CZ=[1000010000100001],SWAP=[1000001001000001].\mathrm{CNOT} = \begin{bmatrix}1 & 0 & 0 & 0\\0 & 1 & 0 & 0\\0 & 0 & 0 & 1\\0 & 0 & 1 & 0\end{bmatrix},\quad \mathrm{CZ} = \begin{bmatrix}1 & 0 & 0 & 0\\0 & 1 & 0 & 0\\0 & 0 & 1 & 0\\0 & 0 & 0 & -1\end{bmatrix},\quad \mathrm{SWAP} = \begin{bmatrix}1 & 0 & 0 & 0\\0 & 0 & 1 & 0\\0 & 1 & 0 & 0\\0 & 0 & 0 & 1\end{bmatrix}.

The matrix written for CNOT above takes qubit 0 as the control and qubit 1 as the target. Swapping those roles gives a different matrix,

CNOT10=[1000000100100100],\mathrm{CNOT}_{1\rightarrow 0} = \begin{bmatrix}1 & 0 & 0 & 0\\0 & 0 & 0 & 1\\0 & 0 & 1 & 0\\0 & 1 & 0 & 0\end{bmatrix},

so the wiring matters. CZ and the standard two-qubit controlled‑phase gates are symmetric, so it makes no difference which qubit is labelled the control. CZ and CNOT are related by CZ=(IH)CNOT(IH)\mathrm{CZ} = (I\otimes H)\,\mathrm{CNOT}\,(I\otimes H) for the CNOT convention above. Three alternating CNOTs make a swap: SWAP=CNOT01CNOT10CNOT01\mathrm{SWAP} = \mathrm{CNOT}_{0\rightarrow1}\,\mathrm{CNOT}_{1\rightarrow0}\,\mathrm{CNOT}_{0\rightarrow1}.

Single‑qubit rotations together with the CNOT gate form a universal gate set. That means any unitary acting on a collection of qubits can be approximated to arbitrary precision using only these primitives. The Quantum Simulator allows you to place multi‑qubit gates across different lines to observe how entanglement forms.

Example: Bell State

A simple circuit that demonstrates entanglement uses a Hadamard gate followed by a CNOT:

  1. Apply H to qubit 0, creating (0+1)/2(|0\rangle + |1\rangle)/\sqrt{2} on that line, so the two‑qubit state is (00+10)/2(|00\rangle + |10\rangle)/\sqrt{2}.
  2. Use qubit 0 as the control of a CNOT acting on qubit 1, which flips qubit 1 only in the 10|10\rangle branch.

The resulting two‑qubit state is

Φ+=12(00+11).|\Phi^+\rangle = \tfrac{1}{\sqrt{2}}(|00\rangle + |11\rangle).

This state cannot be written as a product of two single‑qubit states. Tracing out either qubit leaves the other in the maximally mixed state ρ=I/2\rho = I/2, rather than a pure superposition. Each qubit on its own yields an unbiased bit when measured in any direction. Its reduced-state Bloch vector is at the origin, while the joint state retains the correlations of Φ+|\Phi^+\rangle.

When qubit 0 is measured it yields |0⟩ or |1⟩ with probability 1/21/2 each, and the two‑qubit state collapses so that qubit 1 must give the matching result: measuring |0⟩ leaves qubit 1 in |0⟩, and measuring |1⟩ leaves it in |1⟩. The outcomes are perfectly correlated, yet each on its own is completely random.

Perfect correlation in the computational basis alone is not proof of entanglement; a shared random bit reproduces it. For Φ+|\Phi^+\rangle, the expectation values are ZZ=XX=+1\langle Z\otimes Z\rangle = \langle X\otimes X\rangle = +1 and YY=1\langle Y\otimes Y\rangle = -1. Suitable tilted measurement axes give the CHSH value 222\sqrt{2}, exceeding the bound of 22 obeyed by local hidden-variable models. Bell-state entanglement is also the resource used by quantum teleportation and superdense coding.

Try running the preparation first with only the Hadamard, then add the CNOT and run it again. After the CNOT, both reduced-state Bloch vectors vanish. For the known pure two-qubit state prepared here, those mixed marginals certify entanglement; a zero local Bloch vector by itself would not certify an arbitrary joint state as entangled.

Simulator Lab: Learn Gates by Controlled Comparison

The fastest way to understand a gate in the Quantum Simulator  is to compare inputs that isolate its different effects.

QSim gate-entry reference

The target list is ordered, and QSim uses the first selected target as local bit 0 of a multi-qubit matrix. The interface enforces the following arities:

Builder buttonJSON gateNameTargetsExtra input
HHadamard1none
XPauliX1none
YPauliY1none
ZPauliZ1none
RX, RY, RZsame as button1angle θ\theta in radians
CNOTCNOT2first target is control
SwapSwap2target order has no physical effect
ToffoliToffoli3first two targets are controls, third is target
CPControlledPhaseShift2angle θ\theta in radians
OracleOracleone or moremarked local basis-state integer
DiffusionDiffusionone or morenone

This table is especially useful when reviewing exported JSON, but use the builder to create the initial file. The interface checks target count, distinct indices and range before adding an operation, while hand-edited files make those mistakes easier to introduce.

Single-qubit rotations

Use one qubit and start in |0⟩:

  1. Add RY on q0 with angle π/21.5708\pi/2 \approx 1.5708 and run. The probabilities should be P(0)=P(1)=1/2P(0)=P(1)=1/2, and the Bloch vector should point along +X+X.
  2. Reset and add RX with the same angle. The Z-basis probabilities are again equal, but the vector points along Y-Y. This demonstrates why probabilities in one basis do not determine a state.
  3. Add RZ after RY and vary its angle. The Z-basis probabilities remain unchanged while the Bloch vector moves around the equator. Exporting results only in the computational basis would miss this phase change, whereas the Bloch view exposes it.

Angles in the gate-entry field are always radians. The Angles selector in the Bloch section changes only how displayed θ\theta and ϕ\phi values are formatted; it does not change the units accepted by RX, RY, RZ or controlled phase.

Control and target ordering

Use two qubits and set the initial basis state to integer 2, displayed as |10⟩. Add CNOT with targets 0,1 and run, then reset and repeat with 1,0. The results differ because the first index is the control. Always hover the completed circuit column and verify which line has the control dot before building on it.

Global phase versus relative phase

Run these two one-qubit circuits from |0⟩:

  • H, Z, H
  • X

Both produce |1⟩, consistent with HZH=XHZH=X. Next compare RX with angle π\pi against X. Both have the same probabilities and Bloch vector because they differ only by the global factor i-i. The simulator correctly has no observable that distinguishes those two output rays.

An efficient entanglement check

Load the Bell (2) preset and run it. Confirm all of the following rather than relying on one picture:

  • only |00⟩ and |11⟩ have nonzero probability;
  • each has probability 1/21/2;
  • each local Bloch radius is zero;
  • increasing Shots makes the two sampled counts approach equal values but does not force them to be exactly equal.

Then remove the CNOT and rerun. The outcome probabilities remain split between two basis states, but the second qubit is no longer correlated with the first. This comparison separates mere local superposition from entanglement.

Last updated on