# Stabilizers and quantum error correction {#correction}

**Learning goals.** Encode an unknown state without cloning it, extract parity syndromes, understand code distance, and derive stabilizer commutation and recovery conditions.

## Protect amplitudes without learning them

An encoding maps one logical qubit into a larger physical space:

$$\alpha|0\rangle+\beta|1\rangle
\longmapsto \alpha|0_L\rangle+\beta|1_L\rangle.$$

It does not produce three copies $(\alpha|0\rangle+\beta|1\rangle)^{\otimes3}$. The logical amplitudes are distributed through a code subspace. Error checks must reveal information about errors while preserving the encoded information.

The three-qubit bit-flip code uses
$|0_L\rangle=|000\rangle$, $|1_L\rangle=|111\rangle$.
CNOTs from the input to two zero ancillas encode it. A flip on the middle qubit produces
$\alpha|010\rangle+\beta|101\rangle$.
Measuring every physical bit would reveal the logical value and destroy a general superposition. Instead measure parity.

## Syndrome extraction

The checks are $Z_0Z_1$ and $Z_1Z_2$. Every valid code state has eigenvalue +1 for both. A bit flip changes the signs of checks touching its location:

| Error | $Z_0Z_1$ | $Z_1Z_2$ | Syndrome bits |
|:--|:--:|:--:|:--:|
| I | +1 | +1 | 00 |
| $X_0$ | −1 | +1 | 10 |
| $X_1$ | −1 | −1 | 11 |
| $X_2$ | +1 | −1 | 01 |

The bit convention is 0 for eigenvalue +1 and 1 for −1. A fresh ancilla initialized to zero receives CNOTs from the two data qubits; measuring it in Z reveals their parity. The two components of the encoded superposition share the same syndrome, so the syndrome does not reveal α or β.

After syndrome 11, apply $X_1$:
$X_1(\alpha|010\rangle+\beta|101\rangle)
=\alpha|000\rangle+\beta|111\rangle$.
The same correction acts on both amplitudes.

Two flips can mimic one. $X_0X_1$ has the same syndrome as $X_2$. Correcting as though $X_2$ occurred leaves $X_0X_1X_2$, a logical X. Thus under independent flips and perfect checks the failure probability is $3p^2-2p^3$. This code does not correct arbitrary phase errors.

::: {.lab #lab-repetition}
**Laboratory L23 — Repetition-code memory.** Inject a specific bit-flip pattern, inspect neighboring parity checks and the chosen recovery, and compare exact odd-distance failure probabilities. Measurements and recovery are ideal in this model.
:::

![Encode an arbitrary input in the three-qubit repetition code, then extract the two Z-parity checks into separate ancillas. This ideal circuit explains the syndrome; it is not a fault-tolerant extraction schedule.](figures/repetition.svg)

![Repetition-code failure under independent X errors and perfect recovery. The improvement concerns one error type.](figures/repetition-scaling.svg)

## Why correcting Pauli errors is enough in principle

Any one-qubit operator can be expanded as $aI+bX+cY+dZ$. If a code corrects an appropriate error set, it also corrects coherent combinations in the span under the quantum error-correction conditions. Syndrome extraction separates error sectors without reading the logical amplitudes.

This does not mean hardware errors literally select a Pauli every time. It is a statement about a linear operator basis and recoverability. Coherent noise, correlated multi-qubit errors, leakage, and faulty syndrome circuits still require careful modeling.

A phase-flip repetition code uses $|+++\rangle,|---\rangle$ and X-type checks. Combining protection against bit and phase errors leads to codes such as Shor's nine-qubit code [@shorcode]. Its logical states can be written

$$|0_L\rangle=\left(\frac{|000\rangle+|111\rangle}{\sqrt2}\right)^{\otimes3},
\quad
|1_L\rangle=\left(\frac{|000\rangle-|111\rangle}{\sqrt2}\right)^{\otimes3}.$$

The construction protects against any single physical-qubit error, not just a classical bit flip.

## Stabilizer groups and logical operators

A Pauli string is a tensor product of I,X,Y,Z with a phase. Two strings commute if the number of positions where they have different nonidentity Paulis is even. For example, XX and ZZ commute: each position contributes one minus sign, so the total sign is positive.

An abelian stabilizer group S not containing −I defines the common +1 eigenspace of its generators. With r independent generators on n qubits, the code-space dimension is $2^{n-r}$, encoding k=n−r logical qubits. Independence matters: a product of existing generators imposes no new constraint [@gottesman].

A logical Pauli commutes with all stabilizers but is not itself a stabilizer. For the repetition code,
$\overline X=X_0X_1X_2$ and $\overline Z=Z_0$ are logical operators.
Multiplying a logical operator by a stabilizer changes its physical representative but not its action within the code space.

An $[[n,k,d]]$ quantum code has distance d equal to the smallest weight of a nontrivial logical Pauli, for a stabilizer code. It can correct arbitrary errors on up to $\lfloor(d-1)/2\rfloor$ unknown locations. Known erasures can be corrected on up to d−1 locations under the code's assumptions. The bit-flip repetition code has distance one as a full quantum code because a single Z is an undetectable logical phase operation.

## The Knill–Laflamme condition

Let P project onto the code space and $\{E_a\}$ be a set of errors. A recovery correcting their span exists exactly when

$$PE_a^\dagger E_bP=c_{ab}P.$$

The constants may depend on the error labels but not on the encoded logical state. Intuitively, the environment must not learn which logical state was present while distinguishing correctable error processes [@knilllaflamme].

For distinct logical basis states, the condition implies
$\langle i_L|E_a^\dagger E_b|j_L\rangle=0$ when i≠j and equal diagonal values for all i. Error images must preserve logical distinguishability while revealing no logical information through their error-label overlaps.

## CSS codes and a next example

A CSS code uses X-only and Z-only checks specified by binary matrices $H_X,H_Z$. Commutation requires

$$H_XH_Z^T=0\pmod2.$$

Z-type checks detect X components of errors, and X-type checks detect Z components. A Y has both components. The seven-qubit Steane code is an $[[7,1,3]]$ CSS code built from the classical Hamming structure [@steane]. Unlike the three-qubit bit-flip code, it corrects arbitrary single-qubit Pauli errors.

## Exercises

:::: {.exercise #ex17-1}
**17.1.** Give the syndrome of $X_0X_2$ in the repetition code and the result of single-error recovery.

::: {.solution}

Both checks flip, giving 11. Recovery applies $X_1$, leaving $X_0X_1X_2$, a logical X failure.
:::

::::

:::: {.exercise #ex17-2}
**17.2.** Do XZI and ZXI commute? What about XII and ZII?

::: {.solution}

The first pair has two local anticommutations and commutes. The second has one and anticommutes.
:::

::::

:::: {.exercise #ex17-3}
**17.3.** Ten physical qubits have seven independent stabilizer generators. How many logical qubits are encoded?

::: {.solution}

k=10−7=3, so the code space has dimension eight.
:::

::::

:::: {.exercise #ex17-4}
**17.4.** What arbitrary unknown-location errors can a distance-five code correct?

::: {.solution}

Up to two physical-qubit errors. Under an erasure model with known locations, it can correct up to four erasures.
:::

::::

:::: {.exercise #ex17-5}
**17.5.** Why is measuring a parity safer than separately measuring both bits for an encoded superposition?

::: {.solution}

Parity can be identical in both logical components, preserving their coherence within the parity subspace. Separate measurements can distinguish the logical components and reveal encoded information.
:::

::::

