Discrete Structures
Discrete Structures
If p or q, then r.
q.
Therefore, r.
Statement variables
March 19, 2024 8
2.1.2. Compound Statements
Logical connectives:
also
~
not and or
Truth values:
p q pq p q pq
p ~p T T T T T T
T F T F F T F T
F T F T F F T T
F F F F F F
Order of operations:
~ is performed first
and are coequal in order of operation
~p q = (~p) q pqr
Ambiguous
Given:
h = “It is hot”
s = “It is sunny”
Write logical statements for the following:
a. “It is not hot but it is sunny.”
(1) Dogs bark and cats meow. (2) Cats meow and dogs bark.
Double negation:
~(~p) p
p ~p ~(~p)
T F T
F T F
~(p q) ~p ~q
Truth table method:
p q ~p ~q pq ~(p q) ~p ~q
T T F F T F F
T F F T F T F
F T T F F T F
F F T T F T T
~(p q) ~p ~q
Counter example method:
Let p be the statement “0 < 1” and
q the statement “1 < 0”.
“Not the case that both 0<1 and 1<0”
~(p q)
which is TRUE.
~(p q) ~p ~q
p t c pt pc
T T F T F
F T F F F
Conditional statement
If p, then q pq
28
Conditional Statements
Logical connective: Truth values: p q pq
T T T
T F F
if-then/implies F T T
F F T
Example #1:
A Conditional Statement with a False Hypothesis
If 0 = 1, then 1 = 2
31
Conditional Statements: Order of Operations
Order of operations:
~
not and or if-then/implies
Coequal in order
32
Conditional Statements: Example #2
Example #2: Truth Table for p ~q ~p
p ~q ~p (p (~q)) (~p)
conclusion hypothesis
p q ~p ~q p ~q p ~q ~p
T T F F T
T F F T T
F T T F F
F F T T T
33
Conditional Statements: Example #3
Example #3: Show that
pqr (p r) (q r)
p q r pq pr qr pqr (p r) (q r)
T T T T T T
T T F T F F
T F T T T T
T F F T F T
F T T T T T
F T F T T F
F F T F T T
F F F F T T
34
2.2.2. Representation of If-Then as Or
35
Representation of If-Then as Or
p q pq p q ~p q
T T T T T T
T F F T F F
F T T F
~p
T
q T
F F T F F T
pq
36
2.2.3. Negation of a Conditional Statement
~(p q) p ~q
37
Negation of a Conditional Statement: Quick Quiz
35
2.2.4. Contrapositive of a Conditional Statement
pq ~q ~p
contrapositive
36
Contrapositive: Quick Quiz
37
2.2.5. Converse and Inverse of a Conditional Statement
qp ~p ~q
converse inverse
42
Converse and Inverse: Quick Quiz
Write the converse and inverse of the following
statements:
a. If Howard can swim across the lake, then Howard can
swim to the island.
Converse:
Inverse:
pq ~q ~p
conditional contrapositive
statement
qp ~p ~q
converse inverse
Note that:
pq qp
44
2.2.6. Only If and the Biconditional
45
Only If : Quick Quiz
Rewrite the following statement in if-then form in two
ways, one of which is the contrapositive of the other.
John will break the world’s record only if he runs the mile in
under four minutes.
Version 1: If John does not run the mile in under four minutes,
then John will not break the world’s record.
Version 2:
43
Only If and the Biconditional
Definition 2.2.6 (Biconditional)
pq p q pq
T T T
T F F
F T F
F F T
47
Only If and the Biconditional
pq (p q) (q p)
48
Only If and the Biconditional
Order of operations:
~
not and or if-then/implies if and only if
Performed first
Performed last
49
Biconditional : Quick Quiz
47
2.2.7. Necessary and Sufficient Conditions
51
Necessary and Sufficient Conditions
On the other hand, to say “r is a necessary condition
for s” means that if r does not occur, then s cannot
occur either: The occurrence of r is necessary to
obtain the occurrence of s.
Note that due to the equivalence between a
statement and its contrapositive:
r is a necessary condition for s also means “if s then r”.
Consequently,
r is a necessary and sufficient condition for s
means “r, if and only if, s”.
52
Necessary and Sufficient Conditions
“If John is eligible to vote, then he is at least 18 years old.”
53
2.3 Valid and Invalid
Arguments
55
Valid and Invalid Arguments
Definition 2.3.1 (Argument)
An argument (argument form) is a sequence of statements (statement forms).
All statements in an argument (argument form), except for the final one, are
called premises (or assumptions or hypothesis). The final statement
(statement form) is called the conclusion. The symbol , which is read
“therefore”, is normally placed just before the conclusion.
To say that an argument form is valid means that no matter what particular
statements are substituted for the statement variables in its premises, if the
resulting premises are all true, then the conclusion is also true.
Example:
If p, then q
premises
p
q conclusion
56
Valid and Invalid Arguments
When an argument is valid and its premises are true,
the truth of the conclusion is said to be inferred or
deduced from the truth of the premises.
If a conclusion “ain’t necessarily so”, then it isn’t a
valid deduction.
57
2.3.2. Determining Validity or Invalidity
Testing an Argument Form for Validity
1. Identify the premises and conclusion of the argument form.
2. Construct a truth table showing the truth values of all the
premises and the conclusion.
3. A row of the truth table in which all the premises are true is
called a critical row.
If there is a critical row in which the conclusion is false
the argument form is invalid.
If the conclusion in every critical row is true
the argument form is valid.
58
Determining Validity or Invalidity: Example #1
p q ~r
qpr Invalid argument
pr premises
conclusion
p q r ~r q ~r pr p q ~r qpr pr
Critical
T T T F T T T T T rows
T T F T T F T F
T F T F F T F T
T F F T T F T T F
F T T F T F T F
F T F T T F T F
F F T F F F T T T
F F F T T F T T T
59
2.3.3. Modus Ponens and Modus Tollens
Syllogism: An argument form consisting of two
premises and a conclusion.
A famous form of syllogism is called modus ponens:
If p then q
p
q
60
Modus Ponens and Modus Tollens
Modus ponens is a valid form of argument.
pq
p
p q pq p q
q
T T T T T
T F F T
F T T F
F F T F
61
Modus Ponens and Modus Tollens
Modus tollens is another valid form of argument.
If p then q
~q
~p
62
Modus Ponens and Modus Tollens: Quick Quiz
Use modus ponens or modus tollens to fill in the
blanks of the following arguments so that they
become valid inferences.
a. If there are more pigeons than there are pigeonholes,
then at least two pigeons roost in the same hole.
There are more pigeons than there are pigeonholes.
60
2.3.4. Additional Valid Argument Forms: Rules of
Inference
A rule of inference is a form of argument that is valid.
Thus modus ponens and modus tollens are both rules of
inference.
More examples:
1. Generalization
2. Specialization
3. Elimination
4. Transitivity
5. Proof by Division into Cases
64
2.3.4.1. Rules of Inference: Generalization
Example:
Anton is a junior.
(More generally) Anton is a junior or Anton is a senior.
65
2.3.4.2. Rules of Inference: Specialization
66
2.3.4.3. Rules of Inference: Elimination
The following argument forms are valid.
pq pq When you have two
possibilities and you
~q ~p can rule one out,
the other must be
p q the case.
Example:
Suppose you know that for a particular number x,
x – 3 = 0 or x + 2 = 0
If you also know that x is not negative, then x -2, so
by elimination you can conclude that x = 3.
67
2.3.4.4. Rules of Inference: Transitivity
The following argument form is valid.
pq Many arguments in mathematics contain
chains of if-then statements.
qr From the fact that one statement implies a
second and the second implies the third,
pr you can conclude that the first statement
implies the third.
Example:
If 18,486 is divisible by 18, then 18,486 is divisible by 9.
If 18,486 is divisible by 9, then the sum of the digits of
18,486 is divisible by 9.
If 18,486 is divisible by 18, then the sum of the digits
of 18,486 is divisible by 9.
68
2.3.4.5. Rules of Inference: Proof by Division into Cases
r
Example:
Suppose you know that x is a nonzero real x is positive or x is negative.
number. If x is positive, then x2 > 0.
The trichotomy property of the real If x is negative, then x2 > 0.
numbers says that any number is positive, x2 > 0.
negative, or zero. Thus (by elimination) you
know that x is positive or negative.
You can deduce that x2 > 0 by arguing as
follows: 66
2.3.4.6. Rules of Inference: Example
You are about to leave for school in the morning and discover
that you don’t have your glasses. You know the following
statements are true:
a. If I was reading the newspaper in the kitchen, then my glasses are on
the kitchen table.
b. If my glasses are on the kitchen table, then I saw them at breakfast.
c. I did not see my glasses at breakfast.
d. I was reading the newspaper in the living room or I was reading the
newspaper in the kitchen.
e. If I was reading the newspaper in the living room then my glasses are
on the coffee table.
68
2.3.5. Fallacies
72
Fallacies
For an argument to be valid, every argument
of the same form whose premises are all true
must have a true conclusion.
It follows that for an argument to be invalid
means that there is an argument of that form
whose premises are all true and whose
conclusion is false.
73
2.3.5.1. Fallacies: Converse Error
Example:
If Zeke is a cheater, then Zeke sits in the back row.
Zeke sits in the back row.
Zeke is a cheater.
pq qp
q q
p p
75
2.3.5.3. Fallacies: A Valid Argument with a False
Premise and a False Conclusion
76
2.3.5.4. Fallacies: An Invalid Argument with True
Premises and a True Conclusion
77
2.3.5.5. Fallacies: Sound and Unsound Arguments
78
2.3.6. Contradictions and Valid Arguments
Contradiction Rule
If you can show that the supposition that statement
p is false leads logically to a contradiction, then you
can conclude that p is true.
79
Contradictions and Valid Arguments: Example –
Contradiction Rule
Show that the following argument form is valid:
~p c where c is a contradiction
p
premise conclusion
Only one critical row, and
p ~p c ~p c p in this row the conclusion
T F F T T is true.
Hence this form of
F T F F argument is valid.
80
Contradictions and Valid Arguments: Example –
Contradiction Rule
81
2.3.7. Summary of Rules of Inference
Table 2.3.1 Rule of inference
Modus Ponens pq
p
q
Modus Tollens pq
~q
~p
Generalization p q
pq pq
Specialization pq pq
p q
Conjunction p
q
pq
82
2.3.7. Summary of Rules of Inference
Table 2.3.1 Rule of inference
(cont’d) Elimination pq pq
~q ~p
p q
Transitivity pq
qr
pr
Proof by Division pq
Into Cases pr
qr
r
Contradiction Rule ~p c
p
83
DISCRETE STRUCTURES
7
Predicates and Quantified Statements I
When an element in the domain of the variable of a
one-variable predicate is substituted for the variable,
the resulting statement is either true or false. The set
of all such elements that make the predicate true is
called the truth set of the predicate.
6
3.1.2. The Universal Quantifier:
One sure way to change predicates into statements is
to assign specific values to all their variables.
1
0
The Universal Quantifier:
Quantifiers are words that refer to quantities such as
“some” or “all” and tell for how many elements a
given predicate is true.
The symbol denotes “for all” (or “for any”, “for
every”, “for each”) and is called the universal quantifier.
Definition 3.1.3 (Universal Statement)
Let Q(x) be a predicate and D the domain of x. A universal
statement is a statement of the form “x D, Q(x)”.
It is defined to be true iff Q(x) is true for every x in D.
It is defined to be false iff Q(x) is false for at least one x in D. A
value for x for which Q(x) is false is called a counterexample.
11
The Universal Quantifier: Truth and Falsity of Universal
Statements
Truth and Falsity of Universal Statements
a. Let D = {1, 2, 3, 4, 5}, and consider the statement
x D, x2 x.
Show that this statement is true.
10
3.1.3. The Existential Quantifier:
Example: “There is a student in CS1231” can be
written as
a person p such that p is a student in CS1231.
Or, more formally,
p P such that p is a student in CS1231.
where P is the set of all people.
The words such that are inserted just before the
predicate. Some alternative expressions for “there
exists” are “there is a”, “we can find a”, “there is at least
one”, “for some”, and “for at least one”.
14
The Existential Quantifier:
Sentences that are quantified existentially are defined
as statements by giving them the truth values
specified in the following definition.
Definition 3.1.4 (Existential Statement)
Let Q(x) be a predicate and D the domain of x. An existential
statement is a statement of the form “x D such that Q(x)”.
It is defined to be true iff Q(x) is true for at least one x in D.
It is defined to be false iff Q(x) is false for all x in D.
15
The Existential Quantifier: Truth and Falsity of Existential
Statements
Truth and Falsity of Existential Statements
a. Show that the following statement is true.
m Z+ such that m2 = m.
Observe that 12 = 1. Thus “m2 = m” is true for at least one
integer m. Hence “m Z+ such that m2 = m” is true.
b. x R, x2 -1. All real numbers have squares that are not -1.
No real numbers have squares equal to -1.
c. m Z+ such that m2 = m.
There is a positive integer whose square is itself.
We can find at least one positive integer equal to its own square.
Some positive integer equals its own square.
17
3.1.5. Universal Conditional Statements
A reasonable argument can be made that the most
important form of statement in mathematics is the
universal conditional statement:
18
Universal Conditional Statements Quick Quiz
19
3.1.6. Equivalent Forms of Universal and Existential
Statements
Are these the same?
real numbers x, if x is an integers x, x is rational.
integer then x is rational.
20
Equivalent Forms of Universal and Existential Statements
21
Equivalent Forms of Universal and Existential Statements
Similarly,
x such that P(x) and Q(x)
19
Equivalent Forms of Universal and Existential Statements
a. n such that .
b. n such that .
20
3.1.7. Implicit Quantification
Mathematical writing contains many examples of implicitly
quantified statements. Some occur, through the presence
of the word a or an. Others occur in cases where the
general context of a sentence supplies part of its meaning.
24
Implicit Quantification: Using => and <=>
Mathematicians often use a double arrow to indicate
implicit quantification symbolically.
For instance, they might express the above statement as
x > 2 x2 > 4
Notation
Let P(x) and Q(x) be predicates and suppose the common
domain of x is D.
The notation P(x) Q(x) means that every element in the
truth set of P(x) is in the truth set of Q(x), or, equivalently,
x, P(x) Q(x).
The notation P(x) Q(x) means that P(x) and Q(x) have
identical truth sets, or, equivalently, x, P(x) Q(x).
25
Implicit Quantification: Using => and <=>
Let
Q(n) be “n is a factor of 8”,
R(n) be “n is a factor of 4”,
S(n) be “n < 5 and n 3”,
and suppose the domain of n is Z+, the set of positive
integers.
Use the and symbols to indicate true relationship
among Q(n), R(n), and S(n).
26
Implicit Quantification: Using => and <=>
1. The truth set of Q(n) is {1,2,4,8} Q(n) be “n is a factor of 8”,
and the truth set of R(n) is {1,2,4}. R(n) be “n is a factor of 4”,
S(n) be “n < 5 and n 3”
Thus it is true that every element in the truth
set of R(n) is in the truth set of Q(n), or,
n in Z+, R(n) Q(n)
so R(n) Q(n)
Or, equivalently,
n is a factor of 4 n is a factor of 8
27
Implicit Quantification: Using => and <=>
2. The truth set of S(n) is {1,2,4} Q(n) be “n is a factor of 8”,
which is the same as the truth R(n) be “n is a factor of 4”,
set of R(n), or S(n) be “n < 5 and n 3”
Or, equivalently,
n is a factor of 4 n < 5 and n 3.
28
3.1.8. Tarski’s World
29
Tarski’s World
The program for Tarski’s World provides pictures of blocks of various
sizes, shapes, and colors, which are located on a grid.
Shown in Figure 3.1.1 is a picture of an arrangement of
objects in a two-dimensional Tarski world.
Figure 3.1.1
30
Tarski’s World
31
Tarski’s World
34
Negations of Quantified Statements: Negation of an
Existential Statement
Theorem 3.2.2 Negation of an Existential Statement
The negation of a statement of the form
x in D such that P(x)
is logically equivalent to a statement of the form
x in D, ~P(x)
Symbolically,
~(x in D such that P(x)) x in D, ~P(x)
That is, the negation of an existential statement (“some
are”) is logically equivalent to a universal statement
(“none are” or “all are not”).
35
Negations of Quantified Statements: Quick Quiz
33
3.2.2. Negations of Universal Conditional Statements
34
Negations of Universal Conditional Statements: Quick
Quiz
35
3.2.3. The Relation among ∀ , ∃ , ∧ , and ∨
The negation of a for all statement is a there exists
statement, and the negation of a there exists
statement is a for all statement.
These facts are analogous to De Morgan’s laws,
which state that the negation of an and statement
is an or statement and that the negation of an or
statement is an and statement.
This similarity is not accidental. In a sense,
universal statements are generalizations of and
statements, and existential statements are
generalizations of or statements.
39
The Relation among ∀ , ∃ , ∧ , and ∨
If Q(x) is a predicate and the domain D of x is the set
{x1, x2 ,…, xn}, then
x D, Q(x) Q(x1) Q(x2) Q(xn)
40
3.2.4. Vacuous Truth of Universal Statements
Suppose a bowl sits on a table and next to the
bowl is a pile of five blue and five gray balls, any
of which may be placed in the bowl.
If three blue balls and one gray ball are placed in
the bowl, as shown in Figure 3.2.1(a), the
statement “All the balls in the bowl are blue”
would be false (since one of the balls in the bowl
Figure 3.2.1(a)
is gray).
41
Vacuous Truth of Universal Statements
Is the statement true or false? The statement is false if, and
only if, its negation is true.
And its negation is
There exists a ball in the bowl that is not blue.
But the only way this negation can be true is for there
actually to be a non-blue ball in the bowl.
And there is not! Hence the negation is false, and so the
statement is true “by default”.
In general, a statement of the form
x in D, if P(x) then Q(x)
is called vacuously true or true by default
if, and only if, P(x) is false for every x in D.
42
3.2.5. Variants of Universal Conditional Statements
We have known that a conditional statement has a
contrapositive, a converse, and an inverse.
The definitions of these terms can be extended to
universal conditional statements.
Definition 3.2.1 (Contrapositive, converse, inverse)
43
Variants of Universal Conditional Statements
Write a formal and an informal contrapositive, converse, and
inverse for the following statement:
If a real number is greater than 2, then its square is greater than 4.
The formal version: x R, if x > 2 then x2 > 4.
Contrapositive: x R, if x2 4 then x 2.
If the square of a real number is less than or equal to 4, then the number is
less than or equal to 2.
Converse:
Inverse:
41
Variants of Universal Conditional Statements
Let P(x) and Q(x) be any predicates, let D be the domain of x,
and consider the statement:
x D, if P(x) then Q(x)
and its contrapositive
x D, if ~Q(x) then ~P(x)
Any particular x in D that makes “if P(x) then Q(x)” true also
makes “if ~Q(x) then ~P(x)” true (by the logical equivalence
between p q and ~q ~p).
It follows that “if P(x) then Q(x)” is true for all x in D iff “if ~Q(x)
then ~P(x)” is true for all x in D.
46
3.2.6. Necessary and Sufficient Conditions, Only if
The definitions of necessary, sufficient, and only if can
also be extended to apply to universal conditional
statements.
Definition 3.2.2 (Necessary and Sufficient conditions, Only if)
47
Necessary and Sufficient Conditions, Only if
Rewrite the following statements as quantified
conditional statements. Do not use the word necessary
or sufficient:
a. Squareness is a sufficient condition for rectangularity.
x, if x is a square, then x is a rectangle.
Informal: If a figure is a square, then it is a rectangle.
b. Being at least 35 years old is a necessary condition for being
President of the United States.
45
3.3 Statements with Multiple
Quantifiers
50
3.3.1. Interpreting Multiply-Quantified Statements
If you want to establish the truth of a statement of the form:
∀x in D, ∃y in E such that P(x, y)
your challenge is to allow someone else to pick whatever
element x in D they wish and then you must find an element y
in E that “works” for that particular x.
51
Interpreting Multiply-Quantified Statements
A college cafeteria line has four stations: salads, main courses,
desserts, and beverages.
The salad station offers a choice of green salad or fruit salad; the main
course station offers spaghetti or fish; the dessert station offers pie or
cake; and the beverage station offers milk, soda, or coffee. Three
students, Uta, Tim, and Yuen, go through the line and make the
following choices:
Uta: green salad, spaghetti, pie, milk
Tim: fruit salad, fish, pie, milk, coffee
Yuen: spaghetti, fish, pie, soda
52
Interpreting Multiply-Quantified Statements
These choices are illustrated in Figure 3.3.2.
Figure 3.3.2
53
Interpreting Multiply-Quantified Statements
Write each of following statements informally and find its
truth value.
1. an item I such that students S, S chose I.
There is an item that was chosen by every student. True of false?
2. a student S such that items I, S chose I.
55
3.3.3. Ambiguous Language
You are visiting a computer microchips factory. The factory guide
tells you:
There is a person supervising every detail of the
production process.
“there is” – existential quantifier; “every” – universal quantifier.
Which of the following best describes its meaning?
There is one single person who supervises all the details of the
production process.
For any particular production detail, there is a person who
supervises the detail, but there might be different supervisors
for different details.
56
Ambiguous Language
Once you interpreted the sentence in one way, it may have been
hard for you to see that it could be understood in the other way.
Perhaps you had difficulty even though the two possible
meanings were explained.
Although statements written informally may be open to multiple
interpretations, we cannot determine their truth or falsity
without interpreting them one way or another.
57
3.3.4. Negations of Multiply-Quantified Statements
Recall in 3.2.1: ~(x in D, P(x)) x in D such that ~P(x)
~(x in D such that P(x)) x in D, ~P(x)
(A) So, to find: ∼(∀x in D, ∃y in E such that P(x, y))
∃x in D such that ∼(∃y in E such that P(x, y))
∃x in D such that ∀y in E, ∼P(x, y).
∼(∀x in D, ∃y in E such that P(x, y)) ∃x in D such that ∀y in E, ∼P(x, y)
58
Negations of Multiply-Quantified Statements
Refer to the Tarski’s world of Figure 3.3.1
again.
Write a negation for each of the
following statements, and determine
which is true, the given statement or
its negation.
a. For all squares x, there is a circle y
such that x and y have the same color. Figure 3.3.1
Negation:
a square x such that ~( a circle y such that x and y have the
same color)
a square x such that circles y, x and y do not have the
same color. TRUE (Square e is black and no circle is black).
59
Negations of Multiply-Quantified Statements
57
3.3.5. Order of Quantifiers
62
Order of Quantifiers
Refer to the Tarski’s world of Figure 3.3.1. What are the truth
values of the following two statements?
a. For every square x, there is a triangle y
such that x and y have different colors.
60
3.3.6. Formal Logical Notation
64
Formal Logical Notation: Formalizing Statements in a
Tarski’s World
Example:
Tarski’s world.
Let the common domain D of all variables be the set of all the
objects in the Tarski’s world.
Triangle(x): “x is a triangle” Blue(x): “x is blue”
Circle(x): “x is a circle” Gray(x): “x is gray”
Square(x): “x is a square” Black(x): “x is black”
RightOf(x,y): “x is to the right of y”
Above(x,y): “x is above y”
SameColorAs(x,y): “x has the same color as y”
x = y: “x is equal to y”
65
Formal Logical Notation: Formalizing Statements in a
Tarski’s World
Use formal, logical notation to write the following statements,
and write a formal negation for each statement.
a. For all circles x, x is above f.
Statement: x (Circle(x) Above(x, f))
Negation:
67
Formal Logical Notation: Formalizing Statements in a
Tarski’s World
Use formal, logical notation to write the following statements,
and write a formal negation for each statement.
d. There is a square x such that for all triangles y, x is to right of y.
Statement:
Negation:
68
Formal Logical Notation
Formal logical notation is used in branches of computer science such as
artificial intelligence, program verification, and automata theory and
formal languages.
Taken together, the symbols for quantifiers, variables, predicates, and
logical connectives make up what is known as the language of first-
order logic.
Even though this language is simpler in many respects than the
language we use every day, learning it requires the same kind of practice
needed to acquire any foreign language.
69
3.3.7. Prolog
The programming language Prolog (short for programming in logic)
was developed in France in the 1970s by A. Colmerauer and P.
Roussel to help programmers working in the field of artificial
intelligence.
A simple Prolog program consists of a set of statements describing
some situation together with questions about the situation. Built
into the language are search and inference techniques needed to
answer the questions by deriving the answers from the given
statements.
This frees the programmer from the necessity of having to write
separate programs to answer each type of question.
70
Prolog: A Prolog Program
Consider the following picture, which shows colored blocks
stacked on a table.
71
Prolog: A Prolog Program
b. ?color(w1, X)
c. ?color(X, blue)
76
3.4.2. Universal Modus Ponens
The rule of universal instantiation can be combined with
modus ponens to obtain the valid form of argument
called universal modus ponens.
Universal Modus Ponens
Formal version Informal version
x, if P(x) then Q(x). If x makes P(x) true, then x makes Q(x) true.
P(a) for a particular a. a makes P(x) true.
Q(a). a makes Q(x) true.
77
Recognizing Universal Modus Ponens
Rewrite the following argument using quantifiers, variables,
and predicate symbols. Is this argument valid? Why?
If an integer is even, then its square is even.
k is a particular integer that is even.
k2 is even.
Solution:
Premise: x, if x is an even integer then x2 is even.
Let E(x) be “x is an even integer”, let S(x) be “x2 is even”, and
let k stand for a particular integer that is even.
x, if E(x) then S(x) . This argument has the form of
E(x), for a particular k. universal modus ponens and
S(k). is therefore valid.
78
3.4.3. Use of Universal Modus Ponens in a Proof
79
Use of Universal Modus Ponens in a Proof
80
Use of Universal Modus Ponens in a Proof
How universal modus ponens is used in the proof.
Hence
m + n = 2r + 2s = 2(r + s) (3)
(3) If a quantity is an integer, then it is a real number.
r and s are particular integers.
r and s are real numbers.
82
3.4.4. Universal Modus Tollens
Another crucially important rule of inference is universal
modus tollens. Its validity results from combining
universal instantiation with modus tollens.
Universal modus tollens is the heart of proof of
contradiction.
Universal Modus Tollens
Formal version Informal version
x, if P(x) then Q(x). If x makes P(x) true, then x makes Q(x) true.
~Q(a) for a particular a. a does not make Q(x) true.
~P(a). a does not makes P(x) true.
83
Recognizing Universal Modus Tollens
Rewrite the following argument using quantifiers, variables, and
predicate symbols. Write the major premise in conditional form.
Is this argument valid? Why?
All human beings are mortal.
Zeus is not mortal.
Zeus is not human.
Solution:
Premise: x, if x is human then x is mortal.
85
3.4.6. Using Diagrams to Test for Validity
Consider the statement: All integers are rational numbers.
integers n, n is a rational number.
Figure 3.4.1
86
Using Diagrams to Test for Validity
Use a diagram to show the invalidity of the following
argument:
All human beings are mortal.
Felix is mortal.
Felix is a human being.
Figure 3.4.4
87
Using Diagrams to Test for Validity
Use a diagram to show the invalidity of the following
argument:
All human beings are mortal. Hence,
Felix is mortal. argument
Felix is a human being. is invalid.
Conclusion Conclusion
is true. is false.
Figure 3.4.5
88
Using Diagrams to Test for Validity
The argument of previous example would be valid if the
major premise were replaced by its converse. But since a
universal conditional statement is not logically equivalent to
its converse, such a replacement cannot, in general, be
made.
We say that this argument exhibit the converse error.
Converse Error (Quantified Form)
Formal version Informal version
x, if P(x) then Q(x). If x makes P(x) true, then x makes Q(x) true.
Q(a) for a particular a. a makes Q(x) true.
P(a). a makes P(x) true.
89
Using Diagrams to Test for Validity
The following form of argument would be valid if a
conditional statement were logically equivalent to its inverse.
But it is not, and the argument form is invalid.
90
An Argument with “No
Use diagrams to test the following argument for validity:
No polynomial functions have horizontal asymptotes.
This function has a horizontal asymptote.
• This function is not a polynomial function.
Hence argument
is valid.
Figure 3.4.6
91
An Argument with “No
93
Creating Additional Forms of Argument
Consider the following argument:
p q
q r
p r
95
Evaluating an Argument for Tarski’s World
Consider the Tarski’s world:
99
Remark on the Converser and Inverse Errors
For instance, suppose a doctor knows that Only for
For all x, if x has pneumonia, then x has a fever and reading.
chills, coughs deeply, and feels exceptionally tired
and miserable.
And suppose the doctor also knows that
John has a fever and chills, coughs deeply,
and feels exceptionally tired and miserable.
On the basis of these data, the doctor concludes that a diagnosis of
pneumonia is a strong possibility, though not a certainty.
Proof Techniques
Acknowledgement
Pierre de Fermat,
1601 — 1665
Reading
Sections 2.1 — 2.7 of Campbell
Sections 4.1 — 4.3, 4.7 of Epp
Introduction by Construction if-then for-all by Contraposition by Contradiction Summary
1.1.1. Notation
We begin our study of proofs by recalling the following notations:
Additional notations:
∀y ∈ R, ∃!z ∈ R s y + z = 0
For all real numbers y, there is a unique real z such that y + z = 0.
or
Every real number y has exactly one real z such that y + z = 0.
Introduction by Construction if-then for-all by Contraposition by Contradiction Summary
Questions:
• Is 1353 colorful?
• What about (208 − 201)?
• 0?
Introduction by Construction if-then for-all by Contraposition by Contradiction Summary
Answer
• Yes, 1353 is colorful because 1353 = 3 × 451.
• No, because 208 − 201 = 7, and there is no integer k such
that 7 = 3k. (See Example 7: Proposition 1.6.2)
• Yes, 0 is colorful because 0 = 3 × 0.
Introduction by Construction if-then for-all by Contraposition by Contradiction Summary
Proof:
1. Note that 1000 ∈ Z and 1000 > 2.
2. Also, 10002 − 5(1000) + 6 = 995006 > 0.
QED1
1
quot erat demonstrandum — that which was to be demonstrated.
Introduction by Construction if-then for-all by Contraposition by Contradiction Summary
Existence Proof 2
Prove that there exist irrational numbers p and q such pq is
rational.
Proof:
1.2.3. Disproof
• To disprove a statement, you are arguing why the statement is
not true.
• You may use the same type of argument as in a proof. But
sometimes, it is easier just to show a counterexample.
Example
Disprove this statement:
∀x, y ∈ Z+, 𝑥 + 𝑦 = 𝑥 + 𝑦 .
In other words, for all positive integers x and y ,
𝑥 + 𝑦 = 𝑥 + 𝑦.
Disproof
if P then Q
One strategy is to use a direct proof: assume P is true, then
combine this with other known facts F and theorems T to
conclude that Q must be true.
In your final, polished proof, you must argue only forwards, not
backwards.
Introduction by Construction if-then for-all by Contraposition by Contradiction Summary
Example
Prove that:
if x,y are colorful integers, then so is x + 2y.
Identify P and Q to be:
P : x,y are colorful integers
Q : x + 2y is colorful
We can immediately write down the start and end of the proof, as
follows:
Draft proof:
1. Assume that x,y are colorful integers.
2. ...
3. And thus x + 2y is colorful. QED.
Introduction by Construction if-then for-all by Contraposition by Contradiction Summary
x + 2y = 3a + 2(3b), by substitution
= 3a + (2 ·3)b, by associativity
= 3a + (3 ·2)b, by commutativity
= 3a + 3(2b), by associativity
= 3(a + 2b), by distributivity
Proof.
1. Assume that x,y are colorful integers.
2. Then by definition of colorful, ∃a,b ∈ Z such that x = 3a
and y = 3b.
3. Now, x + 2y = 3a + 2(3b), by substitution
4. = 3a + 3(2b), by commutativity and associativity
5. = 3(a + 2b), by distributivity
6. Let c = a + 2b. Note that a + 2b ∈ Z because integers
are closed under addition and multiplication.
7. So ∃c ∈ Z such that x + 2y = 3c.
8. And thus x + 2y is colorful, by definition of colorful.□
1.3.2. Divisibility
Definition 1.3.1 (Divisibility)
More examples
• For integers a,b,c, it is clear that if a | b and a | c, then
a | (b + c). Reason: if a is a factor of b and c, then it is a
factor of the sum.
Trivial example: 2 | 6 and 2 | 8. Also, 2 | (6 + 8).
• But the inverse is not true. That is, if a ∤b and a ∤c, then it
is still possible to have a | (b + c).
Trivial example: 3 ∤10 and 3 ∤14, but 3 | (10 + 14).
• Finally, it should be obvious that a | ab, for any b.
Warning!
Do NOT use division. There is no concept of division in Number
Theory. The notation a | b simply means a is a factor of b. No
actual division is performed.
Introduction by Construction if-then for-all by Contraposition by Contradiction Summary
Note that the theorem is silent for the case b = 0, because 0 is not
positive.
Introduction by Construction if-then for-all by Contraposition by Contradiction Summary
Givens Goals
a,b ∈ Z+ a≤b
a|b
Introduction by Construction if-then for-all by Contraposition by Contradiction Summary
Givens Goals
a,b ∈ Z+ a≤b
a|b
b = ak, for some k ∈ Z
Proof.
1. Assume a,b ∈ Z+ , and a | b.
2. So by definition of divisibility, b = ak for some k ∈ Z.
3. Since a,b > 0, and b = ak, we deduce k is positive by
rule T25 of Appendix A (Epp).
4. Thus 1 ≤ k.
5. Using rule T20, multiply the inequality by a to get
a ≤ ak = b □.
Introduction by Construction if-then for-all by Contraposition by Contradiction Summary
1. Suppose a | b and a | c.
2. Then ax = b and ay = c for any integers x and y.
3. Then bx + cy = (ax)x + (ay)y = a(xx + yy).
4. Since x and y are any integers and the integers are
closed under addition and multiplication, we know that
(xx + yy) ∈ Z.
5. Thus a | (bx + cy). QED.
Introduction by Construction if-then for-all by Contraposition by Contradiction Summary
∀x P(x)
Proof.
1. Take any three integers a,b,c.
2. Assume that a | b and b | c.
3. Then by definition of divisibility, we know that b = ar
and c = bs, for some r ,s ∈ Z
4. Thus, c = (ar )s = a(rs), by basic algebra
5. Now, rs is an integer, by closure of integers
6. ∴ a | c, by definition of divisibility
7. Since a,b, c was chosen arbitrarily, the statement is true for
all integers. □
Introduction by Construction if-then for-all by Contraposition by Contradiction Summary
Remarks:
• We will usually omit Line 7, since it is understood.
• For Line 1, if instead we had said: Take positive integers
a,b, c, then the proof would still be valid until Line 6. But in
Line 7, we would not be able to generalize to all integers,
because our proof thus far was valid only for positive integers.
• Likewise, we cannot assume a ≤ b or b ≤ c or a ≤ c, since
this is an unnecessary restriction.
• Another common mistake is to say, in Line 3: b = ar and
c = br. This forces b and c to be the same multiple, which
again restricts our proof.
Introduction by Construction if-then for-all by Contraposition by Contradiction Summary
Both statements are logically equivalent; that is, they are True and
False for exactly the same truth values of P and Q.
Proof.
Contrapositive form: if x is rational then x 2 is rational
1. Assume x is rational.
2. Then by definition of rationals, there exist integers a,b
such that b /= 0 and x = a/b.
3. So x 2 = (a ·a)/(b ·b), by basic algebra
4. Both numerator and denominator are integers, by the
closure property of integers.
5. Moreover, by rule T21 of Appendix A (Epp), b2 /= 0.
6. Thus, x 2 is a ratio of two integers.
7. Thus, by definition of rationals, x 2 is rational. □
Introduction by Construction if-then for-all by Contraposition by Contradiction Summary
Remarks:
• To prove the statement directly, you would have to start by
assuming x 2 is irrational. That is, x 2 ≠ a/b for all integer a
and nonzero integer b.
Remarks:
• To prove a statement S by contradiction, you first assume
that ∼ S is true. Based on this, you use known facts and
theorems to arrive at a contradiction. Since every step of your
argument thus far is logically correct, the problem must lie in
your assumption. Thus, you conclude that ∼ S is false, and
hence S is true.
• A formal definition of contradiction will be given in the
chapter on logic; for now, it suffices to say that a
contradiction is something that is logically impossible. For
example, at the start of your proof, you may assume (or
deduce) that x ≥ 5. Then later you deduce that x < 5. These
two facts are clearly contradictory.
• In a proof by contradiction, the contradictory facts need not
be directly related to S. As long as you contradict any known
thing in mathematics, eg. 1 = 0, your proof has succeeded.
Introduction by Construction if-then for-all by Contraposition by Contradiction Summary
Examples:
Proof by contradiction
proof cont’d
Proposition 1.6.2
7 is not colorful.
Proof.
[Proof by contradiction]
1. Suppose 7 is colorful.
2. Then, by definition of colorful, 7 = 3k for some integer k.
3. ⇒ 6 = 3k − 1, by basic algebra.
4. ⇒ 1 = 3(k − 2), by basic algebra.
5. Since k − 2 is an integer by the closure property,
the above means that 3 | 1, by definition of divisibility.
6. Then by Theorem 4.3.1 (Epp), this means 3 ≤ 1.
7. Clearly, this is absurd, so the Proposition is true. □
Introduction by Construction if-then for-all by Contraposition by Contradiction Summary
Remarks:
• It is wrong to say: “7 is not colorful because 7/3 = 2.333...,
which is not an integer.” There is no concept of division in
Number Theory. Moreover, the definition of colorful does not
use division, but instead uses the existence of an integer.
• It is also wrong to say: “I cannot find an integer k such
7 = 3k, therefore 7 is not colorful.” If you cannot find it, it
doesn’t mean no such integer exists.
• The irrefutable way to prove the non-existence of something is
to show that if it exists, then it will lead to an absurd
conclusion. This is the essence of a proof by contradiction.
Introduction by Construction if-then for-all by Contraposition by Contradiction Summary
Summary
• Proofs are at the heart of mathematics.
• Proving a statement is like solving a jigsaw puzzle. No two
proofs are alike. Some strategies are useful.
• These lecture notes illustrate strategies for dealing with:
existence proofs, if-then and for-all statements, disproof by
counterexample, proof by contraposition and contradiction.
• For a given proof, which strategy to use will come with
experience. For longer proofs, multiple strategies may be
combined.
• Read Section 4.1 (pages 154 — 158) of the textbook for how
to correctly write a proof, and the common mistakes to avoid.
Use indentation to facilitate reading.
• Two more proof techniques — Induction and Diagonalization
— will be covered in future lectures.
DISCRETE STRUCTURES
Number Theory
Acknowledgement
Leopold Kronecker,
1823 — 1891
Reading
Sections 4.1 — 4.7 of Epp
Recap Primes
4.1. Recap
Definition 1.3.1 (Divisibility)
Theorem 4.1.1
∀a,b,c ∈ Z , if a | b and a | c, then ∀x,y ∈ Z ,a | (bx + cy)
Proof.
1. For any a,b,c ∈ Z :
2. If a | b and a | c:
3. Let k ∈ Z such that b = ak. (by definition of divisibility)
4. Let m ∈ Z such that c = am. (by definition of
divisibility)
5. For any x,y ∈ Z :
6. bx + cy = (ak)x + (am)y = a(kx + my).
(by basic algebra)
7. Note that kx + my ∈ Z . (by closure of addition
and multiplication over integers)
8. Thus a | bx + cy. (by definition of divisibility) □
Recap Primes
4.2. Primes
To see this, consider all positive pairs r , s such that n = rs. There
is always the trivial pairs r = n, s = 1, and r = 1, s = n. Note that
they satisfy 1 ≤ r,s ≤ n. But if these are the only pairs, then n is
prime by definition.
Note that this property does not hold for composites, e.g. 4 | 8 but
4 ≠ 8.
Recap Primes
Proof:
1. For any primes p and p':
2. If p | p':
3. Let k ∈ Z such that p' = pk, by definition of divisibility.
4. Then p = 1 or p = p', since p' is prime.
5. Also, p > 1, since p is prime.
6. Therefore p = p'. □
The next property of primes sets the stage for the important fact
that prime numbers do not end; ever larger primes exist.
Recap Primes
proof cont’d
• This proof shows that if you form the product of all primes up
to some point and add 1, the result, N, is divisible by a prime
not in the list.
• Note that this does not mean that N is prime. As an exercise,
try to find an N constructed in this way that is not prime.
Recap Primes
So now we know that primes do not end. Ever larger primes can
always be found.
Theorem 4.2.3
Thus, 17 | m.
Recap Primes
4.2.2. An application
Suppose you wish to send a message consisting of two positive
integers m, n to a friend. Unfortunately, the Send device can only
send a single integer, however large, but not two. The Receive
device is likewise limited to receiving only a single integer.
def decode(s):
# Repeatedly d i v i d e s by 2 , and count number o f times
# t h i s can be done. Do the same f o r 3 .
m= 0
while i s E v e n ( s ) :
s =s / 2
m= m+ 1
n= 0
while i s C o l o r f u l ( s ) :
s =s / 3
n = n + 1
return m,n
Recap Primes
def i s C o l o r f u l ( x ) :
# x i s c o l o r f u l i f i t s remainder i s 0
# when divided by 3
return x %3 == 0
Recap Primes
If not, then another random person is picked, and the trial is repeated
several times. If no Witness emerges, then the Suspect is probably a
Prime.
Recap Primes
Furthermore, the Miller-Rabin test does not tell you the factors of
the composite; it merely tells you if the integer is composite or
probably prime.
Terence Sim
Well Ordering Principle Quotient-Remainder Greatest Common Divisor Least Common Multiple
Answer:
• We may list all the elements of the set.
A = {−6, −5, . . . , 5, 6}. Thus, any integer less than or equal
to −6 is a lower bound.
• There is no lower bound. To see this, suppose not; suppose
the lower bound is some integer c. Then one of
c −1,c −2,c −3 must be divisible by 3. But all of them are
less than c, contradicting the fact that c is a lower bound.
• If x 2 ≤ 100x then x(x −100) ≤ 0, by basic algebra. Thus C
is the set of integers x such that 0 ≤ x ≤ 100. Thus any
integer m ≤ 0 is a lower bound.
Well Ordering Principle Quotient-Remainder Greatest Common Divisor Least Common Multiple
1
Text in green are corrections of errors.
Well Ordering Principle Quotient-Remainder Greatest Common Divisor Least Common Multiple
Examples: Does each set below have a least element? If so, what
is it? If not, explain why there is no violation of the Well Ordering
Principle.
• The set of all positive real numbers.
• The set of all non-negative integers n such that n2 < n.
• The set of all non-negative integers of the form 46 −7k,
where k is any integer.
Well Ordering Principle Quotient-Remainder Greatest Common Divisor Least Common Multiple
Answer:
• There is no least (smallest) positive real number. To see this,
suppose x ∈R + , then x/2 ∈R + and x/2 < x . There is no
violation of the Well Ordering Principle because the principle
concerns only sets of integers, not real numbers.
• This set is empty! Thus there is no least element, and no
violation of the Well Ordering Principle.
• Now, 46 −7k ≥ 0 implies 7k ≤ 46, which means k ≤ 6.57.
When k = 6, 46 −7(6) = 4, which is therefore the least
element.
Well Ordering Principle Quotient-Remainder Greatest Common Divisor Least Common Multiple
Proof:
1. Suppose x and z are two least elements in S:
2. Then ∀y ∈ S , x ≤ y, by definition of least element.
3. Since z ∈ S, this means x ≤ z [Universal instantiation].
4. Also, since z is a least element, then ∀w∈ S, z ≤ w, by
definition of least element.
5. And since x ∈ S, this means z ≤ x [Universal instantiation].
6. Now, (x ≤ z) ∧(z ≤ x) simplifies to x = z,
by the distributive and identity laws of logical
equivalences.
7. Thus the least element is unique. □
Well Ordering Principle Quotient-Remainder Greatest Common Divisor Least Common Multiple
Proof:
1. Let R be the set of “remainders”:
R = { x ∈ N | a = by + x for some y ∈ Z} .
2. (Claim: R is not empty.)
3. If a ≥ 0:
4. Then a = b ·0 + a ≥ 0, and thus a ∈ R .
5.Else a < 0: 6.
Then a −ab = a(1 −b) ≥ 0 [because a < 0 and (1 −b) ≤ 0,
so their product ≥ 0.]
7. Thus (a −ab) ∈ R by definition of R .
8. In either case, R has at least one element.
9. Thus R is a non-empty subset of integers, and there exists a least
element r ∈ R , by the Well Ordering Principle.
···
Well Ordering Principle Quotient-Remainder Greatest Common Divisor Least Common Multiple
proof cont’d
Examples: Find the quotient and remainder for each of the following.
• a = 54,b = 4
• a = −54,b = 4
• a = 54,b = 70
• 54 = 4 × 13 + 2, so q = 13,r = 2.
• −54 = 4 × (−14) + 2, so q = −14,r = 2.
• 54 = 70 × 0 + 54, so q = 0,r = 54.
In C/C++ and Java the integer division “/” computes the quotient,
while “%” computes the remainder. However, these do not give the
correct answer if a is negative, e.g. C gives q = −13, r = −2 when
a = −54,b = 4. Thus some caution is advised.
Well Ordering Principle Quotient-Remainder Greatest Common Divisor Least Common Multiple
Division Algorithm
def d i v i s i o n ( a , b ) :
#assumes a>=0, b > 0
q=0
r = a
while r >= b :
r = r - b
q = q + 1
return q , r
n = bq0 + r0
q0 = bq1 + r1
q1 = bq2 + r2
..
qm− 1 = bqm + rm
Well Ordering Principle Quotient-Remainder Greatest Common Divisor Least Common Multiple
𝑛 = 𝑟𝑖 𝑏𝑖
𝑖=0
𝑏
Note that the summation notation 𝑓(𝑖) is shorthand for:
𝑖=𝑎
f (a) + f (a + 1) + f (a + 2) + ... + f (b −1) + f (b)
The index i increments by 1 starting from the lower limit a and ending at
the upper limit b. It is assumed b ≥ a. If b < a, then the sum is empty,
which by default equals 0.
Likewise, a product of terms f (a) × f (a + 1) × ... × f (b −1) × f (b) is
more compactly written as:
𝑏
ෑ 𝑓(𝑖)
𝑖=𝑎
Again, it is assumed b ≥ a. And if b < a then the product is empty,
which by default equals 1.
Well Ordering Principle Quotient-Remainder Greatest Common Divisor Least Common Multiple
109 = 2 × 54 + 1
54 = 2 × 27 + 0
27 = 2 × 13 + 1
13 = 2 × 6 + 1
6 = 2×3+ 0
3 = 2×1+ 1
1 = 2×0+ 1
Here, we need new symbols to represent the decimal digits 10, 11, ...,15
in base 16. The usual convention is:
But a quicker way is to use the binary notation: starting from the right,
take the bits (binary digits) in groups of 4, and convert each group to
base 16 using this table:
0000 = 0 0001 = 1 0010 = 2 0011 = 3
0100 = 4 0101 = 5 0110 = 6 0111 = 7
1000 = 8 1001 = 9 1010 = A 1011 = B
1100 = C 1101 = D 1110 = E 1111 = F
(a) (10110101)2 = 27 + 25 + 24 + 22 + 20
= 128 + 32 + 16 + 4 + 1 = (181)10.
The greatest common divisor is also called the highest common factor.
More examples:
What is gcd(0,0) ?
Any integer k divides 0. Since there is no largest integer, there is
no largest common divisor.
Well Ordering Principle Quotient-Remainder Greatest Common Divisor Least Common Multiple
Proof:
1. Let D = { all common divisors of a,b} .
2. Clearly, 1 ∈ D , and D ⊆ Z.
3. By assumption, one of a, b is non-zero. Let it be a, since
gcd(a, b) = gcd(b, a) by its definition, so we can swap the numbers
to make a the non-zero number.
4. Also, |a| is an upper bound for D, since no common divisor of a, b
can be larger than this.
5. Thus by Well Ordering 2, there exists a greatest element d in D.
6. By Proposition 4.3.4, d is unique. □
Well Ordering Principle Quotient-Remainder Greatest Common Divisor Least Common Multiple
(i) gcd(a,0) = a.
For Line (ii), note that since a = bq + r , then any common divisor c of
a, b must divide r by Theorem 4.1.1 (r is a linear combination of a, b.)
Also, any common divisor of b, r must divide a for the same reason.
So (a, b) and (b, r) have the same set of common divisors, and thus their
gcd’s must be equal.
Well Ordering Principle Quotient-Remainder Greatest Common Divisor Least Common Multiple
def g c d ( I , CAN):
# assumes I > 0 , CAN>=0
# computes gcd using E u c l i d ’s algorithmm
return I
Well Ordering Principle Quotient-Remainder Greatest Common Divisor Least Common Multiple
6 = 18 −12 × 1 = 18 + 12 × (−1)
= 18 + (156 −18 × 8) × (−1) = 156 × (−1) + 18 × 9
= 156 × (−1) + (330 −156 × 2) × 9 = 330 × 9 + 156 × (−19)
The test is this: fill a large trough in the field with exactly 1 litre of river
water. Only two cans are available to scoop water from the river: one is
exactly 9 litres when full, the other 7.
Since the cans must be completely full or empty when transferring water,
Dueet is dealing with multiples of 7 and 9 litres. In other words, Dueet
needs to solve the equation:
9x + 7y = 1.
Thus, Dueet needs to pour in four cans of water into the trough using
the 9-litre can, and then scoop out five cans using the 7-litre can.
Well Ordering Principle Quotient-Remainder Greatest Common Divisor Least Common Multiple
Examples:
• 9 and 7 are coprime (from Aiken & Dueet’s puzzle).
• 10 and 100 are not coprime, since gcd(10,100) = 10.
• In fact, for any integer a > 1, a and ka are not coprime for
any integer k (because their gcd is a).
• Obviously, any two distinct primes p,q are coprime.
Well Ordering Principle Quotient-Remainder Greatest Common Divisor Least Common Multiple
Theorem 4.2.3
If p is a prime and x1, x2, ...,xn are any integers such that: p | x1x2 ...xn,
then p | xi , for some i (1 ≤ i ≤ n).
Proof:
(by Induction)
1. Let P(n) = ( (p | x1x2 ...xn ) −→ (p | xi for some i ∈ [1,n]) )
2. (Consider the base case n = 1:)
3. Clearly, P(1) is true.
···
Well Ordering Principle Quotient-Remainder Greatest Common Divisor Least Common Multiple
proof cont’d
proof cont’d
Proposition 4.5.5
For any integers a, b, not both zero, if c is a common divisor of a and b,
then c | gcd(a,b).
Proof:
Example:
gcd(30,45) = 15.
30 = 2 ·3 ·5
45 = 32 ·5.
Thus the common divisors are 1,3,5,15.
Prove that for all positive integers a,b, a | b if, and only if,
gcd(a,b) = a.
Proof:
The lcm of a, b exists because the Well Ordering Principle guarantees the
existence of the least element on the set of common multiples of a, b.
Examples: Find
• lcm(12,18)
• lcm(22 ·3 ·5, 23 ·32 )
• lcm(2800, 6125)
Well Ordering Principle Quotient-Remainder Greatest Common Divisor Least Common Multiple
Proof:
1. Take any non-zero integers a,b.
2. Let d =gcd(a,b), and m =lcm(a,b).
3. Then d | a and d | b, by definition of gcd.
4. Also, a | m and b | m, by definition of lcm.
5. Thus d | m, by the Transitivity of Divisibility (Theorem 4.3.3
(Epp)). □
Modulo Arithmetic Summary
Terence Sim
Modulo Arithmetic Summary
1
Text in green are the corrections of errors.
Modulo Arithmetic Summary
m ≡ n (mod d)
Answer:
• True. Clearly, 5 | (12 − 7).
• False. Because 4 ‡ (6 − (−8)).
• True. Since 7 | (3 − 3).
• True. Let d = gcd(a, b). Then d | (a − b) because d | a and d | b.
Modulo Arithmetic Summary
4.7.1. Arithmetic
Theorem 8.4.3 (Epp): Modulo Arithmetic
Let a,b, c, d and n be integers with n > 1, and suppose:
Then
1. (a + b) ≡ (c + d) (mod n)
2. (a − b) ≡ (c − d) (mod n)
3. ab ≡ cd (mod n)
4. am ≡ c m (mod n), for all positive integers m.
Modulo Arithmetic Summary
Proof:
or, equivalently,
Example:
Calculate: (a) 55 ·26 mod 4, (b) 1444 mod 713
Answer:
(a) 55 ·26 mod 4 = [(55 mod 4)(26 mod 4)] mod 4
= (3)(2) mod 4
= 6 mod 4
= 2
4.7.2. Inverses
Normal arithmetic has the Cancellation Law for Multiplication (T7 of
Appendix A (Epp)):
For integers a,b,c with a /= 0, if
(1) ab = ac
then b = c.
Example:
Clearly, 3 × 1 ≡ 3 × 5 (mod 6).
But, 1 ≢ 5 (mod 6).
Modulo Arithmetic Summary
Example:
Consider a = 5 and n = 9: By inspection, 5 ·2 ≡ 1
(mod 9), so 5 −1 = 2 mod 9.
Other multiplicative inverses include: 2+9 = 11, 2−9 =
−7, 2 + 900 = 902.
Modulo Arithmetic Summary
Given any integer a, its multiplicative inverse a −1 may not exist. This
next theorem tells us exactly when it exists.
Recall that two numbers are coprime, or relatively prime, iff their gcd is 1.
Note that the above tells us how to find a multiplicative inverse for a
modulo n: simply run the Extended Euclidean Algorithm!
Modulo Arithmetic Summary
Example:
Find 3 −1 mod 40.
Example:
Find 2 −1 mod 4.
Note that gcd(2, 4) = 2, so 2 and 4 are not coprime. Thus, by Theorem
4.7.3, 2 −1 does not exist.
2 ·1 ≡ 2 (mod 4),
2 ·2 ≡ 0 (mod 4),
2 ·3 ≡ 2 (mod 4).
Proof sketch
Since a and n are coprime, Theorem 4.7.3 guarantees the existence of a
multiplicative inverse a −1 .
Multiply both sides of ab ≡ ac (mod n) with a −1 gives the desired
answer.
Quiz: In T7 of Appendix A (Epp) (Cancellation Law for integers), it is
explicitly stated that a ≠ 0. Yet the above theorem doesn’t seem to
require this. Why not?
Modulo Arithmetic Summary
Example:
Solve the equation 5x + 13y = 75 for integers x,y.
1. Re-write: 5x = 75 − 13y.
2. Then 5x ≡ 75 (mod 13), by Theorem 8.4.1 (Epp).
3. Re-write: 5x ≡ 5 ·15 (mod 13).
4. Note that 5 and 13 are coprime.
5. Thus, x ≡ 15 (mod 13), by Theorem 8.4.9 (Epp).
6. Thus, x ≡ 2 (mod 13), because 15 mod 13 = 2.
7. So x = 2 is a solution.
8. Substituting back into the equation: 5(2) + 13y = 75.
9. And thus y = 5.
Other solutions include: (x, y) = (15, 0), (−11, 10), (28, −5).
Modulo Arithmetic Summary
4.8. Summary
5.1. Sequences
You may already be familiar with the following sequences:
N: 0, 1, 2, 3, 4, 5, . . .
Even numbers: 0, 2, 4, 6, 8, 10, . . .
Fibonacci: 0, 1, 1, 2, 3, 5, . . .
Sequences Summation & Product Common sequences Solving recurrences Application Summary
Examples:
Sequence Recurrence relation Initial conditions
Even numbers: an = an− 1 + 2 a0 = 0
Geometric: an = 2an−1 a0 = 1
Fibonacci: an = an− 1 + an− 2 a1 = 1,a0 = 0
Sequences Summation & Product Common sequences Solving recurrences Application Summary
Thus,
c2 = c1 + 2c0 + 1 = 2 + 2(1) + 1 = 5
c3 = c2 + 3c1 + 1 = 5 + 3(2) + 1 = 12
c4 = c3 + 4c2 + 1 = 12 + 4(5) + 1 = 33
Sequences Summation & Product Common sequences Solving recurrences Application Summary
def cTermR(n):
i f n < 2:
return n+1
else:
return cTermR(n-1) + n * cTermR(n-2) + 1
def cTermI(n):
i f n == 0 :
return 1
I = 2 # ) I n i t i a l conditions
CAN = 1 # )
DOIT = 2
while n > 1 :
( I , C A N ) = (I+CAN*DOIT+1,I) #Recurrence r e l a t i o n
DOIT = DOIT + 1
n= n - 1
return I
an = an− 1 + 2
𝑛
n(n + 1)
i= = Δ n.
𝑖=𝑚
2
This is the sum of the first n + 1 integers, starting from 0. It
generates the sequence called the Triangle numbers.
n 0 1 2 3 4 5 6
Δn 0 1 3 6 10 15 21
Sequences Summation & Product Common sequences Solving recurrences Application Summary
Example:
𝑛
ෑ i = n!
𝑖=𝑚
n 0 1 2 3 4 5 6
n! 1 1 2 6 24 120 720
0
Note that the formula above gives 0! = ෑ i = 1 because an empty
product defaults to 1. 𝑖=1
Sequences Summation & Product Common sequences Solving recurrences Application Summary
𝑛 0, 𝑖𝑓 𝑛 < 𝑚
𝑛−1
ෑ 𝑎𝑖 = ൞
ෑ 𝑎𝑖 . 𝑎𝑛 , 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
𝑖=𝑚 𝑖=𝑚
1Note: the cases when n < m are called the empty sum and
empty product, respectively. The empty sum is 0 by definition,
while the empty product is 1 by definition.
1
Things highlighted in green are the corrections of typos.
Sequences Summation & Product Common sequences Solving recurrences Application Summary
Example
𝑛+1 𝑘
Replace k with j = k − 1 in .
𝑘=1 𝑛 + 𝑘
Answer: since j = k − 1, so k = j + 1.
j+1
1. Replace k in the term: n+j+1
.
2. Change the lower limit: k = 1 becomes j + 1 = 1, so j = 0.
Change the upper limit: k = n + 1 becomes j + 1 = n + 1, so j = n
Thus:
𝑛+1 𝑛 𝑛
𝑘 𝑗+1 𝑘+1
= = .
𝑛+𝑘 𝑛+𝑗+1 𝑛+𝑘+1
𝑘=1 𝑗=0 𝑘=0
• Arithmetic sequence
• Geometric sequence
• Square numbers
• Triangle numbers
• Fibonacci numbers
• Binomial numbers
Sequences Summation & Product Common sequences Solving recurrences Application Summary
𝑎, 𝑖𝑓 𝑛 < 𝑚
∀𝑛 ∈ ℕ, 𝑎𝑛 = ቊ
𝑎𝑛−1 , 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
𝑎, 𝑖𝑓 𝑛 < 𝑚
∀𝑛 ∈ ℕ, 𝑎𝑛 = ቊ
𝑟𝑎𝑛−1 , 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
To see this, note that the positive odd numbers is an arithmetic sequence
with a = 1, d = 2. Using Equation (1) for the sum of an arithmetic
sequence:
n
∀n ∈ N, Sn = [2a + (n − 1)d]
2
= n [2(1) + (n − 1)(2)]
2
= n2
= □n.
Sequences Summation & Product Common sequences Solving recurrences Application Summary
∀n ∈ N, F0 = 0, F1 = 1,
Fn = Fn− 1 + Fn− 2
𝜙 𝑛 − (−𝜙)−𝑛
∀𝑛 ∈ ℕ, 𝐹𝑛 =
5
where 𝜙 = (1 + 5)/2) 2 ≈ 1.6180339887. . . is called the golden ratio.
Pascal’s triangle
Note that there are two indices in the triangle: the rows are indexed by n
from top to bottom, while the columns are indexed by r from left to right.
𝑛 𝑛!
∀n,r ∈ N such that r ≤ n, 𝑟
=
𝑟! 𝑛 − 𝑟 !
1 if r = 0 and n ≥ 0,
𝑛 𝑛−1 𝑛−1
∀n,r ∈ N, =൞ + , if 0 < r ≤ n,
𝑟 𝑟 𝑟−1
0 otherwise.
The second line above also says that adding two consecutive terms in one
row gives one term in the next row.
Sequences Summation & Product Common sequences Solving recurrences Application Summary
which says the sum of all possible ways to choose r things from n is 2n .
Now, 2n = 2 × 2n− 1
𝑛 𝑛−1
Thus, 𝑛 = 2 × 𝑛 − 1
𝑟 𝑟
𝑟=0 𝑟=0
That is, the sum of numbers in one row of the triangle is twice that of
the previous row.
Sequences Summation & Product Common sequences Solving recurrences Application Summary
1. Look it up.
2. Guess and check (aka iteration).
3. Use formula.
Sequences Summation & Product Common sequences Solving recurrences Application Summary
9781439835487
Sequences Summation & Product Common sequences Solving recurrences Application Summary
if k = 1,
∀k ∈ Z+ , mk =
{ 1,
2mk− 1 + 1, if k ≥ 2.
Sequences Summation & Product Common sequences Solving recurrences Application Summary
Solution:
m1 = 1
m2 = 2m1 + 1 = 2(1) + 1 = 2 + 1
m3 = 2m2 + 1 = 2(2 + 1) + 1 = 22 + 2 + 1
m4 = 2m3 + 1 = 2(22 + 2 + 1) + 1 = 23 + 22 + 2 + 1
m5 = 2m4 + 1 = 2(23 + 22 + 2 + 1) + 1 = 24 + 23 + 22 + 2 + 1
Thus, we may guess the formula: mn = 2n− 1 + 2n− 2 + ... + 21 + 20 .
1. Let P(n) = ( mn = 2n − 1 ), ∀n ∈ Z + .
2. m1 = 1, by the initial conditions.
3. Also, 21 − 1 = 1. Thus P(1) is true.
4. For any k ∈ Z + :
5. Assume P(k) is true.
6. That is, mk = 2k − 1.
7. Now, mk+1 = 2mk + 1, by the recurrence relation.
8. = 2(2k − 1) + 1, using the Inductive hypothesis.
9. = 2k+1 − 2 + 1 = 2k+1 − 1, so P(k + 1) is true.
10. Thus by Mathematical Induction, the statement is true. □
Sequences Summation & Product Common sequences Solving recurrences Application Summary
ak = Aak− 1 + Bak− 2 , ∀k ∈ Z ≥ k0
ak = Aak− 1 + Bak− 2
t2 − t − 1 = 0
1 ± 1 − 4(−1)
𝑡=
2
which yields distinct roots:
Fn = C 𝜙 n + D 𝜓 n , ∀n ∈ N
F0 = 0 = C 𝜙 0 + D 𝜓 0 = C + D
F1 = 1 = C 𝜙 1 + D 𝜓 1 = C 𝜙 + D 𝜓
These are two linear equations in two unknowns. Solving them gives:
C= 1/ 5, D=-1/ 5
Note that 𝜓 = −1/𝜙. We can thus write:
𝜙 𝑛 −(−𝜙) −𝑛
∀n ∈ N, Fn = .
5
Sequences Summation & Product Common sequences Solving recurrences Application Summary
ak = Aak− 1 + Bak− 2
an = Cr n + Dnr n , ∀n ∈ N
where C, D are real numbers determined by the value a0, and any other
known value of the sequence.
Proof omitted.
Sequences Summation & Product Common sequences Solving recurrences Application Summary
5.5. Application
Tower of Hanoi
E´duoard Lucas invented this puzzle in 1883. The goal is to move a set of
n disks of different sizes from one pole to another, subject to:
(i) Only one disk can be moved at a time.
(ii)At all times, no disk can rest on a smaller disk.
What is the minimum number of moves needed?
Sequences Summation & Product Common sequences Solving recurrences Application Summary
(c) After moving bottom disk (d) After moving k − 1 disks from
from A to C. B to C.
Sequences Summation & Product Common sequences Solving recurrences Application Summary
5. You can now move the bottom disk from A to C, using 1 move.
6. You then ask the genie to move the k − 1 disks from B to C, using
another m k−1 moves.
5.6. Summary
• Sequences are common in Computer Science. They can be
expressed either by an explicit closed-form formula, or by
recurrence relations plus some initial conditions.
• In either way, code can be written to generate the sequence.
• Common sequences include Arithmetic and Geometric
sequences, Square and Triangle numbers, Fibonacci, and
Binomial numbers.
• Sums and products of a sequence generate another sequence.
• Solving a recurrence relation may be done in several ways:
looking it up, guessing and checking, using a formula.
• Recurrence relations are important for analyzing the behavior
of algorithms and data structures.
DISCRETE STRUCTURES
Graphs
Acknowledgement
Graphs: Introduction
Graphs: Introduction
6
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Graphs: Introduction
Graphs: Introduction
7
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Graphs: Introduction
Map Colouring
Four-Colour Conjecture
Proposed by Guthrie in 1852, who conjectured that…
Four colours are sufficient to colour any map in a plane,
such that regions that share a common boundary do not
share the same colour.
Many false proofs since then.
Finally proved by Appel and Haken in 1977, with the help
of computer.
Robertson et al. provided another proof in 1996.
8
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Graphs: Introduction
Map Colouring
Example of a 4-
coloured map. World map with 4 colours.
1
0
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Definition: Graph
A graph G consists of 2 finite sets: a nonempty set V(G) of
vertices and a set E(G) of edges, where each edge is associated
with a set consisting of either one or two vertices called its
endpoints.
An edge is said to connect its endpoints; two vertices that are
connected by an edge are called adjacent vertices; and a vertex
that is an endpoint of a loop is said to be adjacent to itself.
An edge is said to be incident on each of its endpoints, and two
edges incident on the same endpoint are called adjacent edges.
We write e = {v, w} for an edge e incident on vertices v and w.
1
1
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Guy
Ven Sur
Col Fre
Bra
Ecu
Per
Bol Par
Chi Uru
Arg
Fal
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Guy
Ven Sur
Col Fre
Bra
Ecu
Per
Bol Par
Chi Uru
Arg
Fal
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Wedding Planner
You are your best friend’s wedding planner and you
need to plan the seating arrangement for his 16 guests
attending his wedding dinner. However, some of the
guests cannot get along with some others.
A doesn’t get along with F, G or H. You don’t want to put
B doesn’t get along with C, D or H. guests who cannot
C doesn’t get along with B, D, E, G or H. get along with each
D doesn’t get along with B, C or E. other at the same
E doesn’t get along with C, D, F, or G. table!
F doesn’t get along with A, E or G. How many tables do
G doesn’t get along with A, C, E or F. you need?
H doesn’t get along with A, B or C.
Acknowledgement: http://www.math.uri.edu/~eaton/0131873814_MEb.pdf 15
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Acknowledgement: http://www.math.uri.edu/~eaton/0131873814_MEb.pdf
16
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Special Graphs
Simple Graphs
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Special Graphs
Complete Graphs
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Special Graphs
K3,2 K2,5
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Special Graphs
Subgraph of a Graph
A graph G A subgraph
of G
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Corollary 10.1.2
The total degree of a graph is even.
Proposition 10.1.3
In any graph there are an even number of vertices of odd degree.
10.2 Trails, Paths, and
Circuits
Introduction
Introduction
Königsberg bridges
The subject of graph theory began in the year 1736
when the great mathematician Leonhard Euler
published a paper giving the solution to the following
puzzle:
The town of Königsberg in Prussia (now Kaliningrad in
Russia) was built at a point where two branches of the
Pregel River came together. It consisted of an island and
some land along the river banks.
These were connected by 7 bridges.
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Introduction
Königsberg bridges
Question: Is it possible to
take a walk around town,
starting and ending at
the same location and
crossing each of the 7
bridges exactly once?
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Introduction
Königsberg bridges
Definitions
Definitions
Travel in a graph is accomplished by moving from one
vertex to another along a sequence of adjacent edges.
In the graph below, for instance, you can go from u1 to
u4 by taking f1 to u2 and then f7 to u4. This is
represented by writing u1 f1 u2 f7 u4.
Definitions
Definitions
Definitions
Definitions
Definitions
Notes
Because most of the major developments in graph
theory have happened relatively recently and in a variety
of different contexts, the terms used in the subject have
not been standardized.
For example, what this book calls a graph is sometimes
called a multigraph, what this book calls a simple graph
is sometimes called a graph, what this book calls a vertex
is sometimes called a node, and what this book calls an
edge is sometimes called an arc.
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Definitions
Notes
Similarly, instead of the word trail, the word path is
sometimes used; instead of the word path, the words
simple path are sometimes used; and instead of the
words simple circuit, the word cycle is sometimes used.
The terminology in this book is among the most
common, but if you consult other sources, be sure to
check their definitions.
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Connectedness
Connectedness
Connectedness
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Connectedness
Connected Component
Connected Component
Connected Component
Connected Component
Euler Circuits
Euler Circuits
Euler Circuits
Euler Circuits
Theorem 10.2.2
If a graph has an Euler circuit, then every vertex of the graph has
positive even degree.
Euler Circuits
Euler Circuits
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Euler Circuits
Theorem 10.2.3
If a graph G is connected and the degree of every vertex of G is a
positive even integer, then G has an Euler circuit.
The proof of Theorem 10.2.3 is constructive: It contains an algorithm to find an
Euler circuit for any connected graph in which every vertex has even degree.
Theorem 10.2.4
A graph G has an Euler circuit if, and only if, G is connected and
every vertex of G has positive even degree.
A corollary to Theorem 10.2.4 gives a criterion for determining when it is
possible to find a walk from one vertex of a graph to another, passing through
every vertex of the graph at least once and every edge of the graph exactly
once.
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Euler Circuits
Corollary 10.2.5
Let G be a graph, and let v and w be two distinct vertices of G.
There is an Euler trail from v to w if, and only if, G is connected,
v and w have odd degree, and all other vertices of G have
positive even degree.
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Euler Circuits
(1) (5)
50
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Euler Circuits
The floor plan shown below is for a house that is open for public
viewing. Is it possible to find a trail that starts in room A, ends in
room B, and passes through every interior doorway of the house
exactly once? If so, find such a trail.
Each vertex of this graph has even degree except for A and B,
each of which has degree 1.
Hence by Corollary 10.2.5, there is an Euler path from A to B.
One such trail is AGHFEIHEKJDCB.
Hierholzer’s Algorithm for Identifying Eulerian Circuits
55
Example
56
57
Quiz
58
Fleury’s Algorithm for Identifying Eulerian Circuits
Chapter 9. Paths
12/30/2019 59
Quiz
60
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Hamiltonian Circuits
Hamiltonian Circuits
A related question:
Given a graph G, is it possible to find a circuit for G in
which all the vertices of G (except the first and the last)
appear exactly once?
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Hamiltonian Circuits
Hamiltonian Circuits
Hamiltonian Circuits
Hamiltonian Circuits
Hamiltonian Circuits
Hamiltonian Circuits
Hamiltonian Circuits
Hamiltonian Circuits
H is indicated by
the black lines.
Hamiltonian Circuits
The reason for this is that there are exactly two edges
incident on any vertex. These are ei and ei+1 for any
vertex vi except v0=vn, and they are e1 and en for v0 (=vn).
These observations have established the truth of the following
proposition in all cases where G has at least two vertices.
Proposition 10.2.6
If a graph G has a Hamiltonian circuit, then G has a subgraph H
with the following properties:
1. H contains every vertex of G.
2. H is connected.
3. H has the same number of edges as vertices.
4. Every vertex of H has degree 2.
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Hamiltonian Circuits
Matrices
Definition: Matrix
An m n (read “m by n”) matrix A over a set S is a rectangular
array of elements of S arranged into m row and n columns.
ith row of A
jth column of A
We write A = (𝑎 ij ).
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Matrices
If A and B are matrices, then A = B if, and only if, A and B have the
same size and the corresponding entries of A and B are all equal;
that is,
𝑎i j = 𝑏i j for all i = 1, 2, ⋯ , 𝑚 and j = 1, 2, ⋯ , 𝑘.
A matrix for which the numbers of rows and columns are equal is
called a square matrix.
If A is a square matrix of size n n, then the main diagonal of A
consists of all the entries 𝑎11 , 𝑎22 , ⋯ 𝑎𝑛 𝑛 .
main diagonal of A
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
(a) (b)
(a)
72
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Example: Find the adjacency matrix for the graph G shown below.
Adjacency matrix of G:
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Matrix Multiplication
Matrix Multiplication
Matrix Multiplication
where
𝑐i j = 𝑎i1 𝑏1 j + 𝑎i2 𝑏2 j + ⋯ + 𝑎ik 𝑏k j = ∑k𝑟=1 𝑎 i𝑟 𝑏 𝑟j .
for all i = 1, 2, …, m and j = 1, 2, …, n.
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Matrix Multiplication
Solution:
2 3
where
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Matrix Multiplication
Solution:
2 3
-2 -1
where
–2
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Matrix Multiplication
Matrix Multiplication
Identity Matrix
Matrix Multiplication
Matrix Multiplication
Matrix Multiplication
Matrix Multiplication
Solution:
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Compute A2:
Note that the entry in the second row and the second
column is 6, which equals the number of walks of
length 2 from v2 to v2.
Theorem 10.3.2
If G is a graph with vertices v1, v1, …, vm and A is the adjacency
matrix of G, then for each positive integer n and for all integers i, j
= 1, 2, …, m,
the ij-th entry of An = the number of walks of length n from vi to vj.
10.4 Isomorphims of Graphs
Isomorphisms of Graphs
Introduction
Figure 10.4.1
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Isomorphisms of Graphs
Isomorphisms of Graphs
Figure 10.4.3
Isomorphisms of Graphs
Two graphs that are the same except for the labeling of
their vertices and edges are called isomorphic.
Isomorphisms of Graphs
Isomorphisms of Graphs
100
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Isomorphisms of Graphs
110
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Isomorphisms of Graphs
Isomorphisms of Graphs
113
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
114
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
a.
b.
115
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
116
Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms
Yes.
Define g: V(G) → V(G) by the arrow diagram shown below.
Then g is one-to-one and onto by inspection.
117
DISCRETE STRUCTURES
Graphs
Acknowledgement
Definition
6
Trees Rooted Trees Spanning trees and Shortest Paths
Definition
Definition
Definition: Tree
A graph is said to be circuit-free if, and only if, it has no circuits.
A graph is called a tree if, and only if, it is circuit-free and
connected.
A trivial tree is a graph that consists of a single vertex.
A graph is called a forest if, and only if, it is circuit-free and not
connected.
7
Trees Rooted Trees Spanning trees and Shortest Paths
Examples
Possibility Tree
Examples
Parse Tree
9
Trees Rooted Trees Spanning trees and Shortest Paths
Examples
Parse Tree
Examples
Parse Tree
11
Trees Rooted Trees Spanning trees and Shortest Paths
Examples
Parse Tree
The derivation of the sentence “The young man caught the ball”
from the mentioned rules is described by the tree shown below:
12
Trees Rooted Trees Spanning trees and Shortest Paths
Characterizing Trees
Lemma 10.5.1
Any non-trivial tree has at least one vertex of degree 1.
Characterizing Trees
Lemma 10.5.1
Any non-trivial tree has at least one vertex of degree 1.
14
Trees Rooted Trees Spanning trees and Shortest Paths
Characterizing Trees
15
Trees Rooted Trees Spanning trees and Shortest Paths
Characterizing Trees
16
Trees Rooted Trees Spanning trees and Shortest Paths
Characterizing Trees
Theorem 10.5.2
Any tree with n vertices (n > 0) has n – 1 edges.
Characterizing Trees
Proof: (continued…)
3. Hence, by Lemma 10.5.1, T has a vertex v of degree 1, and has at least
another vertex in T besides v.
4. Thus, there is an edge e connecting v to the rest of T.
5. Define a subgraph T' of T so that V(T') = V(T) – {v} and E(T') = E(T) – {e}.
1. The number of vertices of T' is (k + 1) – 1 = k.
2. T' is circuit-free.
e T'
3. T' is connected. …
v
6. Hence by definition, T' is a tree.
7. Since T' has k vertices, by inductive hypothesis,
number of edges of T' = (number of vertices of T') – 1 = k – 1.
8. But number of edges of T = (number of edges of T') + 1 = k.
9. Hence P(k+1) is true.
18
Trees Rooted Trees Spanning trees and Shortest Paths
Characterizing Trees
19
Trees Rooted Trees Spanning trees and Shortest Paths
Characterizing Trees
20
Trees Rooted Trees Spanning trees and Shortest Paths
Characterizing Trees
Lemma 10.5.3
If G is any connected graph, C is any circuit in G, and one of the
edges of C is removed from G, then the graph that remains is still
connected.
Characterizing Trees
Characterizing Trees
Theorem 10.5.4
If G is a connected graph with n vertices and n – 1 edges, then G
is a tree.
Proof:
1. Suppose G is a particular but arbitrarily chosen graph that is
connected and n vertices and n – 1 edges.
2. Since G is connected, it suffices to show that G is circuit-free.
3. Suppose G is not circuit free
1. Let C be the circuit in G.
2. By Lemma 10.5.3, an edge of C can be removed from G to obtain a
graph G' that is connected.
3. If G' has a circuit, then repeat this process: Remove an edge of the
circuit from G' to form a new connected graph.
4. Continue the process of removing edges from the circuits until
eventually a graph G'' is obtained that is connected and is circuit-free2.0
Trees Rooted Trees Spanning trees and Shortest Paths
Characterizing Trees
Proof: (continued…)
4. Continue the process of removing edges from the circuits until
eventually a graph G'' is obtained that is connected and is circuit-free.
5. By definition, G'' is a tree.
6. Since no vertices were removed from G to form G'', G'' has n vertices.
7. Thus, by Theorem 10.5.2, G'' has n – 1 edges.
8. But the supposition that G has a circuit implies that at least one edge
of G is removed to form G''.
9. Hence G'' has no more than (n – 1) – 1 = n – 2 edges, which contradicts
its having n – 1 edges.
10. So the supposition is false.
4. Hence G is circuit-free, and therefore G is a tree.
24
Trees Rooted Trees Spanning trees and Shortest Paths
Characterizing Trees
25
10.6 Rooted Trees
Trees Rooted Trees Spanning trees and Shortest Paths
Definitions
27
Trees Rooted Trees Spanning trees and Shortest Paths
Definitions
28
Trees Rooted Trees Spanning trees and Shortest Paths
Definitions
29
Trees Rooted Trees Spanning trees and Shortest Paths
Example
27
Trees Rooted Trees Spanning trees and Shortest Paths
Binary Trees
Binary Trees
31
Trees Rooted Trees Spanning trees and Shortest Paths
Binary Trees
Binary Trees
32
Trees Rooted Trees Spanning trees and Shortest Paths
Binary Trees
Binary Trees
33
Trees Rooted Trees Spanning trees and Shortest Paths
34
Trees Rooted Trees Spanning trees and Shortest Paths
35
Trees Rooted Trees Spanning trees and Shortest Paths
36
Trees Rooted Trees Spanning trees and Shortest Paths
37
Trees Rooted Trees Spanning trees and Shortest Paths
Proof:
1. Every vertex, except the root, has a parent.
2. Since every internal vertex of a full binary tree has exactly
two children, the number of vertices that have a parent is
twice the number of parents, or 2k.
#vertices of T = #vertices that have a parent +
#vertices that do not have a parent
= 2k + 1
3. #terminal vertices = #vertices – #internal vertices
= 2k + 1 – k = k + 1
4. Therefore T has a total of 2k + 1 vertices and has k + 1
terminal vertices.
38
Trees Rooted Trees Spanning trees and Shortest Paths
39
Trees Rooted Trees Spanning trees and Shortest Paths
Theorem 10.6.2
For non-negative integers h, if T is any binary tree with height h
and t terminal vertices (leaves), then
t 2h
Equivalently,
log2 t h
41
Trees Rooted Trees Spanning trees and Shortest Paths
Proof: (continued…)
Case 1 (v has only one child):
v
Level 0
vL
Level 1
Level 2
Level 3
Left subtree TL
42
Trees Rooted Trees Spanning trees and Shortest Paths
Proof: (continued…)
7. Case 1 (v has only one child):
1. Without loss of generality, assume that v’s child is a left child
and denote it by vL. Let TL be the left subtree of v.
2. Because v has only one child, v is a leaf, so the total number of
leaves in T equals the number of leaves in TL + 1. Thus, if tL is
the number of leaves in TL , then t = tL + 1.
3. By inductive hypothesis, tL 2k because the height of TL is k,
one less than the height of T.
4. Also, because v has a child, k+1 1 and so 2k 20 = 1.
5. Therefore,
t = tL + 1 2k + 1 2k + 2k = 2k+1
43
Trees Rooted Trees Spanning trees and Shortest Paths
Proof: (continued…)
Case 2 (v has two children):
v
Level 0
vL
Level 1
vR
Level 2
Level 3
Level 4
44
Trees Rooted Trees Spanning trees and Shortest Paths
Proof: (continued…)
8. Case 2 (v has two children):
1. Now v has a left child vL and a right child vR , and they are the
roots of a left subtree TL and a right subtree TR respectively.
2. Let hL and hR be the heights of TL and TR respectively.
3. Then hL k and hR k since T is obtained by joining TL and TR
and adding a level.
4. Let tL and tR be the number of leaves of TL and TR respectively.
5. Then, since both TL and TR have heights less than k + 1, by
inductive hypothesis, tL 2hL and tR 2hR.
6. Therefore,
t = tL + tR 2hL + 2hR 2k + 2k 2k+1
9. We proved both cases that P(k+1) is true.
10. Hence if T is any binary tree with height h and t terminal vertices
(leaves), then t 2h. 42
Trees Rooted Trees Spanning trees and Shortest Paths
46
Trees Rooted Trees Spanning trees and Shortest Paths
47
Trees Rooted Trees Spanning trees and Shortest Paths
Breadth-First Search
7 8 9
48
Trees Rooted Trees Spanning trees and Shortest Paths
Breadth-First Search
Depth-First Search
47
Trees Rooted Trees Spanning trees and Shortest Paths
Depth-First Search
Definitions
Figure 10.7.1
53
Trees Rooted Trees Spanning trees and Shortest Paths
Definitions
The company wishes to legitimately advertise service to all the cities shown
but, for reasons of economy, wants to use the least possible number of
individual routes to connect them. One possible route system is given in
Figure 10.7.2, where the chosen routes are in red.
54
Trees Rooted Trees Spanning trees and Shortest Paths
Definitions
Lemma 10.5.3
Is the number of individual If G is any connected graph, C is any
routes minimal? circuit in G, and one of the edges of
C is removed from G, then the graph
The fact is that the graph of any that remains is still connected.
system of routes that satisfies
the company’s wishes is a tree,
because if the graph were to
contain a circuit, then one of
the routes in the circuit could
be removed without
disconnecting the graph (by
Lemma 10.5.3), and that would
give a smaller total number of
routes. Figure 10.7.2
55
Trees Rooted Trees Spanning trees and Shortest Paths
Definitions
Proposition 10.7.1
1. Every connected graph has a spanning tree.
2. Any two spanning trees for a graph have the same
number of edges.
56
Trees Rooted Trees Spanning trees and Shortest Paths
Definitions
The graph G has one circuit v2v1v4v2 and removal of any edge
of the circuit gives a tree. Hence there are three spanning
trees for G.
57
Trees Rooted Trees Spanning trees and Shortest Paths
Figure 10.7.3
58
Trees Rooted Trees Spanning trees and Shortest Paths
59
Trees Rooted Trees Spanning trees and Shortest Paths
Kruskal’s Algorithm
Kruskal’s Algorithm
61
Trees Rooted Trees Spanning trees and Shortest Paths
Kruskal’s Algorithm
Figure 10.7.4
62
Trees Rooted Trees Spanning trees and Shortest Paths
Kruskal’s Algorithm
63
Trees Rooted Trees Spanning trees and Shortest Paths
Kruskal’s Algorithm
64
Trees Rooted Trees Spanning trees and Shortest Paths
Prim’s Algorithm
65
Trees Rooted Trees Spanning trees and Shortest Paths
Prim’s Algorithm
Prim’s Algorithm
Figure 10.7.6
67
Trees Rooted Trees Spanning trees and Shortest Paths
Prim’s Algorithm
68
Trees Rooted Trees Spanning trees and Shortest Paths
Prim’s Algorithm
69
Trees Rooted Trees Spanning trees and Shortest Paths
1
71
Trees Rooted Trees Spanning trees and Shortest Paths
1
L(u) of each vertex u
other than a is set to .
72
Trees Rooted Trees Spanning trees and Shortest Paths
The rest of
a the vertices
78
Trees Rooted Trees Spanning trees and Shortest Paths
3
Step 1: Going into the while loop:
0
V(T) = {a}, E(T) = Ø, and F = {a}
1
During iteration:
F = {b, c}, L(b) = 3, L(c) = 4.
Since L(b) < L(c), b is added to V(T) and {a, b} is added
to E(T).
79
Trees Rooted Trees Spanning trees and Shortest Paths
3
Step 2: Going into the while loop:
0
V(T) = {a, b}, E(T) = {{a, b}}
4 1
During iteration:
F = {c, d, e}, L(c) = 4, L(d) = 9, L(e) = 8.
Since L(c) < L(d) and L(c) < L(e), c is added to V(T) and
{a, c} is added to E(T).
80
Trees Rooted Trees Spanning trees and Shortest Paths
3
Step 3: Going into the while loop:
0
V(T) = {a, b, c},
E(T) = {{a, b}, {a, c}}
4 1
5
During iteration:
F = {d, e}, L(d) = 9, L(e) = 5.
L(e) becomes 5 because ace, which has length 5, is a
shorter path to e than abe, which has length 8. Since
L(e) < L(d), e is added to V(T) and {c, e} is added to E(T).
81
Trees Rooted Trees Spanning trees and Shortest Paths
3 7
Step 4: Going into the while loop:
0
V(T) = {a, b, c, e},
E(T) = {{a, b}, {a, c}, {c, e}}
4 1 5
During iteration:
F = {d, z}, L(d) = 7, L(z) = 17.
L(d) becomes 7 because aced, which has length 7, is a
shorter path to d than abd, which has length 9. Since
L(d) < L(z), d is added to V(T) and {e, d} is added to E(T).
82
Trees Rooted Trees Spanning trees and Shortest Paths
3 7
Step 5: Going into the while loop:
0
V(T) = {a, b, c, e , d},
14
E(T) = {{a, b}, {a, c}, {c, e}, {e, d}}
4 1 5
During iteration:
F = {z}, L(z) = 14.
L(z) becomes 14 because acedz, which has length 14, is
a shorter path to z than acez, which has length 17.
Since z is the only vertex in F, its label is a minimum,
and so z is added to V(T) and {d, z} is added to E(T).
Algorithm terminates at this point because z V(T).
The shortest path from a to z has length L(z) = 14.
83
Trees Rooted Trees Spanning trees and Shortest Paths
{d, z}}
Table 10.7.1
84