Inference in FOL (AIMA Ch. 9)
Inference in FOL (AIMA Ch. 9)
9]
• Reducing first-order inference to
propositional inference
• Unification
• Generalized Modus Ponens
• Forward and backward chaining
• Logic programming
• Resolution
1
A brief history of reasoning
450b.c. Stoics propositional logic, inference (maybe)
322b.c. Aristotle “syllogisms” (inference rules), quantifiers
1565 Cardano probability theory (propositional logic+
uncertainty)
1847 Boole propositional logic (again)
1879 Freg first-order logic
1922 e proof by truth tables
1930 Wittgenstein ∃ complete algorithm for
1930 Gödel FOL
Herbrand complete algorithm for FOL (reduce to
1931 Gödel propositional)
1960 Davis/Putnam ¬∃ complete algorithm for arithmetic
“practical” algorithm for propositional
1965 Robinson logic
“practical” algorithm for FOL—
resolution
2
Universal instantiation (UI)
• Every instantiation of a universally quantified sentence
is entailed by it:
∀vα
SUBST({v/g}, α)
3
Existential instantiation (EI)
• For any sentence α, variable v, and constant symbol k that does
not appear elsewhere in the knowledge base:
∃v α
SUBST({v/k}, α)
4
Existential instantition contd.
• UI can be applied several times to add new
sentences; the new KB is logically equivalent to the
old
5
Reduction to propositional inference
Suppose the KB contains just the following:
∀x K ing(x) ∧ Greedy(x) ⇒ E vil(x)
K ing(J ohn)
Greedy(J ohn)
Brother(Richard, J ohn)
The new KB is 6
Reduction contd.
• 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)))
7
Reduction contd.
• 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 and see if α is entailed by KB
• Problem: works if α is entailed, loops if α is not
entailed
• Theorem: Turing (1936), Church (1936),
entailment in FOL is semidecidable
8
Problems with propositionalization
• Propositionalization seems to generate lots of
irrelevant sentences.
• E.g., from
∀x K ing(x) ∧ Greedy(x) ⇒ E vil(x)
K ing(J ohn)
∀y Greedy(y)
Brother(Richard, J ohn)
• it seems obvious that E vil(J ohn), but propositionalization
produces lots of facts such as Greedy(Richard) that are
irrelevant
• With p k-ary predicates and n constants, there are p · nk
instantiations
• With function symbols, it gets much much worse!
9
Unification
• We can get the inference immediately if we can find
a substitution θ such that K ing(x) and Greedy(x)
match K ing(John) and Greedy(y)
• θ = {x/John, y/John} works
• UNIFY(α, β) = θ if αθ = βθ
p q θ
K nows(J ohn, x) K nows(J ohn, J ane) {x/J ane}
K nows(J ohn, x) K nows(y,OJ) {x/OJ , y/J ohn}
K nows(J ohn, x) K nows(y,M other(y)) {y/J ohn, x/M other(J ohn)}
K nows(J ohn, x) K nows(x,OJ ) f ail
10
The unification algorithm
11
The unification algorithm
12
Generalized Modus Ponens (GMP)
p1’, p2’, … , pn’ , (p1 ∧ p2 ∧ … ∧ pn ⇒ q)
qθ
13
Soundness of GMP
Need to show that
14
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.
15
Example knowledge base contd.
… 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) ∧ M issile(x):
16
Forward chaining algorithm
17
Forward chaining proof
18
Forward chaining proof
19
Forward chaining proof
20
Properties of forward chaining
• Sound and complete for first-order definite clauses
(proof similar to propositional proof)
• Datalog = first-order definite clauses + no
functions (e.g., crime KB)
• FC terminates for Datalog in poly iterations: at
most p · nk literals
• May not terminate in general if α is not
entailed
• This is unavoidable: entailment with definite
clauses is semidecidable
21
Efficiency of forward chaining
• Simple observation: no need to match a rule on iteration k if
a premise wasn't added on iteration k-1
⇒ match each rule whose premise contains a newly added literal
22
Hard matching example
24
Backward chaining example
25
Backward chaining example
26
Backward chaining example
27
Backward chaining example
28
Backward chaining example
29
Backward chaining example
30
Backward chaining example
31
Properties of backward chaining
Depth-first recursive proof search: space is linear in size of
proof
32
Logic programming
• Sound bite: computation as inference on logical
KBs
Logic programming Ordinary programming
1. Identify problem Identify problem
2. Assemble information Assemble information
3. Tea break Figure out solution
4. Encode information in Program solution
KB Encode problem as data
5. Encode problem as Apply program to data
facts Debug procedural
6. Ask queries errors
7. Find false
Should factsto debug Capital(NewYork,US) than x := x + 2!
be easier
33
Prolog systems
•Basis: backward chaining with Horn clauses + bells & whistles Widely
used in Europe, Japan (basis of 5th Generation project) Compilation
techniques ⇒ approaching a billion LIPS
35
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 )=θ.
For example,
¬Rich(x) ∨ Unhappy(x)
Rich(K en)
Unhappy(K en)
with θ = {x/K en}
37
Conversion to CNF contd.
38
Resolution proof: definite clauses
39