0% found this document useful (0 votes)
6 views

Module 4

Module 4 discusses First-Order Logic (FOL) and its application in representing knowledge about objects and their relationships. It covers the syntax and semantics of FOL, inference methods such as unification and chaining, and the use of quantifiers to express properties of collections of objects. The module also highlights the differences between propositional and first-order logic, emphasizing FOL's greater expressiveness for complex reasoning tasks.

Uploaded by

h13584962
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Module 4

Module 4 discusses First-Order Logic (FOL) and its application in representing knowledge about objects and their relationships. It covers the syntax and semantics of FOL, inference methods such as unification and chaining, and the use of quantifiers to express properties of collections of objects. The module also highlights the differences between propositional and first-order logic, emphasizing FOL's greater expressiveness for complex reasoning tasks.

Uploaded by

h13584962
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 94

BAD402-Module 4

FIRST-ORDER LOGIC AND


INFERENCE IN FIRST ORDER
LOGIC

The world is blessed with many objects, some of which are related to other objects, and
in which we endeavor to reason about them.

1
Module 4-Contents
First Order Logic
• Representation Revisited
• Syntax and Semantics of First Order logic
• Using First Order logic.

Inference in First Order Logic


• Propositional Versus First Order Inference
• Unification, Forward Chaining
• Backward Chaining
• Resolution

2
FIRST-ORDER LOGIC
• Propositional logic is too puny a language to represent
knowledge of complex environments in a concise way.

• First-order logic, which is sufficiently expressive to represent a good deal


of our commonsense knowledge.
o Representation languages in general
o The syntax and semantics of first-order logic.
o Illustrate the use of first-order logic for simple representations

3
REPRESENTATION REVISITED
The development of first-order logic, a much more expressive language
than the propositional logic
1. The language of thought
• Data Structure using programming languages- “There is a pit in [2,2] or [3,1]”.
• Propositional Logic- B1,1 ⇔ (P1,2 ∨ P2,1).
• First Order Logic- CNF - “¬(A ∨ B)” and “¬A ∧ ¬B”.
2. Combining the best of formal and natural languages
Syntax of natural language
• Object- nouns and noun phrases (squares, pits, wumpuses)
• Relation- verbs and verb phrases (is breezy, is adjacent to, shoots)
• Functions- relations in which there is only one “value” for a given “input.”

4
Examples:

• Objects: people, houses, numbers, theories, Ronald McDonald, colors, baseball games,
wars, centuries ...
• Relations: these can be unary relations or properties such as red, round, bogus, prime,
multistoried .. ., or
more general n-ary relations such as brother of, bigger than, inside, part of, has color,
occurred after, owns, comes between, ...
• Functions: father of, best friend, third inning of, one more than, beginning of ...
• “One plus two equals three.”
• “Evil King John ruled England in 1200.”
Objects: one, two, three, one plus two;
Relation: equals; Objects: John, England, 1200;
Function: plus. Relation: ruled;
Properties: evil, king.
• “Squares neighboring the wumpus are smelly.”
Objects: wumpus, squares;
Property: smelly;
Relation: neighboring.
5
Language Ontological Commitment Epistemological Commitment
(What exists in the world) (What an agent believes about facts)
Propositional logic facts true/false/unknown
First-order logic facts, objects, relations true/false/unknown
Temporal logic facts, objects, relations, times true/false/unknown
Probability theory facts degree of belief ∈ [0, 1]
Fuzzy logic facts with degree of truth ∈ [0, 1] known interval value

Figure 8.1 Formal languages and their ontological and epistemological commitments.

6
SYNTAX AND SEMANTICS OF FIRST-ORDER LOGIC
First-order logic reflect the ontological commitment to objects and relations

1. Models for first-order logic

• The domain of a model is the set of objects


• The domain is required to be nonempty—every possible world must contain at
least one object.

7
A model with five
objects:
1. Richard the Lionheart,
King of England from
1189 to 1199;
2. His younger brother,
the evil King John,
who ruled from 1199
to 1215;
3. The left legs of
Richard
4. The left legs of John;
and
5. A crown.
8
A relation is just the set of tuples of objects that are related,
the brotherhood relation in this model is the set
{ (Richard the Lionheart, King John), (King John, Richard the Lionheart)}
• The crown is on King John’s head, so the “on head” relation contains just one tuple, (the
crown, King John).
• The “brother” and “on head” relations are binary relations—that is, they relate pairs of
objects.
Unary Relations
• The “person” property is true of both Richard and John;
• The “king” property is true only of John
• The “crown” property is true only of the crown.
A unary function - “left leg”
(Richard the Lionheart)→ Richard’s left leg
(King John)→ John’s left leg .

Strictly speaking, models in first-order logic require total functions, that is, there
must be a value for every input tuple.
9
2. Symbols and interpretations
First-order logic are the symbols that stand for objects, relations, and functions.

Three kinds of Symbols:


• Constant symbols, which stand for objects;
Example: Richard and John
• Predicate symbols, which stand for relations;
Example: Brother , OnHead , Person, King, and Crown
• Function symbols, which stand for functions.
Example: LeftLeg

Each model includes an interpretation that specifies exactly which objects, relations
and functions are referred to by the constant, predicate, and function symbols.

10
11
12
13
3. Terms
A term is a logical expression that refers to an object.
A term f (t1,... , tn),
• f refers to some function in the model (call it F ) ,
• The argument terms refer to objects in the domain (call them d1,... , dn)
• Example: LeftLeg (John ) refers to King John’s left leg.

14
4. Atomic sentences

An atomic sentence (or atom for short) is formed from a predicate


symbol optionally followed by a parenthesized list of terms.

Intended interpretation - Brother (Richard , John).

Atomic sentences can have complex terms as arguments


Length(LeftLeg(KingJohn))

15
5. Complex sentences

Use logical connectives to construct more complex sentences


• ¬Brother (LeftLeg (Richard ), John )
• Brother (Richard , John) ∧ Brother (John, Richard )
• King(Richard ) ∨ King(John)
• ¬King(Richard ) ⇒ King(John)

16
6. Quantifiers
To express properties of entire collections of objects, instead of enumerating
the objects by name.
Two standard quantifiers are:
1. Universal quantification (∀)
2. Existential quantification (∃)
• Nested quantifiers
• Connections between ∀ and ∃

17
i. Universal quantification (∀)

• “All kings are persons”


• ∀ x King(x) ⇒ Person(x) . “For all x, if x is a king, then x is a person.”
• The symbol x is called a variable.
• A term with no variables is called a ground term.
• ∀ x P is true in a given model- if P is true in all possible extended
interpretations constructed from the interpretation given in the model,
• where each extended interpretation specifies a domain element to
which x refers.

18
The interpretation in five ways:
x → Richard the Lionheart,
x → King John,
x → Richard’s left leg,
x → John’s left leg,
x → the crown.
The universally quantified sentence ∀ x King(x) ⇒ Person(x) is true in
the original model
if the sentence King(x) ⇒ Person(x) is true under each of the five
extended interpretations.

19
The universally quantified sentence is equivalent to asserting the following five
sentences:
• Richard the Lionheart is a king ⇒ Richard the Lionheart 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.
⇒ turns out to be perfect for writing general rules with universal quantifiers.

A common mistake to use conjunction instead of implication


∀ x King(x) ∧ Person(x)
King John is a king ∧ King John is a person
20
ii. Existential quantification
(∃)
A statement about some object in the universe without naming it, by using an existential
quantifier.
Example:
• King John has a crown on his head
• ∃ x Crown (x) ∧ OnHead (x, John)
• ∃x is pronounced “There exists an x such that .. .” or “For some x.. .”.
• The sentence ∃ x P says that P is true for at least one object x.
• ∃ x P is true in a given model if P is true in at least one extended interpretation that assigns x
to a domain element.
At least one of the following is true:
• Richard the Lionheart is a crown ∧ Richard the Lionheart 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. 21
Using ⇒ with ∃ usually leads to a very weak statement.
Consider the following sentence:
∃ x Crown (x) ⇒ OnHead (x, John )

At least one of the following assertions is true:


Richard the Lionheart is a crown ⇒ Richard the Lionheart 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;
and so on…

22
Nested quantifiers

• To express more complex sentences using multiple quantifiers


For example, “Brothers are siblings” can be written as
∀ x ∀ y Brother (x, y) ⇒ Sibling (x, y)
• quantifiers of the same type can be written as one quantifier with several variables.
For example, to say that siblinghood is a symmetric relationship
∀ x, y Sibling (x, y) ⇔ Sibling (y, x)
• “Everybody likes somebody” means that for every person, there is someone that
person likes:
∀ x ∃ y Likes(x, y)
• “There is someone who is liked by everyone,”
∃ y ∀ x Likes(x, y)
• use different variable names with nested quantifiers

23
Some confusion can arise when two quantifiers are used with the same variable
name.
∀ x (Crown (x) ∨ (∃ x Brother (Richard , x)))
Here the x in Brother (Richard , x) is existentially quantified.

Another way to think of it is this:


∃ x Brother (Richard , x) is a sentence about Richard (that he has a brother), not
about x; so putting a ∀ x outside it has no effect

24
Connections between ∀ and ∃
The two quantifiers are actually intimately connected with each other, through negation.
• Asserting that everyone dislikes parsnips is the same as asserting there does not exist
someone who likes them, and vice versa:
• ∀ x ¬Likes(x, Parsnips ) is equivalent to ¬∃ x Likes(x, Parsnips )
• “Everyone likes ice cream” means that there is no one who does not like ice cream:
∀ x Likes(x, IceCream) is equivalent to ¬∃ x ¬Likes(x, IceCream)
Because ∀ is really a conjunction over the universe of objects and ∃ is a disjunction

The De Morgan rules for quantified and unquantified sentences are as follows:

∀ x ¬P ≡ ¬∃ x P ¬(P ∨ Q) ≡ ¬P ∧ ¬Q
¬∀ x P ≡ ∃ x ¬P ¬(P ∧ Q) ≡ ¬P ∨ ¬Q
∀ x P ≡ ¬∃ x ¬P P ∧ Q ≡ ¬(¬P ∨ ¬Q)
∃ x P ≡ ¬∀ x ¬P P ∨ Q ≡ ¬(¬P ∧ ¬Q) .

25
Equality
• The equality symbol to signify that two terms refer to the same
object. For example,
Father (John)= Henry
• The object referred to by Father (John) and the object referred to
by Henry are the same
• It can also be used with negation to insist that two terms are not
the same object. To say that Richard has at least two brothers
∃ x, y Brother (x, Richard ) ∧ Brother (y, Richard ) ∧ ¬(x = y)
• The sentence ∃ x, y Brother (x, Richard ) ∧ Brother (y, Richard )
does not have the intended meaning.

26
8. An alternative semantics?

Suppose that we believe that Richard has two brothers, John and Geoffrey
Assert Brother (John, Richard ) ∧ Brother (Geoffrey , Richard ) ? Not quite

1. This assertion is true in a model where Richard has only one brother—we need to
add John != Geoffrey .
2. The sentence doesn’t rule out models in which Richard has many more brothers
besides John and Geoffrey.
3. The correct translation of “Richard’s brothers are John and Geoffrey” is as follows:
Brother (John, Richard ) ∧ Brother (Geoffrey , Richard ) ∧ John ≠ Geoffrey ∧
∀ x Brother (x, Richard ) ⇒ (x = John ∨ x = Geoffrey )

27
Database Semantics
One proposal that is very popular in database systems works as
follows.
• First, we insist that every constant symbol refer to a distinct object—
the so-called unique-names assumption.
• Second, we assume that atomic sentences not known to be true are in
fact false—the closed-world assumption.
• Finally, we invoke domain closure, meaning that each model
contains no more domain elements than those named by the
constant symbols.

28
USING FIRST-ORDER LOGIC
• TELL/ASK interface for first-order knowledge bases
• The domains of family relationships, numbers, sets, and lists, and at the wumpus
world.
1. Assertions and queries in first-order logic
Sentences are added to a knowledge base using TELL, exactly as in propositional logic.
Such sentences are called assertions.
For example: Assert that John is a king, Richard is a person, and all kings are
persons:
• TELL(KB, King(John )) .
• TELL(KB, Person(Richard )) .
• TELL(KB, ∀ x King(x) ⇒ Person(x))

Ask questions of the knowledge base using ASK.


For example, ASK(KB, King(John )) returns true.
Questions asked with ASK are called queries or goals.
29
• ASK(KB, Person(John ))
• ASK(KB, ∃ x Person(x)) .
“Can you tell me the time?” with “Yes.”
If we want to know what value of x makes the sentence true
a different function, ASKVARS
• ASKVARS(KB, Person(x))……… yields a stream of answers.
• There will be two answers: {x/John} and {x/Richard }
Such an answer is called a substitution or binding list.

Knowledge Bases
Every way of making the query true will bind the variables to specific values.

First-order logic

if KB has been told King(John) ∨ King(Richard ), then there is no binding to x - ∃ x King(x)


30
2. The kinship domain
The domain of family relationships, or kinship.
Elizabeth is the mother of Charles” and “Charles is the father of William.

“One’s grandmother is the mother of one’s parent.”

The objects in this domain are people.


Two unary predicates, Male and Female
Kinship relations—parenthood, brotherhood, and so on.
Binary predicates: Parent , Sibling , Brother , Sister , Child , Daughter , Son etc.

one’s mother is one’s female parent:


∀ m, c Mother (c)= m ⇔ Female (m) ∧ Parent(m, c) .

Male and female are disjoint categories:


∀ x Male(x) ⇔ ¬Female(x) .
31
Parent and child are inverse relations:
• ∀ p, c Parent(p, c) ⇔ Child (c, p) .
A grandparent is a parent of one’s parent:
• ∀ g, c Grandparent (g, c) ⇔ ∃ p Parent (g, p) ∧ Parent(p, c) .
A sibling is another child of one’s parents:
• ∀ x, y Sibling (x, y) ⇔ x /= y ∧∃ p Parent (p, x) ∧ Parent(p, y) .

Kinship axioms are defined as


∀ x, y P (x, y) ⇔ …………

Not all logical sentences about a domain are axioms. Some are theorems
entailed by the axioms.
∀ x, y Sibling(x, y) ⇔ Sibling(y, x) .
32
Not all axioms are definitions
predicates have no complete definition
∀ x Person(x) ⇔ . . .

partial specifications of properties


∀ x Person(x) ⇒ . . .
∀x . . . ⇒ Person(x) .

Axioms can also be “just plain facts,”


Male(Jim)
Sibling(Jim, Aana)

33
3. Numbers, sets, and lists

The theory of natural numbers or non-negative integers.

Required
• A predicate NatNum that will be true of natural numbers.
• One constant symbol, 0; and
• One function symbol, S (successor).
• 0 is a natural number, and for every object n,
• if n is a natural number, then S(n) is a natural number.
• The natural numbers are 0, S(0), S(S(0)), and so on
• axioms to constrain the successor function
∀ n 0 ≠ S(n) .
∀ m, n m ≠ n ⇒ S(m) ≠ S(n) .

34
Addition in terms of the successor function: (0-zero)
∀ m NatNum(m) ⇒ + (0, m) = m
∀ m, n NatNum(m) ∧ NatNum(n) ⇒ + (S(m), n) = S(+(m, n))
write S(n) as n + 1
∀ m, n NatNum(m) ∧ NatNum(n) ⇒ (m + 1)+ n = (m + n)+ 1 .
• The use of infix notation is an example of syntactic sugar, that is, an extension to
or abbreviation of the standard syntax that does not change the semantics.
• Addition, it is straightforward to define multiplication as repeated addition,
exponentiation as repeated multiplication, integer division and remainders, prime
numbers, and so on.

35
Sets
The domain of sets is also fundamental to mathematics as well as to commonsense
reasoning.
• Normal vocabulary of set theory as syntactic sugar.
• Empty set { }.
• One unary predicate, Set, which is true of sets.
• The binary predicates are x ∈ s (x is a member of set s) and s1 ⊆ s2 (set s1 is a subset, not
necessarily proper, of set s2).
• The binary functions are s1 ∩ s2 (the intersection of two sets), s1 ∪ s2 (the union of two
sets), and {x|s} (the set resulting from adjoining element x to set s).

36
Possible set of axioms is as follows:
• The only sets are the empty set and those made by adjoining something to a set:
∀ s Set(s) ⇔ (s = { }) ∨ (∃ x, s2 Set (s2) ∧ s = {x|s2})
• The empty set has no elements adjoined into it. In other words, there is no way to
decompose {} into a smaller set and an element:
¬∃ x, s {x|s} = {}
• Adjoining an element already in the set has no effect:
∀ x, s x ∈ s ⇔ s = {x|s}
• Say that x is a member of s if and only if s is equal to some set s2 adjoined with some
element y, where either y is the same as x or x is a member of s2:
∀ x, s x ∈ s ⇔ ∃ y, s2 (s = {y|s2}∧ (x = y ∨ x ∈ s2)) .

37
• A set is a subset of another set if and only if all of the first set’s members are
members of the second set:
∀ s1, s2 s1 ⊆ s2 ⇔ (∀ x x ∈ s1 ⇒ x ∈ s2) .
• Two sets are equal if and only if each is a subset of the other:
∀ s1, s2 (s1 = s2) ⇔ (s1 ⊆ s2 ∧ s2 ⊆ s1) .

38
Lists are similar to sets. The differences are that lists are ordered and the same element
can appear more than once in a list
• List ? is a predicate that is true only of lists.
• lists: Nil is the constant list with no elements;
• Cons , Append , First , and Rest are functions; and
• Find is the predicate that does for lists what Member does for sets.

• Cons(x, y), where y is a nonempty list, is written [x|y]


• Cons(x, Nil ) (i.e., the list containing the element x) is written as [x]
• Nested term Cons(A, Cons (B, Cons (C, Nil )))

39
The wumpus world
• Wumpus agent receives a percept vector with five elements:
Percept ([Stench, Breeze, Glitter , None, None], 5)
• The actions in the wumpus world can be represented by logical terms:
Turn(Right), Turn(Left ), Forward , Shoot , Grab, Climb.
• To determine which is best, the agent program executes the query
ASKVARS(∃ a BestAction(a, 5))---------returns a binding list such as {a/Grab }.
• The raw percept data implies certain facts about the current state
example:
∀ 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) ,…….
• These rules exhibit a trivial form of the reasoning process called perception
• Simple “reflex” behavior can also be implemented by quantified implication sentences.
Example: ∀ t Glitter (t) ⇒ BestAction(Grab, t)

40
• To represent the environment itself
Adjacency of any two squares can be defined as
∀ x, y, a, b Adjacent([x, y], [a, b]) ⇔
(x = a ∧ (y = b − 1 ∨ y = b + 1)) ∨ (y = b ∧ (x = a − 1 ∨ x = a + 1))

• The agent’s location changes over time


At(Agent , s, t) to mean that the agent is at square s at time t
• Fix the wumpus’s location with ∀t At(Wumpus, [2, 2], t)
• objects can only be at one location at a time
∀ x, s1, s2,t At(x, s1, t) ∧ At(x, s2, t) ⇒ s1 = s2
• If the agent is at a square and perceives a breeze, then that square is breezy
∀ s, t At(Agent , s, t) ∧ Breeze(t) ⇒ Breezy (s)
• First-order logic just needs one axiom to deduce where the pits are :
∀ s Breezy (s) ⇔ ∃ r Adjacent (r, s) ∧ Pit(r)
• The axiom for the arrow
∀ t HaveArrow (t + 1) ⇔ (HaveArrow (t) ∧ ¬Action(Shoot , t)) 41
INFERENCE IN FIRST-ORDER LOGIC
To define effective procedures for answering questions posed in first- order logic

● Propositional Vs. First-order Inference


• Reducing first-order inference to propositional inference
● Unification and Lifting
• A first-order inference rule
• Generalized Modus Ponens
• Unification
• Storage and retrieval
● Forward chaining
● Backward chaining
• Logic programming
● Resolution

42
PROPOSITIONAL VS. FIRST-ORDER INFERENCE
First-order inference can be done by converting the knowledge base to propositional
logic and using propositional inference

Inference rules for quantifiers

43
Universal
● Every instantiation ofInstantiation
a universally quantified sentence is entailed by it:

∀v α
SUBST({v/g}, α)

for any variable v and ground term g

● E.g., ∀ x K i n g ( x ) ∧ Greedy(x) =⇒ E v i l ( x ) yields

K i n g ( J o h n ) ∧ Greedy(John) =⇒ E v i l ( J o h n )
K i n g ( R i c h a r d ) ∧ Greedy(Richard) =⇒
Ev i l ( R ich a r d )
K i n g ( Fa t h e r ( J o h n ) ) ∧ Greedy(Father (John)) =⇒
Ev i l ( Fa t h e r ( J o h n ) )
⋮ 44
Existential
Instantiation
● For any sentence α, variable v, and constant symbol k
that does not appear elsewhere in the knowledge base:
∃v

α
SUBST(Iv/k}, α)

● E.g., ∃ x C r o w n ( x ) ∧ OnHead(x, J o h n ) yields

C r ow n ( C 1 ) ∧ OnHead(C 1 , J o h n )
provided C 1 is a new constant symbol, called a Skolem constant

45
Reduction to Propositional
Inference
● Claim: a ground sentence is entailed by new KB iff entailed by original KB

● Claim: every FOL KB can be propositionalized so as to preserve entailment


● Idea: propositionalize KB and query, apply resolution, return result
● Problem: with function symbols, there are infinitely many ground terms,
e.g., Father (Father (Father (John)))
● Theorem: Herbrand (1930). If a sentence α is entailed by an FOL KB,
it is entailed by a finite subset of the propositional 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, loops if α is not entailed
● Theorem: Turing (1936), Church (1936), entailment in FOL is
semidecidable 46
Practical Problems with
Propositionalization
● Propositionalization seems to generate lots of irrelevant sentences.

● E.g., from ∀ x K i n g ( x ) ∧ Greedy(x) =⇒


Evil(x) King(John)
∀ y Greedy(y)
Brother(Richard,
John)
it seems obvious that Ev i l ( J o h n ) , but propositionalization produces lots of facts
such as Greedy(Richard) that are irrelevant

● With p k-ary predicates and n constants, there are p ⋅ n k instantiations

● With function symbols, it gets nuch much worse!


47
UNIFICATION AND LIFTING
A first-order inference rule
● We have the inference rule
– ∀ x K i n g ( x ) ∧ Greedy(x) ⇒ E v i l ( x )

● We have facts that (partially) match the precondition


– King(John)
– ∀ y Greedy(y)

● We need to match them up with substitutions: θ = {x/John, y/John}


works
– unification
– generalized modus ponens

48
Unification

● UNIFY(p, q) = θ if pθ =

θ
p s(John,
Know x) K n o w s ( J o h n , J ane )
Knows(John, x) Knows (y, M a r y )
q s(John,
Know x) Knows (y, Mother(y))
Knows(John, x) Knows(x, Mary)

49
Unification

● UNIFY(p, q) = θ if pθ =

θ
p s(John,
Know x) K n o w s ( J o h n , J ane ) { x/ J ane }
Knows(John, x) Knows (y, M a r y )
q s(John,
Know x) Knows (y, Mother(y))
Knows(John, x) Knows(x, Mary)

50
Unification

● UNIFY(p, q) = θ if pθ =

θ
p s(John,
Know x) K n o w s ( J o h n , J ane ) {x/ J ane }
Knows(John, x) Knows (y, M a r y ) {x/Mary, y/John}
q s(John,
Know x) Knows (y, Mother(y)) {y/John,
Knows(John, x) Knows(x, Mary) x/Mother(John)}

51
Unification

● UNIFY(p, q) = θ if pθ =

θ
p s(John,
Know x) K n o w s ( J o h n , J ane ) {x/ J ane }
Knows(John, x) Knows (y, M a r y ) {x/Mary, y/John}
q s(John,
Know x) Knows (y, Mother(y)) {y/John,
Knows(John, x) Knows(x, Mary) x/Mother(John)} fa i l

● Standardizing apart eliminates overlap of variables, e.g., Knows(z 1 7 , M a r y )

Kn o w s ( J o h n , x ) Knows(z 1 7 , M a r y ) {z 1 7 /John, x/Mary}

52
Generalized Modus
● Generalized modus Ponens
ponens used with KB of definite clauses
(exactly one positive literal)

● All variables assumed universally quantified

p 1′, p2′, . . . , p n ′ , (p 1 ∧ p2 ∧ . . . ∧ p n ⇒ q)
where p i ′ θ = piθ for all i

● Rule: K i n g ( x ) ∧ Greedy(x) ⇒ E v i l ( x )
● Precondition of rule: p1 is K i n g ( x ) p2 is Greedy(x)
● Implication: q is E v i l ( x )
● Facts: p1′ is p2′ is Greedy(y)
● Substitution: θK iis
n g{x/John,
( J o h n ) y/John}

⇒ Result of modus ponens: qθ is E v i l ( J o h n )


53
54
Storage and retrieval

• TELL and ASK functions used to inform


• Interrogate a knowledge base are the more primitive STORE and FETCH functions.
• STORE(s) stores a sentence s into the knowledge base
• FETCH(q) returns all unifiers such that the query q unifies with some sentence in
the knowledge base.
Example: unify with Knows (John, x)—is an instance of FETCHing

55
FORWARD CHAINING
1. First-order definite clauses

• The following are first-order definite clauses:


King (x) ∧ Greedy (x) ⇒ Evil (x) .
King (John ) .
Greedy (y) .
• first-order literals can include variables, in which case those variables
are assumed to be universally quantified.

56
Example
Knowledge
The law says that it is a crime for an American to sell
weapons to hostile nations. The country Nono, an enemy
of America, has some missiles, and all of its missiles were
sold to it by Colonel West, who is American.

Prove that Colonel West is a criminal

57
Example Knowledge
American(x) ∧ Base
● . . . it is a crime for an American to sell weapons to hostile nations:
Weapon(y) ∧ Sells (x, y, z ) ∧ Hosti le(z) ⇒ C r i m i n a l ( x )
● Nono . . . has some missiles, i.e., ∃ x Owns(Nono, x ) ∧ Missile (x):
Owns(Nono, M 1 ) and Missile (M 1 )
● . . . all of its missiles were sold to it by Colonel West
∀ x M i s s i l e ( x ) ∧ Owns(Nono, x ) ⇒ Sells(West, x, Nono)
● Missiles are weapons:
M i s s i l e ( x ) ⇒ Weapon(x)
● An enemy of America counts as “hostile”:
En e my ( x , America) ⇒ Hosti le(x)
● West, who is American . . .
American(West)
● The country Nono, an enemy of America . . .
Enemy(Nono, America)
58
59
60
61
62
Forward Chaining
Algorithm

63
Hard Matching
Example
Diff(wa, nt) ∧ Diff(wa, sa) ∧
Diff(nt, q)Diff(nt, sa) ∧
Diff(q, nsw) ∧ Diff(q, sa) ∧
Diff(nsw, v) ∧ Diff(nsw, sa)
∧ Diff(v, sa) =⇒
Colorable()
Diff(Red, Blue) Diff(Red, Green)
Diff(Green, Diff(Green,
Red) Diff(Blue, Blue )
Red) Diff(Blue, Green)

● Colorable() is inferred iff the constraint satisfaction problem has a solution

● CSPs include 3SAT as a special case, hence matching is NP-hard


64
Backward
Chaining

● Start with query

● Check if it can be derived by given rules and facts


– apply rules that infer the query
– recurse over pre-conditions

65
66
67
68
69
70
71
72
73
74
Logic programming
• Prolog is by far the most widely used logic programming
language.
• Prolog programs are sets of definite clauses written in a notation
different from standard first-order logic.
• Prolog uses uppercase letters for variables and lowercase for
constants.
• Clauses are written with the head preceding the body; " : -" is
used for left implication, commas separate literals in the body,
and a period marks the end of a sentence
criminal(X) :- american(X), weapon(Y), sells(X,Y,Z), hostile(Z).

75
Prolog program for append (X, Y, Z), which succeeds if list Z is the result of
appending lists x and Y

append([],X,Y).
append([A|X],Y,[A|Z]) :- append(X,Y,Z).

For example, we can ask the query append(X,Y,[1,2]): what two lists can be
appended to give [1,2]? We get back the solutions
X=[] Y=[1,2];
X=[1] Y=[2];
X=[1,2] Y=[]

76
The execution of Prolog programs is done via depth-first backward chaining
• Prolog allows a form of negation called negation as failure. A negated goal not P
is considered proved if the system fails to prove p. Thus, the sentence
• Alive (X) : - not dead(X) can be read as "Everyone is alive if not provably dead."
• Prolog has an equality operator, =, but it lacks the full power of logical equality.
• An equality goal succeeds if the two terms are unifiable and fails otherwise.
• So X+Y=2+3 succeeds with x bound to 2 and Y bound to 3, but
Morningstar=evening star fails.
• The occur check is omitted from Prolog's unification algorithm.

77
Redundant inference and infinite loops:
Consider the following logic program that decides if a path exists between two points on
a directed graph.
path(A,B) :- link(A,B).
path(A,B) :- path(A,B), link(A,B).

78
79
Database semantics of Prolog

Prolog assertions about some course offerings:


Course (CS , 101), Course (CS , 102), Course (CS , 106),
Course(EE , 101)

In FOL, we would get this:


Course (d, n) ⇔ (d = CS ∧ n = 101) ∨ (d = CS ∧ n =
102)
∨ (d = CS ∧ n = 106) ∨ (d = EE ∧ n = 101) .

80
Constraint logic programming

• The Constraint Satisfaction problem can be solved in prolog as same like


backtracking algorithm.
• Because it works only for finite domain CSP’s in prolog terms there must be finite
number of solutions for any goal with unbound variables.

triangle(X,Y,Z) :-
X>0, Y>0, Z>0, X+Y>=Z, Y+Z>=X, X+Z>=Y.

If we have a query, triangle (3, 4, and 5) works fine but the query like,
triangle (3, 4, Z) no solution.

81
Resolution
As in the propositional case, first-order resolution requires that sentences be in
conjunctive normal form (CNF) that is, a conjunction of clauses, where each
clause is a disjunction of literals.

∀ x American(x) ∧ Weapon (y) ∧ Sells(x, y, z) ∧ Hostile(z)


⇒ Criminal (x)
becomes, in CNF,
¬American(x) ∨ ¬Weapon (y) ∨ ¬Sells(x, y, z) ∨
¬Hostile(z) ∨
Criminal (x) .
82
Conversion to
CNF
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: p ⇒q ≡ ¬p ∨ q

∀ 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)]
83
Conversion to
CNF
3. Standardize variables: each quantifier should use a different one

∀ x [∃ y Animal (y) ∧ ¬Loves(x, y)] ∨ [∃ z Loves(z, x)]

4. Skolemize: a more general form of existential instantiation.


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

∀ x [ A n im a l ( F ( x ) ) ∧ ¬Loves(x, F ( x ) ) ] ∨
Loves (G(x), x )

5. Drop universal quantifiers:

[ A n ima l ( F ( x ) ) ∧ ¬Loves(x, F ( x ) ) ] ∨ Loves (G(x), x )

6. Distribute ∧ over ∨:

[ A n ima l ( F ( x ) ) ∨ Loves (G(x), x ) ] ∧ [¬Loves(x, F ( x ) ) 84


● Rules
Our Previous

Example
– American(x) ∧ Weapon(y) ∧ Sells (x, y, z ) ∧ Hosti le(z) ⇒ C r i m i n a l ( x )
Mis sile ( M 1 ) and Owns(Nono, M 1 )
– ∀ x M i s s i l e ( x ) ∧ Owns(Nono, x ) ⇒ Sells(West, x, Nono)
– M i s s i l e ( x ) ⇒ Weapon(x)
– En e my ( x , America) ⇒ Hosti le(x)
– American(West)
– Enemy(Nono, America)
● Converted to CNF
– ¬American(x) ∨ ¬Weapon(y) ∨ ¬Sells(x, y, z ) ∨ ¬Hosti le(z) ∨
Criminal(x)
– Mis sile ( M 1 ) and Owns(Nono, M 1 )
– ¬Missile(x) ∨ ¬Owns(Nono, x ) ∨ Sells(West, x, Nono)
– ¬Missile(x) ∨ Weapon(x)
– ¬Enemy(x, America) ∨ Hosti le(x)
– American(West)
– Enemy(Nono, America) 85
Resolution Proof
{x/West}

{x/y}

{y/M1}

{x/M1} {z/Nono}

M i s s i l e ( M 1 ) and
Owns(Nono, M 1 )

{x/Nono}

86
Now we apply the conversion procedure to convert
each sentence to CNF:
A1. Animal(F(x)) ∨ Loves(G(x), x)
A2. ¬ Loves(x, F(x)) ∨ Loves(G(x), x)
B. ¬ Loves(y, x) ∨ ¬ Animal (z) ∨ ¬ Kills(x, z)
C. ¬ Animal(x) ∨ Loves(Jack, x)
D. Kills(Jack, Tuna) ∨ Kills(Curiosity, Tuna)
E. Cat(Tuna)
F. ¬ Cat(x) ∨ Animal (x)
¬ G. ¬ Kills(Curiosity, Tuna)

87
88
Completeness of resolution

89
1. First, we observe that if S is unsatisfiable, then there exists a particular set of ground
instances of the clauses of S such that this set is also unsatisfiable (Herbrand’s theorem).
2. We then appeal to the ground resolution theorem given in Chapter 7, which states that
propositional resolution is complete for ground sentences.
3. We then use a lifting lemma to show that, for any propositional resolution proof using
the set of ground sentences, there is a corresponding first-order resolution proof using
the first-order sentences from which the ground sentences were obtained.

90
Herbrand universe: If S is a set of clauses, then HS, the Herbrand
universe of S, is the set of all ground terms constructable from the
following:
a. The function symbols in S, if any.
b. The constant symbols in S, if any; if none, then the constant
symbol A.
For example, if S contains just the clause ¬ P(x, F(x,A))∨ ¬
Q(x,A)∨R(x,B), then
HS is the following infinite set of ground terms:
{A,B, F(A,A), F(A,B), F(B,A), F(B,B), F(A,F(A,A)), . . .} .

91
Saturation: If S is a set of clauses and P is a set of ground terms, then
P(S), the
saturation of S with respect to P, is the set of all ground clauses
obtained by applying
all possible consistent substitutions of ground terms in P with variables
in S.

92
Herbrand base: The saturation of a set S of clauses with respect to its
Herbrand universe
is called the Herbrand base of S, written as HS(S). For example, if S
contains
solely the clause just given, then HS(S) is the infinite set of clauses
{ ¬ P(A, F(A,A)) ∨ ¬ Q(A,A) ∨ R(A,B),
¬ P(B,F(B,A)) ∨ ¬ Q(B,A) ∨ R(B,B),
¬ P(F(A,A), F(F(A,A),A)) ∨ ¬ Q(F(A,A),A) ∨ R(F(A,A),B),
¬ P(F(A,B), F(F(A,B),A)) ∨ ¬ Q(F(A,B),A) ∨ R(F(A,B),B), . . . }

93
Thank you!

94

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy