Вы находитесь на странице: 1из 17

ConjunctiveNormalForm

&HornClauses
YorkUniversityCSE3401
VidaMovahedi
YorkUniversity CSE3401 V.Movahedi
1
Overview Overview
Definitionofliterals,clauses,andCNF , ,
ConversiontoCNF Propositionallogic
Representation of clauses in logic programming Representationofclausesinlogicprogramming
HornclausesandPrograms
Facts Facts
Rules
Queries(goals)
ConversiontoCNF Predicatelogic
[ref.:Clocksin Chap.10andNilsson Chap.2]
YorkUniversity CSE3401 V.Movahedi
2
Conjunctive Normal Form ConjunctiveNormalForm
Aliteral iseitheranatomicformula(calledapositive ( p
literal)oranegatedatomicformula(calledanegated
literal)
e.g. p, q e.g.p, q
Aclause is
Aliteral,or
Disjunction oftwoormoreliterals,or
Theemptyclause,shownas,: or{}
e.g.p,
r q p
Aformula issaidtobeinConjunctiveNormalForm
(CNF)ifitistheconjunction ofsomenumberofclauses
YorkUniversity CSE3401 V.Movahedi
3
CNF (example) CNF(example)
) ( ) ( ) ( t r r s q q p ) ( ) ( ) ( t r r s q q p


p q q s r r t
YorkUniversity CSE3401 V.Movahedi
4
CNF Facts CNF Facts
For every formula of propositional logic, there Foreveryformula ofpropositionallogic,there
existsaformulaAinCNFsuchthatAisatautology
A polynomial algorithm exists for converting to A Apolynomialalgorithmexistsforconverting toA
Forpracticalpurposes,weuseCNFsinLogic
i Programming
YorkUniversity CSE3401 V.Movahedi
5
Conversion to CNF ConversiontoCNF
1. Removeimplicationandequivalence
Example:
p q
Use
) ( ) (
) ( ) ( ) (
) ( ) (
p q q p q p
q p q p

)) ( (
) (
s r p
s r p


Example:
2. Movenegationsinwards
U D M
) ( ) ( p q q p

) (
) ) ( (
)) ( (
r p
p s r
s r p



UseDeMorgans
) ( ) (
) ( ) (
q p q p
q p q p



) (
) (
) (
s p
r p



3. DistributeORoverAND
) ( ) ( q p q p
) ( ) ( ) ( r p q p r q p

) ( p s r
YorkUniversity CSE3401 V.Movahedi
6
) ( ) ( ) ( r p q p r q p
Representing a clause Representingaclause
Consider this clause:
s r q p
Considerthisclause:
Itcanbewrittenas:
q p
) ( ) ( ) ( s q r p s q r p
InLogicprogramming,itisshownas:
) ( ) ( r p s q
. , : ;
) ( ) (
r p s q
p s q


Easyway:positiveliteralsontheleft,negativeliterals
ontheright
YorkUniversity CSE3401 V.Movahedi
7
Logic Programming Clause LogicProgrammingClause
A clause in the form: Aclauseintheform:
is equivalent to:
. ,..., , : ;...; ;
2 1 2 1 n m
q q q p p p
isequivalentto:
or
n m
p p p q q q
q q q p p p

... ...
2 1 2 1
or
if is true then at least one of
m n
p p p q q q ... ...
2 1 2 1
q q q
if istrue,thenatleastoneof
istrue.
n
q q q ...
2 1
m
p p p ,..., ,
2 1
YorkUniversity CSE3401 V.Movahedi
8
Another Example AnotherExample
WritethefollowingexpressionasLogicProgrammingClauses: WritethefollowingexpressionasLogicProgrammingClauses:
1 Conversion to CNF:
( ) ( ) ) ( ) ( t r q r s p
( ) ( )
1 ConversiontoCNF:
2 Symmetryof
( ) ( )
) ( ) ( ) (
) ( ) (
t r q r s q p
t r q r s p


allowsforsetsnotation
ofaCNF
3 S t f
{ } ) ( ), ( ), ( t r q r s q p
3 Symmetryof
allowsforsetnotation
ofclauses
{ } { } { } { } , , , , , , t r r s q q p
4 AsLogicProg.
YorkUniversity CSE3401 V.Movahedi
9
. : . : ; . : ; r t s r q q p
Horn Clause HornClause
A Horn clause is a clause with at most one positive AHornclauseisaclausewithatmostonepositive
literal:
Rules head: body. e.g.p
1
:q
1
,q
2
,...,q
n
.
Facts head:. e.g.p
2
:.
Queries (or goals) :body. e.g. : r
1
, r
2
, ..., r
m
. Queries (orgoals) : body. e.g.: r
1
,r
2
,...,r
m
.
H l i lif h i l i f l i Hornclausessimplifytheimplementationoflogic
programminglanguagesandarethereforeusedinProlog.
YorkUniversity CSE3401 V.Movahedi
10
A Program AProgram
A logic programming program P is defined as a finite AlogicprogrammingprogramPisdefinedasafinite
setofrulesandfacts.
Forexample,P={p:q,r.,q:.,r:a.,a:.}
rule1fact1rule2fact2
Rulesandfacts(withexactlyonepositiveliteral)are
called definite clauses and therefore a program defined calleddefinite clausesandthereforeaprogramdefined
bythemiscalledadefinite program.
YorkUniversity CSE3401 V.Movahedi
11
Query Query
Acomputationalquery(orgoal)istheconjunctionofsome p q y ( g ) j
positiveliterals(calledsubgoals),e.g.
n
r r r ...
2 1
AqueryisdeductiblefromPifitcanbeprovenonthebasis
ofP:
n
r r r P ... |
2 1

Notethisqueryiswrittenas
whichisor
) ... (
2 1 n
r r r
n
r r r ...
2 1
.
n
r r r ,..., , :
2 1

Why?Inlogicprogrammingtheoremprovingisusedto
answerqueries:
iff isinconsistent
YorkUniversity CSE3401 V.Movahedi
12
n
r r r P ... |
2 1
{ } ) ... (
2 1 n
r r r P U
Example Example
P: { p:q. , q:.} P:{p: q.,q: .}
Ifwewanttoknowaboutp,wewillaskthequery:
:p.
Note that the set { p:q., q:., :p.} is inconsistent. Notethattheset{p: q.,q: .,: p.}isinconsistent.
(Reminder:truthtableforaboveclausesdoesnot
haveevenonerowwherealltheclausesaretrue)
Thereforepisprovableandyourtheoremproving
program (e.g. Prolog) will return true. program(e.g.Prolog)willreturntrue.
YorkUniversity CSE3401 V.Movahedi
13
Predicate Logic Clauses PredicateLogicClauses
Same definition for literals, clauses, and CNF except Samedefinitionforliterals,clauses,andCNFexcept
noweachliteralismorecomplicatedsinceanatomic
formulaismorecomplicatedinpredicatelogic
d d l i h ifi d h i bj Weneedtodealwithquantifiersandtheirobject
variableswhenconvertingtoCNF
YorkUniversity CSE3401 V.Movahedi
14
Conversion to CNF in Predicate Logic ConversiontoCNFinPredicateLogic
1. Removeimplicationandequivalence p q
2. Movenegationsinwards
Note ) ( ) ( ) ( ) ( x p x x p x Note
3. Renamevariablessothatvariablesofeachquantifierare
) ( ) ( ) ( ) ( x p x x p x
unique
4. Moveallquantifierstothefront(Prenex NormalForm) q ( )
YorkUniversity CSE3401 V.Movahedi
15
Conversion to CNF (cont.) ConversiontoCNF(cont.)
5. Skolemizing (getridofexistentialquantifiers) g (g q )
5. Skolem constants
6 Skolem functions
) , 1 ( ) 1 ( )) , ( ) ( ) (( eve g motherof g female eve X motherof X female X
6. Skolem functions
)) ( 2 , ( ) ( ) (
) , ( ) ( ) )( (
X g X motherof X human X
Y X motherof X human Y X



6. DistributeORoverANDtohaveconjunctionsof
disjunctionsasthebodyoftheformula
)) ( , ( ) ( ) ( g f
j y
7. Removealluniversalquantifiers
YorkUniversity CSE3401 V.Movahedi
16
Example Example
All Martians like to eat some kind of spiced food. AllMartiansliketoeatsomekindofspicedfood.
[fromAdvancedProlog Techniquesandexamples PeterRoss]
))) , ( ) , ( ) ( ) ( )( )( ( ) ( )( ( Y X likes Z Y contains Z spice Y food Z Y X martian X
)))) ( , ( )) ( ), ( ( )) ( ( )) ( ( ( ) ( )( (
))) , ( ) , ( ) ( ) ( ( ) ( )( )( )( (
))) , ( ) , ( ) ( ) ( )( )( ( ) ( )( (
X f X likes X s X f contains X s spice X f food X martian X
Y X likes Z Y contains Z spice Y food X martian Z Y X
Y X likes Z Y contains Z spice Y food Z Y X martian X



))) ( ( ) ( (
)))) ( , ( ) ( ( ))) ( ), ( ( ) ( (
))) ( ( ) ( ( ))) ( ( ) ( )(( (
)))) ( , ( )) ( ), ( ( )) ( ( )) ( ( ( ) ( )( (
X f food X martian
X f X likes X martian X s X f contains X martian
X s spice X martian X f food X martian X
f f p f f




))) ( ( ) ( (
))) ( ), ( ( ) ( (
))) ( ( ) ( (
))) ( ( ) ( (
X f X likes X martian
X s X f contains X martian
X s spice X martian
X f food X martian

YorkUniversity CSE3401 V.Movahedi


17
))) ( , ( ) ( ( X f X likes X martian

Вам также может понравиться