|
13 | 13 | "cell_type": "markdown",
|
14 | 14 | "metadata": {},
|
15 | 15 | "source": [
|
16 |
| - "We have a function which takes in a bit and outputs a bit. This can be represented as $f: \\{0,1\\} \\longrightarrow \\{0,1\\}$. \n", |
| 16 | + "Deutsch's Algorithm is a concise demonstration of the differences in computational complexity between classical and quantum algorithms for certain problems. For Desutch's algorithm, we begin with a function which takes in a bit and outputs a bit. This can be represented as $f: \\{0,1\\} \\longrightarrow \\{0,1\\}$. \n", |
| 17 | + "The function $f$ has the property that it either constant or balanced. The goal of Deutsch's Algorithm is to determine whether our given function is constant or whether it is balanced. \n", |
17 | 18 | "\n",
|
18 |
| - "The function $f$ has a property; either it is constant or balanced. \n", |
| 19 | + "A constant function is \"A balanced function is a function such that the outputs are the same regardless of the inputs, i.e., if $f(0) = 0$ then $f(1) = 1$ or if $f(0) = 1$ then $f(1) = 0$.\n\", the outputs are the same regardless of the inputs, i.e., in the case of $f: \\{0,1\\} \\longrightarrow \\{0,1\\}$, there are are two ways in which this can occur: $f(0) = f(1) = 0$ or $f(0) = f(1) = 1$.\n", |
19 | 20 | "\n",
|
20 |
| - "If constant, the outputs are the same regardless of the inputs, i.e., $f(0) = f(1) = 0$ or $f(0) = f(1) = 1$.\n", |
21 |
| - "\n", |
22 |
| - "If balanced, the ouputs are balanced across their possibilities, i.e, if $f(0) = 0$ then $f(1) = 1$ or if $f(0) = 1$ then $f(1) = 0$.\n", |
23 |
| - "\n", |
24 |
| - "The question we would like to answer is if the function is constant or balanced. \n", |
| 21 | + "A balanced function is defined such that the ouputs are balanced across their possibilities, i.e., if $f(0) = 0$ then $f(1) = 1$ or if $f(0) = 1$ then $f(1) = 0$.\n", |
25 | 22 | " \n",
|
26 |
| - "Classically, if we are given a function $f$, we can solve to find its property via the code below: \n" |
| 23 | + "Classically, if we are given a function $f: \\{0,1\\} \\longrightarrow \\{0,1\\}$, we can determine if it is constant or balanced by evaluating the function at $0$ and at $1$. This is carried out in the code below: \n" |
27 | 24 | ]
|
28 | 25 | },
|
29 | 26 | {
|
|
96 | 93 | "cell_type": "markdown",
|
97 | 94 | "metadata": {},
|
98 | 95 | "source": [
|
99 |
| - "If you step through the `if` statements above, one can see that we require 2 calls to the function to determine its property. That is, we have to query $f$ twice.\n", |
| 96 | + "If you step through the `if` statements above, you may notice that we require 2 calls to the function to determine its property. That is, we have to query $f$ twice.\n", |
100 | 97 | "\n",
|
101 |
| - "The claim is that Deutsch's algorithm can solve for this property with 1 function evalulation, demonstrating quantum advantage. \n", |
| 98 | + "The claim is that Deutsch's Algorithm can determine if a given function is constant or balanced with just 1 function evalulation, demonstrating quantum advantage. \n", |
102 | 99 | "\n",
|
103 |
| - "Below we first go through the math and then the implementation in CUDA Quantum. \n", |
| 100 | + "Below we first outline Deutsch's Algorithm and work through the math to verify that it does as promised. Then, we provide the implementation in CUDA-Q. \n", |
104 | 101 | "\n"
|
105 | 102 | ]
|
106 | 103 | },
|
|
130 | 127 | "\n",
|
131 | 128 | "<img src=\"images/oracle.png\" width=\"300\" height=\"150\">\n",
|
132 | 129 | "\n",
|
133 |
| - "Suppose we have $f(x): \\{0,1\\} \\longrightarrow \\{0,1\\}$. We can compute this function on a quantum computer using oracles which we treat as black box functions that yield the output with an appropriate sequence of logic gates. \n", |
| 130 | + "Suppose we have $f(x): \\{0,1\\} \\longrightarrow \\{0,1\\}$. We can compute this function on a quantum computer using oracles which we treat as black box functions that yield the output with an appropriate sequence of logical gates. \n", |
134 | 131 | "\n",
|
135 | 132 | "Above you see an oracle represented as $U_f$ which allows us to transform the state $\\ket{x}\\ket{y}$ into: \n",
|
136 | 133 | "\n",
|
|
140 | 137 | "\\end{aligned}\n",
|
141 | 138 | "$$\n",
|
142 | 139 | "\n",
|
143 |
| - "If $y = 0$, then $U_f\\ket{x}\\ket{y} = U_f\\ket{x}\\ket{0} = \\ket{x}\\ket{0 \\oplus f(x)} = \\ket{x}\\ket{f(x)}$ since $f(x)$ can either be $0/1$ and $0 \\oplus 0 = 0$ and $0 \\oplus 1 = 1$.\n", |
| 140 | + "If $y = 0$, then $U_f\\ket{x}\\ket{y} = U_f\\ket{x}\\ket{0} = \\ket{x}\\ket{0 \\oplus f(x)} = \\ket{x}\\ket{f(x)}$, since $f(x)$ can either be $0$ or $1$ and $0 \\oplus 0 = 0$ and $0 \\oplus 1 = 1$.\n", |
144 | 141 | "\n",
|
145 | 142 | "This is remarkable because by setting $\\ket{y} = \\ket{0}$, we can extract the value of $f(x)$ by measuring the value of the second qubit. \n",
|
146 | 143 | " \n",
|
|
213 | 210 | "cell_type": "markdown",
|
214 | 211 | "metadata": {},
|
215 | 212 | "source": [
|
216 |
| - "## Deutschs' Algorithm: \n", |
| 213 | + "## Deutsch's Algorithm: \n", |
217 | 214 | "\n",
|
218 | 215 | "Our aim is to find out if $f: \\{0,1\\} \\longrightarrow \\{0,1\\}$ is a constant or a balanced function? If constant, $f(0) = f(1)$, and if balanced, $f(0) \\neq f(1)$.\n",
|
219 | 216 | "\n",
|
|
296 | 293 | },
|
297 | 294 | {
|
298 | 295 | "cell_type": "code",
|
299 |
| - "execution_count": 3, |
| 296 | + "execution_count": null, |
300 | 297 | "metadata": {},
|
301 |
| - "outputs": [ |
302 |
| - { |
303 |
| - "name": "stderr", |
304 |
| - "output_type": "stream", |
305 |
| - "text": [ |
306 |
| - "/usr/local/lib/python3.10/dist-packages/qutip/__init__.py:66: UserWarning: The new version of Cython, (>= 3.0.0) is not supported.\n", |
307 |
| - " warnings.warn(\n" |
308 |
| - ] |
309 |
| - } |
310 |
| - ], |
| 298 | + "outputs": [], |
311 | 299 | "source": [
|
312 | 300 | "# Import the CUDA-Q package and set the target to run on NVIDIA GPUs.\n",
|
313 | 301 | "\n",
|
|
391 | 379 | "elif np.array(result)[0] == '1':\n",
|
392 | 380 | " print('f(x) is a balanced function')"
|
393 | 381 | ]
|
| 382 | + }, |
| 383 | + { |
| 384 | + "cell_type": "markdown", |
| 385 | + "metadata": {}, |
| 386 | + "source": [ |
| 387 | + "This algorithm can be generalized to determine if a $n$-bit function $f:{0,1}^n\\longrightarrow {0,1}$ is constant or a balanced with only $\\frac{n}{2}$ function evaluations, for $n$ even. A function if balanced if half of the inputs map to $0$ and half map to $1$. \n", |
| 388 | + "\n", |
| 389 | + "Here we must assume that the function that we are given is either constant or balanced since there are $n$-bit functions that are neither constant, nor balanced. For instance the $2$-bit function $f(b_0,b_1) = \\max(b_0,b_1)$ is neither balanced, nor constant.\n", |
| 390 | + "\n", |
| 391 | + "A hint on how you might approach this problem is to first solve the problem for $n=2$ and see if you can then use that approach to handle $n$-bit functions for larger values of $n$." |
| 392 | + ] |
394 | 393 | }
|
395 | 394 | ],
|
396 | 395 | "metadata": {
|
|
0 commit comments