The untyped stack calculus and Bohm's theorem
DD. Kesner and P. Viana (Eds.): LSFA 2012EPTCS 113, 2013, pp. 77–92, doi:10.4204/EPTCS.113.9 c (cid:13)
A. CarraroThis work is licensed under theCreative Commons Attribution License.
The untyped stack calculus and B ¨ohm’s theorem
Alberto Carraro
PPS, Universit´e Paris Diderot, France [email protected]
The stack calculus is a functional language in which is in a Curry-Howard correspondence withclassical logic. It enjoys confluence but, as well as Parigot’s λ µ , does not admit the B¨ohm Theorem,typical of the λ -calculus. We present a simple extension of stack calculus which is for the stackcalculus what Saurin’s Λ µ is for λ µ . In [3] Corrado B¨ohm proved the so-called
B¨ohm’s theorem , a fundamental syntactical feature of the pure λ -calculus which states that if M and N are two distinct β η -normal terms, then for each pair of terms P , Q there exists a context C [ · ] such that C [ M ] is β -equivalent to P and C [ N ] is β -equivalent to Q . If moreover M and N are closed, the context C [ · ] can have shape [ · ] (cid:126) L , for a suitable sequence (cid:126) L = L , . . . , L k of λ -terms.The original issue motivating this result was the quest for solutions of systems of equations between λ -terms: given closed λ -terms M , N , . . . , M n , N n , is there a λ -term S such that SM = β N ∧ · · · ∧ SM n = β N n holds? The answer is trivial for n = S = λ z . N for a fresh variable z ) and B¨ohm’s theoremgives a positive answer for n = M , M are distinct β η -normal forms (apply the theorem to M and M and then set S = λ f . f (cid:126) LN N ). The result has been then generalized (and this step is non-trivial)in [4] to treat every finite family M , . . . , M n of pairwise distinct β η -normal forms.The notion of operational equivalence has been a subject of many research works in the literature.Essentially one considers as “equivalent” two λ -terms M and N when for every possible context C [ · ] the head reduction process of C [ M ] halts iff the head reduction process of C [ N ] halts. It is common tothink of two non-operationally equivalent terms as programs that can be distinguished one another bymaking them interact with all possible environments, observing termination of head reduction. FromB¨ohm’s theorem it follows that given two distinct β η -normal forms one can choose a term P that admitsa head normal form and a term Q does not have a head normal form, having the guarantee that thereexists a context C [ · ] such that C [ M ] = β P and C [ N ] = β Q . In this sense M and N would be “separated”(or distinguished) by the context C [ · ] witnessing that M and N are not operationally equivalent. For thisreason B¨ohm’s theorem is also known as the separation theorem and it is said to prove the separationproperty for the untyped λ -calculus.The separation property has consequences both on the semantical and on the syntactical side. Forexample it implies that β η -equivalence is the maximal non-trivial congruence on normalizable terms ex-tending the β -equivalence, so that any model of the λ -calculus cannot identify two different β η -normalforms without being trivial. A possible reading of B¨ohm’s theorem is that the λ -calculus is powerfulenough to “inspect” itself and the syntax and the reduction rules fit each other well. Nonetheless B´ohm’sresult gives an alternative characterization of operational equivalence for normalizable terms. The com-plete characterization operational equivalence (also for non-normalizable terms) was then achieved byHyland [17] and Wadsworth [28]. In general two λ -terms are operationally equivalent iff they have thesame B¨ohm tree, up to possibly infinite η -expansion iff they have the same denotation in Scott’s D ∞ The untyped stack calculus and B¨ohm’s theorem model (see also [2]). B¨ohm’s proof shows how to produce the separating context with an algorithmwhose inputs are M , N ( β η -normal terms) P and Q (arbitrary terms). Following this observation Huet[16] shows an ML implementation of B¨ohm’s algorithm and poses the problem of formalizing a proofof B¨ohm’s theorem for the purpose of mechanical checking. The combinatorial core of B¨ohm’s algo-rithm is called the B¨ohm-out technique and it is at the basis of the implementation, presented in [6], ofthe CUCH-machine, a λ -calculus interpreter introduced by B¨ohm and Gross in [5]. Various general-izations/extensions of B¨ohm’s theorem have been studied. The λ -calculus has been immersed in otherlanguages in order to obtain finer observations on the behaviour of λ -terms. Sangiorgi [22] considers theencoding of the λ -calculus in the π -calculus with the addition of a unary non-deterministic operator. In[10] and [11] Dezani et al. add a binary parallel operator and a non-deterministic choice. Manzonettoand Pagani [19] give a proof of B¨ohm’s theorem for a resource-sensitive extension of the λ -calculus.Curry-Howard correspondence [15] was first stated as the isomorphism between natural deduction forminimal intuitionistic logic [21] and the simply typed λ -calculus. Later Griffin [13] proposed that naturaldeduction for classical logic could be viewed as a type system for a λ -calculus with a certain controloperator introduced by Felleisen [12]. Several other proposals have been made for a computationalinterpretation of classical logic, among which Parigot’s λ µ -calculus [20] received a lot of attention.In [8] David and Py proved that the λ µ -calculus does not satisfy the separation property. Saurin [23]exhibited an extension of λ µ -calculus, the Λ µ -calculus, in which the separation property does hold. In[7] the authors introduce the stack calculus, a finitary functional language in which the λ µ -calculus canbe faithfully translated.In the present paper we prove, using David and Py’s [8] counterexample, that the separation propertydoes not hold for the stack calculus, i.e., there are (extensionally) different normal forms which areoperationally equivalent. We introduce the extended stack calculus which is a calculus that contains thestack calculus (as Saurin’s Λ µ extends Parigot’s λ µ ). We show that operational equivalence is maximallyconsistent, i.e. it cannot be properly extended to another consistent equational theory both in the stackcalculus and in the extended stack calculus. We work out the details of a B¨ohm-out technique for theextended stack calculus. A nice feature of the extended stack calculus is that, having only one binder(instead of two as in λ µ ), it admits a simpler proof of B¨ohm’s theorem, which is similar to the one forthe λ -calculus.The treatment of B¨ohm’s theorem deserves a prominent place in classical monographs on the λ -calculus (Hindley–Seldin [26], Hankin [14], Barendregt [2]). Besides the applications of B¨ohm’s the-orem, there has always been interest around the proof itself and the algorithmic content of B¨ohm-outtechnique. In [9] Dezani et al. give a thorough account of B¨ohm’s theorem, together with an overviewof the impressive research activity which originated from it. To the best of our knowledge since Huet’schallenge [16], no mechanical proof of B¨ohm’s theorem has been produced yet. Instead Aehlig andJoachimski [1] provide a different proof of B¨ohm’s theorem that does not use the B¨ohm-out technique.In view of the interest in proofs of B¨ohm’s theorem for various calculi, we believe useful to contributein the present work with a direct proof of B¨ohm’s theorem (i.e. with a B¨ohm-out technique) for theextended stack calculus, even if the mere separation result would follow by a suitable mutual translationwith the Λ µ -calculus. We report the presentation of stack calculus from [7]. The language has three syntactic categories: terms that are in functional position, stacks that are in argument position and represent streams of arguments, . Carraro processes that are terms applied to stacks.The basis for the definition of the stack calculus language is a countably infinite set of stack variables ,ranged over by the initial small letters α , β , γ , . . . of the greek alphabet. The language is then given bythe following grammar:stacks π , ϖ :: = nil | α | cdr ( π ) | M (cid:5) π terms M , N :: = car ( π ) | µα . P processes P , Q :: = M (cid:63) π We use letters E , E (cid:48) to range over expressions which are either stacks, terms or processes. The operator µ is a binder. An occurrence of a variable α in an expression E is bound if it is under the scope of a µα ;the set FV ( E ) of free variables is made of those variables having a non-bound occurrence in E . Stacks represent lists of terms: nil is the empty stack. A stack M (cid:5) · · · (cid:5) M k (cid:5) nil , stands for a finite list whilea stack M (cid:5) · · · (cid:5) M k (cid:5) α stands for a non-terminated list that can be further extended. Terms are entities thatrepresent the “active part” of computations. A term µα . P is the µ -abstraction of α in P . Processes result from the application M (cid:63) π of a term M to a stack π . This application, unlike in the λ -calculus, has to be thought as exhaustive : an application of a stack to a term is an evolving entity thatdoes not have any outcome.As usual, the calculus involves a substitution operator. By E { π / α } we denote the substitution of thestack π for all free occurrences of α in E (paying attention to avoid capture of free variables). A basicbut useful fact about substitutions is the substitution lemma (see [7]): for all E ∈ Σ e and all π , ϖ ∈ Σ s with α (cid:54)∈ FV ( ϖ ) and α (cid:54)≡ β we have E { π / α }{ ϖ / β } ≡ E { ϖ / β }{ π { ϖ / β } / α } (the symbol ‘ ≡ ’ standsfor syntactic equality).The reduction rules characterizing the stack calculus are the following ones: ( µ ) ( µα . P ) (cid:63) π → µ P { π / α } ( car ) car ( M (cid:5) π ) → car M ( cdr ) cdr ( M (cid:5) π ) → cdr π Adding the following rules we obtain the extensional stack calculus: ( η ) µα . M (cid:63) α → η M if α (cid:54)∈ FV ( M )( η ) car ( π ) (cid:5) cdr ( π ) → η π We simply write → s for the contextual closure of the relation ( → µ ∪ → car ∪ → cdr ) . Moreover wewrite → η for the contextual closure of the relation ( → η ∪ → η ) and finally we set → s η = ( → s ∪ → η ) .We denote by (cid:16) s (resp. (cid:16) s η ) the reflexive and transitive closure of → s (resp. → s η ) and we denote by = s (resp. = s η ) the reflexive, symmetric, and transitive closure of → s (resp. → s η ).An example of term is I : = µα . car ( α ) (cid:63) cdr ( α ) (the symbol ‘: = ’ stands for definitional equality).For example I (cid:63) I (cid:5) nil → s I (cid:63) nil → s car ( nil ) (cid:63) cdr ( nil ) and the reduction does not proceed further. If ω : = µα . car ( α ) (cid:63) α , then ω (cid:63) ω (cid:5) nil → s ω (cid:63) ω (cid:5) nil ; this is an example of a non-normalizing process. Thestack calculus enjoys confluence, even in its extensional version, as stated in the following theorem. Theorem 2.1 ([7]) . The reductions → s and → s η are both Church-Rosser. It seems natural to define a meta-language with constructions π [ n ) : = cdr ( · · · cdr ( π ) · · · ) ( n times)and π [ n ] : = car ( π [ n )) . It is easily checkable that every expression E has a (cid:16) car , cdr -normal form, that wewill refer to as the canonical form of E . If (cid:126) N = N , . . . , N m is a sequence of terms, we write (cid:126) N (cid:5) γ [ k ) and (cid:126) N (cid:5) nil [ k ) for the obvious corresponding stacks. In an expression in canonical form the stacks have eithershape (cid:126) N (cid:5) γ [ k ) or (cid:126) N (cid:5) nil [ k ) and the non-abstraction terms have shape either α [ n ] or nil [ n ] .0 The untyped stack calculus and B¨ohm’s theorem
We provide a notion of outer reduction for the stack calculus, obtained by performing the contraction ofouter-most redexes only. The one-step outer-reduction on terms is given by the following rule: M → o µα . P { π / β } if µα . ( µβ . P ) (cid:63) π is the canonical form of M Note that outer-reduction is deterministic and we don’t take any contextual closure for → o ; its re-flexive and transitive closure is denoted by (cid:16) o . A term M is in outer-normal form ( onf , for short) if it isnot → o -reducible. It is straightforward to see that a term is in onf iff it has the form µα . H (cid:63) (cid:126) N (cid:5) τ , wherethe terms in the sequence (cid:126) N are arbitrary, H is either β [ n ] (in which case we say that the onf is proper )or nil [ n ] (in which case we say that the onf is improper ) and τ is either γ [ n ) or nil [ n ) ; H is the head of theonf and τ is the tail of the onf in question. A term has a onf if it (cid:16) o -reduces to a term in onf. Of coursethe outer reduction strategy is complete for finding onf’s of terms, i.e., if M (cid:16) s -reduces to a term N (cid:48) inonf, then M reduces to some onf N (cid:48)(cid:48) via outer reduction.A head context is a context generated by the grammar C [ · ] :: = [ · ] | µα . C [ · ] (cid:63) π . Definition 2.1 (Operational equivalence) . Two terms M , N are operationally equivalent , notation M ≈ N,if for every head context C [ · ] we have that C [ M ] has a proper onf iff C [ N ] has a proper onf. Operational equivalence is a fairly common notion. In Definition 2.1 we only quantify over headcontexts, but it can be shown (as it is done for the λ -calculus [2] and the λ µ -calculus [8]) that a quan-tification over all contexts gives as equivalent definition.We now define some important terms: T : = µα . α [ ] (cid:63) α [ ) , F : = µα . α [ ] (cid:63) α [ ) , and Ω : = µγ . ω (cid:63) ω (cid:5) γ , where ω : = µα . α [ ] (cid:63) α . Clearly Ω is an example of term without onf and we have nil [ ] ≈ Ω (cid:54)≈ T (cid:54)≈ F .We conclude the first part of the paper showing that in the stack calculus there exist different → s η -normal forms which are operationally equivalent. This situation is in contrast with the λ -calculus: theoriginal B¨ohm’s theorem [3] implies that two different β η -normal λ -terms M and N are never opera-tionally equivalent because there exists a context C [ · ] such that C [ M ] has a head normal form and C [ N ] does not have a head normal form. However an analogous situation occurs for the λ µ -calculus: Davidand Py [8] exhibited two extentionally different normal λ µ -terms which are operationally equivalent. Infact the counterexample given in the next theorem is obtained by translating David and Py’s terms intothe stack calculus. Theorem 2.2.
Let U : = µγ . α [ ] (cid:63) α and W [ · ] : = µα . α [ ] (cid:63) ( µβ . α [ ] (cid:63) U (cid:5) [ · ] (cid:5) α ) (cid:5) U (cid:5) α . Then for all termsM , N we have W [ M ] ≈ W [ N ] .Proof. Let M be a term and let C [ · ] : = µδ . ( µδ . · · · ( µδ m . [ · ] (cid:63) π ) (cid:63) π m · · · ) (cid:63) π be a term context. Let M (cid:48) : = M { π / δ } · · · { π m / δ m } π (cid:48) : = π { π / δ } · · · { π m / δ m } U (cid:48) : = U { π (cid:48) / α } π (cid:48)(cid:48) : = ( µβ . π (cid:48) [ ] (cid:63) U (cid:48) (cid:5) M (cid:48) (cid:5) π (cid:48) ) (cid:5) U (cid:48) (cid:5) π (cid:48) Then C [ W [ M ]] (cid:16) o µδ . π (cid:48) [ ] (cid:63) π (cid:48)(cid:48) . At this point we distinguish six possible cases:(1) π (cid:48) [ ] is not an abstraction;(2) π (cid:48) [ ] ≡ µε . nil [ n ] (cid:63) ϖ ;(3) π (cid:48) [ ] ≡ µε . ε (cid:48) [ n ] (cid:63) ϖ , with ε (cid:54)≡ ε (cid:48) ;(4) π (cid:48) [ ] ≡ µε . ε [ ] (cid:63) ϖ ;(5) π (cid:48) [ ] ≡ µε . ε [ ] (cid:63) ϖ ; . Carraro π (cid:48) [ ] ≡ µε . ε [ n ] (cid:63) ϖ , with n ≥ C [ W [ M ]] proceeds as:(1) . . . (cid:16) o µδ . π (cid:48) [ ] (cid:63) π (cid:48)(cid:48) (cid:54)→ o .(2) . . . (cid:16) o µδ . nil [ n ] (cid:63) ϖ { π (cid:48)(cid:48) / ε } (cid:54)→ o .(3) . . . (cid:16) o µδ . ε (cid:48) [ n ] (cid:63) ϖ { π (cid:48)(cid:48) / ε } (cid:54)→ o .(4) . . . (cid:16) o µδ . ( µε . ε [ ] (cid:63) ϖ ) (cid:63) π (cid:48)(cid:48) (cid:16) o µδ . π (cid:48) [ ] (cid:63) π (cid:48) .(5) . . . (cid:16) o µδ . ( µε . ε [ ] (cid:63) ϖ ) (cid:63) π (cid:48)(cid:48) (cid:16) o µδ . π (cid:48) [ ] (cid:63) π (cid:48) .(6) . . . (cid:16) o µδ . ( µε . ε [ n ] (cid:63) ϖ ) (cid:63) π (cid:48)(cid:48) (cid:16) o µδ . π (cid:48) [ n − ] (cid:63) ϖ { π (cid:48)(cid:48) / ε } .Suppose C [ W [ M ]] has a proper onf, say, Z . In each of the above cases there is no step in the outerreduction path C [ W [ M ]] (cid:16) o Z such that a substitution instance of the occurrence of M put into the holeis active part of a contracted redex. Therefore an isomorphic outer-reduction path takes any other term C [ W [ N ]] to its onf, which must be proper too. Failure of B¨ohm’s Theorem.
Theorem 2.2 implies that B¨ohm’s theorem fails (and quite violently)in the stack calculus. Every pair M , N of distinct → s η -normal forms yields a pair W [ M ] , W [ N ] of distinct → s η -normal forms which are operationally equivalent.A stack-theory (resp. extensional stack-theory ) for the stack calculus is any set T of equalities be-tween stack-expressions containing = s (resp. = s η ) and closed under context formation and replacementof T -equal sub-expressions. We indicate by = T the congruence associated to the theory T .A stack-theory T is inconsistent if for every pair of terms M , N and every variable γ (cid:54)∈ FV ( M ) ∪ FV ( N ) we have that µγ . M (cid:63) γ = T µγ . N (cid:63) γ ; T is consistent otherwise. Since there are distinct → s η -normal forms, Theorem 3.1 implies that = s and = s η are consistent equational theories, of which = s η is extensional. Also the relation ≈ is an extensional equational theory which is consistent, because forexample T (cid:54)≈ Ω .A theory is Hilbert–Post complete (HP-complete, for short) if it is maximally consistent (cannotbe properly extended to a consistent theory). The next theorem shows that operational equivalence ismaximally consistent.
Theorem 2.3.
The relation ≈ is an HP-complete equational theory for the stack calculus.Proof. The relation ≈ is indeed an equational theory for the stack calculus, because it is closed w.r.t.context formation. Suppose, by contradiction, that T is a consistent theory that contains ≈ properlyand let M , N be terms such that M (cid:54)≈ N and M = T N .Then there exists a head context C [ · ] such that,say, C [ M ] has a proper onf and C [ N ] does not have a proper onf. Assume C [ M ] = s µα . β [ n ] (cid:63) (cid:126) N (cid:5) γ [ k ) and define the context C (cid:48) [ · ] : = µε . ( µβ . [ · ] (cid:63) α ) (cid:63) I (cid:5) . . . (cid:5) I (cid:124) (cid:123)(cid:122) (cid:125) n (cid:5) ( µδ . I (cid:63) ε ) (cid:5) ε . Then C (cid:48) [ C [ M ]] = s I . On the otherhand C (cid:48) [ C [ N ]] cannot have a proper onf. Let u : = µ x . f [ ] (cid:63) ( µβ . x [ ] (cid:63) x [ ] (cid:5) β ) (cid:5) x [ ) , U : = µγ . u (cid:63) u (cid:5) γ and Y : = µ f . U (cid:63) f [ ) . Finally set T ∞ : = µδ . Y (cid:63) T (cid:5) δ .Since T ∞ does not have an onf we have C (cid:48) [ C [ N ]] ≈ T ∞ and from I = s C (cid:48) [ C [ M ]] = T C (cid:48) [ C [ N ]] and thefact that the congruence = T extends both = s and ≈ , we get that I = T T ∞ . Now take an arbitrary term Z and a variable γ (cid:54)∈ FV ( Z ) . We have µγ . Z (cid:63) γ = s µγ . I (cid:63) Z (cid:5) γ = T µγ . T ∞ (cid:63) Z (cid:5) γ = s T ∞ . Since the congruence = T extends both = s and ≈ , we can conclude that µγ . Z (cid:63) γ = T µγ . Z (cid:48) (cid:63) γ for all terms Z , Z (cid:48) and everyvariable γ (cid:54)∈ FV ( Z ) ∪ FV ( Z (cid:48) ) . Therefore T is inconsistent.2 The untyped stack calculus and B¨ohm’s theorem
The extended stack calculus is a super-language of the stack calculus. Formally, it is obtained by incor-porating the syntactic category of processes into that of terms. Therefore the grammar for the extendedlanguage is the following one:stacks π , ϖ :: = nil | α | cdr ( π ) | M (cid:5) π terms M , N :: = car ( π ) | µα . M | M (cid:63) π We still use letters E , E (cid:48) to range over expressions which are either stacks or terms. An exampleof term which belongs to the extended language but not to the original one is µβ . µα . car ( α ) (cid:63) cdr ( α ) .Application associates to the left, so that M (cid:63) π (cid:63) ϖ stands for ( M (cid:63) π ) (cid:63) ϖ and application has precedenceover µ -abstraction. If (cid:126) π = π , . . . , π m and (cid:126) α = α , . . . , α n , we shall abbreviate the term µα . . . µα n . ( M (cid:63) π (cid:63) · · · (cid:63) π m ) as µ (cid:126) α . M (cid:63)(cid:126) π . We denote by Σ t , Σ s and Σ e the sets of all terms, stacks and expressions respec-tively. We still use → s , → s η , = s and = s η to indicate the straightforward extensions of the correspondingrelations defined for the stack calculus. Also the notion of canonical form extends straightforwardly tothe extended stack calculus. Theorem 3.1.
The reductions → s and → s η in the extended stack calculus are both Church-Rosser. The proof of Theorem 3.1 is an easy modification of that of Theorem 2.1 (see [7]).Also the definitions of (consistent) equational theories and HP-completeness extend straightfor-wardly to the larger calculus and once again Theorem 3.1 guarantees the consistency of the theories = s and = s η .In this paper we are not concerned with semantics. We just mention that the works of Streicherand Reus [27] and Nakazawa and Katsumata [18] already provide sound models for the extended stackcalculus, which are the same as those for the Λ µ -calculus. We now provide a notion of head-reduction for the stack calculus, which is performed by contracting theleft-most redex only. The one-step head-reduction on terms is given by the following rule: M → h µ (cid:126) α . N { ϖ / β } (cid:63)(cid:126) π if µ (cid:126) α . ( µβ . N ) (cid:63) ϖ (cid:63)(cid:126) π is the canonical form of M Note that head-reduction is deterministic and we don’t take any contextual closure for → h ; its reflex-ive and transitive closure is denoted by (cid:16) h . A term M is in head-normal form ( hnf , for short) if it is not → h -reducible. It is straightforward to see that a term is in hnf iff it has the form µ (cid:126) α . H (cid:63) (cid:126) π , where thestacks in the sequence (cid:126) π are arbitrary, H is either β [ n ] (in which case we say that the hnf is proper ) or nil [ n ] (in which case we say that the hnf is improper ); H is the head of the hnf in question. A term has ahnf if it (cid:16) h -reduces to a term in hnf. Of course the head-reduction strategy is complete for finding hnf’sof terms, i.e., if M (cid:16) s -reduces to a term N (cid:48) in hnf, then M reduces to some hnf N (cid:48)(cid:48) via head-reduction.For convenience we define a partial function Hnf ( · ) : Σ t (cid:42) Σ t which returns the → h -normal form ofa term, if it exists.The head contexts of the extended stack calculus are produced by the following grammar: C [ · ] :: = [ · ] | C [ · ] (cid:63) π | µα . C [ · ] The next definition is the analogue of Definition 2.1 for the extended stack calculus. . Carraro Definition 3.1 (Operational equivalence (extended)) . Two terms M , N are operationally equivalent , no-tation M ≈ N, if for every head context C [ · ] we have that C [ M ] has a proper hnf iff C [ N ] has a properhnf. We use the same symbol as in Definition 2.1 because there will be no ambiguity: from now on weare only concerned with the extended stack calculus. The relation ≈ is a consistent extensional theorywhich is HP-complete, because the proof of Theorem 2.3 works also for the larger calculus. Theorem 3.2.
The relation ≈ is an HP-complete equational theory for the extended stack calculus. The following definition introduces an important concept, somewhat orthogonal to operational equiva-lence, which is very typical of functional calculi (as the λ -calculus). Definition 3.2 (Separability) . We say that M and N are separable if there exists a head context C [ · ] suchthat C [ M ] = s T and C [ N ] = s F . The following theorem says that separability and operational equivalence are somewhat orthogonalto each other.
Theorem 3.3.
If M and N are separable, then M (cid:54)≈
N.Proof.
Suppose M , N separable. Then there exists a context C [ · ] such that C [ M ] = s T and C [ N ] = s F andsetting C (cid:48) [ · ] : = µε . C [ · ] (cid:63) Ω (cid:5) I (cid:5) ε we obtain that C (cid:48) [ M ] = s Ω and C (cid:48) [ N ] = s I , thus showing that M (cid:54)≈ N .The converse of Theorem 3.3 does not hold. For example Ω (cid:54)≈ I but it is also true that Ω and I arenot separable. In fact if a term M does not have a hnf, then C [ M ] does not have a hnf too for every headcontext C [ · ] . This means that for no head context C [ · ] we can have C [ Ω ] = s T (or C [ Ω ] = s F ).Next we introduce the notion of similarity between stacks and terms which, for terms having an hnf,is weaker than inseparability. Definition 3.3 (Similarity for stacks) . We define the similarity relation s ∼ on Σ s as the smallest equiva-lence relation closed under = s satisfying the following conditions:(1) π s ∼ M (cid:5) . . . (cid:5) M m (cid:5) nil [ k ) (2) if k − m = k (cid:48) − m (cid:48) , then M (cid:5) . . . (cid:5) M m (cid:5) γ [ k ) s ∼ N (cid:5) . . . (cid:5) N m (cid:48) (cid:5) γ [ k (cid:48) ) Definition 3.4 (Similarity for terms) . We define the similarity relation ∼ on Σ t as the smallest equiva-lence relation closed under = s satisfying the following conditions:(1) if k − m = k (cid:48) − m (cid:48) , π i s ∼ ϖ i for all i = , . . . , min { m , m (cid:48) } , and ϖ min { m , m (cid:48) } + j s ∼ α min { k , k (cid:48) } + j for all j = , . . . , ( max { k , k (cid:48) } − min { k , k (cid:48) } ) then µα . . . α k . β [ n ] (cid:63) π (cid:63) · · · (cid:63) π m ∼ µα . . . α k (cid:48) . β [ n ] (cid:63) ϖ (cid:63) · · · (cid:63) ϖ m (cid:48) (2) if Hnf ( M ) and Hnf ( N ) are both defined and improper, then M ∼ N(3) if
Hnf ( M ) and Hnf ( N ) are both undefined, then M ∼ N The following theorems show that dissimilarity of terms having a hnf implies their separability. Westart by treating a particular case, which is nevertheless non-trivial.It will occur frequently to use stacks of the form n (cid:122) (cid:125)(cid:124) (cid:123) M (cid:5) . . . (cid:5) M (cid:5) π . Therefore we set the special notation M n (cid:5) π for these stacks.4 The untyped stack calculus and B¨ohm’s theorem
Theorem 3.4.
Let M ≡ µα . β [ n ] (cid:63) π and N ≡ µα . β (cid:48) [ n (cid:48) ] (cid:63) π (cid:48) . If M (cid:54)∼ N, then M and N are separable.Proof.
Assume M (cid:54)∼ N . We analyze the different reasons for this fact and each time we build a context C [ · ] such that C [ M ] = s T and C [ N ] = s F . In the rest of the proof we let ε be a fresh variable. Since M and N are not similar, we have the following possible cases: (1) β (cid:54)≡ β (cid:48) ; (2) β ≡ β (cid:48) but n (cid:54) = n (cid:48) ; (3) β ≡ β (cid:48) , n = n (cid:48) but π (cid:54) s ∼ π (cid:48) . (1) Define π : = I n (cid:5) ( µδ . T (cid:63) ε ) (cid:5) ε , where δ (cid:54)≡ ε , π (cid:48) : = I n (cid:48) (cid:5) ( µδ . F (cid:63) ε ) (cid:5) ε , where δ (cid:54)≡ ε , and C [ · ] : = µε . ( µβ (cid:48) . ( µβ . [ · ] (cid:63) α ) (cid:63) π ) (cid:63) π (cid:48) . Then C [ M ] = s T and C [ N ] = s F . (2) We can assume w.l.o.g. that n > n (cid:48) since the opposite case can be treated symmetrically. Define π : = I n (cid:48) (cid:5) ( µδ . F (cid:63) ε ) (cid:5) I n − n (cid:48) − (cid:5) ( µδ . T (cid:63) ε ) (cid:5) ε , where δ (cid:54)≡ ε , and C [ · ] : = µε . ( µβ . [ · ] (cid:63) α ) (cid:63) π . Then C [ M ] = s T and C [ N ] = s F .In order to treat case (3) , we need to explicit the possible forms of π and π (cid:48) . By assumption theresome are terms M , . . . , M m , N , . . . , N m (cid:48) and numbers k , k (cid:48) ∈ N such that: • M ≡ µα . β [ n ] (cid:63) M (cid:5) . . . (cid:5) M m (cid:5) γ [ k ) • N ≡ µα . β (cid:48) [ n (cid:48) ] (cid:63) N (cid:5) . . . (cid:5) N m (cid:48) (cid:5) γ (cid:48) [ k (cid:48) ) Case (3) can be exhaustively splitted in the following sub-cases: (3.1) β ≡ β (cid:48) , n = n (cid:48) but γ (cid:54)≡ γ (cid:48) (no assumptions on m , k , m (cid:48) , k (cid:48) ) and (3.1.1) γ (cid:54)≡ β ; (3.1.2) γ ≡ β . (3.2) β ≡ β (cid:48) , n = n (cid:48) , γ ≡ γ (cid:48) but m − k (cid:54) = m (cid:48) − k (cid:48) and (3.2.1) γ (cid:54)≡ β ; (3.2.2) γ ≡ β .We now show how to reduce the cases (3.1.1), (3.1.2) and (3.2.1) to the case (3.2.2), for which weshow how to build the separating context. (3.1.1) If γ (cid:48) ≡ β , then case (3.1.2) applies (changing the roles of γ and γ (cid:48) ). If γ (cid:48) (cid:54)≡ β , then define C [ · ] : = µα . ( µγ . [ · ] (cid:63) α ) (cid:63) β . Now case (3.1.2) applies to C [ M ] and C [ N ] . (3.1.2) Define C [ · ] : = µα . ( µγ (cid:48) . [ · ] (cid:63) α ) (cid:63) γ (cid:48) [ m (cid:48) + m + k + ) . Now case (3.2.2) applies to C [ M ] and C [ N ] . (3.2.1) Define C [ · ] : = µα . ( µγ . [ · ] (cid:63) α ) (cid:63) β . Now case (3.2.2) applies to C [ M ] and C [ N ] . (3.2.2) Let ∂ m = | m − m (cid:48) | , ∂ k = | k − k (cid:48) | , d = ∂ k + ∂ m , and e = min { ∂ k , ∂ m } . Note that m − k = m (cid:48) − k (cid:48) if, and only if, m − m (cid:48) = k − k (cid:48) . Therefore, under the hypothesis of this case, m − m (cid:48) (cid:54) = k − k (cid:48) and d > X : = (cid:40) µδ . δ [ ] (cid:63) ε [ ) if k < k (cid:48) µδ . δ [ e ] (cid:63) ε [ ) if k ≥ k (cid:48) . Carraro π : = I n (cid:5) ( µδ . X (cid:63) δ [ n + + max { m , m (cid:48) } )) (cid:5) ε [ ] ∂ m + max { k , k (cid:48) } (cid:5) ε [ ] (cid:5) ε and C [ · ] : = µε . ( µβ . [ · ] (cid:63) α ) (cid:63) π . We can assume w.l.o.g. that m ≥ m (cid:48) (the other case can be treated symmetri-cally) so that we have C [ M ] = s (cid:40) µε . X (cid:63) ε [ ] d (cid:5) ε [ ] (cid:5) ε if k < k (cid:48) µε . X (cid:63) ε [ ] ∂ m (cid:5) ε [ ] (cid:5) ε if k ≥ k (cid:48) and C [ N ] = s (cid:40) µε . X (cid:63) ε [ ] (cid:5) ε if k < k (cid:48) µε . X (cid:63) ε [ ] ∂ k (cid:5) ε [ ] (cid:5) ε if k ≥ k (cid:48) Concluding the computation we obtain C [ M ] = s (cid:40) F if k < k (cid:48) T if k ≥ k (cid:48) and C [ N ] = s (cid:40) T if k < k (cid:48) F if k ≥ k (cid:48) Now we can now prove the following more general statement.
Theorem 3.5.
Let M , N be terms having a proper hnf. Then M (cid:54)∼
N implies that M and N are separable.Proof.
Suppose M and N be terms with a proper hnf and assume M (cid:54)∼ N . We analyze the different casesin which M (cid:54)∼ N and each time we build a context C [ · ] such that C [ M ] = s T and C [ N ] = s F . Since M , N both have a hnf, let’s say we have • Hnf ( M ) = µα . . . α k . β [ n ] (cid:63) π (cid:63) · · · (cid:63) π m • Hnf ( N ) = µα . . . α k (cid:48) . β (cid:48) [ n (cid:48) ] (cid:63) ϖ (cid:63) · · · (cid:63) ϖ m (cid:48) In the rest of the proof we let ε be a fresh variable and we suppose, w.l.o.g. that k (cid:48) ≥ k . Since M and N are not similar, we have the following possible cases: (1) β (cid:54)≡ β (cid:48) ; (2) β ≡ β (cid:48) but n (cid:54) = n (cid:48) ; (3) β ≡ β (cid:48) , n = n (cid:48) but m − k (cid:54) = m (cid:48) − k (cid:48) ; (4) β ≡ β (cid:48) , n = n (cid:48) , m − k = m (cid:48) − k (cid:48) but there is some i = , . . . , m such that π i (cid:54) s ∼ ϖ i (note that m (cid:48) ≥ m ); (5) β ≡ β (cid:48) , n = n (cid:48) , m − k = m (cid:48) − k (cid:48) , π i s ∼ ϖ i for all i = , . . . , m but there is some j = , . . . , k (cid:48) − k suchthat ϖ m + j (cid:54) s ∼ α k + j (note that m (cid:48) ≥ m ).We now show how to build in each case a separating context. (1) Define π : = I n (cid:5) ( µδ . . . δ m α k + . . . α k (cid:48) . T ) (cid:5) ε , π (cid:48) : = I n (cid:48) (cid:5) ( µδ . . . δ m (cid:48) . F ) (cid:5) ε , and C [ · ] : = ( µβ β (cid:48) . [ · ] (cid:63) α (cid:63) · · · (cid:63) α k (cid:48) ) (cid:63) π (cid:63) π (cid:48) . Then C [ M ] = s T and C [ N ] = s F . (2) Suppose that n (cid:48) > n (all other cases can be treated similarly). Define π : = I n (cid:5) ( µδ . . . δ m α k + . . . α k (cid:48) . T ) (cid:5) I n (cid:48) − n − (cid:5) ( µδ . . . δ m (cid:48) . F ) (cid:5) ε and C [ · ] : = ( µβ . [ · ] (cid:63) α (cid:63) · · · (cid:63) α k (cid:48) ) (cid:63) π . Then C [ M ] = s T and C [ N ] = s F . (3) Note that, having assumed m − k (cid:54) = m (cid:48) − k (cid:48) , we have m + k (cid:48) − k (cid:54) = m (cid:48) . Suppose m + k (cid:48) − k > m (cid:48) (theopposite case can be treated similarly). Now let p = m + k (cid:48) − k , h = p − m (cid:48) and define π : = I n (cid:5) ( µα . . . α p + . α p + [ ]) (cid:5) ε , C [ · ] : = ( µβ . [ · ] (cid:63) α (cid:63) · · · (cid:63) α k (cid:48) (cid:63) δ (cid:63) ε (cid:63) · · · (cid:63) ε h ) (cid:63) π , and C (cid:48) [ · ] : = ( µδ ε h . [ · ]) (cid:63) (( µα . . . α h . T ) (cid:5) ε ) (cid:63) ( F (cid:5) ε ) . Then C (cid:48) [ C [ M ]] = s T and C (cid:48) [ C [ N ]] = s F .6 The untyped stack calculus and B¨ohm’s theorem (4)
Define X : = µα . . . α m (cid:48) β (cid:48)(cid:48) . β (cid:48)(cid:48) [ ] (cid:63) α i , π (cid:48) : = I n (cid:5) X (cid:5) ε , and C [ · ] : = ( µβ . [ · ] (cid:63) α (cid:63) · · · (cid:63) α k (cid:48) ) (cid:63) π (cid:48) . Then wehave C [ M ] = s µβ (cid:48)(cid:48) . β (cid:48)(cid:48) [ ] (cid:63) π i { π (cid:48) / β } and C [ N ] = s µβ (cid:48)(cid:48) . β (cid:48)(cid:48) [ ] (cid:63) ϖ i { π (cid:48) / β } Finally since π i (cid:54) s ∼ ϖ i and (cid:54) s ∼ is closed under substitution, we also have π i { π (cid:48) / β } (cid:54) s ∼ ϖ i { π (cid:48) / β } , whichin turn implies C [ M ] (cid:54)∼ C [ N ] . At this point we can apply Theorem 3.4 to show that C [ M ] and C [ N ] areseparable, and hence M and N are separable. (5) Define X : = µα . . . α m (cid:48) β (cid:48)(cid:48) . β (cid:48)(cid:48) [ ] (cid:63) α m + j , π (cid:48) : = I n (cid:5) X (cid:5) ε , and C [ · ] : = ( µβ . [ · ] (cid:63) α (cid:63) · · · (cid:63) α k (cid:48) ) (cid:63) π (cid:48) . Thenwe have C [ M ] = s µβ (cid:48)(cid:48) . β (cid:48)(cid:48) [ ] (cid:63) α k + j { π (cid:48) / β } and C [ N ] = s µβ (cid:48)(cid:48) . β (cid:48)(cid:48) [ ] (cid:63) ϖ m + j { π (cid:48) / β } Finally since ϖ m + j (cid:54) s ∼ α k + j and (cid:54) s ∼ is closed under substitution, we also have ϖ m + j { π (cid:48) / β } (cid:54) s ∼ α k + j { π (cid:48) / β } ,which in turn implies C [ M ] (cid:54)∼ C [ N ] . At this point we can apply Theorem 3.4 to show that C [ M ] and C [ N ] are separable, and hence M and N are separable.The converse of Theorem 3.5 does not hold; for example µγ . γ [ ] (cid:63) T (cid:5) γ and µγ . γ [ ] (cid:63) F (cid:5) γ are separablebut it is also true that µγ . γ [ ] (cid:63) T (cid:5) γ ∼ µγ . γ [ ] (cid:63) F (cid:5) γ . The point is that the relation ∼ only looks at the“surface” of terms, while separation may require to unravel terms by iteratively computing head normalforms, i.e., looking at their B¨ohm trees. As for the λ -calculus, B¨ohm trees can be defined for stack terms too. While the nodes of B¨ohm trees of λ -terms are indexed by sequences of natural numbers, the nodes of B¨ohm trees of stack terms should beindexed by sequences of pairs of natural numbers. The reason for this choice is that a child of the nodecorresponding to a hnf µ (cid:126) α . β [ n ] (cid:63)(cid:126) π must be selected with two coordinates ( j , j (cid:48) ) , saying that the child isthe root of the B¨ohm tree of the j (cid:48) -th term of the canonical form of the stack π j .The B¨ohm trees for the λ -calculus (see [2, § ⊥ or to a λ -term o shape λ (cid:126) x . y . We will still speak of B¨ohm treesfor the extended stack calculus, but strictly speaking we mean partial functions mapping pairs of naturalnumbers to non-necessarily normal terms, called nodes . Letters σ , τ , ρ , . . . range over the set Seq of allfinite sequences of pairs of strictly positive natural numbers. We define the order < on these sequencesas follows: τ < σ iff τ is a proper prefix of σ . We denote by (cid:93) σ the length of the sequence σ .Moreoverif (cid:126) N is a sequence of terms, then (cid:93)(cid:126) N indicates the lenght of (cid:126) N . Definition 3.5.
Given a term M we define a partial map M ( · ) : Seq (cid:42) Σ t as follows:M ( σ ) : = M if σ is the empty sequenceM ( τ · ( j , j (cid:48) )) : = N j (cid:48) if M ( τ ) is defined, Hnf ( M ( τ )) = µ (cid:126) α . β [ n ] (cid:63) π (cid:63) · · · (cid:63) π m andj ≤ m and π j has canonical form (cid:126) N (cid:5) γ [ k ) or (cid:126) N (cid:5) nil [ k ) , with j (cid:48) ≤ (cid:93)(cid:126) Nundefined otherwise
The map M ( · ) : Seq (cid:42) Σ t for us is the B¨ohm tree of M . We let dom ( M ) = { σ ∈ Seq : M ( σ ) is defined } .In the present section we prove a theorem which is the analogue of B¨ohm’s Theorem for λ -calculus.Such theorem is supported fundamentally by the forthcoming Lemma 3.7 (analogous to what is called . Carraro λ -calculus [2, § dom ( M , n ) = { σ ∈ dom ( M ) : (cid:93) σ ≤ n } . Thefollowing definitions 3.6, 3.7 and 3.8 are all auxiliary for the statement and proof of the subsequentLemma 3.6. Definition 3.6.
We define the breadth b ( M ) and the weight w ( M ) of M ∈ Σ t as b ( M ) = if Hnf ( M ) is undefined if Hnf ( M ) is defined but improperm if Hnf ( M ) = µ (cid:126) α . β [ n ] (cid:63) π (cid:63) · · · (cid:63) π m w ( M ) = if Hnf ( M ) is undefined if Hnf ( M ) is defined but impropern if Hnf ( M ) = µ (cid:126) α . β [ n ] (cid:63) π (cid:63) · · · (cid:63) π m Definition 3.7.
The n- bounded breadth b ( M , n ) and the n- bounded weight w ( M , n ) of a term M are de-fined as b ( M , n ) = max { b ( M ( σ )) : σ ∈ dom ( M , n ) } and w ( M , n ) = max { w ( M ( σ )) : σ ∈ dom ( M , n ) } ,respectively. Definition 3.8.
Let q , p be natural numbers. We define the expressions A ( q ) : = µε . . . ε q δ . δ [ ] (cid:63) ε (cid:63) · · · (cid:63) ε q π ( ε , q , p ) : = A ( q ) (cid:5) . . . (cid:5) A ( q ) (cid:124) (cid:123)(cid:122) (cid:125) p times (cid:5) ε Clearly by the common conventions about bound variables, in the above definition ε , . . . , ε q , δ areall distinct from each other and from ε .The next lemma is the combinatorial core of the forthcoming Lemma 3.7, and is the analogue forthe extended stack calculus of what is called the B¨ohm-out technique for the λ -calculus (see [2, § σ = ( j , j (cid:48) ) · · · ( j l , j (cid:48) l ) and a natural number i ≤ l we indicate with σ (cid:22) i the sequence ( j , j (cid:48) ) · · · ( j i , j (cid:48) i ) (so for example σ (cid:22) Lemma 3.6 (B¨ohm out) . Let M be a term, let n a natural number and let q ≥ b ( M , n ) , p ≥ w ( M , n ) .Then for every sequence σ ∈ dom ( M , n ) there exists a context C [ · ] such thatC [ M ] (cid:16) s M ( σ ) { π ( ε , q , p ) / β } · · · { π ( ε l , q , p ) / β l } where(i) l = (cid:93) σ and for each i = , . . . , l, β i is the head variable ofM ( σ (cid:22) i − ) { π ( ε , q , p ) / β } · · · { π ( ε i − , q , p ) / β i − } (ii) ε , . . . , ε l is a sequence of pairwise distinct variables disjoint from β , . . . , β l and not occurring inM(iii) C [ M ] has a proper hnf iff M ( σ ) has a proper hnf.Proof. We proceed at the same time to define the context C [ · ] and prove its properties by induction onthe length of σ .If σ is the empty sequence, then C [ · ] : = [ · ] and the statement is trivially satisfied.Let σ = ( j , j (cid:48) ) · · · ( j l , j (cid:48) l ) ∈ dom ( M , n ) and τ = σ (cid:22) l −
1. Now τ ∈ dom ( M , n ) , since τ < σ , so byinduction hypothesis applied to τ we have a context C [ · ] such that C [ M ] (cid:16) s M ( τ ) { π ( ε , q , p ) / β } · · · { π ( ε l − , q , p ) / β l − } where(i) for each i = , . . . , l − β i is the head variable of M ( τ (cid:22) i − ) { π ( ε , q , p ) / β } · · · { π ( ε i − , q , p ) / β i − } (ii) (cid:126) ε = ε , . . . , ε l − is a sequence of pairwise distinct variables disjoint from (cid:126) β = β , . . . , β l − and notoccurring in M .8 The untyped stack calculus and B¨ohm’s theorem
For simplicity, we write E ∗ for E { π ( ε , q , p ) / β } · · · { π ( ε l − , q , p ) / β l − } , so that C [ M ] (cid:16) s ( M ( τ )) ∗ . Thedefinition of the new context for the longer sequence σ is based on the shape of the hnf of C [ M ] (andtherefore on its existence). Since τ ∈ dom ( M , n ) and it is not maximal, we have that M ( τ ) does have aproper hnf, say, Hnf ( M ( τ )) ≡ µ (cid:126) α . β [ h ] (cid:63) π (cid:5) . . . (cid:5) π m . Then we have Hnf ( M ( τ )) ∗ ≡ (cid:40) µ (cid:126) α . A ( q ) (cid:63) π ∗ (cid:63) · · · (cid:63) π ∗ m if β ∈ (cid:126) βµ (cid:126) α . β [ h ] (cid:63) π ∗ (cid:63) · · · (cid:63) π ∗ m if β (cid:54)∈ (cid:126) β (cid:16) s (cid:40) µ (cid:126) αε m + . . . ε q δ . δ [ ] (cid:63) π ∗ (cid:63) · · · (cid:63) π ∗ m (cid:63) ε m + (cid:63) · · · (cid:63) ε q if β ∈ (cid:126) βµ (cid:126) α . β [ h ] (cid:63) π ∗ (cid:63) · · · (cid:63) π ∗ m if β (cid:54)∈ (cid:126) β ≡ Hnf (( M ( τ )) ∗ ) because by hypothesis p ≥ h and q ≥ m . The computations above give, according to the different cases,the head variable of C [ M ] , since C [ M ] (cid:16) s ( M ( τ )) ∗ . Now let ε (cid:54)∈ FV ( Hnf (( M ( τ )) ∗ )) and set • C (cid:48) [ · ] : = [ · ] (cid:63)(cid:126) α if β ∈ (cid:126) β ( µβ . [ · ] (cid:63)(cid:126) α ) (cid:63) π ( ε , q , p ) if β (cid:54)∈ (cid:126) β and β (cid:54)∈ (cid:126) α [ · ] (cid:63) α (cid:63) · · · (cid:63) α r − (cid:63) π ( ε , q , p ) (cid:63) α r + (cid:63) · · · (cid:63) α t if β (cid:54)∈ (cid:126) β and β ≡ α r ∈ (cid:126) α = α , . . . , α t • C (cid:48)(cid:48) [ · ] : = [ · ] (cid:63) ε m + (cid:63) · · · (cid:63) ε q (cid:63) (( µα . . . α q . α j l [ j (cid:48) l − ]) (cid:5) ε ) We claim that the context D [ · ] : = C (cid:48)(cid:48) [ C (cid:48) [ C [ · ]]] satisfies the statement of the lemma. By all the definitionsand results above we have that C (cid:48) [ Hnf (( M ( τ )) ∗ )] (cid:16) s µε m + . . . ε q δ . δ [ ] (cid:63) π ∗ { π ( ε , q , p ) / β } (cid:63) · · · (cid:63) π ∗ m { π ( ε , q , p ) / β } (cid:63) ε m + (cid:63) · · · (cid:63) ε q because if β ∈ (cid:126) β , then the sequences of stacks π ∗ , . . . , π ∗ m and π ∗ { π ( ε , q , p ) / β } , . . . , π ∗ m { π ( ε , q , p ) / β } coin-cide since in that case the variable β does not occur free in π ∗ , . . . , π ∗ m . Therefore D [ M ] (cid:16) s C (cid:48)(cid:48) [ C (cid:48) [( M ( τ )) ∗ ]] (cid:16) s C (cid:48)(cid:48) [ C (cid:48) [ Hnf (( M ( τ )) ∗ )]] (cid:16) s ( π ∗ j l { π ( ε , q , p ) / β } )[ j (cid:48) l − ] (cid:16) s ( M ( σ )) ∗ { π ( ε , q , p ) / β } Finally we remark that M ( σ ) has a proper hnf iff ( M ( σ )) ∗ { π ( ε , q , p ) / β } has a proper hnf. This concludesthe proof.Note that if σ ∈ dom ( M ) is non-empty, then for every proper prefix τ < σ , the term M ( τ ) must havea proper hnf. This fact allows the “navigation” of the B¨ohm tree of M implemented in Lemma 3.6. Theimproper hnf’s do not play the same role that head normal forms have in the λ -calculus.Now we want to look at terms as maps which are defined also at nodes reachable by the suitableamount of η -expansions. To this end the following concept of path expansion will be used to definethese maps. Definition 3.9 (Path expansion) . Let σ be a sequence and let M be a term. We define the path expansion . Carraro (cid:104) M (cid:107) σ (cid:105) of M by σ by induction on the length of σ as follows: (cid:104) M (cid:107) σ (cid:105) : = M if σ is the empty sequence (cid:104) M (cid:107) ( j , j (cid:48) ) · τ (cid:105) : = µ (cid:126) α . β [ n ] (cid:63) π (cid:63) · · · (cid:63) ( (cid:126) N (cid:5) γ [ k ] (cid:5) . . . (cid:5) (cid:104) γ [ k + j (cid:48) − ] (cid:107) τ (cid:105) (cid:5) γ [ k + j (cid:48) )) (cid:63) · · · (cid:63) π m if Hnf ( M ) = µ (cid:126) α . β [ n ] (cid:63) π (cid:63) · · · (cid:63) π m , j ≤ m and (cid:126) N (cid:5) γ [ k ) is the canonical form of π j and j (cid:48) > (cid:93)(cid:126) N µ (cid:126) αγ . . . γ j − m . β [ n ] (cid:63) π (cid:63) · · · (cid:63) π m (cid:63) γ (cid:63) · · · (cid:63) ( γ j − m [ ] (cid:5) . . . (cid:5) (cid:104) γ j − m [ j (cid:48) − ] (cid:107) τ (cid:105) (cid:5) γ j − m [ j (cid:48) )) if Hnf ( M ) = µ (cid:126) α . β [ n ] (cid:63) π (cid:63) · · · (cid:63) π m and j > mundefined otherwise Definition 3.10.
Given a term M we define a partial map M ( · ) : Seq (cid:42) Σ t (extending that of Definition3.5) as follows:M σ : = (cid:104) M ( τ ) (cid:107) τ (cid:48) (cid:105) ( τ (cid:48) ) if τ is the longest prefix of σ such that τ ∈ dom ( M ) , σ = τ · τ (cid:48) and (cid:104) M ( τ ) (cid:107) τ (cid:48) (cid:105) is definedundefined otherwise The map M ( · ) : Seq (cid:42) Σ t contains information about all possible η -expansions of the B¨ohm tree of M .We let vir ( M ) = { σ ∈ Seq : M σ is defined } . Note that dom ( M ) ⊆ vir ( M ) and for every σ ∈ dom ( M ) ,the values M σ and M ( σ ) coincide. The elements of vir ( M ) are the virtual sequences of M . The map M ( · ) extends M ( · ) by giving also virtual nodes , which are intuitively nodes of some η -expansion of theB¨ohm tree of M , but still M ( · ) cannot return the unreachable nodes, that correspond to sequences in Seq − vir ( M ) , which do not belong to any of the η -expansions of the B¨ohm tree of M . Note that for themaximal sequences σ ∈ dom ( M ) , the term M σ may have an improper hnf or not have an hnf at all, whilefor non-maximal σ ∈ dom ( M ) , the term M σ must have a proper hnf. Lemma 3.7.
Let M , N be terms. If σ ∈ vir ( M ) ∩ vir ( N ) is minimal such that M σ (cid:54)∼ N σ , then there existsa head context C [ · ] such that C [ M ] (cid:54)∼ C [ N ] . Moreover C [ M ] has a proper hnf iff M σ has a proper hnf andC [ N ] has a proper hnf iff N σ has a proper hnf.Proof. If σ is the empty sequence then the result is trivial. Now assume σ = σ (cid:48) ( j , j (cid:48) ) , so that M σ (cid:48) ∼ N σ (cid:48) and the similarity also holds for all prefixes of σ (cid:48) . Let τ be the longest prefix of σ (cid:48) contained in dom ( M ) and let τ (cid:48) be such that σ (cid:48) = ττ (cid:48) . Let ρ be the longest prefix of σ (cid:48) contained in dom ( N ) and let ρ (cid:48) besuch that σ (cid:48) = ρρ (cid:48) . We assume w.l.o.g. that τ ≥ ρ . Let n = (cid:93) σ , let p be greater than w ( M , n ) , w ( N , n ) and of all the second components of the pairs occurring in σ . Let q be greater than b ( M , n ) , b ( N , n ) and of all the first component of the pairs occurring in σ . Let C [ · ] be the context produced by Lemma3.6 applied to M , n , ρ , q and p . Then C [ M ] and C [ N ] reduce, respectively, to substitution instances ( M ( ρ )) ∗ and ( N ( ρ )) ∗ where the same substitutions have been applied. Therefore ( M ( ρ )) ∗ ∼ ( N ( ρ )) ∗ and C [ M ] ∼ C [ N ] . Now let C (cid:48) [ · ] be the context produced by Lemma 3.6 applied to (cid:104) ( N ( ρ )) ∗ (cid:107) ρ (cid:48) (cid:105) , n (cid:48) = (cid:93) ρ (cid:48) , τ (cid:48) , q and p . Once again C (cid:48) [ C [ N ]] reduces to a substitution instance ( (cid:104) N ( ρ ) ∗ (cid:107) ρ (cid:48) (cid:105) ( ρ (cid:48) )) o and, because M σ (cid:48) ∼ N σ (cid:48) , we have C (cid:48) [ C [ M ]] ∼ C (cid:48) [ C [ N ]] . Finally let C (cid:48)(cid:48) [ · ] be the context produced by Lemma 3.6 appliedto ( (cid:104) N ( ρ ) ∗ (cid:107) ρ (cid:48) (cid:105) ( ρ (cid:48) )) o , n (cid:48)(cid:48) = τ (cid:48)(cid:48) = ( j , j (cid:48) ) , q and p . Then the context C (cid:48)(cid:48) [ C (cid:48) [ C [ · ]]] has the propertiesrequired in the statement, since C (cid:48)(cid:48) [ C (cid:48) [ C [ M ]]] (cid:54)∼ C (cid:48)(cid:48) [ C (cid:48) [ C [ N ]]] , C (cid:48)(cid:48) [ C (cid:48) [ C [ M ]]] has a proper hnf iff M σ has aproper hnf and C (cid:48)(cid:48) [ C (cid:48) [ C [ N ]]] has a proper hnf iff N σ has a proper hnf.0 The untyped stack calculus and B¨ohm’s theorem
Theorem 3.8 (B¨ohm’s theorem for the extended stack calculus) . Let M , N be two distinct → s η -normalforms without subterms which are improper hnf ’s. Then M and N are separable.Proof. Under the hypotheses of the statement about M and N , there has to be a minimal sequence σ ∈ vir ( M ) ∩ vir ( N ) such that M σ (cid:54)∼ N σ so that by Lemma 3.7 there exists a head context C [ · ] such that C [ M ] (cid:54)∼ C [ N ] . Now by hypothesis M σ and N σ are proper hnf’s and hence C [ M ] and C [ N ] have properhnf’s. Therefore, applying Theorem 3.5 we have that C [ M ] and C [ N ] are separable, which triviallyimplies that M and N are separable.Supppose that there is a σ ∈ dom ( M ) ∩ dom ( N ) such that M ( σ ) = µ (cid:126) α . nil [ h ] (cid:63)(cid:126) π and N ( σ ) = µ (cid:126) α (cid:48) . nil [ h (cid:48) ] (cid:63)(cid:126) ϖ . Assume P is the j (cid:48) -th term of the j -th stack of (cid:126) π and Q is the j (cid:48) -th term of the j -th stack of (cid:126) ϖ andthat P (cid:54)∼ Q . If P and Q are the only dissimilar subterms then no separating context can be built with thetechnique described in Lemma 3.6. As a matter of fact the requirement, appearing in the statement ofTheorem 3.8, that M and N do not have subterms which are improper hnf’s is more strict then neces-sary. In fact we only need that, among the dissimilar subterms, there is a σ ∈ vir ( M ) ∩ vir ( N ) such that M σ (cid:54)∼ N σ and M σ , N σ are proper hnf’s.We decided to study the extension of the stack calculus as defined in [7], thus including nil in the lan-guage. However nil received a special treatment throughout this paper, in the sense that the improperhnf’s are kept do not play a role similar to the proper hnf’s (see for example Definition 3.1, Definition3.4 and Definition 3.5). The reason is that improper hnf’s and terms without hnf are, in the extendedstack calculus, in some sense comparable to what unsolvable terms are in the λ -calculus. In any case,we do not treat a notion of solvability for the extended stack calculus. In this section we give a concrete characterization of operational equivalence that does not involve anyuniversal quantification over head contexts (see Definition 2.1). Rather, this characterization is based onB¨ohm trees.
Definition 3.11.
We define a binary relation ∞ ∼ on Σ t as follows: M ∞ ∼ N iff vir ( M ) = vir ( N ) and for all σ ∈ vir ( M ) we have that M σ ∼ N σ (up to rename of variables which are bound in some M τ , N τ , where τ < σ , but free in M σ , N σ ). Theorem 3.9. M ≈ N iff M ∞ ∼ N.Proof. ( ⇒ ) We prove the contrapositive. Suppose M (cid:54) ∞ ∼ N . Then there exists a sequence σ such that M (cid:54)∼ σ N . Let σ be minimal w.r.t. this property. Then σ ∈ vir ( M ) ∩ vir ( N ) , so that in fact M σ (cid:54)∼ N σ .Since M σ and N σ are not similar, at least one among them must have a proper hnf: say it is M σ . Nowsuppose N σ does not have a proper hnf. By Lemma 3.7 there exists a head context C [ · ] such that C [ M ] has a proper hnf while C [ N ] does not have a proper hnf. This proves that M (cid:54)≈ N .If N σ has a proper hnf, then by Lemma 3.7 there exists a head context C (cid:48) [ · ] such that C (cid:48) [ M ] (cid:54)∼ C (cid:48) [ N ] andboth C (cid:48) [ M ] , C (cid:48) [ N ] have a proper hnf; therefore applying Theorem 3.5 we obtain that C (cid:48) [ M ] and C (cid:48) [ N ] areseparable and consequently by Theorem 3.3, we have C (cid:48) [ M ] (cid:54)≈ C (cid:48) [ N ] . This trivially implies M (cid:54)≈ N .( ⇐ ) Immediate, because by Theorem 3.2, the relation ≈ is an HP-complete equational theory which, byTheorem 3.9, is contained in ∞ ∼ . . Carraro The stack calculus [7] is a finitary functional language in which the λ µ -calculus can be faithfully trans-lated, in the sense that conversion (and typing, for the typed versions) is preserved by the translation. Asit happens for the λ µ -calculus, the stack calculus fails to have the separation property and in this paperwe introduce the extended stack calculus which, as Saurin’s Λ µ -calculus [23], does have this property.The separation property proved in this paper for the extended stack calculus has consequences both onthe semantical and on the syntactical side. For example it implies that = s η is the maximal consistent con-gruence on normalizable terms extending = s , so that any model of the extended stack calculus cannotidentify two different s η -normal forms without being trivial.Nonetheless the definition of operational equivalence involves a universal quantification over con-texts but the problem of checking operational equivalence between nil -free normalizable terms reducesto the problem of finding their s η -normal forms (Theorem 3.8) (with a leftmost strategy, for example).The complete characterization of operational equivalence (also for non-normalizable terms) is achieved:two terms of the extended stack calculus are operationally equivalent iff they have the same B¨ohm tree,up to possibly infinite η -expansion (Theorem 3.9), a condition that does not involve a quantification overall head contexts. We showed that operational equivalence is maximally consistent, i.e. it cannot beproperly extended to another consistent equational theory both in the stack calculus and in the extendedstack calculus. We work out the details of a B¨ohm-out technique for the extended stack calculus (Lemma3.6). A nice feature of the extended stack calculus is that, having only one binder, it admits a simplerproof of B¨ohm’s theorem, which is similar to the one for the λ -calculus. Besides the applications ofB¨ohm’s theorem, there has always been interest around the proof itself and the algorithmic content of theB¨ohm-out technique: from Huet’s [16] interest in the implementation and mechanical formalization ofB¨ohm’s proof, Aehlig and Joachimski [1] alternative proof and to Dezani et al.’s account [9]. Saurin in[24] establishes a standardization theorem for the Λ µ -calculus, and studies B¨ohm-like trees for the Λ µ -calculus, strengthening the separation results that he obtained in [23]. In view of the interest in proofsof B¨ohm’s theorem for various calculi, we believe useful to contribute in the present work with a directproof of B¨ohm’s theorem (i.e. with a B¨ohm-out technique) for the extended stack calculus, even if themere separation result would follow by a suitable mutual translation with the Λ µ -calculus.It is out of the scope of this paper to analyze the typed extended stack calculus. In the case of Saurin’s Λ µ the Curry–Howard isomorphism carries through via the straightforward extension of the type system.However Saurin [25] and Nakazawa and Katsumata [18] noted that with this approach many “interesting” Λ µ -terms are not typeable (for example those used in the B¨ohm out technique). For this reason Saurin[25] studies an alternative type system for the Λ µ -calculus. This latter approach could also be adaptedto the extended stack calculus. References [1] K. Aehlig & F. Joachimski (2002):
A note on B¨ohm’s theorem . Available at .[2] H.P. Barendregt (1984):
The Lambda calculus: its syntax and semantics . North-Holland.[3] C. B¨ohm (1968):
Alcune propriet`a delle forme β η -normali nel λ K-calcolo.
Pubblicazioni dell’IAC
A discrimination algo-rithm inside lambda-beta-calculus . Theoretical Computer Science
8, pp. 265–292, doi:10.1016/0304-3975(79)90014-8. The untyped stack calculus and B¨ohm’s theorem [5] C. B¨ohm & W. Gross (1966):
Introduction to the CUCH . In E. Caianiello, editor:
Automata Theory , Aca-demic Press, London, UK, pp. 35–65.[6] C. B¨ohm, A. Piperno & S. Guerrini (1994):
Lambda-Definition of Function(al)s by Normal Forms . InD. Sannella, editor:
ESOP , Lecture Notes in Computer Science
The Stack calculus . Submitted to LSFA12.[8] R. David & W. Py (2001): λ µ -Calculus and B¨ohm’s Theorem . J. Symb. Log.
B¨ohm’s Theorem , pp. 1–15. World Scientific Pub.Co. Inc. Available at .[10] M. Dezani-Ciancaglini, U. De’ Liguoro & A. Piperno (1996):
Filter Models for Conjunctive-disjunctive λ -calculi . Theoretical Computer Science
Discrimination by parallel observers: the algorithm . Information and computation
On the expressive power of programming languages . In:
ESOP , LNCS, pp. 134–151,doi:10.1007/3-540-52592-0 60.[13] T. Griffin (1990):
A Formulae-as-Types Notion of Control . In:
POPL , pp. 47–58, doi:10.1145/96709.96714.[14] C. Hankin (1995):
Lambda Calculi: a guide for computer scientists . Oxford University Press.[15] W.A. Howard (1980):
The formulas-as-types notion of construction . In J.R. Hindley & J.P. Seldin, editors:
To H.B. Curry: Essays on Combinatory Logic, Lambda Calculus and Formalism , pp. 479–490.[16] G.P. Huet (1993):
An Analysis of B¨ohm’s Theorem . Theor. Comput. Sci.
A syntactic characterization of the equality in some models of the λ -calculus . J.London Math. Soc.
Extensional models of untyped λ µ -calculus . In:
CL& C ,doi:10.4204/EPTCS.97.3.[19] G. Manzonetto & M. Pagani (2011):
B¨ohm’s theorem for resource lambda calculus through Taylor expansion .In:
TLCA , pp. 153–168, doi:10.1007/978-3-642-21691-6 14.[20] M. Parigot (1991):
Free Deduction: An Analysis of ”Computations” in Classical Logic . In:
RCLP , pp.361–380, doi:10.1007/3-540-55460-2 27.[21] D. Prawitz (1965):
Natural Deduction - a proof theoretical study . Almqvist & Wiksell, Stokholm.[22] D. Sangiorgi (1994):
The lazy lambda calculus in a concurrency scenario . Information and computation
Separation with streams in the Λ µ -calculus . In: LICS , pp. 356–365,doi:10.1109/LICS.2005.48.[24] A. Saurin (2010):
Standardization and B¨ohm Trees for Λ µ -calculus . In: FLOPS , pp. 134–149,doi:10.1007/978-3-642-12251-4 11.[25] A. Saurin (2010):
Typing streams in the Λ µ -calulus . ACM Trans. Comput. Log.
Introduction to combinators and λ -calculus . Cambridge University Press.[27] T. Streicher & B. Reus (1998): Classical logic, continuation semantics and abstract machines . J. Funct.Program.