0% found this document useful (0 votes)
53 views141 pages

Discrete Mathematics Notes 2023

Uploaded by

techlum008
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)
53 views141 pages

Discrete Mathematics Notes 2023

Uploaded by

techlum008
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/ 141

Discrete Mathematics

Course Notes

Felipe Balbi

May 25, 2020


Contents

Week 1 5
1.101 Introduction to discrete mathematics . . . . . . . . . . . . . . . . . . . . 5
1.104 The definition of a set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.106 The listing method and rule of inclusion . . . . . . . . . . . . . . . . . . . 7
1.108 The powerset of a set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.110 Set operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Week 2 13
1.201 The representation of a set using Venn diagrams . . . . . . . . . . . . . . 13
1.203 De Morgan’s laws . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.205 Laws of sets: Commutative, associative and distributive . . . . . . . . . . 16
1.207 Partition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

Week 3 20
2.101 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.102 The Definition of A Function . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.104 Plotting functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.106 Injective and surjective functions . . . . . . . . . . . . . . . . . . . . . . . 25

Week 4 28
2.201 Function composition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.203 Bijective functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.205 Logarithmic functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
2.207 Floor and ceiling functions . . . . . . . . . . . . . . . . . . . . . . . . . . 32

Week 5 35
3.101 Introduction to propositional logic . . . . . . . . . . . . . . . . . . . . . . 35
3.103 Propositions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3.105 Truth tables and truth sets . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.107 Compound propositions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

Week 6 41
3.202 Logical implication (→) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3.204 Logical equivalence (↔) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.206 Laws of propositional logic . . . . . . . . . . . . . . . . . . . . . . . . . . 45

2
Contents

Week 7 46
4.101 Introduction to predicate logic . . . . . . . . . . . . . . . . . . . . . . . . 46
4.103 What are predicates? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.105 Quantification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
4.107 Nested Quantifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

Week 8 52
4.201 De Morgan’s laws for quantifiers . . . . . . . . . . . . . . . . . . . . . . . 52
4.203 Rules of inference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
4.205 Rules of inference with quantifiers . . . . . . . . . . . . . . . . . . . . . . 59

Week 9 63
5.101 Introduction to Boolean algebra . . . . . . . . . . . . . . . . . . . . . . . 63
5.103 Postulates of Boolean algebra . . . . . . . . . . . . . . . . . . . . . . . . . 65
5.105 Boolean functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

Week 10 70
5.201 Logic gates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
5.203 Combinational circuits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
5.205 Simplification of circuits . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78

Week 11 81
6.101 Introduction to proofs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
6.103 The principle of mathematical induction . . . . . . . . . . . . . . . . . . . 83
6.106 Proof by induction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
6.108 Strong induction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

Week 12 89
6.201 Recursive definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
6.204 Recurrence relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
6.206 Solving recurrence relations . . . . . . . . . . . . . . . . . . . . . . . . . . 91

Week 13 93
7.101 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
7.103 Definition of a graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
7.105 Walks and paths in a graph . . . . . . . . . . . . . . . . . . . . . . . . . . 96
7.107 The degree sequence of a graph . . . . . . . . . . . . . . . . . . . . . . . . 100
7.109 Special graphs: simple, r-regular and complete graphs . . . . . . . . . . . 102

Week 14 105
7.201 Isomorphic graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
7.203 Bipartite graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
7.205 The adjacency matrix of a graph . . . . . . . . . . . . . . . . . . . . . . . 107
7.207 Dijkstra’s algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

3
Contents

Week 15 112
8.103 Definition of a tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
8.105 Spanning trees of a graph . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
8.107 Minimum spanning tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

Week 16 117
8.201 Rooted trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
8.203 binary search trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

Week 17 122
9.101 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
9.103 Definition of a relation: relation versus function . . . . . . . . . . . . . . 123
9.105 Matrix and graph representations of a relation . . . . . . . . . . . . . . . 124
9.107 The properties of a relation: reflexive, symmetric and anti-symmetric . . 126
9.109 Relation properties: transitivity . . . . . . . . . . . . . . . . . . . . . . . 129

Week 18 132
9.201 Equivalence relations and equivalence classes . . . . . . . . . . . . . . . . 132
9.203 Partial and total order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134

Week 19 135
10.101 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
10.103 The basics of counting . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
10.105 The pigeonhole principle . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
10.107 Permutations and combinations . . . . . . . . . . . . . . . . . . . . . . . 137

Week 20 138
10.201 Binomial coefficients and identities . . . . . . . . . . . . . . . . . . . . . 138
10.204 Generalised permutations and combinations . . . . . . . . . . . . . . . . 140
10.206 Distinguishable objects and boxes . . . . . . . . . . . . . . . . . . . . . . 141

4
Week 1

Learning objectives:
• Define a set, the elements of a set and the cardinality of a set.
• Define the concepts of the universal set and the complement of a set, and the
difference between a set and a powerset of a set.
• Define the concepts of the union, intersection, set difference and symmetric differ-
ence, and the concept of a membership table.
Essential Reading
• Rosen, K.H. Discrete mathematics and its applications. (New York: McGraw-Hill,
2012) 7th edition, pp.117–126
• Exercises
pp.127–128 exercises 1–8 and 12–19.
For reading on set operations, please see the Essential reading for Week 2.

1.101 Introduction to discrete mathematics


The study of discrete objects. Such objects are separated or distant from each other.
We will study integers, propositions, sets, relations or functions.
We will learn their properties and relationships among them.
Sets, functions, logic, graphs, trees, relations, combinatorics, mathematical induction
and recursive relations. We will gain mathematical understanding of these topics and
that will improve our skill of thinking in abstract terms.

1.104 The definition of a set


Set Theory deals with properties of well-defined collection of objects. Introduced by
George Cantor.
Forms the basis of other fields of study: counting theory, relations, graph theory and
finite state machines.

5
Week 1

Definition of a set
A collection of any kind of objects: people, ideas, numbers. . .
A set must be well-defined, meaning that there can be no ambiguity to which objects
belongs to the set.

E = {2, 4, 6, 8}
V = {a, e, i, o, u}
EmptySet = {} = ∅

Definition 1 (Set). A set is an unordered collection of unique objects.

Element of a set (∈)


Given the set E = {2, 4, 6, 8} we can say 2 ∈ E (2 is an element of E) and 3 ∈
/ E (3 is
not an element of E)

Cardinality of a set (Card)


Definition 2 (Cardinality). Given a set S, the cardinality of S is the number of ele-
ments contained in S. We write the cardinality of S as |S|. Note that the cardinality of
the empty set is zero (|∅| = 0)

Subset of a set (⊆)


Definition 3 (Subset). A is said to be a subset of B if and only if every element of A is
also an element of B. In this case we write A ⊆ B.
This means we have the following equivalence:

A ⊆ B ↔ if x ∈ A then x ∈ B(for all x)

The emptyset ∅ is a subset of any set.


Any set if a subset of itself (S ⊆ S)

Special Sets: N, Z, Q, R
N: set of natural numbers
Z: set of integers
Q: set of rational numbers
R: set of real numbers

6
Week 1

1.106 The listing method and rule of inclusion


Two different ways of representing a set.
The listing method consists of simply listing all elements of a set.
S1 = {1, 2, 3}
The rule of inclusion method consists of producing a rule such that when that rule is
true, the element is a member of the set. For example, here’s a rule of inclusion for the
set of all odd integers:
S2 = {2n + 1 | n ∈ Z}
In some cases, the rule of inclusion (or set building notation) is the only way to actually
describe a set. For example, if we were to try to list the elements of the set of rational
numbers Q, we would never be able to reach the end. However, with the set builder
notation it becomes simple and concise:
n
Q = {m | n, m ∈ Zandm 6= 0}
We can use the same notation for the set of elements in my bag:
Sbag = {x | xis in my bag}

1.108 The powerset of a set


A set can contain other sets as elements. For example:

A = {1, 2, 3, 4, 5, 6, 7, 8, 9}
B = {{1, 2, 3, 4}, {5, 6}, {7, 8, 9}}

Note that {1, 2, 3, 4} is a subset of A but it is an element of B. In mathematical terms:

{1, 2, 3, 4} ⊆ A but {1, 2, 3, 4} ∈ B

Powerset of a set
Definition 4 (Powerset). Given a set S, the powerset of S, P (S), is the set containing
all the subsets of S
1. Example 1
Given a set S = {1, 2, 3}, the subsets of S are:
∅, {1}, {2}, {3},
{1, 2}, {1, 3}, {2, 3},
{1, 2, 3}

7
Week 1

Therefore, the powerset of S, P (S) is as follows:


P (S) = {∅, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}
2. Example 2
What is the powerset of the empty set? What is the powerset of the powerset of
the empty set?

P (∅) = {∅}
P (P (∅)) = {∅, {∅}}

Cardinality of a powerset
Given a set S, then |P (S)| = 2|S|
In other words: the cardinality of the powerset of S is the 2 to the power of the cardinality
of S. For example:

S = {1, 2}
|S| = 2
P (S) = {∅, {1}, {2}, {1, 2}}
|P (S)| = 4 = 22 = 2|S|
1. Example
Given a set A, if |A| = n find |P (P (P (A)))|

|P (A)| = 2n
n
|P (P (A))| = 22
2n
|P (P (P (A)))| = 22

1.110 Set operations


We will look at set operations (intersection, union, difference, symmetric difference).

Union (∪)
Definition 5 (Union). Given two sets A and B, the union of A and B, A ∪ B, contains
all the elements in either A or B.

A ∪ B = {x | x ∈ A or x ∈ B}

8
Week 1

A B

1. Example

A = {1, 2, 3}
B = {4, 5, 6}
A ∪ B = {1, 2, 3, 4, 5, 6}

2. Membership Table (A ∪ B)
A B A∪B
0 0 0
0 1 1
1 0 1
1 1 1

Intersection (∩)
Definition 6 (Intersection). Given two sets A and B, the intersection of A and B,
A ∩ B, contains all the elements in both A and B.

A ∩ B = {x | x ∈ A and x ∈ B}

A B

9
Week 1

1. Example

A = {1, 2, 3}
B = {2, 3, 4}
A ∩ B = {2, 3, }

2. Membership Table (A ∩ B)
A B A∩B
0 0 0
0 1 0
1 0 0
1 1 1

Difference (−)
Definition 7 (Difference). Given two sets A and B, the difference of A and B, A − B,
contains all the elements that are in A but not in B.

A − B = {x | x ∈ A and x ∈
/ B}

A B

1. Example

A = {1, 2, 3}
B = {3, 4, 5}
A − B = {1, 2, }

2. Membership Table (A − B)

10
Week 1

A B A−B
0 0 0
0 1 0
1 0 1
1 1 0

Symmetric Difference (⊕)


Definition 8 (Symmetric Difference). Given two sets A and B, the symmetric difference
of A and B, A ⊕ B, contains all the elements that are in A or in B but not in both.

A ⊕ B = {x | (x ∈ A or x ∈ B) and x ∈
/ A ∩ B}

A B

1. Example

A = {1, 2, 3}
B = {3, 4, 5}
A ⊕ B = {1, 2, 4, 5}

2. Membership Table (A ⊕ B)
A B A⊕B
0 0 0
0 1 1
1 0 1
1 1 0

Summary
1. Operations

11
Week 1

A = {1, 2, 3}
B = {3, 4, 5}
A ∪ B = {1, 2, 3, 4, 5}
A ∩ B = {3}
A − B = {1, 2}
A ⊕ B = {1, 2, 4, 5}

2. Membership Table
A B A∪B A∩B A−B A⊕B
0 0 0 0 0 0
0 1 1 0 0 1
1 0 1 0 1 1
1 1 1 1 0 0

12
Week 2

Learning objectives:
• Understand the concept of Venn diagrams and how they are used to represent and
compare different set expressions.
• Understand and prove De Morgan’s law using membership tables.
Essential Reading
• Rosen, K.H. Discrete mathematics and its applications. (New York: McGraw-Hill,
2012) 7th edition, pp.128–137.
• Exercises
pp.138–139 exercises 1–9, 14, 15, 17, 18, 22–26, 32 and 34–36.

1.201 The representation of a set using Venn diagrams


Venn diagrams can be used to represent sets and visualize the possible relations among
a collection of sets. During this lesson we studied the following concepts:
• The universal set
• The complement of a set
• Set representation using Venn Diagrams

The Universal Set


The universal set is a set containing everything. It’s referred to by the letter U.
Note that A ⊆ U .

13
Week 2

Complement of a set
Given a set A, the complement of A is written as A, contains all the ements in the
universal set U but not in A. It’s represented by the area in red in figure below.
U

In other words A = U − A.
Example

U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
A = {2, 4, 6, 8, 10}
A=U −A
= {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} − {2, 4, 6, 8, 10}
= {1, 3, 5, 7, 9}

The union of a set A with its completement A is always the universal set U .

A∪A=U

The symmetric difference of A and B is the same as the union of A and B minus the
intersection of A and B:

14
Week 2

A ⊕ B = A ∪ B − (A ∩ B)

1.203 De Morgan’s laws


De Morgan’s laws describe how mathematical statements and concepts are related through
their opposites. In se theory, they relate to intersection and unions of sets through their
complements.

De Morgan’s First Law


The complement of the union of two sets A and B is equal to the intersection of their
complements.

A∪B =A∩B

De Morgan’s Second Law


The complement of the intersection of two sets A and B is equal to the union of their
complements.

A∩B =A∪B

Proof using membership tables


1. A ∪ B = A ∩ B
A B A B A∪B A∪B A∩B
0 0 1 1 0 1 1
0 1 1 0 1 0 0
1 0 0 1 1 0 0
1 1 0 0 1 0 0
2. A ∩ B = A ∪ B
A B A B A∩B A∩B A∪B
0 0 1 1 0 1 1
0 1 1 0 0 1 1
1 0 0 1 0 1 1
1 1 0 0 1 0 0

15
Week 2

1.205 Laws of sets: Commutative, associative and


distributive
We discussed three set identities: Commutativity, Associativity, and Distributivity.

Commutativity
When the order of operands in an operation does NOT affect the result, we say the
operation is commutative. For example, addition is commutative

2+3=3+2

Same applies for multiplication:

2·3=3·2

Subtraction, however, is NOT commutative:

2 − 3 6= 3 − 2

In Set Theory, Union ∪, Intersection ∩, and Symmetric Difference ⊕ are all commutative
operations. Much like in Algebra, Set difference is NOT commutative:

A = {1, 2}
B = {1, 3}
A − B = {1, 2} − {1, 3} = {2}
B − A = {1, 3} − {1, 2} = {3}
(A − B) 6= (B − A)

Associativity
When the grouping of elements in an operation doesn’t change the result, we say the
result is associative. Addition is associative:

(a + b) + c = a + (b + c)

In set theory, Union, Intersection and Symmetric Difference are all associative opera-
tions. Set difference is not associative:

16
Week 2

A = {1, 2}
B = {1, 3}
C = {2, 3}
(A − B) − C = ({1, 2} − {1, 3}) − {2, 3}
= {2} − {2, 3}
=∅

A − (B − C) = {1, 2} − ({1, 3} − {2, 3})


= {1, 2} − {1}
= {2}

∴ (A − B) − C 6= A − (B − C)

Distributivity
The distributive property, in general, refers to the distributive law of multiplication which
states that multiplying a sum of two numbers b and c by a coefficient a is the same as
multiplying each addend by the coeficient a and adding the resulting products. We say
the multiplication is distributive over the addition:

a · (b + c) = a · b + a · c

Similarly, the set union is distributive over set intersection:

A ∪ (B ∩ C) = (A ∪ B) ∩ (B ∪ C)

And the set intersection is distributive over the set union:

A ∩ (B ∪ C) = (A ∩ B) ∪ (B ∩ C)

Table of Set Identities

17
Week 2

Union Name Intersection


A∪B =B∪A commutative A∩B =B∩A
(A ∪ B) ∪ C = A ∪ (B ∪ C) associative (A ∩ B) ∩ C = A ∩ (B ∩ C)
A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C) distributive A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)
A∪B =A∩B De Morgan’s Laws A∩B =A∪B
A∪∅=A identities A∩∅=∅
A∪U =U A∩U =A
A∪A=U complement A∩A=∅
U =∅ ∅=U
A=A double complement
A ∪ (A ∩ B) = A absorption A ∩ (A ∪ B) = A
A−B =A∩B set difference

Applying set identities to simplify expressions


Show that (A ∩ B) ∪ B = B ∩ A

(A ∩ B) ∪ B = (A ∩ B) ∩ B
= (A ∩ B) ∩ B
= (A ∪ B) ∩ B
=A∩B∪B∩B
=A∩B∪∅
=A∩B
=B∩A

1.207 Partition
A partition of an object is a subdivision of the object into parts such that the parts are
completely separated from each other, yet together they form the whole object.
Data partitioning has many applications in Computer Science such as Big Data analysis.
This is usually referred to as Divide and Conquer approach. Such techniques must be
applied in cases where the entire input data doesn’t fit into the physical memory of the
Computer. In such cases, we must find a way to partition the data so that subsets of the
original data can be operated on without changing the result of the whole computation.

Definition of a partition of a set


Two sets A and B are said to be disjointed if and only if A ∩ B = ∅.

18
Week 2

Definition 9 (Set Partition). A partition of set A is a set of subsets Ai such that all
subsets are disjointed and then union of all subsets Ai is equal to A.

19
Week 3

Learning objectives:
• Define a function.
• Describe the properties of functions.
• Explain how to plot a function.
Essential Reading
• Rosen, K.H. Discrete mathematics and its applications. (New York: McGraw-Hill,
2012) 7th edition, pp.140–146.
• Exercises
pp.153–154 exercises 1–4 and 6–17.

2.101 Introduction
A function is a rule that relates to how one quantity depends on another quantity. Much
like a voltage depends on electrical current and resistance.
During this lecture, we learn the definition of a function and study a few of their prop-
erties.

2.102 The Definition of A Function


A function is a relation between a set of inputs and a set of outputs such that each input
maps to exactly one output.

Definition
A function maps an element of set 1 to an element in set 2. Such mapping is well-behaved
meaning that given a starting point we always know exactly where to go. For example,
we could have a function that maps a set of strings to their corresponding number of
characters:

20
Week 3

S1 = {Sea, Land, Sky}


S2 = {1, 2, 3, 4, 5, 6}

Sea → 3
Land → 4
Sky → 3

From Rosen’s book, functions are defined as:


Definition 10 (Function). Let A and B be nonempty sets. A function f from A to B
is an assignment of exactly one element of B to each element of A. We write f (a) = b
if b is the unique element of B assigned by the function f to the element a of A. If f is
a function from A to B, we write f : A → B and read as f maps A to B.
x ∈ A : x → f (x) = y (y ∈ B)

Domain, co-domain and range of a function


Given a function f : A → B
x ∈ A → f (x) = y ∈ B
A is the set of inputs and its referred to as the Domain of f. We write it as Df = A.
B is the set containing all possible outputs; referred to as the co-domain of f. We write
it as co − Df = B.
The set containing all outputs is called the Range of f and is written as Rf .

Image and pre-image (antecedent) of an element


y, the output of the function of a given input x, is called the Image of x where x itself
is called the pre-image of y. We write f (x) = y.

Example of Domain, co-domain and range


Let A be the set {On, Sea, Land, Sky}, B be the set {1, 2, 3, 4, 5, 6}, and f be the function
that maps the set of strings to their corresponding number of characters. We have:

On → 2
Sea → 3
Land → 4
Sky → 3

21
Week 3

In this case:

Df = A = {On, Sea, Land, Sky}


co − Df = B = {1, 2, 3, 4, 5, 6}
Rf = {2, 3, 4}

Moreover, we can say that 2 is the image of the string On and On is the pre-image of 2.
P re − images(2) = {On}.
3 is the image of Sea and Sky, therefore P re − images(3) = {Sea, Sky}.

2.104 Plotting functions


We explore and plot some special functions.

Linear Functions
A function f is called a linear function if it is of the form f (x) = ax + b. This function
is a straight line passing through the point (0, b) with gradient a.
If a > 0, then the function is increasing. It’s decreasing if a < 0.
In order to plot this function, first we make a table of values for this function. We use
f (x) = 3x + 2 as an example.
x f(x)
0 2
1 5
2 8
3 11
4 14

22
Week 3

Quadratic functions
A function f of the form f (x) = ax2 + bx + c is called a Quadratic function.
x f(x)
0 0
1 1
2 4
3 9
4 16

23
Week 3

Exponential functions
A function f of the form f (X) = bx is called an exponential function. The variable b is
called the base of the function.
A more formal definition may be:
Definition 11 (Exponential Function). The function f defined by f : R → R+ and
f (x) = bx where b > 0 and b 6= 1 is called and exponential function with a base b.
x f(x)
0 1
1 2
2 4
3 8
4 16

24
Week 3

Exponentials have some properties which are good to remember:


Form Result
bx · b y bx+y
bx
by bx−y
(bx )y bx·y
(a · b)x a x · bx
a x ax
b bx
1
b−x bx

The point (0, 1) is the common point for all exponentials. When b > 1 we have an
exponential growth. When 0 < b < 1, we have exponential decay.

2.106 Injective and surjective functions


Injective Functions
Let f : A → B be a function; f is said to be injective, or one-to-one if and only if
∀a, b ∈ A, if a 6= b then f (a) 6= f (b). In plain english, this means that two different
inputs will lead to two different outputs, i.e. given two different inputs a and b, then the
image of a is different than the image of b.
A corollary of this is that:
Corollary 1. ∀a, b ∈ A, f (a) = f (b) → a = b
1. Example: linear function

25
Week 3

Show that a function f : R → R with f (x) = 2x + 3 is an injection (one-to-one).


We can prove this in two different ways. The first proof assumes f (a) = f (b)

Proof. Let a, b ∈ R, show that if f (a) = f (b) then a = b.

f (a) = f (b) →2a + 3 = 2b + 3


2a + 3 − 3 = 2b + 3 − 3
2a = 2b
2a 2b
=
2 2
a=b

∴ f is injective.

The second proof assumes a 6= b

Proof. Let a, b ∈ R, show that if a 6= b then f (a) 6= f (b).

a 6= b →2a 6= 2b
2a + 3 6= 2b + 3
f (a) 6= f (b)

∴ f is injective.

2. Example: quadratic function


To prove that a function is not injective, we only need to find one example of two
different inputs having the same image.
Show that a function f : R → R with f (x) = x2 is not injective.

Proof.
f (5) = (5)2 = (−5)2 = f (−5)
however 5 6= −5

∴ f is not injective.

However, if we change the domain of the function such that f : R+ → R, we can


make it injective. To prove this, we can apply the same two methodologies from
the previous example.

26
Week 3

Surjective Functions
Let f : A → B be a function; f is said to be surjective, or onto if and only if ∀y ∈ B ∃x ∈
A | y = f (x). This means that every element in the co-domain of f , B, has at least
one pre-image in the domain of f , A. This is equivalent to saying that the range and the
co-domain of a surjective function, are equal (i.e. Rf = co − Df ).
1. Example: linear function
Show that a function f : R → R with f (x) = 2x + 3 is a surjection (onto).
To prove this, we must show that for every element in B, there is a pre-image in
A.

Proof. Let y ∈ R, show that ∃x ∈ R | f (x) = y.

f (x) = y →2x + 3 = y
2x + 3 − 3 = y − 3
2x y−3
=
2 2
y−3
x= ∈R
2
y−3
∴ ∀y ∈ R∃x = 2 ∈ R | f (x) = y, hence f is surjective.

2. Example: quadratic function


Show that a function f : R → R with f (x) = x2 is not a surjection.

Proof. Let y ∈ R, show that ∃x ∈ R | f (x) = y.


Let y ∈ R, show that ∃x ∈ R | f (x) = y.
Rf = [0, +∞[6= co − Df = R
∴ f is not surjective.

27
Week 4

Learning objectives:
• Discuss special functions.
• Describe inverse functions.
Essential Reading
• Rosen, K.H. Discrete mathematics and its applications. (New York: McGraw-Hill,
2012) 7th edition, pp.146–153.
• Exercises
pp.153–155 exercises 5, 14–25, 30–36, 44–46 and 49.
For logarithmic and exponential functions, please read Appendix 2 and complete exercises
1 to 6 in Appendix 2.

2.201 Function composition


Using examples we will understand function composition and how to work out the compo-
sition of two functions. We will also show that function composition is not commutative.
Given two functions, f and g, the composition of f and g is written as f ◦ g = f (g(x)).
For example, let f (x) = 2x and g(x) = x2 , the composition of f and g can be worked
out as follows:

(f ◦ g)(x) = f (g(x))
= f (x2 )
= 2x2

(f ◦ g)(1) = f (g(x))
= f (12 )
= 2 · 12
=2

28
Week 4

What this means is that if we have a function g : A → B and a function f : B → C,


function composition allows us to produce a function (f ◦ g) : A → C.
Note that function composition is not commutative. In other words, f ◦ g 6= g ◦ f . Let
f = 2x and g = x2 , we can show that (f ◦ g) = 2x2 and (g ◦ f ) = 4x2 .

2.203 Bijective functions


Definition
A bijective or invertible function is a function f : A → B that can be described as both
injective and surjective simultaneously. This means that each element of the co-domain
has exactly one pre-image.
Definition 12 (Bijection). A function f (x) is said to be bijective if and only if it is both
injective and surjective.

Exercise 1:
Show that the function f : R → R with f (x) = 2x + 3 is a bijective (invertible) function.

Proof. To prove this, suffices to prove that this function is both an injection and a
surjection. Let’s prove the injection case first:
Let a, b ∈ R, we will show that if f (a) = f (b) then a = b.

f (a) = f (b) →2a + 3 = 2b + 3


2a + 3 − 3 = 2b + 3 − 3
2a = 2b
2a 2b
=
2 2
a=b

∴ f is injective.
Now turning our attention to the surjection case, we have:
Let y ∈ R, we will show that ∀y ∈ R∃x ∈ R | f (x) = y.

f (x) = y →2x + 3 = y
2x + 3 − 3 = y − 3
2x y−3
=
2 2
y−3
x= ∈R
2

29
Week 4

y−3
∴ ∀y ∈ R∃x = 2 ∈ R | f (x) = y, hence f is surjective.
Because we have proved that f (x) = 2x + 3 is both an injection and a surjection, we
have also proved that it is a bijection.

Inverse function
Definition 13 (Inverse function). Let f : A → B, if f is bijective, then the inverse
function f −1 exists and is defined as f −1 : B → A.
Given this definition, let’s find the inverse of 2x + 3.

Exercise 2:
The following function f : R → R with f (x) = 2x + 3 is a bijection. Find the inverse
function f −1 .

f (x) = 2x + 3
f (x) = y
2x + 3 = y
2x + 3 − 3 = y − 3
2x y−3
=
2 2
y−3
x=
2

x−3
∴ f −1 (x) =
2

Identity function
There is one special case of composition which is (f ◦ f −1 )(x) = (f −1 ◦ f )(x) = x. For
example if f (x) = 2x, then f −1 (x) = x2 , therefore (f ◦ f −1 )(x) = 2 x2 = x. Similarly,
(f −1 ◦ f )(x) = 2x
2 = x.

Plotting the inverse function


The function f and its inverse f −1 are always symmetric to the straight line y = x.

30
Week 4

y
f (x) = 2xf (x) = x

x
f (x) = 2

2.205 Logarithmic functions


Exponential and logarithmic functions are closely related. Therfore, let’s review expo-
nential functions before dealing with logarithmic functions.
Exponential functions were defined back in Definition 11. We know from that definition
that:

y = f (x) = bx (b > 0, b¬1)

The domain of the function is (−∞, +∞).


The range of the function is (0, +∞).
The graph of an exponential function always passes through the point with coordinates
(0, 1). If the base b is greater than 1, then the function is increasing on (−∞, +∞) and
we call it exponential growth. Conversely, if b < 1, then the function is decreasing on
(−∞, +∞) and we call it exponential decay.

Definition
With that review out of the way, we can define Logarithmic functions:
Definition 14 (Logarithmic function). The logarithmic function with base b where b > 0
and b 6= 1 is defined as follows:

logb x = y ↔ x = by

We can say that logb x is the inverse function of the exponential function bx .

31
Week 4

Laws of logarithmic functions


1. logb m × n = logb m + logb n
2. logb m
n = logb m − logb n

3. logb mn = n timeslogb m
4. logb 1 = 0
5. logb b = 1

Exercise 1
1. log3 81
log3 81 = log3 34 = 4 × log3 3 = 4 × 1 = 4
2. log10 100
log10 100 = log10 102 = 2 × log10 10 = 2 × 1 = 2
1
3. log3 81
1
log3 81 = log3 81−1 = log3 3−4 = −4 × log3 3 = −4 × 1 = −4
4. log2 1
log2 1 = log2 20 = 0 × log2 2 = 0 × 1 = 0

Natural logarithm
The natural logarithm, commonly written as ln(x) is the logarithm with base e. In other
words: ln(x) = loge x where e ≈ 2.71828.

2.207 Floor and ceiling functions


Floor function
Definition 15 (Floor function). The floor function is a function f : R → Z. It takes
a real number x as input and outputs the largest integer that is less than or equal to x.
Denoted as f loor(x) = ⌊x⌋.
For example, given a real number x such that n ≤ x < n + 1, the floor of x is n. In other
words: f loor(x) = ⌊x⌋ = n.

32
Week 4

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

−2

−3

−4

We can think of the floor function as if we’re walking on the number line to the left until
we find an integer. This means that ⌊1.1⌋ = 1 but ⌊−1.1⌋ = −2.

Ceiling function
Definition 16 (Ceiling function). The ceiling function is a function f : R → Z. It
takes a real number x as input and outputs the smallest integer that is greater than or
equal to x. Denoted as ceiling(x) = ⌈x⌉.
For example, given a real number x such that n < x ≤ n + 1, the ceiling of x is n + 1. In
other words: ceiling(x) = ⌈x⌉ = n + 1.

33
Week 4

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

−2

−3

−4

This is exact opposite of the floor function. So we can think of it as if were were walking
on the number line to the right until we find an integer. This means that ⌊1.1⌋ = 2, but
⌊−1.1⌋ = −1.

Exercise 1
Let n be an integer and x a real number. Show that:

⌊x + n⌋ = ⌊x⌋ + n

Proof. Let m be an integer such that m = ⌊x⌋. By definition of the floor function we have
m ≤ x < m+1. Addin n to both sides of this inequality, we have m+n ≤ x+n < m+n+1.
This implies that ⌊x + n⌋ = m + n by definition. And m = ⌊x⌋. Therefore ⌊x + n⌋ =
⌊x⌋ + n.

34
Week 5

Learning Objectives
• Explain and apply basic concepts of propositional logic.
• Construct truth tables of propositions and use them to demonstrate the equivalence
of logical statements.
• Translate natural language statements into symbolic logical statements and vice
versa.
Essential Reading
• Rosen, K.H. Discrete mathematics and its applications. (New York: McGraw-Hill,
2012) 7th edition, pp.1–12.
• Exercises
p.12 exercises 1–3.

3.101 Introduction to propositional logic


Definition 17 (Propositional Logic). It is a branch of logic that is interested in studying
mathematical statements.
Propositional Logic is the basis of all mathematical reasoning and the rules used to
construct mathematical theories. Its original purpose was to model reasoning and dates
back to Aristotle.
Effectively, it is an algebra of propositions. In this algebra, the variables are unknown
propositions rather than unknown real numbers.
The operators used are and (∧), or (∨), not (¬), implies (→) and if and only if (↔)
instead of our regular +, −, ×, and ÷.

Applications of propositional logic


Propositional logic can be used in logic circuit design. It can also be applied to program-
ming languages, such as Prolog.

35
Week 5

Many computer reasoning systems, including theorem provers, program verifiers and
applications in the field of Artificial Intelligence, have been implemented in logic-based
programming languages.
These languages, generally employ predicate logic, a form of logic that extends the ca-
pabilities of propositional logic.

3.103 Propositions
Definition 18 (Proposition). A declarative sentence that is either true or false, but not
both.
A Proposition is the most basic element of logic. Which means that propositions are the
building blocks for our reasoning and logical statements.

Examples of propositions
As mentioned above, a proposition must be a declarative statement that is either true or
false, therefore the following statements are propositions:
• London is the capital of the United Kingdom
We know this is true, so this is considered to be a true proposition.
• 1+1=2
This is also a true proposition.
• 2<3
This is also a true proposition.
• Madrid is the capital of France
This is a false proposition.
• 3<2
This is also a false proposition.
• 10 is an odd number
This is also a false proposition.
What follows is a series of statements which are not propositions, as they can not assume
a true or false value:
• x+1=2
We don’t know the value of x, so this is not a proposition. However, if a value
is assigned to x, then at that moment it becomes a proposition. IF we assign the

36
Week 5

value 1 to x, this will be a true proposition, if any other value is assigned to x,


then it’ll be a false proposition.
• x+y =z
Also not a proposition as x, y and z have no values.
• What time is it?
Is not a proposition as it is not a declarative sentence.

Propositional Variables
To avoid writing long, repetivive propositions, we make use of propositional variables.
They are typically a letter, such as p, q, r, . . .
We can assign letters to our previous propositions, for example: Let p be the proposition
London is the capital of the United Kingdom.

3.105 Truth tables and truth sets


As we begin to build more complex compound propositions, we need a method of keeping
track of this proposition’s truth value. A truth table is one such method.

True Tables
A truth table is tabular representation of all the possible combinations of truth values
for a set of propositional variables.
For example:
p q
F F
F T
T F
T T
A truth table of n propositional variables, will contain 2n rows. So a table for 3 propo-
sitional variables, will have 8 rows:

37
Week 5

p q r
F F F
F F T
F T F
F T T
T F F
T F T
T T F
T T T

Truth Set
Definition 19 (Truth Set). Let p be a proposition on a set S. The truth set of p is the
set of elements of S for which p is true.
Commonly, we use a capital letter to refer to the truth set of a proposition. For example
the truth set of a proposition p is referred to as P .
1. Example
Let S = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}.
Let p and q be two propositions concerning an integer n in S, defined as follows:
p : n is even
q : n is odd
Therefore, the truth set of p is P = {2, 4, 6, 8, 10} and the truth set of q is Q =
{1, 3, 5, 7, 9}.

3.107 Compound propositions


Compound propositions are built by combining propositions with logical operators (also
referred to as connectives). The connectives which we deal with in this lecture are:
• Negation ¬
• Conjunction ∧
• Disjunction ∨
• Exclusive-or ⊕

Negation ¬
Let p be a proposition, the negation of p, denoted by ¬p, and read as “not p”, is the
statement: it is not the case that p.

38
Week 5

For example if p is the statement John’s program is written in Python, then ¬p is the
statement John’s program is not written in Python.
p ¬p
F T
T F

Conjunction ∧
Let p and q be propositions, the conjuntion of p and q, denoted by p ∧ q, and read as “p
and q”, is the statement: p and q.
The conjunction is only true when both p and q are true and false otherwise.
For example if p is the statement John’s program is written in Python, and q is the
statement John’s program has less then 20 lines of code, then p ∧ q is the statement
John’s program is written in Python and has less than 20 lines of code.
p q p∧q
F F F
F T F
T F F
T T T

Disjunction ∨
Let p and q be propositions, the disjuntion of p and q, denoted by p ∨ q, and read as “p
or q”, is the statement: p or q.
The disjunction is only false when both p and q are false and true otherwise.
For example if p is the statement John’s program is written in Python, and q is the
statement John’s program has less then 20 lines of code, then p ∨ q is the statement
John’s program is written in Python or has less than 20 lines of code.
p q p∨q
F F F
F T T
T F T
T T T

Exclusive-or ⊕
Let p and q be propositions, the exclusive-or of p and q, denoted by p ⊕ q, and read as
“p exclusive-or q”, is the statement: p exclusive-or q.
The exclusive is true when either p or q are true, but not both.

39
Week 5

For example if p is the statement John’s program is written in Python, and q is the
statement John’s program has less then 20 lines of code, then p ⊕ q is the statement
John’s program is written in Python or has less than 20 lines of code, but not both.
p q p⊕q
F F F
F T T
T F T
T T F

Precedence of logical operators


Propositions can be combined to build complex compound propositions. To do this we
need to start relying on precedence of logical operators or use parenthesis.
The meaning of compound propositions can change depending on the order in which
parentheses are used. For example (p ∨ q) ∧ (¬r) 6= p ∨ (q ∧ ¬r).
Here’s a small table of precedence:
Operator Precedence
¬ 1
∧ 2
∨ 3

Exercise
Given a positive integer n, let’s consider the propositions p and q, where:
• p: n is an even number
• q: n is less than 10
Let’s write the logical expression for each of the following propositions:
1. n is an even number and is less than 10 p ∧ q
2. n is either an even number or is less than 10 p ∨ q
3. n is either an even number or is less than 10 but not both p ⊕ q
4. ¬p ∨ (p ∧ q)
p q p∧q p∨q p⊕q ¬p ¬p ∨ (p ∧ q)
F F F F F T T
F T F T T T T
T F F T T F F
T T T T F F T

40
Week 6

Learning Objectives
• How to formalise a logical implication
• Apply the laws of propositional to analyse propositions and arguments.
Essential Reading
• Rosen, K.H. Discrete mathematics and its applications. (New York: McGraw-Hill,
2012) 7th edition, pp.1–12.
• Exercises
p.13 exercises 6–12
p.14 exercises 19–21
p.33 exercises 6–11.

3.202 Logical implication (→)


Definition 20 (Implication). Let p and q be propositions. The conditional statement or
implication p → q is the proposition "if p then q".
p is called the hypothesis (or antecedent) q is called the conclusion (or consequence)
1. Example 1
Let p and q be the following statements:
• p: John did well in Discrete Mathematics
• q: John will do well in the Programming Course
The conditional statement p → q can be written as follows:
If John did well in Discrete Mathematics then John will do well in the Programming
Course.

41
Week 6

Truth Table
p q p→q
F F T
F T T
T F F
T T T
As we can see, the only situation where an implication evaluates to false is when our
hypothesis is true but the conclusion is false.

Different expressions for p → q


Let p and q be the following statements:
• p: It’s sunny
• q: John goes to the park
There are many ways to write the conditional statement p → q:
• p→q
• if p then q
• if p, q
• p implies q
• p only if q
• q follows from p
• p is sufficient for q
• q unless ¬p
• q is necessary for p
All of these forms are equivalent to if it’s sunny then John goes to the park.
Note that the statement John going to the park is necessary for a sunny day sounds a bit
strange in English. We should try to think of it as John going to the park is a necessary
consequence of a sunny day.

Converse, inverse and contrapositive


Let p and q be propositions and A the conditional statement p → q.
The conditional statement q → p is referred to as the converse of A.
The conditional statement ¬q → ¬p is referred to as the contrapositive of A.

42
Week 6

The conditional statement ¬p → ¬q is referred to as the inverse of A.


The contrapositive of A has the same truth table as A and is, therefore, equivalent to
it.
1. Example 2
Let p and q be the following statements:
• p: It’s sunny
• q: John goes to the park
• A = p → q: If it’s sunny then John goes to the park
Therefore:
• converse: If John goes to the park, then it’s sunny
• contrapositive: If John does not go to the park, then it’s not sunny
• inverse: If it’s not sunny then John does not go the park
We can build a large truth table with all of these:
p q p→q ¬q → ¬p ¬p → ¬q q→p
F F T T T T
F T T T F F
T F F F T T
T T T T T T
Note, also, that the converse or A and the inverse of A are equivalent.

3.204 Logical equivalence (↔)


Definition 21 (Logical Equivalence). Let p and q be propositions. The biconditional
or equivalence statement p ↔ q is the proposition p → q ∧ q → p.
Biconditional statements are also called bi-implications and can be read p if and only
if q

Truth Table
p q p↔q
F F T
F T F
T F F
T T T
We can see here that the biconditional statement of p and q is true whenever p and q
have the same truth value and is false otherwise.

43
Week 6

Equivalent propositions
Let p and q be propositions. We say that p and q are logically equivalent if they always
have the same truth value.
We write p ≡ q to signify that p is equivalent to q.
Note that ≡ is not a logical operator, and p ≡ q is not a compound proposition. p ≡ q
means that the compound proposition p ↔ q is always true.

Proving equivalence
One way of determining logical equivalence, is by means of truth tables and verifying
that two propositions have the same truth values for every possible input.
p q p→q ¬p ¬p ∨ q
F F T T T
F T T T T
T F F F F
T T T F T
If values difer in any row, then we demonstrate non-equivalence.
1. Example 1
Let p, q, and r be the following propositions concerning n:
• p: n = 20
• q: n is even
• r: n is positive
Let’s express each conditional statement below symbolically:
• If n = 20, then n is positive
p→r
• n = 20 if n is even
q→p
• n = 20 only if n is even
p→q

Precedence of logical operators (Updated)


Propositions can be combined to build complex compound propositions. To do this we
need to start relying on precedence of logical operators or use parenthesis.

44
Week 6

The meaning of compound propositions can change depending on the order in which
parentheses are used. For example (p ∨ q) ∧ (¬r) 6= p ∨ (q ∧ ¬r).
Here’s a small table of precedence:
Operator Name Precedence
¬ Negation 1
∧ Conjunction 2
∨ Disjunction 3
→ Conditional or Implication 4
↔ Biconditional or Equivalence 5

3.206 Laws of propositional logic


The following table summarizes the laws of Propositional Logic.
Disjunction Conjunction
Idempotent laws p∨p≡p p∧p≡p
Commutative laws p∨q ≡q∨p p∧q ≡q∧p
Associative laws (p ∨ q) ∨ r ≡ p ∨ (q ∨ r) (p ∧ q) ∧ r ≡ p ∧ (q ∧ r)
Distributive laws p ∨ (q ∧ r) ≡ (p ∨ q) ∧ (p ∨ r) p ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r)
Identity laws p∨F≡p p∧T≡p
Domination laws p∨T≡T p∧F≡F
De Morgan’s laws ¬(p ∨ q) ≡ ¬p ∧ ¬q ¬(p ∧ q) ≡ ¬p ∨ ¬q
Absorption laws p ∨ (p ∧ q) ≡ p p ∧ (p ∨ q) ≡ p
Negation laws p ∨ ¬p ≡ T1 p ∧ ¬p ≡ F2

Double negation ¬¬p ≡ p


law

1
A statement that’s always true is a Tautology
2
A statement that’s always false is a Contradiction

45
Week 7

Learning Objectives
• Describe the basic concepts of predicate logic.
• Describe existential and universal quantifiers.
• Assign truth values to quantified statements.
Essential Reading
• Rosen, K.H. Discrete mathematics and its applications. (New York: McGraw-Hill,
2012) 7th edition, pp.34–49 and pp.53–60.
• Exercises
pp.50–51 exercises 1–8, 10–12 and 15–20
p.60 exercises 1–5.

4.101 Introduction to predicate logic


Our previous Propositional Logic is useful for studying propositions but has some limi-
tations:
• It cannot express precisely the meaning of complex mathematical statements.
• It only studies propositions, i.e. statements with known truth values
Predicate Logic is a different type of Mathematical Logic which overcomes the limitations
of Propositional Logic and can be used to build more complex reasoning.

Example 1
Given the statements:
• All men are mortal.
• Socrates is a man.
It’s natural to conclude that Socrates is a man. This sort of reasoning cannot be expressed
by Propositional Logic. Predicate Logic enables us to formalise it.

46
Week 7

Example 2
Given the statement x square is equal to 4. We know this statement is NOT a proposi-
tion as its truth value is a function depending on x, however Predicate Logic can express
and formalise this statement.

4.103 What are predicates?


We start with some examples of statements which cannot be expressed by Propositional
Logic.

Insufficiency of Propositional Logic


Going back to the previous example x squared is equal to 4. We already saw that this
statement cannot be a proposition because its truth value is a function depending on x.

Definition of Predicate
Predicates are generalizations of propositions. They are (Boolean) functions which
return TRUE or FALSE depending on their variables. They become propositions when
their variables are assigned values.
Predicates, much like regular sentences, are composed of smaller parts. The statement x
square is equal to 4 contains two parts: the variable x; and the predicate is equal to 4.
We can formalize this statement as P (x) where P is the predicate squared is equal to 4
and x is the variable.
P is referred to as the Propositional Function.
As soon as a value is assigned to the variable x, the statement P (x) becomes a proposition
and has a truth value.
1. Example 1
Let x be an integer and let P be the propositional function square is equal to 4,
therefore P (2) is TRUE and P (3) is FALSE.

Predicates with multiple variables


It’s important to note that Predicates can depend on more than one variable.
1. Example 1
Let P (x, y) denote x2 > y, therefore P (−2, 3) ≡ 4 > 3 is TRUE and P (2, 4) ≡ 4 >
4 is FALSE.

47
Week 7

2. Example 2
Let Q(x, y, z) denote x + y < z, therefore Q(2, 4, 5) ≡ 2 + 4 < 5 which is FALSE,
Q(1, 2, 4) ≡ 1 + 2 < 4 which is TRUE, and Q(1, 2, z) is NOT a proposition.

Logical operations
All logic previously defined for propositional logic carries over to predicate logic.
1. Example 1
If P (x) denotes x2 < 16, then P (1) ∨ P (−5) ≡ (1 < 16) ∨ (25 < 16) ≡ T ∨ F ≡ T.

4.105 Quantification
Quantification expresses the extent to which a predicate is true over a range of elements.
The two most most important quantifiers are the universal quantifier ∀ and the existential
quantifier ∃.
There is a third quantifier called the uniqueness quantifier ∃!.
1. Example 1
The following statements give examples of quantified predicates.
• All men are mortal.
• Some computers are not connected to the network.

Universal Quantifier ∀
The Universal Quantification of a predicate P (x) is the proposition:
• P (x) is true for all values of x in the universe of discourse.
We use the notation ∀xP (x) and read it as for all x.
If the universe of discourse is finite {n1 , n2 , . . . , nk } then the universal quantifier is the
conjunction of the propositions over all elements: ∀xP (x) ≡ P (n1 )∧P (n2 )∧. . .∧P (nk ).
1. Example 1
Let P, Q denote the following propositional functions of x:
• P (X): x must take a discrete mathematics course
• Q(X): x is a Computer Science student
Where the universe of discourse for both P (x) and Q(x) is all university students.
Let’s express the following statements symbolically:

48
Week 7

• Every CS student must take a course on discrete mathematics.


∀xQ(x) → P (x)
• Everybody must take a discrete mathematics course or be a CS student.
∀x(P (x) ∨ Q(x))
• Everybody must take a discrete mathematics course and be a CS student.
∀x(P (x) ∧ Q(x))
2. Example 2
Let’s formalise the following statement S
• S: For every x and for every y, x + y > 10
Let P (x, y) be the statement x + y > 10, where the universe of discourse is
the set of all integers.
∀x∀yP (x, y) ≡ ∀x, yP (x, y)

Existential Quantifier ∃
The existential quantification of a predicate P (x) is the proposition There exists a value
of x in the universe of discourse, such that P (x) is true.
If the universe of discourse is finite {n1 , n2 , . . . , nk }, then the existential quantifier is the
disjunction of the proposition over all elements: ∃xP (x) ≡ P (n1 ) ∨ P (n2 ) ∨ . . . ∨ P (nk ).
1. Example 1
Let P (x, y) denote the statement x + y = 5. The expression ∃x∃yP (x, y) means
“There exists a value x and a value y in the universe of discourse such that x+y = 5
is true”.
2. Example 2
Let a, b, c denote fixed real numbers and S be the statement /There exists a real
solution to ax2 + bx − c = 0. S can be expressed as ∃xP (x).

Uniqueness Quantifier ∃!
The uniqueness quantification of a predicate P (x) is the proposition There exists a unique
value x in the universe of discourse such that P (x) is true.
The uniqueness quantifier is a special case of the existential quantifier.
We use the notation ∃!xP (x) and read it as /there exists a unique x“.

49
Week 7

Example 1
Let P (x) be the statement x2 = 4. The expression ∃!xP (x) means “There exists a unique
value of x such that x2 = 4 is true”.

4.107 Nested Quantifiers


When we want to express statements with multiple variables, we employ nested quanti-
fiers.
Nested Quantifier Meaning
∀x∀yP (x, y) P (x, y) is true for every pair (x, y)
∃x∃yP (x, y) There is a pair (x, y) for which $P(x,y) is true
∀x∃yP (x, y) For all x, there is a y for which P(x,y) is true
∃x∀yP (x, y) There is an x for which P (x, y) is true for all y

Binding Variables
A variable is said to be bound if it is within the scope of a quantifier. A variable that
is not bound is called a free variable.
1. Example 1
Let P be a propositional function and S be the statement ∃xP (x, y). In this case,
x is bound while y is free.

Logical operations
All the logical operations discussed previously, can also be applied to quantified state-
ments.

Order of operations
When we have quantifiers of the same type, either all universal or all existential, the
other doesn’t matter. However, when we’re dealing with quantifiers of different types we
must apply the quantifiers at the correct order.
1. Example 1
∀x∀yP (x, y) ≡ ∀y∀xP (x, y)
However
∀x∃yP (x, y) 6= ∃y∀xP (x, y)

50
Week 7

Precedence of Quantifiers
The quantifiers ∀ and ∃ have precedence over all other logical operators. This means
that ∀xP (x) ∨ Q(x) should be read as (∀xP (x)) ∨ Q(x) and ∀xP (x) → Q(x) is to be
read as (∀xP (x)) → Q(x).

51
Week 8

Learning Objectives
• Identify logical equivalence involving quantifiers and apply De Morgan’s laws.
• Apply predicate logic to programming.
Essential Reading
• Rosen, K.H. Discrete mathematics and its applications. (New York: McGraw-Hill,
2012) 7th edition, pp.26–28 and pp.62–74.
• Exercises
p.32 exercises 1–5
pp.74–75 exercises 1–5 and 8–12.

4.201 De Morgan’s laws for quantifiers


The intuition of De Morgan’s Laws
Negating quantified expressions is a common activity. Starting with an example.
Let S be the statement All the university’s computers are connected to the network, and
P be the statement There is at least one computer in the university operating on Linux.
Intuitively we can find contradictions to both S and P . In the case of S, if we find at
least one computer not connected to the network, then we contradict S. In the case
of P , if not a single computer operates on Linux, we contradict P . Note that the
statement Not a single computer operates on Linux is equivalent to All computers are
not operating on Linux.
De Morgan’s Laws formalise these intuitions.

De Morgan’s Laws
Quantified Expression Negated Expression
∀xP (x) ∃x¬P (x)
∃xP (x) ∀x¬P (x)

52
Week 8

Example 1
Let S be the statement Every student of Computer Science has taken a course in Neural
Networks. Therefore S can be expressed symbolically as ∀xP (x) where U = {students in CS}
and P (x) = x has taken a course in Neural Networks.
The negation of S is ¬S which translates to It is not the case that every student in
Computer Science has taken a course in Neural Networks. This statement implies that
There is at least one student of Computer Science who has not taken a course in Neural
Networks. Which can be expressed symbolically as ∃x¬P (x).

Negating nested quantifiers


When we have expressions with nested quantifiers, we simply apply De Morgan’s succes-
sively from left to right.

∀x∃y∀zP (x, y, z) ≡ ∃x¬∃y∀zP (x, y, z)


≡ ∃x∀y¬∀zP (x, y, z)
≡ ∃x∀y∃z¬P (x, y, z)

4.203 Rules of inference


Valid argument
In propositional logic, an argument is defined as a sequence of propositions. The final
proposition is called the conclusion and each of the other propositions are called the
premises (or hypotheses).
And argument is valid if the truth of all its premises implies the truth of the conclusion.
1. Example 1
Given the following argument:
• If you have access to the internet, you can order a book in Machine Learning.
• You have access to the internet

• ∴ Therefore, you can order a book on Machine Learning.


This argument is valid because whenever all its premises are true, the conclusion
must also be true.
2. Example 2
Given the following argument:

53
Week 8

• If you have access to the internet, you can order a book in Machine Learning.
• You can order a book on Machine Learning.

• ∴ Therefore, you have access to the internet.


This argument is not valid because we can imagine situations where both premises
are true, but the conclusion is false.

Rules of inference
These can be seen as building blocks for constructing complex valid arguments incre-
mentally.
Given an argument, we could use a truth table to decide whether an argument is true or
false, however we will need 2n rows in the truth table for n variables. This process can
be really labor-intensive.
Rules of inference, however, provide a much simpler way of proving the validity of an
argument.
Moreover, every rule of inference can be proved using a Tautology1 .

Modus Ponens
Here’s the tautology used as the basis for Modus Ponens.
(p ∧ (p → q)) → q
And the rules of inference
p→q
p
∴q
And an example
p: It is snowing
q: I will study Discrete Mathematics

If it is snowing, I will study Discrete Mathematics.


It is snowing.

Therefore, I will study Discrete Mathematics.

54
Week 8

Modus Tollens
Tautology shown below is the basis for Modus Tollens.
(¬q ∧ (p → q)) → ¬p
And the rule of inference
¬q
p→q
∴ ¬p
And an example
p: It is snowing
q: I will study Discrete Mathematics

I will not study Discrete Mathematics


If it is snowing, I will study Discrete Mathematics.

Therefore, it is not snowing.

Conjunction
The following tautology is the basis for Conjunction.
((p) ∧ (q)) → (p ∧ q)
This leads to the following rule of inference
p
q
∴p∧q
And an example
p: I will study Programming
q: I will study Discrete Mathematics

I will study Programming


I will study Discrete Mathematics

Therefore, I will study Programming and Discrete Mathematics

Simplification
The next tautology is the basis for Simplification
(p ∧ q) → p

55
Week 8

It leads to the following valid argument form


p∧q
∴p
And an example
p: I will study Programming
q: I will study Discrete Mathematics

I will study Programming and Discrete Mathematics

Therefore, I will study Programming

Addition
The tautology shown below is the basis for Addition
p → (p ∨ q)
It leads to the following valid argument form
p
∴p∨q
And an example
p: I will study Programming
q: I will study Discrete Mathematics

I will study Programming

Therefore, I will study Programming or Discrete Mathematics

Hypothetical Syllogism
The tautology that follows is the basis for Hypothetical Syllogism
(p → q) ∧ (q → r)) → (p → r)
It leads to the following valid argument form
p→q
q→r
∴p→r
And an example
p: It is snowing

56
Week 8

q: I will study Discrete Mathematics


r: I will get good grades

If it is snowing, then I will study Discrete Mathematics


If I study Discrete Mathematics, then I will get good grades

Therefore, if it is snowing, then I will get good grades

Disjunctive Syllogism
The following tautology is the basis for Disjunctive Syllogism
((p ∨ q) ∧ ¬p) → q
It leads to the following valid argument form
p∨q
¬p
∴q
And an example
p: I will study Programming
q: I will study Discrete Mathematics

Either I will study Programming or Discrete Mathematics


I will not study Programming

Therefore, I will study Discrete Mathematics

Resolution
The next tautology is the basis for Resolution
((p ∨ q) ∧ (¬p ∨ r)) → (q ∨ r)
It leads to the following valid argument form
p∨q
¬p ∨ r
∴q∨r
And an example
p: It is raining
q: It is cold
r: It is snowing

57
Week 8

Either it’s raining or it’s cold


It’s not raining or it’s snowing

Therefore, It’s cold or it’s snowing

Building valid arguments


1. If it’s initially written in English, transform into argument form by assigning vari-
ables to each proposition
2. Start with the hypothesis of the argument
3. Build a sequence of steps in which each step follows from the previous by applying
rules of inference or laws of logic
4. The final step is the conclusion
1. Example 1
Let’s build a valid argument from the following premises:
• It is not cold tonight
• We will go to the theatre only if it is cold
• If we do not go to the theatre, we will watch a movie at home
• If we watch a movie at home, we will need to make popcorn
First, we define our propositional variables:
• p: It is cold tonight
• q: We will go to the theatre
• r: We will watch a movie at home
• s: We will need to make popcorn
Next, we convert English into logical statements using our propositional variables.
We have, respectively:
• ¬p
• q→p
• ¬q → r
• r→s
Now we can build a valid argument:

58
Week 8

Step Justification
1 q→p Hypothesis
2 ¬p Hypothesis
3 ∴ ¬q Modus Tollens 1,2
4 ¬q → r Hypothesis
5 ∴r Modus Ponens 3,4
6 r→s Hypothesis
7 ∴s Modus Ponens 5,6
Conclusion: We will need to make popcorn

Fallacies
A fallacy is the use of incorrect argument when reasoning. Formal fallacies can be
expressed in propositional logic and proved to be incorrect.
Common formal fallacies:
• affirming the consequent
• a conclusion that denies the premises
• contradictory premises
• denying the antecedent
• existential fallacy
• esclusive premises

4.205 Rules of inference with quantifiers


The rules are:
• Universal Instantiation
• Universal Generalisation
• Existential Instantiation
• Existential Generalisation
• Universal Modus Ponens
• Universal Modus Tollens
These rules will either reintroduce or remove quantifiers within a statement.

59
Week 8

Universal Instantiation (UI)


The rule of inference:
∀xP (x)
∴ P (c)
Example:
All Computer Science students study Discrete Mathematics.

∴ Therefore John, who is a Computer Science student, studies Discrete Mathematics.

Universal Generalisation (UG)


The following rule of inference is used to conclude that a proposition is valid for all
members of the Universe of Discourse by showing that it is valid for an arbitrary element
in the Universe of Discourse.
P (c)
∴ ∀xP (x)
Example:
Let DS = {all data science students} and let c be an arbitrary element in DS.
c studies machine learning.

∴ Therefore, ∀x ∈ DS, x studies machine learning.

Existential Instatiation (EI)


This is used to conclude that there is an element c for which P (c) is true.
∃xP (x)
∴ P (c)
Example:
Let DS = {all data science students}. There exists a student x of data science who uses
Python Pandas Library.

∴ Therefore, there is a student, c, who is using Python Pandas Library.

60
Week 8

Existential Generalization (EG)


The existential generalization is used to conclude that ∃xP (x) when P (c) is true for some
c.
P (c)
∴ ∃xP (x)
Example:
Let DS = {all data science students}. John, a student of data science, got an A in the
machine learning course.

∴ Therefore, there exists someone in DS who got an A in machine learning.

Universal Modus Ponens


The Universal Modus Ponens can be thought of as a combination of Universal Instanti-
ation and Modus Ponens.
∀xP (x) → Q(x)
P (a)
∴ Q(a)
Example:
Let DS = {all data science students}. Every computer science student studying data
science, will study machine learning.
John is studying data science.

∴ John will study machine learning.

Universal Modus Tollens


Similarly, this can be seen as a combination of Universal Instantiation and Modus Tollens.
∀xP (x) → Q(x)
¬Q(a)
∴ ¬P (a)
Example:
Let DS = {all data science students}. Every computer science student studying data
science, will study machine learning.
John is not studying machine learning.

61
Week 8

∴ John is not studying data science.

Expressing complex statements


Given a statement in natural language, we can formalise it by following these steps:
1. Determine the universe of discourse of the variables
2. Reformulate the statement by making for all and there exists explicit
3. Reformulate the statement by introducing variables and defining predicates.
4. Reformulate the statement by introducing quantifiers and logical operations.
1. Example 1
Express the following statement S: There exists a real number between any two not
equal real numbers.
a) The universe of discourse is the set of all real numbers R.
b) For all real numbers, there exists a real number between any other two real
numbers.
c) For all real numbers x and y, there exists a real number z between x and y.
d) ∀x, y ∈ R ∃z ∈ R x < z < y
2. Example 2
Express the following statement S: Every student has taken a course in machine
learning.
a) The universe of discourse is the set of all students CS. Let M (x) be the
proposition has taken a course in machine learning.
b) For all students, every student has taken a course in machine learning.
c) For all students x, x has taken a course in machine learning.
d) ∀x M (x).
If the Universe of discourse changes, the expression changes:
a) The universe of discourse is the set of all people. Let S(x) be the proposition
is a student and M (x) be the proposition has taken a course in machine
learning.
b) S can be expressed as ∀x(S(x) → M (x)).

62
Week 9

Learning Objectives
• Write Boolean expressions.
• Use the laws of Boolean algebra to simplify Boolean expressions.
• Represent a Boolean function.
• Simplify logic circuits/expressions.
• Convert truth tables into Boolean expressions and vice versa.
Essential Reading
• Rosen, K.H. Discrete mathematics and its applications. (New York: McGraw-Hill,
2012) 7th edition, pp.811–821.
• Exercises
pp.818–819 exercises 1–5, 20–25 and 35–40.
For gates and circuits, see the Essential reading for Week 2.

5.101 Introduction to Boolean algebra


History of Boolean Algebra
Between 384-322C Aristotle established the foundation of Logic in his Organon. Later in
1854, George Boole, an English Mathematician and Logician, published An Investigation
of the Laws of Thought on Which are Founded the Mathematical Theories of Logic and
Probabilities, which developed a system of Logical Algebra by which reasoning can be
expressed mathematically.
In 1904, Edward V. Huntington, an American Mathematician, published Sets Of Inde-
pendent Postulates For The Algebra Of Logic in which he defined 6 rules (or postulates)
of Boolean Algebra.
In 1938, Claude Shannon published his Master’s Thesis entitled A Symbolic Analysis of
Relay and Switching Circuits. In this thesis, Shannon proved that Boolean Algebra could
be used to simplify the arrangement of relays; essentially demonstrating that Boolean
Algebra could be used to simplify logic.

63
Week 9

Applications of Boolean Algebra


Boolean Algebra is the basic building block of computer circuit analysis.
System requirements can be converted into Boolean Algebra and implemented as a cir-
cuit. For example, if we have the requirement:
• When the system is activated, a fire sprinkler should spray water if high heat is
detected could be implemented as follows:
w = hAN Da
where h represents high heat detected, a represents system activated and w repre-
sents spraying water.

Two-valued Boolean Algebra


The most well-known and widely used for of Boolean Algebra. Variables are binary,
therefore they can only accept values of the set {0, 1}. The operators + and · correspond
to OR and AN D respectively.
This form of Boolean Algebra can be used to specify and design digital circuits.

Operations of Boolean Algebra


There are three fundamental operations in Boolean Algebra.
• AND
Also referred to as logical product, intersection or conjunction. Can be represented
as x · y, x ∩ y or x ∧ y.
Truth Table is as follows:
x y x·y
0 0 0
0 1 0
1 0 0
1 1 1
• OR
Also referred to as logical sum, union or disjunction. Can be represented as x + y,
x ∪ y or x ∨ y.
Truth Table is as follows:

64
Week 9

x y xy
0 0 0
0 1 1
1 0 1
1 1 1
• NOT
Also referred to as logical complement or negation. Can be represented as x′ , x̄ or
¬x.
Truth Table is as follows:
x x̄
0 1
1 0
When parentheses are not used, these three operators have the following order of prece-
dence: NOT > AND > OR. Note that this still respects the same order of precedence
defined in Precedence of logical operators.

5.103 Postulates of Boolean algebra


Huntington’s postulates
There 6 axioms defined by Huntington’s postulates. These 6 axioms must be satisfied by
any Boolean Algebra.
The axioms are:
• Closure
any result from logical operation must belong to the set {0, 1}.
• Identity
The logical sum identity x + 0 = x and the logical product identity x · 1 = x.
• Commutativity
Both logical sum and logical product are commutative, therefore x + y = y + x and
x · y = y · x.
• Distributivity
Both logical sum and logical product and distributive between each other, therefore
x · (y + z) = x · y + x · z and x + (y · z) = (x + y) · (x + z).
• Complement
Complements exist for all elements: x + x̄ = 1 and x · x̄ = 0.

65
Week 9

• Distinct Elements
This states that any Boolean Algebra has to have two distinct values, therefore
0 6= 1.

Basic theorems
Using the 6 axioms from previous sections, we can establish other useful theorems for
designing and analysing digital circuits.
Logical Sum Theorem Logical Product
x+x=x Idempotent Laws x·x=x
x+1=1 Tautology and Contradiction x·0=0
¯=x
x̄ Involution
(x + y) + z = x + (y + z) Associative Laws (x · y) · z = x · (y · z)
x + (x · y) = x Absorption Laws x · (x + y) = z
if y + x = 1 and y · x = 0, Uniqueness of Complement
then x = ȳ
0̄ = 1 and 1̄ = 0 Inversion Law

De Morgan’s Theorems
Theorem 1 (De Morgan’s Theorem 1). The complement of a logical product or variables
is equal to the logical sum of the complements of the variables. x · y = x̄ + ȳ.
Theorem 2 (De Morgan’s Theorem 2). The complement of a logical sum or variables is
equal to the logical product of the complements of the variables. x + y = x̄ · ȳ.

Principle of duality
Starting with a Boolean Relation, we can build another equivalent Boolean Relation by:
• Changing every + to ·
• Changing every · to +
• Changing every 0 to 1
• Changing every 1 to 0
For example A + B · C ≡ A · (B + C).

Ways of proving theorems


There are 4 ways to prove the equivalence of Boolean relations

66
Week 9

• Perfect Induction
Show that both relations have identical truth tables. This can be tedious as the
number of variables grow.
• Axiomatic Proof
Apply Huntington’s postulates or theorems to the expressions until identical ex-
pressions are found.
• Duality Principle
Every theorem remain valid after application of the Duality Principle.
• Contradiction
Assuming the hypothesis is false and then proving that the conclusion is also false.
1. Example: Absorption Rule
This rule can be proved easily with a truth table:
x y x + (x · y)
0 0 0
0 1 0
1 0 1
1 1 1
It can also be proved directly:

x + (x · y) ≡ (x · 1) + (x · y)
≡ x · (1 + y)
≡x·1
≡x

To prove the second part of the absorption law, we can use the duality principle,
therefore x + (x · y) = x = x · (x + y).

5.105 Boolean functions


Definition
Definition 22 (Boolean Function). A Boolean Function defines a mapping from one or
multiple Boolean input values to a Boolean output value.
For n input values, there are 2n possible combinations.
Given a function f with 3 input values, f can be completely defined with a table of 8
rows:

67
Week 9

x y z f (x, y, z)
0 0 0 1
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 0
1 0 1 0
1 1 0 0
1 1 1 1

Algebraic forms
There is a single way of representing a Boolean function in a truth table, however al-
gebraically a function can be represented in a variety of forms. For example f (x) =
x + x̄ · y = x + y.

Standardised forms of a function


Boolean functions are standardised to be represented either a sum-of-products or product-
of-sums.
The sum-of-products is a function of the form f (x, y, z) = xy + xz + yz, while a product-
of-sums is a function of the form f (x, y, z) = (x + y) · (x + z) · (y + z).
The sum-of-products form is, usually, easier to use and simplify.

Build a sum-of-products form


Building sum-of-products from a truth table is simple.
1. Look at values of the variables that make the function evaluate to 1.
2. If an input is 1, it appears uncomplemented in the expression
3. If an input is 0, it appears complemented in the expression
4. The function f is, then, represented as a sum-of-products of all the terms for which
the function is 1.
1. Example
Given the truth table below, represent the function as a sum-of-products.
x y f (x, y)
0 0 0
0 1 1
1 0 1
1 1 1

68
Week 9

Therefore, f (x, y) = x̄y + xȳ + xy.

Useful functions
The exclusive-or function x ⊕ y is true when either x or y is true, but not both. This
can be expressed as f (x, y) = x̄y + xȳ.
The implies function x → y is false when x is true and y is false, and true otherwise.
This can be expressed f (x, y) = x̄ + y.

69
Week 10

Learning Objectives
• Write Boolean expressions.
• Use the laws of Boolean algebra to simplify Boolean expressions.
• Represent a Boolean function.
• Simplify logic circuits/expressions.
• Convert truth tables into Boolean expressions and vice versa.
Essential Reading
• Rosen, K.H. Discrete mathematics and its applications. (New York: McGraw-Hill,
2012) 7th edition, pp.15–21.
• Exercises
p.22 exercises 23 and 24.

5.201 Logic gates


Definition of a gate
A Logic Gate is the basic element of circuits implementing a Boolean operation. The most
elementary of such gates are the OR gate, the AND gate and the NOT (or inverter)
gate.
All Boolean functions can be written in terms of these three logic gates.

AND Gate
The AND Gate produces a HIGH output (value 1) when all its inputs are HIGH ; oth-
erwise, the output LOW (value 0).
The AND Gate is represented as show in figure 1, below we show its truth table:

70
Week 10

x
y AND

Figure 1: A 2-input AND Gate

x OR
y

Figure 2: A 2-input OR Gate

x y x·y
0 0 0
0 1 0
1 0 0
1 1 1
Note that f = x · y can also be written as f = xy.

OR Gate
The OR Gate produces a HIGH output (value 1) when at least one of its inputs are
HIGH ; otherwise, the output LOW (value 0).
The OR Gate is represented as show in figure 2, below we show its truth table:
x y x+y
0 0 0
0 1 1
1 0 1
1 1 1

Inverter Gate
The Inverter Gate produces a HIGH output (value 1) when its input is LOW ; and
produces a LOW when its input is HIGH.
The Inverter Gate is represented as show in figure 3, below we show its truth table:
x x̄
0 1
1 0

71
Week 10

x NOT

Figure 3: An Inverter Gate

x
y XOR

Figure 4: A 2-input XOR Gate

XOR Gate
The XOR Gate produces a HIGH output (value 1) its inputs have different values and
a LOW otherwise.
The XOR Gate is represented as show in figure 4, below we show its truth table:
x y x⊕y
0 0 0
0 1 1
1 0 1
1 1 0

NAND Gate
Equivalent to “not AND”, so this is the inversion of the AND Gate. The NAND Gate is
represented as show in figure 5.

NOR Gate
Similarly, this is the inversion of the OR Gate. The NOR Gate is represented as show in
figure 6.

XNOR Gate
The inversion of the XOR Gate. The XOR Gate is represented as show in figure 7.

x
y NAND

Figure 5: A 2-input NAND Gate

72
Week 10

x
y NOR

Figure 6: A 2-input NOR Gate

x
y XNOR

Figure 7: A 2-input XNOR Gate

Multiple input gates


AND, OR, XOR and XNOR are all commutative and associative operations. All of
them can be extended to more than 2 inputs as shown in figure 8.
NAND and NOR are both commutative but not associative. Extending number of
inputs is less obvious. We must use parentheses correctly when cascading NAND and
NOR operations.

Representing De Morgan’s Laws


• Theorem 1
x · y ≡ x̄ + ȳ.
This says that figure 9 is equivalent to 10.
• * Theorem 2*
This says that figure 11 is equivalent to 12.

5.203 Combinational circuits


Definition of circuit
A Combinational Circuit is a combination of different logic gates designed to model a
Boolean function. In other words, a Combinational Circuit implements a particular
Boolean function.

x
y
z

Figure 8: A 3-input OR Gate

73
Week 10

x
y NAND

Figure 9: A 2-input NAND Gate

x
y OR

Figure 10: A 2-input OR Gate with negated inputs

Building a circuit from a function


Given a particular boolean function, we can implement a logic circuit representing all
states of the function.
Intuitively, we want to minimise the number of logic gates used in order to minimize
the cost of producing the circuit.
For example, let’s build a circuit for the function f defined as f (x, y, z) = x + ȳz. See
figure 13 for the result.

Writing Boolean expressions from a circuit


Given a logic network, we can write its Boolean expression as follows:
1. Label all gate outputs that are a function of input variables
2. Express the Boolean functions for each gate in the first level
3. Repeat until all outputs of the circuit are written as Boolean expressions
1. Example
Consider the circuit in 14. Figures 15, 16, and 17 show the steps necessary to
extract a Boolean expression from a circuit layout.

x
y NOR

Figure 11: A 2-input NOR Gate

74
Week 10

x
y OR

Figure 12: A 2-input AND Gate with negated inputs

x y z

f (x, y, z)

Figure 13: f (x, y, z) = x + ȳz

f (x, y, z)

Figure 14: Logic Circuit to extract Boolean expression

w z y x

Figure 15: Logic Circuit: Label Inputs

75
Week 10

w z y x

(x + y)

Figure 16: Logic Circuit: Express Boolean Expression of first level

w z y x

(x + y)

z(x + y)

z(x + y) + w

Figure 17: Logic Circuit: Repeat for other levels

76
Week 10

y x

sum

carry

Figure 18: 1-bit half-adder

Building a circuit to model a problem


Combinational circuits are useful for designing systems that solve a specific problem.
When we want to build a combinational circuit to solve a problem we follow these steps:
1. Label inputs and outputs using variables
2. Model the problem as Boolean expression
3. Replace each operation by equivalent logic gate

Building an adder circuit


We’re going to build a Half-adder circuit for two 1-bit inputs and a carry out signal.
The truth table is as follows:
x y sum carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
If we look closely, the colum sum contains the the truth table for an exclusive or gate
while the colum carry contains the truth table for an and gate. Therefore, our circuit is
shown in figure 18.
Note that a half-adder is not useful for multi-bit additions since it lacks a carry input
signal.

Building a full adder


To overcome the limitations of a half-adder, we can transform it into a full adder by
adding a carry input and including gates for processing the carry input.

77
Week 10

carry − iny x

sum

carry − out

Figure 19: 1-bit full-adder

The new truth table is as follows:


x y carry − in sum carry − out
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
We can see here that sum = x ⊕ y ⊕ carry − in and carry − out = xy + carry − in · (x ⊕ y).
The corresponding circuit is shown in figure 19.

5.205 Simplification of circuits


Benefits of Simplification
Every function can be written as a sum-of-products, however this may not be the optimal
solution in terms of number of gates and the depth of the circuit.

78
Week 10

This is why circuits need to be simplified.


Simplification – also referred to as minimisation or optimisation – is benefitial in circuit
design for the following reasons:
• Reduces the cost of circuits by reducing the number of gates used
• May reduce the computation time
• Allows more logic to fit into the same area

Algebraic simplification
A technique based on the application of Boolean algebra theorems to simplify the be-
havior of Boolean functions.
To produce a sum-of-product expression, we usually need to rely on at least one of the
following theorems:
• De Morgan’s laws and involution
• Distributive laws
• Commutative laws
• Idempotent laws
• Complement laws
• Absorption laws
1. Example
Simplify the following Boolean expression:

E = ((xy)z)((x̄ + z)(ȳ + z̄))

≡ ((xy) + z̄)((x̄ + z)(ȳ + z̄))


≡ (xy + z̄)((x̄ + z) + (ȳ + z̄))
¯z̄ + ȳ¯z̄¯)
≡ (xy + z̄)(x̄
≡ (xy + z̄)(xz̄ + yz)
≡ xyxz̄ + xyyz + z̄xz̄ + z̄yz
≡ xyz̄ + xyz + xz̄
≡ xy + xz̄

79
Week 10

Karnaugh maps
A Karnaugh Map (or K-map) is a graphical representation of Boolean functions and is
different from a truth table. Adjacent cells in a K-map only change one variable.
ȳ y
x̄ 0 0
x 1 1
1. Example
Consider the Boolean function represented by the truth table below:
x y z f
0 0 0 0
0 0 1 0
0 1 0 0
0 1 1 1
1 0 0 1
1 0 1 1
1 1 0 1
1 1 1 1
Since we have three variables, we need a K-map of three inputs:
ȳz̄ ȳz yz yz̄
x̄ 0 0 1 0
x 1 1 1 1
In this case, the expression is x + yz.

80
Week 11

Learning Objectives
• State the principle of mathematical induction.
• Discuss the ideas of the base step and inductive step in a proof by mathematical
induction.
• Apply the ideas of mathematical induction to recursion and recursively defined
structures.
Essential Reading
• Rosen, K.H. Discrete mathematics and its applications. (New York: McGraw-Hill,
2012) 7th edition, pp.307–325 and pp.328–336.
• Exercises
pp.325–326 exercises 1, 2, 6, 7, 15 and 16
p.338 exercises 19–21.
For recursion, see the Essential reading for Week 2

6.101 Introduction to proofs


We start with some definitions and terminology and how to formalize a theorem. Then
we continue with three types of proofs: direct proof, proof by contraposition, and proof
by contradiction.
A proof is, simply put, a valid argument used to prove the truth of a mathematical
statement. In order to build a proof, we must rely on all the knowledge introduced
previously:
• Variables
• Predicates
• Quantifiers
• Laws of Logic
• Rules of inference

81
Week 11

Terminology
Theorem A formal statement that can be shown to be true
Axiom A statement assumed to be true to serve as a premise to further arguments
Lemma A proven statement used as a step to a larger result rather than as a statement
of interest by itself
Corollary A theorem that can be established by a short proof from a theorem

Formalising a theorem
The statement S There exists a real number between any two non-equal real numbers can
be formalized as:
Theorem 3. ∀x, y ∈ Rx < y → ∃z ∈ R | x < z < y

Direct proof
A Direct Proof is simply a demonstration that a conditional statement p → q is true.
We always with the assumption that p is true, then we employ axioms, definitions,
and theorems, together with rules of inference, to show that q must also be true.
For example, let’s prove our theorem defined in section Formalising a theorem.

Proof. Let x and y be arbitrary elements in R. Let’s assume x < y.


x+y
Let z = 2 . z ∈ R, satisfying x < z < y.
Using the Universal Generalization rule of inference, we can conclude:
∴ ∀x, y ∈ Rx < y → ∃z ∈ R | x < z < y

Proof by contrapositive
A Proof by Contrapositive is a proof technique that relies on the fact that proving p → q
is equivalent to proving ¬q → ¬p.
We start the proof by assuming ¬q is true, then use axioms, definitions, and theorems,
together with rules of inference, to show that ¬p must also be true.
For example, let’s prove the theorem If n2 is even, then n is even.

Proof. Let’s assume n is odd. Then ∃k ∈ Z | n = 2k + 1. Then ∃k ∈ Z | n2 = (2k + 1)2 =


2(2k 2 + 2k) + 1. Then, n2 is also odd. Therefore, we conclude that if n is odd, then n2
is also odd.

82
Week 11

Proof by contradiction
A Proof by Contradiction is a form of proof which relies on assuming the premise to be
false and showing that it leads to a contradiction.
We start the proof by assuming ¬p to be true\ then use axioms, definitions, and
theorems, together with rules of inference, to show that ¬p is false. We can conclude,
therefore, that assuming ¬p was wrong, so it must be true.
For example, let’s prove the theorem There are infinitely many prime numbers.

Proof. Let’s suppose there are finitely many prime numbers and list them as p1 , p2 , p3 , . . . , pn .
Let’s consider the number c = p1 · p2 · p3 · . . . · pn + 1, the product of all primes + 1.
As c is a natural number, it has at least one prime divisor. Then, ∃k ∈ {1, . . . , n} | pk /c.
Then, ∃k ∈ {1, . . . , n}∃d ∈ N | d · pk = c = p1 · p2 · p3 · . . . · pn + 1.
1
Then, ∃k ∈ {1, . . . , n}∃d ∈ N | d = p1 · p2 · p3 · . . . · pk−1 + pk+1 + . . . + pn + pk .

6.103 The principle of mathematical induction


Mathematical Induction can be used to assert that a propositional function P (n) is true
for all positive integers n. In other words, given a propositional function P (n), we can
use mathematical induction to show that P (n) holds for all n.
It can formalised using the following rule of inference:
P (1)is true
∀k(P (k) → P (k + 1))
∴ ∀nP (n)

The intuition behind induction


Let P (n) be the propositional function verifying:
• P (1) is true
• ∀k(P (k) → P (k + 1))
Intuitively, we can say that P is true for 1. Since P is true for 1, then it is true for 2.
Since it is true for 2, then it is true for 3, and so on. Since P is true for n − 1, it’s true
for n.
What this means is that the Base Case P (1) shows that the property holds true initially.
The Inductive Step ∀k(P (k) → P (k + 1)) shows tha the property holds for all k by
showing how each iteration influences the next.

83
Week 11

Structure of induction
In order to complete a proof by induction for a propositional function P (n), we need to
verify two steps:
Base Case Prove that P (1) is true
Inductive Step Prove that ∀k ∈ NP (k) → P (k + 1)1

Some uses of induction


Mathematical induction can be used to proce that P (n) is true for all integers greater
than a particular threshold, where P (n) is a propositional function. This might cover
multiple cases:
• Proving formulas
• Proving inequalities
• Proving divisibility
• Proving properties of subsets and their cardinality

6.106 Proof by induction


Mathematical Induction is a proof technique which allows us to prove that a property
holds for all natural numbers.

Proving formulas
n(n+1)
Let’s prove P (n) : 1 + 2 + 3 + . . . + n = 2 .

Proof. We start with the base case:

1(1 + 1)
1=
2
1(2)
1=
2
2
1=
2
1=1

Then we move on to the inductive step:

1
P (k) is referred to as the inductive hypothesis

84
Week 11

k(k + 1)
1 + 2 + 3 + ... + k =
2
(k + 1)(k + 2)
1 + 2 + 3 + . . . + k + (k + 1) =
2
k(k + 1) (k + 1)(k + 2)
+ (k + 1) =
2 2
k(k + 1) + 2(k + 1) (k + 1)(k + 2)
=
2 2
(k + 1)(k + 2) (k + 1)(k + 2)
=
2 2
We have shown that the property holds for the base case and for the inductive step,
therefore the proof is complete.

Proving inequalities
Let’s prove P (n) : 3n < n! if n ≥ 7.

Proof. We start with the base case:

37 < 7!
2187 < 5040

Then we move on to the inductive step.

3k < k!
3k+1 < (k + 1)!
3 · 3k < (k + 1) · k!

We have shown that the property holds for the base case and for the inductive step,
therefore the proof is complete.

Proving divisility
Let’s prove P (n) : ∀n ∈ N5|6n + 4.

Proof. We start with the base case:

5|60 + 4
5|1 + 4
|
55

85
Week 11

Then we move on to the inductive step.

5|6k + 4

Let 6k + 4 = 5p, then 5p − 4 = 6k.

5|6k+1 + 4
5|6 · 6k + 4
5|6(5p − 4) + 4
5|30p − 24 + 4
5|30p − 20
5|5(6p − 4)

We have shown that the property holds for the base case and for the inductive step,
therefore the proof is complete.

6.108 Strong induction


Strong Induction is a form of mathematical induction which makes the inductive step
easier to prove by using a stronger hypothesis. We assume that the property holds for
all k less than k + 1.
In other words, we employ the conditional statemente P (1), P (2), . . . , P (k) → P (k + 1)l

Strong induction
It can formalised using the following rule of inference:
P (1)is true
∀k(P (1), P (2), . . . , P (k) → P (k + 1))
∴ ∀nP (n)
It’s sometimes called Complete Induction.

Example
Let’s prove P (n) : ∀n ∈ N ∧ n ≥ 2, n is divisible by a prime number.

Proof. We start with the base case, which reduces to 2. 2 is a prime number and divides
itself.

86
Week 11

Then we move on to the inductive step. Let k ∈ N, greater than 2. If the inductive
hypothesis P (k) is true, let’s assume P (2), . . . , P (k + 1) is true. Then, ∀m ∈ N and
2 ≤ m ≤ k + 1, ∃p a prime number dividing m.
Here we have two cases:
k + 2 is a prime number then k + 2 is trivially divisible by itself
k + 2 is a composite number then ∃m dividing k + 2. Because 2 ≤ m ≤ k + 1, then ∃p
dividing m, which also divides k + 2.
We have shown that the property holds for the base case and for the inductive step,
therefore the proof is complete.

Well-ordering property
It is an axiom about N that we assume to be true. The axioms about N are as follows:
1. The number 1 is a positive integer
2. If n ∈ N, then n + 1 is also a positive integer
3. Every positive integer other than 1, is the successor of a positive integer
4. The Well-ordering property: every non-empty subset of the set of positive integers
has a least element
The well-ordering property can be used as a tool in building proofs.

Example
Let’s reconsider our previous proof.

Proof. Let S be the set of positive integers greater than 1 without a prime divisor.
Suppose S is non-empty. Let n be its smallest element. n cannot be prime since n divides
itself if n is prime; i.e. n would be its own prime divisor.
Therefore, n must be composite, which means it must have a divisor d such that 1 < d < n
Then d must have a prime divisor.
Let p be the prime divisor of d. We know that p/d and d/n, therefore p/n, which
contradicts our statement that S is the set of positive integers greater than 1 without a
prime divisor.
Therefore, S must be an empty set, which verifies P (n).

87
Week 11

Equivalence of the three concepts


• mathematical induction → well-ordering property
• well-ordering property → strong induction
• strong induction → mathematical induction
All three concepts are equivalent.

88
Week 12

Learning Objectives
• Describe the concept of recursion and give examples of its application.
• Identify the base case and the general case of a recursively defined problem.
Essential Reading
• Rosen, K.H. Discrete mathematics and its applications. (New York: McGraw-Hill,
2012) 7th edition, pp.339–351.
• Exercises
p.351 exercises 1–9 and 15–17.

6.201 Recursive definitions


Definition
When we define a mathematical object in terms of itself, this is called Recursion.

Recursively defined functions


A recursively defined function f with domain N is defined by:
Basis Step initial value of the function
Recursive Step a rule for finding the value of the function at an integer from its previous
values.
For example the Fibonacci function can be defined as:


f (0) 1

f (1) 1

f (n) f (n − 1) + f (n − 2)

89
Week 12

Recursively defined sets


A recursively defined set S, is defined by:
Basis Step initial elements of the set
Recursive Step a rule for generating new elements from the ones we already have
For example, the set S is recursively defined by:
Basis Step 4 ∈ S
Recursive Step x ∈ S ∧ y ∈ S → x + y ∈ S

Recursive algorithms
An algorithm is a finite sequence of precise instructions for performing a computation or
for solving a problem.
A recursive algorithm is an algorithm which solves a problem by reducing it to a smaller
instance of the same problem with smaller input.
For example, here’s a recursive algorithm for computing n!:

Algorithm 1 Computing n!
1: function Factorial(n)
2: if n = 0 then
3: return 1
4: return n× Factorial(n − 1)

6.204 Recurrence relations


Definitions
A Recurrence Relation is an equation that defines a sequence based on a rule that pro-
duces the next term as a function of the previous.
An infinite sequence is a function from the set of integers to the set of real numbers.
In many cases, it’s useful to formalise a problem as a sequence before solving it.

Linear recurrences
A relation in which each term of the sequence is a linear function of earlier terms.
There are two types of linear recurrences:

90
Week 12

Linear Homogenous Recurrences an = c1 an−1 + c2 an−2 + . . . + ck an−k . c1 , . . . , ck ∈ R.


k is the degree of the relation.
Linear Non-homogenous Recurrences an = c1 an−1 + c2 an−2 + . . . + ck an−k + f (n).
c1 , . . . , ck ∈ R. k is the degree of the relation.

Arithmetic sequences
A sequence is called arithmetic if the difference between consecutive terms is a constant
c.

Geometric sequences
A sequence is called geometric if the ratio between consecutive terms is a constant r.

Divide and conquer recurrence


A divide and conquer algorithm consists of three steps:
• Dividing the problem into smaller subproblems
• Solving each subproblem recursively
• Combining all solutions to find a final solution to the original problem

6.206 Solving recurrence relations


Solving linear recurrence
Let:
an = c1 an−1 + c2 an−2 + . . . + ck an−k
be a linear homogenous recurrence. If a combination of the geometric sequence:
an = r n
is a solution to this recurrence, it satisfies:
rn = c1 rn−1 + c2 rn−2 + . . . + ck rn − k
By dividing both sides by rn−k we get:
rk = c1 rk−1 + c2 rk−2 + . . . + ck
This equation is called the characteristic equation. Solving this equation is the first
step towards finding a solution to the linear homogenous recurrence.
If r is a solution of the equation with multiplicity p, then the combination:

91
Week 12

(α + βn + γn2 + . . . + µnp−1 )rn


satisfies the recurrece.

Induction for solving recurrence


Sometimes it’s easier to solve a recurrence relation using strong induction.

92
Week 13

Learning Objectives
• Define a graph, edges, vertices, parallel edges, loops, cycles and walk, path and
connected graphs.
• Describe the degree sequence of a graph and the relation that links the sum of the
degree sequence.
• Describe special graphs: simple graphs, complete graphs and r-regular graphs.
Essential Reading
• Rosen, K.H. Discrete mathematics and its applications. (New York: McGraw-Hill,
2012) 7th edition, pp.617–625, pp.627–631, pp.637–640 and pp.666–676.
• Exercises
pp.625–626 exercises 1–3, 18, 19 and 20
pp.641–642 exercises 1–10 and 28–32
pp.676–677 exercises 1–4 and 12–23.

7.101 Introduction
We start studying Graphs. Graphs are discrete structures consisting of vertices and edges
connecting them.
Graph Theory is a branch of discrete mathematics which studies these structures.

Applications of Graphs
• Modeling computer networks
• Modeling road maps
• Solving shortest-path problems between cities
• Assigning jobs to employees
• Distinguishing chemical compound structures

93
Week 13

• Modeling molecules

7.103 Definition of a graph


Graph
A graph G is an ordered triple G = {V, E}, where V is the set of vertices and E is the
set of edges.

Vertex
The basic element of a graph, drawn as a node or a dot. The set of vertices of G is
usually denoted by V (G) or simply V . Figure 20 denotes a graph with 3 vertices.

e1
v1 v2

e2

v3

Figure 20: A sample graph with 3 vertices

In the graph shown in figure 20, V (G) = {v1, v2, v3}.

Edge
A link between two vertices. It’s drawn as line connecting exactly two vertices. The set
of edges in a graph G is denoted by E(G) or simply E.
In the graph shown in figure 20, E(G) = {e1, e2} = {{v1, v2}, {v2, v3}}.

Adjacency
• Two vertices are adjacent if they are endpoints on the same edge
• Two edges are adjacent if they share the same vertex
• If vertex v is and endpoint of edge e, then we say that v and e are incident

94
Week 13

Loops and parallel edges


Let’s consider the following graph:

v6

e4

e5
v4 v5

e7

e3 e6 e8 v1 e9

e1

v3 v2
e2

Figure 21: Loops and Parallel Edges

The vertices v2 and v5 are linked with two edges (e6 and e8), those edges are referred to
as parallel edges.
The vertex v1 is linked to itself by edge e9, that edge is called a loop.

Directed Graph - Digraph


A direct graph is a graph in which the edges have a direction, indicated with an arrow
on the edge. In the graph shown in figure 22, we can see that e1 is a connection from v1
to v2 but it is not a connection from v2 to v1.

95
Week 13

v6

e4

e5
v4 v5

e7

e3 e6 e8 v1 e9

e1

v3 v2
e2

Figure 22: A directed graph

7.105 Walks and paths in a graph


Definition of a walk
A walk is a sequence of vertices and edges of a graph where vertices and edges can be
repeated.
A walk of length k is a succession of k (not necessarily different) edges of the form:
uv, vw, wx, . . . , yz
Taking the graph in figure 20 as an example, we can define a walk of length 4 from v1
to v6:
v1v2, v2v3, v3v4, v4v6 = e1, e2, e3, e4 = v1v2v3v4v6

Definition of a trail
A trail is a walk in which no edge is ever repeated. Vertices can be repeated, but no
edges can be repeated.

Definition of a circuit
A circuit is a closed trail, meaning the starting and ending vertices are the same. Only
vertices can be repeated.

96
Week 13

Definition of a path
A path is a trail in which neither vertices nor edges are repeated.

Definition of a cycle
A cycle is a closed path in which a vertex is reachable from itself.

Eulerian path
An Eulerian path is a path that uses each edge precisely once. If such a path exists, the
graph is called traversable.

Hammiltonian path
A Hammiltonian path (or traceable path) is a path that visits each vertex precisely once.
If such a path exists, the graph is called a traceable graph.

Hammiltonian cycle
A cycle that uses each vertex exactly once (except for the starting vertex, which is visited
exactly twice) is called a Hammiltonian cycle. If such a cycle exists, the graph is called
a Hammiltonian graph.

Connectivity
An undirected graph is connected if you can get from any node to any other node by
following a sequence of edges. This means that any two random nodes in a graph are
connected by a path.
The graph depicted in figure 23 is a connected graph while the graph depicted in figure
24 is not a connected graph.

97
Week 13

v4 v5

v1

v3 v2

Figure 23: A Connected Graph

v4 v5

v1

v3 v2

Figure 24: Not A Connected Graph

Strong Connectivity
A directed graph is a strongly connected graph if there is a directed path from any node
to any other node. Figure 25 shows a depiction of such a graph. Conversely, the graph
depicted by figure 26 is not strongly connected.

98
Week 13

v3

v1

v4 v2

Figure 25: A Strongly Connected Graph

v3

v1

v4 v2

Figure 26: Not A Strongly Connected Graph

Transitive Closure
Given a digraph G, the Transitive Closure of G is the digraph G∗ such that:
• G∗ has the same vertices as G
• If G has a directed path from u to v (u 6= v), G∗ has a directed edge from u to v.
Figure 27 shows a depiction of a transitive closure of G.

99
Week 13

y u v y u v

x z x z

Figure 27: Transitive Closure

7.107 The degree sequence of a graph


Terminology - Undirected Graphs
Degree (deg(v)) the number of edges incident on v
• A loop contributes twice to the degree
• An isolated vertex has degree 0
In figure 28, we show a graph with the degree for every node written inside the node.

1 2
v4 v2

0 4
v6 v1

v4 v3
3 4

Figure 28: A graph with its vertices’ degrees

Terminology - Directed Graphs


In-degree (in − deg(v)) Number of edges going into v

100
Week 13

Out-degree (out − deg(v)) Number of edges going out of v


Degree (deg(v)) out − deg(v) + in − deg(v)
In figure 29 we show a graph with all in and out degrees for every vertex.

1 2
v5 v2

0 2
v6 v1

v4 v3
3 4

Figure 29: A digraph with its vertices’ degrees

Degree sequence of a graph


Given an undirected graph G, a degree sequence is a monotonic non-increasing sequence
of the vertex degrees of all the vertices of G.
The degree sequence of the graph from figure 30 is 4,3,2,1.

1 2
v4 v2

4
v1

v4 v3
2 3

Figure 30: A graph with its degree sequence

101
Week 13

Degree sequence property I


• The sum of the degree sequence of a graph is always even

Degree sequence property II


• The sum of the degree sequence of a graph is always twice the number of edges

7.109 Special graphs: simple, r-regular and complete graphs


Simple Graphs
A graph which contains no loops and no parallel edges, like the one in figure 31.

v4 v2

v1

v4 v3

Figure 31: Simple graph

Properties of simple graphs


• Given a simple graph G with n vertices, the degree of each vertex of G is at most
n−1

Regular graphs
A graph is said to be regular if all local degrees are the same number.
A graph G where all vertices have the same degree r is called an r-regular graph.

102
Week 13

v2 v1

v3 v4

Figure 32: 3-regular graph

Properties of regular graphs


Given an r-regular graph G with n vertices, the following is true:
• Degree sequence of G is r, r, r, . . . (repeated n times)
• Sum of degree sequence is r · n
r·n
• Number of edges in G is 2

Complete graph
A simple graph where every pair of vertices is adjacent. Complete graphs with n vertices
are represented by the symbol Kn .
Figure 33 shows an example of a complete graph with 8 vertices.

103
Week 13

8 2

7 3

6 4

Figure 33: Complete graph

Complete graph properties


A complete graph with n vertices, Kn has the following properties:
• Every vertex has degree n − 1
• Sum of degree sequences is n(n − 1)
n(n−1)
• Number of edges is 2

104
Week 14

Learning Objectives
• Define the adjacency matrix of a graph.
Essential Reading
• Rosen, K.H. Discrete mathematics and its applications. (New York: McGraw-Hill,
2012) 7th edition, pp.632–636, pp.643–650, pp.652–663 and pp.681–688.
• Exercises
pp.641–642 exercises 17–23
pp.650–652 exercises 1–4, 6–18, 22–24 and 40–44
pp.663–664 exercises 1–3, 7, 16 and 17
pp.688–689 exercises 2–5, 13 and 14.

7.201 Isomorphic graphs


Definition of isomorphism
Two graphs G1 and G2 are isomorphic if there is a bijection (an invertible function)
f : G1 → G2 that preserves adjacency and non-adjacency.
This means that if uv is an edge in G1 , then f (u)f (v) is an edge in G2 . In other words,
u and v are adjacent in G1 if and only if f (u) and f (v) are adjacent in G2 .

Properties of isomorphic graphs


• Two graphs with different degree sequences cannot be isomorphic
• Two graphs with the same degree sequence aren’t necessarily isomorphic

7.203 Bipartite graphs


A graph G(V, E) is called bipartite if the set of vertices V can be partitioned in two
disjoint sets V1 and V2 such that edge e in G has one endpoint in V1 and one endpoint
in V 2.

105
Week 14

Figure 34 depicts a bipartite graph:

1 2 3 4 5

a b c d e

Figure 34: Bipartite Graph

Bipartite graphs are 2-colourable, meaning 2 colours are enough to color the graphs in a
way that adjacent nodes do not have the same colour.
There are no odd-length cycles in bipartite graphs.

Matching
A Matching is a set of pairwise non-adjacent edges, none of which are loops. Meaning
no two edges share the same endpoint.
A vertex is matched (or saturated) if it is an endpoint of one of the edges in the matching.
Otherwise, the vertex is unmatched.

Maximum matching
A matching of maximum size such that if any edge is added, it is no longer a matching.
In a single bipartite graph, there may be many possible maximal matchings.

The Hopcroft-Karp Algorithm 1


The Hopcroft-Karp Algorithm is an algorithm for finding the maximum matching in a
bipartite graph.
Augmenting paths a path that starts on a free node, ends on a free node and alternates
between unmatched and matched edges within the path
Breadth First Search traversing the graph level by level
Depth First Search traversing the graph all the way to the leaf before starting another
path
A simplified pseudocode for the algorithm is as follows:

106
Week 14

1. M ← ∅
2. While there is an augmenting path P
a) Use BFS to build layers that terminate at free vertices
b) Start at free vertices in C, use DFS
3. Return M

7.205 The adjacency matrix of a graph


• Adjacency list
• Adjacency matrix
• Properties of adjacency matrix

Graph representation recap


Graphs can be represented as a set of vertices and a set of edges.

Adjacency list
A list of all the vertices of G and their corresponding individual adjacent vertices. Table
0.1 shows the adjancency list for the graph in figure 35.

Table 0.1: Adjancency list


Vertex Adjacent Vertices
A B, C
B A, C, D
C A, B, D, E
D B, C, E
E C, D

107
Week 14

e2
A C
e7

e1 e5 E
e3

e6

B e4 D

Figure 35: Sample Graph For Adjacency List

Note that we can draw a graph from its adjacency list alone.

Example
Given the adjacency list in table 0.2, let’s draw the graph:

Table 0.2: Adjancency list


Vertex Adjacent Vertices
v1 v 2 , v 3 , v4
v2 v1
v3 v 1 , v 4 , v5
v4 v 1 , v 3 , v5
v5 v 3 , v 4 , v5

We know, from table 0.2 that the graph has 5 vertices. So we can start our drawing with
only 5 vertices drawn, without any edges. That’s shown below:

v3

v4 v1 v2

v5

108
Week 14

Now we can start adding edges. First covering v1 ’s adjacent vertices:

v3

v4 v1 v2

v5

Next we go for v2 , but that’s already covered. So we move on to v3 :

v3

v4 v1 v2

v5

Next, we tackle for v4 :

v3

v4 v1 v2

v5

Lastly, we look at v5 :

109
Week 14

v3

v4 v1 v2

v5

Now that all vertices are done, the final graph is:

v3

v4 v1 v2

v5

Adjacency matrix
A graph can be represented by its adjacency matrix. Given the graph is figure 36, we
can produce its adjacency matrix as shown below:

 
2 1 1
M (G) = 1 2 2
1 2 0

The format of the matrix is as follows:

 
v1 v1 v1 v2 v1 v3
M (G) = v2 v1 v2 v2 v2 v3 
v3 v1 v3 v2 v3 v3

Note that in the leading diagonal, we have the loops which are counted twice. One
interesting observation is that sum of all the edges in the undirected graph, is equal to

110
Week 14

half the sum of all the elements in its adjacency matrix. The sum of the degree sequence
is equal to the sum of the adjacency matrix.

v3

v1 v2

Figure 36: A graph for producing adjacency matrix

The adjacency matrix can also be produced for a directed graph, but we need to in mind
that v1 being adjacent to v2 does not imply v2 being adjacent to v1 .

7.207 Dijkstra’s algorithm


Weighted graphs
A weighted graph is a graph in which each edge is assigned a weight. Like shown in
figure 37.

v3
2
3
1
1
v1 v2

Figure 37: Weighted Graph

It can be used to model the distance between cities, response time in a network or the
cost of a transaction, among other things.

Dijstra’s algorithm
In 1956, Edsger Dijkstra designed an algorithm for finding the shortest path between any
two nodes in a weighted graph. This algorithm is now know as Dijkstra’s Algorithm.

111
Week 15

Learning Objectives
• Define a tree.
• Define spanning trees.
• Define non-isomorphic spanning trees.
Essential Reading
• Rosen, K.H. Discrete mathematics and its applications. (New York: McGraw-Hill,
2012) 7th edition, pp.715–717, pp.753–762 and pp.764–769.
• Exercises
p.725 exercises 1 and 11
p.763 exercises 1–3, 5 and 6
p.769 exercises 1–5.

8.103 Definition of a tree


Acyclic graph
A graph G is acyclic if and only if it has no cycles.

Definition of a tree
A tree is a connected acyclic undirected graph. Figure 38 depicts a sample tree. A tree
cannot have loops or parallel edges.

112
Week 15

root

left right

child child

Figure 38: A sample tree

Definition of a forest
A forest is a cycle-free disconnected graph.

Theorem 1
An undirected graph is a Tree if and only if there is a unique simple path between any
two of its vertices.
Well, if there are more than one path, we have a cycle.

Theorem 2
A tree with n vertices has n − 1 edges.

Rooted trees
A Rooted Tree is a tree in which one vertex has been designated as the root. Every edge
is directed away from the root.

8.105 Spanning trees of a graph


A spanning tree of a graph G, is a connected subgraph of G that contains all vertices of
G, without any cycles.
Figure 39 shows a complete graph with 4 vertices:

113
Week 15

4 2

Figure 39: Complete graph with 4 vertices

There are four possible spanning trees in this graph.

Constructing a spanning tree


To get a spanning tree of graph G
1. Keep all vertices of G
2. Break all the cycles but keep the tree connected
Figures 40, 41, 42 show the process in a visual form. Note that figure 42 shows one out
of 16 possible spanning trees for the graph shown in figure 40.

114
Week 15

v1 v2

v4 v3

Figure 40: Starting Graph G

v1 v2

v4 v3

Figure 41: Keep all the vertices

v1 v2

v4 v3

Figure 42: Break all cycles but keep the tree connected

Non iso-morphic spanning trees


Two spanning trees are said to be iso-morphic if there is a bijection preserving adjacency
between the two trees.

115
Week 15

8.107 Minimum spanning tree


Spanning tree cost
Suppose we have a connected undirected graph with a weight (or cost) associated with
each edge. The cost of a spanning tree would be the sum of the cost of its edges.
The cost of the spanning tree marked in red is 8 + 3 + 2 + 1 = 14.

2
A C

5 2 E
3

B D
1

Figure 43: Sample Graph With Weights

Minimum-cost spanning tree


A spanning tree with the lowest cost.

Finding spanning trees


There are two basic algorithms for finding minimum-cost spanning trees.
• Kruskal’s Algorithm
• Prim’s Algorithm
Both are greedy algorithms.

116
Week 16

Learning Objectives
• Define minimum spanning trees.
• Define rooted trees and binary trees, and find the height of binary trees.
Essential Reading
• Rosen, K.H. Discrete mathematics and its applications. (New York: McGraw-Hill,
2012) 7th edition, pp.717–725 and pp.726–729.
• Exercises
p.725–726 exercises 2–8, 12, 13, 24 and 26
p.738 exercises 1–4.

8.201 Rooted trees


Definition of a rooted tree
A Rooted Tree is a tree in which a vertex r has been designated the root of the tree. For
every other vertex v there is a directed path to r.
The edges of a rooted tree are either away from the root (arborescence or out-tree) or
towards the root (anti-arborescence or in-tree).
Figure 44 shows the depiction of a rooted tree:

117
Week 16

a b

c d e f g h

i j

Figure 44: Rooted Tree

Theorem
A directed tree is a rooted tree if and only if one vertex has in-degree 0 and all the other
vertices have in-degree 1.

Terminology of rooted trees


Using figure 44 as an example, we have:
• r is the root of the tree
• a is the parent of vertices c, d, e
• f, g, h are the children of b
• r and b are ancestors of i and j
• i and j are sibblings
• h and b are internal nodes
• c, d, e, f, g, i, j are external nodes

Depth and height in a tree


The depth (or path length) of a node in a tree is the number of edges between that node
and the root. With regards to figure 44, we can say:
• depth of r is 0
• depth of a and b is 1
• depth of c, d, e, f, g, h is 2
• depth of i and j is 3

118
Week 16

The height of a node in a tree is the longest from that node to a leaf.
• height of r is 3
• height of b is 2
• height of a and h is 1
• height of c, d, e, f, g, i, j is 0
The depth or height of a tree is the maximum path length across all its nodes. The
height of the graph in figure 44 is 3.

Special trees
Binary Tree A tree in which every vertex has 2 or fewer children
Ternary Tree A tree in which every vertex has 3 or fewer children
m-ary Tree A tree in which every vertex has m or fewer children

Regular rooted trees


An m-ary tree is regular if every one of its internal nodes has exactly m children.

Properties
• An m-ary tree has at most mh vertices at level h

Isomorphic trees
Two trees T1 and T2 are isomorphic if there is a bijection:
f : V (T1 ) → V (T2 )
which preserves adjacency and non-adjacency. This means that if uv is in E(T1 ) then
f (u)f (v) is in E(T2 ).
Notation T1 ∼
= T2 means T1 and T2 are isomorphic.

Properties
• Two trees with different degree sequences are not isomorphic
• Two trees with the same degree sequence are not necessarily isomorphic

119
Week 16

Isomorphic rooted trees


Two isomorphic trees are isomorphic as rooted trees if and only if there is a bijection
that maps the root of one tree to the root of another tree.

Properties
Two trees which are isomorphic may or may not be isomorphic as rooted trees.

8.203 binary search trees


Definition
a Binary Search Tree (BST) is a rooted binary tree whose internal nodes stores keys and,
optionally, an associated value. The tree also satisfies the Binary Search property which
requires that the key in each node must be greater than or equal to the keys in the nodes
on the left subtree and less than or equal to the keys in the nodes on the right subtree.

Example
The tree depicted by figure 45 is a Binary Search Tree.

4 12

2 6 10 14

1 5 7 9 11 13 15

Figure 45: Binary Search Tree

Applications
BST are good data stores for modifiable data. It allows very fast insertion, deletion and
searching.

120
Week 16

Height of the tree


There are two methods to find the height of a tree with n elements.
The first method employs a log2 inequality:

2h−1 < n + 1 ≤ 2h
h − 1 < log2 (n + 1) ≤ h

While the second method relies on the ceiling function:

h = ⌈log2 (n + 1)⌉

It should be clear that both of these will give the same result and are equivalent.

Binary search algorithm


Start by comparing the midpoint. The list is then split into two sub-lists of approximately
the same size.
The search is restricted to the appropriate sub-list based on the comparison of the mid-
point.
This process continues until the element we’re looking for is found or the list has be
completely consumed.

121
Week 17

Learning Objectives
• Define a relation.
• Define a relation digraph.
• Describe the properties of a relation.
Essential Reading
• Rosen, K.H. Discrete mathematics and its applications. (New York: McGraw-Hill,
2012) 7th edition, pp.553–561
• Exercises
p.561 exercises 1–12
p.562 exercises 20-22

9.101 Introduction
A binary relation over two sets A and B is a subset of the Cartesian product A × B. We
say that the element a of A is related to the element b of B, if and only if the ordered
pair (a, b) is belongs to the set.
This same idea can be extended to more than two sets by considering the cartesian
product with rank k. Instead of an ordered pair, we would have k-tuples. The relation
in this case is referred to as finitary relation or n-ary relation.
In mathematics we study relationships such as:
• Relation between a positive integer and one it divides
• Relation between a real number and one larger than it
• Relation between a real number x and the value f (x), where f is a function

122
Week 17

9.103 Definition of a relation: relation versus function


What is a relation?
A relation can be defined between elements of a set B and elements of another set B. It
can also be defined between elements of the same set.
We always refer to a relation by the letter R.
More formally, let A and B be two sets. Let R be a relation linking elements of the set
A to elements of the set B. Let x ∈ A and y ∈ B. We say that x is related to y with
respect to the relation R and write x R y.
A relation is a link between two elements of a set. For example person x is a SON OF
a person y. Where SON OF is a relation that links x to y.
When x is the son of y, we write x R y. When x is not the son of y, we write xRx.

Cartesian product
If we have two sets A and B, as depicted below:

A B

3 6

2 4

1 2

Figure 46: Sets A and B

The Cartesian Product A × B is defined by a set of ordered pairs (a, b) where a ∈ A and
b ∈ B.

123
Week 17

A × B = {(a, b) | a ∈ A ∧ b ∈ B}
For example, from our sets A and B shown in figure 46, we have:
A × B = {(1, 2), (1, 4), (1, 6), (2, 2), (2, 4), (2, 6), (3, 2), (3, 4), (3, 6)}

Definition of relation
A binary relation over two sets A and B is a subset of the Cartesian product A × B. In
other words, R⊆ A × B. This means that R is the set of ordered pairs (a, b) where a ∈ A
and b ∈ B.
(a, b) ∈R means a R b.

Relations on a set
When A = B, we have a relation from A to A, or R⊆ A × A.

Example
Let A = {1, 2, 3, 4}. Let R be a relation on A.
x, y ∈ A, x R y if and only if x < y. Therefore: 1 R 2, 1 R 3, 1 R 4, 2 R 3, 2 R 4, 3 R 4.
We can see that R= {(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)}.

9.105 Matrix and graph representations of a relation


Relations using matrices
Given a relation R from A to B we should list the elements of A and B. Ordering doesn’t
matter, however, it’s conventional to list elements in ascending order.
Let na = |A| and nb = |B|, we can produce a matrix Mr of dimensions na × nb such that:

(
1 if(ai , bj ) ∈R
mij =
0 if(ai , bj ) ∈R
/

Example
Let A = {Sofia, Samir, Sarah} and $B = \ CS100, CS101, CS102, CS103\. Consider the
relation of who’s enrolled in which class defined in the table below:

124
Week 17

CS100 CS101 CS102 CS103


Sofia X X
Samir X X
Sarah X X
We can produce a matrix representation of this relation as follows:
 
1 1 0 0
Am,n = 0 1 1 0
1 0 1 0

Combining relations
Union The union of two relations is the same as the union of two sets as defined in
section Union (∪). The union produces a new set containing all ordered pairs that
are in at least one relation. The union of two relations R and S is written as R ∪S
or R orS
Intersection Works the same as defined in section Intersection (∩). Contains all the
elements that are in both R and S. Written as R ∩S or R andS

Combining relations via Boolean operators


Let:
 
1 0 1
MR =  1 0 0 
0 1 0
and
 
1 0 1
MS =  0 1 1 
1 0 0
The union (join) of these two relations can be calculated as:
 
1 0 1
MR∪S = MR ∨ MS = 1 1 1
1 1 0
The intersection (meet) of these two relations can be calculated as:
 
1 0 1
MR∩S = MR ∧ MS = 0  0 0
0 0 0

125
Week 17

Representing relations using directed graphs


When a relation is defined on a set, it can be represented by a digraph.
In order to build a digraph for a relation on a set A, we follow these steps:
1. List all elements of A
2. When (a, b) ∈R, a directed edge from a to b is drawn
3. Repeat until all ordered pairs (a, b) are drawn

Example
Let A = {1, 2, 3, 4}, let R= {(x, y) | x|y}. The relation R can be represented by the
digraph below:

1 2

3 4

Figure 47: A digraph representation of relation R

9.107 The properties of a relation: reflexive, symmetric and


anti-symmetric
Definition of reflexivity
A relation R in a set S is said to be reflexive if and only if x R x, ∀x ∈ S. This means
that (x, x) ∈R.

Example
Let R be the relation:
R= {(a, b) ∈ Z2 | a ≤ b}

126
Week 17

It’s easy to see that this relation is reflexive. Well take any arbitrary element x in Z, we
can show that x ≤ x, which means x R x, hence (x, x) ∈R.
This implies that this relation R is reflexive.
Conversely, the relation:
R= {(a, b) ∈ Z2 | a < b}
Is not reflexive because x 6< x, hence xRx.

Digraph of reflexive relation


Every node in the digraph will have a loop, as shown in figure 48

a0 a1

a2 a3

Figure 48: Reflexive Relation

Matrix of a reflexive relation


When looking at the matrix MR of a reflexive relation R, all elements of the main diagonal
will be 1, as shown below:
 
1 0 1
MR = 0 1 0
0 1 1

Definition of symmetry
A relation R in a set S is symmetric if and only if ∀a, b ∈ S, a R b → b R a.

127
Week 17

Digraph of a symmetric relation


The digraph of a symmetric relation contains a symmetric pair of arcs or every edge of
S. This is depicted in figure 49.

a0 a1

a2 a3

Figure 49: Symmetric Relation

Matrix of symmetric relation


The matrix MR of a symmetric relation is, itself, symmetric. As shown below:
 
1 0 1
MR = 0 0 1
1 1 0

Definition of anti-symmetric
A relation R is anti-symmetric if and only if ∀a, b ∈ S, (a R b ∧ b R a) → a = b.

Digraph of anti-symmetric relation


The digraph of an anti-symmetric relation contains no parallel edges between any two
different vertices. As depicted in figure 50.

128
Week 17

a0 a1

a2 a3

Figure 50: Anti-symmetric Relation

Matrix of anti-symmetric relation


Let MR be the matrix of an anti-symmetric relation. If i 6= j and mij 6= 0, then mji = 0.
 
1 0 1
MR =  1 0 1 
0 0 1

9.109 Relation properties: transitivity


Definition of transivity
A relation R on a set S is called transitive if and only if ∀a, b, c ∈ S, (a R b ∧ b R c) →
a R c.

Examples
1. R= {(x, y) ∈ N2 | x ≤ y}
Transitive if x ≤ y and y ≤ z, then x ≤ z.
2. R= {(2, 3), (3, 2), (2, 2)}
Not Transitive 3 R 2 and 2 R 3 but 3R3

Transitive closure of a relation


Given the relation depicted in figure 51, what is the minimum number of edges to make
the relation transitive?

129
Week 17

a b

d c

Figure 51: Initial Relation

We can see that a R b and b R c but aRc, therefore we must add a new edge from a to
c, as depicted in figure 52.

a b

d c

Figure 52: First new edge

We can also see that b R c and c R d, but bRd, therefore we must add a new edge from
b to d.

a b

d c

Figure 53: Second new edge

This relation is still not transitive. When we added the new edge depicted in figure 52,
we created a new situation where a R c and c R d but aRd, therefore we must add a new
edge from a to d.

130
Week 17

a b

d c

Figure 54: Final new edge

Finally, we have a transitive relation which is called the Transitive Closure of the
original relation R.

131
Week 18

Learning Objectives
• Define an equivalence relation.
• Define partial and total order.
Essential Reading
• Rosen, K.H. Discrete mathematics and its applications. (New York: McGraw-Hill,
2012) 7th edition, pp.570–575, pp.587–594 and pp.597–601.
• Exercises
pp.575–576 exercises 1–4 and 14–22
pp.594–595 exercises 1–6, 9, 17–23, 25 and 32
p.609 exercises 1, 5–7 and 12–15.

9.201 Equivalence relations and equivalence classes


Definition of equivalence relation
Equivalence Relations are binary relations that are reflexive, symmetric, and transitive.

Example
Let R be a relation of elements in Z:
R= {(a, b) ∈ Z2 | a mod 2 = b mod 2}
This relation is:
Reflexive a R a, ∀a ∈ Z
Symmetric ∀a, b ∈ Za R b → b R a
Transitive ∀a, b, c ∈ Z(a R b ∧ b R c) → a R c
∴R is an equivalence relation.

132
Week 18

Definition of equivalence classes


An equivalence class is a subset of a set S such that equivalent elements are part of that
subset.
In order words, if the elements of S have a notion of equivalence (by means of an equiv-
alence relation R) defined on them, then we can split the set S into equivalence classes
in such a way that elements a and b belong to the same equivalence class (a subset of S)
if and only if a and b are equivalent.
This means that the equivalence class defined by the equivalence relation R will form a
subset of S containing all elements related to a through R.
Formally, it’s defined as follows:
[a] = {x : x ∈ S | x R a}1

Example
Let S = {1, 2, 3, 4} and R be a relation on elements in S:
R= {(a, b) ∈ S 2 | a mod 2 = b mod 2}
R is an equivalence relation with 2 equivalence classes:
• [1] = [3] = {1, 3}
• [2] = [4] = {2, 4}
Graphically:

1 2

3 4

Figure 55: Two equivalence classes

1
In Rosen’s book, the notation a ∽ b is used instead of a R b

133
Week 18

9.203 Partial and total order


Definition of partial order
If we have a relation R, we say that R is a Partial Order if and only if R is:
• Reflexive
• Anti-symmetric
• Transitive

Example
Let R be a relation of elements in Z
R= {(a, b) ∈ Z2 | a ≤ b}
This relation is:
Reflexive ∀a ∈ Za ≤ a
Transtivie ∀a, b, c ∈ Z(a ≤ b ∧ b ≤ c) → a ≤ c
Anti-symmetric ∀a, b ∈ Z(a ≤ ∧b ≤ a) → a = b
∴R is a partial order.

Definition of total order


If we have a relation R on the elements of a set S, we say that R is a Total Order if and
only if R is:
• a partial order
• ∀(a, b) ∈ S(a R b ∨ b R a)
– this part means that every pair of elements in S must be comparable with
respect to the relation R

Example
Let R be a relation of elements in Z
R= {(a, b) ∈ Z2 | a ≤ b}
This relation is:
• A partial order (see previous example)
• ∀a, b ∈ Z(a ≤ b ∨ b ≤ a)

134
Week 19

Learning Objectives
• Apply the addition principle and the multiplication principle to count objects when
they are sampled with or without replacement.
Essential Reading
• Rosen, K.H. Discrete mathematics and its applications. (New York: McGraw-Hill,
2012) 7th edition, pp.375–385 and pp.395–401.
• Exercises
pp.386–387 exercises 1–5, 7, 8, 14–17, 30, 32 and 40
pp.394–395 exercises 1–6, 14, 15, 19 and 28
pp.402–403 exercises 1–10, 16, 17, 20, 21, 32 and 34.

10.101 Introduction
Combinatorics is a branch of Discrete Mathematics concerned with the study of finite
or countable discrete structures. It’s the study of collections or arrangements of objects.
Combinatorics finds applications in computer science, economics, physics, and many
other fields.

10.103 The basics of counting


Product Rule
To compute the number of different possible outcomes in a process, we can break it into
two independent tasks.
If there are n different ways of executing the first task and m different ways of executing
the second task, then there are n · m different possible outcomes to the process.
One way to think about this is that if there are n ways of executing the first task, for
each of those n ways, there will be m different ways of executing the second process.

135
Week 19

Product rule in terms of sets


Let A be a set of ways to complete the first task and B be a set of ways to complete the
second task. If A and B are disjoint, then the number of ways of completing both tasks,
can be represented by:
|A × B| = |A| · |B|
This means that the cardinality of the cartesian product of two sets, is the product of
cardinality of each set.

Addition Rule
Let’s assume that we have two independent tasks. Task 1 can be completed in n ways and
task 2 can be completed in m ways. Because these tasks are independent (i.e. completing
task 1 or not has no effect on task 2), the total number of ways of completing both tasks
is n + m.

Example
Let’s assume that a University has to choose either a staff member or a student to be
a University representative. Let’s also assume that there are 77 students and 10 staff
members and nobody is both a student and a staff member. How many ways are there
to choose a representative?
77 + 10 = 87

The sum rule in terms of sets


Let A be the set of ways of completing task 1 and B be the set of ways of completing
task 2, where A and B are disjoint sets. The number of ways of completing either task
1 or task 2 can be represented by:
|A ∪ B| = |A| + |B|

Combining the sum and product rules


Let’s assume that a label in a programming language can be either a single letter or a
letter followed by 2 digits. How many possible labels are there?

136
Week 19

single_letter + letter_2_digits = 26 + (letters · digits2 )


= 26 + (26 · 102 )
= 26 + (26 · 100)
= 26 + 2600
= 2626

Subtraction rule
Suppose a task can be done in either one of n1 ways or one of n2 ways. Then the total
number of ways to do the task is n1 + n2 minus the number of ways common to the two
different ways.
This is also known as the Pinciple of Inclusion-Exclusion.
|A ∪ B| = |A| + |B| − |A ∩ B|

Division rule
Suppose a task can be done using a procedure that can be carried out in n ways, and for
n
every way w, exactly d of the n ways correspond to w. Then this task can be done in
d
ways.
In terms of sets, if the finite set A is the union of n pair-wise disjoint subsets each with
|A|
d elements, then n = .
d
In terms of functions, if f is a function from A to B, where both A and B are finite sets,
and for every value b ∈ B there are exactly d values a ∈ A such that f (a) = b, then
|A|
|B| = .
d

10.105 The pigeonhole principle


See Fundamentals of Computer Science notes and Pigeonhole Principle in wikipedia.

10.107 Permutations and combinations


See Fundamentals of Computer Science notes and Permutations and Combinations on
wikipedia

137
Week 20

Learning Objectives
• Calculate the number of permutations of length r chosen from a set of n objects.
• Demonstrate how to use combination formulae to count the number of unordered
subsets of r objects taken from a set of n distinct objects.
• Distinguish between combinations and permutations.
• Apply the techniques learnt in new counting problems.
Essential Reading
• Rosen, K.H. Discrete mathematics and its applications. (New York: McGraw-Hill,
2012) 7th edition, pp.403–409, pp.410–419 and pp.422–425.
• Exercises
pp.409–410 exercises 1–7 and 13–15
pp.419–421 exercises 1–8, 27, 28, 30–32, 44 and 45.
p.425 exercises 1–3.

10.201 Binomial coefficients and identities


Binomial expression
An expression consisting of two terms connected by a + or − is a binomial expression.
For example
• x+a
• 2x − y
• x2 + y 2
• 3x − 2y

138
Week 20

Binomial theorem
The complexity of an expanded binomial expressions grows with the power.

(x + y)1 = x + y
(x + y)2 = x2 + 2xy + y 2
(x + y)3 = x3 + 3x2 y + 3x y 2 + y 3
(x + y)4 = x4 + 4x3 y + 6x2 y 2 + 4xy 3 + y 4
...

The Binomial Theorem states the following:


Let x and y be variables, and n a non-negative integer. The expansion of (x + y)n can
be formalised as:

n  
n
X n
(x + y) = xk y n−k
k
k=0

Example
What is the coefficient of x8 y 7 in the expansion of (3x − y)15 ?
This expression can be re-written as (3x + (−y))15 . By the binomial theorem we can
describe this expression as:

15  
X 15
(3x + (−y)) =n
(3x)k (−y)15−k
k
k=0

Therefore, we can set k = 8 in order to find the coefficient. Which is:

   
15 8 15−8 15 8
3 (−1) = 3 (−1)7
8 8
15!
= −38 ·
8!7!

Pascal’s identity
Pascal’s identity helps us simplify complicated binomial coefficients.
It states that for positive natural numbers n and k:

139
Week 20

     
n n n+1
+ =
k k−1 k

Proof. Let T be a set where |T | = n + 1, a ∈ T and S = t − {a}.


There are n+1

k subsets of T containing k elements. Each of these subsets either.
• contains a with another k − 1 elements, or
• contains k elements of S and not a.
n n
 
Hence, there are k−1 subsets of k elements containing a and k subsets of k elements
of T that don’t contain a.
∴ nk + k−1n
= n+1
  
k .

Pascal’s triangle
Using Pascal’s identity, we can organise binomial coefficients in a trigular shape called
Pascal’s Triangle.
In this triangle, the element an,r is the binomial coefficient nr .


0

n = 0: 0
1 1
 
n = 1: 0 1
2 2 2
  
n = 2: 0 1 2
3 3 3 3
   
n = 3: 0 1 2 3
4 4 4 4 4
    
n = 4: 0 1 2 3 4
We can also show the same triangle with coeffiecients pre-calculated, as follows:
n = 0: 1
n = 1: 1 1
n = 2: 1 2 1
n = 3: 1 3 3 1
n = 4: 1 4 6 4 1

10.204 Generalised permutations and combinations


Permutations with repetition
The number of r-permutations of a set of n objects with repetition allowed is nr .

Permutations without repetition


n!
The number of r-permutations of a set of n objects without repetition allowed is .
(n − r)!

140
Week 20

Combination with repetition


The number of ways in which k objects can be selected from n categories with repetition
 (n + k − 1)!
permitted is n+k−1
k = .
k!(n − 1)!

Combination without repetition


The number of ways in which k objects can be selected from n categories without repe-
n!
tition permitted is nk =

.
k!(n − k)!

Choice of formulas

Ordered (permutations) Unordered (combinations)

n! n!
Repetition is not permitted (n−k)! k!(n−k)!

(n+k−1)!
Repetition is permitted nk k!(n−1)!

10.206 Distinguishable objects and boxes


Counting problems can be phrased in terms of distributing k objects into n boxes.

Distinguishable objects and distinguishable boxes with exclusion


We want to distribute k balls, numbered from 1 to k, into n boxes, numbered from 1 to
n, in such a way that no box receives more than one ball.
This is equivalent to making and ordered selection of k boxes from n boxes.

141

You might also like