5
Vol.6 No. 1 J. of Comput. Sci. & Technol. 1991 Construction of the Model of the Lambda Calculus System with Algebraic Operators Lu Ruzhan (NNdi), Zhang Zheng (~ N) and Sun Yongqiang (~J~7~:~) Department of Computer Science, Shanghai Jiao Tong University, Shanghai 200030 Received January 20, 1989; revised July 19, 1989. Abstract A lambda system with algebraic operators, lambda-plus system, is introduced. After giving the definitions of the system, we present a s~cient condition for formulating a model of the system. Finally, a model of such system is constructed. 1. Introduction Lambda calculus is a formal theory which describes the properties of the functionals and the combination of the functionals. It is the basis of functional programming. There is a well-formed theory for pure lambda calculus. But the pure lambda calculus system is simple and its representability is limited. Functional programming languages are usually formed by adding some initial constants to the pure lambda calculus system. The representability of these systems is powerful. However, these systems are quite different from each other and lack of a unified theo- ry. Hence, it is necessary to seek for more general formal system. In [ 1] a lambda calculus sys- tem with algebraic operators is presented, which extends the idea of abstraction and gives more general inference rules. It can be the most fundamental theory of functional programming lan- guages. The system has the following features: 1)treating the lambda calculus system with con- stants in a unified way; 2) the idea of structure and structure abstraction can make some com- putations more convenient and sound; 3)describing and representing dat~ structure and opera- tions upon them more naturally and clearly. The definition of the grammar of the system is given in [ 1]. In this paper, we discuss its semantic model, first, the definitions of the model, and then a model of the system. 2. The Lambda Calculus with Algebraic Operators Let N ={0, 1, 2,..., }, ~={0, 1, -.-, n-l}. A signature is a pair (F, r where F is a non-empty set of symbols and q~ a map from F to N. For all ne N, we denote Fn={feFI q~C) =n }. The elements of Fn are called n-ary algebraic operators. Definition 1. Let oars be a set of variables, and Z be a signature. The term set upon oars is defined recursively as follows : 1 ) oars ~ T z (oars) 2 ) forfe F, ifrp (f)=0, then fe Tz (oars) 3) for f ~ F, if ~o(f ) =n >0, and to'" tn-l S Tx (vars ) then f (to ,"-, tn-I )e Tz (vars ). Definition 2. A Y-algebraic spec~'ication is a set of Z-equations. Each equation has the form l=r, where l, reTx(vars). Def'mition 3. Let feFn. For all ien , if there exists P} (Yo ,'", Ym) E T x (oars), which satis- fies {Y0'"" Ym } n {x0,---, x_ l }= ~b, where m is a natural number determined by i and f, and Supported by Chinese Natural Science Foundation.

Construction of the model of the lambda calculus system with algebraic operators

Embed Size (px)

Citation preview

Page 1: Construction of the model of the lambda calculus system with algebraic operators

Vol.6 No. 1 J. of Comput. Sci. & Technol. 1991

Construction of the Model of the Lambda Calculus System with Algebraic Operators

Lu Ruzhan (NNdi) , Zhang Zheng ( ~ N) and Sun Yongqiang (~J~7~:~) Department of Computer Science, Shanghai Jiao Tong University, Shanghai 200030

Received January 20, 1989; revised July 19, 1989.

Abstract

A lambda system with algebraic operators, lambda-plus system, is introduced. After giving the definitions of the system, we present a s ~ c i e n t condition for formulating a model of the system. Finally, a model of such system is constructed.

1. Introduction

Lambda calculus is a formal theory which describes the properties of the functionals and the combinat ion of the functionals. It is the basis of functional programming. There is a well-formed theory for pure lambda calculus. But the pure lambda calculus system is simple and its representability is limited. Funct ional programming languages are usually formed by adding some initial constants to the pure lambda calculus system. The representability of these systems is powerful. However, these systems are quite different from each other and lack of a unified theo- ry. Hence, it is necessary to seek for more general formal system. In [ 1] a lambda calculus sys- tem with algebraic operators is presented, which extends the idea of abstraction and gives more general inference rules. It can be the most fundamental theory of functional programming lan- guages. The system has the following features: 1)treating the lambda calculus system with con- stants in a unified way; 2) the idea of structure and structure abstraction can make some com- putations more convenient and sound; 3)describing and representing dat~ structure and opera- tions upon them more naturally and clearly.

The definition of the grammar of the system is given in [ 1]. In this paper, we discuss its semantic model, first, the definitions of the model, and then a model of the system.

2. The Lambda Calculus with Algebraic Operators

Let N = { 0 , 1, 2 , . . . , }, ~ = { 0 , 1, -.-, n - l } . A signature is a pair (F , r where F is a non-empty set of symbols and q~ a map from F to N. For all n e N, we denote Fn={ feFI q~C) = n }. The elements of Fn are called n-ary algebraic operators.

Definition 1. Let oars be a set of variables, and Z be a signature. The term set upon oars is defined recursively as follows :

1 ) oars ~ T z (oars) 2 ) f o r f e F, ifrp ( f ) = 0 , then f e Tz (oars) 3) for f ~ F, i f ~o ( f ) =n >0, and to'" tn-l S Tx (vars ) then f (to ,"- , tn-I )e Tz (vars ).

Definition 2. A Y-algebraic spec~'ication is a set of Z-equations. Each equation has the form l=r, where l, reTx(vars) .

Def'mition 3. Let f e F n . For all i e n , if there exists P} (Yo , ' " , Ym) E T x (oars), which satis- fies {Y0 ' " " Ym } n {x0,---, x _ l } = ~b, where m is a natural number determined by i and f , and

Supported by Chinese Natural Science Foundation.

Page 2: Construction of the model of the lambda calculus system with algebraic operators

No.l Lambda Calculus System with Algebraic Operators 109

the following equations can be inferenced by E:

I~(yo , ' " , Yj-I , f ( xo , ' " , x , - i ), y j + p ' " , Ym ) = x i

then f is called structure operator using {(P) (Y0 , ' " , Ym ) 'J ) [ i ~ n } as representative, else f is called non-structure operator.

Definition 4. The set o f structure type over E(denoted as S ( E ) ) and the set o f f ree variables in a structure type ~ are defined recursively as fol lows:

1 ) i f x evars, then x e S ( E ) and V ( x ) = { x } . 2) i f ~ , . . . , otn_1e S ( E ) , n e N and for all i, j e n , V(ct i )c~ V ( ~ ) = r , or i = j , then for all

f e f ~ , (f], is the set o f r vary structure operators), f (oto , ... , ~,_I ) e S ( E ) and V ( f (oto , . . . , et,_l ) ) = ?-~ V (~ i ) .

Definition 5. The set o f lambda term Tz (vars ) is defined as follows : 1 ) i f x e vars, then x e T z (vars) 2 ) i f f eFo , then f e Tz (vars ) 3 ) i f M o , ' " , M , _ 1 e T z (vars), f e F , then f ( M o , ' " , M , _ l ) ~ T:E (vars) 4 ) i f M e Tz (vars) and ~ e S (E) then 2+c~. M e Tz (vars). Definition 6. Let M e T z ( v a r s ) . An occurrence o f M is a word o~ over N +, where N + is the

set o f positive integers. ~ is an empty word. We define : 1) M / 8 = M

2') f ( M o , " . , Mn-1 ) / i o 9 = M i _ l / o 9 3) 2+~.M/lco=ct /co 4) 2+ct.M/2co= M/a ) Definition 7. Formal system 2 + (E) is defined as follows : (I) Axioms

1) i f for O<~j<k, ije-n, p ( X o , . . . , x , _ l ) = q ( X i o , . . . , x ik_ l ) can be inferenced by E, then for all M i e T z ( v a r s ) , ie-n, p (M0,:--, M n - l ) = q ( M i o , ' " , M i k - l ) hold.

2 ) i f M can be substituted with respect to ~, then

(2+c~.M) " N = M [ o ~ "-- N] (ti-rule)

3) i f ~ , t i e S ( E ) , ~=ti/og, and y is a new variable, then

2 + ti. M = 2 + ti ( o9 " - y ) " M[ ~ ",-- y] (g~- rule ) ( I I ) Rules o f inference 1 ) M = M

2 ) if M1 = M 2 , M2 = M3 then Ml = M3 3) i f M l = M z , ~ e S ( E ) then 2+cc.Ml=2+~.M2 4) for all i e n , M i = M i ' , f e F . . f ( M o , "". M._~ )=f(M'0 , ' " , M: - i ) 5) i f M = M ', then N " M = N " M ' 6) i f M = M ", then M " N = M ' N 7) i f M = N , then N = M

The meaning of M [ ~ -~-- N] in ]?-rule and g~-rule i~: for each variable x in M, i f x e V ( ~ ) , then x is transformed to the representation ~ of x The structure type ~ is then replaced by N.

I f~ , t i e S ( E ) and t i=~/o9 then~(og----ti) is defined as follows :

2) F ( ~ , . . . , o ~ _ l ) ( i o ) - , - t i )= F(oto,...,o~i_ t (co"-- [1), . . . ,o~,-1) For example, if the following algebraic specification is given :

1st ((x,jr) ) = x 2nd ((x, y ) ) = y (Ist (x), 2nd ( x ) ) = x

Let us calculate the terms x[ ( x , y ) "~-- z] and ( ( x , y ) , z ) ( 1 2 " - ~ ) :

x [ ( x , y ) " - - z] = 1st ( (x ,y))[ ( x, y ) "-- z] = 1st (z)

( ~ x , y ) , z ) ( 1 2 ~ - cc)=(x ,y) (2 -.-- ~ ) , z ) = ( ( x , y ( 8 -~-- ~ ) ) , z ) = ( ( x , o t ) , z )

Page 3: Construction of the model of the lambda calculus system with algebraic operators

110 J. of Comput. Sci. & Technol. Vol. 6

3. Definitions of the Model of Lambda-Plus System

Definition 8. let Z denote the signature ( F , q~). The pari ( M , PM) is called E-algebra i f and only i f :

1 ) M is a non-empty set

2) for f~Fo , p g ( f ) ~ M 3 ) for f ~ F , , n>0 , p g ( f ) is a map from M n to M. Definition 9. Let (A , PA ) , (B, PB ) be two Y.-algebras. I f h is the map from A to B and sat-

isfies the following conditions, then h is called Z-homomorphism.

1) i f f ~ Fo, then h(pa ( f ) ) = p s ( f ) 2 ) i f f eFn , n > 0 and ai~ A, i ~ n, then h (PA 0 c) (a0 , " - , an- l)) =PB ( f ) (h ( a o ) , ' " , h (an- t ) ). Definition 10. Let ( M , PM ) be a E-algebra. For all maps h : vars --~ M, i f its extention h* :

( T z ( v a r s ) , , P z ) ~" ( M , pM) satisfies h*( l ) = h * ( r ) f o r all l=r in E, then ( M , p m ) is called a model of E, where E is a Z-algebraic specification.

Definition 11. Let ( M, pM , <~ m ) be a triple, where ( M, pm ) is Z-algebra and <~ m satisfies the following conditions :

1) there ex&ts - I - , _J_ ~M, for all x ~ M , X<~m-f- , I <~mX

2 ) for f ~ Fn, n>0 , i f x i <~mYi, i e n then pm( f ) (xo, . . . , xn_l ) <~g P r o ( f ) ( Yo, "" , Yn-I ) . We call ( M, PM, <~M ) continuous E-algebra.

Definition 12. Let ( M, pm , <~ m ) be continuous E-algebra, where ( M, pm ) is a model of E. Then ( M, PM, <~ m ) is called a continuous model o f E.

Definition 13. The model of lambda-plus system is defined as a triple ( D, ", [ ] ) , where I~ ] is a map from lambda term Tz (vars ) and variable assignment p to D. The following conditions rroz~t also be satisfied.

1) Ix] u = p(x ) 2) KP �9 a]p=~P]p �9 [ Q ] p

3) ~(2+c~ "P ) ' N ] p = [ ( P ] [PT~(x){x~N}/xlp , where x represents all variables in V(c~). PT~ (x ) is the selecting operator on ~. I t is defined as follows :

a) PT , ( x ) = x b) i f c~=F(%,...,7~_~ ) and x ~ , , then er , ( x ) = e T , i ( x ) { x ~ ffr(~F., X,-~F )}, where -~F,ZF

are new different variable arrays which correspond to the variables in structure operator representa live.

4) i f for all x e F V ( M ) , a ( x ) = p ( x ) , then ~ M ] ~ = ~ M ] p 5 ) [2 ~ + . M ] o = [2~(~o- y ). M [ ~'+-- y] ]p , where or, ~ E S ( E ) and o~=fl/eJ, y does not oc-

cur in M and ~ . 6) i f f o r all d e T z ( v a r s ) , ~ M [co'*--d] ]p = [ N [ 0 r d]]p , ~ S ( E ) , then [)]. +cr . M ~ p

= [).+o~ - N ] p 7) i f M = N can_be inferenced by E then KM]R=KN]p 8) i f for all i e n , [ M i ]p = [Ni ] p , f e F n , then [ f (Mo , "" , M n - l )]p =~:f (N0, , ' " , N , - l ) ]p . The following theorem gives a sufficient condition for being as a model of lambda-plus sys-

tem. Theorem 1. Let (D, PD, <~ ) be a continuous model o f E. I f (D, �9 ,[ ] ) is a model o f pure

lambda system, then (D, ", ~ ]+ ) is a model of lambda-plus system, where [ ]+ is defined as fol- lows :

+ = [ M ] p , i f M is a pure lambda term. 1) [ M ] v 2) [2+~ .M]~" =K2x . Mice-,- x ] ~ , o t iS (E ) and x is a new variable.

3) I f ( M 0 , " - , M , - I )]~ = P o ( f ) ( [ M 0 ] ~ , " , [Mn-a ]~ ), where f~Fn . 4) [If ] ~ =PDQ'), where f~Fo .

Proof. This will be done by verifying the eight conditions in Definition 13. For the reason of making the proof succinct, we only verify condition 4.

4- Condition 4 : for all x ~ F V ( M ) , i f c r ( x ) = p ( x ) then [ M ] + ~ = ~ M ] v .

Page 4: Construction of the model of the lambda calculus system with algebraic operators

No. 1 Lambda Calculus System with Algebraic Operators 111

We make induction on the structure of M : 1) if M i sa pure lambda term, then [(M]~ + - - ~ M ] ~ = ~ : M ] p = [ ( M ] ~ - 2) if M=fEFo , then ~M]+~=po(f )=[~M31~-. 3) if M = f ( M o , . . . , M . _ I ) w h e r e f E F and for all iEn-- ~Mi]~+=KMi]~, then

~ f ( M o ' " " Mn-l )] +=PD~r)(~Mo ] ~ , ' " ' ~Mn-I ]+a )

+ ~M. - l ] '~ ) = ~ f ( M o , " ' , M . - I ) ] p + = a n ( f ) (~Mo] p , -" , + then 4) if M=).~ +. N, where c~.e S(E) , ~:N] ~+ = [N ] p,

K2+c~ - N ] + = ~ 2 x -N[c~---- x] ]~= [2~ �9 N[cz-'-- x] ]p=~)o+ �9 N ] ~ �9

4. Construction of the Model of Lambda-Plus System

Let P = { ~ - , T }. We can get a free E-algebra ( T z ( P ) , p~)121. We define a partial order

1) for all xE T~(P) , x<~a T , I <~px 2) f o r f E F n , n>0 , if xi<~py i, where x i , Y i E T z ( P ) , i e n t h e n

p~ ( f ) ( x o , "", Xn--l) ~'.-r.pp zp ( f ) (Yo ' ' ' ' 'Y . - - l ) " Obviously, (Tz (P), pP z , ~<p) is a continuous E-algebra. Let R = T z ( P ) / ~ e , where ~ e is the congruence relation generated by E. If

f e Tz , (P) , the congruence class of f is denoted by Dr]. PR is defined as follows : 1) f o r f E F o , pR( f )=[ f ] 2) for f e F . , n>0 , PR ( f ) ([to], ' " , [t._j] ) = I f ( t 0 , ' " , t . - l ) ] It may be proved that [21 the definition of PR is independent of the selection of ti in [ti].

Thus we get a model of E : (R, p.~). For the elements in R, we define a partial order ~<R :

X<<.Ry ~ ~ t l . , t2ET z (P), x = [ t l ] , y = [ t 2] and tl<~pt 2 . Theorem 2. (R, PR, ~<R ) is a continuous model of E. Proof. It 's enough to prove that the partial order ~<R satisfies the conditions in Definition

11. 1) For all x E R , let x = [ t ] . Since J_ ~<pt, t~<p-]-, we can get that [t]~<R[-]-], [ ~- ]

~<Rt, i.e. x~<R[ -[- ], [ _L_ ] <~RX 2) f o r f E Fn, n>0 , if xi<~Ry i, where t e n , xi ,Yi E R, there exists ui, vieTz (P) satisfying

ui <~pvi and X=[Ui],y=[13i ] . We can deduce that: p~ (f) (uo , ' " , Un-, ) <~pp~ ( f ) (vo, '" , vn-, )

f ( u o , ' " , U.:l ) < p f ( v o , ' " , v~_j ) If(u0 , ' " , Un-J )] <~R[f(Vo ' " " V.-t )]

PR ( f ) ( [u] , - . . , [u_~])< RpRff)([%] ,.-',Iv,_,]) that is PR ~c) (x0 , ' " , xn-l ) ~<RPR Or) (Y0 ' " " Y.-t )- Q.E.D.

We use Do to denote R and consider the set of continuous function Dt =[Do--" Do]. We de- fine PDt as follows :

1) f o r f e F o , poj ( f )=2c~E Do . PDo ~f ) 2) f o r f e F . , n>0 , P o l ~ f ) ~ , ' " , f . - I )=g , w h e r e f i E D l ' i E n ' for all xEDo,gOc)=Poo~f)

~ fo (x ) , ' " , f . - i (x) ). Theorem 3. g is a continuous function flora Do to Do �9 Proof. This can be done by proving that for all directed set X ~ D o , g(l__lX)=[__lg(x).

Since (Do, ~D0 ) is a lattice, the least upper bound of a directed set always exists. Now we prove that g([_lX) is the lub of g (X) .

g (L_Ix)= PD0 ~ ) 0% (LIX),... ,f._ t(L_/X) )= Pno ~f) (U f0 (X), -.. , LI f . - , (X))

for all x e X . Sincefi(x)<~ ooL~i (X) , we can get

Po0 ( f ) (fo (x), . .- ,fi-x (x) )~< on P~ ( f ) (Lifo ( X),- . . , [__If.-j (X)) ,

that is g(X)<~Do g ( L I X ) , g ( l J X ) i s the upper bound of g (X ) .

Page 5: Construction of the model of the lambda calculus system with algebraic operators

112 J. of Comput. Sci. & Technol. Vol.6

I f g ( X ) h a s an upper bound t, then t either be TOo or be pD0( f ) ( t0 , - . - , tn_ 1 ). We want to prove that g (l IX)~<D0 t

1 ) if t=-]-o0 , then g(k_JX)~<o0 t holds obviously.

2 ) if t=PDo~f)(to,. . . , t ,- t ), w h e r e f i ( X ) ~ < D 0 ti, that is, t i is the upper bound o f f i ( X ) , so that I lfi (X) <~Do ti �9

Since f i is a continuous funct ion, then fi(l__lX)=1 If i(X)<~ 190 t . F r o m that we can deduce

that Poo(f ) ( fo(I IX ) , . . . , f n_ l (I IX))<~DoPDo ( f ) ( t o , ' " ' t n - 1 ) " This means g(I I X ) ~ < D 0 t . g ( lAX) is the lub of g ( X ) , that is

g(I IX)=I Ig(X) . Q. E .D. F r o m Theorem 3, we can get that ( D I , PD1 ) is a Z-algebra and is also a model o f E. W e

define the partial order ~< D 1 :

for all h , k ~ D t , h <~olk ~) for all x~Do, h(x)<~Dok(x) �9 It is easy to verify that ~<Dl satisfies the conditions o f Definition 11. So that ( D I , PD1 ,

~<D1 ) is a continuous medel of E.

In the same way, we can construct 1)2 from D l , and /)3 from /)2. We get a se- quence {Dn }, where (Dn , PDn, ~< o n ) are all the continuous model of E. I n [ 3 ] , .the D~o obtained in above way was proved to be a model of pure lambda system. The definition o f application

" " and map "1~ ]" were also given. We define Polo and ~<Doo as follows respectively,

(Poo. PDI,PD2,"" )' ( "-< o0, "-< Dl ' "-< O2 ' ' ' " ) " It is easy to verify that (Doo, P D ~ , ~<D~o ) is a continuous model of E. F r o m Theorem 1 we

know that (D~o, �9 [ ] + ) is the model of lambda- plus system.

Acknowledgement

Thanks to Lin Kai for his constant help in writing this paper.

References

[ 1] Sun Yongqiang and Lin Kai, The lambda calculus with algebraic operators and its combinatory logic. Conference on Intelligent Computer System, Jan., 1989.

[2] J. Goguen, J. Thatcher and E. Wagner, An initial algebra approach to the specification, correctness and implementation of abstract data type. Current Trends in Programming Methodology, IV, Data Structuring (R. T. Yeh, Ed) Prentice Hall, New Jersey, !978 �9

[3] R. Hindleyand J. Seldin, Introduction to Combinators and 2-calculus. Cambridge University Press, 1986.