QAP Algorithms With Function Oracle and Phase Kickback
QAP Algorithms With Function Oracle and Phase Kickback
1/44
Introduction
⇒ Deutsch’s Algorithm
⇒ Deutsch Jozsa’s Algorithm
⇒ Bernstein Vazirani Algorithm
2/44
Deutsch’s Algorithm
3/44
Constant and Balanced Function
Tables for Constant Function:
X f(X) X f(X)
0 0 0 1
1 0 1 1
X f(X) X f(X)
0 1 0 0
1 0 1 1
⇒ We need to check if
f (0) = f (1)?
5/44
Reversible Gates
⇒ In quantum computation all gates and operation must be
reversible.
⇒ Reversible gates or reversible logic gates are the gates with a
property of equal number of inputs and outputs
⇒ Example of non-reversible classical gate: AND Gate and Its
conversion to reversible gate
*When C=0 output of this gate will be that of a AND gate 6/44
Quantum Oracle
⇒ We use technique above to build quantum oracles.
⇒ We have seen Grover’s Oracle before.
⇒ Here |x⟩ is input to function and |y ⟩ is target qubit where
output is to written. This ensures that oracle is reversible.
⇒ This would mean |x⟩|y ⟩ → |x⟩|y ⊕ f (x)⟩
⇒ It is important to note that x, y and f (x) are bits and |x⟩, |y ⟩
and |f (x)⟩ are quantum states
⇒ As we have seen in last table when y=0,
Since 0 ⊕ 0 = 0 and 0 ⊕ 1 = 1
x y x y ⊕ f (x)
x 0 x f (x)
x 1 x f (x)
Figure: A Basic Function Oracle Table: Function Oracle Table
7/44
Basis States
8/44
Phase of Qubit
|0⟩ → θ = 0, sin θ = 0
|1⟩ → θ = π, sin θ = 0
π
|+⟩ → θ = , sin θ = 1
2
3π
|−⟩ → θ = , sin θ = −1
2
9/44
Phase Oracle
3π
⇒ Let’s set the target qubit to |−⟩. (θ = 2 , sin θ = −1)
⇒ Here we get something called as phase kickback.
⇒ Phase kickback is powerful quantum phenomenon that uses
entanglement properties to allow for transfer of phase
information from target register to control qubit
⇒ Here instead of f (x) being applied to target qubit, phase is
applied to input qubit.
⇒ This is important phenomenon and used in multiple
algorithms.
10/44
Phase Oracle proof:
⇒ We start with |x⟩|−⟩
1
|x⟩|−⟩ = |x⟩ √ (|0⟩ − |1⟩)
2
1
= √ (|x⟩|0⟩ − |x⟩|1⟩)
2
Apply Oracle Uf
1
= √ (Uf |x⟩|0⟩ − Uf |x⟩|1⟩)
2
Equivalent to
1
= √ (|x⟩|f (x)⟩ − |x⟩|f (x)⟩)
2
cont..
11/44
Phase Oracle proof:
⇒ Or,
|x⟩|−⟩ : f (x) = 0
=
−|x⟩|−⟩ : f (x) = 1
12/44
Deutsch’s Algorithm : Quantum Gates
⇒ Hadamard Gate(H):
⇒ Matrix Representation:
1 1 1
√
2 1 −1
13/44
Deutsch’s Algorithm : Quantum Gates
⇒ Pauli X Gate:
⇒ Single-qubit rotation through π radians around the x-axis.
⇒ This works like a not gate.
⇒ Matrix Representation:
0 1
1 0
14/44
Deutsch’s Algorithm : Quantum Gates
⇒ CNOT Gate:
⇒ CNOT stands for Controlled NOT gate.
⇒ Unlike X Gate and Hadamard Gate, this gate is used with
two qubits.
⇒ Ex. [Link](q0 , q1 ) would mean q0 is control qubit and
q1 is bit that will be changed.
⇒ If q0 is 0 there are no changes to q1 .
⇒ If q0 is 1 then q1 is flipped.
⇒ Matrix Representation:
1 0 0 0
0 1 0 0
0 0 0 1
0 0 1 0
15/44
Deutsch’s Algorithm : Quantum Gates
16/44
Deutsch’s Algorithm
17/44
Working of Deutsch’s Algorithm
⇒ Initially qubits are in state |ψ0 ⟩ = |00⟩
⇒ Next we apply X gate on target qubit and get |ψ1 ⟩ = |01⟩
⇒ Applying Hadamard Gate on both qubit gives us:
1 1
|ψ2 ⟩ = | + −⟩ = √ (|0⟩ + |1⟩)|−⟩ = √ (|0⟩|−⟩ + |1⟩|−⟩)
2 2
cont.. 18/44
Working of Deutsch’s Algorithm
⇒ Now we apply oracle Uf
1 1
|ψ3 ⟩ = Uf √ (|0⟩|−⟩ + |1⟩|−⟩) = √ (Uf |0⟩|−⟩ + Uf |1⟩|−⟩)
2 2
⇒ As can be seen above state (in red), are in Phase oracle form:
Uf |x⟩|−⟩ = (−1)f (x) |x⟩|−⟩
⇒ Now we can rewrite the equation as:
1
|ψ3 ⟩ = √ ((−1)f (0) |0⟩|−⟩ + (−1)f (1) |1⟩|−⟩)
2
cont.. 19/44
Working of Deutsch’s Algorithm
⇒ If we separate |−⟩ state we write the equation as:
1
|ψ3 ⟩ = √ ((−1)f (0) |0⟩ + (−1)f (1) |1⟩)|−⟩
2
⇒ Going forward we won’t consider |−⟩ state as it is not
measured. So,
1
|ψ3 ⟩ = √ ((−1)f (0) |0⟩ + (−1)f (1) |1⟩)
2
cont.. 20/44
Working of Deutsch’s Algorithm
⇒ Now if f (0) = f (1) = 0,
1
|ψ3 ⟩ = √ (|0⟩ + |1⟩)
2
⇒ If f (0) = f (1) = 1,
1
|ψ3 ⟩ = √ (−|0⟩ − |1⟩)
2
or
1
|ψ3 ⟩ = − √ (|0⟩ + |1⟩)
2
⇒ Here we can say that
1
|ψ3 ⟩ = ± √ (|0⟩ + |1⟩) = ±|+⟩ if f (0) = f (1)
2
21/44
Working of Deutsch’s Algorithm
⇒ Now if f (0) ̸= f (1),
1
|ψ3 ⟩ = ± √ (|0⟩ − |1⟩) = ±|−⟩ if f (0) ̸= f (1)
2
⇒ Now apply Hadamard Gate:
if f (0) = f (1) : |ψ4 ⟩ = ±|0⟩
if f (0) ̸= f (1) : |ψ4 ⟩ = ±|1⟩
⇒ Upon Measuremnt ± sign would not matter.
⇒ If we measure 0, f (x) is constant.
⇒ And if we measure 1, f (x) is balanced.
22/44
Deutsch - Jozsa Algorithm
23/44
Deutsch - Jozsa Algorithm
24/44
Deutsch - Jozsa Algorithm Circuit
25/44
Deutsch - Jozsa Algorithm
⇒ Initial State:
|ψ0 ⟩ = |0⟩⊗n |−⟩
⇒ For n = 2:
1 1 1
H ⊗2 |0⟩⊗2 = √ (|0⟩ + |1⟩) ⊗ √ (|0⟩ + |1⟩) = √ (|00⟩ + |01⟩ + |10⟩ + |11⟩)
2 2 22
26/44
Deutsch - Jozsa Algorithm
⇒ For N = 3:
1
H ⊗3 |0⟩⊗3 = √ (|000⟩ + |001⟩ + |010⟩ + |011⟩ + |100⟩ + |101⟩ + |110⟩ + |111⟩)
23
⇒ We can write these equations as:
1 X 1 X
H ⊗2 |0⟩⊗2 = √ |x⟩ and H ⊗3 |0⟩⊗3 = √ |x⟩
22 x∈{0,1}2
23 x∈{0,1}3
27/44
Deutsch - Jozsa Algorithm
⇒ Apply Oracle to get |ψ2 ⟩:
1 X 1 X
|ψ2 ⟩ = Uf √ |x⟩|−⟩ = √ Uf |x⟩|−⟩
2n x∈{0,1}n
2n x∈{0,1}n
28/44
Deutsch - Jozsa Algorithm
29/44
Hadamard Gate on |x⟩
1
H ⊗3 |x⟩ = √ (|000⟩ + (−1)x2 |001⟩ + (−1)x1 |010⟩ + (−1)x1 +x2 |011⟩ + (−1)x0 |100⟩
23
+ (−1)x0 +x2 |101⟩ + (−1)x0 +x1 |110⟩ + (−1)x0 +x1 +x2 |111⟩)
1
H ⊗3 |x⟩ = √ (|000⟩ + (−1)x.001 |001⟩ + (−1)x.010 |010⟩ + (−1)x.011 |011⟩
23
+ (−1)x.100 |100⟩ + (−1)x.101 |101⟩ + (−1)x.110 |110⟩ + (−1)x.111 |111⟩)
1 X
H ⊗3 |x⟩ = √ (−1)x.z |z⟩
23 z∈{0,1}3
1 X
H ⊗n |x⟩ = √ (−1)x.z |z⟩
2n z∈{0,1}n
31/44
Deutsch - Jozsa Algorithm
1 X
|ψ3 ⟩ = √ (−1)f (x) H ⊗n |x⟩
2n x∈{0,1}n
1 X 1 X
|ψ3 ⟩ = √ (−1)f (x) √ (−1)x.z |z⟩
2n x∈{0,1}n 2n z∈{0,1}n
1 X X
|ψ3 ⟩ = (−1)f (x) (−1)x.z |z⟩
2n
x∈{0,1}n z∈{0,1}n
1 X X
|ψ3 ⟩ = (−1)f (x)+x.z |z⟩
2n
x∈{0,1}n z∈{0,1}n
32/44
Deutsch - Jozsa Algorithm
1 X X
|ψ3 ⟩ = (−1)f (x)+x.z |z⟩
2n
x∈{0,1}n z∈{0,1}n
Rather than figuring out what we will get after measuring |ψ3 ⟩, let’s check: What is
probability that |ψ3 ⟩ will collapse to state |0⟩? We can answer this by setting z = 0
⇒ This happens if f (x) is constant
⇒ |ψ3 ⟩ with all 0 state |0⟩⊗n
1 X
|ψ3 ⟩ = (−1)f (x)+x.00···0 |0⟩
2n
x∈{0,1}n
1 X
|ψ3 ⟩ = (−1)f (x) |0⟩
2n
x∈{0,1}n
33/44
Deutsch - Jozsa Algorithm
⇒ If f(x) is constant:
(
1 P 0
2n n (−1) |0⟩ : f (x) = 0
|ψ3 ⟩ = 1 Px∈{0,1} 1
2n x∈{0,1}n (−1) |0⟩ : f (x) = 1
(
1 P 0
2n n (−1) |0⟩ : f (x) = 0
|ψ3 ⟩ = 1 Px∈{0,1} 1
2n x∈{0,1}n (−1) |0⟩ : f (x) = 1
1 n
|ψ3 ⟩ = 2n 2 |0⟩ : f (x) = 0
1 n
2n (−2 )|0⟩ : f (x) = 1
1|0⟩ : f (x) = 0
|ψ3 ⟩ =
−1|0⟩ : f (x) = 1
|ψ3 ⟩ = ±1|0⟩
35/44
Bernstein Vazirani (BV) Algorithm
⇒ Invented by Ethan Bernstein and Umesh Vazirani in 1997.
⇒ Restricted version of Deutsch–Jozsa algorithm.
⇒ Instead of distinguishing between two different classes of
functions, it tries to learn string encoded in function.
⇒ Given oracle that implements function f : {0, 1}n → {0, 1}.
⇒ f (x) is promised to be dot product between x and secret
string s ∈ {0, 1}n modulo 2,
f (x) = x · s (mod 2) = x1 s1 ⊕ x2 s2 ⊕ · · · ⊕ xn sn , find s.
⇒ x.s = x1 s1 + x2 s2 + · · · + xn sn ⇒ ′ +′ stands for addition.
⇒ x1 s1 ⊕ x2 s2 ⊕ · · · ⊕ xn sn = 1 for odd no. of 1’s and 0 for
even no. of 1’s.
⇒ Ex.
(x.s) = (11.11) = (1)(1) + (1)(1) = 1 + 1 = 0
= (1)(1) ⊕ (1)(1) = 1 ⊕ 1 = 0
(x.s) = (100.111) = (1)(1) + (0)(1) + (0)(1) = 1 + 0 + 0 = 1
= (1)(1) ⊕ (0)(1) ⊕ (0)(1) = 1 ⊕ 0 ⊕ 0 = 1
37/44
Classical Approach for BV Algorithm
37/44
Classical Approach for BV Algorithm
37/44
Classical Approach for BV Algorithm
37/44
Classical Approach for BV Algorithm
37/44
Classical Approach for BV Algorithm
37/44
BV Algorithm
38/44
BV Algorithm
⇒ As seen before |ψ3 ⟩ could be given as:
1 X X
|ψ3 ⟩ = (−1)f (x)+x.z |z⟩
2n
x∈{0,1}n z∈{0,1}n
(−1)x.s+x.z = (−1)3 = −1
(−1)x.(s⊕z) = (−1)1 = −1
40/44
BV Algorithm
⇒ Coming back to state |z⟩. |z⟩ is superposition of states:
|z⟩ = α0 |0 · · · 0⟩ + · · · + αs |s⟩ + · · · + αn |1 · · · 1⟩
⇒ |α0 |2 + · · · + 1 + · · · + |αn ⟩ = 1
42/44
BV Algorithm Qiskit Circuit analysis.
44/44