# General approach for switching control and target qubit

It is well known that circuit can be replaced with this circuit The situation is even easier in case of controlled $$\mathrm{Z}$$ where gate controlled by $$q_0$$ and acting on $$q_1$$ have same matrix as one controlled by $$q_1$$ and acting on $$q_0$$. This means that replacing gate controled by qubit "below" with one controlled by qubit "above" does not need any additional gate.

I was thinking about general case, i.e. how to replace general controlled gate $$\mathrm{U}$$ with controlling qubit "below" by the gate controlled by qubit "above". The very basic idea is to apply swap gate, then controlled $$\mathrm{U}$$ with controlling qubit "above" and then again swap gate. This is right approach because $$\mathrm{U}$$ gate controlled by qubit "above" is described by matrix

$$\mathrm{CU_{above} =} \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & u_{11} & u_{12} \\ 0 & 0 & u_{21} & u_{22} \end{pmatrix}$$

and the gate controlled by qubit "below" has this matrix

$$\mathrm{CU_{below} =} \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & u_{11} & 0 & u_{12} \\ 0 & 0 & 1 & 0 \\ 0 & u_{21} & 0 & u_{22} \end{pmatrix}.$$

It can be easily checked that $$\mathrm{CU_{bellow}} = \mathrm{SWAP} \cdot \mathrm{CU_{above}} \cdot \mathrm{SWAP}$$.

Swap gate can be implemented with three $$\mathrm{CNOT}$$, two controlled by qubit "above", one controlled by qubit "below". However, the latter can be converted to $$\mathrm{CNOT}$$ controlled by qubit "above" with help of Hadamards. Ultimatelly, all $$\mathrm{CNOT}$$s in swap gate are controlled by qubit "above".

So, this is a desired general approach how to convert a gate controlled by qubit "below" to one controlled by qubit "above". However, application of two swap gates increases depth of the circuit.

My question are these:

1. Is there a simpler general approach how to convert a gate controlled by qubit "below" to one controlled by qubit "above"?
2. Are there other specific construction for other controlled gates similar to approach for controlled $$\mathrm{X}$$ and $$\mathrm{Z}$$? For example for controlled $$\mathrm{Y}$$, $$\mathrm{H}$$, $$\mathrm{Ry}$$ etc.

Any controlled-$$U$$ where $$U^2=I$$ is straightforward. This is because you can write $$U=VZV^\dagger$$. So, we can think of controlled-$$U$$ as $$V^\dagger$$ on target, then controlled-phase, then $$V$$ on target.
Given the symmetry of controlled-phase, all you have to do is switch which qubits the single-qubit unitaries are applied to. This clearly contains your two stated cases ($$U=X,Z$$) as special cases ($$V=H,I$$).
About the case of more general $$U$$, I've never thought about it... My first instinct is that given any controlled-$$U$$ can be decomposed in terms of two controlled-nots and three single-qubit gates, and it seems most likely that it would take that to reverse the action, you'd be better off just directly implementing controlled-$$U$$ with the switched control/target assignment, and ignoring the fact that you already have controlled-$$U$$ in the other direction!