Gareth J. Janacek & Mark Lemmon Close
Mathematics for Computer Scientists
Mathematics for Computer Scientists
2014 Gareth J. Janacek, Mark Lemmon Close & Ventus Publishing ApS ISBN 978-87-7681-426-7
Contents
Numbers
The statement calculus and logic
Mathematical Induction
Sets
Counting
Functions
Sequences
Calculus
Algebra: Matrices, Vectors etc.
Probability
Looking at Data
Introduction
The aim of this book is to present some the basic mathematics that is needed by computer scientists. The reader is not expected to be a mathematician and we hope willnd what follows useful.
Just a word of warning. Unless you are one of the irritating minority math- ematics is hard. You cannot just read a mathematics book like a novel. The combination of the compression made by the symbols used and the precision of the argument makes this impossible. It takes time and eort to decipher the mathematics and understand the meaning.
It is a little like programming, it takes time to understand a lot of code and you never understand how to write code by just reading a manual - you have to do it! Mathematics is exactly the same, you need to do it.
Chapter 1 Numbers
Defendit numerus: There is safety in numbers
We begin by talking about numbers. This may seen rather elementary but is does set the scene and introduce a lot of notation. In addition much of what follows is important in computing.
1.0.1 Integers
We begin by assuming you are familiar with th e integers
1,2,3,4 , .. . ,101,102 ,... , n,... , 2 32582657 1, .. . ,
sometime called the whole numbers. These are just the numbers we use for count- ing. To these integers we add th e zer o , 0, dened as
0+ any intege rn=0+n=n+0= n
Once we have the integers and zero mathematicians create negative integers by denin g(n) as:
the number which when added t on gives zero, s on + (n ) = (n ) +n= 0.
Eventually we get fed up with writin gn + (n ) =0 and write this a snn=0 .
We have now got the positive and negative integer s{... , 3 , 2 , 1, 0, 1, 2, 3, 4, .. . }
You are probably used to arithmetic with integers which follows simple rules.
To be on the safe side we itemize them, so for integer sa an d b 1 .a+b=b+ a
ab=ba o r a b= ba
ab= ab
4 .(a)(b ) = ab
5. To save space we writ e a k as a shorthand fo ra multiplied by itsel fk times. So3 =3333 an d = . Not e a n a m = a n + m
6. Do note tha t n =1.
Factors and Primes
Many integers are products of smaller integers, for exampl e 2 3 7= 4. Here
2, 3 and 7 are called th e factor s of 42 and the splitting of 42 into the individual components is known a s factorizatio n . This can be a dicult exercise for large
integers, indeed it is so dicult that it is the basis of some methods in cryptography.
Of course not all integers have factors and those that do not, such as
3, 5, 7, 11, 13,... , 216091 1,...
are known a s prime s . Primes have long fascinated mathematicians and others see
http://primes.utm.edu/,
and there is a considerable industry looking for primes and fast ways of factorizing integers.
To get much further we need to consider division, which for integers can be tricky since we may have a result which is not an integer. Division may give rise to a remainde r , for example
9=24+ 1.
and so if we try to divide 9 by 4 we have a remainder of 1 .
In general for any integer sa an d b
b=ka+ r
wher er is th e remainder . I fr is zero then we sa ya divide s b writte na|b . A single vertical bar is used to denot e divisibilit y . For exampl e2| 12 8,7| 4but 3 d o es not divide 4, sym b olicall y 3.
Aside
Tond the factors of an integer we can just attempt division by primes i.e.
2, 3, 5, 7, 11, 19, .. .. If it is divisible b yk the nk is a factor and we try again. When we cannot divide b yk we take the next prime and continue until we are left with a prime. So for example:
1. 2394/2=1197 cant divide by 2 again so try 3
2. 1197/3=399
3. 399/3 = 133 cant divide by 3 again so try 7 ( not divisible by 5) 4. 133/7 = 19 which is prime so 2394 =2337 19
Modular arithmetic
Th e mo d operator you meet in computer languages simply gives the remainder after division. For example,
1 . 2mo d4=1 becaus e 2 54=6 remainder 1. 2 . 1mo d5=4 sinc e 1 9=35+4 .
3 . 2mo d5=4 .
4 . 9mo d 1 1=0 .
There are some complications when negative numbers are used, but we will ignore them. We also point out that you will often see these results written in a slightly dierent way i.e . 2 4=4 mo d5 o r 2 1=0 mo d7 . which just mean s 2mo d5 =
an d 21 o d7=
Modular arithmetic is sometimes called clock arithmetic. Suppose we take a
24 hour clock so 9 in the morning is 09.00 and 9 in the evening is 21.00. If I start a journey at 07.00 and it takes 25 hours then I will arrive at 08.00. We can think of this as 7+25 = 32 and 32 mod 24 = 8. All we are doing is starting at 7 and going around the (25 hour) clock face until we get to 8. I have always thought this is a complex example so take a simpler version.
Four people sit around a table and we label their positions 1 to 4. We have a
pointer point to position 1 which we spin. Suppose it spins 11 and three quarters or 47 quarters. The it is pointing a t 4mo d4 or 3.
The Euclidean algorithm
Algorithms which are schemes for computing and we cannot resist putting one in at this point. The Euclidean algorithm fornding the gcd is one of the oldest algorithms known, it appeared in Euclids Elements around 300 BC. It gives a way ofnding the greatest common divisor (gcd) of two numbers. That is the largest number which will divide them both.
Our aim is tond a a way ofnding the greatest common divisor, gc d( a, b) of two integer sa an db .
Suppos ea is an integer smaller tha nb .
1. Then tond the greatest common factor betwee na an db , divid eb b ya . If the remainder is zero, the nb is a multiple o fa and we are done.