Académique Documents
Professionnel Documents
Culture Documents
A summary of chapters 7, 8, 9 of
Artificial Intelligence: A modern approach
by Russel and Norving
Outline
Knowledge-based agents
Logic in general - models and entailment
Propositional (Boolean) logic
Equivalence, validity, satisfiability
Inference rules
forward chaining
backward chaining
resolution
Knowledge bases
Logic in general
Logics are formal languages for representing
information such that conclusions can be drawn
Syntax defines the sentences in the language
Semantics define the "meaning" of sentences;
i.e., define truth of a sentence in a world
Entailment
Entailment means that one thing follows from
another:
KB
Knowledge base KB entails sentence if and
only if is true in all worlds where KB is true
E.g., the KB containing the Giants won and the
Reds won entails Either the Giants won or the
Reds won
E.g., x+y = 4 entails 4 = x+y
Entailment is a relationship between sentences
(i.e., syntax) that is based on semantics
Models
Logicians typically think in terms of models, which are formally
structured worlds with respect to which truth can be evaluated
We say m is a model of a sentence if is true in m
M() is the set of all models of
Then KB iff M(KB) M()
Inference
KB i = sentence can be derived from KB by
procedure i
Soundness: i is sound if whenever KB i , it is also
true that KB
Completeness: i is complete if whenever KB , it is
also true that KB i
Preview: we will define a logic (first-order logic)
which is expressive enough to say almost anything
of interest, and for which there exists a sound and
complete inference procedure.
That is, the procedure will answer any question
whose answer follows from what is known by the
KB.
Inference by enumeration
Depth-first enumeration of all models is sound and complete
Logical equivalence
Two sentences are logically equivalent} iff true in
same models: iff and
A A, A A, (A (A B)) B
Proof methods
Proof methods divide into (roughly) two kinds:
Application of inference rules
Legitimate (sound) generation of new sentences from old
Proof = a sequence of inference rule applications
Can use inference rules as operators in a standard search
algorithm
Typically require transformation of sentences into a normal
form
Model checking
truth table enumeration (always exponential in n)
improved backtracking, e.g., Davis--Putnam-LogemannLoveland (DPLL)
heuristic search in model space (sound but incomplete)
e.g., min-conflicts-like hill-climbing algorithms
Resolution
Conjunctive Normal Form (CNF)
conjunction of disjunctions of literals
clauses
E.g., (A B) (B C D)
Resolution
Soundness of resolution inference rule:
Conversion to CNF
B1,1 (P1,2 P2,1)
1. Eliminate , replacing with ( )( ).
(B1,1 (P1,2 P2,1)) ((P1,2 P2,1) B1,1)
Resolution algorithm
Proof by contradiction, i.e., show KB
unsatisfiable
Resolution example
KB = (B1,1 (P1,2 P2,1)) B1,1 = P1,2
E.g., C (B A) (C D B)
Forward chaining
Idea: fire any rule whose premises are satisfied in
the KB,
add its conclusion to the KB, until query is found
Proof of completeness
4. Hence m is a model of KB
5. If KB q, q is true in every model of KB,
including m
Backward chaining
Idea: work backwards from the query q:
to prove q by BC,
check if q is known already, or
prove by BC all premises of some rule concluding q
First-Order Logic
Outline
Why FOL?
Syntax and semantics of FOL
Using FOL
Knowledge engineering in FOL
First-order logic
Whereas propositional logic assumes the world contains facts,
first-order logic (like natural language) assumes the world
contains
Objects: people, houses, numbers, colors, baseball games, wars,
Relations: red, round, prime, brother of, bigger than, part of,
comes between,
Functions: father of, best friend, one more than, plus,
Sqrt, LeftLegOf,...
Variables
x, y, a, b,...
Connectives
, , , ,
Equality
Quantifiers
Atomic sentences
Atomic sentence = predicate (term1,...,termn)
or term1 = term2
Term
function (term1,...,termn)
or constant or variable
E.g.,
Brother(KingJohn,RichardTheLionheart)
Married(FatherOf(Richard), MotherOf(John))
Complex sentences
Complex sentences are made from atomic sentences using
connectives
objects
relations
functional relations
Universal quantification
<variables> <sentence>
Everyone at NUS is smart:
x At(x,NUS) Smart(x)
x P is true in a model m iff P is true with x being
each possible object in the model
Roughly speaking, equivalent to the conjunction of
instantiations of P
At(KingJohn,NUS) Smart(KingJohn)
At(Richard,NUS) Smart(Richard)
At(NUS,NUS) Smart(NUS)
...
Existential quantification
<variables> <sentence>
Someone at NUS is smart:
x At(x,NUS) Smart(x)$
x P is true in a model m iff P is true with x being
some possible object in the model
Roughly speaking, equivalent to the disjunction of
instantiations of P
At(KingJohn,NUS) Smart(KingJohn)
At(Richard,NUS) Smart(Richard)
At(NUS,NUS) Smart(NUS)
...
Properties of quantifiers
x y is the same as y x
x y is the same as y x
x y is not the same as y x
x y Loves(x,y)
y x Loves(x,y)
Equality
term1 = term2 is true under a given
interpretation if and only if term1 and term2
refer to the same object
E.g., definition of Sibling in terms of Parent:
x,y Sibling(x,y) [(x = y) m,f (m = f)
Parent(m,x) Parent(f,x) Parent(m,y)
Parent(f,y)]
Using FOL
The kinship domain:
Sibling is symmetric
x,y Sibling(x,y) Sibling(y,x)
Using FOL
The set domain:
s Set(s) (s = {} ) (x,s2 Set(s2) s = {x|s2})
x,s {x|s} = {}
x,s x s s = {x|s}
x,s x s [ y,s2} (s = {y|s2} (x = y x s2))]
s1,s2 s1 s2 (x x s1 x s2)
s1,s2 (s1 = s2) (s1 s2 s2 s1)
x,s1,s2 x (s1 s2) (x s1 x s2)
x,s1,s2 x (s1 s2) (x s1 x s2)
3. Decide on a vocabulary
Alternatives:
Type(X1) = XOR
Type(X1, XOR)
XOR(X1)
Type(X2) = XOR
Type(A2) = AND
Connected(Out(1,X1),In(1,X2)) Connected(In(1,C1),In(1,X1))
Connected(Out(1,X1),In(2,A2)) Connected(In(1,C1),In(1,A1))
Connected(Out(1,A2),In(1,O1)) Connected(In(2,C1),In(2,X1))
Connected(Out(1,A1),In(2,O1)) Connected(In(2,C1),In(2,A1))
Connected(Out(1,X2),Out(1,C1))
Connected(In(3,C1),In(2,X2))
Connected(Out(1,O1),Out(2,C1))
Connected(In(3,C1),In(1,A2))
Outline
Reducing first-order inference to propositional inference
Unification
Generalized Modus Ponens
Forward chaining
Backward chaining
Resolution
Reduction contd.
Every FOL KB can be propositionalized so as to
preserve entailment
(A ground sentence is entailed by new KB iff entailed
by original KB)
Idea: propositionalize KB and query, apply
resolution, return result
Reduction contd.
Theorem: Herbrand (1930). If a sentence is entailed by an FOL
KB, it is entailed by a finite subset of the propositionalized KB
Idea: For n = 0 to do
create a propositional KB by instantiating with depth-$n$ terms
see if is entailed by this KB
Unification
We can get the inference immediately if we can find a
substitution such that King(x) and Greedy(x) match
King(John) and Greedy(y)
= {x/John,y/John} works
Unify(,) = if =
p
q
Knows(John,x) Knows(John,Jane)
Knows(John,x) Knows(y,OJ)
Knows(John,x) Knows(y,Mother(y))
Knows(John,x) Knows(x,OJ)
Standardizing apart eliminates overlap of variables, e.g.,
Knows(z17,OJ)
Unification
We can get the inference immediately if we can find a
substitution such that King(x) and Greedy(x) match
King(John) and Greedy(y)
= {x/John,y/John} works
Unify(,) = if =
p
q
Knows(John,x)
Knows(John,Jane)
Knows(John,x)
Knows(y,OJ)
Knows(John,x)
Knows(y,Mother(y))
Knows(John,x)
Knows(x,OJ)
{x/Jane}}
Unification
We can get the inference immediately if we can find a
substitution such that King(x) and Greedy(x) match
King(John) and Greedy(y)
= {x/John,y/John} works
Unify(,) = if =
p
q
Knows(John,x)
Knows(John,Jane)
Knows(John,x)
Knows(y,OJ)
Knows(John,x) Knows(y,Mother(y))
Knows(John,x) Knows(x,OJ)
{x/Jane}}
{x/OJ,y/John}}
Unification
We can get the inference immediately if we can find a substitution
such that King(x) and Greedy(x) match King(John) and Greedy(y)
= {x/John,y/John} works
Unify(,) = if =
p
q
Knows(John,x)
Knows(John,Jane)
Knows(John,x)
Knows(y,OJ)
Knows(John,x)
Knows(y,Mother(y))
Knows(John,x)
Knows(x,OJ)
{x/Jane}}
{x/OJ,y/John}}
{y/John,x/Mother(John)}}
Unification
We can get the inference immediately if we can find a substitution
such that King(x) and Greedy(x) match King(John) and Greedy(y)
= {x/John,y/John} works
Unify(,) = if =
p
q
Knows(John,x)
Knows(John,Jane)
Knows(John,x)
Knows(y,OJ)
Knows(John,x)
Knows(y,Mother(y))
Knows(John,x)
Knows(x,OJ)
{x/Jane}}
{x/OJ,y/John}}
{y/John,x/Mother(John)}}
{fail}
Unification
To unify Knows(John,x) and Knows(y,z),
= {y/John, x/z } or = {y/John, x/John, z/John}
Soundness of GMP
Missile(x) Weapon(x)
Prolog
Appending two lists to produce a third:
append([],Y,Y).
append([X|L],Y,[X|Z]) :- append(L,Y,Z).
query:
append(A,B,[1,2]) ?
answers:
A=[]
B=[1,2]
A=[1]
B=[2]
A=[1,2] B=[]
Conversion to CNF
Everyone who loves all animals is loved by
someone:
2. Move inwards: x p x p, x p
x p
2.
3.
4.
Distribute over :