22c:145 artificial intelligence - university of...

58
22c:145 Artificial Intelligence Fall 2005 First-Order Logic Hantao Zhang The University of Iowa Copyright 2001-05 — Cesare Tinelli and Hantao Zhang. a a These notes are copyrighted material and may not be used in other course settings outside of the University of Iowa in their current or modified form without the express written permission of the copyright holders. 22c:145 Artificial Intelligence, Fall’05 – p.1/57

Upload: lamdien

Post on 30-Sep-2018

235 views

Category:

Documents


0 download

TRANSCRIPT

22c:145 Artificial IntelligenceFall 2005

First-Order Logic

Hantao Zhang

The University of Iowa

Copyright 2001-05 — Cesare Tinelli and Hantao Zhang. a

a These notes are copyrighted material and may not be used in other course settings outside of the

University of Iowa in their current or modified form without the express written permission of the copyright

holders.22c:145 Artificial Intelligence, Fall’05 – p.1/57

Readings

Chap. 8 of [Russell and Norvig, 2003]

22c:145 Artificial Intelligence, Fall’05 – p.2/57

Einstein’s Puzzle in Logic

We used propositinal variables to specify everything:x1 = “house #1 is red”;x2 = “house #2 is red”;...x26 = “Brit lives in house #1”;...

Can we use one symbol with parameters for “the color of house#x is y”, i.e., IsColor(x, y)?

Or simply, color(x) = y?

Yes, we can do this in First-Order Logic.

22c:145 Artificial Intelligence, Fall’05 – p.3/57

First-Order Logic

Rather powerful representation and reasoning system.

Very well understood and extensively studied (a couple ofthousand years!).

Many fancy knowledge representation formalisms—semanticnets, frames, scripts—are basically sugar-coated variants of(part of) it.

22c:145 Artificial Intelligence, Fall’05 – p.4/57

Ontological Commitments

1. The world is made of objects , things with individual identitiesand properties that distinguish them.

2. Various relations hold among objects. Some of these relationsare functional .

3. Every fact involving objects and their relations is either true orfalse.

22c:145 Artificial Intelligence, Fall’05 – p.5/57

The Language of First-OrderLogic

Symbols

Variables

Constant symbols

Functional symbols (with arities)

Relational symbols (with arities)

Logical symbols: As in Propositional Logic plus

∀ (for all) ∃ (there exists) = (equal)

22c:145 Artificial Intelligence, Fall’05 – p.6/57

Language of FOL: Symbols

Variables, constant symbols, and function symbols are used tobuild terms :x, Bill, 6,FatherOf (x), Height(FatherOf (Bill)), Log(3 + y), . . .

Relational symbols are applied to terms to build predicates :Even(x), Married(Bill, Hillary), Loves(x,MotherOf (x)), . . .

Predicates and logical symbols are used to build sentences :Even(3), ∃x ¬Loves(x,MotherOf (x)), ∀x Even(x)→Odd(x + 1), . . .

22c:145 Artificial Intelligence, Fall’05 – p.7/57

Language of FOL: Terms

A variable is a term.

A constant symbol is a term.

If f is an n-ary function symbol and t1, . . . , tn are n terms,f(t1, . . . , tn) is a term.

Nothing else is a term.

22c:145 Artificial Intelligence, Fall’05 – p.8/57

Language of FOL: Sentences

True (False) is a sentence.

If t1, t2 are terms, t1 = t2 is a sentence.

If p is an n-ary relation symbol and t1, . . . , tn are n terms,p(t1, . . . , tn) is a sentence.

If ϕ is a sentence, ¬ϕ, ∃x ϕ, ∀x ϕ are sentences.

If ϕ1, ϕ2 are sentences, ϕ1 ∧ ϕ2, ϕ1 ∨ ϕ2, ϕ1 → ϕ2, ϕ1 ↔ ϕ2 aresentences.

Nothing else is a sentence.

22c:145 Artificial Intelligence, Fall’05 – p.9/57

Language of FOL: Grammar

Sentence ::= AtomicS | ComplexS

AtomicS ::= True | False | RelationSymb(Term, . . .) | Term = Term

ComplexS ::= (Sentence) | Sentence Connective Sentence | ¬Sentence

| Quantifier Sentence

Term ::= FunctionSymb(Term, . . .) | ConstantSymb | Variable

Connective ::= ∧ | ∨ | → | ↔Quantifier ::= ∀ Variable | ∃ Variable

Variable ::= a | b | · · · | x | y | · · ·ConstantSymb ::= A | B | · · · | John | 0 | 1 | · · · | π | . . .

FunctionSymb ::= F | G | · · · | Cosine | Height | FatherOf | + | . . .

RelationSymb ::= P | Q | · · · | Red | Brother | Apple | > | · · ·22c:145 Artificial Intelligence, Fall’05 – p.10/57

A Note on the Syntax of FOL

As defined, the syntax of FOL is ambiguous:

∀x ¬P (x) ∨Q(x) ∧R(x)→ S(x) (1)

It can be disambiguated by using parentheses or fixing aprecedence ordering on the logical connectives. We will use thefollowing ordering:

(¬, ∧, ∨, →, ↔, {∀, ∃})

With this ordering, (1) actually is

∀x (((¬P (x)) ∨ (Q(x) ∧R(x)))→ S(x))

When in doubt, use parentheses!

22c:145 Artificial Intelligence, Fall’05 – p.11/57

Semantics of First-Order Logic

Interprets

constant symbols and variables as objects;

functional symbols as functions from objects to objects;

relational symbols as relations over objects;

= as equality (i.e., the identity relation).

22c:145 Artificial Intelligence, Fall’05 – p.12/57

Constant Symbols andVariables

Denote (stand for) objects/individuals.Example:

Dog143 is a constant symbol denoting a particular dog.peach is a variable ranging over peaches.

The symbol−→object association is arbitrary!

Under another interpretation Dog143 could denote another dog,or maybe something else altogether. Similarly, peach might aswell range over apples.

22c:145 Artificial Intelligence, Fall’05 – p.13/57

Formalizing Knowledge in FOL

First Step: Fix a Universe of Discourse , that is, the set of objects ofinterest.

Example: The Blocks World

a

b

c

d

e

t

Here the universe is { the table, block a, block b, . . . , block e }.Note: The universe may be infinite, even uncountable!(the integers, the reals, . . . )

22c:145 Artificial Intelligence, Fall’05 – p.14/57

Relations

Let U be the universe of discourse.

A relation of arity n is a subset of the Cartesian productU × · · · × U︸ ︷︷ ︸

n times

.

Example: Some relations in the Blocks World

a

b

c

d

e

t

On := {〈a, b〉, 〈b, c〉, 〈c, t〉, 〈d, e〉, 〈e, t〉}

Clear := {〈a〉, 〈d〉}

Example: “Less Than” over the naturals

< := {〈x, y〉 | x, y ∈ N, ∃z 6= 0 ∈ N s.t. x + z = y}:= {〈0, 1〉, 〈0, 2〉, . . . , 〈1, 2〉, 〈1, 3〉, . . .}

22c:145 Artificial Intelligence, Fall’05 – p.15/57

Functions

A function in one variable is simply a functional binary relation.

A relation f over U × U is functional if for all x ∈ U there is oneand only one y ∈ U such that 〈x, y〉 ∈ f .

If f is a function

(〈x, y〉 ∈ f) ∧ (〈x, z〉 ∈ f) implies y = z

Hence, instead of writing 〈x, y〉 ∈ f we write y = f(x).

Functions in n > 1 variables are defined similarly.

22c:145 Artificial Intelligence, Fall’05 – p.16/57

Examples of Functions

Most mathematical functions +,×, ex, sine, . . .

Some relations in the Blocks World

a

b

c

d

e

t

Color := {〈a, blue〉, 〈b, red〉, 〈c, blue〉, . . .}

Support := {〈a, b〉, 〈b, c〉, 〈c, t〉, 〈d, e〉, 〈e, t〉}

We may define function color(x) such that color(a) = blue,color(b) = red , ...

Note: Functions in FOL are always total , i.e., defined over theentire universe of discourse.

22c:145 Artificial Intelligence, Fall’05 – p.17/57

Relations and Predicates

The notation Mother(Jane,Bill) is intended to mean that

〈Jane,Bill〉 ∈ Mother

A relation implicitly defines (or provides the meaning of) apredicate , i.e., a function ranging over {True,False}.Predicate is a syntactic way of representing a relation (in thestyle of a function).

22c:145 Artificial Intelligence, Fall’05 – p.18/57

Functions and Names

The functional notation can be used to create several names forthe same object.

Examples:

3,√

9, 1 + 2, age(Baby)

George_W _Bush, PresidentOf (US ), SonOf (Barbara)

22c:145 Artificial Intelligence, Fall’05 – p.19/57

Universal quantification

∀ 〈variables〉 〈sentence〉Everyone at UIowa is smart:∀x At(x, UIowa) =⇒ Smart(x)

∀x P (x) is true in an interpretation m iff P (x) is true with x beingeach possible object in the domain

Roughly speaking, equivalent to the conjunction of instantiations ofP

At(KingJohn, UIowa) =⇒ Smart(KingJohn)

∧ At(Richard, UIowa) =⇒ Smart(Richard)

∧ At(UIowa, UIowa) =⇒ Smart(UIowa)

∧ . . .

22c:145 Artificial Intelligence, Fall’05 – p.20/57

A common mistake to avoid

Typically, =⇒ is the main connective with ∀

Common mistake: using ∧ as the main connective with ∀:

∀x At(x, UIowa) ∧ Smart(x)

means “Everyone is at UIowa and everyone is smart”

22c:145 Artificial Intelligence, Fall’05 – p.21/57

Existential quantification

∃ 〈variable〉 〈sentence〉

Someone at Stanford is smart:∃x At(x, Stanford) ∧ Smart(x)

∃x P is true in an interpretation I iff P is true with x being somepossible object in the domain

Roughly speaking, equivalent to the disjunction of instantiations of P

At(KingJohn, Stanford) ∧ Smart(KingJohn)

∨ At(Richard, Stanford) ∧ Smart(Richard)

∨ At(Stanford, Stanford) ∧ Smart(Stanford)

∨ . . .

22c:145 Artificial Intelligence, Fall’05 – p.22/57

Another common mistake toavoid

Typically, ∧ is the main connective with ∃

Common mistake: using =⇒ as the main connective with ∃:

∃x At(x, Stanford) =⇒ Smart(x)

is true if there is anyone who is not at Stanford!

22c:145 Artificial Intelligence, Fall’05 – p.23/57

Semantics of First-Order Logic

Interprets

the universal quantifier (essentially) as an infinite conjunction;(∀x Red(x) ≡ Red(Obj

1)∧Red(Obj

2)∧Red(Obj

3)∧Red(Obj

4)∧· · · )

the existential quantifier (essentially) as an infinite disjunction;(∃x Red(x) ≡ Red(Obj

1)∨Red(Obj

2)∨Red(Obj

3)∨Red(Obj

4)∨· · · )

True,False,∧,∨,¬,→,↔ as in propositional logic.

22c:145 Artificial Intelligence, Fall’05 – p.24/57

Semantics of FOL: Examples

Sentence Intuitive meaning

1. Above(A, B) object A is above object B

2. British(Elisabeth) an “object” called Elisabeth is British

3. ∀x Apple(x)→ Red(x) . . .

4. ∀x Apple(x) ∧ Red(x) . . .

5. ∃x Apple(x) ∨ Red(x) . . .

6. ∀x ∃y y > x . . .

6b. ∀x Number(x)→ ∃y y > x . . .

7. (∀x Apple(x)) ∨ ∃y Pear(y) . . .

7b. (∀x Apple(x)) ∨ ∃x Pear(x) . . .

8. ∀x ∃y Loves(x, y) . . .

8b. ∃y ∀x Loves(x, y) . . .22c:145 Artificial Intelligence, Fall’05 – p.25/57

Semantics of FOL: Examples

Sentence Intuitive meaning

9. ∃x ∀y Loves(x, y) . . .

10. ∀x (Bird(x) ∧ ¬Ostrich(x))→ Flies(x) . . .

11. ∀x (Fish(x) ∧ ¬Ostrich(x))→ Flies(x) . . .

12. ∀x Flies(x)↔ (Bird(x) ∨ P lane(x)) . . .

13. ∀x Person(x)→(W (x) ∨M(x)) ∧ ¬(W (x) ∧M(x)) . . .

Note: The scope of a quantifier is the sentence it applies to:

∀x P (x) ∧Q(x)︸ ︷︷ ︸

scope of ∀x

∀x R(x, z) ∧ ∃y S(x, y)︸ ︷︷ ︸

scope of ∃y︸ ︷︷ ︸

scope of ∀x22c:145 Artificial Intelligence, Fall’05 – p.26/57

Free and Bound Variables

An occurrence of variable in a sentence is free if it is not in the scopeof any quantifier with the same variable. A non-free variableoccurrence is bound .

∀x P (x) ∧Q(x) both occurrences of x bound by ∀x(∀x P (x)) ∧Q(x) first occurrence of x bound by ∀x, second free

∀x R(x, z) ∧ ∃y S(x, y) both occurrences of x bound by ∀x, occurrence of y

bound by ∃y, occurrence of z free

A sentence is open if it contains free variables; it is closed otherwise.

22c:145 Artificial Intelligence, Fall’05 – p.27/57

Properties of quantifiers

∀x ∀ y is the same as ∀ y ∀x (why?)

∃x ∃ y is the same as ∃ y ∃x (why?)

∃x ∀ y is not the same as ∀ y ∃x

∃x ∀ y Loves(x, y)

“There is a person who loves everyone in the world”∀ y ∃x Loves(x, y)

“Everyone in the world is loved by at least one person”

Quantifier duality: each can be expressed using the other

∀x Likes(x, IceCream) ¬∃x ¬Likes(x, IceCream)∃x Likes(x, Broccoli) ¬∀x ¬Likes(x, Broccoli)

22c:145 Artificial Intelligence, Fall’05 – p.28/57

Fun with sentences

Brothers are siblings∀x, y Brother(x, y) =⇒ Sibling(x, y).

“Sibling” is symmetric

22c:145 Artificial Intelligence, Fall’05 – p.29/57

Fun with sentences

Brothers are siblings∀x, y Brother(x, y) =⇒ Sibling(x, y).

“Sibling” is symmetric∀x, y Sibling(x, y) ⇔ Sibling(y, x).

One’s mother is one’s female parent

22c:145 Artificial Intelligence, Fall’05 – p.30/57

Fun with sentences

Brothers are siblings∀x, y Brother(x, y) =⇒ Sibling(x, y).

“Sibling” is symmetric∀x, y Sibling(x, y) ⇔ Sibling(y, x).

One’s mother is one’s female parent∀x, y Mother(x, y) ⇔ (Female(x) ∧ Parent(x, y)).

A first cousin is a child of a parent’s sibling

22c:145 Artificial Intelligence, Fall’05 – p.31/57

Fun with sentences

Brothers are siblings∀x, y Brother(x, y) =⇒ Sibling(x, y).

“Sibling” is symmetric∀x, y Sibling(x, y) ⇔ Sibling(y, x).

One’s mother is one’s female parent∀x, y Mother(x, y) ⇔ (Female(x) ∧ Parent(x, y)).

A first cousin is a child of a parent’s sibling∀x, y F irstCousin(x, y) ⇔ ∃ p, ps Parent(p, x) ∧ Sibling(ps, p) ∧Parent(ps, y)

22c:145 Artificial Intelligence, Fall’05 – p.32/57

Equality

term1 = term2 is true under a given interpretationif and only if term1 and term2 refer to the same object

E.g., 1 = 2 and ∀x ×(Sqrt(x), Sqrt(x)) = x are satisfiable2 = 2 is valid

E.g., definition of (full) Sibling in terms of Parent:∀x, y Sibling(x, y) ⇔ [¬(x= y) ∧ ∃m, f ¬(m = f) ∧

Parent(m, x) ∧ Parent(f, x) ∧ Parent(m, y) ∧ Parent(f, y)]

22c:145 Artificial Intelligence, Fall’05 – p.33/57

Semantics of First-Order Logic

(A little) more formally:

An interpretation is a pair (D, σ) where

D is a set of objects, the universe (or domain);

σ is mapping from variables to objects in D;

CD is an object in D for every constant symbol C;

FD is a function from Dn to D for every function symbol F ofarity n;

RD is a relation over Dn for every relation symbol R of arity n;

22c:145 Artificial Intelligence, Fall’05 – p.34/57

An Interpretation I in theBlocks World

Constant Symbols: A, B, C, D, E, T

Function Symbols: Support

Relation Symbols: On,Above,Clear

a

b

c

d

e

t

AI = a, BI = b, CI = c, DI = d, EI = e, F I = f, T I = t

SupportI = {〈a, b〉, 〈b, c〉, 〈c, t〉, 〈d, e〉, 〈e, t〉, 〈t, t〉}OnI = {〈a, b〉, 〈b, c〉, 〈d, e〉}AboveI = {〈a, b〉, 〈a, c〉, 〈b, c〉, 〈d, e〉}Clear I = {〈a〉, 〈d〉}

22c:145 Artificial Intelligence, Fall’05 – p.35/57

A different interpretation: J

Constant Symbols: A, B, C, D, E, T Function Symbols: Support

Relation Symbols: On,Above,Clear

. ..

bike

JoeJill

ground

Joe’s hat

case

AJ= Joe′sHat , BJ

= Joe, CJ= bike, DJ

= Jill , EJ= case, TJ

= ground

SupportJ= {〈Joe′s hat , Joe〉, 〈Joe, bike〉, 〈bike, ground〉, 〈Jill , case〉,

〈case, ground〉, 〈ground , ground〉}

OnJ= {〈Joe′s hat , Joe〉, 〈Joe, bike〉, 〈Jill , case〉, }

AboveJ= {〈Joe′s hat , Joe〉, 〈Joe′s hat, bike〉, . . .}

ClearJ= {〈Jill〉 (no hat), Joe′s hat} 22c:145 Artificial Intelligence, Fall’05 – p.36/57

A Herbrand interpretation: H

Constant Symbols: A, B, C, D, E, T Function Symbols: Support

Relation Symbols: On,Above,Clear

AH= A, BH

= B , CH= C , DH

= D , EH= E , TH

= T

SupportH= {〈A,T 〉, 〈B ,A〉, 〈C ,B〉, 〈D ,C 〉, 〈E ,D〉}

OnH= {〈A,T 〉, 〈B ,A〉, 〈C ,B〉, 〈D ,C 〉, 〈E ,D〉}

AboveH= {〈E ,D〉, 〈D ,C 〉, . . .}

ClearH= {〈E〉}

22c:145 Artificial Intelligence, Fall’05 – p.37/57

Semantics of First-Order Logic

Let (D, σ) be an interpretation and E an expression of FOL. Wewrite [[E]]Dσ to denote the meaning of E in the domain D underthe variable assignment σ.

The meaning [[t]]Dσ of a term t is an object of D. It is inductivelydefined as follows.[[x]]Dσ := σ(x) for all variables x

[[C]]Dσ := CD for all constant symbols C

[[F (t1, . . . , tn)]]Dσ := FD([[t1]]Dσ , . . . , [[tn]]Dσ ) for all function symbols F

of arity n

22c:145 Artificial Intelligence, Fall’05 – p.38/57

Example

Consider the symbols MotherOf , SchoolOf ,Bill and theinterpretation (D, σ) where

MotherOf D is a unary fn mapping people to their mother

FchildOf D is a binary fn mapping a couple to their first child

σ := {x 7→ George W Bush, y 7→ Barbara Bush}

What is the meaning of MotherOf (x) according to (D, σ)?

[[MotherOf (x)]]Dσ = [[MotherOf ]]Dσ ([[x]]Dσ ) = MotherOf D(σ(x)) = Barbara Bush

22c:145 Artificial Intelligence, Fall’05 – p.39/57

Semantics of First-Order Logic

The meaning [[ϕ]]Dσ of a formula ϕ is either True or False.

It is inductively defined as follows.

[[t1 = t2]]Dσ := True iff [[t1]]

Dσ is the same as [[t2]]

[[R(t1, . . . , tn)]]Dσ := True iff 〈[[t1]]Dσ , . . . , [[tn]]Dσ 〉 ∈ RD

[[¬ϕ]]Dσ := True/False iff [[ϕ]]Dσ = False/True

[[ϕ1 ∨ ϕ2]]Dσ := True iff [[ϕ1]]

Dσ = True or [[ϕ2]]

Dσ = True

[[∃x ϕ]]Dσ := True iff [[ϕ]]Dσ′ = True for some σ′ the

same as σ except for x

22c:145 Artificial Intelligence, Fall’05 – p.40/57

Semantics of First-Order Logic

The meaning of formulas built with the other logical symbolscan be defined by reduction to the previous symbols.[[ϕ1 ∧ ϕ2]]

Dσ := [[¬(¬ϕ1 ∨ ¬ϕ2)]]

[[ϕ1 → ϕ2]]Dσ := [[¬ϕ1 ∨ ϕ2]]

[[ϕ1 ↔ ϕ2]]Dσ := [[(ϕ1 → ϕ2) ∧ (ϕ2 → ϕ1)]]

[[∀xϕ]]Dσ := [[¬∃x ¬ϕ]]Dσ

If a sentence is closed (no free variables), its meaning does notdepend on the the variable assignment (although it maydepend on the domain):

[[∀x ∃y R(x, y)]]Dσ = [[∀x ∃y R(x, y)]]Dσ′ for any σ, σ′

22c:145 Artificial Intelligence, Fall’05 – p.41/57

Models, Validity, etc. forSentences

An interpretation (D, σ) satisfies a sentence ϕ, or is a model forϕ, if [[ϕ]]Dσ = True.

A sentence is satisfiable if it has at least one model.Examples: ∀x x ≥ y, P (x)

A sentence is unsatisfiable if it has no models.Examples: P (x) ∧ ¬P (x), ¬(x = x)

A sentence ϕ is valid if every interpretation is a model for ϕ.Examples: P (x)→ P (x), x = x

ϕ is valid/unsatisfiable iff ¬ϕ is unsatisfiable/valid.

Valid sentences do not tell us anything about the world.(They are always true!)

22c:145 Artificial Intelligence, Fall’05 – p.42/57

Models, Validity, etc. for Setsof Sentences

An interpretation (D, σ) satisfies a set Γ of sentences, or is amodel for Γ, if it is a model for every sentence in Γ.

A set Γ of sentences is satisfiable if it has at least one model.Ex: {∀x x ≥ 0, ∀x x + 1 > x}

Γ is unsatisfiable , or inconsistent , if it has no models.Ex: {P (x), ¬P (x)}

As in Propositional Logic, Γ entails a sentence ϕ (Γ |= ϕ), ifevery model of Γ is also a model of ϕ.

Ex: {∀x P (x)→ Q(x), P (A10)} |= Q(A10)

Note: Again, Γ |= ϕ iff Γ ∧ ¬ϕ is unsatisfiable.

22c:145 Artificial Intelligence, Fall’05 – p.43/57

Possible InterpretationsSemantics

Sentences can be seen as constraints on the set S of allpossible interpretations.

A sentence denotes all the possible interpretations that satisfyit (the models of ϕ).If ϕ1 denotes a set of interpretations S1 and ϕ2 denotes a setS2, then

ϕ1 ∨ ϕ2 denotes S1 ∪ S2,ϕ1 ∧ ϕ2 denotes S1 ∩ S2,¬ϕ1 denotes S \S1,ϕ1 |= ϕ2 iff S1 ⊆ S2.

A sentence denotes either no interpretations or an infinitenumber of them!

22c:145 Artificial Intelligence, Fall’05 – p.44/57

Models for FOL: Lots!

We can enumerate the models for a given FOL sentence:

For each number of universe elements n from 1 to∞For each k-ary predicate Pk in the sentence

For each possible k-ary relation on n objectsFor each constant symbol C in the sentence

For each one of n objects mapped to C. . .

Enumerating models is not going to be easy!

22c:145 Artificial Intelligence, Fall’05 – p.45/57

Herbrand Intepretations andModels

A Herbrand interpretation H is an interpretation which maps asymbol to the symbol itself, maps a term to the term itself andmaps a subset of atomic formulas to true.

A Herband interpretation is often represented by a set S ofatomic formulas with the meaning that an atomic formula is truein this interpretation iff it is in S.

Example: Let the domain be {john, mary, table}. The sentenceφ is ∀x human(x)→ mortal(x). Then a Herbrand interpretationH1 can be {human(john), mortal(john)} and H1 is a model of φ.

Theorem : If a set of sentences has a model, then it has aHerbrand model.

22c:145 Artificial Intelligence, Fall’05 – p.46/57

The Wumpus World in FOL

Breeze Breeze

Breeze

BreezeBreeze

Stench

Stench

BreezePIT

PIT

PIT

1 2 3 4

1

2

3

4

START

Gold

Stench

22c:145 Artificial Intelligence, Fall’05 – p.47/57

Interacting with FOL KBs

Suppose a wumpus-world agent is using an FOL KBand perceives a smell and a breeze (but no glitter) at t = 5:

Tell(KB, Percept([Smell, Breeze, None], 5))Ask(KB, ∃ a Action(a, 5))

I.e., does the KB entail any particular actions at t = 5?

Answer: Y es, {a/Shoot} ← substitution (binding list)

Given a sentence S and a substitution σ,Sσ denotes the result of plugging σ into S; e.g.,S = Smarter(x, y)σ = {x/Hillary, y/Bill}Sσ = Smarter(Hillary, Bill)

Ask(KB, S) returns some/all σ such that KB |= Sσ

22c:145 Artificial Intelligence, Fall’05 – p.48/57

Knowledge base for thewumpus world

“Perception”∀ b, g, t Percept([Smell, b, g], t) =⇒ Smelt(t)∀ s, b, t Percept([s, b, Glitter], t) =⇒ AtGold(t)

Reflex: ∀ t AtGold(t) =⇒ Action(Grab, t)

Reflex with internal state: do we have the gold already?∀ t AtGold(t) ∧ ¬Holding(Gold, t) =⇒ Action(Grab, t)

Holding(Gold, t) cannot be observed⇒ keeping track of change is essential

22c:145 Artificial Intelligence, Fall’05 – p.49/57

Deducing Hidden Properties

Properties of locations:∀x, t At(Agent, x, t) ∧ Smelt(t) =⇒ Smelly(x)

∀x, t At(Agent, x, t) ∧Breeze(t) =⇒ Breezy(x)

Squares are breezy near a pit:

Diagnostic rule—infer cause from effect∀ y Breezy(y) =⇒ ∃x Pit(x) ∧Adjacent(x, y)

Causal rule—infer effect from cause∀x, y P it(x) ∧Adjacent(x, y) =⇒ Breezy(y)

Neither of these is complete—e.g., the causal rule doesn’tsay whether squares far away from pits can be breezyDefinition for the Breezy predicate:∀ y Breezy(y) ⇔ [∃x Pit(x) ∧Adjacent(x, y)]

22c:145 Artificial Intelligence, Fall’05 – p.50/57

Keeping Track of Change

Facts hold in situations, rather than eternallyE.g., Holding(Gold, Now) rather than just Holding(Gold)

PIT

PIT

PIT

Gold

PIT

PIT

PIT

Gold

S0

Forward

S1

22c:145 Artificial Intelligence, Fall’05 – p.51/57

Situation Calculus

Situation calculus is one way to represent change in FOL:Adds a situation argument to each non-eternal predicateE.g., Now in Holding(Gold, Now) denotes a situation (or a timestamp).

Situations are connected by the Result functionResult(a, s) is the situation that results from doing a in s

22c:145 Artificial Intelligence, Fall’05 – p.52/57

Describing Actions

“Effect” axiom—describe changes due to action∀ s AtGold(s) =⇒ Holding(Gold, Result(Grab, s))

“Frame” axiom—describe non-changes due to action∀ s HaveArrow(s) =⇒ HaveArrow(Result(Grab, s))

22c:145 Artificial Intelligence, Fall’05 – p.53/57

Frame, Qualifcation, andRamification

Frame problem: find an elegant way to handle non-change

representation—avoid frame axiomsinference—avoid repeated “copy-overs” to keep track ofstate

Qualification problem: true descriptions of real actions requireendless caveats—what if gold is slippery or nailed down or . . .

Ramification problem: real actions have many secondaryconsequences—what about the dust on the gold, wear and tearon gloves, . . .

22c:145 Artificial Intelligence, Fall’05 – p.54/57

Describing Actions

Successor-state axioms solve the representational frameproblem

Each axiom is “about” a predicate (not an action per se):

P true afterwards ⇔ [an action made P true ∨P true already and no action made P false]

Exmaple: For holding the gold:∀ a, s Holding(Gold, Result(a, s)) ⇔

[(a =Grab) ∧AtGold(s) ∨Holding(Gold, s) ∧ (a 6= Release)]

22c:145 Artificial Intelligence, Fall’05 – p.55/57

Making Plans

Initial condition in KB:At(Agent, [1, 1], S0)At(Gold, [1, 2], S0)

Query: Ask(KB, ∃ s Holding(Gold, s))

i.e., in what situation will I be holding the gold?

Answer: {s/Result(Grab, Result(Forward, S0))}i.e., go forward and then grab the gold

This assumes that the agent is interested in plans starting at S0

and that S0 is the only situation described in the KB

22c:145 Artificial Intelligence, Fall’05 – p.56/57

Making plans: A better way

Represent plans as action sequences [a1, a2, . . . , an]

P lanResult(p, s) is the result of executing p in s

Then the query Ask(KB, ∃ p Holding(Gold, P lanResult(p, S0)))has the solution {p/[Forward, Grab]}Definition of P lanResult in terms of Result:∀ s P lanResult([ ], s) = s∀ a, p, s P lanResult([a|p], s) = P lanResult(p, Result(a, s))

Planning systems are special-purpose reasoners designed todo this type of inference more efficiently than ageneral-purpose reasoner

22c:145 Artificial Intelligence, Fall’05 – p.57/57

Summary

First-order logic:– objects and relations are semantic primitives– syntax: constants, functions, predicates, equality, quantifiers

Increased expressive power: sufficient to define wumpus world

Situation calculus:– conventions for describing actions and change in FOL– can formulate planning as inference on a situation calculusKB

22c:145 Artificial Intelligence, Fall’05 – p.58/57