# What's the matrix representation of this 3 qubit circuit?

How do I calculate the matrix representation of this part of a teleportation circuit? It must be a matrix of dimension 8.

• Hi, Nillmer. Welcome to Quantum Computing! I recommend trying to figure it by yourself. Start here. It looks like a simple controlled-$Z$ gate to me. – Sanchayan Dutta Nov 10 '18 at 20:36

One way to do it is to build a sort of quantum IF statement. You have in quantum computing projector operators telling you whether a qubit is 0 or 1: $$P_0 = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix}$$
$$P_1 = \begin{pmatrix} 0 & 0 \\ 0 & 1 \end{pmatrix}$$
$$Z= \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}$$
To build the unitary for your controlled operation, we do : $$CZ = P_0 \otimes I \otimes I + P_1 \otimes I \otimes Z$$
with $$\otimes$$ the tensor product. That means, if your first qubit is in the $$|0\rangle$$ state, we apply the identity operation, otherwise we apply the Z operator only on the third qubit.