Let there be a system of three qubits, $a,b,c,d$ where $d$ is an ancilla qubit. We can add more ancilla if required. The operation I want to implement is as follows:

"If $a$ and $b$ are both in the '$1$' state, then swap qubits $b$ and $c$."

Obviously this is not a unitary transformation but it might be possible with the use of ancilla qubits. I got a similar self-controlling circuit to work with Toffoli gates, but the double-control SWAP gate eludes me. My advisor thinks it might be impossible, but neither of us has proven that.

Basically, does anyone have any idea how this operation might be implemented in a quantum circuit using one or more ancilla?

  • $\begingroup$ Why is this not a unitary gate?? -- Also, why would you call this a "double-control swap"? Wouldn't the latter swap c and d, given a=b=1? $\endgroup$ Sep 20, 2019 at 15:09
  • $\begingroup$ I call it a double control because it requires two different control qubits a and b. Also, the trick is that it swaps b and c, not c and d. This is a sort of self-control. As to why that isn't unitary, we'll imagine it with just the first three qubits and no ancilla. Then 000 is mapped to 000, 001 to 001, 010 to 010, 011 to 011, 100 to 100, 101 to 101, 111 to 111 but 110 is mapped to 101. It's no longer bijective. $\endgroup$ Sep 20, 2019 at 16:11
  • $\begingroup$ You're right. Then you can't do it coherently (that is, as a linear map on the Hilbert space). $\endgroup$ Sep 20, 2019 at 16:49

1 Answer 1


I'm not sure that this is what you want, but sure, you can make the operation unitary by adding an ancillary qubit that starts with a fixed state.

For example, you can add a fourth qubit which is initially always in the $|0\rangle$ state, and modify the gate to also apply $X$ to the fourth qubit when $a=b=1$. This avoids the problem of having both $|101\rangle$ and $|110\rangle$ going to the same output.

  • $\begingroup$ That looks like what I was looking for! Thanks. I didn't think of using Toffoli gates for some reason. $\endgroup$ Sep 30, 2019 at 18:37
  • $\begingroup$ @KenRobbins no problem. Don't forget to upvote/accept an answer if you think it's helpful! $\endgroup$
    – glS
    Sep 30, 2019 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.