Eﬀectful 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 inﬁnitary tree-like normal forms, i.e. at their B¨ohm or L´evy-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 eﬀects, `a la Plotkin and Power. We show that some mild conditions on monads and rela-tors, which have already been shown to guarantee eﬀectful applicative bisimilarity to be a congruence relation, are enough to prove that the obtained notion of bisimilarity, which we call eﬀectful normal form bisim-ilarity , 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 eﬀectful 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 [51], 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 Thanks to the ANR projects 14CE250005 ELICA and 16CE250011 REPAS. many alternative techniques the research community has been proposing along the years, one can cite logical relations and applicative bisimilarity [1,4,8], both based on the idea that equivalent higher-order terms should behave the same 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 [5] 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 [11], 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 [37,65]. 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 [37,65]), or to their eager normal form (like in the call-by-value λ-calculus [38]). 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 [49,56] have been studied by way of denotational semantics [18,20,31], logical relations [10,14], applicative bisimilarity [13,16,36], and normal form bisimilarity [20,41]. While the denotational semantics, logical relation semantics, and applicative bisimilarity of effectful calculi have been studied in the abstract [15,25,30], the same cannot be said about normal form bisimilarity. Particularly relevant for our purposes is [15], 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 [71] or lax extension [6,26], 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 [1,16,36,52] 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 [67] and applicative distances [23] for languages with generic algebraic effects.
The main contribution of [15] 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 [15]. 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 [47,51], or logical relations [55,61]-(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 [60], 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 bisim-ilarity (and thus for contextual equivalence), full abstraction fails, as already observed in the case of the pure λ-calculus [3,38] (nonetheless, it is worth mentioning that full abstraction results are known to hold for calculi with a rich expressive power [65,68]).
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 Sect. 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 Sect. 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 Sect. 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 Sect. 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 [1]. 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(λ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 [66] (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: Θ λ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 [16], probabilistic CIU equivalence and logical relations [10], and probabilistic applicative bisimilarity [13,16]. 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 [66], the call-by-name counterparts of Y and Z are proved to be equivalent using probabilistic environmental bisimilarity. The notion of an environmental bisimulation [63] 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: 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 (Sect. 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. For instance, we can consider the following variation of Curry's and Turing's fixed point combinator of Example 1, obtained by adding the operation symbol tick after every λ-abstraction. Y λy.tick(ΔΔ), Δ λx.tick(y(λz.tick(xxz))), Z ΘΘ, Θ λx.tick(λy.tick(y(λz.tick(xxyz)))).
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 [62].

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 [2] (in particular with the notions of ω-complete (pointed) partial order-ω-cppo, for short-monotone, and continuous functions), basic order theory [19], and basic category theory [46]. Additionally, we assume the reader to be acquainted with the notion of a Kleisli triple [46] 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 [46] and [2], with the only exception that we use the notation (x n ) n to denote an ω-chain x 0 · · · x n · · · in a domain (X, , ⊥). 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.
We use monads to give operational semantics to our calculi. Following Moggi [49,50], 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. [50,73].
Example 6 (Probabilistic Nondeterminism). In this example we assume sets to be countable 3 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(MX), whereas the unit dm is defined in the obvious way. For f : X → DM Y , define: It is easy to see that DM is isomorphic to the subdistribution monad.
Example 7 (Cost). The cost (also known as ticking or improvement [62]) monad whereas Kleisli extension is defined as follows: 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: 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 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 [28]. Although these operations are defined on Lawvere theories [29,40], here we can rephrase them in terms of monads as follows. T (S × X) S , whereas the maps tm and t ⊗ g are defined as tm X t MX • m X and (t ⊗ g) X curry t S×X , respectively. Finally, define: where, for a function f : , 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 [28]). 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][57][58], 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 symbol 5 (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 [12]) such that f † is Σ-algebra morphism, meaning that for any f : X → T Y , and elements 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 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: 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 [58] 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 for any f : X → T Y , p ∈ P , and κ : I → T X: 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( 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 [28] for details. Here we simply notice that we can define the interpretation ] 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 [17] we need monads to account for infinitary computational behaviours. We thus look at Σ-continuous monads. [24]) 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 : When clear from the context, we will omit subscripts in ⊥ X and X . whereas the order on DM X is defined by μ ν ⇐⇒ ∀x ∈ X. μ(just x) ≤ ν(just x). Finally, the order on GM X is defined pointwise 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 coarsegrain [44] version of the calculus studied in [15]. 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 [5] (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 .
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 [15], postponing the definition of monadic call-by-name operational semantics to Sect. 6.4. Recall that a (call-by-value) evaluation context [22] is a term with a single hole [−] defined by the following grammar, where e ∈ Λ and v ∈ V: We write E[e] for the term obtained by substituting the term e for the hole [−] in E.
Following [38], 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 function [[−]] mapping 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).  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 [38] to calculi with algebraic effects. In order to account for effectful behaviours, we follow [15] and parametrise our notions of equivalence and refinement by relators [6,71].

Relators
The notion of a relator for a functor T (on Set) [71] (also called lax extension of T [6]) 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 [6] and coalgebra [71], relators have been recently used to study notions of applicative bisimulation [15], logic-based equivalence [67], and bisimulation-based distances [23] for λ-calculi extended with algebraic effects. Moreover, several forms of monadic lifting [25,32] resembling relators have been used to study abstract notions of logical relations [55,61].
Before defining relators formally, it is useful to recall some background notions on (binary) relations. The reader is referred to [26] 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(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 : We can now define relators formally.

Definition 3. A relator for a functor T (on Set) is a set-indexed family of maps
. We say that Γ is conversive if it additionally satisfies condition (rel 5).
( r e l 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 [15,43] a kernel preservation condition is required in place of (rel 3). Such a condition is also known as stability in [27]. Stability requires the equality It is easy to see that a relator always satisfies stability (see Corollary III.1.4.4 in [26]).
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:
Finally, we observe that the collection of relators is closed under specific operations (see [43]).

Proposition 2.
Let T , U be functors, and let UT denote their composition. Moreover, let Γ , Δ be relators for T and U , respectively, and {Γ i } i∈I be a family of relators for T . Then: The mappingM describes the structure of the usual simulation clause for partial computations, whereas M • describes the corresponding co-simulation clause. It is easy to see thatM is a relator for M. By Proposition 2, the mapM ∧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 relatorD relying on the notion of a coupling and results from optimal transport [72]. 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) mapD : Rel(X, Y ) → Rel(DX, DY ) as follows: We can show thatD is a relator for D relying on Strassen's Theorem [69], which shows thatD can be characterised universally (i.e. using an universal quantification). [69]). For all μ ∈ DX, ν ∈ DY , and

Theorem 1 (Strassen's Theorem
As a corollary of Theorem 1, we see thatD describes the defining clause of Larsen-Skou bisimulation for Markov chains (based on full distributions) [34]. Finally, we observe thatDM DM 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 C : 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 [62].
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.

Proposition 3. Given a monad T = T , t, − T and a relatorT for T, define the sumTM ofT andM asTM. Additionally, define the tensor T ⊗ G ofT andĜ by α (T ⊗ G)R β if an only if ∀σ. α(σ)T(I S × R) β(σ). ThenTM is a relator for TM, and (T ⊗ G) is a relator for T ⊗ G.
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 : The relatorsM,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.
Having defined relators and their basic properties, we now introduce the notion of an effectful eager normal form (bi)simulation.

Effectful 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 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
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 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 [15]. 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 ( 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(Λ, is defined as follows (here I X denotes the identity relation on variables, i.e. the set of pairs of the form (x, x)): 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 [70], 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: Finally, we define effectful eager normal form bisimilarity.
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 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 [37]. Such a construction has been previously adapted to the pure call-by-value λ-calculus (and its extension with delimited and abortive control operators) in [9], whereas Lassen has proved compatibility of pure eager normal form bisimilarity via a CPS translation [38]. 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 Fig. 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 [5]), and it is closed under the substitution operation (a property known as substitutivity [5]). 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.
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 ] 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.
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 Fig. 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 [15]. First of all, we rephrase the notion of an effectful applicative (bi)simulation of [15] 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
We can thus phrase the definition of effectful applicative similarity (with respect to a relator Γ ) as follows.

Definition 8. A term relation
is an effectful applicative simulation with respect to Γ (applicative simulation, for short) if: 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 amongx = x 1 , . . . , x n . We letv range over n-ary sequences of closed values v 1 , . . . , v n . Define: 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
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,  [15] 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 [38], 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 [37,60,64] 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.
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 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.
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 [35].

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 1 · · · e n . The evaluation function of Definition 2 now maps terms to elements in T W, and it is essentially obtained modifying 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.
A straightforward modifications of the rules in Fig. 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 [65], where it was called open bisimilarity. Open bisimilarity provides a coinductive characterisation of Lévy-Longo tree equivalence [42,45,53], and has been shown to coincide with the equivalence (notably weak bisimilarity) induced by Milner's encoding of the λ-calculus into the π-calculus [48].
In [37] 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 [38], 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 [54], and thus to be a congruence relation. An elementary proof of congruence properties of eager normal form bisimilarity is given in [9], where Lassen's relational construction [37] is extended to the call-by-value λ-calculus, as well as its extensions with delimited and abortive control operators. Finally, following [65], 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 [21].
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 [9], as well as control and state [68] (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 [39], 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 [20] and probabilistic [41] 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 [15].
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 [37,38], but to hold in presence of control and state [68], 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 [33], 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 [7,59].
Open Access This chapter is licensed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license and indicate if changes were made.
The images or other third party material in this chapter are included in the chapter's Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the chapter's Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder.