Many classical programming languages are equipped with a construct known as the conditional statement
if (condition) {
u();
}
where condition
is a boolean expression, i.e. an expression that evaluates to one of two values: true
or false
and where u()
is an operation to be executed when condition
evaluates to true
. In quantum computing this construct corresponds to a controlled gate
$$
CU = \begin{pmatrix}
I & 0 \\
0 & U
\end{pmatrix}
$$
which applies $U$ to target qubit(s) when the control qubit is in state $|1\rangle$.
Both, the conditional statement and the controlled gate use an input that has two values: true
and false
in the former case and $|1\rangle$ and $|0\rangle$ in the latter, to decide between two branches: execute u()
or do nothing in the former case and apply $U$ or identity in the latter case.
One way to generalize a controlled gate to qudits is to mimic the way the conditional statement is generalized to expressions that evaluate to more than two values. In many programming languages this is achieved using the switch statement
switch (expression) {
case 1:
u_1();
break;
case 2:
u_2();
break;
...
case n:
u_n();
break;
}
which executes u_k()
when expression
evaluates to k
.
Quantum counterpart of the switch statement is the quantum multiplexor (see e.g. section 3 in this paper and the answer to this question by @forky40)
$$
U = \begin{pmatrix}
U_1 & 0 & \dots & 0 \\
0 & U_2 & \dots & 0 \\
\vdots & \vdots & & \vdots \\
0 & 0 & \dots & U_n
\end{pmatrix}
$$
which applies unitary $U_k$ to the target subsystem if the control qudit is in state $|k\rangle$ where $k=1,\dots, n$.
Incidentally, this also suggests a quantum generalization of the conditional statement with the else branch:
if (condition) {
u();
} else {
v();
}
which is a two-part multiplexor
$$
W = \begin{pmatrix}
V & 0 \\
0 & U
\end{pmatrix}
$$
that applies $V$ to the target when the control is in state $|0\rangle$ and applies $U$ when the control is in state $|1\rangle$.