A Resumption Monad Transformer and its Applications in the Semantics of Concurrency Λ - PDF

Description
A Resumptio Moad Trasformer ad its Applicatios i the Sematics of Cocurrecy Nikolaos S. Papaspyrou Natioal Techical Uiversity of Athes, Departmet of Electrical ad Computer Egieerig,

Please download to get full document.

View again

of 10
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Information
Category:

Services

Publish on:

Views: 29 | Pages: 10

Extension: PDF | Download: 0

Share
Transcript
A Resumptio Moad Trasformer ad its Applicatios i the Sematics of Cocurrecy Nikolaos S. Papaspyrou Natioal Techical Uiversity of Athes, Departmet of Electrical ad Computer Egieerig, Software Egieerig Laboratory, Polytechioupoli, 1578 Zografou, Athes, reece. Abstract Resumptios are a valuable tool i the aalysis ad desig of sematic models for cocurret programmig laguages, i which computatios cosist of sequeces of atomic steps that may be iterleaved. I this paper we cosider a geeral otio of resumptio, parameterized by the kid of computatios that take place i the atomic steps. We defie a moad trasformer which, give a moad M that represets the atomic computatios, costructs a moad R(M ) for iterleaved computatios. Moreover, we use this moad trasformer to defie the deotatioal sematics of a simple imperative laguage supportig odetermiism ad cocurrecy. 1 Itroductio Moder computer architectures ad operatig systems have made it practical to execute differet parts of a program simultaeously. From the programmer s poit of view, it is ofte ot importat whether the parts of a program are executed by differet physical processors or by a sigle processor usig a time-sharig strategy. New tools are eeded to defie the sematics of cocurret programmig laguages, which allow the parts of a program that execute simultaeously to iteract with oe aother, typically usig the same memory variables. Resumptios have log bee suggested as a model of iterleaved computatio i the sematics of cocurret programmig laguages. I brief, a resumptio is either a computed value of some domai D or a atomic computatio that results i a ew resumptio. A extesive treatmet is offered i [dbak96] usig the theory of com- This paper is based o work supported by the Natioal Techical Uiversity of Athes, uder the Programme for the Support of Basic Research Archimedes. Project title SySemAL: Sytax ad Sematics of Artificial Laguages. plete metric spaces as the mathematical framework for domais. May variatios of resumptio domais (also called brachig domais) for specific istaces of atomic computatios are ivestigated there. I this paper, we propose a structured geeralizatio of this techique. We allow the atomic steps to perform ay type of computatio, represeted by a arbitrary moad M. Thus, we defie the resumptio moad trasformer R, which trasforms moad M to a ew moad R(M ) represetig iterleaved computatios. Domais costructed by R(M ) satisfy the isomorphism R(M )(D) ' D + M (R(M )(D)) which defies the essece of resumptio domais. By itroducig R(M ) we obtai a geeral framework for reasoig about such domais. For example, the domai D ' U +(S! P(S D)) that is used i [dbak96] for defiig the sematics of ouiform parallelism (igorig some complexities related to the use of complete metric spaces) is exactly the same as the domai R(D(P))(U) that we use i Sectio 4 for the same purpose. The rest of the paper is structured as follows. Sectio 2 cotais a brief itroductio to moads as part of the mathematical backgroud that is required for this paper. I Sectio 3 we defie the resumptio moad trasformer R ad i Sectio 4 we use it to preset the deotatioal sematics of a simple imperative laguage featurig o-determiism ad cocurrecy. We coclude with Sectio 5. 2 Mathematical backgroud I this sectio we defie part of the mathematical backgroud that is ecessary for the rest of the paper. We itroduce moads ad moad trasformers ad discuss their 1 coectio with computatios ad the sematics of programmig laguages. The reader is referred to [Papa1] for a more complete ad iformative itroductio, ad to the literature related to category theory [Pier91, Aspe91, Barr96] ad domai theory [Scot82, ut9]. 2.1 Moads ad moad trasformers The otio of moad, also called triple, is ot ew i the cotext of category theory. I Computer Sciece, moads became very popular i the 199s. The categorical properties of moads are discussed i most books o category theory, e.g. i [Barr96]. For a comprehesive itroductios to moads ad their use i deotatioal sematics the user is referred to [Mogg9]. A somehow differet approach to the defiitio of moads is foud i [Wadl92], which expresses the curret practice of moads i fuctioal programmig. The two approaches are equivalet. I this paper, the categorical approach (preseted here) is used for the defiitio of moads, sice it is much more elegat, ad the fuctioal approach (preseted i Sectio 2.2) is used for describig the sematics of programmig laguages. Defiitio 2.1 A moad o a category C is a triple hm; ; μi, where M : C! C is a edofuctor, : Id C _! M ad μ : M 2 _! M are atural trasformatios. For all objects x i C, the followig diagrams must commute. M (x) M(x) - M 2 (x) ff M ( x) M μ x id R Ψ? M (x) id M(x) M 3 (x) M (μ x) - M 2 (x) μ M(x)? M 2 (x) μ x μ? x - M (x) The trasformatio is called the uit of the moad, whereas the trasformatio μ is called the multiplicatio or joi. The commutativity of these two diagrams is equivalet to the followig three equatios, commoly called the three moad laws: μ x ffi M(x) = id M(x) (1st Moad Law) μ x ffi M ( x ) = id M(x) (2d Moad Law) μ x ffi M (μ x ) = μ x ffi μ M(x) (3rd Moad Law) Defiitio 2.2 If C is a category, a moad trasformer o C is a mappig betwee moads o C Moads ad computatios A alterative approach to the defiitio of moads has become very popular i the fuctioal programmig commuity. Accordig to this, a moad o category Dom is defied as a triple hm;uit M ; M i. I this triple M is a domai costructor, uit M : D! M (D) is a cotiuous fuctio ad M : M (A) (A! M (B))! M (B) is a biary operatio. I the sematics of programmig laguages, domais costructed by moad M typically deote computatios, e.g. the domai M (D) deotes computatios returig values of the domai D. The result of uit M v is simply a computatio returig the value v ad the result of m M f is the combied computatio of m, returig v, followed by computatio f (v). Moad trasformers are useful to trasform betwee differet types of computatios [Lia95, Lia98]. The followig equatios coect a moad hm;uit M ; M i defied usig the fuctioal approach with a moad hm; ; μi defied usig the categorical approach. uit M = m M f = (μ ffi M (f )) m = uit M μ = m:m M id M (f ) = m:m M (uit M ffi f ) I the fuctioal approach, the three moad laws ca be formulated as follows. m M uit M = m (uit M v) M f = fv m M ( v:(f v) M g) = (m M f ) M g A iterestig remark is that these three laws are eough to prove that the equivalet (M; ; μ), as defied above, is ideed a moad, i.e. that M is a fuctor (preserves fuctio idetities ad compositio) ad ad μ are atural trasformatios. I this settig, it is useful to defie two special classes of moads, equipped with additioal operatios that are 1 May optios for the defiitio of moad trasformers have bee suggested i literature. ive a category C, moads o C ad moad morphisms (which have ot bee defied i this paper) form a category Mo(C). Moad trasformers ca be defied as mappigs betwee objects i Mo(C), as edofuctors o Mo(C), as premoads o Mo(C) (i.e. edofuctors with a uit), ad as moads o Mo(C). I this paper we have selected the first optio. 2 useful for modelig the sematics of cocurrecy i programmig laguages. Defiitio 2.3 A multi-moad is a moad M with a biary operatio k M : M (D) M (D)! M (D), where D is a domai. Defiitio 2.4 A strog moad is a moad M with a biary operatio./ M : M (A) M (B)! M (A B), where A ad B are domais. The biary operatio k of a multi-moad is used to express disjuctio i computatios. I other words, if M is a multimoad, D is a domai ad m 1 ;m 2 2 M (D) are two computatios, the computatio m 1 k m 2 idicates a (possibly o-determiistic) optio betwee m 1 ad m 2. Moreover, the biary operatio./ of a strog moad is used to express cojuctio i computatios. Let M be a strog moad, let A ad B be domais. If m 1 2 M (A) ad m 2 2 M (B) are two computatios, the computatio m 1./ m 2 idicates that both m 1 ad m 2 will be performed ad their results will be combied. The optio here relates to the order, if ay, i which the two computatios will be performed. 3 Resumptio moad trasformer The otio of executio iterleavig is a well kow oe i the theory of cocurrecy. I this cotext, computatios are cosidered to be sequeces of atomic steps the ature of which depeds o our otio of computatio. I isolatio, these atomic steps are performed oe after aother util the computatio is complete. ive two computatios A ad B, a iterleaved computatio of A ad B cosists of a arbitrary mergig of the atomic steps that costitute A ad B. Iterleavig easily exteds to more tha two computatios. The atomic steps of ay computatio must still be executed i the right order, but this process ca be iterrupted by the executio of atomic steps belogig to other computatios. Our primary goal is to defie a moad trasformer R capable of modellig geeric iterleaved computatios. I this way, if we are give a moad M which models the computatios takig place at the atomic steps, we ca obtai a moad R(M ) which models iterleaved computatios of such atomic steps. Oe possible solutio to this problem is to use the log suggested techique of resumptios, illustrated i [Schm86, dbak96] for specific istaces of M. eeralizig this techique, the domai R(M )(D) of resumptios must satisfy the followig isomorphism: R(M )(D) ' D + M (R(M )(D)) I this domai, atomic steps are arbitrary computatios defied by M. The left part of the sum represets a already evaluated result, i.e. a computatio that cosists of zero atomic steps. The right part represets a computatio that requires at least oe atomic step. The result of this atomic step is a ew elemet of the resumptio domai. We start by cosiderig a arbitrary locally cotiuous moad M o Dom. The rest of the sectio is orgaized as follows. I Sectio 3.1 we defie a edofuctor R M : Dom! Dom. I Sectio 3.2 we defie two atural trasformatios uit : Id _! R M ad joi : R 2 M _! R M ad i Sectio 3.3 we prove that (R M ; uit ; joi ) satisfies the three moad laws. I this way we defie the moad trasformer R. Next, i Sectio 3.4 we prove that R(M )(D) satisfies the aforemetioed isomorphism by costructig the two compoets h e ad h p of the isomorphism. Fially, i Sectio 3.5 we defie a few additioal operatios o domais costructed by R(M ). Most proofs of the results cotaied i this sectio have bee omitted due to space restrictios. The reader is referred to [Papa1] for more details. 3.1 Fuctor R M We start by defiig for each domai D a edofuctor F M;D : Dom! Dom, ad some auxiliary fuctios. The domai R(M )(D) that we are tryig to defie is a fixed poit of F M;D. Defiitio 3.1 Let D, A ad B be domais ad f : A! B a cotiuous fuctio. We defie the followig mappigs: F M;D (X) = D + M (X) F M;D (f ) = [ il ; ir ffi M (f )] Theorem 3.1 F M;D : Dom! Dom is a fuctor. Defiitio 3.2 Let D be a domai. We defie the pair of fuctios e : O! F M;D (O) ad p : F M;D (O)! O to be equal to?. We proceed by defiig a mappig of objects ad a mappig of fuctios, which will defie the edofuctor R M : Dom! Dom at the ed of this sectio. Defiitio 3.3 Let D be a domai. The domai R M (D) is the set R M (D) = f (x )2! j 8 2!: x 2 F M;D (O) ^ x = F ( p)(x M;D +1 ) g with its elemets ordered poitwise: (x )2! v R M (D) (y )2!, 8 2!: x v F M;D (O) y 3 Defiitio 3.4 Let D be a domai. For all m; 2!, we defie a fuctio fm; D : Fm M;D (O)! F M;D (O) by: f D m; = id F M;D (O),ifm = f D m;+1 = f D m; ffi F M;D ( p),ifm» f D m+1; = F m M;D ( e) ffi f D m;,ifm Defiitio 3.5 Let D be a domai, 2!, z 2 F M;D (O) ad (x m )m2! 2 R M (D). We defie the pair of fuctios μ e : F M;D (O)! R M (D) ad μ p : R M (D)! F M;D (O) as follows: μ e z = (f m; D z) m2! μ p (x m)m2! = x Defiitio 3.6 Let A ad B be domais ad f : A! B a cotiuous fuctio. For all 2! we defie a cotiuous fuctio A;B f : F M;A (O)! F M;B (O) by: A;B f =? A;B +1 f = [ il ffi f;ir ffi M ( A;B f )] Defiitio 3.7 Let A ad B be domais ad f : A! B a cotiuous fuctio. We defie a cotiuous fuctio R M (f ):R M (A)! R M (B) by: R M (f )(x )2! = ( A;B fx )2! The cetral result of this sectio is Theorem 3.2 i which we prove that R M is a fuctor. For doig so, we make use of the followig lemmata. Lemma 3.1 For all m; 2!, μ p m ffi μe = f D m;. Lemma 3.2 Let A be a domai. The for all 2!, A;A id A = id F M;A (O) Lemma 3.3 Let A, B ad C be domais, f : A! B ad g : B! C cotiuous fuctios. The for all 2!, A;C (g ffi f )= B;C g ffi A;B We ca ow proceed with the proof of Theorem 3.2. Theorem 3.2 R M : Dom! Dom is a fuctor. Proof We must prove that R M preserves idetities ad the compositio of cotiuous fuctios. 1. Let X be a domai ad (x )2! 2 R M (X). R M (id X )(x )2! = h Defiitio of R M i ( X;X id X x )2! = h Lemma 3.2 i (id F M;X (O) x )2! = h Idetity fuctio i (x )2! = h Idetity fuctio i id R M (X) (x )2! f 2. Let A ad B be domais, f : A! B ad g : B! C cotiuous fuctios ad (x )2! 2 R M (X). R M (g ffi f )(x )2! = h Defiitio of R M i ( A;C (g ffi f ) x )2! = h Lemma 3.3 i (( B;C g ffi A;B f ) x )2! = h Compositio i ( B;C g ( A;B fx ))2! = h Defiitio of R M i R M (g) ( A;B fx )2! = h Defiitio of R M i R M (g) (R M (f )(x )2!) = h Compositio i (R M (g) ffi R M (f )) (x )2! 3.2 Uit ad joi Havig defied R M as a fuctor, we ow defie the two moad operatios uit ad joi. For each oe, we prove that it is a atural trasformatio. Defiitio 3.8 Let D be a domai. For all 2! we defie a cotiuous fuctio D : D! F M;D (O) by: D =? D +1 = il Defiitio 3.9 Let D be a domai ad d 2 D. We defie the fuctio uit D : D! R M (D) by: uit D d = ( D d) 2! Lemma 3.4 Let A ad B be domais, f : A! B a cotiuous fuctio. The, for all 2!, A;B f ffi A = B ffi f Theorem 3.3 uit : Id _! R M is a atural trasformatio. Proof Let A ad B be domais ad f : A! B a cotiuous fuctio. We must show that uit B ffi f = R M (f ) ffi uit A. Let a 2 A. uit B (fa) = h Defiitio of uit i ( D (fa)) 2! = h Compositio i (( D ffi f ) a) 2! = h Lemma 3.4 i (( A;B ffi A ) a) 2! = h Compositio i ( A;B ( A a)) 2! = h Defiitio of R M i 4 R M (f )( A a) 2! = h Defiitio of uit i R M (f )(uit A a) Defiitio 3.1 Let D be a domai. For all 2! we defie a cotiuous fuctio ο D : F M;RM (D) (O)! F M;D (O) by: ο D =? ο D +1 f = [ μp +1 ; ir ffi M (οd )] Defiitio 3.11 Let D be a domai ad (x )2! 2 R 2 M (D). We defie the fuctio joi D : R2 M (D)! R M (D) by: joi D (x )2! = (ο D x )2! Lemma 3.5 Let A ad B be domais, f : A! B a cotiuous fuctio. The for all 2!, ο B ffi RM (A);RM (B) (R M (f )) = A;B f ffi ο A Theorem 3.4 joi : R 2 M _! R M is a atural trasformatio. Proof Let A ad B be domais ad f : A! B a cotiuous fuctio. We must show that joi B ffi R M (R M (f )) = R M (f ) ffi joi A. Let (x )2! 2 R 2 M (A). joi B (R M (R M (f )) (x )2!) = h Defiitio of R M i RM (A);RM (B) joi B ( (R M (f )) x )2! = h Defiitio of joi i (ο B (A);RM (B) ( RM = h Compositio i ((ο B ffi RM (A);RM (B) (R M (f )) x ))2! (R M (f ))) x )2! = h Lemma 3.5 i (( A;B f ffi ο A ) x )2! = h Compositio i ( A;B f (ο A x ))2! = h Defiitio of R M (f ) i R M (f )(ο A x )2! = h Defiitio of joi i R M (f )(joi A (x )2!) 3.3 Moad R(M ) I this sectio we prove that fuctor R M together with the atural trasformatios uit ad joi defies a moad. The three theorems of this sectio verify the three moad laws. The followig lemmata are ecessary for provig the moad laws. Let D be a domai. Lemma 3.6 For all 2!, ο D ffi RM (D) = μ p. Lemma 3.7 For all 2!, ο D ffi D;RM (D) Lemma 3.8 For all d 2!, ο D ffi R2 M (D);RM (D) uit D = id F M;D (O) joi D = ο D RM (D) ffi ο We ca ow proceed by provig the three moad laws. Theorem 3.5 (1st Moad Law) joi D ffi uit R M (D) = id R M (D) Proof Let (x )2! 2 R M (D). The joi D (uit R M (D) (x )2!) = h Defiitio of uit i RM (D) joi D ( = h Defiitio of joi i (ο D ( RM (D) = h Compositio i RM (D) (x m )m2!)2! (x m )m2!))2! ((ο D ffi )(x m )m2!)2! = h Lemma 3.6 i (μ p (x m)m2!)2! = h Defiitio of μ p i (x )2! Theorem 3.6 (2d Moad Law) joi D ffi R M (uit D )=id R M (D) Proof Let (x )2! 2 R M (D). The joi D (R M (uit D )(x )2!) = h Defiitio of R M i D;RM (D) joi D ( uit D x )2! = h Defiitio of joi i (ο D (D) ( D;RM uit D x ))2! = h Compositio i ((ο D D;RM (D) ffi uit D ) x )2! = h Lemma 3.7 i (id F M;D (O) x )2! = h Idetity i (x )2! Theorem 3.7 (3rd Moad Law) Proof joi D ffi R M (joi D )=joi D ffi joi R M (D) Let (x )2! 2 R 3 M (D). The joi D (R M (joi D )(x )2!) = h Defiitio of R M i joi D ( R2 M (D);RM (D) joi D x )2! = h Defiitio of joi i (ο D ( R2 M (D);RM (D) joi D x ))2! = h Compositio i ((ο D ffi R2 M (D);RM (D) joi D ) x )2! 5 = h Lemma 3.8 i ((ο D ffi ο = h Compositio i (ο D RM (D) ) x )2! (οrm (D) x ))2! = h Defiitio of joi i RM (D) joi D (ο x )2! = h Defiitio of joi i joi D (joi R M (D) (x )2!) Havig established that R M satisfies the three moad laws, we ca ow coclude the defiitio of the resumptio moad trasformer R. Defiitio 3.12 The resumptio moad trasformer R is defied by the mappig R(M )=R M. 3.4 Isomorphism Let D be a domai. I this sectio, we defie the pair of fuctios h e ad h p that establish the isomorphism betwee domais R M (D) ad D + M (R M (D)). Usig these fuctios, it is possible to defie a operatio i oe of these two domais ad obtai the correspodig operatio o the other domai by applyig h e ad h p appropriately. The defiitio of the embeddig fuctio h e is straightforward. Defiitio 3.13 For all 2! we defie a fuctio D : F M;D (R M (D))! F M;D (O) by: D =? D +1 = [ il ; ir ffi M (μ p )] Defiitio 3.14 Let z 2 F M;D (R M (D)). We defie the fuctio h e : F M;D (R M (D))! R M (D) by: h e z = ( D z) 2! O the other had, the defiitio of the projectio fuctio h p is more complicated. It first requires the defiitio of a additioal domai Q M (D). Furthermore, it requires the proof of Lemma 3.9, which states that elemets of R M (D) come i three distict forms. This lemma is crucial i the defiitio of h p ad i the proofs of several theorems that follow. Defiitio 3.15 The domai Q M (D) is the set Q M (D) = f (z )2! j 8 2!: z 2 M (F M;D (O)) ^ z = M (F ( p))(z M;D +1 ) g with its elemets ordered poitwise: (z )2! v Q M (D) (w )2!, 8 2!: z v M(F M;D (O)) w Defiitio 3.16 Let (z m )m2! 2 Q M (D). For all 2!, we defie a fuctio ff D : Q M (D)! F M;D (O) by: ff D (z m)m2! =? ff D +1 (z m)m2! = ir z Lemma 3.9 Let (x )2! 2 R M (D). The exactly oe of the followig is true: 1. For all 2!, x =?. 2. There exists a t 2 D such that for all 2!, x = D t. 3. There exists a (z m )m2! 2 Q M (D) such that for all 2!, x = ff D (z m)m2!. Defiitio 3.17 We defie the fuctio h p : R M (D)! F M;D (R M (D)) by case aalysis o its argumet (x )2! based o Lemma 3.9: 1. If for all 2!, x =?, the h p (x )2! =? 2. If there exists a t 2 D such that for all 2!, x = D t, the h p (x )2! = il t 3. If there exists a (z m )m2! 2 Q M (D) such that for all 2!, x = ff D (z m)m2!, the ψ! h p (x )2! = ir M (μ e ) z 2! I order to esure that the least upper boud i the third case of the previous defiitio exists, we prove Lemma 3.1 which states that M (μ e ) z form a!-chai. Lemma 3.1 Let (z )2! 2 Q M (D). For all 2!, M (μ e ) z v M (μ e +1 ) z +1 The followig lemmata are ecessary for provig the cetral theorems of this sectio. Lemma 3.11 For all t 2 D, for all 2!, D (il t) = D t Lemma 3.12 For all w 2 M (R M (D)), for all 2!, D (ir w) =ffd (M (μp m ) w) m2! Lemma 3.13 For all w 2 M (R M (D)), 2! M (μ e ffi μp ) w = w Lemma 3.14 Let (z m )m2! 2 Q M (D). For all m 2!, M (fm; D ) z = z m 2! 6 Ad ow we ca proceed to Theorem 3.8 ad Theorem 3.9, which coclude that the two fuctios h e ad h p defie ideed a isomorphism betwee the domais R M (D) ad D + M (R M (D)). Theorem 3.8 h p ffi h e = id F M;D(RM (D)) Proof By case aalysis o z. Let z 2 F M;D (R M (D)) = D + M (R M (D)). 1. Case z =?. The both sides are equal to? accordig to the defiitios of h e ad h p 2. Case z = il t for some t 2 D. The h p (h e (il t)) = h Defiitio of h e i h p ( D (il t)) 2! = h Lemma 3.11 i h p ( D t) 2! = h Defiitio of h p i il t 3. Case z = ir w for some w 2 M (R M (D)). The h p (h e (ir w)) = h Defiitio of h e i h p ( D (ir w)) 2! = h Lemma 3.12 i h p (ff D (M (μp m ) w) m2!)2! = h Defiitio ψ of h p i! ir M (μ e )(M(μp ) w) 2! = h Compositio, ψ M is a fuctor i ir 2! = h Lemma
Related Search
Similar documents
View more...
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks