Discrete Math Cam
Discrete Math Cam
Discrete Math Cam
Discrete Mathematics:
Computer Science
Ham Karim
Department of Mathematics
Royal University of Phnom Penh
Permission is granted to copy, distribute and/or modify this document under the
terms of the GNU Free Documentation License, Version 1.2 or any later version
published by the Free Software Foundation; with no Invariant Sections, no Front-
Cover Texts, and no Back-Cover Texts. A copy of the license is included in the
appendix entitled “GNU Free Documentation License”.
2 Language of Mathematics 19
1 Set Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.1 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.2 Venn Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.3 Set Operations . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.4 Counting with Venn Diagrams . . . . . . . . . . . . . . . . . 22
1.5 Properties of Sets . . . . . . . . . . . . . . . . . . . . . . . . . 23
1.6 Generalized Union and Intersection . . . . . . . . . . . . . . . 24
1.7 Partitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.8 Ordered Pairs, Cartesian Product . . . . . . . . . . . . . . . . 24
2 Sequences and strings . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.1 Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.2 Sum and Product Notation . . . . . . . . . . . . . . . . . . . 27
2.3 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3 Relations and properties of relations . . . . . . . . . . . . . . . . . . 27
4 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4.1 Correspondences . . . . . . . . . . . . . . . . . . . . . . . . . 27
iii
iv
3 Counting Methods 37
1 Mathematical induction . . . . . . . . . . . . . . . . . . . . . . . . . 37
1.1 Principle of Mathematical Induction . . . . . . . . . . . . . . 37
1.2 Strong Form of Mathematical Induction . . . . . . . . . . . . 39
1.3 The Well-Ordering Principle . . . . . . . . . . . . . . . . . . 39
2 Recurrence Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
2.1 First Order Recurrence Relations . . . . . . . . . . . . . . . . 40
2.2 Second Order Recurrence Relations . . . . . . . . . . . . . . . 41
3 Basic Principle of Counting . . . . . . . . . . . . . . . . . . . . . . . 43
3.1 The Rule of Sum . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.2 The Rule of Product . . . . . . . . . . . . . . . . . . . . . . . 43
3.3 The Inclusion-Exclusion Principle . . . . . . . . . . . . . . . . 43
4 Combinatorics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.1 Permutations . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.2 Combinations . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
5 Generalized Permutations and Combinations . . . . . . . . . . . . . 45
5.1 Permutations with Repeated Elements . . . . . . . . . . . . . 45
5.2 Combinations with Repetition . . . . . . . . . . . . . . . . . 45
6 Binomial Coefficients . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
6.1 Binomial Theorem . . . . . . . . . . . . . . . . . . . . . . . . 46
6.2 Properties of Binomial Coefficients . . . . . . . . . . . . . . . 47
6.3 Pascal’s Triangle . . . . . . . . . . . . . . . . . . . . . . . . . 47
7 The Pigeonhole Principle . . . . . . . . . . . . . . . . . . . . . . . . 48
7.1 The Pigeonhole Principle . . . . . . . . . . . . . . . . . . . . 48
COURSE SYLLABUS
COURSE NAME : Introduction to Discrete Mathematics: Computer Science
CREDITS : 2 (32h)
Class meets: Friday 1:00-5:00 PM (if not 7:00-11:00 AM for alter.) in Room ???
In this chapter, we will cover some basic points of logic and then fundamental
methods of proof are also focused. The contents of the chapter are as follows:
• Conditional propositions
• Proofs
This chapter is not meant to be a complete enumeration of all possible proof tech-
niques. Its philosophy is that you will learn more about proofs by reading, watching,
and attempting proofs than by an extended study of the logical rules behind proofs.
As such, some examples of proofs can help you read and do proofs if we reflect on
their structure and discuss what constitutes a proof. Thus, we first develop a lan-
guage that will allow us to talk about proofs, and then this kind of language can
be described the logical structure of a proof.
1 Logic
1.1 Propositions, connectives
• “2 < 4” −→ (true),
• “4 = 7” −→ (false).
1
2 CHAPTER 1. LOGIG AND PROOFS
However the following are not propositions: “what is your name?” (this is a ques-
tion), “do your homework” (this is a command), “this sentence is false” (neither
true nor false), “x is an even number” (it depends on what x represents), “Socrates”
(it is not even a sentence). The truth or falsehood of a proposition is called its truth
value, represented by 1 or T for “Truth” and 0 or F for “False”.
For instance: “if Sao is from Battambang then Sok is from Phnom Penh”. The
proposition p, “Sao is from Battambang”, is called hypothesis or antecedent, and
the proposition q, “Sok is from Phnom Penh”, is the conclusion or consequence.
However the following one is false: “if 2 < 4 then London is in Denmark” (true −→
false). ■
To consider a proposition “p ⇒ q”, it seem a bit strange that it is true when
p is false, regardless of the truth value of q. This will become clearer when we
study predicates such as “if x is a multiple of 4 then x is a multiple of 2”. That
implication is obviously true, although for the particular case x = 3 it becomes “if
3 is a multiple of 4 then 3 is a multiple of 2”.
p ∼p p∨∼p p∧∼p
T F T F
T F T F
F T T F
F T T F
We know that the compound propositions p ⇒ q and ∼ p ∨ q have the same truth
values:
p q ∼p ∼p∨q p⇒q
T T F T T
T F F F F
F T T T T
F F T T T
When two compound propositions have the same truth values no matter what
truth value their constituent propositions have, they are called logical equiva-
lence. For instance p ⇒ q and ∼ p ∨ q are logically equivalent, we, then, write it
as:
p⇒q ≡ ∼p∨q
Note that that two propositions A and B are logically equivalentprecisely when
A ⇐⇒ B is a tautology.
∼ (p ∨ q) ≡ ∼p∧∼q
∼ (p ∧ q) ≡ ∼p∨∼q
p⇔q ≡ (p ⇒ q) ∧ (q ⇒ p)
■
Exercise: Check the following logical equivalences:
∼ (p ⇒ q) ≡ p∧ ∼ q
p⇒q ≡ ∼ q ⇒∼ p
∼ (p ⇔ q) ≡ p⊕q
p⇔q ≡ (p ⇒ q) ∧ (q ⇒ p)
6 CHAPTER 1. LOGIG AND PROOFS
So, for instance, saying that “John is married if and only if he has a spouse” is
the same as saying “if John is married then he has a spouse” and “if he has a spouse
then he is married”. Note that the converse is not equivalent to the given condi-
tional proposition, for instance “if John is from Chicago then John is from Illinois”
is true, but the converse “if John is from Illinois then John is from Chicago” may
be false.
On the other hand, the contrapositive of “if John is from Chicago then John is
from Illinois” is “if John is not from Illinois then John is not from Chicago”. Thus,
they are logically equivalent.
Equivalence Name
p∧T ≡p Identity laws
p∨F ≡p
p∨T≡T Domination laws
p∧F≡F
p∨p≡p Idenpotent laws
p∧p≡p
∼ (∼ p) ≡ p Double negation law
p ∨q ≡q ∨p Commutative laws
p ∧q ≡q ∧p
(p ∨ q) ∨ r ≡ p ∨ (q ∨ r) Association laws
(p ∧ q) ∧ r ≡ p ∧ (q ∧ r)
p ∨ (q ∧ r) ≡ (p ∨ q) ∧ (p ∨ r) Distributive laws
p ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r)
∼ (p ∧ q) ≡ ∼ p∨ ∼ q De Morgan’s laws
∼ (p ∨ q) ≡ ∼ p∧ ∼ q
p ∨ (p ∧ q) ≡ p Absorption laws
p ∧ (p ∨ q) ≡ p
p∨∼p≡T Negation laws
p∧∼p≡F
Question: (A merge sort program) Joe and Mary have each written an algorithm
for a function that takes two sorted lists, List1 and List2, of lengths m and n,
respectively, and merges them into a third list, List3. Part of Mary’s algorithm is
as follows:
(1) if ((i + j <= m + n) && (i <= m) && ((j > n)
1. LOGIC 7
Example 5.
Solution:
8 CHAPTER 1. LOGIG AND PROOFS
1.5 Formulas
More complicated propositional expressions, formulas or well-formed formulas,
can be built from the proposition letters using the propositional connectives and
parentheses. When we say ϕ = (p ∧ q) ⇒ r, we mean that ϕ is the string of symbols
(p ∧ q) ⇒ r. Consider the following formulas, whether the conclusion is necessarily
true:
(i.) ψ = (p ∧ q) ⇒ r, means “If p and q are both true, then r is also true.”
(ii.) ψ1 = (p ∨ q) ⇒ r, means “If p or q (or both) is true, then r is also true.”
(iii.) ψ2 = (p ⇒ r) ⇒ ((p ∧ q) ⇒ r), means “Suppose that if p is T , then r is T .
Then, if p and q are both T , then r is T .”
Proof:
ϕ = (p ∧ q) ⇒ (∼ (r ∧ s))
Definition 1.6 A formula is any string of symbols that is formed using the
following rules:
p p p
. p∧q . p∨q p . ∼p . p⊕q
q q q
p p
. p↑q . p↓q
q q
Example 7.
(p ∧ q) ∧ r
is shown as follows:
p p∧q
q
(p ∧ q) ∧ r
r
.
Figure 1.2: AND gates
p∧p
p (p ∧ p) ∧ p
Note: Since gates are used to describe computer circuits that will be implemented
in a device or printed on a chip, it is common to represent more than one formula
in the same diagram.
1.7 Predicates
1.8 Quantifiers
Given a predicate P (x), the statement “for some x, P (x)” or “there is some x such
that P (x)”, written as “∃x, P (x)”, has a definite truth value, so it is a proposition.
For instance, if P (x) is “x + 2 = 7” with the integers as domain of discourse, then
∃x, P (x) is true, since there is indeed an integer, say 5, such that P (5) is a true
statement. Yet, if Q(x) is “2x = 7” and the domain of discourse is still the integers,
then ∃x, Q(x) is false. On the other hand, ∃x, Q(x) would be true if x ∈ Q. The
symbol ∃ is called the existential quantifier.
With the same sense, the sentence “for all x, P (x)” or “for any x, P (x)” or “for
every x, P (x)” or “for each x, P (x)”, written as “∀x, P (x)”, has a definite truth
value. For instance, if P (x) is “x + 2 = 7” and the domain of discourse is the inte-
gers, then ∀x, P (x) is false. However, if Q(x) represents “(x + 1)2 = x2 + 2x + 1”
then “∀x, Q(x)” is true. The symbol ∀ is called the universal quantifier.
Remark:
∀x ∃y, P (x, y) ̸= ∃y ∀x, P (x, y)
( ) ( )
∼ ∃x ∀y, p(x, y) ≡ ∀x ∼ ∀y, P (x, y) ≡ ∀x ∃y, ∼ P (x, y)
Example 10. Write formally the statement “for every real number there is a
greater real number”. Write the negation of that statement. ■
2 Proofs
2.1 Mathematical Systems
A Mathematical System consists of:
Answer: Assuming x > 2 and y > 3 and adding the inequalities term by term, we,
then, get:
x+y >2+3=5
Answer:
( ) that x + y > 5 ⇒ (x > 2) ∨ (y >
We must prove ( 3). Thus, we must
) proof
∼ (x > 2) ∨ (y > 3) ⇒ ∼ (x + y > 5). We have: ∼ (x > 2) ∨ (y > 3) is the
same as (x ≤ 2) ∧ (y ≤ 3), so adding both inequalities we get x + y ≤ 5, which is
the same as ∼ (x + y > 5).
Answer: We assume the hypothesis x + y > 5. From here we must conclude that
x > 2 or y > 3. Assume to the contrary that “x > 2 or y > 3” is false, so x ≤ 2
and y ≤ 3. Adding those inequalities, we get x + y ≤ 2 + 3 = 5, which contradicts
the hypothesis x + y > 5. From here, we conclude that the assumption “x ≤ 2 and
y ≤ 3” cannot be right, so “x > 2 or y > 3” must be true.
Note: See its difference. In an indirect proof, we prove an implication of the form
p ⇒ q by proving the contrapositive ∼ q ⇒∼ p. In a proof by contradiction, we
prove an statement s (which may or may not be an implication); by assuming ∼ s
and deriving a contradiction. In fact, proofs by contradiction are more general than
indirect proofs
√
Example 4. Prove by contradiction that 2 is not a rational number. ■
√ √
Answer: Assume that 2 is rational, i.e., 2 = a/b, where a and b are integers
and the fraction is written in least terms. We have,
2 = a2 /b2
hence
2b2 = a2
Since the left hand side is even, then a2 is even, but this implies that a itself is
even, so a = 2a′ . Hence:
2b2 = 4a′2
and simplifying:
b2 = 2a′2
This implies that b2 is even, so b is even: b = 2b′ . Consequently, a/b = 2a′ /2b′ =
a′ /b′ , which is contradicting the hypothesis that a/b was in least terms.
2. PROOFS 13
p1
p2
..
.
pn
∴ q
The argument is called valid if q is true whenever p1 , p2 , · · · , pn are true; oth-
erwise it is called invalid.
Rules of inference: are certain simple arguments known to be valid and used to
make a proof step by step. In logic, a rule of inference, is the act of making a conclu-
sion relied on the form of premises interpreted as a function which takes premises,
analyses their syntax, and returns a conclusion (or conclusions). Common
rules of inference are cited as follows:
i). Modus Ponens: commonly called as Rule of Detachment (in Latin for the
way that affirms by affirming) or implication elimination is a valid, simple
argument form. It is a very common rule of inference, and takes the following
form:
p⇒q
p
∴ q
p q p⇒q p q
T T T T T
T F F T F
F T T F T
F F T F F
”If roses are red and violets are blue, then sugar is sweet and so are
you.”
”Roses are red and violets are blue.”
ii). Modus Tollens: (or modus tollendo tollens in Latin) means the way that
denies by denying), which has the following argument form:
p⇒q
∼q
∴ ∼p
p q p⇒q ∼p ∼q
T T T F F
T F F F T
F T T T F
F F T T T
p
∴ p∨q
Example 7. Consider:
Socrates is a man.
p∧q
∴ p
Example 8.
v). Conjunction: is the inference that, if p is true, and q is true, then the
conjunction p ∧ q is true.
p
q
∴ p∧q
Example 9. Consider:
If it’s true that it’s raining, and it’s true that I’m inside, then it’s true
that ”it’s raining and I’m inside”. ■
p⇒q
q⇒r
∴ p⇒r
p∨q
∼p
∴ q
viii). Resolution:
16 CHAPTER 1. LOGIG AND PROOFS
p∨q
∼p∨r
∴ q∨r
“It is cold or raining” and “It is not cold or it is snowing” are true, then it is
raining or snowing. ■
Exercises
1. Use the truth tables to determine whether the following logical equivalences are
correct:
1. p ∧ (q ⊕ r) ≡ (p ∧ q) ⊕ (p ∧ r)
2. (p ⊕ q) ⊕ r ≡ p ⊕ (q ⊕ r)
3. (p ⇒ q) ⇒ r ≡ p ⇒ (q ⇒ r)
4. (p ⊕ q) ⊕ r ≡ (p ⇔ q) ⇔ r
5. p ⇒ (q ⇒ r) ≡ (p ∧ q) ⇒ r
2. ∀x∃y, (x < y)
3. ∃x∀y, (x < y 2 )
4. ∃x∃y, (x ≤ y)
Determine their truth value assuming that the universe of discourse is:
3. Let C(x, y) means that student x is enrolled in class y, where the domain for
x consists of all students in your school and the domain for y consists of all classes
being given at your school. Express each of these statements by a simple English
sentence.
3. A is red or C is red.
4. B is not green.
Use a formal argument to prove that D is green (write it in three columns con-
taining respectively a label (no.), a compound proposition and a reason).
1. ∀x∀y, (x2 = y 2 ⇒ x = y)
2. ∀x∃y, (y 2 = x)
3. ∀x∀y, (xy ≥ x)
7. Show that each of these conditional statements is a tautology by using (i) truth
tables and (ii) logical equivalence properties (without construct their truth tables)
1. [∼ p ∧ (p ∨ q)] ⇒ q
2. [(p ⇒ q) ∧ (q ⇒ r)] ⇒ (p ⇒ r)
1. There exists a pair of consecutive integers such that one is a perfect square
and the other one is a perfect cube.
2. The product of two of the numbers: 651000 −82001 + 3177 , 791212 −92399 +
22001 ,
and 244493 −58192 + 71777 is nonnegative. (Do not try to evaluate these
numbers!).
18
Chapter 2
Language of Mathematics
1 Set Theory
1.1 Definition
A Set is a collection of objects, called elements of the set. A set can be represented
by listing its elements between braces, such as A = {1, 2, 3, 4, 5}. The symbol ∈
is used to express that an element is (or belongs to) a set, for instance 3 ∈ A. Its
negation is represented by ∈,
/ e.g. 7 ∈ / A. If the set is finite, its number of elements
is represented by |A| or card(A), e.g. in above example, we get |A| = 5.
3. S∗ = set of elements in S excluding zero, for instance R∗ = the set of non zero
real numbers.
Set-builder notation. An alternative way to define a set, called set-builder nota-
tion, is by stating a property (predicate) P(x) verified by exactly its elements, for
instance A = {x ∈ Z | 1 ≤ x ≤ 5} = “set of integers x such that 1 ≤ x ≤ 5” — i.e.,
A = {1, 2, 3, 4, 5}.
19
20 CHAPTER 2. LANGUAGE OF MATHEMATICS
Principle of Extension: Two sets are equal if and only if they have the same
elements, i.e.: ( )
A = B ≡ ∀x x ∈ A ⇔ x ∈ B (2.1)
Subset: We say that A is a subset of set B, or A is contained in B, and we
represent it “A ⊆ B”, if all elements of A are in B, e.g., if A = {a, b, c} and
B = a, b, c, d, e then A ⊆ B.
A is a proper subset of B, represented “A ⊂ B”, if A ⊆ B but A ̸= B, i.e.,
there is some element in B which is not in A.
Empty Set: A set with no elements is called empty set (or null set, or void set),
and is represented by ∅ or {}.
Power Set: The collection of all subsets of a set A is called the power set of A,
and represented by P(A). For instance, if A = {1, 2, 3}, then
{ }
P(A) = ∅, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, A
U
B
A∩B
Figure 2.2: The intersection of two sets A and B
Union: The set of elements that belong to either of two sets, then
{ }
A∪B= x | x∈A∨x∈B (2.3)
U
B
A
A ∪ B
Complement: The set of elements (in the universal set) that do not belong to a
given set, represented by Ac or A
{ }
Ac = x ∈ U | x ∈
/A (2.4)
Difference: The set of elements that belong to a set but not to another:
{ }
A\B= x | x∈A∧x∈ / B =A∩B (2.5)
22 CHAPTER 2. LANGUAGE OF MATHEMATICS
A
B
A\B
B\A
Symmetric Difference: Given two sets, their symmetric difference is the set of
elements that belong to either one or the other set but not both:
{ }
A⊕B= x | x∈A⊕x∈B (2.6)
A
B
60 90 185
10
140 65
235
C
Proof: The number of students taking exactly one of those courses is 60 + 185 +
235 = 480.
■
1. SET THEORY 23
2. Commutative Laws:
A∪B = B∪A (2.9)
A∩B = B∩A (2.10)
3. Distributive Laws:
A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C) (2.11)
A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) (2.12)
4. Identity Laws:
A∪∅ = A (2.13)
A∩U = A (2.14)
5. Complement Laws:
A∪A = U (2.15)
A∩A = ∅ (2.16)
6. Idempotent Laws:
A∪A = A (2.17)
A∩A = A (2.18)
7. Bound Laws:
A∪ U = U (2.19)
A∩∅ = ∅ (2.20)
8. Absorption Laws:
A ∪ (A ∩ B) = A (2.21)
A ∩ (A ∪ B) = A (2.22)
9. Involution Law:
A = A (2.23)
Analogously, their intersection is the set of elements that belong to all the sets
simultaneously:
∩
n { }
An = A1 ∩ A2 ∩ · · · ∩ An = x | ∀k (x ∈ An ) . (2.29)
k=1
These definitions can {be applied to infinite } collections of sets as well. For in-
stance assume that Sn = kn | k = 2, 3, 4, · · · = set of multiples of n greater than
n. Then,
∞
∪
Sn = S2 ∪ S3 ∪ S4 ∪ · · · = {4, 6, 8, 9, 10, 12, 14, 15, · · · }
k=2
= set of composite positive integers
1.7 Partitions
A partition of a set X is a collection S of non overlapping non-empty subsets of X
whose union is the whole X. Thus, X1 , X2 , . . . , Xn is a partition of X if and only
if n
∪
Xk = X where Xk ̸= ∅
k=1 (2.30)
X ∩ X = ∅ for all i ̸= j
i j
Example 3. The{ divisions of} Z in negative integers, positive integers and zero is a
partition: S = Z+ , Z− , {0} ■
Given two sets A, B, their Cartesian product A × B is the set of all ordered
pairs (a, b) such that a ∈ A and b ∈ B:
{ }
A×B = (a, b) | (a ∈ A) ∧ (b ∈ B) (2.31)
B
b7 b b b b b b b b b
b6 b b b b b b b b b
b5 b b b b b b b b b
b4 b b b b b b b b b
b3 b b b b b b b b b
b2 b b b b b b b b b
b1 (a1 , b1 )
b b b b b b b b b
a1 a2 a3 a4 a5 a6 a7 a8 a9 A
Analogously, we can define triples or 3-tuples (a, b, c), 4-tuples (a, b, c, d), · · · ,
n-tuples (a1 , a2 , · · · , an ), and the corresponding 3-fold, 4-fold, · · · , n-fold Cartesian
products:
∏
n { }
Ak = (a1 , . . . , an ) | (a1 ∈ A1 ) ∧ . . . ∧ (an ∈ An ) (2.32)
k=1
Remark: In case of all the sets in a Cartesian product are the same, then we can
use an exponent, such as : A2 = A × A, A3 = A × A × A, etc. In general:
An = A × A × . . . × A (2.33)
| {z }
n−times
∏
n
{ }
= A= (a1 , a2 , . . . , an ) | ∀k ∈ Nn : ak ∈ A
k=1
An example of Cartesian product is the real plane R2 , where R is the set of real
numbers (R is sometimes called real line).
Example 1.
26 CHAPTER 2. LANGUAGE OF MATHEMATICS
1, 2, 3, 4, . . . , n, . . .
2, 4, 6, 8, . . . , 2n, . . .
iv). The sequence of Fibonacci numbers (each one is the sum of the two pre-
vious ones):
0, 1, 1, 2, 3, 5, 8, 13, ...
1 1 1 1
1, , , , ···, , ···
2 3 4 n
Here we are assuming that the first element is s1 , but we can start at any value
of the index that we want, for instance if we declare s0 to be the first term, the
previous sequence would become:
1, 3, 5, 7, 9, ...
1, 2, 3, 4, 5...,
2, 4, 6, 8, ...
3. RELATIONS AND PROPERTIES OF RELATIONS 27
∑
n
ak = am + am+1 + am+2 + . . . + an (2.34)
k=m
2. Product notation:
∏
n
ak = am × am+1 × am+2 × . . . × an (2.35)
k=m
∏6 ∑6
Answer: n=3 an = 9009, n=3 an = 40
2.3 Strings
Given a set A, a string over A is a finite ordered list of elements of A.
Example 3. If A = {a, b, c}, then the following are strings over A : aba, aaaa, bba,
etc ■
Note: If repetitions exist, a superscripts can be replaced them, for instance:
a2 b3 ac2 a3 = aabbbaccaaa, (ab)3 = ababab, etc
The string with no elements is called null string, represented λ. Its length is
zero, i.e, |λ| = 0.
The set of all strings over A is represented A∗ . The set of no null strings over
A (i.e., all strings over A except the null string) is represented by A+
4 Functions
4.1 Correspondences
Suppose that to each element of a set A we assign some elements of another set
B. For instance, A = N, B = Z, and to each element x ∈ N we assign all elements
y ∈ Z such that y 2 = x.
28 CHAPTER 2. LANGUAGE OF MATHEMATICS
1 1
2
3 -1
4 2
5
6 7 -2
9 3
8
-3
10
N Z
√
Figure 2.8: Correspondence of x 7→ ± x
Arrow diagrams: Venn diagrams and arrows can be used for representing rela-
tions between given sets. As an example, figure 2.9 represents the relation from
A = {a, b, c, d} to B = {1, 2, 3, 4} given by R = {(a, 1), (b, 1), (c, 2), (c, 3)}. In the
diagram an arrow from x to y means that x is related to y. This kind of graph
is called directed graph or digraph.
a
1
b
2
c
3
d
4
A
B
Figure 2.9: Correspondence of R
Another example is given in diagram 2.10, which represents the divisibility rela-
tion on the set A = {1, 2, 3, 4, 5, 6, 7, 8, 9}.
4. FUNCTIONS 29
1
4
3 2
5
7
6 8
A
Figure 2.10: Binary relation of divisibility of set A
1 2 3 4
a ⃝
1 0 0 0
b ⃝1 0 0 0
c 0 ⃝
1 ⃝
1 0
d 0 0 0 0
R S
A B C
S ◦R
1. Reflexive: if for all x ∈ A, xRx. For instance on Z the relation “equal to”
(=) is reflexive.
2. Transitive: if for all x, y, z ∈ A, xRy and yRz implies xRz. For instance
equality (=) and inequality (<) on Z are transitive relations.
Example 1.
■
4. FUNCTIONS 31
bc 4 6
bc
2 bc 3 bc
bc
1
Figure 2.11: Hasse diagram for divisibility
Example 2.
• On Z, the equality (=) is an equivalence relation.
1). Ai ∩ Aj = ∅ for i ̸= j,
∪
2). k Ak = A
Example 4. In Z with the relation of congruence modulo 2 (call it “∼ 2”), there are
two equivalence classes: the set E of even integers and the set O of odd integers. The
quotient set of Z by the relation “∼ 2” of congruence modulo 2 is Z/ ∼ 2 = {E, O}.
We see that it is in fact a partition of Z, because E ∩ O = ∅, and Z = E ∪ O. ■
Exercise: Let m be an integer greater than or equal to 2. On Z we define the
relation x ≡ y (mod m) ⇔ m|(y−x) (i.e., m divides exactly y−x). Prove that it is
an equivalence relation. What are the equivalence classes? How many are there?
5 Functions
A function or mapping f from a set A to a set B, denoted f : A → B, is a
correspondence in which to each element x of A corresponds exactly one element
y = f (x) of B . See (figure 2.12).
b
f b
b b
b
b
b b
b
b
b
b
b b
A B
Figure 2.12: Diagram of a function
f : A −→ B
x 7−→ y
or
f
A −−→ B
x 7−→ y
For instance, the following represents the function from Z to Z defined by f (x) =
2x + 1:
5. FUNCTIONS 33
f : Z −→ Z
x 7−→ 2x + 1
■
34 CHAPTER 2. LANGUAGE OF MATHEMATICS
g◦f
A f B g C
( )
x y = f (x) z = g(y) = g f (x)
f ◦ 1A = 1B ◦ f = f
f g h
2). Function composition is associative A −
→B→ − C−
→ D, we have
( ) ( )
h◦ g◦f = h◦g ◦f
The arrow diagram of f −1 is the same as the arrow diagram of f but with all
arrows reversed.
f −1 ◦ f = 1A and f ◦ f −1 = 1B
5.5 Operators
A function from A × A to A is called a binary operator on A . For instance the
addition of integers is a binary operator + : Z × Z → Z. In the usual notation
for functions the sum of two integers x and y would be represented +(x, y). This
is called prefix notation. The infix notation consists of writing the symbol of the
binary operator between its arguments, i.e, x + y (this is the most common). There
is also a postfix notation consisting of writing the symbol after the arguments: xy+.
1 Mathematical induction
Many properties of positive integers can be proved by mathematical induction.
37
38 CHAPTER 3. COUNTING METHODS
1. MATHEMATICAL INDUCTION 39
2 Recurrence Relations
Here we look at recursive definitions under a different point of view. Rather than
definitions they will be considered as equations that we must solve. The point is
that a recursive definition is actually a definition when there is one and only one ob-
ject satisfying it, i.e., when the equations involved in that definition have a unique
solution. Also, the solution to those equations may provide a closed-form (explicit)
formula for the object defined.
Using the summation notation, its solution can be expressed like this:
∑
n
xn = Arn + ck rn−k
k=1
and
xn = A + cn, if r=1
Example 1. Example: Assume that a country with currently 100 million people
has a population growth rate (birth rate minus death rate) of 1% per year, and it
also receives 100 thousand immigrants per year (which are quickly assimilated and
reproduce at the same rate as the native population). Find its population in 10
years from now. (Assume that all the immigrants arrive in a single batch at the
end of the year.) ■
Thus,
x10 = 110, 462, 317
In Set Theory, the rule of sum is determined as: If A and B are disjoint sets
(A ∩ B = ∅) then
n(A ∪ B) = n(A) + n(B)
Example 1. If a class has 30 male students and 25 female students, then the class
has 30 + 25 = 45 students. ■
As such, the rule of product in Set Theory: Let A × B be the Cartesian product
of sets A and B. Then:
n(A × B) = n(A).n(B)
Example 2. Assume that a license plate contains two letters followed by three
digits. How many different license plates can be printed? ■
Proof: Each letter can be printed in 26 ways, and each digit can be printed in
10 ways, so 26.26.10.10.10 = 676000 different plates can be printed.
Example 3. Given a set A with m elements and a set B with n elements, find the
number of functions from A to B . ■
Example 4. Assume that in a university with 1000 students, 200 students are
taking a course in mathematics, 300 are taking a course in physics, and 50 students
are taking both. How many students are taking at least one of those courses? ■
For three sets the following formula applies:
n(A1 ∩ A2 ∩ . . . An ) = s1 − s2 + s3 − s4 + . . . ± sn
4 Combinatorics
4.1 Permutations
Assume that we have n objects. Any arrangement of any k of these objects in
a given order is called a permutation of size k. If k = n then we call it just a
permutation of the n objects.
Example 1. The permutations of the letters a, b, c are the following: abc, acb, bac,
bca, cab, cba. The permutations of size 2 of the letters a, b, c, d are: ab, ac, ad, ba, bc, bd,
ca, cb, cd, da, db, dc. ■
Note that the order is important. Given two permutations, they are considered
equal if they have the same elements arranged in the same order.
P(n, n) = n!
By convention 0! = 1.
Example 3. Given a set A with m elements and a set B with n elements, find the
number of one-to-one functions from A to B. ■
4.2 Combinations
Assume that we have a set A with n objects. Any subset of A of size r is called a
combination of n elements taken r at a time.
Task (i) can be performed in C(n, r) ways, and task (ii) can be performed in
P(r, r) ways. By the product rule we have P(n, r) = C(n, r) × P(r, r), hence
P(n, r) n!
C(n, r) = =
P(r, r) r!(n−r)!
Example 1. With 3 a’s and 2 b’s we can write the following 5−letter words:
aaabb, aabab, abaab, baaab, aabba, ababa, baaba, abbaa, babaa, bbaaa. ■
We may solve this problem in the following way, as illustrated with the example
above. Let us distinguish the different copies of a letter with subscripts: a1 a2 a3 b1 b2 .
Next, generate each permutation of this five elements by choosing 1) the position
of each kind of letter, then 2) the subscripts to place on the 3 a’s, then 3) these
subscripts to place on the 2 b’s. Task 1) can be performed in P(5; 3, 2) ways, task
2) can be performed in 3! ways, task 3) can be performed in 2!. By the product
rule we have 5! = P(5; 3, 2) × 3! × 2!, hence P(5; 3, 2) = 5!/3!2!.
In general the formula is:
n!
P(n; n1 , n2 , . . . , nk ) =
n1 !n2 ! . . . nk !
Two combinations with repetition are considered identical if they have the same
elements repeated the same number of times, regardless of their order.
Note that the following are equivalent:
(i) The number of combinations of n objects taken r at a time with repetition.
(ii) The number of ways r identical objects can be distributed among n distinct
containers.
(iii) The number of nonnegative integer solutions of the equation:
x1 + x2 + . . . + xn = r
Example 3. Assume that we have 3 different (empty) milk containers and 7 quarts
of milk that we can measure with a one quart measuring cup. In how many ways
can we distribute the milk among the three containers? ■
Proof: We solve the problem in the following way. Let x1 , x2 , x3 be the quarts
of milk to put in containers number 1, 2 and 3 respectively. The number of possible
distributions of milk equals the number of non negative integer solutions for the
equation x1 + x2 + x3 = 7. Instead of using numbers for writing the solutions,
we will use strokes, so for instance we represent the solution x1 = 2, x2 = 1, x3 =
4, or2 + 1 + 4, like this: || + | + ||||. Now, each possible solution is an arrangement( of
)
7 strokes and 2 plus signs, so the number of arrangements is P(9; 7, 2) = 7!2! 9!
= 97 .
6 Binomial Coefficients
6.1 Binomial Theorem
The following identities can be easily checked:
(x + y)0 = 1
(x + y)1 = x + y
(x + y)2 = x2 + 2xy + y 2
(x + y)3 = x3 + 3x2 y + 3xy 2 + y 3
They can be generalized by the following formula, called the Binomial Theorem:
∑n ( )
n n n−k k
(x + y) = x y
k
k=0
( ) ( ) ( )
n n n n−1 n n−2 2
= x + x y+ x y + ...+
0 1 2
( ) ( )
n n−1 n n
xy + y
n−1 n
6. BINOMIAL COEFFICIENTS 47
(x + y)n = (x + y) × (x + y) × . . . × (x + y)
| {z }
(n−factors)
expanding, and grouping terms of the form xa y b . Since there are n factors of
the form (x + y), we have a + b = n, hence the terms must be of the form xn−k y k .
The coefficient of xn−k y k will be equal to the number of ways in which we can select
the y from any ( )the x from the remaining n − k factors), which
( )k of the factors (and
is C(n, k) = nk . The expression nk is often called binomial coefficient.
We notice that each binomial coefficient on this arrangement must be the sum
( ) of
the two closest binomial coefficients on the line above it. This together with n0 =
48 CHAPTER 3. COUNTING METHODS
(n )
n = 1, allows us to compute very quickly the values of the binomial coefficients
on the arrangement:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1
Although it was already known by the Chinese in the XIV century
2
The Pigeonhole Principle (Schubfachprinzip) was first used by Dirichlet in Number Theory.
The term pigeonhole actually refers to one of those old-fashioned writing desks with thin vertical
wooden partitions in which to file letters.