• Keine Ergebnisse gefunden

Initial Algebra Semantics and Continuous Algebras

N/A
N/A
Protected

Academic year: 2022

Aktie "Initial Algebra Semantics and Continuous Algebras "

Copied!
28
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Initial Algebra Semantics and Continuous Algebras

J. A . G O G U E N

UCLA, Los Angeles, California

A N D

J. W . T H A T C H E R , E. G. W A G N E R , A N D J. B. W R I G H T IBM Thomas J Watson Research Center, Yorktown Heights, New York

ABSTRACT Many apparently divergent approaches to specifying formal semantics of programmmg languages are applications of mmal algebra semantics In this paper an overview of imtial algebra semantics ts provided The major technical feature ts an mmal continuous algebra which permits unified algebraic treatment of lteratlve and recurslve semantic features in the same framework as more basic operations

KEY WORDS AND PHRASES algebraic semantics, algebras, free algebras, continuous algebras, posets, pro- grammmg language semantics, flow diagrams, syntax directed translation, solutions of equations

CR CATEGORIES 5 23, 5 24

1. Introduction

In the past few years there has been quite a proliferation of formal semantics for programming languages, or at least of different descriptive terms, for example, opera- tional, interpretive, fixed point, predicate calculus, denotational, algebraic, mathemati- cal, synthesized, W-grammar, axiomatic, inherited, declarative, continuation, process, and now initial algebra semantics. Moreover, mathematical concepts, said to be deep, or strange, or new, are asserted to he relevant, for example, continuous lattices, lterative algebraic theories, infimtary logic, and bicategories This is quite perplexing. How do these things fit together, if at all? In fact, what is "syntax"; what is "semantics"?

This paper is not going to answer all these questions. But we believe the subject cannot be said to be in very good shape when such questions are ignored or glossed over, and when "practical" and "theoretical" approaches have so little to say to each other. In this paper we offer a unified approach to these questions with some preliminary answers which expose a surprising and beautiful unity in the apparent diversity of approaches.

The key concept is very simple: An algebra S is init:al in a class C of algebras lff for every A in C there exists a unique homomorphlsm ha : S ~ A. 1

Copyright © 1977, Association for Computing Machinery, lnc General permission to repubhsh, but not for profit, all or part of this material ts granted provided that ACM's copyright notice is gwen and that reference lS made to the pubhcat~on, to its date of issue, and to the fact that reprinting privileges were granted by permission of the Assooatton for Computmg Machinery.

This is a revised and expanded version of a paper entitled "Initial Algebra Semantics," which was presented at the 15th I E E E Symposmm on Switching and Automata Theory, October 1974

The work of J A Goguen was partmlly supported by the Naropa Institute, Boulder, Colorado, and the University of Colorado, Boulder, Colorado.

Authors' addresses: J A Goguen, Computer Soence Department, UCLA, Los Angeles, CA 90024, J W Thatcher, E G Wagner, and J B Wright, IBM Thomas J Watson Research Center, 'Yorktown Heights, NY 10598

i We are assuming that C comes with an "appropriate" class of homomorphisms which is dosed under assooative composition and includes an identity for each algebra More f~rmally, we assume that C ts a category. The reader seeking a more comprehensive algebraic context may want to consult [23] and/or [39]

Journal of the Association for Computing Machinery, Vol 24, No 1, January 1977, pp 68-95

(2)

Initial Algebra Semanttcs and Continuous Algebras 69 In the cases we examine, syntax ts an initial algebra in a class of algebras, and any other algebra A in the class ts a possible semantic d o m a i n (or semantic algebra); the semantic f u n c t i o n is the uniquely d e t e r m i n e d h o m o m o r p h t s m hA : S ~ A, assigning a meaning hA(s) in A to each syntactic structure s in S. F r o m this viewpoint it becomes clear that a m a j o r aspect of formal semantics (both practical and theoretical) is constructing mtended semantic algebras for particular programming languages. We believe that is what Scott and Strachey [65] and thetr followers are doing with the tools outlined by Scott [60] and more fully developed m [62-64].

We use abstract syntax (cf. McCarthy [36]), but without employing any " c o n c r e t e "

verston such as in the Vienna Defmitlon Language [35] W h a t is abstract about "abstract syntax" is captured by the following propositton.2

PROPOSITION 1 1. I f S a n d S ' are both initial in a class C o f algebras, then S a n d S ' are isomorphic. I f S" is tsomorphic to an intttal algebra S, then S" ts also initial.

PROOF z If S and S' are imtiai in the class C of algebras we have (unique) h o m o m o r - phtsms hs, : S ~ S' and hs : S' --> S. The composite of hs, followed by hs (denoted hs ohs ,) is a homomorphtsm from S to S. The tdentity function, l s , ts also a h o m o m o r p h i s m ; so h s ° hs, = l s by untqueness Similarly hs, ° hs = Is,, thus h s is an isomorphism.

I f S ts tnittal and S" is tsomorphtc to S, then hs. • S --> S" must be the isomorphism. F o r any algebra A in C, we have hA : S ~ A so that ha o h~J is a h o m o m o r p h i s m from S" to A . If g : S" ~ A is any o t h e r such h o m o m o r p h i s m then g o h s , : S ~ A so g o h s , = ha and g = ha ° h ~ . Thus S" as initial. []

R a t h e r than assume "that programs are 'really' abstract, hierarchically structured data objects . . . ," as in Reynolds [53], we avoid t r o u b l e s o m e questions of definition and notation by identifying "abstract syntax" with "initial a l g e b r a " ; Proposition 1.1 says abstract syntax ~s i n d e p e n d e n t of notational varmtlon - as it should be. F o r e x a m p l e , if as a r a n k e d alphabet, 4 define a E-tree to be an e l e m e n t of an imtial Z-algebra. In this way we are not t~ed to any particular representatton of trees (Pohsh notation, infix terms, prefix parenthesized terms, functions defined on tree domains, o r certain directed o r d e r e d labeled graphs). This abstract syntax for trees d e p e n d s only on the essential algebraic-structural properties that characterize trees

Because of the connection with abstract syntax, the initial algebra a p p r o a c h as implicit m McCarthy's [36] proposals for a "Mathematacal Science of C o m p u t a U o n " and tn I r o n ' s pioneering p a p e r [29] on syntax directed translation. The approach becomes more exphcit at least as far back as Landin [31] and Petrone [50], as well as in McCarthy and Painter [38], Knuth [30], Burstall and Landln [10], Nivat [48], and Morris [46, 47]. O f these, Burstall and Landin first use universal algebra (a la Cohn [13]) and (implicitly) the initiality p r o p e r t y , Morris [46, 47] brings m m a n y - s o r t e d algebras, which are essential for any applications of algebraic semantics to m t e r e s t m g p r o g r a m m i n g languages.

This p a p e r makes the mitml algebra a p p r o a c h to semantics completely explicit, providing the necessary algebraic background and several examples. O u r principal new result is the existence of initial continuous algebras. This extends the applicabdity of mttial algebra semantics by combining the algebraic insights of Burstall. Landin, and Morris with the (lamce-) order-theoretic ideas of Scott and Strachey. We consider solutions of equations in continuous algebras and show, for e x a m p l e , how Scott's lattice of flow diagrams [61] is a specml case ~ an inttial continuous algebra.

Section 2 makes the notion of many-sorted algebra precise. T h a t material is not mathematically new and has a survey character. H o w e v e r , our p r e s e n t a t i o n is different 2 In order to prove existence of initial algebras, we have to employ a concrete construction, but once done, we can forget about that construction and rely solely on Proposition 1 1

This proof depends exactly on the assumptions about C mentioned in the footnote to the deflmtlon of

"Initial "

4 A ranked alphabet is a family ( 2 , ) , ~ o f disjoint sets i n d e x e d b y the n a t u r a l n u m b e r s 2~ is the set of operator s y m b o l s of rank k, T h e r e are m o r e details in Section 2 N o t e that the a s s u m p t i o n t h a t the 2 , a r e disjoint is n o t

necessary (or even d e s i r a b l e m g e n e r a l - s e e T h a t c h e r [67]), we a d o p t it h e r e to sJmphfy the e x p o s i t i o n

(3)

7 0 J . A . G O G U E N , J. W. THATCHER, E. G. W A G N E R , AND J. B. WRIGHT

from the literature (we hope it is simpler) and seems to us to be of fundamental i m p o r t a n c e . A careful reading of Section 2 serves multiple p u r p o s e s , because the material there can be e x t e n d e d to almost any initial algebra situation, including mttlal continuous algebras (Section 4).

Section 3 contains applications (examples) of initial many-sorted algebras. Section 4 defines " c o n t i n u o u s a l g e b r a " and constructs initial continuous algebras. A p p h c a t i o n s of this, including Scott's lattice of flow dmgrams [61], are m Section 5. Section 6 contains some questions and p r o b l e m s .

Some of the subject m a t t e r included here is being p r e p a r e d for inclusion in the second part of the first r e p o r t of the A D J series [23] 5

2. Many-Sorted Algebras

A n algebra in the sense of Birkhoff [6] (see also Cohn [13] and G r a e t z e r [27]) is simply a set, called the carrier of the algebra, together with an indexed family of o p e r a t i o n s (functions) defined on (Cartesian powers of) that set. A m a n y - s o r t e d algebra consists of an indexed family of sets (called carriers) and an indexed family o f o p e r a t i o n s defined on Cartesian products of those sets. Generalizing to m a n y - s o r t e d algebras is very natural for c o m p u t e r science. The index set for carriers is called the set of sorts, and might be, for example, {real, int, bool}. A n algebra A of this kind would have three carriers, Areal, Aint, and A b o o l , together with some operations such as "1" . A real × A int ~ A real o r ~ : A bool X A,e,~ × A,e,~ ~ A,,,~, which might be e x p o n e n t i a t l o n o r conditional, respectively.

A finite a u t o m a t o n , in the sense of R a b i n and Scott [52], is an algebra with two sorts:

states n a m e d S and mputs named E, i.e. an {S, E}-sorted algebra. The transition function is an o p e r a t i o n M of " t y p e " (S~, S) ( M . S × E ~ S, using the sort symbols to d e n o t e the carrters, an ambiguous but c o m m o n practice). The initial state is a constant So of sort S (So E S ) .

The definition below is equivalent to Birkhoff and Lipson's [7] " h e t e r o g e n e o u s a l g e b r a " and therefore (according to them) is equivalent to Hlggins' [28] " a l g e b r a with a scheme of o p e r a t o r s . " Btrkhoff and Ltpson show that the conventional theory of

"universal a l g e b r a " (as in [6, 13, 27]) carries o v e r "with undiminished f o r c e " to the theory of m a n y - s o r t e d algebras. In particular, the concepts of s u b a l g e b r a , h o m o m o r - phlsm, quotient, congruence relation, product, w o r d algebras, and free algebras general- lze naturally and easily. A l t h o u g h Birkhoff and Lipson give some c o m p u t e r science examples, the first explicit use for new results in c o m p u t e r science seems to be in M a l b a u m [41, 42]. The concept a p p e a r s to have originated with B6nabou [5] in a category theoretic form.

L e t S be a set whose e l e m e n t s are called sorts. A n S-sorted operator domain o r stgnature ~ is a family (~w,8) of disjoint sets indexed by S* × S. ~w.8 is the set of operator symbols of type (w, s ), arity w, sort s, and rank lg (w ) (lg (w ) is the length of w, h ~ S* is the e m p t y string, and lg(h) = 0). A E-algebra A consists of a famdy (As)~es of sets called the carriers o f A (A, is the career ofsorts E S); and for each (w, s) ~ S* × S and for each o- Ew,s, an o p e r a t i o n O'A of type (w,s), i.e era : Aw, × • " • × Aw~ -->A~ where w = w~ • • • w~ and w, E S for t = 1, • • • , n. A n o p e r a t i o n era of type (h, s) is a constant of sort s, i.e O'A ~ As

F o r fixed S and varying E we have the class of S-sorted algebras, and as S varies too, the class of many-sorted algebras.

W h e n # S = 1, we have the conventional case of (one-sorted) a l g e b r a s - h e r e the o p e r a t o r d o m a i n is just as well Indexed by to = {0, 1, 2, • • • }, and tr E E , names an o p e r a t i o n era : A n ~ A m an algebra A (the single carrter and the algebra being ambiguously d e n o t e d by the same symbol).

5 The set of authors of thJs paper ~s referred to as "ADJ". the series referenced here is devoted 1o an exploration of "the junction between category theory and computer scwnce "

(4)

I n i t i a l A l g e b r a S e m a n t t c s a n d C o n t i n u o u s A l g e b r a s 71 R e t u r n i n g to the general case, if A and A ' are both E-algebras, a E - h o m o m o r p h i s m h : A ~ A ' is a family of functions (hs : A s ~ A ~ ) s ~ s that preserve the operations, i.e.

(0) if tr ~ `z~,s, then hs(O'A) = ora, ;

(1) If ~ ~ E . . . and (ai, "'" , a,) E As, × "'" × As,, then hs(tra(al, ' ' ' , a,)) = o'a, (hs I ( a l ) , "" ", hs, (a,)).

The utility of iniUal algebra semantics rests heavily on being able to handle many- sorted algebras with as much clarity and notational simplicity as the one-sorted (conven- tional) case. Indeed, the generalization from sets and functions to S-indexed families of sets and S-indexed famflms of functions ~s not that great a j u m p . If A is an S-indexed family of sets (A = (,4s)s~s) and w = s l • • • s , E S*, then generalizing A n, define A w to be the Cartesian product A,, × . ' . × As,. Similarly, for an S-indexed family of functions h : A --->A' ((hs : A s - - - ~ A ~ ) s E s ) , d e f i n e h w : A t e - - - ) A ' U ' b y h W ( a l , • "" , a n ) = (hs, ( a l ) , "" • , hs. (a,)), which generahzes h " : A " ~ A ' " , The special case w = h (n = 0) is handled uniformly by A ° = A ~ = {~.}, and a function o'a with source A ~ IS identified with the

" c o n s t a n t " which IS ItS value (ra(X) at ItS single a r g u m e n t ?

Now with this notation, an S - s o r t e d "Z-algebra A consists of: a carrier (ambiguously denoted) A , which is an S-indexed family of sets; and, for each operator symbol (r ~ Ew.s, a function t r a : A w ~ A s . A n S - s o r t e d ~ h o m o m o r p h i s m h from A to A ' IS an S-indexed family of functions (hs : As --~ A~) such that h s (O'a (a)) = o'A, (h ~ (a)), i.e.

(/'4

A u • A,

cr A ,

A TM ~ A',

commutes for all o" ~_ Ew.s and a ~ A w. This has now become only a minor varmtmn on the one-sorted definition.

Letting A l g z denote the class of Z-algebras with E-algebra homomorphism, we state the first basic result concerning initml algebras.

PROPOSITION 2.1 T h e c l a s s A l g z o f ` z - a l g e b r a s h a s a n m i t l a l a l g e b r a ; c a l l tt T ~ . []

This IS a well-known result, at least for the one-sorted case (see Blrkhoff [6] or Cohn [13] or Graetzer [27]), and the many-sorted case is treated in Birkhoff and Llpson [7].

T z is often called the Z - w o r d a l g e b r a and the carriers are sometimes callod the H e r b r a n d u n t v e r s e for `Z. The set T~,s (the carrier of T~ of sort s) can be thought of as the set of well- formed expressions (or trees) of sort s built up m the usual way (to be made p r e o s e in a m o m e n t ) from the operator symbols of `Z. But we emphastze that this characterization is (mathematically) mlportant o n l y for the proof of Proposition 2.1. Once proved, we do not n e e d to know how a particular initial algebra was c o n s t r u c t e d - w e use only initiality.

C o m m e n t s about expressions (or pictures of trees) occur only to aid understanding.

Let E (ambiguously) denote the set of all operator symbols in the S-sorted operator domain E. Now let (T~.s)ses be the smallest family of sets contained in (E t./ {(,)})*

satisfying the following two c o n d m o n s (here {(,)} is a two-element set disjoint from E):

(0) E~,s c T_~,s;

( 1 ) l f o - ~ E ... w = s , ' ' ' s , , n > 0 , a n d T , ~ Tz,s ,, t h e n o-(t~ . . . tn) ~ T z , s T h e n make the family ( T z , s ) into a Z-algebra T z by defimng the operations:

(0) f o r cr ~ `Z~,~, o-, = o" ~ T,=,s; ~

(1) for cr @ Ew.s, w = s l • • • sn, and t, @ T~ .... o'v(tl, • • • ,ta) = o'ffl • • • tn) E T z , s . A l t h o u g h this u n i f o r m i t y ~s m a t h e m a t m a l l y r a c e , it Is o f t e n m o r e c o n v e n i e n t to s e p a r a t e o u t t h e c o n s t a n t s f r o m t h e m o r e g e n e r a l o p e r a t o r s , f o r t h e m o s t p a r t this wdl b e d o n e in t h e s e q u e l

W e a r e w r i t i n g o-r i n s t e a d o f O-cr~

(5)

72 J . A . G O G U E N , J. W. THATCHER, E. G. W A G N E R , A N D J. B. WRIGHT U n d e r the natural identification of elements of A w with strings aw, • • • am. such that aw, E Aw,, (1) immediately above can be rewritten:

for all (r ~ Ew,s and t E T ~ , (rr (t) = tr(t).

A s an artificial example, S = {a, b}, Z~,a = {xa}, Ex.b = {Xb}, E~b,a = {f}, a n d Eb,b = {g}. Then T~., contains terms xa, f ( X a X b ) , f ( x a g (Xb)), f ( f ( x j b ) X b ) , etc., while T~,b contains Xb, g(Xb), g ( g ( x D ) , etc. Much less artificial is the correspondence, in Section 3, of any context-free g r a m m a r to an imtial N-sorted algebra (where N is the set of nontermmals).

In any algebra A in the class A l g a , if cr E ~ , ~ and a ~ A w, then crA(a ) ~ As. This algebraic structure on the set T~ (making it the initial E-algebra) seems to be "synthetic syntax" [36], and o-r is familiar as the "constructor function" denoted m k - or in Reynolds

[53].

O n the other hand, "analyUc syntax" [36] is based on

PROPOSITION 2.2. For any t ~ T~, s there exist unique n -> O, s~ • • • sn E S*, o" E E<s, s,.s>, a n d t, E Tz,s. (1 -< i -< n) such that t = o'r(q, • • • , tn). [] s

The notation in Reynolds [53] can be generalized to m a n y sorts as follows: For each o- E , is - o" tests whether its argument is of the form o'r(q, • • • , t,), taking values in the set {true, false}; is - s tests whether Its a r g u m e n t could be of sort s; and for each pair (o', i) with 1 _< i -< rank(o-), s<~,,> is the "selector function" defined iff i s - o " is true by s<~,,> (o-r(q, " • , t,,)) = t,. These functions are well defined by Proposition 2.2, and ff is - tr(t) is true, then

m k - - t r ( s ~ o , , > ( t ) , " ' " , S<a,n>(t)) = t .

Moreover, if o- ~ X<, . . . . ,> and if is - s,(t,) is true for 1 -< z -< n , then s < , ~ , d m k - o'(t~ , . . . , t , ) ) = t , .

In [53] the various selector f u n c a o n s are given names (e.g. o p r , o p n d , etc.), but of course this isn't necessary. In fact, as an example below illustrates, the " l a n g u a g e " of synthetic and analytic syntax is unnecessary with the mittal algebra approach to abstract syntax.

We now introduce "freely g e n e r a t e d " X-algebras in order to get a concise definition of

"derived operator"; for n o t a t m n a l simplicity we consider the one-sorted case first.

Let X be a set (whose elements are called variables) disjoint from E. We form a new ranked alphabet, denoted E(X), by adjoining the varmbles as new constant symbols:

E(X)o = Eo t.J X and ~(X)k = Ek for all k > 0. By Proposition 2.1, Tx(x) ts the tmtial X(X)-algebra. The trees whtch are m its carrier differ from those in Tx only m that they may have variables on the leaf nodes as well as constants from Eo Now Tx(x> has E(X) as tts signature, whereas we want to thmk of Tx<x) as a X-algebra Since the operations (and constants) n a m e d by X(X) include those n a m e d by E, we can do thts just by "forgetting"

that the variables have names in the stgnature; that is, we define a new X-algebra, d e n o t e d T x ( X ) . wtth carrier that of T,~x) and with operations those n a m e d by ~ in T.~x). It

~s the free X-algebra generated by X , in the following sense.

PROPOSITmN 2 3. I f h : X ~ A ts any f u n c t i o n m a p p i n g X into the carrter o f a X- algebra A , then there exists a unique Z - h o m o m o r p h i s m tt : Tx(X) ~ A extending h, t.e

~ ( x O = h ( x ) ?

PROOf. A is a E-algebra. Given h : X --> A , m a k e A m t o a E(X)-algebra by having x name h(x) in A (xa = h(x)). By Proposition 2.1, there ~s a unique E(X)-homomorpbism /t . Tx<x)~ A , and (by clause (0) of the definition of hornomorphism) [t(XT) = Xa = h(x);

because /~ is a E(X)-homomorphtsm, ~t ts immediately a E-homomorph~sm. For the untqueness part, ifg : T~(X) ~ A ts a E-bomomorph~sm with g(x~) = h(x), then tt IS also a E(X)-homomorphism, and thus g = h. []

a This is f a m i l i a r f o r w e l l - f o r m e d e x p r e s s i o n s a n d / o r Z - t r e e s , a n d t h a t is sufficient p r o o f b e c a u s e o f P r o p o s i t i o n 1 1

a N o t e t h a t xT is w h a t e v e r the z e r o - a r y s y m b o l x ~ X n a m e s m the m l u a l a l g e b r a T ~ r ) - m the a b o v e c o n c r e t e c o n s t r u c t i o n ~ r = x , b u t we c a n ' t a s s u m e t h a t since we a r e d e p e n d i n g o n l y on the m f l m h t y of T~a)

(6)

I n i t i a l A l g e b r a S e m a n t i c s a n d C o n t m u o u s A l g e b r a s 73 T h i s c o n s t r u c t i o n is typical of initial a l g e b r a s e m a n u c s . T h e p h r a s e , " m a k e B into a Z- a l g e b r a by • • . , " is f u n d a m e n t a l b e c a u s e m a k i n g B into a Z - a l g e b r a gives t h e u n i q u e h o m o m o r p h i s m hB : T~ --* B by lnitiality. In the p r o o f o f P r o p o s i t i o n 2.3 this was particularly e a s y - A was a l r e a d y a Z - a l g e b r a and we m a d e it a Z ( X ) - a l g e b r a In g e n e r a l , if B ts any set (later, any family i n d e x e d by S), we m a k e B into a E - a l g e b r a by d e f i n i n g a p p r o p r i a t e o p e r a t i o n s cr B : B" ~ B for e a c h (r ~ E . ; then (zap!) h9 : T~ ~ B.

W e are n o w m a position to d e f i n e the v e r y i m p o r t a n t n o t i o n of d e r i v e d o p e r a t o r . T h e intmtive idea is that the t e r m s m Tz(X) (like p o l y n o m i a l s m o r d i n a r y a l g e b r a ) do n o t h a v e values, since t h e y contain variables, but t h e y d o d e f i n e f u n c t i o n s on any Y - a l g e b r a by assigning values to the variables. B e c a u s e this gives rise to n e w o p e r a t o r s on E - algebras A c o m p o u n d e d o u t of those n a m e d by E , the n e w o p e r a t o r s are called d e r i v e d o p e r a t o r s

First, let X , = {x~, • • • , x,,}, and call t E T ~ ( X , ) a E - t e r m m n v a r m b l e s or an n - a r y E- t e r m . N o w given a E - a l g e b r a A and t E T ~ ( X , , ) , we w a n t to d e f i n e its c o r r e s p o n d i n g d e r i v e d o p e r a t o r o n A , ta : A " ---> A . T h i s e m p l o y s P r o p o s i t i o n 2.3 as follows: G i v e n (al, • • • , an) E A " , let a . Xn --~ A be d e f i n e d by s e n d i n g x , ~ a~ f o r 1 -~ t -~ n ; t h e n , by P r o p o s i t i o n 2 . 3 , t h e r e exists a u n i q u e E - h o m o m o r p h l s m d : T~(Xn) ~ A e x t e n d i n g a : Xn ~ A ; n o w we d e f i n e tA(a~, " " " , an) to h a v e v a l u e d(t). T h u s we are letting a v a r y in the expression d(t), while k e e p i n g t fixed; d(t) ts the " e v a l u a t i o n " in A of the n - a r y t e r m t in which the v a r i a b l e x, is g i v e n the v a l u e a, m A , using the o p e r a t i o n s of t h e E - a l g e b r a A . F o r the special cases w h e n A is of the f o r m A = T z ( X m ) , the a b o v e gives us a precise f o r m u l a t i o n of t h e o p e r a t i o n of substitution of m - a r y E - t e r m s f o r v a r i a b l e s . ( W h e n v a r i a b l e s are assigned to t e r m s , " e v a l u a t i o n " ~s just s u b s t i t u t i o n . )

T h a t is, g i v e n t ~ T z ( X n ) and an n - t u p l e of m - a r y E - t e r m s t' = (t~, - . . , t~) ( T ~ ( X m ) ) n, we again identify t' with t h e m a p p i n g f r o m Xn to T z ( X m ) which s e n d s x, to t;

for 1 ~- i -< n. T h e result of s i m u l t a n e o u s l y substituting t,' for x, in t for i = 1, • • • , n is precisely F(t). W e write t ~-- t ' for the substitution of (the n - t u p l e o f m - a r y Z - t e r m s ) t' in the n-ary t e r m t.

If we t a k e t to be a p - t u p l e of n-ary E - t e r m s t = (t~, • • • , tp) E ( Z ~ ( X n ) ) p r a t h e r t h a n just a single n-ary E - t e r m , t h e n we c o u l d d e f i n e t ~-- t' as (6 ~ t ' , • • • , tp ~-- t'). H o w e v e r , by e x p l o i t i n g t h e c o r r e s p o n d e n c e b e t w e e n p - t u p l e s t E (Tz(Xn)) p a n d m a p p i n g s t : X p ---> T z ( X n ) , we can m o r e succinctly d e f i n e t ~-- t' as

i'ot ("o"

is a f u n c t i o n c o m - p o s i t i o n ) .

x , x ,

T~(X,,) t' • Tz(X,. )

T h e n t ~ t' = i' ot : X p ~ T ~ ( X m ) and the " l t h c o m p o n e n t " o f this " p - t u p l e " is (t ~-- t')(x,)

= (i' o t)(x,) = i'(t(x,)) = i'(t,) = t, ~-- t' just as before.

W i t h th~s d e f i n i t i o n it is easy to s h o w that substitution is associative. F o r given t : X p - - * T x ( X n ) , t : X . ~ Tz(Xm), a n d t " : X m - - ~ T z ( X q ) ,

we h a v e

X . X . X,.

| ~ t'

T~(X.) ) T~(X,.) • T~(X.)

(7)

74 J . A . GOGUEN, J. W. THATCHER, E. G. WAGNER, AND J. B. WRIGHT (t + - t ' ) + - t " = ([' ot) + - t " = i" o ([, ot) = ([, o/,) ot by d e f i n i t i o n o f + - . B u t t h e n / " or' a n d

? ' o i ' a r e b o t h h o m o m o r p h i s m s Tz(X,~) ~ T ~ ( X a ) e x t e n d i n g t " o t ' , a n d so P r o p o s i t i o n 2.3 says t h e y a r e e q u a l , w h e n c e q + - t ' ) + - t " = ( i " o i ' ) o t = ( i " ~ ) o t = t + - ( i " o t ' ) = t + - (t' + - t " ) as d e s i r e d . T h u s w e h a v e

PROVOSXTION 2.4. S u b s t i t u t i o n is a s s o c t a t t v e F o r t : X v ~ T ~ ( X n ) , t' : X n ~ T~.(Xm) a n d t" : X m --+ T~(Xq), t h e n (t +- t') +- t" = t +- (t' +- t"). [] lo

Just as we can e x t e n d substitution to p - t u p l e s , so we can e x t e n d t h e n o t i o n of d e r i v e d o p e r a t o r s to p - t u p l e s of n - a r y S - t e r m s . G i v e n t = (q, • • • , t o) : X p --+ T_~(Xm), we d e f i n e tA : A m ~ A p to be such that, for e a c h a ~ A 'n (i.e. a : X,n ~ A ) , ta(a) = ci o t, which, for t

= ( t l , " ' " , tp), g i v e s t a ( a ) = ( t ( x ~ ) a ( a ) , " ' " , t ( x p ) a ( a ) ) = ( ( t l ) A ( a ) , " ' " , ( t v ) A ( a ) ) . N O W given

X~ X , X,.

T~(X.) ) F~(X,.) I. A

which is a trtwal modification of the d m g r a m for substitution, the proof of Proposition 2.4 Is i m m e d i a t e l y m o d i f i e d to yield

PROPOSITION 2.5. (t +- t')A = ta ° t ] ( w h e r e t h e r i g h t - h a n d s i d e ts f u n c t i o n c o m p o - s i t i o n a n d the l e f t - h a n d s i d e is s u b s t i t u t i o n ) . []

S o m e famflmr f u n c n o n s on t r e e s or e x p r e s s i o n s are f u r t h e r e x a m p l e s of initial a l g e b r a s e m a n t i c s

F r o n t t e r . M a k e E~ into a Z - a l g e b r a . (0) F o r o- ~ ~o, let o- b e o- ~ Eo*.

( 1 ) F o r ~ r E E , , wa, " . , w , E E g , letcr(w~, " " ,w,~) = wl " ' " w , . T h e u n i q u e E - h o m o m o r p h i s m f r : Tz --) E~ is t h e f r o n t i e r (or yield) f u n c t i o n .

G e n e r a l l y Ws clear and ntce to write era to specify w h a t ~r n a m e s m the a l g e b r a A , b u t th,s gets t i r e s o m e , and m fact it is n o t c o n v e n t i o n a l practice F o r A b e l i a n g r o u p s o n e d o e s n ' t see + c and 0G, but Just + and 0, t h e s y m b o l s i n d e e d n a m e t h e f u n c t i o n s a n d constants.

Whtle the c o n v e n t i o n o f using the o p e r a t o r s y m b o l s to d e n o t e the f u n c t i o n s m (different) algebras can lead to s o m e r a t h e r strange l o o k i n g expressions (cf. case (0) in the e x a m p l e a b o v e a n d m the two that f o l l o w ) , it Js a r e c o g m z e d c o n v e m e n c e and a v o t d s n a m i n g algebras m t h e s e e x a m p l e s and t h e r e s u l t i n g c o m p l e x subscrtpts.

H e i g h t . M a k e o) = {0, 1 , 2 , • - .}11 into a Z - a l g e b r a : (0) F o r ~r ~ E0, let o- = 1.

(1) F o r o- E E,,, k~, . . • , k, ~ w, let o'(k,, - . . , k,,) = max,(k,) + 1.

T h e u n i q u e ~ - h o m o m o r p h i s m h g : Tz ~ co is t h e h e i g h t f u n c t i o n - i n t r e e t e r m i n o l o g y , the l e n g t h of the longest p a t h f r o m the r o o t to a t e r m i n a l n o d e ( + 1).

S y m b o l s . M a k e ~2 p ( E ) i n t o a Z - a l g e b r a : (0) F o r o- ~ E0, let (r = {~r}.

(1) F o r o- ~ En, n > 0, a n d u , , • • • , un ~ p ( E ) , let o-(u,, • • • , un) = {o'} O I.Lu,.

T h e u n i q u e E - h o m o m o r p h i s m s y m : T z - + p ( E ) is t h e set o f s y m b o l s t h a t o c c u r in an e x p r e s s i o n .

W e fimsh off thts section by s h o w i n g h o w the i m p o r t a n t p r o c e s s o f d e f i n i n g d e r i v e d o p e r a t o r s w o r k s for m a n y - s o r t e d algebras. W h e r e a s m t h e c o n v e n t t o n a l case we g e n e r - to From a categorical point of view what we have here is a category T~ (the algebraic theory [32] freely generated by ~ ) with set of ob)ects oJ; m o r p h l s m s from m to n are functions from Xm to T~(X,~), composition is substitution; and for each n ~ ~o, the m a p p i n g X n ---, T ~ ( X , ) taking x, to x, is the identity for n

n T h r o u g h o u t we use ~ to denote the n o n n e g a t w e integers.

~ p(E) is the set of subsets of the set of o p e r a t o r symbols E (p is for " p o w e r set").

(8)

Inittal Algebra Semantics and C o n t m u o u s Algebras 75 a t e d a free a l g e b r a f r o m a single set, n o w we must h a v e g e n e r a t o r s for e a c h sort, i.e an S - i n d e x e d family X G i v e n an S - s o r t e d o p e r a t o r d o m a i n E , d e f i n e an o p e r a t o r d o m a i n E(X) by E(X)x,, = X~ tO E~,~ and E(X)~,~ = E ... for w ~ ~; that is, the g e n e r a t o r s a r e a d j o i n e d as symbols of arity h and sort s. A g a i n T~x~ is v i e w e d as a Z - a l g e b r a Tz(X), a n d we h a v e the " f r e e n e s s " p r o p o s i t i o n p r o v e d exactly as P r o p o s i t i o n 2 3.

PROPOSmON 2.6. For an S-sorted operator d o m a i n ~ and an S - m d e x e d faintly X , T~(X) is the ~ a l g e b r a freely generated by X in the sense that any S-indexed f a m i l y o f functions, h : X ~ A , to the carrter o f a Z-algebra A , extends untquely to a ~ - h o m o m o r - p h t s m I~ : T~(X) ~ A . []

F o r u = s~ • • • s . E S*, d e f i n e X~ (the a n a l o g u e of X . is the o n e - s o r t e d case) by X . = {x~ .... x2 .... • • • , x .... }. X . ts a set of n " s o r t e d " o r " t y p e d " v a r i a b l e s a n d c a n be v i e w e d as an S - i n d e x e d family with (X.)s = {X~,s, [ s, = s}. This specifies, for e a c h s, t h e c o u n t a b l e set {x~,~, xz,~, x3,,, • • • } o f s - s o r t e d vartables via c o n v e n t e n t f i m t e subsets X . for u E S*.

F o r e x a m p l e , with S = {a, b} again, Xa~b~b = {Xl,~, Xz,a, X4,a, X3,b, Xs,b}.

In an a l g e b r a A , a t e r m t ~ (T~(X~))s d e f i n e s a d e r i v e d o p e r a t o r ta : A ~ ~ A s a n a l o g o u s l y to the o n e - s o r t e d case: V i e w a U A ~ as an i n d e x e d f a m i l y o f f u n c t i o n s a : X .

A bya,(X,,s,) = a~ ~ A~, a n d , using P r o p o s i t i o n 2 . 6 , d e f i n e tA(a) = ~(t).

A g a i n , substitution is a special case. A f a m i l y o f m a p s t : X~ ~ T z ( X . ) is like an n- tuple of t e r m s m v a r i a b l e s X , e x c e p t that t(x,.~,) has to be m T~(X~)~, so that v a r i a b l e s of sort s, are assigned t e r m s of sort s,. A l s o given t' : X~ ~ T~(Xw), S - s o r t e d substitution is d e f i n e d by t ~ t' = t ° / ' ; t ~ t' is again the result of s i m u l t a n e o u s l y substituting t~

= t'(X,,~,) forx,,~, in e a c h c o m p o n e n t o f t . A s s o c i a t i v i t y o f substitution a n d its r e l a t i o n s h i p to d e r i v e d o p e r a t o r s go t h r o u g h exactly as in P r o p o s i t i o n s 2.4 a n d 2.5.

3. Applications o f lnitial M a n y - S o r t e d Algebras

3.1 CONTEXT-FREE GRAMMARS. T h e m o s t i m p o r t a n t a n d g e n e r a l e x a m p l e of initial m a n y - s o r t e d a l g e b r a s e m a n t i c s ~s s e m a n t t c s for c o n t e x t - f r e e g r a m m a r s

L e t G = (N,E,P> be a c o n t e n t - f r e e g r a m m a r 13 w i t h n o n t e r m i n a l s N , t e r m i n a l s E (N N E = ~ ) , a n d p r o d u c t i o n s P C N × (N U E) +. L e t V = N to E ; for any w ~ V*, d e f i n e n t ( w ) to be the string of n o n t e r m i n a l s in w, in t h e s a m e o r d e r . ( M o r e precisely, n t : V* --~

N* is the u m q u e e x t e n s i o n to a m o n o l d h o m o m o r p h t s m o f the m a p V ~ N* which is t h e identity on N and takes e a c h o" ~ E to h E N* )

N o w m a k e G into an N - s o r t e d o p e r a t o r d o m a i n w h e r e , for e a c h (w, A ) E N* × N , Gw,a = {p E P ] p = ( A , w ' ) and n t ( w ' ) = w}.

T h u s a p r o d u c t i o n A o--* u o A l u l A 2 • • • u . _ i A nU. (A, E N , u, ~ 5;*) is an o p e r a t o r s y m b o l of type (A~ • • • A . , A0) T h e imtial G - a l g e b r a TG has carriers Tc.,a w h i c h a r e parse t r e e s for d e r i v a t i o n s m G f r o m A E N .

R e g a r d i n g the g e n e r a l i t y of this situation, we h a v e just seen that any c o n t e x t - f r e e g r a m m a r gives rtse to an inttial N - s o r t e d a l g e b r a . C o n v e r s e l y ( b e c a u s e we allow mfm~te g r a m m a r s ) , If E is any S - s o r t e d o p e r a t o r d o m a i n , t h e n t h e r e is a c o n t e x t - f r e e g r a m m a r which gives us the initial Z - a l g e b r a back again u n d e r the c o n s t r u c t i o n a b o v e . In parttcu- lar, t a k e

= ( S , E tO {(,)}, P) w i t h P = {(s, o-(s, . . . s . ) ) I o- ~ Es . . . . s}.

T h e n o n e can c h e c k t h a t , u n d e r the i d e n t i f i c a t i o n o f the o p e r a t o r s y m b o l (s, or(s1 • • • s.)) m ~ with cr in E , T~ and T z are i s o m o r p h i c .

T h e i m p a c t of initial a l g e b r a s e m a n t i c s h e r e is that any G - a l g e b r a w h a t s o e v e r (a set Sn for e a c h n o n t e r m m a l A and a f u n c t i o n p s : Sa, × • • • × Sa. ~ SA for e a c h p r o d u c t i o n p 13 Usually N, E, and P are fimte (see [19]) We don't have (or want) that restriction here We believe that the context-free g r a m m a r for the abstract syntax of many p r o g r a m m i n g languages will have an infinite n u m b e r of terminals, nontermmals, and productions We don't consider the effective presentation of such systems here (see van W l j n g a a r d e n [77]), but this must be carefully thought out

(9)

76 J A. GOGUEN, J. w. THATCHER, E. G. WAGNER, AND J. B. WRIGHT of type (Aa • • • A n , A ) ) p r o v i d e s a s e m a n t i c s for the context-free l a n g u a g e g e n e r a t e d by G. TG, b e i n g initial, gives the u n i q u e h o m o m o r p h i s m h s : TG ~ S which assigns " m e a n - ings" in S to all syntactically w e l l - f o r m e d p h r a s e s of the l a n g u a g e ( n o t j u s t to the

" s e n t e n c e s " g e n e r a t e d from s o m e specified start s y m b o l in N ) .

F o r e x a m p l e , we m a k e X* into a G - a l g e b r a (with e v e r y carrier X*) by l e t t i n g p ( v l , • • • ,

V n ) = U o V i U l V 2 " " " Un-lVnU a for p = (Ao, u o A l u l A 2 • • • u,~_lA,,u,~). T h e n t h e u n i q u e

h o m o m o r p h i s m d : TG---> ~ * assigns to a d e r i v a t i o n t ~ TG.A the string which is d e r i v e d ) 4 N o t e that d : T~ ~ (X U {(,)})* gives exactly the w e l l - f o r m e d X-expressions c o r r e s p o n d - ing to p a r s e trees in T~; this is the basis for p r o v i n g the i s o m o r p h i s m of T~ a n d T~.

G m i g h t be a m b i g u o u s ( d n o t i n j e c t i v e ) , b u t that is n o t a p r o b l e m since initial a l g e b r a s e m a n t i c s (the abstract syntax p o i n t of view) factors o u t the parsing p r o b l e m ( w i t h o u t , of c o u r s e , e l i m i n a t i n g i t ) ? 5

T h u s e v e n " s t r i n g g e n e r a t e d " is a n initial a l g e b r a semantzcs for c o n t e x t - f r e e gram- m a r s . K n u t h ' s [30] s y n t h e s i z e d a t t r i b u t e s (following Irons'~ [29] ideas) really do what we describe h e r e , b u t K n u t h ' s d e f i n i t i o n s a n d n o t a t i o n s e e m m o r e c o m p l e x t h a n is neces- sary. I n o u r f o r m u l a t i o n , K n u t h constructs a G - a l g e b r a S in which each carrier Sa is itself a C a r t e s i a n p r o d u c t o f sets. T h e c o m p o n e n t s o f that p r o d u c t are called " s y n t h e s i z e d a t t r i b u t e s " o f A . T h e n K n u t h ' s " s e m a n t i c r u l e s " d e f i n e (by the c o m p o n e n t s ) o p e r a t i o n s of the a p p r o p r i a t e type for each p r o d u c t i o n . O f c o u r s e , s e m a n t i c s of the l a n g u a g e is the u n i q u e h o m o m o r p h l s m hs • TG ~ S ) 6

3.2. DENOTATIONAL SEMANTICS Scott [63] begins with the m o t t o " E x t e n d B N F to s e m a n t i c s " In fact, that is the " m o r a l " of the p r e v i o u s discussion W e n o w k n o w that B N F ~7 yields a n initial m a n y - s o r t e d a l g e b r a , that s e m a n t i c s arises from a n a l g e b r a of the same type, a n d that " m e a n i n g " is the u n i q u e h o m o m o r p h i s m . W e view the principal a c h i e v e m e n t of Scott a n d Strachey (say [60, 6 4 , 65]) as p r o v i d i n g m a t h e m a t i c a l tools for c o n s t r u c t i n g s e m a n t i c d o m a i n s ( m a n y - s o r t e d algebras with o p e r a t i o n s c o r r e s p o n d i n g to the p r o d u c t i o n s of a context-free g r a m m a r ) so that the u m q u e h o m o m o r p h l s m is the i n t e n d e d ( d e n o t a t i o n a l ) m e a n i n g of the l a n g u a g e .

Scott a n d Strachey s e e m to say (e.g. [65, p. 17]) that they d o n ' t care if the syntax of the l a n g u a g e is context-free. ( " T h e last thing we w a n t to be d o g m a t i c a b o u t ts lan- g u a g e . " ) B u t their s e m a n t i c s does d e p e n d o n the context-free c h a r a c t e r of the source l a n g u a g e , b e c a u s e the m e a n i n g of a phrase is a f u n c t i o n of the m e a n i n g s of its c o n s t i t u e n t phrases. ( F r o m [65, p. 12], " T h e s e m a n t i c a l d e f i n i t i o n is syntax directed m that it follows the s a m e o r d e r of clauses a n d t r a n s f o r m s each l a n g u a g e c o n s t r u c t i n t o the i n t e n d e d o p e r a t i o n s on the m e a n i n g s of the p a r t s . " ) This essentially says that syntax is c o n t e x t - free a n d s e m a n t i c s is a h o m o m o r p h i s m . 18

In g e n e r a l , the " s e m a n t i c e q u a t i o n s " (typical of [65, 26], etc.) d e f i n e the m e a n i n g of a syntactic c o n s t r u c t C as a f u n c t i o n F c of the m e a n i n g s of the c o m p o n e n t s to that construct, a n d in so d o i n g the s e m a n t i c e q u a t i o n s describe an a l g e b r a (the f u n c t i o n F c is the o p e r a t i o n c o r r e s p o n d i n g to the syntactic c o n s t r u c t C) a n d say that s e m a n t i c s is a

~4 This is actually a generalization of the frontier function defined in Section 2

~5 As Schwartz [59] puts it, "We have sufficwnt confidence in our understanding of syntactic analysis to be wdhng to make the outcome of syntactic analys~s, namely the syntax tree representaUon of program, into a standard starting point for our thinking on program semantics "

18 Knuth's [30] reheated attributes are not treated in this paper, but Goguen and Zamfir (unpubhshed) have suggested treating them as variables (that is, new unmterpreted constants) in free algebras whose operator domain contains, in addition to these varmble symbols for inherited atmbutes, all the operatzons and constants which are employed m semantic definmons Burstall (personal communication) has suggested using [1 ~ S] as the carrier of a generalized semantic algebra These issues will hopefully be explored elsewhere On the other hand, Knuth's [30} mare result, an algorithm testing for c~rcularity of a semantic defmmon mvolwng both inherited and synthesmed attributes, lies outside the domain of mterest of this paper

~7 Backus-Naur Form, a well-known and convement formulation for context-free syntax

~8 The homomorph~c character of the semantic function must have been clear to Scott In fact, he uses the phrase "continuous algebraic homomorphlsm" [61, p 46] for the semantic funcUon on the lattice of flow diagrams (See Section 5.3)

(10)

Initial Algebra Semantics and Contmuous Algebras 77 h o m o m o r p h i s m . Usually semantic equations give the meaning with respect to an "envi- r o n m e n t , " for example [65, p. 27],

"where p ts an environment; ~ is the semantic function for c o m m a n d s with target, say, F;

and ~ is the semantic function for expressions wtth target T = {true, false}. The initial algebra " t r a n s l a t i o n " of that semantic equation abstracts the environment variable to get

c ~ ~ To, V,~ = hp cond(C~%i~(p), c~Vl~ (p)) * ~ e ~ . Now this has exactly the form of the h o m o m o r p h i s m condition,

and the operation (in the semantic target algebra) ts F ~ : T x F z ~ F, defined for all ~ @ T and 'y0, 'yi ~ F in terms of cond, *, and abstraction:

F ~ (~, q/o, ~i) = kp cond (~o (P), ~, (P)) * E.

The point is that one need only define the target algebra; m m a l i t y yields the semantic h o m o m o r p h i s m .

W e illustrate this m more detail with a simple apphcative language which we call S A L , drawn (and modified) from Reynolds [53]. TM Let X = {xi, x2, "" "} be a set of variables 0dentiflers). In specifymg S A L syntax we give each rule a name m o r d e r to have mnemonics for defining a semantic algebra; those with subscript x r e p r e s e n t families, one m e m b e r for each x ~ X. T h e r e ts one nonterminal, (exp), and all boldfaced symbols are terminals. Thus varmbles occur as terminal symbols, just as, say, if does.

The (context-free) productions of S A L are the foliowmgZ°:

(%) (exp) ::= x

(cond) (exp) : : = if (exp) then (exp) else (exp) (apply) (exp) : : = (exp) ((exp))

(abs~) (exp) ::= l a m h d a x ((exp)) (lets) (exp) : : = l e t x be (exp) in (exp)

(let-reck) (exp) :: = let recursive x be (exp) in (exp)

F r o m Scott [63 ] there is a complete lattice 21 V of values satisfying the isomorphism,

v ~ 1 + n + [ V ~ V], (*)

where I and B represent respectively the mtegers and the Boolean values {true, false} as lattices with ~ and -1- a d j o i n e d , and [V ~ V] is the complete lattice of continuous functions from V to V. The + - o p e r a t i o n on the right-hand side of (*) is the "coalesced lattice sum ''22 (disjoint union with m i m m u m (and m a x i m u m ) elements identified). For X {1, B, [V--~ V]}, letj~ be the i n j e c t t o n j a : X--~ I + B + [V---~ V], and let ~b be the isomorphism ¢b : V "~ I + B + [V---~ V]. Then V ts equipped with injection tx : X---~ V (Ix

= qb -I Olx ) and also "proJections" 7rx : V ~ X such that f~b(V) If ~b(V)EX,

~ x ( V ) =

otherwise

19 O u r l a n g u a g e differs s u b s t a n h a l l y f r o m R e y n o l d s ' s m that his e m p l o y s a call-by-value i n t e r p r e t a t i o n o f application

20 T h e fact that this is an a m b i g u o u s g r a m m a r Is irrelevant for o u r p u r p o s e s

21 We dISCUSS c o m p l e t e n e s s , c o n t i n u i t y , a n d alternatives to lattices in Section 4 F o r n o w , a complete lattice is a partmlly o r d e r e d set w h e r e every subset has a least u p p e r b o u n d , a function is continuous lff it p r e s e r v e s least u p p e r b o u n d s of directed subsets, a n d D is directed lff every finite subset of D has an u p p e r b o u n d in D T h e m i n i m u m a n d m a x i m u m e l e m e n t s of a c o m p l e t e lattice are d e n o t e d ~ a n d * , respectively

~2 F o r lattices (and a n a l o g o u s l y for posets, with only ~ ) . the coalesced ~um of two lattices Lj a n d L2 consists o f the disjoint u n i o n (say) L1 x { 1 } U L2 × {2} with (-% 1) a n d (-r, 1) identified respectively with (_t_, 2), (-% 2) u n d e r the o b v i o u s o r d e r i n g T h e separated s u m is the disjoint u n i o n with new x a n d -1- a d l o m t e d , x C (1, z) C_ -r for all 1 E L, a n d i ~ {1, 2}.

(11)

78 J . A . G O G U E N , J. W. THATCHER, E. G. W A G N E R , A N D J. B. WRIGHT We wish variables to have values in V. Thus let E be the set of environments, 1.e. of all total functions from X to V, E = V x as a complete lattice with componentwise ordering e E_ e' iffe(x) ~ e'(x) in V for allx ~ X. Finally, m e a n i n g s of expressions are continuous functions from e n v i r o n m e n t s to values, M = [E ~ V].

M becomes a semantic algebra when we define an operation on M for each production of SAL; letx, let-recx, and apply are of rank 2, functions M 2 ~ M; c o n d is rank 3; absx is rank 1; and vx is rank 0, a constant.

To carry this out, we define some auxdiary continuous functions (and functionals).

O u r presentation here is rather sketchy since this development Is what Scott, Strachey, and followers do anyway, and our aim here is just to show that the relation to the mitml algebra framework.

(3.1) access~ : E ~ V is the evaluation function on V x at x ~ X : access~(e) = e(x).

(3.2) c : V 3 ~ V is some conditional, say:

i -r

if vl

= - r ,

c(v~, v2,

v3) =

ffv~ = true, v3 flY1 = false,

_L otherwise.

(3.3) ap : V 2 - ~ V is application: ap(vl, v2) = (~'~v--,v~(vl))(v2), where 7rfwvl is the in- dicated projection; see discussion following (*) above.

(3.4) assign~ : E × V ~ E is our friend the assignment operator:

{~ i f y = x, assigns (e, v) = e' where e'@) = e@) otherwise.

A l l o f the a b o v e have etther been s h o w n to be c o n t i n u o u s or can eastly be s h o w n to be such. In addttion, Scott 1-63] defines

(3.5) abstract : [D × D ' ~ D"] ~ [D ~ [D' ~ D"]] by ((abstract(f))(x))(y) = f ( x , y ) for a l l f ~ [D × D ' ~ D"], x ~ D , a n d y E D ' .

Here we too enjoy some notational amblgmty by writing "abstract" instead of

"abstracto.D,,o,"; and similarly in other cases.

(3.6) The least fixed point operator Y : [D ~ D] ~ D is continuous.

(3.7) If m, : E ~ V, (1 -< i -< k) are continuous, then [ml, "'" , mk] : E --~ V1 × " " × V~ defined by [ml, "'" , mk](e) = (ml(e), " " , ink(e)) Is continuous (called target-tupling)

(3.8) For continuous functions f : D ~ D ' and f ' : D ' ~ D", the composite f ' o f is continuous; and so is composition itself, o : ([D' --~ D"] z [D ~ D']) ~ [D ~ D"].

Now make M = [ V x ~ V] into a SAL-algebra by gwmg an appropriate operation for each production of SAL:

v x = access ~

c o n d ( m l , m s , m3) = c o Ira1, m2, m3]

apply(m1, m2) = ap o [ m l , mz]

abs z(m ) = t[v~vl o abstract(m o assign x) letx(ml, m2) = ms ° asstgnx o [1E, ml]

let-recx(ml, m2) = letx(y ° abstract(ml o assign×), m2)

Actually the defimtions of most of these operations seem to be clearer as dmgrams, since the source and target of each f u n c u o n is e x p h o t . " A b s t r a c t i o n " is regarded as a way of getting one function from another The funcUon " a s s u m e d " (or given) appears on the top, the function " d e d u c e d " appears below it, and the process is represented by a line between them; thus

D × D ' - f ~ D "

~' D"]

D ---~ [ D' ---~

for g = abstract(f). T h e n the first five definitions are:

(12)

lnittal Algebra Semantics and C o n t m u o u s Algebras 79 (1) vx = E ... ~V

(2) c o n d ( m l , m2, m3) = E ["!: . . . J~, V 3 ..5_, V (3) a p p l y ( m , , rn2) E ~ V 2 "p '~ g

E x V .... g"~ ' E ~ V (4) abs~(m) = E --~ [ V --* V] ... , V

(5) letz(ml, m~) = E I-I~'m~1, E X V .... u,~ E - - - - ~ V ,,~

With M a S A L - a l g e b r a , tlae unique h o m o m o r p h l s m h u : TG --~ M is a semantics for S A L . There is no claim for great gains in perspicuity, but our m o d e of definition does illuminate the places where semantic choices are m a d e . It is through the Introduction of standard mathematical f u n c t i o n s - c o m p o s i U o n , tupilng, injecUon, and the l i k e - t h a t these choices are clarified, and this process has the a d d m o n a l benefit of getting n d of the need for-"dragging along" the variable for environments.

Given the particular conditional and application functions ((3.2) and (3.3) respec- tively), then the functions c o n d and apply ((2) and (3) respectively) on the semantic carrier M are essentially the only choices possible; this differs from R e y n o l d ' s meta- circular interpreters in that he presumes a "defining l a n g u a g e " m which the Interpreters are written and the semantic choices have not been c o m p l e t e l y made for that meta- language. In the semantic c a r e e r E---~V, there is simply no way to m a k e a distinction between o r d e r of evaluation of o p e r a t o r and o p e r a n d in (2), for example. If expressions had side effects and E - - - ~ E x V were taken as carrier, then the two orders of evaluation would be clearly r e p r e s e n t e d in

m2 mlXl~)

E ~ E x V E x V x V - k . ~ - ~ E x V and

E - - 4 E x V ,,,,×1, E x V x V z'×a.P'~ExV, where ap'(vl, v2) = ap(v2, vl) = v2(vl) and f x g ( a , b) = ( f ( a ) , g(b))

3.3. SYNTAX DIRECTED TRANSLATION. The noUon of syntax directed translation p i o n e e r e d by Irons [29] has been mathematically treated by several authors [1-3, 30, 35, 50, 63, 73]. W e can wew these technical interpretations of syntax directed translation as special cases of initml algebra semantics with the "semantic a l g e b r a " nearly flee. T h e r e are two problems: First, we a r e n ' t yet sure how best to treat " n o n d e t e r m i m s t i c "

translation and therefore d o n ' t . Second, we only formulate various concepts, giving neither new results nor simplified proofs We hope that the reader, faced with these r e m a r k a b l y simple definmons, may be moved to simplify and e x p a n d the theoretical d e v e l o p m e n t .

Just as generahzed sequentml machines [19] m a p E* to X'* (for alphabets ~, and X'), syntax directed maps go from T~ to T x, (for o p e r a t o r domains X and X'). Just as one later restricts a generalized sequential machine to a subset o f X* (e.g. a context-free language), one can later consider a syntax directed m a p on a subset of T~, say a set of derivation or parse trees

Thatcher [69] shows that many prior formulations of syntax translation are special cases of a general algebrmc formulaUon. So do we here, but with even greater s i m p l i o t y , if less m t u m v e transparency.

Definition 3.1 A k-state root to frontier syntax m a p from T x into T x, is the unique h o m o m o r p h l s m h : Tx ~ (T~,) k g u a r a n t e e d by lnltmhty of Tx after making (Tx,) k into a E-algebra. The set [k] = {1, 2, • • • , k} is the set o f states. Ifh(t) = (It, • • • , tk), then t, is the image of t under the syntax map from start state t. []

The standard e x a m p l e (cf. Rounds [57], Thatcher [69]) is polynomial derivative.

T a k e X0 = {0, 1, x}, Xz = {+, x} and define a (2-state) syntax m a p (from Tx to T~) by placing the following X-structure on (Ts)Z:

(13)

8 0 J A GOGUEN, J. W THATCHER, E. G. WAGNER, AND J B. WRIGHT

(t'l, t i ) + (t~, t 2 ) = (t~ + t~,ti + t2)

(t'l, t l ) × (t~, t2) = ((t~ × t2) + (tl × t ~ ) , t l × tz) o = <o, o)

i = <o, 1) x = (1, x )

T h e s e " e q u a t i o n s , " e s p e c i a l l y the last t h r e e , m a y be s o m e w h a t confusing; of c o u r s e the s y m b o l s + , × , 0, 1, x are f r o m X a n d , for e x a m p l e , the last e q u a t i o n says t h a t x in X n a m e s the p a i r (1, x) in (T~) 2 of o b j e c t s n a m e d by 1 and x (each m Tx).

N o w h : Tx--~ (T=) 2 yields h(t) = (t', t); the left m e m b e r of the p a i r is the ( u n s i m p l i f i e d ) d e r i v a t i v e and the right m e m b e r is lust t again.

The d e f i m t i o n simphfies a n d e n c o m p a s s e s T h a t c h e r ' s [69] " r o o t to f r o n t i e r a u t o m a - ton with o u t p u t " (called "finite state t r a n s f o r m a t i o n " in [68]). I n t u i t i v e l y , if t = or(t', t"), t~ is the t r a n s l a t i o n of t' f r o m r o o t (start) state t, a n d t~' is the t r a n s l a t i o n of t" f r o m state :, t h e n o'((t~, . . - , t~>, (t~, . - . , t~))~ is the t r a n s l a t i o n o f or(t', t") f r o m state 1.

I f k = 1 a n d the E - s t r u c t u r e on T~, is u n i f o r m m the sense that for each o- ~ E,, t h e r e ts a t e r m t , in T x , ( X , ) such t h a t for all t' ~ Tz,, or(t~, • • • , t;,) = t , ,,-- (t~, • • • , t~,), t h e n the resulting syntax m a p is c a l l e d a h o m o m o r p h t s m , g e n e r a l i z i n g the h o m o m o r p h i s m s of o r d i n a r y f o r m a l l a n g u a g e t h e o r y If, m a d d i t i o n , each t , is h n e a r (no r e p e t i t i o n s o f v a r i a b l e s ) , then the resulting m a p s include the " s y n t a x d i r e c t e d t r a n s l a t i o n s " of L e w i s a n d S t e a r n s [34] and the syntax d i r e c t e d t r a n s l a t i o n s c h e m e s of A h o a n d U I l m a n [1]. If k >- 1 and the X-structure on (Tx,) k is u n i f o r m in the a b o v e sense, our syntax m a p s include

the g e n e r a h z e d syntax d i r e c t e d t r a n s l a t i o n s c h e m e s of A h o a n d U l l m a n [2].

T h e o t h e r case of s y n t a x d i r e c t e d t r a n s l a t i o n we want to c o n s i d e r is f r o n t i e r to r o o t translation. O u t s i d e tree a u t o m a t a t h e o r y (1.e. o u t s i d e B a k e r [3], M a g i d o r and M o r a n [40], T h a t c h e r [69], e t c . ) we d o n ' t seem to find f r o n t i e r to r o o t t r a n s l a t i o n as m u c h as r o o t to f r o n t i e r m a p s , e x c e p t when they c o i n c i d e (k = 1). B u t the d e f i n i t i o n of finite state fronUer to r o o t syntax m a p is r e m a r k a b l y s i m p l e a n d p a r t i c u l a r l y i n t e r e s t i n g in that it ~s o b t a i n e d by r e p l a c i n g " k t h p o w e r " in D e f i n i t i o n 3.1 by " p r o d u c t with k . " ( M o r e technically, we r e p l a c e the " k - f o l d p r o d u c t of Tx," wxth its c a t e g o r y t h e o r e t i c d u a l , the

" k - f o l d c o p r o d u c t of Tx,.")

D e f i m t t o n 3 2. A k-state f r o n t i e r to r o o t s y n t a x m a p f r o m Tx to Tx, Is the u n i q u e h o m o m o r p h i s m h : T~ ~ [k] × T~, g u a r a n t e e d by m l t i a h t y of T~ a f t e r m a k i n g [k] × T~, into a E - a l g e b r a . T h e set [k] = {1, 2, • • • , k} is the set o f states. If h(t) = (:, t'), then t' is

the i m a g e of t a n d the t e r m i n a t i n g state is i. []

F o r e x a m p l e , a tree a u t o m a t o n ( D o n e r [15], T h a t c h e r a n d W r i g h t [70]) with transi- tion function M : X × [k]" ~ [k] is i m i t a t e d as a f r o n t i e r to r o o t s y n t a x m a p by m a k i n g [k] x T z into a E - a l g e b r a with or(<i~, t,), • - • , (i,, t,)) = (M(or, i,, • • • , i~), or(t, • • • t , ) ) , the s e c o n d c o m p o n e n t is the ~dentlty.

3 4. SYSTEMS o r EQUATIONS. If A is a E - a l g e b r a , we m a k e p A (the set of s u b s e t s o f A ) into a Z - a l g e b r a with the " s u b s e t c o n s t r u c t i o n " :

(0) F o r or ~ Xo, OvA = {orA}.

(1) F o r n > 0 , or G X,, and ut, . . . , u , ~ p A ,

o r ~ ( u , , . - . , u , ) = {ora(t,, " - " , t , ) i t , ~ u , , 1 -< ~ - n } .

A s s o c i a t e d with each t ~ T x ( X , ) is a d e r i v e d o p e r a t o r tEA : ( p A ) " - + p A ; e x t e n d i n g this idea to sets of t e r m s , if r C_ p T ~ ( x , ) , d e f i n e

rvA(U,,

" ' " , Un) = I,.J{tea ( U , , " - " , Un) i t ~ r } .

E : X n ~ p T z ( X , ) is called a s y s t e m o f e q u a t : o n s (in n v a r i a b l e s ) which d e t e r m i n e s a function Epa : (pA)" ~ (pA) ", by E~A = [E(XOeA, " " " , E(xn)pa] (target-tupling), called the s y s t e m f u n c t i o n b y M e z e l a n d W r i g h t [45], who show that EeA is o - c o n t i n u o u s , i.e.

least u p p e r b o u n d s of o - c h a i n s in ( p A ) " are p r e s e r v e d . T h e r e f o r e Epa has a m i n i m u m fixed p o i n t , called its s o l u t i o n , say (s~, • • • , s , ) G W A ) " ; in fact,

(s,, . . . , s , ) = tJkE~A(O, " ' " , ~ ) .

Referenzen

ÄHNLICHE DOKUMENTE

actions user.ejectCard(); trialsNum = 0, trialsNum++, messages user.ejectCard(), bank.markInvalid(cardId).. .}, {Idle}) In particular, PINEntered occurs both as a state and as

I Axiomatic semantics tries to give a meaning of a programming construct by giving proof rules. This means we have to put them into relation with each other, and show that

Since the flow of control in the specific FFT-program does not depend on concrete val- ues of floating point numbers (but only on integer values in loop counters) and because

Zero-safe nets provide a notion of transactions over parts of a net by distinguishing bet- ween so called stable places and zero places. A marking in which all tokens are on

F σ denotes formalism F under semantics σ, where “su” is the supported and “st ” the stable model semantics; formalisms are among AFs (argumentation frameworks), ADFs

Andrea

meaning of the mother node can be computed from the meanings of the daughter nodes:.. for non-branching nodes, mother node and daughter node have the

Just like APs, PPs have a predicative and a attributive use (plus an adverbial use, that will not be covered here). same systematic relationship between predicative and attributive