First Order Logic + Inference in First Order Logic
First Order Logic + Inference in First Order Logic
Chapter 8
Introduction
• Knowledge is represented in 2 ways:
• Propositional & First-order Logic
• Statements are represented using propositional logic.
•Constants - objects
•Predicates - relations; Brother, >,...
•Functions- Sqrt, plus etc
•Atomic sentence state facts:
•Brother(Richard, John)
•predicate and function have arity.
•Eg: Likes(Jane, Pizza)- 2 arity
•Term is a logical expression that refers to an
object.
•Eg:LeftLeg(John)
Atomic sentences
•Atomic sentences are the most basic
sentences of first-order logic. These
sentences are formed from a predicate
symbol followed by a parenthesis with a
sequence of terms.
•We can represent atomic sentences as
Predicate (term1, term2, ......, term n).
•Example: Ravi and Ajay are brothers: =>
Brothers(Ravi, Ajay).
•Brother (Richard, John).
Complex Sentences
1. Pizza is a food
2. Tom likes pizza
3. All birds fly.
4. All kings are person
5. No one likes math
1. Every man respects his parent. ∀x man(x) → respects (x,
parent).
2. Some boys play cricket. ∃x boys(x) → play(x, cricket).
3. Brothers are siblings.
4. All indoor games are easy.
5. Caesar was a king
Nested quantifiers
• Nested quantifiers are a concept in predicate logic
where multiple quantifiers (like ∀ for "for all" and ∃
for "there exists") are used together ,often with one
quantifier inside the scope of another.
• Two quantifiers are said to be nested if one is within
the scope of the other.
• ∀x ∀y P(x, y): This means "for all x and for all y, P(x, y)
is true." Here, the proposition P applies universally to
all pairs of x and y.
• For example, “Brothers are siblings” can be written as
• ∀ x ∀ y Brother (x, y) ⇒ Sibling(x, y) .
•∃x ∃y P(x, y): This means "there exists an x and
there exists a y such that P(x, y) is true." Here, there
is at least one pair of x and y for which the
proposition P is true.
•∀x ∃y P(x, y): This means "for all x, there exists a
y such that P(x, y) is true." In other words, for each
x, you can find at least one y that makes P(x, y)
true.
•∀x ∃y (x + y = 0): This means for every real
number x, there exists a real number y (specifically
y = -x) such that x + y = 0.
Equality
• The first step of the process is to identify the task, and for the digital
circuit, there are various reasoning tasks.
• At the first level or highest level, we will examine the functionality of
the circuit:
• Does the circuit add properly?
• What will be the output of gate A2, if all the inputs are high?
• At the second level, we will examine the circuit structure details such
as:
• Which gate is connected to the first input terminal?
• Does the circuit have feedback loops?
Assemble the relevant knowledge:
• function Arity(c, i, j)
• The function Arity(c, i, j) says that circuit c has i input and j
output terminals.
• The connectivity between gates can be represented by a
predicate, Connected, which takes two terminals as
arguments, as in Connected(Out(1,X1), In(1,X2)).
• Connected is commutative:
• ∀ t1, t2 Connected(t1, t2) ⇔ Connected(t2, t1) .
• An OR gate’s output is 1 if and only if any of its inputs is 1:
• ∀ g Gate(g) ∧ Type(g)=OR ⇒
• Signal (Out(1, g))= 1 ⇔ ∃n Signal (In(n, g))=1 .
39
Inference Engine
• When the If (condition) part of the rule matches the fact, the rule is
fired, and its THEN (action ) part is executed.
43
Properties
Backward chaining
46
Forward vs. backward chaining
• FC is data-driven
• Automatic, unconscious processing
• E.g., object recognition, routine decisions
• May do lots of work that is irrelevant to the goal
• BC is goal-driven, appropriate for problem-solving
• Where are my keys? How do I get to my next class?
• Complexity of BC can be much less than linear in the size of the KB
47
Resolution
48
Resolution in first-order logic
• Given sentences
P1 ∨ ... ∨ Pn
Q1 ∨ ... ∨ Qm
• in conjunctive normal form:
• 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 ∨... ∨ Pj-1 ∨ Pj+1 ... Pn ∨ Q1 ∨ …Qk-1 ∨ Qk+1 ∨... ∨ Qm)
• Example
• from clause P(x, f(a)) ∨ P(x, f(y)) ∨ Q(y)
• and clause ¬P(z, f(a)) ∨ ¬Q(z)
• derive resolvent P(z, f(y)) ∨ Q(y) ∨ ¬Q(z)
• using θ = {x/z}
49
Unification
51
Unification algorithm
procedure unify(p, q, θ)
Scan p and q left-to-right and find the first corresponding
terms where p and q “disagree” (i.e., p and q not equal)
If there is no disagreement, return θ (success!)
Let r and s be the terms in p and q, respectively,
where disagreement first occurs
If variable(r) then {
Let θ = union(θ, {r/s})
Return unify(subst(θ, p), subst(θ, q), θ)
} else if variable(s) then {
Let θ = union(θ, {s/r})
Return unify(subst(θ, p), subst(θ, q), θ)
} else return “Failure”
end
52
Unification examples
• Example:
• parents(x, father(x), mother(Bill))
• parents(Bill, father(Bill), y)
• {x/Bill, y/mother(Bill)}
• Example:
• parents(x, father(x), mother(Bill))
• parents(Bill, father(y), z)
• {x/Bill, y/Bill, z/mother(Bill)}
• Example:
• parents(x, father(x), mother(Jane))
• parents(Bill, father(y), mother(y))
• Failure
53
Resolution example
54
Practice example
Did Curiosity kill the cat
• 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?
• These can be represented as follows:
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)
GOAL
55
• Convert to clause form
A1. (Dog(D))
A2. (Owns(Jack,D))
D is a skolem constant
B. (¬Dog(y), ¬Owns(x, y), AnimalLover(x))
C. (¬AnimalLover(a), ¬Animal(b), ¬Kills(a,b))
D. (Kills(Jack,Tuna), Kills(Curiosity,Tuna))
E. Cat(Tuna)
F. (¬Cat(z), Animal(z))
• Add the negation of query:
¬G: (¬Kills(Curiosity, Tuna))
56
• The resolution refutation proof
R1: ¬G, D, {} (Kills(Jack, Tuna))
R2: R1, C, {a/Jack, b/Tuna} (~AnimalLover(Jack),
~Animal(Tuna))
R3: R2, B, {x/Jack} (~Dog(y), ~Owns(Jack, y),
~Animal(Tuna))
R4: R3, A1, {y/D} (~Owns(Jack, D),
~Animal(Tuna))
R5: R4, A2, {} (~Animal(Tuna))
R6: R5, F, {z/Tuna} (~Cat(Tuna))
R7: R6, E, {} FALSE
57
• The proof tree
¬G D
{}
R1: K(J,T) C
{a/J,b/T}
R2: ¬AL(J) ∨ ¬A(T) B
{x/J}
R3: ¬D(y) ∨ ¬O(J,y) ∨ ¬A(T) A1
{y/D}
R4: ¬O(J,D), ¬A(T) A2
{}
R5: ¬A(T) F
{z/T}
R6: ¬C(T) A
{}
R7: FALSE
58
Example
1. ¬Battery-OK ∨ ¬Bulbs-OK ∨ Headlights-Work
2. ¬Battery-OK ∨ ¬Starter-OK ∨ Empty-Gas-Tank ∨ Engine-Starts
3. ¬Engine-Starts ∨ Flat-Tire ∨ Car-OK
4. Headlights-Work
5. Battery-OK
6. Starter-OK
7. ¬Empty-Gas-Tank
8. ¬Car-OK
9. ¬Flat-Tire negated goal
59