18
$\begingroup$

Quantum cNOT Gate (Classical XOR Gate)

A "Controlled NOT (cNOT) Gate" flips the 2nd qubit if the 1st qubit is $\left|1\right>$, and returns the 2nd qubit as-is if the 1st qubit is $\left|0\right>$. The 1st qubit is simply not changed.

The net effect of this gate is a classical XOR gate:

  • It keeps the 1st qubit unchanged
  • It outputs "the 1st qubit XOR the 2nd qubit" as the result of the 2nd qubit

In table form, the function looks like:

$$ \begin{array}{|c|c|} \hline \text{Input} & \text{Output} \\ \hline \begin{array}{cc}0 & 0\end{array} & \begin{array}{cc}0 & 0\end{array} \\ \hline \begin{array}{cc}0 & 1\end{array} & \begin{array}{cc}0 & 1\end{array} \\ \hline \begin{array}{cc}1 & 0\end{array} & \begin{array}{cc}1 & \color{red}{1}\end{array} \\ \hline \begin{array}{cc}1 & 1\end{array} & \begin{array}{cc}1 & \color{red}{0}\end{array} \\ \hline \end{array} $$

Therefore, an input:

$$\alpha\left|00\right>+\beta\left|01\right>+\gamma\left|10\right>+\delta\left|11\right>$$

is mapped to:

$$\alpha\left|00\right>+\beta\left|01\right>+\gamma\left|1\color{red}{1}\right>+\delta\left|1\color{red}{0}\right>$$

Or, in other words:

$$\alpha\left|00\right>+\beta\left|01\right>+\color{red}{\delta}\left|10\right>+\color{red}{\gamma}\left|11\right>$$

In matrix form, we need to find the all the $a_{ij}$'s that satisfy the following:

$$ \begin{pmatrix} a_{11} & a_{12} & a_{13} & a_{14} \\ a_{21} & a_{22} & a_{23} & a_{24} \\ a_{31} & a_{32} & a_{33} & a_{34} \\ a_{41} & a_{42} & a_{43} & a_{44} \\ \end{pmatrix} \cdot \begin{pmatrix} \alpha \\ \beta \\ \gamma \\ \delta \\ \end{pmatrix} = \begin{pmatrix} \alpha \\ \beta \\ \color{red}{\delta} \\ \color{red}{\gamma} \\ \end{pmatrix} $$

It is trivial to find the solution:

$$ \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \color{red}{0} & \color{red}{1} \\ 0 & 0 & \color{red}{1} & \color{red}{0} \\ \end{pmatrix} \cdot \begin{pmatrix} \alpha \\ \beta \\ \gamma \\ \delta \\ \end{pmatrix} = \begin{pmatrix} \alpha \\ \beta \\ \color{red}{\delta} \\ \color{red}{\gamma} \\ \end{pmatrix} $$


Quantum AND Gate?

Similarly, if there exists a gate that mimics the classical AND gate, it should have the following net effect:

  • It keeps the 1st qubit unchanged
  • It outputs "the 1st qubit AND the 2nd qubit" as the result of the 2nd qubit

In table form, the function looks like:

$$ \begin{array}{|c|c|} \hline \text{Input} & \text{Output} \\ \hline \begin{array}{cc}0 & 0\end{array} & \begin{array}{cc}0 & 0\end{array} \\ \hline \begin{array}{cc}0 & 1\end{array} & \begin{array}{cc}0 & \color{red}{0}\end{array} \\ \hline \begin{array}{cc}1 & 0\end{array} & \begin{array}{cc}1 & 0\end{array} \\ \hline \begin{array}{cc}1 & 1\end{array} & \begin{array}{cc}1 & 1\end{array} \\ \hline \end{array} $$

Therefore, an input:

$$\alpha\left|00\right>+\beta\left|01\right>+\gamma\left|10\right>+\delta\left|11\right>$$

should be mapped to:

$$\alpha\left|00\right>+\beta\left|0\color{red}{0}\right>+\gamma\left|10\right>+\delta\left|11\right>$$

Or, in other words:

$$\color{red}{(\alpha+\beta)}\left|00\right>+\color{red}{0}\left|01\right>+\gamma\left|10\right>+\delta\left|11\right>$$

In matrix form, we need to find the all the $a_{ij}$'s that satisfy the following:

$$ \begin{pmatrix} a_{11} & a_{12} & a_{13} & a_{14} \\ a_{21} & a_{22} & a_{23} & a_{24} \\ a_{31} & a_{32} & a_{33} & a_{34} \\ a_{41} & a_{42} & a_{43} & a_{44} \\ \end{pmatrix} \cdot \begin{pmatrix} \alpha \\ \beta \\ \gamma \\ \delta \\ \end{pmatrix} = \begin{pmatrix} \color{red}{\alpha+\beta} \\ \color{red}{0} \\ \gamma \\ \delta \\ \end{pmatrix} $$

It is trivial to find the solution:

$$ \begin{pmatrix} 1 & \color{red}{1} & 0 & 0 \\ 0 & \color{red}{0} & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ \end{pmatrix} \cdot \begin{pmatrix} \alpha \\ \beta \\ \gamma \\ \delta \\ \end{pmatrix} = \begin{pmatrix} \color{red}{\alpha+\beta} \\ \color{red}{0} \\ \gamma \\ \delta \\ \end{pmatrix} $$


Quantum OR Gate?

Similarly, if there exists a gate that mimics the classical OR gate, it should have the following net effect:

  • It keeps the 1st qubit unchanged
  • It outputs "the 1st qubit OR the 2nd qubit" as the result of the 2nd qubit

In table form, the function looks like:

$$ \begin{array}{|c|c|} \hline \text{Input} & \text{Output} \\ \hline \begin{array}{cc}0 & 0\end{array} & \begin{array}{cc}0 & 0\end{array} \\ \hline \begin{array}{cc}0 & 1\end{array} & \begin{array}{cc}0 & 1\end{array} \\ \hline \begin{array}{cc}1 & 0\end{array} & \begin{array}{cc}1 & \color{red}{1}\end{array} \\ \hline \begin{array}{cc}1 & 1\end{array} & \begin{array}{cc}1 & 1\end{array} \\ \hline \end{array} $$

Therefore, an input:

$$\alpha\left|00\right>+\beta\left|01\right>+\gamma\left|10\right>+\delta\left|11\right>$$

should be mapped to:

$$\alpha\left|00\right>+\beta\left|01\right>+\gamma\left|1\color{red}{1}\right>+\delta\left|11\right>$$

Or, in other words:

$$\alpha\left|00\right>+\beta\left|01\right>+\color{red}{0}\left|10\right>+\color{red}{(\gamma+\delta)}\left|11\right>$$

In matrix form, we need to find the all the $a_{ij}$'s that satisfy the following:

$$ \begin{pmatrix} a_{11} & a_{12} & a_{13} & a_{14} \\ a_{21} & a_{22} & a_{23} & a_{24} \\ a_{31} & a_{32} & a_{33} & a_{34} \\ a_{41} & a_{42} & a_{43} & a_{44} \\ \end{pmatrix} \cdot \begin{pmatrix} \alpha \\ \beta \\ \gamma \\ \delta \\ \end{pmatrix} = \begin{pmatrix} \alpha \\ \beta \\ \color{red}{0} \\ \color{red}{\gamma+\delta} \\ \end{pmatrix} $$

It is trivial to find the solution:

$$ \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \color{red}{0} & 0 \\ 0 & 0 & \color{red}{1} & 1 \\ \end{pmatrix} \cdot \begin{pmatrix} \alpha \\ \beta \\ \gamma \\ \delta \\ \end{pmatrix} = \begin{pmatrix} \alpha \\ \beta \\ \color{red}{0} \\ \color{red}{\gamma+\delta} \\ \end{pmatrix} $$


However, since:

$$ A = \begin{pmatrix} 1 & \color{red}{1} & 0 & 0 \\ 0 & \color{red}{0} & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ \end{pmatrix} $$

and

$$ B = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \color{red}{0} & 0 \\ 0 & 0 & \color{red}{1} & 1 \\ \end{pmatrix} $$

are not unitary matrices, as shown by $\det(A) = \det(B) = 0 \ne 1$, they could not be implemented directly as a quantum logic gate.

I have read the answer here:

If quantum gates are reversible how can they possibly perform irreversible classical AND and OR operations?

but it is not intuitive enough for me:

  • to understand what the final solution is; and
  • to visualize how it achieves the same result as the matrix $A$ and $B$ above.

Does anyone have any idea on how to implement "Classical AND" and "Classical OR" with an explanation in matrix form? Thanks!

$\endgroup$
5
  • 2
    $\begingroup$ You need to use an ancilla qubit and find an 8x8 unitary instead. See the section on "arbitrary boolean functions" here. $\endgroup$ Commented Apr 1, 2019 at 17:25
  • $\begingroup$ @Blue Thanks! In fact I have already read Wikipedia before asking the question, and I am reading the link you posted in your previous comment (the same as the recent comment). $\endgroup$ Commented Apr 1, 2019 at 17:28
  • 2
    $\begingroup$ You don't need to do anything fancy to get back a AND b I think. Just set it as 0 initially. 0 XOR 0 is 0, and 0 XOR 1 is 1. That is, c XOR (a AND b) = a AND b if you take c as 0. Basically, set the ancillary qubit to $|0\rangle$ initially, and you'll get required output at the third "wire". $\endgroup$ Commented Apr 1, 2019 at 17:43
  • 1
    $\begingroup$ From here and here, I know that Toffoli gate maps the input {a, b, c} to {a, b, c XOR (a AND b). To get back (a AND b), we can do a XOR c to the result. However, since the output is at the wire c, and qubits could not be copied, how could I do a XOR c after that? Let's say if we set $c=\left|0\right>$, can we use another qubit $d=\left|0\right>$ instead of c, and do a XOR d to get the same result? $\endgroup$ Commented Apr 1, 2019 at 17:49
  • 1
    $\begingroup$ @Blue : Oh yes... I got it now... Too silly to overlook that 0 XOR x = x for any x. Thank you so much! $\endgroup$ Commented Apr 1, 2019 at 17:54

4 Answers 4

14
$\begingroup$

Your construction by gueswork in this answer is OK but not really elegant. Moreover, it's a convention to start in the state $|0\rangle$; we usually don't initialize a qubit with the state $|1\rangle$. It's better to follow the general construction which I illustrate here.


The idea here is to use ancillary qubits and impose unitary evolution on the larger system instead i.e. by treating the two-qubit system as a subsystem. There's a general method for constructing such gates. Essentially, you are trying to construct a quantum gate that'll perform a Boolean mapping like $f: \{0, 1\}^n \longrightarrow \{0, 1\}$. You've noted that for $n=2$ (two qubits), you cannot constructing unitary gates corresponding to some classical operations like the AND and OR as there's a rank deficiency (this happens precisely because those classical operations are irreversible). So we'll try with $n=3$ instead. Let's take the example of the quantum OR gate, which would perform the mapping $$|a \ b \ c\rangle \mapsto |a \ b \ c\oplus(a+b)\rangle$$ where $a,b,c \in \{0,1\}$. By the way, $\oplus$ here stands for XOR and $+$ stands for OR. You do know that $0 \oplus x = x$ for any $x \in \{0,1\}$? Otherwise, check the XOR table. Thus, if we set the additional qubit to $|0\rangle$ initially, it boils down to $$|a \ b \ 0\rangle \mapsto |a \ b \ a+b\rangle.$$

Let's construct the table now.

$$\begin{array}{|c c c|c c c|} \hline a & b & c & a & b & c\oplus (a+b) \\ \hline 0 & 0 & \color{red}{0} & 0 & 0 & \color{red}{0} \\ \hline 0 & 0 & 1 & 0 & 0 & 1 \\ \hline 0 & 1 & \color{red}{0} & 0 & 1 & \color{red}{1} \\ \hline 0 & 1 & 1 & 0 & 1 & 0 \\ \hline 1 & 0 & \color{red}{0} & 1 & 0 & \color{red}{1} \\ \hline 1 & 0 & 1 & 1 & 0 & 0 \\ \hline 1 & 1 & \color{red}{0} & 1 & 1 & \color{red}{1} \\ \hline 1 & 1 & 1 & 1 & 1 & 0 \\ \hline \end{array}$$

We're only only concerned with the cases where $c=0$ i.e. the ones marked in red. Half done now! If we translate this to mapping of the computational basis vectors of the three-qubit system, we get

$$|000\rangle \mapsto |000\rangle \equiv [1 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0]^T \mapsto \color{blue}{[1 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0]^T}$$ $$|001\rangle \mapsto |001\rangle \equiv [0 \ 1 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0]^T \mapsto \color{brown}{[0 \ 1 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0]^T}$$ $$|010\rangle \mapsto |011\rangle \equiv [0 \ 0 \ 1 \ 0 \ 0 \ 0 \ 0 \ 0]^T \mapsto \color{teal}{[0 \ 0 \ 0 \ 1 \ 0 \ 0 \ 0 \ 0]^T}$$ $$|011\rangle \mapsto |010\rangle \equiv [0 \ 0 \ 0 \ 1 \ 0 \ 0 \ 0 \ 0]^T \mapsto \color{violet}{[0 \ 0 \ 1 \ 0 \ 0 \ 0 \ 0 \ 0]^T}$$ $$|100\rangle \mapsto |101\rangle \equiv [0 \ 0 \ 0 \ 0 \ 1 \ 0 \ 0 \ 0]^T \mapsto \color{green}{[0 \ 0 \ 0 \ 0 \ 0 \ 1 \ 0 \ 0]^T}$$ $$|101\rangle \mapsto |100\rangle \equiv [0 \ 0 \ 0 \ 0 \ 0 \ 1 \ 0 \ 0]^T \mapsto \color{magenta}{[0 \ 0 \ 0 \ 0 \ 1 \ 0 \ 0 \ 0]^T}$$ $$|110\rangle \mapsto |111\rangle \equiv [0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 1 \ 0]^T \mapsto \color{orange}{[0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 1]^T}$$ $$|111\rangle \mapsto |110\rangle \equiv [0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 1]^T \mapsto \color{purple}{[0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 1 \ 0]^T}$$

The columns vectors highlighted in blue will the columns of the required matrix cf. change of basis transformation matrix. The matrix is certainly unitary as basis vectors are simply getting mapped to basis vectors, and the mapping is bijective.

$$\color{red}{\text{quantum OR}} = \begin{pmatrix} {\color{blue} 1} & {\color{brown} 0} & {\color{teal} 0} & {\color{violet} 0} & {\color{green} 0} & {\color{magenta} 0} & {\color{orange} 0} & {\color{purple} 0} \\ {\color{blue} 0} & {\color{brown} 1} & {\color{teal} 0} & {\color{violet} 0} & {\color{green} 0} & {\color{magenta} 0} & {\color{orange} 0} & {\color{purple} 0} \\ {\color{blue} 0} & {\color{brown} 0} & {\color{teal} 0} & {\color{violet} 1} & {\color{green} 0} & {\color{magenta} 0} & {\color{orange} 0} & {\color{purple} 0} \\ {\color{blue} 0} & {\color{brown} 0} & {\color{teal} 1} & {\color{violet} 0} & {\color{green} 0} & {\color{magenta} 0} & {\color{orange} 0} & {\color{purple} 0} \\ {\color{blue} 0} & {\color{brown} 0} & {\color{teal} 0} & {\color{violet} 0} & {\color{green} 0} & {\color{magenta} 1} & {\color{orange} 0} & {\color{purple} 0} \\ {\color{blue} 0} & {\color{brown} 0} & {\color{teal} 0} & {\color{violet} 0} & {\color{green} 1} & {\color{magenta} 0} & {\color{orange} 0} & {\color{purple} 0} \\ {\color{blue} 0} & {\color{brown} 0} & {\color{teal} 0} & {\color{violet} 0} & {\color{green} 0} & {\color{magenta} 0} & {\color{orange} 0} & {\color{purple} 1} \\ {\color{blue} 0} & {\color{brown} 0} & {\color{teal} 0} & {\color{violet} 0} & {\color{green} 0} & {\color{magenta} 0} & {\color{orange} 1} & {\color{purple} 0} \\ \end{pmatrix} $$

Calculate the determinant and convince yourself that it's unitary.

Exercise:

  1. Use the method demonstrated here to construct the quantum gates corresponding to the classical NAND, NOR and XNOR gates.

  2. Prove that the mapping defined by $(a,b,c)\mapsto (a, b, c\oplus f(a,b))$ is one-one and onto, where $f$ is any arbitrary Boolean function of $a$ and $b$.

$\endgroup$
2
8
$\begingroup$

Simulating Classical "AND/NAND/OR/NOR/XOR/XNOR" Gates

With the help of this answer from Blue, constructing a matrix for a classical gate is just a matter of following the steps.

Here is the combined truth table for classical logic gates:

$$ \begin{array}{|c|c|c|c|c|c|c|} \hline \text{Input} & \text{AND} & \text{NAND} & \text{OR} & \text{NOR} & \text{XOR} & \text{XNOR} \\ \hline \begin{array}{cc}0 & 0\end{array} & 0 & 1 & 0 & 1 & 0 & 1 \\ \hline \begin{array}{cc}0 & 1\end{array} & 0 & 1 & 1 & 0 & 1 & 0 \\ \hline \begin{array}{cc}1 & 0\end{array} & 0 & 1 & 1 & 0 & 1 & 0 \\ \hline \begin{array}{cc}1 & 1\end{array} & 1 & 0 & 1 & 0 & 0 & 1 \\ \hline \end{array} $$

It could be seen that since the output of AND, NAND, OR, and XOR do not have equal number of 0's and 1's, they need an ancilla bit. For XOR and XNOR, no ancilla bit is needed.

Below is a table for the mappings and matrices.

The light color mappings represent mappings that are "not used", since the ancilla bit is always prepared to be $\left|0\right>$ by convention.

A color tone groups a pair of mapping swap, which is necessary to achieve reversibility and keep the matrix a unitary matrix.

$$ \begin{array}{|c|c|} \hline \text{Gate} & \text{Mapping} & \text{Matrix} \\ \hline \text{AND} & \begin{array}{} \left|000\right> \mapsto \left|000\right> \\ \color{#999}{\left|001\right> \mapsto \left|001\right>} \\ \left|010\right> \mapsto \left|010\right> \\ \color{#999}{\left|011\right> \mapsto \left|011\right>} \\ \left|100\right> \mapsto \left|100\right> \\ \color{#999}{\left|101\right> \mapsto \left|101\right>} \\ \left|110\right> \mapsto \color{#f00}{\left|111\right>} \\ \color{#999}{\left|111\right> \mapsto \color{#f99}{\left|110\right>}} \\ \end{array} & \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & \color{#f00}{0} & \color{#f00}{1} \\ 0 & 0 & 0 & 0 & 0 & 0 & \color{#f00}{1} & \color{#f00}{0} \\ \end{pmatrix} \\ \hline \text{NAND} & \begin{array}{} \left|000\right> \mapsto \color{#f00}{\left|001\right>} \\ \color{#999}{\left|001\right> \mapsto \color{#f99}{\left|000\right>}} \\ \left|010\right> \mapsto \color{#0b5}{\left|011\right>} \\ \color{#999}{\left|011\right> \mapsto \color{#7b9}{\left|010\right>}} \\ \left|100\right> \mapsto \color{#07c}{\left|101\right>} \\ \color{#999}{\left|101\right> \mapsto \color{#7ac}{\left|100\right>}} \\ \left|110\right> \mapsto \left|110\right> \\ \color{#999}{\left|111\right> \mapsto \left|111\right>} \\ \end{array} & \begin{pmatrix} \color{#f00}{0} & \color{#f00}{1} & 0 & 0 & 0 & 0 & 0 & 0 \\ \color{#f00}{1} & \color{#f00}{0} & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & \color{#0b5}{0} & \color{#0b5}{1} & 0 & 0 & 0 & 0 \\ 0 & 0 & \color{#0b5}{1} & \color{#0b5}{0} & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & \color{#07c}{0} & \color{#07c}{1} & 0 & 0 \\ 0 & 0 & 0 & 0 & \color{#07c}{1} & \color{#07c}{0} & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ \end{pmatrix} \\ \hline \text{OR} & \begin{array}{} \left|000\right> \mapsto \left|000\right> \\ \color{#999}{\left|001\right> \mapsto \left|001\right>} \\ \left|010\right> \mapsto \color{#f00}{\left|011\right>} \\ \color{#999}{\left|011\right> \mapsto \color{#f99}{\left|010\right>}} \\ \left|100\right> \mapsto \color{#0b5}{\left|101\right>} \\ \color{#999}{\left|101\right> \mapsto \color{#7b9}{\left|100\right>}} \\ \left|110\right> \mapsto \color{#07c}{\left|111\right>} \\ \color{#999}{\left|111\right> \mapsto \color{#7ac}{\left|110\right>}} \\ \end{array} & \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & \color{#f00}{0} & \color{#f00}{1} & 0 & 0 & 0 & 0 \\ 0 & 0 & \color{#f00}{1} & \color{#f00}{0} & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & \color{#0b5}{0} & \color{#0b5}{1} & 0 & 0 \\ 0 & 0 & 0 & 0 & \color{#0b5}{1} & \color{#0b5}{0} & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & \color{#07c}{0} & \color{#07c}{1} \\ 0 & 0 & 0 & 0 & 0 & 0 & \color{#07c}{1} & \color{#07c}{0} \\ \end{pmatrix} \\ \hline \text{NOR} & \begin{array}{} \left|000\right> \mapsto \color{#f00}{\left|001\right>} \\ \color{#999}{\left|001\right> \color{#f99}{\mapsto \left|000\right>}} \\ \left|010\right> \mapsto \left|010\right> \\ \color{#999}{\left|011\right> \mapsto \left|011\right>} \\ \left|100\right> \mapsto \left|100\right> \\ \color{#999}{\left|101\right> \mapsto \left|101\right>} \\ \left|110\right> \mapsto \left|110\right> \\ \color{#999}{\left|111\right> \mapsto \left|111\right>} \\ \end{array} & \begin{pmatrix} \color{#f00}{0} & \color{#f00}{1} & 0 & 0 & 0 & 0 & 0 & 0 \\ \color{#f00}{1} & \color{#f00}{0} & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ \end{pmatrix} \\ \hline \text{XOR} & \begin{array}{} \left|00\right> \mapsto \left|00\right> \\ \left|01\right> \mapsto \left|01\right> \\ \left|10\right> \mapsto \color{#f00}{\left|11\right>} \\ \left|11\right> \mapsto \color{#f00}{\left|10\right>} \\ \end{array} & \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \color{#f00}{0} & \color{#f00}{1} \\ 0 & 0 & \color{#f00}{1} & \color{#f00}{0} \\ \end{pmatrix} \\ \hline \text{XNOR} & \begin{array}{} \left|00\right> \mapsto \color{#f00}{\left|01\right>} \\ \left|01\right> \mapsto \color{#f00}{\left|00\right>} \\ \left|10\right> \mapsto \left|10\right> \\ \left|11\right> \mapsto \left|11\right> \\ \end{array} & \begin{pmatrix} \color{#f00}{0} & \color{#f00}{1} & 0 & 0 \\ \color{#f00}{1} & \color{#f00}{0} & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ \end{pmatrix} \\ \hline \end{array} $$

$\endgroup$
3
$\begingroup$

Simulating "Classical AND Gate" using "Toffoli Gate" (also known as "Controlled-Controlled-NOT Gate", or "CCNOT Gate")

With the help of Blue's comment, and the Wikipedia pages here and here, a solution to simulating classical AND gate was found.

The CCNOT gate is a 3-qubit gate having the following properties:

  • If both the 1st and 2nd inputs are $\left|1\right>$, then it flips the 3rd input while keeping the 1st and 2nd inputs unchanged;
  • Otherwise, it keeps all inputs unchanged.

The net effect of this gate is:

  • It keeps the 1st qubit unchanged;
  • It keeps the 2nd qubit unchanged;
  • It outputs "the 3rd qubit XOR (the 1st qubit AND the 2nd qubit)" as the result of the 3rd qubit.

In table form, the function looks like:

$$ \begin{array}{|c|c|} \hline \text{Input} & \text{Output} \\ \hline \begin{array}{ccc}0 & 0 & 0\end{array} & \begin{array}{ccc}0 & 0 & 0\end{array} \\ \hline \begin{array}{ccc}0 & 0 & 1\end{array} & \begin{array}{ccc}0 & 0 & 1\end{array} \\ \hline \begin{array}{ccc}0 & 1 & 0\end{array} & \begin{array}{ccc}0 & 1 & 0\end{array} \\ \hline \begin{array}{ccc}0 & 1 & 1\end{array} & \begin{array}{ccc}0 & 1 & 1\end{array} \\ \hline \begin{array}{ccc}1 & 0 & 0\end{array} & \begin{array}{ccc}1 & 0 & 0\end{array} \\ \hline \begin{array}{ccc}1 & 0 & 1\end{array} & \begin{array}{ccc}1 & 0 & 1\end{array} \\ \hline \begin{array}{ccc}1 & 1 & 0\end{array} & \begin{array}{ccc}1 & 1 & \color{red}{1}\end{array} \\ \hline \begin{array}{ccc}1 & 1 & 1\end{array} & \begin{array}{ccc}1 & 1 & \color{red}{0}\end{array} \\ \hline \end{array} $$

In matrix form, it looks like:

$$ \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & \color{red}{0} & \color{red}{1} \\ 0 & 0 & 0 & 0 & 0 & 0 & \color{red}{1} & \color{red}{0} \\ \end{pmatrix} $$

If we want to calculate $\left|x\right>$ AND $\left|y\right>$, we can:

  • Prepare the 1st input to be $\left|x\right>$;
  • Prepare the 2nd input to be $\left|y\right>$;
  • Prepare the 3rd input to be $\left|0\right>$.

Since we prepare the 3rd input to be $\left|0\right>$ on purpose, we can just ignore the cases where the 3rd input is $\left|1\right>$. By removing all the rows containing a $1$ in the 3rd input (i.e. the 2nd, 4th, 6th, 8th row) from the table above, it becomes:

$$ \begin{array}{|c|c|} \hline \text{Input} & \text{Output} \\ \hline \begin{array}{ccc}0 & 0 & 0\end{array} & \begin{array}{ccc}0 & 0 & 0\end{array} \\ \hline \begin{array}{ccc}0 & 1 & 0\end{array} & \begin{array}{ccc}0 & 1 & 0\end{array} \\ \hline \begin{array}{ccc}1 & 0 & 0\end{array} & \begin{array}{ccc}1 & 0 & 0\end{array} \\ \hline \begin{array}{ccc}1 & 1 & 0\end{array} & \begin{array}{ccc}1 & 1 & \color{red}{1}\end{array} \\ \hline \end{array} $$

The net effect of the gate in this setting is:

  • It keeps the 1st qubit unchanged;
  • It keeps the 2nd qubit unchanged;
  • It outputs "the 3rd qubit XOR (the 1st qubit AND the 2nd qubit)" as the result of the 3rd qubit, since "0 XOR x = x" for any "x".

If we just look at the 1st input, the 2nd input, and the 3rd output, the table is exactly the same as the classical AND gate:

$$ \begin{array}{|c|c|} \hline \text{Input} & \text{Output} \\ \hline \begin{array}{cc}0 & 0\end{array} & 0 \\ \hline \begin{array}{cc}0 & 1\end{array} & 0 \\ \hline \begin{array}{cc}1 & 0\end{array} & 0 \\ \hline \begin{array}{cc}1 & 1\end{array} & \color{red}{1} \\ \hline \end{array} $$

$\endgroup$
1
  • $\begingroup$ @Blue Thanks! I am improving my wordings and thinking about the solution for OR right now. $\endgroup$ Commented Apr 1, 2019 at 18:43
1
$\begingroup$

Simulating "Classical OR Gate"

Please read my answer for simulating "Classical AND Gate" in this post first.

In this answer, I am going to use another approach to reach the solution. Let's begin with the table for classical OR gate:

$$ \begin{array}{|c|c|} \hline \text{Input} & \text{Output} \\ \hline \begin{array}{cc}0 & 0\end{array} & 0 \\ \hline \begin{array}{cc}0 & 1\end{array} & 1 \\ \hline \begin{array}{cc}1 & 0\end{array} & 1 \\ \hline \begin{array}{cc}1 & 1\end{array} & 1 \\ \hline \end{array} $$

As discussed in the comment section of the question, it is impossible for any 2-qubit quantum gate to simulate a classical OR gate - an ancilla bit is needed to do so.

Let's see the table for the 3-qubit identity gate:

$$ \begin{array}{|c|c|} \hline \text{Input} & \text{Output} \\ \hline \begin{array}{ccc}0 & 0 & 0\end{array} & \begin{array}{ccc}0 & 0 & 0\end{array} \\ \hline \begin{array}{ccc}0 & 0 & 1\end{array} & \begin{array}{ccc}0 & 0 & 1\end{array} \\ \hline \begin{array}{ccc}0 & 1 & 0\end{array} & \begin{array}{ccc}0 & 1 & 0\end{array} \\ \hline \begin{array}{ccc}0 & 1 & 1\end{array} & \begin{array}{ccc}0 & 1 & 1\end{array} \\ \hline \begin{array}{ccc}1 & 0 & 0\end{array} & \begin{array}{ccc}1 & 0 & 0\end{array} \\ \hline \begin{array}{ccc}1 & 0 & 1\end{array} & \begin{array}{ccc}1 & 0 & 1\end{array} \\ \hline \begin{array}{ccc}1 & 1 & 0\end{array} & \begin{array}{ccc}1 & 1 & 0\end{array} \\ \hline \begin{array}{ccc}1 & 1 & 1\end{array} & \begin{array}{ccc}1 & 1 & 1\end{array} \\ \hline \end{array} $$

Let's assume the solution to be similar to that of classical AND gate - if we want to calculate $\left|x\right>$ OR $\left|y\right>$, we can:

  • Prepare the 1st input to be $\left|x\right>$;
  • Prepare the 2nd input to be $\left|y\right>$;
  • $\color{red}{\text{Prepare the 3rd input to be some value}}$.

Let's separate the table above by rows having $\left|0\right>$ as the 3rd input, and rows having $\left|1\right>$ as the 3rd input:

$$ \begin{array}{cc} \begin{array}{|c|c|} \hline \text{Input} & \text{Output} \\ \hline \begin{array}{ccc}0 & 0 & 0\end{array} & \begin{array}{ccc}0 & 0 & 0\end{array} \\ \hline \begin{array}{ccc}0 & 1 & 0\end{array} & \begin{array}{ccc}0 & 1 & 0\end{array} \\ \hline \begin{array}{ccc}1 & 0 & 0\end{array} & \begin{array}{ccc}1 & 0 & 0\end{array} \\ \hline \begin{array}{ccc}1 & 1 & 0\end{array} & \begin{array}{ccc}1 & 1 & 0\end{array} \\ \hline \end{array} & \begin{array}{|c|c|} \hline \text{Input} & \text{Output} \\ \hline \begin{array}{ccc}0 & 0 & 1\end{array} & \begin{array}{ccc}0 & 0 & 1\end{array} \\ \hline \begin{array}{ccc}0 & 1 & 1\end{array} & \begin{array}{ccc}0 & 1 & 1\end{array} \\ \hline \begin{array}{ccc}1 & 0 & 1\end{array} & \begin{array}{ccc}1 & 0 & 1\end{array} \\ \hline \begin{array}{ccc}1 & 1 & 1\end{array} & \begin{array}{ccc}1 & 1 & 1\end{array} \\ \hline \end{array} \\ \end{array} $$

It is trivial to see that the table on the right looks more similar to the classical OR gate, and thus is a better starting point. Therefore, we choose to $\color{red}{\text{prepare the 3rd input to be} \left|1\right>}$.

Since it is not possible to modify just one entry in the table to make a valid quantum gate - the resulting matrix will not be a unitary matrix, we need to pair it up and swap the values with another entry:

$$ \begin{array}{cc} \begin{array}{|c|c|} \hline \text{Input} & \text{Output} \\ \hline \begin{array}{ccc}0 & 0 & 0\end{array} & \begin{array}{ccc}0 & 0 & \color{red}{1}\end{array} \\ \hline \begin{array}{ccc}0 & 1 & 0\end{array} & \begin{array}{ccc}0 & 1 & 0\end{array} \\ \hline \begin{array}{ccc}1 & 0 & 0\end{array} & \begin{array}{ccc}1 & 0 & 0\end{array} \\ \hline \begin{array}{ccc}1 & 1 & 0\end{array} & \begin{array}{ccc}1 & 1 & 0\end{array} \\ \hline \end{array} & \begin{array}{|c|c|} \hline \text{Input} & \text{Output} \\ \hline \begin{array}{ccc}0 & 0 & 1\end{array} & \begin{array}{ccc}0 & 0 & \color{red}{0}\end{array} \\ \hline \begin{array}{ccc}0 & 1 & 1\end{array} & \begin{array}{ccc}0 & 1 & 1\end{array} \\ \hline \begin{array}{ccc}1 & 0 & 1\end{array} & \begin{array}{ccc}1 & 0 & 1\end{array} \\ \hline \begin{array}{ccc}1 & 1 & 1\end{array} & \begin{array}{ccc}1 & 1 & 1\end{array} \\ \hline \end{array} \\ \end{array} $$

Merging them back into one table, we get:

$$ \begin{array}{|c|c|} \hline \text{Input} & \text{Output} \\ \hline \begin{array}{ccc}0 & 0 & 0\end{array} & \begin{array}{ccc}0 & 0 & \color{red}{1}\end{array} \\ \hline \begin{array}{ccc}0 & 0 & 1\end{array} & \begin{array}{ccc}0 & 0 & \color{red}{0}\end{array} \\ \hline \begin{array}{ccc}0 & 1 & 0\end{array} & \begin{array}{ccc}0 & 1 & 0\end{array} \\ \hline \begin{array}{ccc}0 & 1 & 1\end{array} & \begin{array}{ccc}0 & 1 & 1\end{array} \\ \hline \begin{array}{ccc}1 & 0 & 0\end{array} & \begin{array}{ccc}1 & 0 & 0\end{array} \\ \hline \begin{array}{ccc}1 & 0 & 1\end{array} & \begin{array}{ccc}1 & 0 & 1\end{array} \\ \hline \begin{array}{ccc}1 & 1 & 0\end{array} & \begin{array}{ccc}1 & 1 & 0\end{array} \\ \hline \begin{array}{ccc}1 & 1 & 1\end{array} & \begin{array}{ccc}1 & 1 & 1\end{array} \\ \hline \end{array} $$

Then it is trivial to see the matrix is:

$$ \begin{pmatrix} \color{red}{0} & \color{red}{1} & 0 & 0 & 0 & 0 & 0 & 0 \\ \color{red}{1} & \color{red}{0} & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ \end{pmatrix} $$

It is easy to show that the matrix above is unitary.

P.S.: I don't know if there is a name for this quantum gate, or how it could be written in terms of other named gates.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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