Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 47

Inference in FOL

Ch-4-II

10/16/2021 Inference in FOL 1


Introduction
• Inferencing is the process of driving new sentences from the old
sentences which is KB. We have seen different kind of inferencing
rules in propositional logic and these rules holds in first-order logic
as well.
• But we need additional inference rules to handle first-order logic
sentences with quantifiers
• The three additional rules, we introduce here are more complex
than previous ones, because we have to talk about substituting
particular individuals for the variables.
• We will use the notation SUBST(θ, a) to denote the result of applying
the substitution (or binding list) to the sentence a. For example:
• SUBST({x/Sam, y/Pam], Likes(x,y)) = Likes(Sam,Parri).

10/16/2021 Inference in FOL 2


Universal Instantiation/Elimination
• Universal elimination
• Infer any sentence by substituting a ground term (a term without variables) for
the variable
Ѵx(P(x))
•  .’. P(C)
Ѵ==for all
• for any variable v and ground term g
• Or, If “Vx P(x) is true, then P(c) is true, where c is a constant in the domain of x.
• Example: determine whether the argument “ all students in this class understand logic. Alex is student
in this class. Therefore, Alex understands logic.” is it correct or not?
• Assume, P(x) denotes “X is a student in this class” Q(x) denotes “x understands logic”
1. Ѵx(P(x)Q(x) premise
2. P(Alex) premise
3. P(Alex)Q(Alex) by universal elimination (1)
4. Q(Alex) by modus Ponens from 2 and 3 yes

10/16/2021 Inference in FOL 3


Existential elimination
• For any sentence α, variable v, and constant symbol k that does NOT appear
elsewhere in the knowledge base, replace v with k.
$x P(x)
•  .’. P(k)

• It allows as to conclude that there is some element k for which P(k) is true when $x
P(x) is true
• For example, from $x Kill(x, Victim), we can infer Kill(Murderer, Victim), as long as
Murderer does not appear elsewhere in the knowledge base.
• From $x P(x) infer P(k).
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.

10/16/2021 Inference in FOL 4


Example
• Suppose a knowledge base contains just one
sentence,$x AsHighAs(x, Everest). Which of the
following are legitimate results of applying Existential
Instantiation?

• AsHighAs(Everest, Everest)
• AsHighAs(Kilimanjaro, Everest)
• AsHighAs(Kilimajaro, Everest) and AsHighAs(BenNevis,
Everest)

10/16/2021 Inference in FOL 5


Proof
• 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 (4, 5)

10/16/2021 Inference in FOL 6


Reduction to Propositional Inference
• Suppose the KB contains just the following:
• " x King(x) ^ Greedy(x) Evil(x)
• King(John)
• Greedy(John)
• Brother(Richard,John)
• Instantiating the universal sentence in all possible ways, we have:
• King(John) ^ Greedy(John)Evil(John)
• King(Richard) ^ Greedy(Richard)Evil(Richard)
• King(John)
• Greedy(John)
• Brother(Richard,John)
• The new KB is propositionalized: proposition symbols are
• King(John), Greedy(John), Evil(John), King(Richard), etc.

10/16/2021 Inference in FOL 7


Problems with proposition
• Propositionalizing seems to generate a lots of irrelevant sentences

• It seems obvious that Evil(John) is true, but propositionalization


produces lots of facts such as Greedy(Richard) that are irrelevant
• Propozitionalization approach is rather inefficient  other option
10/16/2021 Inference in FOL 8
FOL-inference rule(sound)
• If there is some substitution θ that makes the premise of the
implication identical to sentences already in the KB, then we assert
the conclusion of the implication, after applying θ.

• Sometimes we need to find a substitution θ both for the variables in


the implication and in the sentence to be matched.

Subs using, {x/john,y/john}

10/16/2021 Inference in FOL 9


Generalized Modus Ponens (GMP)
• For atomic sentences pi, pi’ and q where there is a substitution θ such
that Subst(θ,pi’)=Subst(θ,pi), for all i.
Both Ps are analogues

Can be used with KB of definite clauses (exactly one positive literal)

10/16/2021 Inference in FOL 10


Generalized Modus Ponens (GMP)
• Combines And-Introduction, Universal-Elimination, and Modus Ponens
• Given atomic sentences P1, P2, ..., PN, and 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.

10/16/2021 Inference in FOL 11


Horn clause
• 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
10/16/2021 Inference in FOL 12
Unification
• GMP is a lifted version of Modus Ponens and raises Modus
Ponens from propositional to FOL.
• Lifted inference rules require finding substitutions that
make different logical expressions look identical.
• This process is called unification and is a key component of
all first-order inference algorithms
• The unify algorithm takes two sentences and returns a
unifier for them if one exists:
• UNIFY(p,q) = θ where Subst(θ, p) = Subst(θ, q)

10/16/2021 Inference in FOL 13


Unification example

• Standardizing apart: renaming variables to avoid name clashes


UNIFY(Knows(John, x), Knows(z, OJ)) = {x/OJ, z/John}
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,OJ)
Likes(John,Mother(John))
10/16/2021 Inference in FOL 14
More on Unification example
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(z)) x/Bill, y/Bill, z/dog(jane)

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.
10/16/2021 Inference in FOL 15
Example of KB
• 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 (rules of KB)
• American(x): x is an American
• Weapon(x): x is a weapon
• Hostile(x): x is a hostile nation
• Criminal(x): x is a criminal
• Missile(x): x is a missile
• Owns(x, y): x owns y
• Sells(x, y, z): x sells y to z
• Enemy(x, y): x is an enemy of y
• Constants: America, Nono, West

10/16/2021 Inference in FOL 16


Cont…
R1. American(x) ^ Weapon(y) ^ Sells(x,y,z) ^ Hostile(z)  Criminal(x)
... it is a crime for an American to sell weapons to hostile nations:
R2. Owns(Nono,M1) non has some missiels
R3. Missiel(M1) m1 is missile
R4. Missile(x)  Weapon(x) a missile is a weapon
R5. Missile(x) ^ Owns(Nono, x)  Sells(West, x,Nono) all missiels sold by nono
R6. Enemy(x, America) Hostile(x) enemy of America are hostile
R7. American(West) west is American
R8. Enemy(Nono, America) a country Nono an enemy of America
Proof, west is criminal
10/16/2021 Inference in FOL 17
Forward chaining ask
iterations
• Iteration 1
• R5 satisfied with {x/M1} ans R9: Sells(West,M1,Nono) is added to KB
• R4 satisfied with {x/M1} and R10: Weapon(M1) is added
• R6 satisfied with {x,/Nono} and R11: Hostile(Nono) is added
• Iteration 2:
• R1 is satisfied with {x/West,y/M1, z/Nono and Criminal(West) will be added
• Adding rules by unification continue until we get the value of the
variable and reach to our goal.
• Then ask like Criminal(west) …returns yes

10/16/2021 Inference in FOL 18


Inference in FOL
• Once we have facts that evaluates to T or F
• We can apply Forward Chaining, Backwards Chaining and resolution
algorithm
• The key is to understand unification
• Very similar to logical agents

10/16/2021 Inference in FOL 19


Forward Chaining
• Starting from known facts, it triggers all the rules
whose premises are satisfied, adding their conclusions
to the known facts. This process will continue until
query is answered.
• When a new fact P is added to the KB:
• For each rule such that P unifies with a premise
• if the other premises are already known
• then add the conclusion to the KB and continue chaining
• Forward chaining is data-driven:
• inferring properties and categories from percepts
10/16/2021 Inference in FOL 20
Consider this example
R1. American(x) ^ Weapon(y) ^ Sells(x,y,z) ^ Hostile(z)  Criminal(x)
... it is a crime for an American to sell weapons to hostile nations:
R2. Owns(Nono,M1) non has some missiels
R3. Missiel(M1) m1 is missile
R4. Missile(x)  Weapon(x) a missile is a weapon
R5. Missile(x) ^ Owns(Nono, x)  Sells(West, x,Nono) all missiels sold by nono
R6. Enemy(x, America) Hostile(x) enemy of America are hostile
R7. American(West) west is American
R8. Enemy(Nono, America) a country Nono an enemy of America
Proof, west is criminal
10/16/2021 Inference in FOL 21
Forward chaining proof

10/16/2021 Inference in FOL 22


Forward chaining proof

10/16/2021 Inference in FOL 23


Forward chaining proof

10/16/2021 Inference in FOL 24


Analysis of FC
• A fixed point of the inference process can be reached
• The algorithm is sound and complete
• Its efficiency can be improved

10/16/2021 Inference in FOL 25


Sources of complexity
• 1. “Inner loop” involves finding all possible unifiers such that the
premise of a rule unifies with facts in the KB
• Often called “pattern matching”, very expensive
• 2. The algorithm rechecks every rule on every iteration to see
whether its premises are met
• 3. It might generate many facts that are irrelevant to the goal

• Solution? Backwards chain

10/16/2021 Inference in FOL 26


Backwards Chaining
• p1 and p2 … pn q ==
• When a query q is examined:
• if a matching fact q' is known, return the unifier
• for each rule whose consequent q' matches q
• attempt to prove each premise of the rule by 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

• Backward chaining is the basis for “logic programming,” e.g., Prolog


10/16/2021 Inference in FOL 27
Backward Chaining Example

10/16/2021 Inference in FOL 28


Backward Chaining Example

10/16/2021 Inference in FOL 29


Backward Chaining Example

10/16/2021 Inference in FOL 30


Backward Chaining Example

10/16/2021 Inference in FOL 31


Backward Chaining Example

10/16/2021 Inference in FOL 32


Backward Chaining Example

10/16/2021 Inference in FOL 33


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.
• Generalized Resolution inference rule provides a complete system for
proof by refutation/contradiction.
• Resolution is a generalization of modus ponens
• It requires a normal form, but any sentence can be put into CNF
•Unification is a key concept in proof by resolution
•Clause is disjunctive of literals and CNF is a sentence represented as a
conjunction of clauses

10/16/2021 Inference in FOL 34


Resolution
• 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)
10/16/2021 Inference in FOL 35
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)
10/16/2021 Inference in FOL 36
Generalized Resolution

• The steps in resolutions are:


• Convert the facts/sentences to FOL
• Convert FOL statement to CNF
• Negate the statement which needs to
prove(by contradiction)
• Draw the resolution graph(apply
unification)

10/16/2021 Inference in FOL 37


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/costant.
• 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.
10/16/2021 Inference in FOL 38
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: (unique variable for each quantifier)
(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)) horn clause
• Standardize variables
10/16/2021
P(x) v P(y) v P(f(x,y)), P(z) v Q(z,g(z)), P(w) v P(g(w))
Inference in FOL 39
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) ]

10/16/2021 Inference in FOL 40


Recall the Previous Example

Query: ~Criminal(West)
10/16/2021 Inference in FOL 41
Resolution Graph Proof

Empty { }
10/16/2021 Inference in FOL 42
Resolution Refutation Proof
Practice exercise
• Jack owns a dog. Every dog owner is an animal lover. No
animal lover kills an animal. Either Jack or Curiosity killed
the cat, who is named Tuna. Did Curiosity kill the cat?
• FOL representation:
A. (x) Dog(x)  Owns(Jack,x)
B. (x) ((y) Dog(y)  Owns(x, y))  AnimalLover(x)
C. (x) AnimalLover(x)  ((y) Animal(y)  Kills(x,y))
D. Kills(Jack,Tuna)  Kills(Curiosity,Tuna)
E. Cat(Tuna)
F. (x) Cat(x)  Animal(x)
G. Kills(Curiosity, Tuna)

10/16/2021 Inference in FOL 43


Annexes

10/16/2021 Inference in FOL 44


Backwards chaining algorithm

10/16/2021 Inference in FOL 45


Forward chaining example
•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.

10/16/2021 Inference in FOL 46


Backward chaining example
•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,
• So we conclude. Yes, Ziggy eats fish

10/16/2021 Inference in FOL 47

You might also like