dt1 introduction combinatory logic offers a practical approach to the implementations of func-tional...

30
N Capturing Strong Reduction in Director String Calculus by DT .5C SECTE AUG 3 0 1990 Vugranam Sreedhar and Kazem Taghva Department of Computer Science University of Nevada, Las Vegas July 5, 1990 CSR-90-38 Abstract A modified version of Director String Calculus (MDSC) is intro- duced which preserves the applicative structure of the original lambda terms and captures the strong reduction as opposed to weak reduction of the original Director String Calculus (DSC). Futhermore, MDSC provides an environment which supports the nonatomic nature of the substitution operation and hence can lend itself to parallel and optimal reduction. 'This research was supported in part by U. S. Army Research Office under grant DAAL03-87-G-0004 _ 9 o2 8 O

Upload: others

Post on 01-Jun-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

N Capturing Strong Reduction inDirector String Calculus

byDT .5CSECTE

AUG 3 0 1990 Vugranam Sreedhar and Kazem Taghva

Department of Computer ScienceUniversity of Nevada, Las Vegas

July 5, 1990

CSR-90-38

Abstract

A modified version of Director String Calculus (MDSC) is intro-duced which preserves the applicative structure of the original lambdaterms and captures the strong reduction as opposed to weak reductionof the original Director String Calculus (DSC). Futhermore, MDSCprovides an environment which supports the nonatomic nature of thesubstitution operation and hence can lend itself to parallel and optimalreduction.

'This research was supported in part by U. S. Army Research Office under grantDAAL03-87-G-0004

_ 9 o2 8 O

Page 2: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

i I.

Form ApprovedREPORT DOCUMENTATION PAGE OMB No. 0704-0188

Puylei report.ng Ourcenf for this .ciiectson of ,nformation s estimated to average flour Per restmnse. ,nciuvng te time tot reiew.ng nstrz,o-%. iearh.nq exrating data sources.gathenq and maintainsg the data needed, and ,omsteting and tevieinfg the claecti n of ,rformaton. Send comment regarding th$ orden et.mate or any oither amnect of :h-s,coIectzon ti inlformation. .nucing suggestions tot reducing this ourden. to ,wasnngton rieadquarten Services, Zisrectcrate for ,nformat,on Ooerations and Reports. 12:5 ,efferwvnDavis tighway. Sute 204. Adington. vA 22202-4302. and to the Office of Management and 8udget. Paperwork Reduction ProjeCt t0704-0 288). hashgton. C 2003.

1. AGENCY USE ONLY (Leave blank) 2. REPORT DATE 3. REPORT TYPE AND DATES COVERED

1 1990 Technical4. TITLE AND SUBTITLE 5. FUNDING NUMBERS

Capturing Strong Reduction in Director String

Calculus DAAL03-87-G-0004

6. AUTHOR(S)

Vugranam Sreedhar and Kacem Taghva

7. PERFORMING ORGANIZATION NAME(S) AND ADDRESS(ES) 8. PERFORMING ORGANIZATION

REPORT NUMBER

Univ of Nevada

Las Vegas, Nevada 89154-4019

9. SPONSORINGI MONITORING AGENCY NAME(S) AND ADDRESS(ES) 10. SPONSORINGI MONITORING

U. S. Army Research Office AGENCY REPORT NUMBER

P. 0. Box 12211Research Triangle Park, NC 27709-2211 ARO 24960.52-MA-REP

11. SUPPLEMENTARY NOTES

The view, opinions and/or findings contained in this report are those of theauthor(s) and should not be construed as an official Department of the Armyposition, policy, or decision, unless so designated by other documentation.

12a. DISTRIBUTION /AVAILABILITY STATEMENT 12b. DISTRIBUTION CODE

Approved for public release; distribution unlimited.

13. ABSTRACT (Maximum 200 words)

A modified version of Director String Calculus (MDSC) is intro-duced which preserves the applicative structure of the original lambdaterms and captures the strong reduction as opposed to weak reductionof the original Director String Calculus (DSC). Futhermore, MDSCprovides an environment which supports the nonatomic nature of thesubstitution operation and hence can lend itself to parallel and optimalreduction.

14. SUBJECT TERMS 15. NUMBER OF PAGES28

16. PRICE CODE

17. SECURITY CLASSIFICATION 18. SECURITY CLASSIFICATION 19. SECURITY CLASSIFICATION 20. LIMITATION OF ABSTRACT

OF REPORT OF THIS PAGE OF ABSTRACT

UNCLASSIFIED UNCLASSIFIED UNCLASSIFIED ULNSN 7540-01-280-5500 Standard Form 298 (Rev. 2-89)

Prescribed by ANSI Std. Z39-18298-102

Page 3: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

1 Introduction

Combinatory logic offers a practical approach to the implementations of func-

tional languages (6, 12]. Generally, the implementations involve removal of

variables from the text by introducing abstractions such as A, and then trans-

lating the new text into combinatory logic [3, 15. However, as O'Donnell and

Strandh [111 point out, the translation from A-calculus to combinatory logic

disables some of the redexes present in the original term; and consequently

avoids the possibility of doing parallel reductions. Furthermore, the size of

the term in the combinatory logic tends to be larger than the corresponding

A-term. It is also apparent from the literature that one of the main problems

in this approach is the operation of substitution in P-reduction [11, 13].

Kennaway and Sleep [8] introduced director strings as combinators to

formally study the approach taken by Turner. Director strings also provide

an intuitive interpretation of the reduction rules of the combinators to explain

what combinators achieve. Director string implementation of A-calculus as

shown in [8] involves weak reduction according to Hindley et al [5]. In this

paper, we introduce a modified version of director string calculus and obtain

the strong reduction. In addition, our approach intuitively supports the

nonatomic nature of substitutiion as explained in [11, 13] and lends itself to

parallel and optimal reduction [4, 7, 9, 10, 14].

We assume that the readers are familiar with [8] throughout the rest of

this paper.

$

Page 4: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

2 Preliminaries

In this section, we will introduce some notations and preliminaries which will

be used throughout the rest of the paper. As usual [1], let VAR be the set

of variables, then the set of A-terms A is defined inductively to be:

1. x is a term, where x E VAR.

2. (EF) is a term, where E, F E A.

3. Ax.E is a term, where x E VAR, and E E A.

An occurence of a variable x in a A-term E is bound if it is inside a sub-

term of the form Ax.F, otherwise it is free. We will use subscripts to encode

the freeness or otherwise of the variable x in a term. For example, E. de-

notes the A-term E with free variable x. Kennaway and Sleep [8] introduced

director symbols A, /, \, - to abstract a variable from an application using

the following six rules:

Accesion For1. CRAMI

DTIC TAB 02. Ax.(E.F) 1 ((,Ax.E.)F) Unannoiced 0

Justlficzxtlu ,

3. Ax.(EFx) \(E(Ax.F.)) ByOisti ibutton I

4. Ax.(EF) -- -(EF) Availabiity Codes

Avail and I or5. Ax.x -Dist Soecial

tPA-

Page 5: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

6. Ax.y - (Ky), where K and I are the standard combinators

Here, the objective is to move abstraction through an application, leaving

a directing symbol behind. For example, the second rule says, the abstraction

of x from a combination in which x occurs free in E but not in F can be

encoded as a "send to the left"' director symbol, denoted by /. The graph

notation [121 represents a natural interpretation for these rules. For example,

the term AxAy.xy is transformed using the above rules in figure .Ax

x I IA

Figure 1

and the A-term Ax.((Ay.xy)x) is transformed in figure 2.Ax

Ay X A

I1@

Figure 2

Director string calculus is defined as a term rewriting system with sym-

bols from VARu{fA, /, \, -, #, A } together with pair and triple constructors.

Informally, the three unary operators #,!, and A are interpreted as "dis-

3

Page 6: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

card", "insert", and "hole" respectively, and the four binary operators A,/, \

and - are interpreted as "both ways", "send to left", "send to right", andneither wav" respectively. Following [8], the A-terms Ax.Ay.xy and A-term

Ax.((Ay.xy)x) are written as

(/A,(0, A),(01,A))

and

(A, A/,(,,.) ! ) ! ))

respectively. Observe that the last two expressions represent the trees in

figure 1 and figure 2 with I's replaced by (!, A). Now, let @1, @2, d, and D

denote empty unary, empty binary, arbitrary director symbol, and arbitrary

direztor string respectively. Then the rules of [8] defines how the terms are

reduced in director string calculus.

1. (@2,(AD, El,E 2),E 3) (D,(@2, El,E 3),(@2, E2,E3))

2. (@2, (ID, El, E2), E3) (D, (@2, El, E3), E2)

3. (@2, (\D, El, E2), E.) - (D, El, (@2, E2, E3))

4. (@2,(-D,El,E 2),E.) - (D,El,E 2)

5. (@2,(!D,E 1),E-2) --+ (D,(@2,E,,E2))

6. (@2,(#D,E),E2 ) -+ (D,E)

7. (@2, A, El) -- El

4

Page 7: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

I

Now, the expression (Ax.Ay.xy)EF can be reduced to (EF) with the

above conversion rules. String director calculus is not capable of strong

reduction as our second example Ax.((Ay.xy)x)) can not be reduced further,

although it can be reduced in A-calculus to Ax.xx.

In the next section, we will give a modified string director calculus which

is capable of strong reduction.

3 Modified Director String Calculus

Modified Director String Calculus (MDSC) has the same set of unary opera-

tors {!, -, A} and four binary operators {/\,-\,/-,--} together with pair

and triple constructors. The binary director symbols {/\,/-,-\.--} have

the natural interpretations send both to left and right, send to left but not

right, send to right but not to left, send neither to left nor to right. Although

we are at liberty to choose one symbol for each binary operator, we prefer to

use two symbols and intuitively think of them as the right side and left side of

the binary operator. In addition, these two symbol operators make it easier

to explain our evaluation strategies. We will basically follow the notation of

[8] and let D, D1 , D2, d, @1 and @2 denote arbitrary director string, director

string over unary operatoi, director string over binary operator, arbitrary

director symbol, empty director string over unary operators, and empty di-

rector str;ng over binary operators respectively. We define Modified Director

String Terms(MDST) as follows:

5

Page 8: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

0 (DI. a) E MDST, where a is either a variable or A

(D1, E) E MDST, where E E MDST

* (D 2, E1 , E2) E MDST, where El, E2 E MDST

In order to go back and forth between A-calculus and MDSC, we utilize

a mixed A-calculus and Director String terms (MDSAT). We basically map

each term in A-calculus to a term in MDSAT by replacing each variable x

by (@j,x) and every application (EF) by (@2, E, F). This as in [8 embeds

the A-calculus into a system MDSA generated by the syntactic rules:

o E E MDST E E MDSAT

• E E MDST = Ax.E E MDSAT, where x is a variable.

Thus AfAz.f(fx) converts to the mixed term:

A fAx.(@2, A@, A) A@, A@, A) A@, X)))

Then we define a translation from A-terms in MDSAT to MDST, which

removes all A's and bound variables.

SAx.(DI, x) -+ (!DI ,A)

o Ax.(DI,A) - (#Dl,A)

* Ax.(DI,y) -+ (#Di,y), where x y

o Ax.(D 2, E,, F,) -* (/\D2 , (Ax.E=), (Ax.F,))

6

Page 9: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

* Ax.(D 2 .E=,F) ( - D2 , (Ax.E=), (Ax.F))

e Ax.(D 2,E=,F)-, (-\D2, (Ax.E), (Az.F))

e Ax.(D 2 , E., Fx) -- - D2 , (Ax.E), (Ax.F))

Example 3.1 The term AfAx.f(fx) will be written as follows:

A A

Af.(-\, t x.h(ee , fe),Ax.(@2, (@li, f),(@, x)))

(A\- \,(0#, A), I(/- -\, (, f),(:f! A)))

One may represent the last expression as the tree shown in figure 3.

ing at the root the first argument to this expression will go both ways, the

77

Page 10: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

second argument to right but not to left, at the next tree level, for exam-

ple, the left subtree says insert the first argument and discard the second

argument. We will continue to use the tree structure to explain the conver-

sion rules. We also want to point out that the translation does preserve the

applicative structure of the original A-term.

Proposition 3.1 The abstraction rules are confluent and terminating. Ev-

ery A-term has a unique normal form, and this normal form is a MDS term.

Proof: Similar to the proof of Proposition 2.2.1 in [8].

0

4 Conversion Rules

In this section, we will introduce our conversion rules and give detailed exam-

ples to illustrate the difference between MDS and the original DS. Before we

formally write our conversion rules, we need three basic operations, namely

insert, shift, and remove.

Let E E MDS and ij be natural numbers, then:

0 shift(E, i,j) is defined to be a term F E MDS obtained from E by

shifting (i + 1)th director j places to the right for each director string

in E.

* insert(E,i,j) is also defined to be a term G E MDS obtained from E

by inserting j numbers of -- between (i + 1) and (i + 2) positions of

8

Page 11: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

--.

£

each binary director string E, and inserting j numbers of # between

(i + 1) and (i + 2) positions of each unary director string in E.

* remove(E, i) is defined to be a term H E MDS obtained from E by

removing (i + 1)st director of every director in E.

Example 4.1 Let E denote (-\--/-,(#!,A), (!#,A)), then

shift(E. 1, 1) = - -- ,( , A),(!##,A))

insert(E, 1,1) = - -/-, (###!, A), (!###, A))

remove(E, 1) = (-\/-, (#!, A), (!#, A))

The operation insert will be used to avoid variable clashes (ce-conversion),

shift will be used to preserve the correspondence between a director and its

binding, and remove will be used to indicate that a f-reduction is done and

that a particular director will not be needed further.

In order to make our conversion rules easier to understand, we will use

tree representation. Basically, we have two types of rules: the binary rules

and the unary rules.

I. Binary Rules The left hand side of each binary rule is of the form:

(D, (UdV, -E, E2), E 3)

where D, U, V are director strings, d is a single d;rector, and the length of

D is equal to length of the U, i.e., ID = IUI (whenever the length of the

|9

Page 12: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

director string of the left child is bigger than the length of the director string

of the parent, we have a redex).

The tree representation is then:D

UdV E3

Figure 4

We will use p, r and I for parent, right child, and left child respectively,

and give computation rules for evaluating parent, left child, and right child

director strings.

1.1

(D, (U/\V, E1, E2), E3)

(UPV P, (U'V', shift(Ei, IU1, IVI), insert(E3, IUI, IVi)),

(U'Vr, shift(E2, IUI, lVI), insert(E3 , IUI, IVI)))

Pictorially, the tree in figure 4 is converted to the tree in figure 5 which says

E1 and E2 will take E3 as an argument.UPVP

'V UVwhere E' = shift(El, jUI, IVI)uIvi uv shift(E2, IUI, IVI)

E3 insert(E3, JUI, jVI)|El E' E3

3 -E3

Figure 5

10

7

Page 13: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

1.2

(D, (U/ - V, El,E2),E3 )

remove(E2, iUl))

Upvp

E2V where E' = shift(El, IUI, IVI)=P remove(E2, Ii)=3 insert(E3, IUI, IVI)

Figure 6

1.3

(D, (U -V, El,E2), E3 ) -

(Urvr, shift(E2, IUI, lVI), insert(E3, IUI, IVI)))

Upvp

EurVr where E' remove(E1 , IUI)E2 shift(E2, IUI, IVI)

Figure 7

t

Page 14: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

1.4

(D.,(U- -VElE2), E3)

(UPVP, remove(El, IUI), remove(E 2, IUI))

Upvpwhere E' =remove(El, JUI)

E2= remove(E2, JUI)Ef E

Figure 8

II. Unary Rules: The left hand side of each unary rule is of the form

(D, (UdV, E1), E3) - E3

where D is a binary director string, UdV is an unary director string, and

IDI =UI.

(D,(U!V,EI),E 3) E3

Pictorially, figure 8 is converted to a tree with one node labelled by E3.D

U!V E3 E3

El

Figure 9

11.2

(D,(U#V,EI),E3 ) -- (UV, E)

12

Page 15: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

Pictorially, in figure 10, the figure on the left is converted to the figure

on the right.D

UVU#V E3 >

Figure 10

We now explain in detail how to construct director strings UPVP, U'V' and

UrVr. Let D = dld 2 .. .dk, U = UlU2 ... uk, and V = V 1V2 .. Vm. Intuitively

di's and ui's refer to the distribution of the variables over left and right

expressions in an application. Again referring to figure 4, observe that when

d = a particular variable occurs in both E1 and E2, and hence E3 will

be substituted for that variable in both E1 and E2. Also, we point out that

after substitution, the variables of E3 now occur in both (E1E3) and (E2E3).

Let di, d2 ,... , dk refer to variables X 1 ,z,... , Xk, then essentially di says

how xi is distributed over E3 and (E1E2). If di = q- (where q may be -

or /), then di says that xi does not occur in E3 . Hence after reduction, xz

occurs in (E1E3) or (E2E3) only if it occurred in E1 or E 2 before reduction.

This gives two cases, depending on whether xi occurs in E 3 or not:

1. if di = q-, where q E {-,/}, then u? = ui and Ur and U' are defined

as follows depending on ui (observe that there may be no U1 or U' in

some cases such as 1.2, 1.3, or 1.4):

13

Page 16: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

iL

(a) u =/\, then ,., I-

(b) u = /-,then 4 =--

(c) ui = -\, then u( - =-

(d) ui = -- ,then u = -u --

vp= v

2. if di = q\, where q E {-,/}, then UP is defined as follows depending

on d:

(a) if d =/\, then u? =/\

(b) if d =/-, then u? =/- when ui = s- and uP =/\ when ui = s\,

where s E {-,/}.

(c) if d = -\ then u' = -\ when ui = -s and uf =/\ when ui = \s,

where s e {-, \}.

(d) if d -- , then uf -ui

and U" and U1 are defined as follows depending on ui:

(a) u =/\, then u= u=/\

(b) ui = / - then u si =/ , ,r = _

(c) ui = -\, then u( =-

(d) uj = then u( " ur -

14

)

Page 17: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

VP V

Now again, let v1,v 2,... ,vm refer to variables Y1,Y2 ...Yin. We point

out that yj's represent the list of variables which do not occur in E3 .

Here is a complete set of rules for evaluating vis and vF's:

(a) if vi =/\, then v! =v=1-

(b) if vi = /- then v! =/_,4 = --

(c) ifv = -\,thenv= -- ,v =/-

(d) if vj = , then v -4 = --

Example 4.2 Consider the A-expression

4.(Ax.Ay.x(yf))Ap.p

or equivalently

U/-, M-/- _\IOar,#, A), (- _ /-, (##, -4 (4-7a, 4), Oa", A))

in MDSC. Pictorially, we will show the evaluation in detail. For clarity, we

will use asterisk to mark the node where the next reduction occurs.

15

Page 18: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

Af

I I-

t@

ly I

I I

Fgr 11.1/* / .\I... /'\T

Figure 1i

This last tree represents the A-term AfAy.(yf) which is the normal form of

the original A-expression.

Appendix A gives a reduction for a more detailed example.

Theorem 4.1 MDSC is confluent.

Proof: Similar to the proof of theorem 2.3.1 in (8].

0

Remark: Conversion rule 1.4 upon application can cause a minor problem

which we address here. Consider the A-expression and its MDS equivalent

expression in figure 12.

I16

Page 19: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

AX.

I Pq/I \

Aq x q

S# I

P P P

Figure 12

After applying 1.4 at., we get the tree in figure 13.I-

/\

qP Ip p

Figure 13

Starting at the root in figure 12, the director/- says that x occurs in the

left subtree, the next node labelled by /\ says that x occurs both in the left

and right subtree, the next node labelled by -\ says x occurs in the right

17

Page 20: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

subtree, and the next node says x occurs neither in the right subtree nor left

subtree. Although it causes no problem when the tree is applied to some

argument, it is not representing the same expression in A-calculus, according

to our definition of abstraction rules, after the corresponding /-reduction.

The problem is due to the reduction (Aq.pp)x. The solution is easy, we start

at *-node in figure 12 and move up the tree towards the root converting each

directors of the form/- or -\ to --. If we encounter a director of the

form /\, then convert/\ to -\ or/- depending on the direction we went

up the tree and stop. This has to be done for each director d of the type -\

at *-node. We call this operation backtracking. Figure 14 shows the result

of this process. Now, we apply rule 1.4 at *-node in figure 14. Backtracting

and rule 1.4 has to be done one after another and cannot be separated.I-

q -\

I IP p

Figure 14

Now we can apply 1.4. The same problem can also be caused by # in rule

818

Page 21: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

11.2 and the solution is the same. From now on, we assume the backtracking

operation is done when necessary.

5 Translating MDS terms to A-terms

In this section, we will show how to translate MDS terms back to A-terms

using the following rules:

1. A --+ Ax.x. where x is a new variable

2. (!D, Ax.x) -- Ax.(D,x)

3. (#D, y) --+ Ax.(D, y), where x is a new variable

4. (i\D, Ax.E, Ay.F) --* Az.(D,E[x := z],F[y := z]), where z is a new

variable

5. (/- D, Ax.E, Ay.F) --+ Az.(D,E[x z],F), where z is a new variable

6. (-\D, Ax.E, Ay.F) - Az.(D, E, F[y := z]), where z is a new variable

7. (- - D, Ax.E, Ay.F) -- Az.(D, E, F) where z is a new variable

Rules (1) to (7) convert MDS terms into MDSA terms. The following two

rules convert MDSA terms into A-terms:

L. (@,,E) -1

2. (@2, E, F) --+ (E)

19

Page 22: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

Example 5.1 Consider the A-expression

Af.((AxAy.((xf)y))Ap.p).

The equivalent MDS expression is

We first translate subterms.

-a#I -, 4) -+ (#!#-, Axi.xi)

-+AX 2 Ax.(#, xi)

-4AX 2AxAX3 (@,Xl)

Similarly,

(!##,A) -+AX 4 AxsAX6 (@I, X4),

and

(##!,) -4AM 7AX8Ax 9(@i,Xg),

and

(!,) AjIxj@~j)

20

Page 23: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

I-I

For the subterm

_I- -- , , A), (!##, A))

- \/- -- , ,A2AiA .(@, x), AX4Ax5A 6.(@I, X4 )

,X,2.(/- -- , Ax,Ax 3.(@1, xj), AX 5 A ,.(@,, X1 2 )

-4Axi 2Ax 3.(--, AX3.(@I, X13), .\X6.(@1 , X12)

Ax, 2A1 3Ax 4.(@2 , (91, X13), (@1, X12))

Similarly, for the subterm

(/ -/- -\, AX 2 Ax 3 Axl 4,(@ 2 , (@I, X13 ), (@I, X 1 2)), AX7AX8Ax(@ 1 , x9))

-+ Axis.(/ - -\, Ax, 3 AxI 4 .(@2 , (@I, X13 ), (@,, x1 )), Ax8Ax9 (@,, x9 ))

-~AxIsAxl6 (-\, Ax 14 .(@2 , (%~, X1 6 ), (@I, X15)), Ax9(@i, x9 ))

And finally,

(I-,( U - -\, (-V - __--70!# A), (!#r, A)), (##!," A)), 0011, A))

Axl,.(,AX,6AX,7.(@2, (@2, (@1, X16), (@I, X,1,)), (@I, X17)), Axi(,,(, x,,))

Translating to A-calculus,

Ax, 8.(AX 16AX17 .((Xl 6X,8)x, 7)Axii .x11 ).

This is equivalent to the original lambda term up to a-conversion.

I21

Page 24: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

Theorem 5.1 Every MDS expression E has a unique normal form with re-

spect to these rules. Furthermore, for each A-term E, if we translate E into

MDS term, denoted by F(E), and translate F(E) back to A-term, denoted by

B(F(E)), then B(F(E)) = E (up to a-conversion).

Proof:

1. E = \x, ... x .x

B(F(E)) = B((D. A)) where D = #x!#- if x iB(F(E)) = B((D,x)) where D =#n ifnox=x

= E (upto a - conversion)

2. E = Ax1 ... x,.(FG)

First consider F(E). First, we rewrite Ax,.(FG) giving (H,, Axn.F, Ax,.G).

d, is /\, /-, -\, or -- , depending upon the free occurrence of x in F

and/or G. Next, we reduce

,Axn-I (dn, A znF, Axn.G)

giving

( d,._ldn) , Xnx,_n.F, Ax~rn-l Xn.G).

Continuing this process for all lambdas in the outer most parentheses,

we get

F(E) = F((D, Ax, ... Xn.F, Axi ... x,.G))

= (D, F(Ax, ... x,.F), F(Ax, ... x,.G)).I

22

It

Page 25: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

Hence, B(F(E)) = B((D, F(Ax ... x,.F),F(Axi...x,,.G)). By con-

flunce of the B-rules, we can evaluate the right hand side by first eval-

uating each subexpression giving

B(F(E)) = B((D,F(Axi .. .x,.F),F(Ax, ... x,.G))

= B((D,B(F(Axi ... x,.F)), B(F(Ax x...x,.G)))

= B((D, Ax, ... x,,.F, Ax1 ... x,.G)).

We can now apply B-rules to eliminate D, giving

B((D, Ax, ... x,,.F, Ax1 ... x,.G)) = Ax, ... x..(FG) = E.

6 Conclusion

We have modified director string calculus to obtain strong reduction as op-

posed to weak reduction given in [8]. in addition, this mudified calculus

can be considered as a different implementation of A-calculus. Particularly,

the subsitution operation supports the ideas given by Revesz in [13] and

O'Donnell and Strandh in [11].

MDSC provides an environment in which, one can further study and

implement optimal reduction and parallel reduction [4, 7, 9, 10, 141. There

is also a close relationship between the position of a director in the director

string and de Bruijn number [2]. This is basically the way both MDSC and de

23

I

Page 26: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

R

I

Bruijn calculus avoid a-conversion. We intend to point out these connections

in detail in our upcoming paper.

References

[1) BARENDREGT, H. P. The Lambda Calculus - its syntax and semantics.

North Holland, 1981, 1984.

[2] DE BRUIJN, N. G. Lambda calculus notation with nameless dummies.

Inagationes Mathematicae S.; (1972), 381-392.

[3] DIJKSTRA, E. W. A mild variant of combinatory logic. Unpublished

note. EWD735, 1980.

[4] FIELD, J., AND TEITELBAUM, T. On laziness and optimality in lambda

interpreters: Tools for specification and analysis. In Proceedings of Prin-

ciples of Programming Languages (January 1990), ACM, ACM Press.

[5] HINDLEY, J. R., LERCHER, B., AND SELDIN, J. P. Introduction to

combinatory logic. Cambridge University Press, 1972.

[61 HUDAK, P., AND KRANZ, D. A combinator-based compiler for a func-

tional language. In 11th A CM Symposium on Principles of Programming

Languages (1984), ACM, pp. 121-132.

24

Page 27: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

[7] HUDAK, P., AND MOHR, E. Graphinators and the duality of SIMD and

MIMD. In Proceedings 1988 ACM Conference on Lisp and Functional

Programming (1988), pp. 224-234.

[8] KENNAWAY, R., AND SLEEP, R. Director strings as combinators. ACM

Trans. on Programming Languages and Systems 10, 4 (October 1988),

602-626.

[9] LAMPING, J. An algorithm for optimal lambda calculus reduction. In

Proceedings of Principles of Programming Languages (January 1990),

ACM. See also his earlier draft.

[10] LEVY, J. J. Optimal reductions in the lambda-calculus. In To H. B.

Curry: Essays on Combinatory logic, Lambda Calculus, and Formalism.

Academic Press, 1980.

[11] O'DONNELL, M. J., AND STRANDH, R. I. Toward a fully parallel

implementation of the lambda calculus. Tech. Rep. JHU/EECS-84/13,

The Johns Hopkins University, 1984.

[12] PEYTON-JONES, S. The Implementation of Functional Programming

Languages. Prentice-Hall International, Englewood Cliffs, NJ, 1987.

[13] REVESZ, G. Axioms for the theory of lambda-conversion. SIAM Journal

of Computing 14, 2 (May 1985).

25

I

Page 28: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

[14] STAPLES. J. Optimal evaluations of graph-like expressions. Theoretical

Computer Science 10 (1980), 297-316.

[15] TURNER, D. A. A new implementation technique for applicative lan-

guages. Software-Practice and Experience 9 (1979), 31-49.

A Church's Numeral02

Ax Ax

Ky ly I-i j I--\ ! /\

x y x y A A A

#1-

6t !# #I#A I\I I I

26

Page 29: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

-- L

1

I *

A A

I I -- I'-'

A A A

A

-\* L

IA A A

I I

I27

Page 30: DT1 Introduction Combinatory logic offers a practical approach to the implementations of func-tional languages (6, 12]. Generally, the implementations involve removal of variables

TI 1

AA

A Ay

A @#

x

28