You are on page 1of 9

Mathematics for Computer Science

Mircea Marin

The course provides an introduction to concepts and techniques of discrete


mathematics that are important in computer science. It consists of 9 lectures
L1-L9 that cover the following material:
L1-2: Propositional and predicate logic: proof techniques; applications.
L3: Mathematical reasoning. Recursive definitions and structural induction.
L4-5: Relations: Basic properties. n-ary relations and their applications. Rep-
resenting relations. Equivalence relations. Partial orderings.
L6: Graphs: types of graphs; representations of graphs; applications.
L7-8: Trees: Introduction to trees;tree traversals; spanning trees; minimum
spanning trees; applications.

L9: Boolean algebras; boolean functions; logic gates; applications and exam-
ples.

Schedule
9 lectures, on Tuesdays, from 10:10 to 11:25, in the following days:
September 7, 14, 21, 28
October 5, 10, 26
November 2, 9.
Exam: November 16.
Lecture material can be downloaded from the webpage
http://www.score.is.tsukuba.ac.jp/~mmarin/MathCS/
Every lecture ends with a set of related exercises.
The participants will receive a grade after a written exam in November 18,
from 10:10 to 11:25.
References
Kenneth H. Rosen. Discrete Mathematics and its Applications. Fifth Edition.
ISBN 0-07-242434-6.
For further questions, you can contact me by email at mmarin@cs.tsukuba.ac.jp

1
1 L1: Propositional and Predicate Logic
In this lecture you will learn
1. How to specify correct mathematical statements,
2. How to give precise meaning to mathematical statements, and
3. How to prove mathematical statements.

1.1 What is Logic?


Logic is the science that gives rules that help us understand the meaning of
sentences and reason with statements.
In natural languages, such as English or Japanese, there are several kinds of
sentences:
(a) Declarative sentences that state some fact. For example:
• Tokyo is the capital of Japan.
• 2 + 2 = 3.
(b) Sentences that don’t state a fact. For example:
• What time is it?
• Read this book carefully!

Logic is the study of declarative sentences that state some fact. This means that
only sentences of type (a) are studied by logic. In mathematics, such sentences
are called formulas.

1.2 Propositional logic


The simplest form of logic is propositional logic. In propositional logic we
work only with sentences that are either true or false.
The truth value of a proposition is true, denoted by T, if it is a true
proposition and false, denoted by F, if it is a false proposition.

Exercise 1 Fill out the missing entries of the following table:


Sentence Is it a proposition? Truth value
Moscow is the capital of Russia.
2 + 7 = 0.
Where is the train station?
Don’t forget to do your homework!
Today is Sunday.

2
We use letters p, q, r, s to denote propositions.
New propositions, called propositional formulas, are formed from existing
propositions using logical operators ¬ (not), ∧ (and), ∨ (or), ⊕ (exclusive or),
→ (implies), ↔ (if and only if):
F ::= propositional formulas:
p proposition
| ¬F negation
| F1 ∧ F2 conjunction
| F1 ∨ F2 disjunction
| F1 ⊕ F2 exclusive disjunction
| F1 → F2 implication
| F1 ↔ F2 equivalence

1.2.1 Translating English sentences into propositional logic


Natural languages, such as English, Japanese, etc., are often ambiguous. In
order to remove the ambiguity, we can try to translate the sentences from English
into propositional logic. The translation proceeds as follows:
1. Detect the words for logical connectives, and identify their logical meaning.
Here are some common patterns:
A and B A∧B
A, but B.
A, yet B.
If A then B. A→B
A is sufficient for B.
B is necessary for A.
B if A.
B whenever A.
A only if B.
B when A.
A if and only if B. A↔B
A iff B.
If A then B, and conversely.
A is necessary and sufficient for B.
A precisely if B.
A is equivalent to B.
A unless B. ¬B → A
Unless B, A.
If not B then A.
A if not B.
2. If possible, identify alternative readings of the initial sentence that are
easier to analyze. For example:
X and Y are students ⇔ X is student and Y is student.
X or Y is guilty ⇔ X is guilty or Y is guilty.

3
3. Split the sentence into simpler sentences and give distinct names to the
component propositions.
4. Reformulate the English sentence as a propositional formula.

Example 1 Translate the sentence


“You can access the Internet from campus only if you are a computer
science major or you are not a freshman.”
into a propositional formula.
1. First, we detect the logical connectives.
“You can access the Internet from campus only if you are a computer
| {z }

science major |{z}
or you are |{z}
not a freshman.”
∨ ¬

2. We distinguish 3 component sentences:


p ≡ “You can access the Internet from campus.”
q ≡ “You are a computer science major.”
r ≡ “You are a freshman.”
3. We obtain the propositional formula p → (q ∨ ¬r).

Example 2 Translate the sentence


“Students who have taken calculus or physics, but not both, can enroll in
this class.”
into a propositional formula.

First, we detect the logical connectives.


• “Students who have taken calculus or physics, but not both, can
enroll in this class.”
The construct A or B, but not both is an exclusive or (⊕): It means
A ⊕ B. Thus, if we define
p ≡ “Students who have taken calculus can enroll in this class.”
q ≡ “Students who have taken physics can enroll in this class.”
then we obtain the translation p ⊕ q.

Example 3 Translate the sentence


“You can not ride the roller coaster if you are under 4 feet tall unless you
are older than 16 years old.”

1. Detect the words for logical connectives and identify their logical meaning:

4
“You can not ride the roller coaster if you are under 4 feet tall unless
you are older than 16 years.”
not =¬
A unless B =(¬B → A)
C if D =D → C.
2. We identify the following propositions:
O ≡ “You are older than 16 years.”
T ≡ “You are under 4 feet tall.”
R ≡ “You can ride the roller coaster.”
3. The initial sentence becomes

¬O → (T → ¬R)

which has the following reading in English:


“If you are younger than 16 years then if you are under 4 feet tall
then you can not ride the roller coaster.”

1.2.2 Truth values of propositional formulas


The truth value of a propositional formula can be computed with truth tables.
Every logical operator has its own truth table, which displays the relationship
between the truth values of component formulas and the truth value of the
formula constructed with that logical operator.

F ¬F F1 F2 F1 ∧ F2 F1 F2 F1 ∨ F2 F1 F2 F1 ⊕ F2
T F T T T T T T T T F
F T T F F T F T T F T
F T F F T T F T T
F F F F F F F T F
F1 F2 F1 → F2 F1 F2 F1 ↔ F2
T T T T T T
T F F T F F
F T T F T F
F F T F F T

Table 1: Truth tables.

Definition 1 (tautology, contradiction, equivalence) A propositional for-


mula is
• a tautology if it is always true.
• a contradiction if it is always false.

5
Two propositional formulas F1 and F2 are equivalent if F1 ↔ F2 is a tautology.
The notation F1 ≡ F2 denotes that F1 and F2 are equivalent.
Example 4 (A → ¬B) ∨ A is a tautology because it is always true:

A B ¬B A → ¬B (A → ¬B) ∨ A
T T F F T
T F T T T
F T F T T
F F T T T
A → B and (¬B) → ¬A are equivalent because (A → B) ↔ ((¬B) → ¬A) is a
tautology.
A B ¬A ¬B A→B (¬B) → ¬A (A → B) ↔ ((¬B) → ¬A)
T T F F T T T
T F F T F F T
F T T F T T T
F F T T T T T
Definition 2 (converse, contrapositive, and inverse) There are 3 related
implications that can be formed from a formula p → q.
• The converse of p → q is the formula q → p.
• The contrapositive of p → q is the formula (¬q) → (¬p).
• The inverse of p → q is the formula (¬p) → (¬q).
Example 5 What are the contrapositive, the converse, and the inverse of the
implication
“The
| home{zteam wins} whenever
| {z } it is raining.”?
| {z }
q ← p

We note that this implication can be rephrased as p → q where


p: “It is raining.”
q: “The home team wins.”
The converse is q → p:
“If the home team wins then it is raining.”
The contrapositive is (¬q) → (¬p):
“If the home team does not win then it is not raining.”
The inverse is (¬p) → (¬q):
“If it is not raining then the home team does not win.”
Note that an implication and its contrapositive are equivalent. The converse
and the inverse of an implication are also equivalent.

6
1.3 Applications of propositional logic
System and software engineers translate requirements in natural language (such
as English or Japanese) into logical formulas. In general, system specifications
must be consistent.

Definition 3 A set of propositional formulas is consistent if all its formulas


can be simultaneously true.
We can check the consistency of a set S = {F1 , . . . , Fn } of propositional
formulas by the method of truth tables. Assume p1 , . . . , pm are the propositional
variables that occur in the formulas F1 , . . . , Fn . We can compute the truth value
of F1 ∧ . . . ∧ Fn for every possible combination of truth values (p1 , . . . , pm ) with
pi ∈ {T, F}. There are 2m such combinations. Then S is consistent if and only
if F1 ∧ . . . ∧ Fn is not a contradiction.

Example 6 Determine whether the system specifications are consistent:


1. “The diagnostic message is stored in a buffer or it is retransmitted.”
2. “The diagnostic message is not stored in a buffer.”

3. “If the diagnostic message is stored in a buffer, then it is retransmitted.”


First, we translate the English statements into logical formulas:
p : “The diagnostic message is stored in a buffer.”
q : “The diagnostic message is retransmitted.”

In this example, the system specifications are S = {p ∨ q, ¬p, p → q}. They are
consistent because all components are true when p is F and q is T.

Limitations of propositional logic


Propositional logic talks only about propositions and propositional formu-
las.

• Propositions have no structure. For this reason, we say that propositions


are atomic.
• Statements such as “x > 3”, “x = y + 1” , ∀x. x + 1 > x are often found in
mathematical assertions and in computer programs. These statements are
made of constants, function symbols, predicates, variables, and quantifiers.
Propositional logic does not know this kind of expressions.
Predicate logic is a generalization of propositional logic that can talk about
variables, terms, atomic formulas and predicative formulas.
Predicate logic will be the subject of next lecture.

7
Homeworks
1. Let p, q, r be the propositions

p: Grizzly bears have been seen in the area.


q: Hiking is safe on the trail.
r: Berries are ripe along the trail.

Write the following propositions using p, q, r and logical connectives.


(a) Berries are ripe along the trail, but grizzly bears have not been seen
in the area.
(b) Grizzly bears have not been seen in the area and hiking on the trail
is safe, but berries are ripe along the trail.
(c) If berries are ripe along the trail, hiking is safe if and only if grizzly
bears have not been seen in the area.
(d) It is not safe to hike on the trail, but grizzly bears have not been
seen in the area and the berries along the trail are ripe.
(e) Hiking is not safe on the trail whenever grizzly bears have been seen
in the area and berries are ripe along the trail.
2. State the converse, contrapositive, and inverse of each of these implica-
tions.
(a) If it snows today, I will ski tomorrow.
(b) I come to class whenever there is going to be a quiz.
(c) A positive integer is prime only if it has no divisors other than 1 and
itself.
(d) When I stay up late, it is necessary that I sleep until noon.
3. Construct a truth table for each of the following propositional formulas.
(a) p → (¬q ∨ r)
(b) (¬p) → (q → r)
(c) (p → q) ∨ ((¬p) → r)
(d) ((¬p) ↔ (¬q)) ↔ (q ↔ r)
4. Are these system specifications consistent? “The router can send packets
to the edge system only if it supports the new address space. For the router
to support the new address space it is necessary that the latest software
release be installed. The router can send packets to the edge system if the
latest software release is installed. The router does not support the new
address space.”
5. Express these system specifications using the propositions p “The message
is scanned for viruses” and q “The message was sent from an unknown
system” together with logical connectives.

8
(a) “The message is scanned for viruses whenever the message was sent
from an unknown system.”
(b) “The message was sent from an unknown system but it was not
scanned for viruses.”
(c) “It is necessary to scan the message for viruses whenever it was sent
from an unknown system.”
(d) “When a message is not sent from an unknown system it is not
scanned for viruses.”
6. Determine whether each of these implications is true or false.

(a) If 1 + 1 = 2, then 2 + 2 = 5.
(b) If 1 + 1 = 3, then 2 + 2 = 4.
(c) If pigs can fly, then 1 + 1 = 3.
(d) If 1 + 1 = 3, then pigs can fly.
(e) If 2 + 2 = 4, then 1 + 2 = 3.

7. Write each of the following statements in the form “if p, then q” in English.
(a) Willy gets caught whenever he cheats.
(b) You can access the website only if you pay a subscription fee.
(c) It snows whenever the wind blows from the north-east.
(d) It is necessary to walk more than 10 miles to get to the top of Mount
Tsukuba.
(e) To be a citizen of this country, it is sufficient that you were born in
Japan.

You might also like