Sunteți pe pagina 1din 156

Gareth J.

Janacek & Mark Lemmon Close


Mathematics
for Computer Scientists
Gareth J. Janacek & Mark Lemmon Close
Mathematics
for Computer Scientists
2009
Mathematics for Computer Scientists
2009 Gareth J. Janacek, Mark Lemmon Close & Ventus Publishing ApS
ISBN 978-87-7681-426-7
3
Mathematics for Com puter Scientists Contents
Contents
Introduction 7
Chapter 1 8
1.0,1 Integers 8
1.0.2 Rationals and Reals 12
1.0.3 Number Systems 14
Chapter 2 The Statement Calculus and Logic 22
2.0.4 Analyzing Arguments Using Truth Tables 33
2.0.5 Contradiction and Consistency 36
Chapter 3 Induction 37
Chapter 4 Sets 41
4.0.6 Relations and Functions 47
Chapter 5 Counting 51
5.0.7 Binomial Expensions 55
Mathematics for Com puter Scientists Contents
Chapter 6 Functions 58
6.0.8 Imp01iant Functions 66
6.1 Functions and Angular Measw'e 71
Chapter 7 Sequences 75
7.0.1 Limits or Sequences 76
7.1 Series 79
7.1.1 T 111111 i te Ser; es RO
Chapter 8 Calculus 85
8.0.2 Continuity and Differentiability 87
R.0.3 Newto11-Raphson Methods 93
8.0.4 Intehrals and Integrations 96
Chapter 9 Algehra: Vectors ect. 100
9.0.5 Equation Sol ving 101
9.0.6 More on Matrices 108
9.0.7 Addition and Subtraction 108
9.1 Detenninants 116
9.2 Propeliies of the Determinant 117
9.2.1 Cramer's Rule 119
Chapter 10 Prop ability 121
5
Mathematics for Com puter Scientists
10.0.2
10.0.3
10.0A
10.0.5
10.0.6
10.1
10.1.1
10.1.2
10.1.3
10.1.4
10.2
Chapter 11
11.1
11.1.1
11.1.2
11.2
Propability - the Rules
Equally Likely Events
Conditional Probability
Bayes
Random Variables and Distributions
Expectation
Monents
Some Discrete Probability Distributions
Continuous Variables
Some Continuous Probability Distributions
The Normal Distribution
Looking at Data
Looking at Data
Summary Statistics
Diagrams
Scatter Diagrams
6
Contents
123
123
126
129
131
132
133
135
13R
140
146
148
14R
149
152
154
Mathematics for Com puter Scientists
Introduction
The a.ln1 of this book is 1,0 presenL sorne the basic 111;1Lhernatics tha,t is needed by
cOlnputer scientisLs. The reader is not expected 1,0 be a, rnatherna,tician and \ve
hope will find whaL follows useful.
J1lst. a word of w;:trning. Unless yon ;:tre one of the irritat.ing minority mat h-
emat.ics iR 118,1'0. 1"011 cannot jnst re8d 8, ll1Rt hematicR hook like a novel. The
cOIIlbination of the cOlnpression Inade by the SYIIlbolb used and the precibion of
the arguIIlent Inakes this irnpossible. It takes tiIIle and effort to decipher the
lnathernatics and understand the IIleaning.
It is a, liLtle like progrannning, it takes tirne to undersLand a 101, of code and
you never understand how to wriLe code by just reading; a nlcUlUctl - }'OU have to
do it! IVlat.hell1R.tic:s is eXRdly t.he Rame, yon need to do it.
7
Introduction
Mathematics for Com puter Scientists Chapter 1. Numbers
Chapter 1
NUlllbers
\Ve begin by t;:dking :='thont nnmbers. ThiR m8Y seen rather elementary hut iR does
Ret the Rcene and introdnce A lot of notAtion. In addition mnch of \vhat follmvR is
iInportant in cornputing.
1.0.1 Integers
\Ve hegin hy ass11ming you are familiar ,vith the intr:gers
2
32582657 1
1,2,:3,4" , ,,101,102: " , ,11" , , , - '" "
Rometime ulllen the \vll0le numbers. TheRe are jnRt the n11mherR \ve 11Re for connt-
ing. To thet:le integers \ve add the ;;ero, 0, defined as
0+ allY integer n = 0 + n = n + 0 = n
OlKe we have the int egers and hero nlctLhernaticians u'eat e negctLi ve integers uy
de llning (-n) as:
tlle n11mher Wllidl ,vhen anded to n giveR 7.ero: RO n + (-n) = (-n) + n = O.
Eventnally \ve get fen np \vith writing n+ (-n) = 0 8nn ,vrite this 8,R n-n = O.
\Ve hmre nmv got tlle positive ann negative integers { ... ,-3, -2, -1,O,l,2,3,4, ... J
Yon are probably URen to 8Tit hmetic \vith integers ,vhic;h followR simple r11leR.
To he Oll the safe t:lide \ve iternize theIn, so for integers a cUld b
1. a+b=b+a
2. a x b = b x a or a b = ba
3. -a X b = -ab
8
Mathematics for Com puter Scientists Chapter 1. Numbers
4. (-a)x(-b)=ab
5. To save space \ve \vrite a k as a shorthand for a Inultiplied by itself k tinleb.
So 3
4
= 3 x 3 x 3 x 3 and 2
10
= 1024. Note an x am = ani m
Factors and PriInes
lVla.ny integers are products of srnaller integers, [or exarnple 2 x 3 x 7 = 42. IIere
2, :3 and 7 are cctlled the .radon) o[ 42 and the splitting; o[ 42 into the individual
componentR iR known aR far:torization. This c;;m be a difficlllt exerc:iRe fOf large
integefs: inoeed it iR RO difficult tll;;tt it is the hasiR of Rome methodR in cfyptography.
Of course not all integers have factors and those that do not, buch as
3 5 7 11 1
, 2216lW 1 1
, " ) .:), ... , - , ...
are kllO\Vll as primes. PrirIleb have long fascinated rnathelnaticians and others see
http://primes.utm.edu/,
ano tllere iR a c:onRidenthle industry looking for prirnes and faRt v'laYR of fadori:;>;ing
integerR.
To get Inuch further vve need to consider division, vvhich for integer:::; can be
tricky :::;inee \ve Inay have a. rebult \vhich is an integer. Divibion rnay give ri:::;e to a
rt'1nai1tder, [or eXcuIlple
9=2x4+1.
and RO if \ve try to divide 9 by 4 ,ve have a femainoer of 1
In general for any integefs Q ;;1110 b
b=kxa+r
where T i:::; the Te-rnaindcT. If r is zero then we say a di'uidc8 b vvritten a I b. A
:::;ingle vertiull bar is used to denote diuisibilii-y. For exarnple 2 I 128, 7 I 49 but ~
does llot divide /1, bYlnbolically 3 /4.
Aside
To fino the fadorR of an integef \ve C;:'IJ1 jllRt atternpt diviRion by primeR i.e.
2,35,7,11,19, ... _ If it iR diviRihle hy k then k is a f;:'l.ctOf and \ve try ;:'I.gain.
\\Then we ca.nnot divide by k we take the next prirne and continue until we aTe left
with a prilne. So for exalnple:
1. 2:394/2=1197 can'1, divide by 2 again so tr}' :3
9
Mathematics for Com puter Scientists Chapter 1. Numbers
2. 1197/3=:399
'J. 'Jon ") 1 ')') 't -1" . -1 1 2" ....., ( t -1" . "11 h r.:')
o .J.:J:-:J / oJ = .h) c;:'m , u]Vlue)y ag;;:un RO try ( no, u]VIRl ) e y ,)
/'1. = 19 which ib prirne so 239J =2 X 3 X 3 x 7 x 19
IVlodular arithrnetic
The mod operator you rlleet in cornputer languetges sirnpl}' gives the the rernainder
after oivision. For example,
1. 25 rllod 4 = 1 becetuse 25 -;- 4 = 6 reillaincier 1.
2. 19 moo 5 = 4 Rince 19 = 3 x 5 + 4 .
24 Inod 5 = 4.
4. 99 nlOd 11 = O.
There aTe sonle cornplications "vhen negative nUInbers are but \ve "vill ignore
theIn. \Ve also point out that .you \'lill often bee thebe results \'lritten in a slightly
diIIerent way i.e. 24 = 4 rnod 5 or 21 = 0 IlIod 7. v.'hic"h just rneeU1S 24 IlIod 5 =
4 and 27 IlIod 7 = 0
l\:lodula.r arithrneLic is sOllIeLirnes called dock aritlnnetic. Suppose \Ve take a
24 h011r clock so 9 in the morning iR 09.00 ana (:) in the evening iR 21.00. If I start
a jonrney at 07.00 ;:'I,no it t;:'l,kes 2,) h011rs then I will arrive at Otl.OO. \Ve can think
of this as 7+225 = and B2 Inod 2/1 = 8. All \ve are doing is starting at 7 and
going around the (25 hour) clock face until we get to 8. I have ahvays thought this
is d, cOlnplex exmnple bO take a siInpler version.
Four peOlJle sit around a table etnd vve label their positions 1 to 4. \Ve have a
pointer IJoint to position 1 which v.'e spin. Suppose it spins 11 and three quarters
or 47 q11arterR. Tlle it iR pointing; ;:'It
1
47 1'noo 4 or ::L

4
( f )

2
10
Mathematics for Com puter Scientists Chapter 1. Numbers
The Euclidecill algorithm
Algoritlnns which are bcherneb for cornputing and we cannot resist putting one
in a.t Lhis point. The Euclidean algori 1111n [or finding the gcd is one of the oldest
a.lgori11nns known, iL appeared in Euclid's Elernents around ;300 13C.11 gives a \vay
of finding t.he greateRt c;ommon diviso1' g u ~ ) of two nnrnherR. That. is t.he l;;trgest
numhef whic;h will oivioe t.hern both.
Onr aim is to fino ;;t a "VRY of finding tlle gfe;:ttest. c;ommon rliviRof, gc;rl( a, b) of
two integers Q and b.
Suppobe Q ib an integer srnaller than b.
1. Then 1.0 find the greatest c-onlIIlOn fador between a andb: divide b by a. If
the rerna.inder is zero: then b is a. InulLiple of Q and we are done.
2. If not, divide the divisor a by the rerna.inder.
Cont.inue t.his p1'oceRS: oivioing t.he last diviso1' by the l;:tRt 1'emainoef, nntil the
rem;:tinrle1' is 7.e1'O. The l;:tRt nOn-7.e1'O 1'ernainoef is then the greatest C;0111mon f;:tc:t.01'
of the intege1's a anrl b.
11
Mathematics for Com puter Scientists Chapter 1. Numbers
T11A ;:dgorit11m is illw:;t.ratAo by t.he follovYing example. Consioer 72 and 246.
\VA have t.he following 4 steps:
1. 246 = 3 x 72 + 30 or 246 IlIod 72 = 30
2. 72 = 2 x 30 + 12 or 72 Inod 30 = 12
;:L 30 = 2 x 12 + 6 or 30 moo 12 = 6
it 12=2x6+0
so the gcd is 6.
There are several websites that offer Java applications using thib v'll'
give a Python function
def gcd(a,b):
II"" the euclidean algorithm """
if b == 0:
return a
else:
return gcd(b, (a%b))
Those of you who would like to see a direct appliccttion of SOllIe these ideas 100
c;omputing should look ;:tt the section on ranoorn numbers
1.0.2 Rationals and Reals
Of c;onrRe life wonlo he harcl if we only hacl int.egers :='tncl it. is a short Rtep t.o the
rat.ionalR or fractions. By a nttion;:d nnmher \ve mean a nnrnher th;:tt (::='tn he vYritten
:='tR PI Q w11e1'e P and Q :='Ire integers. Examples are
3
2 4
7
11
7
6
These nUInbers aribc ill a.n obvious you can iInagine a rulcr divided into 'ith:::;:
i:llld thCll v'll' can Ineabure a. length in of hmrc Inore
conl}Jlica.1oed dellnitions based on IIlodular a.riLhrnetic . They vvollld argue Lhat for
every integer 11, excluding :,.';ero, there is an inverse, writ ten 1 In which has Lhe
properLy Lha.1o
1 1
nx-=-xn=l
n n
Of course lIlllltiplying lin by m gives a fraction min. These ctre of Len called
ral:iO'lI.a[ nwnbers.
\Ve can Illana.g;e \viLh the silnple idea, of fractions.
12
Mathematics for Com puter Scientists Chapter 1. Numbers
One problcln \ve encounter is that there are nUlnbers which arc neither integers
or rationals but sOlnething else. The Greeks vvere surprised and confused \vhen it
was dell10nstraLed Lhat V2 could not be written exa.ctlv ctS a [racLion. Technicallv
there ;=tre no int.eger values P ann Q snch th;=d, P / Q = ,'J2. '
F1'om onr point of vievY we will not need t.o nelve muc;h fnrther into the netails:
eRpecially A.R we can get goon enongh Rl)proxim;=ttion nRing fractions, For example
22/7 ib a reabonablc approxilnation for 'iT "vhile Li is better. )rou will find
people refer to the Teal n'uTnbcT'8, sonletinles "vritten by which they rnean all the
nUlIlbers we have discussed to daLe.
Notation
As yon vyill hAve realized hy no,\, there is a goon oe;;d of notation ann \ve liRt some
of t.he Ryrnhols and functionR YOll rnay meet .
If x is If.'i8 than 1-) tllen we write x < 1-). If there is a pORRihilit.y t hat they
rnight be equal then x :::; 1), Of course \ve can write thebe the other \vay
around. So 1J > x or 1) :2: x. Obvioubl,Y we can also say 1J is greater than x
or greater Lhan or equal 1.0 x
The 17001' f(l'nd:ion o[ ct rectlnurnber x, denoted by lx.J or floor(x), is a.
fUIlcLion that returns Lhe largest integer less Lhcu1 or equal to x.. So l2.7 J = 2
and l-3.6 J = -3. The function floor in .JAva ann Pyt.hon performs this
operation.
13
Mathematics for Com puter Scientists Chapter 1. Numbers
A leRR uRed function iR the tf'1hng j111l.dion, \\'ritten r xl or ceil (x) or ceiling( x) 1
is t.he function that. ret.urns tlle sm:=,dlest integ;er not IfS.'! than x.
r2.7l = 3. There iR an obviouR(?) connection t.o moo Rince b mod a
can be written b - flOOT(b Q) x Q, SO 25 IJlod 4 = 25 - l25/4J x 4 =
25 - 6 x 4 = 1
The 1flo(lulu,'j o[x vniLLenl xl is just. x \\'hen x 0 and -x when x < O. So
I 2 1= 2 and I -6 1= 6. The LUTloUS result etbout the 1110dulus is tha,t [or anv
x and y
I x + 1:1 1<1 x I + 11:1 I
\Ve lnet Q b when we discussed integers and in the saUle \vay \ve can have
x
lJ
\vhen x and 1:1 are integers. \Ve discuss this in detail "vhen \ve rneet the
exponential function, Note ho\vever
aO=l [or all a
o h = 0 for all values of b except zero \vhere we \vill use 0 = 1.
1.0.3 Number Systems
\Ve are so useo to \\'orking; in a clecirnal syst.em \\'e forget th;:tt it iR a recent invention
and \\':='tR a revolllt.ionary idea. It iR t.irne we lookeo ulreflllly at. ho\\' \ve represent
llulnbers. \Ve llonnally use the deciInal systern so J,t')!) is shorthand for 3 x 1000 +
4 x 100 + 5 x 50 + 9. The position of the digit is vital as it enables us to distinguish
bet vveen ;30 and 3. The declrnal systern is et positional nun1eral sys1,ern; i1, hetS
positions [or uni1,s, tens, hundreds and so OIl. The position o[ eetch digit iIT1}Jlies
t.he mult.iplier (;:'1, po\ver of ten) to be llseo \\'ith that ancl each pORition h;:tR
a value ten t.irnes t.hat. of the posit.ion to its right.. Perh;:tps t.he devereRt part \\':='tR
t.he aodition of t.he decim;:d point allo\ving UR t.o incluoe oecim;:d fradions. ThuR
12]A5C1 is equivalent to
1 x 100+2 x 10 +3+ nurnherR after the point +4 x 1/10+5 x 1/100 +6 X 1/1000
1\,1 ult i plier
digits
')
d
T
oecim;:d point
10-
1
4
10-
2
10-
3
S (j
However t.here is no real reason why we should use powers o[ 10, or base 10.
The 13etbylonians use base 60 and base 12 \Vas very COnlITlOn during the ITliddle
ages in Europe. Today the conlIIlOn nunlber sys1,enls are
14
Mathematics for Com puter Scientists
Decimal ll111'nher \fste1'n: symholR 0-9: h:='tRe 10
Binary nUlnber systeln:sYlnbols syrnbols 0: 1; base 2
Hexadecirnal nurnbeI bYbtern:syrnbolb 0-9:A-F'; base Hi
here .A == 10 . B == 11 . C == 12 , D ==):3 E == 14 ~ F== 15.
Octal number system: RY1'nhols 0-7; hase is
Binary
Chapter 1. Numbers
In the binary scale \ve express nUlnbeIb in pm,vers of 2 rather than the lOb of the
decirnal scale. _For SOlne nUlnbers this is easv so. if recall 2 = 1,
Dec;imal
111nnber
8
7
,)
..1
2
1
in po\vers of 2
z ~
22+ 21 + 20
22+21
22 + 2
l
)
22
2' +2
2'
2
po\ver of 2
:) 2 1 0
1 000
o I I 1
o I I 0
o I 0 1
o 1 0 0
001 1
001 0
000 1
Binary llumber
1000
I II
110
101
100
11
10
1
As ill decinlal we vvrite this with the position of the digit representing the pov.'er,
the first place after the decirnal being the 2 position the next the 2' awJ so on.
To convert a o.ecim;=d nllmher to binary ,ve UUl lIse Ol1r mod operator.
As all example cOllRio.er SiS in o.ecjm;=d or 88
10
. \\le \vo111o. like to "vrite it :='tR a
hin;=try. \Ve take tlle ll111'n11er allo. Ruc;c;essively oivioe mod 2. See helo",'
Step llulnber n Xn l xnj2 J Xn Inod 2
0 SiS 44 0
I 44 22 0
2 22 11 0
.J
,) 11
,)
1
4 5 2 1
i) 2 1 0
G 1 0 1
\Vriting the last col111'nn in re"l!fT8e, that iR from the hottom lIP, we have 10 11000
Wllidl iR tlle binary for of 8S: i.e.SS10 = 1011000
2
.
15
Mathematics for Com puter Scientists Chapter 1. Numbers
Binary decilnals arc lebb COIIlIIlon but quite thus 101.1011 ib just
22 + 2 + 2-
1
+ 2-
3
+ 2-
4
which is: ct[ter SOlne calcula,Lion 5.6875. \Ve have see hov.'
to Lurn the integer parL of a, decilnal nUlnber inLo ct bina,r.Y' nurnber and v,,re can do
the sarne with a, decilnal fraction. Consider 0.6875. S before v.'e dravv up a table
Step nurnber n Xn l xn/
2
J Xn lHod 2
0
0.()87,) 1.37,) 1
1 0.;375 0.75 0
2 0.75
1 r.:
.,'} 1
;3
0.5 1 1
givillg reading down 0.687510 = 1011
2
Beware it is possible to get into a non-ending cycle \\,rhen v,,re have a. non
terrninating decilnal. _For exa.lnple 0.4.
Step mnnl)er n
Xn l xn/
2
J X-rL
moo 2
0 OA 0.8 0
1 0.8
1.()
1
2 O.G 1.2 1
:3 0.2 0.4 0
4 0.4 0.8 0 t- here we repeat
')
.J O.S 1.0
4
so 0.410 = 0.011 0011 0011 00 ... 2
16
Mathematics for Com puter Scientists
Anoition in binary
0+0 = 0
0+1 = 1
J + 1 = J 0 RO we carry 1 :='mo Ip,;::rve a :;;o;ero
1+1+1 = 1+(1+1)=1+10=11 .
\Ve CcU1 wriLe Lhis in ver)' lnudl the sa.n1e way as for a decilnal addition
1 1 0 1 0 1
+
1 0 1 1 1 0
1 1 0 0 0 1 1 SUIn
r r
Chapter 1. Numbers
t.he rigllt hano llparro,v show ,vhere vve carry a 1. The left h;:tno one Rho,vR
where we have 1 + 1 + 1 so vve carry a 1 and have Cl. 1 left over
To t:lubtrad
1 1 0 1 0 1
1 0 1 1 1 0
0 0 0 nifferenr,e
I'vlulLiplication in dedInal
2
;)
0
'7
8 IVfl11tiplir,and I
x 3 8
....,
I'vT lIlt ipl ier {
8
'7
0
'7
4 G tilnes 7 I (
0 0
;)
4 2 4 Shift left one ann t.irnes 8
')
7
'7
0
.)
4 Shift left t'.vo ann t.irnes 3 c) I IJ
4 8 G
;3
7 3 8 G Add to geL product
I'vlultiplication in binary
0 0 1 1 0 1'vT 111t.iplicann
x 1 0 1 rv[ultiplier
1 0 0 1 1 1 0 Ul1leS 1
0 0 0 0 0 0 0 Shift left one ann t.irneR 0
J 0 0 1 J 1 0 Shift left two ann t.irneR 1
1 1 0 0 0 0 1 1 0 Add to geL Lhe product
As you CcU1 see Inuit iplicttLion in binttry is easy.
17
Mathematics for Com puter Scientists Chapter 1. Numbers
Octal
Base 8 or octal docs not bring an,Y nevv problerns. \Ve usc the syrnbolb 0, 2" , . }
and the position denotes the po\ver of 8. So is 1 X 8 + 2 = lOin while
3021 ib
3 X 8
3
+ 0 X 8
2
+ 2 x 8 + 1 x 8 = 1536 + 16 + 1 = 1553
in decirnal. Obviously we do not need the syrnbol for 9 as 910 = 8 + 1 = 118 in
octal. To convert a decinlal nurnber to octal we can use our mod operator as \ve
did in the binary case.
As an exalnple consider 155;3 in decirnal or 1553
10
, \Ve would like to \vrite it
as an octal nurnber. \Ve take the nunlber and successively divide mod 8, See belo\v
Step nurn ber n Xn. l xnj2 J Xn rnod 2
0
15,);3
HJ4 J
1 19/1 2/1 2
2 2-1
"
0 ,)
" "
0
"
,) ,) ,)
\Vriting the labt cohunn in ,(,C'1)(},(,8(; vve have ;3021 \vhich is the octal nurnber vve
req uire since
3 X 8
3
+ 0 X 8
2
+ 2 x 8 + 1 x 8 = 1553
There is a sirnple link between odal and binary if \Ve notice that
7 = 22 + 21 + 2 = 1112
6 = 22 + 21 = 11 O
2
5 = 22 + 2
l
) = 1 01
2
4 = 22 = 100
2
Yon migllt like to check that J 55:3 is
3=21 +2=11
2
2 = 21 = 10
2
1=+21=12
0=0
2
11000010001
in hillary.
Sepm'(},ting thit:l illto blocks of 3 giveb
11 000 010 001
If v.'e use our table to vvrite the digit corresponding to each binary block of ;3 we
have
302 1
18
Mathematics for Com puter Scientists Chapter 1. Numbers
which is our octal representation!
As in the binary case we can also have octal for exarIlpll' 0.:':WI2. This
is et way of representing
To convert to <lecirnal \ve proceed a.s for the <lecirnal case only here "ye use 8 rather
that 2 to gi ve
Step rlluIlber n X
rt
8x
rt l8xrtJ
0 0.::W12 2.40(:)6 2
1 0.4090 ;3.270S
')
.J
2 0.276f3 2.2144 2
"
0.21;1:1 1. 7L")2 1 ,)
/1
0.7152 5.72165 5
5 0.7216 5.7728 5
6 0.7728 6.1824 6
( 0.1824 1.4592 1
S 0.4592 ;3.67:36
')
d
9 0.0730 5.;38f3S 5
10 0.:'3888 110/1
'J
,)
11. 0.110'1002 0.88B201(i 0
12 0.88B201(i 7.0656128 7
13 0.06561279 0.52490234 0
14 0.5249023 4.1992188 4
Ii) o. J 99218f3 1.59:37500 1
10 0.,)9375 4.75000 4
17 0.7,) 0.00 6
18 0 0
giving Trading down 0.3012
w
= 0.641407035316551232
8
hexadecimal
13ase 16 is IIlOre cornplicated because vve need 1nore syrnbols. \\7e have the integers
o Lo 9 and v.'e also use A == 10 , 13 == 11 , C == 12 : D ==,1:3 E == 14 , F== 15.
So 123'6 is 1 in deci1nal and A2E'6 is 10 x 16
2
+2 x 16' + 14 The good thing
about hex is that each of the s}'lnbols corresponds to a, 4 digit binetry seq uenee (
if we allow leading heros). This rneans we can easil}' translate 1'r0111 hex to binary
aRbe]mv010111101011010100102
2
=0101 1110 1011 0101 00102
19
Mathematics for Com puter Scientists Chapter 1. Numbers
exercises
I. Factorize
(a) 309G
(h) 12:34
(c)
24 -1
2. It was thought that 2
v
- 1 was prirne when pp is a prirne. Shown that this
is not true when p = 11
3. Fino t.he gco for :3090 ana 12;34.
4. \Vrit.e t.he follovving dec:irnal numbers in hin;:try
(a) 256
10
(b)
24 -1
(c) 549
(a) 12.34
20
Mathematics for Com puter Scientists Chapter 1. Numbers
5. Convert. the following binRT,'/ nnmhers int.o decimalnnmbers and explain yonr
answerb.
(a) 101.001
2
(h) J 01 J 112
(c:) 0.10101
2
(d) 11.0001
2
(e) JOOJ
2
(f) 0.112
6. Convert the following decinwJ nunlbers into binary nUlnbers and explain your
answers.
(a) ()010
(b) 7010
(c) 0410
(0) :39.56
10
(c) 20.625
10
(f) 13.1 J 10 (8 significant digitR )
7. Add tl18 follo\ving nnmhers in binary and explain yonr ;;ms\vers.
(a) 1112 + 1112
(b) J 1102 + 112
(c) 11101
2
+ 11001
2
8. J\1ulLiply the following; nunlbers in binar}' and expla,in }'our ansv.'ers.
21
Mathematics for Com puter Scientists Chapter 2. The statement calculus and logik
Chapter 2
The statelllent calculus and logic
"Conlrari'Luise" '; conliu'ued Twee(lle(lee" a'i/ it 'Was 80: it 'rniyhl be;'
and 1f it were .s 0, it W() 11 ld be 1J 11 t as it i.c;n:t, it ain:'t, Thors
Le\viR Carroll
You will have encountered several languages - your native language or the one in
Wllidl we 8,re c;nrrently r.omnl11l1iulting( English) 8,no other natllral l8,ngn8,ges Rnch
as SpaniRll, Germ8,n etc;. Yon m8y 8lRO h8ve enc;onntered programming langnages
like Pytholl or C. \rou have certainly rnet sorne rnathernaticb if you have got this
far.
A hl,nguage ill which -vve describe another hl,nguage is called d, metalang'Uagc. For
a1nlOsL all of n1ctLhernatics, the IneLalanguage is English with sorne extra noLation.
In COnl}Juting vve need to define, and use, languages and fonnal nohtLion so it
is essential that we 118ve a clear ano prer.ise rnet8J8,ngllage. \Ve hegin hy looking
at some English expreRRions \vhir.h \ve c;onlo llse in r.ornpllting. I\ToRt sentenr.eR in
EngliRll r.8,n he thollght of 8,R a series of st8,tements r.ornhineo llsing r.onnedives
:::;uch d,:::; d,nd or "if. , , then . . .;1.
For exmnple the sentence if it is relining and I go outside then I get ,vet is
construded fron1 the three sirnple shtLernents:
1. "1 t is raining."
2. "I go out:::;ide."
B. "I get wet."
\Vhether the original sentence is true or not depends upon the truth or not of these
three :::;irnple staternellts.
If a stateillent is true we shall say LhaL its logical vctlue is true, and i[ it is false,
iLs logical value is false. As a shorLhand v.'e shall use the letter T [or Lrue and F
[or false.
22
Mathematics for Com puter Scientists Chapter 2. The statement calculus and logik
\Ve will huild co1'np011no. shtte1'nents from simple statements like "it iR raining"
, "it is hy connecting them vvit h and and o't In orner to make things shorter
ana we 110pe 1'nore re;:to;;thle: we introduce Rymholic notation.
1. Negation will be denoted by"'",
2. "and" by /\,
;3. "or" by V.
\Ve now look ctL Lhese connecti yes in a little Inore det ail.
Negation "-
T11e neg;:ttion of a Rtatement is f;:'tlse ,\Then the Rtatement is true ana iR trlle if the
btaternent is falbe, So a staternent and its negation ahvays have different truth
values. For exalnple "It ib and "It ib not hot," In logic you need to be quite
clear about rnea.nings so the negcttion of
cOlnputer scientists ctre
is

"No computer scientists are men."
The firt:lt and third btaternent are both falbe!
23
Mathematics for Com puter Scientists Chapter 2. The statement calculus and logik
In sYlnbolic tenns if p is a sLa.LelnenL, sa.y ~ ~ it is ra.ining;; : then -... p is its
nega.Lion. That is '" p is the sLa.Lernent "iL is not ntining;;. \Ve sununa.ri:L;e the
Lruth or otherwise of Lhe staLernents in ct ['ruth [able, see table 2.1.
lEU
) '""'p
T l'
F T
Table 2.1: Truth htble for negation ("')
In t.he trllt.h table 2.1 the first. ro,v readR in plain EngliRh - "If P iR t.rne then
,"" p is f;:dse" and row t.wo :;If p iR fRIse t.hen ~ , p iR true'.
Conjunction 1\
Similarly, if p ;;mo q ;;tre st;:tternents: then p /\ q IR read RS :;p ;;mo q" . This
(confnRingly) iR c;Rlleo t.he conjnndion of p ;;md q.
So if vve hRve
p= " it is green" wllile q=" it is an apple" then
p /\ q = :;rt, is green ;;mo it is an apple"
Clearly this btatelIleIlt ib true only if both p and q are true. If either of thcrn is
false theu the COIIlpound staternent is false. It \vill be helpful if \ve have (}, precise
defiuition of /\ and \ve can get one ubing a truth table.
p q p/\q
T T T
T F F
F T F
F F F
Table 2.2: The truth table for 1\
.Frorn table 2 vve see that if p and q are boLh true Lhen C= p /\ q is also true.
If p is true ctnd q is false then C=p 1\ q is false.
Disjunction V
Suppose we no\v look at :;or;l, In logic we use p V q as a bYIIlbolic way of vvriting p
or q. The truth Lable in this case is gi ven in Lable 2.:3 This version or o r ~ ~ , v.'hich
24
Mathematics for Com puter Scientists Chapter 2. The statement calculus and logik
p q pVq
T T T
T F' T
F T T
F F' F'
T;;thle 2.3: The trutll tahle for V
is the (;01'nmon one nseo in logic iR someti1'nes known as tlle induRi"ve or hecauRe
we can 11Hve p true or falRe or q trne or fRIse or true.
'{ou could of course define the exclmlive or , say"- as having the truth table in
2./1
p q pq
T T F
T F T
l' T T
F F F
Tctble 2.4: The truth table [or
The Conditional =} and the Biconditional {==}
A rather IHore interesting connective is ctS in p q. This can lJe
written IHany ways, [or exa.lnple
p implies q
If p then q
q if P
p is a suffident (-ondition for q
I aIIl sure you can think o[ other variants. \Ve shall use the s),rnbolic fornl p ::::::} q
;;mo tlle truthtahle is in given in table 2.,).
\Ve someti1'nes c;811 p the hYJJotlu:sis and q the eonsequen(:e or c;ondusion. IVIany
people find it confuRing ,vhen the read that " p only if q" iR the same as "If p
then Notice that" p only if q" sayt:l that p cannot be true "vhen q is llot
in other \vordb the btaternent ib falbe if p it:l true but q is false. \Vhen p ib falbe q
IIlay be true or false.
2S
Mathematics for Com puter Scientists Chapter 2. The statement calculus and logik
p q p=}q
T T T
T F' F
l' T T
l' F T
Table 2.:): The truth table for =}
You need t.o be RWRre tllR.t ~ ; q onl,'l if p" iR lVOT :='t vvay of expreRRing " p =} q.
\Ve Ree t hiR l)y dlecking tlle trllt.h vaIneR. The t.rntll value in line ~ of t.ahle 2.5 is
tlle c;ritic;=d oifference. Yon migllt like to check that ~ ; q unleRR "-, p ~ ; is eqlliv;=dent
to p ::::} q.
p
~ p q q uniebb "''''- p
T F T F
T F F T
F T T T
F T F' T
T;=thle 2.0: The trllt.h t<=thle for =}
".\otic;e tl18t onr oefinition of implic;Rtion iR rather broaoer t.han the nRuR.lnRage.
26
Mathematics for Com puter Scientists Chapter 2. The statement calculus and logik
Typic:=,dly YOll rnight RRy
::if the sun shines today we \vill have u.
The hypothesis and the conclusion axe linked in SOHle sensible vvay and the state-
ment iR true unleRR it is sllnny :=,mo. we 00 not 11ave a barbec;lle. By contrast the
st:='lternent
the sun shines 19 is
is true from tl1e o.efinition of :='1,11 irnplic:='ltion beulllRe tl1e c;ondllsion is :='IJw8YS trlle
no m:='ltter if it is Runny or not. If ,ve c;onsider
the sun shines 8 is
the Rtatement iR trlle vvl1en the R1111 doeR not Rhine even though 8 is never prirne.
Of course we arc unlikely to Inake staternents like these in real life.
8U1)pORe p :='I,nd q :='Ire two st:='ltements. Then the st:='ltement "p if ana only if
iR cRlled the hi(:onditional :='I,no. oenoteo. hy p {===} q . It is true only ,vhen p ano.
q have the saIne logical values, i.e., \vhen either both aTe true or both arc fal:::;e.
-You may alRo meet the eCJuivalent
p ilI q
P is lwceRR8ry ana Rufficient for q
The truth table is shown in figure 2.7. l'or exa.l11ple v.'e Inight sa}'
p q p {==} q
T T T
T F F
F T F
F' F T
Tahle 2.7: The truth table for {==}
YOll can go to tl1e matd1 if ana only if YOll huy :='I, tic;ket.
This sort of construction is not 'very COIrnnon in ordinary language and it is often
hanI to decide \vhether a biconditional is ilIlplied in ordinary speech. In 111ath-
ernatics or cOl11puting; you need to be clear if you are dealing; \vith irnplication
p =} q or the biconditional p {::::::::?- q
27
Mathematics for Com puter Scientists Chapter 2. The statement calculus and logik
Converse
l
contrapositive and inverse
Propositional logic has lots or terrninology. So If p =} q then
q =} p is the converbe.
.... q =}'" p is the contrapositive.
.... p =} .... q is the inverse.
Truth tables
It ib probabl.Y obvious that we airn to Ube logic to help us in checking argurnentb.
\Ve hope to be able to tranblate frorn English to byrnbols. Thus if p is learns
to and q is " John \vill find a job" then p =} q represent s . If .John learns
to cook" and then John will find a In problerns like these the truth table,
while cUlIlbersOlne can be very helpful in giving a Inechctnicctl rneans of chec'king;
t.lle t.rllt h v:=,dlles of :='trgnrnel1ts.
To C;Ol1 strlld hthles for componnd Rt.atement.R RllC;h as p V ,"" q =} (p /\ q) "ve
neeo to think :='thont. the oroer we work of he prec;eoence of logic;:d Ryrnhols. The
table 2.8 gives the precedellce , one is 2 second, etc The 'vital point about
Precedence 1 2 3 4 0
Operator not 1\ V {==}
Table 2.8: Operator precedence
logical statelnents and about truth tables is :
Two sywholir: -'itatewr:nt8 orr: eq?li?hIlent 1f thr:Jj hrwe thr: S01tIr: truth table.
If bvo Rt.atement.R P 1 ;:tnd p2 :='Ire eqlliv:='IJent., \ve ,vill ,vrit.e p 1 {==} p2.
Thus, for eXCllnple, the stat ernents (p V q) 1\ "" p and r.,. p /\ q are equivalent.
\Ve call deduce thib fr'oIn the truth tables, bee table 2.9
p q pVq p {pVq)/\r.,.p p ---p q ""p/\q
T T T F F T F T F
T F T F F T F F F
1-' T T T T F T T T
1-' F F T F F T F F
Table Tlle trllth t:='l.hles for (p V q)/\ "- P :='I.nd ('"" p /\ q)
The reader can use t I'll th t able to veri(y' the rollo\v ing eq ui valences.
28
Mathematics for Com puter Scientists Chapter 2. The statement calculus and logik
1. "- (p V q) iff ". p 1\ ~ q
2. "- (p /\ q) <=>". pV "- q
One can avoid writing truth tablet:; in table 2.9 and verify the first equivalence
as follovvt:;:
p V q is false only \Vhell both p and q are false. Therefore r.,. (p V q) it:; true onl:y
when both P etnel q are false. Silnilarly: '" p/\ .... q is true only \\'hen boch .... p and
" q are Lrue: which is when p and q are false. This proves the equivalence.
Exercise
Constrnct trllt.h t<=thleR for
1. ---(p/\q)
2. --- (p V q)/\ "'- (q V p)
~ i . (p =} q) /\ (q ::::} 1') ::::} (p =} T)
4. (p V q ::::} 1') 1\ (1' ::::} s)
5. (p V q ::::} 1') 1\ (1'::::} s) =} (p::::} 1')
29
Mathematics for Com puter Scientists Chapter 2. The statement calculus and logik
Arguluents
\Ve now look briefly a.t logical argUlnenLs and begin vvith sorne definitions. Defini-
Lion:
1\ stateHlent that ib alwayt:l true is called a tautology .
1\ stateHlent that ib alwaYb false it:l called a contradiction.
So :='t, Rtat.ement is
1. A tautology if its truth table has no vct1ue F.
2. A contradiction if itb truth table has no value T.
".'\otic;e yon may find some \"Tit.ers \Vll0 S8Y thRt a fonnllla ( in t.he st8tement
calculus we have jUbt debcribed ) ib valid rather than Ube the terrn tautology. The
t:lyrnbol F 1\ ib nonnall,? ubed ab a shorthand for is a tautology" or " 1\ ib \.Tali(r.
Exalnples
1. The st.atement. pV "- p IR 8. t8.utology: while the st.atement p/\ "- p IS a
cOlltradictioll.
2. The staternellt (( p V q) 1\ p) {==} p is a tautology.
T \vo staternents p 1 and p2 are cqni'ualent \vhen p 1 {==} p2 is a tautology,
and t:lO p 1 == p2 \vhen p 1 {===:? p2 ib a tautology.
Definition 1: Given t.wo st8tements p 1 8.nd p2 we R8y t118t P 1 1:mpl'l:e8 p2 if
P 1 =} p2 is a t.allt.ology.
In everyday life we often enc;onnter situ8tions ,vhere ,ve rnake conclusions h8.Red
Oll evidence. In a courtroorn the fate of the accused Inay depend the defence prov-
ing that the opposing bide:s argulnellts are not valid. 1\ typical tabk in theoretical
sciellC'es is 1,0 logically C'Olne to conclusions given prelnises. ThctL is to provide
princi 1)1es [or reasoning.
A scient ist nlight say
"if all the prernit:les aTe true thell we have the follo\ving conclusion. l:
TllllS t.hey wOllIn assert that the conditional
all the prelnises are true then \ve have Lhe follov,ring conclusion"
ib a or that the prernibes irnply hib/her conclusion. If his/her reasoning
is corred we bay that his argurnent is valid.
Definition 2: A conditional of the fOfln
30
Mathematics for Com puter Scientists Chapter 2. The statement calculus and logik
( a conjunction of shtLelnents) iinplies c
where c is a staternent, is called an aT.CJ'ument. The btaternentb in the conjunction on
the left bide of the conditional are called pn:miscs, while c is called the conclusion.
An argUlnenL is valid if it is ct La.uLology, that is, if the preinises iinply the
conclusion, otherwise it is invalid. So v,,'e rnight have a sequence of prernises
A,! A
2
, A
3
) ... ,Am for vvhich B is ct valid consequence, syrnbollcally
You should noLe LhaL
1. A conjunction of bC"veral staternents ib true only when all the btatcrnentb are
true.
2. A c;onnition;=d is false only \vhen tlle antec;enent is true ann the conseCjuent
is f;=dse.
;3. an ctrgurnent is invalid only when there is a. sit nation where all
the prernises are trlle: bllt the c;onc:lusion is false. If sllch a sitnation cannot
oc;c;ur: the argllment is valin.
Exercise s:
1. Is the following argUlnenL vctlid?
All birdb are rnmrnnalb and the platypus is a bird. Therefore, the
platypub is a rnmrnnal.
Note the premises may be ,vrong but \ve are interested in the argument.
2. Show that the hypotheses below iinply LhctL "It
(},nd
If it does not rain or if it ib not foggy then the regatta \vill be held
and the lifeboaL dernonsLration will go on. If the regatta is held
thell the Lrophy will be awarded.
the trophy \vas not 8\v8rded.
;3. Shov.' that the following argurnent is valid.
Blo(hvin \vorkb hard. If Blochvin vvorks hard then bhe ib a dull girl.
If Blo(hvin is a dull girl she \vill not get the job therefore Blodvvin
will noL get the job.
31
Mathematics for Com puter Scientists Chapter 2. The statement calculus and logik
So far we have llsed Lruth tables only to detennine the vctlidity or ctrgLllnents tha.t
ctre given in sYlnbolic fornl. lIoweveL v'.le can do the sarne v'.lith other a.rglllnenLs b}'
first. rewriting tllAll1 in symholic fonn. This iR illllRtrat.eo in t.he following ex;;trnple.
Eit her I shall go home or stay 8no 118VA 8, orin k. I shall not. go home.
Therefore I bta.y and have a. drink.
Suppose p= I shall go hOIne and q = I shall btay and have a drink. The arguIIlent
is '" p q.
p "'p
q "p=}q
T F T T
T F F F
l' T T T
l' T F F
Table 2.10: The truth table for ::::}
F:rOlIl the truth table table 2.10 \ve have a F and so the arguInent ib not valid
is "ve do not have a tautolog,y 11 "'- p ::::} q.
\Ve SllnlInari:L;e the process or detennining the validity or arglllnenLs as rollo\vs.
32
Mathematics for Com puter Scientists Chapter 2. The statement calculus and logik
2.0.4 Analyzing Arguments Using Truth Tables
Step 1: TranshtLe the prelnises and the conclusion into syrnbolic [ornl.
Step 2: \Vrite the truth table for the prernises and the conclusion.
Step 3: Determine if there is ;:'I, row in vvllir,h ;:'1,11 the premiRes are true ;:'I,nd
tlle c;ondw:;ion is f;:'lJse. If yes, tlle ;:'I,rgnment iR invalio: otherwise it is valia.
However truth table can becorne unwield)' i[ vve have several prernises. Consider
the following
p, r I (p /\ q) r F"- q
Given we have p,q and r we need 8 rows (2
3
) in our table 2.11 as we need all
cornbinations o[ p, q and r. If we exarnine line :3 in table 2.11 \lIre CcUl see that
when p, 1', (p /\ q) -----1'"' l' are all true ( we can ignore q ) then the result'" q is true
and we 11Hve ;:'I, tantology.
p q r p /\ q =} .... r
"'q
T T T F l'
T T F T F
T F T T T
T F F' T T
F T T T T
F T F' T F
F l' T T T
F l' F T T
T;:'I,hle 2.1 J: Trnth tahle with p, q and r
No'\-v suppo:::;e vve have PI q I r I sand t. Our table vvill have 2
5
= 32 rO\\'s,
T;:l,ke as i:Ul exarnplc :
If I go to lny fir:::;t class tornorrovv : then I rnust get up early: and if I go to the
dcuKe tonight, I \x,rill stay up late. If I stay up htte and get up early, then I will
be forced to exist on only five hours sleep. I cannot exist on five hours of sleel).
Tllerefore I must either misR rny fiRt class tomorrow or not go to the nance.
Let P be :: I go to lny finlt class tornorrov;/l
Let q he :: I rnllRt get IIp
Let r be " I go to the dance
Let s be " I stay up late .
33
Mathematics for Com puter Scientists Chapter 2. The statement calculus and logik
Let t be "I can exist on five hours slcq/ .
The the preIIlibeb are
(p =} q) J\ (r =} t L s /\ q =} t, "- t
and the conclubion ib "- pV r.,. T. \Ve will prove that "'- pV "- r is a valid conbequence
o[ the prelnises.
Of course we could write out a. truth hU'.:vever \ve can try to be cunning.
1. Take the consequence" pV .... rand aSSUlne tha.1o it is FALSE.
2. Then both p and r mnRt he TRUE.
The first prernise (p =} q) J\ (r =} t) irnplieb that q and t are true.
4. So t is true and the last prelnise is " t is assurned THUE so \ve have a
contradiction.
S. ThllR onf premiRe is valid.
1 think you Inight agree that this is a good deal shorter than using truth tablcb!.
Exanlple s
Sho,,,, that
1. F (p =} q) =} ((q =} (p rn
2. F p =} q =}---, p) =} q)
\Ve add bOlne tables of tautologies \vhieh enable us to dirninate conditionalb and
1 )icondi t ionals.
1. Fp=}q {==}""pVq
2. F p =} q {==} "'- (pV "- q)
;3. FpVq {==}""P---7q
34
Mathematics for Com puter Scientists Chapter 2. The statement calculus and logik
5. F p V q {==} '" P ---1 q
6, F V V q {==} "'- V ---1 q
7. F p 1\ q (p q)
9, F (V {==} q) {==} (V =} q) /\ (q =} V)
Nonnal fonus
A Rtatement iR in disjunr:ti?h' normal form (D"'\F) if it iR 8. oisjnndion i.e. a
:::;equellce of V':::; consisting of one or Inore disjuncts. Ed.ch disjuncts is a conjunction,
of one or Inore literals (i.e., staternent letters and negationb of stateInent letter:::;.
For eXcullple
1. P
2. (p 1\ q) V (p/\ " r)
(V 1\ q 1\ "'- T) V (V /\ q)
4. P V (q /\ r)
Ho\yever --- (V V q) i:::; not a disjunctive nonnal forrn( --- is the outennost operator) nor
is pV(q/\(rVs) as a V is insiue ct /\. Converting; ct fonnula to D:'\F involves using;
logical equi such as the double negati ve elirnination, De J\lorgan's la'vvs,
ano tlle distribntive L:nv. All logic8J forrnnlaR can he convert eo into oisjnnrtive
norrnal forrn hnt r;onverRion to D"'\F C8.n leao to an exploRion in the Rize of of the
expreRRion.
A [orInula is in coujnnclive nonnal Jonn (C:'\F ) if it is ct conjunction of cIa.uses,
where a cIa.use is a disj unction of literals. Essentiall}' we have the scune forn1 as a
DNF bu 1, v.'e use 1\ ra.1oher than V. As a nonnal [orIn, it is useful ( ctS is the D:'\F)
in tlleorem proving.
\Ve leave 'with borrle ideas \vhich are both irnportant and COIIlrnon in rrldthe-
IIlat ie:s.
3S
Mathematics for Com puter Scientists Chapter 2. The statement calculus and logik
2.0.5 Contradiction and consistency
\Ve say a c:ontnvlidion is a forrnnlR thM, ahvayR btkeR the 'valne F, for ex;:tmple
p/\ r.,. p. Then a sct of btaterIlcntb p,) P 2, ... , Pn is inconsistent if a contradiction
can bc drawn a.s a valid conscquence of this bet.
Pl, P2, ... , Pn F q/\ " q for SOlne fOlTllula b if ct contradiction ca.11 be derived
as ct valid consequence of p" P2) ... ) Pn F q and -... q
J'vlathenlatics is full of proofs by contradiction or Reduct io ad absurdurn (Latin
for" redudion to the abRuro"). For exmnl)le
There are infinitely many prime numbers.
i\ssurnc to the contrary that there aTC only finitely rnany prirIle n u r n e r s ~ and all
of thcrIl are libted ab follo\vs: n" n2 ... ,Pm.' Considcr thc rllnIlbcr
q = nl X n2 X ... X Pm + 1
Thcn the rnunber q is cither prirnc or corIlposite. If \ve divided any of the listed
prillles ni. into q there would result a rernainder of 1 for each i = 1) 2, ... , rn Thus,
q ("('l.11110t be cornposite. \:\'e conclude that q is a prirne nunlber, not arIlong the
primeR listeo above, c,ontradiding 011r ass11rnption that ;:dl primeR are in the liRt.
n 1, n2 ... , n
m
. Thus there :='ITe ano infinite nnrnl)er of primeR.
there is no smallest rational number greater than 0
RerIlerIlber that a ration can be vvrittcn as the ratio of t\VO integcrb pi q say.
i\SSUlIlC no = pi q ib the sHwllcst rational bigger that zero. Conbider noll. It
is dear that no/2 < no and no is rational. Thus v,,re have a contradiction cU1d ca.11
ass UlIle that there is no srnallest rational nunlber greater than O.
36
Mathematics for Com puter Scientists Chapter 3. Mathematical Induction
Chapter 3
Mathematical Induction
1 have hardly eVtT know-n a 'lnalheuUl,liC'ian who was capable oj rea-
son:ing.
PIM,o (427 Be - ;347 B C ~ The Repuhlic;
You will rer,;;dl t.hat. t.he integefs 8,re t.he cou11ting mnnherR, 1,2,3,4,.... Afathe-
uwticaZ indu,ction it:; a technique for proving a a. theorern, or a. fonnula - that is
asserted about ever,Y integer. Suppose for exarnplc \ve believe
1 + 2 + 3 + ... + n = n(n + 1 )/2
that. iR t11e Sll111 of conRer,llt.ive nurnherR from 1 t.o nis give11 by t.he fonnllla on the
right.. \Ve want. to prove t118t t.his "vill be true for all n. As 8. st.art we can t.est the
fo nn uL:l. for any gi ven nurn b er say n = ~ 3 :
1 + 2 + 3 = 3 x 4/2 = 6
11 is also t rue for n = 4
1 + 2 + 3 + 4 = 4 x 5/2 = 10
But ho\v arc \ve to prove this rule for every value of n'? The rnethod of proof \ve
describe is called the prillciple of rnathernatical induction. The idea is sirnple If
an the following are true
1. \\:'11e11 a st8ternent is t.rue for some 118tUf8J mnnher n = k say.
2. \V11e11 it is 8JSO true for itR Rur,c;eRRor, n = k + 1.
B. The staternellt it:) true for n = 1.
37
Mathematics for Com puter Scientists Chapter 11. Looking at Data
then the sta.tement is tT11f fOT f'/ifTy integfT n.
This is \vhen the statelnent ib true for n = 1, then according to it
will also be true for 2. But that irnplies it will be true for :3; which irnplies it will
be true for 4. And so on. IIence it vvill be true for eve(y' na,tural nurnber and thus
is true for all n.
To prove :='t, reRult by indudion, tllen, \ve must pro-ve parts 1: 2 :='tno. ;) ahove.
The hypothesis of step 1
"The btaternent is true for n = k"
is called Lhe induction ass ulnpLion , or the indue-Lion hypoLhesis. It is vvhaL vve
assume wllAn WA prove R them'ern by indlldion.
Exanlple
Prove that the Slun of the first n natural rllnnberb is given by this fonnula:
5
n
= 1 + 2 + 3 + ... + n = n( n + 1) /2
\Ve ,vill call this statelIlCnt 5
n
, because it depends on n. No \ve do steps 1 and
2 above. First, we will aSSlllne th1.tL the sLa.1oelnenL is true for n = k Lha.1o is: \Ve \vill
aSSLlllle Lh1.tL 5
k
is Lrue so
5
k
= 1 + 2 + 3 + ... + k = k(k + 1 )/2
.:\oLe Lhis is Lhe induction asslllnption.
Assurning this: ,ve must prove th;=tt S [k-l) iR also true. Th;=d. iR, \ve need to
Rll0W:
S(k+l) = 1 + 2 + 3 + ... + (k + 1 ) = (k + 1)(k + 2)/2
To 0.0 that: "ve \vill Rimply ao.a the next term (k + 1) to hoth sides of the
ind uet ion assurnpt ion
5
tk
111 = 1 + 2 + 3 + ... + (k + 1) = k(k + 1)/2 + (k + 1) = (k + 1)(k + 2)/2
This is line 2, which is the firbt thing \ve ,vanted to sho\v. Next, we Illust sho\v
t.h1.tt. the statelllent is true for n = 1. \Ve have 5(1) = 1 = 1 x 2/2 The fonl1ula
t.herefore is true for n = 1. \Ve have nov.' fulfilled boLh condiLions of the principle
of nl1.tt.helnatical indue-Lion. 5
n
is therefore true for every n1.ttuntl nllll1ber.
38
Mathematics for Com puter Scientists Chapter 3. Mathematical Induction
Exanlple
\Ve prove that 811.-3
T1
is divisible b.y 5 [or all n E N. The proof is by rna.thelnatical
indudion.
1. The resnlt holdR for n = 1 becAuRe g - 3 = 5 and so is divisible by 5.
2. Now assnrne the reRult holrls for n = k, thRt is gk - 31< mod 5 = O. Then
gk+l _ 3
k
-
1
= 8 X gk - 3 X 3
k
,
~ i Now the clever step
But gk - 3k ib divisible by 5 (by the induction hypothebis) and 5 x gk is
obviously a rnultiple of 5.
There[ore it follows that (8
k
11 - 3
k
11) is eli visible by 5. lIenee, the result holds [or
n=k+1.
So vve hAve Rllo,vn that the result holds for all n - by induction.
39
Mathematics for Com puter Scientists Chapter 3. Mathematical Induction
Another Exalnple
\Ve prove t.his r111e of exponentR:
(ab
iTL
= aTLb
rt
) f' I 1 ) . or every natura nurn )er n.
Call thiR Rtat.ement S(n) :='mo Rssnll1e thRt it. iR true when n = k: that is, "ve aSS11me
S( k) = (ab) k = akb
k
iR true.
\Ve mllRt now prove that S(k + 1) is t.rne, that is
Simply hy multiplying hot.h sideR of line (:3) hy ab gives:
binee the order of factors docs not rnatter,
(ab)kab = ak+'b
k
+'.
\Vhidl is ,vhat. ,ve wanteo to Rho,v. So: we have shm.vn t.hat. if t.he t.heorem is
true for any bpecific natural nurnber k, then it is also true for its successor: k + 1.
::\ ext: "ve Inust sho"v that the theorern ib true for n = 1 \vhich is trivial binee
(ab)l(ab) = ab = alb'.
This Lheorern is therefore true for every l1ctLuntl I1ulnber n.
Exercises
In eac;h of t.he follo\ving 0 < n iR an integer
1. Prove that. n
2
+ n is even.
2. Prove that L ~ L 1 n
2
= n(n + 1 )(2n + 1 )16.
~ i Prove that 1 +4+7+ ... +(3n-2) =n(3n-l)12.
4. Prove tha.1o n! :2: 2lL
40
Mathematics for Com puter Scientists Olapter 4. Sets
Chapter 4
Sets
Philosophers have 'not found 'it easy lo sort o'ut sets . ..
D. l'vI. A rmRtrong,
It is llReflll to 118ve a wRy of deRcrihing R colledion of "things" ana the m8the-
rnatic8J n8,1'ne for Sllell 8, colledion is 8, .c;et. So the colledion of c;olonrs {Red:Blne,
Green } is a set we rnight call A (md "vrite ab A= {Red: Blue: Green } . Othef
exaIIlples are
1. {1,3,7,14J
2. {l, 2, 3,5,7,11 ... } the set of all priIIle nUIIlberb.
;3. { lVla.Lthevv, 1\11.),rk, Luke, John}
4. {k : k is 8,11 integer 8.nrl k is rlivisible hy 4} here the contents are rlefinerl hy
8, rule.
5. {All bongs available on iTuneb} again the contents are defined by a fUle.
\Ve 00 not c;are abollt the oroer of the elementR of a Ret so {J, 2, 3} is flip smnf'
Of, {:3,2, I}.
Of courbe \ve IIlay want to do thingb with sets and there is a whole Inathern(},t-
ical b,ngu(},ge attached as you Inight expect. For exarnple you \vill often see the
sta.Lernent 1.), belongf5 to the set A written 1.),S a E A. The S),lllbol is. of course,
the ('onverse i.e. does nol belong lo.
So
rvlark E { rvlatthevv, rvlark, Luke, .John}
A berga,il { J\:1aLLhmv: J\:1ark Luke, John} .
41
Mathematics for Com puter Scientists
Tllere are Rome RetR that 118ve Rpeci8J Rymhols hecallRe they 8,1'e llReo. a lot.
Exanlplcs are
1. The Ret with nothing in it: c8,lleo. tlle (''ttl pty sff is \vritten 8R 0.
2. N = fO, 1,2,3) ... } the set o[ integers.
Z = { ... ) -3, - 2) - 1 , 0) 1 ) 2, 3) ... }
4. Q= the Ret of fradions.
5. JR = the set o[ real nurnbers.
6. The bCt that contains cver,ything ib called the univc-rsal sd \Vrittcll U or
D.
Fin8,lly we \vill \vrite "- A "vhen ,ve mean the set of thingR ,vhic;h 8Te not in A.
Subsets
Olapter 4. Sets
It is probably obvious tha.1o SOlne set are 1,h1.u1 others, [or ex1.unple {A,13,C,D,E}
and {13:C,D}. \Ve [onnali:t;e this idea, by dellning .sv,bse{.s.
If the bCt B contains all the derncnts in the set A togcther \vith SOIIle others
then \ye \vrite A c B. \Vc bU,y that A ib a subset of B. So
{ John} c { Luke, John, Thornab }
\Ve C;8.l1 of conrse \vrite this the other \V8y 81'onno.: RO A c B iR the S8Tne as
B
1. Fonnall,y \vc bU,y if Q E A then Q E B or
2. If R iR a suhset hnt migllt possihly be the Rame 8,R A then we nse AeR.
:3. \Ve will use A = B to rne1. U1 A cont1.tins exactly lhe saTne things as B. Note
that if A e Band B e A then A = B.
In our logical syrnbolisnl \ve have
(A B) /\ (B A) =} A = B.
42
Mathematics for Computer Scientists Olapter 4. Sets
The power set of PtA), or 2\ ib the set of all bubbets of A. So if
A = { Nlatthe\v, rvIark, Luke} then P(A) consists of
{ Nla.Lthew, Nla.rk, Luke}
{ Nla.L thew, lVla.rk }
{ IVI at. t. hew , Lnke }
{ 1\Jark, Lnke }
{ 1\J atthew }
{ Nlark }
{ Luke}

The nUlnber of elelnents in a set A is called the ('anti-nalily of A and \vriLLen II A II.
SO if A = { lVhtLLhew, lVlark, Luke, John} then IIAII=4.
Venn Diagraills and l\IIanipulating Sets
\VA int.enn t.o m;;miplllat.e Rets and it. 11el]1R to introonc;e Venn niagrams t.o illnRtn1.t.e
what we arc up to. \Ve can think of the univerbal sd S as a rectangle and a set,
bay A as the iuterior of the circle dravvn in S bee figure /1.1 The speckled area is A
..
.. .-, ..
.. . .... .
. .. , .... ,.
. . ..... .
. .. .
... :. A .... : ..
.. . ........ ,
.. . ""'"
.. . ...... .
.... . .. .
.. ... ... ..

Figure /1.1; Veun diagrarn of sd A and univerbal bet 5
vvhile the rernainder of the area of the rectangle ib r.,. A. \Ve see innnediatcIy that
A together \'lith --- A Inake up S
43
Mathematics for Com puter Scientists
Intersection
\Ve can wriLe Lhe seL or iLenlS that belong 1.0 both the set A and Lhe set B as A rl B.
FOlTllally (x E A) /\ (x E B) =? (x EArl B).
\Ve call Lhis a, intersection of A and B or, less fonnally: A and B. In Lenns or
tllA Venn oiagram in fignrA 4.1 tllA two rjrdAR rel)reRent A ;;tnd B while the overlap
(in hlar;k) iR tllA intersedion. AR eX8ml)leR
Fignre 4.2: Venn oiagram of An B
1. {1:2:3:4} n { 3,4"J,o,7} ={ 3:4}. ~ o t i r e ;3 E { ;3,4} while J rt. { 3:4}.
2. {1:2:3:4} n { ];3,14),\J6,27} =0.
3. {AhArgail, Ann, Blorhvin: Bronvvin, ChtirJn { Abergail: Bronwin, Gareth,
Ian} = {Ahergail, BrOIl\vin, }.
it In figure /'1.2 \ve bee A n "'- A = so A and r.,. A have nothing in l'ornrnon.
5. A rl B c B and A nBc A
lTnion:
\Ve call \\'riLe Lhe seL or iLenlS that belong 1.0 Lhe seL A or Lhe seL 13 or to boLh as
A U R. Fonnally (x E A) V (x E B) =? (x E AU B).
\Ve call this tlle nnion of A ;;tnrl B or, leRR fonnally, A or R. The corresponrling
diagrmn is /'1.B Here the bpecklcd area reprebents Au B
44
Olapter 4. Sets
Mathematics for Com puter Scientists Olapter 4. Sets
Figure 4.:3: Venn diagranl of set A U B (speckled) and universe),l set S
As cxalnplcs \VC have
2. { 13lue,Green} U { ={ Hed,13lue , Green}
:3. III figure 4.2 we see AU '" A = S so A and'" A together Inake up S.
4. If A c B then A U B c B
\Ve (;;:'\J1 110\V 11Re 0111' h;=tRic; definitions to get Rome reR11lts.
4S
Mathematics for Com puter Scientists
1. A= " ( .... A) The set" A consists of all the elelnents of S ( the universal
set.) which do not belong to A. So '" ( '" A) is the set of elelnents that do not
l)elong to (tlle elell1ents of S vvllich 00 not belong to A). That iR the elements
that l)elong to A.
Or snppORe a E'" (". A) =} a rt."" A =} a E A
2. "" (A n B 1 =". AU ". B
\Ve have a E'" (A n B) =} (a rt. A) /\ (a rt. B) =} (a E"" A) /\ (a E"" B) =}
a E'" An "" B
There is a, table of useful results in table 4.1. :\oLice each rule in the left C01UII1n
has 1.1 dual rule in the right. This dual has the U s}'lnbol replace by n
AUA =A
(A U B) U C = AU (B U C)
AuB=BuA
Au (B r ~ C) = (A U B) n (A U C)
Au=A
AuS=S
AU .... A = S
.... (A U B) = ..... An ..... B
AnA =A
(A n B) II C = A II (B n C)
AIIB=BnA
A rl (B u C) = (A n B) u (A n C)
AnS=A
An=
An .... A = cp
.... (A n B) = .... AU ..... B
Table It 1: RUleb for sd operations
Cartesian Product
Suppot:le vve have t\VO setb A and B. \Ve define the Cartebian Produd P = A X B
to be the set of ordered pairs (a! b) \x"here a E A and b E B. Or
p = {( a, b) : (a E A) J\ (b E B n.
Tlle pair (a, b) iR ordered in the senRe that the firRt terrn (a) c;omeR from the Ret
A in A x B. The obviolls exmnple and hence the narne COInes fr'OIn the georndry
of the phule. \Ve uSllally \vrite (x, 1:1) to denote the coordinates of a point on the
plane. This is an ordered pair! If \ve take real valueb x and 1:1 with x E JR and
y E JR then the Cartesian prod ud is lK x JR
1. Suppose A = {a, b} and B = {l, 2} then A x B = {(a) 1 L (a, 2), (b, 1), (b, 2n.
2. \Ve can extend to B or Inore bets so A x B x C ib the set of ordered triples
(a,b,e).
46
Olapter 4. Sets
Mathematics for Com puter Scientists Olapter 4. Sets
4.0.6 Relations and functions
Given Two bets A and B and the product A x B \ve define a relation between
A and B as ct subseL R of Ax B. \Ve sc\v Lhat Q E A and b E B a,re relaLed if
(Q, b) E R, 1110re connnonly writ ten aRb. This is a, quite obscure definition unless
we look at t he I' ule gi v ing Lhe s u bseL.
Take the sirnple exarnple of A = {l, 2) 3) 4, 5, 6} ctnd B = 11,2,3) 4) 5, 6} then
A x B is the a,nay
(1)) ( 1 (1 (1 (1 ())
(2)) (2 (2 ())
(;3: 1) (;3:2) (;3:;3) (;3A) (;3:5) (:3,6)
( 4:1) ( 4:2) ( 4:;3) (4A) (4:5) (4,6)
(5:1) (5:2) (5:;3) (5A) (5:5) (5,6)
(6: J) (6)) (6:3) (6:4) (6:5) (6,6)
A relttLioll R is the subset H1, 11, (2) 2), (3,31, (4)41, (5,5), (6, 6)} or the seL ((l,j) :
i = n. Other exarnple are
2. R = Hi.j) : 1 = 2j} = H2) 11, (4,21, (6,3)}
R = {iij} =
(1:1 ) (1 )) (1 :3) (1,4 ) (1,5) (J ,0)

)
C) i-:)
,)
C) C)
,) )
(4:5) (4,6)
(5,6)
.As you can sec \ve can think of the relation R ab a rule connecting elernents of A
to elelIlCuts of B The relation aRb betvveen 2 sets A and B can be represented as
in figur e .1.-1
For eXi:lInple
1. if A={ one, Lv.'o, threeJourJive} and B={ 1.2:;3A:5} \\'e CcUl dellne R as the set
of pairR {(vvorri,mnnber of let.t.erR)} ego {(one:3): (two:3): (three,5) ... }
2. If A={ and the we rnight define R as the bet
{ (2, 1 ) : ( 4: 2 ) , ( 8,3) , ( 16: 4) : ( ;3 2,5) }
Tllere are all kinds of 118TneR for Rpecial typeR of rel8tiollR. Some of thenl are
47
Mathematics for Com puter Scientists
A
B


... 7'\ B
Figure 4.4: The relation R be1,ween 2 se1,s A and B
1. n:fir:;ri?jf': for ;:'tll x E X it follovvR that xRx. For example, than or
equal to" is a. rdicxive relation but is not.
2. syrnmciric: for all x and y in X it follovvb that if xRy then y Rx. a blood
relaLi ve oC is a, synllne1,ric- relatioll, because x is et blood relati ve of y if and
only if y is a, blood relati ve of x.
:3. anli.syrmn.elT'ic: for all x etnd y in X it fo11ov.'s 1ohet1, if xRy and y Rx 10henx = y.
tl18Jl or eC]118J to" is an antiRymmetric rel8tioll: hecallRe if xy ana
yx, then x = y.
48
Olapter 4. Sets
Mathematics for Com puter Scientists
4. o..symmetrir: for ;:'tll x ana y in X it follo,,.,R that if xRy then not y Rx. Gre8ter
than;; it:; an at:;yrIlrnl'tric because iJx > 1:1 then not 1:1 > x.
5. {nt1tS'i{ ive: [or all x) y and z in X iL [ollovvs LhctL if xRy and 1) Rz then xRz.
an ancesLor of' is a, tntnsiLive rehtLiOlL becctuse if x is an ancestor of y
and y is an ancestor o[ z, then x is an ctncesLor of z.
6. Encl'idcan: for all x) 1:1 and z in X it follo\vs that if xR1:I and xRz: then 1) Rz.
7. A rehtLion which is rel1exive, synnnetric and transitive is called an eq'llivalence
reLal:ion.
You CcUl now specuhtLe as the Lhe narne "Relational Database;; .
exercises
1. If A - B is the set of elements x that RatiRfy x E A 8,no x rt. B oravv 8, Venn
diagrarn for A - B
2. Prove that [or sets A, Band C
(8,) If A C B 8,nd Bee then Ace
(b) If A C B 8,11 d Bee then Ace
( c;) If A c B 8,11 d Bee then Ace
(ei) If A c Band B C C then A C C
3. Rec;811 that Z = to) 1) 2,3,4) ... } 8,110 we define the following Rets
(a) A = {x E Z I for SOine inLegery > 0) x = 2y}
(b) B = {x E Z I for SOnll' intl'geI1J > 0) x = 21) - 1}
(c) A = {x E Z I for sorne intl'gerx < 10}
Describe A, .... (A U BL--- C,A- .... C, ctndC - (A U B)
4. Sho,v that for all sets A, Band C
(A n B) U C = A n (B U C)
iff C C A
5. \Vhd,t is the cal'dinalty of {{l ) 2}) {3L 1}.
6. Give tlle dom8jn ana the range of each of the following rel8tions. DrH,v the
graph in e8,ch case.
49
Olapter 4. Sets
Mathematics for Com puter Scientists
(8.) Ux,Y)EJRxJR}lx
2
+4y2=1}
(b) {(x, y) E 1R x 1Ft} I x
2
= y2}
( c:) U x, y) E 1R x JR} I 0 < y, Y < x an a x + 1 y < 1 J
7. Define the relation c> on {(x, y) and (u, v) E Z} \VheIe (x, y) c> (u, v) IIleans
xv = yu. Show that c> is an equivalence relation.
50
Olapter 4. Sets
Mathematics for Com puter Scientists
Chapter 5
Counting
Therc are thrce t'.I)PC8 of people in this world: Thosc 'who can COLtn(
and thosc who can"t.
Chapter 5. Counting
Counting seern quite birnplc but this is quite deceptive, ebpecially "vhen \ve have
cOInplicated s,ystern. If,you do not believe rne have a look at the probability bection.
To rnake like et lit tIe sirnpler we lay elovvn sorne rules.
Sets
If we have two sets A and B the nllnlber of itern in the sets ( the cetrdinality) is
wriLLellllAl1 etnel IIBII. Then we can show that
IIA U BII = IIAII + IIBII-IIA II BII
Tllis iR fairly easy to see if Y011 use 8, Venn riiagr8Tn. For;3 Rets
IIA U B II = IIAII + IIBII + II ell -IIA rl B II -liB rl ell -IIA rl ell + IIA rl B ~ ell
Exalnple
Let S be the set of all outcorneb when t\VO dice (one blue; one green) are thro\vn.
Let A be the subset of outcornes ill which both dice are o d d ~ and let B be the subset
of ollLcOlnes in which both dke are even. \\7e \\-Tite e for the set of olltcornes when
the 1,\\,'0 dice have the sa.lne nurnber sho\\,'ing;.
Ho\v m8,ny elernents are there in the follov.ring RetR?
11 is useful to have the set S set out as belo\\'
51
Mathematics for Com puter Scientists Cha pter 5. Cou ntin 9
1 1 1 2 1 ;3 1 4 1 5 1 G
2 1 2 2 2 ;3 2 4 2 5 2G
')
.J 1 :3 2 :3 3 :3 4 :3 5 :3 6
-1 1 -12 43 44 45 46
5 1 5 2 5 ~ i
5 (1
5 5 5 6
() 1 ()2 () ~ i
() ,1 ()5 () 6
then we have
1. IIAII=9
2. IIBII = 9
3. Ilell = 6
4. IIA n BII=O
5. IIA U BII = 18
6. IIArlCl1 = 11(1) 1L(31 3L(S)S)11 =3
7. IIA U CII = IIAII + Ilcll-IIA ~ cil = 9 + 6 - 3 = 12
Chains of actions
If \lIre have to perfonn two actions in sequence ctnd the 11rst CcUI be done rn \vays
\vhile the second can be done in n there will be mn possibilities in tohtI.
SnppoRe vve ,viRh to pick 2 people from 9. The first c;:'m be pic;keo in 9 \V8ys
the sec;ono in 8 giving 9 x 8 = 72 possibilities in tohd .
If \'le roll a die and then toss a coin there are 6 x 2 = 12 possibilities.
52
Mathematics for Com puter Scientists Cha pter 5. Cou ntin 9
This extends to several successive actiOlls. Thus
L If we roll a die 3 tirnes then there arc 6 x 6 = 216 possibilities.
2. If we toss a coin 7 tirnes there are 2 x 2 x 2 x 2 x 2 x 2 x 2 = 27 = 128
possi bili tics.
~ i rvIy bic.yele lock has ,'1 rotors each \vith 10 digits. That gi\.'es lOx lOx lOx 10 =
10
4
cOlHbina.Lions.
4. Suppose ,you have to provide an 8 charadeI' passvvord for a. credit ca.rd con1-
pany. They say thaL you can use a to z ( case is ignored) a.nd 0 to 1 but
there m11Rt he at leRst one n111'nher 8nn 8t least one letter.
there aTe 2C1 letters and 10 Ilurnbers so you ca.n rnake 8
36
possible P,lss\vords.
Of these Lhere are 8
10
which are all nunlbers and 8
26
which are all let ters.
This gi yes 8
36
- 8
26
- 8
10
= 3.245 x 10
32
a.llowable passwords.
Permutations
SUPIJOSe I have n distinct iLerns and I want to arrange thern in a line. I C"tln do
Lhis ill
n x (n -1) x (n - 2) x (n - 3) x ... x 3 x 2 x 1
\Ve C'on1lJute Lhis product so orten iL has a special sylHbol n!. IIowever to avoid
prohlems ,ve dr/int
1! = 0 and O! = 1
So 3! = 3 x 2 x 1 = 6 \vhile 5! = 5 x 4 x 3 x 2 x 1 = 120
If we look at the charac'Lers in (lD4Y) there ctre 4! = 24 possible distilld
arrangementR.
SOlIletilIles we do not have all distinct iterns. \:Ve lHight have n itelll of \vhich r
are identical then there are n!/r! dilIerent possible ctrrangelHenLs. So \VALL'Il can
ue arrallged ill 5!/2! = 60 ways.
11 is sirnpler to jusL sLate a rule in Lhe rnore genentl case:
Suppose \ve have n objects and
there (},Ie n 1 of type 1.
there (},Ie n2 of type 2.
..... .
there (},Ie nk of type k.
53
Mathematics for Com puter Scientists Cha pter 5. Cou ntin 9
Tlle total nnmher of ite1'nR in n, so n = nl + n2 + ... nk then there are
possible arrangell1ent s.
SnpPoRe we 11Hve :) white, 4 reo 8no 4 hlRc;k hallR. They C;8n be arntnged in a
row 111
11 !
3!4!4! = 11550
possible w8ys while the letters in \VALLY can he arrangeo in
51
--- = 60 ways
2t1!1!1! '
COlnbinations
Tlle n11mher of vvaYR of picking k itemR from a gronp of Ri7.e n is \vritten ~ ) or
(for the traditionalists) nCk. The definition is
(
n) n!
k - (n- k)!k!
So the n111'n her of ,V8YR of picking 5 Rt110ents from a gro11p of 19 iR
19!
5!14!
19x 18x 17x 16
4x3x2x2
54
Mathematics for Com puter Scientists Cha pter 5. Cou ntin 9
Examples
J _ SuppoRe yon want t.o win tlle 1 ott ery_ There are 4(:) nnmhers ano yon can
pick (). This can be done in
49!
-4- = 13983816 vvavs
6
! ?! '
. J.
so your chances of a win are 1/1:398;3816.
2. How IIl,ln}' \Vll}'S can you pick 5 correct rllullbers in the lottery. There are
Wll.yS to pick the 5 correct rllullbers and /19-()=/ti \VaYb of picking the
rernaining rllunbeI. This gives 6 x 43 \vays.
::L \Vhen vve pick 3 correct nllmhers there are \V8yS of pir;king t.he \vinning
nnmbers and ,V8yS of picking the losing oneR_ This gives x =
20 x 12341 = 246820 w8yS in AlL
5.0.7 Binomial Expansions
Now we have cOlnbinctLions we ("cUI excunine ct very useful result known as the
binomial expanRion. To Rtart. ,ve UUl show that
ana
(0 + b)J = 0
3
+ 3a
2
b + 30b
2
+ b
J
In gener8J \ve can prove that for an integer n > 0
or
This UU} be dOlle by but there isib a page or so of algebra!
For exmnple
or
5S
Mathematics for Com puter Scientists Cha pter 5. Cou ntin 9
SuppoRe }'"OU vvere given (3x + ;;tno. you wanteo the term in the expansion
wllic:h did not lHfve 8n x. Fl'om the R hove the genr,r81 term iR
The x tenus cancel when 8 - i = 3i or i = 2. Then the ternl is
\Ve can do sorIlething sirIlilar for non-integral n as follo\vb:
( 1
1
TL 1 11 ( n - 1) 2 n (11 - 1)( n - 2) 11 ( n - 1 )( n - 2) ... (11 - k + 1) k
+x = +nx+ x + + ... + x + ...
- 1.2 1.2.3 1.2.3 ... k
hut tllis is only true vvhen Ixl < 1.
Thus (1 + x) 1/2 = 1 + X
1
/
2
+ (-j) X-
1
/
2
+ (-1) X-
3
/
2
+ ...
Exanlples
1. Suppose \'le look at sportb scholarbhipb i-l\varded by ArIlerican uni'versitiet:l.
A toLal of schohtrships were earned in 2001. OuL of the schol-
arships for athletics, 1500 v.'ere earned by vvornen. \\-'ornen earned 75,000
sc;holarships in tohd. How many 1'nen earned scholarships in athleticR?
2. In clinical trials of the suntan lotion, Delta Sun, 100 test bubjectt:l experi-
enced third degree burns or nausea (or both). Of a total of people
experiellced third degree burns, and 25 experienced both third degree uurns
awJ llausea. IIow 111 any subjects experienced nausect?
3. A total of Hli) 0 1\,18c o.egrees ,vere e;:trneo. in 2002. Ont of the 41 1\{Sc
o.egrees in 1'nnsic: and 1'nnsic: ,) ,vere e;;trneo. by men. 1\,1en earneo 050
1\:ISc degrees. Hovv Inany \VOnlCn earned 1\:ISc degrees in fields other than
nlut:lic (},nd nmsic therapy?
4. A survey of 200 (-redit card cusLOluers revectled thctL 98 of thelTl have a Visa
;:'I,c:collnt, 11;3 of them 11ave a I'vTaster Card, 62 of them have a Visa acconnt
;:'I,no. ;:'I, Americ;;:'I,n Express: :36 of the1'n have ;:'I, 1\,1;:'1,Rter Card ;:'I,cconnt ;:'1,110. ;:'1,11
.AlIleIican Express, .J 7 of thenl have only a rvIaster Card account, ;32 have a
Viba account and a. Card account and an ArIlerican Exprebb. AssllIIle
that every cllbtolner has at least one of the bcrvices. The nurIlber of CUbtoIIlers
who have only have a Visa, card is?
56
Mathematics for Com puter Scientists Cha pter 5. Cou ntin 9
5. So for example from t.he New York Tirnes According to a New York Times
report on the 1 () top-perfonning rebtaurallt chaillb
(a) 11 serve breakfabt.
(h) 1 1 serve beer.
(c) 10 have full table service i.e. the,V server ctlc-ohol and all rneals.
All 16 olTered at least one of these services. A total of ;) vvere classified as
"family meaning t.hat. t.hey serve breakf:='tRt, but. do not serve akohol.
Fnrt.her a tot.al of five Rerve hre;:tkf.qst 8no have full t.ahle service: while none
serve heel', ;:tno. alRo h8ve fnll t.R hIe Rervice. \Ve 8sk
( a) (How rnany serve beer and breakfast '!
(h) HovY rnany serve heer hut not. breakf;:tRt?
(c) IIow rna.ny serve brea.kLtst, but neither have full table service, nor serve
beer'?
(d) How rnan,? serve beer and have full table ser\,rice'?
(), vVIlCn 1 x 1< 1 then sho\v that
1/(1-x) = 1 +X+X2+XJ+ X4+"+XT1+ ..
1/(1 -X)',/2 = 1 + (1/2)x+ ll,/2)(-1/'2Jx2 + +x/
1
+ ...
1.2 1._.3
1/(1-x)2 = 1 +2x+3x
2
+4x
3
+5x
4
+ ... +nx
n
-
1
+ ...
7. Expand (1 + 2xf
8, vVhich is the coefficient of the terrn \vithout an x in (x + 2/x) 11 .
!l Find an approxirnation for (0.95) 11.
10. Find the first B ternlb of the expanbion of (1 + x) 1//1,
57
Mathematics for Com puter Scientists
Chapter 6
Functions
1\1atheTflal:ician,8 are Like Fre'u.chmen: whalever YO'(l say 10 them they
translale i'u.to lheir O'wn lany'uaye and j01'lh'with it i8 sO'lnething enli'rely
rhfleTent.
Johann \Volfgang von Goethe
Chapter 6. Functions
QIle of the rnost fundarnenLal ( and useful) ideas in rna.1ohernatics is tha.1o of a
juncl'io'u.. As a prelirnina.ry dellnition suppose we have tvvo seLs X etnel Ya.llu \\.'e
also have a rule vvhidl assigns 100 every x E X a U:\IQCE value y E Y. \Ve will call
tlle rllle f ;;mo say tll;;tt for eac;h x tllere is ;:'} 1:1 = f( x) in the Ret Y. This is a very
"vioe oefinition ;;md one th;:tt is very similar to th;:tt of ;;t relation: the critical point
is tb.:l,t for ed,ch Cl. there it:; Cl. 'unique 'value y. A connnon \vay of \vriting functiolls is
f: X -----1 Y
wllic;h illllstrates that \ve have two setR X and Y together \vith ;:'I, rnle f giving vaIneR
in Y for values ill X. \Ve can thillk of the pairt:; (x) 1)) or Inore clearly (Xl f(x)).
This bet of pd.irs ib the graph of the function
In \vhat follo\vs \ve sho\v how fnndions ;:'ITiRe frorn the ioe;:'l, of relationR ana come
np \vith Rome of the main oefinitions. -YOll neeo to keep in mino the sirnple ioea
a fUllctioll is d, rule that takes in x "Talues and produces y values. It it:; probably
ellough to visualize f as a device \vhich when given an x value produceb d, y.
257
58
Mathematics for Com puter Scientists Chapter 6. Functions
f the fnndion
x y =f(x)
59
Mathematics for Com puter Scientists Chapter 6. Functions
Figure 6.1: FuncLion f
Clearly if yon think of f ;:'tR a m;:tc:hine \ve need to take C8Te ahont ,vhat ,ve are
allo\ved to put in, x, and have a good idea of the range of \vhat cornes u t ~ -yo It
is these technical issues "ve look at next.
The set X is called the dOlna.in o[ the [uneLion f and Y is codOrn(l:ln. \Ve are
lloflllally IIlOre interested in the set o[ vctlues { f( x) : x EX}. This is the range R
SOllletiInes called the 'ima,Yt' o[ the [undion. See figure 6.1
Examples
'Ve call have
f:X---+Y
1. f(x) = L" where X = {x: 0 < x < oo} 8J1d Y = {y : 0 < x < oo}
2. f(x) = 'Vx vvhere X = fx: 0 :::; x < oo} and Y = fy : 0 :::; y < oo}
B. f(x) = sin-
1
(x) where X ={x: -n/2:::; x < pi/2} and Y ={-l :S; 1I:S; 1}
If we think of the possibilitieR we hmre
There Inay be SOlne points in Y (the codOlnain) \vhich cannot be reached
by function f. If ,ve take 8Jl tlle pointR in X Rnd Rpply f \ve get 8, Ret
60
Mathematics for Com puter Scientists Chapter 6. Functions
-
-l

-l
.. u
o
..
-t:.J
--
j+-.J
o
tI--
-
---
-<;::)
o
rlonnn 1'.
Rnn;rr'-I'.
Figure 6.2: An onto function
R = {f(x) : x E XJ which is the range of the function f. Notice R iR ;;t snbset
of Y i.e.R C Y.
SYu:r jection8 (or onto functiont:;) have the property that for every 1) ill the
codoInain there is an x in the dornain such that f( x) = y. If you look at 6.1
you can see that in this C1.tse the codon11.tin is bigger th1.U1 the ntnge of the
function. See figure 6.2 If the range and codorna.in are the sa.lne then out
function is ;;t sllrjedion. ThiR meanR every y has a corresponoing x for \vhi(;h
y = f(x)
Allother ilIlportallt kind of function it:; the injection ( or one-to-one functioll),
\vhich have the property that if Xl = X2 then 1), Irlllt:lt equal 1)2. See figure
6.3
Lastly we e-all fune-Lions b'ljed:io'll.$, vvhen they are are both one-to-one and
onto.
A Inore str(},ightfonvard exmnple is at:; follo\vs. Suppose \ve define
f: X -----1 Y
vvllere f(x) = 2:<: ;;mo X = {x: 0 < x < oo} ana Y = b-J : -00 < x < ooJ. The rRngA
of the function iR R = {y : 0 < x < ooJ \vhile the (;ooornain Y has negative valuAs
vvhich \ve callnot reach usillg our function.
Conlposition of functions
The composition of tv.'O or rnore fune-Lions uses the output of one function, say f,
as the input of another, s1.\'y' g. The functions f : X ---1 Y and 9 : Y ---1 Z can be
61
Mathematics for Com puter Scientists Chapter 6. Functions






Figure 0.;3: An 1 to 1 function
cornposed by applying f to an argurnenL x 1,0 outain y = f(x) and Lhen applying
g to 11 to oht<=tin z = g( 11). See fignre O.i). The cornposite fnndion formed in this
,VRY frorn f ano g C;Rn he ,vritten g(f(x)) or g 0 f. This last form can be a hit
dallgerous as the order call be different in different tmbjectb. Ut:ling cornpot:lition
we call COllt:ltrud cornplex fUllctionb frorn sirnple vvhich it:l the point of the
exercise.
One interesting givell \vould be the function g for which x=g( f(x)).
In other \vords g is the iTU)CT8C function. :\ot all functions have in tl,ct
there is all inverse g written f-
1
if and onl,? if f ib bijective. In thit:l (,(l,t:le x =
f-
1
(f(x)) = f(f-
1
(x)).
The mTOWt:l and blob diagrarns are not the ubual \vay we dnnv functions. t'"ou
\vill recall that the technical description of f : X ---7 Y ib the bet of valueb (x) f( x))
SU}JPose \\.'e htke Lhe reals IR so our function takes real vetllles etnel gives us a.
nev,' seL of reals: say f(x) = v,.'e take x vetllles : cornpllte y = f( x) for these
vaIneR ano plot them ;:'I,R in figure 6.6. Plotting fnndions is a vital skill, yon kno,v
very little ;:'I,hont a fnndion until you have d1'8\.vn the graph. It need not he very
ac;c:n1'ate, m;:'l,tllenlR.ticians often talk abont skr:tr:hing ;:'I, fnndion. By t hiR they
Ineall a dnnving \vhich is not cornpldcly accurate but \vhich illustrateb the rrli:l.in
chi:l.raderistics of the functioll,
Now \ve rnight reason;:'l,hly ooes every sensihle looking function have an inverse:
An exmnple consider f(x) = x
2
which is plotted in figure (1.8. There is now problern
ill the definition of f for all real values of x, that is the dornain is :1Ft and the
coelonletin lR.. lIov,.'ever if \Ve exarnine the inverse v,.'e have a problelll.
if we ti:l,ke this rnay aTise frorn x=2 or x=-2. So there ib not an f-
1
= 1) -1/2
! If we change the dornain we can get around this. Suppose we define :IFt- = {x :
62
Mathematics for Com puter Scientists Chapter 6. Functions

(

(Y
--------
'-,
"'"

( z z=g(y)=g(f(x))

'-"'------

Figure 6.4: Cornposition of 1\,vo functions f and 9
Figure (),5: The ilrverse f and 9 = f-
1
Exanlples
1. Suppose f(x) = x
2
and 9(Y) = 1/Y then g(f(x)) = 1/x
2
. \Ve of course have
to htke care about the dellnition if the range and the dOlna.in to avoid x = 0
2. V",llen f(x) = x
2
ana g(x) = xl/2 9 is the inverRe fnnction when f is op,fineo
on the pORitive fealR.
63
Mathematics for Com puter Scientists
o
o
.,-
o
U")
~ 0 ~ - - - - - - - - = - - - - - - ~ - - - - - - ~
o
U")
I
o
o
..-
I
-4 -2 o 2 4
x
Fignre 6.6: Plot of f(x) = x
3
-1
Figure 6.7: Plot of f(x) = x
J
- 2X2 - X + 2
Chapter 6. Functions
64
Mathematics for Com puter Scientists Chapter 6. Functions
Figure 6.8: PloL or f(x) = Xl
Figure (),!): Plot of f(x) = x
2
o < x < oo} and c;onRioer f( x) = x
2
defined on lR + i.e.
In this r,:='tRe vve do not 11Hve the problem of neg;:d,ive values of x. Every valne of y
ariseR from :='t uniqne x.
65
Mathematics for Com puter Scientists
Exercises
For the following pairs evaluate 9 ( f ( x )) and f ( 9 ( x)) .
1. f(x) = l/x, g(x) = x
2
2. f(x) =3+4x) g(x) =2x-5
::L f ( x) = x + 1) 9 ( x) = x - 1
6.0.8 Important functions
Chapter 6. Functions
Over tilne we have COlne to see that SOlne functions crop up aga.in and ctgain in
applications. This seeIllS a. good point to look at SOIne of these.
polynoluials
\Ve r,;:dl functionR like f(x) = upxP + Up_1X
p
-
l
+ ... + U1X + Uo polynomials ;;md
thebe usuall,y have a dornain conbisting of the realb. In out exarnple the cocificientb
Qo) Q1)' ) Up are rllllnbers and our polynornial is said to have order p. Exmnple:::;
are
1. f(x) =x+2
2. f(x) =x
3
- x
2
+ x+2
::L f(x) = X
17
-11
4. f(x) =x
2
-3x+2
66
Mathematics for Com puter Scientists Chapter 6. Functions
Zeros
VAry often WA nAAo. t.o know for what. 'valnes ofx for which f(x) = upXP+Up_1Xp-l +
... + a,x + 00 = 0 ib zero. The valueb are called the zeros or the roots of the
polynolnial. vVe can prove that a polynornial of degree p has at Inost p roots which
helps a lit tIe. The sill1plest 1,0 way 1,0 find heros is 1,0 fadorize the polynornial so if
f( x) = x
J
- 6 * x
2
+ 11 x - 6 = (x - 1 )( x - 2)( x - 3)
bO f(x) = 0 when x = 1,2,3.
FctcLorihctLion is (ctS for integers) rather dilTicult. The best straLegy is to try
and guess one hero, say x=a and then divide the polynornial by (x-a.). \Ve then
repA:='It. Polynomial division is just likA long o.ivision. So t.o o.ivio.A x
3
-6x
2
+ 11x-6
hy x -1:
x - 1) x
3
- 6x
2
+ 11 x - 6
- x
3
+X2
x - 1) X
3
- 6x
2
+ 11 x - 6
- x
3
+x
2
- 5x
2
+ 11 x
x - 1) x
3
- 6x
2
+ 11 x - 6
- x
3
+ x
2
- 5x
2
+ 11x
x - 1) x
3
- 6x
2
+ 11 x - 6
- x
3
+ x
2
- 5x
2
+ 11x
5x
2
- 5x
6x- 6
",,'fitA out. t.he Rum
fino t.he power of x t.o mnltiply x - 1
mnltiply x - 1 hy x
2
:='I.R Rll0,vn.
snht.rad :='I.R RhoVln1.
fiud a rnultiplier to Irmltiply x - 1 to get (}. -5x
2
lIlUlLiply x - 1 and subtract as shov,,'n
67
Mathematics for Com puter Scientists Chapter 6. Functions
find a rnultiplier to rnultiply x-I to get a 6x
x - 1) x
3
- 6x
2
+ 11 x - 6
- x
3
+ x
2
- 5x
2
+ 11x
5x
2
- 5x
6x- 6
x-I) X
3
- 6x
2
+ 11 x - 6
-x
3
+x
2
- 5x
2
+ 11 X
5x
2
- 5x
6x- 6
-6x+6
o
notlling left so we Rtop!
The ans\ver is x
2
- 5x + 6. If there ib borrlething left then it is the rcrnainder.
Hence x - 3
x - 2) x
2
- 5x + 6
- x
2
+ 2x
-3x+6
3x-6
o
The (},ns\ver is x
2
- 5x + 6 = (x - 2) ( x - 3),
lIowever suppose we try x - 4
x - 1) X
2
- 5x + 6
-x
2
+x
-4x+6
4x-4
2
\Ve have a l'ernaiuder and the ans\ver is x
2
- 5x + 6 = (x - 1) (x - 4) + 2.
Exercises
FJLLoriL;e
1. 2xJ - x
2
- 7x + 6
2. 2xJ - 3 * x
2
- 5x + 6
68
Mathematics for Com puter Scientists Chapter 6. Functions
The power function
Suppose we take values x frorn the reals and cont:lider the function P(x) = XU for
SOlne value a. \Ve can suppose that a is ctlso real. So v,re have
An exalnple lnight be P(x) = x
2
or P(x) = X
l
.
5
. In the second case v.'e clearly have
1.0 redefine the dOlnain. Can you see why? The properties of Lhe pov.'er function
1. XU X x
b
=x
u
+
b
LogarithlTIS
\Ve know that we can \vrite po\vers of nurnbers, t:lO
10 = 1 10' = 2 10
2
= 100 10
2
= 1000
and 10
5
= 3.162278 ....
:\ow consider the badnvards probleln:
Given 1) can we llnd an x such LhctL y = lOx.
In otllef \vordR if ,ve define the po,ver function y = P( x) = lOx for x E 1(, as R hove,
tllen ,vhat iR tlle inverRe of thiR p-l (y)? It rnay help to look ;:tt figure 6.10. \Ve
11Hve plotteo ootteo lineR frorn (1.5JJ) to the c;urve. Going frorn x vertir,;:dly to the
curve and then to the 1:1 axit:l gives the po\ver value P( x) = 1). Thc re
1
lCl't:lC path
fr'oIn 1:1 to x is thc logaritlnn.
69
Mathematics for Com puter Scientists Chapter 6. Functions
0
;:
0
o:l
0
rJ:)
>.
0
'o:t
0
('.1
0
-2 -1 0 2
x
Figure G.I0: PloL o[ f(x) = lOx
The inverse of p(x) ib call the logarithrn or log and is \vritten lOglO(X), So
Often we are lazy and drop the 10 and just write log(x)
13eul.use we know that log is the inverse of Lhe po\ver funcLion \Ve have SOIIle
useful ruleR
1. log(u) + log(v) = log(uv)
2, log(u
V
) = v log(uv)
:1 log(u -log(v) = log ~ )
4. -log(u) = l o g ~ )
Of course ,ve did not 11ave to dl00se lOin Ol1r definitionR. \Ve c011ld have chooRe
2, like m;;my engineers: or ;;my pORitive n11mher a say. \\le t.hen ,vrit.e 1:1 = logu(x)
to indicate the n11mher 1:1 ,vhic;h satisfieR x = a
bl
. The lOgll(X) iR ullled t.he log of
x to base Q,
FoI' I'easons \vhich '.vill (v{e hope) becorne apparent rnathernaticianb like to Ube
nat-ural loys \vhich have a base e = 2.718282. ... because they are used so o[ten
rather than \\'rite loge ex) you vvill o[ten see thern \vriLLen as In(x) or j usL ctS log (x).
All logs sctLisfy Lhe rules set out in the list G.0.8. \Ve shall be la:t;y and just use
logarit.llms to hase e.
70
Mathematics for Com puter Scientists Chapter 6. Functions
\Ve can of course express logs in one base as logs in (.tnot11e1'. Suppose x
a1og(l Ix) = b10gb (x) Lhen taking logs gi ves
SOInetirne it ib natural to express powers as base 2 for exarnple 1:1 = P(x) = 2
X
,
rvrathernaticianb often Ube the nurnber e bO the power definition is 1) = eX. which
you will orten see writ ten as y = exp(x) since eX is called Lhe t':1pone'll,l:iaL juncl'icrl/..
6.1 Functions and angular measure
\Ve look briefly 8t the ll1eRS11rement of 8,ngleR. Angular ll1e8,Rure h8,R been import8,nt
fi'0111 t11A vAry beginning of 11111118.11 11istory both in astronorny ana navigation.
Consider a circle with the angle e Inade \vith the x axis ab sho\vn, Unlike Inaps in
Inathelnatics the reference line is not :\orth but along the x axib and if "ve rotate
anti-clockwise we sweep out an angle e. The angle is tradiUonctll}' Inectsured in
lllinuLes and seconds. \:\'e "vill sUck 1.0 degrees for the InornenL.
I
t
I
x
If v,,re sweep allU-clockwise Lhrough 360 degrees v,,re sweep out ct circle. 180 degrees
is a half circle and 720 = 3 x 360 two circles. RotctUons in a clockv.'ise direction
are aSRumed to he negative oegrees, RO -90
u
= 270
0
To c:0111plir;8te things 8, little "ve C8J1 also meaS11re the angle in an eCJuivalent
,V8Y hy measuring the length of the 8TC we 1118,ke out on the r;irde 8,R \ve Rweep
through the angle e, Suppose this is s. For a circle of radius 1 s is a rneasure of
the d,lthough in different units called radians. So one circle ib 2IT radiaut:)
and 90
0
is n/2 radians. \Ve convert fronl degrees 1.0 ra.diculs ctS [ollo\vs
71
Mathematics for Com puter Scientists
8
360s/(271)
rao.ianR
2718/360
s
Chapter 6. Functions
If you look at IIlOSt you will sec a button for switching frorn
degrees to radians and v ice versa ..
The trigonolnetric functions
Of c;onfse we can ;;mgleR in otller ,V8YR. Suppose "ve look at the angle e
in the di8,gram. The f8tio of tlle y 8,no. x valnes iR related to the 8,ngle. Homan
RurveYOfS wonlo. often dl00Re ana angle by fixing tlle x valne ana the y -v8J11e. As
you can. iIIlagine, five steps and then steps vertically giveb the saIIle angle no
Inatter \vhere :you arc
r
x
TllUS frorn tlle di8,gram 8 iR rel8teo to y/x. In f8Ft we define y/x to he the tangent
of e "vrittell as tall e = y/x. The iln,'erse function is tan-
1
8 = -y/x or sOIIldirnes
archu} e = y/x The reader Inight like to exarnine our triable and see "vhy the
tangent or 90
0
does not exist. \:Ve provide a, plot or the tangent 1'1'0111 0 to just
under 90 degrees in figure G .11. If \ve keep the definition on the donlctin 0 :::; e < 90
as is (relatively) silllple. \Vhile the d01nain is easil}' extended \Ve leave this to those
of yon \vill intereRtR in tllis difedion.
or course we do not have to use tangents, although they ctre probctbl}' the
lIlOSt practic-al in applic-ations. Alternative are to use the ratio y/r the height y
oivioeo. hy tlle rao.ius of tlle cirde r. This is called the sine function and ,vritten
Rin 8 = y/x.
In ct silIlilar \ve \ve could use the cosine \vriLLen cos 8 = x/r. Both or these
fnndions 8Te plotteo. in fignre O. J 2 Tllere 8Te lotR of links hetween theRe functionR,
72
Mathematics for Com puter Scientists
0
l.I') -
= -
"'"
'" Q)
.c.
g -
=
I
0
-
N
-
=
-
I
0
for example
I
20
I
40
thetFl
I
60
Figure G.11: Lan x
sin e
tane =--
cos e
I
80
ThiR can he oeouc;ed ql1ite Rimple frorn the oefinitionR. Try it yom'Relf!
Chapter 6. Functions
The trigonornetric functionR are periooic in th;;tt if \ve plot them over a large
part of the axis the,? repeat as in figure (), Li
Out next btep ib the stud,? of the bhapes of functionb \vhich brings us to Cal-
culus.
73
Mathematics for Com puter Scientists Chapter 6. Functions
<::>
- <Xl8
- - ~ n
co
o
=
a
o 20 40 60 80
Figure 6.12: t cUI X
~
<n
0
"2
=
"m
0
<n
T'
~
,.
-15 -10 -5 0 5 10 15
Figure 6. L3: Plot of sin and cos
74
Mathematics for Com puter Scientists Chapter 7. Sequences
Chapter 7
Sequences
Reason's last .slep i.s lhe -recognition Ow.l there are an infinite nu.mber
(;f things whieh an bf:!jond it. Pascal
\Ve \vrite a sequence U'I U2, ... I Un.1 . .. as {un.} and our interest is nOrIIlally
whether the sequence tends 1,0 a lirniL A \vritten
Un ---1 Acts n ---1 00 .
or limTL 'oc Un = A
However there are IIlHny interesting sequences \vhere liIIlits i:lTe not the rnain inter-
est. For exalnplc the Fibonacci sequence. In Libel' .Abaci (1202) poses
the follo\ving problern
IIow l\'iany Pairs of Rabbits Are CrectLed by One Pair in One Year:
A cerLa.in IIlcUl had one pa.ir of ntbbits together in ct cerhtin enclosed
place, 8,nd one \vishes to kno,v hovv many are c:re8teo from the pair
in one year ,vhen it is the natnre of them in a single month to be8T
8,notller p8,ir: and in the secono. rnont h those horn to hear 8JSO.
The resulting sequence is
and each tenn is the SUIn of the previous Lv>'o tenns. An interesting; aside is Lhat
Lhe nth Fibollacci nUlnber F( n) can v,re \\TiLLen as
F(n) = [q/I - (1 - rlJ /15 where = (1 + 15)/2 1.618 ...
vvhich is a surprise since F( n) is an integer and the forrnula contains VS. For lots
lIlOfe on sequences see
http://www.researdl.att.com/ njas / sequences /
7S
Mathematics for Com puter Scientists Chapter 7. Sequences
7.0.1 Limits of sequences
\Ve turn our attention to the behaviour of sequences such as {an} as n becolnes
very large.
J. A m8y approadl R finite v81ue A. \Ve Ray that it tenOR to a limit,
RO for example we write
(
1) (1)2 (l)n
1, 2: ) 2: ! 2: ... 2: , ...
or
1.0000 0.5000 0.2500 0.1250 0.0625 0.0312 0.0156 0.0078 0.0039 0.0020 ...
{Gf}
ana we shall Ree that
2. If a sequence does not converge it lIla,? go to oo, that is keep increasing or
decreasillg.
2 4 8 16 32 64 128 256 512 1024 ...
Informally {2rt} ---1 00 ;:'tR ---1 00.
'J
,). A sequellce IIlay just oscillate
1 -1 1 -1 1 -1 1 -1 1 -1
Limit
vVe need a definitioll of a liIIlit alld after 2000 years of trying \ve use:
{an} ---1 A as ---t 00 if and only if, given any nunlber there is an N such that for
n Niall. - AI < E.
In essence I gi ve you a. guaranLee that I can gel, as close as }'OU \vish 1,0 a lirni L
(if it exiRtR) for all members of tlle Reqnence ,vith snfficient ly large N : that is after
N all the valueR of tlle Reqnenc;e RatiRfy I an - A 1< E. The ioe;:'\, iR th;:'\t if there iR
a. lilnit then if you give rne SOIIle here , I can guarantee thi:l,t for sorne
point in the sequence all the tenns beyond that all lie vvithin E' of the linlit.
76
Mathematics for Com puter Scientists Chapter 7. Sequences
Exanlples
\Ve 8Tgne aR follows:
Sn]1pose yon give me 8, (Rm8,1l) v8Jne for . I can then choose a v8Jne N
\vhere N > IIE'. vVe can do this s ~ for 1 x 1< 1
It then follows that as N > 1/ then E > liN. But ifn > N then lin < liN
so we can say:
if we choose N > 1 1 the when N > n 11/n - 0 1< and so lin ----+ 0
\Ve ctrgue as follovvs:
Sn]1pose yon give me 8, (Rm8Jl) v8Jne for . I can then choose a v8Jne N
where 1 x IN< E. Or N log 1 x 1< log . Rearranging
log E
N > 1 1 beware the signs!
log x
But if log; 1 x 1< 1 then
So v.'e dlOose N > log I log; 1 x 1 then \\'hen N > n
aHci so 1 x
Tl
1----+ 0
77
1 x
Tl
1=1 xn - 0 1<
Mathematics for Com puter Scientists Chapter 7, Sequences
Rules
Nlanipulating expressions like 1 U
rL
- U 1 can be tricky bO it ib easier to de\.rclop
SOlne rules. C sing these is vel',v rnuch eetsier ets vve shan see.
If {un} and {b
ll
} are two sequences and {an} ----+ A v/hile {b
n
} ----t B then
{urL b rL} ----+ A B
{urL/bnJ _____1 A/B provided B ib nonzero as arc the {b
n
}
For a c;onst;:tnt c we hRve {CU
n
] _____1 cA
albo
If {all.} ----+ oo then {1 / un} ----+ 0
If {unJ _____1 oo \vhile {bnJ -----1 B (fiuite B) then{u
rL
+ b
rL
} -----1 oo
If tUn} _____1 00 '\vhile tb
n
] -----1 B (finite B) thentunbrJ _____1 oo oepenrIing on the
sign of B.
\Ve can look at rationetl fund ions as follows
1.
{
n+l
n + 13 1 + 13/n 1 + 0
2.
3.
{
n+1 }={ 1+1/n }_____11/1-----11
n + 13x
rL
1 + 13x
rL
/n
1 x 1< 1
4.
= _____1 0/1 = 0 -----11
{
3rL + 1} {(3/4)rL + 1/4rL}
4
n
+ 13 1 + 13(1/4)n
Subsequence
A subsequence of a sequence {an} is an infinite succession of its tenns picked out in
any "vay. ".\ote tl18t if tlle original Reries convergeR to A so rIoes any sl1hseqnence.
If U
n
+ 1 > Un '\ve say tlle snbseC]l1ence is inc;reasing while if u
n
+ 1 < Un ,\V8 RAy
the bubbequence is decrea.sing. Increabing or decreabing sequences are sOInctiIIles
called rnonatonic.
78
Mathematics for Com puter Scientists Chapter 7. Sequences
Bounded
If ;;m incre;:'\,Ring Requence iR 11ounaeo. 8,ho-ve then it mURt converge to 8, limit. Simi-
larly If an decreabing sequence is bounded below then it rnust con\terge to a linlit.
7.1 Series
A series is the sunl of Lenns of a sequence written
N
U, + Uz + U3 + ... + UN = L Ui
i='
\Ve USA Ulpit8J sigm8, ( L) for Sl1111R ana by
l=a
WA mean the Rum of tennR like Ui for i taking the v8J11eR a to b. Of C011rRe there
are lnany series \ve Slun, for exalnple \ve have rnet the Binolnial series and \ve have
the follovving ubeful rebultb.
79
Mathematics for Com puter Scientists Chapter 7. Sequences
, + 2 + 3 + 4 + ... + N = = N (N + 1 )/2
,2 + 22 + 3
2
+ 4
2
+ ... + N
2
= i
2
= N (2N + 1 )( N + , )/6
1
3
+ + 3
3
+ 4
3
+ ... + N
3
= i
3
= :N (N + 1)/2J
2
+ 1* + ... + = = 1 -
7.1.1 Infinite series
If \ve want the SHIn of the infinite beries L 1 lii -if bHCh a thing exibtb - \ve need to
be clear we Inean. Jlss'I1:rnc that all the te-rrns in the 8eTics aTe non-negati'l.lc: that
is 0 :::; lii. COllbider the partial SHIns
Ift.lle ReCjllence t5
r
J C;Ol1verges to a limit 5 t.hen ,ve R8y that the series 1 Ui iR
convergent alld the Slun ib S. Othenvibe \ve bay the serieb diverges or is divergent.
Exarnples
,OC 1 i:::; divergellt
i....n 1 n .
\Ve call i;ll'gue: Let
54 = 1 + - + - + - = 1 + - + - + - 1 + - + - > 2
, 1 1 1 (1') 1 1
234 2 34.-' 22
and
58 = 1 + - + - + - + - + - + - + - > 1 + - + - + - > :>/2
1 (1 1) (' 1 1') l' 1 '1
2 34 5678 222
80
Mathematics for Com puter Scientists
111 1
> 1 + - + - + - + - > 6/2
2 2 2 2
In general we can ( \vith care sho\v )
k
52k > "2 + 1
Chapter 7. Sequences
So we can rnake the partial sunlS or 2k tenns as large as we like a.nd Lhey axe
increasing and unbounded. Thus Lhe series rnusL be di vergenL.
This has an irnporhtnL consequence if Un ---t 0 it does not lllean that the
sum is convergent. It m8y he hut it m8y not he!
l) xn is convergent for Ixl < 1 ano the Rum iR l/(l-x). \\Then Ixl > 1 the
serie:::l is divergent.
\Ve can argue that
N 1 _ X
N
-
1
L xn = 1 _ X ---1 1/(1 - x)
n=O
(},nd :::linee "ve have all explicit forrn for the snIn the result follmvs,
converges and the surn is 1 silKe
N 1 N (1 1) 1
L n( n + 11 - L n: - (n + 11 = 1 - N + 1
n 1 - rL 1 -
,OC 1 is diver.Q:ent for ex > 1 and c;onveraent othen.viRe .
.::::... n h
Some R.ules for series of positive terms
If L:=l Un ann L:=l Vn are both convergent \vith snnlS Sand T then
1 (Un v
n
) converges to 5 1
If 1 Un converges then adding or t:mbtracting a finite rnunber of terrns
docs not affed it "vill howe\rer affect the SUIn.
81
Mathematics for Com puter Scientists Chapter 7. Sequences
If Un does not converge 1,0 hero Lhen L ~ = Un does not converge.
The cOlnpa.rison tesL: If L ~ = l U-
n
and L ~ = l Vn are 10\\'0 series of positive
tenns and if {un/v
l
,} Lends to et non zero finite lilnit R then the series either
l)ot.h c;onverge or hotll diverge.
The Rat.io teRt.: If ~ , Un is;1 RerieR ofpoRitive t.ermR and Rnppose tun+,ju
n
} ~
l then
If l < 1 the series convergcb.
If l > 1 the Reries divergeR.
If L = 1 the question is unresolved.
The integral teRt.: SllPPoRe -vve 118ve L ~ = Un ano f(n) = Un for Rome funct.ion
f Wllidl RR.tiRfieR
J. f( x) is oecreaRing 8.R x increRseR.
2. f( x) > 0 for x 2 1
Then
N fN+l
L O<Ln ,U
n
- 1 f(x)dx<f(l)
2. The sunl converges if the integral f ~ f(x)dx is llnite etnd diverges if
J ~ f( x) dx iR infinite.
Absolute Convergence
\Vc say that L 1 Un is absolutely co TUHJgent if L ~ I Un I convergcs. If
,IX: Iu I does llOt cOllvcrge but ,:;0 U does thcn \VC sa
v
the series ib con-
i....n 1 n . i....n , n .J
(lil:ion.alLy canoe/yen.t. The nice thing about etbsoluLely convergent series is \-ve can
rearrallge Lhe tenns without alTee-Ling the convergence or Lhe Sllll1.
Alternating sign test
On simple teRt. for non conditionally convergent series iR t.he alt.ernating Rign teRt.
SnpPoRe ,ve have a decre8.Ring Reqllence of pORit.ive t.erms tUn} and let
S = U, - U2 + UJ - U4 + ... + (-1 r'U
n
...
Then S convcrgcb. For exalnplc
1 1 1 1 1
1--+---+--- ...
2 3 4 5 6
82
Mathematics for Com puter Scientists
Power series
A series of tlle form
:"'XJ
S = uo+u,x+U,X+U2
X2
+
U
JX
3
... = L U11.
Xn
11.=0
Chapter 7. Sequences
is called a. powe,. .serie.s IVhul)' power series only converge for values of x v,,,hich
RatiRfy 1 x 1< R for Rome v;:dlle R. Tllis vRlne iR called tlle radi?Ui of ton?h''tgente.
\VA UHl llR1Utlly rino R llRing the rRtio test: for example
(
X) ( X) 2 ( X) 3 ( X) ,1
5=1+ 5" + :5 + :5 + 5"
Then
1 ';un 1= 1 G) nil/G) nl = I G) I
for thib to be less than 1 \ve need 1 x 1< 5 You can then check x 5 separately.
Exercises
1. vVrite do\vn the firbt five terrns of each of the bequences defined below
(a) Un = 1 - (O.2)n
(h) u
n
=1-(-O.2)n
( c) Un = (n
2
+ 1) / (n + 1).
(d) Un = 3/Un-l Q, = -1
2. Graph the sequences in question 1.
;3. Decide v.'hidl of the follovving; sequences converges and llnd the linlit if it
exists.
(a) 2 - (O.2)n
(b) 2 - (-O.2)n
(c) (n+1)/(n
2
+1)
(d) (4+n)/(3n-2)
(e) (4 + n)
(f) ( n
2
- n + 2) / (5n
2
+ 4 n + 1 )
(g;) 211. - ( - ~ )
83
Mathematics for Com puter Scientists
4. How l;:trge m11Rt. n he for (1/3 fL to be leRR t.h;;tt
(a) o.t)]
(b) 10-
6
5. Find a. llulnber N such th(.),1, n2/2n :; 0.001 if n > N.
f
' C1 - 1 In
). ,")11ppORe a
TL
- X . x>l
(a) Show t.hat. t.he ReCj11ence iR decreasing.
(b) Show tha.1o the sequence is bounded below.
(c) Is the sequence convergent?
7. Show that
1 + 3 + 5 + ... + (2N -1) = N
2
8. FiwJ
N 1
.L (n+ 11(n+21
TL 1 ' ,
9. Decioe \vhich of the follovving R11111R are c;ol1vergent..
( a) L 1 1 / (2n - 1)
(b) L ~ = , 2/( n
2
+ 3)
(c) L ~ ~ = 1 /v2n - 1
84
Chapter 7. Sequences
Mathematics for Com puter Scientists
Chapter 8
Calculus
Fm. very good al 'integral and dljJerential ('alC'(ll-us
J
1 know lhe SC'l-
r:nhfi,r names ()f br:ing.c; aniuwleulous: Tn .c;hort, in 1naifers ?h'gr:tahlr:,
animal, and mineraL J am the ?iery modd ()f a modern Afnjor-Gr:neraL
Tlle Pirates of Pen7.ance. Ac;t 1.
Chapter 8. Calculus
\Ve have looked at lirnits of sequences, now I want 1,0 look at lilnits of functions.
Suppose we have a function f(x) defined on an interval Q :::; X :::; b. I have a
Reqnence Xl, X2, ... , X
rL
\vhidl tenos to ;;t lirnit xo. Can I say that the Reqnenr:e
f(xd, f(X2,"" f(xn) tenos to ;;mo \vhat do I me;;m? \Ve norm;:dly oefine the limit
8S follo\vs:
\Ve R8y tll;;tt f(x) ----1 f(x
l
)) ;;tR x ----1 Xo if for ;;my > 0 there is a vahle
8 > 0 slldl th;:tt 1 x - Xo 1< 8 =}I f(x) - 1<
Tllis is in the same spirit as onr previolls oefinition for S8CplenC;eR. \Ve r:;:tn he ;;tR
close RR "ve \viRll to the lirniting valne t
For eX;;U11ple (x - 2)4 ----1 0 ;;tR x ----1 2. If yon given me an 0 < < 1 then if
1 x - 2 I:::; 8 we kIlO"V 1 (x - 2)'1 - 0 I:::; SIJ. So pro\,rided S :::; E" \ve have a lirnit at:)
x ----1 O!
80.0
70.0
60.0
50.0
/10.0
;30.0
20.0
10.0
/
/
1.0 2.0 3.0 4.0
85
Mathematics for Com puter Scientists Chapter 8. Calculus
0.:)
.i) 1.0 1.52.0 2.() 3.0 3.5
-0.5
In the ser;ono Ul.se we plot Rin (1 Ix). ThiR Rtarts to oscillate faster :='mo f;=tRter as it
;=tpproar;heR 7.ero :='mo ( it is not Cjuite sirnple to Rll0\V) doeR not have a lirnit.
86
Mathematics for Com puter Scientists Chapter 8. Calculus
8.0.2 Continuity and Differentiability
\Ve did not specify which direction v.'e used to a.pproetch the lilniting value, [rorn
above or [roIn below. This Inight be iInporhtn1, as in the diagran1 belo\v vvhere the
f(x)
/
/
X-----1 Xo
[uncLion hetS a Jump a.L Xo.
\Ve like conliu:(LO'(lS these are functions where f(x) -----1 f(xo) etS X -----1 Xo
frOIll above and below. You can 1,hink of these etS [unctions you Ce),11 draw withou1,
lifting yonr penc;il off the p8.ge. ContinllollR fllndionR h8ve lotR of nic;e properties.
If vve h8ve a c:ontinllOllS fllndion ,ve might reasonahly look at the slope of t.he
curve at an,Y point. Thib UlaY have a real physical rnea.ning. So buppose vve have
the track of a car. vVe rnight plot the distance it East against tirIle.
If the difference bet\veen the distance at tirnes to and tl is 0 then 0/( tl - to)
gives the approxilna1,e speed. This is just the procedure follo\ved by aventge speed
calneras 011 roads! IIowever \\rha.L v,re have observed is an average speed. If we \\"etn1,
an est.irnate of speeo at a particlllar t.irne t we neeo to 8no t1 t.o 8,pproach t.
to t tl
87
Mathematics for Com puter Scientists Chapter 8. Calculus
" e
y
-------------------------- [(x)
x
x+ Sx
If we take the tirnes to be t and t + \vhere St Ineans a sInall extra bit of t, then
f(t + St) - f(t)
(t + St - t)
as St becolIles srnall or Inore explicitl,?
f(t + St) - f(t)
------ as t ---i 0
St
ThiR lirnit giveR the dr:rinoti?}f' vvhic;h iR the slope of the cnrve f( t) at the point t
;;mo is \vritten f' (t) or
df = lin1 f(t + St) - f(t)
dx bt)O St
(8.1)
Suppose \ve take 1:1 = f ( t) = 3 - 4 t, a line with constant negat i ve slope. Using the
equaLioll 8.1 we have
df
dx
lim 3-4(t+St) -3+4t = -4St =-4
bL----;.O St St
If \ve now have 1:1 = x
2
- 3 we writing x for t
df
dx
lirn (x + Sx)2 3 - x
2
+ 3 = x
2
+ 2xSx + - 3 - x
2
+ 3 = 2xSx (Sx)2 = 2x+bx =
bt )0 bx bx ex
So at x=2 the Rlope is 7.ero \vhile \vhe11 x iR 11eg;:ttive the slope iR do\vn and then
is npwaroR \vhen x is greater tl18t 7.ero. You might find it uReful to c011Rioer the
plot. Note that if \ve take a point on a curve and draw a straight line whose slope
is f' ( x) this line is kno\vn as the tangent at x.
88
Mathematics for Com puter Scientists Chapter 8. Calculus
\
12
/
'\
10
j
\
,
I
\
8
I
\
/
()
/1
2 /
\
/ ...
Of course life is too short for working out the derivatives dy/dx like this 1'1'0111 first
principles so we tend to use rules ( derived fr0111 first principles ).
d [ . df
1. - Qf(xi = Q- \vhere Q is a COllbtant.
dx ,. dx
2. ~ l f x ) + g(x)] = df dg
dx dx dx
:,. dd
x
[f(x)g(x) = f(x) ~ + g(x) ~ :
d 1
4 ---
. dx f(x)
1 df
df(g(x)), I .'
G. = f (g (x)) 9 (x) uSlng; , lor the den vat 1 ve.
dx
89
Mathematics for Com puter Scientists
This bet of rules Inakes like very bO
d ')
- (3x- - 11 x + 59) = 3 x 2 x - 11
dx
d 1 6x - 11
dx (3x
2
- llx + 59) (3x
2
- l1x + 59)2
d 2
dx (3x - 11 x + 59)(x - 1) = (6x - 11)(x - 1) + - llx + 59)( 1)
Example
Chapter 8. Calculus
Suppose we \vould like to bhow that sin x :::; x for 0 :::; x :S niL \Ve kno\v that
when x = 0 x = sin x = O. But
dx d sin x
- = 1 ano --- = c:osx
dx dx
Sin('e ('os x :::; 1 in the interval it irnplies that sin x grovvs 1nore slowl)' than x and
the result follows.
011ce we 1110ve away fron1 polynornials life gets a lit tIe n10re cOll1plex. In rectlity
yon neeo to kno\v tlle oeriv:=ttive to he ahle to proc;eed so YOll neeo a list snch as
in tahle S.1. Note that the oerivative of exp( x) is jllSt exp( x). So for eX8Tnple
Table tl. J: Tahle of oerivatives: 8Jl logs 8Te h8.se e ano a is a c;onst8.nt
Fnn ct ion Derivative
exp( ax) aexp(ax)
aX
aXlog(a)
log(ax)
1
-
x
XX
xX(l + logx)
sin( ax) a c:os( x)
c;os( ax) -asin(x)
tan( ax)
Q
cos
2
(x)
. 2 dexp(-x
2
) )
H 1) = exp( -x ) then = exp( -x-)( -2x)
dx
J d log(3x2 - 4x + 1) 6x - 4
If 1-) = - 4x + 1) tllen = C J )
dx - 4x + 1,
It is important to rernember that the formnlas only work for logarithms to base e
and trigonornetric bin, cos etc expressed in radians.
90
Mathematics for Com puter Scientists Chapter 8, Calculus
higher derivatives
S
d-y. ft' . h . h t --J . ff t . t . t .' d II.]
, ll1ce - lR a nne; Ion we 1'mg t. '"VIR ,0 ul eren la P, 1 t.o get. --- ca e(1

d
2
l d
4
tl 1
J 't' 1 'tt Y If' l'if' , l' ,Y
Ie t:leconc uenva Ive an( \vn en --'J' we (1 erentlUte ... tlIIles \ve wnte --4
and in general
So if Y = log(x) we have
dy
dx
IVlaxillla and llliniIna
dx'
n = 2,3)4, ...
6
x
4
'
One conanon use for the derivative is to find the rnaxinnun or rninirIlurIl of a
function, It is eas,Y to see that if \ve have a rIlaxirIlUIIl or rninirIlUIIl of d, function
t.hen t.he derivative is Consider -y = + - 6x + 8
/
I
40
:30
20
-10
-20
-:30
/
;
i
/
df
\Ve C;o111pllt.e -d = x
2
+ X - 6 '\vhic;h iR "vhen x
2
+ x - 6 = (x + 3) (x - 2) = 0
'x
or x = -3 d,nd x = 2 and h'orn the plot it we sec that we have found the turning
pointt:l of the function, These are the local rnaxirna and rninirna.
lIov.'ever \\'hen we step back and look at the "vhole picLure it is possible t.o we
df
11Hve ;:,\, Rtationarv 110int. i.e, - = 0 wllie;h iR not ;:,\, tnrnin,g 110int. and hence '\ve
"dx "
need a. local rnax or Ininirrnnn rule:
91
Mathematics for Com puter Scientists Chapter 8. Calculus
dy
I
-=0
dx
dy .
dy 0 f
- < 0 for x < xo - > or x < xo
dx dx
dy .
dy 0 f
- > 0 for x> xo - < or x> xo
dx dx
Xo iR 8, rmmmnm Xl) iR a rnaximnm
d
2
y
d\J

dx2 < 0

1. The fllnction f(x) = -3' x
3
+ 1x2 - 6x + 8 h8,R derivative dy = x
2
+ X - 6 RO
dx
at X = 2 we 118ve = O. \V11e11 x < 2 the oerivative is neg8,tive vvhile ,vhen
(X
x > 2 it iR pORitive so we h8ve a minimnm.
2. Or perhaps simpler = 2x + 1 > 0 at x = 2 so we have it minimum.
\Vhcll x = -3 again dy = O. For x < -3 dy > 0 vvhilc \vhcll x > -3 dlJ < 0
dx dx
irnpl,yillg a lIla,xirnurn.
4
,\ '[ , 1" d
2
y 2 1 0 :) 1 1 '
" or Sllnp ICILy --2 = x+ < at x = -':'l lellce vve lave a.lnaxl111Ulll.
dx
92
Mathematics for Com puter Scientists Chapter 8. Calculus
Exarnple
Suppose we lnake steel CeUIS. If the fonn of the CeUl is a. c.:y'linder of height hand
radius r the vollllue of the can is V = 1[:1'2h etnel the etrea of the steel used is
A = 27tTh + 27tT
2
.
\Ve want t.he volume to he 64c:c Rnd henc;e V = '7tT21'"1 = 64 ,vhich giveR
1'"1 = 64/( 7Tr
2
). Tlle ;:'I,rea iR tllerefore A = 2rtTl'"1 + 2'7t,,2 = 128/r
2
+ 27Tr2
To rninirnize the area \ve cornpute
dA 7
- = -128/1'- + 47t1'
dr
which is zero \vhen 7 T r ~ = 128 giving 1':::: 2.17 and h = 64/{7Tr
2
) r::: 4.34.
To check that this is a rninirnurn
w hic-h is positive when r is posi Li ve so we have a rninin1lllTl.
The Taylor Expansion
\\le leave you vvith one useful approxirnation. If ,ve hAve ;:'I, fllndion f( x) then ,V8
hav8
df a
2
df2 an dfn
f(x+o)=f{xl+u-+-
2
-,+ ... +---+ ...
- dx ! dx- n! dx
n
\:V11ell 0 i:::; slIlal1 alld vve evaluate the derivatives at x. For exarnple if \ve take sin x
the derivatives are cosx, -sinx, -cosx, sinx, .... So at x = 0 since :::;in 0 = 0
and co:::; 0 = 1
0
3
U') 0
7
sin(a) =a--+----
3! 5t 7t ...
8.0.3 Newton-Raphson method
\Ve no\v examine a rnethoo: kno\vn ;:'I,R t.he Newton-R;:'I,phROn rnethoo: that. makeR
use of tlle oerivative of tlle fundion t.o fino ;:'I, 7;ero of that fundion. SllPPoRe ,ve
have reason to believe that there is a zero of f(x) ncar the pointxo. The Taylor
expall:::;ion for f{x) about Xo call be written as;
I 1 , /I
f ( x) = f (xo) + (x - xo) f (xo) + 2 t ( x - xof ( xo) + ...
If \ve drop the the tenus of this expansion beyond the first order tern1 v,.'e have
f ( x) = f (xo) + (x - xo) f' ( Xo )
93
Mathematics for Com puter Scientists Chapter 8. Calculus
".\ow set f(x) = 0 to fino the next approxirnation, Xl, to the 7.ero of f(x), we
fino:
or
f(xo)
Xl = Xl) - f' ( Xo )
This provides us \vith an itc'(ution sehe-rnc vvhich IIlay well converge on the zero
of f( x) under appropriate conditions.
example
SnpPoRe we vvant the c;ul)e root of 2 or the value of x for ,vhirJl f( x) = x3 - 2 = O.
Here f' (x) = 3x
2
so
x8-
2
Xl =Xo--:)-,-
JX
o
Starting \'lith Xo = 1 we have Xl = 1.333333 and using this value for Xo \ve get
Xl = 1.263889. The steps ,He laid out belo\'l
Step Est inlctte
0
1 1 ~ i ; r 3 ~ i ; r 3
2 1.2fB889
;3 1.25093:3
4 1.250921
Or SUIJpose f (x) = sin x - ('os x then f' (x) = cos x + sin x and so
sin Xo - cos Xo
Xl =Xo- .
cos Xl' + Slll Xo
tllen starting ,vitll Xo = 1 ,ve 11Hve
Step Estim;;d.e
1 1
2 0.7820419
')
d 0.78i);39f32
4 0.78i);39f32
5 0.7825]982
To examine the conditions nnder \'lhich this iteration converges, we consioer the
iteration function
f(x)
g(x) = x- f'(x)
94
Mathematics for Com puter Scientists
whose derivative is:
'( ) = 1- (f'(x))2-f(x)f
li
(x)
9 x (x)
f(x)(' (x)
(f'(X))2
Chapter 8. Calculus
At t,llA actnal 7.ero, f(x) = 0, so tll;:,,,t as long as f' (x) = 0, WA h8ve g' (x) = 8.t.
the zero of f(x). In addition \ve \vould like the iteration function to get srnaller
that it:; 1 g' (x) 1< 1. vVe conclude that the :\e\vton-Raphson IIlethod converges in
the interval where.
f(x)f" (x) - 1
(f'(x)J2 <.
Step Estilnate
0
1 1.;33:3;33:3
2 1,26;3889
"
1,259!Xi;3 c)
/1 1,259921
9S
Mathematics for Com puter Scientists Chapter 8. Calculus
8.0.4 Integrals and Integration
rvrany irnport:='mt problell1R can he reduceo to finoing the are;=t uno.er a curve hetween
two pointR a :=,mo. b
f(x)
a X-----7
b
Tlle ohviollR idea is to split the are8. into small redangleR 8.nd RUll1 the are8, of
thet:le. So if \ve the the rectangle bet\veen Xj and Xj-l thib has a height of f(xj)
and au area of f ( Xj ) (Xj+ 1 - Xj ). If \ve add all buch rectangles thib gi veb an gi veb an
apprOXilIlation to the area. \Ve do better \vhen the \vidth of the rectangles gett:l
slllall so if we choose all the vvidLhs as 8 our ctpproxirna.Lion is
L f (xd 8x for a = Xl) X 21 ... ) X
rL
= b
\:Vheu \ve t:lhl'iuk 8x to zero we have the area. \ve need and \vrite
J: f(x)dx
The f sign \vas originally (;\' capit (;\,1 S, for sun1.
96
Mathematics for Com puter Scientists Chapter 8. Calculus
f(x)
a x---+
b
\Ve avoid technicalities and define the (It:[inite 'integral of a fUllcLionf(x) betvveen
a and b as
f f(x)dx
whir;h iR the :='ITea unoer the curve: see figure 8.1 r ~ sing the irle:='l. of R.re:='l,R ,ve hRve
b
Figure 8.1: .Areas under f (x)
80n1e r111e for integr:='lJs
1. If a < c < b tllen ~ f(x)dx = ~ f(x)dx + J: f(x) dx
2 .. For a. constant C I'hcf(x)dx = cj'bf(X)dx
,a a
3. F'or tvvo functions f(x) and g(x) S: c (f(x) + g(x)) dx = J: f(x)dx+ S: g(x)dx
97
Mathematics for Com puter Scientists Chapter 8. Calculus
Perhaps the rnost ilnportant result about intcgration is the fundarnental theorCln
of calculus. It is easy to follovv, if not to pro\-'e, Suppose we have a function f(x)
and we dcfinc
F ( x) = J: f ( t ) d t
Thcn
dF(x) = (f"f(t)dt) = f(x)
dx dx. a
In ot.her woroR integration iR rRther like t.he reverRe of oifferentiation. vVe neerl t.o
he a bit ulTeflll RO rlefine F(x) ;;tR tlle primiti'lif: of f(x) if
dF(x) = f(xl
dx .
So log; x is a prilniLi ve [or l/x ,JS is log x + 23. The prirnit i ve is nornH.tll}' called Lhe
indefinite integral Jf(x)dx o[ f(x) and is defined up to a constanL so Jf(x)dx =
F(x) + constant
If t.he limit.R of the integration exist: say a ;;md b then ,ve h8ve the rlefinite
iutegral
J
b
a f(x)dx = F(b) - F(a) (8.2)
\Ve can o[ course spend tilne looking at [unctions \vhich dilTerenLia.Le Lo \vhat
vve wallL. .\onnally however we use htbles ( or Ollr nIeITlOr}') So
f(x) F( x) = f f(x)dx
xn (n -# -1) xn/(n + 1)
l/x
logx
exp( ax) exp(ax)/a
log x xlo(f X - X
C>
aX
a
X
/ log a
sin(ax) -cos( ax)/a
r;oR(ax) sin (ax)/a
1/Ja
2
- x
2
sin-
1
(x/a) (-1 < x < a)
1/(a
2
-x
2
) htn-
1
(x/a)
Example
1. f x
2
dx = + constant
2. x
2
dx = [x
3
/3] = - (-2)3/3 = (27 + 8)/3
3. f
0
= 1 / xdx = [log x j l) = log 1 0 - log 1 = 2.3 0 ... - 0
4. = = sin-
1
(1/2) - sin_l(O) = 71/6
98
Mathematics for Com puter Scientists Chapter 8. Calculus
Exercises
Evaluate the following; integrals and check your solutions by difIerenLiaLing;.
1. J x
3
dx
2. f 1/x
2
dx
3. f(25 + x
2
)-1 dx
Evaluate
1. f ~ log xdx
2
f
2 -3j2d
. 1 X x
;3. f!U( 0
2
+ X
2
)-1 dx
99
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
Chapter 9
Algebra: Matrices, Vectors etc.
The hwnan,m'irul has 'IM:.'ve1' -invented a labor-saving Tflach'ine t'([ual
to algrhra
Al1thor Unkno\vn
\Ve now 111eeL the ideas o[ 'trW,! rices and veclo'rs. \\lhile they rnay seern raLher
odd at first they etre vital [or sLudies in ahl10sL all subjects. The easiest \/.,'e\ly' to see
tl18 power of tl18 ideR iR to c;onsider Rirnllltan8011R eCj11:='1,tions. 811PPOR8 \ve hmre th8
Ret of 8Cjl1:='1,t i on R
3x - 51:1 12
x + 5y 24
\Ve can find Lhe solution x = 9 1J = 3 in seventl vvays . For exa.ll1ple i[ \Ve add
Lhe second equation 1,0 the first we have equations
4x 36
x +51:1 24.
Tll11R X = 9 :='I,no RllbRtitllting (j in t h8 R8cono eCj11:='1,tion giv8R 9 + 51:1 = 24 or
51J = 15 giving 1J = 3. rvIany rnathcrnatical rnodds result in SCtb of siIIlllltancout:l
equationt:l, like thesc exccpt Inuch Inore cOInplex \vhich need to be or pcr-
haps just Lo be exa.ll1ined. To do this nlOre eetsil)' the rna.Lrix WetS invented. The
essence of Lhe set o[ eq ua.Lions
3x - 5y 12
x + 51:1 24
is captured in the array or matrix of coefliroients -:;;5) or the Q,uqmcntrr]
. (3
1natru 1
-5
5
10
2
) These array" of 1111mbers are (aJled matrire". To save
100
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
spa.ce we often gi ve nw..trices na.Ines in boldface: for exa.Inple
or
x = ~ ~ 5 i ~ ~ ) .
\Ve oefine an r x c mRtrix as ;1 rectRnglllar array of nnmbers with r rOvVR ;;md
c colunmb, for exarnple A above ib a 4 x 3 Inatrix \vhile X is 2 x 4 is
A rnatrix \vith jUbt one colurnn ib called a column 'uedo.,. vvhile one \vith jUbt
OIle row is a row cedor, for exarnple a. colUlnn vector
U= U)
and d, ro\v vector
b = (3 -5 12 -19)
\\Fe Ube Inatrices in \va.ys vvhich keep our links vvith systerns of equations. Before
looking d.t the aritlnIletic of rnatrices \ve see how \ve can Ube thern to corne up with
a gelleral Inethod of sol ving equations.
9.0.5 Equation Solving.
If you \vere to look at \va.ys people use to solve equationb you would be able do
deduce SOIne bilnple rules.
J _ EqnationR can he rnllltipled hy a non-7.ero c;onst;:'I,nt
2. Equatiollb can be interchanged
3. Equations can be added or subtracted to other equations
If equd.tions are lIlanipulated following thebe rules they Inay look different but they
hace the sa'rne sol'utions a.s \vhen you btarted. \Ve can bolve equations by \vriting
the coeflle:ients in the aayme'nte(lmu,t1'ix forn1 and Inanipulating as follo'vvs
J _ ro\vs of the rnatrix m8Y be interdlangeo
2. ro\vs of the rnatrix Inay be InulLiplied by a nonhero constant.
101
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
:3. rows can be added (or subtntcLed ) 1,0 (1'1'0111) other rovvs
Our airn is to reduce the rna.Lrix 1,0 \\.'ha.L is knov,,'n as row echelon form. This 111ecUlS
that:
the leading non zero tenn in each row is a, one.
Also the leading 1 in Lhe firsL row lies to the left of tha,t in the second ro\v
and RO on. 1\:Iore preciRely t he 1 in ;:'I,ny row lies to the left of the
leading onAR in all the rOvVR helo\v it.
For example
-5 12 1 -5 12 0 1
o 24) or (0 1 24) or 0 0
(
1 1
00 001 00
The reabOll for this \vill becorne appaTent \vhen vve do it.
Lds tr,Y it out: \Ve start vvith the equations
2x + 1) + 2z 10
x - 21) + 3z 2
-x+y+z 0
ill thit:l case the cocificicntb arc
( i,
\Ve are allowed 1,0 rnanipulate rows, Lhese are anu operal:iml.8, to Lry and get 1,0
the row echelon [onn. Thus v,.'e have
I. Add row 2 t.o row:j t.o ( 1
1 2
y)
-2
3
-1 4
(
1 3 -1
n
2. Subt.ract ro,v 2 from ro,v 1 to get 1
-2
3
0 -1 4
Subtract row 1 from row 2 (
3 -1
)
'J
-5 4
,),
-1 4
102
Mathematics for Com puter Scientists
11. Tidy to get ( ~
3 -1
5 -4
1 -4
Olapter 9. Algebra: Matrices, Vectors stc.
5. Subtract:) tirnl'b ro\v ;3 frorn ro\v 2 to get (
0
1
~ ~ 1
8
6)
1 -4 -2
6. Interchange rows 2 and 3 (00
1
~ =! !2)
a 16 16
(
1 3 -1 8)
7. Tidy ~ ~ ~ 4 ~
This SAernR morA like ro\v Achelon .
Thib labt rnatrix COITl'bpOnds to the set of equations
x + 3y - z 8
1:) - 4z -2
z
These are 11111Ch easier to solve! IIere
z = 1 1:) = 2 x = 3.
103
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
It. iR often nicer to go a hit further ano get rid of as mnch of the npper triangle
ab possible. Clearly the leading 1 in each row can be ubed to get zerOb in the
colurnn above it. The resulting rnatrix ib called reduced row echelon form of the
original rna.Lrix. lIere we get
(

=! !
2
) ---1 ---1
01 1 0011 0011
It. ooeR really m;:ttter a gre;;\J. oe;:tJ to lIR vvllidl ,ve lIRe Rince we are only interesteo
in RolutionR.
Lds look at another exarnple
6x + 3y + 6z 9
x + 21} = 16
4x + 5y + 1z 18
The auglIlented fornl is
(:
:)
6
)
J
2 0
5 1
\Ve h8ve

9 ) C -9 6 -27) C
2 0
;
2
6 ----7 1 2 0 6 ----7 0 3 -2 1
451 1 0 -3 1 -6 0 3 -1 -6 0 0
SonIC :::;teps have been concatenated!
What can go wrong
In reality nothing 1l1uch can go wrong buL v,,re need to exarnine ct couple or cases
\vhere the reslIlt.R we ohtain reC]uire Rome t.hOlIght.
1. Suppose \ve elld up \vith a ro'l.1) of ;;eros. This is no problern, except \vhen
the rllllnber of llOll-zero rOWb is less that the nurnber of variables. Thib just
llleans there is noL an unique solution e.g
x+ 21} - Z 0
x+z 3
2x + 2y 3
104
0
;, )
-2/3
1
-.:)
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
\Ve 11i1VP,
(l
2 -1
+ .. (
1 2 -1 0
)
U
2
-6 )
0 1 0 1 -2 "' -----7 1 -1

-.:)
2 0 0 0 0 0 0 0
This corresponds to
x+y+z -69
y-Z= -3/2
Now there is a solution [or these equations bu t it is not the explicit unique
t.ype we have heen dealing \'lit.h n]1 to novv. If z iR kno,vn, RAy tllen it.
follo\\'R x = 3-z
o
and y = (2zo-3)/2. \Ve hAve a Rolntion fOf every vAIne.
Technically there are an i'njinitc nurnbe-r cf solutions. It is obvious if you
think about it that if you have fevver equations than variables (llnknovvns)
then .you \'lill not have a sirnple bolution.
If we have 2 ro\'lS all zero then \ve have to give d, vdl11e to hvo if
then ;3 variables and so on.
2. No Solllt.ion
Of COllrRe yonf eCjni1.tions mAy not. hRve a Rolntion in that they i1,re c:.ontra-
for exmnple:
x = 1 1) = 3 x = -2 z = 16
\Ve recogni:;r;e t.he eCjllRtionR are ( hAve no Rolntions at all ) in
t.he follo\'ling \'lAy. lfwr: ha?h' a row (;f whirh is all ,".::r:TO e.reept fOT the venj
last ele-rncnt then the equations }u//ue no sol-ution. For exarnple:
Suppose \Vc have the equationb
x - 21) - 3z
2x+ cy + 6z 6
-x+3y +(c-3)z= 0
,vhere c iR Rome conRtant.. \\7"e proc:.eed to ro\'l er;helon
( i
1
-2 3
U
-2 3

c 6 c+6 0
:)
c-3 1 c J
105
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
Before we go fnft11ef \vhat 11;:'\'P1)enS if c = -67 The miridle row of our matrix
correspondR to 0=4 vv11id1 is nonsenRe. Thus the origin;:d eqnation Ret rioes
not have a solution when c = -6
However we will just carryon
( !1
-2 3
D (
-2 3
D
(
-2 3
c 6 0 c+6 2c ---t 0 0 2c - c(c + 6)
3 c-3 0 1 c 0 1 c
C -2
3 1
)
U
-2 3
D
-----101 c 0 -----1 1 c
o 0 2c - c(c + 6) 6 0 -4c - c
2
Now if -4c - c
2
= 0, t11:='1t is c = 0: or c = -4 onf 1:='l,Rt eqnation is 0 = 1
which ib dearly nonsense! This rneans that the original equatiollb had no
solution.
You Illay feel LhetL this is a, bit of a sledge heuluner to crack a nul" but Lhere is
a real IJurpose to our exercise. If you Inove avvay [ronl the trivial cases then the
sdlellle we have outlined above is the best approach. It is etlso the Lechnique use
in t11e c;ompnter pfogr:='lJl1S avail:='l,hle for eqnation Rolving. In the shape of
the fedllceo fO\V echelon form tell ns a lot :='I,hont matrices. Often \ve have a Ry-Rten1
of eqwltions \vhere \ve have SOIne pararneters e,g, using our techniques d,bu'le we
GUl find the range of values: or perhapb the valueb thernsdveb \vhen solution:::; dTe
p0:::;:::; ible,
The row elirnination ideas v,re have outlined are knov,.'ll etS GU;(lss'iau. elhniu.a{:iou.
in llUlllerical circles. The algoriLhnls which beetr Lis neune, \\.'hile ver}' Inuch slicker
:='ITe h:='l,Red on these sinlple ideas.
106
1
)
4
0
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
Exercises
1. SolvA
(a)
2x +3y 7
5x-y 9
(b)
x+3y +3z 1
2x+Sy + 7z
-2x - 4y - Sz
(c)
v-w-x-y-z 1
2v - lV + 3x + 4z 2
2v - 2lV + 2x + y + z 1
v+x+2y+z 0
(0.)
w + 2x - 3y - 4z 6
w+3x+y - 2z 4
ltv + 5 x - 2y - 5z 1 0
2. Consider the equations
V-lV-X-y-z 1
2v-w+3x+4z 2
2v - 2w + 2x + y + z
v+x+2y+z c
For vVll:='tt valuAs of c no tllASA ACtU8tiol1R hmre a UniCj11A Rolution: Are t hArA
:=,my v;:dllAS of c for \vhic:h tllAre is no solution?
107
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
9.0.6 More on Matrices
If we have cUI n x rn lllatrix A "ve need SOHle \\.'c't,y of referring to a, pa,rLicular
elel11enL. It is (:0l11111on 1,0 refer to the (in tll elernent 111ectning the elel11enL in ro"v
i Rnd column j _ \VA think of tllA mAtrix as 118ving tllA form
Q11 Q12 Q 1,11.-1 Q111.
Q21 Qn Q2,11.-1 Q211.
A= a31 Q.E QJ,n-l a3n
cdots
Qm1 Q
m
2 Qm,n-1 um,n
If WA havA a typical ijt h elernAnt \ve RomAtimeR vvritA
TllA unit ma.trix iR an n x n matrix \vith onAS on t hA diagonal 8J1d 7.eros eIRe,vhAre,
usually written I for exmnple
~ n or U ! ! n
So A is 8, unit matrix if
1. It is square.
2. The elernenLs aij satisfy aii = 1 for all i and Qi.j = 0 [or all i -I- j
9.0.7 Addition and Subtraction
\:\7e (;(1.11 i:ldd or subtract rnatricl's that ha'ue the same dimensions by just adding or
subtrading the corresponding elernents .. For exa.lnple
(
all
a12 ) +
( b
ll
b
12
)
(
all + b 11 U12 + b 12
)
a21 a22 b
21
b
22 a21 + b21 U22 + bn
and
(
a"
al2 ) _ ( b
ll
bl2 ) = (
Q" - b"
a12 - b
12
)
a21 a22 b
21
b
22
a21 - b
21
U22 - b
n
(! ~ )
B = (
-4
-3 ) ( -3
-1
)
,vhAn A And -2
~ 1 thAn A + B = !
3
0
0
5
)
'.vhill' A - B = 5
5
108
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
IVlultiplication by a scalar ( nUlnber)
\Ve can nlUltiply a rnatrix A by ct nlllnber s to give sA vvhich is the nmLrix \vhose
elernents ;=t1'e tll0Re of A mnltiplieo hy S, RO if
all a12 a1,TL-1 a1n
021 all 2,TL-1 02n
A= 03rL
m1
Qm.2
m,n-l 01n,n
then
so"
S012 SOl,rL-1 Sa1rL
S021 SOn S02,11,-1 Sa2rL
sA= SOJl S032 S03,n-1 saJn
Sa
m
1 sa
1
n2 sam ,n-1 sa1n,n
\Ve use the Lenn !3c(tLm' [or quantities that are not vectors.
Transpose of a matrix
If \Vc hl,ke a rnatrix A and "vritc thc colunms as ro\vs thcn thc nc\v rnatrix is callcd
thc transpot:lc A writtcn AT or AI
Thus if A = (1\ 122 6) then AT = Notice that (A T)T = A.
Any lllaLrix that satisfies
is s;:'t.io to be symmeirir:. If
A=-A
T
tllen it is ;:'t,nti-symmetric:.
IVlultiplication of IVlatrices
This is a rather 1110re cOlnplicated Lopic. \Ve define Inultiplication in a ntLher
cOlnplex v,ray so that \Ve keep a connection \vith systerl1s of equcttions. Suppose A
is ;:'t,n n x p lYli1trix ano B is a p x nt rnatrix. Then the (ij )th element of AB iR
p
L aikbkj = all blj + ai2
b
2j + aU
b
3j + ai4
b
4j + ... + alp-l b p- 1j + aipbpj
1< 1
109
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
.:\ote tha.t AB is an n x rn Incttrix. One \vay of thinking; of ehis is to notice that
the (ij )th elell1ent of the product n1cttrix is Inade up b}' 111ulLipl}'ing elelnents in
the ith row of the first Inatrix b}' the corresponding elernenLs in the jeh COlUlllll or
tllA sAcono m;:ttrix. The proo.ndR arA then s111'nmeo..
examples
( 1
2 3) ( ! ) = 1 x 7 + 2 x 6 + 3 X 4 = 31
(
~ ) (1 2 3) = ~ ~ ~ ~ ~ )
4 4 8 12
(! 1
2
2) (i n
(
5 22)
28 124
Some conseqnAnc;eR are
-Yon C;:'\J1 only mnltiply matrices if they have the right dimensionR.
In general A B #- BA
AI =A
IA = A but I has different dirnellsionb to that above
AO =0
OA = 0 but 0, a. Inatrix of heros, has dilTerent dilnensions to thctt above
110
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
As we said the reason for this stntnge ideet is so Lhat iL Lies in vviLh linear
equations: thus if
x+2y u
4x+ 9y v
and
v+4y 3
2v-y 0
tllARe can he written in matrix form
ano
So we call write boLh e CeUl wriLe sysLerl1s of equetLions as one rna.Lrix equetLion
4
-1
BAx= (n
)(!
Tllis iR Axact ly thA RamA SAt of Aqnations ,VA ,,\TonIa h8ve h;;"o if ,VA h;:to Alirnin;:tted
U d,nd v \vithout ,m,Y rnatrices.
Inverses
So we have a, whole set of algebraic operations we can use Lo play \vith nletLrices,
excelJt v.'e have not dellned division since if we can rl1ulLiply Lhen \\rh}' not divide?
For ;:'I, ( nOn-7.Aro) nnmher Z ,"VA (;;:'I,n definA the invArRe z-l ,vhic;h s;:'Itisfies
ZZ-l = Z-l Z = 1 .
In the s,une ,"vav we sav that the rnatrix A has an inverse A -1. if there is d, rrld.trix
A -, \vhich .'
Beware not all IIlatl'ices have inverses! Those that do arc said to be non-singular
otherwise a rnatrix which does noL have an inverse said Lo be is singular. If you
111
Mathematics for Computer Scientists Chapter g. Algebra: Matrices, Vectors stc.
think about it you will see that only square matrices can have inverses. Suppose
A is an n x n matrix and B is another n x n matrix. If
AB =BA=I
where I is an n x n unit matrix then B is the inverse of A. Notice A must be
square but not all square matrices have inverses.
We can of course find the inverse by solving equations. For example
So
~ ~ ) ~ ~ )
(
ae+bg af+bh)
ce + dg cf + dh
we then solve the four equations .
ae + bg 1
af + bh 0
ce + dg 0
cf+ dh
Not a very promising approach. However we can use the row-echelon ideas to get
an inverse. All we do is take a matrix A and paste next to it a unit matrix I .
Write this augmented matrix as B = (AI).
We row reduce B to reduced row echelon form. The position of the original I
is the inverse. For example suppose A = (! ~ ) then
B = (AI) (1 2 1 0)
490 1
We get using row operations
(
1210) (12
4901 ----101
and the inverse is A -1 = (!4 ~ )
Of course we check
1
-4
112
9
-4
~ )
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
What can go wrong?
1. If you rnanage to convert the left hand rnatrix A to a unit Inatrix I then you
have succeeded.
2, Sornetirnes a.s }'OU rnanipulate the uugrnented rnatrix B you introduce a row
of zeros inLo Lhe position where )'OU placed A. In Lhis case you can sLop as
there is no 8ol'(llion.
Consider A = ~ ~ ~ ) . Tlle Rllgmented m;:ttrix iR B = ~ ~ ~ ~ ~ ~ o )
45045 1 0 0
Now using ro\v operations we have
(!
:)
6 1
o 0) ( 0
-9 6
-6 0)
0
0 3 1
-6 0)
J
2 0 0 1 0 ---i 1 2 0 0 1 0 ---i 2 0 0 1 0
5 1 0 o 0 0
:J
1 0 o 1
:J
1 0 -4 1 -J -J
U
2 0 0
1 0) C 0
0 -2/9 -3
4/3 )
---i 1 -1/3 0 -4/3 - 1 /3 ---i 0 1 0 1/9
0 1 1/3 2 1 0 0 1
1/3
grvmg 11S our inverse
(-2/9 -3 4/3 )
1/9 2 -1/3
1/3 2 0
(
6 3 6)
COllsider novv A = ! ~ ~ . The auglnenLed 11lctLrix is B =
Novv using ro\v operations ,ve have
(
6 3 6 1 0 0) (0 -9 6 1 -6 0)
1 2 0 0 1 0 ---i 1 2 0 0 1 0
480 0 0 0 0 000 0 0
Given the zero:::; vve kllO\V there is no inverse!
2 -1/3
2
(!
-1
361 0
2 0 0 1
8 0 0 1
Of cour:::;e vve can think of soh"illg equations using irrvcrsc rnatrices. It is d,hnost
cU ways beLLer 1.0 use ro\\' operations on the augrnenLed InaLrix but we CcUI proceed
as follows. If we have the equations
6x + 31} + 6z 9
x+2y 6
4x + 5y + z 18
113
~ )
Mathematics for Com puter Scientists
t hiR can he writtfm as
so
In general if
then
.---1.] A-1 .
prOVlue(1 eXIRtR.
(
-2/9
1/9
1/3
Ax=b
114
Olapter 9. Algebra: Matrices, Vectors stc.
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
SUlnmary
1. The transpose of A vvriLLell AT is 1,he nlct1,rix nw.de by vvriting the rov.'s of A
as col unlns in AT.
2. A is synnnetric if A = A T
;i. The zero matrix is the n X m array of zeros e.g ~ ~ ~ )
;1. The unit rnatrix I ( of order n) is the n x m rnatrix with 1 'b 011 the diagonal
;;mo 7.eros elsewhere e.g. ~ ~ ~ )
001
5. The nlct1,rix A has an inverse B ilI AB = BA = 1. B is vniLLen A -1.
6. A Inatrix \vhich has an inverse is said to be non-singular.
7. Do rernernber 1,hat excep1, in special cases AB #- BA
Exercises
L Givp-n A = ~ ~ ~ 1 ~ 1 ) Rnd B = 0 ~ ) rompntp- AB and BA
2. Sho\v tha.1o ( ~ , ~ 2 ~ ) is skew synnnetric.
-J -4 3
3. IfA= ( ~ 1 !: i) showthatA=A
2
4. Show tha.1o ABT = B TAT
5. Sho\v that the inverse of A B is B-
1
A -1
Find the inverRP- of ( 1
3
1 ) and (!
4
6. 2
6
5
2
5
115
3
~ 3 )
5
2
14
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
Geometry
We write thc point (x, 11) in thc plane as the vcctor X = ( ). If A is a 2 x 2
matrix Ax transforms x into a new point. Suppose A = 1{2) Then
1.
A(n=(n
2.

'J
IJ.
A( n = C{2)
4.
AC ) = e{2)
If we plot the /1 points and their transfonns \ve get
N -
[J
' ---,.
I I
I I
I I
I I
I I
,.... -
>. 0-
";"' -

-2 -1 0 2
x
9.1 Determinants
Considcr the matrix vVc ca:n show that this has an invcrse
when \7 = ad - be =1= bee g.O. 7. The quantity \7 is called the determinant of the
116
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
llw,Lrix A = and is wriLLen I lor del (A). Simibrly
has an inverse when
abc
d e f
9 h i
The general definition of a, deLenninanL of an n x n n1ctLrix A is as fo11ov.'s.
1. If n = 1 Lhen del, ( A) = all
2. if n > 1 Let Mij be Lhe delennin,anl of the (n-1) x (n-1) rnatrix obLa,ined
fr0111 A by deleting row i and colU111n j. Mij is called a, min,or.
ThAn
rt
det(A) = Ul1Mll-U12M12+UnMn-ullJMH+ ... (-1)rt+1UlrtMlrt = L(-1)i+1a1jM1j
i=l
DAtermin;:tntR arA pretty nasty but -VVA :='ITe fortun:='lte as -vve really only 11eed them
for n = 1) 2 01' ;3.
9.2 Properties of the Determinant
J. Any m:='ltrix A :='1110 its tranRpoRe AT have the same oeterminant: i.e. oet(A)=oet(A
T
).
:\ote: ThiR is useful Rince it implieR that -vvhene"ver -vve use ro,\'s, a sirnil:='lT
behavior \vill result if \ve use colurnns, In particular \ve \vill sec ho,v fO,V
elelIlentary operations are helpful in finding the deterrninant,
2. The detenninant (Of OUoa rnatrix is the product of the entries on the
oiago11al, that is e = uel
o
;), If \ve interchange tV{O rows, the deterrninant of the new rnatrix is the opposite
sign of the old that is
117
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
(

9 h i
Note Lh1.tL whenever you want to replace a, rovv by sOlnething (Lhrough ele-
nlentary do not rnultiply Lhe row iLself by 1.t conshtnL. Otherwise,
it is easy to rnake errors: see property 4
6. det(AB)=dct(A)dct(B)
7. A is invertible if 1.tnel only if deLlA) -I- O. Note in Lh1.tL case det (A -1 )=l/deL(A)
\Vhile detenninant s can be useful in geornetry and Lheory they are cOlnplex and
quite difficult to handle. Our last result is for cOlnpleteness and links nl1.tLrix
inverses wiLh detenninants.
Recall tl18t tlle n x n rnatrix A doeR not have 8,11 inverse \vhen net (A)=O. Hovv-
ever the connedion between netennin8,11tR 8,11d matrices iR more complex. Suppose
vve dcfine a nc\v Inatrix: thc adjoint of A say adj (A) as
(
M"
. i-l T -M21
(l,dJA = (( - 1 ) Mij) = , ..
(-1 pL+l MTLl
-M12
M22
(
-1)ll. 1M )T l,ll.
(
-11
TL
-
2
M,.
.
(-1 )2n M
Ttn
iT T !3) T
1 5 ... 1 -2 1 2 -3
\Vhy is 8.nyone interest en in the adjoint: The rnain reason is
A-1 = adjA
dct(A)
Of courbC you \vould havc to havc a vcry special rca.SOIl to cornputc an invcrsc this
wa)',
118
Mathematics for Com puter Scientists
9.2.1 Cramer's Rule
S11ppose we 118ve the Ret of eCju8tions
U1X + b(!-) + C1Z d
1
Q, b, c,
and let D = 02 b
2
C2
OJ b
J
CJ
Q2X + btl) + C2Z d2
Q3
X
+ b J1J + CJZ d3
Then Cramer' R rule stRtes that
d, b, c,
X=- d
2
b
2 C2
0
b
3 UJ C3
1
Q, d, C,
Y =- Q2 d2 C2
D
d
3 U3 C3
1
l
b, d
l
Z=-
02 b
2
d
2
0
b
J
d
J OJ
There is even a, nlOre general case. Suppose vve ba ve
Ax=d
Olapter 9. Algebra: Matrices, Vectors stc.
\vhere x T = (Xl! X2, ... ,x
n
) and d
T
= (d,) d
2
, ... ,d
n
), Let D =det(A).
Then
Xk = ~ ( ~
U'tk-ll
d
1 U'tk III
d
n Qn' QrL(k-lj QrL(k+l)
Ul
n
)
Q
nn
\Vhile this is a nice fonnula you \vould have to be Inad to UbC it to solve equatiollb
since the best v,ray or evaluating big deLenninanLs is b}' ro\\! reduction, etnd this
gi ves solutions directl}'.
Exercises
J. Evaluate
2 4
3 6
119
Mathematics for Com puter Scientists Olapter 9. Algebra: Matrices, Vectors stc.
2 4 3
2_
Eval118te 3 6 5
2 5 2
x 2
3_
Evah18te
)
2x+ 1 x
3
x-
0 3x-2 2
4. If A = (:
o 0 9
) show that
14
del(A) = I II
120
Mathematics for Com puter Scientists Chapter 10. Probability
Chapter 10
Probability
Probabil-ity theory 'is nothi'l/.Y bnt COTflU/D'l/. sense 're(hlCed to ca[c:ala-
fion.
Pierre Simon L;:'I,plac;e
In what. followR we are going t.o c;over t.he h;:'l,RiUl of prohahilit.y. The ioeaR are
reasonably btraightforward, ho\vever a.s it involves counting it ib very easy to rnake
rnibtakeb - ab we shall sec.
Suppose we perfortn an experirnent vvhobe out corne is not perfectly predictable
e.g. roll a, die or Loss a coin. Irnagine we rnake a, list of all possible ouLcornes, (all
Lhis list S Lhe sample space. So
If we Loss a coin S cOllsists of {lIead: Tail}, \\'e write S = {lIealL Tctil}:
If a princebb kisses a frog then \ve have two pObbibilities
S= { \ve get a. prince, \ve get an ernbarrassed frog}
\Vhell we roll t \,vo dice then S is the seL of pairs
(1,1 )
(2,1 )
(3,1 )
(4, J)
(i), J )
(f)))
(L2)
(2:2)
(:l2)
( 4:2)
(5:2)

(lA)
(2A)
(:3A)


(
(L5)
(2:5)
(:l5)
(


(1,6)
(2,6)
(:3,6 )
(4,6)
(5,6)
(fjJj)
An event A is a (ollecLion of outcOlnes of interest, for exa.lnple rolling 10\\'0 dice and
getting a double. In this case Lhe event A is dellned as
121
Mathematics for Com puter Scientists Chapter 10. Probability
A = { (1: 1 ) : (2: 2) , ( :),;) ) , ( 4,4) : ( 5: 5) : ( 6: 6) } .
SnpPoRe that tllA Avent B is that tllA Rum iR less th;;tt 4 when we roll two rlice, then
B={ (1,1),(1,2),(2,1)} .
If two events A and B have no elernents in conUI1on then v,re say the}' aremu['ualLy
p:rrlllsi'l!(. For eX8,rnple let A be the event {At le8st one 6} that is
Since A and B have no elernents in COIInI10n they are rnuLuall}' exclusive. Define
Lhe event C as
C={ (2,;3),(25,7)}
Then A and C ,HC also Irmtually exclusive. If D={tmrn cxceeds IO} then A and
o axe not lI1utually exclusive! Check this YO'(l'tselj.
COlnbining events
It is handy to have a s,yrnbol for not A, \ve UbC r.,. A but \VC are not 'vcry picky
and not A is acccptable.
The event A and B, often \vrittcn A rl B ib the bCt of OUtCOIrlCS vvhich belong
both to A etHci 1,0 B.
The event A or B; often \\'riLLen A U B is the seL of ouLCOlnes \vhich belong;
either to A or 1,0 B or to boLh.
Yon \vill recognise the notation from the e8Tlier disc;ussion on setR.
Sup}Jose S={O,L2;:14)\Q,7,8,9} then if\ve define A={1,:3,5,7,9} etnd B={4:5:7}
. .
\ve h8ve
A n B = A an rl B = {5,7}
\Vllile AU B = A or B = {l ,;),4,5,7,9}
122
Mathematics for Com puter Scientists Chapter 10. Probability
10.0.2 Probability - the rules
Now to Aadl Avent WA :='ITe going to Rssig;n a mAAsure ( in RomA vvay ) callAo thA
probability. \Ve will vvritc the probabilit,)" of an evcnt A as P[AJ. \Vc will set out
SOIne rules for the nw.in ones are u.s follows:
1. 0:::; P:AJ :::; 1.
2. P[SJ = 1
3. For InuLually exclusive events A and B P:A or BJ = P[A: + P[BJ
\Ve will ada a few extrR rulAR
(i) For mutu:='IJly exclusivA AVAnts A 1 Ana A2 ano A3 ... An thAn
or written oifferAnt ly
P[A, or A2 or A
3
or An"': = P[A,: + P[A
2
J + P:AJJ + ... + P[AnJ +.,'
(ii) For all evenL A
P [ not AJ = 1 - P :AJ
(iii) For Avents A ana B
P[A or B: = P[AJ + P:BJ - P:A and BJ
All this is (}, bit fiddle,)" but is not really vcry hanL If you vverc not too confused
at this point you vvill have noticed that v.'e do noL have a V .. 'cl}' or geLLing the
prolJalJiliLies. This is a dilTicult point excepL in Lhe case v .. 'e are going to discuss.
10.0.3 Equally likely events
Suppose that every outcoIne of Cl.n experirncnt is equally likely. Thcn \ve UUl shovv
rrOln Lhe rules alJove 1'01' any event A
'AJ = the nunlber of out COlnes in A
p. the nUlnber of possible outcOlnes
123
Mathematics for Com puter Scientists Chapter 10. Probability
This IIleans we can do SOIIle calculatiOlls.
examples
1. Snppose that the ontcomes
tl18t a baby is 8, girl
tl18t a baby is 8, hoy
8re eCj118,lly likely. Then RS there 8re t\VO possihle ontcomes "ve have P[girl]=] /2=P[hoy].
2. Suppose now a f8Tnily has ;) dliloren: the possihilities are
BB BG GB GG
etHci so P[ one boy and one girl]= 2/4=1/2 while P[tv.,o girls]=1/4
;3. The fanlOus shtListician R A Fisher had seven daughters. If }'OU C'OLlI1t the
possihle SACplenC;eR BBBBBBB to GGGGGGG yon \vill fino that there are
27 = 128. Only one seqnenc;e iR 8,11 girl so the prohahility of t hiR event is
]/128.
4. A pair of dice iR thrown. \\lhat is the prohahility of getting totalR of 7 ana
11, Suppose no\\' \\'e throv{ the t\VO dice t\vice. vVhat is the probability of
getting a total of 11 and 7 in this case'!
5. \Ve draw 2 balls frolIl an urn containing () \vhite and 5 bhl,ck: vVHat is the
}Jrobability that we get one \\'hite etnd one bIack betll?
As you ean see vve really need SOine help in counting.
ExercisesS
1. A }Joker hanu c'onsists of 5 cards drawn fron1 et pack of 52. \Vhat is the
}Jfobability tha.1o a hand is a slru;igh r tha.1o is 5 cards in nUlnerical order, but
not 8,11 of tlle S8Tne snit.
2. \Vl18t is tlle proh8,hility that a poker hand iR 8, full house, that iR 8, triple and
8, p8,ir.
3. A 8,no B flip 8, coin in tnrn. Tlle firRt to get 8, head wins. Find the s8,mple
space. \Vhd,t is the probability that A wins?
124
Mathematics for Com puter Scientists Chapter 10. Probability
4. The garne of craps is pla}'ed as 1'o11ov.'s: A player rolls tvvo dice. If Lhe sunl is
a, ~ ;3 or 12 he loses. If the Sllln is ct seven or cUI 11 he \\'ins. OLhenvise the
playAr rollR t.he dice llnt.il l1A gAts l1is initial s c o n ~ : in which case he wins or
gets :='1, 7 in whir;h U1Re he 10ReR. \Vh;:d, is the probability of "vinning?
,). A rnan has n keyb, one of \vhieh "vill open hib door. He trieb keys at ran-
dOIIl, discarding thobe that don't \vork until he opens the door. \Vhat is the
probctbility that he is successful on the kth try.
6. The birthday problenl lIow Inany people should be in a rOOIn Lo Inake the
proh;:thility of t.wo or more hRving t.he SRme birthdRY 1'nore th;:tn O.S? ThiR iR
Cjllit.e diffkll1t. ana a si1'npler approar;h is to c:onRirier t.he prohahility that. no
two people hRve tl1e S:='Ul1e birthday.
It is often a, useful dodge in probability Lo look at P[ noL A: vvhen P[A] is
11:='1,1'0.
So P [ no coincidences] =
365 x 364 x 363 x ... x (365 - n + 1)
365 x 365 x ... x 365
= 1 x (1-364/365) x (1-364/365) x (1-363/365) x x (1-(365-n+ 1 )/365)
Nunlber Probabilit),
125 0.7/1709S()8
16 0.716:39599
17 0.684992:3:3
18 0.65308858
HJ 0.62088147
20 0.58f356162
21 0.55fBIH)6
22 0.52 j]0'i()9
2;3 0./19270277
24 0.46165574
25 0.4:31:300:30
125
Mathematics for Com puter Scientists
Prob of coincident birthdays
:
00
6 -
6 -
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
o
000
I
10
I
20
I
30
I
40
I
50
number
10.0.4 Conditional Probability
I
60
I
70
I
80
Chapter 10. Probability
SOllletillle it is natural to htlk of the probctbility of an event A given sonle other
eVAnt has oCClllTed. \Ve "vrite the proh;:thility of A given B as P lA 1 B j ann nefinA
it as
Reillernber this is a fancy "vay of writing
P[A 1 B] = P:A and BJ
PlB
\:Vhile conditional probabilities can have interesting philosophic-al ill1plic-ations they
also allow one to do calculations. Thus
P[A] = P[A 1 B]P:B] + P[A 1--- B]P[", B]
or l110re generally if B1! B
2
) ... are the onl}' possibilities so Bi = 1 then
l1.
P[A] = L P:A 1 Bi]P[B
i
]
i=1
126
Mathematics for Com puter Scientists Chapter 10. Probability
127
Mathematics for Com puter Scientists Chapter 10. Probability
Exanlples
1. Consider the t able below.
Ernployed U nernployed Total
IVIale 400 40 500
FernRle 140 260 400
Total GOO 300 900
Then
P[ rvlale] = 500/900
P[ rvIale and Unelnployed] =/10/900
P[ - rvlale] =/10/500 = P[ Unernployed and rvlale] /p[rvIalC:
= /10/000 --;- 500/900 =/10/500,
2. SU}JPose we buy widgets fro111 :3 suppliers A,13 and C. They supply all pro-
ducLion and the 11ulnber of defedi ve itelns per bcttch as "veIl as their share
of our supply is gi ven below.
A
Proportion supplied
0.(-)0
Proportion defective 0.0]
\Vhd,t proportioll of \vidgets are defective'!
\Ve kllO\V
P[defed.iveIA] = 0.03
P[defed.ivel13]=0.0;3
P[defed.iveIC]=0.07
so using the fonnula \ve have
B C
Supplier
0.;30 0.10
0.05 0.07
P[oefedive: =P[oefediveIA: x P[A]+P[oefectiveIB] xP[B: +P[oefect.iveIC] xP[C]
So P[oefective] = 0,03 x 0.6 + 0.03 x 0.3 + 0.07 x 0.1 = 0.034
128
Mathematics for Com puter Scientists Chapter 10. Probability
10.0.5 Bayes
\Ve alRo Bayes Theorem
or
P[AIB] = P[BIAJP[AJ
P[BJ
P[AIB: IX P[BIA]P[A]
(10.1 J
(10.2;
Here :x 1'neanR eqw=d to h11t 1'n11ltiplieo by 8 c,onRtant.
Y011 will often fino t hRt Y011 c,;;m c:ompnte P I B j when re;=dlv von ,v;;mt
PlB I Aj. B8yeR theorem giveR yon the ll1e;;mR for tnrning one into the other.
Examples
J. Take tlle data in the example 2 above. \Ve kno\v that Pldefective I Aj=0.0:3
ano we f0l1l10 that P =0.0:34. Then Sl1ppORe ,ve pick 11p a defective
cOInpollent and ask \vhat ib the probability that it corne frorn A. Thus \ve
need P:A I defective].
\Ve (;8.11 11Re Bayes to give
P[A I defective] = P[defective I A:P:A]/P[defective]
= 0.03 X 0.6/0.34 = 9/17 = 0.529.
2. SnpPoRe tl18t the proh8,hility that a person h8,R 8, oiRease P j = 0.01. A teRt
it:) available vvhich ib correct 90% of the tirne. If \ve use Y to denote that the
test it:) positive and .--... Y negative \ve rnean
P:YID: = P[.--... YI .--... D] = 0.9
:\o\v the probability of a yeb is
P[Y] = P[yID]P[D] + P[YI .--... D]P[.--... D] = 0.9 x 0.01 + 0.1 x 0.99 = 0.108.
The Inore interesting case is
P[DIY] = = 0.009/0.108 = 0.0833
129
Mathematics for Com puter Scientists Chapter 10. Probability
Exercises
1. An insnrance hroker believes th;:'\J, :='t qnartpr of o.rivers are aceioent prone.
\Vhat is Inore the probability of an accident prone driver Inaking a clairn
is 1ri while for a non accident prone drive the probability ib 1/5. \Vhat is
the probability of a dairn'? On his way horne the broker sees that one of his
custorners has driven his car into ct tree. \Vhat is the probabilit}, that this
custorner is accident prone?
2. An nrn cont:=tinR 4 rea ano. 0 green hRllR. One ball iR dnrwn :='d n'mo.om ana
it colonr ohserveo. It iR tllen ret11rneo to the 11rn :=,mo. ;) n8vV h:dls of the
saIne colour are added to the urn, \vhich nO'\v contains 13 balls. .A becond
ball is now drawn frorn the urn.
(a) \Vhat ib the probabilit,y that the first ball dravvn \Vab green?
(h) \Vhat is the proh:thility of getting a red hall gi?}p17. the first h:dl onnvn
was greell
( c) \Vhat iR tlle probability of getting a green hall in the sec;ono dnnv?
3. Sometirne nseo by nnRcrnpnlons stnoents of proh:thility -
\Ve hAve 3 utros. The first c;:tro has t\VO reO. Rio.es, the sec;ono t\VO bl;:tek sideR.
The reInailling card has one black and one red side. Othenvibe the cards are
idelltical.
The three c;ArdR are mixeo in a hat ana one earo. iR Relecteo. at n'mo.om :='m
placpo. on a table. If the exposeo side iR rea \vhat is the prohahility that the
hiddell side is black?
130
Mathematics for Com puter Scientists Chapter 10. Probability
Independence
If P[AIBJ = P[AJ thell \ve say A and B ctre independent. This is usuall}' v.rriLLen in
the equi valent forn1
Independent ib ver,Y ubeful and plays (}, central role in btatibticb.
10.0.6 Random Variables and distributions
If we c;onourJ ;;mo experiment ;=mo Ree ;;m olltcorne we alrnost ;=thV8YR cooe the
olltcorne in Rame vvay, RRy H:T for he;=to ;;mo tRil or even 0,1. The c;ooing iR knO\vn
a.s a. randorn variable, ubually written a.s a. capital buch ab X. If \ve tObb a coin \ve
can bU,Y that the out corne ib X. The actual values rnay be head: head, tail, giving
the sequence of vctlues of X as It II, T: .. \-Ve use randorn variables \\rhen vve have
prouauility distributions, that is lists of possible outcOlnes ctnd prouctuilities: sud1
as in the table
o
0.1
1 2
0.3 0.5 0.1
\Ve point Ollt that the Sllrn of the probabilitieR mURt he one, that iR L o P [X = kJ
\Ve oefine the ellmulati?h' distrih1dion funrtion (c.d..) F( x) aR the curnlllative Rum
of the probabilitieb
k
F(x) = .L P[X = kJ
x l)
So in tlle example above
k 0 1 2 3
P[X=k 0.1 0.:3 0.5 0.1
F(x) 0.1 0.4 O.Y 1.0
It is 1I1Ore usual to give a fornmla for a randorn variable: for exarnple
P[x = kJ = 0.3 X 0.r-
1
x= 1,2,3""
As the fonnula ib cOHnnonly shorter you can see why.
131
Mathematics for Com puter Scientists Chapter 10. Probability
10.1 Expectation
\Ve can also view probability fron1 the point of vievv of vvhat happens in the long
run. Given a randorn variable X define the expected vctlue of X v.'l'iLLen E[X] as
E[Xl = L = xl
(lUx.
The expeded value can be regarded as the Long r(l'l/. avenzye. So if v,re roll a. fa.il
aie and the Ollt.come iR X t.hen = i = 1/6 i = 1,2, ,61 ana so
-11
1
2
1
6
1
..,
E X = x (; + x (; + ... + x (; = .:>.5
You UHl he Rure tll:='tt if YOll roll a die YOll \vill never get ::L,), hOWf'?}fT if YOll rolled
a die and kept an average of the score you \vill find that thib \vill approach see
the plot bclovv
0

.....
=
0
M

cP
=
M
w
0)
rn o.n
W N
0 0>-
m
0)
= c:
'E N
2
.....
0
=
o 20 40 60 80 100
no rolls
For a. coin \ve have Head and Tail. Suppose we count head as 1 and tail as zero,
then
P[X = 1J = 1/2 and P:X = 0: = 1/2
ana so E = 1 x 1 + 0 x :l = A similar experiment gives the following
132
Mathematics for Com puter Scientists Chapter 10. Probability
I"--
a
0
0 0
c.o
00
0
0
o ~
~
~
0
0
u 0
V)
(])
-<::t: 0)
0
~
0
(])
>
C? (1J
0)
0
~
c:
"!
c:
2
0
..-
0
0
0
c>
0 20 40 60 80 100
no rolls
10.1.1 Moments
SOllle inl}JorLant expec-Led values in statistics are the l1/.otru:,ul.s
I1-r = E[XI']
r = 1 )2""
since ,ve can lls11811y esti1'nate theRe \vhile proh;=thilitieR are much 1'nore difficult.
Yon vvill 11Hve met tlle
m.f'(w. ~ l = E [Xj
The 'Lim'iauu:, (J2 = E[(X - 11-)2:.
The pararneter () is knovvn a.s the standard deviation.
Tlle c;entral mo1'nents are defined as
r = 1,2, ...
The third and fourth rnornentb E[(X -11-)3],E:(X -11-)1J: (U'e less eorrnnonly used.
\\-'e ea.n pIove i:U} interebting link bet"\veen the rnean 11- and the variance 0'2, The
result s kno\vn as Chebyshev:s inequaliL}'
(10.3)
This tellb Ub that dep(}Tture frorn the rnean have srnall probability when 0' is srnall.
133
Mathematics for Com puter Scientists Chapter 10, Probability
10.1.2 Some Discrete Probability Distributions
\Ve shall rUll Lhrough sorne of the 1110sL COIIllIlOn and irnportant discrete probability
dis t ri bu tiOllS,
The Discrete 1) niform distribution
Suppose X can take OIle valueb 1) 2) ... ,n \vith equal that ib
1
PlX = kj =-
n
The Hleal1 is E:XJ = TL;-l
k = 1,2
"
" , n
Lhe vctriculCe is var(X) = + + in -
(10.4 )
For example a oie is tllro\vn: the oistrihlltion of the sc;ore X is uniform on the
integer J to 6,
The Binomial distribution
Suppose we have a. series if trials each of vvhich hab t\VO outcorneb, :::;UlTCSS S i:l,Ild
failure F. vVe aSSlll11e Lhat Lhe probctbiliLy of suc'c'ess, P: is c'onshtnL, so for every
trial
Pl Snccessj = p ;:'I,nd Pl fRilure j = 1 - p
e the prolJalJility of X successes in 11 Lra,ils is gi ven by
k=0,1)2,n (10.25)
Tlle meRn is = np
thc Vi:l,rii:l,flCC is "Tar(X) = np( 1 - p)
The IJrobability LhaL a person \vill survive a, serious blood disectse is 0.4. If
15 IJeople have Lhe disease the nUlllber of survi vors X has a, 13inornial 13( 15,0.4)
distribntion.
P [X = 3J = c:) ( 0.4 ) 3 ( 0.6) 12
P[X ::; 8J = (0.4 )X( 0.6) 15-x
P[3::; X::; 8J = P[X::; 8: - P[X:=; 2: = 2 C:)(0.4r(0.6)1!l-X
134
Mathematics for Com puter Scientists Chapter 10. Probability
Applying expectation using the Binomial
A Inore interesting usc is:
Suppose we wish to test wheLher N people have ct disease. It \vould SeelI1 that
Lhe only way 1,0 do Lhis is 1,0 Lake a blood Lest, v/hich v/ill require N blood tesLs.
Snppose WA try the following:
1. \Ve pool t.he hlood of k < N people.
2. If t.he combined s;:trnple is neg;:ttive ,ve have k people vvit hOllt. t.he diRease.
~ i If the pooled test is pot:litive vve then test all k people individually, retmlting
in k + 1 tet:ltt:l ill all.
"'1. Repeat until everyone it:l diagnosed
\VhaL does this save us'?
135
Mathematics for Com puter Scientists Chapter 10. Probability
Assnrne the probabilit:y of 8, person hmring thp, oise8,Re iR p ana that we h8ve a
Binornial dibtribution for the nurnber with the disease. Then for a group of k
1. Pl jnst J teRt = (1 - p) k
2. P[ k+ 1 tests] = 1 - P[ jUt:lt 1 test] = 1 - (1 - p) k
So the expected nurnber of tebtb is
Thib does give a cOllbiderable buving in the rnunber of see the diagrarn belo\v
OJ


J
..-'
-
-
p=
0.1
k
p=
0.001
0
0
_ 00
.0 000

0
a
0
111 1,.,
The Hypergeolnetric distribution


-
I
=
.rl
-
-
p=
0.01
p=
1e-04
0
0
0
_ 00
[a
caoo

0
Cl
1() 1;-'
SnppoRe \ve have :'\ itemR and D of theRe 8Te oefedive. I take a Rample of n
from tllese itemR, then the probability th8t this sample contains k oefediveR is
(
N-D) (D)
P [X = kJ = n-l< k

k = 0, 1,2, ... n (10.G)
The lIleall is E[X: =
1
. . (X) (N-nJ D (1 D)
t le vanance IS vax = (N-l :; n N - N
\\-'hile sit nations involving the lIypergeorneLric are c-onlIIlOn ii COIIllnon practice Lo
approxirnate \\'iLh Lhe 13inornial \vhen N is large cornpared Lo D. \Ve set p = DIN
<1.110 Rue
PiX = kJ = _ p)N-k k = 0,1,2"" n
136
Mathematics for Com puter Scientists Chapter 10. Probability
The Poisson distribution
Suppose events occur at randOlll
k = 1,2, , n (10.7)
The mean is ElX = A
tlle variance is var(X) = A
The average nUlnber of oil tankerb arriving per day at a port is 10. The facilities
at the port can handle at Inost 15 arrivals in a day. \Vhat is the probability that
the port will not be able to handle all the arrivals in a day? The variable X is
Poissoll A = 10 so
IX: lOx 15 lOx
P[X> 16J = -exp(-lOi = 1 - -exp(-lOi = 1 - 0.9513
- L xl ' L xl '
x=16 x=O
137
Mathematics for Com puter Scientists Chapter 10. Probability
10.1.3 Continuous variables
All the eases we have considered so feu' have been vvhere X ta,kes discrete values.
This does not have to be true - we CeUl irnagine X t etking a continuous set of values.
SInce we have tll011gh of :='t probability 8t X=k vve rnight think of the proh.:thility
of X being in Rome Rrnall interv;:tJ x, x + 8x This lwobability will he
< X < x + 8xl = f(x)8x
The function f(x) is called the probability density [unction.
8x
--
3.0
2.0
1.0
\
x
The as can be seen fr'oIn the sketch is Inade up of and if \ve add
these together we get a probability.
Persollally I find it sirnpler to think of the curnula.Live distribution function
F(x) v.'hkh is dellned as P:X :::; x: = F(x). This is just et probabilit}, etnd is what
yon fino in tableR. \Ve re];:tte thiR to the oenRity fnndion by
F(x) = ['" f(t)dt
It iR then not diffir;nlt to sho\v that
P[a < X < b = J: f(t)dt
Typical shetpes are
138
Mathematics for Com puter Scientists Chapter 10. Probability
density function
.........
><
ct'.!
-
E
0
a
c:
q
-0
0
-3 -2 -1
0 1 2 3
x
distribution function
.........
I

CX)
E
0
L-
a
c:
q
a.
0
I I
-3 -2 -1
0 1 2 3
139
Mathematics for Com puter Scientists
10.1.4 Some Continuous Probability Distributions
Unifornl Distribution
Here X is unifolTllly distributed on a, range, sc\y' (a, b) so
1
f(x) = b - a
It follows t.hat. F(x) = PlX < xj = lx-a :='mo Pk < X < dj = ld-C
I-ll 1-(\
Tlle mean is = Qi
b
the vctriculCe is var(X) = (b - a f
TlliR iR a nsefnl mooel for :='t 1'anoo1'n choice in he interval froma t.o b.
Exponential Distribution
Here X is distributed on the range (0) 00) and
f(x) = A exp( -AX)
Chapter 10. Probability
(lO.iS)
( 10.9)
where A is a constant. It follo\vs that f(x) = P[X < xJ
P[c :; X :; d] = exp(Ac)1 - exp(Ad)
- exp(Ax) and
The llleall is E:X] = *
the variance is var(X) = /1.
12
Normal Distribution
Here X is distributed Oll the range (-00) 00) and
1 {(X -
f(x) = JhW2 exp - 2 2
, IT
(10.10)
The HleaIl is E :XJ = J.!
the v:=t1'i;:tnr;e is var(X) = (J2
The nonnal distribution cropt:; up all over the place the probleln is that there it:;
no silnple "vay of working out the probabilities. They can be cOlnputed but you
either need the algoritlun or tables.
140
Mathematics for Com puter Scientists Chapter 10. Probability
N orInal Cornputation
Suppose X has a Norrnal distribution with lIlean 1-1 and Vctrictnce (}"2: often \\.'riLLen
N (1-1) (}"2). \Ve can show that X is rehtted to a, Slo;nda'rd Normal vctrictble z, Llw,t, is
z is lV ((). 1) by
And of course we have the reverbe
x -
Z=--
IT
(10.11)
(10.12)
:\ow the standard nonnal is what is given in the tables do we convert our
prohlem int.o a st<=tnoaro on8.
I. SnpPos8 X iR lV (100,9
2
) Then
(a) P[X:::; 70J = P [z = x-
9
WO :s; :::; -3.33J = 0.004
(b) P[X:::; 95J = P [z = :s; :::; -5/9J = 0.2893
(c) P[X 2:: 109J = 1 - P [z = 2:: 109
9
100 2:: 1J = 1 - 0.2893
(d) P[70:S; X:s; 109J = P:X 2:: 109: - P[X:::; 70J = 0.7017 - 0.004
SUPIJOSe vve wish to llnd the vctlue a so that P [X :::; oJ = 0.95. Then
X-IOO 0-100.
P[X> a] = P[z = > z = = 0.9
- 9 - 9
Fl'Olll htules = 1.645 and so 0 = 100 + 1.645 x 9
Another example
SUPP0i::lC vve kuo\v
1. P[X < 2J = 0.05
2. P[X> 14J = 0.25
So we have
PlX < 2j = = (X - I-..l)/u < (2 - I-..l)/uj = 0.05
ana so fro1'n t.ahles (2 - = -1.645
\Ve dlso have P[X > 14J = 0.25 or
PlX < 14 = PlZ < (X - < (X - I-..l)/uj = 1 - 0.25 = 0.975
lIenee (14 - 1-1)/IT = 1.96 \Ve have a pa,ir of equations
141
Mathematics for Com puter Scientists
1. 2 - I-l = -0- X 1.645
2. 14 - I-l = 0- x 1.96
Solving gives
(14 -I-t) - (2 -I-t) = 12 = 0.3150-
or 0- = 3.32871 and so I-t = 7.475728
The N ornlal approxirnation to the Binornial
Chapter 10. Probability
A 13illOll1ial vctrictble X which is B (n) p) can be apprOXill1a1,ed b}' a, :.\ onnal va,riahle
Y, 11lean np. varia.lKe np(l - p). This can be very useful as the 13illOll1ial 1,ahles
provioeo RTB not very extensive. This is known 0.8 the lVormal apPTo:n:moho17. to
the Rinomi(JL
In tllis CRse
z = (Y - np)/ J(np( 1 - p))
is st;;mdard NormaL
Excunple
SUPIJOSe X is nurnber of 6:s in 40 rolls of a die. Let '{ be :.\ ~ \ 4 i ~ ) . TheIl
5 - 20/3
P[X < 5J ~ P[Y < 5J = P[z < . J5679 J = <!J( -0.7071068) = 0.2398
, 50/9
You can refine thib approxiInation but \ve "vill bettIe for this at the rnornent.
Exercises
1. A die is rolled; \x,rhat is 1,he probahili1,}' that
(a) Tlle ol1tc;ome is even.
(0) The outC'OllIe is a, prirne.
( c) The 0 u t C'Olne exceeds 2.
(d) The outcolIle is -1.
(e) Tlle ol1tc;ome is leRR tl18Jl 12.
2. T\vo dice are rolled. \Vhat is the probability that
(a) The SUIn of the upturned faces ib 7'!
(b) The score on one die is exactly twice the score on the other.
142
Mathematics for Com puter Scientists Chapter 10. Probability
(c J You thro\v a double, that is the dice each have the SHIne beore.
3. Suppobe we toss a coin ;3 tinleb. Find the probability distribution of
(a) X=the nUIIlber of tails,
(b) Y = tlle number of nms. Here;:'l, run is a Rtring of or tailR. So for
HTT Y=2,
;1. The student population in the rvraths departIIlent at the niversity of San
Diego \vas rnade up ab follo\vs
10% were frOI11 California
6% \vere of Spanibh origin
2(7r: were fron1 California, and of Spanish origin.
If;:'l, Rtuoent from the d;:'l,RR vvas to be oravvn ;:'It ra11o.o1'n ,vhat iR the prohahility
that they are
(a) FroIn California or of Spanibh origin.
(b) .\either frol11 California, nor of Spanish origin.
(c) Of Spanish origin but not fr'oIn California
143
Mathematics for Com puter Scientists
5. FbI' two event.s A and 13 the follov.'ing probabilities are kno\vn
P:A] = 0.52
Determine tlle probabilitieR
(a,) P[A n B]
(h) Pl"" A
(c) [ ~ BJ
P:B] = 0.36 P:A u B: = 0.68
Chapter 10. Probability
6. A hospihtl Lrust dassilles a group of Iniddle aged Inen according Lo bod}'
weigllt and the incjoence of hypertension. The reRults :='ITe gi'ven in the table.
() ver\veight Nonna'! \Vcight l ~ ndcnveight Total
IIypertensi ve 0.10 0.08 0.02 0.20
Not HypertenRive 0.15 0.4;) 0.20 0.80
Total 0.25 0.53 0.22 1.00
(a) \Vhat is the probability that a person bclectcd at randorn horn this
group will have hypertension?
(h) A perRon seledeo at ranoo1'n from this gronp iR founo to he overvveight:
\vhat is the prohahility that t hiR person is :='IJso hypertensive?
(c) Find P)l.YI)('rtensivc U Undenvcight:
(d) Find P )wperLensi ve U Not U ndervveight]
7. T\vo cardR :='ITe orav{n from an ordinary deck of 52 C:='ITOS. \Vhat iR the proh-
ability of dru\villg
(a,) Two aces.
(h) Tlle two hlack :='I,ces.
(c) T\vo ulTds froIn the court cards KJl,.J
( a) Four cardt:l arc aceb
(b) Fbur cards are the sarne Le. 4 10's, 4 9'2 etc.
(c) All the C:='ITOS :='ITe of the Rame snit.
(d) All the card are of the sarne suit and are in sequence.
144
Mathematics for Com puter Scientists Chapter 10. Probability
9. A Rtudent. of st.atistics "vas t.old t.hat. tllere \vas a chance of 1 in a million that
there wab a. bornb on an aircraft. The reasoned that there would be a one in
10
12
chance of being two bornbs on a plane. He thus decided that he bhould
take a bornb with hirn ( defused - he vvas lloL st upid) 1,0 reduce Lhe odds of
an ex plosioll.
Assurning no securit.y problcrnb is this a bensible strategy?
10. There arc four ticketb rllunbered 1),;3,.-1. A two digit nurnber ib fonned by
drawing; a ticket at randorn frolll the four and a secolld frorn the relnaining;
three. So if Lhe tickets were 4 and 1 Lhe resulting; nurnber would be 41. \\7hat
is the probetbiliLy Lhat
(a) TllA rARulting nllmher is even.
(b) The resulting; nUlllber exceeds 20
( c) The rebulting rnunber ib bet\veen 22 and ;30.
11. Three production lines contribute to the total pool of parts ubed by a corIl-
pan,Y
Lille 1 conLributes 20% etnd 15(7r: of iLelllS etre defective.
Lille 2 contributes 50% and 5% of iterIlS arc defective.
Lille :3 conLributes 30% etnd 6% of iterns are defective.
(a) \Vhat. perr;entage of items in the pool :='ITe oefective?
(b) Suppose an iLelll was selected at ntndorn etnd foulld to be defective,
",,,-hal, is the probabiliLy LhetL it c-a.lne frolll line I?
(c) Suppose all itelIl "vas bclected at randorIl and found not to be defective,
whaL is the probabiliLy LhetL it c-a.lne frolll line I?
145
Mathematics for Com puter Scientists Chapter 10. Probability
10.2 The Normal distribution
This table gi,ies the cumulative probabilities for the standard
lIor1l1al d1stribllt1(11) thHt is
P[Z S zJ = -= exp( _x
2
j2)dx r 1
yl2n
This is the shaded area in the figure.
L
?; 0.00 -0.01 -U.U2 -0.04 -0.05 -0.00 -0.7 -O.OD
-3.'1 0.0003 0.0003 0.0003 0.0003 0.0003 0.0003 0.0003 0.0003 0.0003 0.0002
0.0005 0.0005 0.0005 0.OUU4 U.0004 (.1.0004 0.0004 0.0004 0.0004
-3.2 0.0007 0.0007 O.OOOG O.OOOG O.OOOG O.OOOG O.OOOG 0.0005 0.0005 0.0005
-3.1 0.0010 0.0009 0.0008 0.0008 0.0008 0.0008 0.0008 0.0008 0.0007 0.0007
0.001 ;) 0.001 ;) 0.0013 0.0012 0.0012 (.1.0011 0.0011 0.0011 0.0010 0.0010
-2.9 0.0019 0.0018 0.0018 0.0017 O.OOlG O.OOlG 0.0015 0.0015 0.0014 0.0014
-2.8 0.0026 0.002.5 0.002-'1 0.0023 0.0023 0.0022 0.0021 0.0021 0.0020 0.0019
-2.7 0.00:)5 0.00;)4 0.00;)3 0.0032 0.00:)1 O.O();)O 0.0029 0.002S 0.0027 (.1.0020
-2.G 0.0047 0.0045 0.0044 0.004:1 0.0041 0.0040 0.00:19 0.00:18 0.00:17 0.003G
-2.5 0.0062 0.0060 0.00.58 0.0057 0.0055 0.005.-1 0.00.52 0.00.51 0.00-'18 0.0018
-2.4 O.OOSO 0.007S 0.0075 0.007:) (.1.0071 0.00ti9 O.OOtiS 0.0000 0.00ti4
-2.:) OJ)107 0.0104 0.0102 o.omm O.OODti 0.00D4 0.0091 0.00S7
-2.2 0.0139 0.01:16 0.01:12 0.0129 0.0125 0.0122 0.0119 0.0116 0.011:1 0.0110
-2.1 0.0179 0.017--1 0.0170 0.0166 0.0162 0.0158 0.01.5'1 0.01.50 0.01-'16 0.0113
-2.0 0.0222 0.0217 0.0212 0.0207 (.1.0202 OJ)197 0.0192 O.OlSS 0.01
-1.9 0.0287 0.0281 0.0274 0.0268 0.0262 0.0256 0.0250 0.0244 0.02:19 0.0233
-1.8 0.0359 0.03.51 0.031-'1 0.0336 0.0329 0.0322 0.031-1 0.0307 0.0301 0.0201
-1.7 0.044ti 0.04;)ti 0.0427 0.041S 0.040D 0.0401 0.();)92 0.0375 (.1.0307
-1.6 0.0548 0.05:17 0.0526 0.0516 0.0505 0.0495 0.0485 0.0475 0.0465 0.0455
-1.5 0.0668 0.06.5.5 0.06.-13 0.0630 0.0618 0.0606 0.059-1 0.0.582 0.0571 0.0550
-1.4 0.079;) 0.077S 0.0704 0.074D 0.07:)5 0.0721 0.070S 0.0094
-1.3 0.0968 0.0951 0.09:14 0.0918 0.0901 0.0885 0.0869 0.085:1 0.08:18 0.0823
-1.2 0.1151 0.11:11 0.1112 0.109:1 0.1075 0.1056 0.10:18 0.1020 0.100:1 0.0985
-1.1 0.1357 0.133.5 0.13V1 0.1282 0.1271 0.1251 0.1230 0.1210 0.1180 0.1170
-1.0 0.15ti2 0.15;)9 0.1515 (.I. 14D2 (.I. 1409 0.144ti 0.1423 0.1401 0.137D
-0.9 0.1841 0.1814 0.1788 0.1762 0.1736 0.1711 0.1685 0.1660 0.16:15 0.1611
-0.8 0.2119 0.2090 0.2061 0.2033 0.2005 0.1977 0.19,19 0.1922 0.188;1 0.1867
-0.7 0.2420 0.2;)5S 0.2327 (.I. 22 Do (.I. 220ti 0.22;)ti 0.2200 0.2177
-0.6 0.274:1 0.2709 0.267G 0.2G4:1 0.2G11 0.2578 0.2546 0.2514 0.248:1 0.2451
-0.5 0.308.5 0.30.50 0.3015 0.2881 0.2816 0.2912 0.2877 0.28.-13 0.2810 0.2776
-0.4 0.:)44ti 0.:)409
(};);)72 0.;)330 0.3300 (.1.3204 (};)192 0.;)150 0.3121
-0.3 0.3821 0.378:1 0.:1745 0.:1707 0.:1G69 0.:1632 0.3594 0.:1557 0.:1520 0.:1483
-0.2 0.1207 0..t168 0.-1128 0.-1080 0.-'1052 0.-'1013 0.397--1 0.3936 0.3887 0.3859
-0.1 0.4002 0.45ti2 0.4522 0.44S3 0.444:) (.1.4404 0.4:)ti4 0.4;)25 0.42SO 0.4247
0.0 0.5000
146
Mathematics for Com puter Scientists Chapter 10. Probability
This table gives the cumulative probabilities for the standard
lIor1l1al distrilmt101I) thHt is
fZ 1 '
P[Z z] = f)"; exp( _x
2
/2) dx
--oc '\ 271
This is Lhe shaded area ill Lhe Iigure.
z 0.00 0.01 0.02 0.03 0.0'1 0.0.5 0.06 0.07 0.08 0.09
0.0 0.5000 0.5040 0.5080 0.5120 0.5160 0.5199 0.52;19 0.5279 0.5;119 0.5359
0.1 0.5398 0 .. 5''138 0 .. 5,'178 0.5517 0.5557 0.5.596 0 .. 5636 0 .. 5675 0.5711 0.5753
lL2 0.579:) U.5910 lU::i02ti lU::iOti4 0.ti10:) 0.ti141
0.;1 0.6179 0.6217 0.6255 0.6293 0.6331 0.6;168 0.6406 0.644;1 0.6480 0.6517
0.--'1 0.6.5.5--'1 0.6.5[H 0.6628 0.666'1 0.6700 0.6736 0.6772 0.6808 0.68'11 0.6879
0 .. 5 0.691.5 0.6950 0.6885 0.7019 0.705--'1 0.7088 0.7123 0.7157 0.7190 0.722--'1
lU::i 0.7257 lL 7291 lL7324 0.7357 0.7422 lL7454 0.7517 0.7549
0.7 0.7580 0.7611 0.7642 0.7673 0.7704 0.77;14 0.7764 0.7794 0.7823 0.7852
0.8 0.7881 0.7910 0.7839 0.7867 0.799.5 0.8023 0.80.51 0.8078 0.8106 0.8133
0,9 Sti (JS2:)S lJ.S2ti4 15 (JS3ti5 0.S:)S9
1.0 0.841;1 0.84;18 0.8461 0.8485 0.8508 0.85;11 0.8554 0.8577 0.8599 0.8621
1.1 0.86--'13 0.8665 0.8686 0.8708 0.8729 0.87-'19 0.8770 0.8780 0.8810 0.8830
1.2 (JS907 0.S9D7 0.9015
1.;1 0.90;12 0.9049 0.9066 0.9082 0.9099 0.9115 0.91;11 0.9147 0.9162 0.9177
1.,'1
0.0192 0.9207 0.9222 0.8236 0.9251 0.926.5 0.9278 0.9282 0.8306 0.8319
1.5 0.D;);)2 0,9;)45 lUJ357 0.9370 lU);)94 lUJ40ti lUJ41S 0.942D 0.9441
1.6 0.9452 0.946;1 0.9474 0.9484 0.9495 0.9505 0.9515 0.9525 0.9535 0.9545
1.7 0.9554 0.9564 0.9573 0.9582 0.9591 0.9599 0.9608 0.9616 0.9625 0.963;1
1.8 0.06--'11 0.96,'18 0.9656 0.866,1 0.9671 0.9678 0.9686 0.9683 0.8600 0.8706
1.9 0.D71 ;) lUJ719 lUJ 72 ti 0.97:)2 0.D744 lUJ750 lUJ75ti 0.97til 0.97ti7
2.0 0.9772 0.9778 0.9783 0.9788 0.979;1 0.9798 0.980;1 0.9808 0.9812 0.9817
2.1 0.0821 0.9826 0.9830 0.883,1 0.9838 0.98-'12 0.98-'16 0.9850 0.885-1 0.8857
2,2 lUJStiS (J9S71 lUJSS4
2.;1 0.989;1 0.9896 0.9898 0.9901 0.9904 0.9906 0.9909 0.9911 0.9913 0.9916
2.,'1
0.0918 0.9920 0.9822 0.8825 0.9927 0.9929 0.9931 0.9832 0.883;1 0.8036
2,5 0,9940 lUW41 0.994:) 0.DD45 0.D94ti lUm4S lUW49 0.9951 lUHJ52
2.6 0.995;1 0.9955 0.9956 0.9957 0.9959 0.9960 0.9961 0.9962 0.9963 0.9964
2"" ./ 0.096.5 0.9966 0.9867 0.8868 0.9969 0.9970 0.9971 0.9872 0.8873 0.807--'1
2.8 0.097-'1 0.9975 0.9876 0.8877 0.9977 0.9978 0.9978 0.9878 0.8880 0.8081
2,9 lUmS2 lUWS2 lUWS5
;1.0 0.9987 0.9987 0.9987 0.9988 0.9988 0.9989 0.9989 0.9989 0.9990 0.9990
3.1 0.0990 0.9981 0.9881 0.8891 0.9992 0.9992 0.9992 0.9882 0.8803 0.8003
;),2 lUm93 0,9994 0.99D4 0.DDD4 0.D994 0,mm4 lUW95 (J99D5 0.9DD5
;1.;1 0.9995 0.9995 0.9995 0.9996 0.9996 0.9996 0.9996 0.9996 0.9996 0.9997
3.--'1 0.9997 0.9987 0.9887 0.8897 0.9997 0.9997 0.9997 0.9887 0.8897 0.8998
147
Mathematics for Com puter Scientists Chapter 11. Looking at Data
Chapter 11
Looking at Data
It is very much more difficult to handle data rather than to construct nice probability
arguments. \Ve begin by considering the problems of handling data. The first questions
prOVE-nla1}(;p. of tIlE-l data.
Is it rp.lia,bh-l?
\Vho collected it?
Ie; iL w haL iL is said Lo be?
Is it a srlmplp. rlnd frolll \vIlat population?
Such questions are inlportant because If the data is wrong no amount of statisticaL theory
'/1,"ill Tf/,(],k:p 'it lwttpf', Colh-lding YOllr O\Vll drltc-l, is tbE-l rlS you sll()llld knO\v \vhrlt is
going on. AlmosL all sLatistical Lheory is based on Lhe assumption thaL Lhe observaLions
are independent and in consequence there is a large body of methodology on sampling
alld drlta (;ollp.ctioll.
11.1 Looking at data
Once you have Lhe data vvhat is he nexL sLep? If it is presenLed as a Lable ( do read
the description) it may well be worth reordering the table and normalising the entries.
Silllplifyi11g amI rOllnding call p.spE-lcirllly ill rE-lports.
data, iL pays to look at Lhe daLa in as many \Nays as possible. Any unusual or inLeresUng
patterns in the data should be flagged for further investigation.
The Histogranl
Anyone \vho does noL dra\v a picLure 01' their daLa deserves all the problems LhaL they
'-vill undoubtedly encounter. The ba.,ic picture is the histogram, F'or the histogram we
split tbE-l rallgE-l of drlta i11tO intE-lrvrlls a11(1 COll1lt nll1llhE-lr of ohsE-lrvi-l.tions i11
148
Mathematics for Com puter Scientists Chapter 11. Looking at Data
interval. VVc thcn construct a diagrmn Inadc up of rcctangles crccted on cach intcrval.
ThE-l a'f'P(]. of tllE-l rE-lctallg1E-l proportiOllii,1 to thp. COllllt.
110 190
5,)
65 4:3 ]5 40 :32
11
;1 ..t 7f) 28 12 15 37
19 70 12 17
.",
,),.) ,19 If)
150 29 18 21 60
,13 2" ,.) ;3()
22 11 26 29 82 6 21 64
84 7;3 54 44 82 16 95 29
30 27
8,)
')r.
.. h) 5 22
,)2 ]9
18 17,) 10 20 29 Hi Hi 20
17 6 47 130 1 ]5
')'""'
IJ ( ,)0 ]7
..tl 61 116 55 67
2() 251 9
50
..t;3
80 52 17 22 28
8 27 ;32 75 10 45
Table 11.1: Dorsal lengths of octapodt:l
Histog..-a.-n of' oct:

=
,I


-
() 1 (ll) L(H)
oct
11.1.1 Summary Statistics
LocaUon This he; of Len called Lhe measure of cenLral in our texLbooks, or the
of Lhe daLaseL in oLher sources. Common measures of location are the
mcan and nlcdian. Lcss comnlon meW31HCS arc thc modc and thc truncated nlcan.
Giwm obsE-lrvrlti01IS Xl) X2, ... ) Xn
Thc sample mcan isjust 1 Xi. writtcn x. For thc Octopods it is ;H.67021.
Thp. H1E-ldirln is thE-l llliddlp. ValllE-l, WE-l armngp. tbE-l obsE-lI"vatlolls 111 oniE-lr ii.lId if
n he; odd pick Lhe middle one. If n he; even Lhen \\Ie take Lhe average of the
two middle values. For thc Octopods it is 32.5
149
Mathematics for Com puter Scientists Chapter 11. Looking at Data
A trllllcatE-ld H1P.<1.1I i:-; dip. 11JE-lrHl of rl dat<1. :-;E-lt whp.rp. :-;01JJE-l ]rlrgp. or :-;111<1.11 (or
bOLh) observaLions have been deleLed.
As you might expect the lllcdian is much less influenccd by outliers - it is a robust
P.:-;t i 11 I i1J P..
Histogram of oct
-
l.O
-
'"
=
'"
-
:>-..
U

c:

cr
CJ)
r--
U:::
;=
l.O
rn
=
I I I I I
0 50 100 150 200
ocL
Example
ThE-l Allstm]irl1l TIllrp.i1,1l of lVIdp.orology col1E-lds (htrl 011 ri1j1lfall rlcross Allstra]irl.
Given belO\v is Lhe mean monthly rainfall in Broken Hill a..c; 'well as Lhe median
monthly rainfall.
Average l\lonLhly n ainfall in Broken Hill (in millimeLers) 1900 Lo 1990
J\IonLh l\lean J\Iedian
.Tan 2;1 9
Fp.b 24 10
l\1ar 18
!)
Apr 19
!)
J\Iay 22
I")
d
.Tun 22 15
.1111 17 15
Aug 19 17
Sep 20 12
Od 25 15
"KOY 19 10
Dp.(: 20 7
150
Mathematics for Com puter Scientists Chapter 11. Looking at Data
(a) _\Jotc that thc median monthly rainfall is January is much smaller than thc
ll1E-lrH\ 111011tll1y rai1lfrllL \Vhrlt dOE-ls this illlply ahollt t hp. sllapp. of tlle distri-
bution of Lhe rainfall data for the monLh of January'!
(b) \Vhich measure of cenLral Lendency, Lhe mean or Lhe is more ap-
propriate for dcscribing rainfall in Brokcn Hill? Justify your answer using
knmvlp.dgE-l of ll1E-lrln amI lllE-l<iiall.
(c) UsP. tllE-l ahovE-l ti1hlE-l to caknlaJ,E-l thp. total YE-larly minfall for Orokp.ll Hill.
(d) In Lhe norLh of the \-veL season occurs from Novelllber to April.
Broken in central is occasionally drenchcd by a northern
stOrlll dllrillg t hp.sE-l months. TllE-lsE-l storllls tE-lnd drop rl Irlrge rlmOllnt of raill
in a comparaUvely short Lime. How does the Lable reLled this facL':
Spread This is Lhe amount of variaUon in Lhe daLa. Common measures of spread are the
sample variance, standard dcviation and the interquartile rangc. Lcss common is
tllE-l mngp.. Thp. traditionrll ll1E-lrlSnrE-l is tllE-l s(Jmplf'- '(7(].rimu'p
TL
,2 1 L - 2
t> -- (xi-xl
n '
i 1
and dip. squarp. root of tllE-l srlmplp. variiUlce kllO\Vll rlS t hE-l .c.;tando:rd (if:v-{ohon
For the odopods s=:1G.OGlf>9. AlLernaLi ves are:
The range This is delined as
range = largcst data value - smallest data value
tllis is obviously not vp.ry rolmst iUld llencE-l is not OftE-lll nSE-ld wllicll is a shrlmp..
InLerquartile Range The inLerquartile range Q:1-QL \vhile simple in concepL, has caused much
grief to introductory statistics teachcrs sincc differcnt rcspectable sources
dHfille it in different rp.spE-letahlE-l WrlYs! First WE-l find tlle lowp.r qllrlni.lE-l Ql
Lhis is the k = (n/4)th of Lhe ordered observations. If k is not an integer 'vve
take the intcger part of k plus 1 othcnvise \ve talw k+ 1. Thc upper quartilc
Q3 is obtrlilled by cOll1ltillg dmvll from t hE-l nppE-lr E-llHI of tllE-l ordered srlmplp..
This is a good robusL mea..c;ure of spread. For Lhe Odopods Q;1-Ql= 59.25
-18.00 =10.25.
151
Mathematics for Com puter Scientists Chapter 11. Looking at Data
Shape
The shapc of a datasct is commonly categorized a.., symmctric, right-skcwed
or bi-lllodaL TllE-l :-;hi1PE-l is ;1,11 importallt frldor informing tllE-l dE-lcisions on tIle best
measure of location and spread. There are several swmnary mea...c;ures. The sample
third InOlnent
mcasures skc\'lness-it is zero for a SYll1l11ctric distribution. The fourth moment
gives a flat top mea..,urc. It is 3 for a normal variable!
Outliers
Outliers are data values that lie mvay from the gcneral cluster of other data values.
Erldl olltlim' lIE-lE-lds to bE-l eXrlminE-ld to dE-ltE-lrlllillE-l if it rE-lpn-;sellts ;1, possiblE-l va.1uE-l frolll thE-l
population being sLudied, in \Nhich case it should be reLained, or if iL is non-represenLaLi ve
(or an error) in "\vhich case it can bc cxcludcd. It may be that an outlicr is the most
importallt fe;1,tllrE-l of a dataset. It is said t hrlt the 07.011e llOle rl hOVE-: tIlE-: SOllth Pole llad
bE-lE-ln detE-lded by a srltE-lllitE-l YE-lrlrs bE-lfore it "\Vl-l . '-\ dmectE-ld by gToll1}(1-hrlsed ohservations)
buL the values \vere Lossed ouL by a compULer program because Lhey \-vere smaller Ulan
\'lcrc thought possible.
Clustering
Clustering in1plies that thc data tends to bunch up around certain values.
Granularity
Granularity in1plics that only ccrtain discrete valucs arc c.g. a company may
ollly prlY srl],uies in mllltiples of 1 )000. A dotplot sllm'ls gmnnlarity rlS strlcks of dots
separaLed by gaps. DaLa LhaL is discreLe onen shovvs granulariLy because of its discreLe-
ness. ConLinuous daLa can show granulariLy if the daLa is rounded.
11.1.2 Diagrams
ThE-lrE-l is lII11ch to be si1,id for driPNillg pidllres. It is liard to illli1,gillE-l ii, di1,ta sm \vhE-lrE-l i1.
histOgTiUlI is lIot nSE-lfll1. If YOllr c01IlImtE-lr progTiull does lIot dri1w pidllres t hE-:ll replrlcE-l
iL! I rather like Lo Sl1lOoth the hisLogram Lo geL an idea of Lhe shape of Lhe p.d.L
l\ote hm'lever ,ve nced to takc care evcn \'lith the humble histogram! Ideally a
histOgTiUlI shollld show the slH-tpe of the distrilmtioll of the drlta. For somE-: dati1,sets 1mt
152
Mathematics for Com puter Scientists Chapter 11. Looking at Data
the choice of bin \vidth can hmre a profound effect on how the histogram displays the
(hbL
SteIn and Leaf charts
If YOll an-l hI a COl IlplltE-lr-fn-lE-l E-lHvir01l1llmlt a stE-lm-a1l<1-lml.f plot call hE-l a quick a11 E-lffp.ctivE-l
way of drawing up such a charLo ConI,ider Lhe daLa belO\v
stem
2
3
4
5
'27
37
,17
leaves
789
0123456789
0123456789
0123456
'2g
38
,18
2D 30
;)1 ;)'2 :):) :)4 :)5 36
39
,-to --11 --12
,13 ,1,1 ,15 /'16
,-t9
50 .51 .52 53
5,1
55 56
freq cum freq
3 3
10 13
10 23
7 30
Such a stem and leaf charL is valuable in giving an appro.x.imaLe hisLogram and giving
the ba.,is for some interesting data summaries. As you can see it is fairly ea.,y to find
tllE-l rallgE-l m.c. frolll thp. stmll iWeI Ip.i1f Cbiut.
Dotplots
A tmditi01H1.1 dotplot rE-lsE-lmblp.s r1 stE-l1Ilplor. lyi11g on its bc1,ck) with dots mplr1cillg tbE-l
values on Lhe leaves. H does a good job of displaying Lhe shape, location and spread of
the distribution, as \vell as shmving evidence of granularity and outliers. And for
slIlallisb dati1,sds r1 dotplot is E-lc-l..'-'Y to c01lstrllct, so r.11E-l dotplot is a piuticnlr1rly va.111a.blE-l
tool for Lhe sLaLisLics sLudenL vvho is \-vorking wiLhouL technology.
Box-Plots
A.llOLher useful pid ure is Lhe box ploL Here \ve mark Lhe quarLiles Ql Q2 on an axis and
drmv a box viTllOse ends are at these points. The ends of the vertical lines or
indici1JE-l tbE-l minimlllil amI llli1,ximlllll dati1, ValllE-ls) llnlE-lss olltliE-lrs r1rE-l prp.SE-lllt i11 \vllidl
ca..c;e the whiskers exLend Lo a maximum of 1.5 Limes Lhe illter-quarLile range. The points
outside the ends of the \vhiskers arc outliers or suspected outliers. can be very useful,
E-lspE-lcir111y vdlml llli1,king COl Ilpi1,ris01 IS.
One drmvback of boxplots is that they tend to empha.,ize the tails of a distribution,
\vbicb arE-l tllE-l IE-lr1st Cp.rtai11 poillts ill tbE-l di1Ja sd. TIIE-lY r11so bidE-l mr1ny of thp. ddr1ils
of Lhe disLribuLion. Displaying a histogram in conjundion \vith Lhe boxploL helps. BoLh
arc nnportant tools for exploratory data analysis.
153
Mathematics for Com puter Scientists
a
II)
a
=
=
II)
Octopod Boxplot
o
o
o
o
11.2 Scatter Diagram
Chapter 11. Looking at Data
A common diagram is the scaLter diagram 'where \ve plot x values againsl y values. \Ve
illustrate thc idcas '\vith hvo cxanlples.
Breast cancer
In a 19G5 repOrL Lea discussed lhe relationship bel'ween mean annual temperat ure and
the mortality rate for a type of brea..,t cancer in '\vomen. The subjccts '\vere residcnt.s of
certain regions of Grcat and Swcdcn. A simple regression of mortalit.y
011 tE-nnpm'i1JllrE--l shmvs ii, strong rE--llar,iollsllip t hp. two varii1,bh-ls,
Data
Data contains the mean annual tempcraturc (in dcgrces F) and rvlort.ality Indcx for
llE-lopla.'nlls of r,bE-l fmnrl]p. Di1Jrl wp.rp. frolll rp.giolls of Gmrlt TIritail1,
Konvay, and S\' . .:eden. )Jumber 01' cases: IG Variable )James
1. I\/fortalir,y: illdE-lx for of fP.1I1i1JE-l brp.i1,st
154
Mathematics for Com puter Scientists Chapter 11. Looking at Data
ity
102 .. 5 51.3
104.5 49.9
100.4 50
95.9 49.2
87 '18.5
9.5 '17.8
88.0 47.3
45.1
46.:)
8'1.6 '12.1
81.7 '11.2
72.2 43.f)
65.1 42.:)
40.2
67.3 31.8
52.5 ;14
0
a
0

- 0
0
0
0 -
en 0
0
0
0
1:: 0
0
0
00
-
0
E
0
0
-
r-
0
0
0
0 -
(!)
0
I I I I
35 40 45 50
temp
155
Mathematics
for
Computer
Scientists
Gareth J. Janacek & Mark Lemmon Close

S-ar putea să vă placă și