














Hi, my name is Craig
and I miss university.


REACT
QUANTUM
COMPUTING
QUANTUM
COMPUTING
Quantum State
Quantum Gates
Quantum Measurement
Quantum Algorithms




?
Wow, you really do just put the word Quantum in front of everything.
Unknown
QUANTUM
COMPUTING
Quantum State
Quantum Gates
Quantum Measurement
Quantum Algorithms




?
Wow, you really do just put the word Quantum in front of everything.
Unknown
QUANTUM
COMPUTING
Quantum State
Quantum Gates
Quantum Measurement
Quantum Algorithms




?
Wow, you really do just put the word Quantum in front of everything.
Unknown
Go to your computer, Craig.
Unknown
?
QUANTUM
COMPUTING
Quantum State
Quantum Gates
Quantum Measurement
Quantum Algorithms




?
Wow, you really do just put the word Quantum in front of everything.
Unknown
Go to your computer, Craig.
Unknown
?
QUANTUM
COMPUTING
Quantum State
Quantum Gates
Quantum Measurement
Quantum Algorithms




?
Wow, you really do just put the word Quantum in front of everything.
Unknown
Go to your computer, Craig.
Unknown
?
QUANTUM
COMPUTING
Quantum State
Quantum Gates
Quantum Measurement
Quantum Algorithms




?
Wow, you really do just put the word Quantum in front of everything.
Unknown
Go to your computer, Craig.
Unknown
?



















HI CRAIG IT'S
?
It's Scott, Ant-Man, whatever, hey I need your help. 🐜
Unknown





?
It's Scott, Ant-Man, whatever, hey I need your help. 🐜
Unknown

Hurry up it's important. 🐜
Scott Lang

HI CRAIG IT'S






?
It's Scott, Ant-Man, whatever, hey I need your help. 🐜
Unknown

Hurry up it's import🐜. 🐜
Scott Lang

HI CRAIG IT'S



?
It's Scott, Ant-Man, whatever, hey I need your help. 🐜
Unknown

Hurry up it's import🐜. 🐜
Scott Lang


HI CRAIG IT'S



?
It's Scott, Ant-Man, whatever, hey I need your help. 🐜
Unknown

Hurry up it's import🐜. 🐜
Scott Lang
I am in the middle of a talk.
Reply:


HI CRAIG IT'S



?
It's Scott, Ant-Man, whatever, hey I need your help. 🐜
Unknown

Hurry up it's import🐜. 🐜
Scott Lang
I am in the middle of a talk.
Reply:


HI CRAIG IT'S



?
It's Scott, Ant-Man, whatever, hey I need your help. 🐜
Unknown

Hurry up it's import🐜. 🐜
Scott Lang
I am in the middle of a talk.
Reply:


HI CRAIG IT'S



?
It's Scott, Ant-Man, whatever, hey I need your help. 🐜
Unknown

Hurry up it's important. 🐜
Scott Lang
I am in the middle of a talk.
Reply:


HI CRAIG IT'S

I KNOW! That's why I need you. Teach the nice people about Qubits and I'll be in touch. 🐜
Scott Lang



?
It's Scott, Ant-Man, whatever, hey I need your help. 🐜
Unknown


HI CRAIG IT'S

I KNOW! That's why I need you. Teach the nice people about Qubits and I'll be in touch. 🐜
Scott Lang



?
It's Scott, Ant-Man, whatever, hey I need your help. 🐜
Unknown



I KNOW! That's why I need you. Teach the nice people about Qubits and I'll be in touch. 🐜
Scott Lang
HI CRAIG IT'S



?
It's Scott, Ant-Man, whatever, hey I need your help. 🐜
Unknown

OH AND I'M IN YOUR JAVASCRIPT
🐜🐜🐜🐜🐜🐜🐜🐜🐜🐜
🐜🐜🐜🐜🐜🐜🐜🐜🐜🐜
🐜🐜🐜🐜🐜🐜🐜🐜🐜🐜
🐜🐜🐜🐜🐜🐜🐜🐜🐜🐜
🐜🐜🐜🐜🐜🐜🐜🐜🐜🐜
🐜🐜🐜🐜🐜🐜🐜🐜🐜🐜
Bits:
0
A representation of a binary state
Qubits:
A representation of a quantum state
10
0110
11010110
0011101011010110
00101111100101100011101011010110
0010111110010110001110101101011000101111100101100011101011010110
Quantum State
Qubits:
A representation of a quantum state

Quantum State
Qubits:
A representation of a quantum state

Quantum State
Qubits:
A representation of a quantum state

Quantum State
Qubits:
A representation of a quantum state

Quantum State
Qubits:
A representation of a quantum state

Quantum State
Qubits:
A representation of a quantum state

Quantum State
Qubits:
A representation of a quantum state

Quantum State
Qubits:
A representation of a quantum state

Quantum State
Qubits:
A representation of a quantum state

Quantum State
Qubits:
A representation of a quantum state

Quantum State
Qubits:
A representation of a quantum state

Quantum State
Quantum State
const psi = [
probabilityA,
probabilityB
];
Qubits:
A representation of a quantum state
const psi = [
complex(1 / Math.sqrt(2), 0), // { r: 0.7071067812, i: 0 }
complex(0, 1 / Math.sqrt(2)) // { r: 0, i: 0.7071067812 }
];
Quantum State
Qubits:
A representation of a quantum state

Oh cool, maths. Okay here's the deal, I'm locked up in the Quantum Realm, and I need you to help me get out. 🐜
Scott Lang
type Complex = [number, number];
type Row = Array<Complex>;
type Matrix = Array<Row>;
function complex (r = 0, i = 0): Complex {
return [r, i];
}
function kZero(): Matrix {
return [[complex(1)], [complex(0)]];
}
function kOne(): Matrix {
return [[complex(0)], [complex(1)]];
}
Quantum State
Qubits:
A representation of a quantum state

Oh cool, maths. Okay here's the deal, I'm locked up in the Quantum Realm, and I need you to help me get out. 🐜
Scott Lang
type Complex = [number, number];
type Row = Array<Complex>;
type Matrix = Array<Row>;
function complex (r = 0, i = 0): Complex {
return [r, i];
}
function kZero(): Matrix {
return [[complex(1)], [complex(0)]];
}
function kOne(): Matrix {
return [[complex(0)], [complex(1)]];
}


?
It's Scott, Ant-Man, whatever, hey I need your help. 🐜
Unknown



Someone knocked me out, and I woke up in a prison cell. 🐜
Scott Lang




Someone knocked me out, and I woke up in a prison cell. 🐜
Scott Lang

BUT I accessed the system that controls the locks, and entangled myself with your CPU...
Scott Lang





Someone knocked me out, and I woke up in a prison cell. 🐜
Scott Lang

BUT I accessed the system that controls the locks, and entangled myself with your CPU...
Scott Lang

So I can send you messages and run code. 🐜
Scott Lang





Someone knocked me out, and I woke up in a prison cell. 🐜
Scott Lang

BUT I accessed the system that controls the locks, and entangled myself with your CPU...
Scott Lang

So I can send you messages and run code. 🐜
Scott Lang





Someone knocked me out, and I woke up in a prison cell. 🐜
Scott Lang

BUT I accessed the system that controls the locks, and entangled myself with your CPU...
Scott Lang

So I can send you messages and run code. 🐜
Scott Lang





Someone knocked me out, and I woke up in a prison cell. 🐜
Scott Lang

BUT I accessed the system that controls the locks, and entangled myself with your CPU...
Scott Lang

So I can send you messages and run code. 🐜
Scott Lang





Someone knocked me out, and I woke up in a prison cell. 🐜
Scott Lang

So I can send you messages and run code. 🐜
Scott Lang





Shit, someone's coming, one sec. 🐜
Scott Lang




Someone knocked me out, and I woke up in a prison cell. 🐜
Scott Lang

So I can send you messages and run code. 🐜
Scott Lang





Shit, someone's coming, one sec. 🐜
Scott Lang
Quantum Measurement
const bit: boolean = false;
console.log(bit); // false
Quantum Measurement
function normalise(ket: Matrix): KeMatrixt {
const flat = ket.map(([c]) => c);
const total = flat.reduce((sum,[re,im])=>sum+re*re+im*im,0);
return flat.map(([re,im])=>[re/Math.sqrt(total), im/Math.sqrt(total)]);
}
function measure(ket: Matrix): Matrix {
const normalised = normalise(ket);
const probabilities = normalised.map(([re, im]) => re*re + im*im);
const cumulative = [];
probabilities.reduce((acc, p, i) => {
cumulative[i] = acc + p;
return acc + p;
}, 0);
const r = Math.random();
for (let i = 0; i < cumulative.length; i++) {
if (r < cumulative[i]) return i;
}
return cumulative.length - 1;
}
Quantum Measurement
const psi = [
[complex(1, 0)],
[complex(0, 0)]
];
measure(psi); // 0
measure(psi); // 0
measure(psi); // 0
measure(psi); // 0
Quantum Measurement
const psi = [
[complex(1 / Math.sqrt(2), 0)],
[complex(0, 1 / Math.sqrt(2))]
];
measure(psi); // 0
measure(psi); // 1
measure(psi); // 0
measure(psi); // 0
measure(psi); // 1
measure(psi); // 1
Quantum Measurement
const psi = [
[complex(1 / Math.sqrt(2), 0)],
[complex(0, 0)],
[complex(0, 0)],
[complex(1 / Math.sqrt(2), 0)]
];

CRAIG. 🐜
Scott Lang
measure(psi); // 00
measure(psi); // 11
measure(psi); // 11
measure(psi); // 00
Quantum Measurement
const psi = [
[complex(0, 0)],
[complex(0, 0)],
[complex(1 / Math.sqrt(2), 0)],
[complex(1 / Math.sqrt(2), 0)]
];

CRAIG. 🐜
Scott Lang
measure(ignore(psi, 1)); // 0
measure(ignore(psi, 1)); // 0
measure(ignore(psi, 1)); // 0
measure(ignore(psi, 1)); // 0
Sometimes we only care about a specific qubit:
Quantum Measurement

CRAIG. 🐜
Scott Lang
function ignore(ket: Matrix, n: number): Matrix {
const normalized = normalise(ket);
const size = normalized.length;
const chunkSize = Math.pow(2, n);
const newKet: Ket = [];
for (let i = 0; i < size / chunkSize; i++) {
let sumProb = 0;
for (let p = i * chunkSize; p < (i + 1) * chunkSize; p++) {
const [re, im] = normalized[p];
sumProb += re * re + im * im;
}
newKet.push([[Math.sqrt(sumProb), 0]]);
}
return newKet;
}
Quantum Measurement

CRAIG. 🐜
Scott Lang
measure(psi); // 00
measure(psi); // 11
measure(psi); // 11
measure(psi); // 00

CRAIG. 🐜
Scott Lang
const psi = [
[complex(1 / Math.sqrt(2), 0)],
[complex(0, 0)],
[complex(0, 0)],
[complex(1 / Math.sqrt(2), 0)]
];
Quantum Measurement

CRAIG. 🐜
Scott Lang

CRAIG. 🐜
Scott Lang

CRAIG. 🐜
Scott Lang
measure(psi); // 00
measure(psi); // 11
measure(psi); // 11
measure(psi); // 00
const psi = [
[complex(1 / Math.sqrt(2), 0)],
[complex(0, 0)],
[complex(0, 0)],
[complex(1 / Math.sqrt(2), 0)]
];
Quantum Measurement

CRAIG. 🐜
Scott Lang

CRAIG. 🐜
Scott Lang
measure(psi); // 00
measure(psi); // 11
measure(psi); // 11
measure(psi); // 00

CRAIG. 🐜
Scott Lang
const psi = [
[complex(1 / Math.sqrt(2), 0)],
[complex(0, 0)],
[complex(0, 0)],
[complex(1 / Math.sqrt(2), 0)]
];






QUANTUM SECURITY CAM_1

I've made some progress! I've got access to the Quantum security system computer! 🐜
Scott Lang

CRAIG. 🐜
Scott Lang

CRAIG. 🐜
Scott Lang

CRAIG. 🐜
Scott Lang





QUANTUM SECURITY CAM_1

I've made some progress! I've got access to the Quantum security system computer! 🐜
Scott Lang


Darn it, there's three layers of security to get this door open. 🐜
Scott Lang

Darn it, there's three layers of security to get this door open. 🐜
Scott Lang

I'm going to try something quickly. 🐜
Scott Lang

Darn it, there's three layers of security to get this door open. 🐜
Scott Lang

I'm going to try something quickly. 🐜
Scott Lang





QUANTUM SECURITY CAM_1


Quantum Gates
Classical:
AND:
OR:
XOR:
NAND:
Apply a binary operation to a binary state:
Quantum Gates
Quantum:
Apply a matrix operation to a quantum state:
IDENTITY:
HADAMARD:
Quantum Gates
Quantum:
Apply a matrix operation to a quantum state:
Quantum Gates
Quantum:
Apply a matrix operation to a quantum state:
IDENTITY:
HADAMARD:
Quantum Gates
Quantum:
Apply a matrix operation to a quantum state:
function mIdentity (n: number = 1): Matrix {
const size = Math.pow(2, n);
return Array.from({ length: size }, (_, row) =>
Array.from({ length: size }, (_, column) => complex(row === column ? 1 : 0))
);
}
function mHadamard(): Matrix {
const oneOverRoot2 = 1 / Math.sqrt(2);
return [
[complex(oneOverRoot2), complex(oneOverRoot2)],
[complex(oneOverRoot2), complex(-oneOverRoot2)],
];
}
Quantum Gates
Quantum:
Quantum Gates
Quantum:
const H = mHadamard()
const psi = kZero();
const Hpsi = [
[H[0][0] * psi[0] + H[0][1] * psi[1]],
[H[1][0] * psi[0] + H[1][1] * psi[1]]
];
console.log(Hpsi);
// [[0.7071067811865475], [0.7071067811865475]]
Quantum Gates
Quantum:
As the number of qubits increases, so does the complexity of the expressions:
Kronecker Product
Quantum Gates
Quantum:
Kronecker Product
Quantum Gates
Quantum:
Kronecker Product
Quantum Gates
Quantum:
Kronecker Product
Quantum Gates
Quantum:
Kronecker Product
Quantum Gates
Quantum:
Kronecker Product
Quantum Gates
Quantum:
Kronecker Product
const zero = kZero(); // [[1], [0]]
const one = kOne(); // [[0], [1]]
const zeroKronOne = [
[zero[0] * one[0]],
[zero[0] * one[1]],
[zero[1] * one[0]],
[zero[1] * one[1]]
];
console.log(zeroKronOne); // [[0], [1], [0], [0]]
Quantum Gates
Quantum:
Kronecker Product
const H = mHadamard();
const HkronH = [
[
H[0][0] * H[0][0], H[0][0] * H[0][1],
H[0][1] * H[0][0], H[0][1] * H[0][1]
],
[
H[0][0] * H[1][0], H[0][0] * H[1][1],
H[0][1] * H[1][0], H[0][1] * H[1][1]
],
[
H[1][0] * H[0][0], H[1][0] * H[0][1],
H[1][1] * H[0][0], H[1][1] * H[0][1]
],
[
H[1][0] * H[1][0], H[1][0] * H[1][1],
H[1][1] * H[1][0], H[1][1] * H[1][1]
]
];
Quantum Gates
Quantum:
Kronecker Product
const H = mHadamard();
const HkronH = [
[
H[0][0] * H[0][0], H[0][0] * H[0][1],
H[0][1] * H[0][0], H[0][1] * H[0][1]
],
[
H[0][0] * H[1][0], H[0][0] * H[1][1],
H[0][1] * H[1][0], H[0][1] * H[1][1]
],
[
H[1][0] * H[0][0], H[1][0] * H[0][1],
H[1][1] * H[0][0], H[1][1] * H[0][1]
],
[
H[1][0] * H[1][0], H[1][0] * H[1][1],
H[1][1] * H[1][0], H[1][1] * H[1][1]
]
];
function cAdd(c1: Complex, c2: Complex): Complex {
const [c1r, c1i] = c1;
const [c2r, c2i] = c2;
return [c1r + c2r, c1i + c2i];;
}
function cMultiply(c1: Complex, c2: Complex): Complex {
const [c1r, c1i] = c1;
const [c2r, c2i] = c2;
return [
c1r * c2r - c1i * c2i,
c1i * c2r + c1r * c2i,
];
}
function mKron(...matrices: Array<Matrix>): Matrix {
if (matrices.length === 1) {
return matrices[0];
}
const [m1, m2, ...rest] = matrices;
const height1 = m1.length, width1 = m1[0].length;
const height2 = m2.length, width2 = m2[0].length;
const kronProd: Matrix = Array.from(
{ length: height1 * height2 },
() => Array(width1 * width2)
);
for (let m = 0; m < height1; m++) {
for (let n = 0; n < width1; n++) {
for (let p = 0; p < height2; p++) {
for (let q = 0; q < width2; q++) {
const newM = m * height2 + p;
const newN = n * width2 + q;
kronProd[newM][newN] = cMultiply(m1[m][n], m2[p][q]);
}
}
}
}
return mKron(kronProd, ...rest);
}
function mMultiply (...matrices: Array<Matrix>): Matrix {
const [first, second, ...rest] = matrices;
const height1 = first.length,
width1 = first[0].length;
const height2 = second.length,
width2 = second[0].length;
if (width1 !== height2) {
throw new Error("Matrix dimensions incorrect for multiplication.");
}
for (let r = 0; r < height1; r++) {
for (let c = 0; c < width2; c++) {
let val = complex(0);
for (let k = 0; k < width1; k++) {
val = cAdd(val, cMultiply(first[r][k], second[k][c]));
}
result[r][c] = val;
}
}
let product = result;
for (const m of rest) {
product = mMultiply(product, m);
}
return product;
}




QUANTUM SECURITY CAM_1



OH HI CRAIG IT'S DARREN. I HAVE SCOTT.
MODOK




QUANTUM SECURITY CAM_1



OH HI CRAIG IT'S DARREN. I HAVE SCOTT.
MODOK

HE'S NEVER GETTING OUT OF HERE.
MODOK




QUANTUM SECURITY CAM_1



OH HI CRAIG IT'S DARREN. I HAVE SCOTT.
MODOK

HE'S NEVER GETTING OUT OF HERE.
MODOK




QUANTUM SECURITY CAM_1



OH HI CRAIG IT'S DARREN/MODOK. I HAVE SCOTT.
MODOK

HE'S NEVER GETTING OUT OF HERE.
MODOK




QUANTUM SECURITY CAM_1



OH HI CRAIG IT'S DARREN/MODOK. I HAVE SCOTT.
MODOK

HE'S NEVER GETTING OUT OF HERE.
MODOK






OH HI CRAIG IT'S DARREN/MODOK. I HAVE SCOTT.
MODOK

HE'S NEVER GETTING OUT OF HERE.
MODOK

Craig! It's Cassie, Scott's daughter!
Cassie Lang





OH HI CRAIG IT'S DARREN/MODOK. I HAVE SCOTT.
MODOK

HE'S NEVER GETTING OUT OF HERE.
MODOK

Craig! It's Cassie, Scott's daughter!
Cassie Lang

We've figured out how to open dad's cell! You need to run some Quantum Algorithms!
Cassie Lang





OH HI CRAIG IT'S DARREN/MODOK. I HAVE SCOTT.
MODOK

HE'S NEVER GETTING OUT OF HERE.
MODOK

Craig! It's Cassie, Scott's daughter!
Cassie Lang

We've figured out how to open dad's cell! You need to run some Quantum Algorithms!
Cassie Lang

It's Deutsch-Josza, Grover, Shor, in that order! But we don't know the inputs!?
Cassie Lang





OH HI CRAIG IT'S DARREN/MODOK. I HAVE SCOTT.
MODOK

HE'S NEVER GETTING OUT OF HERE.
MODOK

Craig! It's Cassie, Scott's daughter!
Cassie Lang

We've figured out how to open dad's cell! You need to run some Quantum Algorithms!
Cassie Lang

It's Deutsch-Josza, Grover, Shor, in that order! But we don't know the inputs!?
Cassie Lang





OH HI CRAIG IT'S DARREN/MODOK. I HAVE SCOTT.
MODOK

HE'S NEVER GETTING OUT OF HERE.
MODOK

Craig! It's Cassie, Scott's daughter!
Cassie Lang

We've figured out how to open dad's cell! You need to run some Quantum Algorithms!
Cassie Lang

It's Deutsch-Josza, Grover, Shor, in that order! But we don't know the inputs!?
Cassie Lang
Quantum Algorithms
Deutsch
The Deutsch Algorithm solves a problem that isn't particularly difficult or particularly important, but it can be solved faster on a quantum computer than on a classical computer.
Quantum Algorithms
Deutsch
const constant0 = () => 0
const constant1 = () => 1
const balancedX = (x) => x;
const balancedNotX = (x) => 1 - x;
const oracles = [constant0, constant1, balancedX, balancedNotX];
const oracle = oracles[Math.floor(Math.random() * oracles.length)];
Quantum Algorithms
Deutsch: Classical
const constant0 = () => 0
const constant1 = () => 1
const balancedX = (x) => x;
const balancedNotX = (x) => 1 - x;
const oracles = [constant0, constant1, balancedX, balancedNotX];
const oracle = oracles[Math.floor(Math.random() * oracles.length)];
const constant = oracle(0) === oracle(1);
const balanced = !constant;
A classical solution of Deutsch requires inspecting the oracle twice - once with each input
Quantum Algorithms
Deutsch: Quantum
Initial state with two qubits
Quantum Algorithms
Deutsch: Quantum
Hadamard gate for two qubits
Apply Hadamard gate to get superposition
Quantum Algorithms
Deutsch: Quantum
Black Box "Oracle" for the unknown function
Apply the Oracle to the superpositioned state
Quantum Algorithms
Deutsch: Quantum
First Qubit only Hadamard gate
Apply the gate to the state
Quantum Algorithms
Deutsch: Quantum
The second qubit contains redundant information
Quantum Algorithms
Deutsch: Quantum
const constant0 = [[complex(1),complex(0),complex(0),complex(0)],[complex(0),complex(1),complex(0),complex(0)],[complex(0),complex(0),complex(1),complex(0)],[complex(0),complex(0),complex(0),complex(1)]];
const constant1 = [[complex(0),complex(1),complex(0),complex(0)],[complex(1),complex(0),complex(0),complex(0)],[complex(0),complex(0),complex(0),complex(1)],[complex(0),complex(0),complex(1),complex(0)]];
const balancedX = [[complex(1),complex(0),complex(0),complex(0)],[complex(0),complex(1),complex(0),complex(0)],[complex(0),complex(0),complex(0),complex(1)],[complex(0),complex(0),complex(1),complex(0)]];
const balancedNotX = [[complex(0),complex(0),complex(1),complex(0)],[complex(0),complex(0),complex(0),complex(1)],[complex(1),complex(0),complex(0),complex(0)],[complex(0),complex(1),complex(0),complex(0)]];
const oracles = [constant0, constant1, balancedX, balancedNotX];
const oracle = oracles[Math.floor(Math.random() * oracles.length)];
const zero = kZero();
const one = kOne();
const phi0 = mKron(kZero(), kOne());
const HkH = mKron(mHadamard(), mHadamard());
const phi1 = mMultiply(HkH, phi0);
const phi2 = mMultiply(oracle, phi1);
const HkI = mKron(mHadamard(), mIdentity());
const phi3 = mMultiply(HkI, phi2);
const result = measure(ignore(phi3, 1));
if (result === 0) {
console.log('Function is constant');
} else {
console.log('Function is balanced');
}
A quantum solution of Deutsch requires inspecting the oracle just once!
Quantum Algorithms
Deutsch - Jozsa
Generalised Deutsch algorithm for bigger inputs
Quantum Algorithms
Deutsch - Jozsa: Classical
const oracle = ORACLES[Math.floor(Math.random() * oracles.length)];
function isConstant (f, n) {
const first = f(0);
for (let i = 1; i < 2 ** n; i++) {
if (f(i) !== first) {
return false;
}
}
return true;
}
const constant = isConstant(oracle, 3);
const balanced = !constant;
A classical solution requires inspecting the oracle 2 ⁿ times!
Quantum Algorithms
Deutsch - Jozsa: Quantum
Initial state with three qubits
Hadamard gate for three qubits
Quantum Algorithms
Deutsch - Jozsa: Quantum
Apply Hadamard gate to get superposition
Quantum Algorithms
Deutsch - Jozsa: Quantum
Black Box "Oracle" for the unknown function
Size will increase exponentially with number of qubits
Apply the Oracle to the superpositioned state
Quantum Algorithms
Deutsch - Jozsa: Quantum
First N-1 Qubits Hadamard gate
Apply the gate to the state
Quantum Algorithms
Deutsch - Jozsa: Quantum
The second qubit contains redundant information
Quantum Algorithms
Deutsch - Jozsa: Quantum
const oracle = [
// ...
];
let x = kZero();
for (let i = 1; i < n; i++) {
x = mKron(x, kZero());
}
let y = kOne();
const phi0 = mKron(x, y);
const Hn = mKron(...Array(n).fill(mHadamard()));
const HnH = mKron(Hn, mHadamard());
const phi1 = mMultiply(HnH, phi0);
const phi2 = mMultiply(oracle, phi1);
const HnI = mKron(Hn, mIdentity());
const phi3 = mMultiply(HnI, phi2);
const outcome = measure(ignore(phi3, 1));
if (outcome === 0) {
console.log("Function is constant");
} else {
console.log("Function is balanced");
}
A quantum solution still requires inspecting the oracle just once!





OH HI CRAIG IT'S DARREN/MODOK. I HAVE SCOTT.
MODOK

HE'S NEVER GETTING OUT OF HERE.
MODOK

Craig! It's Cassie, Scott's daughter!
Cassie Lang

We've figured out how to open dad's cell! You need to run some Quantum Algorithms!
Cassie Lang

It's Deutsch-Josza, Grover, Shor, in that order! But we don't know the inputs!?
Cassie Lang
DEUTSCH-JOSZA





OH HI CRAIG IT'S DARREN/MODOK. I HAVE SCOTT.
MODOK

HE'S NEVER GETTING OUT OF HERE.
MODOK

Craig! It's Cassie, Scott's daughter!
Cassie Lang

We've figured out how to open dad's cell! You need to run some Quantum Algorithms!
Cassie Lang

It's Deutsch-Josza, Grover, Shor, in that order! But we don't know the inputs!?
Cassie Lang
DEUTSCH-JOSZA

THAT WORKED. THE FIRST LOCK OPENED! 🐜
Scott Lang





OH HI CRAIG IT'S DARREN/MODOK. I HAVE SCOTT.
MODOK

HE'S NEVER GETTING OUT OF HERE.
MODOK

Craig! It's Cassie, Scott's daughter!
Cassie Lang

We've figured out how to open dad's cell! You need to run some Quantum Algorithms!
Cassie Lang

It's Deutsch-Josza, Grover, Shor, in that order! But we don't know the inputs!?
Cassie Lang
DEUTSCH-JOSZA

THAT WORKED. THE FIRST LOCK OPENED! 🐜
Scott Lang
Quantum Algorithms
Grover's
Finds a marked item in an unsorted database of N items.
Quantum Search Algorithm
Quantum Algorithms
Grover's: Classical
const N = 8;
const marked = 5;
const result = [...Array(N).keys()].find(x => x === marked);
console.log(result);
A classical solution of Grovers requires inspecting each item once.
Quantum Algorithms
Grover's: Quantum
Initial state with two qubits
Quantum Algorithms
Grover's: Quantum
Hadamard gate for two qubits
Apply Hadamard gate to get superposition
Quantum Algorithms
Grover's: Quantum
Black Box "Oracle" for the search function
Apply the Oracle to the superpositioned state
Quantum Algorithms
Grover's: Quantum
Fancy operator made up of multiple gates
Quantum Algorithms
Grover's: Quantum
Apply diffusion
times
Quantum Algorithms
Grover's: Quantum
const N = Math.pow(2, n);
let state = kZero();
for (let i = 1; i < n; i++) {
state = mKron(state, kZero());
}
let Hn = mHadamard();
for (let i = 1; i < n; i++) {
Hn = mKron(Hn, mHadamard());
}
state = mMultiply(Hn, state);
const ones = Array.from({ length: N }, () => Array.from({ length: N }, () => complex(1 / N)));
const I = mIdentity(n);
const D = Array.from({ length: N }, (_, r) => Array.from({ length: N }, (_, c) => {
const [onesReal] = ones[r][c];
const [identityReal] = I[r][c];
return complex(2 * onesReal - identityReal, 0);
}));
const iterations = Math.max(Math.floor((Math.PI / 4) * Math.sqrt(N)), 1);
for (let i = 0; i < iterations; i++) {
state = mMultiply(oracle, state);
state = mMultiply(D, state);
}
console.log(measure(state));
The quantum algorithm requires only iterations!





OH HI CRAIG IT'S DARREN/MODOK. I HAVE SCOTT.
MODOK

HE'S NEVER GETTING OUT OF HERE.
MODOK

Craig! It's Cassie, Scott's daughter!
Cassie Lang

We've figured out how to open dad's cell! You need to run some Quantum Algorithms!
Cassie Lang

It's Deutsch-Josza, Grover, Shor, in that order! But we don't know the inputs!?
Cassie Lang
GROVER'S





OH HI CRAIG IT'S DARREN/MODOK. I HAVE SCOTT.
MODOK

HE'S NEVER GETTING OUT OF HERE.
MODOK

Craig! It's Cassie, Scott's daughter!
Cassie Lang

We've figured out how to open dad's cell! You need to run some Quantum Algorithms!
Cassie Lang

It's Deutsch-Josza, Grover, Shor, in that order! But we don't know the inputs!?
Cassie Lang
GROVER'S

NICE! The second lock is open!
Cassie Lang





OH HI CRAIG IT'S DARREN/MODOK. I HAVE SCOTT.
MODOK

HE'S NEVER GETTING OUT OF HERE.
MODOK

Craig! It's Cassie, Scott's daughter!
Cassie Lang

We've figured out how to open dad's cell! You need to run some Quantum Algorithms!
Cassie Lang

It's Deutsch-Josza, Grover, Shor, in that order! But we don't know the inputs!?
Cassie Lang
GROVER'S

NICE! The second lock is open!
Cassie Lang
Quantum Algorithms
Prime Factorisation: Classical
let n = 391;
const factors = [];
for (let i = 2; i < n; i++) {
while (n % i === 0) {
factors.push(i);
n = n / i;
}
}
if (n > 1) {
factors.push(n);
}
console.log(factors);
Not web scale
Quantum Algorithms
Shor's Algorithm
It efficiently finds non-trivial factors of a composite number NNN
Quantum Algorithms
Shor's Algorithm
let a;
do {
a = Math.floor(Math.random() * (N - 2)) + 2;
} while (gcd(a, N) !== 1);
console.log(`Chosen a = ${a}`);
const n = Math.ceil(Math.log2(N));
const m = Math.ceil(Math.log2(N));
let input = kZero();
for (let i = 1; i < n; i++) input = mKron(input, kZero());
let output = kZero();
for (let i = 1; i < m; i++) output = mKron(output, kZero());
let phi0 = mKron(input, output);
const Hn = Array.from({ length: n }, () => mHadamard());
const HnKron = mKron(...Hn, mIdentity(m));
let phi1 = mMultiply(HnKron, phi0);
const U_f = modExpMatrix(a, N, n);
const UfFull = mKron(U_f, mIdentity(m));
let phi2 = mMultiply(UfFull, phi1);
const QFTn = qft(n);
const QFTFull = mKron(QFTn, mIdentity(m));
let phi3 = mMultiply(QFTFull, phi2);
const measured = measure(ignore(phi3, m));
console.log(`Estimate of period fraction: ${measured}`);
let r = 1;
while (modExp(a, r, N) !== 1) r++;
console.log("Estimated period r =", r);
if (r % 2 === 0) {
const factor1 = gcd(modExp(a, r / 2, N) - 1, N);
const factor2 = gcd(modExp(a, r / 2, N) + 1, N);
console.log(`Potential factors: ${factor1}, ${factor2}`);
} else {
console.log("Odd period found; retry with another a");
}





OH HI CRAIG IT'S DARREN/MODOK. I HAVE SCOTT.
MODOK

HE'S NEVER GETTING OUT OF HERE.
MODOK

Craig! It's Cassie, Scott's daughter!
Cassie Lang

We've figured out how to open dad's cell! You need to run some Quantum Algorithms!
Cassie Lang

It's Deutsch-Josza, Grover, Shor, in that order! But we don't know the inputs!?
Cassie Lang
SHOR'S





OH HI CRAIG IT'S DARREN/MODOK. I HAVE SCOTT.
MODOK

HE'S NEVER GETTING OUT OF HERE.
MODOK

Craig! It's Cassie, Scott's daughter!
Cassie Lang

We've figured out how to open dad's cell! You need to run some Quantum Algorithms!
Cassie Lang

It's Deutsch-Josza, Grover, Shor, in that order! But we don't know the inputs!?
Cassie Lang
SHOR'S

WHAT! HOW ARE YOU DOING THIS!
MODOK





OH HI CRAIG IT'S DARREN/MODOK. I HAVE SCOTT.
MODOK

HE'S NEVER GETTING OUT OF HERE.
MODOK

Craig! It's Cassie, Scott's daughter!
Cassie Lang

We've figured out how to open dad's cell! You need to run some Quantum Algorithms!
Cassie Lang

It's Deutsch-Josza, Grover, Shor, in that order! But we don't know the inputs!?
Cassie Lang
SHOR'S

WHAT! HOW ARE YOU DOING THIS!
MODOK




OH HI CRAIG IT'S DARREN/MODOK. I HAVE SCOTT.
MODOK

HE'S NEVER GETTING OUT OF HERE.
MODOK

Craig! It's Cassie, Scott's daughter!
Cassie Lang

We've figured out how to open dad's cell! You need to run some Quantum Algorithms!
Cassie Lang

It's Deutsch-Josza, Grover, Shor, in that order! But we don't know the inputs!?
Cassie Lang



I'M OUT! THANKS CRAIG! 🐜
Scott Lang




OH HI CRAIG IT'S DARREN/MODOK. I HAVE SCOTT.
MODOK

HE'S NEVER GETTING OUT OF HERE.
MODOK

Craig! It's Cassie, Scott's daughter!
Cassie Lang

We've figured out how to open dad's cell! You need to run some Quantum Algorithms!
Cassie Lang

It's Deutsch-Josza, Grover, Shor, in that order! But we don't know the inputs!?
Cassie Lang



I'M OUT! THANKS CRAIG! 🐜
Scott Lang

THE END
deck
By Craig Spence
deck
- 2