Mathematical Background For Quantum Computing: Georgina Carson

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

Mathematical Background for

Quantum Computing
Georgina Carson

This is a brief summary of some of the maths needed to understand quantum computing,
which you might not have seen before. If you’re familiar with these topics, you can use this
as a refresher on your existing knowledge, and check that you’re across all the required
topics.

If any of this is new to you, I recommend doing some further learning, as this document
just covers the basics. I’ve provided some resources for each topic for you to learn more
and practice on examples.

Don’t expect to have to do all of this maths by hand throughout the course – most of
it will be done by computer, and there won’t be an exam or anything! You just need to
have a conceptual understanding of what is happening in these topics, so that you don’t
get lost when I refer to them when teaching quantum computing theory.

I am assuming a high-school level knowledge of algebra and trigonometry, and will be


giving all angles in radians (0 ≤ θ ≤ 2π).

A good calculator that can do all this maths (and much more) is WolframAlpha. Keep
this bookmarked to quickly check your working throughout this course.

1
Binary Numbers

Computers, both classical and quantum, represent numbers in a different way to humans.
When you write down a number, you’re usually using base 10, otherwise known as decimal.
The number 10 in base 10 means that we have 10 different digits to use (0-9) and each
digit’s place represents a power of 10. From right to left, we have ones, tens, hundreds,
thousands, ten thousands, et cetera.

Take the number 1736 as an example. Working from right to left, we have 6 ones, 3
tens, 7 hundreds, and 1 thousand. In other words, we can write this number as:

1736 = 1 × 103 + 7 × 102 + 3 × 101 + 6 × 100

Nearly every number you see is written in base 10, because that’s what humans are used
to – but in fact you can use any base to write numbers! Some of the bases you might
have heard of are binary (base 2), ternary (base 3), octal (base 8) and hexadecimal (base
16).

Binary, or base 2, is the most common way computers represent numbers. Rather than
10 different digits, we only have two digits (0 and 1). This is an easy representation for
computers, since the two states can be represented physically by a switch or transistor,
with 0 = “off” and 1 = “on”.

In binary, the places go up by powers of two. From right to left, we have ones, twos,
fours, eights, sixteens, et cetera.

Digit place 8 7 6 5 4 3 2 1 0
Value in binary 28 = 256 27 = 128 26 = 64 25 = 32 24 = 16 23 = 8 22 = 4 21 = 2 20 = 1

Table 1: Decimal values corresponding to the first 9 places in binary.

The 1s and 0s of binary have a special name: bits. The number of bits in a number
is simply the number of digits required to write that number down in binary. You’ve
probably heard of bits before - we use them to measure computer memory. In fact, the

2
number of bits (digits) you need to write a number in binary corresponds exactly to the
amount of physical memory (number of transistors) that your computer needs to store
that number.

Converting decimal to binary

Follow these steps to convert decimal numbers to binary:

1. Find the largest power of 2 that is smaller than your number.

2. Put a 1 in the place corresponding to that power of 2, and 0s everywhere else.

3. Subtract the power of 2 from your original number.

4. Repeat steps 1-3 with the new, smaller number, until you get down to 0.

It’s handy to write out the powers of 2 for reference; see Table 1 for the first 9 digits in
binary.

Examples

Converting the number 19 to binary:

Decimal value remaining Highest power of 2 Binary value so far


19 24 = 16 10000
19 − 16 = 3 21 = 2 10010
0
3−2=1 2 =1 10011

Converting the number 1736 to binary:

3
Decimal value remaining Highest power of 2 Binary value so far
10
1736 2 = 1024 10000000000
1736 − 1024 = 712 29 = 512 11000000000
712 − 512 = 200 27 = 128 11010000000
6
200 − 128 = 72 2 = 64 11011000000
3
72 − 64 = 8 2 =8 11011001000

Converting binary to decimal

Binary to decimal is simple - just add up the decimal value of every place containing a 1,
and ignore the places with 0s.

Examples

The binary number 10011base2 is equal to 19 in decimal notation:

10011base2
= 1 × 24 + 0 × 23 + 0 × 22 + 1 × 21 + 1 × 20
= 16 + 2 + 1
= 19

The binary number 11011001000base2 is equal to 1736 in decimal notation:

11011001000base2
= 1 × 210 + 1 × 29 + 0 × 28 + 1 × 27 + 1 × 26 + 0 × 25 + 0 × 24 + 1 × 23 + 0 × 22 + 0 × 21 + 0 × 20
= 1024 + 512 + 128 + 64 + 8
= 1736

4
What you need to know for this course

You should be able to read and convert small numbers (up to 5 bits) between binary
and decimal. When we write quantum programs in the IBM Quantum Experience, we
program the physical qubits directly, meaning that everything is in binary. Understanding
binary will help you interpret the input and output of your program.

Further resources

• Khan Academy: Binary numbers

• Learn How to Read Binary in 5 Minutes

• CSIRO Double Helix: Binary for beginners

5
Complex Numbers

Complex numbers are used to represent quantum states. The complex numbers include
all real numbers (the numbers you already know about), plus the imaginary unit i.

To understand what i is, we need to have a look at square roots. You may have learnt
that it is impossible to take the square root of a negative number. This is true for the
real numbers. There is no number on the real number line that you could square to get
−4, for instance.

Complex numbers arise as a bit of mathematical fun – what if we imagine a number


exists that we could square to get a negative number? Mathematicians call this imaginary
number i, and it’s defined to be the square root of −1.

i2 = −1

We can then define a complex number as any number of the form:

z = a + bi

Where a and b can be any real numbers (including 0). a is called the real part and b is
called the imaginary part of the complex number.

It turns out that these complex numbers aren’t just a mathematical game, they actually
have real uses! Many concepts in electrical engineering are described efficiently using
complex numbers, and quantum mechanics only makes sense if we allow complex numbers
to represent quantum states.

6
Complex Arithmetic

Complex numbers work basically the same as every other number – just remember that
i2 = −1, and otherwise treat i) as any other variable.

When adding complex numbers, add the real and imaginary parts separately:

(a + bi) + (c + di) = (a + c) + (b + d)i

When multiplying complex numbers, follow distributive multiplication rules (just like
when expanding out a quadratic):

(a + bi) × (c + di) = ac + adi + bci + cdi2


= ac + adi + bci + cd(−1)
= (ac − cd) + (ad + bc)i

The complex conjugate of a complex number is the number with the same real part, but
with the opposite sign on the imaginary part. The complex conjugate of z is represented
by z. If z = a + bi, then:
z = (a + bi) = a − bi

The magnitude, or modulus of a complex number, |z|, is a real number which measures
how “big” the complex number is. We define the magnitude of a complex number as the
square root of the product of the number and its complex conjugate. We can simplify
this down a little. If z = a + bi, then:

2
|z| = zz
= (a + bi)(a − bi)
= a2 − abi + abi − b2 i2
= a2 + b2
p
|z| = a2 + b2

7
For purely real or imaginary numbers, the magnitude is simpler to calculate:

zre = x; |zre | = |x|


zim = yi; |zim | = |y|

Examples

1
Let z1 = 3 − 2i and z2 = 2 + 4i. Then:

1
z1 + z2 = 3 − 2i + + 4i
2
7
= + 2i
2

1
z1 − z2 = 3 − 2i − ( + 4i)
2
5
= − 6i
2

z1 × z2 = (3 − 2i) × (0.5 + 4i)


3
= + 12i − i − 8(−1)
2
19
= + 11i
2

z1 = 3 + 2i
1
z2 = − 4i
2
p
|z1 | = 32 + 2 2

= 13
r
1
|z2 | = ( )2 + 42
2
r
65
=
4

8
Argand diagrams

An easy way to represent complex numbers is on the complex plane. Just as the real
numbers can be represented on a number line, we can represent complex numbers on a
plane, with the real part plotted on the x-axis and the imaginary part on the y-axis. We
call this representation an Argand diagram (see Figure 1).

Figure 1: An Argand diagram of the complex number z = x + iy. We can see the
magnitude r = |z| and phase angle θ represented in this diagram. Source: Wikipedia

On an Argand diagram, it is sometimes more useful to represent complex numbers in


polar coordinates, rather than Cartesian coordinates. We can describe the number with
its magnitude and angle from the x-axis, rather than its x- and y-coordinates.

The magnitude |z| of a complex number is equal to its distance from the origin in the
complex plane. Notice that the set of all complex numbers with the same magnitude form
a circle around the origin.

We can also define the angle θ that z makes with the x-axis (anticlockwise). This is called
the phase or argument of the number, and ranges from 0 on the positive x-axis, to π/2

9
on the positive y-axis, to π on the negative x-axis, to 3π/2 on the negative y-axis, and
finally back to 2π, which is equivalent to 0 in polar coordinates.

To calculate the magnitude (aka modulus, Mod(z), or |z|) and phase (aka argument,
Arg(z), or θ) of a complex number z = x + yi:
p
|z| = Mod(z) = x2 + y 2



 0, for x > 0, y > 0

Im(z) 
θ = Arg(z) = arctan ( )+ π, for x < 0
Re(z) 



 2π, for x > 0, y < 0

To convert back to Cartesian coordinates:

x = |z| cos θ
y = |z| sin θ

We often write complex numbers in exponential form, a useful way to represent polar
coordinates. We define:
|z|e iθ = |z|(cos θ + i sin θ)

In this form, multiplying complex numbers becomes very simple – just multiply the
magnitudes and add the phases. We can visualise this on an Argand diagram. Take
the vector corresponding to the first number, rotate it anticlockwise by the phase of the
second, and multiply its length by the magnitude of the second.

|z1 |e iθ1 × |z2 |e iθ2 = |z1 ||z2 |e i(θ1 +θ2 )

It’s useful to note that multiplying a number by i, or e iπ/2 in exponential form, rotates
π
that number anticlockwise by 2.

10
Examples

Cartesian form Exponential form


1 e0i
π
i e2i
−1 eπ i

−i e2i
√ πi
1+i 2e 4
√ πi
5 + 5i 5 2e 4
π
√1 (1 + i) e4i
2

√1 (1 − i) e 4 i
2

√1 (1 − i) e 4 i
2
√ π
i
3+i 2e 6

√ π
3+i 2e 6 i
√ 2π
i
1 − 3i 2e 3

We get the same result multiplying complex numbers in Cartesian and exponential form:

What you need to know for this course

Quantum computing requires familiarity with complex numbers. You need to be able
to confidently add and multiply complex numbers in both Cartesian and exponential
form, and find the magnitude and phase of a complex number. For the most part in
this experiment, the maths will be done by a computer, not by hand, but we will work
through a few examples by hand when learning the concepts of quantum computing.

Further resources

• Khan Academy: Complex numbers

• Paul’s Online Notes: Complex Numbers Primer

11
• 3Blue1Brown’s lecture on complex number fundamentals

12
Matrix Algebra

Matrices are a convenient way of expressing complicated ideas in a variety of fields, par-
ticularly quantum physics, graphics, computer modelling and finance. The basic concept
of a matrix is just a grid of numbers. For example, let’s call the following matrices M
and N :

   
1 6 −2 10 −1 2
   
M = 0
 0 4
 N =
 0 11 5

2 1 −1 0 −3 0

We call M a 3 × 3 matrix, since it has 3 rows and 3 columns. We always list rows before
columns, but in this course we only need to use square matrices (same number of rows
and columns), so it doesn’t matter too much.
The numbers in M are called the elements of the matrix. These can be any number at all,
including 0 or complex numbers. We refer to each element by its position in the matrix.
For example, the (2, 3) element of M is the element in the 2nd row and 3rd column; that
is, the number 4.

Another type of matrix we need to know about is the column matrix, sometimes called
a vector. This is just a matrix with only one column. Let’s define the following 3 × 1
matrix:  
5
 
c = 1


2

Adding matrices

Adding and subtracting matrices is simple – you just add or subtract the elements in
corresponding cells. You can only add or subtract matrices with identical di-
mensions. We can add M and N , but not M and c.

13
     
1 6 −2 10 −1 2 11 5 0
     
M +N =
0 0
 +   =
4   0 11 5  0  11 9

2 1 −1 0 −3 0 2 −2 −1

Multiplying matrices

Multiplying matrices is defined rather differently to multiplying numbers. You can only
multiply two matrices together if the number ofrows in the first matrix equals the number
of columns in the second matrix. If you multiply a x × y matrix by a y × z matrix, the
result will be a x × z matrix.
Note that matrix multiplication is not commutative – it matters which order
you multiply them!

The process of matrix multiplication is as follows:

1. Choose an element to calculate. We’ll start with element (1,1) (the top left).

2. Highlight (in your mind or otherwise) row 1 of the first matrix, and column 1 of the
second matrix.

3. Multiply the corresponding elements of this row and column. Multiply the first
element in the row by the first element in the column, the second in the row by the
second in the column, and so on.

4. Add the results of these multiplications, and place the result in element (1,1) of the
final answer.

5. Repeat the process for every element of the final matrix.

For element (1,2), we use row 1 of the first matrix, and column 2 of the second.

For element (2,3), we use row 2 of the first matrix, and column 3 of the second.

This is much easier to understand visually, so here’s an example.

14
Matrix multiplication example

Let’s multiply our two square matrices from earlier.


     
1 6 −2 10 −1 2 ? ? ?
     
M ·N = 0 0 4  ·  0 11 5 = ?
    ? ?

2 1 −1 0 −3 0 ? ? ?

First, let’s calculate element (1,1). We take row 1 of the first matrix, multiply its elements
by the corresponding elements in column 1 of the second matrix, and add the resulting
numbers.      
1 6 −2 10 −1 2 10 ? ?
     
M · N = 0
 0 4 ·0
  11 5 =  ?
  ? ?

2 1 −1 0 −3 0 ? ? ?
Working:
1 × 10 + 6 × 0 + −2 × 0 = 10 + 0 + 0 = 10

Now let’s do element (1,2):


     
1 6 −2 10 −1 2 10 71 ?
     
M ·N = 0 0 4  ·  0 11 5 =  ?
   ? ?

2 1 −1 0 −3 0 ? ? ?

Working:
1 × −1 + 6 × 11 + −2 × −3 = −1 + 66 + 6 = 71

Repeating the process for every element gives us the final answer:
     
1 6 −2 10 −1 2 10 71 32
     
M ·N = 0 0 4  ·  0 11
 
 =  0 −12
5  0 
2 1 −1 0 −3 0 20 12 9

Another example, multiplying M by c:


       
1 6 −2 5 1 × 5 + 6 × 1 + −2 × 2 7
       
M ·N = 0 0 4  · 1 =  0 × 5 + 0 × 1 + 4 × 2  = 8
      

2 1 −1 2 2 × 5 + 1 × 1 + −1 × 2 9

Notice how a square matrix multiplied by a column matrix gives us a column matrix of
the same size.

15
One very special matrix is the square identity matrix, often called I. This is the 4 × 4
identity matrix:  
1 0 0 0
 
0 1 0 0
 
 
0 0 1 0
 
0 0 0 1
If you multiply the identity matrix by any other matrix (with matching dimensions),
you’ll get the same matrix back. Try it for yourself!

What you need to know for this course

Every operation on a quantum computer can be represented by a square matrix, and


every quantum state can be represented by a column matrix. Again, computers will do
most of the work for us, since matrix multiplication can get very long and tedious, but
you need to be able to understand matrix multiplication to know what’s happening when
you apply a quantum operation.

You should understand how to multiply square matrices and column vectors, and do
simple ones fairly quickly by hand (up to about 4 × 4, with many of the elements just
being 1, 0 or i so they’re not too hard).

Further resources

• Khan Academy: Intro to Matrix Multiplication

• 3 Ways to Understand Matrix Multiplication by Glenn Henshaw

• Wolfram-Alpha can multiply matrices for you, if you want to check your working.
See this guide for how to input matrices.

16

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy