Computing Library › Worked Examples
Worked Examples

Trotterizing a Simple Hamiltonian

Approximate time evolution under a sum of non-commuting terms by splitting it into small, easy-to-simulate steps.

The challenge

To simulate exp(-i H t) when H = A + B and A, B do not commute, you cannot just multiply exp(-iAt) exp(-iBt) - that introduces error of order t^2. The Trotter-Suzuki formula controls this by taking many small steps.

First-order Trotter

Kronos motion — confinement time

Split t into n steps of size dt = t/n. Then exp(-iHt) is approximated by [exp(-iA dt) exp(-iB dt)]^n. The error per step is order dt^2, so the total error scales as t^2/n - shrinking as you add steps.

Example: transverse-field Ising on one spin

Take H = Z + X (a single qubit for clarity). Z and X do not commute. Evolve for t = 1 and compare exact to Trotter.

python
import numpy as np
from scipy.linalg import expm
Z=np.array([[1,0],[0,-1]]); X=np.array([[0,1],[1,0]])
H=Z+X; t=1.0
exact=expm(-1j*H*t)
for n in [1,4,16,64]:
    dt=t/n; step=expm(-1j*Z*dt)@expm(-1j*X*dt)
    approx=np.linalg.matrix_power(step,n)
    err=np.linalg.norm(approx-exact)
    print(n, round(err,4))   # error falls ~ 1/n

Second order

The symmetric (Strang) splitting exp(-iA dt/2) exp(-iB dt) exp(-iA dt/2) has error order dt^3 per step, so the total error scales as 1/n^2 - far better for the same number of exponentials. Higher-order product formulas trade more gates for steeper convergence.

Where it is used

Trotterization is the standard route to Hamiltonian simulation on quantum computers and to time-splitting integrators in classical plasma and quantum-chemistry codes, where each term is chosen to be individually easy to apply.