Schemes with recursion on higher types

2 downloads 0 Views 301KB Size Report
In this paper we define syntax and semantics of combinator schemes which originated ... Y e [[tl s]Es It] [rlt]] s]Erlt] [r Ist]]. [slt]]. It] J [r [slt3]]. [slt_]] I [rslt]] t]l t].
SCHEMES

WITH

RECURSION

Klaus

ON

TYPES

Indermark

LehrstiIhl f~r I n f o r m a t i k II, B ~ c h e l 29 - 31,

HIGHER

RWTH Aachen

D - 51oo

Aachen

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

In p r o g r a m scheme theory it has b e e n shown that r e c u r s i o n is a more p o w e r f u l control structure than iteration:

f l o w c h a r t schemes are t r a n s l a t a b l e into r e c u r s i o n schemes,

b u t n o t vice versa. For a c o m p r e h e n s i v e t r e a t m e n t of this and r e l a t e d results see the b o o k s of

ENGELFRIET

121

and

GREIBACH

141.

These r e c u r s i o n schemes do n o t involve

o b j e c t s o f higher functional types. In o r d e r to i n v e s t i g a t e the impact o f h i g h e r types on the d e f i n i t i o n o f lower type objects we introduce a class of p r o g r a m schemes w h i c h are b a s e d on t y p e d c o m b i n a t o r s including f i x e d - p o i n t combinators.

These "combinator schemes" have two c h a r a c t e r i s t i c features: i) C a r t e s i a n p r o d u c t s are not e l i m i n a t e d b y means o { ((A x B) ÷ C)

~

(A ÷

(B ÷ C))

SCHONFINKEL's

2) The schemes are c o m p l e t e l y u n i n t e r p r e t e d in the sense of if ... then ... else

...

isomorphisms

b e c a u s e this w o u l d lead to i r r e l e v a n t h i g h e r types. NIVAT

161:

and p r e d i c a t e symbols do n o t occur; o p e r a t i o n symbols w i l l

be i n t e r p r e t e d as continuous o p e r a t i o n s o n c h a i n - c o m p l e t e p a r t i a l l y o r d e r e d sets.

In this p a p e r we define s y n t a x a n d semantics of c o m b i n a t o r schemes w h i c h o r i g i n a t e d from the author's lectures on recursive d e f i n i t i o n s

151.

Furthermore, we reduce this

class of schemes to c e r t a i n subclasses. Due to space limits p r o o f s are o m i t t e d a n d w i l l be p u b l i s h e d elsewhere.

2. C a r t e s i a n types

Types are names for sets. S t a r t i n g from a set of base types we g e n e r a t e cartesian types b y use of two b i n a r y operations. and e x p o n e n t i a t i o n .

They w i l l b e i n t e r p r e t e d as c a r t e s i a n p r o d u c t

353

For a given set

I

of base types we define the set

as the smallest class

K ~ (I O {[ ,~,

(i)

{e} u I & K

(ii)

tl,t 2 E K --> ~tl I t2] ~ K

(iii)

tl,t 2 s K \ {e} => tlt 2 e K

l,e}) +

typ(I) of cartesian types over I

such that

typ (I) can be considered as the carrier of an algebra with operations Etl I t2],

(tl,t 2)

(tl,t 2)

~ tlt 2

algebra is freely generated by

I

with unit

e

and

( )

~ e.

Moreover,

this

in the class of all algebras with two binary and

one nullary operation where in addition one binary operation is associative with the nullary operation as its neutral element.

3. Typed combinators

Typed combinators The set

F(I)

are names for canonical elements of certain function spaces.

of combinators

over I

is defined as the disjoint union of the follow-

ing symbol sets:

{C

< tl,t2,t3 >

t

~ typ(1)}

tupling c ombinators

{T

< tl,t2,t 3 >

t

~ typ(1)}

(iii)

abstraction combinators

{K

< tl,t 2 >

t v s typ(1)}

(iv)

Sch6nfinkel

{S

< tl,t2,t 3 >

t v s typ(1)}

{$



t v E typ(I)}

(i)

composition

(ii)

combinators

combinators and

(v)

fixed-point combinators

{Y < t >

t

e typ(I)}

Their meaning can be guessed from the notation and will be defined below. Since we deal with cartesian products we have included tupling and Sch6nfinkel Fixed-point application,

According

combinators

lay outside the scope of this paper.

to its indices each combinator over

The mapping

combinators.

are required because infinite types, and therefore

T : F(I) + typ(I)

is defined by

I

is given a type.

self-

854

(i)

C



(ii)

T



(iii)

~

(vi)

Y



~

>

Syntactically,

s]Es It] [rlt]] [r Ist]] [ I x l s]Erlt] [t L [slt]] [ [ r s It] J [r [slt3]] [ [ r 1 [slt_]] I [rslt]] [[tl t]l t]

~> [ [ r I

e

these types allow for typed combinations

symbols, whereas semantically

4. Combinator

geneous operation let

The class

of combinators

the corresponding

and operation

function spaces.

schemes

Now, we can introduce

precise

they will indicate

~(I)

the class of combinator

schemes over an alphabet

symbols as the typed combination

closure of

be a set of operation s y m b o l s over

rec(~(I))

of combinator

schemes over

I

~(I)

~

and

~

of hetero-

F.

To be more

typed by

is defined as the smallest

subclass K ~ (~(I) ~ F(I) ~ {( , )})+

(ii)

K,

S,SI, .... S n i 4~

rec

typed by

Y : K ÷ typ(I)

Y(S) = [tlt2...t n I t],

(S S 1 S 2...Sn)

£ K

T(S ) = t ,

with type

stands for "recursion".

such that

t

In fact, the fixed-point

combinators will

describe recursion on higher types.

5. Semantics

Types will be interpreted continuous

operations,

as chain-complete

combinators

posers

as continuous

(cpo's);

operators,

operation

symbols as

and combinations

as

applications.

The class

cpo

that the set

of all (A + B)

cpo's has the following property. of continuous

functions

from

A

ordering and the associative

cartesian p r o d u c t

b e l o n g again to

we denote the o n e - e l e m e n t

cpo. By

i

A × B

to

For

A,B £ cpo

B

w.r.t,

we know

w.r.t, point-wise component-wise

cpo {~}

ordering

w h i c h is the neutral

355

X.

element of closure

Thereby, we can define for a given class

cart(~)

as the smallest subclass of

closed under exponentiation Let

(A,B)

A := {A i I i £ I} ~ cpo.

A

cpo

~ (A ÷ B)

~

of

cpo's

that contains

and product

its cartesian

~ u {~}

(A,B)

and that is

~ A x B.

is called a (continuous) interpretation of

I

and

it extends uniquely to all cartesian types over I: The mapping

h A : t_~(I)

÷ cart(A)

i

~ Ai

e

~

Is It] For the uniqueness of They prove

:= {F ~ A t

An interpretation mapping

(hAis) ÷ hA t))

st

~ hA(S ) x hA(t )

hA

see the remarks in 2. on the algebraic character of typ(I).

to be an algebra homomorphism.

hA

Notation: We write

ob~(A)

is determined by

At

for

hA(t)

as in the case of base types and

I t ~ tJzziz)}. A

of

I

implies the semantics of the typed combinators: The

[ ~ A : F(I) ÷ obj(A)

is given by

: A [rls] × A [sit]

÷ A [rIt]

[TIA

: A [rls] × A [rlt]

+ A [rlst], if,g) ~ Ix.

[

:

A llA

[SIA ~ ~Y~

At

A [slt]

,

: A [felt] ÷ A [rlEslt]] ~ A : A [rl[slt]] ÷ A [rslt]

A

(f,g) ~ Xx.

: A[tlt] + A t

f

~"

g(f(x)) (fix), gix))

lX. f

, f

~Xx.

, f

~ X(x,y).

, f

~

f(x,y)

Xy.

f(x) (y)

{ ~ < I ) I n S/N}

It can be shown that all these objects are in fact continuous.

Now, let in addition F ~ ~t T(F) = [w I ~ interpretation of

~ : ~(I) ÷ obj(A)

be a type preserving mapping, i.e.,

=> ~(F) £ (Aw ÷ Ai)- Then, ~(I).

5 := (A;~)

is called a (continuous)

It implies the semantics of combinator schemes as follows.

re__~c(~(I)) ÷ ob_~j(A) is determined by

lA

:= [ S

IA

(i)

[ S

(iii)

~ (S S1 " ' ' S n ) ~ A

Finally, we define equivalence of schemes S1 ~ $2 [ S1 ~ A

= [ $2 ~ A

for

S g r(I)

:= I S I A

( [ S I ~ A ..... ~ S n ~A)

SI,S 2 ~ rec(~(I))

as usual:

for every interpretation

A

of

~(I).

356

6. Reduction

The language of combinator schemes is rather redundant concerning equivalence. fore we shall reduce this language to equivalent sublanguages.

There-

For that purpose we

first select a hierarchy of types: I o := I and denote by type is in (I)

and

In+l := [I~ I I n ]

rec(~(I)) n

(n ~ ~)

the class of combinator schemes of degree

S E req(~(I)) n

This construction

For all

and

s,tl, .... tr,u E typ(I)

1

rec(~(I)) n

is based on the following combinator

w '



and

~ < s't~"'"tr'U

[ O < s,t I ..... t r ' U > ~

the class

of

~(I)

f(fl(x) ..... fr(X))

~ < s'ti' .... t r ' U > ~ A

(f'fl .... ,fr ) = Ix.

f(~y.

A

(fl(x,y) ..... fr(X,y)))

~x. f( )

(a) = I ( ) .

a

and

I~IA

=

~ E Ae

The types should be clear from the context, e.g.:

T(K)

If there is no danger of confusion type indices are dropped. (~ns)

for

n-fold

contains

< < s,u>,

(el ..... ar) = a (f'fl ..... fr ) = ix.

(f) =

rec(~(I))

the following property:

a

~' ~

p r o v i d e d that the a r g u m e n t schemes have suitable types. 171 this is c a l l e d the

~ - clone of

F r o m n o r m a l form theorems for (2)

such that

B ( ~ ( I ) ) n _= L

(iii)

WAND

L & rec(~(I)) n

~ - rec(~(I))I

(In the t e r m i n o l o g y of

B(~(I))n.)

~ - clones i t can be d e r i v e d that

is e q u i v a l e n t to the class o f regular e q u a t i o n schemes w i t h

p a r a m e t e r s in the sense of

GOGUEN / THATCHER

131,

and that (3)

~ - rec(~(I)) 2

is e q u i v a l e n t to the class of r e c u r s i o n e q u a t i o n schemes w i t h

o p e r a t i o n parameters, Moreover, (4)

a slight g e n e r a l i z a t i o n o f

N I V A T ' s r e c u r s i o n schemes

c o m b i n a t o r schemes can b e r e d u c e d to these schemes:

For each

n /> 1

and S ~ rec(~(I)) n there is m > 1 and n+m such t h a t S ~ (... (S'I) I)...!).

S' g ~ - rec(~(I))

t

m--~

S i n c e w e w a n t to use h i g h e r types o n l y as an a u x i l i a r y device for g e n e r a t i n g low i level o b j e c t s our i n t e r e s t c o n c e n t r a t e s on the class rec(~(I) ) of "operational" c o m b i n a t o r schemes. F r o m some h i g h e r - t y p e

(4) we k n o w that e v e r y such scheme can be o b t a i n e d from

~ - clone

scheme b y i t e r a t e d applications.

This leads to the

following d e f i n i t i o n : - rec(~(I)) nI := {(. .. ((S i)I). .._l) I S C ~ - r e c ( ~ ( I ) ) n U--n-I ---~

T (S)

suitable}

T h e n we can p r o v e the f o l l o w i n g h i e r a r c h y of schemes: (5)

~ - rec(~(I))~

Moreover, (6)

in

DAMM

is t r a n s l a t a b l e into

~ - r e c ( ~ ( I ) ) l +I

Iii we find a p r o o f of

~ - rec(~(I)) 2 i

is n o t translatable into

It should b e n o t e d that

(6)

i ~ - rec(~(I)) 1

requires certain r e s t r i c t i o n s o n

contains only m o n a d i c function symbols the classes of

(6)

~.

E.g., if

are intertranslatable.

161.

358

7. C o n c l u s i o n

This d i s c u s s i o n leads to the p r o b l e m w h e t h e r the h i e r a r c h y of (5) is strict. A p o s i t i v e answer w o u l d d e m o n s t r a t e that p r o c e d u r e s w i t h recursion on h i g h e r types e n l a r g e the c o m p u t a t i o n a l p o w e r o f a p r o g r a m m i n g language.

This r e s e a r c h is b e i n g c o n t i n u e d in c o l l a b o r a t i o n w i t h Werner

DAMM, a n d I take the

o p p o r t u n i t y to thank h i m for m a n y h e l p f u l and s t i m u l a t i n g discussions.

8. R e f e r e n c e s

It1

DAMM, W.:

E i n f a c h - r e k u r s i v e und rekursive S c h e m a t a m i t s t e t i g e n I n t e r p r e t a t i o n e n - D i p l o m a r b e i t Bonn (1976)

121

E N G E L F R I E T , J. :

Simple P r o g r a m Schemes and For]hal L a n g u a g e s L e c t u r e Notes in C o m p u t e r Science 2_~o (1974)

131

G O G ~ N , J.A., THATCHER, J.W. :

Initial A l g e b r a Semantics IEEE Conf. Rec. SWAT 15 (1974), 63 - 77

141

GREIBACH,

T h e o r y o f P r o g r a m Structures: Schemes, Semantics, V e r i f i c a t i o n - Lecture Notes in C o m p u t e r Science 3 6

Isl

INDERMARK, K. :

Theorie rekursiver Definitionen V o r l e s u n g , U n i v e r s i t ~ t B o n n (1975)

161

NIVAT, M. :

O n the I n t e r p r e t a t i o n of R e c u r s i v e P r o g r a m Schemes IRIA - R a p p o r t de R e c h e r c h e 8 4 (1974)

171

WAleD, M. :

A C o n c r e t e A p p r o a c h to A b s t r a c t R e c u r s i v e D e f i n i t i o n s in: Automata, Languages, and P r o g r a m m i n g (ed. NIVAT), A m s t e r d a m (1973), 331 - 341

S.A. :

(1975)