An Interpreter For The Programming Languages Predicate Logic
چکیده
We d e s c r i b e an I n t e r p r e t e r f o r the programming language p r e d i c a t e l o g i c . Some t o p i c s a r e ; s y n t a x and p r o o f p r o c e d u r e , procedure e v o c a t i o n , f u n c t i o n t r a n s f o r m a t i o n , g o a l v a r i a t i o n and i n t e r a c t i v e c o m p u t a t i o n a l c o n t r o l . I n t r o d u c t i o n The development of programming languages has more and more r e l i e v e d a programmer from machine c o n t r o l and d e t a i l s , g i v i n g him the power of abs t r a c t reasoning and thus helped him to c o n c e n t r a te more on h i s problem. Kowalski [ 8 , 9 ] has c o n v i n c i n g l y argued t h a t p r e d i c a t e l o g i c f o r m a l i z e s a man's thoughts and i s a u s e f u l s i m p l e programming language f o r human problem s o l v i n g . Consequently I t i s d e s i r a b l e t o have p r e d i c a t e l o g i c implemented on machines f o r p r a c t i c a l programming. There i s one i m p l e m e n t a t i o n a t the U n i v e r s i t y o f A i x M a r s e i l l e , PROLOGUE [ 2 ] . At the U n i v e r s i t y of Stockholm we have implemented an i n t e r p r e t e r in LISP 1,6 [ 1 1 ] . Syntax and Proof Procedure The syntax of the language c o n s i s t s of Kowalski's p r o c e d u r a l form [ 7 ] p l u s a c o n t r o l s t r u c t u r e c o n s i s t i n g o f a n o r d e r e d procedure, o r dered procedures and c o m p u t a t i o n a l consequences (Tarnlund [ 1 4 ] ) . The p r o o f procedure is based on Kowalski's c o n n e c t i o n graph system ( 6 ] . Kowalski's procedure form A procedure is the o n l y type of statement in the language. It c o n t a i n s two s p e c i a l cases, a g o a l and an a s s e r t i o n . Two t y p i c a l procedures are Own(x,y) •*• Own ( x , z) t P a r t (y ,z) , which is read "x owns y if t h e r e Is a z such t h a t x owns z and y is a p a r t of z", and D( x , y ) , D ( x , z ) * D(x tw),P(x),M(y,z,w) t which is read "x d i v i d e s y or x d i v i d e s z if t h e r e is a w such t h a t x d i v i d e s w and x is a prime and y z * w". The p a r t to the l e f t of the arrow is c a l l e d procedure name and the p a r t t o the r i g h t i s c a l l e d procedure body c o n s i s t i n g o f procedure calls. A g o a l statement is a procedure w i t h o u t a name e.g., "•Own (John, t y r e ) . An a s s e r t i o n Is a procedure w i t h o u t a body e.g. , P a r t ( t y r e , c a r ) « . A program is a set of procedures connected In a graph depending on how t h e y match each o t h e r . F l g . l . A c o n n e c t i o n graph. Each atom is connected t o a l l o t h e r atoms w i t h the same name o c c u r r i n g on o p p o s i t e s i d e s of the arrows, p r o v i d e d t h a t they can be matched i . e . , u n i f i e d ( 1 2 ) . Recursive p r o cedures are l i n k e d w i t h d o t t e d l i n e s . The c o n n e c t i o n graph is i n d i p e n d e n t of the o r d e r the programmer p r e s e n t s h i s s t a t e m e n t s . Depending on one's programming s t y l e ( p r o b l e m s o l v i n g ) one can combine top-down, m i d d l e o u t and bottom-up programming. The g o a l of the i n t e r p r e t e r i s t o a c t i v a t e l i n k s ( r e s o l v e c o r r e s p o n d i n g atoms) in a way t h a t e v e n t u a l l y leads to the empty p r o cedure D . C o n t r o l s t r u c t u r e The c o n t r o l s t r u c t u r e t r a n s f e r s some d e c i s i o n making r e s p o n s i b i l i t y from the search s t r a tegy to the programmer and makes the d e c i s i o n s exp l i c i t . T h i s i s i l l u s t r a t e d by a program t h a t probes f o r a node to be d e l e t e d in a b i n a r y t r e e such t h a t i t s r e m a i n i n g nodes are s o r t e d when t r a v e rsed i n s y m m e t r i c a l o r d e r . The program i s based on a d e l e t e a l g o r i t h m in Knuth [ 5 ] . We use Knuth's zodiac example (sec. 6.2.2) to d e l e t e the node CAPRICORN from a b i n a r y t r e e . The i n i t i a l g o a l i s Delete*(CAPRICORN). (1) Suppose t h a t we have the b i n a r y t r e e in a data base A ( t r e e ) , (2) where A is an a r b i t r a r y p r e d i c a t e whose argument t r e e i s equal t o