## 12.5 Repetition codes

In order to give a sense of how quantum error correction actually works, let us begin with a *classical* example of a **repetition code**.

Suppose that Alice is communicating to Bob over a channel which, with some probability ^{207}
Even if Bob *knows* that these potential flips are happening, he cannot always compensate for the errors introduced.
It could be the case that he receives the binary message, converts it into alphabetic characters, and reads “Hello Bpb”.
Then he would likely think to himself that Alice had intended to send “Hello Bob”, and no problems would arise.
But if the transmitted message instead read “Hellp Bob”, then he might be less sure — maybe Alice had just meant to send “Hello Bob”, but maybe she had instead meant to send “Help Bob”.
Of course, if the probability

One thing that they might try is to encode each bit into *three* bits:

The *quantum* case, however, is more complicated, because we have to worry about both bit-flip *and* phase-flip errors.

But let’s start simply: how can we protect a qubit against a *single bit-flip error*

Given some qubit in an unknown pure state

Suppose that the *second* qubit is flipped by our noisy channel, so that the encoded state becomes *two additional* qubits, which we refer to as **ancilla bits**, both in state **encoding network**:

We measure the two ancilla bits (in the standard basis), and the result of the measurement, known as the **error syndrome**, tells us how to reset the three qubits of the code, as follows.

The first ancilla compares qubits one and two (counting from the top), and the second ancilla compares qubits two and three: if the ancilla is measured and found to be the *same* state; if it is found in the *different* states.
Hence, the four possible error syndromes —

This three-qubit code^{208} that we have just demonstrated is sufficient to protect a qubit against single bit-flips, but not phase-flips.
But if we know that we *only* have to worry about phase-flips, not bit-flips, then this is actually enough!
Recall that

Finally then, we can consider how to deal with *both* types of errors at once.
First we encode the qubit using the phase-flip code, and then we encode each of the resulting three qubits of the code using the bit-flip code.
This gives an error correction scheme that allows us to protect against both types of error by encoding a single logical qubit across *nine* physical qubits, protecting against a *single* quantum error on any of the nine qubits.

If we want to preserve a quantum state for a long time without doing any computations, or if we want to send it through a noisy communications channel, we can just encode the state using a quantum code and decode it when we are done.
Computation on encoded states using noisy *gates*, however, requires a few more tricks…