Lectures in Logic
Lectures in Logic
Contents
Lecture
1
Logic (TDDC36)
http://www.ida.liu.se/TDDC36/
Andrzej Szalas
IDA, University of Link
oping
Recommended book:
M. Ben-Ari: Mathematical Logic for Computer Science
Note that there are substantial additions during each lecture
2
3
4
5
6
7
8
9
Andrzej Szalas
Topic
Introduction to logics.
Propositional calculus.
Propositional calculus: tableaux,
deductive systems.
Propositional calculus: resolution.
Applications.
Predicate calculus. Tableaux.
Predicate calculus: deductive systems.
Predicate calculus: resolution.
Applications.
Deductive databases.
Modal logics.
Temporal logics.
Repetition
Slide 1 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Modeling
Andrzej Szalas
Book chapter
2
2
3
4
5
6
7
11
Slide 2 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Modeling
A good model is a more or less simplified description of reality.
It should allow to derive conclusions valid in the modeled reality.
Usually the goal is to use as elementary formal tools as possible
to specify the model at the required level of simplification.
K1
R
AooiTY
...
K2
Kn
EaLity
Re Al i t y
Example
Model of a car:
a drivers point of view: e.g., steering wheel, gears, starter,
light switches, etc.
a designers point of view: e.g., model of aerodynamical flows,
models of materials strength, etc.
REALITY
REALITY
REALITY
REALITY
Slide 3 of 225
Andrzej Szalas
Slide 4 of 225
perception
language
logic
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
analytical/numerical methods
probabilistic/statistical methods
fuzzy logic.
Symbolic reasoning
classical logic and logic programming
three- and many-valued logics
modal and temporal logics
nonmonotonic reasoning
approximate reasoning
Slide 5 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Quantitative reasoning
algorithmic methods
Andrzej Szalas
Incomplete,
inconsistent
data
Noisy,
incomplete
data
6 ...
Qualitative reasoning
6
Qualitative
Databases
...
6
Quantitative reasoning
6
...
...
Andrzej Szalas
Quantitative
Databases
)
Sensors,
cameras,...
Slide 6 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Modeling in logics
Logic
Andrzej Szalas
Slide 7 of 225
Andrzej Szalas
Slide 8 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Andrzej Szalas
Slide 9 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Example
Andrzej Szalas
Slide 10 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Logical language
M |= red or brown
Andrzej Szalas
Andrzej Szalas
Slide 12 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Logical language
Elements of a logical language continued
individual constants (constants), representing objects
e.g., 0, 1, John
Slide 13 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Bnf notation
S ::= S1 | . . . | Sn
Slide 14 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Propositional calculus
Andrzej Szalas
meaning
symbol S may be replaced by sequence
S1 . . . Sn
symbol S may be replaced by one of
S1 , . . . , Sn
Andrzej Szalas
Slide 15 of 225
Slide 16 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Propositional calculus
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Truth tables
engine on
motion
gear on
gear on motion slow down
...
Andrzej Szalas
Truth tables
Truth tables provide us with a semantics of logical connectives.
Truth table consists of columns representing arguments
of a connective and one (last) column representing the logical
value of the sentence built from arguments, using the connective.
Connective not
Connective not, denoted by , expresses the negation
of a sentence.
Truth table for negation
A
F
T
Slide 17 of 225
Andrzej Szalas
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Slide 18 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Examples
Connective and
Connective and, denoted by , expresses the conjunction
of sentences.
A
T
F
B
F
T
F
T
Andrzej Szalas
AB
F
F
F
T
Slide 19 of 225
Andrzej Szalas
Slide 20 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Examples
Connective or
Connective or, denoted by , expresses the disjunction
of sentences.
B
F
T
F
T
Andrzej Szalas
AB
F
T
T
T
Slide 21 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Andrzej Szalas
Slide 22 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Connective implies
Connective implies, denoted by , expresses the implication of
sentences(if then).
Connective equivalent to
Connective equivalent to, denoted by , expresses the equivalence
of sentences (if and only if).
A
F
F
T
T
B
F
T
F
T
Andrzej Szalas
AB
T
T
F
T
Slide 23 of 225
A
F
F
T
T
B
F
T
F
T
Andrzej Szalas
AB
T
F
F
T
Slide 24 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
The method
Truth table method is the proof method based on truth tables (it
is also called the 0-1 method, since truth values F and T are often
denoted by 0 and 1, respectively).
Construction of truth tables for formulas
rows: all possible assignments of F, T to atomic sentences
columns:
first columns correspond to all atomic sentences, i.e.,
sentences not involving connectives
next columns correspond to sub-formulas involving one
connective, if any
next columns correspond to sub-formulas involving two
connectives, if any
etc.
the last column corresponds to the whole formula.
Andrzej Szalas
Slide 25 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Andrzej Szalas
Slide 26 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Example
Consider sentence
It is not the case that John does not have a daughter.
Therefore John has a daughter.
The structure of this sentence is [(A)] A, where A stands for
John has a daughter.
Truth table for [(A)] A:
A
F
T
A
T
F
(A)
F
T
[(A)] A
T
T
Andrzej Szalas
Slide 27 of 225
Andrzej Szalas
Slide 28 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Checking satisfiability
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Verifying counter-tautologies
Example
Check whether the following formula is satisfiable:
Example
Check whether the following formula is a counter-tautology:
A [(A B) B]
We construct the following truth table:
A
F
F
T
T
B
F
T
F
T
B
T
F
T
F
AB
F
T
T
T
(1)
(A B) B
F
F
T
F
A
F
F
T
T
(1)
T
T
T
F
B
F
T
F
T
B A
T
F
T
T
(2)
A (B A)
T
T
T
T
(2)
F
F
F
F
[A (B A)]
We construct the following truth table:
Slide 29 of 225
Andrzej Szalas
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Slide 30 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
(3)
[(A B)] (A B)
The following truth table proves (3):
A
F
F
T
T
B
F
T
F
T
A
T
T
F
F
B
T
F
T
F
AB
F
F
F
T
Andrzej Szalas
(4)
(A B)
T
T
T
F
Slide 31 of 225
A B
T
T
T
F
(3)
T
T
T
T
A
F
F
T
T
B
F
T
F
T
A
T
T
F
F
B
T
F
T
F
AB
F
T
T
T
Andrzej Szalas
(A B)
T
F
F
F
Slide 32 of 225
A B
T
F
F
F
(4)
T
T
T
T
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Consider:
Consider:
(A B) (A B)
(5)
B
F
T
F
T
A
T
T
F
F
AB
T
T
F
T
Andrzej Szalas
(6)
(5)
T
T
T
T
A
F
F
T
T
B
F
T
F
T
Slide 33 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Andrzej Szalas
(A B) (A B)
Slide 35 of 225
B
T
F
T
F
AB
T
T
F
T
(A B) A B
F
F
F
F
T
T
F
F
Andrzej Szalas
(6)
T
T
T
T
Slide 34 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
p
F
F
T
T
F
F
T
T
r
F
F
F
F
T
T
T
T
sr
T
F
T
F
T
T
T
T
pr
T
T
F
F
T
T
T
T
Andrzej Szalas
s p
F
T
T
T
F
T
T
T
1
T
F
F
F
T
T
T
T
Slide 36 of 225
2
T
F
F
F
T
T
T
T
1 2
T
T
T
T
T
T
T
T
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Summary
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
propositional calculus
truth table method.
Andrzej Szalas
Slide 37 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Examples
Andrzej Szalas
Slide 38 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Proof systems
Hilbert-like systems
resolution (Robinson)
Andrzej Szalas
Slide 39 of 225
Andrzej Szalas
Slide 40 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Proof rules
Andrzej Szalas
Slide 41 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Andrzej Szalas
Slide 42 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
AB
B
John is a student.
If John is a student then John learns a lot.
Therefore, John learns a lot.
AB
B
A
if there is fire here, then there is oxygen here.
There is oxygen here.
Therefore, there is fire here.
Denying the antecedent
Modus tollens
AB
B
A
if there is fire here, then there is oxygen here.
There is no oxygen here.
Therefore, there is no fire here.
Andrzej Szalas
Slide 43 of 225
AB
A
B
if there is fire here, then there is oxygen here.
There is no fire here.
Therefore, there is no oxygen here.
Andrzej Szalas
Slide 44 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Slide 45 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Andrzej Szalas
Slide 46 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Some meta-properties
A meta-property is a property of logic rather than of the reality the
logic describes.
There are two important meta-properties relating syntactical and
semantical approaches, namely soundness (also called correctness)
and completeness of a proof system wrt a given semantics.
Assume a logic is given by its semantics S and by a proof system
P. Then we say that:
proof system P is sound (correct) wrt the semantics S
iff every property that can be inferred using P
is true under semantics S,
proof system P is complete wrt the semantics S
iff every property that is true under semantics S
can be inferred using P.
Andrzej Szalas
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Andrzej Szalas
Slide 47 of 225
axioms:
A (B A)
A (B C ) (A B) (A C )
(B A) (A B)
AB
B
Slide 48 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Example
3
4
5
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
We prove A A.
1
A ((A A) A) (A (A A)) (A A)
(axiom 2 with B replaced by (A A)) and C replaced by A
A ((A A) A) (axiom 1 with B replaced by
(A A))
(A (A A)) (A A) (MP applied to 1, 2)
A (A A) (axiom 1 with B replaced by A)
A A (MP applied to 3, 4).
Andrzej Szalas
Slide 49 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Example
Andrzej Szalas
Slide 50 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
The tableau:
D, E , F , G
B, C
E , H, I , J, K
represents
D E F G E H I J K
{z
} |
{z
}
|
the first branch
the second branch
Andrzej Szalas
Slide 51 of 225
1
2
A1
A1
A1 A2
A1
A2
(A1 A2 ) A1
A2
(A1A2 )
A1
A2
A1A2
A1A2 A2A1
Andrzej Szalas
(B1 B2 )
B1
B2
B1 B2
B1
B2
B1B2
B1
B2
(B1B2 ) (B1B2 ) (B2B1 )
Slide 52 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Andrzej Szalas
Slide 53 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Example
Slide 54 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Important properties
(p q) p q
(p q), p q
(p q), p, q
p, p, q
q, p, q
Andrzej Szalas
Slide 55 of 225
Andrzej Szalas
Slide 56 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Example
To prove (p q) p p we construct a closed tableau for its
negation:
(p q) p p
(p q) p , p
(p q), p
p, p
| {z }
closed
p, q, p
| {z }
closed
Andrzej Szalas
Slide 57 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Andrzej Szalas
Slide 58 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Examples of sequents
1
2
p, q r represents [p q] r
p, q r , s, t represents
[p q] [r s t].
Fact
If A B 6= then A B represents a tautology.
Andrzej Szalas
Slide 59 of 225
AB
from A B derive C D
C D
AB
from A B derive conjunction
C D and E F
C D; E F
Note that we present rules upside down, which better reflects
construction of proofs.
Axioms
Axioms are of the form A, B, C D, B, E ,
i.e., the same formula appears at both sides of .
Andrzej Szalas
Slide 60 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Gentzen-like proofs
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Rules
Negation
(l )
A, B, C D
A, C B, D
(l )
Rules
A, B C , D E
A, B, C , D E
A B, C D, E
A B, C , E ; A B, D, E
Slide 61 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
A B, C , D
A, C B, D
Conjunction
(r )
Andrzej Szalas
(r )
Andrzej Szalas
Slide 62 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Examples
Proof of P (P Q)
Disjunction
(l )
A, B C , D E
A, B, D E ; A, C , D E
(r )
A B, C D, E
A B, C , D, E
Andrzej Szalas
Slide 63 of 225
Slide 64 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Example: rule ( r )
Consider first A, B C , D E :
Consider now A B, C D, E :
(def )
A, B C , D E
A, B C , D E
(l )
A, B, D E
(l )
; A, C , D E
A, D B, E
(def )
A B, C D, E
A B, C D, E
(r )
A B, C , D, E
(r )
A, C B, D, E
A, B C , D E
A, D B, E ; A, C , D E
Andrzej Szalas
A B, C D, E
A, C B, D, E
Andrzej Szalas
Slide 66 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Summary
Andrzej Szalas
( r )
Slide 65 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Slide 67 of 225
proof systems
soundness and completeness
Hilbert-like proof systems, system H
tableaux for propositional calculus
Andrzej Szalas
Slide 68 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Examples
2
3
4
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
(p q s) t is in Nnf
(p q s) t is not in Nnf
r q s t is in Nnf
Subformula
AB
AB
A
(A B)
(A B)
Replaced by
(A B) (A B)
A B
A
A B
A B
r q [s t] is not in Nnf.
Andrzej Szalas
Slide 69 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Example
[(p r ) ((q r ))]
(2)
(4)
(3)
((p r )) ((q r ))
(p r ) ((q r ))
(p r ) (q r ).
Andrzej Szalas
(3)
Slide 71 of 225
Andrzej Szalas
Slide 70 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Andrzej Szalas
Slide 72 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Examples
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
1
2
3
4
5
6
[A1 A2 . . . Al ] B,
Andrzej Szalas
Slide 73 of 225
Andrzej Szalas
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Non-Horn clauses
Slide 74 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Andrzej Szalas
Slide 75 of 225
Subformula
(A B) C
C (A B)
Andrzej Szalas
Replaced by
(A C ) (B C )
(C A) (C B)
Slide 76 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Example
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Applications of CNF
Andrzej Szalas
(7)
tautology checking.
A formula in Cnf can easily be tested for validity, since in this
case we have the following simple criterion:
if each clause contains a literal together with its
negation, then the formula is a tautology, otherwise
it is not a tautology.
Examples:
1
2
(p q p) (p q r q) is a tautology
(p q p) (p q r ) is not a tautology.
Slide 77 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Andrzej Szalas
(7)
fastFood walk
^
fastFood park
restaurant walk
restaurant park.
(6)
Slide 79 of 225
Andrzej Szalas
Slide 78 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Remarks
Resolution rule reflects the transitivity of implication
Resolution rule can be formulated equivalently as:
() L,
L
()
reflecting the transitivity of implication.
Presenting , as clauses, the resolution rule takes the form:
L1 . . . Lk L,
L M1 . . . Ml
L1 . . . Lk M1 . . . Ml
In the book an abbreviated notation is used:
L M1 . . . Ml
L1 . . . Lk1 L,
L1 . . . Lk M1 . . . Ml
and duplicates in the result are assumed to be removed. We
will formulate this principle as a separate rule called (fctr ).
Andrzej Szalas
Slide 80 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Examples
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Example
P Q,
Q S T
P S T
P P Q P Q
P Q
Q P,
S T Q
P S T
Andrzej Szalas
Slide 81 of 225
Andrzej Szalas
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Resolution method
Slide 82 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Example
Andrzej Szalas
Slide 83 of 225
AB
A
B
B
F
Andrzej Szalas
Slide 84 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Andrzej Szalas
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
The task
(i) the conjunction of (1), (2) and (3) implies (4)
(ii) the conjunction of (1), (2) and (4) implies (3).
Atomic sentences
ir standing for interest rate of the central bank will be
changed
ge standing for government expenses will be increased
un standing for new unemployment will arise
tx standing for taxes will be reduced
Andrzej Szalas
Slide 86 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Example continued
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Example continued
Slide 85 of 225
Example continued
(ge) tx
(tx ir ) un
Our first task is then to check whether the conjunction of (1), (2)
and (3) implies (4), i.e., whether:
[(tx ir ) un]
Negation of the above formula
(ir ) ge.
Slide 87 of 225
Andrzej Szalas
Cnf:
[ir ge un]
[ge tx]
[tx ir un]
ir
ge
Slide 88 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Example continued
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Example continued
The second task (do (1), (2) and (4) imply (3)?)
[(ir ) ge]
ir ge un
ge tx
tx ir un
ir
ge
tx un
ge un
ge un
ge ge
ge
F
Negated
(res) : 3, 4
(res) : 2, 6
(res) : 1, 4
(res) : 7, 8
(fctr ) : 9
(res) : 5, 10
Andrzej Szalas
[ir ge un]
[ge tx]
[ir ge]
tx
ir
un
No matter how (res) and (fctr ) are applied, F cannot be derived.
[(ir ) (ge un)]
[(ge) tx]
[(ir ) ge]
Cnf:
[tx ir ]
un
Slide 89 of 225
Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution
Summary
Andrzej Szalas
Slide 90 of 225
Quantifiers
Andrzej Szalas
Slide 91 of 225
Andrzej Szalas
Slide 92 of 225
Examples
1
Relation R is reflexive:
etc.
x R(x, x)
3
Relation R is symmetric:
xy R(x, y ) R(y , x)
A hierarchy of logics
xy loves(x, y )
2
Relation R is transitive:
xy z ((R(x, y ) R(y , z)) R(x, z))
Andrzej Szalas
Slide 93 of 225
Higher-order formulas
Slide 94 of 225
Examples
1
Andrzej Szalas
Andrzej Szalas
Slide 95 of 225
::=
::=
::=
::=
::=
::=
::=
::=
::=
::=
x
a
argument
argument, argument list
p | p(argument list)
atomic formula
formula
formula formula
x formula
x formula
Andrzej Szalas
Slide 96 of 225
Examples
Andrzej Szalas
Slide 97 of 225
x
R(x) y
z
the scope of y
}|
{
R(x) S(x, y )
{z
the scope of x
the scope of y
z
}|
{
x
x
R(x)
T
(x,
y
,
z)
R(x)
|
{z
}
the scope of x
|
{z
}
the scope of x
Andrzej Szalas
Slide 98 of 225
Interpretations
Let U be a set of formulas such that {p1 , . . . , pm } are all relation
symbols and {a1 , . . . , ak } are all constant symbols appearing in U.
An interpretation is a triple hD, {R1 , . . . , Rm }, {d1 , . . . , dk }i, where
D is a non-empty domain
Ri is an assignment of a relation on D to pi
di D is an assignment of an element of D to ai .
Andrzej Szalas
Slide 99 of 225
Semantics
Let A be a formula, I an interpretation and I an assignment.
The value of A under I , denoted by vI (A) is defined by
Restricted quantifiers
all Ps are Qs
i.e., all individuals satisfying P satisfy Q this form is also
called the restricted universal quantification
some Ps are Qs
i.e., some individuals satisfying P satisfy Q this form is also
called the restricted existential quantification
no Ps are Qs
i.e., no individuals satisfying P satisfy Q
some Ps are not Qs
i.e., some individuals satisfying P do not satisfy Q.
Andrzej Szalas
Aristotelian forms
Aristotelian forms
The four Aristotelian forms of quantification are:
1
Andrzej Szalas
Examples
1
Examples
1
x [student(x) hasToLearn(x)]
2
Andrzej Szalas
Examples
Eve is a student
constants: Eve, variables: none
concepts: student
other relations: none.
Translation: student(Eve).
Eve is the best student
constants: Eve, variable: x (needed in quantification)
concepts: student
other relations: two-argument relation betterStudent.
Translation:
student(Eve) x[student(x) betterStudent(x, Eve)]
Andrzej Szalas
[x A(x)] [x A(x)]
[x A(x)] [x A(x)]
Examples
1
Andrzej Szalas
2
3
4
2
x[P] is equivalent to P
x[P] is equivalent to P
x[P Q(x)] is equivalent to P x[Q(x)]
x[P Q(x)] is equivalent to P x[Q(x)].
Tableaux
Null quantification.
Assume variable x is not free in formula P. Then:
1
and formulas
x A(x)
x A(x)
(a)
A(a)
A(a)
x A(x)
x A(x)
(a)
A(a)
A(a)
Semantic tableau
A semantic tableau for formula A is a tree T each node of which is
labeled with a set of formulas. The tableau construction extends
the construction given for propositional calculus (see slides 50
54).
Andrzej Szalas
Tableaux
Example
Andrzej Szalas
Summary
Andrzej Szalas
Rules
Andrzej Szalas
Example
Universal quantifier
(l )
A, x B(x), C D
A, x B(x), C , B(a) D
(r )
A B, x C (x), D
A B, x C (x), D, C (a)
A, x B(x), C D
A, x B(x), C , B(a) D
(r )
A B, x C (x), D
A B, x C (x), D, C (a)
Soundness
The provided Gentzen proof system G is sound: if all leaves of
a derivation tree of A are axioms then A is a tautology.
Completeness
G is complete: if A is a tautology then there is a derivation tree for
A with all leaves containing axioms.
Andrzej Szalas
Proof
One has to prove:
O(c, d),x[O(x, d) C (x)], O(e, c),x[O(x, c) O(x, d)] C (e)
Hint: use rule (l ) to obtain intermediate sequent (below
redundant formulas are omitted):
O(c, d), O(e, d) C (e), O(e, c), O(e, c) O(e, d) C (e).
Next, applications of (l ) and then of (l ) result in leaves
containing axioms.
Andrzej Szalas
Some properties of H
Deduction theorem
The following rule can be derived, where A contains no free
variables:
U {A} B
.
UAB
Soundness
The proof system H is sound, i.e., any formula of predicate
calculus provable in H is a tautology.
Completeness
The proof system H is complete, i.e., any tautology of predicate
calculus is provable in H.
Andrzej Szalas
Examples
2
3
2
3
xA(x) A(a)
(axiom)
(PC)
A(a) xA(x)
(deMorgan, PC)
A(a) xA(x)
Examples
x A(x) A(a)
(axiom)
(proof above)
x A(x) x A(x)
(generalization).
A(a) x A(x)
Andrzej Szalas
Examples
(axiom)
(axiom)
(PC)
(generalization)
(deduction)
Andrzej Szalas
(assumption)
(deduction).
Examples
Andrzej Szalas
A(a, b) x A(x, b)
(proved)
y A(a, y ) y x A(x, y )
(generalization 1)
y x A(x, y ) y A(a, y )
(PC)
xy A(x, y ) y xA(x, y )
(generalization)
(axiom)
(PC)
xy A(x, y ) y xA(x, y )
Andrzej Szalas
(deMorgan).
Summary
Examples
1
2
3
Andrzej Szalas
Subformula
Qx A(x), A(x) without variable z
x A(x) x B(x)
x A(x) x B(x)
A Qx B, where A contains no x
A Qx B, where A contains no x
Slide 131 of 225
Example
Andrzej Szalas
Rule
12
13
14
15
16
Replaced by
Qz A(z)
x [A(x) B(x)]
x [A(x) B(x)]
Qx (A B)
Qx (A B)
(15)
(16)
(15)
Andrzej Szalas
(12)
(15)
Functions
A function is a special type of relation. It takes a sequence of
arguments and returns a unique value.
Standard notation: name(expr1 , . . . , exprn ) denotes a function
value, where name is a function name and expr1 , . . . , exprn are
function arguments. The number of arguments is called the arity
of the function. We write
name : U1 U2 . . . Un U
meaning that the first argument takes a value from U1 , the second
from U2 , . . ., the n-th from Un and the result is from U.
A two-argument function id called binary and a one-argument
function is called unary. For binary functions one often uses infix
notation, some functions have traditionally accepted special
notations.
Andrzej Szalas
Examples
1
x + y , x y (infix notation);
what notation + : [0, 1] [2, 5] [2, 6] means?
Andrzej Szalas
Semantics
Terms
Let F be a set of function symbols. The following grammar
defines terms. The rule for atomic formula is modified to take
a term list as its argument.
term
::= x
for any x V
term
::= a
for any a A
term
::= f (term list)
for any f F
::= term
term list
term list
::= term, term list
for any p P.
atomic formula ::= p(term list)
Interpretations
Let U be a set of formulas such that {p1 , . . . , pm } are all relation
symbols, {f1 , . . . , fl } are all the function symbols and {a1 , . . . , ak }
are all constant symbols appearing in U. An interpretation is
a tuple hD, {R1 , . . . , Rm }, {F1 , . . . , Fl }, {d1 , . . . , dk }i, where
D is a non-empty domain
Ri is an assignment of a relation on D to pi
Fi is an assignment of a function on D to fi
di D is an assignment of an element of D to ai .
Examples
Examples of terms: a, x, f (a, x), f (g (x), y ), g (f (a, g (b))).
Examples of atomic formulas: p(a, b), p(g (f (a, g (b)), f (a, x)).
Andrzej Szalas
Andrzej Szalas
Semantics
vI (ai ) = di
Andrzej Szalas
Andrzej Szalas
Example
1
x [rare(x) expensive(x)]
y [expensive(y ) guarded(y )]
Important
A formula is satisfiable iff its Skolem normal form is satisfiable.
Andrzej Szalas
Clause form:
rare(x) expensive(x)
expensive(y ) guarded (y )
Can we apply (res)? NO! Because expensive(x) and
expensive(y ) are not the same!
On the other hand, y could equivalently be replaced by x and
resolution could be applied.
Andrzej Szalas
Unification
Given two expressions, unification depends od substituting variables
by expressions so that both input expressions become identical.
If this is possible, the given expressions are said to be unifiable.
Consider:
rare(x) expensive(x)
rare(VermeerPainting )
Examples
Andrzej Szalas
Andrzej Szalas
Expression trees
f (g (f (v ), z))
f
g
f
g
To unify expressions (x + f
(y )) and ( 2 z + f (3)), it
suffices to substitute x by 2 z and y by 3
h
y
f
v
1
2
3
Input: expressions e, e
Output: substitution of variables which makes e and e identical
or inform that such a substitution does not exist.
Andrzej Szalas
Examples
Andrzej Szalas
attends(John, math)
Do the above formulas imply that John is obliged to take math?
Andrzej Szalas
We consider implication:
Proof
1 med(x) attends(x, y ) likes(x, y ) obliged(x, y )
obliged(John, math)
med (John)
attends(John, math)
obliged(John, math)
10
(res): 5, 9.
Andrzej Szalas
Example
Example
P(a, x , x )
P(f
(a), x , f
(res): 1, 2 with x = a, y =
Andrzej Szalas
x , z
P(x, y ) P(a, y )
P(x , g (x ))
P(a, y )
(fctr ): 1 with x = a
Andrzej Szalas
Summary
What is a database?
A database is any finite collection of related data.
Examples
Andrzej Szalas
a phone book
a Swedish-to-English dictionary
a library
an electronic mailbox
an accounting database
...
Andrzej Szalas
Database
an atomic data item
= number, letter, etc.
a record
= a tuple of atomic data items
a table
= a collection of compatible records
a relational database
= a collection of tables
+ integrity constraints
Andrzej Szalas
Representation in logic
an element
of a domain (universe)
a fact
a relation
an extensional database
= a collection of relations
+ formulas
Database
a deductive database
= relational database
+ deduction mechanism
a database query
a linguistic tool for selecting
pieces of information
Representation in logic
a deductive database
= extensional database
+ intensional database
(rules)
a formula
Integrity constraints
An integrity constraint of a database is a constraint that has to be
satisfied by any instance of the database.
Andrzej Szalas
Database
atomic data:
= first&last name,
phone number
a record:
{Eve Lin, 0701 334567}
a table:
{Eve Lin, 0701 334567}
{John Smith, 0701 334555}
...
Representation in logic
domains:
Names,
Numbers
a fact:
PN( Eve Lin , 0701 334567)
a relation:
PN( Eve Lin , 0701 334567)
PN( JohnSmith , 0701 334555)
...
Andrzej Szalas
Database
a relational database:
the above table + constraints
e.g., different persons have
different phone numbers
a database query:
find phone numbers
of Eve Lin
Andrzej Szalas
Representation in logic
the extensional database:
the above relation +
x, y Names n, m Numbers
[PN(x, n) PN(y , m) x 6= y ]
n 6= m
formula:
PN( Eve Lin , X )
Common assumptions
intensional databases
Integrity
constraints
Extensional
Database
}|
s
.....
+
deduction mechanisms
6
.....
Andrzej Szalas
Queries
x [R(
x ) (
x = a1 . . . x = ak )].
Andrzej Szalas
Datalog
address(John, Kungsgatan 12 )
likes(John, Marc).
Andrzej Szalas
Rules in Datalog
Andrzej Szalas
Rules in Datalog
Semantics
The intended meaning of the rule is that
[R1 (Z1 ) . . . Rk (Zk )] R(Z ),
where all variables that appear both in the rules head and body
are universally quantified, while those appearing only in the rules
body, are existentially quantified.
Example
Rule: R(X , c):Q(X , Z ), S(Z , X ) denotes implication:
X {Z [Q(X , Z ) S(Z , X )] R(X , c)}.
Andrzej Szalas
Andrzej Szalas
Rules
isA(zebra,mammal).
isA(whale,mammal).
isA(herring,fish).
isA(shark,fish).
lives(zebra,onLand).
lives(whale,inWater).
lives(frog,onLand).
lives(frog,inWater).
lives(shark,inWater).
Andrzej Szalas
canSwim(X):- isA(X,fish).
canSwim(X):- lives(X,inWater).
Based on the above facts and rules, can one derive that:
Datalog queries
Andrzej Szalas
The scenario
Consider a database containing information about book authors.
It is reasonable to store authors in one relation, say A, and book
titles in another relation, say T . The intended meaning of relations
is the following:
A(N, Id) means that the author whose name is N has its
identification number Id
T (Id, Ttl ) means that the author whose identification number
is Id is a (co-) author of the book entitled Ttl .
Examples
1
Andrzej Szalas
n, m, i , j
[(A(n, i ) A(n, j)) i = j]
[(A(n, i ) A(m, i )) n = m]
Andrzej Szalas
Andrzej Szalas
Andrzej Szalas
Andrzej Szalas
Exam-like exercise
Andrzej Szalas
Queries
1 Event(N,D,U), D>2006-02-03, U>10,
Related(N,project evaluation).
We need a new relation related directly or indirectly:
diRelated(N1,N2):- Related(N1,N2)
diRelated(N1,N2):- Related(N1,N3),
diRelated(N3,N2).
The required query:
diRelated(N1,given),
where given is the name of the given event.
Andrzej Szalas
Relations
Event(N,D,U) meaning that an event named N occurred in
date D and its duration has been U
Related(N1,N2) meaning that events N1 and N2 are
related to each other.
Integrity constraints
Related (N1, N2) Related (N2, N1)
NDUD U
[(Event(N, D, U) Event(N, D , U )) (D = D U = U )]
The scenario
Design a Datalog database for storing information about events.
Each event is characterized by its name, date and duration. In
addition, for each event the database contains information about
a number of related events. Formulate in logic queries selecting:
1
Andrzej Szalas
Summary
Andrzej Szalas
Modal logics
Modalities
Readings of modalities
Example
Suppose that the intended meaning of A is A is sure.
Then its dual, A, is defined to be:
def
A
(A) is sure
(A) is not sure
(A) is doubtful
A is doubtful
Andrzej Szalas
a possible reading of A
A is necessary
A is obligatory
always A
in the next time moment A
A is known
all program states satisfy A
A is provable
A is possible
A is allowed
sometimes A
in the next time momentA
A is believed
some program state satisfies A
A is not provable
Andrzej Szalas
necessary, possible
obligatory, allowed
always, sometimes, in the next time
known, believed
all (some) states of a program satisfy
(un)provable
Andrzej Szalas
aletic logics
deontic logics
temporal logics
epistemic logics
logics of programs
provability logics
Andrzej Szalas
Andrzej Szalas
Andrzej Szalas
-2
-1
...
def
def
Andrzej Szalas
def
Assume that time is discrete and linear, with time points labeled
by integers, as in the figure below.
...
Andrzej Szalas
A A
def
A A
A A
A A
def
def
def
def
def
def
def
def
A A
A A
A A
((A A) A) A
(A A) A.
Andrzej Szalas
Andrzej Szalas
=
=
=
=
=
=
=
=
Andrzej Szalas
KT4M
KT4G
KT4H
KT4Dum
KT4Grz
K4W
=
=
=
=
=
=
S4.1
S4.2
S4.3
D = Prior logic
KGrz = Grzegorczyk logic
KW = L
ob logic.
Andrzej Szalas
A
A
>
: A
...
s
>
: A
...
s
Andrzej Szalas
Andrzej Szalas
Example
Example continued
H
*
SR
1
2
3
T
1H
j
H = head
T = tail
S = start
H
*
does T hold?
does H hold?
does H hold?
T
1 H
j
What are answers to the same questions for the above structure?
Andrzej Szalas
Andrzej Szalas
Exercises
Multimodal logics
Andrzej Szalas
Examples
What modalities appear in the following sentences:
1
If you know what I believe to, then you might be wiser than
myself.
Andrzej Szalas
Temporal logics
Interpretation of ,
In temporal logics:
A is interpreted as A always holds
A is interpreted as A eventually holds.
Examples
(failure alarm)
(requestPrint print).
Andrzej Szalas
Andrzej Szalas
Models of time
Interpretations
We characterize time by interpretations hS, i, where
Eventuality properties
p q (there is a program state satisfying q reached by a
program after the state satisfying p)
(atFirst p) (atEnd q) (total correctness w.r.t.
conditions p and q)
p q (repeating a request p will force a response q)
Andrzej Szalas
Andrzej Szalas
Operator nexttime
Semantic tableaux
Andrzej Szalas
-, - and X -rules
We add the following rules to tableaux rules for classical
propositional calculus (recall that -rules have a conjunctive flavor
and -rules have a disjunctive flavor):
A
A
1
A
A
2
A
A
Semantic tableaux
1
A
A
2
A
A
Andrzej Szalas
A problem
Consider p
p
p,
p
6
p
Remark
Note that p is not a tautology.
X
A
A
A
A
Andrzej Szalas
X1
A
A
Discussion
Remark
Using the tableau from slide 204 one can construct a model
for p by transforming the cycle into an infinite branch. If
such a loop appears, one can stop the algorithm and answer
that the input formula is not a tautology.
To make this principle working we need to really make the
branch a model also when formulas of the form p (or p)
appear in the cycle. Namely, whenever such formula appears
in a node, there should be a future node containing p
(respectively, p).
Andrzej Szalas
Definition
A semantic tableau is completed if:
all its leaves contain a formula and its negation
or
tableau rules do not create new nodes.
A path is called fulfilling if:
whenever a node
reachable from n
whenever a node
reachable from n
Andrzej Szalas
Definition
A semantic tableau is closed if all its leaves contain a formula and
its negation.
Soundness and completeness
A formula A is unsatisfiable iff there is a closed tableau for A with
all cycles unfulfilling.
Andrzej Szalas
(p q) ( p q)
(p q), ( p q)
(p q),
p
(p q),
q
p q, p
p q, q
p, q, p
p, q, q
Andrzej Szalas
Summary
(p q) p
(p q) p
(p q), p
p q, (p q), p
p, q, (p q), p
p, q,
(p q), p
p, q,
(p q),
p
6
(p q), p
Andrzej Szalas
Exercise 1
Andrzej Szalas
Exercise 1 - solution
Translation
Andrzej Szalas
Exercise 1 - solution
Exercise 2
Hypothesis
After a semantical considerations one can state the hypothesis that
the robot should go to the right (expressed by right).
Proof
Will be carried out during the lecture.
Hint: it suffices to use resolution to chosen clauses, e.g.:
from (3) and (6) deduce shadowLeft left, so using (9)
deduce left
Definitions
R is reflexive iff x[R(x, x)]
using (1) together with left and then with center deduce
right.
Andrzej Szalas
Andrzej Szalas
Exercise 2 - solution of 1
Exercise 2 - solution of 1
Semantical check
Will be carried out during the lecture.
Formulation of 1
xy [R(x, y )]
Proof of 1
1.
2.
3.
4.
5.
6.
7.
8.
Andrzej Szalas
(res) : 1, 3
(res) : 2, 3
(res) : 5, 6
(res) : 4, 8
with
with
with
with
y
y
z
x
= f (x)
= f (x)
=x
= a.
Exercise 2 - solution of 2
Exercise 3
Semantical check
The answer is no. Will be carried out during the lecture.
1
Formulation of 2
R(y , x)]
xy [R(x, y )]
Andrzej Szalas
Exercise 3 - solution
Exercise 3 - solution
Translation
x[red(x) green(x) blue(x)]
xy [over (x, y ) below (x, y )]
xy [(red(x) green(y )) over (x, y )]
below (a, b)
green(b)
gren(a)
Semantical proof
Will be carried out during the lecture.
Andrzej Szalas
blue(a)
Andrzej Szalas
Exercise 3 - solution
Proof
Andrzej Szalas
(res) : 1, 7 with: x = a
(res) : 6, 8
(res) : 2, 4 with: x = a, y = b
(res) : 3, 5 with: y = b
(res) : 9, 11 with: x = a
(res) : 10, 12
Andrzej Szalas
Exercise 4 - solution
8.
9.
10.
11.
12.
13.
Exercise 4
Exercise 3 - solution
Clausal form
1.
2.
3.
4.
5.
6.
7.
Database design
Relations:
region(id, shape, size, color ) id is a unique id of the region
intersects(id1, id2) region id1 intersects region id2.
Integrity constraint (ids are unique):
x, y , y , z, z , u, u
[(region(x, y , z, u) region(x, y , z , u ))
(y = y z = z u = u )].
Integrity constraint (intersects is reflexive and symmetric):
x[intersects(x, x)]xy [intersects(x, y ) intersects(y , x)].
Andrzej Szalas
Andrzej Szalas
Exercise 4 - solution
Queries
1 all pairs consisting of intersecting regions, first of which is
small and the second is round and green:
region(X , , small , ), region(Y , round , , green ),
intersects(X , Y ).
2
: region(X , , medium , ),
region(Y , , large , ), path(X , Y ).
: aux(X , ).
Andrzej Szalas