# Matrix representation of multi-qubit operations when there's irrelevant qubit(s)

Suppose there are three qubits, q0, q1, and q2, if you perform a CX on q0 and q1, the entire matrix of the operation you performed on the whole quantum circuit will simply be the tensor product of CX and I.

My question is, how to do so if the irrelevant qubit is between the involved qubits? I have listed three such gates in the upper figure, one CX and two CSWAPs.

P.S. If you do some SWAPs such case can be fixed, but is there a simpler, and more general method?

• Commented Feb 21, 2022 at 15:34

A CNOT gate is $$|0\rangle \langle0|\otimes I +|1\rangle \langle1|\otimes X$$. If there is an intermediary qubit between it then it will simply be $$CNOT_{1,3}=|0\rangle \langle0|\otimes I \otimes I +|1\rangle \langle1| \otimes I\otimes X$$
• Maybe you can stress that any quantum logical gates can be decomposed to a set of universal quantum gates, for example, $R_x (θ), R_y (θ), R_z (θ), P(ϕ)$ and $CNOT$ Commented Feb 22, 2022 at 2:53