The three-qubit bit-flip code stores a|0\rangle + b|1\rangle as a|000\rangle + b|111\rangle. Between storing and reading, at most one wire may have suffered a bit flip: an X gate on one qubit, which flips that qubit's bit in every basis state.
To repair the register, measure the syndrome (s_1, s_2) with s_1 = b_0 \oplus b_1 and s_2 = b_1 \oplus b_2, where b_0 b_1 b_2 are the bits of any basis state with a nonzero amplitude (all of them give the same two bits). Each of the four possible damages (no flip, or a flip of qubit 0, 1 or 2) gives a different syndrome, so the syndrome says which X undoes the damage.
Write correct(state) that returns the repaired register, a|000\rangle + b|111\rangle, as 8 amplitudes. state is a code state with an X on at most one qubit.
Conventions: amplitude i belongs to basis state i; qubit 0 is the leftmost bit, so |100\rangle is index 4 and |011\rangle is index 3.
Examples
Input: state = [0, 0, 0, 0.8, 0.6, 0, 0, 0]
Output: [0.6, 0, 0, 0, 0, 0, 0, 0.8]
Explanation: 0.6|100> + 0.8|011> has syndrome (1, 0): qubit 0 was flipped.
Input: state = [0.6, 0, 0, 0, 0, 0, 0, 0.8]
Output: [0.6, 0, 0, 0, 0, 0, 0, 0.8]
Explanation: syndrome (0, 0): nothing to repair.
Input: state = [0, 0.7071067811865476j, 0, 0, 0, 0, -0.7071067811865476, 0]
Output: [0.7071067811865476j, 0, 0, 0, 0, 0, 0, -0.7071067811865476]
Amplitudes are compared with a tolerance of 1e-6. Any global phase is accepted: [-0.6, 0, 0, 0, 0, 0, 0, -0.8] is the same state as the first answer.
Goals
- Turn a syndrome into the qubit that needs an X
- Repair a damaged code state without learning its amplitudes