Inference
in
First Order Logic

CS 540-2

Louis Oliphant

oliphant@cs.wisc.edu

Remembering Inference

Entailment – Given some Knowledge what must logically follow

a╞ b

Inference is the mechanism by which you can show what is entailed

a├ib

i – the inference mechanism

We would like Inference mechanisms that are:

Sound

Complete

Methods of Inference in FOL

There are two main methods of inference in FOL:

convert FOL sentences to propositional sentences

Resolution in FOL

Additional methods exist for subsets of FOL

First Order Definite Clauses and Datalog

Forward Chaining and Backward Chaining

Reducing to Propositional Logic

x King(x)  Greedy(x)  Evil(x)

Universal Instantiation – substitute in all possible constants from the knowledge base for the variable

King(John)  Greedy(John)  Evil(John)

King(Richard)  Greedy(Richard)  Evil(Richard)

King(Father(John))  Greedy(Father(John))  Evil(Father(John))

...

Then treat each predicate with its arguments as a
unique symbol in propositional logic.

Reducing to Propositional Logic

x Crown(x)  OnHead(x,John)

Existential Instantiation – substitute in a new constant not in the knowledge base for the variable

Crown(C1)  OnHead(C1,John)

Again, treat each predicate with its arguments as a unique symbol in propositional logic.

Reducing to Propositional Logic

Universal Instantiation – substitute in all possible constants from the knowledge base for the variable

v a

subst({v/g}, a)*

*for any variable v and ground term g.

Existential Instantiation – substitute in a new constant not in the knowledge base for the variable

v a

subst({v/k}, a}*

*For any sentence a,variable v, and constant symbol k that does not appear in the knowledge base

Reducing to Propositional Logic

Using Universal Instantiation and Existential Instantiation you can convert all FOL sentences into a set of Propositional sentences

Then use standard Propositional reasoning methods to decide if a query is true or false.

Reducing to Propositional Logic

Let's Try it. Here are the sentences in the Knowledge base:

x Man(x)  Mortal(x)

Man(Socrates)

And Here is my Query:

Mortal(Socrates)

Oh, and one other point. The Knowledge base contains the function Father(x). What is the set of Propositional sentences?

Problems with converting to Propositional Logic

Universal instantiation creates a huge number of sentences in propositional logic.

Each term in the knowledge base needs to be substituted into sentences in each possible way

How many ways to substitute 3 constants into this predicate?

x,y Pred(x,y)

Universal instantiation may create an infinite number of sentences in propositional logic if there are any functions in the knowledge base

Father(John), Father(Father(John)), ...

Reducing to Propositional Logic

Theorem: Herbrand (1930). If a sentence α is entailed by a FOL KB, it is entailed by a finite subset of the propositionalized KB

Idea: For n = 0 to ∞ do

create a propositional KB by instantiating with depth-$n$ terms

see if α is entailed by this KB

Problem: works if α is entailed, infinitely loops if α is not entailed

Theorem: Turing (1936), Church (1936) Entailment for FOL is semidecidable (algorithms exist that say yes to every entailed sentence, but no algorithm exists that also says no to every nonentailed sentence.)

So let's try reasoning in FOL directly.

Unification

To reason in FOL directly we need to be able to decide if there is some setting for the variables that would make two sentences identical:

x Knows(John,x) -- Knows(John,Jane) –

x Knows(John,x) -- y Knows(y,Father(Jane)) –

x Knows(John,x) -- x Knows(x,Father(Jane)) –

x Knows(John,x) -- y Knows(John,y) –

Unification is the process of generating a substitution (if one exists) that would make two sentences look identical.

We want the Most General Unifier

(MGU is unique up to renaming of variables for any two sentences)

{x/Jane}

{x/Father(Jane), y/John}

????

Standardize Apart: Change the name of variables

so sentences don't have any in common

Unification

To reason in FOL directly we need to be able to decide if there is some setting for the variables that would make two sentences identical:

x Knows(John,x) -- Knows(John,Jane) – {x/Jane}

x Knows(John,x) -- y Knows(y,Father(Jane)) – {x/Father(Jane), y/John}

x Knows(John,x) -- y Knows(y,Father(Jane)) –

x Knows(John,x) -- y Knows(John,y) –

Unification is the process of generating a substitution (if one exists) that would make two sentences look identical.

We want the Most General Unifier

(MGU is unique up to renaming of variables for any two sentences)

{x/Father(Jane), y/John}

{x/Jane, y/Jane} or {y/x} or {x/Father(Jane), y/Father(Jane)}

Unification Algorithm

What if you have to unify(a,F(a))? -- fail

This makes algorithm O(n2)

Resolution: brief summary

Full first-order version:

l1  ···  lk, m1  ···  mn

(l1  ···  li-1  li+1  ···  lk  m1  ···  mj-1  mj+1  ···  mn)θ

where Unify(li, mj) = θ.

The two clauses are assumed to be standardized apart so that they share no variables.

For example,

Rich(x)  Unhappy(x)

Rich(Ken)

Unhappy(Ken)

with θ = {x/Ken}

Use resolution on CNF(KB  α); complete for FOL

So First convert to Conjunctive Normal Form

Conversion to CNF in FOL

Everyone who loves all animals is loved by someone:

x [y Animal(y)  Loves(x,y)]  [y Loves(y,x)]

1. Eliminate biconditionals and implications

x [y Animal(y)  Loves(x,y)]  [y Loves(y,x)]

2. Move  inwards: x p ≡ x p,  x p ≡ x p

x [y (Animal(y)  Loves(x,y))]  [y Loves(y,x)]

x [y Animal(y)  Loves(x,y)]  [y Loves(y,x)]

x [y Animal(y)  Loves(x,y)]  [y Loves(y,x)]

Conversion to CNF contd.

3. Standardize variables: each quantifier should use different one

x [y Animal(y)  Loves(x,y)]  [z Loves(z,x)]

4. Skolemize: general form of existential instantiation.

Each existential variable is replaced by a Skolem function of the enclosing universally quantified variables:

x [Animal(F(x))  Loves(x,F(x))]  Loves(G(x),x)

5. Drop universal quantifiers:

[Animal(F(x))  Loves(x,F(x))]  Loves(G(x),x)

6. Distribute  over  :

[Animal(F(x))  Loves(G(x),x)]  [Loves(x,F(x))  Loves(G(x),x)]

Conversion to CNF contd.

You try – “Anyone who kills all the animals is loved by no one.”

x [y Animal(y)  Kills(x,y)]  [y Loves(y,x)]

1. Eliminate biconditionals and implications
ab ≡ ab  ba	ab ≡ ab

2. Move  inwards:
x p ≡ x p	 x p ≡ x p
(ab) ≡ a  b	(ab) ≡ a  b

3. Standardize variables: each quantifier should use different one

4. Skolemize: general form of existential instantiation.

Each existential variable is replaced by a Skolem function of the

enclosing universally quantified variables

5. Drop universal quantifiers

6. Distribute  over 
(a(bc) ≡ (ab)(ac)

[Animal(G(x))  Loves(y,x)]  [Kills(x,G(x))  Loves(y,x)]

Example Knowledge Base

Everyone who loves all animals is loved by someone.

Anyone who kills an animal is loved by no one.

Jack loves all animals.

Either Jack or Curiosity killed the cat, who is named Tuna.

Did Curiosity kill the cat?

Convert to FOL sentences

Convert to CNF

Use Resolution by Refutation to prove (KB  α) is false

Convert to FOL sentences

x [y Animal(y)  Loves(x,y)]  [y Loves(y,x)]

x [y Animal(y)  Kills(x,y)]  [z Loves(z,x)]

x Animal(x)  Loves(Jack,x)

Kills(Jack,Tuna)  Kills(Curiosity,Tuna)

Cat(Tuna)

x Cat(x)  Animal(x)

Kills(Curiosity,Tuna)

Convert FOL sentences to CNF

Animal(F(x))  Loves(G(x),x)

Loves(x,F(x))  Loves(G(x),x)

Animal(y)  Kills(x,y)  Loves(z,x)

Animal(x)  Loves(Jack,x)

Kills(Jack,Tuna)  Kills(Curiosity,Tuna)

Cat(Tuna)

Cat(x)  Animal(x)

Kills(Curiosity,Tuna)

Remember to write every clause on a seperate line

Resolution by Refutation

Kills(Curiosity,Tuna)

Cat(Tuna)

Cat(x)  Animal(x)

Kills(Jack,Tuna)  Kills(Curiosity,Tuna)

Animal(y)  Kills(x,y)  Loves(z,x)

Loves(x,F(x))  Loves(G(x),x)

Animal(x)  Loves(Jack,x)

Animal(F(x))  Loves(G(x),x)

Resolution by Refutation

Kills(Curiosity,Tuna)

Cat(Tuna)

Cat(x)  Animal(x)

Kills(Jack,Tuna)  Kills(Curiosity,Tuna)

Animal(y)  Kills(x,y)  Loves(z,x)

Loves(x,F(x))  Loves(G(x),x)

Animal(x)  Loves(Jack,x)

Animal(F(x))  Loves(G(x),x)

Resolution by Refutation

Kills(Curiosity,Tuna)

Cat(Tuna)

Cat(x)  Animal(x)

Kills(Jack,Tuna)  Kills(Curiosity,Tuna)

Animal(y)  Kills(x,y)  Loves(z,x)

Loves(x,F(x))  Loves(G(x),x)

Animal(x)  Loves(Jack,x)

Animal(F(x))  Loves(G(x),x)

Animal(Tuna)

Resolution by Refutation

Kills(Curiosity,Tuna)

Cat(Tuna)

Cat(x)  Animal(x)

Kills(Jack,Tuna)  Kills(Curiosity,Tuna)

Animal(y)  Kills(x,y)  Loves(z,x)

Loves(x,F(x))  Loves(G(x),x)

Animal(x)  Loves(Jack,x)

Animal(F(x))  Loves(G(x),x)

Animal(Tuna)

Resolution by Refutation

Kills(Curiosity,Tuna)

Cat(Tuna)

Cat(x)  Animal(x)

Kills(Jack,Tuna)  Kills(Curiosity,Tuna)

Animal(y)  Kills(x,y)  Loves(z,x)

Loves(x,F(x))  Loves(G(x),x)

Animal(x)  Loves(Jack,x)

Animal(F(x))  Loves(G(x),x)

Animal(Tuna)

Kills(Jack,Tuna)

Resolution by Refutation

Kills(Curiosity,Tuna)

Cat(Tuna)

Cat(x)  Animal(x)

Kills(Jack,Tuna)  Kills(Curiosity,Tuna)

Animal(y)  Kills(x,y)  Loves(z,x)

Loves(x,F(x))  Loves(G(x),x)

Animal(x)  Loves(Jack,x)

Animal(F(x))  Loves(G(x),x)

Animal(Tuna)

Kills(Jack,Tuna)

Resolution by Refutation

Kills(Curiosity,Tuna)

Cat(Tuna)

Cat(x)  Animal(x)

Kills(Jack,Tuna)  Kills(Curiosity,Tuna)

Animal(y)  Kills(x,y)  Loves(z,x)

Loves(x,F(x))  Loves(G(x),x)

Animal(x)  Loves(Jack,x)

Animal(F(x))  Loves(G(x),x)

Animal(Tuna)

Kills(Jack,Tuna)

Kills(x,Tuna)  Loves(z,x)

Resolution by Refutation

Kills(Curiosity,Tuna)

Cat(Tuna)

Cat(x)  Animal(x)

Kills(Jack,Tuna)  Kills(Curiosity,Tuna)

Animal(y)  Kills(x,y)  Loves(z,x)

Loves(x,F(x))  Loves(G(x),x)

Animal(x)  Loves(Jack,x)

Animal(F(x))  Loves(G(x),x)

Animal(Tuna)

Kills(Jack,Tuna)

Kills(x,Tuna)  Loves(z,x)

Resolution by Refutation

Kills(Curiosity,Tuna)

Cat(Tuna)

Cat(x)  Animal(x)

Kills(Jack,Tuna)  Kills(Curiosity,Tuna)

Animal(y)  Kills(x,y)  Loves(z,x)

Loves(x,F(x))  Loves(G(x),x)

Animal(x)  Loves(Jack,x)

Animal(F(x))  Loves(G(x),x)

Animal(Tuna)

Kills(Jack,Tuna)

Kills(x,Tuna)  Loves(z,x)

Loves(z,Jack)

Resolution by Refutation

Kills(Curiosity,Tuna)

Cat(Tuna)

Cat(x)  Animal(x)

Kills(Jack,Tuna)  Kills(Curiosity,Tuna)

Animal(y)  Kills(x,y)  Loves(z,x)

Loves(x,F(x))  Loves(G(x),x)

Animal(x)  Loves(Jack,x)

Animal(F(x))  Loves(G(x),x)

Animal(Tuna)

Kills(Jack,Tuna)

Kills(x,Tuna)  Loves(z,x)

Loves(z,Jack)

Resolution by Refutation

Kills(Curiosity,Tuna)

Cat(Tuna)

Cat(x)  Animal(x)

Kills(Jack,Tuna)  Kills(Curiosity,Tuna)

Animal(y)  Kills(x,y)  Loves(z,x)

Loves(x,F(x))  Loves(G(x),x)

Animal(x)  Loves(Jack,x)

Animal(F(x))  Loves(G(x),x)

Animal(Tuna)

Kills(Jack,Tuna)

Kills(x,Tuna)  Loves(z,x)

Loves(z,Jack)

Animal(F(Jack))  Loves(G(Jack),Jack)

Resolution by Refutation

Kills(Curiosity,Tuna)

Cat(Tuna)

Cat(x)  Animal(x)

Kills(Jack,Tuna)  Kills(Curiosity,Tuna)

Animal(y)  Kills(x,y)  Loves(z,x)

Loves(x,F(x))  Loves(G(x),x)

Animal(x)  Loves(Jack,x)

Animal(F(x))  Loves(G(x),x)

Animal(Tuna)

Kills(Jack,Tuna)

Kills(x,Tuna)  Loves(z,x)

Loves(z,Jack)

Animal(F(Jack))  Loves(G(Jack),Jack)

Resolution by Refutation

Kills(Curiosity,Tuna)

Cat(Tuna)

Cat(x)  Animal(x)

Kills(Jack,Tuna)  Kills(Curiosity,Tuna)

Animal(y)  Kills(x,y)  Loves(z,x)

Loves(x,F(x))  Loves(G(x),x)

Animal(x)  Loves(Jack,x)

Animal(F(x))  Loves(G(x),x)

Animal(Tuna)

Kills(Jack,Tuna)

Kills(x,Tuna)  Loves(z,x)

Loves(z,Jack)

Animal(F(Jack))  Loves(G(Jack),Jack)

Loves(G(Jack),Jack)

Resolution by Refutation

Kills(Curiosity,Tuna)

Cat(Tuna)

Cat(x)  Animal(x)

Kills(Jack,Tuna)  Kills(Curiosity,Tuna)

Animal(y)  Kills(x,y)  Loves(z,x)

Loves(x,F(x))  Loves(G(x),x)

Animal(x)  Loves(Jack,x)

Animal(F(x))  Loves(G(x),x)

Animal(Tuna)

Kills(Jack,Tuna)

Kills(x,Tuna)  Loves(z,x)

Loves(z,Jack)

Animal(F(Jack))  Loves(G(Jack),Jack)

Loves(G(Jack),Jack)

Resolution by Refutation

Kills(Curiosity,Tuna)

Cat(Tuna)

Cat(x)  Animal(x)

Kills(Jack,Tuna)  Kills(Curiosity,Tuna)

Animal(Tuna)

Animal(y)  Kills(x,y)  Loves(z,x)

Kills(Jack,Tuna)

Loves(x,F(x))  Loves(G(x),x)

Animal(x)  Loves(Jack,x)

Kills(x,Tuna)  Loves(z,x)

Loves(z,Jack)

Animal(F(x))  Loves(G(x),x)

Animal(F(Jack))  Loves(G(Jack),Jack)

Loves(G(Jack),Jack)

Resolution by Refutation

Resolution is Refutation Complete

If a╞ b then resolution will find a proof in a finite number of steps

Gödel's completeness theorem (1930)

If a╞ b then resolution may never terminate – entailment for FOL is semidecidable

Similar to Turing's Halting Problem

FOL with mathematical induction is incomplete

There are sentences that can not be proven even though a╞ b

Gödel's incompleteness theorem (1931)

Gödel, Escher, Bach
an Eternal Golden Braid

"I realized that to me, Gödel and Escher and Bach were only shadows cast in different directions by some central solid essence. I tried to reconstruct the central object, and came up with this book.” -- Douglas Hofstadter

Induction

Induction (mathematics) – A two-part method of proving a theorem involving an integral parameter. First the theorem is verified for the smallest admissible value of the integer. Then it is proven that if the theorem is true for any value of the integer, it is true for the next greater value. The final proof contains the two parts.

Induction (logic) – The process of deriving general principles from particular facts or instances.

Conclusion

How to Convert FOL to Propositional Logic

Universal Instantiation

Existential Instantiation

Drawbacks of doing this

Reasoning in FOL with resolution

converting to CNF and skolemization

Most General Unifier

substitutions

Next Time – Definite clauses, Back and Forward Chaining

2005-09-15T11:39:48