Entanglement: Bell and GHZ states
30 min
Two gates
The Hadamard gate h turns |0⟩ into (|0⟩ + |1⟩)/√2. The CNOT, cx a, b, flips the target b when the control a is 1 and does nothing when a is 0.
A Bell pair
Start from |00⟩, apply h to a, then cx a, b. The state is (|00⟩ + |11⟩)/√2. Read alone, each qubit is a fair coin. Read together, they always agree: 00 or 11, never 01 or 10. No pair of single-qubit states multiplies out to this state, which is what entangled means.
More qubits
A chain of CNOTs spreads the same correlation: h on the first qubit and three CNOTs give the four-qubit GHZ state (|0000⟩ + |1111⟩)/√2.
What the counts show and what they do not
Perfect agreement in one basis could also come from a classical coin copied twice. Entanglement shows when you measure in other bases too, as in a Bell test, which needs more than these two programs. Here the point is to build the states and see the correlation. Our runs read 00 on 51.4% and 11 on 48.6% of 1,000 shots for the Bell pair, and only 0000 or 1111 for GHZ.
HiQ lab 1
A Bell pair
A Hadamard puts qubit a in an equal superposition, and a CNOT copies its value into b. The two qubits are now entangled.
// Bell pair: a Hadamard and a CNOT entangle two qubits.// The two bits always agree: 00 or 11, each about half the time.program bellqubits a, bbits m0, m1h acx a, bmeasure a -> m0measure b -> m1- What you should see
- Only 00 and 11, each about half the time. Never 01 or 10.
- What we measured
- 00 on 51.4% of the shots, 11 on 48.6%, nothing else. QCOS checked this program and ran it on a Softquantus Cloud simulator, 1,000 shots, 13 November 2026.
Check it yourself
Save the program as bell.qcos, set QCOS_API_KEY to a key from your workspace on the Softquantus Research Platform, and ask QCOS to check it. Change a line, check again, and see what the checker says.
pip install softqcossoftqcos lang check bell.qcos
HiQ lab 2
A four-qubit GHZ state
The same idea on four qubits: one Hadamard, then a chain of three CNOTs.
// GHZ state on four qubits: every shot reads 0000 or 1111.program ghzqubits q[4]bits m[4]h q[0]cx q[0], q[1]cx q[1], q[2]cx q[2], q[3]repeat i in 0..4 { measure q[i] -> m[i]}- What you should see
- Only 0000 and 1111, each about half the time.
- What we measured
- 0000 on 52.1% of the shots, 1111 on 47.9%, nothing else. QCOS checked this program and ran it on a Softquantus Cloud simulator, 1,000 shots, 13 November 2026.
Check it yourself
Save the program as ghz.qcos, set QCOS_API_KEY to a key from your workspace on the Softquantus Research Platform, and ask QCOS to check it. Change a line, check again, and see what the checker says.
pip install softqcossoftqcos lang check ghz.qcos