logic examples and exercises

31
Logic Examples and Exercises Brandon Bennett October 12, 2020 Contents 1 Translating from English into First-Order Logic 3 2 Translation into Logic — Answers 5 3 Questions on First-Order Models 7 4 Automated Reasoning Exercises 8 4.1 Using the Prover9 Theorem Prover ................... 8 4.1.1 Running Prover9 Executables on SoC Linux Machines ..... 8 4.1.2 Prover9’s Proof Method ..................... 8 4.1.3 Simple Examples ......................... 9 4.2 Propositional Logic Examples ...................... 12 4.3 Some Simple Syllogisms ......................... 13 4.3.1 Barbara .............................. 13 4.3.2 Celarent .............................. 13 4.3.3 Ferio ................................ 13 4.3.4 Baroco ............................... 13 4.4 Extended Syllogistic Reasoning ..................... 14 4.5 Invalid and Unsound Syllogisms ..................... 14 4.6 Reasoning with Properties and Individuals ............... 15 4.7 A Murder Mystery Problem ....................... 16 4.8 Ballooning Pigs .............................. 16 4.9 Illegible Letters .............................. 17 4.10 Email Logic Clique ............................ 17 4.11 Qualitative Spatial Reasoning (QSR) .................. 17 4.12 Bovinophobia ............................... 18 4.13 Favourite Colours ............................. 19 4.14 A Geographic Example .......................... 20 4.15 UK Geography Reasoning ........................ 21 1

Upload: others

Post on 07-Dec-2021

21 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Logic Examples and Exercises

Logic Examples and Exercises

Brandon Bennett

October 12, 2020

Contents

1 Translating from English into First-Order Logic 3

2 Translation into Logic — Answers 5

3 Questions on First-Order Models 7

4 Automated Reasoning Exercises 84.1 Using the Prover9 Theorem Prover . . . . . . . . . . . . . . . . . . . 8

4.1.1 Running Prover9 Executables on SoC Linux Machines . . . . . 84.1.2 Prover9’s Proof Method . . . . . . . . . . . . . . . . . . . . . 84.1.3 Simple Examples . . . . . . . . . . . . . . . . . . . . . . . . . 9

4.2 Propositional Logic Examples . . . . . . . . . . . . . . . . . . . . . . 124.3 Some Simple Syllogisms . . . . . . . . . . . . . . . . . . . . . . . . . 13

4.3.1 Barbara . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134.3.2 Celarent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134.3.3 Ferio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134.3.4 Baroco . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

4.4 Extended Syllogistic Reasoning . . . . . . . . . . . . . . . . . . . . . 144.5 Invalid and Unsound Syllogisms . . . . . . . . . . . . . . . . . . . . . 144.6 Reasoning with Properties and Individuals . . . . . . . . . . . . . . . 154.7 A Murder Mystery Problem . . . . . . . . . . . . . . . . . . . . . . . 164.8 Ballooning Pigs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164.9 Illegible Letters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174.10 Email Logic Clique . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174.11 Qualitative Spatial Reasoning (QSR) . . . . . . . . . . . . . . . . . . 174.12 Bovinophobia . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184.13 Favourite Colours . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194.14 A Geographic Example . . . . . . . . . . . . . . . . . . . . . . . . . . 204.15 UK Geography Reasoning . . . . . . . . . . . . . . . . . . . . . . . . 21

1

Page 2: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 2

5 Natural Deduction 225.1 The Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225.2 Derivations of Derived Rules . . . . . . . . . . . . . . . . . . . . . . . 235.3 Natural Deduction Tips and Examples . . . . . . . . . . . . . . . . . 255.4 Natural Deduction Exercises . . . . . . . . . . . . . . . . . . . . . . . 27

5.4.1 Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

6 Theorem Proving with Binary Resolution 306.1 Clausification and Conclusion Negation . . . . . . . . . . . . . . . . . 31

Page 3: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 3

1 Translating from English into First-Order Logic

Batch 1

Formulate the following English sentences as formulae in classical 1st-order logic(answers are given at the end of this document).

1. All purple mushrooms are poisonous.

2. No student likes every lecture.

3. Everest is the highest mountain on Earth.

4. There are at least two apples in a barrel.

5. There are at least two apples in every barrel.

6. x is part of y just in case everything that is connected to x is also connected toy (this is a fundamental definition used in certain theories of spatial relations).

7. No region is part of each of two disjoint regions.

8. Nothing can be inside two different boxes unless one box is inside the other.(Quite hard)

Batch 2

1. Jane ate a mushroom that she had picked herself.

2. No yellow frogs are edible.

3. All students that had missed a lecture answered at least one question incorrectly.

4. Young creatures who go up in balloons are liable to giddiness.

5. Every bag contains at least one coin.

6. The father of a mother or father is a grandfather.

7. Tom’s sister knows Mary’s brother.

8. A careless soldier killed himself.

9. No happy girl despises all animals.

10. Every boy baked at least two cakes.

11. Two regions overlap just in case they share a common part.

12. If three convex regions all overlap each other they share a common part.

13. If a cake is from France then it has more sugar if it is made with chocolate thanwhen it is made with cream but if a cake is from Italy then it has more sugarif it is made with cream than if it is made of chocolate”.

Page 4: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 4

Batch 3

1. Every person loves themself.

2. Everyone loves some person who loves themself.

3. All gardeners like the sun.

4. Some person loves no one except themself.

5. Toby loves everyone who loves him.

6. Love is never requited. (Expand out the meaning of requited.)

7. Brown frogs are bigger than green frogs.

8. No natural food is blue.

9. Mary gave an apple to Tom.

10. One of the apples that Mary gave to Tom is Rotten.

Sentences that are Difficult to Represent

Some sentences whose logical form cannot easily be captured in 1st-order logic:

1. The exam was hard but not very hard.(How should one represent the modifier ‘very’?)

2. You only live twice. (Adverbs are not easily formalised)

3. By this time tomorrow I shall have finished my exams.(Complex temporal expressions hard to formalise.)

Page 5: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 5

2 Translation into Logic — Answers

Here are some possible answers for some, but not all of the translation examples.There will generally be many acceptable translations of any given English sentence.The main reasons for this are the following:

Batch 1

1. ∀x[(Mushroom(x) ∧ Purple(x)) → Poisonous(x)]

2. ¬∃x[Student(x) ∧ ∀y[Lecture(y) → Likes(x, y)]]

3. Mountain(everest) ∧ ¬∃x[Mountain(x) ∧ Higher(x, everest) ∧ On(x, earth)]

4. ∃x∃y∃z[Apple(x) ∧ Apple(y) ∧ ¬(x = y) ∧ Barrel(z) ∧ In(x, z) ∧ In(y, z)]

5. ∀z∃x∃y[Barrel(z) → (Apple(x) ∧ Apple(y) ∧ ¬(x = y) ∧ In(x, z) ∧ In(y, z))]

(Note that the universal quantification over barrels comes before the existentialquantifiers over apples. If we had ∃x∃y∀z[. . .] this would mean that the sametwo apples were present in every barrel.

6. P(x, y) ↔ ∀z[C(z, x) → C(z, y)](In this formula, the connective α ↔ β is logical equivalence and means thesame as (α → β) ∧ (β → α).)

7. ¬∃x∃y∃z[Reg(x) ∧ Reg(y) ∧ Reg(z) ∧ P(x, y) ∧ P(x, z) ∧ Disjoint(y, z)]

8. ∀x∀b1∀b2[(Box(b1) ∧ Box(b2) ∧ ¬(b1 = b2) ∧ In(x, b1) ∧ In(x, b2)) →(In(b1, b2) ∨ In(b2, b1))]

(There are many equivalent alternative formulations; but there are also manysimilar formulae which are incorrect.)

Batch 2

1. Jane ate a mushroom that she had picked herself.∃x[Mushroom(x) ∧ Ate(jane, x) ∧ Picked(jane, x)]

2. No yellow frogs are edible.¬∃x[Frog(x) ∧ Yellow(x) ∧ Edible(x)]

3. All students that had missed a lecture answered at least one question incorrectly.

4. Young creatures who go up in balloons are liable to giddiness.∀x[(Y y ∧ Cx ∧ Bx) → Gx](Illustrates a concise representation for the logical form of the sentence.)

5. Every bag contains at least one coin.∀x[Bag(x) → ∃y[Coin(y) ∧ Contains(x, y)]]

Page 6: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 6

6. The father of a mother or father is a grandfather.This is quite tricky and it is debatable what is the best representation.One possibility is to represent all the family terms using relations:∀x∀y[ ∃z[IsFatherOf(x, z) ∧ (IsMotherOf(z, y) ∨ IsFatherOf(z, y))] ↔

IsGrandfatherOf(x, y)]Also we could treat some of the terms as single-argument properties:∀x∃y[IsFatherOf(x, y) ∧ (Father(y) ∨ Mother(y))] ↔ Grandfather(x)]But then the connection between the Father property and the IsFatherOf relationis not made explicit. We could make this explicit with an additional formula:∀x[Father(x) ↔ ∃y[IsFatherOf(x, y)]](Similar definitions could be given for the Mother and Grandfather properties.)

7. Tom’s sister knows Mary’s brother.∃x∃y[IsSisterOf(x, tom) ∧ IsBrotherOf(y,mary) ∧ Knows(x, y)]

8. A careless soldier killed himself.∃x[Soldier(x) ∧ Careless(x) ∧ Killed(x, x)]

9. No happy girl despises all animals.¬∃x[Happy(x) ∧ Girl(x) ∧ ∀y[Animal(y) → Dispises(x, y)]]

10. Every boy baked at least two cakes.∀x[Boy(x) → ∃y∃z[¬(y = z) ∧ Baked(x, y) ∧ Baked(x, z)]]

11. Two regions overlap just in case they share a common part.∀x∀y[(Reg(x) ∧ Reg(y)) → (Overlap(x, y) ↔ ∃z[Part(z, x) ∧ Part(z, y)])]

12. If three convex regions all overlap each other they share a common part.????

13. If a cake is from France then it has more sugar if it is made with chocolate thanwhen it is made with cream but if a cake is from Italy then it has more sugarif it is made with cream than if it is made of chocolate”.????

Batch 3

1. Every person loves themself.∀x[Person(x) → Loves(x, x)]

2. Everyone loves some person who loves themself.∀x[Person(x) → ∃y[Person(y) ∧ Loves(x, y) ∧ Loves(y, y)]]

3. All gardeners love the sun.∀x[Gardener(x) → Loves(x, sun)](Since ‘sun’ refers to a unique object, it is most straightforwardly representedby a constant (sun).)

4. ...

Page 7: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 7

3 Questions on First-Order Models

1. Consider a fist order language whose vocabulary consists of a single binaryrelation, R, and four models: M1 = 〈D, δ1〉, M2 = 〈D, δ2〉, M3 = 〈D, δ3〉 andM4 = 〈D, δ4〉, which all have the same domain of individuals, D = {a, b, c}).The denotation functions for each of the models are as follows:

M1: δ1(R) = {〈a, a〉, 〈a, b〉, 〈a, c〉, 〈b, a〉, 〈b, b〉, 〈b, c〉, 〈c, a〉, 〈c, b〉, 〈c, c〉}M2: δ2(R) = {〈b, a〉, 〈b, b〉, 〈b, c〉}M3: δ2(R) = {〈a, b〉, 〈b, a〉, 〈c, a〉}M4: δ3(R) = {〈a, a〉}

For each of the following formulae, state which of the modelsM1 –M4 satisfyit, if any:

(a) ∃x[R(x, x)]

(b) ∀x[R(x, x)]

(c) ∀x∀y[R(x, y)]

(d) ∀x∃y[R(x, y)]

(e) ∃x∀y[R(x, y)]

(f) ∃x∃y[R(x, y)]

2. M = 〈D, δ〉 is a model for a first-order language with a unary predicate P and abinary relation T . The domain of M is the set {a, b, c, d}; and the denotationsof P and T are as follows:

• δ(P ) = {a, c}• δ(T ) = {〈a, b〉, 〈b, c〉, 〈c, d〉, 〈d, a〉}

Which of the following formulae are satisfied by this model:

(a) ∃x[T (x, x)]

(b) ∃x∀y[T (x, y)]

(c) ∀x∃y[T (x, y)]

(d) ∀x∀y∀z[(T (x, y) ∧ T (y, z)) → T (x, z)]

(e) ∀x∀y[(P (x) ∧ T (x, y)) → ¬P (y)]

Page 8: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 8

4 Automated Reasoning Exercises

4.1 Using the Prover9 Theorem Prover

A wide variety of automated theorem provers have been developed since their originin the 1960’s. However, this kind of program is difficult to implement and oftendifficult to use. Thus, very few theorem provers have gained many users beyondthe researchers who developed them. One of the more popular was Otter, whichat one time was arguably the most powerful prover around, and was able to verifya number of theorems that mathematicians had hypothesised but not been able toprove. Prover9 is an improved version of the original Otter. Although it is not usuallyregarded as one of the most powerful, it does have the advantage of being relativelysimple compared to most of the more modern provers.Documentation and downloads can be found on the Prover9 home page at:

http://www.cs.unm.edu/~mccune/prover9/

4.1.1 Running Prover9 Executables on SoC Linux Machines

To run Prover9 on the Soc Linux machines, just enter the following command at aterminal prompt:

∼csc5bb/bin/prover9

Or, to use the GUI version (recommended for beginners), use the command:

∼csc5bb/bin/prover9gui

4.1.2 Prover9’s Proof Method

The primary mode of inference used by Prover9 is resolution. It repeatedly makes res-olution inferences with the aim of detecting inconsistency by deriving a contradiction.As discussed in the lecture notes, resolution provides a complete proof procedure fordetecting inconsistency of formulae that are expressed in clausal form.Prover9 will first do some preprocessing on the input file to convert it into the form ituses for inferencing. First it negates the formula given as a goal.1 It then translatesall formulae into clausal form. (In some cases it will do some further pre-processing,but you do not need to worry about this.) Then it will compute inferences and bydefault write these standard output. Unless the input is very simple it will oftengenerate a large number of inferences. If it detects an inconsistency it will stop andprint out a proof consisting of the sequence of resolution rules that generated theinconsistency. It will also print out various statistics associated with the proof.

1Actually Prover9 allows multiple goal formulae, but it is best to use just one, since the semanticsof multiple goals is potentially confusing.

Page 9: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 9

4.1.3 Simple Examples

Here is an example of a very simple Prover9 file:

formulas(assumptions).

p & s. % ‘&’ symbol is for conjunction, ‘and’

p -> q. % ‘->’ symbol is for implication, ‘implies’

q -> -r. % ‘-’ symbol is for negation, ‘not’

end_of_list.

formulas(goals).

-r | t. % ‘|’ symbol is for disjunction ‘or’

end_of_list.

If you are using the GUI version you don’t need the lines declaring the formula listand goal list. You just enter the formulae into the appropriate boxes in the interface.Here is a slightly more complex example using quantifiers (borrowed from the intro-ductory material on the Prover9 web site):

formulas(assumptions).

all x all y (subset(x,y) <-> (all z (member(z,x) -> member(z,y)))).

end_of_list.

formulas(goals).

all x all y all z (subset(x,y) & subset(y,z) -> subset(x,z)).

end_of_list.

Page 10: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 10

A More Complex Example

Here is a much more complex example devised by Len Schubert. It was originallyknown as ‘The Steamroller’ because at the time (in the 80s) it was very difficult forautomated theorem provers to solve (it would flatten them). However, it presents noproblem for a modern theorem prover such as Prover9 running on a modern computer.

% Schubert’s "Steamroller" Problem

%

% Wolves, foxes, birds, caterpillars, and snails are animals,

% and there are some of each of them.

%

% Also there are some grains, and grains are plants.

%

% Every animal either likes to eat all plants or all animals much

% smaller than itself that like to eat some plants.

%

% Caterpillars and snails are much smaller than birds, which are much

% smaller than foxes, which are in turn much smaller than wolves.

%

% Wolves do not like to eat foxes or grains, while birds like to eat

% caterpillars but not snails.

%

% Caterpillars and snails like to eat some plants.

%

% Prove there is an animal that likes to eat a grain-eating animal.

% (where a grain eating animal is one that eats all grains)

formulas(assumptions).

all x (Wolf(x) -> animal(x)).

all x (Fox(x) -> animal(x)).

all x (Bird(x) -> animal(x)).

all x (Caterpillar(x) -> animal(x)).

all x (Snail(x) -> animal(x)).

all x (Grain(x) -> plant(x)).

exists x Wolf(x).

exists x Fox(x).

exists x Bird(x).

exists x Caterpillar(x).

exists x Snail(x).

exists x Grain(x).

Continued Overleaf.

Page 11: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 11

% All animals either eat all plants or eat all smaller animals that eat some plants.

all x (animal(x) -> (all y (plant(y)->eats(x,y)))

|

(all z ( animal(z) &

Smaller(z,x) &

(exists u (plant(u)&eats(z,u)))

->

eats(x,z)))).

all x all y (Caterpillar(x) & Bird(y) -> Smaller(x,y)).

all x all y (Snail(x) & Bird(y) -> Smaller(x,y)).

all x all y (Bird(x) & Fox(y) -> Smaller(x,y)).

all x all y (Fox(x) & Wolf(y) -> Smaller(x,y)).

all x all y (Bird(x) & Caterpillar(y) -> eats(x,y)).

all x (Caterpillar(x) -> (exists y (plant(y) & eats(x,y)))).

all x (Snail(x) -> (exists y (plant(y) & eats(x,y)))).

all x all y (Wolf(x) & Fox(y) -> -eats(x,y)).

all x all y (Wolf(x) & Grain(y) -> -eats(x,y)).

all x all y (Bird(x) & Snail(y) -> -eats(x,y)).

end_of_list.

formulas(goals).

% "there is an animal that eats {an animal that eats all grains}".

exists x exists y ( animal(x) & animal(y) & eats(x,y) &

(all z (Grain(z) -> eats(y,z)))

).

end_of_list.

Page 12: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 12

4.2 Propositional Logic Examples

Enter propositional logic translations of the following arguments into Prover9 (us-ing Prover9’s ASCII representation for the formulae). Then use Prover9’s theoremproving capabilities to show that the arguments are valid:Remember that when translating to propositional logic you often have to simplifyand/or alter the structure of sentences. You need to look for underlying propositions(i.e. statements that are true or false) and recast each sentence in terms of thesepropositions combined by means of the truth-functional operators.

A) 1. The diamond has been stolen!

2. If the diamond has been stolen, a thief got in the house.

3. If a thief got in, either the door was open or the window was smashed.

4. The window is not smashed.

∴ The door was open.

B) 1. If Alan did not lock the door he either forgot or lost the key.

2. If he lost the key he will be in trouble.

3. If he has a good memory he did not forget.

4. Alan has a good memory.

∴ Either Alan locked the door or he will be in trouble.

C) 1. Either the picture is valuable or it is a fake.

2. If it is valuable it is by Rembrandt.

3. If it is a fake there will be a police investigation.

∴ Either the picture is by Rembrandt or there will be a police investigation.

D) 1. Sunday is a Holiday.

2. Saturday and Sunday is the weekend.

3. On holidays the University is closed.

4. It is the weekend.

5. It is not Saturday

∴ The University is closed.

Note that in some contexts we can translate names of days or time periods intopropositions. Thus, sometimes ‘Saturday’ can be translated as a proposition,i.e. as ‘It is Saturday’.

Page 13: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 13

E) 1. If Tarquin learns philosophy then he acquires wisdom and if he learnsscience he will advance human knowledge.

2. If he acquires wisdom, Tarquin will not die in misery.

3. If he advances human knowledge, his aspirations will be satisfied.

4. If Tarquin’s aspirations are not satisfied he will die in misery.

5. Alas, Tarquin’s aspirations will never be satisfied.

∴ Thus, he learns neither philosophy nor science.

4.3 Some Simple Syllogisms

The Syllogisms were probably the first forms of logical inference that were systemati-cally investigated by humans. The Greeks originally studied arguments in the contextof legal disputes and recognised that some (but not all) arguments are based on theform of sentences with which they are expressed. A syllogism is a basic form of argu-ment in which the meanings of two assertions are used to derive a consequence. Morespecifically, the term ‘syllogism’ is usually applied to a class of inferences involvingsentences constructed from two property terms (predicates) linked by quantifiers andpossibly negations.The Medieval logicians continued the study of syllogisms and gave them all namesbased on a coding of the quantifiers and negations into letters. To find out more aboutthe valid syllogisms and the coding used to name them take a look at the Wikipediaarticle http://en.wikipedia.org/wiki/Syllogism.

4.3.1 Barbara

1. All Greeks are men.

2. All men are mortal.

∴ All Greeks are mortal.

4.3.2 Celarent

1. No reptiles have fur.

2. All snakes are reptiles.

∴ No snakes have fur.

4.3.3 Ferio

1. No homework is fun.

2. Some reading is homework.

∴ Some reading is not fun.

4.3.4 Baroco

1. All informative things are useful.

2. Some web sites are not useful.

Page 14: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 14

∴ Some web sites are not informative.

4.4 Extended Syllogistic Reasoning

The basic syllogisms involve exactly two predicates in each sentence. But we can usesimilar reasoning principles when this is not the case.

A) 1. No old rabbits are greedy.

2. All black rabbits are greedy.

∴ No old rabbits are black.

B) 1. Young rabbits are greedy.

2. Greedy animals are fat.

3. Rabbits are animals.

∴ All young rabbits are fat.

4.5 Invalid and Unsound Syllogisms

Here are a couple of Syllogisms that are not valid. Try proving them and see whathappens.

A) 1. Some rhombuses are equilateral.

2. Some equilaterals are triangular.

∴ Some rhombuses are triangular.

B) 1. All polygons are shapes.

2. Some shapes are triangular.

∴ All polygons are triangular.

C) Note that an argument can be logically invalid even if the conclusion is true.The conclusion may happen to be true even though this is not a consequenceof the premisses.

1. Some birds fly.

2. Some flying things eat nuts.

∴ Some birds eat nuts.

D) Conversely an argument can be logically valid even if the conclusion is false.

1. Some fish eat bananas.

2. All banana eaters enjoy backgammon.

∴ Some fish enjoy backgammon.

If an argument is valid but its conclusion is false, then at least one of its pre-misses must be false.An argument with one or more false premisses is called unsound.

Page 15: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 15

4.6 Reasoning with Properties and Individuals

A) 1. Socrates is Greek.

2. All Greeks are men.

3. All men are mortal.

∴ Socrates is mortal.

B) 1. Porky is a pig.

2. Pigs are animals.

3. All pigs are fat.

4. No fat animals run fast.

∴ Porky does not run fast.

C) 1. The Jabberwock has eyes of flame.

2. All creatures with eyes of flame whiffle and burble.

3. All creatures that whiffle or burble have claws.

∴ The Jabberwock has claws.

Page 16: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 16

4.7 A Murder Mystery Problem

Translate the following sentences into 1st-order logic and put them in a file usingProver9 syntax.

1. Someone who lives in Dreadbury Mansion killed Aunt Agatha.

2. Agatha, the butler, and Charles live in Dreadbury Mansion, and are the onlypeople who live therein.

3. A killer always hates his victim, and is never richer than his victim.

4. Charles hates no one that Aunt Agatha hates.

5. Agatha hates everyone except the butler.

6. The butler hates everyone not richer than Aunt Agatha.

7. The butler hates everyone Aunt Agatha hates.

8. No one hates everyone.

9. Agatha is not the butler.

Now use the Prover9 theorem prover to deduce who killed Aunt Agatha.(Hint: try for each of the possibilities.)

4.8 Ballooning Pigs

Enter formulae into Prover9 corresponding to the following sentences:2

1. All, who neither dance on tightropes nor eat penny-buns, are old.

2. Pigs, that are liable to giddiness, are treated with respect.

3. A wise balloonist takes an umbrella with him.

4. No one ought to lunch in public who looks ridiculous and eats penny-buns.

5. Young creatures, who go up in balloons, are liable to giddiness.

6. Fat creatures, who look ridiculous, may lunch in public, provided that they donot dance on tightropes.

7. No wise creatures dance on tightropes, if liable to giddiness.

8. A pig looks ridiculous, carrying an umbrella.

9. All, who do not dance on tightropes, and who are treated with respect are fat.

Use Prover9 to determine that the following conclusion can be inferred:No wise young pigs go up in balloons.

In order to prove this you will have to add two further formula to the assumptions.Each of these additional formula is a general axiom which captures a necessary inter-dependence between two of the concepts that occur in propositions 1-9. One of themis a general fact about pigs and the other is about age.

2This exercise is based on a problem set by Lewis Carroll (Author of Alice in Wonderland) inhis book Symbolic Logic.

Page 17: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 17

4.9 Illegible Letters

Encode and prove the following argument. You may assume that the domain ofdiscourse consists of all the letters in the room.

1. All the dated letters in this room are written on blue paper.

2. None of them are in black ink except those that are written in the third person.

3. I have not filed any of them that I can read.

4. None of them that are written on one sheet are undated.

5. All of them that are not crossed are in black ink.

6. All of them written by Brown begin with “Dear Sir”.

7. All of them written on blue paper are filed.

8. None of them written on more than one sheet are crossed.

9. None of them that begin with “Dear Sir” are written in third person.

∴ The letters written by Brown cannot be read.

4.10 Email Logic Clique

Anna, Barry, Charles and Deborah are logic students. Each logic studentwho has received an email has sent an email to every logic student. Everyemail that was sent was received (by the correct recipient). Anna has sentan email to Barry.

Encode the preceeding statements in first-order logic and use an automated theoremprover to prove that:

Charles has received an email from Deborah.

4.11 Qualitative Spatial Reasoning (QSR)

In Qualitative Spatial Reasoning the spatial part relation is defined in terms of theconnection relation as follows:

∀x∀y[P(x, y) ↔ ∀z[C(z, x) → C(z, y)]] .

Use a theorem prover to demonstrate that the part relation is transitive.

Page 18: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 18

4.12 Bovinophobia

a) Encode the following argument in Prover9 syntax:

1. Cows are animals that eat grass.

2. I don’t eat grass.

3. Apart from me, the only animals in my house are feline.

4. No animals ever take to me, except those in my house.

5. I detest animals that do not take to me.

6. When I detest an animal, I avoid it.

7. Every animal that loves to gaze at the moon is suitable for a pet.

8. No animals are carnivorous, unless they prowl at night.

9. Every feline eats some animal smaller than itself.

10. I am not the smallest animal in my house.

11. Only carnivores eat animals.

12. Cows are not suitable for pets.

13. Animals that prowl at night always love to gaze at the moon.

14. ∴ I avoid cows.

b) Use a theorem prover to show that proposition 14 is a logical consequence ofthe other propositions.

c) Which premiss is redundant to the proof? (Hints: Take a look through theprover’s output file. Test your answer by commenting out this proposition.)

d) Give a formula stating a property of cows, which when added to propositions1–6 entails proposition 14, without the need for propositions 7–13. Test youranswer.

Page 19: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 19

4.13 Favourite Colours

a) Translate the following sentences into an appropriate encoding for the first-orderlogic theorem prover that you are using:

1. There are three children called Alfred, Betty and Charles.(Hint: you must explicitly ensure that different names refer to distinctindividuals).

2. Every child is wearing either a hat, coat or a scarf.

3. Alfred is wearing a red hat.

4. Betty is wearing a green coat.

5. Charles is wearing a blue scarf.

6. Each child has a different favourite colour, which is either red, green, orblue.

7. No child is wearing anything that has their favourite colour.

8. Betty’s favourite colour is red.

b) Use the theorem prover to determine what are the favourite colours of Alfredand Charles.

c) Which proposition is redundant to the proof?

d) By examining the theorem prover’s output, give relevant information that forcomparing the behaviour of the prover (e.g. run-time, inferences generated etc.)when generating a proof, with and without the redundant proposition.

Page 20: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 20

4.14 A Geographic Example

Exercise Specification

In this exercise you will analyse a set of natural language sentences expressing avariety of forms of geographic information and translate the core meaning into first-order logic.You will then look at a further set of sentences, which intuitively follow as conse-quences of the first set. Your aim will be to demonstrate that given a suitable logicalrepresentation of the sentences, together with additional axioms specifying intercon-nections between the concepts that are involved, each of these consequences can beproved using a first-order logic theorem prover (i.e. Prover9 ).

Step 1

Translate the following sentences into first-order logic and enter their representationsinto Prover9 (in the assumptions box).Given information:

1. Leeds is a city located in Yorkshire.

2. Sheffield is a city located in Yorkshire.

3. Lancaster is a city located in Lancashire.

4. Lancaster has a port.

5. Leeds is the largest city in Yorkshire.

6. Yorkshire is a county of the United Kingdom.

7. Lancashire is a county of the United Kingdom.

8. Yorkshire borders Lancashire.

Step 2

Think about why the following formulae are consequences of the ones you have justanalysed. Then translate them into first-order logic and enter their representationsinto Prover9 but enter them into the goals box of the interface.Consequences:

1. Sheffield is smaller than Leeds.

2. Leeds is located in the United Kingdom.

3. Leeds is not located in Lancashire.

4. Yorkshire is an administrative region.

5. Lancashire borders the sea.

Page 21: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 21

Step 3

Try to identify axioms capturing logical relationships between the concepts in thepreviously given sentences that are necessary to derive the consequences from thegiven information.Enter your axioms into the assumptions box. But keep them separate from thegiven information. For clarity, I advise that you use comments to give an informaldescription of each of your axioms. Comments can be given on lines starting withthe‘%’ character.

Step 4

Try to prove each of the consequences from the combination of the initial informationand your additional axioms.To do this you should comment out all the goals apart from the one you wish toprove. Then press the ‘Start’ button to run Prover9. It should then tell you whetherthe goal follows from your formalisation of the initial information and axioms.Use comments to make a note of which goals have been proved.You don’t need to worry about the form of the actual proofs as for the purpose ofthis exercise we are treating the theorem prover as a ‘black box’.

4.15 UK Geography Reasoning

UK.1) The United Kingdom is an island country, spanning an archipelago includingGreat Britain, the northeastern part of the island of Ireland, and many smallislands.

UK.2) Northern Ireland is the only part of the UK with a land border, sharing it withthe Republic of Ireland.

UK.3) Apart from this land border, the UK is surrounded by the Atlantic Ocean, theNorth Sea, the English Channel and the Irish Sea.

Consequences.

The following propositions are either direct or indirect consequences of the abovepropositions about the United Kingdom:

UK-C.1) Great Britain is part of the United Kingdom.

UK-C.2) Great Britain consists of at least two islands.

UK-C.3) Great Britain is externally connected to an ocean.

UK-C.4) The United Kingdom is connected to the Republic of Ireland.

Page 22: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 22

5 Natural Deduction

This section begins with a concise summary of the rules of a Natural Deductionproof system for propositional logic. Following that, I shall give a number of tips onhow to construct proofs along with some examples. At the end of the section is theactual exercise, which is a list of sequents that you should try to prove using NaturalDeduction.

5.1 The Rules

Basic Rule Set

P Q

P ∧ Q∧I

P ∧ Q

P∧Er

P ∧ Q

Q∧El

P

P ∨ Q∨Ir

Q

P ∨ Q∨Il

A ∨ B

[ A ]na....P

[ B ]nb....P

P∨En

[ A ]n....

P ∧ ¬P

¬A¬In

[ ¬A ]n....

P ∧ ¬P

A¬En

Rules for → (can be derived via the definition of → )

[ P ]n....Q

P → Q→In

P P → Q

Q→E

Page 23: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 23

Rules for ⊥ (optional — will make some proofs shorter)

P ¬P

⊥⊥I

P⊥E

[ A ]n....⊥

¬A¬In

[ ¬A ]n....⊥

A¬En

Useful Derived Rules (derivable from the basic rule set)

P ∧ ¬P

AEFSQ

P ∨ ¬PEM

¬¬P

PDNE

5.2 Derivations of Derived Rules

The following rules are quite fundamental, but can actually be derived using the basicintroduction and elimination rules. Here are the proofs:

Ex falso sequitur quadlibet (EFSQ)

From falisty (i.e. contradiction) follows everything.

P ∧ ¬P [ ¬A ]n

(P ∧ ¬P ) ∧ ¬A∧I

P ∧ ¬P∧Er

A¬En

=⇒P ∧ ¬P

AEFSQ

Law of Excluded Middle (EM)

[ P ]1

P ∨ ¬P∨Ir

[ ¬(P ∨ ¬P ) ]2

(P ∨ ¬P ) ∧ ¬(P ∨ ¬P )∧I

¬P¬I1

P ∨ ¬P∨Il

[ ¬(P ∨ ¬P ) ]2

(P ∨ ¬P ) ∧ ¬(P ∨ ¬P )∧I

P ∨ ¬P¬E2

=⇒P ∨ ¬P

EM

Page 24: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 24

Double Negation Elimination (DNE)

[ ¬P ]1 ¬¬P

P ∧ ¬P∧I

P¬E1

=⇒¬¬P

PDNE

Modus Ponens (MP) — using equivalent ¬A ∨ B in place ofA → B

¬A ∨ B

A [ ¬A ]1

A ∧ ¬A∧I

BEFSL

[ B ]2

B∨E1,2

=⇒A ¬A ∨ B

BMP

Conditional Proof (CP)

P ∨ ¬PEM

[ P ]1....Q

¬P ∨ Q∨Il

[ ¬P ]2

¬P ∨ Q∨Ir

¬P ∨ Q∨E1,2

=⇒

[ P ]n....Q

¬P ∨ QCPn

Page 25: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 25

5.3 Natural Deduction Tips and Examples

When and What to Assume

One aspect of Natural Deduction proofs that you need to get the hang of is when andwhat to assume. There are actually four different reasons why an assumption maybe made. Each of these is described and illustrated in this document.

Case 1. Assume the premissesYou should always assume all the formulae that are given as premisses (i.e. on theleft hand side) of the sequent you wish to prove.

For example, to proveP, P → Q, Q → R ` R

you should assume P , P → Q and Q → R, then try to derive R:

P P → Q

Q→E

Q → R

R→E

Case 2. If you have a premiss P ∨ Q, assume P then assume QIf you have a disjunctive premiss, you can often prove the conclusion by successivelyassuming each disjunct and trying to prove the conclusion from each. Then you canconclude the proof by using the ∨E rule.

For example:A, B ∨ C, ` (A ∧ B) ∨ (A ∧ C)

B ∨ C

A [ B ]1a

A ∧ B∧I

(A ∧ B) ∨ (A ∧ C)∨Ir

A [ C ]1b

A ∧ C∧I

(A ∧ B) ∨ (A ∧ C)∨Il

(A ∧ B) ∨ (A ∧ C)∨E1

(Note that the assumption A occurs twice. Proofs often contain duplicates of theassumptions. This just means that the assumption takes part in more than one ruleapplication.)

Page 26: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 26

Case 3. To Prove P → Q assume PIf the conclusion you want to prove is of the form P → Q, you should assume P(along with any premisses) and try to prove Q. You can then use the rule →E todischarge the assumption P and derive Q.For example, to prove

A → B, B → C ` A → C

assume A (as well as the premisses A → B and B → C). Then prove C; and finallyprove A → C by →E:

[ A ]1 A → B

B→E

B → C

C→E

A → C→I1

Case 4. Assume the opposite of what you want to proveA final tactic that you may need to use is to assume the negation of the conclusions youwant to prove. The idea is to then derive a contradiction to show that the assumptionmust be false. One can then use either ¬E or ¬I to derive a conclusion that eitherremoves or adds a negation to the formula that was assumed. The assumption itselfis then discharged.This mode of proof using ¬I is typically where the formula to be proved is negated:

¬(P ∨ Q) ` ¬P

[ P ]1

P ∨ Q∨Ir

¬(P ∨ Q)

(P ∨ Q) ∧ ¬(P ∨ Q)∧I

¬P¬I1

But a similar form of proof using ¬E can be employed to prove an un-negated con-clusion:

¬¬P ` P

[ ¬P ]1 ¬¬P

¬P ∧ ¬¬P∧I

P¬E1

Page 27: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 27

5.4 Natural Deduction Exercises

Construct Natural Deduction proofs of each of the following sequence, using any ofthe rules in the Basic Rule Set and the Rules for → (as specified in Section 5.1above). All the given sequents are valid and therefore provable (since this rule set iscomplete for propositional logic reasoning).Answers to cases a–f are given below.

a) P ∧ Q ` P ∧ (Q ∨ R)

b) P → Q, ¬Q ` ¬P

c) P → Q ` ¬Q → ¬P

d) P ∨ Q, P → R, Q → R ` R

e) P → (¬Q ∨ R), P, Q ` R

f) P ∧ (Q ∨ R) ` (P ∧ Q) ∨ R

g) P ` ¬¬P

h) P ∨ Q, P → R, Q → R ` R

i) P ` Q → P

j) ` (P ∨ Q) → (Q ∨ P )

k) ` P → (P ∨ Q)

l) ¬(P ∨ Q) ` ¬P

m) ¬(P ∨ Q) ` ¬P ∧ ¬Q

n) P ∧ Q ` ¬(¬P ∨ ¬Q)

o) P → Q ` ¬Q → ¬P

p) (P ∧ Q) ∨ (P ∧ R) ` P ∧ (Q ∨ R)

q) ¬R, (P ∨ Q) → R ` ¬P

r) P ∨ (Q ∨ R) ` (P ∨ Q) ∨ R

Page 28: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 28

5.4.1 Answers

a)

P ∧ Q

P∧Er

P ∧ Q

Q∧El

Q ∨ R∨Ir

P ∧ (Q ∨ R)∧I

b) [ P ]1 P → Q

Q→E

¬Q

Q ∧ ¬Q∧I

¬P¬I1

c) [ P ]1 P → Q

Q→E

[ ¬Q ]2

Q ∧ ¬Q∧I

¬P¬I1

¬Q → ¬P→I2

d)

P ∨ Q

[ P ]1a P → R

R→E

[ Q ]1b Q → R

R→E

R∨E1

e)

P P → (¬Q ∨ R)

¬Q ∨ R→E

Q

[ ¬Q ]2a [ ¬R ]1

¬Q ∧ ¬R∧I

¬Q∧Er

Q ∧ ¬Q∧I

R¬E1

[ R ]2b

R∨E2

Page 29: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 29

f)

P ∧ (Q ∨ R)

Q ∨ R∧El

P ∧ (Q ∨ R)

P∧Er

[ Q ]1a

P ∧ Q∧I

(P ∧ Q) ∨ R∨Ir

[ R ]1b

(P ∧ Q) ∨ R∨Il

(P ∧ Q) ∨ R∨E1

Page 30: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 30

6 Theorem Proving with Binary Resolution

By default, Prover9 carries out a wide variety of different kinds of inference. Most ofthese are varieties of inference, but they may combine several resolution steps together(e.g. Hyper-resoluton) or they only operate in restricted cases (for instance when theresult of the inference is particularly simple).3 Often a combination of these muti-step and restricted application rules can perform better than using the basic binaryresolution rule. However, depending on which rules are chosen, the resulting systemmay or may not provde a complete inference system.To see how the simple binary resolution rule works, it is easiest if we run Prover9from the command line rather than using the GUI. That way we have full controlover the input file that the prover will use and can directly specify which rules wewant it to do.As a first example, put the following into a text file (let us call the file binres test.p9):

set(raw). %% Clear all default rules

set(binary_resolution). %% Add binary resolution rule

set(factor). %% Add factoring rule

formulas(assumptions).

A | B.

-A | -C | D.

A | D.

-A | C.

-B | C.

-C | -D.

end_of_list.

The first line removes all the default inference rules and the following two add binaryresolution and factoring rules. (For propositional reasoning we do not actually needto set the factoring fule, because Prover9 always merges identical literals within eachnew formula that it infers; but it is needed to get a complete inference system forfirst-order logic (i.e. if we have formula with quantifiers.)Now from the command prompt (in the same directory as the input file) enter:4

/usr/local/prover9/bin/prover9 < restest.p9

Now look at the output. You can skip past the initial processing and search sections.The actual proof should be near the end of the file. Here you see that a series ofresolution steps has been applied, resulting in a final cancellation of a literal with itsnegation. This results in the so-called ‘empty clause’, which in Prover9 is denoted by$F. This shows that the assumptions are inconsistent.

3An example of this is so-called unit resulting (UR) resolution, which is only used when theinfered formula consists of a single literal.

4You may want to redirect the output to a file by adding > output file at the end of thecommand.

Page 31: Logic Examples and Exercises

Brandon Bennett, Logic Examples and Exercises 31

6.1 Clausification and Conclusion Negation

In the previous example, we gave Prover9 a set of formulae all in clausal form formand with no conclusion that we wanted to prove. In this case the system simplyapplies binary resolution repeatedly. This gives us a complete test for consistency ofthe assumptions: the empty clause will be derived if and only if the empty clause $F

can be derived.In the following example the input is not quite so simple. For one thing, the as-sumptions are given in terms of arbitrary propositional formulae, not clauses. Thismeans that, before using resolution, Prover9 must convert the formulae into clausalform. For another thing, we have a ‘goal’, i.e. a conclusion we want to prove. Sinceresolution detects inconsistency, we add the negation of the goal to the assumptions.If the negation of the goal is logically inconsistent with the other assumptions thenthe goal must be a logical consequence of the premisses.Run Prover9 on the following example file (in the same way as for the previousexample):

set(raw). %% Clear all default rules

set(binary_resolution). %% Add binary resolution rule

set(factor). %% Add factoring rule

formulas(assumptions).

p & s. % ‘&’ symbol is for conjunction ‘and’

p -> q. % ‘->’ symbol is for implication ‘implies’

q -> r.

end_of_list.

formulas(goals).

r | t. % ‘|’ symbol is for disjunction ‘or’

end_of_list.

If you look through the output, you will see how Prover9 first converts the input into aset of clauses by adding the the negation of the goal to the assumption and convertingall formulae to clausal form. It then proceeds to compute resolution inferences in orderto construct a proof. The proof consists of all the assumptions that are required forthe proof together with all inferred formulae that contribute to the chain of inferenceleading to the derivation of $F.