Alan Bundy, University of Edinburgh. ⢠Robert Constable, Cornell ... Nachum Dershowitz, Mitsuhiro Okada, and G. Sivakumar. 538. Program Synthesis by ...
Lecture Notes in Computer Science Edited by G. Goos and J. Hartmanis
310 E. Lusk R. Overbeek (Eds.)
9th International Conference on Automated Deduction Argonne, Illinois, USA, May 2 3 - 2 6 , 1988 Proceedings
Springer-Verlag Berlin Heidelberg New York London Paris Tokyo
I
9^.
Editorial Board D. B a r s t o w C. Moler
Ρ?6
W. Brauer
(
3 ' h a s b e e n d e c l a r e d . C l a u s e s t h a t a r e not r e p r e s e n t e d a s P r o l o g r u l e s m a y t h e n b e r e p r e s e n t e d in i m p l i c a t i o n a l f o r m as ( A
v
... , A
m
— > C ^ ... ; C ) w h e r e - A n
1
to ~ A
m
are the negative, C
1
p o s i t i v e literals in t h e c l a u s e . C o m p l e t e l y p o s i t i v e c l a u s e s are w r i t t e n a s (true — > C ^ while completely negative clauses are implicationally represented by ( A
the
n
... ; C ) , n
— > false).
Thus
n e g a t i o n n e v e r o c c u r s e x p l i c i t l y . W e call t h e l e f t - h a n d s i d e of a n i m p l i c a t i o n its antecedent
and
t h e r i g h t - h a n d s i d e its
2. 2.1
v
... , A
to C
m
consequent.
Model Generation in Prolog A basic procedure
It is w e l l - k n o w n t h a t e v e r y m o d e l of a set of c l a u s e s c a n b e r e p r e s e n t e d b y a s e t Μ of p o s i t i v e g r o u n d a t o m s . T h e e l e m e n t s of Μ a r e t h o s e g r o u n d literals t h a t a r e s a t i s f i e d in t h e m o d e l , t h e r e m a i n i n g o n e s a r e - b y d e f a u l t - a s s u m e d v i o l a t e d . A g r o u n d c o n j u n c t i o n / d i s j u n c t i o n is s a t i s f i e d in M , if Μ c o n t a i n s a l l / s o m e of its c o m p o n e n t s . A c l a u s e (A — > C) is s a t i s f i e d in Μ , if Co
is
s a t i s f i e d f o r e v e r y s u b s t i t u t i o n σ s u c h t h a t Α σ is s a t i s f i e d . C o n v e r s e l y , (A — > C) is v i o l a t e d in Μ if t h e r e is a s u b s t i t u t i o n σ s u c h t h a t Α σ is s a t i s f i e d in M , b u t C o is not. ' T r u e ' is s a t i s f i e d , ' f a l s e ' is v i o l a t e d in e v e r y m o d e l . It s e e m s to b e a v e r y n a t u r a l c h o i c e to i m p l e m e n t m o d e l c o n s t r u c t i o n b y a s s e r t i n g f a c t s into P r o l o g ' s i n t e r n a l d a t a b a s e a n d t h e t e s t f o r s a t i s f a c t i o n in a m o d e l b y m e a n s of P r o l o g g o a l e v a l u t i o n o v e r t h e " p r o g r a m " t h a t c o n s i s t s of t h e f a c t s a s s e r t e d . C o n s i d e r , e . g . , a P r o l o g d a t a b a s e containing
P(1). P(2). P(3).
q(1,2). q(2,1). q(2.2).
418
T h e c l a u s e ( p ( X ) . q ( X . Y ) — > p ( Y ) ) is s a t i s f i e d in t h i s d a t a b a s e , b e c a u s e e v a l u a t i o n of t h e P r o l o g g o a l 'p(X),q(X,Y),not p ( Y ) ' fails. O n the other h a n d , the clause (q(X,Y),q(Y,Z)
---> q ( X , Z ) )
is
violated, as the goal 'q(X,Y),q(Y,Z),not q(X,Z)' succeeds and returns bindings X = 1 , Y = 2 , Z = 1 . These
bindings
represent
a
substitution
such
that
the
corresponding
ground
instance
( q ( 1 , 2 ) , q ( 2 , 1 ) — > q ( 1 , 1 ) ) is not s a t i s f i e d in t h e c u r r e n t d a t a b a s e . V i o l a t e d c l a u s e s c a n b e a p p l i e d a s g e n e r a t i o n r u l e s in o r d e r t o f u r t h e r e x t e n d t h e d a t a b a s e s o far c o n s t r u c t e d . Initially, t h e d a t a b a s e is e m p t y a n d t h e r e f o r e c l a u s e s of t h e f o r m (true — > C ) a r e t h e o n l y o n e s t h a t a r e v i o l a t e d . If t h e r e is a c l a u s e (A ---> C ) a n d a s u b s t i t u t i o n σ s u c h t h a t Α σ is s a t i s f i e d a n d C o is v i o l a t e d , t h e c l a u s e c a n b e s a t i s f i e d b y s a t i s f y i n g C o , i.e., by • a s s e r t i n g C o , if C o is a n a t o m • c r e a t i n g a c h o i c e p o i n t , c h o s i n g a c o m p o n e n t a t o m of C o a n d a d d i n g it to t h e d a t a b a s e , if C o is a d i s j u n c t i o n . G e n e r a t i o n of ' f a l s e ' i n d i c a t e s t h a t t h e c u r r e n t d a t a b a s e c o n t r a d i c t s at least o n e of t h e c o m p l e t e l y n e g a t i v e c l a u s e s a n d t h u s c a n n o t b e e x t e n d e d into a m o d e l . O n e h a s t o b a c k t r a c k to a p r e v i o u s l y e s t a b l i s h e d c h o i c e p o i n t (if a n y ) a n d to c h o o s e a d i f f e r e n t a t o m t h e r e (if a n y r e m a i n s ) . A l l f a c t s a s s e r t e d b e t w e e n t h i s c h o i c e point a n d t h e point w h e r e 'false* h a s b e e n g e n e r a t e d h a v e t o b e retracted from the database on backtracking. If all p o s s i b l e c h o i c e s l e a d t o a c o n t r a d i c t i o n , t h e p r o c e s s t e r m i n a t e s w i t h a n e m p t y d a t a b a s e a n d r e p o r t s t h a t a m o d e l c o u l d not b e c r e a t e d . T h e c l a u s e s e t u n d e r c o n s i d e r a t i o n is u n s a t i s f i a b l e . If o n t h e o t h e r h a n d a d a t a b a s e h a s b e e n c o n s t r u c t e d in w h i c h e v e r y c l a u s e is s a t i s f i e d , t h i s d a t a b a s e r e p r e s e n t s a m o d e l of t h e c l a u s e set a n d satisfiability h a s b e e n s h o w n . In c e r t a i n c a s e s g e n e r a t i o n w i l l n e v e r s t o p , b e c a u s e n o finite d a t a b a s e s a t i s f i e s all c l a u s e s , but a c o n t r a d i c t i o n d o e s not a r i s e e i t h e r . T h i s is d u e t o t h e u n d e c i d a b i l i t y of satisfiability. T h e m o d e l g e n e r a t i o n p r o c e s s o u t l i n e d a b o v e c a n b e i m p l e m e n t e d in P r o l o g by m e a n s of t h e following very simple program:
s a t i s f i a b l e :i s _ v i o l a t e d ( C ) , !, satisfy ( C ) , satisfiable. satisfiable. is__violated(C) :(A ~ > C ) , A , not C .
on_backtracking(X). on_backtracking(X) X , ! , fail.
s a t i s f y ( C ) :component(X.C), asserta(X), ο n _ b a c k t racki n g (ret ract ( X ) ) , not f a l s e .
c o m p o n e n t s , ( Y ; Z ) ) :!, ( X = Y ; c o m p o n e n t ( X , Z ) ) . component(X,X).
419
N o t e t h a t ' t r u e ' is a built-in P r o l o g p r e d i c a t e t h a t a l w a y s s u c c e e d s , w h e r e a s ' f a l s e ' d o e s
not
succeed unless asserted. T h e f o l l o w i n g e x a m p l e is i n t e n d e d to illustrate m o d e l g e n e r a t i o n in P r o l o g . C o n s i d e r t h e c l a u s e setS1:
t r u e - > p(a) ; q ( b ) q ( X ) — > s(f(X)) r(X) - > s(X)
p ( X ) - > q ( X ) ; r(X) q ( X ) , s(Y) — > f a l s e p ( X ) , s(X) — > f a l s e
T h e c h o i c e s a n d a s s e r t i o n s m a d e d u r i n g e x e c u t i o n of ' s a t i s f i a b l e ' c a n b e r e c o r d e d in f o r m of a tree:
true
P(a)
q(b)
q(a)
r(a)
s(f(b))
s(f(a))
s(a)
false
I
I
false
false
W h e n e x e c u t i n g ' s a t i s f i a b l e ' , t h i s t r e e is t r a v e r s e d in a l e f t - t o - r i g h t , d e p t h - f i r s t m a n n e r .
Every
p o s s i b l e p a t h t o w a r d s a m o d e l of S 1 is c l o s e d b e c a u s e ' f a l s e ' is f i n a l l y g e n e r a t e d . T h u s , S 1 h a s b e e n s h o w n unsatisfiable.
If t h e c l a u s e ( p ( X ) , s ( X ) — > f a l s e ) w e r e m i s s i n g , ' f a l s e ' c o u l d not b e
g e n e r a t e d along the middle branch and the database constructed along this branch - consisting of p ( a ) , r(a) a n d s(a) - w o u l d r e p r e s e n t a m o d e l of t h e r e d u c e d c l a u s e set.
2.2
How to achieve soundness for unsatisfiability
If ' s a t i s f i a b l e ' fails - w h e n a p p l i e d to a p a r t i c u l a r s e t S of c l a u s e s - t h i s s h o u l d a l w a y s c o i n c i d e w i t h S b e i n g u n s a t i s f i a b l e . C o n v e r s e l y , if ' s a t i s f i a b l e ' t e r m i n a t e s s u c c e s s f u l l y , S s h o u l d in f a c t b e satisfiable. where
W h i l e t h e latter is a c h i e v e d , t h e f o r m e r a i m is not a l w a y s r e a c h e d : T h e r e a r e c a s e s
' s a t i s f i a b l e ' f a i l s a l t h o u g h a m o d e l of S
generated that
exists. This
happens when
a disjunction
still c o n t a i n s u n i n s t a n t i a t e d v a r i a b l e s s h a r e d b y d i f f e r e n t c o m p o n e n t s
of
is the
420
d i s j u n c t i o n . C o n s i d e r , e . g . t h e f o l l o w i n g c l a u s e set S 2 : true > p(X) ; q(X) p(a) — > f a l s e q(b) — > false
Initially ' p ( X ) ; q ( X ) ' is g e n e r a t e d . If ' p ( X ) ' is a s s e r t e d , t h e d i s j u n c t i o n is s a t i s f i e d , b u t ' f a l s e ' w i l l b e g e n e r a t e d in t h e n e x t s t e p .
T h e s a m e is t h e c a s e if ' q ( X ) ' is a s s e r t e d . T h u s , ' s a t i s f i a b l e ' f a i l s .
H o w e v e r , t h e s e t { p ( b ) , q ( a ) } r e p r e s e n t s a finite m o d e l of S 2 w h i c h t h e p r o g r a m w a s u n a b l e t o find. S o u n d n e s s f o r u n s a t i s f i a b i l i t y c a n b e g u a r a n t e e d if all d i s j u n c t i o n s g e n e r a t e d a r e
completely
i n s t a n t i a t e d . T h i s is t h e c a s e iff all c l a u s e s a r e r a n g e - r e s t r i c t e d , i.e., if e v e r y v a r i a b l e in t h e c o n s e q u e n t of a c l a u s e o c c u r s in its a n t e c e d e n t a s w e l l . In p a r t i c u l a r , c o m p l e t e l y p o s i t i v e c l a u s e s - t h o s e h a v i n g ' t r u e ' as t h e i r a n t e c e d e n t - h a v e to b e v a r i a b l e - f r e e in o r d e r to b e r a n g e - r e s t r i c t e d . T h e e x a m p l e s e t S 1 g i v e n a b o v e is r a n g e - r e s t r i c t e d , w h i l e S 2 is not.
Range-restriction requires
t h a t f o r e v e r y v a r i a b l e in a c l a u s e t h e s u b s e t of t h e u n i v e r s e o v e r w h i c h t h e v a r i a b l e r a n g e s is explicitly specified inside the clause. Variables universe are not allowed.
implicitly
a s s u m e d to r a n g e o v e r t h e
whole
O n e c a n e x p e c t m a n y c l a u s e s t o b e r a n g e - r e s t r i c t e d if the p r o b l e m
d o m a i n is s o m e h o w n a t u r a l l y s t r u c t u r e d . T h i s is in p a r t i c u l a r t h e c a s e if a p r o b l e m is ( i n h e r e n t l y ) many-sorted. If a s e t S c o n t a i n s c l a u s e s t h a t a r e not r a n g e - r e s t r i c t e d , S n e v e r t h e l e s s c a n b e t r a n s f o r m e d into a s e t S* t h a t is r a n g e - r e s t r i c t e d a n d t h a t is s a t i s f i a b l e iff S is s o . For t h i s p u r p o s e a n a u x i l i a r y p r e d i c a t e ' d o r n ' is i n t r o d u c e d a n d t h e f o l l o w i n g t r a n s f o r m a t i o n s a n d a d d i t i o n s a r e p e r f o r m e d : • every
clause
(true
—>
(dom(X ),...,dom(X ) - > 1
n
C)
that
contains
variables
X
t
to
X
is
n
transformed
into
C)
• e v e r y o t h e r c l a u s e (A ---> C) s u c h t h a t C c o n t a i n s v a r i a b l e s Y
1
to Y
m
not o c c u r i n g in A is
t r a n s f o r m e d into ( A , d o m ( Y ) , . . . , d o m ( Y ) — > C ) . 1
m
• f o r e v e r y c o n s t a n t c o c c u r r i n g in S, a c l a u s e (true — > d o m ( c ) ) is a d d e d ; if S d o e s n o t c o n t a i n a n y c o n s t a n t a s i n g l e c l a u s e (true — > d o m ( a ) ) is a d d e d w h e r e ' a ' is a n artificial constant • f o r e v e r y n-ary f u n c t i o n s y m b o l f o c c u r r i n g in S o n e a d d s a c l a u s e ( d o m ( X ) , . . . , d o m ( X ) ---> 1
n
d o m ^ , . . ^ ) ) )
T h e ' d o r n ' literals a d d e d to n o n - r a n g e - r e s t r i c t e d c l a u s e s explicitly p r o v i d e f o r a n i n s t a n t i a t i o n of t h e r e s p e c t i v e v a r i a b l e s o v e r t h e H e r b r a n d u n i v e r s e of S . T h e t r a n s f o r m a t i o n of S into its r a n g e r e s t r i c t e d f o r m S* c a n b e c o m p a r e d w i t h t h e t r a n s f o r m a t i o n of a f o r m u l a into its S k o l e m i z e d f o r m : a l t h o u g h t h e t r a n s f o r m e d s e t is not e q u i v a l e n t t o t h e initial s e t in t h e strict s e n s e , a k i n d of w e a k e q u i v a l e n c e c a n b e o b s e r v e d . If t h e r e l a t i o n a s s i g n e d t o ' d o r n ' (the f u n c t i o n s a s s i g n e d to t h e S k o l e m f u n c t i o n s y m b o l s , r e s p . ) is r e m o v e d f r o m a n y m o d e l of t h e t r a n s f o r m e d s e t , a m o d e l of
421
t h e initial set is o b t a i n e d . T h e r e is 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 m o d e l s of b o t h s e t s of c l a u s e s u p to t h e r e l a t i o n ( f u n c t i o n s , resp.)
a s s i g n e d to t h e a d d i t i o n a l p r e d i c a t e
s y m b o l s , r e s p . ) . T h e r e f o r e t h e t r a n s f o r m a t i o n d e s c r i b e d p r e s e r v e s satisfiability.
(function
Transformation
of S 2 into r a n g e - r e s t r i c t e d f o r m y i e l d s S 2 * : true — > dom(a) true — > dom(b) dom(X) - >
p(a) — > q(b) — > p(X) ; q ( X )
false false
If ' s a t i s f i a b l e ' is a p p l i e d to S 2 * t h e p r o g r a m t e r m i n a t e s s u c c e s s f u l l y w i t h t h e f a c t s d o m ( a ) , d o m ( b ) , q ( a ) a n d p ( b ) in t h e d a t a b a s e . If a p p l i e d to r a n g e - r e s t r i c t e d c l a u s e s o n l y , ' s a t i s f i a b l e ' w i l l b e s o u n d for u n s a t i s f i a b i l i t y a s w e l l . For t h e rest of t h e p a p e r w e a s s u m e that all p r o b l e m s m e n t i o n e d h a v e b e e n t r a n s f o r m e d into r a n g e r e s t r i c t e d f o r m prior to c h e c k i n g t h e m for satisfiability.
2.3
How to achieve refutation-completeness
A s satisfiability is u n d e c i d a b i e no t h e o r e m p r o v e r is a b l e t o s u c c e s s f u l l y t e r m i n a t e f o r e v e r y s a t i s f i a b l e set of c l a u s e s . U n s a t i s f i a b i l i t y , h o w e v e r , is s e m i - d e c i d a b l e . T h e r e f o r e , o u r
program
s h o u l d t e r m i n a t e w i t h f a i l u r e for e v e r y u n s a t i s f i a b l e c l a u s e s e t . T h e f o l l o w i n g e x a m p l e set S 3 is unsatisfiable:
true - >
p(a)
P(f(X)), P(g(X» - >
false
p(X) - >
p(f(X))
p(X) - >
p(g(X))
W h e n a p p l i e d t o S 3 , ' s a t i s f i a b l e ' w i l l g e n e r a t e a n infinite s e q u e n c e of p - a t o m s :
p(a), p(f(a)),
p ( f ( f ( a ) ) ) , . . . etc. T h e e x a m p l e s h o w s t h a t ' s a t i s f i a b l e ' is n o t c o m p l e t e f o r u n s a t i s f i a b i l i t y ! T h i s is d u e t o t h e fact t h a t t h e P r o l o g - l i k e s e a r c h s t r a t e g y e m p l o y e d b y t h e p r o g r a m is i n h e r e n t l y u n f a i r : at e a c h r e c u r s i v e call of ' s a t i s f i a b l e ' t h e d a t a b a s e of p r o b l e m c l a u s e s is s e a r c h e d f r o m t h e t o p a n d t h e first v i o l a t e d c l a u s e f o u n d is t r i e d t o s a t i s f y . T h e r e a r e p r o b l e m s - like S 3 - w h e r e some
violated
clauses
are
never
considered
and
thus
a
contradiction
is
never
reached.
S o m e t i m e s a p r o p e r o r d e r i n g of c l a u s e s s u f f i c e s f o r c o n t r o l l i n g t h e o r d e r in w h i c h f a c t s
are
g e n e r a t e d . In o u r e x a m p l e , h o w e v e r , o r d e r i n g d o e s not h e l p ! C o m p l e t e n e s s c a n b e a c h i e v e d if c l a u s e s a r e g e n e r a t e d s y s t e m a t i c a l l y l e v e l b y l e v e l . First, all atoms/disjunctions
that
can
be
generated
from
a
given
database
are
determined
without
m o d i f y i n g t h e d a t a b a s e . T h e n all f a c t s n e e d e d in o r d e r to s a t i s f y t h e s e a t o m s / d i s j u n c t i o n s a r e
422
asserted altogether.
If S 3 w o u l d h a v e b e e n t r e a t e d t h i s w a y , t h e f o l l o w i n g f a c t s w o u l d h a v e b e e n
asserted:
level 1 : level 2 : level 3 :
p(a) p(f(a)) p(f(f(a»)
q(f(a)) p(f(g(a)))
p(g(f(a))
p(g(g(a))
false
A c o n t r a d i c t i o n w o u l d b e d e t e c t e d o n level 3 a n d t h e a t t e m p t t o g e n e r a t e a m o d e l f o r S 3 w o u l d fail. T h e following p r o g r a m i m p l e m e n t s m o d e l generation o n a level-saturation basis:
satisfiablejevel
:- s a t i s f i a b l e _ l e v e l ( 1 ) .
s a t i s f i a b l e J e v e l ( L ) :i s _ v i o l a t e d _ l e v e l ( L ) , !, on_backtracking(clean_level(L)), satisfyJevel(L), L1 is L + 1 , satisfiable_level(L1). satisfiableJevel(L).
i s _ v i o l a t e d _ l e v e l ( L ) :is_violated(C), not g e n e r a t e d ( L . C ) , assert(generated(L,C)), fail. i s _ v i o l a t e d _ l e v e l ( L ) :generated(L.X).
satisfyJevel(L)
cleanJevel(L)
:-
generated(L.C), not C, !, satisfy ( C ) , satisfyJevel(L). satisfyJevel(L).
:-
retract(generated(L,X)), fail. cleanJevel(L).
T h e p r o g r a m w o r k s with an intermediate relation 'generated' u s e d for storing atoms/disjunctions v i o l a t e d o n a l e v e l in o r d e r to b e a b l e to s a t i s f y t h e m after t h e g e n e r a t i o n p r o c e s s f o r t h a t l e v e l h a s b e e n f i n i s h e d . G e n e r a t i o n of a level c a n b e e f f i c i e n t l y o r g a n i z e d b y m e a n s of a b a c k t r a c k i n g l o o p , w h e r e a s l e v e l s h a v e to b e s a t i s f i e d r e c u r s i v e l y . T h i s is b e c a u s e t h e c h o i c e p o i n t s c r e a t e d w h e n s a t i s f y i n g a d i s j u n c t i o n h a v e to b e k e p t " o p e n " t o b a c k t r a c k i n g . A l t h o u g h ' s a t i s f i a b l e ' - a s o p p o s e d t o ' s a t i s f i a b l e j e v e l ' - is n o t c o m p l e t e , m o s t of t h e p r o b l e m s t o b e c o n s i d e r e d in t h e f o l l o w i n g s e c t i o n w i l l in f a c t t u r n o u t t o b e s o l v a b l e b y ' s a t i s f i a b l e ' .
In c a s e s
w h e r e b o t h p r o g r a m s a r e a p p l i c a b l e o n e w i l l u s u a l l y o b s e r v e t h a t t h e f o r m e r is m u c h
more
efficient t h a n t h e latter.
2.4
Enhancing efficiency through Prolog derivation rules
P r o l o g is k n o w n t o b e a p o w e r f u l i n t e r p r e t e r f o r H o r n c l a u s e s . S o m e d e s i g n d e c i s i o n s m a d e f o r t h e s a k e of e f f i c i e n y , h o w e v e r , p r e v e n t P r o l o g f r o m b e i n g a b l e to h a n d l e a r b i t r a r y H o r n p r o b l e m s .
423
T h e m i s s i n g occurs c h e c k requires to avoid certain unification patterns, the u n b o u n d e d depth-first s t r a t e g y p r e v e n t s c e r t a i n r e c u r s i v e p r o b l e m s f r o m b e i n g t r a c t a b l e in P r o l o g . F o r t h e r e m a i n i n g c a s e s P r o l o g ' s p o w e r c a n v e r y w e l l b e e x p l o i t e d if t h o s e p r o b l e m c l a u s e s t h a t a r e in t h e s c o p e of P r o l o g a r e r e p r e s e n t e d a s P r o l o g r u l e s , i.e., b y (C :- A) i n s t e a d of (A ™ > C ) .
The four Horn
c l a u s e s in e x a m p l e s e t S 1 , e . g . , c a n all b e t r e a t e d t h i s w a y :
true — >
p(a) ; q ( b )
s(X)
p(X)
q ( X ) ; r(X)
s(f(X)) :- q ( X ) f a l s e :- p ( X ) , s ( X ) f a l s e :- q ( X ) , s ( Y )
- >
:- p ( X )
W h e n a p p l i e d to this r e p r e s e n t a t i o n of S 1 , ' s a t i s f i a b l e ' w i l l initially w o r k a s b e f o r e , i.e., p ( a ) a n d q ( a ) a r e a s s e r t e d into t h e d a t a b a s e in o r d e r t o s a t i s f y t h e t w o ' — > ' - c l a u s e s . A s s o o n a s q ( a ) h a s b e e n a s s e r t e d , h o w e v e r , ' f a l s e ' b e c o m e s d e r i v a b l e . T h e t e s t 'not f a l s e ' p e r f o r m e d a f t e r a s s e r t i o n of q ( a ) f a i l s a n d b a c k t r a c k i n g is i m m e d i a t e l y i n i t i a t e d : s(f(a)) a n d ' f a l s e ' n e e d n o m o r e b e a s s e r t e d in o r d e r t o run into a c o n t r a d i c t i o n . S i m i l a r l y t h e t w o o t h e r b r a n c h e s c a n b e c u t e a r l i e r d u e t o d e r i v a b i l i t y of 'false'. T h e t r e e of f a c t s a s s e r t e d h a s b e c o m e c o n s i d e r a b l y s m a l l e r t h a n b e f o r e :
true
P(a)
q(b)
X q(a)
r(a)
X
X
C r o s s e s 'X' indicate that the respective branch has b e e n closed b e c a u s e 'false' has
become
derivable. If p a r t of a c l a u s e s e t is d i r e c t l y r e p r e s e n t e d in P r o l o g , ' s a t i s f i a b l e ' c a n b e a p p l i e d w i t h o u t a n y c h a n g e , p r o v i d e d i n c o n s i s t e n c y of t h e P r o l o g part of t h e p r o b l e m h a s b e e n t e s t e d b e f o r e . T h i s c a n b e d o n e by simply e v a l u a t i n g 'false' o n c e before calling 'satisfiable'. T h e s a m e applies to 'satisfiablejevel'. What
has changed, however,
is t h e w a y t h e m o d e l u n d e r c o n s t r u c t i o n
is r e p r e s e n t e d
and
s a t i s f a c t i o n of c l a u s e s is d e t e r m i n e d . T h e p r o b l e m c l a u s e s t h a t h a v e b e e n d i r e c t l y r e p r e s e n t e d in P r o l o g n o w s e r v e as d e r i v a t i o n r u l e s .
If t h e r e q u i r e m e n t f o r c l a u s e s to b e r a n g e - r e s t r i c t e d is
r e s p e c t e d , only g r o u n d literals will be derivable t h r o u g h t h e s e rules. G r o u n d a t o m s that
are
required for satisfying the
are
>'-clauses
n e e d not b e explicitly a s s e r t e d a n y m o r e , if t h e y
424
derivable from the already existing facts. Thus, the
model
under construction
is n o
longer
r e p r e s e n t e d b y explicitly s t o r e d f a c t s a l o n e , b u t b y all f a c t s d e r i v a b l e v i a t h o s e p r o b l e m c l a u s e s t h a t h a v e b e e n r e p r e s e n t e d d i r e c t l y in P r o l o g .
As the Prolog goal evaluation m e c h a n i s m solves
g o a l s not o n l y o v e r f a c t s b u t t h r o u g h r u l e s a s w e l l , n o t h i n g h a s to b e c h a n g e d in t h e p r o g r a m s given. In e v e r y c l a u s e s e t at least t h e p o s i t i v e g r o u n d u n i t s a n d t h e c o m p l e t e l y n e g a t i v e c l a u s e s c a n a l w a y s b e f o r m u l a t e d d i r e c t l y in P r o l o g . T h e r e a r e e v e n p r o b l e m s w h e r e all c l a u s e s c a n b e r e p r e s e n t e d t h i s w a y . In t h i s c a s e satisfiability c h e c k i n g r e d u c e s t o a s i n g l e ' f a l s e ' e v a l u a t i o n . W h e n u s i n g P r o l o g r u l e s f o r c l a u s e r e p r e s e n t a t i o n o n e n e v e r t h e l e s s h a s t o b e v e r y c a r e f u l in order to avoid recursion and occurs check problems. connection
graph
contains
a
cycle
that
has
a
(A set o f c l a u s e s
unifier.)
Although
a
is r e c u r s i v e , if its complete
syntactic
c h a r a c t e r i z a t i o n of s u c h c a s e s is not e a s y , t h e r e a r e r e l a t i v e l y s i m p l e s u f f i c i e n t c o n d i t i o n s , like, e . g . , t o a v o i d literals w i t h m o r e t h a n o n e o c c u r r e n c e of t h e s a m e v a r i a b l e ( s t a t i c o c c u r s c h e c k ) in o r d e r t o a v o i d d y n a m i c o c c u r s c h e c k p r o b l e m s . If in d o u b t , t h e o p t i o n t o r e p r e s e n t a H o r n c l a u s e a s a g e n e r a t i o n rule a l w a y s r e m a i n s . B e c a u s e of r a n g e - r e s t r i c t i o n t h i s r e p r e s e n t a t i o n w i l l n e v e r l e a d to a n y o c c u r s c h e c k p r o b l e m .
2.5
Further variations and optimizations
T h e b a s i c m o d e l g e n e r a t i o n p a r a d i g m - as o u t l i n e d a b o v e - m a y , of c o u r s e , e x h i b i t
serious
i n e f f i c i e n c i e s in s p e c i a l s i t u a t i o n s . H o w e v e r , o n e c a n e a s i l y i n c o r p o r a t e s e v e r a l v a r i a t i o n s into t h e b a s i c p r o c e d u r e t h a t m a y l e a d to c o n s i d e r a b l e o p t i m i z a t i o n s in c e r t a i n u n d e s i r a b l e c a s e s . In t h e f o l l o w i n g w e w i l l s h o r t l y d i s c u s s t h r e e s u c h v a r i a t i o n s t h a t a r e o p t i o n a l l y a v a i l a b l e in S A T C H M O . T h e y a r e i n t e n d e d t o s p e e d u p t h e s e a r c h f o r v i o l a t e d c l a u s e s , or p e r m i t t o d e r i v e c o n t r a d i c t i o n s earlier.
W h e r e a s t h e first - c a l l e d c l a u s e - s e t c o m p a c t i o n in [ B U T 8 6 ] - will a l w a y s r e s u l t in s o m e
b e n e f i t , o t h e r s will p a y off o n l y if a p p l i e d to p r o b l e m s t h a t in f a c t e x h i b i t t h e i n e f f i c i e n c y t h e y a r e intended to cure.
Otherwise these variations m a y e v e n lead to s o m e o v e r h e a d c o m p a r e d with
the basic procedures.
1. clause-set c o m p a c t i o n : Search
for
violated
clauses
may
be
fairly
expensive
in c a s e s
where
the
clausal
f o r m u l a t i o n of a p r o b l e m is h i g h l y r e d u n d a n t , a s is t h e c a s e , e . g . , w i t h
p(X,Y),q(Y,Z) p(X,Y) , q(Y,Z) p(X,Y) , s(Y,Z) p(X,Y) , s(Y,Z)
-
> > > >
h(X) h(Y) h(X) h(Y)
T h e p- a n d h - r e l a t i o n s h a v e to b e s e a r c h e d f o u r t i m e s , t h e q - a n d s - r e l a t i o n s t w i c e in
425
o r d e r t o d e t e r m i n e all i n s t a n c e s of t h e c l a u s e s t h a t a r e v i o l a t e d in a g i v e n d a t a b a s e . If w e w o u l d a l l o w ';' to o c c u r in t h e a n t e c e d e n t , a n d ',' t o o c c u r in t h e c o n s e q u e n t of a r u l e a s w e l l , t h e s e f o u r c l a u s e s c o u l d b e c o m p a c t i f i e d into t h e s i n g l e rule p(X,Y) , (q(Y,Z) ; s(Y,Z)) - >
h(X) . h ( Y )
If t h i s e x p r e s s i o n is t e s t e d f o r v i o l a t i o n , t h e p-, q - , a n d s - r e l a t i o n a r e s e a r c h e d o n l y o n c e , t h e h - r e l a t i o n t w i c e . In o r d e r to h a n d l e n o n - c l a u s a l g e n e r a t i o n rules a s w e l l , t h e f o l l o w i n g h a s t o b e a d d e d o n t o p of 'satisfy': satisfy((A,B))
:- !, s a t i s f y ( A ) , s a t i s f y ( B ) .
2. c l a u s e c o m p i l a t i o n : W h e n t e s t i n g for c o n t r a d i c t i o n s by e v a l u a t i n g ' f a l s e ' , t h e t e s t is p e r f o r m e d g l o b a l l y o v e r t h e w h o l e d a t a b a s e of f a c t s .
O n e d o e s not t a k e into c o n s i d e r a t i o n t h e s p e c i f i c f a c t
a s s e r t e d just b e f o r e . A s ' f a l s e ' h a s not b e e n d e r i v a b l e b e f o r e this u p d a t e , it c a n b e derivable derivation
n o w only of
'false'.
if t h e
most-recently
Therefore
it
introduced
is p o s s i b l e
to
literal is a b l e to p a r t i c i p a t e "focus"
the
contradiction
in a
test
by
p r e c o m p i l i n g t h e c o m p l e t e l y n e g a t i v e p r o b l e m c l a u s e s into local t e s t c l a u s e s . C o n s i d e r , e . g . , a set of c l a u s e s c o n t a i n i n g
false : - p ( X , Y ) , q ( Y , Z ) . q(A,B) : - s ( B , A ) .
P r e c o m p i l a t i o n w o u l d result in t h e f o l l o w i n g l o c a l test c l a u s e s b e i n g g e n e r a t e d :
incompatible(p(X,Y)) incompatible(p(X,Y))
:-q(Y,Z). :- s ( Z , Y ) .
incompatible(q(Y,Z)) incompatible(s(Z,Y))
:-p(X,Y). :- p ( X , Y ) .
O n c e n e g a t i v e c l a u s e s h a v e b e e n c o m p i l e d t h i s w a y o n e c a n e x p l o i t t h e m b y slightly m o d i f y i n g t h e 'satisfy' p r e d i c a t e a g a i n : i n s t e a d of ' a s s e r t ( X ) , . . , n o t f a l s e ' o n e p e r f o r m s 'not incompatible(X),assert(X),..'.
T h u s , f a c t s t h e a s s e r t i o n of w h i c h w o u l d d i r e c t l y l e a d to a
c o n t r a d i c t i o n a r e n e v e r a s s e r t e d . P r e c o m p i l a t i o n of t h e i n c o m p a t i b i l i t y rules c a n e a s i l y a n d efficiently be p r o g r a m m e d in P r o l o g .
A similar precompilation idea m a y be applied
for the remaining clauses as well possibly speeding-up the search for violated clauses. W e h a v e r e p o r t e d a b o u t t h i s in [ B R Y 8 7 ] .
3. c o m p l e m e n t splitting: When
the
assertion
of
an
atom
Aj
chosen
from
a
disjunction
has
resulted
in
a
c o n t r a d i c t i o n o n e m a y try to b e n e f i t f r o m t h e i n f o r m a t i o n t h u s o b t a i n e d w h i l e t r y i n g t h e
426
remaining
components.
( f a l s e :- Aj).
This
can
be
achieved
by
temporarily
asserting
T h i s w a y a n y a t t e m p t to r e - a s s e r t A w h i l e t r y i n g t o satisfy t h e (
the
rule
respective
d i s j u n c t i o n a r e i m m e d i a t e l y b l o c k e d . T h e size of t h e s e a r c h t r e e m a y be c o n s i d e r a b l y c u t d o w n in c a s e s e v e r a l o c c u r r e n c e s of big s u b t r e e s a r e a v o i d e d t h i s w a y .
Exploiting
information about attempts that h a v e already failed for avoiding r e d u n d a n t w o r k
has
a l r e a d y b e e n s u g g e s t e d b y D a v i s a n d P u t n a m in t h e i r e a r l y p r o o f p r o c e d u r e . T h e f e a t u r e c a n be i m p l e m e n t e d by modifying the ' c o m p o n e n t ' predicate as follows:
component(X,(Y;Z))
:- !,
(X=Y; a s s e r t ( ( f a l s e :- Y ) ) , o n _ b a c k t r a c k i n g ( r e t r a c t ( ( f a l s e :- Y ) ) ) , component(X.Z)).
3.
Experiences with SATCHMO
When
reporting
about
experiences
with a
new
method, one
of c o u r s e t e n d s
to
start
with
" s h o w c a s e " e x a m p l e s t h a t a r e p a r t i c u l a r l y w e l l h a n d l e d b y t h e a p p r o a c h p r o p o s e d . In o u r c a s e , it t u r n s o u t t h a t s e v e r a l e x a m p l e s r e c e n t l y d i s c u s s e d in t h e l i t e r a t u r e a r e s u i t a b l e f o r t h i s p u r p o s e . T h u s , w e b e g i n t h i s s e c t i o n w i t h d i s c u s s i n g t h e s e e x a m p l e s in s o m e d e t a i l . T h e n w e
shortly
a d d r e s s c o m b i n a t o r i a l p u z z l e s - a c l a s s of p r o b l e m s p r e f e r a b l y t a k e n f o r d e m o n s t r a t i n g t h e p o w e r of a t h e o r e m p r o v e r . T h e t h i r d a n d m o s t c o m p r e h e n s i v e s e c t i o n will b e d e v o t e d t o
Pelletier's
"Seventy-five Problems for Testing T h e o r e m Provers" [PEL 86]. A s this collection c o v e r s a wide r a n g e of p r o b l e m c l a s s e s , w e r e g a r d it a s p a r t i c u l a r l y w e l l s u i t e d f o r e x h i b i t i n g t h e p o t e n t i a l p o w e r a s w e l l a s t h e limits of t h e a p p r o a c h s u g g e s t e d . A l l e x a m p l e s d i s c u s s e d h a v e b e e n r u n u n d e r i n t e r p r e t e d C P r o l o g V e r s . 1.5 o n a V A X
11/785.
T h e s o l u t i o n t i m e s t h a t w i l l b e g i v e n h a v e b e e n m e a s u r e d u s i n g t h e built-in p r e d i c a t e ' c p u t i m e ' . T h e a u t h o r s a r e v e r y m u c h a w a r e of t h e f a c t t h a t c o m p a r i n g t h e o r e m p r o v e r s o n t h e b a s i s of c p u t i m e s is h a r d l y e v e r a b l e to d o j u s t i c e to t h e p a r t i c u l a r a p p r o a c h e s e x c e p t if all c o n d i t i o n s a r e r e s p e c t e d a b s o l u t e l y f a i r l y . R e p o r t i n g c p u t i m e s in t h i s p a p e r is not i n t e n d e d t o c o m p e t e w i t h o t h e r s , but to s h o w w h i c h k i n d of e x a m p l e s a r e h a r d f o r m o d e l g e n e r a t i o n a n d w h i c h a r e e a s y . M o r e o v e r , w e w o u l d like t o d e m o n s t r a t e t h i s w a y t h a t t h e o r e m p r o v i n g in P r o l o g is f e a s i b l e a n d that the efficiency obtained w h e n doing so m a y be remarkable.
3.1
Schubert's Steamroller
T h e steamroller p r o b l e m has b e e n p r e s e n t e d by Len S c h u b e r t
nearly a d e c a d e
ago.
Mark
S t i c k e l ' s article " S c h u b e r t ' s S t e a m r o l l e r P r o b l e m : F o r m u l a t i o n s a n d S o l u t i o n s " [ S T I 8 6 ] p r o v i d e s
427
an
excellent
overview
of
various
attempts
to
solve
this
problem.
We
use
the
(unsorted)
f o r m u l a t i o n t h a t S t i c k e l h a s p r o p o s e d a s a s t a n d a r d . A s a l r e a d y m e n t i o n e d in t h e i n t r o d u c t i o n , t h i s p r o b l e m c a n b e c o m p l e t e l y e x p r e s s e d in P r o l o g e x c e p t f o r o n e n o n - H o r n c l a u s e :
wolf(w).
animal(X) animal(X) animal(X) animal(X) animal(X)
fox(f). bird(b). snail(s). caterpillar(c). grain(g). smaller(X.Y) smaller(X,Y) smaller(X,Y) smaller(X,Y) likes(X,Y) false false false
plant(X) -
fox(X) , wolf(Y). bird(X) , f o x ( Y ) . snail(X), bird(Y). caterpillar(X) , bird(Y).
- wolf(X). - fox(X). - bird(X). - snail(X). - caterpillar(X). :- g r a i n ( X ) .
p l a n t ( i ( X ) ) :- s n a i l ( X ) . l i k e s ( X , i ( X ) ) :- s n a i l ( X ) . p l a n t ( h ( X ) ) :- c a t e r p i l l a r ( X ) . l i k e s ( X , h ( X ) ) :- c a t e r p i l l a r ( X ) .
:- b i r d ( X ) , c a t e r p i l l a r ( Y ) .
wolf(X) , (fox(Y) ; grain(Y)) , likes(X.Y). bird(X) , snail(Y) , likes(X.Y). animal(X) , animal(Y) , likes(X.Y) , grain(Z) , likes(Y.Z).
animal(X) , animal(Y) , smaller(Y,X) , plant(W) , likes(Y.W) , plant(Z) — >
likes(X.Y) ; likes(X,Z).
S a t i s f i a b i l i t y of t h e P r o l o g part of t h e p r o b l e m f o r m u l a t i o n c a n b e d e m o n s t r a t e d w i t h i n 0 . 0 5 s e e s b y e v a l u a t i o n of t h e g o a l ' f a l s e ' . U n s a t i s f i a b i l i t y of t h e w h o l e p r o b l e m is p r o v e d b y m e a n s of ' s a t i s f i a b l e ' after 0.3 s e e s . ( T h e b e s t t i m e r e p o r t e d in S t i c k e l ' s p a p e r w a s 6 s e e s f o r t h e u n s o r t e d v e r s i o n of t h e p r o b l e m . ) T h e c h o i c e s a n d a s s e r t i o n s p e r f o r m e d d u r i n g e x e c u t i o n a r e a s f o l l o w s :
ι
1
likes(b,s)
likes(b,g)
likes(f.b)
likes(f.g)
likes(w,f) X
likes(w,g) X
T h e w a y ' s a t i s f i a b l e ' s o l v e s t h e p r o b l e m c o r r e s p o n d s p r e t t y w e l l to t h e n a t u r a l l a n g u a g e s o l u t i o n given by Stickel.
428
3.2
Lewis Carroll's "Salt-and-Mustard problem"
T h i s p r o b l e m - w h i c h s t e m s f r o m L e w i s C a r r o l l ' s " S y m b o l i c L o g i c " of 1 8 9 7 - h a s b e e n d i s c u s s e d in a p u b l i c a t i o n b y L u s k a n d O v e r b e e k
in t h e p r o b l e m c o r n e r of t h e J o u r n a l of
Automated
R e a s o n i n g [ L O 8 5 ] . It is a b o u t five f r i e n d s w h o h a v e i m p o s e d c e r t a i n r u l e s g o v e r n i n g
which
c o n d i m e n t - salt o r m u s t a r d - to t a k e w h e n t h e f i v e a r e h a v i n g b e e f t o g e t h e r . T h e p r o b l e m is t o c h e c k w h e t h e r t h e s e r u l e s a r e c o m p a t i b l e , i.e., s a t i s f i a b l e . T h e m a j o r p a r t of t h e p r o b l e m c o n s i s t s of i f - a n d - o n l y - i f c o n d i t i o n s f o r e a c h f r i e n d a n d e a c h c o n d i m e n t . E a c h of t h e s e c a n b e e x p r e s s e d b y m e a n s of a n o n - H o r n g e n e r a t i o n rule a n d a H o r n d e r i v a t i o n r u l e . O u r f o r m u l a t i o n is as f o l l o w s (note that s o m e 'false'-rules have b e e n compactified):
salt(X) :- b o t h ( X ) . m u s t a r d ( X ) :- b o t h ( X )
friend(barry). friend(cole). friend(dix). friend(lang). friend(mill).
salt(X) , m u s t a r d ( X )
salt(barry) mustard(barry) salt(cole) mustard(cole) salt(dix) mustard(dix) salt(lang) mustard(lang) salt(mill) mustard(mill) salt(barry) mustard(barry) salt(cole) mustard(cole) salt(dix) mustard(dix) salt(lang) mustard(lang) salt(mill) mustard(mill)
-
—> •— >
—> ... > ---> —> —> —> —> —>
oneof(cole) neither(dix) oneof(barry) both(dix) neither(barry) neither(lang) oneof(barry) neither(cole) both(barry) oneof(cole)
-
oneof(lang). both(mill). neither(mill). both(lang). both(cole). neither(mill). oneof(dix). neither(mill). both(lang). oneof(dix). oneof(lang). both(mill). neither(mill). both(lang). both(cole). neither(mill).
oneof(cole) neither(dix) oneof(barry) both(dix) neither(barry) neither(lang) oneof(barry) neither(cole) both(barry)
oneof(dix). neither(mill). both(lang).
oneof(cole)
oneof(dix).
oneof(X) — > salt(X) ; mustard(X). friend(X) — > both(X) ; neither(X) ; oneof(X). false
false false
: - o n e o f ( X ) ,(both(X) ; neither(X)) :- o n e o f ( X ) , s a l t ( X ) , m u s t a r d ( X ) .
:- n e i t h e r ( X ) , ( b o t h ( X ) ; s a l t ( X ) ; m u s t a r d ( X ) ) .
T h e problem has a single m o d e l :
salt(barry) sait(mill)
mustard(barry) mustard(lang)
neither(dix) neither(cole)
oneof(lang) oneof(mill)
both(barry)
429
' S a t i s f i a b l e ' f i n d s it w i t h i n 1.1 s e e s . L u s k a n d O v e r b e e k h a v e j u d g e d t h i s p r o b l e m to b e e s p e c i a l l y h a r d as t h e i r t h e o r e m p r o v e r h a s p r o d u c e d 3 2 0 0 0 c l a u s e s f o r s o l v i n g t h e p r o b l e m . A l t h o u g h t h e t r e e to b e s e a r c h e d b e f o r e a s o l u t i o n is f o u n d is c o n s i d e r a b l y b i g g e r t h a n f o r t h e S t e a m r o l l e r t h e p r o b l e m is still a s i m p l e o n e for a m o d e l g e n e r a t i o n a p p r o a c h . T h e t w o o t h e r p r o b l e m s d i s c u s s e d in t h e article b y L u s k a n d O v e r b e e k a r e in fact m u c h e a s i e r : " t r u t h t e l l e r s a n d liars" a r e d i s m a n t l e d w i t h i n 0.1 s e e s , w h i l e a m o d e l f o r t h e " s c h o o l b o y s p r o b l e m " is f o u n d after 0.2 s e e s .
3.3
A non-obvious problem
P e l l e t i e r a n d R u d n i c k i [ P R 8 6 ] h a v e r e c e n t l y d i s c u s s e d a p r o b l e m t h a t is s i m p l e to s t a t e , b u t h a r d to p r o v e . B e c a u s e of its b r e v i t y w e g i v e t h e i r p r o b l e m f o r m u l a t i o n a s w e l l :
" S u p p o s e there are
t w o r e l a t i o n s , Ρ a n d Q . Ρ is t r a n s i t i v e , a n d Q is b o t h t r a n s i t i v e a n d r e f l e x i v e . S u p p o s e f u r t h e r t h e ' s q u a r e n e s s ' of Ρ a n d Q: a n y t w o t h i n g s a r e e i t h e r r e l a t e d in t h e Ρ m a n n e r o r in t h e Q m a n n e r . P r o v e t h a t e i t h e r Ρ is t o t a l or Q is t o t a l . " O u r f o r m a l i z a t i o n of t h e p r o b l e m - r e q u i r i n g a t r a n s f o r m a t i o n into r a n g e - r e s t r i c t e d f o r m - is a s follows:
dom(a) dom(b) dom(c). dom(d)
p(X,Y) , p(Y,Z) - > p(X,Z). q(X,Y) , q(Y,Z) - > q(X,Z). q(X,Y) - > q(Y,X). dom(X),dom(Y) - > p(X,Y) ; q(X,Y). f a l s e :- p ( a , b ) . f a l s e :- q ( c , d ) .
T h e t r e e to b e s e a r c h e d b y ' s a t i s f i a b l e '
is a l r e a d y q u i t e b i g :
348 facts are asserted
and
s u b s e q u e n t l y retracted again, 52 choice points are established a n d 5 3 b r a n c h e s are closed. T h e t h e o r e m is p r o v e d w i t h i n 1 6 s e e s . P e l l e t i e r / R u d n i c k i report a b o u t a s o l u t i o n t i m e j u s t u n d e r 2 m i n s , M c C u n e r e p o r t s just u n d e r 1 m i n [ M c C 8 6 ] . J u s t r e c e n t l y W a l t h e r h a s o b t a i n e d 3 1 . 1 s e e s [ W A L 8 8 ] . If c o m p l e m e n t s p l i t t i n g is applied for this example, the search tree c a n be considerably r e d u c e d s u c h that the solution time g o e s d o w n t o 9.5 s e e s .
430
3.4
Some combinatorial puzzles
In P e l l e t i e r ' s c o l l e c t i o n , to b e d i s c u s s e d b e l o w , t h e r e is a n o t h e r p r o b l e m ( n u m b e r 5 5 ) p o s e d b y L e n S c h u b e r t . T h i s p r o b l e m is a s i m p l e c o m b i n a t o r i a l p u z z l e w h e r e t h e m u r d e r e r of a u n t A g a t h a has to be found.
E q u a l i t y (or identity) is u s e d in o r d e r to e x p r e s s t h a t t h e m u r d e r e r h a s to b e
f o u n d a m o n g t h e t h r e e p e o p l e living in t h e h o u s e . W e c o n j e c t u r e t h a t t h e f o l l o w i n g f o r m u l a t i o n of t h e p r o b l e m (not u s i n g '=*) is s i m p l e r a n d m o r e n a t u r a l t h a n P e l l e t i e r ' s :
lives(agatha). lives(butler). lives(charles).
false false false
:- k i l l e d ( X . Y ) , r i c h e r ( X . Y ) . :- h a t e s ( a g a t h a . X ) , h a t e s ( c h a r l e s . X ) . :- h a t e s ( X . a g a t h a ) , h a t e s ( X . b u t l e r ) , h a t e s ( X . c h a r l e s )
hates(agatha.agatha). hates(agatha.charles).
h a t e s ( X . Y ) :- k i l l e d ( X . Y ) . h a t e s ( b u t l e r , X ) :- h a t e s ( a g a t h a . X ) .
true — > killed(agatha.agatha) ; killed(butler,agatha) ; killed(charles,agatha). lives(X) — > richer(X,agatha) ; hates(butler.X).
A f t e r 0 . 0 5 s e e s a m o d e l f o r t h e p r o b l e m is f o u n d i n d i c a t i n g t h a t a u n t A g a t h a h a s k i l l e d herself. A f t e r 0.1 s e e s all o t h e r p o s s i b i l i t i e s h a v e b e e n r u l e d o u t p r o v i n g t h a t A g a t h a i n d e e d m u s t h a v e committed suicide. U s i n g t h i s s t y l e of f o r m u l a t i o n , i.e., e x p r e s s i n g t h e d i f f e r e n t c h o i c e s t h a t a r e e x i s t i n g o v e r t h e finite d o m a i n of t h e p u z z l e b y m e a n s of d i s j u n c t i o n s a n d e x p r e s s i n g t h e r e m a i n i n g c o n d i t i o n s d i r e c t l y in P r o l o g , o n e c a n s o l v e q u i t e a lot of s i m i l a r p u z z l e s e f f i c i e n t l y . W e j u s t w o u l d like to m e n t i o n a s examples • L e w i s C a r r o l l ' s Ί ί ο η - a n d - u n i c o r n " p u z z l e ( d i s c u s s e d r e c e n t l y in t h e J o u r n a l of A u t o m a t e d R e a s o n i n g [ O H L 8 5 ] ) : 2 0 P r o l o g c l a u s e s , 1 n o n - H o r n c l a u s e - s o l v e d in 0.1 s e e s or a more substantial one: • t h e full " j o b s " p u z z l e t a k e n f r o m [ W O S 8 4 ] :
31 P r o l o g c l a u s e s , 2 n o n - H o r n c l a u s e s -
s o l v e d in 4 . 5 s e e s
A g a i n t h e incomplete p r o g r a m 'satisfiable' has b e e n sufficient.
3.5
Pelletier's seventy-five problems
A l l p r o b l e m s d i s c u s s e d in t h e f o l l o w i n g h a v e b e e n s o l v e d w i t h ' s a t i s f i a b l e ' a s w e l l , u n l e s s s t a t e d differently. T h e p r o p o s i t i o n a l p r o b l e m s 1-17 a r e all v e r y e a s y o n c e c l a u s a l f o r m h a s b e e n o b t a i n e d . Eight of t h e m c a n b e c o m p l e t e l y r e p r e s e n t e d in P r o l o g a n d a r e all s o l v e d u n d e r 0.01 s e e s . P r o b l e m 12 is the hardest a m o n g the remaining o n e s - a solution requires 0.15 sees.
431
T h e m o n a d i c p r o b l e m s 1 8 - 3 3 ( 3 4 h a s b e e n o m i t t e d b e c a u s e t h e a u t h o r s d i d not w a n t t o p e r f o r m t h e " e x e r c i s e " of c o m p u t i n g 1 6 0 0 c l a u s e s ) a r e s i m p l e a s w e l l , w i t h o n e e x c e p t i o n n a m e l y p r o b l e m 29.
T h i s p r o b l e m - c o n s i s t i n g of 3 2 c l a u s e s - r e q u i r e s 3 3 s e e s ! ( A t t e n t i o n :
version contains two typing mistakes.)
Pelletier's clausal
A c l a u s e - s e t c o m p a c t i o n a s d e s c r i b e d a b o v e r e s u l t s in 2 3
c o m p a c t i f i e d c l a u s e s a n d u n s a t i s f i a b i l i t y of t h e c o m p a c t i f i e d set c a n b e s h o w n w i t h i n 4 . 3 s e e s .
If
in a d d i t i o n c o m p l e m e n t s p l i t t i n g is a p p l i e d , t h e t i m e n e e d e d g o e s d o w n to 1.1 s e e s . P r o b l e m s 1 9 , 2 0 , 2 7 , 2 8 , a n d 3 2 a r e c o m p l e t e l y e x p r e s s a b l e in P r o l o g a n d s o l v a b l e in l e s s t h a n 0 . 0 2 s e e s ( p r o b l e m 2 8 is s a t i s f i a b l e ! ) . T h e full p r e d i c a t e l o g i c p r o b l e m s w i t h o u t i d e n t i t y a n d ( n o n - S k o l e m ) f u n c t i o n s 3 5 - 4 7 d o not i m p o s e p a r t i c u l a r p r o b l e m s e i t h e r . P r o b l e m 4 4 is t h e o n l y o n e t h a t c a n b e c o m p l e t e l y r e p r e s e n t e d in Prolog (solved u n d e r 0.01 sees). forever. g(X)'
P r o b l e m 3 5 is t h e first p r o b l e m f o r w h i c h ' s a t i s f i a b l e ' w o u l d r u n
' S a t i s f i a b l e j e v e l ' s o l v e s it w i t h i n 0 . 0 7 s e e s . In p r o b l e m 4 6 t h e c l a u s e 'f(X) — > f(f(X)) ;
h a s to
b e " h i d d e n " at t h e e n d of t h e c l a u s e
list in o r d e r t o m a i n t a i n
applicability
of
' s a t i s f i a b l e ' . T h e m o s t difficult p r o b l e m in this s e c t i o n is p r o b l e m 4 3 , r e q u i r i n g 0 . 6 5 s e e s . P r o b l e m 4 7 is t h e S t e a m r o l l e r d i s c u s s e d earlier. Among
the
remaining
problems
48-69
there
are
nine functional
problems
without
identity.
P r o b l e m s 5 7 , 5 9 a n d 60 (Pelletier's faulty clausal f o r m corrected) c a n be s o l v e d by 'satisfiable' u n d e r 0.1 s e e s , p r o b l e m 5 0 r e q u i r e s 0.55 s e e s ( 0 . 2 8 w i t h c o m p l e m e n t s p l i t t i n g ) . F o r p r o b l e m 6 2 o n c e a g a i n t h e c l a u s a l f o r m g i v e n b y P e l l e t i e r d o e s not c o r r e s p o n d t o t h e n o n c l a u s a l f o r m of t h e t h e o r e m . If c o r r e c t e d t h e c l a u s a l f o r m c a n i m m e d i a t e l y b e s h o w n s a t i s f i a b l e a s n o c o m p l e t e l y p o s i t i v e c l a u s e s exist. P r o b l e m s 6 6 - 6 9 c a n n o t b e s o l v e d b y a n y of t h e t w o S A T C H M O p r o g r a m s ! v a r i a t i o n s of a h a r d r e c u r s i v e H o r n - p r o b l e m w i t h f u n c t i o n s .
T h e s e problems are
T h e r e is a s i n g l e p r e d i c a t e r a n g i n g
o v e r t h e w h o l e d o m a i n . A s t h e p r o b l e m s a r e not r a n g e - r e s t r i c t e d i n s t a n t i a t i o n o v e r t h e H e r b r a n d universe h a s to b e p r o v i d e d t h r o u g h the 'dom'-predicate. Consider, e.g., p r o b l e m 6 6 :
t ( i ( X ) , i ( Y , X ) ) :- d o m ( X ) , d o m ( Y ) . t ( i ( i ( X , i ( Y , Z ) ) , i ( i ( X , Y ) , i ( X , Z ) ) ) :- d o m ( X ) , d o m ( Y ) , d o m ( Z ) . t ( i ( i ( n ( X ) , n ( Y ) ) , i ( Y , X ) ) :- d o m ( X ) , d o m ( Y ) . t(i(X,Y)).t(X) - > t(Y) f a l s e :- t ( i ( a , n ( n ( a ) ) ) ) . dom(X) — > dom(n(X)). dom(X) , dom(Y) — > dom(i(X,Y)).
S a t c h m o f a i l s b e c a u s e t h e g e n e r a t i o n of n e w H e r b r a n d t e r m s v i a t h e t w o ' d o m ' - r u l e s i n t e r f e r e s w i t h t h e g e n e r a t i o n of t h e n e c e s s a r y 't'-facts. T h e n u m b e r of ' d o m ' - f a c t s g e n e r a t e d e x p l o d e s a n d the c o m p a r a t i v e l y f e w 't'-facts that c a n be g e n e r a t e d o n e a c h level are " b u r i e d " by t h e m . T h e only
432
w a y t o w a r d s p o s s i b l y s o l v i n g p r o b l e m s of t h i s k i n d s e e m s to b e a c a r e f u l c o n t r o l of term
generation:
'dom'-rules
should
not
be
applied
before
the
other
rules
have
Herbrand not
been
e x h a u s t i v e d . A s s u c h a c o n t r o l f e a t u r e h a s not yet b e e n i m p l e m e n t e d , w e d o not f u r t h e r e l a b o r a t e o n this point. P r o l o g ' s i m p l e m e n t a t i o n of ' = ' c a n n o t b e u s e d for c o r r e c t l y r e p r e s e n t i n g l o g i c a l i d e n t i t y ( e x c e p t in v e r y r e s t r i c t e d c a s e s ) . In o r d e r t o r e p r e s e n t the r e m a i n i n g p r o b l e m s w i t h i d e n t i t y t h e r e are t w o possibilities: 1. to introduce
a special equality predicate
and to add the n e c e s s a r y
equality
axioms
(transitivity, s u b s t i t u t i v i t y e t c . ) : t h i s h a s b e e n d o n e f o r p r o b l e m s 4 8 , 4 9 , 5 1 - 5 4 , 5 6 , a n d 5 8 2. to r e c o d e t h e p r o b l e m s w i t h o u t e x p l i c i t l y u s i n g identity a s d o n e in t h e o r i g i n a l f o r m u l a t i o n of t h e t h r e e g r o u p t h e o r y p r o b l e m s 6 3 - 6 5 by W o s ; p r o b l e m 61 h a s b e e n c o d e d t h i s w a y too Of t h e p r o b l e m s t h u s a u g m e n t e d o r r e c o d e d , ' s a t i s f i a b l e ' w a s a b l e to s o l v e p r o b l e m s 4 8 , 4 9 , 6 1 , 6 4 , a n d 6 5 in less t h a n 1 s e c e a c h .
F o r t h e r e m a i n i n g p r o b l e m s ' s a t i s f i a b l e j e v e l ' h a d to b e
e m p l o y e d : of t h e s e , p r o b l e m 5 8 w a s s o l v e d in 0.15 s e e s a n d p r o b l e m 6 3 in 0 . 7 5 s e e s ; p r o b l e m 55 has been discussed above.
P r o b l e m s 5 1 - 5 4 a n d 5 6 c o u l d not b e s o l v e d b y e i t h e r p r o g r a m s ,
d u e t o d e f i c i e n c i e s v e r y s i m i l a r to t h o s e r e s p o n s i b l e for f a i l u r e in c a s e of 6 6 - 6 9 . T h e last s e c t i o n in P e l l e t i e r ' s c o l l e c t i o n p r o v i d e s p r o b l e m s f o r s t u d y i n g t h e c o m p l e x i t y of a p r o o f s y s t e m . T h e f o l l o w i n g f i g u r e s a r e g i v e n w i t h o u t f u r t h e r c o m m e n t as w e h a v e n o t really s t u d i e d their relevance yet. Pigeonhole problems (72,73):
η I sees I
1 0.05
2 0.13
3 0.7
4 3.8
5 25.5
...
T i m e s a r e g i v e n f o r o u r f o r m u l a t i o n of t h e p r e d i c a t e logic v e r s i o n ( 7 3 ) : t h e t i m e s c l e a r l y i n d i c a t e e x p o n e n t i a l g r o w t h . T h e e x p o s i t o r y a r b i t r a r y g r a p h p r o b l e m 7 4 is s o l v e d in 0 . 1 8 s e e s . F o r U - p r o b l e m s (71) c o d e d a s a r b i t r a r y g r a p h p r o b l e m s (75) g r o w t h s e e m s to b e at m o s t c u b i c :
η
I
sees I
1
2
0.05
0.2
3
4
0.75
2.15
...
433
4.
Conclusion
In this p a p e r
SATCHMO,
a t h e o r e m p r o v e r b a s e d o n m o d e l g e n e r a t i o n , is p r e s e n t e d
and
e x p e r i e n c e s are d e s c r i b e d . Prolog has b e e n u s e d as a representation l a n g u a g e for expressing p r o b l e m c l a u s e s a s w e l l a s f o r t h e i m p l e m e n t a t i o n of S A T C H M O . T h e a p p r o a c h e x t e n d s P r o l o g w h i l e r e t a i n i n g its e f f i c i e n c y f o r H o r n c l a u s e s a s h a s b e e n d o n e b y S t i c k e l ' s P T T P . T h e a d d i t i o n s we
are
proposing
are,
however,
considerably
different
from
Stickel's.
As
a
consequence,
S A T C H M O c a n b e i m p l e m e n t e d o n t o p of P r o l o g w i t h o u t c a u s i n g t o o s e v e r e i n e f f i c i e n c i e s b y d o i n g so. A s a n e x t e n s i o n of t h e w o r k r e p o r t e d h e r e , w e w o u l d like t o i n v e s t i g a t e m o r e d e e p l y h o w t o b e n e f i t f r o m f u r t h e r c o m p i l a t i o n s of p r o b l e m c l a u s e s a n d h o w t o c o n t r o l t e r m g e n e r a t i o n . S o m e c o n s i d e r a b l e g a i n in e f f i c i e n c y c a n a l s o b e e x p e c t e d f r o m i n v e s t i g a t i o n s in m o r e solutions
to c o n t r o l l i n g
recursive
Prolog-rules. Apart from this, w e w o u l d
sophisticated
like to k n o w
how
S A T C H M O b e h a v e s w h e n i m p l e m e n t e d in u p - t o - d a t e P r o l o g - s y s t e m s . T h e s i m p l i c i t y of its c o d e s h o u l d m a k e it e x t r e m e l y p o r t a b l e . D u e to t h e s p l i t t i n g f e a t u r e e s p e c i a l l y f o r t h c o m i n g
parallel
i m p l e m e n t a t i o n s of P r o l o g s h o u l d b e p r o m i s i n g .
5.
Acknowledgement
W e w o u l d like t o t h a n k H e r v e G a l l a i r e a n d J e a n - M a r i e N i c o l a s as w e l l a s o u r c o l l e a g u e s at E C R C f o r p r o v i d i n g u s w i t h a v e r y s t i m u l a t i n g r e s e a r c h a m b i e n c e . T h e w o r k r e p o r t e d in t h i s article h a s b e n e f i t e d a lot f r o m it. W e a l s o w o u l d like to t h a n k t h e A r g o n n e t e a m f o r t h e i r i n t e r e s t in o u r w o r k a n d their e n c o u r a g e m e n t to present our results to the a u t o m a t e d d e d u c t i o n c o m m u n i t y .
References: [BRY 87]
Bry, F. et. a l . , A Uniform Satisfiability
Approach
in Deductive
to Constraint
Satisfaction
and
Constraint
Databases,
E C R C T e c h n . R e p . K B - 1 6 , 1 9 8 7 (to a p p e a r in P r o c . Int. C o n f . E x t e n d i n g Database Technology E D B T 88) [BUT 86]
B u t l e r , R. et. a l . , Paths to High-Performance Automated Proc. 8th C A D E 1986, Oxford, 1986, 5 8 8 - 5 9 7
[LO 85]
L u s k , E. a n d O v e r b e e k , R., Non-Horn problems, J o u r n a l of A u t o m a t e d R e a s o n i n g 1 ( 1 9 8 5 ) , 1 0 3 - 1 1 4
[MB 87]
M a n t h e y , R. a n d Bry, F., A hyperresolution-based proof procedure and its implementation in PROLOG, P r o c . of G W A I - 8 7 ( 1 1 t h G e r m a n W o r k s h o p o n Artificial I n t e l l i g e n c e ) , G e s e k e , 1 9 8 7 , 2 2 1 - 2 3 0
[McC 86]
M c C u n e , B., A Proof
of a Non-Obvious
Theorem,
Theorem
Proving,
A A R Newsletter N o . 7,
1986, 5 [NIC 79]
N i c o l a s , J . M . , Logic for improving integrity checking Tech. Rep., O N E R A - C E R T , Toulouse, Feb. 1979 (also in A c t a I n f o r m a t i c a 1 8 , 3 , D e c . 1 9 8 2 )
[OHL 85]
O h l b a c h , H . J . a n d S c h m i d t - S c h a u s s , M . , The Lion and the J . of A u t o m a t e d R e a s o n i n g 1 ( 1 9 8 5 ) , 3 2 7 - 3 3 2
[PEL 86]
Pelletier,
F.J.,
Seventy-five
Problems
for
in relational
Testing
databases,
Unicorn,
Automatic
Theorem
434
Provers,
J . of A u t o m a t e d R e a s o n i n g 2 ( 1 9 8 6 ) , 1 9 1 - 2 1 6
[PR 86]
Pelletier, F.J. a n d R u d n i c k i , P., A A R N e w s l e t t e r N o . 6, 1 9 8 6 , 4 - 5
Non-Obviousness,
[ S M U 68]
S m u l l y a n , R., First-Order
[STI 84]
S t i c k e l , M . , A Proiog Technology Theorem Prover, N e w G e n e r a t i o n C o m p u t i n g 2, ( 1 9 8 4 ) , 3 7 1 - 3 8 3
[STI 86]
S t i c k e l , M., Schubert's steamroller problem: formulations J . of A u t o m a t e d R e a s o n i n g 2 ( 1 9 8 6 ) , 8 9 - 1 0 1
[WAL 84]
W a l t h e r , C , A mechanical solution of Schubert's steamroller resolution, P r o c . of A A A I - 8 4 , A u s t i n , T e x a s , 1 9 8 4 , 3 3 0 - 3 3 4 (Revised version in Artificial Intelligence, 26, 1985, 217-224)
[WAL 88]
W a l t h e r , C , An Obvious Solution for a Non-Obvious A A R Newsletter No. 9, J a n . 1988, 4-5
[ W O S 84]
W o s , L. et. a!., Automated
Logic, S p r i n g e r - V e r l a g , 1 9 6 8
Reasoning,
and
Problem,
Prentice Hall, 1984
solutions, by
many-sorted