# Encoding a block unitary matrix in a quantum circuit

My goal would be to implement the unitary matrix $$M=\begin{bmatrix}U_{1} &0\\0&U_{0}\end{bmatrix}$$ as a circuit for arbitrary $$N \mathrm{x} N$$ unitary matrices. It is trivial to show that if $$U_{1}$$ and $$U_{0}$$ are both unitary ($$U_{1}U_{1}^{\dagger}= 1$$ and $$U_{0}U_{0}^{\dagger}=1$$) then the matrix $$M$$ will also be unitary.

However it is not so clear to me how to implement the above block matrix structure in circuit form.

Say you have the circuit to implement the unitary $$U_{1}$$, given by

then you can implement $$\begin{bmatrix}U_{1} &0\\0&U_{1}\end{bmatrix}$$ by simply adding another qubit i.e

as the tensor product of the $$2 \mathrm{x} 2$$ identity operator $$1_{2\mathrm{x}2}$$ with the $$N \mathrm{x} N$$ matrix $$U_{1}$$ is:

$$1_{2\mathrm{x}2} \otimes U_{1} = \begin{bmatrix}U_{1} &0\\0&U_{1}\end{bmatrix}$$.

However I am not sure how to do something similar when $$U_{0} \neq U_{1}$$ but as the matrix will still be unitary there still should be a circuit performing the block encoding given access to $$U_{1}$$ and $$U_{0}$$ however whether this will require controlled unitaries and is constructible in a similarly efficient manner I don't know!

Let's assume that $$U_0$$ and $$U_1$$ act on the same number of qubits. In that case, what you're after is a controlled-unitary. Introduce one extra qubit, called the control. For example, if you do the sequence controlled-$$U_0$$ (controlled off the control qubit), $$X$$ (on the control qubit), controlled-$$U_1$$ (controlled off the control qubit), $$X$$ (on the control qubit), you'll get what you're after.
Alternatively, implement $$U_1$$ on every qubit except the control, then do controlled-$$U_0U_1^\dagger$$.
If you have the circuit to implement $$U_1$$, you can make controlled-$$U_1$$ just by replacing every gate with its controlled version. In practice, you won't need every qubit to be controlled, but that is guaranteed to work.