# Shor code: phase flip error

For Shor's error correcting code, what is the intuition behind saying that the following circuit corrects the phase flip error?

I realize that the circuit is trying to compare phases of the three 3-qubit blocks, two at a time. But I don't understand how the Hadamards and CNOTs help in that task. It seems different from the general method followed for phase error correction with three qubits encoded in the Hadamard basis. It also seems to entangle the two ancillas at the end with the encoded 9 qubit code.

The context here is that you've already corrected for a possible bit flip error, so that the input to the circuit is a state that resulted from at most one phase error being applied to a vector in the code space of Shor's 9 qubit code. Vectors in this code space look like $$\alpha |\phi_0\rangle |\phi_0\rangle |\phi_0\rangle + \beta |\phi_1\rangle |\phi_1\rangle |\phi_1\rangle,$$ where $$|\phi_0\rangle = \frac{|000\rangle + |111\rangle}{\sqrt{2}} \quad \text{and} \quad |\phi_1\rangle = \frac{|000\rangle - |111\rangle}{\sqrt{2}}.$$ A phase error on the first block (i.e., qubit 1, 2, or 3), for instance, would result in the state $$\alpha |\phi_1\rangle |\phi_0\rangle |\phi_0\rangle + \beta |\phi_0\rangle |\phi_1\rangle |\phi_1\rangle.$$
Now, the reasoning behind the circuit is that applying Hadamard gates to each qubit of $|\phi_0\rangle$ gives a uniform superposition over even-parity strings, while applying Hadamard gates to each qubit of $|\phi_1\rangle$ gives a uniform superposition over odd-parity strings. Each set of three controlled-NOT gates will therefore induce a bit flip on one of the syndrome qubits when the three corresponding qubits are in the $|\phi_1\rangle$ state but not in the $|\phi_0\rangle$ state.