226
Logic: Exercises Andrzej Sza las First edition: August 1, 2015 Current version: January 24, 2018 Contents 1 Introduction to logics 3 2 Tableaux and SAT 26 3 Resolution 43 4 First-order logic 67 5 Tableaux: FOL 91 6 Resolution: FOL 119 7 Deductive databases 150 8 Sequent (Gentzen) calculus 170 9 Sample exams 187 1

Logic: Exercises - IDA > HomeTDDD72/material/exercises-ebook.pdf · Logic: Exercises Andrzej Sza las First edition: August 1, 2015 Current version: January 24, 2018 Contents ... we

Embed Size (px)

Citation preview

Logic: Exercises

Andrzej Sza las

First edition: August 1, 2015Current version: January 24, 2018

Contents

1 Introduction to logics 3

2 Tableaux and SAT 26

3 Resolution 43

4 First-order logic 67

5 Tableaux: FOL 91

6 Resolution: FOL 119

7 Deductive databases 150

8 Sequent (Gentzen) calculus 170

9 Sample exams 187

1

Some remarks

This ebook contains exercises for lectures on logic. Thereare two types of exercises:

• warm-up exercises: for practicing useful techniques;

• exam-like exercises: similar exercises are likely toappear as (parts of) exam exercises.

Exam-like exercises are marked by ¡E!.

Solutions for exercises are provided but it is a good ideato first try to solve them yourself. Note that typicallythere are many different equally good solutions.

Recall that 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∨Fabbreviates

[A ∨

((¬B) ∧ C

)]→[(¬D)↔ (E ∨ F )

].

Paper and font sizes are selected to make the manualsuitable for ebook readers.

2

Lecture 1

Introduction to logics

3

LECTURE 1. INTRODUCTION TO LOGICS 4

1.1 Exercise

Let high temp, highpressure, signal on be propositionalvariables. Let M1 be a model, such that:

• M1 |= high temp, M1 |= signal;

• M1 6|= high pressure, M1 6|= danger,M1 6|= reduce speed,

and let M2 be a model such that:

• M2 |= high temp, M2 |= signal,M2 |= reduce speed;

• M2 6|= high pressure, M2 6|= danger.

Are the following statements true?

1a. M1 |= (high temp ∧ high pressure)→ danger;

1b. M1 |= (high temp ∧ signal)→ reduce speed;

2a. M2 |= (high temp ∧ high pressure)→ danger;

2b. M2 |= (high temp ∧ signal)→ reduce speed.

LECTURE 1. INTRODUCTION TO LOGICS 5

1.1 Solution

1

In M1:

• high temp and signal take the value T;

• high pressure, danger and reduce speed take thevalue F.

1a

In M1:

(high temp ∧ high pressure) → danger ↔( T ∧ F ) → F ↔

F → F ↔T.

1b

In M1:

(high temp ∧ signal) → reduce speed ↔( T ∧ T ) → F ↔

T → F ↔F.

LECTURE 1. INTRODUCTION TO LOGICS 6

2

In M2:

• high temp, signal and reduce speed take the value T;

• high pressure and danger take the value F.

2a

In M2:

(high temp ∧ high pressure) → danger ↔( T ∧ F ) → F ↔

F → F ↔T.

2b

In M2:

(high temp ∧ signal) → reduce speed ↔( T ∧ T ) → T ↔

T → T ↔T.

LECTURE 1. INTRODUCTION TO LOGICS 7

1.2 Exercise

Using the truth table method prove that:

1. (p→ ¬p)→ ¬p. (1.1)

2.[(p ∨ q) ∧ (¬p ∨ q)

]→ q; (1.2)

3.[(p→ q) ∧ (r → q)

]↔[(p ∨ r)→ q

]; (1.3)

4.[p→ (q ∧ r)

]↔[(p→ q) ∧ (p→ r)

]. (1.4)

LECTURE 1. INTRODUCTION TO LOGICS 8

1

There is only one variable in (1.1). A suitable truth tableis:

p ¬p p→ ¬p (p→ ¬p)→ ¬pT F F TF T T T

2

There are two variables in (1.2). A suitable truth tableis:

p q p ∨ q ¬p ¬p ∨ q (p ∨ q) ∧ (¬p ∨ q) (1.2)

T T T F T T TT F T F F F TF T T T T T TF F F T T F T

LECTURE 1. INTRODUCTION TO LOGICS 9

3

There are three variables in (1.3). A suitable truth tableis:

p q r p→q r→q(p→q)∧

(r→q)p∨r (p∨r)

→ q(1.3)

T T T T T T T T TT T F T T T T T TT F T F F F T F TT F F F T F T F TF T T T T T T T TF T F T T T F T TF F T T F F T F TF F F T T T F T T

LECTURE 1. INTRODUCTION TO LOGICS 10

4

There are three variables in (1.4). A suitable truth tableis:

p q r q∧rp→(q∧r) p→q p→r

(p→q)∧

(p→r)(1.4)

T T T T T T T T TT T F F F T F F TT F T F F F T F TT F F F F F F F TF T T T T T T T TF T F F T T T T TF F T F T T T T TF F F F T T T T T

LECTURE 1. INTRODUCTION TO LOGICS 11

1.3 Exercise

Translate the following sentence into propositional logic:1

“She asked me to stay and she told me to sitanywhere.

So I looked around and I noticed there wasn’ta chair.”

Remark: when we translate natural language into logic,we usually have to simplify and rephrase sentences tomake them closer to a logical form. This is often done byunderstanding what sentences actually say and then for-mulating them appropriately. In propositional logic onlyfragments of natural language can be expressed, so wefrequently only approximate the meaning of more com-plicated sentences.

1Taken from “Norwegian wood” lyrics.

LECTURE 1. INTRODUCTION TO LOGICS 12

1.3 Solution

Simplifying a bit, we have the following atomic sentences:2

• “she asked me to stay”;

• “she told me to sit anywhere’;

• “I looked around”;

• “there was a chair”.

The last two sentences are implied by the second onebeing a reason for them.

Denoting the above sentences respectively by asked, told,looked, chair, we can translate the initial sentence into:

asked ∧ told

∧told→ (looked ∧ ¬chair).

2That is, sentences not involving connectives.

LECTURE 1. INTRODUCTION TO LOGICS 13

1.4 Exercise ¡E!

1. Translate the following sentences into a set of propo-sitional formulas:

“Move small, medium or large objects.”“Move small objects to the first container,

medium objects to the second containerand large objects to the third container.”

“Small objects are green.”“Medium objects are red.”“Large objects are blue.”“Move objects to the second or to the third

container.”“Do not move blue objects.”

2. Assuming that each object can be moved to atmost one container, determine what objects can bemoved.

LECTURE 1. INTRODUCTION TO LOGICS 14

1.4 Solution

1

We have atomic sentences like “move small objects”,“move medium objects”, “move large objects”, . . .

We denote these sentences by small, medium, large,first, second, third, green, red, blue.

It is important to see that sentences as“large objects are blue”

mean that whenever we move a large object then it isblue, so should be translated into implication like:

large→ blue.

The translation is:

small ∨medium ∨ large (1.5)

small→ first (1.6)

medium→ second (1.7)

large→ third (1.8)

small→ green (1.9)

medium→ red (1.10)

large→ blue (1.11)

second ∨ third (1.12)

¬blue. (1.13)

LECTURE 1. INTRODUCTION TO LOGICS 15

2

The assumption that each object can be moved to atmost one container is translated into:

first→ ¬second (1.14)

first→ ¬third (1.15)

second→ ¬first (1.16)

second→ ¬third (1.17)

third→ ¬first (1.18)

third→ ¬second. (1.19)

By (1.13) the object cannot be blue so, by (1.11), can-not be large. Can it be small? By (1.5), small objectsare moved to the first container which violates (1.12) to-gether with (1.14) and (1.15). Therefore, only medium(and, therefore, red) objects can be moved (if any).

LECTURE 1. INTRODUCTION TO LOGICS 16

1.5 Exercise ¡E!

Let L, T and John be persons such that that L alwayslies and T always tells the truth.

L claims that on Saturdays:

“John works.”“John does not read books and he does not

watch TV and he cooks.”

T claims that on Saturdays:

“When John does not work, he does not watchTV either.”

“John reads books or watches TV or cooks.”

1. Translate the above claims into a set of proposi-tional formulas.

2. Determine what is John’s activity on Saturdays.

LECTURE 1. INTRODUCTION TO LOGICS 17

1.5 Solution

1

First we translate claims of L. We have atomic sentences:

• “John works”;

• “John reads books”;

• “John watches TV”;

• “John cooks”.

Denoting these sentences by works, books, tv and cooks,respectively, we translate L’s claims to:

works and (¬books ∧ ¬tv ∧ cooks). (1.20)

Since L lies, in reality, rather than (1.20) we have nega-tions:

¬works and ¬(¬books ∧ ¬tv ∧ cooks). (1.21)

Using a DeMorgan Law and removing double negationwe translate L’s claims into:

¬works; (1.22)

books ∨ tv ∨ ¬cooks. (1.23)

Claims of T can be translated into:

¬works→ ¬tv; (1.24)

books ∨ tv ∨ cooks. (1.25)

LECTURE 1. INTRODUCTION TO LOGICS 18

2

Observe that, by (1.22), we know that John does notwork. Therefore, by (1.24), he does not watch tv either.Now (1.23) and (1.25) reduce to:

books ∨ ¬cooks (1.26)

books ∨ cooks. (1.27)

Suppose ¬books. Then the above reduces to:

¬cooks (1.28)

cooks, (1.29)

which is a contradiction. Therefore, ¬books cannot betrue and the only option that remains is that John actu-ally reads books.

LECTURE 1. INTRODUCTION TO LOGICS 19

1.6 Exercise

Translate the following sentence into propositional logic:3

“If I burden myself with a companion in myvarious little inquiries it is not done out ofsentiment or caprice, but it is that Watsonhas some remarkable characteristics of his own.”

3After Sherlock Holmes.

LECTURE 1. INTRODUCTION TO LOGICS 20

1.6 Solution

We first have to find out what, in fact, Holmes said. Themeaning is more or less the following:

“If I burden myself with a companion in myvarious little inquiries then it is not done outof sentiment or caprice, but because Watsonhas some remarkable characteristics of his own.”

The sentence after “but” can be approximately rephrased:

“The reason for burdening myself is that Wat-son has some remarkable characteristics of hisown.”

We have the following atomic sentences:

• “I burden myself with a companion in my variouslittle inquiries”,

• “it is done out of sentiment”,

• “it is done out of caprice”,

• “Watson has some remarkable characteristics of hisown”.

We denote these sentences by burden, sentiment, capriceand watson, respectively.

LECTURE 1. INTRODUCTION TO LOGICS 21

Using the rephrased sentence, one can translate Holmes’sentence to:

burden→ ¬(sentiment ∨ caprice) (1.30)

∧watson→ burden. (1.31)

Using a DeMorgan law and tautology (1.4) (see page 7),we can simplify (1.30) to:

burden→ ¬sentiment

∧burden→ ¬caprice.

LECTURE 1. INTRODUCTION TO LOGICS 22

1.7 Exercise

Verify whether the following sentence is valid:

“If I’ll go to a cinema then I’ll take a bus, orif I’ll take a bus then I’ll go to a cinema”.

LECTURE 1. INTRODUCTION TO LOGICS 23

1.7 Solution

The above sentence looks a bit strange but it actually isa tautology. To see it, lets translate it into propositionallogic. We have two atomic sentences:

• “I’ll go to a cinema”;

• “I’ll take a bus”.

Denoting these sentences respectively by cinema and bus,the translation is:

(cinema→ bus) ∨ (bus→ cinema). (1.32)

To convince ourselves that (1.32) is a tautology we canuse truth tables or the following reasoning:

(cinema→ bus) ∨ (bus→ cinema)↔ (1.33)

¬cinema ∨ bus ∨ ¬bus ∨ cinema. (1.34)

Sentence (1.34) reduces to T since ¬cinema∨ cinema aswell as bus∨¬bus are T. So disjunction (1.34) is T, too.

LECTURE 1. INTRODUCTION TO LOGICS 24

1.8 Exercise

Verify the following reasoning:

It is not true that:John bought a house, orif he bought a house then he had money.

Therefore John didn’t have money.

LECTURE 1. INTRODUCTION TO LOGICS 25

1.8 Solution

To verify the reasoning we first translate it into logic. Wehave two atomic sentences:

• “John bought a house”;

• “John had money”.

We denote these sentences by h and l, respectively. Thetranslation is:[

¬(b ∨ (b→ l)

)]→ ¬l. (1.35)

We apply truth table method, showing that (1.35) isa tautology:

b l b→ l b ∨ (b→ l) ¬(b ∨ (b→ l)

)¬l (1.35)

T T T T F F TT F F T F T TF T T T F F TF F T T F T T

Lecture 2

Tableaux and SAT

26

LECTURE 2. TABLEAUX AND SAT 27

2.1 Exercise

Using tableaux transform the following formula into thedisjunctive normal form:

(p ∨ q)→ (p ∧ q). (2.1)

A disjunctive normal form is:

(a1 ∧ a2 ∧ . . . ∧ ak) ∨ . . . ∨ (c1 ∧ c2 ∧ . . . ∧ cm),

where each a1, a2, ak, . . . , c1, c2, . . . , cm are literals (possi-bly negated propositional variables).

LECTURE 2. TABLEAUX AND SAT 28

2.1 Solution

We construct a tableau for (2.1):

(p ∨ q)→ (p ∧ q)↙ ↘ (→)

¬(p ∨ q) p ∧ q(¬∨) ↓ ↓ (∧)¬p,¬q p, q

Recall that a tableau represents disjunction of conjunc-tions of literals in leaves. Therefore, the above tableaurepresents:

(¬p ∧ ¬q) ∨ (p ∧ q). (2.2)

Of course, formula (2.2) is equivalent to (2.1) and is indisjunctive normal form.

LECTURE 2. TABLEAUX AND SAT 29

2.2 Exercise ¡E!

Using tableaux check whether the following formula issatisfiable:

(p ∨ q) ∧ (¬p ∨ ¬q). (2.3)

If it is, provide a satisfying valuation.

LECTURE 2. TABLEAUX AND SAT 30

2.2 Solution

We construct a tableau for (2.3):

(p ∨ q) ∧ (¬p ∨ ¬q)↓ (∧)

p ∨ q,¬p ∨ ¬q↙ ↘ (∨)

p,¬p ∨ ¬q q,¬p ∨ ¬q↙ ↘ (∨) ↙ ↘ (∨)

p,¬p︸ ︷︷ ︸closed

p,¬q q,¬p q,¬q︸︷︷︸closed

The formula is satisfiable since the tableau has openleaves. Each open leaf provides a satisfying valuation:

• p,¬q: p = T and q = F;

• q,¬p: p = F and q = T.

Note that checking satisfiability requires only one sat-isfying valuation, so one can interrupt constructing thetableau after obtaining the first open leaf.

LECTURE 2. TABLEAUX AND SAT 31

2.3 Exercise ¡E!

Using tableaux check whether the following formulas aretautologies. If not, extract a counterexample from theconstructed tableau.

1. (p ∨ q)→ p. (2.4)

2. (p ∨ q)→ (p ∧ r). (2.5)

3. (p→ q) ∨ (q → p). (2.6)

4. (p ∨ q)→[(p ∨ q ∨ ¬r) ∧ (r ∨ p ∨ q)

](2.7)

LECTURE 2. TABLEAUX AND SAT 32

2.3 Solution

1

We construct a tableau for negated (2.4):

¬[(p ∨ q)→ p]↓ (¬→)

p ∨ q,¬p↙ ↘ (∨)

p,¬p︸ ︷︷ ︸closed

q,¬p

The above tableau is not closed. The leaf containing q,¬pprovides a counterexample for (2.4): q = T and p = F.Indeed, in such a case:

(p ∨ q)→ p ↔(F ∨ T)→ F ↔T→ F︸ ︷︷ ︸

F

.

LECTURE 2. TABLEAUX AND SAT 33

2

We construct a tableau for negated (2.5):

¬[(p ∨ q)→ (p ∧ r)]↓ (¬→)

p ∨ q,¬(p ∧ r)↙ ↘ (¬∧)

p ∨ q,¬p p ∨ q,¬r↙ ↘ (∨) ↙ ↘ (∨)

p,¬p︸ ︷︷ ︸closed

q,¬p p,¬r q,¬r

The above tableau is not closed. All open leaves providecounterexamples for (2.5).

• The leaf containing q,¬p provides a counterexam-ple q = T and p = F. Note that the value r is notdetermined: when q = T and p = F, formula (2.5)is false no matter whether r is T or F.

• The leaf containing p,¬r provides a counterexam-ple p = T and r = F. In this case the value of (2.5)is F no matter what the value of q is.

• The leaf containing q,¬r provides a counterexam-ple q = T and r = F. Again, in this case the valueof (2.5) is F no matter what the value of p is.

LECTURE 2. TABLEAUX AND SAT 34

3

We construct a tableau for the negation of (2.6):

¬[(p→ q) ∨ (q → p)

]↓ (¬∨)

¬(p→ q),¬(q → p)↓ (¬→)

p,¬q,¬(q → p)↓ (¬→)

p,¬q, q,¬p︸ ︷︷ ︸closed

The tableau is closed, so formula (2.6) is a tautology.

4

We construct a tableau for the negation (2.7):

¬[(p ∨ q)→

[(p ∨ q ∨ ¬r) ∧ (r ∨ p ∨ q)

]]↓ (¬→)

p ∨ q,¬[(p ∨ q ∨ ¬r) ∧ (r ∨ p ∨ q)

]]↙ ↘ (¬∧)

p ∨ q,¬(p ∨ q ∨ ¬r) p ∨ q,¬(r ∨ p ∨ q)↓ (¬∨) ↓ (¬∨)

p ∨ q,¬p,¬q,¬¬r p ∨ q,¬r,¬p,¬q↙ ↘ (∨) ↙ ↘ (∨)

p,¬p,¬q,¬¬r︸ ︷︷ ︸closed

q,¬p,¬q,¬¬r︸ ︷︷ ︸closed

p,¬r,¬p,¬q︸ ︷︷ ︸closed

q,¬r,¬p,¬q︸ ︷︷ ︸closed

The tableau is closed, so (2.7) is a tautology.

LECTURE 2. TABLEAUX AND SAT 35

2.4 Exercise

Consider the following relationships among concepts:

“Children and adults are persons.”“Children and adults are humans.”

According to the above specification:

1. Are persons humans?

2. Are humans persons?

LECTURE 2. TABLEAUX AND SAT 36

2.4 Solution

We have the following concepts:1 person (p), child (c),adult (a) and human (h).

Lets first translate relationships among concepts into propo-sitional formulas:

c→ p (2.8)

a→ p (2.9)

c→ h (2.10)

a→ h. (2.11)

1In brackets we give their abbreviations used later on.

LECTURE 2. TABLEAUX AND SAT 37

1

We have to verify whether p → h follows from (2.8)–(2.11), so construct a tableau:

¬[[(c→ p) ∧ (a→ p) ∧ (c→ h) ∧ (a→ h)]→ (p→ h)

]↓ (¬→)

(c→ p) ∧ (a→ p) ∧ (c→ h) ∧ (a→ h),¬(p→ h)↓ (∧)

c→ p, (a→ p) ∧ (c→ h) ∧ (a→ h),¬(p→ h)↓ (∧)

c→ p, a→ p, (c→ h) ∧ (a→ h),¬(p→ h)↓ (∧)

c→ p, a→ p, c→ h, (a→ h),¬(p→ h)↓ (¬→)

c→ p, a→ p, c→ h, a→ h, p,¬h↙ (→) ↘

¬c, a→ p, c→ h, a→ h, p,¬h . . .↓ (→) ↘

¬c, a→ p, c→ h, a→ h, p,¬h . . .↓ (→) ↘

¬c,¬a, c→ h, a→ h, p,¬h . . .↓ (→) ↘

¬c,¬a,¬c, a→ h, p,¬h . . .↓ (→) ↘

¬c,¬a,¬c,¬a, p,¬h . . .

We have an open leaf, so p → h does not follow fromformulas (2.8)–(2.11). The open leaf provides a coun-terexample: c = F, a = F, p = T and h = F.

LECTURE 2. TABLEAUX AND SAT 38

2

We have to verify whether h → p follows from (2.8)–(2.11), so have to construct a tableau for:

¬[[(c→ p)∧(a→ p)∧(c→ h)∧(a→ h)]→ (p→ h)

].

A tableau can be similar to that constructed previouslywith p→ h replaced by h→ p. Repeating the construc-tion we will obtain an open leaf:

¬c,¬a,¬c,¬a, h,¬p,

providing a counterexample: c = F, a = F, h = T andp = F.

LECTURE 2. TABLEAUX AND SAT 39

2.5 Exercise

Consider the following relationships among concepts:

“A good scientific paper is a paper contain-ing outstanding results or published ina very good scientific journal, and onlysuch papers are good scientific papers.”

“Papers containing outstanding results andpapers published in very good scien-tific journals are publications.”

According to the above specification:

1. Are good scientific papers also publications?

2. Are publications good scientific papers?

LECTURE 2. TABLEAUX AND SAT 40

2.5 Solution

We have concepts good scientific paper (g), paper con-taining outstanding results (o), paper published in a verygood scientific journal (j) and publication (p).

Translating our specification into propositional formulasresults in:

g ↔ (o ∨ j) (2.12)

o→ p (2.13)

j → p. (2.14)

Note that equivalence in (2.12) comes from “and onlysuch paper” meaning that such papers are limited tothose explicitly specified. On the other hand, this isnot stated about publications, so publications can in-clude other types of papers/books, too. Therefore wehave inclusions expressed by implications.

LECTURE 2. TABLEAUX AND SAT 41

1

The first question is expressed by g → p. We then have toverify whether (2.12)–(2.14) imply g → p. We constructa tableau showing that this indeed is the case:

¬[[(

g ↔ (o ∨ j))∧ (o→ p) ∧ (j → p)

]→ (g → p)

]↓ (¬→)(

g ↔ (o ∨ j))∧ (o→ p) ∧ (j → p) ∧ ¬(g → p)

↓ (∧)g ↔ (o ∨ j), o→ p ∧ (j → p) ∧ ¬(g → p)

↓ (∧)g ↔ (o ∨ j), o→ p, (j → p) ∧ ¬(g → p)

↓ (∧)g ↔ (o ∨ j), o→ p, j → p,¬(g → p)

↓ (∧)g ↔ (o ∨ j), o→ p, j → p, g,¬p

↙ ↘ (→)g ↔ (o ∨ j),¬o, j → p, g,¬p g ↔ (o ∨ j), p, j → p, g,¬p︸ ︷︷ ︸

closed↓ (→) ↘g ↔ (o ∨ j),¬o,¬j, g,¬p g ↔ (o ∨ j),¬o, p, g,¬p︸ ︷︷ ︸

closed↓ (↔)¬g ∨ o ∨ j, g ∨ ¬(o ∨ j),¬o,¬j, g,¬p

↓ (∨) ↘¬g, g∨¬(o∨j),¬o,¬j, g,¬p︸ ︷︷ ︸

closed

o∨j, g∨¬(o∨j),¬o,¬j, g,¬p

↙ (∨) ↓o, g∨¬(o∨j),¬o,¬j, g,¬p︸ ︷︷ ︸

closed

j, g∨¬(o∨j),¬o,¬j, g,¬p︸ ︷︷ ︸closed

LECTURE 2. TABLEAUX AND SAT 42

2The second question is expressed by p → g. We have toverify whether (2.12)–(2.14) imply p→ g. We constructa tableau showing that this is not the case:

¬[[(

g ↔ (o ∨ j))∧ (o→ p) ∧ (j → p)

]→ (p→ g)

]↓ (¬→)(

g ↔ (o ∨ j))∧ (o→ p) ∧ (j → p) ∧ ¬(p→ g)

↓ (∧)g ↔ (o ∨ j), o→ p ∧ (j → p) ∧ ¬(p→ g)

↓ (∧)g ↔ (o ∨ j), o→ p, (j → p) ∧ ¬(p→ g)

↓ (∧)g ↔ (o ∨ j), o→ p, j → p,¬(p→ g)

↓ (∧)g ↔ (o ∨ j), o→ p, j → p, p,¬g

↙ ↘ (→)g ↔ (o ∨ j),¬o, j → p, p,¬g . . .

↓ (→) ↘g ↔ (o ∨ j),¬o,¬j, p,¬g . . .

↓ (↔)¬g ∨ o ∨ j, g ∨ ¬(o ∨ j),¬o,¬j, p,¬g

↙ (∨) ↘¬g, g∨¬(o∨j),¬o,¬j, p,¬g . . .

↙ (∨) ↘. . . ¬g,¬(o ∨ j),¬o,¬j, p,¬g

↓ (¬∨)¬g,¬o,¬j,¬o,¬j, p,¬g

The above open leaf gives a valuation satisfying (2.12)–(2.14) and falsifying p→ g: g = F, o = F, j = F, p = T.

Lecture 3

Resolution

43

LECTURE 3. RESOLUTION 44

3.1 Exercise

Transform into an equivalent set of clauses:

¬[(¬p↔ r)→ [(q ∧ r) ∨ p]

]. (3.1)

LECTURE 3. RESOLUTION 45

3.1 Solution

We first transform (3.1) into the conjunctive normal form:

¬[(¬p↔ r)→ [(q ∧ r) ∨ p]

]↔

(¬p↔ r) ∧ ¬[(q ∧ r) ∨ p] ↔(¬¬p ∨ r) ∧ (¬p ∨ ¬r) ∧ ¬[(q ∧ r) ∨ p] ↔(p ∨ r) ∧ (¬p ∨ ¬r) ∧ ¬[(q ∧ r) ∨ p] ↔(p ∨ r) ∧ (¬p ∨ ¬r) ∧ ¬(q ∧ r) ∧ ¬p ↔(p ∨ r) ∧ (¬p ∨ ¬r) ∧ (¬q ∨ ¬r) ∧ ¬p.

So we have the following clauses:

p ∨ r

¬p ∨ ¬r¬q ∨ ¬r¬p.

LECTURE 3. RESOLUTION 46

3.2 Exercise ¡E!

Using resolution prove the following propositional for-mula:

(p ∨ q)→[(p ∨ q ∨ ¬r) ∧ (r ∨ p ∨ q)

](3.2)

LECTURE 3. RESOLUTION 47

3.2 Solution

First, we negate (3.2) and transform it into a conjunctivenormal form:

¬[(p ∨ q)→

[(p ∨ q ∨ ¬r) ∧ (r ∨ p ∨ q)

]]↔

(p ∨ q) ∧ ¬[(p ∨ q ∨ ¬r) ∧ (r ∨ p ∨ q)

]↔

(p ∨ q) ∧ [¬(p ∨ q ∨ ¬r) ∨ ¬(r ∨ p ∨ q)]↔(p ∨ q) ∧ [(¬p ∧ ¬q ∧ ¬¬r) ∨ (¬r ∧ ¬p ∧ ¬q)]↔(p ∨ q) ∧ [(¬p ∧ ¬q ∧ r) ∨ (¬r ∧ ¬p ∧ ¬q)]↔(p ∨ q) ∧ [((¬p ∧ ¬q ∧ r) ∨ ¬r)∧

((¬p ∧ ¬q ∧ r) ∨ (¬p ∧ ¬q))]↔(p ∨ q) ∧ [((¬p ∧ ¬q ∧ r) ∨ ¬r)∧

((¬p ∧ ¬q ∧ r) ∨ ¬p)∧((¬p ∧ ¬q ∧ r) ∨ ¬q)]↔

(p ∨ q) ∧ (¬p ∨ ¬r) ∧ (¬q ∨ ¬r) ∧ (r ∨ ¬r)∧(¬p ∨ ¬p) ∧ (¬q ∨ ¬p) ∧ (r ∨ ¬p)∧(¬p ∨ ¬q) ∧ (¬q ∨ ¬q) ∧ (r ∨ ¬q).

LECTURE 3. RESOLUTION 48

So we have the following clauses:

1. p ∨ q2. ¬p ∨ ¬r3. ¬q ∨ ¬r4. r ∨ ¬r5. ¬p ∨ ¬p6. ¬q ∨ ¬p7. r ∨ ¬p8. ¬p ∨ ¬q9. ¬q ∨ ¬q

10. r ∨ ¬q.

A proof by resolution:

11. ¬p – (fctr): 512. ¬q – (fctr): 913. q – (res): 1, 1114. ∅ – (res): 12, 13

LECTURE 3. RESOLUTION 49

3.3 Exercise

Using resolution check whether the following formula isa tautology:

(p ∨ q)→(q → (p ∨ (p ∧ q))

). (3.3)

LECTURE 3. RESOLUTION 50

3.3 Solution

We first transform negated (3.3) into conjunctive normalform:

¬[(p ∨ q)→

(q → (p ∨ (p ∧ q))

)]↔

(p ∨ q) ∧ ¬(q → (p ∨ (p ∧ q))

)↔

(p ∨ q) ∧ q ∧ ¬(p ∨ (p ∧ q)) ↔(p ∨ q) ∧ q ∧ ¬p ∧ ¬(p ∧ q) ↔(p ∨ q) ∧ q ∧ ¬p ∧ (¬p ∨ ¬q).

In the following reasoning we will apply an optimizationtechnique: whenever we have a clause containing propo-sition and its negation - we remove this clause.

This follows from the fact that such clauses are equivalentto T since the subexpression r∨¬r in a clause of the form(. . .∨r∨. . .∨. . .∨¬r∨. . .) is T and (. . .∨T∨. . .) is equiv-alent to T. Therefore any clause containing a propositionand its negation is equivalent to T, so can be removed (Tin conjunction with other clauses is equivalent to otherclauses).

Clauses:

1. p ∨ q2. q3. ¬p4. ¬p ∨ ¬q.

LECTURE 3. RESOLUTION 51

Resolution can be applied to:

• 1, 3: resulting in q which is already present (asclause 2.);

• 1, 4: resulting in q ∨ ¬q (removed as containinga proposition and its negation);

• 2, 4: resulting in ¬p which is already present (asclause 3.).

Therefore no matter how we apply resolution, the emptyclause ∅ cannot be obtained. So, formula (3.3) is nota tautology.

LECTURE 3. RESOLUTION 52

3.4 Exercise

Using resolution check whether the following formula issatisfiable:

(p ∨ q) ∧ (¬p ∨ q) ∧ (p ∨ ¬q) ∧ (¬p ∨ ¬q). (3.4)

LECTURE 3. RESOLUTION 53

3.4 Solution

Formula (3.4) is in conjunctive normal form and consistsof the following clauses:

1 p ∨ q2 ¬p ∨ q3 p ∨ ¬q4 ¬p ∨ ¬q.

Lets check conclusions that can be obtained using reso-lution:

5. q ∨ q – (res): 1, 26. q – (fctr): 57. p – (res): 3, 68. ¬p – (res): 4, 69. ∅ – (res): 7, 8.

The above derivation shows that the set of clauses im-plies the empty clause ∅, equivalent to F. So (3.4) is notsatisfialble.

LECTURE 3. RESOLUTION 54

3.5 Exercise ¡E!

Using resolution prove the conclusion of Exercise 1.4(page 13). Recall formulas resulting from translation con-sidered there:

small ∨medium ∨ large (3.5)

small→ first (3.6)

medium→ second (3.7)

large→ third (3.8)

small→ green (3.9)

medium→ red (3.10)

large→ blue (3.11)

second ∨ third (3.12)

¬blue. (3.13)

first→ ¬second (3.14)

first→ ¬third (3.15)

second→ ¬first (3.16)

second→ ¬third (3.17)

third→ ¬first (3.18)

third→ ¬second. (3.19)

LECTURE 3. RESOLUTION 55

3.5 Solution

The translation given by (1.5)–(1.19) (on page 14) im-plied medium. The same translation is recalled as for-mulas (3.5)–(3.19) (on page 54), so to apply resolutionwe first transform (3.5)–(3.19) into the following set ofclauses:

1. small ∨medium ∨ large2. ¬small ∨ first3. ¬medium ∨ second4. ¬large ∨ third5. ¬small ∨ green6. ¬medium ∨ red7. ¬large ∨ blue8. second ∨ third9. ¬blue

10. ¬first ∨ ¬second11. ¬first ∨ ¬third12. ¬second ∨ ¬first13. ¬second ∨ ¬third14. ¬third ∨ ¬first15. ¬third ∨ ¬second.

Next, we add negated conclusion:

16. ¬medium

LECTURE 3. RESOLUTION 56

Proof by resolution:

17. ¬large – (res): 7, 918. small ∨ large – (res): 1, 1619. small – (res): 17, 1820. f irst – (res): 2, 1921. ¬second – (res): 10, 2022. ¬third – (res): 11, 2023. third – (res): 8, 2124. ∅ – (res): 22, 23.

LECTURE 3. RESOLUTION 57

3.6 Exercise ¡E!

Using resolution prove the conclusion of Exercise 1.5(page 16). Recall formulas resulting from translation con-sidered there:

¬works; (3.20)

books ∨ tv ∨ ¬cooks. (3.21)

¬works→ ¬tv; (3.22)

books ∨ tv ∨ cooks. (3.23)

LECTURE 3. RESOLUTION 58

3.6 Solution

We add negated conclusion ¬books to formulas (3.20)–(3.23) we obtain the following set of clauses:

1. ¬works2. books ∨ tv ∨ ¬cooks3. works ∨ ¬tv4. books ∨ tv ∨ cooks

5. ¬books.

Proof by resolution:

6. ¬tv – (res): 1, 3

7. books ∨ ¬cooks – (res): 2, 6

8. books ∨ cooks – (res): 4, 6

9. books ∨ books – (res): 7, 8

10. books – (fctr): 9

11. ∅ – (res): 5, 10

LECTURE 3. RESOLUTION 59

3.7 Exercise ¡E!

Using resolution verify (1.35) (from Exercise 1.8, page 24).Recall that (1.35) was:[

¬(b ∨ (b→ l)

)]→ ¬l. (3.24)

LECTURE 3. RESOLUTION 60

3.7 Solution

We have to negate (3.24) and transform into the clausalform:

¬[[¬(b ∨ (b→ l)

)]→ ¬l

]↔

¬(b ∨ (b→ l)

)∧ ¬¬l ↔

¬b ∧ ¬(b→ l) ∧ ¬¬l ↔¬b ∧ b ∧ ¬l ∧ ¬¬l ↔¬b ∧ b ∧ ¬l ∧ l.

We have clauses:

1. ¬b2. b3. ¬l4. l.

Proof by resolution:

4. ∅ – (res): 1, 2.

LECTURE 3. RESOLUTION 61

3.8 Exercise

Using resolution solve Exercise 2.5 (page 39). That is,we have to verify whether formulas:

g ↔ (o ∨ j) (3.25)

o→ p (3.26)

j → p (3.27)

imply:

1. g → p;

2. p→ g.

LECTURE 3. RESOLUTION 62

3.8 Solution

First, we transform formulas (3.25)–(3.27) into clauses:

1. ¬g ∨ o ∨ j – obtained from g ↔ (o ∨ j)2. ¬o ∨ g – obtained from g ↔ (o ∨ j)3. ¬j ∨ g – obtained from g ↔ (o ∨ j)4. ¬o ∨ p – obtained from o→ p5. ¬j ∨ p – obtained from j → p.

1

We first verify whether the obtained set of clauses impliesg → p, so negate conclusion:

¬(g → p)↔ (g ∧ ¬p).

Therefore we add clauses:

6. g7. ¬p

and use resolution:

8. o ∨ j – (res): 1, 69. ¬o – (res): 4, 7

10. ¬j – (res): 5, 711. j – (res): 8, 912. ∅ – (res): 10, 11.

LECTURE 3. RESOLUTION 63

2

Below we shall use another optimization. Namely, weshall remove subsumed clauses. A clause C subsumes aclause D if every literal in C occurs also in D. In sucha cease we have that C → D and so clause D can beremoved.

No we verify whether the obtained set of clauses impliesp→ g, so negate conclusion:

¬(p→ g)↔ (p ∧ ¬g).

Therefore we add clauses:

6′. p7′. ¬g

and use resolution:

8′. ¬o – (res): 2, 7’9′. ¬j – (res): 3, 7’.

Using clauses 1–5 and 6′–11′ one can obtain clauses:

• which are already among 1–5, 6′–11′;

• which can be removed as containing both g and ¬g;

• which can be removed as subsumed by clause 7′.

Therefore, no matter how we apply resolution and factor-ization, we cannot obtain the empty clause ∅, so p → gis not implied by the considered set of clauses.

LECTURE 3. RESOLUTION 64

3.9 Exercise ¡E!

Consider the following relationships among concepts:

“persons who consume neither meat nor fishfood are vegetarians;”

“vegans consume no animal food nor milkproducts,”

“meat is animal food,”“fish food is animal food.”

Do the above relationships among concepts imply thatvegans are vegetarians?

LECTURE 3. RESOLUTION 65

3.9 Solution

In the sentences we have concepts:1 meat (m), fish food(f), animal food (a), milk products (mp), vegetarian (vt),vegan (v).

We have the following concept inclusions (represented byimplications):

(¬m ∧ ¬f)→ vt (3.28)

v → (¬a ∧ ¬mp) (3.29)

m→ a (3.30)

f → a. (3.31)

We want to verify whether (3.28)–(3.31) imply v → vt.

We transform concept inclusions into clauses:

(¬m ∧ ¬f)→ vt ↔ ¬(¬m ∧ ¬f) ∨ vt↔ ¬¬m ∨ ¬¬f ∨ vt↔ m ∨ f ∨ vt

v → (¬a ∧ ¬mp) ↔ ¬v ∨ (¬a ∧ ¬mp)↔ (¬v ∨ ¬a) ∧ (¬v ∨ ¬mp)

m→ a ↔ ¬m ∨ af → a ↔ ¬f ∨ a.

1In brackets we give their abbreviations used later on.

LECTURE 3. RESOLUTION 66

Next, we add negated conclusion (which is v ∧ ¬vt):

1. m ∨ f ∨ vt2. ¬v ∨ ¬a3. ¬v ∨ ¬mp4. ¬m ∨ a5. ¬f ∨ a6. v7. ¬vt.

Proof by resolution:

8. m ∨ f – (res): 1, 79. ¬a – (res): 2, 6

10. ¬m – (res): 4, 911. ¬f – (res): 5, 912. f – (res): 8, 1013. ∅ – (res): 11, 12.

We then conclude that (3.28)–(3.31) imply v → vt.

Lecture 4

First-order logic

67

LECTURE 4. FIRST-ORDER LOGIC 68

4.1 Exercise

Translate the following sentences into first-order logic:

1. “All employees have income.”

2. “Some employees are on holidays.”

3. “No employees are unemployed.”

4. “Some employees are not satisfied by their salarypolicy.”

LECTURE 4. FIRST-ORDER LOGIC 69

4.1 Solution

Note that the sentences are in Aristotelian forms. Possi-ble translations are given below.

1 ∀x[employee(x)→ has income(x)].

2 ∃x[employee(x) ∧ on holidays(x)].

3 ∀x[employee(x)→ ¬unemployed(x)].

4 ∃x[employee(x) ∧ ¬satisfied(x, salary policy)],

where ‘salary policy’ is a constant denoting a particularsalary policy.

LECTURE 4. FIRST-ORDER LOGIC 70

4.2 Exercise

Translate the following sentences into first-order logic:

1. “I always travel somewhere not far from the citywhere I live.”

2. “I sometimes travel somewhere not far from the citywhere I live.”

3. “I sometimes visit all my favourite places not farfrom the city where I live.”

LECTURE 4. FIRST-ORDER LOGIC 71

4.2 Solution

Concepts occurring in sentences are time and/or locationdependent. So, we have the following concepts (vocabu-lary):

• travel(t, p) – “at time t I travel to place p”;

• far from(p1, p2) – “places p1, p2 are far from eachother”;

• favorite(p) – “p is one of my favourite places”.

1 ∀t∃p[travel(t, p) ∧ ¬far from(p,my city)

],

where ‘my city’ is a constant denoting “my city”.

2 ∃t∃p[travel(t, p) ∧ ¬far from(p,my city)

].

3 ∃t∀p[(favorite(p)∧¬far from(p,my city))

→ travel(t, p)].

LECTURE 4. FIRST-ORDER LOGIC 72

4.3 Exercise

Translate the following formulas into natural language:

∀x[(strongEngine(x) ∧ car(x) ∧ wheels(x, 4))→ fast(x)];

(4.1)

∀x∀y[(parent(x, y) ∧ ancestor(y))→ ancestor(x)];

(4.2)

∀x∀y[(car(x) ∧ onRoad(x, y) ∧ highway(y)∧ (4.3)

normalConditions(y))→ fastSpeedAllowed(x)].

LECTURE 4. FIRST-ORDER LOGIC 73

4.3 Solution

(4.1) Four-wheels cars with strong engines are fast.

(4.2) A parent of an ancestor is an ancestor, too.

(4.3) Under normal conditions, for cars on a highway fastspeed is allowed.

LECTURE 4. FIRST-ORDER LOGIC 74

4.4 Exercise

Negate formulas obtained in Exercise 4.2 (page 70), sim-plify them by moving negation inside and translate theminto natural language.

That is, we have to negate the following formulas consid-ered in Exercise 4.2:

1. ∀t∃p[travel(t, p) ∧ ¬far from(p,my city)

];

2. ∃t∃p[travel(t, p) ∧ ¬far from(p,my city)

];

3. ∃t∀p[(favorite(p)∧¬far from(p,my city))→

travel(t, p)].

LECTURE 4. FIRST-ORDER LOGIC 75

4.4 Solution

1¬∀t∃p

[travel(t, p) ∧ ¬far from(p,my city)

]↔

∃t¬∃p[travel(t, p) ∧ ¬far from(p,my city)

]↔

∃t∀p¬[travel(t, p) ∧ ¬far from(p,my city)

]↔

∃t∀p[¬travel(t, p) ∨ ¬¬far from(p,my city)

]↔

∃t∀p[¬travel(t, p) ∨ far from(p,my city)

].

The resulting sentence can be translated into:

“Sometimes I don’t travel anywhere or I travelfar from the city I live in.”

Note that the resulting sentence can be presented in amore readable form:

∃t∀p[travel(t, p)→ far from(p,my city)

], (4.4)

which can be translated into an equivalent sentence butperhaps more elegant than before:

“Sometimes I travel far from the city I live in,if anywhere.”

LECTURE 4. FIRST-ORDER LOGIC 76

2¬∃t∃p

[travel(t, p) ∧ ¬far from(p,my city)

]↔

∀t¬∃p[travel(t, p) ∧ ¬far from(p,my city)

]↔

∀t∀p¬[travel(t, p) ∧ ¬far from(p,my city)

]↔

∀t∀p[¬travel(t, p) ∨ ¬¬far from(p,my city)

]↔

∀t∀p[¬travel(t, p) ∨ far from(p,my city)

].

The resulting sentence can be translated into:

“Always I don’t travel anywhere or I travelfar from the city I live in.”

3 ¬∃t∀p[(favorite(p) ∧ ¬far from(p,my city))

→ travel(t, p)]

↔∀t¬∀p

[(favorite(p) ∧ ¬far from(p,my city))

→ travel(t, p)]

↔∀t∃p¬

[(favorite(p) ∧ ¬far from(p,my city))

→ travel(t, p)]

↔∀t∃p

[favorite(p) ∧ ¬far from(p,my city)

∧ ¬travel(t, p)].

The resulting sentence can be translated into:

“Always there is a favorite place of mine, notfar from the city I live in, where I don’t travelto.”

LECTURE 4. FIRST-ORDER LOGIC 77

4.5 Exercise ¡E!

1. Verify informally the following reasoning:

“Every animal in this room is a dog ora cat.

Therefore there is an animal in this roombeing a dog or a cat.”

2. Does correctness of the above reasoning change whenwe add the assumption:

“There is an animal in this room”?

LECTURE 4. FIRST-ORDER LOGIC 78

4.5 Solution

1

We first translate sentences into first-order formulas:

∀x[(animal(x)∧in room(x))→(dog(x)∨cat(x))]; (4.5)

∃x[animal(x) ∧ in room(x) ∧ (dog(x) ∨ cat(x))]. (4.6)

The reasoning is formalized as:

(4.5)→ (4.6). (4.7)

In such exercises a good idea is to start with constructinga counterexample.

Consider a situation when there are no animals in theconsidered room. In this case formula (4.5) is true, since:

∀x[(animal(x) ∧ in room(x)︸ ︷︷ ︸false

)→(dog(x)∨cat(x))],

so no matter what value of implication conclusion is, thewhole implication is true.

On the other hand, formula (4.6) is false, since we have:

∃x[animal(x) ∧ in room(x)︸ ︷︷ ︸false

∧(dog(x)∨cat(x))],

so the whole conjunction under ∃x is false.

The reasoning expressed by (4.7) reduces in this case toT → F which is F. Therefore the reasoning, in general,is incorrect.

LECTURE 4. FIRST-ORDER LOGIC 79

2

The additional assumption can be translated into:

∃x(animal(x) ∧ in room(x)). (4.8)

The reasoning is now formalized as:

((4.5) ∧ (4.8))→ (4.6). (4.9)

We will show that the above reasoning is correct.

Assume that (4.5) ∧ (4.8) is true. In particular, (4.8) istrue. Denote by jd the existing x. So we have that:

animal(jd) ∧ in room(jd). (4.10)

By (4.5), we have:

(animal(jd)∧in room(jd))→(dog(jd)∨cat(jd)). (4.11)

Applying modus ponens to (4.10) and (4.11) we derive:

(dog(jd) ∨ cat(jd)), (4.12)

which, in conjunction with (4.10) gives us:

animal(jd)∧in room(jd)∧(dog(jd)∨cat(jd)), (4.13)

so (4.6) holds (the existing x is jd).

LECTURE 4. FIRST-ORDER LOGIC 80

4.6 Exercise ¡E!

Consider games, in which players move stones betweenplaces. A move from place p to place q is possible ifthere is an arrow between p and q. For example, in thegame represented in Figure 4.1, there are moves from ato b, from b to c, from c to a and from c to c and thereare no moves from b to a, from c to b, from a to a andfrom b to b.

���� ����

����

*

W

6

a

b

cy

Figure 4.1: Sample game.

Different games are obtained by drawing different con-nections between places. A particular game can, for ex-ample, satisfy the following conditions:

LECTURE 4. FIRST-ORDER LOGIC 81

(a) “From every place there is a move.”(b) “Every two places x, y have the property

that whenever there is a move from xto y then there is also a move from yto x.”

(c) “For every places x, y, z, if there are movesfrom x to y and from x to z then thereis also a move from y to z.”

1. Express in predicate logic properties (a), (b), (c).

2. Check informally whether the conjunction of (a)and (c) implies that “From every place there isa move to itself.”

3. Check informally whether the conjunction of (a),(b) and (c) implies that “From every place there isa move to itself.”

LECTURE 4. FIRST-ORDER LOGIC 82

4.6 Solution

1

(a) ∀x∃y[move(x, y)];

(b) ∀x∀y[move(x, y)→ move(y, x)];

(c) ∀x∀y∀z[(move(x, y) ∧move(x, z))→ move(y, z)].

2

We start with constructing a counterexample. Considera place, say p. By (a), there is q such that move(p, q)is true. By (c) we conclude move(q, q) (when x = p andy = z = q). We cannot obtain any other conclusions, sotry to construct a counterexample:

• the set of places is {p, q},• we have move(p, q),move(q, q).

In such a case, formulas (a) and (c) are true but it is notthe case that from every place there is a move to itself(there is no move from p to p).

LECTURE 4. FIRST-ORDER LOGIC 83

3

Attempts to construct a counterexample fail, so lets tryto prove that the conclusion is correct.

Take arbitrary place p. By (a) there is a place q suchthat there is a move from p to q (i.e., move(p, q)) is true.Therefore, by (b), there is a move from q to p. Theformula under quantifiers in (c) holds for every x, y, z so,in particular, for x = q, y = z = p. That is, we have:

(move(q, p) ∧move(q, p))→ move(p, p). (4.14)

The antecedent of implication (4.14) is true, so we con-clude that move(p, p) must be true, too. Since p wasarbitrarily chosen, we have that ∀p(move(p, p)), mean-ing that from every place there is a move to itself.

LECTURE 4. FIRST-ORDER LOGIC 84

4.7 Exercise ¡E!

Consider Exercise 4.6 with (a) substituted by:

(a’) “To every place there is a move”.

1. Express in predicate logic property (a’).

2. Check informally whether the conjunction of (a’)and (c) implies that “From every place there isa move to itself.”

Recall that, in Exercise 4.6, (c) is the formula:

∀x∀y∀z[(move(x, y) ∧move(x, z))→ move(y, z)].

LECTURE 4. FIRST-ORDER LOGIC 85

4.7 Solution

1

(a’) ∀x∃y[move(y, x)].

2

Again, attempts to construct a counterexample fail, sowe try to prove that the conclusion is correct.

Take arbitrary place p. By (a’) there is a place q such thatthere is a move from q to p (i.e., move(q, p)) is true. Theformula under quantifiers in (c) holds for every x, y, z so,as before, we have (4.14) and we conclude that move(p, p)must be true. Since p was arbitrarily chosen, we have that∀p(move(p, p)), meaning that from every place there isa move to itself.

LECTURE 4. FIRST-ORDER LOGIC 86

4.8 Exercise ¡E!

1. Translate into first-order formulas:

“Every considered object is red, greenor blue.”

“If x is to the left of y then x is not tothe right of y.”

“Red objects are to the left of green ob-jects.”

“Object a is to the right of object b.”“Object b is green and object a is not

green.”

2. Verify informally whether object a is blue.

LECTURE 4. FIRST-ORDER LOGIC 87

4.8 Solution

1

A natural translation is:

∀x[red(x) ∨ green(x) ∨ blue(x)]; (4.15)

∀x∀y[left(x, y)→ ¬right(x, y)]; (4.16)

∀x∀y[(red(x) ∧ green(y))→ left(x, y)]; (4.17)

right(a, b); (4.18)

green(b) ∧ ¬green(a). (4.19)

2

Assumung (4.15)–(4.19) we can conclude that blue(a) istrue. By (4.19) we have that a is not green so, by (4.15),it must be red or blue. By (4.18), a is to the right ofb where, by (4.19), b is green. Contraposing (4.16), wehave that a is not to the left of b. Therefore, by (4.17),a cannot be red. So it has to be blue.

LECTURE 4. FIRST-ORDER LOGIC 88

4.9 Exercise ¡E!

Consider the following properties of binary relations:

∀x[R(x, x)→ ∀yR(x, y)]; (4.20)

∀x∀y[R(x, y)→ R(y, x)]; (4.21)

∀x∃y[¬R(y, x)]; (4.22)

∀x[¬R(x, x)]. (4.23)

1. Check informally whether the conjunction of (4.20),(4.21) and (4.22) implies (4.23).

2. Check informally whether the conjunction of (4.20),(4.22) and (4.23) implies (4.21).

LECTURE 4. FIRST-ORDER LOGIC 89

4.9 Solution

1

Attempts to construct a counterexample fail, so we tryto prove that 1 holds.

We proceed using the reduction to absurdity method.Suppose that (4.23) does not follow from the conjunc-tion of (4.20)–(4.22). This means that (4.20)–(4.22) holdwhile there is a domain element a such that R(a, a) holds.From R(a, a) and (4.20) we deduce that ∀yR(a, y) holds.Using(4.21) we deduce ∀yR(y, a). This contradicts (4.22)because, for x = a, (4.22) implies ∃y[¬R(y, a)] beingequivalent to ¬∀yR(y, a).

The assumption that (4.23) is not true leads to contra-diction. Therefore (4.23) follows form the conjunction of(4.20)–(4.22).

LECTURE 4. FIRST-ORDER LOGIC 90

2

We construct a counterexample. That is, we assumethat (4.20), (4.22) and (4.23) are true and (4.21) is false.

Observe that (4.21) is false when there are elements a, bin the domain such that R(a, b) is true and R(b, a) isfalse. Now, to satisfy (4.22), we have to add a domainelement, say c, such that ¬R(c, b) is true. This givesrise to a counterexample: we assume that the domainis {a, b, c}, and that R(x, y) is true only for x = a, y =b. In particular, ∀x[¬R(x, x)] holds, so (4.23) is true.This, in turn, makes (4.20) true since the antecedent ofimplication is always false.

Therefore, in the constructed example formulas (4.20),(4.22) and (4.23) are true and (4.21) is false. Hence, (4.21)does not follow from the conjunction of (4.20), (4.22) and(4.23).

Lecture 5

Tableaux: FOL

91

LECTURE 5. TABLEAUX: FOL 92

5.1 Exercise

Consider the following statement concerning a barber(actually the only barber in town):1

“The barber is a man in town who shaves allthose, and only those, men in town who donot shave themselves.”

Using tableaux check whether the above statement is sat-isfiable.

1Derived from famous Russell’s paradox.

LECTURE 5. TABLEAUX: FOL 93

5.1 Solution

The translation of the considered statement is:

∀x[shaves(barber, x)↔ ¬shaves(x, x)]. (5.1)

We construct a tableau for (5.1):

∀x[shaves(barber, x)↔ ¬shaves(x, x)]↓ (∀x with x = barber)

shaves(barber, barber)↔ ¬shaves(barber, barber)↓ (↔)

¬shaves(barber, barber) ∨ ¬shaves(barber, barber),shaves(barber, barber) ∨ ¬¬shaves(barber, barber)

↓ (¬¬)¬shaves(barber, barber) ∨ ¬shaves(barber, barber),shaves(barber, barber) ∨ shaves(barber, barber)

↓ (fctr)¬shaves(barber, barber),

shaves(barber, barber) ∨ shaves(barber, barber)↓ (fctr)

¬shaves(barber, barber), shaves(barber, barber)︸ ︷︷ ︸closed

The tableau is closed, so formula (5.1) is unsatisfiable.Thus the initial sentence is unsatisfiable, too.

LECTURE 5. TABLEAUX: FOL 94

5.2 Exercise

Using tableaux check whether the following formula issatisfiable:

∀xR(x, a) ∧ ∀z¬R(z, z), (5.2)

where a is a constant.

LECTURE 5. TABLEAUX: FOL 95

5.2 Solution

We construct a tableau for (5.2):

∀xR(x, a) ∧ ∀z[¬R(z, z)]↓ (∧)

∀xR(x, a),∀z[¬R(z, z)]↓ (∀x with x = a)

R(a, a),∀z[¬R(z, z)]↓ (∀z with z = a)

R(a, a),¬R(a, a)

The tableau is closed, so formula (5.2) is not satisfiable.

Note: in general, checking first-order satisfiability can-not be done using tableaux (as well as any other com-putable method). For example consider the formula:

∀x∃yR(x, y). (5.3)

Constructing a tableau we obtain:

∀x∃yR(x, y)↓ (∀x with x = a)

∃yR(a, y)↓ (∃y with y = b)

R(a, b)

However, the obtained leaf contains only R(a, b) so doesnot provide a model for (5.3) since there is no y such thatR(b, y) holds.

LECTURE 5. TABLEAUX: FOL 96

Of course, we can continue the construction using rulesquantifiers, e.g., next nodes can contain:

↓ (∀x with x = b)R(a, b),∃yR(b, y)

↓ (∃y with y = c)R(a, b), R(b, c)

Note that eliminating ∃y we have to use a fresh con-stant (we have used c). Now there is no y such thatR(c, y) holds. The construction loops forever, not pro-viding a model for (5.3). On the other hand, (5.3) is sat-isfiable, e.g., assuming that the domain consists of {a, b}and such that R(a, b) and R(b, a) hold.

LECTURE 5. TABLEAUX: FOL 97

5.3 Exercise ¡E!

Using tableaux prove the following first-order formula:[∀x∃y[R(x, y)] ∧ ∀x∀y[R(x, y)→ ∀zR(x, z)]

]→ ∀x∀yR(x, y).

(5.4)

LECTURE 5. TABLEAUX: FOL 98

5.3 Solution

We construct a tableau for the negation of (5.4):

¬[[∀x∃y[R(x, y)]∧∀x∀y[R(x, y)→∀zR(x, z)]

]→∀x∀yR(x, y)

]↓ (¬→)

∀x∃y[R(x, y)] ∧ ∀x∀y[R(x, y)→ ∀zR(x, z)],¬∀x∀yR(x, y)↓ (¬∀x with x = a)

∀x∃y[R(x, y)] ∧ ∀x∀y[R(x, y)→ ∀zR(x, z)],¬∀yR(a, y)↓ (¬∀y with y = b)

∀x∃y[R(x, y)] ∧ ∀x∀y[R(x, y)→ ∀zR(x, z)],¬R(a, b)↓ (∀x with x = a)

∃y[R(a, y)] ∧ ∀x∀y[R(x, y)→ ∀zR(x, z)],¬R(a, b)↓ (∃y with y = c)

R(a, c) ∧ ∀x∀y[R(x, y)→ ∀zR(x, z)],¬R(a, b)↓ (∧)

R(a, c),∀x∀y[R(x, y)→ ∀zR(x, z)],¬R(a, b)↓ (∀x with x = a)

R(a, c),∀y[R(a, y)→ ∀zR(a, z)],¬R(a, b)↓ (∀y with y = c)

R(a, c), R(a, c)→ ∀zR(a, z),¬R(a, b)↙ ↘ (→)

R(a, c),¬R(a, c),¬R(a, b)︸ ︷︷ ︸closed

R(a, c), ∀zR(a, z),¬R(a, b)↓ (∀z with z = b)

R(a, c), R(a, b),¬R(a, b)︸ ︷︷ ︸closed

The tableau is closed, so formula (5.4) is a tautology.

LECTURE 5. TABLEAUX: FOL 99

5.4 Exercise ¡E!

Using tableaux check whether formula:

∀x∃y∃z[P (x, y, z) ∨ ¬∃z∃u(¬P (x, z, u))] (5.5)

implies:

∃x∃yP (a, x, y), (5.6)

where a is a constant.

LECTURE 5. TABLEAUX: FOL 100

5.4 Solution

We construct a tableau for ¬[(5.5)→ (5.6)]:

¬[∀x∃y∃z[P (x, y, z)∨¬∃z∃u(¬P (x, z, u))]→∃x∃yP (a, x, y)

]↓ (¬→)

∀x∃y∃z[P (x, y, z) ∨ ¬∃z∃u(¬P (x, z, u))],¬∃x∃yP (a, x, y)↓ (∀x with x = a)

∃y∃z[P (a, y, z) ∨ ¬∃z∃u(¬P (a, z, u))],¬∃x∃yP (a, x, y)↓ (∃y with y = b)

∃z[P (a, b, z) ∨ ¬∃z∃u(¬P (a, z, u))],¬∃x∃yP (a, x, y)↓ (∃z with z = c)

P (a, b, c) ∨ ¬∃z∃u(¬P (a, z, u)),¬∃x∃yP (a, x, y)↓ (¬∃x with x = b)

P (a, b, c) ∨ ¬∃z∃u(¬P (a, z, u)),¬∃yP (a, b, y)↓ (¬∃y with y = c)

P (a, b, c) ∨ ¬∃z∃u(¬P (a, z, u)),¬P (a, b, c)↙ ↘ (∨)

P (a, b, c),¬P (a, b, c)︸ ︷︷ ︸closed

¬∃z∃u(¬P (a, z, u)),¬P (a, b, c)↓ (¬∃z with z = b)

¬∃u(¬P (a, b, u)),¬P (a, b, c)↓ (¬∃u with u = c)

¬¬P (a, b, c),¬P (a, b, c)↓ (¬¬)

P (a, b, c),¬P (a, b, c)︸ ︷︷ ︸closed

The tableau is closed, so formula (5.5) implies (5.6).

LECTURE 5. TABLEAUX: FOL 101

5.5 Exercise ¡E!

Given the following assumptions about persons:

∀x[child(x)↔ ∃y(parent(y, x))]; (5.7)

∀x∀y[parent(x, y)→ (person(x) ∧ person(y))], (5.8)

check whether concept child is a subconcept of person.

LECTURE 5. TABLEAUX: FOL 102

5.5 Solution

We verify whether:

[(5.7) ∧ (5.8)]→ ∀x[child(x)→ person(x)], (5.9)

so construct a tableau for:

¬[[(5.7)∧ (5.8)]→ ∀x[child(x)→ person(x)]

]. (5.10)

For the tableau to better fit the page we shall use thefollowing abbreviations:

• child is denoted by C;

• parent is denoted by P ;

• person is denoted by S.

LECTURE 5. TABLEAUX: FOL 103

The tableau:

¬[∀x[C(x)↔ ∃y(P (y, x))] ∧ ∀x∀y[P (x, y)→ (S(x) ∧ S(y))]

→ ∀x[C(x)→ S(x)]]

↓ (¬→)∀x[C(x)↔ ∃y(P (y, x))] ∧ ∀x∀y[P (x, y)→ (S(x) ∧ S(y))],

¬∀x[C(x)→ S(x)]↓ (∧)

∀x[C(x)↔ ∃y(P (y, x))], ∀x∀y[P (x, y)→ (S(x) ∧ S(y))],¬∀x[C(x)→ S(x)]

↓ (¬∀x with x = a)∀x[C(x)↔ ∃y(P (y, x))], ∀x∀y[P (x, y)→ (S(x) ∧ S(y))],

¬(C(a)→ S(a))↓ (¬→)

∀x[C(x)↔ ∃y(P (y, x))], ∀x∀y[P (x, y)→ (S(x) ∧ S(y))],C(a),¬S(a)↓ (∀x with x = a)

C(a)↔ ∃y(P (y, a)),∀x∀y[P (x, y)→ (S(x) ∧ S(y))],C(a),¬S(a)↓ (↔)

¬C(a)∨∃y(P (y, a)), C(a)∨¬∃y(P (y, a)),∀x∀y[P (x, y)→ (S(x) ∧ S(y))], C(a),¬S(a)

↙ � (∨)¬C(a), C(a)∨¬∃y(P (y, a)), |

∀x∀y[P (x, y)→(S(x)∧S(y))], C(a),¬S(a)︸ ︷︷ ︸closed

|↓

∃y(P (y, a)), C(a)∨¬∃y(P (y, a)),∀x∀y[P (x, y)→(S(x) ∧ S(y))], C(a),¬S(a)

↙ ↘ (∨)(∗) (∗∗)

LECTURE 5. TABLEAUX: FOL 104

We continue starting with branch (∗):∃y(P (y, a)), C(a), ∀x∀y[P (x, y)→(S(x)∧S(y))], C(a),¬S(a)

↓ (∃y with y = b)P (b, a), C(a),∀x∀y[P (x, y)→ (S(x) ∧ S(y))], C(a),¬S(a)

↓ (∀x with x = b)P (b, a), C(a),∀y[P (b, y)→ (S(b) ∧ S(y))], C(a),¬S(a)

↓ (∀y with y = a)P (b, a), C(a), P (b, a)→ (S(b) ∧ S(a)), C(a),¬S(a)

↙ � (∨)P (b, a), C(a),¬P (b, a), C(a),¬S(a)︸ ︷︷ ︸

closed

|↓

P (b, a), C(a), S(b) ∧ S(a), C(a),¬S(a)↓ (∧)

P (b, a), C(a), S(b), S(a), C(a),¬S(a)︸ ︷︷ ︸closed

Branch (∗) is closed, so we continue with branch (∗∗):∃y(P (y, a)),¬∃y(P (y, a)),

∀x∀y[P (x, y)→ (S(x) ∧ S(y))], C(a),¬S(a)↓ (∃y with y = b)

P (b, a),¬∃y(P (y, a)),∀x∀y[P (x, y)→ (S(x) ∧ S(y))], C(a),¬S(a)

↓ (¬∃y with y = b)P (b, a),¬P (b, a),∀y[P (b, y)→ (S(b) ∧ S(y))], C(a),¬S(a)︸ ︷︷ ︸

closed

Branch (∗∗) is also closed which completes the tableauand shows that child is a subconcept of person.

LECTURE 5. TABLEAUX: FOL 105

5.6 Exercise

Let the following taxonomy, reflecting a particular situ-ation, be given:

• “color” is a subconcept of “red” or “brown”;

• “color” is a subconcept of red or not “brown”.

Using first-order logic verify whether this taxonomy im-plies that “color” is a subconcept of “red”.

LECTURE 5. TABLEAUX: FOL 106

5.6 Solution

Let B and R denote “brown” and “red”, respectively.

We have to verify:

∀x[(color(x)→ (R(x) ∨B(x)))∧(color(x)→ (R(x) ∨ ¬B(x)))→ (color(x)→ R(x))].

(5.11)

LECTURE 5. TABLEAUX: FOL 107

We construct a closed tableau for the negation of (5.11):

¬[∀x[(color(x)→ (R(x) ∨B(x)))∧

(color(x)→ (R(a) ∨ ¬B(a)))→ (color(a)→ R(a))]↓ (¬→)

∀x[(color(x)→ (R(x) ∨B(x))∧(color(x)→ (R(x) ∨ ¬B(x))],¬(color(x)→ R(x))

↓ (∀x with x = a)(color(a)→ (R(a) ∨B(a))∧

(color(a)→ (R(a) ∨ ¬B(a)),¬(color(a)→ R(a))↓ (∧)

(color(a)→ (R(a) ∨B(a)),(color(a)→ (R(a) ∨ ¬B(a)), color(a),¬R(a)

↓ (¬→)(color(a)→ (R(a) ∨B(a)),

(color(a)→ (R(a) ∨ ¬B(a)), color(a),¬R(a)↙ � (→)

¬color(a), (color(a)→ (R(a) ∨ ¬B(a)), |color(a),¬R(a)︸ ︷︷ ︸

closed

||↓

R(a) ∨B(a), color(a)→ (R(a) ∨ ¬B(a)), color(a),¬R(a)↙ � (∨)

R(a), color(a)→ (R(a) ∨ ¬B(a)), color(a),¬R(a)︸ ︷︷ ︸closed

||↙

B(a), color(a)→ (R(a) ∨ ¬B(a)), color(a),¬R(a)↙↘ (→)

B(a),¬color(a), color(a),¬R(a)︸ ︷︷ ︸closed

B(a), R(a) ∨ ¬B(a),color(a),¬R(a)

↙ ↘ (∨)B(a), R(a), color(a),¬R(a)︸ ︷︷ ︸

closed

B(a),¬B(a), color(a),¬R(a)︸ ︷︷ ︸closed

LECTURE 5. TABLEAUX: FOL 108

5.7 Exercise ¡E!

Verify your informal reasoning form Exercise 4.5, point 1(page 77) using tableaux.

Recall that we considered implication (4.7), that is:

∀x[(animal(x)∧in room(x))→(dog(x)∨cat(x))]→∃x[animal(x)∧in room(x)∧(dog(x)∨cat(x))].

(5.12)

LECTURE 5. TABLEAUX: FOL 109

5.7 Solution

For the tableau to better fit the page we shall use thefollowing abbreviations:

• animal is denoted by a;

• in room is denoted by i;

• dog is denoted by d;

• cat is denoted by c.

In Exercise 5.2 we have indicated that, in general, show-ing satisfiability of a first order formula is impossible.However, as we show below, this can sometimes be done.

LECTURE 5. TABLEAUX: FOL 110

We construct a tableau for the negation of (5.12):

¬[∀x[(A(x) ∧ I(x))→ (D(x) ∨ C(x))]→ ∃x[A(x) ∧ I(x) ∧ (D(x) ∨ C(x))]

]↓ (¬ →)

∀x[(A(x) ∧ I(x))→ (D(x) ∨ C(x))],¬∃x[A(x) ∧ I(x) ∧ (D(x) ∨ C(x))]

↓ (∀x with x = e)(A(e) ∧ I(e))→ (D(e) ∨ C(e)),¬∃x[A(x) ∧ I(x) ∧ (D(x) ∨ C(x))]

↓ (¬∃x with x = e)(A(e) ∧ I(e))→ (D(e) ∨ C(e)),¬[A(e) ∧ I(e) ∧ (D(e) ∨ C(e))]

↙ ↘ (→)¬(A(e) ∧ I(e)),¬[A(e) ∧ I(e) ∧ (D(e) ∨ C(e))] . . .

↙ ↘ (¬∧)¬A(e),¬[A(e) ∧ I(e) ∧ (D(e) ∨ C(e))] . . .

↙ ↘ (¬∧)¬A(e),¬A(e) . . .

We have obtained an open leaf, where animal(e) is false.Using this information we can construct a counterexam-ple being a model where:

• the domain is {e};

• animal(e) = F.

In this case, no matter what truth values of other literalsare, formula (5.12) is false.

LECTURE 5. TABLEAUX: FOL 111

5.8 Exercise ¡E!

Verify your informal reasoning form Exercise 4.8 (page 86)using tableaux. Recall that we have considered:

∀x[red(x) ∨ green(x) ∨ blue(x)]; (5.13)

∀x∀y[left(x, y)→ ¬right(x, y)]; (5.14)

∀x∀y[(red(x) ∧ green(y))→ left(x, y)]; (5.15)

right(a, b); (5.16)

green(b) ∧ ¬green(a), (5.17)

with the goal to show blue(a).

LECTURE 5. TABLEAUX: FOL 112

5.8 Solution

We have to show that:

[(5.13)∧(5.14)∧(5.15)∧(5.16)∧(5.17)]→ blue(a). (5.18)

We construct a tableau for the negation of (5.18). For thetableau to better fit the page we shall use the followingabbreviations:

• red is denoted by R;

• green is denoted by G;

• blue is denoted by B;

• left is denoted by l;

• right is denoted by H.

The tableau is constructed on next pages.

LECTURE 5. TABLEAUX: FOL 113

¬[[∀x[R(x) ∨G(x) ∨B(x)] ∧ ∀x∀y[L(x, y)→ ¬H(x, y)]∧

∀x∀y[(R(x) ∧G(y))→ L(x, y)]∧H(a, b) ∧G(b) ∧ ¬G(a)

]→ B(a)

]↓ (¬→)

∀x[R(x) ∨G(x) ∨B(x)] ∧ ∀x∀y[L(x, y)→ ¬H(x, y)]∧∀x∀y[(R(x) ∧G(y))→ L(x, y)]∧H(a, b) ∧G(b) ∧ ¬G(a),¬B(a)

↓ (∀x with x = a)R(a) ∨G(a) ∨B(a) ∧ ∀x∀y[L(x, y)→ ¬H(x, y)]∧

∀x∀y[(R(x) ∧G(y))→ L(x, y)]∧H(a, b) ∧G(b) ∧ ¬G(a),¬B(a)

↓ (∧)R(a) ∨G(a) ∨B(a), ∀x∀y[L(x, y)→ ¬H(x, y)]∧

∀x∀y[(R(x) ∧G(y))→ L(x, y)]∧H(a, b) ∧G(b) ∧ ¬G(a),¬B(a)

↓ (∧)R(a) ∨G(a) ∨B(a), ∀x∀y[L(x, y)→ ¬H(x, y)],

∀x∀y[(R(x) ∧G(y))→ L(x, y)]∧H(a, b) ∧G(b) ∧ ¬G(a),¬B(a)

↓ (∧)R(a) ∨G(a) ∨B(a), ∀x∀y[L(x, y)→ ¬H(x, y)],

∀x∀y[(R(x) ∧G(y))→ L(x, y)],H(a, b) ∧G(b) ∧ ¬G(a),¬B(a)

↓ (∧)R(a) ∨G(a) ∨B(a), ∀x∀y[L(x, y)→ ¬H(x, y)],

∀x∀y[(R(x) ∧G(y))→ L(x, y)],H(a, b), G(b) ∧ ¬G(a),¬B(a)

↓ (∧)

LECTURE 5. TABLEAUX: FOL 114

↓ (∧)R(a) ∨G(a) ∨B(a),∀x∀y[L(x, y)→ ¬H(x, y)],

∀x∀y[(R(x) ∧G(y))→ L(x, y)],H(a, b), G(b),¬G(a),¬B(a)

↙ ↘ (∨)R(a),∀x∀y[L(x, y)→ ¬H(x, y)], (∗)∀x∀y[(R(x) ∧G(y))→ L(x, y)],H(a, b), G(b),¬G(a),¬B(a)

↓ (∀x with x = a)R(a), ∀y[L(a, y)→ ¬H(a, y)],∀x∀y[(R(x) ∧G(y))→ L(x, y)],H(a, b), G(b),¬G(a),¬B(a)

↓ (∀y with y = b)R(a), L(a, b)→ ¬H(a, b), ∀x∀y[(R(x) ∧G(y))→ L(x, y)],

H(a, b), G(b),¬G(a),¬B(a)� ↘ (→)| ¬H(a, b),∀x∀y[(R(x) ∧G(y))→ L(x, y)],| H(a, b), G(b),¬G(a),¬B(a)︸ ︷︷ ︸

closed|↓

R(a),¬L(a, b),∀x∀y[(R(x) ∧G(y))→ L(x, y)],H(a, b), G(b),¬G(a),¬B(a)

↓ (∀x with x = a)R(a),¬L(a, b),∀y[(R(a) ∧G(y))→ L(a, y)],

H(a, b), G(b),¬G(a),¬B(a)↓ (∀y with y = b)

R(a),¬L(a, b), (R(a) ∧G(b))→ L(a, b),H(a, b), G(b),¬G(a),¬B(a)

↙ ↘ (→)(∗∗) (∗ ∗ ∗)

LECTURE 5. TABLEAUX: FOL 115

The continuation of (∗):

G(a) ∨B(a), ∀x∀y[L(x, y)→ ¬H(x, y)],∀x∀y[(R(x) ∧G(y))→ L(x, y)],H(a, b), G(b),¬G(a),¬B(a)

↙ �(∨)G(a), ∀x∀y[L(x, y)→ ¬H(x, y)], |∀x∀y[(R(x) ∧G(y))→ L(x, y)], |H(a, b), G(b),¬G(a),¬B(a)︸ ︷︷ ︸

closed

||↓

B(a), ∀x∀y[L(x, y)→ ¬H(x, y)],∀x∀y[(R(x) ∧G(y))→ L(x, y)],H(a, b), G(b),¬G(a),¬B(a)︸ ︷︷ ︸

closed

The continuation of (∗∗):

R(a),¬L(a, b),¬(R(a) ∧G(b)), H(a, b), G(b),¬G(a),¬B(a)↙ �(¬∧)

R(a),¬L(a, b),¬R(a), H(a, b), G(b),¬G(a),¬B(a)︸ ︷︷ ︸closed

||↙

R(a),¬L(a, b),¬G(b), H(a, b), G(b),¬G(a),¬B(a)︸ ︷︷ ︸closed

The continuation od (∗ ∗ ∗):

R(a),¬L(a, b), L(a, b), H(a, b), G(b),¬G(a),¬B(a)︸ ︷︷ ︸closed

LECTURE 5. TABLEAUX: FOL 116

5.9 Exercise ¡E!

Verify your informal reasoning form Exercise 4.9, point 1(page 88) using tableaux. That is, we have to prove that:

∀x[R(x, x)→ ∀yR(x, y)]∧∀x∀y[R(x, y)→ R(y, x)]∧∀x∃y[¬R(y, x)]

→ ∀x[¬R(x, x)]. (5.19)

LECTURE 5. TABLEAUX: FOL 117

5.9 Solution

We construct a tableau for the negation of (5.19):

¬[[∀x[R(x, x)→ ∀yR(x, y)] ∧ ∀x∀y[R(x, y)→ R(y, x)]∧

∀x∃y[¬R(y, x)]]→ ∀x[¬R(x, x)]]

↓ (¬→)∀x[R(x, x)→ ∀yR(x, y)] ∧ ∀x∀y[R(x, y)→ R(y, x)]∧

∀x∃y[¬R(y, x)],¬∀x[¬R(x, x)]↓ (∧)

∀x[R(x, x)→ ∀yR(x, y)],∀x∀y[R(x, y)→ R(y, x)]∧∀x∃y[¬R(y, x)],¬∀x[¬R(x, x)]

↓ (∧)∀x[R(x, x)→ ∀yR(x, y)], ∀x∀y[R(x, y)→ R(y, x)],

∀x∃y[¬R(y, x)],¬∀x[¬R(x, x)]↓ (¬∀x with x = a)

∀x[R(x, x)→ ∀yR(x, y)], ∀x∀y[R(x, y)→ R(y, x)],∀x∃y[¬R(y, x)],¬¬R(a, a)

↓ (¬¬)∀x[R(x, x)→ ∀yR(x, y)], ∀x∀y[R(x, y)→ R(y, x)],

∀x∃y[¬R(y, x)], R(a, a)↓ (∀x with x = a)

∀x[R(x, x)→ ∀yR(x, y)], ∀x∀y[R(x, y)→ R(y, x)],∃y[¬R(y, a)], R(a, a)

↓ (∃y with y = b)∀x[R(x, x)→ ∀yR(x, y)], ∀x∀y[R(x, y)→ R(y, x)],

¬R(b, a), R(a, a)↓ (∀x with x = a)

R(a, a)→ ∀yR(a, y),∀x∀y[R(x, y)→ R(y, x)],¬R(b, a), R(a, a)� ↘ (→)| (∗)↓

¬R(a, a),∀x∀y[R(x, y)→R(y, x)],¬R(b, a), R(a, a)︸ ︷︷ ︸closed

LECTURE 5. TABLEAUX: FOL 118

We continue with branch (∗):

∀yR(a, y),∀x∀y[R(x, y)→ R(y, x)],¬R(b, a), R(a, a)↓ (∀y with y = b)

R(a, b),∀x∀y[R(x, y)→ R(y, x)],¬R(b, a), R(a, a)↓ (∀x with x = a)

R(a, b),∀y[R(a, y)→ R(y, a)],¬R(b, a), R(a, a)↓ (∀y with y = b)

R(a, b), R(a, b)→ R(b, a),¬R(b, a), R(a, a)↙ � (→)

R(a, b),¬R(a, b),¬R(b, a), R(a, a)︸ ︷︷ ︸closed

||↓

R(a, b), R(b, a),¬R(b, a), R(a, a)︸ ︷︷ ︸closed

The tableau is closed which proves implication (5.19).

Lecture 6

Resolution: FOL

119

LECTURE 6. RESOLUTION: FOL 120

6.1 Exercise

Transform the following formula into an equisatisfiableset of clauses:1

¬∀x∃y[∀z(R(x, y, z)→ ∀u(S(x, u) ∨ T (y, z, u)))

∧∃vS(x, y, v)].

(6.1)

1Formulas A and B are equisatisfiable when A is satisfiable iffB is satisfiable.

LECTURE 6. RESOLUTION: FOL 121

LECTURE 6. RESOLUTION: FOL 122

6.1 Solution

We first transform (6.1) into the prenex normal form:

¬∀x∃y[∀z(R(x, y, z)→ ∀u(S(x, u) ∨ T (y, z, u)))

∧∃vS(x, y, v)] ↔

∃x¬∃y[∀z(R(x, y, z)→ ∀u(S(x, u) ∨ T (y, z, u)))

∧∃vS(x, y, v)] ↔

∃x∀y¬{[∀z(R(x, y, z)→ ∀u(S(x, u) ∨ T (y, z, u)))

∧∃vS(x, y, v)]} ↔

∃x∀y[¬∀z(R(x, y, z)→ ∀u(S(x, u) ∨ T (y, z, u)))

∨¬∃vS(x, y, v)] ↔

∃x∀y[∃z¬(R(x, y, z)→ ∀u(S(x, u) ∨ T (y, z, u)))

∨∀v¬S(x, y, v)] ↔

∃x∀y[∃z(R(x, y, z) ∧ ¬∀u(S(x, u) ∨ T (y, z, u)))

∨∀v¬S(x, y, v)] ↔

∃x∀y[∃z(R(x, y, z) ∧ ∃u¬(S(x, u) ∨ T (y, z, u)))

∨∀v¬S(x, y, v)] ↔

∃x∀y∃z[(R(x, y, z) ∧ ∃u¬(S(x, u) ∨ T (y, z, u)))

∨∀v¬S(x, y, v)] ↔

∃x∀y∃z∀v[(R(x, y, z) ∧ ∃u¬(S(x, u) ∨ T (y, z, u)))

∨¬S(x, y, v)] ↔

∃x∀y∃z∀v[∃u(R(x, y, z) ∧ ¬(S(x, u) ∨ T (y, z, u)))

∨¬S(x, y, v)] ↔

∃x∀y∃z∀v∃u[(R(x, y, z) ∧ ¬(S(x, u) ∨ T (y, z, u)))

∨¬S(x, y, v)].

LECTURE 6. RESOLUTION: FOL 123

Observe that in the last steps we could move to the prefixquantifier ∃u before moving ∀v. The resulting formulawould still be equivalent to (6.1).

The resulting formula is equivalent (thus also equisatis-fiable) to (6.1). We have to eliminate existential quanti-fiers ∃x, ∃z and ∃u, so apply Skolemization, where a isa constant and f, g are function symbols:

∃x∀y∃z∀v∃u[(R(x, y, z) ∧ ¬(S(x, u) ∨ T (y, z, u)))

∨¬S(x, y, v)];

∀y∃z∀v∃u[(R(a, y, z) ∧ ¬(S(a, u) ∨ T (y, z, u)))

∨¬S(a, y, v)];

∀y∀v∃u[(R(a, y, f(y)) ∧ ¬(S(a, u) ∨ T (y, f(y), u)))

∨¬S(a, y, v)];

∀y∀v[(R(a, y,f(y))∧¬(S(a, g(y, v))∨T (y,f(y), g(y, v))))∨¬S(a, y, v)

].

Note that Skolemization preserves satisfiability but notequivalence, so the resulting formula is equisatisfiable(but not equivalent) to (6.1).

LECTURE 6. RESOLUTION: FOL 124

Universal quantifiers ∀y∀v can now be removed and wetransform the resulting formula into the conjunctive nor-mal form:

(R(a, y, f(y)) ∧ ¬(S(a, g(y, v)) ∨ T (y, f(y), g(y, v))))∨¬S(a, y, v)

(R(a, y, f(y)) ∧ ¬S(a, g(y, v)) ∧ ¬T (y, f(y), g(y, v)))∨¬S(a, y, v)

(R(a, y, f(y)) ∨ ¬S(a, y, v))∧(¬S(a, g(y, v)) ∨ ¬S(a, y, v))∧(¬T (y, f(y), g(y, v)) ∨ ¬S(a, y, v)).

We then have the following set of clauses equisatisfiableto (6.1) (all transformations we applied are satisfiabilitypreserving):

1. R(a, y, f(y)) ∨ ¬S(a, y, v)2. ¬S(a, g(y, v)) ∨ ¬S(a, y, v)3. ¬T (y, f(y), g(y, v)) ∨ ¬S(a, y, v).

LECTURE 6. RESOLUTION: FOL 125

6.2 Exercise

Unify the following literals:

1. P (x, f(x), g(y, z)) and P (f(z), u, v));

2. P (x, f(x), v) and P (f(z), x, v)).

LECTURE 6. RESOLUTION: FOL 126

6.2 Solution

1

Expression trees are:

P� | �

x f g| ��x y z

P� | �

f u v|z

The first difference is between x and f so we set x = f(z)and obtain trees:

P� | �

f f g| | ��z f y z

|z

P� | �

f u v|z

LECTURE 6. RESOLUTION: FOL 127

To eliminate the next difference, we set u = f(f(z)) andobtain:

P� | �

f f g| | ��z f y z

|z

P� | �

f f v| |z f

|z

The last difference is eliminated by setting v = g(y, z):

P� | �

f f g| | ��z f y z

|z

P� | �

f f g| | ��z f y z

|z

Summing up, both literals are unifiable by substitutionx = f(z), u = f(f(z)), v = g(y, z).

LECTURE 6. RESOLUTION: FOL 128

2

Expression trees are:

P� | �

x f v|x

P� | �

f x v|z

The first difference is between x and f so we set x = f(z)and obtain trees:

P� | �

f f v| |z f

|z

P� | �

f f v| |z z

The last difference is requires to set z = f(z). Since zappears in f(z) such substitution is not allowed (occur-rence check). Therefore the considered literals are notunifiable.

LECTURE 6. RESOLUTION: FOL 129

6.3 Exercise

Using resolution solve Exercise 5.1 (page 92). That is,we have to chect the satisfiability of:

∀x[shaves(barber, x)↔ ¬shaves(x, x)]. (6.2)

LECTURE 6. RESOLUTION: FOL 130

6.3 Solution

We transform (6.2) into a set of clauses:

∀x[shaves(barber, x)↔ ¬shaves(x, x)] ↔shaves(barber, x)↔ ¬shaves(x, x) ↔¬shaves(barber, x) ∨ ¬shaves(x, x)∧shaves(barber, x) ∨ ¬¬shaves(x, x) ↔¬shaves(barber, x) ∨ ¬shaves(x, x)∧shaves(barber, x) ∨ shaves(x, x).

A resolution proof (after renaming variables):

1. ¬shaves(barber, x1) ∨ ¬shaves(x1, x1)

2. shaves(barber, x2) ∨ shaves(x2, x2)

3. ¬shaves(barber, barber)

– (fctr): 1 with x1 = barber

4. shaves(barber, barber)

– (fctr): 2 with x2 = barber

5. ∅ – (res): 3, 4.

LECTURE 6. RESOLUTION: FOL 131

6.4 Exercise ¡E!

Using resolution check whether the following formula isa tautology:

∀x∃y∃z[[P (x, y, z) ∨ ¬∃z∃u(¬P (x, z, u))]

→ ∃x∃yP (f(a), x, y)],

(6.3)

where a is a constant.

LECTURE 6. RESOLUTION: FOL 132

LECTURE 6. RESOLUTION: FOL 133

6.4 Solution

We transform negated (6.3) into the prenex normal form:

¬∀x∃y∃z[(P (x, y, z) ∨ ¬∃z∃u(¬P (x, z, u)))

→ ∃x∃yP (f(a), x, y)] ↔

∃x¬∃y∃z[(P (x, y, z) ∨ ¬∃z∃u(¬P (x, z, u)))

→ ∃x∃yP (f(a), x, y)] ↔

∃x∀y¬∃z[(P (x, y, z) ∨ ¬∃z∃u(¬P (x, z, u)))

→ ∃x∃yP (f(a), x, y)] ↔

∃x∀y∀z¬[(P (x, y, z) ∨ ¬∃z∃u(¬P (x, z, u)))

→ ∃x∃yP (f(a), x, y)] ↔

∃x∀y∀z[(P (x, y, z) ∨ ¬∃z∃u(¬P (x, z, u)))

∧¬∃x∃yP (f(a), x, y)] ↔

∃x∀y∀z[(P (x, y, z) ∨ ∀z¬∃u(¬P (x, z, u)))

∧∀x¬∃yP (f(a), x, y)] ↔

∃x∀y∀z[(P (x, y, z) ∨ ∀z∀u¬(¬P (x, z, u)))

∧∀x∀y¬P (f(a), x, y)] ↔

∃x∀y∀z[(P (x, y, z) ∨ ∀z′∀uP (x, z; , u))

∧∀x′∀y′¬P (f(a), x′, y′)] ↔

∃x∀y∀z[(P (x, y, z) ∨ ∀z′∀uP (x, z′, u))

∧∀x′∀y′¬P (f(a), x′, y′)] ↔

∃x∀y∀z∀z′∀u[(P (x, y, z) ∨ P (x, z′, u))

∧∀x′∀y′¬P (f(a), x′, y′)] ↔

∃x∀y∀z∀z′∀u∀x′∀y′[(P (x, y, z) ∨ P (x, z′, u))∧¬P (f(a), x′, y′)

].

LECTURE 6. RESOLUTION: FOL 134

We Skolemize (b is a fresh constant):

∀y∀z∀z′∀u∀x′∀y′[(P (b, y, z) ∨ P (b, z′, u))∧¬P (f(a), x′, y′)

].

We then have the following clauses (after renaming vari-ables):

1. P (b, y1, z) ∨ P (b, z1, u)2. ¬P (f(a), x2, y2).

Clause 2 contains the only negative literal. However itdoes not unify with any positive literal, so the emptyclause cannot be obtained. Therefore (6.3) is not a tau-tology.

LECTURE 6. RESOLUTION: FOL 135

6.5 Exercise ¡E!

Prove the following formula using resolution, where b isa constant:[∀yQ(b, y) ∧ ∀x∀y[Q(x, y)→ Q(s(x), s(y))]

]→

∃z[Q(b, z) ∧Q(z, s(s(b)))].(6.4)

LECTURE 6. RESOLUTION: FOL 136

6.5 Solution

We first negate formula (6.4):

¬{[∀yQ(b, y) ∧ ∀x∀y[Q(x, y)→ Q(s(x), s(y))]

]→

∃z[Q(b, z) ∧Q(z, s(s(b)))]}↔[

∀yQ(b, y) ∧ ∀x∀y[Q(x, y)→ Q(s(x), s(y))]]∧

¬∃z[Q(b, z) ∧Q(z, s(s(b)))] ↔[∀yQ(b, y) ∧ ∀x∀y[Q(x, y)→ Q(s(x), s(y))]

]∧

∀z¬[Q(b, z) ∧Q(z, s(s(b)))].

This gives the following clauses (after renaming vari-ables):

1. Q(b, y1);

2. ¬Q(x2, y2) ∨Q(s(x2), s(y2));

3. ¬Q(b, z3) ∨ ¬Q(z3, s(s(b))).

Proof by resolution:

4. ¬Q(z4, s(s(b))) – (res): 1, 3 with y1 = z3

and renaming z3/z4

5. ∅ – (res): 1, 4 with z4 = b, y1 = s(s(b)).

LECTURE 6. RESOLUTION: FOL 137

6.6 Exercise ¡E!

Provide a resolution proof for Exercise 5.5 (page 101).That is, given the following assumptions:

∀x[child(x)↔ ∃y(parent(y, x))]; (6.5)

∀x∀y[parent(x, y)→ (person(x) ∧ person(y))], (6.6)

we have to check whether concept child is a subconceptof person. Thus we verify whether:

[(6.5) ∧ (6.6)]→ ∀x[child(x)→ person(x)]. (6.7)

LECTURE 6. RESOLUTION: FOL 138

6.6 Solution

We have to prove that implication (6.7) indeed holds, sowe negate it:

¬[∀x[child(x)↔ ∃y(parent(y, x))]∧

∀x∀y[parent(x, y)→ (person(x) ∧ person(y))]

→ ∀x[child(x)→ person(x)]]↔

∀x[child(x)↔ ∃y(parent(y, x))]∧∀x∀y[parent(x, y)→ (person(x) ∧ person(y))]∧¬∀x[child(x)→ person(x)]↔

∀x[(¬child(x) ∨ ∃y(parent(y, x)))∧(¬∃y(parent(y, x)) ∨ child(x))]∧∀x∀y[¬parent(x, y) ∨ (person(x) ∧ person(y))]∧∃x¬[child(x)→ person(x)]↔

∀x∃y[(¬child(x) ∨ parent(y, x))∧(∀y(¬parent(y, x)) ∨ child(x))]∧∀x∀y[(¬parent(x, y) ∨ person(x))∧

(¬parent(x, y) ∨ person(y))]∧∃x[child(x) ∧ ¬person(x)].

LECTURE 6. RESOLUTION: FOL 139

We Skolemize and obtain the following clauses (after re-naming variables):

1. ¬child(x1) ∨ parent(f(x1), x1);2. ¬parent(y2, x2) ∨ child(x2);3. ¬parent(x3, y3) ∨ person(x3);4. ¬parent(x4, y4) ∨ person(y4);5. child(a);6. ¬person(a).

Proof by resolution:

7. parent(f(a), a) – (res): 1, 5 with x1 = a8. person(a) – (res): 4, 7 with x4 = f(a), y4 = a9. ∅ – (res): 6, 8.

LECTURE 6. RESOLUTION: FOL 140

6.7 Exercise ¡E!

Verify your informal reasoning form Exercise 4.5 (page 77)using resolution.

Recall that we considered implication (4.7), that is:

∀x[(animal(x)∧in room(x))→(dog(x)∨cat(x))]→∃x[animal(x)∧in room(x)∧(dog(x)∨cat(x))].

(6.8)

LECTURE 6. RESOLUTION: FOL 141

6.7 Solution

We first transform negated (6.8) into the conjunctive nor-mal form:

¬[∀x[(animal(x)∧in room(x))→(dog(x)∨cat(x))]→∃x[animal(x)∧in room(x)∧(dog(x)∨cat(x))]

]↔

∀x[(animal(x)∧in room(x))→(dog(x)∨cat(x))]∧¬∃x[animal(x)∧in room(x)∧(dog(x)∨cat(x))]↔∀x[¬(animal(x)∧in room(x)) ∨ dog(x)∨cat(x)]∧∀x¬[animal(x)∧in room(x)∧(dog(x)∨cat(x))]↔∀x[¬animal(x) ∨ ¬in room(x) ∨ dog(x) ∨ cat(x)]∧∀x[¬animal(x) ∨ ¬in room(x) ∨ ¬(dog(x)∨cat(x))]↔∀x[¬animal(x) ∨ ¬in room(x) ∨ dog(x) ∨ cat(x)]∧∀x[¬animal(x)∨¬in room(x)∨(¬dog(x)∧¬cat(x))]↔∀x[¬animal(x) ∨ ¬in room(x) ∨ dog(x) ∨ cat(x)]∧∀x[(¬animal(x)∨¬in room(x)∨¬dog(x))∧ (¬animal(x)∨¬in room(x) ∨ ¬cat(x))].

We then have the following clauses (after renaming vari-ables):

1. ¬animal(x1) ∨ ¬in room(x1) ∨ dog(x1) ∨ cat(x1)2. ¬animal(x2)∨¬in room(x2)∨¬dog(x2)3. ¬animal(x3)∨¬in room(x3) ∨ ¬cat(x3).

LECTURE 6. RESOLUTION: FOL 142

We use resolution and factorization:

4. ¬animal(x4) ∨ ¬in room(x4)∨¬animal(x4)∨¬in room(x4) ∨ cat(x4)

– (res): 1, 2 with x1 = x2 and renaming x2/x4

5. ¬animal(x5) ∨ ¬in room(x5) ∨ cat(x5)– (fctr): 4 and renaming x4/x5

6. . . .

Note that no matter how we apply resolution and factor-ization, the empty clause cannot be obtained. In fact,clauses 1–3 contain literals ¬animal(. . .), ¬in room(. . .)which cannot be resolved out since there are no theirpositive occurrences.

Therefore, implication (6.8) indeed is not a tautology.

LECTURE 6. RESOLUTION: FOL 143

6.8 Exercise ¡E!

Verify your informal reasoning form point 3 of Exer-cise 4.6 (page 80) using resolution.

Recall that we have considered:

(a) ∀x∃y[move(x, y)];

(b) ∀x∀y[move(x, y)→ move(y, x)];

(c) ∀x∀y∀z[(move(x, y) ∧move(x, z))→ move(y, z)].

We have to show that (a), (b), (c) imply ∀x[move(x, x)].

LECTURE 6. RESOLUTION: FOL 144

6.8 Solution

We negate the claim and obtain formulas:

∀x∃y[move(x, y)]; (6.9)

∀x∀y[move(x, y)→ move(y, x)]; (6.10)

∀x∀y∀z[(move(x, y) ∧move(x, z))→ move(y, z)];(6.11)

¬∀x[move(x, x)]. (6.12)

We transform them into:

∀x[move(x, f(x))] – Skolemization; (6.13)

∀x∀y[¬move(x, y) ∨move(y, x)]; (6.14)

∀x∀y∀z[¬(move(x, y)∧move(x, z))∨move(y, z)]; (6.15)

∃x[¬move(x, x)]. (6.16)

So we obtain clauses, where a is a constant obtained bySkolemizing formula (6.16) and renaming variables:

1. move(x1, f(x1));2. ¬move(x2, y2) ∨move(y2, x2);3. ¬move(x3, y3) ∨ ¬move(x3, z3) ∨move(y3, z3);4. ¬move(a, a).

LECTURE 6. RESOLUTION: FOL 145

Proof by resolution:

5. move(f(x5), x5) – (res): 1, 2 with y2 = f(x1)x2 = x1 and renaming x1/x5

6. ¬move(f(x6), z6) ∨move(x6, z6)– (res): 3, 5 with x3 = f(x5), y3 = x5

and renaming x5/x6, z3/z67. move(x7, x7) – (res): 5, 6 with x5 = x6 = z6

and renaming x6/x7

8. ∅ – (res): 4, 7 with x7 = a.

The empty clause is derived, so (a), (b), (c) indeed imply∀x[move(x, x)].

LECTURE 6. RESOLUTION: FOL 146

6.9 Exercise ¡E!

Verify your informal reasoning form Exercise 4.8 (page 86)using resolution.

Recall that we have considered:

∀x[red(x) ∨ green(x) ∨ blue(x)]; (6.17)

∀x∀y[left(x, y)→ ¬right(x, y)]; (6.18)

∀x∀y[(red(x) ∧ green(y))→ left(x, y)]; (6.19)

right(a, b); (6.20)

green(b) ∧ ¬green(a), (6.21)

with the goal to show blue(a). That is, we want to showthat:

[(6.17)∧(6.18)∧(6.19)∧(6.20)∧(6.21)]→ blue(a). (6.22)

LECTURE 6. RESOLUTION: FOL 147

6.9 Solution

We transform the negated (6.22) into the clausal form:

1. red(x1) ∨ green(x1) ∨ blue(x1)2. ¬left(x2, y2) ∨ ¬right(x2, y2)3. ¬red(x3) ∨ ¬green(y3) ∨ left(x3, y3)4. right(a, b)5. green(b)6. ¬green(a)7. ¬blue(a).

Resolution proof:

8. red(a) ∨ green(a) – (res): 1, 7 with x1 = a9. red(a) – (res): 6, 8

10. ¬green(y10) ∨ left(a, y10)– (res): 3, 9 with x3 = a and renaming y3/y10

11. left(a, b) – (res): 5, 10 with y10 = b12. ¬right(a, b) – (res): 2, 11 with x2 = a, y2 = b13. ∅ – (res): 4, 12

LECTURE 6. RESOLUTION: FOL 148

6.10 Exercise ¡E!

Verify your informal reasoning form Exercise 4.9, point1 (page 88) using resolution. That is, we have to provethat:

∀x[R(x, x)→ ∀yR(x, y)]∧∀x∀y[R(x, y)→ R(y, x)]∧∀x∃y[¬R(y, x)]

→ ∀x[¬R(x, x)]. (6.23)

LECTURE 6. RESOLUTION: FOL 149

6.10 Solution

We transform negated (6.23) into clausal form:

1. ¬R(x1, x1) ∨R(x1, y1) (with ∀y moved to the prefix)2. ¬R(x2, y2) ∨R(y2, x2)3. ¬R(f(x3), x3) (Skolemized)4. R(a, a) (negated and Skolemized

conclusion).

Resolution proof:

5. R(a, y5) – (res): 1, 4 with x1 = a and renaming y1/y56. R(y6, a) – (res): 2, 5

with x2 = a, y2 = y5 and renaming y5/y67. ∅ – (res): 3, 6 with x3 = a, y6 = f(a).

Lecture 7

Deductive databases

150

LECTURE 7. DEDUCTIVE DATABASES 151

7.1 Exercise

Translate the following rule into a first-order formula:

brother(X, Y ) :− male(X),parent(Z,X),parent(Z, Y ).

(7.1)

LECTURE 7. DEDUCTIVE DATABASES 152

7.1 Solution

In rule (7.1) variable Z occurs only in the rule’s body, soit is existentially quantified. The body is translated into:

∃z[male(x) ∧ parent(z, x) ∧ parent(z, y)]. (7.2)

Rules are understood as body → head, so rule (7.1) istranslated (almost) into:

∃z[male(x) ∧ parent(z, x) ∧ parent(z, y)]→ brother(x, y).

(7.3)

In (7.3) variables x, y are not yet quantified. Since vari-ables X, Y appear both in rule’s (7.1) head and body, weuniversally quantify them and the required translation is:

∀x∀y[∃z[male(x) ∧ parent(z, x) ∧ parent(z, y)]

→ brother(x, y)].

(7.4)

LECTURE 7. DEDUCTIVE DATABASES 153

7.2 Exercise

Transform the following formulas into Datalog rules:

1. ∀x∀y[(mother(x, y) ∨ father(x, y))→parent(x, y)

];

(7.5)

2. ∀x∀y[[¬(parent(x, y)→ ¬male(y))]→ son(y)

];

(7.6)

3. ∀x∀y[mother(x, y)→ (parent(x, y) ∧ female(x))

].

(7.7)

4. ∀y∀z[∃x(parent(y, x) ∧ parent(x, z))]→ grandparent(y, z)

].

(7.8)

LECTURE 7. DEDUCTIVE DATABASES 154

7.2 Solution

1

First note that, according to our convention, universalquantifiers in (7.5) can be removed:

(mother(x, y)∨father(x, y))→parent(x, y). (7.9)

Now we use tautology[(p∨q)→ r

]↔ [(p→ r)∧(q → r)]

according to which (7.9) is equivalent to:

mother(x, y)→ parent(x, y) ∧father(x, y)→ parent(x, y).

(7.10)

Now it is easy to see that (7.10) is equivalent to the fol-lowing Datalog rules:

parent(X, Y ) :− mother(X, Y ).parent(X, Y ) :− father(X, Y ).

(7.11)

LECTURE 7. DEDUCTIVE DATABASES 155

2

As before, we remove universal quantifiers from (7.6):

[¬(parent(x, y)→ ¬male(y))]→ son(y). (7.12)

Using the implication law we obtain the following formulaequivalent to (7.12):

[parent(x, y) ∧ ¬¬male(y)]→ son(y). (7.13)

We remove double negation:

[parent(x, y) ∧male(y)]→ son(y). (7.14)

and obtain the following Datalog rule:

son(Y ) :− parent(x, y),male(y). (7.15)

3

As before, we remove universal quantifiers from (7.7):

mother(x, y)→ (parent(x, y) ∧ female(x)). (7.16)

Now we use tautology[p→ (q∧r)

]↔ [(p→ r)∧(p→ r)]

according to which (7.16) is equivalent to:

mother(x, y)→ parent(x, y) ∧mother(x, y)→ female(x).

(7.17)

Now it is easy to see that (7.17) is equivalent to the fol-lowing Datalog rules:

parent(X, Y ) :− mother(X, Y ).female(X) :− mother(X, Y ).

(7.18)

LECTURE 7. DEDUCTIVE DATABASES 156

4

First we remove universal quantifiers from (7.8):

∃x(parent(y, x) ∧ parent(x, z))→ grandparent(y, z).

(7.19)

Existential quantifier ∃x binds x in the antecedent of im-plication (7.19) and x does not appear in its conclusion.Therefore we can remove ∃x:1

(parent(y, x)∧parent(x, z))→grandparent(y, z). (7.20)

Observe that (7.20) is equivalent to the following Datalogrule:

grandparent(Y, Z) :− parent(Y,X),parent(X,Z).

(7.21)

1Note that this is not Skolemization. We simply use the factthat variables appearing in rule’s body and not appearing in itshead are implicitly existentially quantified in the body.

LECTURE 7. DEDUCTIVE DATABASES 157

7.3 Exercise ¡E!

1. Design a Datalog database for storing informationabout objects on a town street. Objects mightbe cars, bikes, etc. Each object is characterizedby its size (small, medium or large) and velocity(slow, moderate, fast). In addition, the databaseshould contain information about direct precedencebetween objects.2

2. Express in predicate calculus the constraint

“every object has unique (exactly one)size and unique velocity”.

3. Provide an integrity constraint concerning the prece-dence relation between objects.

4. Formulate in logic queries selecting:

a) all bikes which are directly between two largecars;

b) all medium cars which precede (not necessar-ily directly3) a fast large car.

2Object a “directly precedes” object b, denoted by a← b, if aprecedes b and there are no objects between a and b.

3It is assumed that object c precedes object e if c← e or thereis n ≥ 1 and objects d1, . . . , dn such that c ← d1 ← d2 ← . . . ←dn ← e.

LECTURE 7. DEDUCTIVE DATABASES 158

7.3 Solution

1

The database contains relations:

• object(id, type, size, velocity), where id is a (unique)object identifier, type ∈ String is an object type(car, bike, etc.), size ∈ Numbers is its size, andvelocity ∈ String is its velocity (small, moderate,fast);

• d prec(id1, id2), where id1, id2 are object identi-fiers.

Example:

object(2, ‘car’, ‘medium’, ‘moderate’)– object 2 is a medium car whosevelocity is moderate;

object(6, ‘bike’, ‘small’, ‘slow’)– object 2 is a small bike whosevelocity is slow;

d prec(2, 6) – object 2 directly precedes ob-ject 6.

LECTURE 7. DEDUCTIVE DATABASES 159

2

Every object has unique (exactly one) size and uniquevelocity:

∀i∀t∀s∀v∀t′∀s′∀v′[(object(i, t, s, v) ∧ object(i, t′, s′, v′))

→ (s = s′ ∧ v = v′)].

3

An integrity constraint concerning the precedence rela-tion between objects:

∀x∀y[d prec(x, y)→ ¬d prec(y, x)].

4(a)

Select all bikes which are directly between two large cars(recall that ‘ ’ is an anonymous “don’t care” variable):

answer(Id) :− object(Id1, ‘car’, ‘large’, ),object(Id, ‘bike’, , ),object(Id2, ‘car’, ‘large’, ),d prec(Id1, Id),d prec(Id, Id2).

Now answer(X) provides all required objects.

LECTURE 7. DEDUCTIVE DATABASES 160

4(b)

Select all medium cars which precede (not necessarilydirectly) a fast large car.

We first define the precedence relation:

prec(Id1, Id2) :− d prec(Id1, Id2).prec(Id1, Id2) :− d prec(Id1, Id),

prec(Id, Id2).

Now we are ready to formulate the required query:

answer(Id) :− object(Id, ‘car’, ‘medium’, ),object(Id1, ‘car’, ‘large’, ‘fast’),prec(Id, Id1).

LECTURE 7. DEDUCTIVE DATABASES 161

7.4 Exercise ¡E!

Consider regions on a screen. We say that a region r iscontained in region t if all pixels of region r are locatedwithin region t and r 6= t. We say that r is directlycontained in region t when

• r is contained in region t, and

• there is no region s such that r is contained in sand s is contained t.

For example, in Figure 7.1 region a is contained in regionb and in region c. Region a is directly contained in b butnot directly contained in c. Region b is directly containedin c. Region d is contained (also directly) in c but neitherin a nor in b.

'

&

$

%a

b

c

d

Figure 7.1: Sample screen regions.

LECTURE 7. DEDUCTIVE DATABASES 162

1. Design a Datalog database for storing informationabout screen regions, where each region is charac-terized by its shape, size and color. In addition,for each pair of regions r, s, the database containsinformation whether r is directly contained in s.

2. Express in predicate calculus the constraint:

“the relation of containment is antisym-metric”

3. Provide another integrity constraint concerning therelation of region containment.

4. Formulate in logic queries selecting:

a) all small regions directly contained in a largecircle;

b) all small objects contained4 in a big green square.

4Directly or not.

LECTURE 7. DEDUCTIVE DATABASES 163

7.4 Solution

1

The database contains relations:

• region(id, shape, size, color), where id is a (unique)identifier for each region, shape, size, color ∈ Stringare its shape, size and color;

• d cont(id1, id2), where id1, id2 are region identi-fiers.

Example:

region(18, ‘oval’, small, red)– region 18 is a small, red oval;

street(22, ‘square’, large, green) – region 22is a large, green square;

d cont(18, 22) – region 18 is directly containedin region 22.

2

The relation of containment is antisymmetric:

∀x∀y[d cont(x, y)→ ¬d cont(y, x)].

LECTURE 7. DEDUCTIVE DATABASES 164

3

Another integrity constraint concerning the relation ofregion containment:

∀x[¬d cont(x, x)].

4(a)

Select all small regions directly contained in a large circle:

answer(R) :− region(R, , ‘small’, ),region(R1, ‘circle’, ‘large’, ),d cont(R,R1).

Now answer(X) provides all required regions.

4(b)

Select all small objects contained in a big green square.

We first define:

contained(R1, R2) :− d cont(R1, R2).contained(R1, R2) :− d cont(R1, R3),

contained(R3, R2).(7.22)

The required query can be formulated as:

answer(R) :− region(R, , ‘small’, ),region(R1, ‘square’, ‘big’, ‘green’),contained(R,R1).

LECTURE 7. DEDUCTIVE DATABASES 165

7.5 Exercise ¡E!

Consider road segments and landmarks. Road segmentsare chosen in such a way that each landmark is close toexactly one road segment. Road segments are directlyconnected if they have a common border. In particular,each road segment is directly connected to itself.

ii

L1

L2

S1

S2

S3 S4 S5

S6

Figure 7.2: Sample road segments S1, . . . , S6 and land-marks L1, L2.

For example, in Figure 7.2:

• segments S1 and S3, segments S3 and S4, segmentsS4 and S5, segments S4 and S6 as well as S4 and S2

are directly connected;

• for 1 ≤ i ≤ 6 we have that Si is directly connectedto Si;

• for example, segments S1 and S6, segments S2 andS5 as well as S3 and S5 are not directly connected

• landmark L1 is close to segment S5 and landmarkL2 is close to road segment S1.

LECTURE 7. DEDUCTIVE DATABASES 166

A landmark L is accessible by a road trip from landmarkL′ if L is close to a road segment S and L′ is close toa road segment S ′ and there is a sequence of road seg-ments R1, . . . , Rn with n ≥ 1 such that S = R0, S

′ = Rn

and for all i such that 1 ≤ i < n, Ri is directly connectedto Ri+1.

1. Design a database storing information about roadsegments, their direct connections and landmarksclose to particular road segments. Road segmentsare characterized by their quality (low, medium,high) and average speed. The database containsalso information about direct connections betweenroad segments.

2. Express in predicate calculus the constraint:

“each landmark is close to exactly oneroad segment”.

3. Provide another integrity constraint concerning re-lationships in the database.

4. Formulate in logic queries selecting:

a) all landmarks close to roads which are of highquality with average speed greater than 65km

h;

b) find all landmarks which are accessible by a roadtrip from a given landmark.

LECTURE 7. DEDUCTIVE DATABASES 167

7.5 Solution

1

The database contains relations:

• segment(id, quality, avs), where id is a (unique)road segment identifier, quality ∈ String is itsquality (low, medium or high), and avs ∈ Numbersis its average speed;

• d con(id1, id2), where id1, id2 are street identifiers;

• close(idL, idS), where idL is a landmark identifierand idS is a street identifier.

Example:

segment(64, ‘low’, 50) – road segment withid = 64 is of low quality and average

speed 50km

h;

segment(12, ‘medium’, 60) – road segmentwith id = 12 is of medium quality and

average speed 60km

h;

d con(12, 64) – road segments 12 and 64 aredirectly connected;

close(11, 64) – landmark 11 is close to roadsegment 64.

LECTURE 7. DEDUCTIVE DATABASES 168

2

Each landmark is close to exactly one road segment:

∀x∃y[close(x, y) ∧ ∀z(close(x, z)→ z = y)

]. (7.23)

3

Another integrity constraint concerning relationships inthe database:

∀x∀y∀z∀y′∀z′[(segment(x, y, z) ∧ segment(x, y′, z′))→ (y = y′ ∧ z = z′)]

4(a)

Select all all landmarks close to roads which are of high

quality with average speed greater than 65km

h:

answer(L) :− segment(S, ‘high’, Av),Av > 65,close(L, S).

Now answer(L) provides all required landmarks.

LECTURE 7. DEDUCTIVE DATABASES 169

4(b)

Select all landmarks which are accessible by a road tripfrom a given landmark.

We first define accessibility among road segments (acc)and accessibility among landmarks (accessible):

acc(S1, S2) :− d con(S1, S2).acc(S1, S2) :− d con(S1, S3),

acc(S3, S2).

accessible(L1, L2) :− close(L1, S1),close(L2, S2),acc(S1, S2).

Now, given a landmark, say ‘Huge Statue’, we can for-mulate the required query:

answer(N) :− accessible(‘HugeStatue’, N).

Lecture 8

Sequent (Gentzen)calculus

170

LECTURE 8. SEQUENT (GENTZEN) CALCULUS171

8.1 Exercise

Using Gentzen system solve Exercise 2.2, i.e., check whetherthe following formula is satisfiable:

(p ∨ q) ∧ (¬p ∨ ¬q). (8.1)

If it is, provide a satisfying valuation.

LECTURE 8. SEQUENT (GENTZEN) CALCULUS172

8.1 Solution

To check satisfiability we use the “inverted” sequent:

(∧l) (p ∨ q) ∧ (¬p ∨ ¬q)⇒ ∅

(∨l) p ∨ q,¬p ∨ ¬q ⇒ ∅

(∨l) p,¬p ∨ ¬q ⇒ ∅(∨l) q,¬p ∨ ¬q ⇒ ∅

(¬l) p,¬p⇒ ∅(¬l) p,¬q ⇒ ∅

(¬l) q,¬p⇒ ∅(¬l) q,¬q ⇒ ∅

p⇒ p︸ ︷︷ ︸axiom

p⇒ q q ⇒ p q ⇒ q︸ ︷︷ ︸axiom

Leaves containing non-axioms provide counterexamplesfor the negated formula (represented by the “inverted”sequent). Each such a counterexample provides a satis-fying valuation of the initial formula:

• p⇒ q gives p = T and q = F;

• q ⇒ p gives q = T and p = F.

LECTURE 8. SEQUENT (GENTZEN) CALCULUS173

8.2 Exercise ¡E!

Using Gentzen system check whether formulas given inExercise 2.3 are tautologies. If not, extract a counterex-ample from the constructed proof.

Recall that in Exercise 2.3 we considered the followingformulas:

1. (p ∨ q)→ p. (8.2)

2. (p ∨ q)→ (p ∧ r). (8.3)

3. (p→ q) ∨ (q → p). (8.4)

4. (p ∨ q)→[(p ∨ q ∨ ¬r) ∧ (r ∨ p ∨ q)

](8.5)

LECTURE 8. SEQUENT (GENTZEN) CALCULUS174

8.2 Solution

1

We construct a proof tree for (8.2):

(→r) ∅ ⇒ (p ∨ q)→ p

(∨l) p ∨ q ⇒ p

p⇒ p︸ ︷︷ ︸axiom

q ⇒ p

There is a leaf containing a non-axiom q ⇒ p. This leafprovides a counterexample q = T, p = F.

LECTURE 8. SEQUENT (GENTZEN) CALCULUS175

2

We construct a proof tree for (8.3):

(→r) ∅ ⇒ (p ∨ q)→ (p ∧ r)

(∨l) p ∨ q ⇒ p ∧ r

(∧r) p⇒ p ∧ r (∧r) q ⇒ p ∧ r

p⇒ p︸ ︷︷ ︸axiom

p⇒ r q ⇒ p q ⇒ r

There are leaves containing non-axioms and providingcounterexamples for (8.3):

• p ⇒ r: a counterexample p = T, r = F (the valueof q does not matter);

• q ⇒ p: a counterexample q = T, p = F (the valueof r does not matter);

• q ⇒ r: a counterexample q = T, r = F (the valueof p does not matter).

LECTURE 8. SEQUENT (GENTZEN) CALCULUS176

3

We construct a proof tree for (8.4):

(∨r) ∅ ⇒ (p→ q) ∨ (q → p)

(→r) ∅ ⇒ p→ q, q → p

(→r) p⇒ q, q → p

p, q ⇒ q, p︸ ︷︷ ︸axom

The only leaf contains an axiom, so formula (8.4) is a tau-tology.

LECTURE 8. SEQUENT (GENTZEN) CALCULUS177

4

We construct a proof tree for (8.5):

(→ r) ∅ ⇒ (p ∨ q)→[(p ∨ q ∨ ¬r) ∧ (r ∨ p ∨ q)

](∧r) p ∨ q ⇒ (p ∨ q ∨ ¬r) ∧ (r ∨ p ∨ q)

(∨r)p ∨ q ⇒ p ∨ q ∨ ¬r

(∨r)p ∨ q ⇒ r ∨ p ∨ q

(∨r)p ∨ q ⇒ p, q ∨ ¬r

(∨r)p ∨ q ⇒ r, p ∨ q

(∨l) p ∨ q ⇒ p, q,¬r(∨l) p ∨ q ⇒ r, p, q

p⇒ p, q,¬r︸ ︷︷ ︸axiom

q ⇒ p, q,¬r︸ ︷︷ ︸axiom

p⇒ r, p, q︸ ︷︷ ︸axiom

q ⇒ r, p, q︸ ︷︷ ︸axiom

All leaves contain axioms, so formula (8.5) is a tautology.

LECTURE 8. SEQUENT (GENTZEN) CALCULUS178

8.3 Exercise

Derive rules for the connective “exclusive or” ∨ definedby:

[A∨B]↔ (A ∨B) ∧ (¬B ∨ ¬A). (8.6)

LECTURE 8. SEQUENT (GENTZEN) CALCULUS179

8.3 Solution

Derivation of rule (∨ l):

(def) A,B ∨C,D ⇒ E

(∧l) A, (B ∨ C) ∧ (¬B ∨ ¬C), D ⇒ E

(∨l) A,B ∨ C,¬B ∨ ¬C,D ⇒ E

(∨l) A,B,¬B ∨ ¬C,D ⇒ E (∗)

(¬l) A,B,¬B,D ⇒ E (¬l) A,B,¬C,D ⇒ E

A,B,D ⇒ B,E︸ ︷︷ ︸axiom

A,B,D ⇒ C,E

(∨l) (∗) : A,C,¬B ∨ ¬C,D ⇒ E

(¬l) A,C,¬B,D ⇒ E (¬l) A,C,¬C,D ⇒ E

A,C,D ⇒ B,E A,C,D ⇒ C,E︸ ︷︷ ︸axiom

The rule:

(∨ l) A,B ∨C,D ⇒ E

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

LECTURE 8. SEQUENT (GENTZEN) CALCULUS180

Derivation of rule (∨ r):

(def) A⇒ B,C ∨D,E

(∧r) A⇒ B, (C ∨D) ∧ (¬C ∨ ¬D), E

(∨r) A⇒ B,C ∨D,E A⇒ B,¬C ∨ ¬D,E

(∨r) A⇒ B,C,D,E (¬r) A⇒ B,¬C,¬D,E

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

A,C,D ⇒ B,E

The rule:

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

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

LECTURE 8. SEQUENT (GENTZEN) CALCULUS181

8.4 Exercise

Using rules derived in Exercise 8.3, verify whether:

1. (p∨ q)→ (p ∨ q);

2. (p ∨ q)→ (p∨ q).

LECTURE 8. SEQUENT (GENTZEN) CALCULUS182

8.4 Solution

1

(→r) ∅ ⇒ (p∨ q)→ (p ∨ q)

(∨r) p∨ q ⇒ p ∨ q

(∨ l) p∨ q ⇒ p, q

p⇒ q, p, q︸ ︷︷ ︸axiom

q ⇒ p, p, q︸ ︷︷ ︸axiom

All leaves are axioms, so formula (p∨ q) → (p ∨ q) isa tautology.

2

(→r) ∅ ⇒ (p ∨ q)→ (p∨ q)

(∨r) p ∨ q ⇒ p∨ q

(∨l) p ∨ q ⇒ p, q (∨l) p ∨ q, p, q ⇒ ∅p⇒ p, q︸ ︷︷ ︸axiom

q ⇒ p, q︸ ︷︷ ︸axiom

p, p, q ⇒ ∅ q, p, q ⇒ ∅

The formula is not a tautology. Both non-axiom leavesprovide the same counterexample for (p ∨ q) → (p∨ q),which is p = q = T.

LECTURE 8. SEQUENT (GENTZEN) CALCULUS183

8.5 Exercise ¡E!

Using Gentzen system prove the following first-order for-mula (see Exercise 5.4, page 97 for a tableaux proof):

[∀x∃y[R(x, y)] ∧ ∀x∀y[R(x, y)→ ∀zR(x, z)]

]→ ∀x∀yR(x, y).

(8.7)

LECTURE 8. SEQUENT (GENTZEN) CALCULUS184

8.5 Solution

A proof:

∅ ⇒[∀x∃y[R(x, y)] ∧ ∀x∀y[R(x, y)→ ∀zR(x, z)]

](→r) → ∀x∀yR(x, y)

∀x∃y[R(x, y)] ∧ ∀x∀y[R(x, y)→ ∀zR(x, z)]⇒

(∧l) ∀x∀yR(x, y)

(∀x r)∀x∃y[R(x, y)],∀x∀y[R(x, y)→ ∀zR(x, z)]⇒ ∀x∀yR(x, y)

(∀y r) ∀x∃y[R(x, y)],∀x∀y[R(x, y)→ ∀zR(x, z)]⇒ ∀yR(a, y)

(∀x l) ∀x∃y[R(x, y)],∀x∀y[R(x, y)→ ∀zR(x, z)]⇒ R(a, b)

(∃y l) ∃y[R(a, y)], ∀x∀y[R(x, y)→ ∀zR(x, z)]⇒ R(a, b)

(∀x l) R(a, c),∀x∀y[R(x, y)→ ∀zR(x, z)]⇒ R(a, b)

(∀y l) R(a, c), ∀y[R(a, y)→ ∀zR(a, z)]⇒ R(a, b)

(→ l) R(a, c), R(a, c)→ ∀zR(a, z)⇒ R(a, b)

R(a, c)⇒ R(a, c), R(a, b)︸ ︷︷ ︸axiom

(∀z l) R(a, c), ∀zR(a, z)⇒ R(a, b)

R(a, c), R(a, b)⇒ R(a, b)︸ ︷︷ ︸axiom

LECTURE 8. SEQUENT (GENTZEN) CALCULUS185

8.6 Exercise ¡E!

Using Gentzen system prove that formula:

∀x∃y∃z[P (x, y, z) ∨ ¬∃z∃u(¬P (x, z, u))] (8.8)

implies:

∃x∃yP (a, x, y), (8.9)

where a is a constant.

(The same implication is considered in Exercise 5.4,page 99).

LECTURE 8. SEQUENT (GENTZEN) CALCULUS186

8.6 Solution

∅ ⇒ ∀x∃y∃z[P (x, y, z) ∨ ¬∃z∃u(¬P (x, z, u))]

(→r)→ ∃x∃yP (a, x, y)

(∀x l) ∀x∃y∃z[P (x, y, z) ∨ ¬∃z∃u(¬P (x, z, u))]⇒ ∃x∃yP (a, x, y)

(∃y l) ∃y∃z[P (a, y, z) ∨ ¬∃z∃u(¬P (a, z, u))]⇒ ∃x∃yP (a, x, y)

(∃z l) ∃z[P (a, b, z) ∨ ¬∃z∃u(¬P (a, z, u))]⇒ ∃x∃yP (a, x, y)

(∃x r)P (a, b, c) ∨ ¬∃z∃u(¬P (a, z, u))⇒ ∃x∃yP (a, x, y)

(∃y r)P (a, b, c) ∨ ¬∃z∃u(¬P (a, z, u))⇒ ∃yP (a, b, y)

(∨l) P (a, b, c) ∨ ¬∃z∃u(¬P (a, z, u))⇒ P (a, b, c)

P (a, b, c)⇒ P (a, b, c)︸ ︷︷ ︸axiom

(¬l) ¬∃z∃u(¬P (a, z, u))⇒ P (a, b, c)

(∃z r) ∅ ⇒ P (a, b, c),∃z∃u(¬P (a, z, u))

(∃u r)∅ ⇒ P (a, b, c), ∃u(¬P (a, b, u))

(¬r)∅ ⇒ P (a, b, c),¬P (a, b, c)

P (a, b, c)⇒ P (a, b, c)︸ ︷︷ ︸axiom

Both leaves contain axioms which proves that the con-sidered formula is a tautology.

Lecture 9

Sample exams

Exam rules

1. You can use your own copies of compendium ex-tracted from lectures as well as an English-Swedishdictionary.

2. Exercises are formulated in English, but answerscan be given in English or Swedish.

3. You are not allowed to:

• use any writing material other than indicatedin point 1, in particular you cannot use thisebook with exercises and solutions;

• use calculators, mobile phones or any otherelectronic devices;

187

LECTURE 9. SAMPLE EXAMS 188

• lend/borrow/exchange anything during theexam.

4. If an exercise has not been specified completely asyou see it, state which (reasonable) assumptionsyou have made.

5. Begin each exercise on a new sheet of paper. Writeonly on one side of the paper. Write clearly andmake sure to give adequate explanations for all youranswers.

6. There are 4 exercises, each exercise gives maximum10 points (40 points together). Grading is providedin the following table.

number of points (n) grade34 ≤ n ≤ 40 527 ≤ n < 34 420 ≤ n < 27 3

n < 20 U (not passed)

Note: exercises for the first two exams are solved whilefor the third one are intentionally left unsolved.

LECTURE 9. SAMPLE EXAMS 189

9.1 Exercise (exam 1)

1. Prove the following propositional formula[p ∧ (¬q ∨ r)

]→[¬(¬p ∧ q) ∨ r

](9.1)

a) (2 points) using Gentzen system;

b) (2 points) using resolution.

2. Prove the following formula of predicate logic, wherea, b are constants:

∃x∀y∀z[R(x, y, z) ∧ S(x) ∧ T (y)

]→

∃x[R(x, a, b) ∧ T (a)

] (9.2)

a) (3 points) using tableaux;

b) (3 points) using resolution.

LECTURE 9. SAMPLE EXAMS 190

9.1 Solution

1(a)

(→r) ∅ ⇒[p ∧ (¬q ∨ r)

]→[¬(¬p ∧ q) ∨ r

](∨r) p,¬q ∨ r ⇒ ¬(¬p ∧ q) ∨ r

(¬r) p,¬q ∨ r ⇒ ¬(¬p ∧ q), r

(∧l) p,¬q ∨ r,¬p ∧ q ⇒ r

(¬l) p,¬q ∨ r,¬p, q ⇒ r

p,¬q ∨ r, q ⇒ r, p︸ ︷︷ ︸axiom

LECTURE 9. SAMPLE EXAMS 191

1(b)

We first negate formula (9.1):

¬[[p ∧ (¬q ∨ r)

]→[¬(¬p ∧ q) ∨ r

]]↔[

p ∧ (¬q ∨ r)]∧ ¬[¬(¬p ∧ q) ∨ r

]↔

p ∧ (¬q ∨ r) ∧ ¬¬(¬p ∧ q) ∧ ¬r ↔p ∧ (¬q ∨ r) ∧ ¬p ∧ q ∧ ¬r. (9.3)

Clausal form of (9.3):

1. p2. ¬q ∨ r3. ¬p4. q5. ¬r

Proof by resolution:

6. ¬q (res) : 5, 27. ∅ (res) : 6, 4

LECTURE 9. SAMPLE EXAMS 192

2(a)

We construct a tableau for the negated formula (9.2):

¬[∃x∀y∀z

[R(x, y, z)∧S(x) ∧ T (y)

]→∃x

[R(x, a, b)∧T (a)

]]↓ (¬→)

∃x∀y∀z[R(x, y, z)∧S(x) ∧ T (y)

],¬∃x

[R(x, a, b)∧T (a)

]↓ (∃x with x = c)

∀y∀z[R(c, y, z) ∧ S(c) ∧ T (y)

],¬∃x

[R(x, a, b)∧T (a)

]↓ (¬∃x with x = c)

∀y∀z[R(c, y, z) ∧ S(c) ∧ T (y)

],¬[R(c, a, b) ∧ T (a)

]↓ (∀y with y = a)

∀z[R(c, a, z) ∧ S(c) ∧ T (a)

],¬[R(c, a, b) ∧ T (a)

]↓ (∀z with z = b)

R(c, a, b) ∧ S(c) ∧ T (a),¬[R(c, a, b) ∧ T (a)

]↓ (∧)

R(c, a, b), S(c) ∧ T (a),¬[R(c, a, b) ∧ T (a)

]↓ (∧)

R(c, a, b), S(c), T (a),¬[R(c, a, b) ∧ T (a)

]↙ ↘ (¬∧)

R(c, a, b), S(c), T (a),¬R(c, a, b)︸ ︷︷ ︸closed

R(c, a, b), S(c), T (a),¬T (a)︸ ︷︷ ︸closed

The tableau is closed, so formula (9.2) is a tautology.

LECTURE 9. SAMPLE EXAMS 193

2(b)

We first negate the formula:

¬[∃x∀y∀z

[R(x, y, z)∧S(x)∧T (y)

]→∃x

[R(x, a, b)∧T (a)

]]↔

∃x∀y∀z[R(x, y, z)∧S(x)∧T (y)

]∧¬∃x

[R(x, a, b)∧T (a)

]↔

∃x∀y∀z[R(x, y, z)∧S(x)∧T (y)

]∧∀x¬

[R(x, a, b)∧T (a)

]↔

∃x∀y∀z[R(x, y, z)∧S(x)∧T (y)

]∧∀x

[¬R(x, a, b)∨¬T (a)

].

Now Skolemiztion for ∃x results in:

∀y∀z[R(c, y, z)∧S(c)∧T (y)

]∧∀x

[¬R(x, a, b)∨¬T (a)

],

so we have clauses (after renaming variables):

1. R(c, y1, z1)2. S(c)3. T (y3)4. ¬R(x4, a, b) ∨ ¬T (a)

A proof by resolution:

5. ¬R(x5, a, b) – (res): 3, 4 with y3 = aand renaming x4/x5

6. ∅ – (res): 1, 5 withx5 = c, y1 = a, z1 = b.

LECTURE 9. SAMPLE EXAMS 194

9.2 Exercise (exam 1)

1. (4 points) Translate the following sentences intoa set of propositional formulas:

“Boxes are small or medium.”“Each box is red, green or blue.”“Small boxes are blue or red.”“Medium boxes are green or blue.”“For shipment robots chose red boxes.”“For activities other than shipment, robots

neither chose blue nor green boxes.”

2. (2 points) Assuming that exactly one box is to bechosen and that each box can have exactly onecolor, hypothesize what choice (size and color) canbe made and explain your reasoning informally.

3. (4 points) Prove your claim formally using a proofsystem of your choice (tableaux or resolution).Please do not use truth table method, as this willgive no points).

LECTURE 9. SAMPLE EXAMS 195

9.2 Solution

1

A possible translation:

small ∨mediumred ∨ green ∨ bluesmall→ (blue ∨ red)medium→ (green ∨ blue)shipment→ red¬shipment→ (¬blue ∧ ¬green).

(9.4)

2

Observe that for shipment red boxes are chosen. Fornon-shipment neither blue nor green boxes are chosen, soonly red boxes remain. Therefore no matter whether forshipment or not, red boxes are chosen.

We have only small or medium boxes. The chosen boxesare red, which excludes medium boxes, (if a box is redthen it is neither blue nor green). So one can chose onlyboxes being both small and red.

LECTURE 9. SAMPLE EXAMS 196

3

We use resolution. We first show that the set of formulas(9.4) implies red. We first transform (9.4) into a set ofclauses:

1. small ∨medium2. red ∨ green ∨ blue3. ¬small ∨ blue ∨ red4. ¬medium ∨ green ∨ blue5. ¬shipment ∨ red6. shipment ∨ ¬blue7. shipment ∨ ¬green.

(9.5)

Now we negate formula:

[1. ∧ 2. ∧ 3. ∧ 4. ∧ 5. ∧ 6. ∧ 7.]→ red

and obtain:

[1. ∧ 2. ∧ 3. ∧ 4. ∧ 5. ∧ 6. ∧ 7.] ∧ ¬red.

Therefore, we consider clauses (1) – (7) together with

8. ¬red

A possible proof by resolution:

9. ¬shipment – (res): 5, 810. ¬blue – (res): 6, 911. ¬green – (res): 7, 912. green ∨ blue – (res): 2, 813. green – (res): 10, 1214. ∅ – (res): 11, 13.

LECTURE 9. SAMPLE EXAMS 197

To prove that the chosen box is small, we need formulas:1

red→ ¬greenred→ ¬bluegreen→ ¬bluegreen→ ¬redblue→ ¬greenblue→ ¬red.

We could add all of them, but it suffices to take the firsttwo, so for the sake of simplicity we skip the remain-ing ones. We also add the conclusion red which is al-ready proved to be the consequence of the initial set ofclauses. Since we want to prove that small is implied byour clauses, we also add its negation to the set of clauses.The new clauses are:

15. red16. ¬red ∨ ¬green17. ¬red ∨ ¬blue18. ¬small.

(9.6)

1For the sake of simplicity, we consider the assumption aboutuniqueness of colors separately. The formulas expressing unique-ness could be added to clauses 1–8 immediately but the proof wouldbe less readable.

LECTURE 9. SAMPLE EXAMS 198

A possible proof that the set of clauses (9.5) togetherwith (9.6) leads to contradiction:

19. ¬green – (res): 15, 1620. ¬blue – (res): 15, 1721. medium – (res): 1, 1822. green ∨ blue – (res): 4, 2123. blue – (res): 19, 2224. ∅ – (res): 20, 23

which completes the proof.

LECTURE 9. SAMPLE EXAMS 199

9.3 Exercise (exam 1)

Consider a set of persons and a relation R of “being a rel-ative of”. Let:

(a) the relation relative has the property that wheneverperson A is a relative of both B and C then also Bis a relative of C.

Consider the relation “the same family member”, de-noted by F . We assume that:

(b) whenever a person A is a relative of a person Bthen they are in the same family;

(c) everybody is in his/her family.

Using the provided information:

(1) (3 points) express in predicate logic the properties(a), (b), (c);

(2) (2 points) provide informal arguments that R (asunderstood in “real life”) is transitive and expressin predicate logic the transitivity of R;

(3) (5 points) using resolution, facts from points (1),(2) and the property:

∀x∀y[R(x, y) ∨ ∃z[R(x, z) ∧R(z, y)]

],

prove that ∀x∀y[F (x, y)].

LECTURE 9. SAMPLE EXAMS 200

9.3 Solution

1

(a) ∀x∀y∀z[(R(x, y) ∧R(x, z))→ R(y, z)];

(b) ∀x∀y[R(x, y)→ F (x, y)];

(c) ∀x[F (x, x)].

2

The transitivity of R is expressed by:

∀x∀y∀z[(R(x, y) ∧R(y, z))→ R(x, z)].

The informal argument can be as follows. A relative isa person related by blood or marriage. So, if x, y arerelatives, there is a chain of persons x1 − x2 − . . . − xk

such that:

– x is related by blood or marriage to x1,– x1 related by blood or marriage to x2,– . . .– xk−1 is related by blood or marriage to xk,– xk is related by blood or marriage to y.

If y and z are relatives then there is a similar chain be-tween y and z. Therefore, there is a chain of personsrelating x and z (the chain from x to y plus the chainfrom y to z), i.e., x and z are relatives, too.

LECTURE 9. SAMPLE EXAMS 201

3

We have to show that the conjunction of formulas:

∀x∀y∀z[(R(x, y) ∧R(x, z))→ R(y, z)]∀x∀y[R(x, y)→ F (x, y)]∀x[F (x, x)]∀x∀y∀z[(R(x, y) ∧R(y, z))→ R(x, z)]

∀x∀y[R(x, y) ∨ ∃z[R(x, z) ∧R(z, y)]

]implies ∀x∀y[F (x, y)].

To apply resolution we negate the conclusion, translateformulas into clauses and try to derive the empty clause∅. Below clauses 5., 6. are obtained from:

∀x∀y[R(x, y) ∨ ∃z[R(x, z) ∧R(z, y)]]

by Skolemizing and transforming the formula into clauses.Clause 7. is a Skolemized negation of the conclusion, i.e.,Skolemized ∃x∃y[¬F (x, y)]. As usually, variables are re-named.

The clauses:

1. ¬R(x1, y1) ∨ ¬R(x1, z1) ∨R(y1, z1)2. ¬R(x2, y2) ∨ F (x2, y2)3. F (x3, x3)4. ¬R(x4, y4) ∨ ¬R(y4, z4) ∨R(x4, z4)5. R(x5, y5) ∨R(x5, f(x5, y5))6. R(x6, y6) ∨R(f(x6, y6), y6)7. ¬F (a, b).

LECTURE 9. SAMPLE EXAMS 202

A proof by resolution:

8. ¬R(a, b) – (res): 2, 7 with x2 = a, y2 = b9. R(a, f(a, b)) – (res): 5, 8 with x5 = a, y5 = b

10. R(f(a, b), b) – (res): 6, 8 with x6 = a, y6 = b11. ¬R(f(a, b), z11) ∨R(a, z11)

– (res): 4, 9 with x4 = a, y4 = f(a, b)and renaming z4/z11

12. R(a, b) – (res): 10, 11 with z11 = b13. ∅ – (res): 8, 12,

which completes the proof.

LECTURE 9. SAMPLE EXAMS 203

9.4 Exercise (exam 1)

1. (2 points) Design a Datalog database for storinginformation about streets in a town. Each streetis characterized by its name, width and length. Inaddition, for each street s the database containsinformation whether s is closed for traffic as well asinformation about all streets intersecting s.

2. (1 point) Express in predicate calculus the con-straint:

“the relation of road intersection is sym-metric.”

3. (1 point) Provide another integrity constraint con-cerning the relation of road intersection.

4. Formulate in logic queries selecting:

a) (2 points) all streets longer than 7km and widerthan 3m, intersecting the street named “Kungs-gatan”;

b) (4 points) all streets accessible by car froma given street, assuming that driving throughclosed streets is impossible.

LECTURE 9. SAMPLE EXAMS 204

9.4 Solution

1

The database contains relations:

• street(id, name,width, length, closed), where id isa (unique) identifier for a street, name ∈ String isits name, width, length ∈ Numbers are its widthand length, closed ∈ {true, false} indicates whethera given street is closed for traffic,

• intersects(id1, id2), where id1, id2 are street iden-tifiers.

Example:

street(21, ‘HanburySt.’, 5, 300, False)‘Hanbury St.’ is a street with id = 21,width = 5, length = 300, not closedfor traffic;

street(46, ‘NobleSt.’, 7, 200, T rue) – ‘Noble St’is a street with id = 46, width = 7,length = 200, closed for traffic;

intersects(21, 46) – streets 21 and 46 inter-sect each other.

LECTURE 9. SAMPLE EXAMS 205

2

The relation of road intersection is symmetric:

∀x∀y[intersects(x, y)→ intersect(y, x)].

3

Another integrity constraint concerning the relation ofroad intersection:

∀x[¬intersects(x, x)].

4(a)

Select all streets longer than 700m and wider than 3m,intersecting the street named “Kungsgatan” (recall that‘ ’ is an anonymous “don’t care” variable):

answer(Id) :− street(Id, ,W,L, ),W > 3, L > 700,street(Id1, ‘Kungsgatan’, , , ),intersects(Id, Id1).

Now answer(X) provides all required streets.

LECTURE 9. SAMPLE EXAMS 206

4(b)

Select streets accessible by car from a given street, assum-ing that it is impossible to drive through closed streets.We first define:

accessible(Id1, Id2) :− street(Id1, , , , C1),street(Id2, , , , C2),C1 6= True, C2 6= True,intersects(Id1, Id2).

accessible(Id1, Id2) :− street(Id1, , , , C1),street(Id2, , , , C2),C1 6= True, C2 6= True,intersects(Id1, Id3),accessible(Id3, Id2).

Now, given a street, say ‘Stone St.’, we can formulate therequired query (assuming that we are interested in streetnames, not identifiers):

answer(N) :− street(Id, ‘StoneSt.’, , , ),street(Id1, N, , , ),accessible(Id, Id1).

LECTURE 9. SAMPLE EXAMS 207

9.5 Exercise (exam 2)

1. Prove the following propositional formula:[(¬p ∨ ¬q) ∧ (p ∨ ¬q) ∧ r

]→[¬q ∧ r

](9.7)

a) (2 points) using tableaux;

b) (2 points) using resolution.

2. Prove the following formula of predicate logic, wherea is a constant:

∀x[P (x, x, x)

]∧

¬∃x∃y∃z[P (x, y, z) ∧ ¬P (z, x, a)

]→ ∃z

[P (a, z, a)

] (9.8)

a) (3 points) using Gentzen system;

b) (3 points) using resolution.

LECTURE 9. SAMPLE EXAMS 208

9.5 Solution

1(a)

We construct a tableau for the negated formula (9.7):

¬[[

(¬p ∨ ¬q) ∧ (p ∨ ¬q) ∧ r]→[¬q ∧ r

]]↓ (¬→)

(¬p ∨ ¬q) ∧ (p ∨ ¬q) ∧ r,¬[¬q ∧ r

]↓ (∧)

(¬p ∨ ¬q), (p ∨ ¬q) ∧ r,¬[¬q ∧ r

]↓ (∧)

(¬p ∨ ¬q), (p ∨ ¬q), r,¬[¬q ∧ r

]↙ ↘ (¬∧)

(¬p ∨ ¬q), (p ∨ ¬q), r,¬¬q (¬p ∨ ¬q), (p ∨ ¬q), r,¬r︸ ︷︷ ︸closed

↓ (¬¬)(¬p ∨ ¬q), (p ∨ ¬q), r, q

↓ ↘ (∨)¬p, (p ∨ ¬q), r, q ¬q, (p ∨ ¬q), r, q︸ ︷︷ ︸

closed↙ ↘ (∨)

¬p, p, r, q︸ ︷︷ ︸closed

¬p,¬q, r, q︸ ︷︷ ︸closed

The tableau is closed, so formula (9.7) is a tautology.

LECTURE 9. SAMPLE EXAMS 209

1(b)

We first negate formula (9.7):

¬{[(¬p ∨ ¬q) ∧ (p ∨ ¬q) ∧ r

]→[¬q ∧ r

]} ↔

(¬p ∨ ¬q) ∧ (p ∨ ¬q) ∧ r ∧ ¬[¬q ∧ r

]↔

(¬p ∨ ¬q) ∧ (p ∨ ¬q) ∧ r ∧ (q ∨ ¬r). (9.9)

Clausal form of (9.9):

1. ¬p ∨ ¬q2. p ∨ ¬q3. r4. q ∨ ¬r.

A possible proof by resolution:

5. q – (res): 3, 46. p – (res): 2, 57. ¬p – (res): 1, 58. ∅ – (res): 6, 7.

LECTURE 9. SAMPLE EXAMS 210

2(a)

∅ ⇒ ∀x[P (x, x, x)

]∧ ¬∃x∃y∃z

[P (x, y, z) ∧ ¬P (z, x, a)

](→r) → ∃z

[P (a, z, a)

]∀x[P (x, x, x)

]∧ ¬∃x∃y∃z

[P (x, y, z) ∧ ¬P (z, x, a)

]⇒

(∧l) ∃z[P (a, z, a)

]∀x[P (x, x, x)

],¬∃x∃y∃z

[P (x, y, z) ∧ ¬P (z, x, a)

]⇒

(¬l) ∃z[P (a, z, a)

]∀x[P (x, x, x)

]⇒

(∀x l) ∃z[P (a, z, a)

],∃x∃y∃z

[P (x, y, z) ∧ ¬P (z, x, a)

]P (a, a, a)⇒

(∃z r) ∃z[P (a, z, a)

],∃x∃y∃z

[P (x, y, z) ∧ ¬P (z, x, a)

]P (a, a, a)⇒ P (a, a, a),∃x∃y∃z

[P (x, y, z) ∧ ¬P (z, x, a)

]︸ ︷︷ ︸axiom

LECTURE 9. SAMPLE EXAMS 211

2(b)

We first negate the formula:

¬{∀x[P (x, x, x)

]∧¬∃x∃y∃z

[P (x, y, z)∧¬P (z, x, a)

]→

∃z[P (a, z, a)

]} ↔

∀x[P (x, x, x)

]∧ ¬∃x∃y∃z

[P (x, y, z) ∧ ¬P (z, x, a)

]∧

¬∃z[P (a, z, a)

]↔

∀x[P (x, x, x)

]∧ ∀x∀y∀z

[¬P (x, y, z) ∨ P (z, x, a)

]∧

∀z[¬P (a, z, a)

].

Clausal form (after renaming variables):

1. P (x1, x1, x1)2. ¬P (x2, y2, z2) ∨ P (z2, x2, a)3. ¬P (a, z3, a)

A proof by resolution:

4. ∅ – (res): 1, 3 with x1 = z3 = a.

LECTURE 9. SAMPLE EXAMS 212

9.6 Exercise (exam 2)

1. (4 points) Translate the following sentences intoa set of propositional formulas:

“chose one of three roads: short, mediumor long”

“the short road is always crowded”“the medium road is not comfortable,

but fast”“the long road is comfortable”“the chosen road should be comfortable.”

2. (2 points) Assuming that fast roads are not crowdedand crowded roads are not comfortable, hypothe-size what roads can be chosen explain your reason-ing informally.

3. (4 points) Prove your claim formally using a proofsystem of your choice (tableaux, or resolution.Please do not use truth table method, as this willgive no points).

LECTURE 9. SAMPLE EXAMS 213

9.6 Solution

1

A possible translation:

short ∨medium ∨ longshort→ crowdedmedium→ (¬comfortable ∧ fast)long → comfortablecomfortable.

(9.10)

2

The chosen road should be comfortable. Therefore it can-not be medium since medium roads are not comfortable.

The chosen road cannot be short since short roads arecrowded and crowded roads are not comfortable.

Therefore the only road that can be chosen if the longone.

3

To prove our hypothesis, we also need the translation ofassumptions provided in point 2 of Exercise:

fast→ ¬crowdedcrowded→ ¬comfortable

(9.11)

LECTURE 9. SAMPLE EXAMS 214

We use resolution. We first transform (9.10) and (9.11)into a set of clauses:

1. short ∨medium ∨ long2. ¬short ∨ crowded3. ¬medium ∨ ¬comfortable4. ¬medium ∨ fast5. ¬long ∨ comfortable6. comfortable7. ¬fast ∨ ¬crowded8. ¬crowded ∨ ¬comfortable.

Now we negate formula

[1. ∧ 2. ∧ 3. ∧ 4. ∧ 5. ∧ 6. ∧ 7. ∧ 8.]→ long

and obtain:

[1. ∧ 2. ∧ 3. ∧ 4. ∧ 5. ∧ 6. ∧ 7. ∧ 8.] ∧ ¬long.

Therefore, we consider clauses 1. – 8. together with

9. ¬long.

A possible proof by resolution:

10. short ∨medium – (res): 1, 911. crowded ∨medium – (res): 2, 1012. ¬medium – (res): 3, 613. crowded – (res): 11, 1214. ¬comfortable – (res): 8, 1315. ∅ – (res): 6, 14.

LECTURE 9. SAMPLE EXAMS 215

9.7 Exercise (exam 2)

Consider a relation R and properties:

(a) ∀x∀y∀z[(R(x, y) ∧R(x, z))→ R(y, z)](b) ∀x∀y

[R(x, y)→ ∃u[R(u, x) ∧R(u, y)]

](c) ∀x∀y[R(x, y)→ R(y, x)].

1. (4 points) Check informally whether the conjunc-tion of (a) and (b) implies (c).

2. (6 points) Verify your informal reasoning using res-olution.

LECTURE 9. SAMPLE EXAMS 216

9.7 Solution

1

To check whether (c) holds assume that for arbitrarilychosen elements s and t we have that R(s, t) holds. Toprove (c), we have to show that given assumptions (a)and (b), R(t, s) holds, too.

1. First, using (b), we observe that R(s, t) implies thatthere exists u such that R(u, s) and R(u, t) hold.

2. Second, using (a) we know that for all x, y and z, wehave that R(x, y) and R(x, z) imply R(y, z). Now,for y = t, z = s and x = u we have that R(u, t) andR(u, s) imply R(t, s).

3. From the first point we have that R(u, s) and R(u, t)hold. From the second point we have that these im-ply R(t, s). Therefore we conclude that R(t, s).

That way we have shown that indeed the conjunction of(a) and (b) implies (c).

LECTURE 9. SAMPLE EXAMS 217

2

To apply resolution we negate the implication:((a)∧ (b))→ (c):

¬{∀x∀y∀z[(R(x, y) ∧R(x, z))→ R(y, z)]∧∀x∀y

[R(x, y)→ ∃u[R(u, x) ∧R(u, y)]

]→

∀x∀y[R(x, y)→ R(y, x)]} ↔∀x∀y∀z[(R(x, y) ∧R(x, z))→ R(y, z)]∧∀x∀y

[R(x, y)→ ∃u[R(u, x) ∧R(u, y)]

]∧

¬∀x∀y[R(x, y)→ R(y, x)]↔∀x∀y∀z[(R(x, y) ∧R(x, z))→ R(y, z)]∧∀x∀y

[R(x, y)→ ∃u[R(u, x) ∧R(u, y)]

]∧

∃x∃y[R(x, y) ∧ ¬R(y, x)].

We deal with the following conjuncts:

∀x∀y∀z[(R(x, y) ∧R(x, z))→ R(y, z)] (9.12)

∀x∀y[R(x, y)→ ∃u[R(u, x) ∧R(u, y)]

](9.13)

∃x∃y[R(x, y) ∧ ¬R(y, x)]. (9.14)

We first Skolemize (9.13) and (9.14):

∀x∀y[R(x, y)→

(R(f(x, y), x) ∧R(f(x, y), y)

)](9.15)

R(s, t) ∧ ¬R(t, s), (9.16)

where s, t are constants.

LECTURE 9. SAMPLE EXAMS 218

Formulas (9.12), (9.15) and (9.16) are transformed intothe following clauses (where variables are renamed):

1. ¬R(x1, y1) ∨ ¬R(x1, z1) ∨R(y1, z1)2. ¬R(x2, y2) ∨R(f(x2, y2), x2)3. ¬R(x3, y3) ∨R(f(x3, y3), y3)4. R(s, t)5. ¬R(t, s).

A proof by resolution:

6. R(f(s, t), s) – (res): 2, 4 with x2 = s, y2 = t7. R(f(s, t), t)– (res): 3, 4 with x3 = s, y3 = t8. ¬R(f(s, t), z8) ∨R(t, z8)

– (res): 1, 7 with x1 = f(s, t), y1 = tand renaming z1/z8

9. R(t, s) – (res): 6, 8 with z8 = s10. ∅ – (res): 5, 9.

LECTURE 9. SAMPLE EXAMS 219

9.8 Exercise (exam 2)

1. (2 points) Design a Datalog database for storinginformation about scientific papers, containing,among others, title, authors and information aboutdirect references between papers (i.e., for each pa-per, information about papers listed in its bibliog-raphy section).

By p q we denote that paper q is among refer-ences listed in paper p.

We define that paper q is indirectly referenced bypaper p (and denote this by p� q) if there is k ≥ 1and papers p1, p2, . . . , pk such that

p p1 p2 . . . pk−1 pk q.

2. (1 point) Provide a sample integrity constraint con-cerning .

3. (1 point) Provide a sample integrity constraint con-cerning �.

4. Formulate in logic queries selecting:

a) (2 points) all pairs p1, p2 of papers both(co-)authored by ‘J.Smith’ such that p1 p2

b) (4 points) all pairs p1, p2 of papers both(co-)authored by ‘J.Smith’ such that p1 � p2.

LECTURE 9. SAMPLE EXAMS 220

9.8 Solution

1

The database contains relations:

• paper(id, title), where id is a (unique) identifier fora paper, and title ∈ String is its title;

• author(id, name), where id is a paper identifier andname ∈ String is a name of its (co-)author;

• refers to(id1, id2), where id1, id2 are paper iden-tifiers.

Example:

paper(11, ‘Logic in Databases’) – paper enti-tled Logic in Databases has id = 11;

paper(22, ‘Fixpoint Logics’) – paper entitledFixpoint Logics has id = 22;

author(11, ‘J.Smith’) – J.Smith (co-)autho-red paper 11;

author(11, ‘M.Jones’) – M.Jones (co-)autho-red paper 11;

refers to(11, 22) – paper 11 refers to paper22.

LECTURE 9. SAMPLE EXAMS 221

2

The relation of road intersection is irreflexive:

∀x[¬refers to(x, x)].

3

Relation � is transitive:

∀x∀y∀z[(x� y ∧ y � z

)→ x� z].

4(a)

Select all pairs p1, p2 of papers both (co-)authored by‘J.Smith’ such that p1 p2 (recall that ‘ ’ is an anony-mous “don’t care” variable):

answer(Id1, Id2) :− paper(Id1, ), paper(Id2, ),author(Id1, ‘J.Smith’),author(Id2, ‘J.Smith’),refers to(Id1, Id2).

Now answer(X, Y ) provides all required pairs of papers.

Note that the above query can be simplified to:

answer(Id1, Id2) :− author(Id1, ‘J.Smith’),author(Id2, ‘J.Smith’),refers to(Id1, Id2).

LECTURE 9. SAMPLE EXAMS 222

4(b)

Select all pairs p1, p2 of papers both (co-)authored by‘J.Smith’ such that p1 � p2.

We need to define the relation p1 � p2 (we give it thename indirectly ref):

indirectly ref(Id1, Id2) :− refers to(Id1, Id),refers to(Id, Id 2).

indirectly ref(Id1, Id2) :− refers to(Id1, Id),indirectly ref(Id, Id2).

Now we can formulate the required query:

answer(Id1, Id2) :− paper(Id1, ), paper(Id2, ),author(Id1, ‘J.Smith’),author(Id2, ‘J.Smith’),indirectly ref(Id1, Id2).

As before, the above query can be simplified to:

answer(Id1, Id2) :− author(Id1, ‘J.Smith’),author(Id2, ‘J.Smith’),indirectly ref(Id1, Id2).

LECTURE 9. SAMPLE EXAMS 223

9.9 Exercise (exam 3)

1. Prove the following propositional formula:[(¬P ∧ ¬Q) ∨ (P ∧ ¬Q) ∨R

]→[¬Q ∨R

]a) (2 points) using tableaux;

b) (2 points) using Gentzen system.

2. Prove the following formula of predicate logic, wherea is a constant:

∀x[P (x, x, x)

]∧

¬∃x∃y∃z[P (x, y, z) ∧ ¬P (f(x), y, g(z))

]→

∃z[P (f(a), z, g(a))

]a) (3 points) using Gentzen system;

b) (3 points) using resolution.

LECTURE 9. SAMPLE EXAMS 224

9.10 Exercise (exam 3)

1. (4 points) Translate the following sentences intoa set of propositional formulas:

“objects are light, medium or heavy”“one can pack light objects to the first

truck, medium objects to the sec-ond truck and heavy objects tothe third truck”

“light objects are green”“medium objects are blue”“heavy objects are red”“pack objects to the second or to the

third truck”“do not pack red objects”.

2. (2 points) Assuming that each object can be packedto at most one truck, hypothesize what choice asto object’s weight can be made and explain yourreasoning informally.

3. (4 points) Prove your claim formally using a proofsystem of your choice (tableaux or resolution. Donot use truth table method, as this will give nopoints).

LECTURE 9. SAMPLE EXAMS 225

9.11 Exercise (exam 3)

Consider a drawing which consists of lines connectingpoints and satisfying the following conditions:

(a) “Every point is connected to a point.”(b) “Connection is symmetric.”(c) “For every points x, y, z, if there is a con-

nection between x and y and betweenx and z then there is also a connectionbetween y and z.”

1. (1.5 points) Express in predicate logic properties(a), (b) and (c).

2. (3.5 points) Check informally whether the conjunc-tion of (a), (b) and (c) implies that “every point isconnected to itself”.

3. (5 points) Verify your informal reasoning using res-olution.

LECTURE 9. SAMPLE EXAMS 226

9.12 Exercise (exam 3)

1. (2 points) Design a Datalog database for storing in-formation about employees (including position andsalary) as well as information about the direct su-pervisor relationship among employees.

We define that employee e′ is an indirect supervisorof employee e′′ if there is k ≥ 1 and employeese1, e2, . . . , ek such that:2

e′ e1 e2 . . . ek−1 ek e′′.

2. (1 point) Express in logic the constraint:

“the relationship of being an indirect su-pervisor is transitive.”

3. (1 point) Provide another integrity constraint con-cerning direct supervisor relationship.

4. Formulate in logic queries selecting:

a) (2 points) all pairs of employees consisting ofexecutive officers with one being a direct su-pervisor of another

b) (4 points) all pairs of employees X, Y suchthat the X is a direct or indirect supervisorof Y and X has a lower salary than Y .

2By e′ e′′ we denote that e′ is a direct supervisor of e′′.