Full Abstraction for a Recursively Typed Lambda Calculus with Parallel Conditional
We define the syntax and reduction relation of a recursively typed lambda calculus with a parallel case-function (a parallel conditional). The reduction is shown to be confluent. We interpret the recursive types as information systems in a restricted…
Authors: Fritz M"uller
F ull Abstraction for a Recursiv ely T yp ed Lam b da Calculus with P arallel Conditional ∗ F ritz M ¨ uller email : ( λ x.muel lerxc s.uni-sb.de)@ URL: rw4.cs .uni- sb.de/~mueller/recurs ive.ps.gz 1993 Abstract W e defin e the syn tax and reduction relation of a recursiv ely t yp ed lambd a calculus with a paralle l case-function (a parallel conditional). T he reduction is sho wn to be confluen t. W e interpret the recursiv e t yp es as information systems in a restricted form , wh ic h we call prime systems . A denotational semanti cs is defined with this interpretation. W e defin e the syn tactical normal f orm approx- imations of a term and pr o v e the Approximati on T heorem: The seman tics of a term equals the limit of the semantic s of its ap p ro ximations. The p r o of uses inclusiv e p redicates (logical relations). T he s emantics is adequate with r esp ect to th e obs er v ation of Bo olean v alues. It is also fully abstract in th e presence of the parallel case-function. Keyw ords: lam b da calculus, recursive t yp e, parallel conditional, parallel or, confluence, denotational semantics, information system, app ro ximation th eorem, limiting completeness, inclusive predicates, adequacy , f ull abstraction 1 In tro duction In his seminal pap er [Plo77], Gordon Plotkin explores the relationship b et w een the op erational (reduction) seman tics and the denotational sem antics of the f unctional programming langua ge PCF. PCF is a call-b y-name t yp ed lam b da calculus with the ground ty p es b o olean and in teger, and an y functional t yp e. In order to compare op erational and denotational seman tics, one defines a notion o f o p erational observ ation and a preorder on terms induced by this notion. In the case of PCF, the observ a tion is of in teger v alues only , and the preorder is defined by observ ation of ar bitrary terms ∗ revised version of Repo rt 12 /1993 of SFB 124, FB 14 - Informatik, Universit¨ at des Saa rlandes, Saarbr ¨ uc ken 1993 1 1 INTR ODUCTION 2 through integer conte xts. The closed terms of g r ound t yp e integer are singled out as pr o gr ams . Programs are regarded as the only terms whose syn tactical v alues (integers ) can b e observ ed directly . If the semantic s o f a progr a m M is an integer v alue i , then M can b e reduced to i . This result is called the ade quacy of t he seman tics. (The denotational seman tics is simply called the seman tics here and in the follow ing.) A more general result ab o ut terms of an y t yp e is the Appr oximation Th e or em or limiting completeness, as prov ed in [W ad78] for the un ty p ed lambda calculus and in [Ber79 ] for PCF. The appro ximations of a term M are defined, roughly , as the normal form prefixes of the reducts of M . The Appro ximation Theorem states that the seman tics of a term equals the limit of the seman tics of its approx imations. Plotkin’s programme pro ceeds as follows: The op erational preorder on terms is defined as M ⊑ N iff for all con texts C [ ] suc h tha t C [ M ] and C [ N ] are progr a ms: if C [ M ] reduces to a v alue i , then also C [ N ]. If S [ [ M ] ] ⊑ S [ [ N ] ], where S is the seman tics function, then M ⊑ N ; this follo ws from adequacy . The con v erse, if M ⊑ N then S [ [ M ] ] ⊑ S [ [ N ] ], is not true for PC F with only sequen tial op erations. This is due to the fact that there are para llel functions in the seman tic mo del, lik e the parallel or, that cannot b e defined syn tactically . But when a para llel if- op eration, or the para llel o r , is added to the syn tax, then “if M ⊑ N t hen S [ [ M ] ] ⊑ S [ [ N ] ]” holds. This is called the ful l abstr action of the seman tics; the op erational and denotational preorders on terms coincide. W e elab o r a te the prog ramme ab ov e for a call-by -na me recursiv ely typed lam b da calculus and establish similar results : Approx imation Theorem and adequacy f o r the sequen tia l or parallel calculus and f ull a bstraction for t he para llel calculus only . Chapter 2 defines the syn tax and t he reduction relation of our calculus. T yp es are built up from the separated sum +, the cartesian separated pro duct × , the function space → , and recursion. E ve ry recursiv e t yp e denotes a p ossibly infinite t yp e tree. Recursiv e types with the same type t r ee ar e regarded as equiv alent. T erms are built up f r om v ariables, λ - abstraction, application, and constants for the t yp e constructors + and × . Among the constants is a parallel case op eration p case . The op erational seman tics is defined b y the one- step reduction → of a redex in an y con text. W e prov e that reduction is confluent. F o r the pro of w e use the confluence theorem of [M ¨ ul92] whic h sa ys roughly: The com bination of the lambda calculus with a confluen t, left- linear and not v ariable-applying alg ebraic term rewriting system is confluent. The subsequen t c hapters explore the semantics . W e use information systems to giv e the semantics of recursiv e types [L W91, Win93]. Chapter 3 in tro duces a sp e- cialized form of information systems that w e call prim e systems : Here the predicates of consistency and en tailmen t are giv en b y binar y relations on the set of primes (= tok ens). Prime systems w ere first introduced for differen t purp oses under the name ev en t structures in [NPW81] and shown to b e equiv alen t to prime algebraic coheren t partial orders. W e tra nsfer the results of [L W91] to our prime systems: The class o f prime systems is a complete partial o r der unde r the substructure relation ✂ . W e define 1 INTR ODUCTION 3 op erations on prime systems corresponding to our type constructors +, × , → and sho w that they are con tin uous. This enables us, in Chapter 4, to giv e a seman tic in terpretation of ty p e trees and recursiv e t yp es as prime systems. The in terpretation of finite prefixes of a t yp e tree giv es a ✂ -c hain of prime systems ; the in terpretation of the whole ty p e tree is the limit of this c hain. No t e that the primes at one lev el of the c hain are directly contained in the fo llowing lev els; there is no need for em b edding-pro jection pairs as in the inv erse limit solution of recursiv e domain equations. This is an adv an tage of the concrete represen tation o f domains b y info r ma t ion system s or prime systems. An yw a y , this concrete represen tation of domain elemen ts b y sets o f primes will b e needed to pro ve full abstraction. Chapter 4 a lso g iv es the semantic s function S o n t erms and prov es its soundness: R eduction do es not change the seman tics of terms. Chapter 5 prov es t he Appro ximation Theorem. W e define a prefix order ≺ on terms where the constant Ω is the least term. A normal form A is an ap pr oxima tion of a term M iff there is a reduct N of M suc h that A ≺ N ′ for a ll reducts N ′ of N . The set A ( M ) of appro ximations of M is a n ideal and can b e seen as the syn tactic v a lue or B¨ ohm tree of M . F or the parallel calculus, it is not p ossible to define approximations b y an analogue of head normal forms. But for t he sequen tial calculus (without p case ), w e giv e t w o analogues of head no rmal forms t o define alternative sets of a ppro ximations. The Appro ximation Theorem say s that the seman tics o f a term equals the limit of the seman tics o f its appro ximations. This is pr ov ed b y the inclusiv e predicate tec hnique, as it w as used in [MP87] to prov e the a nalogous theorem for the un ty p ed lam b da calculus. W e adapt the tec hnique to prime systems: W e giv e an inductiv e definition of the inclusiv e predic ates (logical relations) on the primes of our prime system in terpretation of t yp es. Chapter 6 prov es adequacy and full abstraction of the sem antics. W e hav e to define a notion of o bserv ation and the corresp onding op erationa l preorder on terms. W e c ho ose to observ e the v alues 0 and 1 of t yp e b o ol = void + vo id , where void is the type of just one b ottom elemen t. So our pr o gr ams are the closed terms of type b o ol . F or a program M w e define the op era t ional v alue O [ [ M ] ] as 0 o r 1 if M reduces t o 0 or 1 resp ectiv ely , and a s ⊥ otherwise. The Adequacy Theorem says that O [ [ M ] ] = S [ [ M ] ] ⊥ for ev ery progra m M ; it is a consequence of the Approximation Theorem. The op erational pre order on t erms is defined a s M ⊑ N iff for a ll con texts C [ ] suc h that C [ M ] and C [ N ] a r e pro g rams, O [ [ C [ M ]] ] ⊆ O [ [ C [ N ]] ] holds. Again w e hav e: If S [ [ M ] ] ⊆ S [ [ N ] ], then M ⊑ N , a s a consequence of adequacy . F ull a bstraction, M ⊑ N iff S [ [ M ] ] ⊆ S [ [ N ] ], is prov ed fo r the para llel calculus. As in [Plo77] the pro of is based on the Definability Lemma: F or all finite elemen ts d of a seman tic domain there is a term M with S [ [ M ] ] ⊥ = d . The pro of uses the represen tation of elemen ts as sets of primes. The last Chapter 7 prov es that the p case - function is definable from the parallel and function. 1 INTR ODUCTION 4 Related w ork Recen tly , [Win93 ] ga v e tw o r ecursiv ely typed λ - calculi with their denotatio na l seman- tics, b y information systems, and prov ed the a dequacy b y the inclusiv e predicate (log - ical relation) tech nique. The first calculus has an eager (call-by-v alue) op erational seman tics. The second one has lazy (call-by-name) op erational seman tics lik e ours, but a differen t notion of obse rv ation is chosen: F or ev ery t yp e certain terms are singled out as c anonic al forms . F or pro duct ty p es these are the terms ( M , N ), for sum types inl ( M ) and inr ( M ), and for function t yp es the terms λx.M . The observ ation that is made of terms is the con v ergence to a canonical form. The giv en denotational seman- tics is adequate with r esp ect to this notion o f observ ation. This means that a term con v erges to a canonical form iff its s emantics is not b o ttom. Especially , the seman tics of ev ery term λx.M is not b ottom, whereas w e hav e S [ [ λ x. Ω] ] ε = ⊥ . Finally some remarks on coalesced sums and the observ ation of termination f or all t yp es. W e did not include the coalesced sum in our t yp e system, only separated sums. The coalesced sum o f tw o domains is the disjoint union of the domains, with the tw o b ottom elemen t s iden tified. A coalesced sum w ould demand strict constructors inl : τ → τ ⊕ and inr : → τ ⊕ . These constructors hav e to ev aluat e their arguments to a non-b ottom v alue b efor e they can b e used b y a case -op eration. ( In con trast our corresp onding constructors 0 and 1 are non- strict; they can b e used without ev aluat ed argumen t.) But the detection of non-b ottom v alues is a complicated task for functional t yp es, wh en w e ass ume our denotational seman tics of f unctions. On the other side I see no use for coalesced sums of functional types. Therefore I think that coalesced sums should b e restricted to non-f unctional types, so that e.g. the recursiv e definition of the flat cp o of integers b ecomes p ossible. The ch ec k f or non-b ottomness of functional v alues, if it is desired, should b e pro grammed using sp ecial functions incorp orated in the language, e.g. Plotkin’s “exists” op erator . [Cos89] constructs ev aluators for a recursiv ely ty p ed lambda calculus with coalesced sums and strict, coalesced pro ducts of any type. The notion of observ ation f o r these ev aluators is the observ ation of termination for terms of all t yp es. The relation of op- erational and denota tional se mantics is given by the prop erty o f “complete adequacy ”: The semantic s of an y term is non-b o ttom iff its ev aluation terminates. This ensures the detection o f non- b ottomness for coalesced sums. The w ork succeeds with a tric k: The seman tic domains are lattices; top elemen ts (that are not syn tactically definable) are added t o the domains. Th us a term lik e λx. if x ( if x Ω 0 ) Ω, whose normal seman tics is ⊥ , no w b ecomes non-b ottom. F o r the no r ma l cp o seman tics only a v ague sk etc h of an ev aluator is giv en. There has b een la t er w ork pro ving a dequacy for a lazy functional language with recursiv e and p olymorphic ty p es, a lso using info r ma t io n systems [BC94 ]. 2 SYNT AX AND REDUCTION 5 2 Syn tax and reduction 2.1 T yp es W e adopt the syn tax of the rec ursiv e t yp e system of [CC90, CC91]. Esp ecially , recursiv e t yp es are considered equiv alen t if they hav e the same unfoldings as regular trees. But instead of type constan ts we hav e some more t yp e constructors b esides → . The typ e expr e ssions are giv en by the follo wing gr a mmar, where t stands for elemen ts of a den umerable set V T of t yp e v ariables: τ ::= t | τ + τ | τ × τ | τ → τ | µt.τ | void T µ is the set of all t yp e expressions. T c µ is the set of all closed t yp e expressions, called typ es . W e giv e t he info r ma l meaning of types in terms of domains: σ + τ is the separated sum o f σ a nd τ , σ × τ is the cartesian separated pro duct of σ and τ , σ → τ is the space of con tin uous functions from σ to τ , µt.τ is the fixed p oint of the mapping t 7→ τ , the solution of the recursiv e domain equation t = τ , void is the c anonical notation o f the undefined type; it has the same meaning as µt.t . In [CC90] it is called Ω. The corresp onding domain has just one elemen t ⊥ . W e define the simple typ es by the grammar: τ ::= void | τ + τ | τ × τ | τ → τ T is the set of all simple t yp es. It is T ⊆ T c µ . Definition 2.1 The void -prefix order ≺ ⊆ T × T c µ is the least partial order satisfying: 1) void ≺ τ for all τ ∈ T c µ , 2) σ ≺ σ ′ , τ ≺ τ ′ ⇒ σ @ τ ≺ σ ′ @ τ ′ for @ ∈ { + , × , →} , σ , τ ∈ T , and σ ′ , τ ′ ∈ T c µ . ≺ is a partial order on T . F or ev ery σ, τ ∈ T with an upp er b ound there is a least upp er b ound σ ⊔ τ ∈ T . T ∞ denotes the ideal completion of T , i.e. the set of ideals of simple types, o rdered b y ⊆ . Here ideals are sets I of simple ty p es that a r e non-empty , do wn w ard closed: τ ∈ I ∧ σ ≺ τ ⇒ σ ∈ I , and directed: fo r all σ , τ ∈ I there is ∈ I with σ ≺ and τ ≺ . The elemen ts of T ∞ are called typ e tr e es and are also denoted b y σ, τ , . W e define void ∈ T ∞ as vo id = { void } . F or @ = + , × , → and σ, τ ∈ T ∞ w e define σ @ τ = { void } ∪ { σ ′ @ τ ′ | σ ′ ∈ σ ∧ τ ′ ∈ τ } Ev ery t yp e tree of T ∞ has one of the forms v oid , σ + τ , σ × τ , σ → τ with unique σ , τ ∈ T ∞ . 2 SYNT AX AND REDUCTION 6 Definition 2.2 The unfolding ❀ ⊆ T c µ × T c µ is the least relatio n satisfying: 1) µt.τ ❀ τ [ µt.τ /t ] The righ t term is the replacemen t of µt.τ for all free o ccurrences of t in τ ; it is a lso closed. Note that µt.τ do es not contain free v ariables that could b e bound after the replacemen t. 2) τ ❀ τ ′ ⇒ ( τ @ σ ) ❀ ( τ ′ @ σ ) a nd ( σ @ τ ) ❀ ( σ @ τ ′ ) for @ ∈ { + , × , →} , τ , τ ′ , σ ∈ T c µ . ❀ reduces only one outermost redex µt.τ . The outermost redexes are disjoin t, therefore ❀ fulfills the diamond prop erty: If τ ❀ σ and τ ❀ , then there is ψ with σ ❀ ψ a nd ❀ ψ . ❀ ∗ is the reflexiv e, transitiv e closure of ❀ . It is confluen t: If τ ❀ ∗ σ and τ ❀ ∗ , then there is ψ with σ ❀ ∗ ψ and ❀ ∗ ψ . If σ ≺ τ and τ ❀ ∗ τ ′ , then also σ ≺ τ ′ , for all σ ∈ T and τ , τ ′ ∈ T c µ . F or ev ery τ ∈ T c µ w e define the unfolding τ ∗ = { σ ∈ T | ∃ τ ′ ∈ T c µ . τ ❀ ∗ τ ′ and σ ≺ τ ′ } Prop osition 2.3 τ ∗ ∈ T ∞ . Pro of: W e hav e to sho w that τ ∗ is an ideal. It is non-empt y , void ∈ τ ∗ , and do wn w ard closed. It is also directed: Let σ, ∈ τ ∗ . Then there is τ ′ with τ ❀ ∗ τ ′ , σ ≺ τ ′ and τ ′′ with τ ❀ ∗ τ ′′ , ≺ τ ′′ . As ❀ is confluen t, there is ψ with τ ′ ❀ ∗ ψ and τ ′′ ❀ ∗ ψ . It follo ws σ ≺ ψ and ≺ ψ , therefore σ ⊔ ≺ ψ a nd σ ⊔ ∈ τ ∗ . Definition 2.4 W e define an equiv alence relation ≈ on t yp es by : σ ≈ τ iff σ ∗ = τ ∗ . ≈ is decidable [AC90]. 2.2 T erms F or ev ery t yp e τ ∈ T c µ there is a den umerable set V τ of v aria bles of t yp e τ . The sets V τ are mutually disjoin t. Their mem b ers are denoted b y x τ , y τ , . . . There is a set C o f constan ts with ty p es ctyp e : C → T c µ . General unt yp ed t erms are built from v ar ia bles and constants b y application M N and ( λ - ) a bstraction λx.M , without regarding the t yp es. Λ is the set of all unt yp ed terms. W e giv e r ules for the formation of typed terms; M : σ means: M has type σ , σ ∈ T c µ : (const) c : ctyp e ( c ) for c ∈ C (v ar) x σ : σ ( → I) M : τ ⇒ λx σ .M : σ → τ 2 SYNT AX AND REDUCTION 7 ( → E) M : σ → τ , N : σ ⇒ M N : τ ( ≈ ) M : σ, σ ≈ τ ⇒ M : τ T erms are considered equal mo dulo α -con v ersion. W e abbreviate λx.λy .M a s λxy .M . Often type sup erscripts of v a riables will b e omitted. T is the set of all ty p ed terms. The t yp e of a ty p ed term is unique up to ≈ , so the inference rules could b e g iven for t yp e trees instead o f types. T σ is the set of all terms with type σ ∈ T c µ or with t yp e tree σ ∈ T ∞ . T c σ is the corresp onding set of all closed terms. In the follo wing c hapters terms will alw ay s b e understo o d to b e typed. F or ev ery type σ w e can define a fixed p oin t combin ato r: Y σ = λy σ → σ . ( λx µt. ( t → σ ) .y ( xx ))( λx µt. ( t → σ ) .y ( xx )) : ( σ → σ ) → σ Remark: W e ha ve g iven a type system with rule ( ≈ ) instead o f explicit conv er- sion op erators b etw een the t yp es µt.σ and σ [ µ t.σ /t ], called rep/abs, unfold/fold or elim/in tro in [Win93, Cos89, AC 90 , Gun92]. There are unt yp ed terms that can b e t yp ed in our system, but not in a system with explicit con v ersion, ev en with the in tro- duction of arbitrary rep/abs in the term. E.g. let M = Y ( λf x.f ) and N = Y ( λf xy .f ) in ( v M , v N ) . In this term, M and N must hav e the same type, whic h is imp ossible in an abs/rep-system. In our system the types of M : µt.σ → t and N : µt.σ → σ → t are equiv alen t. Moreo v er o ur type system with rule ( ≈ ) has principle type sc hemes. A system with the weak er congruence ∼ , as the smallest congruence (w.r.t. type con- structors) suc h that µt.σ ∼ σ [ µt.σ /t ], lack s t his prop ert y [CC90, CC91]. Our sp ecial set of constan ts consists of the follow ing sym b ols for all t yp es σ, τ , : 0 σ ,τ : σ → ( σ + τ ), also called “inleft” in the literature 1 σ ,τ : τ → ( σ + τ ), also called “inrigh t” case σ ,τ , : ( σ + τ ) → ( σ → ) → ( τ → ) → , sequen tial conditional p case σ ,τ , : ( σ + τ ) → → → , parallel conditional. Note the t yp e differen t from case ’s t yp e. pair σ ,τ : σ → τ → ( σ × τ ), pair x y is also written ( x, y ) fst σ ,τ : ( σ × τ ) → σ snd σ ,τ : ( σ × τ ) → τ Ω σ : σ , the canonical undefined term o f t yp e σ . Ω σ has the same denotational seman tics as Y σ ( λx σ .x ). There are no reduction rules for Ω. W e will frequen tly omit the type subscripts o f the constan ts. The term r ewriting system will t reat them as single sym b ols. Notice that w e do not in tro duce these op erators b y sp ecial term formatio n rules for the t yp es σ + τ and σ × τ , as it is often done, but as c onstants of higher order types that can b e applied by normal application. 0 , 1 , pair a re the constructors fo r building up the canonical t erms of t yp e σ + τ , σ × τ resp ectiv ely . case, p case, fst, snd are the correspo nding ev aluators. W e will usually write 0 instead of 0 Ω and 1 instead o f 1 Ω. 2 SYNT AX AND REDUCTION 8 W e could also include in our calculus separated sum types with a differen t n um b er of comp onen ts tha n tw o . A sp ecial case would b e the t yp e constructor lift with just one t yp e arg umen t. It adds a new b ott o m elem ent to the domain of the t yp e. The constan ts for t his t yp e constructor w ould b e ℓ σ : σ → ( lift σ ) and lcase σ ,τ : ( lif t σ ) → ( σ → τ ) → τ , corresp onding to 0 and case . W e omit this t yp e constructor a s it can b e treated analogously to +. Examples of common t yp es and their canonical terms: void ≈ µt.t has just one elemen t, denoted b y Ω void . b o ol = def void + v oid Ω 0 Ω 1 Ω bitstream = def µt.t + t Ω 0 Ω 1 Ω 0 ( 0 Ω) 0 ( 1 Ω) 1 ( 0 Ω) 1 ( 1 Ω) nat = def µt. void + t , the lazy na t ural num b ers: Ω 0 ∼ = 0 Ω 1 Ω succ 0 ∼ = 1 ( 0 Ω) 1 ( 1 Ω) succ(succ 0 ) ∼ = 1 ( 1 ( 0 Ω)) 1 ( 1 ( 1 Ω)) b o ollist = def µt. void + ( b o ol × t ) b o ollist is t he type of lists of elemen ts of b o o l , e.g. 0 void , b ool × b o ollist Ω void : b o ollist , simply written as 0 without type subscripts and un- defined term Ω , the empt y list, e.g. 1 void , bo ol × b oollist ( 1 void , void Ω void , 0 void , bo ol × b oollist Ω void ) : b o ollist , simply written as 1 ( 1 , 0 ), the list of one elemen t 1 . Note that “infinitely bra nc hing” domains, like the flat domain of natural n umbers of PCF, cannot b e defined in our t yp e system b ecause the t yp e constructor of coalesced sums is missing. 2.3 Reduction W e define a reduction relation → on terms. It p erforms a o ne-step reduction of a single redex in an y con text. It is the least relation satisfying: 2 SYNT AX AND REDUCTION 9 ( β ) the β -reduction rule: ( λx.M ) N → M [ x := N ] for any terms M , N a nd v ariable x , where M [ x := N ] is the substitution of N for the free o ccurrences of x in M , with appropriate renaming of b ound v ariables of M , three con text rules: (app) M → M ′ = ⇒ M N → M ′ N , N → N ′ = ⇒ M N → M N ′ , ( λ ) M → M ′ = ⇒ λx.M → λx.M ′ , and a set of applicativ e term rewriting rules for the constan ts, where the v ariables x, y , z , w denote arbitrary terms: ( case0 ) case ( 0 x ) y z → y x ( case1 ) case ( 1 x ) y z → z x ( pair 1) fst ( pair x y ) → x ( pair 2) snd ( pa ir x y ) → y ( p case0 ) p case ( 0 x ) y z → y ( p case1 ) p case ( 1 x ) y z → z ( p case00 ) p case σ ,τ , 0 + 1 x ( 0 y ) ( 0 z ) → 0 ( pcase σ ,τ , 0 x y z ) ( p case11 ) p case σ ,τ , 0 + 1 x ( 1 y ) ( 1 z ) → 1 ( pcase σ ,τ , 1 x y z ) ( p case × × ) p case σ ,τ , 1 × 2 x ( y 1 , y 2 ) ( z 1 , z 2 ) → ( pcase σ ,τ , 1 x y 1 z 1 , p case σ ,τ , 2 x y 2 z 2 ) ( p case → ) ( p case σ ,τ , 1 → 2 x y z ) w → p case σ ,τ , 2 x ( y w ) ( z w ) → ∗ is the r eflexiv e, transitiv e closure of → . Note the o rder of parameters of case : y is the 0 -part, z is the 1 -part. The function- alit y of case p ermits the definition of the usual ev aluat ors “outleft” and “outrigh t”, so that w e need not in tro duce them with reduction rules: out0 σ ,τ : ( σ + τ ) → σ out0 = def λx. case x ( λy .y ) Ω out1 σ ,τ : ( σ + τ ) → τ out1 = def λx. case x Ω ( λy .y ) p case is not a sequen tial function, as it forces its three arguments to b e reduced in pa rallel. As so on as the “b o olean v alue” of it s first argument app ears, a reduction with rule ( p case 0) or ( p case 1) can b e made. As so on a s the second and the third argumen t con ve y the same piece of information, namely a constructor 0 , 1 or pa ir , this piece of information can b e drawn out of the p case -expression according to rule ( p case00 ), ( p case11 ) o r ( p case ×× ). If the second and the third argumen t are o f func- tional type, then the argument w of the p case -expression can b e dra wn in according 2 SYNT AX AND REDUCTION 10 to rule ( p case → ), so that ( y w ) and ( z w ) can deliv er constructor inf o rmation b efore the ev aluatio n of x is finished. Note t ha t p case app ears on the rig h t sides of its rules ( p case00 )–( p case → ). It p erfo rms a recursion on the type tree of its second and third argumen t. W e could think o f a para llel conditional with the same type a s case . But for suc h a conditional it is more difficult to implemen t this recursion b y r ewrite rules; in f act w e w ould need conditioned rewrite rules with λ - abstractions and out0 , out1 in the righ t sides. Prop osition 2.5 O ur r e duction r elation → fulfil ls the subje ct r e duction pr op erty: If M : σ and M → ∗ N , then also N : σ . Pro of: The prop ert y can b e c hec k ed f or each reduction rule. Theorem 2.6 (Confluence) → is c onfluent (C h ur ch-R osser) on typ e d terms: F or an y typ e d term M ∈ T with N ← ∗ M → ∗ P ther e is a term Q with N → ∗ Q ← ∗ P . ( N , P , Q ar e als o typ e d with e quivalent typ es d ue to the subje ct r e duction pr op erty.) Note that the restriction of M to typed t erms is essen tial, as can b e seen with the term p case x ( 0 y ) ( 0 z ) w . This term is not typable , as ( 0 y ) is not of function type. It reduces to p case x ( 0 y w ) ( 0 z w ) by rule ( p case → ), and to 0 ( p ca se x y z ) w by rule ( p case00 ). This critical pa ir do es not conv erge to a common reduct. Pro of: W e will use the confluence theorem o f [M ¨ ul92]: F or eve ry left- linear, not v ariable-a pplying A T RS (applicativ e term rewriting system) with reduction relation → a nd ev ery → -closed set T of terms: If → is confluen t on the a pplicative terms of T then → is confluen t on T . W e explain the notions of this theorem in our con text: The applicativ e terms are the terms without an y λ -abstraction, i.e. they a re built only fro m v aria bles, constan ts and application. An A TRS is a set of pair s h L → R i of applicativ e terms, where L is no v ariable and all v ariables of R app ear in L , to o. In our case, the A TRS is the set o f reduction rules ( case0 ) . . . ( p case → ). T ogether with β -reduction and the context rules (app) and ( λ ) it determines t he r eduction relation → o n terms o f Λ. It is left- linear, i.e. ev ery v ariable has at most one o ccurrence in eac h left side o f the rules. It is not v ariable- a pplying, i.e. no left side of an y rule con tains a subterm of the f orm ( xM ), where x is a v ariable. In our case, T will b e the set T of t yp ed terms. T is → -closed, i.e. for ev ery M ∈ T the following hold: 1) M → M ′ ⇒ M ′ ∈ T , the sub ject reduction prop erty , 2) every subterm of M is in T , 3) for ev ery o ccurrence u of an abstraction in M , M /u = λ . . . , there is a v aria ble x not o ccurring in M with M [ u ← x ] ∈ T . W e use the same notations for o ccurrences of subterms and replacemen t at an o ccur- rence as [Hue80, M ¨ ul92]. In condition 3 we c hose a new v ariable of the appropriate t yp e. 2 SYNT AX AND REDUCTION 11 No w it remains to prov e the confluence of → on the set A of applicativ e terms of T , i.e. the confluence of the A TRS alone, without β -reduction. Our t heorem, the confluence of → on all t erms of T , follow s by the cited theorem. F rom no w on, → is the reduction relation on applicativ e terms of Λ. W e will first pro v e tha t → is lo cally confluent on A via conv erg ence of critical pairs, then pro v e that → is no etherian (terminating, strongly normalizing) and conclude the confluence of → on A b y Newman’s Lemma ( L emma 2.4 of [Hue80]). L o c a l (or we ak) c onfluenc e of → on a set T o f terms means: F o r a n y M ∈ T with N ← M → P there is a term Q with N → ∗ Q ← ∗ P . Notice that the sufficien t conditions for confluence in [Hue80] that c hec k only con- v ergence of critical pairs, without termination, are not applicable here: Huet’s Lemma 3.3 is almost applicable (Corollary: Any left-linear parallel closed term rewriting sys- tem is confluent), but it demands of the critical pair: y w ← ( p case ( 0 x ) y z ) w → p case ( 0 x ) ( y w ) ( z w ) that there should b e a parallel reduction step: y w → p case ( 0 x ) ( y w ) ( z w ). Note that the righ t term of a critical pair is defined b y a reduction at the r o ot . The lemma demands a parallel r eduction step from the left to the right term, not a n a r bitrary reduction. But in our example there is only a reduction in the opp osite direction. [T oy88, Corolla ry 3.2] gives a sufficien t condition more general than Huet’s Lemma 3.3; it is a lso not applicable here by the same reason. F or t he pro o f of lo cal confluence of → on A we will apply a generalized ve rsion of Lemma 3 .1 of [Hue80]: “F or an y term rewriting system R : The relation → R is lo cally confluen t iff f or ev ery critical pair ( P , Q ) of R w e hav e P ↓ Q , i.e. P and Q ha v e a common reduct.” This lemma cannot b e applied directly , as the non-typable, non-con v ergent critical pair giv en b efore this pro o f show s us. It should state lo cal confluence on certain subsets of terms whic h resem ble sets of w ell-t yp ed terms, similar to t he → -closed sets of terms ab ov e. This leads us to: Definition 2.7 A subset T of terms is called → R -c om plete for a term rewriting system with reduction relation → R if for ev ery M ∈ T the follo wing hold: 1) M → R M ′ ⇒ M ′ ∈ T , 2) ev ery subterm of M is in T , 3) for ev ery set of o ccurrences u 1 , . . . , u n of the same subterm N in M , i.e. M /u i = N for all i , there is a v ariable x not o ccurring in M with M [ u 1 ← x ] . . . [ u n ← x ] ∈ T . Let us recall the definition o f critical pairs of a term rewriting system. Definition 2.8 Let h S → T i , h L → R i b e tw o rules whose v ariables are renamed suc h that L and S hav e disjoin t v ariable sets. Let u b e an o ccurrence in L suc h that L/u is no v ariable a nd L/u and S are unifiable with substitution µ as the most general unifier. The sup erp osition of h S → T i on h L → R i in u determines the critic al p air ( P , Q ) defined b y P = ( µL )[ u ← µT ], Q = µR . It is P ← µL → Q . W e call µL a n overlap o f the critical pair ( P , Q ). 2 SYNT AX AND REDUCTION 12 Our generalization of Huet’s Lemma 3.1 is no w: Lemma 2.9 F or any term r ewriting system R and → R -c om plete subset T of terms: The r e duction r e l a tion → R is lo c al ly c onfluent on T iff for every c ritic al p air ( P , Q ) of R with an overlap i n T we have P ↓ Q . Pro of: (sk etc h) The pro of is es sen tially the pro of of Lemma 3.1 in [Hue80]. The “only if ” part is trivial again. F or the “ if ” part w e add the assumption M ∈ T . Case 1 (disjoin t redexes) a nd case 2 a (prefix redexes that do not ov erla p) are t he same a s in [Hue80]. Case 2b deals with ov erlapping redexes: An ov erlap of t he critical pair is obtained from the subterm M /u 1 b y replacing some subterms b y v aria bles. It is M / u 1 ∈ T according to condition 2 of → R -completeness. The replacemen t of subterms b y v ariables is p o ssible according to condition 3 of → R -completeness, so that the o v erlap is in T . Thus P ↓ Q b y h yp othesis, and the pro of pro ceeds as in [Hue80]. W e use t he lemma to sho w lo cal confluence of → on A . A is → -complete. Eigh t critical pairs with an o v erlap in A remain to b e chec ke d for con v ergence: ( 0 y ) ← p case ( 0 x ) ( 0 y ) ( 0 z ) → 0 ( pcase ( 0 x ) y z ) ( 1 y ) ← p case ( 0 x ) ( 1 y ) ( 1 z ) → 1 ( pcase ( 0 x ) y z ) ( 0 z ) ← p case ( 1 x ) ( 0 y ) ( 0 z ) → 0 ( p case ( 1 x ) y z ) ( 1 z ) ← p case ( 1 x ) ( 1 y ) ( 1 z ) → 1 ( p case ( 1 x ) y z ) ( y 1 , y 2 ) ← p case ( 0 x ) ( y 1 , y 2 ) ( z 1 , z 2 ) → ( p case ( 0 x ) y 1 z 1 , p case ( 0 x ) y 2 z 2 ) ( z 1 , z 2 ) ← p case ( 1 x ) ( y 1 , y 2 ) ( z 1 , z 2 ) → ( p case ( 1 x ) y 1 z 1 , p case ( 1 x ) y 2 z 2 ) y w ← p case ( 0 x ) y z w → p case ( 0 x ) ( y w ) ( z w ) z w ← pcase ( 1 x ) y z w → p case ( 1 x ) ( y w ) ( z w ) W e pro v e no w that → is no etherian on applic ative terms. (This will a lso b e used in the pro of of Lemma 5.3.) W e define a mapping ϕ from applicativ e terms t o { 2 , 3 , . . . } inductiv ely b y the follow ing equations: ϕM = 2 , if M is a v ariable or a constant ϕ ( 0 M ) = 2 · ϕM ϕ ( 1 M ) = 2 · ϕM ϕ ( p case M ) = 2 · ϕM ϕ ( p case M N ) = 2 · ϕM · ϕN ϕ ( p case M N P ) = 2 · ϕM · ϕN · ϕP ϕ ( pair M ) = 2 + ϕM ϕ ( pair M N ) = 2 + ϕM + ϕN ϕ ( M N ) = ( ϕM ) ϕN , for all other applications M N 3 PRIME SYSTEMS 13 By simple computations w e sho w fo r eve ry reduction rule h L → R i that ϕL > ϕ R , where v ariables of the rule stand for arbitra r y terms. The tw o in teresting rules are: ( p case × × ) p case x ( pair y 1 y 2 ) ( pair z 1 z 2 ) → pai r ( p case x y 1 z 1 ) ( pcase x y 2 z 2 ) ϕL = 2 · ϕx · (2 + ϕy 1 + ϕy 2 ) · (2 + ϕz 1 + ϕz 2 ) ϕR = 2 + 2 · ϕx · ϕy 1 · ϕz 1 + 2 · ϕx · ϕy 2 · ϕz 2 ( p case → ) ( p case x y z ) w → pcase x ( y w ) ( z w ) ϕL = 2 ϕw · ( ϕx ) ϕw · ( ϕy ) ϕw · ( ϕz ) ϕw ϕR = 2 · ϕx · ϕ ( y w ) · ϕ ( z w ) F or the last rule (and some o t her) w e need the fact that ( ϕM ) ϕN ≥ ϕ ( M N ) for all terms M , N , whic h we prov e b y a case analysis o ve r the term M . It remains to sho w that a reduction at an y p osition dec reases the ϕ -v alue of a term. W e prov e tha t ϕN > ϕN ′ ⇒ ϕ ( M N ) > ϕ ( M N ′ ) and that ϕM > ϕM ′ and M → M ′ ⇒ ϕ ( M N ) > ϕ ( M ′ N ) for all terms M , N , M ′ , N ′ b y a case analysis o v er M . W e hav e now prov ed that M → N ⇒ ϕM > ϕN . Th us there ar e no infinite reduction c hains. F rom this and the lo cal confluence of → on A follo ws b y Newman’s Lemma t he confluence of → on A . As explained ab o ve , the confluence of → on all t yp ed terms follows from the theorem of [M ¨ ul92]. 3 Prime systems W e in tro duce prime systems as concrete represen tations of domains, together with op erations on them corresp onding to the t yp e constructors + , × , → . The results of this c hapter are ta k en from [L W91 ] , where they w ere given f o r the more general information systems. Definition 3.1 A prime system A = ( A, ↑ , ≤ ) consists of a set A (the primes , denoted by a, b, c ), a reflexiv e and symmetric binary relation ↑ on A (the c onsistency ), and a partial order ≤ o n A (the entailment ), suc h that for all a, b, c ∈ A : If a ↑ b and c ≤ b , then a ↑ c . PSys is the class of a ll prime systems. Prime system s w ere first in tro duced in [NPW81] under the name “ev en t structures”, where the eleme nts of A w ere interpre ted as ev en ts of a computation pro cess. (Instead 3 PRIME SYSTEMS 14 of consistency there w as the dual conflict relation.) Here w e c hose a differen t name b ecause w e do not in terpret the elemen ts of A as ev en ts, but as pieces of info rmation, as in information systems . A prime is an elemen tary , indivisible piece of info r ma t ion ab out data ele ments . The relation a ≤ b means that whenev er b is v alid of an elemen t, then so is a . a ↑ b means that b oth primes a and b ma y b e v alid of an elemen t. Ev ery prime system determines an information system in the sens e of [L W91]: The set of toke ns is A . A finite subset X o f A is consisten t ( X ∈ Con) iff for all a, b ∈ X , a ↑ b . F or X ∈ Con and a ∈ A w e define X ⊢ a iff ∃ b ∈ X. a ≤ b . W e use t he simpler prime systems instead of infor mat ion systems as they are just suited for o ur data ty p es. Definition 3.2 The e lements of a prime system A = ( A, ↑ , ≤ ) are the subsets d ⊆ A that are dow nw ard closed: a ≤ b ∧ b ∈ d ⇒ a ∈ d , and consisten t: a ↑ b for all a, b ∈ d . |A| is the set of elemen ts of A . W e call |A| , ordered b y ⊆ , the domain of A . The least elemen t ∅ is also denoted by ⊥ . F or X ⊆ A w e write X ↓ = { a ∈ A | ∃ b ∈ X . a ≤ b } , also a ↓ fo r { a }↓ . The finite elements of A ar e defined a s the elemen ts of the form X ↓ for finite X ⊆ A . W e will give the characterization of the domains of prime systems from [NPW81]. First some domain theoretic definitions. Definition 3.3 Let ( D , ⊑ ) b e a par tial order. A subset of D is p airwise c onsistent iff an y t wo of its elem ents hav e an upp er bound in D . ( D , ⊑ ) is c oher ent iff ev ery pairwise consisten t subset of D has a lub. p ∈ D is a c omplete prime iff for eve ry S ⊆ D , if the lub F S exists and p ⊑ F S , then there is d ∈ S with p ⊑ d . ( D , ⊑ ) is prime algebr aic iff for e ve ry d ∈ D the set { p ⊑ d | p is a complete prime } has d a s its lub. Theorem 3.4 [NPW81] L et A = ( A, ↑ , ≤ ) b e a prime system. Then ( |A| , ⊆ ) is a prime alge b r aic c oher ent p artial or der. I ts c omplete primes ar e the elements a ↓ f o r a ∈ A . It fol lows that ( |A| , ⊆ ) is also an algebr aic cp o. Its iso l a te d (or fi nite, c o mp act) elements ar e the fin i te elements define d ab ove. Conversely, let ( D , ⊑ ) b e a prime algebr aic c oher ent p artial or der. L et P b e the set of c omplete primes of D , and a ↑ b iff a, b ∈ P have an upp er b ound. Th en P = ( P, ↑ , ⊑ ) is a prime system with ( |P | , ⊆ ) isomorphic to ( D , ⊑ ) . This theorem explains our name for “primes”. F rom this c haracterization w e only need the fact that the domain of a prime system is a cp o, i.e. has lubs of directed subsets. These lubs a re the set unions of the elemen ts. As in [L W91] w e define a complete partial order on the class of prime systems and con tin uous op erations on prime systems. 3 PRIME SYSTEMS 15 Definition 3.5 Let A = ( A, ↑ A , ≤ A ) and B = ( B , ↑ B , ≤ B ) b e prime systems. W e define A ✂ B iff A ⊆ B and for all a, b ∈ A : a ↑ A b ⇔ a ↑ B b and a ≤ A b ⇔ a ≤ B b . A ✂ B means that A is a subsystem o f B : A ⊆ B and ↑ A , ≤ A are the r estrictions of ↑ B , ≤ B on A . If A ✂ B and A = B , then A = B . Theorem 3.6 ✂ is a p artial or d er with ⊥ = ( ∅ , ∅ , ∅ ) as le as t element. If A 0 ✂ A 1 ✂ . . . is an ω -chain of prime systems A i = ( A i , ↑ i , ≤ i ) , then [ i A i = ( [ i A i , [ i ↑ i , [ i ≤ i ) is the lub of the chain . Pro of: Clearly ✂ is a partial order, ⊥ is the least elemen t. No w for the c hain A i let A = ( A, ↑ , ≤ ) = ( S i A i , S i ↑ i , S i ≤ i ) . A is a n upp er b ound of the c hain: A i ⊆ A for all i . Let a, b ∈ A i . If a ↑ i b , then a ↑ b . Con ve rsely , if a ↑ b , then a, b ∈ A j and a ↑ j b for some j . If j ≤ i , then A j ✂ A i ; if i ≤ j , then A i ✂ A j . In either case follo ws a ↑ i b . Analogously we sho w a ≤ i b ⇔ a ≤ b . A is the least upp er b ound of the c hain: Let B = ( B , ↑ B , ≤ B ) b e an upp er b ound of the c hain. Then A = S i A i ⊆ B . Let a, b ∈ A . Then a, b ∈ A i for some i . W e ha v e a ↑ b ⇔ a ↑ i b ⇔ a ↑ B b and a ≤ b ⇔ a ≤ i b ⇔ a ≤ B b . W e extend ✂ to n-tuples of prime systems . Definition 3.7 F or n ≥ 1, PSys n are all n-tuples ( A 1 , . . . , A n ) of prime systems. W e define ( A 1 , . . . , A n ) ✂ ( B 1 , . . . , B n ) ⇔ A 1 ✂ B 1 ∧ . . . ∧ A n ✂ B n . . Prop osition 3.8 ✂ is a p artial or der on PSys n with ( ⊥ , . . . , ⊥ ) as le ast ele ment. Al l incr e asing ω -chains in ( PSys n , ✂ ) hav e a le ast upp er b ound taken c o o r dinate-wise. Definition 3.9 Let F : PSys n → PSys b e an op eration on prime systems. F is called mono toni c iff A ✂ B ⇒ F ( A ) ✂ F ( B ) for all A , B ∈ P Sys n . F is called c ontinuous iff it is monotonic and for a ny ω - c hain of prime systems A 0 ✂ A 1 ✂ . . . in P Sys n , F ( S i A i ) = S i F ( A i ). (Since F is monotonic, F ( A i ) , i ≥ 0 , is an ascending c hain a nd S i F ( A i ) exists.) Prop osition 3.10 F : PSys n → PSys is monotoni c (c o n tinuous) iff it is monotonic (c on tinuous) in e ach ar gument sep ar a tely (i.e. c onsider e d a s a function i n any of its ar gumen ts, hold i n g the o thers fi xe d). 3 PRIME SYSTEMS 16 Th us to sho w tha t an op eratio n is monotonic or contin uous w e hav e to sho w that some unary op erations are monotonic o r contin uous. The following lemma will help in these pro ofs. Definition 3.11 F : PSys → PSys is c ontinuous on prime sets iff for any ω -c hain of prime systems A 0 ✂ A 1 ✂ . . . eac h prime of F ( S i A i ) is a prime of S i F ( A i ). Lemma 3.12 F : PSys → PSys is c ontinuous iff F i s monotonic an d c ontinuous on prime se ts. Pro of: The “only if ” part is obvious . “if ”: L et A 0 ✂ A 1 ✂ . . . b e an ω -c hain o f prime systems. F rom A i ✂ S i A i and mono- tonicit y follow s F ( A i ) ✂ F ( S i A i ). Then S i F ( A i ) ✂ F ( S i A i ). As F is contin uous on prime sets, the primes o f S i F ( A i ) are the same as those of F ( S i A i ). Therefore they are the same prime systems. Op erations on p r ime systems W e giv e con tin uous op erations o n prime systems corresp onding to our syn tactic ty p e constructors void , + , × , → . Corresp onding to vo id is the prime sy stem ⊥ = ( ∅ , ∅ , ∅ ). It has the o nly elemen t ∅ = ⊥ . Separated sum + Definition 3.13 Let A 0 = ( A 0 , ↑ 0 , ≤ 0 ) and A 1 = ( A 1 , ↑ 1 , ≤ 1 ) b e prime systems. De- fine A 0 + A 1 = ( B , ↑ , ≤ ) b y B = B 0 ∪ B 1 where B 0 = { 0 } ∪ ( { 0 } × A 0 ) and B 1 = { 1 } ∪ ( { 1 } × A 1 ) , a ↑ b ⇔ ( a, b ∈ B 0 and if a = (0 , a 0 ) , b = (0 , b 0 ) , then a 0 ↑ 0 b 0 ) or ( a, b ∈ B 1 and if a = (1 , a 1 ) , b = (1 , b 1 ) , then a 1 ↑ 1 b 1 ) , a ≤ b ⇔ a = 0 , b ∈ B 0 or a = 1 , b ∈ B 1 or a = (0 , a 0 ) , b = (0 , b 0 ) , a 0 ≤ 0 b 0 or a = (1 , a 1 ) , b = (1 , b 1 ) , a 1 ≤ 1 b 1 . Prop osition 3.14 A 0 + A 1 is a prime system. Its dom ain is |A 0 + A 1 | = {∅} ∪ {{ 0 } ∪ ( { 0 } × d ) | d ∈ | A 0 |} ∪ {{ 1 } ∪ ( { 1 } × d ) | d ∈ |A 1 |} . W e abbreviate the elemen t { 0 } as 0 and { 1 } as 1. Theorem 3.15 + is c ontinuous on ( P Sys , ✂ ) . Pro of: It is easy to show tha t + is con tinu ous in its first and second argumen t, using Lemma 3.12. 3 PRIME SYSTEMS 17 Pro duc t × Definition 3.16 Let A 0 = ( A 0 , ↑ 0 , ≤ 0 ) and A 1 = ( A 1 , ↑ 1 , ≤ 1 ) b e prime systems. De- fine A 0 × A 1 = ( B , ↑ , ≤ ) b y B = ( { 0 } × A 0 ) ∪ ( { 1 } × A 1 ) , a ↑ b ⇔ a = (0 , a 0 ) , b = (0 , b 0 ) , a 0 ↑ 0 b 0 or a = (1 , a 1 ) , b = (1 , b 1 ) , a 1 ↑ 1 b 1 or a = (0 , a 0 ) , b = (1 , b 1 ) or a = (1 , a 1 ) , b = (0 , b 0 ) , a ≤ b ⇔ a = (0 , a 0 ) , b = (0 , b 0 ) , a 0 ≤ 0 b 0 or a = (1 , a 1 ) , b = (1 , b 1 ) , a 1 ≤ 1 b 1 . Prop osition 3.17 A 0 × A 1 is a prime system. Its dom ain is |A 0 × A 1 | = { ( { 0 } × d ) ∪ ( { 1 } × e ) | d ∈ |A 0 | ∧ e ∈ |A 1 |} Theorem 3.18 × is c ontinuous on ( PSys , ✂ ) . Pro of: It is easy to sho w t hat × is con tinuous in its first and second argumen t, using Lemma 3.12. F unction sp ace → Definition 3.19 Let A = ( A, ↑ A , ≤ A ) a nd B = ( B , ↑ B , ≤ B ) b e prime systems. (W e lea v e out the indexes in the fo llowing.) W e define A → B = ( C , ↑ , ≤ ): C = A × B , where A is the set of all finite subsets of A that a r e pairwise consisten t and incomparable, A = { X ⊆ A | X finite and ∀ a, b ∈ X . a ↑ b ∧ ( a ≤ b ⇒ a = b ) } . Let ( X , a ) , ( Y , b ) ∈ C . ( X , a ) ↑ ( Y , b ) ⇔ ( X ↑ Y ⇒ a ↑ b ) , where X ↑ Y ⇔ ∀ a ∈ X, b ∈ Y . a ↑ b . ( X , a ) ≤ ( Y , b ) ⇔ Y ≤ X and a ≤ b, where Y ≤ X ⇔ Y ⊆ X ↓ , i.e. ∀ a ∈ Y . ∃ b ∈ X . a ≤ b . Prop osition 3.20 A → B is a prime system. 3 PRIME SYSTEMS 18 Pro of: ↑ is reflexiv e and symmetric. ≤ is reflexiv e. ≤ is a ntisymm etric: Let ( X , a ) ≤ ( Y , b ) and ( Y , b ) ≤ ( X, a ). W e show ( X , a ) = ( Y , b ). W e ha ve a ≤ b and b ≤ a , so a = b . F rom X ≤ Y a nd Y ≤ X w e conclude X ⊆ Y : Let x ∈ X . There is y ∈ Y with x ≤ y , and x ′ ∈ X with y ≤ x ′ . So x ≤ x ′ , and x = x ′ b y the condition on X . Hence x = y ∈ Y . Similarly w e conclude Y ⊆ X . ≤ is tr a nsitiv e: Let ( X , a ) ≤ ( Y , b ) ≤ ( Z, c ). W e show ( X , a ) ≤ ( Z, c ). W e ha ve a ≤ b ≤ c , so a ≤ c . F rom Z ≤ Y ≤ X w e conclude Z ≤ X : Let z ∈ Z . There is y ∈ Y with z ≤ y , and x ∈ X with y ≤ x . It remains to sho w: If ( X , a ) ↑ ( Y , b ) a nd ( Z , c ) ≤ ( Y , b ), then ( X , a ) ↑ ( Z, c ). Supp ose X ↑ Z . Then X ↑ Y : Let x ∈ X , y ∈ Y . Y ≤ Z , therefore ∃ z ∈ Z. y ≤ z . It is x ↑ z , hence x ↑ y . W e get a ↑ b and c ≤ b , therefore a ↑ c . The elemen ts of A → B corresp ond to the contin uous functions from domain |A| to | B | . Prop osition 3.21 L et r ∈ |A → B | . Then | r | : |A| → |B| give n by | r | ( d ) = { a | ∃ X ⊆ d. ( X, a ) ∈ r } for d ∈ |A| is a c o ntinuous function fr om the domain |A| to |B | . Pro of: W e show | r | ( d ) ∈ |B | . | r | ( d ) is consisten t: Let a, b ∈ | r | ( d ). There is X ⊆ d with ( X , a ) ∈ r and Y ⊆ d with ( Y , b ) ∈ r . As ( X , a ) ↑ ( Y , b ) and X ↑ Y , w e conclude a ↑ b . | r | ( d ) is down w ard closed: Let b ∈ | r | ( d ) and a ≤ b . There is Y ⊆ d with ( Y , b ) ∈ r . It is ( Y , a ) ≤ ( Y , b ), so ( Y , a ) ∈ r a nd a ∈ | r | ( d ). | r | is monotonic, ob viously . | r | is con tin uous: Let D b e a directed subset of |A| . [ d ∈ D | r | ( d ) = { a | ∃ d ∈ D . ∃ X ⊆ d. ( X , a ) ∈ r } = { a | ∃ X ⊆ [ D . ( X , a ) ∈ r } , b ecause the X are finite = | r | ( [ D ) F or cp os ( D , ⊆ ) and ( E , ⊆ ), let ([ D → E ] , ⊆ ) b e the cp o of contin uous functions from D to E , ordered p oint wise b y ⊆ . W e will also write f : D → E fo r f ∈ [ D → E ], 3 PRIME SYSTEMS 19 and f : D → E → F for f ∈ [ D → [ E → F ]]. F or f : D → E and d ∈ D w e will usually write f d instead of f ( d ), as in the syn tax of the lambda calculus. Here also application is asso ciated to the left, i.e. f d e = ( f d ) e . W e will frequen tly write r d instead of | r | ( d ). It is clear from the con text that the function b et w een domains is mean t. Prop osition 3.22 L et f : |A| → |B | b e monotoni c and A b e the set of prim e s of A . Then the prime set of f , Pr ( f ) = { ( X, a ) | X ∈ A ∧ a ∈ f ( X ↓ ) } , is an ele m ent of |A → B | . Pro of: Pr ( f ) is consisten t: Let ( X , a ) , ( Y , b ) ∈ Pr ( f ) and assume X ↑ Y . Then ( X ∪ Y ) ↓∈ |A| . As a ∈ f ( X ↓ ) and b ∈ f ( Y ↓ ), w e ha v e a, b ∈ f (( X ∪ Y ) ↓ ), b y monotonicit y of f . Therefore a ↑ b . Pr ( f ) is down ward closed: Let ( X , a ) and ( Y , b ) b e primes o f A → B , ( Y , b ) ∈ Pr ( f ) and ( X, a ) ≤ ( Y , b ). F rom Y ≤ X follows Y ↓⊆ X ↓ . Then b ∈ f ( X ↓ ), as b ∈ f ( Y ↓ ) and f is monoto nic. As a ≤ b , also a ∈ f ( X ↓ ) and ( X , a ) ∈ Pr ( f ). Theorem 3.23 F or al l prime systems A , B the map | . | : ( |A → B| , ⊆ ) → ([ |A| → |B| ] , ⊆ ) is an iso m orphism of cp os. The map Pr is its inverse. Ther efor e the c omplete prime s and isolate d elements of [ | A| → |B| ] ar e the ima g e s under | . | o f the c orr esp ondin g elements of | A → B | . Pro of: W e show that for all r ∈ |A → B | , Pr ( | r | ) = r : ( X , a ) ∈ Pr ( | r | ) ⇔ a ∈ | r | ( X ↓ ) ⇔ ∃ Y ⊆ X ↓ . ( Y , a ) ∈ r ⇔ ( X , a ) ∈ r , b ecause ( X , a ) ≤ ( Y , a ) and r is do wn w ard closed W e sho w that for all f ∈ [ |A| → |B | ], | Pr ( f ) | = f : Let A, B b e the set o f primes of A and B , resp. L et d ∈ |A| and a ∈ B . a ∈ | Pr ( f ) | ( d ) ⇔ ∃ X ⊆ d . X ∈ A ∧ ( X , a ) ∈ Pr ( f ) ⇔ ∃ X ⊆ d. X ∈ A ∧ a ∈ f ( X ↓ ) ⇔ a ∈ f ( d ) W e prov e the last equiv alence: ⇒ : X ↓⊆ d and f is monotonic. 3 PRIME SYSTEMS 20 ⇐ : Let D = { Y ↓ | Y finite and Y ⊆ d } . D is a directed set in |A| . S D = d . Since f is con tinuous , there is some finite Y with Y ⊆ d and a ∈ f ( Y ↓ ). Let X b e t he set of maximal primes of Y . W e get X ⊆ d , X ∈ A , Y ↓ = X ↓ and a ∈ f ( X ↓ ). So the map | . | is o ne-t o-one, Pr is its inv erse. It remains to show that | . | and Pr resp ect the partial order ⊆ : F or all r , s ∈ |A → B| : r ⊆ s ⇔ ∀ d ∈ |A| . | r | ( d ) ⊆ | s | ( d ) ⇒ is obvious . ⇐ : Let ( X , a ) ∈ r . Then a ∈ | r | ( X ↓ ). As a ∈ | s | ( X ↓ ), there is Y ⊆ X ↓ with ( Y , a ) ∈ s . As Y ≤ X , also ( X, a ) ∈ s . Theorem 3.24 → is c o ntinuous on ( P Sys , ✂ ) . Pro of: 1) → is monotonic in its first argumen t: Let A 0 = ( A 0 , ↑ 0 , ≤ 0 ) ✂ A ′ 0 = ( A ′ 0 , ↑ ′ 0 , ≤ ′ 0 ), A 1 = ( A 1 , ↑ 1 , ≤ 1 ) b e prime systems a nd A 0 → A 1 = ( B , ↑ , ≤ ), A ′ 0 → A 1 = ( B ′ , ↑ ′ , ≤ ′ ). W e ha ve to prov e: A 0 → A 1 ✂ A ′ 0 → A 1 . First w e sho w: B = A 0 × A 1 ⊆ A ′ 0 × A 1 = B ′ . Let X ∈ A 0 . F or all a, b ∈ X : a ↑ ′ 0 b and ( a ≤ ′ 0 b ⇒ a = b ). Therefore X ∈ A ′ 0 . No w let ( X , a ) , ( Y , b ) ∈ B . ( X , a ) ↑ ( Y , b ) ⇔ ( X ↑ 0 Y ⇒ a ↑ 1 b ) ⇔ ( X ↑ ′ 0 Y ⇒ a ↑ 1 b ) ⇔ ( X , a ) ↑ ′ ( Y , b ) ( X , a ) ≤ ( Y , b ) ⇔ Y ≤ 0 X and a ≤ 1 b ⇔ Y ≤ ′ 0 X and a ≤ 1 b ⇔ ( X , a ) ≤ ′ ( Y , b ) 2) → is con tin uous o n prime sets in its first arg umen t: Let A 0 ✂ A 1 ✂ . . . b e an ω - c hain o f prime systems with A i = ( A i , ↑ i , ≤ i ), and B b e a prime system. Let ( X , b ) b e a prime of ( S i A i ) → B . Then X ∈ S i A i . Since X is finite, X ⊆ A n for some n . F or all a, c ∈ X , a ↑ n c and ( a ≤ n c ⇒ a = c ), b ecause A n ✂ S i A i . So X ∈ A n and ( X , b ) is a prime of S i ( A i → B ). 3) → is monotonic in its second a r g umen t: Let A 0 = ( A 0 , ↑ 0 , ≤ 0 ), A 1 = ( A 1 , ↑ 1 , ≤ 1 ) ✂ A ′ 1 = ( A ′ 1 , ↑ ′ 1 , ≤ ′ 1 ) b e prime systems a nd A 0 → A 1 = ( B , ↑ , ≤ ), A 0 → A ′ 1 = ( B ′ , ↑ ′ , ≤ ′ ). W e ha v e to show : A 0 → A 1 ✂ A 0 → A ′ 1 . B = A 0 × A 1 ⊆ A 0 × A ′ 1 = B ′ . 4 DENOT A TIONAL SEMANTICS 21 No w let ( X , a ) , ( Y , b ) ∈ B . ( X , a ) ↑ ( Y , b ) ⇔ ( X ↑ 0 Y ⇒ a ↑ 1 b ) ⇔ ( X ↑ 0 Y ⇒ a ↑ ′ 1 b ) ⇔ ( X , a ) ↑ ′ ( Y , b ) ( X , a ) ≤ ( Y , b ) ⇔ Y ≤ 0 X and a ≤ 1 b ⇔ Y ≤ 0 X and a ≤ ′ 1 b ⇔ ( X , a ) ≤ ′ ( Y , b ) 4) → is con tin uous o n prime sets in its second argumen t: Let A 0 ✂ A 1 ✂ . . . be an ω -c hain of prime s ystems with A i = ( A i , ↑ i , ≤ i ), and B = ( B , ↑ , ≤ ) b e a prime system. The set of primes o f B → ( S i A i ) is B × ( S i A i ) = S i ( B × A i ), the set of primes of S i ( B → A i ). 4 Denotatio nal seman tics 4.1 Seman tics of t yp es W e giv e a seman tic inte rpretatio n o f the type trees of T ∞ as prime systems. So w e do not solv e recursiv e domain equations directly , but define the seman tics of a recursiv e t yp e τ ∈ T c µ b y the seman tics of its unfolding τ ∗ . Definition 4.1 The sequence of maps P n : T ∞ → PSys , n ≥ 0, is defined inductiv ely b y: P 0 ( σ ) = ⊥ for all σ ∈ T ∞ , P n +1 ( void ) = ⊥ , P n +1 ( σ @ τ ) = P n ( σ ) @ P n ( τ ) for @ ∈ { + , × , →} and σ , τ ∈ T ∞ . Define P i ( σ ) as the prime set of P i ( σ ). Prop osition 4.2 F o r al l σ ∈ T ∞ , n ≥ 0 : P n ( σ ) ✂ P n +1 ( σ ) . (This pr op osition dep ends o nly on the mo n otonicity of the op er ations + , × , → on prime systems.) Pro of: b y induction o n n. T r ivial f or n = 0. No w assume that for some n ≥ 0: ∀ σ ∈ T ∞ . P n ( σ ) ✂ P n +1 ( σ ). W e prov e P n +1 ( σ ) ✂ P n +2 ( σ ) for all cases of σ : P n +1 ( void ) = ⊥ ✂ P n +2 ( void ). P n +1 ( σ @ τ ) = P n ( σ ) @ P n ( τ ) ✂ P n +1 ( σ ) @ P n +1 ( τ ) = P n +2 ( σ @ τ ) for @ ∈ { + , × , →} . This p ermits to giv e the seman tics o f type tr ees: 4 DENOT A TIONAL SEMANTICS 22 Definition 4.3 Define the map P : T ∞ → PSys by P ( σ ) = S i P i ( σ ). P ( σ ) is the set of primes of P ( σ ). Prop osition 4.4 P ( void ) = ⊥ P ( σ @ τ ) = P ( σ ) @ P ( τ ) for @ ∈ { + , × , → } and σ , τ ∈ T ∞ (This pr op o s i tion dep ends on the c ontinuity of the op e r ations + , × , → on prime sys- tems.) Pro of: Clearly P ( void ) = ⊥ . P ( σ @ τ ) = [ i ( P i +1 ( σ @ τ )) = [ i ( P i ( σ ) @ P i ( τ )) = ( [ i P i ( σ )) @ ( [ i P i ( τ )) = P ( σ ) @ P ( τ ) . Definition 4.5 The domain for a t yp e tr ee σ ∈ T ∞ is D σ = | P ( σ ) | , the domain for a type σ ∈ T c µ is D σ = | P ( σ ∗ ) | . F or d ∈ D σ , σ ∈ T ∞ , we define the n -th pr oje ction of d as d | n = d ∩ P n ( σ ). Note that the primes of P ( σ ) are expressions o f finite size and therefore structural induction ma y b e applied to them. More precisely: F or a prime a ∈ P ( σ ) let level ( a ) b e the least i such that a ∈ P i ( σ ). If (0 , a ) ∈ P ( σ + τ ), then a ∈ P ( σ ) and level ( a ) < level (0 , a ). If (1 , a ) ∈ P ( σ + τ ), then a ∈ P ( τ ) and level ( a ) < level (1 , a ). The same holds f o r σ × τ instead of σ + τ . If ( X , a ) ∈ P ( σ → τ ), then for all x ∈ X : x ∈ P ( σ ) and level ( x ) < le vel ( X , a ), and a ∈ P ( τ ) and leve l ( a ) < l e vel ( X, a ). Therefore definitions and pro ofs for primes ma y b e given by induction on t heir parts with smaller lev el. 4.2 Seman tics of terms W e will define the seman tics f unction S for terms. As usual w e need environme nts: Let V = S τ ∈ T c µ V τ b e the set o f all term v ariables o f a n y t yp e. An envir onment is a function ε : V → S σ ∈ T c µ D σ suc h that ε ( x σ ) ∈ D σ for all x σ ∈ V . Env is the set of all en vironmen ts. It is a cp o under the p oin t wise o rder ⊆ . Its least elemen t is denoted by 4 DENOT A TIONAL SEMANTICS 23 ⊥ , ⊥ ( x ) = ⊥ for all x . F or any en vironmen t ε , ε [ x 7→ d ] is the en vironmen t ε ′ with ε ′ ( x ) = d and ε ′ ( y ) = ε ( y ) for y 6 = x . F or ev ery constant c we will give a contin uous function on domains. This function is then transformed by Pr into an elemen t of the prime system corresp onding to t he t yp e of c . W e need v ersions of Pr for functions with 2 and 3 argumen ts: Let f : |A| → ( |B | → |C | ) b e contin uous fo r prime sy stems A , B , C . Define Pr 2 ( f ) ∈ |A → ( B → C ) | b y Pr 2 ( f ) = Pr ( Pr ◦ f ), where ( f ◦ g ) x = f ( g ( x )). Note that Pr ◦ f is con tinuous since Pr is contin uous as an order isomorphism. It is ( Pr 2 ( f )) a b = | ( | Pr 2 ( f ) | a ) | b = f a b . Let f : |A| → ( |B | → ( |C | → |D | )) b e con tinuous for prime systems A , B , C , D . Define Pr 3 ( f ) ∈ |A → ( B → ( C → D )) | b y Pr 3 ( f ) = Pr ( Pr 2 ◦ f ) . No t e that Pr 2 ◦ f is con tin uous as Pr 2 is con tinuous . It is ( Pr 3 ( f )) a b c = | ( | ( | Pr 3 ( f ) | a ) | b ) | c = f a b c . Definition 4.6 W e define the seman tics function S : T → ( En v → S σ ∈ T c µ D σ ) b y structural induction on the term a r g umen t. W e write S [ [ M ] ] and S [ [ M ] ] ε , f or M ∈ T , ε ∈ Env . It is S [ [ M ] ] ∈ [ Env → D σ ] fo r M : σ , see the fo llo wing prop osition. S [ [ 0 σ ,τ ] ] ε = Pr (0) , with 0 : D σ → D σ + τ 0 d = { 0 } ∪ ( { 0 } × d ) S [ [ 1 σ ,τ ] ] ε = Pr (1) , with 1 : D τ → D σ + τ 1 d = { 1 } ∪ ( { 1 } × d ) S [ [ case σ ,τ ] ] ε = Pr 3 ( c as e ) , with c ase : D σ + τ → D σ → → D τ → → D c ase d f g = ⊥ , if d = ⊥ | f | e, if d = 0 e | g | e, if d = 1 e S [ [ p ca se σ ,τ , ] ] ε = Pr 3 ( p c ase ) , with p c ase : D σ + τ → D → D → D p c ase a b c = b ∩ c, if a = ⊥ b, if a = 0 a ′ c, if a = 1 a ′ S [ [ pa ir σ ,τ ] ] ε = Pr 2 ( p a i r ) , with p air : D σ → D τ → D σ × τ p air d e = ( { 0 } × d ) ∪ ( { 1 } × e ) S [ [ fst σ ,τ ] ] ε = Pr ( fst ) , with fst : D σ × τ → D σ fst ( p air d e ) = d S [ [ snd σ ,τ ] ] ε = Pr ( snd ) , with snd : D σ × τ → D τ snd ( p air d e ) = e 4 DENOT A TIONAL SEMANTICS 24 S [ [Ω σ ] ] ε = ⊥ S [ [ x ] ] ε = ε ( x ) S [ [ λx σ .M ] ] ε = Pr ( d ∈ D σ 7→ S [ [ M ] ]( ε [ x 7→ d ])) , where ( d ∈ D 7→ exp) denotes the function that ma ps each d ∈ D to exp S [ [ M N ] ] ε = |S [ [ M ] ] ε | ( S [ [ N ] ] ε ) Prop osition 4.7 F o r al l terms M : ψ , S [ [ M ] ] ∈ [ Env → D ψ ] . Pro of: b y structural induction on M . • Let M b e a constan t: It is easy to c hec k that the giv en f unction on domains is contin uous and that the seman tics of M is in the appropriate doma in. W e show this only for M = pcase σ ,τ : p c ase is monotonic (and con tinu ous) in its first a rgumen t, since b ∩ c ⊆ b and b ∩ c ⊆ c . p c ase is con tin uous in its second (third) argumen t: This is clear for the cases a = 0 a ′ and a = 1 a ′ . In the case a = ⊥ it follo ws fr o m t he contin uit y of ∩ . Now p c ase : D σ + τ → D → D → D is con tin uous, therefore S [ [ p ca se σ ,τ , ] ] ε = Pr 3 ( p c ase ) ∈ |P (( σ + τ ) ∗ ) → P ( ∗ ) → P ( ∗ ) → P ( ∗ ) | = D ( σ + τ ) → → → . If p case σ ,τ , : ψ , then ψ ≈ ( σ + τ ) → → , and S [ [ p case σ ,τ , ] ] ∈ [ Env → D ψ ]. • Let M = x σ : S [ [ x σ ] ] = ( ε 7→ ε ( x σ )) : Env → D σ is con tin uous. • Let M = λx σ .N : σ → τ : Then N : τ , and S [ [ N ] ] ∈ [ Env → D τ ] f o llo ws by induction h yp othesis. Let ε ∈ Env and f = ( d ∈ D σ 7→ S [ [ N ] ]( ε [ x 7→ d ])). f is con tinuous, b ecause ε [ x 7→ . ] and S [ [ N ] ] are con tin uous. So f ∈ [ D σ → D τ ], and S [ [ λx.N ] ] ε = Pr ( f ) ∈ | P ( σ ∗ ) → P ( τ ∗ ) | = D σ → τ . It remains to sho w that S [ [ λx.N ] ] is con tin uous. It is monotonic: Let ε , ε ′ ∈ Env and ε ⊆ ε ′ . Then S [ [ λx.N ] ] ε = Pr ( d ∈ D σ 7→ S [ [ N ] ]( ε [ x 7→ d ])) ⊆ Pr ( d ∈ D σ 7→ S [ [ N ] ]( ε ′ [ x 7→ d ])) , as S [ [ N ] ] and Pr are monotonic = S [ [ λx.N ] ] ε ′ Let E b e a directed set of en vironmen ts. S [ [ λx.N ] ]( [ ε ∈ E ε ) = Pr ( d ∈ D σ 7→ S [ [ N ] ](( [ ε ∈ E ε )[ x 7→ d ])) 4 DENOT A TIONAL SEMANTICS 25 = Pr ( d ∈ D σ 7→ S [ [ N ] ]( [ ε ∈ E ( ε [ x 7→ d ]))) = Pr ( d ∈ D σ 7→ [ ε ∈ E S [ [ N ] ]( ε [ x 7→ d ])) , as S [ [ N ] ] is con tinuous = [ ε ∈ E Pr ( d ∈ D σ 7→ S [ [ N ] ]( ε [ x 7→ d ])) , as Pr is con tinuous = [ ε ∈ E S [ [ λx.N ] ] ε • Let M = N P , N : σ → τ , P : σ : By induction h yp othesis we ha ve S [ [ N ] ] ∈ [ Env → D σ → τ ] and S [ [ P ] ] ∈ [ Env → D σ ]. Let ε ∈ Env . Then |S [ [ N ] ] ε | ∈ D σ → D τ and S [ [ P ] ] ε ∈ D σ , hence S [ [ N P ] ] ε ∈ D τ . S [ [ N P ] ] is contin uous b ecause S [ [ N ] ], S [ [ P ] ] a nd | . | are con tin uous. So we get S [ [ N P ] ] ∈ [ Env → D τ ]. 4.3 Soundness of the seman tics W e sho w that reduction do es not change the seman tics of terms. First w e pro ve the Substitution Lemma. Lemma 4.8 (Substitution L emma) S [ [ M [ x := N ]] ] ε = S [ [ M ] ]( ε [ x 7→ S [ [ N ] ] ε ]) , for al l app r opriately typ e d terms M , N , and al l ε ∈ Env. Pro of: b y induction o n the structure of M , see Lemma 2.12 of [G un92]. Theorem 4.9 (Soundness) I f M , N ∈ T and M → ∗ N , then S [ [ M ] ] = S [ [ N ] ] . Pro of: It is clear that t he seman tics o f a term is not c hanged by r eplacing a subterm b y a term with the same seman tics. W e hav e the prop erties: S [ [ M ] ] = S [ [ M ′ ] ] ⇒ S [ [ M N ] ] = S [ [ M ′ N ] ] S [ [ N ] ] = S [ [ N ′ ] ] ⇒ S [ [ M N ] ] = S [ [ M N ′ ] ] S [ [ M ] ] = S [ [ M ′ ] ] ⇒ S [ [ λx.M ] ] = S [ [ λx.M ′ ] ] So if S [ [ M ] ] = S [ [ M ′ ] ], then S [ [ C [ M ]] ] = S [ [ C [ M ′ ]] ] for an y con text C [ ]. It can b e easily c hec ke d that each reduction rule do es not c hange the semantics . F or the β -rule this follows from the Substitution Lemma. 5 APPR O XIMA TION THEOREM 26 5 Appro ximation Theorem F or ev ery term M w e will define a set A ( M ) of normal forms that approx imate the reducts of M . A ( M ) can b e seen as the syn tactic v a lue of M or the B¨ ohm tree of M . W e will prov e the Appro ximation Theorem: S [ [ M ] ] ε = S A ∈A ( M ) S [ [ A ] ] ε . Thus the seman tics of M is en tirely determined b y the normal fo rm a ppro ximations of M . There are three metho ds in the literature to pro v e the Approximation Theorem: [Ber79, Th. 3.1.12] prov es it for PCF and [W ad78] for the un ty p ed lam b da calculus, b oth with the aid of a lab elled λ -calculus. [MP87] pro ve s it for the un ty p ed λ -calculus b y t w o other metho ds: by a n in termediate seman tics and b y inclusiv e predicates. W e will giv e an inclus ive pred icate pro of, mo dified f o r the recurs ive ly t yp ed λ -calculus and prime systems. First w e use the constan t Ω to define the usual Ω-prefix partial order on terms: Definition 5.1 F or eve ry σ ∈ T ∞ , ≺ is t he least relation o n T σ satisfying: Ω ≺ M for ev ery M ∈ T σ , x ≺ x for ev ery v ariable or constan t x , M ≺ M ′ ⇒ λx.M ≺ λx.M ′ , M ≺ M ′ ∧ N ≺ N ′ ⇒ M N ≺ M ′ N ′ . If M , N ∈ T σ ha v e an upp er bound und er ≺ , then M ⊔ N is defined as their least upper b ound. It is clearly: M ≺ N ⇒ S [ [ M ] ] ⊆ S [ [ N ] ]. Definition 5.2 Let σ ∈ T ∞ . N σ is the set of normal form terms of T σ . Normal forms are denoted b y A, B , . . . . Let A ∈ N σ , M ∈ T σ . A is a dir e ct appr oximation of M , A ✁ M , iff ∀ N . ( M → ∗ N ⇒ A ≺ N ). A is an appr oximation of M , A ✁ − M , iff ∃ N . M → ∗ N and A ✁ N . A ( M ) denotes the set of approximations of M . W e abbreviate S [ [ M ] ] ε = S A ✁ − M S [ [ A ] ] ε . A direct appro ximation of M con v eys a fixed syn tactic inf o rmation ab out M : It is in normal fo r m a nd is part of all reducts of M . If A ✁ M and M → ∗ N , then A ✁ N . W e w an t to sho w that A ( M ) is an ideal. Therefore w e need the following lemma, which relies on the fact that a ll applicativ e terms ha ve a nor ma l form. Lemma 5.3 If A ✁ M and B ✁ M , then A ⊔ B exists and is a norma l form, an d A ⊔ B ✁ M . Pro of: A ⊔ B exists b ecause A ≺ M and B ≺ M . No w assume that A ⊔ B is not a normal form. Then t here is an o ccurrence u in A ⊔ B suc h that ( A ⊔ B ) /u is a redex. 5 APPR O XIMA TION THEOREM 27 First assume that it is a β -redex: ( A ⊔ B ) /u is of the form ( λx.N ) P . Then either A/u is of the form ( λx.N ′ ) P ′ , or B /u is of this fo rm. This con tradicts the assumption that A a nd B are no r ma l forms. No w assume that ( A ⊔ B ) /u is a redex of a constant, corresp onding to o ne of the rules ( case 0) – ( p case → ). Let L = M /u . Let u i , 1 ≤ i ≤ n , b e a sequence of all the outermost o ccurrences of λ -abstractions in L . Let x i , 1 ≤ i ≤ n , b e a sequence o f distinct v a riables that do not o ccur in L . (The type of x i should b e that of L/u i .) Let K = L [ u 1 ← x 1 , . . . , u n ← x n ]. K is a n applicativ e term, i.e. it do es no t con tain an y λ -abstraction. As → is strongly nor malizing (no etherian) on applicative terms, there is a normal form K ′ of K , K → ∗ K ′ . It is L = K [ x 1 :=( L/u 1 ) , . . . , x n :=( L/u n )], the result of the replacemen t of the x i b y L/u i . Let L ′ = K ′ [ x 1 :=( L/u 1 ) , . . . , x n :=( L/u n )]. Then L → ∗ L ′ . As K ′ is a normal fo r m and the L/u i are λ -abstractions, L ′ is not a redex of a constant. It is M → ∗ M [ u ← L ′ ], as L → ∗ L ′ . As A ✁ M a nd B ✁ M , w e hav e A ⊔ B ≺ M [ u ← L ′ ]. Therefore ( A ⊔ B ) /u ≺ L ′ . This con tradicts the f act that L ′ is not a redex of a constan t. So in ev ery case w e deduced a con tr adiction from the assu mption that A ⊔ B is not a normal form. Clearly A ⊔ B ✁ M . Theorem 5.4 A ( M ) is an ide al under ≺ , i. e . it is non-em p ty, downwa r d clo se d and dir e cte d. Pro of: W e hav e Ω ∈ A ( M ). A ( M ) is down ward closed: If A ✁ − M a nd B ≺ A , then B ✁ − M . A ( M ) is directed: Let A ✁ − M and A ′ ✁ − M . There is N with M → ∗ N ∧ A ✁ N , and N ′ with M → ∗ N ′ ∧ A ′ ✁ N ′ . By confluence there is a term P with N → ∗ P and N ′ → ∗ P . Then A ✁ P a nd A ′ ✁ P . By the preceding lemma, A ⊔ A ′ is a no rmal form and A ⊔ A ′ ✁ P . Hence A ⊔ A ′ ✁ − M . With this prop osition A ( M ) is an elemen t of the ideal completion of N σ (under ≺ ); it can b e seen as a B¨ ohm tree of M . Let us first discuss our definition of approx imation and compare it with differen t ap- proac hes in the literature: 1) The treatment of PCF in [Ber79] is differen t: The approxim atio ns are obtained by reducing only β - and Y -redexe s. The constan ts are treated like v ariables; redexes of rules fo r constan ts ar e not reduced. They are only in terpreted seman tically in the B¨ ohm tree. This approach is only p ossible b ecause the reduction of constan t redexes can b e p ostp oned after the reduction of β - and Y -redex es. In our case constan ts op erate on higher order t yp es a s w ell, therefore the reduction of constan t redexes is intert wined with β -reduction. 2) A ( M ) is not minimal: In many cases there is a prop er subset of A ( M ) with the same seman tics; e.g. for M = λx. Ω or M = Ω N the appro ximation Ω is sufficien t. A ( M ) 5 APPR O XIMA TION THEOREM 28 w as defined to give “all p o ssible” normal form information ab out M . The ques tions arise: In whic h sense is A ( M ) maximal? [My conjecture is: F or ev ery directed set S of minimum normal forms o f M (def. b elow ), if S has the same seman tics as A ( M ), then S ⊆ A ( M ).] Is a smaller set of appro ximations definable with the same seman tics, that giv es a substan tially stronger Approximation Theorem? In the presence of parallel op erations there is in g eneral no least approx imation w ith the same semantic s: Consider M = λx . p case x ( case x Ω ( λy . 1 )) 1 : b o ol → bo ol . S [ [ M ] ] ⊥ is the function that maps 1 7→ 1, 0 7→ ⊥ . Bo th λx. p case Ω ( case x Ω ( λy . 1 )) 1 and λ x. pcase x Ω 1 are minimal approx imations o f M with the same seman tics a s M . 3) In the presence of pcase it is not possible to defi ne the appro ximations b y an analogue of head no r ma l fo rms. W e will mak e this statemen t precise af ter the pro of of the Appro ximation Theorem. W e will also giv e analogues of head nor ma l forms for the sequen tia l calculus without p case . W e no w prov e t w o useful lemmas ab out appro ximations. Lemma 5.5 If M ↓ N , then A ( M ) = A ( N ) and S [ [ M ] ] ε = S [ [ N ] ] ε . Pro of: Let M → ∗ P ← ∗ N . Assume A ✁ − M . Then there is M ′ with M → ∗ M ′ and A ✁ M ′ . By confluence there is L with M ′ → ∗ L ← ∗ P . Then A ✁ L and A ✁ − N . This sho ws A ( M ) ⊆ A ( N ). Symmetrically A ( M ) ⊇ A ( N ). Lemma 5.6 L et cM 1 . . . M n b e a term w h er e c is a c onstant and ther e a r e no r e ducts M i → ∗ M ′ i , 1 ≤ i ≤ m ≤ n , with cM ′ 1 . . . M ′ m a r e dex. Then S [ [ cM 1 . . . M n ] ] ε = ( S [ [ c ] ] ⊥ ) ( S [ [ M 1 ] ] ε ) . . . ( S [ [ M n ] ] ε ) . Pro of: S [ [ cM 1 . . . M n ] ] ε = [ {S [ [ A ] ] ε | A ✁ − cM 1 . . . M n } = [ {S [ [ cA 1 . . . A n ] ] ε | A 1 ✁ − M 1 ∧ . . . ∧ A n ✁ − M n } = ( S [ [ c ] ] ⊥ ) ( S [ [ M 1 ] ] ε ) . . . ( S [ [ M n ] ] ε ) W e ha v e used the fa ct that A ✁ − cM 1 . . . M n iff A = cA 1 . . . A n with some A i ✁ − M i ; as no cM 1 . . . M m , m ≤ n , can b e reduced to a redex. Theorem 5.7 (Approxima tion Theorem) F or al l terms M and envir onments ε : S [ [ M ] ] ε = S [ [ M ] ] ε. 5 APPR O XIMA TION THEOREM 29 S [ [ M ] ] ε ⊆ S [ [ M ] ] ε follows from S [ [ A ] ] ε ⊆ S [ [ M ] ] ε for A ✁ − M . This is a consequence of soundnes s and of monotonict y of S w.r.t. ≺ . W e wan t to pro v e the remaining inclusion S [ [ M ] ] ε ⊆ S [ [ M ] ] ε b y structural induction on M . Therefore w e use inclusiv e predicates (logical relatio ns), also used in [MP87] to prov e the analogous theorem (limiting completeness) for the un typed λ - calculus. W e define the inclusiv e predicates on the sets of primes P ( σ ) of the t yp e interpretations P ( σ ): Definition 5.8 F or ev ery σ ∈ T ∞ and ε ∈ Env w e define a relatio n < σ ε ⊆ P ( σ ) × T σ . a < σ ε M is defined b y structural induction on a , i.e. in terms of prop ositions a ′ < τ ε M ′ , where a ′ is a part of a with smaller lev el. There are the follow ing cases for σ and the primes: σ = τ + : 0 < τ + ε M ⇔ 0 ∈ S [ [ M ] ] ε (0 , a ) < τ + ε M ⇔ (0 , a ) ∈ S [ [ M ] ] ε and a < τ ε Out0 ( M ) 1 < τ + ε M ⇔ 1 ∈ S [ [ M ] ] ε (1 , a ) < τ + ε M ⇔ (1 , a ) ∈ S [ [ M ] ] ε and a < ε Out1 ( M ) where Out0 ( M ) abbreviates the term case M ( λ y .y ) Ω, and Out1 ( M ) the term case M Ω ( λy .y ). σ = τ × : (0 , a ) < τ × ε M ⇔ (0 , a ) ∈ S [ [ M ] ] ε and a < τ ε fst M (1 , a ) < τ × ε M ⇔ (1 , a ) ∈ S [ [ M ] ] ε and a < ε snd M σ = τ → : ( X , a ) < τ → ε M ⇔ ( X, a ) ∈ S [ [ M ] ] ε and ∀ N ∈ T τ . ( X < τ ε N ⇒ a < ε M N ) F or ev ery set X of primes X < τ ε N means: ∀ b ∈ X. b < τ ε N . In tuitiv ely a < σ ε M means tha t a ∈ S [ [ M ] ] ε and tha t the relation is main tained in all con texts formed by Out0 , Out1 , fst , snd and application on related argumen ts. W e ha ve to prov e a few lemmas f o r the Approx imation Theorem. Lemma 5.9 If a ≤ b an d b < σ ε M , then also a < σ ε M . Pro of: b y structural induction on b . In ev ery case w e ha v e a ∈ S [ [ M ] ] ε . • σ = τ + : The case a = 0, b = (0 , b ′ ) is clear. No w let a = (0 , a ′ ), b = (0 , b ′ ). Then a ′ ≤ b ′ and b ′ < τ ε Out0 ( M ) . By induction h yp othesis follows a ′ < τ ε Out0 ( M ). The cases a = 1 , b = (1 , b ′ ) and a = (1 , a ′ ) , b = (1 , b ′ ) are analogous. • σ = τ × is like σ = τ + 5 APPR O XIMA TION THEOREM 30 • σ = τ → : Let a = ( X, a ′ ), b = ( Y , b ′ ). It is Y ≤ X and a ′ ≤ b ′ . F or all N ∈ T τ the follo wing implications hold: X < τ ε N ⇒ Y < τ ε N , b y induction hypothesis ⇒ b ′ < ε M N , as ( Y , b ′ ) < σ ε M ⇒ a ′ < ε M N , b y induction h yp othesis Therefore a = ( X, a ′ ) < σ ε M . Lemma 5.10 If a < σ ε M and M ↓ N , then a l s o a < σ ε N . Pro of: b y structural induction on a . W e ha ve S [ [ M ] ] ε = S [ [ N ] ] ε b y L emma 5.5 , therefore a ∈ S [ [ N ] ] ε . • σ = τ + : Let a = (0 , a ′ ). Then a ′ < τ ε Out0 ( M ). By induction hypothesis follow s a ′ < τ ε Out0 ( N ), so a < σ ε N . a = (1 , a ′ ) is analo g ous. • σ = τ × is like σ = τ + . • σ = τ → : Let a = ( X, a ′ ). F or a ll P ∈ T τ : X < τ ε P ⇒ a ′ < ε M P , as a < σ ε M ⇒ a ′ < ε N P , b y induction hy p., as M P ↓ N P Therefore a < σ ε N . W e also need the new notion of passiv e term: Definition 5.11 A term M is a r e dex p art iff M = λx.N fo r some x and N , or there is some t yp ed left- hand side L of a rule ( case0 ). . . ( p case → ) and a subte rm L ′ of L su ch that L ′ 6 = L , L ′ is no v ariable and M is obtained fr o m L ′ b y replacing v ariables b y terms of the same type. This means: M is a redex part iff M is of one of the followin g f o rms: λx.N , 0 , 0 N , 1 , 1 N , pair , pair N 1 , pa ir N 1 N 2 , fst , snd , case , case ( 0 N ) , case ( 0 N 1 ) N 2 , case ( 1 N ) , case ( 1 N 1 ) N 2 , p case , p case N 1 , p case N 1 ( 0 N 2 ) , p case N 1 ( 1 N 2 ) , p case N 1 ( N 2 , N 3 ) , p case N 1 N 2 with N 2 : τ → , p case N 1 N 2 N 3 with N 2 , N 3 : τ → . (Note the t yp e restrictions of the last t w o forms: They are part s of the left-hand side of rule ( p case → ).) A term M is called p assive iff there is no redex part N with M → ∗ N . 5 APPR O XIMA TION THEOREM 31 No reduct of a passiv e term is able to interact with a con text in the reduction of a redex. Simple examples of passiv e terms ar e the v ar ia bles. The f o llo wing tw o lemmas state the needed pr o p erties of pa ssiv e terms. Lemma 5.12 1) If M is p assive and M N → ∗ P , then P = M ′ N ′ with M → ∗ M ′ and N → ∗ N ′ . 2) If M is p assive, then M N is also p assive for al l N . 3) If M is p assive, then S [ [ M N ] ] ε = |S [ [ M ] ] ε | ( S [ [ N ] ] ε ) for al l N . Pro of: 1) The pro of is b y induction on the length n of the reduction M N → ∗ P . It is clear for n = 0 . Induction step: Let M N → ∗ P → Q b e a reduction of length n + 1. By induction h yp othesis P = M ′ N ′ with M → ∗ M ′ and N → ∗ N ′ . M ′ is no redex part. Therefore either Q = M ′′ N ′ with M ′ → M ′′ or Q = M ′ N ′′ with N ′ → N ′′ . 2) Let M N → ∗ P . By part 1) w e hav e P = M ′ N ′ with M → ∗ M ′ . As M ′ is not a redex part, P is not a redex part either. (There is no rule with a v ariable-applying left-hand side xM 1 . . . M n .) 3) F or all A we ha v e: A ✁ − M N ⇔ ∃ P . M N → ∗ P ∧ A ✁ P ⇔ ∃ M ′ , N ′ . M → ∗ M ′ ∧ N → ∗ N ′ ∧ A ✁ M ′ N ′ , ⇒ b y part 1) ⇔ ∃ M ′ , N ′ , B , C . M → ∗ M ′ ∧ N → ∗ N ′ ∧ A = B C ∧ B ✁ M ′ ∧ C ✁ N ′ , ⇐ b y pa rt 1), a s M ′ is passiv e ⇔ ∃ B , C . A = B C ∧ B ✁ − M ∧ C ✁ − N . F rom the direction ⇒ follo ws: S [ [ M N ] ] ε ⊆ |S [ [ M ] ] ε | ( S [ [ N ] ] ε ). The direction ⇐ giv es: |S [ [ M ] ] ε | ( S [ [ N ] ] ε ) = | [ B ✁ − M S [ [ B ] ] ε | ( [ C ✁ − N S [ [ C ] ] ε ) = [ B ✁ − M [ C ✁ − N S [ [ B C ] ] ε, b y con tinuit y ⊆ S [ [ M N ] ] ε, from ⇐ . Lemma 5.13 If M ∈ T σ is p a s s ive and a ∈ S [ [ M ] ] ε , then a < σ ε M . Pro of: b y structural induction on a . • σ = τ + : The lemma is clear f or a = 0 and a = 1. 5 APPR O XIMA TION THEOREM 32 No w let a = (0 , a ′ ). As M is passiv e, M will not reduce to t he form 0 M ′ or 1 M ′ . Therefore Out0 ( M ) = case M ( λy .y ) Ω is passiv e, to o. a ′ ∈ case ( S [ [ M ] ] ε ) ( S [ [ λy .y ] ] ε ) ( S [ [Ω] ] ε ) , as a ∈ S [ [ M ] ] ε = S [ [ case M ( λy .y ) Ω] ] ε , b y Lemma 5.6 = S [ [ Out0 ( M )] ] ε . By the induction h yp othesis w e get a ′ < τ ε Out0 ( M ). The case a = (1 , a ′ ) is analo g ous. • σ = τ × is like σ = τ + . • σ = τ → : Let a = ( X, a ′ ). Let N ∈ T τ and X < τ ε N . Then M N is passiv e b y Lemma 5.1 2, 2). ( X , a ′ ) ∈ S [ [ M ] ] ε and X ⊆ S [ [ N ] ] ε imply a ′ ∈ | S [ [ M ] ] ε | ( S [ [ N ] ] ε ) = S [ [ M N ] ] ε, b y Lemma 5.12, 3) . By induction h yp othesis we get a ′ < ε M N . Th us w e hav e sho wn a < σ ε M . W e need a sp ecial lemma for p case giving its prop erties with resp ect to the inclusiv e predicates. It m ust b e prov ed by induction on primes. Note that suc h a lemma is not necessary for the other constan ts. Lemma 5.14 1) If 0 ∈ S [ [ M 0 ] ] ε and a < σ ε M 1 , then a < σ ε p case M 0 M 1 M 2 . 2) If 1 ∈ S [ [ M 0 ] ] ε and a < σ ε M 2 , then a < σ ε p case M 0 M 1 M 2 . 3) If a < σ ε M 1 and a < σ ε M 2 , then a < σ ε p case M 0 M 1 M 2 . Pro of: W e abbreviate M = p case M 0 M 1 M 2 . 1) The pro of is b y structural induction on a . If M 0 → ∗ 0 M ′ 0 for some M ′ 0 , then M → ∗ M 1 , and a < σ ε M follo ws from Lemma 5.10. W e assume in the follo wing that not M 0 → ∗ 0 M ′ 0 . (Also M 0 → ∗ 1 M ′ 0 is not p ossible b ecause of 0 ∈ S [ [ M 0 ] ] ε .) W e giv e a case analysis on a : • σ = τ + : Let a = (0 , a ′ ) : a) W e assume M 1 → ∗ 0 M ′ 1 and M 2 → ∗ 0 M ′ 2 for some M ′ 1 , M ′ 2 . Then M → ∗ 0 ( p case M 0 M ′ 1 M ′ 2 ). (0 , a ′ ) < σ ε M 1 implies a ′ < τ ε Out0 ( M 1 ). 5 APPR O XIMA TION THEOREM 33 F rom Lemma 5.10 and Out0 ( M 1 ) → ∗ M ′ 1 follo ws a ′ < τ ε M ′ 1 . The induction h yp othesis giv es a ′ < τ ε p case M 0 M ′ 1 M ′ 2 . Therefore a ′ ∈ S [ [ p ca se M 0 M ′ 1 M ′ 2 ] ] ε and (0 , a ′ ) ∈ 0 ( S [ [ p case M 0 M ′ 1 M ′ 2 ] ] ε ) = S [ [ 0 ( p case M 0 M ′ 1 M ′ 2 )] ] ε, by Lemma 5.6 = S [ [ M ] ] ε, b y Lemma 5.5 . F urthermore a ′ < τ ε Out0 ( M ) , as Out0 ( M ) → ∗ p case M 0 M ′ 1 M ′ 2 , b y Lemma 5.10. b) W e assume that not ( M 1 → ∗ 0 M ′ 1 and M 2 → ∗ 0 M ′ 2 ) for an y M ′ 1 , M ′ 2 . T o gether with the ass umption ( no t M 0 → ∗ 0 M ′ 0 ) there is no reduct o f M that is a redex. Then a ∈ p c ase ( S [ [ M 0 ] ] ε ) ( S [ [ M 1 ] ] ε ) ( S [ [ M 2 ] ] ε ) = S [ [ M ] ] ε, b y Lemma 5.6 . M is passiv e (note that M 1 , M 2 are not of functional type). By Lemma 5.13 w e get a < σ ε M . The case a = 0 is con tained in the pro o f for a = (0 , a ′ ), and the cases a = 1, a = (1 , a ′ ) are a nalogous. • σ = τ × is lik e σ = τ + . • σ = τ → : Let a = ( X , a ′ ). With the assumption (not M 0 → ∗ 0 M ′ 0 ) there is no reduct o f M that is a redex. Then a ∈ p c ase ( S [ [ M 0 ] ] ε ) ( S [ [ M 1 ] ] ε ) ( S [ [ M 2 ] ] ε ) = S [ [ M ] ] ε, b y Lemma 5.6 . It remains t o show : ∀ N ∈ T τ . ( X < τ ε N ⇒ a ′ < ε M N ). It is M N = p case M 0 M 1 M 2 N → pcase M 0 ( M 1 N )( M 2 N ). W e get: X < τ ε N ⇒ a ′ < ε M 1 N , as ( X , a ′ ) < σ ε M 1 ⇒ a ′ < ε p case M 0 ( M 1 N )( M 2 N ) , b y induction hy p othesis ⇒ a ′ < ε M N , b y Lemma 5.10. This concludes part 1) of the lemma. 2) P art 2) is analo gous to part 1). 3) The pro of is b y structural induction on a . If M 0 → ∗ 0 M ′ 0 for some M ′ 0 , then M → ∗ M 1 , and a < σ ε M follo ws from Lemma 5.10. If M 0 → ∗ 1 M ′ 0 for some M ′ 0 , then M → ∗ M 2 , and a g ain a < σ ε M . W e assume in the f ollo wing that neither M 0 → ∗ 0 M ′ 0 nor M 0 → ∗ 1 M ′ 0 . W e give a case ana lysis on a : • σ = τ + : Let a = (0 , a ′ ). 5 APPR O XIMA TION THEOREM 34 a) W e assume M 1 → ∗ 0 M ′ 1 and M 2 → ∗ 0 M ′ 2 for some M ′ 1 , M ′ 2 . Then M → ∗ 0 ( p case M 0 M ′ 1 M ′ 2 ). F rom a < σ ε M 1 , a < σ ε M 2 w e conclude by Lemma 5.10 that a ′ < τ ε M ′ 1 and a ′ < τ ε M ′ 2 . By induction hypothesis a ′ < τ ε p case M 0 M ′ 1 M ′ 2 . As in part 1) we conclude a < σ ε M . b) W e assume that not ( M 1 → ∗ 0 M ′ 1 and M 2 → ∗ 0 M ′ 2 ) for an y M ′ 1 , M ′ 2 . As in pa rt 1) w e conclude a < σ ε M . The case a = 0 is con tained in the pro o f for a = (0 , a ′ ), and the cases a = 1, a = (1 , a ′ ) are a nalogous. • σ = τ × is lik e σ = τ + . • σ = τ → : The ar g umen tation is just the same as in par t 1), except tha t w e conclude: X < τ ε N ⇒ a ′ < ε M 1 N and a ′ < ε M 2 N . In the fo llowing lemma w e collect all the prop erties of the re latio ns < σ ε on elem ents of D σ that we need in the pro of of the Appro ximation Theorem. Lemma 5.15 (Inclusive Predicate Lemma) I n the fol lowing d is an element of D σ , D τ , or D , and M , N ∈ T σ . 1) ⊥ < σ ε M . 2) σ = τ + : 0 d < τ + ε M ⇔ 0 d ⊆ S [ [ M ] ] ε and d < τ ε Out0 ( M ) 1 d < τ + ε M ⇔ 1 d ⊆ S [ [ M ] ] ε and d < ε Out1 ( M ) 3) σ = τ × : d < τ × ε M ⇔ d ⊆ S [ [ M ] ] ε a n d fst d < τ ε fst M and s n d d < ε snd M 4) σ = τ → : d < τ → ε M ⇔ d ⊆ S [ [ M ] ] ε a n d ∀ e ∈ D τ , N ∈ T τ . ( e < τ ε N ⇒ | d | e < ε M N ) 5) L et n ≥ 0 and c b e a c onstant of typ e σ = τ 1 → . . . → τ n → , such that ther e is no r e duction rule for c w ith less than n ar guments. T hen S [ [ c ] ] ⊥ < σ ε c iff d i < τ i ε M i for 1 ≤ i ≤ n ⇒ ( S [ [ c ] ] ⊥ ) d 1 . . . d n < ε cM 1 . . . M n . 6) If d < σ ε M and M ↓ N , then also d < σ ε N . 7) If M ∈ T σ is p a s s ive and d ⊆ S [ [ M ] ] ε , then d < σ ε M . 8) If 0 ∈ S [ [ M 0 ] ] ε and d < σ ε M 1 , then d < σ ε p case M 0 M 1 M 2 . 9) If 1 ∈ S [ [ M 0 ] ] ε and d < σ ε M 2 , then d < σ ε p case M 0 M 1 M 2 . 5 APPR O XIMA TION THEOREM 35 10) If d 1 < σ ε M 1 and d 2 < σ ε M 2 , then d 1 ∩ d 2 < σ ε p case M 0 M 1 M 2 . Note: The parts 6) and 7) of this lemma r eplace the Lemma 5 of the pro of of the Appro ximation Theorem for the un typed λ -calculus in [MP87]. A condition for the recursiv ely t yp ed λ -calculus corresp onding to that of Lemma 5 would b e t o o compli- cated. Pro of: 1), 2), and 3) are simple consequenc es of the definition o f < σ ε . 4) ⇒ : d ⊆ S [ [ M ] ] ε is clear. No w let e ∈ D τ , N ∈ T τ and e < τ ε N . Let a ∈ | d | e . Then there is X ⊆ e with ( X , a ) ∈ d . F rom ( X , a ) < τ → ε M and X < τ ε N follows a < ε M N . ⇐ : Let ( X , a ) ∈ d . W e sho w: ∀ N . X < τ ε N ⇒ a < ε M N . Let e = X ↓ . By Lemma 5.9 we get e < τ ε N . Then a ∈ | d | e < ε M N . 5) The pro of is b y induction on n . Note that may b e a functional type that v aries with n . n = 0 is clear. No w assume the prop osition for c is true for some n ≥ 0; w e prov e it f o r n + 1: S [ [ c ] ] ⊥ < σ ε c iff d i < τ i ε M i for 1 ≤ i ≤ n ⇒ ( S [ [ c ] ] ⊥ ) d 1 . . . d n < τ n +1 → ε cM 1 . . . M n , b y induction hy p othesis iff d i < τ i ε M i for 1 ≤ i ≤ n ⇒ ( S [ [ c ] ] ⊥ ) d 1 . . . d n ⊆ S [ [ cM 1 . . . M n ] ] ε and ( d n +1 < τ n +1 ε M n +1 ⇒ ( S [ [ c ] ] ⊥ ) d 1 . . . d n +1 < ε cM 1 . . . M n +1 ) , b y part 4). Lemma 5 .6 say s S [ [ cM 1 . . . M n ] ] ε = ( S [ [ c ] ] ⊥ )( S [ [ M 1 ] ] ε ) . . . ( S [ [ M n ] ] ε ), therefore ( S [ [ c ] ] ⊥ ) d 1 . . . d n ⊆ S [ [ cM 1 . . . M n ] ] ε is fulfilled. 6) F ollo ws from Lemma 5.10. 7) F ollo ws from Lemma 5.13. 8), 9) and 1 0 ) follow from Lemma 5 .14. The Appro ximation Theorem w ould b e prov ed if we could sho w that S [ [ M ] ] ε < σ ε M for all M ∈ T σ . W e w ill no w prov e, b y structural induction on M , a stronger statemen t in order to handle free v ariables in the case of abstraction. Lemma 5.16 (Approxima tion Lemma) L et M ∈ T σ , ε ∈ Env, x σ i i (1 ≤ i ≤ n, n ≥ 0) b e a se quenc e of distinct variables, d i ∈ D σ i and N i ∈ T σ i for al l i . If d i < σ i ε N i for al l i , then S [ [ M ] ]( ε [ x 1 7→ d 1 , . . . , x n 7→ d n ]) < σ ε M [ x 1 := N 1 , . . . , x n := N n ] . Her e ε [ x 1 7→ d 1 , . . . , x n 7→ d n ] is the e nvir onm e nt that m aps x to ε ( x ) if x 6 = x i for al l i , and x i to d i . M [ x 1 := N 1 , . . . , x n := N n ] is the r esult of the simultane ous substitu tion of 5 APPR O XIMA TION THEOREM 36 the N i for the fr e e o c curr enc es of x i in M , with appr opriate r enaming of b ound variables of M . Pro of: b y structural induction on M . F or a n y ε ′ ∈ Env w e abbreviate ε ′ = ε ′ [ x 1 7→ d 1 , . . . , x n 7→ d n ], and for any term L we write L = L [ x 1 := N 1 , . . . , x n := N n ]. W e cite the parts of the In clusiv e Predicate Lemma simply b y part i). The us e of par t s 1) – 5) should b e o bvious a nd is of t en not men tioned. • M = Ω: S [ [Ω] ] ε = ⊥ < σ ε Ω. • M = 0 , σ = τ → ( τ + ) : T o sho w S [ [ 0 ] ] ε < σ ε 0 , we prov e d < τ ε N ⇒ 0 d < τ + ε 0 N . W e ha v e 0 d ⊆ 0( S [ [ N ] ] ε ) = S [ [ 0 N ] ] ε . F urthermore d < τ ε Out0 ( 0 N ) b y part 6), as Out0 ( 0 N ) → ∗ N . • M = 1 is analogous. • M = case , σ = ( τ + ) → ( τ → ψ ) → ( → ψ ) → ψ : T o sho w S [ [ case ] ] ε < σ ε case , w e ha ve to prov e: d 0 < τ + ε M 0 ∧ d 1 < τ → ψ ε M 1 ∧ d 2 < → ψ ε M 2 ⇒ c ase d 0 d 1 d 2 < ψ ε case M 0 M 1 M 2 . This is clear for d 0 = ⊥ . No w let d 0 = 0 d ′ 0 . a) W e assume M 0 → ∗ 0 M ′ 0 for some M ′ 0 . As d 1 < τ → ψ ε M 1 and d ′ 0 < τ ε Out0 ( M 0 ), w e get c ase d 0 d 1 d 2 = | d 1 | d ′ 0 < ψ ε M 1 ( Out0 ( M 0 )) . W e ha ve case M 0 M 1 M 2 → ∗ M 1 M ′ 0 and M 1 ( Out0 ( M 0 )) → ∗ M 1 M ′ 0 , so c ase d 0 d 1 d 2 < ψ ε case M 0 M 1 M 2 b y part 6). b) W e assume that not M 0 → ∗ 0 M ′ 0 for an y M ′ 0 . M 0 → ∗ 1 M ′ 0 is also imp ossible. So there is no reduct of case M 0 M 1 M 2 that is a redex. F rom Lemma 5.6 w e conclude: c ase d 0 d 1 d 2 ⊆ c ase ( S [ [ M 0 ] ] ε ) ( S [ [ M 1 ] ] ε ) ( S [ [ M 2 ] ] ε ) = S [ [ case M 0 M 1 M 2 ] ] ε. F urthermore case M 0 M 1 M 2 is passiv e, and c ase d 0 d 1 d 2 < ψ ε case M 0 M 1 M 2 follo ws from pa rt 7). The case d 0 = 1 d ′ 0 is analogous. • M = pcase , σ = ( τ + ) → ψ → ψ → ψ : W e ha ve to prov e: d 0 < τ + ε M 0 ∧ d 1 < ψ ε M 1 ∧ d 2 < ψ ε M 2 ⇒ p c a se d 0 d 1 d 2 < ψ ε p case M 0 M 1 M 2 . F or d 0 = ⊥ w e hav e p c ase d 0 d 1 d 2 = d 1 ∩ d 2 . The result follows from part 10). F or d 0 = 0 d ′ 0 w e use part 8), for d 0 = 1 d ′ 0 part 9). 5 APPR O XIMA TION THEOREM 37 • M = pair is lik e M = 0 . • M = fst , σ = ( τ × ) → τ : d < τ × ε N ⇒ fst d < τ ε fst N follo ws directly from part 3). • M = snd is analogous. • M = x : If x = x i for some i , then S [ [ x ] ] ε = d i < σ ε N i = x . No w let x 6 = x i for a ll i . Then S [ [ x ] ] ε = ε ( x ) ⊆ S [ [ x ] ] ε . x is passiv e. F rom part 7) follo ws S [ [ x ] ] ε < σ ε x . • M = N P , where N : τ → σ and P : τ : By induction h yp othesis we hav e S [ [ N ] ] ε < τ → σ ε N and S [ [ P ] ] ε < τ ε P . Therefore |S [ [ N ] ] ε | ( S [ [ P ] ] ε ) < σ ε N P , by part 4). Th us w e g et S [ [ N P ] ] ε < σ ε N P . • M = λx τ .M ′ , σ = τ → : W e ma y assume that x is no x i and x do es not o ccur free in an y N i . ( x can b e renamed b y α -con v ersion.) First w e pro ve that S [ [ λx.M ′ ] ] ε ⊆ S [ [ λx.M ′ ] ] ε . S [ [ λx.M ′ ] ] ε = Pr ( d ∈ D τ 7→ S [ [ M ′ ] ]( ε [ x 7→ d ])) = Pr ( d ∈ D τ 7→ S [ [ M ′ ] ]( ε [ x 7→ d ])) , as x is no x i ⊆ Pr ( d ∈ D τ 7→ S [ [ M ′ ] ]( ε [ x 7→ d ])) , as S [ [ M ′ ] ]( ε [ x 7→ d ]) < ε [ x 7→ d ] M ′ b y induction hy p othesis = Pr ( d ∈ D τ 7→ [ A ✁ − M ′ S [ [ A ] ]( ε [ x 7→ d ])) = [ A ✁ − M ′ Pr ( d ∈ D τ 7→ S [ [ A ] ]( ε [ x 7→ d ])) = [ A ✁ − M ′ S [ [ λx.A ] ] ε = [ B ✁ − λx.M ′ S [ [ B ] ] ε , as A ✁ − M ′ ⇔ λx.A ✁ − λx.M ′ = λx.M ′ , since x is no x i = S [ [ λx.M ′ ] ] ε No w w e prov e that: d < τ ε N ⇒ |S [ [ M ] ] ε | d < ε M N . |S [ [ M ] ] ε | d = S [ [ M ′ ] ]( ε [ x 7→ d ]) = S [ [ M ′ ] ]( ε [ x 1 7→ d 1 , . . . , x n 7→ d n , x 7→ d ]) , as x is no x i < ε M ′ [ x 1 := N 1 , . . . , x n := N n , x := N ] , b y induction h yp othesis F urthermore w e ha v e: M N = ( λx.M ′ ) N , as x is no x i → ( M ′ [ x 1 := N 1 , . . . , x n := N n ])[ x := N ] = M ′ [ x 1 := N 1 , . . . , x n := N n , x := N ] , as x is not free in an y N i 5 APPR O XIMA TION THEOREM 38 F rom part 6) follows |S [ [ M ] ] ε | d < ε M N . Pro of of the Approxim ation Theorem: S [ [ M ] ] ε ⊆ S [ [ M ] ] ε follo ws fro m S [ [ M ] ] ε < σ ε M , whic h ho lds by the preceding lemma. Corollary 5.17 F or al l terms M and envir onments ε : S [ [ M ] ] ε = [ {S [ [ A ] ] ε | A is a normal form and ∃ N . M → ∗ N ∧ A ≺ N } Pro of: S [ [ M ] ] ε ⊆ the righ t-hand side, and the right-hand side ⊆ S [ [ M ] ] ε . Note: The original pap er [W ad78] gives a definition of a ppro ximations in the form of this corollary , for the un typed λ -calculus. Corollary 5.18 The semantics of the fixe d p oint c ombinator Y σ = λy σ → σ . ( λx.y ( xx ))( λx.y ( xx )) is S [ [ Y σ ] ] ε = Pr ( f ∈ D σ → σ 7→ [ n ≥ 0 f n ( ⊥ )) , so |S [ [ Y σ ] ] ε | f i s the le ast fi xe d p oint of | f | . Pro of: The approximations o f Y σ are just the terms λy .y n Ω, with y 0 Ω = Ω and y n +1 Ω = y ( y n Ω). S [ [ Y σ ] ] ε = S [ [ Y σ ] ] ε = [ n ≥ 0 S [ [ λy .y n Ω] ] ε = [ n ≥ 0 Pr ( f ∈ D σ → σ 7→ f n ( ⊥ )) = Pr ( f ∈ D σ → σ 7→ [ n ≥ 0 f n ( ⊥ )) Let us contin ue our discussion of the definition of approximations. In the case of the unt yp ed λ -calculus [Bar84] it is p ossible to define least a ppro ximations via head normal forms. Let us lo o k a t this approac h more abstractly: W e are giv en a set H of normal fo rms with the prop ert y: If A ∈ H and A ≺ M , then A ✁ M . This means that an H -prefix of a term M do es no t change b y r eductions o f M . In the case of the un t yp ed λ -calculus H is the set consisting just of Ω and all terms of the form λx 1 . . . x n .y A 1 . . . A m with A i ∈ H . W e define S H [ [ M ] ] ε = [ {S [ [ A ] ] ε | A ∈ H and ∃ N . M → ∗ N ∧ A ≺ N } . H should fulfill: S H [ [ M ] ] ε = S [ [ M ] ] ε for all M , ε . W e sho w that a set H with this prop ert y a nd the prop erty ab ov e do es not exist for our calculus with p case : 5 APPR O XIMA TION THEOREM 39 Let M = p case x 0 Ω. It is M 6∈ H , b ecause of the first prop erty of H and as not M ✁ p case x 0 0 . F or all A ≺ M with A 6 = M we ha v e S [ [ A ] ]( ⊥ [ x 7→ 0]) = ⊥ . Therefore S H [ [ M ] ]( ⊥ [ x 7→ 0]) = ⊥ 6 = 0 = S [ [ M ] ]( ⊥ [ x 7→ 0 ]) . Let us no w consider the sequen tial calculus without p case . In this case we can define t w o sets H with the desired prop erties. Definition 5.19 A normal form A is a minimum normal form (mnf ) iff for all B ≺ A : S [ [ B ] ] = S [ [ A ] ] ⇒ B = A . A normal f orm A is a c onstant norm al form (cnf ) iff A = Ω or A = λx 1 . . . x n .y A 1 . . . A m , where n ≥ 0, m ≥ 0, y is a v ariable or a constant 6∈ { Ω , p case } , the A i are cnfs and for y ∈ { fst , snd , case } and m ≥ 1 it is A 1 6 = Ω. Constan t no rmal forms resem ble the normal f o rms of H defined b y head normal forms ab o ve , for the un t yp ed λ - calculus. Lemma 5.20 Every minimum normal form without p case is a c on s tant normal form. Pro of: Supp ose A is a nor mal form without p case that is no cnf. W e sho w by structural induction on A that A is no mnf. W e hav e A = λx 1 . . . x n .y A 1 . . . A m , n ≥ 0, m ≥ 0, y a v a riable or a constan t, and one of the f o llo wing three cases: 1) y = Ω and ( n > 0 or m > 0). Then Ω ≺ A , Ω 6 = A and S [ [Ω] ] = S [ [ A ] ], so A is no mnf. 2) Some A i is no cnf. By induction hypothesis A i is no mnf. Then also A is no mnf. 3) y is fst , snd or case and A 1 = Ω. Then S [ [ A ] ] = S [ [Ω] ], A is no mnf. Lemma 5.21 If A is a c onstant norm al form and A ≺ M , then A ✁ M . Pro of: W e prov e: If A is a cnf, A ≺ M and M → N , then A ≺ N , b y structural induction on A . (The lemma f o llo ws b y simple induction on reductions M → ∗ N .) The case A = Ω is clear. No w let A = λx 1 . . . x n .y A 1 . . . A m . Then M = λx 1 . . . x n .y M 1 . . . M m with A i ≺ M i for all i . The term y M 1 . . . M m is no redex: This is clear if y is a v ar ia ble or 0 , 1 , or pair . If y = fst or y = snd , and m ≥ 1, then A 1 6 = Ω and A 1 is not of the for m pair A ′ A ′′ . So M 1 is not of this form either. 6 ADEQUA CY AND FULL ABSTRA CTION 40 If y = ca se and m ≥ 1, then A 1 6 = Ω and A 1 and M 1 are not of the fo r m 0 A ′ or 1 A ′ . Th us there is some j with M j → N j and N = λx 1 . . . x n .y M 1 . . . M j − 1 N j M j +1 . . . M m . By the induction h yp othesis w e get A j ≺ N j , therefore A ≺ N . By this lemma the set of cnfs (and the set of mnfs) has t he first of the tw o pro p erties of H . W e define tw o new approximation sets f o r terms: B ( M ) = { A | A is a mnf and ∃ N . M → ∗ N ∧ A ≺ N } C ( M ) = { A | A is a cnf and ∃ N . M → ∗ N ∧ A ≺ N } F or the sequen tial calculus without p case w e hav e: B ( M ) ⊆ C ( M ) ⊆ A ( M ) . The first inclusion follow s from Lemma 5.2 0 , the second from Lemma 5.21. B ( M ) ⊆ A ( M ) is not v alid for M = p case x 0 0 : W e ha v e p case x 0 Ω ∈ B ( M ), but p case x 0 Ω 6∈ A ( M ). In ev ery case, also for p case : S [ [ M ] ] ε = [ A ∈A ( M ) S [ [ A ] ] ε ⊆ [ A ∈B ( M ) S [ [ A ] ] ε for all ε ∈ Env . This is b ecause for every normal fo rm A there is a mnf B ≺ A with S [ [ A ] ] = S [ [ B ] ]. W e com bine these results with the Approxim atio n Theorem: Theorem 5.22 In the s e quential c alculus without p case : F or al l terms M and envi - r onm ents ε , [ A ∈B ( M ) S [ [ A ] ] ε = [ A ∈C ( M ) S [ [ A ] ] ε = S [ [ M ] ] ε = S [ [ M ] ] ε. With this theorem the set of mnfs and the set of cnfs b oth ha ve t he second prop erty of H . [My conjecture is tha t in the sequen tial calculus B ( M ) is the least approx imation of M with the same semantic s as M . More precisely the conjecture is: Let I b e an ideal of normal forms suc h that for a ll A ∈ I there is N with M → ∗ N a nd A ≺ N , and S [ [ M ] ] = S A ∈ I S [ [ A ] ]. Then B ( M ) ⊆ I .] 6 Adequacy and full abstract ion The classical seman tical analysis of the programming language PCF [Plo77] pro ceeds as follows: The closed terms of the gro und t yp e integer are singled out as pr o gr ams . Programs are regarded as the only terms whose syntactical v alues (integers) can b e observ ed directly . All other terms m ust b e observ ed throug h pro gram contexts . If the seman tics of a programm M is an in teger v a lue i , then M can b e reduced to i . This 6 ADEQUA CY AND FULL ABSTRA CTION 41 result is called the ade quacy of the seman tics. Then an o p erational preorder is defined on terms: M ⊑ N iff for a ll con texts C [ ] suc h that C [ M ] and C [ N ] are programs, if C [ M ] → ∗ i , then also C [ N ] → ∗ i . If S [ [ M ] ] ⊆ S [ [ N ] ], then M ⊑ N ; this follow s fro m soundness and adequacy . The con v erse, ful l abstr action , is not true for sequen tial PCF, but holds for PCF with a parallel conditional. W e fo llo w the same programme for our recursiv ely t yp ed λ -calculus. W e c ho ose the closed terms of t yp e b o ol = void + vo id as o ur programs. Th us the o bserv able non-b ottom syn tactical v alues are the terms of the form 0 M or 1 M . W e ha v e c hosen the smallest type with mor e than one elemen t. (Any non-functional, non- trivial ty p e, built from + and × only , w ould do as w ell.) Definition 6.1 The set of pr o gr ams is Pr o g = T c bo ol . W e define t he op er ational evaluation function O : Pr o g → D bo ol b y O [ [ M ] ] = 0 if M → ∗ 0 M ′ , O [ [ M ] ] = 1 if M → ∗ 1 M ′ , for some M ′ , and O [ [ M ] ] = ⊥ otherwise. W e w ant to pro v e adequacy (that the reduction of a program reache s its seman tic v a lue) from the Appro ximation Theorem of the preceding c hapter. W e need the follo wing lemma: Lemma 6.2 L et σ ∈ T ∞ and A ∈ N σ b e a normal form with S [ [ A ] ] ⊥ 6 = ⊥ . If σ = τ + , then A = 0 A ′ or A = 1 A ′ for some A ′ . If σ = τ × , then A = pair A ′ A ′′ for some A ′ , A ′′ . Pro of: b y structural induction on A . W e suppose A is of t yp e τ + or τ × . Then A = cA 1 . . . A n , n ≥ 0, with c a constant and the A i normal f orms. W e give a case analysis on c : c = 0 , 1 or pair : The lemma is fulfilled. c = fst or snd : Then n ≥ 1 . S [ [ A ] ] ⊥ 6 = ⊥ implies S [ [ A 1 ] ] ⊥ 6 = ⊥ implies A 1 = pair A ′ A ′′ b y induction h yp othesis. Then A is no no rmal form. c = case : Then n ≥ 3. S [ [ A ] ] ⊥ 6 = ⊥ implies S [ [ A 1 ] ] ⊥ 6 = ⊥ implies A 1 = 0 A ′ 1 or A 1 = 1 A ′ 1 b y induction h yp othesis. Then A is no no r ma l form. c = pcase : Then n = 3. If S [ [ A 1 ] ] ⊥ 6 = ⊥ , then A 1 = 0 A ′ 1 or A 1 = 1 A ′ 1 b y induction hy p othesis and A is no normal f orm. If S [ [ A 1 ] ] ⊥ = ⊥ , then S [ [ A ] ] ⊥ = S [ [ A 2 ] ] ⊥ ∩ S [ [ A 3 ] ] ⊥ 6 = ⊥ . If σ = τ + , then by induction h yp othesis either ( A 2 = 0 A ′ 2 , A 3 = 0 A ′ 3 ) or ( A 2 = 1 A ′ 2 , A 3 = 1 A ′ 3 ). In b o th cases A is no normal form. If σ = τ × , then b y induction h yp othesis A 2 = pa ir A ′ 2 A ′′ 2 and A 3 = pa ir A ′ 3 A ′′ 3 and A is no normal f orm. Theorem 6.3 (Adequacy) F or al l M ∈ Pr o g : O [ [ M ] ] = S [ [ M ] ] ⊥ . 6 ADEQUA CY AND FULL ABSTRA CTION 42 Pro of: O [ [ M ] ] ⊆ S [ [ M ] ] ⊥ follows from soundnes s: If M → ∗ 0 M ′ , then S [ [ M ] ] ⊥ = S [ [ 0 M ′ ] ] ⊥ = 0; and if M → ∗ 1 M ′ , then S [ [ M ] ] ⊥ = S [ [ 1 M ′ ] ] ⊥ = 1 . It remains to sho w the adequacy: S [ [ M ] ] ⊥ ⊆ O [ [ M ] ]. Supp ose S [ [ M ] ] ⊥ = 0. By the Appro ximation Theorem there is an approxim atio n A ✁ − M with S [ [ A ] ] ⊥ = 0. F rom the preceding lemma follow s A = 0 A ′ for some A ′ , therefore O [ [ M ] ] = 0. Analogously S [ [ M ] ] ⊥ = 1 implies O [ [ M ] ] = 1. Note that this theorem is also v alid f or the sequen tial calculus without p case . It can also b e prov ed directly using the inclusiv e predicate tec hnique, with a pro of a bit easier than the pro of of the Appro ximation Theorem, e.g. the passiv e terms are not needed. No w w e define the op era t ional preorder on terms, based on the o bserv ation of terms through program con texts. Definition 6.4 Let M , N ∈ T σ . M ⊑ N iff fo r all contex ts C [ ], such that C [ M ] and C [ N ] are programs, O [ [ C [ M ]] ] ⊆ O [ [ C [ N ]] ] holds. Theorem 6.5 (F ull abstraction) F or al l M , N ∈ T σ : M ⊑ N iff S [ [ M ] ] ⊆ S [ [ N ] ] . The direction “If S [ [ M ] ] ⊆ S [ [ N ] ] then M ⊑ N ” follow s easily from soundness and adequacy: O [ [ C [ M ]] ] = S [ [ C [ M ]] ] ⊥ ⊆ S [ [ C [ N ]] ] ⊥ = O [ [ C [ N ]] ]. This holds also f or the sequen tia l calculus without p case . In this case the con texts are restricted. Therefore the o pp o site direction is not v alid f o r the sequen tial calculus, a s can b e sho wn by the same example as in [Plo7 7 ]. F or t he pro of o f the opp osite direction (for the para llel calculus ) w e prov e a lemma that states the definabilit y o f all finite elemen ts of the seman tics. Lemma 6.6 (Definabilit y) F or al l finite d ∈ D σ ther e is a close d term M ∈ T c σ with S [ [ M ] ] ⊥ = d . W e recall that finite ele men ts are the elem ents that are do wnw ard closures o f finite sets of primes. In our term construction w e use the following para llel function and instead of p case : and : b o ol → b o ol → bo ol , defined as and = λxy . p case x y 1 . Here and in the followin g we interpret the Bo olean v alue 0 as true and 1 as false, and c hose the names of our functions accordingly . (W e made this c hoice in order to in terpret case lik e if-t hen-else, with the second ar g umen t as true-part and the thir d argument as false-part.) The seman tics of and fulfills: ( S [ [ and ] ] ⊥ )00 = 0, ( S [ [ and ] ] ⊥ )1 ⊥ = 1, ( S [ [ a nd ] ] ⊥ ) ⊥ 1 = 1. Here w e sho w that all finite elemen ts are definable fro m and and the sequen tial constan ts. In the next c hapter we will show that also p case (which is not finite) is definable from and . 6 ADEQUA CY AND FULL ABSTRA CTION 43 Pro of: W e hav e to in tro duce some notions first. A term C : b o ol is called a c ondition iff for ev ery en vironmen t ε : ( ∀ ε ′ ⊇ ε. S [ [ C ] ] ε ′ 6 = 0) ⇒ S [ [ C ] ] ε = 1 . The se mantics of a condition is so “dense” that it giv es the v alue 1 for ev ery en vironmen t that cannot b e enlarged to giv e the v alue 0. A c onditione d prime is a pair C → a of a condition C and a prime a . In the course of our construction the condition o f C → a will b e used to accum ulate a term that c hec ks function arg umen ts. The intuitiv e semantic s of the “mixed term” C → a is the prime a for ev ery en vironmen t ε with S [ [ C ] ] ε = 0. F or a set P of primes, Cond ( P ) is the set o f all conditioned primes C → a with a ∈ P . A set X of conditioned primes is called c on sistent iff for a ll C → a, C ′ → a ′ ∈ X holds: ( ∃ ε. S [ [ C ] ] ε = S [ [ C ′ ] ] ε = 0) ⇒ a ↑ a ′ . F or M ∈ T σ , X ⊆ Co n d ( P ( σ )) finite and consisten t, w e define a predicate term : M term X iff S [ [ M ] ] ε = { a | ∃ C. ( C → a ) ∈ X ∧ S [ [ C ] ] ε = 0 } ↓ for all ε . F or M ∈ T c σ → b o ol , X ⊆ P ( σ ) finite and consisten t, w e define a predicate e q : M e q X iff |S [ [ M ] ] ⊥| d = 0 , if X ⊆ d 1 , if d ↑ − X ⊥ otherwise where d ↑ − X means: ∃ a ∈ d, b ∈ X. not a ↑ b . W e prov e f o r ev ery n ≥ 0 and ev ery σ ∈ T ∞ : 1) F or ev ery finite and consisten t X ⊆ Cond ( P n ( σ )) there is M ∈ T σ with M term X . 2) F or ev ery finite and consisten t X ⊆ P n ( σ ) there is M ∈ T c σ → b o ol with M e q X . W e use abbreviations fo r the following function terms: if = λxy z . case x ( λ w .y ) ( λw .z ) : b o ol → σ → σ → σ not = λx. if x 1 0 : b o ol → b o ol o r = λxy . not ( and ( not x ) ( not y )) : b o ol → b o ol → b o ol The seman tics of or is: ( S [ [ o r ] ] ⊥ )11 = 1, ( S [ [ o r ] ] ⊥ )0 ⊥ = 0, ( S [ [ o r ] ] ⊥ ) ⊥ 0 = 0 . The pro of o f statemen ts 1) and 2) is by simultaneous induction on n : n = 0: 1) X = ∅ . Ω term X . 2) X = ∅ . ( λx. 0 ) e q X . 6 ADEQUA CY AND FULL ABSTRA CTION 44 Induction step: 1) Let X ⊆ Cond ( P n +1 ( σ )) b e finite and consisten t. W e construct M term X b y case analysis o v er σ . • σ = void : X = ∅ , Ω t erm X . • σ = τ + : Define the condition sets C 0 = { C | ∃ a ≥ 0 . ( C → a ) ∈ X } and C 1 = { C | ∃ a ≥ 1 . ( C → a ) ∈ X } . Define the term M 0 : b o ol as M 0 = 1 for C 0 = ∅ , otherwise as M 0 = or C 0 1 ( o r C 0 2 . . . C 0 j ) for some enume rat io n { C 0 1 , C 0 2 , . . . , C 0 j } = C 0 . Analogo usly , M 1 is defined as a n or -term of the elemen ts of C 1 . Let X 0 = { C → a | ( C → (0 , a )) ∈ X } and X 1 = { C → a | ( C → (1 , a )) ∈ X } . It is X 0 ⊆ Cond ( P n ( τ )) and X 1 ⊆ Cond ( P n ( )), b oth are finite and consisten t. By the induction h yp othesis there are terms N 0 ∈ T τ , N 1 ∈ T with N 0 term X 0 and N 1 term X 1 . W e build the term M = if M 0 ( 0 N 0 ) ( if M 1 ( 1 N 1 ) Ω) and sho w that M term X , i.e. for a ll ε , S [ [ M ] ] ε = Y ↓ with Y = { a | ∃ C. ( C → a ) ∈ X ∧ S [ [ C ] ] ε = 0 } : ⋆ S [ [ M ] ] ε ⊆ Y ↓ : Let a ∈ S [ [ M ] ] ε . W e sho w a ∈ Y ↓ in eac h of the tw o cases: a) S [ [ M 0 ] ] ε = 0: Then a ∈ 0 ( S [ [ N 0 ] ] ε ). First let a = 0. There is some C ∈ C 0 with S [ [ C ] ] ε = 0. ( C → a ′ ) ∈ X for some a ′ ≥ 0, therefore 0 ∈ Y ↓ . No w let a = (0 , a ′ ). Then a ′ ∈ S [ [ N 0 ] ] ε . Since N 0 term X 0 , there is ( C → a ′′ ) ∈ X 0 with S [ [ C ] ] ε = 0 and a ′ ≤ a ′′ . ( C → (0 , a ′′ )) ∈ X , therefore (0 , a ′ ) ∈ Y ↓ . b) S [ [ M 0 ] ] ε = 1 a nd S [ [ M 1 ] ] ε = 0: Then a ∈ 1 ( S [ [ N 1 ] ] ε ). Analogously to case a) we show that a ∈ Y ↓ . ⋆ S [ [ M ] ] ε ⊇ Y ↓ : Let a ∈ Y , i.e. ( C → a ) ∈ X and S [ [ C ] ] ε = 0 for some C . W e show a ∈ S [ [ M ] ] ε in eac h of the f o ur cases: a) a = 0: C ∈ C 0 , therefore S [ [ M 0 ] ] ε = 0 a nd 0 ∈ S [ [ M ] ] ε . b) a = (0 , a ′ ): Again C ∈ C 0 , therefore S [ [ M 0 ] ] ε = 0 and S [ [ M ] ] ε = 0 ( S [ [ N 0 ] ] ε ). ( C → a ′ ) ∈ X 0 , therefore a ′ ∈ S [ [ N 0 ] ] ε , as N 0 term X 0 . It follows (0 , a ′ ) ∈ S [ [ M ] ] ε . c) a = 1 : Then C ∈ C 1 , therefore S [ [ M 1 ] ] ε = 0. W e sho w that S [ [ M 0 ] ] ε = 1, i.e. for all C ′ ∈ C 0 : S [ [ C ′ ] ] ε = 1. Here w e use the fact that C ′ is a condition: 6 ADEQUA CY AND FULL ABSTRA CTION 45 Let ε ′ ⊇ ε . Then S [ [ C ] ] ε ′ = 0. S [ [ C ′ ] ] ε ′ = 0 w ould contradict the consistency of X , as C ∈ C 1 and C ′ ∈ C 0 . Therefore S [ [ C ′ ] ] ε ′ 6 = 0. W e conclude S [ [ C ′ ] ] ε = 1. So w e ha v e S [ [ M 0 ] ] ε = 1, S [ [ M 1 ] ] ε = 0 a nd 1 ∈ S [ [ M ] ] ε . d) a = (1 , a ′ ): As in case c) we hav e S [ [ M 0 ] ] ε = 1, S [ [ M 1 ] ] ε = 0 a nd S [ [ M ] ] ε = 1 ( S [ [ N 1 ] ] ε ). ( C → a ′ ) ∈ X 1 , therefore a ′ ∈ S [ [ N 1 ] ] ε , as N 1 term X 1 . It follows (1 , a ′ ) ∈ S [ [ M ] ] ε . • σ = τ × : Let X 0 = { C → a | ( C → (0 , a )) ∈ X } ⊆ Cond ( P n ( τ )), and X 1 = { C → a | ( C → (1 , a )) ∈ X } ⊆ Cond ( P n ( )). Both sets are finite and compatible. By the induction h yp othesis there are terms N 0 , N 1 with N 0 term X 0 and N 1 term X 1 . Let M = ( N 0 , N 1 ). S [ [ M ] ] ε = p air ( S [ [ N 0 ] ] ε ) ( S [ [ N 1 ] ] ε ) = { 0 } × { a | ∃ C . ( C → a ) ∈ X 0 ∧ S [ [ C ] ] ε = 0 } ↓ ∪ { 1 } × { a | ∃ C . ( C → a ) ∈ X 1 ∧ S [ [ C ] ] ε = 0 } ↓ = { a | ∃ C . ( C → a ) ∈ X ∧ S [ [ C ] ] ε = 0 } ↓ • σ = τ → : Let X = { C i → ( Y i , a i ) | 1 ≤ i ≤ k } b e an enum eration o f the elemen t s of X . F or all i , Y i ⊆ P n ( τ ) is finite and consisten t . By the induction h yp othesis there is N i e q Y i for all i . Let x b e a v ariable of t yp e τ that do es not occur free in an y C i . Let D i = a nd C i ( N i x ). W e define Z = { D i → a i | 1 ≤ i ≤ k } and first pro v e that Z ⊆ Cond ( P n ( )) a nd Z is consisten t: ⋆ D i = and C i ( N i x ) is a condition: Let ε b e an en vironmen t suc h t ha t fo r all ε ′ ⊇ ε , S [ [ D i ] ] ε ′ 6 = 0. W e hav e to sho w that S [ [ D i ] ] ε = 1. Assume S [ [ C i ] ] ε 6 = 1. As C i is a condition, there is ε ′′ ⊇ ε with S [ [ C i ] ] ε ′′ = 0 . Let ε ′ = ε ′′ [ x 7→ Y i ↓ ]. Then S [ [ C i ] ] ε ′ = 0, as x do es no t o ccur free in C i . F urthermore S [ [ N i x ] ] ε ′ = 0, a s N i e q Y i . T ogether w e get S [ [ D i ] ] ε ′ = 0. Then ε a nd ε ′ cannot hav e an upp er b ound. (F or suc h an upp er b ound δ would b e: δ ⊇ ε and S [ [ D i ] ] δ = 0.) As ε ′′ ⊇ ε , it m ust b e ε ( x ) ↑ − ε ′ ( x ) = Y i ↓ . Hence S [ [ N i x ] ] ε = 1, and w e conclude S [ [ D i ] ] ε = 1. ⋆ Z is consisten t: Let S [ [ D i ] ] ε = S [ [ D j ] ] ε = 0 for some i, j, ε . Then S [ [ C i ] ] ε = S [ [ C j ] ] ε = 0, hence ( Y i , a i ) ↑ ( Y j , a j ). Also S [ [ N i x ] ] ε = S [ [ N j x ] ] ε = 0, therefore Y i ⊆ ε ( x ) and Y j ⊆ ε ( x ). So Y i ↑ Y j and w e conclude a i ↑ a j . 6 ADEQUA CY AND FULL ABSTRA CTION 46 W e hav e prov ed that Z ⊆ Cond ( P n ( )) is a finite, consisten t, conditioned prime set. By induction h yp othesis there is N term Z . Let M = λx.N . W e pro ve M term X , i.e. S [ [ M ] ] ε = Pr ( d ∈ D τ 7→ S [ [ N ] ]( ε [ x 7→ d ]) ) = { ( Y i , a i ) | 1 ≤ i ≤ k ∧ S [ [ C i ] ] ε = 0 } ↓ . ⊆ : Let ( Y , a ) ∈ S [ [ M ] ] ε . Then a ∈ S [ [ N ] ]( ε [ x 7→ Y ↓ ]) = { a i | S [ [ D i ] ]( ε [ x 7→ Y ↓ ]) = 0 } ↓ , as N term Z . Let a ≤ a i and S [ [ D i ] ]( ε [ x 7→ Y ↓ ]) = 0 . Then |S [ [ N i ] ] ⊥| ( Y ↓ ) = 0. Hence Y i ⊆ Y ↓ , as N i e q Y i . So w e get ( Y , a ) ≤ ( Y i , a i ). F urthermore S [ [ C i ] ] ε = S [ [ C i ] ]( ε [ x 7→ Y ↓ ]) = 0 . ⊇ : Let S [ [ C i ] ] ε = 0. W e hav e |S [ [ N i ] ] ⊥| ( Y i ↓ ) = 0, as N i e q Y i . Therefore S [ [ D i ] ]( ε [ x 7→ Y i ↓ ]) = 0. As N term Z , it is a i ∈ S [ [ N ] ]( ε [ x 7→ Y i ↓ ]). Hence ( Y i , a i ) ∈ S [ [ M ] ] ε . 2) Let X ⊆ P n +1 ( σ ) b e finite and consisten t. W e construct M e q X b y case ana lysis o v er σ . • σ = void : X = ∅ , ( λx. 0 ) e q X . • σ = τ + : If X = ∅ , then ( λx. 0 ) e q X . No w let a ∈ X for some a ≥ 0. Let Y = { a | (0 , a ) ∈ X } ⊆ P n ( τ ). By induction h yp othesis there is some N with N e q Y . T ak e M = λx. case x N 1 . It can b e easily c hec k ed that M e q X . The case a ∈ X f or some a ≥ 1 is similar. • σ = τ × : Let X 0 = { a | (0 , a ) ∈ X } ⊆ P n ( τ ) and X 1 = { a | (1 , a ) ∈ X } ⊆ P n ( ). There are N 0 e q X 0 and N 1 e q X 1 b y induction hy p othesis. Let M = λx. and ( N 0 ( fst x )) ( N 1 ( snd x )). W e che ck easily that M e q X . • σ = τ → : If X = ∅ , then ( λx. 0 ) e q X . Otherwise, let X = { ( Y i , a i ) | 1 ≤ i ≤ k } b e an en umeration o f X . Let Y ′ i = { 0 → b | b ∈ Y i } ⊆ Cond ( P n ( τ )) for all i , it is finite and consisten t. By induction h yp othesis there is N i term Y ′ i for all i . F urthermore, b y induction h yp othesis there is Q i e q a i for all i . W e define M = λx . and ( Q 1 ( xN 1 ))( and ( Q 2 ( xN 2 )) . . . ( Q k ( xN k ))) . W e c hec k that M e q X : Let d ∈ D σ . If X ⊆ d , t hen fo r all i : |S [ [ Q i ] ] ⊥| ( | d | ( S [ [ N i ] ] ⊥ )) = |S [ [ Q i ] ] ⊥| ( | d | ( Y i ↓ )) = 0, a s a i ∈ | d | ( Y i ↓ ). 7 INTERDEFINABILITY OF CONST ANTS 47 Therefore |S [ [ M ] ] ⊥| d = 0. If d ↑ − X , then there is some j with d ↑ − ( Y j , a j ), i.e. | d | ( Y j ↓ ) ↑ − { a j } . Therefore |S [ [ Q j ] ] ⊥| ( | d | ( S [ [ N j ] ] ⊥ )) = 1, and |S [ [ M ] ] ⊥| d = 1. Otherwise, d ↑ ( Y i , a i ) for all i and ( Y j , a j ) 6∈ d for some j . Then |S [ [ M ] ] ⊥| d = ⊥ . W e hav e no w prov ed statemen ts 1 ) and 2) for all n and σ . The lemma follo ws easily from 1 ) : If d ∈ D σ is finite, it has the form d = X ↓ with X ⊆ P n ( σ ) for some n , X finite and consisten t. There is a term M with M term { 0 → a | a ∈ X } , i.e. S [ [ M ] ] ⊥ = X ↓ . Pro of of the F ull Abstraction Theorem: It remains to sho w for all M , N ∈ T σ : If M ⊑ N , then S [ [ M ] ] ε ⊆ S [ [ N ] ] ε fo r all ε . First supp ose that M and N are closed terms. Let a ∈ S [ [ M ] ] ε . Define f = ( { a } , 0) ↓∈ D σ → b o ol . By the D efinabilit y Lemma, there is P ∈ T c σ → b o ol with S [ [ P ] ] ⊥ = f . P [ ] serv es a s a con text suc h that P M and P N ar e programs. 0 = S [ [ P M ] ] ⊥ = O [ [ P M ] ] ⊆ O [ [ P N ] ] = S [ [ P N ] ] ⊥ , therefore a ∈ S [ [ N ] ] ε . No w let M and N b e terms with their free v ariables in { x 1 , . . . , x n } . W e get λx 1 . . . x n .M ⊑ λx 1 . . . x n .N : F or a ll con texts C [ ] apply the con text C [ λx 1 . . . x n . [ ]] to M and N . F or the closed t erms f ollo ws: S [ [ λx 1 . . . x n .M ] ] ε ⊆ S [ [ λx 1 . . . x n .N ] ] ε for all ε . Hence S [ [ M ] ] ε ⊆ S [ [ N ] ] ε for all ε . 7 In terdefin abilit y o f c o nstan ts Our first observ a tion is that case can b e defined from p case and o ut0 , out1 (see page 9 for the def. o f out0 , o ut1 ). W e hav e S [ [ case ] ] = S [ [ λxy z . p case x ( p case x ( y ( o ut0 x )) Ω)( p case x Ω ( z ( out1 x )))] ] . In the precedin g c hapter w e used the function and : b o ol → b o ol → b o ol , de- fined as and = λxy . p case x y 1 , to build defining terms fo r all finite elemen ts of the seman tic mo del. Now w e will sho w that also p case (whose semantics is not finite) is definable from and and the sequen tial constan ts. Compare the definition o f PCF’s parallel conditiona l in terms of the parallel or in [Sto91]. W e assume a constan t and : bo ol → b o ol → bo ol with the seman tics: ( S [ [ a nd ] ] ⊥ )00 = 0 , ( S [ [ a nd ] ] ⊥ )1 ⊥ = 1 , ( S [ [ and ] ] ⊥ ) ⊥ 1 = 1 . Without lo ss o f generality , w e will define only p case void , void ,σ : b o ol → σ → σ → σ for all types σ , and write simp ly p case σ . The general p case can be easily defined from this. In order to cop e with recursiv e types, w e ha v e to extend the inductiv e definition of p case σ to general ty p e expressions σ (with free type v ariables). Then we hav e to asso ciate with each ty p e v ariable t of σ some type τ and a term v ar iable p : b o ol → τ → τ → τ , that stands f or the p case τ -function in its r ecursiv e definition. 7 INTERDEFINABILITY OF CONST ANTS 48 So w e are lead to define an op eration Pc ase ( θ , σ ) that pro duces terms for p ca se - functions. Its second a rgumen t is a ty p e expression σ ∈ T µ . The first a r gumen t is a partial map θ : V T → V from t yp e v ariables to term v a r ia bles, with θ ( t ) 6 = θ ( s ) f o r t 6 = s . θ is defined on a finite set of t yp e v ariables that con tains a ll free v ariables of σ . θ ( t ) m ust b e of the type b o ol → τ → τ → τ for some type τ . W e asso ciate with θ the partial map θ : V T → T c µ defined b y θ ( t ) = τ for θ ( t ) : b o ol → τ → τ → τ . Pc ase ( θ , σ ) will b e a term of type b o ol → θ ( σ ) → θ ( σ ) → θ ( σ ) , where θ is naturally extended to the substitution of free t yp e v ar ia bles o f ty p e expressions. [ ] is the totally undefined map. The notatio n θ [ t 7→ p ] will b e used as fo r en vironmen ts. In the definition of Pc as e w e use abbreviations for the follo wing function terms: if : b o ol → σ → σ → σ if = λxy z . case x ( λw .y ) ( λw .z ) not : b o ol → bo ol not = λx. if x 1 0 o r : b o ol → b o ol → b o ol o r = λxy . not ( and ( not x ) ( not y )) p c : b o ol → b o ol → b o o l → b o o l p c = λxy z . or ( or ( and x y ) ( and ( not x ) z )) ( and y z ) It is S [ [ p c ] ] ⊥ = S [ [ p case bo ol ] ] ⊥ . sb : τ + → bo ol sb = λx. case x ( λy . 0 ) ( λy . 1 ) Pc ase ( θ , σ ) is defined by structural induction on the type expression σ : Pc ase ( θ , t ) = θ ( t ) Pc ase ( θ , τ + ) = λx bo ol y θ ( τ + ) z θ ( τ + ) . if ( p c x ( sb y ) ( sb z )) ( 0 ( Pc ase ( θ , τ ) x ( out0 y ) ( out0 z ))) ( 1 ( Pc ase ( θ , ) x ( out1 y ) ( out1 z ))) Pc ase ( θ , τ × ) = λx bo ol y θ ( τ × ) z θ ( τ × ) . ( Pc a s e ( θ, τ ) x ( fst y ) ( fst z ) , Pc ase ( θ , ) x ( snd y ) ( snd z )) Pc ase ( θ , τ → ) = λx bo ol y θ ( τ → ) z θ ( τ → ) w θ ( τ ) . Pc ase ( θ , ) x ( y w )( z w ) Pc ase ( θ , µt.τ ) = Y π ( λp π . Pc ase ( θ [ t 7→ p π ] , τ )) , where π = bo ol → θ ( µt.τ ) → θ ( µt.τ ) → θ ( µt.τ ), and p π denotes the first v ariable in V π that is not in the image of θ Pc ase ( θ , vo id ) = Ω 7 INTERDEFINABILITY OF CONST ANTS 49 It is easy to show by induction tha t Pc ase ( θ , σ ) : b o ol → θ ( σ ) → θ ( σ ) → θ ( σ ). In the case of the r ecursiv e ty p e expression we hav e Pc ase ( θ [ t 7→ p π ] , τ ) : b o ol → → → with = θ [ t 7→ p π ]( τ ) = ( θ [ t 7→ θ ( µ t.τ )])( τ ) = θ ([ ][ t 7→ µ t.τ ]( τ )) ≈ θ ( µt.τ ) , so Pc ase ( θ [ t 7→ p π ] , τ ) : π , therefore Pc ase ( θ , µt.τ ) : π . Pc ase ( θ , σ ) has the free v ariables θ ( t ) f o r all t free in σ . Definition 7.1 Let f ∈ D bo ol → τ → τ → τ for some type τ . W e sa y that f appr oximates the function p c ase to level n , app n ( f ), iff f c a b ⊇ ( p c ase c a b ) | n for all c ∈ D bo ol and a, b ∈ D τ . Lemma 7.2 L et θ , σ b e admissible ar g uments in Pc ase ( θ , σ ) , as d e scrib e d ab ove. L et n ≥ 0 and ε b e an envir onment with app n ( ε ( θ ( t ))) f o r al l t fr e e in σ . Then fo r f = S [ [ Pc ase ( θ , σ )] ] ε we have app n ( f ) . If σ is not of the form µt 1 . . . µt m .t , with m ≥ 0 , t a typ e vari a ble a nd t 6 = t i for al l i , then app n +1 ( f ) . Pro of: b y structural induction on σ . • σ = t : f = ε ( θ ( t )), hence app n ( f ). • σ = τ + : W e sho w ap p n +1 ( f ), i.e. f c a b ⊇ ( p c ase c a b ) | n +1 for all c ∈ D bo ol , a, b ∈ D θ ( σ ) . 1) c = ⊥ : The case a ∩ b = ⊥ is clear. No w let a = 0 a ′ , b = 0 b ′ . f ⊥ (0 a ′ ) (0 b ′ ) = 0 ( ( S [ [ p case ( θ , τ )] ] ε ) ⊥ a ′ b ′ ) ⊇ 0 (( a ′ ∩ b ′ ) | n ) , b y induction hypothesis = ( a ∩ b ) | n +1 = ( p c ase c a b ) | n +1 The case a = 1 a ′ , b = 1 b ′ is analogous. 2) c = 0: The case a = ⊥ is clear. No w let a = 0 a ′ . f 0 (0 a ′ ) b = 0 ( ( S [ [ Pc ase ( θ , τ ) ] ] ε ) 0 a ′ (( S [ [ out0 ] ] ⊥ ) b )) ⊇ 0 ( a ′ | n ) , b y induction hypothesis = a | n +1 = ( p c ase c a b ) | n +1 7 INTERDEFINABILITY OF CONST ANTS 50 The case a = 1 a ′ is analogous. 3) c = 1 is analog o us to c = 0. • σ = τ × : W e sho w ap p n +1 ( f ). F or all c ∈ D bo ol , a 1 , b 1 ∈ D θ ( τ ) and a 2 , b 2 ∈ D θ ( ) w e ha v e: f c ( p a ir a 1 a 2 ) ( p air b 1 b 2 ) = p air (( S [ [ Pc ase ( θ, τ )] ] ε ) c a 1 b 1 )(( S [ [ Pc ase ( θ , )] ] ε ) c a 2 b 2 ) ⊇ p air ( p c ase c a 1 b 1 ) | n ( p c ase c a 2 b 2 ) | n , b y induction hyp. = ( p air ( p c ase c a 1 b 1 ) ( p c ase c a 2 b 2 )) | n +1 = ( p c ase c ( p air a 1 a 2 ) ( p air b 1 b 2 )) | n +1 • σ = τ → : W e prov e ap p n +1 ( f ). Let c ∈ D bo ol and a, b ∈ D θ ( σ ) . f c a b = Pr ( d ∈ D θ ( τ ) 7→ ( S [ [ Pc ase ( θ , )] ] ε ) c ( a d ) ( b d )). Let ( X , r ) ∈ ( p c ase c a b ) | n +1 . Then r ∈ (( p c ase c a b ) ( X ↓ )) | n = ( p c ase c ( a ( X ↓ )) ( b ( X ↓ ))) | n ⊆ ( S [ [ Pc ase ( θ, )] ] ε ) c ( a ( X ↓ )) ( b ( X ↓ )) , b y induction hy p ot hesis Hence ( X , r ) ∈ f c a b . • σ = µt.τ : 1) W e assume that τ is not o f the form µt 1 . . . µt m .s with m ≥ 0, s a t yp e v ar ia ble, s 6 = t , and s 6 = t i for all i . W e ha v e to show app n +1 ( f ). 1.1) W e a ssume τ = µt 1 . . . µt m .t . Then θ ( σ ) = σ ≈ v oid , hence f ∈ D bo ol → v oid → void → void and app n +1 ( f ). 1.2) Otherwise, τ is not of the form µt 1 . . . µt m .s with m ≥ 0, s a type v ariable a nd s 6 = t i for all i . W e ha ve f = S i ≥ 0 g i ⊥ with g = |S [ [ λp. Pc ase ( θ [ t 7→ p ] , τ )] ] ε | . W e sho w b y induction o n i tha t app i ( g i ⊥ ) for 0 ≤ i ≤ n + 1 : app 0 ( g 0 ⊥ ) is t r ivial. Induction step: W e assume app i ( g i ⊥ ) for some i ≤ n . g i +1 ⊥ = g ( g i ⊥ ) = S [ [ Pc ase ( θ [ t 7→ p ] , τ )] ]( ε [ p 7→ g i ⊥ ]). By the general induc tion hy p othesis (for the ty p e expression τ ) w e get app i +1 ( g i +1 ⊥ ). Esp ecially w e hav e app n +1 ( g n +1 ⊥ ), hence app n +1 ( f ). 2) W e assume τ = µt 1 . . . µt m .s with m ≥ 0, s a ty p e v ariable, s 6 = t , and s 6 = t i for all i . Then f = S [ [ Pc as e ( θ , s )] ] ε = ε ( θ ( s )), so app n ( f ). • σ = void : T rivial. 7 INTERDEFINABILITY OF CONST ANTS 51 Theorem 7.3 L et θ , σ b e admissi b le ar guments in Pc ase ( θ , σ ) , as desc ri b e d ab ove. L et ε b e an envir onment with ε ( θ ( t )) = S [ [ p case θ ( t ) ] ] ⊥ for al l t fr e e in σ . Then S [ [ Pc ase ( θ, σ )] ] ε = S [ [ p case θ ( σ ) ] ] ⊥ . Esp e cial ly f o r al l typ es σ we have: S [ [ Pc ase ([] , σ )] ] ⊥ = S [ [ p ca se σ ] ] ⊥ . Pro of: S [ [ Pc ase ( θ , σ )] ] ε ⊇ S [ [ p case θ ( σ ) ] ] ⊥ follows from the preceding lemma. No w let f = S [ [ Pc ase ( θ , σ )] ] ε . W e sho w f ⊆ S [ [ p case θ ( σ ) ] ] ⊥ b y structural induction on σ : • σ = t : f = ε ( θ ( t )) = S [ [ p case θ ( t ) ] ] ⊥ . • σ = τ + : W e sho w f c a b ⊆ p c ase c a b for all c ∈ D bo ol and a, b ∈ D θ ( σ ) . 1) c = ⊥ : F or a ∩ b = ⊥ it is f ⊥ a b = ⊥ . No w let a = 0 a ′ , b = 0 b ′ . f ⊥ (0 a ′ ) (0 b ′ ) = 0 ( ( S [ [ Pc ase ( θ , τ )] ] ε ) ⊥ a ′ b ′ ) ⊆ 0 ( p c as e ⊥ a ′ b ′ ) , b y induction hypothesis = p c ase ⊥ a b The case a = 1 a ′ , b = 1 b ′ is analogous. 2) c = 0 : F or a = ⊥ it is f 0 ⊥ b = ⊥ . No w let a = 0 a ′ . f 0 (0 a ′ ) b = 0 ( ( S [ [ Pc ase ( θ , τ ) ] ] ε ) 0 a ′ (( S [ [ out0 ] ] ⊥ ) b )) ⊆ 0 ( p c ase 0 a ′ (( S [ [ out0 ] ] ⊥ ) b )) , b y induction h yp othesis = p c ase 0 a b The case a = 1 a ′ is analogous. 3) c = 1 is analog o us to c = 0. • σ = τ × : F or all c ∈ D bo ol , a 1 , b 1 ∈ D θ ( τ ) and a 2 , b 2 ∈ D θ ( ) : f c ( p a ir a 1 a 2 ) ( p air b 1 b 2 ) = p air (( S [ [ Pc ase ( θ, τ )] ] ε ) c a 1 b 1 )(( S [ [ Pc ase ( θ , )] ] ε ) c a 2 b 2 ) ⊆ p air ( p c ase c a 1 b 1 ) ( p c ase c a 2 b 2 ) , b y induction h yp. = p c ase c ( p air a 1 a 2 ) ( p air b 1 b 2 ) • σ = τ → : F or all c ∈ D bo ol , a, b ∈ D θ ( σ ) and d ∈ D θ ( τ ) : f c a b d = ( S [ [ Pc ase ( θ , )] ] ε ) c ( a d ) ( b d ) ⊆ p c ase c ( a d ) ( b d ) , b y induction hypothesis = p c ase c a b d 8 CONCLUSION 52 • σ = µt.τ : f is the least fixed p oin t of g = |S [ [ λp. Pc ase ( θ [ t 7→ p ] , τ )] ] ε | . Let d = S [ [ p case θ ( σ ) ] ] ⊥ . Then g d = S [ [ Pc ase ( θ [ t 7→ p ] , τ )] ]( ε [ p 7→ d ]) ⊆ S [ [ p case ] ] ⊥ with = θ [ t 7→ p ]( τ ) ≈ θ ( σ ) , by induction hypothesis = d. Therefore f ⊆ d . • σ = void : T rivial. 8 Conclus ion W e hav e give n the syn ta x and reduc tion relation of a recursiv ely typed λ -calculus with a parallel conditional p case on all t yp es. The calculus w as prov ed to b e confluen t, with the aid of a general result on the confluence of the λ -calculus with algebraic term rewriting r ules. Our reduction relatio n simply defines the reduction of a redex in any con text. It remains to define a reduction s trategy that effectiv ely finds the normal form appro ximations of a term. Such a strategy cannot prescribe deterministically whic h redex to reduce, as w e hav e the para llel p case . Instead, it should giv e fo r ev ery term a set of its outermost redex es to b e reduced in the nex t reduction steps. Such a strategy could b e giv en for general algebraic term rewriting rules. W e unfolded the recursiv e t yp es to (p ossibly infinite) t yp e trees and interpreted these ty p e trees as prime systems. With this interpre tat io n of types, w e gav e a de- notational semantics of terms. The Appro ximation Theorem was the ke y result on the strength o f reduction with resp ect to the denotational seman tics: The semantic s of a term equals the limit of the semantics of its normal form approximations. F rom this follo w ed the adequacy of the seman t ics with respect to the observ ation of Bo olean v alues: If the seman tics of a program is 0 or 1, then the program reduc es to this v alue. F urthermore, w e sho w ed full abstraction of the seman tics. T o achiev e this, the syn tax m ust con tain a parallel function lik e p case or and . These f unctions are definable fro m eac h other, so a calculus with the same expre ssiv e p o w er could b e giv en with reduction rules for and instead of p case . The same expres siv e p ow er means that the same elemen ts of the seman tic mo del are definable in b oth calculi. The seman tic mo del corresp onds to the observ ation of Bo olean v alues, as w e hav e seen. There are other op erational, in tensional prop erties of the original p case that are not v alid f o r t he p case -function defined from and , e.g. the reduction p case 0 M N → ∗ M . The pro ofs o f confluence and of the Appro ximation Theorem w ould b e (sligh tly) easier fo r a calculus with and . Nev ertheless, w e preferred to mak e these in v estigations with a p case -calculus. Ac knowle dgemen ts: I thank Reinhold Heck mann for carefully reading a draft of this pap er. REFERENCES 53 References [A C90] R. M. Amadio and L. Cardelli. Subt yping recursiv e ty p es. Rep ort 62, Digital Systems Researc h Cen ter, 1990. [Bar84] H. P . Barendregt. The L amb da Calculus. Its Syntax and Semantics . North- Holland, revised edition, 1984 . [BC94] B. Blaab erg and C. Clausen. Adequacy for a lazy functional language with recursiv e and p olymorphic ty p es. The or etic al Comp uter Scien c e , 136 :2 43– 275, 1994. [Ber79] G. Berry . Mo d ` eles c o m pl ` etement ad´ equats et stables des lamb da-c alculs typ´ es . PhD thesis, Univ ersit ´ e Paris VI I, 1979 . [CC90] F. Cardone a nd M. Copp o. Tw o extensions of Curry’s t yp e inference system. In P . O difreddi, editor, L o gic an d c omputer scienc e , pages 19–7 5. Academic Press, 1990. [CC91] F. Cardone and M. C opp o . T yp e inference with recurs ive t yp es: Syn tax and seman tics. Information a nd C omputation , 92:4 8–80, 1991 . [Cos89] S. Cosmadakis. Computing with recursiv e t yp es. In Pr o c. L o gic in Computer Scienc e , pages 24– 3 8. IEEE, 1989. [Gun92] C. A. Gun ter. S e m antics of Pr o gr amming L anguages: Structur es and T e c h- niques . MIT Press, 1992 . [Hue80] G. Huet. Confluent reductions: Abstract prop erties and applications to term rewriting systems. J. o f the ACM , 27(4 ):797–821, 1980 . [L W91 ] K . G . Larsen and G. Winsk el. Using information systems t o solv e recursiv e domain equations. Information and C o mputation , 91:23 2–258, 1991. [MP87] P . D. Mosses and G . D . Plotkin. On pro ving limiting completeness. SIAM J. Comput. , 16:179– 1 94, 1987. [M ¨ ul92] F. M ¨ uller. Confluence of the lam b da calc ulus with left-linear algebraic rewrit- ing. I nformation Pr o c essing L etters , 41:2 93–299, 19 92. [NPW81] M. Nielsen, G. Plotkin, and G. Winsk el. Pe tri nets, ev en t structures and domains, part I. The or etic a l Computer Scienc e , 1 3 :85–108, 1 9 81. [Plo77] G. D. Plotkin. LCF considered as a pro g ramming langua ge. The or etic al Computer Scienc e , 5:223– 256, 1977. [Sto91] A. Stoughton. In terdefinabilit y o f parallel o p erations in PCF. T he or etic a l Computer Scienc e , 79:357 –358, 1991 . REFERENCES 54 [T oy88] Y. T o y ama. Commutativit y of term rewriting systems. In K. F uchi and L. K o tt, editors, Pr o gr amming of F utur e Gener ation C omputers II , pages 393–407. North-Ho lla nd, 1988 . [W ad78] C. P . W adsw orth. Approximate reduction and lambda calculus mo dels. SIAM J. Comput. , 7:337–3 56, 1978. [Win93] G. Winsk el. The F o rmal Semantics of Pr o gr amming L an guages . MIT Press, 1993.
Original Paper
Loading high-quality paper...
Comments & Academic Discussion
Loading comments...
Leave a Comment