05-Quantum-query-algorithms-slides
05-Quantum-query-algorithms-slides
quantum information
and computation
By John Watrous
Lesson 5
Quantum query algorithms
Key point
input
⋯ queries
computation output
n m ⋯ queries
f∶Σ →Σ
Queries
Parity
n
Input: f∶Σ →Σ
0 if f(x) = 1 for an even number of strings x ∈ Σ
n
Output:
1 if f(x) = 1 for an odd number of strings x ∈ Σ
n
Minimum
n m
Input: f∶Σ →Σ
The string y ∈ {f(x) ∶ x ∈ Σ } that comes first in the
n
Output:
m
lexicographic ordering of Σ
Examples of query problems
Sometimes we also consider query problems where we have a promise on the
input. Inputs that don’t satisfy the promise are considered as “don’t care”
inputs.
Unique search
n
Input: f∶Σ →Σ
There is exactly one string z ∈ Σ for which f(z) = 1,
n
Promise:
/z
with f(x) = 0 for all strings x =
Output: The string z
Or, Parity, Minimum, and Unique search are all very “natural” examples of query
problems — but some query problems of interest aren’t like this.
For Boolean circuits, query gates generally compute the input function f directly.
⎧
⎪
⎪
⎪ ⎫
⎪
⎪ ⎪
⎪
x ⎪
⎨
⎪ ⎬
⎪
⎪ ⎪
⎪
f(x)
⎪
f
⎪
⎪ ⎭
⎩
0 f ∧
¬
¬
1 f ∧
Query gates
For the quantum circuit model, we choose a different definition for query gates
that makes them unitary — allowing them to be applied to quantum states.
Definition
n m
The query gate Uf for any function f ∶ Σ →Σ is defined as
Uf (∣y⟩∣x⟩) = ∣y ⊕ f(x)⟩∣x⟩
n m
for all x ∈ Σ and y ∈ Σ .
Notation
The string y ⊕ f(x) is the bitwise XOR of y and f(x). For example:
Uf (∣y⟩∣x⟩) = ∣y ⊕ f(x)⟩∣x⟩
n m
for all x ∈ Σ and y ∈ Σ .
∣x⟩ ∣x⟩
Uf
∣y⟩ ∣y ⊕ f(x)⟩
Deutsch’s problem
Input: f∶Σ→Σ
Output: 0 if f is constant, 1 if f is balanced
Deutsch’s problem
Deutsch’s problem
Input: f∶Σ→Σ
Output: 0 if f is constant, 1 if f is balanced
Every classical query algorithm must make 2 queries to f to solve this problem —
learning just one of two bits provides no information about their parity.
Our query algorithm from earlier is therefore optimal among classical query
algorithms for this problem.
0 f ∧
¬
¬
1 f ∧
Deutsch’s algorithm
Deutsch’s algorithm solves Deutsch’s problem using a single query.
0 if f is constant
∣0⟩ H H {
1 if f is balanced
Uf
∣1⟩ H
1 1
∣π1 ⟩ = ∣−⟩∣+⟩ = (∣0⟩ − ∣1⟩)∣0⟩ + (∣0⟩ − ∣1⟩)∣1⟩
2 2
1 1
∣π2 ⟩ = (∣0 ⊕ f(0)⟩ − ∣1 ⊕ f(0)⟩)∣0⟩ + (∣0 ⊕ f(1)⟩ − ∣1 ⊕ f(1)⟩)∣1⟩
2 2
1 1
= (−1) (∣0⟩ − ∣1⟩)∣0⟩ + (−1) (∣0⟩ − ∣1⟩)∣1⟩
f(0) f(1)
2 2
(−1) ∣0⟩ + (−1) ∣1⟩
= ∣−⟩ ( )
f(0) f(1)
√
2
Deutsch’s algorithm
Deutsch’s algorithm solves Deutsch’s problem using a single query.
0 if f is constant
∣0⟩ H H {
1 if f is balanced
Uf
∣1⟩ H
0 if f is constant
∣0⟩ H H {
1 if f is balanced
Uf
∣1⟩ H
⎧
⎪
⎪
⎪(−1) ∣−⟩∣+⟩ f(0) ⊕ f(1) = 0
f(0)
∣π2 ⟩ = ⎨
⎪
⎪
⎩(−1)
⎪ ∣−⟩∣−⟩ f(0) ⊕ f(1) = 1
f(0)
⎧
⎪
⎪
⎪(−1) ∣−⟩∣0⟩ f(0) ⊕ f(1) = 0
f(0)
∣π3 ⟩ = ⎨
⎪
⎪
⎩(−1)
⎪ ∣−⟩∣1⟩ f(0) ⊕ f(1) = 1
f(0)
∣b ⊕ c⟩ = X ∣b⟩
c
∣π1 ⟩ = ∣−⟩∣+⟩
1 1
∣π2 ⟩ = Uf (∣−⟩∣+⟩) = √ Uf (∣−⟩∣0⟩) + √ Uf (∣−⟩∣1⟩)
2 2
(−1) ∣0⟩ + (−1) ∣1⟩
= ∣−⟩( )
f(0) f(1)
√
2
The Deutsch-Jozsa circuit
The Deutsch-Jozsa algorithm extends Deutsch’s algorithm to input functions of
the form f ∶ Σ → Σ for any n ≥ 1.
n
The quantum circuit for the Deutsch-Jozsa algorithm looks like this:
∣0⟩ ⎫
⎪
⎪
⎪
H H
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
∣0⟩ ⎪
⎪
⎪
⎪
H H
⎪
⎪
⎬
⎪
n
⎪
y∈Σ
⎪
⎪
⎪
⎪
⎪
⎪
Uf
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
∣0⟩ H H ⎪
⎭
∣1⟩ H
x f(x)
00 0
01 0
10 0
11 1
Input functions that are neither constant nor balanced are “don’t care” inputs.
The Deutsch-Jozsa problem
The Deutsch-Jozsa problem generalizes Deutsch’s problem: for an input function
f ∶ Σ → Σ, the task is to output 0 if f is constant and 1 if f is balanced.
n
Deutsch-Jozsa problem
n
Input: f∶Σ →Σ
Promise: f is either constant or balanced
Output: 0 if f is constant, 1 if f is balanced
The Deutsch-Jozsa problem
Deutsch-Jozsa problem
n
Input: f∶Σ →Σ
Promise: f is either constant or balanced
Output: 0 if f is constant, 1 if f is balanced
∣0⟩ ⎫
⎪
⎪
⎪
⎪
H H
⎪
⎪
⎪
⎪
⎪
⎪
∣0⟩ ⎪
⎪
⎪
⎪
⎪
⎪
H H
⎪
⎬
⎪
n
⎪
y∈Σ
⎪
⎪
⎪
⎪
⎪
⎪
⎪
Uf
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
∣0⟩ H H ⎭
∣1⟩ H
1 1
H∣0⟩ = √ ∣0⟩ + √ ∣1⟩
2 2
1 1
H∣1⟩ = √ ∣0⟩ − √ ∣1⟩
2 2
1 1 1
H∣a⟩ = √ ∣0⟩ + √ (−1) ∣1⟩ = √ ∑ (−1) ∣b⟩
a ab
2 2 2 b∈{0,1}
Deutsch-Jozsa analysis
The Hadamard operation works like this on standard basis states:
1
H∣a⟩ = √ ∑ (−1) ∣b⟩
ab
2 b∈{0,1}
∣xn−1 ⋯x1 x0 ⟩
⊗n
H
= (H∣xn−1 ⟩) ⊗ ⋯ ⊗ (H∣x0 ⟩)
1 1
= (√ ∑ (−1) ∣yn−1 ⟩) ⊗ ⋯ ⊗ ( √ ∑ (−1) 0 0 ∣y0 ⟩)
xn−1 yn−1 x y
2 yn−1 ∈Σ 2 y0 ∈Σ
1
= √ ∑ (−1) ∣yn−1 ⋯y0 ⟩
xn−1 yn−1 +⋯+x0 y0
2n yn−1 ⋯y0 ∈Σn
Deutsch-Jozsa analysis
∣xn−1 ⋯x1 x0 ⟩
⊗n
H
1
= √ ∑ (−1) ∣yn−1 ⋯y0 ⟩
xn−1 yn−1 +⋯+x0 y0
2n yn−1 ⋯y0 ∈Σn
1
∣x⟩ = √ ∑ (−1) ∣y⟩
⊗n x⋅y
H
2n y∈Σn
x ⋅ y = xn−1 yn−1 ⊕ ⋯ ⊕ x0 y0
⎧
⎪
⎪1 if xn−1 yn−1 + ⋯ + x0 y0 is odd
=⎪
⎨
⎪
⎪
⎪
⎩
0 if xn−1 yn−1 + ⋯ + x0 y0 is even
Deutsch-Jozsa analysis
1
∣x⟩ = √ ∑ (−1) ∣y⟩
⊗n x⋅y
H
2n y∈Σn
∣0⟩ H H
∣0⟩ H H
Uf
∣0⟩ H H
∣1⟩ H
∣π1 ⟩
1
∣π1 ⟩ = ∣−⟩ ⊗ √ ∑ ∣x⟩
2n x∈Σn
Deutsch-Jozsa analysis
1
∣x⟩ = √ ∑ (−1) ∣y⟩
⊗n x⋅y
H
2n y∈Σn
∣0⟩ H H
∣0⟩ H H
Uf
∣0⟩ H H
∣1⟩ H
∣π2 ⟩
1
∣π2 ⟩ = ∣−⟩ ⊗ √ ∑ (−1) ∣x⟩
f(x)
2n x∈Σn
Deutsch-Jozsa analysis
1
∣x⟩ = √ ∑ (−1) ∣y⟩
⊗n x⋅y
H
2n y∈Σn
∣0⟩ H H
∣0⟩ H H
Uf
∣0⟩ H H
∣1⟩ H
∣π3 ⟩
1
∣π3 ⟩ = ∣−⟩ ⊗ ∑ ∑ (−1) ∣y⟩
f(x)+x⋅y
2n
n n
y∈Σ x∈Σ
Deutsch-Jozsa analysis
The probability for the measurements to give y = 0 is
n
22 222
22 1 f(x) 22 1 if f is constant
p(0 ) = 222 n ∑ (−1) 22 = {
22
n
22 2 x∈Σn 22
2 0 if f is balanced
∣0⟩ ⎫
⎪
⎪
⎪
⎪
H H
⎪
⎪
⎪
⎪
⎪
⎪
∣0⟩ ⎪
⎪
⎪
⎪
⎪
⎪
H H
⎪
⎬
⎪
⎪
⎪
s
⎪
⎪
⎪
⎪
⎪
⎪
Uf
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
∣0⟩ H H ⎭
∣1⟩ H
∣π3 ⟩
The Bernstein-Vazirani problem
1
∣π3 ⟩ = ∣−⟩ ⊗ ∑ ∑ (−1) ∣y⟩
f(x)+x⋅y
2n
n n
y∈Σ x∈Σ
1
= ∣−⟩ ⊗ ∑ ∑ (−1) ∣y⟩
s⋅x+y⋅x
2n
n n
y∈Σ x∈Σ
1 (s⊕y)⋅x
= ∣−⟩ ⊗ ∑ ∑ (−1) ∣y⟩
2n
n n
y∈Σ x∈Σ
= ∣−⟩ ⊗ ∣s⟩
n
for all x, y ∈ Σ
Output: The string s
Case 1: s = 0
n
[f(x) = f(y)] ⇔ [x = y]
f(x) = f(x ⊕ s)
x f(x)
s = 011
000 10011
001 00101 f(000) = f(011) = 10011
010 00101
f(001) = f(010) = 00101
011 10011
100 11010 f(100) = f(111) = 11010
101 00001 f(101) = f(110) = 00001
110 00001
111 11010
Simon’s algorithm
Simon’s algorithm consists of running the following circuit several times,
followed by a post-processing step.
∣0⟩ ⎫
⎪
⎪
⎪
H H
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
∣0⟩ ⎪
⎪
⎪
⎪
H H
⎪
⎪
⎬
⎪
n
⎪
y∈Σ
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
∣0⟩ H Uf H ⎪
⎭
∣0⟩
∣0⟩
∣0⟩
Simon’s algorithm analysis
∣0⟩ ⎫
⎪
⎪
⎪
H H
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
∣0⟩ ⎪
⎪
⎪
⎪
H H
⎪
⎪
⎬
⎪
n
⎪
y∈Σ
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
∣0⟩ H Uf H ⎪
⎭
∣0⟩
∣0⟩
∣0⟩
1
∣π1 ⟩ = √ ∑ ∣0 ⟩∣x⟩
m
2 x∈Σn
n
1
∣π2 ⟩ = √ ∑ ∣f(x)⟩∣x⟩
2n x∈Σn
1 ⎛ 1 ⎞ 1
∣π3 ⟩ = √ ∑ ∣f(x)⟩ ⊗ ⎜ √ ∑ (−1) ∣y⟩⎟ = n ∑ ∑ (−1) ∣f(x)⟩∣y⟩
x⋅y x⋅y
2 x∈Σn
n ⎝ 2 y∈Σn
n ⎠ 2
y∈Σn x∈Σn
Simon’s algorithm analysis
1
∑ ∑ (−1) ∣f(x)⟩∣y⟩
x⋅y
2n n n y∈Σ x∈Σ
;
; ;
;
; ;
2
;
;
p(y) = ;
1
∑ (−1) ∣f(x)⟩; ;
;
; ;
x⋅y
;
; 2n ;
;
; x∈Σn ;
;
; ;
;
; ⎛ ⎞ ;
2
;
; ;
;
=; ∑ ⎜ ⎜ ∑ (−1) ⎟ ⎟ ∣z⟩;
1
;
; ;
;
x⋅y
;
; 2n ⎝ ⎠ ;
;
;
; z∈range(f) x∈f (z)
−1 ;
;
22 222
22 22
∑ 2222 ∑ (−1) 2222
1 x⋅y
2 22
=
z∈range(f) 22x∈f−1 ({z}) 22
22n
2
range(f) = {f(x) ∶ x ∈ Σ }
n
({z}) = {x ∈ Σ ∶ f(x) = z}
−1 n
f
Simon’s algorithm analysis
22 222
22 x⋅y 22
2
1 2
∑ 222 ∑ (−1) 222
2 22
p(y) =
z∈range(f) 22x∈f−1 ({z}) 22
22n
2
Case 1: s = 0
n
22 222
22 2
22 ∑ (−1)x⋅y 222 = 1
22 22
22 −1 22
22x∈f ({z}) 22
1 1
⋅2 =
n
p(y) =
22n 2n
n
(for every y ∈ Σ ).
Simon’s algorithm analysis
22 222
22 x⋅y 22
2
1 2
∑ 222 ∑ (−1) 222
2 22
p(y) =
z∈range(f) 22x∈f−1 ({z}) 22
22n
2
/0
n
Case 2: s =
22 222
22 2
22 ∑ (−1)x⋅y 222 = 222(−1)w⋅y + (−1)(w⊕s)⋅y 2222 = 2221 + (−1)s⋅y 2222 = {4 s ⋅ y = 0
22 22 22 22 22 22
22 −1 22 2 2 2 2
22x∈f ({z}) 22
0 s⋅y=1
22 222 ⎧ 1
22 x⋅y 22
2 ⎪
⎪ 2n−1
1 2
∑ 222 ∑ (−1) 222 = ⎪ ⎨
s⋅y=0
p(y) =
2 22 ⎪
⎪
22n z∈range(f) 22x∈f−1 ({z}) 22 ⎪
⎩0
2
s⋅y=1
Classical post-processing
n
Running the circuit from Simon’s algorithm one time gives us a random string y ∈ Σ .
Case 1: s = 0 /0
n n
Case 2: s =
⎧
⎪
⎪
1
⎪
1 s⋅y=0
p(y) = ⎨
2n−1
p(y) = ⎪
⎪
2n ⎪
⎩
0 y⋅s=1
1
Suppose we run the circuit independently k = n + r times, obtaining strings y , . . . , y .
k
⎛yn−1 y0 ⎞ ⎛0⎞
1 1 1 1 1
y = yn−1 ⋯ y0 ⋯
⎜
⎜ 2⎟ ⎛sn−1 ⎞ ⎜ ⎟
⎜
⎜yn−1 y0 ⎟
⎟
⎟ ⎜ ⎟
⎜
⎜
⎜0⎟ ⎟
⎟
2
⎜ ⎟ ⎜ ⎟ ⎜ ⎟
2 2 2
⎜ ⎟ M⎜ ⎟ ⎜ ⎟
y = ⋯ y0 ⋯
M=⎜ ⎟ ⎜ ⎟ ⎜ ⎟
yn−1
⎜
⎜ ⋮ ⋮ ⎟
⎟ ⎜
⎜
⋮ ⎟
⎟ ⎜
= ⎜ ⎟
⎟
⎜
⎜ ⎟
⎟ ⎜ ⎟
⎜ ⎟ ⎝ s0 ⎠ ⎜ ⎟⎜ ⎟
⋮ ⋱ ⋮
k
y = yn−1 ⋯ y0
k k ⎝yk
n−1 ⋯ y0
k⎠ ⎝0⎠
Using Gaussian elimination we can efficiently compute the null space (modulo 2) of M.
With probability greater than 1 − 2 it will be {0 , s}.
−r n
Classical difficulty
Any probabilistic algorithm making fewer than 2 − 1 queries will fail to
n/2−1