7 FirstOrderLogic

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 28

First Order Logic (FOL)

First Order Logic (FOL)


• PL isn’t powerful enough as a general KR language.
– Impossible to make general statements.
E.g.: 1. all students sit for exams
2. if any student sits an exam, they either pass or fail
• FOL is a more powerful form of logic
– Almost any English sentence may be represented in first- order predicate
calculus
Example:
(1) John’s mother is married to John’s father
married(father(john), mother(john))
(2) Potato is good and Potato is a kind of food
good(Potato)  is(Potato, food)
good(Potato)  food(Potato)
(3) All food are edible
X food( X)  edible( X)
First Order Logic (FOL)
•FOL (like natural language) assumes the world
contains
–Objects: that have attributes/properties
people, house, number, color, baseball-game, war, …
–Relations: between objects:
brother-of, bigger-than, part-of, …
–Properties: distinguishing features.
color (red), shape (round), size (length), …
–Functions: returns value for a given object
father-of, best-friend, cosine, plus, …
•Almost any fact refer to objects & relations/properties
Example: King John ruled England in 1200
Objects: John, England, 1200
Relations: ruled
Properties: king
Syntax of FOL
• Constants symbol
–names (like Jonas, kebede, …), numbers (like 1, 2, … n), ...
• Predicates:
–Predicates used to relate one object with another. E.g.
brother, >,...
• Functions: Returns value (Sqrt, mother-of,...)
• Variables: x, y, a, b,...
–Important to increase generalization capability of KB
• Connectives:
–retains connectives used in PL (, , , , )
• Equality: =
• Quantifiers:
–Quantifiers specify whether all or some objects satisfy
properties or relations between objects
–Two standard quantifiers: Universal ( for all, for every) and
Existential ( there exists, some)
Universal quantification
• Universal Quantifiers: makes statements about every object
<variables> <sentence>
–Everyone at AAU is smart:
x At(x,AAU)  Smart(x)
–All cats are mammals:
x cat(x)  mammal(x)

x sentence P is true iff P is true with x being each possible


object in the given universe
–The above statement is equivalent to the conjunction
At(Jonas, AAU)  Smart(Jonas) 
At(Rawad, AAU)  Smart(Rawad) 
...
• A common mistake to avoid
–Typically,  is the main connective with 
–Common mistake: the use of  as the main connective with :
x At(x,AAU)  Smart(x) is true if “Everyone is at AAU & everyone is smart”
Existential quantification
•Makes statements about some objects in the universe
<variables> <sentence>
–Someone at AAU is smart:
x At(x,AAU)  Smart(x)
–Spot has a sister who is a cat:
x sister(spot,x)  cat(x)
x sentence P is true iff P is true with x being some
possible objects
–The above statement is equivalent to the disjunction
At(Jonas, AAU)  Smart(Jonas) 
At(Alemu, AAU)  Smart(Alemu) 
…..
•Common mistake to avoid
–Typically,  is the main connective with 
–Common mistake: using  as the main connective with :
 At(x,AAU)  Smart(x) is true if there is anyone who is not at AAU
Nested quantifiers
x,y parent(x,y)  child(y,x)
–for all x and y, if x is the parent of y then y is the child of x.
x y Loves(x,y)
–There is a person who loves everyone in the given world
y x Loves(x,y)
–Everyone in the given universe is loved by at least one person
Properties of quantifiers
   is the same as  
x y y x
   is the same as  
x y y x
   is not the same as  
x y y x

• Quantifier duality: each can be expressed using the other,


using negation ()
x Likes(x,icecream) x Likes(x,icecream)
–Everyone likes ice cream means that there is nobody who dislikes ice
cream
x Likes(x,cake) x Likes(x,cake)
–There is someone who likes cake means that not every one dislikes cake
Sentence structure
In FOL the basic unit is a predicate (argument/terms)
structure called sentence to represent facts.
• Terms refer to objects
Example: likes(samson, chocolate); tall(Berry)
–Terms or arguments can be any of: Constant symbol, such
as ‘samson’, variable symbol, such as X , functions, such as
motherof(fred), father-of( father-of( john))
• A predicate is the one that says something about the
subject. E.g., The book is red
• Subject: color of the book, represented as: is-red(book)
• is-red: predicate, and book: argument
–Predicate also refers to a particular relation between objects
• Example: likes(X, richard)
friends(motherof(jonas), motherof(semu))
–A predicate statement takes the value true or false
Sentences
Atomic sentences: formed from a predicate symbol
followed by a parenthesized list of terms
Atomic sentence = predicate (term1,...,termn)
Example: Brother(John, Richard)
• Atomic sentences can have arguments that are complex terms
(e.g. term = function (term1,...,termn) )
Example: married(fatherof(Richard),motherof(John))
Complex sentences: complex sentences are made by
combining atomic sentences using connectives:
S, S1  S2, S1  S2, S1  S2, S1  S2,
Ex. likes(john, mary)  tall(mary)
tall(john)  handsome(john)
Sibling(John, Richard)  Sibling(Richard, John)
• Sentences can also be formed using quantifiers to indicate how
to treat variables:
– Universal quantifier: x lovely(x) - Everything is lovely.
– Existential quantifier: x lovely(x) - Something is lovely.
Sentences
•Can have several quantifiers, e.g.,
x y loves(x, y)
x handsome(x)  y loves(y, x)
Represent the following using variables & quantifiers:
• Everything in the garden is lovely  x in(x, garden)  lovely(x)
• Everyone likes ice cream  x likes(x, icecream)
y friends(y, Peter)
• Peter has some friends 
• John plays the piano or the violin
plays(john, piano) v plays(john, violin)
• Some people like snakes -- x(person(x) Λ likes(x, snakes))
• Winston did not write Hamletwrite(
– winston, hamlet)
• Nobody wrote Hamlet – x write(x, hamlet)
• Every city has a dogcatcher who has been bitten by
every dog in town
x {city(x)  y{dogcatcher(y, z) Λ z{[dog(z) Λ live- in(z, x)]  bit(z, y)}}}
Semantics
• There is a precise meaning to expressions in predicate logic.
• Like in propositional logic, it is all about determining whether
something is true or false.
x P(x) means that P(x) must be true for every object x in the
domain of interest.
x P(x) means that P(x) must be true for at least one object x in
the domain of interest.
– So if we have a domain of interest consisting of just two people, john
and mary, and we know that tall(mary) and tall(john) are true,
we can say that x tall(x) is true.
• Atomic sentence is true if the relation referred by the
predicate holds b/n the objects referred by the arguments
brother(John, Richard)
• The truth value of complex sentences depends on logical
connectives used
older(John,30)  younger(John,30)
Proof and inference
• We can define inference rules allowing us to say that if certain
things are true, certain other things are sure to be true,
E.g. All men are mortal
Aristotle is a man
using logical inferences we can deduce that:
Aristotle is mortal
x man(x) mortal(x)
man(Aristotle)
so we can conclude that mortal(Aristotle)
– This involves matching man(x) against man(Aristotle) and binding the
variable x to Aristotle.

Example 1: What can we conclude from the following?


x tall(x)  strong(x)
tall(john)
 x strong(x)  loves(mary, x)
Example 2: Every metal is dissolved by sulphuric acid
copper is a metal
can we conclude: Copper is dissolved by sulphuric acid
Sound Inference Rules
•Rules for PL apply to FOL as well.
–For example, Modus Ponens, And-Introduction, And-
Elimination, etc.
•New (sound) inference rules for use with quantifiers:
–Universal Elimination, Existential Introduction,
Existential Elimination
–By substituting particular individuals for the
variable. E.g. substitute (x/sam, y/cake). Then
likes(x,y) = likes(sam,cake)
•Universal Elimination: If x P(x) is true, then P(c) is
true, where c is a constant in the domain of x.
Example: x eats(x, IceCream).
Using the substitution (x/Ben) we can infer eats(Ben,
Icecream).
–The variable symbol can be replaced by any constant symbol
Sound Inference Rules
• Existential Introduction: If P(c) is true, then x
P(x) is inferred.
Example: eats(John, IceCream) we can infer x eats(x,
icecream).
– All instances of the given constant symbol are replaced
by the new variable symbol.

• Existential Elimination: From x P(x) infer P(c).


Example: x eats(Sol, x) infer eats(Sol, Cheese)
– Note that the variable x is replaced by a brand new
constant (like Cheese) that does not occur in this or any
other sentence in the Knowledge Base.
Proofs
• Sound inference: find α such that KB |= α
• Proof process is a search, operators are inference
rules
–It requires the operation of a series of inference rule to
come up with some conclusion
Example:
Bob is a buffalo. Pat is a pig. Buffaloes outrun pigs
Conclude: Bob outruns Pat
1. Buffalo(Bob)
2. Pig(Pat)
3. x,y Buffalo(x) ^ Pig(y) → Faster(x,y)
4. Buffalo(Bob) ^ Pig(Pat) And Introduction (1, 2)
5. Buffalo(Bob) ^ Pig(Pat) → Faster(Bob, Pat)
Universal Elimination (3, {x/Bob,y/Pat})
6. Faster(Bob,Pat) Modus Ponens (6, 7)
Generalized Modus Ponens (GMP)
• Combines And-Introduction, Universal-Elimination, and
Modus Ponens
• Given atomic sentences P1, P2, ..., PN, and implication
sentence (Q1 ^ Q2 ^ ... ^ QN)  R, where Q1, ..., QN and R are
atomic sentences, derive new sentence R. That is,
from P(c), Q(c), and x (P(x) ^ Q(x)  R(x)), derive R(c)
Example: Given Faster(Bob,Pat), Faster(Pat,Steve) and
Faster(x,y) ^ Faster(y,z)  Faster(x,z)
by substituting {x/Bob, y/Pat, z/Steve}
infer in one step the new sentence: Faster(Bob, Steve)
• Generalized Modus Ponens is not complete for FOL. Natural
deduction using GMP is complete for KBs containing only
Horn clauses.
Horn clauses
•A Horn clause is a sentence of the form:
x (P1(x) ^ P2(x) ^ ... ^ Pn(x))  Q(x)
where there are 0 or more Pi's, and the Pi's and Q
are positive (i.e., un-negated) literals
•Horn clauses represent a subset of the set of
sentences representable in FOL
e.g. p(a) v q(a) is a sentence in FOL but it is not a
horn clause

Example: All cats like fish, cats eat everything they


like, and Ziggy is a cat.
Goal query: Does Ziggy eat fish?
Conclude by Chaining
•Forward chaining
–Proofs start with the given axioms/premises in KB,
deriving new sentences using GMP until the
goal/query sentence is derived.
–This defines a forward chaining inference
procedure because it moves "forward" from the KB
to the goal.
–Given premises in the KB =
1. (x) cat(x)  likes(x, Fish)
2. (x)(y) (cat(x) ^ likes(x,y))  eats(x,y)
3. cat(Ziggy)
–Proof: 4. likes(Ziggy, Fish) Using GMP with (1) and (3)
5. eats(Ziggy, Fish) Using GMP with (3), (4)
and (2) So, Yes, Ziggy eats fish.
Conclude by Chaining
•Backward chaining:
–Proofs start with the goal query, find implications that would
allow you to prove it, and then prove each of the antecedents
in the implication, continuing to work "backwards" until we get
to the axioms, which we know are true.
–To prove eats(Ziggy, Fish), first see if this is known from one
of the axioms directly. Otherwise, see if there is a Horn
clause that has the consequent (i.e., right-hand side (RHS))
of the implication matching the goal. Here,
• Goal matches RHS of (2), so prove new sub-goals
cat(Ziggy) and likes(Ziggy, Fish) that correspond to the LHS of
(2)
• cat(Ziggy) matches axiom (3), so we've "solved" that sub-goal
• likes(Ziggy, Fish) matches the RHS of (1), so prove cat(Ziggy)
• cat(Ziggy) matches (3), so we've solved this sub-goal
• There are no unsolved sub-goals,
Unification
•Unification is an algorithm for determining the substitutions
needed to make two expressions match
–Unification is a "pattern matching" procedure that takes two atomic
sentences (literals) as input, and returns "failure" if they do not match and
a substitution list, θ, if they do match.
unify(p,q) = θ means subst(θ, p) = subst(θ, q) for two atomic sentences p
and q.
•Example: To make, say p(X, X) and p( Y, Z) match, we may use
subst(Y/X) or subst(Z /X)
•It is also possible to substitute a function for a variable:
e. g., human( X)  mortal( X) and human(father_ of( plato))
subst(X/father_ of( plato))
human(father_ of( plato))  mortal(father_ of( plato))
{X/fred, Y/Z} like( fred, a, friend( Z))
like( X, a, friend( Y))

{X/Z, Y/brother( Z)} {X/ W, Y / jack} like( W, a, friend( jack))

like( Z, a, friend(brother( Z)))


More Examples of Unification
Literal 1 Literal 2 Unifier
group(x, cat(x), dog(Bill)) group(Bill, cat(Bill), y) {x/Bill, y/dog(Bill)}
group(x, cat(x), dog(Bill)) group(Bill, cat(y), z) {x/Bill, y/Bill, z/dog(Bill)}
group(x, cat(x), dog(Jane)) group(Bill, cat(y), dog(y)) Failure

Unify is a linear time algorithm that returns the most general


unifier, i.e., a shortest length substitution list that makes the
two literals match.
•A variable can never be replaced by a term containing
that variable. For example, x/f(x) is illegal.

•Unification and inference rules allows us to make


inferences on a set of logical assertions. To do this,
the logical database must be expressed in an
appropriate form
Unification
• A substitution α unfies atomic sentences p and q if pα = qα
p q α
Knows(John,x) Knows(John,Jane) {x/Jane}
Knows(John,x) Knows(y, Abe) {y/John, x/Abe}
Knows(John,x) Knows(y,Mother(y)) {y/John, x/Mother(John)}
Knows(John,x) Knows(x,Abe) Fail

Idea: Unify rule:


• Premises with known facts apply unifier to conclusion
Example. if we know q and Knows(John,x) → Likes(John,x)
then we conclude Likes(John,Jane)
Likes(John,Abe)
Likes(John,Mother(John))
Generalized Resolution
• Resolution procedure is a sound and complete inference
procedure for FOL
–It uses a single resolution rule of inference: which is generalization of the
same rule used in PL.
• Resolution Rule for PL: From sentence P1 v P2 v ... v Pn and sentence
P1 v Q2 v ... v Qm derive resolvent sentence: P2 v ... v Pn v Q2 v ... v Qm
Examples:
–Given P, P v Q, derive Q (unit resolution)
–Given (P v Q), (Q v R), derive P v R (resolution)
–Given P, P, derive False
–Given (P v Q), (P v Q), derive True

• Resolution Rule for FOL:


Given sentence P1 v ... v Pn and sentence Q1 v ... v Qm where
each Pi and Qi is a literal, i.e., a positive or negated predicate
symbol with its terms, if Pj and Qk unify with substitution list θ,
then derive the resolvent sentence:

subst(θ, P1 v ... v Pj-1 v Pj+1 v ... v Pn v Q1 v ... Qk-1 v Qk+1 v ... V Qm)
Example: Resolution
• Given: P(x, f(a)) v P(x, f(y)) v Q(y) and
P(z, f(a)) v Q(z),

We can derive resolvent clause


P(z, f(y)) v Q(y) v Q(z)
using θ = {x/z}

• Given: Rich(ken)
Rich(x) v unhappy(x)
using θ = {x/ken}
we can conclude that:
unhappy(ken)
Generalized Resolution
• Generalized Resolution inference rule provides a
complete system for proof by refutation.
–Resolution is a generalization of modus ponens
–It requires a normal form, but any sentence can be put into
CNF
• Conjunctive normal form (CNF)
–Each individual sentence is a disjunction of literals. This
form is CNF
–CNF is more common
Example: P(x) v R(x)
Q(y) v S(y)
• Conversion to CNF:
–any FOL sentence can be put into normal form
Steps to convert a FOL sentence to CNF
• Eliminate all  connectives: replace (P  Q) by ((P  Q) ^ (Q  P))
• Eliminate all  connectives: replace each instance (P  Q) by (P v Q)
• Reduce the scope of each negation symbol to a single predicate:
P to P; (P v Q) to P ^ Q; (P ^ Q) to P v Q; (x) P to (x) P,
and (x) P to (x) P
• Eliminate  by introducing Skolem symblos/function.
 x P(x) converted to P(c) where c is a brand new Skolem constant
symbol that is not used in any other sentence.
– If  is within the scope of a universal quantified variable, then introduce a
Skolem function (f). Example, (x)(y)P(x,y) is converted to (x)P(x,
f(x)).
E.g.: x y loves(x,y) converted to x loves(x,f(x)) where f(x) specifies the
person that x loves. (If everyone loved their mother, then f could be
mother_of function)
• Remove  by moving quantifiers to the left end and making the
scope of each the entire sentence.
For example, convert x P(x) to P(x).
• Distribute "and" over "or" to get conjunctive normal form.
Convert (P ^ Q) v R to (P v R) ^ (Q v R), and (P v Q) v R to (P v Q v R).
• Split each conjunct into a separate clause, which is just a disjunction
("or") of negated and un-negated predicates, called literals.
Example
Convert the following sentence to CNF
x (P(x)  (y (P(y)  P(f(x,y))) ^ y(Q(x,y)  P(y)))
• Eliminate :
(x)(P(x) v ((y)(P(y) v P(f(x,y))) ^ (y)(Q(x,y) v P(y))))
• Reduce scope of  :
(x)(P(x) v ((y)(P(y) v P(f(x,y))) ^ (y)(Q(x,y) ^ P(y))))
• Standardize variables:
(x)(P(x) v ((y)(P(y) v P(f(x,y))) ^ (z)(Q(x,z) ^ P(z))))
• Eliminate :
(x)(P(x) v ((y)(P(y) v P(f(x,y))) ^ (Q(x,g(x)) ^ P(g(x)))))
• Drop universal quantification
(P(x) v ((P(y) v P(f(x,y))) ^ (Q(x,g(x)) ^ P(g(x)))))
• Distribute " ^ " over " v " to get conjunctive normal form
(P(x) v P(y) v P(f(x,y))) ^ (P(x) v Q(x,g(x))) ^ (P(x) v P(g(x)))
• Create separate clauses
P(x) v P(y) v P(f(x,y)), P(x) v Q(x,g(x)), P(x) v P(g(x))
• Standardize variables
P(x) v P(y) v P(f(x,y)), P(z) v Q(z,g(z)), P(w) v P(g(w))
More Example:
Convert the following sentence to CNF
• Everyone who loves all animals is loved by
someone.

x[(y animal(y)  loves(x,y))  y loves(y,x) ]

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