Simulation in the Call-by-Need Lambda-Calculus with Letrec, Case, Constructors, and Seq

This paper shows equivalence of several versions of applicative similarity and contextual approximation, and hence also of applicative bisimilarity and contextual equivalence, in LR, the deterministic call-by-need lambda calculus with letrec extended by data constructors, case-expressions and Haskell's seq-operator. LR models an untyped version of the core language of Haskell. The use of bisimilarities simplifies equivalence proofs in calculi and opens a way for more convenient correctness proofs for program transformations. The proof is by a fully abstract and surjective transfer into a call-by-name calculus, which is an extension of Abramsky's lazy lambda calculus. In the latter calculus equivalence of our similarities and contextual approximation can be shown by Howe's method. Similarity is transferred back to LR on the basis of an inductively defined similarity. The translation from the call-by-need letrec calculus into the extended call-by-name lambda calculus is the composition of two translations. The first translation replaces the call-by-need strategy by a call-by-name strategy and its correctness is shown by exploiting infinite trees which emerge by unfolding the letrec expressions. The second translation encodes letrec-expressions by using multi-fixpoint combinators and its correctness is shown syntactically by comparing reductions of both calculi. A further result of this paper is an isomorphism between the mentioned calculi, which is also an identity on letrec-free expressions.

Abstract.This paper shows equivalence of several versions of applicative similarity and contextual approximation, and hence also of applicative bisimilarity and contextual equivalence, in LR, the deterministic call-by-need lambda calculus with letrec extended by data constructors, case-expressions and Haskell's seq-operator.LR models an untyped version of the core language of Haskell.The use of bisimilarities simplifies equivalence proofs in calculi and opens a way for more convenient correctness proofs for program transformations.
The proof is by a fully abstract and surjective transfer into a call-by-name calculus, which is an extension of Abramsky's lazy lambda calculus.In the latter calculus equivalence of our similarities and contextual approximation can be shown by Howe's method.Similarity is transferred back to LR on the basis of an inductively defined similarity.
The translation from the call-by-need letrec calculus into the extended call-by-name lambda calculus is the composition of two translations.The first translation replaces the call-by-need strategy by a call-by-name strategy and its correctness is shown by exploiting infinite trees which emerge by unfolding the letrec expressions.The second translation encodes letrec-expressions by using multi-fixpoint combinators and its correctness is shown syntactically by comparing reductions of both calculi.
A further result of this paper is an isomorphism between the mentioned calculi, which is also an identity on letrec-free expressions.

Introduction
Motivation.Non-strict functional programming languages, such as the core-language of Haskell [Pey03], can be modeled using extended call-by-need lambda calculi.
The operational semantics of such a programming language defines how programs are evaluated and how the value of a program is obtained.Based on the operational semantics, the notion of contextual equivalence (see e.g.[Mor68,Plo75]) is a natural notion of program equivalence which follows Leibniz's law to identify the indiscernibles, that is two programs are equal iff their observable (termination) behavior is indistinguishable even if the programs are used as a subprogram of any other program (i.e. if the programs are plugged into any arbitrary context).For pure functional programs it suffices to observe whether or not the evaluation of a program terminates with a value (i.e.whether the program converges).Contextual equivalence has several advantages: Any reasonable notion of program equivalence should be a congruence which distinguishes obvious different values, e.g.different constants are distinguished, and functions (abstractions) are distinguished from constants.Contextual equivalence satisfies these requirements and is usually the coarsest of such congruences.Another (general) advantage is that once expressions, contexts, an evaluation, and a set of values are defined in a calculus, its definition of contextual equivalence can be derived, and thus this approach can be used for a broad class of program calculi.
On the other hand, due to the quantification over all program contexts, verifying equivalence of two programs w.r.t.contextual equivalence is often a difficult task.Nevertheless such proofs are required to ensure the correctness of program transformations where the correctness notion means that contextual equivalence is preserved by the transformation.Correctness of program transformations is indispensable for the correctness of compilers, but program transformations also play an important role in several other fields, e.g. in code refactoring to improve the design of programs, or in software verification to simplify expressions and thus to provide proofs or tests.
Bisimulation is another notion of program equivalence which was first invented in the field of process calculi (e.g.[Mil80,Mil99,SW01]), but has also been applied to functional programming and several extended lambda calculi (e.g.[How89,Abr90,How96]). Finding adequate notions of bisimilarity is still an active research topic (see e.g.[KW06,SKS11]).Briefly explained, bisimilarity equates two programs s 1 , s 2 if all experiments passed for s 1 are also passed by s 2 and vice versa.For applicative similarity (and also bisimilarity) the experiments are evaluation and then recursively testing the obtained values: Abstractions are applied to all possible arguments, data objects are decomposed and the components are tested recursively.Applicative similarity is usually defined co-inductively, i.e. as a greatest fixpoint of an operator.Applicative similarity allows convenient and automatable proofs of correctness of program transformations, e.g. in mechanizing proofs [DBG97].
Abramsky and Ong showed that applicative bisimilarity is the same as contextual equivalence in a specific simple lazy lambda calculus [Abr90,AO93], and Howe [How89,How96] proved that in classes of lambda-calculi applicative bisimulation is the same as contextual equivalence.This leads to the expectation that some form of applicative bisimilarity may be used for calculi with Haskell's cyclic letrec.However, Howe's proof technique appears to be not adaptable to lambda calculi with cyclic let, since there are several deviations from the requirements for the applicability of Howe's framework.(i) Howe's technique is for call-by-name calculi and it is not obvious how to adapt it to call-by-need evaluation.(ii) Howe's technique requires that the values (results of reduction) are recognizable by their top operator.This does not apply to calculi with letrec, since letrec-expressions may be values as well as non-values.(iii) Call-by-need calculi with letrec usually require reduction rules to shift and join letrec-bindings.These modifications of the syntactic structure of expressions do not fit well into the proof structure of Howe's method.
Nevertheless, Howe's method is also applicable to calculi with non-recursive let even in the presence of nondeterminism [MSS10], where for the nondeterministic case applicative bisimilarity is only sound (but not complete) w.r.t.contextual equivalence.However, in the case of (cyclic) letrec and nondeterminism applicative bisimilarity is unsound w.r.t.contextual equivalence [SSSM11].This raises a question: which call-by-need calculi with letrec permit applicative bisimilarity as a tool for proving contextual equality?
Our Contribution.In [SSSM10] we have already shown that for the minimal extension of Abramsky's lazy lambda calculus with letrec which implements sharing and explicit recursion, the equivalence of contextual equivalence and applicative bisimilarity indeed holds.However, the full (untyped) core language of Haskell has data constructors, case-expressions and the seq-operator for strict evaluation.Moreover, in [SSMS13] it is shown that the extension of Abramsky's lazy lambda calculus with case, constructors, and seq is not conservative, i.e. it does not preserve contextual equivalence of expressions.Thus our results obtained in [SSSM10] for the lazy lambda calculus extended by letrec only are not transferable to the language extended by case, constructors, and seq.For this reason we provide a new proof for the untyped core language of Haskell.
As a model of Haskell's core language we use the call-by-need lambda calculus L LR which was introduced and motivated in [SSSS08].The calculus L LR extends the lazy lambda calculus with letrec-expressions, data constructors, case-expressions for deconstructing the data, and Haskell's seq-operator for strict evaluation.
We define the operational semantics of L LR in terms of a small-step reduction, which we call normal order reduction.As it is usual for lazy functional programming languages, evaluation of L LR -expressions successfully halts if a weak head normal form is obtained, i.e. normal order reduction does not reduce inside the body of abstractions nor inside the arguments of constructor applications.The L LR calculus has been studied in detail in [SSSS08] and correctness of several important program transformations has been established for it.
Our main result in this paper is that several variants of applicative bisimilarities are sound and complete for contextual equivalence in L LR , i.e. coincide with contextual equivalence.Like context lemmas, an applicative bisimilarity can be used as a proof tool for showing contextual equivalence of expressions and for proving correctness of program transformations in the calculus L LR .Since we have completeness of our applicative bisimilarities in addition to soundness, our results can also be used to disprove contextual equivalence of expressions in L LR .Additionally, our result shows that the untyped applicative bisimilarity is sound for a polymorphic variant of L LR , and hence for the typed core language of Haskell.
Having the proof tool of applicative bisimilarity in L LR is also very helpful for more complex calculi if their pure core can be conservatively embedded in the full calculus.An example is our work on Concurrent Haskell [SSS11,SSS12], where our calculus CHF that models Concurrent Haskell has top-level processes with embedded lazy functional evaluation.We have shown in the calculus CHF that Haskell's deterministic core language can be conservatively embedded in the calculus CHF.
Figure 1: Overall structure.Solid lines are fully-abstract translations, which are also isomorphisms and identities on letrec-free expressions; dotted lines are convergence preservation to/from the system L tree of infinite trees.
We prove the equivalence between the applicative similarities and contextual equivalence in L LR , by lifting the equivalence from a letrec-free call-by-name calculus L lcc .The calculus L lcc minimally extends Abramsky's lazy calculus by Haskell's primitives.As shown in [SSMS13], data constructors and seq are explicitly needed in L lcc .The structure of the proof, with its intermediate steps, is shown in Figure 1.We prove the equivalence between the applicative similarities and contextual equivalence in L lcc , by extending Howe's method.We bridge L LR and L lcc in two steps, using intermediate calculi L name and L tree .L name is the call-by-name variant of L LR , and L lcc is obtained from L name by encoding letrec using multi-fixpoint combinators.The calculi L LR and L name are related to each other via their infinite unfoldings, thus we introduce a calculus L tree of infinite trees (similar infinitary rewriting, see [KKSdV97,SS07]).Convergence of expressions in L LR and L name is shown to be equivalent to their translation as an infinite tree in the calculus L tree (dotted lines in the picture).We establish full abstractness of translation N and W between calculi L LR , L name , and L lcc with respect to contextual equivalence.Correctness of similarity is transferred back from L lcc to L LR on the basis of an inductively defined similarity (for more details see Fig. 7.

2).
A consequence of our result is that the three calculi L LR , L name , and L lcc are isomorphic, modulo the equivalence (see Corollaries 6.17 and 5.33), and also that the embedding of the calculus L lcc into the call-by-need calculus L LR is an isomorphism of the respective term models.
Related Work.In [Gor99] Gordon shows that bisimilarity and contextual equivalence coincide in an extended call-by-name PCF language.Gordon provides a bisimilarity in terms of a labeled transition system.A similar result is obtained in [Pit97] for PCF extended by product types and lazy lists where the proof uses Howe's method ( [How89,How96]; see also [MSS10,Pit11]), and where the operational semantics is a big-step one for an extended PCF-language.The observation of convergence in the definition of contextual equivalence is restricted to programs (and contexts) of ground type (i.e. of type integer or Bool).Therefore Ω and λx.Ω are equal in the calculi considered by Gordon and Pitts.This does not hold in our setting for two reasons: first, we observe termination for functions and thus the empty context already distinguishes Ω and λx.Ω, and second, our languages employ Haskell's seq-operator which permits to test convergence of any expression and thus the context seq [•] True distinguishes Ω and λx.Ω.
[Jef94] presents an investigation into the semantics of a lambda-calculus that permits cyclic graphs, where a fully abstract denotational semantics is described.However, the calculus is different from our calculi in its expressiveness since it permits a parallel convergence test, which is required for the full abstraction property of the denotational model.Expressiveness of programming languages was investigated e.g. in [Fel91] and the usage of syntactic methods was formulated as a research program there, with non-recursive let as the paradigmatic example.Our isomorphism-theorem 7.7 shows that this approach is extensible to a cyclic let.
Related work on calculi with recursive bindings includes the following foundational papers.An early paper that proposes cyclic let-bindings (as graphs) is [AK94], where reduction and confluence properties are discussed.[AFM + 95, AF97] study equational theory for call-by-need lambda calculus extended with non-recursive let, which is finer than contextual equivalence, and in [MOW98] it is shown that call-by-name and call-by-need evaluation induce the same observational equivalences for a call-by-need lambda calculus with non-recursive let.Additionally, the extension of the corresponding calculi by recursive let is discussed in [AFM + 95, AF97], and further call-by-need lambda calculi with a recursive let are presented in [AB97, AB02,NH09] where [NH09] study the equivalence between a natural semantics and a reductions semantics.In [AB02] it is shown that there exist infinite normal forms and that the calculus satisfies a form of confluence.All these calculi correspond to our calculus L LR .A difference is that the let-shifting in the standard reduction in the mentioned works is different from L LR .However, this difference is not substantial, since it does not influence the contextual semantics.A more substantial difference is that L LR combines recursive let with data constructors, case-expressions and seq, which none of the related works do.
In [MS99] a call-by-need calculus is analyzed which is closer to our calculus L LR , since letrec, case, and constructors are present (but not seq).Another difference is that [MS99] uses an abstract machine semantics as operational semantics, while their approach to program equivalence is based on contextual equivalence, as is ours.
The operational semantics of call-by-need lambda calculi with letrec are investigated in [Lau93] and [Ses97], where the former proposed a natural semantics, and proved it correct and adequate with respect to a denotational semantics, and the latter derived an efficient abstract machine from the natural semantics.
Investigations of the semantics of lazy functional programming languages including the seq-operator can be found in [JV06,VJ07].
Outline.In Sect. 2 we introduce some common notions of program calculi, contextual equivalence, similarity and also of translations between those calculi.In Sect. 3 we introduce the extension L lcc of Abramsky's lazy lambda calculus with case, constructors, and seq, and two letrec-calculi L LR , L name as further syntactic extensions.In Sect. 4 we show that for so-called "convergence admissible" calculi an alternative inductive characterization of similarity is possible.We then use Howe's method in L lcc to show that contextual approximation and a standard version of applicative similarity coincide.Proving that L lcc is convergence admissible then implies that the alternative inductive characterization of similarity can be used for L lcc .In Sect. 5 and 6 the translations W and N are introduced and the full-abstraction results are obtained.In Sect.7 we show soundness and completeness of our variants of applicative similarity w.r.t.contextual equivalence in L LR .We conclude in Sect.8.

Common Notions and Notations for Calculi
Before we explain the specific calculi, some common notions are introduced.A calculus definition consists of its syntax together with its operational semantics which defines the evaluation of programs and the implied equivalence of expressions: Definition 2.1.An untyped deterministic calculus D is a four-tuple (E, C, →, A), where E are expressions (up to α-equivalence), C : E → E is a set of functions (which usually represents contexts), → is a small-step reduction relation (usually the normal-order reduction), which is a partial function on expressions (i.e., deterministic), and A ⊂ E is a set of answers of the calculus.
For C ∈ C and an expression s, the functional application is denoted as C[s].For contexts, this is the replacement of the hole of C by s.We also assume that the identity function Id is contained in C with Id [s] = s for all expressions s, and that C is closed under composition, i.e.
The transitive closure of → is denoted as We will have to deal with several calculi and preorders.Throughout this paper we will use the symbol for co-inductively defined preorders (i.e.similarities), and ≤ for (inductively defined or otherwise defined) contextual preorders.For the corresponding symmetrizations we use ≃ for ∩ and ∼ for ≤ ∩ ≥.All the symbols are always indexed by the corresponding calculus and sometimes more restrictions like specific sets of contexts are attached to the indices of the symbols.
Contextual approximation and equivalence can be defined in a general way: Definition 2.2 (Contextual Approximation and Equivalence, ≤ D and ∼ D ).Let D = (E, C, →, A) be a calculus and s 1 , s 2 be D-expressions.Contextual approximation (or contextual preorder) ≤ D and contextual equivalence ∼ D are defined as: Note that ≤ D is a precongruence, i.e., ≤ D is reflexive, transitive, and s for all C ∈ C, and that ∼ D is a congruence, i.e. a precongruence and an equivalence relation.
We also define a general notion of similarity coinductively for untyped deterministic calculi.We first define the operator F D,Q on binary relations of expressions: Definition 2.3.Let D = (E, C, →, A) be an untyped deterministic calculus and let Q ⊆ C be a set of functions on expressions (i.e.∀Q ∈ Q : Lemma 2.4.The operator F D,Q is monotonous w.r.t.set inclusion, i.e. for all binary relations η 1 , η 2 on expressions Since F D,Q is monotonous, its greatest fixpoint exists: We also provide an inductive definition of behavioral equivalence, which is defined as a contextual preorder where the contexts are restricted to the set Q (and the empty context).Definition 2.6.Let D = (E, C, →, A) be an untyped deterministic calculus, and Q ⊆ C. Then the relation ≤ D,Q is defined as follows: Note that contextual approximation is a special case of this definition, i.e. ≤ D = ≤ D,C .Later in Section 4.1 we will provide a sufficient criterion on untyped deterministic calculi that ensures that D,Q and ≤ D,Q coincide.
We are interested in translations between calculi that are faithful w.r.t. the corresponding contextual preorders.

Definition 2.7 ([SSNSS08, SSNSS09]). For
The following properties of translations are defined: • τ is an isomorphism iff it is fully abstract and a bijection on the quotients τ /∼ : Note that isomorphism means an order-isomorphism between the term-models, where the orders are ≤ 1 /∼ and ≤ 2 /∼ (which are the relations in the quotient).

Three Calculi
In this section we introduce the calculi L LR , L name , and L lcc .L LR is a call-by-need calculus with recursive let, data constructors, case-expressions, and the seq-operator.The calculus L name has the same syntactic constructs as L LR , but uses a call-by-name, rather than a callby-need, evaluation.The calculus L lcc does not have letrec, and also uses a call-by-name evaluation.
For all three calculi we assume that there is a (common) set of data constructors c which is partitioned into types, such that every constructor c belongs to exactly one type.We assume that for every type T the set of its corresponding data constructors can be enumerated as c T,1 , . . ., c T,|T | where |T | is the number of data constructors of type T .We also assume that every constructor has a fixed arity denoted as ar(c) which is a non-negative integer.We assume that there is a type Bool among the types, with the data constructors False and True both of arity 0. We require that data constructors occur only fully saturated, i.e. a constructor c is only allowed to occur together with ar(c) arguments, written as (c s 1 . . .s ar(c) ) where s i are expressions of the corresponding calculus1 .We also write (c − → s ) as an abbreviation for the constructor application (c s 1 . . .s ar(c) ).All three calculi allow deconstruction via case-expressions: where s, s i are expressions and x i,j are variables of the corresponding calculus.Thus there is a case T -construct for every type T and we require that there is exactly one case-alternative (c T,i x i,1 . . .x i,ar(c T,i ) → s i ) for every constructor c T,i of type T .In a case-alternative (c T,i x i,1 . . .x i,ar(c T,i ) → s i ) we call c T,i x i,1 . . .x i,ar(c T,i ) a pattern and s i the right hand side of the alternative.All variables in a case-pattern must be pairwise distinct.We will sometimes abbreviate the case-alternatives by alts if the exact terms of the alternatives are not of interest.As a further abbreviation we sometimes write if s 1 then s 2 else s 3 for the case-expression (case Bool s 1 of (True → s 2 ) (False → s 3 )).
We now define the syntax of expressions with letrec, i.e. the set E L of expressions which are used in both of the calculi L LR and L name .Definition 3.1 (Expressions E L ).The set E L of expressions is defined by the following grammar, where x, x i are variables: We assign the names application, abstraction, seq-expression, or letrec-expression to the expressions (s t), (λx.s), (seq s t), or (letrec x 1 = s 1 , . . ., x n = s n in t), respectively.A value v is defined as an abstraction or a constructor application.A group of letrec bindings is sometimes abbreviated as Env .We use the notation {x g(i) = s h(i) } n i=m for the chain x g(m) = s h(m) , x g(m+1) = s h(m+1) , . . ., x g(n) = s h(n) of bindings where g, h : N → N are injective, e.g., {x i = s i−1 } n i=m means the bindings x m = s m−1 , x m+1 = s m , . . .x n = s n−1 .We assume that variables x i in letrec-bindings are all distinct, that letrec-expressions are identified up to reordering of binding-components, and that, for convenience, there is at least one binding.letrec-bindings are recursive, i.e., the scope of x j in (letrec In all three calculi we will use the symbol Ω for the specific (letrec-free) expression (λz.(z z)) (λx.(x x)).In all of our calculi Ω is divergent and the least element of the corresponding contextual preorder.This is proven in [SSSS08] for L LR and can easily be proven for the other two calculi using standard methods, such as context lemmas.Note that this property also follows from the Main Theorem 7.6 for all three calculi.
3.1.The Call-by-Need Calculus L LR .We begin with the call-by-need lambda calculus L LR which is exactly the call-by-need calculus of [SSSS08].It has a rather complex form of reduction rules using variable chains.The justification is that this formulation permits direct syntactic proofs of correctness w.r.t.contextual equivalence for a large class of transformations.Several modifications of the reduction strategy, removing indirections, do not change the semantics of the calculus, however, they appear to be not treatable by syntactic proof methods using diagrams (see [SSSS08]).L LR -expressions are exactly the expressions E L .
Definition 3.3.The reduction rules for the calculus and language L LR are defined in Fig. 2, where the labels S, V are used for the exact definition of the normal-order reduction below.Several reduction rules are denoted by their name prefix: the union of (llet-in) and (llet-e) is called (llet).The union of (llet), (lapp), (lcase), and (lseq) is called (lll).
For the definition of the normal order reduction strategy of the calculus L LR we use the labeling algorithm in Fig. 3 which detects the position where a reduction rule is applied according to the normal order.It uses the following labels: S (subterm), T (top term), V (visited), and W (visited, but not target).We use ∨ when a rule allows two options for a label, e.g.s S∨T stands for s labeled with S or T .
A labeling rule l ❀ r is applicable to a (labeled) expression s if s matches l with the labels given by l, where s may have more labels than l if not otherwise stated.The labeling algorithm takes an expression s as its input and exhaustively applies the rules in Fig. 3 to s T , where no other subexpression in s is labeled.The label T is used to prevent the labeling algorithm from descending into letrec-environments that are not at the top of the expression.The labels V and W mark the visited bindings of a chain of bindings, where W is used for variable-to-variable bindings.The labeling algorithm either terminates with fail or with success, where in general the direct superterm of the S-marked subexpression indicates a potential normal-order redex.The use of such a labeling algorithm corresponds to the search of a redex in term graphs where it is usually called unwinding.Definition 3.4 (Normal Order Reduction of L LR ).Let s be an expression.Then a single normal order reduction step LR − − → is defined as follows: first the labeling algorithm in Fig. 3 is applied to s.If the labeling algorithm terminates successfully, then one of the rules in Fig. 2 is applied, if possible, where the labels S, V must match the labels in the expression The normal order reduction of L LR implements a call-by-need reduction with sharing which avoids substitution of arbitrary expressions.We describe the rules: The rule (lbeta) is a sharing variant of classical β-reduction, where the argument of an abstraction is shared by a new letrec-binding instead of substituting the argument in the body of an abstraction.The rules (cp-in) and (cp-e) allow to copy abstractions into needed positions.The rules (lapp), (lcase), and (lseq) allow moving letrec-expressions to the top of the term if they are inside a reduction position of an application, a case-expression, or a seq-expression.To flatten nested letrec-expressions, the rules (llet-in) and (llet-e) are added to the reduction.Evaluation of seq-expressions is performed by the rules (seq-c), (seq-in), and (seq-e), where the first argument of seq must be a value (rule seq-c) or it must be a variable which is bound in the outer letrec-environment to a constructor application.Since normal order reduction avoids copying constructor applications, the rules (seq-in) and (seq-e) are required.Correspondingly, the evaluation of case-expressions requires several variants: there are again three rules for the cases where the argument of case is already a constructor application (rule (case-c)) or where the argument is a variable which is bound to a constructor application (perhaps by several indirections in the letrec-environment) which are covered by the rule (case-in) and (case-e).All three rules have two variants: one variant for the case when a constant is scrutinized (and thus no arguments need to be shared by new letrec-bindings) and another variant for the case when arguments are present (and thus the arity of the scrutinized constructor is strictly greater than 0).For the latter case the arguments of the constructor application are shared by new letrec-bindings, such that the newly created variables can be used as references in the right hand side of the matching alternative.Definition 3.5.A reduction context R LR is any context, such that its hole is labeled with S or T by the L LR -labeling algorithm.
Of course, reduction contexts could also be defined recursively, as in [SSSS08, Definition 1.5], but such a definition is very cumbersome due to a large number of special cases.The labeling algorithm provides a definition that, in our experience, is easier to work with.By induction on the term structure one can easily verify that the normal order redex, as well as the normal order reduction, is unique.A weak head normal form in L LR (L LR -WHNF) is either an abstraction λx.s, a constructor application (c s 1 . . .s ar(c i ) ), or an expression (letrec Env in v) where v is a constructor application or an abstraction, or an expression of the form (letrec We distinguish abstraction-WHNF (AWHNF) and constructor WHNF (CWHNF) based on whether the value v is an abstraction or a constructor application, respectively.The notions of convergence, divergence and contextual approximation are as defined in Sect. 2. If there is no normal order reduction originating at an expression s then s⇑ LR .This, in particular, means that expressions for which the labeling algorithm fails to find a redex, or for which there is no matching constructor for a subexpression (that is a WHNF) in a case redex position, or expressions with cyclic dependencies like letrec x = x in x, are diverging.
The labeling algorithm applied to s 1 yields (letrec x = (y V λu.u) V , y = (λz.z)S in x V ) V .
The reduction rule that matches this labeling is the reduction rule (cp-e), i.e. s 1 Concluding, the calculus L LR is defined by the tuple (E L , C L , LR − − →, A LR ) where A LR are the L LR -WHNFs, where we equate alpha-equivalent expressions, contexts and answers.
In [SSSS08] correctness of several program transformations was shown: Theorem 3.7 ([SSSS08, Theorems 2.4 and 2.9]).All reduction rules shown in Fig. 2 are correct program transformations, even if they are used with an arbitrary context C in the rules without requiring the labels.The transformations for garbage collection (gc) and for shifting of letrec-expressions (lwas) shown in Fig. 4 are also correct program transformations.In Fig. 5 the rules of the labeling algorithm for L name are given.The algorithm uses the labels S and T .For an expression s the labeling starts with s T .
An L name reduction context R name is any context where the hole is labeled T or S by the labeling algorithm, or more formally they can be defined as follows: Definition 3.8.Reduction contexts R name are contexts of the form L[A] where the context classes A and L are defined by the following grammar, where s is any expression: Normal order reduction name − −− → of L name is defined by the rules shown in Fig. 6 where the labeling algorithm according to Fig. 5 must be applied first.Note that the rules (seq-c), (lapp), (lcase), and (lseq) are identical to the rules for L LR (in Fig. 2), but the labeling algorithm is different.
Unlike L LR , the normal order reduction of L name allows substitution of arbitrary expressions in (beta), (case), and (gcp) rules.An additional simplification (compared to L LR ) is that nested letrec-expressions are not flattened by reduction (i.e.there is no (llet)-reduction in L name ).As in L LR the normal order reduction of L name has reduction rules (lapp), (lcase), and (lseq) to move letrec-expressions out of an application, a seqexpression, or a case-expression.3.3.The Extended Lazy Lambda Calculus L lcc .In this subsection we give a short description of the lazy lambda calculus [Abr90] extended by data constructors, case-expressions and seq-expressions, denoted with L lcc .Unlike the calculi L name and L LR , this calculus has no letrec-expressions.The set E λ of L lcc -expressions is that of the usual (untyped) lambda calculus extended by data constructors, case, and seq:

Note that
Contexts C λ are E λ -expressions where a subexpression is replaced by the hole [•].The set A lcc of answers (or also values) are the L lcc -abstractions and constructor applications.Reduction contexts R lcc are defined by the following grammar, where s is any E λ -expression: reduction is defined by the three rules shown in Fig. 7, and thus the calculus 4.1.Characterizations of Similarity in Deterministic Calculi.In this section we prove that for deterministic calculi (see Def. 2.1), the applicative similarity and its generalization to extended calculi, defined as the greatest fixpoint of an operator on relations, is equivalent to the inductive definition using Kleene's fixpoint theorem.
This implies that for deterministic calculi employing only beta-reduction, applicative similarity can be equivalently defined as s t, iff for all n ≥ 0 and closed expressions r i , i = 1, . . ., n, the implication (s r 1 . . .r n )↓ D =⇒ (t r 1 . . .r n )↓ D holds, provided the calculus is convergence-admissible, which means that for all r: This approach has a straightforward extension to calculi with other types of reductions, such as case-and seq-reductions.The calculi may also consist of a set of open expressions, contexts, and answers, as well as a subcalculus consisting of closed expressions, closed contexts and closed answers.We will use convergence-admissibility only for closed variants of the calculi.
In the following we assume D = (E, C, →, A) to be an untyped deterministic calculus and Q ⊆ C be a set of functions on expressions.Note that the relations D,Q and ≤ D,Q are defined in Definitions 2.5 and 2.6, respectively.Lemma 4.1.For all expressions s 1 , s 2 ∈ E the following holds: s 1 D,Q s 2 if, and only if, ).This equation is equivalent to the claim of the lemma.Now we show that the operator F D,Q is lower-continuous, and thus we can apply Kleene's fixpoint theorem to derive an alternative characterization of D,Q .
For infinite chains of sets S 1 , S 2 . . ., we define the greatest lower bound w.r.t.setinclusion ordering as glb(S 1 , S 2 , . ..) ).Now we can move the universal quantifier for i inside the formula: Definition 4.3.Let D,Q,i for i ∈ N 0 be defined as follows: Proof.The claim follows from Kleene's fixpoint theorem, since F Q is monotonous and lowercontinuous, and since D,Q,i+1 ⊆ D,Q,i for all i ≥ 0. This representation of D,Q allows inductive proofs to show similarity.Now we show that Q-similarity is identical to ≤ D,Q under moderate conditions, i.e. our characterization result will only apply if the underlying calculus is convergence-admissible w.r.t.Q: Convergence-admissibility can be seen as a restriction on choosing the set Q: In most calculi (subsets of) reduction contexts satisfy the property for convergence-admissibility, while including non-reduction contexts into Q usually breaks convergence-admissibility.
Lemma 4.6.Let (E, C, →, A) be convergence-admissible w.r.t.Q.Then the following holds: Proof.The first part is easy to verify.For the second part it is important that D is deterministic.Let s 1 ≤ D,Q s 2 , and Finally, convergence-admissibility (applied multiple times) shows that It remains to show for all ) for all Q ∈ Q.We now prove that ≤ D,Q and Q-similarity coincide for convergence-admissible deterministic calculi: We use Theorem 4.4 and show s 1 D,Q,i s 2 for all i.We use induction on i.The base case (i = 0) obviously holds.Let i > 0 and let For the induction step we use the following induction hypothesis:  4.2.Applicative Simulation in L lcc .In this section we will show that applicative similarity and contextual preorder coincide in L lcc .
Notation.In abuse of notation we use higher order abstract syntax as e.g. in [How89] for the proof and write τ (..) for an expression with top operator τ , which may be all possible term constructors, like case, application, a constructor, seq, or λ, and θ for an operator that may be the head of a value, i.e. a constructor or λ.We say a binary relation µ is operator-respecting, iff s i µ t i for i = 1, . . ., n implies τ (s 1 , . . ., s n ) µ τ (t 1 , . . ., t n ).
Note that τ and θ may also represent the binding λ using λ(x.s) as representing λx.s.For consistency of terminology and treatment with that in other papers such as [How89], we assume that removing the top constructor λx in relations is done after a renaming.For example, λx.s µ λy.t is renamed before further treatment to λz.s[z/x] µ λz.t[z/y] for a fresh variable z.
Plan of Subsection 4.2.We start by explaining the subgoals of the soundness and completeness proofs for similarities in L lcc and its structure, illustrated in Fig. 8 Another obstacle is that the contextual preorder contains the irregularity λx.Ω ≤ lcc c s 1 . . .s n for any constructor c.This requires an adapted definition of the similarity relation, and a slightly modified proof route.
In the following let cBot be the set of E λ -expressions s with the property that for all E λ -substitutions σ: if σ(s) is closed, then σ(s)⇑ lcc .That λx.s ≤ lcc (c s 1 . . .s n ) indeed holds is shown in Proposition 4.32.Now we define an applicative similarity lcc in L lcc analogous to [How89,How96], where this irregularity is taken into account.
Definition 4.10 (Similarity in L lcc ).Let η be a binary relation on closed E λ -expressions.Let F lcc be the following operator on relations on closed E λ -expressions: ) and the relation s ′ i η t ′ i holds for all i Similarity lcc is defined as the greatest fixpoint of the operator F lcc .Bisimilarity ≃ lcc is defined as s ≃ lcc t iff s lcc t ∧ t lcc s.
Note that the operator F lcc is monotone, hence the greatest fixpoint lcc exists.4.2.1.Similarity and Contextual Preorder Coincide in L lcc .Although applying Howe's proof technique is standard, for the sake of completeness, and to demonstrate that the irregularity λx.Ω ≤ lcc (c s 1 . . .s n ) can also be treated, we will explicitly show in this section that o lcc = ≤ lcc using Howe's method [How89,How96].Lemma 4.11.For a relation η on closed expressions it holds ((η) o ) c = η, and also s η o t implies σ(s) η o σ(t) for any substitution σ.For a relation µ on open expressions, µ ⊆ ((µ) c ) o is equivalent to s µ t =⇒ σ(s) (µ) c σ(t) for all closing substitutions σ.Proposition 4.12 (Co-Induction).The principle of co-induction for the greatest fixpoint of F lcc shows that for every relation η on closed expressions with η ⊆ F lcc (η), we derive η ⊆ lcc .This obviously also implies (η The fixpoint property of lcc implies: Lemma 4.13.For a closed value θ 1 (s 1 , . . ., s n ), and a closed term t with θ 1 (s 1 , . . ., s n ) lcc t, we have t↓ lcc θ 2 (t 1 , . . ., t n ), and there are two cases: (1) θ 1 = θ 2 are constructors or λ and s i o lcc t i for all i.
(2) θ 1 (s 1 , . . ., s n ) = λ(x.s)with s ∈ cBot and θ 2 is a constructor.Lemma 4.14.For two expressions s, t: s ∈ cBot implies s o lcc t.Thus any two expressions s, t ∈ cBot are bisimilar: s ≃ o lcc t.Particular expressions in cBot are (case (λx.s) alts) and (c(s 1 , . . ., s n ) a 1 . . .a m ) for m ≥ 1; also s ∈ cBot implies that (s t), (seq s t), (case s alts) and σ(s) are also in cBot.The goal in the following is to show that lcc is a precongruence.This proof proceeds by defining a precongruence candidate cand as a closure of lcc within contexts, which obviously is operator-respecting, but transitivity needs to be shown.By proving that o lcc and cand coincide, on the one hand transitivity of cand follows (since lcc is transitive) and on the other hand (and more importantly) it follows that o lcc is operator-respecting (since cand is operator-respecting) and thus a precongruence.
Definition 4.16.The precongruence candidate cand is a binary relation on open expressions and is defined as the greatest fixpoint of the monotone operator F cand on relations on all expressions: Since cand is a fixpoint of F cand , we have: Some technical facts about the precongruence candidate are now proved: Lemma 4.19.The following properties hold: (1) cand is reflexive.
Part (6) follows from item (5).Part (7) where we assume that the redex s is not at the top level and that R is an L lcc -reduction context.The relation R[s] cand t implies that R[s] = τ (s 1 , . . ., s n ) and that there is some Proof.This follows from Lemmas 4.21 and 4.30.Now we show a characterization for E λ -expressions, which includes the previously mentioned irregularity of ≤ lcc : Proposition 4.32.Let s be a closed L lcc -expression.Then there are three cases: s ∼ lcc Ω, s ∼ lcc λx.s ′ for some s ′ , s ∼ lcc (c s 1 . . .s n ) for some terms s 1 , . . ., s n and constructor c.
For two closed L lcc -expressions s, t with s ≤ lcc t: Either s ∼ lcc Ω, or s ∼ lcc (c s 1 . . .s n ), t ∼ lcc (c t 1 . . .t n ) and s i ≤ lcc t i for all i for some terms s 1 , . . ., s n , t 1 , . . ., t n and constructor c, or s ∼ lcc λx.s ′ and t ∼ lcc λx.t ′ for some expressions s ′ , t ′ with s ′ ≤ o lcc t ′ , or s ∼ lcc λx.s ′ and t ∼ lcc (c t 1 . . .t n ) for some term s ′ ∈ cBot, expressions t 1 , . . ., t n and constructor c.
Proof.We apply Lemma 4.30.Corollary 4.31 then shows that using reduction the classification of closed expressions into the classes w.r.t.∼ lcc holds.
For two closed L lcc -expressions s, t with s lcc t: we obtain the classification in the lemma but with lcc instead of ≤ lcc .For the three cases s ≃ lcc Ω, both s, t are equivalent to constructor expressions, and both s, t are equivalent to abstractions, we obtain also that s ≤ lcc t.In the last case λx.s ′ lcc (c s 1 . . .s n ), we also obtain from the lcc -definition, that it is valid and from Lemma 4.30, that it implies λx.s ′ ≤ lcc (c s 1 . . .s n ).Other combinations of constructor applications, abstractions and Ω cannot be in ≤ lcc -relation:  where all right hand sides of other case-alternatives are Ω.The relations lcc,Q lcc , ≤ lcc,Q lcc are instantiations of Definitions 2.5 and Definition 2.6, respectively, with the set Q lcc and the closed part of L lcc consisting of the subsets of all closed E λ -expressions, closed contexts C λ , and closed answers A lcc .
Lemma 4.36.The calculus L lcc is convergence-admissible in the sense of Definition 4.5, where the Q-contexts are defined as above.
Proof.Values in L lcc are L lcc -WHNFs.The contexts Q are reduction contexts in L lcc .Hence every reduction of Q[s] will first evaluate s to v and then evaluate Q The first equation is proved by showing that the relations satisfy the fixpoint equations of the other one in Definition 4.10 and 2.5, respectively.
• lcc ⊆ F Q ( lcc ): Assume s lcc t for two closed s, t.If s↓ lcc v, then t↓ lcc w for values v, w.Since reduction preserves ≃ lcc , the fixpoint operator conditions are satisfied if v, w are both abstractions or both constructor applications.If v = λx.s′ with s ′ ∈ cBot and Then also t↓ lcc w for some value w.In the cases that v, w are both abstractions or both constructor applications, when using appropriate Q of kind (ii) or (iii), the F lcc -conditions are satisfied.If v = λx.s′ and w = c(t 1 , . . ., t n ), we have to show that s ′ ∈ cBot: this can be done using all Q-contexts of the form ([] r), since (w r)⇑ lcc in any case.
Definition 4.38.Let CE lcc be the following set of closed E λ -expressions built from constructors, Ω, and closed abstractions.These can be constructed according to the grammar: where λx.s is any closed E λ -expression.The set Q CE is defined like the set Q lcc in Definition 4.35, but only expressions r from CE lcc are taken into account in the contexts ([•] r) in (i).
We summarize several alternative definitions for contextual preorder and applicative simulation for L lcc , where we also include further alternatives.( 1) is contextual preorder, (2) the applicative simulation, (3), (4) and ( 5) are similar to the usual call-by-value variants, where (4) and (5) separate the closing part of contexts, where (5) can be seen as bridging the gap between call-by-need and call-by-name.( 7) is the Q-similarity, (8) is a further improved inductive Q-simulation by restricting the set of test arguments for abstractions, and ( 9) is the co-inductive version of (8).
It is easy to verify that the reduction for C[s 1 ] can also be performed for It is easy to verify that no term in this sequence can be of the form R[Ω], where R is a reduction context, since otherwise the reduction would not terminate (since ).This implies that we can replace the Ω-expression by the free variables, i.e. that C[s 2 ]↓ lcc .Note that this also shows by the previous items (and Corollary 4.31) that (nbeta) is correct for ∼ lcc .
• (1) ⇐⇒ (4): This follows from Corollary 4.31 since closing substitutions can be simulated by a context with subsequent (nbeta)-reduction.This also implies that (nbeta) is correct for ∼ lcc,2 and by the previous item it also correct for ∼ lcc,1 (where The direction " =⇒ " is trivial.For the other direction let s 1 ≤ lcc s 2 and let C be a context, σ be a substitution, such that We show the other direction by induction on n -the number of holes in M -that for all E λ -expressions s 1 , s 2 : The base cases for n = 0, 1 are obvious.For the induction step assume that and hence M ′′ [σ(s 1 ), . . ., σ(s 1 )]↓ lcc .Now, since the number of holes of M ′′ is strictly smaller than n, the induction hypothesis show that • (7) ⇐⇒ (8): The direction ( 7) =⇒ (8) is trivial.
For the other direction we show that to an L lcc -WHNF.Since the reduction rules are correct w.r.t.∼ lcc , for every subexpression r of the contexts Q i , there is some r ′ with r ′ ≤ lcc r, where r ′ ∈ Q CE , which is derived from r by (top-down)-reduction, which may also be non-normal order, i.e. r lcc, * − −− → r m+1 where r m+1 has reducible subexpressions (not in an abstraction) only at depth at least m + 1.All those deep subexpressions are then replaced by Ω, and this construction results in r ′ .By construction, r ′ ≤ lcc r.We do this for all the contexts Q i , and obtain thus contexts )↓ lcc , since the normal-order reduction does not use subexpressions at depth greater than m in those r ′ .By assumption, this implies (Q We finally consider a more relaxed notion of similarity which allows to use known contextual equivalences as intermediate steps when proving similarity of expressions: Definition 4.43 (Similarity up to ∼ lcc ).Let lcc,∼ be the greatest fixpoint of the following operator F lcc,∼ on closed L lcc -expressions: We define an operator F lcc,∼ on binary relations η on closed L lcc -expressions: s F lcc,∼ (η) t iff the following holds: (1) If s ∼ lcc λx.s ′ then there are two possibilities: Obviously, we have s lcc,∼ t iff one of the three cases holds: (i) s ∼ lcc λx.s ′ , t ∼ lcc λx.t ′ , and (λx.s ′ ) r lcc,∼ (λx.t ′ ) r for all closed r; (ii) s ∼ lcc λx.s ′ , t ∼ lcc (c t 1 . . .t n ), and s ′ ∈ cBot, or (iii) s ∼ lcc (c s 1 . . .s n ), t ∼ lcc (c t 1 . . .t n ), and s i lcc,∼ t i for all i.  (ii) We prove that the relation lcc satisfies the fixpoint equation for F lcc,∼ : Let s lcc t for closed s, t.We know that this is the same as s The translation W : L LR → L name is defined as the identity on expressions and contexts, but the definitions of convergence predicates are different.In this section we prove that contextual equivalence based on L LR -evaluation and contextual equivalence based on L nameevaluation are equivalent.We use infinite trees to connect both evaluation strategies.In [SS07] a similar result was shown for a lambda calculus without seq, case, and constructors.5.1.Calculus for Infinite Trees L tree .We define infinite expressions which are intended to be the letrec-unfolding of the E L -expressions with the extra condition that cyclic variable chains lead to local nontermination represented by Bot.We then define the calculus L tree which has infinite expressions and performs reduction on infinite expressions.Definition 5.1.Infinite expressions E I are defined like expressions E L without letrecexpressions, adding a constant Bot, and interpreting the grammar co-inductively, i.e. the grammar is as follows In order to distinguish in the following the usual expressions from the infinite ones, we say tree or infinite expressions.As meta-symbols we use s, s i , t, t i for finite expressions and S, T, S i , T i for infinite expressions.The constant Bot is without any reduction rule.
In the following definition of a mapping from finite expressions to their infinite images, we sometimes use the explicit binary application operator @ for applications inside the trees (i.e. an application in the tree is sometimes written as (@ S 1 S 2 ) instead of (S 1 S 2 )), since it is easier to explain, but use the common notation in other places.A position is a finite sequence of positive integers, where the empty position is denoted as ε.We use Dewey notation for positions, i.e. the position i.p is the sequence starting with i followed by position p.For an infinite tree S and position p, the notation S| p means the subtree at position p and p(S) denotes the head symbol of S| p .
This induces the representation of an infinite expression S as a (partial) function S from positions to labels where application of the function S to a position p is written as p(S) and where the labels are @, case T , (c x 1 . . .x n ) (for a case-alternative), seq, c, λx, and x.The domain of such a function must be a prefix-closed set of positions, and the continuations of a position p depend on the label at p and must coincide with the syntax according to the grammar in Definition 5.1.
Definition 5.2.The translation IT : E L → E I translates an expression s ∈ E L into its infinite tree IT (s) ∈ E I .We define the mapping IT by providing an algorithm that, computes the partial function IT (s) from positions to labels.Given a position p, computing p(IT (s)) starts with s p and then proceeds with the rules given in Fig. 9.The first group of rules defines the computed label for the position ε, the second part of the rules describes the general case for positions.If the computation fails (or is undefined), then the position is not valid in the tree IT (s).The equivalence of infinite expressions is extensional equality of the corresponding functions, where we additionally do not distinguish α-equal trees.

C[(s t)
The cases for general positions p: If the position ε hits the same (let-bound) variable twice, then the result is Bot.(This can only happen by a sequence of rules 11,12,13.)Figure 9: Infinite tree construction from positions for fixed s The set C I of infinite tree contexts includes any infinite tree where a subtree is replaced by a hole [•].Reduction contexts on trees are defined as follows: Definition 5.4.Call-by-name reduction contexts R tree of L tree are defined as follows, where the grammar is interpreted inductively and S ∈ E I : For an infinite tree, a reduction position p is any position such that p(S) is defined and there exists some R ∈ R tree with R[S ′ ] = S and R| p = [•] Definition 5.5.An L tree -answer (or an L tree -WHNF) is any infinite E I -expression S which is an abstraction or constructor application, i.e. ε(S) = λx or ε(S) = c for some constructor c.The reduction rules on infinite expressions are allowed in any context and are as follows: Here S 1 is the tree-redex of the tree-reduction.We also use the convergence predicate ↓ tree for infinite trees defined as: S↓ tree iff S tree, * − −− → S ′ and S ′ is an L tree -WHNF.Concluding, the calculus L tree is defined by the tuple (E I , C I , tree − − →, A tree ) where A tree are the L tree -WHNFs.

Note that
In the following we use a variant of infinite outside-in developments [Bar84, KKSdV97] as a reduction on trees that may reduce infinitely many redexes in one step.The motivation is that the infinite trees corresponding to finite expressions may require the reduction of infinitely many redexes of the trees for one Definition 5.6.We define an infinite variant of Barendregt's 1-reduction: Let S ∈ E I be an infinite tree.Let † be a special label and M be a set of (perhaps infinitely many) positions of S, which must be redexes w.r.t. the same reduction a ∈ {(betaTr), (caseTr), or (seqTr)}.Now exactly all positions m ∈ M of S are labeled with †.By S I,M −−→ S ′ we denote the (perhaps infinite) development top down, defined as follows: • Iteratively compute M i+1 and S i+1 from M i and S i for i = 0, 1, 2, . . .as follows: Let d be the length of the shortest position in M i , and M i,d be the finite set of positions that are the shortest ones in M i .For every p ∈ M i,d construct an infinite tree T p from S i | p by iterating the following reduction until the root of S i | p is not labeled: remove the label from the top of S i | p , then perform a labeled reduction inheriting all the labels.If this iteration does not terminate, because the root of S i | p gets labeled in every step, then the result is T p := Bot (unlabeled), otherwise a result T p is computed after finitely many reductions.Now construct S i+1 by replacing every subtree at a position p ∈ M i,d in S i by T p : for the positions p of S i that do not have a prefix that is in M i,d , we set p(S i+1 ) := p(S i ) and for p ∈ M i,d we set S i | p := T p .
Let M i+1 be the set of positions in S i+1 which carry a label †.The length of the shortest position is now at least d + 1.Then iterate again with M i+1 , S i+1 .
• S ′ is defined as the result after (perhaps infinitely many) construction steps S 1 , S 2 , . . .There may be S, S ′ such that S I,M −−→ S ′ as well as S I,M ′ − −− → S ′ for some sets M, M ′ where M contains a reduction position, but M ′ does not contain a reduction position.For example S = (λx 1 .x 1 ) ((λx 2 .x 2 ) ((λx 3 .x3 ) . ..)),where a single (betaTr)-reduction at the top reproduces S, as well as a single (betaTr)-reduction of the argument.5.2.Standardization of Tree Reduction.Before considering the concrete calculi L LR and L name and their correspondence to the calculus with infinite trees, we show that for an arbitrary reduction sequence on infinite trees resulting in an answer we can construct a tree-reduction sequence that results in an L tree -WHNF.Lemma 5.10.Let T be an infinite tree such that there is a tree-reduction sequence of length n to a WHNF T ′ , and let S be an infinite tree with T I,M −−→ S. Then S has a tree-reduction sequence of length ≤ n to a WHNF T ′′ .
Proof.This follows from Lemma 5.9 by induction on n.
Proof.The argument is that the set M 3 is computed by labeling the positions in T using M 1 , and then by performing the infinite development using the set of redexes M 2 , where we assume that the M 1 -labels are inherited.The set of positions of marked redexes in T k for a reduction context R k and where S k−1 is the redex and S k is the contractum of T k−1 → T k and the normal order tree-redex of M k labels a subterm of S k .This holds, since the infinite development for T I,M −−→ T ′ is performed top down.This implies that the infinite tree-reduction goes deeper and deeper along one path of the tree, or at some point all remaining tree-reductions are performed at the same position.
where R k is a reduction context, and M k labels the hole of R k , which is the normal order redex.The normal order reduction is k ] =: T k+1 .Let p k be the path of the hole of R k , together with the constructors and symbols (case, seq, constructors and @) on the path.Also let , (where • ∪ means disjoint union) where the labels of M k,1 are in R k , and the labels M k,2 are in S k .Lemma 5.11, the structure of the expressions and the properties of the infinite top down developments show that the normal order redex can only stay or descend, i.e. h > k implies that p k is a prefix of p h .

Also, we have
, and S k I − → S ′ .There are three cases: • The normal order reduction of T 0 halts, i.e., there is a maximal k.Then obviously −−→ T ′ will reduce infinitely often at the position of the hole, hence it will plug a Bot at position p k of T ′ , and so . But then T ′ cannot converge, and so this case is not possible.
• The positions p k of the reduction contexts R k will grow indefinitely.Then there is an infinite path (together with the constructs and symbols) p such that p k is a prefix of p for every k.Moreover, p is a position of T ′ .The sets M k,1 are an infinite ascending set w.r.t.
⊆, hence there is a limit tree T ∞ with T tree,∞ − −−− → T ∞ , which is exactly the limit of the contexts R k for k → ∞.There is a reduction Hence T ′ has the path p, and we see that the tree T ′ cannot have a normal order redex, since the search for such a redex goes along p and thus does not terminate.This is a contradiction, and hence this case is not possible.
If M does not contain a normal order redex, then the induction hypothesis shows that T 1 ↓ tree and thus also T ↓ tree .Now assume that M contains a normal order redex.Then we apply Lemma 5.12 to T 1 I,M −−→ T 0 (note that T 0 ↓ tree and hence the lemma is applicable).
Now we can apply the induction hypothesis to T ′′ contains a normal order redex, then we apply Lemma 5.12 and have the following situation i is an L tree -WHNF.We apply Lemma 5.In this section we will show that L LR -convergence for finite expressions s ∈ E L coincides with convergence for the corresponding infinite tree IT (s).
Lemma 5.17.Let s be a finite expression.If s is an L LR -WHNF then IT (s) is an answer.If IT (s) is an answer, then s↓ LR .Proof.If s is an L LR -WHNF, then obviously, IT (s) is a answer.If IT (s) is an answer, then the label computation of the infinite tree for the empty position using s, i.e. s ε , must be λx or c for some constructor.If we consider all the cases where the label computation for s ε ends with such a label, we see that s must be of the form NL[v ], where v is an L LR -answer and the contexts NL are constructed according to the grammar: We show by induction that every expression NL[v ], where v is a value, can be reduced by normal order (cp)-and (llet)-reductions to a WHNF in L LR .We use the following induction measure µ on NL[v ]: The base case obviously holds, since v is already an L LR -WHNF.For the induction step as- Let NL, and v be fixed, such that µ(NL[v ]) = k ≥ 1 .There are two cases: Otherwise NL ′ [v ] is a letrec-expression.Thus we can apply an (LR, (llet-in))-reduction to NL[v ], where the measure µ is decreased by one.The induction hypothesis shows the claim.
] is a letrec-expression, then we can apply an (LR, llet-in)-reduction to NL[v ] and the measure µ is decreased by 1.If NL n+1 is the empty context, and there is some i such that NL i is not the empty context, then we can choose the largest number i and apply an (LR, llet-e)-reduction to NL[v ].Then the measure µ is strictly decreased and we can use the induction hypothesis.If all the contexts NL i for i = 1, . . ., n + 1 are empty contexts, then either NL[v ] is an L LR -WHNF (if v is a constructor application) or we can apply an (LR, cp) reduction to obtain an L LR -WHNF.Proof.Only the latter needs a justification.Therefore, we label every redex in IT (s) that is derived from the redex s LR − − → t by IT (.).This results in the set M for IT (s).There will be at least one position in M that is a normal order redex of IT (s).
Proof.We assume that s LR, * − −− → t, where t is a WHNF.Using Lemma 5.18, we see that there is a finite sequence of reductions IT (s) I , * − − → IT (t).Lemma 5.17 shows that IT (r ) is an L tree -WHNF.Now Proposition 5.15 shows that IT (s)↓ tree .
We now consider the other direction and show that for every expression s: if IT (s) converges, then s converges, too.
Then for (a ′ , a) ∈ {(betaTr, lbeta), (caseTr, case), (seqTr, seq)} there exist expressions s 1 , s 2 , s 3 and an infinite tree T ′ with s Proof.Let p be the position of the hole of R. We follow the label computation to T along p inside s and show that the redex corresponding to T can be found in s after some (lll) and (cp) reductions.For applications, seq-expressions, and case-expressions there is a one-toone correspondence.If the label computation shifts a position into a "deep" letrec, i.To join the reductions we perform an I,M −−→-reduction for IT (s) where all redexes are labeled in M , which also results in Bot.
Proposition 5.22.Let s be an expression such that IT (s)↓ tree .Then s↓ LR .
Proof.The precondition IT (s)↓ tree implies that there is a tree-reduction sequence of IT (s) to an L tree -WHNF.The base case, where no tree-reductions are necessary, is treated in Lemma 5.17.In the general case, let T Lemma 5.25.For (a, a ′ ) ∈ {(beta, betaTr), (case, caseTr), (seq, seqTr)} it holds: 1 is mapped by IT to a unique tree position within a tree reduction context in IT (s 1 ).We only consider the (beta)-reduction, since for a (case)-or a (seq)-reduction the reasoning is completely analogous.So let us assume that s )) where σ is a substitution replacing variables by infinite trees.The tree reduction replaces σ((λx.IT (s ′′ 1 )) IT (s ′′ 2 )) by σ(IT (s ′′ 1 ))[σ(IT (s ′′ 2 ))/x ], hence the lemma holds.
Proposition 5.26.Let s ∈ E L be an expression with s↓ name .Then IT (s)↓ tree .
Proof.This follows by induction on the length of a normal order reduction of s.The base case holds since IT (L[v ]), where v is an L name -answer is always an L tree -answer.For the induction step we consider the first reduction of s, say s ] is a reduction context for some L-context L and some A-context A, s ′′ may be an abstraction, a constructor application, or a beta-, case-or seq-redex iff T is an abstraction, a constructor application, or a betaTr-, caseTr-or seqTr-redex, respectively, and the position p of the hole in R is also the position of the hole in A[•].
Proof.The tree T may be an abstraction, a constructor application, an application, or a betaTr-, caseTr-or seqTr-redex in R[T ].Let p be the position of the hole of R. We will show by induction on the label-computation for p in s that there is a reduction We consider the label-computation for p to explain the induction measure, where we use the numbers of the rules given in Fig. 9. Let q be such that the label computation for p is of the form (10) * .qand q does not start with (10).The measure for induction is a tuple (a, b), where a is the length of q, and b ≥ 0 is the maximal number with q = (2 ∨ 4 ∨ 6) b .q′ .The base case is (a, a): Then the label computation is of the form (2 ∨ 4 ∨ 6) * and indicates that s is of the form L[A[s ′′ ]] and satisfies the claim of the lemma.For the induction step we have to check several cases: (1) The label computation starts with (10) * (2 ∨ 4 ∨ 6) + (10).Then a normal-order (lapp), (lcase), or (lseq) can be applied to s resulting in s 1 .The label-computation for p w.r.t.s 1 is of the same length, and only applications of (10) and (2 ∨ 4 ∨ 6) are interchanged, hence the second component of the measure is strictly decreased.(2) The label computation starts with (10) * (2 ∨ 4 ∨ 6) * (11).Then a normal-order (gcp) can be applied to s resulting in s 1 .The length q is strictly decreased by 1, and perhaps one (12)-step is changed into a (11)-step.Hence the measure is strictly decreased.In every case the claim on the structure of the contexts and s ′ can easily be verified.Proof.We use induction on the length k of a tree reduction IT (s) tree,k −−−→ T , where T is an L tree -answer.For the base case it is easy to verify that if IT (s) is an L tree -answer, then s Proof.In Corollary 5.30 we have shown that L name -convergence is equivalent to infinite tree convergence.In Theorem 5.23 we have shown that L LR -convergence is equivalent to infinite tree convergence.Hence, L name -convergence and L LR -convergence are equivalent, which further implies that both contextual preorders and also the contextual equivalences are identical.
Corollary 5.32.The translation W is convergence equivalent and fully abstract.
Since W is the identity on expressions, this implies: Corollary 5.33.W is an isomorphism according to Definition 2.7.
A further consequence of our results is that the general copy rule (gcp) is a correct program transformation in L LR .This is a novel result, since in previous work only special cases were proved correct.The idea of the translation is to replace (letrec x 1 = s 1 , . . ., x n = s n in t) by t[B 1 /x 1 , . . ., B n /x n ] where B i := Y n i F 1 . . .F n and F i := λx 1 , . . ., x n .si .In this way the fixpoint combinators implement the generalized fixpoint property: Y n i F 1 . . .F n ∼ F i (Y n 1 F 1 . . .F n ) . . .(Y n n F 1 . . .F n ).However, our translation uses modified expressions, as shown below.

On Similarity in L LR
In this section we will explain co-inductive and inductive (bi)similarity for L LR .Our results of the previous sections then enable us to show that these bisimilarities coincide with contextual equivalence in L LR .7.1.Overview of soundness and completeness proofs for similarities in L LR .Before we give details of the proof for lifting soundness and completeness of similarities from L lcc to L LR , we show an outline of the proof in Fig. 11.The diagram shows fully abstract translations between the calculi L LR , L name , and L lcc defined and studied in Sections 5 and 6, where Corollary 5.32 and Theorem 6.16 show full abstractness for W and N , respectively.These fully-abstract translations that are also surjective, and the identity on letrec-free expressions, allow us to prove that s 1 ≤ LR s 2 ⇐⇒ N (W (s 1 )) ≤ lcc N (W (s 2 )).By Theorem 4.37 in L lcc , this is equivalent to N (W (s 1 )) o lcc N (W (s 2 )).The proof is completed by using the translations by transferring the equations back and forth between L LR and L lcc in this section in order to finally show that s 1 ≤ LR s 2 ⇐⇒ s 1 o LR,Q CE s 2 in Theorem 7.6.First we show that finite simulation (see [SSM08]) is correct for L LR : Proof.The ⇒ direction is trivial.We show ⇐, the nontrivial part: Assume that the inequation s 1 ≤ LR,Q CE s 2 holds.Then N (W (s 1 )) ≤ lcc,Q CE N (W (s 2 )), since for every n ≥ 0 and context Q = Q n (. . .(Q 2 (Q 1 []) . ..)) with Q i ∈ Q CE , we have N (W (Q)) = Q, and also Q(s i ) ↓ LR ⇐⇒ Q(s i ) ↓ lcc , since N •W is convergence-equivalent and compositional, and the identity on letrec-free expressions.Now Theorem 4.39 shows N (W (s 1 )) ≤ lcc N (W (s 2 )), and then Theorem 6.16 shows s 1 ≤ LR s 2 .
The following lemma is helpful in applying Theorem 4.8.The "⇐"-direction can be proven using induction on the length of reduction sequences.

Figure 3 :
Figure 3: Labeling algorithm for L LR

Figure 4 :
Figure 4: Transformations for garbage collection and letrec-shifting

Figure 6 :
Figure 6: Normal order reduction rules name − −− → of L name name − −− → is unique.An L name -WHNF is defined as an expression either of the form L[λx.s] or of the form L[(c s 1 . . .s ar(c) )] where L is an L context.Let A name be the set of L name -WHNFs, then the calculus L name is defined by the tuple (E L , C L , name − −− →, A name ) (modulo α-equivalence).

Figure 7 :
Figure 7: Normal order reduction lcc −→ of L lcc lcc o lcc open extension of similarity in lcc cand co-inductively defined candidate relation for Howe's technique

Figure 8 :
Figure 8: Structure of soundness and completeness proofs for similarities in L lcc .The =!= indicates a required equality which can only be proved via Howe's technique.
Definition 4.9.For a relation η on closed E λ -expressions η o is the open extension on L lcc : For (open) E λ -expressions s 1 , s 2 , the relation s 1 η o s 2 holds, if for all substitutions σ such that σ(s 1 ), σ(s 2 ) are closed, the relation σ(s 1 ) η σ(s 2 ) holds.Conversely, for binary relations µ on open expressions, (µ) c is the restriction to closed expressions.

( 7 )
cand ⊆ (( cand ) c ) o Proof.Parts (1) -(3) can be shown by structural induction and using reflexivity of o lcc .Part (4) follows from the definition, Lemma 4.18, and transitivity of o lcc .For part (5) let η := cand ∪ {(r[s/x], r ′ [s ′ /x]) | r cand r ′ }.Using co-induction it suffices to show that η ⊆ F cand (η): In the case x cand r ′ , we obtain x o lcc r ′ from the definition, and s ′ o lcc r ′ [s ′ /x] and thus x[s/x] cand r ′ [s ′ /x].In the case y cand r, we obtain y o lcc r ′ from the definition, and y[s/x] = y o lcc r ′ [s ′ /x] and thus y

Lemma 5. 8 .
Let T be an infinite expression.If T I,M,¬tree − −−−−− → T ′ for some M , where T ′ is an answer, then T is also an answer.Proof.This follows since an answer cannot be generated by I,M,¬tree − −−−−− →-reductions, since neither abstractions nor constructor expressions can be generated at the top position.Lemma 5.9.Any overlapping between a tree − − →-reduction and a I,M −−→-reduction can be closed as follows.The trivial case that both given reductions are identical is omitted.This follows by checking the overlaps of I − → with tree-reductions.The third diagram applies if the positions of M are removed by the tree-reduction.The second diagram applies if the tree-redex is included in M and the first diagram is applicable in all other cases.

T 2 that 1 I,M 2 − 1 I 1 I
remain and are not reduced by T −− → T 2 is exactly the set M 3 .Consider a reduction T I,M −−→ T ′ of type (betaTr), (caseTr) or (seqTr).This reduction may include a redex of a normal order tree-reduction.Then the reduction can be split into T tree − − → T − → T ′ , and splitting of the reduction can be iterated as long as the remaining T − → T ′ has a tree-redex.It may happen that this process does not terminate.We consider this non-terminating case, i.e. let T 0 I,M −−→ T ′ and we can assume that there exist infinitely many T 1 , T 2 , . . .and M 1 , M 2 , . . ., such that for any k: T 0 tree,k −−−→ T k and T k I,M k − −− → T ′ .By induction we can show for every k ≥ 1: Lemma 5.12.Let T I,M −−→ T ′ such that T ′ ↓ tree and M labels the normal order redex of T .Then there exists T ′′ and M ′ such that T tree, *− −− → T ′′ M ′ ,¬tree −−−−−→ T ′ .Proof.Let T = T 0 tree,k −−−→ T k , T k I,M k − −− → T ′where M k labels a normal order redex.
Lemma 5.13.Let T I,M,¬tree − −−−−− → T 1 tree − − → T ′ .Then the reduction can be commuted to T tree → T ′ for some M ′ .Proof.This follows since the I,M,¬tree − −−−−− →-reduction cannot generate a new normal order treeredex.Hence, the normal order redex of T 1 also exists in T .The set M ′ can be found by labeling T with M , then performing the tree-reduction where all labels of M are kept and inherited by the reduction, except for those positions which are removed by the reduction.Lemma 5.14.Let T I,¬tree − −−− → T ′ and T ′ ↓ tree .Then T ↓ tree .Proof.We show by induction on k that whenever T I,¬tree − −−− → T ′ tree,k −−−→ T ′′ where T ′′ is an L tree -WHNF, then T ↓ tree .The base case is k = 0 and it holds by Lemma 5.8.For the induction step let T I,¬tree − −−− → T ′ tree − − → T 0 tree,k −−−→ T ′′ .We apply Lemma 5.13 to T → T ′′ for some M .This situation can be depicted by the following diagram where the dashed reductions follow by Lemma 5.13: / / T ′ tree / / T 0 tree,k
e. C[(letrec Env in s) p ] → C[(letrec Env in s p )] where C is non-empty, then a sequence of normal order (lll)-reduction moves the environment Env to the top of the expression, where perhaps it is joined with a top-level environment of C. Let s LR,lll, * −−−−→ s ′ .Lemma 5.16 shows that IT (s ′ ) = IT (s) and the label computation along p for s ′ requires fewer steps than the computation for s.Hence this construction can be iterated and terminates.This yields a reduction sequence s LR,lll, * −−−−→ s 1 such that the label computation along p for s 1 does not shift the label into deep letrecs and where IT (s) = IT (s 1 ) (see Lemma 5.16).Now there are two cases: Either the redex corresponding to T is also a normal order redex of s 1 , or s 1 is of the form letrec x 1 = λx.s′ , x 2 = x 1 , . . ., x m = x m−1 , . . .R ′ [x m ] . ... For the latter case an (LR, cp) reduction is necessary before the corresponding reduction rule can be applied.Again Lemma 5.16 assures that the infinite tree remains unchanged.After applying the corresponding reduction rule, i.e. s 2 LR,a − −− → s 3 , the normal order reduction may have changed infinitely many positions of IT (s 3 ), while R[T ] tree,a ′ − −−− → R[T ′ ] does not change all these positions, but nevertheless Lemma 5.18 shows that there is a reduction R[T ] I,M,a ′ − −−− → IT (s 3 ), and Lemma 5.11 shows that also R[T ′ ] I,M ′ ,a ′ −−−−→ IT (s 3 ) for some M ′ .Example 5.21.An example for the proof of the last lemma is the expression s defined as s := letrec x = (λy.y)x in x.Then IT (s) = (λy.y)((λy.y)((λy.y) . ..)).The tree-reduction for IT (s) is IT (s) tree,betaTr − −−−−−− → IT (s).On the other hand the normal order reduction of L LR reduces to s ′ := letrec x = (letrec y = x in y) in x and IT (s ′ ) = Bot.
tree,a ′ − −−− → T ′ be a tree-reduction.Lemma 5.20 shows that there are expressions s ′ , s ′′ with s LR,lll, *−−−−→ LR,cp,0∨1 −−−−−−→ s ′ LR,a− −− → s ′′ , and T ′ I,M −−→ IT (s ′′ ).Lemma 5.10 shows that IT (s ′′ ) has a normal order tree-reduction to a WHNF where the number of tree-reductions is strictly smaller than the number of tree-reductions of T to a WHNF.Thus we can use induction on this length and obtain a normal order LR-reduction of s to a WHNF.Propositions 5.19 and 5.22 imply the theorem Theorem 5.23.Let s be an E L -expression.Then s↓ LR if and only if IT (s)↓ tree .5.4.Equivalence of Infinite Tree Convergence and L name -convergence.It is easy to observe that several reductions of L name do not change the infinite trees w.r.t. the translation IT (•): Lemma 5.24.Let s 1 , s 2 ∈ E L .Then s 1 name,a −−−−→ s 2 for a ∈ {gcp, lapp, lcase, lseq} implies IT (s 1 ) = IT (s 2 ).
Lemma 5.28.Let s be an expression with IT (s) tree − − → T .Then there is some s ′ with s name, * −−−−→ s ′ and IT (s ′ ) = T .Proof.If IT (s) tree − − → T , then IT (s) = R[S ] where R is a reduction context, S a tree-redex with S tree − − → S ′ and T = R[S ′ ].Let p be the position of the hole of R in IT (s).We apply Lemma 5.27, which implies that there is a reduction s name, * −−−−→ s ′ , such that IT (s) = IT (s ′ ) and s ′ = R[s ′′ ] where R = L[A[•]] is a reduction context and IT (L[s ′′ ]) is a beta-, case-, or seq-redex.It is obvious that s ′ = L[A[s ′′ ]] name,a −−−−→ t.Now one can verify that IT (t) = T must hold.Proposition 5.29.Let s be an expression with IT (s)↓ tree .Then s↓ name .
name,gcp, * − −−−−−− → L[v] for some L-context L and some L name -value v. Hence we have s↓ name .The induction step follows by repeated application of Lemma 5.28.Corollary 5.30.For all E L -expressions s: s↓ name if, and only if IT (s)↓ tree .Theorem 5.31.≤ name = ≤ LR .

1 ≤ LR s 2 s 1 ≤ 2 s 1 2 WFigure 11 :
Figure 11: The structure of the reasoning for the similarities in L LR for closed expressions.

7. 2 .
Similarity in L LR .The definition of L LR -WHNFs implies that they are of the form R[v], where v is either an abstraction λx.s or a constructor application (c s 1 . . .s ar(c i ) ), and where R is an L LR -AWHNF-context according to the grammar R ::= [•] | (letrec Env in [•]) if v is an abstraction, and R is an L LR -CWHNF-context according to the grammar R ::= [•] | (letrec Env in [•]) | (letrec x 1 = [•], {x i = x i−1 } m i=2 , Env in x m ) if v is a constructor application.Note that L LR -AWHNF-contexts and L LR -CWHNF-contexts are special L LRreduction contexts, also called L LR -WHNF-contexts.

Lemma 7 . 4 .
In L LR , the equation (≤ c LR ) o = ≤ LR holds.Proof.If s, t are (open) E L -expressions with s ≤ LR t, then (λx 1 . . . .x n .s)s 1 . . .s n ≤ c LR (λx 1 . . . .x n .t)s 1 . . .s n for closed expressions s i , and then by correctness of reduction in L LR , σ(s) ≤ c LR σ(t), and hence ≤ LR ⊆ (≤ c LR ) o .If for all closing E L -substitutions σ: σ(s) ≤ cLR σ(t), then using the fully abstract translations N • W , we obtainN • W (σ)(N • W (s)) ≤ c lcc N • W (σ)(N • W (t)), hence N • W (s) ≤ c lcc (N • W (t)) by Theorem 4.39.Again using fully abstractness of N • W , we obtain s ≤ LR t.Theorem 7.5.In L LR , for closed E L -expressions s and t the statements s LR,Q CE t, s ≤ LR,Q CE t and s ≤ LR t are all equivalent.Proof.Lemma 7.3 shows that Theorem 4.8 is applicable for the testing contexts from Q CE , i.e.LR,Q CE= ≤ LR,Q CE and Proposition 7.2 shows ≤ LR,Q CE = ≤ cLRFor open E L -expressions, we can lift the properties from L lcc , which also follows from full abstraction of N • W and from Lemma 4.40.The results above imply the following theorem:Main Theorem 7.6.≤ LR = o LR,Q CE .Proof.Theorem 7.5 shows LR,Q CE = ≤ LR,Q CE = ≤ c LR , hence o LR,Q CE = (≤ c LR ) o .Then Lemma 7.4 shows (≤ c LR ) o = ≤ LR = o LR,Q CE .The Main Theorem 7.6 implies that our embedding of L lcc into the call-by-need letrec calculus L LR (modulo ∼) is isomorphic w.r.t. the corresponding term models, i.e.Theorem 7.7.The identical embedding ι : E λ → E L is an isomorphism according to Definition 2.7.
Given an expression s, a sequence s → s 1 → . . .→ s n is called a reduction sequence; it is called an evaluation if s n is an answer, i.e. s n ∈ A; in this case we say s converges and denote this as s↓ D s n or as s↓ D if s n is not important.If there is no s n s.t.s↓ D s n then s diverges, denoted as s⇑ D .When dealing with multiple calculi, we often use the calculus name to mark its expressions and relations, e.g.
and the transitive and reflexive closure of → is denoted as * − →.The notation 0∨1 − − → means equality or one reduction, and k − → means k reductions.D − → denotes a reduction relation in D.
[How89,How96]sult we want to show is that contextual preorder ≤ lcc and o lcc,Q lcc coincide, where o lcc,Q lcc is the open extension of lcc,Q lcc , and lcc,Q lcc is Q-similarity introduced in Definition 2.5 instantiated with the subcalculus of L lcc which consists of closed expressions, closed contexts, and closed answers, and Q lcc is a specific set of small closed L lcc -contexts.Q-similarity does not allow a direct proof of soundness and completeness for contextual equivalence using Howe's method[How89,How96], since it is not stated in terms of the syntactic form of values derived by evaluation.We overcome this obstacle by defining another similarity lcc in L lcc for which we will perform the proof of soundness and completeness w.r.t.contextual preorder.Since the definition of lcc does not obviously imply that lcc is a precongruence, a candidate relation cand is defined, which is trivially compatible with contexts, but needs to be shown to be transitive.After proving cand = o lcc , i.e. that o lcc is a precongruence, soundness of o lcc w.r.t.contextual preorder ≤ lcc follows.Completeness can then also be proven.In a second step we prove that o lcc,Q lcc is sound and complete for contextual equivalence, i.e.≤ lcc = o lcc,Q lcc .After showing that L lcc is convergence-admissible we are also able to show that the inductive description ≤ lcc,Q lcc of Q-similarity coincides with lcc,Q lcc .
Lemma 4.26.If λx.s, λx.t are closed, λx.s cand λx.t, and t ∈ cBot , then also s ∈ cBot.Proof.For any closed r, we also have (λx.s)rcand(λx.t)r, since cand is operatorrespecting.From t ∈ cBot, we obtain that ((λx.t)r)⇑lcc.Now suppose that (λx.s) r Lemma 4.27.Let s, t be closed expressions such that s = θ(s 1 , ..., s n ) is a value and s cand t.Then there are two possibilities: (1) s = λx.s 1 , t↓ lcc c(t 1 , ..., t n ) where c is a constructor, and s 1 ∈ cBot.(2)there is some closed value t ′ = θ(t 1 , ..., t n ) with t ′ and for all i : s i cand t i .Proof.This follows from Lemma 4.23 and Lemma 4.26.Now we are ready to prove that the precongruence candidate and similarity coincide.Theorem 4.28.( cand ) c = lcc and cand = o lcc .Proof.Since lcc ⊆ ( cand ) c by Lemma 4.19, we have to show that ( cand ) c ⊆ lcc .Therefore it is sufficient to show that ( cand ) c satisfies the fixpoint equation for lcc .We show that ( cand ) c ⊆ F lcc (( cand ) c ).Let s ( cand ) c t for closed terms s, t.We show that s F lcc (( cand ) c ) t: If s ⇑ lcc , then s F lcc (( cand ) c ) t holds by Definition 4.10.If s↓ lcc θ(s 1 , . . ., s n ), then θ(s 1 , . . ., s n ) ( cand ) c t by Proposition 4.25.− −− → θ(t 1 , . . ., t n ) and for all i : s i cand t i .This implies s F lcc (( cand ) c ) t. Thus the fixpoint property of ( cand ) c w.r.t.F lcc holds, and hence ( cand ) c = lcc .Now we prove the second part.The first part, ( cand ) c ⊆ lcc , implies (( cand ) c ) o ⊆ Let s, t be expressions with s o lcc t such that C[s]↓ lcc .Let σ be a substitution that replaces all free variables of C[s], C[t] by Ω.The properties of the call-by-name reduction show that also σ(C[s])↓ Hence σ(C[t])↓ lcc .This is equivalent to C[t]↓ lcc , since free variables are replaced by Ω, and thus they cannot overlap with redexes.Hence o lcc ⊆ ≤ lcc .