Exercises Booklet
Exercises Booklet
We thank Annapaola Marconi for her work in previous editions of this booklet.
Contents
1 Introduction
2 Propositional Logic
10
10
17
28
31
31
35
4 Modal Logic
55
56
63
76
Chapter 1
M AX D EHN
Introduction
The purpose of this booklet is to give you a number of exercises on propositional, first order and modal logics to complement the topics and exercises
covered during the lectures of the course on mathematical logic. The material presented here is not a direct component of the course but is offered to
you as an incentive and a support to understand and master the concepts and
exercises presented during the course.
Symbol
Difficulty
Trivial
Easy
Medium
Difficult
Very difficult
Chapter 2
Propositional Logic
2.1
Exercise 2.1.
Basic Concepts
Propositional Logic
Exercise 2.2.
2.2
Exercise 2.3.
Truth Tables
F G
F G
(F G)
(F G) (F G)
Exercise 2.4.
pq
p q
(p q) (p q)
Exercise 2.5.
p q
r p
q r p
(p r)
Propositional Logic
Exercise 2.6.
p q
pq
p q p q
|= since each
Exercise 2.7.
q q
p (q q)
for every possible interpretation they evaluate to tha same truth value.
Exercise 2.8.
Exercise 2.9.
Use the truth table method to verify whether the following formulas are valid,
satisfiable or unsatisfiable:
(p q) q p
(p q) (p q)
(p q r) p q
(p q) (p r q) (q r p)
(p (q r)) ((p q) (p r))
(p q) (q p)
(p q) ((p r) q)
(p q) (p q)
(p (q r)) (r p)
Propositional Logic
Exercise 2.10.
Use the truth table method to verify whether the following logical consequences
and equivalences are correct:
(p q) |= p q
(p q) q |= p
p q r |= (p q) r
p (q r) |= q r p
(p q) p q
(p q) (p q) q
(p q) r (p q) r
(p q) (p q) p
((p q) q) q p q
2.3
Propositional Formalization
2.3.1
Exercise 2.11.
guages.
Exercise 2.12.
pq
11
Propositional Logic
Exercise 2.13.
logically equivalent to A B
5. (A B) (A B)
logically equivalent to A B
Exercise 2.14.
Angelo, Bruno and Carlo are three students that took the Logic exam. Lets
consider a propositional language where
A =Aldo passed the exam,
B =Bruno passed the exam,
C =Carlo passed the exam.
Formalize the following sentences:
12
Exercise 2.15.
Propositional Logic
6. A necessary condition for Angelo coming to the party, is that, if Bruno
and Carlo arent coming, Davide comes
7. Angelo, Bruno and Carlo come to the party if and only if Davide doesnt
come, but, if neither Angelo nor Bruno come, then Davide comes only if
Carlo comes
Solution.
1. D B C
2. C A B
3. D (C A)
4. D (C A)
5. (D C) (D B)
6. A (B C D)
7. (A B C D) (A B (D C))
Exercise 2.16.
Exercise 2.17.
Socrate says:
If Im guilty, I must be punished;
Im guilty. Thus I must be punished.
Is the argument logically correct?
Solution. The argument is logically correct: if p means Im guilty and q
means I must be punished, then:
(p q) p |= q
(modus ponens)
Exercise 2.18.
Socrate says:
If Im guilty, I must be punished;
Im not guilty. Thus I must not be punished.
Is the argument logically correct?
15
Propositional Logic
Solution. The argument is not logically correct:
(p q) p 2 q
+ consider for instance v(p) = F and v(q) = T
Exercise 2.19.
Socrate says:
If Im guilty, I must be punished;
I must not be punished. Thus Im not guilty.
Is the argument logically correct?
Exercise 2.20.
Socrate says:
If Im guilty, I must be punished;
I must be punished. Thus Im guilty.
Is the argument logically correct?
Exercise 2.21.
Formalize the following arguments and verify whether they are correct:
If Carlo won the competition, then either Mario came second or Sergio
came third. Sergio didnt come third. Thus, if Mario didnt come second,
then Carlo didnt win the competition.
16
2.3.2
Exercise 2.22.
Formalizing Problems
Aladdin finds two trunks A and B in a cave. He knows that each of them either
contains a treasure or a fatal trap.
On trunk A is written: At least one of these two trunks contains a
treasure.
On trunk B is written: In A theres a fatal trap.
Aladdin knows that either both the inscriptions are true, or they are both false.
Can Aladdin choose a trunk being sure that he will find a treasure?
If this is the case, which trunk should he open?
Solution. Lets consider a propositional language where a =Trunk A contains the treasure and b =Trunk B contains the treasure.
17
Propositional Logic
+ Obviously a =Trunk a contains a trap (and similarly for b), since each
trunk either contains a treasure or a trap (exclusive or).
Lets formalize what Aladdin knows:
Formalization of the inscriptions:
ab
a
Exercise 2.23.
18
Three boxes are presented to you. One contains gold, the other two are empty.
Each box has imprinted on it a clue as to its contents; the clues are:
Box 1 The gold is not here
Box 2 The gold is not here
Box 3 The gold is in Box 2
Only one message is true; the other two are false. Which box has the gold?
Formalize the puzzle in Propositional Logic and find the solution using a truth
table.
Solution. Let Bi with i {1, 2, 3} stand for gold is in the i-th box. We can
formalize the statements of the problem as follows:
1. One box contains gold, the other two are empty.
(B1 B2 B3 ) (B1 B2 B3 ) (B1 B2 B3 )
(2.1)
(2.3)
F
19
Propositional Logic
The only assignment I that verifies both (2.1) and (2.3) is the one with I(B1 ) =
T and I(B2 ) = I(B3 ) = F , which implies that the gold is in the first box.
Exercise 2.25.
Kyle, Neal, and Grant find themselves trapped in a dark and cold dungeon
(HOW they arrived there is another story). After a quick search the boys find
three doors, the first one red, the second one blue, and the third one green.
Behind one of the doors is a path to freedom. Behind the other two doors,
however, is an evil fire-breathing dragon. Opening a door to the dragon means
almost certain death.
On each door there is an inscription:
freedom
freedom
freedom
is behind
is not behind
is not behind
this door
this door
Given the fact that at LEAST ONE of the three statements on the three doors
is true and at LEAST ONE of them is false, which door would lead the boys to
safety?
Solution.
Language
r: freedom is behind the red door
b: freedom is behind the blue door
g: freedom is behind the green door
20
(2.4)
(2.5)
(2.6)
Solution
r
2.5
2.6
2.5 2.6
Exercise 2.26.
Propositional Logic
The guardian of the gold street: This road will bring you straight to
the center. Moreover, if the stones take you to the center, then also the
marble takes you to the center.
The guardian of the marble street: Neither the gold nor the stones will
take you to the center.
The guardian of the stone street: Follow the gold and youll reach the
center, follow the marble and you will be lost.
Given that you know that all the guardians are liars, can you choose a road
being sure that it will lead you to the center of the labyrinth? If this is the case,
which road you choose?
Provide a propositional language and a set of axioms that formalize the problem and show whether you can choose a road being sure it will lead to the
center.
Solution.
Language
g: the gold road brings to the center
m: the marble road brings to the center
s: the stone road brings to the center
Axioms
1. The guardian of the gold street is a liar
(g (s m))
(2.7)
(2.8)
(2.9)
2.7
2.8
2.9
Exercise 2.27.
Propositional Logic
Language For each 0 i 5, bi is a proposition, which intuitively means
that the i-th bit has value 1. Obviously, bi means that the i-th bit does not
have value 1, and thus it has value 0.
k
^
k=0
i=0
bi
5
^
bi
k
^
i=0
i=k+1
bi
5
^
!!
bi
(2.10)
i=k+1
Exercise 2.28.
Provide a propositional language and a set of axioms that formalize the graph
coloring problem of a graph with at most n nodes, with connection degree
m, and with less then k + 1 colors.
node degree: number of adjacent nodes
connection degree of a graph: max among all the degree of its nodes
graph coloring problem: given a non-oriented graph, associate a color to
each of its nodes in such a way that no pair of adjacent nodes have the
same color.
Solution.
Language
For each 1 i n and 1 c k, coloric is a proposition, which intuitively means that the i-th node has the c color
For each 1 i 6= j n, edgeij is a proposition, which intuitively means
that the i-th node is connected with the j-th node.
24
Wk
c=1 coloric
jJ
edgeij
Exercise 2.29.
Anna and Barbara carpool to work. On any day, either Anna drives Barbara
or Barbara drives Anna. In the former case, Anna is the driver and Barbara
is the passenger; in the latter case Barbara is the driver and Anna is the passenger.
Formalize the problem using the following propositions:
1. Anna drives Barbara
2. Barbara drives Anna
3. Anna is the driver
4. Barbara is the driver
5. Anna is the passenger
6. Barbara is the passenger
25
Propositional Logic
Exercise 2.30.
26
Sudoku is a placement puzzle. The aim of the puzzle is to enter a numeral from
1 through 9 in each cell of a grid, most frequently a 9 9 grid made up of 3 3
subgrids (called "regions"), starting with various numerals given in some cells
(the "givens"). Each row, column and region must contain only one instance of
each numeral. Its grid layout is like the one shown in the following schema
Language
which means that the number n has been inserted in the cross between row r
and column c.
Axioms
1. A raw contains all numbers from 1 to 9
9
^
9
^
9
_
r=1
n=1
c=1
!!
in(n, r, c)
27
Propositional Logic
2. A column contains all numbers from 1 to 9
9
^
9
^
9
_
c=1
n=1
r=1
!!
in(n, r, c)
for any 0 k, h 2
9
^
3
_
3
_
n=1
r=1
c=1
!!
in(n, 3 k + r, 3 h + c)
2.4
Exercise 2.32.
in(n, r, c) in(n0 , r, c)
28
Exercise 2.34.
NNF
4. (p r s) (q r s)
Exercise 2.35.
29
Propositional Logic
Solution.
1. (p q) (q r)
2. (p q) (q r)
3. (p q) (q r)
NNF
4. (p q r) (q r)
Exercise 2.36.
30
Mathematics as a science,
commenced when first
someone, probably a Greek,
proved propositions about
"any" things or about "some"
things, without specifications
of definite particular things.
Chapter 3
Exercise 3.1.
Basic Concepts
Exercise 3.2.
32
Exercise 3.4.
Exercise 3.5.
34
3.2
Exercise 3.6.
FOL Formalization
Exercise 3.7.
Exercise 3.8.
Exercise 3.9.
37
Exercise 3.10.
38
Exercise 3.12.
Language
Constants: A, B, C, D, E, F ;
39
Exercise 3.13.
Language
Constants: A, B, C, D, E, F ;
b5
b3
b2
table
41
2.
x.l(x)
3.
Its sufficient to find an interpretation I for which the logical consequence does
not hold:
l(x)
a(x)
j(x)
i(x)
Bob
Tom
Mary
Exercise 3.15.
Exercise 3.16.
Provide a FOL language and a set of axioms that formalize the graph coloring problem of a graph with at most n nodes, with connection degree m,
and with less then k + 1 colors.
node degree: number of adjacent nodes
connection degree of a graph: max among all the degree of its nodes
graph coloring problem: given a non-oriented graph, associate a color to
each of its nodes in such a way that no pair of adjacent nodes have the
same color.
Solution.
43
2. xx1 . . . xk+1 .
V
k+1
h=1 edge(x, xh )
Wk+1
i,j=1,j6=i xi = xj
Exercise 3.17.
Let {c1 , .., ck } be a non empty and finite set of colors. A partially colored directed graph is a structure hN, R, Ci where
N is a non empty set of nodes
R is a binary relation on N
C associates colors to nodes (not all the nodes are necessarily colored,.
and each node has at most one color)
Provide a first order language and a set of axioms that formalize partially
colored graphs. Show that every model of this theory correspond to a partially
colored graph, and vice-versa. For each of the following properties, write a
formula which is true in all and only the graphs that satisfies the property:
1. connected nodes dont have the same color
2. the graph contains only 2 yellow nodes
44
45
(edge(n, m)
i=1
i1
^
j=1
Exercise 3.18.
n
^
i=1
mine(xi ) y mine(y)
n
_
!!
y = xi
i=1
47
from e.
Exercise 3.19.
Formalize in first order logic the train connections in Italy. Provide a language
that allows to express the fact that a town is directly connected (no intermediate train stops) with another town, by a type of train (e.g., intercity, regional,
interregional). Formalize the following facts by means of axioms:
1. There is no direct connection from Rome to Trento
2. There is an intercity from Rome to Trento that stops in Firenze, Bologna
and Verona.
48
(3.4)
(3.5)
Exercise 3.20.
The game of Draughts is played on a standard Chess board 64 black and white
chequered squares. Each player has 12 pieces (men) normally in the form of
fat round counters. One player has black men and the other has white men.
When starting, each players men are placed on the 12 black squares nearest to
that player (see Figure 3.20). The white squares are not used at all in the game
50
(3.6)
(3.7)
(3.8)
4. "In each instant of the game, black squares are either empty or contain
a piece."
x.(square(x) black(x) t.(empty(x, t) y.contain(x, y, t))) (3.9)
5. "At the beginning of the game (instant zero) there are 12 white and 12
black men on the board."
numW (0) = 12 numB(0) = 12
(3.10)
6. "Whenever a black man captures a white man, in the next instant of the
game there is a white man less (and vice-versa)."
x, y, t.(piece(x) black(x) piece(y) white(y) capture(x, y, t) numW (t) = n
numW (t + 1) = n 1)
7. "If a piece in square x captures a piece in square y hopping over it into
the vacant square z, then in the next instant of the game the square z
contains the piece that moved while squares x and y are empty."
p1 , p2 , x, y, z, t.(piece(p1 ) piece(p2 ) square(x) square(y) square(z) empty(z, t)
contain(x, p1 , t) contain(y, p2 , t) capture(p1 , p2 , t)
empty(x, t + 1) empty(y, t + 1) contain(z, p1 , t + 1))
53
54
Chapter 4
Modal Logic
4.1
Exercise 4.1.
L EWIS C ARROLL
Basic Concepts
Say whether the following strings of symbols are well formed modal formulas
on P = {p, q}
1. p
2. p p
3. p p
4. q
5. p p
6. >
7. p p
Solution.
Well formed formulas: 2., 3., 5., 6. and 7.
55
Modal Logic
Exercise 4.2.
Say whether the following strings of symbols are well formed modal formulas
on P = {p, q}
1. q
2. q
3. p p
4. (> p) q
5. (p q) (p q)
6. q (p p(q))
Solution.
Well formed formulas: 1., 3., 4., and 5.
Exercise 4.3.
4
2
56
Exercise 4.4.
4
2
Exercise 4.5.
2
p,q
Exercise 4.6.
Consider the following model M = ((W, R), I) for the basic modal language of
P = {p}:
57
Modal Logic
W = {1, 2, 3}, R = {(1, 2), (2, 2), (2, 3)}, I(p) = {1, 2}.
Draw it as a labelled graph and then verify which of the following holds:
1. M, 1 |= p
2. M, 2 |= p
3. M, 3 |= p
4. M, 1 |= p
5. M, 1 |= p
6. M, 1 |= p
7. M, 2 |= p
8. M, 2 |= (p p) (p p)
9. M, 3 |= (p p) (p p)
Solution.
1
Exercise 4.7.
Determine whether the following formulas are valid in the lowermost worlds
of the two Kripke models below:
1. p
2. q
3. p q
4.
58
3 q
p 2
3 q
p 2
M1
M2
Solution.
1. M1 , 1 2 p and M2 , 1 2 p
2. M1 , 1 2 q and M2 , 1 |= q
3. M1 , 1 2 p q and M2 , 1 2 p q
4. M1 , 1 |= and M2 , 1 2
5. M1 , 1 |= (q (p q)) M2 , 1 2 (q (p q))
Exercise 4.8.
Determine in which worlds, of the two Kripke models below, are valid the following formulas:
1. p
2. q
3. p q
4.
5. (q (p q))
59
Modal Logic
3 q
p 2
3 q
p 2
M1
M2
Exercise 4.9.
Consider the following model M2 = ((W2 , R2 ), I2 ) for the basic modal language of P = {p}:
W2 = {1, 2}, R2 = {(1, 2), (2, 1)}, I(p) = {2}.
Draw it as a labelled graph and then verify which of the following holds:
1. M2 , 1 |= p p
2. M2 , 1 |= p p
3. M2 , 2 |= p p
4. M2 , 1 |= p p
5. M2 , 1 |= p
6. M2 , 1 |= p
7. M2 , 1 |= p
8. M2 , 2 |= p
9. M2 , 2 |= p
10. M2 , 1 |= p p
11. M2 , 2 |= p p
60
Exercise 4.10.
Consider the following model M3 = ((W3 , R3 ), I3 ) for the basic modal language of P = {p, q}:
W3 = {1, 2, 3, 4}, R2 = {(1, 2), (2, 3), (3, 1), (3, 4), (4, 2)}, I(p) = {1, 3}, I(q) =
{1, 2}.
Draw it as a labelled graph and then verify which of the following holds:
1. M3 , 1 |= q
2. M3 , 1 |= (p q)
3. M3 , 3 |= ((p q) (p q))
4. M3 , 1 |= p
5. M3 , 1 |= p q
6. M3 , 1 |= p q
7. M3 , 3 |= (p q)
8. M3 , 3 |= p q
4.2
Exercise 4.11.
Is p p satisfiable?
61
Modal Logic
Solution.
Its sufficient to find a model M and a world w in M such that M, w |= p
p:
Exercise 4.12.
Is p p satisfiable?
Solution.
M, w |= p p
iff
M, w |= p and M, w |= p
iff
iff
u W , (w, u) R implies M, u |= p
iff
for some world v W , (w, v) R and v I(p), and for every world
u W , (w, u) R implies u
/ I(p)
iff
v
/ I(p)
iff
Exercise 4.13.
Exercise 4.14.
63
Modal Logic
Solution. Suppose M = ((W, R), I) is an arbitrary Kripke model and w is an
arbitrary world in M.
M, w |= p
iff
not M, w |= p
iff
iff
iff
iff
iff
M, w |= p
Exercise 4.15.
(modus ponens)
(necessitation)
Exercise 4.16.
M1 , 4 2 p p
64
M1
2
p,q
Exercise 4.17.
Prove that the following formulae are not valid in the class of all frames.
1. p p
2. p p
3. p p
4. p p
Exercise 4.18.
For each of the following formulas, show that it is valid (i.e., true in all models)
or find a counterexample
1. A B (A B)
2. A A
3. (A B) A B
Solution.
1. A B (A B)
M, w |= A B M, w |= A and M, w |= B
for all w0 with wRw0 , M, w0 |= A and
there is a w0 with wRw0 , and M, w0 |= B
there is a w0 with wRw0 , and M, w0 |= B and M, w0 |= A
there is a w0 with wRw0 , and M, w0 |= A B
M, w |= A B
65
Modal Logic
2. A A
Counterexample:
1
M, 1 2 A A
3. (A B) A B
Counterexample:
2
1
3
Exercise 4.19.
For each of the following formulas, either prove that it is valid or find a Kripke
model hW, R, Ii and a w W that does not satisfy it.
1. A A
2. A (B C) (A (B C))
3. A A
Solution.
1. A A
Counterexample:
66
A
3
Exercise 4.20.
For each of the following formulas either prove that it is valid or find a counterexample. Note that if your attempts to produce a falsifying model always end
in incoherent pictures, it may be because the formula is valid.
1. A A
2. (A B) T
3. A A
Solution.
1. Countermodel:
67
Modal Logic
M
w
M, w 2 A A.
2. (A B) T
is valid.
We prove that for all models M and for all worlds w, M, w |= (A
B) T.
M, w |= (A B) there exists a v W s.t. wRv and M, v |= A B
there exists a v W s.t. wRv and M, v |= A and M, v |= B
there exists a v W s.t. wRv and M, v |= A
and there exists a v 0 s.t. vRv 0 and M, v 0 |= B
there exist v, v 0 W s.t. wRv and vRv 0
M, w |= T
3. Countermodel:
M
w
M, w 2 A A.
Exercise 4.21.
For each of the following formulas, either prove that it is valid or find a Kripke
model hW, R, Ii and a w W that does not satisfy it.
1. A A
2. (A B) (A B)
68
A
w2
M, w1 2 A A.
2. (A B) (A B)
We prove that for all models M and for all worlds w, M, w |= (A
B) (A B). Consider any model M and any world w. We have
two cases:
case 1: M, w 2 A B
M, w 2 A B = by def. of , M, w |= (A B) (A B) .
case 2: M, w |= A B
then we have two cases:
case 2.1: M, w 2 A
M, w 2 A = M, w 2 A
= M, w |= A B
= M, w |= (A B) (A B)
case 2.2: M, w |= A
M, w |= A = since M, w |= A B, M, w |= B
= by def of , M, w |= A B
= M, w |= (A B) (A B)
69
Modal Logic
Exercise 4.22.
For each of the following formulas, either prove that it is valid or find a Kripke
model hW, R, Ii and a w W that does not satisfy it.
1. A A
2. (A B) (A B)
3. A A
Solution.
1. Countermodel:
M
A
w2
w1
M, w1 2 A A.
2. We prove that for all models M and for all worlds w, M, w |= (A
B) (A B).
M, w |= A B M, w |= A and M, w |= B
M, w 2 A and M, w |= B
for all w0 , wRw0 implies M, w0 2 A and
there is a w0 with wRw0 , and M, w0 |= B
there is a w0 with wRw0 s.t. M, w0 2 A and M, w0 |= B
there is a w0 with wRw0 s.t. M, w0 |= A and M, w0 |= B
M, w |= 9(A B)
3. Countermodel:
M
A
w3
A
w1
w2
A
w4
70
Exercise 4.23.
M, v |=
2. M, v |=
Then by def. of
for every u W , if (v, u) R then M, u |= .
R is reflexive, hence (v, v) R.
Therefore M, v |= .
So, M, v |= .
71
Modal Logic
Exercise 4.24.
Prove that if, for every formula , the modal logic formula
is valid in a Kripke frame F = (W, R), then R is reflexive.
Solution. Assume that is valid in F = (W, R), for every .
Then, for every I and for any world w W we have
if M, w |=
then M, w |= .
Exercise 4.25.
Exercise 4.26.
Exercise 4.27.
73
Modal Logic
4.3
Exercise 4.28.
Provide a modal language and a set of axioms that formalize the graph coloring problem of a graph with at most n nodes, with connection degree m,
and with less then k + 1 colors.
node degree: number of adjacent nodes
connection degree of a graph: max among all the degree of its nodes
graph coloring problem: given a non-oriented graph, associate a color to
each of its nodes in such a way that no pair of adjacent nodes have the
same color.
Solution.
Language A set of propositional variables, C1 , . . . Ck one for each color.
Axioms
1. "Each node has at least one color":
k
_
Ci
i=1
Ci Cj
i6=j=1
3. "Each node does not have the same color as an accessible nodes:
k
^
(Ci Ci )
i=1
74
m+1
_
(i j )
i6=j=1
Exercise 4.29.
Modal Logic
1. You cannot be at the same time in Roma and Firenze
RM F I
2. There is no direct train connection from Roma to Trento.
RM TN
3. From Rome you can reach Trento with 2 changes.
RM TN
4. At Riva del Garda there is no train station.
RivaDelGarda
76