Quantum_Computing_for_Computer_Scientists
Quantum_Computing_for_Computer_Scientists
Computer Scientists
The gate quantum computation model
Why learn quantum computing?
One bit with the value 0, also written as |0ۧ (Dirac vector notation)
1
0
One bit with the value 1, also written as |1ۧ
0
1
Review: matrix multiplication
𝑎 𝑏 𝑥 𝑎𝑥 + 𝑏𝑦
=
𝑐 𝑑 𝑦 𝑐𝑥 + 𝑑𝑦 1 0 0 0 𝑎 𝑎
0 1 0 0 𝑏 = 𝑏
0 0 1 0 𝑐 𝑐
0 0 0 1 𝑑 𝑑
𝑎 𝑏 𝑐 𝑥 𝑎𝑥 + 𝑏𝑦 + 𝑐𝑧
𝑑 𝑒 𝑓 𝑦 = 𝑑𝑥 + 𝑒𝑦 + 𝑓𝑧 1 0 0 0 0 0
𝑔 ℎ 𝑖 𝑧 𝑔𝑥 + ℎ𝑦 + 𝑖𝑧 0 0 1 0 1 = 0
0 1 0 0 0 1
0 0 0 1 0 0
𝑎 𝑏 𝑤 𝑥 𝑎𝑤 + 𝑏𝑦 𝑎𝑥 + 𝑏𝑧
𝑦 𝑧 =
𝑐 𝑑 𝑐𝑤 + 𝑑𝑦 𝑐𝑥 + 𝑑𝑧
Operations on one classical bit (cbit)
0 0 1 0 1 1 1 0 0 0
Identity 𝑓 𝑥 =𝑥 = =
1 1 0 1 0 0 0 1 1 1
0 0 0 1 1 0 0 1 0 1
Negation 𝑓 𝑥 = ¬𝑥 = =
1 1 1 0 0 1 1 0 1 0
0 0 1 1 0 1
Constant-0 𝑓 𝑥 =0 1 1 1 1
= =
1 1 0 0 0 0 0 0 1 0
Constant-1 𝑓 𝑥 =1
0 0
0 0 1 0 0 0 0 0
= =
1 1 1 1 0 1 1 1 1 1
Reversible computing
Reversible means given the operation and output value, you can find the input value
For 𝐴𝑥 = 𝑏, given 𝑏 and 𝐴, you can uniquely find 𝑥
Operations which permute are reversible; operations which erase & overwrite are not
Identity and Negation are reversible
Constant-0 and Constant-1 are not reversible
Quantum computers use only reversible operations, so we will only care about those
In fact, all quantum operators are their own inverses
Review: tensor product of vectors
𝑦0 𝑥0 𝑦0 3
𝑥0 𝑦0 𝑥0 𝑥0 𝑦1 1 3
= 4
𝑦1
⊗ = = 𝑥1 𝑦0 ⊗
𝑥1 𝑦1 𝑥1 𝑦0
2 4 6
𝑦1 𝑥1 𝑦1
8
𝑥0 𝑦0 𝑧0
𝑥0 𝑦0 𝑧1 0
𝑥0 𝑦1 𝑧0 0
𝑥0 𝑦0 𝑧0 𝑥0 𝑦1 𝑧1
⊗ ⊗ = 0
𝑥1 𝑦1 𝑧1 𝑥1 𝑦0 𝑧0 0 0 1 0
𝑥1 𝑦0 𝑧1 ⊗ ⊗ =
1 1 0 0
𝑥1 𝑦1 𝑧0 0
𝑥1 𝑦1 𝑧1 1
0
Representing multiple cbits
1 0
1 1 1 0 0
|00ۧ = ⊗ = 0 |01ۧ = ⊗ = 1
0 0 0 0 1 0 0
0 0 0
0 1 1 0
|4ۧ = |100ۧ = ⊗ ⊗ =
1 0 0 1
0 0 0
0 1 0 0 0
|10ۧ = ⊗ = 0 |11ۧ = ⊗ = 0
1 0 1 1 1 0 0
0 1
Operates on pairs of bits, one of which is the “control” bit and the other the “target” bit
If the control bit is 1, then the target bit is flipped
If the control bit is 0, then the target bit is unchanged
The control bit is always unchanged
With most-significant bit as control and least-significant bit as target, action is as follows:
00 00
1 0 0 0
01 01
𝐶= 0 1 0 0
10 10 0 0 0 1
0 0 1 0
11 11
Operations on multiple cbits: CNOT
1 0 0 0 0 0
0 1 0 = 0 = 0 ⊗ 0 = |11ۧ
𝐶|10ۧ = 𝐶 ⊗ = 0 1 0 0
1 0 0 0 0 1 1 0 1 1
0 0 1 0 0 1
1 0 0 0 0 0
0 0 0 = 0 = 0 ⊗ 1 = |10ۧ
𝐶|11ۧ = 𝐶 ⊗ = 0 1 0 0
1 1 0 0 0 1 0 1 1 0
0 0 1 0 1 0
Operations on multiple cbits: CNOT
1 0 0 0 1 1
1 1 0 = 0 = 1 ⊗ 1 = |00ۧ
𝐶|00ۧ = 𝐶 ⊗ = 0 1 0 0
0 0 0 0 0 1 0 0 0 0
0 0 1 0 0 0
1 0 0 0 0 0
1 0 1 = 1 = 1 ⊗ 0 = |01ۧ
𝐶|01ۧ = 𝐶 ⊗ = 0 1 0 0
0 1 0 0 0 1 0 0 0 1
0 0 1 0 0 0
Recap
1 0
We represent classical bits in vector form as 0
for 0 and 1
for 1
Operations on bits are represented by matrix multiplication on bit vectors
Quantum computers only use reversible operations
Multi-bit states are written as the tensor product of single-bit vectors
The CNOT gate is a fundamental building block of reversible computing
Qbits and superposition
1 1 1
2 2 −1 2
1 3 0 −1
2 2 2
Qbits and superposition
How can a qbit to have a value which is not 0 or 1? This is called superposition.
Superposition means the qbit is both 0 and 1 and the same time
When we measure the qbit, it collapses to an actual value of 0 or 1
We usually do this at the end of a quantum computation to get the result
𝑎
If a qbit has value 𝑏
then it collapses to 0 with probability 𝑎 2
and 1 with probability 𝑏 2
1
2 1 2 1
For example, qbit 1 has a = chance of collapsing to 0 or 1 (coin flip)
2 2
2
1 0
The qbit 0
has a 100% chance of collapsing to 0, and 1
has a 100% chance of collapsing to 1
Qbits and superposition
𝑎𝑐
𝑎 𝑐 𝑎𝑑
Multiple qbits are similarly represented by the tensor product 𝑏
⊗ 𝑑
= 𝑏𝑐
𝑏𝑑
Note that 𝑎𝑐 2
+ 𝑎𝑑 2
+ 𝑏𝑐 2
+ 𝑏𝑑 2
=1
1
2
1 1 1
2 2 2 1 2 1 1 1 1 1
For example, the system 1 ⊗ 1 = 1 (note that = 4, and 4 + 4 + 4 + 4 = 1)
2
2 2 2
1
2
There’s a ¼ chance each of collapsing to |00ۧ, |01ۧ, |10ۧ, or |11ۧ
Operations on qbits
How do we operate on qbits? The same way we operate on cbits: with matrices!
All the matrix operators we’ve seen also work on qbits (bit flip, CNOT, etc.)
Matrix operators model the effect of some device which manipulates qbit
spin/polarization without measuring and collapsing it
1 3
0 1 2 2
= 1
1 0 3
2 2
There are several important matrix operators which only make sense in a quantum context
The Hadamard gate
The Hadamard gate takes a 0- or 1-bit and puts it into exactly equal superposition
1 1 1 1 1 1
2 2 1 2 2 2 0 2
𝐻|0ۧ = = 𝐻|1ۧ = =
1 −1 0 1 1 −1 1 −1
2 2 2 2 2 2
The Hadamard gate
The Hadamard gate also takes a qbit in exactly-equal superposition, and transforms it into
a 0- or 1-bit! (This should be unsurprising – remember operations are their own inverse!)
1 1 1 1 1 1
2 2 2 1 2 2 2 0
= =
1 −1 1 0 1 −1 −1 1
2 2 2 2 2 2
X H
0 0
1 1
1 1
−1 −1
2 2
2 1 2 1
1 1
2 2
2 2
−1 1 −1 1
0 0 0 0
−1 1 −1 1
2 2 2 2
−1 −1 −1 −1
2 2 2 2
0 0
−1 −1
The unit circle state machine
0
1
1
−1
2
2 1
1
2
2
−1 1 1 −1
0 0 X H X H X
0 0
−1 1
2 2
−1 −1
2 2
0
−1
Recap
Cbits are just a special case of qbits, which are 2-vectors of Complex numbers
Qbits can be in superposition, and are probabilistically collapsed to cbits by measurement
Multi-qbit systems are tensor products of single-qbit systems, like with cbits
Matrices represent operations on qbits, same as with cbits
The Hadamard gate takes 0- and 1-bits to equal superposition, and back
We can think of qbits and their operations as forming a state machine on the unit circle
Actually the unit sphere if we use complex numbers
The Deutsch oracle
Imagine someone gives you a black box containing a function on one bit
Recall! What are the four possible functions on one bit?
You don’t know which function is inside the box, but can try inputs and see outputs
How many queries would it take to determine the function on a classical computer?
How many on a quantum computer?
The Deutsch oracle
What if you want to check whether the unknown function is constant, or variable?
Constant-0 & constant-1 are constant, identity & negation are variable
How many queries would it take on a classical computer?
How many on a quantum computer?
The Deutsch oracle
Before: After:
|0ۧ 𝑓(|xۧ)
|xۧ 𝑓(|xۧ) Output Output'
Input BB Output |xۧ BB |xۧ
Input Input'
The black box leaves the input qbit unchanged, writing function output to output qbit
The Deutsch oracle: constant-0
|0ۧ |0ۧ
Output Output'
|xۧ BB |xۧ
Input Input'
Output
Input
The Deutsch oracle: constant-1
|0ۧ |1ۧ
Output Output'
|xۧ BB |xۧ
Input Input'
Output X
Input
The Deutsch oracle: identity
|0ۧ |xۧ
Output Output'
|xۧ BB |xۧ
Input Input'
Output
Input
The Deutsch oracle: negation
|0ۧ |¬xۧ
Output Output'
|xۧ BB |xۧ
Input Input'
Output X
Input
The Deutsch oracle
|0ۧ
Output X H H
BB
|0ۧ
Input X H H
If the black-box function is constant, system will be in state |11ۧ after measurement
If the black-box function is variable, system will be in state |01ۧ after measurement
The Deutsch oracle: preprocessing
−1 1 −1 1
0 0 0 0
−1 1 −1 1
2 2 2 2
−1 −1 −1 −1
2 2 2 2
0 0
−1 −1
The Deutsch oracle: constant-0
|0ۧ |0ۧ
Output Output'
|xۧ BB |xۧ
Input Input'
Output
Input
The Deutsch oracle: constant-0
−1 1 −1 1
0 0 0 0
−1 1 −1 1
2 2 2 2
−1 −1 −1 −1
2 2 2 2
0 0
−1
Result: |11ۧ −1
The Deutsch oracle: constant-1
|0ۧ |1ۧ
Output Output'
|xۧ BB |xۧ
Input Input'
Output X
Input
The Deutsch oracle: constant-1
−1 1 −1 1
0 0 0 0
−1 1 −1 1
2 2 2 2
−1 −1 −1 −1
2 2 2 2
0 0
−1
Result: |11ۧ −1
The Deutsch oracle: identity
|0ۧ |xۧ
Output Output'
|xۧ BB |xۧ
Input Input'
Output
Input
The Deutsch oracle: identity
−1 1 −1 1
0 0 0 0
−1 1 −1 1
2 2 2 2
−1 −1 −1 −1
2 2 2 2
0 0
−1
Result: |01ۧ −1
The Deutsch oracle: identity
1
2
1 1 −1 1 0 0 0 1 1 1 1
2 ⊗ 2 1 0 1 0 0 −1 = 1 −1 = 2 ⊗ 2
𝐶 =𝐶 2 =
−1 −1 −1 2 0 0 0 1 −1 2 1 1 −1
2 2 2 0 0 1 0 1 −1 2 2
1
2
The Deutsch oracle: negation
|0ۧ |¬xۧ
Output Output'
|xۧ BB |xۧ
Input Input'
Output X
Input
The Deutsch oracle: negation
−1 1 −1 1
0 0 0 0
−1 1 −1 1
2 2 2 2
−1 −1 −1 −1
2 2 2 2
0 0
−1
Result: |01ۧ −1
The Deutsch oracle
We did it! We determined whether the function was constant or variable in a single query!
Intuition: the difference within the categories (negation) was neutralized, while the
difference between the categories (CNOT) was magnified
This problem seems pretty contrived (and it was, when it was published)
A generalized version with an n-bit black box also exists (Deutsch-Josza problem)
Determine whether the function returns the same value for all 2𝑛 inputs (i.e. is constant)
A variant of the generalized version was an inspiration for Shor’s algorithm!
Full recap
Quantum entanglement
Quantum teleportation
Entanglement
If the product state of two qbits cannot be factored, they are said to be entangled
1 1
𝑎𝑐 =
2 2
0 𝑎 𝑐 𝑎𝑑 = 0
= ⊗
0 𝑏 𝑑 𝑏𝑐 = 0
1 1
𝑏𝑑 =
2 2
The system of equations has no solution, so we cannot factor the quantum state!
This has a 50% chance of collapsing to |00ۧ and 50% chance of collapsing to |11ۧ
Entanglement
|0ۧ
|0ۧ
H
1 1
1 1 0 0 0 2 2
1 1 2 ⊗ 1
𝐶𝐻1 ⊗ =𝐶 = 0 1 0 0 0 = 0
0 0 1 0 0 0 0 1 1 0
2 0 0 1 0 1
2
0 2
Entanglement
Quantum teleportation is the process by which the state of an arbitrary qbit is transferred
from one location to another by way of two other entangled qbits
You can transfer qbit states (cut & paste) but you cannot clone them (copy & paste)
This is called the No-cloning theorem
The teleportation is not faster-than-light, because some classical information must be sent
Teleportation
| ψۧ
𝑇 H
|0ۧ 1 0
𝐴 H 𝑍=
0 −1
|0ۧ | ψۧ
𝐵 X Z
Further learning goals
𝐴𝐵 𝑥 = 𝐴(𝐵𝑥) (𝐻𝑋𝐻)𝑥 = 𝑍𝑥
1 1 1 0 1 1 1 𝛼 1 0 𝛼
𝑎 𝑎 =
0 1 0 1 0 1 0 1 2 1 −1 1 0 1 −1 𝛽 0 −1 𝛽
=
1 0 1 0 𝑏 1 0 1 0 𝑏 1 1 1 1 −1 𝛼 𝛼
=
2 1 −1 1 1 𝛽 −𝛽
1 0 𝑎 0 1 𝑏 𝛼 𝛼
= 1 0
0 1 𝑏 1 0 𝑎 =
0 −1 𝛽 −𝛽
𝛼 𝛼
𝑎 𝑎 =
= −𝛽 −𝛽
𝑏 𝑏
You only have to care about the cumulative effect of a series of gates; the specific
sequence changes nothing.
Review: tensor product of matrices
𝑤 𝑥 𝑤 𝑥 𝑎𝑤 𝑎𝑥 𝑏𝑤 𝑏𝑥
𝑤 𝑥 𝑎 𝑦 𝑧 𝑏 𝑦 𝑧 𝑎𝑦 𝑎𝑧 𝑏𝑦 𝑏𝑧
𝑎 𝑏
⊗ 𝑦 𝑧 = 𝑤 𝑥 𝑤 𝑥 = 𝑐𝑤 𝑐𝑥
𝑐 𝑑 𝑑𝑤 𝑑𝑥
𝑐 𝑦 𝑧 𝑑 𝑦 𝑧 𝑐𝑦 𝑐𝑧 𝑑𝑦 𝑑𝑧
1 0 1 0 0 0 1 0
0 1
0 1 1 0 0 1 0 1
⊗ = = 0 0 0 1
1 0 0 1 1 0 1 0 1 0 0 0
1 0
0 1 0 1 0 1 0 0
Single-bit operations on multi-bit states
When applying gates to multi-bit states, we want to specify which qbit we’re modifying
We use subscripts to identify the qbit
The subscript value is the power of 2 associated with the significance of that qbit
So 0, 1, 2, 3, 4, etc. since any binary number is written as 𝛼0 20 + 𝛼1 21 + 𝛼2 22 + ⋯
So 𝑋2 refers to the bit-flip operator which flips the most-significant qbit in a 3-qbit system
Single-bit operations on multi-bit states
What if we want to operate on a single bit in the product state? What matrix do we use?
Example - flip the least-significant bit:
0 0 1 0 0 0 1
1 0 0 1 1 = 1 0 0 0 1 = 0 = |00ۧ
𝑋0 |01ۧ = ⊗
0 1 1 0 0 0 0 0 1 0 0
0 0 0 1 0 0 0
The operation we want is tensored with the identity matrix, in the position matching the
significance of that bit.
Single-bit operations on multi-bit states
We can also tensor multiple one-bit operators together to operate on bits in parallel.
Example – flip both bits:
0 0 0 0 1 0 0
0 1 0 1 1 = 0 0 1 0 1 = 0 = |10ۧ
𝑋1 𝑋0 |01ۧ = ⊗
1 0 1 0 0 0 1 0 0 0 1
0 1 0 0 0 0 0
Many useful operators are products of one-bit operators, but some (like CNOT) cannot be
factored that way.
Single-bit operations on multi-bit states
CNOT gate subscripts are of the form 𝐶𝑐𝑡 where 𝑐 specifies control bit and 𝑡 target bit
We can tensor CNOT matrices with the identity to operate on adjacent bits out of multiple
Throughout the presentation, the CNOT gate we used was 𝐶10
The 𝐶01 gate (with least-significant bit as control and most-significant target) is as follows:
00 00
1 0 0 0
01 01
𝐶01 = 0 0 0 1
10 10 0 0 1 0
0 1 0 0
11 11
Quantum teleportation math
| ψۧ
𝑇 H
|0ۧ 1 0
𝐴 H 𝑍=
0 −1
|0ۧ | ψۧ
𝐵 X Z
Quantum teleportation math
1
𝛼 1 1 𝛼 2 ⊗ 1
𝐻2 𝐶21 𝐶10 𝐻1 ⊗ ⊗ = 𝐻2 𝐶21 𝐶10 ⊗
𝛽 0 0 𝛽 1 0
2
𝛼 𝛼
1 0 𝛽
2 0 𝛽
𝛼 0 1 𝛼 1 𝛼
= 𝐻2 𝐶21 ⊗ = 𝐻2 =
𝛽 0 2 0 2 𝛼
1 𝛽 −𝛽
2 𝛽 −𝛽
0 𝛼
Quantum teleportation math
The state right before measurement breaks down into four cases:
𝛼 𝛼
𝛽 |00ۧ 𝛽
𝛽 𝛽
1 𝛼 1 𝛼 𝛽 𝛼 −𝛽 |01ۧ 𝛼
= ۧ
|00 𝛽 + |01ۧ + |10 −𝛽 + |11ۧ
ۧ
2 𝛼 2 𝛼 𝛼 𝛼
−𝛽 |10ۧ −𝛽
−𝛽
−𝛽
𝛼 |11ۧ
𝛼
When Alice measures her two qbits, Bob’s qbit is forced into one of four states.
The bits measured by Alice determine the state into which Bob’s qbit was forced.
Bob needs to apply a transformation to get his qbit to the state that he wants.
Bob needs to know the values of Alice’s bits to know which transformation(s) to apply.
Quantum teleportation math
𝛽 𝛽 0 1 𝛽 𝛼
|01ۧ 𝑋 = = 𝛽
𝛼 𝛼 1 0 𝛼
𝛼 𝛼 1 0 𝛼 𝛼
|10ۧ −𝛽 𝑍 −𝛽 = −𝛽 = 𝛽
0 −1
−𝛽 −𝛽 0 1 1 0 −𝛽 𝛼
|11ۧ 𝑋𝑍 = = 𝛽
𝛼 𝛼 1 0 0 −1 𝛼