44
1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

Embed Size (px)

Citation preview

Page 1: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

1

First Order Logic

CS 171/271(Chapters 8 and 9)

Some text and images in these slides were drawn fromRussel & Norvig’s published material

Page 2: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

2

Propositional Logic Limitations Stating similar facts is cumbersome

Can’t make generalizations The world (in propositional logic)

contains facts, not objects Natural language deals with objects

(nouns) and relations (verbs), hence is more expressive

Ontological commitment of PL is limited

Page 3: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

3

First Order Logic World consists of

Objects Relations Functions

Sentences are made up of Symbols: for constant objects, predicates,

and functions Connectives: as in PL Quantifiers and variables: x, y

Page 4: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

4

FOL Syntax Sentence

Atomic Sentence ( Sentence Connective Sentence ) Sentence Quantifier Variable Sentence

Atomic Sentence Predicate-Symbol( Term, … ) Term = Term

Page 5: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

5

FOL Syntax Term (refers to an object)

Function-Symbol( Term, … ) Constant-Symbol Variable

Connective: , , , , Quantifier: , Variable: x, y, z, …

Page 6: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

6

Example

Page 7: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

7

Symbols Constants: John, Richard, C, L1, L2 Predicates:

Person={John, Richard} King={Richard} Crown={C} Brother={(John,Richard),(Richard,John)} OnHead={(C,Richard)}

Functions: LeftLeg={(Richard->L1),(John->L2)}

(strictly speaking, the function should be total)

Page 8: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

8

Models and Interpretations A model in FOL consists of the objects

(domain elements) and relations (including functions) See example diagram “conceptual” view of world

An interpretation associates the symbols to the objects, relations, and functions in the model Number of interpretations for a given set of

symbols is combinatorially explosive

Page 9: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

9

Semantics Truth of a sentence in FOL:

Determined with respect to a model and an interpretation

Analogous notions for entailment, validity, and satisfiability

Model enumeration is impractical in FOL

Page 10: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

10

Sample Sentences Person(John) Person(Richard) OnHead(C, John) LeftLeg(John) = L1 LeftLeg(Richard) = L1

Richard, and LeftLeg(John) are examples of terms(a term is an expression that refers to an object)

Atomic Sentences: constructed by equating terms (=) or by a predicate (with terms as arguments)

Complex Sentences: sentences with connectives

Page 11: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

11

Quantifiers Universal Quantification

x P is true in a model m iff P is true with x being each possible object in the model

A conjunction of instantiations Existential Quantification

x P is true in a model m iff P is true with x being some object in the model

A disjunction of instantiations

Page 12: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

12

Sample SentencesUsing Quantifiers x King(x) Person(x) x Crown(x) OnHead(x,John)

“John has a crown on his head” xy Brother(x,y) Brother(y,x) xy Brother(x,Richard)

Brother(y,Richard) (x=y) “Richard has at least 2 brothers”

Page 13: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

13

Properties of Quantifiers Nested Quantifiers

x y P equivalent to y x P y x P equivalent to y x P Does not apply if quantifiers are different

De Morgan’s law for quantifiers x P x P x P x P x P x P x P x P

Page 14: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

14

More About Quantifiers Be careful when:

Using quantifiers (, ) in combination with , The domain consists of multiple kinds of objects

In the quantified sentence(such as x P or x P), P would typically contain terms that are variables Not just ground terms (terms that have no

variables) x P as a query: binding list more

important than truth of the sentence

Page 15: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

15

Axioms and Theorems Axioms are sentences that

represent first principles Plain facts Definitions

Theorems are sentences entailed by axioms

Page 16: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

16

Some Useful Domains Natural Numbers

Built from 0, successor function S, and Peano axioms

Sets , , , , and element insertion

Lists Nil, Cons, Append, First, Rest, Find, …

Page 17: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

17

FOL and the Wumpus World We can represent the Wumpus World in a

more compact fashion Less sentences needed to represent rules

We can include time and percept objects in the world A percept is represented as a list of constant

symbols Predicates with time arguments capture the

dynamic nature of the agent moving in this world

Page 18: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

18

Knowledge Engineering Identify the task Assemble the relevant knowledge Decide on a vocabulary Encode general knowledge of the

domain Encode the specific problem instance Pose queries to the inference procedure Debug the knowledge base

Page 19: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

19

Inference Algorithms in FOL Reduction to Propositional

Inference(Propositionalization)

Lifting and Unification Resolution

Page 20: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

20

Propositionalization Strategy: convert KB to

propositional logic and then use PL inference

Ground atomic sentences become propositional symbols

What about the quantifiers?

Page 21: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

21

Example KB in FOL:

x King(x) Greedy(x) Evil(x) King(John) Greedy(John) Brother(Richard,John)

The last 3 sentences can be symbols in PL

Apply Universal Instantiation to the first sentence

Page 22: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

22

Universal Instantiation UI says that from a universally quantified

sentence, we can infer any sentence obtained by substituting a ground term for the variable

Back to Example From: x King(x) Greedy(x) Evil(x) To:

King(John) Greedy(John) Evil(John) King(Richard) Greedy(Richard) Evil(Richard) …

Page 23: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

23

Issue with UI Ground terms: all symbols that refer to

objects as well as function applications (recall that function applications return objects)

For example, suppose Father is a function: Father(John) and Father(Richard) are also

objects/ground terms But so are Father(Father(John)) and

Father(Father(Father(John))) Infinitely many ground terms/instantiations

Page 24: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

24

Existential Instantiation Whenever there is a sentence, x P,

introduce a new object symbol called the skolem constant and then add the unquantified sentence P, substituting the variable with that constant

Example: From: x Crown(x) OnHead(x, John) To: Crown(Cnew) OnHead(Cnew, John)

Page 25: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

25

Substitution UI and EI apply substitutions A substitution is represented by a variable

v and a ground term g; {v/g} Can have sets of these pairs if there are more

variables involved Let be a sentence (possibly containing v) SUBST( {v/g}, ) stands for the

sentence that applies the substitution to

Page 26: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

26

UI and EI Defined UI:

v α ___ for any ground term g SUBST({v/g}, α)

EI: v α ___ for some constant symbol

k not SUBST({v/k}, α) yet in the knowledge base

Page 27: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

27

Back to Propositionalization Given a KB in FOL, convert KB to PL by

1. applying UI and EI to quantified sentences2. converting atomic sentences to symbols

If there are no functions (Datalog KB), UI application does not result in infinitely many sentences

Regular PL Inference can now be carried out without problems

What if there are functions?

Page 28: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

28

Dealing with Infinitely Many Ground Terms Can set a depth-limit for ground terms

Depth specifies levels of function nesting allowed

Carry out reduction and inference process for depth 1, then 2, then 3, …

Stop when entailment can be concluded This works if there is such a proof, but goes

into an endless loop if there is not The strategy is complete The entailment problem in this sense is

semidecidable

Page 29: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

29

Inefficiencies in Propositionalization An inordinate number of irrelevant

sentences may be generated, resulting from UI

This motivates generating only those sentences that are important in entailment

Page 30: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

30

Example Suppose KB contains:

x King(x) Greedy(x) Evil(x) y Greedy(y) King(John)

Suppose we want to conclude Evil(John) Because of the existence of objects

other than John (such as Richard) and the existence of functions, UI will generate many sentences

Page 31: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

31

Example, continued It is sufficient to generate:

King(John) Greedy(John) Evil(John) Greedy(John)

Which is just: SUBST( {x/John}, King(x) Greedy(x) Evil(x) ) SUBST( {y/John}, Greedy(y) )

Applying the substitution matches the Premises: King(x) Greedy(x) With other sentences in the KB:

Greedy(y), King(John)

Page 32: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

32

Lifted Modus Ponens Lifting: Raising propositional inference

rules to first order logic Example: Generalized Modus Ponens

If there is a substitution θ, such thatSUBST(θ, pi) = SUBST(θ, pi’) for all i, then

p1', p2', … , pn’, ( p1 p2 … pn q)_______________________________________________________________________________

SUBST(θ,q) In our example, = {x/John, y/John}

Page 33: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

33

Unification Process that makes logical

expressions identical Goal: match the premises of

implications so that conclusions can be derived

UNIFY algorithm takes two sentences and returns a unifier (substitution) if it exists

Page 34: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

34

Unification Algorithm

Page 35: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

35

Unification Algorithm

Page 36: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

36

About UNIFY UNIFY returns a Most General

Unifier (MGU) There are efficiency issues with

OCCUR-CHECK function May need to standardize apart:

rename variables to avoid name clashes

Unification is a key component of all first-order algorithms

Page 37: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

37

Algorithms that use unification Forward and backward chaining

algorithms Will not be discussed

Resolution-based theorem proving systems

Page 38: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

38

PL Resolution Revisited Recall PL Resolution algorithm:

Convert (KB ) to CNF Repeatedly get pairs of clauses and eliminate

complementary literals If an empty clause results, KB╞

Resolution applies to FOL, but we need to refine definitions of: CNF (for quantified sentences) Resolution inference rule / complimentary

literals

Page 39: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

39

CNF Conversion in FOL1. Eliminate biconditionals and implications2. Move inwards (De Morgan’s)

For quantifiers: x P x P, x P x P

3. Standardize variables Eliminate possible name clashes

4. Skolemize (Apply EI to existential sentences)

Introduce Skolem constants or functions

5. Drop universal quantifiers 6. Distribute over

Page 40: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

40

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

Standardize variables: each quantifier should use a different one

x [y Animal(y) Loves(x,y)] [z Loves(z,x)]

Page 41: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

41

Example, continued4. Skolemize: a more 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)]

Page 42: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

42

Resolution Lifted version of resolution inference rule:

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}

Page 43: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

43

Page 44: 1 First Order Logic CS 171/271 (Chapters 8 and 9) Some text and images in these slides were drawn from Russel & Norvig’s published material

44

Making ResolutionMore Efficient Can favor particular clauses in the

KB Unit preference (unit clauses) Sets of support Input resolution (e.g. “single spine”)

Subsumption Reduces size of KB by eliminating

redundant sentences