# Realisation of arbitrary controlled quantum gate

I am interested if there's some known approach when constructing quantum gates out of universal set.

I was trying to construct Controlled Z gate (gate that will apply pauli-Z gate on the target qbit depending on control qbit) out of gates from universal set (namely C-NOT, Hadamard and phase rotation gates). But after some time, I've found out that I am just guessing, and that the actual way of constructing it would be probably a lot more complex then I originally imagined.

Is there some universal approach to construct any controlled quantum gate?

Firstly, "universal" method can be interpreted in different ways. You could mean a method, which a human being could use to deduct a controlled U gate for the majority cases, or an algorithm, which can always solve it, but usually is not usable by a human. So I want to mention my thoughts on both points, but I concentrate on the former case, since I believe this is more what your intention was with the question. Secondly, I assume you mean $2\times2$ unitary matrices. Just for the reason that I do not understand the $n$-dimensional case good enough. With N&C I mean the reference to Nielsen's and Chuang's book Quantum Computation and Quantum Information. All pictures in this post are from N&C. I won't explain much the reasons for the steps, if someone wants to really understand this, read N&C section 4.2.
Every unitary matrix $U$ can be decomposed into rotations and a global phase $U=e^{i\alpha}R_z(\beta)R_y(\gamma)R_z(\delta)$ (N&C Theorem 4.1 Z-Y decomposition, page 175). Let us assume for now we already have this decomposition, then we can construct a controlled C-NOT gate by decomposing first $U$ into $U=e^{i\alpha}AXBXC$, where $ABC=I$, using $A=R_z(\beta)R_y(\gamma/2)$, $B=R_y(-\gamma/2)R_z(-(\delta+\beta)/2)$, $C=R_z((\delta-\beta)/2)$ (see proof N&C Corollary 4.2 page 176). Then you use the following equivalence and your controlled-$U$ gate is ready to go. How to construct a controlled-$U$ gate with $n$ control qubits can be also seen in N&C page 183. Here an example for 5 control qubits, I think the basic idea can be seen from the picture Here an example for your controlled-$Z$ gate: $Z=e^{i\pi/2}R_z(\pi)\equiv R_z(\pi)$ therefore $\alpha = \pi/2$, $\beta=\gamma=0$, $\delta = \pi$ and $A= I$, $B=R_z(-\pi/2)$, $C=R_z(\pi/2)$. So we have $Z = e^{i\pi/2}XR_z(-\pi/2)XR_z(\pi/2)$. The $e^{i\pi/2}$ can be modeled with the phase gate $S$. Since it just changes a global phase of the gate, it should be the same, if we omit it.