• No results found

An approach to declarative programming based on a rewriting logic

N/A
N/A
Protected

Academic year: 2021

Share "An approach to declarative programming based on a rewriting logic"

Copied!
41
0
0

Loading.... (view fulltext now)

Full text

(1)

ELSEVIER The Journal of Logic Programming 40 { 1999) 47 87 THE.IOURN.~, L OF ~ ' ~ A M M ~ N G

A n a p p r o a c h to declarative p r o g r a m m i n g b a s e d

o n a rewriting logic

J.C. G o n z d l e z - M o r e n o , M . T . H o r t a l f i - G o n z d l e z ,

F.J. L d p e z - F r a g u a s , M . R o d r f g u e z - A r t a l e j o *

Dpto. tie Sistemas h!/brma~, y Prog. Facultad de ~$httematicas. Unirersidad Comph¢tt'nse de ~/htdrid, At'. Comphttense sht. 28040 ~htdrit~ Spain

Received 15 August 1996: received in revised lbrm 6 November 1997: accepted 31 July 1998

Abstract

We p r o p o s e an a p p r o a c h to declarative p r o g r a m m i n g which integrates the functional a n d relationa! p a r a d i g m s by taking possibly non-deterministic lazy f u n c t i o n s as the f u n d a m e n t a l notion. Classical e q u a t i o n a l logic d o e s not s u p p l y a suitable semantics in a natural way. There- fore, we suggest to view p r o g r a m s as theories in a c o n s t r u c t o r - b a s e d c o n d i t i o n a l rewriting log- ic. W e present p r o o f calculi a n d a m o d e l t h e o r y for this logic, a n d we p r o v e the existence o f free term m o d e l s which p r o v i d e an a d e q u a t e intended semantics for programs. W e d e v e l o p a s o u n d a n d strongly c o m p l e t e lazy n a r r o w i n g calculus, which is able to s u p p o r t sharing w i t h o u t the technical o v e r h e a d o f g r a p h ,cwriting a n d to identify safe cases for e a g e r variable elimina- tion. M o r e o v e r , we give s o m e illustrative p r o g r a m m i n g examples, a n d we discuss the imple- mentability o f o u r a p p r o a c h . © 1999 Elsevier Science Inc. All rights reserved.

Keywords." Declarative p r o g r a m m i n g : N o n - d e t e r m i n i s t i c functions: C o n s t r u c t o r - b a s e d rewrit- ing logic; Lazy n a r r o w i n g

I. I n t r o d u c t i o n T h e i n t e r e s t in c o m b i n i n l z d i f f e r e n t d e c l a r a t i v e p r o g r a m m i n g p a r a d i g m s , e s p e - c i a l l y l h n c t i o n a i a n d l o g i c p r o g r a m n a i n g , hlt~ g r o w n o v e r t h e last d e c a d e ; s e e R e f . [23] f o r a r e c e n t s u r v e y . T h e o p e r a t i o n a l s e m a n t i c s o f m a n y f u n c t i o n a l l o g i c l a n g u a g e s is b a s e d o n s o - c a l l e d n a r r o w i n g , w h i c h c o m b i n e s t h e b a s i c e x e c u t i o n m e c h a n i s m s o f f u n c t i o n a l a n d l o g i c l a n g u a g e s , n a m e l y r e w r i t i ~ g a n d i t n i f i c a t i o n . S e v e r a l m o d e r n f u n c t i o n a l l a n g u a g e s , a s e.g. H a s k e l l [44], a l l o w n o n - s t r i c t f u n c -

"Corresponding author. Tel.: +34 91 394 4512: fax: +34 91 394 4602: e-mail: mario@sip.ucm.es. i This paper is a substantially extended and revised version of Ref. [21]. The authors have been partially supported by the spanish CICYT (project TIC 95-0433-C03-01 - C P D " ) and by the EU {ESPRIT BR Working Group EP 22457 "'CCLII"L

0743-1066/99/$ - see front matter © 1999 Elsevier Science Inc. All rights reserved. P I I : S 0 7 4 3 - 1 0 6 6 ( 9 8 J 1 0 0 2 9 - 8

(2)

48 J.c. Gonz(dez-Moreno et aL I J. Logic Progrannning 40 (1999) 4,z4t7

tions, t h a t m a y return a defined result even if s o m e a r g u m e n t is n o t defined. T h e o p e r a t i o n a l s e m a n t i c s o f non-strict f u n c t i o n a l l a n g u a g e s relies o n a lazy r e d u c t i o n strategy, r o u g h l y e q u i v a l e n t to o u t e r m o s t r e w r i t i n g (see Ref. [9]), w h i c h d e l a y s the e v a l u a t i o n o f f u n c t i o n a r g u m e n t s as m u c h as possible. T h i s feature h a s been a d o p t - ed b y s o m e f u n c t i o n a l logic languages, such as K - L E A F [15] a n d B A B E L [42]. T h e s e l a n g u a g e s use so-called constructor-based term rewriting systems to model the b e h a v i o u r o f n o n - s t r i c t functions. A c o n s t r u c t o r - b a s e d term r e w r i t i n g s y s t e m classifies o p e r a t i o n s y m b o l s in t w o categories: defined functions, w h o s e b e h a v i o u r is given b y rewrite rules, a n d conslrzcctors, w h i c h are used to represent c o m p u t e d values as c o n s t r u c t o r terms. A n o t h e r special feature o f lazy f u n c t i o n a l logic lan- g u a g e s is the d i s t i n c t i o n b e t w e e n o r d i n a r y e q u a l i t y e = e' a n d strict equality e = = e'. Strict e q u a l i t y m e a n s t h a t e a n d e' c a n be reduced to the same c o n s t r u c t o r t e r m (a finite, t o t a l l y a e f i n e d value), while o r d i n a r y e q u a l i t y does n o t exclude the p o s s i b i l i t y t h a t the c o m m o n v a l u e o f e a n d e' m a y be infinite a n d / o r p a r t i a l l y de- fined. T y p i c a l l y , strict e q u a t i o n s are used for b u i l d i n g goals a n d c o n d i t i o n s o f con- d i t i o n a l rewrite rules.

O n the o t h e r h a n d , the usefulness o f n o n - d e t e r m i n i s t i c o p e r a t i o n s for a l g e b r a i c specification a n d prograrr,_,.ning h a s been a d v o c a t e d by H u s s m a n n [27,28], w h o p r o v i d e s several e x a m p l e s ( i n c l u d i n g the specification o f s e m a n t i c s for c o m m u - n i c a t i n g s e q u e n t i a l processes) a n d leaves as an i n t e r e s t i n g o p e n q u e s t i o n 'the integra-

tion o f non-strict operations (at least non-strict constructors)' (see Ref. [28], Section 8.2). In this paper, we p r o p o s e a quite general a p p r o a c h to d e c l a r a t i v e p r o g r a m m i n g , w h e r e p o s s i b l y n o n - d e t e r m i n i s t i c f u n c t i o n s are t a k e n as the f u n d a m e n t a l n o t i o n . T h e m a i n idea is to keep c o n s t r u c t o r s d e t e r m i n i s t i c , a n d to allow defined f u n c t i o n s to re- t u r n m o r e t h a n o n e c o n s t r u c t o r t e r m as a c o m p u t e d result, for fixed c o n s t r u c t o r t e r m s given as a r g u m e n t s . F o r instance, the f o l l o w i n g c o n s t r u c t o r - b a s e d rewrite rules define a f u n c t i o n m e r g e t h a t merges two given lists n o n - d e t e r m i n i s t i c a l l y in all possible ways. W e use P r o l o g ' s s y n t a x for the list c o n s t r u c t o r s .

m e r g e ( [ ] , Y s ) m e r g e ( [ X [ X s ] , [ ] ) m e r g e ( [ X I X s ] , [Y ! Y s ] ) m e r g e ( [ X [ X s ] , [Y I Y s ] ) Y s [ x I x s ] [X I m e r g e ( X s , [Y [ Ys])] [Y [ m e r g e ( [ X [ Xs], Ys)]

G i v e n this definition, the f u n c t i o n call m e r g e ( [ 1 ] , [ 2 , 3 ] ) is expected ~o r e t u r n three possible results, n a m e l y [ i , 2, 3 ] , [ 2, 1, 3 ] a n d [ 2 , 3 , 1 ]. M o r e concretely, we expect a b a c k t r a c k i n g m e c h a n i s m to search for the results a n d deliver t h e m o n e after the o t h e r , as in typical P r o l o g systems. N o t e t h a t search is possible in o u r set- ting even for g r o u n d goak,. But. as we will see s o o n , goals i n c l u d i n g logic variables are also allowed.

O u r a p p r o a c h gives a positive a n s w e r to H u s s m a n n ' s q u e s t i o n , since b o t h o u r c o n s t r u c t o r s a n d o u r defined f u n c t i o n s have a n o n - s t r i c t semantics. D e t e r m i n i s t i c f u n c t i o n s are o f c o u r s e possible as a p a r t i c u l a r case. T h e r e f o r e , o u r f r a m e w o r k c a n exploit k n o w n a d v a n t a g e s o f d e t e r m i n i s m , such as d y n a m i c cut [33] or simplifi- c a t i o n [24,25]. R e l a t i o n s c a n be also m o d e l l e d as b o o l e a n functions. H o w e v e r , the m a i n r e a s o n for o u r choice o f f u n c t i o n s as the f u n d a m e n t a l n o t i o n is t h a t f u n c t i o n s h a v e o f t e n a better o p e r a t i o n a l b e h a v i o u r , thus h e l p i n g to a v o i d d i v e r g e n t c o m p u t a - tions or to detect failure ear'ier. In the case o f d e t e r m i n i s t i c functions, these benefits

(3)

J. C. Gon~_~lez-Aloreno et al. I J. Logic Programming 40 ( 1 9 9 9 ) 4 7 - 8 7 4 9

c a n be o b t a i n e d t h a n k s to d e t e r m i n i s t i c s i m p l i f i c a t i o n b y rewriting, as s b o w n in Refs. [22,23]. In the case o f n o n - d e t e r m i n i s t i c f u n c t i o n s , s i m i l a r benefits a r e still p o s s i b l e t h a n k s to lazy e v a l u a t i o n . T h i s idea h a s been a l r e a d y a d v o c a t e d in Ref. [1]; we will s h o w t w o c o n c r e t e e x a m p l e s in Section 2.

T e c h n i c a l l y , n o n - d e t e r m i n i s t i c f u n c t i o n s c a n be m o d e l l e d b y m e a n s o f n o n - c o n f l u - e n t c o n s t r u c t o r - b a s e d t e r m r e w r i t i n g s y s t e m s , w h e r e a given t e r m m a y be r e w r i t t e n to c o n s t r u c t o r t e r m s in m o r e t h a n o n e w a y . T o e x p r e s s g o a l s a n d c o n d i t i o n s o f c o n - d i t i o n a l r e w r i t e rules, strict e q u a l i t y is r e p l a c e d b y t h e m o r e g e n e r a l n o t i o n

ofjoin-

ability,:

t w o term~ a , b are r e g a r d e d as j o i n a b l e (in s y m b o l s , a. ~-~ b) iff t h e y c a n be r e w r i t t e n t o a c o m m o n c o n s t r u c t o r term. F o r i n s t a n c e , a p o s s i b l e g o a l for t h e m e r g e f u n c t i o n is m e r g e (X-q, Y s ) t ~ [A, B] f o r w h i c h the f o l l o w i n g f..,?~lr a n s w e r s c a n be c o m p u t e d : X s = [], Y s = [ A , B ] X s = [ A , B ] , Y s = [] X s = [ A ] , Y s = [B] x s = [B], Y s = [A]

N o t e t h a t we are able to c o m p u t e g e n e r a l s o l u t i o n s for t h i s goal, w h i l e m o s t pre- v i o u s a p p r o a c h e s to strict e q u a l i t y [15,42,4,37] a t t e m p t a n ( o f t e n infinite) e n u m e r - a t i o n o f g r o u n d s o l u t i o n s . W e h a v e d e s i g n e d a

la-_y narrowing colcuhts

t h a t is s o u n d a n d c o m p l e t e f o r s o l v i n g a r b i t r a r y goals. In c o n t r a s t to o t h e r iazy n a r r o w i n g calculi, as e.g. t h o s e in Refs. [15,42,4,24,37], c o m p l e t e n e s s o f o u r c a l c u l u s h o l d s w i t h o u t a n y c o n f l u e n c e o r n o n - a m b i g u i t y h y p o t h e s i s , even for c o n d i t i o n a l rewrite s y s t e m s w i t h e x t r a v a r i a b l e s in the c o n d i t i o n s , w h i c h m a y c a u s e i n c o m p l e t e n e s s o f n a r r o w i n g w.r.t, the s e m a n t i c s o f e q u a t i o n a l logic [40]. P r e v i o u s w o r k s [15.42,19] h a v e a l r e a d y s h o w n h o w to o v e r c o m e s u c h i n c o m p l e t e n e s s p r o b l e m s by a d o p t i n g the r e s t r i c t i o n to left-linear, c o n s t r u c t o r - b a s e d rewrite rules ( w h i c h a r e expressive e n o u g h f o r p r o g r a m m i n g ) a n d r e p l a c i n g a l g e b r a i c e q u a l i t y in g o a l s a n d c o n d i t i o n s b y strict e q u a l i t y . A s hove! p o i n t s w.r.t, these p a p e r s , we a l l o w n o n - d e t e r m i n i s m a n d we ctabora:.e a !og.:cai f r a m e w o r k , so-called

constructor-based rewriting logic,

w h i c h p r o v i d e s e .'.k:Jarative a n d m o d e l - t h e o r e t i c s e m a n t i c s for p r o g r a m s . In p a r - ticular, t h e i n t e n d e d se~nn.-'ics o f a n a r b i t r a r y p r o g r a m is given b y a free t e r m m o d e l .

T h e p r e s e n c e o f n o n - d e t e r m i n i s m in p r o g r a m m i n g l a n g u a g e s raises s e m a n t i c p r o b l e m s t h a t are n o t a l w a y s well u n d e r s t o o d . M a n y different s e m a n t i c s are p o s s i b l e a c c o r d i n g t o the d e c i s i o n s t a k e n for several i n d e p e n d e n t issues, i n c l u d i n g :

* s t r i c t / n o n - s t r i c t f u n c t i o n s ;

e c a l l - t i m e c h o i c e / r u n - t i m e c h o i c e for p a r a m e t e r passing;

- a n g e l i c / d e m o n i c / e r r a t i c view o f n o n - d e t e r m i n i s t i c choices.

A nice d i s c u s s i o n o f t h e s e q u e s t i o n s c a n be f o u n d in Ref. [49]. T h e s e m a n t i c o p t i o n in t h i s p a p e r c o r r e s p o n d s to

angelic non-determ;niam

w i t h

call-time choice

for

non-strict

f u n c t i o n s . T h e ' a n g e l i c ' view m e a n s , i n t m t i v e l y , t h a t the results o f all possible c o m - p u t a t i o n s {due to different n o n - d e t e r m i n i s t i c choices) are collected by t h e s e m a n t i c s , even i f t h e p o s s i b i l i t y o f infinite c o m p u t a t i o n s is n o t e x c l u d e d . T e c h n i c a l l y , a n g e l i c non-dete~':ninism c o r r e s p o n d s tc, t h e c h o i c e o f o n e o f the t h r e e m a i n p o w e r d o m a i n c o n s t r u c t i o n s , so-called

Hoare's powerdomain

[52]. T h e "call-time choice" view, a l s o a d o p t e d b y H u s s m a n n ha Refs. [27,28], h a s the f o l l o w i n g i n t u i t i v e m e a n i n g : g i v e n

(4)

50 J . c . Gonzhh, z-Moreno et al. I J. Logk" Programmi1,g 40 (1999) 4 7 - 8 7 a f u n c t i o n call f ( e l . . . e , , ) , o n e c h o o s e s s o m e fixed ( p o s s i b l y p a r t i a l ) v a l u e f o r e a c h o f t h e a c t u a l p a r a m e t e r s e i b e f o r e a p p l y i n g t h e r e w r i t e r u l e s t h a t d e f i n e f ' s b e h a v - i o u r . T h i s o p t i o n s e e m s t o b e t h e m o s t n a t u r a l w a y t o c o m b i n e n o n - d e t e r m i n i s t i c c h o i c e w i t h p a r a m e t e r p a s s i n g a n d it m u s t n o t b e c o n f u s e d w i t h s t r i c t n e s s , s i n c e t h e c o m p l e t e e v a l u a t i o n o f t h e t e r m s ~ t o c o n s t r u c t o r t e r m s in n o r m a l f o r m is n o t r e q u i r e d . T h e u s u a l n o t i o n o f r e w r i t i n g , h o w e v e r , is n o t s o u n d w . r . t , c a l l - t i m e c h o i c e s e m a n t i c s . -" T h e f o l l o w i n g e x a m p l e , i n s p i r e d b y R e f . [27], will c l a r i f y t h i s p o i n t . LeL u s c o n s i d e r t h e f o l l o w i n g r e w r i t e r u l e s : c o i n ~ 0 c o i n --. I d o u b l e ( X ) ~ X + X t o g e t h e r w i t h s u i t a b l e r u l e s f o r t h e a d d i t i o n o p e r a t i o n + . A c c o r d i n g t o c a l l - t i m e c h o i c e s e m a n t i c s , t h e t e r m d o u b l e ( c o i n ) s h o u l d h a v e 0 a n d p, b u t n o t 1, a s p o s - s i b l e v a l u e s . U n f o r t u n a t e l y , a n o u t e r m o s t r e w r i t i n g d e r i v a t i o n is a b l e t o c o m p u t e t h e i n c o r r e c t r e s u l t l : "2 ~ u b l e ( c o i n ) - ~ c o i n + c o i n - ~ 0 + c o i n --+ 0 + I ~ 1 I n n e r m o s t r e w r i t i n g is s o u n d w . r . t , c a l l - t i m e c h o i c e , bt, t it is n o t c o m p l e t e w . r . t , t h e s e m a n t i c s o f n o n - s t r i c t f u n c t i o n s . T h e r e f o r e , w e a d o p t a n o t h e r s o l u t i o n s u g g e s t e d in R e f . [28]: all t h o s e v a r i a b l e s t h a t h a v e m o r e t h a n o n e o c c u r r e n c e in t h e r i g h t - h a n d s i d e o f s o m e r e w r i t e r u l e ( s u c h a s X in t h e r e w r i t e r u l e f o r d o u b l e ) m u s t b e s h a r e d . I n R e f s . [28,47] s h a r i n g is r e a l i z e d b y p e r f o r m i n g r e v c r i t i n g a n d n a r r o w i n g o v e r t e r m g r ~ t p h s [8], w h i c h l e a d s t o a s i g n i f i c a n t t e c h n i c a l o v e r h e a d . I n o u r s e t t i n g , t h e e f f e c t o f s h a r i n g is b u i l t - i n w i t h i n o u r r e w r i t i n g a n d n a r r o w i n g c a l c u l i , in s u c h a w a y t h a t t e r m g r a p h s c a n b e a v o i d e d . F o r ti~c s~ake o f s i m p l i c i t y , w e r e s t r i c t o u r p r e s e n t a t i o n t o t h e u n s o r t e d c a s e , b u t all o u r r e s u l t s c a n b e e x t e n d e d t o m a n y - s o r t e d s i g n a t u r e s , o r e v e n t o t y p e d l a n - g u a g e s w i t h p a r a m e t r i c p o l y m o r p h i s m : s e e R e f s . [6,7]. T h e p a p e r is o r g a n i z e d a s f o l l o w s : in t h e n e x t s e c t i o n w e g i v e f u r t h e r e x a m p l e s a t t e m p t i n g t o m o t i v a t e t h e i n t e r e s t o f o u r a p p r o a c h . I n S e c t i o n 3 w e r e c a l l s o m e t e c h n i c a l p r e l i m i n a r i e s . I n S e c t i o n 4 w e i n t r o d u c e a C o n s t r u c t o r - b a s e d c o n d i t i o n a l R e W r i t i n g L o g i c ( C R W L J t h a t f o r m a l i z e s t h e n o n - c l a s s i c a l v e r s i o n o f r e w r i t i n g n e e d e d in o u r s e t t i n g . S e c - t i o n 5 is c o n c e r n e d w i t h t h e m o d e l - t h e o r e t i c s e m a n t i c s f o r C R W L p r o g r a m s ; t h i s i n c l u d e s t h e e x i s t e n c e o f f r e e t e r m m o d e l s , w h i c h a r e c l o s e l y r e l a t e d t o C R W L - p r o v a b i l i t y . I n S e c t i o n 6 w e p r e s e n t a C o n s t r u c t o r - b a s e d L a z y N a r r o w i n g C a l c u l u s ( C L N C ) . I n S e c t i o n 7 w e e s t a b l i s h t h e s o u n d n e s s a n d s t r o n g c o m p l e t e n e s s o f C L N C w . r . t , t h e m o d e l - t h e o r e t i c s e m a n t i c s o f C R W L . I n S e c t i o n 8 w e d i s c u s s p o s s i b l e r e f i n e m e n t s o f C L N C , b a s e d o n d e m a n d - d r i v e n s t r a t e g i e s , t h a t c a n b e u s e d t o b u i l d e f f i c i e n t i m p l e m e n t a t i o n s . F i n a l l y , in S e c t i o n 9 w e s u m m a r i z e o u r c o n c l u s i o n s .

2 This makes an important difference between our setting and a classical paper by Boudo| [10l, which is based on t:lassical rewriting. Moreover. Boudol's work does not dea~ ~,ith nut'rowing.

(5)

J. ( : (hm=6h~: - M¢,r~'tlo et al. t J. Logi~ ~ P r o g r a m m i n g 40 ~ i 909) 4 7 - 8 7 5 !

2. Motivating examples

N o n - d e t e r m i n i s m is o n e o f the m a i n n o v e l t i e s o f o u r p r o p o s a l . T h e r e f o r e , w e in- c l u d e h e r e t w o small C R W L - p r o g r a m s a t t e m p t i n g to s h o w h o w (lazy) n o n - d e t e r m i n - istic f u n c t i o n s c o n t r i b u t e to a m o r e clear, c o n c i s e a n d t h u s p r o d u c t i v e d e c l a r a t i v e p r o g r a m m i n g style. F o r a d i s c u s s i o n o f t h e g e n e r a l a d v a n t a g e s o f f u n c t i o n a l logic p r o g r a m m i n g w,r.t, r e l a t i o n a l logic p r o g r a m m i n g , t h e r e a d e r is r e f e r r e d to Ref. [23]. In the first e x a m p l e w e p r o g r a m a small p a r s e r f o r a g r a m m a r o f s i m p l e a r i t h m e t i c e x p r e s s i o n s . In the s e c o n d o n e w e s h o w h o w a t y p i c a l l y inelficient " g e n e r a t e a n d test" logic p r o g r a m c~,n be c o n v e r t e d i n t o a m o r e efficient f u n c t i o n a l logic p r o g r a m b y ex- p l o i t i n g the c o m b i n a t i o n o f n e n - d e t e r m i n i s t i e f u n c t i o n s a n d lazy e v a l u a t i o n . B o t h e x a m p l e s use a h o p e f u l l y s e l l - e x p l a n a t o r y s y n t a x for c o n s t r u c t o r - b a s e d , c o n d i t i o n a l r e w r i t e rules, w h i c h is f o n ~ a l l y e x p l a i n e d in S e c t i o n 4.

2 . 1 . . 4 p ~ t r . s e r

B N F - d e s c r i p t i o n s o f g r a m m a r s h a v e m o s t o f the times s o m e d e g r e e o f n o n - d e t e r - m i n i s m , b e c a u s e o f the p r e s e n c e o f different a l t e r n a t i v e s for the s a m e n o n - t e r m i n a l s y m b o l . F o r this r e a s o n , t h e task o f vcriting a p a r s e r is simplified if a l a n g u a g e s u p - p o r t i n g s o m e k i n d o f n o n - d e t e r m i n i s t i c c o m p u t a t i o n s is used. T h i s h a p p e n s , for in- s t a n c e , w i t h logic p r o g r a m m i n g , for w h i c h t h e w r i t i n g o f a p a r s e r is o n e o f t h e nicest e x a m p l e s o f d e c l a r a t i v e p r o g r a m m i n g . T h e s t a n d a r d t r a n s l a t i o n o f a B N F - r u l e f o r a n o n - t e r m i n a l s y m b o l s i n t o a c l a u s e for a p r e d i c a t e .~(ht, O t t l ) (see, e.g., Ref. [50]) gives as result a logic p r o g r a m w h i c h is q u i t e s i m i l a r to the o r i g i n a l B N F - d e s c r i p t i o n . T h e s i m i l a r i t y is e v e n i n c r e a s e d w i t h t h e h i d i n g o f the a r g u m e n t s El, O u t by m e a n s o f t h e f o r m a l i s m o f D C G ' s ( d e t i n i t e c l a u s e g r a m m a r s ) , b u t in this ease a p r e p r o c e s s i n g

3 is n e e d e d for o b t a i n i n g a n e x e c u t a b l e p r o g r a m .

In o u r setting, the use o f n o n - d e t e r m i n i s t i c f u n c t i o n s a l l o w s a f o r m u l a t i o n o f BN F - r u l e s e v e n m o r e n a t u r a l t h a n in the c a s e o f logic p r o g r a m s : n o e x t r a a r g u m e n t s n o r p r e p r o e e s s i n g is n e e d e d . As a c o n c r e t e s i t u a t i o n w e c o n s i d e r a g r a m m a r for sim- ple a r i t h m e t i c e x p r e s s i o n s ( u s i n g o n l y 0 a n d !, for f u r t h e r s i m p l i c i t y ) , g i v e n by t h e f o l l o w i n g B N F - r u l e s ( t e r n , . , l a l s a r e enclc~sed by "" a n d [ i n d i c a t e s a n o n - d e t e r m i n i s t i c a l t e r n a t i v e ) : e A ' p r e s . ~ i o l l . ' . " - l¢'rpll e_vpre.s'.~'ion . ' : = t e r m ( " + ' 1 "--') e.xl~r¢'.~'sion t e r m "" ~ / i t c l o r t e r m "" = . t k t c t o r ( ' * ' l "/" ) term . / a c t o r .'.-= "0'1 "1" . l k t c t o r .'.'~ ' ( "e.vpres.~'ion" )" F o r w r i t i n g a C R W L - p a r s e r f o r this g r a m m a r , we a s s u m e t h a t t h e i n p u t is g i v e n in t h e f o r m o f a list o f t o k e , t s o f the f o r m O, l , + , - , * , / , ( , ) ( w h i c h a r e all

(6)

52 J . C Gonchlez-Moreno et al. I J. Logic + Programmbtg 40 (1999) 47-87

c o n s t a n t s , i.e., c o n s t r u c t o r s o f arity 0). W e m o d e l e a c h n o n - t e r m i n a l s by a n o n - d e - t e r m i n i s t i c f u n c t i o n ( o f arity O) r e t u r n i n g a piece o f i n p u t (a list o f tokens). T h e set o f possible values to w h i c h s reduces is the set o f lists o f t o k e n s r e c o g n i z e d by s. F o r e x p r e s s i n g a l t e r n a t i v e s we i n t r o d u c e the n o n - d e t e r m i n i s t i c f u n c t i o n ' p a r excellence' / / , used in infix n o t a t i o n 4 a n d d e f i n e d by the rules:

X / / Y - * X X / / Y - ~ Y

S e q u e n c i n g o f s y m b o l s in r i g h t - h a n d sides o f B N F - r u l e s is e,,:oressed by m e a n s o f list c o n c a t e n a t i o n , w h i c h is d e f i n e d as a f u n c t i o n + + (used in infix n o t a t i o n , a n d associ- a t i n g to the right) w i t h rules:

[ ] -H- Y s -~ Y s

[X I Xs] -n-Ys -~ [X 1 X s q + Y s ]

A c c , , r d i n g to this, termiffals m u s t a p p e a r as an explicit list o f t o k e n s (the s a m e h a p - p e n s in D C G ' s ) . This results in the f o l l o w i n g C R W L - r u l e s for the g r a m m a r : e x p r e s s i o n -~ t e r m e x p r e s s i o n -~ t e r m q + [ + / / - - ] ~ e x p r e s s i o n t e r m ~ f a c t o r - t e r m --, f a c t o r q q - [ * / / /1 q + t e r m f a c t o r -~ [0//I] f a e t o r -* [(]+b e x p r e s s i onq-b[)]

G i v e n this p r o g r a m , e x p r e s s i o n yields all t h e e x p r e s s i o n s a c c e p t e d by the g r a m - m a r (as t h e results o f a l t e r n a t i v e c o m p u t a t i o n s ) . T h e r e f o r e , we c a n solve a variety o f goals, as e.g.

,, t o k e n L i s t t ~ e x p r e s s i o n , w h e r e t o k e n L i s t is a n y c o n c r e t e list o f tokens. T h i s goal will succeed if t o k e n L i s t r e p r e s e n t s a c o r r e c t a r i t h m e t i c expression, a c c e p t e d by t h e g r a m m a r :

• [ T t , W2, T3, T4, Ts, T6, ' I ' 7 ] t><l e x p r e s s i o n , w h e r e T i a r e logic variables. This goal will h a v e several s o l u t i o n s , representLng all the w e l l - f o r m e d a r i t h m e t i c expres- sions that c a n be built w i t h seven t o k e n s .

2 . 2 . P e r m u t a t i o n s o r t

A q u i t e usual e x a m p l e o f a very concise, descriptive, but inefficient logic p r o g r a m is p e r m u t a t i o n s o r t : the list L' is t h e result o f s o r t i n g L if L' is a p e r m u t a t i o n o f L a n d

(7)

J.C. Gon=iilez-Moreno et a L I J. Logic Programming 40 (1999) 4.7-87 53 L' is sorted. T h e m o s t i m m e d i a t e f o r m u l a t i o n o f t h i s idea l e a d s to t h e f o l l o w i n g n a i v e ' g e n e r a t e a n d test' logic p r o g r a m :

permutation_sort(L,L')

:- permute(L,L'), sorted.(L').

w h e r e

p e r m u t e

a n d

s o r t e d

are defined in t h e u s u a l w a y .

O f c o u r s e t h i s is n o t a g o o d m e t h o d f o r s o r t i n g lists, b u t t h e i n t e r e s t i n g p o i n t to discuss h e r e is the r e a s o n o f its e x t r e m e inefficiency w h e n t h e p r o g r a m is e x e c u t e d u n d e r P r o l o g ' s s t a n d a r d c o m p u t a t i o n rule: e v e r y c a n d i d a t e s o l u t i o n L' is c o m p l e t e l y g e n e r a t e d b e f o r e it is tested. A n e x t e n s i o n o f P r o l o g ' s c o m p u t a t i o n m o d e l b y a co- r o u t i n i n g m e c h a n i s m [43] h a s b e e n p r o p o s e d to solve this p r o b l e m . T h e c o - r o u t i n i n g a p p r o a c h r e q u i r e s t h e explicit i n t r o d u c t i o n o f ' w a i t ' d e c l a r a t i o n s for s o m e p r e d i - cates.

O n the o t h e r h a n d , in o r d e r to solve generat.e-and-test p r o b l e m s in a lazy f u n c - t i o n a l l a n g u a g e ( w h e r e t h e r e is n c b u i l t - i n s e a r c h f o r s o l u t i o n s ) , o n e w o u l d t y p i c a l l y f o l l o w t h e 'list o f successes" a p p r o a c h [5 ! ]: g e n e r a t e t h e list o f all c a n d i d a t e s o l u t i o n s (all p e r m u t a t i o n s , in t h i s case) a n d filter it b y m e a n s o f t h e tester. A l t h o u g h lazy eval- u a t i o n e n s u r e s t h a t the list o f c a n d i d a t e s is g e n e r a t e d o n l y to t h e e x t e n t r e q u i r e d b y t h e tester ( w h i c h c a n reject a p a r t i a l l y g e n e r a t e d s o l u t i o n ) , in a n y c a s e it c a n be a v e r y l a r g e s t r u c t u r e . Moreover.. s o m e special l a n g u a g e c o n s t r u c t i o n s , s u c h as l i s t c o m p r e - henv,fon [9], a r e u s u a l l y n e e d e d to p r o g r a m t h e g e n e r a t i o n o f t h e c a n d i d a t e s " list in a d e c i a r , , t i v e l y n e a t w a y .

In o u r setting, we c a n use a n o n - d e t e r m i n i s t i c f u n c t i o n to d e s c r i b e the g e n e r a , I o n o f c a n d i d a t e s o l u t i o n s (i.e., p e r m u t a t i o n s ) in a c o n c i s e a n d d e c l a r a t i v e w a y . Since c a n d i d a t e s o l u t i o n s a r e g e n e r a t e d o n e by one, we c a n a v o i d t h e c o m p u t a t i o n o f a bigger s t r u c t u r e ( n a m e l y , the list o f all c a n d i d a t e s ) w i t h o u t loss o f c o m p l e t e n e s s . A t tht: s a m e time, we a v o i d the inefficiency o f t h e n a i v e logic p r o g r a m , b e c a u s e l a z y e v a l u a t i o n will e n s u r e t h a t t h e g e n e r a t i o n o f e a c h p a r t i c u l a r p e r m u t a t i o n will be in- t e r r u p t e d as s o o n as s o r t e d recognizes t h a t it c a n n o t lead to a n o r d e r e d list. T h i s c o m b i n a t i o n o f a lazy, n o n - d e t e r m i n i s t i c g e n e r a t o r a n d a lazy tester c a n be d e s c r i b e d as t h e "lazy g e n e r a t e a n d test" a p p r o a c h .

M o r e precisely, o u r g e n e r a t o r p e r m u t e is defined as follows:

permute([ ])

permute([X I

Xs])

insert(X, Ys)

insert(X, [Y I Ys])

-~ insert(X, permute(Xs))

-~ [ X i Y s ]

-~ [Yl

insert(X, Ys)]

N o t e t h a t

p e r m u t e

is a non-determini.~tic f a n c t i o , , d u e to t h e a u x i l i a r y f u n c t i o n i n s e r t . T o e a c h o f t h e p e r m u t a t i o n s p r o d u c e d b y p e r m u t e ( L ) , s a y L', we w a n t to a p p l y the test s o r t e d ( L ' ) a n d r e t u r n L' as final result in case o f suc- cess. I f t h e test fails ( r e m e m b e r : this m a y h a p p e n e v e n if p e r m u t e ( L ) h a s been o n l y p a r t i a l l y e v a l u a t e d ) this p a r t i c u l a r c o m p u t a t i o n fails, a n d a n o t h e r p o s s i b l e v a l u e o f p e r m u t e ( L ) m u s t be tried. U s i n g s o m e k i n d o f C R W L - p s e u d o c o d e w i t h a " w h e r e - c o n s t r u c t i o n " t y p i c a l o f f u n c t i o n a l p r o g r a m m i n g , we c o u l d t h e n write:

(8)

54 J.C. Gon:&le---Morel~o et aL I J. Logic Programming 40 (1909) 47-87 I n t h e f o l l o w i n g t r u e C R W L - p r o g r a m w e 'lift" t h e ~ w h e r e - c o n s t r u c t i o n " b y m e a n s o f a n a u x i l i a r y f u n c t i o n c h e c k : s o r t ( L ) --+ c h e c k ( p e r m u t e ( L ) ) c h e c k ( L ' ) -+ L ' ~ s o r t e d ( L ' ) ~ t r u e T h e d e f i n i t i o n o f t h e t e s t e r s o r t e d is t h e n a t u r a l o n e : if w e a s s u m e t h a t lists c o n s i s t o f n a t u r a l n u m b e r s r e p r e s e n t e d b y m e a n s o f t h e c o n s t r u c t o r s z e r o , s u e , t h e n w e c a n d e f i n e : s o r t e d ( [ ] ) s o r t ed([X]) s o r t e d ( I X , X' I Xs]) l e q ( z e r o ~ Y) l e q ( s u c ( X ) , z e r o ) l e q ( s u c ( X ) , s u c ( Y ) ) --~ t r u e -~ t r u e --+ t r u e ~ l e q ( X , X') I><I t r u e , s o r t e d ( [ X ' I Xs]) ~ t r u e --. t r u e -~ f a l s e --, l e q ( X , Y) T h i s c o m p l e t e s t h e p r o g r a m . N o t e t h a t c a l l - t i m e c h o i c e is e s s e n t i a l f o r its c o r r e c t be- h a v i o u r . M o r e p r e c i s e l y , s i n c e s o r t ( L ) c a l l s c h e c k ( p e r m u t e ( L ) ~ , c a l l - t i m e c h o i c e is n e e d e d t o e n s u r e t h a t b o t h o c c u r r e n c e s o f L' in t h e rigP, t - h a n d s i d e o f t h e r e w r i t e r u l e f o r c h e e k r e f e r t o t h e s a m e p e r m u t a t i o n o f L. T o s o r t a n y g i v e n c o n c r e t e list list, it is n o w s u f f i c i e n t t o s o l v e s o r t ( l i s t ) ~ a 8 o r t e d L i s t , w h i c h w i l l s u c c e e d a n d b i n d t h e l o g i c v a r i a b l e 8 o r t e d L i s t t o t h e d e s i r e d r e s u l t . N o t e t h a t t h e t e c h n i q u e d e s c r i b e d in t h i s s u b s e c t i o n c a n b e a p p l i e d t o a n y g e n e r - a t e a n d test p r o b l e m , i n p a r t i c u l a r , t h e p a r s i n g g o a l t o k e n L i s t t-~ e x p r e s s i o n s h o w n in t h e p r e c e d i n g s u b s e c t i o n c a n b e a l s o v i e w e d as a g e n e r a t e a n d test p r o b l e m , w h e r e e x p r e s s i o n is t h e g e n e r a t o r a n d t h e j o i n a b i l i t y c o m p a r i s o n w i t h t h e g i v e n t o k e n L i s t a c t s a s a t e s t e r . E x a c t l y a s in t h e I e e r m u t a t i o n s o r t CX'~.x*ple, m a n y c a n d i - d a t e t o k e n lists p r o d u c e d b y e x p r e s s i o n , b u t d i f f e r e n t f r o m t o k e n L i s t , will b e d i s - c a r d e d w i t h o u t g e n e r a t i n g t h e m c o m p l e t e l y . 3. Technical preliminaries T h e r e a d e r is a s s u m e d t o h a v e s o m e t a m i l i a r i t y w i t h t e e b a s i c s o f l o g i c p r o g r a m - m i n g [5,31] a n d t e r m r e w r i t i n g [I 2,30]. W e will a l s o n e e d s o m e n o t i o n s r e l a t e d t o se- m a n t i c d o m a i n s [48]. T h i s s e c t i o n i n t e n d s t o m a k e t h e p a p e r m o r e s e i f c o n t a i n e d . W e fix b a s i c n o ' , i o n s , t e r m i n o l o g y a n d n o t a t i o n s , t o be u s e d in t h e rest o f t h e p a p e r . 3. i. P o s e t s a n d C P O s A p a r t i a l l y o r d e r e d s e t (in s h o r t , p o s e t ) w i t h b o t t o m _L is a set S e q u i p p e d w i t h a p a r t i a l o r d e r E_ a n d a l e a s t e l e m e n t _1_ ( w . r . t . E_). W e s a y t i m t a n e l e m e n t x 6 S is to- t a l l y d e f i n e d iff x is m a x i m a l w . r . t . c . T h e set o f all t o t a l l y d e f i n e d e l e m e n t s o f S will b e n o t e d D e f ( S ) . D C S is a d i r e c t e d s e t iff f o r all x , y E D t h e r e e x i s t s z 6 D w i t h x E_ z , y _ z. A s u b s e t A C_ S is a c o n e iff _I_EA a n d A is d o w n c l o s e c L i.e., y _ x =0- y E A, f o r all x E A, y 6 S. A n i d e a l I C_ S is a d i r e c t e d c o n e . W e w r i t e ~ ' ( S ) , J ( S ) f o r t h e s e t s o f c o n e s a n d i d e a l s o f S r e s p e c t i v e l y . T h e set

(9)

J.C. Gon:dde=-Moreno et aL I J. Logic Programming 40 ( 1 9 9 9 ) 4 7 - 8 7 55 =,.<:f J ( S ) , e q u i p p e d w i t h t h e s e t - i n c l u s i o n C a s o r d e r i n g , is a p o s e t w i t h b o t t o m , c a l l e d t h e ideal completion o f S. N o t e t h a t S ' s b o t t o m is p r e c i s e l y {_1_}, w h e r e 2. is S ' s b o t t o m . T h e r e is a n a t u r a l , o r d e r - p r e s e r v i n g e m b e d d i n g o f S i n t o ~, w h i c h m a p s e a c h x E S i n t o t h e principal ideal g e n e r a t e d b y x , ( x ) =def { Y E S : y ____. x } E .~.

A p o s e t w i t h b o t t o m C is a complete partial order (in s h o r t , cpo) iff D h a s a l e a s t u p p e r b o u n d I_.ID ( a l s o c a l l e d limit) f o r e v e r y d i r e c t e d set D C C. I n p a r t i c u l a r , U0 = 2 . . A n e l e m e n t u E C is c a l l e d a finite e l e m e n t iff w h e n e v e r u ___ t_tD f o r a n o n - e m p t y d i r e c t e d D, t h e r e e x i s t s x E D w i t h ~: ~ x . M o r e o v e r , u is c a l l e d total

iff u is m a x i m a l w.:-.t. ___, a n d partial o t h e r w i s e . A c p o C is c a l l e d algebraic iff a n y el- e m e n t o f C is t h e l i m i t o f a d i r e c t e d set o f f i n i t e e l e m e n t s . F o r a n y p o s e r w i t h b o t t o m S, its i d e a l c o m p l e t i o n ~ t u r n s o u t t o b e t h e l e a s t c p o i n c l u d i n g S. F u r t h e r m o r e , S is a n a l g e b r a i c c p o w h o s e finite e l e m e n t s a r e p r e c i s e l y t h e p r i n c i p a l i d e a l s ( x ) , x E S; see, e.g. R e f . [38]. N o t e t h a t e l e m e n t s x E D e f ( S ) c o r r e s p o n d t o finite a n d t o t a l el- e m e n t s (x) in t h e i d e a l c o m p l e t i o n . A l g e b r a i c c p o s a r e c o m m o n l y u s e d a s s e m a n t i c d o m a i n s f o r t h e d e n o t a t i o n a l se- m a n t i c s o f p r o g r a m m i n g l a n g u a g e s [48]. T h e p a r t i a l o r d e r is i n t e r p r e t e d a s a n a p - p r o x i m a t i o n o r d e r i n g b e t w e e n p a r t i a l l y d e f i n e d v a l u e s ; i.e. x c y is u n d e r s t o o d a s t h e s t a t e m e n t t h a t y is m o r e d e f i n e d t h a n x . I n f i n i t e v a l u e s s u c h a s i n f i n i t e lists o r f u n c t i o n s (in t h e c a s e o f h i g h e r - o r d e r l a n g u a g e s ) c a n b e c a p t u r e d a s l i m i t s o f d i r e c t e d s e t s o f f i n i t e p a r t i a l v a l u e s , l u t h i s p a p e r , w e will w o r k w i t h p o s e r s i n s t e a d o f a l g e - b r a i c c p o s , b e c a u s e t h i s s i m p l i f i e s t e c h n i c a l i t i e s . A n y g i v e n p o s e t S m u s t b e i m a g i n e d a s a n i n c o m p l e t e s e m a n t i c d o m a i n , w h i c h p r o v i d e s o n l y finite s e m a n t i c v a l u e s . T h e i d e a l c o m p l e t i o n S s u p p l i e s t h e m i s s i n g i n f i n i t e v a l u e s . A s w e will s e e i n S e c t i o n 5, finite v a l u e s a r e e n o u g h f o r d e s c r i b i n g t h e s e m a n t i c s o f o u r p r o g r a m s .

3.2. Signatures, terms and C-terms

A signatto'e with constructors is a c o u n t a b l e set Z" = DCx U l~Sz, w h e r e

DCz = U , , ~ DC~ a n d 3'S~ = U,,cr~ F S ~ a r e d i s j o i n t s e t s o f constructor a n d defined

fitnction s)'tnboIs r e s p e c t i v e l y , e a c h o f t h e m w i t h a s s o c i a t e d arity. W e a s s u m e a c o u n t -

a b l e set ~ " o f variables, a n d w e o m i t e x p l i c i t m e n t i o r , o f Z" in t h e s u b s e q u e n t n o t a - t i o n s . W e w r i t e T e r m f o r t h e set o f t e r m s b u i l t u p w i t h a i d o f Z a n d ~", a n d w e d i s t i n g u i s h t h e s u b s e t C T e r m o f t h o s e t e r m s ( c a l l e d constructor terms, s h o r t l y C - t e r m s ) w h i c h o n l y m a k e u s e o f DC a n d ~¢ . W e will n e e d s o m e t i m e s t o e n h a n c e Z w i t h a n e w c o n s t a n t ( 0 - a r i t y c o n s t r u c t o r ) _1_, o b t a i n i n g a n e w s i g n a t u r e Z ± . 5 W e will w r i t e T e r m ± a n d C T e r m ± f o r t h e c o r r e s p o n d i n g sets o f t e r m s in t h i s e x t e n d e d s i g n a t u r e , t h e s o - c a l l e d partial t e r m s . A s f r e q u e n t n o t a t i o n a l c o n v e n t i o n s w e will a l s o u s e e , d C DC; f , g E F S ; , ~ , t 6 C T e r m ± ; a , b , e 6 T e r m j . M o r e o v e r , v a t ( e ) will b e u s e d f o r t h e set o f v a r i a b l e s o c c u r r i n g in t h e t e r m e . A n a t u r a l approxhnation ordering E f o r p a r t i a l t e r m s c a n b e d e f i n e d a s t h e l e a s t p a r t i a l o r d e r i n g o v e r T e r m ± s a t i s f y i n g t h e f o l l o w i n g p r o p e r t i e s : . I C _ e, for .all e 6 T e r m ± ,

• et ___ e~ ... e, ~ e,', = ~ h ( e l , . . . , e,) ___ h ( e ~ .... , e,') for all h e D C " U I~S", l

e,, e i E T e r m ± .

s S e m a n t i c a l l y , the s y m b o l ~t is i n t e n d e d t o d e n o t e t h e b o t t o m e l e m e n t , a l s o w r i t t e n as ± b y an a b u s e o f n o t a t i o n .

(10)

5 6 J . t ~ Gonr&!e---Moreno e t a l . I J. L o g i c P r o g r a m m i n g 40 ( 1 9 9 9 ) 4 7 ~ 7 W e a r e p a r t i c u l a r l y i n t e r e s t e d in t h e r e s t r i c t i o n o f __. t o t h e set C T e r m ± o f p a r t i a l C - T e r m s . T h e i d e a l c o m p l e t i o n o f C T e r m ± is i s o m o r p h i c t o a c p o w h o s e e l e m e n t s a r e p o s s i b l y i n f i n i t e t r e e s w i t h n o d e s l a b e l l e d b y s y m b o l s f r o m DC tJ {_L} in s u c h a w a y t h a t t h e a r i t y o f e a c h l a b e l c o r r e s p o n d s t o t h e n u m b e r o f s o n s o f t h e n o d e ; see R e f . [16]. F o r i n s t a n c e , i f w e a s s u m e a s i g n a t u r e t h a t i n c l u d e s t h e c o n s t r u c t o r s z e r o , s u c f o r n a t u r a l n u m b e r s , a s w e l l a s list c o n s t r u c t o r s ( w r i t t e n in P r o l o g s y n t a x ) , w e c a n o b t a i n t h e i n f i n i t e list o f all n a t u r a l n u m b e r s a s l i m i t o f t h e f o l l o w i n g c h a i n o f p a r t i a l C - t e r m s : J_ ___ [ z e r o I _L] ___ [ z e r o , s u e ( z e r o ) I _1_] [ z e r o , s u c ( z e r o ) , s u c ( s u e ( z e r o ) ) I _1_] _____ . . . 3.3. Substitutions C-substitutions a r e m a p p i n g s 0 : Y" ~ C T e r m w i f i c h h a v e 0 - T e r m --~ T e r m a s u n i q u e n a t u r a l e x t e n s i o n , a l s o n o t e d a s 0. T h e set o f r ' ! C - s u b s t i t u t i o n s is n o t e d a s C S u b s t . T h e b i g g e r set C S u b s t ± o f all p a r t i a l C - s u b s t i t t ~ t i o n s 0 : ~ - , CTe-,-m± is d e f i n e d a n a l o g o u s l y . W e n o t e a s t O t h e r e s u l t o f a p p l y i n g t h e s u b s t i t u t i o n 0 t o t h e t e r m t , a n d w e d e f i n e t h e c o m p o s i t i o n tr0 s u c h t h a t t ( a 0 ) ---- (t,,~)0. A s u s u a l , t h e do- main o f a s u b s t i t u t i o n 0 is d e f i n e d a s d o m ( O ) = { X ~ ~' I X O ~ X } , a n d 0 = { X i / t l . . . X , / t , , } s t a n d s f o r t h e s u b s t i t u t i o n t h a t satisfies X;/~--- t t (! <~i<~n) a n d Y0 --- Y f o r all Y E ¢- \ {X~ . . . X,,}. A s u b s t i t u t i o n 0 s u c h t h a t 00 --- 0 is c a l l e d idempotent. T h e a p p r o x i m a t i o n o r d e r i n g o v e r C T e r m z i n d u c e s a n a t u r a l a p p r o x i m a - t i o n o r d e r i n g o v e r C S u b s t ± , d e h n e d b y t h e c o n d i t i o n : 0 ___ 0' iff X0 E X0', f o r all X E ~¢". W e will u s e a l s o t h e sabsumption ordering o v e r C S u b s t ~ , d e f i n e d by:

0 ~ O' iff 0' = 0tr f o r s o m e o-. F i n a l l y , t h e n o t a t i o n 0 ~< 0'[,//], w h e r e ¢ / c _ ~", m e a n s

t h a t X0' -- X(0tr) f o r s o m e tr a n d f o r all X E 4/ (i.e, 0 is m o r e g e n e r a l t h a n 0' o v e r t h e v a r i a b l e s in 4/).

4. A constructor-based conditional rewriting logic

A s w e h a v e s e e n in S e c t i o n 1, o u r i n t e n d e d s e m a n t i c s e m b o d i e s angelic non-deter-

minism w i t h call-time choice f o r non-strict f u n c t i o n s , a n d t h e u s u a l n o t i o n o f r e w r i t -

i n g is u n s o u n d w . r . t , s u c h a s e m a n t i c s . T h e r e f o r e , w e will u s e a s p e c i a l p r o o f s y s t e m c a l l e d C o n s t r u c t o r - b a s e d c o n d i t i o n a l R e W r i t i n g L o g i c ( C R W L ) t o f o r m a l i z e t h e n o n - c l a s s i c a l v e r s i o n o f r e w r i t i n g n e e d e d f o r o u r p u r p o s e s . I n t h e rest o f t h e p a p e r , w e will s e e t h a t C R W L c a n b e e q u i p p e d w i t h a n a t u r a l m o d e l t h e o r y , a n d u s e d a s a l o g i c a l b a s i s f o r d e c l a r a t i v e p r o g r a m m i n g . A s s u m e a n y f i x e d s i g n a t u r e w i t h c o n s t r u c t o r s Z" = DC U F S . C R W L - t h e o r i e s , w h i c h will b e c a l l e d s i m p l y programs in t h e r e s t o f t h e p e p e r , a r e d e f i n e d a s sets ~P o f c o n d i t i o n a l r e w r i t e r u l e s o f t h e f o r m :

f ( ~ ) -~ r ~= C

left h a n d side (I) right h a n d side C o n d i t i o n

w h e r e f E F S ", t m u s t b e a l i n e a r n - t u p l e o f C - t e r m s t , E C T e r m a n d t h e c o n d i t i o n C m u s t c o n s i s t o f f i n i t e l y m a n y ( p o s s i b l y z e r o ) j o i n a b i l i t y s t a t e m e n t s a ~,a b w i t h a , b E T e r m . A s u s u a l (see, e . g . , R e f . [12]) "'t, l i n e a r " m e a n s t h a t e a c h v a r i a b l e o c c u r -

(11)

J.C. Gonz&lez-Moreno et al. ! J. Logic P r o g r a m m i n g 40 ( ! 0 9 0 ) 47-@7 5 7 r i n g in t m u s t h a v e a s i n g l e o c c u r r e n c e . I n t h e s e q u e l w e u s e t h e f o l l o w i n g n o t a t i o n f o r p o s s i b l y p a r t i a l C - i n s t a n c e s o f r e w r i t e r u l e s : [.9]1 = { ( 1 --, r ~ c ) 0 1 (1 -~ r ~ c) • ~ , 0 e C S u b s t i } . F r o m a g i v e n C R W L - p r o g r a m : ~ w e w i s h t o b e a b l e t o d e r i v e s t a t e m e n t s o f t h e f o l - l o w i n g t w o k i n d s : • R e d u c t i o n s t a t e m e n t s : a ~ b , w i t h a , b E T e r m t . • J o i n a b i l i t y s t a t e m e n t s : a t><a b , w i t h a , b E T e r m ± . T h e i n t e n d e d m e a n i n g o f a r e d u c t i o n s t a t e m e n t a ~ b is t h a t a c a n b e r e d u c e d t o b , w h e r e ' r e d u c t i o n " i n c l u d e s t h e p o s s i b i l i t y o f a p p l y i n g r e w r i t e r u l e s f r o m .:~¢ o r r e p l a c - i n g s o m e s u b t e r m s o f a b y _L. W e a r e p a r t i c u l a r l y i n t e r e s t e d in r e d u c t i o n s t a t e m e n t s o f t h e f o r m a - ~ t w i t h t 6 C T e r m ± . w h i c h w e w i l l c a l l approximation statements. O n e s u c h s t a t e m e n t is i n t e n d e d t o m e a n t h a t t r e p r e s e n t s o n e o f t h e v a l u e s t h a t m u s t b e c o l l e c t e d i n o r d e r t o o b t a i n t h e n o n - d e t e r m i n i s t i c s e m a n t i c s o f a . N o t e t h a t t c a n b e a p a r t i a l C - t e r m ; t h i s m e a n s t h a t w e a r e a i m i n g a t a n o n - s t r i c t s e m a n t i c s . O n t h e o t h e r h a n d , t h e i n t e n d e d m e a n i n g o f a j o i n a b i l i t y s t a t e m e n t a ~ b is t h a t a a n d b c a n b e b o t h r e d u c e d t o s o m e c o m m o n t o t a l l y d e f i n e d v a l u e ; in o t h e r w o r d s , a ~< b will h o l d if w e c a n p r o v e a ~ t a n d b ----, t f o r s o m e c o m m o n total C - t e r m t E C T e r m . N o t e t h a t . a c c o r d i n g t o t h i s i d e a . ~-~ b e h a v e s i n d e e d a s a g e n e r a l i z a t i o n o f s t r i c t e q u a l i t y . A f o r m a l s p e c i f i c a t i o n o f C R W L - d e r i v a b i l i t y f r o m a p r o g r a m # f is g i v e n b y t h e f o l l o w i n g r e w r i t i n g c a l c u l u s .

D e f i n i t i o n 4.1 (Basic Re,vriting Calcuhls).

B M N R F R T R J B o t t o m : e --~_L. M o n o t o n i c i t y : ' . . . e~, f o r h E D e " U F S " . el ~ e ! e . ---. h ( e , , . . . , e , , ) --~ h ( e ~ . . . e : , ) R e f l e x i v i t y : e ~ e. C R e d u c t i o n : ~ - f o r a n y i n s t a n c e ( 1 ----, r ~ C) E ['~¢]1- I - ~ r T r a n s i t i v i t y : e - ~ e ' e ' ~ e " e ---~ e n a - ~ t b - ~ t J o i n : i f t 6 C T e r m . a > ~ b S o m e c o m m e n t s a b o u t t h i s c a l c u l u s a r e i n o r d e r . R u l e s M N , R F , R a n d T R r e f l e c t t h e u s u a l b e h a v i o u r o f r e w r i t i n g , e x c e p t t h a t R a l l o w s t o a p p l y o n l y ( p a r t i a l ) C - i n - s t a n c e s o f r e w r i t e r u l e s , w h i l e t r a d i t i o n a l r e w r i t i n g w o u l d a l l o w a r b i t r a r y i n s t a n c e s . A t t h i s p o i n t , B a s i c R e w r i t i n g C a l c u l u s ( B R C ) r e f l e c t s o u r o p t i o n f o r n o n - s t r i c t f u n c - t i o n s a n d c a l l - t i m e c h o i c e ( a n e x p l i c i t s h a r i n g m e c h a n i s m is n o t n e e d e d , b e c a u s e C - i n s t a n c e s a r e b u i l t f r o m C - t e r m s , t h a t r e p r e s e n t c o m p u t e d - p o s s i b l y p a r t i a l - v a l - u e s ) . R u l e B e n a b l e s t o d e r i v e a p p r o x i m a t i o n s t a t e m e n t s a ~ t w i t h p a r t i a l g; t h e n e e d t o c o l l e c t s u c h s t a t e m e n t s is a l s o d u e t o n o n - s t r i c t n e s s . F i n a l l y , r u l e J o b v i o u s l y

(12)

58 J.C. Gon:hlez-Moreno et al. I ~ ¢.ogic Programming 40 (i~99) 47--87

reflects t h e i n t e n d e d m e a n i n g o f j o i n a b i l i t y , as e x p l a i n e d a b o v e . N o t e t h a t J requires t to be total. O t h e r w i s e , we w o u l d o b t a i n a useless n o t i o n , since a ~ b w o u l d f o l l o w f r o m B, f o r a r b i t r a r y t e r m s a, b. A s a c o n c r e t e e x a m p l e o f B R C - d e r i v a b i l i t y , a s s u m e t h a t ,~ i n c l u d e s the rewrite rule:

f r o m ( N ) -~ IN i f r o m ( s u c ( N ) ) ] T h e n , t h e f o l l o w i n g a p p r o x i m a t i o n s t a t e m e n t s c a n be d e r i v e d f r o m ~ in B R C : f r o m ( z e r o ) ~ ± f r o m ( z e r o ) ~ [ z e r o I ±] f r o m ( z e r o ) ----, [ z e r o , s u e ( z e r o ) I 1 ] ...

N o t e t h a t { t E C T e r m z I /'¢ t-aRc f r o m ( z e r o ) --~ t } is a directed set, w h o s e limit (in t h e ideal c o m p l e t i o n o f C T e r m ± ) r e p r e s e n t s the infinite list o f all n a t u r a l n u m - bers.

A t t h i s p o i n t we c a n c o m p a r e C R W L w i t h a n o t h e r well k n o w n a p p r o a c h to re- w r i t i n g as logical d e d u c t i o n , n a m e l y M e s e g u e r ' s R e w r i t i n g L o g i c [35] ( s h o r t l y R W L , in w h a t follows), w h i c h h a s been also used as a basis for c o m p u t a t i o n a l sys- t e m s a n d l a n g u a g e s such as E L A N [29] a n d M a u d e [36]. In spite o f s o m e o b v i o u s a n a l o g i e s , t h e r e a r e several c l e a r differences r e g a r d i n g b o t h the i n t e n d e d a p p l i c a - t i o n s a n d t h e s e m a n t i c s . C R W L i n t e n d s to m o d e l t h e e v a l u a t i o n o f t e r m s in a c o n - s t r u c t o r - b a s e d languz~ge i n c l u d i n g n o n - s t r i c t a n d p o s s i b l y n o n - d e t e r m i n i s t i c f u n c t i o n s , so t h a t it c a n serve as a logical basis for d e c l a r a t i v e p r o g r a m m i n g lan- g u a g e s i n v o l v i n g l a z y e v a l u a t i o n . O n t h e o t h e r h a n d , R W L w a s o r i g i n a l l y p r o p o s e d w i t h b r o a d e r a i m s , as a logical f r a m e w o r k in w h i c h o t h e r logics c o u l d be r e p r e s e n t - ed, as well as a s e m a n t i c f r a m e w o r k for the ~pecification o f l a n g u a g e s a n d ( p o s s i b l y c o n c u r r e n t ) systems. A c c o r d i n g l y , R W L is n o t c o n s t r u c t o r - b a s e d a n d lacks t h e a n a i o g o n to o u r rule B. M o r e o v e r , R W L relies o n a m o r e g e n e r a l n o t i o n o f rewrit- ing, n a m e l y r e w r i t i n g m o d u l o e q u a t i o n a l a x i o m s ( t y p i c a l l y , a s s o c i a t i v i t y a n d / o r co- m m u t a t i v i t y o f s o m e o p e r a t o r s ) , i n t e n d e d to p r o v i d e a s t r u c t u r a l e q u i v a l e n c e b e t w e e n terms. F i n a l l y , R W L a d o p t s r u n - t i m e c h o i c e r a t h e r t h a n c a l l - t i m e choice. T h i s o p t i o n c o r r e s p o n d s to t h e classical b e h a v i o u r o f r e w r i t i n g , u s i n g a r b i t r a r y in- s t a n c e s o f t h e r e w r i t e rules, in c o n t r a s t to o u r rule R. W e believe t h a t c a l l - t i m e c h o i c e is a m o r e c o n v e n i e n t o p t i o n for p r o g r a m m i n g p u r p o s e s ; t h e d i s c u s s i o n o f the p e r m u t a t i o n s o r t e x a m p l e in S e c t i o n 2 h a s p r o v i d e d s o m e e v i d e n c e to this p o i n t . M o r e o v e r , c a l l - t i m e c h o i c e leads to a n i m p l e m e n t a t i o n b a s e d o n s h a r i n g , w h i c h is the m o s t efficient c h o i c e for a lazy l a n g u a g e . See the d i s c u s s i o n in S e c t i o n 1.

In o r d e r to use C R W L as a logical basis for d e c l a r a t i v e p r o g r a m m i n g , it is c o n - v e n i e n t to i n t r o d u c e a s e c o n d r e w r i t i n g c a l c u l u s called G o a l - O r i e n t e d R e w r i t i n g C a l - c u l u s ( G O R e ) w h i c h a l l o w s to b u i l d g o a l - o r i e n t e d p r o o f s o f a p p r o x i m a t i o n a n d j o i n a b i l i t y s t a t e m e n t s . G o a l - o r i e n t e d p r o o f s h a v e t h e p r o p e ~ t y t h a t the o u t e r m o s t s y n t a c t i c s t r u c t u r e o f the s t a t e m e n t to be p r o v e d d e t e r m i n e s the i n f e r e n c e rule w h i c h m u s t be a p p l i e d a t t h e last p r o o f step; in this w a y , the s t r u c t u r e o f t h e p r o o f is de- t e r m i n e d b y t h e s t r u c t u r e o f t h e goal. T h i s will p r o v i d e a very h e l p f u l t e c h n i c a l sup- p o r t f o r p r o v i n g t h e c o m p l e t e n e s s o f a g o a l s o l v i n g p r o c e d u r e b a s e d o n lazy n a r r o w i n g ; see S e c t i o n 7.

(13)

J.c. GonzEdec-Moreno et a L I J. Logic" Prograrmning 40 (1999) 47-87 59 W e will p r o v e t h a t B R C a n d G O R C h a v e t h e s a m e d e d u c t i o n p o w e r f o r d e r i v i n g a p p r o x i m a t i o n a n d j o i n a b i l i t y s t a t e m e n t s . T h e f a c t t h a t B R C - p r o v a b l e s t a t e m e n t s a l w a y s h a v e G O R C - p r o o f s b e a r s s o m e a ~ a l o g y t o t h e e x i s t e n c e o f s o - c a l l e d u n i f o r m p r o o f s in a b s t r a c t l o g i c p r o g r a m m i n g l a n g u a g e s b a s e d o n s e q u e n t c a l c u l i [41]. T h e f o r m a l p r e s e n t a t i o n o f G O R C is a s f o l l o w s : D e f i n i t i o n 4.2 ( G O R C ) . B R R D C O R B o t t o m : e --*_L. R e s t r i c t e d R e f l e x i v i t y : X ~ X f o r X E ¢ ' . e l --+ t l . . . e. -~ tn D e c o m p o s i t i o n : c ( e i , . . . , e,,) ~ c(tl . . . t,,) t b r c E DC". ti E C T e r m ± . O u t e r R e d u c t i o n : ~ _ _ _ ~ t _ j . . _ , e,, ~ t , et C r ~ t t ( e , . . . e,,) - ~ t . if t ~_L, ( f ( t , . . . t,,) - - r -'-=- C) C [-Y?JJ_- J o i n : a ----, t a. t><l b b ---, t if t E C T e r m . N o t e t h a t G O R C c : m d e r i v e o n l y s u c h r e d u c t i o n s t a t e m e n t s t h a t a r e in f a c t a p - p r o x i m a t i o n s t a t e m e n t s . T h e f o l l o w i n g p r o p o s i t i o n e n s u r e s t h e d e s i r e d e q u i v a l e n c e b e t w e e n B R C a n d G O R C : P r o p o s i t i o n 4,1 ( C a l c u l i e q u i v a l e n c e ) . F o r a n y p r o g r a m :~, t h e c a l c u l i B R C a n d G O R C d e r i v e t h e s a m e a p p r o x b ~ m t i o n a n d j o h m b i l i o ' s t a t e m e n t s . P r o o f . L e t . ~ ( p r o g r a m ) a n d tp ( a p p r o x i m a t i o n o r j o i n a b i l i t y s t a t e m e n t ) b e g i v e n . W e will s h o w t h a t .:~ F ~ R c ~p iff . ~ I-GORe tO.

T h e "'if" p a r t h o l d s b e c a u s e a n y s t e p w i t h i n a g i v e n G O R C - p r o o f c a n b e e a s i l y r e p l a c e d b y o n e o r s e v e r a l B R C - s t e p s . T h i s is o b v i o u s f o r B-, R R - , D C - a n d J - s t e p s , w h i l e a n y O R - s t e p c a n b e r e p l a c e d b y f o u r B R C - s t e p s a c c o r d i n g t o t h e f o l l o w i n g s c h e m e : 6 T R f ( e ! . . . e . ) - ~ t M N f ( e ~ . . . e~) - ~ f ( t ~ . . . t ~ ) T R f ( t , . . . t . ) ~ t e l ~ t , . . . e . - ~ t,, R f ( t l . . . t . ) - ~ r r - ~ t C T h e " ' o n l y i f " p a r t c a n b e p r o v e d b y i n d u c t i o n o n t h e s t r u c t u r e o f B R C - d e r i v a t i o n s . T h e i n d u c t i o n relies o n t h e f o l l o w i n g k e y o b s e r v a t i o n : A n y g i v e n B R C - p r o o f f o r ~ I-BRC f(e, . . . e . ) --~ t

Here and in the sequel, we draw BRC and GORC proofs as trees growing downwards, where each node corresponds to the conclusion of some inference rule whose premises correspond to the node's children.

(14)

60 J.C. Gon:&le:-Moreno et al. I J. Logic Programming 40 (1099) 47-87 ( w h e r e t is n o t _L) d e t e r m i n e s a r e w r i t i n g 7 s e q u e n c e o f t h e f o r m f ( e l , . . . , e , , ) ~ * f ( t l , . . . , t , ) - - ~ r - ~ * t, w h e r e e a c h r e w r i t e s t e p a p p l i e s s o m e r e w r i t i n g r u l e f r o m [ ~ ] ± , o r a r e w r i t e r u l e o f t h e f o r m e --~_1_. I n p a r t i c u l a r t h e r e w r i t e s t e p f ( t ~ . . . . , t , , ) --~ r w i l l c o r r e s p o n d t o s o m e i n s t a n c e f ( t ~ , . . . , t , ) ~ r ~ 0 E f.~']~. B y i n d u c t i o n h y p o t h e s i s w e c a n a s s u m e t h a t : ]"(]OR(7 e i --"> ti

(1

~ i <~ n), • ~ [-GORC a t ~ b f o r e a c h a t>q b in C ,~ I'-GORC r -~ t, b e c a u s e e a c h o f t h e s t a t e m e n t s h a s a s h o r t e r B R C - p r o o f t h a n f ( e ~ . . . . , e~) --~ t . T h e n w e c a n c o n c l u d e t h a t , ~ ~-~ORC f ( e l . . . e , ) ~ t b y a p p l y i n : ~ r u l e O R . [ ] I n t h e r e s t o f t h e p a p e r , t h e n o t a t i o n : ~ [-CRWL (~O will m e a n p r o v a b i l i t y o f t# ( a n a p p r o x i m a t i o n o r j o i n a b i l i t y s t a t e m e n t ) in a n y o f t h e c a l c u l i B R C o r G O R C . W e clo:ge t h i s s e c t i o n w i t h a t e c h n i c a l r e s u l t w h i c h will b e u s e d in S e c t i o n s 5 a n d 7. L e m m a 4.~ ( M o n o t o n i c i t y L e m m a ) . L e t .~ be a p r o g r a m , e E T e r m ± , O,O'ECgubs~'L, a n d t E C T e r m ± . I f OE_O' a n d 1I is a G O R C - p r o o f o f I--CRWL e 0 - * t . there e x i s t s a G O R C - p r o o f H' o f J¢ I-CRWL e 0 ' ~ t with the s a m e length a n d structure as FI.

P r o o f . F i r s t , w e n o t e t h a t 0 E 0' e n t a i l s e 0 E e 0 ' . T h e r e f o r e , w e c a n a s s u m e e0___ a E a ' = e 0 ' . W e r e a s o n b y i n d u c t i o n o n t h c size o f H , m e a s u r e d a s t h e n u m b e r o f G O R C - i n f , ~ r e n c e s t e p s . B a s e case (n = 0): H m u s t h a v e o n e o f t h e t w o f o r m s : B a - ~ ± o r R R a - ~ a . I n t h e first c a s e w e c a n t a k e B a ' --,_1_ a s H ' . I n t h e s e c o n d c a s e a m u s t b e a v a r i a b l e . T h e n a E_ a ' e n t a i l s a = a ' a n d H i t s e l f c a n b e t a k e n a s H ' . Inductive case ( n > 0): W e d i s t i n g u i s h t w o s u b c a s e s a c c o r d i n g t o t h e G O R C - r u l e u s e d f o r t h e l a s t i n f e r e n c e s t e p in H . R u l e D C . T h e n /1 m u s t b e o f t h e f o r m : H i • . . H , , D C a = c ( a l , . . . , a , , ) --~ e ( t ~ , . . . , t , , ) w h e r e H i is a G O R C - p r o o f f o r : ~ I-CRWL a~ ~ t ~ ( 1 <~ i ~ n). T h e n w e c a n b u i l d H ' a s D C n', . . . n'o a ' =-- c ( a ' I . . . a ; ) ---. c ( t l . . . t , ) w h e r e t h e G O R C - p r o o f s H'; f o r . ~ I-CRWL a~ --~ t ; d o e x i s t b y i n d u c t i o n h y p o t h e s i s . • R u l e O R . I n t h i s c a s e : h e s t r u c t u r e o f H is H I . . . H , , A F O R a _~ f(al . . . a,)--* t

(15)

J.C. Gonz~lez-Moreno et al. I J. Logic Programming 40 (1999) 47-87 61 w h e r e H~ is a G O R C - p r o o f f o r ~ i-CRWL a~ ---* t,- (1 <~ i~< n), A a G O R C - p r o o f f o r F-CRWL C, F a G O R C - p r o o f f o r ~ I--CRWL r ---* t , f ( t l . . . t . ) ~ r ~ C E [~]±, T h u s , b y i n d u c t i o n h y p o t h e s i s we c a n a s s u m e G O R C - p r o o f s /'/~ f o r ~-CRWL a~ ~ t i (1 ~< i <~ n) a n d b u i l d H ' as O R /7tl.../7" A r [] a ~ f ( a ' i , . . . , a,') --> t

5. Model-theoretic semantics for CRWL-programs

In this s e c t i o n we define m o d e l s f o r C R W L a n d we e s t a b l i s h s o u n d n e s s a n d c o m - p l e t e n e s s o f C R W L - p r o v a b i l i t y w.r.t, s e m a n t i c v a l i d i t y in m o d e l s . M o r e o v e r , w e p r o v e t h a t e v e r y p r o g r a m h a s a free t e r m m o d e l , w h i c h c a n be sa~zn as a g e n e r a l i z a - t i o n o f ~ - s e m a n t i c s [14] for H o r n c l a u s e p r o g r a m s . 5.1. C R W L - a l g e b r a s I n S~ction 3 we h a v e e x p l a i n e d t h a t t h e e l e m e n t s o f a p o s e t S c a n be v i e w e d as finite a p p r o x i m a t i o n s o f v a l u e s o f a s e m a n t i c d o m a i n D, t h a t c a n be o b t a i n e d f r o m 5 b y a d d i n g limit e l e m e n t s via a n ideal c o m p l e t i o n c o n s t r u c t i o n . T h e r e f o r e , we will use m o d e l s w i t h posers as carriers. In a n y s u c h m o d e l , we will i n t e r p r e t f u n c t i o n s y m - bols as m o n o t o n i c m a p p i n g s t a k i n g e l e m e n t s as a r g u m e n t s a n d r e t u r n i n g as result a c o n e o f e l e m e n t s r a t h e r t h a n a single e l e m e n t , b e c a u s e o f t h e p o s s i b i l i t y o f c a l l - t i m e c h o i c e n o n - d e t e r m i n i s m . A t e c h n i c a l j u s t i f i c a t i o n f o r t h e use o f c o n e s is t h e c o n s t r u c - t i o n o f H o a r e ' s p o w e r d o m a i n [48.52], w h e r e c o n e s o f finite e l e m e n t s o f a g i v e n d o - m a i n D, p a r t i a l l y o r d e r e d by set i n c l u s i o n , b e c o m e t h e e l e m e n t s o f H o a r e ' s p o w e r d o m a i n .~(D). In fact, w h e n a p p l y i n g ideal c o m p l e t i o n t o o u r m o d e l s , m o n o - t o n i c m a p p i n g s f r o m e l e m e a t s to c o n e s b e c o m e c o n t h m o u s m a p p i n g s f r o m d o m a i n s to H o a r e ' s p o w e r d o m a i n s . "f he p o s e t - b a s e d p r e s e n t a t i o n t u r n s o u t to be c o n v e n i e n t for all o u r p u r p o s e s . D e t e r m i n i s t i c f u n c t i o n s , in this setting, c a n be viewed as t h o s e m a p p i n g s f r o m e l e m e n t s to c o n e z t h a t r e t u r n d i r e c t e d c o n e s (i.e., ideals) as results. T h i s is b e c a u s e ideals c o r r e s p o n d t o ( p o s s i b l y infinite) e l e m e n t s in t h e ideal c o m p l e - tion.

T e c h n i c a l l y , we n e e d t h e f o l l o w i n g d e f i n i t i o n :

Definition 5.1 ~Non-deterministic a n d deterministic f u n c t i o n s ) . G i v e n t w o p o s e t s w i t h b o t t o m D, E, we define:

• t h e set o f all non-deterministic f u n c t i o n s f r o m D to E as

[D-~.

E] = ~ r { f : D--, ~ ( E ) I Vu, u' S D:(u __ ~' $ f ( u ) c _ f ( u ' ) ) } ; • t h e set o f all deterministic f u n c t i o n s f r o m D to E as

[D ~

El =~ef I f s [D --*n El IVu ~ D: f ( u ) ~ Y(E)}.

N o t e a l s o t h a t a n y n o n - d e t e r m i n i s t i c f u n c t i o n f E [D ---~, E] c a n be e x t e n d e d t o a m o n o t o n i c m a p p i n g f : ~ ( D ) ~ ~ ( E ) d e f i n e d b y f'(C) - d ~ f u u e c f ( u ) . T h e b e h a v - i o u r o f f" a c c o r d i n g to this d e f i n i t i o n reflects c a l l - t i m e choice. By a n a b u s e o f n o t a - tion, we will n o t e f also as f in t h e sequel.

References

Related documents

More information on the School of Education and its history can be found in the University of San Diego Accreditation reports, University of San Diego Course Catalogs, University

In extrapolation approach II, the dust emissions of the sectors not surveyed were estimated on the basis of the mean volume flows determined for each company size category from

The observed changes in murine body size distribution from Units 4 to 5 and 5 to 6 remain modest (CD ¼ 0.12 and 0.19, respectively) but reveal small increases in medium and

Then compared the SIMPLIS small signal VRM model with different linear models of voltage regulator module (VRM) in both frequency domain and time domain, these

Since the Mercury compiler has perfect data ow information,reuse analyses for Mercury can be simpler, faster and yet more e ective than reuse analyses for logic languages without

The course of study in political science is designed to give students a breadth of knowledge of the discipline while allowing them the freedom to concentrate their studies in

We analyzed saccade rates, saccade amplitudes, saccade latencies and peak velocity of saccades in the time window 200-400 ms after stimulus onset (Figure 5) using repeated

He was the founder and leader of the NJFIT: Future in Transportation Program, which provided transportation and planning land use assistance to more than 50 communities in New