# How do you apply a multi qubit gate to specific qubits in a multi qubit circuit?

Let's say that you have a 6 qubit system and you want to apply a Hadamard gate to qubits 2 and 4.

How would you construct a matrix that did that, while leaving the state of the other qubits alone?

## 1 Answer

Imagine that the qubits were $0$ and $1$ (or $1$ and $2$, depending on your numbering scheme). You want to apply the Hadamard gate on the first two coordinates, and nothing – the identity – on the rest. This leads to a block diagonal matrix whose second block is the $4\times 4$ identity.

Now make the necessary arrangements for the qubits you're interesting it.

• My question is specifically, what are the necessary arrangements when not using neighboring qubits? :p – Alan Wolfe Oct 18 '15 at 20:48
• You take the tensor product of your gate and the identity on the rest of the bits. I don't know what you mean by arrangement. In terms of matrices, this is just a block diagonal matrices with its rows and columns shuffled. – Yuval Filmus Oct 18 '15 at 20:53
• It turns out I didn't ask the question I intended to ask, due to incomplete understanding. Sorry about that Yuval and thanks for your answer! – Alan Wolfe Oct 21 '15 at 14:59
• Yuval, I meant to ask about a multi qubit gate. For instance, let's say you wanted to apply a controlled not to qubits 2 and 4, in a 6 qubit system. I'd like to ask a new question for that, but the title is going to be the same as the title of this question so not sure. Think I ought to delete this one?? – Alan Wolfe Oct 28 '15 at 5:08
• I just went ahead and asked a new one, in case you want some more points hehe. cs.stackexchange.com/questions/48834/… – Alan Wolfe Oct 29 '15 at 4:05