l6 logic programming
TRANSCRIPT
-
8/2/2019 l6 Logic Programming
1/44
Knowledge Engineering
Quang Nhat NGUYEN
(Academic year 2010-2011)
Hanoi University of Science and Technology
School of Information and Communication Technology
-
8/2/2019 l6 Logic Programming
2/44
Content
Introduction
First-order logic
Knowledge representation
Semantic Web
og c programm ng
Resolution
Forward reasonin
Backward reasoning
Uncertain reasoning
Expert systems
Knowledge discovery by Machine learning
Knowledge discovery by Data mining
2Knowledge Engineering
-
8/2/2019 l6 Logic Programming
3/44
Logical inference in First-order logic (1) Logical inference problem
, does the KB semantically entail ?KB ?
In all interpretations in which sentences in the KB are true, is
also true?
entailment for all possible input sentences in a finite
number of steps
For the propositional logic: Yes
However, the logical inference problem in the first-order
logic is undecidable
3Knowledge Engineering
-
8/2/2019 l6 Logic Programming
4/44
Logical inference in First-order logic (2) Is the Truth-table approach a viable approach for the
-
No!
It would require us to enumerate and list all possible
interpretations I
I= (assignments of symbols to objects, predicates to
relations and functions to relational mappings)
ere are oo many poss e n erpre a ons
4Knowledge Engineering
-
8/2/2019 l6 Logic Programming
5/44
Logical inference in First-order logic (3) Is the Inference-rule approach a viable approach for the
- -
Yes
The inference rules represent sound inference patterns
that one can apply to sentences in the KB
Reuse inference rules from the propositional logic, , - , - ,Or-introduction, Negation elimination
Additional inference rules are needed for sentences with
quan ers , We need to handle variables
5Knowledge Engineering
-
8/2/2019 l6 Logic Programming
6/44
Variable substitutions Variables in FOL sentences can be substituted with
Ground terms = {constants, variables, functions}
ground terms
{x1 /t1, x2/t2,}
Application of the substitution to FOL sentences
SUBST x/Tuan /Hai Likes x = Likes Tuan Hai
SUBST ({x/z, y/fatherOf(Vu)}, Likes(x, y)) = Likes (z,
fatherOf(Vu))
6Knowledge Engineering
-
8/2/2019 l6 Logic Programming
7/44
Inference rules for quantifiers (1) Universal instantiation (elimination)
o su s u e a var a e w a groun erm
x: (x) ; a is a ground term
a
Example
x: Likes(x, IceCream) Likes(Tuan, IceCream)
By the substitution of the variablexwith the constant Tuan
Denoted as: SUBST({x/a}, x: (x)) = (a)
Universal Instantiation can be applied many times to
produce many different consequences
7Knowledge Engineering
-
8/2/2019 l6 Logic Programming
8/44
Inference rules for quantifiers (2) Existential instantiation (elimination)
elsewhere in the KBx: (x) ; a does not appear in KB
(a)
Example
, ,
By the substitution of the variablexwith the constant Murderer
=,
Existential Instantiation can be applied once
8Knowledge Engineering
-
8/2/2019 l6 Logic Programming
9/44
Unification (1) Problem in inference: Universal instantiation gives many
x: (x) ; a is a ground term
(a)
Solution: Try substitutions of similar sentences in KB
Example Lets assume we have KB containing the 3 following sentences
x: King(x) Greedy(x) Evil(x)
King(John)
y: Greedy(y)
If we use a substitution = {x/John,y/John}, then we can infer
Evil John
9Knowledge Engineering
-
8/2/2019 l6 Logic Programming
10/44
Unification (2) A unification takes two similar sentences and computes
,
existsUNIFY(p,q) = such that SUBST(,p) = SUBST(,q)
Examples
UNIFY(Knows(John, x), Knows(John, Jane)) = {x/Jane}
UNIFY(Knows(John, x), Knows(y, Bill)) = {x/Bill, y/John}
UNIFY(Knows(John, x), Knows(y, MotherOf(y))) =
x o er o n , y o n UNIFY(Knows(John, x), Knows(x, Elizabeth )) = fail Because no
substitution can make the two sentence are the same (i.e.,xcannot take
on the values John and Elizabeth at the same time)
10Knowledge Engineering
-
8/2/2019 l6 Logic Programming
11/44
Most general unifier UNIFYshould return a substitution that makes the two
,
than one such unifier
For exam le, to unif Knows John,x and Knows ,z
1 = {y/John, x/z }
2 = {y/John, x/John, z/John} In the above example, the first unifier is more general
than the second
,most general unifier (MGU) that is unique up to
renaming of variables
In the above example: MGU = {y/John, x/z}
11Knowledge Engineering
-
8/2/2019 l6 Logic Programming
12/44
Resolution inference rule (1) Basic propositional version
,
Equivalent to
,
12Knowledge Engineering
-
8/2/2019 l6 Logic Programming
13/44
Resolution inference rule (2) FOL version:
1 j m, 1 k n
SUBST (, (p1 pj-1 pj+1 pm q1 qk-1 qk+1 qn))
k k j, k
is the most general unifier (MGU) ofpjand qk
The literalspjand qkare called complementary literals
Because each one unifies with the negation of the other
The resulting disjunction is called a resolvent
13Knowledge Engineering
-
8/2/2019 l6 Logic Programming
14/44
Resolution inference rule Examples (1) Example 1
,
Unhappy(Me)by the most general unifier = {x/Me}
Example 2
Lets assume that KB contains the following sentences PhD(x) HighlyQualified(x)
PhD(x) EarlyEarnings(x)
EarlyEarnings(x) Rich(x)
Tr resolution to infer Rich Me
14Knowledge Engineering
-
8/2/2019 l6 Logic Programming
15/44
Resolution inference rule Examples (2)
Convert KB to the equivalent sentences
PhD x Hi hl Qualified x
PhD(x) EarlyEarnings(x) HighlyQualified(x) Rich(x)
From PhD(x) HighlyQualified(x) and PhD(x) EarlyEarnings(x)
and using the MGU = {x/Me}, we infer HighlyQualified(Me)
EarlyEarnings(Me)
From HighlyQualified(x) Rich(x) and HighlyQualified(Me)
Earl Earnin s Me and usin the MGU = x/Me we infer
Rich(Me) EarlyEarnings(Me)
From Rich(Me) EarlyEarnings(Me) and EarlyEarnings(x)
,
15Knowledge Engineering
-
8/2/2019 l6 Logic Programming
16/44
Resolution-based proving
Proof by refutation: To prove KB, we need to prove thatKB is unsatisfiable
Main steps of the resolution-based proving procedure1. Convert {KB, } to CNF with ground terms and universal
variables only
2. Apply repeatedly the resolution rule while keeping track and
consistency of substitutions3. Stop when eitheran empty set (contradiction) is derivedorno
more new resolvents (conclusions) follow
,
clause (equivalent to false) is derived
p, p
16Knowledge Engineering
-
8/2/2019 l6 Logic Programming
17/44
Conjunctive normal form
To be able to do resolution, the given formulas have to
A literal is an atomic formula or the negation of anatomic formula
An atomic formula is also called a positive literal
The negation of an atomic formula is called a negative literal
A clause is a disjunction of literals
A special clause called the empty clause equivalent to false
is a conjunction of disjunctions of literals
Equivalently, if it is a set of clauses
17Knowledge Engineering
-
8/2/2019 l6 Logic Programming
18/44
Conversion to CNF (1)
1. Eliminate implications and equivalences using the laws
(p q) ((p q) (q p)) ((p q) (q p))
.
(p q) (p q)
(p q) (p q)(x: p(x)) (x: p(x))
(x: p(x)) (x: p(x))
3. Rename variables so that each quantifier has a unique variable
18Knowledge Engineering
-
8/2/2019 l6 Logic Programming
19/44
Conversion to CNF (2)
4. Eliminate existential quantifiers ()
quantifier (x), drop the existential quantifier and replace alloccurrences of the existential quantifier variablexby a new
E.g., (x: p(A) q(x)) (p(A) q(B))
If universal uantifiers ,, recede an existential
quantifier (x), drop the existential quantifier and replace all
occurrences of the existential quantifier variablexby the term
f(y1, , yn) where fis a new function symbol (called a Skolem
function) E.g., (x, y: p(x) q(y)) (x: p(x) q(f(x)) where f(x) is a
Skolem function
19Knowledge Engineering
-
8/2/2019 l6 Logic Programming
20/44
Conversion to CNF (3)
5.Drop all universal quantifiers ()
. .,
6.Convert to CNF by using the distributive law of over
, ,
E.g., (p (q r)) (p q) (p r)
7.Flatten nested con unctions or dis unctions. Then write
each disjunction on a separate line
20Knowledge Engineering
-
8/2/2019 l6 Logic Programming
21/44
Conversion to CNF Example (1)
Problem: Convert to CNF the following sentence:
, , ,
1. Eliminate implications
x: y: p x, y y: q x, y r x, y
2. Move inwardsx: ((y: p(x, y)) (y: (q(x, y) r(x, y))))
3. Rename variables
x: ((y: p(x, y)) (z: (q(x, z) r(x, z))))
21Knowledge Engineering
-
8/2/2019 l6 Logic Programming
22/44
Conversion to CNF Example (2)
4. Skolemize (i.e., eliminate existential quantifiers)
, 1 , 2 , 2
5. Drop universal quantifiers
p x, 1 x q x, 2 x r x, 2 x
6. Distribute over(p(x, f1(x)) q(x, f2(x))) (p(x, f1(x)) r(x, f2(x)))
7. Write each disjunction on a separate line
p(x, f1(x)) q(x, f2(x))p(x, f1(x)) r(x, f2(x))
22Knowledge Engineering
-
8/2/2019 l6 Logic Programming
23/44
Resolution-based proving Example
The crime example is described as follows:
weapons to hostile nations The countr Nono, an enem of America, has some
missiles
All of the country Nonos missiles were sold to it by
Use resolution to prove that West is a criminal!
23Knowledge Engineering
-
8/2/2019 l6 Logic Programming
24/44
Example: Formalization in FOL (1)
... it is a crime for an American to sell weapons to
x,y,z: American(x) Weapon(y) Sells(x, y, z) Hostile(z) Criminal(x)
Nono ... has some missiles
x: Owns(Nono, x) Missile(x)
All of the country Nonos missiles were sold to it by
Colonel West
x: Owns(Nono, x) Missile(x) Sells(West, x, Nono)
24Knowledge Engineering
-
8/2/2019 l6 Logic Programming
25/44
Example: Formalization in FOL (2)
Missiles are weapons
x: Missile x Wea on x
An enemy of America is a hostile nationx: Enemy(x, America) Hostile(x)
West, who is an American
American(West)
Nono, an enemy of America ...
Enemy(Nono, America)
To be proved that West is a criminalCriminal(West)
25Knowledge Engineering
-
8/2/2019 l6 Logic Programming
26/44
Example: Convert to CNF form
American(x) Weapon(y) Sells(x, y, z)
Owns(Nono, M1)
Missile(x) Owns(Nono, x) Sells(West, x, Nono)
Missile x Wea on x
Enemy(x, America) Hostile(x)
American West
Enemy(Nono, America)
Criminal West
26Knowledge Engineering
-
8/2/2019 l6 Logic Programming
27/44
Example: Proof
27Knowledge Engineering
-
8/2/2019 l6 Logic Programming
28/44
Horn normal form
A formula is in the Horn norm form if: The formula is a conjunction () of clauses
Each clause is a disjunction () of literals, in which at most 1 (possibly
no!) positive literal E.g., (p q) (p r s)
e now e ge ase can e represen e n e ornnorm form
Rules 1 2 n
Equivalent to the rule: (p1 p2 pn q)
Facts
,
Integrity constraints (p1 p2 pn)
Equivalent to the rule: (p1 p2 pn false)
28Knowledge Engineering
-
8/2/2019 l6 Logic Programming
29/44
Generalized Modus Ponens inference rule
(p1 p2 pn q), p1, p2, , pn
The application of the Generalized Modus Ponensn erence ru e requ res a a e sen ences n musbe in the Horn norm form
The Generalized Modus Ponens inference rule can beapplied in both reasoning strategies
Forward reasonin
Backward reasoning
29Knowledge Engineering
-
8/2/2019 l6 Logic Programming
30/44
Forward reasoning
Problem: Given a set of premises (i.e., rules and facts) stored in the
knowledge base KB, prove the conclusion Q
Idea: Iterate the two following steps until the conclusion is derived
Apply rules whose condition clause match KB
For each matched rule add its conclusion clause to KB
30Knowledge Engineering
-
8/2/2019 l6 Logic Programming
31/44
Forward reasoning Example (1)
31Knowledge Engineering
-
8/2/2019 l6 Logic Programming
32/44
Forward reasoning Example (2)
32Knowledge Engineering
-
8/2/2019 l6 Logic Programming
33/44
Forward reasoning Example (3)
33Knowledge Engineering
-
8/2/2019 l6 Logic Programming
34/44
Forward reasoning Example (4)
34Knowledge Engineering
-
8/2/2019 l6 Logic Programming
35/44
Forward reasoning Example (5)
35Knowledge Engineering
-
8/2/2019 l6 Logic Programming
36/44
Forward reasoning Example (6)
36Knowledge Engineering
-
8/2/2019 l6 Logic Programming
37/44
Forward reasoning Example (7)
37Knowledge Engineering
-
8/2/2019 l6 Logic Programming
38/44
Backward reasoning
Idea: the backward reasoning process starts from theconclusion Q
To prove Q by using the set of premises (i.e., rules and facts)in KB
If not yet, prove all the conditions of a rule (in KB) whoseconclusion clause is Q
Avoid loops
Check if the new derived clause has already been in the list of to-be-proved ones? If already, dont add it again!
Avoid to repeat the proof of a proved clause
The clause has already been proved true
e c ause as a rea y een prove unsa s a e a se n
38Knowledge Engineering
-
8/2/2019 l6 Logic Programming
39/44
Backward reasoning Example (1)
39Knowledge Engineering
-
8/2/2019 l6 Logic Programming
40/44
Backward reasoning Example (2)
40Knowledge Engineering
-
8/2/2019 l6 Logic Programming
41/44
Backward reasoning Example (3)
41Knowledge Engineering
-
8/2/2019 l6 Logic Programming
42/44
Backward reasoning Example (4)
42Knowledge Engineering
-
8/2/2019 l6 Logic Programming
43/44
Backward reasoning Example (5)
43Knowledge Engineering
-
8/2/2019 l6 Logic Programming
44/44
Forward vs. Backward reasoning
Forward reasoning is a data-driven inference process
. ., ,
Forward reasoning may do some redundant work
Backward reasoning is a goal-driven inference process,
-
E.g., How do I get into a PhD program?
44Knowledge Engineering