
Trotterization: Approximating Quantum Evolution with Short Gate Sequences
First-order Trotterization approximates evolution under a sum of Hamiltonian terms with repeated short rotations. A NumPy example tracks the improving fidelity.
Many quantum algorithms need to model how a state changes under a Hamiltonian. When that Hamiltonian is a sum of simpler pieces, Trotterization replaces one difficult evolution with a sequence of shorter, simpler operations. The idea is intuitive, but the order of those operations matters whenever the pieces do not commute.
Split the evolution into short steps
With hbar set to 1, evolution for time t under Hamiltonian H is U(t) = exp(-iHt). If H = A + B, the first-order Lie-Trotter formula approximates it as:
U(t) approx (exp(-i A dt) exp(-i B dt))^r
dt = t / r
Here r is the number of steps. If A and B commute, the product is exact. If they do not, a single short product has an error proportional to dt squared, and the total first-order error decreases roughly like 1/r for fixed t. Reversing the order of the factors gives a different approximation.
A one-qubit example
Let H = (X + Z)/2, where X and Z are Pauli operators. These terms do not commute. Each piece is still easy to implement: exp(-i X dt/2) is an X-axis rotation by angle dt, and exp(-i Z dt/2) is a Z-axis rotation by the same angle.
We will start in |0>, evolve for t = 1, and compare the exact state with the first-order approximation for several step counts. In matrix notation, step = Ux @ Uz means Uz acts first on the state, followed by Ux. That matches the product written above.
For this particular Hamiltonian, H squared equals I/2, so the exact exponential can be calculated directly with sine and cosine. The example therefore uses NumPy alone and does not need a matrix-exponential package.
import numpy as np
I = np.eye(2, dtype=complex)
X = np.array([[0, 1], [1, 0]], dtype=complex)
Z = np.array([[1, 0], [0, -1]], dtype=complex)
H = (X + Z) / 2
psi0 = np.array([1, 0], dtype=complex)
t = 1.0
# H has eigenvalues plus or minus lam because H squared is I/2.
lam = 1 / np.sqrt(2)
exact = (np.cos(lam * t) * I - 1j * np.sin(lam * t) / lam * H) @ psi0
for r in (1, 2, 4, 8, 16):
dt = t / r
Ux = np.cos(dt / 2) * I - 1j * np.sin(dt / 2) * X
Uz = np.cos(dt / 2) * I - 1j * np.sin(dt / 2) * Z
step = Ux @ Uz
approx = np.linalg.matrix_power(step, r) @ psi0
fidelity = abs(np.vdot(exact, approx)) ** 2
print(f"steps={r:2d}, fidelity={fidelity:.6f}")
Expected output:
steps= 1, fidelity=0.950005
steps= 2, fidelity=0.988651
steps= 4, fidelity=0.997287
steps= 8, fidelity=0.999336
steps=16, fidelity=0.999836
Fidelity is the squared overlap between the exact and approximate pure states, so it is 1 for a perfect match. In this small ideal example, more steps improve the approximation. On hardware, however, each extra step also adds gates and circuit depth, which can expose the state to more noise.
Trotterization is a practical tradeoff, not a magic removal of complexity. It lets a programmer express useful dynamics with operations a device can perform, while the step count controls how closely the sequence follows the intended evolution.