Download as pdf or txt
Download as pdf or txt
You are on page 1of 57

Logic: introduction & propositional calculus

Logic: predicate calculus


Other topics

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Book chapter

2
2
3
4

5
6
7

11

Slide 2 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Typical environments of intelligent systems

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

a dealers point of view: shape, color, price, etc.


Andrzej Szalas

Slide 3 of 225

Andrzej Szalas

Slide 4 of 225

perception
language
logic

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Quantitative and symbolic reasoning

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 5 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

What are logics?

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

From sensors to higher level reasoning


6

Quantitative reasoning
algorithmic methods

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Incomplete,
inconsistent

data

Noisy,

incomplete

data

6 ...

Qualitative reasoning
6

Qualitative
Databases

...
6

Quantitative reasoning
6

...


...
Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Quantitative

Databases

)
Sensors,
cameras,...

Slide 6 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Modeling in logics

Logic (approximately) is the tool allowing us to perceive (specify


and reason about) the world through truth level of properties
(formulas) expressed in a given language with well defined syntax
and semantics.

fix a formal language (dictionary, grammar)


fix methods of correct reasoning
specify properties of the investigated reality the chosen
language obtaining a model
test the model by reasoning about properties of the reality

Logic

language + semantics/models (semantically)


language + deduction
(syntactically)

Andrzej Szalas

Slide 7 of 225

investigate the reality solely through the level of truth of the


expressed properties.

Andrzej Szalas

Slide 8 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Fixing the language

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Semantical presentation of logics

The language is adjusted to a given application area. For example,


1

talking about politics we use concepts like political party,


prime minister, parliament, program, etc.

talking about computer science we use concepts like


software, database, program, etc.

We may have different vocabularies, although some names can be


the same having different meanings.

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Semantical presentation depends on choosing models and


attaching interpretation of formulas in models.
If A is a formula and M is a model then we write M |= A to
indicate that A is true in M and M 6|= A to indicate that A is not
true in M.
If S is a set of formulas then M |= S denotes the fact that
for all A S, M |= A.
We say that a formula A is a consequence of a set of formulas S
if for any model M we have that M |= S implies that M |= A.

Slide 9 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Example

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 10 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Logical language

Assume that in a model M we have three objects: o1 being a red


car, o2 being a brown car and o3 being a red bicycle. Assume
further that in our language we have propositions:
car , bicycle, red, brown.
Let proposition car be T for o1 , o2 , bicycle be T for o3 , red be T
for o1 , o3 and brown be true for o2 .
Then:

Elements of a logical language


logical constants: true, false, denoting logical values T, F;
sometimes also another,
e.g., Unknown, Inconsistent
logical (propositional) variables (letters, atoms),
representing logical unknowns, e.g.,: p, q

M |= red or brown

M 6|= if car then brown

Andrzej Szalas

Logical language is defined by fixing logical connectives, operators,


dictionaries and syntax rules how to form formulas. Logical
connectives and operators have a fixed meaning. Dictionaries
reflect concepts of a given application area and are flexible.

relation symbols, representing relations,


e.g., =, , 
Slide 11 of 225

Andrzej Szalas

Slide 12 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

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

Why function/relation symbols rather


than functions/relations?

individual variables, representing objects, e.g., x, y , m, n

In natural language names are not objects they denote.


In logics symbols correspond to names.
Function/relation symbol is not a function/relation, but a name.
Comparing to natural language, in logic:
a symbol denotes a unique object.

function symbols, representing functions, e.g., +, , father ()

propositional connectives and operators allow one to create


more complex formulas from simpler formulas,
examples of connectives: and, or, implies,
examples of operators: for all, exists, knows,
always
auxiliary symbols, making notation easier to read
examples: (, ), [, ].
Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 13 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Bnf notation

S ::= S1 | . . . | Sn

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 14 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Propositional calculus

Bnf notation allows us to define syntax of languages. There are


two forms of rules:
rule
S ::= S1 . . . Sn

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

Propositional calculus investigates the validity of complex


sentences on the basis of truth values of sub-sentences.
Let P denote the set of propositional variables.
Truth values: T, F
Formulas:
fml ::= P | fml | fml fml | fml fml |
fml fml | fml fml | (fml ) | [fml ]
Convention
Brackets are used to make the notation unambiguous. To simplify
notation we often omit brackets, assuming that the order of
precedence from high to low is: , , , , .
For example, A B C D
 E F abbreviates
A ((B) C ) (D) (E F ).
Andrzej Szalas

Slide 16 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Propositional calculus

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Truth tables

Examples of propositional formulas


break pedal pressed slow down

engine on

motion
gear on

gas pedal pressed



gear on motion slow down
...

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

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

Truth tables: conjunction

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

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.

Eve is a student and works part-time in a lab.


This sentence is true when both Eve is a student
and Eve works part-time in a lab are true.
If one of these sentences if false, the whole conjunction is
false, too.

Students and pupils read books translates into


Students read books and pupils read books.

Marc is a driver who likes his job translates into the


conjunction Marc is a driver and Marc likes his job, so
connective and does not have to be explicit.

Truth table for conjunction


A
F
F
T
T

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Truth tables: disjunction

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Examples

Connective or
Connective or, denoted by , expresses the disjunction
of sentences.

Truth table for disjunction


A
F
F
T
T

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

B
F
T
F
T

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

AB
F
T
T
T

Slide 21 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Truth tables: implication

Sentence Marc went to a cinema or to a shop is false only


when Marc went neither to a cinema nor to a shop.

Students and pupils read books translates into


If a person is a student or is a pupil then (s)he reads books
compare this with the translation given previously and try
to check whether these translations are equivalent.

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 22 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Truth tables: equivalence

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).

Truth table for implication

Truth table for equivalence

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Truth table method

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Truth table method

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 25 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

A tautology is a formula which is T for all possible


assignments of truth values to atomic sentences.
A formula is satisfiable if it is T for at lest one such
assignment.
A formula which is F for all such assignments is called
a counter-tautology.

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

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

The same applies to any formula of the shape [(A)] A, no


matter what A is! For example,
It is not true that I do not say that John is a good
candidate for this position
implies
I do say that John is a good candidate for this
position.

Thus our initial formula is a tautology.

Andrzej Szalas

Slide 27 of 225

Andrzej Szalas

Slide 28 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Checking satisfiability

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Verifying counter-tautologies

Recall that a formula is satisfiable if there is at least one row in its


truth table, where it obtains value T.

Recall that a formula is a counter-tautology if in all rows in its


truth table it obtains value F.

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

B
F
T
F
T

B A
T
F
T
T

(2)

A (B A)
T
T
T
T

(2)
F
F
F
F

Formula (2) is F in all rows, thus it is a counter-tautology.

There are rows, where (1) is T, thus (1) is satisfiable.


Andrzej Szalas

[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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Example: DeMorgans laws

Slide 30 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Example: DeMorgans laws

DeMorgans laws are:


[(A B)] (A B)

(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

The following truth table proves (4):

(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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Example: implication laws

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Example: implication laws

Consider:

Consider:

(A B) (A B)

(5)

Let us check whether it is a tautology.


The following table does the job.
A
F
F
T
T

B
F
T
F
T

A
T
T
F
F

AB
T
T
F
T

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

(6)

Let us check whether it is a tautology.


The following table does the job.
A B
T
T
F
T

(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

Example: three atomic sentences

Let us return to the question about equivalence of two translations


of the sentence:
Students and pupils read books.
The two translations were:
1

Students read books and pupils read books

If a person is a student or is a pupil then (s)he reads books.

Translating those sentences into logic results in:


1. [s r ] [p r ]
2. [s p] r ,

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

(6)
T
T
T
T

Slide 34 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Example: three atomic sentences (continued)


We check the equivalence 1 2 :
s
F
T
F
T
F
T
F
T

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Summary

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

What is correct reasoning?

A correct reasoning is based on correct (sound) arguments.


A correct (sound) argument is one in which anyone who accepts its
premises should also accept its conclusions.

the notion of a logic


modeling in logic
semantical presentation of logics
elements of a logical language

To see whether an argument is correct, one does not judge


whether there are good reasons for accepting the premisses, but
whether person who accepted the premisses, for whatever reasons,
good or bad, ought also accept the conclusion.

propositional calculus
truth table method.

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 37 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Examples

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 38 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Proof systems

Examples of correct arguments


if x is a parent of y , and y is a parent of z,
then x is a grandparent of z
if A and B is true, then A is true.

Proof systems allow us to formalize correct reasoning. There are


many ways to define them. For example:
analytic tableaux (Beth, Smullyan)
Gentzen-like proof systems (natural deduction)

Examples of incorrect arguments


if A implies B then B implies A

Hilbert-like systems
resolution (Robinson)

if A or B is true, then A is true.

Andrzej Szalas

Slide 39 of 225

Andrzej Szalas

Slide 40 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

What is a proof system?

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Proof rules

Hilbert-like proof systems


Let us first illustrate the idea by Hilbert-like proof systems.
Hilbert-like proof systems consist of:
a set of axioms (i.e. obvious formulas accepted without
proof)
a set of proof rules (called also derivation or inference rules),
where any rule allows one to prove new formulas on the basis
of formulas proved already.

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 41 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Examples of known rules

Proof rules are usually formulated according


to the following scheme:
if all formulas from a set of formulas F are proved
then formula A is proved, too.
Such a rule is denoted by F A, often by F .
A
Formulas from set F are called premises (assumptions) and
formula A is called the conclusion of the rule.

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 42 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Examples of invalid rules


Affirming the consequent

Modus ponens (MP)


A

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Hilbert-like formal proofs

every axiom is provable


if the premises of a rule are provable then its conclusion is
provable, too.

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

The process of proving theorems can be formulated as the


following (nondeterministic) procedure, where formula A is the one
to be proved valid:
if A is an axiom or is already proved, then the proof
is done; otherwise:
select a set of axioms or a theorem proved already
select an applicable proof rule
apply the selected rule and accept its conclusion as
a new theorem
repeat the described procedure from the beginning.

Slide 45 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 46 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Hilbert proof system H for propositional calculus

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

Hilbert-like formal proofs

The set of provable formulas is defined as the (smallest) set of


formulas satisfying the following conditions:

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 47 of 225

axioms:
A (B A) 

A (B C ) (A B) (A C )
(B A) (A B)

rule (modus ponens):


A

AB
B

Soundness and completeness of H


The proof system H is sound,
i.e., any formula provable in H is a tautology.
The proof system H is complete,
i.e., any tautology is provable in H.
Andrzej Szalas

Slide 48 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Example

3
4
5

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Propositional calculus: tableaux

We prove A A.
1

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics



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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 49 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Example

A literal is an atom or negation of an atom.


For any formula A, {A, A} is a complementary pair of formulas.
A is the complement of A and A is the complement of A.
Semantic tableau for a formula A
A semantic tableau T is a tree with each node labeled with a set
of formulas, where T represents A in such a way that A is
equivalent to the disjunction of formulas appearing in all leaves,
assuming that sets of formulas labeling leaves are interpreted as
conjunctions of their members.

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 50 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

-formulas and -formulas

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Closed and open leaves

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Construction of a semantic tableau for a formula C

A leaf is called closed if it contains a complementary pair of literals.


Observe that our definition of a closed leaf differs a bit from
the one given in the book. We do not require that it contains
literals only so this definition leads to a more efficient construction.
If a leaf consists of literals only and contains no complementary
pair of literals then we call it open.
A tableau is completed if all its leaves are open or closed.

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 53 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Example

Initially, T consists of a single node labeled with {C }.


If T is completed then no further construction is possible.
Otherwise chose a leaf, say l , labeled with S containing
a non-literal and chose from S a formula D which is not a literal
and:
if D is an -formula
then create a successor of l and label it

with S {D} {1 , 2 }
if D is a -formula then create two
 new successors of l , the
first one labeled with S {D} {1 } and the second one
labeled with S {D} {2 }.
Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

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

Soundness and completeness


The construction of a tableau always terminates and leads to
a completed tableau. A completed tableau is closed iff all its leaves
are closed.
Let T be a completed tableau for a formula A.
Then A is unsatisfiable iff T is closed.
Proving with semantic tableaux
To prove that a formula A is a tautology we construct a completed
tableau for its negation A.
If the tableau is closed then A is a tautology (its negation is not
satisfiable). Otherwise A is not a tautology.

Andrzej Szalas

Slide 56 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

The Gentzen system G

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Gentzen systems are dual to tableaux in the sense that we directly


prove validity rather than unsatisfiability of formulas. Here we shall
concentrate on Gentzen systems, as defined originally.
Sequents
By a sequent we understand any expression of the form A B,
where A, B are finite sets of formulas.
Let A = {A1 , . . . , Ak } and B = {B1 , . . . , Bm }.
Then the sequent A B represents




A1 . . . Ak B1 . . . Bm ,

where it is assumed that the empty disjunction is F and the


empty conjunction is T.

Slide 57 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

The Gentzen system G

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 58 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Sequent-based rules and axioms


General form of rules

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Gentzen-like proofs

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Rules
Negation

We shall always have two rules for each connective or operator,


one when it appears at the lefthand side of the sequent and one
when it appears at the righthand side of the sequent.
By a sequent proof of a formula A we shall understand the
derivation starting from A and ending up in sequents for
which rules are no longer applicable. If all such final sequents are
axioms then A is a tautology otherwise it is not a tautology.

(l )

A, B, C D
A, C B, D

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

(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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

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

We do not have rules for implication, so replace it using a suitable


implication law and start with P (P Q):
P (P Q)
(r )
P, P Q
(r )
P, P, Q
(r )
P P, Q
Proof of (P Q) P

We use a suitable implication law and start with (P Q) P:


(P Q) P
(r )
(P Q), P
(r )
P Q P
(l )
P, Q P
Andrzej Szalas

Slide 64 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Derived rules for definable connectives

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Derived rules for definable connectives

Example: rule ( l ) for implication

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

Thus we have the following derived rule for implication:


( l )

(def )

A B, C D, E
A B, C D, E
(r )
A B, C , D, E
(r )
A, C B, D, E

Thus we have the following derived rule:

A, B C , D E
A, D B, E ; A, C , D E

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Soundness and completeness

A B, C D, E
A, C B, D, E

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 66 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Summary

The provided Gentzen proof system G is sound: if all leaves of


a derivation tree of A are axioms then A is a tautology.
It is complete: if A is a tautology then there is a derivation tree for
A with all leaves containing axioms.
(The above concerns formulas containing only connectives for
which we have rules or definitions which use such connectives.)

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

Gentzen system G for propositional calculus


derived rules.

Andrzej Szalas

Slide 68 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

NNF: Negation Normal Form

Examples
2
3
4

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Transforming formulas into NNF

Recall that a literal is a formula of the form A or A, where A is


an atomic formula. A literal of the form A is called positive and of
the form A is called negative.
We say that formula A is in negation normal form, abbreviated by
Nnf, iff it contains no other connectives than , , , and the
negation sign appears in literals only.

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

(p q s) t is in Nnf

(p q s) t is not in Nnf
r q s t is in Nnf

Any propositional formula can be equivalently transformed into the


Nnf by replacing subformulas according to the table below, until
Nnf is obtained.
Rule
1
2
3
4
5

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 69 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Transforming formulas into NNF

Example
[(p r ) ((q r ))]

[(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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 70 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

CNF: Conjunctive Normal Form

A clause is any formula of the form A1 A2 . . . Ak , where


k 1 and A1 , A2 , . . . , Ak are literals
A Horn clause is a clause in which at most one literal is
positive.

Formula A is in conjunctive normal form, abbreviated by Cnf,


if it is a conjunction of clauses. It is in clausal form if it is
a set of clauses (considered to be an implicit conjunction of
clauses).

Andrzej Szalas

Slide 72 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Examples

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Why Horn clauses are important?


Any Horn clause can be transformed into the form of implication:

1
2
3
4
5
6

[A1 A2 . . . Al ] B,

p q r is a clause but not a Horn clause

p q r as well as p q r are Horn clauses


(p q t) (s t) (p s t) is in Cnf

{(p q t), (s t), (p s t)} is in clausal form


(p q t) (s t) (p s t) is not in Cnf

{(p q t), (s t), (p s t)} is not in clausal form.

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

where all A1 , A2 , . . . , Al , B are positive literals. Such implications


are frequently used in everyday reasoning, expert systems,
deductive database queries, etc.
Examples
rain take umbrella,
(snow ice) cold weather,
(starterProblem cold weather) chargeBattery.

Slide 73 of 225

Andrzej Szalas

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Non-Horn clauses

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 74 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Transforming formulas into CNF

In the case of more positive literals a clause is equivalent to:


[A1 A2 . . . Al ] [B1 B2 . . . Bn ],
where all literals A1 , . . . , Al , B1 , . . . , Bn are positive.
Disjunction at the righthand side of implication causes
serious complexity problems.

Andrzej Szalas

Slide 75 of 225

Any propositional formula can be equivalently transformed into the


Cnf:
1

Transform the formula into Nnf

Replace subformulas according to the table below, until Cnf


is obtained.
Rule
6
7

Subformula
(A B) C
C (A B)

Andrzej Szalas

Replaced by
(A C ) (B C )
(C A) (C B)

Slide 76 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Example

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Applications of CNF

(fastFood restaurant) (walk park)

(restaurant (walk park))


(fastFood walk) (fastFood park)
(restaurant walk) (restaurant park)

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

(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

Resolution rule for propositional calculus

Resolution method has been introduced by Robinson (1965) and is


considered the most powerful automated proving technique.
Resolution rule, denoted by (res), is formulated as follows:
L,
L

where L is a literal and , are clauses.


The position of L and L in clauses does not matter.
The empty clause is equivalent to F.

Andrzej Szalas

logic programming and deductive databases

(7)

(fastFood (walk park)) (restaurant (walk park))


(fastFood walk) (fastFood park)

We then have the following conjunction of implications:

fastFood walk

^
fastFood park
restaurant walk

restaurant park.

rule-based reasoning and expert systems

(6)

Slide 79 of 225

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Examples

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Factorization rule for propositional calculus


Factorization rule, denoted by (fctr ):
Remove from a clause all repetitions of literals.

John sleeps John works,


John sleeps John doesnt work
John sleeps

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Resolution rule preserves satisfiability, while factorization preserves


equivalence.

Slide 81 of 225

Andrzej Szalas

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Resolution method

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 82 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Example

The method, where formula A is to be proved


1
2

transform A into the conjunctive normal form


try to derive the empty clause F by applying resolution (res)
and factorization (fctr )
if the empty clause is obtained then A is a tautology,
if the empty clause cannot be obtained no matter how (res)
and (fctr ) are applied, then conclude that A is not a tautology.

Soundness and completeness


Resolution method is sound: deriving F for A proves that A is
a tautology. It is complete: if a formula A is a tautology then there
is a derivation of F using the resolution method.

Andrzej Szalas

Slide 83 of 225

Prove that formula [(A B) (A)] B is a tautology:


1
2

negate: (A B) (A) B this formula is in the Cnf


obtaining the empty clause F:
1.
2.
3.
4.
5.

AB
A
B
B
F

the first clause


the second clause
the third clause
(res): 1, 2
(res): 3, 4

Andrzej Szalas

Slide 84 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Example of application of propositional reasoning


Consider the following sentences:
1

if the interest rate of the central bank will not be changed


then government expenses will be increased or new
unemployment will arise

if the government expenses will not be increased then taxes


will be reduced

if taxes will be reduced and the interest rate of the central


bank will not be changed then new unemployment will not
arise

if the interest rate of the central bank will not be changed


then the government expenses will be increased.

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 86 of 225

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Example continued

Translation of the considered sentences


1 (ir ) (ge un)
3

Lecture I: introduction
Lecture II: deductive systems
Lecture III: resolution

Example continued

Slide 85 of 225

Example continued

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

(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:

[(ir ) (ge un)]


[(ge) tx]
[(ir ) ge]

[(tx ir ) un]
Negation of the above formula

(ir ) ge.

[(ir ) (ge un)]


[(ge) tx]
[(tx ir ) un]
ir
ge
Andrzej Szalas

Slide 87 of 225

Andrzej Szalas

Cnf:

[ir ge un]
[ge tx]
[tx ir un]
ir
ge

Slide 88 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

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 un)]


[(ge) tx]
[(tx ir ) un]

[(ir ) ge]

Proof of the first implication


1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

[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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 90 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Quantifiers

In the classical logic we have two quantifiers:

negation normal form


conjunctive and clausal normal form
Horn clauses
resolution and factorization rules
resolution method.

Andrzej Szalas

Slide 91 of 225

the existential quantifier


there exists an individual x such that ...,
denoted by x
the universal quantifier
for all individuals x ...,
denoted by x.

Andrzej Szalas

Slide 92 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Examples
1

It is important that variables under quantifiers represent


individuals. In fact, we have the following hierarchy of logics:

Everybody loves somebody:

Relation R is reflexive:

zero-order logic (propositional), where we do not allow neither


variables representing domain elements nor quantifiers

first-order logic, where we allow variables representing domain


elements and quantifiers over domain elements (in this case
quantifiers are called first-order quantifiers)

second-order logic, where we additionally allow variables


representing sets of domain elements and quantifiers over sets
of elements (so-called second-order quantifiers),

third-order logic, where we additionally allow variables


representing sets of sets of domain elements and quantifiers
over sets of sets of elements (so-called third-order quantifiers)

etc.

x R(x, x)
3

Relation R is symmetric:
xy R(x, y ) R(y , x)

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

A hierarchy of logics

xy loves(x, y )
2

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Relation R is transitive:
xy z ((R(x, y ) R(y , z)) R(x, z))
Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 93 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Higher-order formulas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 94 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Syntax of predicate calculus

Examples
1

To like is to be pleased with: likes pleased


a formula of the zero-order logic

John likes everybody: x likes(John, x)


a formula of the first-order logic

John has no relationships with anybody: Rx R(John, x)


a formula of the second-order logic

No matter how the word good is understood, John has no


good relationships with anybody:
GoodRx Good(R) R(John, x)
a formula of the third-order logic.

Andrzej Szalas

Andrzej Szalas

Slide 95 of 225

Let x stands for an individual variable, a stands for a constant


symbol and p sands for a relation symbol.
argument
argument
argument list
argument list
atomic formula
formula
formula
formula
formula
formula

::=
::=
::=
::=
::=
::=
::=
::=
::=
::=

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

The scope of quantifiers

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Examples

The scope of a quantifier is the portion of a formula where it binds


its variables.
If a variable is in the scope of a quantifier then it is bound by the
quantifier.
Free variables are variables which are not in the scope of
a quantifier.

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Slide 97 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Semantics of predicate calculus

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 98 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Semantics of predicate calculus


Example
Interpretations for the formula x[p(a, x)] can be:

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

hN , {}, {0}i, hN , {}, {3}i, hN , {>}, {1}i,


where N is the set of natural numbers.
In the first case x[p(a, x)] is interpreted as x[ (0, x)]
(or, in a bit more readable infix notation, x[0 x]).
Assignments
Let V be the set of variables. An assignment I : V D is
a function which maps every variable to an element of the domain
of I. By I [xi di ] we denote the assignment the same as I
except that xi is mapped to di .
Andrzej Szalas

Slide 100 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Semantics of predicate calculus

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Semantic analysis: examples

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

Formula xy [p(x, y ) p(y , x)] is T, e.g., in an


interpretation, where p is assigned the relation = and is F in
an interpretation, where p is assigned the relation parent
between persons.

let A = p(c1 , . . . , cn ) be an atomic formula, where each ci is


either a variable xi or a constant ai . vI (A) = T iff
(d1 , . . . , dn ) R, where R is the relation assigned by I to p
and di D is assigned to ci either by I (if ci is a constant) or
by I (if ci is a variable)

Formula xy [p(x, y )] is T, e.g., in an interpretation with


natural numbers as the domain, where p is assigned the
relation and is F in an interpretation, where p is assigned
the relation >.

vI (A) = T iff vI (A) = F


vI (A1 A2 ) = T iff vI (A1 ) = T or vI (A2 ) = T
vI (x A) = T iff vI [xd] (A) = T for all d D

vI (x A) = T iff vI [xd] (A) = T for some d D.


Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 101 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 102 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Aristotelian forms

Aristotelian forms
The four Aristotelian forms of quantification are:
1

Andrzej Szalas

Slide 103 of 225

Examples
1

All students have to learn.

Some students have jobs.

No students are illiterate.

Some students do not like math.

Translation of Aristotelian forms into quantified formulas


1
2
3
4

all Ps are Qs translates into x [P(x) Q(x)]

some Ps are Qs translates into x [P(x) Q(x)]


no Ps are Qs translates into x [P(x) Q(x)]

some Ps are not Qs translates into x [P(x) Q(x)].


Andrzej Szalas

Slide 104 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Examples
1

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Translating natural language sentences

All students have to learn translates into:

We integrate information from two sources:


1 vocabulary (words in the sentence); here we get:

x [student(x) hasToLearn(x)]
2

constants (names of individuals), e.g., Eve, John


variables (representing indefinite individuals), e.g.,
corresponding to a, one, or appearing within quantifiers
all, some, etc.
concepts (sets of individuals), e.g., man, animal,
furniture; these are represented by one argument relation
symbols (e.g., man(x) means that x is a man)
relations (other than those formalizing concepts) showing the
relationships between constant and concepts.

Some students work translates into:


x [student(x) hasJob(x)]

No students are illiterate translates into:


x [student(x) illiterate(x)]

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

syntactic structure of the sentence; here we get:

Some students do not like math translates into:

knowledge about logical operators appearing in the sentence,


like connectives and quantifiers
knowledge how to combine constants, variables, concepts and
other relations.

x [student(x) likes(x, math)]


Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 105 of 225

Andrzej Szalas

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Examples

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 106 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

DeMorgans laws for quantifiers


DeMorgan laws for quantifiers are:

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

Slide 107 of 225

[x A(x)] [x A(x)]
[x A(x)] [x A(x)]
Examples
1

It is not the case that all animals are large


is equivalent to Some animals are not large.

It is not the case that some animals are plants


is equivalent to All animals are not plants.

xy z [friend(x, y ) likes(y , z)]


is equivalent to xy z [friend(x, y ) likes(y , z)].

What is the negation of Everybody loves somebody and


of Everybody loves somebody sometimes?
Andrzej Szalas

Slide 108 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Analogies between quantifiers and propositional


connectives

For all individuals x relation R(x) holds is equivalent to


R holds for the first individual
and R holds for the second individual
and R holds for the third individual
and . . .
Given a fixed set of individuals U = {u1 , u2 , u3 , . . .} we then have
that:
x U [R(x)] [R(u1 ) R(u2 ) R(u3 ) . . .]

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

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)].

Pushing quantifiers past connectives:


1
2

x[P(x) Q(x)] is equivalent to x[P(x)] x[Q(x)]


x[P(x) Q(x)] is equivalent to x[P(x)] x[Q(x)]

However observe that:


1
2

Similarly, Exists an individual x such that relation R(x) holds is


equivalent to
R holds for the first individual
or R holds for the second individual
or R holds for the third individual
or . . .
Given a fixed set of individuals U = {u1 , u2 , u3 , . . .} we then have
that:
x U [R(x)] [R(u1 ) R(u2 ) R(u3 ) . . .]
Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 110 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Tableaux

Null quantification.
Assume variable x is not free in formula P. Then:
1

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Analogies between quantifiers and propositional


connectives

Slide 109 of 225

Other laws for quantifiers


1

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

x[P(x) Q(x)] is not equivalent to x[P(x)] x[Q(x)]

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).

x[P(x) Q(x)] is not equivalent to x[P(x)] x[Q(x)]


Andrzej Szalas

Slide 111 of 225

Andrzej Szalas

Slide 112 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Tableaux

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Soundness and completeness

Construction of a semantic tableau for formula A


Initially T consists of a single node labeled with {A}. Until
possible choose an unmarked leaf l labeled with U(l ) and apply:
if U(l ) contains a pair of complementary literals
{p(a1 , . . . , ak ), p(a1 , . . . , ak ))} then mark the leaf closed
if U(l ) does not contain a pair of complementary literals and
contains non-literals, choose a non-literal A U(l )

if A is an or formula, apply rules provided in slide 54


if A is a formula, create a child node l for l and label l with
U(l ) = U(l) {(a)}, where a preferably is a constant
appearing in U(l).
If U(l) consists of literals and formulas only and for all
choices of a, U(l) = U(l ) then mark the leaf as open
if A is a formula, create a child node l for l and label l with
U(l ) = (U(l) {A}) {(a)}, where a is a constant not
appearing in U(l).
Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Closed and open branches


A branch in a tableau is closed if it terminates in a leaf marked
closed. Otherwise (it is infinite or terminates in a leaf marked
open), the branch is open.
Soundness
Let A be a formula and let T be a tableau for A. If all branches of
T are closed then A is unsatisfiable (equivalent to F).
Completeness
Let A be a valid formula (equivalent to T). Then there is
a tableau T for A with all branches closed.

Slide 113 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Example

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 114 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Summary

Proof of x[p(x) q(x)] [xp(x) xq(x)]


x[p(x) q(x)] [xp(x) xq(x)]

x[p(x) q(x)], [xp(x) xq(x)]

x[p(x) q(x)], xp(x)


x[p(x) q(x)], xq(x)

x[p(x) q(x)], p(a)


x[p(x) q(x)], q(b)

p(a) q(a), p(a)


p(b) q(b), q(b)

p(a), q(a), p(a)


p(b), q(b), q(b)
|
|
{z
}
{z
}
closed
closed
Andrzej Szalas

Slide 115 of 225

quantifiers, the scope of a quantifier


free and bound variables
syntax and semantics of predicate calculus
restricted quantifiers
translating natural language into predicate calculus
laws for quantifiers
tableaux.

Andrzej Szalas

Slide 116 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

The Gentzen system G

where it is assumed that the empty disjunction is F and the


empty conjunction is T.

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Rules

There is a close correspondence between Gentzen system and


tableaux. It is explored in the book by Ben Ari. Here we follow the
original style of presentation of G.
We define sequent calculus for the predicate calculus by accepting
axioms and rules as given for propositional calculus in slides 58
67. We have to provide rules for quantifiers.
Recall that By a sequent we understand any expression of the form
A B, where A, B are finite sets of formulas.
Let A = {A1 , . . . , Ak } and B = {B1 , . . . , Bm }.
Then the sequent A B represents




A1 . . . Ak B1 . . . Bm ,

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 117 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

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)

where a does not occur in A, B, D in application of (r ).


Existential 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)

where a does not occur in A, C , D in application of (l )


Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 118 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Soundness and completeness

Proof of formula x[P(x) Q(x)] [x P(x) x Q(x)]


x[P(x) Q(x)] [x P(x) x Q(x)]
x[P(x) Q(x)] [x P(x) x Q(x)]
x[P(x) Q(x)] x P(x), x Q(x)
x[P(x) Q(x)] x P(x), x Q(x), Q(a)
x[P(x) Q(x)] x P(x), x Q(x), Q(a), P(a)
x[P(x) Q(x)], P(a) Q(a) x P(x), x Q(x), Q(a), P(a)
Now applying (l ) creates two leaves:
x[P(x) Q(x)], P(a) x P(x), x Q(x), Q(a), P(a)
x[P(x) Q(x)], Q(a) x P(x), x Q(x), Q(a), P(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.

each containing an axiom.


Andrzej Szalas

Slide 119 of 225

Andrzej Szalas

Slide 120 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Example of practical reasoning


The scenario
Assumptions:
Car c is older than car d.
Every car older than d is cheap.
Car e is older than car c.
Every car older than c is older than d.
Conclusion: Car e is cheap.
Translation into logic
Assumptions:
O(c, d)
x[O(x, d) C (x)]
O(e, c)
x[O(x, c) O(x, d)].
Conclusion: C (e).
Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 121 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

The Hilbert system H for predicate calculus


We extend the proof system H defined in slide 48 for propositional
calculus by adding axioms:
[x A(x)] A(a)

x[A B(x)] [A x B(x)], provided that x is not free


in A
and the inference rule reflecting generalization:
A(a)
.
x A(x)

Note that in presence of assumptions U, this rule is formulated as


U A(a)
,
U x A(x)
where a does not appear in U.
Andrzej Szalas

Slide 123 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Example of practical reasoning

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 122 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

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

Slide 124 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Examples

2
3

2
3

Proof of x[A(x) B(x)] [x A(x) x B(x)]

xA(x) A(a)

(axiom)
(PC)

A(a) xA(x)

(deMorgan, PC)

A(a) xA(x)

Proof of x A(x) x A(x)


1

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Examples

Proof of A(a) x A(x)


1

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

x A(x) A(a)

(axiom)

(proof above)

x A(x) x A(x)

(generalization).

A(a) x A(x)

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

x[A(x) B(x)], x A(x) x A(x)


x[A(x) B(x)], x A(x) A(a)

Examples

(axiom)

x[A(x) B(x)], x A(x) x[A(x) B(x)] (assumption)


x[A(x) B(x)], x A(x) A(a) B(a)
x[A(x) B(x)], x A(x) B(a)

(axiom)

(PC)

x[A(x) B(x)], x A(x) x B(x)

(generalization)

x[A(x) B(x)] x A(x) x B(x)

(deduction)

x[A(x) B(x)] [x A(x) x B(x)]

Slide 125 of 225

Andrzej Szalas

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

(assumption)

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

(deduction).

Slide 126 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Examples

Derived rule: generalization 1


Using modus ponens and the reasoning from slide 126, we have
the following derived rule:
A(x) B(x)
.
x A(x) x B(x)

Proof of xy A(x, y ) y xA(x, y )


1
2
3
4
5
6
7

Andrzej Szalas

Slide 127 of 225

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)

x[y x A(x, y ) y A(x, y )]


y xA(x, y ) xy A(x, y )

xy A(x, y ) y xA(x, y )

(generalization)
(axiom)
(PC)

xy A(x, y ) y xA(x, y )

Andrzej Szalas

Slide 128 of 225

(deMorgan).

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Summary

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

PNF: Prenex Normal Form


We say A is in prenex normal form, abbreviated by Pnf, if all its
quantifiers (if any) are in its prefix, i.e., it has the form:
Q1 x1 Q2 x2 . . . Qn xn [A(x1 , x2 , . . . , xn )],

Gentzen proof system G.

where n 0, Q1 , Q2 , . . . , Qn are quantifiers (, ) and A is


quantifier-free.

Hilbert proof system H.

Examples
1
2
3

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 130 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Example

Replace subformulas according to the table below, until Pnf


is obtained, where Q denotes any quantifier, or .

Andrzej Szalas

A(x) x [B(x, y ) C (y )] as well as


x [A(x) B(x, y ) yC (y )] are not in Pnf.
Andrzej Szalas

Any predicate formula can be equivalently transformed into the


Pnf
1 Transform the formula into Nnf

Rule
12
13
14
15
16

xy [A(x) B(x, y ) C (y )] is in Pnf

Slide 129 of 225

Transforming formulas into PNF

A(x) B(x, y ) C (y ) is in Pnf

Replaced by
Qz A(z)
x [A(x) B(x)]
x [A(x) B(x)]
Qx (A B)
Qx (A B)

Transforming a formula into Pnf


A(z) x [B(x, u) yC (x, y ) z D(z)]

x {A(z) [B(x, u) yC (x, y ) z D(z)]}

(15)

(16)

(15)

x {A(z) y [B(x, u) C (x, y ) z D(z)]}


(16)

xy {A(z) [B(x, u) C (x, y ) z D(z)]}

xy {A(z) t [B(x, u) C (x, y ) D(t)]}


xy t {A(z) [B(x, u) C (x, y ) D(t)]}.

xy {A(z) z [B(x, u) C (x, y ) D(z)]}

Andrzej Szalas

Slide 132 of 225

(12)

(15)

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Functions and terms

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Functions and terms

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Examples
1

Let mother : Persons Persons have the commonsense


meaning. Then mother (x) is a function.

son(x) is not a function (why?)

x + y , x y (infix notation);
what notation + : [0, 1] [2, 5] [2, 6] means?

x + y , 2x 2 + 3x + 7, x 2 + 2xy + y 3 are examples of special


notations.

Slide 133 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Functions and terms

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 134 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

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

Slide 135 of 225

Andrzej Szalas

Slide 136 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Semantics

vI (ai ) = di

vI (x) = I (x), where x V

A formula is in the Skolem normal form iff it is in the Pnf and


contains no existential quantifiers.
Transforming formulas into the Skolem normal form
Eliminate existential quantifiers from left to right:

vI (fi (t1 , . . . , tn )) = Fi (vI (t1 ), . . . , vI (tn )).

when we have xA(x) then remove x and replace x in A by a


new constant symbol

when we have x1 . . . xk xA(x1 , . . . , xk , x) then remove x


and replace x in A by a term f (x1 , . . . , xk ), where f is a new
function symbol.

For atomic formulas:


vI (pi (t1 , . . . , tn )) = T iff (vI (t1 ), . . . , vI (tn )) Ri .

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 137 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Skolem normal form

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 138 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Generalizing resolution to predicate calculus


Consider the following two formulas:

Example
1

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Skolem normal form

Let t be a term, I an interpretation and I an assignment. The


value of t under I , denoted by vI (t) is defined by

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

x [rare(x) expensive(x)]
y [expensive(y ) guarded(y )]

Skolem normal form for


xy zu[R(x, y , z, u)]
is y z[R(a, y , z, f (y , z)]

Skolem normal form for


xy zuw [R(x, y , z, u, w )]
is y u[R(a, y , g (y ), u, h(y , u)].

Important
A formula is satisfiable iff its Skolem normal form is satisfiable.

Andrzej Szalas

Slide 139 of 225

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

Slide 140 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Generalizing resolution to predicate calculus

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

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

We would like to conclude expensive(VermeerPainting ).


But again (res) cannot be applied
We need a general method to solve such problems. It is offered by
unification.

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 141 of 225

Expressions father (x) and mother (father (John)) cannot be


unified.

Andrzej Szalas

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Expression trees

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 142 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

The unification algorithm

Expressions can be represented as trees. For example, expressions


f (g (x, h(y ))) and f (g (f (v ), z)) can be represented as:

f (g (x, h(y )))

f (g (f (v ), z))

f
g

f
g

To unify expressions father (x) and father (mother (John)) it


suffices to substitute x by expression mother (John).

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

Slide 143 of 225

1
2
3

traverse trees corresponding to expressions e, e


if the trees are identical then stop
let t and t be subtrees that have to be identical, but are not
if t and t are function symbols/constants then conclude that
the substitutions do not exist and stop
otherwise t or t is a variable; let t be a variable, then
substitute all occurrences of t by the expression represented by
t assuming that t does not occur in t (if it occurs then
conclude that the substitutions do not exist and stop)

In order to unify expressions we have to detect nonidentical


sub-trees and try to make them identical.
Andrzej Szalas

Input: expressions e, e
Output: substitution of variables which makes e and e identical
or inform that such a substitution does not exist.

change the trees, according to the substitution determined in


the previous step and repeat from step 2.
Andrzej Szalas

Slide 144 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Resolution rule for the predicate calculus


Resolution rule, denoted by (res), is formulated for first-order
clauses as follows:
L1 (t1 ) . . . Lk1 (tk1 ) Lk (tk )
s1 ) . . . Ml (
sl )
Lk (tk ) M1 (
,

L1 (t1 ) . . . Lk1 (tk1 ) M1 (


s1 ) . . . Ml (
sl )
where:
L1 , . . . , Lk , M1 , . . . , Ml are literals
tk and tk are unifiable
primed expressions are obtained from non-primed expressions
by applying substitutions unifying tk and tk .

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 145 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Factorization rule for the predicate calculus


The rule
Factorization rule, denoted by (fctr ):
Unify some terms in a clause and remove from the
clause all repetitions of literals.
Examples
1

(fctr ) with x = Jack, y = mother (Eve):


parent(x, y ) parent(Jack, mother (Eve))
parent(Jack, mother (Eve))
(fctr ) with z = x, u = y :
P(x, y ) S(y , z, u) P(z, u)
P(x, y ) S(y , x, y )
Andrzej Szalas

Slide 147 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Examples

(res) with x = John, y = Mary :


parent(x, y ) x = father (y ) x = mother (y )
parent(John, Mary )
John = father (Mary ) John = mother (Mary )
(res) with y = x:
rare(x) expensive(x), expensive(y ) guarded (y )
rare(x) guarded (x)
(res) with x = VermeerPainting :
rare(x) expensive(x), rare(VermeerPainting )
expensive(VermeerPainting )

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 146 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Example of proof by resolution

Consider the following formulas, where med stands for medicine


student (recall that clauses are assumed to be implicitly
universally quantified):

[med(x) attends(x, y )] [likes(x, y ) obliged(x, y )]

likes(x, math) med (x)


=
med(John)

attends(John, math)
Do the above formulas imply that John is obliged to take math?

Andrzej Szalas

Slide 148 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Example of proof by resolution

Example of proof by resolution

We consider implication:

Proof
1 med(x) attends(x, y ) likes(x, y ) obliged(x, y )

obliged(John, math)

To apply the resolution method we negate this formula and obtain


obliged(John, math),
i.e.,
[med (x) attends(x, y )] [likes(x, y ) obliged(x, y )]
likes(x, math) med(x)
med(John)
attends(John, math)
obliged(John, math).
Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

med (John)

attends(John, math)

obliged(John, math)

med(x) attends(x, math) med(x) obliged(x, math)


(res): 1, 2 with y = math

med(x) attends(x, math) obliged(x, math) (fctr ): 6

attends(John, math) obliged(John, math) (res): 3, 7 with


x = John

obliged(John, math) (res): 4, 8

10

(res): 5, 9.
Andrzej Szalas

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 150 of 225

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Example

Prove that xP(a, x, x) xy z[P(x, y , z) P(f (x), y , f (z))]


implies zP(f (a), z, f (f (a))).
We start with negating the above implication, transforming it to
the clausal form and then try to derive F.
2

likes(x, math) med(x)

Slide 149 of 225

Example

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

P(a, x , x )

for clarity x is renamed

P(x, y , z) P(f (x), y , f (z))

P(f (a), z, f (f (a)))


(x ))

P(f

(a), x , f

(res): 3, 4 with x = z = f (a)

(res): 1, 2 with x = a, y =

Andrzej Szalas

Prove that xy [P(x, y ) P(a, y )] implies xyP(x, y )


We start with negating the above implication, transforming it to
the clausal form and then try to derive F.

Slide 151 of 225

x , z

P(x, y ) P(a, y )
P(x , g (x ))

P(a, y )

g is a Skolem function and x is renamed

(fctr ): 1 with x = a

(res) with x = a and y = g (a).

Andrzej Szalas

Slide 152 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture IV: introduction & tableaux


Lecture V: deductive systems
Lecture VI: resolution

Summary

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

What is a database?
A database is any finite collection of related data.
Examples

prenex normal form


functions and terms
Skolem normal form
unification
resolution for predicate calculus
factorization for predicate calculus

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 153 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

A closer look at databases

a figure illustrating dependencies between shapes on a plane

a phone book

a Swedish-to-English dictionary

a library

an electronic mailbox

a personnel database of a department

an accounting database

a flight reservation database

...
Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 154 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

A closer look at databases

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

Slide 155 of 225

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

Slide 156 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Example: a mobile phone book

Database
atomic data:
= first&last name,
phone number
a record:
{Eve Lin, 0701 334567}
a table:
{Eve Lin, 0701 334567}
{John Smith, 0701 334555}
...

Example: a mobile phone book continued

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

Slide 157 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

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

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

The architecture of deductive databases

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 )

Slide 158 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Common assumptions

intensional databases

Integrity

constraints

Extensional
Database

}|
s

.....
+

deduction mechanisms
6

.....

Andrzej Szalas

Slide 159 of 225

If c1 , . . . , cn are all constant symbols appearing


in the database, then it is assumed that

Queries

UNA (Unique Names Axiom):


for all 1 i 6= j n we have that ci 6= cj
DCA (Domain Closure Axiom):
x [x = c1 . . . x = cn ]

CWA (Closed World Assumption):


if R(
a1 ), . . . , R(
ak ) are all facts about R stored in the
database then we have:

x [R(
x ) (
x = a1 . . . x = ak )].

Andrzej Szalas

Slide 160 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Datalog

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Atomic queries about facts

Extensional databases, integrity constraints and queries are present


in traditional database management systems.
Deductive databases offer means to store deductive rules
(intensional databases) and provide a deduction machinery.
The basic language for deductive databases is Datalog.
Facts in Datalog
Facts in Datalog are represented in the form of relations
name(arg1 , . . . , argk ), where name is a name of a relation and
arg1 , . . . , argk are constants.
Examples
1

address(John, Kungsgatan 12 )

likes(John, Marc).
Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Atomic queries are of the form


name(arg1 , . . . , argk ),
where arg1 , . . . , argk are constants or variables, where is also
a variable (without a name, do-not-care variable).
Examples
1

likes(John, Marc) does John like Marc?

likes(X , Marc) who likes Marc?


(compute X s satisfying likes(X , Marc))

likes(John, X ) whom likes John?

likes(X , Y ) compute all pairs hX , Y i such that likes(X , Y )


holds.

Slide 161 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Rules in Datalog

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 162 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Rules in Datalog

Rules in Datalog are expressed in the form of (a syntactic variant


of) Horn clauses:
R(Z ):R1 (Z1 ), . . . , Rk (Zk )
where Z, Z1 , . . . , Zk are vectors of variable or constant symbols
such that any variable appearing on the lefthand side of :
(called the head of the rule) appears also on the righthand side of
the rule (called the body of the rule).

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

Slide 163 of 225

Andrzej Szalas

Slide 164 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Example of Datalog facts and rules


Facts

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Example of Datalog facts and rules continued

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

canSwim(X):- isA(X,fish).
canSwim(X):- lives(X,inWater).
Based on the above facts and rules, can one derive that:

Slide 165 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Datalog queries

a whale can swim?

a frog can swim?

a salmon can swim?

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 166 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Example: authors database

A Datalog query is a conjunction of literals (conjunction is denoted


by comma). Assumptions UNA, DCA and CWA allow one to
formally define the meaning of queries as minimal relations which
make queries logical consequences of facts and rules stored in the
database. Intuitively,
if a query does not have free variables, then the answer is
either T or F dependently on the database contents

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:

if a query contains variables, then the result consists of all


assignments of values to variables, making the query T.

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

isA(X,mammal) returns all Xs stored as mammals

isA(X,mammal), can swim(X)


returns all mammals listed in the database that can swim.
Andrzej Szalas

Slide 167 of 225

Andrzej Szalas

Slide 168 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Example: authors database continued


The scenario
Now, for example, one can define a new relation Co(N1, N2),
meaning that authors N1 and N2 co-authored a book:
Co(N1,N2):- A(N1,Id1), T(Id1,B),
A(N2,Id2), T(Id2,B), N1=/= N2.
Note that the above rule reflects the intended meaning provided
that authors have unique Id numbers, i.e., that the following
integrity constraint holds:

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Example: authors database continued

Querying the author database


In the authors database:
Co(Widom,Ullman) returns T iff the database contains
a book co-authored by Widom and Ullman
Co(N,Ullman) returns a unary relation consisting of all
co-authors of Ullman.

n, m, i , j
[(A(n, i ) A(n, j)) i = j]
[(A(n, i ) A(m, i )) n = m]

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 169 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Predicate logic as a query language

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 170 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Example: train and bus connections

Assume we have relations:


In fact, query language can easily be made more general by
allowing all first-order formulas to be database queries. For
example, query
X , Y [T (X , Y ) Z (T (X , Z ) Z 6= Y )]
returns T iff any person in the database is an author of at least
two books.

bus(p1 , p2 ) meaning that there is a direct bus connection


between places p1 and p2
train(p1 , p2 ) meaning that there is a direct train connection
between places p1 and p2 .
We define a new relation connected(p1 , p2 ) meaning that places p1
and p2 are connected by train/bus connections, perhaps indirectly
(changes of busses and trains might be necessary):
def

connected(p1 , p2 ) [bus(p1 , p2 ) train(p1, p2 )


q(connected (p1 , q) connected(q, p2 ))].

Andrzej Szalas

Slide 171 of 225

Andrzej Szalas

Slide 172 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Exam-like exercise

all events later than 2006-02-03, whose duration greater than


10 and which are related to an event named project
evaluation
all events related (maybe indirectly) to a given event (a given
event E is indirectly related to an event F if there are events
E1 , . . . , Ek with k 1 such that E is related to E1 , E1 is
related to E2 , . . ., Ek is related to F .

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

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 )]

Slide 173 of 225

Exam-like exercise continued

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Exam-like exercise continued

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 175 of 225

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 174 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Summary

logical (deductive) database


extensional and intensional databases
integrity constraints
UNA, DCA and CWA
Datalog
querying deductive databases.

Andrzej Szalas

Slide 176 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Modal logics

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Modalities

Extensional and Intensional operators


Extensional operators allow to substitute equal by equal and
equivalent by equivalent. Intensional operators violate this
principle. Intensional operators give rise to so-called modal
operators (modalities, in short). Logics allowing such operators are
called modal logics and sometimes intensional logics.
Example
Consider the operator Knows(x, y ) meaning that person x knows
who is person y . Assume that Knows(Jack, X ) and that
Knows(Jack, Mary ). Here we assume that X is a masked person.
It might, however, happen that Mary = X . If expression Knows
was extensional, one could then replace X by Mary and obtain
Knows(Jack, Mary ) leading to an obvious contradiction.
Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 177 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 178 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Types of modal logics

Modalities  and have many possible readings, dependent on


a particular application. The following table summarizes the most
frequent readings of modalities.
a possible reading of A

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

Boxes and diamonds


In the simplest case one deals with a single one-argument modality
def
 and its dual , i.e., A A.

Slide 179 of 225

The types of modal logics reflect the possible readings of


modalities. The following table summarizes types of logics
corresponding to the possible readings of modalities.
Reading of modalities

Type of modal logic

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

Slide 180 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

How to chose/design a logic for a particular application

Recall that there are two approaches to defining logics, the


semantical and syntactical approach. In consequence there are two
approaches to chosing/defining modal logics suitable for a given
application:
1

syntactical approach, which depends on providing a set


of axioms describing the desired properties of modal operators
semantical approach, which starts with suitable models and
then develops syntactic characterization of modalities.

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 181 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Example: syntactical approach


Suppose we are interested in formalizing knowledge operator. One
can postulate, or instance, the following properties:
1
2
3

A A if A is known then A is believed

A A if A is known then it actually holds


A A if A holds then it is believed.

There are many important questions at this point, including:


are the properties consistent?
do the properties express all the desired phenomena?
is a property a consequence of another property?
Usually answers to such questions are given by semantic
investigations.
Andrzej Szalas

Slide 183 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

How to chose/design a logic for a particular application

The applications might, e.g., be:


temporal reasoning
understanding (fragments of) natural language
commonsense reasoning
specification and verification of software
understanding law and legal reasoning
etc.

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 182 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Example: semantical approach


Consider temporal logic, where A means always A and A
means sometimes A.
In order to define meaning of  and we first have to decide what
is the time structure, e.g.,
consisting of points or intervals?
continuous or discrete?
linear or branching?
is there the earliest moment (starting point) or there is an
unbounded past?
is there the latest moment (end point) or there is an
unbounded future?

Andrzej Szalas

Slide 184 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Example: semantical approach

-2

-1

...

Now always A and sometimes A can be more or less be


defined as follows:
always A

def

i [A is satisfied in time point i ]

def

sometimes A i [A is satisfied in time point i ]

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 185 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Lemmons classification of modal logics


Some well-known axioms
D
T
4
E
B
M
G
Grz
Dum
W

def

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Lemmons classification of modal logics

Assume that time is discrete and linear, with time points labeled
by integers, as in the figure below.

...

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lemmon introduced a widely accepted classification of modal


logics, defined below.
The basis for Lemmons classification is the logic K.
K is defined to extend the classical propositional logic
by adding rules:
(A B)
1 rule (K):
A B
A
2 rule (Gen):
A
Other normal modal logics are defined by additional axioms
expressing the desired properties of modalities.

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 186 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Lemmons classification of modal logics


D comes from deontic

A A

T is a traditional name of the axiom (after Feys)

def

A A

E comes from Euclidean (it is often denoted by 5)

A A

M comes after McKinsey

A A

Grz comes after Grzegorczyk

((A A) A) (A A)

W comes from reverse well founded (it is also known as the


L
ob axiom).

def

def

def

def

def

def

def

def

A A

4 is characteristic for logic S4 of Lewis

A A

B comes after Brouwer

A A

G comes after Geach

((A A) A) A

Dum comes after Dummett

(A A) A.
Andrzej Szalas

Slide 187 of 225

Andrzej Szalas

Slide 188 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Lemmons classification of modal logics

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Lemmons classification of modal logics

In Lemmons classification KX0 ...Xm denotes the logic extending


K in which formulas X0 , ..., Xm are accepted as axioms.
Some well-known modal logics
Some well-known modal logics
KT
KT4
KT4B
K4E
KD
KD4
KD4B
KTB

=
=
=
=
=
=
=
=

T = logic of Godel/Feys/Von Wright


S4
KT4E = S5
K45
deontic T
deontic S4
deontic S5
Brouwer logic

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

KT4M
KT4G
KT4H
KT4Dum
KT4Grz
K4W

=
=
=
=
=
=

S4.1
S4.2
S4.3
D = Prior logic
KGrz = Grzegorczyk logic
KW = L
ob logic.

Slide 189 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Kripke semantics for modal logics


Possible worlds
The basis for the Kripke semantics (in fact, similar semantics has
been defined a couple of years earlier by Kanger. Also, in the same
year, a similar semantics has been given by Hintikka and by
Guillaume) is the universe of possible worlds (states). Formulas are
evaluated in the so-called actual world. The other worlds,
alternatives to the actual world correspond to possible situations.
Modalities  and have the following intuitive meaning:

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 190 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Kripke semantics for modal logics

A
A

>
: A

...
s

>
: A

...
s

formula A holds in a given world w , if A holds in all worlds


alternative for w
formula A holds in a given world w , if A holds in some world
alternative for w .

Andrzej Szalas

Slide 191 of 225

Andrzej Szalas

Slide 192 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Example

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Example continued

Consider the situation where one drops a coin twice.


The following Kripke structure describes all possible situations.
*

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 193 of 225

Andrzej Szalas

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Exercises

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 194 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Multimodal logics

In many applications one needs to introduce many modalities. In


such a case we have multimodal logics.
1

Design a logic for formalizing the reasoning about perception,


where A is intended to mean that an event satisfying
formula A is being observed by a subject.
Propose a deontic logic (for obligatory allowed
modalities)
Characterize a commonsense implication.

Andrzej Szalas

Slide 195 of 225

Examples
What modalities appear in the following sentences:
1

When it rains one ought to take umbrella.

It is necessary that anyone should be allowed to have right to


vote.

If you know what I believe to, then you might be wiser than
myself.

Andrzej Szalas

Slide 196 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Temporal logics

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Temporal properties of programs

Invariance (safety) properties

Interpretation of ,
In temporal logics:
A is interpreted as A always holds
A is interpreted as A eventually holds.
Examples
(failure alarm)

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

(atFirst p) (atEnd q) (partial correctness w.r.t


conditions p and q, where propositional variable atFirst is true
only at the beginning of the specified program, while atEnd is
true only when the program reaches its terminal state)
(q p) (the program cannot enter critical regions p and
q simultaneously (mutual exclusion)).

(requestPrint print).

Andrzej Szalas

p q (all states reached by a program after the state


satisfying p will satisfy q)

Slide 197 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Temporal properties of programs

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 198 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

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)

p q (permanent holding a request p will force a


response q).

S = {s1 , . . . , sn } is a set of states (worlds)

is a binary relation on S; the intended meaning of (s, s ) is


that s is a future of s. We often write s (s) to indicate
that (s, s ) holds.
Time is usually characterized semantically. Axioms reflect the
required properties.
Examples of correspondences between axioms and time structure
A A relation is reflexive
A A relation is transitive.

Andrzej Szalas

Slide 199 of 225

Andrzej Szalas

Slide 200 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Operator nexttime

s, |= A iff there is s (s) such that s , |= A.


We define to be the reflexive and transitive closure of . In such
a case we have:
|= p p
|= p p.
Linear time is characterized by axiom A A.

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Semantic tableaux

Assume we have a binary relation on states. The intended


meaning of s (s) is that the state s occurs in the next time
moment. The nexttime operator, denoted by is defined by

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

-, - 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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 202 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

A problem

Building semantic tableaux


For classical propositional connectives and temporal - and
-formulas the construction is traditional.
If a leaf l consists only of literals and formulas of the form:
A1 , . . . , Am , Am+1 , . . . , An ,
then
if A1 , . . . , Am , Am+1 , . . . , An is a contents of a node l which
is an ancestor of l then make l a successor of l
otherwise create a new successor node containing formulas:
A1 , . . . , Am , Am+1 , . . . , An

Consider p

p 

p, p
6
p

Remark
Note that p is not a tautology.

(observe that we do not include literals which have not been in


the scope of ).
Andrzej Szalas

Slide 203 of 225

X
A
A

The status of X -rules


X -rules are used to build the contents of the next node.

Slide 201 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

A
A

Andrzej Szalas

Slide 204 of 225

X1
A
A

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Discussion

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Completed and closed tableaux

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 205 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Semantic tableaux: soundness and completeness

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

n contains A then there is a node n


along the path and containing A
n contains A then there is a node n
along the path and containing A.

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 206 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Semantic tableaux: example


(p q) ( p q)

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

Slide 207 of 225

(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

Slide 208 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Semantic tableaux: example

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

modal operators (modalities)


possible readings of modalities
frequently considered types of modal logics
Lemmons classification of modal logics
multi-modal logics
temporal logics
properties expressible by temporal formulas
Semantic tableaux for temporal logic of linear time.

Slide 209 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Exercise 1

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 210 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Exercise 1 - solution
Translation

Translate the following sentences and assumptions concerning


a robot behavior into a set of propositional formulas:
It is possible to go to the left or to the center or to the right.
Video camera detects an obstacle in the center or to the right.
It also detects that to the left there is an obstacle or a
shadow. There is a shadow to the left of any obstacle. Do not
go towards a shadow nor towards an obstacle.
What directions can be chosen in (1) assuming that a robot
can chose only one direction? Prove your claim syntactically
using a chosen proof system.

Andrzej Szalas

Slide 211 of 225

(1)left center right


(2)obstacleCenter obstacleRight
(3)obstacleLeft shadowLeft
(4)obstacleCenter shadowLeft
(5)obstacleRight shadowCenter
(6)obstacleLeft left
(7)obstacleCenter center
(8)obstacleRight right
(9)shadowLeft left
(10)shadowCenter center
(11)shadowRight right
Andrzej Szalas

One direction only:


(a)left (center right)
(b)center (left right)
(c)right (left center )

Slide 212 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Exercise 1 - solution

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

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

from (2) and (5) deduce obstacleCenter shadowCenter , so


using (7) deduce shadowCenter center , which together
with (10) gives center

Consider a binary relation R.


1

Check semantically whether transitivity, symmetry and


seriality of R together imply reflexivity of R.

Check semantically whether transitivity, reflexivity and seriality


of R together imply symmetry of R.

Prove your claims obtained in (1) and (2) syntactically using


chosen proof systems.

Definitions
R is reflexive iff x[R(x, x)]

R is transitive iff xy z[(R(x, y ) R(y , z)) R(x, z)]


R is symmetric iff xy [R(x, y ) R(y , x)]

using (1) together with left and then with center deduce
right.
Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 213 of 225

Andrzej Szalas

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Exercise 2 - solution of 1

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 214 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Exercise 2 - solution of 1

Semantical check
Will be carried out during the lecture.
Formulation of 1

xy z[(R(x, y ) R(y , z)) R(x, z)]


xy [R(x, y ) R(y , x)]
x[R(x, x)]

xy [R(x, y )]

Proof of 1 by resolution - negated

xy z[(R(x, y ) R(y , z)) R(x, z)]


xy [R(x, y ) R(y , x)]
xy [R(x, y )]
x[R(x, x)]
Andrzej Szalas

R is serial iff xy [R(x, y )].

Slide 215 of 225

Proof of 1
1.
2.
3.
4.
5.
6.
7.
8.

R(x, y ) R(y , z) R(x, z)


R(x, y ) R(y , x)
R(x, f (x))
R(a, a)
R(f (x), z) R(x, z)
R(f (x), x)
R(x, x)
F

Andrzej Szalas

(res) : 1, 3
(res) : 2, 3
(res) : 5, 6
(res) : 4, 8

Slide 216 of 225

with
with
with
with

y
y
z
x

= f (x)
= f (x)
=x
= a.

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Exercise 2 - solution of 2

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Exercise 3

Semantical check
The answer is no. Will be carried out during the lecture.
1

Formulation of 2

xy z[(R(x, y ) R(y , z)) R(x, z)]


xy [R(x, y )
x[R(x, x)]

R(y , x)]

xy [R(x, y )]

Proof of 2 by resolution - negated

xy z[(R(x, y ) R(y , z)) R(x, z)]


x[R(x, x)]
xy [R(x, y )]
xy [R(x, y ) R(y , x)]
to be continued during the lecture
Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Translate into quantified (first-order) formulas:


Every considered item is red, green or blue.
If an item x is over an item y then it is not below y .
Red items are over green items.
Item a is below item b.
Item b is green.
Item a is not green.
Prove semantically that the conjunction of formulas in (1)
implies Item a is blue.
Prove (2) syntactically using a chosen proof system.

Slide 217 of 225

Andrzej Szalas

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Exercise 3 - solution

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 218 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

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

Slide 219 of 225

Proof by resolution - negated

blue(a)

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)
blue(a)

Andrzej Szalas

Slide 220 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Exercise 3 - solution

Proof

red (x) green(x) blue(x)


over (x, y ) below (x, y )
red (x) green(y ) over (x, y )
below (a, b)
green(b)
gren(a)
blue(a)

Andrzej Szalas

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

red (a) green(a)


red(a)
over (a, b)
red(x) over (x, b)
over (a, b)
F

(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

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Slide 222 of 225

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Exercise 4 - solution

Design a Datalog database for storing information about


regions on a screen. Each region is characterized by its shape,
size and color. In addition, for each pair of regions c1 , c2 , the
database contains information whether c1 intersects c2 .
Formulate in logic queries selecting:
1

8.
9.
10.
11.
12.
13.

Slide 221 of 225

Exercise 4

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

Exercise 3 - solution

Clausal form
1.
2.
3.
4.
5.
6.
7.

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

all pairs consisting of intersecting regions, first of which is


small and the second is round and green
all medium regions from which there is a path to a large region,
assuming that a path between regions c and d is a sequence of
regions r1 , . . . , rk (k 1) such that r1 = c, rk = d and for
each i such that 1 i k 1, we have that ri intersects ri +1 .

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

Slide 223 of 225

Andrzej Szalas

Slide 224 of 225

Logic: introduction & propositional calculus


Logic: predicate calculus
Other topics

Lecture VII: deductive databases


Lecture VIII: modal and temporal logics
Lecture IX: repetition

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

all medium regions from which there is a path to a large


region:
path(X , Y ) : intersects(X , Y ).
path(X , Y ) : intersects(X , Z ), path(Z , Y ).
aux(X , Y )
answer (X )

: region(X , , medium , ),
region(Y , , large , ), path(X , Y ).
: aux(X , ).
Andrzej Szalas

Slide 225 of 225

You might also like