Case Study: From Hamming to Steane — Building a Quantum Code from Classical Parts

Executive Summary

The Steane code — 7 physical qubits protecting 1 logical qubit against any single-qubit error — is not invented from scratch. It is the classical Hamming(7,4) code, used twice: once for bit-flip errors and once for phase-flip errors.

This case study performs the construction explicitly, which is the fastest route to understanding why the CSS framework works and why the classical condition $C_2^\perp \subseteq C_1$ is exactly what makes the two error types compatible. Doing it by hand once makes the surface code (Chapter 25) read as a variation rather than a new subject.

Skills applied

  • Constructing parity-check matrices for classical Hamming codes (§23.6).
  • Applying the CSS construction to a nested code pair (§23.11).
  • Deriving stabilizer generators from classical checks.
  • Verifying commutation as the compatibility condition.

Phase 1: The classical ingredient

Hamming(7,4) is a $[7,4,3]$ code with parity-check matrix

$$H = \begin{pmatrix} 0&0&0&1&1&1&1\\ 0&1&1&0&0&1&1\\ 1&0&1&0&1&0&1 \end{pmatrix}$$

Its columns are the binary representations of 1 through 7, which is the elegance of the construction: the syndrome, read as a binary number, is the index of the flipped bit.

Received word Syndrome $Hr$ Error location
Codeword 000 none
Bit 1 flipped 001 bit 1
Bit 5 flipped 101 bit 5
Bit 7 flipped 111 bit 7

Distance 3, so it corrects one error.

Phase 2: The CSS recipe

Take two classical codes $C_2 \subseteq C_1$ with $C_1 = [n,k_1,d_1]$ and $C_2 = [n,k_2,d_2]$. The CSS code encodes $k_1 - k_2$ logical qubits into $n$ physical ones, with stabilizers:

  • $X$-type, from the parity checks of $C_2^\perp$
  • $Z$-type, from the parity checks of $C_1$

The compatibility condition: $C_2^\perp \subseteq C_1$. This is what makes $X$-type and $Z$-type stabilizers commute — and commutation is mandatory, since non-commuting stabilizers cannot be measured simultaneously.

For Steane, take $C_1 = C_2 = $ Hamming(7,4). Hamming is self-dual-containing: $C^\perp \subseteq C$, so the condition holds automatically.

$$k = k_1 - k_2 = 4 - 4 = 0?$$

Not quite — the correct statement uses $C_2 = C_1^\perp = [7,3,4]$, giving $k = 4 - 3 = 1$ logical qubit. This is the $[[7,1,3]]$ Steane code.

Phase 3: The stabilizers

Convert each row of $H$ into a stabilizer, twice — once as $Z$ operators, once as $X$:

$Z$-type generators (detect bit flips):

$$g_1 = Z_4Z_5Z_6Z_7,\qquad g_2 = Z_2Z_3Z_6Z_7,\qquad g_3 = Z_1Z_3Z_5Z_7$$

$X$-type generators (detect phase flips):

$$g_4 = X_4X_5X_6X_7,\qquad g_5 = X_2X_3X_6X_7,\qquad g_6 = X_1X_3X_5X_7$$

Six generators on 7 qubits leaves $7 - 6 = 1$ logical qubit. The parameters $[[7,1,3]]$ fall directly out of the classical $[7,4,3]$.

Phase 4: Verify commutation

Every $X$-type generator must commute with every $Z$-type generator, or they cannot be measured together.

Two Pauli strings commute iff they overlap on an even number of positions where one has $X$ and the other $Z$. Check $g_1 = Z_4Z_5Z_6Z_7$ against $g_5 = X_2X_3X_6X_7$:

  • Support of $g_1$: {4,5,6,7}
  • Support of $g_5$: {2,3,6,7}
  • Overlap: {6,7} — two positions, even → commute

Check $g_2 = Z_2Z_3Z_6Z_7$ against $g_6 = X_1X_3X_5X_7$:

  • Overlap: {3,7} — two positions → commute ✓

All nine pairs commute. This is not luck — it is exactly the condition $C^\perp \subseteq C$ expressed in operator language. Any two rows of $H$ overlap in an even number of positions precisely because the code contains its own dual.

The insight worth carrying forward. The classical duality condition and the quantum commutation condition are the same statement in different notation. That is the whole content of the CSS construction.

Phase 5: Decoding

Because the $X$- and $Z$-type stabilizers are independent, decoding splits into two independent classical problems:

  1. Measure the three $Z$-type stabilizers → 3-bit syndrome → classical Hamming decoding → locate and fix the $X$ error.
  2. Measure the three $X$-type stabilizers → 3-bit syndrome → classical Hamming decoding → locate and fix the $Z$ error.

A $Y$ error is $X$ and $Z$ on the same qubit, so it appears in both syndromes and is corrected by both passes.

H = np.array([[0,0,0,1,1,1,1],
              [0,1,1,0,0,1,1],
              [1,0,1,0,1,0,1]])

def decode(syndrome):
    idx = int(''.join(map(str, syndrome)), 2)   # syndrome IS the bit index
    return None if idx == 0 else idx

The quantum decoder is the classical decoder, run twice. That is the practical payoff of CSS: decades of classical decoding theory transfer directly.

Phase 6: Comparing codes

Code Parameters Classical origin Transversal gates
Shor $[[9,1,3]]$ 3-bit repetition, concatenated CNOT
Steane $[[7,1,3]]$ Hamming(7,4) All of Clifford
Perfect $[[5,1,3]]$ None (not CSS) Fewer
Surface $[[d^2,1,d]]$ Topological / 2D lattice CNOT, limited

Steane's advantage over Shor is not merely 7 qubits versus 9. Its self-dual structure makes the entire Clifford group transversal — $H$, $S$, and CNOT all apply bitwise, which is exactly what fault tolerance requires (Chapter 25). That property comes directly from $C_1 = C_2^\perp$ being the same code, and it is why Steane remains a reference point three decades on.

Discussion Questions

  1. The condition $C_2^\perp \subseteq C_1$ guarantees stabilizer commutation. Explain the correspondence in both directions.
  2. Steane needs 7 qubits and Shor 9, both correcting one error. Where does Shor's inefficiency come from?
  3. CSS decoding splits into two independent classical problems. What quantum error type breaks that independence, and how is it handled?
  4. Steane's self-duality makes all of Clifford transversal. Why can that not extend to $T$?

Your Turn: Extensions

  • Implement Hamming(7,4) encoding and syndrome decoding classically; verify the syndrome-as-index property.
  • Build the Steane stabilizers in Qiskit and verify all nine commutation relations programmatically.
  • Encode $|0_L\rangle$ and $|1_L\rangle$, inject each single-qubit $X$, $Y$, $Z$, and confirm correction.
  • Construct a CSS code from a different nested pair and compute its parameters.

Key Takeaways

  • The Steane code is Hamming(7,4) applied twice — once for $X$ errors, once for $Z$ errors — via the CSS construction.
  • The classical condition $C_2^\perp \subseteq C_1$ and the quantum requirement that stabilizers commute are the same statement.
  • CSS decoding reduces to two independent classical decoding problems, letting classical coding theory transfer wholesale.
  • Steane's self-dual structure makes the full Clifford group transversal, which is why it beats Shor's 9-qubit code by more than qubit count.
  • Understanding one CSS code by hand makes surface codes and qLDPC codes read as variations rather than new theory.