Two qubits prepared together and then separated give results that agree in a way no pair of coins explains. This is the sentence that gets repeated, and on its own it does not tell you how to recognize entanglement in a program, how to measure how strong it is, or why it does not let you send messages faster than light. Here you have three verifiable tools: an algebraic test (can the state be written as a product?), a statistical test (does the CHSH value exceed 2?) and a protocol (teleportation transfers a state using an entangled pair and two classical bits). Each one is a NumPy listing that was executed, in local simulation, with Python 3.14.4 and NumPy 2.5.4.
This is the third lesson of Quantum Computing in Italiano. You need the gates from the previous lesson, in particular Hadamard and CNOT, and the measurement rule from the first. Convention: in the listings the first qubit is the leftmost one, as in the rest of the series.
When a two-qubit state does not separate
A two-qubit state has four amplitudes, one for each of $|00\rangle, |01\rangle, |10\rangle, |11\rangle$. It is separable if it can be written as a product $(a|0\rangle + b|1\rangle)\otimes(c|0\rangle + d|1\rangle)$, that is with amplitudes $ac, ad, bc, bd$. The Bell state $|\Phi^+\rangle = (|00\rangle + |11\rangle)/\sqrt2$ is not: it would require $ad = bc = 0$ with $ac \neq 0$ and $bd \neq 0$, and if $a$ and $d$ are both nonzero the product $ad$ cannot vanish. You obtain it with two gates: Hadamard on the first qubit, then CNOT with the first as control.
The same question can be asked with a calculation. Arrange the four amplitudes in a 2×2 matrix, with rows for the first qubit and columns for the second. If the state is a product, the matrix has rank 1; if it is entangled, it has rank 2. The singular values of the matrix, obtained with the singular value decomposition (SVD), are the Schmidt coefficients. Their squares give the probabilities with which each term appears, and the entropy of that distribution, in bits, measures the entanglement: 0 for a product, 1 bit for the maximally entangled pairs of two qubits.
import numpy as np
H = np.array([[1, 1], [1, -1]]) / np.sqrt(2)
I2 = np.eye(2)
X = np.array([[0, 1], [1, 0]], dtype=complex)
Y = np.array([[0, -1j], [1j, 0]])
Z = np.array([[1, 0], [0, -1]], dtype=complex)
CNOT = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]], dtype=complex)
def schmidt(psi):
# A 2x2 matrix of amplitudes: rows = qubit A, columns = qubit B
return np.linalg.svd(psi.reshape(2, 2), compute_uv=False)
def entropy(psi):
p = schmidt(psi) ** 2
p = p[p > 1e-12]
return float(-(p * np.log2(p)).sum())
ket = lambda a, b: np.kron(np.eye(2)[a], np.eye(2)[b]).astype(complex)
product = np.kron(H @ np.eye(2)[0], H @ np.eye(2)[1]) # |+>|+>
bell = CNOT @ np.kron(H, I2) @ ket(0, 0) # H on qubit A, then CNOT
print("amplitudes of |Phi+> :", np.round(bell.real, 4))
for name, s in (("|+>|+>", product), ("|Phi+>", bell)):
print(f"{name}: Schmidt coefficients {np.round(schmidt(s), 4)}, entropy {entropy(s):.4f} bit")
# The four Bell pairs
for name, (a, b) in {"Phi+": (0, 0), "Phi-": (1, 0), "Psi+": (0, 1), "Psi-": (1, 1)}.items():
s = CNOT @ np.kron(H, I2) @ ket(a, b)
corr = [float(np.vdot(s, np.kron(P, P) @ s).real) for P in (X, Y, Z)]
print(f"{name}: <XX>,<YY>,<ZZ> = {np.round(corr, 3)}")
# Reduced density matrix of A: trace over B
rho = np.outer(bell, bell.conj()).reshape(2, 2, 2, 2)
rho_A = np.einsum("ijkj->ik", rho)
print("rho_A of |Phi+>:", np.round(rho_A.real, 3).tolist())
# Z measurements on both, 20000 pairs, fixed seed
rng = np.random.default_rng(11)
p = np.abs(bell) ** 2 # P(00), P(01), P(10), P(11)
outcomes = rng.choice(4, size=20000, p=p)
a, b = outcomes // 2, outcomes % 2
print("frequency of A=1:", a.mean(), " B=1:", b.mean(), " A!=B:", (a != b).mean())
# Output:
# amplitudes of |Phi+> : [0.7071 0. 0. 0.7071]
# |+>|+>: Schmidt coefficients [1. 0.], entropy 0.0000 bit
# |Phi+>: Schmidt coefficients [0.7071 0.7071], entropy 1.0000 bit
# Phi+: <XX>,<YY>,<ZZ> = [ 1. -1. 1.]
# Phi-: <XX>,<YY>,<ZZ> = [-1. 1. 1.]
# Psi+: <XX>,<YY>,<ZZ> = [ 1. 1. -1.]
# Psi-: <XX>,<YY>,<ZZ> = [-1. -1. -1.]
# rho_A of |Phi+>: [[0.5, 0.0], [0.0, 0.5]]
# frequency of A=1: 0.49325 B=1: 0.49325 A!=B: 0.0
The listing compares |+>|+>, a product state, with |Phi+>. For the first, the Schmidt coefficients are [1, 0] and the entropy is 0; for the second they are both 0.7071 and the entropy is 1.0000 bit. The function schmidt is all there is to it: psi.reshape(2, 2) arranges the amplitudes and np.linalg.svd(..., compute_uv=False) returns the singular values. The loop over the four Bell pairs prints the expectation values $\langle XX\rangle, \langle YY\rangle, \langle ZZ\rangle$: for $|\Phi^+\rangle$ they are +1, −1, +1. With the same three numbers you can recognize each of the four pairs, each with a different combination of signs.
Two lines deserve a slow reading. The first computes the reduced density matrix of the first qubit (np.einsum("ijkj->ik", rho), which sums over the second): it is $I/2$, that is the completely undetermined state. You know everything about the pair and nothing about each of the two qubits taken alone: this is the difference between a classical correlation and entanglement. The second simulates 20,000 pairs measured in the $Z$ basis with a fixed seed: the outcome of the first qubit is 1 in 49.3% of the cases (0.49325), that of the second is identical, and the two outcomes are never different (A!=B is 0.0). But this perfect correlation, on its own, you could reproduce with two gloves in two boxes: if you open one box and find the left glove, you know the other contains the right one. To find something the gloves do not explain you have to measure in more than one basis together, and that is the test that follows.
Bell's test: the CHSH value
Alice and Bob each receive one qubit of the pair. Alice chooses between two measurements, $A_0$ and $A_1$, Bob between $B_0$ and $B_1$, and each measurement gives +1 or −1. The four average correlations are combined in $S = \langle A_0B_0\rangle + \langle A_0B_1\rangle + \langle A_1B_0\rangle - \langle A_1B_1\rangle$. If the outcomes were values that the two qubits carry with them from the preparation (the gloves, in a more sophisticated version), then $|S| \le 2$: this is the limit of the inequality proposed by Clauser, Horne, Shimony and Holt in 1969, which I recompute here by enumeration. Quantum mechanics instead predicts values up to $2\sqrt2 \approx 2.828$.
import itertools
import numpy as np
X = np.array([[0, 1], [1, 0]], dtype=float)
Z = np.array([[1, 0], [0, -1]], dtype=float)
phi_plus = np.array([1, 0, 0, 1]) / np.sqrt(2)
def observable(angle):
return np.cos(angle) * Z + np.sin(angle) * X # eigenvalues +1 and -1
def correlation(a, b):
return float(phi_plus @ np.kron(observable(a), observable(b)) @ phi_plus)
a0, a1, b0, b1 = 0.0, np.pi / 2, np.pi / 4, -np.pi / 4
E = {k: correlation(*v) for k, v in {"A0B0": (a0, b0), "A0B1": (a0, b1),
"A1B0": (a1, b0), "A1B1": (a1, b1)}.items()}
S = E["A0B0"] + E["A0B1"] + E["A1B0"] - E["A1B1"]
print({k: round(v, 4) for k, v in E.items()})
print("quantum S:", round(S, 6), " 2*sqrt(2) =", round(2 * np.sqrt(2), 6))
# The case with swapped signs: B1 = (X - Z)/sqrt(2) instead of (Z - X)/sqrt(2)
S_wrong = E["A0B0"] - E["A0B1"] + E["A1B0"] + E["A1B1"]
print("with B1 of opposite sign S =", round(S_wrong, 6))
# Classical limit: 16 deterministic assignments of +-1 to A0, A1, B0, B1
maximum = max(abs(x0 * y0 + x0 * y1 + x1 * y0 - x1 * y1)
for x0, x1, y0, y1 in itertools.product((1, -1), repeat=4))
print("maximum of |S| over 16 deterministic classical strategies:", maximum)
# Search the grid for the quantum maximum (angles that are multiples of pi/16)
grid = np.arange(32) * np.pi / 16
best = max(abs(correlation(p, r) + correlation(p, s) + correlation(q, r) - correlation(q, s))
for p in grid[:1] for q in grid for r in grid for s in grid)
print("maximum of |S| on the grid:", round(best, 6))
# Estimate from samples: 25000 pairs for each of the 4 combinations of settings
rng = np.random.default_rng(5)
def sample(a, b, n):
_, va = np.linalg.eigh(observable(a))
_, vb = np.linalg.eigh(observable(b))
p = np.array([[abs(np.kron(va[:, i], vb[:, j]) @ phi_plus) ** 2 for j in range(2)] for i in range(2)]).ravel()
k = rng.choice(4, size=n, p=p / p.sum())
return (np.where(k // 2 == 1, 1, -1) * np.where(k % 2 == 1, 1, -1)).mean() # eigenvalues -1,+1
n = 25000
estimate = sample(a0, b0, n) + sample(a0, b1, n) + sample(a1, b0, n) - sample(a1, b1, n)
print("S estimated from", 4 * n, "pairs:", round(float(estimate), 4), "(standard error ~0.009)")
# Output:
# {'A0B0': 0.7071, 'A0B1': 0.7071, 'A1B0': 0.7071, 'A1B1': -0.7071}
# quantum S: 2.828427 2*sqrt(2) = 2.828427
# with B1 of opposite sign S = 0.0
# maximum of |S| over 16 deterministic classical strategies: 2
# maximum of |S| on the grid: 2.828427
# S estimated from 100000 pairs: 2.8296 (standard error ~0.009)
The listing computes everything in three ways. First the exact one: to measure "along an angle" in the $x$-$z$ plane it uses the observable cos(a) Z + sin(a) X, which has eigenvalues +1 and −1. With the angles $0$ and $\pi/2$ for Alice and $\pi/4$ and $-\pi/4$ for Bob, the four correlations are 0.7071, 0.7071, 0.7071 and −0.7071, and $S = 2.828427$, equal to $2\sqrt2$ to the sixth digit. The next line prints the value of $S$ if the sign of $B_1$ is reversed: $0.0$. Signs matter: a single wrong sign cancels the violation, and it is the mistake worth checking against a known case before trusting a value.
Then the classical limit: with itertools.product the listing tries all 16 deterministic assignments of ±1 to the four values and finds that the maximum of $|S|$ is 2. On the quantum side, a search over a grid of angles that are multiples of $\pi/16$ (with the angle of $A_0$ fixed at 0, because rotating everything does not change the expectation values) does not exceed 2.828427: a numerical check consistent with Tsirelson's bound (1980), not a proof. Finally the sampling: 25,000 pairs for each of the four combinations of settings, that is 100,000 pairs, give $S = 2.8296$, with a standard error of about 0.009, hence compatible with 2.828 and about 90 standard errors away from the classical limit.
What it shows and what it does not. The listing computes the theory's predictions and samples them: it does not prove that nature obeys them. That proof comes from experiments: Aspect, Dalibard and Roger (1982) with time-varying analyzers, and Hensen and colleagues (2015) with electron spins 1.3 kilometres apart and the experimental loopholes closed. Of those papers I checked title, journal and year on Crossref, I did not read the text.
Teleportation: moving a state with a pair and two bits
Alice has a qubit in a state $|\psi\rangle$ that she does not know, and she wants Bob to have an identical one, without sending him the qubit. She cannot measure it to communicate the results to him (a measurement is not enough to reconstruct a state), nor copy it (no-cloning forbids it). The protocol of Bennett and colleagues (1993) uses a shared Bell pair: Alice has the first qubit of the pair, Bob the second.
The steps are these: Alice applies a CNOT from the unknown qubit to her qubit of the pair, then a Hadamard on the unknown qubit, and measures both. She obtains two bits $(m_0, m_1)$ and sends them to Bob over a classical medium. Bob applies $X$ if $m_1 = 1$ and then $Z$ if $m_0 = 1$: his qubit is now Alice's state.
import numpy as np
H = np.array([[1, 1], [1, -1]]) / np.sqrt(2)
X = np.array([[0, 1], [1, 0]], dtype=complex)
Z = np.array([[1, 0], [0, -1]], dtype=complex)
I2 = np.eye(2)
def apply_1q(state, U, q):
t = np.moveaxis(np.tensordot(U, state, axes=([1], [q])), 0, q)
return t
def cnot(state, c, t):
out = state.copy()
idx = [slice(None)] * 3
idx[c] = 1
axis = t if t < c else t - 1
out[tuple(idx)] = np.flip(out[tuple(idx)], axis=axis)
return out
rng = np.random.default_rng(3)
v = rng.normal(size=2) + 1j * rng.normal(size=2)
v /= np.linalg.norm(v) # Alice's unknown state
print("state to teleport:", np.round(v, 4))
bell = np.array([1, 0, 0, 1]) / np.sqrt(2) # qubit 1 (Alice) and 2 (Bob)
state = np.kron(v, bell).reshape(2, 2, 2) # qubit 0 = unknown state
state = cnot(state, 0, 1) # CNOT 0 -> 1
state = apply_1q(state, H, 0) # H on qubit 0
rho_bob_avg = np.zeros((2, 2), dtype=complex)
f_reversed = 1.0
for m0 in (0, 1):
for m1 in (0, 1):
bob = state[m0, m1, :] # projection onto the outcome (m0, m1)
prob = float(np.vdot(bob, bob).real)
bob = bob / np.sqrt(prob)
rho_bob_avg += prob * np.outer(bob, bob.conj())
corrected = np.linalg.matrix_power(Z, m0) @ np.linalg.matrix_power(X, m1) @ bob
fidelity = abs(np.vdot(v, corrected)) ** 2
reversed_order = np.linalg.matrix_power(X, m1) @ np.linalg.matrix_power(Z, m0) @ bob
f_reversed = min(f_reversed, abs(np.vdot(v, reversed_order)) ** 2)
print(f"outcomes ({m0},{m1}): probability {prob:.3f}, fidelity after the correction {fidelity:.6f}")
print("Bob's state without knowing the outcomes:", np.round(rho_bob_avg.real, 3).tolist())
print("minimum fidelity with the corrections in reverse order (Z then X):", round(float(f_reversed), 6))
# Output:
# state to teleport: [ 0.61 +0.125j -0.7639-0.1697j]
# outcomes (0,0): probability 0.250, fidelity after the correction 1.000000
# outcomes (0,1): probability 0.250, fidelity after the correction 1.000000
# outcomes (1,0): probability 0.250, fidelity after the correction 1.000000
# outcomes (1,1): probability 0.250, fidelity after the correction 1.000000
# Bob's state without knowing the outcomes: [[0.5, 0.0], [0.0, 0.5]]
# minimum fidelity with the corrections in reverse order (Z then X): 1.0
The listing prepares a random state v with a fixed seed and builds the three qubits with np.kron(v, bell). It applies CNOT (cnot(state, 0, 1)) and Hadamard on qubit 0. Then, for each of the four outcomes, it takes with state[m0, m1, :] the sub-vector of Bob compatible with that outcome, normalizes it, applies the corrections with matrix_power and computes the fidelity with v. Each of the four outcomes has probability 0.250 and the fidelity after the correction is 1.000000: the protocol works for every outcome, not only for the "lucky" ones. Qiskit 2.6.2, with controlled corrections in place of the measurements (the "deferred measurement"), gives the same fidelity 1.
The last line is the most important. If Bob does not know Alice's outcomes, his state is the average over the four cases, and the resulting density matrix is $I/2$: no information about v. It is the numerical demonstration that teleportation does not allow communicating faster than light: the classical channel is needed, and with it the two bits.
- The state is transferred, not matter: Bob's qubit is a different physical system, prepared in another way.
- Two classical bits are needed for each qubit transferred, and the Bell pair is consumed.
- The original does not survive: Alice's measurement has collapsed it, in agreement with no-cloning.
- Alice does not need to know the state, and neither does Bob.
The four points describe what the protocol costs and what it leaves intact. They are properties that can be read directly in the calculation: from the four identical probabilities, from the matrix $I/2$ and from the fact that Bob never uses v in any step, because he receives only its effect through the pair.
The mistakes made most often
The first is saying "entangled states communicate": the reduced matrix $I/2$ says that one of the two qubits alone carries no information about the choices of the other. The second is using correlation in a single basis as proof of entanglement: two gloves produce it. The third, tied to the second, is forgetting that the CHSH limit of 2 holds for any model with predetermined values, not only for those you have in mind. The fourth is getting a sign wrong in the observables, as the line with $S = 0$ shows. In teleportation, finally, people ask whether the order of the corrections matters: $X$ and $Z$ anticommute, so swapping them changes only a global phase, and the last line of the third listing confirms it with a minimum fidelity of 1.
What you can do now
You can recognize an entangled state from the rank of the amplitude matrix, measure its strength with the Schmidt entropy, compute the CHSH value of a Bell pair and compare it with the classical limit 2 found by enumeration, and simulate teleportation, checking that it works for every outcome and carries no information without the two bits. In the next lesson you use interference, not entanglement, to solve an oracle problem with fewer questions than the best deterministic classical algorithm.
Frequently asked questions
How do you recognize an entangled state of two qubits?
You arrange the four amplitudes in a 2×2 matrix: if it has rank 1 the state is a product, if it has rank 2 it is entangled. The singular values are the Schmidt coefficients and their entropy measures the entanglement, from 0 to 1 bit.
Why does the classical CHSH value not exceed 2?
Because if the outcomes are values fixed in advance, there are only 16 assignments of ±1 to the four values, and for each of them $|S|$ is 2. The listing enumerates them all: the maximum is 2. With a Bell pair and well-chosen angles the quantum prediction is $2\sqrt2 \approx 2.83$.
Is teleportation faster than light?
No. Without Alice's two classical bits, Bob's state is $I/2$ whatever the state sent, so he receives no information. The bits travel over a classical channel, which does not exceed the speed of light.
Does teleporting a state violate no-cloning?
No: in the protocol the original is destroyed by Alice's measurement. At the end there is only one qubit in the state $|\psi\rangle$, Bob's, not two.
Later in the series you will also find Shor's algorithm (article 6) and quantum hardware (article 10).
Sources
- C. H. Bennett et al., "Teleporting an unknown quantum state via dual classical and Einstein-Podolsky-Rosen channels", Phys. Rev. Lett. 70, 1895 (1993) - the teleportation protocol; title, journal and year checked on Crossref, the text was not read, consulted on 2026-11-13
- J. F. Clauser, M. A. Horne, A. Shimony, R. A. Holt, "Proposed Experiment to Test Local Hidden-Variable Theories", Phys. Rev. Lett. 23, 880 (1969) - the CHSH inequality; title and year checked on Crossref, the limit 2 is recomputed in the article by enumeration, consulted on 2026-11-13
- B. Hensen et al., "Loophole-free Bell inequality violation using electron spins separated by 1.3 kilometres", Nature 526 (2015) - the loophole-free experiment; title and year checked on Crossref, the text was not read, consulted on 2026-11-13
- A. Aspect, J. Dalibard, G. Roger, "Experimental Test of Bell's Inequalities Using Time-Varying Analyzers", Phys. Rev. Lett. 49, 1804 (1982) - the experiment with time-varying analyzers; title and year checked on Crossref, the text was not read, consulted on 2026-11-13
- B. S. Tsirelson, "Quantum generalizations of Bell's inequality", Lett. Math. Phys. 4 (1980) - the quantum limit of the CHSH; title and year checked on Crossref, the text was not read, consulted on 2026-11-13
The three listings were run twice with Python 3.14.4 and NumPy 2.5.4, with identical output. The CHSH value of the Bell pair and the teleportation were repeated with Qiskit 2.6.2 (current version on PyPI on 2026-11-13) with the same result. Of the five works cited I did not read the text: where the article reports a result from them, it reports it as stated by the title or recomputed here.
Commenti
Caricamento commenti...
Sign in to comment