Logic2 6pp
Logic2 6pp
Syntax
formula
Review
Semantics
models
Inference rules
Inference task
Inference task Input: Knowledge base KB (e.g., {Rain, Rain Wet}) Query formula f (e.g., Wet) Output: Whether KB entails f (KB |= f )? (e.g., yes)
Review: formulas
Propositional logic: any combination of symbols
restricted to
Review: inference
Inference algorithm: (repeatedly apply inference rules) KB f
Formulas allowed
Approaches
Inference rule Complete?
Propositional logic
Modus ponens no
Propositional logic
resolution
yes
Roadmap
Resolution in propositional logic
First-order logic
Horn clauses: at most one positive propositional symbol Clause: disjunction of literals Literal: either p or p, where p is a propositional symbol
Other logics
Resolution
General clauses have any number of literals: A B C D E F Denition: resolution inference rule f1 fn p, p g1 gm f1 fn g1 gm Example: Rain Snow, Snow Trac Rain Trac Snow, Snow false
CS221: Articial Intelligence (Autumn 2013) - Percy Liang 8
Soundness of resolution
Rain Snow Snow Trac (resolution rule) Rain Trac
M(Rain Snow)M(Snow Trac)?M(Rain Trac)
Snow 0 1 Rain, Trac Rain, Trac 0,0 0,1 1,0 1,1 0,0 0,1 1,0 1,1 Snow 0 1 Rain, Trac 0,0 0,1 1,0 1,1 Snow 0 1
Sound!
10
11
Resolution algorithm
Recall: KB operations boil down to satisability KB |= f KB {f } is unsatisable
KB |= f
KB {f } is unsatisable
Algorithm: resolution-based inference Convert all formulas into CNF. Repeatedly apply resolution rule. Return unsatisable i derive false.
f (g h ) ( f g ) (g h )
12
13
Resolution: example
Knowledge base (is it satisable?): KB = {A (B C ), A, B, C } Convert to CNF: KB = {A B C, A, B, C } Repeatedly apply resolution rule:
p1 ,
Time complexity
Denition: Modus ponens inference rule , pk , (p1 pk ) q q
Each rule application adds clause with one propositional symbol linear time
Denition: resolution inference rule
false C BC A B C
CS221: Articial Intelligence (Autumn 2013) - Percy Liang
C B
f1 fn h, h g1 gm f1 fn g1 gm
Each rule application adds clause with many propositional symbols exponential time
A
14 CS221: Articial Intelligence (Autumn 2013) - Percy Liang 15
Unsatisable!
Summary
Horn clauses any clauses
Roadmap
Resolution in propositional logic
Modus ponens
linear time
exponential time
less expressive
16
17
Propositional logic is very clunky. Whats missing? Objects and relations: propositions (e.g., AliceKnowsArithmetic) have more internal structure (alice, Knows, arithmetic) Quantiers and variables: all is a quantier which applies to each person, dont want to enumerate them all...
Every even integer greater than 2 is the sum of two primes. ???
18
19
First-order logic
Syntax
formula models
Semantics
Inference rules
20
21
Quantiers
Universal quantication (): Every student knows arithmetic. x Student(x)Knows(x, arithmetic) Existential quantication (): Some student knows arithmetic. x Student(x)Knows(x, arithmetic) Note the dierent connectives!
23
Quantiers
Universal quantication (): Think conjunction: x P (x) is like P (A) P (B ) Existential quantication (): Think disjunction: x P (x) is like P (A) P (B ) Some properties: x P (x) equivalent to x P (x) x y Knows(x, y ) dierent from y x Knows(x, y )
If a student takes a course and the course covers some concept, then the student knows that concept.
x y z (Student(x) Takes(x, y ) Course(y ) Covers(y, z )) Knows(x, z )
24
25
First-order logic
Syntax
formula models
Semantics
First-order logic: Model w maps atomic formulas to truth values (this is almost right, but not quite).
w = {Knows(alice, arithmetic) : 1, Knows(bob, arithmetic) : 0}
Inference rules
Problem is that if bob and robert refer to the same person, then w(Knows(bob, arithmetic)) must equal w(Knows(robert, arithmetic))
26
27
o2 robert
Knows
o3 arithmetic Nodes are objects, labeled with constant symbols Directed edges are relations, labeled with predicate symCS221: Articial Intelligence (Autumn 2013) - Percy Liang bols
28
29
A restriction on models
John and Bob are students. Student(john) Student(bob)
w1
Student Student
Propositionalization
If one-to-one mapping between constant symbols and objects (unique names and domain closure), rst-order logic is syntactic sugar for propositional logic:
w2
Student
w3
Student Student
Knowledge base in rst-order logic Student(alice) Student(bob) x Student(x) Person(x) x Student(x) Creative(x)
Knowledge base in propositional logic Student(alice) Student(bob) (Student(alice) Person(alice)) (Student(bob) Person(bob)) (Student(alice) Creative(alice)) (Student(bob) Creative(bob))
john o1
o2 bob
john o1 bob
john o1
o2
o3 bob
Unique names assumption: Each object has at most one constant symbol. This rules out w2 . Domain closure: Each object has at least one constant symbol. This rules out w3 . Point: constant symbol
CS221: Articial Intelligence (Autumn 2013) - Percy Liang
First-order logic
Syntax
formula models
Denite clauses
Denition: denite clause (rst-order logic) A denite clause has the following form: x1 xn (a1 ak ) b for atomic formulas a1 , . . . , ak , b and variables x1 , . . . , xn . Example:
Semantics
Inference rules
x y z (Takes(x, y ) Covers(y, z )) Knows(x, z ) (if propositionalize, get one formula for each x, y, z )
32
33
Substitution
Denition: Substitution A substitution is a mapping from variables to constant symbols or other variables. Subst[, f ] returns the result of performing substitution on f . Examples:
Subst[{x/alice}, P (x)] = P (alice)
Substitution: morph a formula into another Unication: make two formulas the same
Subst[{x/alice, y/z }, P (x) K (x, y )] = P (alice) K (alice, z )
34
35
Unication
Denition: Unication Unication takes two formulas f and g and returns a substitution which is the most general unier: Unify[f, g ] = such that Subst[, f ] = Subst[, g ] or fail if no exists. Examples:
Unify[Knows(alice, arithmetic), Knows(x, arithmetic)] = {x/alice} Unify[Knows(alice, y ), Knows(x, z )] = {x/alice, y/z } Unify[Knows(alice, y ), Knows(bob, z )] = fail Unify[Knows(alice, y ), Knows(x, F (x))] = {x/alice, y/F (alice)}
Modus ponens
Denition: Modus ponens (rst-order logic) a1 , ak x1 xn (a1 ak ) b , b
36
37
Complexity
x y z P (x, y, z ) Each application of Modus ponens produces an atomic formula. If no function symbols, number of atomic formulas is at most (num-constant-symbols)(maximum-predicate-arity) If there are function symbols (e.g., F ), then innite...
Q(a) Q(F (a)) Q(F (F (a))) Q(F (F (F (a))))
Conclusion:
= {x/alice, y/cs221, z/mdp} Derive Knows(alice, mdp)
38
39
Complexity
Theorem: completeness Modus ponens is complete for rst-order logic with only Horn clauses. Theorem: semi-decidability First-order logic (even restricted to only Horn clauses) is semi-decidable. If KB |= f , forward inference on complete inference rules will prove f in nite time. If KB |= f , no algorithm can show this in nite time.
Resolution
Recall: First-order logic includes non-Horn clauses
x Student(x) y Knows(x, y )
High-level strategy (same as in propositional logic): Convert all formulas to CNF Repeatedly apply resolution rule
40
41
Conversion to CNF
Input: x (y Animal(y ) Loves(x, y )) y Loves(y, x) Output:
(Animal(Y (x)) Loves(Z (z ), x)) (Loves(x, Y (x)) Loves(Z (z ), x))
Conversion to CNF
Anyone who likes all animals is liked by someone. Input: x (y Animal(y ) Loves(x, y )) y Loves(y, x) Eliminate implications (old): x (y Animal(y ) Loves(x, y )) y Loves(y, x) Push inwards, eliminate double negation (old): x (y Animal(y ) Loves(x, y )) y Loves(y, x) Standardize variables (new): x (y Animal(y ) Loves(x, y )) z Loves(z, x)
New to rst-order logic: All variables (e.g., x) have universal quantiers by default Introduce Skolem functions (e.g., Y (x)) to represent existential quantied variables
42
43
Resolution
Denition: Resolution rule (rst-order logic) f1 fn h1 , h2 g1 gm Subst[, f1 fn g1 gm ] where = Unify[h1 , h2 ].
Example: resolution
Animal(Y (x)) Loves(Z (x), x), Loves(u, v ) Kills(u, v ) Animal(Y (x)) Kills(Z (x), x)
Interpretation: Y (x) represents animal that x doesnt like, Z (x) represents person who likes x
44
45
Summary
Propositional logic model checking First-order logic n/a propositionalization Modus ponens (Horn clauses) resolution (general) Modus ponens++ (Horn clauses) resolution++ (general) ++: unication and substitution Key idea: variables in rst-order logic Variables yield compact knowledge representations.
CS221: Articial Intelligence (Autumn 2013) - Percy Liang 46 CS221: Articial Intelligence (Autumn 2013) - Percy Liang
Roadmap
Resolution in propositional logic
First-order logic
Other logics
47
Motivation
Goal: represent knowledge and perform inferences Why use anything besides propositional or rst-order logic? Expressiveness: Temporal logic: express time Modal logic: express beliefs Higher-order logic: generalized quantiers Notational convenience, computational eciency: Description logic
Temporal logic
Barack Obama is the US president. President(BarackObama, US) George Washington was the US president. P President(GeorgeWashington, US) Some woman will be the US president. F x Female(x) President(x, US)
48
49
Temporal logic
Point: all formulas interpreted at a current time. The following operators change the current time and quantify over it (think of Pf as t [t < now] f (t)): P f : f held at some point in the past F f : f will hold at some point in the future H f : f held at every point in the past G f : f will hold at every point in the future Every student will at some point never be a student again. x.Student(x) FGStudent(x)
50
51
Balice City(boston)
More complex: Alice has visited at least 10 museums. x Museum(x)Visited(alice, x): boolean function representing set of museums Alice has visited Count(x Museum(x)Visited(alice, x)) 10 Higher-order logic allows us to model these generalized quantiers.
52
53
Description logic
People with at least three sons who are all unemployed and married to doctors, and at most two daughters who are professors...are weird.
Limitations
In logic, a formula carves out subset of models. x y z Takes(x, y ) Covers(y, z ) Knows(x, z )
Description logic:
Person ( 3 Son.Unemployed Spouse.Doctor) Weird
In reality, there is uncertainty. Key idea: distribution Model a distribution over models P(W = w; ).
( 2 Daughter.Professor)
54
55
Markov logic
Example: Markov logic network (MLN) formula G(a) G(b) x G(x) H (x) weight 0.2 5.1 1.2 Propositionalize:
Markov logic
Assume unique names + domain closure.
Example: grounded Markov logic network formula G(a) G(b) G(a) H (a) G(b) H (b) G(c) H (c) weight 0.2 5.1 1.2 1.2 1.2
57
56
Markov logic
Recall propositional logic encodes a factor graph: e1.2[G(a)H (a)] e0.2[G(a)=1] G(a) H (b)
Summary
Logic is used to represent knowledge and perform inferences on it Considerations: expressiveness, notational convenience, inferential complexity Propositional logic with denite clauses, propostional logic, description logic, rst-order logic, temporal logic, modal logic, higher-order logic Markov logic: marry logic (abstract reasoning by working on formulas) and probability (maintaining uncertainty)
e1.2[G(b)H (b)] e
5.1[G(b)=1]
G(b)
H (b)
58
59