You are on page 1of 5

262

| The Institution of Structural Engineers


Computational engineering

Appendix K:
Quantum computing 230,262

Quantum computing involves many things far beyond our experience here in the classical world, but the maths can
be surprisingly straightforward.

Vector notation
We can represent quantum bits (qubits) with the Dirac vector notation:
   
1 0
0 = |0 〉 = 1 = |1〉 =
0 1

The values in Dirac vectors represent the amplitude (probability) of the qubit collapsing to that value when measured:
  √
α P(0)
|ψ〉 = α|0〉 + β|1〉 = = √
β P(1)

Where α and β are complex numbers and |α|2 + |β|2 = 1. The qubit will collapse to 0 with a probability of |α|2
   
1 0
and to 1 with a probability |β|2 . The qubit has a 100% chance of collapsing
 to 0, and has a 100% chance
0 √1
1
of collapsing to 1. A qubit in an equal superposition of 0 and 1 has the value 12 , which shows that it has a
√
 2
√1 2
 2 = 2 chance of collapsing to 0 or 1.
1

Similarly, a two-qubit register’s Dirac vector represents:


⎛ ⎞ ⎛ √ ⎞ ⎛ √ ⎞
α P (0 ) P(00)
⎜ β ⎟ ⎜ √ ⎟ ⎜ √ ⎟
⎜ ⎟ ⎜ P(1) ⎟ ⎜ P(01) ⎟
|ψ〉 = α|00〉 + β|01〉 + γ|10〉 + δ|11〉 = ⎜ ⎟ = ⎜ √ ⎟ = ⎜ √ ⎟
⎝ γ ⎠ ⎝ P(2) ⎠ ⎝ P(10) ⎠
√ √
δ P (3 ) P(11)

We derive these Dirac vectors by taking the tensor product of the individual qubit vectors, which we call the
product state:
⎛  ⎞ ⎛ ⎞
c ac
 a  c  ⎜ a
⎜ d ⎟ ⎜
⎟ ⎜ ad ⎟

⊗ = ⎜  ⎟ = ⎜ ⎟
b d ⎝ c ⎠ ⎝ bc ⎠
b
d bd
The Institution of Structural Engineers
Computational engineering | 263

where |ac|2 + |ad|2 + |bc|2 + |bd|2 = 1. We can factor the product state back to the individual state representation if
the qubits are not entangled. The product state of n bits is a vector of size 2n.
⎛ ⎞ ⎛ ⎞
1 0
    ⎜ ⎟     ⎜ ⎟
1 1 ⎜0⎟ 1 0 ⎜1⎟
0 = |00〉 = ⊗ =⎜ ⎟ 1 = |01〉 = ⊗ =⎜ ⎟
0 0 ⎝0⎠ 0 1 ⎝0⎠
0 0
⎛ ⎞ ⎛ ⎞
0 0
    ⎜ ⎟     ⎜ ⎟
0 1 ⎜0⎟ 0 0 ⎜0⎟
2 = |10〉 = ⊗ =⎜ ⎟ 3 = |11〉 = ⊗ =⎜ ⎟
1 0 ⎝1⎠ 1 1 ⎝0⎠
0 1
⎛ ⎞
0
⎜0⎟
⎜ ⎟
⎜ ⎟
⎜0⎟
      ⎜
⎜0⎟

0 0 1 ⎜ ⎟
|6〉 = |110〉 = ⊗ ⊗ =⎜ ⎟
1 1 0 ⎜0⎟
⎜ ⎟
⎜0⎟
⎜ ⎟
⎜ ⎟
⎝1⎠
0

If we have two qubits in superposition we get:


⎛1⎞
  2
√1 √1 ⎜1⎟
⎜ ⎟
2
⊗ 12 = ⎜ 21 ⎟
√1 √ ⎝2⎠
2 2
1
2

 2
Note that 12 = 14, so there is a 1
4 chance of collapsing to |00〉, |01〉, |10〉, or |11〉.

While measuring a qubit will collapse it, we can manipulate the qubits without measuring them and thus leave them
in superposition. We mathematically manipulate the qubit vectors using matrix operations.

Logic gates
Classical computing uses a number of logic gates.

NOT OR AND XOR


Input Output Input 1 Input 2 Output Input 1 Input 2 Output Input 1 Input 2 Output
0 1 0 0 0 0 0 0 0 0 0
1 0 0 1 1 0 1 0 0 1 1
1 0 1 1 0 0 1 0 1
1 1 1 1 1 1 1 1 0
264
| The Institution of Structural Engineers
Computational engineering

Quantum computing also uses logic gates:

CNOT gate
The Controlled NOT or CNOT gate has a control bit that remains unchanged, but the target bit is flipped if the
control qubit is equal to 1.

CNOT
Input Output

Control Target Control Target

0 0 0 0

0 1 0 1

1 0 1 1
1 1 1 0

The matrix form of the CNOT gate is:


⎛ ⎞
1 0 0 0
⎜0 1 0 0⎟
⎜ ⎟
c=⎜ ⎟
⎝0 0 0 1⎠
0 0 1 0
⎛ ⎞⎛ ⎞ ⎛ ⎞
1 0 0 0 1 1
    ⎜    
1 1 ⎜0 1 0 ⎟ ⎜ ⎟
0 ⎟⎜ 0 ⎟ ⎜ 0 ⎟

⎟ 1 1
c|00〉 = c ⊗ =⎜ ⎟⎜ ⎟ = ⎜ ⎟ = ⊗ = |00〉
0 0 ⎝0 0 0 1 ⎠ ⎝ 0 ⎠ ⎝ 0 ⎠ 0 0
0 0 1 0 0 0
⎛ ⎞⎛ ⎞ ⎛ ⎞
1 0 0 0 0 0
    ⎜    
1 0 ⎜0 1 0 ⎟ ⎜ ⎟ ⎜
0 ⎟⎜ 1 ⎟ ⎜ 1 ⎟ ⎟ 1 1
c|01〉 = c ⊗ =⎜ ⎟⎜ ⎟ ⎜ ⎟= = ⊗ = |01〉
0 1 ⎝0 0 0 1 ⎠⎝ 0 ⎠ ⎝ 0 ⎠ 0 0
0 0 1 0 0 0
⎛ ⎞⎛ ⎞ ⎛ ⎞
1 0 0 0 0 0
    ⎜ ⎜ 0 ⎟ ⎜ 0 ⎟ 0 0
0 1 ⎜0 1 0 0⎟⎟⎜ ⎟ ⎜ ⎟
c|10〉 = c ⊗ =⎜ ⎟⎜ ⎟ = ⎜ ⎟ = ⊗ = |11〉
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 1 0 ⎟ ⎜ ⎟
0 ⎟⎜ 0 ⎟ ⎜ 0 ⎟

⎟ 0 1
c|11〉 = c ⊗ =⎜ ⎟⎜ ⎟ = ⎜ ⎟ = ⊗ = |10〉
1 1 ⎝0 0 0 1 ⎠⎝ 0 ⎠ ⎝ 1 ⎠ 1 0
0 0 1 0 1 0
The Institution of Structural Engineers
Computational engineering | 265

CCNOT or Toffoli gate


The Toffoli or controlled-controlled-not gate is similar to the CNOT gate but works on three qubits. It inverts the third
bit only if both the first bits are set to 1.

CCNOT
Input A Input B Input C Output A Output B Output C

0 0 0 0 0 0

0 0 1 0 0 1

0 1 0 0 1 0

0 1 1 0 1 1
1 0 0 1 0 0

1 0 1 1 0 1

1 1 0 1 1 1

1 1 1 1 1 0

The matrix form is:


⎛ ⎞
1 0 0 0 0 0 0 0
⎜0 1 0 0 0 0 0 0⎟
⎜ ⎟
⎜ ⎟
⎜0 0 1 0 0 0 0 0⎟
⎜ ⎟
⎜0 0 0⎟
⎜ 0 0 1 0 0 ⎟
CC = ⎜ ⎟
⎜0 0 0 0 1 0 0 0⎟
⎜ ⎟
⎜0 0 0⎟
⎜ 0 0 0 0 1 ⎟
⎜ ⎟
⎝0 0 0 0 0 0 0 1⎠
0 0 0 0 0 0 1 0

Hadamard gate
The Hadamard gate takes a 0- or 1-bit and puts it into equal superposition:
⎛ ⎞ ⎛ ⎞
√1 √1   √1
⎝ 2 2
⎠ 1 ⎝ 2

H|0〉 = =
√ √
1 −1 0 √
1
2 2 2
⎛ ⎞ ⎛ ⎞
√1 √1   √1
0
H|1〉 = ⎝ ⎠ ⎝ ⎠
2 2 2
=
√1 √
−1 1 √
−1
2 2 2

The Hadamard gate is reversible, so if we reapplied it to the superimposed qubits they would revert to their original
state: they would transition out of superposition without measurement and thus the quantum calculation can be
deterministic.
266
| The Institution of Structural Engineers
Computational engineering

Entanglement
We can entangle two qubits by using a Hadamard gate on one, then using it as the control of a CNOT gate with the
other (Figure K1). First initialise both qubits to |0〉, then pass one through the Hadamard gate to put it into
superposition, before using the CNOT gate to entangle them.

Figure K1: Entanglement of two qubits


|0l

|0l
H C

⎛ ⎞⎛ √1 ⎞ ⎛ √1 ⎞
1 0 0 0
      
2
⎜ ⎟ ⎜ ⎟
2
√1 ⎜0 ⎟ ⎜ ⎟ ⎜ ⎟
1 1 1 ⎜ 1 0 0⎟ 0
⎟=⎜ 0 ⎟
CH1 ⊗ =C 2
⊗ = ⎜ ⎟⎜
0 0 √1 0 ⎝0 0 0 ⎜ 1 ⎟
1 ⎠⎝ √ ⎠ ⎝ 0 ⎟


2 2
0 0 1 0 √1
0 2

If the product state of two qubits cannot be factored back to the individual qubits, they are said to be entangled.
⎛ 1 ⎞
√
2
ac = √12
⎜ ⎟    
⎜0⎟ ad = 0
⎜ ⎟= a ⊗ c
⎜0⎟ b d bc = 0
⎝ ⎠
√1 bd = √12
2

This has no solution but does have a 50% chance of collapsing to |00〉 and 50% to |11〉.

If a qubit had been initialised to |1〉 the entangled pair would collapse to |01〉 or |10〉, which I will leave to you to
prove.

For further reading, two important quantum algorithms are Grover’s algorithm263, for fast searching of unordered
databases, and Shor’s algorithm264, which factors exceptionally large numbers exponentially faster than a
classical computer.

You might also like