-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathU2L4d.txt
190 lines (152 loc) · 5.63 KB
/
U2L4d.txt
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
#
# File: content-mit-8370x-subtitles/U2L4d.txt
#
# Captions for course module
#
# This file has 181 caption lines.
#
# Do not add or delete any lines. If there is text missing at the end, please add it to the last line.
#
#----------------------------------------
Now what I want to do is the two-qubit Fourier transform.
Well, let's write down the quantum Fourier
transform for two qubits using our matrix,
which I unfortunately erased.
But it's 1 over the square root of n, that's 2,
times, well, this is e to the 2 pi i minus 2 pi i over 4.
Is there a simpler way of stating this, anybody?
Yeah?
Minus i.
Minus i, very good.
This is minus i.
And this is minus 1, i, minus 1, i, and this is minus 1,
1, minus 1, and i, 1, minus i.
So that's what we want to get, and we
want to build it out of gates.
But this is also--
the i-th entry is going to be e to the 2 pi--
or the j, k entry is going to be e to the 2 pi i j
k over 4 is equal to e to the minus 2 pi i j0--
yeah, j0 plus 2j1 k0 plus 2k1 over 4 equals e to the minus 2
pi i.
Well, we get j0 k0 over 4 times e to the minus 2 pi i
j1 k0 over 2 times e to the minus 2 pi i j0 k1 over 2.
OK.
And we don't get a j1 k1 term because, well,
because 2j1 times 2k1 is a multiple of 4.
So let's think about this.
Well, the ji's are represented by qubits,
so we can think of these as three potential gates.
And here, I'm going to cheat a little bit--
at least j0 goes to k.
Let's try implementing the second one.
So that j1 goes to k0 e to the 2 pi i j0 j1 k0.
I need to do a sum over k0 equals
0 to 1 e to the 2 pi i ji k0 over 2, right, over 2.
So this is, well, 0 goes to 0, 1 goes to 0, 0 goes to 1,
and 1 goes to 1.
Actually, 1 goes to minus 1.
And I forgot the--
I forgot normalization factor.
We need a normalization factor to make this unitary.
So you should all recognize this gate.
This is just the Hadamard gate.
0 goes to 0--
0 goes to 0 with a factor of 1 over root 2, 1
goes to 0 with a factor of 1 over root 2, 0
goes to 1 with a factor 1 over root 2,
and 1 goes to 1 with a factor of minus 1 over root 2.
So the Hadamard gate implements this piece,
and it also implements this piece,
because this is just the same thing with j0 and k1.
So let's try drawing the circuit.
OK, so this would be j0, j1, Hadamard, k0--
oh, well, no k1, because remember, j1
was Hadamarded from k0, and k1 was Hadamarded from j0.
So this is not right yet.
So this might be a first attempt at the circuit,
but it doesn't work.
So why doesn't it work?
Need term.
Well, we need the last term over here-- e to the minus 2 pi i
j0 k0 over 4.
e to the minus 2 pi i j0 k0 over 4.
So what does this do?
Well, this interacts-- j0, we want j0 to interact with k0.
So what you want is you want to draw a gate that connects
this piece with that piece.
And of course, you can if you--
j1, H, if you move this top Hadamard
later than the bottom Hadamard.
And now what is this thing?
Well, j0 k0 goes to--
well, nothing happens, or rather you multiply by 1 if j0 is 0
or if k0 is 0.
So that's 1, 1, 1.
And otherwise, you multiply by e to the minus 2 pi i over 4,
which you should recognize is minus i.
And I drew this too far to the right.
j0 k0 goes to 1, 1, 1, minus i, j0 k0.
So that is just a controlled--
remember, that was a controlled--
well, a controlled-S gate has this i.
So this is a controlled-S dagger gate, which gives minus i.
So do nothing if the first qubit is 0.
And if the second qubit is 0, multiply-- oh, or no.
If the first qubit is a 1, multiply the second qubit by--
multiply the phase by minus i if the second qubit is also a 1.
So you see this gate is symmetric in, I guess,
j0 and k0.
So this is the quantum Fourier transform for two qubits.
So let's try writing it out in terms of matrices.
So the first thing we do is an H to j1.
This is the first qubit of j--
or no-- yeah.
First thing we do is an H on j1, which is the first qubit of j.
And of course, when we're multiplying matrices,
the first thing we do to a vector
is a matrix on the very right, which is 1, 1, 1, 1, 1, 1,
minus 1, minus 1.
The second thing we do is this controlled-S star,
which is this matrix--
1, 1, 1, 1, minus i.
And the third thing we do is a Hadamard on the other qubit,
which is the second qubit for writing them out
in the standard way we write binary numbers.
So that's 1, 1, 1, minus 1, 1, 1, 1, minus 1.
And we want to multiply this by 1 over root 2 and this by 1
over root 2, which give us a 1/2 in front of it.
So this equals 1/2.
OK.
And I believe this thing multiplies the last row by i--
or by minus i.
So that's 1, 1, 1, 1, 1, minus i, minus 1, i.
And now let's multiply those two together, and we get 1/2 1,
1, 1, 1.
I'm not going to actually--
1 minus 1, 1, minus i, minus 1, i, 1, i, minus 1, minus i.
Well, this isn't what we wanted.
So what did we forget to do?
Yeah?
Do we want to swap the bits of k?
Yeah, we wanted to swap the bits of k,
because this came out k0 and k--
This came out k0, j0, k1, and j1 went to k0.
So these bits are in the wrong order.
So to swap them what we need to do
is multiply this whole thing by the swap gate,
which swaps 1, 0 with 0, 1.
And what does the swap gate do?
Well, it swaps the second and third rows of this matrix.
So that equals 1, 1, 1 1, 1, minus i,
minus 1, i, 1, minus 1, 1, minus 1, 1, i, minus 1, minus i.
So that actually-- so this circuit
does work, except we need to do a swap at the end.
And maybe that's not the best notation for a swap gate.
OK.
So if you're used to the Cooley-Tukey fast Fourier
transform, you remember that the answer comes out
in the wrong order, and you have to reverse the bits.
And this is exactly the same thing happens here.
The answer comes out in the wrong order.
We need to reverse the bits.