大一新生也能懂的量子计算

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 123

Linear Algebra

and
Quantum Physics
Learn Basic Quantum Physics in the point of
view of Linear Algebra
不正经讲师:理科宅Hunt
Abstract vector space

• A set is called vector space (矢量空间) if it satisfies the following axioms. The
elements in the set are called vectors (矢量).
Example – All complex functions

Let 𝐻 be a set of complex functions defined on ℂ. Then 𝐻 is an abstract vector space.


Let 𝑓, 𝑔, ℎ ∈ 𝐻, and 𝑎, 𝑏 ∈ ℂ then
• 𝑓+ 𝑔+ℎ = 𝑓+𝑔 +ℎ
• 𝑓+𝑔 =𝑔+𝑓
• …
• 𝑎 𝑓 + 𝑔 = 𝑎𝑓 + 𝑏𝑔
• 𝑎 + 𝑏 𝑓 = 𝑎𝑓 + 𝑏𝑓

• A set of all wave functions (波函数) is vector space. We can treat wave functions as
vectors!
Example – Electron spins(电子自旋)

Let 𝐻 be a set of wave functions that describes electron spin in 𝑧-direction.


Then 𝐻 is an abstract vector space.
𝐻 = 𝑆𝑝𝑖𝑛 𝑢𝑝, 𝑆𝑝𝑖𝑛 𝑑𝑜𝑤𝑛
Using Dirac notation, we can denote them as
0 = 𝑆𝑝𝑖𝑛 𝑢𝑝, 1 = 𝑆𝑝𝑖𝑛 𝑑𝑜𝑤𝑛
|0⟩ and |1⟩ are called “qubit”(量子比特).
Example – Photon polarizations (光的偏振)

Let 𝐻 be a set of polarizations of light. Then 𝐻 is an abstract vector space.


𝐻 = 𝐻𝑜𝑟𝑖𝑧𝑜𝑛𝑡𝑎𝑙, 𝑉𝑒𝑟𝑡𝑖𝑐𝑎𝑙
Using Dirac notation, we can denote them as
0 = 𝐻𝑜𝑟𝑖𝑧𝑜𝑛𝑡𝑎𝑙, 1 = 𝑉𝑒𝑟𝑡𝑖𝑐𝑎𝑙
|0⟩ and |1⟩ are called “qubit”.
Inner product and Hilbert space

• Define inner product (内积) of complex functions, |𝜓⟩ and |𝜑⟩ as



𝜑 𝜓 = න 𝜑ത (𝑥)𝜓(𝑥)𝑑𝑥 (𝑖𝑓 𝜓 𝑎𝑛𝑑 𝜑 𝑎𝑟𝑒 𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛𝑠)
−∞

𝝋 𝝍 = 𝝋† 𝝍 = 𝝋 ഥ 𝑇 𝝍 (𝑖𝑓 𝝋 𝑎𝑛𝑑 𝝍 𝑎𝑟𝑒 𝑐𝑜𝑙𝑢𝑚𝑛 𝑣𝑒𝑐𝑡𝑜𝑟𝑠)


• Simply speak: Hilbert space (希尔伯特空间) is a complex vector space with inner product.

• ⋅ are called bra-vector and ⋅ are called ket-vector. Together ⋅ ⋅ , it’s called bracket :D
Physical interpretation of inner product

• Suppose |𝜓⟩ is the initial state of a particle, then the probability of finding it in
|𝜑⟩ state is given by
𝜑𝜓 2
Properties of qubits

The qubits are normalized (归一的),


0 0 = 1, 1 1 = 1
The qubits are orthogonal (正交的),
0 1 = 0, 1 0 = 0
Therefore, qubits form a basis of their Hilbert space. i.e. Any quantum states can be represented
using linear combination of 0 and |1⟩.

Sometimes, it is more convenient to write them as


𝑖 𝑗 = 𝛿𝑖𝑗
Where 𝛿𝑖𝑗 is Kronecker delta,
0, 𝑖≠𝑗
𝛿𝑖𝑗 = ቊ
1, 𝑖=𝑗
Superposition of states (叠加态)

Suppose an electron’s spin can be described by a wave function


3 2
𝜓 = 0 + |1⟩
5 5
Find the probability of measuring |0⟩ state and |1⟩ state.

Solution:
Tensor product (张量积)

Tensor product between 2 vectors is defined as

In quantum physics, we have several notations for tensor product


𝜓 ⊗ 𝜑 ≡ 𝜓 𝜑 ≡ 𝜓, 𝜑 ≡ 𝜓𝜑
Tensor product has the following properties:

• Tensor product is not commutative, ORDER IS IMPORTANT!


Inner product on the tensor products

Suppose |𝜓1 ⟩, |𝜑1 ⟩ ∈ 𝐻1 and |𝜓2 ⟩, |𝜑2 ⟩ ∈ 𝐻2 where 𝐻1 and 𝐻2 are two Hilbert
spaces. Then
𝜑1 𝜑2 𝜓1 𝜓2 = 𝜑1 𝜓1 1 𝜑2 𝜓2 2
Where ⋅ ⋅ 1 and ⋅ ⋅ 2 are inner product defined on 𝐻1 and 𝐻2 , respectively.

Example:
01 01 = 0 0 1 1 = 1 ⋅ 1 = 1
011 010 = 0 0 1 1 1 0 = 1 ⋅ 1 ⋅ 0 = 0
• Two quantum states are orthogonal if qubits are different.
Example

Suppose there are 2 electrons, their spins are


3 2 1 1
𝜓1 = 0 + 1, 𝜓2 = 0 + |1⟩
5 5 2 2
Find the probability of measuring electron 1 in |0⟩ state and electron 2 in |1⟩
state (in state |01⟩).
Solution:
Outer product (外积)

• The outer product of two vectors |𝜓⟩ and |𝜑⟩ are defined as
|𝜓⟩⟨𝜑| = 𝜓 ⊗ ⟨𝜑|
• Outer product is used to produce operators (算符).

1 1
Example: Let 𝜓 = 0 + |1⟩. Then 𝑃෠0 ≡ |0⟩⟨0| is a projection
2 2
operator (投影算符) and it projects the wave function onto |0⟩ state.
1 1 1
𝑃෠0 𝜓 = 0 00 + 0 01 = 0
2 2 2
Eigenvalues and Eigenvectors

• Let 𝐴መ be an operator. If
𝐴መ 𝜓 = 𝜆|𝜓⟩
Then 𝜆 is an eigenvalue (特征值) of 𝐴መ and |𝜓⟩ is an eigenvector (特征向量)
associated with 𝜆.

Example: Find the eigenvalues and eigenvectors of projection operator


𝑃෠ ≡ |0⟩⟨0|
Solution: Eigenvalues are 1 and 0, eigenvectors are |0⟩ and |1⟩.
𝑃෠ 0 = 1 ⋅ |0⟩
𝑃෠ 1 = 0 ⋅ |1⟩
Spectral theorem (谱定理)

Spectral theorem: Suppose the eigenvalues 𝜆1 , 𝜆2 , ⋯ , 𝜆𝑛 of 𝐴መ are real, and their


corresponding eigenvectors are 𝜓1 , 𝜓2 , ⋯ , 𝜓𝑛 . Then the operator 𝐴መ can be
written as
𝑛

𝐴መ = ෍ 𝜆𝑖 |𝜓𝑖 ⟩⟨𝜓𝑖 |
𝑖=1
Moreover, 𝜓1 , 𝜓2 , ⋯ , 𝜓𝑛 form a complete basis for the Hilbert space 𝐴መ
living in.


Sometimes, this is called spectral decomposition of operator 𝐴.
Completeness relation (完备性关系)

From spectral theorem, we can easily get the so-called completeness relation:
𝜓1 , 𝜓2 , ⋯ , 𝜓𝑛 is a complete basis if and only if

𝐼 = ෍ |𝜓𝑖 ⟩⟨𝜓𝑖 |
𝑖=1
Where 𝐼 is an identity matrix.
Summary

1. Abstract vector space


2. Inner product
1. Superposition
3. Tensor product
1. Multiple qubits
4. Outer product
1. Projection operator
5. Eigenvalues and Eigenvectors
1. Spectral theorem
2. Completeness relation
Bloch Sphere
and
Density Operator
Visualization of quantum states
不正经讲师:理科宅Hunt
Bloch Sphere

• The coefficients of a normalized quantum states must satisfy


𝜓 =𝑎 0 +𝑏 1 , 𝑤𝑖𝑡ℎ 𝑎 2 + 𝑏 2 = 1
• A normalized quantum state must be on a “sphere” (Bloch sphere).
• This sphere is called Bloch sphere
• Using polar angle, 𝜃, and azimuthal angle, 𝜙, we can write
𝜃
cos
𝜓 = 2
𝑖𝜙
𝜃
𝑒 sin
2
Example – Visualization in Qiskit

• Unfortunately, Qiskit does not provide convenient visualization in


(𝜃, 𝜙) representation, we need to convert this to (𝑥, 𝑦, 𝑧).

𝑟=1
Global and relative phase

• In computational basis, we can express a quantum state as


𝑖𝛾
𝜃 𝑖𝜙
𝜃
𝜓 =𝑒 cos 0 + 𝑒 sin |1⟩
2 2
Where 𝑒 𝑖𝛾 is called global phase, 𝑒 𝑖𝜙 is called relative phase.

• Global phase DOES NOT affect anything (we can ignore it).
• Relative phase IS important, DO NOT forget it.
Example
Unitary operators
• Definition: An operator, 𝑈, is unitary if 𝑈 † 𝑈 = 𝑈𝑈 † = 𝐼.
• Unitary operator PRESERVES the norm.
𝑈 𝜓 2 = 𝜓 𝑈 † 𝑈 𝜓 = 𝜓 𝜓 = ‖ 𝜓 ‖2
• In other words, unitary operators keep quantum states on the Bloch sphere.

Examples: Pauli matrices.


Rotation about arbitrary axis

𝑛ො
• Pauli-Euler relation:
exp 𝑖𝛼𝑛ො ⋅ 𝜎Ԧ = cos 𝛼 𝐼 + 𝑖 sin 𝛼 𝑛ො ⋅ 𝜎Ԧ
• 𝑛ො is a unit vector in ℝ3 .
• 𝜎Ԧ = 𝑋𝑥ො + 𝑌𝑦ො + 𝑍𝑧Ƹ is a vector of Pauli matrices.
0 1
• For example: 𝑥ො ⋅ 𝜎Ԧ = 𝑋 =
1 0

• To rotate a state |𝜓⟩ along unit vector 𝑛ො with angle 𝛼, multiply the rotation
matrix 𝑅𝑛ො (𝛼),
𝛼
𝑅𝑛ො 𝛼 𝜓 = exp −𝑖 𝑛ො ⋅ 𝜎Ԧ 𝜓
2
Example

𝜋
Rotate |0⟩ along 𝑥ො by .
2
𝜋 𝜋/2 𝜋/2
Rotation matrix 𝑅𝑥ො = cos 𝐼 − 𝑖 sin 𝑥ො ⋅ 𝜎Ԧ
2 2 2
Pure state and mixed state

• A pure state is a quantum state can be represented as a single vector.


• That means, all vectors on the surface Bloch sphere are pure states! Since they
can be written as
𝜃
cos
𝜓 = 2
𝑖𝜙
𝜃
𝑒 sin
2

• A mixed state is a vector inside Bloch sphere.


Density matrix and Bloch vector

• For a given pure state |𝜓⟩, define the density operator as


𝜌 = |𝜓⟩⟨𝜓|
𝜃 𝜃 𝑇
• Let 𝜓 = cos , 𝑒 𝑖𝜙 sin , then we have
2 2

1 1 + cos 𝜃 𝑒 −𝑖𝜙 sin 𝜃 = 1 𝐼 + 𝑥𝑋 + 𝑦𝑌 + 𝑧𝑍 = 1 (𝐼 + 𝑟Ԧ ⋅ 𝜎)


𝜌= 𝜌 Ԧ
2 𝑒 𝑖𝜙 sin 𝜃 1 − cos 𝜃 2 2

Where 𝜎Ԧ = (𝑋, 𝑌, 𝑍) is the vector of Pauli matrices and


𝑟Ԧ𝜌 = 𝑥, 𝑦, 𝑧 = (sin 𝜃 cos 𝜙 , sin 𝜃 sin 𝜙 , cos 𝜃)
Is called the unit Bloch vector. It is the Cartesian representation of |𝜓⟩.
Purity

• Define purity of a quantum state |𝜓⟩ as


𝛾 = 𝑇𝑟 𝜌2
Where 𝜌 = |𝜓⟩⟨𝜓| is the density operator of |𝜓⟩.
• Purity measures how much a state is mixed.
1
• ≤ 𝛾 ≤ 1 where d is the dimension of the Hilbert space.
𝑑
• 𝛾 = 1 if it’s a pure state, 𝛾 = 1/𝑑 if it’s a completely mixed state.

• Suppose 𝑟Ԧ1 and 𝑟Ԧ2 are the Bloch vectors of two pure states |𝜓1 ⟩ and |𝜓2 ⟩, then
2
1
𝜓1 𝜓2 = 𝑇𝑟 𝜌1 𝜌2 = (1 + 𝑟Ԧ1 ⋅ 𝑟Ԧ2 )
2
• This formula relates the inner product in 𝐻 and the inner product in ℝ3 .
Example – Bloch sphere geometry

Suppose 𝜓1 𝜓2 = 0 (orthogonal in 𝐻), how do they look like on Bloch sphere?

Using the formula,


2
1
𝜓1 𝜓2 = (1 + 𝑟Ԧ1 ⋅ 𝑟Ԧ2 )
2
Since 𝜓1 𝜓2 = 0, so we have 𝑟Ԧ1 ⋅ 𝑟Ԧ2 = −1. 𝜓1 and |𝜓2 ⟩ have opposite directions!
Example – Purity

0 −|1⟩
Let 𝜓 = , calculate its purity.
2

This is obvious, since |𝜓⟩ can be drawn on Bloch sphere, so it is a pure state.
Summary

1. Bloch sphere can be used to visualize quantum states.


1. Orthogonal(in 𝐻) states are pointing opposite to each other(in ℝ3 )
2. Pure states are on the surface of Bloch sphere, and mixed states are
inside the Bloch sphere.
2. Unitary operators are operators that preserve norm.
1. Pauli matrices
2. Pauli-Euler relation and Rotation operator
3. Density operator
1. Density matrix and Purity
2. Bloch vector
Quantum Circuit
Learn the basics of quantum computing
不正经讲师:理科宅Hunt
Quantum Circuits (量子线路)

• Quantum circuits is a graphical representation of operations on qubits.


• There are 2 kinds of operations: Quantum logic gates and measurements.
• Chronological order is from left to right.

qubits gates measurements


Qubits

• We talked about qubits in last lecture already.


• Computational basis: 0 = 1,0 𝑇 , 1 = 0,1 𝑇
• There are other basis, such as Bell Basis for quantum teleportation.
Quantum logic gates (量子逻辑门)

• Quantum logic gates are unitary operators.


• Common quantum gates: Pauli matrices, Hadamard gates, CNOT …
Example – Pauli X matrix

Apply Pauli X matrix to |0⟩ and |1⟩, what do we get?

0 1 1 0
𝑋0 = = = |1⟩
1 0 0 1

0 1 0 1
𝑋1 = = = |0⟩
1 0 1 0
• Sometimes, Pauli X matrix is called NOT gate.
Example – Hadamard gate

Apply Hadamard gate to |0⟩ and |1⟩, what do we get?

1 1 1 1 1 1 0 + |1⟩
𝐻0 = = =
2 1 −1 0 2 1 2

1 1 1 0 1 1 0 − |1⟩
𝐻1 = = =
2 1 −1 1 2 −1 2

• Hadamard gate is used to generate superposition states.


Example – Controlled NOT gate (CNOT)

Apply CNOT gate to 00 , 01 , 10 and |11⟩, what do we get?

Using tensor product, we have


Example – Controlled NOT gate (CNOT)

• If the first bit is 0, do nothing; If the first bit is 1, flip the second
bit.

|0⟩ |0⟩ |0⟩ |0⟩ |1⟩ |1⟩ |1⟩ |1⟩


|0⟩ |0⟩ |1⟩ |1⟩ |0⟩ |1⟩ |1⟩ |0⟩
No-cloning theorem (不可克隆原理)

• There is no unitary operator 𝑈 on 𝐻 ⊗ 𝐻 such that for all


normalized states 𝜓 𝐴 and 𝑒 𝐵 on 𝐻
𝑈 𝜓 𝐴 𝑒 𝐵 = 𝑒 𝑖𝛼(𝜓,𝑒) 𝜓 𝐴 𝜓 𝐵
Proof:

• This DOES NOT mean we cannot copy quantum states.


• People CANNOT eavesdrop a quantum communication.
Measurement (测量)

• You will only know the state of Schrödinger's cat if you open the
box (measure).
• Qubit’s wave function will collapse to a certain state (|0⟩ or |1⟩)
when you measure it.
• To get the final results, you need to measure qubits!
Example

What do you measure after a Hadamard gate is applied to 1 ?

0 − |1⟩
𝐻1 =
2
By reading the coefficients, we know there is 50% chance we get
|0⟩ and 50% change to get |1⟩.
Summary

1. Quantum circuits consists of:


1. Quantum logical gates
2. Measurements (usually at the end)
2. No-cloning theorem
Reversible Circuits
and
Universal Gates

不正经讲师:理科宅Hunt
Reversible function

• A function is reversible if and only if it is bijective.


Reversible circuits in classical computing

• Gates in classical computing are not always reversible.

Example: NOT gate is reversible; AND gate is not reversible.


Reversibility in classical computing
• In classical computing, we can always make a gate reversible.
• How to make a given 𝑓 reversible
• Suppose 𝑓 ∶ 𝑖 → 𝑓(𝑖) has 𝑛 inputs 𝑚 outputs
• Introduce 𝑛 extra outputs and 𝑚 extra inputs
• Replace 𝑓 by 𝑓𝑟𝑒𝑣 ∶ 𝑖, 𝑗 → 𝑖, 𝑓 𝑖 ⊕ 𝑗 where ⊕ is XOR
Reversibility in quantum computing

• Quantum circuits(gates only, excluding the measurements) are


ALWAYS reversible!
• Since all quantum gates are unitary matrix, so by definition we know
that every unitary matrix 𝑈 has a unique inverse 𝑈 † .

Reverse of Hadamard gate


Example – Quantum AND gate

• Since quantum gates are reversible, so it’s the same as the classical
reversible AND gate
• To get AND gate, set 𝑐 = |0⟩.
• To get NAND gate, set 𝑐 = |1⟩.

𝑎 𝑎
This is a AND
gate if c=0;
𝑏 This is a NAND 𝑏
gate if c=1.
𝑐 𝑎𝑏 ⊕ 𝑐
Example – Quantum OR gate

• Reversible OR gate in classical computing suits our purpose

𝑎 𝑎
This is a OR gate
if c=0;
𝑏 This is a NOR 𝑏
gate if c=1.
𝑐 𝑎∨𝑏 ⊕𝑐
Universal gate sets

• We can APPROXIMATE any unitary operators to any given


precision by finite number of gates. (Similar to Taylor series)
• The set of gates that does this job is called universal gate set.

For example:
1. {𝐻𝑎𝑑𝑎𝑚𝑎𝑟𝑑, 𝑃ℎ𝑎𝑠𝑒, 𝜋/8, 𝐶𝑁𝑂𝑇}
2. {𝐻𝑎𝑑𝑎𝑚𝑎𝑟𝑑, 𝑃ℎ𝑎𝑠𝑒, 𝑇𝑜𝑓𝑓𝑜𝑙𝑖, 𝐶𝑁𝑂𝑇}
Decomposition of unitary matrix

A 𝑑-dimensional unitary matrix 𝑈 can be decomposed into


products of two-level unitary matrices
𝑈 = 𝑉1 𝑉2 ⋯ 𝑉𝑘
Where 𝑘 ≤ 𝑑 − 1 + 𝑑 − 2 + ⋯ + 1 = 𝑑(𝑑 − 1)/2.

• This means we can use two-level unitary matrices to represent


any unitary matrices.
Summary

1. Quantum circuits are always reversible.


2. We can use 4 gates to approximate any unitary operations.
Deutsch-Jozsa
Algorithm
A demo algo that shows the usefulness of QC
不正经讲师:理科宅Hunt
Deutsch Algorithm – Problem Description

• A function 𝑓: 0,1 → {0,1} is called constant if all inputs have the


same output, i.e. 𝑓 0 = 𝑓(1); It is called balanced if the outputs of
half inputs are different from the other half, i.e. 𝑓 0 ≠ 𝑓(1).
• Given an unknown function 𝑓: 0,1 → {0,1}, determine if 𝑓 is
constant or balanced.
constant balanced
0 0 0 0
1 0 1 1
or or
0 1 0 1
1 1 1 0
How classical algorithm solve this.

• We must calculate both 𝑓(0) and 𝑓(1) (2 queries) to determine the


type of 𝑓.

• In quantum computing, we can do better! We can use determine


the type of 𝑓 using only 1 query.
What does 𝑓 look like in quantum circuit ?

• Recall that every operation in quantum circuit MUST be reversible.


• But constant 𝑓 is NOT reversible, we need to modify it.
• By adding an extra input and output, now 𝑈𝑓 is reversible.

𝑈𝑓 : 𝑥 𝑦 ↦ 𝑥 |𝑦 ⊕ 𝑓(𝑥)⟩
Quantum Circuit

• There are 2 ways to draw the circuit.


• Both are equivalent since 𝑈𝑓 only acts on the last bit,
so 𝑈𝑓 can be seen as a “controlled gate”.
Quantum Circuit
Quantum Circuit
Quantum Circuit

If 𝑓 is constant, then 𝑓 0 = 𝑓(1), so 𝑓 0 ⊕ 𝑓 1 = 0

If 𝑓 is balanced, then 𝑓 0 ≠ 𝑓(1), so 𝑓 0 ⊕ 𝑓 1 = 1


Derivation of |𝜓2 ⟩
Quantum Circuit

If 𝑓 is constant

If 𝑓 is balanced
Quantum Circuit

• 𝑓 is constant ⇔ measurement IS |0⟩.


• 𝑓 is balanced ⇔ measurement IS NOT |0⟩.

If 𝑓 is constant If 𝑓 is balanced

𝑓 0 2 𝑓 0 2
𝑃(1𝑠𝑡 𝑏𝑖𝑡 0) = −1 =1 𝑃 1𝑠𝑡 𝑏𝑖𝑡 1 = −1 = 1.
Thus, 𝑃 1𝑠𝑡 𝑏𝑖𝑡 0 = 0
Deutsch-Jozsa Algorithm – Problem Description

• A function 𝑓: 0,1 𝑛 → {0,1} is called constant if all bit strings have


the same output; It is called balanced if the outputs of half bit
strings are different from the other half.
• Given an unknown function (but guaranteed to be constant or
balanced) 𝑓: 0,1 𝑛 → {0,1}, determine if 𝑓 is constant or balanced.
constant balanced

𝒙 𝟎
𝒙 half 0s half 1s
or

𝒙 1
Quantum Circuit

• In classical algorithm, we need to


2𝑛
evaluate 𝑓 at most + 1 times.
2
• In Deutsch-Jozsa, we only need to
evaluate 𝑓 once.

𝑈𝑓 : 𝒙 𝑦 ↦ 𝒙 |𝑦 ⊕ 𝑓(𝒙)⟩
Quantum Circuit
Hadamard gate on bit string

Derive formula:

We can prove this using the following hint:


Quantum Circuit

A useful formula:

We can prove this using the following hint:


Quantum Circuit

We apply 𝑈𝑓 on the last bit, but the result adds


an extra phase to the controlled-bits −1 𝑓 𝒙 |𝒙⟩.
We call this phenomenon Phase Kick-Back.
Quantum Circuit
Quantum Circuit

• It seems quite complicated, but it can be simplified.


• Let’s look at the situation when 𝒛 = |𝟎⟩.

If 𝑓 is constant If 𝑓 is balanced
Quantum Circuit

• 𝑓 is constant ⇔ measurement IS |𝟎⟩.


• 𝑓 is balanced ⇔ measurement IS NOT |𝟎⟩.

If 𝑓 is constant If 𝑓 is balanced
Summary

• Given an unknown function (but guaranteed to be constant or balanced)


𝑓: 0,1 𝑛 → {0,1}
• Applying Deutsch-Jozsa algorithm, then
• 𝑓 is constant ⇔ measurement IS |𝟎⟩.
• 𝑓 is balanced ⇔ measurement IS NOT |𝟎⟩.
Simon’s Algorithm
Finding periodicity of a function
不正经讲师:理科宅Hunt
Periodic function

• A function, 𝑓: {0,1}𝑛 → 0,1 𝑚 , is periodic if there exists 𝑠 ∈ {0,1}𝑛


such that 𝑓 𝒙 ⊕ 𝒔 = 𝑓 𝒙 , ∀𝒙 ∈ 0,1 𝑛 .

Example: A function has the following values


𝑓 002 = 102 , 𝑓 012 = 012 , 𝑓 102 = 102 , 𝑓 112 = 012
This function has period 𝒔 = 102 since 𝑓 𝒙 ⊕ 𝒔 = 𝑓(𝒙) for all x.
Classical Algorithm that find the periodicity

• I will make a simple but natural algorithm:

1. Calculate all 𝑓 𝒙 and record them.


2. Suppose 𝑓 is periodic, then its period must divide 2𝑛 . So, there
are 𝑛 possible periods.
3. For each possible period, check if 𝑓 𝒙 ⊕ 𝒔 = 𝑓(𝒙) for all 𝒙.

• In this algorithm, we need to make 2𝑛 function evaluations(step 1).


• In quantum computing, we do less than 𝑛 function evaluations.
Simon’s Algorithm
Example – Step 1 and 2 (Prepare states)

• Suppose 𝑓: 0,1 2 → 0,1 2 , then 𝑛 = 2.


• Set counter 𝑖 = 1.

|𝜓0 ⟩ |𝜓1 ⟩ |𝜓2 ⟩ |𝜓3 ⟩


Example – Step 3 (Function evaluation)

• Let 𝑓: 0,1 2 → 0,1 2 be defined as


𝑓 002 = 102 , 𝑓 012 = 012 , 𝑓 102 = 102 , 𝑓 112 = 012

|𝜓0 ⟩ |𝜓1 ⟩ |𝜓2 ⟩ |𝜓3 ⟩


Example – Step 5 (Hadamard gates on 1st register)

• You can get rid of the second register, this makes the calculation
easier. This is what the optional in the algo step does.

|𝜓0 ⟩ |𝜓1 ⟩ |𝜓2 ⟩ |𝜓3 ⟩


Example – Step 6 (Measurements)

• No matter what the second register is, we have 1/2 probability of


getting 00 , 01 on the first register.

1/2 prob 1/2 prob

|𝜓0 ⟩ |𝜓1 ⟩ |𝜓2 ⟩ |𝜓3 ⟩


Example – Step 7 (Measurements)

• If we measured 𝐰1 = 00, then dim 𝒘1 = 0, we need to repeat


previous steps again.
• If we measure 𝐰1 = 01, then dim 𝒘1 = 𝑛 − 1 = 1, we can
proceed to next step.

• Textbook did not explain the definition of dimension of a bit string.


You can simply think that the dim of zero-bit is 0 and 1 otherwise.
𝑻 𝑻
Example – Step 8 (Solve 𝑊𝒔 = 𝟎 )

• Remember that every bit string is a ROW vector.


• 𝑊 = 𝒘1 = [0,1] is a 1 × 2 matrix
𝑇 𝑇
𝑠1
• 𝒔 = 𝑠1 , 𝑠2 = 𝑠 where s1 and s2 are the two digits of 𝒔.
2
• In textbook, 𝟎𝑇 is a 𝑛 − 1 × 1 column vector (not the zero bit).
This is quite confusing. So, in this example, 𝟎𝑇 = 0 is just a binary
number 0.
• Solve the linear system and take the NON-ZERO solution.
Time complexity of Simon’s Algorithm

• In this algorithm, we O(𝑛) function evaluations.


• Solving 𝑊𝑠 𝑇 = 0𝑇 takes 𝑂(𝑛3 ) steps if you use Gaussian elimination.
Summary

1. Simon’s algorithm significantly reduces the time complexity of


period finding, from exponential to polynomial.
Grover’s Algorithm
Quantum search algorithm
不正经讲师:理科宅Hunt
Classical search algorithm

Problem: Given 𝑓: 0,1 𝑛 → {0,1}, we want to find a bit string 𝑤 ∈


0,1 𝑛 such that 𝑓 𝑤 = 1. The existence of 𝑤 is guaranteed.

Classical algo: The sequence of input has length 𝑁 = 2𝑛 , we loop


through this sequence and calculate 𝑓 one by one until we find 𝑤.

• The time complexity of classical algorithm is 𝑂(𝑁).


• In quantum computing, Grover’s algorithm provides quadratic
speed up! Which is 𝑂 𝑁 .
Grover’s iterate

The same old 𝑈𝑓 . Need to make it


𝑈0⊥ adds a phase shift -1 to all
reversible so that we can put it in states that are different from 𝟎.
quantum circuit.
Exercise – Phase kick-back revisit

Find 𝑈𝑓 |𝑥⟩(𝐻|1⟩) where |𝑥⟩ is an arbitrary bit-string.

Solution: If you still remember phase kick-back, it is just


𝑈𝑓 |𝑥⟩(𝐻|1⟩) = −1 𝑓(𝑥) |𝑥⟩(𝐻|1⟩)

So, in some textbook, they will ignore the second register 𝐻|1⟩, just
like the Fig.8.2 earlier.
Grover’s Algorithm
Example – Step 1 and 2 (Prepare states)

𝜓 𝜓1 𝜓2 𝜓𝑘

1
𝜓 =𝐻0 = ෍ |𝑥⟩
𝑁 𝑥
Example – Step 3 (first iteration)

• For simplicity, there is only one 𝑤 such that 𝑓 𝑤 = 1. Let the collection of the other bit-
strings be 𝜓𝑏𝑎𝑑 . Then we can write
1 𝑁−1
𝜓 = 𝑤 + |𝜓𝑏𝑎𝑑 ⟩
𝑁 𝑁
1 𝑁−1
• Let sin(𝜃) = and cos 𝜃 = . Then after applying 𝐺, we have
𝑁 𝑁
𝜓1 = 𝐺 𝜓 = sin(3𝜃) 𝑤 + cos(3𝜃) |𝜓𝑏𝑎𝑑 ⟩

𝜓 𝜓1 𝜓2 𝜓𝑘
Example – Step 3 (k-th iteration)

• If we keep applying 𝐺, we will have


𝜓𝑘 = 𝐺 𝑘 𝜓 = sin((2𝑘 + 1)𝜃) 𝑤 + cos((2𝑘 + 1)𝜃) |𝜓𝑏𝑎𝑑 ⟩
• We see that the amplitude of 𝑤 increases and the amplitude of |𝜓𝑏𝑎𝑑 ⟩ decreases as 𝑘
increments.
• When 2𝑘 + 1 𝜃 ≈ 𝜋/2, the amplitude of |𝑤⟩ is maximized. In order to maximize the
probability of measuring |𝑤⟩, we should let
𝜋 1 𝜋 1 𝜋
𝑘≈ − ≈ − ≈ 𝑁
4𝜃 2 4 1 2 4
𝑁

𝜓 𝜓1 𝜓2 𝜓𝑘
Summary

1. Classical search algorithm has time complexity 𝑂(𝑁) for a sequence of


length 𝑁.
2. Grover’s algorithm has time complexity 𝑂 𝑁 for a sequence of
length 𝑁, quadratic speed up.
3. Grover’s algorithm utilizes the amplification of probability amplitudes.
Quantum Fourier Transform
Discrete Fourier Transform, but in quantum…
不正经讲师:理科宅Hunt
Hadamard gate

• Hadamard gate is to encode/decode(编码/解码) the information to


a phase

1
• Encode: 𝐻 𝑥 = σ1𝑦=0 −1 𝑥𝑦 |𝑦⟩
2
1
• Decode: 𝐻 σ1𝑦=0 −1 𝑥𝑦 |𝑦⟩ = 𝑥
2

• Hadamard gate is good, but what if we want to encode/decode


more complicated information to/from the phase??
• We want to change the phase to a more general form 𝑒 𝑖𝜙 ?
A useful notation and identity

• Suppose 𝒙 = 𝑥1 𝑥2 ⋯ is a binary number, then


2−𝑚 𝒙 = 0.0 ⋯ 0 𝑥1 𝑥2 ⋯
𝑚
• One useful identity,
Quantum Fourier Transform

2𝑛 −1
1 𝒙
2𝜋𝑖 𝑛 ⋅𝒚
𝑄𝐹𝑇2𝑛 𝒙 = ෍ 𝑒 2 |𝒚⟩
2𝑛 𝑦=0
What is 𝑅𝑘 ??

𝑅𝑘 is a rotation matrix,
1 0 1 0
𝑅𝑘 = 2𝜋𝑖/2𝑘 = 2𝜋𝑖(0.0⋯01)
0 𝑒 0 𝑒 𝑘

The action of it is
2𝜋𝑖(0.0⋯01)
0 + 1 1 1 0 1 0 +𝑒 𝑘 1
𝑅𝑘 = 2𝜋𝑖(0.0⋯01) =
2 2 0 𝑒 𝑘 1 2
That means 𝑅𝑘 puts 1 into k-th “decimal” place (keep in mind these
numbers are binary).
Inverse Quantum Fourier Transform

2𝑛 −1
1 𝒙
−2𝜋𝑖 𝑛 ⋅𝒚
𝑄𝐹𝑇2−1
𝑛 𝒙 = ෍ 𝑒 2 |𝒚⟩
2𝑛 𝑦=0
Summary

• QFT is to encode information to the phase


• Inverse QFT decodes information from the phase
• We’ll use QFT in Shor’s algorithm
Shor’s Algorithm
Factorization of a number
不正经讲师:理科宅Hunt
Number theory

• If 𝑎 and 𝑏 have the same remainder (余数) when divided by 𝑁,


then we say 𝑎 is congruent to (同余) 𝑏, denoted as
𝑎 ≡ 𝑏 𝑚𝑜𝑑 𝑁
• The remainder of 𝑎 𝑥 when divided by 𝑁 is periodic. The smallest
number 𝑟 ≠ 0 such that 𝑎𝑟 ≡ 1 (𝑚𝑜𝑑 𝑁) is called order(阶) of 𝑎
modulo 𝑁.
Example: The order 5 modulo 7 is 6.
RSA encryption

• Let 𝑁 = 𝑝𝑞 where 𝑝 and 𝑞 are prime numbers.


• The Euler’s totient function(欧拉函数), 𝜑 𝑁 = (𝑝 − 1)(𝑞 − 1).
• Let 𝑒 be a number between 1 and 𝜑(𝑛), 1 < 𝑒 < 𝜑(𝑁), such that 𝑒 is
coprime(互质) to 𝜑(𝑁).
• Let 𝑑 be the inverse(逆元) of 𝑒 modulo 𝜑 𝑁 , 𝑒𝑑 ≡ 1 (𝑚𝑜𝑑 𝜑(𝑁)).

Public key(公钥): 𝑁, 𝑒
Private key(密钥): 𝑁, 𝑑

• Public key is to encrypt(加密) info; Private key is to decrypt(解密) info.


RSA encryption (continued)

• Public key are public, everyone can use it to encrypt info.


• Private key is only visible to the receiver.
• RSA relies on the fact that large number is hard to factor!
• If one can factor 𝑁 into 𝑝𝑞, then he/she knows your private key!
Shor’s algorithm

Problem: Given 𝑁 = 𝑝𝑞 for some unknown 𝑝 and 𝑞 such that gcd 𝑝, 𝑞 = 1,


find 𝑝 and 𝑞.

1. Pick a random number, 1 < 𝑎 < 𝑁.


2. Compute 𝐾 = gcd(𝑎, 𝑁), the greatest common divisor of 𝑎 and 𝑁. This may
be done using the Euclidean algorithm.
3. If 𝐾 ≠ 1, then 𝐾 is a nontrivial factor of 𝑛, so we are done.
4. Otherwise, use the quantum period-finding subroutine to find the order 𝑟 of
𝑎 modulo 𝑁.
5. If 𝑟 is odd, then go back to step 1.
6. If 𝑎𝑟/2 ≡ −1 (𝑚𝑜𝑑 𝑁), then go back to step 1.
7. Otherwise, both gcd(𝑎𝑟/2 + 1, 𝑁) and gcd(𝑎𝑟/2 − 1, 𝑁) are nontrivial factors
of 𝑁, so we are done.
Example

Suppose 𝑁 = 15, how to factor it?

1. Pick a random number, 1 < 𝑎 < 𝑁. Say, 𝑎 = 7


2. 𝐾 = gcd 𝑎, 𝑁 = 1. It is trivial, we need to find the order of 𝑎.
4. The order 𝑟 = 4 since 𝑎4 ≡ 1 (𝑚𝑜𝑑 𝑁).
𝑟 𝑟
5. gcd 𝑎 + 1, 𝑁 = 5 and gcd 𝑎 − 1, 𝑁 = 3 are nontrivial
2 2

factors of 𝑁.
Shor’s algorithm (Quantum subroutine)

The quantum part of Shor’s algorithm is for order-finding.

𝑈𝑎𝑥 : |𝑥⟩|𝑦⟩ → |𝑥⟩|𝑦𝑎 𝑥 (𝑚𝑜𝑑 𝑁)⟩

Since the second register is 1, so


𝑈𝑎𝑥 : |𝑥⟩|1⟩ → |𝑥⟩|𝑎 𝑥 (𝑚𝑜𝑑 𝑁)⟩
Time-complexity
Summary

1. Shor’s algorithm can factor number in polynomial time (some


polynomial of log 𝑁).
Quantum
Error
Correction
The start of fault tolerance computing…
不正经讲师:理科宅Hunt
Fault Tolerance Computing

Simply speak, fault tolerance computing(容错计算) can produce


correct answer even if error (fault) occurs.
Error types in Quantum Computing

1. Bit-flip error(位翻转错误): 0 ↦ |1⟩ or 1 ↦ |0⟩


2. Phase-flip error(相翻转错误): 𝛼 0 + 𝛽 1 ↦ 𝛼 0 − 𝛽|1⟩
• 𝛼 0 + 𝛽 1 ↦ 𝛼 0 − 𝛽|1⟩ and 𝛼 0 + 𝛽 1 ↦ −𝛼 0 + 𝛽|1⟩ are the
SAME error, since we can factor out -1 ignore the global phase, so
−𝛼 0 + 𝛽 1 = −(𝛼 0 − 𝛽|1⟩) ≡ 𝛼 0 − 𝛽|1⟩
Classical bit-flip correction – Three-bit code

• We assume at most 1 bit-flip can occur within each bit (In fact, it is
not correctable if more than 1 bit-flip occurs at the same time).
• The way to correct bit-flip error is by copying the bit to extra
bits(ancilla).
• We can determine what operations to perform according to the
ancilla bits.

Encode b to ancilla by using 2 CNOT gates. Abstract this action by 𝐺𝑒𝑛𝑐 gate.
Classical bit-flip correction – Three-bit code

• Abstract the classical bit-flip error to a gate, call it 𝜀 𝐶


• Abstract the classical bit-flip correction to a gate, call it 𝑅𝐶
• Before error corrupt the bit 𝑏, encode it into ancilla bits by 𝐺𝑒𝑛𝑐 .
We then apply Recovery gate to the corrupted bits.

General error correction procedure Three-bit Recovery gate


Example

Let 𝑏 = 0, so we have 𝑏𝑒𝑛𝑐 = 000 after encoding. Now bit-flip error


happens, recover 𝑏 by applying recovery gate.

Suppose bit-flip occurs on 1st bit, then the corrupted data is 𝑏ത𝑒𝑛𝑐 = 100
Fault Tolerance circuit

• The three-bit code is good. But at the end of recovery we decodes


the data (𝑏𝑏𝑏 ↦ 𝑏00). Next time if we want to do correction again,
we need to do encoding again (𝑏00 ↦ 𝑏𝑏𝑏)…
• Here is a way to do recovery without decoding. Hence we can do
recovery later, hence the circuit is fault tolerant.

The hollow circles in the controlled


gates in the circuit correspond to a 0-
control (i.e. conditioned on that
control bit being 0).
Example

Let 𝑏 = 0, and bit-flip error happened on 2nd bit. Recover 𝑏.


Quantum bit-flip correction

• It seems No-cloning theorems tells us encoding does not work.


BUT we can bypass it by using 2 CNOT gates.
• Others are the same.
Example – An exercise for you as well

Let 𝜓 = 𝛼0 0 + 𝛼1 |1⟩, and assume the 2nd bit is flipped, recover it.
Summary

By copying information to ancilla bits, we can make computation


fault tolerance.

You might also like