0% found this document useful (0 votes)
101 views421 pages

M Foundations

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views421 pages

M Foundations

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 421

Mathematical Foundations

for Computer Science


Katarína Bachratá, Hynek Bachratý, Iveta Jan£igová, Monika Smie²ková

May 29, 2019


ii
Contents

Introduction x

Abbreviations xii

1 Combinatorics 1
1.1 Lecture overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.1 Rules for counting . . . . . . . . . . . . . . . . . . . . . . 1
1.1.2 Pigeonhole (Dirichlet) principle . . . . . . . . . . . . . . . 8
1.1.3 Brief review of related concepts . . . . . . . . . . . . . . . 10
1.2 Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.3 Problem set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.3.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 16
1.4 Lab problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
1.4.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 31

2 Number theory 39
2.1 Lecture overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
2.1.1 Divisibility . . . . . . . . . . . . . . . . . . . . . . . . . . 39
2.1.2 Primes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.1.3 Common divisors . . . . . . . . . . . . . . . . . . . . . . . 43
2.2 Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
2.3 Problem set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
2.3.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 51
2.4 Lab problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
2.4.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 59

iii
iv CONTENTS

3 Automata and Turing machines 65


3.1 Lecture overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
3.1.1 Finite state automata . . . . . . . . . . . . . . . . . . . . 68
3.1.2 Turing machines . . . . . . . . . . . . . . . . . . . . . . . 72
3.2 Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
3.3 Problem set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
3.3.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 80
3.4 Lab problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
3.4.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 94

4 Mathematical logic 101


4.1 Lecture overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
4.1.1 Logical statements and operators . . . . . . . . . . . . . . 101
4.1.2 Quantiers and predicate logic . . . . . . . . . . . . . . . 105
4.1.3 Language of mathematics . . . . . . . . . . . . . . . . . . 105
4.2 Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
4.3 Problem set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
4.3.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 115
4.4 Lab problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
4.4.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 124

5 Number sets 135


5.1 Lecture overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
5.1.1 Natural numbers N . . . . . . . . . . . . . . . . . . . . . . 135
5.1.2 Integers Z . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
5.1.3 Rational numbers Q . . . . . . . . . . . . . . . . . . . . . 139
5.1.4 Real numbers R . . . . . . . . . . . . . . . . . . . . . . . 141
5.1.5 Complex numbers C . . . . . . . . . . . . . . . . . . . . . 143
5.2 Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
5.3 Problem set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
5.3.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 151
5.4 Lab problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
5.4.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 163

6 Sets and set theory 173


6.1 Lecture overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
6.1.1 Historical context . . . . . . . . . . . . . . . . . . . . . . . 173
6.1.2 Current set theory . . . . . . . . . . . . . . . . . . . . . . 174
6.1.3 Properties of sets . . . . . . . . . . . . . . . . . . . . . . . 174
CONTENTS v

6.1.4 Number of elements and cardinality . . . . . . . . . . . . 176


6.2 Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
6.3 Problem set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
6.3.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 185
6.4 Lab problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
6.4.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 199

7 Relations and functions 203


7.1 Lecture overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
7.1.1 Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
7.1.2 Mappings and functions . . . . . . . . . . . . . . . . . . . 206
7.2 Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
7.3 Problem set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
7.3.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 213
7.4 Lab problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
7.4.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 231

8 Sequences 237
8.1 Lecture overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
8.1.1 Introduction and denition . . . . . . . . . . . . . . . . . 237
8.1.2 Basic properties . . . . . . . . . . . . . . . . . . . . . . . 239
8.1.3 Limits of sequences . . . . . . . . . . . . . . . . . . . . . . 240
8.1.4 Properties and calculations of limits . . . . . . . . . . . . 241
8.2 Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
8.3 Problem set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
8.3.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 254
8.4 Lab problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
8.4.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 266

9 Sums and products 275


9.1 Lecture overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
9.1.1 Sums . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
9.1.2 Products . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
9.1.3 Double sums/products . . . . . . . . . . . . . . . . . . . . 279
9.1.4 Geometric sequence and series . . . . . . . . . . . . . . . 280
9.2 Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
9.3 Problem set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
9.3.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 291
9.4 Lab problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
vi CONTENTS

9.4.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 306

10 Real functions  part 1 315


10.1 Lecture overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
10.1.1 Linear functions . . . . . . . . . . . . . . . . . . . . . . . 318
10.1.2 Quadratic functions . . . . . . . . . . . . . . . . . . . . . 320
10.1.3 Absolute value function . . . . . . . . . . . . . . . . . . . 322
10.2 Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
10.3 Problem set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
10.3.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 327
10.4 Lab problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
10.4.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 338

11 Real functions  part 2 345


11.1 Lecture overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
11.1.1 Cubic, polynomial and rational functions . . . . . . . . . 345
11.1.2 Rational functions . . . . . . . . . . . . . . . . . . . . . . 346
11.1.3 Exponential functions . . . . . . . . . . . . . . . . . . . . 346
11.1.4 Logarithmic functions . . . . . . . . . . . . . . . . . . . . 348
11.1.5 Trigonometric functions . . . . . . . . . . . . . . . . . . . 350
11.2 Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
11.3 Problem set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
11.3.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 356
11.4 Lab problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
11.4.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 369

12 Asymptotic approximations and proofs 373


12.1 Lecture overview . . . . . . . . . . . . . . . . . . . . . . . . . . . 373
12.1.1 Asymptotic approximations . . . . . . . . . . . . . . . . . 373
12.1.2 Proofs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
12.2 Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
12.3 Problem set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
12.3.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 388
12.4 Lab problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
12.4.1 Hints and solutions . . . . . . . . . . . . . . . . . . . . . . 400

Farewell 408
Bibliography 408
Introduction
The interconnectedness of mathematics and computer science is generally ac-
cepted as relevant and necessary, especially in the undergraduate curricula on
technical schools. However, this linking often remains in the form of general
statements and is not quite understood by the computer science students them-
selves. They sometimes feel that the mathematics they are required to study is
not relevant for computer science and is a nuisance in their studies. Oftentimes
in such cases, the problem is not the mathematics itself, but rather the content
selected and the way it is presented.
Still, the well known experts, such as Donald Knuth in his textbook [4],
consider teaching mathematics to future computer scientists and programmers
as extremely useful. Also in practice, it has been shown that it is not sucient
to add a mathematician to a team of programmers. To nd a good solution
to an informatics problem, we need more than a rudimentary appreciation of
mathematical recipes. Understanding the underlying mathematical concepts
can signicantly improve the work and eectiveness of the created solutions and
tools and in many cases can help spot errors and inaccuracies.
The inspiration for our teaching of mathematics for computer science was
an MIT course by Professor Albert R. Meyer [6]. In our own course, we chose
a lower diculty level to enable the rst-year bachelor' studies in computer
science also for students coming from high schools that do not primarily prepare
students for higher education. The problems in this textbook are typically at
the level of the senior year at high school, interspersed with more dicult tasks
and challenges for those who are familiar with the basics.
Our goal is not just to teach the students how to solve the problems provided
in this textbook. In addition to this, it is important that the students learn how
to approach a problem, how to discuss it with others, how to verify that a
solution (either one's own or somebody else's) is correct.
The topics and problems were selected in such a way that they show many

vii
viii CONTENTS

common concepts and analogies between mathematics and computer science.


This is the reason why every topic includes a set of problems meant to be
worked out using a computer and link both mathematical and algorithmic skills
of the students.
The book contains 12 chapters which represent the material covered in 12
weeks of semester  one chapter per week. Each chapter has four sections. The
rst one is Lecture Overview. It is not an exhaustive theoretical treatment
of the week's topic. We tried to avoid the traditional high formalism, which
sometimes makes the content incomprehensible for students, but rather the text
is provided in the form of notes from an introductory lecture. New terms and
ideas are explained as we encounter them and are denoted in italics.
The second section in each chapter is a list of Questions. The answers
to these questions should be clear after going through the lecture overview
and serve as a conrmation of understanding. We do not provide the answers
explicitly next to the questions, but recommend going back to the lecture text
for clarication, if needed. After answering these questions, a reader should be
ready to tackle the problems.
The Problem Set is meant for practice, to help the reader gain condence
in mastering the material and clear up ambiguities if there are any. It is not
meant to be read all at once, therefore we start with stating the problems and
then in the next sections we give Hints. These should only serve as inspiration
or kick-o points if the reader does not know how to start or how to continue
with a problem. The reader should follow the hints only to such extent as
minimally needed and then continue on their own.
We also provide more detailed Solutions for selected problems but reading
all the steps should be the last resort. We consider them almost unnecessary,
because reading the solutions cannot replace working out the problems but we
agree they can be useful for people who solved the problem and want to compare
the results. We also recommend working on these problems in groups with fellow
students. In our experience, this is very benecial for mastering the material.
The nal section in each chapter is called Lab problems. This is a second
problem set, structured similarly to the previous one. The dierence is that
these problems should be worked out on computer, mostly using Excel. The
choice of Excel over the option to work in some programming language, e.g.
Java or Matlab, was made for clarity. It allows us to focus less on the technical
solution and more on the mathematical concepts we want to demonstrate.
While we provide some introduction to Excel functions as we go, this is
not meant to teach Excel. We view Excel as a tool, which lets the reader
experiment. In these problems, it is often not sucient to create a particular
CONTENTS ix

Excel worksheet that does something, but it is necessary to use it to answer


(mathematical) questions. Again, the reader should attempt to create their
own solution before reading the hints and steps provided in the text, which
should only be read to the extent needed to for continuing.

Challenges
Throughout the text we have included boxes like this one. They contain
more advanced questions or more challenging problems. As a warmup, try
to estimate which chapters contain material that you know and in which
are you going to encounter new ideas.

With few exceptions noted below, the individual topics are self-contained and
in principle, could be re-arranged, but we recommend using them in the order
presented in the textbook. This order resulted from our experience teaching
the course in a few dierent ways. We have decided to use some concepts even
before they are formally introduced and only make them more precise later.
This can be seen for example with proofs, which are theoretically discussed at
the very end of the book. The reason behind this is that we wanted the students
to have some experience with proofs before we discuss them theoretically.
We want to thank our students who already took this course and iteratively
lead us in development of this material. We thank our colleagues who taught
the course with us and shared their experience. Our sincere thanks also be-
long to our reviewers who oered detailed constructive feedback that helped us
signicantly improve the manuscript. And nally, we acknowledge the support
of Ministry of Education, Science, Research and Sport of the Slovak Republic
(contract No. KEGA 052šU-4/2018).
We hope this textbook will be a helpful, to this day not very common,
crosslink between the worlds of mathematics and computer science.
x CONTENTS
Abbreviations
AD = Anno Domini
FSA = Finite State Automaton
GCD = Greatest Common Divisor
IBAN = International Bank Account Number
ID = IDentication
LCM = Least Common Multiple
PC = Personal Computer
RSA = encryption algorithm developed by Rivest, Shamir, Adleman
TM = Turing Machine
XOR = eXclusive OR operator
ZFC = ZermeloFraenkel set theory with the axiom of Choice

xi
xii CONTENTS
Chapter 1

Combinatorics

1.1 Lecture overview

1.1.1 Rules for counting


Problem 1.1 Castles from blocks:
Suppose we want to build all possible castles using seven cube blocks while
respecting the following rules. 1. Castle has several towers in a row. 2. The
towers can have dierent height. 3. When looking at two towers that are next
to each other, a tower on the left cannot be smaller than the tower on the right,
see Figure 1.1. So going from the left to right, the towers stay the same or
decrease in height. How many possible castles are there?

Figure 1.1: Castles from blocks. a) Correct castle. b) Incorrect castle, because
the tower on the right is taller than the tower immediately to the left of it.

1
2 CHAPTER 1. COMBINATORICS

Solution: To solve this problem, we split it into smaller subproblems. We cal-


culate how many castles with seven oors are there, how many with six, all the
way to how many with just one oor. We add the results to nd out that there
are 15 castles. Alternatively, we could have split the problem by the number of
towers in a castle.

Good advice for solving problems


• If the problem is too dicult, split it into several smaller simpler problems.

• Often it is helpful to solve the problem for smaller numbers rst. Even if
it means writing out all the possibilities.

• When solving combinatorial problems by writing out all the possibilities, it


is useful to create some sort of system using which it will be clear whether
a given possibility has already been counted or not.

Addition rule
Let A1 , A2 , . . . , An be disjoint sets. Then

|A1 ∪ A2 ∪ . . . ∪ An | = |A1 | + |A2 | + . . . + |An |.

Here we see some notation that will be explained later in more detail. For now,
we simply say that set, e.g. A1 , is a collection of items, |A1 | says how many
items there are and ∪ denotes set union  two sets joined into one. Disjoint
means that every item can be only in one set. If two or more sets share an item,
this rule can no longer be used and we return to such situations in Section 6.1.4.
For our Problem 1.1, n = 7, A1 may denote the set of castles with just one oor,
|A1 | = 1 because there is just one such castle and |A1 ∪ A2 ∪ ... ∪ A7 | = 15.

Problem 1.2 Licence plates:


Licence plates have 6 to 8 characters. They have to start with a letter, but the
remaining characters can be either letters or digits. How many dierent licence
plates are there?

L = {A, B, . . . , Z}, C = {A, B, . . . , Z, 0, 1, . . . , 9}

Solution: Here we again have some new notation that will be revisited later
when we talk about sets. For now only briey: A×B denotes a Cartesian
product of sets. The result is a new set of ordered pairs. The rst item in the
1.1. LECTURE OVERVIEW 3

pair comes from the set A, the second from the set B . All possibilities are
included. A generalisation of this concept is An , where we repeat the product
operation several times, e.g. A4 = A × A × A × A. We write the solution to the
licence plates problem in this notation:

|(L × C 5 ) ∪ (L × C 6 ) ∪ (L × C 7 )| = |(L × C 5 )| + |(L × C 6 )| + |(L × C 7 )|

= |L| · |C 5 | + |L| · |C 6 | + |L| · |C 7 |


.
= 1.3 · 1012 .

Multiplication rule
Let A1 , A2 , . . . , An be distinct sets. Then

|A1 × A2 × . . . × An | = |A1 | · |A2 | · . . . · |An |,

where × denotes the Cartesian product.

Problem 1.3 Passengers on a bus:


a) 28 passengers have arrived at a bus station and formed a queue to buy
tickets. How many dierent queues are possible?

b) 28 passengers boarded a bus which has 40 seats. How many possibilities


are there for them to sit down?

c) 28 passengers exited the bus and nobody else has entered. In the 40-seat
bus, there are now 28 used and 12 unused seats. How many possibilities
are there to have 28 used seats out of 40?

d) How many possibilities are there to have 12 unused seats out of 40?

e) 28 passengers exited the bus at stops K, L, M, N, O. Leaving the stop O,


the bus was empty. How many possibilities are there for this to happen?
Note that this question can be understood in two ways. In one we care
which person got o at which stop, in the other we only care how many
people got o at each stop. Find both answers.

Hint: We solve the 28 passenger problem for 3 passengers rst. Let us call them
A, B, C. Using the second advice mentioned before, we write out all the possible
queues: ABC, ACB, BAC, BCA, CAB, CBA. Looking at this, we can formulate
4 CHAPTER 1. COMBINATORICS

a strategy. We start with one passenger, from the remaining ones we select one
for the second place and then put the remaining person at the third place. It
means we have 3 options for the rst place, 2 for the second and 1 for the third.
Altogether 3·2·1=6 possibilities. Can you now extend this to 28 passengers
and use similar strategy for questions b)-e)?

Problem 1.4 Passwords:


a) How many possible four-letter passwords can be created using four letters
of the word POKE? (The password must contain each letter exactly once.)

b) How many possible four-letter passwords can be created using four let-
ters of the word BOOK? Words BOOK and BOOK (two letters O have
switched places) are the same.

c) How many possible six-letter passwords can be created using six letters of
the word KEEPER?

d) How many possible ten-letter passwords can be created using ten letters
of the word BOOKKEEPER?

Problem 1.5 Codes with zeros and ones:


a) How many possibilities are there to place two 1s in a 4-bit word?

Solution: For one digit 1, we have 4 possibilities for placement. For the
other digit 1, we only have 3 (one is occupied), so at the rst glance it
might seem that there are 4 · 3 = 12 possibilities. However, the 1s are
identical (similar to letters O in the previous problem, part b)), so the
order does not matter and each possibility was counted twice. Therefore
the actual number of possibilities has to be halved, bringing us down to
6. We do not have to consider the placement of 0s now, because for each
placement of 1s, there is just one way how to ll in the 0s. We could have
however started by placing the two 0s rst and then lling the remaining
bits by 1s, the outcome would have been the same.

b) How many possibilities are there to place four 1s in an 8-bit word?


Hint: Carefully consider how many placements of those four 1s result in

the same possibility.


1.1. LECTURE OVERVIEW 5

Problem 1.6 Encoding sets by sequences:


For counting something, it might be easier to count something else, e.g. instead
of directly counting the number of subsets of a given set with n elements, we can
count the number of dierent sequences of 0s and 1s. The problems then are
how do we know that we have the same number of items (subsets/sequences)
in each case? And how do we transform a set into a sequence? Let us look at
these step-by-step.

a) Let us have a set {x1 , x2 , x3 }. What are its subsets?

Solution:
∅ = {}, {x1 }, {x2 }, {x3 }, {x1 , x2 }, {x1 , x3 }, {x2 , x3 }, {x1 , x2 , x3 }

b) Write these subsets as bit sequences (sequences of 0s and 1s).

Solution: We use 1 for those bits that represent elements present in the
subset and 0 for those bits that are not included in the subset:

(0, 0, 0), (1, 0, 0), (0, 1, 0), (0, 0, 1)

(1, 1, 0), (1, 0, 1), (0, 1, 1), (1, 1, 1)

c) Can we nd exactly one 8-bit sequence for each subset of {x1 , x2 , . . . , x8 }?

Solution: We can use the same encoding as in the previous case, e.g.:

{x2 , x3 , x6 , x7 , x8 } → (0, 1, 1, 0, 0, 1, 1, 1)

d) How many subsets does an n-element set have?

Solution:
{0, 1} × {0, 1} × . . . × {0, 1} = {0, 1}n ⇒ |{0, 1}n | = |{0, 1}|n = 2n

Problem 1.7 Hockey match outcomes:


The CAN:SVK hockey match score was 6:3. Write all possible courses of play
as sequences of letters C and S, representing goals scored by individual teams.
Re-write these sequences using 1s and 0s. How many are there?
6 CHAPTER 1. COMBINATORICS

Problem 1.8 Streets and avenues:


Suppose that going from home to school in Manhattan, where there is a rectan-
gular grid of streets and avenues, means going 3 blocks north and 5 blocks east.
How many dierent possibilities are there to get to school if we always take the
shortest route (only 3 blocks north and 5 blocks east)? Write these routes as
sequences of letters N and E and then as sequences of 0s and 1s. How many are
there?

Problem 1.9 Donuts and their avors:


Donuts can have ve dierent avors and there is always a dozen of them in a
box. We do not have to include every avor in every box and the position of
the donut in the box does not matter. How many dierent boxes can we have?

Solution: Suppose the avors are P  plain, L  lemon, C  chocolate, N 


nougat, B  berry. One possibility is: PPPLLLLCCNBB. Another possibility
is: PPLCCCCCCBBB. We map the possibilities to 16-bit words using 1s and
0s, while keeping the order of P L C N B. The 1s separate the individual avors:

PPPLLLLCCNBB → 0001000010010100

PPLCCCCCCBBB → 0010100000011000
For example, if we order the 0000000000001111 box, we are going to get 12 plain
donuts. We have created a bijection between boxes of dozen donuts and 16-bit
words with four 1s.

Bijection rule
Bijection is a one-to-one correspondence between two sets. If f :A→B is a
bijection, then |A| = |B|. By f :A→B we denote a mapping f which gives an
element of B for an element of A.

Injection rule
Injection is such a mapping that cannot assign the same elements of B to dif-
ferent elements of A. If f :A→B is an injection, then |A| ≤ |B|.

Surjection rule
Surjection is such a mapping that each element of B is assigned to some element
of A, i.e. the whole B is covered. If f :A→B is a surjection, then |A| ≥ |B|.
1.1. LECTURE OVERVIEW 7

Problem 1.10 What do these questions have in common?


a) There were 5 teams in a round-robin tournament, i.e. every team played
with every other team. How many matches were there?

b) Five people at a birthday party clinked their wine glasses with each other.
How many clinks were there?

c) How many edges are there in a complete graph with ve vertices?

d) How many airline routes can there be to connect ve cities?

e) How many sides and diagonals does a regular pentagon have?

Problem 1.11 Coding contest (reducing possibilities):


There were 12 participants in the latest hackathon. The top three received a
new laptop. How many possibilities are there for the best trio out of 12 coders?

Solution:
12 · 11 · 10
6

Problem 1.12 Chessboard (reducing possibilities):


How many possibilities are there to place two rooks (towers) of the same color
on a chessboard so that they do not protect the same row or column?

Solution: The position (r1 , c1 , r2 , c2 ) is the same as (r2 , c2 , r1 , c1 ).

8·8·7·7
2

Division rule
If f is a mapping A → B which maps exactly k elements of A to each element
of B , (mapping k -to -1), then it is true that

|A|
|A| = k|B|, |B| = .
k

Problem 1.13 Zeros and ones (revisited):


How many possibilities are there to place four 1s in an 8-bit word?
8 CHAPTER 1. COMBINATORICS

Solution: We have already looked at this problem once. Now we know that we
need a reduction for all those placements of 1s that result in the same possibility.
What kind of reduction? For any given 4 bits we have 4·3·2·1 possibilities
how to place four distinct 1s. Since they are not distinct for us in this setting,
the reduction is 24- to -1. The number of possibilities is then

8·7·6·5
.
4·3·2·1

Factorial
There is a useful notation for shortening expressions such as 4·3·2·1 and it is
4!. It is called factorial and it denotes the product of all natural numbers not
larger than the given number, i.e. n! = n · (n − 1) · (n − 2) · . . . · 2 · 1. Note the
special case dened separately: 0!=1.
Incidentally, the statement 0!=1 is also true in many programming lan-
guages, since 0 is clearly not equal to 1.

Combinatorial number
Many of the previous problems came down to computing how many ways we
can choose a set of k items out of n options. The notation for the number
of such selections is
n
k and it is called a combinatorial number or a binomial
coecient . It is calculated as

 
n n · (n − 1) · (n − 2) · . . . · 2 · 1 n!
= = .
k (k · (k − 1) · . . . · 2 · 1) · ((n − k) · (n − k − 1) · . . . · 2 · 1)) k!(n − k)!

1.1.2 Pigeonhole (Dirichlet) principle


Problem 1.14 Drawers, pigeons, socks and Prague:
a) Suppose we have books and notebooks for ve dierent subjects. Our desk
has ve drawers and so we put all items for each subject into a separate
drawer. Then we nd out that a mouse has moved into one of the drawers
and so we have only four drawers left. As a consequence, we have to move
the items from that drawer to another one and thus there will certainly
be a drawer that contains items for two dierent subjects.

b) Suppose we have 15 pigeons and a dovecot with 10 holes. There is certainly


be at least one hole through which at least two pigeons enter the dovecot.
1.1. LECTURE OVERVIEW 9

c) We are taking socks out of a drawer. There are black and white socks but
it is so dark in the bedroom that we cannot tell them apart. Since we do
not see them, we have to take at least three socks to be sure that we have
a pair of the same color.

d) There are at least six people in Prague, who have the same number of
hairs on their heads.

Solution: We have to make some assumptions about the number of hairs


and the number of people in Prague. Suppose that a person has at most
200 000 hairs and that there are 1 391 000 people in Prague. If we group
the people in Prague by their hair number and try to do it in such a way
that there are no more than ve people in each group, we end up with
200 000 · 5 = 1 000 000 people in groups. There is a group of ve people
with one hair each, a group of ve people with two hairs each, with three
hairs etc. There are still 391 000 people left. We could make a one more
group of ve bald people, but everybody else must join one of the existing
groups and so we know that there will be at least one group of six people
with the same number of hairs.

e) Can we say that there are at least seven people in Prague who have the
same number of hairs?

Pigeonhole principle
• If the number of elements of set A is larger than the number of elements
of set B, i.e.

|A| > |B|,

then for each mapping f from A to B it is true that we can nd two
distinct elements a1 and a2 from A for which f (a1 ) = f (a2 ).

• If the number of elements of set A is larger than k -times the number of


elements of set B, i.e.

|A| > k|B|,

then for each mapping f from A to B it is true that we can nd k+1
distinct elements of A which get mapped to the same element of B by the
mapping f.
10 CHAPTER 1. COMBINATORICS

1.1.3 Brief review of related concepts


Binomial theorem
This theorem tells us about expansion of powers of a binomial:
n n n
  
(a + b)n = 0 an b0 + 1 an−1 b1 + ... + n a0 bn .

Figure 1.2: Pascal's triangle.

Pascal's triangle
Binomial coecients are also present in the Pascal's triangle. It is a triangular
array of combinatorial numbers in which the numbers in nth row are the same
as the coecients in front of the terms of (a + b)n . The sum of numbers in
the nth row of Pascal's triangle is 2n , Figure 1.2. Every number in the Pascal's
triangle except the 1s that are on both sides can be calculated as the sum of
the two numbers directly above it.
1.2. QUESTIONS 11

1.2 Questions

1. A castle consists of several towers built next to each other. A tower cannot
be taller than the tower immediately to its left. How many dierent castles
can be built using 7 cubes?

2. There are 28 people in a queue for tickets. How many dierent queues can
there be?

3. A bus has 35 seats. How many ways are there for 28 passengers to sit
down?

4. 28 passengers got on an empty bus in šilina. They all got o at one of


stops Tepli£ka, Stre£no, Vrútky, Martin. How many possible ways were
there for them to get o the bus?

5. How many 4-letter passwords can be created using the letters SONG?

6. How many 4-letter passwords can be created using the letters LOOK?

7. How many 10-bit words can be created using exactly four 1s


(e.g. 1111000000)?

8. How many subsets does the set {2, sun, @} have?

9. What is the connection between the number of subsets of a 4-element set


and the number of 4-bit words?

10. What is the connection between the number of dierent matches that
ended 3:2 and the number of 5-bit words with three 1s?

11. Going home from school, I have to go 3 blocks east and 6 blocks south.
What is the connection between these routes and the set of all sequences
of three 0s and six 1s? Re-write the route ESSSEESSS using 0s and 1s.
Re-write the sequence 101111001 using directions E and S.

12. How many ways are there to ll a box with 10 donuts when there are 3
avors available?

13. How many games are there in a round-robin tournament with 6 players
(everybody plays all other players)?

14. How many dierent triplets of winners can there be in the top coder con-
test, when all 800 students at the faculty participate?
12 CHAPTER 1. COMBINATORICS

15. How many ways are there to place 3 white rooks (towers) on a chessboard
8×8 so that they do not attack each other?

16. What does the binomial theorem say?

17. What is the sum of coecients in the binomial theorem (i.e. in one row of
Pascal's triangle)?

18. What does the pigeonhole principle say?

19. There are white, black and pink socks in a drawer. When in the dark,
how many of them do we have to take out to be sure that we have a pair
of the same color?
1.3. PROBLEM SET 13

1.3 Problem set

1. Horse-race
a) There were three horses in a horse-race: Alejandra, Beatrix and
Claire. Write all possible orders how they can arrive at the nish
line. (We assume that two horses never arrive at exactly the same
time.)

b) What are the possible orders if a horse called Pedro joins the race as
well? You can use the orders from the previous question.

c) There were eight horses in a race. How many dierent orders are
there at the rst three places (we do not care about the remaining
places)?

d) There were eight horses in a race. How many possible triplets of


winners are there? Winners here are the rst three horses regardless
their specic medal position.

2. Shortest path in a grid


How many dierent shortest paths are there from the upper left corner to
the lower right corner in a grid 5 × 3, see Figure 1.3?

Figure 1.3: One of the shortest paths in the grid is shown in red.

3. Hockey match
The result of a hockey match between Slovakia and Canada was 4:3.

a) How many dierent matches can there be? (Here dierent matches
are those that have a dierent order of Slovak and Canadian goals.)
14 CHAPTER 1. COMBINATORICS

b) In the next match, there were also 7 goals. In how many ways could
these goals be scored in the 1st , 2nd and 3rd period of the game?
(Here we do not care which team scored which goal.)

c) Overall, there were 22 matches at the tournament and none of them


had more than six goals total. At most, how many matches could
there (certainly) be which had the same number of goals?

4. Licence plates
A licence plate in our town can have these forms:

• Letters ZA, then three digits, then two letters

• Letters ZA, then ve letters

Let us denote by L the set of all licence plates in our town.

a) Express the set L using the sets C = {A, B, C, . . . , Z} and D =


{0, 1, 2, . . . , 9} and set operations.
b) Compute |L|, i.e. the number of all possible licence plates.

5. Queues
There are six boys (B) and four girls (G) who are asked to form a queue
BBGGBBGGBB. They all have dierent names.

a) In how many ways can they arrange themselves into such a queue?

b) In how many ways can they arrange themselves into such a queue if
we do not care about the order in the BB, GG pairs?

6. Oranges
Parents want to give seven oranges to their four children.

a) In how many ways can they do that?

b) In how many ways can they do that if each child should get at least
one orange?

c) In how many ways can they do that if the youngest child should get
at least two oranges? (It may happen that some of the older children
get zero oranges.)

7. Grandpa's bunnies
Grandpa has 21 bunnies and ve stalls. Determine whether the following
statements are always true, sometimes true or always false. In case the
statement is sometimes true, give an example with placement of bunnies
in stalls that makes it true and another example that makes it false:
1.3. PROBLEM SET 15

a) There is a stall that has two bunnies.

b) In every stall there is at least one bunny.

c) There is a stall that has at least two bunnies.

d) There is a stall that has exactly four bunnies.

e) In at least two stalls there are at least four bunnies.

f ) There is a stall that has at least four bunnies.

g) In at most three stalls there are at most three bunnies.

h) There is a stall that has 22 bunnies.

i) In at most two stalls there are at least six bunnies.

j) There is a stall that has exactly ve bunnies.

k) There is a stall that has at least ve bunnies.

l) There is a stall that has zero bunnies.

8. Grandpa's bunnies one more time


Grandpa has 21 bunnies and

a) four stalls

b) ve stalls

c) six stalls

Based on this information, what can be said about the number of bunnies
in the individual stalls?

9. Hiking in a forest
a) Five students went hiking in a forest in the shape of square with 4

km side. Each student has a transmitter with range 2 2 km. How
do you show that at least two of them can contact each other?

b) Solve the same problem if the forest is an equilateral triangle and the
range of the transmitter is 2 km.
16 CHAPTER 1. COMBINATORICS

1.3.1 Hints and solutions


1. Horse-race
a) There were three horses in a horse-race: Alejandra, Beatrix and
Claire. Write all possible orders how they can arrive at the nish
line. (We assume that two horses never arrive at exactly the same
time.)

b) What are the possible orders if a horse called Pedro joins the race as
well? You can use the orders from the previous question.

c) There were eight horses in a race. How many dierent orders are
there at the rst three places (we do not care about the remaining
places)?

d) There were eight horses in a race. How many possible triplets of


winners are there? Winners here are the rst three horses regardless
of their specic medal position.

Hints :
• When writing out all possibilities it is useful to stick to a reasonable
system and not write the possibilities in random order. Using a
system ensures that we do not forget any possibility and do not write
any possibility twice.

• We can verify the number of possibilities by a calculation. The fol-


lowing questions can help us with that: How many possibilities are
there for the rst place? How many possibilities remain for the sec-
ond place and subsequently for the third place? The multiplication
rule might help.

• When looking for the triplets of medalists, we are not interested in


specic orders in each triplet, therefore what we need to do is to suit-
ably reduce the number of orders. How many dierent possibilities
are there for ordering the horses in each triplet?

Solution:
a) We can start with the possibility that they arrive in the alphabetical
order A, B, C and then switch the second and third place. We repeat
this for the cases when the other horses nish rst.

ABC ACB BAC BCA CAB CBA


1.3. PROBLEM SET 17

An alternative method for writing out all possibilities is to use a tree


structure as depicted in Figure 1.4. We have all the possibilities for
the rst place written on top. Then we have all options for second
places and nally all third places. The lines connecting the names of
the horses represent the individual possibilities.

Figure 1.4: All possibilities of the orders of three horses at the nish line.

We can do the following calculation to verify that we have all the


possibilities. There were three options for the rst place. Since a
horse cannot take two places simultaneously, there are only two op-
tions left for each second place and consequently just one option for
the third place. The multiplication rule helps us calculate that there
are six possible orders.

1st place 2nd place 3rd place


⇒ 3·2·1=6
3 possibilities 2 possibilities 1 possibility

b) The new horse Pedro (P) can nish at any place. We obtain the
orders for four horses from the orders for three horses by including
Pedro consecutively at all possible places:

PABC PACB PBAC PBCA PCAB PCBA


APBC APCB B PAC B PCA C PAB C PBA
AB PC AC PB BAPC BC PA CAPB CB PA
ABC P ACB P BAC P BCAP CAB P CBAP

The visualisation using the tree method is shown in Figure 1.5.

We calculate the number of possible orders the same way as before.


This time, there are four possibilities for the rst place (one of the
horses A, B , C and P ). Regardless of who won, there are three
possibilities for the second place. The same reasoning leads to the
fact that only one of the remaining two horses could be at the third
18 CHAPTER 1. COMBINATORICS

Figure 1.5: All possible orders for four horses.

place in each case and the last horse nished fourth. Altogether, this
gives 24 possible orders.

1st place 2nd place 3rd place 4th place


4 poss. 3 poss. 2 poss. 1 poss.

4 · 3 · 2 · 1 = 24

c) There were eight possibilities for the winner, seven possibilities for
the second place and one of the remaining six horses nished third,
therefore there are 156 dierent possible orders.

1st place 2nd place 3rd place


⇒ 8 · 7 · 6 = 156
8 poss. 7 poss. 6 poss.

d) We know from the previous problem that there are 8 · 7 · 6 = 156


possibilities for rst three places in races of of eight horses. Since
now we are only interested in medal placements, not a specic medal,
we need to suitably reduce this number. For example, if Alejandra,
Beatrix and Pedro were the rst three, then we consider all orders
in which they could have nished (ABP , AP B , BAP , BP A, P AB ,
P BA) as one triplet. Therefore we calculate the number of all winner
triplets as
8·7·6 156
= = 56.
3·2·1 6
2. Shortest path in a grid
How many dierent shortest paths are there from the upper left corner to
the lower right corner in a grid 5 × 3?
1.3. PROBLEM SET 19

Hints : In order to understand the problem better, we can draw a grid


with three rows and ve columns. Since we are looking for the shortest
path, there are only two directions allowed: south and east. We need to
go south three times and east ve times. If we denote the directions by 0s
(for south) and 1s (for east), the individual possible trips can be written
as sequences of 0s and 1s. We can thus map the grid problem into binary
words and continue using the approach shown in the lecture.

Solution: We start by drawing the grid, Figure 1.6.

Figure 1.6: One possible shortest path in the grid. The numbers at the crossings
denote how many ways there are to get to each crossing.

We are going to calculate how many possible ways are there to get to the
individual crossings when we can travel only east (E) or south (S). There
is only one way how to get to the crossing immediately to the right of the
starting point and we denote it E. Similarly, there is only one way how to
get to the rst crossing to the south and we denote it S. Now there are
two possible paths to the crossing that lies south-east: SE and ES. The
crossing that can be reached via SSE can also be reached through SES and
ESS, which means three dierent paths. This can also be determined by
adding the numbers of paths that lead to the immediate predecessors of
these crossings, i.e. one way to SS and two ways to SE/ES. We continue
this way until we get to the lower right corner.

Another solution : Instead of using S and E to denote the directions, we


can use 0s and 1s. If we denote the south direction ↓ as 0 and the east
direction → as 1, we can express each path as a sequence of three 0s and
ve 1s. 00011111 is an example of one such path, which rst takes us three
blocks south and then ve blocks east. We can now transform the problem
20 CHAPTER 1. COMBINATORICS

into a dierent question. How many dierent 8-bit words are there that
contain exactly three 0s? How many dierent 8-bit words are there that
contain exactly ve 1s?

8·7·6 156 8·7·6·5·4 6720


= = 56 or = = 56
3·2·1 6 5·4·3·2·1 120
This approach is revisited in more detail in Problem 5 in Section 1.4.

3. Hockey match
The result of a hockey match between Slovakia and Canada was 4:3.

a) How many dierent matches can there be? (Here dierent matches
are those that have a dierent order of Slovak and Canadian goals.)

b) In the next match, there were also 7 goals. In how many ways could
these goals be scored in the 1st , 2nd and 3rd period of the game?
(Here we do not care which team scored which goal.)

c) Overall, there were 22 matches at the tournament and none of them


had more than six goals total. At most, how many matches could
there (certainly) be which had the same number of goals?

Hints:
• There are many possible ways how a match can go. If the number of
goals is small, we can try to write them all out. When doing so, it is
good to think about how to go through them a in logical fashion so
that we always know which is the next one to write and so that we
do not forget any of them.

• If we want to calculate the number of possibilities, both questions


a) and b) can be transformed into problems using bit sequences, but
the 1s and 0s do not denote the same things in these two cases.

• Question c) is of completely dierent nature. It does not ask about


possibilities, but rather about an upper bound ( at most ) on some-
thing that has to happen ( certainly ). This should remind us of the
pigeonhole principle from the lecture. We just need to realise what
are the pigeons and what are the holes here.
1.3. PROBLEM SET 21

Solution:
a) One possible score order in a match could have been SSSSCCC. This
means that Slovakia scored the rst four goals, the score was 4:0
and they thought the game was theirs and stopped paying attention.
Canada woke up, seized the opportunity and managed to score three
times. A completely dierent game would be CSCSCSS. This one
would keep the fans on their toes, because the score was 0:1, then
1:1, then 1:2, then 2:2 and so on. Always close.

So how many dierent orders could there be? To answer this ques-
tion, it is good to realise that we need four letters S and three Cs.
With this realisation, the problem is transformed into nding the
number of 7-bit sequences that contain four 1s and three 0s. Fortu-
nately, we already know how to do that and thus the total number
7!
of possibilities is
4!3! .
b) In the next match, we do not care what teams played, who won, or
even how many goals they each scored. The only thing that matters
is how the goals were divided into the periods. Again, we could
systematically write them out, starting with e.g. 7+0+0 to denote
that all goals happened in the rst period of the game, then 6+1+0,
6+0+1, 5+2+0, 5+1+1, 5+0+2, etc. While certainly doable for
seven goals, we should also try to calculate the number possibilities.

This time we can denote each goal with a 0 (a puck is round, is it not?)
and separate the thirds using dividers  1s. Thus 7+0+0 corresponds
to 000000011, 6+1+0 to 000000101, 5+1+1 to 000001010, etc. For
each division of goals we have one sequence and for each sequence, we
have one division of goals, so that means we have one-to-one mapping
and the number of possibilities is the same as the number of 9-bit
9!
sequences with seven 0s and two 1s, which is
7!2! .
c) We start by thinking about how many dierent matches could we
have. None of them had more than six goals total. This means,
there are seven possibilities: matches without goals, matches with
one goal, matches with two goals, . . ., matches with six goals.

While unlikely, it is possible that all matches had six goals. Then
we have 22 matches with the same number of goals. However, we
cannot be sure, because it is also possible that only 21 had six goals
and one had no goals at all. And there are many other possibilities
how the tournament could go. We are looking for something we can
22 CHAPTER 1. COMBINATORICS

be certain of. We can surely say that there were two matches that
had the same number of goals. If there were not, we could have at
most seven matches  to get seven dierent outcomes. Since we have
22, there is surely an outcome that has to repeat.

And we can make an even stronger statement: In any such tourna-


ment there must be at least four matches that had the same number
of goals. If there were only three (or fewer), we would have at most
3 · 7 matches total. Since we have 22, this means that one of the out-
comes (we do not know which one) has to repeat at least four times.
We need to remember that the pigeonhole principle that we used
here tells us not what can happen, but rather what has to happen.
In this case the matches were pigeons and the possible outcomes we
pigeonholes.

4. Licence plates
A licence plate in our town can have these two forms:

• Letters ZA, then three digits, then two letters

• Letters ZA, then ve letters

Let us denote by L the set of all licence plates in our town.

a) Express the set L using the sets C = {A, B, C, . . . , Z} and D =


{0, 1, 2, . . . , 9} and set operations.

b) Compute |L|, i.e. the number of all possible licence plates.

Hints :
• Use the addition and multiplication rules from the lecture.

• Consider whether the letters and the numbers can repeat. Do we


select each character from the whole set of letters and/or numbers?

• Since the licence plates can have two distinct formats, that result in
two disjoint sets, we can use the addition rule to determine the total
number of licence plates.

Solution: The letters ZA are the same on all the licence plates, therefore,
we do not need to include them in the calculations and only consider those
parts of the licence plates that can dier. The numbers and the letters
can repeat, therefore we choose each character from the whole set that
1.3. PROBLEM SET 23

is available. The individual types of licence plates can be written in the


following way using the set operations:

L1 = D × D × D × C × C = D3 × C 2
L2 = C × C × C × C × C = C5

The set of all possible licence plates is then union of these two sets

L = L1 ∪ L2 = (D3 × C 2 ) ∪ C 5 .

To determine the number of possible licence plates, we calculate

|L| = |(D3 × C 2 ) ∪ C 5 |.

Since the sets D and C are disjoint, we can use the addition rule and the
multiplication rule. If we use a 26-letter alphabet for C, then the total
number of available licence plates is

|L| = |D3 × C 2 | + |(C ∪ D)5 | = |D|3 · |C|2 + |C|5


= 103 · 262 + 265 .

5. Queues
There are six boys (B) and four girls (G) who are asked to form a queue
BBGGBBGGBB. They all have dierent names.

a) In how many ways can they arrange themselves in such queue?

b) In how many ways can they arrange themselves in such queue if we


do not care about the order in the BB, GG pairs?

Hints :
• Clearly a person cannot be at two places at the same time, therefore
we have fewer and fewer boys and girls to choose from once some of
the places are already occupied.

• Since we know the order of the boys and girls, we only choose from
one of the two groups when assigning people to specic places.

Solution: One of the six boys stands rst in the line, one of the remaining
ve stands second. Then we have a pair of girls, so one of the four girls
24 CHAPTER 1. COMBINATORICS

stands third in the line and one of the remaining three stands fourth.
Continuing like this, we get the overall number of possibilities:

order B B G G B B G G B B
possibilities 6 5 4 3 4 3 2 1 2 1

⇒ 6 · 5 · 4 · 3 · 4 · 3 · 2 · 1 · 2 · 1 = 6! · 4!

To answer the second question, consider the rst two places. If Tom is
rst, Jerry second and then they switch places, we consider this as one
possibility. All other pairs of boys and girls can switch similarly, therefore
we divide the number of possibilities for each pair by two:

6·5 4·3 4·3 2·1 2·1 6! · 4!


· · · · = .
2 2 2 2 2 25

6. Oranges
Parents want to give seven oranges to their four children.

a) In how many ways can they do that?

b) In how many ways can they do that if each child should get at least
one orange?

c) In how many ways can they do that if the youngest child should get
at least two oranges? (It may happen that some of the older children
get zero oranges.)

Hints:
• We can start by checking a few ways how parents can divide the
oranges among their children, e.g. 7+0+0+0 (one child gets all seven
oranges) or 2+2+2+1 (three children get two oranges each and one
child gets one orange). Can these possibilities be coded into sequences
of 0s and 1s? Could we use the separators here similarly as in the
donut Problem 1.9?

• The additional requirement in question b) can be taken care of at


the beginning by giving each child one orange rst. The problem
then transforms into a problem of dividing three oranges among four
children.

• A similar approach can help in problem c).


1.3. PROBLEM SET 25

Solution:
a) Similarly to the donut problem in the lecture, we can use the encoding
to binary words here. In this case, the 0s represent the oranges and
the 1s represent the separators for splitting the oranges among the
children. For example, the binary word (0101010000) means that
three children got one orange each and the fourth child got four
oranges. The problem of dividing seven oranges among four children
is now transformed into the problem of how many binary words of
length 10 with three 1s are there:

 
10 · 9 · 8 10! 10
= = .
3·2·1 3!7! 3

b) We can simplify the problem by giving each child one orange rst
and only then divide the remaining three oranges. Again we use 1s
to represent the separators and we are looking for 6-bit words with
three 1s:
 
6·5·4 6! 6
= = .
3·2·1 3!3! 3

c) We use the same idea as in the previous question. The youngest


child gets two oranges and then we divide the remaining ve oranges
among the four children:

 
8·7·6 8! 8
= = .
3·2·1 3!5! 3

7. Grandpa's bunnies
Grandpa has 21 bunnies and ve large stalls. Determine whether the
following statements are always true, sometimes true or always false. In
case the statement is sometimes true, give an example with placement of
bunnies in stalls that makes it true and another example that makes it
false:

a) There is a stall that has two bunnies.

b) In every stall there is at least one bunny.

Hints:
26 CHAPTER 1. COMBINATORICS

• For each statement we should try to look whether we can place the
bunnies into the stalls in a way that does not contradict the state-
ment. If so, the statement cannot be always false. We should then
also try to place the bunnies in such a way that it does contradict
the statement. If we succeed, the statement cannot be always true.

• The words to look for and be careful about are at least, at most and
exactly. Also there is a dierence between there is a stall . . . and in
every stall . . .

Solution:
a) There is a stall that has two bunnies.

We can make the following placement A: stall 1 has 2 bunnies, stall 2


has 5 bunnies, stall 3 has 5 bunnies, stall 4 has 5 bunnies, stall 5 has
4 bunnies (denoted by 2+5+5+5+4). Thus the statement is true.

It is also true, if there are two such stalls, i.e. placement B: 2+2+5+5
+7, since this does not contradict the statement.

Is it also true for placement C: 3+3+3+3+10? There are at least two


bunnies in each stall, but none of the stalls has exactly two bunnies. If
not stated otherwise, we interpret this as requirement to have exactly
two bunnies and thus placement C contradicts the statement.

Therefore we conclude that the statement is sometimes true.

b) In every stall there is at least one bunny.

Placement D: 1+2+3+4+11 makes the statement true, placement E:


0+5+5+5+6 makes it false. So this statement is sometimes true.

8. Grandpa's bunnies one more time


Grandpa has 21 bunnies and

a) four stalls

b) ve stalls

c) six stalls

Based on this information, what can be said about the number of bunnies
in the individual stalls?

Hints : We are interested in the strongest statements we can be sure about


even when we do not know the precise partition of bunnies into the stalls.
One statement which we can be sure about is that there will be at least one
1.3. PROBLEM SET 27

bunny in at least one stall, regardless the overall placement of the bunnies.
The pigeonhole principle guarantees that. Can we say something stronger?
Do there have to be at least two bunnies together in at least one stall?
Three bunnies? Try using the pigeonhole principle again to determine the
largest number of bunnies that have to be together in one stall.

Solution:
a) By placing the bunnies uniformly and thus trying to nd the least
favorable placement we have ve of them in each of the four stalls.
We can place the last one into any stall, Figure 1.7.

Figure 1.7: Placing 21 bunnies into four stalls.

Therefore we can claim that that there is always going to be at least


one stall that holds at least six bunnies. We do not know which one
is it going to be. We certainly do not know the exact placement of
all bunnies, but even if they were all together in one stall, it does not
invalidate our statement. There might be a stall with seven bunnies
or with eleven, but we cannot be sure of that. The only thing that
is certain is that there is a stall with at least six of them.

b) If there are ve stalls available, in the least favorable case, we have
four stalls with four bunnies and one with ve, since:

21 = 5 · 4 + 1.
Therefore we claim that there will be at least one stall with at least
ve bunnies.

c) In this case we have:


21 = 6 · 3 + 3.
We start by three bunnies in each stall and there are various possibil-
ities for the remaining three bunnies. Each one of them can go to a
28 CHAPTER 1. COMBINATORICS

dierent stall or perhaps all can go together to one stall. We simply


do not know. Therefore the strongest statement we can make is the
lower bound : there is at least one stall that has at least four bunnies.

9. Hiking in a forest
a) Five students went hiking in a forest in the shape of square with 4

km side. Each student has a transmitter with range 2 2 km. How
do you show that at least two of them can contact each other?

b) Solve the same problem if the forest is an equilateral triangle and the
range of the transmitter is 2 km.

Hints :
We can divide the forest into four equal parts. Thanks to the pigeonhole
principle, there is certainly going to be a forest part in which there are
two students. If the largest possible distance of this pair of students is
shorter than the transmitter range, we can be certain that at least these
two can communicate. The question thus is, how to divide the square
and triangle forests into parts and what is the maximum distance in these
parts relative to the transmitter range.

Solution:
a) The square forest with 4 km side can be split into four equal squares
with 2 km sides, Figure 1.8.

Figure 1.8: Partition of the square forest into four smaller squares. At least two
students will be in the same smaller square.
1.3. PROBLEM SET 29

The largest distance of two points in a smaller square is the length


of its diagonal. It can be determined using the Pythagorean theorem
√ √ √
as 22 + 22 = 8 = 2 2. Since the pigeonhole principle implies
that there are at least two students in the same smaller square, we

know they be at most 2 2 km apart. Therefore they will be able
to communicate, since this distance corresponds to the transmitter
range.

What would happen if we partitioned the square dierently? For ex-


ample into four triangles using the diagonals or into four rectangular
stripes, Figure 1.9? Can we ensure connection also in these cases?

Figure 1.9: Two dierent partitions of a square forest.

If we tried to partition the square into triangles as shown in Figure


1.9, we see that the largest distance is 4 km, which is more than the
transmitter range. Similarly, the diagonal of a rectangular stripe is
longer than this range. Thus, with this reasoning we cannot guaran-
tee connection. It does not mean that it is not there (it is as we saw
when we partitioned the square into four smaller squares), it just can-
not be proven this way. This hints at a strategy how to partition the
forest: we try to partition it into parts with the smallest (minimal)
maximal distance.
30 CHAPTER 1. COMBINATORICS

1.4 Lab problems

1. Snowmen
Draw all 3-level snowmen when we have 4 dierent colors of snow available.
Draw all 4-level snowmen if only 3 kinds of snow are available.

2. Pascal's triangle
Write the rst 20 lines of Pascal's triangle using a suitable formula. Color
the numbers in the triangle so that you use dierent colors for

a) even and odd numbers,

b) numbers that give dierent remainders when divided by 3.

3. Hockey match
A hockey match ended 4:3. Write (in a reasonable way) all possible orders
how the teams scored and count how many there are.

4. Hockey match II
There were 7 goals in a match. Write (in a reasonable way) all possible
ways how to divide the goals into thirds (how they could have been scored)
and count how many there are.

5. Wall-e goes to Eve


Simulate in Excel the shortest path from robot Wall-e to Eve. The robot
moves in a eld 5 × 3, it can go up and to the right. The graph will show
a random path from [0,0] to [5,3], see Figure 1.10. Compute how many
possible paths can the robot take.

Figure 1.10: One possible path Wall-e can take on his journey to Eve.
1.4. LAB PROBLEMS 31

1.4.1 Hints and solutions


1. Snowmen
Draw all 3-level snowmen when we have 4 dierent colors of snow available.
Draw all 4-level snowmen if only 3 kinds of snow are available.

Hints: What a weird problem! When we were growing up, the snow used
to be just white. Well, sometimes yellow and that was it. But ok, let us
suppose we have few more snow colors and that we want to draw some
snowmen. 3-level snowman would be the regular kind as we know it and
we can draw each level with dierent color, see Figure 1.11 A. Can we
draw a dierent one? Of course, we just shue the colors somewhat or
use the fourth color that we have available, as in Figure 1.11 B. Note that
since we are working in Excel, we have to loosen the snowman-making
rules just a tiny bit and allow snowman with rectangular levels. The color
of the cells in Excel can be changed using the Home toolbar.

Figure 1.11: Very weird snowmen. From the left: A: 3-level snowman with 3
colors, B: 3-level snowman with 3 colors, C: 3-level snowman using just 2 colors,
D: 3-level snowman using just one color and E: 4-level snowman when only 3
colors are available.

So how many dierent snowman can we build? It is good to settle on a


system and not just jump arbitrarily between dierent colors. Using a
system, we do not miss any combinations.

And what if we use the same color twice in the same snowman, e.g. Figure
1.11 C or even three times as in Figure 1.11 D? Of course, we can do that.
How many snowmen are possible now?

Once we can answer these questions, it will be no problem to extend the


same kind of thinking to 4-level snowmen, Figure 1.11 E, i.e. those that
consist of four balls on paper or four rectangles in Excel. In this case,
since we only have 3 colors available, it is certain that at least one of them
will repeat.
32 CHAPTER 1. COMBINATORICS

2. Pascal's triangle
Write the rst 20 lines of the Pascal's triangle using a suitable formula.
Color the numbers in the triangle so that you use dierent colors for

a) even and odd numbers,

b) numbers that give dierent remainders when divided by 3.

Solution: To write the Pascal's triangle, we need to rst think about how
to make a(n isosceles) triangle in Excel. Some possibilities are shown in
Figure 1.12. Note that we might run into problems for larger triangles if
we try to keep the actual triangular shape, as in Figure 1.12 a).

a) b) c)

Figure 1.12: Dierent ways of creating Pascal's triangle in Excel.

The numbers in the Pascal triangle are not calculated using factorials (we
would have to stop very quickly in such case) but rather by using addition
 each number is a sum of the two numbers above it. To get the colors
according to requirements, we can use Conditional formatting and setting
a rule =IF(MOD(A1;2)=0). This will ensure that even numbers will be
colored as selected.

3. Hockey match
A hockey match ended 4:3. Write (in a reasonable way) all possible orders
how the teams scored and count how many there are.

Hints: There are many possible ways (two of them are illustrated in Figure
1.13). When writing your own, it is good to think about the following:

• How to write one possibility? Into one cell? Into seven cells? Arrange
them in rows? In columns?

• How to go through them in logical fashion so that we always know


what is the next one to write?
1.4. LAB PROBLEMS 33

• How can we be certain that we have them all and that they do not
repeat?

• How to format the result (using color or something else) so that it is


easy to check?

Figure 1.13: Two possible ways how to write the match outcomes. The one
on the left systematically goes through all correct possibilities. The one on the
right shows all 7-bit sequences and highlights those that contain three 1s.

Solution: In Section 1.3.1 we already counted how many possible ways


there are. Now we are asked to write them all out. One approach is to
write out all 7-bit sequences of 0s and 1s in the rst seven columns and
then use the SUM function to determine which contain exactly three 1s.
Those can be highlighted by conditional formatting.

Binary words using text processing functions


A more challenging variant of this solution is one that uses text pro-
cessing and conversion from decimal to binary. The smallest binary
number that satises our conditions is 0000111, which evaluates to
7 in decimal system and largest 1110000, which evaluates to 112. In
this 7 to 122 range, we have all numbers we are looking for. The
downside is that the range also includes some numbers, which do not
t the criteria, e.g. 0001111. We can use the Excel built-in functions
to convert the number to string and count the number of 1s to reject
the incorrect sequences.

An alternative way to solve this problem, would be to write a tree, as in


Figure 1.14. It starts with the initial 0:0 score at the top of the Excel
34 CHAPTER 1. COMBINATORICS

sheet. Suppose it is Slovakia and Canada playing. Then there are two
possibilities what could happen: either Slovakia scores and we have 1:0 or
Canada scores and we have 0:1. We include them both in the line below.
What happens next? If Slovakia scores, we get either 2:0 or 1:1, depending
on the current situation. If Canada scores, we get either 1:1 or 0:2. So we
can write the three possible outcomes (2:0, 1:1 and 0:2) into the next line.
Note that they are not of the same kind. The outcome 1:1 can happen two
dierent ways. This will be useful later when counting all the possibilities.
Also note that at rst the tree branches out but from some point on, the
branches start converging to the same nal value 4:3. Scores like 5:2 or 2:4
should not appear anywhere in your tree, because they could not happen
in this match.

Figure 1.14: A tree-representation of the solution. Black denotes the current


state of the match, red denotes how many ways can the state be achieved and
the arrows show the possible paths from each state to other states.

To count the possible outcomes, it is necessary to count all possible paths


1.4. LAB PROBLEMS 35

from 0:0 to 4:3. This looks similar to the Pascal's triangle. So we can
determine the number of possible matches by lling in the corresponding
portion of the Pascal's triangle.

4. Hockey match II
There were 7 goals in a match. Write (in a reasonable way) all possible
ways how to divide the goals into thirds (how they could have been scored)
and count how many there are.

Solution: Continuing with the hockey topic from the previous problem,
we try to answer a dierent question this time. We do not care if it was
Slovakia or Canada who scored the goal this time. We only care in which
period it was. One possibility is that all seven goals were scored in the
rst period and then it was a boring match when nothing happened till
the end. Or maybe the goals were evenly spaced out  2 in the rst period,
3 in the second and 2 in the nal period. Or there could have been 6 goals
in the rst period, nothing in the second and the nal goal scored in the
third period.

Again, we need some systematic way to write all of them without forgetting
any, so the rules from the previous problem still apply. One way would be
to break the task into several smaller subproblems. We could write out
all possibilities with 7 goals in the rst third (there will not be too many
of those), then all possibilities with 6 goals in the rst third, then 5, etc.
Clearly, no possibility will be included twice, so to get to the answer, it is
sucient to just add up all the partial answers.

Note that as a check, we can also count how many possibilities do we


expect. Looking at the lecture, we can treat the goals as 0s (the puck is
round after all) and partition them into three periods using 2 dividers,
e.g. 000100010 is a match with 3 goals in the rst and second periods each
and one in the nal period. The problem is then reduced to counting how
many 9-bit sequences with two 1s and seven 0s are there.

Goal orders separated into periods


What if we combined the previous two problems? How many ways
are there to partition goals into periods, if we do care about who
scored each goal? This time SS CCS SC is dierent from SS SSC CC,
but both were counted as the same option 001000100 in the previous
problem. The two options SS CCS SC and SS CCS CS represent the
36 CHAPTER 1. COMBINATORICS

same partition in this question.

5. Wall-e goes to Eve


Simulate in Excel the shortest path from robot Wall-e to Eve. The robot
moves in a eld 5 × 3, it can go up and to the right. The graph will show
a random path from [0,0] to [5,3]. Compute how many possible paths can
the robot take.

Solution: Two possible paths are shown in the Figure 1.15. The orange
one is [0,0] to [0,1] to [2,1] to [2,2] to [3,2] to [3,3] to [5,3]. Perhaps it would
be better to denote the individual steps: [0, 0] ↑ [0, 1] → [1, 1] → [2, 1] ↑
[2, 2] → [3, 2] ↑ [3, 3] → [4, 3] → [5, 3]. Try writing out the coordinates of
the green path.

Figure 1.15: Wall-e starts at [0,0] and is trying to get to Eve who waits at the
position [5,3]. Only steps to the right and up are allowed. One possible path is
shown.

How to draw this in Excel? Once we have the coordinates in two separate
columns for x and y, we can insert a scatter plot with straight lines (x-y
dependence chart) from the Insert toolbar.

For one specic path we would just write down the coordinates as in Figure
1.16.

Instead of re-writing the coordinates by hand to show a dierent path,


let us do something dierent. We are going to generate Wall-e's steps at
random, so that every time it will move either up or to the right. For that
1.4. LAB PROBLEMS 37

Figure 1.16: Coordinates of points on Wall-e's path.

we can use the =RANDBETWEEN(0,1) function in Excel. It returns


either 0 or 1 and each of these numbers is equally likely to appear.

We then use 0 to denote ↑ and 1 to denote →. In each move up, the y -


coordinate increases by 1 and x-coordinate remains constant. In each move
right, the x-coordinate increases by 1 and y -coordinate remains constant.
Note that we could have used =RANDBETWEEN(7,8) or any other two
subsequent integers and everything would work the same way.

Each new generated number has to cause a change in coordinates, since it


denes the direction of step. So we write the directions for the arrows: ↑
is [0,1] and → is [1,0]. In each move, starting from [0,0] we add the new
generated step and build the path as in Figure 1.17.

Figure 1.17: One of the possible randomly generated paths for Wall-e.

We can now hit the reload key (F9) a few times. Each time, this will
38 CHAPTER 1. COMBINATORICS

generate a new set of 0s and 1s that will determine the steps and we will
see a new path. A chart linked to the coordinates automatically updates
and draws the new path. Have you noticed something? We also see paths
that do not lead to Eve! This way it is possible to end up at coordinates
[4,4] or (even though not very likely) [0,8].

So how do we x this? There are a few options. In all of them, it is


helpful to count how many times have we stepped up or right (or both).
Once we reach the allowed number (e.g. three 0s), we can simply stop
accepting that digit and and the next time that digit is generated, we just
force the use of the other one (1 in this case). This can be done by using
the IF commands. Similarly, we can simply refuse to use the 1s that are
generated once we have enough of them and only use the next 0s.

Probability of paths
Note that if we generate the paths using the steps described in this
solution, not all of them are equally likely. Since we need more steps
to the right, but both directions are generated with the same proba-
bility, we will see more solutions which end in (are padded with) steps
to the right. Can you come up with a dierent way of generating the
individual paths, so that they are all equally likely? (The term for
this is generating them uniformly.)

So now that we have a functional simulation of Wall-e's walks, we can


think about calculating how many possible paths there are.

We have seen that the sequences of 0s and 1s are a useful tool in various
combinatorics problems. Even problems which originally do not have 0s
and 1s, can often be transformed into equivalent problems that do. Here
we do not even need to do that. We already have a sequence with ve
1s and three 0s. So to count the number of possible paths it is sucient
to calculate how many 8-bit sequences with ve 1s there are. Using the
8!
approach from the lecture, we get
5!3! .

General nal coordinates


Can you solve this problem for general Eve's coordinates? Her po-
sition would be given as input in two cells in your Excel sheet and
everything else would recalculate with respect to these coordinates.
Chapter 2

Divisibility and Algorithms in


Number Theory

2.1 Lecture overview

2.1.1 Divisibility
Problem 2.1 Horse-racing:
A journalist is preparing an article about a horse-race with 10 horses. He has
decided to prepare all possible articles for outcomes for the top four places in
advance so that he does not have to worry about work after the race. How many
articles does he have to prepare?

Solution: Using what we learned in the previous chapter, we know that the
answer to this problem is

 
10 · 9 · 8 · 7 10
= .
4·3·2·1 4

Combinatorial fractions that simplify to integers


In the previous chapter we have solved many problems similar to Problem 2.1
and in all of them the answer was a natural number. Of course, it should be,
since the number of possibilities is a whole number, but how do we know that
is always the case, when we have a fraction of this sort?

39
40 CHAPTER 2. NUMBER THEORY

n

Also, to calculate
k for large values of n and k we cannot use factorials,
i.e. the formula
 
n n!
= .
k k! · (n − k)!
The computer will have trouble calculating the factorials for large n and k . Eval-
uating a combination number in such case means reducing the multiplication
terms where possible and in order to do that, we need to understand divisibility.
In the following, we consider natural numbers with 0, denoted by N0 (see
Section 5.1.1), but the properties also hold for integers, denoted by Z (Section
5.1.2).

Divisibility
Let us have a, b ∈ N. divides b (and we write a | b) if and only if
We say that a
b = a·k for some suitable number We also say that a is a divisor of b
k ∈ N.
and that b is a multiple of a. (The notation a ∈ N means that number a belongs
to the set N.)

Divisibility properties
• If a|b and b | c, then a | c. We say that divisibility is transitive.
• If a | b, then for any number c, more precisely for any c ∈ N0 , it is true
that a | b · c. So if a divides b, it also divides its multiples.

• If a|b and a | c, then a | (b + c).

• If a|b and a | c, then a | (b − c).

Divisibility criteria
For some numbers we have simple criteria we can use to check whether a given
number is divisible by them. For number two, the criterion says: A number
is divisible by two if and only if its last digit divisible by two. For three, the
criterion says: A number is divisible by three if and only if the sum of its digits
is divisible by three. The criteria simplify the situation by reducing the size of
the problem. What other divisibility criteria do you know?
2.1. LECTURE OVERVIEW 41

2.1.2 Primes
Prime numbers
We call a natural number p a prime number if and only if it has exactly two
divisors: one and p. If it has more than two divisors, it is called a composite
number. Number one does not t into these categories and is neither prime nor
composite.

Innitely many prime numbers


There are innitely many prime numbers. We can prove this statement by
assuming the opposite: Suppose, there is a nite number of primes. Then
we can label them p1 , p2 , . . . , pn . And we can construct a new number M =
p1 · p2 · . . . · pn + 1. The number M must be a composite number because it is
larger than all known primes. Thus there must exist at least one prime number
which divides M. But which one is it? The number M gives a remainder 1 after
division by any prime pi . We get a contradiction. Our assumption was false.
Thus the opposite statement is true.

Goldbach's conjecture
This hypothesis states that every even number greater than 2 can be split into
sum of two primes. Despite great eorts of many mathematicians and use of
computers (at the time of writing this book, the conjecture has been tested up
to 400 000 000 000 000), this statement remains a hypothesis. It has not been
proven yet and no counterexample has been found yet.

Prime twins hypothesis


There exist innitely many prime twins, i.e. prime numbers that dier by 2.
Also this hypothesis has neither been proven nor rejected, yet.

Sieve of Eratosthenes  a method for searching for primes


This method comes from the ancient Greece. It involves writing out as many
natural numbers as we want (in order) and then using the following steps to
cross some of them out. Step 1: Cross out number 1. Step 2: Circle number 2
and cross out all its multiples. Repeat step 2 with every number has not been
crossed yet (3, 5, . . .). In the end, every number that is circled is a prime.
42 CHAPTER 2. NUMBER THEORY

How to check if a number is prime?


For a large n, it is not ecient to try whether it is divisible by all numbers

smaller than n. It is sucient to try all numbers not greater than n. Why?

Fundamental Theorem of Arithmetics


Every natural number a greater than 1, a ∈ N − {1}, can be uniquely (up to
the order of factors) written in the form

pα α2 α3 αn
1 · p2 · p3 · . . . · pn ,
1

where p1 , p2 , p3 , . . . pn are distinct prime numbers and α1 , α2 , α3 , . . . αn are nat-


ural numbers (not 0).

Problem 2.2 Factorisation into primes:


Find all divisors of the number 100? Write them as products of powers of primes.

Solution: First we factor 100 according to the Fundamental theorem of arith-


metics: 100 = 22 · 52 . The divisors are numbers 2α1 · 5α2 , where α1 ∈ {0, 1, 2}
and α2 ∈ {0, 1, 2}. There are nine possible pairs of α1 , α2 , therefore 100 has 9
divisors.

Number of divisors
For any pα α2 αn
1 · p2 · . . . · pn
1
we can calculate the number of its divisors using the
formula
(α1 + 1) · (α2 + 1) · . . . · (αn + 1).

Problem 2.3 Numbers with given number of divisors:


Which number has 6 divisors? Which has 12? Which has 7?

Hint: Starting with the denition of a prime number, we know that any num-
ber with two divisors is a prime. To have three, we need 1, the number and
something that multiplied by itself gives our desired number. That looks like a
square, e.g. 9 with divisors 1, 3, 9. Now it is easy to continue and get a number
with 4 divisors, e.g. 27 with 1, 3, 9, 27. However, the powers of primes are not
the only way how to go about it. We could use two dierent primes and their
product, e.g. 1, 2, 5, 10. Following this approach, it is possible to build numbers
with the desired number of divisors.
2.1. LECTURE OVERVIEW 43

Hasse diagram
The divisors of a number and relations among them can be displayed in a Hasse
diagram, Figure 2.1. We start with 1 at the bottom and the given number at
the top. We write and connect divisors from those that have the fewest prime
factors (counting their powers) to those that have the most observing the rule
that only direct multiples/divisors are connected, i.e. no lines going over a level.
This diagram is related to partial ordering that is covered in Section 7.1.1.

Figure 2.1: Hasse diagram. Note the correspondence between the divisors and
sequences of 1s and 0s.

2.1.3 Common divisors


Problem 2.4 Dancers:
Suppose we have a group with 24 dancers. What kind of rectangles can they
form? Now suppose we have a second group of 30 dancers. What kind of
rectangles can this group form? In which rectangular formations can the groups
join so that the resulting formation is also a rectangle?

Hint: The rst group can stand in a line and face the audience, this corresponds
to a rectangle 1 × 24. They can also stand in a row so that the audience sees
just the rst person, this corresponds to a rectangle 24 × 1. There are other
rectangles, e.g. three rows of eight people each, 8 × 3. Similarly, we can look at
the second group. Ultimately, we are looking for such a formation that has the
same number of rows (or lines) for both groups.

Greatest common divisor (GCD)


Take a, b ∈ N. If there is a number d ∈ N for which d | a and d | b, then we
say that d is a common divisor of a and b. The largest such d is called the
44 CHAPTER 2. NUMBER THEORY

greatest common divisor and is denoted GCD(a, b). GCD(a, b) can be found
by factoring a and b into product of prime numbers. If GCD(a, b) = 1, we say
that a, b are relatively prime or coprime.

Euclidean algorithm for nding GCD


Suppose we are looking for the greatest common divisor of numbers a and b. If
a > b, then GCD(a, b) = GCD(a − b, b). Similarly, if a < b, then GCD(a, b) =
GCD(a, b − a). We repeat these steps until we get the same numbers. These
represent GCD(a, b).
Here we illustrate how the algorithm works for two pairs of numbers:

GCD(247, 437) = GCD(437 − 247, 247) = GCD(190, 247)


= GCD(247 − 190, 190) = GCD(57, 190) = GCD(133, 57)
= GCD(76, 57) = GCD(19, 57) = GCD(38, 19)
= GCD(19, 19) = 19
GCD(437, 110) = GCD(327, 110) = GCD(217, 110)
= GCD(107, 110) = GCD(107, 3) = GCD(104, 3)
= GCD(101, 3) = GCD(98, 3) = . . . = GCD(2, 3)
= GCD(2, 1) = GCD(1, 1) = 1
Note that in the second case, the number 107 is the remainder when dividing
437 : 110 and 2 is the remainder when dividing 107 : 3.

Improved Euclidean algorithm for nding GCD


We are again looking for the greatest common divisor of numbers a and b. Let
a > b and z be the remainder after division a : b.
GCD(a, b) = GCD(z, b).
Then
Similarly if a < b and z is the remainder after division b : a, then GCD(a, b) =
GCD(a, z). We repeat these steps until we get z = 0. The non-zero number of
the nal pair represents GCD(a, b). Returning to the example we already saw:

GCD(437, 110) = GCD(107, 110) = GCD(107, 3)


= GCD(2, 3) = GCD(2, 1) = GCD(1, 0) = 1
Note that we could use the same stopping criterion (one number equal to
zero) for the slower, subtraction-based Euclidean algorithm if we performed
one additional step. This would ensure that also for edge-cases, such as nding
GCD(x, 0), the algorithm nishes in nite number of steps.
2.1. LECTURE OVERVIEW 45

Common multiples
Suppose a, b ∈ N and suppose there exists a number n∈N for which a|n a
b | n. is a common multiple of numbers a and b. We denote
Then we say that n
the smallest such number LCM (a, b) and call it least common multiple. It can
be found by factorisation of a and b into products of primes and is used, for
example, when adding fractions. An interesting property is that

GCD(a, b) · LCM (a, b) = a · b.

Remainder after division


We have already used the remainder after division in the Euclidean algorithm.
Here we specify it more precisely: Take a, b ∈ N and let a = b · k + z , where
k ∈ N is a suitable natural number and z ∈ {0, 1, 2, . . . , (b − 1)}. Then we say
that z is the remainder after division of number a by the number b. This is
sometimes denoted by z = rem(a, b).

Congruence
If the numbersa, b ∈ N have the same remainder after division by the number
m ∈ N, then we say that a and b are congruent modulo m and we write a≡b
(mod m). Some properties of congruence are:
• For all a, m ∈ N we have a ≡ a (mod m).
• For all a, b, m ∈ N, if a ≡ b (mod m), then b ≡ a (mod m).
• a, b, c, m ∈ N,
For all if a ≡ b (mod m) and b ≡ c (mod m), then a≡c
(mod m).
The congruence (mod m) is thus an equivalence relation in N (more on equiva-
lence relation can be found in Section 7.1.1). The set of natural numbers can be
split using the equivalence relation into groups of numbers that give the same
remainder after division by m. We call these groups congruence classes modulo
m.

Fermat's little theorem


Let p be a prime. Then for any natural number a is the number ap −a a multiple
of p, i.e. ap ≡ a (mod p). A generalisation of this theorem is used in the proof
of correctness of the RSA encryption.
46 CHAPTER 2. NUMBER THEORY

Some uses of divisibility and prime numbers


• Personal ID numbers in Slovakia - The format of these is yymmdd/aaab,
where the rst six digits represent the date of birth and also encode gender
in the mm digits (01-12 for males and 51-62 for females). The next three
digits are related to the registrar oce in the place of birth and the nal
digit is added so that the 10 digit number yymmddaaab is divisible by 11.
The divisibility by 11 can be veried as follows: the dierence of sums of
numbers on even and odd places has to be also divisible by 11 (problem
reduction). The reason for using divisibility by 11 is that if just one digit
of the ID number is compromised, e.g. a typo, the result is not another
valid ID number.

• IBAN - The format of the international bank account numbers is such


that a single typo or position exchange of two neighboring digits do not
result in another correct IBAN. The check relies on division by 97.

• Cryptography - Large primes are used for encryption. Some encryption


algorithms use the fact that factoring a product of two extremely large
prime numbers is a very time-consuming task. Some simple encryption
examples using primes inspired by Alan Turing, together with introduc-
tion into RSA (= Rivest, Shamir, Adleman - authors of the algorithm)
encryption, can be found in [6].

Showing that the Slovak ID rule works


Prove that if we change a single digit in a correct Slovak personal ID number
to a dierent digit, we do not get another valid ID number.
2.2. QUESTIONS 47

2.2 Questions

1. Decide whether the following statements are true:

a) 5 divides 10.

b) 10 divides 5.

c) 7 divides 490.

d) 10 is divisible by 5.

2. Decide whether the following statements are true:

a) If (x divides y and z divides y) then x+z divides y.


b) If (x divides y and x divides z) then x divides y + z.
c) If (x|y and z|y ) then x − z|y .
d) If (x|y and x|z ) then x|y − z .
e) If (x divides y and z divides y) then x·z divides y.
f ) If (x|y and x|z ) then x|y · z .
3. Write the criterion for divisibility by 11.

4. Explain how is IBAN protected against common typos.

5. How many dierent rectangular formations can 24 dancers form?

6. Every even natural number can be written as a sum of two prime numbers.
Check this statement for numbers from 10 to 30. For each of them, nd
all possible partitions.

7. How does the Sieve of Eratosthenes work?

8. Is the number 119 prime? Is 117 prime? Is 2017 prime?

9. How many divisors does the number 72 have? Draw the Hasse diagram
for them.

10. What does the Fundamental Theorem of Arithmetics say?

11. How many divisors does the number p31 · p52 · p23 have? (p1 , p2 and p3 are
distinct primes.)

12. Find the greatest common divisor of numbers 54 and 72.


48 CHAPTER 2. NUMBER THEORY

13. Find the smallest common multiple of numbers 54 and 72.

14. Find two natural numbers that are not primes but do not have a common
divisor other than 1.

15. How does Euclidean algorithm work and what is it for?

16. What is the largest remainder after division by 13?

17. What is the largest remainder after division by 12?

18. What is the smallest remainder after division by 6?

19. Two natural numbers m and n both give remainder 4 when divided by 5.

a) What is the remainder after division of m−n by 5?

b) What is the remainder after division of m+n by 5?

c) What is the remainder after division of m·n by 5?

20. For each natural number, we are only interested in its remainder after
division by 4. What groups will the numbers form, if we group them by
their remainder after division by 4?
2.3. PROBLEM SET 49

2.3 Problem set

1. Euclidean algorithm
Find all common divisors for the following pairs and triplets of numbers
using

• simple, subtraction-based, Euclidean algorithm

• faster, remainder-based, Euclidean algorithm

a) (350, 460, 820)

b) (85, 340)

c) (360, 450, 840)

d) (65, 420)

e) (1260, 300)

f ) (84, 210)

g) (3850, 198, 1764)

2. Number of divisors
For each of these numbers determine how many divisors it has:

a) 120

b) 760

c) 504

d) 1650

e) 840

3. Factorisation
Using the factorisation into prime numbers nd the greatest common di-
visor and the least common multiple for the pairs and triplets of numbers:

a) (84, 210)

b) (70, 165, 220)

c) (64, 180)

d) (50, 145, 310)

4. Reverse engineering
Write at least 3 numbers that have 2, 4, 5, 8, 10, 12, 15, ... divisors.
50 CHAPTER 2. NUMBER THEORY

5. Modulo equations
For which n are the following statements true?

a) 16 ≡ n (mod 7)

b) n ≡ 13 (mod 13)

c) 4 ≡ 13 (mod n)
d) 171 ≡ n (mod 71)

e) 7 ≡ 18 (mod n)
f) 10 ≡ 34 (mod n)
g) 6 ≡ 61 (mod n)
6. Systems of modulo equations
For which n are both statements true?

a) 12 ≡ 4 (mod n) and 15 ≡ 30 (mod n)


b) 10 ≡ 2 (mod n) and 10 ≡ 34 (mod n)
c) 4 ≡ 13 (mod n) and 7 ≡ 18 (mod n)
7. Hasse diagram
Find the divisors of numbers 6, 12, 15, 18, 24, 28, 36, . . . and display them
using a Hasse diagram.
2.3. PROBLEM SET 51

2.3.1 Hints and solutions


1. Euclidean algorithm
Find all common divisors for (85, 340) and (350, 460, 820) using

• simple, subtraction-based, Euclidean algorithm,

• faster, remainder-based, Euclidean algorithm.

Hints :
• To nd all common divisors we need to rst nd the GCD and then
all its divisors.

• In order to nd the GCD, the pairs of numbers can be treated directly
as shown in the Section 2.1.3.

Solution: Using the subtraction-based Euclidean algorithm we calculate:

GCD(85, 340) = GCD(85, 340 − 85) = GCD(85, 255)


= GCD(85, 255) = GCD(85, 255 − 85)
= GCD(85, 170) = GCD(85, 170 − 85)
= GCD(85, 85) = 85

Then we nd all divisors of 85 by trying out numbers smaller than 85.
Of those, only 1 and 5 divide 85. The remaining divisors are then 85:1 =
85 and 85:5 = 17.
These four numbers (1, 5, 17, 85) then also divide the number 340 and
there are no other common divisors.
If we wanted to use the remainder-based Euclidean algorithm, we would
be able to combine several steps of subtracting 85 into one step:

GCD(85, 340) = GCD(85, rem(340, 85)) = GCD(85, 0)


= 85

After that we proceed the same way as before by searching for all divisors
of 85.
Note that in this case, the remainder was 0, which means that we found
the answer in one step. If the remainder was non-zero, we would divide
again. In this case, we stop when one of the numbers is 0 (we cannot
divide any further). The other number is then the GCD. This stopping
criterion is universal and will work also for more general cases.
52 CHAPTER 2. NUMBER THEORY

What should we do when we have three numbers to consider? We would


like to modify the Euclidean algorithm to work with three numbers too.
Certainly, we can reduce the problem, by looking at a pair of numbers and
performing the subtraction:
GCD(350, 460, 820) = GCD(350, 460 − 350, 820) = GCD(350, 110, 820)
Whatever the GCD for the initial triplet of numbers was, it is the same
for the new triplet. As with the pair of numbers, we subtract a smaller
number from a larger number, but here we have more options to choose
a pair. We could consider 350 and 460. We could also start with 460 and
820. And of course, we could also start with 350 and 820. To save work,
it makes sense to perform such subtractions that lead to answers in small
number of steps, i.e. use the largest numbers, however, keep in mind, that
choosing any pair should lead to the same nal result. (Give it a try.)

GCD(350, 460, 820) = GCD(350, 460, 820 − 460)


= GCD(350, 460, 360) = GCD(350, 460 − 360, 360)
= GCD(350, 100, 360) = GCD(350, 100, 360 − 350)
= GCD(350, 100, 10) = GCD(350 − 100, 100, 10)
= GCD(250, 100, 10) = GCD(250 − 100, 100, 10)
= GCD(150, 100, 10) = GCD(150 − 100, 100, 10)
= GCD(50, 100, 10) = GCD(50, 100 − 50, 10)
= GCD(50, 50, 10) = GCD(50, 50 − 10, 10)
= GCD(50, 40, 10) = GCD(50 − 40, 40, 10)
= GCD(10, 40, 10) = GCD(10, 40 − 10, 10)
= GCD(10, 30, 10) = GCD(10, 30 − 10, 10)
= GCD(10, 20, 10) = GCD(10, 20 − 10, 10)
= GCD(10, 10, 10) = 10

All common divisors of numbers (350, 460, 820) are then divisors of num-
ber 10, i.e. numbers 1, 2, 5, 10.

How do we adapt the remainder-based Euclidean algorithm in a similar


2.3. PROBLEM SET 53

manner?

GCD(350, 460, 820) = GCD(350, 460, rem(820, 460))


= GCD(350, 460, 360)
= GCD(350, rem(460, 360), 360)
= GCD(350, 100, 360)
= GCD(350, 100, rem(360, 350))
= GCD(350, 100, 10)
= GCD(rem(350, 100), 100, 10)
= GCD(50, 100, 10)
= GCD(50, rem(100, 50), 10)
= GCD(50, 0, 10)
= GCD(rem(50, 10), 0, 10)
= GCD(0, 0, 10) = 10.
And again we proceed to nd all divisors of number 10.

The algorithms for three numbers presented here are suitable for com-
puter implementation. However, a human doing the calculations, would
probably work slightly dierently. Once we encounter GCD(50, 50, 10)
in the subtraction-based version, we can eliminate one 50 and continue
with GCD(50, 10). Similarly, once we encounter GCD(350, 100, 10) in
the remainder-based version, where we see that 100 is a multiple of 10, we
can eliminate the multiple and continue with GCD(350, 10).

Generalisations of Euclidean algorithm


Can you now state the generalised versions of both Euclidean algo-
rithms for three numbers?
How about a generalised version of a generalised version: Euclidean
algorithm for any nite set of numbers?

2. Number of divisors
Determine how many divisors does the number 120 have.

Hint: to determine the number of divisors, it would certainly be helpful


to know the factorisation of the number into prime numbers.

Solution: So let us rst factor the number 120 into prime numbers. We
start by the smallest prime numbers, factor them out if possible and con-
tinue towards the larger ones until we have factored the whole number.
54 CHAPTER 2. NUMBER THEORY

120 = 2 · 60 = 2 · 2 · 30 = 2 · 2 · 2 · 15 = 2 · 2 · 2 · 3 · 5. This can alternatively


be written as 120 = 23 · 3 · 5. In all the divisors, the factor 5 may or may
not be present  these are two options. Similarly, the factor 3 may or may
not be present and this gives us two more options. As for the 2s: we can
include none of them, one of them, two of them or all three of them 
four dierent possibilities. Altogether, to build a divisor, we have 2·2·4
options, which means that the number 120 has 16 divisors. (To make sure,
here they are: 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 24, 30, 40, 60, 120. If
we pick any of them, e.g. 24, we can determine which prime numbers are
included  here 2, 2, 3.)

3. Factorisation
Using the factorisation into prime numbers nd GCD(84, 210) and also
LCM (84, 210).
Hint : The LCM has to include all prime factors of both numbers in
question, but not more than necessary.

Solution: We factor the numbers 84 = 22 · 3 · 7 and 210 = 2 · 3 · 5 · 7. The


LCM denitely has to include 5, otherwise it would not be a multiple of
210. It has to include two 2s, since one would be sucient for the result to
be a multiple of 210, but we need another one for it to also be a multiple
of 84. Finally, the LCM also has to include 3 and 7, but it is sucient
to include them only once each, because they appear only once in each
factorisation.

To solve problems with more than two numbers, we need to collect all the
necessary primes across all numbers in the problem.

To nd the GCD using the factorisations, we simply collect the primes
(including their powers) that are in both factorisation (Unlike the union
we performed for LCM , now we are performing an intersection.) and we
calculate their product. In this case, 2 · 3 · 7 = 42.

4. Reverse engineering
Write at least 3 numbers that have 2, 4, 5, 8, 10, 12, 15, ... divisors.

Hint : First try this by manually looking for such numbers, then try to
build them.
Solution: To nd numbers that have 2 divisors, all we need to do is recall
that every number is divisible by 1 and by itself. Therefore to have only 2
divisors, it cannot be divisible by anything else. We even have a name for
2.3. PROBLEM SET 55

this kind of numbers  they are prime. So for example 2, 3, 83, ... have 2
divisors.

To nd numbers that have 3 divisors, we build on that. We already know


that two divisors will be for free, so we are looking for a number that has
one more divisor. Clearly if we have a divisor a, there is a co-divisor b,
such that a · b = number. And we must have b = a, because otherwise,
we would have another dierent divisor and their total would be 4. So we
can have 4 (divisors are 1, 2, 4) or 9 (divisors are 1, 3, 9) or any other
number of the form p2 (divisors are 1, p, p2 ).
To nd numbers that have 4 divisors, we can follow the same thought
process and arrive at p3 with divisors (1, p, p2 , p3 ), such as 8. But notice
that there are other numbers that do not t this recipe, e.g. divisors of
10 are 1, 2, 5, 10. This is due to the fact that 10 is not a power of a
single prime. Since its factorisation is 21 · 51 , its number of divisors is
(1 + 1) · (1 + 1).
If we want to nd numbers that have 12 divisors, we rst factor 12 = 1·12.
This will be one type of solutions  powers of a single prime. Then we
can factor 12 = 2 · 6. This will be second type of solutions p1 · p52 . We
can factor in yet another way 12 = 3 · 4 and this will be the third type of
solutions p21 · p32 .

Building numbers that have exactly 12 divisors


Can you nd still another type of numbers (not mentioned above)
that also have 12 divisors?

5. Modulo equations
For which n are the following statements true?

a) 16 ≡ n (mod 7)

b) n ≡ 13 (mod 13)

c) 4 ≡ 13 (mod n)

Hints :
• Try plugging in a few numbers for n and see whether the statement
holds. Find a few for which it holds and few for which it does not.

• For these problems it is very helpful to read them properly. For ex-
ample in the rst one, we are looking for such a number n which gives
56 CHAPTER 2. NUMBER THEORY

the same remainder as 16, when divided by 7. The same remainder


part is denoted by the sign ≡.
• What is the dierence between 16 ≡ n (mod 7) and n ≡ 16 (mod 7)?
• Can the number n be larger than 16?

• What is special about problem b)? If we read it carefully, we see


that we are looking for numbers that give the same remainder after
division by 13 as 13 does. In other words, we are looking for multiples
of 13.

• We would read problem c) as Which number do we need to divide 4


and 13 by in order to get the same remainder?
Solution: Looking at the rst problem, the rem(16, 7) = 2. Which other
number gives the same remainder? Number 9, since 7 · 1 + 2 = 9. Clearly,
this is not the only solution, we also have 7 · 3 + 2 = 23 and many more.
Number 2 is among them, since 7 · 0 + 2 = 2. Can you write these numbers
using one common description? The set of solutions is thus {7 · k + 2, for
all k ∈ Z}.

Looking at the third problem, we see that we are now looking for such a
number that 4 and 13 give the same remainder when divided by it. This
means that 4 = a · n + rem and 13 = b · n + rem. To get rid of the
unknown rem, which is the same for both numbers, we can subtract these
two equations and get 13 − 4 = 9 = (b − a) · n. Therefore n has to be
a divisor of 9. We can check them all to see that they indeed make the
statement 4 ≡ 13 (mod n) true. Thus this problem has three solutions: 1,
3 and 9.

Unknown n at two places


Combine the insights from the two types of problems just discussed
and nd all values of n which make 15 ≡ n (mod n) true.

6. Systems of modulo equations


For which n are both statements true?
12 ≡ 4 (mod n) and 15 ≡ 30 (mod n)
Hint : This problem consists of two equations of the type discussed in the
previous problem. Try solving them individually. Once you have the two
sets of solutions, the correct values of n have to appear in both of them,
since both of the statements have to be true at the same time.
2.3. PROBLEM SET 57

7. Hasse diagram
Find the divisors of 28 and display them using a Hasse diagram.
Solution: The divisors of 28 are 1, 28, 2, 14, 4, 7. The corresponding

Hasse diagram, Figure 2.2 is constructed by placing 1 at the bottom of


the diagram and 28 at the top. We place the prime divisors above 1. The
next level are the numbers composed of two primes. We would proceed
in this fashion, if we had more divisors. In our case, the second level is
connected to 28.

Figure 2.2: Hasse diagram for divisors of 28.


58 CHAPTER 2. NUMBER THEORY

2.4 Lab problems

1. Subtraction-based Euclidean algorithm


• Create an Excel sheet that will compute the GCD for any pair
(triplet) of positive integers. Optimise the algorithm speed for the
triplet of numbers.

• Indicate when the algorithm found the GCD and how many steps
were necessary.

2. Remainder-based Euclidean algorithm


Solve the same problems for nding GCD with the Euclidean algorithm
that uses remainders after division.

3. Spirolaterals
Create an Excel sheet that for a given n draws its spirolateral. Spirolateral
is a polyline which changes direction with a constant angle at each step, see
e.g. [2]. For this problem we consider 90 degrees angle, i.e. four directions.

4. Prime numbers
• Write a program that tests whether a number n is prime. Give a
statement about computational complexity of your algorithm.

• In a given time limit, write down the largest prime number that you
can and a method for verication (using a PC) that it is indeed a
prime.

• In a given time limit, write down the largest composite number and
its factorisation and a method for verication (using a PC) that the
factorisation is correct.
2.4. LAB PROBLEMS 59

2.4.1 Hints and solutions


1. Subtraction-based Euclidean algorithm
• Create an Excel sheet that will compute the GCD for any pair
(triplet) of positive integers. Optimise the algorithm speed for the
triplet of numbers.

• Indicate when the algorithm found the GCD and how many steps
were necessary.

Hints :
• When looking for GCD(a, b) using the Euclidean algorithm, we in-
tuitively subtract the smaller number from the larger number. (Here
we are using the property that GCD(a, b) = GCD(b, a).) For this to
work in Excel, we need to specify which number is subtracted from
which. It is also possible (but not necessary) to write the formulas
in such a way that larger numbers appear in the same column and
smaller numbers in the next column.

• The whole algorithm should proceed until a = b, therefore, we can


check the previous line for this and if this happens, stop and report
the result.

• The Excel function COUNT can be used to determine how many


cells in a given column are non-empty and thus indicate the number
of steps needed.

• When working with three numbers, for the nal result, it does not
matter which two of them we choose for subtraction. This choice
manifests itself in the number of steps needed. If we choose numbers
that are close to each other, the result after subtraction is small.

Solution :
• Start with numbers a, b, see Figure 2.3.

• In the next line, we can for example use the formulas =MAX(ABS(a−
b);MIN(a, b)) and =MIN(ABS(a − b);MIN(a, b)), where a, b are the
numbers in the previous line. This ensures that the dierence is
always positive and always written on the left. (Other formulas are
possible.)

• Copy this formula down.


60 CHAPTER 2. NUMBER THEORY

• In the next column, check if the work should stop =IF(a = b; a; ).
This will write the greatest common divisor. This condition can also
be combined with the previous formulas and the process will stop
at the GCD. If we do it this way, we can use COUNT to nd out
number of steps necessary for calculation.

Figure 2.3: Calculation of the greatest common divisor and the number of steps
needed. Input is denoted in yellow (row 2), output in green (column D).

2. Remainder-based Euclidean algorithm


Solve the same problems for nding GCD with the Euclidean algorithm
that uses remainders after division.

Hint : Modify the sheet from previous problem and use division instead of
subtraction. The function MOD(a, b) gives rem(a, b). Note that it is also
important to change the stopping criterion. This time we nish, when one
of a, b is 0, as in Figure 2.4. The other number is then the GCD.

Figure 2.4: Calculation of the greatest common divisor and the number of steps
needed using the remainder-based Euclidean algorithm. Input is denoted in
yellow (row 2), output in green (column D).
2.4. LAB PROBLEMS 61

Most steps needed


Using the created sheets for the two algorithms, nd the pair (triplet)
of numbers from 1 to 100 (1 to 500, . . .) for which the algorithms
needed the most steps.

3. Spirolaterals
Create an Excel sheet that for a given n draws its spirolateral. Spirolateral
is a polyline which changes direction with a constant angle at each step, see
e.g. [2]. For this problem we consider 90 degrees angle, i.e. four directions.

Hints :
• Write multiples of n and the sums of their digits.

• Cyclically add the sum of their digits to the current position of the
pen as multiples of the directional vector N/E/S/W. The origin is at
[0,0]. Draw the spirolateral as an x-y chart.

• Examine the shapes and symmetries of the chart for dierent n. For
which n do we get the same charts? For which n do we get symmetric
graphs?

Sum of digits vs. divisibility by 9


Prove that for all integers n that are not multiples of 9, the repeated
sum of their digits is equal to the remainder after division n:9. By
repeated sum of digits we mean that we repeat the sum of digits until
we get a one-digit result, e.g. 64 → 10 → 1.

Solution :
• While it is easy to write a formula for multiples of n (column B in
Figure 2.5), the sum of digits (column C) is a trickier problem. There
is no simple function for this in Excel. We could write a complicated
expression that relies on several built-in Excel functions, but instead,
we are going to use the property described in the previous grey box.
The repeated sum of digits of any integer n that is not a multiple
of 9 is equal to the remainder after division n:9. For multiples of 9,
we can use a logical test =IF(MOD(B4;9)=0;9;MOD(B4;9)). This
number now represents the length of the step.

• To determine the direction of the step, we rst assign the rst four
directions: [0,1] for North, [1,0] for East, [0,-1] for South and [-1,0]
62 CHAPTER 2. NUMBER THEORY

for West. These will be cyclically repeated, so we can use formulas,


e.g. in H7 use =H3 and copy down. The same can be done for the I
column. The directions now repeat every four steps.

• The origin is at [0,0]. The new x and y coordinates are then calculated
by taking the previous coordinates and adding to them a step of a
given length in a given direction. Note that due to the direction
vectors, each of which has one 0 coordinate, only one of the x, y
changes in each step. This means that for example in line 5, we are
at the position [8,1] and move 7 steps south by adding 7 · [−1, 0].
After this step, we are at coordinates [1,1], line 6.

• Once the trajectory returns to [0,0], we draw a scatter plot with lines.
The chart should look similar to the one in Figure 2.5.

Figure 2.5: Calculation and chart of the spirolateral for n = 4.

Other interesting things to do with spirolaterals


What happens (and why), when we use a decimal number instead of
an integer n?
Also try changing the directions from N/E/S/W to NE/SE/SW/NW
to see what happens with the resulting charts.

4. Prime numbers
Hints :
2.4. LAB PROBLEMS 63

• This task can be done better by programming, e.g. in python, than


in Excel. The numbers to check are all the prime numbers smaller
√ √
than n. √n, the compu-
If we checked all numbers smaller than
tational complexity (in the worst case) would be O( n). For more
information about the computational complexity and the O -notation,
see Section 12.1.1. Since we are checking only primes, we expect the

algorithm to be better than O( n).
Note that in practice, the primes are tested by even more sophisti-
cated and ecient methods.

• Good place to start looking for primes is


https://primes.utm.edu/largest.html.
64 CHAPTER 2. NUMBER THEORY
Chapter 3

Finite state automata and


Turing machines

3.1 Lecture overview

Problem 3.1 River crossing problem:


A farmer (F) wants to get across the river in a boat. He or she also needs to
take a wolf (W), a goat (G) and a cabbage (C). Only one of these can be with
the farmer in the boat at any given time, since the boat is small and the farmer
is the only one who can row. Without the supervision of the farmer, the wolf
eats the goat and the goat eats the cabbage. How should the farmer transport
W, G and C so that nothing gets eaten in the process?

Solution: First we write out all admissible situations/states on the riverbanks:

1. (FWGC, ∅)

2. (∅, FWGC)

3. (FWG, C)

4. (FWC, G)

5. (FGC, W)

6. (C, FWG)

65
66 CHAPTER 3. AUTOMATA AND TURING MACHINES

7. (G, FWC)

8. (W, FGC)

9. (FG, WC)

10. (WC, FG)

Then we draw a diagram, such as the one in Figure 3.1, where the individual
situations are connected with lines that represent transitions between them. We
can then nd a path in this diagram that connects the states 1 and 2.

Figure 3.1: Situations/states and transitions between them in the river crossing
problem.

Problem 3.2 Trac lights:


Draw a diagram for trac lights that can be red, yellow and green.

Solution: The three states and transitions between them are shown in Figure
3.2.

Problem 3.3 Open/close problem:


Consider a valve with two states: open and closed. Draw a diagram with possible
transitions.
3.1. LECTURE OVERVIEW 67

Figure 3.2: A trac light with three colors that represent the states. The arrows
denote the transitions between the states.

Figure 3.3: An open/close valve.

Solution: If the valve is open, it remains open until somebody/something closes


it. It then remains closed until somebody/something opens it, see Figure 3.3.

Problem 3.4 Parity problem:


Alice is reading a very long sequence of 0s and 1s. Bob is listening to her, but
he has a very bad memory. There is a light with a switch in the room. How can
Bob use it so that when Alice is done reading, he will be able to whether there
was an even or an odd number of 1s?

Solution: This light has two states: on (E) for even and o (O) for odd number
of 1s. At the beginning we are in state E (Bob switches the light on), because
so far there are zero digits and that means even number of 1s. As Alice reads
the individual digits, Bob switches the light on and o, transitioning between
the states E and O depending on whether Alice read 0 or 1. The digit 1 means
a transition to the other state (using the switch), the digit 0 means that we
remain in the current state (doing nothing). If the light is on (state E) at the
end of the reading, the sequence had an even number of 1s. If the light is o
68 CHAPTER 3. AUTOMATA AND TURING MACHINES

(state O), the sequence had an odd number of 1s.

3.1.1 Finite state automata


Finite state automaton
A nite state automaton (FSA), sometimes also called a nite state machine,
is a simple theoretical model of a computer that solves a task using a given
algorithm. The task is to read an input word and correctly determine whether
it belongs to the acceptance set. FSA has

• an alphabet of letters, this is usually {0, 1}, which are used in words.
• a nite set of states S = {s0 , s1 , s2 , . . . , sn }. The automaton starts in the
initial state s0 , reads the whole word, changes states in the process and
then stops. Some of the states are acceptance states  if the automaton
stops in these, it means that the input word is accepted.

• a set of transition rules that let it get from one state to another. A
transition depends on the combination of the current state and the current
letter of the word that is being read. The transition rules are either
written directly or in a table (matrix) or they can be drawn in the form
of a diagram. The diagram is more readable for humans, the table for
computers.

Problem 3.5 Automaton which accepts words ending with 0:


Find the transition rules for an automaton which accepts the words ending with
0. The alphabet is {0, 1}.

Solution: We use states s0 and s1 . s0 corresponds to last read digit was 0 and
s1 corresponds to last read digit was 1. The state s0 is an acceptance state. The
transition rules are:

[s0 , 0] → s0
[s0 , 1] → s1
[s1 , 0] → s0
[s1 , 1] → s1
The same rules can also be written in a table:

0 1
s0 s0 s1
s1 s0 s1
3.1. LECTURE OVERVIEW 69

And the same rules can also be depicted in a diagram, Figure 3.4. Note that
there have to be both arrows with 0 and with 1 coming out of each state. It is
worth checking this property for the diagrams you draw to prevent mistakes.

Figure 3.4: FSA that accepts words ending in 0. Note how similar this Figure
is to Figure 3.3.

Problem 3.6 Automaton which accepts words starting with 110:


Find the transition rules for an automaton which accepts the words starting
with 110. The alphabet is {0, 1}.

Solution: The states are s0 =I do not know anything, s1 =word starts with 1,
s2 =word starts with 11, s3 =input is ok and s4 =input is not ok. The state s3 is
an acceptance state. The transition rules are:

[s0 , 0] → s4
[s0 , 1] → s1
[s1 , 0] → s4
[s1 , 1] → s2
[s2 , 0] → s3
[s2 , 1] → s4
[s3 , 0] → s3
[s3 , 1] → s3
[s4 , 0] → s4
[s4 , 1] → s4

The diagram of this automaton is depicted in Figure 3.5.

Problem 3.7 Automaton which accepts words ending with 110:


Find the transition rules for an automaton which accepts the words ending with
110. The alphabet is {0, 1}.
70 CHAPTER 3. AUTOMATA AND TURING MACHINES

Figure 3.5: FSA that accepts words starting with 110.

Solution: The states are s0 =last digit was 0 or nothing, s1 =last digit was 1,
s2 =last two digits were 11 and s3 =last three digits were 110. The state s3 is an
acceptance state. The transition rules are:

[s0 , 0] → s0
[s0 , 1] → s1
[s1 , 0] → s0
[s1 , 1] → s2
[s2 , 0] → s3
[s2 , 1] → s2
[s3 , 0] → s0
[s3 , 1] → s1
The diagram of this automaton is depicted in Figure 3.6.

Figure 3.6: A diagram of a nite state automaton that accepts words ending
with 110.
3.1. LECTURE OVERVIEW 71

Problem 3.8 Automaton which represents volleyball matches with


two sets:
Consider the alphabet {H, G} (home team, guests). Then consider the words
with letters H, G that represent the sequences of sets won by home team and
by guests. Find the transition rules for an automaton which accepts all correct
outcomes of a best-of-three match.

Solution: The states are 0:0, 0:1, 1:0, 1:1, 2:0, 0:2, 1:2 and 2:1. The states with
2 are acceptance states. The transition rules are:

[0 : 0, H] → 1 : 0
[0 : 0, G] → 0 : 1
[0 : 1, H] → 1 : 1
[0 : 1, G] → 0 : 2
[1 : 0, H] → 2 : 0
[1 : 0, G] → 1 : 1
[1 : 1, H] → 2 : 1
[1 : 1, G] → 1 : 2

The diagram of this automaton is depicted in Figure 3.7.

Figure 3.7: FSA which represents best-of-three matches.


72 CHAPTER 3. AUTOMATA AND TURING MACHINES

There are problems a FSA cannot solve


An example of problem which a FSA cannot solve, is to recognise the set of
words:
n n
z }| { z }| {
n n
0 1 = 00 . . . 0 11 . . . 1
for arbitrary n. In order to do that, we would have to use the states (we do not
have anything else at our disposal) to count the number of 0s at the beginning
of the word. The thing is that n can be arbitrarily large, which is in conict
with the nite number of states.
Can you design a FSA that accepts words of the type 0n 1n , where n is at
most 100?

3.1.2 Turing machines


What is a Turing machine?
The idea of Turing machine (TM), Figure 3.8, as a theoretical computer model
dates back to the year 1937. Similarly to the FSA, a Turing machine can
accept words that have given properties (even some properties that were too
complicated for FSA) but it can do more than that. It can perform a calculation
or operation and write their results on an input/output tape. The Church-
Turing hypothesis states that anything we can calculate by any algorithm, can
be done using a Turing machine.

• The alphabet of a TM is usually {0, 1, t}, where t represents an empty


space.

• The input/output tape is as long as needed (sometimes it said that it is


innite). At the beginning of the calculation, there is a nite word written
on the tape. The rest of the tape is empty.

• The TM has a head that can read and write the symbol at its current
location. At the beginning of the calculation, the head is at the rst
symbol of the input word. The head may stay in place, but it can also
move one place to the left and one place to the right (N, L, R).

• The TM has a nite number of states among which is the initial state s0
and some nal states sk1 , sk2 , sk3 , . . .. Some nal states may be acceptance
states.
3.1. LECTURE OVERVIEW 73

Figure 3.8: A ctitious illustration of Turing machine with an innite tape, a


reading head and an engine that performs instructions and remembers a state
in which it is.

• The TM has unambiguous instructions (rules) for each pair (state, symbol)
in the format:
(state, symbol on the tape) → (new state, write symbol, move)

• There are several ways how a TM can nish a task. If there is no instruc-
tion for a given combination of a state and a symbol, TM stops. In some
cases it might be important in which state it stopped  whether it was an
acceptance state or not. In other cases, the nal state is not important
but the output written on the tape is.

Problem 3.9 Turing machine for negation:


Create a Turing machine that can negate each bit of a binary number, i.e. it
replaces 1s with 0s and 0s with 1s.

Solution: It is sucient to have two states. The state s0 is an initial state and
we remain in it while we traverse and overwrite the input word. When we read
either 0 or 1, we replace them with the other symbol and move the head onto
the next symbol. If we read an empty symbol, we know we are at the end of
the word. At this point, the head does not do anything more, except it changes
its state into the nal state s1 for which we do not have any more instructions.
The result is written on the tape.
74 CHAPTER 3. AUTOMATA AND TURING MACHINES

state symbol on the tape new state write symbol move


s0 0 s0 1 R
s0 1 s0 0 R
s0 t s1 t N

Problem 3.10 Turing machine for multiplication by two:


Create a TM that multiplies a binary number by two.

Solution: Binary multiplication essentially translates into adding a 0 at the end


of the number. The alphabet is {0, 1, t}, states are s0 , s1 , where s0 is initial.
The instructions are:

state symbol on the tape new state write symbol move


s0 0 s0 0 R
s0 1 s0 1 R
s0 t s1 0 N

These instructions can also be written as:

(state, symbol on the tape) → (new state, write symbol, move)


(s0 , 0) → (s0 , 0, R)
(s0 , 1) → (s0 , 1, R)
(s0 , t) → (s1 , 0, N)

Problem 3.11 Turing machine for adding one:


Create a TM which adds 1 to a binary number.

Solution: This machine moves to the end of the word rst, then adds 1 and then
carries over if necessary. The alphabet is {0, 1, t}, states are s0 , s1 , s2 , where s0
is initial and s2 is acceptance state. Once TM reaches s2 , the result is written
on the tape. The instructions are:

state symbol on the tape new state write symbol move


s0 0 s0 0 R
s0 1 s0 1 R
s0 t s1 t L
s1 1 s1 0 L
s1 0 s2 1 L
s1 t s2 1 N
3.1. LECTURE OVERVIEW 75

Problem 3.12 Turing machine that can do more than a FSA:


Create a Turing machine that accepts numbers in the format:

n n
z }| { z }| {
00 . . . 0 11 . . . 1 .

Solution: The alphabet is {0, 1, t}, states are s1 , s2 , s3 , s4 , s5 , s6 , where s1 is an


initial state and s6 is an acceptance state. If the automaton stops in any other
state, the word is not accepted. This machine erases pairs of numbers  always
one 0 and one 1. It gets to the acceptance state if there is nothing left when it
cannot erase another pair. The instructions are:

state symbol on the tape new state write symbol move


s1 0 s2 t R
s2 0 s2 0 R
s2 1 s2 1 R
s2 t s3 t L
s3 1 s4 t L
s4 0 s4 0 L
s4 1 s4 1 L
s4 t s5 t R
s5 0 s2 t R
s5 t s6 t N

Innite cycles
It is possible to create TMs that fail to halt, e.g. a TM that moves to the right
without writing anything or changing its state. Moreover, in general it is not
possible to determine whether an arbitrary TM halts for an arbitrary input. In
computability theory, this is called the halting problem.

A brief reminder about the binary system


When performing conversion from decimal to binary system we have: 110 is 12 ,
210 is 102 , 310 is112 , 410 is 1002 , 510 is 1012 , etc. Note that powers of two are
all of the form 100..0002 . Why?

State
Here we return to one concept which we encountered both when working with
the FSA and with TMs. It is dicult to precisely dene what a state can
76 CHAPTER 3. AUTOMATA AND TURING MACHINES

represent. As we saw in the problems, the states and transition rules comprise
the inner logic of the automaton, which depends on the task for which it was
designed. And for the same task, it is possible to design dierent machines.
The state is the inner situation or setting of the FSA or TM. It can represent
a typical activity being currently performed (e.g. a TM head is moving to the
end of the binary word), some quantity (e.g. the parity of the number of 1s in
the word being currently read), current situation of the object represented by
the automaton (e.g. a closed valve) or something completely else depending on
how we designed the machine.
3.2. QUESTIONS 77

3.2 Questions

1. Write all admissible states for the problem of transferring a man, a goat
and a wolf to the other side of the river using a boat for two.

2. Write at least four admissible states for the problem of transferring a man,
a goat, a wolf and a cabbage to the other side of the river using a boat for
two.

3. Write at least four admissible states for the problem of transferring a man,
a goat, a sheep, a cabbage and a wolf to the other side of the river using a
boat for three. (Wolf eats both goats and sheep and both goats and sheep
eat cabbage.)

4. Write at least four admissible states for the problem of transferring a man,
a woman, a cabbage, a goat, a sheep and a wolf to the other side of the
river using a boat for three. (Wolf eats both goats and sheep and both
goats and sheep eat cabbage. Both people can row and take care that
nothing gets eaten on their watch.)

5. Draw all possible transitions between the closed and open states of a valve.
6. Propose a FSA for determining the parity of number of 1s in any binary
word.

7. Propose a FSA for determining the parity of number of 0s in any binary


word.

8. What is nite in a FSA? What is its alphabet ?


9. What do state and initial state mean in the denition of a FSA?

10. What does acceptance state mean in the denition of a FSA?

11. What does a Turing machine consist of ?

12. How long is the input/output tape of a Turing machine?

13. What is the most commonly used alphabet of a Turing machine?

14. What is the dierence between a Turing machine and a FSA?

15. What does Church-Turing hypothesis say about a Turing machine?


78 CHAPTER 3. AUTOMATA AND TURING MACHINES

3.3 Problem set

River-crossing problems
1. A mother M with two children  a son s and a daughter d  stand at a
river bank. They have a small boat, which can carry at most one adult
person or two children. Children can row. How can they all get to the
other side of the river?

2. Two people, a big ape and a small monkey stand on the riverbank. Only
people and the ape can row. In any moment there cannot be more animals
than humans standing on a riverbank. Only two creatures t into the boat.
Animals can jump in and out of the boat by themselves. How can they
all get to the other side of the river?

3. Two parents with two children  younger and older son  stand on a
riverbank. The boat is small and can carry at most one adult person or
two children. Children can row. How can they all get to the other side of
the river?

4. Three people, one big ape and two small monkeys stand on a riverbank.
Only people and big ape can row. In any moment there cannot be more
animals than humans standing on a riverbank. Only two creatures t into
the boat. Animals can jump in and out of the boat by themselves. How
can they all get to the other side of the river?

5. Three missionaries and three cannibals stand on a riverbank. The boat


can carry two people. We cannot allow more cannibals than missionaries
at the riverbank, because the cannibals would eat the missionaries. How
can they all get safely to the other side of the river?

Finite state automata


6. Write and draw a FSA which accepts words starting with 1010.

7. Write and draw a FSA which accepts words ending with 101.

8. Write a FSA which accepts words containing 111.

9. Write a FSA which accepts words containing 010.

10. Write a FSA which accepts words containing 010 and not containing 011
(both conditions must hold).
3.3. PROBLEM SET 79

11. Write a FSA which accepts words starting with 1010 and ending with 111.

12. In the previous problems, change the text FSA which accepts words to
FSA which does not accept words.
13. Write a FSA which accepts words with even number of 0s and odd number
of 1s.

14. Write a FSA which recognises correct game outcomes, when playing vol-
leyball for three winning sets.

Turing machines
15. Write instructions for a Turing machine which performs binary XOR op-
eration of the word on the tape with a (ctitious) word 111...111 of the
same length.

16. Write instructions for a Turing machine which performs binary XOR op-
eration of the word on the tape with a (ctitious) word 000...000 of the
same length.

17. Write instructions for a Turing machine which multiplies the binary num-
ber written on the tape by 4.

18. Write instructions for a Turing machine which adds 2 to the binary number
written on the tape.

19. Write instructions for a Turing machine which divides the binary number
written on the tape by 2 (and rounds down).
80 CHAPTER 3. AUTOMATA AND TURING MACHINES

3.3.1 Hints and solutions


River-crossing problems
First we need to write admissible states, the transitions between them and nd
a path in the graph from the initial to the nal state. If it is not clear how to
start or continue with the problem, we can try the following steps. Read them
only until it is clear how to continue!

Hints :
a) We simplify the problem by translating it into the language of states and
transitions between them. The states correspond to dierent arrangements
of people (and animals/things) on the riverbanks. The transitions are done
using admissible boat transfers.

b) Which state represents the initial situation and which state corresponds
to a successful solution?

c) We need to think about the representation of all possible states which


can arise in the problem, including all theoretical options. Some of them
might not be actually used but we will take care of them later. What does
each state have to clearly determine? We should also decide if we need to
include only people or also animals/things.

d) Then we make a list of all the states, thinking carefully about its organi-
sation. We should be able to explain and conrm that the list is complete
and that there is nothing missing from it. It should be transparent enough
for easy examination of transitions between states. There should be ap-
proximately 10 to 20 states in this problem.

e) Once our list of states is complete, we draw them as vertices of a simple


graph into which we can also draw the transitions. If we do not know the
structure of the graph in advance, we can draw the vertices in a circle.

f ) Using our list, we start examining from which state can we get to which
other state(s). We join the respective vertices by an edge. We should
do this examination in such a way that we do not forget any transition
and also do not examine the same transition too many times. Are the
transitions one-way or two-way? Does this distinction help with examining
the transitions?
3.3. PROBLEM SET 81

g) Once we have a graph, we can nd a path from the initial to the nal
state. Graphs in these problems are not too complicated and it should be
possible to nd the path without going into graph theory algorithms.

h) Check carefully whether it is truly possible to follow the path through the
states that we have found. When solving problems such as these, it is a
common mistake to underestimate the state description part. If necessary,
we should return to points b) and c).

1. A mother M with two children  a son s and a daughter d  stand at a


river bank. They have a small boat, which can carry at most one adult
person or two children. Children can row. How can they all get to the
other side of the river?

Solution:
In this solution we translate the problem into the language of states, tran-
sitions between them and nding the path from the initial to the nal
state. We show our steps that lead to a surprise, but this is not the only
solution.

a) The individual states correspond to the placement of people on the


riverbanks. It is helpful to look for a reasonably sorted and clear way
to write the states. We have created the following list:

s0 : M, d, s | | ...
s1 : M, d | | s
s2 : M, s | | d
s3 : d, s | | M
s4 : M | | d, s
s5 : d | | M, s
s6 : s | | M, d
s7 : ... | | M, d, s
• What kind of system have we used to write out these states?

• Are we certain that we did not miss any state (that we have them
all)? Why?

• What is the initial state? What is the acceptance state? Do we


know if there is a nal state?

It is possible to create a dierent ordered list of these same states


and solve the problem with it.
82 CHAPTER 3. AUTOMATA AND TURING MACHINES

b) The transitions between pairs of states correspond to the allowed boat


transfers. We can draw the states as vertices of a simple graph and
represent the permissible transitions as edges. Let us rst examine
the transitions from state s0 . In this situation M , d, s or d + s can
row to the opposite riverbank. So we can get to states s3 , s2 , s1 or
s4 . The second approach is to go through the state list s1 to s7 and
for each state check whether we can get into it from s0 . The result
should be the same. Then we continue with s1 and the rest. Before
we do that though, try to answer the following questions:

• We have noted that it is possible to transition from s0 to s1 .


Does it mean we can also go from s1 to s0 ?
• If we join s0 and s1 in the graph by an edge, do we need to denote
the orientation of this edge?

• When we analyze the state s1 (and then s2 , s3 , ...), is it necessary


to check also the transitions to the previous states?

Finish the analysis of states and draw them into a graph. Repeat the
steps for your own list of states.

c) For our list of states, we got a graph shown in Figure 3.9. Our task
now is to nd a path from s0 to s7 . There are multiple such paths,
e.g. s0 → s3 → s7 or s0 → s4 → s7 or a longer one s0 → s2 → s6 →
s7 . We see that the problem has more than one solution. Can you
estimate the number of solutions?

d) Now we check the solutions that we found. First, let us look at


s0 → s3 → s7 . In this case, the M transfers from the left riverbank
to the right, and in the second step d+s row from the left riverbank
to the right. However, they cannot do that, since they do not have a
boat! The boat is on the other side of the river, with their mother.
Our solution has a huge aw and for the same reason also the other
solutions will not work. Why is our solution incorrect? What did we
forget when we were describing the states?

e) Create a list of states which also consider the boat position. If we


leave out unreasonable states (a boat alone on the riverbank), we
should get 14 states. Solve the problem using the steps a) to d) with
these correct states. There will be more transitions but they should
result in the correct solution.

f ) Consider if it is important to distinguish between the son and the


daughter. Will the solution be simpler, if we just have two children
3.3. PROBLEM SET 83

Figure 3.9: Graph that represents the states and transitions in the boat problem.

and do not know anything about their gender? If we only consider


the number of children on the riverbanks, 10 states will suce. Solve
the problem for this situation.

Finite state automata

Hints :
When drawing graphs of state automata, there are no simple and universal
hints. To create the automaton is similarly dicult to (and sometimes even
more dicult than) writing a corresponding computer program. We oer the
following hints and recommendations:

a) The initial state s0 corresponds to the beginning of the reading. We can


stay in this state until something interesting starts happening.
b) The state should start paying attention when it reads the characters of
the desired sequence and use subsequent states to monitor how far into
the sequence has the automaton gotten into.

c) Once the FSA is done, check if it is complete, i.e. whether for each state
and each admissible letter of the alphabet there is a transition rule.
84 CHAPTER 3. AUTOMATA AND TURING MACHINES

d) If we are interested in a sequence at the beginning of a word, once we


found it, we are done and we can remain in the acceptance state. On the
contrary, if the search was unsuccessful, we can go to the reject state and
remain there.

e) If we are looking for a sequence at the end of the word, even if we nd
such a sequence, the next letter can throw away this success. Still it does
not land us in a reject situation, we just need to return to one of the
previous states, not necessarily the initial one. Consider a search for an
end sequence 0011 and a hopeful state 001. If we now get the letter 0, we
do not return to the initial state because we already have the rst letter
of the desired sequence.

f ) There are other types of problems besides those mentioned in d) and e)


and there is no universal solution. The approach should be a modication
of the reasoning shown above.

6. Write a FSA that accepts words starting with 1010.


Solution: Follow these steps only to the point from which you can continue

on your own:

a) The initial state s0 corresponds to the beginning of the reading. Since


we are interested in the sequence 1010 at the beginning of the world,
we go to the state s1 when we read the rst letter 1. How to proceed
from here?

b) From the state s1 we go to state s2 , when we read the next 0, then


to state s3 , when we read 1 and then to state s4 , if we read letter 0.
What have we read so far?

c) If we are in s4 , this means we have read the sequence 1010 at the


beginning of the word. This is the nal accepting state. However, the
description of states and transitions between them is not complete
yet.

d) If the beginning of the word is 1010, the outcome will not change no
matter what the subsequent letters are. So we remain in the state s4
even if we read another 0 or 1. Is the description of the FSA complete
now?

e) For each state s0 , s1 , s2 and s3 we only have one transition that


corresponds to reading the correct sequence 1010. If at any point we
read anything else, the word cannot be accepted. In those cases, we
3.3. PROBLEM SET 85

transition into a common garbage state s5 . This is also a nal but


not accepting state. Therefore we cannot leave it whether we get a
0 or 1 afterwards. Can you write a list of transition rules for this
automaton?

f ) The transition rules are: [s0 , 1] → s1 , [s0 , 0] → s5 , [s1 , 0] → s2 , [s1 , 1] →


s5 , [s2 , 1] → s3 , [s2 , 0] → s5 , [s3 , 0] → s4 , [s3 , 1] → s5 , [s4 , 0] →
s4 , [s4 , 10] → s4 , [s5 , 0] → s5 , [s5 , 1] → s5 .
g) The diagram of this FSA is depicted in Figure 3.10.

Figure 3.10: FSA that accepts words starting with with 1010.

7. Write a FSA which accepts words ending with 101.


Solution: Follow these steps only to the point from which you can continue

on your own:

a) The initial state s0 corresponds to the beginning of the reading. Since


we are interested in the sequence 101 at the end of the word, we only
start paying attention when we read the letter 1. In such case we get
to state s1 . In case we are in state s0 and read a 0 (at the beginning
or later on), we remain in the state s0 .
b) If we are in s1 and read a 0, we get to s2 which corresponds to having
read 10. If we are in s1 and read a 1, we remain in s1 , since we still
only have the rst letter of the desired sequence.

c) If we are in state s2 and read a 1, we go to s3 which means we


have read the desired sequence 101. A lot of work is lost though, if
the word continues. If we are in state s2 and read a 0, the hopeful
86 CHAPTER 3. AUTOMATA AND TURING MACHINES

sequence 10 has changed to 100, which is unusable. We return to


state s0 and wait for a 1 again. What can you say about s3 ?
d) The state s3 is accepting state and corresponds to the fact we were
looking for a 101 sequence. If the word continues, we leave the state
s3 . In case the next letter is 1, we currently have 1011. Therefore we
go to state s1 , which waits for a 0. If we are in s3 and the next letter
is 0, we currently have 1010. Therefore we go to state s2 , which waits
for a 1.

e) We have nished the description of this FSA, see Figure 3.11. Since
we are interested in the sequence 101 at the end of the word, there is
always hope until we read the last letter, so we keep moving through
the graph. We do not have any hopeless garbage state. However,
even the arrival to the acceptance state does not guarantee that we
have found our word yet. We can only be certain, if we are in the
acceptance state after reading the last letter.

f ) Write the transition rules.

Figure 3.11: FSA that accepts words ending with 101.

10. Write a FSA which accepts words containing 010 and not containing 011
(both conditions must hold).
Solution:

a) This problem is more dicult than the previous one because it has
two requirements that have to hold at the same time. Note that both
sequences that determine whether the word is accepted or not start
with the same digits 01. This will help signicantly when designing
the FSA.
3.3. PROBLEM SET 87

b) We start and remain in the initial state s0 while we read uninteresting


digits 1 at the beginning of a word. Only once we get a 0, which is
the start of both important sequences 010 and 011, we switch to state
s1 .
c) We remain in s1 while reading more 0s  always a fresh potential
start of the important sequences. Once we get a 1, we can switch
to state s2 . This means we have already encountered a sequence 01.
The next digit will determine the fate of the word.

d) If the next digit is 1, the word contains the forbidden sequence 011
and we do not accept it no matter what comes next. Therefore we
switch to state s4 and remain in it. This state is not an acceptance
state.

e) If we are in state s2 and the next digit is 0, we know we read the good
sequence 010 and we would like to accept the word. We can switch
to state s5 and remain in it, see Figure 3.12.

Figure 3.12: First attempt at FSA that accepts words containing 010 and not
containing 011.

f ) Are we happy with this result? We should carefully consider the


properties of this FSA. What would it do with the word 01011? This
word starts with the good sequence 010 and ends with the bad se-
quence 011. We should reject it, but after reading the rst three
digits, our FSA switches to the acceptance state s5 and stays in it.
Where do we have a mistake?

g) Even though the FSA correctly identies the sequence 010 and switches
to the state s5 , it is premature to remain in it. We need to remain
88 CHAPTER 3. AUTOMATA AND TURING MACHINES

on the lookout for the forbidden sequence 011 and (denitely) leave
the acceptance state if it arrives. We need to extend our FSA design.

h) While reading digits 0, we remain in s5 , but if we encounter the digit


1, we are again the 01 situation (and new state s6 ) and wait for the
nal outcome.

i) Subsequent 0 indicates another good sequence 010 and brings us


(again temporarily) back to the acceptance state s5 . If we read the
digit 1, the sequence 011 is complete and this leads us to the nal
state s4 .
j) We should verify that the modied FSA shown in Figure 3.13 works
as it is supposed to.

Figure 3.13: FSA that accepts words containing 010 and not containing 011.

Turing machines

Hints :
According to the Church-Turing hypothesis (which we assume holds), the
Turing machines can perform each computational task that can be described
algorithmically. The scope is so broad that we cannot expect a general set of
steps for problems in which we are supposed to write instructions for a Turing
machine. We oer some basic advice instead:

a) Consider the type of the problem. Is the machine supposed to perform a


calculation and write the result on the tape? Or is the machine supposed
to accept a word of given properties? In the rst case, the transition rules
are primarily steps how to read the input and write output. The output
3.3. PROBLEM SET 89

can be written on a completely dierent part of the tape or can be a


modication of or addition to the original input. In this case, the nal
acceptance state has to be dened more precisely to distinguish among
the cases when the calculation did not go correctly, result does not exist
or is incorrect. In the second case, the resulting text on the tape is not
important (often the input gets modied), but the important distinction
is whether the machine ended up in an acceptance state.

b) Remember that a standard means for stoping a Turing machine is a situ-


ation in which for a given current state and letter on the tape there is no
instruction for the next move. This current state is then the nal state of
the machine and if necessary, we need to be able to decide, whether it is
also an acceptance state.

c) When designing a Turing machine, think about the mathematical foun-


dation of the algorithm it is supposed to represent. A good start of the
analysis is to try the required calculation by hand, ideally for all types of
input, result or method of calculation.

d) Based on this experience, think about the basic stages and steps of the
algorithm.

e) Formalise these steps into the machine rules. Often the machine work
regimes get represented by the states. It is common to encounter new
problems and ambiguities in this phase.

15. Write instructions for a Turing machine which performs binary XOR op-
eration of the word on the tape with a (ctitious) word 111...111 of the
same length.
Solution: Follow this solution only to the point from which you can con-

tinue on your own:

The result in this problem should be a word written on the tape. The
calculation can always be performed and thus the machine will stop once
the operation is done correctly. Consequently, we do not need to separately
specify acceptance states. The result will be written in place of the original
input word.

The idea of the algorithm lies in the way we modify the letter we have
read. Since 0 XOR 1 = 1 and 1 XOR 1 = 0, the input letter 0 is changed
to 1 and the input letter 1 is changed to 0. It is thus sucient to change
90 CHAPTER 3. AUTOMATA AND TURING MACHINES

the 0s to 1s and vice versa, as we read the word until we get to its end.
Two states will suce for this. The state s0 is the initial state and we
remain in this state while reading and modifying the input word. If we
are in state s0 and read an empty space, we know that we are at the end
of the word. The head will not do anything else but change the state to
the nal state s1 for which we do not need any more instructions.

Note that in the lecture overview, there is a description of a Turing ma-


chine which performs binary negation. Have you noticed any similarities
with this problem?

16. Write instructions for a Turing machine which performs binary XOR op-
eration of the word on the tape with a (ctitious) word 000...000 of the
same length.
Solution: Follow this solution only to the point from which you can con-

tinue on your own:

The problem is very similar to the previous one. The only dierence is in
the way we do the change of the letter. Since 0 XOR 0 = 0 and 1 XOR 0
= 1, the input 0 should be changed to 0 and the input 1 should be changed
to 1. We can easily modify the Turing machine from the previous problem
to do this.

However, when we look at this more closely, we see that the machine does
not actually have to do anything. For every binary word it is true that
binary XOR with the word 000...000 does not change the input. How to
write a Turing machine which does not do anything is more of a theoretical
question. The machine should have a set of instructions. We could leave
the set empty, but that is unusual and confusing.

What we can do instead, is for s0 and letters 0, 1 and empty space move
to nal state s1 , which does not have any further instructions.

17. Write instructions for a Turing machine which multiplies the binary num-
ber written on the tape by 4.
Solution: The result of this machine's work is again a word written on the

tape and the calculation can always be performed.

Algorithmically, multiplication by 4 is easy: we add two zeros at the


end of the word. This is because multiplication by 4 corresponds to two
multiplications by 2, which have been described in Section 3.1.2.

First, while in state s0 , we move to the end of the word without any
changes to the current 0s and 1s. At the end of the word (when we read
3.3. PROBLEM SET 91

an empty space), we change it to 0 and switch to state s1 . We move to


the right once and write the second 0. We switch to state s2 and nish.
92 CHAPTER 3. AUTOMATA AND TURING MACHINES

3.4 Lab problems

1. Finite state automata with alphabet {0, 1}.


If a word is accepted, the output is accepted word, if not, the output is
rejected word.
a) Design a FSA that accepts words ending with 1.

b) Design a FSA that accepts words ending with 10.

c) Design a FSA that accepts words ending with 11.

d) Design a FSA that accepts words containing (anywhere) a sequence


of at least ve 1s.

e) Design a FSA that accepts words containing (anywhere) a sequence


101.

2. Bunny invasion
The Australian prairie with dimensions 5 miles × 5 miles is invaded by
a growing number of bunny colonies. The colonies gradually cover 25
square regions 1 mile × 1 mile. In the rst year, two colonies settled
in two of the regions. When colonising regions, we consider neighboring
regions to be those which share either a side or a corner. Every year, new
colonies appear in every region, which has at least two neighboring regions
colonised. Existing colonies survive indenitely.
Create an Excel sheet with 5 × 5 input. Two numbers 1 denote the two
regions initially colonised by bunnies and 0s in all other regions represent
free prairie. The output is a sequence of suciently many 5 × 5 squares
corresponding to the next years of colonies' spreading.

Using the created sheet, answer the following questions:

a) In which initial setups, there will be no new colonies?

b) Are there any initial setups that result in colonisation of the whole
prairie?

c) Find such initial setups which colonise the whole prairie in the short-
est and in the longest time.

d) Are there any initial setups that stop spreading after some time?

e) Use the conditional formatting to denote the colonised and free re-
gions.
3.4. LAB PROBLEMS 93

f ) Find geometrically and graphically interesting examples of colonisa-


tion.

g) How do the solutions (and corresponding formulas) change, if the


colonisation condition changes from at least two to exactly two ?
h) Answer the same questions for dierent colonisation rules.

3. Game of life
There are several Game of Life applets available online. We are going to
create our own in Excel. The game environment is 5×5. At the beginning,
some cells are occupied, some are not. In the next generation, some cells
die, some stay alive and some come alive depending on the number of
neighbors. Neighbors share either a side of the square or a corner. If
a populated cell has 2 or 3 neighbors, it will survive. If it has 0 or 1
neighbor, it dies from loneliness, if 4 or more, it dies from overpopulation.
If the cell is free and has 3 neighbors, it will come alive because of suitable
surroundings.

Create an Excel sheet with 5 × 5 input. Denote the occupied cells by


some character, e.g. x or o. The output are 5 × 5 squares representing
the next generations that arose from the rst one using the above-stated
rules. Using the Excel sheet, solve the following problems:

a) Find the largest population that will die out fast (in a given number
of steps).

b) Find an oscillator with the smallest initial number of cells. Oscillator


is a setup which repeats after some time.

c) Find oscillators with a period of 2, 3, 4, ...


d) Find an oscillator with a known period but a dierent initial regime.

e) Find the smallest/largest stationary state. Here we are looking for


an initial setup that does not change in the next generation.

f ) What happens in a given conguration if you symmetrically add/delete


certain cells? Does it help or harm the population?
94 CHAPTER 3. AUTOMATA AND TURING MACHINES

3.4.1 Hints and solutions


1. Finite state automata with alphabet {0, 1}.
If a word is accepted, the output is accepted word, if not, the output is
rejected word.
a) Design a FSA that accepts words ending with 1.

b) Design a FSA that accepts words ending with 10.

c) Design a FSA that accepts words ending with 11.

d) Design a FSA that accepts words containing (anywhere) a sequence


of at least ve 1s.

e) Design a FSA that accepts words containing (anywhere) a sequence


101.

Hints :
• The automata a) to c) are relatively simple and of the same type.
They test the end of the word.

• We rst decide whether we are using the vertical or horizontal repre-


sentation of the input word. In either case, its end is indicated by an
empty space after a sequence of 0s and 1s. This is a suitable place
for evaluation of the word and making the acceptance decision.

• To test the short ends of words, it is possible to make the decision


with a single condition (=IF) at the end of the word.

• For more complex conditions, e.g. problem d), we can use auxiliary
calculations next to the input word. In problem d) this would be a
calculation of continuous sequences of 1s.

• The auxiliary calculation can be further improved for more compli-


cated automata, such as the one in problem e). The auxiliary line
or column can contain the individual (numerically coded) states and
in the condition that calculates them, we write the transition rules
using logical operators.

• If we are using the auxiliary line for calculation, in certain sense,


we are solving the problem using a TM, since we write and evaluate
necessary data. This can replace the need for additional states.

• The most dicult and also the most universal approach is to state
the transition rules in a table and then generate the states in the
3.4. LAB PROBLEMS 95

auxiliary line or column by searching this table using the functions


VLOOKUP and MATCH.

a) Design a FSA that accepts words ending with 1.


Solution:

• We designate a part of a row for input consisting of 0s, 1s and empty


cells. The length of the input region is xed, e.g. 20 cells. The input
is entered manually. Be careful when using an empty cell ( ) and a
space ( ), which appear to be the same but behave dierently.

• We evaluate the input word in the next line. The value z corresponds
to the part under the input letters. Under the rst empty cell, we
evaluate whether the previous letter was 1 and accept the word in the
state a or otherwise transition to a non-acceptance nal state k . This
can be achieved using a command =IF(I4<> ;z;IF(H4=1;a;k)).

• The nal result can be displayed by checking whether there is the


state a in the state row, e.g. =IF(COUNTIF(C3:W3;a)>0;accepted
word;rejected word), as in Figure 3.14.

Figure 3.14: FSA that accepts words ending with 1.

Clever input
If we want to enter the input in a more clever way, we can use a
random number generator. In such case, we also need to generate
the random ending of the word in addition to generating a random
sequence of 0s and 1s. To do that, we can use additional row with
commands =RANDBETWEEN(0;2), where 2 corresponds to a space,
as in Figure 3.15. Using the command =IF(OR(C2=2;B4= ); ;C2)
we achieve that the sequence of 0s and 1s ends with the rst occur-
rence of 2 after which there are only empty cells.
96 CHAPTER 3. AUTOMATA AND TURING MACHINES

Figure 3.15: FSA that accepts words ending with 1. Input is randomly gener-
ated.

d) Design a FSA that accepts words containing (anywhere) a sequence of at


least ve 1s.
Solution:
• The input can again be entered manually.

• In the state row, we now use the command =IF(C3=1;B4+1;0) for a


sequence of 1s and calculate its length. After the letter 0 or empty
cell, we reset the counter to 0. The numbers corresponding to the
sequence length can represent the states.

• The correct answer is obtained using the command


=IF(COUNTIF(C4:W4;5)>0;accepted word; rejected word), which
checks whether there was at least one number 5 in the state row. This
FSA is shown in 3.16.

• There are several ways how to improve this solution. Our automaton
unnecessarily uses states 6, 7, 8, 9, ... Formally, we have not even
created a FSA, since we cannot say in advance (for an arbitrary but
nite input length) how many states are we going to need. However,
it is possible to change the condition in the state row in such a way
that once we enter the state 5, we remain in it.

Randomness
If we wanted to generate the input word randomly again, the previ-
ously described method using =RANDBETWEEN(0;2) would gen-
erate an accepted word very rarely. To generate the accepted words
more often, we can generate the 0s, 1s and 2s in a more favorable
ratio using random numbers from interval (0,1). We do this using a
function =RAND() and an auxiliary line with command
3.4. LAB PROBLEMS 97

Figure 3.16: FSA that accepts words containing a sequence of at least ve 1s.

=IF(C1<0,6;1;IF(C1<0,9;0;2)), as shown in Figure 3.17. Now in ap-


proximately 60% of cases we generate a 1, in 30% of cases 0 and in
10% of cases 2.

Figure 3.17: FSA that accepts words containing a sequence of at least ve 1s.
Input is randomly generated.

2. Bunny invasion
Hints:
• We create a sequence of tables 5×5 in which more and more new
bunny colonies appear. The colonised regions are denoted by 1, the
free regions are denoted by 0. To answer the questions, we should
display at least 10 generations.

• The only place where we enter the colonies manually is the rst table.
In all others, a formula (the same one for all regions) determines
whether there is a 0 or a 1 in the given region. The 5×5 tables
should be displayed in a graphically clear manner.

• If we leave sucient gaps between the tables, we can copy the formu-
las for the individual regions. In fact, it is sucient to use the same
formula for all regions, write it just once and then copy.
98 CHAPTER 3. AUTOMATA AND TURING MACHINES

Solution:
• We create one 5×5 table for each generation in which 1 represents
a colonised region and 0 represents a free region.

• We enter the 0s and 1s manually in the rst table.

• To determine the population of the region in the next year, we need


to check its current population (if it is 1, it is going to remain 1) and
the number of neighbors. For this we add their values.

• If we have at least one row and one column padding around the table,
we can use the same formula for all regions, even those that are at
the sides. Their neighbors are empty and Excel interprets the empty
cells as numerical value 0.

• We can use the formula


=IF(OR(B3=1,A2+B2+C2+C3+C4+B4+A4+A3>1),1,0)

• This formula is copied to all regions in the table and the whole table
is copied below (or next to) the original one with one row (column)
between them, as in Figure 3.18.

Figure 3.18: Bunny invasion.

3. Game of life
Hints:
• Our goal is to generate a sequence of 5×5 tables in which the next
generations of life arise. Only the rst table is entered manually,
the rest of them are generated automatically. We are going to need
around 10 generations.
3.4. LAB PROBLEMS 99

Figure 3.19: Life

• It is useful to have a few auxiliary tables for determining the occu-


pancy in the next generation, e.g. one for calculating the number of
neighbors or one for applying the life rules.

• If there are more tables per generation, it is useful to nd a clear


graphical representation.

• It should be possible to copy the formulas when creating next gener-


ations and preforming their calculations.

Solution:
• For each generation, we rst create a table that displays the occupied
cells. We use three auxiliary tables with numbers for calculations.

• In the rst auxiliary table, we transform the occupancy into numer-


ical values 1 (occupied) and 0 (empty).

• Based on this table we create a second auxiliary table into which we


denote the number of occupied neighbors for each cell.
100 CHAPTER 3. AUTOMATA AND TURING MACHINES

• In the third auxiliary table, we use the life rules and the second table
to calculate the occupancy in the next generation and denote it by
0s and 1s.

• The following formulas may be used for calculating the values in the
auxiliary tables:
=IF(D4="X",1,0)
=K3+L3+L4+L5+K5+J3+J4+J5
=IF(OR(AND(K4=1,OR(R4=2,R4=3)),AND(K4=0,R4=3)),1,0)

• The four tables together represent one generation of life starting with
the display of initial state and ending with a precalculation of the next
generation.

• The tables of the next generation again start with a display of the
environment occupancy. Unlike in the rst table, this one is obtained
by redrawing the precalculation from the row above.

• We obtain the next generations by copying, see Figure 3.19.


Chapter 4

Mathematical logic

4.1 Lecture overview

4.1.1 Logical statements and operators


Logical statements and their truth value
A logical statement or a proposition is the basic building block of more compli-
cated mathematical structures. It is any statement for which we can determine
whether it istrue (denoted by 1) or false (denoted by 0). Two examples are:
"The snow is cold." which is a true statement and "My hair is green." which is
a false statement.

Not a statement
Consider "Let's go to Mars." We cannot determine whether this sentence is true
or false, therefore it is not a logical statement.
Consider also the sentence "Apples are the best fruit." Is it a statement?
Is it true? We are using sentences about the world around us to illustrate the
mathematical concepts, but while doing so, we have to work only with sentences
for which it is clear whether they are true or false. Some people might agree
that apples are the best fruit, some might not, so this is not an example of a
logical statement.
The main use of mathematical logic is to examine the statements whose truth
value can be determined unambiguously. Even if we stay in the mathematical
realm, we have to be careful because the sentence "For every x and y there

101
102 CHAPTER 4. MATHEMATICAL LOGIC

exists a z such that x+z=y." is true if we are talking about integers, but not
true if we are talking about natural numbers.

Negation
The negation replaces the original proposition by its opposite. It essentially
means "It is not true what the statement says." We denote it by the symbol:
¬, or by an apostrophe or by a bar over the proposition we are negating. The
proposition ¬A is true if and only if the proposition A is not false and vice
versa. For example a negation of a true statement "The snow is cold." is the
false statement "It is not true that the snow is cold." which can also be stated
as "The snow is not cold."
Note that the negation has to be the exact opposite of the original state-
ment. For example, since there are things that are neither large nor small, the
statement "The mouse is large." is not a correct negation of the statement "The
mouse is small."

Two basic principles of classical logic


Since there are only two options for the truth value of a logical statement, in
classical mathematical logic we have the following two principles. The rst one
is the principle of excluded middle also known as the law of excluded third which
means that every statement which is not true has to be false and vice versa.
There are no other options. The second principle is the principle of double
negation which means that if we negate a proposition twice, we return to the
original proposition.

Problem 4.1 Double negation:


Negate the following statement twice: "A googol is a large number."
Solution: The negation is"A googol is not a large number." The negation of
the negation is"It is not true that a googol is a not large number." which is the
same as the statement "A googol is a large number."

Problem 4.2 Positive auto-reference:


Consider "This statement is true."
Solution: If this sentence is true, everything is ok. If it is false, then its negation
must be true. The negation is "This statement is false." Since we assumed it
was, there is no contradiction. However, we cannot have it both ways. Since
4.1. LECTURE OVERVIEW 103

we cannot determine whether the sentence is true or false, it is not a logical


statement.

Problem 4.3 Negative auto-reference:


Consider "This statement is false."

Solution: If this sentence is true, it has to also be false, since that is what is
says. And obviously it cannot be both at the same time. On the other hand if
it is false, then its negation "This statement is true." must be true. So again,
the sentence should be both true and false which cannot happen. So there is an
inconsistency either way and the sentence is not a logical statement. We call a
sentence like this one or the one in the previous problem a paradox.

Equivalence
The equivalence of two propositions means that either both of them are true
or both of them are false. It is also often expressed using the words if and
only if, sometimes shortened to i. We denote it by ⇐⇒ . So the proposition
A ⇐⇒ B is true i both A and B are true or both of them are false. It is
false, when A and B have dierent truth values. The statement "A number is
divisible by two if and only if its last digit is divisible by two." is an example of
an equivalence. We cannot have one property without the other.

Conjunction
The conjunction of two propositions is also called and or logical product. It is
denoted by ∧ or &. The statement A∧B is true if and only if both A and B
are true. The negation of "A and B are true."
"A or B are not true.",
is thus
i.e. ¬(A ∧ B) ⇐⇒ ¬A ∨ ¬B . An example statement is: x > 0 ∧ y > 0.

Alternative
The alternative of two propositions is sometimes called or, disjunction, logical
sum or at least one of. It is denoted by ∨. The statement A ∨ B is true i at
least one of A and B is true. Indeed, both of then can be true, this or is not
excluding. The negation of "A or B are true." is thus "A is false and B is
false.", i.e. ¬(A ∨ B) ⇐⇒ ¬A ∧ ¬B . An example statement is "I have a soup
or I have a sandwich for lunch." I can certainly also have both.
104 CHAPTER 4. MATHEMATICAL LOGIC

Implication
This is the logical operator that often causes confusion. It is sometimes called
If... then... If the premise is true, then the conclusion needs to be true. We
denote it by⇒. The statement A ⇒ B is false i the premise A is true and
the conclusionB is false. In all other cases, it is true. For the negation we have
¬(A ⇒ B) ⇐⇒ A ∧ ¬B . The statement B ⇒ A is called a converse and may
or may not be true. The statement ¬B ⇒ ¬A is called a contrapositive and is
always true.
Let us look at an example statement: "If it is snowing, I wear a scarf."
This is only false, if it is snowing and I do not have a scarf. If it is not snowing,
I may or may not have a scarf, whatever I do, the original statement remains
true. Since the negation is "It is snowing and I do not have a scarf." the original
implication can also be written in the form of an alternative "It is not snowing
or I wear a scarf."
Consider another example. Your Mom tells you "If you get an A in this
class, I will bake you a cheesecake." There are four scenarios that can happen:

• You got an A, Mom baked a cheesecake. Life is great, implication is true.

• You did not get an A, Mom did not bake a cheesecake. Not that great
but the implication is true.

• You did not get an A, Mom baked a cheesecake. Mom is great, wanted to
cheer you up, the implication is still true.

• You got an A, Mom did not bake a cheesecake. This should not happen,
implication is false.

It might seem that our intuition of how the world works is fairly aligned with
the mathematical rules in this case, but we should not rely on it in general.
Consider a similar situation, only this time, Mom says "If you get FX in this
class, I will bite your head o." There are again four scenarios:

• You got FX, Mom bit your head o. Not that great but the implication
is true.

• You did not get FX, Mom did not bite your head o. Life is great and
the implication is true.

• You did not get FX, Mom bit your head o. Wait, what? This should not
happen, but the implication is true!
4.1. LECTURE OVERVIEW 105

• You got FX, Mom did not bite your head o. Mom is great and the
implication is false.

4.1.2 Quantiers and predicate logic


Predicates
Predicate logic examines the structure of predicates or atomistic logical formulas.
These formulas contain variables denoting objects from an agreed-upon set,
usually a number set, such as natural numbers, real functions, etc. and talk
about (properly dened) properties of these objects. The properties can be
related to individual objects, e.g. a number is even, a function is periodic or
to groups of objects, e.g. a number a divides a number b, linear functions are
continuous, etc. When we want these formulas to be exact, we have to determine
for which objects are they true. To do this, we use two basic quantiers.

Universal quantier
A universal quantier also called for all and denoted ∀ means that the property
holds for all objects from the set under consideration. We read ∀n ∈ N as "For
all n in N ..." or "For every natural number n..." The negation of statement
"For every x in A, the following is true." is "There exists an x in A for which
the following is not true."

Existential quantier
An existential quantier denoted by ∃ means that there exists (at least one)
object with the given property, e.g. ∃n ∈ N : 3|n. The negation of statement
"There exists an x in A for which the following is true." is "For all x in A, the
following is not true."

4.1.3 Language of mathematics


The mathematics uses the language of formulas, predicates and quantiers when
it wants to be precise, especially in writing. Mathematical texts (books, articles,
lectures) contain a formal, and for general public often unusual, language. To get
oriented in it, here we mention some of its typical and important components.
106 CHAPTER 4. MATHEMATICAL LOGIC

Denition
Since the time of Aristotle it has been clear that for meaningful communication,
it is necessary to establish common terms that are going to be used. To do this
in mathematics, we use denitions. The denitions use the already known,
previously dened terms to introduce the new ones. The good denitions have
to be not only correct, but also understandable and should only be used for
important key terms.

Axiom
Before we get to denitions of complex terms, we need to dene simpler ones.
Similarly, complex properties of mathematical objects are derived from simpler
and simpler ones. However, this process has to start somewhere. The set of
basic denitions of objects and their basic properties is usually captured in the
axioms of the given theory. We consider the axioms to be true and we do not
prove them. Conversely, the whole theory can be derived from the axioms.
It is necessary to verify the correctness of the axiomatic system, e.g. whether
the axioms contradict each other or whether there are theorems that cannot
be derived from these axioms. The rst axiomatic system is the planar theory
described in Euclid's Foundations, which is the basis of the planar geometry.

Theorem
Important mathematical statements that describe properties of and relation-
ships among mathematical objects are called theorems. Some of them are im-
portant enough that they earned names, e.g. Pythagorean Theorem, Funda-
mental Theorem of Arithmetics, Fundamental Theorem of Algebra, Fermat's
Last Theorem, etc. The auxiliary theorems that are important but not focal in
various mathematical elds are called lemmas. Some of these also have their
own names, such as Zorn's lemma. Some other statements mathematicians use
are corollary, note, etc.

Proof
With the exceptions of axioms and denitions, all statements in mathematics
need to be proven. (And even for axioms and denitions it needs to be proven
that they are not formally incorrect.) The proof of a theorem or a lemma has
to start from the valid axioms or from previously proven theorems. Using the
rules of mathematical logic, new theorems can be derived.
4.1. LECTURE OVERVIEW 107

The proof can be more or less formal. A completely exact proof of the state-
ment 1+1=2 originating from the axioms of set theory supposedly contains
approximately 20 000 steps [8]. While this is interesting, it is only interesting
for mathematicians (and even for them for reasons other than to nd out how
much is 1+1). For us, the proof is useful and necessary for the following reasons:

• It convinces us of correctness of the hypothesis, which holds for some cases


but we cannot verify it for all cases one-by-one.

• It claries the meaning and background of the theorem. It shows how it


is connected to and follows from other simpler theorems or concepts.

• A constructive proof includes steps how to create an object or calculate a


quantity which is needed or useful for solving a problem.
108 CHAPTER 4. MATHEMATICAL LOGIC

4.2 Questions

1. Explain what inaccuracy (in language or in thinking) causes the paradox:

a) Girls are not boys. Girls are busy. Therefore boys are not busy.

b) Tea may be hot. Tea may be cold. Therefore hot is the same as cold.

c) Horse is a word. Horse can gallop. Therefore words can gallop.

d) 3 divides 18. 4 does not divide 18. 7 is 3 and 4. Therefore 7 divides


and does not divide 18.

2. Which of these sentences are logical statements? Explain. If possible,


determine whether they are true:

a) In the year 2020, there will be a person on Mars.

b) In the year 1970 there was a person on the Moon.

c) In the year 1670 there was a person on the Moon.

d) We will go to Mars!

e) Go to Mars!

f ) This sentence is true.

g) This sentence is false.

3. Do the following equivalences hold? Prove or give a counterexample:

a) A number is divisible by 5 if and only if its last digit is 0.

b) A number is divisible by 5 if and only if its last digit is 0 or 5.

4. We have an implication "If the last digit of a number is 0, then the number
is divisible by 5."
a) State its negation.

b) State this implication in terms of an alternative.

5. State the negations of these statements about all natural numbers:

a) If a number is divisible by 5, then its last digit is either 0 or 5.

b) If a number is divisible by 6, then it is divisible by 3 and divisible by


2.
4.2. QUESTIONS 109

c) If a number is divisible by 2, then it is a multiple of 4. (Note that


this statement is not true.)

d) If a number is a multiple of 4, then it is divisible by 2.

6. State the negations of the statements:

a) Everybody likes something.

b) Everybody dislikes something.

c) Sometimes everybody likes something.

d) Sometimes everybody dislikes something.

7. Evaluate in binary:

110010110
AND 001110100
a)

100101100
OR 001001110
b)

111100100
XOR 010011010
c)

8. Solve equation in binary:

100111010
AND
a)
100100010

101101011
OR
b)
011010110
110 CHAPTER 4. MATHEMATICAL LOGIC

100110010
XOR
c)
100001101

9. Write a denition

a) of a geometric object or property

b) of an arithmetic object or property

10. Write

a) a theorem from geometry

b) a theorem from arithmetics

c) a theorem from algebra

d) Pythagorean Theorem in the form of two implications

11. Write a false statement (theorem)

a) from geometry

b) from arithmetics

c) from algebra

12. Write your best denition of

a) a right angle

b) an equilateral triangle

c) an isosceles triangle

d) a rectangle

e) a cube

f ) a line

g) the number 0

h) the number 1

i) the number π
4.3. PROBLEM SET 111

4.3 Problem set

1. Pseudo-scientic language
The following sentences use a pseudo-scientic language to describe well-
known proverbs. What are the proverbs?

a) Repeated execution of a task causes one not to make mistakes when


performing the task later.

b) The graphical representation of a certain object has three orders of


magnitude larger value than a meaningful array of individual letters
describing the said object.

2. Marbles in boxes
In each of two boxes there is exactly one marble, which may be black or
white. Each box has something written on the lid. We know that the lids
are either both true or both false. Determine whether they are true/false
and what color marble is in each box.

a) The writing on the rst box says "There is a white marble in the rst
box or there is a black marble in the second box." The writing on the
second box says "There is a black marble in the rst box."

b) The rst box says "In the rst or in the second box there is a white
marble." The second box says "There are black marbles in both boxes."
3. Tools
P (x) denotes x
is at the right place. O(x) denotes x is in good order. T (x)
denotesx is a tool. Let us assume that the domain of x are all things
A. Write the following statements in everyday language and write their
negations:

a) ∃x ∈ A : ¬P (x)
b) ∀x ∈ A : T (x) ⇒ (P (x) ∧ O(x))
c) ∀x ∈ A : P (x) ∧ O(x)
d) ∀x ∈ A : ¬(P (x) ∧ O(x))
e) ∃x ∈ A : (T (x) ∧ ¬P (x) ∧ O(x)) ∧ (∀y ∈ A : (T (x) ∧ ¬P (x) ∧ O(x)) ⇒
(x = y))
f) ∀x ∈ A : (P (x) ∧ T (x)) ⇒ O(x)
112 CHAPTER 4. MATHEMATICAL LOGIC

4. Princesses and tigers


(These problems are inspired by the book The lady or the tiger [7].) We
have princesses (P) and tigers (T). Behind each door, there is either a
P or a T. There is also a statement (more or less helpful) on each door.
A prince wants to get married and for that he needs to nd a P (if he
nds a T, he will be eaten). Which door should he choose in the following
scenarios?

a) There may be a T or P in either room (both rooms can even contain


the same creature):
Door 1: There is a P in this room and a T in the next room.
Door 2: In one of the rooms there is a P and in the other a T.
One statement is true, one is false.

b) There may be a T or a P in either room (both rooms can even contain


the same creature).
If there is a P in the room 1, the statement on the door 1 is true,
if there is a T, the statement is false. If there is a P in room 2, the
statement on door 2 is false, if there is a T, the statement is true.
Door 1: It makes a dierence what you choose.
Door 2: It is better to go next door.

c) We have three rooms, in one of them is a P, in the remaining two are


Ts:
Door 1: There is a T in this room.
Door 2: There is a P in this room.
Door 3: T is in room 2.
At most one statement is true.

5. Negating quantiers
Read each statement and decide whether it is true. Then negate it and
check if the negation has the opposite true/false value.

a) (∀x ∈ N)(∀y ∈ N) x > y


b) (∀x ∈ N)(∃y ∈ N) x > y
c) (∃x ∈ N)(∀y ∈ N) x > y
d) (∃x ∈ N)(∃y ∈ N) x > y
e) (∀y ∈ N)(∀x ∈ N) x > y
f) (∀y ∈ N)(∃x ∈ N) x > y
4.3. PROBLEM SET 113

g) (∃y ∈ N)(∀x ∈ N) x > y


h) (∃y ∈ N)(∃x ∈ N) x > y

6. Autoreferencing tablets
There were a few stone tablets found during an archaeological research.
Each of them contains some statements. Find out which statements are
true and which are false. Find all solutions.

a) Tablet A:
There is exactly one true statement on this tablet.
There are exactly two true statements on this tablet.
There are exactly three true statements on this tablet.
. . .
There are exactly eight true statements on this tablet.

b) Tablet B:
There are exactly two true statements on this tablet.
There are exactly three true statements on this tablet.
. . .
There are exactly six true statements on this tablet.

c) Tablet C:
There are exactly zero false statements on this tablet.
There is exactly one false statement on this tablet.
There are exactly two false statements on this tablet.
There are exactly three false statements on this tablet.
. . .
There are exactly ten false statements on this tablet.

d) Tablet D:
There are exactly ve false statements on this tablet.
There are exactly six false statements on this tablet.
There are exactly seven false statements on this tablet.
There are exactly eight false statements on this tablet.

e) Tablet E:
There are at least zero true statements on this tablet.
There is at least one true statement on this tablet.
There are at least two true statements on this tablet.
There are at least three true statements on this tablet.
. . .
There are at least ten true statements on this tablet.
114 CHAPTER 4. MATHEMATICAL LOGIC

f ) Tablet F:
There are at least three true statements on this tablet.
There are at least four true statements on this tablet.
There are at least ve true statements on this tablet.
. . .
There are at least ten true statements on this tablet.
4.3. PROBLEM SET 115

4.3.1 Hints and solutions


1. Pseudo-scientic language
The following sentences use a pseudo-scientic language to describe well-
known proverbs. What are the proverbs?

a) Repeated execution of a task causes one not to make mistakes when


performing the task later.

b) The graphical representation of a certain object has three orders of


magnitude larger value than a meaningful array of individual letters
describing the said object.

Hint: The following sentence could serve as a hint how to solve this kind
of problem: "An asymmetric discussion that includes a barter transaction
of personally obtained experience is of signicant value." The language
of mathematics is often perceived as pointlessly complicated. Sometimes
such observation leads to the incorrect conclusion that the wisdom or
importance of the mathematical statements lies in the incomprehensibility
and diculty of their language. This problem demonstrates how even a
well-known simple proverbs can be obfuscated just by using a pseudo-
scientic language.

To decode them, we can try to replace some of the expressions by simpler


words and remember a proverb that contains them. For example repeated
execution may be a practice. A graphical representation may be a picture.
Solution:
a) Repeated execution of a task causes one not to make mistakes when
performing the task later. (Practice makes perfect.)

2. Marbles in boxes
In each of two boxes there is exactly one marble, which may be black or
white. Each box has something written on the lid. We know that the lids
are either both true or both false. Determine whether they are true/false
and what color marble is in each box.

Hint: There is more than one approach to this problem:

a) Follow the logical line of the statements.

b) Write out all possibilities for truth values of the statements. Choose
from them those that meet the conditions stated in the problem.
116 CHAPTER 4. MATHEMATICAL LOGIC

These problems are used for development of reasoning and logical thinking.
The logical correctness in thinking should come before the exactness of
expression and formulation of mathematical statements. Therefore it is
important to discuss these problems in pairs or in larger groups and to try
to understand a dierent solution and compare it with one's own. That
should be also a method for solving this kind of problems: be able to
explain one's own reasoning, understand a dierent reasoning, confront
the two and perhaps apply either of them in another problem.

Solution:
• Suppose it is true that"There is a white marble in the rst box or
there is a black marble in the second box." The marbles can then
be placed either WW or WB or BB. The second statement has the
same truth value as the rst statement, so also the following has to
be true: "There is a black marble in the rst box." Of the available
options, only BB ts. We now need to check what happens if the
rst statement is false. Then it is true that"There is a black marble
in the rst box and a white marble in the second box." Also "There is
not a black marble in the rst box." has to be true. However, these
two statements cannot be true at the same time. Consequently, BB
is the only solution.

• We now try to solve the problem in a slightly dierent way. We write


all the options for truth values of the statements: 11, 10, 01 and 00.
We know that both statements have the same truth value, therefore
we can exclude the options 10 and 01. In the case 11, it is true that
"There is a white marble is in the rst box or a black marble is in
the second box." and it is also true that "There is a black marble in
the rst box." This implies solution BB. In the case 00, it is not true
that "There is a white marble is in the rst box or a black marble is
in the second box." and it is not true that "There is a black marble
in the rst box." This implies that the black marble both is and is
not in the rst box. Thus BB is the only solution.

• Yet another possible approach is to write out all possible marble


placements: WW, WB, BW and BB. We evaluate the corresponding
truth values of the statements on the boxes: 10, 10, 01 and 11. We
know that both statements have the same truth value, so we have to
exclude 10 and 01. Only BB with 11 remains, thus this is the only
solution to the problem.
4.3. PROBLEM SET 117

3. Tools
P (x) denotes x
is at the right place. O(x) denotes x is in good order. T (x)
denotesx is a tool. Let us assume that the domain of x are all things
A. Write the following statements in everyday language and write their
negations:

a) ∃x ∈ A : ¬P (x)
b) ∀x ∈ A : T (x) ⇒ (P (x) ∧ O(x))
c) ∀x ∈ A : P (x) ∧ O(x)
d) ∀x ∈ A : ¬(P (x) ∧ O(x))
e) ∃x ∈ A : (T (x) ∧ ¬P (x) ∧ O(x)) ∧ (∀y ∈ A : (T (x) ∧ ¬P (x) ∧ O(x)) ⇒
(x = y))
f) ∀x ∈ A : (P (x) ∧ T (x)) ⇒ O(x)

Hint: In mathematical statements, we use quantiers to state the number


of items with the given property. The basic rule when negating state-
ments with quantiers states that the negation of statement with universal
quantier is a statement with an existential quantier. For example the
negation of the statement "All aliens are pink." is "There exists an alien,
which is not pink." Formally, this negation is OK, it is problematic only
for those that do not think there are any aliens. In that we encounter the
properties of an empty set, which we will examine in one of the following
chapters. Here we are trying to make statements about objects we know
exist. For example, the statement "All dogs are dachshunds." is clearly
not true. Its negation "There exists a dog, which is not a dachshund." has
the opposite truth value and thus it is true. We can use a similar approach
in the problems with tools.

We need to be careful when negating statements everything holds as noth-


ing holds. This is not a negation. We can see this clearly when we look at
the statement "All integers are even." This statement is false. However,
also this attempt at negation is false "No integers are even."
Solution:
a) This statement says: There exists a thing which is not at the right
place. To negate it, we would say All things are in the right place
and write ∀x ∈ A : P (x).
118 CHAPTER 4. MATHEMATICAL LOGIC

b) This statement says that All tools are in the right place and in order.
To negate it, we would say that There exists a tool which either is
not at the right place or is not in good order. We would write it as
∃x ∈ A : T (x) ∧ (¬P (x) ∨ ¬O(x))
e) This statement says There exists a tool, which is in order and not at
the right place and for all tools in order and not at the right place we
have that they are the same as the rst tool we mentioned. In plain
language we could simplify this statement to There exists exactly one
tool which is in order and not at the right place. This can be written
as ∃!x ∈ A : (T (x) ∧ ¬P (x) ∧ O(x)). For negation of this statement,
we need to consider both cases: There is no thing in A that . . . and
More than one thing in A . . .

More quantiers
Use the quantiers in the proverbs.
State a statement with three quantiers about dogs and dachshunds.

4. Princesses and tigers


(These problems are inspired by the book The lady or the tiger [7].) We
have princesses (P) and tigers (T). Behind each door, there is either a
P or a T. There is also a statement (more or less helpful) on each door.
A prince wants to get married and for that he needs to nd a P (if he
nds a T, he will be eaten). Which door should he choose in the following
scenarios?
a) There may be a T or P in either room (both rooms can even contain
the same creature):
Door 1: There is a P in this room and a T in the next room.
Door 2: In one of the rooms there is a P and in the other a T.
One statement is true, one is false.

Hint: There is more than one approach to this problem. One is to consider
the content of the statements written on the doors. Another is to write
out all the four possibilities for the truth values of the statements on the
doors, i.e. (True, True), (True, False), (False, True) and (False, False)
and gure out what creatures can be behind each door. Yet another
approach is to write out all the four possibilities of room occupancy behind
(Tiger, Tiger), (Princess, Princess), (Princess, Tiger) and
the doors, i.e.
(Tiger, Princess) and evaluate the truth value of the statements on the
doors based on these occupancies. We can try to solve the same problem
4.3. PROBLEM SET 119

using all three of these approaches to verify the correctness of the solution
and compare the complexity and clarity of the individual solutions and
reasonings.

Solution: The solution of this problem follows from the fact that the rst
sentence implies the second. Therefore, if the rst statement is true, the
second must be true as well. However, having both statements true contra-
dicts king's information. Therefore only the second sentence can be true
and the rst one is false. The only way how to put two dierent creatures
into two rooms and contradict the rst sentence is to have a tiger behind
the rst door and a princess behind the second. Our recommendation for
the prince is to try the second door.

5. Negating quantiers
Read the statement and decide whether it is true. Then negate it and
check if the negation has the opposite true/false value.
(∀x ∈ N)(∀y ∈ N) x > y
Hint: In these problems, it is helpful to substitute specic numbers. A
basic sanity check is that if the statement is true, its negation has to be
false and vice versa. Remember that the order of quantiers matters.

Solution: Since the statement must be true for all natural x and y , we can
try numbers 5 and 3:

(5 ∈ N)(3 ∈ N) 5 > 3.

We see that the statement is true. However, it has to be true for all pairs
of x and y. For the pair 7 and 9, the statement is not true. Therefore it
is not true overall.

Its negation is
(∃x ∈ N)(∃y ∈ N) x ≤ y.
This is true. There are such numbers, e.g. 2 and 22.

6. Autoreferencing tablets
There were a few stone tablets found during an archaeological research.
Each of them contains some statements. Find out which statements are
true and which are false. Find all solutions.

a) Tablet A:
There is exactly one true statement on this tablet.
120 CHAPTER 4. MATHEMATICAL LOGIC

There are exactly two true statements on this tablet.


There are exactly three true statements on this tablet.
. . .
There are exactly eight true statements on this tablet.

Hint: The purpose of these problems is to make clear how the truth value
changes when a statement references itself and is bound also to other
statements. Also remember that to solve a problem, we need to nd all
solutions.

Solution:
• We need to consider the connections between the statements. Since
they talk about specic numbers of true statements, every two sen-
tences are mutually exclusive. Once one of them is true, all the rest
of them has to be false. This means, at most one statement on the
tablet can be true. If one was true, obviously it has to be the rst
one (because it says that one statement is true) and the rest of them
are false.

• There is also a second solution: all statements false.

• With any solution, we need to check that it is correct, i.e. that the
truth values as we determined them correspond to the content of the
statements.
4.4. LAB PROBLEMS 121

4.4 Lab problems

1. Tool for verication of algorithms


Here are three simple algorithms. Would you give them a certicate of
correctness? Check them on examples. If you nd mistakes, try to correct
them.

a) We have a string that contains an algebraic expression. We want to


check that it uses the brackets correctly. At the beginning, we set
the variables L and R to 0. We read the string from left to right. If
we encounter "(", we increment L, if we encounter ")", we increment
R. If R 6= L at the end, the use of brackets is not correct. If R = L,
it is correct.

b) Heron's formula calculates the area of a triangle using the lengths


of its sides. We start with numbers x, y , z and calculate A using
Heron's formula. The value A represents the area of triangle with
sides x, y and z.

Figure 4.1: A diagram for Sleeping Beauty.


122 CHAPTER 4. MATHEMATICAL LOGIC

c) Sleeping Beauty was asleep for 100 years. Then came a prince, kissed
her and maybe she woke up. If she did not wake up, he returned
again after one year and kissed her again. Create a table in Excel
that counts the years of Sleeping Beauty's sleep as suggested in the
Figure 4.1. Assume that there is a 0.5 probability that the Sleeping
Beauty wakes up after a kiss. Generate randomness by repeated use
of the F9 key and observe when the princess wakes up. What was
the longest time your princess was asleep?

2. Tool for checking numeric games


Create an Excel checker for number games Latin square and Magic square
which checks if the square is correct. For the Magic square it is sucient
to consider only rows and columns (not the diagonals).

a) Latin squares 3 × 3, 4 × 4
A Latin square of order n is a table n×n whose elements are n
dierent symbols placed in such a way that every symbol appears in
every row and every column exactly once, see Figure 4.2.

Figure 4.2: Examples of Latin squares 3×3 and 4 × 4.

b) Magic squares 3 × 3, 4 × 4
A Magic square is a placement of natural numbers 1, 2, 3, ..., n2 in
a table n×n in such a way that every number is used only once and
the sum of numbers in every row, every column and every diagonal
is the same, see Figure 4.3.

3. Tool for solving logical problems


Princess Porcia has a golden, a silver and a bronze box. To select a
husband, she places a portrait of herself in one of the boxes. Two boxes
remain empty. She puts a sign on each box, but the signs do not have to
be true. The future husband tries to nd the box with the portrait.
4.4. LAB PROBLEMS 123

Figure 4.3: Examples of Magic squares 3×3 and 4 × 4.

In Excel, create a tool for solving specic logical problems about hiding
things in boxes. This tool should conveniently display the question and
test where the portrait is located. The Excel sheet should automatically
evaluate whether the statements are true or false and determine whether
the placement of the portrait ts the problem.

a) At most one sign is true.


Golden: The portrait is in this box.
The portrait is not in this box.
Silver:
Bronze: The portrait is not in the golden box.

b) At least one sign is true and at least one is false.


Golden: The portrait is not in the silver box.
The portrait is not in this box.
Silver:
Bronze: The portrait is in this box.

c) There are two sentences on each box. On one box, both are true, on
one box, both are false and on one box, one is true and one is false.
Golden: Portrait is not in this box. Portrait is in the silver box.
Silver: Portrait is not in the golden box. Portrait is in the bronze
box.
Bronze: Portrait is not in this box. Portrait is in the golden box.
d) There are two sentences on each box. At most one sentence on each
box is true.
Golden: Portrait is not in this box. Painter is from Venice.
Portrait is not in the golden box. Painter is from Florence.
Silver:
Bronze: Portrait is not in this box. Portrait is in the silver box.
124 CHAPTER 4. MATHEMATICAL LOGIC

4.4.1 Hints and solutions


1. Tool for verication of algorithms
Here are three simple algorithms. Would you give them a certicate of
correctness? Check them on examples. If you nd mistakes, try to correct
them.

a) We have a string that contains an algebraic expression. We want to


check that it uses the brackets correctly. At the beginning, we set
the variables L and R to 0. We read the string from left to right. If
we encounter (, we increment L, if we encounter ), we increment R.
If R 6= L at the end, the use of brackets is not correct. If R = L, it
is correct.

Hint: We can indeed check the parentheses using this algorithm.


In some situations, the algorithm gives a correct answer, in some it
does not. The situations in which it does not give a correct answer
are the situations when we have the same number of left and right
parentheses but they are not in the correct places.

Solution: According to the problem, we should write an algebraic


expression and create two variables L and R. We can write their
values in the rows below the input expression. The sequence of values
represents the changes in the variables and the last value in the row
is the nal value that gets evaluated.

Figure 4.4: Variable L.

The characters + and − cannot be entered directly as text in Ex-


cel, therefore we input them as '+ and '−. Initially, the variable L
contains zero, see Figure 4.4, but then it changes according to the
formula we entered in C3.

What to do if the formula does not seem to work properly? It is


possible that it did not get copied correctly, see Figure 4.5. We check
4.4. LAB PROBLEMS 125

another cell to see its formula. To display which cells enter the given
formula, we click the formula and the cells are highlighted both in
the spreadsheet and in the formula line. In this case, we nd out
that we need to x the cell A1 (using the F4 key) and replace the
zero with the cell's left neighbor in the condition, see Figure 4.6.

Figure 4.5: Formulas can be checked in the formula line.

Then we create a similar line for the right parentheses and variable
R.

Figure 4.6: The formula is xed by adding dollar signs.

Finally, we check whether the last values in L and R match, as in


Figure 4.7.

We used the Excel IF command to evaluate the condition whether we


have the same values in the green elds. If we want to check whether
the algorithm works as desired, we break the parentheses rule and
check what it says, see Figure 4.8.

What about some other expression?

The algorithm does not work properly on all inputs, see Figure 4.9.
We need to modify it in such a way that there are never more right
parentheses than left.
126 CHAPTER 4. MATHEMATICAL LOGIC

Figure 4.7: Final check whether the nal values of variables L and R match.

Figure 4.8: Result of processing of an incorrect input.

Figure 4.9: Apparently, we are not done yet, because in some cases an incorrect
input is not discovered by our checks.

More complex input situations


How would we make sure that the rst character inside paren-
theses is not a + and the last character is not a + or a −?
Another condition is that the whole expression cannot end with
4.4. LAB PROBLEMS 127

a + or a −. How do we ensure that?


And how would our algorithm change if the whole algebraic ex-
pression was given as a string in one cell?

b) Heron's formula calculates the area of a triangle using the lengths


of its sides. We start with numbers x, y , z and calculate A using
Heron's formula. The value A represents the area of triangle with
sides x, y and z.
Hint: Nobody remembers all mathematical formulas, therefore it is
ok to look up the Heron's formula online. In the spreadsheet, we
designate some cells as input for x, y , z that represent the lengths
of triangle sides. We calculate the auxiliary value that represents
half the triangle perimeter and use it to calculate the triangle area.
We try various values of x, y , z to see whether this approach works
correctly and x any issues that arise.

Solution:
p
The Heron's formula is s(s − a)(s − b)(s − c), where
A=
s = (a + b + c)/2. In the Excel sheet, we designate cells for input of
triangle sides x, y , z and for calculation of s and A, see Figures 4.10
and 4.11.

Figure 4.10: Calculation of s for Heron's formula.

Figure 4.11: Calculation of A for Heron's formula.

Then we enter sides of various triangles for which we can easily com-
pute the area, e.g. right triangles for which the area is half the product
of the two short sides and the hypothenuse is calculated using the
Pythagorean theorem, see Figure 4.12.
128 CHAPTER 4. MATHEMATICAL LOGIC

Figure 4.12: Verifying that Heron's formula works for the right triangles.

Figure 4.13: Verifying that Heron's formula works for random triangles.

We can enter few more random triangles to see whether we get correct
results, see Figure 4.13.

The results seem to be ok, except for the last two triangles. If we
tried to construct those two, we would nd out it is not possible.
Therefore, we need to check the input values and display a message
when they are inadmissible. We can write the message Incorrect
input of triangle sides when the triangle inequality does not hold,
see Figure 4.14.

Checking inputs for correctness


The sides of the triangle have to have positive lengths. Do we
need to check for this separately or is the triangle inequality a
sucient check that takes care also of this issue?

c) Sleeping Beauty was asleep for 100 years. Then came a prince, kissed
her and maybe she woke up. If she did not wake up, he returned
again after one year and kissed her again. Create a table in Excel
4.4. LAB PROBLEMS 129

Figure 4.14: Incorrect input of triangle sides.

that counts the years of Sleeping Beauty's sleep. Assume that there
is a 0.5 probability that the Sleeping Beauty wakes up after a kiss.

Hints : We adjust the owchart slightly so that we use a variable Y


to denote the number of years asleep. We use the function =RAND-
BETWEEN(0;1) to generate randomness in such a way that both
options are equally probable. Depending on this chance, we decide
whether the Sleeping Beauty wakes up or not, i.e. whether we should
add 1 to Y or end the algorithm. Next we verify if the algorithm
works as expected for the inputs we enter. We can generate various
random inputs by repeated use of the F9 key.

Solution: As usual, we should consider how to create the solution


in such a way that it is comprehensible even if we return to it after
some time. An example layout is shown in Figure 4.15. In addi-
tion to the command RANDBETWEEN(0;1), we used the commands
IF(B2=0;"yes";"no"), IF(C2="no";"";"end") and IF(D2="end"; A2;
""). It is also possible to improve the solution in such a way that
after the rst ending, the algorithm does not re-start. This can be
done in the next column of the table.

Unequal probabilities
How would we modify the formula for chance, if the Sleeping
Beauty woke up after a kiss with probability 1/10 and kept on
sleeping with probability 9/10?
130 CHAPTER 4. MATHEMATICAL LOGIC

Figure 4.15: Sleeping Beauty

Revisiting Wall-e
Draw a owchart for the Wall-e problem from Section 1.4.

2. Tool for checking numeric games


Create an Excel checker for number games Latin square and Magic square
which checks if the square is correct. For the Magic square it is sucient
to consider only rows and columns (not the diagonals).

Hints : We enter (or randomly generate) the numbers that represent the
problem solution that needs to be checked. We use auxiliary rows and
columns on the perimeter of the table to verify the sums according to the
problem. We indicate the correct and the incorrect rows, columns and
whole table. What can be checked? How should we highlight incorrect
data?

a) Latin squares 3 × 3, 4 × 4
Solution: See Figure 4.16 for an example of a simple check for a Latin
square. The user enters values into the yellow cells. The OKs for rows
and columns are determined using the formula =IF(AND (COUNTIF
(B2:D2,1)=1, COUNTIF(B2:D2,2)=1, COUNTIF (B2:D2,3)=1), "OK",
"NOT OK").
4.4. LAB PROBLEMS 131

Figure 4.16: Check for a Latin square.

b) Magic squares 3 × 3, 4 × 4
Hint : See Figure 4.17 for an attempt at a check for a Magic square.
The user enters values into the yellow cells. The numbers in the green
cells are determined by the computer. Is this check sucient? Will
it work also for larger values of n? How can it be done dierently?

Figure 4.17: Check for a Magic square.

3. Tool for solving logical problems


Princess Porcia has a golden, a silver and a bronze box. To select a
husband, she places a portrait of herself in one of the boxes. Two boxes
remain empty. She puts a sign on each box, but the signs do not have to
be true. The future husband tries to nd the box with the portrait.

In Excel, create a tool for solving specic logical problems about hiding
things in boxes. This tool should conveniently display the question and
test where the portrait is located. The Excel sheet should automatically
evaluate whether the statements are true or false and determine whether
the placement of the portrait ts the problem.
132 CHAPTER 4. MATHEMATICAL LOGIC

Hints : After writing the symbols into boxes, Excel translates the symbols
into numbers and veries whether the conditions are met. Using a suitable
logical operation we can count the number of true statements and check
that it is as it should be.

Generalisation for other rules


The algorithm can evaluate the problem according to the rule written
in B3 and thus it can solve multiple problems at once. Can you write
the (more complicated) condition for B7 for such case?

a) At most one sign is true.


Golden: The portrait is in this box.
Silver:The portrait is not in this box.
Bronze: The portrait is not in the golden box.

Solution: It is useful to design the table header in a clear format so


that it helps to perform the needed evaluations. We ll the second
and third row according to the problem, see Figure 4.18. The user
enters values into the white cells. The numbers in the green cells
are generated by the computer. We use the fourth line to place the
portrait into one of the boxes. Excel evaluates the statements in the
fth line and makes a control checksum. If the checksum is larger
than one, it writes out"This placement is incorrect.", otherwise it
writes out "This placement is OK."

Figure 4.18: Checker of statements.


4.4. LAB PROBLEMS 133

Inverse problem
Is it possible to work in reverse, i.e. input the truth values of indi-
vidual statements and the worksheet determines the contents of the
boxes?
134 CHAPTER 4. MATHEMATICAL LOGIC
Chapter 5

Number sets

5.1 Lecture overview

The number sets did not arise all at once. They appeared historically as they
were needed for practical, technical and scientic progress. Later, mathemati-
cians dened them precisely and investigated their, often very abstract, proper-
ties. However, many of them are important for understanding practical problems
appearing in computer science.

5.1.1 Natural numbers N


The natural numbers are the simplest and basic number set. While this state-
ment is true when we think about them from the position of the science of
mathematics today, in the history of people, science and mathematics, their
discovery was signicant and not at all obvious.

Natural numbers dened using sets


In the set theory, we dene the natural numbers in such a way that we model
the rst one as an empty set ∅. Every next number is created as a set containing
all previous sets, e.g. {∅}, {∅, {∅}} etc. These sets are so special that using the
set operations, it is possible to dene addition of natural numbers. Using the
addition it is then possible to dene multiplication. This approach is only feasi-
ble when examining the inherent properties of natural numbers and theoretical
foundations of mathematics.

135
136 CHAPTER 5. NUMBER SETS

Peano axioms
A more convenient approach for examining the natural numbers and their arith-
metics are the Peano axioms. We call every set which has the following proper-
ties a set of natural numbers :
• Natural numbers N contain a special element, which we denote O. This
essentially says that the set N is nonempty. The notation suggests that
this special element is 0, which may be true but it is not necessary.

• With every element x, the set N also contains the element S(x), its suc-
cessor. As the following axioms show, the successor corresponds to the
natural number following immediately after x, i.e. to the number x + 1.
• O is not a successor of any element in N. Therefore, O is the rst element
of the setN. Using this property, we can also show that S(O) 6= O,
S(S(O)) 6= S(O) etc. N is thus an ever growing set that continues to
innity.

• If x 6= y , then S(x) 6= S(y). (We can also use the contrapositive S(x) =
S(y) implies x = y .) Thus it cannot happen that two dierent elements
have the same successor. Together with the following axiom, this prop-
erty lets us show that there is no other element between O and S(O), or
between x and S(x) in general.

• Axiom of induction is a dierent beast. It says that if O has some property


V and for each x in N we can prove (the implication) that if x has the
property V, then also its successor S(x) has this property, than all natural
numbers have the property V. This axiom enables proofs by mathematical
induction. The principle is simple and can be thought of as a domino
principle. If we knock down one domino and we ensure that every domino
knocks down the one that comes after it, then we know that all dominoes
are going to fall, even if there are innitely many of them. It also ensures
that the natural numbers form one line, which can be traversed from the
origin O by sequential addition of one.

Arithmetics and ordering


The arithmetics and ordering of natural numbers are described by the following
properties, where O corresponds to the number 0:

• x+0=x
5.1. LECTURE OVERVIEW 137

• x + S(y) = S(x + y)

• x·0=0

• x · S(y) = x · y + x

• x≤y i there exists such z that x + z = y. (It can be shown that ≤ is a


linear ordering, see Section 7.1.1.)

If we are content with a simple, not completely precise, denition we can


say that natural numbers are those which can be used to denote the number of
elements of sets. Even though the properties that we mentioned consider 0 to
be the rst natural number, other areas of mathematics typically say that the
smallest natural number is 1. We also adopt this convention, therefore in the
following, we will have N = {1, 2, 3, 4, . . .}. In case we want to include also zero,
we are going to use the notation N0 = {0, 1, 2, 3, 4, . . .}.

Base systems
If we want to use a number system, besides the denition, we also need some
means to write the numbers down. Finding a suitable and generally accepted
notation for natural numbers took thousands of years. From sticks, stones,
knots or notches people transitioned to ngers and then to written forms and
various counting tools. Even the Egyptian hieroglyphs, Sumerian cuneiforms or
Roman numerals were not the denitive answers. After those, people adopted
the Hindu, i.e. Arab numbers. (The Arabs adopted them form the Indians and
the Europeans from the Arabs).
The various system brought with them also various bases. The base systems,
such as decimal, binary or hexadecimal, all work on the same principle. They
use n dierent characters, mostly 0, 1, 2, . . . , n − 1, which also represent the
amount 0, 1, 2, . . . , n − 1. If there is not enough digits, e.g. in the hexadecimal
system, some other symbols are included, e.g. a, b, c, d, e, f . The individual
digits and their position in the written number denote the power to which the
base n is raised. So for the decimal system, they represent ones, tens, hundreds,
thousands, etc. For binary they represent ones, twos, fours, eights etc. If we also
use the decimal point, we write the reciprocals after it, i.e. tenths, hundredths,
etc. or halves, quarters, eighths, etc.

Problem 5.1 Binary to decimal:


Convert 100010 from binary to decimal.
138 CHAPTER 5. NUMBER SETS

Solution:
1000102 = 1 · 25 + 0 · 24 + 0 · 23 + 0 · 22 + 1 · 21 + 0 · 20 = 32 + 2 = 3410

Problem 5.2 Decimal to binary:


Convert 34 from decimal to binary.

Solution:
34 : 2 = 17 rem 0
17 : 2 = 8 rem 1
8:2 = 4 rem 0
4:2 = 2 rem 0
2:2 = 1 rem 0
1:2 = 0 rem 1

The numbers in the binary system are the remainders after division ordered
from the end, i.e. 3410 = 1000102 .

Problem 5.3 Decimal to hexadecimal:


Convert 43 from decimal to hexadecimal.

Solution:
43 : 16 = 2 rem 11
2 : 16 = 0 rem 2

The numbers in the hexadecimal system are the remainders after division or-
dered from the end, i.e. 4310 = 2b16 = 0x2b, where the digit b represents 11 and
0x is used to denote a hexadecimal number.

Problem 5.4 Binary to hexadecimal:


Convert 100010 from binary to hexadecimal.

Solution: 1000102 = 0010|00102 = 0x22. Here we used the fact that 16 = 24 and
thus all we need is to split the binary number into groups of four and replace
each of them with the corresponding hexa-digit.
5.1. LECTURE OVERVIEW 139

5.1.2 Integers Z
The natural numbers are a great invention but they are not perfect. As soon
as we want to subtract a larger number from a smaller one, we encounter a
problem. Many years ago, the merchants keeping track of their gains and losses
and of course mathematicians in their calculations encountered this problem.
Formally, it is not dicult to create integers from N0 . To every number (besides
0) we add once a character + and once a character −. We thus create a set Z =
{0, +1, −1, +2, −2, +3, −3, . . .} and dene the operations using the operations
we had with natural numbers, e.g. (−, 7) + (−, 4) is (−, 7 + 4), or (−, 3) · (+, 4) =
(−, 3 · 4). We extend the ordering in a similar fashion: positive (+) numbers
are ordered in the same way as natural numbers, negative (−) numbers are in
reverse order and each negative numbers is smaller than each positive numbers.

The natural numbers N are part of integers. They correspond to the + part.
Compared to the natural numbers, integers are innite in both directions. We

use the notation Z+ , Z− , Z+
0 , Z0 .

5.1.3 Rational numbers Q


The integers solved the problem with subtraction, but not with division of num-
bers. Various economic, geodesic and technical calculations required working
with parts or fractions of integers. This work was hindered for a long time by
the lack of a suitable notation. Egyptian root fractions and Babylonian fractions
with base 60 were impractical and complicated the development of mathemat-
th
ics until the 16 century. That was the time when the decimal numbers and
fractions nally arrived in Europe.

Fractions as ordered pairs


Formally, we can dene the rational numbers as ordered pairs (z, n) that belong
to the Cartesian product Z × N, which can be thought of as fractions z/n. We
dene the operations as we are used to from working with fractions, e.g. (z, n) +
(u, m) = (z · m + u · n, n · m). Note that if we dene fractions in this way, we
have too many of them. Many ordered pairs (fractions) (2,3), (4,6), (−20/−30),
etc. denote the same rational number. Therefore, we can say that if n·u = m·z
then we consider the numbers (z, n) and (u, m) equivalent and they merely
represent a dierent notation for the same number.
140 CHAPTER 5. NUMBER SETS

Periodic decimal numbers as fractions


The integers are part of rational numbers and correspond to the pairs (z, 1). If
we write the rational numbers in the base 10 system, we use a decimal point and
the digits to the right of it represent tenths, hundredths, etc. The decimal part
of a rational number is either nite or innitely periodic. The decimal numbers
with innitely periodic part can be written as fractions using the following
method:

0, 7̄ = x
7, 7̄ = 10x
7 + 0, 7̄ = 7 + x = 10x
7 = 9x
x = 7/9

Ordering and being dense


The ordering of rational numbers remains linear but compared to integers they
have a new property. They are dense : between every two rational numbers
r, q , there is another rational number, e.g. their average (or middle point)
(r + q)/2. Consequently, between every two rational numbers, there are in-
nitely many more rational numbers. Similarly to integers, we use the notation

Q+ , Q− , Q+
0 , Q0 .

Representation in computers
When representing natural numbers and integers in computers, we do not en-
counter many surprises. Of course, due to hardware limitations, it is necessary
to limit their minimal and maximal values. Issues then arise when the re-
sults of some operations overow the ranges of represented values, so dierent
approaches have to be taken when computing with really large numbers with
millions of digits, e.g. when searching for large primes and factorisations.
When working with rational numbers, we encounter also issues pertaining
to accuracy  innite decimal numbers do not t into the computer memory.
Moreover, since they are saved in binary, even seemingly simple numbers such as
0.1 have innite binary expansions and calculation with such numbers leads to
unpleasant and sometimes downright dangerous numerical inaccuracies. Some-
times the solution is to teach the algorithms to work with fractions.
5.1. LECTURE OVERVIEW 141

It is not correct to say that for computers, engineering and science it is


sucient to only know the rational numbers to the extent to which they are
restricted by hardware. If we restricted our knowledge in this way, the numerical
errors could lead to collapse of buildings, trac accidents, chaos in banks, etc.
The knowledge of number sets leads us to solutions that eliminate these errors.

5.1.4 Real numbers R


Irrational numbers
The path from rational numbers to real numbers was long and winding and
ended only in the 19th century. The ancient Greeks knew that if the side of a
square was a fraction, the diagonal was not a fraction. The reason is that the
square root of 2 is irrational. However, if we only wanted to extend the rational
numbers by all the numbers that can be created using a ruler and a compass, it
would be sucient to iteratively add just square roots of all already constructed
numbers.
The ancient Greeks knew about other numbers, e.g. the golden ratio φ and
more importantly π, whose signicance was primarily geometric. Another area
that needed extension of rational numbers was algebra. Solving polynomial
equations with degree 2, 3, 4 and more required existence of square, cube, fourth
etc, roots and expressions containing them. Today we call these numbers (roots
of polynomials) algebraic. They represent a signicant but still not sucient
extension of the rational numbers. Later, more and more irrational numbers
appeared: a special singleton is e, large groups were values of the sine, cosine
and logarithmic functions. What else are we going to need?

Dedekind cuts
The denitive answer to the previous question required quite advanced mathe-
matics. One formulation was given by Richard Dedekind. If we restrict ourselves
to the positive rational numbers q, we can consider the open intervals (0, q) in-
stead of them. These intervals have simple properties: 1. with every rational
number, they also contain all smaller rational numbers and 2. we can dene
certain arithmetics on them. If (0, q) + (0, r) is an interval containing all sums
of any number from the rst interval with any number from the second interval,
it corresponds to the interval (0, q + r).
However, there exist other sets that have these properties but do not cor-
respond to any interval ending with a rational number. One of them is for
142 CHAPTER 5. NUMBER SETS

example the set of all positive rational numbers for which q2 < 2 holds. Upper

end-point of the corresponding interval suggests the irrational number 2. If
we take all sets of positive rational numbers that have properties 1 and 2, their
upper end-points correspond to all positive real numbers.

Limits of sequences
Another path to real numbers leads through sequences of rational numbers. If
we write a sequence, such as 1/2, 1/3, 1/4, 1/5, . . . we often notice that it tends to
some number, in this case to zero. Tending to some number has been precisely
dened at the beginning of the 19th century and is called a limit. Considering
special properties of sequences, see Section 8.1.3, it is possible to determine that
a sequence must have a limit even if we do not know its value (yet). And here
was the problem. For some sequences, it was possible to prove that the limit
exists but that it is not a rational number. If we extend the rational numbers
by all limits of such sequences, we again obtain real numbers.
Both methods of extending the rational numbers are very eective. If we
repeated either of them one more time, there would be no additional new num-
bers. So both of these constructions extend the rational numbers by all irrational
numbers and we thus obtain all real numbers.

Geometric notion
Compared to the numbers we had before, there are many more real numbers.
It manifests in such a way that if we place them all on a line, we cover all its
points. The rational numbers did not do that. Even though they were dense
and there were innitely many of them, they left out even more points on the
line. In a geometry based on rational line segments, the diagonals of a square
would not intersect. This cannot happen with real numbers. This is the reason
why we can say that every polynomial of odd degree must have at least one real
root, because its graph has to intersect the x-axis.

We again use the notation R+ , R− , R+
0 , R0 for positive, negative, non-positive
and non-negative real numbers.

Approximations
We can approximate real numbers using fractions with various degrees of pre-
cision. It can be shown that of all fractions with single-digit denominator, 22/7
is the best approximation of π. If we allow a three-digit denominator, the best
5.1. LECTURE OVERVIEW 143

approximation (to six decimal places) is 355/113. The next better fraction is
103993/33102. Using 355/113 is thus very eective. We can arrive at these
estimates also by using the continued fractions of the form:

1
x = a0 + 1 .
a1 + a2 + 1
a3 + 1
a4 +...

We can expand both rational numbers (their continued fractions are nite) and
irrational numbers (their fractions are innite). If we only use the nite part of
the innite fractions, we obtain the ecient approximations.

5.1.5 Complex numbers C


Imaginary unit and algebraic form
The complex numbers turned out to be inevitable at the beginning of the 16th
century. Italian mathematician Cardano discovered formulas for calculation of
roots of cubic equations and showed that to express their values, he had to work
with square roots of negative numbers. In these calculations, it turned out that
it is sucient to use the square root of −1, which was later denoted as i by
Euler, and we call it an imaginary unit. For this number, we have a property
never heard of before: i2 = −1. Every complex number z now can be expressed
using i and two real numbers a, b as a + bi. We call this an algebraic form of a
complex number and we clearly see its real and imaginary parts. As expected,
it was possible to solve the polynomial equations with these numbers. All of the
equations now had roots.

Geometric representation
If we want to represent a complex number geometrically, we treat the x and
y axes as real and imaginary. Every complex number z = a + bi thus gets
its place in the complex plane, see Figure 5.1. The place is determined by the
coordinates a on the real and b on the imaginary axis. The addition of complex
numbers corresponds to addition of vectors in the plane. The relation i2 = −1
implies a dierent meaning of the multiplication (compared to real numbers).
Multiplication by a real number corresponds to prolongation/shortening of the
vector that represents the complex number. Multiplication by a complex number
corresponds to both prolongation/shortening and rotation. The solutions of
equation zn = 1 correspond to vertices of regular n-sided polygons in a plane.
144 CHAPTER 5. NUMBER SETS

Figure 5.1: Complex numbers.

Complex conjugates

Sometimes it is useful to consider the complex number z = a − bi together with


z = a + bi. The number z is called complex conjugate to z and it is its mirror
image with respect to the x-axis, see Figure 5.2. For the product of a complex
number and its conjugate we have z · z = (a + bi) (a − bi) = a2 + b2 = |z|2 .

Figure 5.2: Complex conjugate numbers.


5.1. LECTURE OVERVIEW 145

Trigonometric form
To understand the multiplication properties of complex numbers (other than
z = 0), it is useful to write them in trigonometric form. It species the complex
number by its distance r from origin 0 + 0i and by its angle ϕ (as measured from
the positive real axis) at which we should walk this distance. The distance r is
called the modulus of the number z (similar to the real axis, where the absolute
value represents the distance from 0) and is denoted by |z|. The angle ϕ is
also called an argument of the complex number. Using the unit circle, we see
that a complex number z can be written as z = a + bi = |z| cos ϕ + i|z| sin ϕ =
|z|(cos ϕ + i sin ϕ). The last expression the trigonometric form.
Using the Pythagorean theorem and the algebraic form
√ z = a + bi, we get
|z| = a2 + b2 and determine ϕ √ a
from cos ϕ =
or sin ϕ = √a2b+b2 .
a2 +b2
If we write two complex numbers in trigonometric form u = |u|(cos ϕ+i sin ϕ)
and v = |v|(cos ψ + i sin ψ), their product is

u · v = |u||v|(cos ϕ · cos ψ − sin ϕ. sin ψ + i(cos ϕ · sin ψ + cos ψ. sin ϕ)).


Using the trigonometric formulas, we can simplify this expression to

u · v = |u||v|(cos(ϕ + ψ) + i sin(ϕ + ψ)).


Thus, when multiplying two complex numbers, we multiply their distances
from 0 + 0i and add their angles (arguments). This allows relatively easy calcu-
lations with complex numbers and a geometrical use. The roots of the equation
zn = 1 represent vertices of a regular polygon. The rst use of this property
was the discovery of young Gauss, who determined which regular polygons with
n vertices can and which cannot be constructed using a ruler and a compass.

Problem 5.5 Division of complex numbers:


Calculate (3 + 4i) : (6 − 12i).

Solution: We talked about multiplication, but how do we divide complex num-


bers? The rst thing we can try is to use what we know about multiplication. If
we assume that the result of this calculation is again a complex number a + bi,
then we can rewrite the problem as

3 + 4i = (6 − 12i) · (a + bi)
and multiply everything out:

3 + 4i = 6a − 12ai + 6bi − 12bi2 = (6a + 12b) + (6b − 12a)i.


146 CHAPTER 5. NUMBER SETS

This results in a system of two equations with two real unknowns:

3 = 6a + 12b
4 = 6b − 12a

The unique solution of this system is a = −1/6 and b = 1/3 and thus

(3 + 4i) : (6 − 12i) = −1/6 + i/3.

An alternative way of solving this problem is to use the complex conjugate of


the denominator and perform the following calculation which makes the denom-
inator a real number:

3 + 4i 3 + 4i 6 + 12i 18 + 24i + 36i + 48i2 18 + 60i − 48


= · = 2
=
6 − 12i 6 − 12i 6 + 12i 36 − 144i 36 + 144
−30 + 60i
= = −1/6 + i/3.
180

Exponential form
There is one more form of a complex number that is frequently used, the expo-
nential form. It results from the relation eiϕ = cos ϕ + i sin ϕ. It can be derived
from functional series and is useful in many applications. A complex number
z = |z|(cos ϕ + i sin ψ) can thus be written as z = |z|eiϕ and the product of two
i(ϕ+ψ)
complex numbers is then u · v = |u||v|e .

Ordering
We pay a price for the many useful properties of complex numbers. This is
the rst number set that cannot be linearly ordered, i.e. we cannot place the
numbers on a suitable axis. We could order the complex numbers alphabetically,
but then the binary operations as we are used to them would not work any more.
This is one of the reasons why we display complex numbers in a plane. And even
though we do not have linear ordering, it is useful to compare their magnitudes:
|z1 | < |z2 |.
5.2. QUESTIONS 147

5.2 Questions

1. In which number eld is mathematical induction dened and what does


this concept mean?

2. Decide which of the operations (addition, subtraction, multiplication and


division) may be performed without restrictions in the following number
elds:

a) Natural numbers

b) Rational numbers

c) Real numbers

d) Irrational numbers

e) Complex numbers

3. Why is it not sucient to use integers for mathematical calculations? Give


an example of a problem that cannot be solved in integers.

4. Write as a fraction

a) 0.6
b) 0.9
c) 0.42
5. Write at least two

a) rational numbers between 0.7 and 0.8


b) rational numbers between 3/11 and 4/12
√ √
c) irrational numbers between 15 and 17
d) irrational numbers between 15 and 17

6. When we add the number 0.01 one thousand times in Excel, we will not
get exactly 10. Why? For which numbers will this multiplication work?

7. Is there a rational number between every two rational numbers?

8. Is there an irrational number between every two irrational numbers?

9. For which natural numbers is it true that twice their square is also a square
(a number raised to a second power)? Prove your answer.
148 CHAPTER 5. NUMBER SETS

10. Why is it not sucient to use rational numbers for mathematical calcu-
lations? Give an example of a problem that cannot be solved in rational
numbers.

11. Explain how to draw a square root of 2, 3, 4, 5, 6, 7, . . .


12. Write at least 3 decimal numbers that dier from π by at most 0.002.

13. Describe a mathematical construction that can build all real numbers from
rational numbers.

14. Why is it not sucient to use real numbers for mathematical calculations?
Give an example of a problem that cannot be solved in real numbers.

15. Write a quadratic equations that does not have a solution in real numbers.

16. Write a complex number with real part 1 and imaginary part 2 in

a) algebraic form

b) trigonometric form

c) exponential form

17. Express 360 degrees in radians. Express π/2 in degrees. What is the
general formula for conversion of degrees to radians? What is the formula
for conversion of radians to degrees?


18. Draw in complex plane z1 = 3 + 5i, z2 = 5(cos 45◦ + i sin 45◦ ), z3 = ei60 .

19. Draw the sum of these two numbers in the complex plane: z1 = 3 + 5i
and z2 = 2 + 3i.

20. Draw the product of these two numbers in a complex plane z1 = 3ei60

and z2 = 3ei90 .

21. Which of the complex numbers z1 = 3 + 5i and z2 = 2 + 3i is farther from


0+0i?

22. A number in binary system is 11001101. Write the same number in decimal
and in hexadecimal system.
5.3. PROBLEM SET 149

5.3 Problem set

1. Dividing by complex numbers


Calculate

3+2i
a)
2−3i
(3+2i)(4−3i)
b)
(2−3i)
(7−i)(−2+4i)
c)
(1+4i)
(−2+5i)(2+5i)
d)
(5+2i)
(6i)(5+2i)
e)
(−4−3i)

2. Complex roots
Find one complex root of the equation and verify it by plugging it into
the equation:

a) x2 + 3x + 4 = 0
b) x2 − 2x + 3 = 0
c) −x2 + x − 2 = 0
3. Trigonometric form
Write the complex numbers in trigonometric form:

a) 2 − 3i
b) −2i
c) −1 + 5i
d) −3 + i
e) −4
4. Algebraic form
Write the complex numbers in algebraic form:

a) 2 · (cos 45◦ + i · sin 45◦ )


b)
1
3 · (cos 60◦ + i · sin 60◦ )
c) (−1) · (cos(−30◦ ) + i · sin(−30◦ ))
5. Rational numbers as fractions
Write these numbers as fractions:
150 CHAPTER 5. NUMBER SETS

a) 0.7
b) 0.27
c) 0.369
d) 0.123
e) 0.5342
6. Continued fractions
Write these numbers as chain (continued) fractions:

a) 3.456
b) 15/7

c) 2

7. Conversion to decimal system


Convert the following numbers to decimal form:

a) From binary: 110110; 10101

b) From ternary: 120120; 22222

c) From hexadecimal: 0x3d39; 0xd431

8. Conversion from decimal system


Convert the numbers 123 and 321 from decimal to:

a) Binary form

b) Base-8 form

c) Hexadecimal form

Add the converted numbers.


5.3. PROBLEM SET 151

5.3.1 Hints and solutions


1. Dividing by complex numbers
Calculate

(3+2i)(4−3i)
b)
(2−3i)
(7−i)(−2+4i)
c)
(1+4i)

Hints :
In these problems, to calculate means to convert the expressions into a
complex number in the algebraic form z = a+bi so that the imaginary unit
i does not appear in the denominator. The numerators can be multiplied
out and the corresponding terms collected. To remove the imaginary part
from the denominator of a fraction, we can multiply both the numerator
and denominator of a fraction by a complex conjugate of the denominator.

Solution:
b)
(3 + 2i)(4 − 3i) (2 + 3i) (12 − 9i + 8i − 6i2 )(2 + 3i)
· = =
(2 − 3i) (2 + 3i) (4 + 6i − 6i − 9i2 )

(18 − i)(2 + 3i) 36 + 54i − 2i − 3i2 39 + 52i


= = = = 3 + 4i
13 13 13

c)
(6i)(5 + 2i) (−4 + 3i) (30i + 12i2 ) · (−4 + 3i)
· = =
(−4 − 3i) (−4 + 3i) 16 − 12i + 12i − 9i2

−120i + 90i2 + 48 − 36i −42 − 156i 42 156i


= = =− −
25 25 25 25
2. Complex roots
Find one complex root of the equation and verify it by plugging it into
the equation:

a) x2 + 3x + 4 = 0

Hints :
152 CHAPTER 5. NUMBER SETS

• To calculate the roots of the quadratic equation ax2 + bx + c = 0,


where a, b, c are real numbers and a 6= 0, we can use the discriminant

D = b2 − 4ac. The roots can be expressed as x1,2 = −b± 2a
D
.

• What to do when the discriminant is negative? In such case, the


equation does not have a real root. But now we know that the number
2
−1 can be expressed as
√ i which
√ lets us √evaluate square roots of
negative numbers, e.g. −10 as 10i2 = i 10.
• To verify the result, we can plug the roots back into the original
equation and check that the left-hand side equals the right-hand side.

Solution:
a) x2 + 3x + 4 = 0

D = b2 − 4ac = 32 − 4 · 1 · 4 = −7 = 7i2
√ √ √
−b ± D −3 ± 7i2 −3 ± i 7
x1,2 = = =
2a 2·1 2
Plugging the root x1 into the equation:

√ !2 √ !
−3 + i 7 −3 + i 7
x21
+ 3x1 + 4 = +3· +4=
2 2
√ √ √ √
9 − 6i 7 − 7 9 − 3i 7 2 − 6i 7 − 18 + 6i 7 + 16
= − +4= =0
4 2 4
Plugging the root x2 into the equation:

√ !2 √ !
−3 − i 7 −3 − i 7
x22
+ 3x2 + 4 = +3· +4=
2 2
√ √ √ √
9 + 6i 7 − 7 9 + 3i 7 2 + 6i 7 − 18 − 6i 7 + 16
= − +4= =0
4 2 4
3. Trigonometric form
Write the complex numbers in trigonometric form:

a) 2 − 3i
b) −2i
5.3. PROBLEM SET 153

Hints :
• To convert a complex number to its trigonometric form we need to
nd out its modulus (length) and its argument (angle) ϕ.
• It is helpful to draw the complex number in the complex plane and
look at the angle ϕ we are trying to nd. The angle is taken in the
counter-clockwise direction from the positive x-axis. If we go in the
clockwise direction, the angle is negative.

• The length of the complex number can be calculated using a Pythagorean


theorem and the angle using a suitable trigonometric function.

Solution:
a) We start by drawing the complex number 2 − 3i in a complex plane.

Figure 5.3: Complex number 2 − 3i.

ϕ can be calculated as 360◦ − ϕ0


In Figure 5.3, we see that the angle
0 3 0 3 ◦

and that tan ϕ = −
2 ⇒ ϕ = arctan − 2 ≈ −56.3 . Note that
this is not an exact value. While for some angles it is possible to
obtain the answer as an expression containing the irrational number
π , here we give a rational approximation Then ϕ ≈ 360◦ − 56.3◦ =
303.7◦ .
We can calculate the size of the complex number using the Pythagorean
p √
theorem as |z| = 22 + (−3)2 = 13.
Now we express the complex number 2−3i in the trigonometric form:

z≈ 13 · (cos 303.7◦ + i · sin 303.7◦ )
154 CHAPTER 5. NUMBER SETS

Figure 5.4: Complex number −2i.

b) The complex number −2i lies directly on the imaginary axis, see
Figure 5.4, therefore its angle ϕ can be determined directly without
any calculations as ϕ = 270◦ or as ϕ = 32 π radians. The length of
the complex number is |z| = 2, therefore the trigonometric form is

3 3
z = 2 · (cos π + i · sin π).
2 2

4. Algebraic form
Write the complex numbers in algebraic form:

a) 2 · (cos 45◦ + i · sin 45◦ )


1
b) · (cos 60◦ + i · sin 60◦ )
3
c) (−1) · (cos(−30◦ ) + i · sin(−30◦ ))

Hints:
• For the real and imaginary components of complex numbers a + bi
we have: a = |z| · cos ϕ, b = |z| · sin ϕ.
• For some angles, such as 45◦ or 30◦ , the values of the trigonometric
functions evaluated at them are well know and tabulated.

• For negative angles (going clockwise from the x-axis) we have: cos(−ϕ) =
cos ϕ and sin(−ϕ) = − sin ϕ. These relations follow from the facts
that cos ϕ is an even function and sin ϕ is an odd function.

Solution:
5.3. PROBLEM SET 155

√√ !
◦ ◦ 2 2 √ √
a) 2 · (cos 45 + i · sin 45 ) = 2 · +i· = 2+i 2
2 2
√ ! √
1 ◦ ◦ 1 1 3 1 3
b) · (cos 60 + i · sin 60 ) = · +i· = +i·
3 3 2 2 6 6
√ ! √
◦ ◦ 3 1 3 1
c) (−1)·(cos(−30 )+i·sin(−30 )) = (−1)· −i· =− +i·
2 2 2 2

5. Rational numbers as fractions


Write these numbers as fractions:

a) 0.7
b) 0.27
c) 0.369
d) 0.123

Hints:
• Before we start converting decimal numbers to fractions, we can look
at the problem from the other side. What are the decimal numbers
1 1 1 1
for
2 , 3 , 5 , 9 ? Some of them have a nite number of digits after the
decimal point, some of them are innite. The interesting fact is that
the innite ones are periodic. To turn them back into fractions, we
can observe a connection between the fractions that contain digits 9 in
1
their denominators:
9 = 0.1, 12 123 1234
99 = 0.12, 999 = 0.123, 9999 = 0.1234.
5 1 47
How much is
10 + 10 · 99 ?
• Using our observations, we can start converting the periodic decimal
numbers into fractions, e.g. 0.6 = 6 · 0.1 = 6 · 19 = 69 or 0.06 =
1 6 6
0.1 · 0.6 = 10 · 9 = 90 . Similarly, we can write any number that
contains only a periodic part after the decimal point. The situation
is slightly more complicated if there is also a non-periodic part. In
such case, it helps to separate the two parts and express them as
4 6 4·9+6 42
separate fractions, e.g. 0.46 = 0.4 + 0.06 = 10 + 90 = 90 = 90 .
• An alternative method for converting a decimal number to a fraction
is shown in the lecture. We represent the number as a variable,
multiply both sides by a suitable number so that the periodic part of
the number can be separated from the non-periodic. We substitute
156 CHAPTER 5. NUMBER SETS

the variable for the periodic part and express it from the equation in
the form of a fraction.

• In this problem we can easily verify the results using a calculator.

Solution:
a) Let x = 0.7, then
10x = 7.7 = 7 + 0.7
7
10x = 7 + x ⇒ 9x = 7 ⇒ x =
9
b) Let z = 0.27, then
100z = 27.7 ⇒ 100z = 27 + 0.7

Now we use the result of the previous calculation and replace 0.7
7
with
9.
7
100z = 27 +
9
27 · 9 + 7 27 · 9 + 7 27
100z = ⇒ z= =
9 9 · 100 90
c) Let x = 0.369, then
100x = 36.9 = 36 + 0.9

Now we convert 0.9 to a fraction separately.


Let y = 0.9, then
10y = 9.9 = 9 + 0.9
9
10y = 9 + y ⇒ y = =1
9
And then we insert the result into the original equation.
37
100x = 36 + 1 ⇒ x =
100
d) Let x = 0.123, then
⇒ 1000x = 123.123 = 123 + 0.123 ⇒ 1000x = 123 + x ⇒
123
⇒ 999x = 123 ⇒ x =
999
6. Continued fractions
Write these numbers as continued (chain) fractions:
5.3. PROBLEM SET 157

a) 3.456
Hints: In the lecture we show the form of the chain fraction in which the
term a1 represents the integer part of the number and the digits after the
1
decimal point are converted to a fraction, e.g. 0.5 = 1 . The fraction
0.5
that appears in the denominator should again be split into the integer
part (a2 , a3 , . . . , an ) and the digits after the decimal point. By repeating
this algorithm we can express any real number as a chain fraction. For a
rational number, the resulting fraction is nite, for irrational it is innite.
Solution:
1 1 1
a) 3.456 = 3 + 0.456 = 3 + =3+ =3+ =
1 2.1929.. 2 + 0.1929..
0.456

1 1 1
=3+ =3+ =3+ =
1 1 1
2+ 2+ 2+
1 5.1818.. 5 + 0.1818..
0.1929..

1 1 1
=3+ =3+ =3+
1 1 1
2+ 2+ 2+
1 1 1
5+ 5+ 5+
1 5.5 1
5+
0.1818.. 2
7. Conversion to decimal system
Convert the following numbers to decimal form:

a) From binary: 110110; 10101

b) From ternary: 120120; 22222

c) From hexadecimal: 0x3d39; 0xd431

Hints:
• When converting a binary number to decimal, the digits 1 tell us
which powers of 2 (ordered from the right) we should add.

• Conversions from other number systems work on the same principle.


Every digit tells us how many times should we add the particular
power of the base, e.g. 203 = 2 · 31 + 0 · 30 = 610 .
158 CHAPTER 5. NUMBER SETS

• If we do not have enough digits, e.g. in the hexadecimal system, we


can use letters, e.g. a, b, c, d, e, f for digits 10, 11, 12, 13, 14, 15.

Solution:
25 24 23 22 21 20
a) 32 16 8 4 2 1
binary number: 1 1 0 1 1 0

decimal number: 1 · 32 + 1 · 16 + 0 · 8 + 1 · 4 + 1 · 2 + 0 · 1 = 5410

35 34 33 32 31 30
b) 243 81 27 9 3 1
ternary number: 1 2 0 1 2 0

decimal number: 1 · 243 + 2 · 81 + 0 · 27 + 1 · 9 + 2 · 3 + 0 · 1 = 42010

163 162 161 160


c) 4096 256 16 1
hexadecimal number: 3 d 3 9

decimal number: 3 · 4096 + d · 256 + 3 · 16 + 9 · 1 = 1567310

8. Conversion from decimal system


Convert the numbers 123 and 321 from decimal to:

a) Binary form

b) Base-8 form

c) Hexadecimal form

Add the converted numbers.

Hints:
5.3. PROBLEM SET 159

• When converting numbers from the decimal system to binary, we are


looking for the largest powers of 2 that are comprised in the base-10
number. For example, the largest power of 2 comprised in 1810 is
24 = 16. Afterwards, we check what other powers of 2 would t.
3 2 1
Since 18 − 16 = 2, the powers 2 and 2 are represented by zeros, 2
0
by a one and 2 again by a zero. The conversion can be written as
1810 = 1 · 16 + 0 · 23 + 0 · 22 + 1 · 21 + 0 · 20 = 100102 .

• Algorithmically, this method is usually performed as successive divi-


sion by 2. The remainders after this division taken in reverse order
represent the binary number. The same approach works for conver-
sions to other number systems.

• If we already have a binary representation of a number, the conversion


to base-8 or hexadecimal is much easier (compared to conversion from
decimal system). Consider triplets (quartets) of binary digits and
their relation to base-8 (hexadecimal) digits.

Solution:

a) Decimal to binary

123 : 2 = 61 rem 1
61 : 2 = 30 rem 1
30 : 2 = 15 rem 0
15 : 2 = 7 rem 1
7 : 2 = 3 rem 1
3 : 2 = 1 rem 1
1 : 2 = 0 rem 1

⇒ 12310 = 11110112
160 CHAPTER 5. NUMBER SETS

321 : 2 = 160 rem 1


160 : 2 = 80 rem 0
80 : 2 = 40 rem 0
40 : 2 = 20 rem 0
20 : 2 = 10 rem 0
10 : 2 = 5 rem 0
5 : 2 = 2 rem 1
2 : 2 = 1 rem 0
1 : 2 = 0 rem 1

⇒ 32110 = 1010000012
1111011 + 101000001 = 110111100 = 44410
Addition in binary:

b) Decimal to base-8

123 : 8 = 15 rem 3
15 : 8 = 1 rem 7
7 : 8 = 0 rem 7

⇒ 12310 = 7738
c) Decimal to hexadecimal

123 : 16 = 7 rem 11
7 : 16 = 0 rem 7

⇒ 12310 = 0x7b16
Alternatively, we can take the binary representation 11110112 and
split it into quartets: 0111 and 1011. Note that we included an
initial 0 in the rst quartet, because the number of all digits was
not divisible by 4. The rst quartet 0111 represents the digit 7 in
hexadecimal (and in decimal). The second quartet 1011 represents 11
in decimal and thus b in hexadecimal. In this method, it is sucient
to have a table for conversion of the 16 hexadecimal digits.
5.4. LAB PROBLEMS 161

5.4 Lab problems

1. Complex numbers
• Find the commands to write and compute with complex numbers,
to perform arithmetic operations with them and to convert between
their arithmetic and trigonometric forms. Draw the numbers in a
chart.

• Create a complex number with modulus 1 and angle 2π /24. Calculate


its powers and draw them on a suitable chart.

• What happens when we change the modulus slightly to 0.9 or 1.1?

2. Approximation of real numbers by fractions


Create a sheet with a single input  an irrational number r.
• Look for the most accurate approximation of this number using a
fraction of the type x/n, where n can be between 1 and 1000, inclu-
sive.

• For each fraction, determine the error of approximation.

• Indicate the rows, where the error has decreased. These correspond
to the new best approximation.

• It is easy to approximate with a fraction with large denominator.


Good estimate will have a small error and the smallest possible de-
nominator.

• Find a better estimate for π than 355/113.

3. Approximation of real numbers by continued fractions


Continued fraction is a fraction of this form:

1
x = a0 + 1
a1 + a2 + 1
a3 + 1
a4 +...

Create a sheet that takes as input an irrational number (square root, cube
root, π, . . .).
• The output will be the coecients which correspond to the continued
fraction.

• Compare these fractions with the best approximations from the pre-
vious problem.
162 CHAPTER 5. NUMBER SETS

4. Conversions between number systems


• Create a simple sheet which converts a binary number to a decimal
number. Use the powers of 2. Include the digits after the deci-
mal/binary point.
• Create a sheet that converts a number from decimal system to bi-
nary. How do we do this for numbers that have also digits after the
decimal/binary point?

• Create a sheet that converts binary numbers to hexadecimal.

5. Numerical errors in Excel


Create a sheet in which you add the same rational number 100 times (1000
times).

• Input may be a decimal number or a fraction.

• Which numbers will not give a precise sum?

• Does the error vary depending on the selected precision?

• Try using partial sums to determine when does the error occur.
5.4. LAB PROBLEMS 163

5.4.1 Hints and solutions


1. Complex numbers
• Find the commands to write and compute with complex numbers,
to perform arithmetic operations with them and to convert between
their arithmetic and trigonometric forms. Draw the numbers in a
chart.

• Create a complex number with modulus 1 and angle 2π /24. Calculate


its powers and draw them on a suitable chart.

• What happens when we change the modulus slightly to 0.9 or 1.1?

Solutions:
• We start by familiarising ourselves with Excel functions that work
with complex numbers. The inputs are the real and imaginary parts
of two complex numbers. We convert them to the algebraic form
(COMPLEX), calculate their modulus (IMAB) and angle in radi-
ans (IMARGUMENT). We can convert the radians to degrees using
the DEGREES function and calculate the (IMREAL) and imaginary
(IMAGINARY) part of the complex number. We can use the func-
tion IMSUM to add complex numbers and IMPRODUCT to multiply
them. We can also display them in the complex plane as shown in
Figure 5.5.

• We start by taking the angle 2π/4 and creating the algebraic form of
the corresponding complex number:

mod. angle Real Imaginary algebraic form


|z | ϕ a = |z| cos(ϕ) b = |z| sin(ϕ) z =COMPLEX(a;b)
1 2π/4 0 1 i

We calculate the powers of i:

power algebraic form Real Imaginary


n z = IMPOWER(i;n) IMREAL(z ) IMAGINARY(z )
1 i 0 1
2 -1 -1 0
3 -i 0 -1
4 1 1 0
164 CHAPTER 5. NUMBER SETS

Figure 5.5: Complex numbers, operations with them and algebraic-to-


trigonometric form conversions.

These are the solutions of the equation z 4 = 1.


If we change the angle to 2π/8 and keep the modulus |z| = 1, we get
solutions of z8 = 1 at the vertices of a regular octagon, see Figure
5.6.
If we change the angle to 2π/24, it means we are solving the corre-
sponding equation z 24 = 1. The solutions represented by vertices of
a regular 24-sided polygon are shown in Figure 5.7 left.

• If we change the modulus of the complex number to |z| = 1.1, its


powers create a spiral shape, see Figure 5.7 right.

No longer a complex number


What happens to the graph if we change the modulus in the rst
problem to a negative number?

2. Approximation of real numbers by fractions


Create a sheet with a single input  an irrational number r.
• Look for the most accurate approximation of this number using a
fraction of the type x/n, where n can be between 1 and 1000, inclu-
sive.
5.4. LAB PROBLEMS 165

Figure 5.6: Solutions of z 8 = 1.

Figure 5.7: Powers of complex numbers for |z| = 1.0 and 1.1.

• For each fraction, determine the error of approximation.

• Indicate the rows, where the error has decreased. These correspond
to the new best approximation.

• It is easy to approximate with a fraction with large denominator.


Good estimate will have a small error and the smallest possible de-
nominator.

• Find a better estimate for π than 355/113.

Solutions:

We can start with an irrational number r= 2 = 1.41421356237309 . . .
We want to nd the best rational approximation of this number using a
166 CHAPTER 5. NUMBER SETS

n
fraction
m . If we take a denominator m = 13, we determine the value of
the numerator as

n √ √ .
= 2 ⇒ n = 13 · 2 = 18.3847 . . . = 18
13

This way we obtained an approximation of 2 using the fraction 18/13 =
1.3849 . . . The approximation is not very accurate as can be seen by cal-

culating the error | 2 − 18/13| = 0.02959 . . .
We can write these steps in an Excel sheet as:

m m·r n n/m error


13 18.3847 18 1.3849 0.02959

The numerator value n n=ROUND(m · r).


is calculated by rounding

Our task is to nd the the best approximation of 2 by n/m with de-
nominators up to m = 50. We need to repeat the steps for m = 1, . . . , 50.
Then we nd the minimum of the approximation error (using the MIN(.;.)
function) and determine the most accurate fraction 12/29:

m m·r n n/m error


29 41.0121 12 1.4137 0.00041

Can we nd a better approximation of r=π than 355/133?

m m·r n n/m error


133 354.999 355 3.14159 0.00008

Since we do not know which denominator results in a better approxima-


tion, we need to create a check that compares the current error with the
minimal error so far and noties us in case there is a decrease, see Figure
5.8.

3. Approximation of real numbers by continued fractions


Continued fraction is a fraction of this form:

1
x = a0 + 1
a1 + a2 + 1
a3 + 1
a4 +...

Create a sheet that takes an input  an irrational number (square root,


cube root, π, . . .).
5.4. LAB PROBLEMS 167

Figure 5.8: Approximation of π using fractions.

• The output will be the coecients which correspond to the continued


fraction.

• Compare these fractions with the best approximations from the pre-
vious problem.

Solution: Here we show the continued fraction for π.


1
π = 3.1415926 . . . = 3 +
1
7+
1
15 +
1
1+
1
292 +
1 + ...

Using the steps shown in Figure 5.9 left, we get:

1. b3.1415 . . .c = 3
2. 3.1415 . . . . − 3 = 0.1415 . . .
3. (0.1415 . . .)−1 = 7.0625 . . .
1. b7.0625 . . . .c = 7
2. 7.0625 . . . − 7 = 0.0625 . . .
168 CHAPTER 5. NUMBER SETS

Figure 5.9: Approximation of π using continued fractions.

3. (0.0625 . . .)−1 = 15.9965 . . .


1. b15.9965 . . .c = 15
etc.

We obtained the sequence h3, 7, 15, 1, 292, 1, . . .i which can be used to ap-
proximate π. Even if we use just the rst two coecients in the continued
fraction, we get an estimate of π that is 10−3 accurate:

. 1 22
π =3+ = = 3.1428 . . .
7 7

If we include the next coecient, the error drops to 10−5 :

. 1 15 333
π =3+ =3+ = = 3.1415094 . . .
1 106 106
7+
15
Using the continued fractions, see Figure 5.9 right, we obtain an accurate
approximation of an irrational number faster than by going over many
fractions as in the previous problem.

4. Conversions between number systems


• Create a simple sheet which converts a binary number to a decimal
number. Use the powers of 2. Include the digits after the deci-
mal/binary point.
5.4. LAB PROBLEMS 169

• Create a sheet that converts a number from decimal system to bi-


nary. How do we do this for numbers that have also digits after the
decimal/binary point?

• Create a sheet that converts binary numbers to hexadecimal.

Hints:
• Excel includes functions for conversions DEC2BIN, BIN2DEC, DEC2HEX,
BIN2HEX, etc. We can use these to verify our calculations.

• The conversion from the decimal system to other number systems is


based on consecutive division of the decimal number by the new base.
The remainders after this division represent the digits in the new
number system, see Figure 5.10 and Figure 5.11 The Excel function
MOD is very helpful in these calculations. We need to read the digits
of the converted number in the correct order.

• The CONCATENATE function may be helpful for joining results


from several cells together.

Figure 5.10: Conversion from decimal to binary system.

• We can also convert non-integer numbers when we use negative pow-


ers of 2 for the digits that come after the decimal point as in Figure
170 CHAPTER 5. NUMBER SETS

Figure 5.11: Conversion from binary system system to decimal.

5.12.
... 24 23 22 21 20 . 2−1 2−2 2−3 . . .
... 16 8 4 2 1 . 0.5 0.25 0.125 . . .

Figure 5.12: Conversion from decimal to binary system for numbers with binary
point.

• Of course, we can also make the conversion of decimal number from


the decimal system to binary, as shown in Figure 5.13.

• To convert a binary number to hexadecimal, we can convert quartets


of binary digits (taken from the right) to decimal, keep the digits 0
to 9 and replace the digits 10 to 15 by the letters, e.g.:
BIN: 1 1 0 0 | 1 0 0 1
23 22 21 20 | 23 22 21 20
DEC: 12 | 9
HEX: c | 9

This is also shown in Figure 5.14.


5.4. LAB PROBLEMS 171

Figure 5.13: Conversion from decimal to binary system for numbers with deci-
mal point.

Figure 5.14: Conversion from binary to hexadecimal.

5. Numerical errors in Excel


Create a sheet in which you add the same rational number 100 times (1000
times).

• Input may be a decimal number or a fraction.

• Which numbers will not give a precise sum?

• Does the error vary depending on the selected precision?

• Try using partial sums to determine when does the error occur.

Hints:
172 CHAPTER 5. NUMBER SETS

• We start by entering the same number 1000 times into the rst col-
umn and adding them. We need to format the cells so that they show
many digits, see Figure 5.15.

• Try adding numbers 0.25, 0.50 or 0.75. Then try adding numbers
0.1, 0.3 or 0.251. Observe the nal sum. Why is there an error in
some cases and no error in other cases?

Figure 5.15: Representation errors in Excel.

Solution: Numbers in computer are represented in binary and what we


see is a kind of rounding error similar to taking 0.33333 in the decimal
system instead of 0.3. While the number 0.1 is not periodic in base 10, it
has an innite binary representation as we saw in the previous problem.
Therefore a computer can only store its approximation. The situation is
dierent for numbers such as 0.25, 0.345 which can be represented exactly.
Chapter 6

Sets and set theory

6.1 Lecture overview

6.1.1 Historical context

The mathematical logic is both a theoretical and a practical building block of


a mathematical foundation describing exact and correct means of expressing,
proving and building mathematical theories. The set theory is another building
block of this foundation and allows us to dene (basically all) objects math-
ematics examines. It also allows us to formulate their properties and prove
them.

th
The set theory arose in the second half of the 19 century as a special tool
for examining innite sets related to the problems of functional series. George
Cantor is the most famous mathematician who looked at the set theory as a
separate research area that should become a universal tool for description of
mathematical objects. After the removal of issues and paradoxes of the early
th
set theory, this goal was reached at the beginning of the 20 century and some
important questions are still being examined today. There have been attempts
at new and dierent foundations of the set theory. In the 80s and 90s, the so-
called alternative set theory arose in Czech Republic and Slovakia. Its author
was Petr Vop¥nka. Currently, the fuzzy set theory is gaining interest.

173
174 CHAPTER 6. SETS AND SET THEORY

6.1.2 Current set theory


As any other theory in modern mathematics, also the set theory has its axioms.
The most well known is the Zermelo-Fraenkel axiomatic system ZFC. Its im-
portant axiom of extensionality says that two sets are equal i they have the
same elements. This axiom carries in itself the essence of the idea of a set : a
set is uniquely determined by its elements and by nothing else. When dening
a set, we thus do not examine these elements, the relations among them, their
order or function. In this sense, the idea of a set is very simple and basic. And
yet, it lets us build the whole mathematics.
Another axiom declares the existence of one non-empty innite set. The
next few axioms guarantee the possibility to create new sets, e.g. by creating
subsets of a set, their intersections, unions, pairs etc. Another axiom lets us
create such subset of the original set that contains an element with a (correctly)
dened property. The correctness protects us from the paradoxes of the early
set theory, such as set of all sets that do not contain themselves. The axiom
of regularity has a similar purpose and prevents situations such as A∈B and
B∈A at the same time.
The nal axiom is the axiom of choice, which guarantees the existence of
a set that contains one element from each non-empty set from a group. This
axiom allows some paradoxes even in the current set theory, such as: split a
sphere into several parts and build two spheres from these parts that are both
identical to the original sphere. Without this axiom though, it would not be
possible to state and prove some important properties in very necessary parts
of mathematics. The search for a suitable replacement for the axiom of choice
is a current open question in the modern set theory.
Using the set theory and its axioms as a practical starting point for all areas
of mathematics would be very cumbersome but some properties of sets are very
useful for common mathematical notation and it is necessary and useful to know
them.

6.1.3 Properties of sets


Using sets we can specify groups of objects that have certain properties. There-
fore we often encounter expressions of the form x∈N or ∀z ∈ R. The set of
elements for which x∈A is not true, is called the complement of a set A and is
denoted by Ā.
The empty set ∅ = {} can also be dened using a special property: x 6= x.
An important relation of two sets is to be a subset. A ⊂ B i all elements of
6.1. LECTURE OVERVIEW 175

A are also elements of B. A B even if they are


is usually considered a subset of
equal. Otherwise we use the symbols A ⊂ B a A ⊆ B.
If we have two (or more) sets A, B, C, . . ., we can perform basic set operations
with them:

• The intersection A ∩ B (A ∩ B ∩ C, . . .) is a set that contains the elements


that are in each of the sets A, B (C, . . .).
• The union A ∪ B (A ∪ B ∪ C, . . .) is a set that contains the elements that
are in at least one of the sets A, B (C, . . .).
• The dierence A − B is a set that contains those elements of A which are
not in B . The symmetric dierence A4B contains those elements from a
union of two sets that are not in their intersection.

• If we consider the set A, which is a subset of another larger set B, we


can consider the complement of B . For A in example, the odd numbers
are a complement of even numbers in Z, the irrational numbers are the
complement of the rational numbers in R.)

• The Cartesian product A × B (A × B × C, . . .) is a set of all ordered pairs


(triplets, . . .) in which the rst element is from the rst set, the second
element is from the second set (the third is from the third, . . .). For
example, the ordered pairs of real numbers create a set of vectors in a
plane or points in a coordinate system.

Another property related to intersection and union is a decomposition of a


set. We decompose the set A into sets A1 , A2 , A3 , . . . (the decomposition may
be nite or innite), if the union of these sets is the whole A and all pairwise
intersections of Ai and Aj are empty. The decomposition of a set is useful
because when examining the set properties, we can examine the individual sets
of the decomposition. That way we can be sure that we do not forget anything
and also if we do the decomposition in a clever way, the elements of some
decomposition sets may have special properties that we can use.

Venn diagrams
A useful depiction of sets and their intersections are Venn diagrams, see Figure
6.1. While easy to draw two or three sets, they get more complicated for larger
numbers of sets, because all possible intersections need to be included.
176 CHAPTER 6. SETS AND SET THEORY

Figure 6.1: Venn diagrams for two and for three sets.

Problem 6.1 Decomposition of a set:


We have seven boys and ve girls on the roster for a volleyball tournament. We
need to pick a team with six members in which we need at least two boys and
at least two girls. How many possible teams can we pick?

Hint: We can examine the cases with two, three and four boys separately.

6.1.4 Number of elements and cardinality


Number of elements
For a nite set M , |M | denotes the number of elements of the set, e.g. if A=
{1, 2, 3, 8}, |A| = 4. If we have a decomposition of A into A1 , A2 , A3 , . . ., we
can easily determine the number of elements of A using this decomposition: it
it sucient to determine how many elements there are in the sets A1 , A2 , . . .
and add these numbers.

Inclusion-exclusion principle
The decomposition of the set and the addition rule help us calculate the number
of elements in a union if the two sets are disjoint. What should we do if the sets
have a non-empty intersection?

• Union of two sets Suppose we have students who like mathematics (set M )
and students who like computer science (set C ). Moreover, each student
in the class likes at least one of these subjects. To determine the number
of students in the class, we cannot use the sum |M | + |C|. If we have
6.1. LECTURE OVERVIEW 177

somebody who likes both subjects, we would count him or her twice. This
is the reason why we have: |M ∪ C| = |M | + |C| − |M ∩ C|.

• Union of three sets If some students also like English and every student
still likes at least one of the three subjects, then we have
|M ∪ C ∪ A| = |M | + |C| + |A| − |M ∩ C| − |M ∩ A| − |C ∩ A| + |M ∩ C ∩ A|.
Check that each type of student is counted only once on the right, e.g. Su-
san who likes computer science and mathematics, but not English, is added
twice: both in C and in M but subtracted in |M ∩ C|. Thomas, who likes
all three subjects is rst added three times, then subtracted three times
and nally added once.

• Number of elements of union of n sets |S1 ∪ S2 ∪ . . . ∪ Sn | =


= sum of number of elements of the individual sets
− number of elements in all pairwise intersections
+ number of elements of all intersections of triplets of sets
− number of elements of all intersections of all groups of four sets
+ etc.

Power set
When considering the number of elements, it is also useful to mention the
power set : P (X) is the set of all subsets of X . If X = {1, 4, 9}, P (X) =
{∅, {1}, {4}, {9}, {1, 4}, {1, 9}, {4, 9}, {1, 4, 9}}. The number of elements in power
|X| 3
set is |P (X)| = 2 , i.e. in our case |P (X)| = 2 = 8.

Cardinality
In general, |M | denotes the cardinality of the set. For nite sets, we saw that
this property corresponds to the number of elements. For innite sets, where
it does not make sense to ask about a number of elements, it lets us determine
how large the sets are. Two (innite) sets A, B have the same cardinality, if we
can nd a mapping which assigns exactly one element of B to each element in
A and covers the whole set B in the process. In other words, we can pair the
elements up or nd a one-to-one mapping. Such mapping is called a bijection.
It is possible to nd a bijection between the natural numbers N and integers
Z. It is also possible to nd a bijection between natural numbers and rational
numbers. However, not all innite sets have the same cardinality. For example,
it is not possible to nd a bijection between N and R. Even the set of real
numbers in the interval (0,1) has a larger cardinality than N. The power sets
178 CHAPTER 6. SETS AND SET THEORY

P (X) are important for creation of larger and larger innite sets. For each set
X it is true that P (X) has larger cardinality than X , i.e. |P (X)| > |X|.
6.2. QUESTIONS 179

6.2 Questions

1. Choose three of these sets which are dierent from one another:
M1 = {a, a, a, b, dog}, M2 = {dog, dog, a, b}, M3 = {1, a, b, dog}, M4 =
{1, a, b}, M5 = {1, 1, 1, a, a, a, b, b, b, dog}

2. Which of these sets are the same:


P1 = even numbers
P2 = multiples of 4
P3 = multiples of 3
P4 = odd numbers
P5 = numbers which give remainder 1 when divided by 5
P6 = numbers of which half is even
P7 = numbers which give remainder 0 when divided by 2
P8 = numbers of which half is odd
P9 = all powers of 2

3. Using a formula with quantiers, write a denition of two sets being equal.

4. Using a formula with quantiers, write a denition of a subset.

5. Relate these sets using subsets: A = the set of all dogs, B = the set of
all poodles, C = the set of all mammals, D = the set of all short-haired
poodles, E = set of all short-haired huskies, F = the set of all long-haired
poodles.

− −
6. Relate these sets using subsets: N, Z+ + + +
0 , R0 , R0 , Q 0 , Q , Q 0 , C.

7. A set with which property do we postulate in the Set theory as an axiom?

8. Dene the odd natural numbers by selecting them from all integers using
a suitable property.

9. Dene the positive numbers using some property and the set of real num-
bers.

10. Dene a circle using an appropriate properties of complex numbers.

11. How is the empty set dened?

12. Using the sets A, B , C , an empty set and Venn diagrams, draw

a) the intersection of A and B


180 CHAPTER 6. SETS AND SET THEORY

b) the union of A, B and C


c) dierence B−A
d) dierence A−B
e) dierence (A − B) − C
f ) (intersection of B and C) union A
13. Let A = {a, b}, B = {1, 2, 3}, C = ∅. Write all elements of the Cartesian
products

a) A×B
b) B×A
c) A×C
d) C ×B

14. Using the sets A = N, B = Z+
0 , C = Q0 , describe the following sets

a) A∪B
b) A∪B∪C
c) B−A
d) A−B
e) (A − B) − C
f) (B ∩ C) ∪ A
15. Write the intersection, union, dierence and symmetric dierence of set
N1 = integers from 10 to 30 and set N2 = integers from 20 to 40.

16. In the room, there are 60 Java programmers and 45 C++ programmers.
15 people can program in both languages. How many programmers are
there in the room?

17. When is it more appropriate to say that two sets have the same cardinality
and when that they have the same number of elements? What is the
connection between the cardinality and the number of elements of a set?

18. Determine whether the following sets have the same cardinality and state
why:

a) N and N0
6.2. QUESTIONS 181

b) N and even numbers from N


c) N and integers greater than 10

19. Determine whether the following sets have the same cardinality and state
why:

a) intervals (0, 1) and (0, 4)


b) intervals (0, 1) and (3, 4)
182 CHAPTER 6. SETS AND SET THEORY

6.3 Problem set

1. Inclusion-exclusion principle
a) There are 40 students in the class. Every one of them speaks at least
one foreign language  English or German. 27 speak English, 7 speak
both. How many students speak German? How many students speak
only German?

b) Some students like to eat fruit. 22 like pears, 25 like apples and 39
like grapes. We also know that 9 like apples and grapes, 17 like pears
and grapes, 20 like apples and pears. 6 students like all three kinds
of fruit and 4 students do not like any fruit. How many students are
there altogether?

c) In the room, there are 57 programmers in Pascal, 48 programmers in


C++ and 72 programmers in Java. 15 of them can program in both
P and J, 7 can program in all three languages, 10 can program in P
and C++ and 13 can program in J and C++. There are no other
people in the room. How many people are there in the room?

2. Operations on sets of quadrilaterals


Let us have the following seven sets:
A: All quadrilaterals
T: Trapezoids (at least one pair of opposite sides is parallel)
P: Parallelograms (both pairs of opposite sides are parallel)
K: Kites, i.e. deltoids (two and two neighboring sides have equal length)
D: Diamonds, i.e. rhombi (all four sides have equal length)
R: Rectangles (four right angles)
S: Squares (equal sides and right angles)
In each of the subtasks, nd all pairs of these sets with the desired property.

a) The rst set is a subset of the second one.

b) The intersection of the two sets is equal to one of them.

c) The intersection of the two sets is equal to one of the remaining ve
sets.

d) The intersection of the two sets is not equal to any of the seven sets.

e) The union of the two sets is equal to one of them.

f ) The union of the two sets is equal to one of the remaining ve sets.

g) The union of the two sets is not equal to any of the seven sets.
6.3. PROBLEM SET 183

h) Examine also the dierences of these sets.

3. Operations on special number sets


Let us denote Cn,k the set of natural numbers that have the digit k at the
nth position from the right. Let us denote Zn,k the set of natural numbers
that give remainder k when divided by n.
a) Express the set Z2,0 using suitable sets Cn,k .
b) Express the set Z5,0 using suitable sets Cn,k .
c) Express the set Z5,1 using suitable sets Cn,k .
d) Express the set Z25,0 using suitable sets Cn,k .
e) Express the set Z50,1 using suitable sets Cn,k .
f ) Express single- and two-digit numbers from Z3,0 using suitable sets
Cn,k .
g) Express two-digit numbers from Z11,0 using suitable sets Cn,k .
h) Express C1,7 using suitable Zn,k .
i) Express C2,0 using suitable Zn,k .
4. Set dierence
We have sets:
A = {x: x is a natural number from 10 to 16}
B = {y : y is an even number between 8 and 20}
C = {7, 9, 11, 14, 18, 20}

a) Find A − B.
b) Find B − C.
c) Find C − A.
d) Find B − A.
5. Operations on sets with abstract elements
We have sets:
K = {a, {a}, b, {c}}
L = {a, b, c}
M = {{a}}
a) Find K ∪ L ∪ M.
b) Find K ∩ L.
184 CHAPTER 6. SETS AND SET THEORY

c) Find K ∩ M.
d) Find K ∩ L ∩ M.
e) Find (K ∪ L) ∩ M .
f ) Find K ∪ (L ∩ M ).
g) Find K − L.
h) Find K − M.
i) Find K × L.
j) Find M × L.
6. Cardinality
Determine if the following pairs of sets have the same cardinality. If so,
prove it by nding an appropriate pairing/bijection.

a) N and numbers from N that give remainder 3 when divided by 7

b) N and odd integers larger than 100

c) N0 and Z
d) N and N×N
e) N and Z×N
f ) Intervals (0, 1) and (2, 4)
g) Intervals (0, 2i and h0, 1)
h) Intervals (0, 2) and h0, 1)
i) Intervals (0, 1) and (3, 6)
j) Intervals (3, 5) and (7, 12)
k) Intervals (−2, 4) and (−11, 3)
l) Intervals (0, 1) and (0, ∞)
m) Intervals (0, 1) and (−∞, ∞)
6.3. PROBLEM SET 185

6.3.1 Hints and solutions


1. Inclusion-exclusion principle
There are 40 students in the class. Every one of them speaks at least
one foreign language  English or German. 27 speak English, 7 speak
both. How many students speak German? How many students speak
only German?

Hints:
• It is helpful to draw the groups of students, e.g. in circles (Venn dia-
gram) and note the number of students in each separate region. This
is still possible with three basic groups, but gets more complicated as
the number of groups grows. In such case, it is more useful to start
with the inclusion-exclusion equation and look at which of its terms
we know and which need to be determined.

• There is a dierence between speaks the language (belongs to the


group, may also belong to other groups) and speaks only the language
(belongs only to this group).

Solution: If 27 students speak English and 7 speak both languages, that


means there are 20 students that speak English only. Consequently, if out
of 40 students 20 speak English, 7 speak both languages and there are no
other students left than those who speak German, we have 13 students
who speak German only. To determine how many students speak German,
we have to consider both German only students and bilingual students.
We get 13+7= 20, as we also see in Figure 6.2.

Figure 6.2: Venn diagram for English and German.


186 CHAPTER 6. SETS AND SET THEORY

Restrictions
Determine what are the restrictions on the number of elements of the
intersections in case with two sets and in case with three sets.

2. Operations on sets of quadrilaterals


Let us have the following seven sets:
A: All quadrilaterals
T: Trapezoids (at least one pair of opposite sides is parallel)
P: Parallelograms (both pairs of opposite sides are parallel)
K: Kites, i.e. deltoids (two and two neighboring sides have equal length)
D: Diamonds, i.e. rhombi (all four sides have equal length)
R: Rectangles (four right angles)
S: Squares (equal sides and right angles)
In each of the subtasks, nd all pairs of these sets with the desired property.

a) The rst set is a subset of the second one.

b) The intersection of the two sets is equal to one of them.

Hints:
• This problem does not deal with numbers but with sets of geometrical
objects. And that is all right, since the elements of a set can be almost
anything. Just note that the denitions of the geometrical objects (in
parentheses) might be slightly dierent than those you are used to.
This is just for the purposes of these specic problems to illustrate
how we work with sets.

• Also, when we talk about intersections (or unions etc.), we mean in-
tersections of the sets containing these elements and not intersections
of the geometric shapes drawn in some plane.

• To determine which sets are subsets of other sets, it helps to consider


which set has more restrictions on its elements. For example, if one
set contains all blue cubes and another set contains all blue cubes
that smell like oranges, the second set is a subset of the rst one.
Every blue cube that smells like oranges is a blue cube, so it also
belongs to the rst set. And this is a denition of a subset. However,
only some blue cubes smell like oranges, some might smell like apples,
some might not smell at all, therefore not all elements of the rst set
are elements of the second set. Consequently, the rst set in not
6.3. PROBLEM SET 187

a subset of the second set. We need to consider the properties of


geometrical objects in this way.

• What is the intersection A∩B in case A ⊂ B?

Solution: The most general of these sets is A, therefore it cannot be a


subset of any of the others. All other sets introduce restrictions on the
quadrilaterals and therefore are subsets of A. If we want to form a chain
of subsets, we need to think about which properties restrict which other
properties. All squares certainly have four right angles, therefore we can
write S ⊂ R. All rectangles have pairs of opposite sides parallel, therefore
we can extend this chain to S ⊂ R ⊂ P. And having both pairs of opposite
sides parallel implies having at least one pair parallel, therefore we next
have S ⊂ R ⊂ P ⊂ T. Note that the denition of T here is dierent
from what you might be used to. We allow some very peculiar-looking
trapezoids. This is purely for the purposes of this problem and for the
discussion of the relations among sets. Finally, since all other sets are
subsets of A, we can write S ⊂ R ⊂ P ⊂ T ⊂ A.

Figure 6.3: Chains of subsets.

We can start the chain dierently. All squares have all sides of equal
length, therefore S⊂D and all rhombi are also parallelograms, therefore
S ⊂ D ⊂ P . Using the same reasoning as above, this chain can be
extended to S ⊂ D ⊂ P ⊂ T ⊂ A. We should now ask, what is the
relationship between the sets R and D , in other words, could the two
chains be combined?

On the one hand, rhombi/diamonds are not required to have right angles,
so R is not a subset of D. On the other hand, rectangles are not required
to have all sides of equal length, so D is not a subset of R. Consequently,
we cannot merge the two chains. There are two alternative paths from
squares to parallelograms.
188 CHAPTER 6. SETS AND SET THEORY

∩ A T P K D R S
A A T P K D R S
T T T P D R S
P P P P D R S
K K K D S
D D D D D D S
R R R R R S
S S S S S S S S

Table 6.1: Intersections of sets written in the header with sets written in the
rst column. Note that the table is symmetric along the diagonal, since A∩B =
B ∩ A.

So far, we considered all sets except deltoids/kites K. Where do they


t? We immediately have D ⊂ K. On the right side, there are not many
options. By relaxing the kite property, we do not get T or P, therefore
the best we can do here is S ⊂ D ⊂ K ⊂ A. Figure 6.3 shows all the
relationships that we found.

After answering the question about subsets, we can move on to considering


intersections. We know that if A ⊂ B , then we automatically have A∩B =
A, since all elements of A are in both sets. And if A ⊂ B ⊂ C , then also
A ⊂ C . Therefore we can recycle the insight from chains we built earlier
and collect all the information in a table such as Table 6.1. In it we also
used the fact that intersection of any set with A is the set itself and that
intersection of any set with S is S. In each case we also make sure that
the intersection is correct with respect to the geometric properties of the
set elements.

After using all the information about subsets, we are left with four empty
spaces. Let us examine them one by one. Only rectangles that have all
sides of equal length are squares, therefore R ∩ D = S. Also, the only way
how a rectangle can also be a kite is if it is square and we have R ∩ K = S.
The diamonds are the only kites that have the pairs of opposite sides
parallel, i.e. K ∩ P = D. And even if we relax the condition of parallel
opposite sides to just one pair, we do not get any new objects, but the
diamonds. This information completes the Table 6.2.

A similar table may be constructed for unions or dierences of sets.


6.3. PROBLEM SET 189

∩ A T P K D R S
A A T P K D R S
T T T P D D R S
P P P P D D R S
K K D D K D S S
D D D D D D S S
R R R R S S R S
S S S S S S S S

Table 6.2: Completed table of intersections of sets written in the header with
sets written in the rst column.

3. Operations on special number sets


Let us denote Cn,k the set of natural numbers that have the digit k at the
nth position from the right. Let us denote Zn,k the set of natural numbers
that give remainder k when divided by n.
a) Express the set Z2,0 using suitable sets Cn,k .
d) Express the set Z25,0 using suitable sets Cn,k .
h) Express C1,7 using suitable Zn,k .
Hints:
• Before starting to express any Z sets using any C sets and vice versa,
it is helpful to write out rst few elements of each. For example
Z3,0 = {3, 6, 9, 12, . . .}, C2,7 = {71, 72, 73, . . . , 171, 172, 173, . . .}.
• Consider if you are looking for a property that some sets share or have
in common, this points towards a union, or for a property that only
some portions of the sets have, which points towards an intersection.

• Consider how would the Z sets look for n ≤ k.


• When solving this problem, it is also helpful to remember the criteria
of divisibility because they are closely related to the digits of numbers.

Solution:
a) Z2,0 = {2, 4, 6, 8, 10, 12, . . .}, since even numbers are those that give
remainder 0 when divided by 2. Note that all even numbers end by
one of the digits {2, 4, 6, 8, 0}. We know that all elements of C1,0 =
190 CHAPTER 6. SETS AND SET THEORY

{10, 20, 30, . . .}, C1,2 = {2, 12, 22, 32, . . .}, C1,4 = {4, 14, 24, 34, . . .},
C1,6 = {6, 16, 26, 36, . . .} and C1,8 = {8, 18, 28, 38, . . .} taken together
also end by one of the digits {2, 4, 6, 8, 0}. Therefore we have
Z2,0 = C1,0 ∪ C1,2 ∪ C1,4 ∪ C1,6 ∪ C1,8 .
d) Z25,0 = {25, 50, 75, 100, 125, 150, . . .}. There will be four types of
numbers in this set: those that end in 25, those that end in 50,
those that end in 75 and those that end in 00. We can express each
of these four groups as a separate set and the answer will then be
their union. To express numbers that end in 25 using the C sets,
we need to consider two digits: we need the last digit to be 5 and
the one before last to be 2. Since we need both of these properties
at the same time, we construct the desired set using an intersection
C1,5 ∩ C2,2 . After doing this for the other three endings, we form the
union Z25,0 = (C1,5 ∩C2,2 )∪(C1,0 ∩C2,5 )∪(C1,5 ∩C2,7 )∪(C1,0 ∩C2,0 ).

h) C1,7 = {7, 17, 27, . . . , 137, . . .}. To dene numbers ending in 7 using
remainders after division hints at the remainder being 7. Then the
question arises: by what number do we need to divide n, in order to
give us remainder 7 in the case when it ends by 7? It can be seen
that it is division by 10 and thus C1,7 = Z10,7 .

4. Set dierence
We have sets:
A = {x: x is a natural number from 10 to 16}
B = {y : y is an even number between 8 and 20}
C = {7, 9, 11, 14, 18, 20}
Find C − A.

Hint: While the set C is explicitly written with all its terms, sets A and
B are dened using a property. Since the property includes short ranges,
it is feasible (and helpful) to write them out explicitly too. Then we can
use the denition of set dierence and determine which elements are in
one set and are not in the other.

Solution: A = {10, 11, 12, 13, 14, 15, 16}. We are then looking for numbers
that are in C but are not in A and we get C − A = {7, 9, 18, 20}.

5. Operations on sets with abstract elements


We have sets:
K = {a, {a}, b, {c}}
6.3. PROBLEM SET 191

L = {a, b, c}
M = {{a}}
e) Find (K ∪ L) ∩ M .
g) Find K − L.
j) Find M × L.

Hint: It seems strange that the set L contains both a and {a}. Are these
two the same thing? No, they are not. It might be helpful to think of sets
as baskets. a is an element. {a} is a basket that contains the element a.
{a, {a}} is a basket that contains two things: an element a and another
basket.

Empty basket
Is any of these an empty basket: {∅}, {}, ∅?

Solution:
e) First, we look at the parentheses and collect all elements of K and
L with each appearing only once (K ∪ L) = {a, {a}, b, {c}, c}. Their
order does not matter. Then we look only for those elements that
appear both in this newly created set and in M to determine the
intersection (K ∪ L) ∩ M = {{a}} = M .
g) To determine the dierence, we look for those elements that are in
K and are not in L. So we get K − L = {{a}, {c}}.
j) The Cartesian product is a set of ordered pairs. The rst element
of the pair is from the rst set and the second element from the
second set. We need to include all combinations. Thus we have
M × L = {[{a}, a], [{a}, b], [{a}, c]}.
6. Cardinality
Determine if the following pairs of sets have the same cardinality. If so,
prove it by nding an appropriate pairing/bijection.

c) N0 and Z
d) N and N×N
f ) Intervals (0, 1) and (2, 4)
h) Intervals (0, 2) and h0, 1)
192 CHAPTER 6. SETS AND SET THEORY

k) Intervals (−2, 4) and (−11, 3)


l) Intervals (0, 1) and (0, ∞)
m) Intervals (0, 1) and (−∞, ∞)

Hints:
• While counterintuitive, there are more kinds of innity, i.e. not all sets
that are innite have the same cardinality. Moreover, with innite
sets it is possible to construct a bijection even between two sets one
of which is a proper subset of the other, e.g. N and N0 . Therefore,
relying purely on intuition, can be counterproductive while solving
these problems. We should rather focus on nding the bijections.

• For the discrete sets such as N, Z or some combinations of them, it is


useful to think in terms of ordering the elements. If we can order the
elements of any set in such a way that they start with one specic
element and for all others it is clear where in the row they stand, we
have a bijection with N by simply pairing them with their index in
this order.

• For intervals, the ordering is not going to work. Instead, we are


looking for functions that can stretch and shift the interval as desired.
Once we have found it, it always makes sense to check the endpoints,
to verify that they are transformed as desired. If the function is
continuous, also the inner part of the rst interval will transform
into the inner part of the second interval.

• Sometimes it might be useful to break the complex transformation


into a sequence of simpler transformations and then compose them
together.

• If an endpoint needs to be included, e.g. as problem h), we can lever-


age a well dened innite sequence, whose rst point gets paired up
with the endpoint, the second point with the rst, etc.

Solution:
c) N0 and Z:
We can order Z in the following way: Z = {0, 1, −1, 2, −2, 3, −3, . . .}.
Now we can dene the bijection in such a way that we pair 0 with
0, even numbers from N0 with positive numbers from Z and odd
6.3. PROBLEM SET 193

numbers from N0 with negative numbers from Z. Written in mathe-


matical language:


0
 n=0
n → n/2 n = 2k, k ∈ N
 −n−1

otherwise
2

Thus the two sets have the same cardinality. This one-to-one map-
ping assigns dierent integers to dierent numbers from N0 , e.g. the
number 34 gets 17, the number 35 gets −18. Moreover, for each in-
teger there is a number in N0 that gets imaged on it, e.g. for 6, we
nd 12 and for −6, we nd 11.

The other way round


Can you nd a one-to-one mapping from Z to N0 ?

d) N and N × N:
We need to order the set N × N. Consider Figure 6.4. It shows
how the ordered pairs can be numbered by traversing the table in
longer and longer diagonals. Surely this way we are going to cover
all elements in the table  eventually. Even though it is dicult to
write a formula such as in the previous case that would explicitly
state which ordered pair is assigned to which n, nevertheless, the two
sets have the same cardinality because we showed that a pairing can
be found.

Figure 6.4: Two possible orderings of the set N × N.


194 CHAPTER 6. SETS AND SET THEORY

Explicit expression for mapping


Can you nd an explicit expression for the one-to-one mapping
between N and N × N?

f ) Intervals (0, 1) and (2, 4):


Here we are looking for a one-to-one mapping (bijection) that stretches
the interval by a factor of two (because the length of (0, 1) is 1 and
the length of (2, 4) is 2) and shifts it by 2 units. x → 2x + 2 seems
to do both. We can verify this by checking the endpoints. Thus the
two intervals have the same cardinality.

h) Intervals (0, 2) and h0, 1):


If these were intervals (0, 2) and (0, 1), the answer would be simply
x/2. However, we have the additional zero at the left endpoint of
the second interval. Let us take the number 1 from the rst interval
and pair it with the zero from the second. That solves the issue with
zero, but creates a new one with 1/2. So let us take 1/2 from the
rst interval and pair it with 1/2 from the second, etc. This results
in a formula for all numbers of the form 1/2k . Everything else can
be scaled down as x/2:

0
 x=1
x→ x x = 1/2k , k ∈ N

x/2 otherwise

This mapping is also shown in Figure 6.5. Note that the sequence
1/2k is not the only one that works. We could have come up with
another one that lies inside the interval. The reason why it works is
that we performed a similar shift as in going from N to N0 , which is
possible due to the open end.
k) Intervals (−2, 4) and (−11, 3):
This is a similar problem to f ) but at the rst glance it is not obvious
what the bijection is. Therefore it is helpful to perform it step-by-
step (−2, 4) → (0, 6) → (0, 1) → (0, 14) → (−11, 3). The successive
operations are +2, :6, ·14 and −11, so the bijection is x → ((x +
2)/6) · 14 − 11 = 73 x − 19
3 . Therefore also these intervals have the
same cardinality.

A dierent method would be to directly look for a linear transforma-


tion y = ax + b. We know that the endpoint −2 is transformed to
6.3. PROBLEM SET 195

Figure 6.5: Bijection from (0, 2) to h0, 1)

−11, therefore we have one equation −11 = −2a + b. Similarly, we


know that the endpoint 4 is transformed to 3 which gives us the sec-
ond equation 3 = 4a + b. This system has a unique solution a = 7/3
and b = −19/3.

l) Intervals(0, 1) and (0, ∞):


Since ∞ is not a number, we cannot stretch the interval here as easily
as before but we can consider other operations, such as 1/x. Using
this, we transform (0, 1) to (1, ∞) which is almost what we want.
The numbers close to 1 in (0, 1) are paired up with numbers close to
1 in (1, ∞). 1/2 is paired up with 2. 1/3 with 3, etc. Numbers close
to 0 are paired up with really large numbers. To nd the bijection
for the two original intervals, we shift this auxiliary result by 1 and
1
get the bijection x→ x − 1. Therefore also (0, 1) and (0, ∞) have
the same cardinality.

m) Intervals (0, 1) and (−∞, ∞):


In the previous problem, we saw that a nite interval can be mapped
to a half-innite 1 1
one. Therefore we can split (0, 1) into (0, ) ∪ { } ∪
2 2
1
( 2 , 1) and (−∞, ∞) into (−∞, 0) ∪ {0} ∪ (0, ∞) and reuse what we
already know.

We start by considering the intervals (0, 12 ) and (−∞, 0). Mapping


x→ − x1 maps (0, 1
2 ) to (−∞, −2). Therefore we need to add a shift.
1 1
Then we map
2 → 0 and consider the intervals ( 2 , 1) and (0, ∞).
1 1
First we shift ( , 1) → (0, ) and then use the same idea as before.
2 2
Combining everything together, we get the following bijection be-
196 CHAPTER 6. SETS AND SET THEORY

tween (0, 1) and (−∞, ∞):


1
− x + 2
 x ∈ (0, 12 )
x→ 0 x = 12
1/(x − 21 ) − 2 x ∈ ( 12 , 1)

Dierent image for 1


2
Can you nd a dierent one-to-one mapping for this problem
1
which maps
2 to some number other than 0?
6.4. LAB PROBLEMS 197

6.4 Lab problems

1. Inclusion and exclusion principle


• Create an Excel worksheet for three, four, (ve) sets that will com-
pute the number of elements in the union of all sets using the number
of elements of individual sets and their intersections.

• Create an Excel worksheet for three, four, (ve) sets that will com-
pute the number of elements in the intersection of all sets using the
number of elements of individual sets, their intersections and the
union of all sets.

• Can the inputs be arbitrary integers? Add necessary checks!

• Combine the rst two tasks into a sheet that will calculate either the
number of elements in the intersection or the number of elements in
the union, depending on the inputs.

2. Number sets
Let us denote Cn,k the set of all natural numbers that have the digit k at
the nth position from the right. Let us denote Zn,k the set of all natural
numbers that give remainder k when divided by n.

• Create an Excel sheet that will have inputs n and k . Using a column
of natural numbers from 1 to 100 (or to 1000) it will then produce
columns containing only the elements of sets Cn,k and Zn,k . Compute
the number of elements in each of these sets. Then solve the following
problems.

• Create the intersections of the following pairs of sets

 Z3,0 and Z7,0


 Z5,0 and Z11,0
 Z8,0 and Z9,0
 Z4,0 and Z12,0
 Z6,0 and Z24,0
 Z5,0 and Z25,0
 Z10,0 and Z14,0
 Z15,0 and Z24,0
 Z12,0 and Z28,0
198 CHAPTER 6. SETS AND SET THEORY

• Investigate the intersections of the type Zn,1 and Zm,1 and in general
Zn,k and Zm,j . When are they empty? How many elements can they
have?

• Express the following sets using the sets Cn,k : Z2,0 , Z2,1 , Z5,0 , Z5,2 ,
Z10,0 , Z10,7 , Z25,0 , Z25,24 , Z100,1 , Z100,33 , . . .
6.4. LAB PROBLEMS 199

6.4.1 Hints and solutions


1. Inclusion and exclusion principle
Hints:
• Before solving the problem for three or more sets, it might be useful
to try it for two sets. What restriction do we have for the number
of elements of the intersection of two sets, if we know the number of
elements of the individual sets?

• When we solve the problem for three sets, consider how many inputs
do we need for the inclusion and exclusion formula. Which of those
need checks?

Solution: For three sets, we need seven inputs, see the yellow cells in Figure
6.6: number of elements of the sets A, B and C , number of elements in
their pairwise intersections A ∩ B , A ∩ C and B ∩ C and the intersection
of all three sets A ∩ B ∩ C. In this case, the output (indicated by green in
Figure 6.6) is the number of elements of the union A ∪ B ∪ C calculated
using the formula |A| + |B| + |C| − |A ∩ B| − |A ∩ C| − |B ∩ C| + |A ∩ B ∩ C|.
Note that if we had |A ∪ B ∪ C| as an input, we could calculate |A ∩ B ∩ C|
using the formula |A ∪ B ∪ C| − |A| − |B| − |C| + |A ∩ B| + |A ∩ C| + |B ∩ C|.

Figure 6.6: Calculation of number of elements in a union of three sets.

The number of elements of any intersection of sets has to be smaller than


the number of elements of either of the two sets. Therefore we should use
checks such as =IF(F4<MIN(B4;C4);"OK";"wrong input") for the pair-
wise intersections. Similarly, for the intersection of three sets, we can write
=IF(J4<MIN(F4;G4;H4);"OK";"wrong input"). To evaluate all checks
together, we can use numerical values instead of OK and wrong input,
with 1 denoting that the inputs are ne and 0 denoting the cases when
they are not. The nal check can then be performed by multiplication
200 CHAPTER 6. SETS AND SET THEORY

IF(F6*G6*H6*J6>0;"OK";"wrong input"). This check relies on the fact


that if one or more of the smaller checks fail, the nal check fails too.

Generalisation
Try making a worksheet in which we can input any seven of the
eight quantities involved in the inclusion-exclusion formula for three
sets. The worksheet then calculates the eighth quantity. Include all
necessary checks.

2. Number sets
Let us denote Cn,k the set of all natural numbers that have the digit k at
the nth position from the right. Let us denote Zn,k the set of all natural
numbers that give remainder k when divided by n.

Hints:
• See also the hints provided in Section 6.3.1.

• We can start by writing out a column of consecutive natural numbers


and then checking for every number whether it belongs to Zn,k for a
given n and k . For this check we can use the remainder after division
that is calculated using the Excel function MOD().

• Constructing the set Cn,k is slightly more complicated and we should


test it for small n rst.

• It is possible to construct the set Cn,k using functions that manip-


ulate strings, e.g. MID() combined with LEN(), or again using the
remainders after division with functions MOD() and QUOTIENT().

• Before constructing the Cn,k , try taking a 5-digit number and write
ve formulas in Excel each of which would extract one of the digits.
What do the formulas have in common?

Solution: To construct the sets Zn,k , we write out natural numbers in one
column (e.g. column K in Figure 6.7) and compare their remainders after
division by n (one of the inputs highlighted in yellow) with the number k
(also highlighted in yellow). We use the formula =IF(MOD(Ki ;n)=k ;Ki ;"")
to display the numbers that meet the condition and hide those which do
not. We can test this by using various inputs n and k.
To construct the sets Cn,k , we rst try to gure out how to extract indi-
vidual digits from a given number. Suppose we have a number 12345 in
6.4. LAB PROBLEMS 201

Figure 6.7: Finding the Zn,k numbers for given n and k.

A1. The formula =MOD(A1;10) gives the last digit 5. To get the 4, we
can rst calculate =MOD(A1;100) to get 45 and then perform a division
=QUOTIENT(MOD(A1;100);10) to get 4. The QUOTIENT function per-
forms division with integers and throws away any remainders. To get the
digit 3, we rst calculate =MOD(A1;1000) to get 345 and then =QUO-
TIENT(MOD(A1;1000);100). This is the same formula as before, with
one zero added at two places to account for the shift in the digit. Now we
n n−1
can write a general formula =QUOTIENT(MOD(A1;10 );10 ), which
is also shown in Figure 6.8.

Figure 6.8: Picking digits from a number.

To nd the intersections of pairs of Z sets, we construct two of them next


to each other, each similar to the one in Figure 6.7, and use a new column
202 CHAPTER 6. SETS AND SET THEORY

to display only those numbers that appear in both green columns. Note
that for union, we would display numbers that appear in either of the two
green columns.
Chapter 7

Relations and functions

7.1 Lecture overview

7.1.1 Relations
Problem 7.1 Pairs I:
What relation may the following set represent?

D = {[3, 6], [3, 9], [9, 18], [1, 2], [5, 10], [, , ], . . .}

Solution: Looking at the pairs, we might notice the rule that the rst number
divides the second. This relation may represent divisibility.

Problem 7.2 Pairs II:


What relation may be dened by the following?

L = {[3, 6], [23, 91], [9, 8], [111, 212], [55, 16], [, , ], . . .}

[7, 64] 6∈ L, [−45, 9] 6∈ L, [435, 19] 6∈ L, ...

Solution: Considering both pairs that belong to L and those that do not, it
seems that this could be a relation of two integers that have the same number
of digits.

Problem 7.3 Triplets:


In a similar fashion as in the previous problems, we can dene more complex

203
204 CHAPTER 7. RELATIONS AND FUNCTIONS

properties. What relation may the following set represent?

S = {[1, 1, 2], [1, 3, 4], [3, 4, 7], [10, 20, 30], [4, 1, 5], [, , ], . . .}

Solution: It is a relation of triplets of natural numbers. One of the possible


answers is that the third is the sum of the rst two.
S = {[a, b, c] ∈ N × N × N, a + b = c}

Relation
Any subset of the Cartesian product A1 × . . . × An is a relation on a set of
ordered n-tuples from A1 × . . . × An . For example, relation K , two lines being
parallel, K ⊂ L × L, where L is the set of all lines in a plane. Another example
is a parents-child relation C ⊂ P × P × P , where P is the set of all people. If
the relation is binary, i.e. involving a Cartesian product of only two sets, we can
use the notation aRb instead of [a, b] ∈ R.

Properties of relations
We call the relation R⊂A×A

1. Reexive i ∀a ∈ A : aRa

2. Transitive i ∀a, b, c ∈ A : (aRb ∧ bRc) ⇒ aRc

3. Symmetric i ∀a, b ∈ A : aRb ⇒ bRa

4. Antisymmetric i ∀a, b ∈ A : (aRb ∧ bRa) ⇒ a = b

5. Trichotomous i ∀a, b ∈ A : a = b ∨ aRb ∨ bRa

Table 7.1 shows several relations and their properties. A relation can also be
displayed as an oriented graph and its properties imply the orientation of graph
edges. Illustration is shown in Figure 7.1.

Symmetric and antisymmetric


The relations is in Table 7.1 are all either symmetric or antisymmetric.
Can you nd a relation that is neither? And can you nd a relation which
is both?
7.1. LECTURE OVERVIEW 205

Figure 7.1: Relation is reexive, if all vertices of its graph have a loop. It is
transitive, if every a→b→c path in its graph implies also a→c path. It is
symmetric if all edges in its graph are bidirectional.

Relation 1 2 3 4 5
≤ on R×R + + − + +
divisibility on N×N + + − + −
same remainder after division by 5 on N×N + + + − −
being parallel on L×L + + + − −
being perpendicular on L×L − − + − −
a is a descendant of b on P × P − + − + −
a lives with b on P × P + + + − −

Table 7.1: Examples of various relations. The + symbol indicates that the
relation has a given property. The − symbol indicates that it does not have it.

Equivalence

A relation R on A×A is called an equivalence i it is reexive, transitive and


symmetric. The equivalence relation splits the set A into classes of equivalence.
Each of those classes contains one maximal set of elements of A that are in
relation R with each other. For example, the relation numbers that give the
same remainder after division by 5 splits N into equivalence classes

{1, 6, 11, 16, . . .}, {2, 7, 12, 17, . . .}, {3, 8, 13, 18, . . .}, {4, 9, 14, 19, . . .}, {0, 5, 10, . . .},

which are called residue classes. The relation lines being parallel splits the set
of lines into classes of parallel lines that are called directions. The relation lives
with splits the people into households.
206 CHAPTER 7. RELATIONS AND FUNCTIONS

Linear ordering
A relation R on A×A is called a linear ordering or total ordering i it is
reexive, transitive, antisymmetric and trichotomous. An example of a linear
ordering is ”≤” on R × R. We draw the real numbers linearly on a line, real
axis, ordered by their magnitude.

Partial ordering
A relation R on A × A is called a partial ordering i it is reexive, transitive and
antisymmetric. An example of a partial ordering is to be a divisor on A × A,
where A = {1, 2, 3, 4, 6, 12} is the set of all divisors of number 12. The graphical
representation in this case is the Hasse diagram, as depicted in Figure 2.1.
Note that in case of linear ordering, we put the small numbers to the left
and the large numbers to the right (on the real axis). With Hasse diagram,
we put the smaller elements below and larger elements up. While these two
conventions are not the same, the basic underlining property is that there is a
clear progression from the small to the large, no matter what the characteristic
direction is.

7.1.2 Mappings and functions


Mapping
A mapping is a binary relation R such that for each a b
we have at most one
such that [a, b] ∈ R. We say that the relation R a onto the
maps the input
output b. Formally, a mapping R : A → B is a relation R ⊂ A × B such that
([a, b] ∈ R ∧ c 6= b) ⇒ [a, c] 6∈ R. Thanks to this property, we can write R(a) = b
or f (a) = b instead of [a, b] ∈ R.
We call the set {a ∈ A : ∃b ∈ B, f (a) = b} a domain and denote it by D(f ).
We call the set {b ∈ B : ∃a ∈ A, f (a) = b} a range and denote it by H(f ).

Function
Sometimes mappings are also called functions. We reserve the term function for
those mappings which work with number sets, such as

n2
f : N → N, f (n) = √
f : N → N, f (n) = n
x2
f : R → R, f (x) = √
f : R → R, f (x) = x
7.1. LECTURE OVERVIEW 207

Injective, surjective and bijective mappings


A mapping f :A→B is injective, also called one-to-one, when
∀a, b ∈ A, a 6= b ⇒ f (a) 6= f (b).

A mapping f :A→B is surjective, also called onto, i


∀b ∈ B ∃a ∈ A, f (a) = b.

A mapping f :A→B which is both injective and surjective is called a bijection.

Cardinality of a set
Now the denition of cardinality of a set in Section 6.1.4 hopefully makes more
sense. We say that two sets, A and B, have the same cardinality and we write
|A| = |B| i there exists a bijection between A and B. For example the set
of even natural numbers E and the set of natural numbers N have the same
cardinality, because there exists a bijection

n
f : E → N, f (n) = .
2

Inverse mapping
For injective mapping f we always have an inverse mapping f −1 . It is a mapping
which determines the input from the output, i.e. if f (a) = b, then f −1 (b) = a.
−1 −1
We also have D(f ) = H(f ) a H(f ) = D(f ). Similarly, we have also inverse
functions.

Composition of mappings
The composition of mappings is an operation which takes two mappings f (x)
and g(x) and producesh(x) = f (g(x)), provided that the range of g(x) is
a subset of the domain of f (x). Consequently, we have also composition of
2
functions, for example, for f (x) = 2x + 3 and g(x) = x we get composite
2 2
functions h(x) = f (g(x)) = 2x + 3 and s(x) = g(f (x)) = (2x + 3) .
We can also perform a composition of a mapping and its inverse and we have
∀x ∈ D(f ) : f −1 (f (x)) = x.
208 CHAPTER 7. RELATIONS AND FUNCTIONS

7.2 Questions

1. State a few dierent ways how we can dene relations. Include examples
of each.

2. Relation denes a certain property for a group of elements. How many


elements can there be in these groups?

3. List a few elements of the relation sum of natural numbers which is dened
using sets. How does it compare to the relation sum of real numbers ?
4. List a few elements of the relation dierence, dened as a suitable subset
of a Cartesian product.

5. List a few elements of the relation divisibility of natural numbers which is


dened using sets.

6. When is a relation called a binary relation? Is the relation dening a sum


of two real numbers a binary relation?

7. Determine if the relations =, <, a divides b, a has a common divisor with


b, dened on N×N are reexive, transitive, symmetric, antisymmetric,
trichotomous (complete)?

8. Find a binary relation (give an example) which is not reexive, one which is
not transitive, one which is not symmetric, one which is not antisymmetric
and one which is not trichotomous.

9. Is the relation of two lines being perpendicular (in plane, in 3D space)


transitive?

10. Is the relation of two lines being not parallel (in plane, in 3D space) tran-
sitive?

11. Is the relation of two lines being parallel (in plane, in 3D space) transitive?

12. What are the properties of an equivalence?

13. What are the properties of a partial ordering?

14. What are the properties of a complete (linear) ordering?

15. State the denition of a mapping. How is it dierent from relation? Also
give an example.
7.2. QUESTIONS 209

16. What is the domain of a mapping?

17. What is the range of a mapping?

18. Dene injective mapping. Give an example. Also give an example of a


mapping that is not injective.

19. Dene surjective mapping. Give an example. Also give an example of a


mapping that is not surjective.

20. Dene bijective mapping. Give an example. Also give an example of a


mapping that is not bijective.

21. What kind of mapping is used to determine whether two sets have the
same cardinality (or number of elements)? What is the relation between
the terms cardinality and number of elements ?
210 CHAPTER 7. RELATIONS AND FUNCTIONS

7.3 Problem set

1. Relations on the set of people


Consider the following relations R on the set of all people in Slovakia and
determine which of the typical properties of relations do they have:

• Reexivity (xRx)

• Transitivity (if xRy and yRz then also xRz )


• Symmetry (if xRy then yRx)
• Antisymmetry (if xRy and yRx then x = y)
• Trichotomy (for distinct x and y we have either xRy or yRx)
If you get an equivalence, describe the equivalence classes. If you get an or-
dering (partial, linear), describe it in human characteristics. Characterise
people who can and people who cannot be in these relations.

a) x is a spouse of y.
b) x is a child of y.
c) x is a descendant of y.
d) x and y have the same rst two digits in their Slovak birth ID number.
e) x has the same rst name as y.
f) x is a sibling of y.
g) x is a sister of y.
2. Relations on numbers
Examine the relations and nd their typical properties:

a) Two integers (numbers in Z) are in relation R2 , if their dierence is


even.

b) Two integers (numbers in Z) are in relation R5 , if the last digit of


their dierence is 0 or 5.

c) Two integers (numbers in Z) are in relation Rk , if their dierence is


a multiple of k.
d) Two integers (numbers in Z) are in relation R1 0, if their dierence is
at most 10.

e) Two natural numbers (from N) are in relation D, if the rst divides


the second.
7.3. PROBLEM SET 211

f ) Two real numbers are in relation C, if their dierence is an integer.

3. Relations in geometry
Examine the relations and nd their typical properties:

a) Two lines are in relation R, if they cross. Solve in 2D case and then
in 3D case.

b) Two lines are in relation R, if their intersection is either an empty


set or one of these two lines. Solve in 2D case and then in 3D case.

c) Two lines are in relation R, if they are perpendicular. Solve in 2D


case and then in 3D case.

d) Two triangles are in relation R, if they have the same set of angles
same angles ).
(

e) Two triangles are in relation R, if their have the same set of side
lengths ( same sides ).
4. Hasse diagram
a) Consider the set {a, b} and all its subsets with the relation to be a
subset. Draw the corresponding Hasse diagram. Do this also for a
set with 3 elements, with 4 elements.

b) Draw the Hasse diagram of the relation x divides y for all divisors of
number 30, 24, 48, 36, 210.

c) Which diagrams from a) and b) are the same?

5. Functions and their properties


Check which of the following are functions R → R. For those that are, nd
their D(f ), H(f ) and typical properties. Which are injective, surjective
and which are bijective? Provide a justication.

a) f (x) = 2x + 1

b) f (x) = x
c) f (x) = x2 + 3x + 1
d) f (x) = 3x
e) f (x) = tan(x)
f) f (x) = sin(x)
212 CHAPTER 7. RELATIONS AND FUNCTIONS

6. Relations vs. functions


These equalities dene relations for real numbers [x, y]. For each case,
write ve pairs that belong to the relation and ve that do not. Find out
which of the relations are also functions R → R. For each case, examine
their typical properties.

a) 2x + 3y = 5
b) −x2 + y = 4
c) 3x − y 2 = 5
d) 3x − y 3 = 5
e) sin(x) − y = 0
f) y − 2x = 1
7.3. PROBLEM SET 213

7.3.1 Hints and solutions


1. Relations on the set of people
Consider the following relations R on the set of all people in Slovakia and
determine which of the typical properties of relations do they have.

Hints:
• When considering mathematical objects and properties in real life
examples, we have to accept that there will be some inaccuracies
and things that need clarication. If necessary, we can specify the
problem more precisely and restrict the properties to e.g. citizens of
particular state, adults only, etc.

• If the relation has a given property, it has to be true for all pairs of
people. If not, it is sucient to nd one counterexample.

• If the relation resembles some kind of equality, it is often reexive,


symmetric and transitive. Similarly, if it does some form of compar-
ison, it often has the properties of linear or partial ordering.

• Sometimes it is easier to imagine certain documents, e.g. birth certi-


cates or records in databases, instead of the people. For example, x
a y are spouses, if there exists a marriage certicate. A birth certi-
cate denes the parent-child relation. We certainly do not mean to
judge any form of family arrangements and preferences, this is done
solely for simplication purposes when working with human relations
as mathematical objects.

• The properties that are stated in the form of an implication hold also
in case if the assumption is not true. Therefore it can (surprisingly)
happen that they sometimes formally hold even if there is no such
case that can happen.

Solution: d) Which basic properties does the relation x and y have the
same rst two digits in their Slovak birth ID number have?
If we restrict ourselves to the current Slovak citizens, every one of them
has a unique birth ID number and we know the meaning of its digits.
The rst two digits correspond to the last two digits of the year when the
person was born. To avoid complications, we add an assumption that we
do not consider people over 100 years old. (Why?) Now we can examine
the individual properties.
214 CHAPTER 7. RELATIONS AND FUNCTIONS

Is this relation reexive? If we had two copies of an ID card of one person,


both would show the same rst two digits of the birth ID number. There-
fore, even though it sounds somewhat peculiar, a person has the same rst
two digits of the birth ID number as he or she has. Thus the relation is
reexive.

To examine transitivity, consider three people: x, y and z. If x and y


share the same rst two digits (in the correct order of course), and also
y and z have the same rst two digits, then x and z have to have the
same rst two digits, too. Here we use the more general property that the
equality of numbers is transitive. If we wanted to prove this property, we
could use the fact that if a = b, then a − b = 0. Therefore

(a − b = 0 ∧ b − c = 0) ⇒ a − c = a − b + b − c = (a − b) + (b − c) = 0.

Similarly, we can show that the relation is symmetric. If x has the same
rst two digits as y, then y has to have the same rst two digits as x. In
other words,

a − b = 0 ⇒ b − a = 0.

Since the relation is reexive, symmetric and transitive, it is an equiva-


lence. It factors the set of people into classes. In each class, we have all
the people who have the same rst two digits of the birth ID number.
With respect to the assumption made at the beginning, these equivalence
classes split the Slovak citizens younger than 100 years into cohorts of
people born in the same calendar year.

Now we check the last two properties. If I check mine and my classmate's
birth certicates and nd out that we have the same rst two digits of
the birth ID number (the relation is symmetric), this does not mean that
we are the same person. Clearly, we are two distinct people and thus the
relation is not antisymmetric.

This is also the underlying reason why the relation is not trichotomous.
Since it is an equivalence, we can also use a dierent reasoning. If it was
true for any pair of people that they have the same the same rst two digits
of the birth ID number (in any order, since the relation is symmetric), then
they would belong to the same equivalence class. Then it would be true
that all people were born in the same year, which is clearly not true. Thus
the original assumption was false and the relation is not trichotomous.
7.3. PROBLEM SET 215

In this case we do not have a linear or partial ordering, since the relation
is not antisymmetric.

c) Which basic properties does the relation x is a descendant of y have?

Again, we need to clarify the problem before we start working on it. Let
us say that a person x is a descendant of a person y when there exists a
direct sequence of relatives of x, p(x), p(p(x)), ..., p(p . . . p(x) . . .) = y ,
where p(a) is a parent of a. If necessary, we can think of this sequence
as a stack of corresponding birth certicates. It is useful to notice that a
parent is older than their child and after repeated application of this rule
we get that a descendant is younger than his or her ancestor.

Consequently, the relation is not reexive. Nobody (and certainly not


everybody) can have a birth certicate on which they are also stated as
their own parent. If the descendancy could be achieved indirectly, by a
longer sequence of successive birth certicates, we would violate the rule
that a parent is older than their child. Since the relation is not reexive,
we can immediately say that it cannot be an equivalence and it cannot be
an ordering either.

It can be easily shown that this relation is transitive. If x is a descendant


ofy then we have a corresponding stack of birth certicates connecting the
child x to the ancestor y . Similarly, we have a stack of birth certicates
connecting the child y to great-great. . .parent z . If we put the rst stack
on top of the second, we get a valid sequence connecting x to z .

The relation is not symmetric. We can see this through the age property.
If x is a descendant of y, he or she is younger than y. Then certainly y
is not younger than x and thus cannot be their descendant. Therefore in
any case (and consequently, certainly not for all cases) we do not have the
implication if x is a descendant of y then y is a descendant of x.
As a reminder, a relation is antisymmetric i ∀x, y ∈ A : (xRy ∧ yRx) ⇒
x = y. At the rst glance, it might seem that the descendancy is not
antisymmetric for the same age-related reason we used before. If x is a
descendant of y , then x is younger than y . Consequently y certainly cannot
be younger than x and therefore is not a descendant of x. When we think
about this more carefully, we have to realise that this property is dened
as an implication. We have shown that the premise of the implication is
never true (we cannot have x as a descendant of y and y a descendant of
x at the same time), therefore we consider the implication to be true even
216 CHAPTER 7. RELATIONS AND FUNCTIONS

if we cannot nd any pair of people that would demonstrate this property.
This relation is antisymmetric. We can come to the same conclusion if we
use an equivalent denition of antisymmetric relation: there are no x and
y such that xRy ∧ yRx ∧ x 6= y.
Finally, we consider the completeness of the relation. If it held for any
two people x and y, it would have to be true that either x is a descendant
of y or y is a descendant of x. This is clearly not true for most people,
consider for example two classmates or two siblings.

Symmetry vs. antisymmetry


Once we know that a relation is not symmetric, can we say that it is
antisymmetric and vice versa?
Can a relation be symmetric and antisymmetric at the same time?
Can it be neither?

2. Relations on numbers and their typical properties


Hints:
• When considering relations on numbers, we work with precisely de-
ned properties and our thinking and answers are more precise than
when talking about human relations. It is very important to carefully
consider the number set on which the relation is dened and make
sure that we fully understand the property or calculation which de-
termines that a pair of numbers is in a relation.

• We can consider the mathematical implications or known properties


of the relation in question. Can the property be simplied or written
dierently?

• Also here, if a property holds, it has to hold for all pairs of numbers.
To show that it does not hold, it is sucient to nd one counterex-
ample.

• For each relation, try to nd specic pairs of numbers which belong to
it and pairs which do not. Do these pairs of numbers have something
in common?

• Use the specic pairs of numbers to test the properties of relations.


Does the pair (1, 1) have the property? If the pair (1, 2) has the
property, does also the pair (2, 1) have it? What pairs need to be
checked for the other properties?
7.3. PROBLEM SET 217

• We can consider the properties of basic relations on numbers, such as


= , < or ≤, as given. If we wanted to prove these in detail, we would
use the fact that the relation a=b can be replaced by a−b = 0 and
a<b by a + x = b, where x is a positive (real) number.

Solution: b) Which basic properties does the relation R5 have?

When considering this relation, we are going to use the properties of divis-
ibility as discussed in Chapter 2, but we need to extend them to negative
numbers as well.

First we note that when we subtract a number from itself, we get zero.
Thus the relation is reexive and for any integer k we have kR5 k , since
k − k = 0.
Now we consider various pairs of numbers. If one of the two numbers is
a zero, we see that it is in this relation with numbers 5, 10, 15, . . . and
also −5, −10, −15, . . . When we start subtracting these numbers from one
another, we see that their dierences also end in 0 or 5. Thus here we
have a group of numbers in which all pairs are in relation R5 . This group
contains all (integer) multiples of 5.

We can construct a similar group in which there are numbers that give a
remainder 1 after division by 5. In other words, these are multiples of 5
plus 1.

Remainders after division for negative numbers


Think about how the remainders work for negative numbers. How
are they evaluated in various programming languages and software
tools?

Next we take numbers −14, −9, −4, 1, 6, 11, 16, . . . Also here we can easily
verify that their dierences end in either 0 or 5 and thus they form another
group of numbers bound by the relation R5 .
If we read the denition of the relation carefully, we might realise one
well-known property. We know that a number is a multiple of 5 i it
ends in 0 or 5. Thus, all numbers whose dierence is divisible by 5 are in
relation R5 , i.e. kR5 l ⇒ k − l = 5p for a suitable integer p. In Chapter 2
we also saw that if the dierence of two numbers is a multiple of 5, they
are congruent modulo 5, i.e. give the same remainder after division by 5.
This conrms the groups of numbers that we constructed previously. With
these properties in mind, we are ready to check the remaining properties.
218 CHAPTER 7. RELATIONS AND FUNCTIONS

To check for transitivity, we start by assuming kR5 l and lR5 m. This


implies k − l = 5p and l − m = 5q for suitable p, q . Then we have
k − m = k − l + l − m = (k − l) + (l − m) = 5p + 5q = 5(p + q). This means
that also the dierence k − m is a multiple of 5, therefore kR5 m. Hence,
the relation is transitive.

To examine symmetry, it is sucient to realise that if k − l = 5p is a


multiple of 5, also l − k = −5p is a multiple of 5. The relation is thus
symmetric.

Since R5 is reexive, symmetric and transitive, it is an equivalence. We


have already discovered its equivalence classes. They are the congruence
(residue) classes modulo 5.

The last two properties do not hold for this relation. For example, both
dierences 7−2 and 2−7 end in 5 but 2 6= 7. Therefore R5 is not
antisymmetric.

And since for example neither of the dierences 2 − 1 and 1 − 2 is divisible


by 5, the relation is not trichotomous.

e) Which basic properties does the relation D have?

In this case, we need to examine the relation of divisibility on natural


numbers. We have nDm (or using a standard notation n|m) i m is a
multiple of n. Therefore m = np for a suitable natural number p.
If we choose p to be 1, we have n = n · 1 for any natural number n. There-
fore, every number is divisible by itself (the ratio is 1) and the relation D
is reexive.

In order to consider transitivity, we start from the assumptions that lDm


and mDn. Then we have m = pl and n = qm. Consequently, n = qm =
qpl, therefore n is a multiple of l and we have lDn. The relation D is
transitive.

The relation D is not symmetric. While it is true that 2|4, certainly it is


not true that 4|2 (2 is not an integer multiple of 4). We could nd many
more counterexamples like this one, but one is sucient to disprove this
property.

Conversely, the antisymmetry looks promising. IfmDn and nDm, then


m = pn and also n = qm for suitable p and q . From there we get m =
pn = pqm. In natural numbers this is only possible if pq = 1 and thus
p = q = 1. This means that n = m and that the divisibility relation is
antisymmetric.
7.3. PROBLEM SET 219

The relation D is not trichotomous. For any two prime numbers, e.g. 5
and 7, we neither have 5D7 nor 7D5.
Considering the previously discussed properties together, we nd out that
D is a partial (not linear) ordering. In certain sense, it can arrange natural
numbers in an order, even though this order does not place them on a line
(like ≤ does). For more information, see also the solution to Problem 4 in
this section.

3. Relations in geometry
Examine the relations and nd their typical properties:

a) Two lines are in relation R, if they cross. Solve in 2D case and then
in 3D case.

b) Two lines are in relation R, if their intersection is either an empty


set or one of these two lines. Solve in 2D case and then in 3D case.

c) Two lines are in relation R, if they are perpendicular. Solve in 2D


case and then in 3D case.

d) Two triangles are in relation R, if they have the same set of angles
same angles ).
(

e) Two triangles are in relation R, if their have the same set of side
lengths ( same sides ).
Hints:
• We should start by looking for pairs of objects that have or do not
have the given geometrical property.

• The geometric properties of pairs of objects are static and often can
be drawn in a picture. Therefore we can expect that in general they
are going to be symmetric, independent of the order in which we
state the relation for them.

• In problem a), the intersection means that the lines have exactly one
point in common. Therefore identical lines, parallel lines or skew lines
in 3D are not in this relation. In general, the properties of relations of
two lines in 2D and 3D are dierent, but for this particular relation,
we get the same, albeit modest, set of properties in both spaces.

• Problem b) examines the complementary property. This relation puts


together lines that are either parallel or identical. This suggests that
we are dealing with equality of something, and thus an equivalence.
220 CHAPTER 7. RELATIONS AND FUNCTIONS

Note that in 3D, we also have skew lines which are not the same as
parallel lines. Two lines in 3D space are parallel, if there exists a
plane in which they are parallel. While skew lines are not parallel,
they also do not have an intersection. Consequently, the answer to
this question is going to be dierent in 2D and in 3D.

• Being perpendicular is a special case of the relation described in a).


The properties of this relation should thus be weaker. Unlike in 3D
space, in plane there is a strong connection between being perpen-
dicular and being parallel.

• For problem d) we should recall that triangles with the same angles
are similar. The same size of angles hints at equivalence.

• In problem e) we have the same length of sides, which points towards


equivalence even more strongly than the previous case. We should
remember the sss comparison criterion.

Solution: Here we provide the answers which you can compare to the
results of your own work.

a) In a plane, this relation is only symmetric. It is not reexive, transi-


tive, antisymmetric nor trichotomous. Consequently, it is neither an
equivalence nor any kind of ordering. Its properties in 3D space are
the same.

b) In a plane, this relation corresponds to two lines being parallel (or


identical). It is reexive, symmetric and transitive, therefore it is
also an equivalence. Its equivalence classes are groups of parallel (or
identical) lines, which are sometimes called directions. The relation
is neither antisymmetric nor trichotomous.

For lines in 3D, the situation is dierent. The reason is that we


can also have skew lines. For those, the relation is not transitive.
Therefore in 3D, it is only reexive and symmetric.

c) Two perpendicular lines are a special case of relation in a). In both


2D and 3D, this relation is only symmetric. In plane, we know that
if p⊥r and r ⊥ s, then p k s. Being perpendicular in 3D space is a
slightly more complicated property.

d) Similarity of triangles is an equivalence (thus a reexive, symmetric


and transitive relation) and its equivalence classes are the groups of
similar triangles. The relation is neither symmetric nor trichotomous.
7.3. PROBLEM SET 221

e) In this case, we have congruence of triangles. The properties of the


relation (except the equivalence classes) are the same as in case of
the similarity of triangles.

4. Hasse diagram
Hints: Hasse diagram is a useful depiction of elements of a set that are
in partial ordering. (In case of linear ordering, the elements of the set
can be drawn on a line, where we draw the smaller elements to the left of
the larger elements. The properties of linear ordering guarantee that is it
always possible.) There are few simple rules for drawing a Hasse diagram
of a relation R:
• Before drawing the diagram, we write out all the elements that belong
to this relation. If xRy , the vertex representing x is drawn below the
vertex representing y . We draw the small elements in the lower part
of the diagram, the large elements in the upper part of the diagram
and the rest in the middle.
• If xRy , there is a connection between the vertex x with the vertex y.
This connection might, but does not have to correspond to an edge
connecting these two vertices.

• The diagram respects transitivity. Therefore, there are no redundant


edges. If xRy and yRz , we do not draw an xz edge. The edges xy
and yz are sucient for capturing the fact that x is also in relation
with z . More precisely, we only draw the edge xy that denotes the
xRy relation, if it cannot be replaced by a pair of edges xz and zy ,
i.e. relations xRz and zRy . If we have inadvertently already placed
such an edge in the diagram, we should later erase it and replace it
with the relevant pair of edges that go through the element z.

Solution:
a) Consider all subsets of the set {a, b, c}. We know that the subset
denes a partial ordering, it should thus be possible to draw the
Hasse diagram.

There are eight subsets of the set {a, b, c}: ∅, {a}, {b}, {c}, {a, b},
{a, c}, {b, c}, {a, b, c}. Thesmallest one is the ∅, which we draw at the
bottom of the diagram. Immediately larger, without any middlemen
are one-element subsets {a}, {b}, {c}. The edges connecting them
to the ∅ cannot be replaced by any other pairs. The next layer
222 CHAPTER 7. RELATIONS AND FUNCTIONS

Figure 7.2: Hasse diagram for subsets of the set {a, b, c}.

comprises the two-element sets {a, b}, {a, c}, {b, c} and the top layer
is the self-subset {a, b, c}.
Try drawing your own diagram and comparing it with Figure 7.2. If
there are dierences, nd out which edges are redundant and which
are missing. If this gure reminds you of another picture, it is not a
coincidence.

b) To draw the diagram of relation x|y for x and y from the set of divisors
of the number 30, we start by a prime factorisation 30 = 2 · 3 · 5.
From Section 2.1 we know that the divisors of the number 30 are
1, 2, 3, 5, 6, 10, 15 and 30. In terms of divisibility, the smallest of these
is the number 1 and the largest is the number 30. The rest of the
divisors can be split into a group of primes 2, 3, 5 and their pairwise
products 6, 10, 15. These two groups correspond to the layers and
vertices of the relation D in the Hasse diagram.

At this point, draw your own diagram, compare it with Figure 7.3
and explain any dierences that might appear.

Now compare the two diagrams in this problem. Up to the vertex


notation, we see the same picture. This demonstrates one of the ad-
vantages of using the Hasse diagram. Partial orderings from various
mathematical topics in fact have the same structure. Many prop-
erties obtained by examining subsets apply to divisibility and vice
versa.
7.3. PROBLEM SET 223

Figure 7.3: Hasse diagram for divisors of the number 30.

5. Functions and their properties


Hints:
• In case of mappings, the typical properties of relations (reexivity,
transitivity, etc.) are not so important. The only reexive mapping
on R×R is the function f (x) = x. While it is unique because it is
the only one, it is neither very useful nor interesting.

• Much more important is for example the ability of mappings to


uniquely map inputs to outputs and therefore in the case of map-
pings, we typically investigate whether they are injective, surjective
and bijective.

• We can recognise and observe the properties of mappings from real


numbers to real numbers from their graphs in Cartesian coordinate
system. We return to this topic again in Chapters 10 and 11 but
already now we should start thinking about where in the graph do
we see D(f ) and H(f ) and how does the fact that f is injective,
surjective, bijective manifest in the graph.

• To distinguish a mapping from a relation, we need to carefully con-


sider whether we get a unique output f (x) for every (reasonable)
input x. In order to do that, we should focus on the formula of f (x).
Can it give the same answer for dierent values of x? Certainly x2
has the same value as (−x)2 , |x| is the same as | − x|, etc. Therefore
224 CHAPTER 7. RELATIONS AND FUNCTIONS

we should suspect formulas that contain even powers of x, absolute


values, etc.

• Similarly, we investigate the formulas of f (x) when we want to de-


termine the domain and the range of f . If we do not articially
restrict the range of arguments x (e.g. possible range of income for
calculation of income tax or non-destructive acceleration values for
calculation of rocket fuel consumption, etc.) it is important to nd
which values of x cannot enter the formula. These are the values for
which the expression is not dened. The suspicious places are denom-
inators (they cannot be zero), even roots (for which x?), logarithms
and exponential functions (why?), undened values of tangent and
cotangent (what are they?), etc.

• Determining D(f ) and H(f ), although in a slightly dierent sense, is


also important in computer science and in writing source codes. The
domain is very often related to the declaration of data types and ad-
missible inputs for algorithms and the range to values used for saving
and output. If we do not dene them correctly, we might end up with
inappropriate data types, which may lead to surprising outcomes for
the results of calculations, e.g. the number −1 cannot be stored in an
unsigned int variable and an attempt to do so will instead produce
an unexpectedly large positive number. It is a serious problem when
a program formally performs a calculation and returns a value even
in case when the solution does not make sense, e.g. Heron's formula
returns some value of triangle area even if the inputs are negative
lengths of sides. Another problem is incorrect estimate of possible
range of outputs, which might lead to overow of used variables or
display of absurd reports.

Solution:
a) To nd the domain of f (x) = 2x + 1 we need to think about which
real values of the input (argument) x would make it impossible to
calculate the output value 2x + 1. We can perform doubling and
adding 1 for all real numbers, therefore D(f ) = R.

We get the same answer for the range H(f ) = R but the reasoning
is slightly more complicated here. How do nd out whether all real
numbers can be the outputs of calculation 2x + 1 for some x? We
can try a few cases. Can the answer be 123? If we decrement it by
1, we get 122 and the half of that is 61. Therefore we know that
7.3. PROBLEM SET 225

f (61) is 123. We can repeat these steps for dierent values of x or


generalise it instead. Simple transformation of the original function
gives us x = (y − 1)/2. Since this calculation can also be performed
without problems, we see that for every real y we can nd an x. This
also gives us the answer to the question whether f (x) is surjective.

For a function to be injective, it has to meet another, in this partic-


ular case a very intuitive, criterion: when we substitute two dierent
values of x into 2x + 1, we need to get two dierent answers. The
simplicity of the formula suggests that this could be true. We prove
it by assuming that for two real numbers u and v we get the same
output values 2u+1 = 2v +1. If we subtract 1 from this equation and
divide by 2, we get u = v . Since this results in two equal numbers,
they had to be equal already at the time of input. This is the same
as saying (see Chapter 4) that we get dierent outputs for dierent
inputs. The function is thus injective.

Since f is both injective and surjective, it means it is also a bijection.

The steps and analysis are very similar for other functions, therefore
we only show brief results here:

b) For function f (x) = x we have D(f ) = H(f ) = R+
0. This means it
is not surjective and consequently not bijective either. It is injective
though, because square roots of distinct non-negative real numbers
are distinct non-negative numbers. With respect to this problem and
working with square roots in general, it is useful to remember that

there is a dierence between the solution of the equation x= 9 and
the solution of the equation x2 = 9.
c) The function f (x) = x2 + 3x + 1 has D(f ) = R and H(f ) =
h−5/4, ∞). The point [−3/2, −5/4] is a vertex of the parabola rep-
resenting this mapping. H(f ) 6= R, therefore this function can-
not be surjective and consequently cannot be bijective. Like all
other quadratic functions, it is also not injective, since for exam-
ple f (−2) = f (−1). The reason for this is the symmetric shape of
the parabola, which is the graph of this function.

d) The function f (x) = 3x is exponential and we return to it in Chapter


11. At this point it is sucient to draw it in a suitable software and
deduce the properties from the graph. We should see D(f ) = R and
H(f ) = R+ . The function is injective (why?). It is not surjective
(H(f ) 6= R) and therefore it is not bijective.
226 CHAPTER 7. RELATIONS AND FUNCTIONS

e) We will also return to the function f (x) = tan(x) later, but now
we can analyse its properties from its graph or from its denition
sin(x)
tan(x) = cos(x) . Since the expression is a fraction, this implies a
restriction on the domain, because we cannot calculate the values of
tan(x) for zero points of cos(x) in the denominator. D(f ) is therefore
the set of real numbers except the odd multiples of π/2, i.e. D(f ) =
R − {(2k + 1)π/2; k ∈ Z}. The range is the whole R, because close to
the asymptotes in undened points the graph of the function tan(x)
escapes towards innity. The function is periodic which implies that
it is not injective (why?) and therefore it is not bijective.

f ) For f (x) = sin(x) we have D(f ) = R, H(f ) = h−1, 1i, the function
is neither surjective not injective (for each multiple of π we get the
same value sin(x) = 0), therefore it is not a bijection either.

6. Relations vs. functions


Hints:
• In the rst step we want to distinguish mappings from general rela-
tions that are not mappings. This is done using the criterion whether
for each value of the input variable, here denoted by x, exists only one
or more output values, here denoted by y. To make this distinction,
we rst transform the expression into the form y = f ormula(x). If
there is only one such y, we have a mapping, if there are more, we
have a general relation.

• Once we distinguish the general relations and mappings, we can de-


cide which properties we are going to examine. For relations that are
not mappings, we investigate whether they are reexive, symmetric,
etc. For mapping we focus on whether they are injective, surjective
and bijective.

• Similarly to the previous problems, it is useful to rst look at ex-


amples and counterexamples of specic pairs of real numbers that
satisfy or do not satisfy the given formula.

Solution:
a) 2x + 3y = 5
In this case we have a mapping. For example for x=3 there exists
a unique y = −1/3, which satises the equality. One example is not
sucient to claim that we have a mapping, but after expressing y as
7.3. PROBLEM SET 227

y = (5 − 2x)/3 we get a one-to-one formula for calculation of output


y for any input x. We can either draw the graph or manipulate the
expression into x = (5−3y)/2 to realise that the mapping is injective,
surjective and bijective. D(f ) = H(f ) = R.

b) −x2 + y = 4
Here we could again start with testing a few [x, y] pairs. Then ma-
nipulate the equation into y = 4 + x2 and realise that for every x
we get one output value y. Therefore we again have a mapping, its
D(f ) = R, but H(f ) is only h4, ∞). This means the mapping is not
surjective. Neither it is injective since the pairs +1 and −1, +2 and
−2 (and x and −x in general) result in the same value of y.
c) 3x − y 2 = 5
In this case we have y 2 = 3x−5.
x = 7 this means y 2 = 3·7−5 =
For
16. There are two values that satisfy this: y = 4 and y = −4.
Therefore this relation contains both [7, 4] and [7, −4] and thus it is
not a mapping. It does not have any of the typical properties of the
relations, which can be veried by nding specic counterexamples
in each case.

d) 3x − y 3 = 5
Compared to the previous problem, we are looking at a dierent root
now. The cube function does not have any issues with the sign and
distinguishes between positive and negative numbers. It is injective
and its inverse  a cube root  is dened on the whole set R. After

3
few steps we get y= 3x − 5 which gives a unique output y for every
input x. Therefore this is a mapping with D(f ) = H(f ) = R. It is
both surjective and injective (and therefore also bijective) as can also
be seen from the graph.

e) sin(x) − y = 0
We can easily change the expression into y = sin(x). Therefore we
now analyse the properties of the mapping sin(x). We know that it is
well dened on the whole R. However, the range is only the interval
h−1, 1i, therefore the mapping is not surjective and consequently it
is not bijective. Moreover, it is not even injective, since it is periodic
and for example all integer multiples of π give the same output value
∀k ∈ Z : sin(kπ) = 0.
f) y − 2x = 1
In this case we are working with an exponential function y = 2x + 1.
228 CHAPTER 7. RELATIONS AND FUNCTIONS

We return to it in more detail in Chapter 11. Here we just state that


D(f ) = R. H(f ) = (1, ∞). Look at the graph to determine that the
function is injective, but not surjective (and therefore not bijective).
7.4. LAB PROBLEMS 229

7.4 Lab problems

1. Innite hotel
Suppose we have an innite hotel and the rooms are numbered 1, 2, 3, 4, . . .
All the rooms are single-occupancy and if there is a guest staying in the
room, he or she remembers the room number. At the beginning, innitely
many of the rooms are occupied, but some may still be free.

At the reception, there are new guests waiting to check-in. Sometimes


they come from a next-door innite hotel and they remember the room
number they had there. The task is to accommodate everyone in such a
way that both the existing and the new guests have rooms and there are
no rooms left empty.

Give the guests who already stay in the hotel an instruction (a suitable
function) they can use to calculate their new room number (they will then
move into this room). Also give an instruction (a suitable function) to the
people waiting at the front desk to calculate the new room number from
their old room number.

Create an Excel sheet in which one column corresponds to the innite


hotel and another column to a line at the front desk. In the next column,
apply the functions that tell them where to move. Finally, check and show
that in every room there is exactly one guest.

Consider these situations:

current guests new guests


1, 2, 3, 4, 5, . . . 1, 2, 3, . . . , 9, 10
1, 2, 3, 4, 5, . . . 1, 2, 3, . . . , 999, 1000
11, 12, 13, 14, 15, . . . 201, 202, 203, . . . , 299, 300
1, 2, 3, 4, 5, . . . 1, 2, 3, 4, 5, . . .
10, 11, 12, 13, 14, 15, . . . 100, 101, 102, 103, 104, 105, . . .
2, 4, 6, 8, 10, . . . 11, 13, 15, 17, 19, . . .
10, 20, 30, 40, 50, . . . 3, 6, 9, 12, 15, . . .
1, 101, 201, 301, 401, . . . −2, −4, −6, −8, −10, . . .

How did you take into account the fact that the hotel is innite? How is
the innite hotel dierent from a nite one?

2. Bijection between intervals


Even though it seems counterintuitive, any two nite intervals have the
230 CHAPTER 7. RELATIONS AND FUNCTIONS

same cardinality  there is a bijection between them. If we think of them


as segments on a number axis, the segments have the same amount of
points.
Create a sheet that will demonstrate this. The input are the endpoints of
two closed intervals.

Using suitable formulas and the input values (over multiple steps, if needed)
transform the points of one interval to the points of the second interval.
The intervals should be tabulated uniformly using 10 (or 20) steps. Find
an appropriate method (graph) for displaying the gradual transformations
of the interval.

3. Mappings vs. relations


• For an independent variable x from −10 to 10 calculate the corre-
sponding values y using a relation y = ax2 + b, where a, b are param-
eters. Draw the graph of this relation in a plane. Is it a function of
variable x? Is it a function for all admissible values of parameters
a, b?
• Solve the same problem for switched values of x and y: For y from
−10 10 calculate the corresponding values x with respect to rela-
to
2
tion x = ay + b, where a, b are parameters. Draw the graph of this
relation in a plane. Is it a function of variable x? Is it a function for
all admissible values of parameters a, b?

• Compare the pairs [x, y], the two relations and their graphs for the
same values of parameters a, b.
7.4. LAB PROBLEMS 231

7.4.1 Hints and solutions


1. Innite hotel
Hints:
• Of course, we are not going to model an innite hotel. It is sucient
to restrict ourselves to the rst few, e.g. 100, rooms. However, we
should carefully consider, whether the solution checked using this
range also works if we extended the hotel to innity.

• It is useful to designate separate columns to contain:

 the list of room numbers 1, 2, 3, . . . This is the basic control col-


umn that guides the other columns in the worksheet.

 only the occupied room numbers.

 the room numbers of the new guests waiting at the front desk.
This list is going to be more complex than 1, 2, 3 . . . In all specic
situations, it is sucient to input the rst few values and then
ll them down either by dragging or by double-clicking the lower
right corner of highlighted cell(s).

• For output, it might be helpful to have columns that contain:

 new rooms for the current guests. The room numbers in this
column should be obtained using a formula into which a guest
inputs their current room number.

 new rooms for waiting guests who obtain their new rooms num-
bers by plugging their old room number into a second suitable
formula.

• The goal is to occupy each room by exactly one guest. How can we
check that we have achieved this using the two formulas mentioned
previously? What numbers do we expect in the two output columns?

• We can create a few verication columns. For clarity and easier


debugging, we recommend to perform the verication separately for
the current guests and for the new guests.

 The verication columns should correspond to the control col-


umn.

 For each hotel room, we can count how many original guests
and how many new guests have moved into it. The function
COUNTIF is a good choice for this task if we use the room
numbers as parameters.
232 CHAPTER 7. RELATIONS AND FUNCTIONS

 The nal check is done by combining the two previous results.


Then we can visually highlight empty rooms, correctly occupied
rooms and overcrowded rooms.

Solution: We describe the solution shown in Figure 7.4. The column A


contains the list of all (although in fact only just the rst 100) hotel rooms.

Figure 7.4: Innite hotel and new guests at the front desk.

Columns B and C contain the particular situation described in the prob-


lem. In this case, the current guests occupy the rooms starting with
number 10 and new guests come from another innite hotel where they
stayed in all the rooms with even numbers.

First we move the current guests to room numbers that are double their
original room numbers. The formula in column D calculates these values
only for the occupied rooms. The current guests thus move to rooms with
even numbers starting with 20.

The new guests waiting at the front desk with their old numbers 2k then
get keys to rooms 2k − 1. Once they check in, all odd room numbers are
occupied and we see the result in column E.

We notice that the formulas were not completely correct. There are some
empty rooms left: the rooms with even numbers smaller than 20. We need
a check that can detect this kind of situation.
7.4. LAB PROBLEMS 233

Using the formula =COUNTIF(D:D,A3) in column F, we calculate the


number of current guests staying in the room number 1, etc. Similarly,
using the formula =COUNTIF(E:E,A3) in column G we calculate the
number of newly checked-in guests in room number 1, etc.

The column H adds the values in F and G and thus determines the number
of people now staying in the rooms with numbers 1, 2, 3, . . . There should
be exactly one guest in each of them. If that is the case, the column I
displays the value OK. If not, it shows the value Wrong.
In our problem, we see that the Excel sheet detected the empty rooms
with numbers 2, 4, 8, . . . , 18. If we want to correct this mistake, the current
guests should use the formula 2k − 18 = 2(k − 9) instead of 2k .
This Excel sheet can check your solution for all situations given in this
problem once you input the formulas in the columns D and E. In all cases
it is possible to nd a solution that moves the current guests to suitable
even numbers and new guests in suitable odd numbers.

2. Bijection between intervals


Hints:

• We can start by tabulating the rst (input) interval into a column


in the worksheet. In order to do that, we need to use the interval
endpoints and decide on the number of tabulated values. Once we
have that, we can calculate and use a step to get from one tabulated
value to the next.

• The neighboring columns should represent the consecutive solution


steps, each performing a certain transformation of the interval, e.g. shift
right, scale down, etc. Once we apply the whole sequence of steps,
we can compare the resulting interval (in terms of its endpoints) with
the expected answer (the endpoints of the second interval).

• The key to solving this problem lies in a correct choice of the transfor-
mation functions that map the numbers from one interval to another.
We recommend working in simple, clear steps. Suppose we want to
map the input interval h2, 5i to output interval h8, 12i. Our steps
could be as follows: h2, 5i → h0, 3i → h0, 1i → h0, 4i → h8, 12i. We
rst shift the interval three units to the left, then scale it down three
times, scale it up four times and shift it eight units to the right.
234 CHAPTER 7. RELATIONS AND FUNCTIONS

• The parameters of the changes are determined by the endpoints of


the intervals and their dierences. We need to calculate them in
general from the endpoints of the two intervals. In any case, we go
through the universal middle interval h0, 1i.
• Of course, it is possible to combine the steps into one single formula.
Such approach might not be as clear as performing the transformation
in successive steps, is more error-prone and more dicult to debug.
Moreover, when using the composite formula, we cannot display and
observe the individual transformation steps. Still, computationally,
it is more ecient.

• In order to display the sequence of intervals in a chart, we need to add


a second coordinate to the tabulated values. The second coordinate
can be a dierent constant for each interval, which then determines
the position of the interval in an x-y chart.

Solution:
In Figure 7.5, we show one possible solution.

Figure 7.5: Bijective transformation of one interval into another.

The values representing the bounds of the intervals h2, 5i and h8, 12i men-
tioned in Hints are entered as input in the yellow cells.

The bounds of the rst interval are used to determine the step for tabulat-
ing it. All the bounds are used to calculate the shifts and scaling needed
for the bijection.
7.4. LAB PROBLEMS 235

In the rows 5 to 25, the columns B, D, F, H and J contain the values of the
individual intervals. The endpoints are highlighted in orange. The column
B corresponds to the initial interval and the column J to the resulting nal
interval.

The formula shown in the cell F5 is used in the whole column F. This
column recalculates the tabulated values from the interval h0, 3i shown in
column D by dividing it by 3 to the values from the interval h0, 1i.
The constant values in columns C, E, G, I and K are used as the y-
coordinates for displaying the sequence of intervals in a suitable x-y chart.

3. Mappings vs. relations


Hints:
• In this problem we want to display and compare two relations. At
the rst glance they might appear to be the same, but there is a
signicant dierence between them. The second relation switches
the rst value x with the second value y in the formula that denes
it.

• In practice, we can start with two tables showing the x-y dependence
and drawing their graphs. In both cases we use the same parameters
a and b. How are the tables going to dier? Which values are going
to be the input and which are going to be calculated using the given
formulas?

• What format can we use to display these relations? How are the two
graphs going to dier and what will they have in common?

• In the rst case, the values x tabulated from x = −10 to x = 10 are


the input. Even if we tabulate with a step = 1, we get a reasonably
good graph. The values in the output column y are calculated using
the formula with parameters a, b.
• In the second case, we can create a table with the same two columns
in the same order, but this time, it is the y column that is tabulated
with values from −10 to 10 with the step 1 and the values of x are
calculated using a formula.

• If both of the tables have the same format, we can use the same
x-y chart to display them. One of them corresponds to a graph of
a mapping that is single-valued for each input x. The other is a
relation in which a given x can be with more than one y. Which
graph is which?
236 CHAPTER 7. RELATIONS AND FUNCTIONS

Figure 7.6: A mapping vs. a relation.

Solution: In Figure 7.6, we show one possible solution.

The values of input parameters a, b and tabulated values x and y are


highlighted in yellow. The calculated values are shown in green.

The rst table and its graph show a mapping. For each tabulated value
x we have one corresponding output value y. We see the output values
above the input values x in the graph.

In the second table and graph we see that for example the value x = 104
is in relation x = 1 · y2 + 4 with y = −10 and also with y = 10. Therefore
this is only a relation and not a mapping. Unlike the previous case, when
we take a line parallel with the y -axis here, e.g. at x = 104, it intersects
the graph twice, giving us two related values of y.
A more careful observation reveals that the two graphs are very similar
(up to the scaling of the axes). We can transform one into the other by
rotating it by 90 degrees, i.e. by switching the variables x a y.
Chapter 8

Sequences

8.1 Lecture overview

8.1.1 Introduction and denition


Examples of sequences around us
• Time series: stock prices, exchange rates, measurements of physical vari-
ables (temperature, pressure) in time, sampling of sound.

• Recurrent processes: adding interest to savings or loans, calculating pop-


ulations based on data from previous time intervals.

• Description of (potentially) innite processes or constructions: inscribing


triangles into triangles, calculation of approximate values.

• Denition, investigation and manipulation of sequentially given data, e.g. el-


ements of arrays.

• Random processes: number of devices connected to a network at a given


time, number of e-mails received in an hour, interval between e-mails,
times when the e-mails were received (how are these related?), numbers
obtained by rolling dice (what we got, how many rolls did it take to get a
six).

These values may be nite, discrete, continuous. In the following we assume


they are real numbers.

237
238 CHAPTER 8. SEQUENCES

Sequence
The basic idea is to dene an ordered sequence of (real) numbers in which we
assume a certain connection, a common meaning. It is clear which number is the
rst and how they are ordered. Each number has its immediate successor and
(except for the rst one) also a predecessor. That way we can clearly determine,
which is the rst, the second, the third etc. number in the sequence.
A sequence is a function a : N → R. The sequence consists of values a(n)
denoted an and called sequence terms. The numbers n are called their indices.
The innite ordered list ha1 , a2 , a3 , a4 , . . . i is denoted {an }∞
n=1 or {an }n∈N . If
we restrict the domain from N to a nite subset of N, we can formally dene a
nite sequence.

Some ways to dene a sequence


A sequence can be given by:

3n−4 1−cos(nπ)
• A formula for the term an ,
7n−1 or bn =
e.g. an = 2 . We can also
3n+4 1−cos(nπ) 3n+4 ∞ 1−cos(nπ) ∞
write {
7n−1 }n∈N , { 2 }n∈N or { 7n−1 }n=1 , { 2 }n=1 . Two
well known sequences are given by formulas:

an = k + (n − 1) · d, (The rst term a1 = k and the dierence d are real


parameters.)  arithmetic sequence
gn = k · q n−1 , (The rst term g1 = k and the quotient q are non-zero real
parameters)  geometric sequence
• Stating the rst terms and a recurrent formula how to calculate next terms.
The calculation is then performed recursively.
a1 = 1, an = n · an−1
a1 = 1, a2 = 1, an = an−1 + an−2
For an arithmetic sequence, it is a1 = k, an = an−1 + d
For a geometric sequence, it is g1 = k, gn = gn−1 · q
• Listing the rst few terms h1, 3, 9, 27, 81, . . . i, h1, 2, 1, −1, −2, −1, 1, 2, . . . i.
Here it is expected that we discover the rule.

• A precise denition but without knowledge of the underlying formula or


the recurrent relation:

pn is the nth prime


th
tn is the n digit of π after the decimal point
8.1. LECTURE OVERVIEW 239

To understand the sequences and their properties better, it is useful to draw


them in a graph.

Notation
The denition of a sequence strictly requires that the set of indices is N. Clearly,
this can always be done, if we denote the rst term of the sequence a1 , the next
a2 etc. Sometimes, we can use a more clever indexing, e.g. the arithmetic and
geometric sequences have simpler formulas, if the indices start at 0. Therefore
we also use the following notation:

{an }∞
n=0 , {an }∞
n=4 , {an }∞
n=−6 , {k + n · d}∞
n=0 , {k · q n }∞
n=0

If we dene the set of indices I , we can also write {an }n∈I . It is also possible
to consider the sequence {an }n∈Z = {an }∞n=−∞ . Another exception is a nite
sequence, where I is a nite set. Note that not all of the following properties
apply to nite sequences.

Subsequence
Sometimes, we only need to examine some terms of a given sequence. We
may for example wish to skip the rst 5 or 50 000 or every other term. The
selection of a subsequence has to maintain order of the terms of the original
sequence, i.e. if we select a term, the next selected term has to come after
it. We say that a sequence {bn }n∈N is a subsequence of sequence {an }n∈N , i
∀n ∈ N ∃m ∈ N : bn = am , moreover ∀n ∈ N if (bn = ak ) ∧ (bn+1 = al ) for some
k, l ∈ N then k < l.

8.1.2 Basic properties


We say that the sequence {an }n∈N is

• Constant i there exists a real number c such that ∀n ∈ N : an = c

h1, 1, 1, 1, 1, . . . i, h−π, −π, −π, −π, . . . i

• Increasing i ∀i, j ∈ N : i < j ⇒ ai < aj (it is also sucient to have


∀i ∈ N : ai < ai+1 ), for example:
1 2 3 4
h1, 2, 3, 4, 5, . . . i, h , , , , . . . i
2 3 4 5
240 CHAPTER 8. SEQUENCES

• Decreasing i ∀i, j ∈ N : i < j ⇒ ai > aj (or ∀i ∈ N : ai > ai+1 )

• Non-decreasing i ∀i, j ∈ N : i < j ⇒ ai ≤ aj (or ∀i ∈ N : ai ≤ ai+1 )

• Non-increasing i ∀i, j ∈ N : i < j ⇒ ai ≥ aj (or ∀i ∈ N : ai ≥ ai+1 )

• Bounded from above i there exists a real number H such that ∀i ∈ N :


ai ≤ H

• Bounded from below i there exists a real number D such that ∀i ∈ N :


ai ≥ D

• Bounded i it is bounded both from below and from above.

Properties of sequences
Which of the properties of sequences imply other properties?
Which preclude other properties?

8.1.3 Limits of sequences


Another important set of properties is related to the fact that sequence is in-
nite. One might ask, why do we care about sequence behavior in innity. In
real world, we only encounter nite sequences (which may be parts of the the-
oretically innite ones). There are two basic reasons: the innite sequences are
an important tool for developing parts of mathematics and many properties of
sequences following from the sequence behavior in innity are useful (and oth-
erwise undetectable) for determining the sequence behavior in its nite initial
parts. Most often we would like to know whether the sequence values stabilise
at a certain value. It could mean a steady stream of e-mails per hour or a
numerical value of π or e.
The key property of the sequence, which makes it a useful term and mathe-
matical tool, is thus its ability to tend to a certain value. It is important that
the sequence approaches this value (or even reaches it, as is the case of a con-
stant sequence) arbitrarily closely and almost the whole sequence achieves this
closeness. There is only a nite number of exceptions. All subsequent terms af-
ter the initial part containing exceptions will be close. We call the value, which
they are approaching, a limit.
8.1. LECTURE OVERVIEW 241

Limit
The closeness of sequence to a limit value L can be understood by its terms
belonging to a (small) neighborhood (L − ε, L + ε). We can think of the neigh-
borhood as a tunnel around the limit value. Even when we make the tunnel
arbitrarily narrow, starting at some sequence term, the whole rest of the se-
quence will be inside the tunnel. If we denote the width of the tunnel by a
real number ε and distance using an absolute value, we can dene the limit as
follows.
We say that a sequence {an }n∈N has a limit L ∈ R i
(∀ε ∈ R+ )(∃m ∈ N)(∀n ≥ m, n ∈ N)(|an − L| < ε)
Since the limit L is a real number, we also say that the sequence has a proper
limit. When a sequence has a limit (L), we say that the sequence converges (to
L). We write lim an = L or lim an = L, if it is clear which index was meant.
n→∞
In such case, we can also write an → L.

Improper limit
We now state a special case when a sequence increases or decreases without
a bound. Again, we require that it has only nitely many exceptions to this
property in some early part of the sequence. Then we say that the sequence
{an }n∈N has an improper limit ∞ i
(∀B ∈ R), (∃m ∈ N)(∀n ≥ m, n ∈ N)(an > B).
We say that the sequence {an }n∈N has an improper limit −∞ i
(∀B ∈ R), (∃m ∈ N)(∀n ≥ m, n ∈ N)(an < B).

8.1.4 Properties and calculations of limits


Calculation of limits from denition
If we want to calculate a limit of a sequence based on what we know so far,
we need to perform two steps. First we need to guess a (proper or improper)
limit and then prove that it meets the tunnel property. These steps are dicult
and impractical but necessary for calculation of few basic limits. Once we have
these, we can use the following properties for calculation of more limits. The
properties hold for proper limits and some of them can also be extended for
improper limits.
242 CHAPTER 8. SEQUENCES

Intuitive calculation of limits


In order to determine the limit of a sequence, we can also use an estimate
obtained by plugging in increasingly large values of n.

Problem 8.1 Intuitive limit:


Calculate lim 4−n .
n→∞ 2n+5

Solution: We are looking for an L such that

4−n
→ L.
2n + 5
We start by plugging in n = 100
−96 .
= −0.468292683;
205
then n = 1000
−996 .
= −0.49675;
2005
and then n = 1 000 000
−999996 .
= −0.49999675.
2000005
At this point we guess that L = −0.5 = − 12 and try to prove it.
To prove it means to show that the following dierence tends to zero:

4−n
− L → 0.
2n + 5
After plugging in, we get

4−n 1 8 − 2n + 2n + 5 13 O(n)
+ = = = → 0.
2n + 5 2 2 · (2n + 5) 2 · (2n + 5) O(n2 )

We use the O notation to indicate the behavior of the sequence in innity. We


return to this in more detail in Section 12.1.1.

Problem 8.2 Another intuitive limit:


2
2n −3n+5
Calculate the limit of the sequence { 3n 2 −2n+5 }n∈N .
8.1. LECTURE OVERVIEW 243

Solution: By plugging in increasingly large values of n we estimate L and then


show that the sequence decreased by L tends to zero.

2n2 − 3n + 5
−L→0
3n2 − 2n + 5
2n2 − 3n + 5 2 6n2 − 9n + 15 − 6n2 + 4n − 10
− = =
3n2 − 2n + 5 3 3 · (3n2 − 2n + 5)
−5n + 5 O(n)
= = →0
9n2 − 6n + 15 O(n2 )

Multiplication by a constant
Suppose an → A, A ∈ R. Then

1. ∀c ∈ R it is true that can → cA;


2. |an | → |A|.
The limit of a sequence whose terms are constant multiples (or absolute values)
of terms of a convergent sequence, is the same multiple (or absolute value) of
the original limit.

Multiplication by a constant for improper limits


Suppose an → ±∞. Then

1. ∀c ∈ R+ it is true that can → ±∞;


2. ∀c ∈ R− it is true that can → ∓∞ (the sign changes!);

3. |an | → ∞.
The limit of a sequence whose terms are constant multiples (or absolute values)
of terms of a sequence that converges to an improper limit, is also an improper
limit (possibly with opposite sign).

Basic operations with two sequences


Suppose an → A, bn → B; A, B ∈ R. We consider sequences whose terms are
obtained by arithmetic operations on terms an and bn .
1. an + bn → A + B ;
244 CHAPTER 8. SEQUENCES

2. an − bn → A − B ;

3. an · bn → A · B ;

4. if B 6= 0 then an /bn → A/B .

Sequences whose terms are created from two convergent sequences using an
arithmetic operation converge to the limits obtained by the same operation
from the original limits.

Ratio of bounded and innitely growing sequences


Suppose an is a bounded sequence and bn → ±∞. Then an /bn → 0.
If the numerator is bounded and denominator grows or decreases unboundedly,
their ratio tends to zero. Note that every sequence that has a nite limit, i.e.
an → A, A ∈ R, is bounded and thus this theorem applies to it.

Ratio of a sequence with a proper limit and a sequence tending to


zero
Suppose an → A 6= 0, bn → 0 and all bn are positive. Denote the sign of A
by sign(A). Then an /bn → sign(A)∞. If all bn are negative, then an /bn →
−sign(A)∞.
If the denominator tends to zero, the ratio unboundedly grows or decreases,
depending on the sign of A and the sign of terms bn . The tunnel property does
not work, if bn changes signs.

Ratio of a bounded sequence and a sequence tending to zero?


Could we just use a bounded sequence in the previous statement instead
of a sequence that has a proper limit? If yes, why? If not, why not?

Composition of continuous functions


Suppose an → A, A ∈ R. Suppose bn is a sequence, whose terms are gener-
ated from an using the same continuous function (e.g. square root, exponential,
power, trigonometric function, etc.). Suppose all an and the limit value A are
in the domain of this function. Then also bn converges and we can obtain its
limit by applying the same function to the original limit A, i.e.:

an → A, bn = f (an ) ⇒ bn → f (A)
8.1. LECTURE OVERVIEW 245

Some examples:


r  
2n 2n 2n
2 2n
→2 ⇒ → 2, 3 n+1 →3 , cos → cos(2)
n+1 n+1 n+1

Therefore if we are calculating a limit of a sequence, whose terms are given by


a formula that enters an outer function, in some (i.e. continuous) cases, we can
rst calculate the limit of the inner part and then apply the function to the
result.

The squeeze theorem


This property uses the inequalities between pairs of sequence terms. It is also
unocially called a Two policemen theorem or Two friends theorem, since in
both cases the two of them will lead the middle person where they should go.
Suppose we have three sequences {an }n∈N , {bn }n∈N and {cn }n∈N . Suppose
∀n ∈ N we have an ≤ bn ≤ cn , and let an → L, cn → L. The sequences {an }n∈N
and {cn }n∈N thus have the same limit, either proper or improper. Then it
follows that {bn }n∈N has the same limit, i.e. bn → L.
The two good friends (or cops) who are headed to the same limit and guard
the third sequence between them, lead the third sequence to the same limit as
well. The inequalities allow us to deal with situation in which it is complicated
or unfeasible to use the arithmetic operations from previous properties. Some
examples of sequences which lead the middle sequence to zero are:

−1 sin(n) 1 1 1 1 1
≤ ≤ , 0≤ ≤ 0≤ ≤
n n n n2 n 2n n
In cases where we used a constant zero (the second and the third example), we
meant a constant sequence.

Uniqueness of the limit


Suppose an → A, A ∈ R. Then A is the only limit of this sequence. Remember
that the interval (A−ε, A+ε) is the tunnel of the limit. Since every neighborhood
(tunnel) around the limit value A contains all sequence terms starting at some
index, it is not possible for innitely many of them to appear in another tunnel
(B − ε, B + ε), around the limit value B. To make sure that these two tunnels
do not overlap, we can suciently decrease ε.
246 CHAPTER 8. SEQUENCES

Monotonicity with boundedness implies proper limit


Suppose a sequence is non-decreasing and bounded from above. Then it has a
proper limit. Similarly if it is non-increasing and bounded from below, then it
has a proper limit.
To understand this property, it is helpful to realise, what is the limit of such
sequence. In the case of non-decreasing sequence bounded from above, it is the
smallest upper bound. If we make an arbitrarily small tunnel around it, the
sequence eventually crosses its lower edge (otherwise, this lower edge would be
a smaller upper bound). And once the sequence crosses this edge, it will remain
in the tunnel due to its monotonicity. (For non-increasing sequence bounded
from below, the greatest lower bound serves a similar purpose.)
This property is very useful both for proving that the sequence has a limit
and for nding this limit. Once we know that the limit exist, we can use heavy
caliber weapons, such as subsequences, for nding it and then proving mono-
tonicity and boundedness of the sequence, which is much easier than examining
complicated limits. Moreover, the monotonicity implies that the sequence is
getting closer and closer to the limit, so its terms themselves can serve as a
self-improving estimate of the limit value.
The most famous application of this property is analysis of the sequence

 n 
1
1+ .
n n∈N

Using the binomial theorem it is possible to show that this sequence is in-
creasing and all its terms are smaller than three. Therefore this sequence has
to have a proper limit. This limit is the well-known and important number
e∼
= 2.718281828 . . .

Limit of subsequence
Suppose that a sequence {an }n∈N has a proper or improper limit. Next suppose
that {bn }n∈N is any subsequence of {an }n∈N . Then {bn }n∈N has the same limit.
This can be seen directly from the denition of both proper and improper limit.
The main use of this property lies in proving that a sequence does not have
a limit. For example a sequence {−1n }n∈N = h−1, 1, −1, 1, . . .i has two special
subsequences. One of them has limit 1 and the other −1. If two subsequences
have two dierent limits, it is clear that the original sequence does not have a
limit. Without this property, it would be very dicult to prove that a sequence
8.1. LECTURE OVERVIEW 247

does not have a limit. We would need to negate the denition and show that
every real number (as well as ∓∞) meets the negation.
The property also gives us new possibilities for determining the value of the
limit, especially if we already know (using the previous property) that a limit
exists.

Problem 8.3 n√
th
square root of 2:
n
Show that lim 2 = 1.
n→∞

Solution: We rst show that the sequence decreasing and bounded from below,
√ √ √
n n+1 n
i.e. for all n we have 2> 2 and 2 > 1. From that we know that a limit

n
exists. We can denote it A. Therefore we have lim 2 = A. But how much is
√ n→∞
n
A?√For that we use a subsequence of { 2}n∈N . We only take the even terms:
{ 2n 2}n∈N . What is its limit? Since
√ it is a subsequence of a sequence with limit
A, it must be true that lim 2n 2 = A. Using the properties we mentioned, we
n→∞
can write:
2n

q

n
r

n

lim 2 = lim 2= lim 2= A.
n→∞ n→∞ n→∞

So we see that A= A. There are only two such numbers: 1 and 0. Since all
sequence terms are greater than 1, we can disregard 0 and we have:

n

2n
lim 2 = lim 2 = 1.
n→∞ n→∞

Other important limits can be determined similarly: lim n n = 1, lim q n =0
n→∞ n→∞
for q ∈ h0, 1). The limit is also 0 for q∈ (−1, 0), but the proof is dierent.

Ratio of successive terms


Consider a sequence with the property that each new term q n+1 is created from
n
the previous term q by multiplying it by a number less than 1:

an+1 q n+1
= n , q ∈ (−1, 1).
an q
Then it is true that lim an = 0. The idea is that if the sequence stabilises
n→∞
to the extent that each successive term is less-than-a-1-multiple of the previous
term, the sequence decreases in such a way that it tends to 0. This property is
very useful in examining the zero-limit sequences and it can be shown that this
property also works if the ratio is not xed but tends to a limit.
248 CHAPTER 8. SEQUENCES

Problem 8.4 Ratio of successive terms:


Evaluate lim 4nn .
n→∞ 6

Solution: We suspect that the numerator tends to innity much slower than the
denominator and the limit could be zero. We evaluate the auxiliary limit:

4(n+1)
an+1 6( n+1) 4(n + 1) · 6n n+1 1
lim | | = lim | 4n | = lim n+1
= lim = .
n→∞ an n→∞
6n
n→∞ 4n · 6 n→∞ 6n 6

Since 1/6 < 1, the original limit is 0.


8.2. QUESTIONS 249

8.2 Questions

1. Write the rst six terms of the sequence


n o∞
a) 2 − sin(π·n)
2 ,
n=1
n o∞
4n+7
b)
3n−2 .
n=4

2. Write the rst seven terms of the arithmetic sequence with the rst term
8 and dierence 3.

3. Write the rst six terms of the geometric sequence with the rst term 2
and quotient 4.

4. Write the rst ve terms of the recurrent sequence a0 = 3; a1 = 2; an =


3 · an−1 + an−2 .

5. Write a simple formula for a sequence that starts with terms

a) h1, 3, 9, 27, 81, . . . i


b) h1, 4, 9, 16, 25, . . . i
c) h1, 2, 4, 6, 10, 12, 16, . . . i

6. Let an = h1, 4, 9, 16, 25, 36. . . i , bn = h4, 16, 36, . . . i and cn = h4, 36, 16, . . . i.
What is the relation between an , bn and cn ?

7. Give an example of a constant sequence.

8. Give an example of

a) an increasing sequence,

b) a non-decreasing sequence which is is not increasing,

c) a non-increasing sequence which is not decreasing,

d) a sequence which is bounded from above,

e) a sequence which is bounded form below and decreasing.


n o∞
4n+1
9. Which of these properties does the sequence have: increasing,
3n+1
n=1
non-increasing, bounded from below, bounded from above, unbounded,
decreasing, non-decreasing?
250 CHAPTER 8. SEQUENCES
n o∞
1
10. Find the smallest upper bound for the sequence 2− 3n+1 .
n=1

11. Find the rst such n, that the distance of the nth term of the sequence
 1 ∞
2− 3n n=1
from 2 is at most

a) 0.1,

b) 0.01.

1. Give examples of at least three sequences which

a) have limit 5.

b) do not have a limit.

c) have a limit ∞.
d) have a limit −∞.
2. Find a q such that lim q n
n→∞

a) equals 0,

b) equals 1,

c) is ∞,
d) does not exist.

3. Let lim an = 7 and let c = 3. How much is lim c · an ?


n→∞ n→∞

4. Let lim an = −7. How much is lim |an |?


n→∞ n→∞

5. Let lim an = −5 and let lim bn = 5. How much is lim (an + bn )?


n→∞ n→∞ n→∞

6. Let lim an = −5 and let lim bn = 5. How much is lim an ?


n→∞ n→∞ n→∞ bn

7. Let lim an = 17. How much is lim sin(an )?


n→∞ n→∞

8. Let the sequence {an }∞


n=1 be increasing and let it have an upper bound 4.
Can the limit of this sequence be −5?
9. Let the sequence {an }∞
n=1 be decreasing and let it have a lower bound 4.
Can the limit of this sequence be −5?
10. Give an example of a sequence that has two dierent limits.

11. Give an example of a sequence that has two subsequences with dierent
limits.
8.3. PROBLEM SET 251

8.3 Problem set

1. Sequences given by a closed form formula


Write the rst few terms of sequences given by the formula.

a) {5n}∞
n=1 ; {5n}∞
n=0 ; {5n}∞
n=3
b) {n2 }∞
n=1 ; {n2 − 1}∞
n=0 ; {n2 + 5}∞
n=−2 ; {3n2 }∞
n=1
c) {2n }∞
n=1 ; {2n }∞
n=0 ; {2n + 2}∞
n=−2 ; {2n+2 }∞
n=−2
d) {(−1)n }∞
n=1 ; {(−1)n }∞
n=0 ; {(−1)n+1 }∞
n=1 ; {(−1)n+1 −(−1)n }∞
n=1
e) {(−1)n + 3}∞
n=1 ; {3 · (−1)n }∞
n=1
n+1 n n+1
−(−1) −(−1)n ∞
f) { (−1) 2 }∞
n=1 ; { (−1) −2 }n=1
g) { 21n }∞
n=1 ; { 21n }∞
n=0 ;
1 ∞
{ n2 }n=1
2. Sequences given by their terms
For each sequence write a formula for the nth term. If possible, write also
a recurrent formula, which can be used to calculate a term using some
previous terms.

a) h3, 6, 9, 12, . . . i = {an }∞ ∞ ∞


n=1 = {bn }n=0 = {cn }n=3
an =?, bn =?, cn =?
b) h3, 7, 11, 15, 19, . . . i = {an }∞ ∞ ∞
n=0 = {bn }n=2 = {cn }n=−5
an =?, bn =?, cn =?
c) h0, 3, 8, 15, 24, . . . i = {an }∞ ∞
n=1 = {bn }n=5
an =?, bn =?
d) h1, 2, 4, 8, 16, 32, . . . i = {an }∞ ∞
n=0 = {bn }n=2
an =?, bn =?
e) h3, −3, 3, −3, 3, . . . i = {an }∞ ∞
n=0 = {bn }n=1
an =?, bn =?
f) h2, 3, 5, 9, 17, 33, . . . i = {an }∞ ∞
n=0 = {bn }n=2
an =?, bn =?
g) h5, 6, 5, 6, 5, 6, . . . i = {an }∞ ∞
n=0 = {bn }n=1
an =?, bn =?
3. Sequences given by a recurrent formula
The following sequences are given by a recurrent formula. Use it to write
out at least the rst ve terms. Try determining the closed formula for the
nth term (formula that uses just the index n and not the previous terms).
252 CHAPTER 8. SEQUENCES

a) a1 = 4, an = an−1 + 2
b) a1 = 2, an = 2 − an−1
c) a1 = 2, an = −an−1
d) a1 = 1, an = 1 + 2an−1
e) a1 = 2, a2 = 1, an = an−1 − an−2

4. Properties of sequences
Write at least the rst ve terms of these sequences. Are the sequences
increasing, decreasing, bounded from above, bounded from below? Prove
your answers.
n o∞
2n+1
a)
5n−3
n=1
n o∞
4−m
b)
2m+5
m=1
n o∞
n+4
c)
n+3
n=1
n o∞
k+1
d)
2k−11
k=1

5. Limits
Find the limits of sequences:

a)

∞ ∞ ∞ ∞
3r2 + 2
   
4−n t+4 k+1
, , ,
2n + 5 n=1 t+3 t=1 3k − 11 k=1 3 − 4r2 r=1
∞
n2 + 2n − 1


1 − 2n + 5n2 n=1

b)

∞ ∞ ∞
4n5 − 9n3 + 148 6l4 + 5l + 4 m2 + 10m
  
, ,
4n5 + 7n2 − n n=1 7l3 + 8l + 9 l=1 2m2 + 5m3 m=1

c)
∞ ∞
3 + 5 · 4n 1 + 7 · 5j
 
,
5 + 7 · 4n n=1 2 − 5 · 7j j=1
8.3. PROBLEM SET 253

d)
n p o∞ √ √ ∞
s − s2 + 2 , n+3− n−3 s=1
s=1

e)

∞ ∞ ∞ ∞
(−1)n
   
1 1 −2
, , ,
n2 n=1 n3 + 1 n=1 n2 + n n=1 n2 n=1
 ∞
sin n
n2 n=1
254 CHAPTER 8. SEQUENCES

8.3.1 Hints and solutions


1. Sequences given by a closed form formula
Write the rst few terms of sequences given by the formula.

a) {5n}∞
n=1 ; {5n}∞
n=0 ; {5n}∞
n=3

b) {n2 }∞
n=1 ; {n2 − 1}∞
n=0 ; {n2 + 5}∞
n=−2 ; {3n2 }∞
n=1

c) {2n }∞
n=1 ; {2n }∞
n=0 ; {2n + 2}∞
n=−2 ; {2n+2 }∞
n=−2

d) {(−1)n }∞
n=1 ; {(−1)n }∞
n=0 ; {(−1)n+1 }∞
n=1 ; {(−1)n+1 −(−1)n }∞
n=1

e) {(−1)n + 3}∞
n=1 ; {3 · (−1)n }∞
n=1
n+1
−(−1)n ∞ n+1
−(−1)n ∞
f) { (−1) 2 }n=1 ; { (−1) −2 }n=1
g) { 21n }∞
n=1 ; { 21n }∞
n=0 ; { n12 }∞
n=1

Hint: In computer science and coding, the sequences are related to cycles
and indexing elds. We often need to input dierent values for a rst few
terms and then starting from some term, the sequence observes a certain
rule. We should be able to capture such behavior using indices. In this
problem, we consecutively insert the natural numbers into the variable n
and express the individual sequence terms. The mathematicians say that
the sequence is given explicitly, the computer scientists say that the terms
are given in the closed form.

Solution:
a) h5, 10, 15, 20, . . . i; h0, 5, 10, 15, 20, . . . i; h15, 20, 25, 30 . . . i
b) h1, 4, 9, 16, 25 . . . i; h−1, 0, 3, 8, 15, 24 . . . i; h9; 6; 5; 6, 9, 18, 21 . . . i;
h3, 12, 27, 48, 75 . . . i
c) h2, 4, 8, 16, . . . i; h1, 2, 4, 8, 16, . . . i; h2 41 , 2 12 , 3, 4, 6, 10, 18, . . . i;
h1, 2, 4, 8, 16, . . . i
d) h−1, 1, −1, 1, −1 . . . i; h1, −1, 1, −1, 1, . . . i; {1, −1, 1, −1, 1, . . . i;
h2, −2, 2, −2, 2, −2, . . . i
e) h2, 4, 2, 4, 2, 4, . . . i; h−3, 3, −3, 3, −3, 3, . . . i
f) h1, −1, 1, −1, 1, −1, . . . i; h−1, 1, −1, 1, −1, 1, −1, , . . . i
g) h 21 , 41 , 18 , 16
1 1
, 32 , . . . i; h1, 21 , 14 , 18 , 16
1 1
, 32 , . . . i; h1, 14 , 19 , 16
1 1
, 25 1
, 36 ,...i
8.3. PROBLEM SET 255

2. Sequences given by their terms


For each sequence write a formula for the nth term. If possible, write also
a recurrent formula, which can be used to calculate a term using some
previous terms.

a) h3, 6, 9, 12, . . . i = {an }∞ ∞ ∞


n=1 = {bn }n=0 = {cn }n=3
an =?, bn =?, cn =?
b) h3, 7, 11, 15, 19, . . . i = {an }∞ ∞ ∞
n=0 = {bn }n=2 = {cn }n=−5
an =?, bn =?, cn =?
c) h0, 3, 8, 15, 24, . . . i = {an }∞ ∞
n=1 = {bn }n=5
an =?, bn =?
d) h1, 2, 4, 8, 16, 32, . . . i = {an }∞ ∞
n=0 = {bn }n=2
an =?, bn =?
e) h3, −3, 3, −3, 3, . . . i = {an }∞ ∞
n=0 = {bn }n=1
an =?, bn =?
f) h2, 3, 5, 9, 17, 33, . . . i = {an }∞ ∞
n=0 = {bn }n=2
an =?, bn =?
g) h5, 6, 5, 6, 5, 6, . . . i = {an }∞ ∞
n=0 = {bn }n=1
an =?, bn =?
Hints:
• While writing out the individual terms of a sequence given in a closed
form is relatively simple, the inverse problem  nding the closed form
of the sequence given by its terms  is more dicult.

• We need to look for regularity for example in dierences or in ratios


of the consecutive terms of the sequence.

• The expression for the nth term of the sequence will depend on the
rst value of n.
• The recurrent relations may be easy (multiplying the previous term
or adding a constant), may be impossible to nd (prime numbers)
and sometimes just dicult (using the powers of −1 or multiple se-
quences).

• For oscillating sequences, such as the one in g), we can use the fact
that the sequence h1, −1, 1, −1, 1, −1, . . . i oscillates around 0, with
amplitude 1. It can be shifted to oscillate around a dierent number
and stretched to oscillate with a dierent amplitude.
256 CHAPTER 8. SEQUENCES

Solution:
a) We notice that the terms are multiples of 3.
h3, 6, 9, 12, . . . i = {an }∞ ∞ ∞
n=1 = {bn }n=0 = {cn }n=3
an = 3n, bn = 3(n + 1), cn = 3(n − 2)
b) We notice that the terms are multiples of 4 decremented by 1.
h3, 7, 11, 15, 19, . . . i = {an }∞ ∞ ∞
n=0 = {bn }n=2 = {cn }n=−5
an = 3 + 4n, bn = 3 + (n − 2) · 4, cn = 3 + (n + 5) · 4
c) h0, 3, 8, 15, 24, . . . i = {an }∞ ∞
n=1 = {bn }n=5
2 2
an = n − 1, bn = (n − 4) − 1
d) h1, 2, 4, 8, 16, 32, . . . i = {an }∞ ∞
n=0 = {bn }n=2
n n−2
an = 2 , bn = 2
e) h3, −3, 3, −3, 3, . . . i = {an }∞ ∞
n=0 = {bn }n=1
n n+1
an = (−1) · 3, bn = (−1) ·3
f) h2, 3, 5, 9, 17, 33, . . . i = {an }∞ ∞
n=0 = {bn }n=2
an = 2n + 1, bn = 2n−2 + 1
g) h5, 6, 5, 6, 5, 6, . . . i = {an }∞ ∞
n=0 = {bn }n=1
n+1
an = 5.5 + 0.5 · (−1) , bn = 5.5 + 0.5 · (−1)n
3. Sequences given by a recurrent formula
The following sequences are given using a recurrent formula. Use it to
write out at least the rst ve terms. Try determining the closed formula
for the nth term (formula that uses just the index n and not the previous
terms).

a) a1 = 4, an = an−1 + 2
b) a1 = 2, an = 2 − an−1
c) a1 = 2, an = −an−1
d) a1 = 1, an = 1 + 2an−1
e) a1 = 2, a2 = 1, an = an−1 − an−2

Hint: The expression for the nth term of the sequence depends on the
initial value of n. It is useful to start with writing the rst few terms
and looking at possible patterns that might emerge. Why do we use
recurrent formulas then at all? Sometimes they are more convenient for
calculating the sequence terms, e.g. calculating a binomial coecient from
an explicit formula is computationally intensive. Evaluating it as a sum
8.3. PROBLEM SET 257

of two suitable smaller binomial coecients is much easier. In cases where


we cannot detect a pattern in the values, the closed form formula can be
obtained using generating functions (these are beyond the scope of this
text).

Solution:
a) a1 = 4, an = an−1 + 2, h4, 6, 8, 10, . . . i, {4 + 2(n − 1)}∞
n=1
b) a1 = 2, an = 2 − an−1 , h2, 0, 2, 0, 2 . . . i, {(−1)n+1 − (−1)n }∞
n=1
c) a1 = 2, an = −an−1 , h2, −2, 2, −2, 2 . . . i, {(−1)n+1 · 2}∞
n=1
d) a1 = 1, an = 1 + 2an−1 , h1, 3, 7, 15, 31 . . . i, {2n − 1}∞
n=1
e) a1 = 2, a2 = 1, an = an−1 −an−2 , h2, 1, −1, −2, −1, 1, 2, 1, −1, . . . i

4. Properties of sequences
Write at least the rst ve terms of these sequences. Are the sequences
increasing, decreasing, bounded from above, bounded from below? Prove
your answers.
n o∞
2n+1
a)
5n−3
n=1
n o∞
4−m
b)
2m+5
m=1
n o∞
n+4
c)
n+3
n=1
n o∞
k+1
d)
2k−11
k=1

Hint: When we try to answer the questions about sequences and prove
their properties, it is useful to have a graphic representation of them.

Looking at Figure 8.1 we see that the sequence is decreasing and possibly
bounded. For a decreasing sequence, it is true that
n o∞ ∀k ∈ N : ak > ak+1 .
2n+1
For our sequence
5n−3 we should then have ∀k ∈ N :
n=1

2·k+1 2 · (k + 1) + 1
> .
5·k−3 5 · (k + 1) − 3

We prove this statement by starting from a true statement, e.g. 2 > −9,
and modifying it by admissible (equivalent) operations to get the desired
statement. How do we know where to start? That is, of course, dicult
258 CHAPTER 8. SEQUENCES

n o∞
2n+1
Figure 8.1: Graph of sequence .
5n−3
n=1

2k+1 2k+3
to guess. Instead of guessing, we can take the inequality
5k−3 > 5k+2
and modify it by equivalent operations until we get to an obviously true
statement. We then take this as a starting point and reverse the order of
the equivalent operations. In Chapter 12 we discuss this approach (and
proofs in general) in more detail.

2 > −9
2 + 10k 2 > −9 + 10k 2
2 + 10k 2 + 9k > −9 + 10k 2 + 9k
(2k + 1)(5k + 2) > (2k + 3)(5k − 3)
2k + 1 2k + 3
>
5k − 3 5k + 2
Alternatively, we can calculate the dierence

2(k + 1) + 1 2k + 1 2k + 3 2k + 1 −11
ak+1 −ak = − = − = < 0.
5(k + 1) − 3 5k − 3 5k + 2 5k − 3 (5k + 2)(5k − 3)
Since the dierence is always negative, each next term is smaller than the
previous one, hence the sequence is decreasing.

Regarding monotonicity, we should realise that if a sequence is decreasing,


it cannot be increasing and vice versa. Consider also the dierence between
a decreasing and non-increasing sequence.

Solution:
8.3. PROBLEM SET 259

n o∞
2n+1
3 5 7 9 11
are: h , ,
a) The terms of the sequence
2 7 12 , 17 , 22 . . . i. The
5n−3
n=1
sequence is decreasing and bounded both from below and above.
n o∞
4−m 3 2 1 −1
are: h , ,
b) The terms of the sequence
2m+5 7 9 11 , 0, 15 . . . i. The
m=1
sequence is decreasing and bounded both from below and above.
n o∞
n+4 5 6 7 8 9
c) The terms of the sequence are: h , , , , . . . i. The
n+3 4 5 6 7 8
n=1
sequence in decreasing and bounded both from below and above.
n o∞
k+1 −2 −3 −4 −5 −6
are: h
d) The terms of the sequence
2k−11 9 , 7 , 5 , 3 , 1 , 7, . . . i.
k=1
The sequence is neither decreasing nor increasing. It is bounded both
from below and above.

5. Limits
Find the limits of sequences:

a)
∞ ∞ ∞ ∞
3r2 + 2
   
4−n t+4 k+1
, , ,
2n + 5 n=1 t + 3 t=1 3k − 11 k=1 3 − 4r2 r=1
 2 ∞
n + 2n − 1
1 − 2n + 5n2 n=1
b)
∞ ∞ ∞
4n5 − 9n3 + 148 6l4 + 5l + 4 m2 + 10m
  
, ,
4n5 + 7n2 − n n=1 7l3 + 8l + 9 l=1 2m2 + 5m3 m=1

c)
∞ ∞
3 + 5 · 4n 1 + 7 · 5j
 
,
5 + 7 · 4n n=1 2 − 5 · 7j j=1

d)
n p o∞ √ √ ∞
s − s2 + 2 , n+3− n−3 s=1
s=1
e)
∞ ∞ ∞ ∞
(−1)n
   
1 1 −2
, , ,
n2 n=1
3
n +1 n=1
2
n +n n=1 n2 n=1
 ∞
sin n
n2 n=1
260 CHAPTER 8. SEQUENCES

Hints:
a)
 ∞
4−n
2n + 5 n=1

A limit is a value to which the terms of the sequence tend to with


increasing n. One way to nd out the value of the limit is to draw
the sequence terms, see Figure 8.2.

n o∞
4−n
Figure 8.2: Graph of the sequence .
2n+5
n=1

Historically, limits have also been calculated by substituting innitely


large values for n and working with them as if they were real values,
e.g.:
4−∞ −∞
or .
2∞ + 5 ∞
This kind of calculation does not always lead to a correct answer.
Therefore we should rather perform suitable algebraic operations
with the expression in the limit that do not change the answer. In
this particular case, we can multiply both the numerator and denom-
1
inator by
n.

1 ∞ ∞ ∞
4 · n1 − n · n1
4
−1
 
4−n n n
· 1 = =
2n + 5 n n=1
2n · n1 + 5 · n1 n=1
2 + n5 n=1

Since each of the four expressions has a nite limit, we can calculate
the limits separately and insert the results into the original fraction.
8.3. PROBLEM SET 261

Then we get

4−n 4
−1 lim n4 − lim 1 0−1 1
lim = lim n 5 = n→∞ n→∞
5 = 2 + 0 = −2.
n→∞ 2n + 5 n→∞ 2 + lim 2 + lim
n n n→∞ n→∞

b)
∞
4n5 − 9n3 + 148


4n5 + 7n2 − n n=1


Similarly to the previous problem, we multiply both the numerator
1
and denominator by
n5 .
For the problem
∞
6l4 + 5l + 4


7l3 + 8l + 9 l=1
1
we multiply both numerator and denominator by
l4 and get
∞
6 + l53 + l44

7 8 9 .
l + l3 + l4 l=1

In this expression we see that the limit of the numerator is 6 and


the limit of the denominator is 0. According to the Theorem Ratio
of a sequence with a proper limit and a sequence tending to zero in
Section 8.1.3 we get

6 + l53 + l44
lim 7 8 9 = ∞.
l + l3 + l4
n→∞

c)
∞
3 + 5 · 4n


5 + 7 · 4n n=1
In this case, we multiply both the numerator and denominator by
1
4n .
d)
n p o∞
s − s2 + 2
s=1
In this case, for innite s, we symbolically get ∞ − ∞, which can
evaluate to −∞, ∞ or anything in between. To calculate the value
of this kind of limit, we use the formula

(a − b)(a + b) = a2 − b2 .
262 CHAPTER 8. SEQUENCES

We can treat s− s2 + 2 as a fraction

s− s2 + 2
1

and multiply both its numerator and denominator by s + s2 + 2.
 −1 ∞
e) Since −1 ≤ sin n ≤ 1, we can nd a lower bound
n2 n=1 and
1 ∞ ∞  sin n
an upper bound for the sequence . These two
n=1n2 n=1 n2
bounding sequences have the same limit, which is 0, so it is possible to
deduce the limit of the sequence bounded by them using the Squeeze
theorem from Section 8.1.3.

Solution: For the rest of the limits we provide the answers so that you can
check your work:

a)
4−n 1 t+4 k+1 1
lim =− , lim = 1, lim = ,
n→∞ 2n + 5 2 n→∞ t+3 n→∞ 3k − 11 3
3r2 + 2 3 n2 + 2n − 1 1
lim =− , lim =
n→∞ 3 − 4r 2 4 n→∞ 1 − 2n + 5n2 5
b)
4n5 − 9n3 + 148 6l4 + 5l + 4
lim = 1, lim = ∞,
n→∞ 4n5 + 7n2 − n l→∞ 7l3 + 8l + 9

m2 + 10m 1
lim 2 3
=
m→∞ 2m + 5m 2
c)
3 + 5 · 4n 5 1 + 7 · 5j
lim = , lim =0
n→∞ 5 + 7 · 4n 7 j→∞ 2 − 5 · 7j

d)
p √ √
lim s − s2 + 2 = 0, lim n+3− n−3=0
s→∞ n→∞

e)
1 1 −2
lim = 0, lim = 0, lim = 0,
n→∞ n2 n→∞ n3 + 1 n→∞ n2 + n
(−1)n sin n
lim = 0, lim =0
n→∞ n2 n→∞ n2
8.4. LAB PROBLEMS 263

8.4 Lab problems

1. Drawing sequences
a) Calculate the rst 1000 terms of a linear fraction sequence {an }∞
n=1
and draw them in a chart. Using the chart, estimate the proper-
ties of the sequence (boundedness, monotonicity, limit). Prove these
properties also theoretically. Use can use the sequences:

 ∞  ∞  ∞
3n + 2 5−n n+3
, , ,
4n − 3 n=1 2n + 4 n=1 n+2 n=1
 ∞  ∞
2n + 1 2n − 3
, .
3n − 13 n=1 3n + 2 n=1

b) Calculate the rst 1000 terms of an arithmetic sequence {an }∞


n=1 us-
ing parameters a1 , d and n, where a1 is the rst term of this sequence,
th
d is the dierence and n is the index of the n term. Find also a
recurrent formula for this sequence.

c) Calculate the rst 1000 terms of a geometric sequence {an }∞


n=1 using
parameters a1 , q and n, where a1 is the rst term of this sequence,
q is its quotient and n is the index of the nth term. Find also a
recurrent formula for this sequence.

d) Calculate the rst 1000 terms of the Fibonacci sequence given by the
recurrent formula an = an−1 + an−2 , a1 = a2 = 1.
e) Create a new sequence from the Fibonacci sequence using a formula:
n o∞
fn
fn+1 , where fn are the terms of the Fibonacci sequence. What
n=1
are the properties of this new sequence?

2. Properties of sequences
n o∞
a·n+b
a) Calculate the terms and draw a chart of the sequence
c·n+d
n=1
given by the input parameters a, b, c, d. Observe how the properties
of the sequence vary with respect to the values of parameters a, b, c, d.
b) For which values of the input parameters
n o∞ a, b, c, d is the sequence
a·n+b
increasing? For which values is it decreasing? When is
c·n+d
n=1
it (is not) bounded from above/below?
264 CHAPTER 8. SEQUENCES

c) For which values does the sequence have a limit? What is the value
of the limit? How does the sequence approach this limit?

d) Propose a typology of functions according to how their properties


depend on the parameters a, b, c, d.
3. Logistic map
Calculate the terms and draw a chart of the sequence {xn }∞
n=1 given by
the recurrent relation:

xn = a · xn−1 · (1 − xn−1 )
The values of the parameter a are from the interval (0, 4) and the values
of x1 from the interval (0, 1). Calculate at least the rst 5 000 terms of
the sequence and display them in a chart. Examine the behavior of the
sequence in response to changes in parameter a.
4. Operations with sequences
Calculate the rst 100 terms of a sequence {an }∞
n=1 .

a) Calculate the terms of the sequence of partial sums of the original


sequence {an }∞
n=1 , i.e. the sum of terms from the rst to the nth
term.

b) Calculate the dierences of two consecutive terms.

c) Calculate the ratios of two consecutive terms.

d) Calculate the ratio of a term and its index.

e) Calculate the ratio of the sum of the rst n terms and the index n.
Display the original sequence and the new sequences together in a chart.
Try this for various sequences {an }∞
n=1 and observe the properties of se-
1 n

quences a) to e). How do the partial sums look for the sequence ?
n 2
1
How do they look for the sequence ? And how do they look for a
10
geometric sequence in general?
Consider the sequence
 n
1
1+ .
n
Is it bounded? Does it have a limit?
Examine the sequence
 
1
n!
and the sequence of its partial sums.
8.4. LAB PROBLEMS 265

5. Iterative calculation of π and e


a) Iteratively calculate approximate values of π as a ratio of the cir-
cumference and diameter of a regular n-sided polygon for increasing
n.
b) Create a similar Excel sheet for calculation of e using compound
interest rates, when we add the yearly 100% interest in two 50% sums,
three 33.3333% sums, four 25% sums, etc. Transform this problem
into a problem with power function. What is the connection of this
problem to previous problems?
266 CHAPTER 8. SEQUENCES

8.4.1 Hints and solutions


1. Drawing sequences
Hints:

a) To get an idea of how the terms of a sequence look like, we draw it in a


n o∞
a·n+b
chart. It is useful to create an Excel sheet for a sequence
c·n+d
n=1
so that we have the sequence parametrised by four values a, b, c
and d. There should be innitely many values of the independent
variable n, but of course, we will only use a (large) nite number,
e.g. 1, 2, 3, . . . , 1000. Then we calculate the value of a general an .
Note that even if we draw the sequence as individual points, if there
are suciently many of them, they will look like a continuous line.
The graphs of the sequences will be dierent for dierent values of
parameters a, b, c and d.
If we wanted to determine the values of parameters for which the
sequences would like we see in Figure 8.3 we could evaluate the ex-
a·n+b
pression
c·n+d for n = 1, n = 2, n = 3 and n = 4. This would give
us a system of four equations with four unknown parameters. We
can also look at the ratio of parameters a and c and observe an in-
teresting rule. Similarly, we can try dierent values of parameters to
determine their impact on monotonicity.

b) First, we should designate two cells as input cells for the parameters
a1 and d. {an }∞
Then we can calculate the values of the sequence n=1
by using the closed form formula involving the current value of n and
xed values of a1 and d. Next to it, we can calculate the terms of
the sequence using a recurrent formula, i.e. using the previous term
of the sequence and the parameter d. If we do not make en error, the
two columns with the sequence terms should be identical.

c) Again, we can rst designate the input cells for the parameters a1
and q. Then we can calculate the values of the sequence by using the
closed form formula involving the current value of n and xed values
of a1 and q. Next to it, we can calculate the terms of the sequence
using a recurrent formula. Also in this case, we should obtain two
identical columns.

d) The graph of the Fibonacci sequence is shown in Figure 8.4.


8.4. LAB PROBLEMS 267

n o∞
a·n+b
Figure 8.3: Graphs of the sequence for dierent values of parame-
c·n+d
n=1
ters a, b, c, d.

Figure 8.4: Fibonacci sequence, rst 1000 terms and rst 16 terms.

e) Using the Fibonacci sequence, we create a new sequence

 ∞
fn
,
fn+1 n=1

where fn are the original Fibonacci terms. From a graph, Figure 8.5,
we see that this sequence is neither increasing, nor decreasing. It has

a limit
1− 5
2 , which is known as the golden ratio.
268 CHAPTER 8. SEQUENCES

Figure 8.5: Golden ratio.

2. Properties of sequences
Hints:
• Similarly to the previous problem, we start with parameters
n o∞ a, b, c, d
a·n+b
that can vary and create and draw a sequence using
c·n+d
n=1
an independent variable n. First, try varying only one of the four
parameters at a time and observe the resulting changes in the graph.
Then try changing two parameters at the same time. Examine which
parameters have impact on which properties of the sequence.

• If we try for example a = 2, b = 1, c = 0, d = 1, we see that the


sequence is not bounded from above and has an improper limit ∞.
Using the same parameters a = 2, b = 1, c = 0 and changing d to
d = −1, we get a sequence that is not bounded from below with
improper limit −∞. We get the same properties for parameters a=
4, b = 1, c = 0, d = −2.
We see that not only the specic values of parameters impact the
sorting of sequences into categories, but (and perhaps even more so)
the ratios between them.

3. Logistic map
Hints: We create a sheet in which we calculate the values of a sequence
given by a recurrent formula xn = a · xn−1 · (1 − xn−1 ) for parameters
a ∈ (0, 4) and x1 ∈ (0, 1). The change of sequence behavior is much more
interesting when we change the parameter a compared to changes in x1 .
Solution: As a increases, the sequence loses its limit but has a growing
number of subsequences that have limits (we call these numbers accumu-
8.4. LAB PROBLEMS 269

lation points ). Figure 8.6 shows the sequences with two and four accumu-
lation points.

Figure 8.6: Logistic map with parameters x1 = 0.2, a = 3.1 (left) has two
accumulation points, with parameters x1 = 0.2, a = 3.46 (right) has four accu-
mulation points.

If we wanted to investigate the accumulation points, we could split the


sequence into subsequences by picking every other term (into the next
column and separate chart) in case of two accumulation points. Similarly,
we could split the terms into four subsequences in case of four accumula-
tion points.

For even larger values of a we observe chaos, Figure 8.7. For almost all
a > 3.6 we no longer see regular oscillations and even a slight change in
x1 yields dramatically dierent results.

Figure 8.7: Logistic map with parameters x1 = 0.2, a = 3.8.


270 CHAPTER 8. SEQUENCES

4. Operations with sequences


Hints:
• It is useful to calculate each new sequence (dierence, ratio, partial
sums, etc.) in a separate column.

• Dierences and ratios are primarily interesting for the arithmetic and
geometric sequences.

• The sequence of partial sums grows rapidly and thus forces an in-
crease in the range displayed on the y -axis. The behavior of the other
sequences cannot be clearly seen then. Therefore it might be useful
to remove it from the graph when observing the other sequences or
perhaps create a separate graph for it.

Solution: An example sequence and the new sequences created from it are
shown in Figure 8.8.

5. Iterative calculation of π and e


a) Solution: Since we can approximate a circle using a regular polygon
with n-sides, we can approximate the value of π using either the area
or circumference of this polygon. If we use polygons inscribed into a
circle, we get an approximation from below, if we use circumscribed
polygons, we get an approximation from the above, Figure 8.9. The
larger the n, the better the approximation.

To calculate the circumference of a unit circle (r = 1), we use the


formula O = 2π · r. The circumference of an equilateral triangle ap-
proximates (albeit badly) this quantity. To nd out the circumference
of the triangle, we can draw and measure it. This is what Archimedes
of Syracuse did approximately 250 years AD. He inscribed and cir-
cumscribed a regular 96-sided polygon to the circle.

German-Dutch mathematician Ludolph van Ceulen repeated this cal-


culation in 1596 with higher precision and obtained an approximation
of π which is correct up to the rst 20 digits. Is it possible to nd
out what polygon he used? And what was the error of Archimedes'
approximation?

In Excel, we calculate the circumference of a regular n-sided polygon


inscribed in a circle for n from 3 to 100 (or more if necessary). For
that we use the sine function, inner angle of the regular polygon
and the radius of the circle r = 1. The calculation also uses the
8.4. LAB PROBLEMS 271

 ∞
Figure 8.8: The sequence n2 − 5
n=1
, dierences and ratios of its successive
terms, partial sum and a ratio of the partial sum to the index.

Excel value of π which, of course, was not available for Archimedes


or Ludolph, but we are not looking for the value of π , but rather how
well can we approximate this value by a precise drawing.

The size of the angle α, see Figure 8.10, in a regular polygon is α = 2n
x
and the sine of this angle is sin(α) =
r . The circumference of the
polygon is then

 
2π π
On = n · 2 · x = n · 2 · sin = 2 · n · sin .
2n n

With growing n, the circumference of the polygon On approaches the


circumference of the circle Oc .
π
On = 2 · n · sin , Oc = 2 · π · r
n
272 CHAPTER 8. SEQUENCES

Figure 8.9: Iterative approximation of π using a regular polygon with n sides.


The inscribed polygons lead to an approximation from below, the circumscribed
polygons lead to the approximation from above.

Figure 8.10: Relationship of the side length of a regular n-sided polygon and a
unit circle circumscribed to this polygon.

The approximation of π can thus be calculated from

On
π= .
2
The dierence of the approximation and π is the approximation error.
(In Excel, π can be evaluated using the function =PI().)

Using a table shown in Figure 8.11, it can be shown that the ap-
proximation error in case of regular 22-sided polygon is 0.010666212.
Regular 96-sided polygon gives the error 0.000560702, which means
the rst four digits of the approximation are correct.
8.4. LAB PROBLEMS 273

Figure 8.11: The side length of a regular polygon with n sides, which is inscribed
in a circle, calculated using a sine function. The table also shows the iterative
approximations of the value of π and the approximation error.

b) Solution: Figure 8.12 shows how we can use the cumulative interest
rates to iteratively approximate the value of the Euler number e.

Figure 8.12: Calculating the nal balance for more frequent addition of the
compound interest.
274 CHAPTER 8. SEQUENCES
Chapter 9

Sums and products

9.1 Lecture overview

9.1.1 Sums
Notation for sums
Let a1 , a2 , . . . , an ∈ R, we then write

n
X
a1 + a2 + . . . + an = ai
i=1

More generally: If a1 , a2 , . . . , an ∈ R, we then write

l
X
ak + ak+1 + ak+2 + . . . + al = ai
i=k

Some examples of using this notation are:

6
P
• 1+2+3+4+5+6= i
i=1

5 4
(2j + 1) = 25 = 52
P P
• 1+3+5+7+9= (2i − 1) =
i=1 j=0

7
(2i − 1) = 1 + 3 + 5 + 7 + 9 + 11 + 13 = 49 = 72
P

i=1

275
276 CHAPTER 9. SUMS AND PRODUCTS

Sums of rst n numbers with given property


Using mathematical induction (Section 12.1.2), it can be proven that the sum
of the rst n odd numbers is

n
X
(2i − 1) = n2
i=1

The formula for the sum of the rst n natural numbers can be proven using the
Pythagorean method with little pebbles arranged in a triangle or a Gaussian
method by adding two opposite rows of numbers:

n
X n · (n + 1)
i=
i=1
2

The following formula for the sum of the rst n squares can also be proven by
induction:

n
X n · (n + 1) · (2n + 1)
i2 = 1 + 4 + 9 + 16 + 25 + · · · + n2 =
i=1
6

Problem 9.1 Sum of the rst 100 numbers:


Calculate 1 + 2 + 3 + 4 + . . . + 100 =
100
Solution: 1 + 2 + 3 + 4 + . . . + 100 = 100·101
P
i= 2 = 5050
i=1

Problem 9.2 Sum of even numbers up to 100:


Calculate 2 + 4 + 6 + 8 + . . . + 100 =
50
Solution:
P
2i = 2 + 4 + 6 + 8 + . . . + 100 = 2 · (1 + 2 + 3 + 4 + . . . + 50) =
i=1
50
i = 2 50·51
P
2 2 = 2550. Here we showed that
i=1

50
X 50
X
2i = 2 i.
i=1 i=1

Problem 9.3 Sum that does not start at the beginning:


Evaluate 51 + 52 + 53 + 54 + . . . + 100 =
9.1. LECTURE OVERVIEW 277

100
Solution: 51 + 52 + 53 + 54 + . . . + 100 =
P
i = (50 + 1) + (50 + 2) + (50 +
i=51
3) + (50 + 4) + . . . + (50 + 50) =

50 50
X X 50 · 51
= (50 + i) = 50 · 50 + i = 50 · 50 + = 2500 + 1275 = 3775
i=1 i=1
2

Another solution:
100
X 50
X 100
X
i= i+ i
i=1 i=1 i=51

100 100 50
X X X 100 · 101 50 · 51
i= i− i= − = 5050 − 1275 = 3775
i=51 i=1 i=1
2 2

Rules for working with sums


n
P
1. c=n·c
i=1

n
P
2. c = (n − k + 1) · c
i=k

n
P n
P
3. c · ai = c · ai
i=1 i=1

n
P n
P
4. c · ai = c · ai
i=k i=k

n
P k
P n
P
5. ai = ai + ai
i=1 i=1 i=k+1

n
P n+k
P
6. ai = ai−k
i=1 i=1+k

n
P n
P n
P
7. (ai + bi ) = ai + bi
i=1 i=1 i=1
278 CHAPTER 9. SUMS AND PRODUCTS

9.1.2 Products
Notation for products
6
Y
1·2·3·4·5·6= i = 6!
i=1

Some examples of using this notation are:

6
2i = 26 · 6!
Q
• 2 · 4 · 6 · 8 · 10 · 12 =
i=1

• One possible explanation for 0! = 1

4! 3! 2! 1!
4! = 4 · 3! ⇒ 3! = ⇒ 2! = ⇒ 1! = ⇒ 0! = ⇒ 0! = 1
4 3 2 1

7
Q
7 i
1·2·3·4·5·6·7 7!
Q i=1
• i=4·5·6·7= 1·2·3 = 3
Q
= 3!
i=4 i
i=1

Rules for working with products


n
c = cn
Q
1.
i=1

n n
c · i = cn i = cn · n!
Q Q
2.
i=1 i=1

n
Q n+k
Q
3. i= (i − k)
i=1 i=1+k

k
Q n
Q n
Q
4. i· i= i
i=1 i=k+1 i=1

k
Q k
Q k
Q
5. (ai bi ) = ai · bi
i=1 i=1 i=1
9.1. LECTURE OVERVIEW 279

9.1.3 Double sums/products


In the following problems, we use these two nite sequences:

{an }5n=1 = {2, 5, 8, 11, 14}, {bm }3m=1 = {3, 6, 12}

Problem 9.4 Double sum:


5
P 3
P
Evaluate an bm in two dierent ways.
n=1 m=1

Solution:
3
5 X 5
! 3
!
X X X
an bm = an bm = (2 + 5 + 8 + 11 + 14)(3 + 6 + 12)
n=1 m=1 n=1 m=1
5 X
X 3 5 X
X 3 5
X
an bm = (an bm ) = (3an + 6an + 12an )
n=1 m=1 n=1 m=1 n=1
= 3 · 2 + 6 · 2 + 12 · 2 + 3 · 5 + 6 · 5 + 12 · 5 + . . .

Problem 9.5 Sum of products:


Only one of the following calculations is correct. Which one? How can be the
incorrect one corrected?

5 Y
3 5
! 3
!
X X Y
an bm = an bm = (2 + 5 + 8 + 11 + 14)(3 · 6 · 12)
n=1 m=1 n=1 m=1
X 3
5 Y X 3
5 Y 5
X
an bm = (an bm ) = (3an · 6an · 12an )
n=1 m=1 n=1 m=1 n=1
= 3 · 2 · 6 · 2 · 12 · 2 + 3 · 5 · 6 · 5 · 12 · 5 + . . .

Problem 9.6 Product of sums:


Only one of the following calculations is correct. Which one?

5 X
3 5
! 3
!
Y Y X
an bm = an bm = (2 · 5 · 8 · 11 · 14)(3 + 6 + 12)
n=1 m=1 n=1 m=1
5 X
Y 3 5 X
Y 3 5
Y
an bm = (an bm ) = (3an + 6an + 12an )
n=1 m=1 n=1 m=1 n=1
= (3 · 2 + 6 · 2 + 12 · 2)(3 · 5 + 6 · 5 + 12 · 5) · . . .
280 CHAPTER 9. SUMS AND PRODUCTS

Problem 9.7 Double product:


Only one of the following calculations is correct. Which one?

5 Y
3 5
! 3
!
Y Y Y
an bm = an bm = (2 · 5 · 8 · 11 · 14)(3 · 6 · 12)
n=1 m=1 n=1 m=1
5 Y
Y 3 5 Y
Y 3 5
Y
an bm = (an bm ) = (3an · 6an · 12an )
n=1 m=1 n=1 m=1 n=1
= (3 · 2 · 6 · 2 · 12 · 2)(3 · 5 · 6 · 5 · 12 · 5) · . . .

9.1.4 Geometric sequence and series


Problem 9.8 Finite chocolate:
Five friends eat chocolate in such a way that the rst one eats half of it and
each next friend eats half of what was left. How much chocolate remains after
they all had their shares?

Solution: In the end there is


1 31
32 of the chocolate and they ate 32 :
1 1 1 1 1 1 31
+ + + + =1− =
2 4 8 16 32 32 32
More generally for n friends:
n
X 1 2n − 1
=
i=1
2i 2n

Sum of nite geometric series


Suppose the rst term of the series is 1 and quotient is q. The sum of the series
is then

Sn = 1 + q + q2 + q3 + . . . + qn
q · Sn = q + q 2 + q 3 + . . . + q n + q n+1
Sn − q · Sn = 1 − q n+1
1 − q n+1
Sn = , q 6= 1
1−q
Problem 9.9 Innite chocolate:
What happens when we extend the nite chocolate series from Problem 9.8 and
have innitely many friends?
9.1. LECTURE OVERVIEW 281

Solution: We get the sum

1 1 1 1 1
+ + + + + . . . = 1.
2 4 8 16 32
Problem 9.10 Achilles and turtle:
The ancient Greek hero Achilles runs 10 times faster than a turtle. The turtle
gets a head start of 1km. Every time Achilles gets to the place where the turtle
1
was in the previous step, the turtle covers
10 of the distance Achilles does. Will
he catch the turtle or not? (This paradox belongs to the Zenon's aporias.)

Solution: The ancient Greeks considered this problem long and hard. The
crucial idea is that a nite length can be expressed as a sum of an innite
number of shorter and shorter parts. Even though we can keep on telling the
race story indenitely, Achilles catches the turtle after 10/9 km. This can be
calculated using the sum of geometric series with the rst term 1 and a quotient
1
10 .

1 1 1
1+ + + + ... = S
10 100 1000
1 1
10 + 1 + + + ... = 10S
10 100
10 + S = 10S
10 = 9S
10
S =
9

Sum of innite geometric series


This sum depends on the limit of the corresponding sequence:

lim q n = 0 for |q| < 1


n→∞
= 1 for q=1
= ∞ for q>1
= does not exist for q = −1
= does not exist for q < −1
When the rst term of the series is 1 and quotient is |q| < 1:
n
X 1 − q n+1 1
lim Sn = lim q i = lim =
n→∞ n→∞
i=0
n→∞ 1−q 1−q
282 CHAPTER 9. SUMS AND PRODUCTS

Similarly when the rst term is a0 and quotient is |q| < 1:


n
X 1 − q n+1 1
lim a0 · Sn = lim a0 · q i = lim a0 · = a0 ·
n→∞ n→∞
i=0
n→∞ 1−q 1−q

If we use this approach with unsuitable q (e.g. with q = 10, q = 20, q = 100
or other cases when the series do not have a nite sum), we get an incorrect
answer.

Problem 9.11 Periodic numbers:


How much is 0.9?

Solution:
1
0.9 = 3 · 0.3 = 3 ·
3  
9 1 1
= 0.9 + 0.09 + 0.009 + . . . = · 1+ + + ...
10 10 100
9 1 9 10
= · 1 = · =1
10 1 − 10 10 9

Geometric series we can now evaluate


1.

X 1
q n = (1 + q + q 2 + q 3 + . . .) =
n=0
1−q

2.

X 1
a0 · q n = a0 · (1 + q + q 2 + q 3 + . . .) = a0 ·
n=0
1−q

3.


X qk
q n = (q k + q k+1 + q k+2 + . . .) = q k (1 + q + q 2 + . . .) =
1−q
n=k

4.

X 1 1
(−q)n = (1 − q + q 2 − q 3 + q 4 − . . .) = =
n=0
1 − (−q) 1+q
9.1. LECTURE OVERVIEW 283

5.

X 1
q 2n = (1 + q 2 + q 4 + q 6 + . . .) =
n=0
1 − q2
284 CHAPTER 9. SUMS AND PRODUCTS

9.2 Questions

1. State the formula for the sum of rst n natural numbers. How much is
1 + 2 + 3 + 4 + . . . + 98 + 99?
2. State the formula for the sum of rst n odd numbers. How much is
1 + 3 + 5 + 7 + . . . + 33?
3. State the formula for the sum of rst n squares. How much is 1+4+9+
16 + . . . + 64?
5
P
4. Express (ai+1 − ai ) using two numbers.
i=1

5. Let ak be the k th term of the geometric sequence, where a1 = 7 and


7
P
q = 1/7. Calculate ak
k=1

6. Calculate 4! =, 3! + 3! =, 4! · 4! =, 0! =, (2 · 3)! =, 1! =
7. Calculate

5
Q
a) 2k
k=1
5
k2
Q
b)
k=1

8. Express the following using factorials

1
Q
a) 5k
k=3
5
Q
b) 3k
k=1

9. Suppose we divide a chocolate in two halves, eat one and leave the other
for next day. The next day we repeat the process with the half and so
on. The last piece we eat was 1/128 of the original chocolate. How many
pieces have we eaten? What part of original chocolate was it? How many
days do we need until the remaining piece of chocolate is one molecule?

10. Calculate the sum of geometric series with quotient q = 1/6. Use the
assumption that the sum S exists.
9.2. QUESTIONS 285

11. Calculate the sum of geometric series with quotient q = −1/6. Use the
assumption that the sum S exists.

12. Calculate the sum of geometric series with quotient q = 6. Use the as-
sumption that the sum S exists.

13. Express as innite series and evaluate

a) 1.1111̄
b) 9.999999̄
c) 3.3333̄

qk ?
P
14. How do we calculate
k=0
286 CHAPTER 9. SUMS AND PRODUCTS

9.3 Problem set

Sums
P
1. Write the following expressions using the notation:

a) 1 + 2 + 3 + . . . + 20
b) 7 + 14 + 21 + . . . + 70
c) 6 + 8 + 10 + . . . + 6n
d) 12n + 12n + 6 + 12n + 12 + 12n + 18 + . . . + 24n
n
P n(n + 1)
2. Using i= calculate
i=1 2
10
P n
P
a) 4i, 4j
i=1 j=1
100
P 2n
P
b) 3k , 3k
k=1 k=1
25
P 3n
P
c) 5, 2i
t=1 i=5
16
P 2n
P
d) i, j
i=8 j=n
3n
P 4n
P
e) 2k , 6t
i=2n t=2n

n
(2i − 1) = n2
P
3. Using calculate
i=1

3n
P
a) (2j − 1)
j=1
n
P
b) 4(2i + 1)
i=0
4n
P
c) (2k − 1)
k=2n
9.3. PROBLEM SET 287

4. Split into two sums and calculate

n
P
a) (4i + 3)
i=1
3n
P
b) (2j − 1)
j=1
2n
(−1)k 3k
P
c)
k=1

5. Calculate

20
P
a) (k + 2)
k=1
100
(−1)i i
P
b)
i=1
n
P
c) (4k + 1)
k=1
Pn
d) 2k
k=4
2n
P
e) (2k − 1)
k=n

Products
n
Q
6. Denote the product i as n! Using this notation, multiplication, division,
i=1
etc., simplify the following expressions:

n
Q
a) (4i)
i=1
4n
Q
b) j
j=2n
n 4+i
Q
c)
i=1 i + 2
n j−5
Q
d)
j=1 j + 2
3n k + 6
Q
e)
k=n k
288 CHAPTER 9. SUMS AND PRODUCTS

n
Q
f) (3i + 2)(3i + 1)
i=1
n
Q
g) (4j − 1)(4j + 1)
j=1
n (4i − 3)(4i + 3)
Q
h)
i=1 4i

Geometric series
n
2i = 2n+1 − 1
P
7. Using calculate
i=0

20
2j
P
a)
j=10
2n
2k
P
b)
k=n
3n
(2i · 3)
P
c)
i=3

8. Calculate the sums of nite geometric series:

10 20 99 n
1 j 2 j
 
3i , 7i ,
P P P P
a)
3 , 3
i=0 j=1 i=1 j=20
10 20 j 99 n j
(−3)i , − 13 (−7)i , − 32
P P P P
b) ,
i=0 j=1 i=1 j=20
6 10 2k 3n
1 j 1 j
 
10i , 10i ,
P P P P
c)
2 , 2
i=4 j=1 i=k j=2n
6 10 j 2k 3n j
(−10)i , − 12 (−10)i , − 12
P P P P
d) ,
i=4 j=1 i=k j=2n

9. Calculate the sums of innite geometric series:

∞ ∞ ∞ ∞
1 i
j 5 i
j
− 52 − 23
P  P P  P
a)
3 , ,
7 , ,
i=0 j=1 i=4 j=30
∞ ∞ j ∞
j
qi , a2
P P P
b) , (−b) ,
i=2 j=1 j=k
9.3. PROBLEM SET 289

∞ ∞ ∞
1 j
j j
− 27

−b3
P P P
c)
2 , ,
j=2n j=1 j=k2

Double sums and products


10. Letan be the nth term of the geometric sequence, where a1 = 4 and q = 2.
th
Let bk be the k term of arithmetic sequence, where b1 = 3 and d = 1.
Check whether the following equality holds:

X 2
3 X 3
X 2
X
(an · bk ) = ( an ) · ( bk )
n=1 k=1 n=1 k=1

11. Letan be the nth term of the geometric sequence, where a1 = 4 and q = 2.
th
Let bk be the k term of arithmetic sequence, where b1 = 3 and d = 1.
Check whether the following equality holds:

X 2
3 X 3
X 2
X
(an /bk ) = ( an )/( bk )
n=1 k=1 n=1 k=1

12. Letan be the nth term of the geometric sequence, where a1 = 4 and q = 2.
th
Let bk be the k term of arithmetic sequence, where b1 = 3 and d = 1.
Check whether the following equality holds:

3 X
X 2 3
X 2
X
(an + bk ) = an + bk
n=1 k=1 n=1 k=1

13. Letan be the nth term of the geometric sequence, where a1 = 4 and q = 2.
th
Let bk be the k term of arithmetic sequence, where b1 = 3 and d = 1.
Check whether the following equality holds:

2 X
Y 3 3 Y
X 2
(an + bk ) = (an + bk )
k=1 n=1 n=1 k=1

14. Write out the terms of the double sums and calculate their values. Which
results are the same and why?

5 X
X 4 5 X
X 6 6
X 3
X 3
X 8
X
i·j, (i+1)(j+2), (i−1) (j+1), (i+3) (j−1)
i=1 j=1 i=2 j=3 i=2 j=0 i=0 j=5
290 CHAPTER 9. SUMS AND PRODUCTS

15. Write out and compare the terms of the two expressions. Are they the
same?
" #
5
P 6
P 5
P 6
P
a) (ai · bj ) and ai bj
i=1 j=3 i=1 j=3
" #
5
P 10
P 10
P 6
P
b) (ci · dj ) and di+1 cj−1
i=3 j=7 i=6 j=4

16. Write out the terms of these expressions and transform them into a prod-
uct of two sums:

X 3
8 X 6 X
X 4 10
X 4
X
a) ci · dj , b) ui · vj , c) (k − 2) (j + 2),
i=4 j=0 i=2 j=3 k=6 j=1

17. Write out the terms, calculate and compare

8 Y
X 5 8
X 5
Y
(i + 2)j and (i + 2) j
i=5 j=3 i=5 j=3
9.3. PROBLEM SET 291

9.3.1 Hints and solutions


Sums
P
1. Write the following expressions using the notation:

a) 1 + 2 + 3 + . . . + 20
b) 7 + 14 + 21 + . . . + 70
c) 6 + 8 + 10 + . . . + 6n
d) 12n + 12n + 6 + 12n + 12 + 12n + 18 + . . . + 24n

Hints :
P
• It is straightforward to use the notation when the two successive
terms in the expression dier by +1.
• If the +1 dierence is not apparent, we can consider whether the
terms have a common divisor. If so, we can factor the divisor out of
all terms.

• In some cases it might be possible to write the sum several dierent


ways.

• Sometimes, e.g. in d), it is helpful to rearrange the order of terms.

Solution:
20
P
a) 1 + 2 + 3 + . . . + 20 = i
i=1
10
P
b) 7 + 14 + 21 + . . . + 70 = 7 · (1 + 2 + 3 + . . . + 10) = 7i
i=1
3n
P
c) 6 + 8 + 10 + . . . + 6n = 2 · (3 + 4 + 5 + . . . + 3n) = 2i
i=3
d) 12n + 12n + 6 + 12n + 12 + 12n + 18 + . . . + 24n =
= 6 · (2n + 2n + 1 + 2n + 2 + 2n + 3 + . . . + 4n) =
4n
P
= 6 · (2n + [2n + 1] + [2n + 2] + [2n + 3] + . . . + 4n) = 6i
i=2n

n
P n(n + 1)
2. Using i= calculate
i=1 2
292 CHAPTER 9. SUMS AND PRODUCTS

10
P n
P
a) 4i, 4j
i=1 j=1
100
P 2n
P
b) 3k , 3k
k=1 k=1
25
P 3n
P
c) 5, 2i
t=1 i=5
16
P 2n
P
d) i, j
i=8 j=n
3n
P 4n
P
e) 2k , 6t
i=2n t=2n

Hints :
4
P
• A constant can be factored out from the sum, e.g. 3i = 3 + 6 +
i=1
4
P
9 + 12 = 3 · (1 + 2 + 3 + 4), which can be written as 3· i.
i=1
• The formula for addition of the rst n natural numbers starts at 1. If
the sum we are trying to calculate does not start at 1, we can either
n
P n+k
P
shift the bounds using the rule ai = ai−k or use the fact
i=1 i=1+k
n
P k−1
P n
P
that ai = ai + ai .
i=1 i=1 i=k
• When shifting the bounds, we need to also adjust the index in the
sum. For example if the original sum was from 3n to 6n, then by
subtracting 3n and adding 1 to both bounds, we adjust the lower
bound to 1. To adjust the iteration index inside the sum accordingly,
we need to add 3n and subtract 1. This way we are still adding
6n
P
the same terms as before. The whole transformation is 3i =
i=3n
3n+1
P
3(i + 3n − 1).
i=1
For verication, it is always a good idea to check the rst few terms
before and after the transformation. In both cases we have to get the
6n
P
same results. In our example, 3i, this would be a1 = 3 · 3n = 9n
i=3n
9.3. PROBLEM SET 293

3n+1
P
and after the transformation to 3(i + 3n − 1) we get a1 = 3(1 +
i=1
3n − 1) = 9n .

• In case the iteration variable in the sum does not correspond to the
variable indices, e.g. the rst problem in part e), it is constant with
respect to the sum and can be factored out.

Solution:
10
P
a) 4i = 4 + 8 + 12 + . . . + 40 = 4 · (1 + 2 + 3 + . . . + 10) =
i=1
10(10 + 1)
=4· = 220
2
Pn n(n + 1)
4j = 4 + 8 + 12 + . . . + 4n = 4 · = 2n(n + 1)
j=1 2
100
P 100
P 100 · 101
b) 3k = 3 · k =3·
k=1 k=1 2
P2n 2n(2n + 1)
3k = 3 · (1 + 2 + 3 + . . . + 2n) = 3 ·
k=1 2
25
P
c) 5 = 5 · 25 = 125
t=1
3n
P
In 2i the sum does not start from 1. We show two ways how we
i=5
can deal with that.

First method: We add the missing nite series and then we subtract
it, i.e. we add a cleverly written 0 to the whole series.

3n
P 3n
P 4
P 4
P 3n
P 4
P
2i = 2i + 2i − 2i = 2i − 2i =
i=5 i=5 i=1 i=1 i=1 i=1
3n(3n + 1) 4(4 + 1)
2· −2· = 3n(3n + 1) − 20 = 9n2 + 3n − 20
2 2
Second method: We shift the lower bound to i = 1. With that
we also have to shift the upper bound and apply the corresponding
change to the iteration index. In the next step, we split the sum into
two sums.
294 CHAPTER 9. SUMS AND PRODUCTS

3n
P 3n−4
P 3n−4
P 3n−4
P
2i = 2(i + 4) = 2i + 8=
i=5 i=1 i=1 i=1
(3n − 4)(3n − 3)
=2 + 8(3n − 4) = 9n2 + 3n − 20
2
2n
P 2n
P n−1
P 2n(2n + 1) (n − 1)n 3n
d) j= j− j= − = (n + 1)
j=n j=1 j=1 2 2 2
3n
P 3n
P
e) 2k = 2k 1 = 2k(n + 1)
i=2n i=2n
4n
P 2n+1
P 2n+1
P 2n+1
P
6t = 6(t + 2n − 1) = 6t + 6(2n − 1) =
t=2n t=1 t=1 t=1
(2n + 1)(2n + 2)
=6 + 6(2n − 1)(2n + 1) = 18n(2n + 1)
2
n
(2i − 1) = n2
P
3. Using calculate
i=1

3n
P
a) (2j − 1)
j=1
n
P
b) 4(2i + 1)
i=0
4n
P
c) (2k − 1)
k=2n

Hints :
• The given formula (sum of the rst n odd numbers) starts with 1.
If we want to use it for other problems that involve odd numbers or
their multiples, we need to be careful about the indices.

• The problems can also be solved without using the formula, just by
splitting the sum into two sums.

Solution:
a) First method: Using the formula for addition of the rst n odd num-
bers.
3n
(2j − 1) = (3n)2
P
j=1
9.3. PROBLEM SET 295

Second method: Splitting the sum.


3n 3n 3n
1 = 3n(3n + 1) − 3n = 9n2
P P P
(2j − 1) = 2j −
j=1 j=1 j=1
n n+1 n+1
4(2i − 1) = 4(n + 1)2
P P P
b) 4(2i + 1) = 4(2(i − 1) + 1) =
i=0 i=1 i=1
4n
P 2n+1
P 2n+1
P 2n+1
P
c) (2k − 1) = (2(k + 2n − 1) − 1) = 2k + (4n − 3) =
k=2n k=1 k=1 k=1

= (2n + 1)(2n + 2) + (4n − 3)(2n + 1) = (2n + 1)(6n − 1)

4. Split into two sums and calculate

n
P
a) (4i + 3)
i=1
3n
P
b) (2j − 1)
j=1
2n
(−1)k 3k
P
c)
k=1

Hints :
• We can split a sum into two sums using the rule
n
P n
P n
P
(ai ± bi ) = ai ± bi
i=1 i=1 i=1
• If it is not clear at the rst glance how to split the sum into two sums,
e.g. in problem c), it might help to write out the rst few terms.

Solution:
n n n 1
3 = 4 n(n + 1) + 3n = 2n2 + 5n
P P P
a) (4i + 3) = 4i +
i=1 i=1 i=1 2
3n 3n 3n
1 = 3n(3n + 1) − 3n = 9n2
P P P
b) (2j − 1) = 2j −
j=1 j=1 j=1
2n  
(−1)k 3k = 3 −1 + 2 − 3 + 4 − 5 + . . . + (−1)2n 2n =
P
c)
k=1

= 3 [(−1 − 3 − 5 − . . . − (2n − 1)) + (2 + 4 + 6 + . . . + 2n)] =


296 CHAPTER 9. SUMS AND PRODUCTS

1
= −3n2 + 3 · 2 n(n + 1) = 3n
2
5. Calculate the sums

Solution:
20
P 20
P 20
P 20 · 21
a) (k + 2) = k+2 1= + 2 · 20
k=1 k=1 k=1 2
100
(−1)i i = −1 + 2 − 3 + 4 − 5 + 6 + . . . + 100 =
P
b)
i=1
= (−1 − 3 − 5 − . . . − 99) + (2 + 4 + 6 + . . . + 100) =
= −1(1 + 3 + 5 + . . . + 99) + 2(1 + 2 + 3 + . . . + 50) =
50 · 51
= −(50)2 + 2 = 100
2
n n n n(n + 1)
+ n = 2n2 + 3n
P P P
c) (4k + 1) = 4k + 1=4
k=1 k=1 k=1 2
Pn n−3
P (n − 3)(n − 2)
d) 2k = 2 (k + 3) = 2 + 6(n − 3) = (n − 3)(n + 4)
k=4 k=1 2
2n
P 2n−n+1
P n+1
P
e) (2k − 1) = (2(k + n − 1) − 1) = (2k + 2n − 3) =
k=n k=1 k=1
(n + 1)(n + 2)
=2 + (2n − 3)(n + 1) = (n + 1)(3n − 1)
2
Products
n
Q
6. Denote the product i as n! Using this notation, multiplication, divi-
i=1
sion, etc, simplify the following expressions

n
Q
a) (4i)
i=1
4n
Q
b) j
j=2n
n 4+i
Q
c)
i=1 i + 2
n j−5
Q
d)
j=1 j + 2
9.3. PROBLEM SET 297

3n k + 6
Q
e)
k=n k
Qn
f) (3i + 2)(3i + 1)
i=1
n
Q
g) (4j − 1)(4j + 1)
j=1
n (4i − 3)(4i + 3)
Q
h)
i=1 4i

Hints :
• With the products, it is very useful to write out the individual terms
(few from the beginning and few from the end), check if we see any
factorials and perhaps multiply by suitable terms to get a factorial
if anything is missing. For example, if we write out the product
10
Q
i = 5 · 6 · 7 · 8 · 9 · 10, we see that we could have 10! if we also had
i=5
4!
1 · 2 · 3 · 4 = 4!. Therefore we can multiply the product by
4! to get
10!
4! .
• An expression can be simplied by factoring out a common divisor,
but we have to remember its multiplicity, e.g. in the product of the
rst n even numbers we have:

n
Y n
Y
(2i) = 2 · 4 · 6 · 8 · . . . · 2n = 2n (1 · 2 · 3 · 4 · . . . · n) = 2n i = 2n n!
k=1 k=1

• If we wanted to calculate the product of the rst n odd numbers, we


can use the result for the even numbers

n
Y 1 · 2 · 3 · 4 · . . . · 2n (2n)!
(2i − 1) = 1 · 3 · 5 · 7 · . . . · (2n − 1) = = n
2 · 4 · 6 · 8 · . . . · 2n 2 n!
k=1

Solution:
n
4i = 4 · 1 · 4 · 2 · 4 · 3 · 4 · 4 · . . . · 4 · (n − 1) · 4 · n = 4n n!
Q
a)
i=1
4n
Q (4n)!
b) j = 2n · (2n + 1) · (2n + 1) · (2n + 1) · . . . · (4n − 1) · 4n =
j=2n (2n − 1)!
298 CHAPTER 9. SUMS AND PRODUCTS

c) When we write out this product, we see that the numerator is almost
(4+n)! What is missing is 4! therefore we multiply the whole fraction
4!
by a cleverly written 1 in the form of
4! . Similarly, in the denomina-
tor, we almost have (n + 2)! To get it, we multiply the fraction also
2!
by
2! .
n 4+i
Q 5 6 7 4 + n − 1 4 + n 4! 2! (4 + n)! 2!
= · · ·. . .· · · · = ·
i=1 i + 2 3 4 5 n + 2 − 1 n + 2 4! 2! 4! (n + 2)!
(n+3)(n+4)
= 12
n j−5
Q −4 −3 −2 −1 0 1 n−6 n−5
d) = · · · · · · ... · · =0
j=1 j + 2 3 4 5 6 7 8 n+1 n+2
3n k + 6
Q n+6 n+7 n+8 3n + 5 3n + 6
e) = · · · ... · · =
k=n k 6 7 8 3n − 1 3n
(3n + 6)! 5!
= ·
(n + 5)! (3n)!
Qn
f) (3i + 2)(3i + 1) = 5 · 4 · 8 · 7 · 11 · 10 · . . . · (3n + 2)(3n + 1) =
i=1
5 · 4 · 3 · 8 · 7 · 6 · 11 · 10 · 9 · . . . · (3n + 2)(3n + 1)3n (3n + 2)!
= =
3 · 6 · 9 · . . . · 3n 2!3n n!
n
Q
g) (4j − 1)(4j + 1) = 3 · 5 · 7 · 9 · 11 · 13 · . . . · (4n − 1) · (4n + 1) =
j=1
2 · 3 · 4 · 5 · 6 · 7 · 8 · 6 · . . . · (4n − 1)4n(4n + 1) (4n + 1)!
= = 2n
2 · 4 · 6 · . . . · 4n 2 (2n)!
n (4i − 3)(4i + 3)
Q 1 · 7 5 · 11 9 · 15 (4n − 3)(4n + 3)
h) = · · ... =
i=1 4i 4 8 12 4n
(4n + 3)!
=
(4n + 1) · 3 · 4n n! · 2n n!

Geometric series
n
2i = 2n+1 − 1
P
7. Using calculate
i=0

20
2j
P
a)
j=10
2n
2k
P
b)
k=n
9.3. PROBLEM SET 299

3n
(2i · 3)
P
c)
i=3

Hints :
• The formula is derived from a general formula for sum of nite geo-
metric series using a quotient q = 2.
• When changing the bounds of the index, we need to also change the
exponent. We can use the properties 2a+b = 2a · 2b , 2a−b = 2a · 2−b =
2a
.
2b
• We can also consider the connection of these sums to a binary system.
4
2i = 1+2+4+8+16 =
P
For example for n = 4 we can write the sum
i=0
25 − 1 in binary as:

12 + 102 + 1002 + 10002 + 100002 = 111112 = 1000002 − 12

This gives us a simple rule for consecutive addition of powers of two


2i in binary.

Solution:
a) First method: When we write out the rst few terms, we see that we
can factor out 210 .
20    
2j = 210 +211 +. . .+220 = 210 1 + 2 + 22 + . . . + 210 = 210 211 − 1
P
j=10

Second method: We can shift the lower bound to zero and then
use the formula to calculate the sum
20 10
2j = 2j+10 = 221 − 210
P P
j=10 j=0
2n n  
2k = 2k+n = 2n 2n+1 − 1
P P
b)
k=n k=0
3n 3n 3n−3  
(2i · 3) = 3 · 23 2i−3 = 3 · 23 2i = 3 · 23 23n−2 − 1
P P P
c)
i=3 i=3 i=0

8. Calculate the sums of nite geometric series.

10 20 99 n
1 j 2 j
 
3i , 7i ,
P P P P
a)
3 , 3
i=0 j=1 i=1 j=20
300 CHAPTER 9. SUMS AND PRODUCTS

10 20 j 99 n j
(−3)i , − 13 (−7)i , − 32
P P P P
b) ,
i=0 j=1 i=1 j=20
6 10 2k 3n
1 j 1 j
 
10i , 10i ,
P P P P
c)
2 , 2
i=4 j=1 i=k j=2n
6 10 j 2k 3n j
(−10)i , − 12 (−10)i , − 12
P P P P
d) ,
i=4 j=1 i=k j=2n

Hints :
n
1−q n+1
qk =
P
• The sum of nite geometric series is Sn = 1−q . This
k=0
series Sn starts at k = 0, i.e. Sn has n+1 terms.

• If we want to use this formula directly, the lower bound in the it-
eration index has to be zero. We can achieve this by shifting the
summation indices directly or by factoring out a suitable power of
the quotient q in front of the sum.

• When calculating powers of negative numbers, we need to be careful


about the signs, e.g. in (−1)k we get a positive result for even powers.

Solution:
10 20 19 20
1 1−( 3 )
1 h i
1−311 1 j 1 j+1 1 1 20
  
3i =
P P P
a)
1−3 , 3 = 3 = 3 1− 13 = 2 1− 3
i=0 j=1 j=0
20 j 19 j+1 1−(− 31 )
20 h i
1 20
− 31 − 13 = − 31 = − 14 1 −
P P 
b) = 1+ 13 3 ,
j=1 j=0
6 2
1−103
10i = 10i+4 = 104 · = 104 [1 + 10 + 100] = 111000,
P P
c)
1−10
i=4 i=0
3n n 2n 1−( 12 )n+1 2n h n+1 i
1 j 1 j+2n
= 12 = 2 21 · 1 − 12
P  P 
2 = 2 · 1− 1
j=2n j=0 2

6 3n j h n+1 i
1 2n
− 12 2
1 − − 12

(−10)i = 104 −105 +106 ,
P P
d) = 3 2 ·
i=4 j=2n

9. Calculate the sums of innite geometric series:

∞ ∞ ∞ ∞
1 i
j 5 i
j
− 52 − 23
P  P P  P
a)
3 , ,
7 , ,
i=0 j=1 i=4 j=30
9.3. PROBLEM SET 301

∞ ∞ j ∞
j
qi , a2
P P P
b) , (−b) ,
i=2 j=1 j=k
∞ ∞ ∞
1 j
j j
− 27

−b3
P P P
c)
2 , ,
j=2n j=1 j=k2

Hints :
1
• The sum of the innite geometric series is Sn = 1−q .
• If we need to shift the indices, the upper bound remains ∞.

Solution:

 i
P 1 1 3
a) = 1 = 2
i=0 3 1− 3

 j ∞
 j+1 ∞
 j  1
P 2 P 2 P 2 2 2 1
− = − = − · − =− · 2
j=1 5 j=0 5 j=1 5 5 5 1+ 5

 i  4
P 5 5 1
=
i=4 7 7 1 − 57

∞ 1
qi = q2
P
b)
i=2 1−q
∞ j1
a2 = a2
P
j=1 1 − a2
∞ 1
j
(−b) = (−b)k
P
j=k 1 + b


 j  2n  2n
P 1 1 1 1
c) = · 1 =2
j=2n 2 2 1− 2 2

 j  k 2
P 2 2 1
− = − · 2
j=k 2 7 7 1 − 7

Double sums and products


Hints :
PP PQ
• A double sum or a combination of a sum and a product
n k n k
can be understood as a double cycle in a source code which is sup-
posed to perform a binary operation on terms of two sequences. The
302 CHAPTER 9. SUMS AND PRODUCTS

index n can be the outer index and the index k can be the inner
index.

• First we set the outer index to its lowest value, e.g. n = 1. We also set
the inner index to its lowest value, e.g. k=1 and then subsequently
increment the inner index with step +1 until it covers its whole range.
When it does, we increment the outer index to n = 2 and reset the
inner index to k = 1. We then cycle through the whole range of
k again and then reset it together with incrementing n. We repeat
these steps until the outer index reaches its upper limit.

11. Let an be the nth term of the geometric sequence, where a1 = 4 and q = 2.
th
Let bk be the k term of arithmetic sequence, where b1 = 3 and d = 1.
Check whether the following equality holds:

X 2
3 X 3
X 2
X
(an /bk ) = ( an )/( bk )
n=1 k=1 n=1 k=1

Solution:
2
3 X
X a1 a1 a2 a2 a3 a3
(an /bk ) = + + + + +
n=1 k=1
b1 b2 b1 b2 b1 b2
3 2
X X a1 + a2 + a3
( an )/( bk ) =
n=1
b1 + b2
k=1

⇒ The equality does not hold.

13. Let an be the nth term of the geometric sequence, where a1 = 4 and q = 2.
th
Let bk be the k term of arithmetic sequence, where b1 = 3 and d = 1.
Check whether the following equality holds:

2 X
Y 3 3 Y
X 2
(an + bk ) = (an + bk )
k=1 n=1 n=1 k=1

Solution:
2 X
Y 3
(an + bk ) = (a1 + a2 + a3 + 3b1 )(a1 + a2 + a3 + 3b2 )
k=1 n=1
9.3. PROBLEM SET 303

3 Y
X 2
(an + bk ) = (a1 + b1 )(a1 + b2 ) + (a2 + b1 )(a2 + b2 ) + (a3 + b1 )(a3 + b2 )
n=1 k=1

⇒ The equality does not hold.

17. Write out the terms, calculate and compare

X 5
8 Y 8
X 5
Y
(i + 2)j and (i + 2) j
i=5 j=3 i=5 j=3

Solution:
8 Y
X 5
(i+2)j = 7·3·7·4·7·5+. . .+10·3·10·4·10·5 = 3·4·5·(73 +. . .+103 )
i=5 j=3

8
X 5
Y
(i + 2) j = 7 · 3 · 4 · 5 + . . . + 10 · 3 · 4 · 5 = 3 · 4 · 5 · (7 + . . . + 10)
i=5 j=3

⇒ The equality does not hold.


304 CHAPTER 9. SUMS AND PRODUCTS

9.4 Lab problems

1. Sums and products


Create an Excel sheet with the rst 15 terms of an arithmetic sequence
{an }15
n=1 and rst 10 terms of a geometric sequence {bm }10
m=1 . Calculate:

15
P 10
P
a) an · bm
n=1 m=1
10
P 15
P
b) ( an bm )
m=1 n=1
15
P 10
Q
c) an · bm
n=1 m=1
15
P 10
Q
d) ( (an + bm ))
n=1 m=1
10
Q 15
P
e) ( (an + bm ))
m=1 n=1

Find out which of these expressions give the same result.

2. Geometric series
Prepare an Excel sheet which will contain the rst 100 terms of a geometric
sequence. Do it in such a way that you can vary the quotient of geometric
sequence in one cell. Calculate also the partial sums that correspond to
the terms of this sequence. Find the limit of these partial sums. In the
next column calculate the sum of the rst n terms using the formula.
Compare the results.

For geometric series with quotient less than 1 examine how the partial
sums converge to the limit of the innite sum.

For geometric series with a negative quotient examine the behavior of the
partial sums. How does the behavior change if the absolute value of the
quotient is larger/smaller than 1?

3. The size of an atom


Create an Excel sheet in which you write the rst 1000 values of splitting
a chocolate in half, down to the mass of an atom. Start with a 100 gram
chocolate. How many times can we split the chocolate in half to get a
piece, which has the mass of an atom? The absolute atom mass is at the
order of 10−26 kg (0.00000000000000000000000001kg).
9.4. LAB PROBLEMS 305

4. Distance to Mars
Create an Excel sheet which shows the rst 1000 steps of the journey to
Mars. The length of the rst step is equal to a paper width. The second
step is the thickness of a paper folded in half. The next is the paper folded
in half again and so on. How many times do we need to fold the paper in
half to get the thickness equal to the distance form Earth to Mars?

A regular package of 500 sheets of paper is 5.3cm thick.

The distance to Mars from Earth varies from 55 to 400 million kilometres.
306 CHAPTER 9. SUMS AND PRODUCTS

9.4.1 Hints and solutions


1. Sums and products
Create an Excel sheet with the rst 15 terms of an arithmetic sequence
{an }15
n=1 and rst 10 terms of a geometric sequence {bm }10
m=1 . Calculate:

15
P 10
P
a) an · bm
n=1 m=1
10
P 15
P
b) ( an bm )
m=1 n=1
15
P 10
Q
c) an · bm
n=1 m=1
15
P 10
Q
d) ( (an + bm ))
n=1 m=1
10
Q 15
P
e) ( (an + bm ))
m=1 n=1

Find out which of these expressions give the same result.

Hints:
• The double sums/products resemble a double cycle used in source
code. The iteration variable of the outer cycle is set to the rst value
and the whole inner cycle is run. Then, the iteration variable of the
outer cycle is set to the next value and again the whole inner cycle
is run and so on. We can work with double sums the same way.

• In the problems where we need to add or multiply the terms of se-


quences pairwise, it is useful to create a table for that. We can use
the same table for problems a) and b) and another table for problems
c), d) and e).

• The problems do not specify the values of the sequence terms, so we


can make our own choice. We can prepare the Excel sheets in such a
way that there are four inputs (the rst term of arithmetic sequence,
the dierence, the rst term of geometric sequence and the quotient).
When these are changed, the expressions with sums and products are
recalculated.

• The indices help us determine whether we are working with rows or


columns in the individual cases.
9.4. LAB PROBLEMS 307

Solution: Since there are no specic sequences given in the problem and
we only know that one of them is arithmetic and the other geometric, we
can select our own. We are going to use the same sequences for all ve
problems. The arithmetic sequence is dened by d = 1 and a1 = 1 and
the geometric sequence is dened by q=2 and b1 = 1. The terms of the
sequences are:

an = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15

bm = 1, 2, 4, 8, 16, 32, 64, 128, 256, 512

We use the same table for problems a) and b). The terms in the individual
table cells are the products of every an with every bm term. In our case,
the sequence an is in a column and the sequence bm in a row, see Figure
9.1, but the results would be the same if an was in the row and bm in the
column.

For problem a), we add the terms an and bm separately and then multiply
the results. In problem b), we rst calculate the inner sums, i.e. we add
the terms for each column and then add the results.
10
P 15
P 15
P 10
P
We nd out that ( an bm ) = ( an bm ) is true.
m=1 n=1 n=1 m=1

Figure 9.1: Sums in a) and b).

We create a similar table for problems c), d) and e) that contains a product
of each term an with each term bm , see Figure 9.2.
308 CHAPTER 9. SUMS AND PRODUCTS

In problem c), we add the terms of the arithmetic sequence and calculate
the product of the terms of the geometric sequence. Then we calculate
the product of these two partial calculations.

Problems very similar to d) and e) are discussed in Section 9.3, problem


13. Practically, here we need to rst perform a product of sums (in the
rows) and then a sum of these products. In problem e), we rst perform
a sum of sums (in the columns) and then a product of these sums. We do
not get the same results, since the order of operations matters here.

Figure 9.2: Calculations for problems c), d) and e).

2. Geometric series
Prepare an Excel sheet which will contain the rst 100 terms of a geometric
sequence. Do it in such a way that you can vary the quotient of geometric
sequence in one cell. Calculate also the partial sums that correspond to
the terms of this sequence. Find the limit of these partial sums. In the
next column calculate the sum of the rst n terms using the formula.
Compare the results.

For geometric series with quotient less than 1 examine how the partial
sums converge to the limit of the innite sum.

For geometric series with a negative quotient examine the behavior of the
partial sums. How does the behavior change if the absolute value of the
quotient is larger/smaller than 1?
9.4. LAB PROBLEMS 309

Hints:
• We can create an Excel sheet, as shown in Figure 9.3, which shows
a geometric sequence, a sequence of its partial sums and the limit of
the sequence of the partial sums. We can then observe the behavior
of these sequences depending on the quotient.

Figure 9.3: Geometric sequence and a sequence of its partial sums.

• Try quotients larger than 1, 0 to 1, −1 to 0 and less than −1. Some


of these are shown in Figure 9.4. Does the behavior correspond to
what we know about limits of geometric series as discussed in the
lecture?

3. The size of an atom


Create an Excel sheet in which you write the rst 1000 values of splitting
a chocolate in half, down to the mass of an atom, Figure 9.5. Start with
a 100 gram chocolate. How many times can we split the chocolate in half
to get a piece, which has the mass of an atom? The absolute atom mass
is at the order of 10−26 kg (0.00000000000000000000000001kg).
Hints:
• If we break a chocolate in half and then break one half again in half,
we obtain a piece which is 1/4 of the original chocolate. What part of
the chocolate do we get if we break the 1/4 piece into halves again?
We continue doing this until the new piece has the mass equal to (or
less than) an atom. What kind of sequence is this? We can write out
the rst few terms and then write a recurrent formula.
310 CHAPTER 9. SUMS AND PRODUCTS

Figure 9.4: Geometric sequences and their partial sums for q = 2, 1, 0.5, −0.5,
−1, −2.

Figure 9.5: Successive splitting of chocolate in half.

• Using the recurrent formula, keep splitting the 100 g chocolate until
the mass of the smallest piece is approximately 10−26 kg . Make sure
that everything is calculated in the same units.

• To make the search for the right number of splits easier, we can write
9.4. LAB PROBLEMS 311

a check that would inform us once we reach the mass of an atom.

Solution:

• The input data are the chocolate mass (100g ) and an approximate
−23
atom mass (1 · 10 g ). These parameters can serve as an input and
perhaps be also changed later on.

• We can designate one column (Num), see Figure 9.6, for tracking the
numbers of splits needed.

• In another column (Geom. sequence), we write the splitting sequence.


1
This is a geometric sequence with q=
2 . If we calculate it using a
recurrent formula, it is sucient to divide the previous cell by two,
with the rst term being 1. We can also directly use the formula
=1*POWER((1/2),E3) for calculation of the nth term.

• The next column (Mass) calculates the mass of each successive piece
of chocolate as =100*F3.

• The nal column contains a check whether the new piece has smaller
mass than an atom using the formula =IF(G3<C3,"TRUE","").

Figure 9.6: Chocolate mass after successive splitting in half.


312 CHAPTER 9. SUMS AND PRODUCTS

4. Distance to Mars
Create an Excel sheet which shows the rst 1000 steps of the journey to
Mars. The length of the rst step is equal to a paper width. The second
step is the thickness of a paper folded in half. The next is the paper folded
in half again and so on. How many times do we need to fold the paper in
half to get the thickness equal to the distance form Earth to Mars?

A regular package of 500 sheets of paper is 5.3cm thick.

The distance from Earth to Mars varies from 55 to 400 millions kilometres.

Hints:
• We can start by assuming that we have an innitely large paper. We
are going to fold it in half until the stack is thick enough to reach
Mars. We can calculate the thickness of one paper from the data
given in the problem.

• The distance from Earth to Mars varies depending on their mutual


positions as they travel around the sun, however, once we calculate
the number of folds needed for the minimum distance, we can easily
check how this number changes for the maximum distance (and the
distances between them).

• What type of sequence do we have here? Looking at the rst few


terms, we can nd a recurrent formula for the nth term. We can use
it to determine the number of layers we have after each fold.

• Try folding a paper a few times yourself. Can you fold it more than
eight times? What is the height of your tallest stack?

Solution:
As in the previous problem, we are dealing with geometric series here,
with q = 2. The recurrent formula an = 2an−1 helps us calculate the nth
n
term an = a0 · q . We can use either of them to determine the thickness of
each new layer and then add them up. The thickness of one paper can be
calculated from the thickness information about one 500-paper package.

As we see in Figure 9.7, we need to fold the paper 49 to 52 times to create


a stack that would reach Mars.
9.4. LAB PROBLEMS 313

Paper dimensions
Suppose we start with an A4 paper with dimensions 210 mm ×
297 mm. What dimensions does the folded paper have, once it has
been folded enough times to reach Mars?

Figure 9.7: Calculating the number of paper folds needed to get from Earth to
Mars.
314 CHAPTER 9. SUMS AND PRODUCTS
Chapter 10

Real functions  part 1

10.1 Lecture overview

Problem 10.1 Velocity with respect to time:


Draw a graph of a function that describes the dependence of velocity on time
for a 100 km long stage of a bicycle race in which Peter Sagan went 50 km uphill
at 25 km/hr and then 50 km downhill at 100 km/hr.

Solution: The graph is shown in Figure 10.1 a). In practice, there would not be
a jump (discontinuity) between the two horizontal lines. Similarly, there would
be a gradual increase from 0 to 25 as the race starts and decrease from 100 to
0 as Sagan breaks after the nish line.

Problem 10.2 Distance with respect to time:


Draw a graph of a function that describes the dependence of distance (from the
starting point) on time for a 100 km long stage of a bicycle race in which Peter
Sagan went 50 km uphill at 25 km/hr and then 50 km downhill at 100 km/hr.
Using this graph, determine, how fast he went, if there were any breaks, when
did he accelerate and when did he slow down.

Solution: The graph is shown in Figure 10.1 b). We can see that in the rst
hour he covered 25 km, in two hours 50 km. This corresponds to the velocity
25 km/hr for the rst two hours. Then the distance grows faster, he covers
additional 50 km in just 1/2 hour. Therefore the velocity is 100 km/hr during
this half hour. There were no breaks, since they would appear as at horizontal

315
316 CHAPTER 10. REAL FUNCTIONS  PART 1

a) b)

Figure 10.1: One stage of a bicycle race: a) velocity dependence on time, b)


distance dependent on time. Note that this is an idealised situation, since
obviously velocity cannot instantaneously increase from 25 to 100 km/h.

lines in the distance graph. Also, there was no acceleration/deceleration - that


would appear as non-straight lines in this graph.

Problem 10.3 Water in the tub:


From a graph of water tap ow rate depending on time, Figure 10.2, nd out
how much water is in the tub.

Solution: We see that in the rst ve minutes, the water was owing at constant
rate 10 liters per minute (l/min), therefore after ve minutes there were 5 · 10
liters of water in the bathtub. This corresponds to the area under the rst line
segment in the graph. In the next ve minutes the water ew in faster  at
20 l/min, therefore during this time, we gained 5 · 20 liters. Again this number
corresponds to the area under the second segment. The total area (including the
third rectangle) thus corresponds to the total amount of water in the bathtub
after 15 minutes: 50 + 100 + 15 · 5 = 225 liters.

Functions  reminder
Functions express the dependence of numerical output on a numerical input.
The input can be any number in R or in its relevant subset. Examples of func-
tions include: relations between physical quantities (e.g. dependence of atmo-
spheric pressure on the altitude), dependence of time needed for an algorithm to
nish on the size of the inputs, server load dependence on time, interest amount
as a function of time, prot as a function of costs, etc.
10.1. LECTURE OVERVIEW 317

Figure 10.2: Water ow rate into a tub.

Domain
The set of all x ∈ R for which there exists a value f (x) is called a domain D(f ).

D(f ) = {x ∈ R; ∃f (x)}

Range
The function f (x) assigns each x ∈ D(f ) exactly one value f (x). The set of all
values f (x) is called a range H(f ).
H(f ) = {y ∈ R, ∃x ∈ R; f (x) = y}

Ways to dene a function


• by a table

• by a graph

• by a formula or algebraic expression which lets us calculate the value of


the function, e.g. 3x6 − 2x2 + 5

• by a known notation, e.g. sin(x), cos(x), sinh(x)

• by instructions, e.g. nd functions fA (x) and gA (x) which are the areas
under the constant f (x) = 1 or under the line g(x) = x from 0 to x. (The
functions are fA (x) = x and gA (x) = x2 /2.)
318 CHAPTER 10. REAL FUNCTIONS  PART 1

Basic properties of functions


A function f (x)
• is increasing on an interval I i ∀x, y ∈ I, x < y ⇒ f (x) < f (y).
• is decreasing on an interval I i ∀x, y ∈ I, x < y ⇒ f (x) > f (y).
• is non-decreasing on an interval I i ∀x, y ∈ I, x < y ⇒ f (x) ≤ f (y).
• is non-increasing on an interval I i ∀x, y ∈ I, x < y ⇒ f (x) ≥ f (y).
• has a minimum m on I i ∀x ∈ I : (f (x) ≥ m ∧ ∃ xm ∈ I : f (xm ) = m).
• has a maximum M on I i ∀x ∈ I : (f (x) ≤ M ∧ ∃ xM ∈ I : f (xM ) = M ).

10.1.1 Linear functions


Problem 10.4 Values of a linear function:
Calculate selected values of the function f (x) = 2x + 3.

Solution: √
x 1 2 3 0 10 −1 −2 −10 0.1 0.3
√2 π
f (x) 5 7 9 3 23 1 −1 −17 3.2 3.6 2 2+3 2π + 3

Graph of a function
A graph of a function f (x) is a set of points G(f ) in a plane, such that G(f ) =
{[x, f (x)]; x ∈ D(f )}.

Problem 10.5 Graphs of linear functions:


Draw graphs of f1 (x) = x, f2 (x) = x + 2, f3 (x) = x − 3, f4 (x) = 2x, f5 (x) =
x
2 , f6 (x) = 2x + 3, f7 (x) = −x, f8 (x) = 2x + 3, f9 (x) = −2x + 3.

Solution: Some of these functions are shown in Figure 10.3. The graphs of
f1 (x) = x, f2 (x) = x + 2 and f3 (x) = x − 3 are parallel lines. f1 (x) passes
through zero and f2 (x) and f3 (x) are shifted with respect to it. f7 (x) has a
completely dierent slope.

Discovering properties of linear functions


The graph of a function f (x) = 2x + 3 is a line. Where in the graph do
we see the value 2 and where do we see the value 3? What do the graphs
f1 (x) = 2x + 1, f2 (x) = 2x − 2 and f3 (x) = 2x have in common? What
10.1. LECTURE OVERVIEW 319

Figure 10.3: Linear functions.

1
do the graphs f1 (x) = 2x + 1, f2 (x) = 5x + 1 a f3 (x) = 2x +1 have in
common?

Linear function
A linear function is a function of the form:

f (x) = ax + b

Depending on the value of a, a linear function f (x) = ax + b is either increasing,


constant or decreasing. Its domain is R. Its range is either R or just one real
number.

Scaling and shifts in graphs


• The coecient a in front of variable x scales the graph. For a>1 we get
a faster behavior (as if we squeezed the x-axis from both sides towards
the center). For 0 < a < 1 we get a slower behavior (as if we stretched
the x-axis from the center to both sides). The graph is mirrored about
the y -axis for a < 0.

• The coecient b shifts the graph. For b>0 we have a shift up and for
b<0 down.

• The graphs can also be shifted left and right (this is useful when drawing
more complicated functions). If we have x − k instead of x, the graph
is shifted k units to the right. For x + k , it is shifted k units to the
320 CHAPTER 10. REAL FUNCTIONS  PART 1

left. Compare the graphs of f (x) = 2x + 3, g(x) = 2(x − 1) + 3 and


h(x) = 2(x + 1) + 3 shown in Figure 10.4.

Figure 10.4: Shifting a linear function.

Inverse function
A function f (x) is inverse to function g(y) i the following is true: ∀x ∈
D(f ), ∀y ∈ D(g) : y = f (x) and x = g(y). More precisely, if we he have:
g(f (x)) = x
We can only look for the inverse function if the original function f (x) was
injective. Some examples of inverse functions:

• 2x and x/2 are mutually inverse.

• We can derive the inverse function g(y) to f (x) = 2x + 3. First we denote


y−3
y = 2x + 3. Then we have 2x = y − 3 and then x = g(y)  = 2 . So we can
x−3 x−3 x−3
write g(x) =
2 . And it is true that f ( 2 ) = 2 2 +3 = x−3+3 = x.

10.1.2 Quadratic functions


Problem 10.6 Values of a quadratic function:
Calculate selected values of the function f (x) = x2 .

Solution: √ √
1
x 0 1 −1 2 −2 2 − 21 2 − 2 3 −3
1 1
f (x) 0 1 1 4 4
4 4 2 2 9 9
The graph of the function f (x) = x2 is a parabola. The minimum of this function
is 0 and it is achieved at x = 0.
10.1. LECTURE OVERVIEW 321

Quadratic function
A quadratic function is dened as:

f (x) = ax2 + bx + c

The domain of a quadratic function is R. The range is a half-closed interval (for


a 6= 0).

Problem 10.7 Graphs of quadratic functions:


2
Draw graphs of f1 (x) = x2 + 1, f2 (x) = x2 − 1, f3 (x) = 2x2 , f4 (x) = x2 , f5 (x) =
(x − 1) , f6 (x) = (x + 2)2 , f7 (x) = x2 + 4x + 4 = (x + 2)2 , f8 (x) = (x −
2

3)2 , f9 (x) = (x + 10)2 . What is the eect of coecients a, b, c on the graph of


f (x) = ax2 + bx + c? For f5 (x) determine the intervals on which it is increasing
and decreasing.

Solution: Some of these functions are shown in Figure 10.5.

Figure 10.5: Quadratic functions.

Zero of a function
Let the function f (x) have a domain D(f ). We call the point x0 ∈ D(f ) a zero
(or root) of the function f (x) i f (x0 ) = 0. This means that the zeros of a
function f (x) are the solutions of the equation f (x) = 0.

• The function f (x) = x2 + 4x + 1 has two zeros.

• The function f (x) = x2 + 4x + 4 has one zero point.

• The function f (x) = x2 + 4x + 6 does not have any zeros.


322 CHAPTER 10. REAL FUNCTIONS  PART 1

• Using a graph of a function, we can learn about the solutions of an equation


x2 + 4x + 1 ≥ 0. We nd
or inequality, e.g. the zeros of the function
2
f (x) = x + 4x + 1:
x2 + 4x + 4 − 3 = 0
(x + 2)2 − 3 = 0
(x + 2)2 = 3

x+2=± 3

x = −2 ± 3

The solutions of inequality x2 + 4x + 1 ≥ 0 are ∀x ∈ −∞, −2 − 3 ∪
√ 
−2 + 3, ∞ .
√ √ 
• The solutions of x2 + 4x + 1 < 0 are ∀x ∈ −2 − 3, −2 + 3 .

10.1.3 Absolute value function


Problem 10.8 Values of an absolute value function:
Calculate selected values of the function f (x) = |x|.

Solution: √
x 1 2 3 0 10 −1 −2 −10 −
√ 2 π
0.1 0.2 −0.3
f (x) 1 2 3 0 10 1 2 10 0.1 0.2 0.3 2 π
The graph of f (x) = |x| is a piecewise linear line. The domain of f (x) = |ax + b|
is R. The range is a half-open interval.

Problem 10.9 Graphs of absolute value functions:


Draw graphs of

• g(x) = |x − 3|, h(x) = |x + 1|.


• g(x) = |x − 3| − 3, h(x) = |x + 1| + 5. How do we determine the zeros of
these functions?

• g1 (x) = |2x − 3| (more bent, sharper angle), h1 (x) = | 12 x + 1| (less bent,


less sharp angle).

• g(x) + h(x) = |x − 3| + |x + 1|.


• g(x) − h(x) = |x − 3| − |x + 1|.
10.2. QUESTIONS 323

10.2 Questions

1. Draw a graph of a function that describes your journey from home to


school on Monday morning. Independent variable is time and dependent
variable is your velocity.

2. Draw a graph of a function that describes your journey from home to


school on Monday morning. Independent variable is time and dependent
variable is your distance from home.

3. Real function of a real variable is a mapping from A to B. What are A


and B?
4. Give an example of a function for which D(f ) = H(f ).
5. Give an example of a function for which D(f ) ∩ H(f ) = ∅.
6. Find a linear function g(x) which grows faster than f (x) = 2x + 3.
7. Find a linear function g(x) whose graph intersects the x-axis to the right
of the function f (x) = 2x + 3.
8. Find a linear function g(x) whose graph is parallel with the graph of the
function f (x) = −2x + 3.
9. Find a linear function g(x) which is neither increasing nor decreasing.

10. Find a quadratic function g(x) whose graph is completely above the graph
of f (x) = x2 + 2x + 1.
11. Find a quadratic function g(x) whose roots are between the roots of the
function f (x) = x2 − 5x + 6.
12. Find a quadratic function g(x) whose graph touches the graph of f (x) =
x2 + 2x + 1 in just one point.

13. Find a quadratic function g(x) whose graph does not cross the x-axis.
14. Find a quadratic function g(x) whose graph does not cross the y -axis.
15. For numbers from which interval is the following statement true: if x>y
then x2 > y 2 ?
16. For numbers from which interval is the following statement true: if x>y
then x2 < y 2 ?
324 CHAPTER 10. REAL FUNCTIONS  PART 1

17. For which number x is f (x) = x2 + 2x + 1 minimal? What is the minimum


value of f (x)?

18. Draw the graphs f (x) = |2x|, g(x) = |x + 1|, h(x) = |2x + 1| and z(x) =
|2x − 1|.
10.3. PROBLEM SET 325

10.3 Problem set

1. Equations and inequalities with absolute values


State the set of solutions, draw the graph of the function and display the
method of solution and the result. Draw the solution on a real axis where
the absolute value can be interpreted as a distance.

a) |x + 2| = 3
b) |x − 1| ≥ 7
c) |x + 2| + |x − 2| = 4
d) |x + 3| + |x − 4| ≤ 7
e) |x − 1| + |x + 8| > 7
2. Equations and inequalities with quadratic functions
Solve the equations and inequalities with quadratic functions. State the
set of solutions, draw the graph of the function and display the method
and result.

a) x2 − x − 6 = −6
b) −x2 + 4x + 2 = 5
c) x2 + 4x − 5 ≤ 14
d) x2 + 6x − 4 ≥ 9
e) −x2 + 5x − 8 ≥ −5
3. Domains and graphs of rational functions
Draw the graphs and state the domains of the following functions:

1
a)
x
1
b)
x−3
1
c)
x+3
3
d)
2x+3
3x−3
e)
x+2
5x+3
f)
2−x
1
g)
(x−2)2
1
h)
(x+4)(x−1)
326 CHAPTER 10. REAL FUNCTIONS  PART 1

4. Domains, ranges, roots and intervals of monotonicity


State the domains, ranges, roots and intervals of monotonicity of the fol-
lowing functions:

a) x2 − x − 6
b) |x + 1| + |x − 3|
3x−4
c)
5−x
1
d)
(x+1)(x−3)

5. Zeroes of quadratic functions


How many zero points can a function f (x) = ax2 + bx + c have? Give an
example for each case.
10.3. PROBLEM SET 327

10.3.1 Hints and solutions


1. Equations and inequalities with absolute values
a) |x + 2| = 3
d) |x + 3| + |x − 4| ≤ 7

Hints:
• Think about what the absolute value does. We evaluate whatever
is inside it. If it is positive or zero, the absolute value does not do
anything at all. On the other hand, if the result is negative, it simply
removes the negative sign. With respect to the graph of a function,
we can think about the absolute value as a mirror that lies on the
x-axis and ips everything from below the axis to the above.

• The problems can be solved analytically by replacing the absolute


value(s) with a set of suitable functions over dierent intervals.

• The absolute value can also be considered as distance. In this case,


remember that |x−2| represents the distance of x from 2, while |x+2|
represents the distance of x from −2.
• Alternatively, these problems can also be solved graphically by sketch-
ing the left-hand side and right-hand side separately and then con-
sidering where the graphs intersect (in case of equations) or regions
where the larger side is above the smaller side (in case of inequalities).

Solution:
a) One way to approach this problem is to remove the absolute val-
ues. We assume that x ∈ R and we solve this problem separately
two times. Once on the interval (−∞, −2i, where the absolute value
changes the sign of what is inside it and therefore we have the equa-
tion −x − 2 = 3. The solution is x1 = −5.
And we also solve the equation x+2 = 3 on the interval (2, ∞),
where the absolute value does not change the sign of the expression
within. Here we get a solution x2 = 1. The set of solutions is then
S = {−5, 1}. This can be interpreted as a set of numbers that have
a distance 3 from the number −2, as illustrated in Figure 10.6 a).

Another way to look at this problem is to draw the graph of the


left-hand side of the equation, a V as shown in red in Figure 10.6 b)
328 CHAPTER 10. REAL FUNCTIONS  PART 1

a) b)

Figure 10.6: Absolute value represents distance as in a), or we can solve the
problem using the graphs of both sides of the equation as in b).

and the constant as a horizontal line (green). The solutions are then
the x-coordinates of the intersections of these two graphs.

d) We again solve this problems in two ways: once by splitting the


domain and removing the absolute values and the second time by
plotting both sides of the inequality.

The domain is split by the zero points of each absolute value, i.e. into
(−∞, −3i ∪ (−3, 4) ∪ h4, ∞). Note that it does not matter into which
interval we include the zero points, we could use e.g. (−∞, −3i ∪
(−3, 4i ∪ (4, ∞) instead.
On (−∞, −3i we have the inequality

−x − 3 − x + 4 ≤ 7
−2x + 1 ≤ 7
−6 ≤ 2x
−3 ≤ x

We have one solution here S1 = {−3}, since −3 is the only x ∈


(−∞, −3i that is greater than (or equal to) negative three.

So we look at the second interval (−3, 4). Only one of the absolute
values changes the sign of its inner expression there (we can verify
that by plugging in any value from the interval):

x+3−x+4 ≤ 7
7 ≤ 7

This is true for all x in this interval, so S2 = (−3, 4).


10.3. PROBLEM SET 329

And then we look at the third interval h4, ∞). The absolute value
does not change sign here, so we have

x+3+x−4 ≤ 7
2x − 1 ≤ 7
x ≤ 4

We have one solution here S3 = {4}.


Combining them all, we get S = S1 ∪ S2 ∪ S3 = h−3, 4i. The same
answer can be obtained by looking at Figure 10.7. We see the indi-
vidual absolute values in black, their sum in red and the right-hand
side in green. Coincidentally, the intersection of the red and green
graphs is the horizontal part of the left-hand side. In general, this is
not true. The green line may intersect the red one at two points or
at none at all. In the latter case there are no solutions, in the former,
the solutions are the x-coordinates of all points on the red line that
lie below or on the green line.

Figure 10.7: A graphic solution to inequality with two absolute values.

2. Equations and inequalities with quadratic functions


a) x2 − x − 6 = −6
d) x2 + 6x − 4 ≥ 9

Hints:
• It is helpful to nd the roots of the quadratic function, e.g. using
discriminant, and the vertex of the parabola that lies between them.
330 CHAPTER 10. REAL FUNCTIONS  PART 1

• The problems can be solved analytically by manipulating the equa-


tions/inequalities or graphically by drawing both sides and looking
for intersections.

Solution:
a) When looking for the zeros of the quadratic function, we rst write it
in the form ax2 + bx + c = 0 by adding 6 to both sides of the equation
(this is one of the equivalent modications that we can perform on
an equation):
x2 − x = x(x − 1) = 0
The zeros are x1 = 0 and x2 = 1.
We can also look at the graphs of both sides of the original equation,
see Figure 10.8. The solutions are then the x-coordinates of their
intersections.

Figure 10.8: Left-hand side (red) and right-hand side (blue) of the equation
x2 − x − 6 = −6.

d) Here we also start by writing it in the form ax2 + bx + c ≥ 0:

x2 + 6x − 13 ≥ 0.

It is not immediately clear how to factor the left-hand side into a


2
product of linear terms. D = b√ −
Therefore, we use discriminant

4ac = 36−4·(−13)√= 88 to determine
√ (x 1 = −6+ 88)/2 = −3+ 22
and x1 = (−6 − 88)/2 = −3 − 22. The inequality can now be
written as

√ √
(x − (−3 + 22)) · (x − (−3 − 22)) ≥ 0.
10.3. PROBLEM SET 331

Now we might remember the fact that a>0 means that we have a
parabola with branches pointed upwards and thus the solution to the
inequality is a union of two intervals where these branches are above
√ √
the x-axis: (−∞, −3 − 22i ∪ h−3 + 22, ∞).
If we do not know this, we can examine a number between the two
roots, e.g. x = −3 and check whether the left-hand side is greater
than 0. Since (−3)2 + 6 · (−3) − 13 = 9 − 18 − 13 < 0, we know
that the whole part of the parabola that lies between the zeros has
to be below the x-axis (if it crossed the axis somewhere, we would
have more zeros, so it cannot do that) and consequently the branches
have to be above it. Then we can make the same conclusion about
the solution as before.

To draw the graph of a quadratic function, it is certainly helpful


to know the roots (if there are any), but there is another point of
interest: the vertex. This is either the maximum (if the branches
of the parabola point downward, i.e. for a < 0) or minimum (if the
branches point upward, i.e. for a > 0). We can nd it by completing
the square :
x2 + 6x − 13 = (x + 3)2 − 9 − 13 = (x + 3)2 − 22.

Here we are using the fact that (x2 + ax) diers from (x + a/2)2
2
only by a constant. The expression x + 6x − 13 is the smallest,
when (x + 3)2 = 0, because it cannot be negative. This happens for
b
xm = −3 = − 2a and this is a point of minimum. The actual value
of minimum is m = f (xm ) and can be obtained either by evaluating
f (xm ) or by looking at expression (xm + 3)2 − 22 = 0 − 22 = −22.
3. Domains and graphs of rational functions
1
a)
x
1
c)
x+3
5x+3
f)
2−x
1
g)
(x−2)2
1
h)
(x+4)(x−1)
332 CHAPTER 10. REAL FUNCTIONS  PART 1

Hints:
• What do these functions have in common is that when drawing their
graphs, we can start from a hyperbola and shift it to the desired
position.

• If the rational function (or portion of a function between two vertical


asymptotes) does not have a zero point, then it has to stay either
above the x-axis or below it.

Solution:
1
a) The domain of
x is R − {0} and the graph  a hyperbola  is shown
in Figure 10.9 a).
1
c) Similarly,
x+3 is not dened at the zero point of the denominator
x = −3 and its domain is R − {−3}. The graph is shown in Figure
10.9 a).
5x+3
f ) The domain of
2−x is R − {2}. To draw the graph, we express the
5x+3 5x−10+13 13
function in the form
2−x = 2−x = −5 + 2−x . We start by
1
the graph of , which is a hyperbola in the second and the fourth
2−x
quadrant (due to the negative sign in front of x). Multiplication by
a constant 13 stretches both the branches away from the x-axis and
−5 shifts the whole graph down, as can be seen in Figure 10.9 b).
1
g) The domain of
(x−2)2 is also R − {2}. The graph is a hyperbola with
both branches above the x-axis and closer the axes (due to the second
power) as shown in Figure 10.9 c).
1
h) The domain of
(x+4)(x−1) is R − {−4, 1}. The graph is shown in
Figure 10.9 d). It is helpful to start by examining the behavior of
the function immediately to the left and to the right of the zeros of
denominator.

Inverse graph problem


Can you nd a function, whose graph is shown in Figure 10.10?

4. Domains, ranges, roots and intervals of monotonicity


b) f (x) = |x + 1| + |x − 3|
1
d) g(x) = (x+1)(x−3)
10.3. PROBLEM SET 333

a) b)

c) d)

Figure 10.9: Graphs of rational functions.

Figure 10.10: Can you write the formula of the function shown in this graph?

Hints:
• When trying to determine a domain, we should look for problematic
spots in the formula of the function. These are typically square roots
or denominators of fractions.

• A graph of the function can be very useful in determining the range.


334 CHAPTER 10. REAL FUNCTIONS  PART 1

In the graph we can easily see all the values of y that are images of
some x ∈ D(f ). The check can be performed by sliding a horizontal
line over the graph up and down  each position corresponding to a
value y. All the values y for which the horizontal line intersects the
graph of the function belong to the range.

• Roots/zeros are the intersections of the graph with the x-axis. They
can be found by solving the equation f (x) = 0.
• While there are analytical methods (which use derivatives) to deter-
mine the intervals of monotonicity of functions, they are beyond the
scope of this material. To determine monotonicity without them,
we have to visually inspect the graph of the function and/or use the
denition.

Solution:
b) Looking at the function f (x) = |x + 1| + |x − 3|, we see that there
are no problematic values of x at which this function would not be
dened. Therefore D(f ) = R. Clearly f (x) ≥ 0, since it is a sum
of two non-negative terms, however this is not sucient to state the
range. For that we draw a graph, Figure 10.11. From the graph we
see that the range is H(f ) = h4, ∞).

Figure 10.11: A graph of the function f (x) = |x + 1| + |x − 3|.

Since the graph does not intersect the x-axis, this function has no
roots and we can also directly determine the intervals of monotonic-
ity: f (x) is decreasing on (−∞, −1i, constant on h−1, 3i and increas-
ing on h3, ∞).
We can also check monotonicity using the denition for example on
the interval (−∞, −1i. On this interval f (x) = −x − 1 − x + 3 =
10.3. PROBLEM SET 335

−2x + 2. For y > x we have −2y < −2x and f (y) = −2y + 2 <
−2x + 2 = f (x). Since for any y > x on the interval (−∞, −1i
we have f (y) < f (x), this means the function is decreasing on this
interval.
1
d) The function g(x) = (x+1)(x−3) has two zero points in the denomina-

tor: x = −1 and x = 3. Therefore the domain is D(g) = R − {−1, 3}.


Looking at the graph, Figure 10.12, we see that the range is H(g) =
R − (− 41 , 0i. Clearly g(x) 6= 0, there are no zeros of this function.
How can we be sure that it is sucient to exclude 0 and nothing
else? We can calculate the limitslim g(x) = lim g(x) = 0 and
x→∞ x→−∞
from this we know that the functional values have to get arbitrarily
close to 0 and thus nothing else needs to be excluded from the range.

1
Figure 10.12: A graph of the function g(x) = (x+1)(x−3) .

The local minimum in the middle part of the graph lies in the middle
−1+3
between the two vertical asymptotes at
2 x=
= 1.
The graph in Figure 10.12 also helps with investigating monotonicity.
We see that the function is increasing on (−∞, −1) and on (−1, 1).
It is decreasing on (1, 3) and on (3, ∞).

Monotonicity on two intervals


Can we write that g(x) is increasing on (−∞, −1) ∪ (−1, 1)?
Why? (Or why not?)

5. Zeroes of quadratic functions


Hints:
• The fundamental theorem of algebra tells us at most how many zeroes
can a polynomial function have. Once we know this number k for a
336 CHAPTER 10. REAL FUNCTIONS  PART 1

quadratic function, we can try to construct dierent functions, that


will have 0, 1, . . . , k roots.

• It is also useful to think about how many parameters there are in a


quadratic function that can be tuned (three) and what implications
this has for the number of roots.

• If a polynomial f (x) has a root r, then it can be written as f (x) =


(x−r)g(x), where the degree of g(x) (largest power of x) is the degree
of f (x) minus 1.

Solution: The fundamental theorem of algebra says that a polynomial of


degree n can have at most n roots. Therefore a quadratic function can have
at most two. Suppose we want the roots to be x1 = 2 and x2 = −3. We can
construct the corresponding quadratic function as f2 (x) = (x−2)(x+3) =
x2 + x − 6. Note that this is not the only quadratic function with these
2
roots, g2 (x) = 2x + 2x − 12 = 2(x − 2)(x + 3) is another one and any
other constant multiple of f2 (x) would work. Of course, we could have
picked any other two real numbers for roots.

Quadratic function can also have just one double real root. This happens
for a suitable combination of coecients when the discriminant D = 0.
Thus we can construct f1 (x) = (x − 1)2 = x2 − 2x − 1. Again we can take
any constant multiple of this function. The parabola touches the x-axis
at precisely one point.

For a quadratic function to have no roots, it cannot cross or even touch


the x-axis. We can start with x2 and shift it upward, i.e. f0 (x) = x2 + 3.
10.4. LAB PROBLEMS 337

10.4 Lab problems

1. Absolute value
• Draw the graph of |x − a| for a variable x and a parameter a. Try
shifts to the right, left, up, down and change of slope.

• Write the equations of individual lines (removal of absolute value).

• Use the graph to analyse equations and inequalities and look for their
solution.

• Solve similar problems for a sum of two absolute values, examine the
shape and shifts. Write the equations of individual lines.

• Solve similar problems for a dierence of two absolute values.

• Create the most peculiar graph with a given number of |x − a| ex-


pressions.

• Create dragon teeth: iterative drawing of ||x−a|−b|, |||x−a|−b|−c|.


Examine the properties, shift up and down, draw a required number
of teeth, at required locations, etc.

2. Quadratic function
Calculate and draw a quadratic function f (x) = ax2 + bx + c for x in
the range h−10, 10i. Keep a, b, c as adjustable parameters. Observe
what is the impact of individual parameters on the shape of the graph.
Calculate the roots (output them only if real roots exist), number of roots,
x-coordinate of the vertex and the value of minimum/maximum.

3. Cubic and bi-quadratic functions


Draw graphs of cubic and bi-quadratic (f (x) = ax4 + bx2 + c) functions.
What shapes can they have? How many roots can they have? Can you
set the parameters in such a way that you get specic number and values
of roots? Can you set the parameters in such a way that you get specic
intervals of monotonicity?

4. Area under the curve


Tabulate a function f (x) (constant, linear with only parameter a) for
nonnegative real numbers and areas under the graph f (x) from 0 to x
using a suitable formula for calculation of area. Draw the graph of the
function f (x) and area Af (x). What relationship between f (x) and Af (x)
do you observe?
338 CHAPTER 10. REAL FUNCTIONS  PART 1

10.4.1 Hints and solutions


1. Absolute value
Hints:
• We can start in Excel by tabulating the values of f (x) = |x|. The
absolute value changes the sign of everything inside it that is below
the x-axis. For a linear function this means that the left half is
reected above and the resulting graph is a V -shape.
• When we parametrise the expression as |x − a| with a parameter a,
we soon realise that the resulting shifts due to dierent inputs for a
might cause our graph to escape to the right or to the left. Of course,
we could tabulate more values or new domains, but that might dis-
tract us from the actual task  investigating the eects of parameter
changes. Therefore, we recommend using a dierent software tool
for this problem, such as the versatile webpage wolframAlpha [3] or
some other webpage dedicated to graphing, such as desmos.com [1]
or perhaps a standalone application like Geogebra [5].

• It is useful to change the parameters one at a time. If you change


more of them at once, it is dicult to realise which eects were due
to which changes.

• To solve the equations or inequalities graphically, draw both sides


and examine their intersections.

• To create the dragon teeth, try using the absolute values iteratively:
||x − a| − b|, |||x − a| − b| − c|. Which parameters determine the size of
individual teeth? How to make the teeth all the same size? How to
make the desired number of them? If needed, add more parameters.

Solution:
Putting the parameter inside the absolute value causes horizontal shift in
the graph. |x − 2| shifts the basic absolute value function two units to the
right, |x + 2| = |x − (−2)| shifts it two units to the left (or −2 units to
the right), as can be seen in Figure 10.13. To achieve a vertical shift, we
need to add something once the value of the function is already calculated,
i.e. outside the absolute value. |x| + 3 shifts the absolute value up by 3
units and |x| − 3 shifts it down.

To change the slope, we need a multiplicative constant with x, similarly


to the basic linear function. For constant k > 1, the V in the graph is
steeper (also seen in Figure 10.13), for k < 1 the V is more shallow.
10.4. LAB PROBLEMS 339

Figure 10.13: Manipulations with absolute value function: the blue one is shifted
to the right by 2, the green one is shifted to the left by 2, the purple one is shifted
to the right by 5 and down by 2. The black one is shifted to the left by 5 and
its slope is increased by a factor of 2.

Various graphing software lets us experiment with parameters in a very


user-friendly way, as shown in Figure 10.14.

Inverse problems
Can you solve an inverse problem, i.e. nd the parameters k and
a given a set of solutions of an equation |kx − a| = c or inequality
|kx − a| < c?

Figure 10.14: In graphing softwares it is possible to parametrise the function


and easily observe the inuence of parameters on the graph of the function
 in this case on the slope (parameter k) and horizontal shift (parameter a).
Performed in Desmos.

To draw the dragon teeth, we apply the absolute values repeatedly. Every
time we shift the function down, the next absolute value mirrors the part
340 CHAPTER 10. REAL FUNCTIONS  PART 1

of V that is below the x-axis up and results in a new tooth. If we want


all teeth be of the same size, the downward shifts should be the same
too. Once we have the desired number of teeth we can display a second
function, which only diers from the original one by a vertical shift, i.e. a
constant added or subtracted at the end. This results in a mouth with
two rows of teeth, Figure 10.15, which can even be animated.

Figure 10.15: By applying the absolute value repeatedly on function that is


repeatedly shifted downward, we can get a teeth function. We can even take
two of such functions, one with parametric vertical shift (parameter a) and
either by manual or automatic changes in the parameter animate the chewing
motion.

Blunt dragon teeth


Can you create dragon teeth that are not sharp like those shown in
Figure 10.15, but rather round ( semicircular or parabolic )?

2. Quadratic function
Calculate and draw a quadratic function f (x) = ax2 + bx + c for x in
the range h−10, 10i. Keep a, b, c as adjustable parameters. Observe
what is the impact of individual parameters on the shape of the graph.
Calculate the roots (output them only if real roots exist), number of roots,
x-coordinate of the vertex and the value of minimum/maximum.

Hints: If we only wanted a graph, we could experiment with the param-


eters in a graphing software as in the previous problem, but since we
should also calculate some characteristics of the parabola, it is useful to
use Excel again here. The roots can be determined using the discrimi-
nant and conditions that check if it is positive, negative or equal to zero.
The x-coordinate of the vertex can either be found in the middle between
the roots or again using a suitable formula that contains some of the pa-
rameters a, b, c. The y -coordinate of the vertex (global extreme of the
10.4. LAB PROBLEMS 341

quadratic function) can be evaluated as the value of f at the x-coordinate


of the vertex.

Solution: An example worksheet is shown in Figure 10.16. We can vary


the input parameters a, b, c and observe their impact on the graph  for
example changing the sign of a ips the branches of the parabola, changes
in c impact the number of roots, etc. Which parameter(s) inuence the
location of the roots?

Figure 10.16: Quadratic function displayed in Excel along with information on


its discriminant, roots and vertex.

Inverse problem
Create an Excel sheet in which the inputs are roots and coordinates
of the vertex. The sheet checks that the input is consistent, draws
the parabola and outputs the values a, b, c.

3. Cubic and bi-quadratic functions


Draw graphs of cubic and bi-quadratic functions. What shapes can they
have? How many roots can they have? Can you set the parameters in such
a way that you get specic number and values of roots? Can you set the
parameters in such a way that you get specic intervals of monotonicity?

Hints:
• While we could deal with this problem similarly to the previous one
and consider the cubic function as f (x) = ax3 + bx2 + cx + d, with
342 CHAPTER 10. REAL FUNCTIONS  PART 1

four input parameters a, b, c and d, it would be dicult to get the


right number of roots at the right positions. For that, it is useful to
consider the formula in a dierent form. More details can be found in
the next chapter  both in the problem section and in the lab section.

• The bi-quadratic function has the form f (x) = ax4 + bx2 + c. It is a


fourth degree polynomial function with no odd terms. Therefore it is
possible to make a change of variables y = x2 to get the well known
2
f (y) = ay + by + c. Once know the roots of f (y) = 0, we can go
back and nd the roots of f (x) = 0.
• When thinking about the number of roots, we have three cases that
can happen to y and then for each of them there are a few cases for
x.
• To get specic values of the roots, we can work backwards and reverse-
engineer them.

Figure 10.17: Tabulated values and graph of a bi-quadratic function.

Solution: An example of a bi-quadratic function is shown in Figure 10.17.


There are the following possibilities:

• No real roots in case f (y) = 0 had no real roots (the whole graph lies
above or below the x-axis).
• One real root, for example in case f (y) = 0 has one root equal to 0
and one negative root.
10.4. LAB PROBLEMS 343

• Two real roots, for example in case f (y) = 0 has one positive and
one negative root.

• Three real roots, in case f (y) = 0 has one root equal to 0 and one
positive root.

• Four real roots in case f (y) = 0 has two positive roots.

4. Area under the curve


Tabulate a function f (x) (constant, linear with only parameter a) for
nonnegative real numbers and areas under the graph f (x) from 0 to x
using a suitable formula for calculation of area. Draw the graph of the
function f (x) and area Af (x). What relationship between f (x) and Af (x)
do you observe?

Hints:
• When calculating the area under a (positive) constant function, we
are calculating the area of rectangles. One side of the rectangle is
the constant f (x) = c and the other is the independent variable x.
In this case, Af (x) grows as x grows.
• When calculating the area under a linear function, it is easier to start
with f (x) = ax. In this case, we are calculating areas of triangles. It
is of course possible to use a general linear function f (x) = ax + b for
positive b and the qualitative results would not change much, but we
would have to calculate with trapezoids instead of triangles or split
the problem into triangle and rectangle.

• We could extend this problem and calculate area under dierent


curves, e.g. parabola, but in this case, we would not have exact area
calculations. We could approximate the area by cutting it into slices
(rectangles and trapezoids) and adding the areas of those.

Solution: In Figure 10.18 we show a constant f (x) and its area function
Af (x), which turns out to be linear. We also show a linear f (x) and its
area function Af (x), which turns out to be a parabola. This is not a
coincidence. If we repeated this procedure for higher order polynomials
the area function is always a one-order-higher polynomial.
344 CHAPTER 10. REAL FUNCTIONS  PART 1

Figure 10.18: Area under the graph: for a constant and for a linear function.

Area under a parabola


Create a sheet which calculates and displays the values of Af (x) for
a quadratic function f (x). Consider dierent options for calculating
the area.
Chapter 11

Real functions  part 2

11.1 Lecture overview

11.1.1 Cubic, polynomial and rational functions


Cubic function
A cubic function has the form f (x) = a · x3 + b · x2 + c · x + d, where a 6= 0, b, c, d
are real parameters.

Problem 11.1 Zeros of cubic function:


Draw graphs of three cubic functions: one that has one zero point, one that has
two zero points and one that has three zero points.

Hint: The graphs can be very similar, it is the shift in y -coordinate that makes
a dierence.

Problem 11.2 Monotonicity of cubic function:


Draw graphs of three cubic functions: one that has one interval of monotonicity,
one that has two intervals of monotonicity and one that has three intervals of
monotonicity.

Problem 11.3 Extremes of cubic function:


Find the extremes of f (x) = 2x3 − 3x2 + x.

345
346 CHAPTER 11. REAL FUNCTIONS  PART 2

Solution: The function f (x) has three zero points: 0, 1/2 and 1. It has a
local maximum at approximately 0.211325 and local minimum at approximately
0.788675. It does not have a (global) minimum or maximum.

Polynomial functions
A polynomial function has the form f (x) = an · xn + an−1 · xn−1 + · · · + a2 · x2 +
a1 · x + a0 .

11.1.2 Rational functions


Rational functions are dened as a ratio of polynomials, e.g. f (x) = x1 . The
graph of this function is a hyperbola, the domain is D(f ) = R − {0} and range
H(f ) = R − {0}. The graph of the function never intersects the lines x = 0 and
y = 0, but gets arbitrarily close to them. We call such lines asymptotes.

Problem 11.4 Asymptotes:


What are the asymptotes of

3
f (x) = ?
x−4

Solution: y = 0 and x = 4.

11.1.3 Exponential functions


Starting point
We start from a sequence {2n }∞
n=0 . By generalising this sequence, we get a func-
tion that is dened not only for natural numbers but also for all real numbers:
f (x) = 2x .

Problem 11.5 Interest rate:


How do we calculate interest at times which are not natural numbers?

Hint: We have already looked at this for rational values of exponent in Section
8.4.1.

Problem 11.6 Bacteria population:


How does the population of bacteria grow in time, not only in discrete time
intervals such as minutes?
11.1. LECTURE OVERVIEW 347

Solution: If we had z bacteria at the beginning and this number grows 10% per
minute, in 5 minutes we have: z · 1.1 · 1.1 · 1.1 · 1.1 · 1.1 = z · 1.15 bacteria. In 20
1
seconds, we have z · 1.1 3 bacteria.
If there were z bacteria at the beginning, and z · 1.110 after 10 minutes, how
many were there in the middle?
z+z·1.110
It is not but rather:
2

z · z · 1.110 = z · 1.15 .

Desired properties
1
How do we dene f (x) = 2x for x = 1, x = 0, x = −1 and x= 2 , i.e. what are
the values f (1), f (0), f (−1), f ( 12 )?
We want to keep the rule:

22 · 27 = 22+7 = 29

We are looking for a function for which:

f (1) = 2, f (x + y) = f (x) · f (y)

We start by examining specic values of x and y:

x = 0, y = 0, then f (0 + 0) = f (0) · f (0), then f (0) = f (0)2

This is only true for f (0) = 0 and for f (0) = 1.


If we go with f (0) = 0, we get a constant zero function. Therefore we select
f (0) = 1.
f (2) = f (1 + 1) = f (1) · f (1)
1
f (0) = f (1 − 1) = f (1) · f (−1), then 1 = 2 · f (−1), then f (−1) =
2
 
     2
1 1 1 1 1
2 = f (1) = f +
=f ·f , then 2=f
2 2 2 2 2

 
1
then f =± 2
2
1

Here we only use +, therefore f ( ) = 2. So:
2
a a √
b
f = 2 b = 2a
b
348 CHAPTER 11. REAL FUNCTIONS  PART 2

2
√ 
To nd the value 2 , i.e. to calculate f (x) for an irrational x, f 2 , we use
√ a
√ √ 
fractions. 2 6=
b but there are many fractions that are close to 2. f 2 is
the smallest upper bound of the set

n a a a √ o
M = 2 b ; ∈ Q, 0 < < 2 .
b b

If we complete the denition of exponential function in this way, its graph is


going to be continuous for all rational and irrational numbers.

Exponential function
Exponential function is denoted by ax , a ∈ R+ . The domain is D(f ) = R and
+
the range is H(f ) = R . A special case of exponential function is f (x) = ex .

It is sucient to calculate ex :

2x = ex·ln 2

3x = ex·ln 3

ax = ex·ln a = ec·x

The function ex can be evaluated using innite series:


x x2 x3 x4 X xn
ex = 1 + + + + + ... =
1 2 6 24 n=0
n!

11.1.4 Logarithmic functions


Logarithms and their properties
We derived the exponential function from the rule f (x + y) = f (x) · f (y). For
a logarithmic function, we use the rule f (x · y) = f (x) + f (y). Logarithm log2 x
is such an exponent of 2 which hits x, e.g. log2 16 = 4.

value x 2 4 8 16 32 64 128 256 512


exponent log2 x 1 2 3 4 5 6 7 8 9
11.1. LECTURE OVERVIEW 349

Multiplication using logarithms


If we want to multiply 4 by 16, we can rst change the product of 4 and 16 to
product of powers of 2, then add the exponents and look up the result in the
table above.
4 · 16 = 22 · 24 = 22+4 = 26 = 64
If we want to multiply 7 · 33, we choose approximate values, e.g.

.
7 · 33 = 23 · 25 = 23+5 = 28 = 256.
The correct result is 231, so the calculation was just an approximation. We
would get an exact result, if we knew the powers of 2 which give values 7 and
33. We call such exponents binary logarithms, i.e. log2 7 a log2 33. In the
past, logarithms have indeed been used for multiplication of large numbers and
logarithmic tables were a desired possession of medieval navigators.

Base of the logarithm


Depending on the base we use, we call the logarithm binary (2), decimal (10)
and natural (e). We denote them log2 x, log10 x = log x and loge x = ln x.

Logarithm and exponential


The functions ln x and ex are mutually inverse. Thus it is true that:

ln ex = x ln e = x and elnx = x.
This also holds for other bases, e.g. log x and 10x are also mutually inverse.

Stirling formula
After taking a logarithm of a factorial n! = 1 · 2 · 3 · 4 · 5 · . . . · n, we get:

ln(n!) = ln 1 + ln 2 + ln 3 + ln 4 + . . . + ln n.

This equality is used to derive an approximation of a factorial, that is called


Stirling formula :
√  n n
n! ≈ 2πn .
e
You may encounter this formula for example when working with binomial
distribution, trying to estimate expressions containing factorials.
2n 1

For n = 30, compare the exact value of expression
n 22n with its approx-
350 CHAPTER 11. REAL FUNCTIONS  PART 2

imation using the Stirling formula. Show that for smaller n, e.g. n = 5,
the approximation is less precise.

11.1.5 Trigonometric functions


Where do they appear?
The most often used trigonometric functions are sine and cosine, denoted by
f (x) = sin(x) and g(x) = cos(x) respectively. We encounter them for exam-
ple when calculating with angles in a right triangle or when using the law of
cosines c2 = a2 + b2 − 2ab cos γ in a general triangle. (What is its connection
to Pythagorean theorem?) The functions sine and cosine are used in analysis of
periodic oscillations, e.g. in sound or signal processing.

Sine
The function sin x is dened for all real numbers. Its range is the closed interval
h−1, 1i. Its zero points are integer multiples of π . sin x is periodic with period
2π . Thus it is true that sin(x) = sin(x + 2π). Shifting the sine function by π2 ,
we get a cosine.

Problem 11.7 Determining the period:


x x
 
What is the period of these functions? sin(2x), sin 2 , sin 2π , 2 sin x, 2 +
sin x, sin(x − 2)?

Cosine
The function cos x is dened for all real numbers. Its range is the closed interval
π
h−1, 1i. Its zero points are
2 + kπ , where k ∈ Z. cos x is periodic with period
2π .

Sine and cosine as innite series


The functions sin x and cos x can be expanded into innite series:

x3 x5 x7
sin(x) = x − + − + ...
3! 5! 7!

x2 x4 x6
cos(x) = 1 − + − + ...
2! 4! 6!
11.1. LECTURE OVERVIEW 351

As a consequence, we can relate the functions ex , sin x a cos x (This can be


veried using the corresponding innite series.):

eix = cos x + i sin x

From this follows the beauty queen of mathematical formulas:

eiπ + 1 = 0.

Tangent
Another trigonometric function is called a tangent, denoted by f (x) = tan(x)
or sometimes f (x) = tg(x). Its properties can be derived directly from its
denition
sin(x)
tan(x) = .
cos(x)
It has the same zero points as sin x. The domain are all real numbers except
those for which cos x = 0. Its asymptotes are dened by x = π2 , x = π2 + π etc.,
π
in general, x =
2 + kπ , where k ∈ Z. The range of tan x is R and it is a periodic
function.

Cotangent
A twin function to tangent is the cotangent function. It is denoted by g(x) =
cot(x) or sometimes g(x) = cotg(x). Its properties also follow from its denition

cos(x)
cot(x) = .
sin(x)
It has the same zero points as the function cos x. The domain are all real
numbers except those for which sin x = 0. Its asymptotes are dened by x = π ,
x = 2π etc., in general, x = kπ , where k ∈ Z. The range of cot x is R and it is
a periodic function.

Problem 11.8 Measuring function change over short interval:


Suppose we select several points x1 , x2 , . . . , xn , . . . , xN in the domain of a func-
tion f. They might or might not be regularly spaced. And then we look at the
value of the following ratio for dierent n ∈ {1, 2, . . . , N }:

f (xn+1 ) − f (xn )
g(x) = .
xn+1 − xn
352 CHAPTER 11. REAL FUNCTIONS  PART 2

g(x), depending on the function f (x).


Consider the properties of this ratio, How
does g(x) look at parts of the domain where f (x) is increasing, decreasing? How
does it look at an extremal point of f (x)?
11.2. QUESTIONS 353

11.2 Questions

1. Write how much is

a) 23 · 25 =
b) 2−3 · 25 =
c) 2−3 · 2−5 =
d) (−2)3 · 25 =
e) (−2)3 · 2−5 =
1
f) 2 2 · 24 =
2. Find the function f (x) for which f (1) = 3 and f (x + y) = f (x) · f (y).

3
3. Explain how do we get the value 2 .

4. Why is it useful to use the function f (x) = ex ?


5. Write the function f (x) = ex as the sum of innite series.

6. Find the function f (x) for which f (x · y) = f (x) + f (y).



5n
P
7. Find the sum of innite series
n! .
n=0

8. How much is 14log14 5 and how much is 5log5 14 ?


9. What is the relation between Pythagorean theorem and cosine theorem?

10. What kind of phenomena are modeled by the sine function?

11. How are the functions sin x, cos x, tan x, cot x related?

12. Find f (x) and g(x) such that f (x) = g(x + π2 ).


13. Find a function for which f (x + y) = f (x) · f (π/2 − y) + f (y) · f (π/2 − x).
14. Find a function for which f (x) = x − x3 /3! + x5 /5! − x7 /7! + . . .?
15. Find a function for which f (x) = 1 − x2 /2! + x4 /4! − x6 /6! + . . .?
16. Fix the equality ex = sin x + cos x.
17. Draw the functions in one graph: sin x, sin 2x, 2 sin x, sin(x + π).
354 CHAPTER 11. REAL FUNCTIONS  PART 2

11.3 Problem set

1. Cubic functions
Sketch the graphs of f : R → R. What do these graphs have in common
and how do they dier?

a) f (x) = (x − 3)(x − 1)(x + 2)


b) f (x) = 3(x − 3)(x − 1)(x + 2)
c) f (x) = −2(x − 3)(x − 1)(x + 2)
d) f (x) = (x − 3)(x − 1)(x + 2) + 4

2. Roots and extremes


Find cubic functions f that have 0, 1, 2, 3, 4 zeros, i.e. roots of the equations
f (x) = 0. How many and what kinds of extremes do they have? Can you
estimate the location of the extreme values?

3. Hyperbolae
Sketch the graphs of f : R → R.
1
a) f (x) = x−1
1
b) f (x) = (x−1)(x+2)
−1
c) f (x) = (x−1)(x+2)
1
d) f (x) = x−1 +2
1
e) f (x) = (x−1)+2
−1
f) f (x) = (x−1)(x+2)+1
1
g) f (x) = (x−1)(x+2) +1

4. Periodic functions
Write the function f which meets the following criteria:

a) Period = 10π , range = h0, 3i, f (0) = 0


b) Period = 10π , range = h0, 3i, f (0) = 1.5
c) Period = 4π , range = h2, 14i, f (0) = 14
d) Period = π/2, range = h−3, 3i, f (0) = −3
e) Period = 8, range = hπ, 5πi, f (0) = 4π
11.3. PROBLEM SET 355

5. Addition to product
Find the function f which meets the following criteria:

a) f (x + y) = f (x) · f (y), f (0) = 1 and f (1) = 2


b) f (x + y) = f (x) · f (y), f (0) = 1 and f (1) = 1/2
c) f (x + y) = f (x) · f (y), f (0) = 1 and f (2) = 9
6. Product to addition
Find the function f which meets the following criteria:

a) f (x · y) = f (x) + f (y), f (1) = 0 and f (2) = 1


b) f (x · y) = f (x) + f (y), f (1) = 0 and f (2) = 1/2
c) f (x · y) = f (x) + f (y), f (1) = 0 and f (9) = 2
356 CHAPTER 11. REAL FUNCTIONS  PART 2

11.3.1 Hints and solutions


1. Cubic functions
Sketch the graphs of f : R → R. What do these graphs have in common
and how do they dier?

a) f (x) = (x − 3)(x − 1)(x + 2)


b) f (x) = 3(x − 3)(x − 1)(x + 2)
c) f (x) = −2(x − 3)(x − 1)(x + 2)
d) f (x) = (x − 3)(x − 1)(x + 2) + 4

Hints:
• In each case we can sketch the graph by evaluating the function in
a reasonable number of points tabulated with a reasonable step, for
example values from −5 to 5 with the step 0.5. We then draw these
points in a coordinate system and connect them. For these functions
though, there exists a more ecient method.

• If we multiply the individual factors, we nd out that all of them


are cubic functions. In general, a graph of a cubic function is a
twice-bent curve. There are some special cases, when the graph is a
simpler curve of the x3 type. Which of these curves do we have in
this problem?

• Let us look at f (x) = (x − 3)(x − 1)(x + 2) rst. The function is


expressed as a product, which allows us to evaluate it very easily for
one type of arguments x. For which x can we easily evaluate this
function? This is also an answer to a simpler question: Which three
real values can be substituted for x and give us the functional value
practically without any calculation?

Once we realise we are talking about roots of the function, we are half
done. The graph of a function crosses the x-axis exactly at the roots.
From which direction? Does it come to the rst root from above or
from below of the x-axis? And which way does it leave from the last
root? To answer these questions, we can think about what values
does the function have for inputs close to ∞ and −∞. In practice, it
is sucient to consider the signs of f (−10) and f (10).
If we answered all these questions, we should be able to draw the
correct curve passing the roots of the function. We can verify the
11.3. PROBLEM SET 357

sketch by checking some other functional values, such as f (0) or f (2),


etc. The exact values might not lie precisely on the graph, but they
have to have the correct sign.

• To sketch the other graphs, we can start by checking how do they


dier from the function in a). The function in b) has three times
larger values than the function in a), therefore its graph is stretched
three times in the vertical direction and keeps the same zeros.

• The function in c) behaves similarly, but is multiplied by a nega-


tive number. This means that all function values (except the roots)
change their sign. How does this manifest in a graph?

• The function in d) is shifted up by 4. In this case, the shape of the


graph remains the same, but the roots change. A careful examina-
tion of function values between the second and the third root of the
original function reveals whether the number of roots remains the
same or decreases.

Solution: To check the solution, we can copy the formula for the function
into any of the freely available tools, webpages or softwares that can draw
graphs, such as WolframAlpha or Desmos.

2. Roots and extremes


Find cubic functions f that have 0, 1, 2, 3, 4 zeros, i.e. roots of the equations
f (x) = 0. How many and what kinds of extremes do they have? Can you
estimate the the location of the extreme values?

Hints:
• We have already worked with a cubic function in the previous prob-
lem. This experience should give us a hint that two of the ve cases
do not have a solution. The remaining three cases can be answered
using a multiplicative form of the function formula, which is very
convenient when working with roots.

• Every cubic function with a positive coecient multiplying x3 takes


on negative values for suciently large negative inputs and positive
values for suciently large positive inputs. Its graph thus comes from
the negative values of y -coordinates and at some point has to leave
to the positive values. The situation is reversed (with respect to the
x-axis) for a negative coecient by x3 . Clearly, in both cases the
graph of the function has to cross the x-axis at some point (and this
358 CHAPTER 11. REAL FUNCTIONS  PART 2

can be proven by the tools of mathematical analysis). This crossing


is a zero of the function and therefore every cubic function has at
least one root. This means there is no cubic function that would
have zero roots.

• A function that has four zeros has to wiggle (switch from growth to
decrease or vice versa) at least three times. No cubic function can do
that. If we consider the product form of the formula for f (x) which
has four rootsa, b, c, d, it would have to contain (at least) the terms
(x − a)(x − b)(x − c)(x − d). This implies a polynomial of at least
fourth degree. That it another reason why there is no cubic function
with four roots.

• We saw examples of a cubic function with three roots in the previous


problem. Suppose we want the roots −2, 1 and 3. The function is
then f (x) = c(x − (−2))(x − 1)(x − 3) = c(x + 2)(x − 1)(x − 3), where
c is a real non-zero constant. We see that we have three roots and
thus a polynomial of third degree.

• If we want a cubic function with fewer roots, we can shift its graph
up or down. For one root we can also use various multiples and shifts
of a simple cubic function x3 .
• There is also a simpler solution. If we want a cubic function to
have one root, its formula in the product form has to contain exactly
three root terms of the form (x − a). The number a is the solution
of equation f (x) = 0 and thus a zero or root of the function. When
we do not need three dierent roots, we can repeat some of them.

• How do we get a cubic function with exactly two roots, e.g. 2 and
4? We need to use the root terms (x − 2) and (x − 4) and add one
more term that does not result in a new solution of f (x) = 0. We
can repeat one of the already used terms. We recommend checking
both of them and comparing the resulting graphs. To get a cubic
function with just a one root, we use the same root term three times
(possibly multiplied by a constant).

• We are not going to give an exact answer to the question about


extremes but rather estimate their positions from the graphs of the
function. The answer depends on the number of roots. The location
of the extremes changes with the roots. Vertical shifts of the function
change the value of the extremes. Which cubic functions do not have
any extremes?
11.3. PROBLEM SET 359

• Graphs of the proposed functions can again be displayed and checked


in suitable available graphical tools.

Solution: Here we provide a few examples of functions that meet the


criteria. Many more can be obtained by small modications.

In case of three roots, we have for example f (x) = (x − 2)(x − 4)(x − 8)


with the roots 2, 4 and 8, Figure 11.1. (Functions in a), b) or c) in the
previous problem work too.) One of the local extremes lies between the
rst and the second root, i.e. in the interval (2, 4) and the other between
the second and the third root, i.e. in the interval (4, 8). Note and check
that they do not lie exactly in the middle of these intervals.

Figure 11.1: Cubic function.

To obtain a function with two roots, we modify it to f (x) = (x−2)2 (x−4)


2
or f (x) = (x − 2)(x − 4) . One of the local extremes lies in the interval
(2, 4) and the other is exactly at the double root.
To obtain a function for which the equation f (x) = 0 has a unique solution,
we need a multiple root, such as f (x) = (x − 2)3 or f (x) = (x − 4)3 .
These functions do not have any extremes. Alternatively, we can use a
vertical shift and we get for example f (x) = (x − 2)(x − 4)(x − 8) + 10 or
f (x) = (x − 2)(x − 4)(x − 8) − 5. These functions have local extremes at
the same points x as the original function f (x) = (x − 2)(x − 4)(x − 8).

3. Hyperbolae
Sketch the graphs of f : R → R.
360 CHAPTER 11. REAL FUNCTIONS  PART 2

1
a) f (x) = x−1
1
b) f (x) = (x−1)(x+2)
−1
c) f (x) = (x−1)(x+2)
1
d) f (x) = x−1 +2
1
e) f (x) = (x−1)+2
−1
f) f (x) = (x−1)(x+2)+1
1
g) f (x) = (x−1)(x+2) +1

Hints:
• The functions in this problem have the form of fractions with the
variable x in the denominator. Therefore the zero points of the de-
nominators are points which are excluded from the domain. It is
important to examine the behavior of the function in the immediate
vicinity of these points. Therefore, to sketch their graphs, it is not
sucient to tabulate the function values with a standard step 1 or
0.5, but rather we need to determine the asymptotes  lines to which
the graph tends for innite values of arguments x or function values
f (x)  and the function behavior close to these asymptotes.

1
• We start with function f (x) =
(x−1)(x+2) . First, we realise what
its values are for very large negative or very large positive x. The
denominator grows with the multiplication of terms. The value of
f (x) is its reciprocal, therefore a very small number close to zero.
We still need to consider its sign. In both cases, the function will
tend to zero both for x → ∞ and x → −∞. This means that the line
y = 0, i.e. the x-axis, is the horizontal asymptote in this case.

• The second type of asymptotes corresponds to the zero points of the


denominator in which the function is not dened. In this case they
are x = −2 x = 1. What are the values of the function in the
and
immediate vicinity of x = 1? We can try to calculate the values f (x)
for x = 0.9, x = 0.95, x = 0.99, x = 0.999. Similarly from the other
side for values x = 1.1, x = 1.05, x = 1.01, x = 1.001. Can you
guess and draw the graph for values of x even closer to 1? Similar
consideration should be given to the values of x close to number −2.
11.3. PROBLEM SET 361

• We can also evaluate the behavior of the function near these points
just qualitatively, e.g. the term (x−1) is very small for values of x very
close to 1. The whole denominator remains small when multiplied
by the term (x + 2), which is about 3 in this case. The value f (x)
is the reciprocal of the denominator and therefore a large number
here. Since x can get arbitrarily close to 1, the value of f (x) will
tend to innity. Here we also need to be careful about the sign of
the denominator, which determines for which values of x we get +∞
and for which −∞. In all cases, the vertical lines x = −2 and x = 1
are also the asymptotes of the function.

• The other cases in this problem are variations on the one we just dis-
cussed. We should carefully consider the impact of their dierences
on the graphs. A negative value in the numerator ips the graph
symmetrically about the x-axis. Adding a constant to the denomi-
nator changes its zero points, i.e. points in which the function is not
dened and thus the location of the vertical asymptotes. Adding a
constant to the whole fraction shifts the graph up or down, which
results in the shift of the horizontal asymptote.

Solution:
Once we have a sketch, we should compare it with a graph obtained by
a suitable software tool. If they do not match, we need to check the
dierences and look for what might have caused them.

Primarily, we should check the asymptotes. In a) they are the x-axis and
the line x = 1. f (x) is increased by 2. The
In the case d), the function
graph thus shifts 2 units up. The asymptote x = 1 remains unchanged
by this shift, but the asymptote that was at the x-axis is now moved to
y = 2.
In e), we can rewrite the function as f (x) = 1/(x + 1). The horizontal
asymptote is the x-axis, the vertical is x = −1.
In b), we have the horizontal asymptote x-axis and two vertical asymp-
totes: x = −2 and x = 1. Case c) is a mirror image of this, but the
asymptotes remain the same. In g), the graph is shifted one unit up and
the horizontal asymptote is moved to y = 1. In case f ), there is a new
quadratic expression in the denominator with new roots and thus new
vertical asymptotes.
362 CHAPTER 11. REAL FUNCTIONS  PART 2

4. Periodic functions
Write the function f which meets the following criteria:

a) Period = 10π , range = h0, 3i, f (0) = 0


b) Period = 10π , range = h0, 3i, f (0) = 1.5
c) Period = 4π , range = h2, 14i, f (0) = 14
d) Period = π/2, range = h−3, 3i, f (0) = −3
e) Period = 8, range = hπ, 5πi, f (0) = 4π

Hints:
• The core of this problems is to ne-tune a correct periodic function
so that it meets three properties: period length, range H(f ) and the
function value at x = 0, which in fact represents a correct horizontal
shift.

• In the following we use the function sin(x) and its modications but
we could work with cos(x) sin(x) is 2π and its
as well. The period of
h−1, 1i. The function values at the interesting points x = 0,
range is
x = π/2 and x = 3π/2 are 0, 1 and −1 respectively. It is a good
idea to draw this function in a software tool and observe the changes
resulting from the following modications.

• First we are going to change the period. To draw one period of the
basic function sin(x) x to run over
we need the independent variable
all values from the interval h0, 2πi. If we change the function to
f (x) = sin(πx), the constant π helps the variable x cover the domain
faster. To draw one period of the function sin(πx) it is sucient for
the independent variable x to run over π -times shorter interval h0, 2i.
The period of the function sin(πx) is thus π -times shorter and equal
to 2.

Conversely, the division by 2 in the formula f (x) = sin(x/2) slows


down the growth of x by a factor of 2. The independent variable
thus needs to cover twice as big interval h0, 4πi in order to draw one
period. The period of sin(x/2) is therefore 4π .
With this in mind, we can correctly determine the value of parameter
c in f (x) = sin(cx) to achieve the correct period in problems a) to e).
Note that these changes do not change the range of the functions.
11.3. PROBLEM SET 363

• We have already discussed transformation of intervals into other in-


tervals in Section 7.4. Here we need to transform the range h−1, 1i
of sin(x) into another interval. First, we make sure that the size of
the range interval is correct. For example, if H(f ) is supposed to be
h2, 14i, we need to increase the original size of range six-fold from
2 to 12. For that we modify the function to 6 sin(x). However, the
range of this function is h−6, 6i, so we still need to shift it into the
correct position h2, 14i. A modication to 6 sin(x) + 8 does precisely
that.

• The last property we need to ensure is the function value at x = 0.


Note that in all the cases we want f (0) to be either the minimum,
maximum or middle of the range. For the original sin(x) those would
be values −1, 1 or 0. sin(0) = 0, we do not need any changes to
Since
achieve the middle value. If we want sin(x) = 1, we need to remember
that the maximum of the sine function is reached at, e.g. x = π/2.
Therefore the graph of the function needs to be shifted to the left by
π/2, which can be done by modifying the function to sin(x + π/2).
• Since sin(3π/2) = −1 (or sin(−π/2) = −1), if we want to achieve the
minimal value at x = 0, we need to shift the graph 3π/2 units to the
left (or π/2 units to the right). This can be done by modifying the
function to sin(x + 3π/2) or sin(x − π/2).

• To solve the problem, it is now sucient to perform all these modi-


cations one after another. The solution can be veried by graphing
the individual steps as well as the nal result in an appropriate soft-
ware tool.

Solution:
Here we show one of the possible answers for each case:

a)
3
2 sin( x−5π/2
5 )+ 3
2 , Figure 11.2.
3 3
b)
2 sin(x/5) + 2
c) 6 sin( x+π
2 )+8
d) 3 sin(4(x − π/8))
e) 2π sin( π(x+2)
4 ) + 3π

5. Addition to product
Find the function f which meets the following criteria:
364 CHAPTER 11. REAL FUNCTIONS  PART 2

Figure 11.2: Sine function.

a) f (x + y) = f (x) · f (y), f (0) = 1 and f (1) = 2


b) f (x + y) = f (x) · f (y), f (0) = 1 and f (1) = 1/2
c) f (x + y) = f (x) · f (y), f (0) = 1 and f (2) = 9
Hints:
• In this problem, we have two types of information that we can use
to nd the functions: a general relation  the so-called functional
equation, which our functions satises  and its values at two specic
points. The functional equation is the same in all three cases and is
mentioned in the lecture. From there we know that the only functions
that satisfy it are exponential functions.

• Once we know we are dealing with exponentials, the only thing that
remains open is to gure out the base of the function in each case.
The functional values should help with that. One of the two is more
helpful than the other. Which one?

• We can also use a software tool for drawing the exponential functions,
guesstimate the base and check that the function has the desired
properties.

Solution: For an exponential function, the equality f (0) = 1 means a0 = 1.


+
Since this is true for all admissible bases a∈R , we do not get any new
information about the function from here. We need to focus on the other
two equalities.

a) We need a1 = 2. This is true for a=2 which gives us the function


x
2 .
11.3. PROBLEM SET 365

1
b) We need a1 = 2 . The solution is thus a decreasing exponential ( 21 )x ,
Figure 11.3.

c) Here we need a2 = 9. There are two values that satisfy this equation:
a = −3 and a = 3. The base of the exponential has to be a real
positive number, therefore we get just one solution: the function 3x .

Figure 11.3: Exponential function.

6. Product to addition
Find the function f which meets the following criteria:

a) f (x · y) = f (x) + f (y), f (1) = 0 and f (2) = 1


b) f (x · y) = f (x) + f (y), f (1) = 0 and f (2) = 1/2
c) f (x · y) = f (x) + f (y), f (1) = 0 and f (9) = 2

Hints:
• Similarly to the previous problem, also here we are looking for three
functions that satisfy the same functional equation. The rule it de-
scribes is unique and typical for logarithmic functions. The functions
dier by their base which we need to determine. For each function,
we are given two functional values. We can use one of them to de-
termine the base. The other serves as conrmation that we have the
correct type of the function. Can you tell which is which?

• Transforming the functional equation into x·y = f −1 (f (x)+f (y)) not


only helps us to re-discover it, but also reveals the historical reason
for discovery of logarithmic functions. In 16th and 17th centuries,
people were trying to simplify multiplications of two large numbers.
Instead of multiplying them, they could nd the logarithms of x and y
366 CHAPTER 11. REAL FUNCTIONS  PART 2

in tables, add these (smaller) values and use inverse tables to lookup
the result to get the product x · y.
• In order to determine the base of the logarithm, we should realise
what does the logarithm tell us: If we are looking for logb x, we are
essentially asking, to what power do we need to raise the base b to
get the value x? The relation f (1) = 0 tells us that logb 1 = 0. This
is not very helpful, since for every positive real number b we have
b0 = 1.
Therefore, the crucial piece of information is in the nal relations.
For example, in a) we are looking for such logarithm base b that
gives us 2 when raised to 1. For which base do we get b1 = 2?

Solution: Since the last hint is quite explicit, we assume that the bases
of the logarithms can now be easily determined. Therefore, here we only
provide the answers without additional explanation:

a) We are looking for a base which gives 2 when raised to the power 1.
Therefore b=2 and the function is log2 x.
1
b) Now we are looking for a base which gives 2 when raised to power
√ 2,
i.e. when we take a square root. Since 2= 4, we have b=4 and
the function is log4 x.
c) Finally, we have 9 = b2 . The base is 3 and the function is log3 x,
Figure 11.4.

Figure 11.4: Logarithmic function.


11.4. LAB PROBLEMS 367

11.4 Lab problems

1. Trigonometric functions
Draw the graph of a sine function on the interval approximately (−20, 20)
and save it for later comparison.
Then observe how the graph changes if the function changes to a sin(x),
sin(x) + a, sin(ax), sin(x − a) for various values of parameter a and gen-
eralise to a sin(bx + c) + d. Next, look for parameters that change the
range of sine function to (−2, 2), (−4, 4), (0, 4), (−3, 7), (0.5, 1.5), (3, 3.1),
(1/2, 1/3), (2/5, 4/7). Can the parameters be determined from the end-
points of the range interval?
Change the period of the sine function. Try to double it, triple it, quadru-
ple it. Make it half, quarter, etc. Which parameter causes this? How to
cause the period to be 2, 1, 5, 10?
Shift the sine curve to the left and to the right. Which parameter needs
to be changed and how? Can you make the graph intersect the
√ √ y -axis at
the point 1/2, 2/2, − 3/2?
Using the examples above, nd the following sine curves:

• Period = π/2, range = h−2, 2i, f (0) = 1


• Period = 2, range = hπ, 2πi, f (0) = π
• Period = 3π , range = h3, 4i, f (0) = 3.25
• Period = 5π , range = h4, 14i, f (0) = 4
• Period = 10, range = hπ, 5πi, f (0) = 4π

• Period = 10π , range = h0, 2i, f (0) = 1 + 3/2

• Period = 2, range = h−1, 1i, f (0) = − 2/2

2. Increase and decrease of a function, intuitive derivative


Tabulate a quadratic function ax2 + bx + c at 20 points, using input pa-
rameters a, b, c and lower and upper bounds of the desired range. In
the next column watch the rate of change of the function relative to the
change in x, i.e.
f (xn+1 ) − f (xn )
.
xn+1 − xn
Draw the graph of the original function and the graph of the function
describing its rate of change. How are they related?
Which changes of the quadratic function change and which do not change
368 CHAPTER 11. REAL FUNCTIONS  PART 2

the rate of change function? How are the important points and properties
of the two functions related?
Do the same for a cubic function? What kind of function describes its
rate of change? How are they related?
Do the same also for sine, cosine and the exponential function.

3. Value of exponential function calculated at irrational points


Calculate the value of an exponential function
√ ax for an irrational point
x, e.g. x = 2. The base a and the irrational number x are given as input
parameters.
For denominators 1, 2, 3, 4, 5, . . . , 100 nd the best lower estimates of the
irrational number by a fraction with the given denominator. For these
fractions k/l calculate the values ak/l . Display them in a chart and com-
pare them with a line drawn at ax (calculated by Excel). Check whether
k/l
the values a are getting closer to the exact value. How does the behav-
ior change if we sort the table according to the value k/l? How does the
behavior change for dierent bases and dierent irrational exponents?
11.4. LAB PROBLEMS 369

11.4.1 Hints and solutions


1. Trigonometric functions
Hints:
• This problem is very suitable for experimentation. As in previous
chapter, we again recommend Desmos [1]. Figure 11.5 illustrates
this environment.

• The Problem 4 from Section 11.3.1 is very similar to this problem


and its hints and solutions can be used here.

Figure 11.5: Changing amplitude and performing a horizontal shift of a sine


function.

2. Increase and decrease of a function, intuitive derivative


Hints:
• First, we tabulate the quadratic function at 20 values of the inde-
pendent variable x from the given range, similarly to Problem 2 in
Section 10.4.

• We need a column for calculation of the increase (decrease) of the


function values between two successive tabulated steps. In general,
this is an increase (decrease) of the function values f (x) divided by
the increase in independent variable x. The increase in the indepen-
dent variable is always the same in our case, therefore the calculation
can refer to a constant value of this step.
370 CHAPTER 11. REAL FUNCTIONS  PART 2

• We should draw the function values and the column with rate of
change into a common graph. The graph of the function is a parabola.
What is the graph of the rate of change? Try changing the lower and
upper bounds of the range for the independent variable. Also try
changing the parameters of the quadratic function and observe their
impact on the function representing the rate of change.

• To modify this worksheet for another function, all we need to do is use


a dierent formula for calculation of f (x). Everything else remains
the same.

• For an exponential function, we see that the graph of changes is very


similar to the original graph. Can you nd such a base of the expo-
nential function that the graphs are the same? For an exact answer,
we recommend using an interval h1, 2i or smaller. Another inter-
esting connection is between the functions sin(x) and cos(x). The
rate of change of a cubic function corresponds to another (simpler)
polynomial.

• The rate of change of a quadratic function is captured by a graph of


a linear function. Similarly, the rate of change of a cubic function
is captured by a one-degree smaller, i.e. quadratic, polynomial. The
exponential function that is identical to its own rate of change is the
ex which is one of the reasons behind its special status among the
exponential functions. The rate of change of sin(x) corresponds to
cos(x) and the rate of change of cos(x) corresponds to − sin(x).

Solution: An example solution is shown in Figure 11.6.

First we calculate the tabulation step in I5. Then we determine the values
of the arguments x in the column B and values of the quadratic function
f (x) = ax2 + bx + c given by the input parameters a, b, c in the column
D. We calculate the dierences in function values f (x) in the column E
and divide them by the constant step in the column F.
f (xn+1 )−f (xn )
The values of f (x) and its rate of change
xn+1 −xn can be shown
using a suitable x-y graph. We can observe that the rate of change is a
linear function. This linear function remains unchanged if we change the
parameter c of the quadratic function. Observe the changes caused by
changing the input parameters a and b.
11.4. LAB PROBLEMS 371

Figure 11.6: A quadratic function and its rate of change.

3. Value of exponential function calculated at irrational points


Hints:
• In this problem we follow a very similar approach to Problem 2 in
Section 5.4. For example, when we are looking for a fraction of the

formk/5, which approximates the value
√ 3 best from below, the
number k can be obtained by rounding 5 3 down. In Excel, this is
calculated using the formula = ROUNDDOWN(SQRT(3)*5;0).

• One column should contain the denominators l from 1 to 100. An-


other column should calculate the numerators k and the next one
fractions k/l. Then we can use the POWER() function to calculate
k/l
the values a .

• We should also create columns for the exact values (as the Excel
calculates them) and display them together with our approximations
in an appropriate chart.

Solution:
An example solution is shown in Figure 11.7. The input parameters are

3
entered in column K. Those shown correspond to calculation of 2 .
372 CHAPTER 11. REAL FUNCTIONS  PART 2

Figure 11.7: Exponential function at an irrational point approximated using


fractions.

In column A, we have tabulated the denominators from 1 to 50. In column


B, we use the formula = ROUNDDOWN(K 2*A4,0) to nd the optimal
numerator. In column D, we calculate the values
√ √
2k/l using = K1C3 . The
3
constant values 3 in column E and 2 in column F are used for drawing
the exact values.

It is highly recommended to experiment with the input base and expo-


nent and observe how the fractions k/l and powers ak/l approximate the
desired values. Also try changing the function ROUNDDOWN to regular
ROUND. What happens?
Chapter 12

Asymptotic approximations
and proofs

12.1 Lecture overview

12.1.1 Asymptotic approximations


Where do we see o and O?
When evaluating computational complexity of algorithms, it is worth considering
asymptotic approximations of sequences and functions. For example, if we look
at sorting algorithms, we nd out that BubbleSort is O(n2 ) and QuickSort is
O(n log n). What does the big O mean and which of the algorithms is better?
When considering the eciency of the algorithms, two things need to be
considered: How long does the computation last for a given size of input? And
how fast does this time grow with growing inputs? If we can write a functional
dependence of computational time on the size of the input, then these ques-
tions can be answered using analytical methods for asymptotic comparison of
functions with the help of O notation.
Little o is useful for approximations. In Section 11.1.3, we saw that for x
close to 0 the value of an exponential function (and similarly also values of
trigonometric functions) can be calculated using innite series:

x x2 x3 x4
ex = 1 + + + + + ...
1 2 6 24

373
374 CHAPTER 12. ASYMPTOTIC APPROXIMATIONS AND PROOFS

x3 x5 x7
sin(x) = x − + − + ...
3! 5! 7!
In practice, for technical or physics applications it is sucient to obtain the
value of ex or sin(x) with certain precision therefore we can stop the calculation
at some point (we sum only nite series). In doing this, we make an approxi-
mation error, which can be estimated if we know what we had neglected. For
example, if we take only the rst three terms when evaluating ex , we can say that
3
the approximation error is of the order O(x ), i.e. negligible when compared to
x2 , which is denoted by o(x2 ):
x x2
ex = 1 + + + o(x2 ).
1 2
If we take only the rst three terms when evaluating sin(x), we can say
that the approximation error is of the order O(x7 ), which is negligible when
compared to x5 :
x3 x5
sin(x) = x − + + o(x5 ).
3! 5!
We formulate the following denitions of asymptotic approximations for
functions (sequences) from N to R and their limits as n → ∞. However, they
can be extended to functions from R to R and limits in other accumulation
points, e.g. x → 0.

Little o notation
For two functions (sequences) f (n) and g(n) from N to R, we say that f ∈ o(g),
(sometimes also denoted f = o(g)) if and only if
f (n)
lim = 0.
n→∞ g(n)
We say that the function f is asymptotically smaller than g. This means that
the function f is signicantly smaller than g and we can neglect it. o(g) is a set
of functions.

Big O notation
For two functions f (n) and g(n) from N to R, we say that f ∈ O(g), (sometimes
also denoted f = O(g)) if and only if there exists a c ∈ R and an n0 ∈ N, such
that ∀n ≥ n0 we have:

|f (n)| ≤ c · |g(n)| or − c · |g(n)| ≤ f (n) ≤ c · |g(n)|


12.1. LECTURE OVERVIEW 375

The function f is asymptotically at most a constant multiple of g. This includes


all cases where f is asymptotically smaller than g . O(g) is a set of functions.

Theta notation
For two functions f (n) and g(n) from N to R we say that f = Θ(g) if and only
if f ∈ O(g) and g ∈ O(f ). We say that the function f diers from g at most by
a constant multiple.

Commentary
f ∈ O(g) essentially says: There is at least one constant c for which the inequal-
ity f (n) < c · g(n) holds for all n.
f ∈ o(g) says that: For any constant c > 0 we can nd a number n0 such that
the inequality f (n) < c · g(n) holds for all n > n0 .
The dierence between these two criteria is whether the functions can be asymp-
totically equal. Intuitively: big O says that f does not grow faster than g (it
can grow at the same rate or slower) and little o says f grows strictly slower
than g. In some sense, the big O is like ≤ and little o like <. f ∈ Θ(g) means
that the growth rate of f is the same as the growth rate of g.

So for example the following statements are true for big O and not for little o:
n2 ∈ O(n2 )
n2 ∈ O(n2 + n)
n2 ∈ O(200 · n2 )
200 · n2 ∈ O(n2 )

And the following statements are true for little o (and therefore also for big O):
n2 ∈ o(n3 )
n2 ∈ o(n!)
ln(n) ∈ o(n)

While the Θ relation is symmetric, the O and o clearly are not.

For many functions we can also use limits to determine lim f (n)
O. If the
n→∞ g(n)
exists and is nal (including the possibility that it is equal to 0), then f ∈ O(g).
Similarly, if the limit exists and is non-zero, then f ∈ Θ(g).
376 CHAPTER 12. ASYMPTOTIC APPROXIMATIONS AND PROOFS

O and Θ notation for complexity of algorithms


Formally, we should use the Θ notation when talking about the compu-
tational complexity of algorithms. Exactly speaking, when we say that
Algorithm A has computational complexity O(n2 + 3n), it means that the
complexity of A is asymptotically at most n2 + 3n. This does not exclude
the possibility that it could actually be better. Can you give such an ex-
ample?
However, in practice, people tend to use O in place of Θ and we adopt the
same approach when talking about computational complexity.

Problem 12.1 Asymptotic comparison:


For the functions f (n) = 2n2 and g(n) = 4n determine whether they are in any
of the following relations f ∈ o(g), g ∈ o(f ), f ∈ O(g), g ∈ O(f ).

Solution: We rst examine whether f ∈ o(g).

2n2 n
lim = lim =∞=
6 0.
n→∞ 4n n→∞ 2

Thus f is not asymptotically smaller than g . Next we consider the f ∈ O(g)


relation and so we look for a constant c such that |2n2 | < c·|4n| for all n starting
at n0 . That would imply |n| < 2c, which is a contradiction, because for any
xed c we can nd an n0 > c. Therefore f 6∈ O(g).

Now we try the reverse order

4n 2
lim = lim = 0.
n→∞ 2n2 n→∞ n

Therefore g is asymptotically smaller than f, i.e. g ∈ o(f ). When considering


g ∈ O(f ), we are looking for a constant c such that |4n| < c · |2n2 | for all n
starting at n0 . Suppose we take n0 = 2 and c = 2. We get the relation:

|4n| < 2 · |2n2 |


|n| < |n2 |

The last inequality holds for all n > n0 , so we have g ∈ O(f ).


12.1. LECTURE OVERVIEW 377

Related to the previous problem


Can we take a smaller c?

Problem 12.2 Asymptotic comparison:


2n−3
Find the asymptotic relation(s) between f (n) = n+5 and g(n) = 54.

Solution: 2n−3
n+5 1
lim = ... =
n→∞ 54 27
54
lim = . . . = 27
n→∞ 2n−3
n+5

So f 6∈ o(g), g 6∈ o(f ). The inequality

2n − 3
< c · |54|
n+5

holds for e.g. c=1 a n0 = 1. Therefore f ∈ O(g). Moreover,

2n − 3
|54| < c ·
n+5

holds for e.g. c = 54 a n0 = 10, so we also have g ∈ O(f ). The last two relations
together tell us that g ∈ Θ(f ) and vice versa. Note that we could have made
this conclusion also from either of the non-zero nite limits that we calculated
at the beginning.

Problem 12.3 Asymptotic comparison:


Find the asymptotic relation(s) between f (n) = 1+(n·sin(n π3 ))2 and g(n) = 4n.

Solution: The limit


1 + (n · sin(n π3 ))2
lim
n→∞ 4n
and the limit
4n
lim
n→∞ 1 + (n · sin(n π3 ))2
do not exist, so f 6∈ o(g), g 6∈ o(f ). The O relations also do not hold because
f oscillates between zero and a quadratic function and therefore (starting at a
suitably chosen n0 ) is alternatively above and below the linear function 4n.
378 CHAPTER 12. ASYMPTOTIC APPROXIMATIONS AND PROOFS

Problem 12.4 Asymptotic comparison:


Find the asymptotic relation(s) between f (n) = 2n and g(n) = 5n .

Solution:
2n
lim = ... = 0
n→∞ 5n

5n
lim = ... = ∞
n→∞ 2n

So we have f ∈ o(g) (and consequently also f ∈ O(g)), g 6∈ o(f ). The inequality

|5n | < c · |2n |


 n
5
< c
2

is not true for any c, because we can always nd an n0 such that for n > n0 is
the left-hand side greater than the right-hand side. So g 6∈ O(f ).

Problem 12.5 Asymptotic comparison:


Find the asymptotic relation(s) between f (n) = n11 and g(n) = en .

Solution:
n11
lim = ... = 0
n→∞ en

en
lim = ... = ∞
n→∞ n11

So we have f ∈ o(g) (and consequently also f ∈ O(g)), g 6∈ o(f ). The inequality

|en | < c · |n11 |


en
< c
n11
is not true for any c, because we can always nd an n0 such that for n > n0 is
the left-hand side greater than the right-hand side, e.g. for c = 1, n0 = 50. n0
can be found using the graph of en /n11 . So g 6∈ O(f ).

Problem 12.6 Asymptotic comparison:


Find the asymptotic relation(s) between f (n) = (log(n))k and g(n) = nk .
12.1. LECTURE OVERVIEW 379

Solution: Assuming k is a natural number

(log(n))k
lim = ... = 0
n→∞ nk
nk
lim = ... = ∞
n→∞ (log(n))k

So we have f ∈ o(g) (and consequently also f ∈ O(g)), g 6∈ o(f ). The inequality

|nk | < c · |(log(n))k |


 k
n
< c
log(n)

is not true for any c, because we can always nd an n0 such that forn > n0 is
the left-hand side greater than the right-hand side, e.g. for c = 1, n0 = 5. So
g 6∈ O(f ).

Redundant calculations
In the previous problems, we considered both limits for f /g and g/f . Could
we tell the value of one of them once we calculate the value of the other?
How? If so, this would save us half of the work when considering o.
Moreover, could we also deduce something for O from this one limit?

12.1.2 Proofs
In general, a mathematical theorem is stated in the form Suppose X is an object
that has properties A, B, C, . . . Then something else has to be true (about this
object or about some other object). A proof of such statement is a sequence
of logical steps which shows the validity of the statement without a doubt and
meets the necessary mathematical criteria. The proof typically:

• clears the doubts about the general validity of the statement,

• shows how the statement is related to other mathematical statements,

• helps us understand the statement and the meaning and importance of


terms used in it.

Sometimes it is useful to reformulate the original statement, because it might


be easier to prove the reformulated version.
There are several types of proofs some of which are listed here:
380 CHAPTER 12. ASYMPTOTIC APPROXIMATIONS AND PROOFS

Direct proof
Using a nite number of steps, we derive the statement from already proven
statements and/or axioms. When proving an implication A⇒B directly, we
add A to the assumptions and then show that B has to be true.

Problem 12.7 Inequality:


1√
Prove:
3−2 2
<6
√ √ √ √
Solution: 1√
3−2 2
· 3+2√2
3+2 2
= 3+2√2
32 −(2 2)2
= 3+2 2
9−8 = 3 + 2 2 < 3 + 2 · 3/2 = 6

To prove the inequality, we used the relation 2 < 3/2.

Problem 12.8 Property of divisibility by 2:


Prove: ∀n ∈ N 2|n ⇒ 2|n2

Solution: 2|n ⇒ ∃k ∈ N : n = 2k
⇒ n2 = 2k · 2k
⇒ ∃m ∈ N : n2 = 2m, it is m = 2k 2
⇒ 2|n2

Indirect proof
It is mostly used for proving implications A ⇒ B. We start with a converse
B 0 ⇒ A0 and prove it directly. We are using the fact that an implication and
its converse always have the same truth value.

Problem 12.9 Another property of divisibility by 2:


Prove: ∀n ∈ N 2|n2 ⇒ 2|n

Solution: ∀n ∈ N 2 does not divide n ⇒ 2


Converse: does not divide n2 .
Proof: 2 does not divide n ⇒ ∃k ∈ N0 : n = 2k + 1
⇒ n2 = 4k 2 + 4k + 1
⇒ ∃m ∈ N : n2 = 2m + 1, it is m = 2k 2 + 2k
⇒ 2 does not divide n2 .

Proof by contradiction
First we make a negation of the statement we are trying to prove and then
we perform a sequence of logical steps until we get to a contradiction. The
12.1. LECTURE OVERVIEW 381

contradiction means that the starting point was incorrect and as implied by the
law of excluded third (see Chapter 4), the original statement must have been
true. We have already seen an example of this in Section 2.1.2, where we proved
that there are innitely many prime numbers.

Problem 12.10 Injective function:


x
Prove that f (x) = 3−x is an injective function.

Solution: Suppose that the given statement is not true, i.e. that its negation
holds: f (x) is not an injective function and thus ∃x1 , x2 ∈ R − {3} : x1 6=
x2 ∧ f (x1 ) = f (x2 ). So we have

x1 x2
=
3 − x1 3 − x2
x1 (3 − x2 ) = x2 (3 − x1 )
3x1 − x1 x2 = 3x2 − x1 x2
3x1 = 3x2
x1 = x2

And this is a contradiction because we assumed x1 6= x2 .

Proof of equivalence
When proving a statement A ⇔ B, it is necessary to prove both A⇒B and
B ⇒ A.

Problem 12.11 Divisibility by 6:


Prove: A natural number is divisible by 6 ⇔ it is divisible by 3 and by 2.

Solution: First we prove thatA ⇒ B:


When a number n is divisible by 6 ⇒ ∃k ∈ N : n = 6k = 2·3k = 3·2k ⇒ 2|n∧3|n
Next we prove A ⇐ B :
When a number is divisible by 3 and by 2 ⇒ ∃k ∈ N : n = 3k ∧ 2|3k ⇒ 2|k ⇒
∃m ∈ N : k = 2m ⇒ n = 6m ⇒ 6|m.
382 CHAPTER 12. ASYMPTOTIC APPROXIMATIONS AND PROOFS

Mathematical induction
The mathematical induction is used for proving statements of the type: For
each natural number n ∈ N a statement V (n) is true. The proof is done in two
steps:

1. We prove that the statement holds for n = 1.


2. We prove that ∀k ∈ N : V (k) ⇒ V (k + 1), i.e. that if V holds for k then
it also holds for k + 1. V (k) is called an induction hypothesis.

Problem
n
12.12 Sum of odd numbers:
(2i − 1) = 1 + 3 + 5 + . . . + (2n − 1) = n2 .
P
Prove
i=1

Solution: First, we verify that the statement is true for n = 1. By plugging into
both sides of the equation we get 1 = 12 , so this is ok.
Next we assume that the statement is true for n = k and we check whether it
implies that the statement holds also for n = k + 1. For n = k + 1, we have on
the left-hand side

k+1
X
(2i − 1) = 1 + 3 + 5 + . . . + (2k − 1) + (2(k + 1) − 1) =
i=1
k
X
= (2i − 1) + (2(k + 1) − 1) = k 2 + 2k + 1.
i=1

The last equality uses the induction hypothesis. And nally: k 2 + 2k + 1 =


2
(k + 1) . This is exactly what we needed.
12.2. QUESTIONS 383

12.2 Questions

1. What is the computational complexity of an algorithm and why should


we know it?

2. Which of the O(f ) or o(f ) is used when expressing the computational


complexity of an algorithm and why?

3. Which asymptotic comparisons are used when approximating functions


using innite series?

4. The computational complexity of BubbleSort is O(n2 ) and the computa-


tional complexity of QuickSort is O(n log n). Which of them is better?

5. Algorithm A has computational complexity O(n2 + 3n) and algorithm B


2
has computational complexity O(n + 24). Which of them is better?

6. Algorithm C has computational complexity O(n log n2 ) and algorithm D


2
has computational complexity O(n log n). Which of them is better?

7. A function f (n) is asymptotically smaller than g(n), i.e. f ∈ o(g), i:

a)
f (n)
lim =0
n→∞ g(n)

or i

b) there exists a c ∈ R and n0 ∈ N such that ∀n ≥ n0 : |f (n)| ≤ c|g(n)|?

8. A function f is either asymptotically smaller or at most larger by a constant


multiple than g, i:

a)
f (n)
lim =0
n→∞ g(n)
or i

b) there exists a c ∈ R and n0 ∈ N such that ∀n ≥ n0 : |f (n)| ≤ c|g(n)|?

9. Find two functions f (n) and g(n) from N to R for which f (n) diers from
g(n) at most by a constant multiple and f 6= Θ(g).
384 CHAPTER 12. ASYMPTOTIC APPROXIMATIONS AND PROOFS

10. Give both direct and indirect proof of the same theorem. Choose your
own theorem or try to prove: If a natural number is divisible by 6, then it
is even.
11. Prove by contradiction: There are innitely many prime numbers.
12. Prove: The sum of the rst n natural numbers is
n · (n + 1)
2
a) by contradiction,

b) by mathematical induction.
12.3. PROBLEM SET 385

12.3 Problem set

Asymptotic approximations
1. Which functions belong to o(n2 ) and which do not:
4 3
n, n , n +n, 5n, n+2, 7, n3 +n+4, log(n3 ), log n, n log n
2. Which functions belong to o(n) and which do not:
n, n4 , n3 +n, 5n, n+2, 7, n3 +n+4, log(n3 ), log n, n log n
3. Which functions belong to o(1) and which do not:
n, n4 , n3 +n, 5n, n+2, 7, n3 +n+4, log(n3 ), log n, n log n
4. Which functions belong to o(n log n) and which do not:
n, n4 , n3 +n, 5n, n+2, 7, n3 +n+4, log(n3 ), log n, n log n
5. Which functions belong to O(n3 ) and which do not:
4 3
n, n , n +n, 5n, n+2, 7, n3 +n+4, log(n3 ), log n, n log n
6. Which functions belong to O(n2 ) and which do not:
4 3
n, n , n +n, 5n, n+2, 7, n3 +n+4, log(n3 ), log n, n log n
7. Which functions belong to O(n) and which do not:
n, n4 , n3 +n, 5n, n+2, 7, n3 +n+4, log(n3 ), log n, n log n
8. Which functions belong to O(1) and which do not:
n, n4 , n3 +n, 5n, n+2, 7, n3 +n+4, log(n3 ), log n, n log n
9. Which functions belong to O(n log n) and which do not:
n, n4 , n3 +n, 5n, n+2, 7, n3 +n+4, log(n3 ), log n, n log n
10. Which of the functions in the previous problems are f = Θ(g)?
11. Find out which of the following pairs of functions f (n) and g(n) are in
relations f ∈ o(g), g ∈ o(f ), f ∈ O(g), g ∈ O(f ), f = Θ(g). In the case of
O, nd the closest bounding constant c.

a) f (n) = 2n2 , g(n) = 4n


2n−3
b) f (n) = n+5 , g(n) = 54
c) f (n) = 1 + (n sin(n π3 ))2 , g(n) = 4n
n n
d) f (n) = 2 , g(n) = 5
2
e) f (n) = n , g(n) = en
386 CHAPTER 12. ASYMPTOTIC APPROXIMATIONS AND PROOFS

f) f (n) = (log(n))k , g(n) = nk

Proofs
√ a

12. Prove that 2 b 6=
is irrational, i.e. ∀a, b ∈ N :
2. What kind of proof

can we use? Can we also use it to prove that 3 is irrational? How will√
the proof break down if we attempt to prove that also 4 is irrational?

13. Prove the criterion of divisibility by 9, i.e. prove A natural number is


divisible by 9 i the sum of its digits is divisible by 9. What kind of proof
can we use? How did we use this criterion when drawing the spirolaterals
in Section 2.4? Can you modify the proof and use it for proving other
divisibility criteria?

14. Prove that the following statements dene the same set of quadrilaterals,
i.e. that the statements are equivalent.

a) The set (A) of quadrilaterals that have all sides of equal length and
all angles 90◦ .
b) The set (B ) of quadrilaterals that have all sides of equal length and
all angles of the same size.

c) The set (C ) of quadrilaterals that are both rectangles and diamonds.

d) The set (D ) of quadrilaterals that have diagonals of equal length.


The diagonals are perpendicular to each other and cut each other in
half.

15. Prove by mathematical induction ∀n ∈ N:

a)
n
X n · (n + 1)
k=
2
k=1

b)
n
X n · (n + 1) · (2n + 1)
k2 =
6
k=1

16. Suppose we have a few lines in a plane. No two of them are parallel, i.e. ev-
ery pair of lines has an intersection. Moreover, no three lines intersect at
a single point. How many intersections are there? Express this number as
a function of number of lines and prove it using mathematical induction.
12.3. PROBLEM SET 387

17. In the lecture, there is an indirect proof of the statement 2|n2 ⇒ 2|n.
2
Repeat this proof for divisibility by 3, i.e. prove 3|n ⇒ 3|n. Then, try to
prove 4|n2 ⇒ 4|n.
388 CHAPTER 12. ASYMPTOTIC APPROXIMATIONS AND PROOFS

12.3.1 Hints and solutions


Asymptotic approximations
1. Which functions belong to o(n2 ) and which do not:
4 3
n, n , n +n, 5n, n+2, 7, n3 +n+4, log(n3 ), log n, n log n
Hints: The function f for which it is true that f ∈ o(g) has to be sig-
nicantly smaller than g. This is expressed by the little o. We use the
denition: f ∈ o(g) if and only if

f (n)
lim = 0,
n→∞ g(n)

i.e. for functions f (n) = n and g(n) = n2 , we need to check if the limit

n 1
lim = lim =0
n→∞ n2 n→∞ n

is equal to zero. We can also draw the functions f (n) = n and g(n) = n2
1
as in Figure 12.1 together with their ratio
n.

n
Figure 12.1: Functions f (n) = n, g(n) = n2 and their ratio
n2 .
12.3. PROBLEM SET 389

Similarly, we should check if the limit of the ratio of f (n) = n · log n and
g(n) = n2
n log n log n
lim = lim
n→∞ n2 n→∞ n

is equal to zero. For this calculation, we would need the tools of mathe-
matical analysis. Alternatively, we can also draw the functions and their
ratio and estimate the limit from the graph, see Figure 12.2.

log n
Figure 12.2: Functions f (n) = n log n, g(n) = n2 and their ratio
n , which
can be used to estimate the limit. Note the similarity to Figure 12.1

Solution:
n ∈ o(n2 ), n4 ∈
/ o(n2 ), n3 + n ∈
/ o(n2 ), 5n ∈ o(n2 ),
2 2 3
n + 2 ∈ o(n ), 7 ∈ o(n ), n + n + 4 ∈ / o(n2 ), log(n3 ) ∈ o(n2 ),
2 2
log n ∈ o(n ), n log n ∈ o(n )

5. Which functions belong to O(n3 ) and which do not:


4 3
n, n , n +n, 5n, n+2, 7, n3 +n+4, log(n3 ), log n, n log n
Hints: The function f, for which we want to have f ∈ O(g), has to be
asymptotically smaller or at most as large as g. This is expressed by
the big O. Instead of just guessing, we examine the functions using the
denition: f ∈ O(g) if and only if there exists a c∈R and n 0 ∈ N, such
390 CHAPTER 12. ASYMPTOTIC APPROXIMATIONS AND PROOFS

that ∀n ≥ n0 we have:

|f (n)| ≤ c · |g(n)| or − c · |g(n)| ≤ f (n) ≤ c · |g(n)|,


e.g. for functions f (n) = 5n and g(n) = n + 2 we are looking for such
c∈R and n0 ∈ N that ∀n ≥ n0 we get the desired inequality.

The inequality is true for example for c = 6:


|5 · n| ≤ c · |n + 2| or − c · |n + 2| ≤ 5 · n ≤ c · |n + 2|
These functions are illustrated in Figure 12.3.

Figure 12.3: Functions f (n) = 5 · n, g(n) = n + 2 and constant c=6 for the
estimate f (n) ∈ O(g(n)).

Solution:
n ∈ O(n3 ), n4 ∈/ O(n3 ), n3 + n ∈ O(n3 ), 5n ∈ O(n3 ),
n + 2 ∈ O(n ), 7 ∈ O(n3 ), n3 + n + 4 ∈ O(n3 ), log(n3 ) ∈ O(n3 ),
3

log n ∈ O(n3 ), n log n ∈ O(n3 )


10. Which of the functions in the previous problems are f = Θ(g)?
Hint:
We need to nd out if the functions can bound each other, i.e. if they are
asymptotically the same.
12.3. PROBLEM SET 391

Two functions f and g are in relation Θ, i.e. f = Θ(g) or g = Θ(f ) if and


only if f ∈ O(g) and g ∈ O(f ).
Since the functions f and g (with suitable multiplicative constants) are
supposed to be bounds for one another, they should not dier too much.
An example of such pair are f (n) = 5n and g(n) = n + 2. We have already
shown that 5n ∈ O(n + 2). Now we show that also n + 2 ∈ O(5n). Here
it is sucient to take c = 0.6 and the inequality in the denition is true,
see Figure 12.4. This way we showed that f (n) = 5n and g(n) = n + 2
are in relation Θ.

Figure 12.4: Functions g(n) = n + 2, f (n) = 5n and constant c = 0.6 for the
estimate g ∈ O(f ).

Solution:
Functions n + 2 ∈ Θ(n), 5n ∈ Θ(n). And of course every pair of these
three is in relation Θ.
Functions n3 + n ∈ Θ(n3 ), n3 + n + 4 ∈ Θ(n3 ). And every pair of these
three is in relation Θ.

Function log(n3 ) ∈ Θ(log n).


For functions f (n) = n log n, f (n) = n4 and f (n) = 7 there are no func-
tions on the list that would be in relation Θ with them.
392 CHAPTER 12. ASYMPTOTIC APPROXIMATIONS AND PROOFS

11. Find out which of the pairs of functions f and g are in relations f ∈ o(g),
g ∈ o(f ), f ∈ O(g), g ∈ O(f ), f = Θ(g). In the case of O, nd the closest
bounding constant c.

Hints: We should use the same approach as in the previous problems. It is


also a good idea to train our intuition by guessing rst and then verifying
the guess by calculations.

Solution: You can nd more detailed solutions to these problems in the
lecture overview.

a) For functions f (n) = 2n2 , g(n) = 4n we have g ∈ o(f ),


g ∈ O(f ) and f 6= Θ(g), g 6= Θ(f ).
b) For functions f (n) = 2n−3
n+5 , g(n) = 54 we have g ∈
/ o(f ),
and f ∈
/ o(g), but g ∈ O(f ) and f ∈ O(g).
Therefore we also have f = Θ(g) and g = Θ(f ).

c) For functions f (n) = 1 + (n sin(n π3 ))2 , g(n) = 4n we have


g∈
/ o(f ) and f ∈
/ o(g), but g ∈ O(f ) and f ∈ O(g).
Therefore we have both f = Θ(g) and g = Θ(f ).

d) For functions f (n) = 2n , g(n) = 5n we have g∈


/ o(f ), but f ∈ o(g).
We also have g ∈ / O(f ) and f ∈ O(g).
Therefore f 6= Θ(g) and g 6= Θ(f ).

e) For functions f (n) = n2 , g(n) = en we have g∈


/ o(f ), but f ∈ o(g).
We also have g ∈ / O(f ) and f ∈ O(g).
Therefore f 6= Θ(g) and g 6= Θ(f ).

f ) For functions f (n) = (log(n))k , g(n) = nk we have g ∈


/ o(f ), but
f ∈ o(g). We also have g ∈
/ O(f ) and f ∈ O(g).
Therefore f 6= Θ(g) and g 6= Θ(f ).

Proofs
√ a

12. Prove that 2 b 6=
is irrational, i.e. ∀a, b ∈ N :
2. What kind of proof

can we use? Can we also use it to prove that 3 is irrational? How will √
the proof break down if we attempt to prove that also 4 is irrational?

Hints:
• This statement can be proven by contradiction. We can start by

a
assuming that there exists a rational number
b equal to 2, with
a and b not having a common divisor. Manipulating the expression
12.3. PROBLEM SET 393

√ a
2=b leads to a contradiction: if such two numbers a and b existed,
both would have to be divisible by two.

• For 3 we get a very similar contradiction with 3 being the common
divisor of a and b.

• For 4 we get 4|a2 , but this does not imply 4|a as in the previous
two cases. We can certainly say that 2|a and get that for a=√
2 and
a
b=1 the fraction
b is that rational number which is equal to 4.

13. Prove the criterion of divisibility by 9, i.e. prove A natural number is


divisible by 9 i the sum of its digits is divisible by 9. What kind of proof
can we use? How did we use this criterion when drawing the spirolaterals
in Section 2.4? Can you modify the proof and use it for proving other
divisibility criteria?

Hints:
• A number x divisible by 9 can be written as a multiple of 9, i.e. x=
9k .
• A number x = cn cn−1 cn−2 . . . c2 c1 c0 written in decimal system can
be written as x = c0 · 1 + c1 · 10 + c2 · 100 + . . . + cn · 10n .
• We can divide the number x into a sum of two components x = y + z
rst of which (y ) is divisible by 9. In order for the whole number to
be divisible by 9, also the second component (z ) has to be divisible
by 9.
• The number 10n − 1 is divisible by 9. This can be shown by using
mathematical induction. Alternatively, we can realise that 10n − 1 =
99 . . . 99 = 9 · 11 . . . 11.

Solution: We can set

y = c0 · 0 + c1 · 9 + c2 · 99 + . . . + cn · (10n − 1)

The number y is always divisible by 9. In order for x to be divisible by 9,


also
z = x − y = c0 · 1 + c1 · 1 + c2 · 1 + . . . + cn · 1
has to be divisible by 9. The number z is the sum of digits of x.
This was a direct proof, but we could have used an indirect proof or proof
by contradiction.
394 CHAPTER 12. ASYMPTOTIC APPROXIMATIONS AND PROOFS

When we were drawing the spirolaterals, we needed the sum of digits of


the numbers and so we used the remainder after division by 9 (except for
the situation when the number was divisible by 9).

We could use this method for example for proving criterion of divisibility
by 3.

14. Prove that the following statements dene the same set of quadrilaterals,
i.e. that the statements are equivalent.

a) The set (A) of quadrilaterals that have all sides of equal length and
all angles 90◦ .
b) The set (B ) of quadrilaterals that have all sides of equal length and
all angles of the same size.

c) The set (C ) of quadrilaterals that are both rectangles and diamonds.

d) The set (D ) of quadrilaterals that have diagonals of equal length.


The diagonals are perpendicular to each other and cut each other in
half.

Hints:
• Proving equivalence means proving two implications, i.e. show that
the statement is true both ways. With four sets, we have 6 equiva-
lences two show, which means 12 implications.

• We can save some work by showing that we can get from each of
these statements to any other statement, show e.g.

a) ⇒ b) ⇒ c) ⇒ d) ⇒ a).

This is equivalent to proving that all the sets are the same, i.e. A=
B = C = D, by showing four subset relations

A ⊂ B ⊂ C ⊂ D ⊂ A.

• To prove that A ⊂ B we need to show that every element from the


set A belongs also to the set B . For example if there is a quadrilateral
that has all sides of equal length and all angles 90◦ , then it also has
sides of equal length and all angles of the same size. This is true
because two right angles are angles of the same size.
12.3. PROBLEM SET 395

15. Prove by mathematical induction ∀n ∈ N:


a)
n
X n · (n + 1)
k=
2
k=1

b)
n
X n · (n + 1) · (2n + 1)
k2 =
6
k=1

Hints:
The proof by mathematical induction uses the axiom that with every nat-
ural number, the set of natural numbers contains its successor, a number
greater by 1. Once we show that if a statement is true for some number,
then it is true for a number greater by 1, we have shown the statement
for all natural numbers (provided that we have shown we can start this
domino eect somewhere).

1. We prove that the statement is true for n = 1.


2. We prove the implication that if the statement is true for some natural
number, it is also true for the next natural number.

Solution:
a) We use mathematical induction to prove the formula:

n
X n · (n + 1)
k=
2
k=1

1.
1
X 1 · (1 + 1)
k = 1, =1
2
k=1
2. In the formula for n + 1:
n+1
X (n + 1) · ((n + 1) + 1)
k=
2
k=1

we start from the left-hand side and use the induction premise

n+1 n
!
X X n · (n + 1) n · (n + 1) 2(n + 1)
k= k +(n+1) = +n+1 = + =
2 2 2
k=1 k=1
396 CHAPTER 12. ASYMPTOTIC APPROXIMATIONS AND PROOFS

n · (n + 1) + 2(n + 1) (n + 1)(n + 2) (n + 1) · ((n + 1) + 1)


= = =
2 2 2
b) We use mathematical induction to prove the formula:

n
X n · (n + 1) · (2n + 1)
k2 =
6
k=1

1.
1
X 1 · (1 + 1) · (2 · 1 + 1)
k 2 = 1, =1
6
k=1

2. In the formula for n + 1:


n+1
X (n + 1) · (n + 2) · (2n + 3)
k2 =
6
k=1

we start from the left-hand side and use the induction premise

n+1
X n · (n + 1) · (2n + 1)
k2 = + (n + 1)2 =
6
k=1

(n + 1) · n · (2n + 1) 6(n + 1)2


= + =
6 6
(n + 1) · (2n2 + n + 6n + 6)
= =
6
(n + 1) · (2n2 + 7n + 6) (n + 1) · (n + 2) · (2n + 3)
= =
6 6
16. Suppose we have a few lines in a plane. No two of them are parallel, i.e. ev-
ery pair of lines has an intersection. Moreover, no three lines intersect at
a single point. How many intersections are there? Express this number as
a function of number of lines and prove it using mathematical induction.

Hints: One line has 0 intersections.


Two lines have 1 intersection.
Three lines that do not intersect at one point have 3 intersections.
Four lines that do not intersect at one point have 6 intersections, see Figure
12.5.
12.3. PROBLEM SET 397

Figure 12.5: Intersections of 1, 2, 3 and 4 lines.

When we add another line, the number of intersections increases. By how


much?

We observe that the number of intersections increases by the previous


number of lines.
One line has 0 intersections.
Two lines have 0+1 intersection.
Three lines have 1+2 intersections.
Four lines have 3+3 intersections.
Five lines have 6+4 intersections.
etc.

We thus have a hypothesis that for n lines there are 0+1+2+3+. . .+n−1 =
(0+n−1)·n
intersections.
2
Solution:
(n−1)·n
n lines have
2 intersections.

Proof by mathematical induction:


(n−1)·n
1. For n=1 line, the number of intersections is
2 = 0.
(n−1)·n
2. Suppose that for n lines we have
2 . When we add one line,
(n−1)·n
it crosses all the n lines already there. Therefore in addition to
2
intersections we have n more. The number of intersections would then be

(n − 1) · n (n − 1) · n + 2n n · (n + 1)
+n= = .
2 2 2
n·(n+1)
We have shown that for n+1 lines, there are
2 intersections and
thus if the statement is true for n, it is also true for n + 1.

17. In the lecture, there is an indirect proof of the statement 2|n2 ⇒ 2|n.
2
Repeat this proof for divisibility by 3, i.e. prove 3|n ⇒ 3|n. Then, try to
prove 4|n2 ⇒ 4|n.
398 CHAPTER 12. ASYMPTOTIC APPROXIMATIONS AND PROOFS

Hints: The proof for divisibility by 3 works the same way as the proof in
the lecture. The proof will not work for divisibility by 4 because 4 is not a
prime. We can nd a counterexample, e.g. n = 2. For thisn, the premise
of the implication is true, since 4|n2 , but the conclusion is false, we do not
have 4|n.
12.4. LAB PROBLEMS 399

12.4 Lab problems

1. Bounding constants
a) Find a constant c with which you can show that the sequence f (n) =
n+5 belongs to O(n2 ), i.e.:

|n + 5| ≤ c|n2 |, or − c|n2 | ≤ n + 5 ≤ c|n2 |.

b) Find a constant c with which you can show that the sequence f (n) =
n2 belongs to O(n log n), i.e.:

|n2 | ≤ c|n log n|, or − c|n log n| ≤ n2 ≤ c|n log n|.

2. Big O
Use graphs to show that a quadratic sequence is O(n2 ) and a cubic se-
3
quence is O(n ).
3. Approximation by polynomial expansion
Show how good is the approximation of functions sin x, cos x and ex using
the rst ve terms of their expansions into series for |x| << 1. Which
of the calculations is most precise? How does the theoretical estimate of
error compare to the calculated error?

4. Computation of new prime numbers


In the proof of the statement that there are innitely many primes we
reasoned that if there was only a nite number of primes, their product
incremented by 1 would give a new prime number. Can we nd a set of
primes that break this rule, i.e. when we increment their product by 1,
we do not get a prime number? If we can nd such a set, does it mean
that the proof is incorrect?
400 CHAPTER 12. ASYMPTOTIC APPROXIMATIONS AND PROOFS

12.4.1 Hints and solutions


1. Bounding constants
a) Find a constant c with which you can show that the sequence f (n) =
n+5 belongs to O(n2 ), i.e.:
|n + 5| ≤ c|n2 |, or − c|n2 | ≤ n + 5 ≤ c|n2 |.

b) Find a constant c with which you can show that the sequence f (n) =
n2 belongs to O(n log n), i.e.:
|n2 | ≤ c|n log n|, or − c|n log n| ≤ n2 ≤ c|n log n|.

Hint: We can create an Excel worksheet, where we can input various values
of the constant c and try to nd a value which shows that the sequence
n+2 belongs to O(n2 ) (or that the sequence n2 belongs to O(n log n)).

Figure 12.6: Looking for c|n2 | bound for n + 5.

Solution:
a) Note that even if we take a small value of c and the graph of the
linear function is initially above the graph of the quadratic function
for the rst few values of n, eventually they two graphs cross and the
quadratic function dominates because it grows faster than a linear
function, see Figure 12.6.
12.4. LAB PROBLEMS 401

b) No matter how useful the software tool is and not matter how we try,
we cannot nd such value c for which we would have |n2 | ≤ c|n log n|,
2
see Figure 12.7. Therefore n ∈ / O(n log n).

Figure 12.7: Attempts to nd c|n log n| bounds for n2 for c = 15 and c = 25.

2. Big O
Use graphs to show that a quadratic sequence is O(n2 ) and a cubic se-
3
quence is O(n ).
Hint: We can start by creating an Excel worksheet with input parameters
a, b, c that dene the function f (n) = an2 + bn + c. The constant D should
also be a variable input. We tabulate and draw the sequences f (n) and
Dn2 for n from 1 to 100. For various values of a, b, c we are looking for
the constant D which would satisfy the inequality |an2 + bn + c| ≤ D|n2 |.
This will manifest by a correct relative position of the graphs.
402 CHAPTER 12. ASYMPTOTIC APPROXIMATIONS AND PROOFS

Similarly, we can show that for any parameters a, b, c, d in a cubic sequence,


we can nd a constant D, such that all terms of f (n) = an3 + bn2 + cn + d
are smaller than D|n3 |.

Solution: Figure 12.8 shows that a quadratic sequence is O(n2 ).

Figure 12.8: Bounding an2 + bn + c using a sequence Dn2 .

Figure 12.9 shows that a cubic sequence is O(n3 ).

Figure 12.9: Bounding an3 + bn2 + cn + d using a sequence Dn3 .


12.4. LAB PROBLEMS 403

3. Approximation by polynomial expansion


Show how good is the approximation of functions sin x, cos x and ex using
the rst ve terms of their expansions into series for |x| << 1. Which
of the calculations is most precise? How does the theoretical estimate of
error compare to the calculated error?

Hint: We have discussed the innite series for sin(x), cos(x), ex in Chapter
11.

x3 x5 x7
sin(x) = x −
+ − + ...
3! 5! 7!
x2 x4 x6
cos(x) = 1 − + − + ...
2! 4! 6!
x2 x3 x4 x5 x6
ex = 1 + x + + + + + + ...
2! 3! 4! 5! 6!
We start by testing the approximation accuracy for x from the interval
(0, 1) and then increasing the values of x. For which functions does the
accuracy depend on x? Does taking more terms of the series always in-
crease the accuracy? On which part of the domain can we approximate
the functions using their respective series reasonably well?

Solution: We can approximate the functions well near 0. For the function
sin(x), we have the approximation error o(x11 ) when using 5 terms close
to zero, see Figure 12.10. The error for cos(x) is o(x10 ) and the error for
ex , Figure 12.11, is o(x6 ).
4. Computation of new prime numbers
In the proof of the statement that there are innitely many primes we
reasoned that if there was only a nite number of primes, their product
incremented by 1 would give a new prime number. 2·3+1 = 7, 2·3·5+1 =
31, . . . Can we nd a set of primes that break this rule, i.e. when we
increment their product by 1, we do not get a prime number? If we can
nd such a set, does it mean that the proof is incorrect?

Hint: This method looks promising, but if it was truly working, we could
keep building new primes (relatively) easily by multiplying existing primes
and adding one. Since this is not happening, it is very likely that there is
something wrong with this method. Try applying it to the rst few primes
(systematically in Excel) and check if all the results are indeed prime. If
there was a composite result, could it be a product of new primes?
404 CHAPTER 12. ASYMPTOTIC APPROXIMATIONS AND PROOFS

Figure 12.10: Approximation of the function sin(x) using power series and the
error when using 3 and 5 terms.

Figure 12.11: Approximation of the function ex using power series and the error
when using 3 and 5 terms.

Solution: A worksheet, such as the one in Figure 12.12, shows that this is
not a universal method for creating new primes.

2 · 3 · 5 · 7 · 11 · 13 + 1 = 30031 = 509 · 59

if there was only a nite


The proof is still correct, because the implication
number of primes, their product incremented by 1 would give a new prime
12.4. LAB PROBLEMS 405

Figure 12.12: Multiplication of rst six primes incremented by 1 yields 30031,


which is divisible by 59.

number was considered under the assumption that the rst part there
was only a nite number of primes is a true statement. It leads to a
contradiction, thus it cannot be true. And in such case the implication is
true regardless the truth value of its conclusion.
406 CHAPTER 12. ASYMPTOTIC APPROXIMATIONS AND PROOFS
Farewell
Dear reader,
on the previous page, you dealt with the last problem in this book. If you are
reading these words, we hope that some of the following statements are true:

• The content of the book was so interesting that you went through it all not
only as a passive reader but actively solving the problems and questions
that are the core of the book.

• Several times you experienced that the calculation, illustration or simu-


lation on the computer helped you solve a problem or better understand
the mathematical terms and principles.

• You also encountered the opposite situations in which mathematical un-


derstanding and correct use of mathematical tools simplied or sped up
a computer algorithm, dened its main idea, helped avoid an error or
understand the cause of an error.

• You are going to transfer the notion of interconnectedness of mathematics


and computer science to your next studies and professional life.

• And if necessary, you will gladly return to the relevant chapters of this
book, which will serve as a foundation and starting point for your study
of more complex problems and other literature.

The nal challenge


When you read the book the next time, solve each problem by a dierent
method than before.

407
408 CHAPTER 12. ASYMPTOTIC APPROXIMATIONS AND PROOFS
Bibliography

[1] Desmos Graphing Calculator. https://www.desmos.com/.

[2] Spirolaterals. http://mathworld.wolfram.com/Spirolateral.html.

[3] Wolfram Alpha. https://www.wolframalpha.com.

[4] R. L. Graham, D. E. Knuth, and O. Patashnik. Concrete mathematics:


a foundation for computer science, 2nd edition. Addison-Wesley Longman
Publishing Co., 1994.

[5] M. Hohenwarter, M. Borcherds, G. Ancsin, B. Bencze, M. Blossier, A. De-


lobelle, C. Denizet, J. Éliás, Á Fekete, L. Gál, Z. Kone£ný, Z. Kovács,
S. Lizelfelner, B. Parisse, and G. Sturr. GeoGebra, 2013. http://www.
geogebra.org.
[6] E. Lehman, F. T. Leighton, and A. R. Meyer. Mathematics for Computer
Science. 12th Media Services, 2017.

[7] R. M. Smullyan. The lady or the tiger. Knopf, 1982.

[8] A. N. Whitehead and R. Bertrand. Principia Mathematica, 6th edition.


Cambridge (England): The University Press, 1925.

409

You might also like