Refocusing in Reduction Semantics

The evaluation function of a reduction semantics (i.e., a small-step operational semantics with an explicit representation of the reduction context) is canonically defined as the transitive closure of (1) decomposing a term into a reduction context and a redex, (2) contracting this redex, and (3) plugging the contractum in the context. Directly implementing this evaluation function therefore yields an interpreter with a worst-case overhead, for each step, that is linear in the size of the input term. We present sufficient conditions over the constituents of a reduction semantics to circumvent this overhead, by replacing the composition of (3) plugging and (1) decomposing by a single ``refocus'' function mapping a contractum and a context into a new context and a new redex, if any. We also show how to construct such a refocus function, we prove the correctness of this construction, and we analyze the complexity of the resulting refocus function. The refocused evaluation function of a reduction semantics implements the transitive closure of the refocus function, i.e., a ``pre-abstract machine.'' Fusing the refocus function with the trampoline function computing the transitive closure gives a state-transition function, i.e., an abstract machine. This abstract machine clearly separates between the transitions implementing the congruence rules of the reduction semantics and the transitions implementing its reduction rules. The construction of a refocus function therefore shows how to mechanically obtain an abstract machine out of a reduction semantics, which was done previously on a case-by-case basis. We illustrate refocusing by mechanically constructing Felleisen et al.'s CK machine from a call-by-value reduction semantics of the lambda-calculus, and by constructing a substitution-based version of Krivine's machine from a call-by-name reduction semantics of the lambda-calculus. We also mechanically construct three one-pass CPS transformers from three quadratic context-based CPS transformers for the lambda-calculus.

[1]  Mitchell Wand Semantics-directed machine architecture , 1982, POPL '82.

[2]  Gilles Kahn,et al.  Natural Semantics , 1987, STACS.

[3]  Matthias Felleisen,et al.  The calculi of lambda-nu-cs conversion: a syntactic theory of control and state in imperative higher-order programming languages , 1987 .

[4]  Matthias Felleisen,et al.  Control operators, the SECD-machine, and the λ-calculus , 1987, Formal Description of Programming Concepts.

[5]  Matthias Felleisen,et al.  Programming languages and lambda calculi , 1989 .

[6]  Pierre Crégut,et al.  An abstract machine for Lambda-terms normalization , 1990, LISP and Functional Programming.

[7]  Pierre-Louis Curien,et al.  An Abstract Framework for Environment Machines , 1991, Theor. Comput. Sci..

[8]  Flemming Nielson,et al.  Semantics with applications - a formal introduction , 1992, Wiley professional computing.

[9]  M. Felleisen,et al.  Reasoning about programs in continuation-passing style , 1993 .

[10]  Olivier Danvy,et al.  Back to Direct Style , 1992, Sci. Comput. Program..

[11]  Joseph A. Goguen,et al.  Algebraic semantics of imperative programs , 1996, Foundations of computing series.

[12]  Philip Wadler,et al.  The essence of functional programming (Invited talk) , 1997 .

[13]  John C. Reynolds Definitional Interpreters for Higher-Order Programming Languages , 1998, High. Order Symb. Comput..

[14]  Thérèse Hardin,et al.  Functional runtime systems within the lambda-sigma calculus , 1998, Journal of Functional Programming.

[15]  Mitchell Wand,et al.  Trampolined style , 1999, ICFP '99.

[16]  Yong Xiao,et al.  From Syntactic Theories to Interpreters: A Specification Language and Its Compilation , 2000, ArXiv.

[17]  Olivier Danvy,et al.  Defunctionalization at work , 2001, PPDP '01.

[18]  Olivier Danvy,et al.  Syntactic Theories in Practice , 2001, RULE@PLI.

[19]  Amr Sabry,et al.  From Syntactic Theories to Interpreters: Automating the Proof of Unique Decomposition , 2001, High. Order Symb. Comput..

[20]  Peter Sestoft,et al.  Demonstrating Lambda Calculus Reduction , 2001, MFPS.

[21]  David A. Schmidt,et al.  The essence of computation: complexity, analysis, transformation , 2002 .

[22]  Olivier Danvy,et al.  A functional correspondence between evaluators and abstract machines , 2003, PPDP '03.

[23]  Olivier Danvy,et al.  A Functional Correspondence between Evaluators and Abstract Machines , 2003 .

[24]  Mads Sig Ager,et al.  From Natural Semantics to Abstract Machines , 2004, LOPSTR.

[25]  Simon L. Peyton Jones,et al.  Making a fast curry: push/enter vs. eval/apply for higher-order languages , 2004, ICFP '04.

[26]  Gordon D. Plotkin,et al.  A structural approach to operational semantics , 2004, J. Log. Algebraic Methods Program..

[27]  M. Goldberg On the Recursive Enumerability of Fixed-Point Combinators , 2004 .

[28]  Hans Hüttel,et al.  Recursion vs. Replication in Simple Cryptographic Protocols , 2004 .

[29]  Glynn Winskel,et al.  New-HOPLA: A Higher-order Process Language with Name Generation , 2004, IFIP TCS.

[30]  Olivier Danvy,et al.  On Evaluation Contexts, Continuations, and the Rest of the Computation , 2004 .

[31]  Peter Rossmanith,et al.  Maximum Exact Satisfiability: NP-completeness Proofs and Exact Algorithms , 2004 .

[32]  Andrew Twigg,et al.  Distributed Approximation of Fixed-Points in Trust Structures , 2005, 25th IEEE International Conference on Distributed Computing Systems (ICDCS'05).

[33]  Olivier Danvy,et al.  CPS transformation of beta-redexes , 2000, Inf. Process. Lett..

[34]  Luca Aceto,et al.  Bisimilarity is not finitely based over BPA with interrupt , 2005, Theor. Comput. Sci..

[35]  Glynn Winskel,et al.  Profunctors, open maps and bisimulation , 2004, Mathematical Structures in Computer Science.

[36]  Bolette Ammitzbøll Madsen An algorithm for exact satisfiability analysed with the number of clauses as parameter , 2006 .