0% found this document useful (0 votes)
14 views121 pages

07 Fol

Uploaded by

czf1643605493
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views121 pages

07 Fol

Uploaded by

czf1643605493
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 121

First-Order Logic

Kalev Kask

Read Beforehand: R&N 8, 9.1-9.2, 9.5.1-9.5.3

Based on slides by Profs. Dechter, Lathrop, Ihler


Common Sense Reasoning
Example, adapted from Lenat
You are told: John drove to the grocery store and bought a pound of noodles, a pound of ground
beef, and two pounds of tomatoes.

• Is John 3 years old?


• Is John a child?
• What will John do with the purchases?
• Did John have any money?
• Does John have less money after going to the store?
• Did John buy at least two tomatoes?
• Were the tomatoes made in the supermarket?
• Did John buy any meat?
• Is John a vegetarian?
• Will the tomatoes fit in John’s car?
• Can Propositional Logic support these inferences?
Pros and cons of propositional logic
☺ Propositional logic is declarative
- Knowledge and inference are separate

☺ Propositional logic allows partial/disjunctive/negated information


– unlike most programming languages and databases

☺ Propositional logic is compositional:


– meaning of B1,1  P1,2 is derived from meaning of B1,1 and of P1,2

☺ Meaning in propositional logic is context-independent


– unlike natural language, where meaning depends on context

 Propositional logic has limited expressive power


– E.g., cannot say “Pits cause breezes in adjacent squares.“
• except by writing one sentence for each square
– Needs to refer to objects in the world,
– Needs to express general rules
Propositional logic is not expressive, cont.

• Combinatorial explosion when trying to


express general statements :
– Exactly one student in the class got perfect score
• Propositional logic
– P1  P 2  …  Pn
– For all i,j : Pi  Pj
• First order logic
– x[P(x)  y[x≠y  P(y)]]
• Q : exactly two students have perfect score?
Outline for First-Order Logic
(FOL, also called FOPC)
• Propositional Logic is Useful --- but Limited Expressive Power

• First Order Predicate Calculus (FOPC), or First Order Logic (FOL).


– FOPC has expanded expressive power, though still somewhat limited.

• New Ontology
– The world consists of OBJECTS.
– OBJECTS have PROPERTIES, RELATIONS, and FUNCTIONS.
• New Syntax
– Constants, Variables, Predicates, Functions, Quantifiers.
• New Semantics
– Meaning of new syntax.

• Unification and Inference in FOL


• Knowledge engineering in FOL
First-Order Logic (FOL), also called
First-Order Predicate Calculus (FOPC)
• Propositional logic assumes the world contains facts.

• First-order logic (like natural language) assumes the world contains

– Objects: people, houses, numbers, colors, baseball games, wars, …


– Functions: father of, best friend, one more than, plus, …
• Function arguments are objects; value of a function is an object
– Objects generally correspond to English NOUNS

– Predicates/Relations/Properties: red, round, prime, brother of, bigger


than, part of, comes between, …
• Predicate arguments are objects; value of a predicate is a truth value
– Predicates generally correspond to English VERBS and ADJECTIVES
• First argument is generally the subject, the second the object
• Hit(Bill, Ball) usually means “Bill hit the ball.”
• Likes(Bill, IceCream) usually means “Bill likes IceCream.”
• Verb(Noun1, Noun2) usually means “Noun1 verb noun2.”
Aside: First-Order Logic (FOL) vs.
Second-Order Logic
• First Order Logic (FOL) allows variables and general rules
– “First order” because quantified variables represent objects.
– “Predicate Calculus” because it quantifies over predicates on objects.
• E.g., “Integral Calculus” quantifies over functions on numbers.
• Aside: Second Order logic
– “Second order” because quantified variables can also represent
predicates and functions.
• E.g., can define “Transitive Relation,” which is beyond FOPC.

• Aside: In FOL we can state that a relationship is transitive


– E.g., BrotherOf is a transitive relationship
–  x, y, z BrotherOf(x,y)  BrotherOf(y,z) => BrotherOf(x,z)
• Aside: In Second Order logic we can define “Transitive”
–  P, x, y, z Transitive(P)  ( P(x,y)  P(y,z) => P(x,z) )
– Then we can state directly, Transitive(BrotherOf)
Syntax
Syntax of FOL: Basic elements
• Constants KingJohn, 2, UCI,...

• Predicates Brother, >,...

• Functions Sqrt, LeftLegOf,...

• Variables x, y, a, b,...

• Quantifiers , 

• Connectives , , , ,  (standard)

• Equality = (but causes difficulties….)


Syntax of FOL: Basic elements of language are symbols
• Constant Symbols (correspond to English nouns)
– Stand for objects in the world.
• E.g., KingJohn, 2, UCI, ...

• Function Symbols (correspond to English nouns)


– Stand for functions (maps a tuple of objects to an object)
• E.g., Sqrt(3), LeftLegOf(John), ...

• Predicate Symbols (correspond to English verbs)


– Stand for relations (maps a tuple of objects to a truth-value)
• E.g., Brother(Richard, John), greater_than(3,2), ...
– P(x, y) is usually read as “x is P of y.”
• E.g., Mother(Ann, Sue) is usually “Ann is Mother of Sue.”

• Model (world) = set of domain objects, relations, functions


• Interpretation maps symbols onto the model (world)
– Very many interpretations are possible for each KB and world!
– The KB is to rule out those inconsistent with our knowledge.
Syntax of FOL: Terms
• Term = expression that refers to an object

• There are three kinds of terms:

– Constant Symbols stand for (or name) objects:


• E.g., KingJohn, 2, UCI, Wumpus, ...

– Variables stand for objects

– Function Symbols map tuples of objects to an object:


• E.g., LeftLeg(KingJohn), Mother(Mary), Sqrt(x)
• This is nothing but a complicated kind of name
– No “subroutine” call, no “return value”
Syntax of FOL: Atomic Sentences
• Atomic Sentences state facts (logical truth values).
– An atomic sentence is a Predicate symbol, optionally followed by a
parenthesized list of any argument terms
• E.g., Married( Father(Richard), Mother(John) )
– An atomic sentence asserts that some relationship (some
predicate) holds among the objects that are its arguments.

• An Atomic Sentence is true in a given model if the relation


referred to by the predicate symbol holds among the
objects (terms) referred to by the arguments.
Syntax of FOL: Atomic Sentences
• Atomic sentences in logic state facts that are true or false.

• Properties and m-ary relations do just that:


LargerThan(2, 3) is false.
BrotherOf(Mary, Pete) is false.
Married(Father(Richard), Mother(John)) could be true or false.
Properties and m-ary relations are Predicates that are true or false.

• Note: Functions refer to objects, do not state facts, and form no sentence:
– Brother(Pete) refers to John (his brother) and is neither true nor false.
– Plus(2, 3) refers to the number 5 and is neither true nor false.
• BrotherOf( Pete, Brother(Pete) ) is True.

Binary relation Function refers to John, an object in the


is a truth value. world, i.e., John is Pete’s brother.
(Works well iff John is Pete’s only brother.)
Syntax of FOL:
Connectives & Complex Sentences
• Complex Sentences are formed in the same way, using
the same logical connectives, as in propositional logic
• The Logical Connectives:
–  biconditional
–  implication
–  and
–  or
–  negation

• Semantics for these logical connectives are the same as


we already know from propositional logic.
Examples
• Brother(Richard, John)  Brother(John, Richard)

• King(Richard)  King(John)

• King(John) =>  King(Richard)

• LessThan(Plus(1,2) ,4)  GreaterThan(1,2)

(Semantics of complex sentences are determined the same way as in


propositional logic)
Syntax of FOL: Variables
• Variables range over objects in the world.

• A variable is a term because it represents an object.

• A variable may be used wherever a term may be used.


– Variables may be arguments to functions and predicates.

• (A term with NO variables is called a ground term.)

• (A variable not bound by a quantifier is called free.)


– All variables we will use are bound by a quantifier.
Syntax of FOL: Logical Quantifiers
• There are two Logical Quantifiers:

– Universal:  x P(x) means “For all x, P(x).”


• The “upside-down A” reminds you of “ALL.”
• Some texts put a comma after the variable:  x, P(x)
– Existential:  x P(x) means “There exists x such that, P(x).”
• The “backward E” reminds you of “EXISTS.”
• Some texts put a comma after the variable:  x, P(x)

• You can ALWAYS convert one quantifier to the other.


–  x P(x)   x P(x)
–  x P(x)   x P(x)
– RULES:    and   

• RULES: To move negation “in” across a quantifier,


Change the quantifier to “the other quantifier”
and negate the predicate on “the other side.”
–  x P(x)    x P(x)   x P(x)
–  x P(x)    x P(x)   x P(x)
Quantifiers
Propositionalisation
Universal Quantification 
•  x means “for all x it is true that…”

• Allows us to make statements about all objects that have


certain properties

• Can now state general rules:


 x King(x) => Person(x) “All kings are persons.”
 x Person(x) => HasHead(x) “Every person has a head.”
 i Integer(i) => Integer(plus(i,1)) “If i is an integer then i+1 is an integer.”

• Note:  x King(x)  Person(x) is not correct!


This would imply that all objects x are Kings and are People (!)

 x King(x) => Person(x) is the correct way to say this

• Note that => is the natural connective to use with  .


Universal Quantification 
• Universal quantification is conceptually equivalent to:
– Conjunction of all sentences obtained by substitution of an object for
the quantified variable.
– Not a sentence in the logic --- all logic sentences must be finite.

• Example: All Cats are Mammals.


– x Cat(x)  Mammal(x)

• Conjunction of all sentences obtained by substitution of an


object for the quantified variable:
Cat(Spot)  Mammal(Spot) 
Cat(Rebecca)  Mammal(Rebecca) 
Cat(LAX)  Mammal(LAX) 
Cat(Shayama)  Mammal(Shayama) 
Cat(France)  Mammal(France) 
Cat(Felix)  Mammal(Felix) 

Existential Quantification 
•  x means “there exists an x such that….”
– There is in the world at least one such object x

• Allows us to make statements about some object without naming


it, or even knowing what that object is:
 x King(x) “Some object is a king.”
 x Lives_in(John, Castle(x)) “John lives in somebody’s castle.”
 i Integer(i)  Greater(i,0) “Some integer is greater than zero.”

• Note:  i Integer(i)  Greater(i,0) is not correct!


It is vacuously true if anything in the world were not an integer (!)
 i Integer(i)  Greater(i,0) is the correct way to say this

• Note that  is the natural connective to use with  .


Existential Quantification 
• Existential quantification is conceptually equivalent to:
– Disjunction of all sentences obtained by substitution of an object
for the quantified variable.
– Not a sentence in the logic --- all logic sentences must be finite.

• Spot has a sister who is a cat.


– x Sister(x, Spot)  Cat(x)

• Disjunction of all sentences obtained by substitution of an


object for the quantified variable:
Sister(Spot, Spot)  Cat(Spot) 
Sister(Rebecca, Spot)  Cat(Rebecca) 
Sister(LAX, Spot)  Cat(LAX) 
Sister(Shayama, Spot)  Cat(Shayama) 
Sister(France, Spot)  Cat(France) 
Sister(Felix, Spot)  Cat(Felix) 

Combining Quantifiers --- Order (Scope)
The order of “unlike” quantifiers is important.
Like nested variable scopes in a programming language.
Like nested ANDs and ORs in a logical sentence.

 x  y Loves(x,y)
– For everyone (“all x”) there is someone (“exists y”) whom they love.
– There might be a different y for each x (y is inside the scope of x)
 y  x Loves(x,y)
– There is someone (“exists y”) whom everyone loves (“all x”).
– Every x loves the same y (x is inside the scope of y)
Clearer with parentheses:  y (  x Loves(x,y) )

The order of “like” quantifiers does not matter.


Like nested ANDs and ANDs in a logical sentence
x y P(x, y)  y x P(x, y)
x y P(x, y)  y x P(x, y)
Connections between Quantifiers
• Asserting that all x have property P is the same as asserting
that does not exist any x that does not have the property P

 x Likes(x, CS-171 class)    x  Likes(x, CS-171 class)

• Asserting that there exists an x with property P is the same


as asserting that not all x do not have the property P

 x Likes(x, IceCream)    x  Likes(x, IceCream)

In effect:
-  is a conjunction over the universe of objects
-  is a disjunction over the universe of objects
Thus, DeMorgan’s rules can be applied
De Morgan’s Law for Quantifiers
De Morgan’s Rule Generalized De Morgan’s Rule
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 x P  x (P )

AND/OR Rule is simple: if you bring a negation inside a disjunction or a


conjunction, always switch between them ( OR → AND  ;  AND → OR ).

QUANTIFIER Rule is similar: if you bring a negation inside a universal or


existential, always switch between them (  →  ;   →  ).
Aside: More syntactic sugar --- uniqueness
• ! x is “syntactic sugar” for “There exists a unique x”
– “There exists one and only one x”
– “There exists exactly one x”
– Sometimes ! is written as 1

• For example, ! x PresidentOfTheUSA(x)


– “There is exactly one PresidentOfTheUSA.”

• This is just syntactic sugar:


– ! x P(x) is the same as  x P(x)  ( y P(y) => (x = y) )
– “Syntactic sugar” = a convenient syntax abbreviation/extension
Equality
• term1 = term2 is true under a given interpretation
if and only if term1 and term2 refer to the same object
• E.g., definition of Sibling in terms of Parent, using = is:

x,y Sibling(x,y) 
[(x = y) 
 m,f  (m = f)  Parent(m,x)  Parent(f,x)
 Parent(m,y)  Parent(f,y)]

• Equality can make reasoning much more difficult!


– (See R&N, section 9.5.5, page 353)
– You may not know when two objects are equal.
• E.g., Ancients did not know (MorningStar = EveningStar = Venus)
– You may have to prove x = y before proceeding
• E.g., a resolution prover may not know 2+1 is the same as 1+2 or 4−1
Syntactic Ambiguity
• FOPC provides many ways to represent the same thing.
• E.g., “Ball-5 is red.”
– HasColor(Ball-5, Red)
• Ball-5 and Red are objects related by HasColor.
– Red(Ball-5)
• Red is a unary predicate applied to the Ball-5 object.
– HasProperty(Ball-5, Color, Red)
• Ball-5, Color, and Red are objects related by HasProperty.
– ColorOf(Ball-5) = Red
• Ball-5 and Red are objects, and ColorOf() is a function.
– HasColor(Ball-5(), Red())
• Ball-5() and Red() are functions of zero arguments that both return an
object, which objects are related by HasColor.
– …
• This can GREATLY confuse a pattern-matching reasoner.
– Especially if multiple people collaborate to build the KB, and they
all have different representational conventions.
Syntactic Ambiguity --- Partial Solution
• FOL can be TOO expressive, can offer TOO MANY choices

• Likely confusion, especially for teams of Knowledge


Engineers

• Different people can make different representation choices


– E.g., represent “Ball43 is Red.” as:
• a predicate (= verb)? E.g., “Red(Ball43)” ?
• an object (= noun)? E.g., “Red = Color(Ball43))” ?
• a property (= adjective)? E.g., “HasProperty(Ball43, Red)” ?

• PARTIAL SOLUTION:
– An upon-agreed ontology that settles these questions
– Ontology = what exists in the world & how it is represented
– The Knowledge Engineering teams agrees upon an ontology
BEFORE they begin encoding knowledge
Making Sentences
More fun with sentences
• “All persons are mortal.”
• [Use: Person(x), Mortal (x) ]
More fun with sentences
• “All persons are mortal.”
[Use: Person(x), Mortal (x) ]

• ∀x Person(x)  Mortal(x)

• Equivalent Forms:
• ∀x ¬Person(x) ˅ Mortal(x)

• Common Mistakes:
• ∀x Person(x)  Mortal(x)
More fun with sentences
• “Fifi has a sister who is a cat.”
• [Use: Sister(Fifi, x), Cat(x) ]
More fun with sentences
• “Fifi has a sister who is a cat.”
• [Use: Sister(Fifi, x), Cat(x) ]

• ∃x Sister(Fifi, x)  Cat(x)

• Common Mistakes:
• ∃x Sister(Fifi, x)  Cat(x)
More fun with sentences
• “For every food, there is a person who eats
that food.”
[Use: Food(x), Person(y), Eats(y, x) ]
More fun with sentences
• “For every food, there is a person who eats that food.”
[Use: Food(x), Person(y), Eats(y, x) ]

• ∀x ∃y Food(x)  [ Person(y)  Eats(y, x) ]

• Equivalent Forms:
• ∀x Food(x)  ∃y [ Person(y)  Eats(y, x) ]
• ∀x ∃y ¬Food(x) ˅ [ Person(y)  Eats(y, x) ]
• ∀x ∃y [ ¬Food(x) ˅ Person(y) ]  [¬ Food(x) ˅ Eats(y, x) ]
• ∀x ∃y [ Food(x)  Person(y) ]  [ Food(x)  Eats(y, x) ]

• Common Mistakes:
• ∀x ∃y [ Food(x)  Person(y) ]  Eats(y, x)
• ∀x ∃y Food(x)  Person(y)  Eats(y, x)
More fun with sentences
• “Every person eats every food.”
[Use: Person (x), Food (y), Eats(x, y) ]
More fun with sentences
• “Every person eats every food.”
[Use: Person (x), Food (y), Eats(x, y) ]

• ∀x ∀y [ Person(x)  Food(y) ]  Eats(x, y)

• Equivalent Forms:
• ∀x ∀y ¬Person(x) ˅ ¬Food(y) ˅ Eats(x, y)
• ∀x ∀y Person(x)  [ Food(y)  Eats(x, y) ]
• ∀x ∀y Person(x)  [ ¬Food(y) ˅ Eats(x, y) ]
• ∀x ∀y ¬Person(x) ˅ [ Food(y)  Eats(x, y) ]

• Common Mistakes:
• ∀x ∀y Person(x)  [Food(y)  Eats(x, y) ]
• ∀x ∀y Person(x)  Food(y)  Eats(x, y)
More fun with sentences
• “All greedy kings are evil.”
[Use: King(x), Greedy(x), Evil(x) ]
More fun with sentences
• “All greedy kings are evil.”
[Use: King(x), Greedy(x), Evil(x) ]

• ∀x [ Greedy(x)  King(x) ]  Evil(x)

• Equivalent Forms:
• ∀x ¬Greedy(x) ˅ ¬King(x) ˅ Evil(x)
• ∀x Greedy(x)  [ King(x)  Evil(x) ]

• Common Mistakes:
• ∀x Greedy(x)  King(x)  Evil(x)
More fun with sentences
• “Everyone has a favorite food.”
[Use: Person(x), Food(y), Favorite(y, x) ]
More fun with sentences
• “Everyone has a favorite food.”
[Use: Person(x), Food(y), Favorite(y, x) ]

• ∀x ∃y Person(x)  [ Food(y)  Favorite(y, x) ]

• Equivalent Forms:
• ∀x Person(x)  ∃y [ Food(y)  Favorite(y, x) ]
• ∀x ∃y ¬Person(x) ˅ [ Food(y)  Favorite(y, x) ]
• ∀x ∃y [ ¬Person(x) ˅ Food(y) ]  [ ¬Person(x) ˅ Favorite(y, x) ]
• ∀x ∃y [Person(x)  Food(y) ]  [ Person(x)  Favorite(y, x) ]

• Common Mistakes:
• ∀x ∃y [ Person(x)  Food(y) ]  Favorite(y, x)
• ∀x ∃y Person(x)  Food(y)  Favorite(y, x)
More fun with sentences
• “There is someone at UCI who is smart.”
[Use: Person(x), At(x, UCI), Smart(x) ]
More fun with sentences
• “There is someone at UCI who is smart.”
[Use: Person(x), At(x, UCI), Smart(x) ]

• ∃x Person(x)  At(x, UCI)  Smart(x)

• Common Mistakes:
• ∃x [ Person(x)  At(x, UCI) ]  Smart(x)
More fun with sentences
• “Everyone at UCI is smart.”
[Use: Person(x), At(x, UCI), Smart(x) ]
More fun with sentences
• “Everyone at UCI is smart.”
[Use: Person(x), At(x, UCI), Smart(x) ]

• ∀x [Person(x)  At(x, UCI) ]  Smart(x)

• Equivalent Forms:
• ∀x ¬[Person(x)  At(x, UCI) ] ˅ Smart(x)
• ∀x ¬Person(x) ˅ ¬At(x, UCI) ˅ Smart(x)

• Common Mistakes:
• ∀x Person(x)  At(x, UCI)  Smart(x)
• ∀x Person(x)  [At(x, UCI)  Smart(x) ]

More fun with sentences
• “Every person eats some food.”
[Use: Person (x), Food (y), Eats(x, y) ]
More fun with sentences
• “Every person eats some food.”
[Use: Person (x), Food (y), Eats(x, y) ]

• ∀x ∃y Person(x)  [ Food(y)  Eats(x, y) ]



• Equivalent Forms:
• ∀x Person(x)  ∃y [ Food(y)  Eats(x, y) ]
• ∀x ∃y ¬Person(x) ˅ [ Food(y)  Eats(x, y) ]
• ∀x ∃y [ ¬Person(x) ˅ Food(y) ]  [ ¬Person(x) ˅ Eats(x, y) ]

• Common Mistakes:
• ∀x ∃y [ Person(x)  Food(y) ]  Eats(x, y)
• ∀x ∃y Person(x)  Food(y)  Eats(x, y)

More fun with sentences
• “Some person eats some food.”
[Use: Person (x), Food (y), Eats(x, y) ]
More fun with sentences
• “Some person eats some food.”
[Use: Person (x), Food (y), Eats(x, y) ]

• ∃x ∃y Person(x)  Food(y)  Eats(x, y)

• Common Mistakes:
• ∃x ∃y [ Person(x)  Food(y) ]  Eats(x, y)
Semantics
Semantics: Worlds
• The world consists of objects that have properties; there are
relations and functions between these objects

– Objects in the world : individuals, people, houses, numbers, colors,


baseball games, wars, centuries
• Clock A, John, 7, the-house in the corner, Tel-Aviv
– Functions on individuals:
• father-of, best friend, third inning of, one more than
• a function returns an object
– Relations (terminology: same thing as a predicate):
• brother-of, bigger than, inside, part-of, has color, occurred after
• a relation/predicate returns a truth value
– Properties (a relation of arity 1):
• red, round, bogus, prime, multistoried, beautiful
Truth in first-order logic
• Sentences are true with respect to a world (model) and an interpretation

• Model contains objects (domain elements) and relations among them

• Interpretation specifies mapping from language to world

constant symbols → objects

predicate symbols → relations (a relation yields a truth value)

function symbols → functions (a function yields an object)

• An atomic sentence predicate(term1,...,termn) is true


iff the objects referred to by term1,...,termn
are in the relation referred to by predicate

• Truth of more complex sentence (using logical connectives) is determined the usual
way; quantifiers means “for all, exists (some)”…

• Satisfiability, validity, unsatisfiability, etc. defined the usual way…


Alternative Semantics
• Database semantics –
1. Unique names assumption
• Every unique constant refers to a distinct object
2. Domain closure
• Each model contains no more domain elements that named by
constant symbols
3. Closed-world assumption
• Every atomic sentence not known to be true is assumed to be false
• Intended Interpretation –
– Each symbol (constant, function, relation) is mapped to
same-named object in the model
Summary of FOL Semantics
• A well-formed formula (“wff”) FOL is true or false with respect to a
world and an interpretation (a model).

• The world has objects, relations, functions, and predicates.

• The interpretation maps symbols in the logic to the world.

• The wff is true if and only if (iff) its assertion holds among the
objects in the world under the mapping by the interpretation.

• Your job, as a Knowledge Engineer, is to write sufficient KB axioms


that ensure that KB is true in your own real world under your own
intended interpretation.
– The KB axioms must rule out other worlds and interpretations.
Semantics : PL vs FOL
Language Possible worlds (interpretations)

Semantics: an
KB : CNF over interpretation maps
prop symbols prop symbols to
{true,false}

Semantics: an interpretation
KB : CNF over has obj’s and maps :
predicates over terms (fn const symbols to const’s,
+ var + const) fn symbols to fn’s,
Note : pred symbols to pred’s
const, fn, pred symbols Note :
const’s, fn’s, pred’s
Note : var’s not mapped!
Reduction of FOL inference to PL
inference
Review : Propositionalisation
• x Cat(x)  Mammal(x)
– Cat(Spot)  Mammal(Spot) 
Cat(Rebecca)  Mammal(Rebecca) 
Cat(LAX)  Mammal(LAX) 
Cat(Shayama)  Mammal(Shayama) 
Cat(France)  Mammal(France) 
Cat(Felix)  Mammal(Felix) 

• x Sister(x, Spot)  Cat(x)
– Sister(Spot, Spot)  Cat(Spot) 
Sister(Rebecca, Spot)  Cat(Rebecca) 
Sister(LAX, Spot)  Cat(LAX) 
Sister(Shayama, Spot)  Cat(Shayama) 
Sister(France, Spot)  Cat(France) 
Sister(Felix, Spot)  Cat(Felix) 

Reduction of FOL to PL
• Every FOL KB can be propositionalized so as to preserve
entailment

– A ground sentence is entailed by new KB iff entailed by original KB

• 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)))
Reduction of FOL inference to PL inference
Theorem: Herbrand (1930). If a sentence α is entailed by an 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 (will terminate) if α is entailed, loops forever 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 non-
entailed sentence.)
Problems with propositionalisation
• Propositionalisation seems to generate lots of irrelevant sentences.

• E.g., from:

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


King(John)
y Greedy(y)
Brother(Richard,John)

• Given query “Evil(x) it seems obvious that Evil(John), but


propositionalisation produces lots of facts such as Greedy(Richard)
that are irrelevant

• With p k-ary predicates and n constants, there are p·nk instantiations.


FOL CNF
Conversion to CNF
• Everyone who loves all animals is loved by someone:

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


Note this is 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)]


x [y(Animal(y)  Loves(x,y))]  [y Loves(y,x)]
2. Move  inwards:
[Recall: x P(x) ≡ x P(x);  x P(x) ≡ x P(x) ]

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)]
x [y (Animal(y)  Loves(x,y))]  [y Loves(y,x)]
Conversion to CNF contd.
3. Standardize variables: each quantifier should use a different variable
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 [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)]
A note on Skolem functions
Consider the statement: x y P(x, y)
P(x,C) for some C is wrong! This is equivalent to saying y x P(x, y)

The statement asserts that, for all x, there is (at least) one y such that P(x,y).
Recall that each x may have a different y, and so y depends on x.

So, at least abstractly, there is a list that pairs each x to a y that satisfies P(x,y):
{ (x1, y1), (x2, y2), (x3, y3), (x4, y4) … } where P(x1, y1) = TRUE; P(x2, y2) =
TRUE; P(x3, y3) = TRUE; and so on.

So, at least abstractly, there is a function that maps xi to yi. Call that function
F(), where F(x1) = y1; F(x2) = y2; F(x3) = y3; and so on. (We don’t know what
that function is, but we do know that it must exist --- even if we can’t write it
down.)

So P(x1, F(x1) ) = TRUE; P(x2, F(x2) ) = TRUE; P(x3, F(x3) ) = TRUE; and so on.

In other words, x y P(x, y)  x P(x, F(x) ), where F() is as described above.


Unification
Unification
• Let θ be a list of substitutions {variable/term}
• Subst(θ, p) = result of substituting θ into sentence p

• Unify algorithm: takes 2 sentences p and q and returns a unifier if one


exists

Unify(p,q) = θ where Subst(θ, p) = Subst(θ, q)

where θ is a list of substitutions = variable/term pairs


that will make p and q syntactically identical

• Example:
p = Knows(John,x)
q = Knows(John, Jane)

Unify(p,q) = {x/Jane}
Unification examples
• simple example: query = Knows(John,x), i.e., who does John know?

p q θ

Knows(John,x) Knows(John,Jane) {x/Jane}


Knows(John,x) Knows(y,OJ) {x/OJ,y/John}
Knows(John,x) Knows(y,Mother(y)) {y/John,x/Mother(John)}
Knows(John,x) Knows(x,OJ) {fail}

• Last unification fails: only because x can’t take values John and OJ at the same time
– But we know that if John knows x, and everyone (x) knows OJ, we should be able to infer
that John knows OJ

• Problem is due to use of same variable x in both sentences

• Simple solution: Standardizing apart eliminates overlap of variables, e.g., Knows(z,OJ)


Unification examples
• UNIFY( Knows( John, x ), Knows( John, Jane ) ) { x / Jane }

• UNIFY( Knows( John, x ), Knows( y, Jane ) ) { x / Jane, y / John }

• UNIFY( Knows( y, x ), Knows( John, Jane ) ) { x / Jane, y / John }

• UNIFY( Knows( John, x ), Knows( y, Father (y) ) ) { y / John, x / Father (John) }

• UNIFY( Knows( John, F(x) ), Knows( y, F(F(z)) ) ) { y / John, x / F (z) }

• UNIFY( Knows( John, F(x) ), Knows( y, G(z) ) ) None

• UNIFY( Knows( John, F(x) ), Knows( y, F(G(y)) ) ) { y / John, x / G (John) }


Unification
• To unify Knows(John,x) and Knows(y,z),
θ = {y/John, x/z } or θ = {y/John, x/John, z/John}

• The first unifier is more general than the second.

• There is a single most general unifier (MGU) that is unique


up to renaming of variables.

MGU = { y/John, x/z }

• General algorithm in Figure 9.1 in the text


Unification Algorithm
Unification Algorithm

If we have failed or succeeded,


then fail or succeed.
Unification Algorithm

If we can unify a variable


then do so.
Unification Algorithm

If we already have bound


variable var to a value, try
to continue on that basis.

There is an implicit assumption that “{var/val}  ”, if it


succeeds, binds val to the value that allowed it to succeed,
Unification Algorithm

If we already have bound x


to a value, try to continue
on that basis.
Unification Algorithm

If var occurs anywhere


within x, then no
substitution will succeed.
Unification Algorithm

Else, try to bind var to x,


and recurse.
Unification Algorithm

If a predicate/function,
unify the arguments.
Unification Algorithm

If unifying arguments,
unify the remaining
arguments.
Unification Algorithm

Otherwise, fail.
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,Red) Diff(Green,Blue)
Diff(Blue,Red) Diff(Blue,Green)

• To unify the grounded propositions with premises of the implication


you need to solve a CSP!
• Colorable() is inferred iff the CSP has a solution
• CSPs include 3SAT as a special case, hence matching is NP-hard
Resolution
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}

• Apply resolution steps to CNF(KB  α); complete for FOL


Example knowledge base
• 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 Col. West is a criminal


Example knowledge base (Horn clauses)
... it is a crime for an American to sell weapons to hostile nations:
American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)
Nono … has some missiles, i.e., x Owns(Nono,x)  Missile(x):
Owns(Nono,M1)  Missile(M1)
… all of its missiles were sold to it by Colonel West
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missiles are weapons:
Missile(x)  Weapon(x)
An enemy of America counts as "hostile“:
Enemy(x,America)  Hostile(x)
West, who is American …
American(West)
The country Nono, an enemy of America …
Enemy(Nono,America)
Resolution proof:

~
Forward Chaining
Backward Chaining
Forward chaining proof: (Horn clauses)
Forward chaining proof (Horn clauses)

Enemy(x,America)  Hostile(x)
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)

Missile(x)  Weapon(x)
Forward chaining proof (Horn clauses)

American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)


Forward chaining proof (Horn clauses)

*American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)


*Owns(Nono,M1) and Missile(M1)
*Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
*Missile(x)  Weapon(x)
*Enemy(x,America)  Hostile(x)
*American(West)
*Enemy(Nono,America)
Backward chaining example (Horn clauses)
Backward chaining example (Horn clauses)
Backward chaining example (Horn clauses)
Backward chaining example (Horn clauses)
Backward chaining example (Horn clauses)
Backward chaining example (Horn clauses)
Backward chaining example (Horn clauses)
FOL Knowledge-Based Agent
Review --- Syntactic Ambiguity
• FOPC provides many ways to represent the same thing.
• E.g., “Ball-5 is red.”
– HasColor(Ball-5, Red)
• Ball-5 and Red are objects related by HasColor.
– Red(Ball-5)
• Red is a unary predicate applied to the Ball-5 object.
– HasProperty(Ball-5, Color, Red)
• Ball-5, Color, and Red are objects related by HasProperty.
– ColorOf(Ball-5) = Red
• Ball-5 and Red are objects, and ColorOf() is a function.
– HasColor(Ball-5(), Red())
• Ball-5() and Red() are functions of zero arguments that both return an
object, which objects are related by HasColor.
– …

• This can GREATLY confuse a pattern-matching reasoner.


– Especially if multiple people collaborate to build the KB, and they
all have different representational conventions.
Review --- Syntactic Ambiguity ---
Partial Solution
• FOL can be TOO expressive, can offer TOO MANY choices

• Likely confusion, especially for teams of Knowledge Engineers

• Different team members can make different representation


choices
– E.g., represent “Ball43 is Red.” as:
• a predicate (= verb)? E.g., “Red(Ball43)” ?
• an object (= noun)? E.g., “Red = Color(Ball43))” ?
• a property (= adjective)? E.g., “HasProperty(Ball43, Red)” ?

• PARTIAL SOLUTION:
– An upon-agreed ontology that settles these questions
– Ontology = what exists in the world & how it is represented
– The Knowledge Engineering teams agrees upon an ontology
BEFORE they begin encoding knowledge
Using FOL
• We want to TELL things to the KB, e.g.
TELL(KB,  x King(x)  PersonX) )
TELL(KB, King(John) )

These sentences are assertions

• We also want to ASK things to the KB,


ASK(KB,  x Person(x) )

these are queries or goals

The KB should return the list of x’s for which Person(x) is true:
{x/John, x/Richard,...}
FOL Version of Wumpus World
• Typical percept sentence:
Percept([Stench,Breeze,Glitter,None,None],5)

• Actions:
Turn(Right), Turn(Left), Forward, Shoot, Grab, Release, Climb

• To determine best action, construct query:


 a BestAction(a,5)

• ASK solves this and returns {a/Grab}


– And TELL about the action.
Knowledge Base for Wumpus World
• Perception
– s,g,x,y,t Percept([s,Breeze,g,x,y],t)  Breeze(t)
– s,b,x,y,t Percept([s,b,Glitter,x,y],t)  Glitter(t)

• Reflex action
– t Glitter(t)  BestAction(Grab,t)

• Reflex action with internal state


– t Glitter(t) Holding(Gold,t)  BestAction(Grab,t)

Holding(Gold,t) can not be observed: keep track of change.


Deducing hidden properties
Environment definition:
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)

Squares are breezy near a pit:


– Diagnostic rule---infer cause from effect
s Breezy(s)   r Adjacent(r,s)  Pit(r)

– Causal rule---infer effect from cause (model based reasoning)


r Pit(r)  [s Adjacent(r,s)  Breezy(s)]
Yale shooting problem
• The Yale shooting problem illustrates the frame
problem. (Its inventors were working at Yale University
when they proposed it.)
• Fred (a turkey) is initially alive and a gun is initially
unloaded. Loading the gun, waiting for a moment, and
then shooting the gun at Fred is expected to kill Fred.
• However, in one solution, Fred indeed dies; in another
(also logically correct) solution, the gun becomes
mysteriously unloaded and Fred survives.
• By Hanks and McDermott, adapted from Wikipedia
Yale Shooting Problem
• Fred, Gun
– alive(0)
– not loaded(0)
• Load
– loaded(1)
• Shoot
– loaded(2) → not alive(3)
• Cannot show
– Fred not alive at (3) since “loaded(2)” not entailed
– alive(1), since “not alive(1)” has a model
Successor state axioms
• Instead of focusing on actions, focus on states
– Things change for a reason
– Things don’t change without reason
FOL Knowledge Engineering
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


The electronic circuits domain
One-bit full adder

Possible queries:
- does the circuit function properly?
- what gates are connected to the first input terminal?
- what would happen if one of the gates is broken?
and so on
The electronic circuits domain
1. Identify the task
– Does the circuit actually add properly?

2. Assemble the relevant knowledge


– Composed of wires and gates; Types of gates (AND, OR, XOR, NOT)

– Irrelevant: size, shape, color, cost of gates

3. Decide on a vocabulary
– Many alternative ways to say X1 is an OR gate:

– Type(X1) = XOR (function)
Type(X1, XOR) (binary predicate)
XOR(X1) (unary predicate)
etc.
The electronic circuits domain
4. 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))


The electronic circuits domain
5. 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))
The electronic circuits domain
6. 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,C1)) = i1  Signal(In(2,C1)) = i2  Signal(In(3,C1)) = i3


 Signal(Out(1,C1)) = o1  Signal(Out(2,C1)) = o2

7. Debug the knowledge base


May have omitted assertions like 1 ≠ 0
Review --- 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


Summary
• First-order logic:
– Much more expressive than propositional logic
– Allows objects and relations as semantic primitives
– Universal and existential quantifiers

• Syntax: constants, functions, predicates, equality, quantifiers

• Nested quantifiers
– Order of unlike quantifiers matters (the outer scopes the inner)
• Like nested ANDs and ORs
– Order of like quantifiers does not matter
• like nested ANDS and ANDs

• Translate simple English sentences to FOPC and back

• Unification: Making terms identical by substitution


– The terms are universally quantified, so substitutions are justified.

• Knowledge engineering using FOL


– Capturing domain knowledge in logical form
Unit resolution is (refutation) complete for
Horn clauses : example
… … … …
B,C C,A
… B B,C

B B,A … C C,A

A A A A

⊥ ⊥

Can transform any non-unit resolution


(Non-unit) resolution is complete! proof to unit resolution proof
Unit resolution is (refutation) complete for
Horn clauses : general case
… …
A,S2 A,S1[,B]

S1,S2[,B]

Only unit resolution here.


S2 eliminated one at a time.

You might also like