/
Lecture4.tex
482 lines (396 loc) · 20.9 KB
/
Lecture4.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
\documentclass[12pt, letterpaper]{article}
\usepackage{abstract}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{braket}
\usepackage[hang,small,bf]{caption}
\usepackage[margin=1in]{geometry}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{
backgrounds,
shadows.blur,
fit,
decorations.pathreplacing,
shapes}
\usepackage[frame,line,arrow,matrix,tips]{xy} % all that is usually necessary
\renewcommand{\abstractname}{} % clear the title
\renewcommand{\absnamepos}{empty} % originally center
% qasm2circ definitions
\def\w{\ar@{-}[l]}
\def\A#1{\save []="#1" \restore}
\def\op#1{*+[F]{\rule[-0.2ex]{0ex}{2.1ex}#1}} % operator in box
\def\b{*={\bullet}}
\def\o{*={\oplus}}
\def\m#1{\left[\matrix{#1}\right]} % matrix shortcut
\def\z{*+[]{\rule[-0.2ex]{0ex}{2.1ex}~|0\>}} % re-init to |0>
\def\discard{*[]{\rule[-0.2ex]{0.75pt}{2.1ex}~}} % vertical ``|''
\def\n{*-{}\w}
\def\>{\rangle}
\def\<{\langle}
\def\ua{\uparrow}
\def\q#1{*+{\rule[-0.2ex]{0ex}{2.1ex}|#1\>}}
\def\qv#1#2{*+{\rule[-0.2ex]{0ex}{2.1ex}|#1\>=|#2\>}}
\title{CS 269Q Lecture 4 \\ \large Programming a quantum algorithm with pyQuil\vspace{-1ex}}
\author{Peter Karalekas \\ \small peter@rigetti.com}
\date{\normalsize April 11, 2019\vspace{-3ex}}
\begin{document}
\maketitle
\begin{abstract}
\noindent
We build out our quantum computing toolbox so that we can implement our very first quantum algorithm. We begin by working through a couple foundational concepts—the wavefunction, classical logic, and quantum parallelism—and then conclude with a walkthrough of the protocol for Deutsch's algorithm. Alongside these notes, there is a Jupyter notebook that uses Rigetti Computing's open-source software development kit, called Forest, to step through the algorithm and inspect the wavefunction.
\end{abstract}
\section{The wavefunction and quantum circuits}
We represent the state of our qubit using the ``ket" $\ket{\psi}$, which is a superposition of the states $\ket{0}$ and $\ket{1}$ that form a
basis for a two-dimensional complex vector space ($\mathbb{C}^2$). We additionally have a normalization condition on our complex amplitudes $\alpha$ and $\beta$ such that their magnitudes squared must sum to 1.
\begin{equation}
\ket{\psi} = \alpha \ket{0} + \beta \ket{1} \hspace{1 cm} |\alpha|^2 + |\beta|^2 = 1
\end{equation}
\subsection{1Q states}
For our quantum virtual machine (QVM), each qubit begins in the $|\psi\rangle = |0\rangle$ state. We then apply quantum gates to evolve the state of the QVM, and each gate $U$ must be unitary, meaning that $U^{\dag}U = I$. We can use an $X$ gate to flip between $|0\rangle$ and $|1\rangle$.
\begin{equation}
X|0\rangle = |1\rangle \hspace{1 cm} X|1\rangle = |0\rangle \vspace{3 mm}
\end{equation}
\noindent
In addition to swapping between the 1Q computational basis states, we can use quantum gates to create superposition states. Here we create the 1Q superposition states $|+\rangle$ amd $|-\rangle$ using the $H$ (Hadamard) gate.\vspace{2 mm}
\begin{equation}
H|0\rangle = \dfrac{|0\rangle + |1\rangle}{\sqrt{2}} = |+\rangle \hspace{1 cm} H|1\rangle = \dfrac{|0\rangle - |1\rangle}{\sqrt{2}} = |-\rangle
\end{equation}
\subsection{2Q states}
For two-qubit states, we can create ``product states" of computational basis states, which just look like two-bit bitstrings. Here we create the 2Q computational basis state $|10\rangle$.
\begin{equation}
(X \otimes I)|00\rangle = |10\rangle \vspace{3 mm}
\end{equation}
\noindent
We can also create product states of superposition states. Here we create the 2Q superposition state $|+,+\rangle$ using two Hadamard gates.\vspace{2 mm}
\begin{equation}
(H \otimes H)|00\rangle = \left( \dfrac{|0\rangle + |1\rangle}{\sqrt{2}}\right) \otimes \left( \dfrac{|0\rangle + |1\rangle}{\sqrt{2}}\right) = |+,+\rangle \vspace{4 mm}
\end{equation}
\noindent
In addition to product states, we can create entangled states, which we can no longer factor into the tensor product of two individual qubit states. Here we create the Bell state $|\Phi^+\rangle$.
\vspace{2 mm}
\begin{equation}
\text{CNOT}_{0,1}(I \otimes H)|00\rangle = \text{CNOT}_{0,1}|0\rangle \otimes \left( \dfrac{|0\rangle + |1\rangle}{\sqrt{2}}\right) = \dfrac{|00\rangle + |11\rangle}{\sqrt{2}} = |\Phi^+\rangle
\end{equation}
\section{Classical logic and function evaluation}
In Computer Science, we learn about Boolean logic gates like \texttt{NOT},
\texttt{AND}, \texttt{OR}, and \texttt{XOR}. In quantum computing, we can implement these classical logic gates, but we must do so in a way that respects the unitarity requirements of quantum logic gates.
\subsection{Boolean functions of 1-bit domain}
\vspace{2 mm}
\begin{equation}
x \in \{0,1\} \hspace{1cm} f(x) \rightarrow \{0,1\} \vspace{2 mm}
\end{equation}
\noindent
One-bit boolean functions represent the simplest classical logic we can implement on a quantum computer. There are four possible one-bit functions $f(x)$, and we will work through all of them.
\subsubsection{Balanced functions}
\vspace{2 mm}
$$\text{Balanced-}I : (0 \rightarrow 0, 1 \rightarrow 1)
\hspace{1 cm}
\text{Balanced-}X : (0 \rightarrow 1, 1 \rightarrow 0) \vspace{2 mm}$$
\noindent
For the balanced 1-bit functions, it’s pretty easy to come up with a quantum circuit that works. If we use just an $I$ gate for Balanced-$I$ and just an $X$ gate for Balanced-$X$, we can produce a quantum circuit $U_f$ that maps $|x\rangle \rightarrow |f(x)\rangle$. Knowing the gate and and output, we can reproduce the input, which means our circuit satisfies our reversibility requirements. Below, we have the quantum circuit for Balanced-$I$ on the left, and Balanced-$X$ on the right.
% the 1-qubit balanced circuits
\def\gAxA{\op{X}\w\A{gAxA}}
\def\bA{ \q{x}}
\begin{equation}
\xymatrix@R=5pt@C=10pt{
\bA &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n
}\hspace{1 cm}
\xymatrix@R=5pt@C=10pt{
\bA &\n &\n &\n &\gAxA &\n &\n &\n &\n
}
\end{equation}
\subsubsection{Constant functions}
\vspace{2 mm}
$$\text{Constant-}0 : (0 \rightarrow 0, 1 \rightarrow 0)
\hspace{1 cm}
\text{Constant-}1 : (0 \rightarrow 1, 1 \rightarrow 1) \vspace{2 mm}$$
\noindent
Coming up with the circuit for the constant functions seems less trivial. We can write down a matrix $M_f$ that maps the 0 state to the 0 state and the 1 state to the 0 state.\vspace{1 mm}
\begin{equation}
M_f = \left(\begin{matrix}
1 & 1 \\
0 & 0
\end{matrix}\right) \vspace{3 mm}
\end{equation}
\noindent
However, this matrix has some problems. It is not invertible (determinant 0) and it is not length preserving (superposition state changes length), and therefore it is not unitary. We can also see that it is not reversible simply from the truth table—knowing the output and the gate isn’t enough to get back to the input.\vspace{1 mm}
\begin{equation}
\text{det}(M_f) = \text{det}\left(\begin{matrix}
1 & 1 \\
0 & 0
\end{matrix}\right) = 1\cdot0 - 1\cdot0 = 0
\end{equation}
\vspace{3 mm}
\begin{equation}
M_f|\psi\rangle = \left(\begin{matrix}
1 & 1 \\
0 & 0
\end{matrix}\right)
\left(\begin{matrix}
0.6 \\
0.8
\end{matrix}\right) =
\left(\begin{matrix}
1.4 \\
0.0
\end{matrix}\right)
\end{equation}
\subsubsection{Ancilla qubits}
In order to write this function as a quantum circuit, we need to introduce a new concept—the ancilla qubit. An ancilla qubit is an additional qubit used in a computation that we know the initial state of. Using an ancilla, we can produce a quantum circuit $U_f$ that maps $|0, x\rangle \rightarrow |f(x), x\rangle$. Now, we can come up with a unitary matrix (albeit a trivial one) that allows us to evaluate constant functions. For the Constant-$0$, we just simply do nothing to the ancilla, and its state encodes $f(x)$. And for the Constant-$1$, all we have to do is flip the ancilla with an $X$ gate, and we get $f(x)$ for all $x$. Below, we have the Balanced-$I$ (top left), Balanced-$X$ (bottom left), Constant-$0$ (top right), and Constant-$1$ (bottom right) functions implemented as quantum circuits with one ancilla qubit. We will continue to use this ordering for sections 2.3 and 2.4.
\begin{equation}
|0, x\rangle \rightarrow |f(x), x\rangle
\end{equation}
% ancilla qubit circuits
\def\gAxB{\op{X}\w\A{gAxB}}
\def\gBxA{\b\w\A{gBxA}}
\def\gBxB{\o\w\A{gBxB}}
\def\bA{ \q{x}}
\def\bB{ \q{0}}
$$
\xymatrix@R=5pt@C=10pt{
\bA &\n &\n &\n &\n &\n &\n &\n &\n &\n &\gBxA &\n &\n &\n
\\ \bB &\n &\n &\n &\n &\n &\n &\n &\n &\n &\gBxB &\n &\n &\n
\ar@{-}"gBxB";"gBxA"
}\hspace{1 cm}
\xymatrix@R=5pt@C=10pt{
\bA &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n
\\ \bB &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n
}$$
$$
\xymatrix@R=5pt@C=10pt{
\bA &\n &\n &\n &\gBxA &\n &\n &\n
\\ \bB &\n &\n &\gAxB &\gBxB &\n &\n &\n
\ar@{-}"gBxB";"gBxA"
}\hspace{1 cm}
\xymatrix@R=5pt@C=10pt{
\bA &\n &\n &\n &\n &\n &\n &\n &\n
\\ \bB &\n &\n &\n &\gAxB &\n &\n &\n &\n
}$$
\subsection{The Quantum \texttt{XOR} gate}
The Boolean function \texttt{XOR} (for ``exclusive or") takes in two bits $x$ and $y$ and returns 1 if and only if the values of the bits are different from one another. Otherwise, it returns 0. The operation is written as $x \oplus y$, and although it is a two-bit function, we can implement it as a quantum circuit without an ancilla, by simply using the \textrm{CNOT} gate.
\begin{equation}
\textrm{CNOT}_{0,1}|y, x\rangle = |y \oplus x, x\rangle
\end{equation}
% xor circuit
\def\gAxA{\b\w\A{gAxA}}
\def\gAxB{\o\w\A{gAxB}}
\def\bA{ \q{x}}
\def\bB{ \q{0}}
$$\xymatrix@R=5pt@C=10pt{
\bA &\n &\n &\gAxA &\n &\n &\n
\\ \bB &\n &\n &\gAxB &\n &\n &\n
\ar@{-}"gAxB";"gAxA"
}$$
\subsection{Deutsch Oracle}
In Deutsch's algorithm, we are given something called an oracle (referred to as $U_f$), which maps $|y, x\rangle \rightarrow |y \oplus f(x), x\rangle$, and the goal is to determine a global property of the function $f(x)$ with as few queries to the oracle as possible. We can combine the two concepts above (one-bit function evaluation with ancillas, and the \texttt{XOR} gate), to produce the four implementations of the Deutsch Oracle with one ancilla qubit.
\begin{equation}
U_f : |y, 0, x\rangle \rightarrow |y \oplus f(x), 0, x\rangle
\end{equation}
% deutsch oracle circuit
\def\gAxB{\op{X}\w\A{gAxB}}
\def\gBxA{\b\w\A{gBxA}}
\def\gBxB{\o\w\A{gBxB}}
\def\gCxB{\b\w\A{gCxB}}
\def\gCxC{\o\w\A{gCxC}}
\def\gDxA{\b\w\A{gDxA}}
\def\gDxB{\o\w\A{gDxB}}
\def\gExB{\op{X}\w\A{gExB}}
\def\bA{ \q{x}}
\def\bB{ \q{0}}
\def\bC{ \q{y}}
$$\xymatrix@R=5pt@C=10pt{
\bA &\n &\n &\n &\n &\n &\n &\gBxA &\n &\gDxA &\n &\n &\n &\n &\n &\n &\n
\\ \bB &\n &\n &\n &\n &\n &\n &\gBxB &\gCxB &\gDxB &\n &\n &\n &\n &\n &\n &\n
\\ \bC &\n &\n &\n &\n &\n &\n &\n &\gCxC &\n &\n &\n &\n &\n &\n &\n &\n
\ar@{-}"gBxB";"gBxA"
\ar@{-}"gCxC";"gCxB"
\ar@{-}"gDxB";"gDxA"
}\hspace{1 cm}
\xymatrix@R=5pt@C=10pt{
\bA &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n & \n &\n &\n &\n
\\ \bB &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\gCxB &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n
\\ \bC &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\gCxC &\n &\n &\n &\n &\n &\n & \n &\n &\n &\n
\ar@{-}"gCxC";"gCxB"
}$$
$$\xymatrix@R=5pt@C=10pt{
\bA &\n &\gBxA &\n &\gDxA &\n &\n
\\ \bB &\gAxB &\gBxB &\gCxB &\gDxB &\gExB &\n
\\ \bC &\n &\n &\gCxC &\n &\n &\n
\ar@{-}"gBxB";"gBxA"
\ar@{-}"gCxC";"gCxB"
\ar@{-}"gDxB";"gDxA"
}\hspace{1 cm}
\xymatrix@R=5pt@C=10pt{
\bA &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n
\\ \bB &\gAxB &\n &\n &\n &\gCxB &\n &\n &\n &\gAxB &\n
\\ \bC &\n &\n &\n &\n &\gCxC &\n &\n &\n &\n &\n
\ar@{-}"gCxC";"gCxB"
}$$
\subsection{Optimized Deutsch Oracle}
For pedagogical reasons, it is nice to separate out the three steps in the Deutsch Oracle—evaluate $f(x)$, calculate $y \oplus f(x)$, and then return the ancilla to $|0\rangle$. But, in practice we always want to implement our circuits in as few gates as possible (this is especially important when running on a real, noisy quantum computer!). Below, we show how we can rewrite each of the four Deutsch Oracle implementations (which we call $U_f$) without the need for an ancilla qubit.
\vspace{20 mm}
\begin{equation}
U_f : |y, x\rangle \rightarrow |y \oplus f(x), x\rangle
\end{equation}
% optimized deutsch oracle circuits
\def\gAxA{\op{X}\w\A{gAxA}}
\def\gBxA{\b\w\A{gBxA}}
\def\gBxB{\o\w\A{gBxB}}
\def\gCxA{\op{X}\w\A{gCxA}}
\def\bA{ \q{x}}
\def\bB{ \q{y}}
$$\xymatrix@R=5pt@C=10pt{
\bA &\n &\n &\n &\n &\n &\n &\gBxA &\n &\n &\n &\n &\n &\n &\n &\n
\\ \bB &\n &\n &\n &\n &\n &\n &\gBxB &\n &\n &\n &\n &\n &\n &\n &\n
\ar@{-}"gBxB";"gBxA"
}\hspace{1 cm}
\xymatrix@R=5pt@C=10pt{
\bA &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n
\\ \bB &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n
}$$
$$\xymatrix@R=5pt@C=10pt{
\bA &\gAxA &\gBxA &\gCxA &\n
\\ \bB &\n &\gBxB &\n &\n
\ar@{-}"gBxB";"gBxA"
}\hspace{1 cm}
\xymatrix@R=5pt@C=10pt{
\bA &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n &\n
\\ \bB &\n &\n &\n &\n &\n &\gAxA &\n &\n &\n &\n &\n &\n
}$$
\section{Quantum parallelism}
In the previous section, we showed that we could implement classical logic using quantum circuits. However, when using a computational basis state ($|0\rangle$ or $|1\rangle$), we don't do anything more interesting than a classical computer can do. If we instead feed a superposition state into one of these circuits, we can effectively evaluate a function $f(x)$ on multiple values of $x$ at once!
\begin{equation}
U_f : |0,+\rangle \rightarrow \dfrac{|f(0), 0\rangle + |f(1), 1\rangle}{\sqrt{2}}
\end{equation}
\vspace{1 mm}
\begin{equation}
U_f : |0,-\rangle \rightarrow \dfrac{|f(0), 0\rangle - |f(1), 1\rangle}{\sqrt{2}}
\end{equation}
\vspace{1 mm}
\noindent
It is important to note, that although this quantum parallelism concept is interesting, we are unable to learn about both $f(0)$ and $f(1)$ when the states above are in that form. This is due to the fact that we can only extract one classical bit of information from a quantum computer (of 1 qubit) when we measure it. But, as we will find in Deutsch's algorithm below, we can cleverly take advantage of quantum parallelism to do things that a classical computer cannot, even with the constraint that measurement yields only one classical bit.
\subsection{Test with Balanced-$I$}
To verify, we run the Balanced-$I$ circuit for an input that is in a superposition state.
\vspace{2 mm}
\begin{equation}
\text{CNOT}_{0,1}|0,+\rangle = \dfrac{\text{CNOT}_{0,1}|00\rangle + \text{CNOT}_{0,1}|01\rangle}{\sqrt{2}} = \dfrac{|00\rangle + |11\rangle}{\sqrt{2}} = |\Phi^+\rangle
\end{equation}
\vspace{1 mm}
\begin{equation}
\text{CNOT}_{0,1}|0,-\rangle = \dfrac{\text{CNOT}_{0,1}|00\rangle - \text{CNOT}_{0,1}|01\rangle}{\sqrt{2}} = \dfrac{|00\rangle - |11\rangle}{\sqrt{2}} = |\Phi^-\rangle
\end{equation}
\vspace{2 mm}
\noindent
In both of our output states, we can see that if we take the state of qubit 0 in each ket to be $x$, the state of qubit 1 in the corresponding ket is equal to $f(x)$ (as $f(x) = x$ for Balanced-$I$).
\section{Deutsch's algorithm}
\noindent
\textbf{Goal}: Determine if function $f(x)$ is \textit{constant} ($f(0) = f(1)$) or \textit{balanced} ($f(0) \neq f(1)$).
\vspace{1 mm}
{
% utulity text box for figuring out width of things
\newbox{\sbox}
% empty space of width determined by the text argument
\def\gspace#1{*+{\rule[-0.2ex]{0ex}{2.1ex}%
\setbox\sbox=\hbox{$#1$}%
\hspace*{\wd\sbox}
\hspace*{\wd\sbox}
\hspace*{\wd\sbox}}}
% n-qubit operation #1=box label, #2=number of qubits (eg d=2 qubits, ddd=4)
\def\gnqubit#1#2{\gspace{#1}
\save [].[#2]!C="qq"*[F]\frm{}\restore
\save "qq"*[]{#1} \restore}
% deutsch's algorithm circuit
\def\gAxA{\op{H}\w\A{gAxA}}
\def\gAxB{\op{H}\w\A{gAxB}}
\def\gBxA{\gnqubit{U_{f}}{d}\w\A{gBxA}}
\def\gBxB{\gspace{U_{f}}\w\A{gBxB}}
\def\gCxA{\op{H}\w\A{gCxA}}
\def\gCxB{\op{H}\w\A{gCxB}}
\def\bA{ \q{0}}
\def\bB{ \q{1}}
\begin{equation}
\begin{split}
\xymatrix@R=5pt@C=10pt{
\bA &\n &\n &\gAxA &\n &\n &\gBxA &\n &\n &\gCxA &\n &\n &\n
\\ \bB &\n &\n &\gAxB &\n &\n &\gBxB &\n &\n &\gCxB &\n &\n &\n
}
\end{split}
\end{equation}
}
\vspace{2 mm}
\noindent
As part of the algorithm, we are given a Deutsch Oracle and are unaware of which one-bit Boolean function $f(x)$ it implements. We show that we can do this with only one query to the Deutsch Oracle, which is impossible on a classical computer, which would require two queries to the Deutsch Oracle to determine this global property of $f(x)$.
\subsection{Initial state}
We begin our algorithm in the computational basis state $|10\rangle$. The fact that the states for qubit 0 and qubit 1 are different proves to be important.
\begin{equation}
|\psi_0\rangle = |10\rangle
\end{equation}
\subsection{Prepare superpositions}
We cannot do anything interesting with computational basis states, so to take advantage of quantum parallelism we put our qubits in superposition states.\vspace{1 mm}
\begin{equation}
|\psi_1\rangle = (H \otimes H)|\psi_0\rangle = (H \otimes H)|10\rangle = \left( \dfrac{|0\rangle - |1\rangle}{\sqrt{2}}\right) \otimes \left( \dfrac{|0\rangle + |1\rangle}{\sqrt{2}}\right) = |-,+\rangle \vspace{1 mm}
\end{equation}
\subsection{Apply the Deutsch Oracle}
We learned earlier that the action of the Deutsch Oracle on input state $|y,x\rangle$ is $U_f|y, x\rangle \rightarrow |y \oplus f(x), x\rangle$. So, what happens if we apply the Deutsch Oracle to the input state $|-,x\rangle$?
\begin{equation}
\begin{split}
U_f|-, x\rangle
&= \dfrac{U_f|0, x\rangle - U_f|1, x\rangle}{\sqrt{2}} \\
\vspace{1 mm}\\
&= \dfrac{|0 \oplus f(x), x\rangle - |1 \oplus f(x), x\rangle}{\sqrt{2}} \\
\vspace{1 mm}\\
&= \begin{cases}
\dfrac{|0, x\rangle - |1, x\rangle}{\sqrt{2}} = (+1)|-,x\rangle \text{ \hspace{5 mm} if } f(x) = 0;\\
\vspace{1 mm}\\
\dfrac{|1, x\rangle - |0, x\rangle}{\sqrt{2}} = (-1)|-,x\rangle \text{ \hspace{5 mm} if } f(x) = 1.
\end{cases}
\end{split}
\end{equation}
\vspace{1 mm}
\noindent
These two branches can be unified, as we see in the following equation.
\begin{equation}
U_f|-, x\rangle = (-1)^{f(x)}|-, x\rangle
\vspace{3 mm}
\end{equation}
\noindent
Thus, we get a negative sign if $f(x) = 1$, and the state is unchanged if $f(x) = 0$. However, something interesting happens when we apply $U_f$ to the state $|-,+\rangle$, which is $|\psi_1\rangle$.
\begin{equation}
\begin{split}
|\psi_2\rangle = U_f|\psi_1\rangle
&= U_f|-, +\rangle \\
\vspace{1 mm}\\
&= \dfrac{U_f|-, 0\rangle + U_f|-, 1\rangle}{\sqrt{2}} \\
\vspace{1 mm}\\
&= \dfrac{(-1)^{f(0)}|-, 0\rangle + (-1)^{f(1)}|-, 1\rangle}{\sqrt{2}} \\
\vspace{1 mm}\\
&= |-\rangle \otimes \left( \dfrac{(-1)^{f(0)}|0\rangle + (-1)^{f(1)}|1\rangle}{\sqrt{2}}\right) \\
\vspace{1 mm}\\
&= \begin{cases}
\pm |-\rangle \otimes \left( \dfrac{|0\rangle + |1\rangle}{\sqrt{2}}\right) = \pm |-,+\rangle \text{ \hspace{5 mm} if constant;} \\
\vspace{1 mm}\\
\pm |-\rangle \otimes \left( \dfrac{|0\rangle - |1\rangle}{\sqrt{2}}\right) = \pm |-,-\rangle \text{ \hspace{5 mm} if balanced.}
\end{cases}
\end{split}
\end{equation}
\vspace{1 mm}
\noindent
If $f(x)$ is balanced, this has the effect of changing the relative phase between the $|0\rangle$ and $|1\rangle$ components of qubit 0's state, which flips it from $|+\rangle$ to $|-\rangle$. This is interesting, because the action of our oracle on the computational basis state $|y,x\rangle$ is to change the state of qubit 1 and leave qubit 0 alone. But, when our qubits are in superposition states, the balanced oracle actually changes the state of qubit 0 (which is the control qubit in the oracle), and leaves alone the state of qubit 1 (which is the target qubit in the oracle).
\subsection{Return to 2Q computational basis states}
We know that the outcome of the previous step is to produce one of two superposition product states, $|-, +\rangle$ or $|-, -\rangle$. However, our goal is to query the Deutsch Oracle as few times as possible, and so although we can see that these states are different, we cannot distinguish them with a single measurement (as we only get a 0 or a 1). Therefore, we use the Hadamard gate to return to 2Q computational basis states that can be distinguished in one measurement.
\begin{equation}
|\psi_3\rangle = (H \otimes H)|\psi_2\rangle =
\begin{cases}
\pm (H \otimes H)|-, +\rangle = \pm |10\rangle \text{ \hspace{5 mm} if constant;}\\
\\
\pm (H \otimes H)|-, -\rangle = \pm |11\rangle \text{ \hspace{5 mm} if balanced.}
\end{cases}
\end{equation}
\vspace{1 mm}
\noindent
Thus, we are in two distinct 2Q computational basis states, dependent on the nature of $f(x)$. We could then measure the state of qubit 0 one time, and we would immediately know the answer to whether $f(x)$ is constant or balanced.
\subsection{Conclusions}
So, we were able to learn about a \textit{global property} of the function $f(x)$ in just one query to the Deutsch Oracle, which is impossible on a classical computer. Although the problem statement for Deutsch's algorithm is a bit contrived, if you can suspend your judgment, you can imagine that we could take some of the non-classical concepts of this algorithm and apply them to a more complex scenario to actually produce an interesting quantum speedup. And, later in the course, you will do exactly this!
\end{document}