Equivalence of eval-readback and eval-apply big-step evaluators by structuring the lambda-calculus's strategy space

Pablo Nogueira,Álvaro García-Pérez
2024-09-19
Abstract:We study the equivalence between eval-readback and eval-apply big-step evaluators in the general setting of the pure lambda calculus. We study `one-step' equivalence (same strategy) and also discuss `big-step' equivalence (same final result). One-step equivalence extends for free to evaluators in other settings (calculi, programming languages, proof assistants, etc.) by restricting the terms (closed, convergent) while maintaining the strategy. We present a proof that one-step equivalence holds when (1) the `readback' stage satisfies straightforward well-formedness provisos, (2) the `eval' stage implements a `uniform' strategy, and (3) the eval-apply evaluator implements a `balanced hybrid' strategy that has `eval' as a subsidiary strategy. The proof proceeds by application of the `lightweight fusion by fixed-point promotion' program transformation on evaluator implementations to fuse readback and eval into the balanced hybrid. The proof can be followed with no previous knowledge of the transformation. We use Haskell 2010 as the implementation language, with all evaluators written in monadic style to guarantee semantics (strategy) preservation, but the choice of implementation language is immaterial. To illustrate the large scope of the equivalence, we provide an extensive survey of the strategy space using canonical eval-apply evaluators in code and big-step `natural' operational semantics. We discuss the strategies' properties, some of their uses, and their abstract machines. We improve the formal definition of uniform and hybrid strategy, use it to structure and classify the strategy space, and to obtain generic higher-order evaluators which are used in the equivalence proof. We introduce a systematic notation for both evaluator styles and use it to summarise strategy and evaluator equivalences, including (non-)equivalences.
Logic in Computer Science
What problem does this paper attempt to address?
The main problem that this paper attempts to solve is the **equivalence problem of evaluators**, specifically to explore and prove the one - step equivalence and big - step equivalence between the `eval - readback` - style and `eval - apply` - style big - step evaluators in pure lambda calculus. ### 1. Problem Background In formal semantics and the implementation of higher - order languages based on lambda calculus, big - step evaluators are very common. A big - step evaluator defines an evaluation strategy by specifying how to locate and contract redexes. It is called "big - step" because it directly gives the final result of iterative small - step reductions. Big - step evaluators usually have two definition styles: - **eval - apply**: Defined by a function, it recursively evaluates sub - terms and delegates the specific evaluation of application terms to a local `apply` function. - **eval - readback**: Defined by the combination of two functions, that is, first perform `eval` evaluation to an intermediate form, and then further simplify it through `readback`. ### 2. Research Problems The paper mainly studies the following two aspects of problems: - **One - step equivalence**: Whether the two evaluators define the same evaluation strategy (i.e., evaluate redexes in exactly the same order). - **Big - step equivalence**: Even if the two evaluators define different strategies, whether they can give the same final result. ### 3. Solutions To prove the equivalence of these two styles of evaluators, the author introduces a new method, using the "lightweight fusion by fixed - point promotion (LWF)" program transformation. The specific steps are as follows: - **LWF Transformation**: Through a series of simple and syntactic program transformation steps that keep the strategy unchanged, fuse the `eval - readback` combination into a single `eval - apply` evaluator. - **General Evaluators**: Define general `eval - apply` and `readback` evaluators, which implement standard evaluators for all standard strategies as fixed points. - **Constraints**: Through the LWF steps and the well - formedness conditions of the general evaluators, collect and list the equations that ensure one - step equivalence. ### 4. Main Contributions The main contributions of the paper include: - Provide a broad survey of various evaluation strategies in pure lambda calculus, covering known, less - known, and novel strategies. - Introduce a new strategy - "spine applicative order" for evaluating general recursive functions in bounded continuation - passing style. - Accurately describe the characteristics of the `eval - readback` style and discuss the extent to which the evaluation can move between `eval` and `readback`. - Propose general templates and evaluators that can implement all variants through parameterization, thereby expressing the entire evaluator space in one definition. - Use LWF transformation to conduct an equivalence proof, providing detailed steps and a technical summary. Through these contributions, the paper not only solves the problem of evaluator equivalence but also lays the foundation for further research on other strategy spaces.