Lecture 4.1 - Quantum Query Algorithms
Lecture 4.1 - Quantum Query Algorithms
Contents
Key point
input
⋯ queries
computation output
Queries
Parity
n
Input: f∶Σ →Σ
n
Output: 0 if f(x) = 1 for an even number of strings x ∈ Σ
n
1 if f(x) = 1 for an odd number of strings x ∈ Σ
Minimum
n m
Input: f∶Σ →Σ
n
Output: The string y ∈ {f(x) ∶ x ∈ Σ } that comes first in the
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∶Σ →Σ
n
Promise: There is exactly one string z ∈ Σ for which f(z) = 1,
with f(x) = 0 for all strings x =
/z
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 ⎬
⎪ f(x)
⎪
⎪ ⎪
⎪
⎪
⎪ ⎭
⎩
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:
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 ∈ Σ .
∣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 f(0) 1 f(1)
= (−1) (∣0⟩ − ∣1⟩)∣0⟩ + (−1) (∣0⟩ − ∣1⟩)∣1⟩
2 2
f(0) f(1)
(−1) ∣0⟩ + (−1) ∣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
f(0) f(1)
(−1) ∣0⟩ + (−1) ∣1⟩
∣π2 ⟩ = ∣−⟩ ( √ )
2
f(0)⊕f(1)
f(0) ∣0⟩ + (−1) ∣1⟩
= (−1) ∣−⟩( √ )
2
⎧
⎪ f(0)
⎪(−1) ∣−⟩∣+⟩ f(0) ⊕ f(1) = 0
=⎪
⎨
⎪
⎪
⎪(−1)
f(0)
∣−⟩∣−⟩ f(0) ⊕ f(1) = 1
⎩
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
⎧
⎪ f(0)
⎪(−1) ∣−⟩∣+⟩ f(0) ⊕ f(1) = 0
∣π2 ⟩ = ⎪
⎨
⎪
⎪
⎪(−1)
f(0)
∣−⟩∣−⟩ f(0) ⊕ f(1) = 1
⎩
⎧
⎪ f(0)
⎪(−1) ∣−⟩∣0⟩ f(0) ⊕ f(1) = 0
∣π3 ⟩ = ⎪
⎨
⎪
⎪
⎪(−1)
f(0)
∣−⟩∣1⟩ f(0) ⊕ f(1) = 1
⎩
f(0)
= (−1) ∣−⟩∣f(0) ⊕ f(1)⟩
Phase kickback
0 if f is constant
∣0⟩ H H {
1 if f is balanced
Uf
∣1⟩ H
c
∣b ⊕ c⟩ = X ∣b⟩
f(a)
Uf (∣b⟩∣a⟩) = ∣b ⊕ f(a)⟩∣a⟩ = (X ∣b⟩)∣a⟩
f(a) f(a)
Uf (∣−⟩∣a⟩) = (X ∣−⟩)∣a⟩ = (−1) ∣−⟩∣a⟩
f(a) phase
Uf (∣−⟩∣a⟩) = (−1) ∣−⟩∣a⟩ ⟵
kickback
Phase kickback
0 if f is constant
∣0⟩ H H {
1 if f is balanced
Uf
∣1⟩ H
f(a) phase
Uf (∣−⟩∣a⟩) = (−1) ∣−⟩∣a⟩ ⟵
kickback
∣π1 ⟩ = ∣−⟩∣+⟩
1 1
∣π2 ⟩ = Uf (∣−⟩∣+⟩) = √ Uf (∣−⟩∣0⟩) + √ Uf (∣−⟩∣1⟩)
2 2
f(0) f(1)
(−1) ∣0⟩ + (−1) ∣1⟩
= ∣−⟩( √ )
2
The Deutsch-Jozsa circuit
The Deutsch-Jozsa algorithm extends Deutsch’s algorithm to input functions of
n
the form f ∶ Σ → Σ for any n ≥ 1.
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
n
f ∶ Σ → Σ, the task is to output 0 if f is constant and 1 if f is balanced.
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
n
Output: 0 if y = 0 and 1 otherwise.
Deutsch-Jozsa analysis
The Hadamard operation works like this on standard basis states:
1 1
H∣0⟩ = √ ∣0⟩ + √ ∣1⟩
2 2
1 1
H∣1⟩ = √ ∣0⟩ − √ ∣1⟩
2 2
1 1 a 1 ab
H∣a⟩ = √ ∣0⟩ + √ (−1) ∣1⟩ = √ ∑ (−1) ∣b⟩
2 2 2 b∈{0,1}
Deutsch-Jozsa analysis
The Hadamard operation works like this on standard basis states:
1 ab
H∣a⟩ = √ ∑ (−1) ∣b⟩
2 b∈{0,1}
⊗n
H ∣xn−1 ⋯x1 x0 ⟩
= (H∣xn−1 ⟩) ⊗ ⋯ ⊗ (H∣x0 ⟩)
1 xn−1 yn−1 1 x y
= (√ ∑ (−1) ∣yn−1 ⟩) ⊗ ⋯ ⊗ ( √ ∑ (−1) 0 0 ∣y0 ⟩)
2 yn−1 ∈Σ 2 y0 ∈Σ
1 xn−1 yn−1 +⋯+x0 y0
= √ ∑ (−1) ∣yn−1 ⋯y0 ⟩
2n yn−1 ⋯y0 ∈Σn
Deutsch-Jozsa analysis
⊗n
H ∣xn−1 ⋯x1 x0 ⟩
1 xn−1 yn−1 +⋯+x0 y0
= √ ∑ (−1) ∣yn−1 ⋯y0 ⟩
2n yn−1 ⋯y0 ∈Σn
⊗n 1 x⋅y
H ∣x⟩ = √ ∑ (−1) ∣y⟩
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
⊗n 1 x⋅y
H ∣x⟩ = √ ∑ (−1) ∣y⟩
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
⊗n 1 x⋅y
H ∣x⟩ = √ ∑ (−1) ∣y⟩
2n y∈Σn
∣0⟩ H H
∣0⟩ H H
Uf
∣0⟩ H H
∣1⟩ H
∣π2 ⟩
1 f(x)
∣π2 ⟩ = ∣−⟩ ⊗ √ ∑ (−1) ∣x⟩
2n x∈Σn
Deutsch-Jozsa analysis
⊗n 1 x⋅y
H ∣x⟩ = √ ∑ (−1) ∣y⟩
2n y∈Σn
∣0⟩ H H
∣0⟩ H H
Uf
∣0⟩ H H
∣1⟩ H
∣π3 ⟩
1 f(x)+x⋅y
∣π3 ⟩ = ∣−⟩ ⊗ ∑ ∑ (−1) ∣y⟩
2n n n
y∈Σ x∈Σ
Deutsch-Jozsa analysis
n
The probability for the measurements to give y = 0 is
»» »»2
» 1 f(x) »» 1 if f is constant
p(0 ) = »»»» n ∑ (−1) »» = {
n
»» 2 x∈Σn »» 0 if f is balanced
» »»
∣0⟩ H H ⎫
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
∣0⟩ H H ⎪
⎪
⎪
⎪
⎪
⎪
⎬
⎪ s
⎪
⎪
⎪
⎪
Uf ⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
⎪
∣0⟩ H H ⎭
∣1⟩ H
∣π3 ⟩
The Bernstein-Vazirani problem
1 f(x)+x⋅y
∣π3 ⟩ = ∣−⟩ ⊗ ∑ ∑ (−1) ∣y⟩
2n n n
y∈Σ x∈Σ
1 s⋅x+y⋅x
= ∣−⟩ ⊗ n ∑ ∑ (−1) ∣y⟩
2 n ny∈Σ x∈Σ
1 (s⊕y)⋅x
= ∣−⟩ ⊗ n ∑ ∑ (−1) ∣y⟩
2 n ny∈Σ x∈Σ
= ∣−⟩ ⊗ ∣s⟩
n
for all x, y ∈ Σ
Output: The string s
n
Case 1: s = 0
[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 m
∣π1 ⟩ = √ ∑ ∣0 ⟩∣x⟩
2n x∈Σn
1
∣π2 ⟩ = √ ∑ ∣f(x)⟩∣x⟩
2n x∈Σn
1 ⎛ 1 x⋅y ⎞ 1 x⋅y
∣π3 ⟩ = √ ∑ ∣f(x)⟩ ⊗ ⎜ √ ∑ (−1) ∣y⟩⎟ = n ∑ ∑ (−1) ∣f(x)⟩∣y⟩
2n x∈Σn ⎝ 2n y∈Σn ⎠ 2
y∈Σn x∈Σn
Simon’s algorithm analysis
1 x⋅y
∑ ∑ (−1) ∣f(x)⟩∣y⟩
2n n n y∈Σ x∈Σ
Â
 Â
 2
 1 Â
p(y) = Â
 ∣f(x)⟩Â
Â
x⋅y
Â
 n ∑ (−1) Â
Â
Â
 2 Â
Â
 x∈Σn Â
Â
 Â
 2
Â
 1 ⎛ ⎞ Â
Â
=ÂÂ ∑ ⎜ ⎜ ∑ (−1) ⎟
Â
⎟ ∣z⟩Â
x⋅y
 2n
 Â
Â
Â
 z∈range(f) ⎝x∈f−1 (z) ⎠ Â
Â
Â
 Â
Â
»» »»2
»» »
=
1
∑ »» ∑ (−1)x⋅y »»»
»» »»
22n »
z∈range(f) »»x∈f−1 ({z})
»»
» »»
n
range(f) = {f(x) ∶ x ∈ Σ }
−1 n
f ({z}) = {x ∈ Σ ∶ f(x) = z}
Simon’s algorithm analysis
»» »»2
»» »
p(y) =
1
∑ »» ∑ (−1)x⋅y »»»
»» »»
22n »
z∈range(f) »»x∈f−1 ({z})
»»
» »»
n
Case 1: s = 0
−1
Because f is a one-to-one, there a single element x ∈ f ({z}) for every z ∈ range(f):
»» »»»2
»»
»» ∑ (−1)x⋅y »»» = 1
»» »»
»» −1 »»
»»x∈f ({z}) »»
n
There are 2 elements in range(f), so
1 n 1
p(y) = ⋅2 = n
22n 2
n
(for every y ∈ Σ ).
Simon’s algorithm analysis
»» »»2
»» »
p(y) =
1
∑ »» ∑ (−1)x⋅y »»»
»» »»
22n »
z∈range(f) »»x∈f−1 ({z})
»»
» »»
n
Case 2: s =
/0
−1 −1
There are two strings in the set f ({z}) for each z ∈ range(f); if w ∈ f ({z}) either one
of them, then w ⊕ s is the other.
»» »»2
»» »
»» ∑ (−1)x⋅y »»» = »»»(−1)w⋅y + (−1)(w⊕s)⋅y »»»2 = »»»1 + (−1)s⋅y »»»2 = {4 s ⋅ y = 0
»» »» »»» »» »»» »»
»» −1 »» » » 0 s⋅y=1
»»x∈f ({z}) »»
n−1
There are 2 elements in range(f), so
»» »»2 ⎧ 1
»» » ⎪ n−1 s⋅y=0
p(y) =
1
∑ »» ∑ (−1)x⋅y »»» = ⎪⎪
⎨ 2
»» »» ⎪
22n »
»
z∈range(f) »x∈f ({z})
»
» ⎪0
⎪ s⋅y=1
»
−1 »» ⎩
Classical post-processing
n
Running the circuit from Simon’s algorithm one time gives us a random string y ∈ Σ .
n n
Case 1: s = 0 Case 2: s =
/0
⎧
⎪ 1
s⋅y=0
1 ⎪ 2n−1
p(y) = p(y) = ⎪
⎨
⎪0
2n ⎪
⎪ y⋅s=1
⎩
1 k
Suppose we run the circuit independently k = n + r times, obtaining strings y , . . . , y .
1 1 1 1 1
y = yn−1 ⋯ y0 ⎛yn−1 ⋯ y0 ⎞ ⎛0⎞
⎜
⎜ 2⎟ ⎜ ⎟
⎛sn−1 ⎞ ⎜
2
y =
2
yn−1
2
⋯ y0 ⎜y2n−1
⎜ ⋯ y0 ⎟
⎟
⎟ ⎜ ⎟ ⎜0⎟
⎜ ⎟
⎟=⎜
⎟
M=⎜
⎜
⎜
⎜
⎟
⎟
⎟ M⎜
⎜ ⋮ ⎟
⎜ ⎜ ⎟
⎟ ⎜
⎟
⎟
⋮ ⎜ ⋮
⎜
⎜ ⋱ ⋮ ⎟
⎟
⎟
⎟
⎜
⎜ ⎟ ⎜
⎟ ⎜ ⋮
⎜ ⎟
⎜
⎟
⎟
⎟
⎜ ⎟ ⎝ s0 ⎠ ⎜ ⎟
k
y = yn−1 ⋯ y0
k k ⎝ykn−1 ⋯ y0
k⎠ ⎝0⎠
Using Gaussian elimination we can efficiently compute the null space (modulo 2) of M.
−r n
With probability greater than 1 − 2 it will be {0 , s}.
Classical difficulty
n/2−1
Any probabilistic algorithm making fewer than 2 − 1 queries will fail to
solve Simon’s problem with probability at least 1/2.