# Syndrome extraction operator as matrix?

I am trying to understand how to achieve the syndrome extraction operator matrix in quantum repetition code (if it even exists). It is given that the syndrome is defined here (page 4) as:

[perform] controlled-nots from the first and second received qubits to the first ancilla qubit, then from the first and third received qubits to the second ancilla bit.

First of all, are the ancilla qubits entangled with $$\vert \psi \rangle$$?

Here is what I have understood so far. Given $$\vert \psi \rangle = \alpha \vert x_1, x_2, x_3\rangle + \beta \vert \overline{x_1}, \overline{x_2}, \overline{x_3}\rangle$$ (where $$\overline{x_{i}} = x_i + 1 \quad (\text{mod }2)$$), we can define an operator $$S$$ as:

$$S: \alpha \vert x_1, x_2, x_3\rangle + \beta \vert \overline{x_1}, \overline{x_2}, \overline{x_3}\rangle \rightarrow \underbrace{\vert x_1 \oplus x_2\rangle}_{\text{1^{\text{st}} ancilla qubit}} \underbrace{\vert x_1 \oplus x_3\rangle}_{\, \text{ 2^{\text{nd}} ancilla qubit}},$$

or equivalently as:

$$S: \alpha \vert x_1, x_2, x_3\rangle + \beta \vert \overline{x_1}, \overline{x_2}, \overline{x_3}\rangle \rightarrow \underbrace{\vert \overline{x_1} \oplus \overline{x_2}\rangle}_{\text{1^{\text{st}} ancilla qubit}} \underbrace{\vert \overline{x_1} \oplus \overline{x_3}\rangle}_{\, \text{ 2^{\text{nd}} ancilla qubit}}.$$

This will yield the ancilla values corresponding to the following states: \begin{align*} \text{State\qquad~~} & \text{~~~~Ancilla qubits}\\ \alpha \vert 000\rangle + \beta \vert 111\rangle &\qquad\qquad \vert 00\rangle\\ \alpha \vert 100\rangle + \beta \vert 011\rangle &\qquad\qquad \vert 11\rangle\\ \alpha \vert 010\rangle + \beta \vert 101\rangle &\qquad\qquad \vert 10\rangle\\ \alpha \vert 001\rangle + \beta \vert 110\rangle &\qquad\qquad \vert 01\rangle\\ \alpha \vert 110\rangle + \beta \vert 001\rangle &\qquad\qquad \vert 01\rangle\\ \alpha \vert 101\rangle + \beta \vert 010\rangle &\qquad\qquad \vert 10\rangle\\ \alpha \vert 011\rangle + \beta \vert 100\rangle &\qquad\qquad \vert 11\rangle\\ \alpha \vert 111\rangle + \beta \vert 000\rangle &\qquad\qquad \vert 00\rangle\\\\ \end{align*}

How can I perform such operation using a matrix?

• To answer your first question, no the ancillas are not entangled with the system. Equation 2 of the link you provided gives you what the joint state of the system and introduced ancillas is. For further discussion about ancillas : quantumcomputing.stackexchange.com/questions/1855/… users.physics.ox.ac.uk/~Steane/qec/qec_ams_4.html Dec 27 '19 at 20:01
• @PurvaThakre, thank you for the suggestion. I did spend lots of time trying to grasp what is happening. I think I now understand that an ancilla qubit is a temporary slot that is used to store some information temporarily. My question now is should one ancilla qubit in the repetiton code be $\vert 000 \rangle$ rather than $\vert 0 \rangle$ so that the vectors are aligned with the operator's dimensions? If not, how can a 2D vector be used with dealing with an $8 \times 8$ matrix? I am more concerned about the details of the math here. Jan 3 '20 at 20:14

First of all, are the ancilla qubits entangled with $$|\psi\rangle$$?

Yes, depending on what the state is. Let's say you started with $$\alpha|000\rangle+\beta|111\rangle,$$ but it has experienced an error of $$(\cos\theta I+i\sin\theta X)$$ on the first qubit. So, your state becomes $$\cos\theta(\alpha|000\rangle+\beta|111\rangle)+i\sin\theta(\alpha|100\rangle+\beta|011\rangle).$$ When you perform syndrome extraction, you'll get $$\cos\theta(\alpha|000\rangle+\beta|111\rangle)|00\rangle+i\sin\theta(\alpha|100\rangle+\beta|011\rangle)|11\rangle.$$ This state has entanglement between the computational qubits register and the ancilla register.

Of course, in the next step, you measure the ancilla qubits, and that projects the ancilla qubits into a basis state, removing all entanglement between system and ancillas.

How can I perform such operation using a matrix?

As for what the matrix is, I strongly recommend against performing such calculations. Once you're up to 5 qubits, you're talking a $$32\times 32$$ matrix, which is fairly awful. It is far better to just talk about the action on (relevant) basis states, as you did. However, since you have explicitly asked:

I calculated this in Mathematica using

cNOT[i_, j_] :=
IdentityMatrix[32] +
KroneckerProduct[IdentityMatrix[2^(i - 1)], {{0, 0}, {0, 1}},
IdentityMatrix[2^(j - i - 1)],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 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ \end{array} \right)$$

We can then verify the calculation that I showed before:

initial = {\[Alpha], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \[Beta], 0, 0, 0};
witherror =
KroneckerProduct[{{Cos[\[Theta]], I Sin[\[Theta]]}, {I Sin[\[Theta]],
Cos[\[Theta]]}}, IdentityMatrix[2^4]].initial
U.witherror

• Thank you for the detailed reply. I have two question please: the first is when the ancilla qubits are measured, the whole system doesn't collapse but just the subsystem? how can this be achieved? Also, how did you come up with IdentityMatrix[32] + ..., how about the two $2 \times 2$ matrices MatrixForm[{{0, 0}, {0, 1}}] and MatrixForm[{{-1, 1}, {1, -1}}]? Jan 7 '20 at 17:15
• The whole system does, kind of, collapse. There’s a standard way of talking about the state after a measurement, particularly when you only measure some qubits. Jan 7 '20 at 17:47
• The logic of controlled not is to do nothing (identity matrix) unless the control qubit is in state 1. If it is, don’t do the identity on the target (so subtract it) and add on the not action. Jan 7 '20 at 17:48
• Can you kindly direct me to learning more about the standard way of talking about the state after a measurement? I am relatively new to QC. Jan 7 '20 at 18:13
• Anything that talks about the measurement postulate will give you the formalism to handle this, although might not talk explicitly about this case. What you need is to describe a projective measurement on only some qubits. For example, on 2 qubits, where you project onto the first qubit, you have projection operators $|0\rangle\langle 0|\otimes I$ and $|1\rangle\langle 1|\otimes I$ Jan 8 '20 at 8:18