Lecture Notes in Computer Science Commenced Publication in 1973 Founding and Former Series Editors: Gerhard Goos, Juris Hartmanis, and Jan van Leeuwen
Editorial Board David Hutchison Lancaster University, UK Takeo Kanade Carnegie Mellon University, Pittsburgh, PA, USA Josef Kittler University of Surrey, Guildford, UK Jon M. Kleinberg Cornell University, Ithaca, NY, USA Alfred Kobsa University of California, Irvine, CA, USA Friedemann Mattern ETH Zurich, Switzerland John C. Mitchell Stanford University, CA, USA Moni Naor Weizmann Institute of Science, Rehovot, Israel Oscar Nierstrasz University of Bern, Switzerland C. Pandu Rangan Indian Institute of Technology, Madras, India Bernhard Steffen University of Dortmund, Germany Madhu Sudan Massachusetts Institute of Technology, MA, USA Demetri Terzopoulos University of California, Los Angeles, CA, USA Doug Tygar University of California, Berkeley, CA, USA Gerhard Weikum Max-Planck Institute of Computer Science, Saarbruecken, Germany
5608
Pierre-Louis Curien (Ed.)
Typed Lambda Calculi and Applications 9th International Conference, TLCA 2009 Brasília, Brazil, July 1-3, 2009 Proceedings
13
Volume Editor Pierre-Louis Curien Université Paris Diderot - Paris 7 Laboratoire PPS (CNRS / Paris 7) Case 7014, 75205 Paris Cedex 13, France E-mail:
[email protected]
Library of Congress Control Number: Applied for CR Subject Classification (1998): D.1.6, D.3.2, F.3, F.4, I.2.3 LNCS Sublibrary: SL 1 – Theoretical Computer Science and General Issues ISSN ISBN-10 ISBN-13
0302-9743 3-642-02272-3 Springer Berlin Heidelberg New York 978-3-642-02272-2 Springer Berlin Heidelberg New York
This work is subject to copyright. All rights are reserved, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, re-use of illustrations, recitation, broadcasting, reproduction on microfilms or in any other way, and storage in data banks. Duplication of this publication or parts thereof is permitted only under the provisions of the German Copyright Law of September 9, 1965, in its current version, and permission for use must always be obtained from Springer. Violations are liable to prosecution under the German Copyright Law. springer.com © Springer-Verlag Berlin Heidelberg 2009 Printed in Germany Typesetting: Camera-ready by author, data conversion by Scientific Publishing Services, Chennai, India Printed on acid-free paper SPIN: 12695461 06/3180 543210
Preface
This volume contains the papers of the 9th International Conference on Typed Lambda Calculi and Applications (TLCA 2009), which was held from July 1–3, 2009, in Bras´ılia, Brazil, as part of the 5th International Conference on Rewriting, Deduction, and Programming (RDP 2009) together with the International Conference on Rewriting Techniques and Applications (RTA 2009), the International School on Rewriting (ISR 2009), the 4th Workshop on Logical and Semantic Frameworks with Applications (LSFA 2009), the 10th International Workshop on Rule-Based Programming (RULE 2009), the 8th International Workshop on Functional and (Constraint) Logic Programming (WFLP 2009), the 9th International Workshop on Reduction Strategies in Rewriting and Programming (WRS 2009), and the annual meeting of the IFIP Working Group 1.6 on term rewriting. The TLCA series of conferences serves as a forum for presenting original research results that are broadly relevant to the theory and applications of lambda-calculus. Typed lambda-calculi are underlying programming language semantics and implementation on one hand, and a large part of proof theory on the other hand. Previous TLCA conferences were held in Utrecht (1993), Edinburgh (1995), Nancy (1997), L’Aquila (1999), Krak´ ow (2001), Valencia (2003), Nara (2005), and Paris (2007). For TLCA 2009, 27 papers were accepted out of 53 submissions. Each paper was reviewed by at least three members of the Program Committee, with the help of 84 external reviewers. I would like to thank the members of the Program Committee and the external reviewers for their great work, as well as Andrei Voronkov for providing the EasyChair system which was invaluable in the reviewing process, the electronic Program Committee meeting, and the preparation of this volume. In addition to the contributed papers, the TLCA program contained three invited talks by: – Marcelo Fiore (abstract included in the proceedings) – Robert Harper (joint with RTA 2009, abstract included in the proceedings) – Jean-Louis Krivine (talk entitled “Ultrafilters and the Heap”) Many people helped to make TLCA 2009 a success. I would like to thank in particular the Conference Chair Mauricio Ayala Rinc´ on, the TLCA Publicity Chair Luca Paolini, and the local organization team, as well as the following sponsors: Universidade de Bras´ılia, Brazilian Counsel of Technological and Scientific Development - CNPq, Brazilian Coordination for the Improvement of Higher Education Personnel - CAPES, and Federal District Research Foundation - FAPDF. April 2009
Pierre-Louis Curien
Organization
Conference Chair (RDP 2009) Mauricio Ayala Rinc´ on
Bras´ılia University, Brazil
Program Chair (TLCA 2009) Pierre-Louis Curien
CNRS and University Paris 7, France
Program Committee (TLCA 2009) Zena Ariola Patrick Baillot Thierry Coquand Ren´e David Dan Ghica Ryu Hasegawa Barry Jay Soren Lassen Luca Paolini Frank Pfenning Thomas Streicher
University of Oregon, USA CNRS and ENS Lyon, France G¨ oteborg University, Sweden Universit´e de Savoie, Chamb´ery, France University of Birmingham, UK Tokyo University, Japan University of Technology, Sydney, Australia Google, Sydney, Australia University of Turin, Italy Carnegie Mellon University, USA Technical University of Darmstadt, Germany
Local Organizing Committee David Deh´ arbe Fl´ avio L.C. de Moura Hermann Haeusler Elaine Pimentel Alejandro R´ıos Alberto Pardo
Federal University of Rio Grande do Norte (UFRN), Natal, Brazil University of Bras´ılia (UnB), Brazil Pontifical Catholic University of Rio de Janeiro (PUC-Rio), Brazil Federal University of Minas Gerais (UFMG), Belo Horizonte, Brazil University of Buenos Aires (UBA), Argentina University of the Republic, Montevideo, Uruguay
TLCA Steering Committee Samson Abramsky Henk Barendregt
Oxford University, UK Radboud University, Nijmegen, The Netherlands
VIII
Organization
Mariangiola Dezani Roger Hindley Martin Hofmann Simona Ronchi Della Rocca Pawel Urzyczyn
University of Turin, Italy Swansea University, UK Ludwig-Maximilians-Universit¨ at, Munich, Germany University of Turin, Italy University of Warsaw, Poland
External Reviewers Thorsten Altenkirch Roberto Amadio Philippe Audebaud David Baelde Franco Barbanera Stefano Berardi Benno van den Berg Aaron Bohannon Guillaume Bonfante Brian Campbell Pierre Clairambault Robin Cockett Claudio Sacerdoti Coen Ferruccio Damiani Daniel Dougherty Gilles Dowek Derek Dreyer Claudia Faggian Lorenzo Tortora de Falco Germain Faure Andrzej Filinski Marcelo Fiore Marco Gaboardi Nicola Gambino Maxime Gamboni Ronald Garcia Richard Garner Dan Grossman Masahiro Hamano Peter Hancock Michael Hanus Robert Harper Masahito Hasegawa Olivier Hermant Claudio Hermida
Chung-Kil Hur Pierre Hyvernat Jun Inoue Mark Jones Ulrich Kohlenbach Tomasz Kowalski Jim Laird Francois Lamarche Pierre Lescanne Paul Blain Levy William Lovas Maria Emilia Maietti Julio Mari˜ no Damiano Mazza Richard McKinley Dale Miller Virgile Mogbil Jean-Yves Moyen C´esar Mu˜ noz Karim Nour Mauro Piccolo Brigitte Pientka Andrew Pitts John Power Myriam Quatrini Femke van Raamsdonk Christophe Raffalli Jason Reed Laurent Regnier Morten Rhiger Simona Ronchi della Rocca Luca Roversi Arnab Roy Didier R´emy
Organization
Andrea Schalk Carsten Sch¨ urmann Jean-Pierre Talpin Kazushige Terui Hayo Thielecke Franklyn Turbak Nikos Tzevelekos
Tarmo Uustalu Vasco T. Vasconcelos Lionel Vaux Luca Vercelli Edwin Westbrook Yoriyuki Yamagata Noam Zeilberger
IX
Table of Contents
Mathematical Synthesis of Equational Deduction Systems (invited talk) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Marcelo Fiore and Chung-Kil Hur A Pronominal Approach to Binding and Computation (invited talk) . . . . Robert Harper, Daniel R. Licata, and Noam Zeilberger
1 3
A Modular Type-Checking Algorithm for Type Theory with Singleton Types and Proof Irrelevance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Andreas Abel, Thierry Coquand, and Miguel Pagano
5
Interactive Learning-Based Realizability Interpretation for Heyting Arithmetic with EM1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Federico Aschieri and Stefano Berardi
20
Syntax for Free: Representing Syntax with Binding Using Parametricity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Robert Atkey
35
On the Meaning of Logical Completeness . . . . . . . . . . . . . . . . . . . . . . . . . . . Michele Basaldella and Kazushige Terui
50
Thick Subtrees, Games and Experiments . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pierre Boudes
65
Bounded Linear Logic, Revisited . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ugo Dal Lago and Martin Hofmann
80
Partial Orders, Event Structures and Linear Strategies . . . . . . . . . . . . . . . . Claudia Faggian and Mauro Piccolo
95
Existential Type Systems with No Types in Terms . . . . . . . . . . . . . . . . . . . Ken-etsu Fujita and Aleksy Schubert
112
Initial Algebra Semantics for Cyclic Sharing Structures . . . . . . . . . . . . . . . Makoto Hamana
127
An Operational Account of Call-by-Value Minimal and Classical λ-Calculus in “Natural Deduction” Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . Hugo Herbelin and St´ephane Zimmermann Refinement Types as Proof Irrelevance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . William Lovas and Frank Pfenning
142
157
XII
Table of Contents
Weak ω-Categories from Intensional Type Theory . . . . . . . . . . . . . . . . . . . . Peter LeFanu Lumsdaine
172
Relating Classical Realizability and Negative Translation for Existential Witness Extraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Alexandre Miquel
188
Session-Based Communication Optimisation for Higher-Order Mobile Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Dimitris Mostrous and Nobuko Yoshida
203
The Cut-Elimination Theorem for Differential Nets with Promotion . . . . Michele Pagani A Polymorphic Type System for the Lambda-Calculus with Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Barbara Petit
219
234
Kripke Semantics for Martin-L¨ of’s Extensional Type Theory . . . . . . . . . . Steve Awodey and Florian Rabe
249
On the Values of Reducibility Candidates . . . . . . . . . . . . . . . . . . . . . . . . . . . Colin Riba
264
Lexicographic Path Induction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Jeffrey Sarnat and Carsten Sch¨ urmann
279
Parametricity for Haskell with Imprecise Error Semantics . . . . . . . . . . . . . Florian Stenger and Janis Voigtl¨ ander
294
Some Observations on the Proof Theory of Second Order Propositional Multiplicative Linear Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Lutz Straßburger
309
Algebraic Totality, towards Completeness . . . . . . . . . . . . . . . . . . . . . . . . . . . Christine Tasson
325
A Logical Foundation for Environment Classifiers . . . . . . . . . . . . . . . . . . . . Takeshi Tsukada and Atsushi Igarashi
341
Inhabitation of Low-Rank Intersection Types . . . . . . . . . . . . . . . . . . . . . . . . Pawel Urzyczyn
356
Differential Linear Logic and Polarization . . . . . . . . . . . . . . . . . . . . . . . . . . . Lionel Vaux
371
Complexity of G¨ odel’s T in λ-Formulation . . . . . . . . . . . . . . . . . . . . . . . . . . Gunnar Wilken and Andreas Weiermann
386
Table of Contents
XIII
The Computational SLR: A Logic for Reasoning about Computational Indistinguishability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Yu Zhang
401
Author Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
417
Mathematical Synthesis of Equational Deduction Systems Marcelo Fiore and Chung-Kil Hur Computer Laboratory, University of Cambridge {Marcelo.Fiore,Chung-Kil.Hur}@cl.cam.ac.uk
Our view of computation is still evolving. The concrete theories for specific computational phenomena that are emerging encompass three aspects: specification and programming languages for describing computations, mathematical structures for modelling computations, and logics for reasoning about properties of computations. To make sense of this complexity, and also to compare and/or relate different concrete theories, meta-theories have been built. These metatheories are used for the study, formalisation, specification, prototyping, and testing of concrete theories. Our main concern here is the investigation of meta-theories to provide systems that better support the formalisation of concrete theories. Thereby we propose a research programme based on the development of mathematical models of computational languages, and the systematic use of these models to synthesise formal deduction systems for reasoning and computation. Specifically, we put forth a mathematical methodology for the synthesis of equational and rewriting logics from algebraic meta-theories. The synthesised logics are guaranteed to be sound with respect to a canonical model theory, and we provide a framework for analysing completeness that typically leads to canonical logics. Our methodology can be used to rationally reconstruct the traditional equational logic of universal algebra and its multi-sorted version from first principles. As for modern applications, we have synthesised: (1) a nominal equational logic for specifying and reasoning about languages with name-binding operators, and (2) a second-order equational logic for specifying and reasoning about simple type theories. Overall, we aim at incorporating into the research programme further key features of modern languages, as e.g. type dependency, linearity, sharing, and graphical structure.
References 1. Fiore, M., Hur, C.-K.: On the construction of free algebras for equational systems. In: Special issue for Automata, Languages and Programming (ICALP 2007). Theoretical Computer Science, vol. 410, pp. 1704–1729. Elsevier, Amsterdam (2009) 2. Fiore, M., Hur, C.-K.: Term equational systems and logics. In: Proceedings of the 24th Conference on the Mathematical Foundations of Programming Semantics (MFPS XXIV). Electronic Notes in Theoretical Computer Science, vol. 218, pp. 171–192. Elsevier, Amsterdam (2008) P.-L. Curien (Ed.): TLCA 2009, LNCS 5608, pp. 1–2, 2009.
2
M. Fiore and C.-K. Hur
3. Fiore, M.: Algebraic theories and equational logics. In: Invited tutorial at the 24th Conference on the Mathematical Foundations of Programming Semantics, MFPS XXIV (2008), http://www.cl.cam.ac.uk/~ mpf23/ 4. Fiore, M.: Second-order and dependently-sorted abstract syntax. In: 23rd Annual IEEE Symposium on Logic in Computer Science (LICS 2008), pp. 57–68. IEEE Computer Society Press, Los Alamitos (2008) 5. Hur, C.-K.: Categorical Equational Systems: Algebraic Models and Equational Reasoning. Forthcoming PhD thesis. Computer Laboratory, University of Cambridge (2009)
A Pronominal Approach to Binding and Computation Robert Harper, Daniel R. Licata, and Noam Zeilberger Carnegie Mellon University {rwh,drl,noam}@cs.cmu.edu
There has been a great deal of research on programming languages for computing with binding and scope (bound variables, α-equivalence, capture-avoiding substitution). These languages are useful for a variety of tasks, such as implementing domain-specific languages and formalizing the metatheory of programming languages. Functional programming with binding and scope involves two different notions of function: functions-as-data and functions-as-computation. Functionsas-data, used to represent abstract syntax with variable binding, have an intensional, syntactic, character, in the sense that they can be inspected in ways other than function application. For example, many algorithms that process abstract syntax recur under binders, treating variables symbolically. On the other hand, functions-as-computation, the usual functions of functional programming, have an extensional character—a function from A to B is a black box that, when given an A, delivers a B. We are investigating a programming language that provides support for both functions-as-data and functions-as-computation as two different types. Our framework provides one type constructor ⇒ for functions-as-data, used to represent variable binding, and another type constructor ⊃ for functions-as-computation, used for functional programming. This permits representations that mix the two function spaces, which is useful, e.g., for implementing normalization-byevaluation. Our framework treats variable binding pronominally: variables are intrinsically-scoped references to a context. This permits types to be used to reason about the scoping of variables—e.g., that a normalization function maps closed terms to closed terms. In our mixed, pronominal setting, the structural properties of weakening and substitution hold only under some conditions on types, but we show that these conditions can be discharged automatically in many cases. The interested reader may refer to either a technical account of our type theory [1], or a more recent discussion [2] of an implementation as an embedding the dependently typed programming language Agda 2. The latter programs a number of examples, such as normalization-by-evaluation for the untyped λcalculus. One of the key technical tools used in our work is a proof-theoretic technique called higher-order focusing [3, 4], which provides a a logical analysis of pattern matching and evaluation order. Higher-order focusing leads to convenient formalizations of programming languages with pattern-matching [5], and has been used to investigate refinement types [6] and dependent types [7] in the presence of effects. P.-L. Curien (Ed.): TLCA 2009, LNCS 5608, pp. 3–4, 2009.
4
R. Harper, D.R. Licata, and N. Zeilberger
References [1] Licata, D.R., Zeilberger, N., Harper, R.: Focusing on binding and computation. In: IEEE Symposium on Logic in Computer Science (2008) [2] Licata, D.R., Harper, R.: A universe of binding and computation (March 2009), http://www.cs.cmu.edu/~ drl [3] Zeilberger, N.: On the unity of duality. Annals of Pure and Applied Logic 153(1–3) (2008); Special issue on Classical Logic and Computation [4] Zeilberger, N.: The logical basis of evaluation order and pattern matching. PhD thesis, Carnegie Mellon University (2009) [5] Zeilberger, N.: Focusing and higher-order abstract syntax. In: ACM SIGPLANSIGACT Symposium on Principles of Programming Languages, pp. 359–369 (2008) [6] Zeilberger, N.: Refinement types and computational duality. In: PLPV 2009: Proceedings of the 3rd Workshop on Programming Languages Meets Program Verification, pp. 15–26. ACM Press, New York (2009) [7] Licata, D.R., Harper, R.: Positively dependent types. In: PLPV 2009: Proceedings of the 3rd Workshop on Programming Languages Meets Program Verification, pp. 3–14. ACM, New York (2009)
A Modular Type-Checking Algorithm for Type Theory with Singleton Types and Proof Irrelevance Andreas Abel1 , Thierry Coquand2 , and Miguel Pagano3 1
Ludwig-Maximilians-Universit¨ at M¨ unchen
[email protected] 2 G¨ oteborg University
[email protected] 3 Universidad Nacional de C´ ordoba
[email protected]
Abstract. We define a logical framework with singleton types and one universe of small types. We give the semantics using a PER model; it is used for constructing a normalisation-by-evaluation algorithm. We prove completeness and soundness of the algorithm; and get as a corollary the injectivity of type constructors. Then we give the definition of a correct and complete type-checking algorithm for terms in normal form. We extend the results to proof-irrelevant propositions.
1
Introduction and Related Work
One of the raisons d’ˆetre of proof-checkers like Agda [26], Coq [18], and Epigram [23] is to decide if a given term has some type; i.e., if a term corresponds to a proof of a proposition [17]. Hence, the convenience of such a system is, in part, determined by the types for which the system can check membership. We extend the decidability of type-checking done in previous works [1,2] for Martin-L¨ of typetheories [21,25] by considering singleton types and proof-irrelevant propositions. Singleton types were introduced by Aspinall [8] in the context of specification languages. An important use of singletons is as definitions by abbreviations (see [8,14]); they were also used to model translucent sums in the formalisation of SML [19]. It is interesting to consider singleton types because beta-eta phase separation fails: one cannot do eta-expansion before beta-normalisation because the shape of the types at which to eta-expand is still unknown at this point; and one cannot postpone eta-expansion after beta-normalisation, because etaexpansion can trigger new beta-reductions. Stone and Harper [29] decide type checking in a LF with singleton types and subtyping. Yet it is not clear whether their method extends to computation on the type level. As far as we know, our work is the first where singleton types are considered together with a universe. De Bruijn proposed the concept of irrelevance of proofs [11], for reducing the burden in the formalisation of mathematics. As shown by Werner [30], the use of proof-irrelevance types together with sigma types is one way to get subset types a la PVS [27] in type-theories having the eta rule—this direction was explored ` by Sozeau [28, Sec. 3.3]. P.-L. Curien (Ed.): TLCA 2009, LNCS 5608, pp. 5–19, 2009. c Springer-Verlag Berlin Heidelberg 2009
6
A. Abel, T. Coquand, and M. Pagano
Checking dependent types relies on checking types for equality. To this end, we compute η-long normal forms using normalisation by evaluation (NbE) [22]. Syntactic expressions are evaluated into a semantic domain and then reified back to expressions in normal form. To handle functional and open expressions, the semantic domain has to be equipped with variables; a major challenge in rigorous treatments of NbE has been the problem to generate fresh identifiers. Solutions include term families [10], liftable de Bruijn terms [7], or Kripke semantics [4]. In this work we present a novel formulation of NbE which avoids the problem completely: reification is split into an η-expansion phase (↓) in the semantics, followed by a read back function (R) into the syntax which is indexed by the number of already used variables. This way, a standard PER model is sufficient, and technical difficulties are avoided. Outline. The definitions of two calculi are presented in section 2. In section 3 we define the semantics of this LF in a PER model, and we show soundness of the model wrt. the derived rules of the calculus. We use this model to introduce a NbE algorithm, for which we prove completeness (if t = s is derivable, then nbe(t) and nbe(s) are identical). In section 4 we prove, using logical relations, the soundness of the algorithm (i.e., t = nbe(t) is derivable). In section 5 we define a bi-directional algorithm for checking the type of normal forms and inferring the type of neutral terms.
2
The Calculus as a Generalised Algebraic Theory
In the section, we introduce the calculus. For ease of reading, and for showing the modularity of our approach, we present it as two calculi: the first one has dependent function spaces, singleton types, and a universe closed under function spaces and singletons. In the second calculus we leave out singleton types and we add proof-irrelevant types. We present the calculi using the formalism proposed by Cartmell for generalised algebraic theories (GAT) [12]; however, our calculi are not proper GATs (the rules are written in the so-called “informal syntax” and the rule for application is ambiguous). We give only the introductory rules and the axioms; the rules stating that equality is a congruence relation, called derived rules, are omitted. An example of a derived rule is A = B ∈ Type(Γ ) γ=δ∈Δ→Γ . A γ = B δ ∈ Type(Δ) Calculus with singleton types Sorts. The set of sort symbols is {Ctx, →, Type, Term}. Γ, Δ ∈ Ctx (ctx-sort) (subs-sort) Ctx is a type Γ → Δ is a type Γ ∈ Ctx Γ ∈ Ctx A ∈ Type(Γ ) (type-sort) (term-sort) Type(Γ ) is a type Term(Γ, A) is a type
A Modular Type-Checking Algorithm for Type Theory with Singleton Types
7
In the following, whenever a rule has a hypothesis A ∈ Type(Γ ), then Γ ∈ Ctx shall be a further, implicit hypothesis. Similarly, σ ∈ Γ → Δ presupposes Γ ∈ Ctx and Δ ∈ Ctx, and t ∈ Term(Γ, A) presupposes A ∈ Type(Γ ), which in turn presupposes Γ ∈ Ctx. Note that judgements of the form Γ ∈ Ctx, A ∈ Type(Γ ), t ∈ Term(Γ, A), and σ ∈ Γ → Δ correspond to the more conventional forms Γ , Γ A, Γ t : A, and Γ σ : Δ, resp. In the rest of the paper we use the latter. Operators. The set of operators is quite large and instead of giving it at once, we define it as the union of the disjoint sets of operators for contexts, substitutions, types, and terms. Contexts. There are two operators for contexts: SC = {, . }. Γ ∈ Ctx A ∈ Type(Γ ) (empty-ctx) (ext-ctx) ∈ Ctx Γ.A ∈ Ctx Substitutions. For substitutions we have five operators: SS = {id , , ( , ), Γ ∈ Ctx (id-subs) idΓ ∈ Γ → Γ
, p}.
Γ ∈ Ctx (empty-subs) ∈ Γ →
δ∈Γ →Θ σ∈Θ→Δ (comp-subs) σδ ∈ Γ → Δ σ∈Γ →Δ t ∈ Term(Γ, A σ) (ext-subs) (σ, t) ∈ Γ → Δ.A
A ∈ Type(Γ ) (fst-subs) p ∈ Γ.A → Γ
Types. The set of operators for types is ST = {U, Fun Γ ∈ Ctx U ∈ Type(Γ ) A ∈ Type(Γ )
(u-f)
A ∈ Term(Γ, U) A ∈ Type(Γ )
t ∈ Term(Γ, A)
{t}A ∈ Type(Γ )
(u-el)
(sing-f)
A ∈ Type(Γ )
,
, { } }. B ∈ Type(Γ.A)
Fun A B ∈ Type(Γ )
A ∈ Type(Δ)
σ∈Γ →Δ
A σ ∈ Type(Γ )
Terms. The set of operators for terms is SE = {Fun
,{ } ,
(fun-f)
(subs-type)
, q, λ , App
}.
A ∈ Term(Γ, U) B ∈ Term(Γ.A, U) t ∈ Term(Γ.A, B) (fun-u-i) (fun-i) Fun A B ∈ Term(Γ, U) λt ∈ Term(Γ, Fun A B) B ∈ Type(Γ.A)
t ∈ Term(Γ, Fun A B) u ∈ Term(Γ, A) (fun-el) App t u ∈ Term(Γ, B (idΓ , u))
σ∈Γ →Δ t ∈ Term(Δ, A) A ∈ Type(Γ ) (subs-term) (hyp) t σ ∈ Term(Γ, A σ) q ∈ Term(Γ.A, A p) A ∈ Term(Γ, U) t ∈ Term(Γ, A) t ∈ Term(Γ, A) (sing-u-i) (sing-i) {t}A ∈ Term(Γ, U) t ∈ Term(Γ, {t}A ) a ∈ Term(Γ, A) t ∈ Term(Γ, {a}A ) (sing-el) t ∈ Term(Γ, A)
8
A. Abel, T. Coquand, and M. Pagano
Axioms. We give the axioms without the premises, except in the cases where they can not be inferred. Substitutions (σ δ) γ = σ (δ γ) idΓ σ = σ id = p (σ, t) = σ
σ = σ idΓ = σ idΓ.A = (p, q) (σ, t) δ = (σ δ, t δ)
Substitutions on types, and terms; η and β-axioms. {t}A σ = {t σ}A σ q (σ, t) = t
Uγ = U (Fun A B) σ = Fun (A σ) (B (σ p, q)) t (σ δ) = (t σ) δ (λt) σ = λ(t (σ p, q)) App (λt) r = t (idΓ , r)
t idΓ = t (App r s) σ = App (r σ) (s σ) λ(App (t p) q) = t
t, t ∈ Term(Γ, {a}A ) t = t ∈ Term(Γ, {a}A ) (sing-eq-i) (sing-eq-el) t = t ∈ Term(Γ, {a}A ) t = t ∈ Term(Γ, A) Notation. We denote with |Γ | the length of the context Γ ; and Γ !i is the projection of the i-th component of Γ , for 0 i < |Γ |. We say Δ i Γ if Δ pi : Γ ; where pi is the i-fold composition of p with itself. We denote with Terms the set of words freely generated using symbols in SS ∪ ST ∪ SE . We write t ≡T t for denoting syntactically equality of t and t in T ⊆ Terms. We call A the tag of {a}A . Definition 1 (Neutral terms, and normal forms) Ne k ::= q | qpi+1 | App k v Nf v, V, W ::= U | Fun V W | {v}V | λv | k Remark 1 (Weakening of judgements) Let Δ i Γ , Γ A = A , and Γ t = t : A; then Δ A pi = A pi , and Δ t pi = t pi : A pi . Remark 2 (Syntactic validity) 1. If Γ t : A, then Γ A. 2. If Γ t = t : A, then both Γ t : A, and Γ t : A. 3. If Γ A = A , then both Γ A, and Γ A . Lemma 1 (Inversion of types) 1. If Γ Fun A B, then Γ A, and Γ.A B. 2. If Γ {a}A , then Γ A, and Γ a : A. 3. If Γ k, then Γ k : U.
A Modular Type-Checking Algorithm for Type Theory with Singleton Types
9
Lemma 2 (Inversion of typing) 1. 2. 3. 4. 5.
If If If If If Γ
Γ Fun A B : A, then Γ A : U, and also Γ.A B : U; Γ {b}B : A, then Γ B : U, and also Γ b : B; Γ λt : A, then Γ.A t : B . Γ t : {a}A , then Γ t : A, and Γ t = a : A. Γ q pi : A, then either Γ A = (Γ !i) pi+1 ; or Γ A = {a}A , and a = q pi : A .
Calculus with Proof-Irrelevance. Our treatment of proof-irrelevance is based on [9,20]. The motivation for a canonical element witnessing the existence of a proof is to keep the modularity of the algorithm for deciding equality; but since its introduction breaks completeness of type-checking, we consider two calculi: the proof (programming) developments are done in a calculus without prf-tm, and the type-checking is performed in a calculus with it. We show then that this is a conservative extension. Introductory rules A ∈ Type(Γ ) Prf A ∈ Type(Γ )
a ∈ Term(Γ, A)
(prf-f)
[a] ∈ Term(Γ, Prf A)
A ∈ Type(Γ )
(prf-i)
O ∈ Term(Γ, Prf A)
t, t ∈ Term(Γ, Prf A)
t = t ∈ Term(Γ, Prf A) B ∈ Type(Γ )
t ∈ Term(Γ, A)
b ∈ Term(Γ.A, B p)
(prf-eq)
t ∈ Term(Γ, Prf A)
B
b where t ∈ Term(Γ, Prf B)
(prf-tm)
(prf-el)
Axioms (Prf A) δ = Prf (A δ)
[t] δ = [t δ]
(b whereB t) δ = b (δ p, q) whereB δ (t δ)
Oδ = O b whereB [t] = [b (id, t)]
Lemma 3 (Inversion) 1. If Γ [t] : A, then Γ A = Prf A and Γ t : A . 2. If Γ b whereB t : A, then Γ A = Prf B, and Γ t : Prf A , and Γ.A b : B p. As is expected we have now more normal forms, and more neutral terms: Ne k ::= . . . | v whereV k Nf v, V ::= . . . | Prf V | [v] | O Now we prove that the calculus with prf-tm is a conservative extension of the one without it. We decorate the turnstile, and the equality symbol with ∗ for referring to judgements in the extended calculus.
10
A. Abel, T. Coquand, and M. Pagano
Definition 2. A term t is called a lifting of a term t, if all the occurrences of O in t have been replaced by terms s0 , . . . , sn−1 , and O does not occur in any si . We extend this definition to substitutions, contexts, and equality judgements. If Γ is a lifting of Γ , and Γ =∗ Γ , and also Γ then we say that Γ is a good-lifting of Γ . We extend the definition of good-lifting to the others kinds of judgement. Lemma 4. Let Γ ∗ J, then there exists a good-lifting Γ J ; moreover for any other good-lifting Γ J of Γ ∗ J, we have Γ = Γ , and Γ J = J . Corollary 1. The calculus ∗ is a conservative extension of .
3
Semantics
In this section we define a PER model of the calculus presented in the previous section. The model is used to define a normalisation function later. 3.1
PER Semantics
Definition 3. We define a domain D = O ⊕ Var ⊥ ⊕ [D → D] ⊕ D × D ⊕ D × D ⊕ O ⊕ D × [D → D] ⊕ D × D, where Var is a denumerable set of variables (as usual we write xi and assume xi = xj if i = j, for i, j ∈ N), E⊥ = E ∪ {⊥} is lifting, O = {}⊥ is the Sierpinski space, [D → D] is the set of continuous functions from D to D, ⊕ is the coalesced sum, and D × D is the Cartesian product of D [6]. An element of D which is not ⊥ can be of one of the forms: (d, d ) U
Var xi Lam f
for d, d ∈ D for xi ∈ Var for d ∈ D, and f ∈ [D → D]
Fun d f
App d d
Sing d d
for d, d ∈ D .
We define application · : [D × D → D] and the projections p, q : [D → D] by f · d = if f = Lam f then f d else ⊥, p d = if d = (d1 , d2 ) then d1 else ⊥, q d = if d = (d1 , d2 ) then d2 else ⊥. We define a partial function R : N → D → Terms which reifies elements from the model into terms; this function is similar to the read-back function of Gregoire and Leroy’s [16]. Definition 4 (Read-back function) Rj U = U Rj (Fun X F ) = Fun (Rj X) (Rj+1 (F (Var xj ))) Rj (Sing d X) = {Rj d}Rj X
Rj (App d d ) = App (Rj d) (Rj d ) Rj (Lam f ) = λ(Rj+1 (f (Var xj ))) q if j i Rj (Var xi ) = j−i−1 qp if j > i
A Modular Type-Checking Algorithm for Type Theory with Singleton Types
11
Partial Equivalence Relations. A partial equivalence relation (PER) over a set D is a binary relation over D which is symmetric and transitive. If R is a PER over D, and (d, d ) ∈ R then it is clear that (d, d) ∈ R. We define dom(R) = {d ∈ D | (d, d) ∈ R} . If (d, d ) ∈ R, sometimes we will write d = d ∈ R, and d ∈ R if d ∈ dom(R). We denote with PER(D) the set of all PERs over D. If R ∈ PER(D) and F : dom(R) → PER(D), we say that F is a family of PERs indexed by R iff for all d = d ∈ R, F d = F d . If F is a family indexed by R, we write F : R → PER(D). We define two binary relations over D: one for neutral terms and the other for normal forms. d = d ∈ Ne : ⇐⇒ ∀i ∈ N. Ri d and Ri d are defined and Ri d ≡Ne Ri d d = d ∈ Nf : ⇐⇒ ∀i ∈ N. Ri d and Ri d are defined and Ri d ≡Nf Ri d The following definitions are standard [8,14] (except for 1); they will be used in the definition of the model. Definition 5. Let X ∈ PER(D) and F ∈ X → PER(D). – – – –
1 = {(, )}; X F = {(d, d ) | p d = p d ∈ X and q d = q d ∈ F (p d)}; X F = {(f, f ) | f · d = f · d ∈ F d, for all d = d ∈ X }; {{d}}X = {(e, e ) | d = e ∈ X and d = e ∈ X }.
We define U, T ∈ PER(D) and [ ] : dom(T ) → PER(D) using Dybjer’s schema of inductive-recursive definition [15]. We show then that [ ] is a family of PERs over D. Definition 6 (PER model) – Inductive definition of U ∈ PER(D). • Ne ⊆ U, • if X = X ∈ U and d = d ∈ [X], then Sing d X = Sing d X ∈ U, • if X = X ∈ U and for all d = d ∈ [X], F d = F d ∈ U then Fun X F = Fun X F ∈ U. – Inductive definition of T ∈ PER(D). • U ⊂T, • U=U∈T, • if X = X ∈ T , and d = d ∈ [X] then Sing d X = Sing d X ∈ T , • if X = X ∈ T , and for all d = d ∈ [X], F d = F d ∈ T , then Fun X F = Fun X F ∈ T . – Recursive definition of [ ] ∈ dom(T ) → PER(D). • [U] = U, • [Sing d X] = { {d}}[X], • [Fun X F ] = [X] (d → [F d]), • [d] = Ne, in all other cases. Lemma 5. The function [ ] is a family of PER(D) over T .
12
A. Abel, T. Coquand, and M. Pagano
3.2
Normalisation and η-Expansion in the Model
The usual way to define NbE [7] is to introduce a reification function which maps elements from the model into normal forms; and a function mapping neutral terms to elements of the model (the former function is called the inverse of the evaluation function, and the later “make self evaluating” in [10]). A tricky point of the algorithm is to find a new variable when reifying functions as abstractions. In this work we do not need to worry about variable capturing when reifying, because we can define functions corresponding to reification, and lifting of neutrals in the model avoiding completely the need to deal with fresh variables. Definition 7. The partial functions ↑ , ↓ given as follows:
: D → D → D and ⇓ : D → D are
↑Fun X F d = Lam (e → ↑F e App d ↓X e) ↓Fun X F d = Lam (e → ↓F ↑Sing d X e = d
↑X e
(d · ↑X e))
↓Sing d X e = ↓X d
↑U d = d
↓U d = ⇓ d
↑d e = e
↓d e = e, in all other cases.
⇓(Fun X F ) = Fun (⇓ X) (d → ⇓(F ↑X d))
⇓U = U
⇓(Sing d X) = Sing (↓X d) (⇓ X)
⇓ d = d, in all other cases.
Lemma 6 (Characterisation of ↑, ↓, and ⇓). Let X = X ∈ T , then 1. if k = k ∈ Ne then ↑X k = ↑X k ∈ [X]; 2. if d = d ∈ [X], then ↓X d = ↓X d ∈ Nf ; 3. and also ⇓ X = ⇓ X ∈ Nf . Definition 8 (Semantics) Contexts. [[]] = 1
[[Γ.A]] =
[[Γ ]] (d → [[[A]]d])
Substitutions. [[]]d = [[(γ, t)]]d = ([[γ]]d, [[t]]d) [[γ δ]]d = [[γ]]([[δ]]d)
[[id]]d = d [[p]]d = p d
Terms (and types). [[U]]d = U [[{a}A ]]d = Sing ([[a]]d) ([[A]]d) [[λt]]d = Lam (d → [[t]](d, d )) [[q]]d = q d
[[Fun A B]]d = Fun ([[A]]d) (e → [[B]](d, e)) [[App t u]]d = [[t]]d · [[u]]d [[t γ]]d = [[t]]([[γ]]d)
A Modular Type-Checking Algorithm for Type Theory with Singleton Types
13
Definition 9 (Validity) 1. 2. 3. 4. 5. 6. 7. 8.
iff true Γ.A iff Γ A Γ A iff Γ A = A Γ A = A iff Γ and for all d = d ∈ [[Γ ]], [[A]]d = [[A ]]d ∈ T Γ t : A iff Γ t = t : A Γ t = t : A iff Γ A and for all d = d ∈ [[Γ ]], [[t]]d = [[t ]]d ∈ [[[A]]d] Γ σ : Δ iff Γ σ = σ : Δ Γ σ = σ : Δ iff Γ , Δ , and for all d = d ∈ [[Γ ]], [[σ]]d = [[σ ]]d ∈ [[Δ]].
Theorem 1 (Soundness of the Judgements). if Γ J, then Γ J. Proof. By induction on Γ J. Theorem 2 (Completeness of NbE). If t = t : A, then ↓[[A]] [[t]] = ↓[[A]] [[t ]] ∈ Nf . Proof. By Thm. 1 we have [[t]] = [[t ]] ∈ [[[A]]] and we conclude by Lem. 6. Calculus with Proof-Irrelevance. We extend all the definition concerning the construction of the model; D = ...⊕ D ⊕ O ; the new inhabitants will be written as Prf(d), and , respectively. The read-back function is extended by the equations Rj (Prf(d)) = Prf (Rj d) and Rj = O. We add a new clause in the definition of T , if X = X ∈ T , then Prf(X) = Prf(X ) ∈ T , and [Prf(X)] = {(, )} . The definitions of normalisation and expansion are extended for Prf(X), ↑Prf(X) d =
↓Prf(X) d =
⇓ Prf(X) = Prf(⇓ X) .
The semantic equations for the new constructions are [[Prf A]]d = Prf([[A]]d) B
[[b where t]]d =
[[[a]]]d = [[O]]d = .
Remark 3. All of lemmata 5, 6, and theorems 1, and 2 are valid for the calculus with proof-irrelevance.
4
Logical Relations
In order to prove soundness of our normalisation algorithm we define logical relations [24] between types and elements in the domain of T , and between terms and elements in the domain of the PER corresponding to elements of T .
14
A. Abel, T. Coquand, and M. Pagano
Definition 10 (Logical relations). The relations Γ A ∼ X ∈ T (ternary) and Γ t : A ∼ d ∈ [X] are defined simultaneously by induction on X ∈ T . – Neutral types: X ∈ Ne. • Γ A ∼ X ∈ T iff for all Δ i Γ , Δ A pi = R|Δ| ⇓ X. • Γ t : A ∼ d ∈ [X] iff Γ A ∼ X ∈ T , and for all Δ i Γ , Δ t pi = R|Δ| ↓X d : A pi . – Universe X = U. • Γ A ∼ U ∈ T iff Γ A = U. • Γ t : A ∼ X ∈ [U] iff Γ A = U, and Γ t ∼ X ∈ T . – Singletons. • Γ A ∼ Sing d X ∈ T iff Γ A = {a}A for some A , a, and Γ a : A ∼ d ∈ [X]. • Γ t : A ∼ d ∈ [Sing d X] iff Γ A = {a}A for some A , a, such that Γ t : A ∼ d ∈ [X], and Γ A ∼ X ∈ T . – Function spaces. • Γ A ∼ Fun X F ∈ T iff Γ A = Fun A B, and Γ A ∼ X ∈ T , and Δ B (pi , s) ∼ F d ∈ T for all Δ i Γ and Δ s : A pi ∼ d ∈ [X]. • Γ t : A ∼ f ∈ [Fun X F ] iff Γ A = Fun A B, Γ A ∼ X, and Δ App (t pi ) s : B (pi , s) ∼ f · d ∈ [F d] for all Δ i Γ and Δ s : A pi ∼ d ∈ [X]. The following lemmata show that the logical relations are preserved by judgemental equality, weakening of the judgement, and the equalities on the corresponding PERs. Lemma 7. Let Γ A = A , Γ t = t : A, Γ A ∼ X ∈ T , and Γ t : A ∼ d ∈ [X]; then Γ A ∼ X ∈ T , and Γ t : A ∼ d ∈ [X]. Lemma 8 (Monotonicity). Let Δ i Γ , then 1. if Γ A ∼ X ∈ T , then Δ A pi ∼ X ∈ T ; and 2. if Γ t : A ∼ d ∈ [X], then Δ t pi : A pi ∼ d ∈ [X]. Lemma 9. Let Γ A ∼ X ∈ T and Γ t : A ∼ d ∈ [X], then 1. if X = X ∈ T , then Γ A ∼ X ∈ T ; and 2. if d = d ∈ [X], then Γ t : A ∼ d ∈ [X]. The following lemma plays a key role in the proof of soundness. It proves that if a term is related to some element in (some PER), then it is convertible to the reification of the corresponding element in the PER of normal forms. Lemma 10. Let Γ A ∼ X ∈ T , Γ t : A ∼ d ∈ [X], and k ∈ Ne, then 1. Γ A = R|Γ | ⇓ X, 2. Γ t = R|Γ | ↓X d : A; and 3. if for all Δ i Γ , Δ t pi = R|Δ| k : A pi , then Γ t : A ∼ ↑X k ∈ [X].
A Modular Type-Checking Algorithm for Type Theory with Singleton Types
15
In order to finish the proof of soundness we have to prove that each well-typed term (and each well-formed type) is logically related to its denotation; with that aim we extend the definition of logical relations to substitutions and prove the fundamental theorem of logical relations. Definition 11 (Logical relation for substitutions) – Γ σ : ∼ d ∈ 1. – Γ (σ, t) : Δ.A ∼ (d, d ) ∈ X (d → [F d]) iff Γ σ : Δ ∼ d ∈ X , Γ A σ ∼ F d ∈ T , and Γ t : A σ ∼ d ∈ [F d]. After proving the counterparts of 7, 8 and 9 for substitutions, we can proceed with the proof of the main theorem of logical relations. Theorem 3 (Fundamental theorem of logical relations). Let Δ δ : Γ ∼ d ∈ [[Γ ]]. 1. If Γ A, then Δ A δ ∼ [[A]]d ∈ T ; 2. if Γ t : A, then Δ t δ : A δ ∼ [[t]]d ∈ [[[A]]d]; and 3. if Γ γ : Θ then Δ γ δ : Θ ∼ [[γ]]d ∈ [[Θ]]. We define for each context Γ an element ρΓ of D, that is, by construction, logically related to idΓ . This environment will be used to define the normalisation function; also notice that if we instantiate Thm. 3 with ρΓ , then a well-typed term under Γ will be logically related to its denotation. Definition 12. Let ρΓ = PΓ , where P d = d and PΓ.A d = (d , ↑[[A]]d Var x|Γ | ) with d = PΓ d. Then Γ idΓ : Γ ∼ ρΓ ∈ [[Γ ]] for Γ ∈ Ctx. Definition 13 (Normalisation algorithm). Let Γ A, and Γ t : A. nbeΓ (A) = R|Γ | ⇓[[A]]ρΓ nbeA Γ (t) = R|Γ | ↓[[A]]ρΓ [[t]]ρΓ The first point of soundness is a direct consequence of Thm. 3 and Lem. 7; and the second point is obtained using Lem. 10. Corollary 2 (Soundness of NbE). Let Γ A, and Γ t : A, then 1. Γ A ∼ [[A]]ρΓ ∈ T , and Γ t : A ∼ [[t]]ρΓ ∈ [[[A]]ρΓ ]; and 2. Γ A = nbe(A), and Γ t = nbe(t) : A. Remark 4. By expanding the definitions, we easily check 1. nbeΓ (Fun A B) = Fun (nbeΓ (A)) (nbeΓ.A (B)), and 2. nbeΓ ({a}A ) = {nbeA Γ (a)}nbeΓ (A) . Corollary 3. If Γ A, and Γ A , then we can decide Γ A = A . Also if Γ t : A, and Γ t : A, we can decide Γ t = t : A. Corollary 4 (Injectivity of Fun and of { } ). If Γ Fun A B = Fun A B , then Γ A = A , and Γ.A B = B . Also Γ {t}A = {t }A , then Γ A = A , and Γ t = t : A.
16
A. Abel, T. Coquand, and M. Pagano
Calculus with Proof-Irrelevance. We add the corresponding cases in the definition of logical relations, Γ A ∼ Prf(X) ∈ T , iff Γ A = Prf A , and Γ A ∼ X ∈ T ; and Γ t : A ∼ d ∈ [Prf(X)], iff Γ A ∼ Prf(X) ∈ T . Remark 5. All the lemmata 7, 8, 9, 10, theorem 3, and remarks 2, 4 are still valid. Moreover we also have nbe(Prf A) = Prf (nbe(A)).
5
Type-Checking Algorithm
In this section we define a bi-directional type-checking algorithm for terms in normal form, and a type-inference algorithm for neutral terms. We prove its correctness and completeness. The algorithm is similar to previous ones [13,3]. The only difference is due to the presence of singleton types. We deal with this by η-normalising the type, and considering first if the normalised type is a singleton (side-condition in typechecking of neutrals); in that case we check that the term is typeable with the tag of the singleton type, and that it is equal to the term of the singleton. We stress the importance of having a normalisation function with the property stated in Rem. 4, and also to have decidability of equality. In fact, it is enough to have a function nbe( ) such that: 1. nbe({a}A ) = {nbe(a)}nbe(A) , and nbe(Fun A B) = Fun nbe(A)nbe(B) ; A 2. nbeΓ (A) = nbeΓ (B) if and only if Γ A = B, and nbeA Γ (t) = nbeΓ (t ), if and only if Γ t = t : A. In this section, let V, V , W, v, v , w ∈ Nf , and k ∈ Ne. We define a function to get the deepest tag of a singleton, that is essentially the same as in [8], V =
W V
if V ≡ {w}W otherwise.
The predicates for type-checking are defined mutually inductively, together with the function for inferring types. Definition 14 (Type-checking and type-inference) Types Γ ⇐ V . We presuppose Γ .
Γ ⇐U
Γ ⇐V Γ.V ⇐ W Γ ⇐ V Γ ⇐ Fun V W
Γ v ⇐ nbe(V ) Γ k ⇐ U Γ ⇐ {v}V Γ ⇐k
A Modular Type-Checking Algorithm for Type Theory with Singleton Types
17
Terms Γ v ⇐ V . We presuppose Γ V , and V in η-long normal form with respect to Γ . Γ V ⇐U Γ.V W ⇐ U Γ Fun V W ⇐ U Γ V ⇐U Γ v ⇐ nbe(V ) Γ {v}V ⇐ U
Γ.V v ⇐ W Γ λv ⇐ Fun V W Γ v = v : V Γ v ⇐V Γ v ⇐ {v }V
Γ k ⇒V Γ V =V V ≡ {w}W Γ k⇐V Type inference Γ k ⇒ V . We presuppose Γ .
Γ.Ai . . . . A0 q p ⇒ nbe(Ai p i
i+1
Γ v ⇐V Γ k⇒V Γ V = Fun V W ) Γ App k v ⇒ nbe(W (id, v))
Theorem 4 (Correctness of type-checking) 1. If Γ ⇐ V , then Γ V . 2. If Γ v ⇐ V , then Γ v : V . 3. If Γ k ⇒ V , then Γ k : V . Proof By simultaneous induction on the type-checking judgement. In order to prove completeness we define a lexicographic order on pairs of terms and types, in this way we can make induction over the term, and the type. Definition 15. Let v, v ∈ Nf , and A, A ∈ Type(Γ ), then (v, A) ≺ (v , A ) is the lexicographic order on Nf × Type(Γ ). The corresponding orders are v ≺ v iff v is an immediate sub-term of v ; and A ≺Γ A , iff nbe(A ) ≡ {w}nbe(A) . Theorem 5 (Completeness of type-checking) 1. If Γ V , then Γ ⇐ V . 2. If Γ v : A, then Γ v ⇐ nbe(A). 3. If Γ k : A, and Γ k ⇒ V , then Γ nbe(A) = V . Proof By simultaneous induction on V , and well-founded induction on (v, A). Calculus with Proof-Irrelevance Definition 16 (Type-checking and type-inference) Γ.V v ⇐ nbe(V p) Γ k ⇒ Prf V Γ ⇐V Γ v⇐V Γ ⇐ Prf V Γ [v] ⇐ Prf V Γ v whereV k ⇒ Prf V Remark 6. Thm. 4 is still valid for the calculus with prf-tm. Moreover, Thm. 5 is valid if we add the axiom Γ O ⇐ Prf V.
18
A. Abel, T. Coquand, and M. Pagano
Remark 7. Type checking happens always before normalisation. If the term to type-check does not contain O, the case Γ O ⇐ Prf V will never be reached— although occurrences of O may be created by normalisation. Corollary 5. The type-checking algorithm is correct (by Cor. 1) and complete (by last remark) with respect to the calculus without prf-tm.
6
Conclusion
The main contributions of the paper are the definition of a correct and complete type-checking algorithm, and the simplification of the NbE algorithm for a calculus with singletons, one universe, and proof-irrelevant types. The type-checker is based on the NbE algorithm which is used to decide equality and to prove the injectivity of the type constructors. We emphasise that the type-checking algorithm is modular with respect to the normalisation algorithm. All the results can be extended to a calculus with annotated lambda abstractions, yielding a type-checking algorithm for terms not necessarily in normal forms. The full version [5] extends this work by sigma-types and data types and an implementation of the type checker in Haskell.
References 1. Abel, A., Aehlig, K., Dybjer, P.: Normalization by evaluation for Martin-L¨ of type theory with one universe. In: Fiore, M. (ed.) Proc. of the 23rd Conf. on the Mathematical Foundations of Programming Semantics (MFPS XXIII). Electr. Notes in Theor. Comp. Sci, vol. 173, pp. 17–39. Elsevier, Amsterdam (2007) 2. Abel, A., Coquand, T., Dybjer, P.: Normalization by evaluation for Martin-L¨ of Type Theory with typed equality judgements. In: Proc. of the 22nd IEEE Symp. on Logic in Computer Science (LICS 2007), pp. 3–12. IEEE Computer Soc. Press, Los Alamitos (2007) 3. Abel, A., Coquand, T., Dybjer, P.: On the algebraic foundation of proof assistants for intuitionistic type theory. In: Garrigue, J., Hermenegildo, M.V. (eds.) FLOPS 2008. LNCS, vol. 4989, pp. 3–13. Springer, Heidelberg (2008) 4. Abel, A., Coquand, T., Dybjer, P.: Verifying a semantic βη-conversion test for Martin-L¨ of type theory. In: Audebaud, P., Paulin-Mohring, C. (eds.) MPC 2008. LNCS, vol. 5133, pp. 29–56. Springer, Heidelberg (2008) 5. Abel, A., Coquand, T., Pagano, M.: A modular type-checking algorithm for type theory with singleton types and proof irrelevance (full version) (2009), http://www.tcs.ifi.lmu.de/~ abel/singleton.pdf 6. Abramsky, S., Jung, A.: Domain Theory. In: Handbook of Logic in Computer Science, pp. 1–168. Oxford University Press, Oxford (1994) 7. Aehlig, K., Joachimski, F.: Operational aspects of untyped normalization by evaluation. Math. Struct. in Comput. Sci. 14, 587–611 (2004) 8. Aspinall, D.: Subtyping with singleton types. In: Pacholski, L., Tiuryn, J. (eds.) CSL 1994. LNCS, vol. 933, pp. 1–15. Springer, Heidelberg (1995) 9. Awodey, S., Bauer, A.: Propositions as [Types]. J. Log. Comput. 14, 447–471 (2004)
A Modular Type-Checking Algorithm for Type Theory with Singleton Types
19
10. Berger, U., Schwichtenberg, H.: An inverse to the evaluation functional for typed λ-calculus. In: Proc. of the 6th IEEE Symp. on Logic in Computer Science (LICS 1991), pp. 203–211. IEEE Computer Soc. Press, Los Alamitos (1991) 11. Bruijn, N.G.d.: Some extensions of Automath: the AUT-4 family (1994) 12. Cartmell, J.: Generalised algebraic theories and contextual categories. Annals of Pure and Applied Logic, 32–209 (1986) 13. Coquand, T.: An algorithm for type-checking dependent types. Science of Computer Programming 26, 167–177 (1996) 14. Coquand, T., Pollack, R., Takeyama, M.: A logical framework with dependently typed records. Fundam. Inform. 65, 113–134 (2005) 15. Dybjer, P.: A general formulation of simultaneous inductive-recursive definitions in type theory. The Journal of Symbolic Logic 65, 525–549 (2000) 16. Gr´egoire, B., Leroy, X.: A compiled implementation of strong reduction. In: Proc. of the 7th ACM SIGPLAN Int. Conf. on Functional Programming (ICFP 2002). SIGPLAN Notices, vol. 37, pp. 235–246. ACM Press, New York (2002) 17. Harper, R., Honsell, F., Plotkin, G.: A Framework for Defining Logics. Journal of the Association of Computing Machinery 40, 143–184 (1993) 18. INRIA: The Coq Proof Assistant, Version 8.1. INRIA (2007), http://coq.inria.fr 19. Lee, D.K., Crary, K., Harper, R.: Towards a mechanized metatheory of Standard ML. In: Hofmann, M., Felleisen, M. (eds.) Proc. of the 34th ACM Symp. on Principles of Programming Languages, POPL 2007, pp. 173–184. ACM Press, New York (2007) 20. Maillard, O.-A.: Proof-irrelevance, strong-normalisation in Type-Theory and PER. Technical report, Chalmers Institute of Technology (2006) 21. Martin-L¨ of, P.: Intuitionistic Type Theory. Bibliopolis (1984) 22. Martin-L¨ of, P.: Normalization by evaluation and by the method of computability, Talk at JAIST. Japan Advanced Institute of Science and Technology, Kanazawa (2004) 23. McBride, C.: Epigram: Practical programming with dependent types. In: Vene, V., Uustalu, T. (eds.) AFP 2004. LNCS, vol. 3622, pp. 130–170. Springer, Heidelberg (2005) 24. Mitchell, J.C., Moggi, E.: Kripke-Style models for typed lambda calculus. In: LICS, pp. 303–314 (1987) 25. Nordstr¨ om, B., Petersson, K., Smith, J.M.: Programming in Martin L¨ of’s Type Theory: An Introduction. Clarendon Press, Oxford (1990) 26. Norell, U.: Towards a practical programming language based on dependent type theory. Ph.D. thesis, Department of Computer Science and Engineering, Chalmers University of Technology, G¨ oteborg, Sweden (2007) 27. Shankar, N., Owre, S.: Principles and Pragmatics of Subtyping in PVS. In: Bert, D., Choppy, C., Mosses, P.D. (eds.) WADT 1999. LNCS, vol. 1827, pp. 37–52. Springer, Heidelberg (2000) 28. Sozeau, M.: Subset coercions in Coq. In: Altenkirch, T., McBride, C. (eds.) TYPES 2006. LNCS, vol. 4502, pp. 237–252. Springer, Heidelberg (2007) 29. Stone, C.A., Harper, R.: Extensional equivalence and singleton types. ACM Trans. Comput. Logic 7, 676–722 (2006) 30. Werner, B.: On the strength of proof-irrelevant type theories. Logical Meth. in Comput. Sci. 4 (2008)
Interactive Learning-Based Realizability Interpretation for Heyting Arithmetic with EM1 Federico Aschieri and Stefano Berardi C.S. Dept. University of Turin
Abstract. We interpret classical proofs as constructive proofs (with constructive rules for ∨, ∃) over a suitable structure N for the language of natural numbers and maps of G¨ odel’s system T . We introduce a new Realization semantics we call “Interactive learning-based Realizability”, for Heyting Arithmetic plus EM1 (Excluded middle axiom restricted to Σ10 formulas). Individuals of N evolve with time, and realizers may “interact” with them, by influencing their evolution. We build our semantics over Avigad’s fixed point result [1], but the same semantics may be defined over different constructive interpretations of classical arithmetic (in [7], continuations are used). Our notion of realizability extends Kleene’s realizability and differs from it only in the atomic case: we interpret atomic realizers as “learning agents”.
1
Introduction
From now on, we will call EM1 the Excluded middle axiom restricted to Σ10 formulas. In this paper we extend Berardi and de’ Liguoro ([4], [7]) notion of atomic realizability - originally conceived for quantifier free primitive recursive Arithmetic plus EM1 - to full predicate logic, namely Heyting Arithmetic with EM1 (HA + EM1 ). Our idea is to interpret classical proofs as constructive proofs on a suitable structure N for natural numbers and maps of system T . We extend in a natural way Kleene’s intuitionistic realizability in terms of a new notion, which we call “Interactive learning-based Realizability”. We provide a term assignment for the standard natural deduction system of HA+EM1 , which is surprisingly equal in all respects to that of HA, but for the fact that we have new realizers for atomic formulas and Excluded Middle. Our semantics may be used to interpret existing program extraction procedure for classical proofs, in order to solve a major problem of all computational interpretations: global illegibility, which means that, even for simple classical proofs, it is extremely difficult to understand the behavior of extracted programs and how each part of the extracted program relates to the others part of the same program. The main sources of inspiration of this paper are works of Kleene, Coquand, Hayashi, Berardi and de’ Liguoro and Avigad. Kleene’s Realizability revisited. In [15], Kleene introduced the notion of realizability, a formal semantics for intuitionistic arithmetic. Realizability is nothing but a formal version of Heyting semantics for intuitionistic logic, translated into the language of arithmetic. P.-L. Curien (Ed.): TLCA 2009, LNCS 5608, pp. 20–34, 2009. c Springer-Verlag Berlin Heidelberg 2009
Interactive Learning-Based Realizability Interpretation
21
Intuitively, realizing a closed arithmetical formula A means exhibiting a computer program - called realizer - able to calculate all relevant information about the truth of A. Hence, realizing a formula A ∨ B means realizing A or realizing B, after calculating which one of the two is actually realized; realizing a formula ∃xA(x) means computing a natural number n - called a witness - and realizing A(n). These two cases are indeed the only ones in which we have relevant information to calculate about the truth of the corresponding formula, and there is a decision to be made: realizing a formula ∀xA means exhibiting an algorithm which takes as input natural numbers n and gives as output realizers of A(n); realizing a formula A ∧ B means realizing A and realizing B; realizing A → B means providing an algorithm which takes as input realizers of A and gives realizers of B; so we see that in these cases, we provide no information about the formula we realize and we only take the inputs we will need for realizing existential or disjunctive formulas. Finally, realizing an atomic formula means that the formula is true: in this case, the realizer does nothing at all. Intuitionistic natural deduction rules are perfectly suited to preserve realizability. In order to actually build realizers from intuitionistic natural deductions, it suffices to give realizers for the axioms. Since our goal is to interpret classical connectives using Heyting and Kleene interpretation of intuitionistic connectives, then a first, quite naive idea would be the following: if we devised realizers for Excluded Middle, we would able to extend realizability to all classical arithmetic. Unfortunately, from the work of Turing is well known that not every instance of Excluded Middle is realizable. If T xyz is Kleene’s predicate, realizing ∀x∀y.∃zT xyz ∨ ∀z¬T xyz implies exhibiting an algorithm which for every n, m calculates whether or not the n-th Turing machine halts on input m: the halting problem would be decidable. Hence, there is no hope of computing with effective programs all the information about the truth of Excluded Middle. However, not all is lost. A first key observation we can make is the following. Suppose we had a realizer O of the Excluded Middle and we made a natural deduction of a formula ∃xA actually using Excluded Middle; then, we would be able to extract from the proof a program u, containing O as subprogram, able to compute the witness for ∃xA. Given the effectiveness of u, after a finite number of steps - and more importantly, after a finite number of calls to O - u would yield the required witness. It is thus clear that u, to perform the calculation, would use only a finite piece of information about the Excluded Middle. This fundamental fact gives us an hope: maybe there is not always necessity of fully realizing Excluded Middle, since in finite computations only a finite amount of information is used. If we were able to gain that information during the computation, we could adapt Kleene’s realizability to Classical Logic. Coquand’s Game Semantics for Classical Arithmetic. As we have seen, computing all relevant information about the truth of a given formula A is not always possible. In [8] and in the context of game semantics, Coquand introduced a new key idea to round on this problem: backtracking and learning. If we cannot
22
F. Aschieri and S. Berardi
compute all the right information about the truth of a formula, maybe we could do this if we were allowed to make mistakes and to learn from them. Suppose, for instance, we have the formula ∀x.∃yP xy ∨ ∀y¬P xy, but no algorithm which, for all n ∈ N given as input, outputs false if ∀y¬P ny holds and outputs true if ∃yP ny holds. Then we may describe a learning algorithm r as follows. Initially, for all n ∈ N given as input, r outputs false. Intuitively, r is initially persuaded - following the principle “if I don’t see, I do not believe” that for all n there is not an m such that P nm holds. Hence, when asked for his opinion about the formula ∃yP ny ∨ ∀y¬P ny, r always says: ∃yP ny is false. However, if someone - an opponent of r - to show that r is wrong, comes out with an m such that P nm holds, r realizes indeed to be mistaken, and stores the information “P nm is true”. Then, the next time being asked for an opinion about ∃yP ny ∨ ∀y¬P ny, r will say: true. In other words, such r, after a maximum of one “mind changing”, would be able to learn the correct answer to any question of the form: “which one among ∃yP ny, ∀y¬P ny does hold?”. This is actually learning by counterexamples and is the key idea behind Coquand’s semantics. Our question is now: can we formulate a realizability notion based on learning by counterexamples in order to extend Kleene’s interpretation to the subclassical Arithmetic HA + EM1 ? In our solution we modify the notion of individual, in such a way that individuals change with time, and realizers “interact” with them. Hayashi’s Proof Animation and Realizability. In [14], Hayashi explains a notion of realizability for a subclassical arithmetic, called limit computable mathematics. Basing his analysis on ideas of Gold, he defines a Kleene’s style notion of realizability equal to the original one but for the fact that the notion of individual changes: the witnesses of existential and disjunctive formulas are calculated by a stream of guesses and “learned in the limit” (in the sense that the limit of the stream is a correct witness). An individual a is therefore a computable map a : N → N, with a(t) representing the value of the individual at time t. The technical device that makes his interpretation working is the class of limiting recursive functions introduced in Gold [11]. For instance, how would Hayashi realize the formula ∀x.∃yP xy ∨ ∀y¬P xy? He would define an algorithm H as follows. Given an n ∈ N, H would calculate the truth value of ∀y ≤ nP ny. Then the correct answer to the question: “which one among ∃yP ny, ∀y¬P ny does hold?” is learned in the limit by computing P (n, 0), P (n, 1), P (n, 2),. . . , P (n, k),. . . and thus producing a stream of guesses either of the form false, false, false,. . . , true, true,. . . , true,. . . or of the form false, false, false, . . . , false, . . . , the first stabilizing in the limit to true, the second to false. Hayashi’s idea is to perform a completely blind and exhaustive search: in such a way, the correct answer is guaranteed to be eventually learned. Hayashi’s realizer do not learn in an efficient way: in Hayashi’s notion of realizability the only learning device is to look through all possible cases. Instead, we want a notion of learning in which we the stream of guesses is driven by the proof itself, as in Coquand’s game semantics.
Interactive Learning-Based Realizability Interpretation
23
Realizability Based on Learning: extending Berardi-de’ Liguoro interpretation. As long as one investigates learning and the process of correcting hypotheses by means of counterexamples, it is natural to use Popper’s ideas [16] as a metaphor. According to Popper, a scientific theory relies on a set of unproved - and unprovable - hypotheses and, through logic, makes predictions suitable to be falsified by experiments. If a prediction is falsified, some hypothesis is incorrect. In front of a counterexample to a theory’s prediction, one must modify the set of hypotheses and build a better theory, which will be tested by experiments, and so on. Laws of Nature are universal statements, that cannot be verified, but are suitable to falsification. Now we may explain the link between falsifiable hypothesis and EM1 . For every n, given an instance ∃y.P ny ∨ ∀y.¬P ny of EM1 (with P atomic), we may formulate an hypothesis about which side of the disjunction is true. If we know that P nm is true for some m, we know that ∃y.P ny is true. Otherwise we may assume ∀y.¬P ny as hypothesis, because it is a falsifiable hypothesis. In order to formalize the process of making hypotheses about EM1 , we introduce a finite base of knowledge, called s, collecting the instances P nm which we know to hold, e.g. by direct calculation. If we have evidence that P nm holds for some m (that is, P nm ∈ s) we know that ∃yP ny is true; in the other case, we assume that ∀y¬P ny is true. So s defines a set of hypotheses on EM1 , of the form ∀y¬P ny: universal falsifiable statements. Using s we can effectively decide which side of a given instance of EM1 is true, albeit at the price of making mistakes: it suffices to define a program which, to decide if ∀y¬P ny is true, looks for any P nm in the finite base s and outputs false if the research is successful, true otherwise. Hence, if s contains enough information, we can provide an effective realizer for every instance of EM1 , as we wished to show. But, as we have said, working with Kleene’s realizability and having realizers for the Excluded Middle implies being able to extract realizers from classical proofs! Now we can take the final step. A Kleene’s style realizer r associated to a classical proof p interprets each step of p deriving some formula as a “prediction” of the truth of this formula, based on the information in s. For example, in front of a formula ∃x.A ∧ B, a realizer r will predict that A(n) ∧ B(n) is true for some n ∈ N (and since n depends on s, it is like we had changed the notion of individual, interpreting “numbers” as computable maps from the set of bases of knowledge to N). Then r will predict B(n) to be true, and so on, until r will arrive at some atomic formula, say ¬P nm, and will predict it to be true. If notwithstanding that prediction - ¬P nm is false, our set of hypotheses is not correct and we have a counterexample. Our reaction is compelled: we enlarge our base of knowledge s by including the information“P nm is true”, thus modifying our set of hypotheses. Our Interactive Realizability differs from Kleene’s realizability in the notion of individual, as we said, and in the realizability relation for the atomic case. In our interpretation, to realize an atomic formula does not mean that the formula is true, but that the realizer extends our base of knowledge s if the formula is not true. The realizer is thought as a learning device. Each extension of s may change the individuals which are parameters of the atomic formula, and therefore may
24
F. Aschieri and S. Berardi
make the atomic formula false again. Then the realizer extends s again, and so forth. The convergence of this “interaction” between a realizer and a group of individuals follows by Avigad’s fixed point thm. [1]. The idea of using finite bases of knowledge and to use them to “decide” Excluded Middle comes from Berardi and de’ Liguoro [4], [7]. In [7] there are only realizers for atomic formulas, which have the task of extending the current knowledge and hence are not trivial: they embody learning strategies. Why the Arithmetic HA + EM1 ? It is now time to explain why we chose to restrict our realizability interpretation to the subclassical Arithmetic HA + EM1 , instead of considering, say, full Peano Arithmetic. There are two main reasons. First, we observe that EM1 enjoys a very good property: the information about its truth can be computed in the limit, in the sense of Gold [11], as we saw en passant when discussing Hayashi’s realizability. This implies that witnesses for existential and disjunctive statements too can be learned in the limit, as shown in Hayashi [14]. Hence HA + EM1 is a very interesting and simple framework to work within. Furthermore, the realizers which we will be able to extract from proofs, will have a straightforward interpretation as winning strategies in 1-Backtracking games [6], which are the most natural and simple instances of Coquand’s style games. This conceptual simplicity helps to understand our semantics, which is completely new and quite subtle, and keeps low the technical complexity. Secondly, if we look at actual mathematical practice, we note that a great deal of mathematical theorems are proved by using EM1 alone ([2], [5]). Plan of the Paper. The paper is organized as follows. In §2 we define the term calculus in which our realizers will be written: a version of G¨ odel’s system T , extended with some syntactic sugar, in order to represent bases of knowledge (which we shall call states) and to manipulate them. Then we prove a convergence property for this calculus (as in Avigad [1]). In §3, we introduce the notion of realizability and prove our Main Theorem, the Adequacy Theorem: “if a closed arithmetical formula is provable in HA + EM1 , then it is realizable”. Proofs are only included in the full version of the paper [3] (downloadable). In [3] we also include some examples of program extraction, which are the motivation of this paper: they show that our theory yields legible, intuitive, effective programs from classical proofs.
2
The Term Calculus
In this section we formalize the intuition of realizer and many more ideas we discussed in the introduction. In particular, we associate to any instance ∃yP xy∨ ∀y¬P xy of EM1 (Excluded Middle restricted to Σ10 -formulas) two functions χP and ϕP . The function χP take a knowledge base s, a value n for x, and it returns a guess for the truth value of ∃y.P ny. When this guess is “true” the function ϕP returns a witness m of ∃y.P ny. The guess for the truth value of ∃y.P ny is computed w.r.t. the knowledge base s, and it may be wrong. For each value of the knowledge base s, the function χP (s, .) is some “approximation” of an
Interactive Learning-Based Realizability Interpretation
25
ideal map, the oracle returning the truth value of ∃y.P xy. The Skolem axioms effectively used by a given proof take the place of a set of experiments testing the correctness of the predictions about ϕP , χP (we do not check the correctness of ϕP , χP in an exhaustive way). Our Term Calculus is based on G¨ odel’s system T . T is simply typed λcalculus, with atomic types N (representing the set N of natural numbers) and Bool (representing the set B of booleans), product types T × U and arrows types T → U , and pairs ., . , projections π0 , π1 , conditional ifT and primitive recursion RT in all types, and the usual reduction rules for λ, ., . , ifT , RT . For more details about T we refer to Girard [10]. Definition 1. (abbreviations for G¨ odel’s system T ). 1. 2. 3. 4.
We write t1 = t2 iff t1 = t2 is a theorem of system T equational theory. If n ∈ N, with n we denote the numeral S n (0) : N. We denote with T, F : Bool the booleans of T . We denote with F V (t) the set of free variables of a term t ∈ T .
We will denote with π2 the string π1 π1 , which is useful since we will often deal with terms u of type A × (B × C). π2 u will represent the third component of u; to be consistent, we will also denote with u0 , u1 , u2 any term u0 , u1 , u2
of type A × (B × C). We formalize now the idea of “finite information about EM1 ” by the notion of state of knowledge. Definition 2. (State Of Knowledge) A state of knowledge, shortly a state, is a finite set s of triples P, n, m such that: – P : Nk+1 → Bool is a closed term of T ; – n = n1 , . . . , nk is a vector of numerals such that P nm = T ; – (consistency) if P, n, m1 ∈ s and P, n, m2 ∈ s, then m1 = m2 . We denote with S the set of all states of knowledge. We think of an atom P, n, m as the code of a witness for ∃y.P (n, y). Consistency condition allows at most one witness for each ∃y.P (n, y) in each knowledge base s. Two witnesses P, n, m , P, n, m with m = m are said inconsistent. odel’s T with T1 is the simply typed lambda calculus obtained by extending G¨ a new atomic type S denoting the elements of S, with four new term formation rules (Def. 3) and four new reduction rules (Def. 4). We will denote terms of T1 of type S by ρ, ρ , . . .. Definition 3. 1. A state s ∈ S is a constant of type S. 2. If P : Nk+1 → Bool is a closed term of T , ρ : S and t1 , . . . , tk : N, then χP ρt1 . . . tk and ϕP ρt1 . . . tk are respectively terms of type Bool and N. 3. If ρ1 , ρ2 : S, then ρ1 ρ2 is a term of type S. 4. If ρ : S, P : Nk → Bool is a closed term of T and t1 , . . . , tk : N, then (Add)ρ P, t1 , . . . , tk is a term of type S.
26
F. Aschieri and S. Berardi
We do not distinguish between a state and the constant denoting it: the set S of states is equal to the set of constants of type S. We interpret χP ρt1 . . . tk and ϕP ρt1 . . . tk respectively as a “guess” for the values of the oracle and the Skolem map for ∃y.P t1 . . . tk y, guess computed w.r.t. the knowledge base s which is the value of ρ. If ρ1 , ρ2 have value the states s1 , s2 , we will interpret ρ1 ρ2 as the union s1 ∪ s2 of the two sets of atoms s1 , s2 , minus all atoms of s2 which are inconsistent with some atom of s1 . s1 s2 is an asymmetrical operation: whenever an atom of s1 and an atom of s2 are inconsistent, we arbitrarily keep the atom of s1 and reject the atom of s2 . In a similar way, if ρ has value the state s, then (Add)ρ P, t1 , . . . , tk denotes s ∪ P, t1 , . . . , tk , minus P, t1 , . . . , tk in the case this atom is inconsistent with some atom of s. Definition 4. Let s, s1 , s2 ∈ S. Assume P : Nk+1 → Bool is a closed term of odel’s T equational T . Then the equational theory associated with T1 extends G¨ theory by the following four rules: 1. If P, n, m ∈ s, then χP sn = T and ϕP sn = m, else χP sn = F and ϕP sn = 0. / 2. s1 s2 = the constant denoting the state s1 ∪ { P, n, m ∈ s2 | P, n, m ∈ s1 for every m ∈ N}. 3. If P nm = T , then Add s P, n, m = s { P, n, m } else Add s P, n, m = s Remark. T1 is nothing but T with some “syntactic sugar”. Indeed, the type S could be translated by N by a suitable bijection between S and N. The terms odel’s T . Each reducχP , ϕP , , Add could be translated by suitable terms of G¨ tion step of T1 could be translated in one or more reduction steps of T . Therefore, we may assume that T1 enjoys the strong normalization. The Church-Rosser property for T1 follows by the fact that redexes of T1 are algebraic and orthogonal each other. We may also prove a normal form property. Any closed normal term of T1 of type N, Bool, S, A × B, A → B is equal respectively to a numeral, a boolean, a state constant, a pair or a λ-abstraction. Proof Sketch. By induction over the term. Assume the first symbol of the term is the primitive recursion symbol, the conditional, or Add, a projection, an application. By case analysis and induction hypothesis on the immediate subterms we may always show that the term is not normal. For the rest of the paper, we assume be fixed a special state variable σ denoting the current “knowledge state” of a term. We introduce now some distinguish subsets of T1 . Definition 5. Let σ : S be a fixed special variable. 1. T1− is the set of all t ∈ T1 without constants of type S. 2. T1σ is the set of all t ∈ T1− such that F V (t) ⊆ {σ}. We will call any t ∈ T1σ a term in the free state variable σ. We have T ⊂ T1σ ⊂ T1− ⊂ T1 , since σ ∈ T1σ − T , xN ∈ T1− − T1σ and s ∈ T1 − T1− . If t ∈ T1σ then t has only one free state variable, and no state constant. If t ∈ T1σ
Interactive Learning-Based Realizability Interpretation
27
we will write, in order to stress the fact, t[σ]; if s is a state, t[s] will denote t[s/σ]. We interpret any t ∈ T1σ as a learning process evaluated w.r.t. the information taken from a unique state, which is the value of the variable σ. t[s] is a closed term of T1 , and if t[σ] : S, then t[s] = s for some s ∈ S. We introduce now a notion of convergence for terms of atomic type of T1σ , expressing the fact that the integers and booleans denoted by a term of T1σ eventually stop changing when the knowledge state σ increases. We say that a sequence {si }i∈N is a weakly increasing chain of states (just w.i. for short), if si ⊆ si+1 for all i ∈ N. We will often write si ≤ si+1 for si ⊆ si+1 . Definition 6. (Convergence). Assume that {si }i∈N is a w.i. chain of states, and u, v ∈ T1σ . 1. u converges in {si }i∈N if ∃n ∈ N.∀m ≥ n.u[sm ] = u[sn ] 2. we say that u converges to v in {si }i∈N and we write “for n → ∞ u[sn ] = v[sn ]” if ∃n ∈ N.∀m ≥ n.u[sm ] = v[sm ]; 3. u converges if u converges in every w.i. chain of states. Remark that if u[σ] is convergent, we do not ask that u is convergent to the same value on all w.i. chain of states. This expresses the fact that the value learned by u may depend on the order by which u gets the information. In Theorem 1 we will prove that if u[σ] has type N, Bool, then u[σ] is convergent: in other words, the value “learned” by u[σ] eventually stops changing. For term of type S we will prove a slightly different property: on all w.i. chains, u[σ] converges to some σ s (this depends on the fact that u[σ] has input σ). In the same Theorem we will prove that if u[σ] : S then u[s] ≥ s for all s ∈ S: we interpret this result by the fact that a learning process always increases the state of knowledge. For each type A of T1 we define a set A of terms u[σ] : A which we call the set of stable terms of type A. We define stable terms by lifting the notion of convergence from atomic types (having a special case for the atomic type S, as we said) to arrow and product types. Definition 7. (Stable Terms). Let {si }i∈N be a w.i. chain of states and s ∈ S. Assume A is a type of T1 . We define a set A of terms t[σ] ∈ T1σ of type A, by induction on A. 1. S is the set of all t[σ] : S such that for all w.i. chains {si }i∈N : (a) ∃s ∈ S. t[σ] converges to σ s in {si }i∈N (b) for all s, s ∈ S, if s = t[s] then s ≥ s 2. N = {t[σ] : N | t converges} 3. Bool = {t[σ] : Bool | t converges} 4. A × B = {t[σ] : A × B | π0 t ∈ A, π1 t ∈ B} 5. A → B = {t[σ] : A → B | ∀u ∈ A, tu ∈ B} If t ∈ A, we say that t is a stable term of type A. By induction on A, we may check that there is some dummy stable term dA ∈ A ∈ T1σ : we set dN = 0, dBool = F, dS = σ, dA×B = dA , dB , dA→B = λ A .dB . We want to prove now that any term u[σ] : A is stable.
28
F. Aschieri and S. Berardi
Lemma 1. (Stability.) Suppose u ∈ T1σ , and for every w.i. chain of states {si }i∈N there is a v ∈ C such that u[sn ] = v[sn ] for n → ∞. Then u ∈ C. Proof. By induction over u (see [3]). Theorem 1. (Stability Theorem) Let w : A be a term of T1σ and let x1 : A1 , . . . , xn : An contain all the free variables of w other than σ. If t1 ∈ A1 , . . . , tn ∈ An , then w[t1 /x1 · · · tn /xn ] ∈ A Proof. By induction over w (see [3]). Corollary 1. Assume that w : A, w ∈ T1σ . Then w ∈ A. If A = N, Bool then w converges, while if A = S, then w converges to some σ s in every w.i. chain, and w[s/σ] ≥ s for all s ∈ S. As last result of this section, we prove that if we start from any state s and we repeatedly apply a term t[σ] in the free state variable σ, eventually we reach a state s = th [s] such that t[s ] = s . We interpret this result by saying that each “learning process” t[σ] eventually stop adding new information to σ. Theorem 2. (Fixed Point Property) Let t[σ] : S be a term in the free variable σ, and s ∈ S. Define t0 [s] = s and tn+1 [s] = t[tn [s]]. Then there are h ∈ N, s ∈ S such that s = th [s], s ≥ s and t[s ] = s . Proof. See the full version of the paper [3].
3
An Interactive Learning-Based Notion of Realizability
In this section we introduce the notion of realizability for HA + EM1 , Heyting Arithmetic plus Excluded Middle on Σ10 -formulas, then we prove our Main Theorem, the Adequacy Theorem: “if a closed arithmetical formula is provable in HA + EM1 , then it is realizable”. For proofs we refer to [3]. We first define the formal system HA + EM1 , from now on “Core Arithmetic”. We will represent atomic formulas of HA + EM1 with terms of T of type Bool. We assume having in T some terms ⇒Bool : Bool, Bool → Bool, ¬Bool : Bool → Bool, . . ., implementing boolean connectives. If t1 , . . . , tn , t ∈ T have type Bool and free variables all of type Bool, we will say that t is a tautological consequence of t1 , . . . , tn in T (a tautology if n = 0) if all boolean assignments making t1 , . . . , tn equal to T in T also make t equal to T in T . Definition 8. (Core and Extended Language of Arithmetic). The Core Language L of Arithmetic is defined as follows. 1. The terms of L are all t ∈ T such that t : N and F V (t) ⊆ {xN1 , . . . , xNn } for some x1 , . . . , xn . 2. The atomic formulas of L are all P t1 . . . tn ∈ T , for some closed P : Nn → Bool and some terms t1 , . . . , tn of L.
Interactive Learning-Based Realizability Interpretation
29
3. The formulas of L are built from atomic formulas of L by the connectives ∨, ∧, → ∀, ∃ as usual. The proofs of Core Arithmetic are proof-trees in natural deduction style, as in van Dalen [9], with: (i) an axiom schema for EM1 ; (ii) the induction rule; (iii) as Post rules: all axioms of equality and ordering on N, all equational axioms of T , and one schema for each tautological consequences of T . We denote with ⊥ the atomic formula F and will sometimes write a generic atomic formula as P (t1 , . . . , tn ) rather than in the form P t1 . . . tn . Finally, since any arithmetical formula has only variables of type N, we shall freely omit their types, writing for instance ∀xA in place of ∀xN A. Post rules cover many rules with atomic assumptions and conclusion as we find useful, for example, the rule: “if f (z) ≤ 0 then f (z) = 0”. As an intermediate step for the Realization interpretation, we introduce an extension of HA+EM1 we call Extended Arithmetic. The Language L1 of Extended Arithmetic extends the Language of Core Arithmetic by allowing terms and atomic formulas to depend on a state, and by the symbols χP , ϕP denoting oracles and Skolem maps for Σ10 -formulas. Definition 9. The the Extended Language L1 is defined as follows. 1. The terms of L1 are all t ∈ T1 such that t : N and F V (t) ⊆ {xN1 , . . . , xNn , σ} for some x1 , . . . , xn . 2. The atomic formulas of L1 are all P t1 . . . tn ∈ T1 , for some P : Nn → Bool, P ∈ T1σ and some terms t1 , . . . , tn of L1 . 3. The formulas of L1 are built from atomic formulas of L1 by the connectives ∨, ∧, → ∀, ∃ as usual. Lσ1 is the subset of the terms and formulas L1 without constants of type S and whose only free variable is σ : S. Deduction rules for Extended Arithmetic are those for Core Arithmetic, plus the axiom schemas for oracles: P (t1 , . . . , tn , t) ⇒Bool χP σt1 . . . tn and for Skolem maps: χP σt1 . . . tn ⇒Bool P (t1 , . . . , tn , (ϕP σt1 . . . tn )). Recall that ⇒Bool : Bool, Bool → Bool is a term implementing implication, therefore P (t1 , . . . , tn , t) ⇒Bool χP σt1 . . . tn is not an implication between two atomic formulas, but it is equal to the single atomic formula Qt1 . . . tn t, where Q = λxN1 . . . λxNn+1 ⇒Bool (P x1 . . . xn xn+1 )(χP σx1 . . . xn+1 ) The set of Skolem axioms effectively used by a given proof will take the place of experiments checking our assumptions about Skolem maps and oracles. The Language of Extended Arithmetic, indeed, is quite unusual. The idea behind it is to offer a way of extending with non computable terms (for example, the ideal χ and ϕ) the standard Language of Arithmetic. We interpret non computable terms t[σ] ∈ Lσ1 as computable maps from S to N, approximating the ideal χ and ϕ by instantiating their free state variable σ with a state s.
30
F. Aschieri and S. Berardi
Using the metaphor explained in the introduction, we will use a theory - whose hypotheses are determined by s - to predict truth values for atomic formulas that we cannot effectively evaluate. Our definition of realizability will provide a formal semantics for the Extended Language of Arithmetic (in the free variable σ), and therefore also for the more usual language of Core Arithmetic in which all functions represent recursive maps. Definition 10. (Types for realizers) For each arithmetical formula A we define a type |A| of T by induction on A: |P (t1 , . . . , tn )| = S, |A ∧ B| = |A| × |B|, |A ∨ B| = Bool × (|A| × |B|), |A → B| = |A| → |B|, |∀xA| = N → |A|, |∃xA| = N × |A| We will now define the realization relation t A, where t ∈ T1σ , A ∈ Lσ1 and t : |A|. Remark that by the Corollary 1 we have t ∈ |A|. By the same Corollary, if A is atomic, that is, if t[σ] : |A| = S, for all s, s ∈ S if s = t[s] then s ≥ s . We interpret this result by saying that any realizer of any atomic formula extends the “current state of knowledge”. We first define t s A, the realization relation w.r.t. any state s ∈ S, then t A. Definition 11. (Indexed Realizability and Realizability) Assume t ∈ T1σ , A ∈ Lσ1 , and t : |A|. We define t s A for any s ∈ S by induction on A. 1. 2. 3. 4. 5. 6.
t s t s t s t s t s t s
P (t1 , . . . , tn ) iff t[s] = s implies P (t1 , . . . , tn )[s] = T A ∧ B iff π0 t s A and π1 t s B A ∨ B iff either π0 t[s] = T and π1 t s A or π0 t[s] = F and π2 t s B A → B iff for all u, if u s A, then tu s B ∀xA iff for all n ∈ N, tn s A[n/x] ∃xA iff π0 t[s] = n and π1 t s A[n/x]
t A iff ∀s ∈ S: t s A In the above definition, at last, we see formalized all the intuitions we hinted at in the introduction. Realizers of disjunctions and existential statements provide a witness, which is an individual depending on an actual state of knowledge s ∈ S, representing the hypotheses used to approximate the non-computable. The actual behavior of a realizer depends upon the current state of knowledge. The state is used only when there is relevant information about the truth of a given formula to be computed: the truth value P (t1 , . . . , tn )[s] of an atomic formula and the existential or disjunctive witness π0 t[s] are computed w.r.t. the state. A realizer t of ∃xA uses the state s to predict that π0 t[s] equals an n, some witness for ∃xA (i.e. A(n) that is realizable). A realizer t of A ∨ B uses the state s to predict which one between A and B is realizable (if π0 t[s] = T then A is realizable, and if π1 t[s] = F then B is realizable). These predictions need not be always correct; hence, it is possible that a realized atomic formula - which ideally should be true when realized - it is actually false; namely, t s P notwithstanding, it may happen that P [s] equals false. If a Skolem axiom predicted to be true is indeed false, then we have encountered
Interactive Learning-Based Realizability Interpretation
31
a counterexample and so our theory is wrong, our approximation still inadequate; in this case, the atomic realizer t takes the state s and extends it to a state t[s] > s. That is to say: if something goes wrong, we must learn from our mistakes. The point is that after every learning, the actual state of knowledge grows, and if we ask to the same realizer new predictions, we will obtain “better” answers. Indeed, we can say more about this last point. Suppose for instance that t A∨B and let {si }i∈N be a w.i. chain of states. Then, since t ∈ Bool×|A|×|B|, π0 t converges in {si }i∈N to a boolean; thus t’s predictions eventually stabilize in the limit and hence a witness is eventually learned. In the atomic case, in order to have t s P (t1 , . . . , tn ), we require that if s is a fixed point of t, then P (t1 , . . . , tn )[s] must equal true. That is to say: if t has nothing more to learn and has no new information to add to s, then it must assure the truth of P (t1 , . . . , tn ) in the state s. By the Fixed Point Theorem, our terms of type S and in the free state variable σ, as we saw, have plenty of fixed points; hence search for truth will be for us computation of a fixed point, driven by the Skolem axioms used by the proof, rather than exhaustive search for counterexamples. As usual for a Realization interpretation, we may extract from any realizer t ∀x.∃y.P (x, y), with P ∈ T , some recursive map ψ : N → N such that P (n, ψ(n)) for all n ∈ N. Indeed, by unfolding the definition of realizer, for all n ∈ N, s ∈ S, if a = π0 t, b = π1 t ∈ T1σ then a(n) s P (n, b(n)). If we define φ(s) = a(n)k [s] for the first k such that a(n)k+1 [s] = a(n)k [s], as in the proof of the Fixed Point Theorem, then a(n)[φ(s)] = φ(s), and by definition of realizer P (n, b(n))[φ(s)] ≡ P (n, b(n)[φ(s)]) is true. The map ψ is then defined by ψ(n) = b(n)[φ(s0 )] for all n ∈ N and some random choice of s0 ∈ S. We may prove that the map ψ in fact belongs to T1 , provided we replace the notion of convergence used in this paper with the intuitionistic notion of convergence introduced in [4], and we use this latter to provide a bound for for the first k such that a(n)k+1 [s] = a(n)k [s]. We postpone this topic to another paper. Now we explain how to turn each proof D of a formula A ∈ L1 in HA+ EM1 into a realizers D∗ of the same A. By induction on D, we define a “decoration with realizers” DReal of D, in which each formula B of D is replaced by a new statement u B, for some u ∈ T1 . If t A is the conclusion of DReal , we set D∗ = t. Then we will prove that if D is closed and without assumptions, then D∗ ∈ T1σ and D∗ A. The decoration DReal of D with realizers is completely standard: we have new realizers only for Excluded Middle and for atomic formulas. For notation simplicity, if xi is the label for the set of occurrences of some assumption Ai of D, we use xi also as a name of one free variable in D∗ of type |Ai |. Definition 12. (Term Assignment Rules for Core Arithmetic). Assume D is a 1 proof of A ∈ L1 in HA + EM1 , with free assumptions A1 , . . . , An labeled xA 1 ,..., An N N xn and free variables α1 , . . . , αm . By induction on D, we define a decorated proof-tree DReal , in which each formula B is replaced by u B for some u ∈ T1 , |A | |A | and the conclusion A with some t A, with F V (t) ⊆ {x1 1 , . . . , x1 1 , αN1 , . . . , N ∗ αm , σ}. Eventually we set D = t. all for type
32
F. Aschieri and S. Berardi
1. x|A| A if D consists of a single free assumption A ∈ L labeled xA . uA tB uA∧B uA∧B 2. u, t A ∧ B π0 u A π1 u B uB uA→B tA 3. ut B λx|A| u A → B uA uB 4. T, u, dB A ∨ B F, dA , u A ∨ B u A ∨ B w1 C w2 C if π0 u then (λx|A| w1 )(π1 u) else (λx|B| w2 )(π2 u) C where dA and dB are dummy stable terms of type |A| and |B| uA u ∀xA 5. ut A[t/x] λxN u ∀xA where t is a term of L and xN does not occur free in any free assumption B of the subproof of D of conclusion A. u ∃αN .A t C u A[t/αN ] 6. N N t, u ∃α .A (λα λx|A| t)(π0 u)(π1 u) C N where α is not free in C nor in any free assumption B different from A in the subproof of D of conclusion C. u A(0) v ∀x.A(x) → A(S(x)) 7. λy N Ruvy ∀xA u A1 u2 A2 · · · un An 8. 1 u1 u2 · · · un A where n > 0 and A1 , A2 , . . . , An , A are atomic formulas of L, and the rule is a Post rule for equality or ordering, or a tautological consequence. 9. σ A where A is an atomic axiom of HA + EM1 (an axiom of equality or of ordering or a tautology or an equation of T ) 10. EP ∀x. ∃y P (x, y) ∨ ∀y¬Bool P (x, y) where EP is defined as λαN χP σα, ϕP σα, σ , λnN (Add)σ P, α, n
The term decorating the conclusion of a Post rule is of the form u1 · · · un . In this case, we have n different realizers, whose learning capabilities are put together through a sort of union. If u1 · · · un has a fixed point s then we may prove that s is a common fixed point for all u1 , . . . , un ,1 i.e., that all ui “have nothing to learn”. Then each ui must guarantee Ai to be true, and therefore the conclusion of the Post rule is true, because true premises A1 , . . . , An spell a true conclusion A. The decoration DReal of a proof D can be extended to any proof of Extended Arithmetic. Definition 13. (Extra Term Assignment Rules for Extended Arithmetic). 1
Proof Sketch for n = 2. Prove the following first, for all s, s1 , s2 ∈ S: (i) s1 ≤ s1 s2 ; (ii) if s1 ≤ s2 then s1 s2 = s2 ; (iii) if s ≤ s1 , s2 , and s = s1 s2 then s = s1 and s = s2 . Now from s ≤ u1 [s], u2 [s] and s = u1 [s] u2 [s] deduce s = u1 [s] = u2 [s].
Interactive Learning-Based Realizability Interpretation
33
– (Add)σ P, t1 , . . . , tn , t P (t1 , . . . , tn , t) ⇒Bool χP σt1 . . . tn , χ-Axiom – σ χP σt1 . . . tn ⇒Bool P (t1 , . . . , tn , (ϕP σt1 . . . tn )) , ϕ-Axiom Example (Realizer of the Excluded Middle 1). We now prove that EP ∀x. ∃y P (x, y) ∨ ∀y¬Bool P (x, y). Let m be a vector of numerals and let s ∈ S. EP is defined as λαN χP σα, ϕP σα, σ , λnN (Add)σ P, α, n
and we want to prove that EP m s ∃y P (m, y) ∨ ∀y¬Bool P (m, y) Assume π0 EP m[s] = χP sm = T : we have to prove that π1 EP m = ϕP σm, σ s ∃y P (m, y) By definition, ϕP sm = n, for some n such that P (m, n) = T ; hence, σ s P (m, n) and ϕP σm, σ s ∃y P (m, y). Now assume π0 EP m[s] = χP sm = F. We have to prove π2 EP m = λn (Add)σ P, m, n s ∀y¬Bool P (m, y) that is that, given any n ∈ N, (Add)σ P, m, n s ¬Bool P (m, n) By definition, we have to assume that s is a fixed point of (Add)σ P, m, n ; that is, (Add)s P, m, n = s. Then, it must be the case that P (m, n)[s] = F : it were not so, P (m, n)[s] = T and hence s = s ∪ P, m, n for some n ∈ N , contradicting χP sm = F . Thus, ¬Bool P (m, n)[s] = T : it follows our thesis. EP works according to the ideas we sketched in the introduction. It uses χP to make predictions about which one between ∃y P (m, y) and ∀y¬Bool P (m, y) is true. χP , in turn, relies on the actual state s to make its own prediction. If χP sm = F , given any n, ¬Bool P (m, n) is predicted to be true; if it is not the case, we have a counterexample and (Add) extends the state with P, m, n . On the contrary, if χP sm = T , there is unquestionable evidence that ∃yP (m, y) holds; namely, there is an n such that P, m, n ∈ s; then ϕP is called, and it returns ϕP sm = n. This is the basic mechanism by which we implement learning: every state extension is linked with an assumption about an instance of EM1 which we used and turned out to be wrong (this is the only way to come across a counterexample); in next computations, the actual state will be bigger, the realizer will not do the same error, and hence will be “wiser”. We will now prove our main theorem, that every theorem of HA + EM1 is realizable. We need a few Lemmas first. In the next Lemma we prove that if we introduce a state constant by substitution, then we eliminate it, we preserve the realization relation. Namely, take any realizer u[σ] in T1σ , then replace some occurrences of σ with a constant s, obtaining some term u”[σ, s] in T1 − T1σ . Assume that u”[σ, s] is equal to some u [σ] ∈ T1σ (without the constant s). Then u, u realize the same formulas.
34
F. Aschieri and S. Berardi
Lemma 2. (State Constant Elimination) Let u, u ∈ T1σ , C, C ∈ Lσ1 . Assume for some u” ∈ T1 , C” ∈ L1 we have u [σ] = u”[σ, s], u[σ] = u”[σ, σ] and C [σ] = C”[σ, s], C[σ] = C”[σ, σ]. Then u s C iff u s C. Proof. By induction on C (see [3]). We will also need the commutation of (.)∗ with substitution: Proposition 1. If D is a proof of A, and m ∈ N, then D∗ [m/αN ] = D[m/αN ]∗ . We are now able to prove our main theorem. Theorem 3. (Adequacy Theorem) Suppose that D is a proof of A in the system An 1 of Extended Arithmetic with free assumptions xA and free variables 1 , . . . , xn ∗ α1 : N, . . . , αk : N, σ : S. Let w = D . For all s ∈ S, if n1 , . . . , nk ∈ N and t1 s A1 [n1 /α1 · · · nk /αk ] and . . . and tn s An [n1 /α1 · · · nk /αk ], then |A1 |
w[t1 /x1
n| · · · tn /x|A n1 /α1 · · · nk /αk ] s A[n1 /α1 · · · nk /αk ] n
Proof. By induction on w (see [3]). Corollary 2. If A is a closed formula provable in HA + EM1 , then there exists w ∈ T1σ such that w A.
References 1. Avigad, J.: Update Procedures and the 1-Consistency of Arithmetic. Math. Log. Q. 48(1), 3–13 (2002) 2. Akama, Y., Berardi, S., Hayashi, S., Kohlenbach, U.: An Arithmetical Hierarchy of the Law of Excluded Middle and Related Principles. In: LICS 2004, pp. 192–201 (2004) 3. Aschieri, F., Berardi, S.: An Interactive Realizability... (Full Paper), Tech. Rep., Un. of Turin (2009), http://www.di.unito.it/~ stefano/Realizers2009.pdf 4. Berardi, S.: Classical Logic as Limit . . . . MSCS 15(1), 167–200 (2005) 5. Berardi, S.: Some intuitionistic equivalents of classical principles for degree 2 formulas. Annals of Pure and Applied Logic 139(1-3), 185–200 (2006) 6. Berardi, S., Coquand, T., Hayashi, S.: Games with 1-Bactracking. In: GALOP 2005 (2005) 7. Berardi, S., de’Liguoro, U.: A calculus of realizers for EM1 -Arithmetic. In: Kaminski, M., Martini, S. (eds.) CSL 2008. LNCS, vol. 5213, pp. 215–229. Springer, Heidelberg (2008) 8. Coquand, T.: A Semantic of Evidence for Classical Arithmetic. Journal of Symbolic Logic 60, 325–337 (1995) 9. Dalen, D.v.: Logic and Structure, 3rd edn. Springer-, Heidelberg (1994) 10. Girard, J.-Y.: Proofs and Types. Cambridge University Press, Cambridge (1989) 11. Gold, E.M.: Limiting Recursion. Journal of Symbolic Logic 30, 28–48 (1965) 12. Hayashi, S., Sumitomo, R., Shii, K.: Towards Animation of Proofs -Testing Proofs by Examples. Theoretical Computer Science (2002) 13. Hayashi, S.: Can Proofs be Animated by Games? FI 77(4), 331–343 (2007) 14. Hayashi, S.: Mathematics based on incremental learning - Excluded Middle and Inductive Inference. Theoretical Computer Science 350, 125–139 (2006) 15. Kleene, S.C.: On the Interpretation of Intuitionistic Number Theory. Journal of Symbolic Logic 10(4), 109–124 (1945) 16. Popper, K.: The Logic of Scientific Discovery. Routledge Classics, Routledge (2002)
Syntax for Free: Representing Syntax with Binding Using Parametricity Robert Atkey School of Informatics, University of Edinburgh
[email protected]
Abstract. We show that, in a parametric model of polymorphism, the type ∀α.((α → α) → α) → (α → α → α) → α is isomorphic to closed de Bruijn terms. That is, the type of closed higher-order abstract syntax terms is isomorphic to a concrete representation. To demonstrate the proof we have constructed a model of parametric polymorphism inside the Coq proof assistant. The proof of the theorem requires parametricity over Kripke relations. We also investigate some variants of this representation.
1
Introduction
Representing, computing with, and reasoning about syntax with binding has been of interest to computer scientists for the last 30 or 40 years. The crucial point that makes these activities difficult is the notion of α-equivalence, the obvious idea that if we have two terms equal up to the swapping of the names of their bound variables, e.g. λx.x and λy.y, then the terms should be treated equally. Unfortunately, the obvious representation of binders as a pair of a variable name and a subterm does not respect α-equivalence, so operations on such data must be carefully written in order to respect it. In this paper, we look at two solutions that have been put forward to deal with this (we do not look at the third major approach: nominal sets [7]): de Bruijn indicies and higher-order abstract syntax, and relate the two. The de Bruijn index approach [5], approaches the problem by removing the names of bound variables altogether. Bound variables are represented by pointers to the construct that binds them. For instance, the λ-term λx.λy.xy is represented as λ.λ.1 0. The bound variable x has been replaced by a pointer to the binder one step away from the occurrence, and the bound variable y has been replaced by a binder zero steps away. The advantage of this representation is that α-equivalent terms are now structurally equal. The disadvantage is the complicated definitions of common operations such as substitution, where non-intuitive shifting operations are required to maintain the correct pointers. Another common approach is to use higher-order abstract syntax [13]. In this approach, we use the binding structure of the meta-language to represent binding in the object-language. For the untyped λ-calculus, we suppose that there is a type tm and operations lam : (tm → tm) → tm and app : tm → tm → tm. P.-L. Curien (Ed.): TLCA 2009, LNCS 5608, pp. 35–49, 2009. c Springer-Verlag Berlin Heidelberg 2009
36
R. Atkey
The object-level term λx.λy.xy is thus represented as the meta-language term lam (λx. lam (λy. app x y)). The key advantage of this approach is that, since object-level variables are represented using meta-level variables, substitution becomes very easy to define. A disadvantage of this representation is the need to make sure that we do not allow too many terms into our type tm. Proving that we have not done so is called adequacy [8], and is usually performed by reasoning on the canonical forms of some weak type theory such as LF. The key to higher-order abstract syntax is that the meta-level variables that are used to represent object-level variables are only used as variables, and cannot be further analysed. Washburn and Weirich [18] noted that parametric type abstraction, as available in System F, is a viable way of ensuring that represented terms are well behaved. They consider the type ∀α.((α → α) → α) → (α → α → α) → α and derive a fold operator and some reasoning principles from it. This type captures the two operations of higher-order abstract syntax, the lam and the app, but abstracts over the carrier type. Washburn and Weirich claim that this type represents exactly the terms of the untyped λ-calculus, but do not provide a proof. Coquand and Huet [4] also state that this type represents untyped lambda terms, also without proof. In this paper we provide such a proof. The reason that this approach works is that System F terms of type ∀α.τ must act parametrically in α, that is, they cannot reflect on what actual instantiation of α they have been provided with. Reynolds [16] formalised this idea by stating that for any two instantiations of α, parametric terms must preserve all relations between them. We take this idea, and extend it to use Kripke relations [15]. Kripke relations are relations R indexed by some preorder W , such that if w ≤ w in W , then Rwxy implies Rw xy. By requiring that all terms of polymorphic type preserve all Kripke logical relations, we can prove that the denotation of the type given by Washburn and Weirich is isomorphic to the type of closed de Bruijn terms: de Bruijn terms that do not have dangling pointers. The preorder-indexing of the relations is used to handle the expansion of the number of meta-variables being used as object-variables as we go under binders. Traditionally, parametric models of System F have been hard to come by, and have generally involved fiddly constructions with PERs. We make life easier for ourselves by starting with a meta-theory1 that already has impredicative polymorphism and construct a parametric model of System F inside it. We use a version of Coq with impredicative polymorphism for this purpose, and we have formalised most of our results here2 . Overview. In the next section we introduce our model of System F inside the Coq type theory. Following that, in Section 3, we present our main result, the 1 2
Or meta-meta-theory, if one is pedantic. The formal development is available from: http://homepages.inf.ed.ac.uk/ratkey/parametricity
Syntax for Free: Representing Syntax with Binding Using Parametricity
37
isomorphism between the Washburn-Weirich HOAS type and de Bruijn terms. In Section 4 we investigate two alternative representations that take different views on how variables are represented. In Section 5, we show how the computational aspect of System F can be integrated into our object-level representations, and prove that a simplified version of the Haskell ST monad can be represented using de Bruijn-style terms. Finally, Section 6 concludes with a discussion of related work.
2
A Model of Parametric Polymorphism
To state and prove our main results, we construct, inside the Coq proof assistant, a denotational model of System F that supports parametricity. For simplicity, we want to let System F types be denoted by objects of sort Set; we can then express denotations of terms as normal Coq functions that preserve all Kripke relations. 2.1
Preparing the Meta-theory
In order to use Sets as denotations of System F types, we require impredicativity. The denotation of the type ∀α.τ quantifies over all denotations of types (i.e. Sets). By default, Coq’s type theory is predicative for Set (although it is impredicative in the type of propositions, Prop), so one cannot construct a new object of sort Set by quantifying over all objects of sort Set. Fortunately, Coq supports a command line option -impredicative-set that allows us to proceed. We also require three axioms to be added to Coq’s theory. The first of these is proof irrelevance, which states that all proofs of a given proposition are equal: ∀P : Prop. ∀p1 , p2 : P. p1 = p2 . We also require extensionality for functions, which states that two functions are equal if they are equal for all inputs: ∀A : Type, B : A → Type, f, g : (∀a.Ba). (∀x. f x = gx) → f = g Extensionality for functions allows our denotational model to support the ηequality rules of System F. We also require propositional extensionality, which will allow us to treat equivalent propositions as equal: ∀P, Q : Prop, (P ↔ Q) → P = Q These axioms allow us to define data with embedded proofs that are equal if their computational contents are equal, which will aid us in proving equalities between denotations of System F types. We informally justify our use of these axioms, plus impredicativity, by the existence of models of CIC in intuitionistic set theory. In the remainder of the paper, we use informal set theoretic notation and do not explicitly highlight the uses of these axioms. Note that everywhere we use the word “set”, we are referring to Coq objects of sort Set.
38
2.2
R. Atkey
Denotational Semantics of System F
The syntax of System F types is standard: τ ::=
α
| τ1 → τ2
| ∀α.τ
where α is taken from a countably infinite set of variables, and ∀α.τ binds α in τ . We actually use a de Bruijn representation of types (and terms) of System F in our Coq development, but we will use the usual concrete representation for exposition. As we mentioned in the introduction, in order to prove the isomorphisms below involving syntax with binding, we require that the denotation of ∀α.τ be parametric over all Kripke relations over all preorders. Preorders consist of a carrier W : Type and a binary relation ≤W : W → W → Prop that is reflexive and transitive. For a given preorder W , a W -Kripke logical relation over sets A, B : Set is a predicate R : W → A → B → Prop, such that ∀w, w , a, b. w ≤W w → Rwab → Rw ab. For brevity, we write the collection of all W -Kripke relations over A, B as KRel(W, A, B). Note that, even though we are using W -indexed Kripke relations, we do not use sets indexed by any particular W as denotations of System F types—we are not constructing a model of System F in the presheaf category for some preorder W . We will require multiple instantiations of W in our proofs. Type environments γ are mappings from type variables to sets. For a preorder W and a pair of type environments γ1 , γ2 , a relation environment ρ is a mapping from type variables α to W -Kripke relations over γ1 (α), γ2 (α). For any type environment γ and preorder W , there is a relation environment ΔW γ that maps all type variables to the equality relation. We now define the denotations of types and the induced Kripke relations between them. The mapping T − maps types with type environments to sets and the mapping R− maps types τ , preorders W and relation environments over type environments γ1 , γ2 to W -Kripke relations over T τ γ1 , T τ γ2 . These mappings are mutually defined over the structure of types: T αγ = γ(α) T τ1 → τ2 γ = T τ1 γ → T τ2 γ T ∀α.τ γ = { x : ∀A : Set. T τ (γ[α → A]) | ∀W, A1 , A2 , R : KRel(W, A1 , A2 ), w : W. Rτ W (ΔW γ [α → R]) w (x A1 ) (x A2 ) } RαW ρ w x y = ρ(α) w x y Rτ1 → τ2 W ρ w f g = ∀w : W, x : T τ1 γ1 , y : T τ1 γ1 . w ≤W w → Rτ1 W ρ w x y → Rτ2 W ρ w (f x) (gy) R∀α.τ W ρ w x y = ∀A1 , A2 , R : KRel(W, A1 , A2 ). Rτ W (ρ[α → R]) w (x A1 ) (y A2 )
Syntax for Free: Representing Syntax with Binding Using Parametricity
39
These clauses are mostly straightforward for Kripke logical relations, but we draw the reader’s attention to the clause for T ∀α.τ . We have used impredicative quantification over all sets here. We also constrain the denotations of polymorphic types to be those that preserve all W -Kripke relations, for all preorders W . It is this parametricity property that we will use to prove the isomorphisms in Section 3. Lemma 1. The following hold, for all τ and preorders W : 1. For all γ1 , γ2 and ρ, Rτ W ρ is a W -Kripke relation over T τ γ1 , T τ γ2 . 2. For all γ and w, Rτ W ΔW γ w x y iff x = y. Proof. Both by induction over the structure of τ . Note that this denotational semantics of types validates the usual representations of inductive types in System F, e.g. T ∀α.α → (α → α) → αγ ∼ = N etc. Denotations of System F terms. We also define a denotation for every well-typed System F term, but we have elided these for lack of space. Please see the formal development for more details. The main result is that every well-typed System F term has a meaning in the model as a function from the denotation of the context to the denotation of the result type, such that all Kripke relations over any preorder are preserved by this function.
3
Representing λ-Terms Using Parametricity
We will show that, in our model, the denotation of the type τH = ∀α.((α → α) → α) → (α → α → α) → α is isomorphic to the set of closed de Bruijn terms. This task is not so straightforward as producing two functions and showing that they are mutually inverse: we must show that the function from the above type to de Bruijn terms actually does give a well-formed closed de Bruijn term. We define the set of well-formed de Bruijn terms as a natural number-indexed inductively defined set Term : N → Set with constructors: Var : {i : N | i < n} → Term(n) Lam : Term(n + 1) → Term(n) App : Term(n) → Term(n) → Term(n) The set of all closed de Bruijn terms is hence given by Term(0). This definition admits the following recursion principle3 : term rec : ∀P : N → Set. (∀n.{i : N | i < n} → P (n)) → (∀n.P (n + 1) → P (n)) → (∀n.P (n) → P (n) → P (n)) → ∀n.Term(n) → P (n) 3
This is less general than the one Coq provides, but suffices for our purposes.
40
R. Atkey
We will also need the set of “pre-de Bruijn” terms—terms that are not necessarily known to be well-formed—as an intermediate staging ground. The set preTerm is defined inductively with the following constructors: preVar : N → preTerm preLam : preTerm → preTerm preApp : preTerm → preTerm → preTerm There is an obvious relation n t relating context sizes to preTerms well-formed in that context, and an isomorphism between Term(n) and {t : preTerm | n t}. Note that the type preTerm is a normal inductive type and is therefore representable in parametric System F. The mapping from τH to preTerm that we give is also expressible in pure System F. We are now ready to define this mapping from denotations of the type τH to Term(0). We do this first by mapping to preTerm and then showing that the produced term satisfies 0 t. By the definition of T τH , the underlying set for this type is ∀A : Set.((A → A) → A) → (A → A → A) → A. We define φ(t) = t (N → preTerm) lam app 0, where: lam = λf.λi.preLam (f (λj.preVar (j − (i + 1))) (i + 1)) app = λx.λy.λi.preApp (x i) (y i) We instantiate a value of type τH with the set N → preTerm, intending that applying a function of this type to a number n will produce a term well-formed in the context of size n. Inside the definition of these functions, the argument represents the depth of context (or the number of binders) surrounding the current term. In the case for app, we do not go under a binder, so we do not increase the depth when applying it to the sub-terms. In the case for lam, given a function f of type (N → preTerm) → (N → preTerm), and a depth i, we apply f to an argument that will evaluate to a bound variable for a future depth j. The arithmetic computes the distance between the bound variable and its binder. Crucially, it is always the case that j > i, since we only ever count upwards in the depth of terms. This is the meat of the following: Lemma 2. For all t : T τH γ, 0 φ(t). Proof. We use the parametricity of the denotation of τH . Unfolding the definition of RτH , this tells us that the following property holds of all t : T τH γ: ∀W, A1 , A2 , R : KRel(W, A1 , A2 ), w : W. (∀w1 ≥ w, lam 1 : (A1 → A1 ) → A1 , lam 2 : (A2 → A2 ) → A2 . (∀w2 ≥ w1 , f1 : A1 → A1 , f2 : A2 → A2 . (∀w3 ≥ w2 , x : A1 , y : A2 .R w3 x y → R w3 (f1 x) (f2 y)) → R w2 (lam 1 f1 ) (lam 2 f2 )) → (∀w4 ≥ w1 , app 1 : A1 → A1 → A1 , app 2 : A2 → A2 → A2 . (∀w5 ≥ w4 , x1 : A1 , x2 : A2 .R w5 x1 x2 → (∀w6 ≥ w5 , y1 : A1 , y2 : A2 .R w6 y1 y2 → R w6 (app1 x1 y1 ) (app2 x2 y2 ))) → R w4 (t A1 lam 1 app 1 ) (t A2 lam 2 app 2 )))
Syntax for Free: Representing Syntax with Binding Using Parametricity
41
We let W be N with the usual ordering. We will not need to use both type arguments for this proof, so we set A1 = N → preTerm and A2 = 1, the one element set (we use dummy implementations of lam and app for this type). We set R n x y iff ∀n ≥ n.n x(n ). It is easy to verify that this is a Kripke relation. This relation will suffice to prove our lemma, provided we can prove that our implementations of lam and app in the definition of φ satisfy the requirements of t’s parametricity property. For lam, we must prove that at all depths n ≥ 0, if we are given a functional argument f : (N → preTerm) → (N → preTerm) satisfying the property at all n ≥ n, then for all n ≥ n, we have n preLam (f (λj.preVar (j − (n + 1))) (n + 1)) This is true if n + 1 f (λj.preVar (j − (n + 1))) (n + 1) Since f preserves R, we need only show that the argument λj.preVar (j −(n +1)) satisfies R at all n ≥ n + 1. This amounts to showing that n preVar(n − (n + 1)) which is trivial. The case for app is easier and is a straightforward application of the required property being satisfied by the two arguments. This proof is very similar to the Kripke logical relations proof employed by Rhiger [17] to prove that a single language embedded using higher-order abstract syntax always gives well-formed terms. We have extended this by allowing multiple languages to be embedded in a single meta-language. Rhiger also considers the use of type constructors to embed typed languages, something we cannot do in our System F setting. We also note that the proofs here are very similar in structure to the proofs used for proving adequacy of higher-order syntax encodings in LF [8]. Corollary 1. The map φ can be seen as a map from T τH γ to Term(0). The map φ−1 from closed de Bruijn terms is defined by recursion over the structure of terms. We make use of an auxiliary data structure of vectors vec A n, representing lists of elements of type A : Set of length n. These have two constructors: vecNil : vec A 0 vecCons : A → vec A n → vec A (n + 1) and a look-up function lookup : vec A n → {i : N | i < n} → A.
42
R. Atkey
The mapping φ−1 : Term(0) → T τH γ is defined as: φ−1 (t) = λA : Set.λlam.λapp. term rec (λn.vec A n → A) (λn, i, env . lookup env i) (λn, h, env . lam (λx. h (vecCons x env ))) (λn, x, y, env . app (x env ) (y env )) 0 t vecNil The basic idea is to recurse down the term, maintaining a vector of representations of bound variables. Every time we go under a binder, we extend the vector by the object provided by the implementation of lam. For this mapping to be well-defined, we must prove the following: Lemma 3. For all t : Term(0), φ−1 (t) is parametric. Proof. We must prove, essentially, that for any preorder W , pair of sets A1 , A2 and W -Kripke relation R over A1 , A2 , then if lam 1 , lam 2 and app 1 , app 2 are related pairs of functions, then the bodies of φ−1 are related by R at some index w. We strengthen the statement from talking about terms in Term(0) with empty starting environments to: for all n and t : Term(n), v1 : vec A1 n, v2 : vec A2 n and w ≥ w, ∀i : {i : N | i < n}, w ≥ w . R w (lookup v1 i) (lookup v2 i) implies R w (term rec ... t v1 ) (term rec ... t v2 ). This is easily proved by induction on t, and implies the lemma statement. We now prove that our two mappings are mutually inverse. We first do the direction that does not require parametricity: Lemma 4. For all t : Term(0), φ(φ−1 (t)) = t. Proof. As with the previous proof, we strengthen the statement to prove that for all n, t : Term(n) and v : vec (N → preTerm) n, ∀i ≤ n, n . n ≤ n → (lookup v i) n = Var(i + (n − n )) implies term rec ... t v n = t. This is easily proved by induction on t, and implies the lemma statement. The other direction requires the use of parametricity: Lemma 5. For all t : T τH , φ−1 (φ(t) = t. Proof. We are given a set A and operations lam and app. We apply the parametricity property of t (as given in the proof of Lemma 2) with the following data. The preorder W consists of lists of elements of A with the prefix ordering. The set A1 is set to N → preTerm, and A2 is set to A. We set the relation R to be R env x y iff: ∀env env . term rec ... (x (length env )) (toVec env ) = y
Syntax for Free: Representing Syntax with Binding Using Parametricity
43
where length gives the length of a list, and toVec maps lists l of As to a value of type vec A (length l). It is easy to prove that is is a Kripke relation. The proof then proceeds in a very similar way to the proof of Lemma 2. Summing up, we have: Theorem 1. Term(0) ∼ = T τH γ.
4
Alternative Representations of Variables
Washburn and Weirich [18] also consider terms with a fixed maximum number of free variables by using types of the form: n = ∀α.((α → α) → α) → (α → α → α) → αn τH
where α0 = α and αn+1 = α → αn . By extending the proof in the previous n γ ∼ section, we have been able to prove T τH = Term(n) for various n, but unfortunately we have not been able to formally prove this for all n. Washburn and Weirich further claim ([18], in the definition of iterList) that the type ∀α.((α → α) → α) → (α → α → α) → [α] → α represents terms with arbitrary numbers of free variables, where [α] is shorthand for lists of α. However, it is easy to see that this is not the case. Consider the following inhabitant of this type: Λα.λlam.λapp.λenv . match env with nil ⇒ lam(λx.x) | cons(x, t) ⇒ x (where we allow ourselves some syntactic sugar for lists in System F). This “term” represents λx.x when the free variable list is empty, and the first available free variable otherwise. This does not correspond to any single λ-term. We now look at two other representations of variables in higher-order abstract syntax and evaluate them in the light of the techniques of Section 3. 4.1
Parameterised and Weak Higher-Order Abstract Syntax
In [6] the authors note that the normal higher-order abstract syntax type cannot be directly translated to an inductive type in Coq due to the negative occurrence in the case for λ-abstraction. They propose weak higher-order abstract syntax, defined by an inductive type parameterised by a type of variables. We can represent this type in System F like so, using the normal encoding of inductive types: τWH (ν) = ∀α.(ν → α) → ((ν → α) → α) → (α → α → α) → α Choosing something obvious for ν, like natural numbers, results in inhabitants of this type that do not represent λ-terms (because they can inspect the variable
44
R. Atkey
names they are given). The solution is to keep the type ν abstract, so that inhabitants cannot inspect their variables. Hofmann [9] analysed this construction in the setting of presheaves, using a presheaf of variables for ν. Following on from [6], Chlipala [3] noticed that, if the meta language has parametric polymorphism, then the type ∀ν.τWH (ν) can be used to represent λ-terms, but he did not have a proof. He called this technique parameterised higher-order abstract syntax. We can supply such a proof: Theorem 2. T τH γ ∼ = T ∀ν.τWH (ν)γ (∼ = Term(0)). Proof. Define (in System F) φ : τH → ∀ν.τWH (ν) and φ−1 : (∀ν.τWH (ν)) → τH by: φ = λt.Λν.Λα.λvar .λlam.λapp. t [α] (λf. lam (λx. f (var x))) app φ−1 = λt.Λα.λlam.λapp. t [α] [α] (λx.x) lam app Since these functions are terms of System F, the parametricity properties automatically hold. The φ−1 (φ(t)) direction is particularly easy to prove: φ−1 (Λν.Λα.λvar .λlam.λapp. t [α] (λf. lam (λx. f (var x))) app) = Λα.λlam.λapp. t [α] (λf. lam (λx. f ((λx. x) x))) app = Λα.λlam.λapp. t [α] lam app =t In the reverse direction we can prove φ(φ−1 (t)) = t by applying parametricity over ordinary relations (Kripke relations are not needed here). If we have sets V for ν and A for α, the key idea is to relate the A and V by Rxy iff x = var y and relate A and A by the equality relation. 4.2
Locally Higher-Order Abstract Syntax
We now consider explicitly representing free variables in terms using any data type we choose, but representing bound variables using higher-order abstract syntax. This approach is inspired by locally nameless representations using de Bruijn indicies only for bound variables [1]. We consider the type: τLH (ν) = ∀α.(ν → α) → ((α → α) → α) → (α → α → α) → α This type has three “constructors”, one for injecting free variables of type ν into terms, and the two higher-order abstract syntax constructors. We are free to choose any type we like for ν, such as natural numbers or strings. Selecting naturals, we can define the following combinators: var : N → τLH (N) var = λx.Λα.λv.λl.λa. v x app : τLH (N) → τLH (N) → τLH (N) app = λxy.Λα.λv.λl.λa. a x y lam : N → τLH (N) → τLH (N) lam = λxt.Λα.λv.λl. l (λy. t [α] (λx .if x = x then y else v x ) l a)
Syntax for Free: Representing Syntax with Binding Using Parametricity
45
The var combinator constructs a term with a single free variable, and app constructs the object-level application of two terms. The lam combinator is more complicated: for free variable x and term t, it creates a new object-level λabstraction, with the body being t with x substituted for the variable bound by the object-level λ-abstraction. It is also possible to define a pattern matching combinator of type: τLH (N) → N + (τLH (N) × τLH (N)) + (τLH (N) → τLH (N)) that analyses a term in our representation, and returns either a free variable, the pair of terms involved in an application, or a term abstracted over another term in the case of object-level λ-abstraction. We cannot give this term here due to lack of space: please see the OCaml files contained with the Coq development. By using the techniques of Section 3 we can prove that this representation is actually equivalent to a representation using de Bruijn terms. We define such a representation LNTerm(A, n) inductively by the following constructors: freeVar : A → LNTerm(A, n) boundVar : {i : N | i < n} → LNTerm(A, n) Lam : LNTerm(A, n + 1) → LNTerm(A, n) App : LNTerm(A, n) → LNTerm(A, n) → LNTerm(A, n) Theorem 3. For closed types τ , LNTerm(T τ γ, 0) ∼ = T τLH (τ )γ. The significance of this theorem arises from the fact that we can use a language with parametric polymorphism to represent locally nameless λ-terms; a type that would normally seem to require some kind of indexed types to represent. We speculate that it would be possible to build a convenient (if inefficient) library for manipulating syntax with binders in OCaml using this representation.
5
Mixing Computation and Representation
We now go beyond the representation of pure syntax to embed the computational power of System F in abstract syntax trees. Licata, Zeilberger and Harper [11] define a system based on a proof theoretic analysis of focusing that allows for a mixing of computational and representational data. Note that the locally higherorder abstract syntax example from the previous section already demonstrates this in action: the ν → α constructor for free variables is computational in the sense that it can inspect the values it is given. 5.1
Arithmetic Expressions
Our first example is from Licata et al [11], that of the abstract syntax of arithmetic expressions with embedded “semantic” binary operations. Binding structure is introduced into the type by a “let” construct. We make the following definition, assuming some primitive type of integers int:
46
R. Atkey
τA = ∀α. (int → α) → ((int → int → int) → α → α → α) → (α → (α → α) → α) → α From the type, we have three “constructors”: one to introduce integers into terms, one for terms representing binary operations, with a function expressing the actual operation to perform, and one to handle lets, using the normal higherorder abstract syntax representation for binding. We can write an evaluator for expressions in this type very easily: eval(t) = t [int] (λx. x) (λf xy. f xy) (λxf. f x) A de Bruijn-style representation for these arithmetic expressions is given by the following constructors for an indexed type AExp : N → Set: Num : int → AExp(n) Binop : (int → int → int) → AExp(n) → AExp(n) → AExp(n) Let : AExp(n) → AExp(n + 1) → AExp(n) Again, using the same method as Section 3 we can prove: Theorem 4. AExp(0) ∼ = T τA γ. 5.2
Encapsulated Side-Effects with Dynamic Allocation
The Haskell programming languages contains a monad called ST, that is used to represent encapsulated side-effects with dynamic allocation. A simplified version of this monad, with a single type of data stored in references σ, a type of references ρ and result type τ is given by the following data: a family of types ST τ σ ρ, with associated monadic return and bind operations, plus three operations: new σρ : σ → ST ρ σ ρ upd σρ : ρ → σ → ST 1 σ ρ lkup σρ : ρ → ST σ σ ρ corresponding to dynamic allocation of a new memory cell, updating a memory cell and looking up the value of a memory cell. This monad has an associated function runST : ∀τ.∀σ.(∀ρ.τST (τ, σ, ρ)) → τ that takes a computation and runs it, producing a final result value of type τ . The intention is that the nested quantification over ρ prevents references leaking or entering from outside the computation. Moggi and Sabry [12] used operational techniques to prove the safety of the full ST monad with typed references. They represent values of the monadic type using a polymorphic type. Simplified to the System F setting with a single type for stored data, this type can be given as: τST (τ, σ, ρ) = ∀α. (τ → α) → (σ → (ρ → α) → α) → (ρ → σ → α → α) → (ρ → (σ → α) → α) → α
Syntax for Free: Representing Syntax with Binding Using Parametricity
47
We can make this family of types into a monad with the following definitions: return τ σρ : τ → τST (τ, σ, ρ) return τ σρ = λx.Λα.λret new upd lkup. ret x bind τ1 τ2 σρ : τST (τ1 , σ, ρ) → (τ1 → τST (τ2 , σ, ρ)) → τST (τ2 , σ, ρ) bind τ1 τ2 σρ = λcf.Λα.λret new upd lkup. c[α](λx. f x[α]ret new upd lkup) new upd lkup Note that, unlike Moggi and Sabry, we have not included a “constructor” in our type to represent bind , it can already be defined from the ret “constructor”. We define the operations of the monad like so: new σρ = λs.Λα.λret new upd lkup. new s (λr. ret r) upd ρ = λrs.Λα.λret new upd lkup. upd r s (ret ∗) lkup σρ = λr.Λα.λret new upd lkup. lkup r (λs. ret s) Using these combinators we can write programs in monadic style that issue commands to dynamically allocate new memory cells via the new operation and access them using the upd and lkup operations. Moggi and Sabry note that (their version of) the type τST (τ, σ, ρ) almost fits the schema for the polymorphic representation of an inductive type in System F, were it not for the negative occurrence of ρ in the new “constructor”. Using the techniques of Section 3, we can show that this type actually does correspond to an inductively defined type using de Bruijn representation for variables. The appropriate type is given by by the following constructors for an indexed type ST(A, S, −) : N → Set, for sets A and S. Ret : A → ST(A, S, n) New : S → ST(A, S, n + 1) → ST(A, S, n) Update : {i : N | i < n} → S → AExp(A, S, n) → AExp(A, S, n) Lookup : {i : N | i < n} → (S → AExp(A, S, n)) → AExp(A, S, n) Theorem 5. For closed types τ and σ, ST(T τ γ, T σγ, 0) ∼ = T ∀ρ.τST (τ, σ, ρ)γ. An obvious question now is whether this result extends to the case with typed references. Following Moggi and Sabry, we would expect that the Fω type λτ.∀ρ : ∗ → ∗.∀α. (τ → α) → (∀σ. σ → (ρ[σ] → α) → α) → (∀σ. ρ[σ] → σ → α → α) → (∀σ. ρ[σ] → (σ → α) → α) → α
48
R. Atkey
should have a de Bruijn-style representation similar to ST above. However, there is a problem with proceeding naively here. Consider the following program written in this monad (using Haskell’s do notation): do x ← new (λ(). return ()) upd x (λ(). do {y ← lkup x; y ()}) y ← lkup x y () which uses “Landin’s knot” to represent a non-terminating computation using mutable references. However, the “obvious” de Bruijn-style type (using a context consisting of lists of types) does not admit the translation of this term.
6
Related Work and Conclusions
Aside from the work of Washburn and Weirich [18], the closest work to ours is that of Rhiger [17], who shows that a higher-order abstract syntax encoding for a single typed object-language is sound and complete in a simply-typed metalanguage with a type constructor Exp : ∗ → ∗. We have extended his work by allowing multiple embedded languages. The use of System F also allows the use of iteration constructs to access terms from the outside, as demonstrated by Washburn and Weirich. Also related is the work of Carette et al [2]. They use the same method as Rhiger to embed languages inside an existing typed language (OCaml in this case). They abstract over the carrier type and actual implementations of lam and app, as we do here, but do not make the connection to concrete terms explicit. It seems obvious, though we have not yet formally proved it, that there is a natural extension of the representation of inductive types in System F as polymorphic types ∀α.(F [α] → α) → α, where α is positive in F to ones, where we allow negative a occurrences, and the represented type is some kind of abstract syntax with binding. We leave formulating and proving a general theorem of this kind to future work, but we suspect that it will be a straightforward application of the ideas in Section 3, the key idea being the use of Kripke logical relations. In future work we also wish to consider more powerful type theories than System F for use as the meta-language. An obvious first step is the use of System Fω , which will allow the use of type parameters to represent object languages with type systems that are subsets of the meta-language type system, although the case of the multi-typed ST monad from Section 5.2 shows that this extension may not be straightforward. Pfenning and Lee [14] have considered the use of Fω as a meta language, using a form of weak higher-order abstract syntax, but did not prove the close connection between representation and syntax that we have here. A yet more powerful route may be to consider the combination of dependent types and parametric polymorphism, so that representations of logics in the same style as the Logical Framework approach maybe used, combined with powerful ways of computing with them. The work of Izumi [10] on parametricity in dependent types may be useful here.
Syntax for Free: Representing Syntax with Binding Using Parametricity
49
Acknowledgements. Thanks to Randy Pollack, Sam Staton and Jeremy Yallop for comments on this work. This work was funded by the ReQueST grant (EP/C537068) from the Engineering and Physical Sciences Research Council.
References 1. Aydemir, B.E., Chargu´eraud, A., Pierce, B.C., Pollack, R., Weirich, S.: Engineering formal metatheory. In: Necula, G.C., Wadler, P. (eds.) POPL, pp. 3–15. ACM Press, New York (2008) 2. Carette, J., Kiselyov, O., Shan, C.-c.: Finally tagless, partially evaluated. In: Shao, Z. (ed.) APLAS 2007. LNCS, vol. 4807, pp. 222–238. Springer, Heidelberg (2007) 3. Chlipala, A.J.: Parametric higher-order abstract syntax for mechanized semantics. In: ICFP, pp. 143–156 (2008) 4. Coquand, T., Huet, G.: Constructions: A higher order proof system for mechanizing mathematics. In: Buchberger, B. (ed.) EUROCAL 1985. LNCS, vol. 203, pp. 151– 184. Springer, Heidelberg (1985) 5. de Bruijn, N.G.: Lambda-calculus notation with nameless dummies: a tool for automatic formula manipulation with application to the Church-Rosser theorem. Indag. Math. 34, 381–392 (1972) 6. Despeyroux, J., Felty, A.P., Hirschowitz, A.: Higher-Order Abstract Syntax in Coq. In: Dezani-Ciancaglini, M., Plotkin, G. (eds.) TLCA 1995. LNCS, vol. 902, pp. 124–138. Springer, Heidelberg (1995) 7. Gabbay, M., Pitts, A.M.: A New Approach to Abstract Syntax Involving Binders. In: LICS, pp. 214–224 (1999) 8. Harper, R., Licata, D.R.: Mechanizing metatheory in a logical framework. J. Funct. Program. 17(4-5), 613–673 (2007) 9. Hofmann, M.: Semantical Analysis of Higher-Order Abstract Syntax. In: LICS, pp. 204–213 (1999) 10. Izumi, T.: The Theory of Parametricity in Lambda Cube. Technical Report 1217, RIMS Kokyuroku (2001) 11. Licata, D.R., Zeilberger, N., Harper, R.: Focusing on Binding and Computation. In: LICS, pp. 241–252. IEEE Computer Society, Los Alamitos (2008) 12. Moggi, E., Sabry, A.: Monadic encapsulation of effects: a revised approach (extended version). J. Funct. Program. 11(6), 591–627 (2001) 13. Pfenning, F., Elliott, C.: Higher-Order Abstract Syntax. In: PLDI, pp. 199–208 (1988) 14. Pfenning, F., Lee, P.: Metacircularity in the polymorphic λ-calculus. Theoretical Computer Science 89, 137–159 (1991) 15. Plotkin, G.D.: Lambda-Definability in the Full Type Hierarchy. In: Seldin, J.P., Hindley, J.R. (eds.) To H. B. Curry: Essays on Combinatory Logic, Lambda Calculus and Formalism, pp. 363–373. Academic Press, London (1980) 16. Reynolds, J.C.: Types, Abstraction and Parametric Polymorphism. In: IFIP Congress, pp. 513–523 (1983) 17. Rhiger, M.: A foundation for embedded languages. ACM Trans. Program. Lang. Syst. 25(3), 291–315 (2003) 18. Washburn, G., Weirich, S.: Boxes go bananas: Encoding higher-order abstract syntax with parametric polymorphism. J. Funct. Program. 18(1), 87–140 (2008)
On the Meaning of Logical Completeness Michele Basaldella and Kazushige Terui Research Institute for Mathematical Sciences, Kyoto University, Kitashirakawa Oiwakecho, Sakyo-ku, Kyoto 606-8502, Japan {mbasalde,terui}@kurims.kyoto-u.ac.jp
Abstract. G¨ odel’s completeness theorem is concerned with provability, while Girard’s theorem in ludics (as well as full completeness theorems in game semantics) is concerned with proofs. Our purpose is to look for a connection between these two disciplines. Following a previous work [1], we consider an extension of the original ludics with contraction and universal nondeterminism, which play dual roles, in order to capture a polarized fragment of linear logic and thus a constructive variant of classical propositional logic. We then prove a completeness theorem for proofs in this extended setting: for any behaviour (formula) A and any design (proof attempt) P , either P is a proof of A or there is a model M of A⊥ which beats P . Compared with proofs of full completeness in game semantics, ours exhibits a striking similarity with proofs of G¨ odel’s completeness, in that it explicitly constructs a countermodel essentially using K¨ onig’s lemma, proceeds by induction on formulas, and implies an analogue of L¨ owenheim-Skolem theorem.
1
Introduction
G¨ odel’s completeness theorem (for first-order classical logic) is one of the most important theorems in logic. It is concerned with a duality (in a naive sense) between proofs and models: For every formula A, either
∃P (P A)
or
∃M (M |= ¬A).
Here P ranges over the set of proofs, M over the class of models, and P A reads “P is a proof of A.” One can imagine a debate on a general proposition A, where Player tries to justify A by giving a proof and Opponent tries to refute it by giving a countermodel. The completeness theorem states that exactly one of them wins. Actually, the theorem gives us far more insights than stated. Finite proofs vs infinite models: A very crucial point is that proofs are always finite, while models can be of arbitrary cardinality. Completeness thus implies L¨owenheim-Skolem and compactness theorems, leading to constructions of various nonstandard models.
Supported by JSPS Postdoctoral Fellowship for Foreign Researcher grant.
P.-L. Curien (Ed.): TLCA 2009, LNCS 5608, pp. 50–64, 2009. c Springer-Verlag Berlin Heidelberg 2009
On the Meaning of Logical Completeness
51
Nondeterministic principles: Any proof of G¨ odel’s completeness theorem relies on a strong nondeterministic principle such as K¨ onig’s or Zorn’s lemma, in contrast to the trivial completeness theorem with respect to the class of boolean algebras. Matching of two inductions: Provability is defined by induction on proofs, while truth by induction on formulas. The two inductions are somehow ascribed to the essence of syntax and semantics, respectively, and the completeness theorem states that they do match. Unlike the real debate, however, there is no interaction between proofs and models in G¨odel’s theorem. A more interactive account of completeness is given by Girard’s ludics ([12,13]; see [10,4] for good expositions). Ludics is a variant of game semantics, which has the following prominent features. Monism: Proofs and models are homogeneous entities, called designs. Existentialism: Behaviours (semantic types) are built from designs, in contrast to the ordinary game semantics (e.g., Hyland-Ong [14]) where one begins with the definition of arenas (types) and then proceeds to strategies (proofs). Normalization as interaction: Designs (hence proofs and models) interact together via normalization. It induces an orthogonality relation between designs in such a way that P ⊥M holds if the normalization of P applied to M converges. A behaviour A is defined to be a set of designs which is equivalent to its biorthogonal (A = A⊥⊥ ). In this setting, Girard shows a completeness theorem for proofs [13], which roughly claims that any “winning” design in a behaviour is a proof of it. In view of the interactive definition of behaviour, it can be rephrased as follows: For every (logical) behaviour A and every (proof-like) design P , either
P A
or
∃M (M |= A⊥ and M beats P ).
Here, “M |= A⊥ ” means M ∈ A⊥ , and “M beats P ” means P ⊥M . Hence in case P A, we may conclude P ∈ A⊥⊥ = A. Notice that M |= A⊥ no more entails absolute unprovability of A; it is rather relativized to each P and there is a real interaction between proofs and models. Actually, Girard’s original ludics is so limited that it corresponds to a polarized fragment of multiplicative additive linear logic, which is too weak to be a stand-alone logical system. As a consequence, one does not observe an opposition between finite proofs and infinite models, since one can always assume that the countermodel M is finite (related to the finite model property for MALL [15]). Indeed, the proof of the above completeness is easy once internal completeness (a form of completeness which does not refer to any proof system [13]) for each logical connective has been proved. In this paper, we employ a term syntax for designs introduced in [19], and extend Girard’s ludics with duplication (contraction) and its dual: universal nondeterminism (see [1] and references therein). Although our term approach disregards some interesting locativity-related phenomena (e.g., normalization as merging of orders and different sorts of tensors [13]), our calculus is easier to
52
M. Basaldella and K. Terui
manipulate and closer to the tradition of λ, λμ, λμ˜ μ, π-calculi and others. Our resulting framework is as strong as a polarized fragment of linear logic with exponentials ([4]; cf. also [16]), which is in turn as strong as a constructive version of classical propositional logic. We then prove the completeness theorem above in this extended setting. Our proof exhibits a striking similarity with Sch¨ utte’s proof of G¨ odel’s completeness theorem [18]. Given a (proof-like) design P which is not a proof of A, we explicitly construct a countermodel M in A⊥ which beats P , essentially using K¨onig’s lemma. Soundness is proved by induction on proofs, while completeness is by induction on types. Thus our theorem gives matching of two inductions. Finally, it implies an analogue of L¨ owenheim-Skolem theorem, which well illustrates the opposition between finite proofs and infinite models. In game semantics, one finds a number of similar full completeness results. However, the connection with G¨ odel’s completeness seems less conspicuous than ours. Typically, “winning” strategies in Hyland-Ong games most naturally correspond to B¨ ohm trees, which can be infinite (cf. [5]). Thus, in contrast to our result, one has to impose finiteness/compactness on strategies in an external and noninteractive way, in order to have a correspondence with finite λ-terms. Although this is also the case in [1], we show that such a finiteness assumption is not needed in ludics.
2 2.1
Designs Syntax
We first recall the term syntax for deterministic designs introduced by the second author [19]. We employ a process calculus notation inspired by the close relationship between ludics and linear π-calculus [11]. Designs are built over a given signature A = (A, ar), where A is a set of names a, b, c, . . . and ar : A −→ IN is a function which assigns to each name a its arity ar(a). Let V be a countable set of variables V = {x, y, z, . . .}. Over a fixed signature A, a (proper) positive action is a with a ∈ A, and a (proper) negative action is a(x1 , . . . , xn ) where variables x1 , . . . , xn are distinct and ar(a) = n. In the sequel, we assume that an expression of the form a(x) always stands for a negative action. The positive (resp. negative) deterministic designs P (resp. N ) are coinductively generated by the following grammar: P ::= Ω N0 |aN1 , . . . , Nn , N ::= x a(x).Pa , where ar(a) = n and x = x1 , . . . , xn . Intuitively, designs may be considered as infinitary λ-terms with named applications and superimposed abstractions. Specifically, a positive design N0 |aN1 , . . . , Nn can be thought of as iterated application N0 N1 · · · Nn of name a ∈ A, and a(x).Pa as iterated abstraction λx.Pa of name a ∈ A. A family {a(x).Pa }a∈A of abstractions indexed by A is
On the Meaning of Logical Completeness
53
then superimposed to form a negative design a(x).Pa . Each a(x).Pa is called its component. The reduction rule for designs conforms to this intuition: ( a(x).Pa ) |bN1 , . . . , Nn −→ Pb [N1 /x1 , . . . , Nn /xn ]. Namely, when the application is of name b, one picks up component b(x).Pb from {a(x).Pa }a∈A and applies β-reduction. Notice that any closed positive design P (i.e., a positive design without free variables) has one of the following forms: , Ω and ( a(x).Pa )|aN1 , . . . , Nn . The last design reduces to another closed one. Hence P eventually reduces to , or Ω or diverges. By stipulating that the normal form of P in the last case is Ω, we obtain a dichotomy between and Ω: the normal form of a closed positive design is either or Ω. As we shall see, this induces an orthogonality relation between positive and negative designs. We also use Ω to encode partial sums. Given a set α = {a(x), b(y), . . . } of negative actions, we write a(x).Pa + b(y ).Pb + · · · to denote the negative design a(x).Ra , where Ra = Pa if a(x) ∈ α, and Ra = Ω otherwise. Although [19] mainly deals with linear designs, there is no difficulty in dealing with nonlinear ones. To obtain completeness, however, we also need to incorporate the dual of nonlinearity, that is universal nondeterminism [1]. It is reminiscent of differential linear logic [8], which has nondeterministic sum as the dual of contraction; the duality is essential for the separation property [17] (see also [7] for separation of B¨ohm trees). It is also similar to the situation in Hyland-Ong game semantics [14], where nonlinear strategies for Player may contain a play in which Opponent behaves noninnocently; Opponent’s noninnocence is again essential for full completeness. Definition 1 (Designs). For a fixed signature A, a positive (resp. negative) design P (resp. N ) is a coinductively defined term given as follows: (positive designs) P ::= Ω I Qi Qi ::= N0 |aN , . . . , N (predesigns) 1 n N ::= x a(x).Pa (negative designs), where I Qi is built from a family {Qi }i∈I of predesigns with I an arbitrary index set. We indicate positive designs by P, Q, . . ., negative designs by N, M, . . ., and arbitrary ones by D, E, . . .. Any subterm E of D is called a subdesign of D. A design D may contain free and bound variables. An occurrence of subterm a(x).Pa binds the free-variables x in Pa . Variables which are not under the scope of the binder a(x) are free. We denote by fv(D) the set of free variables occurring in D. In analogy with λ-calculus, we always consider designs up to α-equivalence, that is up to renaming of bound variables (see [19] for further details). We also identify designs which only differ in indexing: I Pi = J Qj if there is a bijection σ : I −→ J such that Pi = Qσ(i) for every i ∈ I. The daimon is now defined to be the empty conjunction ∅. A unary con junction {i} Qi is simply written as Qi . Furthermore, the conjunction operator can be extended to positive and negative designs: for I, J disjoint sets of indices,
54
M. Basaldella and K. Terui
Q i∧ J Qi = I∪J Qi , a(x).Pa ∧ a(x).Qa = a(x).(Pa ∧ Qa ),
I
Ω ∧ P = Ω, x ∧ N = undefined.
In particular, we have P ∧ = P in contrast to [1], which distinguishes the two. By the above convention, conjunction of two positive designs is always defined. A cut is a predesign of the form ( a(x).Pa )|aN1 , . . . , Nn . Otherwise, a predesign is of the form x|aN1 , . . . , Nn and called a head normal form. The head variable x in the predesign above plays the same role as a pointer in a strategy does in Hyland-Ong games and an address (or locus) in Girard’s ludics. On the other hand, a variable x occurring in a bracket (as in N0 |aN1 , . . . , Ni−1 , x, Ni+1 , . . . , Nn ) does not correspond to a pointer nor address. Rather, it corresponds to an identity axiom (initial sequent) in sequent calculus, and for this reason is called an identity. If a negative design N simply consists of a variable x, then N is itself an identity. A design D is said: – total, if D = Ω; – linear (or affine), if for any subdesign of the form N0 |aN1 , . . . , Nn , the sets fv(N0 ), . . . , fv(Nn ) are pairwise disjoint; – deterministic, if in any occurrence of subdesign I Qi , I is either empty (and hence I Qi = ) or a singleton. Example 1 (Girard’s syntax). Girard’s original designs [13] can be expressed in our syntax by taking the signature G = (Pf in (IN), | |) where Pf in (IN) consists of finite subsets of IN and | | is the function that gives the cardinality to each I ∈ Pf in (IN). Girard’s designs correspond to total, deterministic, linear, cut-free and identity-free designs over the signature G. See [19] for more details. 2.2
Normalization
Ludics is an interactive theory. This means that designs, which subsume both proofs and models, interact together via normalization, and types (behaviours) are defined by the induced orthogonality relation. Several ways to normalize designs have been considered in the literature: abstract machines [3,9,6,1], abstract merging of orders [13], and terms reduction [19]. Here we actually extend the last solution. As in pure λ-calculus, normalization is notnecessarily terminating, but in our setting a new difficulty arises: the operator . We define the normal forms in two steps, first giving a reduction rule which finds conjunctions of head normal forms whenever possible, and then expanding /x] denote the simultaneous and capture-free it corecursively. As usual, let D[N substitution of N = N1 , . . . , Nn for x = x1 , . . . , xn in D. Definition 2 (Reduction relation −→). The reduction relation −→ is defined over the set of positive designs as follows: −→ Q ∧ Pb [N /x]. Ω −→ Ω, Q∧ a(x).Pa | bN We denote by −→∗ the transitive closure of −→.
On the Meaning of Logical Completeness
55
Example 2. Let N = a(x). + b(x).(x|ax ∧ x|by ). Then: N |aw −→ , N |bw −→ w|aw ∧ w|by , N |cw −→ Ω. Given two positive designs P, Q, we write P ⇓ Q and read “P converges to Q” if P −→∗ Q and Q is a conjunction of head normal forms (including the case Q = ). We write P ⇑ and read “P diverges” otherwise (typically when P −→∗ Ω). Notice that the above reduction relation is completely deterministic. Alternatively, a nondeterministic one can be defined over predesigns and Ω as follows. Given predesigns P0 , R0 (which can also be seen as positive designs P , R R0 if P0 −→ Q ∧ R0 for some positive design 0 {0} {0} 0 ), we write P0 − Q. We also write Ω− Ω, and P0 − Ω if P0 −→ Ω. Then it is easy to see that P0 converges if and only if all nondeterministic reduction sequences from P0 are finite. Thus our nondeterminism is universal rather than existential. Definition 3 (Normal form). The normal form function : D −→ D is defined by corecursion as follows: i if P ⇓ P = I xi |ai N I xi |ai Ni ; = Ω if P ⇑; x = x. a(x).Pa = a(x).Pa ; Notice that the dichotomy in the closed case is maintained: for any closed positive design P , P is either or Ω. Theorem 1 (Associativity) D[N1 /x1 , . . . , Nn /xn ] = D[N1 /x1 , . . . , Nn /xn ].
3 3.1
Behaviours Orthogonality
In the rest of this work, we restrict ourselves to a special subclass of designs: namely, we consider only total, cut-free and identity-free designs. Restriction to identity-free designs is not a serious limitation, since identities can be replaced by suitable infinitary identity-free designs (namely, their infinite η expansions, called faxes in [13]). A proof of this fact is given in [19]. Since we work in a cut-free setting, we can simplify our notation: we often identify an expression like D[N/x] with its normal form D[N/x]. Thus, we improperly write D[N/x] = E rather than D[N/x] = E. Definition 4 (Orthogonality). A positive design P is closed if fv(P ) = ∅, atomic if fv(P ) ⊆ {x0 } for a certain fixed variable x0 . A negative design N is atomic if fv(N ) = ∅. Two atomic designs P, N of opposite polarities are said orthogonal and written P ⊥N when P [N/x0 ] = . If X is a set of atomic designs of the same polarity, then its orthogonal set, denoted by X⊥ , is defined by X⊥ := {E : ∀D ∈ X, D⊥E}.
56
M. Basaldella and K. Terui
The meaning of can be clarified in terms of orthogonality. For designs D, E of the same polarity, define D E iff {D}⊥ ⊆ {E}⊥ . D E means that E has more chances of convergence than D when interacting with other designs. The following is easy to observe. Proposition 1. is a preorder. Moreover, we have D ∧ E D and D D ∧ D for any designs D, E of the same polarity. In particular, P = P ∧ for any positive design P . This justifies our identification of with the empty conjunction ∅. Although possible, we do not define orthogonality for nonatomic designs. Accordingly, we only consider atomic behaviours which consist of atomic designs. Definition 5 (Behaviour). An (atomic) behaviour X is a set of atomic designs of the same polarity such that X⊥⊥ = X. A behaviour is positive or negative according to the polarity of its designs. We denote positive behaviours by P, Q, R, . . . and negative behaviours by N, M, K . . . . There are the least and the greatest behaviours among all positive (resp. negative) behaviours with respect to set inclusion: 0+ := {}, 0− := {− },
+ := 0−⊥ , − := 0+⊥ ,
(− =
a(x).).
We now introduce the contexts of behaviours, which corresponds to sequents of behaviours in [13]. Definition 6 (Contexts of behaviours). A positive context Γ is of the form x1 : P1 , . . . , xn : Pn , where x1 , . . . , xn are distinct variables and P1 , . . . , Pn are (atomic) positive behaviours. We denote by fv(Γ) the set {x1 , . . . , xn }. A negative context Γ, N is a positive context Γ enriched with an (atomic) negative behaviour N, to which no variable is associated. We define: – P |= x1 : P1 , . . . , xn : Pn if fv(P ) ⊆ {x1 , . . . , xn } and ⊥ P [N1 /x1 , . . . , Nn /xn ] = for any N1 ∈ P⊥ 1 , . . . , Nn ∈ Pn . – N |= x1 : P1 , . . . , xn : Pn , N if fv(N ) ⊆ {x1 , . . . , xn } and ⊥ ⊥ P [N [N1 /x1 , . . . , Nn /xn ]/x0 ] = for any N1 ∈ P⊥ 1 , . . . , Nn ∈ Pn , P ∈ N . Clearly, N |= N iff N ∈ N, and P |= y : P iff P [x0 /y] ∈ P. Furthermore, associativity (Theorem 1) implies the following quite useful principle: Lemma 1 (Closure principle). P |= Γ, x : P if and only if P [N/x] |= Γ for any N ∈ P⊥ . N |= Γ, N if and only if P [N/x0 ] |= Γ for any P ∈ N⊥ . 3.2
Logical Connectives
We next describe how behaviours are built by means of logical connectives in ludics. Let us assume that the set of variables V is equipped with a fixed linear order x0 , x1 , x2 . . ..
On the Meaning of Logical Completeness
57
Definition 7 (Logical connectives). An n-ary logical connective α is a finite set of negative actions a1 (x1 ), . . . , am (xm ) such that the names a1 , . . . , am are distinct and the variables x1 , . . . , xm are taken from {x1 , . . . , xn }. Given a name a, an n-ary logical connective α and behaviours N1 , . . . , Nn , P1 , . . . , Pn we define: aN1 , . . . , Nm := {x0 |aN1 , . . . , Nm : N1 ∈ N1 , . . . , Nm ∈ Nm }, ⊥⊥ αN1 , . . . , Nn := aN , . . . , N , i i 1 m a( x)∈α ⊥ ⊥ α(P1 , . . . , Pn ) := αP⊥ 1 , . . . , Pn ,
where the indices i1 , . . . , im ∈ {1, . . . , n} are determined by the vector x = xi1 , . . . , xim given for each a(x) ∈ α. In terms of linear logic, the cardinality of the connective α corresponds to the additive arity while the arity of each name to the multiplicative arity. Example 3 (Linear logic connectives). Usual linear logic connectives can be defined by logical connectives , &, ↑ , ⊥, below; we also give some shorthand notations for readability. &
⊗ := , ⊕ := &, ↓ := ↑ , := ∅, &
:= {℘(x1 , x2 )}, & := {π1 (x1 ), π2 (x2 )}, ↑ := {↑ (x1 )}, ⊥ := {∗},
• := ℘, ιi := πi , ↓ := ↑, (∗ 0-ary name).
&
We do not have exponentials here, because we are working in a nonlinear setting so that they are already incorporated into the connectives. With these logical connectives we can built (semantic versions of) usual linear logic types (we use infix notations such as N ⊗ M rather than the prefix ones ⊗N, M ). P Q = •P⊥ , Q⊥ ⊥ , P & Q = ι1 P⊥ ⊥ ∩ ι2 Q⊥ ⊥ , ↑ P = ↓ P⊥ ⊥ , ⊥ = 1⊥ , = ∅⊥ . &
N ⊗ M = •N, M ⊥⊥ , N ⊕ M = (ι1 N ∪ ι2 M )⊥⊥ , ↓ N = ↓ N ⊥⊥ , 1 = {x0 |∗}⊥⊥ , 0 = ∅⊥⊥ ,
The next theorem illustrates a special feature of behaviours defined by logical connectives. It also suggests that nonlinearity and universal nondeterminism play dual roles. Theorem 2. Let P be an arbitrary positive behaviour. 1. P |= x1 : P, x2 : P =⇒ P [x0 /x1 , x0 /x2 ] ∈ P. 2. N ∧ M ∈ P⊥ =⇒ N ∈ P⊥ and M ∈ P⊥ . the converses of 1. ( duplicability) and 2.( closure under Moreover, if P = αN , ) hold.
58
M. Basaldella and K. Terui
Proof. 1. Let N ∈ P⊥ . Then P [N/x1 , N/x2 ] = by assumption. Hence P [x0 /x1 , x0 /x2 ][N/x0 ] = , and so P [x0 /x1 , x0 /x2 ] ∈ P⊥⊥ = P. 2. Because of N ∧ M N, M (Proposition 1). ⊥ . To prove N ∧M ∈ P⊥ , it is sufficient Closure under . Let N, M ∈ P⊥ = αN ∈ to show that N ∧M is orthogonal to any x0 |aK a( x)∈α aNi1 , . . . , Nim . But = since x0 occurs only once at the head position, it boils down to N ∧ M |aK = and M |aK = . , which is an easy consequence of N |aK Duplicability. Let P [x0 /x1 , x0 /x2 ] ∈ P = αN . It suffices to show that P [N/x1 , M/x2 ] = holds for any N, M ∈ P⊥ . But we have just proven that N ∧M ∈ P⊥ , and so P [x0 /x1 , x0 /x2 ][N ∧ M/x0 ] = P [N ∧ M/x1 , N ∧ M/x2 ] = . Since N ∧ M N, M by Proposition 1, we have P [N/x1 , M/x2 ] = . Remark 1. Theorem 2 can be considered as an (internal, monistic) form of soundness and completeness for the contraction rule: soundness corresponds to point 1. whereas completeness to its converse (duplicability). 3.3
Internal Completeness
In [13], Girard proposes a purely monistic, local notion of completeness, called internal completeness. It means that we can give a precise and direct description to the elements in behaviours (built by logical connectives) without using the orthogonality and without referring to any proof system. Negative logical connectives easily enjoy internal completeness: Theorem 3 (Internal Completeness (negative case)). α(P1 , . . . , Pn ) = { a(x).Pa : Pa |= xi1 : Pi1 , . . . , xim : Pim for every a(x) ∈ α}, where the indices i1 , . . . , im are determined by the vector x = xi1 , . . . , xim . In the above, Pb can be arbitrary when b(x) ∈ / α. Thus our approach is “immaterial” in that we do not consider incarnations and material designs. For example, we have P & Q = {π1 (x1 ).P + π2 (x2 ).Q + · · · : P |= x1 : P and Q |= x2 : Q} = {π1 (x0 ).P + π2 (x0 ).Q + · · · : P ∈ P and Q ∈ Q}, where the irrelevant components of the sum are suppressed by “· · · .” Up to incarnation (i.e. removal of irrelevant part), P & Q, which has been defined by intersection, is isomorphic to the cartesian product of P and Q: a phenomenon called mystery of incarnation in [13]. As to positive connectives, [13] proves internal completeness theorems for additive and multiplicative ones separately in the linear and deterministic setting. They are integrated in [19] as follows: Theorem 4 (Internal completeness (linear, positive case)). When the universe of designs is restricted to linear and deterministic ones, we have
On the Meaning of Logical Completeness
αN1 , . . . , Nn =
59
aNi1 , . . . , Nim ∪ {}.
a( x)∈α
However, this is no more true with nonlinear designs. A counterexample is given below. Example 4. Let us consider the behaviour P := ↓ ↑↑ (0+ ) = ↓ ↑↑ (0+ ) ⊥⊥ . By construction, the design P0 := x0 | ↓ ↑ (x1 ). belongs to P, but then, also any design of the form 0 | ↓ ↑ (x1 ).Pn belongs to P. Too see this, note Pn+1 := x⊥ that any N = a(x).Pa ∈ P hascomponent of the form ↑ (y).y| ↓ M with M arbitrary (more precisely, ↑ (y). I y| ↓ Mi for some I with Mi arbitrary). Hence we have Pn+1 [N/x0 ] = N | ↓ ↑ (x1 ).Pn [N/x0 ] = (↑ (x1 ).Pn [N/x0 ]) | ↓ M = Pn [N/x0 ]; P0 [N/x0 ] = . This proves Pn+1 ∈ P. However, Pn+1 ∈ / ↓ ↑↑ (0+ ) , since ↑ (x1 ).Pn is not atomic + and so cannot belong to ↑ (0 ). This motivates us to directly prove completeness for proofs, rather than deriving it from internal completeness as in the original work [13]; internal completeness for positives will be further discussed in our subsequent work. In [1] a weaker form of internal completeness is proved, which is enough to derive a weaker form of full completeness: all finite “winning” designs are interpretations of proofs. While such a finiteness assumption is quite common in game semantics, we will show that it can be avoided in ludics.
4 4.1
Proof System and Completeness for Proofs Proof System
We will now introduce a proof system. In our system, logical rules are automatically generated by logical connectives. Since the set of logical connectives vary for each signature A, our proof system is parameterized by A. If one chooses A rich enough, the constant-only fragment of polarized linear logic ([4]; cf. also [16]) can be embedded. In the sequel, we focus on logical behaviours, which are composed by using logical connectives only. Definition 8 (Logical behaviours). A behaviour is logical if it is inductively built as follows (α denotes an arbitrary logical connective): P := αN1 , . . . , Nn ,
N := α(P1 , . . . , Pn ).
Notice that the orthogonal of a logical behaviour is again logical. As advocated in the introduction, our monistic framework renders both proofs and models as homogeneous objects: designs. Definition 9 (Proofs, Models). A proof is a design in which all the conjunctions are unary. In other words, a proof is a deterministic and -free design. A model is an atomic linear design (in which conjunctions of arbitrary cardinality may occur).
60
M. Basaldella and K. Terui
Given a design D, let ac+ (D) be the set of occurrences of proper positive actions a in D. The cardinality of D is defined to be the cardinality of ac+ (D). Notice that a proof in the above sense can be infinite, so might not “prove” anything. Hence it might be better called a “proof attempt” or “untyped proof.” A positive (resp. negative) sequent is of the form P Γ (resp. N Γ, N) where P is a positive proof (resp. N is a negative proof) and Γ is a positive context (see Definition 6) of logical behaviours such that fv(P ) ⊆ fv(Γ) (resp. fv(N ) ⊆ fv(Γ)). Intuitively, a sequent D Γ should be understood as a claim that D is a proof of Γ, or D is of type Γ. Our proof system consists of three types of inference rules: positive (α, a), negative (α), and cut. M1 Γ, Ni1
...
Mm Γ, Nim (z : αN1 , . . . , Nn ∈ Γ) (α, a) z|aM1 , . . . , Mm Γ
a }a(x)∈α {Pa Γ, x : P a(x).Pa Γ, α(P1 , . . . , Pn )
(α)
P Γ, z : P N Δ, P⊥ (cut) P [N/z] Γ, Δ
with the proviso: – In the rule (α, a), a(x) ∈ α, x = xi1 , . . . , xim , and i1 , . . . , im ∈ {1, . . . , n}. a stands for xi1 : Pi1 , . . . , xim : Pim . A component b(y ).Pb – In (α), x : P of a(xa ).Pa can be arbitrary when b(y ) ∈ α. Hence we again take an “immaterial” approach. It is also possible to adopt a “material” approach by requiring Pb = Ω when b(y) ∈ α. Then a proof D is finite (i.e., ac+ (D) is a finite set) whenever D Γ is derivable for some Γ. Thus, as in ordinary sequent calculi, our proof system accepts only essentially finite proofs for derivable sequents (i.e., finite up to removal of irrelevant part). For linear logic connectives, the positive and negative rules specialize to the following (taking the “material” approach):
M Γ, Ni (z : N1 ⊕ N2 ∈ Γ) (⊕, ιi ) z|ιi M Γ (z : 1 ∈ Γ) (1) z|∗ Γ
4.2
P Γ, x1 : P1 , x2 : P2 ( ℘(x1 , x2 ).P Γ, P1 P2 &
M2 Γ, N2 (z : N1 ⊗ N2 ∈ Γ) (⊗, •) z| • M1 , M2 Γ
&
M1 Γ, N1
)
P1 Γ, x1 : P1 P2 Γ, x2 : P2 (&) π1 (x1 ).P1 + π2 (x2 ).P2 Γ, P1 & P2
P Γ (⊥ ⊥) ∗.P Γ, ⊥
a( x).Ω Γ,
(
)
Completeness for Proofs
We now prove soundness and completeness for proofs. In the statement of the theorem below, “D Γ” means that the sequent D Γ is derivable in our proof system.
On the Meaning of Logical Completeness
61
Theorem 5 (Soundness). D Γ =⇒ D |= Γ. Proof. By induction on the derivation of D Γ, using Lemma 1 (the closure principle) and Theorem 2 (1). Theorem 6 (Completeness for proofs). For every positive logical behaviour P and every proof P (see Definition 9), P |= x : P =⇒ P x : P. Similarly for the negative case. The proof below is analogous to Sch¨ utte’s proof of G¨ odel’s completeness theorem [18], which proceeds as follows: 1. Given an unprovable sequent P, find an open branch in the cut-free proof search tree. 2. From the open branch, build a countermodel M in which P is false. We can naturally adapt 1. to our setting, since the bottom-up cut-free proof search in our proof system is deterministic in the sense that at most one rule applies at each step. Moreover, it never gets stuck at the negative sequent, since a negative rule is always applicable bottom-up. Suppose now that P x : P does not have a derivation. Our goal is to build c(Px ). a model c(Px ) ∈ P⊥ such that P ⊥ By K¨ onig’s Lemma, there exists a branch in the cut-free proof search tree, .. .. N1 Ξ1 P1 Θ1 N0 Ξ0 P0 Θ0 , with P0 = P and Θ0 = x : P, which is either finite and has the topmost sequent Pmax Θmax with max ∈ IN to which no rule applies anymore, or infinite. In the latter case, we set max = ∞. Without loss of generality, we assume that each variable is associated to at most one behaviour. Namely, if x : P and x : Q occur in the branch, we have P = Q (an assumption needed for Lemma 2 (2)). We first consider the former case (max < ∞) and illustrate how to build a model c(Pi ) for 0 ≤ i ≤ max by means of concrete examples. The construction proceeds by downward induction from max to 0. (i) When Pmax = Ω, let c(Pmax ) = − (= a(x).). (ii) Suppose for in Γ, z : M ⊗ K but a = • so stance that Pmax Θmax is of the form z|aM that the proof search gets stuck. Then let c(Pmax ) = ℘(xl , xr ).. (iii) Suppose that we have constructed c(Pj ) for i + 1 ≤ j ≤ max, and the relevant part of the branch is of the form:
M. Basaldella and K. Terui
.. .. Pi+1 Θi+1 Ni Ξi Pi . Θi .. .
.. .. Pi+1 Γ, x : P, y : Q = ℘(x, y).Pi+1 Γ, P Q z| • ℘(x, y).Pi+1 , M Γ .. .. &
62
,
where Γ contains z : (P Q) ⊗ M. Let: c(Px ) = {c(Pj ) : i < j ≤ max, Pj has head variable x} c(Pi ) = ℘(xl , xr ).xl | • c(Px ), c(Py ) . Here, c(Pi ) begins with ℘(xl , xr ).xl rather than ℘(xl , xr ).xr , because the branch goes up to the left direction, choosing the left subformula P Q. When none of Pj (i < j ≤ max) has head variable x, we set c(Px ) = − . Next consider the case max = ∞. We first define cn (Pi ) for every n, i < ∞. Let cn (Pi ) = − for i > n. For 0 ≤ i ≤ n, we build cn (Pi ) by downward induction on i from n to 0, using (iii) above. When n → ∞, each cn (Pi ) grows in the sense that each conjunction obtains more and more conjuncts. This allows us to define c(Pi ) for each i by taking the “limit” limn→∞ cn (Pi ), which is roughly speaking the “union” c(Pi ) = n<∞ cn (Pi ) (cf. [19] for the union of designs). c(Px ) for each variable x is similarly defined. Observe that each c(Pi ) and c(Px ) thus constructed are surely models, i.e., atomic linear designs. Theorem 6 is a direct consequence of the following two lemmas. &
&
Lemma 2. For Pi Θi appearing in the branch, suppose that the head variable of Pi is z and z : R ∈ Θi . Then (1) c(Pi ) ∈ R⊥ , and (2) c(Pz ) ∈ R⊥ . Proof. By induction on R. (1) When i = max and the case (ii) applies, we have ℘(xl , xr ). ∈ (M ⊗ K)⊥ by internal completeness for negatives (Theorem 3). Suppose that the case (iii) applies to Pi Θi . Then c(Pi ) = ℘(xl , xr ).xl | • c(Px ), c(Py ) . By induction hypothesis (2), we have c(Px ) ∈ P⊥ and c(Py ) ∈ Q⊥ . Hence x0 | • c(Px ), c(Py ) ∈ P⊥ ⊗ Q⊥ = (P Q)⊥ . Since xl , xr are not free in c(Px ), c(Py ), we have xl | • c(Px ), c(Py ) |= xl : (P Q)⊥ , xr : M⊥ . Hence by Theorem 3, ℘(xl , xr ).xl | • c(Px ), c(Py ) ∈ (P Q)⊥ M⊥ = ((P Q) ⊗ M)⊥ . (2) Follows from (1) since R⊥ is closed under (Theorem 2). &
&
& &
&
Lemma 3. Suppose that the head variable of P0 is x. Then we have P0 ⊥ c(Px ). Proof. We first prove that there is a nondeterministic reduction sequence Pi [c(Pv1 )/v1 , . . . , c(Pvm )/vm ]− ∗ Pi+1 [c(Pw1 )/w1 , . . . , c(Pwn )/wn ] for any i < max, where v and w are the free variables of Pi and Pi+1 , respectively. Suppose that Pi is as in the case (iii) above. By writing [θ] for [c(Pv1 )/v1 , . . . , c(Pvm )/vm ] and noting that c(Pz ) contains c(Pi ) = ℘(xl , xr ).xl | • c(Px ), c(Py ) as conjunct, we have Pi [θ] = c(Pz )| • ℘(x, y).Pi+1 [θ], M [θ] − (℘(x, y).Pi+1 [θ])| • c(Px ), c(Py ) − Pi+1 [θ, c(Px )/x, c(Py )/y],
On the Meaning of Logical Completeness
63
as desired. When max = ∞, we have obtained an infinite reduction sequence from P0 [c(Px )/x]. Otherwise, we have P0 [c(Px )/x]− ∗ Pmax [θ]. In case (i), [θ] − Ω, because c(Pz ) conPmax [θ] = Ω. In case (ii), Pmax [θ] = c(Pz )|aM tains c(Pmax ) = ℘(xl , xr ). + a(x).Ω + · · · as conjunct. This establishes the proof of Theorem 6. Our explicit construction of the model c(Px ) yields a byproduct. Corollary 1 (Downward L¨ owenheim-Skolem, Finite model property). Let P be a proof and P a logical behaviour. If P ∈ P, then there is a countable M. model M ∈ P⊥ (i.e., ac+ (M ) is a countable set) such that P ⊥ Furthermore, when P is linear, there is a finite (and deterministic) model M. M ∈ P⊥ such that P ⊥ The last statement is due to the observation that when P is linear the positive rule (α, a) can be replaced with a linear variant: M1 Γ1 , Ni1 . . . Mm Γm , Nim z|aM1 , . . . , Mm Γ, z : αN1 , . . . , Nn , where Γ1 , . . . , Γm are disjoint subsets of Γ. We then immediately see that the proof search tree is always finite, and so is the model c(Px ).
5
Conclusion
We have presented a G¨odel-like completeness theorem for proofs in the framework of ludics, aiming at linking completeness theorems for provability with those for proofs. We have explicitly constructed a countermodel against any failed proof attempt, following Sch¨ utte’s idea based on cut-free proof search. Our proof employs K¨ onig’s lemma and reveals a sharp opposition between finite proofs and infinite models, leading to a clear analogy with L¨owenheim-Skolem theorem. In Hyland-Ong game semantics, Player’s “winning” strategies most naturally correspond to possibly infinite B¨ ohm trees (cf. [5]). One could of course impose finiteness/compactness on them to have correspondence with finite proofs. But it would not lead to an explicit construction of Opponent’s strategies beating infinite proof attempts. Although finiteness is imposed in [1] too, our current work shows that it is not necessary in ludics. Our work also highlights the duality: proof model deterministic, nonlinear nondeterministic, linear The principle is that when proofs admit contraction, models have to be nondeterministic (whereas do not have to be nonlinear). A similar situation arises, e.g. in [7,17], when one proves the separation property (an analogue of B¨ ohm’s theorem [2]), stating that two distinct terms can be distinguished via interaction
64
M. Basaldella and K. Terui
with a suitable context. Indeed, our construction of countermodels is based on the B¨ohm out technique that is also crucial for proving separation. To prove the separation property in our setting, however, a more delicate treatment of the conjunction would be required (e.g., D and D ∧ D cannot be separated since {D}⊥ = {D ∧ D}⊥ ). Acknowledgements. We are deeply indebted to Pierre-Louis Curien, who pointed out a gap in an earlier draft of this paper. Our thanks are also due to the anonymous referees.
References 1. Basaldella, M., Faggian, C.: Ludics with repetitions (exponentials, interactive types and completeness). To appear in LICS (2009) 2. B¨ ohm. C.: Alcune propriet` a delle forme β − η-normali nel λ− K-calcolo. Publicazioni dell’Istituto per le Applicazioni del Calcolo 696 (1968) 3. Curien, P.-L.: Abstract B¨ ohm trees. Mathematical Structures in Computer Science 8, 559–591 (1998) 4. Curien, P.-L.: Introduction to linear logic and ludics, part II. CoRR abs/cs/0501039 (2005) 5. Curien, P.-L.: Notes on game semantics (manuscript, 2006) 6. Curien, P.L., Herbelin, H.: Abstract machines for dialogue games. CoRR abs/0706.2544 (2007) 7. Dezani-Ciancaglini, M., Intrigila, B., Venturini-Zilli, M.: B¨ ohm’s theorem for B¨ ohm trees. In: ICTCS 1998, pp. 1–23 (1998) 8. Ehrhard, T., Regnier, L.: Differential interaction nets. Theor. Comput. Sci. 364, 166–195 (2006) 9. Faggian, C.: Travelling on designs. In: Bradfield, J.C. (ed.) CSL 2002 and EACSL 2002. LNCS, vol. 2471, pp. 427–441. Springer, Heidelberg (2002) 10. Faggian, C.: Interactive observability in ludics: The geometry of tests. Theor. Comput. Sci. 350, 213–233 (2006) 11. Faggian, C., Piccolo, M.: Ludics is a model for the finitary linear pi-calculus. In: Della Rocca, S.R. (ed.) TLCA 2007. LNCS, vol. 4583, pp. 148–162. Springer, Heidelberg (2007) 12. Girard, J.-Y.: On the meaning of logical rules I: syntax vs. semantics. In: Berger, U., Schwichtenberg, H. (eds.) Computational Logic, pp. 215–272. Springer, Heidelberg (1999) 13. Girard, J.-Y.: Locus solum: From the rules of logic to the logic of rules. Mathematical Structures in Computer Science 11, 301–506 (2001) 14. Hyland, J.M.E., Ong, C.H.L.: On full abstraction for PCF: I, II, and III. Inf. Comput. 163, 285–408 (2000) 15. Lafont, Y.: The finite model property for various fragments of linear logic. J. Symb. Log. 62, 1202–1208 (1997) 16. Laurent, O.: Polarized games. Ann. Pure Appl. Logic 130, 79–123 (2004) 17. Mazza, D., Pagani, M.: The separation theorem for differential interaction nets. In: Dershowitz, N., Voronkov, A. (eds.) LPAR 2007. LNCS, vol. 4790, pp. 393–407. Springer, Heidelberg (2007) 18. Sch¨ utte, K.: Ein System des Verkn¨ upfenden Schliessens. Archiv. Math. Logic Grundlagenf. 2, 55–67 (1956) 19. Terui, K.: Computational ludics. To appear in Theor. Comput. Sci. (2008)
Thick Subtrees, Games and Experiments Pierre Boudes Laboratoire d’Informatique de l’université Paris-Nord UMR CNRS 7030 Institut Galilée – Université Paris-Nord 99, avenue Jean-Baptiste Clément 93430 Villetaneuse – France
[email protected]
Abstract. We relate the dynamic semantics (games, dealing with interactions) and the static semantics (dealing with results of interactions) of linear logic with polarities, in the spirit of Timeless Games [1]. The polarized game semantics is full and faithfull for polarized proof-nets [2]. We detail the correspondence between cut free proof-nets and innocent strategies, in a framework related to abstract Böhm trees. A notion of thick subtree allows us to reveal a deep relation between plays in games and Girard’s experiments on proof-nets. We then define a desequentializing operation, forgetting time in games which coincides with the usual way of computing a result of interaction from an experiment. We then obtain our main result: desequentializing the game interpretation of a polarized proof-net yields its standard relational model interpretation (static semantics).
1 Introduction Denotational semantics interprets a program (a proof or a λ-term) as a structure representing all its possible interactions (via cut elimination or via β-reduction) with others programs. In static semantics only the result of the interaction is represented. In dynamic semantics (games) an interaction is fully represented by a sequence (play) of actions (moves) of the program (the Player) and the environment (the Opponent). There are many references for game semantics. For an introduction, see [3]. In this paper, we use Hyland-Ong style polarized games [4]. In such games, a move can justify itself by pointing to a preceding move. Laurent proved that polarized game semantics is full and faithful [2], for the proof-nets of LLpol the polarized fragment of linear logic (expressive enough to encode simply-typed λ-calculus). Proof-nets have been introduced together with linear logic [5] as a more parallel syntax than sequent calculus. Experiments on proof-nets (see ([6] for an extensive study) provide the same denotations as the categorical interpretation of the corresponding sequent calculus proofs. The static interpretation of a proof-net is the set of results of experiments on this proof-net. The comparison between static and dynamic semantics is strongly motivated by Ehrhard’s result ([7]) stating that the extensional collapse of sequential algorithms
Work partially supported by project NOCoST (ANR, JC05_43380).
P.-L. Curien (Ed.): TLCA 2009, LNCS 5608, pp. 65–79, 2009. c Springer-Verlag Berlin Heidelberg 2009
66
P. Boudes
(a game model) is the hypercoherences semantics (a static semantics). In [8], by introducing a suitable game semantics (extensional games), P.-A. Mellies gives a finegrained analysis of this result which better details the extensional content of games. We focus here on providing a simple mathematical framework suitable for a direct extraction of the static semantics from the dynamic one. The relational model is the generic static semantics of linear logic, in the sense that the others are generally derived from this one by introducing new ingredients (like various coherence relations, see [9]). In that very simple semantics, formulæ are sets and proofs are relations. A naive approach to the comparison is to consider an operation D which maps a play (an interaction) to Syntax an element in a set of results, as in Figure 1. The diffigames D static semantics culties are then: (i) to build a static semantics with sets play result of results (a natural candidate is the relational model); (ii) to turn D into a logical map, i.e. such that the diFig. 1. Projection D agram commutes for proofs. This approach is successfully used in [1], by introducing a new static semantics, the (bi)-polarized pointed relational model, and in [10], by introducing a new game semantics, bordered games where plays explicitly carry results of interactions. In this paper, we clarify the relation between syntax, static and dynamic semantics, without using models specially designed for the purpose of the projection. We introduce a desequentialization D of justified plays, for which the source is Laurent’s polarized games, and the target is the standard relational model of linear logic. The desequentialization maps a play to the tree of its justification pointers (which is a thick subtree of the formula, see below). The desequentialization introduced here may be used in future works to push some properties of game semantics through the time forgetful projection D or conversely to pull some conditions of the static semantics at the games level. In polarized games, proofs are interpreted as finite innocent strategies. Such strategies can be presented as finite trees of Player’s views. Trees of P-views are particular instances of abstract Böhm trees ([11,12]). When it comes from the interpretation of a proof, a tree of P-views can be thought of as an abstract presentation of the Böhm tree of a simply typed λ-term. (Pointers represent variables binding). Since the polarized game semantics is full and faithful, trees of P-views are in a bijective correspondence with cut free polarized proof-nets of the same type. By analyzing the shape of cut free proof-nets, we detail this correspondence Ψ in a very direct way (comparatively to [2]). To do so, we restrict ourselves to the additive free fragment MELLpol of LLpol. This minimize the complexity of the definition of proof-nets, at a low cost, since additives can (almost) be encoded in MELLpol. Here is a sketch of the correspondence Ψ . Obviously, the Reader unfamiliar with proof-nets and games will find the definitions in the body of the paper. A tree of P-views φ is a finite tree tφ , together with two more datum: a naming fφ of nodes by moves (a node is an occurrence of a move) and a relation ← φ on nodes specifying justification pointers between moves.
Thick Subtrees, Games and Experiments
67
MELLpol proof-nets Ψ
polarized games
D−
trees of P-views (Böhm trees) D
D+ relational model
Fig. 2. Desequentialization
A MELLpol proof-net π is also a finite tree Tπ (the tree representing the nesting of !-boxes) but together with: a labeling Rπ of nodes by flat proof structures (which are finite oriented graphs with pending edges) and a structure (Sπ , Bπ ) relating flat proof structures to each others (the frontiers of the !-boxes). When π is in normal form (cut free) and φ is the strategy interpreting π, the correspondence Ψ establishes a tree isomorphism between Tπ (the !-boxes tree) and the tree of P-views tφ . Moreover each flat proof structure of π has a very particular shape: it only consists of one combined positive connective (a tensor of of course) and one combined negative connective (a par of why not) together with edges connecting them or going through the frontiers of !-boxes. Through Ψ , moves of tφ correspond to these combined connectives and pointers are just another way to draw the connecting edges. We introduce in Section 2 the core ingredient of the paper: the notion of thick subtree, a generalization of the usual notion of rooted subtree. We use thick subtrees both at the term level and at the type level. The desequentialization relates the two levels. Type level (Section 3). A MELLpol formula A can be thought of as a tree: its arena in games. The desequentialization of a play in A is a particular thick subtree of A. And there is a (bijective) encoding of thick subtrees of A into the set of results of type A. Term level (Section 4). Thick subtrees are used at the term level both to represent experiments in proof-nets and to express the intrinsic dynamic of plays of a strategy. The desequentialization D factors into a negative part D− followed by a positive part + D (Fig.2). If p is a play in an innocent strategy φ then D− (p) is a thick subtree s of tφ . Conversely, any thick subtree t of tφ can be lifted into many plays in φ. This is just a matter of extending the tree order of s into a well-shaped total order. Intuitively, the tree order of s corresponds to the internal dynamic of the program (positive/Player) that one will find in any interaction between this program and an environment. The new part of the order is then provided by the environment (negative/Opponent) during a possible interaction. An experiment e in a proof-net π is just a thick subtree s of Tπ , together with an arbitrary valuation v of axioms. By extending the correspondence Ψ between proof-nets and trees of P-views to their thick subtrees, we show that the positive desequentialization D+ of s (together with v) is the result of the experiment e. This proves that the desequentialization is a functor which maps a finite innocent strategy (a set of plays) to the static interpretation of the corresponding proof-net. Figure 2 sketches the full picture we then obtain.
68
P. Boudes
2 Trees and Thick Subtrees (2.a) Trees. Let us recall some basis definition about trees. A finite tree t is a partial order (It , ≤t ), where It is a finite set, called here the indexing set, having a least element (the root), and such that if a ≤t c and b ≤t c then a ≤t b or b ≤t a. In the sequel, trees will all be finite. The associated precedence relation is denoted by <1t (so a <1t b means that a
3 Types Formulæ of multiplicative exponential linear logic with polarities (MELLpol) are given by: N := ?X ⊥ | ⊥ | N N | ?P P := !X | 1 | P ⊗ P | !N
(negative formulæ) (positive formulæ)
with the usual De Morgan laws for the orthogonal (−)⊥ and where X is any element of a given set of atoms V. Here, as in [2], atoms (X, X ⊥ ) are not formulæ. This restriction is necessary for obtaining the faithfulness of the game semantics. For the same reason,
Thick Subtrees, Games and Experiments
69
MELLpol proof-nets (see Section 4) require the introduction of a flat () modality which does not belong to MELLpol and which can be thought of as a why not (?) modality, in semantics. The flat notation is used here to ensure that the introductions of ? in a proof-net are postponed as late as possible. (3.a). The relational interpretation of a formula A is a countable set, denoted |A| and called the web of A. The web of A⊥ is always the same as the web of A. The web of 1 (and the web of ⊥) is the singleton set {∗}, (this set is intended to be the neutral element of the Cartesian product of sets, so ∗ shall be thought of as a notation for the empty tuple). The web of A ⊗ B (or of A B) is |A| × |B|. The web of !A (or of ?A) is the set of finite multisets of elements of |A|. For each atom X ∈ V, an arbitrary enumerable set is chosen as web (both for X and its orthogonal). For convenience, we also set |A| = |?A|. To avoid some bureaucratic aspects, we will work on MELLpol up to associativity and neutrality of multiplicatives. In the relational model, this amounts to working up to associativity of the Cartesian product and neutrality of {∗}. 3.1 Arenas and the Desequentialization An arena A is a labeled ordered finite forest together with a polarity: positive or negative. For the game semantics of MELLpol, we restrict ourselves to finite trees. The labeling function is denoted αA . The labels of leaves are elements of V ∪ {∗} and the labels of other nodes are all equal to ∗. The polarity of the arena is extended to moves by choosing the polarity of the arena for the root and by saying that two successive nodes have different polarities. This corresponds to the usual Player/Opponent polarity as follows: positive corresponds to Player and negative to Opponent. Basically, in MELLpol, the arena associated with a formula A is the syntactic tree of this formula, up to associativity and neutrality of multiplicatives and where exponentials shift polarities. (3.b) Arena of a formula. Let A be a formula. The arena 111+ 112+ (X) of A is defined as follows. The polarity of the arena as11− 21− (X) 22− sociated to A is the polarity of the formula. The tree of ⊥ A and of A are equal. The tree of 1 or of an atom X 2+ 3+ 1+ is the tree reduced to one node: (). If t is the tree of N then (t) is the tree of !N . If (t1 , . . . , tp ) is the tree ε of P and (t1 , . . . , tq ) is the tree of P then the tree of Fig. 4. The arena of N0 P ⊗ P is (t1 , . . . , tp , t1 , . . . , tq ). We adopt the canonical localization of ordered trees on arenas. The labels are chosen such that the label of a node coming from an atom X or X ⊥ is X and the labels of the others nodes are ∗. Conversely, every arena is the arena of a unique formula. We further identify arenas and formulæ. Figure 4 shows the arena of N0 = ?!(?1 ?X ⊥ ) ?(!X ⊗ !⊥) ?1 with the relevant part of the labeling. (3.c). In the arena of a formula A, each sub-formula of A corresponds to a move. Two sub-formulæ can correspond to a same move a, but, for each move, there is a maximal sub-formula F (a) of A corresponding to a. For instance, the first occurrence of ?1 in N0 corresponds to the move 11, but F (11) is ?1 ?X ⊥ .
70
P. Boudes
(3.d). A legal justified tree (LJT, for short) on A is a finite tree (I, ≤) together with a labeling function f : I → IA and a pointing relation ← such that: (i) (I, ←∗ , f ) is a thick subtree of A; (ii) ≤ extends the order ←∗ (i.e. ←∗ ⊆ ≤); and (iii) <1 alternates between positives and negatives. We consider that polarities extend to elements of I by saying that the polarity of a ∈ I is the polarity of f (a). So the set I is the disjoint union of a set of negative nodes I − and a set of positive nodes I + . Observe that (ii) implies that ← alternates between I − and I + (as <1 ). The notion of LJT encompasses the game notion of legal play. A legal play is a LJT where (I ≤) is a total order. (3.e). Observe that a LJT t has two tree structures (It , ≤t ) and (It , ←∗t ). We implicitly generalize some notions on trees (e.g. thick subtrees and prefixes) to LJT by considering that (It , ≤t ) is the tree of the LJT t. If t is a LJT, a thick subtree (It , ≤t , g) of (It , ≤t ) inherits a LJT structure (←t , ft ) from t by setting: ft = ft ◦ g and if a ≤t b and g(a) ←t g(b) then a ←t b. Definition 1. The desequentialization D(t) of a LJT t = (I, ≤, ←, f ) on an arena A is just the thick subtree (I, ←∗ ) of A. (3.f). A thick subtree (t, f ) is equitable when t has as many positive nodes as negative nodes. Observe that the thick subtree associated with an even-length, legal play is equitable. Conversely if a thick subtree (t, f ) of an arena A is equitable then there exists a total order extending t into an even length legal play. (Proof by cases on the number of leaves and internal nodes of t of each polarity). (3.g) Valuation (atoms). Let A be a formula. Let (t, f ) be a thick subtree of A. A valuation v of (t, f ) is a partial labeling of nodes of t given by the choice of an element x of the web of X, for each node a of t such that αA (f (a)) = X (in that case f (a) is a leaf of A and a is a leaf of t). When f (a) is a leaf of A and αA (f (a)) = ∗ we set v(a) = ∗. So, each node a of t such that f (a) is a leaf of A and no other is labeled. A result of type A can be seen as a concrete representation of a valuated thick subtrees of A. This representation commutes to the orthogonal. An element x of |X| (resp. ∗ ∈ |1|), is simply the unique thick subtree of the tree (), together with the valuation mapping its unique node to x (resp. ∗). Let a = ([a11 , . . . , a1n1 ], . . . , [ak1 , . . . , aknk ]) be an element of |P | where P is !N1 ⊗ . . . ⊗ !Nk (Ni can be an atom). For each 1 ≤ i ≤ k and for each 1 ≤ j ≤ ni , aij is an element of the web of Ni , so aij represents a valuated thick subtree (tji , fij , vij ) of Ni . The valuated thick subtree represented by a is then the tree (t11 , . . . , tknk ) (seen unordered) together with: the function f mapping its root to the root of the arena of P and equal to fij on the other nodes; and the valuation vij . Proposition 2. Let A be a formula. The set VTST(A) of valuated thick subtrees of A is equal to the web of A. Direct, by induction on A. So, the desequentialization of a legal play on A together with a valuation is an element of the web of A.
4 Terms (Proof-Nets) (4.a). A flat proof structure R is a finite directed graph, built using links of Figure 5, with at least one pending outgoing edges, called the conclusion edges. A label of an
Thick Subtrees, Games and Experiments
71
edge is either a formula, positive (P , Q) or negative (N , M ) or an atom (X) or its orthogonal (X ⊥ ), or a flat formula F , where F (or G) is either a positive formula or the orthogonal X ⊥ of an atom (so F ⊥ or G⊥ is either a negative formula or an atom X). When connecting two links by an edge, the two labels of the edge must match. Polarities of MELLpol formulæ extend to labels as follows. Atoms X are negN M F F F P Q ative, their orthogonal are ⊗ 1 ⊥ ? positive and flat formulæ are F N M ⊥ ?F P ⊗Q 1 negative. In a link, an outgoing edge is a conclusion ax. ! and an incoming edge is a F ⊥ ⊥F !G⊥ F1 Fn premise. In a !-link, the edge cut X ⊥ ⊥X labeled !G⊥ is the front conclusion and the others edges Fig. 5. Links of flat proof structures are the auxiliary conclusions. There is one !-link (resp. ?-link) for each natural number of auxiliary conclusions (resp. premises). For ?-links and !-link the ordering of incoming and outgoing edges is irrelevant (to remind it we draw them with a double line). Observe that R is acyclic, because for each link, the label of each conclusion is strictly bigger than the label of each premise. (4.b) Correctness criterion. A flat proof structure R is correct if: (i) the graph obtained (starting from R) by inversion of every edge with a positive label is acyclic; and (ii) either R contains no flat link () and has exactly one positive conclusion, or R contains exactly one flat link and has only negative conclusions [13]. (4.c). A !-box (RL , BL ) for a !-link L is a correct flat proof structure RL together with a one to one correspondence BL between the conclusion edges of RL and the conclusions of L such that: the conclusion labeled !G⊥ of L (its front conclusion) is the image of a conclusion edge of R labeled by G⊥ ; and the other edges’ labels are preserved. Definition 3. A proof-net π is a finite tree T and three labeling functions R, S, B of nodes of T such that: – for each node n of T , R(n) is a correct flat proof structure and S(n) is a one to one correspondence between the sons of n and the !-links of R(n); – if n is a son of n in T then (R(n ), B(n )) is a !-box for the !-link S(n)(n ). We do not make any requirement on the label f (r) of the root r of π: this label is just here to ease the writing of the definition and it can be safely forgotten. Observe that, if n is a node of a proof-net π = (T, R, S, B) and if Tn is the maximal subtree Tn of t with root n, then πn = (Tn , R|Tn , S|Tn , B|Tn ) is a proof-net. The conclusions of a proof-net are the conclusions of its root’s flat proof structure. A MELLpol proof-net is a proof-net where conclusions are not atoms or flat formulæ. We do not describe the cut elimination procedure on LLpol proof-nets [13].
72
P. Boudes
4.1 Relational Semantics (4.d). An experiment on a flat proof structure R is a labeling function e on edges of R such that: – if a is a conclusion of an axiom link introducing an atom X, and if its other conclusion is b then e(a) = e(b) and e(a) ∈ |X|; – if a is the front conclusion of a !-link and b1 , . . . , bn are the auxiliary conclusions, labeled respectively by !N , F1 , . . . , Fn then for each i, e(bi ) is a multiset of points of |Fi | and e(a) is a multiset of points of |N |; – if a is the conclusion of a 1-link or of a ⊥-link then e(a) = ∗; – if a1 and a2 are the first and the second premises and a is the conclusion of a ⊗-link or of a -link then e(a) = (e(a1 ), e(a2 )); – if a is the premise and b is the conclusion of a -link then e(b) = [e(a)]; – if a1 , . . . , an are the premises and b is the conclusion of a ?-link then e(a1 ), . . . , e(an ) and e(b) are multisets and e(b) = e(a1 ) + . . . + e(an ); – if a is a premise of a cut link, and if its other premise is b then e(a) = e(b). Observe that e(a) is always an element of the web of the label of the edge a. An experiment on a flat proof structure can be considered as a choice of labels for axiom links and !-links which satisfies the constraint e(a) = e(b) on cut links, when propagated by other links. (4.e). If R has only negative conclusions and if e is an experiment on R then r(e), the result of e, is the family a → e(a) indexed by conclusions of R. This notion of result extends to any flat proof structure R and to any experiment e on R by setting r(e ) = r(e) where e is an experiment on a flat proof structure R defined as follows. If R has a positive conclusion we add below a -link. Then, for each conclusion of type a flat-formula we add below a unary ?-link. The resulting proof structure is R and there is a unique extension of e into an experiment of R which is e. (4.f). Experiments on proof-nets and their results are defined inductively on π as follows. If the root of π is the flat proof structure R then an experiment eπ on π is an experiment e on R together with, for each proof-net πv associated with a !-link v of R, a multiset [e1πv , . . . , ekπvv ] (kv ∈ IN) of experiments on πv which satisfies the following. If a is the front conclusion and b1 ,. . . ,bn are the auxiliary conclusions of v kv 1,v νi , . . . , and if, for each i, the result of eiπv is (xi , νi1,v , . . . , νin,v ) then e(b1 ) = i=1 kv n,v e(bn ) = i=1 νi and e(a) = [x1 , . . . , xkv ]. The result r(eπ ) of eπ is the result of e. Hence on a proof-net, an experiment consists of two choices: (i) a copying choice for !-boxes, inductively given by: taking one copy of the root of π and, for each !-link of the root, choosing an arbitrary finite number of copies of the proof-net above, then starting again for each of these proof-nets; (ii) a choice of labels for axioms links in each (copy of) flat proof structure which have been selected during the first choice. Once propagated, these choices have to obey to the only constraint of equality of labels on cut links. Observe that the first choice (i) is just the choice of an arbitrary thick subtree of Tπ and that there is no constraint on (i) and (ii) when there is no cut link. (4.g). To summarize, in this paper, an experiment on a cut-free proof-net π is given by: a thick subtree s of Tπ ; together with, for each axiom link in s introducing an atom
Thick Subtrees, Games and Experiments
73
X, the choice of an element of the web of X. We call this last choice a valuation of axioms. (4.h). The result of an experiment on a MELLpol proof-net π with only one conclusion N is an element of the web of N . The relational interpretation of a proof-net π is the set of results of experiments on π, for all possible experiments. 4.2 Cut Free MELLpol Proof-Nets In this section, we describe and simplify the structure of cut ax. free proof-nets. We start by introducing two simplifications, there will be a third one. ⊥ X X (4.i). First, we work with multiplicative connectives up to neu+ − trality and associativity. In flat proof structures there are trees of tensor links and 1-links with front conclusions of !-links Fig. 6. Axiom’s case above. We identify maximal such trees, called ⊗-trees, to links (drawn with a triangle). The same for trees of -links and ⊥-links with ?-links above ( -trees). Second, we only consider MELLpol proof-nets with only one negative conclusion. If needed we can always transform a (cut free) proof-net into such a MELLpol proofnet by adding well chosen links to the flat proof structure at its root (the same way as in §4.e). Observe that, if the conclusions of a cut free proof-net are known (before simplification) then we can recover this proof-net from its simplified version. Let π be a (simplified) MELLpol cut ⎧ !G⊥ free proof-net. We detail the shape of the ⎪ 1 ! ⎪ ⎪ ⎪ ⊗ flat proof structures contained in π. Let ⎪ ⎪ ⎪ ! ⎨ P R be a flat proof structure of π. We will !G⊥ p see that there are two cases: one with + ⎪ F 1 Fk11 p p 1 ⎪ ⎪ F F exactly one axiom-link (Fig. 6) and one ⎪ 1 kp ⎪ ⎪ ⎪ without axiom (Fig. 7). ⎩ P Each flat proof structure occurring in σR π is either in a !-box or at the root of π. ⎧ Hence R has conclusion edges labeled ⎪ ⎪ ⎪ F1 , . . . , Fk and exactly one negative ⎪ F1 F1 Fq Fq ⎪ ⎪ − ⊥ ⎪ conclusion edge e labeled G (the only ⎪ ⎪ ? ? ⎪ ⎨ conclusion if R is at the root of π). ?F1 ?Fq According to the correctness criterion − ⎪ ⎪ ⎪ (§4.b), R has only one -link L . Since ⎪ ⎪ ⎪ ⎪ F1 Fk this is the only link which has a positive ⎪ ⎪ N ⎪ ⎩ premise and a negative conclusion, all the links with positive conclusions must be above L in R. Here are the two cases: Fig. 7. What is in the box? (i) either the premise of L is the (positive) conclusion of an axiom link Lax. and there is no other link with some positive conclusions in R; (ii) or the premise of L is the conclusion of a ⊗-tree t⊗ (possibly reduced
74
P. Boudes
to an edge or to a 1-link) with front conclusions of !-links above and there is no other link in R introducing a positive formula (we already found the unique -link). In the first case, the axiom also introduces a negative atom X which cannot be the premise of any link. So, R has no other link than L and Lax. (in particular, R is a leaf of π). Now the second case. The conclusion G⊥ is a MELLpol formula N (if G⊥ was an atom X then there will be an axiom introducing it in R). Above the edge e− , labeled by N , there is a -tree t with ?-links above. There is no other !-link introducing negative conclusions than the above mentioned. If there was one, this would be a formula (because we already found the G⊥ conclusion) but flat formulæ are only introduced by -links (there is only one, L ) and !-links (another one than the above mentioned will also introduce a positive conclusion). Since the premises of the ?-link are formulæ they have to be chosen among the conclusion of L or of the !-links. The others conclusions of these last links which are not premises of ?-links are the conclusions F1 , . . . , Fk of R. So there is a pairwise connection σR of: the conclusion of t⊗ and the auxiliary conclusions of the !-links with: the premises of the ?-links and the conclusions of R different from e− . The third simplification we consider is the following. Observe that the !-links occurring in a flat proof structure R of a cut free proof-net π are totally ordered by mean of the ordering of premises of the unique ⊗-tree of R. As a consequence, rather than using S for matching !-boxes with !-links, we consider Tπ as an ordered tree where the ordering of sons of a node n is the same as the ordering of the !-links of R(n). (This cannot be done in a canonical way when there are cut links). 4.3 Game Semantics In polarized games, a MELLpol proof-net of conclusion A is interpreted as a finite balanced total innocent strategy in the arena A, called further a MELLpol strategy. In the sequel, we restrict ourselves to a negative type (the extension to positive types is easy). (4.j). A Player’s view (P-view for short) is a legal play s such that if si <1 sj and sj is an Opponent’s move then si ← sj (the Opponent always points to the last move). Traditionally a strategy is a set of legal plays satisfying some properties (e.g. prefixclosure, determinism). Composition of strategies is then defined pointwise on legal plays: two interacting legal plays are interleaved and, in the resulting sequence, the part on which the plays have interacted is hidden. We do not recall all the definitions of game semantics and polarized games. It is well known that, when a strategy is innocent, all its legal plays are determined by its P-views. This allows for an alternative description of innocent strategies which only uses P-views which we next relate to the traditional presentation (§4.k and Prop. 5). Definition 4. A finite innocent strategy φ in a negative arena A is an even prefix-closed set of P-views which is finite and deterministic: the longest common prefix of every two elements of the set is of even length. We further consider φ as the prefix tree of its P-views regarded, as a particular LJT (tφ , ←φ , f ) (in which every branch is a P-view).
Thick Subtrees, Games and Experiments
75
(4.k) Traditional presentation. The set of legal plays P (φ) associated with a finite innocent strategy φ on A is the smallest set such that: (i) the P-views of φ are in P (φ); (ii) if there is a visible legal play s · ab such that s ∈ P (φ) and v + (s · ab) is a P-view of φ then s · ab ∈ P (φ). Observe that P (φ) is an even-prefix closed set of visible even length legal plays which is not, in general, finite. (4.l). When (I, ≤, ←, f ) is a LJT, we further consider the following relations: the Player’s pointers ←+ = ← ∩ (I − × I + ); the Opponent’s pointers ←− = ← ∩ (I + × I − ); the Player’s precedence <+ = <1 ∩ (I − × I + ); the Opponent’s precedence <− = <1 ∩ (I + × I − ); and the Player’s order: (<+ ∪ ←− )∗ . The Player’s order on I is still a tree because ←∗ ⊆ ≤. (4.m). A LJT is visible when its Player’s order contains the Player’s pointers. (4.n). The negative desequentialization 112+ 3+ D− ((s, ←s )) of a visible LJT (or play) 3+ + − ∗ is the LJT (Is , (< ∪ ←s ) , ←s ). Each 21− 22− 22− branch of this tree is a P-view. The view 2+ 2+ function v + maps visible legal plays to 112+ 11− 11− P-views: a legal play s with last move 21− 1+ a is mapped to the unique branch of the − + tree D (s) with leaf a. The positive de2 − sequentialization D+ is defined dually, (b) D− (p) − 11 by reversing the roles of Player and Opponent, on co-visible LJTs (the dual no2+ 112+ tion of visible LJTs). We will only use 11− 11− 11− 21− 22− D+ on the image of D− where all LJTs are co-visible (because the Opponent al1+ 1+ 2+ 2+ 3+ ways points to the last move). On LJTs − − the desequentialization D factors through (c) D(p) (a) p D− and D+ , moreover D and D+ coincide on the image of D− . So, for a visible Fig. 8. Desequentialization of a play p legal play s, D(s) = D+ (D− (s)) = D(D− (s)). Figure 8(a) shows a legal play p in the formula N0 (of Fig. 4) which is visible (but not co-visible). If the Player’s move 112 was set to point to the second occurrence of 11 (from bottom to top) then the play would not be visible. Figure 8(b) shows the negative desequentialization of p and Figure 8(c) achieves the desequentialization. (4.o). If a LJT t is such that each Opponent’s move has exactly one son then its compact presentation is itself but where, in the tree (It , ≤t ), each pair of successive nodes a <+ b is regarded as one node (a, b). An even thick subtree t of a finite innocent strategy φ is a thick subtree of φ such that each Opponent’s move has exactly one son (so, t is given by an arbitrary thick subtree of the compact presentation of φ). The set of even thick subtrees of φ is denoted ETST(φ). Proposition 5. Let φ be a finite innocent strategy. If s is a legal play of φ (ie s ∈ P (φ)) then D− (s) is an even thick subtree of φ. Conversely, if t (together with a tree
76
P. Boudes
112+
3+ 1
ax. 21−
22−
112
! ?
11 !
(a) Strategy
?
?X
⊥
(!X ⊗ !⊥) 1
!
2 ?
?1
! ⊗
?
! ⊗
?
11−
1+
⊥ 1
X !
?
2
⊥
X ⊥
⊥ 22 3
21
+
ε−
1
ax.
?
?
?
?
1 ε (b) Go-between
N0 (c) Proof-net
Fig. 9. Example
morphism f ) is an even thick subtree of φ then any total order ≤s on It which extends + ≤t and preserves the Player’s precedence of t (i.e. <+ s =
Thick Subtrees, Games and Experiments
77
proof structure, similar to the one of Fig. 7. The maximal sub-formula F (n− ) of N (§3.c) determines a -tree n( ) with, for each of its premises a1 , . . . , aq , a ?-link Wi of conclusion ai . The premises of these ?-links are yet unknown. The maximal subformula F (n+ ) of N defines a ⊗-tree n(⊗) with: for each of its premises b1 , . . . , bp , a !-link with principal conclusion bi ; and a -link n() having the conclusion of the n(⊗). The auxiliary doors of the !-links and the permutation σRn are not yet defined. In the partial proof-net we then obtain (Figure 9(b)), we still represent the Player’s pointer: if − n+ 1 points to n2 and if F (n1 ) occurs in F (n2 ) at place i then we draw an edge from n1 () to the ith ?-link Wi above n2 ( ). Next, we slice the pointers to reconstruct the missing edges of the flat proof structures, by working inductively on tφ , from leaves to root. When n() points to a ?-link Wi above n( ) we draw an edge from the conclusion of n() to Wi . Otherwise n() is a conclusion of Rn . It is then passed as an auxiliary door to the associated !-link L of the flat proof structure below n: a conclusion edge is drawn from the actual source of the pointer, and this source is changed into L. It is passed again, until the source of the pointer is in the same flat proof structure as its target, a ?-link. We then draw an edge from the source to the target of the pointer. At the end of this process we obtain π. Conversely, let π be a cut free proof-net of conclusion N . We construct φ = ΨN (π) as follows. We define a labeling Mπ of the edges of the flat proof structures of π by moves of N . Intuitively this labeling is just a way to identify the occurrences of sub-formulæ of N to the places where they are created in the proof-net π. The (unique) conclusion edge of π is labeled by the empty word (the root of N ). Going upward through a ?-link, a -link or through a !-link and its associated !-box do not change labels. If L is a ⊗-tree or a -tree and w is the label of its conclusion then its k premises are labeled w · 1, . . . , w · k (in that order). We use Mπ to associate to each node n of π an ordered pair made of one Opponent’s move n− and one Player’s move n+ . For a flat proof structure containing one axiom (Fig. 6) this is respectively the move labeling the negative conclusion and the move labeling the positive conclusion of the axiom. For a flat proof structure without axiom (Fig. 7) this is respectively the move labeling the conclusion of the -tree and the move labeling the conclusion of the ⊗-tree. The tree Tπ equipped with the labeling Mπ will be the compact presentation of − φ. The pointing relation ←φ is not yet defined. We first set n+ 1 ←φ n2 each time − + + − + − + 1 n1 <φ n2 (that is, each time (n1 , n1 ) < (n2 , n2 ) in the compact presentation of φ). Each flat proof structure Rπ (n) associated to a node n of π contains a unique flat link. We denote (n) its conclusion edge. There exists a unique chain n1 <1π . . . <1π nk = n in π such that Bπ (n2 )(. . . Bπ (nk )((n)) . . .) + is the premise of a ?-link of n1 . We set n− 1 ←φ n . We then obtain φ.
4.5 Experiments and Strategies The detailed correspondence between proof-net and strategies shows that a thick subtree of a cut free proof-net π of N can be regarded as an even thick subtree of the corresponding strategy φ = ΨN (π) (and conversely). But an experiment in π is just a thick
78
P. Boudes
subtree of Tπ together with a valuation of axioms (§4.g). We now define valuations of axioms directly in games, to obtain a notion of experiment on MELLpol strategies. The correspondence ΨN then extends into a one to one correspondence between experiments in π and experiments in φ = ΨN (π) and that allows to show that the result of a proof-net’s experiment is the desequentialization of the corresponding strategy’s experiment. (4.q) Valuation of axioms (2). If (t, f ) is an even thick subtree of φ (equivalently, an element of P (φ), §4.k) then a valuation of axioms in (t, f ) is the choice, for each pair a <+ t b such that αN (a) = αN (b) is an atom X, of an element of the web of X. The set of valuated thick subtrees of φ is denoted VETST(φ) and the set of valuated legal plays of P (φ) is denoted V (P (φ)). Proposition 5 extends into a correspondence between these two sets. Even thick subtrees of a strategy inherit the labeling by moves and pointers from the strategy (§3.e). We do the same for thick subtrees of proof-nets. If (t, g) is a thick subtree of Tπ then we define three labeling functions Rt , St and Bt on t as follows. For each node n of t, Rt (n) is a copy of the flat proof structure Rπ (g(n)). If n <1t n then Sπ (g(n))(g(n )) is a !-link L of Rπ (g(n)) which has a corresponding copy Lc in Rt (n). We set St (n)(n ) = Lc . The one to one correspondence Bt (n ) between conclusions of Rt (n ) and conclusions of Lc is then simply a copy of Bπ (g(n )). Lemma 6. Let N be a negative MELLpol formula, ΨN extends into a one to one correspondence between the experiments on π and the experiments on ΨN (π). Moreover, if e is an experiment on π then the valuated thick subtree D+ (ΨN (e)) is the result of e. The extension of ΨN is straightforward, because the condition that the functions Sπ (n) are one to one in the definition of proof-nets (Def. 3) is not necessary to make ΨN work. But one needs to be careful for the slicing of Player’s pointers when reconstructing a − + + proof-net experiment e. If there are two pointers n− ←+ n+ 1 , and n ← n2 such that + + n1 and n2 correspond to the same node in the strategy φ then, when going through the same partial flat proof structure R, these pointers define in R the same edge a (from a !-link to a ?-link or a conclusion) rather than two edges. This identification corresponds to a sum of multisets in the label e(a). There is a labeling of pointers of ΨN (e) which coincides with e on sources of pointers. It is then easy to check that D+ (ΨN (e)) is the result of e. As an immediate consequence of this last Lemma we have: Theorem 7. If π is a MELLpol proof-net of negative conclusion N , then the relational interpretation of π is the set D+ (VETST(ΨN (π))) = D(V (P (ΨN (π)))). This result proves that the desequentialization (together with valuations) defines a logical functor from polarized games to the relational model. By using techniques presented in [9], D can be composed with a functor forgetting some results, to obtain a logical functor from polarized games to coherence spaces or to hypercoherences. The results presented here extend to the full fragment of LLpol with sliced proofnets [14]. The use of additives can be restricted to the outermost flat proof-structure (the root), by using the type isomorphism !(N & M ) = !N ⊗ !M and the distributivity laws
Thick Subtrees, Games and Experiments
79
of linear logic (leaving unchanged the semantics). The only work left is a generalization of the present work from trees to forests. An extension to full linear logic (without polarity constraint) is more problematic at least because of the arbitrary complexity of cut-free flat proof-structures. Since the desequentialization D provides good results for the game semantics of MELLpol, we hope that it can be applied to others game semantics, for instance for languages with imperative features, in order to obtain static semantics of these syntaxes. A corollary of Theorem 7 is that all the results of experiments are equitable. This property, coming from alternation of moves in plays, surely allows for narrowing the relational model to equitable results. Other properties of plays, such as visibility, seem harder to capture on the side of the relational model. Another direction to look at is the faithfulness of the relational model. Factoring the interpretation through abstract Böhm trees by mean of thick subtrees allows for a more combinatoric approach of this long standing conjecture [6]. The author thanks the anonymous referees for their comments on improving the readability of this paper.
References 1. Baillot, P., Danos, V., Ehrhard, T., Regnier, L.: Timeless games. In: Nielsen, M., Thomas, W. (eds.) CSL 1997. LNCS, vol. 1414, pp. 56–77. Springer, Heidelberg (1998) 2. Laurent, O.: Syntax vs. semantics: a polarized approach. Theoretical Computer Science 343(1–2), 177–206 (2005) 3. Abramsky, S., McCusker, G.: Game semantics. In: Proceedings of Marktorberdorf of the 1997 Summer School. Lecture notes. Springer, Heidelberg (1998) 4. Laurent, O.: Polarized games. Annals of Pure and Applied Logic 130(1–3), 79–123 (2004) 5. Girard, J.Y.: Linear logic. Theoretical Computer Science 50, 1–102 (1987) 6. Tortora de Falco, L.: Réseaux, cohérence et expériences obsessionnelles. Thèse de doctorat, Université Paris VII (2000) 7. Ehrhard, T.: Projecting sequential algorithms on strongly stable functions. Annals of Pure and Applied Logic 77 (1996) 8. Melliès, P.A.: Sequential algorithms and strongly stable functions. Theoretical Computer Science 343(1-2), 237–281 (2005) 9. Boudes, P.: Non uniform hypercoherences. In: Blute, R., Selinger, P. (eds.) Proceedings of CTCS 2002. Electronic Notes in Theoretical Computer Science, vol. 69. Elsevier, Amsterdam (2003) 10. Boudes, P.: Projecting games on hypercoherences. In: Díaz, J., Karhumäki, J., Lepistö, A., Sannella, D. (eds.) ICALP 2004. LNCS, vol. 3142, pp. 257–268. Springer, Heidelberg (2004) 11. Curien, P.L.: Abstract Böhm trees. Mathematical Structures in Computer Science 8(6) (1998) 12. Curien, P.-L., Herbelin, H.: Computing with abstract Böhm trees. In: Sato, M., Toyama, Y. (eds.) Fuji International Symposium on Functional and Logic Programming (FLOPS 1998), Kyoto, Japan, April 2-4, 1998, pp. 20–39. World Scientific, Singapore (1998) 13. Laurent, O.: Étude de la polarisation en logique. Thèse de doctorat, Université AixMarseille II (March 2002) 14. Laurent, O., Tortora de Falco, L.: Slicing polarized additive normalization. In: Ehrhard, T., Girard, J.Y., Ruet, P., Scott, P. (eds.) Linear Logic in Computer Science. Lecture Notes Series, vol. 316, pp. 247–282. London Mathematical Society (2004)
Bounded Linear Logic, Revisited Ugo Dal Lago1 and Martin Hofmann2 1
Dipartimento di Scienze dell’Informazione, Universit` a di Bologna 2 Institut f¨ ur Informatik, LMU M¨ unchen
Abstract. We present QBAL, an extension of Girard, Scedrov and Scott’s bounded linear logic. The main novelty of the system is the possibility of quantifying over resource variables. This generalization makes bounded linear logic considerably more flexible, while preserving soundness and completeness for polynomial time. In particular, we provide compositional embeddings of Leivant’s RRW and Hofmann’s LFPL into QBAL.
1
Introduction
After two decades from the pioneering works that started it [3,13,14], implicit computational complexity is now an active research area at the intersection of mathematical logic and computer science. Its aim is the study of machine-free characterizations of complexity classes. The correspondence between an ICC system and a complexity class holds extensionally, i.e., the class of functions (or problems) which are representable in the system equals the complexity class. Usually, the system is a fragment or subsystem of a larger programming language or logical system, the base system, in which other functions besides the ones in the complexity class can be represented. Sometimes, one of the two inclusions is shown by proving that any program (or proof) can be reduced in bounded time; in this case, we say that the system is intensionally sound. On the other hand, ICC systems are very far from being intensionally complete: there are many programs (or proofs) in the base system which are not in the ICC system, even if they can be evaluated with the prescribed complexity bounds. Observe that this does not contradict extensional completeness, since many different programs or proofs compute the same function. Of course, a system that captures all and only the programs of the base system running within a prescribed complexity bound will in all but trivial cases (e.g., empty base system) fail to be recursively enumerable. Thus, in practice, one strives to improve intensional expressivity by capturing important classes of examples and patterns. An obstacle towards applying ICC characterizations of complexity classes to programming language theory is their poor intensional expressive power: most ICC systems do not capture natural programs and therefore are not useful in practice. This problem has been already considered in the literature. Some papers try to address the poor intensional expressive power of ICC systems by defining new programming languages allowing to program in ways which are not allowed P.-L. Curien (Ed.): TLCA 2009, LNCS 5608, pp. 80–94, 2009. c Springer-Verlag Berlin Heidelberg 2009
Bounded Linear Logic, Revisited
81
in existing ICC systems. This includes quasi-interpretations [15] and LFPL by the second author [10]. Other papers analyze the intensional expressive power of existing systems either by studying necessary conditions on captured programs or, more frequently, by studying relations between existing ICC systems. One nice example is Murawski and Ong’s paper [16], in which the authors prove that there cannot be any embedding (satisfying certain properties) of Bellantoni and Cook function algebra BC [3] into light affine logic [1]. In this work, we somehow combine the two approaches, by showing that a new logical system, called QBAL is intensionally at least as expressive as two heterogeneous, existing systems, namely Leivant’s RRW [14] and LFPL. QBAL is a generalization of Girard, Scedrov and Scott’s bounded linear logic (BLL, [8]), itself the first characterization of polynomial time computable functions as a fragment of Girard’s linear logic [6]. Bounded linear logic has received relatively little attention in the past [11,17]. This is mainly due to its syntax, which is more involved than the one of other complexity-related fragments of linear logic appeared more recently [7,12,5]. In bounded linear logic, polynomials are part of the syntax and, as a consequence, computation time is controlled explicitly. However, it seems that BLL is not as intensionally expressive as to be able to embed any existing ICC system corresponding to polynomial time (except Lafont’s SLL [12], which anyway was conceived as a very small fragment of BLL). QBAL is obtained by endowing BLL with bounded quantification on resource variables. In other words, formulas of QBAL includes the ones of BLL, plus formulas like ∃x : {x ≤ y 2 }.A or ∀x, y : {x ≤ z, y ≤ z 3 }.B. This new feature by itself increases the intensional expressive power: both RRW and LFPL can be compositionally embedded into QBAL. Moreover, QBAL remains sound with respect to polynomial time. For these reasons, QBAL is not just another system capturing polynomial time computable functions. An extended version of this paper including all proofs is available [4].
2
Syntax
In this Section, we present the syntax of QBAL, together with some of its main properties. The lack of space prevents us from being exhaustive, but all the details can be found in [4]. In the following, we adhere to the notation adopted in the relevant literature on BLL [8,11]. Resource polynomials of products of binomial coefficients, i.e. sums are finite where the xij are pairwise distinct and they can be written as j≤m i≤kj nxij ij nij are natural numbers. Resource polynomials are closed under binary sum, binary product, bounded sum and composition [8]. Order relations between resource polynomials are captured by constraints and constraint sets: Definition 1 (Constraints) • A constraint is an inequality in the form p ≤ q, where p and q are resource polynomials. A constraint set is a finite set of constraints. Constraint sets are denoted with letters like C or D.
82
U. Dal Lago and M. Hofmann
• For each constraint set C , we define an order C on resource polynomials by imposing p C q iff C |= p ≤ q, i.e., the (pointwise) inequality p ≤ q is a logical consequence of C . • C |= D iff C |= p ≤ q for every constraint p ≤ q in D. Resource polynomials, constraints and constraint sets becomes, in turn, the essential ingredients in the definition of QBAL formulas: Definition 2. Formulas of QBAL are defined as follows: A ::=α(p1 , . . . , pn ) | A ⊗ A | A A | ∀α.A | !x
Bounded Linear Logic, Revisited
83
Axiom and Cut A C B
Γ C A
A
A C B
Δ, A C B
Γ, Δ C B
U
Structural Rules Γ, !x
Γ C B W Γ, A C B
p + q C r
Γ, !x
X
Multiplicative Logical Rules Γ, A C B
R
Γ C A B
Γ C A
Δ, B C C
L
Γ, Δ, A B C C
Γ C A Δ C B R⊗ Γ, Δ C A ⊗ B
Γ, A, B C C Γ, A ⊗ B C C
L⊗
Exponential Rules A1 , . . . , An C B
D, x < p |= C
x∈ / FV (D)
p D qi
!x
1 C p
!x
w<x
q{w/x}/y}, Γ C B
P!
D! x
q C r
!y
N!
Second Order Rules Γ C A
α ∈ FV (Γ )
Γ C ∀α.A
R∀α
Γ, A{B/α(x1 , . . . , xn )} C C Γ, ∀α.A C C
L∀α
First Order Rules Γ C ∪D A
x ∈ FV (Γ ) ∪ FV (C )
Γ C ∀x : D.A Γ C A{p/x}
C |= D{p/x}
Γ C ∃x : D.A
R∃x
R∀x
Γ, A{p/x} C C
Γ, A C ∪D C
C |= D{p/x}
Γ, ∀x : D.A C C
L∀x
x ∈ FV (Γ ) ∪ FV (C) ∪ FV (C ) Γ, ∃x : D : A C C
L∃x
Fig. 1. A sequent calculus for QBAL
2.1
QBAL and Second Order Logic
Second order intuitionistic logic can be presented as a context-independent sequence calculus with explicit structural rules [18], G2i. There is a forgetful map [·] from the space of QBAL proofs to the space of G2i proofs. In particular corresponds to → and ⊗ corresponds to ∧. Essentially, [π] have the same structure of π, except for exponential and first order rules, which have no formal correspondence in G2i. From our point of view, if [π] = [ρ], then π and ρ correspond to the same program, i.e. QBAL can be seen as a proper decoration of second order logic proofs with additional information which are not necessary to perform the underlying computation.
84
2.2
U. Dal Lago and M. Hofmann
Properties
QBAL inherits some nice properties from BLL. In particular, proofs can be manipulated in a uniform way by altering their conclusion without altering their structure, i.e., without changing the underlying second order logic proof. Suppose that π : A1 , . . . , An C B is a QBAL proof. Then, we can construct other proofs with the same skeleton as π. For example: • Whenever B C D and Ci C Ai for every 1 ≤ i ≤ n, there is ρ : C1 , . . . , Cn C D such that [ρ] = [π]. • Whenever p1 , . . . , pn are resource polynomials free for substitution for the free resource variables x1 , . . . , xn in π, there is a proof π{p/x} : A1 {p/x}, . . . , An {p/x} C {p/x} B{p/x} such that [π{p/x}] = [π]. • Whenever D |= C there is a proof ρ : A1 , . . . , An D B such [ρ] = [π]. Unfortunately, space constraints prevent us from explicitly giving the details and proofs of the results above (see [4]). 2.3
Cut-Elimination
A nice application of the observations we have just given is cut-elimination. Indeed, the new rules R∀x , L∀x , R∃x and L∃x do not cause any problem in the cut-elimination process. See [4] for more information. In this paper, we will not study cut-elimination. And polynomial time soundness will be itself proved semantically. 2.4
Programming in QBAL
The Curry-Howard correspondence allows to use BLL and QBAL as programming languages. In particular, following the usual impredicative encoding of data into second order intuitionistic logic, natural numbers can be represented as cut-free proofs of the formula Np = ∀α.!y
Functions on natural numbers can be represented by proofs with conclusion Nx Np , where p is a resource polynomial depending on x, only. More generally, functions on the word algebra W can be represented by proofs with conclusion Wx Wp . For example, all constructors c1W , . . . , cw W corresponds to proofs with
Bounded Linear Logic, Revisited
85
conclusion Wx Wx+1 . More generally, the polynomial p gives a bound on the size of the result, as a function of the size of the input. QBAL supports iteration on any word algebra (including natural numbers). As an example, for every p and for every A where x only appears positively, there is a proof πpA of Np , A{y/x} A{y + 1/x}, A{0/x} A{p/x}. 2.5
Unbounded First Order Quantification Is Unsound
One may wonder why quantification on numerical variables is restricted to be bounded (see Definition 2). The reason is very simple: in presence of unbounded quantification, QBAL would immediately become unsound. To see that, define N∞ to be the formula ∃(x) : ∅.Nx . The composition of the successor with itself yields a proof with conclusion Nx Nx+2 which, by rules R∃x and L∃x , becomes a proof with conclusion N∞ N∞ . Iterating it, we obtain a proof of Nx N∞ which computes the function n → 2n. But by rule L∃x , it can be turned into a proof of N∞ N∞ , and iterating it again we obtain a proof computing the exponential function. The boundedness assumption will be indeed critical in Section 4, where we establish that any functions which is representable in QBAL is polynomial time computable.
3
Set-Theoretic Semantics
In this Section, we give a set-theoretic semantics for QBAL. We assume that our ambient set-theory is constructive. This way we have a set of sets U which contains the natural numbers, closed under binary products, function spaces and U-indexed products. An alternative to assuming a constructive ambient set theory consists of replacing plain sets with PERs (partial equivalence relations) or domains or similar structures. See [11] for a more detailed discussion of this issue. A formula A can be interpreted as a set A ρ , where ρ is an environment mapping atoms to sets. For example, α(p) ρ = ρ(α), while ∀x : C .A ρ is simply A ρ . Please observe that the interpretation of any formula A is completely independent from the resource polynomials appearing in A. To any QBAL proof π of A1 , . . . , An C B we can associate a set-theoretic function π ρ : A1 ⊗ . . . ⊗ An ρ → B ρ by induction on π, in the obvious way. π ρ is equal to the set-theoretic semantics of [π] as a proof of second order intuitionistic logic. Set-theoretic semantics of proofs is preserved by cutelimination: if π reduces to σ by cut-elimination, then π ρ = σ ρ . Observe that A ρ only depends on the values of ρ on atoms appearing free in A. So, in particular,
Nq ρ = (C ⇒ C) ⇒ (C ⇒ C) C∈U
is independent on ρ and on q, since Nq is a closed formula. Similarly for Wq ρ . Actually, there are functions ϕN : N → Np and ψN : Np → N such that ψN ◦ ϕN is the identity on natural numbers. They are defined as follows:
86
U. Dal Lago and M. Hofmann
(ϕN (n))C (f, z) = f n (z) ψN (x) = xN (x → x + 1)(0) So, given a proof π : Nx Np , the numeric function represented by π is simply ψN ◦ π ◦ ϕN . Similar arguments hold for functions with conclusion Wx Wp .
4
QBAL and Polynomial Time
In this Section we show that all functions on natural numbers definable in QBAL are polynomial time computable. To this end, we follow the semantic approach in [11] which we now summarise. 4.1
Realizability Sets
Let X be a finite set of variables. We write V(X) for NX —the elements of V(X) are called valuations (over X). If η ∈ V(X) and c ∈ N then η[x → c] denotes the valuation which maps x to c and acts like η otherwise. We assume some reasonable encoding of valuations as natural numbers allowing them to be passed as arguments to algorithms. If C is a constraint set involving at most the variables in X (over X) then we write η |= C to mean that the valuation η ∈ V(X) satisfies all the constraints in C . We write P(X) for the set of resource polynomials over X. If p ∈ P(X) and η ∈ V(X) we write p(η) for the number obtained by evaluating p with x → η(x) for each x ∈ X. We assume known the untyped lambda calculus as defined e.g. in [2]. An untyped lambda term is affine linear if each variable (free or bound) appears at most once (up to α-congruence). For example, λx.λy.yx and λx.λy.y and λx.xy are affine linear while the term λx.xx is not. Notice that every affine linear term t is strongly normalisable in less than |t| steps where |t| is the size of the term. The runtime of the computation leading to the normal form is therefore O(|t|2 ). We will henceforth use the expression affine lambda term for an untyped affine linear lambda term which is in normal form. If s, t are affine lambda terms then their application st is defined as the normal form of the lambda term st. Notice that the application st can be computed in time O((|s| + |t|)2 ). If s, t are affine lambda terms we write s⊗t for the affine lambda term λf.f st. If t is an affine lambda term possibly containing the free variables x, y then we write λx⊗y.t for λu.u(λxλy.t). Notice that (λx⊗y.t)(u⊗v) = t{u/x, v/y}. More generally, if (ti )i
i
We write Λa for the set of closed affine lambda terms. There is a canonical way of representing terms of any word algebra W as affine lambda terms, which is attributed to Dana Scott [19]. For example, the natural number 2 corresponds to the term 2 = λx.λy.x(λx.λy.x(λx.λy.y)).
Bounded Linear Logic, Revisited
87
Definition 4. Let X be a finite set of resource variables. A realizability set over X is a pair A = (|A|, A ) where |A| is a set and A ⊆ V(X) × Λa × |A| is a ternary relation between valuations over X, affine lambda terms, and the set |A|. We write η, t A a for (η, t, a) ∈A . The intuition behind η, t A a is that a is an abstract semantic value, η measures the abstract size of a, and the affine lambda term t encodes the abstract value a. Example 1. (i) The realizability set Nx over {x} of tally natural numbers (“of size at most x”) is defined by: |Nx | = N and η, t Nx n if t = n and η(x) ≥ n (ii) The realizability set Wx over {x} of free terms of W (“of length at most x”) is defined by: |Wx | = W and η, t Wx w if t = w and η(x) ≥ |w| These realizability sets Nx and Wx turn out to be retracts of the denotations of the BLL formulas from Section 2.4. Definition 5. Let A be a realizability set over X. We say that x ∈ X is positive ( negative, respectively) in A, if for all η, μ ∈ V(X), t ∈ Λa , a ∈ |A| where η and μ agree on X \{x} and η(x) ≤ μ(x) (η(x) ≥ μ(x), respectively), η, t A a implies μ, t A a. We notice that x is positive in Nx and Wx . Definition 6. Let A, B be realizability sets over some set X. A morphism from A to B is a function f : |A| → |B| satisfying the following condition: there exists a function e : V(X) → Λa such that e(η) is computable in time q(η) for some resource polynomial q and for each η ∈ V(X), t ∈ Λa , a ∈ |A|, we have η, t A a
implies
η, e(η)t B f (a)
In this case we say that e witnesses f and write A →fe B where in the notation the algorithm e is presumed to exist. The following definition summarises the interpretation of formulas according to [11]: Definition 7. Let A, B be realizability sets over X. Then the following are realizability sets over X: • A ⊗ B as given by |A ⊗ B| = |A| × |B| and η, t A⊗B (a, b) iff t = u⊗v, where η, u A a and η, v B b. • A B is given by |A B| = |A| ⇒ |B| and η, t AB f iff whenever η, u A a it holds that η, t u B f (a). If C is a realizability set over X ∪ {x} and p ∈ P(X) then a realizability set !x
88
U. Dal Lago and M. Hofmann
• t = i
Extending the Realizability Model to QBAL
The notion of a realizability set above is adequate to model formulas of QBAL. The notion of a morphism, however, should be slightly generalized in order to capture constraints: Definition 8. Let A, B be realizability sets over some set X and C a constraint set over X. A function f : |A| → |B|: is a C -morphism from A to B iff there exists a function e : V(X) → Λa such that e(η) is computable in time q(η) for some resource polynomial q and for each η ∈ V(X) with η |= C , t ∈ Λa , a ∈ |A|, we have that η, t A a implies η, e(η)t B f (a). In order to define realizability sets ∀y:C .A and ∃y:C .A, we fix some encoding of environments η as affine lambda terms using the · encoding of natural numbers. We do not notationally distinguish environments from their encodings. Definition 9. Let X, Y be disjoint sets of variables. Let A be a realizability set over X ∪ Y and C a constraint set over X ∪ Y where we put Y = {y1 , . . . , yn } and y = (y1 , . . . , yn ). Furthermore, for each i = 1, . . . , n let pi ∈ P(X) be such that C |= {y ≤ p}. • |∀y:C .A| = |∃y:C .A| = |A|, • η, t ∀y:C .A a ⇐⇒ ∀μ ∈ V(Y ).η∪μ |= C ⇒ η∪μ, tμ A a. • η, μ ⊗ t ∃y:C .A a ⇐⇒ μ ∈ V(Y ) ∧ η∪μ |= C ∧ η∪μ, t A a Recall that ∀y:C .A and ∃y:C .A are well-formed only if for each i there is a resource polynomial pi such that C |= yi < pi . Therefore, the set {μ | η∪μ |= C } is finite and in fact computable in polynomial time from η.
Bounded Linear Logic, Revisited
89
We are now able to prove the main result of this Section: Theorem 1. Let π be a proof of a sequent Γ C B and ρ a mapping of atoms B to realizability sets. Then π |ρ| is a C -morphism from Γ B ρ to B ρ . Proof. The proof is by induction on derivations. We only show the cases that differ significantly from the development in [11]. Case P! . For simplicity, suppose that n = 1, q1 = p and A1 = A. The induction B hypothesis shows that π |ρ| is a C -morphism from A B ρ to B ρ witnessed by e. As in the proof of the main result in [11], we define d(η) = λ xi . e(η[x → i])xi . i
i
Now, if η |= D, then η[x → i] |= C whenever i < p(η) by the side condition B from rule P! . We obtain that π is a D-morphism from !x
5
On Compositional Embeddings
In this Section, we try to justify our emphasis on compositional embeddings. An embedding of a logical system or programming language L into QBAL is a function · from the space of proofs (or programs) of L into the space of proofs for QBAL. Clearly, for an embedding to be relevant from a computational point of view, any proof π of L should be mapped to an equivalent proof π, e.g., π = π . The existence of an embedding of L into QBAL implicitly proves that QBAL is extensionally at least as powerful as L. Such an embedding · is not necessarily computable nor natural. But whenever L is a sound and complete ICC characterization of polynomial time, it must exists, since the classes of
90
U. Dal Lago and M. Hofmann
definable functions in L and in QBAL are exactly the same. Indeed, QBAL is both extensionally sound (see Section 4) and extensionally complete (since BLL can be compositionally embedded into it, see below). Typically, one would like to go beyond extensionality and prove that QBAL is intensionally as powerful as L. And if this is the goal, · should be easily computable. Ideally, we would like · to act homeomorphically on the space of proofs of L. In other words, whenever a proof π of L is obtained applying a proofforming rule R to ρ1 , . . . , ρn , then π should be obtainable from ρ1 , . . . , ρn in a uniform way, i.e., dependently on R but independently on ρ1 , . . . , ρn . An embedding satisfying the above constraint is said to be strongly compositional. The embeddings we will present in the following two sections are only weakly compositional: [π] can be uniformly built from [ρ1 ], . . . , [ρn ] whenever π is obtained applying R to ρ1 , . . . , ρn . We believe that the existence of a weakly compositional embedding of L into QBAL is sufficient to guarantee that QBAL is intensionally as powerful as L because, as we pointed out in Section 2.1, [π] can be thought as the program hidden in the proof π. Notice that BLL can be embedded into QBAL: for every BLL proof π : Γ A, there is a QBAL proof π : Γ ∅ A such that [π] = [π]. Moreover, the embedding is strongly compositional.
6
Embedding LFPL
LFPL is a calculus for non-size-increasing computation introduced by the second author [10]. It allows to capture natural algorithms computing functions such that the size of the result is smaller or equal to the size of the arguments. This way, polynomial soundness is guaranteed despite the possibility of arbitrarily nested recursive definitions. We here show that a core subset of LFPL can be compositionally embedded into QBAL. LFPL types are generated by the following grammar: A ::= | N | A ⊗ A | A A. Rules for LFPL in natural-deduction style are in Figure 2. We omit terms, since the computational content of type derivations is implicit in their skeleton. The set-theoretic semantics A ofan LFPL formula A can be defined very easily: = C∈U C ⇒ C, N = C∈U (C ⇒ C) ⇒ (C ⇒ C), while the operators ⊗ and are interpreted as usual. Notice that the interpretation of an LFPL formula does not depend on any environment ρ. This way, any LFPL proof π : A1 , . . . , An B can be given a semantics π : A1 ⊗ . . . ⊗ An → B , itself independent on any ρ. LFPL types can be translated to QBAL formulas in the following way: qp = ∃ε : {1 ≤ p}.∀α.α α Nqp = Np
A ⊗ Bqp = ∃(x, y) : {x + y ≤ p}.Aqx ⊗ Bqy
A Bqp = ∀(x) : {x + p ≤ q}.Aqx Bqp+x
Bounded Linear Logic, Revisited
91
Axiom, Base Types and Weakening AA
A
N, N
S
AA A T NA
Γ A W Γ, B A
Multiplicative Rules Γ, A B I Γ AB
Γ AB ΔA E Γ, Δ B
Γ A ΔB I Γ, Δ A ⊗ B ⊗
Γ A ⊗ B Δ, A, B C E⊗ Γ, Δ C Fig. 2. LFPL
Please observe that the interpretation of any LFPL is parametrized on two resource polynomials p and q. If a variable x occurs in p, but not in q, then x occurs only positively in Aqp : this is an easy induction on the structure of A. The correspondence scales to proofs: Theorem 2. LFPL can be embedded into QBAL. In other words, for every LFPL proof π : A1 , . . . , An B, there exists a QBAL proof π : A1 yx1 , . . . , An yxn { i xi ≤y,1≤y} By such that tional.
π
=
i
xi
π . Moreover, the correspondence · is weakly composi-
Proof. As expected, the proof goes by induction on π. We just give two interesting cases: • If the last rule used in π is I , then π : Γ A B and the immediate sub-proof is ρ, with conclusion Γ, A B. By induction hypothesis, there is ρ with the appropriate conclusion and π becomes: σ : Γ yx , Ayz { i xi ≤y, i xi +z≤y,1≤y} By Γ yx
{ i xi ≤y, i xi +z≤y,1≤y}
Ayz
By
Γ yx { i xi ≤y,1≤y} A By
i
xi
i
xi +z
i
xi +z
R R∀x
where σ can be easily obtained from ρ by strengthening the underlying constraint set (see Section 2.2). • If the last rule in π is T , then π : N A and the immediate sub-proofs are ρ with conclusion A A and σ with conclusion A. By the induction hypothesis, there are ρ and σ with the appropriate conclusions and π becomes:
92
U. Dal Lago and M. Hofmann
θ : y1 {z≤y,1≤y} A Ay1 {z≤y,1≤y} A Ay1 {z≤y,1≤y} Ayz Ayz+1
ξ : {z≤y,1≤y} Ay0
Nyz {z≤y,1≤y} Ayz where θ and ξ are obtained by instantiating resource variables in ρ and σ, respectively (see Section 2.2). This concludes the proof. One may ask whether such an embedding might work for BLL proper. We believe this to be unlikely for several reasons. In particular, it seems that BLL lacks a mechanism for turning the information about the size of the manipulated objects from being global to being local. In QBAL, this rˆ ole is played by first order quantifiers. As an example, considered the split function for lists of natural numbers that splits a list into two lists, one containing the even entries and one containing the odd entries. The type of that function in LFPL is L(N) L(N) ⊗ L(N) where L(·) denotes the type of lists that we have elided from our formal treatment for the sake of simplicity. In QBAL this function gets the type Lx (Ny ) ∃(u, v) : {u + v ≤ x}.Lu (Ny ) ⊗ Lv (Ny ) The only conceivable BLL formula for this function is Lx (Ny ) Lx (Ny ) ⊗ Lx (Ny ). In LFPL and in QBAL we can compose the split function with “append” yielding a function of type Lx (Ny ) Lx (Ny ) that can be iterated. In BLL this composition receives the type Lx (Ny ) L2x (Ny ) which of course is not allowed in an iteration. But a hypothetical compositional embedding of LFPL into BLL would have to be able to mimic this construction.
7
Embedding RRW
Ramified recurrence on words (RRW) is a function algebra extensionally corresponding to polynomial time functions introduced by Leivant in the early nineties [14]. Bellantoni and Cook’s algebra BC can be easily embedded into RRW. Given a word algebra W, id is the identity function on W and πim are the m-ary projection functions from m-tuples of terms into terms. Functions on W can be defined by composition, primitive recursion, and conditional selec, fεW ) denotes the function obtained from tion. The expression rec(fc1W , . . . , fcw W , f by primitive recursion. Similarly for comp(g, f1 , . . . , fn ) and fc1W , . . . , fcw ε W W cond(fc1W , . . . , fcw , f ). Not every function obtained this way is in RRW: inε W W deed, they correspond to primitive recursive functions on W. In Figure 3, a formal system for judgements in the form f : Wi1 × . . . × Win → Wi (where i1 , . . . , in , i are natural numbers) is defined. If such a judgement can be derived from the rules in Figure 3, then f is said to be an RRW function (the definition
Bounded Linear Logic, Revisited
93
ji = j id : Wi → Wi
εW : Wi cW : Wi → Wi
g : Wi1 × . . . × Win → Wi
πim : Wj1 × . . . × Wjm → Wj
fk : Wj1 × . . . × Wjm → Wik
comp(g, f1 , . . . , fn ) : Wj1 × . . . Wjm → Wi fcW : Wi1 × . . . × Win × Wi × Wj → Wi rec(fc1 , . . . , f
cw W
W
fcW : W
i1
× ... × W
in
, fεW ) : W j
fε : Wi1 × . . . × Win → Wi
i1
×W →W
× ... × W i
in
fε : W
i1
j
×W →W
i<j
i
× . . . × Win → Wi
cond(fc1 , . . . , fcw , fεW ) : Wi1 × . . . × Win × Wj → Wi W W
Fig. 3. RRW as a formal system
of RRW given here is slightly different but essentially equivalent to the original one [14]). Leivant [14] proved that RRW functions are exactly the polytime computable functions on W. But RRW can be compositionally embedded into QBAL, at least in a weak sense: Theorem 3. RRW can be embedded into QBAL. Suppose, in other words, that π : f : Wi1 × . . . × Win → Wi and that i < ij1 , . . . , ijm , while i = ik1 , . . . , ikh . Then, there exists an QBAL proof π : Wx1 , . . . , Wxn {xk1 ≤x,...,xkh ≤x} Wq(xj1 ,...,xjm )+x n where ( i=1 ψW ) ◦ π ◦ ϕW = f . Moreover · is weakly compositional. Quite interestingly, the proof of Theorem 3 (see [4]) is very similar in structure to the proof of polynomial time soundness for BC given in [3], which is based on the following observation: the size of the output of a BC function is bounded by a polynomial on the sizes of normal arguments plus the maximum of sizes of safe arguments. This cannot be formalized in BLL, because the resource polynomials do not include any function computing the maximum of its arguments. On the other hand, this can be captured in QBAL by way of constraints.
8
Conclusions
We presented QBAL, a new ICC system embedding both known systems of impredicative recursion in the sense of [9]. QBAL allows to overcome the main weakness of BLL, namely that all resource variables are global. In the authors’ view, this constitutes the first step towards unifying ICC systems into a single framework. The next step consists in defining an embedding of light linear logic into QBAL and the authors are currently investigating on that.
94
U. Dal Lago and M. Hofmann
References 1. Asperti, A., Roversi, L.: Intuitionistic light affine logic. ACM Transactions on Computational Logic 3(1), 137–175 (2002) 2. Barendregt, H.: The Lambda Calculus: Its Syntax and Semantics. In: Studies in Logic and the Foundations of Mathematics. North-Holland, Amsterdam (1984) 3. Bellantoni, S., Cook, S.: A new recursion-theoretic characterization of the polytime functions. Computational Complexity 2, 97–110 (1992) 4. Dal Lago, U., Hofmann, M.: Bounded linear logic, revisited. Extended Version (2009), http://arxiv.org/abs/0904.2675 5. Danos, V., Joinet, J.-B.: Linear logic and elementary time. Information and Computation 183(1), 123–137 (2003) 6. Girard, J.-Y.: Linear logic. Theoretical Computer Science 50, 1–102 (1987) 7. Girard, J.-Y.: Light linear logic. Information and Computation 143(2), 175–204 (1998) 8. Girard, J.-Y., Scedrov, A., Scott, P.: Bounded linear logic: A modular approach to polynomial-time computability. Theoretical Computer Science 97(1), 1–66 (1992) 9. Hofmann, M.: Programming languages capturing complexity classes. SIGACT News Logic Column 9, 12 (2000) 10. Hofmann, M.: Linear types and non-size-increasing polynomial time computation. Information and Computation 183(1), 57–85 (2003) 11. Hofmann, M., Scott, P.: Realizability models for BLL-like languages. Theoretical Computer Science 318(1-2), 121–137 (2004) 12. Lafont, Y.: Soft linear logic and polynomial time. Theoretical Computer Science 318(1-2), 163–180 (2004) 13. Leivant, D.: A foundational delineation of computational feasiblity. In: Sixth IEEE Symposium on Logic in Computer Science, Proceedings, pp. 2–11 (1991) 14. Leivant, D.: Stratified functional programs and computational complexity. In: 20th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Proceedings, pp. 325–333 (1993) 15. Marion, J.-Y., Moyen, J.-Y.: Efficient first order functional program interpreter with time bound certifications. In: Parigot, M., Voronkov, A. (eds.) LPAR 2000. LNCS, vol. 1955, pp. 25–42. Springer, Heidelberg (2000) 16. Murawski, A., Ong, L.: On an interpretation of safe recursion in light affine logic. Theoretical Computer Science 318(1-2), 197–223 (2004) 17. Sch¨ opp, U.: Stratified bounded affine logic for logarithmic space. In: 22nd IEEE Symposium on Logic in Computer Science, Proceedings, pp. 411–420 (2007) 18. Troelstra, A., Schwichtenberg, H.: Basic proof theory. Cambridge University Press, Cambridge (1996) 19. Wadsworth, C.: Some unusual λ-calculus numeral systems. In: Seldin, J.P., Hindley, J.R. (eds.) To H.B. Curry: Essays on Combinatory Logic, Lambda Calculus and Formalism. Academic Press, London (1980)
Partial Orders, Event Structures and Linear Strategies Claudia Faggian1 and Mauro Piccolo1,2, 1 2
Preuves, Programmes et Syst`emes, Paris VII (France) Dipartimento di Informatica, Universit` a di Torino (Italia)
Abstract. We introduce a Game Semantics where strategies are partial orders, and composition is a generalization of the merging of orders. Building on this, to bridge between Game Semantics and Concurrency, we explore the relation between Event Structures and Linear Strategies. The former are a true concurrency model introduced by Nielsen, Plotkin, Winskel, the latter a family of linear innocent strategies developed starting from Girard’s work in the setting of Ludics. We extend our construction on partial orders to classes of event structures, showing how to reduce composition of event structures to the simple definition of merging of orders. Finally, we introduce a compact closed category of event structures which embeds Linear Strategies.
1
Introduction and Background
Game Semantics has been successful in providing accurate (fully abstract) models to programming languages and logical systems; the key feature of such a semantics is to be interactive. Computation is interpreted as a play (an interaction) between two players, where Player (P) represents the program/proof, and Opponent (O) represents the environment, the context. The set of the possible plays represents the operational behavior of a term, and is called a strategy. The play should respect some “rules of the game”, expressed by an arena, which denotes a type. Since interaction is the main feature also of a concurrent system and of process calculi, it appears natural to search for an extension of Game Semantics able to model parallel and concurrent computation. This is indeed an active line of research, even though still at its early stage. A way to allow parallelism is to relax sequentiality, and have plays (i.e. traces of computation) which are “partial orders” instead of totally ordered sequences of moves. The intent of this approach is actually two-folded: to allow for parallelism, and to provide partial order models of sequential computation, i.e. models where the scheduling in which the actions should be performed is not completely specified, while it is still possible to express constraints: certain tasks may have to be performed before other tasks; other actions can be performed in parallel, or scheduled in any order.
The second author is supported partially by MIUR-Cofin’07 CONCERTO Project.
P.-L. Curien (Ed.): TLCA 2009, LNCS 5608, pp. 95–111, 2009. c Springer-Verlag Berlin Heidelberg 2009
96
C. Faggian and M. Piccolo
A Game Semantics where strategies would be partial orders has been first propounded by Hyland in a seminal talk in Lyon. Our paper is an effort to pursue this direction. We introduce a Game Semantics where strategies are partial orders, and composition is the merging of the orders; on this basis, we are led to investigate how a class of strategies, here called linear strategies, fits inside a larger picture where we have true concurrency models. Linear strategies. In this paper, we use the name linear strategies to designate a family of strategies originated by the work of Girard in Ludics [10]. Ludics can be seen as a Game Semantics where the foundational role of interaction is taken even further; moreover, many features (actions, names, a built-in observational equivalence) make it close to process calculi. We mention that, as established in [7], Ludics has a close relation with the Linear Pi-calculus [26], i.e. a process calculus which is asynchronous and internal (see [20]). The strategies defined in Ludics (called designs in the original paper) can be seen as a (linear) variant of Hyland-Ong innocent strategies. In [5] was then proposed a “more parallel” version of Ludics, leading to the introduction of graph strategies, called L-nets; these are in many ways close to proof-nets. Exploring this and moving through several degree of sequentiality is the object of [4]. True concurrency. In the literature, there are two main approaches in the study of models for parallel and concurrent programming languages. The first one is represented by interleaving models, that describe a concurrent system by means of possible scheduling of concurrent actions (all traces). The second one is represented by causal models, (also called true-concurrent models) in which concurrency, dependency and conflict relations among actions are directly expressed. A fundamental instance of true concurrent models are event structures, introduced by Nielsen, Plotkin and Winskel [19,23,24] as a theory combining Petri Nets and Domain Theory. An event structure describes a concurrent system in terms of a partial order, which specifies the causality relation between actions, and a conflict relation, which specifies what actions are mutually exclusive. In a previous work [6], we have proposed event structures as a mathematical framework unifying proof-nets and linear strategies. Building on previous work by Varacca and Yoshida [22], there we have given a general definition of composition, based on an abstract machine, which realizes both event structures and game semantics composition. Moreover, we have shown that linear strategies (and proof-nets, in a sense) correspond to a particular subclass of event structure called confusion free event structures; these latter model a kind of well-behaving non-determinism, in which the choice is localized in “cells”. Contributions of this paper. In this paper, we introduce a Game Semantics, where strategies are partial orders (called po strategies) and composition is a generalization of merging of order (Section 2). The merging of two orders has been defined by Girard in [10] as the transitive closure of their set-theoretical union. Under certain acyclicity conditions, the result is a partial order. This is the base of composition of linear strategies, and also of our po strategies. More precisely, a central contribution of this paper is to generalize this operation,
Partial Orders, Event Structures and Linear Strategies
97
without requiring any acyclicity condition. The main advantage of this definition is that it appears mathematically clean and attractive, and this translates into direct and -we believe- clearer proofs. The Game Semantics we defined is rather general, since we do not require our strategies neither to be Player/Opponent alternating nor to be sequential. Moreover we admit an additional neutral polarity; intuitively, neutral actions correspond to internal τ -actions of process calculus. Following an idea proposed by Hyland, we show how to extend the notion of innocence to partial order strategies, i.e. to a setting which is parallel and non-alternating. In the Hyland-Ong game model [12], innocence is an important property on strategies, in order to obtain a well-defined Cartesian closed category which provides a model for PCF and whose effective part consists of morphisms (strategies) that are PCF-definable. In this paper we will see how to extend innocence to a parallel and non alternating setting showing that such a condition allow us to obtain a well defined category where arenas are objects and po strategies are morphisms. In Section 3 we show how to generalize this construction to event structures, in order to define a general setting embedding linear strategies. Arenas are generalized to ES-arenas and po-strategies become typed event structures. All these structures can be described in terms of special families of po-strategies. Using this characterization, we show how to define a simple notion of composition of typed event structure relying on the definition of merging of partial orders. This definition of composition corresponds to the one given in [22]. We conclude then by generalizing the category of innocent po-strategies to a compact closed category of innocent event structures. Finally, starting from this category, we will retrieve linear strategies as a sub-class. Related work. The exploration of concurrent Game Semantics has been initiated by Abramsky and Melli`es with the introduction of Concurrent Games [2], which give a fully complete model of Multiplicative-Additive Linear Logic; strategies are here closure operators. Melli`es and Mimram have then developed the fertile line of asynchronous games [17,18], where plays are seen as Mazurkiewicz traces, and innocence receives a diagrammatic formulation. Since the purpose of this line of work is a better understanding and a generalization of innocence, there are several connections between our work and in particular [18], where strategies also do not require neither alternation nor sequentiality. A main difference is the fact to work with traces or with partial orders, which is the choice which allows us to rely on the merging of orders for composition. Graph strategies have been introduced by Hyland, Schalk [14,21]. Partial order models have then be proposed by McCusker [16], where partial order models where used to study programming languages. The work of Curien, Faggian and Maurel [4,5] also fit in this line. Game semantics for languages equipped with concurrency features have been developed by Ghica, Laird and Murawsky [15,9]. Strategies are here described as set of traces.
98
2
C. Faggian and M. Piccolo
Partial Orders as Strategies
In this section, we introduce a notion of arena and a notion of strategy on an arena, where a strategy is a partial order (po strategies). We follow a minimalist approach, in the spirit of [11,3]. We first introduce a rather general setting in which we have po strategies and a notion of parallel composition (which is well defined and associative); we then gradually add properties (innocence, alternation, arborescence), and show that these properties are all preserved by composition. Furthermore, by introducing a notion of innocence, we eventually obtain (Section 2.4) a category, where the objects are arenas, the arrows are innocent po strategies, and their composition factorizes as parallel composition plus hiding. However, since both parallel composition and hiding have an independent interest, we discuss them separately. At the end of Section 2.3, after giving the definitions, we will discussion the connection between the notions we introduce and the standard notion of innocent strategy. We first recall some preliminary notions on partial orders. A strict partial order (spo for short) is a pair X, <X where X is a set, and <X is binary, transitive and irreflexive relation and it is often denoted simply as X. We will use X, Y, Z, W, . . . to range over spos. We will move freely between a strict partial order X, <X and the partially ordered set or poset X, ≤X , where ≤X is the reflexive closure of <X . Given an element x ∈ X, the set of its enabling elements is [x) = {x ∈ Xx <X x}. An spo is well founded if the set [x) is finite for all x ∈ X. It is arborescent if it is well founded and each x ∈ X has at most one immediate predecessor; we call forest a strict partial order which is arborescent (we will talk of roots and children in the obvious way). A subset S ⊆ X is said to be downward-closed if for all x ∈ S, if y <X x then y ∈ S. 2.1
Arenas and Po Strategies
A polarity is an element of the set {+, −, ±}: The positive polarity + corresponds to Player, while the negative polarity − corresponds to Opponent. The neutral polarity ± plays a role similar to that of a τ action in a process calculus. Given a polarity , its dual ⊥ is defined as +⊥ = − and −⊥ = +, while ±⊥ is undefined. An arena is a set of elements, here called actions, together with a polarity for each action, and possibly some structure of order on the actions (which may express causality or dependency). Our choice here is that the order to is a forest (but this is not necessary). Definition 1. An arena is a set Γ , whose elements are called actions, together with a strict partial order relation <Γ and a polarization function πΓ : Γ → {+, −, ±}, which satisfies: (1.) Γ, <Γ is a forest. (2.) For each a ∈ Γ , if π(a) = ±, then π(c) = ±, for all c ∈ Γ which are comparable with a. With a slight abuse of notation, we will denote in the same way the arena and the set of actions. We use Greek capital letters to range over arenas. Given an arena Γ , we use a, b, c, . . . to range over its actions. A action a is initial if it is a root
Partial Orders, Event Structures and Linear Strategies
99
of Γ, <Γ . If b is immediate predecessor of c, we say that b justifies c, and write b Γ c. An arena Γ is called +/- polarized if πΓ (Γ ) ⊆ {+, −}, it is neutral if πΓ (Γ ) = {±}. An arena Γ is alternating if a1 Γ a2 ⇒ π(a1 ) = π(a2 )⊥ . Observe that our definition of arena is rather general, and does not require alternation. By definition, if b Γ c, either none of them is neutral, or both are neutral. Constructions on arenas. Given two arena Γ1 , Γ2 which are disjoint, i.e. Γ1 ∩ Γ2 = ∅, we write Γ, Δ or, for better readability, Γ Δ for Γ1 ∪ Γ2 with the order and polarization which are induced by the Γi ’s. Given an arena Γ , the neutral arena Γ ± is the arena having the same actions and order relation as Γ , but neutral polarity for all its actions: πΓ ± (a) = ±, for each a ∈ Γ . Given a +/- polarized arena Γ , its dual Γ ⊥ is the arena having the same actions and order relation as Γ , but inverting their polarity: πΓ ⊥ (a) = πΓ (a)⊥ . Remark 1. Observe that Γ ⊥ is not defined on neutral arenas. By writing Γ ⊥ we implicitly assume that Γ is +/- polarized. Po strategies. We are interested in spos X whose elements are taken on an arena Γ . We require that, for the elements, X ⊆ Γ and, for the order, <X respects and refines <Γ (see Condition (1.) below). We will call such spos po strategies. Definition 2. Let Γ be an arena. A spo X on Γ is a well founded spo such that X ⊆ Γ (as sets of actions). X is a a po strategy on the arena Γ , written X : Γ when it satisfies: (1.) For each b ∈ X and a ∈ Γ , if a Γ b then a ∈ X and a <X b. (2.) For each c which is maximal in X, πΓ (c) = +. Both conditions reformulate standard conditions in Game Semantics; the first condition is usually called justification. The second one means that the strategy always has an answer to an opponent move. Observe that each element in X : Γ has a polarity, the one given by πΓ . Given a, b ∈ X, we write a ←X b if a is an immediate predecessor of b according to <X . We remind that we write a Γ b for the same relation in the arena. Let X and Y be spos. If X : Γ, is a po strategy, we write Y X if Y ⊆ X is downward closed and for all a, b ∈ Y a
Parallel Composition
If X is a po strategy on Γ , and Γ = Γ Γ we define X Γ = {c ∈ X|c ∈ Γ } to be the restriction of X to Γ . We compose two po strategies X1 , X2 when they are compatible, that is X1 : Γ1 Λ⊥ and X2 : Λ Γ2 (Γ1 , Γ2 , Λ disjoint). Definition 3 (Parallel composition). Given two orders, Z1 and Z2 , we write Z1 Z2 for the transitive closure of Z1 ∪ Z2 (which does not need to be an order).
100
C. Faggian and M. Piccolo
Let X1 : Γ1 Λ⊥ and X2 : Λ Γ2 (Γ1 , Γ2 , Λ disjoint). The actions on the common arena Λ are called private. We define ⎧ ⎫ Y = Y1 Y2 , ⎨ ⎬ Int(X1 , X2 ) = Y spo on Γ1 Γ2 Λ± | ∃Y1 , Y2 s.t. Y Γ1 Λ⊥ = Y1 + X1 ⎩ ⎭ Y ΛΓ2 = Y2 + X2 We define the parallel composition of X1 , X2 as X1 X2 = max Int(X1 , X2 ). We need to prove that Int(X1 , X2 ) has a unique maximal element. The proof makes essential use of the following immediate Lemma. Lemma 1. Let X1 , X2 and Y be as in Definition 3. If Y1 = Y Γ1 ,Λ⊥ X1 and Y2 Γ2 ,Λ X2 , then for each private action c, c ∈ Y1 iff c ∈ Y2 . Proposition 1. The set Int(X1 , X2 ) given in Definition 3 has a unique maximal element (hence, parallel composition is well defined). Proof. Let U = U1 U2 and V = V1 V2 both belong to Int(X1 , X2 ), where for each i ∈ {1, 2}, Ui = U Γi Λ and Vi = V Γi Λ are downward closed subsets of Xi given by Definition 3. Let us set Y1 = U1 ∪V1 and observe that Y1 + X1 (and similarly for Y2 ). We prove that Y = Y1 Y2 is an spo. Let Y = (Y,
Theorem 2 (Associativity). If X1 , X2 , X3 are po strategies which are pairwise compatible, we have that (X1 X2 )X3 = X1 (X2 X3 ). Proof. Let (X1 X2 )X3 = Z,
Partial Orders, Event Structures and Linear Strategies
101
In the next section, we show that composition preserves several interesting properties. We will need the following easy observations. Proposition 2. Let a ∈ X1 X2 : Γ1 Γ2 Λ± , with X1 : Γ1 Λ⊥ and X2 : Γ2 Λ. Then (1.) If a is private (a ∈ Λ), then a ∈ X1 and a ∈ X2 . Its polarity is neutral. (2.) Otherwise, either a ∈ X1 (and a ∈ X2 ) or a ∈ X2 (and a ∈ X1 ). Moreover, assuming a ∈ X1 , then c ← a (resp. a ← c) in X1 X2 iff c ←X1 a (resp. a ←X1 c); similarly if a ∈ X2 . 2.3
Innocence (and Alternation, and Arborescence)
Composition of po strategies is associative, but -as we will see- it is not possible to define a strategy which behaves as the identity for the composition. This motivates the restriction to a class of po strategies, which we call innocent, for reasons we discuss at the end of this section. Composition preserves innocence. Moreover, more standard notions of strategies, such as arborescent strategies and alternating strategies, will be a subclass of innocent po strategies. Definition 4. We say that a po strategy X : Γ is innocent when for all b, c ∈ X, if b ←X c and (πΓ (c) = − or πΓ (b) = +) then b Γ c Observe that up to now, we have been rather general. In particular, in our definitions we do not require alternation in the polarity of the actions. Remark 2. If the arena Γ is alternating and +/- polarized, then our innocence condition implies +/- alternation in X : Γ . Remark 3. Innocent po strategies allow neutral actions. The innocence condition implies that immediate predecessors (resp. successors) of neutral actions are either negative or neutral (resp. either positive, or neutral). Proposition 3. If X1 : Γ1 Λ and X2 : Γ2 Λ⊥ are innocent, then (1.) X1 X2 : Γ1 Γ2 Λ± is innocent. (2.) Moreover if X1 , X2 are forests, then X1 X2 is a forest. Proof. (1.) Assume c ← a in X1 X2 = Y1 Y2 , and π(a) = − or π(c) = +. By Remark 2, for one of the two Yi (i ∈ {1, 2}), we have c ←Yi a. Hence, by innocence of Yi , c Γi a. (2.) Let Y = X1 X2 , with Y = Y1 Y2 , defined as in 3. Let T be a maximal spo such that T is a forest and T Y . We consider a minimal a ∈ Y s.t. a ∈ T . We observe that (i) each immediate predecessor of a in Y is an immediate predecessor of a in either Y1 or Y2 ; (ii) if a ∈ Y1 (resp. a ∈ Y2 ), a has at most one predecessor. We now prove that a has a unique predecessor in Y , hence the restriction of Y to T ∪ {a} is still a forest. If a is not private, the result is immediate by Proposition 2 and by (ii). The same is true if a is private, and root in one of the Yi . If a is private, let us assume πΛ (a) = −. Let z ←Y2 a and b ←Y1 a. By Innocence of Y1 , we have that b Λ a. By Justification, we have that b ≤Y2 z. Hence z is the only possible immediate predecessor of a also in Y .
102
C. Faggian and M. Piccolo
Discussion. Linearity and pointers. The strategies we have defined are linear, in the sense that there are no repetitions of actions. For this reason, pointers are not required. In fact, for each action c in the strategy there is a unique action b which justifies c. One can also say that pointers are implicit: c points to b. Innocence. Intuitively, innocence captures the idea that Player is not able to see Opponent’s internal calculations; a Player strategy in the game is completely determined by the piece of the play it can see (called view). Since an innocent strategy is completely determined by the views, while the most standard presentation of a strategy is as the set of all its possible plays, an innocent strategy can equivalently be described as a set of views (see [11,3]). This is the approach we follow here, in a sense we are going to explain. It is immediate to associate to a po strategy X a set of views: following the construction developed in [4], we can associate to each x ∈ X the restriction of (X, <) to the set {x ≤ x} (in a parallel setting, a view is not a sequence of action, but a partial order.) One should now see that Definition 4 generalizes the definition of what is a views to a setting which is parallel and non-alternating. In the standard approach, one call view a play where every O move is justified by the immediately preceding P move. This captures the idea that the only information that Player has on O moves is the dependency in the arena. Our condition exactly says that the strategy cannot refine the order given by the Arena on O actions. 2.4
Arenas and Innocent Po Strategies as a Category
In this section, we show that we can organize what we have seen into a category, where the objects are +/- polarized arenas, and the arrows are innocent po strategies. We define composition as standard in Game Semantics: composition = parallel composition + hiding. To complete the construction, we then verify that we have an identity arrow for each object. Hiding consists in removing the private actions, which correspond to “internal communication”, i.e. the actions which are used in the parallel composition to make the two structures communicate. The following is immediate (using Remark 3) Proposition 4 (Hiding). Let X : Γ Λ± be innocent and X := X Γ . We have that X : Γ is a po strategy. Moreover (i) if X is innocent then X is innocent; (ii) if X is arborescent then X is arborescent. Composition preserves innocence, and in that case also arborescence and alternation, as these properties are preserved by both parallel composition and hiding. Putting all pieces together, we have the following Definition 5. Let X1 : Γ1 Λ and X2 : Γ2 Λ⊥ (Γ1 , Γ2 , Λ disjoint). We define their composition as X1 ; X2 = (X1 X2 ) Γ1 ,Γ2 Theorem 3. Let X1 : Γ1 Λ and X2 : Λ⊥ Γ2 . Then X1 ; X2 : Γ1 Γ2 . Moreover, if X1 , X2 are innocent, we have the following: (1.) X1 ; X2 is innocent. (2.) If X1 , X2 are po strategies on alternating arenas, then X1 ; X2 is alternating. (3.) If X1 , X2 are arborescent, then X1 ; X2 is arborescent.
Partial Orders, Event Structures and Linear Strategies
103
Identity (copycat). In this section we introduce a Copycat strategy, which generalizes what is called fax in [10] and copycat in Game Semantics. Our approach closely corresponds to that proposed by Hyland in [13]. All along this section we fix two +/-polarized arenas Δ and Δ , which are disjoint and isomorphic i.e. there is an order isomorphism φ : Δ → Δ such that πΔ (a) = πΔ (φ(a)). We say that φ is a renaming function, and say that Δ and Δ are equal up to renaming. We extend this notion to po strategies too. Given two po strategies X : Γ Δ , X : Γ Δ , we say that they are equal up to renaming if X is obtained from X by substituting each occurrence of a ∈ Δ with φ(a) ∈ φ(Δ). The copycat is a strategy idΔ→φ(Δ) which copies any action from Δ into the corresponding action in φ(Δ). Definition 6 (Copycat). Let Δ and Δ = φ(Δ) be two arenas which are equal up to renaming. We define idΔ→Δ : Δ⊥ Δ as the spo X, where the order is that induced by <Δ and <Δ with the addition of all the pairs {c ←X φ(c) | c ∈ Δ, πΔ (c) = −} and {φ(c) ←X c | c ∈ Δ, πΔ (c) = +}. Example 1. Let Δ⊥ and Δ be the isomorphic arenas represented below. We illustrate idΔ→φ(Δ) in the following picture, where we indicate with a dashed line the order which is added w.r.t. the arenas. Δ⊥
Δ
idΔ→φ(Δ) b+ 2 a− 2
a+ 1 a− 2
a+ 1
b− 1
b+ 2 b−
a+
b− 1
a+ b−
Remark 4. If the arena is alternating, the definition above gives us the standard copycat strategy. Proposition 5 (Identity). (1.) idΔ→φ(Δ) defined in 6 is a innocent po strategy. (2.) idΔ→φ(Δ) φ(Δ) = φ(idΔ→φ(Δ) Δ ). (3.) Let X : Γ Δ be a innocent po strategy. Then X; idΔ→φ(Δ) : Γ φ(Δ) is a innocent po strategy φ(X) which is equal to X up to renaming. Let us conclude with an example of the fact that, without the Innocence condition, the composition with the copycat does not produce the desired effect. Let us consider three singleton arenas Γ1 = {a}, Γ2 = {b}, Γ3 = {c}, where πΓ1 (a) = πΓ2 (b) = πΓ3 (c) = +. We then consider the following po strategy X : Γ1 Γ2 Γ3 , composed with idΓ1 →φ(Γ1 ) . b+
a+
X:
c+
φ(a)+
idΓ1 →φ(Γ1 ) :
a−
b+
X; idA→φ(A) :
φ(a)+ c+
Hiding and observational equivalence. The neutral actions which we hide are silent actions which correspond to an internal synchronization. Hiding gives
104
C. Faggian and M. Piccolo
a canonical representation of an event structure with respect to observational equivalence. This idea is made precise in process calculi by the notion of weak bisimilarity. By analogy with labelled transitions in process calculi, we generate a labelled a transition system on spos as follows: if a is minimal in X then X −→ X \ {a}. We then define the following reductions (i) =⇒ is the reflexive transitive closure τ a a of −→, where τ denotes any neutral action; (ii) =⇒ is =⇒ −→ =⇒, where a is a non-neutral action. We define the weak bisimilarity on po strategies as the greatest binary symmetric relation ≈ satisfying the following property: whenever X1 ≈ X2 and a a X1 −→ X1 then there exists X2 such that X2 =⇒ X2 and X1 ≈ X2 . we have the following Proposition 6. Let X : Γ Λ± , s.t. Γ is +/- polarized. We have that X ≈ X Γ .
3
Event Structures as Strategies
In this section, we extend the construction we have seen for partial orders to event structures. Definition 7. An event structure is a triple E = E, ≤, such that (1.) E, ≤ is a well-founded partial order. (2.) is an irreflexive and symmetric relation, called conflict relation which is hereditary, i.e. for every e1 , e2 , e3 ∈ E, if e1 ≤ e2 and e1 e3 then e2 e3 . Given two event structures E1 = E1 , ≤1 , 1 and E2 = E2 , ≤2 , 2 with E1 ∩ E2 = ∅, we define E1 E2 = E1 ∪ E2 . ≤1 ∪ ≤2 , 1 ∪ 2 . With an abuse of notation, given an event structure E, we will confuse E with the set of its events E, writing e ∈ E (resp. x ⊆ E) for e ∈ E (resp. x ⊆ E). Causal order and conflict are mutually exclusive. Two events which are not causally related nor in conflict are said to be concurrent. A conflict e1 e2 is said inherited from the conflict e1 e2 if e2 ≤ e2 . If the conflict e1 e2 is not inherited from any conflict, we say that it is immediate, written e1 μ e2 . We denote with (resp. μ ) the reflexive closure of (reps. μ ). Given an event structure E a configuration is a set x ⊆ E which is downward closed and conflict free, i.e. if e, e ∈ x then it is never the case that e e . For example, given e ∈ E, the sets [e) and e = [e) ∪ {e} are configurations. Observe that a configuration x is implicitly a partially ordered set (and so a spo), where the partial order is the restriction of the partial order of E to x. This fact is key to our approach, together with the fact that important relations in an event structure can be recovered from its configurations, and in fact an event structure can be described also as a special set of configurations, as we sketch below. Let us denote with C(E) the family of all configurations of E. C(E) ordered by inclusion forms a coherent, finitary prime algebraic domain (a dI-domain
Partial Orders, Event Structures and Linear Strategies
105
satisfying an additional condition [24]) whose set prime elements is {e | e ∈ E}. A converse result holds too, i.e. every coherent finitary prime algebraic domain can be described using an event structure whose events are the prime elements, the order between events is inherited from the order between prime elements and two events are in conflict when they do not admit an upper bound, as prime elements of the domain. The following result, due to Winskel [25, pp. 60-61], summarizes the previous notions. Theorem 4 ([25]). Coherent finitary prime algebraic domain and event structures are equivalent. More details can be found in [25]. This fact will allows us to rely on the results we developed in the previous section. Event structures form the class of objects of a category, whose morphisms are given by any partial map λ : E1 → E2 satisfying λ(x) ∈ C(E2 ) x ∈ C(E1 ) ⇒ ∀e1 , e2 ∈ x.λ(e1 ), λ(e2 ) both defined ∧ λ(e1 ) = λ(e2 ) ⇒ e1 = e2 This category admits all finite products, co-products and pull backs [25]. A morphism is said to be total when the underlying map is. 3.1
Typed Event Structures
We now introduce the notion of typed event structures. Informally, it consists in a pair of event structures, one describing a process (a strategy) and the other one denoting a type (an arena); the typing relation between the two is represented by the existence of a total morphism relating them. Definition 8. An ES-arena is a pair Γ = Γ, Γ where Γ is an arena and Γ is a binary relation such that (1.) Γ, ≤Γ , Γ is an event structure (2.) πΓ is such that (i.) if πΓ (a) = ± then πΓ (b) = ± for all b s.t. b Γ a; (ii.) if a1 μ a2 then πΓ (a1 ) = πΓ (a2 ). All along this section, we will consider an ES-arena Γ both as an event structure and as an arena in the sense of Section 2 (by ignoring the conflict relation). Furthermore, it is clear that each configuration x ∈ C(Γ) with the induced polarization function is also an arena in the sense of Section 2. Thus, we can adapt all the definitions given in Section 2 (alternation, neutrality, duality, +/polarization . . . ) to ES-arenas. In particular, given two disjoint ES-arenas Γ1 = Γ1 , Γ1 and Γ2 = Γ2 , Γ2 we define Γ1 Γ2 = Γ1 Γ2 , Γ1 ∪ Γ2 . Definition 9. Let Γ be an ES-arena, E and event structure. We say that E is typed in Γ (written E : Γ) if there is a total morphism λ : E → Γ, called labeling morphism, satisfying (1.) if e ∈ E is maximal w.r.t. the order of E, then πΓ (λ(e)) = +. Let E : Γ be a typed event structure with a labeling morphism λ, and let x ∈ C(E) be a configuration. Let us consider the structure λ(x), <, where the order < is defined as λ(e1 ) < λ(e2 ) when e1 < e2 (e1 , e2 ∈ E), λ(x), < is a well-defined spo (since λ is a total morphism and an injective map on configurations) and it
106
C. Faggian and M. Piccolo
is isomorphic to x (viewed as spo). We say that λ(x), < a slice of E when x is such that for all e ∈ x, if e is maximal then πΓ (λ(e)) = +. We denote with Slices(E) the set of all slices of E and we use S, S1 , S2 , . . . to range over slices. Lemma 3. Let E : Γ be a typed event structure and let S ∈ Slices(E). Then S = x, < is a po strategy on Γ. The following definition characterizes when a set of slices corresponds to a typed event structure; in this way, we are able to present a typed event structure as a set of spos (which are po strategies). Definition 10. Let Γ be an ES-Arena. A family F of po strategies on Γ ordered by the order (see Section 2) is said to be a po strategies family when it satisfies ⊆ F such that, for every (1.) If X ∈ F and Y + X then Y ∈ F. (2.) For all X X1 , X2 ∈ X they admit an upper bound in F , we have X ∈ F . Observe that the structure of F is very close to the one of a coherent finitary prime algebraic domain. Proposition 7. (1.) Let E : Γ be a typed event structure. Then Slices(E) is a po strategies family. (2.) Let F be a po strategies family on Γ. Then there exists a typed event structure Ev(F ) : Γ such that Slices(Ev(F )) is isomorphic to F . Proof. (1.) can be obtained essentially as a corollary of Theorem 4. To prove (2.), given X ∈ F we define a view to be any subset cX X having a top
element, denoted top(cX ). We define Ev(F ) = E, ≤, as (i) E = X∈F {cX X|cX view} (we denote sets as sequences of their elements without repetitions). (ii) ≤ is the restriction of to E. (iii) cX cX when there is no Y ∈ F such that cX cX Y . We can check that Ev(F ) is an event structure and we can observe by Theorem 4, that Slices and Ev are naturally isomorphic. Moreover Ev(F ) is typed on Γ by taking λ(cX ) = top(cX ). We now define a notion of parallel composition between typed event structure, using the results given in the previous section. Definition 11. Let E1 : Γ Λ⊥ and E2 : Λ Δ be two typed event structures. Then we define E1 E2 = Ev {S1 S2 | S1 ∈ Slices(E1), S2 ∈ Slices(E2 )} where S1 S2 is the parallel composition between spos, defined in Section 2. Theorem 5. Let E1 : Γ Λ⊥ and E2 : Λ Δ. Then E1 E2 : Γ Λ± Δ⊥ . Theorem 6 (Associativity). Let E1 : Γ1 Λ⊥ , E2 : Λ Γ2 Δ⊥ , E3 : Δ Γ3 . Then E1 (E2 E3 ) = (E1 E2 )E3 . We remark that the definition of parallel composition we give is similar to the technique of normalization by slices used to define normalization of designs [10] or L-nets [5] in Ludics.
Partial Orders, Event Structures and Linear Strategies
3.2
107
A Category of Innocent Event Structures
In this section we define a category having ES-arenas as objects and (a subclass of) typed event structures as morphisms. Once again, we rely on the definitions given for po strategies. Definition 12. Let E : Γ be a typed event structure. We say that E is innocent when for all S ∈ Slices(E), S = x, < is an innocent po strategy on Γ. By definition of parallel composition and as a consequence of Proposition 3, we observe that the class of innocent event structures is closed under parallel composition. We then define composition as parallel composition + hiding. ⊥ Definition 13. Given two innocent event structures E1 : Γ Λ , E2 : Λ Δ, we define E1 ; E2 = Ev {S1 ; S2 | S1 ∈ Slices(E1 ), S2 ∈ Slices(E2 )} , where S1 ; S2 is the composition of innocent po strategies defined in Section 2.
Using Proposition 3, we can prove that the class of innocent event structures is closed under composition and it is associative. Moreover, we can define a copycat event structure and prove that it plays the role of an identity with respect to the composition. Definition 14. Let Γ, Γ be two disjoint +/- polarized ES-Arenas which are isomorphic through the isomorphism φ : Γ → Γ and such that for all e ∈ Γ, πΓ (e) =
πΓ (φ(e)). We define the copycat event structure as idΓ→Γ = Ev {idx→φ(x) | x ∈ C(Γ)} , where idx→φ(x) is the copycat spo defined in Section 2.
Proposition 8. idΓ→Γ : Γ Γ⊥ is an innocent event structure and it is the identity w.r.t. composition, i.e. for all innocent E : Γ Δ, E is isomorphic to idΓ→Γ ; E. This result allows us to define a category of innocent event structures. We first introduce some notation. Given two event structures E1 , E2 , we write E1 ∼ E2 when they are isomorphic in the category of event structures and we denote with isoE,E : E → E the isomorphism between them. We denote with [E]∼ = {E | E ∼ E} the class of event structures isomorphic to E. Moreover, given an arena Γ, we define Γ = {Γ ∈ [Γ]∼ | ∀a ∈ Γ.πΓ (a) = πΓ (isoΓ,Γ (a))} i.e. the set of all arenas isomorphic and inducing the same polarity function with respect to a given arena Γ. Definition 15. The category InnEv is the category defined as follows. (1.) The class of objects is Obj(InnEv) = {Γ | Γ +/- polarized ES-arena}. (2.) The set of morphisms between Γ and Δ is InnEv(Γ, Δ) = {[E]∼ | E : Δ Γ⊥ innocent} (3.) The composition of [E1 ]∼ : Γ → Λ and [E2 ]∼ : Λ → Δ is defined as [E2 ]∼ ; [E1 ]∼ = [E1 ; E2 ]∼ : Γ → Δ (4.) Let Γ be an object. and let Γ ∈ Γ be disjoint from Γ. Then, the identity is defined as idΓ = [idΓ→Γ ]∼ : Γ → Γ.
108
C. Faggian and M. Piccolo
Theorem 7. InnEv is a compact closed category. Proof. We can define the tensor product in the following way (1.) Γ Δ = Γ Δ; (2.) given two morphisms [E1 ]∼ : Γ1 → Δ1 and [E2 ]∼ : Γ2 → Δ2 , we have [E1 ]∼ [E2 ]∼ = [E1 E2 ]∼ . It is naturally commutative, associative and it has ∅ as neutral element. Observe also that in this category every object Γ has a dual Γ⊥ = Γ⊥ : it induces a contra-variant functor (−)⊥ defined as above for objects and given a morphism [E]∼ : Γ → Δ we have that ⊥ ⊥ [E]⊥ ∼ = [E]∼ : Δ → Γ . We can use it to define the bifunctor as Γ ⊥ Δ = Γ Δ and we can prove the required adjunction property. 3.3
Retrieving Linear Strategies: Confusion Freeness
In this section we sketch how linear strategies fit into the picture we have been developing, and in fact appear as a subclass of the category InnEv. In [6], we have shown that a feature of event structures representing linear strategies is that they are confusion free. Confusion free event structures describe a form of localized non-determinism, where the non-deterministic choice is localized in cells. Given an event structure E, a cell C ⊆ E is a maximal set of events which are pairwise in immediate conflict, and have the same enabling set: ∀e, e ∈ C.e μ e ∧ [e) = [e ). An event structures is said confusion free when cells are closed under immediate conflict. The relation of conflict models a choice: two events which are in conflict live in two different evolutions of the system. Since conflict is inherited, the point where a choice is made corresponds to events in immediate conflict, i.e. a cell. The construct in process calculus which corresponds to a cell is a guarded sum: each events which is a cell can be seen as a guard on that choice. According to the polarity of the elements of the cell, we would hence have a sum which is guarded by output, input, or τ actions (resp. +, -, or ±). In [6], we showed a correspondence between (negative) cells and additives in Linear Logic. We are now going to define a category where the objects are confusion free ES-arenas and morphisms are confusion free event structures which are innocent. Such a category is derived from InnEv, but we first need to strengthen the conditions imposed to the labeling morphism. This is because the class of innocent confusion free event structures on a confusion free ES-arena (in the sense of Definition 9) is otherwise not closed neither composition. Definition 16. Let E : Γ be a innocent event structure. We say that it is a conf.-free innocent event structure when (1.) E and Γ are confusion free and (2.) if e1 μ e2 then (i.) λ(e1 ) μ λ(e2 ) and (ii.) πΓ (λ(e1 ), πΓ (λ(e2 )) = +. Condition (1.) requires that both the event structure E and the arena Γ are confusion free. Now Γ has really the shape of a MALL formula tree, where immediate conflict codes the additive connectives. Condition (2.) requires that two events which are in immediate conflict in E are in immediate conflict also in Γ and that they are never positive. Observe that this, together with Condition
Partial Orders, Event Structures and Linear Strategies
109
(2.ii) of Definition 8 tells us that events belonging to the same cell of E are labeled with actions in immediate conflict in Γ. Moreover, those actions have the same polarity and such a polarity can only be either negative or neutral. The correspondence innocence/asynchrony (see [7,8]) supports this constraint, which is consistent with the fact in an asynchronous calculus only input-prefixed (external choice) and τ -prefixed (internal choice) terms can be summands in a guarded sum. The following result allows us to define a subcategory of InnEv whose objects are given by equivalence classes of confusion free ES-arenas and whose morphisms are given by equivalence classes of conf.-free innocent event structures. Theorem 8. Let E1 : Γ Λ⊥ and E2 : Λ Δ be two conf.-free innocent event structures. Then (1.) E1 E2 : Γ Λ± Δ is a conf.-free innocent event structure. (2.) E1 ; E2 : Γ Δ is a conf.-free innocent event structure. In the class of conf.-free innocent event structures we are now able to retrieve the family of linear strategies, by imposing opportune constraints. The fundamental fact is that linear strategies can be described as partial orders with a conflict relation (as detailed in [7]). We consider the following constraints on conf.-free innocent event structures: arborescence, sequentiality, acyclicity. An event structure E = E, ≤, is arborescent when E, ≤ is. A conf.-free innocent event structure E : Γ is sequential when it is arborescent and for all S1 , S2 ∈ Slices(E) S1 ∩ S2 ∈ Slices(E) (where the intersection of two slices is the set-theoretical intersection of the underlying set of actions with the induced order). Observe that, if the arena is alternating, this condition tells us that given e, e1 , e2 ∈ E if e ←E e1 , e ←E e2 and π(e) = − then π(e1 ) = π(e2 ) = + and e1 = e2 .Intuitively, this condition would correspond to the constraint that in a process there is an unique output which is active at any time. Finally, we say that E : Γ is acyclic if it satisfies the analogous of the acyclicity constraints given in [5], which we do not detail here. Intuitively, the condition guarantees the absence of deadlocks during parallel composition. When restricting to +/- alternating arenas (and the polarity constraints given in [10]), we retrieve the family of linear strategies Theorem 9. Let E : Γ be a conf.-free event structure on a +/- alternating arena. (1.) If E : Γ is sequential, then E corresponds to a linear strategy as defined by Girard in [10] (these strategies are there called designs). (2.) If E : Γ is arborescent, then E corresponds to a linear strategy extended with mix, as defined in [4] (and there called L-forests). (3.)If E : Γ is acyclic, then E corresponds to an L-net, as defined in [5]. Moreover, all the above sub-classes of conf.-free innocent event structures are closed under composition and all the induced category are all subcategories of InnEv. If we do not insist for the arena to be alternating, we would have also neutral cells, which correspond (in process calculus) to a sum guarded by τ actions. This leaves the space for a possible extension of our work to model internal choices.
110
C. Faggian and M. Piccolo
In future work we want to investigate this direction as a possible approach to non-deterministic Game Semantics. A key element in this paper is linearity, which allows for the definition of composition based on the merging of orders. We believe this is not a limitation to model an expressive calculus. In ongoing work [8] we extend [7], to show that Ludics is in fact able to model a variant of the Linear π-calculus extended with recursion. Even with recursion, the game model is linear.
References 1. Abramsky, S., Malacaria, P., Jagadeesan, R.: Full abstraction for PCF. Inf. and Comp. 163(2), 409–470 (2000) 2. Abramsky, S., Melli`es, P.-A.: Concurrent games and full completeness. In: Proc. of LICS, pp. 431–442 (1999) 3. Curien, P.-L.: Notes on game semantics, http://www.pps.jussieu.fr/~ curien 4. Curien, P.-L., Faggian, C.: L-nets, strategies and proof-nets. In: Ong, L. (ed.) CSL 2005. LNCS, vol. 3634, pp. 167–183. Springer, Heidelberg (2005) 5. Faggian, C., Maurel, F.: Ludics nets, a game model of concurrent interaction. In: Proc. of LICS 2005, pp. 376–385. IEEE Computer Society Press, Los Alamitos (2005) 6. Faggian, C., Piccolo, M.: A graph abstract machine describing event structure composition. ENTCS 175(4), 21–36 (2007) 7. Faggian, C., Piccolo, M.: Ludics is a model for the finitary linear pi-calculus. In: Della Rocca, S.R. (ed.) TLCA 2007. LNCS, vol. 4583, pp. 148–162. Springer, Heidelberg (2007) 8. Faggian, C., Piccolo, M.: Ludics is a model for the linear pi-calculus. Draft (2009) 9. Ghica, D.R., Murawski, A.S.: Angelic semantics of fine-grained concurrency. In: Walukiewicz, I. (ed.) FOSSACS 2004. LNCS, vol. 2987, pp. 211–225. Springer, Heidelberg (2004) 10. Girard, J.-Y.: Locus solum: from the rules of logics to the logics of rules. MSCS 11, 301–506 (2001) 11. Harmer, R.: Innocent game semantics, http://www.pps.jussieu.fr/~ russ 12. Hyland, J.M.E., Ong, L.C.-H.: On full abstraction for PCF: I, II, and III. Inf. and Comp. 163(2), 285–408 (2000) 13. Hyland, M.: A category of partial orders. Communication at AMS/SMF Meeting in Lyon (July 2001), http://www.dpmms.cam.ac.uk/~ martin/Research/Slides/lyon01.pdf 14. Hyland, M., Schalk, A.: Games on graph and sequentially realizable functionals. In: Proc. of LICS 2002, pp. 257–264. IEEE Computer Society Press, Los Alamitos (2002) 15. Laird, J.: A game semantics of the asynchronous π-calculus. In: Abadi, M., de Alfaro, L. (eds.) CONCUR 2005. LNCS, vol. 3653, pp. 51–65. Springer, Heidelberg (2005) 16. McCusker, G., Wall, M.: Categorical and game semantics for SCIR. In: Proc. of GALOP, pp. 157–178 (2005) 17. Melli`es, P.-A.: Asynchronous games 2: The true concurrency of innocence. TCS 358(2-3), 200–228 (2006)
Partial Orders, Event Structures and Linear Strategies
111
18. Melli`es, P.-A., Mimram, S.: Asynchronous games: Innocence without alternation. In: Caires, L., Vasconcelos, V.T. (eds.) CONCUR 2007. LNCS, vol. 4703, pp. 395– 411. Springer, Heidelberg (2007) 19. Nielsen, M., Plotkin, G., Winskel, G.: Petri nets, event structures and domains. TCS 13(1), 85–108 (1981) 20. Sangiorgi, D., Walker, D.: The π-calculus: a theory of mobile processes. Cambridge University Press, Cambridge (2001) 21. Schalk, A., P´erez, J.J.P.: Concrete data structures as games. ENTCS (2005) 22. Varacca, D., Yoshida, N.: Typed event structures and the π-calculus. In: Proc, of MFPS. ENTCS, vol. 158, pp. 373–397 (2006) 23. Winskel, G.: Event structures. In: Brauer, W., Reisig, W., Rozenberg, G. (eds.) APN 1986. LNCS, vol. 255, pp. 325–392. Springer, Heidelberg (1987) 24. Winskel, G.: An introduction to event structures. In: de Bakker, J.W., de Roever, W.-P., Rozenberg, G. (eds.) Linear Time, Branching Time and Partial Order in Logics and Models for Concurrency. LNCS, vol. 354, pp. 364–397. Springer, Heidelberg (1989) 25. Winskel, G., Nielsen, M.: Models for concurrency. In: Handbook of Logic in Computer Science, pp. 1–148. Oxford University Press, Oxford (1995) 26. Yoshida, N., Berger, M., Honda, K.: Strong normalisation in the PI-calculus. Inf. and Comp. 191(2), 145–202 (2004)
Existential Type Systems with No Types in Terms Ken-etsu Fujita1, and Aleksy Schubert2, 1
2
Gunma University, Tenjin-cho 1-5-1, Kiryu 376-8515, Japan [email protected] The University of Warsaw, ul. Banacha 2, 02-097 Warsaw, Poland [email protected]
Abstract. We study type checking, typability, and type inference problems for type-free style and Curry style second-order existential systems where the type-free style differs from the Curry style in that the terms of the former contain information on where the existential quantifier elimination and introduction take place but omit the information on which types are involved. We show that all the problems are undecidable employing reduction of second-order unification in case of the type-free system and semiunification in case of the Curry style system. This provides a fine border between problems yielding to a reduction of second-order unification problem and the semiunification problem. In addition, we investigate the subject reduction property of the system in the Curry-style.
1
Introduction
The System F (λ2) of Girard-Reynolds is a fundamental system for the study of polymorphism. Its polymorphic properties are seen as the theoretical basis for the functional programming languages such as ML and this resulted in thorough studies e.g. [Boe85, Wel99, Sch98] and for the λ2 subsystems [FS00, Mai90]. A system with 2nd order existential types provides a theoretical basis for abstract data types [MP88]. This ingredient is also present in languages based on ML, but has been less studied except for the domain-free style [NTKN08]. The polymorphic system has enough power to encode impredicatively other connectives ∧, ∨, ∃ and so on in terms of →, ∀ [Pra65]. In this sense, the 2nd order existential type system λ∃ [Fuj05] can be regarded as a subsystem of λ2. On the other hand, the existential system λ∃ can serve, under CPS-translations, as a target calculus not only of λ2 (2nd order intuitionistic logic) but also of λμ-calculus (2nd order classical logic) of Parigot [Fuj05, Has06]. Moreover, a recent work [Fuj] on an intimate connection between λ2 and λ∃ reveals duality not only on reduction correspondence but also on proof structures between the systems. In this light, the expressiveness of λ2 and λ∃ is comparable. Still, the undecidability of the type related problems cannot be established as a corollary
This work was partly supported by the bilateral program (2008) between Japan Society for the Promotion of Science and Polish Academy of Sciences. This work was partly supported by the Polish government grant no N N206 355836.
P.-L. Curien (Ed.): TLCA 2009, LNCS 5608, pp. 112–126, 2009. c Springer-Verlag Berlin Heidelberg 2009
Existential Type Systems with No Types in Terms
113
of the mentioned above translations. This is in principle due to the fact that the translation works smoothly for systems with adequate type information, e.g. domain-free style [BS00, NTKN08], while the additional or missing type information introduces complications which are not immediate to overcome. In this paper, we study type checking, typability, and type inference problems of 2nd order existential type systems in the styles of type-free and Curry. First, we show that all of the type related problems are undecidable for 2nd order existential type system in the type-free style, which can be regarded as an intermediate system between Church style and Curry style. For this, 2nd order unification problem in the flat form is introduced, and this form is proved undecidable by the reduction from 2nd order unification of simple instances [Sch98]. Then, by the reduction from the flat forms, it is proved that all of the type related problems of the type-free system are undecidable. Secondly, we show that type checking and typability problems of the system in the style of Curry are undecidable. By reductions from the semiunification problem [KTU90], the undecidability proofs are established for fragments: (→, ∃) and (¬, ∧, ∃). The first of these results answers the decidability issue for the type related problems the solutions of which were left open by Nakazawa et al. [NTKN08]. Moreover, we investigate the subject reduction property of the system in Curry-style. The 2nd order unification is used to prove the undecidability of several type related problems for second-order calculi [Sch98, FS00, Pfe93, Boe85]. Similarly, the semiunification problem (SUP) is appropriate as a tool to prove the undecidability for other ones [Wel99, KTU93]. The systems in this paper elucidate the mutual relation between the two problems as applied to type related questions. We can conclude that the possibility to fix the number of arguments to a second-order construct plays the crucial part here. This possibility is, indeed, the only difference between the type-free system and the Curry-style system. In this light the semiunification problem can be viewed as a kind of 2nd order unification where the number and the shape of 2nd order variable arguments are not known. The main advantage of the Curry-style type systems from the programmers’ point of view is that a programmer is liberated from the burden of making the type annotations. The type-free system can be an interesting alternative here as the annotating tax is not high, but the programmer can decide where the polymorphism is employed and how much of the polymorphism is exploited. One more advantage of the type-free systems is that they correspond to the 2nd order unification which is more extensively studied than the semiunification problem.
2
Second Order Existential Type Systems (¬, →, ∧, ∃)
We consider a second order system consisting of ¬, →, ∧, and second order existential quantification ∃. The subsystem with → and ∃ is denoted by (→, ∃) while the one with ¬, ∧ and ∃ is by (¬, ∧, ∃). The possible types of the full system are: A ::= X | ⊥ | ¬A | A → A | A ∧ A | ∃X.A
114
K. Fujita and A. Schubert
First, a system between Church and Curry styles is defined as follows, where the special symbol ∃ marks the existence of a witness. We call this system type-free system as we erase here all the types from the terms, but we mark the locations where the types should occur in the corresponding Church-style terms. M ::= x | λx.M | M M | M, M | πi (M ) | ∃, M | let ∃, x = M in M Γ, x : A x : A
(var)
Γ, x : A M : ⊥ Γ M1 : ¬A Γ M2 : A (¬I) (¬E) Γ λx.M : ¬A Γ M1 M2 : ⊥ Γ, x : A1 M : A2 Γ M1 : A1 → A2 Γ M2 : A1 (→ I) (→ E) Γ λx.M : A1 → A2 Γ M1 M2 : A2 Γ M : A1 ∧ A2 Γ M1 : A1 Γ M2 : A2 (∧I) (∧E) Γ M1 , M2 : A1 ∧ A2 Γ πi (M ) : Ai Γ M : A[X := A1 ] (∃I) Γ ∃, M : ∃X.A
Γ M1 : ∃X.A Γ, x : A M2 : A1 (∃E)∗ Γ let ∃, x = M1 in M2 : A1
where (∃E)∗ denotes the eigenvariable condition X ∈ F V (Γ, A1 ) and Γ are contexts which are sets of pairs x : A that assign types to object variables. Secondly, a system in Curry style is given as follows, for instance see [SU06], where we show here only the type rules which differ from the type-free system: M ::= x | λx.M | M M | M, M | πi (M ) Γ M : A[X := A1 ] (∃I) Γ M : ∃X.A
Γ M1 : ∃X.A Γ, x : A M2 : A1 (∃E)∗ Γ M2 [x := M1 ] : A1
where (∃E)∗ denotes the eigenvariable condition X ∈ F V (Γ, A1 ). As usual, a forgetful mapping can be defined from type-free to Curry. For instance, ∃, M = M , let ∃, x = M1 in M2 = M2 [x := M1 ] for type-free terms M, M1 , M2 . Then well-typed Curry terms can be lifted to well-typed type-free terms as in [Bar93]. The type checking problem (TCP) is a problem: given a term M , a type A, and a context Γ , is the judgement Γ M : A derivable? The type inference problem (TIP) is a problem: given a term M and a context Γ , is there a type A such that Γ M : A is derivable? Finally, the typability problem (TP) is a problem: given a term M , are there a context Γ and a type A such that Γ M : A is derivable?
3
Undecidability of Restricted Unification
The proof of undecidability of type related problems for type-free system is based on the reduction of a version of the 2nd order unification problem to the problems. We present here the 2nd order unification we are interested in. Based on the syntax of types, we define expressions for unification problems. Here, the countably infinite set of type variables is separated into two sets of
Existential Type Systems with No Types in Terms
115
variables: One is for first order variables denoted by X, Y , and another is for constants denoted by C. . . A unification problem consists of a set of equations E = {A1 = B1 , . . . , Ak = Bk }. And we say that the instance E is solvable if there exists a substitution S such that S(A1 ) = S(B1 ), . . . , S(Ak ) = S(Bk ). We write Dom(S) for the domain of S. Expressions for the first order unification problems are defined from first order variables and constants, together with →. A, B ::= X | C | A → B Expressions for simple instances of the second order unification problem are defined using second order functional variables of a fixed arity denoted by F, G and terms built of constants and → only, e.g. FC1 · · · Cn for F of arity n. Here, free variables in expressions of unification problems are defined as follows: F Vu (C) = ∅; F Vu (X) = {X}; F Vu (F) = {F}; F Vu (A → B) = F Vu (A)∪F Vu (B). Definition 1 (Simple instances Es ). We consider the following set Es of only two equations of simple instances, which is enough for the undecidability [Sch98]. . . {FA1 . . . An = (FA1 . . . An ) → A0 , GB1 . . . Bm = (GB1 . . . Bm ) → (FA1 . . . An )}
where F has the arity n and G has the arity m with m, n ≥ 1, and the set of the free variables F Vu (Ai , Ai , Ai , Bj , Bj ) = ∅ for each i, j. Theorem 1 (Undecidability for simple instances [Sch98]). The second order unification for simple instances is undecidable. The equations can be transformed so that the second-order variables occur only as topmost symbols (at the root of the tree they correspond to). The simple instances of Definition 1 can be reduced to the following equations Esr : Definition 2 (Simple instances with root restriction Esr ). . FA1 . . . An = XFA1 ...An → A0 . → XFA ...A GB1 . . . Bm = YGB1 ...Bm n 1
. FA1 . . . An = XFA1 ...An . = YGB1 ...Bm GB1 . . . Bm . FA1 . . . An = XFA1 ...An
Simple instances together with the root-restriction (Definition 2) can be reduced further to the following restricted form. We say that a set of unification equations E is in the flat form if it obeys all the restrictions as follows: Definition 3 (Flat form) 1. Root restriction: Second-order variables occur only at root positions. 2. Monadic restriction: If second-order variable occurs as FA1 · · · An then either all Ai are constants or all Ai are first order variables; moreover, the symbols Ai occur only in the equation where FA1 · · · An occurs.
116
K. Fujita and A. Schubert
3. Constant restriction: Each time a second-order variable F is applied to a . vector X1 , . . . , Xn of first order variables as FX1 · · · Xn = A, there is a set of pairwise distinct constants C1 , . . . , Cn such that there is exactly one . equation FC1 · · · Cn = B ∈ E, where C1 , . . . , Cn occur exclusively in this equation of E, and all C1 , . . . , Cn occur in B. The first equation of the simple instances with the root restriction (Definition 2) can be reduced to the following flat form Esf : Definition 4 (Simple instances in flat form Esf ) . XA1 ...An = XF A1 ...An → A0 . F X1 . . . Xn = XA1 ...An → A1 → · · · → An → o . → C1 → · · · → Cn → o F C1 . . . Cn = XA 1 ...An are where F is a fresh second order variable with n-arity; Xi , XA1 ...An , XA 1 ...An fresh first order variables; C1 , . . . , Cn are subject to the constant restriction; and o is a distinguished constant. . Lemma 1. The first equation FA1 . . . An = XFA1 ...An → A0 in Esr of Definition 2 is solvable if and only if the equations in Esf of Definition 4 are solvable.
Proof. 1. Suppose that S(F)A1 . . . An = S(XFA1 ...An ) → A0 . Then define a substitution S for Definition 4 as follows: S (F )Z1 . . . Zn = (S(F)Z1 . . . Zn ) → Z1 → · · · → Zn → o; S (XA1 ...An ) = S(F)A1 . . . An ; S (XA ) = S(F)C1 . . . Cn ; 1 ...An S (Xi ) = Ai ; and S (XF A1 ...An ) = S(XF A1 ...An ). Now all the equations in Definition 4 are solvable. 2. Suppose that the equations in Definition 4 are solvable under S. From the constant restriction of the flat form, the substitution S has the following form: S(F )Z1 . . . Zn = (A → Z1 → · · · → Zn → o) for some A such that S(XA1 ...An ) = A[Z1 := A1 , . . . , Zn := An ] and S(XA ) = A[Z1 := 1 ...An C1 , . . . , Zn := Cn ]. Then define a substitution S for the first equation as follows: S (F)Z1 . . . Zn = A and S (XFA1 ...An ) = S(XF A1 ...An ). Now the first equation in Definition 2 is solvable. The other equations of the simple instances with the root restriction (Definition 2) can be reduced similarly to the flat form, to say Esf for the all. Proposition 1 (Reduction from Es to Esf ). The simple instances of Es are solvable if and only if the simple instances in the flat form Esf are solvable. Proof. Es can be reduced to Esr , and then apply Lemma 1.
4
Undecidability of Type Related Problems for Type-Free System
Now, we embark on the reduction of the unification of equations in the flat form to the type related problems. We provide for a set of equations E, a λ-term M
Existential Type Systems with No Types in Terms
117
such that if a type derivation for M exists then a unifier S for E can be separated from it. The main idea of the construction is to ensure that the shape of a type for a variable xA occurring in M which corresponds to a subexpression A in E strictly corresponds to S(A). We simply write An → B for A → · · · → A → B with n-occurrences of A, and M N n for M N . . . N with n-occurrences of N . Since we have a countably infinite set of term variables of λ-calculus, we can assume one-to-one mappings between expressions of unification problems and term variables of λ-terms. Based on this, we write term variables xA and yA corresponding to an expression A of unification problem. For instance, we have term variables xX and yX from the first order variable X, and similarly term variables xC and yC from the constant C. In particular, from the distinguished constant o we have a term variable xo . In order to make the presentation of the paper more accessible, we simplified the formulations of the lemmas so that it fits well the TP. The handling of the TIP and TCP requires more careful handling of the contexts. Definition 5 (Encoding of first order expressions). For an expression A of the first order unification problem, we define a λ-term MA , as follows: 1. Case A of X (first order variable): MX ≡ y1 (yX xX )(y1 x2o ), where y1 is a fresh term variable. 2. Case A of C (constant): MC ≡ y1 (yC xC )(y1 x2o ), where y1 is a fresh term variable. 3. Case A of A1 → A2 : MA1 →A2 ≡ y1 (y2 (xA1 →A2 xA1 )) (y2 xA2 ) MA1 MA2 (y1 x5o ) where y1 , y2 are fresh term variables. For a context Γ , an updated context Γ (x : A) is defined as usual, such that Γ (x : A)(y) = A if y ≡ x, otherwise Γ (x : A)(y) = Γ (y). Lemma 2. 1. For any expression A of first order unification, there exist context Γ such that Γ MA : o and then Γ (xA ) = SΓ (A) for some substitution SΓ . 2. If we have Γ MA : B, then Γ MA : o under some updated Γ of Γ at yi , yXj , xo for yi , yXj , xo ∈ F V (MA ). 3. For any substitution S of first order unification with F Vu (A) ⊆ Dom(S), there exist context ΓS and type o such that ΓS MA : o and then ΓS (xA ) = S(A). Proof. 1. First, we prove 1 by induction on the structure of A. 2 is clear from this proof. We assume that xo : o, which is used implicitly. (a) Case A of X: We take Γ = {y1 : o2 → o, yX : B → o, xX : B} where B is an arbitrary expression of first order unification. Then we have Γ MX : o. For all xXi ∈ Dom(Γ ), we define SΓ = [X1 := Γ (xX1 ), . . . , Xn := Γ (xXn )]. Then we establish Γ (xX ) = B = S(X).
118
K. Fujita and A. Schubert
(b) Case A of C: We take Γ = {y1 : o2 → o, yC : C → o, xC : C}. Then Γ MC : o and Γ (xC ) = C = S(C) for any S. (c) Case A of A1 → A2 : From the induction hypotheses, we have Γ1 MA1 : o and Γ2 MA2 : o for some contexts, where Γ1 (xA1 ) = SΓ1 (A1 ) and Γ2 (xA2 ) = SΓ2 (A2 ) for some substitutions defined by Γi . We update Γ2 at xX1 , . . . , xXk for all Xi ∈ F Vu (A1 ) ∩ F Vu (A2 ), so that Γ2 (xX1 : Γ1 (xX1 ))(yX1 : Γ1 (xX1 ) → o) . . . (xXk : Γ1 (xXk ))(yXk : Γ1 (xXk ) → o), and obtain Γ2 . Let Γ = Γ1 ∪ Γ2 . Then we have Γ MAi : o and Γ (xAi ) = SΓ (Ai ) for i = 1, 2. Now we define ΓA1 →A2 = Γ ∪ {y1 : o5 → o, y2 : Γ (xA2 ) → o, xA1 →A2 : Γ (xA1 ) → Γ (xA2 )}. Finally, we establish ΓA1 →A2 MA1 →A2 : o, and then ΓA1 →A2 (xA1 →A2 ) = Γ (xA1 ) → Γ (xA2 ) = SΓ (A1 ) → SΓ (A2 ) = SΓ (A1 → A2 ) = SΓA1 →A2 (A1 → A2 ), where SΓA1 →A2 = SΓ . 2. For any A, we have Γ MA : o for some Γ . Here, we update Γ at all xXi with Xi ∈ F Vu (A) ⊆ Dom(S), such that Γ (xX1 : S(X1 ))(yX1 : S(X1 ) → o) . . . (xXn : S(Xn )(yXn : S(Xn ) → o), to say ΓS . Then we still have ΓS MA : o, and then ΓS (xA ) = SΓ S (A) for some SΓ S defined by ΓS . Here, SΓ S = [X1 := ΓS (xX1 ), . . . , Xn := ΓS (xXn )] = [X1 := S(X1 ), . . . , Xn := S(Xn )] = S restricted to F Vu (A). Hence, we have ΓS (xA ) = S(A). Definition 6 (Encoding of first order unification). Let E be a finite set of . equations of first order unification E = {A1 = B1 } ∪ E0 . For the equations we define a λ-term ME in case E0 = ∅ as follows: ME ≡ y1 (y2 xA1 )(y2 xB1 )MA1 MB1 ME0 (y1 x6o ), where y1 , y2 are fresh term variables; and in case E0 = ∅: ME ≡ y1 (y2 xA1 )(y2 xB1 )MA1 MB1 (y1 x5o ), where y1 , y2 are fresh term variables. Lemma 3. Let E be a finite set of equations of first order unification. There is a context Γ such that the problem E is solvable if and only if Γ ME : o. Proof. 1. Suppose that E is solvable under S, i.e., S(Ai ) = S(Bi ) for each 1 ≤ i ≤ n. From Lemma 2, we have ΓS MAi : o and ΓS MBi : o, where ΓS (xAi ) = S(Ai ) = S(Bi ) = ΓS (xBi ). Let Γ = ΓS ∪ Γ1 ∪ . . . ∪ Γn , (i) (i) where Γi = {y1 : o6 → o, y2 : ΓS (xAi ) → o} for 1 ≤ i ≤ n − 1, and 5 Γn = {y1 : o → o, y2 : ΓS (xAn ) → o}. Then we establish Γ ME : o. 2. Suppose that Γ ME : o for some context Γ and type o. Now we have Γ MAi : o and Γ MBi : o for each i, and then from Lemma 2, SΓ (Ai ) = . Γ (xAi ) = Γ (xBi ) = SΓ (Bi ) for some substitution SΓ . Hence all of Ai = Bi are solvable under SΓ .
Existential Type Systems with No Types in Terms
119
We define a λ-term ∃n+1 , M ≡ ∃, ∃n , M and ∃1 , M ≡ ∃, M , which means successive applications of (∃I). We also define a λ-term (let ∃n+1 , a1 = M in N ) ≡ (let ∃, a1 = M in (let ∃n , a2 = a1 in N )), which means successive applications of (∃E). A reduction from Es of Definition 1 to simple instances in the flat form Esf provides totally 10 equations with second order variables, where two second order variables are used, to say F for four equations and G for the rest six equations. We define the following encoding for equations with F, and the case with G follows the same pattern. Definition 7 (Encoding of second order unification). For a set of equations E such that the set E\E consists of the equations in the flat form containing the second order variable F of arity n: . FX1 . . . Xn = B1 ,
. FC1 . . . Cn = B2 ,
. FY1 . . . Yn = B3 ,
. FC1 . . . Cn = B4 ,
where B1 ≡ (X → A1 → · · · → An → o), B3 ≡ (Y → A1 → · · · → An → o), B2 ≡ (X → C1 → · · · → Cn → o), and B4 ≡ (Y → C1 → · · · → Cn → o); we define a λ-term ME as follows: y1 (y2 ∃n , xB1 ) (y2 ∃n , xB2 ) (y2 ∃n , xB3 ) (y2 ∃n , xB4 ) (y2 (let ∃n , a = xF in ∃n , λzz1 . . . zn .y1 (azz1 . . . zn )12 )) (y2 xF ) MB1 MB2 MB3 MB4 ME (y1 x12 o )
(1)
where y1 , y2 are fresh term variables; MB1 , . . . , MB4 are encodings of the first order expressions B1 , . . . , B4 ; and ME is an encoding of the set E of equations. Lemma 4. Let E be the equations in the flat form above. There is a context Γ such that the problem E is solvable if and only if Γ ME : o. Proof. (⇒) A straightforward transformation of the substitution. (⇐) Suppose Γ ME : B for some Γ and B , then an updated Γ of Γ even gives Γ ME : o. Thus for all i = 1, 2, 3, 4, we have Γ MBi : o as well and Γ (xBi ) = S(Bi ) for some substitution S. Since (let ∃n , a = xF in ∃n , λzz1 . . . zn .y1 (azz1 . . . zn )12 ) is well-typed by n-times application of (∃E) and (∃I), type of xF has the form of ∃Z1 . . . Zn .B for some B, such that λzz1 . . . zn .y1 (azz1 . . . zn )12 and a have the same type B in the form of (A → 1 → · · · → n → o) for some types A, i . From Γ xBi : S(Bi ) for all i = 1, 2, 3, 4, we must derive the same type ∃Z1 . . . , Zn .B such that Γ ∃n , xBi : ∃Z1 . . . , Zn .B by n-times application of (∃I). From the constant restriction on Ci , Ci , these constants are to be abstracted one by one, and moreover the head parts of S(Bi ); S(X), S(X ), S(Y ), S(Y ) are also to be abstracted by (∃I). This means that B ≡ (A → Z1 → · · · → Zn → o) with S(X) = A[Z1 := A1 , . . . , Zn := An ]; S(X ) = A[Z1 := C1 , . . . , Zn := Cn ]; S(Y ) = A[Z1 := A1 , . . . , Zn := An ]; S(Y ) = A[Z1 := C1 , . . . , Zn := Cn ]. Now we can extend the substitution S to F, such that S(F)Z1 . . . Zn = (A → Z1 → · · · → Zn → o), and that S(Xi ) = Ai and S(Yi ) = Ai for fresh first order variables Xi , Yi . Then we establish S(F)S(X1 ) . . . S(Xn ) = S(F)A1 . . . An = A
120
K. Fujita and A. Schubert
[Z1 := A1 , . . . , Zn := An ] → A1 → · · · → An → o = S(X) → A1 → · · · → An o = S(B1 ); and S(F)C1 . . . Cn = A[Z1 := C1 , . . . , Zn := Cn ] → C1 → · · · Cn → o = S(X ) → C1 → · · · → Cn → o = S(B2 ). The other equations can solved as well. Thus E is solvable.
→ → be
Theorem 2 (TP, TIP, TCP (→ ∃)). TP, TIP, and TCP are undecidable for the system (→, ∃). Proof. The flat form E is solvable iff Γ ME : o for some Γ and o by Lemma 4, so the undecidability of TP follows. In order to obtain TCP and TIP additional care should be taken to make sure that the types of different constants are indeed different and that we have the distinguished type o = Cn . This can be obtained with the help of the following construction ˆ E ≡ let ∃, xC1 = x∃X.X in . . . let ∃, xCn = x∃X.X in ∃, λx.ME M where x∃X.X is a variable of the type ∃X.X and x are all the free variables in ME except xC1 , . . . , xCn . The type ∃X.X for the variable x∃X.X can be enforced in turn using the term: M∃X.X ≡ y1 (y2 x∃X.X )(y2 ∃, (λx.x))(y2 ∃, ∃, y3 ) where y1 , y2 , y3 are fresh variables. We can now combine MˆE and M∃X.X into one term λx.y3 MˆE M∃X.X where x contains all the free variables of y3 M∃X.X MˆE . The details of the construction are left to the reader.
5
Simple Derivations of the System in the Curry-Style
We analyse the structure of derivations in the Curry-style system. This is further applied to TCP and TIP, and to establish the subject reduction property. Definition 8 (Removing vacuous ∃) 1. |X| = X; |⊥| = ⊥; |¬A| = ¬|A|; |A1 A2 | = |A1 | |A2 | for ∈ {→, ∧}. 2. |∃X.A| = ∃X.|A| if X ∈ F V (A); |∃X.A| = |A| if X ∈ F V (A). Lemma 5 (Basic lemma) (Weakening): Γ, x : A N : A1 where x ∈ F V (N ) if and only if Γ N : A1 . (Substitution): If Γ M : A, then Γ [X := A1 ] M : A[X := A1 ]. (Cut): If Γ M : A and Γ, x : A N : A1 , then Γ N [x := M ] : A1 . |A[X := B]| ≡ |A|[X := |B|]. (Non-vacuous ∃): If Γ M : A is derivable, then |Γ | M : |A| is derivable with no vacuous quantification in types throughout the whole derivation. 6. Γ M : ∃X.∃Y.A if and only if Γ M : ∃Y.∃X.A. 1. 2. 3. 4. 5.
Definition 9 (Simple derivations). A derivation D of Γ M : A in the Curry-style system is called simple, if D complies to all the restrictions:
Existential Type Systems with No Types in Terms
121
1. For each existential type ∃X.A in D, we have X ∈ F V (A). 2. (No redundant (∃E)) For each application of (∃E) in D, x ∈ F V (N ) in: Γ M : ∃X.A Γ, x : A N : A1 (∃E) Γ N [x := M ] : A1
3. The derivation D contains no application of rules (∃I), (∃E) such as: Γ M : A[X := A1 ] (∃I) Γ M : ∃X.A Γ, x : A N : A2 (∃E) Γ N [x := M ] : A2
where the major premise of (∃E) is a consequence of (∃I). 4. The derivation D contains no application of rules (∃E) such as: Γ M : ∃X1 .A1 Γ, x1 : A1 N1 : ∃X2 .A2 (∃E) Γ N1 [x1 := M ] : ∃X2 .A2 Γ, x2 : A2 N2 : A (∃E) Γ N2 [x2 := N1 [x1 := M ]] : A
where the major premise of lower (∃E) is a consequence of upper (∃E). 5. The derivation D contains no application of rules (∃E), (∃I) such as: Γ M : ∃X.A Γ, x : A N : A1 [Y := A2 ] (∃E) Γ N [x := M ] : A1 [Y := A2 ] (∃I) Γ N [x := M ] : ∃Y.A1
where the premise of (∃I) is a consequence of (∃E). Proposition 2 (Simple derivations). For any derivation D of Γ M : A in the Curry-style system, we have a simple derivation D of Γ M : A with the same term M . Proof. First step: We obtain the condition 1 of Def. 9 by Lemma 5(5) and the condition 2 is by Lemma 5(1). Second step: We can prove that for any derivation D of Γ M : A, there exists a derivation D of Γ M : A with the same term, which obeys conditions 3 and 4, following [Pra65, And95]. Third step: Suppose that we have a derivation which obeys 1, 2, 3 and 4. Then the application as in case (5) of Def. 9 can be permuted as follows: Γ, x : A N : A1 [Y := A2 ] (∃I) Γ M : ∃X.A Γ, x : A N : ∃Y.A1 (∃E) Γ N [x := M ] : ∃Y.A1
Thus we can show the existence of simple derivations.
Corollary 1 (Application of (∃E)). On the application of (∃E) in a simple derivation: Γ M : ∃X.A Γ, x : A N : A1 (∃E) Γ N [x := M ] : A1
the judgement Γ M : ∃X.A is a consequence of an application of (var), (→ E) or (∧E). Thus the case of M ≡ y (variable) gives Γ (y) = ∃X.A, and the term M can be in the form of neither λy.M1 nor M1 , M2 for some M1 , M2 .
122
K. Fujita and A. Schubert
Under the simple derivations, lemmas of generation are naturally obtained. For successive applications of substitutions, we write A[Y1 := A1 ] . . . [Ym := Am ] where Yi ∈ F V (Aj ) for i = j. A skeleton of a derivation for Γ x : A in the Curry-style system can be represented as a type-free term: M ≡ (let ∃, a1 = x in · · · let ∃, an = an−1 in ∃, . . . , ∃, an ) with M = x. This can be generalised to all terms by Curry-Howard isomorphism together with a natural type erasure · . Lemma 6 (Generation lemma). (1) (var): If Γ x : A, then there exists x : ∃X1 . . . Xn .B ∈ Γ (n ≥ 0), such that B ≡ B0 [Y1 := B1 ] . . . [Ym := Bm ] and A ≡ ∃Y1 . . . Ym .B0 for some B0 , B1 , . . . , Bm (m ≥ 0). (2) (lam): If Γ λx.M : A, then the derivation has, for some Mi , N, the following structure P in terms of the type-free style with P = λx.M : P ≡ (let ∃, x1 = M1 in · · · let ∃, xn = Mn in ∃, . . . , ∃, λx.N ). (3) (app): If Γ M N : A, then the derivation has, for some Mi , N1 , N2 , P , one of the following structures Q in terms of the type-free style with Q = M N :
Case 1: Q ≡ (let ∃, x1 = M1 in · · · let ∃, xn = Mn in ∃, . . . , ∃, N1 N2 ); Case 2: Q ≡ (let ∃, x1 = M1 in · · · let ∃, xn = Mn in let ∃, xn+1 = N1 N2 in P ), where P = xn+1 .
(4) (pair): If Γ M, N : A, then the derivation has, for some Mi , N1 , N2 , the following structure in terms of the type-free style with P = M, N : P ≡ (let ∃, x1 = M1 in · · · let ∃, xn = Mn in ∃, . . . , ∃, N1 , N2 ). (5) (proj): If Γ πk (M ) : A, then the derivation, for some Mi , N, P , has one of the following structures Q in terms of the type-free style with Q = πk (M ):
Case 1: Q ≡ (let ∃, x1 = M1 in · · · let ∃, xn = Mn in ∃, . . . , ∃, πk (N )); Case 2: Q ≡ (let ∃, x1 = M1 in · · · let ∃, xn = Mn in let ∃, xn+1 = πk (N ) in P ), where P = xn+1 .
6
TCP and TIP for (→, ∃) in Curry-Style
For the proof of undecidability of TC and TCP we adopt here the technique of Wells [Wel99]. Let {A1 ≤ B1 , A2 ≤ B2 } be an instance of SUP [KTU90] built of type variables and →.1 Let X be the set of variables of the instance. The instance has a solution S if and only if R1 (S(A1 )) = S(B1 ) and R2 (S(A2 )) = S(B2 ) for some substitutions R1 , R2 . Let γ, γ1 , γ2 , ζ be fresh type variables which do not occur in X . In the system of (→ ∃), we shorten A → ζ as ¬A. Each type ∃X1 . . . Xk .A where F V (A) = {X1 , . . . , Xk , ζ} is called an existential closure, we write it for simplicity ∃.A (this small abuse of notation simplifies a bit the notation below). We reduce SUP to TCP by letting: M1 ≡ λx.λz.c(λy.z(y(λu1 .xu1 )(λu2 .xu2 ))) and Γ = {c : ¬∃.¬(¬¬(B1 → γ1 ) → ¬¬(γ2 → B2 ) → A1 → A2 )}. Theorem 3 (SUP → TCP). {A1 ≤ B1 , A2 ≤ B2 } has a solution if and only if Γ M1 : ∃γ.(¬γ → ¬γ) is derivable in the system (→ ∃). 1
The problem is undecidable for one binary symbol and two equations [KTU90].
Existential Type Systems with No Types in Terms
123
Proof. For the if part, assume that the instance {A1 ≤ B1 , A2 ≤ B2 } of SUP has a solution, i.e., Ri (S(Ai )) = S(Bi ) for i = 1, 2. Then we have the following derivations (the reader is encouraged to reconstruct the contexts missing in the derivations): ui : ¬(Ri (SA1 ) → Ri (SA2 )) (∃I) x : ¬∃.¬(SA1 → SA2 ) ui : ∃.¬(SA1 → SA2 ) xui : ζ λui .xui : ¬¬(Ri (SA1 ) → Ri (SA2 ))
(2)
Let a : ¬(SA1 → SA2 ), and y : B together with B ≡ (¬¬(SB1 → R1 (SA2 )) → ¬¬(R2 (SA1 ) → SB2 ) → SA1 → SB2 ) and A ≡ (¬(¬¬(B1 → γ1 ) → ¬¬(γ2 → B2 ) → A1 → B2 )). Then, one has y(λu1 .xu1 )(λu2 .xu2 ) : SA1 → SB2 under the solution. We continue: a : ¬(SA1 → SA2 ) y(λu1 .xu1 )(λu2 .xu2 ) : SA1 → SA2 a(y(λu1 .xu1 )(λu2 .xu2 )) : ζ (→ I) λy.a(y(λu1 .xu1 )(λu2 .xu2 )) : ¬B (∃I) λy.a(y(λu1 .xu1 )(λu2 .xu2 )) : ∃.γ1 .γ2 .A c : Γ (c) (→ E) z : ∃.¬(SA1 → SA2 ) c(λy.a(y(λu1 .xu1 )(λu2 .xu2 ))) : ζ (∃E) c(λy.z(y(λu1 .xu1 )(λu2 .xu2 ))) : ζ
Finally, the system (→ ∃) derives Γ M1 : ∃γ.(¬γ → ¬γ), as follows: c(λy.z(y(λu1 .xu1 )(λu2 .xu2 ))) : ζ (→ I) λz.c(λy.z(y(λu1 .xu1 )(λu2 .xu2 ))) : ¬∃.¬(SA1 → SA2 ) λx.λz.c(λy.z(y(λu1 .xu1 )(λu2 .xu2 ))) : ¬∃.¬(SA1 → SA2 ) → ¬∃.¬(SA1 → SA2 ) λx.λz.c(λy.z(y(λu1 .xu1 )(λu2 .xu2 ))) : ∃γ.(¬γ → ¬γ)
Note that the derivation above is a simple derivation. For the only if part, assume that Γ M1 : ∃γ.(¬γ → ¬γ) in the system (→ ∃), and investigate simple derivations of the judgement. Theorem 4 (TCP (→ ∃)). The TCP of the system (→ ∃) in the Curry style is undecidable. The proof given to the theorem above works as well for the statement of type inference. Let N ≡ λx.λz.c(λy.z(y(λu1 .xu1 )(λu2 .xu2 ))) and N ≡ bN , and Γ = {b : ¬∃γ.(¬γ → ¬γ), c : ¬∃.¬(¬¬(B1 → γ1 ) → ¬¬(γ2 → B2 ) → A1 → A2 )}.
Theorem 5 (TIP (→ ∃)). {A1 ≤ B1 , A2 ≤ B2 } has a solution if and only if there exists some A such that Γ N : A in the system (→ ∃). Therefore, TIP of the system (→ ∃) in the Curry style is undecidable either. Proof. It is enough to show that if there exists some A such that Γ N : A then we have a simple derivation of Γ N : ζ. The only ways to apply (∃E) at the end of the derivation are: Γ N : ∃X.B Γ, x : B bx : A (∃E) Γ bx[x := N ] : A
Γ N : ∃X.B Γ, x : B x : A (∃E) Γ x[x := N ] : A
124
K. Fujita and A. Schubert
for some ∃X.B. The former case is impossible by Cor. 1, since N is in the form of λ-abstraction. In the latter case, N : ∃X.B must be derived by (→ E) by Cor. 1. Here, however, type of N cannot be existential but ζ. This implies that Γ N : A is, at the last step, derived by (→ E), where A ≡ ζ.
7
TCP and TIP Are Undecidable in Curry-Style (¬, ∧, ∃)
Let {A1 ≤ B1 , A2 ≤ B2 } be an instance of SUP built of type variables and ∧. We use for (¬∧∃) in the Curry style a reduction similar to the one in Theorem 3. Let M1 ≡ λx.c(λy.y λu1 .π1 xu1 , λu2 .π1 xu2 , π2 x) and Γ = {c : ¬∃.¬¬(¬¬(B1 ∧ γ1 ) ∧ ¬¬(γ2 ∧ B2 ) ∧ ¬(A1 ∧ A2 ))}. Theorem 6 (TCP (¬ ∧ ∃)). {A1 ≤ B1 , A2 ≤ B2 } has a solution if and only if Γ M1 : ∃γ.¬(¬γ ∧ γ) in the system (¬ ∧ ∃). The same method can be applied to TIP. Let N1 ≡ b(λx.c(λy.yλu1 .π1 xu1 , λu2 .π1 xu2 , π2 x)) and Γ1 = {b : ¬∃γ.¬(¬γ ∧ γ), c : ¬∃.¬¬(¬¬(B1 ∧ γ1 ) ∧ ¬¬(γ2 ∧ B2 ) ∧ ¬(A1 ∧ A2 ))}.
Theorem 7 (TIP (¬ ∧ ∃)). {A1 ≤ B1 , A2 ≤ B2 } has a solution if and only if there exists A such that Γ1 N1 : A in the system (¬ ∧ ∃). Proof. For the only-if part, assume that there exists A such that Γ1 N1 : A. Then we obtain Γ1 N1 : ⊥, which follows the proof of TCP.
8
Subject Reduction Property for Curry Systems
It is known [SU06] that the subject reduction property is broken in the Curry system with both ∀ and ∃. Prop. 2 is applied to the analysis of the subject reduction property as well. We show a stronger result that the system (→, ∃) does not enjoy the subject reduction property. Let I ≡ λx.x. Proposition 3 (Subject reduction of β). The subject reduction property of β-reduction is broken with respect to the existential system (→, ∃) in Curry-style. Let Γ be {f : Z → ∃X.(X → X), z : Z}. Then Γ λx.(If z)(If zx) : ∃X.(X → X) but Γ λx.(f z)(If zx) : ∃X.(X → X). Proof. It is enough to show that no simple derivations have Γ λx.f z(If zx) : ∃X.(X → X), following Lemma 6. Proposition 4 (Subject reduction of η). The subject reduction property of η-reduction is broken with respect to (→, ∃) or (¬, ∃). Proof. Let f : ∃X.X → W . Then take λa.f a : Z → W . Let g : ¬∃X.X, and then take λa.ga : ¬Z. From Lemma 6, neither f : (∃X.X) → W f : Z → W nor g : ¬∃X.X g : ¬Z can be derived in the Curry system.
Existential Type Systems with No Types in Terms
9
125
Discussion on Unification and Semiunification
In this paper, we consider type-free and Curry-style terms. The systems differ in how much of a derivation is preserved in a term — the Curry-style terms omit the information from the rules (∃E) and (∃I) while the type-free terms mark applications of the rules, but they omit the types used. This makes a considerable difference as far as derivation reconstruction problem are concerned. In case of a Curry-style term, we are forced to consider a potentially infinite number of ∃ introduction rules (as in the rule (∃I) from the derivation (2) in the proof of Theorem 3), while in a type-free term the number of the introduction rules is determined to be the number of occurrences of ∃, · construct (as in the terms of the first line in the term presented as (1) in Definition 7). A solution of a semiunification inequality X ≤ A where X is a variable is a pair of substitutions R, S such that R(S(X)) = S(A). The formulation of the problem does not restrict the domain of R in any way. Therefore, this problem matches well the situation we have in the Curry-style system. Still, the unification of . the equations in the flat form in its instance FX1 . . . Xn = A, where X1 , . . . , Xn are unique in the set of equations, requires a fixed number of ‘additions’ to the variable F. However, the equation in the flat form can be seen as a semiunification inequality in a variant of semiunification where an additional restriction on the substitution R is imposed to have domain of size n. It is indeed so as the variables X1 , . . . , Xn are unique in the whole set of equations. The difference between the case with the potentially infinite domain of R and with a domain of a fixed size is considerable as the original semiunification problem enjoys the most general solution property while the semiunification with restricted domain of R, as well as the 2nd order unification, does not. Therefore, it is difficult to devise a direct translation between the two problems and no such translation is known now. In [FS00], we have studied the type related problems of other systems between Church-style and Curry-style. One of them is known as the domain-free style, and the type inference problem had been shown undecidable for the predicative fragment of domain-free λ2, called domain-free ML. For this, we reduced the 2nd order unification problem for simple instances. However, the same reduction method cannot be applied to the problem of systems in the type-free style, since the previous method essentially refers to type information which is to be erased in the type-free case.
References [And95]
[Bar93] [Boe85]
Andou, Y.: A normalization-procedure for the first order classical natural deduction with full logical symbols. Tsukuba Journal of Mathematics 19(1), 153–162 (1995) Barendregt, H.: Lambda Calculi with Types. In: Handbook of Logic in Computer Science, vol. II. Oxford University Press, USA (1993) Boehm, H.-J.: Partial polymorphic type inference is undecidable. In: 26th Annual Symposium on Foundations of Computer Science, pp. 339–345. IEEE, Los Alamitos (1985)
126
K. Fujita and A. Schubert
[BS00] [FS00]
[Fuj] [Fuj05]
[Has06] [KTU90]
[KTU93]
[Mai90]
[MP88] [NTKN08]
[Pfe93] [Pra65] [Sch98]
[SU06]
[Wel99]
Barthe, G., Sørensen, M.H.: Domain-free pure type systems. J. Functional Programming 10, 412–452 (2000) Fujita, K., Schubert, A.: Partially typed terms between Church-style and Curry-style. In: Watanabe, O., Hagiya, M., Ito, T., van Leeuwen, J., Mosses, P.D. (eds.) TCS 2000. LNCS, vol. 1872, pp. 505–520. Springer, Heidelberg (2000) Fujita, K.: CPS-translation as adjoint (submitted) Fujita, K.: Galois embedding from polymorphic types into existential types. In: Urzyczyn, P. (ed.) TLCA 2005. LNCS, vol. 3461, pp. 194–208. Springer, Heidelberg (2005) Hasegawap, M.: Relational parametricity and control. LMCS 2, 3 (2006) Kfoury, A.J., Tiuryn, J., Urzyczyn, P.: The undecidability of the semiunification problem. In: STOC 1990: Proceedings of the twenty-second annual ACM symposium on Theory of computing, pp. 468–476. ACM Press, New York (1990) Kfoury, A.J., Tiuryn, J., Urzyczyn, P.: Type reconstruction in the presence of polymorphic recursion. ACM Trans. Program. Lang. Syst. 15(2), 290–311 (1993) Mairson, H.G.: Deciding ML typability is complete for deterministic exponential time. In: POPL 1990: Proceedings of the 17th ACM SIGPLANSIGACT symposium on Principles of programming languages, pp. 382– 401. ACM Press, New York (1990) Mitchell, J.C., Plotkin, G.D.: Abstract types have existential type. ACM Trans. Program. Lang. Syst. 10(3), 470–502 (1988) Nakazawa, K., Tatsuta, M., Kameyama, Y., Nakano, H.: Undecidability of type-checking in domain-free typed lambda-calculi with existence. In: Kaminski, M., Martini, S. (eds.) CSL 2008. LNCS, vol. 5213, pp. 478–492. Springer, Heidelberg (2008) Pfenning, F.: On the undecidability of partial polymorphic type reconstruction. Fundamenta Informaticae 19(1,2), 185–199 (1993) Prawitz, D.: Natural Deduction: A Proof-Theoretical Study. Almquist and Wiksell, Stockholm (1965) Schubert, A.: Second-order unification and type inference for Churchstyle polymorphism. In: POPL 1998: Proceedings of the 25th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pp. 279–288. ACM Press, New York (1998) Sørensen, M.H., Urzyczyn, P.: Lectures on the Curry-Howard Isomorphism. Studies in Logic and the Foundations of Mathematics, vol. 149. Elsevier Science Inc., New York (2006) Wells, J.B.: Typability and type checking in system F are equivalent and undecidable. Ann. Pure Appl. Logic 98(1–3), 111–156 (1999)
Initial Algebra Semantics for Cyclic Sharing Structures Makoto Hamana Department of Computer Science, Gunma University, Japan [email protected]
Abstract. Terms are a concise representation of tree structures. Since they can be naturally defined by an inductive type, they offer data structures in functional programming and mechanised reasoning with useful principles such as structural induction and structural recursion. In the case of graphs or ”tree-like” structures – trees involving cycles and sharing – however, it is not clear what kind of inductive structures exists and how we can faithfully assign a term representation of them. In this paper we propose a simple term syntax for cyclic sharing structures that admits structural induction and recursion principles. We show that the obtained syntax is directly usable in the functional language Haskell, as well as ordinary data structures such as lists and trees. To achieve this goal, we use categorical approach to initial algebra semantics in a presheaf category. That approach follows the line of Fiore, Plotkin and Turi’s models of abstract syntax with variable binding.
1 Introduction Terms are a convenient, concise and mathematically clean representation of tree structures used in logic and theoretical computer science. In the field of traditional algorithms or graph theory, one usually uses unstructured representations for trees, such as a pair (V, E) of vertices and edges sets, adjacency lists, adjacency matrices, pointer structures, etc, which are more complex and unreadable than terms. We know that term representation provides a well-structured, compact and more readable notation. However, consider the case of “tree-like” structures such as that depicted in Fig. 1. This kind of structures – graphs, but almost trees involving (a few) exceptional edges – quite often appears in logic and computer science. Examples include internal representations of expressions in implementations of functional languages that share common sub-expressions for efficiency, control flow graphs of imperative programs used in static analysis and compiler optimizations [CFR+ 91], data models of XML such as trees with pointers [CGZ05], proof trees admitting cycles for cyclic proofs [Bro05], and term graphs in graph rewriting [BvEG+ 87, AK96]. Suppose we want to treat such structures in a pure Fig. 1. functional programming language such as Haskell, Clean, or a proof assistant such as Coq, Agda [Nor07]. In such a case, we would have to abandon the use of naive term representation, and would instead be compelled to use an P.-L. Curien (Ed.): TLCA 2009, LNCS 5608, pp. 127–141, 2009. c Springer-Verlag Berlin Heidelberg 2009
128
M. Hamana
unstructured representation such as (V, E), adjacency lists, etc. Furthermore, a serious problem is that we would have to abandon structural recursion/induction to decompose them because they look “tree-like” but are in fact graphs, so there is no obvious inductive structure in them. This means that in functional programming, we cannot use pattern matching to treat tree-like structures, which greatly decreases their convenience. This lack of structural induction means failure of being an inductive type. But, are there really no inductive structures in tree-like structures? As might be readily apparent, treelike structures are almost trees and merely contain finite pieces of information. The only difference is the presence of “cycles” and “sharing”. In this paper, we give an initial algebra characterisation of cyclic sharing structures in the framework of categorical universal algebra. The aim of this paper is to derive the following practical goals from the initial algebra characterisation. [I] To develop a simple term syntax for cyclic sharing structures that admits structural induction and structural recursion principles. [II] To make the obtained syntax directly usable in the current functional languages and proof assistants, as well as ordinary data structures, such as lists and trees. The goal [I] also intends that the term syntax exactly characterises cyclic sharing structures (i.e. no junk terms exist) to make structural induction possible. The goal [II] intends that the obtained syntax should be lightweight as possible, which means that e.g. well-formedness and equality tests on terms for cyclic sharing structures should be fast and easy, as are ordinary data structures such as lists and trees. We do not want many axioms to characterise the intended structures, because in programming situation, to check the validity of axioms every time is expensive and makes everything complicated. Therefore, ideally, formulating structures without axioms is best. The goal [II] is rephrased more specifically as: [II’] To give an inductive type that represents cyclic sharing structures uniquely. We therefore rely on that a type checker automatically ensures the well-formedness of cyclic sharing structures. We choose a functional programming language Haskell to concretely show it in this paper. To archive these goals, we use the category theoretic formulation of initial algebra semantics. Recently, varying the base category other than Set, initial algebra semantics for functor-algebras has proved to be useful framework to characterise various mathematical/computational structures in a uniform setting. We list several: S -sorted abstract syntax is characterised as initial algebra in SetS [Rob02], second-order abstract syntax as initial algebra in SetF [FPT99, Ham04, Fio08] (where F is the category of finite sets), explicit substitutions as initial algebras in the category [Set, Set] f of finitary functors [GUH06], recursive path ordering for term rewriting systems as algebras in the category LO of linear orders [Has02], nested datatypes [GJ07] and generalised algebraic datatypes (GADTs) [JG08] in functional programming as initial algebras in [C, C] and [|C|, C] respectively, where C is a ω-cocomplete category. This paper adds a further example to the above list. We characterise cyclic sharing ∗ structures as an initial algebra in the category (SetT )T , where T is the set of all “shapes”
Initial Algebra Semantics for Cyclic Sharing Structures
129
of trees and T∗ is the set of all tree shape contexts. We derive structural induction and recursion principles from it. An important point is that we merely use algebra of functor to formulate cyclic sharing structures, i.e. not (models of) equational specifications or (Σ, E)-algebras. This achieves the requirement of “without axioms” and is the key to formulate them by an inductive type. Basic idea. It is known in the field of graph algorithms [Tar72] that, by traversing a rooted directed graph in a depth-first search manner, we obtain a depth-first search tree, which consists of a spanning tree (whose edges are called tree edges) of the graph and forward edges (which connect ancestors in the tree to descendants), back edges (the reverse), and cross edges (which connect nodes across the tree from right to left). Forward edges can be decomposed into tree and cross edges by placing indirect nodes. For example, the graph in Fig. 1 becomes a depth-first search tree in Fig. 2 where solid lines are tree edges and dashed lines are back and cross edges. This is the target structure we will model in this paper. That is, tree edges are the basis of an inductive structure, back edges are to form cycles, and cross edges are to form sharing. Consequently, our task is to seek how to characterise pointers making back edges and cross edges in inducFig. 2. Depth-first search tree tive constructions. Formulation. The crucial idea to formulate pointers in inductive constructions is to use binders as pointers in abstract syntax. Trees are formulated as terms. Hence, a remaining problem is how to exactly capture binders in terms. Fiore, Plotkin and Turi [FPT99] has characterised abstract syntax with variable binding by an initial algebra in the category SetF . For example, abstract syntax of λ-terms is modeled as a functor Λ:F
- Set
equipped with three constructors for λ-terms as an algebra structure on Λ. Each set Λ(X) gives the set of all λ-terms which may contain free variables taken from a set X in F. This formulation models a structure (here, abstract syntax trees) indexed by suitable invariant (here, free variables considered as contexts), which is essential information to capture the intended structure (abstract syntax with variable binding). However, this approach using algebras in SetF is insufficient to represent “cross edges” in tree-like graphs. Ariola and Klop has analysed that there are two kinds of sharing in this kind of tree-like graphs [AK96]: (i) vertical sharing (i.e. back edges in depth-first search trees) and (ii) horizontal sharing (i.e. cross edges). In principle, binders capture “vertical” contexts only, but to represent cross edges exactly, we must capture “horizontal” context information, which cannot be handled by the index category F. To solve this problem, in this paper we take a richer index category that is enough to model cross edges. We introduce the notion of shape trees and contexts consisting of them, which represents other parts of a tree viewing from a pointer node. We use shape trees T as “types” of syntax and T∗ as “context”. We use Fiore’s initial algebra semantics
130
M. Hamana
Fig. 3. Trees involving cycle and sharing
for typed abstract syntax with variable binding [Fio02] by algebras in the presheaf cat∗ egory (SetT )T . Hence cyclic sharing trees are modeled as a T and T∗ -indexed set T :T
- (T∗
- Set)
equipped with constructors of cyclic sharing trees as an algebra structure. Organisation. We first give types and abstract syntax for cyclic sharing binary trees in Section 2. We then characterise cyclic sharing binary trees as an initial algebra in Section 3. Section 4 gives a way of implementing cyclic sharing structures by an inductive type in Haskell. Section 5 generalises our treatment to arbitrary signature for cyclic sharing structures. Section 6 relates our representation and equational term graphs in the initial algebra framework by giving a homomorphic translation. In Section 7, we discuss connections to other approaches to cyclic sharing structures.
2 Abstract Syntax for Cyclic Sharing Structures Cyclic structures by μ-terms. The syntax of fixpoint expressions by μ-notation (μterms) is widely used in computer science and logic. Its theory has been thoroughly investigated, e.g., in [AK96]. The language of μ-terms suffices to express all cyclic structures. For example, a cyclic binary tree shown in Fig. 3 (i) is representable by the term μx.bin(μy1 .bin(lf(5), lf(6)), μy2 .bin( x, lf(7) ))
(1)
where bin and lf denote binary and leaf node, respectively. The point is that the variable x refers to the root labeled by a μ-binder, hence a cycle is represented. To uniquely formulate cyclic structures, here we introduce the following assumption: we attach μbinders in front of bin only, and put exactly one μ-binder for each occurrence of bin as for (1). This is seen as uniform addressing of bin-node, i.e., x, y1 , y2 are seen as as labels or “addresses” of bin-nodes. We also assume no axiom to equate μ-terms. That is, we do not identify a μ-term with its unfolding, since they are different (shapes of) graphs. In summary, μ-terms represent cyclic structures. This is the underlying idea of representation of cyclic data in a functional programming language Haskell [GHUV06]. How to represent sharing. Next, we incorporate sharing. The presence of sharing makes the situation more difficult. Consider the tree (ii) in Fig. 3 involving sharing via a cross edge. As similar to the case of cycles, this might be written as a μ-term μx.bin(μy1 .bin(lf(5), lf(6)), μy2 .bin(
, lf(7))).
Initial Algebra Semantics for Cyclic Sharing Structures
131
But can we fill the blank to refer the node a (in Fig. 3 (ii)) from the node c “horizontally” by using the mechanism of binders? Actually, μ-binders are insufficient for this purpose. Hence, we introduce a new notation “ p ↑ x” to refer to a node horizontally. This notation means going up to a node x labelled by a μ-binder and going down to a position p in the subtree rooted by the node x. In the above example, the blank is filled by 11↑x, which means going back to the node x, then going down through the left child twice (using the position 11). See also Example 1. We firstly focus on the formulation of binary trees involving cycles and sharing. Binary trees are the minimal case that can involve the notion of sharing in structures. To ensure correct sharing, we introduce the notion of shape trees. Shape trees. We call our target data structures cyclic sharing trees and its syntactic representation cyclic sharing terms. Cyclic sharing trees are binary trees generated by three kinds of nodes, that is, pointer, leaf, and binary node, and satisfying a certain well-formedness condition. We use skeletons of cyclic sharing trees, called shape trees. Shape trees are binary trees forgetting values in pointer and leaf nodes from cyclic sharing trees. The set T of all shape trees is defined by T τ ::= e | p | l | b(τ1 , τ2 ) where e is the void shape, p is the shape of pointer node, l is the shape of leaf node, and b(τ1 , τ2 ) is the shape of a binary node. We typically use Greek letters σ, τ to denote shape trees. We define referable positions in a shape tree. A position is a finite sequence of {1, 2}. The root position is denoted by the empty sequence and the concatenation of positions is denoted by pq or p.q. The set Pos(τ) of positions in a shape tree τ is defined by Pos(e) = Pos(p) = ∅, Pos(l) = {}, Pos(b(σ, τ)) = {} ∪ {1p | p ∈ Pos(σ)} ∪ {2p | p ∈ Pos(τ)}. An important point is that the void e and the pointer p nodes are not referable by other nodes, hence their positions are defined to be empties. Syntax and types. Shape trees are used as types in a typing judgment. As usual, a typing context Γ is a sequence of (variable, shape tree)-pairs. Typing rules (named binder version) (Pointer)
p ∈ Pos(σ) Γ, x : σ, Γ p↑x : p
(Node)
(Leaf)
k∈Z Γ lf(k) : l
x : b(e, e), Γ s : σ x : b(σ, e), Γ t : τ Γ μx.bin(s, t) : b(σ, τ)
In these typing rules, a shape tree type is assigned to the corresponding tree node. That is, a binary node is of type b(σ, τ) of binary node shape, a pointer node is of type p of pointer node shape, and a leaf node is of type l of leaf node shape. A type declaration x : σ in a typing context (roughly) means that σ is the shape of subtree (say, t) headed by a binder μx (see Example 1). Hence, in (Pointer) rule, taking
132
M. Hamana
a position p ∈ Pos(σ), we safely refer to a position in the tree t. The notation p↑x is designed to realise a right-to-left cross edge. Note also that a path obtained by p↑x is the shortest path from the pointer node to the node referred by p↑x. When p = , we abbreviate ↑x as ↑x. This ↑x exactly expresses a back edge. In (Node) rule, the shape trees b(e, e) and b(σ, e) mask nodes that are reachable via left-to-right references (i.e. not our requirement) or redundant references (e.g. going up to a node x then going back down through the same path) by the void shape e. Example 1. The binary tree involving sharing in Fig. 3 (ii) is represented by a welltyped term μx.bin(μy1 .bin(lf(5), lf(6)), μy2 .bin(11 ↑ x, lf(7))) Typing derivation is as follows. 11 ∈ Pos(β) y1 :α, x:α lf(5) : l y1 :b(l, e), x:α lf(6) : l y2 :α, x:β 11↑x : p y2 :b(p, e), x:β lf(7) : l x:α μy1 .bin(lf(5), lf(6)) : b(l, l) x:β μy2 .bin(11↑x, lf(7)) : b(p, l)
μx.bin(μy1 .bin(lf(5, lf(6)), μy2 .bin(11↑x, lf(7))) : b(b(l, l), b(p, l))
where α = b(e, e), β = b(b(l, l), e). Instead of named variables for binders, a de Bruijn notation is also possible. The construction rules are reformulated as follows. Now a typing context Γ is simply a sequence of shape trees τ1 , . . . , τn . Let |Γ| denote its length. A judgment Γ t : τ denotes a well-formed term t of shape τ containing free variables (de Bruijn indices) from 1 to |Γ|. The intended meaning is that the length |Γ| denotes how many maximally we can go up from the current node t, and each shape tree τi in Γ denotes the shape of the subtree at i-th upped node from t. Therefore, when t is a pointer, a context specifies the set of all positions that a pointer node can refer to. As known from λ-calculus, using de Bruijn notation, binders become nameless, so we can safely omit “x” from μx. Since the typing rules are designed to attach exactly one μ-binder for each bin, even “μ” can be omitted. Hence we have a simplified construction rules of terms. Typing rules (de Bruijn version) (dbPointer)
|Γ| = i − 1 p ∈ Pos(σ) Γ, σ, Γ p↑i : p
(dbNode)
(dbLeaf)
k∈Z Γ lf(k) : l
b(e, e), Γ s : σ b(σ, e), Γ t : τ Γ bin(s, t) : b(σ, τ)
In (dbPointer) rule, the condition |Γ| = i − 1 says that the shape tree σ appears at i-th position of the typing context in the lower judgment. Since for a given graph its depth-first search tree is unique, the following is immediate. Theorem 1. Given rooted graph which is connected, directed and edge-ordered, the term representation in de Bruijn is unique.
Initial Algebra Semantics for Cyclic Sharing Structures
133
Remark 1. This uniqueness of term representation has practical importance. For instance, for the graph in the tree (ii) in Fig. 3, there is only one way to represent it in this term syntax, i.e., bin(bin(lf(5, lf(6)), bin(11↑1, lf(7))) in de Bruijn. Hence, we do not need any complex equality on graphs (other than the syntactic equality) to check whether a given data is the required one. This is in contrast to other approaches. If we represent a graph as a term graph with labels [BvEG+ 87], an equational term graph [AK96], or a letrec-term [Has97], there are several syntactic representations for a single graph, hence some normalisation is required when e.g., defining a function on graphs. Generally speaking, our terms are seen as “de Bruijn notation” of term graphs with labels [BvEG+ 87].
3 Initial Algebra Semantics 3.1 Construction In this section, we show that cyclic sharing terms form an initial algebra and derive structural recursion and induction from it. We use Fiore’s approach to algebras for typed abstract syntax with binding [Fio02] in the presheaf category (SetF↓U )U where U is the set of all types. Now, we take the set T of all shape trees for U, and the set N of natural numbers for variables (i.e. pointers), instead of the category F of finite sets and all functions (used for renaming variables), because we do not need renaming of pointers. Algebras. We define the discrete category T∗ by taking contexts Γ = τ1 , . . . , τn as ob∗ jects (which is equivalent to N ↓ T). We consider algebras in (SetT )T . Two preliminary ∗ definitions. We define the presheaf PO ∈ SetT for pointers by PO( τ1 , . . . , τn ) = { p↑i | 1 ≤ i ≤ n, p ∈ Pos(τi )}. - SetT for context extension by For each τ ∈ T, we define the functor δτ : SetT δτ A = A( τ, − ). ∗ ∗ We define the signature functor Σ : (SetT )T - (SetT )T for cyclic sharing binary ∗ T∗ T trees, which takes A ∈ (Set ) and a type in T, and gives a presheaf in SetT , as follows: ∗
(ΣA)e = 0
(ΣA)p = PO
(ΣA)l = KZ
∗
(ΣA)b(σ,τ) = δb(e,e) Aσ × δb(σ,e) Aτ
where KZ is the constant functor to Z, and 0 is the empty set functor. A Σ-algebra ∗ A is a pair (A, α) consisting of a presheaf A ∈ (SetT )T for a carrier and a natural transformation α : ΣA → A for an algebra structure. By definition of Σ, to give an ∗ algebra structure is to give the following morphisms of SetT : ptrA : PO → Ap
lfA : KZ → Al
binσ,τ A : δb(e,e) Aσ × δb(σ,e) Aτ → Ab(σ,τ) .
A homomorphism of Σ-algebras is a map φ : (A, α) → (B, β) such that φ ◦ α = β ◦ Σφ. Initial Algebra. Let T be the presheaf of all derivable cyclic sharing terms defined by T τ (Γ) = {t | Γ t : τ}.
134
M. Hamana
Theorem 2. For the signature functor Σ for cyclic sharing binary trees, T forms an initial Σ-algebra. Proof. Since δτ preserves ω-colimits, so does Σ. An initial Σ-algebra is constructed by the colimit of the ω-chain 0 → Σ0 → Σ2 0 → · · · [SP82]. These construction steps correspond to derivations of terms by typing rules, hence their union T is the colimit. The algebra structure in : ΣT → T of the initial algebra is obtained by one-step inference of the typing rules, i.e., given by the following operations ptrT (Γ) : PO(Γ) → T p (Γ) p↑i → p↑i
lfT (Γ) : Z → T l (Γ) k → lf(k)
bin (Γ) : T σ (b(e, e), Γ) × T τ (b(σ, e), Γ) → T b(σ,τ) (Γ); T
s, t → bin(s, t).
This development of initial algebra characterisation follows the line of [FPT99, Fio02, MS03]. Hence we can further develop full theory of algebraic models of abstract syntax for cyclic sharing structures along this line. It will provide second-order typed abstract syntax with object/meta-level variables and substitutions via a substitution monoidal ∗ structure and a free Σ-monoid [Ham04, Fio08] in (SetT )T (by incorporating suitable arrows into T∗ ). Object/meta-substitutions on cyclic sharing structures will provide ways to construct cyclic sharing structures from smaller structures in a sensible manner. But this is not the main purpose of this paper, hence details will be pursued elsewhere. 3.2 Structural Recursion Principle One of the important benefit of initial algebra characterisation is that the unique homomorphism from the initial to another algebra is a mapping defined by structural recursion. Theorem 3. The unique homomorphism φ from the initial Σ-algebra T to a Σ-algebra A is described by φp (Γ)( p↑i) = ptrA (Γ)( p↑i) φl (Γ)(lf(k)) = lfA (Γ)(k) φb(σ,τ) (Γ)(bin(s, t)) = binA (Γ)(φσ (b(e, e), Γ)(s), φτ (b(σ, e), Γ)(t)) Proof. Since the unique homomorphism φ : T
- A is a morphism of (SetT∗ )T .
Example 2. We define (1) the function height that computes the height of a cyclic sharing tree t ∈ T τ (Γ) (2) the function leaves that collects all leaf values in t by structural recursion (where max is the maximal function): heightp (Γ)( p↑i) = 1
heightl (Γ)(lf(k)) = 1
heightb(σ,τ) (Γ)(bin(s, t)) = max(heightσ (b(e, e), Γ)(s), heightτ (b(σ, e), Γ)(t)) leavesp (Γ)( p↑i) = ∅
leavesl (Γ)(lf(k)) = {k}
leavesb(σ,τ) (Γ)(bin(s, t)) = leavesσ (b(e, e), Γ)(s) ∪ leavesτ (b(σ, e), Γ)(t)
Initial Algebra Semantics for Cyclic Sharing Structures
135
This is because leaves is the unique homomorphism from T to a Σ-algebra KZ whose operations are ptrKN (Γ)( p↑i) = ∅, lfKN (Γ)(k) = {k}, binKN (Γ)(x, y) = x∪y. Similarly for height. Notice that the height is not so directly defined in ordinary graph representations. From algorithmic point of view, this structural recursion principle provides depth-first search traversal of a rooted graph. Hence, graph algorithms based on depth-first search are directly programmable by this structural recursion. In the author’s home page (http://www.cs.gunma-u.ac.jp/˜hamana/), several other simple graph algorithms have been programmed by structural recursion. 3.3 Structural Induction Principle Another important benefit of initial algebra characterisation is the tight connection to structural induction principle. In order to derive it, following [HJ98], we use the cate∗ ∗ gory Sub((SetT )T ) for predicates on (SetT )T defined by ∗
• objects: sub-presheaves (Q → V), i.e., inclusions between Q, V ∈ (SetT )T , • arrows: u : (Q → V) → (P → U) are natural transformations u : V → U between underlying presheaves satisfying a ∈ Qτ (Γ) implies u(a) ∈ Pτ (Γ) for all τ ∈ T, Γ ∈ T∗ . A sub-presheaf (P → T ) is seen as a predicate P on cyclic sharing terms T , which is indexed by types and contexts. So, we say “PΓτ (t) holds” when t ∈ Pτ (Γ) for t ∈ T τ (Γ). ∗ ∗ ∗ We consider Σ-algebras in Sub((SetT )T ). The signature functor Σ : (SetT )T → (SetT )T T∗ T T∗ T is lifted to Σpred : Sub((Set ) ) → Sub((Set ) ), called the logical predicate lifting in [HJ98], by the same way to Σ: (Σpred (Q → V))p = (PO → PO) (Σpred (Q → V))e = (0 → 0)
(Σpred (Q → V))l = (KZ → KZ )
(Σpred (Q → V))b(σ,τ) = δb(e,e) (Q → V)σ × δb(σ,e) (Q → V)τ ∗
∗
where the context extension is also lifted to δτ : Sub(SetT ) → Sub(SetT ) defined by δτ (A → B) = (A τ, − → B τ, − ). Now, a Σpred -algebra structure α : Σpred (P → T ) → (P → T ) can be read as the induction hypothesis, e.g. binσ,τ P (Γ) : (Pσ (b(e, e), Γ) → T σ (b(e, e), Γ)) × (Pτ (b(σ, e), Γ) → T τ (b(σ, e), Γ))
→ (Pb(σ,τ) (Γ) → T b(σ,τ) (Γ));
s, t → bin(s, t)
means that “if Pσb(e,e),Γ (s) & Pτb(σ,e),Γ (t) holds, then PΓb(σ,τ) (bin(s, t)) holds.” By [HJ98], (T → T ) is an initial Σpred -algebra. The unique homomorphism φ : (T → T ) - (P → T ) means that P holds for all cyclic sharing terms in T . Hence Theorem 4. Let P be a predicate on T . To prove that PΓτ (t) holds for all t ∈ T τ (Γ), it suffices to show (i) PΓp ( p↑i) holds for all p↑i ∈ PO(Γ), (ii) PΓl (lf(k)) holds for all k ∈ Z, (iii) if Pσb(e,e),Γ (s) & Pτb(σ,e),Γ (t) holds, then PΓb(σ,τ) (bin(s, t)) holds. This structural induction principle can be used to prove properties of functions on cyclic sharing terms defined by structural recursion.
136
M. Hamana
4 Inductive Type for Cyclic Sharing Structures In this section, we realise our aim [II] to give an inductive type for cyclic sharing structures. We choose the functional language Haskell, because (1) we show that our characterisation of cyclic sharing is available in today’s programming language technology, and (2) Haskell’s type system is powerful enough to faithfully implement our initial algebra characterisation. The resulting definition might be close to implementations in proof assistants using dependent types such as Coq and Agda. Since the set T τ (Γ) of cyclic sharing terms depends on a shape tree and context, it should be implemented by a dependent type. We have seen in the proof of Thm. 2, constructors of cyclic sharing terms are T and T∗ -indexed functions. Inductive types defined by indexed constructors have been known as inductive families in dependent type theories [Dyb94]. Recently, Glasgow Haskell Compiler incorporates this feature as GADTs (generalised algebraic data types) [PVWW06]. With another feature called type classes, we can realise lightweight dependently-typed programming in Haskell [McB02]. We will implement T τ (Γ) as a GADT “T n t” that depends on a context n (for Γ) and a shape tree t (for τ). Since in Haskell, a type can only depend on types (not values), we firstly define type-level shape trees by using a type class. data E; data P; data L = StopLf; data B a b = DnL a | DnR b | StopB class Shape t instance Shape E; instance Shape P; instance Shape L instance (Shape s, Shape t) => Shape (B s t)
These define constructors of shape trees as types E,P,L and a type constructor B, then group them by the type class Shape. Values of a shape tree τ (e.g. B (B L L) L in Haskell) are Pos(τ) (e.g. DnL (DnR StopLf)), i.e. “referable positions” in τ. Similarly, a context τ1 , . . . , τn is coded as a type-level sequence TyCtx τn (TyCtx τn−1 · · · (TyCtx τ1 TyEmp)), and the type constructors are grouped by the type class Ctx. Values of a context type are “pointers” (e.g. (Up UpStop) meaning ↑2). data TyEmp; data TyCtx t n = Up n | UpStop | UpGD t class Ctx n instance Ctx TyEmp; instance (Shape t, Ctx n) => Ctx (TyCtx t n)
Finally, we define T τ (Γ) by a GADT “T” that takes a context and a shape tree as two arguments of types. data T :: * -> * -> * where Ptr :: Ctx n => n -> T n P Lf :: Ctx n => T n L Bin :: (Ctx n, Shape s, Shape t) => T (TyCtx (B E E) n) s -> T (TyCtx (B s E) n) t -> T n (B s t)
This defines three constructors of cyclic sharing terms faithfully (the part “Ctx n =>” is a quantification meaning that “for every type n which is an instance of the type class Ctx”). For example, the term in Example 1 is certainly a well-typed term and its type is inferred in Haskell:
Initial Algebra Semantics for Cyclic Sharing Structures
137
Bin (Bin (Lf 5) (Lf 6)) (Bin (Ptr (Up (UpGD (DnL (DnL StopLf))))) (Lf 7)) :: T TyEmp (B (B L L) (B P L))
The term Up (UpGD (DnL (DnL StopLf))) is the representation of the pointer 11 ↑ 2 in de Bruijn notation, which is read from the top as “up and up, then going
down (GD is short for going down) along the position 11 and stopping at a leaf”. The type inference and the type checker automatically ensures well-formedness of cyclic sharing terms. In Haskell, we can equally use the GADT T as an ordinary algebraic datatype, so we can define functions on it by structural recursion as described in Example 2 (even simpler; shape tree and context parameters are unnecessary in defining functions due to Haskell’s compilation method [PVWW06]). The implementation and further examples using the GADT T are available from the author’s home page.
5 General Signature We give construction of cyclic sharing structures for arbitrary signature as a natural generalisation of the binary tree case. A signature Σ for cyclic sharing structures consists of a set Σ of function symbols having arities. A function symbol of arity n ∈ N is denoted by f (n) . The set T of all shape trees is defined by T τ ::= e | p | f(τ1 , . . . , τn )
for each f (n) ∈ Σ.
Throughout this section, we use the convention that its small capital is associated with each letter of function symbol, e.g. f for f , g for g, etc. The set of all contexts is T∗ = { τ1 , . . . , τn | n ∈ N, i ∈ {1, . . . , n}, τi ∈ T}. Positions are defined by Pos(e) = Pos(p) = ∅, Pos(f(τ1 , . . . , τn )) = {} ∪ {1.p | p ∈ Pos(τ1 )} ∪ . . . ∪ {n.p | p ∈ Pos(τn )}. Typing rules |Γ| = i − 1 p ∈ Pos(σ) Γ, σ, Γ p↑i : p
γ1 , Γ t1 : τ1 · · · γn , Γ tn : τn f (n) ∈ Σ Γ f (t1 , . . . , tn ) : f(τ1 , . . . , τn )
where γ1 = f(e, . . . , e), γi+1 = f(τ1 , . . . , τi , e, . . . , e) for each 1 ≤ i ≤ n − 1. ∗
The shape trees γi ’s are also used below. The base category is (SetT )T . For a signature ∗ ∗ Σ, we associate a signature functor Σ : (SetT )T → (SetT )T defined by (ΣA)p = PO (ΣA)f(τ1 ,...,τn ) = δγi Aτi for each f (n) ∈ Σ (ΣA)e = 0 1≤i≤n
Theorem 5 (Initial algebra). Let Σ be a signature. T τ (Γ) = {t | Γ t : τ} forms an initial Σ-algebra where operations are: ptrT (Γ) : PO(Γ) → T p (Γ) f T (Γ) : 1≤i≤n T τi (γi , Γ) → T f(τ1 ,...,τn ) (Γ) p↑i → p↑i t1 , . . . , tn → f (t1 , . . . , tn ).
138
M. Hamana
Theorem 6 (Structural recursion). The unique homomorphism φ : T → A is φp (Γ)( p↑i) = ptrA (Γ)( p↑i) φf(τ1 ,...,τn ) (Γ)( f (t1 , . . . , tn )) = f A (Γ)(φτ1 (γ1 , Γ)(t1 ), . . . , φτn (γn , Γ)(tn )) Theorem 7 (Structural induction). To prove that PΓτ (t) holds for all t ∈ T τ (Γ), it suffices to show (i) PΓp ( p↑i) holds for all p↑i ∈ PO(Γ), γ ,Γ (ii) if f (n) ∈ Σ and Pτii (ti ) holds for all i = 1, . . . , n, then PΓf(τ1 ,...,τn ) ( f (t1 , . . . , tn )) holds. Moreover, to define a GADT for a given signature is straightforward as we have done in Sect. 4 for the signature of binary cyclic sharing trees.
6 Connection to Equational Term Graphs in the Initial Algebra Framework We have investigated a term syntax for cyclic sharing structures, which gives a representation of a graph. In this section, we give the converse, i.e., an explicit way to calculate the graph for a given cyclic sharing term. This means to give a semantics of cyclic sharing term by a finite graph. We give it by using Ariola and Klop’s equational term graphs in the initial algebra framework. This semantics makes clear connections to existing works on semantics of cyclic sharing structures. We will see it in next section. Equational term graphs [AK96] are another representation of cyclic sharing structures, which has been used in the formalisation of term graph rewriting. This is a representation of a graph by associating a unique name to each node and by writing down the interconnections through a set of recursive equations. For example, the graph in Figure 4 is represented by an equational term graph {x | x = bin(y1 , y2 ), y1 = bin(z, z), u = lf(6)}.
y2 = lf(9), z = bin(x, u),
We use this form of equational term graphs, called flattened form in [AK96] and formally defined as follows (NB. it is slightly different from the original syntax to make exFig. 4. plicit the connection to cyclic sharing terms). Suppose a signature Σ and a set X = {x, x1 , . . .} of variables. An equational term graph is of the form {x | x1 = t1 , x2 = t2 , . . .} where each ti follows the syntax t ::= x | p↑i | f (x1 , . . . , xn ) for each f (n) ∈ Σ. A variable is called bound if it appears in the left-hand side of an equation, and called free, otherwise. We also call p↑i free variables (and regard them as free variables). It is assumed [AK96] that any useless equation y = t, where y cannot be reachable from the root, is automatically removed. We define a translation from a cyclic sharing term to an equational term graph by the unique homomorphism from the initial algebra to an algebra consisting of equational term graphs. The idea is to use positions as the unique variables in an equational
Initial Algebra Semantics for Cyclic Sharing Structures
139
term graph. We define EGraphτ (Γ) by the set of all equational term graphs having free variables taken from PO(Γ) (where a shape index τ is meaningless for equational term graphs, but we just put this index to form a presheaf). This EGraph form a presheaf ∗ in (SetT )T . Any equational term graph can be drawn as a tree-like graph as Fig. 4, hence for each node, we can give its position in the whole equational term graph. So, an equational term graph {x1 | x1 = t1 , x2 = t2 , . . .} can be normalised to an “α-equivalent form” in which for each x = t, the bound variable x is renamed to the position of t in the whole term as { | = t1 , 1 = t2 , . . .} (see the example below). We identify an equation term graph with its α-normal form. Proposition 1. EGraph forms a Σ-algebra, and the unique homomorphism [[−]] : - EGraph is monomorphic and gives an interpretation of a cyclic sharing term T as a graph represented by an equational term graph. Proof. We define an algebra structure on EGraph on “α-equivalent form” as follows. fτEGraph (Γ)({ | G1 }, . . . , { | Gn }) = { | = f (1, . . . , n), G 1 , . . . , G n } where {1 | G 1 } = shift1 ({ | G1 }) · · · {n | G n } = shiftn ({ | Gn }) EGraph
ptrτ
(Γ)( p↑i) = { | = p↑i}
shiftq { | = t1 , 1 = t2 , . . .} = {q | q = shiftq (t1 ), q.1 = shiftq.1 (t2 ), . . .} shiftq (x) = q.x
for a free variable x, shiftq ( f (t1 , . . . , tn )) = f (shiftq.1 (t1 ), . . . , shiftq.n (tn )) pn · · · pi+1 p if q is pn · · · pi+1 · · · p1 , |q| ≥ i shiftq ( p↑i) = p↑(i − |q|) if |q| < i The function shiftq shifts every bound variable by a position q (i.e. appending q as prefix) in a term in order to form an equational term graph suitably. Then, it is obvious that [[−]] is monomorphic and gives a translation from cyclic sharing terms to equational term graphs. Example 3. Consider the term μx.bin(μy1 .bin(μz.bin(↑x, lf(6)), 1↑y1 ), lf(9)) of Fig. 2. This is represented as the following term in de Bruijn and is interpreted as an equational term graph: bin(bin(bin(↑3, lf(6)), 1↑1), lf(9)) [[−]]
→
12 = 11, { | = bin(1, 2), 111 = , 1 = bin(11, 12), 11 = bin(111, 112)}.
112 = lf(6), 2 = lf(9),
7 Further Connections to Other Works The semantics of cyclic sharing terms by equational term graphs opens connections to other semantics as T - EGraph - S where S is any of the following semantics of equational term graphs.
140
M. Hamana
(i) letrec-expressions: an equational term graph is obviously seen as a letrecexpression. (ii) Domain-theoretic semantics: mentioned below. (iii) Categorical semantics in terms of traced symmetric monoidal categories [Has97]. (iv) Coalgebraic semantics: a graph is seen as a coalgebraic structure that produces every node information along edges, e.g. [AAMV03]. The domain-theoretic semantics of letrec-expressions or systems of recursive equations (e.g. [CKV74]), is now standard, which gives infinite expansion of cyclic sharing structures. Via equational term graphs, we can interpret our cyclic sharing terms in each of these semantics. Each semantics has own advantage and principles to reason about some aspects of cyclic sharing structures. However, none of these has focused on our goals [I] a simple term syntax that admits structural induction, and [II] direct usability in functional programming, mentioned in Introduction. Hence, we have chosen the initial algebra approach to cyclic sharing structures.
8 Conclusion We have given an initial algebra characterisation of cyclic sharing structures and derived inductive datatypes, structural recursion and structural induction on them. We have also associated them with equational term graphs in the initial algebra framework, hence we have shown that various ordinary semantics of cyclic sharing structures are equally applied to them. In programming point of view, practicality of our datatype of cyclic sharing structures still need to be investigated. A possible direction of future work is to use dependently-typed programming language for programming with cyclic sharing structures as an extension of this work. Acknowledgments. The basis for this work, which was motivated by a question of Zhenjiang Hu, was done while the author visited IPL, University of Tokyo during April 2007 - March 2008. I express my sincere gratitude to Masato Takeichi and members of IPL for the opportunity to stay in a stimulating and pleasant research environment. I am also grateful to Varmo Vene and Tarmo Uustalu for discussion on datatypes in Haskell and reading early draft. This work is supported by the JSPS Grant-in-Aid for Scientific Research (19700006) and NII collaboration research grant. Finally, special thanks to Mika.
References [AAMV03] [AK96] [Bro05]
Aczel, P., Ad´amek, J., Milius, S., Velebil, J.: Infinite trees and completely iterative theories: a coalgebraic view. Theor. Comput. Sci. 300(1-3), 1–45 (2003) Ariola, Z.M., Klop, J.W.: Equational term graph rewriting. Fundam. Inform. 26(3/4), 207–240 (1996) Brotherston, J.: Cyclic proofs for first-order logic with inductive definitions. In: Beckert, B. (ed.) TABLEAUX 2005. LNCS (LNAI), vol. 3702, pp. 78–92. Springer, Heidelberg (2005)
Initial Algebra Semantics for Cyclic Sharing Structures [BvEG+ 87]
[CFR+ 91]
[CGZ05] [CKV74]
[Dyb94] [Fio02] [Fio08] [FPT99] [GHUV06] [GJ07] [GUH06] [Ham04]
[Has97] [Has02] [HJ98] [JG08] [McB02] [MS03] [Nor07] [PVWW06] [Rob02] [SP82] [Tar72]
141
Barendregt, H.P., van Eekelen, M.C.J.D., Glauert, J.R.W., Kennaway, R., Plasmeijer, M.J., Ronan Sleep, M.: Term graph rewriting. In: de Bakker, J.W., Nijman, A.J., Treleaven, P.C. (eds.) PARLE 1987. LNCS, vol. 259, pp. 141–158. Springer, Heidelberg (1987) Cytron, R., Ferrante, J., Rosen, B.K., Wegman, M.N., Kenneth Zadeck, F.: Efficiently computing static single assignment form and the control dependence graph. ACM Trans. Program. Lang. Syst. 13(4), 451–490 (1991) Calcagno, C., Gardner, P., Zarfaty, U.: Context logic and tree update. In: Proc. of POPL 2005, pp. 271–282 (2005) Courcelle, B., Kahn, G., Vuillemin, J.: Algorithmes d’equivalence et de reduction a des expressions minimales dans une classe d’equations recursives simples. In: Loeckx, J. (ed.) ICALP 1974. LNCS, vol. 14, pp. 200–213. Springer, Heidelberg (1974) Dybjer, P.: Inductive families. Formal Aspects of Computing 6, 440–465 (1994) Fiore, M.: Semantic analysis of normalisation by evaluation for typed lambda calculus. In: Proc. of PPDP 2002, pp. 26–37 (2002) Fiore, M.: Second-order and dependently-sorted abstract syntax. In: Proc. of LICS 2008, pp. 57–68 (2008) Fiore, M., Plotkin, G., Turi, D.: Abstract syntax and variable binding. In: Proc. of 14th Annual Symposium on Logic in Computer Science, pp. 193–202 (1999) Ghani, N., Hamana, M., Uustalu, T., Vene, V.: Representing cyclic structures as nested datatypes. In: Proc. of TFP 2006, pp. 173–188 (2006) Ghani, N., Johann, P.: Initial algebra semantics is enough! In: Della Rocca, S.R. (ed.) TLCA 2007. LNCS, vol. 4583, pp. 207–222. Springer, Heidelberg (2007) Ghani, N., Uustalu, T., Hamana, M.: Explicit substitutions and higher-order syntax. Higher-Order and Symbolic Computation 19(2/3), 263–282 (2006) Hamana, M.: Free Σ-monoids: A higher-order syntax with metavariables. In: Chin, W.-N. (ed.) APLAS 2004. LNCS, vol. 3302, pp. 348–363. Springer, Heidelberg (2004) Hasegawa, M.: Models of Sharing Graphs: A Categorical Semantics of let and letrec. PhD thesis, University of Edinburgh (1997) Hasegawa, R.: Two applications of analytic functors. Theor. Comput. Sci. 272(12), 113–175 (2002) Hermida, C., Jacobs, B.: Structural induction and coinduction in a fibrational setting. Inf. Comput. 145(2), 107–152 (1998) Johann, P., Ghani, N.: Foundations for structured programming with GADTs. In: Proc. of POPL 2008, pp. 297–308 (2008) McBride, C.: Faking it: Simulating dependent types in Haskell. J. Funct. Program. 12(4&5), 375–392 (2002) Miculan, M., Scagnetto, I.: A framework for typed HOAS and semantics. In: Proc. of PPDP 2003, pp. 184–194. ACM Press, New York (2003) Norell, U.: Towards a practical programming language based on dependent type theory. PhD thesis, Chalmers University of Technology (2007) Peyton Jones, S., Vytiniotis, D., Weirich, S., Washburn, G.: Simple unificationbased type inference for GADTs. In: Proc. of ICFP 2006, pp. 50–61 (2006) Robinson, E.: Variations on algebra: monadicity and generalisations of equational theories. Formal Aspects of Computing 13(3-5), 308–326 (2002) Smyth, M.B., Plotkin, G.D.: The category-theoretic solution of recursive domain equations. SIAM J. Comput 11(4), 763–783 (1982) Tarjan, R.E.: Depth-first search and linear graph algorithms. SIAM Journal of Computing 1(2), 146–160 (1972)
An Operational Account of Call-by-Value Minimal and Classical λ-Calculus in “Natural Deduction” Form Hugo Herbelin1 and Stéphane Zimmermann2 2
1 INRIA, France PPS, University Paris 7, France
Abstract. We give a decomposition of the equational theory of call-byvalue λ-calculus into a confluent rewrite system made of three independent subsystems that refines Moggi’s computational calculus: – the purely operational system essentially contains Plotkin’s βv rule and is necessary and sufficient for the evaluation of closed terms; – the structural system contains commutation rules that are necessary and sufficient for the reduction of all “computational” redexes of a term, in a sense that we define; – the observational system contains rules that have no proper computational content but are necessary to characterize the valid observational equations on finite normal forms. We extend this analysis to the case of λ-calculus with control and provide with the first presentation as a confluent rewrite system of SabryFelleisen and Hofmann’s equational theory of λ-calculus with control. Incidentally, we give an alternative definition of standardization in call-by-value λ-calculus that, unlike Plotkin’s original definition, prolongs weak head reduction in an unambiguous way.
Introduction The study of call-by-value evaluation in the context of λ-calculus goes back to Plotkin [1] who introduced and studied rules βv and ηv and a continuationpassing-style (cps) semantics of a call-by-value λ-calculus, named λv . Significant contributions were made first by Moggi [2] then by Sabry and Felleisen [3] who provided axiomatizations of call-by-value λ-calculus shown by the last authors to be complete with respect to Plotkin’s cps semantics. In the same paper, Sabry and Felleisen also give a sound and complete axiomatization of call-by-value λ-calculus with control (hereafter referred as classical call-by-value λ-calculus). Independently, Hofmann [4] gave an alternative axiomatization of the classical call-by-value λ-calculus. The theory of call-by-value λ-calculus turns out to be de facto more complex to describe than the one of call-by-name λ-calculus. While β-reduction is enough to evaluate terms in call-by-name λ-calculus and η is enough to characterize the observational equality on finite normal forms (what Böhm separability theorem P.-L. Curien (Ed.): TLCA 2009, LNCS 5608, pp. 142–156, 2009. c Springer-Verlag Berlin Heidelberg 2009
Call-by-Value Minimal and Classical λ-Calculus
143
expresses, see [5] for a generic account of Böhm theorem vs observational completeness), the situation is more intricate in the call-by-value λ-calculus, where, facing the two rules of the equational theory of call-by-name λ-calculus, the equational theories of call-by-value λ-calculus of Sabry and Felleisen and of Moggi rely on about a half dozen rules1 . Though, when we observe call-by-name and call-by-value in the context of sequent calculus [6,7], the complexity of the respective theories is about the same. Then, what is so specific to natural deduction (of which the standard λ-calculus is a notation for proofs along the Curry-Howard correspondence) that makes call-by-value more complicated there? Let us first give a more precise look at what happens in sequent calculus. Call-by-name and call-by-value in sequent calculus In a previous work of the first author with Curien [6], an interpretation of (a μvariant of) Gentzen’s sequent calculus [8] as a variant of λ-calculus called λμ˜ calculus was given, where μ refers to Parigot’s control operator [9]. In this interpretation, the left/right symmetry of sequent calculus pervades into a perfect syntactic duality first between terms and evaluation contexts, and secondly between call-by-name and call-by-value reduction. Especially, the operator μ ˜ , dual to μ, builds an evaluation context that binds the term to which it is applied, as in let x = [ ] in M , in the same way as Parigot’s μ builds a term that binds the evaluation context to which it is applied. The analysis of λ-calculus through sequent calculus given in [7], whether we consider call-by-name or call-by-value, shows a clear separation between operational rules and observation rules (the operational rules are cut-elimination rules and they divide into logical rules that contract the interaction of term constructors and evaluation context constructors into more elementary interactions, and two structural rules, one called (μ) for the contraction of μ and one called (˜ μ) for the contraction of μ ˜, that duplicate or erase information, moving terms around to possibly create new logical interactions). A noticeable peculiarity of sequent calculus is that even in the intuitionistic case, the μ operator is required and when sequent calculus is compared to intuitionistic natural deduction, it turns out that (μ) acts as a commutative cut. What is the problem with call-by-value λ-calculus in natural deduction syntax? Call-by-value λ-calculus precisely needs commutative cuts so as to reveal redexes hidden by β redexes that are not βv redexes. Take as an example the term ((λx.λy.y)(zt))u with z, t and u as free variables. With respect to λv , this term is a normal form, however the reduction between λy and u is possible if one 1
The theory of Moggi has seven rules; the theory of Sabry and Felleisen has six axioms of which βlift : E[let x = N in M ] → let x = N in E[M ] is redundant; we will see later on that isolating βlift out is however important from an operational point of view.
144
H. Herbelin and S. Zimmermann
takes a parallel syntax, like proof-nets or parallel application to obtain the term (λx.u)(zt). This is due to the presence of free variables, that can hide potential reductions. When using a parallel syntax, one does not rely anymore on syntactical shapes, but on calculus dependencies. In our example, the reduction between λx and (zt) is independent from the reduction between λy and u. This is where the structural rules announced in the abstract come in: they will denote implicit use of the reduction rule for μ. For call-by-name, we have the well-known σ-equivalence [10] that disentangle redexes, but we have to be more σ → (λy.(λx.M )N )P careful for call-by-value. So here, the rule ((λx.λy.M )N )P − is not valid, because one changes the evaluation order of N and P and will break confluence in presence of a μ operator. Our structural rules should then preserve head reduction order to avoid such problems.
1
Call-by-Value λ-Calculus (λCBV -Calculus)
In this section, we show how the equational theory of call-by-value λ-calculus can be decomposed into three independent subsystems of rules. Note that we consider here only left-to-right call-by-value. 1.1
The Splitting of the Usual βv Rule
To be able to use what sequent calculus teaches us, we need a construction μ. We extend the λ-calculus grammar with a let corresponding to the μ ˜ of λμ˜ construction, as follows: V ::= x | λx.M T ::= M N | let x = M in N M, N ::= V | T The direct counterpart of this splitting is syntactically expressed by the two following rules: (⇒) (λx.M )N → let x = N in M (letv ) let x = V in M → M [x ← V ] To understand the intuition behind this, it is necessary to look at how head reduction is performed on an application. We have to check first if M is a value or not, and then if N is a value or not to determine what to reduce. So control is not clear on an application, sometimes it is the left term that has it and sometimes it is the right one. Using the let is an elegant way to get rid of this. You only need to look at the left term of an application, and when this term is eventually reduced to a λ, it naturally gives the control to the term of the right thanks to the (⇒) rule. Thanks to this decomposition, we can now have a clear notion of control, and be able to determine where to work on. An evaluation context F is now either an application with a hole on the left, or a hole inside a let, say: F ::= [ ]M | let x = [ ] in M
Call-by-Value Minimal and Classical λ-Calculus
145
and the mechanism of giving control to the “right” part of the application is now explicit. As we will see later, this will help to solve a standardization problem that arises from this ambiguity. 1.2
Dealing with the Implicit (μ) Rules
Whenever in the calculus there exists a conditional rule (W )L → R, we will call a pseudo-redex a term matching L but not satisfying the side condition. For call-by-value λ-calculus, the term (λx.x)(yz) is a pseudo-redex, because yz is not a value. In our calculus, the pseudo-redexes are not of the shape (λx.M )T , but more like let x = T in M . Still, they can hide reductions. Take for example the term (let x = zt in λy.y)u, the counterpart to the term ((λx.λy.y)(zt))u. The reduction between λy and u is still hidden, and we need to get the u inside the let, in a sense. This can be done using the two rules (letlet ) and (letapp ). (letlet ) let x = (let y = M in N ) in P → let y = M in let x = N in P (letapp ) (let x = M in N )P → let x = M in N P The (letapp ) rule is here to deal with a pseudo-redex on the left side of an application. If you have a pseudo-redex inside on the left of an application, you can get it outside the application without disturbing the evaluation order, and recover the possible interactions that are independent of the substitution. Using this rule on the example above, we get (let x = zt in λy.y)u → let x = zt in (λy.y)u. The subterm zt still has control during the reduction, but we can do the other reductions as well. The (letlet ) rule has the same role, only for the right part of an application. 1.3
Basic Properties of the Calculus
Our presentation of call-by-value λ-calculus, called λCBV -calculus, is given in Figure 1. The auxiliary definition of evaluation context F (resp. E) is used to find the sub-term locally (resp. globally) in control in the term. The (⇒) and (letv ) rules correspond to the (βv ) rule, and the (letlet ) and (letapp ) rules are the two rules managing the implicit (μ) reductions2 . Regarding notations, we will use as a convention that parentheses on the left of an application are implicit, meaning that the term M N P stands for ((M N )P ). In the term λx.M , we will say that the occurrence of x in M are bound and by free variables, we mean variables that are not bound. The set of the free variables of a term M will be written F V (M ). To avoid problems of capturing variables, we will work modulo α-conversion, i.e. modulo the renaming of bound variables. Therefore, the names for free variables and bound variables in a given term can always be made distinct. By 2
These rules actually correspond to an infinite family of rules since E[yM ] is a metanotation for the term obtained by plugging yM in the hole of E.
146
H. Herbelin and S. Zimmermann Syntax V ::= x | λx.M M, N, P ::= V | M N | let x = M in N
F ::= [ ]M | let x = [ ] in M E ::= [ ] | xE | F [E]
Operational rules (⇒) (letv )
(λx.N )M let x = V in N
r
→ let x = M in N r → N [x ← V ] Structural rules r
(letlet ) let z = (let x = M in N ) in P → let x = M in (let z = N in P ) r (letapp ) (let x = M in N )P → let x = M in N P Observational rules (η⇒ ) λx.(yx) E (ηlet ) let x = M in E[x] (letvar ) z(let x = M in N )
r
→y r → E[M ] if x ∈ F V (E) r → let x = M in zN
Fig. 1. The full λCBV -calculus
M [x ← V ], we mean the capture-free substitution of every occurrence of the free variable x of M by V . r We write → for the compatible closure of → and →∗ for the reflexive and transitive closure of → . We write = for the equational theory associated. Proposition 1 (Confluence). The operational subsystem, its extension with structural rules and the full system of reduction rules are all confluent in λCBV calculus. Otherwise said, for each of these three systems, if M →∗ N and M →∗ N , then there exists P such that N →∗ P and N →∗ P . Proof (Indication). This statement is proved using Tait – Martin-Löf method, applied to the parallel reduction defined by the union (of generalizations) of the above reduction rules and the following congruence: – tt – if M M then λx.M λx.M – if M M and N N then M N M N and let x = M in N let x = M in N Note that (letvar ) is redundant in the equational theory but necessary in the reduction theory to get the confluence. We say that a reduction relation → is operationally complete if whenever a closed M is not a value, it is reducible along → . For instance, usual β-reduction is operationally complete for call-by-name λ-calculus.
Call-by-Value Minimal and Classical λ-Calculus
147
Proposition 2. λCBV equipped with the rules (⇒) and (letv ) is operationally complete. Proof. Any closed term which is not a value has either the form E[let x = λy.M in N ] in which case (letv ) is applicable or E[(λx.M )N ] in which case (⇒) is applicable. Remark. For simplicity of the definition of λCBV , we did not consider a minimal set of operational rules. A minimal operationally complete set can be obtained by restricting both M in (⇒) and V in (letv ) to be of the form λy.P . However, this r would force to explicitly add an observational rule let x = y in N → N [x ← y] r and a structural rule (λx.N )(E[yM ]) → let x = E[yM ] in N (where the notion of pseudo-redex and erasing rule, see below, is extended to the case of β-redexes). Associated to reduction rules with constraint, we can define erasing rules used to erase the pseudo-redex part of the rule. Namely, we will use the system composed of the following rule for this : er let x = N in M −→ N A term M is normal for a reduction → if it is not reducible for → . It er ∗ is structurally normal if, for all N such that M −→ N , N is normal for the reduction generated by the operational rules. A reduction relation → is structurally complete if all terms normal for → are structurally normal. Proposition 3. The set of terms that are normal with respect to the operational and structural rules is described by the entry Q of the following grammar: Q ::= λx.Q | S | let x = S in Q S ::= x | SQ Moreover, the reduction generated by the operational and structural rules of λCBV -calculus is structurally complete. Proof (Indication). The two parts are proved by induction quite directly. It is interesting to see that in a normal form like let x = P in Q, the leftmost subterm of P is always a free variable and the evaluation of P is blocked by this variable. This suggests an alternative definition of structural completeness based on the notion of evaluation of open terms: a set of rules is structurally complete iff any term which is neither a value nor of the form xM1 ...Mn or let y = xM1 ...Mn in N is reducible. Let us now focus on the observational rules of Figure 1. Given a confluent reduction → , we say that an equation M = N between normal terms belongs to the observational closure of → if for every closed evaluation context E and every substitution ρ of the free variables of M and N by closed values, E[ρ(M )] converges along →∗ iff E[ρ(N )] converges. Proposition 4. The observational rules from Figure 1 belong to the observational closure of the set of operational and structural rules of λCBV -calculus. Proof. When instantiated by closed values, both sides of (η⇒ ) and (letvar ) conE verge by respectively using (⇒) and (letv ), (⇒) and (letlet ). For (ηlet ), the result
148
H. Herbelin and S. Zimmermann
follows by standardization (see below) since at some point, for ρ a substitution of the free variables of E [yM ], the reduction of ρ(E [yM ]) eventually yields a value and (letv ) is applicable. 1.4
The Subformula Property and Structural Completeness
The λCBV -calculus can be typed by natural deduction just like the conventional (call-by-name) λ-calculus. The only new construction is the let, which can be typed by the cut rule. The whole typing system is the following: Γ, x : A M : B Γ, x : A x : A
Γ M :A⇒B
Γ λx.M : A ⇒ B Γ, x : A M : B
Γ N :A
Γ MN : B Γ N :A
Γ let x = N in M : B Contrary to the call-by-name λ-calculus, the original call-by value λ-calculus does not satisfy the subformula property for its normal forms. We can distinguish two kinds of “breaking” of this property. The first one happens with the pseudo-redexes. The term (λx.x)(yz) is a normal form, which can be typed this way, with Γ = y : B ⇒ A, z : B : Γ λx.x : A ⇒ A
Γ yz : A
Γ (λx.x)(yz) : A The problem here comes from the type A ⇒ A that appears after the cut between λx.x and yz. If we remember that a cut, in natural deduction, is an introduction rule followed by a elimination rule, then neither of the two rules, taken alone, are problematic. Think of normal forms like yM , corresponding to the elimination of implication, and λx.M , corresponding to the introduction of implication. It is really the cut that is causing problems. In λCBV , because the pseudo-redexes correspond to sequent calculus cuts, we can get rid of this problem. The A ⇒ A formula become A A, and our term become (λx.x)(yz) → let x = yz in x, whose proof has the subformula property. However, this is not enough to get rid of all our problems. With Γ = u : A, z : C ⇒ D, t : C the term (let x = zt in λy.y)u can be typed this way : Γ let x = zt in λy.y : A ⇒ B
Γ u:A
(let x = zt in λy.y)u : B Again, there is a A ⇒ B type appearing and breaking the subformula property. This time, it is not a problem of pseudo-redex, but rather one of hidden redex. To solve this, we need the structural (letapp ) rule to reduce the interaction between y and u and, in a more general manner our terms have to be structurally complete otherwise hidden redexes will create unnecessary arrow types.
Call-by-Value Minimal and Classical λ-Calculus
149
Pushing pseudo-redexes to more atomic let terms and having structural rules is sufficient to gain back the subformula property for λCBV , which is expressed by the following property. Proposition 5. Let M be a term of the λCBV calculus that is normal with respect to the operational and structural rules. Then if Γ M : A, its proof satisfies the subformula property. Proof. We shall reason by induction on the proof of Γ M : A. The only technical point is to know that on a normal form, the leftmost term on an application is a variable which is in the context. 1.5
Standardization
Plotkin’s definition of standard reduction sequences in λv does not characterize canonical standard reduction sequences: the standard reduction of a term is not h always unique. We first recall the definition of head reduction − → and standard reduction sequences (s.r.s.) in Plotkin [1]: h
– (λx.M )V − → M [x ← V ] – if M − → M then M N − → M N h h → M then V M − → V M – if M − h
h
h
– if M1 − → M2 and M2 , . . . , Nn is a s.r.s., then M1 , M2 , . . . , Nn is a s.r.s. – if M1 , . . . , Mn and N1 , . . . , Np are s.r.s., then M1 N1 , . . . , Mn N1 , . . . , Mn Np is a s.r.s. h
h
Now, if we take M and N such that M − → M and N − → N , then the two following reductions are standard: s
s
s
s
→ (λx.M )N − → (λx.M )N (λx.M )N − (λx.M )N − → (λx.M )N − → (λx.M )N The first one is built as an extension of head reduction, while the second one is built only using the application rule of standard reduction. The explanation is that in λv , there is no direct way to determine what is in control in an application, so there is no possibility to have a unique general rule for application. In λCBV , since the (βv ) rule was split, the control is unambiguous, so we can get rid of this problem. Weak-head reduction for λCBV and an alternative, non ambiguous, definition of standard reduction sequences are given below. – M − → M for any subset3 of rules of λCBV h
3
If (letv ) is present in the subset, we assume that M in the rules (letapp ), (letlet ), E ) is restricted to the form E[yM ] so that head reduction favors (letvar ) and (ηlet E ) is present, we assume that N in the rules (letapp ), (letlet ) and (letvar ) letv . If (ηlet E ). is not of the form E[x] so that head reduction favors (ηlet
150
H. Herbelin and S. Zimmermann
→ M then F [M ] − → F [M ] – if M − h
h
– any variable is a s.r.s. – if M, . . . , E1 [V1 ]4 is a head reduction sequence, and V1 , . . . Vn and E1 , . . . , Ep are s.r.s., then M, . . . , E1 [V1 ], . . . E1 [Vn ], . . . Ep [Vn ] is a s.r.s. – if M1 , . . . , Mn is a s.r.s., then λx.M1 , . . . , λx.Mn is a s.r.s. – [ ] is a s.r.s. on contexts – if M1 , . . . , Mn and E1 , . . . , Ep are s.r.s. on terms and on contexts, then the sequences E1 [let x = [ ] in M1 ], . . . , E1 [let x = [ ] in Mn ], . . . , Ep [let x = [ ] in Mn ] and E1 [[ ]M1 ], . . . , E1 [[ ]Mn ], . . . , Ep [[ ]Mn ] are s.r.s. on contexts
Note that the definition applies to λv too by using only (βv ) in the definition of head reduction. Theorem 1 (Standardization). For all M and N , if M →∗ N using any set of reduction rules there is a unique standard reduction sequence M, . . . , N s → N extending head reduction. We shall note this reduction M − Proof (Indication). We shall proceed by induction, with permutation of nonstandard reductions. Uniqueness is by canonicity of the definition of being a standard reduction sequence. But as we said before, we even got a stronger result. If M is a closed term, its head reduction (so its standard reduction) only uses the two rules (⇒) and (letv ), and the other rules are not necessary. We shall prove this, but we need to notice that if M is a closed term, then M cannot be decomposed through E[yP ], and if M = E[yP ], then M never reduces to a value. We could have provided a somehow “lighter” version of λCBV with rules (letapp ) or (letlet ) relaxed, like: (letapp ) (let x = M in N )P → let x = M in N P But then, a critical pair would have arisen, with the term (let x = V in N )P , between the rules (letapp ) and (letv ). This does not break confluence, but then head reduction of closed terms would have used our (letapp ) rule, which is not necessary, and we would have lost some structure on the calculus. To solve this, we only needed to give priority to the (letv ) rule over the (letapp ) rule by restricting the later only to terms which will never reduce to values. We can now state our proposition: Proposition 6. If M is a closed term such that M →∗ V , then there exists V h ∗
s
such that M − → V and V = V with − → using only the rules (⇒) and (letv ). Proof (Indication). As it is a consequence of the standard reduction, we just use an induction on the standard reduction of M . This result is not surprising, if you think that the (⇒) and (letv ) rules correspond to the (βv ) rule, and that (βv ) rule is sufficient to deal with closed terms. So we have a calculus where all rules have their own purpose, which is clearly defined. 4
Remember that E[] can be empty, so that M reduces to a value.
Call-by-Value Minimal and Classical λ-Calculus (βv ) (λx.M )V (letv ) let x = V in M (let.1) T M (let.2) V T (let.let) let y = (let x = M in N ) in P
→ → → → →
λx.V x (η⇒ ) (letid ) let x = M in x
→ V if x is not free in V → M
151
M [x ← V ] M [x ← V ] let x = T in xM with x fresh let x = T in V x with x fresh let x = M in let y = N in P
W ::= x | λx.Q Q ::= let x = yW in Q | xW | W Fig. 2. Moggi’s λC -calculus and its normal forms
1.6
Comparison with Moggi’s λc -Calculus
In [2], Moggi gives a call-by-value calculus, on the same syntax as λCBV . The reduction rules and the grammar characterizing normal forms with respect to the (βv ), (let.1), (let.2) and (let.let) rules are given in Figure 2 (T denotes terms that are not values). This calculus was made to allow more reducing than the original call-by-value calculus while remaining call-by-value. We say that two operational theories are in equational correspondence (see Sabry-Felleisen for the original notion [3]) if there is a bijection between the equivalence classes of the theories. Especially, we can show that our theory of λCBV is in equational correspondence with the one of Moggi. Proposition 7. The two calculi λc and λCBV are in equational correspondence. Proof (Indication). We only show here the interesting cases of the simulation of the rules. letapp = let.1 + let.let + (let.1)−1 letvar = let.2 + let.let + (let.2)−1 let x=[] in N −1 let.1 = (ηlet ) x[] For let.2 we proceed case by case. If V is y, then let.2 = (ηlet )−1 . If V = λy.M then let.2 =⇒ +(⇒)−1 . Our claim is now that λCBV has a finer structure than λc . First, observe that in Moggi’s calculus, for the same reason as in λCBV , the rules (βv ) and (letv ) are sufficient for operational completeness. Proposition 8. The λc -calculus restricted to the rules (βv ) and (letv ) is operationally complete. The λc -calculus equipped with (βv ), (letv ), (let.1), (let.2) and (let.let) is structurally complete. [] A weird point is the presence of an observational rule, namely (η⇒ ) in the simulation of the (let.1) and (let.2) rules, providing an ambiguous status to these two rules, used for computation but containing a bit of observation too. This
152
H. Herbelin and S. Zimmermann
can be related to another not so likable behavior of λc . We remember that the calculus has the (βv ) rule which is sufficient to reduce closed terms to values, but if we reduce the term (λx.x)((λx.x)(λx.x)) with head reduction, we obtain the following reduction sequence : (λx.x)((λx.x)(λx.x)) → let y = (λx.x)(λx.x) in (λx.x)y →∗ λx.x. The head reduction uses the rule (let.2) as the first reduction rule, and for the term ((λx.x)(λxy.y))(λx.x)(λx.x) the head reduction uses the rules (let.1) and (let.let). So, even if we do not need them, these rules appear and the λc -calculus tends to do useless expansions. This was already noticed by Sabry and Wadler in [11] where they showed that λc is isomorphic to one of its sub-calculi where all the let rules have been reduced, and applications occur only between two variables. The let construction is here a way to make the head-reduction flow explicit and to reduce a term, λc firstly encodes its evaluation flow with some let manipulation, and only then reduces the term. By doing this, we lose almost completely a “hidden agent” of the reduction : the structural congruence. In λv , the (βv ) rule was sufficient because it could go inside a term to find a redex, as here we almost never investigate in the term. The evaluation flow is encoded in a way that the topmost term always contains the redex, but is then superseding the structural congruence. So, the status of the let rules is not clearly defined. They are used for reducing closed terms to values, but are also necessary for the structural completeness and contain a taste of observational rules. Interestingly enough, we can switch between the normal forms or λC and E λCBV by using the η⇒ . Oriented from left-to-right we go from λC to λCBV and conversely with the right-to-left orientation.
2 2.1
Call-by-Value λμtp-Calculus (λμtpCBV -Calculus) Confluence and Standardization
Our calculus is not hard to extend with continuation variables and control operators. We follow the approach of [12] and adopt Parigot’s μ operator [9] together with a toplevel continuation constant tp, what simplifies the reasoning on closed computations and the connection with the λ-calculi based on callcc and A or Felleisen’s C operator. We write C[α ← [β]E] for the generalization of Parigot’s structural substitution and we abbreviate C[α ← [β]([ ])] as C[α ← β]. Since the reductions associated to μ absorb their context, structural rules should not change which subterm is in control, but happily structural rules are only like E[T ] → E [T ], so we cannot break confluence with them. We must be careful with μ reductions however. If μ does not have any reduction restrictions, let still can hide μ redexes. Therefore, we need a new structural rule. The full calculus is given in Figure 3. Proposition 9. The operational subsystem, its extension with structural rules and the full system of reduction rules are all confluent in the λμtpCBV -calculus.
Call-by-Value Minimal and Classical λ-Calculus
153
Syntax V M, N, P C q
::= ::= ::= ::=
x | λx.M V | M N | let x = M in N | μα.C [q]M α | tp
F ::= [ ]M | let x = [ ] in M E ::= [ ] | xE | F [E]
Operational rules (⇒) (letv ) (μv ) (μbase )
r
− → r − → r − → r − →
(λx.N )M let x = V in N F [μα.C] [q]μα.C
let x = M in N N [x ← V ] μα.C[α ← [α]F ] C[α ← q]
Structural rules r
→ let x = M in (let z = N in P ) (letlet ) let z = (let x = M in N ) in P − r (letapp ) (let x = M in N )P − → let x = M in N P r (letµ ) let x = M in μα.[β]N − → μα[β].let x = M in N Observational rules (η⇒ ) E (ηlet ) (ηµ ) (letvar ) (μvar )
λx.yx let x = M in E[x] μα.[α]M z(let x = M in N ) z(μα.C)
r
− → r → r − → r − → r − →
y E[M ] if x ∈ F V (E) M if α not free in M let x = M in zN μα.C[α ← [α](z[ ])]
Fig. 3. The full λμtpCBV -calculus
Proof. The proof is the same as before, using a generalization of (μv ) and (μbase ) to contexts of the form E or [q]E, with the parallel reduction extended with the two following rules : – if M M then [α]M [α]M – if C C then μα.C μα.C Note again the redundancy of (letvar ) and (μvar ) which are here for the confluence. As head reduction can be extended with the new rules, we obtain a notion of standardization for this calculus too.
154
H. Herbelin and S. Zimmermann
The rule letμ is here to deal with hidden μ-redexes, obfuscated by a let. As an example, the term (let x = yz in μα.[α]λx.x)t needs first to be reduced to (μα.[α]let x = yz in λx.x)t, then only the reduction between μα and [ ]t can occur. It is also interesting to see that being in call-by-value, we immediately dodge any problems with David and Py’s critical pair [13]. The term λx.(μα.c)x only reduces to λx.(μα.c[α ← [α][ ]x]), because of the η restriction to values. We say that M evaluates to V in λμtpCBV if [tp]M reduces to [tp]V and we say that a reduction relation → is operationally complete if whenever a closed M is not a value, [tp]M is reducible along → . 2.2
Normal Forms
Not only do we keep the confluence, telling us that the extension is reasonable, but we also keep all the other good properties of the intuitionistic calculus. The grammar generating normal forms with respect to the operational and structural rules, with T as an entry point, and the typing rules associated with the new μ construction are given in Figure 4 (T is a global parameter of the type system corresponding to the type of tp and all rules are generalized with a context Δ on the right). Properties on the normal forms are preserved, as the proposition below says. Γ u : N | β : M, α : N, Δ S ::= x | ST Q ::= λx.T | S | let x = S in Q Γ μβ.[α]u : M | α : N, Δ T ::= Q | μα.[β]Q
Γ u : T | β : M, Δ Γ μβ.[tp]u : M | Δ
Fig. 4. Normal forms and new typing rules for the λμtpCBV -calculus
Proposition 10. The λμtpCBV -calculus equipped with its set of operational rules is operationally complete and the λμtpCBV -calculus equipped with its sets of operational and structural rules is structurally complete. If T is a term in normal form relatively to the operational and structural rules of λμtpCBV -calculus and Γ T : A | Δ then its proof satisfies the subformula property. Proof (Indication). The first point is direct by the same proof as for the intuitionistic case. The second point is solved by induction, with most of the cases not being changed. 2.3
Equational Theory
In [3], Sabry and Felleisen devised an equational theory of call-by-value λcalculus with control operators that is sound and complete with respect to callby-value continuation-passing-style (cps) semantics. We recall only the part of the equations concerning the control operators below, because the other one is verified by Moggi’s calculus and so by λCBV .
Call-by-Value Minimal and Classical λ-Calculus
155
(Ccurrent ) callcc (λk.kM ) (Celim ) callcc (λd.M ) E[callcc M ] (Clift ) (Cabort ) (Ctail ) (Abort)
= callcc (λkM ) = M if d ∈ F V (M ) = callcc (λk.E[M (λf.(kE[f ]))]) if k, f ∈ F V (E, M ) callcc (λk.C[E[kM ]]) = callcc (λk.C[kM ]) for C a term with a hole not binding k callcc (λk.((λz.M )N )) = λz.(callcc (λk.M ))N if k ∈ F V (N ) E[AM ] = AM
Because the language of the equations is not the same as ours, we need some translations: callcc and A are encoded by the terms (λx.μα.[α](x(λy.μδ.[α]y))) and λx.μδ.[tp]x while, conversely, we encode μα.[β]M by callcc (λkα .A(kβ M )), μα.[tp]M by callcc (λkα .A(M )) and let x = N in M by (λx.M )N . By unfolding the definitions and doing basic calculations, we obtain the equational correspondence with the equations of Sabry and Felleisen. But instead of only having equations, we now have an oriented reduction system. Proposition 11. There is an equational correspondence at the level of closed expressions between λμtpCBV and Sabry and Felleisen’s axiomatization of λcalculus with callcc and A. Moreover, since we can equip λμtpCBV with a cps-semantics that matches the one considered in Sabry and Felleisen as soon as μα.c is interpreted by λkα .c, [α]M by M kα and [tp]M by M λx.x, we can transfer Sabry and Felleisen completeness result to the full theory of λμtpCBV . Corollary 1. The full calculus λμtpCBV is sound and complete with respect to βη along its cps-semantics. Since tp has a passive role in the reduction system of λμtpCBV , the confluence of the different subsystems and the structural and cps completenesses also hold for λμCBV which is λμtpCBV without tp.
Summary We studied the equational theory of call-by-value λ-calculus and λμ-calculus from a reduction point of view and provided what seems to be the first confluent rewrite systems for λμ-calculus with control that is complete with respect to the continuation-passing-style semantics of call-by-value λ-calculus. The rewrite system we designed is made of three independent blocks that respectively address operational completeness (ability to evaluate closed terms), structural completeness (ability to contract hidden redexes in open terms) and purely observational properties. The notion of structural completeness is related to the ability to enforce the subformula property in simply-typed λ-calculus but we failed to find a purely computational notion that universally captures the subformula property. For instance, any call-by-value reduction system that does not use a let and does
156
H. Herbelin and S. Zimmermann
not smash abstraction and application from redexes of the form (λx.M )(yz) cannot be accompanied with a typing system whose normal forms type derivation satisfies the subformula property. It would have been desirable to characterize the block of observational rules as a block of rules providing observational completeness, in a way similar to the call-by-name control-free case where β provides operational completeness and η provides observational completeness. Obtaining such a result would however require a Böhm-style separability result for call-by-value λ-calculus and λμ-calculus, what goes beyond the scope of this study. Regarding intuitionistic call-by-value λ-calculus we slightly refined Moggi and Sabry and Felleisen rewrite systems by precisely identifying which rules pertain to the operational block, the structural block or the observational block. Finally, we proposed a new definition of standard reduction sequences for call-by-value λ-calculus that ensures the uniqueness of standard reduction paths between two terms (when such a path exists).
References 1. Plotkin, G.D.: Call-by-name, call-by-value and the lambda-calculus. Theor. Comput. Sci. 1, 125–159 (1975) 2. Moggi, E.: Computational lambda-calculus and monads. Technical Report ECSLFCS-88-66, Edinburgh Univ. (1988) 3. Sabry, A., Felleisen, M.: Reasoning about programs in continuation-passing style. Lisp and Symbolic Computation 6(3-4), 289–360 (1993) 4. Hofmann, M.: Sound and complete axiomatisations of call-by-value control operators. Mathematical Structures in Computer Science 5(4), 461–482 (1995) 5. Dezani-Ciancaglini, M., Giovannetti, E.: From Böhm’s theorem to observational equivalences: an informal account. Electr. Notes Theor. Comput. Sci. 50(2) (2001) 6. Curien, P.L., Herbelin, H.: The duality of computation. In: Proceedings of ICFP 2000. SIGPLAN Notices, vol. 35(9), pp. 233–243. ACM, New York (2000) 7. Herbelin, H.: C’est maintenant qu’on calcule: au cœur de la dualité. Habilitation thesis, University Paris 11 (December 2005) 8. Gentzen, G.: Untersuchungen über das logische Schließen. Mathematische Zeitschrift 39, 176–210,405–431 (1935); English Translation in The Collected Works of Gerhard Gentzen, Szabo, M. E. (ed.), pp. 68–131 9. Parigot, M.: Lambda-mu-calculus: An algorithmic interpretation of classical natural deduction. In: Voronkov, A. (ed.) LPAR 1992. LNCS, vol. 624, pp. 190–201. Springer, Heidelberg (1992) 10. Regnier, L.: Une équivalence sur les lambda-termes. Theor. Comput. Sci. 126(2), 281–292 (1994) 11. Sabry, A., Wadler, P.: A reflection on call-by-value. ACM Trans. Program. Lang. Syst. 19(6), 916–941 (1997) 12. Ariola, Z.M., Herbelin, H.: Control reduction theories: the benefit of structural substitution. Journal of Functional Programming 18(3), 373–419 (2008); with a historical note by Matthias Felleisen 13. David, R., Py, W.: Lambda-mu-calculus and Böhm’s theorem. J. Symb. Log. 66(1), 407–413 (2001)
Refinement Types as Proof Irrelevance William Lovas and Frank Pfenning Carnegie Mellon University Pittsburgh, PA 15213, USA [email protected], [email protected]
Abstract. Refinement types sharpen systems of simple and dependent types by offering expressive means to more precisely classify well-typed terms. Proof irrelevance provides a mechanism for selectively hiding the identities of terms in type theories. In this paper, we show that refinement types can be interpreted as predicates using proof irrelevance in the context of the logical framework LF, establishing a uniform relationship between two previously studied concepts in type theory. The interpretation and its correctness proof are surprisingly complex, lending credence to the idea that refinement types are a fundamental construct rather than just a convenient surface syntax for certain uses of proof irrelevance.
1
Introduction
Refinement type systems seek to extend type theories with more expressive means of classifying terms. Refinements typically take the form of an added layer of sorts above the usual layer of types: types express very basic well-formedness criteria while sorts specify precise properties of terms using technology like subsorting and intersection sorts. Refinement types have been profitably employed in functional languages like ML [7, 4], and they are a topic of much recent and ongoing research [6, 5, 17]. In recent work [10], we developed a system of refinement types for the logical framework LF [8]. An essential guiding principle was to restrict attention to canonical forms using bidirectional typing [16]. Under the canonical forms methodology, features which typically complicate a type system’s metatheory could be expressed cleanly and simply. For example, treating intersection introduction as a checking rule and intersection elimination as a synthesis rule avoided any issues relating to intersection type inference, and restricting typing to canonical forms led to subtyping needing to be defined only at base type. A simple example of refinement types in LF is the natural numbers with refinements standing for even and odd numbers: nat : type. z : nat. s : nat → nat. even < nat. odd < nat. z :: even. s :: even → odd ∧ odd → even. P.-L. Curien (Ed.): TLCA 2009, LNCS 5608, pp. 157–171, 2009. c Springer-Verlag Berlin Heidelberg 2009
158
W. Lovas and F. Pfenning
In the above, even < nat declares even as a refinement of the type nat, and the declarations using “::” give more precise sorts for the constructors z and s. Note that since the successor function satisfies two unrelated properties, we give two refinements for it using an intersection sort. In this paper, we exhibit an interpretation of LF refinement types which we refer to as the “subset interpretation”, since a sort refining a type is interpreted as a predicate embodying the refinement, and the set of terms having that sort is simply the subset of terms of the refined type that also satisfy the predicate. For example, under the subset interpretation, we translate the refinements even and odd to predicates on natural numbers, or one-place judgments following the LF judgments-as-types principle [8]. The refinement declarations for z and s turn into constructors for proofs of these predicates. even : nat → type. odd : nat → type. z : even z. s1 : Πx:nat. even x → odd (s x). s2 : Πx:nat. odd x → even (s x). The successor function’s two unrelated sorts translate to proof constructors for two different predicates. We show that our interpretation is correct by proving, for instance, that a term has type S(N ), where S( − ) is the N has sort S if and only if its translation N translation of the sort S into a type family representing a predicate; thus, an adequate encoding using refinement types remains adequate after translation. The chief complication in proving correctness is the dependency of types on terms, which forces us to deal with a coherence problem [2, 13]. Normally, subset interpretations are not subject to the issue of coherence— that is, of ensuring that the interpretation of a judgment is independent of its derivation—since the terms in the target of the translation are the same as the terms in the source, just with the stipulation that a certain property hold of them. The proofs of these properties are computationally immaterial, so they may simply be ignored at runtime. But the presence of full dependent types in LF means that the interpretation of a sort might depend on these proofs, and in turn the derivability of certain typing judgments in the target might depend on the identities of these proofs. Enter proof irrelevance: our primary tool for coping with coherence. Proof irrelevance is a technique used in type theories to selectively hide the identities of certain terms representing proofs of propositions [11,1]. One typical use of proof irrelevance is to render the typechecking of subset types [3, 14] decidable. A subset type {x:A | B(x)} represents the set of terms of type A which also satisfy B; typechecking is undecidable because to determine if a term M has this type, you must search for a proof of B(M ). One might attempt to recover decidability by using a dependent sum Σx:A. B(x), representing the set of terms M of type A paired with proofs of B(M ); typechecking is decidable, since a proof of B(M ) is provided, but equality of terms is overly fine-grained: if there are two proofs of B(M ), the two pairs will be considered unequal. Using proof irrelevance, one can find a middle ground with the type Σx:A. [B(x)],
Refinement Types as Proof Irrelevance
159
where [−] represents the proof irrelevance modality. Type checking is decidable for such terms, since a proof of the property B is always given, but the identity of that proof is ignored, so all pairs with the same first component will be considered equal. Our situation with the subset interpretation is similar: we would like to represent proofs of sort-checking judgments without depending on the identities of those proofs. By carefully using proof irrelevance to hide the identities of sort-checking proofs, we are able to show our translation sound and complete, preserving the adequacy of representations. We begin the remainder of the paper by extending our example above to demonstrate the coherence issues that arise in the subset interpretation (Section 2). After that, we review the formal treatment of refinement types (Section 3) and proof irrelevance (Section 4) in the context of the logical framework LF, and then we discuss our translation and its correctness criteria in detail (Section 5). We conclude by highlighting some broader implications (Section 6).
2
Extended (Counter-)Example
Coherence arises in the subset interpretation due to the presence of dependent types. To show what can go wrong, we extend our example from the introduction to make use of dependency. Our uniform translation in Section 5 will be different in some details, but the essential ideas are unchanged. Consider a judgment double which relates any natural number to its doubling. double : nat → nat → type. dbl/z : double z z. dbl/s : ΠN:nat. ΠN2:nat. double N N2 → double (s N) (s (s N2)). Using refinement kinds, or classes, we can express the property that the second subject of any doubling relation is always even, no matter what properties hold of the first subject. We do so by defining a sort double* which is isomorphic to double, but has a more precise class. double* < double :: → even → sort. dbl/z :: double* z z. dbl/s :: ΠN::. ΠN2::even. double* N N2 → double* (s N) (s (s N2)). The sort represents a natural number with no special properties. Successfully sort-checking the declarations for dbl/z and dbl/s demonstrates that whenever double* M N is inhabited, the second argument, N, is even. There is a crucial difference between refinements like even or odd and refinements like double*: while even and odd denote particular subsets of the natural numbers, the inhabitants of the refinement double* x y are identical to those of the ordinary type double x y. What is important is not whether a particular instance double* x y is inhabited, but rather whether it is well-formed at all. For this reason, we separate the formation of a dependent refinement type family from its inhabitation. Following this idea, the refinement double* translates as follows:
160
W. Lovas and F. Pfenning
: nat → nat → type. double* x y. double*/i : Πx:nat. Πy:nat. even y → double* xy→ double* : Πx:nat. Πy:nat. double* ÷ double x y → type. There are three declarations after translation: which is inhabited exactly when a particular – a formation family, double*, z z will be inhabited, since instance of double* is well-formed (e.g. double* double* z z is well-formed), – a constructor for the formation family, double*/i, which builds such proofs of well-formedness (e.g. double*/i z z z will be a proof that double* z z is well-formed), and – a predicate family, double*, which for any x and y, will be inhabited by proofs that a given derivation of double x y has refinement double* x y, provided that double* x y is well-formed. In the predicate family double*, the proof of well-formedness is made irrelevant using a proof-irrelevant function space A → ÷ B, representing functions from A to B that are insensitive to the identity of their argument. Using irrelevance ensures that a given sort has a unique translation, up to equivalence. We elaborate on this below. The final component, the predicate family double*, is populated by constants generated from the refinement declarations. We write arguments in irrelevant position in [ square brackets ]. : double* z z dbl/z [ double*/i z z z ] dbl/z. : ΠN:nat. ΠN2:nat. Π N2:even dbl/s N2. ΠD:double N N2. ]D double* N N2 [ double*/i N N2 N2 → double* (s N) (s (s N2)) ] [ double*/i (s N) (s (s N2)) (s2 (s N2) (s1 N2 N2)) (dbl/s N N2 D). As is evident even from this short and abbreviated example, the interpretation leads to a significant blowup in the size and complexity of a signature, underscoring the importance of a primitive understanding of refinement types. Note that the formation argument of double* above is always made irrelevant as stipulated by its type. What if we hadn’t made the proofs of formation irrelevant? Then if there were more than one proof that double* x y were wellformed for a given x and y, a soundness problem could arise. To see how, imagine extending the above example with a sort distinguishing zero as a refinement. zero < nat. z :: even ∧ zero.
Refinement Types as Proof Irrelevance
161
As with even and odd, the sort zero turns into a predicate. Now that z has two sorts, it translates to two proof constructors. zero : nat → type. z1 : even z. z2 : zero z. Next, we can observe that zero always doubles to itself and augment the declaration of double* using an intersection class: double* < double :: → even → sort ∧ zero → zero → sort. After translation, since there are potentially two ways for double* x y to be wellformed, there are two introduction constants for the formation family. x y. 1 : Πx:nat. Πy:nat. even y → double* double*/i x y. 2 : Πx:nat. zero x → Πy:nat. zero y → double* double*/i and double* remain the same. The declarations for double* Now recall the refinement declaration for doubling zero, dbl/z :: double* z z , and observe that it is valid for two reasons, since double* z z is well-formed for two reasons. Consequently, after translation, there will be two proofs inhabit z z, but only one of them will be used in the ing the formation family double* translation of the dbl/z declaration. Supposing it is the first one, we’ll have : double* z z [ double*/i 1 z z z1 ] dbl/z , dbl/z check at the but our soundness criterion will still require that the constant dbl/z 2 z z2 z z2 ] dbl/z, the other possibility. The apparent type double* z z [ double*/i mismatch is resolved by the fact that the formation proofs are irrelevant, and so the two types are considered equal. Following the intuition given above, we may formally describe our translation and prove it correct. But first, we take a brief detour to review prior work on refinement types and proof irrelevance in LF.
3
Refinement Types
Refinement types give means of more precisely characterizing well-typed terms. Systems of refinement types usually sit on top of ordinary type systems, allowing the programmer to specify precise properties of programs already known to be well-typed. This refinement restriction is what allows refinement type systems to employ powerful features like subtyping and intersection and union types without overly complicating the system’s metatheory. Although traditionally treated in the context of functional programming [7, 6, 4, 5], recent work has shown how refinement types can be added to the
162
W. Lovas and F. Pfenning
K ::= type | Πx:A. K
(kinds)
A ::= P | Πx:A1 . A2
(types)
P ::= a | P N
(base types)
L ::= sort | Πx::S. L | | L1 ∧ L2
(classes)
S ::= Q | Πx::S1 . S2 | | S1 ∧ S2
(sorts)
Q ::= s | Q N
(base sorts)
Fig. 1. Syntax of LF types and kinds and LFR sorts and classes
logical framework LF [10], making it easier to adequately represent languages and logics with certain forms of judgmental inclusion and to declare and check precise properties about relations over such languages. Above, in Sections 1 and 2, we saw a simple example involving even and odd natural numbers and properties of the doubling relation. Here, we briefly recapitulate some of the details of the formal development to set the stage for what is to come. LF with refinement types, or LFR, is specified using the methodology of canonical forms, pioneered by Watkins, et al. [16] in the definition of the Concurrent Logical Framework, CLF. Following this methodology, we consider only canonical forms, or terms that are β-normal and η-long. Terms are syntactically restricted to the β-normal ones via a separation into atomic and normal terms: R ::= x | c | R N M, N ::= R | λx. N
(atomic terms) (normal terms)
These terms are typed bidirectionally with a synthesis judgment Γ R ⇒ A and a checking judgment Γ N ⇐ A. All judgments are relative to an implicit signature Σ, which declares types and kinds for term and type constants.1 Σ ::= · | Σ, a:K | Σ, c:A
(LF declarations)
In extending to LFR, we add three new forms of declaration: refinement declarations, constant sorting declarations, and subsorting declarations. · · · | Σ, s
(LFR declarations)
Sorts S refine types A, written Γ S < A; this judgment is defined compositionally, with the base case fulfilled by refinement declarations s
As usual, we write the signature explicitly on the turnstile only when necessary.
Refinement Types as Proof Irrelevance
163
The rule is restricted to base types, P , forcing all variables and constants to be fully applied. Note that although switch is the analogue of the usual “conversion rule”, since terms are canonical (β-normal, η-long), the equality P = P is just α-equivalence—we need not worry about β- or η-conversions. This key rule is changed only slightly for sort-checking: equality of base types P and P becomes subsorting between base sorts Q and Q. Q ≤ Q Γ R ⇒ Q (switch-sub) . Γ R⇐Q The switch-sub rule is in fact the only rule that appeals to subsorting: under the canonical forms methodology, subsorting need only be defined on base sorts, where it is simply the reflexive, transitive closure of the relation declared in the signature, extended through applications to identical arguments. Aside from the change to the switch rule, the only other change from typing to sorting is the addition of rules for introducing and eliminating intersections. Following the usual pattern in bidirectional typing, the introduction rules are checking rules and the elimination rules are synthesis rules. Γ N ⇐ S2 Γ N ⇐ S1 (∧-I) Γ N ⇐ S1 ∧ S2 Γ R ⇒ S1 ∧ S2 (∧-E1 ) Γ R ⇒ S1
Γ N ⇐
Γ R ⇒ S1 ∧ S2 (∧-E2 ) Γ R ⇒ S2
(-I)
(no -E)
To maintain terms in canonical form, we must also replace the usual syntactic substitution [M/x] N with the hereditary substitution [M/x]A N which hereditarily contracts any β-redexes substitution might have created. Hereditary substitution is indexed by the putative type A of the variable x in order to facilitate an early proof of decidability. For the purposes of this paper, though, we will simply write [M/x] N for hereditary substitution, since we have no need for ordinary substitution. In addition to sort-checking being decidable, LFR enjoys the usual Substitution and Expansion Principles: canonical terms may be substituted for variables, and every atomic term can be η-expanded to a canonical one. ηP (R) = R
ηΠx:A. B (R) = λx. ηB (R ηA (x))
Principle (Substitution). If ΓL , x::S, ΓR N ⇐ T and ΓL M ⇐ S, then ΓL , [M/x] ΓR [M/x] N ⇐ [M/x] T . Principle (Expansion). If Γ S < A and Γ R ⇒ S, then Γ ηA (R) ⇐ S.
4
Proof Irrelevance
When constructive type theory is used as a foundation for verified functional programming, we notice that many parts of proofs are computationally irrelevant,
164
W. Lovas and F. Pfenning
that is, their structure does not affect the returned value we are interested in. The role of these proofs is only to guarantee that the returned value satisfies the desired specification. For example, from a proof of ∀x:A. ∃y:B. C(x, y) we may choose to extract a function f : A → B such that C(x, f (x)) holds for every x:A, but ignore the proof that this is the case. The proof must be present, but its identity is irrelevant. Proof-checking in this scenario has to ascertain that such a proof is indeed not needed to compute the relevant result. A similar issue arises when a type theory such as λΠ is used as a logical framework. For example, assume we would like to have an adequate representation of prime numbers, that is, to have a bijection between prime numbers p and closed terms M : primenum. It is relatively easy to define a type family prime : nat → type such that there exists a closed M : prime N if and only if N is prime. Then primenum = Σn:nat. prime n is a candidate (with members N, M ), but it is not actually in bijective correspondence with prime numbers unless the proof M that a number is prime is always unique. Again, we need the existence of M , but would like to ignore its identity. This can be achieved with subset types [3, 14] {x:nat | prime(x)} whose members are just the prime numbers p, but if the restricting predicate is undecidable then type-checking would be undecidable, which is not acceptable for a logical framework. For LF, we further note that Σ is not available as a type constructor, so we instead introduce a new type primenum with exactly one constructor, primenum/i: primenum : type. primenum/i : ΠN:nat. prime N → ÷ primenum. Here the second arrow → ÷ represents a function that ignores the identity of its argument. The inhabitants of primenum, all of the form primenum/i N [M ], are now in bijective correspondence with prime numbers since primenum/i N [M ] = primenum/i N [M ] for all M and M . In the extension of LF with proof irrelevance [11, 12], or LFI, we have a new form of hypothesis x÷A (x has type A, but the identity of x should be irrelevant). In the non-dependent case (the only one important for the purposes of this paper), such an assumption is introduced by a λ-abstraction: Γ, x÷A M ⇐ B . Γ λx. M ⇐ A → ÷B We can use such variables only in places where their identity doesn’t matter, e.g., in the second argument to the constructor primenum/i in the prime number example. More generally, we can only use it in arguments to constructor functions that do not care about the identity of their argument: Γ R⇒A→ ÷B Γ⊕ N ⇐ A . Γ R [N ] ⇒ B Here, Γ ⊕ is the promotion operator which converts any assumption x÷A to x:A, thereby making x usable in N . Note that there is no direct way to use an assumption x÷A.
Refinement Types as Proof Irrelevance
165
Table 1. Judgments of the translation Judgment:
Result:
f ( − ) Γ L
≤
Type of proofs of the formation family Kind of the predicate family
s (−, −, −, −, −) K;K −) Γ S < A ; S( Γ Q
Type of coercions between families of kind K
Γ N ⇐S;N Γ R⇒S;R
Proof that N has sort S Proof that R has sort S
Γ Q1 ≤ Q2 ; F ( − , − ) Q1 ≤ Q2 ; Q 1 −Q2 Γ ctx ; Γ Σ sig ; Σ
Metacoercion from proofs of Q1 to proofs of Q2 Coercion from proofs of Q1 to proofs of Q2
Metafunction representing predicate Proof that Q is well-formed
Translated context Translated signature
The underlying definitional equality “=” (usually just α-conversion on canonical forms) is extended so that R [N ] = R [N ] if R = R , no matter what N and N are. The substitution principle (shown here only in its simplest, non-dependent form) captures the proper typing as well as the irrelevance of assumptions x÷A: Principle (Irrelevant Substitution). If Γ, x÷A N ⇐ B and Γ ⊕ M ⇐ A then Γ [M/x] N ⇐ B and [M/x] N = N (under definitional equality).
5
Interpretation
5.1
Overview
We interpret LFR into LFI by representing sorts as predicates and derivations of sorting as proofs of those predicates. The translation is derivation-directed and compositional: for each judgment Γ J , there is a corresponding judgment Γ J ; X whose rules mimic the rules of Γ J . The syntactic class of X and its precise interpretation vary from judgment to judgment (for reference, the various forms are listed in Table 1), but a great deal of insight can be had by examining the specific cases of sort formation and sort checking. Sort formation is embodied by the refinement judgment Γ S < A. The in which corresponding translation judgment has the form Γ S < A ; S, S is a meta-level function representing the sort S as a predicate. Sort checking . Since N represents a Γ N ⇐ S becomes term translation Γ N ⇐ S ; N 2 proof that N has sort S, we should expect that N ⇐ S(N ). 2
Under an appropriate context, briefly discussed below.
166
W. Lovas and F. Pfenning
For example, take the rule ∧-I of intersection introduction. The corresponding translation rule represents the two independent derivations as a pair of proofs. Accordingly, the intersection sort formation rule yields a product of predicates.3 1 Γ N ⇐ S1 ; N 2 Γ N ⇐ S2 ; N 1 , N 2 Γ N ⇐ S1 ∧ S2 ; N
1 Γ S1 < A ; S 2 Γ S2 < A ; S 1 (N ) × S 2 (N ) Γ S1 ∧ S2 < A ; λN . S
We use a bold λ for meta-level abstraction and bold (parens) for meta-level application. Our translation is similar in spirit to Liquori and Ronchi Della Rocca’s Λt∧ [9], a Church-style type system for intersections in which derivations are explicitly represented as proofs and intersections as products. At the top-level, we are interested in checking entire signatures, so it is also instructive to examine the rules for translating the LFR declarations. As we saw with even and odd in Section 1, sorting declarations for constants turn into proof constructor declarations. Σ sig ; Σ c:A ∈ Σ · Σ S < A ; S A (c)) Σ, c::S sig ; Σ, c:S(η This matches our intuitions: the proof constructor c witnesses the fact that the constant c satisfies property S. Since our predicates expect terms in canonical form, we η-expand the constant. The translation on contexts is similar. As we saw with double* in Section 2, a refinement declaration turns into three declarations: one for the formation family, one for the proof constructor for the formation family, and one for the predicate family. pred form p K ; K · Σ L < K ; L f s:K, s/i:L f ( p ( Σ, s
Σ sig ; Σ
a:K ∈ Σ
form The class formation judgment Γ L < K ; L f yields a metafunction describing the type of proofs of formation family, while an auxiliary kind translation pred p yields a metafunction describing the kind of the predicate judgment K ; K family. Recall from our earlier example that the kind of the formation family is the same as the kind of the refined type, in this case K. f takes as input the formation family so far (initially just The metafunction L s) and the translation derivation adds arguments on the way up. At the base case it returns the formation family itself. p takes two arguments: one for the formation family so The metafunction K far (initially s) and one for the refined type so far (initially a). This translation is characterized by its behavior on the base kind, type: pred
type ; λ(Qf , P ). Qf → ÷ P → type 3
For compositionality’s sake, we target an extension of LFI with product and unit types. Such an extension is orthogonal to the addition of proof irrelevance, and has been studied by many people over the years, including Sch¨ urmann [15].
Refinement Types as Proof Irrelevance
167
The kind of the predicate family for a base sort Q refining P is essentially a oneplace judgment on terms of type P , along with an irrelevant argument belonging to the formation family of Q. In light of this, we can make sense of the rule for translating base sorts: Γ Q < P ⇒ L ; Q
P = P L = sort N Γ Q < P ; λN . Q [Q]
yields a proof of The class synthesis translation judgment Γ Q < P ⇒ L ; Q Q’s formation family; thus the predicate for a base sort Q, given an argument that Q is N , is simply the predicate family Q applied to an irrelevant proof Q well-formed and the argument itself, N . We postpone a discussion of subsorting declarations s1 ≤s2 until after a brief review of some metatheoretic results. 5.2
Correctness
Soundness theorems tell us that the result of a translation is well-formed. Even more importantly than telling us that our translation is on some level correct, they serve as an independent means of understanding the translation. In a sense, a soundness theorem can be read as the meta-level type of a translation judgment, and just as types serve as an organizing principle for the practicing programmer, so too do soundness theorems serve the thoughtful theoretician. We mention a few such theorems, then, not only to demonstrate the sensibility of our translation, but also to aid the reader in understanding its purpose. In what follows, form(Q) represents the formation family for a base sort Q. form(s) = s
form(Q N ) = form(Q) N
Then: Theorem 1 (Soundness). Suppose Γ ctx ; Γ and Σ sig ; Σ. ⇐ S(N ). , then Γ N 1. If Γ S < A ; S and Γ N ⇐ S ; N Σ 2. If Γ R ⇒ S ; R, then Γ S < A ; S and Γ Σ R ⇒ S(ηA (R)) (for some A and S). ) ⇐ type. 3. If Γ S < A ; S and Γ N ⇐ A, then Γ Σ S(N p, 4. If Γ Q < P ⇒ L ; Q, then for some K, Lf , and K form ⇒L f ( form(Q)), and – Γ L < K ; Lf and Γ Σ Q pred p and Γ Q ⇒ K p ( form(Q), P ). – K ; K Σ
f (P ) ⇐ type. f and Γ P ⇒ K, then Γ L 5. If Γ L < K ; L Σ pred p (Qf , P ) ⇐ kind. p , Γ Qf ⇒ K, and Γ P ⇒ K, then Γ K 6. If K ; K Σ form
The soundness theorems are each proven by induction on the theorem’s main input derivation. Several clauses must be proved mutually, and not all theorems are shown here. The proofs appeal to several key lemmas.
168
W. Lovas and F. Pfenning
Lemma 1 (Erasure). If Γ J ; X, then Γ J . Lemma 2 (Reconstruction). If Γ J , then for some X, Γ J ; X. Erasure and Reconstruction substantiate the claim that our translation is derivation-directed by allowing us to move freely between translation judgments and ordinary ones. Using Erasure and Reconstruction, we can leverage all of the LFR metatheory without reproving it for translation judgments. For example, several cases require us to substitute into a translation derivation: we can apply Erasure, appeal to LFR’s Substitution Theorem, and invoke Reconstruction to get the output we require. But since Reconstruction only gives us some output X, we may not know that it is the one that suits our needs. Therefore, we usually require another lemma, Compositionality, to tell us that the translation commutes with substitution. There are several such lemmas; we show here the one for sort translation. Lemma 3 (Compositionality). Let σ denote [M/x]. If Γ, x:: S < A ; S ) = S (σN ). and Γ σS < σA ; S , then σ S(N Completeness theorems tell us that our target is not too rich: that everything we find evidence of in the codomain of the translation actually holds true in its domain. While important for establishing general correctness, completeness theorems are not quite so nice to look at as soundness theorems, so we give here only the cases for terms. Then: Theorem 2 (Completeness). Suppose Γ ctx ; Γ and Σ sig ; Σ. ⇐ S(N ), then Γ N ⇐ S. 1. If Γ S < A ; S and Γ Σ N ⇒ B, then Γ S < A ; S, B = S(η A (R)), and Γ R ⇒ S 2. If Γ Σ R (for some S, A, S, and R). In stating Completeness, we syntactically isolate the set of terms that could and N . Completeness is proven by represent proofs using, e.g., metavariables R induction over the structure of these terms. Adequacy of a representation is generally shown by exhibiting a compositional bijection between informal entities and terms of certain LFR sorts. Since we have undertaken a subset interpretation, the set of terms of any LFR sort are unchanged by translation, and so any bijective correspondence between those terms and informal entities remains after translation. Furthermore, soundness and completeness tell us that our interpretation preserves and reflects the derivability of any refinement type judgments over those terms. Thus, we have achieved our main goal: any adequate LFR representation can be translated to an adequate LFI representation. 5.3
Subsorting
We now return to the question of how the translation handles subsorting. Recall that an LFR signature can include subsorting declarations between sort family
Refinement Types as Proof Irrelevance
169
constants, s1 ≤s2 . We require both sort constants to refine the same type constant a and to have the same class L. The rule for translating such declarations creates a coercion constant s1 -s2 . Σ sig ; Σ
s1
s2
≤ s K;K
≤ The auxiliary judgment K ; K s yields a metafunction describing the type of coercions between sorts that refine a type family of kind K. The metafunction s takes five arguments: the refined type, the formation family and predicate K family for the domain of the coercion, and the formation family and predicate family for the codomain of the coercion. As before, the translation derivation builds up a spine of arguments on the way up towards the leaves. At the base kind type, it outputs the type of the coercion:
≤
type ; λ(P , Q1 f , Q1 , Q2 f , Q2 ). Πf1 :Q1 f . Πf2 :Q2 f . Πx:P. Q1 [f1 ] x → Q2 [f2 ] x
Essentially, this is the type of coercions, given x, from proofs of Q1 x to proofs of Q2 x, but of course we must pass Q1 and Q2 proof that they are well-formed, so the coercion requires those proofs as inputs as well. How do these coercions work? Recall from Section 3 that subsorting need only be defined at base sorts Q, and there, it is simply the application-compatible, reflexive, transitive closure of the declared relation. For the purposes of the translation, we give an equivalent algorithmic formulation of subsorting. Following the inspiration of bidirectional typing, we give two judgments: a checking judgment that takes two base sorts as inputs and a synthesis judgment that takes one base sort as input and outputs another base sort that is one step higher in the subsort hierarchy. The synthesis judgment constructs a coercion from the new coercion constants in the signature. s1 ≤s2 ∈ Σ s1 ≤ s2 ; s1 -s2
Q1 ≤ Q2 ; Q 1 −Q2 Q1 N ≤ Q2 N ; Q 1 −Q2 N
The checking judgment, on the other hand, constructs a meta-level coercion between the two sorts. It is defined by two rules: a rule of reflexivity and a rule to climb the subsort hierarchy. Q1 = Q2 (refl) Γ Q1 ≤ Q2 ; λ(R, R1 ). R1 1 Γ Q1 < P ⇒ sort ; Q Γ Q < P ⇒ sort ; Q (climb) Γ Q1 ≤ Q2 ; λ(R, R1 ). F (R, Q 1 −Q Q1 Q R R1 ) Q1 ≤ Q ; Q 1 −Q Γ Q ≤ Q2 ; F
170
W. Lovas and F. Pfenning
The reflexivity rule’s metacoercion simply returns the proof it is given, while the climb rule composes the actual coercion Q 1 −Q with the metacoercion F . Two extra premises generate the necessary formation proofs. We can now end where we started, with the switch rule. Using the metacoercion generated by subsort checking, we can construct the proof we need for soundness. Γ R ⇒ Q ; R
Γ Q ≤ Q ; F (switch-sub). Γ R ⇐ Q ; F (R, R)
6
Conclusion
Logical frameworks are metalanguages specifically designed so that common concepts and notations in logic and the theory of programming languages can be represented elegantly and concisely. LF [8] intrinsically supports α-conversion, capture-avoiding substitution, and hypothetical and parametric judgments, but as with any such enterprise, certain patterns fall out of its scope and must be encoded indirectly. One pattern is the ability to form regular subsets of types already defined. This is addressed in LF extended with type refinement (LFR) [10]. Another pattern is to ignore the identities of proofs, relying only on their existence. This is addressed in LF extended with proof irrelevance (LFI) [11, 12]. In this paper we have shown that the former can be mapped to the latter in a bijective manner, preserving adequacy theorems for LFR representations in LFI. In the methodology of logical frameworks research, it is important to understand the cost of such a translation: how much more complicated are encodings in the target framework, and how much more difficult is it to work with them? We cannot measure this cost precisely, but we hope it is evident from the definition of the translation and the examples that the price is considerable. Even if in special cases more direct encodings are possible, we believe our general translation could not be simplified much, given the explicit goal to preserve the adequacy of representations. Other translations from programming languages, such as coercion interpretations where sorts are translated to distinct types and subsorting to coercions, appear even more complex because adequacy depends on certain functional equalities between coercions. Our preliminary conclusion is that refinement types in logical frameworks provide elegant and immediate representations that are not easy to simulate without them, providing a solid argument for their inclusion in the next generation of frameworks. Refinement types have been also been proposed for functional programming [7, 4], most recently in conjunction with a limited form of dependent types [5]. Proof irrelevance is already integrated in this setting, and also available in general type theories such as NuPrl or Coq. One can ask the same question here: Can we simply eliminate refinement types and just work with dependent types and proof irrelevance? The results in this paper lend support to the conjecture that this can be accomplished by a uniform translation. On the other hand, just as here, it seems there would likely be a high cost in terms of brevity in order to
Refinement Types as Proof Irrelevance
171
maintain a bijection between well-sorted data in the source and dependently well-typed data in the target of the translation. Acknowledgements. Thanks to Jason Reed for many fruitful discussions on the topic of proof irrelevance.
References 1. Awodey, S., Bauer, A.: Propositions as [types]. Journal of Logic and Computation 14(4), 447–471 (2004) 2. Breazu-Tannen, V., Coquand, T., Gunter, C.A., Scedrov, A.: Inheritance as implicit coercion. Information and Computation 93(1), 172–221 (1991) 3. Constable, R.L., et al.: Implementing Mathematics with the Nuprl Proof Development System. Prentice-Hall, Englewood Cliffs (1986) 4. Davies, R.: Practical Refinement-Type Checking. PhD thesis, Carnegie Mellon University (May 2005); Available as Technical Report CMU-CS-05-110 5. Dunfield, J.: A Unified System of Type Refinements. PhD thesis, Carnegie Mellon University (August 2007); Available as Technical Report CMU-CS-07-129 6. Dunfield, J., Pfenning, F.: Tridirectional typechecking. In: Leroy, X. (ed.) ACM Symp. Principles of Programming Languages (POPL 2004), Venice, Italy, pp. 281– 292 (January 2004) 7. Freeman, T.: Refinement Types for ML. PhD thesis, Carnegie Mellon University (March 1994); Available as Technical Report CMU-CS-94-110 8. Harper, R., Honsell, F., Plotkin, G.: A framework for defining logics. Journal of the Association for Computing Machinery 40(1), 143–184 (1993) 9. Liquori, L., Ronchi Della Rocca, S.: Intersection-types ` a la Church. Information and Computation 205(9), 1371–1386 (2007) 10. Lovas, W., Pfenning, F.: A bidirectional refinement type system for LF. Electronic Notes in Theoretical Computer Science 196, 113–128 (2008) 11. Pfenning, F.: Intensionality, extensionality, and proof irrelevance in modal type theory. In: Halpern, J. (ed.) Proceedings of the 16th Annual Symposium on Logic in Computer Science (LICS 2001), Boston, Massachusetts, pp. 221–230. IEEE Computer Society Press, Los Alamitos (2001) 12. Reed, J., Pfenning, F.: Proof irrelevance in a logical framework. Unpublished draft (July 2008) 13. Reynolds, J.C.: The coherence of languages with intersection types. In: Ito, T., Meyer, A.R. (eds.) TACS 1991. LNCS, vol. 526, pp. 675–700. Springer, Heidelberg (1991) 14. Salvesen, A., Smith, J.M.: The strength of the subset type in Martin-L¨ of’s type theory. In: Proceedings of LICS 1988, pp. 384–391. IEEE Computer Society Press, Los Alamitos (1988) 15. Sch¨ urmann, C.: Towards practical functional programming with logical frameworks (July 2003), http://cs-www.cs.yale.edu/homes/carsten/delphin/ (unpublished) 16. Watkins, K., Cervesato, I., Pfenning, F., Walker, D.: A concurrent logical framework I: Judgments and properties. Technical Report CMU-CS-02-101, Department of Computer Science, Carnegie Mellon University (2002) (revised, May 2003) 17. Zeilberger, N.: Refinement types and computational duality. In: PLPV 2009: Proceedings of the 3rd workshop on Programming Languages Meets Program Verification, pp. 15–26. ACM, New York (2009)
Weak ω-Categories from Intensional Type Theory Peter LeFanu Lumsdaine Carnegie Mellon University [email protected]
Abstract. Higher-dimensional categories have recently emerged as a natural context for modelling intensional type theories; this raises the question of what higher-categorical structures the syntax of type theory naturally forms. We show that for any type in Martin-L¨ of Intensional Type Theory, the system of terms of that type and its higher identity types forms a weak ω-category in the sense of Leinster. Precisely, we construct a contractible globular operad PMLId of type-theoretically definable composition laws, and give an action of this operad on any type and its identity types.
1
Overview
Starting with the Hofmann-Streicher groupoid model [1], higher categories have emerged as a natural approach to the semantics of intensional Martin-L¨ of type theory. In the globular approach to higher categories, a higher category has objects (“0-cells”), arrows (“1-cells”) between objects, 2-cells between 1-cells, and so on, with various composition operations and laws depending on the kind of category in question (strict or weak, n- or ω-, . . .). The paradigm for semantics of type theory is then (very roughly!) that types (or contexts) are thought of as / [[B]], terms of identity objects [[A]], terms x : A τ : B as arrows [[τ ]] : [[A]] +3 [[τ ]], terms χ : Id(ρ, ρ ) as 3-cells, and type ρ : IdB (τ, τ ) as 2-cells [[ρ]] : [[τ ]] so on. This idea has recently been explored by various authors in various directions: see for instance [2], [3], [4]. One such direction is investigating the structures formed by the syntax of type theory. In particular, it has been suggested that (terms of) any type (considered together with its higher identity types) should carry the structure of a weak ω-category or -groupoid. We will show that this is indeed the case, using the definition of weak ω-category given by Tom Leinster in [5] following the approach of Michael Batanin [6]. (Note that for this construction, based on a specific type A, the dimensions of cells are always one lower than described above: 0-cells will be terms τ : A, 1-cells will be terms ρ : IdA (τ, τ ), and so on. This comes from the general rule that if X, A are objects of an n-category C, then C(X, A) forms an (n − 1)-category whose 0-cells are 1-cells of C, and so on.) An extended version of this paper, including more background material and proofs, is available online [7]. While writing this paper, I found that Benno van P.-L. Curien (Ed.): TLCA 2009, LNCS 5608, pp. 172–187, 2009. c Springer-Verlag Berlin Heidelberg 2009
Weak ω-Categories from Intensional Type Theory
173
den Berg had independently discovered a similar proof (proposed in 2006 and since completed in unpublished work [8]); a development of this is forthcoming in joint work of van den Berg and Richard Garner [9]. 1.1
Outline of the Construction
(We assume throughout some general familiarity with higher category theory, but not with the particular definition of weak ω-category used, which we will recall in detail in later sections, and similarly for the type theory.) Recall that an ω-category C has a set Cn of “n-cells” for each n > 0. The 0and 1-cells correspond to the objects and arrows of an ordinary category: each arrow f has source and target objects a = s(f ), b = t(f ). Similarly, the source // b, and generally and target of a 2-cell α are a parallel pair of 1-cells f, g : a the source and target of an (n + 1)-cell are a parallel pair of n-cells. Cells of each dimension can be composed along a common boundary in any lower dimension, and in a strict ω-category, the composition satisfies various associativity, unit, and interchange laws, captured by the generalised associativity law: each labelled pasting diagram has a unique composite. (See illustrations in Fig. 1). f f
a •
f
a
•
"
a
b
/•
•
b
α <•
•
Θ
α
_*4
!
g
B•
β
}
g f a
•
b
/•
f
c
•
f
f
f
g ·0 f •
α
a
/•
g
γ
b / D•
f
a
•
α
g
/•
h ·0 (g ·0 f ) = (h ·0 g) ·0 f
h
/•
g
@•
f
γ ·1 α
/•
b
β
c
@•
g
β ·0 α
α
γ
•
/ E•
β / • E δ
(δ ·0 γ) ·1 (β ·0 α) = (γ ·1 α) ·0 (δ ·1 β)
Fig. 1. Some cells, composites, and associativities in a strict ω-category
In a weak ω-category, we do not expect strict associativity, so may have multiple composites for a given pasting diagram, but we do demand that these composites agree up to cells of the next dimension (“up to homotopy”), and that these associativity cells satisfy certain coherence laws of their own, again up to cells of higher dimension, and so on. This is exactly the situation we find in intensional type theory. For instance, even in constructing a term witnessing the transitivity of identity—that is, a
174
P. LeF. Lumsdaine
composition law for the pasting diagram ( • term c such that
/•
/ • ), or explicitly a
x, y, z : X, p : Id(x, y), q : Id(y, z) c(q, p) : Id(x, z) —one finds that there is no single canonical candidate: most obvious are the two equally natural terms cl , cr obtained by applying (Id-elim) to p or to q respectively. These are not definitionally equal, but are propositionally equal, i.e. equal up to a 2-cell: there is a term e with x, y, z : X, p : Id(x, y), q : Id(y, z) e(q, p) : Id(cl (q, p), cr (q, p)). In Leinster’s definition [5], a system of composition laws of this sort is wrapped up in the algebraic structure of a globular operad with contraction, and a weak ω-category is given by a globular set equipped with an action of such an operad. We generalise this slightly, to define an internal weak ω-category in any suitable category C. Accordingly, we would like to find an operad-with-contraction PMLId of all such syntactically-definable composition laws, acting on terms of any type and its identity types. In fact, rather than using the full type theory for this, it is enough to consider the composition laws definable using just the Id- rules, so obtaining the construction for a wider class of theories. The heart of the paper is Sect. 4, where we formalise this idea by considering a type theory MLId [X], the fragment of MLI generated just by the structural and Id-rules plus a single generic base type X; then PMLId is the endomorphism operad of the globular object X• in its syntactic category C(MLId [X]), and by some analysis of the fragment MLId [X] we show that PMLId is contractible. Since X is generic, PMLId acts on all other types, giving our main theorem: Theorem. Let T be any type theory extending MLId , and A any type of T . Then the system of types (A, IdA , IdIdA , . . .) is equipped naturally with a PMLId -action, and hence with the structure of an internal weak ω-category in C(T ). To prepare for this, we first lay out in Sect. 2 our presentation of the full type theory MLI and of the fragment MLId , and in Sect. 3 the relevant background on globular operads and their algebras.
2 2.1
The Type-Theoretic Setting The Type Theories MLId , MLId [X]
Our main theories of interest are the various versions of Intensional MartinL¨of Type Theory, usually given with identity types (Id-types), dependent sums and products ( - and -types), units (1-types), and possibly more base types (natural numbers, Booleans. . .). To cover all these in the main theorem, and for a self-contained presentation, we will work throughout this paper in the fragment MLId with only Id-types, and construct our operad from this.
Weak ω-Categories from Intensional Type Theory
175
Table 1. The type theory MLId Basic judgement forms Γ A type Γ A = B type Γ a:A Γ a=b:A Structural groups Variables (Vble) Substitution (Subst) Weakening (Wkg) Exchange (Exch) Equality (=)
Id-rules Id-form Id-intro Id-elim Id-comp (“β” in [10]) compatibility with substitution and =
Some care is thus required in our choice of presentation; presentations which are equivalent in the presence of - or -types may not be so in their absence. The presentation we use is taken, up to notation, from that of Jacobs [10]; we list in Table 1 the rules assumed, referring to [10] for their statements, except for the Id-rules, given in full in Table 2. The only features perhaps needing comment are the explicit inclusion of exchange rules, and of the extra dependent context Δ in the Id-rules; these are each natural rules, but often omitted since they are derivable in the presence of Π-types (as discussed on e.g. p.587 of [10]). Note that from Exch and this Id-elim rule, we can derive a still slightly more general elimination rule Id-elim+ , as Id-elim but with context Γ, x : A, Δ, y : A, Δ , p : IdA (x, y), Δ . To simplify notation when referring to iterated identity types, we introduce the notation (following Warren [11]) An for the nth iterated identity type of a type A; that is, if Γ A type, then Γ A0 := A type, and inductively Γ, x0 , y0 : A0 , x1 , y1 : A1 (x0 , y0 ), . . . , xn , yn : An (x0 , y0 ; . . . ; xn−1 , yn−1 ) An+1 (x0 , y0 ; . . . ; xn , yn ) := IdAn (x0 ,...) (xn , yn ) type. We will often omit the superscripts on these when unambiguous. As usual, we will also be inconsistent in suppression of dependent variables, writing sometimes e.g. Γ A type and sometimes y : Γ A( y ) type. Finally, for a finite partial order I = {i1 < . . . < in }, we will write i∈I xi : Ai (or just i∈I Ai ) to denote the context xi1 : Ai1 , . . . , xin : Ain . 2.2
Translations and Syntactic Categories
For reference on this section (including proofs not given here), see Cartmell [12] and Jacobs [10].
176
P. LeF. Lumsdaine Table 2. Rules for Id-types Γ A type
Id-form
Γ, x, y : A IdA (x, y) type Γ A type Γ, x : A r(x) : IdA (x, x)
Id-intro
Γ, x, y : A, p : IdA (x, y), Δ(x, y, p) C(x, y, p) type Γ, z : A, Δ(z, z, r(z)) d(z) : C(z, z, r(z)) Γ, x, y : A, p : IdA (x, y), Δ(x, y, p) Jz.d (x, y, p) : C(x, y, p) (premises as for Id-elim) Γ, x : A, Δ(x, x, r(x)) Jz.d (x, x, r(x)) = d(x) : C(x, x, r(x))
Id-elim
Id-comp
From here on, we will consider type theories extending MLId ; precisely, by a type theory we will mean a generalised algebraic theory together with an interpretation of MLId in T , in the sense of Cartmell [12]. Recall that a translation F from such a type theory T into a type theory S consists of suitable mappings of types, terms, and derivable judgements, taking each judgement Γ A type in T to a judgement F (Γ ) F (A) type in S, and so on, preserving Id-types and their term-constructors (or in other words, a morphism of generalised algebraic theories under MLId ). Given T , we write T [X] for the result of adjoining to T a fresh base type X X type
X-form
/ S then with no term formation rules. For any S, a translation F : T [X] / consists of a translation F : T S together with a closed type of S. Stating this precisely in the particular case that we will need: Proposition 1. If S is any type theory extending MLId , and A any closed type / S preserving Id-types of S, then there is a unique translation A : MLId [X] and their term-constructors and with A (X) = A. For any type theory T , there is a syntactic category C(T ), having as objects the / Δ suitable strings of terms closed contexts Γ of T , and as arrows f : Γ in context Γ (context maps), all up to α-equivalence and definitional equality. / C(S); / S induces a functor C(F ) : C(T ) Moreover, a translation F : T / in other words, we have a functor C(−) : Th Cat. We will need a simple proposition on limits in syntactic categories: , and F ⊆ P(I) a Proposition 2. Suppose Γ = i∈I xi : Ai is a context in T set of subsets of I, closed under binary intersection and with F = I, such that for each J ∈ F, ΓJ = i∈J xi : Ai is also a well-formed context.
Weak ω-Categories from Intensional Type Theory
177
Then the ΓJ ’s and dependent projections between them give a diagram Γ− : / C(T ), and the dependent projections Γ / ΓJ express Γ as its (F , ⊆)op limit: Γ = limJ∈F ΓJ . ←− / T , the functor C(F ) preserves all Moreover, for any translation F : T such limits. Here dependent projections are the obvious context morphisms from a context to any well-formed subcontext, constructed from the Vble, Wkg and Exch rules. A familiar special case asserts that if Γ A type and Γ B type, then the following square is a pullback: Γ.A.B
πA .B
/ Γ.B
πA
/Γ
πB
Γ.A
πB
The proof of the general proposition is essentially the same. To relativise the constructions of this section to dependent types and contexts over a (closed) context Γ = 0≤i
3
Globular Operads and Their Algebras
As described in the introduction, we want to describe “the globular operad of composition laws”. Accordingly, we recall briefly in this section what a globular operad is, and how it formalises the intuition of a set of composition laws for pasting diagrams with structure specifying how these laws themselves compose. For a slightly (resp. much) fuller treatment, and background on strict higher categories, see Leinster [13] (resp. [5]). 3.1
Globular Operads and Weak ω-Categories
A globular set is a presheaf on the category G generated by arrows 0
s0 t0
/
/1
s1 t1
/
/2
/ / ...
subject to the equations ss = ts, st = tt (omitting subscripts on the arrows, as := [Gop , Sets] of globular sets and natural usual). We thus have the category G transformations between them. More generally, a globular object in a category / C. C is a functor A• : Gop
178
P. LeF. Lumsdaine
Explicitly, a globular set A• has a set An of “n-cells” for each n ∈ N, and each (n + 1)-cell x has parallel source and target n-cells s(x), t(x), as illustrated in the first line of Fig. 1. (Cells x, y of dimension > 0 are parallel if s(x) = s(y) and t(x) = t(y); all 0-cells are considered parallel.) For parallel x, y ∈ An , we write A(x, y) := {z ∈ An+1 | s(z) = x, t(z) = y}, the set of n + 1-cells from x to y. Example 1. For any topological space X, there is a globular set Πω (X) in which 0-cells are points of X, 1-cells are paths between points, 2-cells are homotopies between paths keeping endpoints fixed, and in general, n-cells are suitable maps / X, viewed as homotopies between (n − 1)-cells. H : [0, 1]n Example 2. For any type A in a type theory T , the contexts x0 , y0 : A, x1 , y1 : A1 (x0 , y0 ) . . . , z : An (x0 , y0 . . . , xn−1 , yn−1 ), along with their dependent projections, form a globular object A• in C(T ). Any strict ω-category (as sketched in the Introduction) has an evident underlying globular set, and in fact there is an adjunction (moreover monadic) / str-ω-Cat : U , giving rise to the “free strict ω-category” monad T o F :G Cells of T A• are free (strictly associative) pastings-together of cells from on G. A• , including degenerate pastings from the identity cells of F (A• ) (as shown in figure 2). h a
•
a
a ∈ T X0 a
•
h
1a ∈ T X1
• b
/•
• g
g ·0 h ∈ T X1
c
/•
β
a
h β
g
b / E•
α
"
c
<•
f
d
/•
g
h
1f ·0 α ·0 (β ·1 β ) ∈ T X2
(for a, b, . . . ∈ A0 , f, g, . . . ∈ A1 , α, β, . . . ∈ A2 ) Fig. 2. Some labelled pasting diagrams, elements of a free strict ω-category T A•
In particular, T 1 (where 1 denotes the terminal globular set, with just one cell of each dimension) consists informally of pastings of this sort, but without labels on the cells. This is the crucial globular set of pasting diagrams. Every ˆ —intuitively, the set pasting diagram π ∈ T 1n has an associated globular set π of cells appearing in π, as shown in our pictures of pasting throughout. diagrams Taking categories of elements then gives a category π := G π ˆ , with objects k k the cells of π ˆ and arrows into each cell c from its sources and targets s (c), t (c), / G giving the dimension of each cell; π may and with a functor dim : π be seen as the shape of the canonical diagram of basic cells whose colimit in G gives π ˆ.
Weak ω-Categories from Intensional Type Theory
179
For more discussion of these various ways of looking at a pasting diagram, see Street [14], or the extended version of this paper [7]. / T 1 (“arity”), A globular operad is a globular set P with maps a : P / / P (“units”), m : T P ×T 1 P P (“composition”), such that e:1 /P 1/ // // a η // // T1 e
/P
a
. T1
T P ×T?1 P ??? T P? P ??T ! a ? Ta T1 T 21
μ
m
commute (i.e. e and m are maps over T 1), satisfying the axioms m · (η · e × 1P ) = 1P = m · (η × e) : P
/ P,
m · (μ × m) = m · (T m × 1P ) : T 2 P ×T 2 1 T P ×T 1 P
/ P.
Considering the fibers of a, we may view P as a family of sets P (π) of “π-ary operations” for each π ∈ T 1: an element p of P (π) is seen as a formal operation symbol, taking π-shaped labelled pasting diagrams as input and returning ncells as output. The map e then gives us an n-cell “identity” operation for each n, while m allows us to compose operations appropriately. / Q of globular operads is a map of underlying globular sets A map f : P commuting with a, e and m. An action of a globular operad P on a globular set X is a composition map / X, satisfying c : T X ×T 1 P c · (η × e) = 1X : X
/ X,
c · (μ × m) = c · (T c × 1P ) : T 2 X ×T 2 1 T P ×T 1 P
/ X.
Informally, this implements the “operations” of P as actual operations on X. An element of T X ×T 1 P over some π ∈ T 1n is a π-shaped diagram x with labels from X together with a π-ary operation p of P ; c tells us how to apply p to x, yielding a single n-cell of X. A P -algebra is a globular set X together with an action of P on X. A map / Y of P -algebras is a map of globular sets commuting with the P f : X actions. We denote the resulting category by P -Alg. Example 3. The globular set T 1 is itself trivially an operad (indeed, the terminal one), with a = 1T 1 , i.e. T 1(π) = 1 for every π; a T 1-algebra is then exactly a strict ω-category. This fits with our description above of a strict ω-category having a unique composition for each pasting diagram. Weak ω-categories will also be described as algebras for a cetain globular operad; to find a suitable operad, we need to specify a little extra structure.
180
P. LeF. Lumsdaine
/ Y of globular sets is a choice of liftings A contraction on a map d : X for fillers of parallel pairs: that is, for each parallel pair x, x ∈ X (with the / X(x, x ), convention that all 0-cells are parallel), a map χx,x : Y (dx, dx ) such that d · χ = 1Y . A globular operad with contraction is a globular operad / T 1; this ensures both that enough P with a contraction on the map a : P composition operations exist in P , and that the operations will be associative up to cells of the next dimension, themselves satisfying appropriate coherence laws up to yet higher cells, and so on. It is shown in [5] that the category of globular operads with contraction has an initial object L; this gives the key definition: Definition 1. A weak ω-category is an L-algebra, where L is the initial operadwith-contraction. / O-Alg; so if we / P of operads induces a functor P -Alg A map O have an algebra X for any operad P with contraction, the unique operad-with/ P endows X with the structure of a weak ω-category. contraction map L Example 4. The terminal operad T 1 has a trivial contraction, giving a canonical / wk-ω-Cat. functor str-ω-Cat Example 5. For any space X, the set Πω (X) of Example 1 may be naturally made into a weak ω-category, the fundamental weak ω-groupoid of X. [5, 9.2.7] 3.2
Endomorphism Operads and More General Actions
/ C is a globular object in a category C, Proposition 3. Suppose X• : Gop and for each pasting diagram π we are given a chosen limit Xπ = limc∈ π Xdim c , ←− an object of “diagrams of shape π in X• ”. Then there is an operad EndC (X• ), or just End(X• ), the endomorphism globular operad of X• , in which (for π ∈ T 1n) an element of End(X• )(π) is a sequence of maps ((σi , τi )0 ≤ i < n; ρ), ρ : Xπ
/ Xn ,
σi : Xsn−i π
/ Xi ,
τi : Xtn−1 π
/ Xi ,
commuting appropriately with the source and target maps—in other words, a way of composing each diagram of shape π in X• to an n-cell of X, extending given ways of composing the source and target in each lower dimension. (More abstractly, such ((σi , τi )0 ≤ i < n; ρ) may be described as a natural / C.) transformation between a certain pair of diagrams (G/n)op / D is a functor preserving the limits involved, we can Moreover, if F : C / End(F X). also construct End(F X), and there is a natural map End(X)
Weak ω-Categories from Intensional Type Theory
181
An illustration may be useful here: the definition of Xπ says, for instance, that when π = ( •
$
:•
⎛
⎜ ⎜ ⎜ Xπ := lim ⎜ ←− ⎜ ⎜ ⎝
$
: • ), XO 1 D XO 1 D DDt Dt s zz s zz s s DDD DD z z }zz ! }zz ! X2 X0 aD X X 0 2 = aDD s = X0 DDs t zz t zz DD t DD t z z D zz zz X1 X1
⎞ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎠
∼ = X2 ×X0 X2 , giving the object of 0-composable pairs of 2-cells in X. In the case C = Sets, the sets Xπ are precisely the fibers of the map T ! : / T 1, so this description of End(X• ) can be shown to agree with the TX definition for globular sets given in [5, 6.4]. We will not give a concrete description of the operad composition maps, noting only that they are “exactly what one would expect”. Proof. See the extended version of this paper [7].
We can now extend the definitions of the previous subsection. An action of an / End(X• ). (If C = Sets then this operad P on X• is a map of operads P agrees with our earlier notions of an action on a globular set, by [5, 6.4]). A P -algebra in a category C is a globular object in C together with an P -action; an internal weak ω-category in C is an L-algebra in C. Moreover, an action of P on X• induces an action of P on the globular set / Sets preserves all limits, and C(Y, X• ) for any Y ∈ C, since C(Y, −) : C / / hence we have maps P End(X• ) End(C(Y, X• )). (This construction of the endomorphism globular operad generalises the case given in [5, 9.2.7].)
4
The Contractible Globular Operad PMLId
In this section, we construct the promised operad PMLId , which will act on any type; we then show that it is contractible, and describe (in the main theorem) how it acts to give the desired weak ω-category structures on types. 4.1
Construction of PMLId
We saw above that for a type A in a type theory T extending MLId , the contexts x0 , y0 : A, x1 , y1 : A1 (x0 , y0 ) . . . , z : An (x0 , y0 . . . , xn−1 , yn−1 ), together with the dependent projections between them, form a “globular con/ C(T ). Using the machinery of the previous section, it is now text” A• : Gop
182
P. LeF. Lumsdaine
easy to describe PMLId : it is EndC(MLId [X]) (X• ). However, since C(T ) does not have chosen limits in general, to show the existence of the operad EndC(T ) (A• ) we must construct contexts Γπ providing the limits required by Proposition 3. ˆ. Accordingly, suppose we are given π ∈ T 1n , with associated globular set π There are various ways of putting a total order on the i-cells of π ˆ for each i ≤ n; pick one such. (There is in fact a canonical choice of such orderings; see [7] for details. This choice has some extra cosmetic properties which will later spare us some use of Exch rules, so for simplicity we will assume it is the ordering chosen.) Then take Γπ to be the context xc : A, xc : A1 (xs(c) , xt(c) ), . . . xc : An (xsn (c) , xtn (c) ; . . . ; xs(c) , xt(c) ). c∈ˆ π0
c∈ˆ π1
c∈ˆ πn
For instance, Γ(•
/•
/ •) is the context
x, y, z : A, p : IdA (x, y), q : IdA (y, z) which we met back in Subsection 1.1. Note that we also have projections src : Γπ
/ Γs(π) , and tgt similarly.
Lemma 1. These contexts exhibit the limits required by Proposition 3; that is, Γπ = limc∈ π Xdim c , with the obvious projection morphisms. Moreover, if F : ←− / S is a translation of type theories, then C(F ) : C(T ) / C(S) preserves T these limits. Proof. By Proposition 2, on limits in syntactic categories.
Thus by Proposition 3, the definition of endomorphism operads, we see: Theorem 1. The globular object A• in C(T ) has an endomorphism operad / S is a translation of type theories, there is EndC(T ) (A• ); and if F : T / EndC(S) (F A• ). an induced map of operads EndC(T ) (A• ) Let us unfold what this operad P := EndC(T ) (A• ) actually looks like. For π ∈ / An in C(T ), and for T 1n , an element of P (π) consists of a map ρ : Γπ / Ak and τk : Γtn−k (π) / Ak , commuting 0 ≤ k < n, maps σk : Γsn−k (π) with the dependent projections. So, concretely, an element of P (A• )(π) (a composition law for π) is a sequence of terms ρ
= ((σi , τi )0≤i
x : Γsn (π) σ0 ( x) : A,
x : Γtn (π) τ0 ( x) : A, .. .
x : Γs(π) σn−1 ( x) : Id(σn−2 (src( x)), τn−2 (tgt( x))),
x : Γt(π) τn−1 ( x) : Id(σn−2 (src( x)), τn−2 (tgt( x))),
x : Γπ ρ( x) : Id(σn−1 (src( x)), τn−1 (tgt( x))).
Weak ω-Categories from Intensional Type Theory
183
The source of this is then the composition law (σ0 , τ0 , . . . , σn−2 , τn−2 ; σn−1 ) ∈ P (s(π)), and the target is (σ0 , τ0 , . . . , σn−2 , τn−2 ; τn−1 ) ∈ P (t(π)). /• / •). Then Γπ is the For a typical example, consider the case π = (• context x, y, z : A, p : IdA (x, y), q : IdA (y, z), and we may give a composition law by taking σ0 (x) = x, τ0 (z) = z, and taking ρ to be some term with x, y, z : A, p : Id(x, y), q : Id(y, z) ρ : Id(x, z) as described in Subsection 1.1. Definition 2. As a special case of the above construction, we take PMLId := EndC(MLId [X]) (X• ), the operad of all definable composition laws on a generic type. 4.2
Contractibility of PMLId
For general T , A, we cannot expect EndC(T ) (A• ) to be contractible: contractibility implies (at least) that any two elements of EndC(T ) (A• )(•), i.e. any two terms / •), i.e. are x : A τ, τ : A, are connected by an element of EndC(T ) (A• )(• propositionally equal, which clearly may fail. However, in the specific case of PMLId , we do wish to show contractibility, since this is the operad which naturally acts on any type. What precisely does contractibility mean, here? For every pasting diagram π and every parallel pair of composition laws σ ∈ PMLId (s(π)), τ ∈ PMLId (t(π)), ρ) = σ , t(
ρ) = τ . we need to find some filler ρ
∈ PMLId (π), with s(
Given π ∈ T 1n , such a parallel pair amounts to terms (σi , τi )0≤i
x : Γπ ρ( x) : Id(σn−1 (src( x)), τn−1 (tgt(x))). Playing with small examples (the reader is encouraged to try!) suggests one should be able to do this by applying Id-elim (possibly repeatedly, working bottom-up as usual) to the variables of identity types in Γπ . Id-elim says that to obtain ρ, it’s enough to obtain it in the case where one of the k-cell variables (with k the highest dimension appearing) is of the form r(−), and its source and target (k − 1)-cell variables are equal; and by repeated application, it’s enough to obtain ρ in the case where multiple higher cells have had identities plugged in in this way. Now, since the terms σi , τi have themselves been built up from just the Idrules, as we plug r(−) terms into them and identify the lower variables, they should sooner or later collapse by Id-comp to be of the form ri (x) themselves. In particular, once we have applied Id-elim as far as possible, identifying all the variables of type X to a single x : X and plugging in ri (x) for all the higher variables, the σi , τi should all compute down to ri (x), giving in particular σn−1 = τn−1 = rn−1 (x), so we can take the desired filler to be x : X rn (x) : Id(rn−1 (x), rn−1 (x)).
184
P. LeF. Lumsdaine
Below, we formalise this argument. The crucial lemma is that the context x : X is an initial object in C(MLId [X]); this expresses the fact that since any context Γ in MLId [X] is built up from X and its higher identity types, there is always a unique way to plug in terms ri (x) (i ≥ 0) to all its variables, and / Γ is a context morphism and we plug in ri (x)’s to all ensures that if σ : Γ the variables of σ, the result must reduce to consist of just ri (x)’s. Lemma 2. The context x : X is an initial object in C(MLId [X]); that is, for / Γ. any closed context Γ there is a unique context morphism rΓ : (x : X) Id Remark 1. This lemma does not generally hold in extensions of ML [X]; if we add -types, for instance, it is easily seen to be false.
Proof. We work by structural induction (as, essentially, we must, since this is a property of the theory MLId [X] which can fail in extensions of it). So, given any derivation δ of a judgement J in MLId [X], we derive another judgement J , with form depending on that of J as follows: J y : Γ A( y ) type
J x : X rΓ A : A(rΓ )
y : Γ A( y ) = A ( y ) type x : X rΓ A = rΓ A : A(rΓ )
y : Γ τ ( y ) : A( y ) x : X τ (rΓ ) = rΓ A : A(rΓ )
y : Γ τ ( y ) = τ ( y ) : A( y ) (nothing needed) The context morphisms rΓ : (x : X)
/ Γ are built of the terms rΓ A , by
rΓ,y:A = rΓ , rΓ A . The judgements above ensure that this is well-typed, and is the unique context morphism from (x : X) to Γ . The induction is essentially routine. As usual, we work by cases, depending on the last rule of δ, and our cases for Subst- and Wkg-rules ensure that the terms rΓ A constructed depend only on the judgment y : Γ A( y ) type and not on the specific derivation δ thereof. Some sample cases of the induction are given in the extended version [7] We are now ready to show that PMLId is contractible, arguing along the lines sketched above. Theorem 2. The operad PMLId is contractible. Proof. As described above, this amounts to the statement: for every n ∈ N and pasting diagram π ∈ T 1n , and every sequence (σi , τi )i
x : Γsn−i (π) σi ( x) : X (σ0 (srci ( x)), . . . , τi−1 (tgt( x)))
x : Γtn−i (π) τi ( x) : X (σ0 (srci ( x)), . . . , τi−1 (tgt( x)))
Weak ω-Categories from Intensional Type Theory
185
(i < n) are derivable in MLId [X], we can find a “filler”, i.e. a term ρ with
x : Γπ ρ( x) : X (σ0 (srcn ( x)), . . . , τn−1 (tgt( x))) We show this by induction on the number of cells in π. Suppose π has more than one cell. Then it must have some cells in dimension > 0. Let k be the highest dimension in which π has cells, and c be the last cell ˆk ). Let π − ∈ T 1n be the pasting diagram in π ˆk (using our chosen ordering on π whose globular set is obtained from that of π by removing c and identifying s(c) and t(c). Now Γπ− is equal, up to renaming of variables, to the context obtained from Γπ by removing the variables xkc and xk−1 t(c) , and replacing any occurences of the latter in subsequent types by xk−1 s(c) (at least, the contexts are equal if we used the canonical choices of orderings; otherwise, we have canonical context isomorphisms given by re-ordering variables), and we have a natural context / Γπ given by plugging in xk−1 for xk−1 and r(xk−1 ) for morphism h : Γπ− s(c) t(c) s(c) xkc ; and these are exactly right for
x : Γπ− ρ− ( x) : X (σ0 (srcn (h( x))), . . . , τn−1 (tgt(h( x)))) k−1 k n
x : Γπ Jxk−1 .ρ− (xk−1 x)), . . . , τn−1 (tgt( x))) s(c) , xt(c) , xc ) : X (σ0 (src (
s(c)
to be an instance of Id-elim+ . So to give the desired filler ρ, it is enough to give ρ− with
x : Γπ− ρ− ( x) : X (σ0 (srcn (h( x))), . . . , τn−1 (tgt(h( x)))). But now note that sn−i (π − ) =
sn−i (π) for i < k (sn−i (π))− for i ≥ k
and similarly for tn−i (π − ); moreover, we can construct context morphisms hsi : Γsn−i (π− )
/ Γsn−i (π)
(analogous to h if i ≥ k, and just the identity otherwise), and these commute with the maps src and tgt. So for each i < n, we have
x : Γsn−i (π− ) σi (h( x)) : X (σ0 (h(srci ( x))), . . . , τi−1 (h(tgt( x)))),
x : Γtn−i (π− ) τi (h( x)) : X (σ0 (h(srci ( x))), . . . , τi−1 (h(tgt( x)))), i.e. the sequence of terms (h∗ (σi ), h∗ (τi ))i
186
P. LeF. Lumsdaine
Unwinding this induction, we can see that it exactly formalises the process described at the start of Subsection 4.2. Note that Lemma 2 was applied only at the base case of the induction, and only to show that terms x : X σ : Id(rn (x), rn (x)) must be equal to rn+1 (x). A sufficiently general normalisation result could also be used to show this, resting on showing that these are the only appropriate normal forms; this would have the advantage of extending to the operad EndMLI [X] (X• ) of all composition laws of the full type theory. However, the present approach seems more economical, and more directly justifies the original intuition. 4.3
Types as Weak ω-Categories
Putting the above results together, we obtain our main goal: Theorem 3. Let T be any type theory extending the fragment MLId , Γ any closed context of T , A a type over Γ . Then the globular context A• carries the structure of a weak ω-category in C(T /Γ ). Proof. By Proposition 1, there is a unique translation A : MLId [X]
/ T /Γ
taking X to A, and hence taking X• to A• . By Proposition 3, this induces an action of PMLId on A• , and so, since by Theorem 2 PMLId admits a contraction, an action of L (the initial operad-with-contraction) on A• , as desired. Corollary 1. Let T , Γ , A be as above, Δ a context over Γ in T . Then the globular set C(T /Γ )(Δ, A• ) of context maps f : Γ, Δ
/ Γ, x0 , y0 : A, . . . , xn−1 , yn−1 : A(x0 , . . . , yn−2 ), z : A(x0 , . . . , yn−1 )
over Γ has the structure of a weak ω-category, naturally in Δ.
References 1. Hofmann, M., Streicher, T.: The groupoid interpretation of type theory. In: Twenty-Five Years of Constructive Type Theory (Venice, 1995). Oxford Logic Guides, vol. 36, pp. 83–111. Oxford Univ. Press, New York (1998) 2. Gambino, N., Garner, R.: The identity type weak factorisation system. Theoretical Computer Science (to appear) (2008) arXiv:0808.2122 3. Garner, R.: 2-dimensional models of type theory. Mathematical Structures in Computer Science (to appear) (2008) arXiv:0808.2122 4. Awodey, S., Warren, M.A.: Homotopy theoretic models of identity types. Math. Proc. of the Cam. Phil. Soc. (to appear) (2008) arXiv:0709.0248 5. Leinster, T.: Higher Operads, Higher Categories. London Mathematical Society Lecture Note Series, vol. 298. Cambridge University Press, Cambridge (2004) arXiv:math/0305049 6. Batanin, M.A.: Monoidal globular categories as a natural environment for the theory of weak n-categories. Adv. Math. 136(1), 39–103 (1998)
Weak ω-Categories from Intensional Type Theory
187
7. Lumsdaine, P. Lef.: Weak ω-categories from intensional type theory (extended version) (2008) arXiv:0812.0409 8. van den Berg, B.: Types as weak ω-categories. Lecture delivered in Uppsala, and unpublished notes (2006) 9. Garner, R., van den Berg, B.: Types are weak ω-groupoids (submitted) (2008) arXiv:0812.0298 10. Jacobs, B.: Categorical Logic and Type Theory. Studies in Logic and the Foundations of Mathematics, vol. 141. North-Holland Publishing Co., Amsterdam (1999) 11. Warren, M.A.: Homotopy Theoretic Aspects of Constructive Type Theory. PhD thesis, Carnegie Mellon University (2008) 12. Cartmell, J.: Generalised algebraic theories and contextual categories. Ann. Pure Appl. Logic 32(3), 209–243 (1986) 13. Leinster, T.: A survey of definitions of n-category. Theory Appl. Categ. 10, 1–70 (2002) (electronic) arXiv:math/0107188 14. Street, R.: The petit topos of globular sets. Journal of Pure and Applied Algebra 154, 299–315 (2000)
Relating Classical Realizability and Negative Translation for Existential Witness Extraction Alexandre Miquel Universit´e Paris 7 & LIP (ENS Lyon) [email protected] Abstract. Friedman showed how to turn a classical proof of a Σ10 formula into an intuitionistic proof of the same formula, thus giving an effective method to extract witnesses from classical proofs of such formulae. In this paper we show how to achieve the same goal efficiently using Krivine realizability with primitive numerals, and prove that the corresponding program is but the direct-style equivalent (using call-cc) of the CPS-style program underlying Friedman’s method.
1
Introduction
Classical realizability is a powerful framework introduced by Krivine [4,7] to study the proofs-as-programs paradigm in classical logic. Its main feature is that the computational interpretation of proofs is not described via a negative translation, but instead expressed in direct style using a λ-calculus extended with the control operator call/cc. Although classical realizability is traditionally presented in second-order classical arithmetic, it can be extended to much more expressive logical frameworks such as Zermelo-Fraenkel set theory [5] or the calculus of constructions with universes [8]. And with the help of extra instructions, it can even provide realizers for several forms of the axiom of choice [5]. The purpose of this paper is twofold. First, it aims at presenting the method that naturally comes with classical realizability in order to extract a witness from a classical proof of a Σ10 -formula. Second, it aims to relate this extraction method with the traditional method introduced by Friedman [2] that combines a negative translation with an intuitionistic realizability interpretation, and to show that through this translation, both extraction methods are basically the same (up to the details in the definition of the negative translation). For that, we first present Krivine’s framework for classical realizability as well as the corresponding witness extraction method, introducing a primitive (and we believe, more efficient) representation of natural numbers in the language of realizers—instead of using Church numerals. We then define an intuitionistic realizability model for second-order arithmetic as well as a negative translation in the spirit of [9], but extended to primitive numerals. We finally analyze the witness extraction method of classical realizability through the negative translation, and show that it corresponds to the transformation used by Friedman to prove the conservativity of Peano arithmetic over Heyting arithmetic for Σ10 (and actually Π20 ) formulæ. P.-L. Curien (Ed.): TLCA 2009, LNCS 5608, pp. 188–202, 2009. c Springer-Verlag Berlin Heidelberg 2009
Relating Classical Realizability and Negative Translation
2 2.1
189
Classical Realizability in Second-Order Logic The Language of Second-Order Logic
The language of second-order logic is parameterized by a first-order language of expressions (a.k.a. first-order terms) to represent the individuals. In this paper, we shall only consider arithmetic expressions (notation: e, e , etc.) that are formed from first-order variables (notation: x, y, z, etc.) and the constant symbol 0 (‘zero’) using function symbols for all primitive recursive definitions of functions (notation: f , g, h, etc.), including a unary function symbol s for the successor function, binary function symbols + and × for addition and multiplication, and a unary function symbol ‘pred’ for the predecessor function. Formulæ of the (minimal) language of second-order logic are formed from second-order variables (notation: X, Y , Z, etc.) of all arities using implication and first- and second-order universal quantification: Formulæ
A, B
::=
X(e1 , . . . , ek )
| A⇒B
| ∀x A
| ∀X A .
The set of all free (first- and second-order) variables of a formula A is written FV (A). The notions of first- and second-order substitution in a formula are defined as usual, and written A{x := e} and A{X(x1 , . . . , xk ) := B} respectively. In what follows we shall consider the following (standard) second-order encodings for connectives and first- and second-order existential quantifications as well as for Leibniz equality: ⊥ ≡ ¬A ≡
∀Z Z A⇒⊥
A∧B A∨B ∃x A(x) ∃X A(X)
≡ ≡ ≡ ≡
∀Z ((A ⇒ B ⇒ Z) ⇒ Z) ∀Z ((A ⇒ Z) ⇒ (B ⇒ Z) ⇒ Z) ∀Z (∀x (A(x) ⇒ Z) ⇒ Z) ∀Z (∀X (A(X) ⇒ Z) ⇒ Z)
e = e
≡
∀Z (Z(e) ⇒ Z(e ))
(where Z is a fresh variable). 2.2
A Type System for Second-Order Logic
We now define a type system for classical second-order logic, based on a judgment of the form Γ NK t : A, where Γ is a typing context, t a proof-term and A a formula of the language defined above. Here, proof-terms (notation: t, u, etc.) are simply the pure λ-terms enriched with a special constant written cc (‘call/cc’), to prove Peirce’s law. Typing contexts (notation: Γ , Γ , etc.) are finite functions from proof-variables to formulæ. The inference rules of this system are given in Fig. 1. These rules contain an axiom rule, introduction and elimination rules for implication and first- and second-order universal quantification, plus a typing rule for cc (Peirce’s axiom). The semantics of this system is given by the classical realizability model we are going to define now.
190
A. Miquel
Γ NK x : A
(x:A)∈Γ
Γ NK cc : ((A ⇒ B) ⇒ A) ⇒ A
Γ, x : A NK t : B Γ NK λx . t : A ⇒ B Γ NK t : A Γ NK t : ∀x A Γ NK t : A Γ NK t : ∀X A
Γ NK t : A ⇒ B Γ NK t : A Γ NK tu : B Γ NK t : ∀x A Γ NK t : A{x := e}
x∈FV / (Γ )
Γ NK t : ∀X A Γ NK t : A{X(x1 , . . . , xk ) := B}
X ∈FV / (Γ )
Fig. 1. Typing rules for classical second-order logic
2.3
A Calculus of Realizers
Krivine’s classical realizability model [7] is based on a much larger larger calculus than the calculus of proof-terms described in 2.2. Instead, the language λc distinguishes three distinct syntactic categories: terms, stacks and processes. Terms (notation: t, u, etc.) and stacks (notation: π, π , etc.) are defined by mutual induction as follows: Terms Stacks
t, u ::= π
::=
x | λx . t
| tu
| κ
| kπ
α | t·π
(t closed)
Terms are the pure λ-terms enriched with constants for every instruction (notation: κ, κ , etc.) of a fixed instruction set K that contains (at least) the instruction cc, plus a continuation constant for every stack π. Stacks are finite lists of closed terms terminated by a stack constant 1 (notation: α, β, etc.) Note that unlike terms (that may be open or closed), stacks only contain closed terms and are thus closed objects—so that the continuation constant kπ associated to every stack π is really a constant. Finally, a process (notation: p, q, etc.) is a pair written t π and formed by a closed term t and a stack π: Processes
p, q
::=
t π
(t closed)
The set of closed terms (resp. the set of stacks) is written Λc (resp. Π), and the set of processes is written Λc Π.
1
Since the witness extraction method we present in this paper (in section 4) does not make use of the constant at the bottom of the stack, it is safe to assume here that there is only a single stack constant ‘nil’. However, the presence of several stack constants is sometimes desirable when working with extra instructions that make use of them, such as the ‘clock’ instruction [5,7].
Relating Classical Realizability and Negative Translation
2.4
191
Evaluation
The set of processes is equipped with a binary relation p p of evaluation that satisfies (at least) the following axioms Grab Push Call/cc Resume
λx . t tu cc kπ
u·π π t·π t · π
t{x := u} t t t
π u·π kπ · π π
for all t, u ∈ Λc and π, π ∈ Π. Note that only processes are subject to evaluation: there is no notion of reduction for either terms or stacks in λc . 2.5
The Realizability Interpretation
The construction of the classical realizability model is parameterized by a set of processes ⊥ ⊥ ⊆ Λc Π (the ‘pole’) which we assume to be saturated (or closed under anti-evaluation) in the sense that conditions p p and p ∈ ⊥ ⊥ together imply p ∈ ⊥ ⊥ for all p, p ∈ Λc Π. We call a falsity value any set of stacks S ⊆ Π. By orthogonality, every falsity ⊥ ⊆ Λc defined as: value S ⊆ Π induces a truth value S ⊥ ⊥ S⊥ = {t ∈ Λc : ∀π ∈ S t π ∈ ⊥ ⊥} .
A valuation is a function ρ that maps every first-order variable x to a natural number ρ(x) ∈ N, and every second-order variable X of arity k to a falsity value function ρ(X) : Nk → P(Π). A parametric expression (resp. a parametric formula) is simply an expression e (resp. a formula A) equipped with a valuation ρ, that we write e[ρ] (resp. A[ρ]). Parametric contexts are defined similarly. For every parametric expression e[ρ] we write Val(e[ρ]) ∈ N the value of e[ρ], interpreting variables by their images in ρ while giving to the primitive recursive function symbols in e their standard interpretation. Every parametric formula A[ρ] is interpreted as two sets, namely: a falsity value A[ρ] ⊆ Π and a truth value |A[ρ]| ⊆ Λc . Both sets are defined by induction on A as follows: X(e1 , . . . , ek )[ρ]
=
ρ(X)(Val(e1 [ρ]), . . . , Val(ek [ρ]))
(A ⇒ B)[ρ]
=
(∀x A)[ρ]
=
|A[ρ]| · B[ρ] = {t · π : t ∈ |A[ρ]|, π ∈ B[ρ]} A[ρ; x ← n] n∈N
(∀X A)[ρ]
=
A[ρ; x ← F ]
F :Nk →P(Π)
|A[ρ]| =
⊥ = {t ∈ Λc : ∀π ∈ A[ρ] t π ∈ ⊥ ⊥} A⊥
Since the truth value |A[ρ]| and the falsity value A[ρ] actually depend on the parameter ⊥ ⊥, we shall sometimes use the notations |A[ρ]|⊥ ⊥ and A[ρ]⊥ ⊥ to indicate this dependency explicitly. In what follows, we shall write
192
A. Miquel
– t NK A[ρ] (‘t realizes A[ρ]’) when t ∈ |A[ρ]|⊥ ⊥ (keeping in mind that this notion depends on the choice of the pole ⊥ ⊥); – t NK A[ρ] (‘t universally realizes A[ρ]’) when t ∈ |A[ρ]|⊥ ⊥ for all saturated sets ⊥ ⊥ ⊆ Λc Π. 2.6
Adequacy
We call a substitution any finite function from proof-variables to closed λc -terms, and write t[σ] the closed term obtained by applying a substitution σ to a term t. Given a substitution σ and a parametric context Γ [ρ], we write σ NK Γ [ρ] when dom(Γ ) ⊆ dom(σ) and σ(x) NK A[ρ] for all (x : A) ∈ Γ . We say that: – A judgment Γ NK t : A is sound (w.r.t. the pole ⊥ ⊥) when for all valuations ρ and for all substitutions σ such that σ NK Γ [ρ], we have t[σ] NK A[ρ]. n (where P1 , . . . , Pn and C are typing judgments) is – An inference rule P1 ···P C sound (w.r.t. the pole ⊥ ⊥) when the soundness of its premises P1 , . . . , Pn (in the above sense) implies the soundness of its conclusion C. From these definitions, it is clear that the conclusion of any typing derivation formed with only sound inference rules is sound. Proposition 1 (Adequacy). The typing rules of Fig. 1 are sound w.r.t. all poles ⊥ ⊥ ⊆ Λc × Π. A consequence of this proposition is that closed proof-terms given by the type system of Fig. 1 provide universal realizers of the corresponding formulæ. (But not all realizers can be detected via typing [7].)
3
From Second-Order Logic to Second-Order Arithmetic
3.1
Extending the Language of Formulæ
We enrich the language of formulæ with a unary predicate constant null(e) (whose name is self-explanatory) plus a syntactic construct {e} ⇒ B (where e is an expression and B a formula) whose semantics will be given in 3.32 : Formulæ
A, B
::=
···
| null(e)
| {e} ⇒ B
This extension of the language is accompanied with the shorthands: ≡ null(0)
nat(e) ≡ ∀Z (({e} ⇒ Z) ⇒ Z)
N
∀ x A(x) ≡ ∀x ({x} ⇒ A(x)) ∃N x A(x) ≡ ∀Z (∀x ({x} ⇒ A(x) ⇒ Z) ⇒ Z) We also introduce two congruences over expressions and formulæ, written e ∼ = A . The congruence e ∼ = e over the class of expressions is = e and A ∼ 2
Intuitively: {e} ⇒ B is the type of functions producing a proof of B when applied to the value of e, using the primitive representation of numerals described in 3.2
Relating Classical Realizability and Negative Translation
193
the congruence generated by the equational theory of the primitive recursive function symbols expressions are made of. The congruence A ∼ = A over the class of formulæ is then defined as the least congruence containing the contextual closure of the congruence e ∼ = e across atomic formulæ, and satisfying the extra ∼ equation null(s(e)) = ⊥ (writing ⊥ ≡ ∀Z Z). Note that from the definition of the propositional constant , the equation null(0) ∼ = comes for free. 3.2
Adding Primitive Numerals to λc
The instruction set K is enriched with the following instructions: – For every n ∈ N, a (pseudo-)instruction n ˆ ∈ K representing the numeral n as a pure datum. We call the constant n ˆ a pseudo-instruction since it comes with no evaluation rule (i.e. of the form n ˆ π · · · ), thus expressing that the constant n ˆ is meaningless in function position. – Two constants s and rec with the reduction rules s n ˆ·u·π 0·π rec u0 · u1 · ˆ rec u0 · u1 · n +1·π
u n +1·π u0 π u1 n ˆ · (rec u0 u1 n ˆ) · π
for all u, u0 , u1 ∈ Λc , n ∈ N and π ∈ Π. With these instructions, it is possible to implement every primitive recursive function f of arity k as a term fˇ with the reduction rule ˆk · u · π fˇ n ˆ1 · · · n
∗
u m ·π,
writing m the image of (n1 , . . . , nk ) by f . To improve efficiency, we can also introduce the fˇs (or some of them) as primitive instructions. Apart from the representation of numerals as pure data, every natural number n ∈ N can be also represented as a program n ˇ defined by n ˇ ≡ λx . xˆ n. (This program will receive the type nat(n) from the type system defined in 3.4.) More generally we call a lazy numeral any closed term t such that tu uˆ n for some n ∈ N (that may depend on u) for all u ∈ Λc . 3.3
The Extended Realizability Interpretation
The realizability interpretation defined in 2.5 is extended to the new syntactic constructs by letting: ∅ if Val(e[ρ]) = 0 null(e)[ρ] = Π otherwise ({e} ⇒ B)[ρ] = {ˆ n · π : n = Val(e[ρ]), π ∈ B[ρ]} From the interpretation of the predicate null(e) and from the definitions of the congruences e ∼ = e and A ∼ = A , we immediately get:
194
A. Miquel
Proposition 2 (Denotations of congruent expressions/formulæ) 1. If e ∼ = e , then Val(e[ρ]) = Val(e [ρ]) for all valuations ρ; 2. If A ∼ = A , then A[ρ] = A [ρ] and |A[ρ]| = |A [ρ]| for all valuations ρ. 3.4
The Extended Type System and Its Adequacy
We first extend the notion of typing context by allowing a second form of declaration x : {e}, where x is a proof-variable and e an arithmetic expression. Given a substitution σ and a parametric context Γ [ρ] (according to the extended definition of contexts), the notation σ NK Γ [ρ] now means that: – dom(Γ ) ⊆ dom(σ); – σ(x) NK A[ρ] for all (x : A) ∈ Γ ; – σ(x) ≡ n ˆ where n = Val(e[ρ]), for all (x : {e}) ∈ Γ . The type system defined in Fig. 1 is extended with the inference rules of Fig. 2.
Γ NK t : A Γ NK t : A
A∼ =A
Γ NK s : ∀N x nat(s(x))
Γ NK t :
Γ NK rec : ∀X (X(0) ⇒ ∀N x (X(x) ⇒ X(s(x))) ⇒ ∀N x X(x)) Γ, x : {e} NK t : B Γ NK λx . t : {e} ⇒ B
Γ NK t : {e} ⇒ B Γ NK tx : B
(x:{e})∈Γ
Γ NK t : {sn 0} ⇒ B Γ NK tˆ n:B
Fig. 2. Typing rules for classical second-order arithmetic
These rules comprise a conversion rule (in the spirit of type theory and deduction modulo), typing rules for the instructions s (2nd Peano axiom) and rec (induction principle), plus typing rules for the construct {e} ⇒ B. Proposition 3 (Adequacy). The typing rules of Fig. 2 are sound w.r.t. all poles ⊥ ⊥ ⊆ Λc × Π. Using these rules, one can derive for instance that n ˇ ≡ λx . xˆ n has type nat(sn 0), and more generally build proof-terms for the axioms of arithmetic: Fact 1. The following judgments are derivable: 1. 2. 3. 4. 5.
NK NK NK NK NK
ˇ 0 : nat(0) s : ∀N x nat(s(x)) λz . z : ∀x (s(x) = s(y) ⇒ x = y) λz . z (λw . w) : ∀x ¬(0 = s(x)) rec : A(0) ⇒ ∀N x (A(x) ⇒ A(s(x))) ⇒ ∀N xA(x)
(1st (2nd (3rd (4th (5th
Peano Peano Peano Peano Peano
axiom) axiom) axiom) axiom) axiom)
Relating Classical Realizability and Negative Translation
4
195
Witness Extraction in Classical Realizability
A fundamental difference between classical realizability and intuitionistic realizability is that in classical realizability we do not evaluate terms but processes, that are objects formed by combining a proof (the current term) and a counter-proof (the current stack) of the same formula. From a logical point of view, evaluation thus takes place in an inconsistent world, where a proof and a counter-proof can coexist and interact with each other. It is well-known that in classical realizability, the truth value |A| of any (parametric) formula A is always inhabited provided the pole ⊥ ⊥ is not empty.3 On the other hand, the realizability model induced by the empty pole ⊥ ⊥ = ∅ simply mimics the (full) standard model of PA2, since |A|(⊥ ⊥=∅) = Λc iff A is true (in the standard model), and |A|(⊥ ⊥=∅) = ∅ otherwise [7]. A consequence of the ‘local inconsistency’ of classical realizability is that when we get a classical realizer t of an existential formula ∃N x A(x) from which we extract a number n ∈ N and a realizer tn NK A(n), we can never trust the certificate tn that ‘A(n) holds’. Instead, we have to test the proposed (and potentially false) witness to check whether A(n) holds or not—which requires a decision procedure for the predicate A(x)—and repudiate the current witness (to get another witness) as long as the test fails. Here is how to proceed formally. We assume given a unary primitive recursive symbol f with a universal realizer t0 NK ∃N x null(f (x)), for instance a universal realizer that comes from a proof in the system described in Fig. 1 and 2. (Any Σ10 formula can be given this form.) Let fˇ be a term that computes f in the sense of 3.2, that is: a term such that fˇ n ˆ · u · π ∗ u f (n) · π for all n ∈ N, u ∈ Λc and π ∈ Π. (Such a term is also a universal realizer of ∀N x nat(f (x)).) From the term fˇ let us define df ≡ λnxy . fˇ n (λp . rec x (λ . y) p). By definition, the term df decides whether f (n) = 0 or not, in the sense that u0 · π if f (n) = 0 ˆ · u0 · u1 · π
df n u1 · π if f (n) = 0 for all n ∈ N, u0 , u1 ∈ Λc and π ∈ Π. Let us now form the term t0 ≡ t0 (λxy . df x (stop x) y) where ‘stop’ is an instruction with no evaluation rule. Intuitively, the argument that is passed to the realizer t0 is a function that extracts a potential witness x ∈ N with a certificate y NK A(x), and that decides whether f (x) = 0 or not using df . When the test succeeds, the (correct) witness x is returned via the return instruction stop. When the test fails, the (wrong) certificate y—a realizer of null(f (x)), that is, a realizer of ⊥—is given 3
Given an arbitrary process t0 π0 ∈ ⊥ ⊥, it is easy to check that kπ0 t0 ∈ |A| for every parametric formula A.
196
A. Miquel
the control. In practice, such a realizer of ⊥ can do nothing but backtrack using a formerly saved stack. In this way we implement a retroaction loop where the successive witnesses proposed by the realizer t0 are tested and repudiated as long as the test fails, until a correct witness is found and then returned.4 Putting these intuitions into symbols, we get the following: Proposition 4 (Decidable witness extraction). For all π ∈ Π, the process t0 π evaluates to stop n ˆ · π for some n ∈ N such that f (n) = 0. Proof. Fix π ∈ Π, and consider the pole ⊥ ⊥ formed by all the processes p such ˆ · π for some n ∈ N such that f (n) = 0. Since t0 is a universal that p ∗ stop n realizer of the formula ∃N x null(f (x)), it is also a realizer w.r.t. the pole ⊥ ⊥ defined above. Taking a valuation ρ such that ρ(Z) = {π}, we immediately check that stop NK ({n} ⇒ Z)[ρ] for all n ∈ N such that f (n) = 0 (by definition of ⊥ ⊥). Distinguishing the cases where f (n) = 0 and f (n) = 0, we then prove that λxy . df x (stop x) y NK ({n} ⇒ null(f (n)) ⇒ Z)[ρ] for all n ∈ N, hence the same term realizes ∀x ({x} ⇒ null(f (x)) ⇒ Z)[ρ]. Consequently, we have t0 π ∗ t0 (λxy . df x (stop x) y) · π ∈ ⊥ ⊥, hence the desired result. In section 7 we shall reinterpret this witness extraction method through a wellsuited negative translation.
5
Intuitionistic Realizability for Second-Order Arithmetic
We now define an intuitionistic type system accompanied with its realizability model whose definition follows the global pattern of the Brouwer-HeytingKolmogorov interpretation. As in [9], we introduce a primitive form of conjunction (as a Cartesian product) and primitive forms of first- and second-order existential quantification (as infinitary unions). 5.1
The Language of Formulæ
Taking the same language of arithmetic expressions as before (cf 2.1) with its congruence e ∼ = e (cf 3.1) we now consider the following language of formulæ: Formulæ
A, B
::= null(e) | nat(e) | X(e1 , . . . , ek ) | A ⇒ B | ∀x A | ∀X A | A ∧ B | ∃x A | ∃X A
Compared with the language for classical logic described in 2.1 and 3.1, the language above replaces the construct {e} ⇒ B by a (more standard) primitive predicate nat(e). We also consider primitive constructions for conjunction and first- and second-order existential quantifications. In this setting, numeric quantifications are defined as ∀N x A(x) ≡ ∀x (nat(x) ⇒ A(x)) 4
and ∃N x A(x) ≡ ∃x (nat(x) ∧ A(x))
This witness extraction method is actually implemented in the module for classical program extraction currently developped by the author for the Coq assistant [10].
Relating Classical Realizability and Negative Translation
197
The congruence A ∼ = A over the class of formulæ is defined from the congru∼ ence induced by e = e (across atomic formulæ) by adding the equations null(e) ∼ = ⊥
and
(∃v A(v)) ⇒ B ∼ = ∀v (A(v) ⇒ B)
where v is any first- or second-order variable that does not occur free in B. (This second equation will be crucial to establish the result of Prop. 9.) As before, we write ≡ null(0). 5.2
A Type System for Intuitionistic Second-Order Arithmetic
We introduce an intuitionistic (and more traditional) proof system based on a judgment of the form Γ NJ t : A, where the proof-term t is now formed in the pure λ-calculus enriched with the following constants: pair (pairing), fst (first projection), snd (second projection), 0 (zero), s (successor) and rec (recursor). In what follows we shall write t; u for the application pair t u, and denote by Λ the set of all closed proof-terms. Typing contexts are simply defined here as finite functions from proof-variables to formulæ. The class of derivable judgments Γ NJ t : A is inductively defined from the rules of inference of Fig. 3, using the abbreviation ∀N x A(x) for the numeric quantification ∀x (nat(x) ⇒ A(x)) such as defined in 5.1. (Note that there is no elimination rule for the primitive existential quantifier, since the desired elimination can be performed using the conversion ∀v (A(v) ⇒ B) ∼ = (∃v A(v)) ⇒ B.) This system is expressive enough to provide typable proof-terms for all the theorems of intuitionistic second-order arithmetic. 5.3
Weak Reduction
Proof-terms are equipped with a binary relation of one-step weak reduction written t w t and defined by the rules (λx . t)u w t{x := u} fst t1 ; t2 w t1
rec u0 u1 0 w u0 snd t1 ; t2 w t2
rec u0 u1 (s t) w u1 t (rec u0 u1 t) t w t tu w t u
u w u tu w tu
Note that weak reduction is allowed both in the left- and right hand-side of applications, but not below λ-abstraction (i.e. we disable the ξ-rule of λ-calculus). We write w∗ the reflexive-transitive closure of one step weak reduction. Complementarily to the notion of weak reduction, we also define a relation of inner reduction written t i t from the rules: t w t λx . t i λx . t
t i t tu i t u
u i u tu i tu
t i t λx . t i λx . t
The reflexive-transitive closure of the relation of inner reduction is written i∗ while its reflexive-symmetric-transitive closure is written =i . The union of both relations w and i is the ordinary relation of one step reduction, written . By the standard method of parallel reductions we get:
198
A. Miquel
Γ NJ x : A
(x:A)∈Γ
Γ NJ t :
Γ NJ t : A Γ NJ t : A
A∼ =A
Γ NJ pair : A ⇒ B ⇒ A ∧ B Γ NJ fst : A ∧ B ⇒ A Γ NJ 0 : nat(0)
Γ NJ snd : A ∧ B ⇒ B Γ NJ s : ∀N x nat(s(x))
Γ NJ rec : ∀X (X(0) ⇒ ∀N x (X(x) ⇒ X(s(x))) ⇒ ∀N x X(x)) Γ, x : A NJ t : B Γ NJ λx . t : A ⇒ B Γ NJ t : A Γ NJ t : ∀x A Γ NJ t : A Γ NJ t : ∀X A
Γ NJ t : A ⇒ B Γ NJ t : A Γ NJ tu : B
X ∈FV / (Γ )
Γ NJ t : A{x := e} Γ NJ t : ∃x A
Γ NJ t : ∀x A Γ NJ t : A{x := e}
x∈FV / (Γ )
Γ NJ t : ∀X A Γ NJ t : A{X(x1 , . . . , xk ) := B} Γ NJ t : A{X(x1 , . . . , xk ) := B} Γ NJ t : ∃X A
Fig. 3. Typing rules for intuitionistic second-order arithmetic
Proposition 5. The relation is confluent. Moreover, we easily check that inner reduction can always be postponed: Proposition 6. If t i t w t , then t w t1 i∗ t for some t1 . From this proposition and the confluence of we get: Proposition 7 (Confluence of w modulo =i ). It t w t1 and t w t2 , then there are terms t1 and t2 such that t1 w t1 , t2 w t2 and t1 =i t2 . 5.4
The Intuitionistic Realizability Model
We now build a simple realizability model for the type system defined above, in which formulæ are interpreted as saturated sets of terms, that is, as sets of closed proof-terms S ⊆ Λ such that both conditions t w t and t ∈ S imply t ∈ S. The set of all saturated sets is written SAT. Here, a valuation is a function ρ that maps every first-order variable x to a natural number ρ(x) ∈ N, and every second-order variable X of arity k to a function ρ(X) : Nk → SAT. Parametric expressions, formulæ and contexts are
Relating Classical Realizability and Negative Translation
199
defined as before. Every parametric formula A[ρ] is interpreted as a saturated set A[ρ] ∈ SAT that is defined by the standard equations X(e1 , . . . , ek )[ρ] = ρ(X)(Val(e1 [ρ]), . . . , Val(ek [ρ])) Λ if Val(e[ρ]) = 0 null(e)[ρ] = ∅ otherwise nat(e)[ρ] = {t ∈ Λ : t w∗ sn 0, where n = Val(e[ρ])} (A ⇒ B)[ρ] = {t ∈ Λ : ∀u ∈ A[ρ] tu ∈ B[ρ]} (A ∧ B)[ρ] = {t ∈ Λ : ∃u1 ∈ A[ρ] ∃u2 ∈ B[ρ] t w∗ t; u} (∀x A)[ρ] =
A[ρ; x ← n]
n∈N
(∃x A)[ρ] =
(∀XA)[ρ] =
A[ρ; X ← F ]
F :Nk →SAT
A[ρ; x ← n]
n∈N
(∃XA)[ρ] =
A[ρ; X ← F ]
F :Nk →SAT
In what follows, we shall write t NJ A[ρ] for t ∈ A[ρ]. Fact 2. If A ∼ = A , then A[ρ] = A [ρ] for all valuations ρ. 5.5
Adequacy
Given a substitution σ and a parametric context Γ [ρ], we write σ NJ Γ [ρ] when dom(Γ ) ⊆ dom(σ) and σ(x) NJ A[ρ] for all (x : A) ∈ Γ . We say that: – A judgment Γ NJ t : A is sound when for all valuations ρ and for all substitutions σ such that σ NJ Γ [ρ], we have t[σ] NJ A[ρ]. n (where P1 , . . . , Pn and C are typing judgments) is – An inference rule P1 ···P C sound when the soundness of its premises P1 , . . . , Pn (in the above sense) implies the soundness of its conclusion C. Proposition 8 (Adequacy). The typing rules of Fig. 3 are sound. From this result combined with the realizability interpretation of existential quantification and conjunction, we immediately get: Fact 3 (Witness property). If NJ t : ∃N x A(x) ≡ ∃x (nat(x) ∧ A(x)), then t w∗ sn 0; t for some n ∈ N and for some realizer t NJ A(n). A consequence of this is that every proof of ∃N x null(f (x)) weakly reduces to a pair of the form sn 0; t , where n is such that f (n) = 0.
6 6.1
The Negative Translation Translating Formulæ
We now define a negative translation of classical formulæ (such as defined in subsections 2.1 and 3.1) into intuitionistic formulæ (in the sense of subsection 5.1),
200
A. Miquel
in the spirit of [9]. As usual, this translation is parameterized by a fixed intuitionistic formula R—the formula that will represent the pole ⊥ ⊥. In what follows, we write ¬R A for A ⇒ R. Every classical formula A is translated as two intuitionistic formulæ written A¬¬ and A⊥ . The formula A¬¬ is simply defined as a shorthand for A¬¬ ≡ ¬R A⊥ whereas the formula A⊥ is defined by induction on A as follows: (X(e1 , . . . , ek ))⊥ ≡ X(e1 , . . . , ek ) (A ⇒ B)⊥ ≡ A¬¬ ∧ B ⊥ ({e} ⇒ B)⊥ ≡ nat(e) ∧ B ⊥
(null(e))⊥ ≡ null(h(e)) (∀x A)⊥ ≡ ∃x A⊥ (∀X A)⊥ ≡ ∃X A⊥
where the (unary) primitive recursive function symbol h is defined by the equations h(0) = 1 and h(s(x)) = 0. It is a simple exercise to check that: ⊥ ¬¬ Fact 4. If A ∼ = A and A¬¬ ∼ = A . = A , then A⊥ ∼
Note also that by definition, we have (∀v A(v))¬¬ ≡ ∃v A(v)⊥ ⇒ R ∼ = ∀v (A(v)⊥ ⇒ R) ≡ ∀v (A(v)¬¬ ) 6.2
CPS-Translating Terms and Stacks
We now define two translations t → t∗ and π → π ∗ (that are defined by mutual induction on t and π) from the terms and stacks of the λc -calculus to the proofterms defined in 5.2. These translations are parameterized by a fixed mapping α → α∗ associating a proof-term α∗ to every stack constant α of λc . Stacks are translated in the obvious way, as finite lists: (α)∗
≡ α∗
(t · π)∗ ≡ t∗ ; π ∗
Variable, abstraction and application are translated as expected x∗ (tu)∗ (λx . t)∗
≡ x ≡ λk . t∗ u∗ ; k ≡ λk . (λx . t∗ ) (fst k) (snd k)
whereas continuation constants and call/cc are translated as (kπ )∗ (cc)∗
≡ ≡
λk . fst k π ∗ λk . fst k (λzk . fst k z) (snd k); snd k
Interestingly, the pure datum n ˆ is translated as (ˆ n)∗
≡
sn 0 .
Here, the translation does not start with a continuation abstraction λk . . ., since the construct n ˆ is not intended to appear in head position. Finally, the instructions s and rec are translated as: (s)∗
≡
λk . fst (snd k) s (fst k); snd (snd k)
∗
≡
λk . rec (fst1 k) (λpyk . fst (snd k) p; y; k ) (fst (snd (snd k))) (snd (snd (snd k)))
(rec)
Relating Classical Realizability and Negative Translation
201
Proposition 9 (Correctness w.r.t. typing). If Γ NK t : A (Fig. 1–2), then Γ ¬¬ NJ t∗ : A¬¬ (Fig. 3). 6.3
Simulation of Evaluation by Weak Reduction
The expected property would be that each evaluation step t1 π2 t2 π2 in λc corresponds to one or several weak reduction steps t∗1 π1∗ w+ t∗2 π2∗ through the CPS-translation. Although this works for almost all the evaluation rules— application, abstraction, call/cc, continuation and successor—the property does not hold for the evaluation of rec so that we need to refine a little bit more. Proposition 10 (One step simulation). If t1 π1 t2 π2 (one step evaluation in λc ), then t∗1 π1∗ w+ t∗2 u (weak reduction) for some term u =i π2∗ . Corollary 1 (Grand simulation). — If t1 π1 ∗ t2 π2 (evaluation in λc ), then t∗1 π1∗ w∗ u (weak reduction) for some term u =i t∗2 π2∗ .
7
The Negative Interpretation of Witness Extraction
Let us now reinterpret the witness extraction method described in section 4 through the negative translation defined in section 6. For that, consider a λc -term t0 such that NK t0 : ∃N x null(f (x)), where N ∃ x null(f (x)) is a shorthand for ∀Z (∀x ({x} ⇒ null(f (x)) ⇒ Z) ⇒ Z). Let df be the decision function for the predicate null(f (x)) introduced in section 4, and write uf ≡ λxy . df x (stop x) y (where ‘stop’ is an instruction with no evaluation rule) and p0 ≡ t0 uf · α (where α is a stack constant). From the discussion of ˆ · α for some n ∈ N section 4, we know that the process p0 evaluates to stop n such that f (n) = 0. Via the negative translation we have by Prop. 9:
NJ t∗0 : ∀Z ∀x nat(x) ∧ (null(h(f (x))) ⇒ R) ∧ Z ⇒ R ∧ Z ⇒ R The crucial point is the following: Proposition 11. In the intuitionistic realizability model:
d∗f NJ ∀x nat(x) ∧ null(f (x)) ⇒ R ∧ null(h(f (x))) ⇒ R ∧ ⇒ R (independently from the choice of R). To type-check the term uf ≡ λxy . df x (stop x) y through the negative translation, let us now fix the pole by setting R ≡ ∃x (nat(x) ∧ null(f (x))), while defining the translation of the instruction stop as (stop)∗ ≡ λz . z. With this implementation of stop∗ we clearly have
202
A. Miquel
NJ stop∗ : ∀x nat(x) ∧ null(f (x)) ⇒ R hence (combining the latter with Prop. 11 using adequacy)
u∗f NJ ∀x nat(x) ∧ null(h(f (x))) ⇒ R ∧ ⇒ R , from which we deduce that p∗0 NJ R ≡ ∃x nat(x) ∧ null(f (x)) . We have thus shown that through the negative translation, the transformation of the classical proof t0 into the process p0 is nothing but the transformation of a classical proof of a Σ10 -formula into an intuitionistic realizer of the same formula, thus giving a constructive explanation why the procedure described in section 4 successfully extracts a reliable witness in finite time. Of course, the point here is that through the negative interpretation, the transformation of the classical proof t0 into the process p0 exactly follows the well-known method (due to Friedman [2]) to transform a classical proof of a Σ10 -formula into an intuitionistic proof of the same formula.
References 1. Barendregt, H.: The Lambda Calculus: Its Syntax and Semantics. Studies in Logic and The Foundations of Mathematics, vol. 103. North-Holland, Amsterdam (1984) 2. Friedman, H.: Classically and intuitionistically provably recursive functions. Higher Set Theory 669, 21–28 (1978) 3. Girard, J.-Y., Lafont, Y., Taylor, P.: Proofs and Types. Cambridge University Press, Cambridge (1989) 4. Krivine, J.-L.: A general storage theorem for integers in call-by-name lambdacalculus. Th. Comp. Sc. 129, 79–94 (1994) 5. Krivine, J.-L.: Typed lambda-calculus in classical Zermelo-Fraenkel set theory. Arch. Math. Log. 40(3), 189–205 (2001) 6. Krivine, J.-L.: Dependent choice, ‘quote’ and the clock. Th. Comp. Sc. 308, 259–276 (2003) 7. Krivine, J.-L.: Realizability in classical logic. Unpublished lecture notes (available on the author’s web page) (2005) 8. Miquel, A.: Classical program extraction in the calculus of constructions. In: Duparc, J., Henzinger, T.A. (eds.) CSL 2007. LNCS, vol. 4646, pp. 313–327. Springer, Heidelberg (2007) 9. Oliva, P., Streicher, T.: On Krivine’s realizability interpretation of classical secondorder arithmetic. Fundam. Inform. 84(2), 207–220 (2008) 10. The Coq Development Team (LogiCal Project). The Coq Proof Assistant Reference Manual – Version 8.1. Technical report, INRIA (2006)
Session-Based Communication Optimisation for Higher-Order Mobile Processes Dimitris Mostrous and Nobuko Yoshida Department of Computing, Imperial College London
Abstract. In this paper we solve an open problem posed in our previous work on asynchronous subtyping [12], extending the method to higher-order session communication and functions. Our system provides two complementary methods for communication code optimisation, mobile code and asynchronous permutation of session actions, within processes that utilise structured, typed communications. In order to prove transitivity of our coinductive subtyping relation, we uniformly deal with type-manifested asynchrony, linear functional types, and contravariant components in higher-order communications. For the runtime system we propose a new compact formulation that takes into account stored higher-order values with open sessions, as well as asynchronous commutativity. In spite of the enriched type structures, we construct an algorithmic subtyping system, which is sound and complete with respect to the coinductive subtyping relation. The paper also demonstrates the expressiveness of our typing system with an e-commerce example, where optimised processes can interact respecting the expected sessions.
1 Introduction Sessions [16,7] have emerged as a tractable and expressive theoretical substrate, which offers direct language and protocol support [17,9,18] for high-level, type-safe and uniform abstraction for a wide range of communication patterns. Session types enable static validation assuring both type and communication-safety — not only is the value of each message correctly typed, but the sequence of messages are sent and received according to the scenario specified by the session type, precluding communication mismatch. Session primitives can be smoothly integrated with traditional subtyping of object and functional languages, to obtain a more flexible behavioural composition [5]. Our recent work [12] developed a new subtyping, asynchronous subtyping, that characterises compatibility between classes of permutations of communications within asynchronous protocols, offering much greater flexibility. However, an open problem remained: how to uniformly introduce communication optimisations in the presence of code mobility [11], incorporating higher-order sessions and functions into the asynchronous subtyping [12, § 6]. This is the question we address in this paper. Higher-Order Processes with Asynchronous Sessions. We develop a session typing system for the Higher-order π-calculus [15], an amalgamation of call-by-value λcalculus and π-calculus, extending [11]. Code mobility is facilitated by sending not just
The work is supported by EPSRC GR/T03208, GR/T03215 and IST2005-015905 MOBIUS.
P.-L. Curien (Ed.): TLCA 2009, LNCS 5608, pp. 203–218, 2009. c Springer-Verlag Berlin Heidelberg 2009
204
D. Mostrous and N. Yoshida
ground values and channels, but also abstracted processes that can be received and activated locally, reducing the number of transmissions of remote messages. The simplest code mobility operations are sending a thunked process P via channel s (denoted as s!P), and receiving and running it by applying the unit (denoted as s?(x).x ()). In our calculus, communications are always within a session, established when accept and receive processes synchronise on a shared channel: a(x).x!5.x!true.x?(y).(y() | R) | a(x).x?(z1 ).x?(z2 ).x!P resulting in a fresh session, consisting two channels s and s, each private to one of the two processes, and their associated queues initialised to be empty: (ν s)(s!5.s!true.s?(y).(y() | R) | s?(z1 ).s?(z2 ).s!P | s : ε | s : ε) To avoid conflicts, an output on a channel s (resp. s) places the value on the dual queue s (resp. s), while an input on s reads from s (resp. for s). Thus, after two steps the outputs of 5 and true are placed on queue s as follows: (ν s)(s?(y).(y() | R) | s?(z1 ).s?(z2 ).s!P | s : ε | s : 5 · true) and in two more steps the right process receives and reduces to s!P{5/z1 }{true/z2 }. Similarly the next step transmits the thunked process, and R can interact with P locally. The session type of s, S =?[nat].?[bool].![H] (where H is the type of P), guarantees that values are received following the order specified by S. Asynchronous Communication Optimisation with Code Mobility. Suppose the size of P is very large and it does not contain z1 and z2 . Then the right process might wish to start transmission of P to s : ε concurrently without waiting for the delivery of 5 and true, since the sending is non-blocking. Thus we send P ahead as in s!P.s?(z1 ).s?(z2 ).0. The interaction with the left process is safe as the outputs are ordered in an exact complementary way. However the optimised code is not composable with the other party by the original session system [16] since it cannot be assigned S. To make this optimisation valid, we proposed the asynchronous subtyping in [12] by which we can refine a protocol to maximise asynchrony without violating the session. For example, in the above case, S =![H].?[nat].?[bool] is an asynchronous subtype of S, hence the resulting optimisation is typable. The idea of this subtyping is intuitive and the combination of two kinds of optimisations is vital for typing many practical protocols [17,18] and parallel algorithms [13], but it requires subtle formal formulations due to the presence of higher-order code. The linear functional typing developed in [11] permits to send a value that contains free session channels: for example, not only message s!s ?(x).s !x (for s!P), but also one which contains its own session s!s?(x).s!x is typable (if R conforms with the dual session like R = s!7.s?(z).0). The first message can go ahead correctly, but the permutation of the second message (as s!P) violates safety since the input action s?(x) will appear in parallel with s?(z1 ).s?(z2 ), creating a race condition, as seen in: (ν s)(s?(x).s!x | R | s?(z1 ).s?(z2 ).0 | s : ε | s : 5 · true)
Session-Based Communication Optimisation for Higher-Order Mobile Processes (Identifiers) u, v, w ::= x, y, z variables | a, b, c shared channels (Terms) P, Q, R ::= V | u(x).P | u(x).P | k?(x).P | k!V .P | k {l1 : P1 , . . . , ln : Pn } | k l.P | P|Q | (ν a : S) P | (ν s) P | PQ | 0 | s :h
value server client input output branching selection parallel restriction restriction application nil process queue
205
k ::= x, y, z variables | s, s session channels (Values) V ::= u, v, w | k | () | λ(x :U).P | µ(x :U → T ).λ(y :U).P
shared linear unit abstraction recursion
(Message Values) h ::= l | V
label
(Abbreviations) def
P = λ(x : unit).P (x ∈ fv(P)) thunk def
run = λx.(x ())
run
Fig. 1. Syntax
This paper shows that the combination of two optimisations is indeed possible by establishing soundness and communication-safety, subsuming the original typability from [11]. The technical challenge is to prove the transitivity of the asynchronous subtyping integrated with higher-order (linear) function types and session-delegation, since the types now appear in arbitrary contravariant positions [12]. Another challenge is to formulate a runtime typing system which handles both stored higher-order code with open sessions and the asynchronous subtyping. We demonstrate all facilities of typepreserving optimisations proposed in this paper by using an e-commerce scenario. A full version, containing omitted definitions and proofs, is available from [1].
2 The Higher-Order π-Calculus with Asynchronous Sessions 2.1 Syntax and Reduction The calculus is given in Fig. 1, based on the π-calculus augmented with asynchronous session primitives and the call-by-value λ-calculus. Except for recursion and message queues for asynchronous communications [8], all constructs are from the synchronous Higher-Order calculus with sessions [11]. A session is initiated over a shared channel and communications belonging to a session are performed via two fresh end-point channels specific to that session, called session channels or queue endpoint channels, used to distinguish the two end points, taking a similar approach to [5,20]. The dual of a queue endpoint s is denoted by s , and represents the other endpoint of the same session. The operation is self-inverse hence s = s. We write V for a potentially empty vector V1 ...Vn . Types, given later, are denoted by U, T and S, but type annotations are often omitted. For values, we have shared and linear identifiers, unit, abstraction and recursion. For terms, we have prefixes for declaring session connections, u(x).P for servers and
206
D. Mostrous and N. Yoshida
(beta) (λx.P)V −→ P{V/x}
(rec) (µy.λx.P)V −→ P{V/x}{µy.λx.P/y}
(send) s!V .P | s :h −→ P | s :h ·V (sel) s l.P | s :h −→ P | s :h · l
(get) s?(x).P | s :V ·h −→ P{V/x} | s :h (bra) s {l1 : P1 , . . . , ln : Pn } | s : lm ·h −→ Pm | s :h
(1 ≤ m ≤ n)
(conn) a(x).P | a(z).Q −→ (ν s) (P{s/x} | Q{s/z} | s : ε | s : ε) (app-l) (resc)
P −→ P PQ −→ P Q P −→ P (ν a)P −→ (ν a)P
(app-r) (ress)
Q −→ Q V Q −→ V Q P −→ P (ν s)P −→ (ν s)P
s, s fresh
P −→ P P | Q −→ P | Q P ≡ P −→ Q ≡ Q (str) P −→ Q (par)
Fig. 2. Reduction
u(x).P for clients. Session communications are performed using the next four primitives: input k?(x).P, output k!V .P, branching k {l1 : P1 , . . . , ln : Pn } (often written as k {li : Pi }i∈I with index set I) which offers alternative interaction patterns, and selection k l.P which chooses an available branch. (ν a : S)P restricts (and binds) a channel a to the scope of P. Similarly, (ν s) P binds s and s, making them private to P. s :h is a message queue, also called buffer, representing ordered messages in transit with destination s (which may be considered as a network pipe in a TCP-like transport). Queues and session restrictions appear only at runtime. A program is a process which does not contain runtime terms. Other primitives are standard. We often omit 0. The bindings are induced by (ν a : S)P, (ν s)P, u(x).P, u(x).P, λx.P and µy.λx.P. The derived notions of bound and free identifiers, alpha equivalence and substitution are standard. We write fv(P)/fn(P) for the set of free variables/channels, respectively. By using recursion, we can represent infinite behaviours of processes such as, e.g. the definition agent def or !u(y).P in [20,7,10,11]. For example the replication !u(y).P in [11] can be defined as u(x).(µy.λz.(P | z(x).y z))u with x ∈ fv(P). The single-step call-by-value reduction relation, denoted −→, is a binary relation from closed terms to closed terms, defined by the rules in Fig. 2. The rules are from those of the HOπ-calculus [11] combined with asynchronous session communications from [8]. Rule (conn) establishes a new session between server and client via shared name u, generating two fresh session channels and the associated two empty queues (ε denotes the empty string). Rules (send) and (sel) respectively enqueue a value and a label at the tail of the queue for a dual endpoint s. Rules (get) and (bra) dequeue, from the head of the queue, a value or label. (get) substitutes value V for x in P, while (bra) selects the corresponding m-branch. Since (conn) provides a queue for each channel, these rules say that a sending action is never blocked (asynchrony) and that two messages from the same sender to the same channel arrive in the sending order (order preservation). Other rules are standard. A session channel s and s can be sent and received (when V = k), with which various protocols are expressed, allowing complex nested and private structured communications. This interaction is called higher-order session passing (delegation). We use the standard structure rules [10] ≡ such as (ν s) P | Q ≡ (ν s) (P | Q) if s, s ∈ fn(Q) (see [11]). “” denote the multi-step reductions defined as (≡ ∪ →)∗ .
Session-Based Communication Optimisation for Higher-Order Mobile Processes
207
2.2 Example: Optimised Business Protocol with Code Mobility We show a business/financial protocol interaction from [18,17] which integrates the two kinds of type-safe optimisations. We extend the scenario from [11] to highlight the expressiveness gained using the new method. Fig. 3 draws the sequencing of actions modelling a hotel booking through a process Agent. On the left Client behaves dually to Agent; on the right, an optimised MClient utilises type-safe asynchronous behaviour.
Agent
Client
MClient
rtt
rtt
move
move
code
code
run code
run code
hotel
hotel
roomtype rate
roomtype rate
creditcard
creditcard local
Fig. 3. Standard (left) and Optimised (right) Interaction for Hotel Booking
The Agent behaves the same towards both clients: initially it calculates the roundtrip time (RTT) of communication (rtt) and sends it; it then offers to the other party the option to consider the RTT and either send mobile code to interact with the Agent on its location, or to continue the protocol with each executing remotely their behaviour. When mobile code (after choice move) is received, it is run by the Agent completing the transaction on behalf of the client, in a sequence of steps. The behaviour of Client is straightforward and complementary to Agent, but MClient has special requirements: it represents a mobile device with limited processing power, and irrespective of the RTT it always sends mobile code; moreover, it does not care about money, and provides the creditcard number (card) before finding out the rate. To represent this optimised scenario, we start from the process for Agent: Agent = a(x).x!rtt.x {move : x?(code).(run code | Q), local : Q} Q = x?(hotel).x?(roomtype).x!rate.x?(creditcard) . . . The session is initiated over a, then the rtt is sent, then the choices move and local are offered. If the first choice is made then the received code is run in parallel to the process Q which continues the agent’s session, performing optimisation by code mobility. As expected, Client has dual behaviour: Client = a(x).x?(rtt).x move.x!x!ritz.x!suite.x?(rate).x!card. . . .
208
D. Mostrous and N. Yoshida
A more interesting optimisation is given by MClient which at first may seem to disagree with the intended protocol: MClient = a(x).x move.x!x!ritz.x!suite.x!card.x?(rtt).x?(rate) . . . After the session is established, it eagerly sends its choice move, ignoring rtt, followed by a thunk that will continue the session; and another important point is that in the mobile code the output of the card happens before rtt and rate are received. Even without subtyping, the typing of sessions in the HOπ-calculus poses delicate conditions [11]; in the present system, we can further verify that the optimisation of MClient does not violate communications safety (but the similar example in § 1, s!s?(x).s!x.s?(z1 ).s?(z2 ).0, must be untypable): when values are received they are always of the expected type, conforming to a new subtyping relation given in the next section.
3 Higher-Order Linear Types with Asynchronous Subtyping 3.1 Types This section presents an asynchronous subtyping relation for the HOπ-calculus based on [12]. The syntax of the types is given below: Term T ::= U | Value U ::= H | S HO-value H ::= unit | U → T | U T | S Session S ::= ![U].S | ?[U].S | ⊕[l1 : S1 , . . . , ln : Sn ] | &[l1 : S1 , . . . , ln : Sn ] | µt.S | t | end It is an integration of the types from the simply typed λ-calculus with linear functional types, U T , and the session types from the π-calculus. A linear type represents a function to be used exactly once. Term types, ranging over T , include all value types and the process type . Session types range over S, S, ... Higher-Order value types consist of the unit type, the function types, the linear function types and the channel type S, and value types consist of HO-value and session types. Note that linear types are attached only to function types. In the session types, ![U].S represents the output of a value typed by U followed by a session typed by S; ?[U] is its dual. ⊕[l1 : S1 , . . . , ln : Sn ] is the selection type on which one of the labels li can be sent, with the subsequent session typed by Si ; &[l1 : S1 , . . . , ln : Sn ] is its dual called the branching type. t is a type variable and µt.S is a recursive type. We only consider contractive recursive types [20]. end denotes the termination of the session. We often write &[li : Si ]i∈I and ⊕[li : Si ]i∈I and T for unit → T and T1 for or unit T . The type end is often omitted. Each session type S has a dual type, denoted by S, which describes complementary behaviour. This is inductively defined as: ![U].S =?[U].S, ⊕[l1 : S1 , . . . , ln : Sn ] = &[l1 : S1 , ..., ln : Sn ], ?[U].S =![U].S, &[l1 : S1 , . . . , ln : Sn ] = ⊕[l1 : S1 , ..., ln : Sn ], t = t, µt.S = µt.S and end = end. We say a type is guarded if it is neither a recursive type nor a type variable. (An occurrence of) a type constructor not under a recursive prefix in a recursive type is
Session-Based Communication Optimisation for Higher-Order Mobile Processes ![U].?[U ].S ?[U ].![U].S
(OI)
(SI)
209
⊕[l j :?[U].S j ] j∈J ?[U]. ⊕ [l j : S j ] j∈J
(OB) ![U].&[l j : S j ] j∈J &[l j :![U].S j ] j∈J (SB) ⊕[li : &[l j : Si j ] j∈J ]i∈I &[l j : ⊕[li : Si j ]i∈I ] j∈J (Tr)
S1 S2 S2 S3 S1 S3
(CO) ![U].S ![U].S
(CB)
∀i ∈ I. Si Si &[li : Si ]i∈I &[li : Si ]i∈I
(CS) ⊕[li : Si ]i∈I ⊕[li : Si ]i∈I
(CI)
S S ?[U].S ?[U].S
(E) end end (M) μt.S μt.S
Fig. 4. Top Level Asynchronous Action Rules
called top-level action (for example, ![U1 ] and ?[U2 ] in ![U1 ].?[U2 ].µt.![U3].t are toplevel, but ![U3 ] in the same type is not). In the above type, ![U1 ] is the head since it appears as the left-most occurrence of the top-level actions in S (note that ?[U2 ] is not the head). We write Type for the collection of all closed types. 3.2 Higher-Order Asynchronous Subtyping This subsection studies a theory of asynchronous session subtyping: reordered communications, even higher-order and mobile, can preserve the faithfulness to the other dual party. Fig. 4 defines the axioms for partial permutation of top-level actions for closed types, denoted . S S is read: S is an action-asynchronous subtype of S , and means S is more asynchronous than (or more optimised than) S . We write S S for S S. A permutation of two inputs or two outputs is not allowed since it violates type-safety. Suppose P = s!2.s!true.s?(x).0 and Q = s?(y).s?(z).s!y + 2.0. These processes interact correctly. If we permute the outputs of P to get P = s!true.s!2.s?(x).0, then the parallel composition (P | Q) causes a type-error. Similarly the reverse direction of (OI, OB, SI, SB) causes a deadlock, losing progress in session s. For example, consider exchanging s!true and s?(z) in P1 = s!true.s?(z).0, and Q1 = s?(y).s!2.0. Note that partial permutation is only applied to finite parts of the top-level actions without unfolding recursive types. To handle recursive types in asynchronous subtyping, we need to generalise the unfolding function defined in [5] since might be applicable to a type after unfolding of recursions under some guarded prefixes. The definition is based on [12]. Definition 3.1 (n-time unfolding) unfold1+n (S) = unfold1 (unfoldn (S)) unfold0 (S) = S for all S 1 1 unfold (![U].S) =![U].unfold (S) unfold1 (⊕[li : Si ]i∈I ) = ⊕[li : unfold1 (Si )]i∈I unfold1 (?[U].S) =?[U].unfold1 (S) unfold1 (&[li : Si ]i∈I ) = &[li : unfold1 (Si )]i∈I unfold1 (t) = t unfold1 (µt.S) = S[µt.S/t] unfold1 (end) = end For any recursive type S, unfoldn (S) is the result of inductively unfolding the top level recursion up to a fixed level of nesting. Because our recursive types are contractive, unfoldn (S) terminates. We now introduce the main definition of the paper, asynchronous communication subtyping for the HOπ-calculus. First, let us define: (H, H ) = (H, H )
(S, S) = (S , S)
( , ) = ( , )
which is used to adjust for the different variance of functional and session types.
210
D. Mostrous and N. Yoshida
Definition 3.2 (Asynchronous Subtyping). A relation ℜ ∈ Type × Type is an asynchronous type simulation if (T1 , T2 ) ∈ ℜ implies the following conditions: 1. If T1 = , then T2 = . 2. If T1 = unit, then T2 = unit. 3. If T1 = U1 → T1 , then T2 = U2 → T2 or T2 = U2 T2 with (U2 ,U1 ) ∈ ℜ and (T1 , T2 ) ∈ ℜ. 4. If T1 = U1 T1 , then T2 = U2 T2 with (U2 ,U1 ) ∈ ℜ and (T1 , T2 ) ∈ ℜ. 5. If T1 = S1 , then T2 = S2 and (S1 , S2 ) ∈ ℜ and (S2 , S1 ) ∈ ℜ. 6. If T1 = end, then unfoldn (T2 ) = end. 7. If T1 =![U1 ].S1 , then unfoldn (T2 ) ![U2 ].S2 , (U1 ,U2 ) ∈ ℜ and (S1 , S2 ) ∈ ℜ. 8. If T1 =?[U1 ].S1 , then unfoldn (T2 ) =?[U2 ].S2 , (U2 ,U1 ) ∈ ℜ and (S1 , S2 ) ∈ ℜ. 9. If T1 = ⊕[li : S1i ]i∈I , then unfoldn (T2 ) ⊕[l j : S2 j ] j∈J , I ⊆ J and ∀i ∈ I.(S1i , S2i ) ∈ ℜ. 10. If T1 = &[li : S1i ]i∈I , then unfoldn (T2 ) = &[l j : S2 j ] j∈J , J ⊆ I and ∀ j ∈ J.(S1 j , S2 j ) ∈ ℜ. 11. If T1 = µt.S, then (unfold1 (T1 ), T2 ) ∈ ℜ. As standard, the coinductive subtyping relation T1 c T2 (read: T1 is an asynchronous subtype of T2 ) is defined when there exists a type simulation ℜ with (T1 , T2 ) ∈ ℜ. The integration of the subtyping of higher-order (linear) functions and asynchronous sessions requires a careful formulation: (1,2,6) are standard identity rules. (3) says the unlimited function can be used as the linear function. Note that the reverse is unsafe: suppose f = λx.k!x with a linear type nat . If we apply the reverse direction, λ(y : nat → ).(y 1 | y 2) f becomes typable, destroying the linearity of session k. In (3), when Ui is a session type, we use the relation (S1 , S2 ) = (S2 , S1 ) to swap the tuple. The session types are dualised since the session channel is going to be used in a process in a contravariant manner.1 To see this condition, suppose process P = (λ(x : S).x!2.x?(y).0) s with S =![nat].?[bool].end. Then P can safely interact with Q = s!true.s?(z).0. For P to be composable with Q, s in P has a dual type of s in Q, which is S =?[bool].![nat].end. Hence we must have S → c S → , with S c S where the subtyping ordering of session channels is covariant. The case Ti is a session type is similarly explained. (4) is similar. (5) says the shared channel type is invariant (as is the standard session types [5,12,7]). In (7), an output of T1 can be simulated after applying asynchronous optimisation to the unfolded T2 . We also need to ensure object type U1 is a subtype of U2 . For similar reasons with (3), we swap the ordering if they are session types. For the input in (8), we do not require , since, by definition of , if the input appears at the top level in S, then it does so in all S such that S S . The definitions of selection and branching subsume the traditional session branching/selection subtyping. In (9), selection is defined 1
The original session typing system uses a judgement “Γ P : Σ” where Γ is a shared (standard) environment and Σ is a mapping from a session channel to a session type. This means: P accesses the session channels specified at most by Σ. Contrarily, in our typing system defined in the next section, Σ appears in the left-side position, so that we need to dualise the session types for subtyping, cf. [19].
Session-Based Communication Optimisation for Higher-Order Mobile Processes
211
similarly to output since a label appearing in T1 must be included in T2 ; dually, in (10), branching is defined like input and any branch of T2 must be included in T1 . Finally (11) forces T1 to be unfolded until it reaches a guarded type. More examples can be found in § 4.3. We conclude this section with the main theorem for c . Since now types include higher-order function types and session delegations with a combination of n-time unfolding and permutation, the proof of transitivity of c requires a family of relations to connect two relations ℜ1 and ℜ2 , for which we use the transitivity connection trc(ℜ1 , ℜ2 ). Lemma 3.3. If S1 c S2 and S1 unfoldn (S1 ) then S1 c S2 . From the above lemma we have that whenever S1 ℜ S2 for type simulation ℜ, then for some n-times unfolding of S1 , and after applying a sequence of permutations to obtain S1 such that S1 unfoldn (S1 ), there exists a type simulation ℜ such that S1 ℜ S2 . We use this fact below: given S1 ℜ S2 , we obtain a simulation (the union of ℜ ) for each level n of unfolding of S1 , relating each possible permutation S1 of unfoldn (S1 ) and S2 . Definition 3.4 (Transitivity Connection). When S1 ℜ S2 for type simulation ℜ, we define the asynchrony relation of S1 and S2 as: A (S1 , S2 ) = (S1 , S2 ) | unfoldn (S1 ) S ∧ S ℜ S2 ∧ ℜ ⊆ c ∧ (S1 , S2 ) ∈ ℜ n∈N
Then, for type simulations ℜ1 and ℜ2 , we define their transitivity connection trc(ℜ1 , ℜ2 ) as the smallest relation such that whenever S1 ℜ1 S2 and S2 ℜ2 S3 , we have A (S2 , S3 ) ⊆ trc(ℜ1 , ℜ2 ). For type simulation ℜ with S1 ℜ S2 , A (S1 , S2 ) (hence trc(ℜ1 , ℜ2 )) is also a type simulation. Using this property, we have: Theorem 3.5 (Preorder). c is a preorder. Proof. Reflexivity is easy. For transitivity, we assume (T1 , T2 ) ∈ ℜ1 and (T2 , T3 ) ∈ ℜ2 for simulations ℜ1 and ℜ2 , to find a simulation ℜ such that (T1 , T3 ) ∈ ℜ. Define ℜ as: ℜ = ℜ12 · ℜ21 ∪ ℜ21 · ℜ12
with
ℜi j = ℜi ∪ trc(ℜ j , ℜi )
We have (T1 , T3 ) ∈ ℜ1 · ℜ2 ⊆ ℜ12 · ℜ21 ⊆ ℜ; we then prove that ℜ is a type simulation, observing the fact that each ℜi j above is a type simulation, as the union of type simulations, see [1].
4 Asynchronous Higher-Order Session Typing 4.1 A Typing System for Programs We first introduce the linear Higher-Order typing system for programs (terms which do not contain queues and session-restrictions). We define two environments: Γ ::= 0/ | Γ, u : H
Σ ::= 0/ | Σ, k : S
212
D. Mostrous and N. Yoshida
(Common) (Shared)
(Session)
(LVar)
(Base)
H = U T / 0/ u : H Γ, u : H; 0;
Γ; k : S; 0/ k : S
/ {x} x : U T Γ, x : U T ; 0;
/ 0/ () : unit Γ; 0;
(Function)
(Process)
Γ, x : H; Σ; L P : T if H = U T then x ∈ L Γ; Σ; L \ x λ(x : H).P : H → T (Abs)
(AbsS )
Γ; Σ, x : S; L P : T Γ; Σ; L λ(x : S).P : S → T
(Recursion)
/ 0/ λ(y :U).P : U → T Γ, x :U → T ; 0; / 0/ µ(x :U → T ).λ(y :U).P : U → T Γ; 0;
(Sub) Γ; Σ; L P : H
Σ c Σ H c H Γ; Σ ; L P : H
(App) Γ; Σ1 ; L1 P : U T Γ; Σ2 ; L2 Q : U if U = U → T then Σ2 = L2 = 0/ Γ; Σ1 , Σ2 ; L1 , L2 P Q : T
Fig. 5. Selected Linear Session Typing
Γ is a finite mapping, associating HO value types to identifiers. Σ is a finite mapping from session channels to session types. In addition, we use a finite set of linear variables ranged over L , L , ... to ensure linear usage of function terms that may contain session channels. Σ, Σ and L , L denote disjoint-domain unions. Γ, u :U means u ∈ dom(Γ). Then the typing judgement takes the shape: Γ; Σ; L P : T which is read: under a global environment Γ, a term P has a type T with session usages described by Σ and linear variables specified by L . We say the judgement is well-formed / The typing system is given in Fig. 5. In each if dom(Γ) ⊇ L and dom(Γ) ∩ dom(Σ) = 0. rule, we assume the environments of the consequence are defined. We focus on the rules which differ from [11]. In the first group, (Common), (Shared) is an introduction rule for identifiers with shared types; (Session) is for session channels. (LVar) is for linear variables. The second group, (Function), comes from the typed linear λ-calculus with recursive types. All rules are identical except the addition of (Recursion). In (Abs), the premise side-condition ensures that the formal parameter x, to be substituted with the received function, appears in the linear variables. In the conclusion, we remove x from the function environment. (AbsS ) is an abstraction rule for session channels. (Recursion) forbids the use of any free linear identifier (by the condi/ because it is repeatedly used. (App) is the rule for application; the side tion Σ = L = 0) condition ensures that when the right term is of shared function type, it is required not to have free session channels or linear variables. The conclusion says that P and Q’s session environments and linear variable sets are disjoint. The final group, (Process), is for processes. The only different rule from [11] is (Sub) which now uses c ; we write Σ c Σ when dom(Σ) = dom(Σ ) and for all k : S ∈ Σ, we have k : S ∈ Σ with S c S . The rest of the rules and their explanations can be found in [11]. 4.2 A Typing System for Runtime Session Remainder. Type soundness is established by also typing the queues created during the execution of a well-typed initial program. We track the movement of linear
Session-Based Communication Optimisation for Higher-Order Mobile Processes
213
functions and channels to and from the queue to ensure that linearity is preserved, and we check that endpoints continue to have dual types up to asynchronous subtyping after each use. To analyse the intermediate steps precisely, we utilise a session remainder S −τ = S which subtracts the vectorτ of queue types (τ ::= U | l) of the values stored in a queue from the complete session type S of the queue, obtaining a remaining session S . The rules are formalised below: (Empty)
S−ε = S
(Get) (Put) (Branch) (Select)
S −τ = S S −τ = S Sk −τ = S ∧ k ∈ I ∀ i ∈ I . Si −τ = Si
⇒ ⇒ ⇒ ⇒
?[U].S − Uτ = S ![U].S −τ =![U].S &[li : Si ]i∈I − lkτ = S ⊕[li : Si ]i∈I −τ = ⊕[li : Si ]i∈I
When S is end, then the session has been completed; otherwise it is not closed yet. (Empty) is a base rule. (Get) takes an input prefixed session type ?[U].S and subtracts the type U at the head of the queue, then returns the remainder S of the rest of the session S minus the tailτ of the queue type. (Put) disregards the output action type of the session and calculates the remainder S of S −τ, which is returned prefixed with the original output giving ![U].τ. Therefore the output is not consumed. (Branch) is similar with (Get), but it only records the remainder of the k-th branch with respect to a stored label lk . Dually, (Select) records the remainder of all selection paths. A Typing System for Runtime. We first extend the session environment as follows: Δ ::= Σ | Δ, s :τ | Δ, s : (S,τ) The typing judgement is also extended with Γ; Σ; L l : l which is used for typing any labels appearing in a session queue. Δ contains usage information for queues (s :τ) in a term, so that the cumulative result can be compared with the expected session type; for this we use the pairing (s : (S,τ)) that combines the usage of a channel and the sequence of types already on its queue. We identify (S,τ) and (τ, S). We define a composition operation on Δ-environments, used to obtain the paired usages for channels and queues: Δ1 Δ2 = {s : (Δ1(s), Δ2 (s)) | s ∈ dom(Δ1 ) ∩ dom(Δ2 )} ∪ Δ1 \dom(Δ2 ) ∪ Δ2 \dom(Δ1 ) The typing rules for runtime are listed in Fig. 6. (Label) types a label in a queue, while (Queue) forms a sequence of the types of the values in a queue: we ensure the disjointness of session environments of values, and apply a weakening for end (Σ0 ) for closure under the structure rules. (Par) composes processes, including queues, and records the session usage by ; this rule subsumes (Par) for programs. (News ) is the main rule for typing the two endpoint queues of a session. Types S1 and S2 can be given to the queues s and s when the session remainders S1 and S2 of S1 − τ1 and S2 − τ2 are dual session types up to asynchronous subtyping; more precisely, S1 must be a subtype of the dual of S2 , written S1 c S2 . Since the session is compatible, we can restrict s. Note that in all runtime systems, the set of linear variables is empty.
214
D. Mostrous and N. Yoshida
/ 0/ l : l Γ; 0; (News )
if τi = U → T then Σi = 0/ Γ; Σi ; 0/ hi : τi i ∈ 1..n Σ0 = {s : end} Γ; (Σ0 , .., Σn ) s : τ1 ..τn ; 0/ s : h1 ..hn :
(Queue)
(Label)
Γ; Δ, s : (S1 , τ1 ), s : (S2 , τ2 ); 0/ P : Si −τi = Si Γ; Δ; 0/ (ν s)P :
i ∈ 1, 2
(Par)
Γ; Δ1,2 ; L1,2 P1,2 :
Γ; Δ1 Δ2 ; L1 , L2 P1 | P2 :
S1 c S2
(New)
Γ, a : S ; Δ; L P :
Γ; Δ; L (ν a : S )P :
Fig. 6. Runtime Typing
4.3 Typing the Optimised Mobile Business Protocol Using the program and runtime typing systems, we can now type the hotel booking example in § 2.2, in the presence of asynchronous optimisation for higher-order mobility. Agent and standard Client can be typed with: SAgent =![int].&[move :?[unit ].SAgent , local : SAgent ]
with
=?[string].?[string].![double].?[int].end and SAgent
Sclient = SAgent
We then type MClient by using the rules in Fig. 5 and [11]. SMClient = ⊕[move :![unit ].![string].![string].![int].?[int].?[double].end] Applying Def. 3.2 we verify that SMClient c SAgent (and SMClient c SClient ). Then using typing rules (Acc,Req) we can type both MClient and Agent with a : SAgent ∈ Γ, after applying (Sub) on the premises of (Req) typing the body of MClient. We now demonstrate runtime typing; after three reduction steps of MClient | Agent we can have this configuration: (νs)( s {move : s?(code).(run code | . . .), local : . . .} | s:rtt | s:move·s!ritz . . . ) with s as the Agent’s queue. Both queues contain values including the linear higherorder code sent by MClient (which became 0 after this output). Using (Queue, Label) we type s:move·s!ritz . . . with session environment {s : SMClient , s : move · unit } where SMClient comes from typing the HO code containing s, and: =![string].![string].![int].?[int].?[double].end SMClient
and similarly we type s : rtt with {s : int}. The Agent s {move : . . . , local : . . .} (Bra) under session environment is typed with s : &[move :?[unit ].SAgent , local : SAgent ] . The above session environments can be synthesised using to obtain: , int), s : (&[move :?[unit ].SAgent , local : SAgent ], move · unit ) s : (SMClient Now we use the rules in § 4.2 to calculate the session remainder of each queue: SMClient − int =![string].![string].![int].?[double].end &[move :?[unit ].SAgent , local : SAgent ] − move · unit = SAgent
Session-Based Communication Optimisation for Higher-Order Mobile Processes
215
and we have ![string].![string].![int].?[double].end c SAgent . Finally, we can apply (News ) and complete the derivation. We can also check that the similar example in § 1, s!s?(x).s!x.s?(z1 ).s?(z2 ).0, is untypable since we cannot compose the session environments which include s both in the sent thunk and in the continuation.
5 Communication Safety and Algorithmic Subtyping 5.1 Type Soundness and Communication Safety This section studies the key properties of our typing system. First we show that typed processes enjoy subject reduction and communication safety. We begin by introducing balanced environments which specify the conditions of composable environments of runtime processes. Definition 5.1 (Balanced Δ). balanced(Δ) holds if whenever {s : (S1 , τ1 ), s : (S2 , τ2 )}⊆ Δ with S1 −τ1 = S1 and S2 −τ2 = S2 , then S1 c S2 . The definition is based on (News ) in the runtime typing system (Fig. 6): intuitively, all subprocesses generated from an initial typable program should conform to the balanced condition. We next define the ordering between the session environments which abstractly represents an interaction at session channels. Definition 5.2 (Δ Ordering). Recall defined in § 4.2. We define Δ s Δ as follows: s :?[U].S s : Uτ s s : S s :τ s :![U].S s :τ s s : S s :τU
s : &[li : Si ]i∈I s : lkτ s s : Sk s :τ k ∈ I s : ⊕[li : Si ]i∈I s :τ s s : Sk s :τlk k ∈ I
s : µt.S s :τ s s : S s :τ if s : S[µt.S/t] s :τ s s : S s :τ Δ Δ1 s Δ Δ2 if Δ1 s Δ2 and Δ Δ1 defined Note that if Δ1 s Δ2 and Δ Δ1 is defined, then Δ Δ2 is defined; and if balanced(Δ) and Δ s Δ then balanced(Δ ). Then by the standard substitution lemmas, we have: Theorem 5.3 (Type Soundness) 1. Suppose Γ; Δ; L P : . Then P ≡ P implies Γ; Δ; L P : . 2. Suppose Γ; Δ; 0/ P : T with balanced(Δ). Then P −→ P implies Γ; Δ ; 0/ P : T and either Δ = Δ or Δ s Δ . We now formalise communication-safety (which subsumes the usual type-safety). First, an s-queue is a queue process s :h. An s-input is a process of the shape s?(x).P or s {li : Pi }i∈I . An s-output is a process s!V .P or s l.P. Then, an s-process is an s-queue, s-input or s-output. Finally, an s-redex is a parallel composition of either an s-input and non-empty s-queue, or an s-output and s-queue. Definition 5.4 (Error Process). We say P is an error if P ≡ (νa)(νs)(Q | R) where Q is one of the following: (a) a |-composition of two s-processes that does not form either an s-redex or an s-input and an empty s-queue; (b) an s-redex consisting an s-input and s-queue such that Q = s?(x).Q | s : lkh or Q = s {li : Pi }i∈I | s : Vh; (c) an s-process for s ∈ s with s not free in R or Q; (d) a prefixed process or application containing an s-queue.
216
D. Mostrous and N. Yoshida
The above says that a process is an error if (a) it breaks the linearity of s by having e.g. two s-inputs in parallel; (b) there is communication-mismatch; (c) there is no corresponding opponent process for a session; or (d) it encloses a queue under prefix, thus making it unavailable. As a corollary of Theorem 5.3, we achieve the following general communication-safety theorem, subsuming the case that P is an initial program. Theorem 5.5 (Communication Safety). If Γ; Δ; L P : with balanced(Δ), then P never reduces into an error. 5.2 Algorithmic Higher-Order Asynchronous Subtyping This subsection proposes an algorithmic subtyping, extending the method from [12, § 3]. While the inclusion of the higher-order sessions and functional types complicates the proof of soundness, the basic idea of the rules and proofs stays as before. First we ! prove the decidability of S S , introducing the rewriting rule S → S which moves ⊕ the output action to the head (using in the reverse direction). Similarly for S → S . ! For a simple example, let S0 = &[l1 :?[U1 ].![U2 ].end, l2 :![U2 ].end]. Then S0 → &[l1 : !
![U2 ].?[U1 ].end, l2 :![U2 ].end] →![U2 ].&[l1 :?[U1 ].end, l2 : end] by applying (OI, OB) in !
⊕
Fig. 4 in the reverse direction. Since → and → terminate, and S S can be decomposed π π into a finite sequence of S →1 · · · →n S (n ≥ 0) with πi ∈ {!, ⊕}, the decidability of is straightforward. Using this relation, we can define the derivability of judgement Σ T T where Σ is a sequence of assumed goals in the subtyping derivation. We list only the key output rule which is used together with the standard output rule [5,4]: (Out)
Σ ![U1 ].S1 ![U2 ].T [S2h ]h∈H
!
T [![U2 ].S2h ]h∈H →![U2 ].T [S2h ]h∈H Σ ![U1 ].S1 T [![U2 ].S2h ]h∈H
S1 1 T [S2h ]h∈H
where T [Sh ]h∈H represents a h-hole context; and T 1 T means that T and T have the same session constructors under matching recursions; and labels in each type are ! distinct. This rule reads: we fix the subtype and apply → to place ![U2 ] to the head; then we can use the standard output rule. As an example, let S1 = &[l1 :?[U1 ].end, l2 : end]. Then we can derive ![U2 ].S1 S0 (S0 is given above) by using (Out). The algorithm is applied to the initial goal 0/ T T . Then using the same method developed in [12,5], we can prove the subtyping algorithm always terminates. We conclude this section with the following theorem (see [1]): Theorem 5.6 (Soundness and Completeness of the Algorithmic Subtyping). For all closed types T and T with T 1 T , T c T if and only if 0/ T T .
6 Related and Future Work The asynchronous subtyping has been firstly studied in [12] for multiparty session types [8]; this work does not support neither higher-order sessions (delegations) nor code mobility (higher-order functions). Both of these features provide powerful abstractions for structured distributed computing; delegation is the key primitive in our implementation of session types in Java [9] and web service protocols [17,18], to which we
Session-Based Communication Optimisation for Higher-Order Mobile Processes
217
can now apply our theory for flexible optimisation. The proof of the transitivity in this paper requires more complex construction of the transitive closure trc(ℜ1 , ℜ2 ) (Definition 3.4) than the one in [12] due to the higher-order constructs. In spite of the richness of the type structures, we proposed more compact runtime typing and proved communication safety in the presence of higher-order code, which is not presented in [12]. Note that our new typing system subsumes the previous linear typing system in [11], demonstrating a smooth integration of two kinds of type-directed optimisation. Coinductive subtyping of recursive session types is first studied in [5], adapting the standard methods for the IO-subtyping in the π-calculus [14]. The system of [5] does not provide any form of asynchronous permutation, thus does not need the nested ntimes unfolding (Definition 3.1). Our transitivity proof and the algorithmic subtyping are more involved than [5] due to the incorporation with n-time unfolding and higherorder functions. Our treatment of runtime typing, specifically our method for typing session queues and the use of session remainders, is more compact than previous asynchronous session works [8,2,3] where they use the method of rolling-back messages – the head type of a queue typing moves to the prefix of the session type of a process using the queue, and then compatibility is checked on the constructed types. Our method is simpler, as we remove type elements appearing in a queue from its typing. On the other hand, our queue typing is more similar to that of the functional language in [6], where smaller types are obtained after matching with buffer values. Our method works with queue types rather than with values directly, hence it can be extended smoothly to handle asynchronous optimisation, which is not treated in [6]. For example we allow a type consisting an output followed by an input action to be reduced with a type corresponding to the input, leaving the output prefix intact. Using a more delicate composition between values and queue typing, our system enables linear mobile code to be stored in the queues. We intend to integrate the improved methods from this work back to our original subtyping method for multiparty sessions [12], extending it to higher-order multiparty sessions. Another direction is progress [2], by which we mean deadlock-free execution of multiple interleaved sessions: in the presence of higher-order code mobility, this extension is challenging since it requires tracking dependencies inside mobile code. For example, if s!P is blocked, the sessions inside P are also blocked. On the other hand, we postulate that asynchronous subtyping does not introduce deadlock to a deadlock-free supertype, as outputs and selections can only be done in advance (partial commutativity), satisfying even stricter input dependencies than those required by the dual session of the supertype.
References 1. On-line Appendix of this paper, http://www.doc.ic.ac.uk/˜mostrous/hopiasync 2. Bettini, L., Coppo, M., D’Antoni, L., De Luca, M., Dezani-Ciancaglini, M., Yoshida, N.: Global progress in dynamically interleaved multiparty sessions. In: van Breugel, F., Chechik, M. (eds.) CONCUR 2008. LNCS, vol. 5201, pp. 418–433. Springer, Heidelberg (2008) 3. Bonelli, E., Compagnoni, A.: Multipoint Session Types for a Distributed Calculus. In: Barthe, G., Fournet, C. (eds.) TGC 2007. LNCS, vol. 4912, pp. 240–256. Springer, Heidelberg (2008)
218
D. Mostrous and N. Yoshida
4. Carbone, M., Honda, K., Yoshida, N.: Structured Communication-Centred Programming for Web Services. In: De Nicola, R. (ed.) ESOP 2007. LNCS, vol. 4421, pp. 2–17. Springer, Heidelberg (2007) 5. Gay, S., Hole, M.: Subtyping for Session Types in the Pi-Calculus. Acta Info. 42(2/3), 191– 225 (2005) 6. Gay, S., Vasconcelos, V.T.: Linear type theory for asynchronous session types (October 2008) (submitted for publication) 7. Honda, K., Vasconcelos, V.T., Kubo, M.: Language Primitives and Type Disciplines for Structured Communication-based Programming. In: Hankin, C. (ed.) ESOP 1998. LNCS, vol. 1381, pp. 22–138. Springer, Heidelberg (1998) 8. Honda, K., Yoshida, N., Carbone, M.: Multiparty Asynchronous Session Types. In: POPL 2008, pp. 273–284. ACM Press, New York (2008) 9. Hu, R., Yoshida, N., Honda, K.: Session-Based Distributed Programming in Java. In: Vitek, J. (ed.) ECOOP 2008. LNCS, vol. 5142, pp. 516–541. Springer, Heidelberg (2008) 10. Milner, R.: Functions as processes. MSCS 2(2), 119–141 (1992) 11. Mostrous, D., Yoshida, N.: Two Session Typing Systems for Higher-Order Mobile Processes. In: Della Rocca, S.R. (ed.) TLCA 2007. LNCS, vol. 4583, pp. 321–335. Springer, Heidelberg (2007) 12. Mostrous, D., Yoshida, N., Honda, K.: Global principal typing in partially commutative asynchronous sessions. In: Castagna, G. (ed.) ESOP 2009. LNCS, vol. 5502, pp. 316–332. Springer, Heidelberg (2009), www.doc.ic.ac.uk/˜mostrous/asyncsub 13. The Message Passing Interface (MPI) standard, http://www-unix.mcs.anl.gov/mpi/ usingmpi/examples/intermediate/main.htm 14. Pierce, B.C., Sangiorgi, D.: Typing and subtyping for mobile processes. In: Logic in Computer Science (1993); Full version in Mathematical Structures in Computer Science 6(5) (1996) 15. Sangiorgi, D.: Expressing Mobility in Process Algebras: First-Order and Higher Order Paradigms. PhD thesis, University of Edinburgh (1992) 16. Takeuchi, K., Honda, K., Kubo, M.: An Interaction-based Language and its Typing System. In: Halatsis, C., Philokyprou, G., Maritsas, D., Theodoridis, S. (eds.) PARLE 1994. LNCS, vol. 817, pp. 398–413. Springer, Heidelberg (1994) 17. UNIFI. International Organization for Standardization ISO 20022 UNIversal Financial Industry message scheme (2002), http://www.iso20022.org 18. Web Services Choreography Working Group. Web Services Choreography Description Language, http://www.w3.org/2002/ws/chor/ 19. Yoshida, N.: Channel dependency types for higher-order mobile processes. In: POPL 2004, pp. 147–160. ACM Press, New York (2004), www.doc.ic.ac.uk/˜yoshida 20. Yoshida, N., Vasconcelos, V.T.: Language Primitives and Type Disciplines for Structured Communication-based Programming Revisit. In: SecRet 2006. ENTCS, vol. 171(3), pp. 127– 151. Elsevier, Amsterdam (2007)
The Cut-Elimination Theorem for Differential Nets with Promotion Michele Pagani Laboratoire Preuves, Programmes et Syst`emes Universit´e Paris Diderot – Paris 7 & Dipartimento di Informatica Universit` a degli Studi di Torino http://www.di.unito.it/~pagani
Abstract. Recently Ehrhard and Regnier have introduced Differential Linear Logic, DiLL for short — an extension of the Multiplicative Exponential fragment of Linear Logic that is able to express non-deterministic computations. The authors have examined the cut-elimination of the promotion-free fragment of DiLL by means of a proofnet-like calculus: differential interaction nets. We extend this analysis to exponential boxes and prove the Cut-Elimination Theorem for the whole DiLL: every differential net that is sequentializable can be reduced to a cut-free net.
Introduction The cut-elimination procedure has been invented by Gentzen in order to prove consistency of classical logic and Peano Arithmetics. First, he introduced the sequent calculus LK, a proof system sound and complete with respect to classical logic. In this system there is just one deductive rule – the cut – which might prove absurdity, so that consistency can be deducted from the redundancy of such rule. In order to achieve it, Gentzen defined then cut-elimination, a procedure transforming a proof π into another one π of the same theorem where however cuts in π are in “some sense” reduced. Redundancy of the cut rule is then obtained by proving that iterating this procedure always terminates to a cutfree proof – the Cut-Elimination Theorem. Through the time the procedure of cut-elimination has acquired more and more importance in proof theory, also independently from the question of consistency. In particular in the 60’s, cut-elimination revealed a deep nexus between logic and computer science, enabling a correspondence between the execution of programs and the cut-elimination of proofs. This correspondence is called the Curry-Howard correspondence, and allows to express termination properties of programming languages as cut-elimination theorems in specific proof systems.
Supported by a post-doc fellowship of R´egion ˆIle de France and Italian MIUR Project “CONCERTO”.
P.-L. Curien (Ed.): TLCA 2009, LNCS 5608, pp. 219–233, 2009. c Springer-Verlag Berlin Heidelberg 2009
220
M. Pagani
Linear logic (LL, [Gir87]) has been build around cut-elimination: it splits the connectives ”and”, ”or” of LK in two classes (the multiplicatives ⊗, , and the additives &, ⊕) depending on their behavior during cut-elimination, and it introduces a new pair of dual connectives (the exponentials !, ?) giving a logical status to the actions of erasing and duplicating whole pieces of a proof. Linear logic allows to express cut-elimination as a rewriting of proof nets – specific graphs that give a sharper account of cut-elimination than LK. Indeed the proof nets drastically decrease the types of commutative cuts, abounding instead in sequent calculus. In the syntax of proof nets the commutative cuts are due to the boxes – special hyper-edges representing the sequent rules of LL that have some restriction on the context (i.e. promotion, additive conjunction and universal quantification)1 . A particular feature of these cuts is that they can be profoundly affected by the reduction of other cuts, even changing their commutative nature: this may considerably muddle the picture (see [PTdF07] for a more detailed discussion). As far as one restricts to the box-free fragment of LL, the cut-elimination is easily tamable, the reduction of a cut does not affect that of the others and a parallel reduction can be defined straightforwardly. Starting from this remark, Lafont has introduced interaction nets [Laf90] – a graph-rewriting paradigm of distributed computation based on the box-free fragment of the proof nets. The discovery of LL and proof nets has been a fundamental step towards the extension of the Curry-Howard correspondence, that was at the beginning restricted to the functional and sequential core of the programming languages. In particular Ehrhard and Regnier [ER06] have recently achieved a significant step towards a logical understanding of concurrency theory with the introduction of differential linear logic (DiLL). This system extends linear logic with three new rules handling the ! modality (codereliction, cocontraction and coweakening) and allows to express a concurrent sharing of resources [EL08]. The codereliction in particular creates data that can be called exactly once, so that a program made of several subroutines is executed non-deterministically on ”coderelicted” inputs, depending on which subroutine gains the unique available copy of the inputs. Thus we have formal sums, where each addendum represents a possibility. The cut-elimination of DiLL is analyzed with a proofnet-like calculus, called differential nets. Actually, [ER06] considers only the promotion-free fragment of DiLL, whose nets are without boxes and called differential interaction nets, being a non-deterministic example of Lafont’s interaction nets. In that restricted setting the authors prove the Cut-Elimination Theorem. In our paper, we extend their result to the whole DiLL, using differential nets with exponential boxes. The main difficulty in such an extension is to account for the exponential commutative cuts, and specifically for the commutative cut between a codereliction and a box, which has a completely non-standard behavior with respect to the commutative cuts in linear logic proof nets (see the discussion on Figure 6). 1
In this paper, indeed, we consider only the exponential boxes. Up to now, differential nets are restricted to the multiplicatives and exponentials; besides, there are specific notions of LL proof nets able to avoid the boxes for additives and quantifiers.
The Cut-Elimination Theorem for Differential Nets with Promotion
A, A
⊥
Γ, A A⊥ , Δ Γ, Δ
ax
Γ, A, B Γ, A ` B Γ Γ, ?A
!A Γ
0
Γ, A B, Δ Γ, A ⊗ B, Δ
`
Γ, ?A, ?A Γ, ?A
?w
Γ, A Γ, ?A
?c
Γ, !A !A, Δ Γ, !A, Δ
!w
Γ Γ Γ
sum
Γ, A, B, Δ Γ, B, A, Δ
cut
empty
ex
⊗
?Γ, A ?Γ, !A
?d
Γ, A Γ, !A
!c
221
p
!d
Γ Δ Γ, Δ
mix
Fig. 1. Sequent calculus rules for differential linear logic
1 1.1
Preliminaries Differential Nets
We recall differential nets and their cut-elimination: first, we introduce the promotion-free nets, called differential interaction nets in [ER06], then we add boxes to accommodate promotion. In the sake of brevity, the presentation is kept informal, and we refer to [ER06,Vau07] for a more detailed one. We denote sets with braces { }, and sequences by angles . Boldface letters a, b etc. range over sequences, and for i ≤ length(a), ai denotes the i-th element of a. Types of DiLL. The formulas of DiLL are generated by the following grammar, where X, X ⊥ range over a fixed set of propositional variables: A, B ::= X | X ⊥ | A ⊗ B | A
B | !A | ?A.
Linear negation is involutional (A⊥⊥ = A) and defined through De Morgan laws: (X)⊥ := X ⊥ , (A ⊗ B)⊥ := A⊥ B ⊥ , (!A)⊥ := ?A⊥ . Variables and their negations are atomic, ⊗, are multiplicative, while !, ? are exponential. For brevity, we omit to consider multiplicative units 1, ⊥, however all the results in this paper can be extended to the general case straightforwardly. A sequent Γ is a finite sequence of formulas A1 , . . . , An . Capital Greek letters Γ, Δ range over sequents. Fig. 1 gives the rules of DiLL sequent calculus. The calculus is extended with the rule mix and its zeroary version empty— this is needed to have a fair correctness criterion (Prop. 1). Differential interaction nets. A simple interaction net α is the union of a graph and an hyper-graph on a given set of nodes, respecting the following constraints (see Figure 5(a) for examples). – The nodes of α are called ports, they are crossed exactly by one edge and at most by one hyper-edge. In the figures, the ports are not explicitly depicted, as they correspond to the extremities of the edges.
222
M. Pagani
B
B
` A
A`B
A
!A
B
⊗
A⊗B
?w A
?A
A !A
?A
?d
?A
?A
!A
B
?c
?A
!w A
!A
A !A
!A
!d
!A
!c !A
!A
Fig. 2. Cells for differential interaction nets, together with their typing rules
– The edges of α are called wires, they are undirected, possibly loops; a wire {a, b} between two distinct ports a, b has two orientations: from a to b, denoted a, b, and from b to a, denoted b, a; with each orientation is associated a formula of DiLL in such a way that the formula associated with a, b must be the linear negation of the formula associated to b, a.2 – The hyper-edges of α are called cells, and they are sequences of the ports they cross; the first port crossed by a cell is called principal, the other ones (if any) are called auxiliary; every cell is labelled by a symbol that determines the arity of the cell and the types of the wires incident to it, as it is depicted in Figure 2. We require also that cells are not incident to loops. The type of a port a of α is the type of b, a, where {a, b} is the unique wire of α crossing a; in particular this means that the ports connected by a wire have dual types. The ports of α which are crossed by no cell nor loop, are called free. We require that α is given with an enumeration p of its free ports, called the interface of α. The sequent conclusion of α is Γ = A1 , . . . , An , where n is the length of p and for every i ≤ n, Ai is the type of pi . A differential interaction net with sequent conclusion Γ is a finite multiset3 , possibly empty, of simple interaction nets with the conclusion Γ . The loops must be admitted, as they can be produced by cut-elimination. However, they do not appear in the differential nets that are sequentializable, and so they are voluntarily left out of the discussion the most of times. Adding boxes. Boxes are a special kind of cells parameterized by a net, this last one standing for a proof of the premise of the corresponding promotion rule. Formally, the sets dN of differential nets and sN of simple nets are defined simultaneously, by induction on the exponential depth. This means that we define sNd and dNd for every d ∈ N and then we set: sN :=
∞ d=0
sNd ,
dN :=
∞
dNd .
d=0
sN0 (resp. dN0 ) is the set of the simple interaction nets (resp. differential 2 3
Loops are intentionally considered untyped. In a general setting, differential nets are finite linear combinations of simple nets with coefficients in a commutative semiring R with units. In this paper however we will consider only the case R = N, and in such a case the differential nets are the finite multisets of simple nets.
(a) a box
!A
?Cn ?C1
P ?Cn
···
?Cn
!π
···
?Cn
···
The Cut-Elimination Theorem for Differential Nets with Promotion
β∈π ?C1
β
A
223
!A
(b) a box with its contents inside
Fig. 3. A box of type !π can be also presented with its contents depicted inside
interaction nets). A simple net of sNd+1 is a simple net α defined from the cells of Fig.2 and 3(a), such that every box o of α is labelled by a symbol !π, where π is a differential net of dNd , called the contents of o. Moreover, together with o it is given a fixed correspondence between the free ports of every simple net β ∈ π and the ports of o: for every port a of o we denote by aβ the correspondent free port of β. This correspondence enjoys the typing conditions sketched in Fig.3(b). A differential net π of dNd with sequent conclusion Γ is a finite multiset, possibly empty, of simple nets of sNd with sequent conclusion Γ . Initial Greek letters α, β, γ (resp. final Greek letters π, σ, ρ) range over simple nets (resp. differential nets). We use the additive notation for multisets: 0 is the empty multiset, π + σ is the disjoint union of π and σ (repetition does matter); a differential net π can also be written as α∈π α. The depth of a simple net α (resp. differential net π) is the minimal d such that α ∈ sNd (resp. π ∈ dNd ). Many definitions are done by induction on the depth: let us skip to mention it explicitly, when evident. So, we say that a cell/wire w is at depth d of a differential net π, denoted w ∈d π, whenever w ∈d α for a simple net α of π; and we say that w ∈d α whenever either d = 0 and w is a cell/wire of α, view as an interaction net, or there is a box !ρ ∈0 α and w ∈d−1 ρ. We write w ∈! π meaning w ∈d π for a d ∈ N. Switching acyclicity. Every proof in the sequent calculus of DiLL can be translated in a differential net with the same sequent conclusion. This translation is defined by induction on the size of the proof and can be easily deduced from the sequent rules of Figure 1. The translation is not surjective (neither injective) over dN and we call sequentializable the differential nets that are images of it. Purely graph-theoretical conditions, called correctness criteria, have been presented in order to characterize the set of sequentializable differential nets. We give here one among the most celebrated of such correctness criteria, switching acyclicity, presented originally by Danos and Regnier [DR89] for the multiplicative fragment of linear logic, and then extended to DiLL in [ER06].4 A switching of a cell c is an undirected graph σ whose nodes are the ports of c and whose edges are defined depending on the label of c: in case c is of type or ?c, σ has exactly one edge, crossing the principal port and one chosen auxiliary port of c (so c has two possible switchings); otherwise σ is unique and it has one edge for each auxiliary port of c, if any, wiring that port to the principal 4
To be precise, [ER06] introduces switching acyclicity in the promotion-free fragment of DiLL, however its generalization to exponential boxes is straightforward.
224
M. Pagani
one. A correctness graph of a simple net α is an undirected graph σ having as nodes the ports of α and as edges the wires of α plus the edges obtained substituting every cell with one among its switchings. A differential net π is switching acyclic if every simple net of π is switching acyclic; a simple net α is switching acyclic if every correctness graph of α is an acyclic graph and for every box !ρ ∈0 α, ρ is switching acyclic. Proposition 1. A differential net π is sequentializable iff it is switching acyclic. Proof. Standard generalization of the technique developed in [DR89,Dan90]. 1.2
Cut-Elimination
A port is active whenever it is the principal port of a cell or it is an auxiliary port of a box. A cut is a wire connecting two active ports. A differential net is cut-free if it has no cut at any depth. The reader should notice the difference with respect to the differential interaction nets: in that restricted setting the only active ports are the principal ones. Exponential boxes add commutative cuts, that are wires between the principal port of a cell and an auxiliary port of a box. Interaction. We denote αa the pair of a simple net and a sequence a of the free ports of α. Let αa and β b be such that a and b have the same length n and for every i ≤ n, ai and bi have dual types, we call the interaction between αa and β b the simple net αa |β b obtained by equaling for every i ≤ n the port ai of α with the port bi of β, and then by merging the wires that have a port in common5 :
αa
βb
... ... ... ... bn :A⊥ a1:A1 an:An b1:A⊥ n 1
:=
αa ...
An
...
βb ...
...
A1
We can omit the superscripts a, b if they are clear or unimportant. The writing αaa |β b , γ c means αa |β b a |γ c , where a and a are sequences of distinct free ports of α with the lengths and the dual types of resp. b and c. Interaction is extended to differential nets by bilinearity: b αa βjb = αa i | i |βj . i≤l
j≤m
i≤l j≤m
Reductions. Let R be a binary relation over differential nets with the same sequent conclusion, the context closure of R is the smallest relation R◦ s.t. 5
Although intuitively clear, the operation of merging wires should be handled with care because each of the two interfaces a and b may contains pairs of ports wired together and then loops can be produced. We refer to [Vau07] for a formal definition.
The Cut-Elimination Theorem for Differential Nets with Promotion
225
P !d
!d/p
!π
−−→
?c
?c
$/?c
−−−→
?c
$
?c ?c
β∈π
∗d
∗d/∗c
−−−→
∗w
$ ···
α
∗c
···
$
∗d
···
P
α∈π
!d/?d
−−−→
?d
···
−−→
!d
··· ···
$/p
!π
··· ···
···
∗w/∗d −−−→ 0
$
$
!d !c
?w
β
+
∗w
∗d
$/?w
−−−→
?w ···
$
∗d
···
···
∗w
α
P !w ···
!d
− −− → π p/?d
?d
···
−−−→
!π
···
···
⊗/`
···
`
⊗
···
α∈π
?w
Fig. 4. Elementary reduction steps (ers) for differential nets, where ∗ (resp. ∗) is ? (resp. !) or ! (resp. ?), and $ is !w, or !c, or !π. In the !w/?w ers the contractum is the empty graph.
– R◦ is closed by sum: πR◦ π implies (π + ρ)R◦ (π + ρ), for ρ ∈ dN; and – R◦ is closed by interaction: πR◦ π implies α|πR◦ α|π , for α ∈ sN; and – R◦ is closed by promotion: πR◦ π implies !πR◦ !π . In Figure 4 we define specific relations called elementary reduction steps, ers for short. The net at left of an ers is the redex, that at right the contractum R of the ers. For any union R among them we define a reduction, denoted − →, as the R∗ R →. context closure of R. We write by −→ the reflexive and transitive closure of − cut In particular, we define the cut-elimination −−→ as the context closure of the e whole Figure 4, and the exponential reduction − → as the context closure of all the ers of Figure 4 but the ⊗/ ers. We say that a differential net π enjoys the cut∗ cut-elimination if there is a cut-free differential net π0 such that π −−−→ π0 . Notice that the redex of every ers in Fig. 4 is a simple net; also the contractum is simple except for !w/?d, !d/?w, !d/?c, !c/?d, !d/p, and p/?d. In particular !w/?d and its symmetric !d/?w yield the empty sum 0. Also the steps !d/p and p/?d yield 0, in case the content of !π is 0. Proposition 2. Let π −−→ π . If π is switching acyclic, then so it is π . cut
Proof. [ER06] gives the proof for the box-free case: the generalization is easy.
!X
?c
!X
!c
?X ⊥ !c/?c
−−−→
!X
!c
(a)
?c
!X
!c
?c
?X ⊥ !c/?c
−−−→ · · · (b)
Fig. 5. A simple net not enjoying cut-elimination, nor switching acyclicity
226
M. Pagani X !d
!d
!X
?c
!X ?d
?d !X
!w
!d
!w
!d
?c
!!X
+ p/?c
− −− →
?d
(a)
?d
!d/?c
−−−→
?d
?d
(b)
?d
?d
(c)
!d !d
!w
!d
− −− →
?d
!w
!c
+ ··· p/?d
!d/p
?d
−−→
(d)
X
+ ... !w
(e)
!d cut∗
−−→
!X
X
+
!w
!X
!w
!X
!d
!X
(f)
Fig. 6. Example of a reduction to a cut-free differential net
Examples. Figure 5 depicts a (typed) simple net not enjoying cut-elimination nor switching acyclicity (Figure 5(b) gives its cyclic correctness graph): as known, switching acyclicity is an hypothesis needed to prove6 cut-elimination. Notice that replacing the !c-cell of Fig. 5(a) with a box gives a counter-example to the cut-elimination for switching cyclic LL nets. Figure 6 gives an example of reduction from the (switching acyclic) simple net in Fig. 6(a) to the cut-free differential net in Fig. 6(f); by the way, notice that the sequent conclusion X ⊥ , !X, !X is provable in DiLL but not in LL. Let us comment p/?c
the main ers. In the s