Ugo Dal

Francesco Gavazzo

Effectful Normal Form Bisimulation

Normal form bisimulation, also known as open bisimulation, is a coinductive technique for higher-order program equivalence in which programs are compared by looking at their essentially infinitary tree-like normal forms, i.e. at their Böhm or Lévy-Longo trees. The technique has been shown to be useful not only when proving metatheorems about λ-calculi and their semantics, but also when looking at concrete examples of terms. In this paper, we show that there is a way to generalise normal form bisimulation to calculi with algebraic effects, à la Plotkin and Power. We show that some mild conditions on monads and relators, which have already been shown to guarantee effectful applicative bisimilarity to be a congruence relation, are enough to prove that the obtained notion of bisimilarity, which we call effectful normal form bisimilarity, is a congruence relation, and thus sound for contextual equivalence. Additionally, contrary to applicative bisimilarity, normal form bisimilarity allows for enhancements of the bisimulation proof method, hence proving a powerful reasoning principle for effectful programming languages.

Introduction

The study of program equivalence has always been one of the central tasks of programming language theory: giving satisfactory definitions and methodologies for it can be fruitful in contexts like program verification and compiler optimisation design, but also helps in understanding the nature of the programming language at hand. This is particularly true when dealing with higher-order languages, in which giving satisfactory notions of program equivalence is well-known to be hard. Indeed, the problem has been approached in many different ways. One can define program equivalence through denotational semantics, thus relying on a model. One could also proceed following the route traced by Morris [START_REF] Morris | Lambda Calculus Models of Programming Languages[END_REF], and define programs to be contextually equivalent when they behave the same in every context, this way taking program equivalence as the largest adequate congruence.

Both these approaches have their drawbacks, the first one relying on the existence of a (not too coarse) denotational model, the latter quantifying over all contexts, and thus making concrete proofs of equivalence hard. Among the many alternative techniques the research community has been proposing along the years, one can cite logical relations and applicative bisimilarity [START_REF] Appel | An indexed model of recursive types for foundational proof-carrying code[END_REF][START_REF] Benton | Relational semantics for effect-based program transformations: higher-order store[END_REF][START_REF] Abramsky | The lazy lambda calculus[END_REF], both based on the idea that equivalent higher-order terms should behave the same Thanks to the ANR projects 14CE250005 ELICA and 16CE250011 REPAS.

when fed with any (pair of related) inputs. This way, terms are compared mimicking any possible action a discriminating context could possibly perform on the tested terms. In other words, the universal quantification on all possible contexts, although not explicitly present, is anyway implicitly captured by the bisimulation or logical game.

Starting from the pioneering work by Böhm, another way of defining program equivalence has been proved extremely useful not only when giving metatheorems about λ-calculi and programming languages, but also when proving concrete programs to be (contextually) equivalent. What we are referring to, of course, is the notion of a Böhm tree of a λ-term e (see [START_REF] Barendregt | The lambda calculus: its syntax and semantics[END_REF] for a formal definition), which is a possibly infinite tree representing the head normal h form of e, if e has one, but also analyzing the arguments to the head variable of h in a coinductive way. The celebrated Böhm Theorem, also known as Separation Theorem [START_REF] Böhm | Alcune proprietà delle forme βη-normali del λk-calcolo[END_REF], stipulates that two terms are contextually equivalent if and only if their respective (appropriately η-equated) Böhm trees are the same.

The notion of equivalence induced by Böhm trees can be characterised without any reference to trees, by means of a suitable bisimilarity relation [START_REF] Lassen | Bisimulation in untyped lambda calculus: Böhm trees and bisimulation up to context[END_REF][START_REF] Sangiorgi | The lazy lambda calculus in a concurrency scenario[END_REF]. Additionally, Böhm trees can also be defined when λ-terms are not evaluated to their head normal form, like in the classical theory of λ-calculus, but to their weak head normal form (like in the call-by-name [START_REF] Lassen | Bisimulation in untyped lambda calculus: Böhm trees and bisimulation up to context[END_REF][START_REF] Sangiorgi | The lazy lambda calculus in a concurrency scenario[END_REF]), or to their eager normal form (like in the call-by-value λ-calculus [START_REF] Lassen | Eager normal form bisimulation[END_REF]). In both cases, the notion of program equivalence one obtains by comparing the syntactic structure of trees, admits an elegant coinductive characterisation as a suitable bisimilarity relation. The family of bisimilarity relations thus obtained goes under the generic name of normal form bisimilarity.

Real world functional programming languages, however, come equipped not only with higher-order functions, but also with computational effects, turning them into impure languages in which functions cannot be seen merely as turning an input to an output. This requires switching to a new model, which cannot be the usual, pure, λ-calculus. Indeed, program equivalence in effectful λcalculi [56,[START_REF] Moggi | Computational lambda-calculus and monads[END_REF] have been studied by way of denotational semantics [START_REF] Jones | Probabilistic non-determinism[END_REF][START_REF] De Liguoro | Non deterministic extensions of untyped lambdacalculus[END_REF][START_REF] Danos | Probabilistic game semantics[END_REF], logical relations [START_REF] Bizjak | Step-indexed logical relations for probability[END_REF][START_REF] Culpepper | Contextual equivalence for probabilistic programs with continuous random variables and scoring[END_REF], applicative bisimilarity [START_REF] Lassen | Relational Reasoning about Functions and Nondeterminism[END_REF][START_REF] Dal Lago | On coinductive equivalences for higherorder probabilistic functional programs[END_REF][START_REF] Crubillé | On probabilistic applicative bisimulation and call-byvalue lambda-calculi[END_REF], and normal form bisimilarity [START_REF] De Liguoro | Non deterministic extensions of untyped lambdacalculus[END_REF][START_REF] Leventis | Probabilistic böhm trees and probabilistic separation[END_REF]. While the denotational semantics, logical relation semantics, and applicative bisimilarity of effectful calculi have been studied in the abstract [START_REF] Goubault-Larrecq | Logical relations for monadic types[END_REF][START_REF] Johann | A generic operational metatheory for algebraic effects[END_REF][START_REF] Dal Lago | Effectful applicative bisimilarity: Monads, relators, and howe's method[END_REF], the same cannot be said about normal form bisimilarity. Particularly relevant for our purposes is [START_REF] Dal Lago | Effectful applicative bisimilarity: Monads, relators, and howe's method[END_REF], where a notion of applicative bisimilarity for generic algebraic effects, called effectful applicative bisimilarity, based on the (standard) notion of a monad, and on the (less standard) notion of a relator [START_REF] Thijs | Simulation and fixpoint semantics[END_REF] or lax extension [START_REF] Barr | Relational algebras[END_REF][START_REF]Monoidal Topology. A Categorical Approach to Order, Metric, and Topology[END_REF], is introduced.

Intuitively, a relator is an abstraction axiomatising the structural properties of relation lifting operations. This way, relators allow for an abstract description of the possible ways a relation between programs can be lifted to a relation between (the results of) effectful computations, the latter being described throughout monads and algebraic operations. Several concrete notions of program equivalence, such as pure, nondeterministic and probabilistic applicative bisimilarity [START_REF] Abramsky | The lazy lambda calculus[END_REF][START_REF] Lassen | Relational Reasoning about Functions and Nondeterminism[END_REF][START_REF] Ong | Non-determinism in a functional setting[END_REF][START_REF] Dal Lago | On coinductive equivalences for higherorder probabilistic functional programs[END_REF]] can be analysed using relators. Additionally, besides their prime role in the study of effectful applicative bisimilarity, relators have also been used to study logic-based equivalences [START_REF] Simpson | Behavioural equivalence via modalities for algebraic effects[END_REF] and applicative distances [START_REF] Gavazzo | Quantitative behavioural reasoning for higher-order effectful programs: Applicative distances[END_REF] for languages with generic algebraic effects.

The main contribution of [START_REF] Dal Lago | Effectful applicative bisimilarity: Monads, relators, and howe's method[END_REF] consists in devising a set of axioms on monads and relators (summarised in the notions of a Σ-continuous monad and a Σ-continuous relator ) which are both satisfied by many concrete examples, and that abstractly guarantee that the associated notion of applicative bisimilarity is a congruence.

In this paper, we show that an abstract notion of normal form (bi)simulation can indeed be given for calculi with algebraic effects, thus defining a theory analogous to [START_REF] Dal Lago | Effectful applicative bisimilarity: Monads, relators, and howe's method[END_REF]. Remarkably, we show that the defining axioms of Σ-continuous monads and Σ-continuous relators guarantee the resulting notion of normal form (bi)similarity to be a (pre)congruence relation, thus enabling compositional reasoning about program equivalence and refinement. Given that these axioms have already been shown to hold in many relevant examples of calculi with effects, our work shows that there is a way to "cook up" notions of effectful normal form bisimulation without having to reprove congruence of the obtained notion of program equivalence: this comes somehow for free. Moreover, this holds both when call-by-name and call-by-value program evaluation is considered, although in this paper we will mostly focus on the latter, since the call-by-value reduction strategy is more natural in presence of computational effects 1 .

Compared to (effectful) applicative bisimilarity, as well as to other standard operational techniques -such as contextual and CIU equivalence [START_REF] Morris | Lambda Calculus Models of Programming Languages[END_REF][START_REF] Mason | Equivalence in functional languages with effects[END_REF], or logical relations [START_REF] Reynolds | Types, abstraction and parametric polymorphism[END_REF][START_REF] Plotkin | Lambda-definability and logical relations[END_REF] -(effectful) normal form bisimilarity has the major advantage of being an intensional program equivalence, equating programs according to the syntactic structure of their (possibly infinitary) normal forms. As a consequence, in order to deem two programs as normal form bisimilar, it is sufficient to test them in isolation, i.e. independently of their interaction with the environment. This way, we obtain easier proofs of equivalence between (effectful) programs. Additionally, normal form bisimilarity allows for enhancements of the bisimulation proof method [START_REF] Pous | Enhancements of the bisimulation proof method[END_REF], hence qualifying as a powerful and effective tool for program equivalence.

Intensionality represents a major difference between normal form bisimilarity and applicative bisimilarity, where the environment interacts with the tested programs by passing them arbitrary input arguments (thus making applicative bisimilarity an extensional notion of program equivalence). Testing programs in isolation has, however, its drawbacks. In fact, although we prove effectful normal form bisimilarity to be a sound proof technique for (effectful) applicative bisimilarity (and thus for contextual equivalence), full abstraction fails, as already observed in the case of the pure λ-calculus [START_REF] Abramsky | Full abstraction in the lazy lambda calculus[END_REF][START_REF] Lassen | Eager normal form bisimulation[END_REF] (nonetheless, it is worth mentioning that full abstraction results are known to hold for calculi with a rich expressive power [START_REF] Sangiorgi | The lazy lambda calculus in a concurrency scenario[END_REF][START_REF] Støvring | A complete, co-inductive syntactic theory of sequential control and state[END_REF]).

In light of these observations, we devote some energy to studying some concrete examples which highlight the weaknesses of applicative bisimilarity, on the one hand, and the strengths of normal form bisimilarity, on the other hand.

This paper is structured as follows. In Section 2 we informally discuss examples of (pairs of) programs which are operational equivalent, but whose equivalence cannot be readily established using standard operational methods. Throughout this paper, we will show how effectful normal form bisimilarity allows for handy proofs of such equivalences. Section 3 is dedicated to mathematical preliminaries, with a special focus on (selected) examples of monads and algebraic operations. In Section 4 we define our vehicle calculus Λ Σ , an untyped λ-calculus enriched with algebraic operations, to which we give call-by-value monadic operational semantics. Section 5 introduces relators and their main properties. In Section 6 we introduce effectful eager normal form (bi)similarity, the call-by-value instantiation of effectful normal form (bi)similarity, and its main metatheoretical properties. In particular, we prove effectful eager normal form (bi)similarity to be a (pre)congruence relation (Theorem 2) included in effectful applicative (bi)similarity (Proposition 5). Additionally, we prove soundness of eager normal bisimulation up-to context (Theorem 3), a powerful enhancement of the bisimulation proof method that allows for handy proof of program equivalence. Finally, in Section 6.4 we briefly discuss how to modify our theory to deal with call-by-name calculi.

From Applicative to Normal Form Bisimilarity

In this section, some examples of (pairs of) programs which can be shown equivalent by effectful normal form bisimilarity will be provided, giving evidence on the flexibility and strength of the proposed technique. We will focus on examples drawn from fixed point theory, simply because these, being infinitary in nature, are quite hard to be dealt with "finitary" techniques like contextual equivalence or applicative bisimilarity. It is well known that Y and Z are contextually equivalent, although proving such an equivalence from first principles is doomed to be hard. For that reason, one usually looks at proof techniques for contextual equivalence. Here we consider applicative bisimilarity [START_REF] Abramsky | The lazy lambda calculus[END_REF]. As in the pure λ-calculus applicative bisimilarity coincides with the intersection of applicative similarity and its converse, for the sake of the argument we discuss which difficulties one faces when trying to prove Z to be applicatively similar to Y .

Let us try to construct an applicative simulation R relating Y and Z. Clearly we need to have (Y , Z) ∈ R. Since Y evaluates to λy.∆∆, and Z evaluates to λy.y(λz.ΘΘyz), in order for R to be an applicative simulation, we need to show that for any value v,

(∆[v/y]∆[v/y], v(λz.ΘΘvz)) ∈ R. Since the result of the evaluation of ∆[v/y]∆[v/y] is the same of v(λz.∆[v/y]∆[v/y]z),
we have reached a point in which we are stuck: in order to ensure (Y , Z) ∈ R, we need to show that (v(λz.∆[v/y]∆[v/y]z), v(λz.ΘΘvz)) ∈ R. However, the value v being provided by the environment, no information on it is available. That is, we have no information on how v tests its input program. In particular, given any context C[-], we can consider the value λx.C[x], meaning that proving Y and Z to be applicatively bisimilar is almost as hard as proving them to be contextually equivalent from first principles.

As we will see, proving Z to be normal form similar to Y is straightforward, since in order to test λy.∆∆ and λy.y(λz.ΘΘyz), we simply test their subterms ∆∆ and y(λz.ΘΘyz), thus not allowing the environment to influence computations.

Example 2. Our next example is a refinement of Example 1 to a probabilistic setting, as proposed in [START_REF] Sangiorgi | Environmental bisimulations for probabilistic higherorder languages[END_REF] (but in a call-by-name setting). We consider a variation of Turing's call-by-value fixed point combinator which, at any iteration, can probabilistically decide whether to start another iteration (following the pattern of the standard Turing's fixed point combinator) or to turn for good into Y , where Y and ∆ are defined as in Example 1: Z ΘΘ, Θ λx.λy.(y(λz.∆∆z) or y(λz.xxyz)).

Notice that the constructor or behaves as a (fair) probabilistic choice operator, hence acting as an effect producer. It is natural to ask whether these new versions of Y and Z are still equivalent. However, following insights from previous example, it is not hard to see the equivalence between Y and Z cannot be readily proved by means of standard operational methods such as probabilistic contextual equivalence [START_REF] Dal Lago | On coinductive equivalences for higherorder probabilistic functional programs[END_REF], probabilistic CIU equivalence and logical relations [START_REF] Bizjak | Step-indexed logical relations for probability[END_REF], and probabilistic applicative bisimilarity [START_REF] Dal Lago | On coinductive equivalences for higherorder probabilistic functional programs[END_REF][START_REF] Crubillé | On probabilistic applicative bisimulation and call-byvalue lambda-calculi[END_REF]. All the aforementioned techniques require to test programs in a given environment (such as a whole context or an input argument), and are thus ineffective in handling fixed point combinators such as Y and Z.

We will give an elementary proof of the equivalence between Y and Z in Example 17, and a more elegant proof relying on a suitable up-to context technique in Example 18. In [START_REF] Sangiorgi | Environmental bisimulations for probabilistic higherorder languages[END_REF], the call-by-name counterparts of Y and Z are proved to be equivalent using probabilistic environmental bisimilarity. The notion of an environmental bisimulation [START_REF] Sangiorgi | Environmental bisimulations for higherorder languages[END_REF] involves both an environment storing pairs of terms played during the bisimulation game, and a clause universally quantifying over pairs of terms in the evaluation context closure of such an environment 2 , thus making environmental bisimilarity a rather heavy technique to use. Our proof of the equivalence of Y and Z is simpler: in fact, our notion of effectful normal form bisimulation does not involve any universal quantification over all possible closed function arguments (like applicative bisimilarity), or their evaluation context closure (like environmental bisimilarity), or closed instantiation of uses (like CIU equivalence).

Example 3. Our third example concerns call-by-name calculi and shows how our notion of normal form bisimilarity can handle even intricate recursion schemes. We consider the following argument-switching probabilistic fixed point combinators: We easily see that P and Q satisfy the following (informal) program equations:

P
P ef = e(P ef ) or f (P f e), Qef = e(Qf e) or f (Qef ).

Again, proving the equivalence between P and Q using applicative bisimilarity is problematic. In fact, testing the applicative behaviour of P and Q requires to reason about the behaviour of e.g. e(P ef ), which in turn requires to reason about the (arbitrary) term e, on which no information is provided. The (essentially infinitary) normal forms of P and Q, however, can be proved to be essentially the same by reasoning about the syntactical structure of P and Q. Moreover, our up-to context technique enables an elegant and concise proof of the equivalence between P and Q (Section 6.4).

Example 4. Our last example discusses the use of the cost monad as an instrument to facilitate a more intensional analysis of programs. In fact, we can use the ticking operation tick to perform cost analysis. Every time a β-redex (λx.tick(e))v is reduced, the ticking operation tick increases an imaginary cost counter of a unit. Using ticking, we can provide a more intensional analysis of the relationship between Y and Z, along the lines of Sands' improvement theory [START_REF] Sands | Improvement theory and its applications[END_REF].

Preliminaries: Monads and Algebraic Operations

In this section we recall some basic definitions and results needed in the rest of the paper. Unfortunately, there is no hope to be comprehensive, and thus we assume the reader to be familiar with basic domain theory [START_REF] Abramsky | Domain theory[END_REF] (in particular with the notions of ω-complete (pointed) partial orderω-cppo, for shortmonotone, and continuous functions), basic order theory [START_REF] Davey | Introduction to lattices and order[END_REF], and basic category theory [START_REF] Maclane | Categories for the Working Mathematician[END_REF]. Additionally, we assume the reader to be acquainted with the notion of a Kleisli triple [START_REF] Maclane | Categories for the Working Mathematician[END_REF] T = T , η, - † . As it is customary, we use the notation f † : T X → T Y for the Kleisli extension of f : X → T Y , and reserve the letter η to denote the unit of T. Due to their equivalence, oftentimes we refer to Kleisli triples as monads.

Concerning notation, we try to follow [START_REF] Maclane | Categories for the Working Mathematician[END_REF] and [START_REF] Abramsky | Domain theory[END_REF], with the only exception that we use the notation ,,⊥). The notation T = T , η, - † for an arbitrary Kleisli triple is standard, but it is not very handy when dealing with multiple monads at the same time. To fix this issue, we sometimes use the notation T = T , t, -T to denote a Kleisli triple. Additionally, when unambiguous we omit subscripts. Finally, we denote by Set the category of sets and functions, and by Rel the category of sets and relations. We reserve the symbol 1 to denote the identity function. Unless explicitly stated, we assume functors (and monads) to be functors (and monads) on Set. As a consequence, we write functors to refer to endofunctors on Set.

(x n ) n to denote an ω-chain x 0 • • • x n • • • in a domain (X
We use monads to give operational semantics to our calculi. Following Moggi [START_REF] Moggi | Computational lambda-calculus and monads[END_REF][START_REF] Moggi | Notions of computation and monads[END_REF], we model notions of computation as monads, meaning that we use monads as mathematical models of the kind of (side) effects computations may produce. The following are examples of monads modelling relevant notions of computation. Due to space constraints, we omit several interesting examples such as the output, the exception, and the nondeterministic/powerset monad, for which the reader is referred to e.g. [START_REF] Moggi | Notions of computation and monads[END_REF][START_REF] Wadler | Monads for functional programming[END_REF].

Example 5 (Partiality). Partial computations are modelled by the partiality (also called maybe) monad M = M , m, -M . The carrier M X of M is defined as {just x | x ∈ X} ∪ {⊥}, where ⊥ is a special symbol denoting divergence. The unit and Kleisli extension of M are defined as follows:

m(x) just x, f M (just x) f (x), f M (⊥) ⊥.
Example 6 (Probabilistic Nondeterminism). In this example we assume sets to be countable 3 . The (discrete

) distribution monad D = D, d, -D has carrier DX {µ : X → [0, 1] | x µ(x) = 1}
, whereas the maps d and -D are defined as follows (where y = x):

d(x)(x) 1, d(x)(y) 0, f D (µ)(y) x∈X µ(x) • f (x)(y).
Oftentimes, we write a distribution µ as a weighted formal sum. That is, we write µ as the sum 4 i∈I p i •x i such that µ(x) = xi=x p i . D models probabilistic total computations, according to the rationale that a (total) probabilistic program evaluates to a distribution over values, the latter describing the possible results of the evaluation. Finally, we model probabilistic partial computations using the monad DM = DM , dm, -DM . The carrier of DM is defined as DM X D(M X), whereas the unit dm is defined in the obvious way. For f : X → DM Y , define:

f DM (µ)(y) x∈X µ(just x) • f (x)(y) + µ(⊥) • d(⊥)(y).
It is easy to see that DM is isomorphic to the subdistribution monad.

Example 7 (Cost). The cost (also known as ticking or improvement [START_REF] Sands | Improvement theory and its applications[END_REF]) monad

C = C, c, -C has carrier CX M (N × X).
The unit of C is defined as c(x) just (0, x), whereas Kleisli extension is defined as follows:

f C (x ) ⊥ if x = ⊥, or x = just (n, x) and f (x) = ⊥ just (n + m, y) if x = just (n, x) and f (x) = just (m, y).
The cost monad is used to model the cost of (partial) computations. An element of the form just (n, x) models the result of a computation outputting the value x with cost n (the latter being an abstract notion that can be instantiated to e.g. the number of reduction steps performed). Partiality is modelled as the element ⊥, according to the rationale that we can assume all divergent computations to have the same cost, so that such information need not be explicitly written (for instance, measuring the number of reduction steps performed, we would have that divergent computations all have cost ∞).

Example 8 (Global states). Let L be a set of public location names. We assume the content of locations to be encoded as families of values (such as numerals or booleans) and denote the collection of such values as V. A store (or state) is a function σ : L → V. We write S for the set of stores V L . The global state monad G = G, g, -G has carrier GX (X × S) S , whereas g and -G are defined by:

g(x)(σ) (x, σ), f G (α)(σ) f (x )(σ ),
where α(σ) = (x , σ ). It is straightforward to see that we can combine the global state monad with the partiality monad, obtaining the monad M⊗G whose carrier is (M ⊗ G)X M (X × S) S . In a similar fashion, we see that we can combine the global state monad with DM and C, as we are going to see in Remark 1.

Remark 1. The monads DM and M⊗G of Example 6 and Example 8, respectively, are instances of two general constructions, namely the sum and tensor of effects [START_REF] Hyland | Combining effects: Sum and tensor[END_REF]. Although these operations are defined on Lawvere theories [START_REF] Lawvere | Functorial Semantics of Algebraic Theories[END_REF][START_REF] Hyland | The category theoretic understanding of universal algebra: Lawvere theories and monads[END_REF], here we can rephrase them in terms of monads as follows.

Proposition 1. Given a monad T = T , t, -T , define the sum TM of T and M and the tensor T ⊗ G of T and G, as the triples T M , tm, -TM and T ⊗ G, t ⊗ g, -T⊗G , respectively. The carriers of the triples are defined as T M X T (M X) and (T ⊗ G)X T (S × X) S , whereas the maps tm and t ⊗ g are defined as tm X t M X • m X and (t ⊗ g) X curry t S×X , respectively. Finally, define:

f TM (f M ) T , f T⊗G (α)(σ) (uncurry f ) T (α)(σ),
where, for a function f :

X → T M Y we define f M : M X → T M Y as f M (⊥) t M X (⊥), f M (just x) f (x)
, and curry and uncurry are defined as usual. Then TM and T ⊗ G are monads.

Proving Proposition 1 is a straightforward exercise (the reader can also consult [START_REF] Hyland | Combining effects: Sum and tensor[END_REF]). We notice that tensoring G with DM we obtain a monad for probabilistic imperative computations, whereas tensoring G with C we obtain a monad for imperative computations with cost.

Algebraic Operations

Monads provide an elegant way to structure effectful computations. However, they do not offer any actual effect constructor. Following Plotkin and Power [56,[START_REF] Plotkin | Notions of computation determine monads[END_REF][START_REF] Plotkin | Algebraic operations and generic effects[END_REF], we use algebraic operations as effect producers. From an operational perspective, algebraic operations are those operations whose behaviour is independent of their continuations or, equivalently, of the environment in which they are evaluated. Intuitively, that means that e.g.

E[e 1 or e 2 ] is operationally equivalent to E[e 1 ] or E[e 2 ]
, for any evaluation context E. Examples of algebraic operations are given by (binary) nondeterministic and probabilistic choices as well as primitives for rising exceptions and output operations. Syntactically, algebraic operations are given via a signature Σ consisting of a set of operation symbols (uninterpreted operations) together with their arity (i.e. their number of operands). Semantically, operation symbols are interpreted as algebraic operations on monads. To any n-ary operation symbol5 (op : n) ∈ Σ and any set X we associate a map op X : (T X) n → T X (so that we equip T X with a Σ-algebra structure [START_REF] Burris | A course in universal algebra[END_REF]) such that f † is Σ-algebra morphism, meaning that for any f : X → T Y , and elements x 1 , . . . ,

x n ∈ T X we have op Y (f † (x 1 ), . . . , f † (x n )) = f † ( op X (x 1 , . . . , x n )).
Example 9. The partiality monad M usually comes with no operation, as the possibility of divergence is an implicit feature of any Turing complete language. However, it is sometimes useful to add an explicit divergence operation (for instance, in strongly normalising calculi). For that, we consider the signature Σ M {Ω : 0}. Having arity zero, the operation Ω acts as a constant, and has semantics Ω = ⊥. Since f M (⊥) = ⊥, we see that Ω in indeed an algebraic operation on M.

For the distribution monad D we define the signature Σ D {or : 2}. The intended semantics of a program e 1 or e 2 is to evaluate to e i (i ∈ {1, 2}) with probability 0.5. The interpretation of or is defined by or (µ, ν)(x) 0.5•µ(x)+ 0.5 • ν(x). It is easy to see that or is an algebraic operation on D, and that it trivially extends to DM.

Finally, for the cost monad C we define the signature Σ C {tick : 1}. The intended semantics of tick is to add a unit to the cost counter:

tick (⊥) ⊥, tick (just (n, x)) just (n + 1, x).
The framework we have just described works fine for modelling operations with finite arity, but does not allow to handle operations with infinitary arity. This is witnessed, for instance, by imperative calculi with global stores, where it is natural to have operations of the form get (x.k) with the following intended semantics: get (x.k) reads the content of the location , say it is a value v, and continue as k[v/x]. In order to take such operations into account, we follow [START_REF] Plotkin | Algebraic operations and generic effects[END_REF] and work with generalised operations.

A generalised operation (operation, for short) on a set X is a function ω : P × X I → X. The set P is called the parameter set of the operation, whereas the (index) set I is called the arity of the operation. A generalised operation ω : P × X I → X thus takes as arguments a parameter p (such as a location name) and a map κ : I → X giving for each index i ∈ I the argument κ(i) to pass to ω. Syntactically, generalised operations are given via a signature Σ consisting of a set of elements of the form op : P I (the latter being nothing but a notation denoting that the operation symbols op has parameter set P and index set I). Semantically, an interpretation of an operation symbol op : P I on a monad T associates to any set X a map op X : P × (T X) I → T X such that that for any f : X → T Y , p ∈ P , and κ : I → T X:

f † ( op X (p, κ)) = op Y (p, f † • κ).
If T comes with an interpretation for operation symbols in Σ, we say that T is Σ-algebraic.

It is easy to see by taking the one-element set 1 = { * } as parameter set and a finite set as arity set, generalised operations subsume finitary operations. For simplicity, we use the notation op : n in place of op : 1 n, and write op(x 1 , . . . , x n ) in place of op( * , n → x n ).

Example 10. For the global state monad we consider the signature

Σ G {set : V 1, get : 1 V | ∈ L}.
From a computational perspective, such operations are used to build programs of the form set (v, e) and get (x.e). The former stores the value v in the location and continues as e, whereas the latter reads the content of the location , say it is v, and continue as e[v/x]. Here e is used as the description of a function κ e from values to terms defined by κ e (v) e[v/x]. The interpretation of the new operations on G is standard:

set (v, α)(σ) = α(σ[ := v]), get (κ)(σ) = κ(σ( ))(σ).
Straightforward calculations show that indeed set and get are algebraic operations on G. Moreover, such operations can be easily extended to the partial global state monad M ⊗ G as well as to the probabilistic (partial) global store monad DM ⊗ G. These extensions share a common pattern, which is nothing but an instance of the tensor of effects. In fact, given a Σ T -algebraic monad T we can define the signature Σ T⊗G as Σ T ∪ Σ G , and observe that the T ⊗ G is Σ T⊗G -algebraic. We refer the reader to [START_REF] Hyland | Combining effects: Sum and tensor[END_REF] for details. Here we simply notice that we can define the interpretation op T⊗G of op : P

V on T ⊗ G as op T⊗G X (p, κ)(σ) op T S×X (p, v → κ(v)(σ))
, where op T is the interpretation of op on T (the interpretations of set and get are straightforward).

Monads and algebraic operations provide mathematical abstractions to structure and produce effectful computations. However, in order to give operational semantics to, e.g., probabilistic calculi [START_REF] Dal Lago | Probabilistic operational semantics for the lambda calculus[END_REF] we need monads to account for infinitary computational behaviours. We thus look at Σ-continuous monads. [START_REF] Goguen | Initial algebra semantics and continuous algebras[END_REF]) if to any set X is associated an order X and an element ⊥ X ∈ T X such that T X, X , ⊥ X is an ω-cppo, and for all (op : P

Definition 1. A Σ-algebraic monad T = T , η, - † is Σ-continuous (cf.
I) ∈ Σ, f , f n , g : X → T Y , κ, κ n , ν : I → T X, x , x n , y ∈ T X, we have f † (⊥) = ⊥ and: κ ν =⇒ op (p, κ) op (p, ν) op (p, n κ n ) = n op (p, κ n ) f g =⇒ f † g † ( n f n ) † = n f † n x y =⇒ f † (x ) f † (y) f † ( n x n ) = n f † (x n ).
When clear from the context, we will omit subscripts in ⊥ X and X .

Example 11. The monads M, DM, GM, and C are Σ-continuous. The order on M X and C is the flat ordering defined by x y ⇐⇒ x = ⊥ or x = y, whereas the order on DM X is defined by µ ν ⇐⇒ ∀x ∈ X. µ(just x) ≤ ν(just x). Finally, the order on GM X is defined pointiwise from the flat ordering on M (X × S).

Having introduced the notion of a Σ-continuous monad, we can now define our vehicle calculus Λ Σ and its monadic operational semantics.

A Computational Call-by-value Calculus with Algebraic Operations

In this section we define the calculus Λ Σ . Λ Σ is an untyped λ-calculus parametrised by a signature of operation symbols, and corresponds to the coarse-grain [START_REF] Levy | Modelling environments in call-by-value programming languages[END_REF] version of the calculus studied in [START_REF] Dal Lago | Effectful applicative bisimilarity: Monads, relators, and howe's method[END_REF]. Formally, terms of Λ Σ are defined by the following grammar, where x ranges over a countably infinite set of variables and op is a generalised operation symbol in Σ. A value is either a variable or a λ-abstraction. We denote by Λ the collection of terms and by V the collection of values of Λ Σ . For an operation symbol op : P I, we assume that set I to be encoded by some subset of V (using e.g. Church's encoding). In particular, in a term of the form op(p, x.e), e acts as a function in the variable x that takes as input a value. Notice also how parameters p ∈ P are part of the syntax. For simplicity, we ignore the specific subset of values used to encode elements of I, and simply write op : P V for operation symbols in Σ.

We adopt standard syntactical conventions as in [START_REF] Barendregt | The lambda calculus: its syntax and semantics[END_REF] (notably the so-called variable convention). The notion of a free (resp. bound) variable is defined as usual (notice that the variable x is bound in op(p, x.e)). As it is customary, we identify terms up to renaming of bound variables and say that a term is closed if it has no free variables (and that it is open, otherwise). Finally, we write f [e/x] for the capture-free substitution of the term e for all free occurrences of x in f . In particular, op(p, x .f )[e/x] is defined as op(p, x .f [e/x]).

Before giving Λ Σ call-by-value operational semantics, it is useful to remark a couple of points. First of all, testing terms according to their (possibly infinitary) normal forms obviously requires to work with open terms. Indeed, in order to inspect the intensional behaviour of a value λx.e, one has to inspect the intensional behaviour of e, which is an open term. As a consequence, contrary to the usual practice, we give operational semantics to both open and closed terms. Actually, the very distinction between open and closed terms is not that meaningful in this context, and thus we simply speak of terms. Second, we notice that values constitute a syntactic category defined independently of the operational semantics of the calculus: values are just variables and λ-abstractions. However, giving operational semantics to arbitrary terms we are interested in richer collections of irreducible expressions, i.e. expressions that cannot be simplified any further. Such collections will be different accordingly to the operational semantics adopted. For instance, in a call-by-name setting it is natural to regard the term x((λx.x)v) as a terminal expression (being it a head normal form), whereas in a call-by-value setting x((λx.x)v) can be further simplified to xv, which in turn should be regarded as a terminal expression.

We now give Λ Σ a monadic call-by-value operational semantics [START_REF] Dal Lago | Effectful applicative bisimilarity: Monads, relators, and howe's method[END_REF], postponing the definition of monadic call-by-name operational semantics to Section 6.4. Recall that a (call-by-value) evaluation context [START_REF] Felleisen | The revised report on the syntactic theories of sequential control and state[END_REF] is a term with a single hole [-] defined by the following grammar, where e ∈ Λ and v ∈ V:

E ::= [-] | Ee | vE.
We write E[e] for the term obtained by substituting the term e for the hole [-] in E.

Following [START_REF] Lassen | Eager normal form bisimulation[END_REF], we define a stuck term as a term of the form E[xv]. Intuitively, a stuck term is an expression whose evaluation is stuck. For instance, the term e y(λx.x) is stuck. Obviously, e is not a value, but at the same time it cannot be simplified any further, as y is a variable, and not a λ-abstraction. Following this intuition, we define the collection E of eager normal forms (enfs hereafter) as the collection of values and stuck terms. We let letters s, t, . . . range over elements in E.

Lemma 1.

Any term e is either a value v, or can be uniquely decomposed as either

E[vw] or E[op(p, x.f )].
Operational semantics of Λ Σ is defined with respect to a Σ-continuous monad T = T , η, - † relying on Lemma 1. More precisely, we define a call-by-value evaluation functionmapping each term to an element in T E. For instance, evaluating a probabilistic term e we obtain a distribution over eager normal forms (plus bottom), the latter being either values (meaning that the evaluation of e terminates) or stuck terms (meaning that the evaluation of e went stuck at some point).

Definition 2. Define the N-indexed family of mapsn : Λ → T E as follows:

e 0 ⊥, v n+1 η(v), E[xv] n+1 η(E[xv]), E[(λx.e)v] n+1 E[e[v/x]] n , E[op(p, x.e) n+1 op E (p, v → E[e[v/x]] n ).
The monad T being Σ-continuous, we see that the sequence ( e n ) n forms an ω-chain in T E, so that we can define e as n e n . Moreover, exploiting Σ-continuity of T we see thatis continuous.

We compare the behaviour of terms of Λ Σ relying on the notion of an effectful eager normal form (bi)simulation, the extension of eager normal form (bi)simulation [START_REF] Lassen | Eager normal form bisimulation[END_REF] to calculi with algebraic effects. In order to account for effectful behaviours, we follow [START_REF] Dal Lago | Effectful applicative bisimilarity: Monads, relators, and howe's method[END_REF] and parametrise our notions of equivalence and refinement by relators [START_REF] Barr | Relational algebras[END_REF][START_REF] Thijs | Simulation and fixpoint semantics[END_REF].

Relators

The notion of a relator for a functor T (on Set) [START_REF] Thijs | Simulation and fixpoint semantics[END_REF] (also called lax extension of T [START_REF] Barr | Relational algebras[END_REF]) is a construction lifting a relation R between two sets X and Y to a relation Γ R between T X and T Y . Besides their applications in categorical topology [START_REF] Barr | Relational algebras[END_REF] and coalgebra [START_REF] Thijs | Simulation and fixpoint semantics[END_REF], relators have been recently used to study notions of applicative bisimulation [START_REF] Dal Lago | Effectful applicative bisimilarity: Monads, relators, and howe's method[END_REF], logic-based equivalence [START_REF] Simpson | Behavioural equivalence via modalities for algebraic effects[END_REF], and bisimulation-based distances [START_REF] Gavazzo | Quantitative behavioural reasoning for higher-order effectful programs: Applicative distances[END_REF] for λ-calculi extended with algebraic effects. Moreover, several forms of monadic lifting [START_REF] Katsumata | Preorders on monads and coalgebraic simulations[END_REF][START_REF] Goubault-Larrecq | Logical relations for monadic types[END_REF] resembling relators have been used to study abstract notions of logical relations [START_REF] Plotkin | Lambda-definability and logical relations[END_REF][START_REF] Reynolds | Types, abstraction and parametric polymorphism[END_REF].

Before defining relators formally, it is useful to recall some background notions on (binary) relations. The reader is referred to [START_REF]Monoidal Topology. A Categorical Approach to Order, Metric, and Topology[END_REF] for further details. We denote by Rel the category of sets and relations, and use the notation R : X + → Y for a relation R between sets X and Y . Given relations R : X + → Y and S : Y + → Z, we write S • R : X + → Z for their composition, and I X : X + → X for the identity relation on X. Finally, we recall that for all sets X, Y , the hom-set Rel(X, Y ) has a complete lattice structure, meaning that we can define relations both inductively and coinductively.

Given a relation R : X + → Y , we denote by R • : Y + → X its dual (or opposite) relations and by -• : Set → Rel the graph functor mapping each function f : X → Y to its graph f • : X + → Y . The functor -• being faithful, we will often write f : X → Y in place of f • : X + → Y . It is useful to keep in mind the pointwise reading of relations of the form g • • S • f , for a relation S : Z + → W and functions f : X → Z, g : Y → W :

(g • • S • f )(x, y) = S(f (x), g(y)).
Given R : X + → Y , we can thus express a generalised monotonicity condition in a pointfree fashion using the inclusion R ⊆ g • •S•f . Finally, since we are interested in preorder and equivalence relations, we recall that a relation R :

X + → X is reflexive if I X ⊆ R, transitive if R • R ⊆ R, and symmetric if R ⊆ R • .
We can now define relators formally. Definition 3. A relator for a functor T (on Set) is a set-indexed family of maps (R :

X + → Y ) → (Γ R : T X + → T Y ) satisfying conditions (rel 1)-(rel 4
). We say that Γ is conversive if it additionally satisfies condition (rel 5).

I T X ⊆ Γ (I X ), ( rel 1)
Γ S • Γ R ⊆ Γ (S • R), ( rel 2)
T f ⊆ Γ f , (T f ) • ⊆ Γ f • , (rel 3) R ⊆ S =⇒ Γ R ⊆ Γ S, ( rel 4)
Γ (R • ) = (Γ R) • . ( rel 5)
Conditions (rel 1), (rel 2), and (rel 4) are rather standard 6 . As we will see, condition (rel 4) makes the defining functional of (bi)simulation relations monotone, whereas conditions (rel 1) and (rel 2) make notions of (bi)similarity reflexive and transitive. Similarly, condition (rel 5) makes notions of bisimilarity symmetric. Condition (rel 3), which actually consists of two conditions, states that relators behave as expected when acting on (graphs of) functions. In [START_REF] Levy | Similarity quotients as final coalgebras[END_REF][START_REF] Dal Lago | Effectful applicative bisimilarity: Monads, relators, and howe's method[END_REF] a kernel preservation condition is required in place of (rel 3). Such a condition is also known as stability in [START_REF] Hughes | Simulations in coalgebra[END_REF]. Stability requires the equality Γ (g

• • R • f ) = (T g) • • Γ R • T f to hold.
It is easy to see that a relator always satisfies stability (see Corollary III.1.4.4 in [START_REF]Monoidal Topology. A Categorical Approach to Order, Metric, and Topology[END_REF]).

Relators provide a powerful abstraction of notions of 'relation lifting', as witnessed by the numerous examples of relators we are going to discuss. However, before discussing such examples, we introduce the notion of a relator for a monad or lax extension of a monad. In fact, since we modelled computational effects as monads, it seems natural to define the notion of a relator for a monad (and not just for a functor). Definition 4. Let T = T , η, - † be a monad, and Γ be a relator for T . We say that Γ is a relator for T if it satisfies the following conditions:

R ⊆ η • Y • Γ R • η X , ( rel 7)
R ⊆ g • • Γ S • f =⇒ Γ R ⊆ (g † ) • • Γ S • f † . ( rel 8)
Finally, we observe that the collection of relators is closed under specific operations (see [START_REF] Levy | Similarity quotients as final coalgebras[END_REF]). Proposition 2. Let T , U be functors, and let U T denote their composition. Moreover, let Γ , ∆ be relators for T and U , respectively, and {Γ i } i∈I be a family of relators for T . Then:

1. The map ∆Γ defined by ∆Γ R ∆(Γ R) is a relator for U T . 2. The maps i∈I Γ i and Γ • defined by

( i∈I Γ i )R i∈I Γ i R and Γ • R (Γ R • ) • ,
respectively, are relators for T . 3. Additionally, if Γ is a relator for a monad T, then so are i∈I Γ i and Γ • . Example 12. For the partiality monad M we define the set-indexed family of maps M : Rel(X, Y ) → Rel(M X, M Y ) as:

x MR y ⇐⇒ (x = ⊥) ∨ (∃x ∈ X. ∃y ∈ Y . x = just x ∧ y = just y ∧ x R y).
The mapping M describes the structure of the usual simulation clause for partial computations, whereas M • describes the corresponding co-simulation clause. It is easy to see that M is a relator for M. By Proposition 2, the map M ∧ M• is a conversive relator for M. It is immediate to see that the latter relator describes the structure of the usual bisimulation clause for partial computations.

Example 13. For the distribution monad we define the relator D relying on the notion of a coupling and results from optimal transport [START_REF] Villani | Optimal Transport: Old and New. Grundlehren der mathematischen Wissenschaften[END_REF]. Recall that a coupling for µ ∈ D(X) and ν ∈ D(Y ) a is a joint distribution ω ∈ D(X × Y ) such that: µ = y∈Y ω(-, y) and ν = x∈X ω(x, -). We denote the set of couplings of µ and ν by Ω(µ, ν). Define the (set-indexed) map D : Rel(X, Y ) → Rel(DX, DY ) as follows:

µ DR ν ⇐⇒ (∃ω ∈ Ω(µ, ν). ∀x, y. ω(x, y) > 0 =⇒ x R y).
We can show that D is a relator for D relying on Strassen's Theorem [START_REF] Strassen | The existence of probability measures with given marginals[END_REF], which shows that D can be characterised universally (i.e. using an universal quantification).

Theorem 1 (Strassen's Theorem [START_REF] Strassen | The existence of probability measures with given marginals[END_REF]). For all µ ∈ DX, ν ∈ DY , and R : X + → Y , we have:

µ DR ν ⇐⇒ ∀X ⊆ X. µ(X ) ≤ ν(R[X ]).
As a corollary of Theorem 1, we see that D describes the defining clause of Larsen-Skou bisimulation for Markov chains (based on full distributions) [START_REF] Larsen | Bisimulation through probabilistic testing[END_REF]. Finally, we observe that DM D M is a relator for DM.

Example 14. For relations R : X + → Y , S : X + → Y , let R×S : X ×X + → Y ×Y be defined as (R×S)((x, x ), (y, y )) ⇐⇒ R(x, y)∧S(x , y ). We define the relator Ĉ : Rel(X, Y ) → Rel(CX, CY ) for the cost monad C as ĈR M(≥ × R), where ≥ denotes the opposite of the natural ordering on N. It is straightforward to see that Ĉ is indeed a relator for C. The use of the opposite of the natural order in the definition of Ĉ captures the idea that we use Ĉ to measure complexity. Notice that Ĉ describes Sands' simulation clause for program improvement [START_REF] Sands | Improvement theory and its applications[END_REF]. Finally, we require relators to properly interact with the Σ-continuous structure of monads. Definition 5. Let T = T , η, - † be a Σ-continuous monad and Γ be relator for T. We say that Γ is Σ-continuous if it satisfies the following clauses -called the inductive conditions -for any ω-chain (x n ) n in T X, element y ∈ T Y , elements x , x ∈ T X, and relation R :

X + → Y . ⊥ Γ R y, x x , x Γ R y =⇒ x Γ R y, ∀n. x n Γ R y =⇒ n x n Γ R y.
The relators M, DM, Ĉ, M ⊗ G, DM ⊗ G, C ⊗ G are all Σ-continuous. The reader might have noticed that we have not imposed any condition on how relators should interact with algebraic operations. Nonetheless, it would be quite natural to require a relator Γ to satisfy condition (rel 9) below, for all operation symbol op : P I ∈ Σ, maps κ, ν : I → T X, parameter p ∈ P , and relation R.

∀i ∈ I. κ(i) Γ R ν(i) =⇒ op (p, κ) Γ R op (p, ν) (rel 9)
Remarkably, if T is Σ-algebraic, then any relator for T satisfies (rel 9) (cf. [START_REF] Dal Lago | Effectful applicative bisimilarity: Monads, relators, and howe's method[END_REF]).

Proposition 4. Let T = T , η, - † be a Σ-algebraic monad, and let Γ be a relator for T. Then Γ satisfies condition (rel 9).

Having defined relators and their basic properties, we now introduce the notion of an effectful eager normal form (bi)simulation.

Effecful Eager Normal Form (Bi)simulation

In this section we tacitly assume a Σ-continuous monad T = T , η, - † and a Σ-continuous relator Γ for it be fixed. Σ-continuity of Γ is not required for defining effectful eager normal form (bi)simulation, but it is crucial to prove that the induced notion of similarity and bisimilarity are precongruence and congruence relations, respectively.

Working with effectful calculi, it is important to distinguish between relations over terms and relations over eager normal forms. For that reason we we will work with pairs of relations of the form (R Λ : Λ + → Λ, R E : E + → E), which we call λ-term relations (or term relations, for short). We use letters R, S, . . . to denote term relations. The collection of λ-term relations (i.e. Rel(Λ, Λ) × Rel(E, E)) inherits a complete lattice structure from Rel(Λ, Λ) and Rel(E, E) pointwise, hence allowing λ-term relations to be defined both inductively and coinductively. We use these properties to define our notion of effectful eager normal form similarity.

Definition 6. A term relation R = (R Λ : Λ + → Λ, R E : E + → E
) is an effectful eager normal form simulation with respect to Γ (hereafter enf-simulation, as Γ will be clear from the context) if the following conditions hold, where in condition

(enf 4) z ∈ F V (E) ∪ F V (E ). e R Λ f =⇒ e Γ R E f , (enf 1) x R E s =⇒ s = x, (enf 2) λx.e R E s =⇒ ∃f . s = λx.f ∧ e R Λ f , ( enf 3
)

E[xv] R E s =⇒ ∃E , v . s = E [xv ] ∧ v R E v ∧ ∃z. E[z] R Λ E [z]. (enf 4)
We say that relation R respects enfs if it satisfies conditions (enf 2)-(enf 4).

Definition 6 is quite standard. Clause (enf 1) is morally the same clause on terms used to define effectful applicative similarity in [START_REF] Dal Lago | Effectful applicative bisimilarity: Monads, relators, and howe's method[END_REF]. Clauses (enf 2) and (enf 3) state that whenever two enfs are related by R E , then they must have the same outermost syntactic structure, and their subterms must be pairwise related. For instance, if λx.e R E s holds, then s must the a λ-abstraction, i.e. an expression of the form λx.f , and e and f must be related by R Λ .

Clause (enf 4) is the most interesting one. It states that whenever E[xv] R E s, then s must be a stuck term E [xv ], for some evaluation context E and value v . Notice that E[xv] and s must have the same 'stuck variable' x. Additionally, v and v must be related by R E , and E and E must be properly related too. The idea is that to see whether E and E are related, we replace the stuck expressions xv, xv with a fresh variable z, and test E[z] and E [z] (thus resuming the evaluation process). We require E[z] R E E [z] to hold, for some fresh variable z. The choice of the variable does not really matter, provided it is fresh. In fact, as we will see, effectful eager normal form similarity E is substitutive and reflexive. In particular, if

E[z] E E E [z] holds, then E[y] E E E [y] holds as well, for any variable y ∈ F V (E) ∪ F V (E ).
Notice that Definition 6 does not involve any universal quantification. In particular, enfs are tested by inspecting their syntactic structure, thus making the definition of an enf-simulation somehow 'local': terms are tested in isolation and not via their interaction with the environment. This is a major difference with e.g. applicative (bi)simulation, where the environment interacts with λabstractions by passing them arbitrary (closed) values as arguments.

Definition

6 induces a functional R → [R] on the complete lattice Rel(Λ, Λ)× Rel(E, E), where [R] = ([R] Λ , [R] E
) is defined as follows (here I X denotes the identity relation on variables, i.e. the set of pairs of the form (x, x)):

[R] Λ {(e, f ) | e Γ R E f } [R] E I X ∪ {(λx.e, λx.f ) | e R Λ f }, ∪ {(E[xv], E [xv ]) | v R E v ∧ ∃z ∈ F V (E) ∪ F V (E ). E[z] R Λ E [z]}.
It is easy to see that a term relation R is an enf-simulation if and only if R ⊆ [R]. Notice also that although [R] E always contains the identity relation on variables, R E does not have to: the empty relation (∅, ∅) is an enf-simulation.

Finally, since relators are monotone (condition (rel 4)), R → [R] is monotone too. As a consequence, by Knaster-Tarski Theorem [START_REF] Tarski | A lattice-theoretical fixpoint theorem and its applications[END_REF], it has a greatest fixed point which we call effectful eager normal form similarity with respect to Γ (hereafter enf-similarity) and denote by E = ( E Λ , E E ). Enf-similarity is thus the largest enf-simulation with respect to Γ . Moreover, E being defined coinductively, it comes with an associated coinduction proof principle stating that if a term relation R is an enf-simulation, then it is contained in E . Symbolically:

R ⊆ [R] =⇒ R ⊆ E .
Example 16. We use the coinduction proof principle to show that E contains the β-rule, viz.

(λx.e)v E Λ e[v/x].
For that, we simply observe that the term relation ({((λx.e)v, e[v/x])}, I E ) is an enf-simulation. Indeed, (λx.e)v = e[v/x] , so that by (rel 1) we have

(λx.e)v Γ I E e[v/x] .
Finally, we define effectful eager normal form bisimilarity. Definition 7. A term relation R is an effectful eager normal form bisimulation with respect to Γ (enf-bisimulation, for short) if it is a symmetric enfsimulation. Eager normal bisimilarity with respect to Γ (enf-bisimilarity, for short) E is the largest symmetric enf-simulation. In particular, enf-bisimilarity (with respect to Γ ) coincides with enf-similarity with respect to Γ ∧ Γ • . Example 17. We show that the probabilistic call-by-value fixed point combinators Y and Z of Example 2 are enf-bisimilar. In light of Proposition 5, this allows us to conclude that Y and Z are applicatively bisimilar, and thus contextually equivalent [START_REF] Dal Lago | Effectful applicative bisimilarity: Monads, relators, and howe's method[END_REF]. Let us consider the relator DM for probabilistic partial computations. We show Y E Λ Z by coinduction, proving that the symmetric closure of the term relation R = (R Λ , R E ) defined as follows is an enf-simulation: R Λ {(Y , Z), (∆∆z, Zyz), (∆∆, y(λz.∆∆z) or y(λz.Zyz))} ∪ I Λ R E {(y(λz.∆∆z), y(λz.Zyz)), (λz.∆∆z, λz.Zyz), (λy.∆∆, λy.(y(λz.∆∆z) or y(λz.Zyz))), (y(λz.∆∆z)z, y(λz.Zyz)z)} ∪ I E .

The term relation R is obtained from the relation {(Y , Z)} by progressively adding terms and enfs according to clauses (enf 1)-(enf 4) in Definition 6. Checking that R is an enf-simulation is straightforward. As an illustrative example, we prove that ∆∆z R Λ Zyz implies ∆∆z DM(R E ) Zyz . The latter amounts to show:

1 • just y(λz.∆∆z)z DM(R E ) 1 2 • just y(λz.∆∆z)z + 1 2 • just y(λz.Zyz)z ,
where, as usual, we write distributions as weighted formal sums. To prove the latter, it is sufficient to find a suitable coupling of ∆∆z and Zyz . Define the distribution ω ∈ D(M E × M E) as follows:

ω(just y(λz.∆∆z)z, just y(λz.∆∆z)z) = 1 2 , ω(just y(λz.∆∆z)z, just y(λz.Zyz)z) = 1 2 ,
and assigning zero to all other pairs in M E × M E. Obviously ω is a coupling of ∆∆z and Zyz . Additionally, we see that ω(x , y) implies x MR E y, since both y(λz.∆∆z)z R E y(λz.∆∆z)z, and y(λz.∆∆z)z R E y(λz.Zyz)z hold. As already discussed in Example 2, the operational equivalence between Y and Z is an example of an equivalence that cannot be readily established using standard operational methods -such as CIU equivalence or applicative bisimilarity -but whose proof is straightforward using enf-bisimilarity. Additionally, Theorem 3 will allow us to reduce the size of R, thus minimising the task of checking that our relation is indeed an enf-bisimulation. To the best of the authors' knowledge, the probabilistic instance of enf-(bi)similarity is the first example of a probabilistic eager normal form (bi)similarity in the literature.

Congruence and Precongruence Theorems

In order for E and E to qualify as good notions of program refinement and equivalence, respectively, they have to allow for compositional reasoning. Roughly speaking, a term relation R is compositional if the validity of the relationship C[e] R C[e ] between compound terms C[e], C[e ] follows from the validity of the relationship e R e between the subterms e, e . Mathematically, the notion of compositionality is formalised throughout the notion of compatibility, which directly leads to the notions of a precongruence and congruence relation. In this section we prove that E and E are substitutive precongruence and congruence relations, that is preorder and equivalence relations closed under term constructors of Λ Σ and substitution, respectively. To prove such results, we generalise Lassen's relational construction for the pure call-by-name λ-calculus [START_REF] Lassen | Bisimulation in untyped lambda calculus: Böhm trees and bisimulation up to context[END_REF]. Such a construction has been previously adapted to the pure call-by-value λ-calculus (and its extension with delimited and abortive control operators) in [START_REF] Biernacki | Proving soundness of extensional normalform bisimilarities[END_REF], whereas Lassen has proved compatibility of pure eager normal form bisimilarity via a CPS translation [START_REF] Lassen | Eager normal form bisimulation[END_REF]. Both those proofs rely on syntactical properties of the calculus (mostly expressed using suitable small-step semantics), and thus seem to be hardly adaptable to effectful calculi. On the contrary, our proofs rely on the properties of relators, thereby making our results and techniques more modular and thus valid for a large class of effects.

We begin proving precongruence of enf-similarity. The central tool we use to prove the wished precongruence theorem is the so-called (substitutive) context closure [37] R SC of a term relation R, which is inductively defined by the rules in Figure 1, where x ∈ {Λ, E}, i ∈ {1, 2}, and

z ∈ F V (E) ∪ F V (E ).
We easily see that R SC is the smallest term relation that contains R, it is closed under language constructors of Λ Σ (a property known as compatibility [START_REF] Barendregt | The lambda calculus: its syntax and semantics[END_REF]), and it is closed under the substitution operation (a property known as substitutivity [START_REF] Barendregt | The lambda calculus: its syntax and semantics[END_REF]). As a consequence, we say that a term relation R is a substitutive compatible relation if R SC ⊆ R (and thus R = R SC ). If, additionally, R is a preorder (resp. equivalence) relation, then we say that R is a substitutive precongruence (resp. substitutive congruence) relation.

x R SC E x (sc-var) e Rx e e R SC x e (sc-↓) s R SC E s s R SC Λ s (sc-to-λ) e R SC Λ f λx.e R SC E λx.f (sc-abs) ei R SC Λ e i e1e2 R SC Λ e 1 e 2 (sc-app) e R SC Λ f op(p, x.e) R SC Λ op(p, x.f ) (sc-op) v R SC E v w R SC E w v[w/x] R SC E v [w /x] (sc-subst-val) e R SC Λ e v R SC E v e[v/x] R SC Λ e [v /x]
(sc-subst)

E[z] R SC Λ E [z] v R SC E v E[xv] R SC E E[xv ] (sc-stuck) E[z] R SC Λ E [z] e R SC Λ e E[e] R SC Λ E [e ]
(sc-ectx) We are now going to prove that if R is an enf-simulation, then so is R SC . In particular, we will infer that ( E ) SC is a enf-simulation, and thus it is contained in E , by coinduction.

Lemma 2 (Main Lemma). If R be an enf-simulation, then so is R SC .

Proof (sketch). The proof is long and non-trivial. Due to space constraints here we simply give some intuitions behind it. First, a routine proof by induction shows that since R respects enfs, then so does R SC . Next, we wish to prove that e R SC Λ f implies e Γ R SC E f . Since Γ is inductive, the latter follows if for any n ≥ 0, e R SC Λ f implies e n Γ R SC E f . We prove the latter implication by lexicographic induction on (1) the natural number n and (2) the derivation e R SC Λ f . The case for n = 0 is trivial (since Γ is inductive). The remaining cases are nontrivial, and are handled observing that E[e] = (s → E[s] ) † e and e[v/x] n -[v/x] † n e n . Both these identities allow us to apply condition (rel 8) to simplify proof obligations (usually relying on part (2) of the induction hypothesis as well). This scheme is iterated until we reach either an enf (in which case we are done by condition (rel 7)) or a pair of expressions on which we can apply part (1) of the induction hypothesis.

Theorem 2. Enf-similarity (resp. bisimilarity) is a substitutive precongruence (resp. congruence) relation.

Proof. We show that enf-similarity is a substitutive precongruence relation. By Lemma 2, it is sufficient to show that E is a preorder. This follows by coinduction, since the term relations I and E • E are enf-simulations (the proofs make use of conditions (rel 1) and (rel 2), as well as of substitutivity of E ).

Finally, we show that enf-bisimilarity is a substitutive congruence relation. Obviously E is an equivalence relation, so that it is sufficient to prove ( E ) SC ⊆ E . That directly follows by coinduction relying on Lemma 2, provided that ( E ) SC is symmetric. An easy inspection of the rules in Figure 1 reveals that R SC is symmetric, whenever R is.

Soundness for Effectful Applicative (Bi)similarity

Theorem 2 qualifies enf-bisimilarity and enf-similarity as good candidate notions of program equivalence and refinement for Λ Σ , at least from a structural perspective. However, we gave motivations for such notions looking at specific examples where effectful applicative (bi)similarity is ineffective. It is then natural to ask whether enf-(bi)similarity can be used as a proof technique for effectful applicative (bi)similarity.

Here we give a formal comparison between enf-(bi)similarity and effectful applicative (bi)similarity, as defined in [START_REF] Dal Lago | Effectful applicative bisimilarity: Monads, relators, and howe's method[END_REF]. First of all, we rephrase the notion of an effectful applicative (bi)simulation of [START_REF] Dal Lago | Effectful applicative bisimilarity: Monads, relators, and howe's method[END_REF] to our calculus Λ Σ . For that, we use the following notational convention. Let Λ 0 , V 0 denote the collections of closed terms and closed values, respectively. We notice that if e ∈ Λ 0 , then e ∈ T V 0 . As a consequence, -induces a closed evaluation function |-| : Λ 0 → T V 0 characterised by the identity -• ι = T ι • |-|, where ι : V 0 → E is the obvious inclusion map. We can thus phrase the definition of effectful applicative similarity (with respect to a relator Γ ) as follows.

Definition 8. A term relation R = (R Λ 0 : Λ 0 + → Λ 0 , R V 0 : V 0 + → V 0
) is an effectful applicative simulation with respect to Γ (applicative simulation, for short) if:

e R Λ 0 f =⇒ |e| Γ R V 0 |f |, ( app 1)
λx

.e R V 0 λx.f =⇒ ∀v ∈ V 0 . e[v/x] R Λ 0 f [v/x]. ( app 2)
As usual, we can define effectful applicative similarity with respect to Γ (applicative similarity, for short), denoted by A 0 = ( A Λ 0 , A V 0 ), coinductively as the largest applicative simulation. Its associated coinduction proof principle states that if a relation is an applicative simulation, then it is contained in applicative similarity. Finally, we extend A 0 to arbitrary terms by defining the relation A = ( A Λ , A V ) as follows: let e, f , w, u be terms and values with free variables among x = x 1 , . . . , x n . We let v range over n-ary sequences of closed values v 1 , . . . , v n . Define:

e A Λ f ⇐⇒ ∀v. e[v/x] A Λ 0 f [v/x], w A Λ u ⇐⇒ ∀v. w[v/x] A Λ 0 u[v/x].
The following result states that enf-similarity is a sound proof technique for applicative similarity.

Proposition 5. Enf-similarity E is included in applicative similarity A .

Proof. Let c = ( c Λ , c V ) denote enf-similarity restricted to closed terms and values. We first show that c is an applicative simulation, from which follows, by coinduction, that it is included in A 0 . It is easy to see that c satisfies condition (app 2). In order to prove that it also satisfies condition (app 1), we have to show that for all e, f ∈ Λ

• , e c Λ f implies |e| Γ c V |f |. Since e c Λ f obviously implies ι(e) E
Λ ι(f ), by (enf 1) we infer ι(e) Γ E V ι(f ) , and thus T ι|e| Γ E V T ι|f |.

By stability of Γ , the latter implies |e| Γ (ι

[v/x] A Λ 0 f [v/x].
We thus conclude e A Λ f . Since in [START_REF] Dal Lago | Effectful applicative bisimilarity: Monads, relators, and howe's method[END_REF] it is shown that effectful applicative similarity (resp. bisimilarity) is contained in effectful contextual approximation (resp. equivalence), Proposition 5 gives the following result.

Corollary 1. Enf-similarity and enf-bisimilarity are sound proof techniques for contextual approximation and equivalence, respectively.

Although sound, enf-bisimilarity is not fully abstract for applicative bisimilarity. In fact, as already observed in [START_REF] Lassen | Eager normal form bisimulation[END_REF], in the pure λ-calculus enf-bisimilarity is strictly finer than applicative bisimilarity (and thus strictly finer than contextual equivalence too). For instance, the terms xv and (λy.xv)(xv) are obviously applicatively bisimilar but not enf-bisimilar.

Eager Normal Form (Bi)simulation Up-to Context

The up-to context technique [START_REF] Pous | Enhancements of the bisimulation proof method[END_REF][START_REF] Lassen | Bisimulation in untyped lambda calculus: Böhm trees and bisimulation up to context[END_REF][START_REF] Sangiorgi | A theory of bisimulation for the pi-calculus[END_REF]] is a refinement of the coinduction proof principle of enf-(bi)similarity that allows for handier proofs of equivalence and refinement between terms. When exhibiting a candidate enf-(bi)simulation relation R, it is desirable for R to be as small as possible, so to minimise the task of verifying that R is indeed an enf-(bi)simulation.

The motivation behind such a technique can be easily seen looking at Example 17, where we showed the equivalence between the probabilistic fixed point combinators Y and Z working with relations containing several administrative pairs of terms. The presence of such pairs was forced by Definition 7, although they appear somehow unnecessary in order to convince that Y and Z exhibit the same operational behaviour.

Enf-(bi)simulation up-to context is a refinement of enf-(bi)simulation that allows to check that a relation R behaves as an enf-(bi)simulation relation up to its substitutive and compatible closure.

Definition 9. A term relation R = (R Λ : Λ + → Λ, R E : E + → E
) is an effectful eager normal form simulation up-to context with respect to Γ (enf-simulation up-to context, hereafter) if satisfies the following conditions, where in condition

(up-to 4) z ∈ F V (E) ∪ F V (E ). e R Λ f =⇒ e Γ R SC E f , (up-to 1) x R E s =⇒ s = x, (up-to 2) λx.e R E s =⇒ ∃f . s = λx.f ∧ e R SC Λ f , (up-to 3) E[xv] R E s =⇒ ∃E , v . s = E [xv ] ∧ v R SC E v ∧ ∃z. E[z] R SC Λ E [z]. (up-to 4)
In order for the up-to context technique to be sound, we need to show that every enf-simulation up-to context is contained in enf-similarity. This is a direct consequence of the following variation of Lemma 2.

Lemma 3. If R is a enf-simulation up-to context, then R SC is a enf-simulation.

Proof. The proof is structurally identical to the one of Lemma 2, where we simply observe that wherever we use the assumption that R is an enf-simulation, we can use the weaker assumption that R is an enf-simulation up-to context.

In particular, since by Lemma 2 we have that E = ( E ) SC , we see that enfsimilarity is an enf-simulation up-to context. Additionally, by Lemma 3 it is the largest such. Since the same result holds for enf-bisimilarity and enf-bisimilarity up-to context, we have the following theorem.

R Λ {(Y x 0 , Zx 0 ), (tick(∆[x 0 /y]∆[x 0 /y]z), tick(ΘΘx 0 z))}, R E = ∅.
Intuitively, Y executes a tick first, and then proceeds iterating the evaluation of ∆[x 0 /y]∆[x 0 /y], the latter involving two tickings only. On the contrary, Z proceeds by recursively call itself, hence involving three tickings at any iteration, so to speak. Since E is substitutive, for any value v we have Zv E Y v.

Theorem 3 makes enf-(bi)similarity an extremely powerful proof technique for program equivalence/refinement, especially because it is yet unknown whether there exist sound up-to context techniques for applicative (bi)similarity [START_REF] Lassen | Relational reasoning about contexts[END_REF].

Weak Head Normal Form (Bi)simulation

So far we have focused on call-by-value calculi, since in presence of effects the call-by-value evaluation strategy seems the more natural one. Nonetheless, our framework can be easily adapted to deal with call-by-name calculi too. In this last section we spend some words on effectful weak head normal form (bi)similarity (whnf-(bi)similarity, for short). The latter is nothing but the call-by-name counterpart of enf-(bi)similarity. The main difference between enf-(bi)similarity and whnf-(bi)similarity relies on the notion of an evaluation context (and thus of a stuck term). In fact, in a call-by-name setting, Λ Σ evaluation contexts are expressions of the form [-]e 1 • • • e n , which are somehow simpler than their call-by-value counterparts. Such a simplicity is reflected in the definition of whnf-(bi)similarity, which allows to prove mutatis mutandis all results proved for enf-(bi)similarity (such results are, without much of a surprise, actually easier to prove).

We briefly expand on that. The collection of weak head normal forms (whnfs, for short) W is defined as the union of V and the collection of stuck terms, the latter being expressions of the form xe

xe 0 • • • e k R W s =⇒ ∃f 0 , . . . , f k . s = xf 0 • • • f k ∧ ∀i. e i R Λ f i .
A straightforward modifications of the rules in Figure 1 allows to prove an analogous of Lemma 2 for whnf-simulations, and thus to conclude (pre)congruence properties of whnf-(bi)similarity. Additionally, such results generalise to whnf-(bi)simulation up to-context, the latter being defined according to Definition 9, so that we have an analogous of Theorem 3 as well. The latter allows to infer the equivalence of the argument-switching fixed point combinators of Example 3, simply by noticing that the symmetric closure of the term relation R = ({(P , Q), (P yz, Qzy), (P zy, Qyz)}, ∅) is a whnf-bisimulation up-to context.

Finally, it is straightforward to observe that whnf-(bi)similarity is included in the call-by-name counterpart of effectful applicative (bi)similarity, but that the inclusion is strict. In fact, the (pure λ-calculus) terms xx and x(λy.xy) are applicatively bisimilar, but not whnf-bisimilar.

Related Work

Normal form (bi)similarity has been originally introduced for the call-by-name λcalculus in [START_REF] Sangiorgi | The lazy lambda calculus in a concurrency scenario[END_REF], where it was called open bisimilarity. Open bisimilarity provides a coinductive characterisation of Lévy-Longo tree equivalence [START_REF] Longo | Set-theoretical models of lambda calculus: Theories, expansions, isomorphisms[END_REF][START_REF] Ong | The Lazy Lambda Calculus: An Investigation Into the Foundations of Functional Programming[END_REF][START_REF] Lévy | An algebraic interpretation of the lambda beta -calculus and a labeled lambda -calculus[END_REF], and has been shown to coincide with the equivalence (notably weak bisimilarity) induced by Milner's encoding of the λ-calculus into the π-calculus [START_REF] Milner | Functions as processes[END_REF].

In [START_REF] Lassen | Bisimulation in untyped lambda calculus: Böhm trees and bisimulation up to context[END_REF] normal form bisimilarity relations characterising both Böhm and Lévy-Longo tree equivalences have been studied by purely operational means, providing new congruence proofs of the aforementioned tree equivalences based on suitable relational constructions. Such results have been extended to the callby-value λ-calculus in [START_REF] Lassen | Eager normal form bisimulation[END_REF], where the so-called eager normal form bisimilarity is introduced. The latter is shown to coincide with the Lévy-Longo tree equivalence induced by a suitable CPS translation [START_REF] Plotkin | Call-by-name, call-by-value and the lambda-calculus[END_REF], and thus to be a congruence relation. An elementary proof of congruence properties of eager normal form bisimilarity is given in [START_REF] Biernacki | Proving soundness of extensional normalform bisimilarities[END_REF], where Lassen's relational construction [START_REF] Lassen | Bisimulation in untyped lambda calculus: Böhm trees and bisimulation up to context[END_REF] is extended to the callby-value λ-calculus, as well as its extensions with delimited and abortive control operators. Finally, following [START_REF] Sangiorgi | The lazy lambda calculus in a concurrency scenario[END_REF], eager normal form bisimilarity has been recently characterised as the equivalence induced by a suitable encoding of the (call-by-value) λ-calculus in the π-calculus [START_REF] Durier | Eager functions as processes[END_REF].

Concerning effectful extensions of normal form bisimilarity, our work seems to be rather new. In fact, normal form bisimilarity has been studied for deterministic extensions of the λ-calculus with specific non-algebraic effects, notably control operators [START_REF] Biernacki | Proving soundness of extensional normalform bisimilarities[END_REF], as well as control and state [START_REF] Støvring | A complete, co-inductive syntactic theory of sequential control and state[END_REF] (where full abstraction of the obtained notion of normal form bisimilarity is proved). The only extension of normal form bisimilarity to an algebraic effect the authors are aware of, is given in [START_REF] Lassen | Normal form simulation for mccarthy's amb[END_REF], where normal form bisimilarity is studied for a nondeterministic call-by-name λ-calculus. However, we should mention that contrary to normal form bisimilarity, both nondeterministic [START_REF] De Liguoro | Non deterministic extensions of untyped lambdacalculus[END_REF] and probabilistic [START_REF] Leventis | Probabilistic böhm trees and probabilistic separation[END_REF] extensions of Böhm tree equivalence have been investigated (although none of them employ, to the best of the authors' knowledge, coinductive techniques).

Conclusion

This paper shows that effectful normal form bisimulation is indeed a powerful methodology for program equivalence. Interestingly, the proof of congruence for normal form bisimilarity can be given just once, without the necessity of redoing it for every distinct notion of algebraic effect considered. This relies on the fact that the underlying monad and relator are Σ-continuous, something which has already been proved for many distinct notions of effects [START_REF] Dal Lago | Effectful applicative bisimilarity: Monads, relators, and howe's method[END_REF].

Topics for further work are plentiful. First of all, a natural question is whether the obtained notion of bisimilarity coincides with contextual equivalence. This is known not to hold in the deterministic case [START_REF] Lassen | Bisimulation in untyped lambda calculus: Böhm trees and bisimulation up to context[END_REF][START_REF] Lassen | Eager normal form bisimulation[END_REF], but to hold in presence of control and state [START_REF] Støvring | A complete, co-inductive syntactic theory of sequential control and state[END_REF], which offer the environment the necessary discriminating power. Is there any (sufficient) condition on effects guaranteeing full abstraction of normal form bisimilarity? This is an intriguing question we are currently investigating. In fact, contrary to applicative bisimilarity (which is known to be unsound in presence of non-algebraic effects [START_REF] Koutavas | From applicative to environmental bisimulation[END_REF], such as local states), the syntactic nature of normal form bisimilarity seems to be well-suited for languages combining both algebraic and non-algebraic effects.

Another interesting topic for future research, is investigating whether normal form bisimilarity can be extended to languages having both algebraic operations and effect handlers [START_REF] Plotkin | Handling algebraic effects[END_REF][START_REF] Bauer | Programming with algebraic effects and handlers[END_REF].

Example 1 .

 1 Our first example comes from the ordinary theory of pure, untyped λ-calculus. Let us consider Curry's and Turing's call-by-value fixed point combinators Y and Z: Y λy.∆∆, Z ΘΘ, ∆ λx.y(λz.xxz), Θ λx.λy.y(λz.xxyz).

e

  ::= x | λx.e | ee | op(p, x.e).

Example 15 .Proposition 3 .

 153 For the global state monad G we define the map Ĝ :Rel(X, Y ) → Rel(GX, GY ) as α ĜR β ⇐⇒ ∀σ ∈ S. α(σ) (I S × R) β(σ). It is straightforward to see that Ĝ is a relator for G.It is not hard to see that we can extend Ĝ to relators for M ⊗ G, DM ⊗ G, and C ⊗ G. In fact, Proposition 1 extends to relators. Given a monad T = T , t, -T and a relator T for T, define the sum TM of T and M as T M. Additionally, define the tensor T ⊗ G of T and Ĝ by α (T ⊗ G)R β if an only if ∀σ. α(σ) T(I S × R) β(σ). Then TM is a relator for TM, and (T ⊗ G) is a relator for T ⊗ G.

Fig. 1 .

 1 Fig. 1. Compatible and substitutive closure construction.

  1• • • e n . The evaluation function of Definition 2 now maps terms to elements in T W, and it is essentially obtained modifying Definition 2 defining E[xe] n+1 η(E[xe]) and E[(λx.f )e] n+1 E[f [e/x]] n . The notion of a whnf-(bi)simulation (and thus the notions of whnf-(bi)similarity) is obtained modifying Definition 6 accordingly. In particular, clauses (enf 2) and (enf 4) are replaced by the following clause, where we use the notation R = (R Λ : Λ + → Λ, R W : W + → W) to denote a (call-by-name) λ-term relation.

  • • E • ι) |f |, and thus the wished thesis, since ι• • E • ι is nothing but c V .Finally, we show that for all terms e, f , if e E Λ f , then e A Λ f (a similar result holds mutatis mutandis for values, so that we can conclude E ⊆ A ). Indeed, suppose F V (e) ∪ F V (f ) ⊆ x, then by substitutivity of E we have that eE Λ f implies e[v/x] E Λ f [v/x],for all closed values v (notice that since we are substituting closed values, sequential and simultaneous substitution coincide). That essentially means e[v/x] c

	Λ f [v/x],
	and thus e

  Theorem 3. Enf-similarity is the largest enf-simulation up-to context, and enfbisimilarity is the largest enf-bisimulation up-to context. Example 18. We apply Theorem 3 to simplify the proof of the equivalence between Y and Z given in Example 17. In fact, it is sufficient to show that the symmetric closure of term relation R defined below is an enf-bisimulation up-to context.

R Λ {(Y , Z), (∆∆z, Zyz), (∆∆, y(λz.∆∆z) or y(λz.Zyz))}, R E I E .

Example 19. Recall the fixed point combinators with ticking operations Y and Z of Example 4. Let us consider the relator Ĉ. It is not hard to see that Y and Z are not enf-bisimilar (that is because the ticking operation is evaluated at different moments, so to speak). Nonetheless, once we pass them a variable x 0 as argument, we have Zx 0 E Λ Y x 0 . For, observe that the the term relation R defined below is an enf-simulation up-context.

Besides, as we will discuss in Section 6.4, the formal analysis of call-by-name normal form bisimilarity strictly follows the corresponding (more challenging) analysis of call-by-value normal form bisimilarity.

Meaning that two terms e1, e2 are tested for their applicative behaviour against all terms of the form E[e], E[e ], for any pair of terms (e, e ) stored in the environment.

Although this is not strictly necessary, for simplicity we work with distributions over countable sets only, as the sets of values and normal forms are countable.

For simplicity, we write only those pis such that pi > 0.

Here op denotes the operation symbol, whereas n ≥ 0 denotes its arity.

Notice that since I = (1)• we can derive condition (rel 1) from condition (rel 3).