Variations on a theme: call-by-value and factorization

Similar documents
The Permutative λ-calculus

Call-by-value solvability, revisited

Proof nets and the call-by-value λ-calculus

On the Value of Variables

arxiv: v2 [cs.lo] 19 Sep 2016

The structural λ-calculus

Call-by-value non-determinism in a linear logic type discipline

Alonzo Church ( ) Lambda Calculus. λ-calculus : syntax. Grammar for terms : Inductive denition for λ-terms

Standardization of a call-by-value calculus

Lazy Strong Normalization

Silvia Ghilezan and Jelena Ivetić

The lambda calculus with constructors

arxiv: v1 [cs.lo] 27 Dec 2018

(Leftmost-outermost) beta reduction is invariant, indeed

REVISITING CALL-BY-VALUE BÖHM TREES IN LIGHT OF THEIR TAYLOR EXPANSION

Typed Arithmetic Expressions

Classical Combinatory Logic

HORSes: format, termination and confluence

Five Basic Concepts of. Axiomatic Rewriting Theory

Geometry of Interaction

Observability for Pair Pattern Calculi

Type Systems Winter Semester 2006

Reasoning about call-by-need by means of types

A General Type for Storage Operators

Parametric parameter passing -calculus

Standardization of a call-by-value lambda-calculus

Typing λ-terms. Types. Typed λ-terms. Base Types. The Typing Relation. Advanced Formal Methods. Lecture 3: Simply Typed Lambda calculus

Lazy Functions as Processes

The Bang Calculus: an untyped lambda-calculus generalizing Call-By-Name and Call-By-Value

Diagrams for Meaning Preservation

Equivalence of Algebraic λ -calculi extended abstract

SHARING IN THE WEAK LAMBDA-CALCULUS REVISITED

A theory of reflexive computation based on soft intuitionistic logic

CS 4110 Programming Languages & Logics. Lecture 16 Programming in the λ-calculus

A Behavioral Congruence for Concurrent Constraint Programming with Nondeterministic Choice

Böhm trees, Krivine machine and the Taylor expansion of ordinary lambda-terms

Continuations, Processes, and Sharing. Paul Downen, Luke Maurer, Zena M. Ariola, Daniele Varacca. September 8, 2014

λ Slide 1 Content Exercises from last time λ-calculus COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification

On space efficiency of Krivine s abstract machine and Hyland-Ong games

THE STRONG INVARIANCE THESIS

Call-by-Value Non-determinism in a Linear Logic Type Discipline

Foundations of Strong Call by Need

Origin in Mathematical Logic

Small families. (at INRIA with Gérard and in the historical λ-calculus) Jean-Jacques Lévy

The Suspension Notation as a Calculus of Explicit Substitutions

What is a Categorical Model of the Differential and the Resource λ-calculi?

The Vectorial Lambda-Calculus

Dependent Types and Explicit Substitutions

Simply Typed λ-calculus

Non deterministic classical logic: the λµ ++ -calculus

EasyChair Preprint. Normalization and Taylor expansion of lambda-terms

A Terminating and Confluent Linear Lambda Calculus

On the Correctness of the Krivine Machine

Intersection and Union Type Assignment and

in Linear Logic Denis Bechet LIPN - Institut Galilee Universite Paris 13 Avenue Jean-Baptiste Clement Villetaneuse, France Abstract

Formalizing a Named Explicit Substitutions Calculus in Coq

The Call-by-Need Lambda Calculus

Confluence via strong normalisation in an algebraic λ-calculus with rewriting

Strong Normalization as Safe Interaction

On Elementary Linear Logic and polynomial time (Extended Abstract)

Origin in Mathematical Logic

A probabilistic lambda calculus - Some preliminary investigations

Correspondence between Normalization of CND. and Cut-Elimination of LKT. Ichiro Ogata Umezono Tsukuba JAPAN

Quantitative Types for the Linear Substitution Calculus

A characterization of the Taylor expansion of λ-terms

Nominal Completion for Rewrite Systems with Binders

The Locally Nameless Representation

Probabilistic Applicative Bisimulation and Call-by-Value Lam

Type Systems. Lecture 2 Oct. 27th, 2004 Sebastian Maneth.

Sub-λ-calculi, Classified

3.2 Equivalence, Evaluation and Reduction Strategies

Characterizing Polynomial and Exponential Complexity Classes in Elementary Lambda-Calculus

Solvability in Resource Lambda-Calculus

Higher-Order Matching in the Linear λ-calculus with Pairing

Towards Correctness of Program Transformations Through Unification and Critical Pair Computation

Bisimulation and coinduction in higher-order languages

Computational Soundness of a Call by Name Calculus of Recursively-scoped Records. UMM Working Papers Series, Volume 2, Num. 3.

summer school Logic and Computation Goettingen, July 24-30, 2016

The Rewriting Calculus as a Combinatory Reduction System

Models of computation

If-then-else and other constructive and classical connectives (Or: How to derive natural deduction rules from truth tables)

A THEORY OF EXPLICIT SUBSTITUTIONS WITH SAFE AND FULL COMPOSITION

6- Normalization of classical call-by-need

An Implicit Characterization of PSPACE

Investigation of Prawitz s completeness conjecture in phase semantic framework

Resource lambda-calculus: the differential viewpoint

Conservativity of Embeddings in the λπ Calculus Modulo Rewriting

Strong Normalization for Guarded Types

Structuring Logic with Sequent Calculus

About Typed Algebraic Lambda-calculi

FROM COHERENT TO FINITENESS SPACES

The Dierential Lambda-Calculus

Sequentiality in Kahn- Macqueen nets and the λ-calculus

Relational Graph Models, Taylor Expansion and Extensionality

Categories, Proofs and Programs

The differential lambda-mu-calculus

Curry-Howard Correspondence for Classical Logic

Računske interpretacije intuicionističke i klasične logike

Congruence of Bisimulation in a Non-Deterministic Call-By-Need Lambda Calculus

On the Correctness and Efficiency of the Krivine Machine

Transcription:

Variations on a theme: call-by-value and factorization Beniamino Accattoli INRIA & LIX, Ecole Polytechnique Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 1 / 31

Outline 1 Call-by-value λ-calculus 2 Factorization Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 2 / 31

Outline 1 Call-by-value λ-calculus 2 Factorization Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 3 / 31

Call-by-value Plotkin s call-by-value λ-calculus: t ::= V t t V ::= x λx.t β v rule: (λx.t) V βv t{x/v } Most functional programming languages are CBV. Most works on λ-calculus are call-by-name (CBN). Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 4 / 31

Call-by-value Plotkin s calculus is not satisfactory for various reasons. Semantic models do not faithful reflect bueibdivergence. Let = λx.xx. Now consider: M = (λx. ) (y z) Semantically M should be divergent, but it is a β v -normal form! Problem studied by Luca Paolini and Simona Ronchi della Rocca ("call-by-value solvability"). Another problem: the completeness of CPS-translations. Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 5 / 31

λ-calculus and Linear Logic λ-calculus can be represented in various ways inside Linear Logic. Two main translations: 1 Call-by-name: (A B) n := (!A n ) B n. 2 Call-by-value: (A B) v :=!(A v B v ). Both appear in Girard s seminal paper (1987) Girard calls the second boring. Sad consequence: the CBV-translation is less known and understood. Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 6 / 31

Call-by-value and Linear Logic The translations are typed but both can be extended to pure CBN and CBV λ-calculus by means of recursive types. Curious fact: M = (λx. ) (y z) diverges when represented in LL Proof-Nets via the CBV translation (which is good). Idea: to extract the calculus corresponding to CBV Proof-Nets. Relation with Proof-Nets requires explicit substitutions. But here ES are evaluated in just one shot. Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 7 / 31

The value-substitution calculus λ vsub Let L be a possibly empty list [x 1 /u 1 ]... [x n /u n ]. Define λ vsub as: Rules: t ::= V t t t[x/u] V ::= x λx.t (λx.t)l s db t[x/s]l t[x/v L] sv t{x/v }L Note that s needs not to be a value. Note that explicit substitutions can be reduced only if the content is a value. Note the use of distance (i.e. L). λ vsub is confluent. Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 8 / 31

Solvability and explicit substitution Re-consider the problematic term: M = (λw. ) (y z) Now let s look at it in our new framework: (λw. ) (y z) db [w/y z] db (x x)[x/ ][w/y z] sv ( )[w/y z]... M has no nf! (which is good) Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 9 / 31

Herbelin-Zimmerman s λ CBV There is a similar calculus by Herbelin and Zimmerman, but without distance. The syntax is the same, but not the rules: t ::= V t t t[x/u] V ::= x λx.t Operational rules (λx.t) s t[x/s] t[x/v ] letv t{x/v } Structural rules t[x/u[y/w]] letlet t[x/u][y/w] t[x/u] w letapp (t w)[x/u] Note that s needs not to be a value, but: (λx.t)[y/w] s is not a redex. t[y/v [x/u]] is not a letv redex. The structural rules become identities on Proof-Nets. Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 10 / 31

Simulation λ vsub is an equational sub-calculus of λ CBV : (λx.t)l s db t[x/s]l (λx.t)l s let app ((λx.t) s)l t[x/s]l t[x/v L] sv t{x/v }L t[x/v L] let let t[x/v ]L letv t{v /x}l Thus λvsub λ CBV. Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 11 / 31

Inverse simulation Apparently, λ vsub is strictly contained in λ CBV. These rules cannot be simulated: t[x/u[y/w]] letlet t[x/u][y/w] t[x/u] w letapp (t w)[x/u] But this is not quite true... Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 12 / 31

Structural congruence Let o be the equivalence relation generated by: t[x/s][y/u] o1 t[y/u][x/s] if x / fv(u)&y / fv(s) t u[x/s] o2 (t u)[x/s] if x / fv(t) t[x/s] u o3 (t u)[x/s] if x / fv(u) t[x/s[y/u]] o4 t[x/s][y/u] if y / fv(t) o contains λ CBV structural rules: t[x/u[y/w]] letlet t[x/u][y/w] t[x/u] w letapp (t w)[x/u] Operational rules: t λcbv u implies t λvsub u. Structural rules: t λcbv u implies t o u. Hence λcbv ( λvsub / o ). Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 13 / 31

Strong bisimulations o is a strong bisimulation, i.e.: t t λvsub t o t s.t. o o u λvsub u t λvsub u Rewriting modulo a strong bisimulation preserves confluence and strong normalisation. If t o u then t and u map to the same Proof-Net. Then they can really be considered as the same object. Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 14 / 31

Concluding In λ vsub there is a good match between semantics and divergence. Recent work in collaboration with Luca Paolini (FLOPS 2012). This work gives an operational characterization of CBV-solvablity (a semantic notion). The operational characterization uses crucially two factorization theorems. Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 15 / 31

Outline 1 Call-by-value λ-calculus 2 Factorization Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 16 / 31

Confluence A system S if confluent when: t u 1 t u 1 implies v s.t. u 2 u 2 v A system S if locally confluent when: t u 1 t u 1 implies v s.t. u 2 u 2 v Termination Confluence = Local Confluence (Newman s Lemma). Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 17 / 31

General Idea λ-calculus has just one rule: (λx.t) u β t{x/u} which does not terminate. Explicit substitutions, abstractly: 1 Creation of substitutions: (λx.t)l u db t[x/u]. 2 Set of rules executing substitutions: t[x/u] t{x/u}. Key property: each rule of an ES-calculus terminates. So ES-calculi are sort of locally terminating systems, which are globally non-terminating. Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 18 / 31

Local termination and confluence New proof technique for confluence. Prove local confluence of each rule alone. Termination gives confluence of each rule. Hindley-Rosen Lemma: if two reductions 1 and 2 commute: t 1 u 1 t 1 u 1 2 implies v s.t. 2 2 u 2 u 2 1 v and are confluent then 1 2 is confluent. Prove commutation of each pair of rule. Termination often reduces commutation to local commutation. Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 19 / 31

Local termination So in ES-calculi a global property as confluence can be reduced to local confluence and local commutation. Surprising: in λ-calculus confluence do not reduce to local confluence. ES-calculi are more complex than λ-calculus, but local termination provides new proof techniques. Another notion which can be localized is factorization. Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 20 / 31

Standardization Termination is about the existence of results. Confluence is about the unicity of results. Standardization instead is about how to compute. It identifies a specific class of reductions to which any other reduction can be transformed by permuting its steps. It has many important corollaries, in particular it gives a normalizing strategy for evaluation. Many applications require a simpler form, called factorization. Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 21 / 31

Factorization Factorization is a simple form of standardization. Head contexts in λ-calculus: H ::= [ ] λx.h H t Head reduction h in λ-calculus is the closure by head contexts H of: (λx.t) u β t{x/u} Internal reduction is the complement of head reduction, i.e. i := β \ h. Factorization theorem: Every reduction t β u can be re-organized as t h i u Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 22 / 31

Factorization theorem in λ-calculus At first sight factorization is easy. Local diagram permutation diagram: t i u h+ v i h w Two abstract lemmas, similar to Newman s, imply the factorization theorem when: 1 + h is composed of at most one step, or 2 h is strongly normalizing. Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 23 / 31

Factorization is non-trivial Unfortunately, β lacks both properties. The sequence + h can have length > 1: (λx.x x) (I I) i (λx.x x) I h (I I) (I I) h I (I I) i h I I h is not strongly normalising: (λx.x x) λx.x x h (λx.x x) λx.x x h... Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 24 / 31

Factorization and explicit substitutions The basic ES-calculus λ sub : Define head contexts as: We get four reductions: (λx.t)l s db t[x/s]l t[x/u] s t{x/u} H ::= [ ] λx.h H t H[x/t] Remember: they all terminates. i h db dbi dbh s si sh Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 25 / 31

Factorization for λ sub We get four diagrams: t dbi u dbh v dbi w t si u dbh v s w dbh dbh t si u sh sh v si w t dbi u sh sh v db w The abstract lemmas get factorization of each single diagram (a new abstract lemma is required). Glueing the obtained local factorizations (easy to do) we get the factorization theorem for λ sub. Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 26 / 31

Back to call-by-value Call-by-value factors with respect to weak reductions. Weak contexts: W ::= [ ] W t t W W [x/t] t[x/w ] Weak reduction w : closure of the rules by weak contexts. Same technique gives factorization: if t λ vsub u then t w w u. Factorization also with respect to stratified weak reduction, defined from head-weak contexts H[W ]. Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 27 / 31

Linear substitution calculus The linear substitution calculus λ ls : (λx.t)l u db t[x/u]l C[x][x/u] ls C[u][x/u] t[x/u] w t x / fv(t) Head factorization does not hold: x[x/y[y/z]][z/u] lsi x[x/z[y/z]][z/u] lsh x[x/u[y/z]][z/u] The two steps cannot be permuted. Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 28 / 31

Linear substitution calculus New notion of head reduction. We need to refine the notion of head substitution. Set: H[x][x/u] hls H[u][x/u] Then define linear head reduction as H[ db ] H[ hls]. The linear substitution calculus enjoys factorization with respect to linear head reduction. Linear head reduction can be seen as an abstraction of Krivine Abstract Machine (Danos and Regnier). Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 29 / 31

Linear Head reduction Linear head reduction arises naturally and repeatedly in the LL literature. First studied in connection with Proof-Nets (Mascari, Pedicini). Then in semantics: geometry of interaction and game semantics. Then in connection with the π-calculus (Mazza) and differential λ-calculus (Ehrhard, Regnier). Recently it has been shown to induce a measure for complexity (Accattoli, Dal Lago). Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 30 / 31

THANKS! Accattoli (INRIA Parsifal) Variations on a theme: call-by-value and factorization 31 / 31