Intro To Quantum Algorithms
Intro To Quantum Algorithms
9th of September
Quantum algorithms
1 / 39
Quantum algorithms
1 / 39
Quantum algorithms
1 / 39
Quantum algorithms
1 / 39
Quantum algorithms
1 / 39
Overview
2 / 39
Overview
2 / 39
Overview
2 / 39
Overview
2 / 39
Overview
2 / 39
Overview
2 / 39
Basics
Quantum states
3 / 39
Quantum states
3 / 39
Quantum states
3 / 39
Quantum states
3 / 39
Quantum states
3 / 39
Quantum gates
4 / 39
Quantum gates
4 / 39
Quantum gates
1 1 1
„ „
1 0
Z :“ , H :“ ? .
0 ´1 2 1 ´1
4 / 39
Quantum gates
1 1 1
„ „
1 0
Z :“ , H :“ ? .
0 ´1 2 1 ´1
I does nothing.
4 / 39
Quantum gates
1 1 1
„ „
1 0
Z :“ , H :“ ? .
0 ´1 2 1 ´1
I does nothing.
X changes |0y into |1y and vice versa.
4 / 39
Quantum gates
1 1 1
„ „
1 0
Z :“ , H :“ ? .
0 ´1 2 1 ´1
I does nothing.
X changes |0y into |1y and vice versa.
Z adds a ´1 in front of |1y.
4 / 39
Quantum gates
1 1 1
„ „
1 0
Z :“ , H :“ ? .
0 ´1 2 1 ´1
I does nothing.
X changes |0y into |1y and vice versa.
Z adds a ´1 in front of |1y.
|0y`|1y |0y´|1y
H changes |0y and |1y into ?
2
and ?
2
.
4 / 39
Changing the basis
Claim: H is a basis transform
5 / 39
Changing the basis
Claim: H is a basis transform
|0y ` |1y |0y ´ |1y
|`y :“ ? |´y :“ ?
2 2
5 / 39
Changing the basis
Claim: H is a basis transform
|0y ` |1y |0y ´ |1y
|`y :“ ? |´y :“ ?
2 2
|1y
|0y
5 / 39
Changing the basis
Claim: H is a basis transform
|0y ` |1y |0y ´ |1y
|`y :“ ? |´y :“ ?
2 2
|1y
|`y
|0y
|´y
5 / 39
A first circuit
H Z H
What does this circuit do? We only need to try a basis (Why?).
6 / 39
A first circuit
H Z H
What does this circuit do? We only need to try a basis (Why?).
On |0y:
|0y ` |1y
|0y ÞÑ ?
2
6 / 39
A first circuit
H Z H
What does this circuit do? We only need to try a basis (Why?).
On |0y:
6 / 39
A first circuit
H Z H
What does this circuit do? We only need to try a basis (Why?).
On |0y:
6 / 39
A first circuit
H Z H
What does this circuit do? We only need to try a basis (Why?).
On |0y:
6 / 39
A first circuit
H Z H
What does this circuit do? We only need to try a basis (Why?).
On |0y:
On |1y:
|0y ´ |1y
|1y ÞÑ ?
2
6 / 39
A first circuit
H Z H
What does this circuit do? We only need to try a basis (Why?).
On |0y:
On |1y:
6 / 39
A first circuit
H Z H
What does this circuit do? We only need to try a basis (Why?).
On |0y:
On |1y:
6 / 39
A first circuit
H Z H
What does this circuit do? We only need to try a basis (Why?).
On |0y:
On |1y:
This is a X gate!
6 / 39
A first circuit
H Z H
What does this circuit do? We only need to try a basis (Why?).
On |0y:
On |1y:
This is a X gate! Z is just X in the t|`y , |´yu basis (and vice versa).
6 / 39
Reflections
|1y
|`y
|0y
|´y
7 / 39
Reflections
|1y
|`y
|0y
|´y
7 / 39
Reflections
|0y
|´y
7 / 39
More gates
8 / 39
More gates
8 / 39
More gates
8 / 39
More gates
‚ “
8 / 39
More gates
1 0 0 0
» fi
—0 1 0 0ffi
‚ “ ‚ “—
–0
ffi
0 0 1fl
0 0 1 0
X
8 / 39
Oracles
9 / 39
Oracles
9 / 39
Oracles
9 / 39
Oracles
Ox |iy|by “ |iy|b ‘ xi y
9 / 39
Oracles
Ox |iy|by “ |iy|b ‘ xi y
9 / 39
Oracles
Ox |iy|by “ |iy|b ‘ xi y
Ox,˘ |iy |0y “ |iy |0y , Ox,˘ |iy |1y “ p´1qxi |iy |1y
9 / 39
Interpreting oracles
Ox |iy|by “ |iy|b ‘ xi y
10 / 39
Interpreting oracles
10 / 39
Interpreting oracles
So a X is applied to b if xi “ 1.
10 / 39
Interpreting oracles
So a X is applied to b if xi “ 1.
Let us look closer at a controlled phase oracle.
#
|iy|by if xi “ 0
Ox,˘ |iy|by “
|iy Z |by if xi “ 1
10 / 39
Interpreting oracles
So a X is applied to b if xi “ 1.
Let us look closer at a controlled phase oracle.
#
|iy|by if xi “ 0
Ox,˘ |iy|by “
|iy Z |by if xi “ 1
A Z is applied to b if xi “ 1.
10 / 39
Interpreting oracles
So a X is applied to b if xi “ 1.
Let us look closer at a controlled phase oracle.
#
|iy|by if xi “ 0
Ox,˘ |iy|by “
|iy Z |by if xi “ 1
A Z is applied to b if xi “ 1.
How would you convert between the two types of oracle?
10 / 39
Amplitude amplification
Randomized algorithms
11 / 39
Randomized algorithms
11 / 39
Randomized algorithms
11 / 39
Randomized algorithms
11 / 39
Randomized algorithms
11 / 39
Randomized algorithms
11 / 39
Randomized algorithms
11 / 39
Randomized algorithms
11 / 39
Randomized algorithms
11 / 39
Example: prime finding
12 / 39
Example: prime finding
12 / 39
Example: prime finding
12 / 39
Quantum algorithms with small success probability
Back to quantum:
13 / 39
Quantum algorithms with small success probability
Back to quantum:
Quantum algorithms are inherently random.
13 / 39
Quantum algorithms with small success probability
Back to quantum:
Quantum algorithms are inherently random.
A Hadamard gate can be used to flip a coin:
1
H |0y “ ? p|0y ` |1yq
2
13 / 39
Quantum algorithms with small success probability
Back to quantum:
Quantum algorithms are inherently random.
A Hadamard gate can be used to flip a coin:
1
H |0y “ ? p|0y ` |1yq
2
13 / 39
Quantum algorithms with small success probability
Back to quantum:
Quantum algorithms are inherently random.
A Hadamard gate can be used to flip a coin:
1
H |0y “ ? p|0y ` |1yq
2
|Gy |1y is the “Good” part of the state, |By |0y is the “Bad” part.
13 / 39
Quantum algorithms with small success probability
Back to quantum:
Quantum algorithms are inherently random.
A Hadamard gate can be used to flip a coin:
1
H |0y “ ? p|0y ` |1yq
2
|Gy |1y is the “Good” part of the state, |By |0y is the “Bad” part.
Is we just measure then the success probability is p “ |αG |2 .
13 / 39
Three states
14 / 39
Three states
14 / 39
Three states
14 / 39
Three states
14 / 39
Three states
14 / 39
Three states
14 / 39
Three states - a picture
|Gy|1y
|By|0y
Three states - a picture
|Gy|1y
|ψy
|By|0y
|Gy|1y
|ψy
|By|0y
|Gy|1y
|ψy
θ |By|0y
|Gy|1y
|ψy
θ |By|0y
θ
|ψ 1 y
|Gy|1y
|ψ 2 y
|ψy
θ |By|0y
θ
|ψ 1 y
|Gy|1y
|ψ 2 y
2θ |ψy
θ |By|0y
θ
|ψ 1 y
|Gy|1y
|ψ 2 y
2θ |ψy
θ |By|0y
θ
|ψ 1 y
15 / 39
Amplitude amplification
16 / 39
Amplitude amplification
16 / 39
Amplitude amplification
sin pp2k ` 1qθq |Gy |1y ` cos pp2k ` 1qθq |By |0y
16 / 39
Amplitude amplification
sin pp2k ` 1qθq |Gy |1y ` cos pp2k ` 1qθq |By |0y
16 / 39
Amplitude amplification
sin pp2k ` 1qθq |Gy |1y ` cos pp2k ` 1qθq |By |0y
16 / 39
Amplitude amplification
sin pp2k ` 1qθq |Gy |1y ` cos pp2k ` 1qθq |By |0y
1
ˆ ˙ ˆ ˙
π
k« ´ 1 {2 “ O
2 arcsin αG |αG |
16 / 39
Amplitude amplification
sin pp2k ` 1qθq |Gy |1y ` cos pp2k ` 1qθq |By |0y
1 1
ˆ ˙ ˆ ˙ ˆ ˙
π
k« ´ 1 {2 “ O “O ?
2 arcsin αG |αG | p
16 / 39
Amplitude amplification
sin pp2k ` 1qθq |Gy |1y ` cos pp2k ` 1qθq |By |0y
1 1
ˆ ˙ ˆ ˙ ˆ ˙
π
k« ´ 1 {2 “ O “O ?
2 arcsin αG |αG | p
16 / 39
Implementing the reflections
17 / 39
Implementing the reflections
17 / 39
Implementing the reflections
17 / 39
Implementing the reflections
17 / 39
Implementing the reflections
17 / 39
Implementing the reflections
17 / 39
Example: the search problem
18 / 39
Example: the search problem
Search problem
Input: x P t0, 1un with k ones.
Goal: Find an i such that xi “ 1 with few queries.
18 / 39
Example: the search problem
Search problem
Input: x P t0, 1un with k ones.
Goal: Find an i such that xi “ 1 with few queries.
18 / 39
Example: the search problem
Search problem
Input: x P t0, 1un with k ones.
Goal: Find an i such that xi “ 1 with few queries.
18 / 39
Example: the search problem
Search problem
Input: x P t0, 1un with k ones.
Goal: Find an i such that xi “ 1 with few queries.
18 / 39
Example: the search problem
19 / 39
Example: the search problem
19 / 39
Example: the search problem
Query in superposition
n
1 ÿ
? |iy |xi y
n i“0
19 / 39
Example: the search problem
Query in superposition
n
˜ ¸
1 ÿ ÿ
? |iy |xi y “ |iy |1y
n i“0 i:xi “1
19 / 39
Example: the search problem
Query in superposition
n
˜ ¸
1 ÿ 1 ÿ
? |iy |xi y “ ? |iy |1y
n i“0 k i:xi “1
19 / 39
Example: the search problem
Query in superposition
n
c ˜ ¸
1 ÿ k 1 ÿ
? |iy |xi y “ ? |iy |1y
n i“0 n k i:x “1
i
19 / 39
Example: the search problem
Query in superposition
n
c ˜ ¸
1 ÿ k 1 ÿ
? |iy |xi y “ ? |iy |1y ` p. . . q |0y
n i“0 n k i:x “1i
19 / 39
Example: the search problem
Query in superposition
n
c ˜ ¸
1 ÿ k 1 ÿ
? |iy |xi y “ ? |iy |1y ` p. . . q |0y
n i“0 n k i:x “1i
`a n ˘
With O k iterations we are done!
19 / 39
Phase estimation
Eigenvalues of unitaries
20 / 39
Eigenvalues of unitaries
For example
Z |0y “ 1 ¨ |0y
20 / 39
Eigenvalues of unitaries
For example
Z |0y “ 1 ¨ |0y
Z |1y “ ´1 ¨ |1y
20 / 39
Eigenvalues of unitaries
For example
Z |0y “ 1 ¨ |0y
Z |1y “ ´1 ¨ |1y
In general for a unitary U and eigenvector |ψy of U:
20 / 39
Goal of phase estimation
Goal
Given a U and |ψy, s.t.,
21 / 39
Goal of phase estimation
Goal
Given a U and |ψy, s.t.,
21 / 39
Goal of phase estimation
Goal
Given a U and |ψy, s.t.,
21 / 39
Goal of phase estimation
Goal
Given a U and |ψy, s.t.,
21 / 39
A `1 or ´1 eigenvalue
22 / 39
A `1 or ´1 eigenvalue
|0y H ‚ H
|ψy U
22 / 39
A `1 or ´1 eigenvalue
|0y H ‚ H
|ψy U
1
Let’s check this for a ´1 “ ei2π 2 phase:
22 / 39
A `1 or ´1 eigenvalue
|0y H ‚ H
|ψy U
1
Let’s check this for a ´1 “ ei2π 2 phase:
We start in |0y|ψy.
22 / 39
A `1 or ´1 eigenvalue
|0y H ‚ H
|ψy U
1
Let’s check this for a ´1 “ ei2π 2 phase:
We start in |0y|ψy.
We apply H to get ?1 p|0y|ψy ` |1y|ψyq.
2
22 / 39
A `1 or ´1 eigenvalue
|0y H ‚ H
|ψy U
1
Let’s check this for a ´1 “ ei2π 2 phase:
We start in |0y|ψy.
We apply H to get ?1 p|0y|ψy ` |1y|ψyq.
2
We apply U only to the |1y part:
?1 p|0y|ψy ` |1y U |ψyq “ ?1 p|0y|ψy ´ |1y |ψyq.
2 2
22 / 39
A `1 or ´1 eigenvalue
|0y H ‚ H
|ψy U
1
Let’s check this for a ´1 “ ei2π 2 phase:
We start in |0y|ψy.
We apply H to get ?1 p|0y|ψy ` |1y|ψyq.
2
We apply U only to the |1y part:
?1 p|0y|ψy ` |1y U |ψyq “ ?1 p|0y|ψy ´ |1y |ψyq.
2 2
We apply H again and get |1y|ψy.
22 / 39
A bit about binary
What if we want to estimate other phases as well?
23 / 39
A bit about binary
What if we want to estimate other phases as well?
In general a phase is ei2πθ .
23 / 39
A bit about binary
What if we want to estimate other phases as well?
In general a phase is ei2πθ .
We can write θ in binary:
θ “ 10.110101
23 / 39
A bit about binary
What if we want to estimate other phases as well?
In general a phase is ei2πθ .
We can write θ in binary:
θ “ 10.110101
23 / 39
A bit about binary
What if we want to estimate other phases as well?
In general a phase is ei2πθ .
We can write θ in binary:
θ “ 10.110101
23 / 39
A bit about binary
What if we want to estimate other phases as well?
In general a phase is ei2πθ .
We can write θ in binary:
θ “ 10.110101
23 / 39
A bit about binary
What if we want to estimate other phases as well?
In general a phase is ei2πθ .
We can write θ in binary:
θ “ 10.110101
24 / 39
Last bit phase estimation
24 / 39
Last bit phase estimation
24 / 39
Last bit phase estimation
|0y H ‚ H |b1 y
|ψy U4 |ψy
24 / 39
Two bit phase estimation
25 / 39
Two bit phase estimation
25 / 39
Two bit phase estimation
25 / 39
Two bit phase estimation
|0y H ‚ ‚ H |b2 y
|0y H ‚ H |b1 y
|ψy U4 |ψy U2 e´i2π0.0b1 I |ψy
25 / 39
Two bit phase estimation
|0y H ‚ ‚ H |b2 y
|0y H ‚ H |b1 y
|ψy U4 |ψy U2 e´i2π0.0b1 I |ψy
25 / 39
Three bit phase estimation
Let U |ψy “ ei2πθ |ψy for θ “ 0.b3 b2 b1 , can we calculate all the bits?
26 / 39
Three bit phase estimation
Let U |ψy “ ei2πθ |ψy for θ “ 0.b3 b2 b1 , can we calculate all the bits?
Yes! just keep going:
|0y H ‚ ‚ H |b2 y ¨ ¨ ¨
|0y H ‚ H |b1 y ¨¨¨
|ψy U4 |ψy U2 e´i2π0.0b1 I |ψy ¨ ¨ ¨
26 / 39
Clean up
27 / 39
Clean up
27 / 39
Clean up
27 / 39
Clean up
27 / 39
Clean up
27 / 39
Clean up
27 / 39
The inverse quantum Fourier transform
|0y H ‚ ‚ H |b2 y ¨ ¨ ¨
|0y H ‚ H |b1 y ¨¨¨
|ψy U4 |ψy U2 e´i2π0.0b1 I |ψy ¨ ¨ ¨
28 / 39
The inverse quantum Fourier transform
28 / 39
The inverse quantum Fourier transform
|0y H ‚ ´π{2 H ‚
|0y H ‚ H ‚ ‚
|ψy U4 U2 U1
28 / 39
The inverse quantum Fourier transform
28 / 39
The inverse quantum Fourier transform
(The inverse quantum Fourier transform actually also swaps the order
of the qubits, but this does not matter for our purpose)
28 / 39
The inverse quantum Fourier transform
(The inverse quantum Fourier transform actually also swaps the order
of the qubits, but this does not matter for our purpose)
1
In total we need to apply Uk for k „ ε
28 / 39
Example: finding an eigenvector
29 / 39
Example: finding an eigenvector
29 / 39
Example: finding an eigenvector
29 / 39
Example: finding an eigenvector
29 / 39
Amplitude estimation
A problem with amplitude amplification
30 / 39
A problem with amplitude amplification
30 / 39
A problem with amplitude amplification
30 / 39
A problem with amplitude amplification
30 / 39
A problem with amplitude amplification
30 / 39
A problem with amplitude amplification
30 / 39
A closer look at the amplitude amplification iterate
31 / 39
A closer look at the amplitude amplification iterate
31 / 39
A closer look at the amplitude amplification iterate
ei2θ , e´i2θ
31 / 39
A closer look at the amplitude amplification iterate
ei2θ , e´i2θ
31 / 39
Amplitude estimation
Amplitude estimation
Input: A unitary that prepares
32 / 39
Amplitude estimation
Amplitude estimation
Input: A unitary that prepares
32 / 39
Amplitude estimation
Amplitude estimation
Input: A unitary that prepares
32 / 39
Amplitude estimation
Amplitude estimation
Input: A unitary that prepares
32 / 39
Amplitude estimation
Amplitude estimation
Input: A unitary that prepares
32 / 39
Amplitude estimation
Amplitude estimation
Input: A unitary that prepares
32 / 39
Example: Speeding up Monte Carlo methods
33 / 39
Example: Speeding up Monte Carlo methods
33 / 39
Example: Speeding up Monte Carlo methods
33 / 39
Example: Speeding up Monte Carlo methods
33 / 39
Example: Speeding up Monte Carlo methods
33 / 39
Example: Speeding up Monte Carlo methods
33 / 39
Example: Speeding up Monte Carlo methods
33 / 39
Example: Speeding up Monte Carlo methods
33 / 39
Example: Speeding up Monte Carlo methods
33 / 39
Example: Speeding up Monte Carlo methods
1
A classical algorithm requires „ ε2
samples to estimate, quantum 1ε .
33 / 39
Overview of some other algo-
rithms
Some other algorithms
There are many more quantum algorithms, often using the discoed
techniques. We will quickly discuss some other important algorithms:
Shor’s algorithm & factoring integers
HHL for “solving” linear systems
Faster gradient computation
34 / 39
Factoring
35 / 39
Factoring
15 “
35 / 39
Factoring
15 “ 3 ˆ 5
35 / 39
Factoring
15 “ 3 ˆ 5
391 “
35 / 39
Factoring
15 “ 3 ˆ 5
391 “ 17 ˆ 23
35 / 39
Factoring
15 “ 3 ˆ 5
391 “ 17 ˆ 23
35 / 39
Factoring
15 “ 3 ˆ 5
391 “ 17 ˆ 23
35 / 39
Factoring
15 “ 3 ˆ 5
391 “ 17 ˆ 23
35 / 39
Shor’s factoring algorithm (’94)
A rough sketch:
36 / 39
Shor’s factoring algorithm (’94)
A rough sketch:
A function f is periodic if fpaq “ fpbq ô b “ a ` t ¨ k for the
period k and some t.
36 / 39
Shor’s factoring algorithm (’94)
A rough sketch:
A function f is periodic if fpaq “ fpbq ô b “ a ` t ¨ k for the
period k and some t.
Classical literature: Factoring is equivalent to period finding for
fpxq “ ax mod N
36 / 39
Shor’s factoring algorithm (’94)
A rough sketch:
A function f is periodic if fpaq “ fpbq ô b “ a ` t ¨ k for the
period k and some t.
Classical literature: Factoring is equivalent to period finding for
fpxq “ ax mod N
36 / 39
Shor’s factoring algorithm (’94)
A rough sketch:
A function f is periodic if fpaq “ fpbq ô b “ a ` t ¨ k for the
period k and some t.
Classical literature: Factoring is equivalent to period finding for
fpxq “ ax mod N
36 / 39
Shor’s factoring algorithm (’94)
A rough sketch:
A function f is periodic if fpaq “ fpbq ô b “ a ` t ¨ k for the
period k and some t.
Classical literature: Factoring is equivalent to period finding for
fpxq “ ax mod N
36 / 39
Shor’s factoring algorithm (’94)
A rough sketch:
A function f is periodic if fpaq “ fpbq ô b “ a ` t ¨ k for the
period k and some t.
Classical literature: Factoring is equivalent to period finding for
fpxq “ ax mod N
36 / 39
Shor’s factoring algorithm (’94)
A rough sketch:
A function f is periodic if fpaq “ fpbq ô b “ a ` t ¨ k for the
period k and some t.
Classical literature: Factoring is equivalent to period finding for
fpxq “ ax mod N
36 / 39
Shor’s factoring algorithm (’94)
A rough sketch:
A function f is periodic if fpaq “ fpbq ô b “ a ` t ¨ k for the
period k and some t.
Classical literature: Factoring is equivalent to period finding for
fpxq “ ax mod N
36 / 39
HHL algorithm for systems of linear equations
37 / 39
HHL algorithm for systems of linear equations
37 / 39
HHL algorithm for systems of linear equations
37 / 39
HHL algorithm for systems of linear equations
Takes only O
r psκq time
37 / 39
HHL algorithm for systems of linear equations
Takes only O
r psκq time, but is not the same problem!
37 / 39
Gradient computation (Jordan ’05)
Gradient computation
Given black-box access to a function f : Rn Ñ R, estimate the
gradient at 0.
38 / 39
Gradient computation (Jordan ’05)
Gradient computation
Given black-box access to a function f : Rn Ñ R, estimate the
gradient at 0.
38 / 39
Gradient computation (Jordan ’05)
Gradient computation
Given black-box access to a function f : Rn Ñ R, estimate the
gradient at 0.
38 / 39
Gradient computation (Jordan ’05)
Gradient computation
Given black-box access to a function f : Rn Ñ R, estimate the
gradient at 0.
38 / 39
Gradient computation (Jordan ’05)
Gradient computation
Given black-box access to a function f : Rn Ñ R, estimate the
gradient at 0.
38 / 39
Gradient computation (Jordan ’05)
Gradient computation
Given black-box access to a function f : Rn Ñ R, estimate the
gradient at 0.
38 / 39
Gradient computation (Jordan ’05)
Gradient computation
Given black-box access to a function f : Rn Ñ R, estimate the
gradient at 0.
38 / 39
Gradient computation (Jordan ’05)
Gradient computation
Given black-box access to a function f : Rn Ñ R, estimate the
gradient at 0.
39 / 39
A quiz
39 / 39
A quiz
39 / 39
A quiz
39 / 39
A quiz
39 / 39
A quiz
39 / 39
A quiz
39 / 39
That was it!