Inference in First-Order Logic
Philipp Koehn 12 March 2019
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
Inference in First-Order Logic Philipp Koehn 12 March 2019 Philipp - - PowerPoint PPT Presentation
Inference in First-Order Logic Philipp Koehn 12 March 2019 Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019 A Brief History of Reasoning 1 450 B . C . Stoics propositional logic, inference (maybe) 322 B .
Philipp Koehn 12 March 2019
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
1
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 Frege first-order logic 1922 Wittgenstein proof by truth tables 1930 G¨
∃ complete algorithm for FOL 1930 Herbrand complete algorithm for FOL (reduce to propositional) 1931 G¨
¬∃ complete algorithm for arithmetic 1960 Davis/Putnam “practical” algorithm for propositional logic 1965 Robinson “practical” algorithm for FOL—resolution
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
2
– forward chaining – backward chaining – resolution (for full propositional logic)
– variables – functions – quantifiers – etc.
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
3
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
4
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
5
∀v α SUBST({v/g},α) for any variable v and ground term g
⇒ Evil(x) yields King(John) ∧ Greedy(John) ⇒ Evil(John) King(Richard) ∧ Greedy(Richard) ⇒ Evil(Richard) King(Father(John)) ∧ Greedy(Father(John)) ⇒ Evil(Father(John)) ⋮
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
6
that does not appear elsewhere in the knowledge base: ∃v α SUBST({v/k},α)
Crown(C1) ∧ OnHead(C1,John) provided C1 is a new constant symbol, called a Skolem constant
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
7
– can be applied several times to add new sentences – the new KB is logically equivalent to the old
– can be applied once to replace the existential sentence – the new KB is not equivalent to the old – but is satisfiable iff the old KB was satisfiable
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
8
∀x King(x) ∧ Greedy(x) ⇒ Evil(x) King(John) Greedy(John) Brother(Richard,John)
King(John) ∧ Greedy(John) ⇒ Evil(John) King(Richard) ∧ Greedy(Richard) ⇒ Evil(Richard) King(John) Greedy(John) Brother(Richard,John)
King(John), Greedy(John), Evil(John),Brother(Richard,John),etc.
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
9
e.g., Father(Father(Father(John)))
it is entailed by a finite subset of the propositional KB
create a propositional KB by instantiating with depth-n terms see if α is entailed by this KB
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
10
∀x King(x) ∧ Greedy(x) ⇒ Evil(x) King(John) ∀y Greedy(y) Brother(Richard,John) it seems obvious that Evil(John), but propositionalization produces lots of facts such as Greedy(Richard) that are irrelevant
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
11
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
12
– ∀x King(x) ∧ Greedy(x) ⇒ Evil(x)
– King(John) – ∀y Greedy(y)
– unification – generalized modus ponens
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
13
p q θ Knows(John,x) Knows(John,Jane) Knows(John,x) Knows(y,Mary) Knows(John,x) Knows(y,Mother(y)) Knows(John,x) Knows(x,Mary)
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
14
p q θ Knows(John,x) Knows(John,Jane) {x/Jane} Knows(John,x) Knows(y,Mary) Knows(John,x) Knows(y,Mother(y)) Knows(John,x) Knows(x,Mary)
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
15
p q θ Knows(John,x) Knows(John,Jane) {x/Jane} Knows(John,x) Knows(y,Mary) {x/Mary,y/John} Knows(John,x) Knows(y,Mother(y)) Knows(John,x) Knows(x,Mary)
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
16
p q θ Knows(John,x) Knows(John,Jane) {x/Jane} Knows(John,x) Knows(y,Mary) {x/Mary,y/John} Knows(John,x) Knows(y,Mother(y)) {y/John,x/Mother(John)} Knows(John,x) Knows(x,Mary)
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
17
p q θ Knows(John,x) Knows(John,Jane) {x/Jane} Knows(John,x) Knows(y,Mary) {x/Mary,y/John} Knows(John,x) Knows(y,Mother(y)) {y/John,x/Mother(John)} Knows(John,x) Knows(x,Mary) fail
Knows(John,x) Knows(z17,Mary) {z17/John,x/Mary}
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
18
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
19
(exactly one positive literal)
p1′, p2′, ..., pn′, (p1 ∧ p2 ∧ ... ∧ pn ⇒ q) qθ where pi′θ =piθ for all i
King(x) ∧ Greedy(x) ⇒ Evil(x)
p1 is King(x) p2 is Greedy(x)
q is Evil(x)
p1′ is King(John) p2′ is Greedy(y)
θ is {x/John,y/John} ⇒ Result of modus ponens: qθ is Evil(John)
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
20
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
21
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.
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
22
American(x) ∧ Weapon(y) ∧ Sells(x,y,z) ∧ Hostile(z) ⇒ Criminal(x)
Owns(Nono,M1) and Missile(M1)
∀x Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono)
Missile(x) ⇒ Weapon(x)
Enemy(x,America) ⇒ Hostile(x)
American(West)
Enemy(Nono,America)
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
23
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
24
(Note: ∀x Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono))
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
25
(Note: American(x) ∧ Weapon(y) ∧ Sells(x,y,z) ∧ Hostile(z) ⇒ Criminal(x))
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
26
(proof similar to propositional proof)
Forward chaining terminates for Datalog in poly iterations: at most p ⋅ nk literals
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
27
if a premise wasn’t added on iteration k − 1
e.g., query Missile(x) retrieves Missile(M1)
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
28
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)
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
29
function FOL-FC-ASK(KB,α) returns a substitution or false repeat until new is empty new←∅ for each sentence r in KB do (p1 ∧ ... ∧ pn ⇒ q)← STANDARDIZE-APART(r) for each θ such that (p1 ∧ ... ∧ pn)θ = (p′
1 ∧ ... ∧ p′ n)θ
for some p′
1,...,p′ n in KB
q′ ← SUBST(θ, q) if q′ is not a renaming of a sentence already in KB or new then do add q′ to new φ← UNIFY(q′,α) if φ is not fail then return φ add new to KB return false
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
30
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
31
– apply rules that infer the query – recurse over pre-conditions
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
32
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
33
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
34
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
35
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
36
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
37
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
38
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
39
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
40
function FOL-BC-ASK(KB,goals,θ) returns a set of substitutions inputs: KB, a knowledge base goals, a list of conjuncts forming a query (θ already applied) θ, the current substitution, initially the empty substitution ∅ local variables: answers, a set of substitutions, initially empty if goals is empty then return {θ} q′ ← SUBST(θ, FIRST(goals)) for each sentence r in KB where STANDARDIZE-APART(r) = (p1 ∧ ... ∧ pn ⇒ q) and θ′ ← UNIFY(q,q′) succeeds new goals←[p1,...,pn∣REST(goals)] answers← FOL-BC-ASK(KB, new goals, COMPOSE(θ′,θ)) ∪ answers return answers
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
41
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
42
Logic programming Ordinary programming 1. Identify problem Identify problem 2. Assemble information Assemble information 3. Tea break Figure out solution 4. Encode information in KB Program solution 5. Encode problem instance as facts Encode problem instance as data 6. Ask queries Apply program to data 7. Find false facts Debug procedural errors
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
43
criminal(X) :- american(X), weapon(Y), sells(X,Y,Z), hostile(Z). missile(M1).
sells(West,X,Nono) :- missile(X), owns(Nono,X). weapon(X) :- missile(X). hostile(X) :- enemy(X,America). American(West). Enemy(Nono,America).
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
44
e.g., given alive(X) :- not dead(X). alive(joe) succeeds if dead(joe) fails
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
45
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
46
ℓ1 ∨ ⋯ ∨ ℓk, m1 ∨ ⋯ ∨ mn (ℓ1 ∨ ⋯ ∨ ℓi−1 ∨ ℓi+1 ∨ ⋯ ∨ ℓk ∨ m1 ∨ ⋯ ∨ mj−1 ∨ mj+1 ∨ ⋯ ∨ mn)θ where UNIFY(ℓi,¬mj)=θ.
¬Rich(x) ∨ Unhappy(x) Rich(Ken) Unhappy(Ken) with θ = {x/Ken}
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
47
Everyone who loves all animals is loved by someone: ∀x [∀y Animal(y) ⇒ Loves(x,y)] ⇒ [∃y Loves(y,x)]
∀x [¬∀y ¬Animal(y) ∨ Loves(x,y)] ∨ [∃y Loves(y,x)]
¬∃x,p ≡ ∀x ¬p: ∀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)]
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
48
∀x [∃y Animal(y) ∧ ¬Loves(x,y)] ∨ [∃z Loves(z,x)]
Each existential variable is replaced by a Skolem function
∀x [Animal(F(x)) ∧ ¬Loves(x,F(x))] ∨ Loves(G(x),x)
[Animal(F(x)) ∧ ¬Loves(x,F(x))] ∨ Loves(G(x),x)
[Animal(F(x)) ∨ Loves(G(x),x)] ∧ [¬Loves(x,F(x)) ∨ Loves(G(x),x)]
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
49
– American(x) ∧ Weapon(y) ∧ Sells(x,y,z) ∧ Hostile(z) ⇒ Criminal(x) – Missile(M1) and Owns(Nono,M1) – ∀x Missile(x) ∧ Owns(Nono,x) ⇒ Sells(West,x,Nono) – Missile(x) ⇒ Weapon(x) – Enemy(x,America) ⇒ Hostile(x) – American(West) – Enemy(Nono,America)
– ¬American(x) ∨ ¬Weapon(y) ∨ ¬Sells(x,y,z) ∨ ¬Hostile(z) ∨ Criminal(x) – Missile(M1) and Owns(Nono,M1) – ¬Missile(x) ∨ ¬Owns(Nono,x) ∨ Sells(West,x,Nono) – ¬Missile(x) ∨ Weapon(x) – ¬Enemy(x,America) ∨ Hostile(x) – American(West) – Enemy(Nono,America)
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019
50
Philipp Koehn Artificial Intelligence: Inference in First-Order Logic 12 March 2019