Chapter8 First-Order Logic 20070503 Chap8 1 Pros and Cons of - - PDF document

chapter8
SMART_READER_LITE
LIVE PREVIEW

Chapter8 First-Order Logic 20070503 Chap8 1 Pros and Cons of - - PDF document

Chapter8 First-Order Logic 20070503 Chap8 1 Pros and Cons of Prop. Logic PL is declarative Knowledge and inference are separate and inference is entirely domain-independent. PL is compositional Meaning of a sentence is a


slide-1
SLIDE 1

1

20070503 Chap8 1

Chapter8

First-Order Logic

20070503 Chap8 2

Pros and Cons of Prop. Logic

  • PL is declarative

Knowledge and inference are separate and inference is entirely domain-independent.

  • PL is compositional

Meaning of a sentence is a function of the meaning of its parts

  • PL allows partial/ disjunctive/negated information
  • The meaning of PL is context-independent.
  • PL has very limited expressive power

e.g. cannot say “pits cause breezes in adjacent squares” except by writing one sentence for each square

slide-2
SLIDE 2

2

20070503 Chap8 3

First-Order Logic

PL assumes world contains facts. FOL= PL + predicates, quantifiers, variables, and equality FOL assumes the world contains

  • Objects: things with individual identities

e.g. people, numbers, blocks A, B, C, D

  • Properties: distinguishing objects from others

e.g. red, round, prime, smelly, …

Inter-relations among objects

  • Functions : a special kind of relation in which there is only one

“value” for a given “input.” e.g. father of, best friend, one more than, …

  • Relations

e.g. brother of, bigger than, on(D, A), on(A, Table), …

20070503 Chap8 4

Logics in General

Ontological Commitment:

What it assums about the nature of reality.

Epistemological Commitment:

The possible states of knowledge that it allows wrt each fact.

slide-3
SLIDE 3

3

20070503 Chap8 5

Examples: Conceptualization

  • One plus two equals three
  • Objects: one, two, three, one plus two
  • Function: plus
  • Relation: equals
  • Squares neighboring the wumpus are smelly
  • Objects: wumpus, square
  • Property: smelly
  • Relations: neighboring
  • Evil King John ruled England in 1200
  • Objects: John, England, 1200
  • Properties: evil, king
  • Relations: ruled
  • All NTU students and their parents are smart

20070503 Chap8 6

Models for FOL: Example

5 objects: Richard, John, … 2 binary relations: brother, on head 3 unary relations: person, king, crown 1 unary function: left leg

slide-4
SLIDE 4

4

20070503 Chap8 7

Syntax of FOL

L L K K K K K | LeftLegOf | Mother n Functio | Raining | HasColor | Before Predicate s | x | a Variable John | X | A Constant | Quantifier | | | Connective Variable | Constant | ) erm, Function(T Term Term Term | ) Term, Predicate( Atomic Sentence Variable, Quantifier | Sentence Connective Sentence | Sentence | (Sentence) Complex Complex | Atomic Sentence

1

→ → → → ∃ ∀ → ⇔ ⇒ ∨ ∧ → → = → ¬ → →

20070503 Chap8 8

Semantics of FOL

  • Sentences are true with respect to a model and

an interpretation.

  • Model contains objects and relations among them.
  • Interpretation specifies referents for

constant symbols → objects predicate symbols → relations function symbols → functional relations

  • An atomic sentence

Predicate(Term1, …Termn) is true iff the objects referred to by Term1, …Termn are in the relation referred to by Predicate

slide-5
SLIDE 5

5

20070503 Chap8 9

Sentences and Terms

  • Sentence: represent a fact
  • Atomic sentence: a predicate symbol followed by

a parenthesized list of terms. i.e. Predicate(Term, …)

  • Complex sentence: constructed via logical connectives
  • Quantified sentence: expressing properties of entire

collections of objects, rather than having enumerate the objects by name.

  • Term: represent an object
  • Constant (0-ary function constant)
  • Variable (0-ary function variable)
  • Function(Term, …)

20070503 Chap8 10

Sentences and Terms (cont.)

  • Interpretation:
  • Each constant names exactly one object.
  • Not all objects have names.
  • Some objects have multiple names.
  • A relation is defined as a set of tuples of objects

that satisfy it, e.g. the relation of brotherhood {< King John, Richard the Lionheart>, <Richard the Lionheart, King John>}

  • An n-ary function maps n objects into another object.
slide-6
SLIDE 6

6

20070503 Chap8 11

FOL Examples

  • Wendy is tall.
  • Durante’s nose is big.
  • John loves his dog.
  • John is the brother of Richard and vice versa.

) tall(Wendy ))

  • f(Durante
  • big(nose
  • f(John))
  • dog

, loves(John Richard) hn, Brother(Jo John) chard, Brother(Ri ∧

20070503 Chap8 12

  • All kings are persons.

All the following must be true: (correct) Richard is a king ⇒ Richard is a person.

King John is a king ⇒ King John is a person. Richard’s left leg is a king ⇒ Richard’s left leg is a person. John’s left leg is a king ⇒ John’s left leg is a person. The crown is a king ⇒ The crown is a person.

(wrong) Richard is a king ∧ Richard is a person.

King John is a king ∧ King John is a person. Richard’s left leg is a king ∧ Richard’s left leg is a person. John’s left leg is a king ∧ John’s left leg is a person. The crown is a king ∧ The crown is a person.

wrong correct Persons(x) Kings(x) x Persons(x) Kings(x) x − − − ∧ ∀ − − − ⇒ ∀

FOL Examples (cont.-1)

slide-7
SLIDE 7

7

20070503 Chap8 13

  • King John has a crown on his head.

At least one of the following must be true: (correct) Richard is a crown ∧ Richard is on John’s head.

King John is a crown ∧ King John is on John’s head. Richard’s left leg is a crown ∧ Richard’s left leg is on John’s head. John’s left leg is a crown ∧ John’s left leg is on John’s head. The crown is a crown ∧ The crown is on John’s head.

(wrong) Richard is a crown ⇒ Richard is on John’s head.

King John is a crown ⇒ King John is on John’s head. Richard’s left leg is a crown ⇒ Richard’s left leg is on John’s head John’s left leg is a crown ⇒ John’s left leg is on John’s head. The crown is a crown ⇒ The crown is on John’s head.

wrong John) OnHead(x, Crown(x) x correct John) OnHead(x, Crown(x) x − − − ⇒ ∃ − − − ∧ ∃

FOL Examples (cont.-2)

20070503 Chap8 14

Representing Sentences in FOL

  • One plus two equals three.
  • Squares neighboring the wumpus are smelly.
  • Evil King John ruled England in 1200.
  • Spot is a cat.
  • All cats are mammals.
  • Spot has a sister who is a cat.
  • A person's brother has that person as a sibling.
  • Everybody loves somebody.
  • There is someone who is loved by everyone.
  • Everyone likes ice cream.

There is no one who does not like ice cream.

  • Spot has at least two sisters.
slide-8
SLIDE 8

8

20070503 Chap8 15

Compound Sentences

  • The truth or falsity of a compound sentence s can be

determined from the truth or falsity of the component sentences

  • f s.
  • atoms + logical connectives Predicate Logic
  • Negation
  • f(John))
  • dog

, loves(John ¬

  • Conjunction
  • f(John))
  • country

, loves(John

  • f(John))
  • dog

, loves(John ∧

  • Disjunction

)] ) i i i even( [odd( ∨ ∀

  • Implication
  • f(John))
  • dog

, loves(John

  • f(John))
  • country

, loves(John ⇒

20070503 Chap8 16

Quantification

  • Existential quantification - the sentence is true for some

value(s) of the variable.

  • John loves everything.

x) , loves(John x. ) everything , loves(John ∀

  • Everything loves everything.

y) loves(x, xy. y) loves(x, y. x. ∀ ∀ ∀

  • John loves all fuzzy things.

x) , loves(John fuzzy(x) x. ⇒ ∀

  • All numbers are either odd or even.

even(i)] [odd(i) i ∨ ∀

  • Universal quantification - the sentence remains true for all values
  • f the variable.
  • John loves something.

x) , loves(John x. ∃

slide-9
SLIDE 9

9

20070503 Chap8 17

Quantifiers

  • Quantifiers ∀ and ∃ can be thought of as the infinitary versions
  • f ∧ and ∨ respectively.
  • A sentence holds in a model M

if and only if p(Z) holds for every object Z in the domain of discourse.

  • Similarly, a sentence holds in a model M

if and only if there is some object Z for which p is valid. (Ex1) If a person is the parent of another person, then the other person is the child of the person. (Ex2) Everybody loves somebody. (Ex3) There is someone who is loved by everyone. p(x) x. ∀

x) Child(y, y) Parent(x, y x, ⇒ ∀ y) Loves(x, y x∃ ∀ x) Loves(y, y x∀ ∃

p(x) x. ∃

20070503 Chap8 18

Quantifiers (cont.)

  • de Morgan's Laws

For any two sentences p and q, the following two expressions are equivalent.

  • Similarly, the following two are equivalent.
  • Negation involving quantifiers

q p q) (p ¬ ∨ ¬ ≡ ∧ ¬ q p q) (p ¬ ∧ ¬ ≡ ∨ ¬

P x P x ∃ ¬ ≡ ¬ ∀ P x P x ¬ ∃ ¬ ≡ ∀ P x P x ¬ ∃ ≡ ∀ ¬ P x P x ¬ ∀ ¬ ≡ ∃

slide-10
SLIDE 10

10

20070503 Chap8 19

Compositional Semantics

Given a model M , FOL allows us to determine whether a sentence is true or false relative to an interpretation I and a variable assignment U .

  • The truth/falsity of any atom is defined by M .
  • is true in M iff

is not true in M .

  • is true iff

is true in M and is true in M .

  • is true iff at least one of and is true in M .

φ

φ ¬ φ

2 1

a a ∧

1

a

2

a

2 1

a a ∨

1

a

2

a

20070503 Chap8 20

A common mistake to avoid

  • Typically, ⇒ is the main connective with ∀
  • Common mistake:

using ∧ as the main connective with ∀ e.g. Everyone at NUS is smart. ∀x At(x,NUS) ⇒ Smart(x)

  • -- (O)

∀x At(x,NUS) ∧ Smart(x) --- (X) means “Everyone is at NUS and everyone is smart”

slide-11
SLIDE 11

11

20070503 Chap8 21

A common mistake to avoid

  • Typically, ⇒ is the main connective with ∀
  • Common mistake: using ∧ as the main

connective with ∀ e.g. Everyone at NUS is smart. ∀x At(x,NUS) ⇒ Smart(x)

  • -- (O)

∀x At(x,NUS) ∧ Smart(x) --- (X) means “Everyone is at NUS and everyone is smart”

20070503 Chap8 22

Another common mistake to avoid

  • Typically, ∧ is the main connective with ∃
  • Common mistake:

using ⇒ as the main connective with ∃ e.g. Someone at NUS is smart. ∃x At(x,NUS) ∧ Smart(x)

  • -- (O)

∃x At(x,NUS) ⇒ Smart(x)

  • -- (X)

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

slide-12
SLIDE 12

12

20070503 Chap8 23

Equality

  • Equality: make statements to the effect that

two terms refer to the same object. (Ex1) Spot has at least two sisters. (Ex2)There is exactly one King.

Henry n) Father(Joh = correct

  • y)

(x y) t, Sister(Spo x) t, Sister(Spo y x, wrong

  • y)

t, Sister(Spo x) t, Sister(Spo y x, = ¬ ∧ ∧ ∃ ∧ ∃ King(x) x ! y x King(y) y King(x) x ∃ = ⇒ ∀ ∧ ∃

20070503 Chap8 24

Extensions

  • Higher-order logic
  • quantify over relations and functions

e.g. Two objects are equal if and only if all properties applied to them are equivalent. e.g. Two functions are equal if and only if they have the same value for all arguments.

  • Lambda calculus
  • introduce anonymous functions

e.g.

  • Uniqueness quantifier: ∃!

p(y)) p(x) p ( y) (x y x, ⇔ ∀ ⇔ = ∀

49 24 25 )(25,24) y x y (λλx

2 2 2 2

= − = −

g(x)) f(x) x ( g) (f g f, = ∀ ⇔ = ∀

slide-13
SLIDE 13

13

20070503 Chap8 25

Using First-Order Logic

  • The kinship domain
  • One’s mother is one’s female parent.
  • One’s husband is one’s male spouse.
  • A sibling is another child of one’s parent.

c) Parent(m, Female(m) m Mather(c) c m, ∧ ⇔ = ∀ ) Spouse(h,w Male(h) w) Husband(h, h w, ∧ ⇔ ∀ y) Parent(p, x) Parent(p, p y x y) Sibling(x, y x, ∧ ∃ ∧ ≠ ⇔ ∀

20070503 Chap8 26

Using First-Order Logic(cont.-1)

  • The set domain

Constant: {} Unary predicate: Set Binary predicate: x ∈ s (member) s1 ⊆ s2 (subset) Binary functions: s1 ∩ s2 (intersection) s1 ∪ s2 (union) {x | s} (adjoin) The only sets are empty set and those made by adjoining something to a set. The empty set has no elements adjoined into it. A set is a subset of another if and only if all of the first set’s members are members of the second set.

}) s2 {x s Set(s2) s2 x, ( {}) (s Set(s) s = ∧ ∃ ∨ = ⇔ ∀ s2) x s1 x x ( s2 s1 s2 s1, ∈ ⇒ ∈ ∀ ⇔ ⊆ ∀ {} } s {x s x, = ¬∃

slide-14
SLIDE 14

14

20070503 Chap8 27

Interacting with FOL KB

Suppose a wumpus-world agent is using an FOL KB And perceives a stench and a breeze , glitter at t = 5

Tell(KB, percept([Stench, Breeze, Glitter, None, None], 5)) Ask(KB, ∃ a BestAction(a, 5))

Does the KB entail any particular actions at t = 5? Answer: Yes, {a/grab}

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

20070503 Chap8 28

KB for the Wumpus World

  • Percept

∀t, s, g ,m, c Percept([s, Breeze, g, m, c], t) ⇒ Breeze(t) ∀t, s, b ,m, c Percept([s, b, Glitter, m, c], t) ⇒ Glitter(t)

  • Reflex

∀t Glitter(t) ⇒ BestAction(Grab, t)

  • Environment

∀x , y, a, b Adjacent([x,y], [a,b]) ⇔ [a,b] ∈{[x+1, y], [x-1, y], [x, y+1] [x, y-1]}

  • Properties of locations

∀s, t At(Agent, s, t) ∧ Breeze(t) ⇒ Breezy(s)

slide-15
SLIDE 15

15

20070503 Chap8 29

KB for the Wumpus World (cont.)

  • Locations are breezy near a pit.
  • Diagnostic rules (infer cause from effect)

∀s Breezy(s) ⇔ ∃r Adjacent(r, s) ∧ Pit(r)

  • Causal rules (infer effect from cause)

∀r Pit(r) ⇒ [∀s Adjacent(r, s) ⇒ Breezy(s)]

∀s [∀r Adjacent(r, s) ⇒ ¬ Pit(r) ] ⇒ ¬ Breezy(s)

20070503 Chap8 30

Knowledge Engineering in FOL

1. Identify the task 2. Assemble the relevant knowledge 3. Decide on a vocabulary of predicates, functions, and constants 4. Encode general knowledge about the domain 5. Encode a description of the specific problem instance 6. Pose queries to the inference procedure and get answers 7. Debug the knowledge base

slide-16
SLIDE 16

16

20070503 Chap8 31

The Electronic Circuits Domain

One-bit full adder

20070503 Chap8 32

  • Identify the task

Does the circuit actually add properly? (circuit verification)

  • Assemble the relevant knowledge

Composed of wires and gates; Types of gates (AND, OR, XOR, NOT) Connections between terminals Irrelevant: size, shape, color, cost of gates

  • Decide on a vocabulary

Alternatives: Type(X1) = XOR Type(X1, XOR) XOR(X1)

The Electronic Circuits Domain (cont.-1)

slide-17
SLIDE 17

17

20070503 Chap8 33

The Electronic Circuits Domain (cont.-2)

Encode general knowledge of the domain

  • ∀t1,t2 Connected(t1, t2) ⇒ Signal(t1) = Signal(t2)
  • ∀t Signal(t) = 1 ∨ Signal(t) = 0
  • 1 ≠ 0
  • ∀t1,t2 Connected(t1, t2) ⇒ Connected(t2, t1)
  • ∀g Type(g) = OR

⇒ Signal(Out(1,g)) = 1 ⇔ ∃n Signal(In(n,g)) = 1

  • ∀g Type(g) = AND

⇒ Signal(Out(1,g)) = 0 ⇔ ∃n Signal(In(n,g)) = 0

  • ∀g Type(g) = XOR

⇒ Signal(Out(1,g)) = 1 ⇔ Signal(In(1,g)) ≠ Signal(In(2,g))

  • ∀g Type(g) = NOT

⇒ Signal(Out(1,g)) ≠ Signal(In(1,g))

20070503 Chap8 34

The Electronic Circuits Domain (cont.-3)

Encode the specific problem instance

Type(X1) = XOR Type(X2) = XOR Type(A1) = AND Type(A2) = AND Type(O1) = OR Connected(Out(1,X1),In(1,X2)) Connected(In(1,C1),In(1,X1)) Connected(Out(1,X1),In(2,A2)) Connected(In(1,C1),In(1,A1)) Connected(Out(1,A2),In(1,O1)) Connected(In(2,C1),In(2,X1)) Connected(Out(1,A1),In(2,O1)) Connected(In(2,C1),In(2,A1)) Connected(Out(1,X2),Out(1,C1)) Connected(In(3,C1),In(2,X2)) Connected(Out(1,O1),Out(2,C1)) Connected(In(3,C1),In(1,A2))

slide-18
SLIDE 18

18

20070503 Chap8 35

The Electronic Circuits Domain (cont.-4)

Pose queries to the inference procedure

What are the possible sets of values of all the terminals for the adder circuit?

∃i1,i2,i3,o1,o2 Signal(In(1,C_1)) = i1 ∧ Signal(In(2,C1)) = i2 ∧ Signal(In(3,C1)) = i3 ∧ Signal(Out(1,C1)) = o1 ∧ Signal(Out(2,C1)) = o2

Debug the knowledge base

May have omitted assertions like 1 ≠

20070503 Chap8 36

Summary

  • First-order logic:
  • bjects and relations are semantic

primitives

  • syntax: constants, functions, predicates,

equality, quantifiers

  • Increased expressive power

sufficient to define wumpus world