Computing Library › Worked Examples
Worked Examples

Preparing a GHZ State on Three Qubits

Extend the Bell recipe to three qubits to build the GHZ state, the simplest genuine multipartite entangled state.

The GHZ state

The Greenberger-Horne-Zeilinger state is |GHZ> = (|000> + |111>)/sqrt(2). All three qubits are correlated at once: a single measurement collapses the whole register to all-zeros or all-ones.

Circuit

Kronos motion — three machines
python
import numpy as np
H=np.array([[1,1],[1,-1]])/np.sqrt(2); I=np.eye(2)
def cnot(c,t,n):
    d=2**n; M=np.zeros((d,d))
    for i in range(d):
        b=[(i>>k)&1 for k in range(n)][::-1]
        if b[c]==1: b[t]^=1
        j=sum(v<<(n-1-k) for k,v in enumerate(b)); M[j,i]=1
    return M
psi=np.zeros(8); psi[0]=1
psi=np.kron(np.kron(H,I),I)@psi
psi=cnot(0,1,3)@psi; psi=cnot(1,2,3)@psi
print(np.round(psi,3))  # 0.707 at |000> and |111>

Why it matters

GHZ states are extremely fragile: losing one qubit destroys all entanglement, unlike the W state which degrades gracefully. That fragility makes GHZ a sensitive probe for benchmarking gate fidelity and for tests of quantum nonlocality across many parties.

The pattern generalises: n-1 chained CNOTs after one Hadamard produce an n-qubit GHZ state, a building block in error-correction encoders and multi-party protocols.