Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Mathematical Logic
Practical Class: Formalization in Propositional Logic
Chiara Ghidini
FBK-IRST, Trento, Italy
2013/2014
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Truth Tables
Formalizing Sentences
Problem Formalization
Traffic Light
Graph Coloring
Sudoku
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Truth Tables
F
T
T
F
F
G
T
F
T
F
F
F
F
T
T
F G
T
F
F
F
F G
T
T
T
F
F G
T
F
T
T
Truth tables of some propositional logical symbols.
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Truth Tables: Example
Compute the truth table of (F G ) (F G ).
F
T
T
F
F
G
T
F
T
F
F G
T
T
T
F
F G
T
F
F
F
(F G )
F
T
T
T
(F G ) (F G )
F
T
T
F
Intuitively, what does this formula represent?
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Truth Tables
Recall some definitions
Two formulas F and G are logically equivalent (denoted with
F G ) if for each interpretation I, I(F ) = I(G ).
Let F and G be formulas. G is a logical consequence of F
(denoted with F |= G ) if each interpretation satisfying F satisfies
also G .
Let F be a formula:
F is valid if every interpretation satisfies F
F is satisfiable if F is satisfied by some interpretation
F is unsatisfiable if there isnt any interpretation satisfying F
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Truth Tables: Example (2)
Use the truth tables method to determine whether (p q) (p q)
is valid.
p
T
T
F
F
q
T
F
T
F
pq
T
F
T
T
q
F
T
F
T
p q
F
T
T
T
(p q) (p q)
T
T
T
T
The formula is valid since it is satisfied by every interpretation.
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Truth Tables: Example (3)
Use the truth tables method to determine whether
(p q) (q r p) (p r ) (denoted with F ) is satisfiable.
p
T
T
T
T
F
F
F
F
q
T
T
F
F
T
T
F
F
r
T
F
T
F
T
F
T
F
p q
T
T
F
F
T
T
T
T
r p
F
F
F
F
F
T
F
T
q r p
F
F
T
T
F
T
T
T
(p r )
T
T
T
T
T
F
T
F
There exists an interpretation satisfying F , thus F is satisfiable.
Chiara Ghidini
Mathematical Logic
F
F
F
F
F
F
F
T
F
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Truth Tables: Example (4)
Use the truth tables method to determine whether p q p q is a
logical consequence of p.
p
T
T
F
F
q
T
F
T
F
p
F
F
T
T
p q
F
T
F
F
Chiara Ghidini
pq
T
F
F
F
p q p q
T
F
T
T
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Truth Tables: Example (5)
Use the truth tables method to determine whether p (q q) and p
are logically equivalent.
p
T
T
F
F
q
T
F
T
F
q q
F
F
F
F
Chiara Ghidini
p (q q)
F
F
T
T
Mathematical Logic
p
F
F
T
T
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Truth Tables: Exercises
Compute the truth tables for the following propositional formulas:
(p p) p
p (p p)
pq pq
p (q r ) (p r ) q
p (q p)
(p q) (p q)
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Truth Tables: Exercises
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)
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Truth Tables: Exercises
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
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Formalizing English Sentences
Exercise
Lets consider a propositional language where p means Paola is happy,
q means Paola paints a picture, and r means Renzo is happy.
Formalize the following sentences:
1
if Paola is happy and paints a picture then Renzo isnt happy
p q r
if Paola is happy, then she paints a picture
pq
Paola is happy only if she paints a picture
(p q) which is equivalent to p q !!!
The precision of formal languages avoid the ambiguities of natural
languages.
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Formalizing English Sentences
Exercise
Let A =Angelo comes to the party, B =Bruno comes to the party, C =Carlo
comes to the party, and D =Davide comes to the party.
Formalize the following sentences:
1
2
3
4
5
6
If Davide comes to the party then Bruno and Carlo come too
Carlo comes to the party only if Angelo and Bruno do not come
If Davide comes to the party, then, if Carlo doesnt come then Angelo comes
Carlo comes to the party provided that Davide doesnt come, but, if Davide
comes, then Bruno doesnt come
A necessary condition for Angelo coming to the party, is that, if Bruno and
Carlo arent coming, Davide comes
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
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Formalizing English Sentences
Exercise - Solution
1
If Davide comes to the party then Bruno and Carlo come too
D B C
Carlo comes to the party only if Angelo and Bruno do not come
C A B
If Davide comes to the party, then, if Carlo doesnt come then
Angelo comes
D (C A)
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Formalizing English Sentences
Exercise - Solution
1
Carlo comes to the party provided that Davide doesnt come, but,
if Davide comes, then Bruno doesnt come
(C D) (D B)
A necessary condition for Angelo coming to the party, is that, if
Bruno and Carlo arent coming, Davide comes
A (B C D)
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
(A B C D) (A B (D C ))
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Formalizing English Sentences
Exercise
Formalize the following arguments and verify whether they are correct:
If you play and you study youll pass the exams, while if you play
and dont study you wont pass. Thus, if you play, either you study
and youll pass the exams, or you dont study and you wont pass.
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Formalizing English Sentences
Exercise
If you play and you study youll pass the exams, while if you play
and dont study you wont pass. Thus, if you play, either you study
and youll pass the exams, or you dont study and you wont pass.
1
2
3
ps e
p s e
p (s e) (s e)
We need to prove that 1. 2. |= 3.
Use truth tables
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
The 3 doors
Problem
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
the blue 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?
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
The 3 doors: Solution
Language
r : freedom is behind the red door
b: freedom is behind the blue door
g : freedom is behind the green door
Axioms
1
behind one of the door is a path to freedom, behind the other two doors
is an evil dragon
(r b g ) (r b g ) (r b g )
at least one of the three statements is true
r b
at least one of the three statements is false
r b
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
The 3 doors: Solution (2)
Axioms
1
(r b g ) (r b g ) (r b g )
r b
r b
Solution
r
T
F
F
b
F
T
F
g
F
F
T
2
T
F
T
3
F
T
T
23
F
F
T
Freedom is behind the green door!
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Traffic Light
Graph Coloring
Sudoku
Traffic Light
Problem
Define a propositional language which allows to describe the state of a
traffic light on different instants. With the language defined above
provide a (set of) formulas which expresses the following facts:
the traffic light is either green, or red or orange;
the traffic light switches from green to orange, from orange to red,
and from red to green;
it can keep the same color over at most 3 successive states.
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Traffic Light
Graph Coloring
Sudoku
Traffic Light
Solution
gk =traffic light is green at instant k, rk =traffic light is red at instant
k and ok =traffic light is orange at instant k.
Lets formalize the traffic light behavior:
1
the traffic light is either green, or red or orange
(gk (rk ok )) (rk (gk ok )) (ok (rk gk ))
the traffic light switches from green to orange, from orange
to red, and from red to green
(gk1 (gk ok )) (ok1 (ok rk )) (rk1 (rk gk ))
it can keep the same color over at most 3 successive states
(gk3 gk2 gk1 gk ) (rk3 rk2 rk1
rk ) (ok3 ok2 ok1 ok )
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Traffic Light
Graph Coloring
Sudoku
Graph Coloring Problem
Problem
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.
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Traffic Light
Graph Coloring
Sudoku
Graph Coloring: Propositional Formalization
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.
Axioms
W
for each 1 i n, kc=1 coloric
each node has at least one color
for each 1 i n and 1 c, c 0 k, coloric coloric 0
every node has at most 1 color
for each 1 i, j n and 1 c k, edgeij (coloric colorjc )
adjacent nodes do not have the same color
for each 1 i
V
V n, and each J {1..n}, where |J| = m,
jJ edgeij
j6J edgeij
every node has at most m connected nodes
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Traffic Light
Graph Coloring
Sudoku
Sudoku Example
Problem
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
Provide a formalization in propositional logic of the sudoku problem, so that
any truth assignment to the propositional variables that satisfy the axioms is a
solution for the puzzle.
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Traffic Light
Graph Coloring
Sudoku
Sudoku Example: Solution
Language
For 1 n, r , c 9,define the proposition
in(n, r , c)
which means that the number n has been inserted in the cross between row r
and column c.
Chiara Ghidini
Mathematical Logic
Outline
Truth Tables
Formalizing Sentences
Problem Formalization
Traffic Light
Graph Coloring
Sudoku
Sudoku Example: Solution
Axioms
1
A raw contains all numbers from 1 to 9
9
9
9
^
^
_
in(n, r , c)
r =1
n=1
c=1
A column contains
numbers from 1to
all
9
9
9
9
^
^
_
in(n, r , c)
A region (sub-grid) contains all numbers from 1 to 9
c=1
for any
n=1
0 k, h 2
r =1
9
^
n=1
3
_
3
_
r =1
in(n, 3 k + r , 3 h + c)
c=1
A cell cannot contain two numbers
0
for any 1 n, n , c, r 9 and n 6= n
in(n, r , c) in(n , r , c)
Chiara Ghidini
Mathematical Logic