[lifschitz] foundations of logic programming, in principles of knowledge representation, csli...

Upload: sergio-arturo

Post on 14-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    1/57

    F o u n d a t i o n s o f L o g i c P r o g r a m m i n g

    V l a d i m i r L i f s c h i t z

    D e p a r t m e n t o f C o m p u t e r S c i e n c e s

    U n i v e r s i t y o f T e x a s

    A u s t i n , T X 7 8 7 1 2

    A b s t r a c t

    T h i s i s a s u r v e y o f t h e t h e o r y o f l o g i c p r o g r a m s w i t h c l a s s i c a l n e g a t i o n a n d

    n e g a t i o n a s f a i l u r e . T h e s e m a n t i c s o f t h i s c l a s s o f p r o g r a m s i s b a s e d o n t h e n o t i o n

    o f a n a n s w e r s e t . T h e o p e r a t i o n o f P r o l o g i s d e s c r i b e d i n t e r m s o f p r o o f s e a r c h i n

    t h e S L D N F c a l c u l u s .

    1 I n t r o d u c t i o n

    I n t h i s s u r v e y , w e v i e w l o g i c p r o g r a m m i n g a s a m e t h o d f o r r e p r e s e n t i n g d e c l a r a t i v e

    k n o w l e d g e . T o p u t t h e s u b j e c t i n a p r o p e r p e r s p e c t i v e , w e b r i e y d i s c u s s h e r e t w o o t h e r

    a p p r o a c h e s t o k n o w l e d g e r e p r e s e n t a t i o n a n d c o m p a r e t h e m w i t h l o g i c p r o g r a m m i n g .

    1 . 1 R e l a t i o n a l D a t a b a s e s a n d F i r s t - O r d e r T h e o r i e s

    W e w o u l d l i k e t o r e p r e s e n t f a c t s a b o u t t h e p a r e n t h o o d r e l a t i o n s a m o n g s e v e r a l m e m b e r s

    o f B r i t a i n ' s r o y a l f a m i l y : t h e Q u e e n , t h e P r i n c e a n d P r i n c e s s o f W a l e s , a n d t h e i r

    c h i l d r e n . T h e s e f a c t s c a n b e r e p r e s e n t e d a s a r e l a t i o n a l d a t a b a s e , a s f o l l o w s :

    R e l a t i o n M o t h e r

    P A R E N T C H I L D

    E l i z a b e t h C h a r l e s

    D i a n a W i l l i a m

    D i a n a H a r r y

    R e l a t i o n F a t h e r

    P A R E N T C H I L D

    C h a r l e s W i l l i a m

    C h a r l e s H a r r y

    W e w i l l c a l l t h i s d a t a b a s e D B

    1

    .

    A l t e r n a t i v e l y , t h e s e f a c t s c a n b e e n c o d e d a s a r s t - o r d e r t h e o r y . T h e n a m e s o f

    t h e v e i n d i v i d u a l s i n v o l v e d a r e t h e o b j e c t c o n s t a n t s o f t h i s t h e o r y T

    1

    M o t h e r a n d

    1

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    2/57

    F a t h e r a r e i t s b i n a r y p r e d i c a t e c o n s t a n t s . T h e r s t g r o u p o f a x i o m s o f T

    1

    t e l l s u s t h a t

    t h e d o m a i n o f r e a s o n i n g c o n s i s t s o f t h e v e d i s t i n c t o b j e c t s r e p r e s e n t e d b y t h e o b j e c t

    c o n s t a n t s :

    8 x ( x = E l i z a b e t h _ x = C h a r l e s _ x = D i a n a _ x = W i l l i a m _ x = H a r r y ) ( 1 )

    E l i z a b e t h 6= C h a r l e s E l i z a b e t h 6= D i a n a : : : W i l l i a m 6= H a r r y : ( 2 )

    A x i o m ( 1 ) i s s a i d t o e x p r e s s t h e \ d o m a i n c l o s u r e a s s u m p t i o n , " a n d a x i o m s ( 2 )

    e x p r e s s t h e \ u n i q u e n a m e a s s u m p t i o n . " T h e s e c o n d g r o u p o f a x i o m s c h a r a c t e r i z e s

    t h e p r e d i c a t e s M o t h e r a n d F a t h e r :

    8 x y M o t h e r ( x y ) ( x = E l i z a b e t h y = C h a r l e s )

    _ ( x = D i a n a y = W i l l i a m )

    _ ( x = D i a n a y = H a r r y ) ]

    8 x y F a t h e r ( x y ) ( x = C h a r l e s y = W i l l i a m )

    _ ( x = C h a r l e s y = H a r r y ) ] :

    ( 3 )

    P r o b l e m 1 . 1 . P r o v e t h a t T

    1

    i s c o n s i s t e n t .

    P r o b l e m 1 . 2 . P r o v e t h a t T

    1

    i s c o m p l e t e .

    T h e r e i s a s i m p l e c o n n e c t i o n b e t w e e n t h e r e l a t i o n a l d a t a b a s e D B

    1

    a n d t h e r s t - o r d e r

    t h e o r y T

    1

    . L e t u s a g r e e t o i d e n t i f y D B

    1

    w i t h t h e s e t o f a t o m i c s e n t e n c e s c o r r e s p o n d i n g

    t o t h e l i n e s o f i t s t a b l e s :

    M o t h e r ( E l i z a b e t h C h a r l e s )

    M o t h e r ( D i a n a W i l l i a m )

    M o t h e r ( D i a n a H a r r y )

    F a t h e r ( C h a r l e s W i l l i a m )

    F a t h e r ( C h a r l e s H a r r y ) :

    ( 4 )

    T h e n a n y a t o m i c s e n t e n c e i n t h e l a n g u a g e o f T

    1

    o t h e r t h a n a n e q u a l i t y i s p r o v a b l e i n

    T

    1

    i f i t b e l o n g s t o D B

    1

    , a n d r e f u t a b l e o t h e r w i s e .

    P r o b l e m 1 . 3 . P r o v e t h i s a s s e r t i o n . W o u l d i t b e t r u e w i t h o u t a x i o m s ( 1 ) i n t h e a x i o m

    s e t o f T

    1

    ? W i t h o u t a x i o m s ( 2 ) ?

    T h e o r y T

    1

    c a n b e f u r t h e r e x t e n d e d b y a x i o m s d e n i n g s o m e n e w p r e d i c a t e s i n t e r m s

    o f M o t h e r a n d F a t h e r , f o r i n s t a n c e :

    8 x y ( P a r e n t ( x y ) M o t h e r ( x y ) _ F a t h e r ( x y ) ) ( 5 )

    8 x ( C h i l d l e s s ( x ) : 9 y P a r e n t ( x y ) ) ( 6 )

    8 x y ( G r a n d p a r e n t ( x y ) 9 z ( P a r e n t ( x z ) P a r e n t ( z y ) ) ) : ( 7 )

    W e c a n a l s o a d d t h e p r e d i c a t e M a l e a n d t h e a x i o m s

    8 x y ( F a t h e r ( x y ) M a l e ( x ) )

    8 x y ( M o t h e r ( x y ) : M a l e ( x ) ) :

    ( 8 )

    2

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    3/57

    N o t e t h a t t h e a x i o m s f o r M a l e a r e d i e r e n t f r o m t h e o t h e r s i n t h a t t h e y d o n o t p r o v i d e

    a n e x p l i c i t d e n i t i o n o f t h e n e w p r e d i c a t e t h e y o n l y g i v e a s u c i e n t c o n d i t i o n a n d a

    n e c e s s a r y c o n d i t i o n . A c c o r d i n g l y , t h e r s t - o r d e r t h e o r y o b t a i n e d a t t h i s s t a g e i s n o t

    c o m p l e t e .

    P r o b l e m 1 . 4 . S h o w t h a t t h e s e n t e n c e s M a l e ( W i l l i a m ) a n d M a l e ( H a r r y ) a r e n e i t h e r

    p r o v a b l e n o r r e f u t a b l e f r o m t h e a x i o m s i n t r o d u c e d a b o v e .

    1 . 2 L o g i c P r o g r a m s

    N o w w e w i l l t u r n t o o u r m a i n s u b j e c t | r e p r e s e n t i n g d e c l a r a t i v e k n o w l e d g e b y l o g i c

    p r o g r a m s . A l o g i c p r o g r a m c o n s i s t s o f r u l e s . A r u l e h a s t w o p a r t s : t h e h e a d a n d t h e

    b o d y . I f t h e b o d y i s n o n e m p t y , t h e n w e s e p a r a t e i t f r o m t h e h e a d b y t h e s y m b o l

    ( \ i f " ) :

    H e a d B o d y :

    T h e p r e c i s e s y n t a x o f t h e h e a d a n d t h e b o d y a n d t h e s e m a n t i c s o f p r o g r a m s w i l l b e

    d e n e d l a t e r . H e r e w e o n l y g i v e a f e w e x a m p l e s .

    T h e d e n i t i o n o f M o t h e r , i n t h e n o t a t i o n o f l o g i c p r o g r a m m i n g , c o n s i s t s o f t h e

    f o l l o w i n g r u l e s :

    M o t h e r ( E l i z a b e t h C h a r l e s )

    M o t h e r ( D i a n a W i l l i a m )

    M o t h e r ( D i a n a H a r r y )

    : M o t h e r ( x y ) n o t M o t h e r ( x y ) :

    ( 9 )

    E a c h o f t h e r s t t h r e e r u l e s h a s a p a r t i c u l a r l y s i m p l e s t r u c t u r e : I t s b o d y i s e m p t y ,

    a n d i t s h e a d i s a n a t o m i c s e n t e n c e . T h e h e a d o f t h e l a s t r u l e i s a n e g a t e d a t o m , a n d

    i t s b o d y i s a n e x p r e s s i o n c o n t a i n i n g t h e s y m b o l n o t , c a l l e d \ n e g a t i o n a s f a i l u r e . " T h e

    r u l e t e l l s u s t h a t , f o r a n y i n d i v i d u a l s x a n d y u n d e r c o n s i d e r a t i o n , w e c a n c o n c l u d e

    : M o t h e r ( x y ) i f t h e p r o g r a m g i v e s n o e v i d e n c e t h a t M o t h e r ( x y ) . T h i s r u l e e x p r e s s e s

    t h e \ c l o s e d w o r l d a s s u m p t i o n " f o r t h e p r e d i c a t e M o t h e r . T h e a v a i l a b i l i t y o f t h i s r u l e

    a l l o w s u s , f o r i n s t a n c e , t o c o n c l u d e : M o t h e r ( E l i z a b e t h E l i z a b e t h ) .

    T h e n e g a t i o n a s f a i l u r e s y m b o l m a k e s l o g i c p r o g r a m s \ n o n m o n o t o n i c . " C l a s s i c a l

    l o g i c i s m o n o t o n i c i n t h e s e n s e t h a t a d d i n g a n a x i o m t o a r s t - o r d e r t h e o r y m a y o n l y

    a l l o w u s t o d e r i v e n e w t h e o r e m s n o t h e o r e m s p r o v e d e a r l i e r w i l l b e l o s t . L o g i c p r o g r a m s

    w i t h n e g a t i o n a s f a i l u r e a r e d i e r e n t : A d d i n g a r u l e t o a l o g i c p r o g r a m m a y f o r c e u s t o

    r e t r a c t s o m e o f t h e c o n c l u s i o n s o b t a i n e d u s i n g t h e m o r e l i m i t e d s e t o f r u l e s . C o n s i d e r ,

    f o r i n s t a n c e , p r o g r a m ( 9 ) w i t h o u t t h e r u l e M o t h e r ( D i a n a H a r r y ) . D u e t o t h e c l o s e d

    w o r l d a s s u m p t i o n , t h i s s m a l l e r p r o g r a m a l l o w s u s t o c o n c l u d e : M o t h e r ( D i a n a H a r r y ) .

    I f w e n o w p u t t h e r u l e M o t h e r ( D i a n a H a r r y ) b a c k i n , t h i s c o n c l u s i o n w i l l h a v e t o b e

    r e t r a c t e d . T h e s a m e p h e n o m e n o n i s o b s e r v e d i n r e l a t i o n a l d a t a b a s e s : A d d i n g a l i n e t o

    a d a t a b a s e t a b l e i n v a l i d a t e s a n e g a t i v e c o n c l u s i o n t h a t c o u l d b e o b t a i n e d e a r l i e r .

    T h e d e n i t i o n o f F a t h e r i s s i m i l a r t o ( 9 ) :

    F a t h e r ( C h a r l e s W i l l i a m )

    F a t h e r ( C h a r l e s H a r r y )

    : F a t h e r ( x y ) n o t F a t h e r ( x y ) :

    ( 1 0 )

    3

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    4/57

    H e r e a r e t h e l o g i c p r o g r a m m i n g c o u n t e r p a r t s o f d e n i t i o n s ( 5 ) { ( 7 ) :

    P a r e n t ( x y ) M o t h e r ( x y )

    P a r e n t ( x y ) F a t h e r ( x y )

    : P a r e n t ( x y ) n o t P a r e n t ( x y )

    ( 1 1 )

    : C h i l d l e s s ( x ) P a r e n t ( x y )

    C h i l d l e s s ( x ) n o t : C h i l d l e s s ( x )

    ( 1 2 )

    G r a n d p a r e n t ( x y ) P a r e n t ( x z ) P a r e n t ( z y )

    : G r a n d p a r e n t ( x y ) n o t G r a n d p a r e n t ( x y ) :

    ( 1 3 )

    T h e d e n i t i o n o f C h i l d l e s s i s d i e r e n t f r o m t h e o t h e r s i n t h a t i t i n c l u d e s t h e c l o s e d

    w o r l d a s s u m p t i o n f o r t h e n e g a t i o n o f t h e d e n e d p r e d i c a t e : I f t h e p r o g r a m g i v e s n o

    e v i d e n c e t h a t : C h i l d l e s s ( x ) t h e n w e c a n c o n c l u d e C h i l d l e s s ( x ) .

    T h e c o u n t e r p a r t o f ( 8 ) i n l o g i c p r o g r a m m i n g i s

    M a l e ( x ) F a t h e r ( x y )

    : M a l e ( x ) M o t h e r ( x y ) :

    ( 1 4 )

    N o t e t h a t t h e r e i s n o c l o s e d w o r l d a s s u m p t i o n h e r e .

    H e r e i s o n e m o r e e x a m p l e o f a l o g i c p r o g r a m m i n g d e n i t i o n :

    A n c e s t o r ( x y ) P a r e n t ( x y )

    A n c e s t o r ( x y ) A n c e s t o r ( x z ) A n c e s t o r ( z y )

    : A n c e s t o r ( x y ) n o t A n c e s t o r ( x y ) :

    ( 1 5 )

    A n c e s t o r o c c u r s b o t h i n t h e h e a d a n d i n t h e b o d y o f t h e s e c o n d r u l e , s o t h a t t h i s

    d e n i t i o n i s \ r e c u r s i v e . " I t h a s n o c o u n t e r p a r t i n r s t - o r d e r l o g i c . T h e a x i o m

    8 x y A n c e s t o r ( x y ) ( P a r e n t ( x y ) _ 9 z ( A n c e s t o r ( x z ) A n c e s t o r ( z y ) ) ) ] ( 1 6 )

    m a y s e e m p r o m i s i n g a s a t r a n s l a t i o n o f ( 1 5 ) i n t o r s t - o r d e r l o g i c b u t i t w o u l d n o t

    a l l o w u s t o p r o v e

    : A n c e s t o r ( E l i z a b e t h E l i z a b e t h ) ( 1 7 )

    o r a n y o t h e r \ n e g a t i v e " f a c t a b o u t A n c e s t o r .

    P r o b l e m 1 . 5 . V e r i f y t h a t ( 1 7 ) i s n o t d e r i v a b l e f r o m a x i o m s ( 1 ) { ( 3 ) , ( 5 ) a n d ( 1 6 ) .

    1 . 3 L o g i c P r o g r a m m i n g S y s t e m s

    W h e n a b o d y o f k n o w l e d g e i s e x p r e s s e d a s a l o g i c p r o g r a m , l o g i c p r o g r a m m i n g s y s t e m s

    c a n b e s o m e t i m e s u s e d t o a n s w e r q u e r i e s o n t h e b a s i s o f t h i s k n o w l e d g e .

    P r o l o g ( f o r P R O g r a m m i n g i n L O G i c ) i s t h e n a m e o f a f a m i l y o f l o g i c p r o g r a m m i n g

    s y s t e m s . H e r e i s a n e x a m p l e o f w h a t P r o l o g c a n d o . W e w o u l d l i k e t o u s e a P r o l o g

    s y s t e m t o a n s w e r q u e r i e s a b o u t t h e r e l a t i o n s M o t h e r , F a t h e r a n d P a r e n t . T o t h i s e n d ,

    w e s a v e r u l e s ( 9 ) { ( 1 1 ) i n a l e , i n t h e f o l l o w i n g f o r m :

    4

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    5/57

    m o t h e r ( e l i z a b e t h , c h a r l e s ) .

    m o t h e r ( d i a n a , w i l l i a m ) .

    m o t h e r ( d i a n a , h a r r y ) .

    f a t h e r ( c h a r l e s , w i l l i a m ) .

    f a t h e r ( c h a r l e s , h a r r y ) .

    p a r e n t ( X , Y ) : - m o t h e r ( X , Y ) .

    p a r e n t ( X , Y ) : - f a t h e r ( X , Y ) .

    T h e s y n t a x o f P r o l o g r e q u i r e s t h a t a n i d e n t i e r b e c a p i t a l i z e d i f i t r e p r e s e n t s a v a r i a b l e ,

    b u t n o t o t h e r w i s e e v e r y r u l e s h o u l d b e f o l l o w e d b y a p e r i o d t h e s y m b o l i s

    r e p r e s e n t e d b y t h e t w o c h a r a c t e r s : - . M o r e i m p o r t a n t l y , t h e c l o s e d w o r l d a s s u m p t i o n

    r u l e i s d r o p p e d f r o m e a c h o f t h e d e n i t i o n s ( 9 ) { ( 1 1 ) b e f o r e t h e p r o g r a m i s p r e s e n t e d t o

    P r o l o g f o r P r o l o g , s u c h a r u l e i s i m p l i c i t i n t h e d e n i t i o n o f e v e r y p r e d i c a t e . O n t h e

    o t h e r h a n d , P r o l o g d o e s n o t p e r m i t a n y e x p l i c i t r e f e r e n c e s t o c l a s s i c a l n e g a t i o n . F o r

    t h i s r e a s o n , o u r d e n i t i o n s o f C h i l d l e s s a n d M a l e c a n n o t b e g i v e n t o a P r o l o g s y s t e m

    a s d i r e c t l y a s t h e o t h e r s . B u t i t i s n o t d i c u l t t o e x t e n d P r o l o g s o t h a t i t w i l l k n o w

    a b o u t c l a s s i c a l n e g a t i o n . I n t h e d i s c u s s i o n o f t h e m a t h e m a t i c a l p r i n c i p l e s o f P r o l o g i n

    t h i s s u r v e y , a p r o g r a m i s a l l o w e d t o c o n t a i n b o t h k i n d s o f n e g a t i o n .

    W h e n y o u c a l l a P r o l o g s y s t e m , i t r e s p o n d s w i t h a l o g i n m e s s a g e , f o r i n s t a n c e :

    Q u i n t u s P r o l o g R e l e a s e 3 . 1 . 2 ( S u n - 4 , S u n O S 4 . 1 )

    C o p y r i g h t ( C ) 1 9 9 0 , Q u i n t u s C o r p o r a t i o n . A l l r i g h t s r e s e r v e d .

    2 1 0 0 G e n g R o a d , P a l o A l t o , C a l i f o r n i a U . S . A . ( 4 1 5 ) 8 1 3 - 3 8 0 0

    T h e n y o u t e l l t h e s y s t e m w h i c h l e c o n t a i n s y o u r s e t o f r u l e s , a n d t h e s y s t e m o p e n s

    a n d \ c o n s u l t s " ( o r \ c o m p i l e s " ) i t . A f t e r t h a t , y o u c a n g i v e t h e s y s t e m q u e r i e s , l i k e

    ? - p a r e n t ( e l i z a b e t h , c h a r l e s ) .

    ( ? - i s t h e P r o l o g p r o m p t ) o r

    ? - m o t h e r ( e l i z a b e t h , h a r r y ) .

    a n d P r o l o g w i l l a n s w e r | y e s t o t h e r s t q u e r y , a n d n o t o t h e s e c o n d .

    A q u e r y m a y c o n t a i n v a r i a b l e s t h i s i s u n d e r s t o o d a s a r e q u e s t t o n d a t u p l e o f

    v a l u e s o f t h e v a r i a b l e s t h a t m a k e s t h e q u e r y t r u e . F o r e x a m p l e , i n r e s p o n s e t o

    ? - p a r e n t ( X , h a r r y ) .

    Q u i n t u s P r o l o g w i l l s a y

    X = d i a n a .

    Y o u c a n a s k f o r a n o t h e r s o l u t i o n , a n d t h e r e p l y w i l l b e

    X = c h a r l e s .

    I f y o u a s k f o r y e t a n o t h e r a n s w e r , P r o l o g w i l l r e p l y n o .

    S o m e t i m e s P r o l o g d o e s n o t p r o d u c e a n a n s w e r . I f , f o r i n s t a n c e , t h e r u l e s

    a n c e s t o r ( X , Y ) : - p a r e n t ( X , Y ) .

    5

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    6/57

    a n c e s t o r ( X , Y ) : - a n c e s t o r ( X , Z ) , a n c e s t o r ( Z , Y ) .

    a r e a d d e d t o t h e l e , a n d t h e q u e r y

    ? - a n c e s t o r ( w i l l i a m , h a r r y ) .

    i s g i v e n t o Q u i n t u s P r o l o g , t h e n , i n s t e a d o f s a y i n g n o , i t w i l l f a i l t o t e r m i n a t e . S o m e

    q u e r y e v a l u a t i o n p r o c e d u r e s h a v e b e t t e r t e r m i n a t i o n p r o p e r t i e s t h a n t h e o n e e m p l o y e d

    i n P r o l o g s y s t e m s . F o r i n s t a n c e , A n c e s t o r q u e r i e s c a n b e s u c c e s s f u l l y h a n d l e d b y t h e

    p r o c e d u r e c a l l e d S L G .

    1 . 4 A b o u t t h i s S u r v e y

    I n s e v e r a l w a y s , t h i s s u r v e y o f t h e f o u n d a t i o n s o f l o g i c p r o g r a m m i n g i s d i e r e n t f r o m

    m o s t o t h e r s a v a i l a b l e i n t h e l i t e r a t u r e .

    1 . O u r f o c u s i s p r i m a r i l y o n s e m a n t i c s , r a t h e r t h a n q u e r y e v a l u a t i o n | o r , a s s o m e w o u l d

    s a y , o n t h e \ d e c l a r a t i v e " s e m a n t i c s o f l o g i c p r o g r a m m i n g , r a t h e r t h a n \ p r o c e d u r a l . "

    T h e m a t h e m a t i c a l f o u n d a t i o n s o f P r o l o g a r e d i s c u s s e d h e r e , b u t t h i s s u b j e c t i s n o t

    g i v e n t h e s a m e p r o m i n e n c e a s i n m o s t o t h e r s u r v e y s .

    2 . W e t r e a t p r o g r a m s a s p r o p o s i t i o n a l o b j e c t s r u l e s w i t h v a r i a b l e s a r e v i e w e d a s

    \ s c h e m a t a " t h a t r e p r e s e n t t h e i r g r o u n d i n s t a n c e s .

    I n t h e n e x t t w o s e c t i o n s , s u c h r u l e s a p p e a r i n e x a m p l e s o n l y . T h i s i s b e c a u s e t h e

    d i e r e n c e b e t w e e n a r u l e w i t h v a r i a b l e s a n d t h e s e t o f i t s g r o u n d i n s t a n c e s i s l e s s

    e s s e n t i a l s e m a n t i c a l l y t h a n f r o m t h e p e r s p e c t i v e o f q u e r y e v a l u a t i o n .

    3 . F r o m t h e v e r y b e g i n n i n g , w e c o n s i d e r p r o g r a m s t h a t m a y c o n t a i n c l a s s i c a l n e g a t i o n .

    N e g a t i o n a s f a i l u r e , c o n c e p t u a l l y m o r e d i c u l t , i s i n t r o d u c e d o n l y i n S e c t i o n 3 .

    H i s t o r i c a l l y , h o w e v e r , l o g i c p r o g r a m m i n g w i t h c l a s s i c a l n e g a t i o n i s a r e l a t i v e l y r e c e n t

    i n v e n t i o n . P r o g r a m s w i t h o u t c l a s s i c a l n e g a t i o n a r e c a l l e d \ n o r m a l , " a n d t h e i r s p e c i a l

    p r o p e r t i e s a r e d i s c u s s e d i n S e c t i o n s 2 . 7 a n d 3 . 8 .

    4 . W e a c c e p t t h e s e m a n t i c s o f n e g a t i o n a s f a i l u r e g i v e n b y t h e c o n c e p t o f a n \ a n s w e r

    s e t , " a n d d o n o t t a l k a t a l l a b o u t a l t e r n a t i v e a p p r o a c h e s . T h e \ w e l l - f o u n d e d m o d e l "

    i s d e n e d i n S e c t i o n 3 . 3 a n d t h e \ c o m p l e t i o n " o f a p r o g r a m i n S e c t i o n 3 . 8 , b e c a u s e

    t h e s e c o n c e p t s a r e c l o s e l y r e l a t e d t o a n s w e r s e t s , b u t t h e i r r o l e a s s t a n d - a l o n e t h e o r i e s

    o f n e g a t i o n a s f a i l u r e i s n o t d i s c u s s e d i n a n y d e t a i l .

    I n t h e n e x t s e c t i o n , w e i n t r o d u c e \ b a s i c " p r o g r a m s t h a t m a y i n c l u d e c l a s s i c a l

    n e g a t i o n , b u t n o t n e g a t i o n a s f a i l u r e . P r o g r a m s w i t h n e g a t i o n a s f a i l u r e a r e i n v e s t i g a t e d

    i n S e c t i o n 3 . A l l t h e s e p r o g r a m s a r e p r o p o s i t i o n a l p r o g r a m s w i t h v a r i a b l e s a r e t h e

    s u b j e c t o f S e c t i o n 4 . I n S e c t i o n 5 , w e d e s c r i b e t w o e x t e n s i o n s o f l o g i c p r o g r a m s w i t h

    n e g a t i o n a s f a i l u r e : d i s j u n c t i v e p r o g r a m s a n d d e f a u l t t h e o r i e s .

    2 B a s i c P r o g r a m s

    B a s i c p r o g r a m s a r e p r o g r a m s w i t h o u t n e g a t i o n a s f a i l u r e . T h e e x p r e s s i v e p o s s i b i l i t i e s

    o f t h i s s u b c l a s s a r e m u c h t o o l i m i t e d f o r m e a n i n g f u l a p p l i c a t i o n s t o k n o w l e d g e

    6

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    7/57

    r e p r e s e n t a t i o n , b u t t h e s t u d y o f i t s m a t h e m a t i c a l p r o p e r t i e s p r o v i d e s a n e c e s s a r y

    f o u n d a t i o n f o r f u r t h e r d i s c u s s i o n .

    2 . 1 S y n t a x

    W e b e g i n w i t h a n o n e m p t y s e t A o f s y m b o l s , c a l l e d a t o m s . T h e c h o i c e o f A d e t e r m i n e s

    t h e \ l a n g u a g e " o f t h e p r o g r a m s u n d e r c o n s i d e r a t i o n . A t o m s w i l l b e a l s o c a l l e d p o s i t i v e

    l i t e r a l s a n e g a t i v e l i t e r a l i s a n a t o m p r e c e d e d b y t h e c l a s s i c a l n e g a t i o n s y m b o l : . A

    l i t e r a l i s a p o s i t i v e l i t e r a l o r a n e g a t i v e l i t e r a l . T h e s e t o f l i t e r a l s w i l l b e d e n o t e d b y L i t

    A

    ,

    o r s i m p l y L i t . F o r a n y a t o m A , t h e l i t e r a l s A a n d : A a r e s a i d t o b e c o m p l e m e n t a r y .

    A s e t o f l i t e r a l s i s i n c o n s i s t e n t i f i t c o n t a i n s a c o m p l e m e n t a r y p a i r , a n d c o n s i s t e n t

    o t h e r w i s e .

    A b a s i c r u l e i s a n o r d e r e d p a i r H e a d B o d y , w h o s e r s t m e m b e r H e a d i s a l i t e r a l ,

    a n d w h o s e s e c o n d m e m b e r B o d y i s a n i t e s e t o f l i t e r a l s . A b a s i c r u l e w i t h t h e h e a d

    L

    0

    a n d t h e b o d y f L

    1

    : : : L

    k

    g c a n b e a l s o w r i t t e n a s

    L

    0

    L

    1

    : : : L

    k

    : ( 1 8 )

    I f t h e b o d y i s e m p t y t h e n c a n b e d r o p p e d .

    A b a s i c p r o g r a m i s a s e t o f b a s i c r u l e s . F o r i n s t a n c e , i f A i s f p q r s g t h e n t h e

    r u l e s

    p

    : q

    r p q

    : r p : q

    s r

    s p s

    : s p : q : r

    ( 1 9 )

    f o r m a b a s i c p r o g r a m . H e r e , a s i n m a n y o t h e r e x a m p l e s , e v e r y a t o m i s u s e d i n t h e

    p r o g r a m a t l e a s t o n c e . I n s u c h c a s e s , i t i s n o t n e c e s s a r y t o s p e c i f y t h e s e t o f a t o m s

    e x p l i c i t l y w e c a n d e s c r i b e a p r o g r a m s i m p l y b y l i s t i n g i t s r u l e s , a n d i t w i l l b e p r e s u m e d

    t h a t A i s t h e s e t o f a l l s y m b o l s u s e d i n t h e r u l e s a s a t o m s .

    N o t e t h a t , a c c o r d i n g t o t h i s d e n i t i o n , t h e b o d y o f a r u l e i s a s e t o f l i t e r a l s , r a t h e r

    t h a n a l i s t . T h e r e i s n o s u c h t h i n g a s t h e o r d e r o f l i t e r a l s , o r t h e n u m b e r o f r e p e t i t i o n s

    o f a l i t e r a l , i n t h e b o d y o f a r u l e . S i m i l a r l y , a p r o g r a m i s a s e t o f r u l e s , a n d n o t a l i s t .

    I n a p p l i c a t i o n s , A i s u s u a l l y t h e s e t o f a t o m i c s e n t e n c e s f o r m e d u s i n g s o m e s u p p l y

    o f o b j e c t , f u n c t i o n a n d p r e d i c a t e c o n s t a n t s . S e t s o f r u l e s i n s u c h a l a n g u a g e a r e o f t e n

    r e p r e s e n t e d b y s c h e m a t a t h a t u s e m e t a v a r i a b l e s f o r g r o u n d ( t h a t i s , c l o s e d ) t e r m s . F o r

    i n s t a n c e , \ s c h e m a t i c p r o g r a m " ( 9 ) s t a n d s f o r a s e t o f 2 8 r u l e s . S c h e m a t i c r u l e s a r e

    d i s c u s s e d i n S e c t i o n 4 . F o r t h e t i m e b e i n g , w e w i l l o n l y o b s e r v e t h a t , i n t h e p r e s e n c e

    o f f u n c t i o n s y m b o l s , a s c h e m a t i c r u l e c a n r e p r e s e n t a n i n n i t e s e t o f i n s t a n c e s . F o r

    t h i s r e a s o n , i t i s i m p o r t a n t t h a t , i n t h e d e n i t i o n a b o v e , a b a s i c p r o g r a m i s a l l o w e d t o

    c o n s i s t o f i n n i t e l y m a n y r u l e s ( a l t h o u g h t h e b o d y o f e a c h r u l e i s r e q u i r e d t o b e n i t e ) .

    7

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    8/57

    H e r e i s a n e x a m p l e o f a p r o g r a m w h o s e l a n g u a g e h a s i n n i t e l y m a n y a t o m s

    p

    0

    p

    1

    : : : :

    p

    5

    p

    n + 1

    p

    n

    ( n 0 ) :

    ( 2 0 )

    2 . 2 T h e C o n s e q u e n c e R e l a t i o n

    I n t h e d e v e l o p m e n t o f c l a s s i c a l l o g i c , t h e \ c o n s e q u e n c e s " o f a s e t o f s e n t e n c e s ; a r e

    u s u a l l y d e n e d a s t h e s e n t e n c e s t h a t c a n b e d e r i v e d f r o m ; a n d f r o m s o m e \ l o g i c a l

    a x i o m s " u s i n g s o m e \ i n f e r e n c e r u l e s . " T o p u t i t d i e r e n t l y , t h e s e t o f c o n s e q u e n c e s o f

    ; i s t h e s m a l l e s t s e t o f s e n t e n c e s t h a t c o n t a i n s ; a n d t h e l o g i c a l a x i o m s a n d i s c l o s e d

    u n d e r t h e i n f e r e n c e r u l e s .

    T h e d e n i t i o n o f t h e c o n s e q u e n c e o p e r a t o r f o r b a s i c p r o g r a m s g i v e n b e l o w i s , i n

    o n e w a y , s i m p l e r . T h e c o n s e q u e n c e s o f a p r o g r a m a r e l i t e r a l s . W h a t i s t h e c o u n t e r p a r t

    o f t h e l o g i c a l a x i o m s a n d i n f e r e n c e r u l e s w h e n l i t e r a l s o n l y a r e i n v o l v e d ? W e a d o p t t h e

    v i e w t h a t a l i t e r a l f o l l o w s f r o m a s e t o f l i t e r a l s \ b y p u r e l o g i c " o n l y w h e n i t b e l o n g s t o

    t h i s s e t , e x c e p t i n t h e t r i v i a l c a s e w h e n t h e s e t i s i n c o n s i s t e n t i n t h i s l a s t c a s e , e v e r y

    l i t e r a l f o l l o w s f r o m i t . T h i s i s m o t i v a t e d b y a s i m p l e f a c t o f c l a s s i c a l p r o p o s i t i o n a l l o g i c :

    I f ; i s a c o n s i s t e n t s e t o f l i t e r a l s a n d a l i t e r a l L i s a c o n s e q u e n c e o f ; t h e n L 2 ; .

    P r o b l e m 2 . 1 . P r o v e t h i s f a c t .

    O n t h e o t h e r h a n d , t h e e l e m e n t s o f a p r o g r a m a r e r u l e s , a n d n o t m e r e l y l i t e r a l s

    i n s t e a d o f r e q u i r i n g t h a t t h e s e t o f c o n s e q u e n c e s o f a p r o g r a m i n c l u d e a l l i t s r u l e s , w e

    w i l l r e q u i r e t h a t i t b e \ c l o s e d " u n d e r t h e m .

    T h i s d i s c u s s i o n s u g g e s t s t h e f o l l o w i n g d e n i t i o n s . L e t X b e a s e t o f l i t e r a l s . W e

    s a y t h a t X i s l o g i c a l l y c l o s e d i f i t i s c o n s i s t e n t o r e q u a l s L i t . W e s a y t h a t X i s c l o s e d

    u n d e r a b a s i c p r o g r a m i f , f o r e v e r y r u l e H e a d B o d y i n , H e a d 2 X w h e n e v e r

    B o d y X . B y C n ( ) w e d e n o t e t h e s m a l l e s t s e t o f l i t e r a l s w h i c h i s b o t h l o g i c a l l y

    c l o s e d a n d c l o s e d u n d e r .

    P r o b l e m 2 . 2 . P r o v e t h a t s u c h a s e t a l w a y s e x i s t s .

    T h e e l e m e n t s o f C n ( ) a r e c a l l e d t h e c o n s e q u e n c e s o f .

    A b a s i c p r o g r a m i s c o n s i s t e n t i f C n ( ) i s c o n s i s t e n t , a n d i n c o n s i s t e n t o t h e r w i s e .

    T h e f o l l o w i n g f a c t e a s i l y f o l l o w s f r o m t h e d e n i t i o n o f C n ( ) :

    P r o p o s i t i o n 2 . 1 . F o r a n y b a s i c p r o g r a m ,

    i f i s c o n s i s t e n t t h e n C n ( ) i s t h e s m a l l e s t s e t o f l i t e r a l s c l o s e d u n d e r

    i f i s i n c o n s i s t e n t t h e n C n ( ) = L i t .

    L e t u s n d , f o r i n s t a n c e , t h e c o n s e q u e n c e s o f p r o g r a m ( 1 9 ) . T h e p r o g r a m i n c l u d e s

    t w o r u l e s w h o s e b o d i e s a r e e m p t y i t i s c l e a r t h a t t h e i r h e a d s

    p : q ( 2 1 )

    8

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    9/57

    b e l o n g t o e v e r y s e t o f l i t e r a l s c l o s e d u n d e r ( 1 9 ) . F u r t h e r m o r e , t h e p r o g r a m i n c l u d e s a

    r u l e w i t h t h e b o d y p : q c o n s e q u e n t l y , t h e h e a d

    : r ( 2 2 )

    o f t h i s r u l e b e l o n g s t o e v e r y s u c h s e t a l s o . T h e n e x t s t e p i s t o o b s e r v e t h a t t h e r e i s o n e

    m o r e r u l e i n t h e p r o g r a m w h o s e b o d y c o n s i s t s o f t h e l i t e r a l s t h a t a r e a l l a m o n g ( 2 1 )

    a n d ( 2 2 ) i t s h e a d

    : s ( 2 3 )

    a l s o b e l o n g s t o e v e r y s e t c l o s e d u n d e r t h e r u l e s o f ( 1 9 ) . T h e s e t o f l i t e r a l s g e n e r a t e d

    b y n o w , ( 2 1 ) { ( 2 3 ) , i s b o t h l o g i c a l l y c l o s e d a n d c l o s e d u n d e r ( 1 9 ) . I t f o l l o w s t h a t t h i s

    i s t h e s e t o f a l l c o n s e q u e n c e s o f ( 1 9 ) .

    P r o b l e m 2 . 3 . F i n d t h e s e t o f c o n s e q u e n c e s o f p r o g r a m ( 2 0 ) .

    N o t e t h a t r e p l a c i n g t h e r u l e

    : s p : q : r

    i n ( 1 9 ) b y a \ c o n t r a p o s i t i v e " r u l e

    r p : q s

    w o u l d c h a n g e t h e s e t o f c o n s e q u e n c e s o f t h e p r o g r a m : ( 2 3 ) w o u l d n o t b e a m o n g t h e

    c o n s e q u e n c e s a n y m o r e . U n l i k e c o n d i t i o n a l s i n c l a s s i c a l l o g i c , a b a s i c r u l e i s , g e n e r a l l y ,

    n o t e q u i v a l e n t t o i t s c o n t r a p o s i t i v e .

    P r o p o s i t i o n 2 . 2 . F o r a n y b a s i c p r o g r a m s

    1

    a n d

    2

    , i f

    1

    2

    t h e n C n (

    1

    )

    C n (

    2

    ) .

    T h e m o n o t o n i c i t y o f C n i s r e l a t e d t o t h e f a c t t h a t b a s i c p r o g r a m s d o n o t u s e

    n e g a t i o n a s f a i l u r e . T h e c o n s e q u e n c e o p e r a t o r h a s a l s o t h e f o l l o w i n g c o m p a c t n e s s

    p r o p e r t y :

    P r o p o s i t i o n 2 . 3 . E v e r y c o n s e q u e n c e o f a b a s i c p r o g r a m i s a c o n s e q u e n c e o f a n i t e

    s u b s e t o f .

    P r o b l e m 2 . 4 . V e r i f y t h i s a s s e r t i o n f o r p r o g r a m ( 2 0 ) .

    L e t b e a b a s i c p r o g r a m , a n d X a s e t o f l i t e r a l s . W e s a y t h a t X i s s u p p o r t e d b y

    i f , f o r e a c h l i t e r a l L 2 X , t h e r e e x i s t s a r u l e H e a d B o d y i n s u c h t h a t H e a d = L

    a n d B o d y X . A r u l e s a t i s f y i n g t h e s e c o n d i t i o n s \ s u p p o r t s " t h e p r e s e n c e o f L i n X

    i t p r o v i d e s a \ r e a s o n " f o r i n c l u d i n g L i n X .

    P r o p o s i t i o n 2 . 4 . F o r a n y c o n s i s t e n t b a s i c p r o g r a m , C n ( ) i s s u p p o r t e d b y .

    P r o b l e m 2 . 5 . V e r i f y t h i s a s s e r t i o n f o r p r o g r a m s ( 1 9 ) a n d ( 2 0 ) .

    P r o b l e m 2 . 6 . S h o w t h a t w i t h o u t t h e c o n s i s t e n c y a s s u m p t i o n t h i s a s s e r t i o n w o u l d b e

    i n c o r r e c t .

    A h e a d l i t e r a l o f a b a s i c p r o g r a m i s t h e h e a d o f a r u l e o f .

    9

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    10/57

    C o r o l l a r y . I f a b a s i c p r o g r a m i s c o n s i s t e n t t h e n e v e r y c o n s e q u e n c e o f i s a h e a d

    l i t e r a l o f .

    T h e r e i s a s i m p l e s y n t a c t i c s u c i e n t c o n d i t i o n f o r c o n s i s t e n c y . A b a s i c p r o g r a m i s

    h e a d - c o n s i s t e n t i f t h e s e t o f i t s h e a d l i t e r a l s i s c o n s i s t e n t .

    P r o p o s i t i o n 2 . 5 . E v e r y h e a d - c o n s i s t e n t b a s i c p r o g r a m i s c o n s i s t e n t .

    F o r i n s t a n c e , ( 2 0 ) i s h e a d - c o n s i s t e n t . P r o g r a m ( 1 9 ) i s c o n s i s t e n t b u t n o t h e a d -

    c o n s i s t e n t .

    2 . 3 B o t t o m - U p E v a l u a t i o n

    C o m p u t i n g t h e s e t o f c o n s e q u e n c e s o f p r o g r a m ( 1 9 ) i n S e c t i o n 2 . 2 i s a n e x a m p l e o f t h e

    p r o c e s s o f \ b o t t o m - u p e v a l u a t i o n " t h a t c a n b e a p p l i e d t o a n y b a s i c p r o g r a m . I n o r d e r

    t o d e s c r i b e t h i s p r o c e s s , w e d e n e , f o r a n y b a s i c p r o g r a m , t h e f u n c t i o n T

    f r o m s e t s

    o f l i t e r a l s t o s e t s o f l i t e r a l s , a s f o l l o w s : T

    X i s

    f H e a d : H e a d B o d y 2 B o d y X g

    i f X i s c o n s i s t e n t , a n d L i t o t h e r w i s e . T h u s T

    X i s t h e s e t o f l i t e r a l s t h a t c a n b e d e r i v e d

    f r o m X \ i n o n e s t e p " u s i n g e i t h e r a r u l e o f o r \ p u r e l o g i c . "

    I t i s c l e a r t h a t T

    i s m o n o t o n e . T h e d i s c u s s i o n o f t h i s f u n c t i o n b e l o w u s e s t h e

    t e r m i n o l o g y a n d r e s u l t s o f t h e t h e o r y o f m o n o t o n e f u n c t i o n s r e v i e w e d i n A p p e n d i x .

    T h e r e i s a s i m p l e r e l a t i o n s h i p b e t w e e n t h e p r e - x p o i n t s o f T

    a n d t h e t w o c l o s u r e

    p r o p e r t i e s d e n e d i n S e c t i o n 2 . 2 :

    P r o p o s i t i o n 2 . 6 . F o r a n y b a s i c p r o g r a m a n d a n y s e t o f l i t e r a l s X , X i s a p r e -

    x p o i n t o f T

    i X i s b o t h l o g i c a l l y c l o s e d a n d c l o s e d u n d e r .

    U s i n g P r o p o s i t i o n A . 1 , w e c o n c l u d e :

    C o r o l l a r y . C n ( ) i s t h e l e a s t x p o i n t o f T

    .

    A c c o r d i n g t o P r o p o s i t i o n A . 2 , t h e u n i o n o f t h e s e t s o b t a i n e d b y i t e r a t i n g T

    o n t h e

    e m p t y s e t i s a s u b s e t o f t h e l e a s t x p o i n t o f T

    . F o r t h i s p a r t i c u l a r f u n c t i o n , t h e u n i o n

    h a p p e n s t o b e e q u a l t o t h i s x p o i n t :

    P r o p o s i t i o n 2 . 7 . F o r a n y b a s i c p r o g r a m ,

    C n ( ) =

    n 0

    T

    n

    :

    F o r e x a m p l e , i f i s ( 1 9 ) t h e n

    T

    0

    =

    T

    1

    = f p : q g

    T

    2

    = f p : q : r g

    T

    3

    = f p : q : r : s g :

    1 0

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    11/57

    T h e l a s t s e t i s a x p o i n t o f T

    , s o t h a t , f o r e v e r y n > 3 , T

    n

    = T

    3

    . A c c o r d i n g t o

    P r o p o s i t i o n 2 . 7 ,

    C n ( ) = f p : q : r : s g :

    I f i s i n n i t e t h e n i t i s p o s s i b l e t h a t n o n e o f t h e s e t s T

    n

    i s a x p o i n t o f , s o

    t h a t e v e r y n e x t t e r m o f t h e s e q u e n c e a d d s n e w c o n s e q u e n c e s t o t h e s e t a c c u m u l a t e d

    e a r l i e r .

    P r o b l e m 2 . 7 . F i n d t h e s e t s T

    n

    f o r p r o g r a m ( 2 0 ) .

    T h e p r o c e s s o f b o t t o m - u p e v a l u a t i o n i s d i e r e n t f r o m t h e p r o c e s s o f c o m p u t a t i o n

    u s e d i n P r o l o g | t h e l a t t e r i s \ g o a l - d i r e c t e d . " T h e o p e r a t i o n o f P r o l o g f o r b a s i c

    p r o g r a m s i s d i s c u s s e d i n S e c t i o n 2 . 6 .

    2 . 4 S p l i t t i n g

    C o m p u t i n g t h e c o n s e q u e n c e s o f a p r o g r a m c a n b e s o m e t i m e s s i m p l i e d b y \ s p l i t t i n g "

    i t i n t o p a r t s .

    W e s a y t h a t a s e t U o f l i t e r a l s s p l i t s a b a s i c p r o g r a m i f , f o r e v e r y r u l e

    H e a d B o d y i n , B o d y U w h e n e v e r H e a d 2 U . I f U s p l i t s t h e n t h e s e t o f

    r u l e s i n w h o s e h e a d s b e l o n g t o U w i l l b e c a l l e d t h e b a s e o f ( r e l a t i v e t o U ) , a n d

    d e n o t e d b y b

    U

    ( ) .

    F o r e x a m p l e , t h e s e t U = f p q : q r g s p l i t s p r o g r a m ( 1 9 ) , a n d t h e b a s e c o n s i s t s o f

    t h e r s t t h r e e r u l e s o f t h e p r o g r a m :

    p

    : q

    r p q :

    ( 2 4 )

    P r o b l e m 2 . 8 . A l i t e r a l o c c u r s i n a b a s i c p r o g r a m i f i t i s t h e h e a d o f a r u l e o f o r

    b e l o n g s t o t h e b o d y o f a r u l e o f . A s p l i t t i n g s e t U f o r a b a s i c p r o g r a m i s t r i v i a l

    i f U c o n t a i n s n o l i t e r a l s o c c u r r i n g i n o r c o n t a i n s a l l o f t h e m . G i v e a n e x a m p l e o f a

    b a s i c p r o g r a m t h a t c o n s i s t s o f 1 0 0 r u l e s a n d h a s n o n o n t r i v i a l s p l i t t i n g s e t s .

    I f U s p l i t s t h e n , a c c o r d i n g t o P r o p o s i t i o n 2 . 8 s t a t e d b e l o w , t h e c o n s e q u e n c e s o f

    c a n b e c o m p u t e d i n t w o s t e p s . F i r s t , w e n d t h e s e t C o f t h e c o n s e q u e n c e s o f t h e

    b a s e b

    U

    ( ) . S e c o n d , C i s u s e d t o e l i m i n a t e t h e e l e m e n t s o f U f r o m t h e r e m a i n i n g r u l e s

    o f t h e p r o g r a m : I f L 2 C t h e n L i s \ t r i v i a l " a n d c a n b e d e l e t e d f r o m t h e b o d i e s o f t h e

    r e m a i n i n g r u l e s i f L 2 U n C t h e n e v e r y r u l e w i t h L i n t h e b o d y i s \ u s e l e s s " a n d c a n

    b e d e l e t e d a s a w h o l e . A f t e r t h a t , w e n d t h e c o n s e q u e n c e s o f t h e r e s u l t i n g p r o g r a m

    a n d a p p e n d t h e m t o C .

    I n t h e e x a m p l e , C = f p : q g a n d U n C = f q r g . T h e c o m p l e m e n t o f t h e b a s e i s

    : r p : q

    s r

    s p s

    : s p : q : r :

    1 1

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    12/57

    W e d r o p t h e r u l e w i t h r i n t h e b o d y a n d d e l e t e p a n d : q f r o m t h e b o d i e s o f t h e

    r e m a i n i n g r u l e s . T h e r e s u l t i s

    : r

    s s

    : s : r :

    T h e s e t o f c o n s e q u e n c e s o f t h i s p r o g r a m i s f : r : s g . T h e u n i o n C f : r : s g i s t h e s e t

    o f c o n s e q u e n c e s o f ( 1 9 ) .

    I n g e n e r a l , t h e e l i m i n a t i o n p r o c e s s c a n b e d e s c r i b e d u s i n g t h e f o l l o w i n g n o t a t i o n .

    F o r a n y b a s i c p r o g r a m , a n y s e t U o f l i t e r a l s a n d a n y s u b s e t C o f U , e

    U

    ( C ) s t a n d s

    f o r t h e b a s i c p r o g r a m o b t a i n e d f r o m b y

    d e l e t i n g e a c h r u l e H e a d B o d y s u c h t h a t B o d y \ ( U n C ) 6= , a n d

    r e p l a c i n g e a c h r e m a i n i n g r u l e H e a d B o d y b y H e a d ( B o d y n U ) .

    H e r e i s a t h e o r e m e x p r e s s i n g t h e s o u n d n e s s o f t h e s p l i t t i n g m e t h o d f o r c o m p u t i n g

    C n ( ) :

    P r o p o s i t i o n 2 . 8 . L e t U b e a s e t o f l i t e r a l s t h a t s p l i t s a b a s i c p r o g r a m , a n d l e t

    C = C n ( b

    U

    ( ) ) . I f t h e s e t C C n ( e

    U

    ( n b

    U

    ( ) C ) ) i s c o n s i s t e n t t h e n i t e q u a l s C n ( )

    o t h e r w i s e , i s i n c o n s i s t e n t .

    P r o b l e m 2 . 9 . V e r i f y t h e a s s e r t i o n o f P r o p o s i t i o n 2 . 8 f o r t h e c a s e w h e n U i s t r i v i a l

    ( a s d e n e d i n P r o b l e m 2 . 8 ) .

    P r o b l e m 2 . 1 0 . V e r i f y t h e a s s e r t i o n o f P r o p o s i t i o n 2 . 8 f o r p r o g r a m ( 1 9 ) a n d U = f q g .

    P r o b l e m 2 . 1 1 . S h o w t h a t t h e r s t a s s e r t i o n o f P r o p o s i t i o n 2 . 8 w o u l d b e i n c o r r e c t

    w i t h o u t t h e c o n s i s t e n c y a s s u m p t i o n .

    2 . 5 T h e S L D C a l c u l u s

    C o n s i d e r t h e p r o g r a m

    p q

    q

    r s

    r p q :

    ( 2 5 )

    W e w o u l d l i k e t o n d o u t w h e t h e r r i s a c o n s e q u e n c e o f t h i s p r o g r a m . T h e p r o g r a m

    h a s t w o r u l e s w i t h t h e h e a d r . T h e r s t o f t h e m s h o w s t h a t r i s a c o n s e q u e n c e o f t h e

    p r o g r a m i f s i s . T h e r e i s n o e v i d e n c e , h o w e v e r , t h a t s i s a c o n s e q u e n c e , b e c a u s e t h e

    p r o g r a m d o e s n o t c o n t a i n r u l e s w i t h s i n t h e h e a d . L e t u s t r y t h e s e c o n d r u l e w i t h t h e

    h e a d r . I t s h o w s t h a t r i s a c o n s e q u e n c e i f b o t h p a n d q a r e c o n s e q u e n c e s . T h e o n l y

    r u l e w i t h t h e h e a d p s h o w s t h a t p i s a c o n s e q u e n c e i f q i s . I t r e m a i n s t o d e t e r m i n e

    w h e t h e r q i s a c o n s e q u e n c e o f t h e p r o g r a m . T h e a n s w e r t o t h i s q u e s t i o n i s y e s , b e c a u s e

    q i s t h e h e a d o f a r u l e w i t h t h e e m p t y b o d y . W e c o n c l u d e t h a t r i s a c o n s e q u e n c e o f

    ( 2 5 ) .

    1 2

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    13/57

    T h e r e a s o n i n g t h a t h a s l e d u s t o t h i s c o n c l u s i o n c a n b e s y m b o l i c a l l y r e p r e s e n t e d a s

    f o l l o w s :

    j =

    j = f q g

    j = f p q g

    j = f r g

    ( 2 6 )

    T h e s i g n j = h e r e e x p r e s s e s \ s u c c e s s . "

    L e t u s d e t e r m i n e n o w w h e t h e r r i s a c o n s e q u e n c e o f t h e p r o g r a m o b t a i n e d f r o m

    ( 2 5 ) b y a d d i n g s t o t h e b o d y o f t h e s e c o n d r u l e :

    p q

    q s

    r s

    r p q :

    ( 2 7 )

    A s b e f o r e , t h e a t t e m p t t o e s t a b l i s h t h a t r i s a c o n s e q u e n c e b y u s i n g t h e r s t r u l e w i t h

    t h e h e a d r f a i l s , a n d t h e s e c o n d r u l e l e a d s u s t o t h e q u e s t i o n w h e t h e r q i s a c o n s e q u e n c e .

    T h e p r o g r a m c o n t a i n s o n e r u l e w i t h t h e h e a d q , a n d i t s b o d y i s s . C o n s e q u e n t l y , w e

    n e e d t o d e t e r m i n e w h e t h e r s i s a c o n s e q u e n c e . S i n c e s i s n o t t h e h e a d o f a n y r u l e , i t

    a p p e a r s t h a t t h e a n s w e r t o t h i s q u e s t i o n m u s t b e n o , s o t h a t r i s n o t a c o n s e q u e n c e o f

    ( 2 7 ) .

    T h e r e a s o n i n g t h a t h a s l e d u s t o t h i s c o n c l u s i o n c a n b e s y m b o l i c a l l y r e p r e s e n t e d

    b y a t r e e :

    = j f s g

    = j f q g

    = j f s g = j f p q g

    = j f r g

    ( 2 8 )

    T h e s i g n = j e x p r e s s e s \ f a i l u r e . "

    F i g u r e s ( 2 6 ) a n d ( 2 8 ) a r e e x a m p l e s o f d e r i v a t i o n s i n t h e \ S L D c a l c u l u s " t h a t w e

    w i l l n o w i n t r o d u c e .

    1

    A g o a l i s a n i t e s e t o f l i t e r a l s . I n t h e S L D c a l c u l u s f o r a b a s i c p r o g r a m , t h e

    d e r i v a b l e o b j e c t s a r e e x p r e s s i o n s o f t h e f o r m s j = G a n d = j G , w h e r e G i s a g o a l . T h e

    1

    T h e l e t t e r s S , L a n d D a r e t h e i n i t i a l l e t t e r s o f t h e w o r d s \ s e l e c t i o n , " \ l i n e a r " a n d \ d e n i t e " | t h e

    n a m e s o f t h r e e i d e a s t h a t w e r e h i s t o r i c a l l y a s s o c i a t e d w i t h g o a l - d i r e c t e d s e a r c h i n l o g i c p r o g r a m m i n g .

    T h e n o t i o n o f a d e n i t e c l a u s e a n d i t s r e l a t i o n t o l o g i c p r o g r a m s a r e d i s c u s s e d i n S e c t i o n 2 . 7 b e l o w .

    T h e o t h e r t w o w o r d s c o m e f r o m t h e t h e o r y o f r e s o l u t i o n i n a u t o m a t e d r e a s o n i n g .

    1 3

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    14/57

    o n l y a x i o m i s

    j = :

    I n t h e i n f e r e n c e r u l e s , t h e f o l l o w i n g n o t a t i o n i s u s e d : F o r a n y l i t e r a l L , B o d i e s ( L ) i s

    t h e s e t o f t h e b o d i e s o f a l l r u l e s i n w i t h t h e h e a d L . T h e r e a r e t w o i n f e r e n c e r u l e s ,

    o n e f o r p r o v i n g s u c c e s s a n d o n e f o r p r o v i n g f a i l u r e :

    ( S )

    j = G B

    j = G f L g

    i f B 2 B o d i e s ( L )

    ( F )

    = j G B f o r a l l B 2 B o d i e s ( L )

    = j G f L g

    N o t e t h a t t h e n u m b e r o f p r e m i s e s o f ( F ) e q u a l s t h e c a r d i n a l i t y o f B o d i e s ( L ) . I n

    p a r t i c u l a r , i t c a n b e z e r o o r i n n i t e .

    2

    F i g u r e ( 2 6 ) i s a d e r i v a t i o n i n t h e S L D c a l c u l u s f o r p r o g r a m ( 2 5 ) . E v e r y h o r i z o n t a l

    b a r i n t h i s g u r e r e p r e s e n t s a n a p p l i c a t i o n o f ( S ) . F o r i n s t a n c e , t h e t r a n s i t i o n f r o m

    j = f p q g t o j = f r g a t t h e e n d o f t h e d e r i v a t i o n i s a n a p p l i c a t i o n o f ( S ) w i t h G = ,

    L = r a n d B = f p q g . H e r e B 2 B o d i e s ( L ) b e c a u s e

    B o d i e s ( r ) = f f s g f p q g g :

    F i g u r e ( 2 8 ) i s a d e r i v a t i o n i n t h e S L D c a l c u l u s f o r ( 2 7 ) , i n w h i c h e v e r y b a r i s a n

    a p p l i c a t i o n o f ( F ) . T h e b a r s o n t o p o f t h e t w o b r a n c h e s o f ( 2 8 ) r e p r e s e n t a p p l i c a t i o n s

    o f ( F ) w i t h z e r o p r e m i s e s .

    I f j = G i s d e r i v a b l e i n t h e S L D c a l c u l u s f o r t h e n w e s a y t h a t G s u c c e e d s r e l a t i v e

    t o . I f = j G i s d e r i v a b l e t h e n w e s a y t h a t G f a i l s r e l a t i v e t o . F o r i n s t a n c e , f r g

    s u c c e e d s r e l a t i v e t o ( 2 5 ) a n d f a i l s r e l a t i v e t o ( 2 7 ) .

    P r o b l e m 2 . 1 2 . S h o w t h a t t h e g o a l f q g f a i l s r e l a t i v e t o t h e p r o g r a m t h a t c o n s i s t s o f

    t h e r u l e s

    q p

    n

    p

    n + 1

    p

    n

    ( 2 9 )

    ( n 0 ) .

    P r o p o s i t i o n 2 . 1 0 . F o r a n y b a s i c p r o g r a m , n o g o a l b o t h s u c c e e d s a n d f a i l s r e l a t i v e

    t o .

    P r o b l e m 2 . 1 3 . S h o w t h a t t h e g o a l f p g n e i t h e r s u c c e e d s n o r f a i l s r e l a t i v e t o t h e

    p r o g r a m

    p p : ( 3 0 )

    T h e f o l l o w i n g p r o p o s i t i o n e x p r e s s e s t h e s o u n d n e s s o f t h e S L D c a l c u l u s .

    2

    F o r a c a l c u l u s w i t h i n n i t a r y r u l e s , a d e r i v a t i o n i s d e n e d a s a ( p o s s i b l y i n n i t e ) t r e e w i t h o u t

    i n n i t e b r a n c h e s , w h o s e n o d e s a r e d e r i v a b l e o b j e c t s s u c h t h a t e v e r y n o d e e i t h e r ( a ) i s a l e a f a n d a n

    a x i o m , o r ( b ) c a n b e o b t a i n e d b y a p p l y i n g a n i n f e r e n c e r u l e t o i t s s u c c e s s o r n o d e s .

    1 4

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    15/57

    P r o p o s i t i o n 2 . 1 1 . F o r a n y b a s i c p r o g r a m a n d a n y l i t e r a l L ,

    i f f L g s u c c e e d s r e l a t i v e t o t h e n L i s a c o n s e q u e n c e o f ,

    i f i s c o n s i s t e n t a n d f L g f a i l s r e l a t i v e t o t h e n L i s n o t a c o n s e q u e n c e o f .

    T h i s p r o p o s i t i o n i s a p p l i c a b l e t o p r o g r a m s ( 2 5 ) a n d ( 2 7 ) , b e c a u s e t h e y a r e h e a d -

    c o n s i s t e n t a n d c o n s e q u e n t l y c o n s i s t e n t ( P r o p o s i t i o n 2 . 5 ) .

    N o t e t h a t t h e S L D c a l c u l u s m a y b e u n s o u n d f o r f a i l u r e i f t h e p r o g r a m i s i n c o n s i s t e n t .

    F o r i n s t a n c e , i f i s i n c o n s i s t e n t a n d L i s n o t a h e a d l i t e r a l o f t h e n L i s a c o n s e q u e n c e

    o f t h a t f a i l s : = j f L g c a n b e d e r i v e d b y o n e a p p l i c a t i o n o f t h e f a i l u r e r u l e t o t h e e m p t y

    s e t o f p r e m i s e s .

    I f t h e p r o g r a m i s c o n s i s t e n t t h e n t h e s u c c e s s r u l e o f t h e S L D c a l c u l u s i s c o m p l e t e :

    P r o p o s i t i o n 2 . 1 2 . F o r a n y c o n s i s t e n t b a s i c p r o g r a m a n d a n y c o n s e q u e n c e L o f ,

    f L g s u c c e e d s r e l a t i v e t o .

    T h e f a i l u r e r u l e i s g e n e r a l l y i n c o m p l e t e e v e n f o r c o n s i s t e n t p r o g r a m s . F o r i n s t a n c e ,

    f p g d o e s n o t f a i l w i t h r e s p e c t t o ( 3 0 ) . W e w i l l n o w d e n e a s y n t a c t i c p r o p e r t y o f b a s i c

    p r o g r a m s t h a t g u a r a n t e e s t h e c o m p l e t e n e s s o f t h e S L D c a l c u l u s f o r f a i l u r e .

    A l e v e l m a p p i n g i s a f u n c t i o n f r o m l i t e r a l s t o o r d i n a l s . A b a s i c p r o g r a m i s s a i d t o

    b e h i e r a r c h i c a l i f t h e r e e x i s t s a l e v e l m a p p i n g s u c h t h a t , f o r e v e r y r u l e H e a d B o d y

    i n ,

    ( H e a d ) > m a x

    L 2 B o d y

    ( L ) : ( 3 1 )

    F o r i n s t a n c e , p r o g r a m s ( 2 5 ) a n d ( 2 7 ) a r e h i e r a r c h i c a l : f o r e a c h o f t h e m , w e c a n t a k e

    ( s ) = 0 ( q ) = 1 ( p ) = 2 ( r ) = 3 :

    P r o g r a m ( 2 0 ) i s h i e r a r c h i c a l a l s o : t a k e ( p

    n

    ) = n . T o s h o w t h a t ( 2 9 ) i s h i e r a r c h i c a l ,

    d e n e

    ( p

    n

    ) = n ( q ) = ! :

    P r o g r a m ( 3 0 ) i s n o t h i e r a r c h i c a l b e c a u s e , f o r t h i s p r o g r a m , c o n d i t i o n ( 3 1 ) t u r n s i n t o

    ( p ) > ( p ) . T h e p r o g r a m s

    p q

    q p

    a n d

    p

    n

    p

    n + 1

    ( n 0 )

    a r e n o t h i e r a r c h i c a l e i t h e r .

    P r o b l e m 2 . 1 4 . D e t e r m i n e w h e t h e r p r o g r a m ( 1 9 ) i s h i e r a r c h i c a l .

    H e r e i s a c o m p l e t e n e s s t h e o r e m f o r t h e f a i l u r e r u l e :

    P r o p o s i t i o n 2 . 1 3 . F o r a n y h i e r a r c h i c a l b a s i c p r o g r a m a n d a n y l i t e r a l L t h a t i s n o t

    a c o n s e q u e n c e o f , f L g f a i l s w i t h r e l a t i v e t o .

    1 5

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    16/57

    2 . 6 P r o p o s i t i o n a l P r o l o g

    T h e w o r k o f P r o l o g , f o r a p r o g r a m w i t h o u t n e g a t i o n a n d v a r i a b l e s , c a n b e v i e w e d a s

    a n a t t e m p t t o e s t a b l i s h t h a t a g o a l G s u c c e e d s o r t h a t i t f a i l s ( t o \ e v a l u a t e " G ) b y

    c o n s t r u c t i n g a d e r i v a t i o n o f o n e o f t h e e x p r e s s i o n s j = G , = j G i n t h e S L D c a l c u l u s u s i n g

    \ b a c k w a r d c h a i n i n g . " T h i s k i n d o f s e a r c h w a s u s e d i n t h e e x a m p l e s a t t h e b e g i n n i n g

    o f S e c t i o n 2 . 5 .

    H e r e i s a g e n e r a l d e s c r i p t i o n o f t h e o p e r a t i o n o f P r o l o g . T h e t a s k i s t o e v a l u a t e

    a g o a l G r e l a t i v e t o a n i t e b a s i c p r o g r a m . I f G i s e m p t y t h e n j = G i s a n a x i o m .

    O t h e r w i s e , i n o r d e r t o n d a r u l e a p p l i c a t i o n t h a t l e a d s t o o n e o f t h e e x p r e s s i o n s j = G ,

    = j G , t h e g o a l G i s r e p r e s e n t e d i n t h e f o r m G

    0

    f L g L i s c a l l e d t h e \ s e l e c t e d s u b g o a l "

    o f G . P r o l o g a t t e m p t s t o e v a l u a t e , o n e b y o n e , t h e g o a l s G

    0

    B f o r a l l B 2 B o d i e s ( L ) .

    I f a t l e a s t o n e o f t h e s e g o a l s s u c c e e d s t h e n j = G c a n b e d e r i v e d b y ( S ) . I f t h e y a l l f a i l

    t h e n = j G c a n b e d e r i v e d b y ( F ) .

    A t t h e b e g i n n i n g o f t h i s p r o c e s s , t h e g i v e n p r o g r a m i s r e p r e s e n t e d a s t h e l i s t o f

    i t s r u l e s , w i t h t h e b o d y o f e v e r y r u l e r e p r e s e n t e d a s t h e l i s t o f i t s e l e m e n t s . S i m i l a r l y ,

    t h e g o a l G i s r e p r e s e n t e d a s a l i s t . T h e o r d e r i n w h i c h t h e e l e m e n t s o f a l l t h e s e l i s t s

    a r e i n i t i a l l y a r r a n g e d c a n a e c t t h e s e a r c h p r o c e s s . S p e c i c a l l y , i t d e t e r m i n e s h o w

    s u b g o a l s a r e s e l e c t e d ( P r o l o g t r i e s t h e l e f t m o s t e l e m e n t o f G r s t ) a n d i n w h a t o r d e r

    t h e e l e m e n t s o f B o d i e s ( L ) a r e c o n s i d e r e d w h e n t h e b o t t o m - u p a p p l i c a t i o n o f ( S ) o r

    ( F ) i s a t t e m p t e d . O r d e r i n g a t o m s a n d r u l e s i n a l o g i c p r o g r a m \ i n t h e r i g h t w a y " i s

    a n i m p o r t a n t p a r t o f t h e a r t o f P r o l o g p r o g r a m m i n g .

    C o n s i d e r , f o r i n s t a n c e , t h e o p e r a t i o n o f P r o l o g o n p r o g r a m ( 2 5 ) a n d t h e g o a l f r g .

    T h e i n i t i a l s t a g e o f t h e p r o c e s s c a n b e s y m b o l i c a l l y r e p r e s e n t e d b y t h e e x p r e s s i o n

    ? ? f r g :

    H e r e ? ? i s a l a b e l t h a t w i l l b e r e p l a c e d b y e i t h e r j = o r = j a t t h e e n d o f t h e c o m p u t a t i o n .

    T h i s e x p r e s s i o n i s t h e r s t i n t h e c h a i n o f \ p a r t i a l d e r i v a t i o n s " t h a t d e s c r i b e s t h e

    o p e r a t i o n o f P r o l o g o n t h e g i v e n g o a l . T h e r s t e l e m e n t o f B o d i e s ( r ) i s f s g , s o t h a t

    t h e n e x t p a r t i a l d e r i v a t i o n i s

    ? ? f s g

    ? ? f r g

    T h e n w e o b s e r v e t h a t B o d i e s ( s ) i s e m p t y , s o t h a t = j f s g c a n b e d e r i v e d b y o n e

    a p p l i c a t i o n o f ( F ) t o t h e e m p t y s e t o f p r e m i s e s . T h i s l e a d s u s t o t h e p a r t i a l d e r i v a t i o n

    i n w h i c h t h e l a b e l ? ? i n f r o n t o f f s g i s r e p l a c e d b y t h e f a i l u r e s y m b o l :

    ( F )

    = j f s g

    ? ? f r g

    ( 3 2 )

    I t r e m a i n s t o e v a l u a t e t h e s e c o n d e l e m e n t o f B o d i e s ( r ) , t h a t i s , f p q g . F i r s t w e

    1 6

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    17/57

    f o r m t h e p a r t i a l d e r i v a t i o n

    ( F )

    = j f s g ? ? f p q g

    ? ? f r g

    A s s o o n a s w e k n o w w h e t h e r ? ? i n f r o n t o f f p q g t u r n s i n t o j = o r = j , t h e e v a l u a t i o n o f

    f r g w i l l b e c o m p l e t e d . S p e c i c a l l y , i f a d e r i v a t i o n o f = j f p q g i s f o u n d t h e n i t w i l l b e

    a p p e n d e d t o ( 3 2 ) t o f o r m a d e r i v a t i o n o f = j f r g :

    : : :

    ( F ) ( F )

    = j f s g = j f p q g

    ( F )

    = j f r g

    I f , o n t h e o t h e r h a n d , a d e r i v a t i o n o f j = f p q g i s f o u n d t h e n w e w i l l d i s c a r d t h e

    d e r i v a t i o n o f = j f s g i n ( 3 2 ) a n d o b t a i n a d e r i v a t i o n o f j = f r g :

    : : :

    ( S )

    j = f p q g

    ( S )

    j = f r g

    I n t h e p r o c e s s o f e v a l u a t i o n o f f p q g , P r o l o g d e s i g n a t e s p a s t h e s e l e c t e d s u b g o a l ,

    b e c a u s e i t i s t h e l e f t m o s t e l e m e n t o f t h e l i s t p q . T h e n e x t p a r t i a l d e r i v a t i o n i s

    ? ? f q q g

    ( F )

    = j f s g ? ? f p q g

    ? ? f r g

    ( 3 3 )

    I n o r d e r t o r e m a i n f a i t h f u l t o t h e a c t u a l o p e r a t i o n o f P r o l o g , i t i s i m p o r t a n t a t t h i s

    s t a g e n o t t o r e m o v e r e p e t i t i o n s i n t h e e x p r e s s i o n f q q g . T h i s e x p r e s s i o n s t a n d s f o r a

    s i n g l e t o n s e t t h a t i s r e p r e s e n t e d a s a l i s t o f l e n g t h 2 .

    O n t h e n e x t s t e p , t h e r s t m e m b e r o f t h e l i s t q q i s s e l e c t e d , s o t h a t L = q a n d

    G

    0

    = G = f q g . T h e n e x t p a r t i a l d e r i v a t i o n i s

    ? ? f q g

    ? ? f q q g

    ( F )

    = j f s g ? ? f p q g

    ? ? f r g

    1 7

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    18/57

    A f t e r t h a t , w e f o r m t h e p a r t i a l d e r i v a t i o n

    ? ?

    ? ? f q g

    ? ? f q q g

    ( F )

    = j f s g ? ? f p q g

    ? ? f r g

    ( 3 4 )

    H e r e w e r e c o g n i z e t h a t j = i s a n a x i o m . A l l o c c u r r e n c e s o f t h e l a b e l ? ? i n t h e r i g h t

    b r a n c h o f ( 3 4 ) a r e r e p l a c e d b y j = , a n d t h e l e f t b r a n c h i s d i s c a r d e d . T h e n a l p r o d u c t

    o f t h i s s e a r c h p r o c e s s i s t h e d e r i v a t i o n

    j =

    ( S )

    j = f q g

    ( S )

    j = f q g

    ( S )

    j = f p q g

    ( S )

    j = f r g

    ( 3 5 )

    N o t e t h a t t h i s d e r i v a t i o n i n c l u d e s a r e d u n d a n t s t e p t h a t i s a b s e n t f r o m ( 2 6 ) . T h e

    d i e r e n c e i s d u e t o t h e f a c t t h a t P r o l o g d o e s n o t c h e c k t h e l i s t r e p r e s e n t a t i o n s o f g o a l s

    f o r r e p e t i t i o n s .

    I f w e s t a r t w i t h p r o g r a m ( 2 7 ) i n s t e a d o f ( 2 5 ) t h e n t h e r s t s e v e r a l p a r t i a l d e r i v a t i o n s

    c o n s t r u c t e d i n t h e p r o c e s s o f e v a l u a t i n g f r g a r e g o i n g t o b e t h e s a m e , u p t o ( 3 3 ) . A f t e r

    t h a t , t h e p a r t i a l d e r i v a t i o n

    ? ? f s q g

    ? ? f q q g

    ( F )

    = j f s g ? ? f p q g

    ? ? f r g

    w i l l b e f o r m e d . T h e n s w i l l b e s e l e c t e d , a n d = j f s q g w i l l b e d e r i v e d f r o m t h e e m p t y

    s e t o f p r e m i s e s . H a v i n g r e p l a c e d e a c h ? ? b y = j i n t h e r i g h t b r a n c h o f t h i s p a r t i a l

    1 8

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    19/57

    d e r i v a t i o n , w e w i l l g e t t h e d e r i v a t i o n

    ( F )

    = j f s q g

    ( F )

    = j f q g

    ( F ) ( F )

    = j f s g = j f p q g

    ( F )

    = j f r g

    T h e g o a l f r g h a s f a i l e d .

    P r o b l e m 2 . 1 5 . D e s c r i b e t h e w o r k o f P r o l o g o n t h e p r o g r a m

    p q r

    p r s

    r u v

    s

    u

    a n d t h e g o a l f p g . H o w w o u l d t h e p r o c e s s b e a e c t e d b y a p p e n d i n g v t o t h e p r o g r a m

    a s a n a d d i t i o n a l r u l e ?

    P r o b l e m 2 . 1 6 . D e s c r i b e t h e w o r k o f P r o l o g o n t h e p r o g r a m

    p p

    p

    a n d t h e g o a l f p g .

    T h e l a s t e x a m p l e d e m o n s t r a t e s t h e i n c o m p l e t e n e s s o f t h e P r o l o g s e a r c h s t r a t e g y :

    P r o l o g n e v e r n d s t h e o n e - s t e p d e r i v a t i o n o f j = f p g i n t h e S L D c a l c u l u s f o r t h i s

    p r o g r a m . T h i s i s s i m i l a r t o t h e c a s e o f n o n t e r m i n a t i o n o f P r o l o g m e n t i o n e d a t t h e

    e n d o f S e c t i o n 1 . 3 .

    2 . 7 N o r m a l P r o g r a m s

    A b a s i c r u l e o r p r o g r a m t h a t d o e s n o t c o n t a i n t h e n e g a t i o n s y m b o l : i s s a i d t o b e

    n o r m a l . M a n y p r o g r a m s t h a t w e h a v e u s e d a s e x a m p l e s a r e n o r m a l . N o r m a l b a s i c

    p r o g r a m s a r e h e a d - c o n s i s t e n t . C o n s e q u e n t l y , a n y n o r m a l b a s i c p r o g r a m i s c o n s i s t e n t

    ( P r o p o s i t i o n 2 . 5 ) , a n d a n y c o n s e q u e n c e o f s u c h a p r o g r a m i s a n a t o m ( C o r o l l a r y t o

    P r o p o s i t i o n 2 . 4 ) .

    A r b i t r a r y b a s i c p r o g r a m s c a n b e r e d u c e d t o n o r m a l b a s i c p r o g r a m s i n t h e f o l l o w i n g

    w a y . F o r e v e r y a t o m A 2 A , s e l e c t a n e w s y m b o l A

    0

    , a n d l e t A

    0

    b e t h e s e t o f t h e s e

    n e w s y m b o l s . F o r a n y L 2 L i t

    A

    , l e t N o r m ( L ) b e t h e s y m b o l f r o m A A

    0

    d e n e d a s

    f o l l o w s :

    N o r m ( A ) = A N o r m ( : A ) = A

    0

    ( A 2 A ) :

    1 9

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    20/57

    T h e m a p N o r m i s e x t e n d e d t o s e t s o f l i t e r a l s , b a s i c r u l e s a n d b a s i c p r o g r a m s i n a

    n a t u r a l w a y :

    N o r m ( X ) = f N o r m ( L ) : L 2 X g

    N o r m ( H e a d B o d y ) = N o r m ( H e a d ) N o r m ( B o d y )

    N o r m ( ) = f N o r m ( R ) : R 2 g :

    T h u s , t o t r a n s f o r m i n t o N o r m ( ) , w e s i m p l y r e p l a c e e v e r y n e g a t i v e l i t e r a l : A i n

    b y A

    0

    . I t i s c l e a r t h a t N o r m i s a o n e - t o - o n e m a p o f t h e s e t o f b a s i c p r o g r a m s o n t o t h e

    s e t o f n o r m a l b a s i c p r o g r a m s o v e r t h e e x t e n d e d s e t o f a t o m s A A

    0

    .

    I f , f o r e x a m p l e , i s ( 1 9 ) , t h e n N o r m ( ) i s

    p

    q

    0

    r p q

    r

    0

    p q

    0

    s r

    s p s

    s

    0

    p q

    0

    r

    0

    :

    ( 3 6 )

    B y C o n t r w e d e n o t e t h e s e t o f c o n t r a d i c t i o n r u l e s

    A B B

    0

    A

    0

    B B

    0

    f o r a l l p a i r s o f d i s t i n c t a t o m s A B 2 A .

    P r o p o s i t i o n 2 . 1 4 . F o r a n y b a s i c p r o g r a m ,

    N o r m ( C n ( ) ) = C n ( N o r m ( ) C o n t r ) :

    M o r e o v e r , i f i s c o n s i s t e n t t h e n

    N o r m ( C n ( ) ) = C n ( N o r m ( ) ) :

    P r o b l e m 2 . 1 7 . S h o w t h a t t h e s e c o n d a s s e r t i o n w o u l d n o t b e c o r r e c t w i t h o u t t h e

    c o n s i s t e n c y a s s u m p t i o n .

    P r o p o s i t i o n 2 . 1 4 s h o w s t h a t N o r m i s a o n e - t o - o n e c o r r e s p o n d e n c e b e t w e e n t h e

    c o n s e q u e n c e s o f a n d t h e c o n s e q u e n c e s o f t h e n o r m a l b a s i c p r o g r a m N o r m ( ) C o n t r

    i f i s c o n s i s t e n t t h e n t h e c o n t r a d i c t i o n r u l e s c a n b e d r o p p e d .

    A n o r m a l b a s i c p r o g r a m c a n b e e n c o d e d b y a p r o p o s i t i o n a l f o r m u l a . T h e f u n c t i o n

    ' f r o m n o r m a l b a s i c r u l e s t o p r o p o s i t i o n a l f o r m u l a s i s d e n e d b y

    ' ( H e a d B o d y ) =

    A 2 B o d y

    A H e a d :

    2 0

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    21/57

    F o r a n y n o r m a l b a s i c p r o g r a m , ' s t a n d s f o r t h e s e t o f f o r m u l a s ' R f o r a l l r u l e s

    R 2 . F o r e x a m p l e , i f i s ( 3 6 ) t h e n ' c o n s i s t s o f t h e f o r m u l a s

    p

    q

    0

    p q r

    p q

    0

    r

    0

    r s

    p s s

    p q

    0

    r

    0

    s

    0

    :

    T h e f o l l o w i n g p r o p o s i t i o n d e s c r i b e s t h e r e l a t i o n s h i p b e t w e e n t h e s e t ' a n d t h e

    c o n c e p t o f c l o s u r e u n d e r d e n e d i n S e c t i o n 2 . 2 . R e c a l l t h a t , i n p r o p o s i t i o n a l l o g i c ,

    a n i n t e r p r e t a t i o n i s a f u n c t i o n f r o m a t o m s t o t r u t h v a l u e s , a n d a m o d e l o f a s e t o f

    f o r m u l a s i s a n i n t e r p r e t a t i o n t h a t s a t i s e s a l l f o r m u l a s i n t h e s e t . W e w i l l i d e n t i f y a n

    i n t e r p r e t a t i o n w i t h t h e s e t o f a t o m s t o w h i c h i t a s s i g n s t h e v a l u e t r u e .

    P r o p o s i t i o n 2 . 1 5 . F o r a n y n o r m a l b a s i c p r o g r a m , a n i n t e r p r e t a t i o n I i s a m o d e l

    o f ' i I i s c l o s e d u n d e r .

    C o r o l l a r y 1 . F o r a n y n o r m a l b a s i c p r o g r a m , C n ( ) i s t h e l e a s t m o d e l o f ' .

    C o r o l l a r y 2 . F o r a n y n o r m a l b a s i c p r o g r a m , C n ( ) i s t h e s e t o f a t o m s e n t a i l e d

    b y ' .

    A c l a u s e i s a d i s j u n c t i o n o f l i t e r a l s . A c l a u s e i s d e n i t e i f e x a c t l y o n e o f i t s l i t e r a l s

    i s p o s i t i v e . I t i s c l e a r t h a t , f o r a n y n o r m a l b a s i c r u l e R , t h e f o r m u l a ' R i s e q u i v a l e n t

    t o a d e n i t e c l a u s e , a n d , c o n v e r s e l y , e v e r y ( p r o p o s i t i o n a l ) d e n i t e c l a u s e i s e q u i v a l e n t

    t o a f o r m u l a o f t h i s f o r m . C o r o l l a r i e s 1 a n d 2 s h o w t h a t r e c o g n i z i n g t h e c o n s e q u e n c e s

    o f a n o r m a l b a s i c p r o g r a m a m o u n t s t o r e c o g n i z i n g t h e a t o m s t h a t b e l o n g t o t h e l e a s t

    m o d e l o f a s e t o f d e n i t e c l a u s e s , o r , e q u i v a l e n t l y , t h e a t o m s t h a t a r e e n t a i l e d b y s u c h

    a s e t .

    3 N e g a t i o n a s F a i l u r e

    N o w w e t u r n t o t h e s t u d y o f l o g i c p r o g r a m s w i t h n e g a t i o n a s f a i l u r e . T h e e x a m p l e s

    d i s c u s s e d i n S e c t i o n 1 . 2 a r e ( s c h e m a t i c r e p r e s e n t a t i o n s o f ) p r o g r a m s o f t h i s k i n d .

    3 . 1 A n s w e r S e t s

    A r u l e e l e m e n t i s a l i t e r a l p o s s i b l y p r e c e d e d b y t h e n e g a t i o n a s f a i l u r e s y m b o l n o t . A

    r u l e i s a n o r d e r e d p a i r H e a d B o d y , w h o s e r s t m e m b e r H e a d i s a l i t e r a l , a n d w h o s e

    s e c o n d m e m b e r B o d y i s a n i t e s e t o f r u l e e l e m e n t s . F o r a n y s e t X o f l i t e r a l s , w e w i l l

    d e n o t e t h e s e t f n o t L : L 2 X g b y n o t ( X ) . T h e n a n y r u l e c a n b e r e p r e s e n t e d a s

    2 1

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    22/57

    H e a d P o s n o t ( N e g ) , f o r s o m e n i t e s e t s o f l i t e r a l s P o s , N e g . T h e r u l e w i t h t h e

    h e a d L

    0

    a n d t h e b o d y f L

    1

    : : : L

    m

    n o t L

    m + 1

    : : : n o t L

    n

    g w i l l b e a l s o w r i t t e n a s

    L

    0

    L

    1

    : : : L

    m

    n o t L

    m + 1

    : : : n o t L

    n

    : ( 3 7 )

    A p r o g r a m i s a s e t o f r u l e s . F o r i n s t a n c e ,

    p

    q p n o t r

    q r n o t p

    r p n o t s

    ( 3 8 )

    i s a p r o g r a m . T h i s p r o g r a m d o e s n o t c o n t a i n t h e c l a s s i c a l n e g a t i o n s y m b o l : t h e

    s y n t a x o f r u l e s a l l o w s u s t o i n s e r t t h i s s y m b o l i n f r o n t o f a n y o f t h e a t o m s p q r s

    a n y w h e r e i n t h e p r o g r a m .

    W e w o u l d l i k e t o g e n e r a l i z e t h e d e n i t i o n o f C n ( ) f r o m S e c t i o n 2 . 2 t o a r b i t r a r y

    p r o g r a m s .

    I n t u i t i v e l y , t h e p r e s e n c e o f a r u l e e l e m e n t n o t L i n t h e b o d y o f a r u l e l i m i t s t h e

    a p p l i c a b i l i t y o f t h e r u l e t o t h e c a s e w h e n t h e p r o g r a m a s a w h o l e p r o v i d e s n o p o s s i b i l i t i e s

    f o r d e r i v i n g L . F o r i n s t a n c e , r u l e s ( 3 8 ) d i e r f r o m t h e b a s i c r u l e s

    p

    q p

    q r

    r p

    ( 3 9 )

    i n t h a t

    t h e s e c o n d r u l e o f ( 3 8 ) a l l o w s u s t o d e r i v e q f r o m p o n l y i f r c a n n o t b e d e r i v e d ,

    t h e t h i r d r u l e o f ( 3 8 ) a l l o w s u s t o d e r i v e q f r o m r o n l y i f p c a n n o t b e d e r i v e d ,

    t h e l a s t r u l e o f ( 3 8 ) a l l o w s u s t o d e r i v e r f r o m p o n l y i f s c a n n o t b e d e r i v e d .

    T h i s i n f o r m a l d e s c r i p t i o n o f h o w t h e s y m b o l n o t \ b l o c k s " t h e a p p l i c a t i o n o f p r o g r a m

    r u l e s i s c i r c u l a r , b e c a u s e i t c h a r a c t e r i z e s t h e p r o c e s s o f a p p l y i n g r u l e s i n t e r m s o f w h a t

    c a n b e d e r i v e d u s i n g t h e s e r u l e s . N e v e r t h e l e s s , f o r a n y s e t X o f l i t e r a l s , t h a t d e s c r i p t i o n

    m a k e s i t p o s s i b l e t o \ t e s t " t h e c l a i m t h a t r u l e s ( 3 8 ) a l l o w u s t o d e r i v e t h e e l e m e n t s o f

    X a n d n o t h i n g e l s e .

    T a k e , f o r i n s t a n c e , X t o b e f p r g . I f p a n d r a r e i n d e e d d e r i v a b l e , a n d t h e o t h e r

    l i t e r a l s a r e n o t , t h e n t h e s e c o n d r u l e o f ( 3 8 ) i s \ b l o c k e d " i n v i e w o f t h e p r e s e n c e o f

    n o t r i n i t s b o d y , a n d t h e t h i r d r u l e i s \ b l o c k e d " b y t h e p r e s e n c e o f n o t p t h e o t h e r

    t w o r u l e s a r e n o t \ b l o c k e d . " T h e n t h e e e c t o f r u l e s ( 3 8 ) i s t h e s a m e a s t h e e e c t o f

    p

    r p

    ( 4 0 )

    2 2

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    23/57

    | t h e s u b s e t o f ( 3 9 ) o b t a i n e d b y d e l e t i n g i t s s e c o n d a n d t h i r d r u l e s . T h i s i s a b a s i c

    p r o g r a m . T h e s e t o f i t s c o n s e q u e n c e s i s f p r g , w h i c h i s e x a c t l y t h e s e t X t h a t w e

    i n i t i a l l y a s s u m e d t o b e t h e s e t o f d e r i v a b l e l i t e r a l s . T h i s f a c t c o n r m s t h a t f p r g w a s

    a \ g o o d g u e s s . "

    G e n e r a l l y , t h e r e c a n b e s e v e r a l \ g o o d g u e s s e s " a b o u t t h e r e s u l t o f a p p l i c a t i o n o f a

    g i v e n s e t o f r u l e s . C o n s i d e r , f o r i n s t a n c e , t h e p r o g r a m

    p n o t q

    q n o t p

    r p

    r q :

    ( 4 1 )

    T h e r e a r e t w o r e a s o n a b l e c o n j e c t u r e s a b o u t w h a t c a n b e d e r i v e d u s i n g t h e s e r u l e s . O n e

    i s t h a t w e c a n d e r i v e p a n d r , b u t n o t q . I f s o , t h e n ( 4 1 ) h a s t h e s a m e m e a n i n g a s t h e

    b a s i c p r o g r a m

    p

    r p

    r q :

    ( 4 2 )

    T h e s e t o f c o n s e q u e n c e s o f t h i s p r o g r a m i s , i n d e e d , f p r g . T h e o t h e r p o s s i b i l i t y i s t h a t

    q a n d r c a n b e d e r i v e d , b u t n o t p . I n t h i s c a s e , ( 4 1 ) h a s t h e s a m e m e a n i n g a s t h e b a s i c

    p r o g r a m

    q

    r p

    r q

    ( 4 3 )

    w h o s e c o n s e q u e n c e s a r e , i n d e e d , q a n d r .

    T h i s e x a m p l e l e a d s u s t o t h e v i e w t h a t n e g a t i o n a s f a i l u r e c a n m a k e t h e r u l e s o f

    a p r o g r a m \ n o n d e t e r m i n i s t i c . " T h e r e c a n b e s e v e r a l \ c o r r e c t " w a y s t o o r g a n i z e t h e

    p r o c e s s o f d e r i v i n g l i t e r a l s u s i n g t h e r u l e s o f a p r o g r a m t h a t c o n t a i n s n e g a t i o n a s f a i l u r e .

    E a c h o f t h e m p r o d u c e s a d i e r e n t s e t o f l i t e r a l s t h e s e s e t s w i l l b e c a l l e d t h e \ a n s w e r

    s e t s " f o r t h e p r o g r a m . A c o n s e q u e n c e o f a p r o g r a m i s a l i t e r a l t h a t i s g u a r a n t e e d t o b e

    p r o d u c e d n o m a t t e r w h i c h d e r i v a t i o n p r o c e s s i s s e l e c t e d | a l i t e r a l t h a t b e l o n g s t o a l l

    a n s w e r s e t s . F o r i n s t a n c e , t h e o n l y a n s w e r s e t f o r ( 3 8 ) i s f p r g , s o t h a t t h e c o n s e q u e n c e s

    o f t h i s p r o g r a m a r e p a n d r t h e a n s w e r s e t s f o r ( 4 1 ) a r e f p r g a n d f q r g , s o t h a t i t s

    o n l y c o n s e q u e n c e i s r .

    I n o r d e r t o g i v e t h e d e n i t i o n o f a n a n s w e r s e t , w e n e e d a g e n e r a l d e s c r i p t i o n o f t h e

    p r o c e s s o f r e d u c i n g a n a r b i t r a r y p r o g r a m t o a b a s i c p r o g r a m t h a t w a s u s e d a b o v e t o

    o b t a i n ( 4 0 ) f r o m ( 3 8 ) , a n d ( 4 2 ) , ( 4 3 ) f r o m ( 4 1 ) .

    L e t b e a p r o g r a m , a n d X a s e t o f l i t e r a l s . T h e r e d u c t o f r e l a t i v e t o X i s t h e

    b a s i c p r o g r a m o b t a i n e d f r o m b y

    d e l e t i n g e a c h r u l e H e a d P o s n o t ( N e g ) s u c h t h a t N e g \ X 6= , a n d

    r e p l a c i n g e a c h r e m a i n i n g r u l e H e a d P o s n o t ( N e g ) b y H e a d P o s .

    2 3

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    24/57

    T h i s p r o g r a m w i l l b e d e n o t e d b y

    X

    . W e s a y t h a t X i s a n a n s w e r s e t f o r i f

    C n (

    X

    ) = X .

    I t i s c l e a r t h a t e v e r y a n s w e r s e t i s l o g i c a l l y c l o s e d . W e h a v e s e e n t h a t a p r o g r a m

    c a n h a v e o n e o r s e v e r a l a n s w e r s e t s . S o m e p r o g r a m s h a v e n o a n s w e r s e t s , f o r i n s t a n c e

    p n o t p : ( 4 4 )

    A c o n s e q u e n c e o f a p r o g r a m i s a l i t e r a l t h a t b e l o n g s t o a l l i t s a n s w e r s e t s .

    A l t e r n a t i v e l y , t h e c o n s e q u e n c e s o f a p r o g r a m c a n b e c h a r a c t e r i z e d a s t h e l i t e r a l s t h a t

    b e l o n g t o a l l i t s c o n s i s t e n t a n s w e r s e t s . I t i s c l e a r t h a t t h e s e t o f c o n s e q u e n c e s i s

    l o g i c a l l y c l o s e d .

    I f a p r o g r a m i s b a s i c t h e n i t s r e d u c t r e l a t i v e t o a n y s e t o f l i t e r a l s i s . I t f o l l o w s

    t h a t t h e o n l y a n s w e r s e t f o r a b a s i c p r o g r a m i s C n ( ) , s o t h a t t h e n e w d e n i t i o n o f a

    c o n s e q u e n c e , a p p l i e d t o a b a s i c p r o g r a m , i s e q u i v a l e n t t o t h e o n e g i v e n i n S e c t i o n 2 . 2 .

    F o r t h e s e t o f c o n s e q u e n c e s o f a p r o g r a m , w e w i l l u s e t h e s a m e n o t a t i o n C n ( )

    a s i n t h e b a s i c c a s e .

    O n p r o g r a m s w i t h n e g a t i o n a s f a i l u r e , t h e c o n s e q u e n c e o p e r a t o r i s n o t m o n o t o n e .

    F o r i n s t a n c e , t h e s e t o f c o n s e q u e n c e s o f f p n o t q g i s f p g i f w e a d d q t o t h i s p r o g r a m

    a s a n o t h e r r u l e , t h e s e t o f c o n s e q u e n c e s w i l l b e f q g . I n t h i s s e n s e , l o g i c p r o g r a m m i n g

    w i t h n e g a t i o n a s f a i l u r e i s a \ n o n m o n o t o n i c f o r m a l i s m . "

    P r o b l e m 3 . 1 . F i n d a l l a n s w e r s e t s f o r t h e p r o g r a m

    p n o t q

    q n o t p

    r n o t r

    r p :

    ( 4 5 )

    P r o b l e m 3 . 2 . F i n d a l l a n s w e r s e t s f o r t h e p r o g r a m

    p

    n + 1

    n o t p

    n

    ( n 0 ) : ( 4 6 )

    P r o b l e m 3 . 3 . F i n d a l l a n s w e r s e t s f o r t h e p r o g r a m

    p

    n

    n o t p

    n + 1

    ( n 0 ) : ( 4 7 )

    P r o p o s i t i o n 3 . 1 . I f X a n d Y a r e a n s w e r s e t s f o r a p r o g r a m a n d X Y t h e n

    X = Y .

    C o r o l l a r y . E v e r y p r o g r a m s a t i s e s e x a c t l y o n e o f t h e f o l l o w i n g c o n d i t i o n s :

    h a s n o a n s w e r s e t s ,

    t h e o n l y a n s w e r s e t f o r i s L i t ,

    h a s a n a n s w e r s e t , a n d a l l i t s a n s w e r s e t s a r e c o n s i s t e n t .

    2 4

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    25/57

    T h e c o n s i s t e n c y o f a p r o g r a m i s d e n e d a s i t w a s d e n e d f o r b a s i c p r o g r a m s i n

    S e c t i o n 2 . 2 : A p r o g r a m i s c o n s i s t e n t i f t h e s e t o f i t s c o n s e q u e n c e s i s c o n s i s t e n t , a n d

    i n c o n s i s t e n t o t h e r w i s e . I n t h e r s t t w o c a s e s l i s t e d i n t h e s t a t e m e n t o f t h e c o r o l l a r y ,

    i s i n c o n s i s t e n t a n d C n ( ) = L i t . I n t h e t h i r d c a s e , i s c o n s i s t e n t .

    T h e d e n i t i o n o f c l o s u r e u n d e r a p r o g r a m g i v e n i n S e c t i o n 2 . 2 i s e x t e n d e d t o

    a r b i t r a r y p r o g r a m s a s f o l l o w s . A s e t X o f l i t e r a l s i s c l o s e d u n d e r a p r o g r a m i f ,

    f o r e v e r y r u l e H e a d P o s n o t ( N e g ) i n , H e a d 2 X w h e n e v e r P o s X a n d

    N e g \ X = .

    P r o p o s i t i o n 3 . 2 . E v e r y a n s w e r s e t f o r a p r o g r a m i s c l o s e d u n d e r .

    T h e s e t o f c o n s e q u e n c e s o f , h o w e v e r , i s n o t n e c e s s a r i l y c l o s e d u n d e r . T h i s c a n

    b e i l l u s t r a t e d b y p r o g r a m ( 4 1 ) .

    W e s a y t h a t a s e t X o f l i t e r a l s i s s u p p o r t e d b y i f , f o r e a c h l i t e r a l L 2 X , t h e r e

    e x i s t s a r u l e H e a d P o s n o t ( N e g ) i n s u c h t h a t

    H e a d = L P o s X N e g \ X = :

    P r o p o s i t i o n 2 . 4 c a n b e g e n e r a l i z e d t o a r b i t r a r y p r o g r a m s i n t h e f o l l o w i n g w a y :

    P r o p o s i t i o n 3 . 3 . A n y c o n s i s t e n t a n s w e r s e t f o r a p r o g r a m i s s u p p o r t e d b y .

    A s i n t h e c a s e o f b a s i c p r o g r a m s , a h e a d l i t e r a l o f a p r o g r a m i s t h e h e a d o f a r u l e

    o f .

    C o r o l l a r y 1 . A n y e l e m e n t o f a n y c o n s i s t e n t a n s w e r s e t f o r a p r o g r a m i s a h e a d

    l i t e r a l o f .

    C o r o l l a r y 2 . I f a p r o g r a m i s c o n s i s t e n t t h e n e v e r y c o n s e q u e n c e o f i s a h e a d l i t e r a l

    o f .

    A s i n t h e c a s e o f b a s i c p r o g r a m s , a p r o g r a m i s h e a d - c o n s i s t e n t i f t h e s e t o f i t s

    h e a d l i t e r a l s i s c o n s i s t e n t . P r o p o s i t i o n 2 . 5 c a n b e g e n e r a l i z e d t o a r b i t r a r y p r o g r a m s a s

    f o l l o w s :

    P r o p o s i t i o n 3 . 4 . I f a p r o g r a m i s h e a d - c o n s i s t e n t t h e n e v e r y a n s w e r s e t f o r i s

    c o n s i s t e n t .

    T h i s p r o p o s i t i o n t e l l s u s t h a t a h e a d - c o n s i s t e n t p r o g r a m c a n n o t b e l o n g t o t h e s e c o n d

    o f t h e t h r e e g r o u p s l i s t e d i n t h e c o r o l l a r y t o P r o p o s i t i o n 3 . 1 . I t i s p o s s i b l e , h o w e v e r ,

    t h a t a h e a d - c o n s i s t e n t p r o g r a m b e l o n g s t o t h e r s t g r o u p , s o t h a t s u c h a p r o g r a m c a n

    b e i n c o n s i s t e n t . F o r i n s t a n c e , ( 4 4 ) i s a h e a d - c o n s i s t e n t p r o g r a m w i t h o u t a n s w e r s e t s .

    A n a d d i t i o n a l c o n d i t i o n n e e d e d t o g u a r a n t e e t h e e x i s t e n c e o f a n a n s w e r s e t , c a l l e d

    \ o r d e r - c o n s i s t e n c y , " i s d i s c u s s e d i n S e c t i o n 3 . 5 .

    3 . 2 T i g h t P r o g r a m s

    A c c o r d i n g t o P r o p o s i t i o n s 3 . 2 a n d 3 . 3 , e v e r y c o n s i s t e n t a n s w e r s e t i s c l o s e d a n d

    s u p p o r t e d . P r o p o s i t i o n 3 . 5 b e l o w s h o w s t h a t f o r a l a r g e c l a s s o f p r o g r a m s t h e c o n v e r s e i s

    2 5

  • 7/30/2019 [Lifschitz] Foundations of Logic Programming, In Principles of Knowledge Representation, CSLI Publications

    26/57

    a l s o t r u e , s o t h a t t h e t w o p r o p e r t i e s , c l o s u r e a n d s u p p o r t e d n e s s , c o m p l e t e l y c h a r a c t e r i z e

    t h e c l a s s o f c o n s i s t e n t a n s w e r s e t s f o r p r o g r a m s i n t h i s c l a s s .

    A p r o g r a m i s t i g h t i f t h e r e e x i s t s a l e v e l m a p p i n g s u c h t h a t , f o r e v e r y r u l e

    H e a d P o s n o t ( N e g ) i n ,

    ( H e a d ) > m a x

    L 2 P o s

    ( L ) :

    N o t e t h a t t h i s c o n d i t i o n d o e s n o t i m p o s e a n y r e s t r i c t i o n o n N e g , t h a t i s , o n t h e r u l e

    e l e m e n t s t h a t i n c l u d e n e g a t i o n a s f a i l u r e . I f P o s = i n e v e r y r u l e o f t h e p r o g r a m t h e n

    t h e p r o g r a m i s t r i v i a l l y t i g h t . A b a s i c p r o g r a m i s t i g h t i i t i s h i e r a r c h i c a l .

    P r o b l e m 3 . 4 . D e t e r m i n e w h i c h o f t h e p r o g r a m s ( 3 8 ) , ( 4 1 ) , ( 4 4 ) { ( 4 7 ) a r e t i g h t .

    P r o p o s i t i o n 3 . 5 . F o r a n y t i g h t p r o g r a m a n d c o n s i s t e n t s e t X o f l i t e r a l s , X i s a n

    a n s w e r s e t f o r i X i s b o t h c l o s e d u n d e r a n d s u p p o r t e d b y .

    P r o b l e m 3 . 5 . S h o w t h a t t h i s a s s e r t i o n w o u l d b e i n c o r r e c t w i t h o u t t h e a s s u m p t i o n

    t h a t i s t i g h t .

    A n y p r o g r a m c a n b e \ t i g h t e n e d " a t t h e p r i c e o f i n t r o d u c i n g i n n i t e l y m a n y n e w

    a t o m s . F o r e v e r y A i n t h e s e t A o f a t o m s a n d f o r e v e r y i n t e g e r n 6= 0 , l e t A

    n

    b e a n e w

    s y m b o l . F o r e v e r y n > 0 , d e n e

    ( : A )

    n

    = A

    ; n

    f o r a n y a t o m A , a n d

    X

    n

    = f L

    n

    : L 2 X g

    f o r a n y s e t X o f l i t e r a l s . I n t u i t i v e l y , A

    n

    s a y s t h a t A c a n b e \ e s t a b l i s h e d i n n s t e p s "

    u s i n g t h e r u l e s o f t h e p r o g r a m A

    ; n

    s a y s t h a t A c a n b e \ r e f u t e d i n n s t e p s . "

    L e t A

    1

    b