Category Theory and Lambda Calculus

Total Page:16

File Type:pdf, Size:1020Kb

Category Theory and Lambda Calculus Category Theory and Lambda Calculus Mario Román García Trabajo Fin de Grado Doble Grado en Ingeniería Informática y Matemáticas Tutores Pedro A. García-Sánchez Manuel Bullejos Lorenzo Facultad de Ciencias E.T.S. Ingenierías Informática y de Telecomunicación Granada, a 18 de junio de 2018 Contents 1 Lambda calculus 13 1.1 Untyped λ-calculus . 13 1.1.1 Untyped λ-calculus . 14 1.1.2 Free and bound variables, substitution . 14 1.1.3 Alpha equivalence . 16 1.1.4 Beta reduction . 16 1.1.5 Eta reduction . 17 1.1.6 Confluence . 17 1.1.7 The Church-Rosser theorem . 18 1.1.8 Normalization . 20 1.1.9 Standardization and evaluation strategies . 21 1.1.10 SKI combinators . 22 1.1.11 Turing completeness . 24 1.2 Simply typed λ-calculus . 24 1.2.1 Simple types . 25 1.2.2 Typing rules for simply typed λ-calculus . 25 1.2.3 Curry-style types . 26 1.2.4 Unification and type inference . 27 1.2.5 Subject reduction and normalization . 29 1.3 The Curry-Howard correspondence . 31 1.3.1 Extending the simply typed λ-calculus . 31 1.3.2 Natural deduction . 32 1.3.3 Propositions as types . 34 1.4 Other type systems . 35 1.4.1 λ-cube..................................... 35 2 Mikrokosmos 38 2.1 Implementation of λ-expressions . 38 2.1.1 The Haskell programming language . 38 2.1.2 De Bruijn indexes . 40 2.1.3 Substitution . 41 2.1.4 De Bruijn-terms and λ-terms . 42 2.1.5 Evaluation . 43 2.1.6 Principal type inference . 43 2.2 User interaction . 45 2.2.1 Monadic parser combinators . 45 2.2.2 Verbose mode . 46 2.2.3 SKI mode . 47 1 2.3 Usage . 48 2.3.1 Installation . 48 2.3.2 Mikrokosmos interpreter . 49 2.3.3 Jupyter kernel . 50 2.3.4 CodeMirror lexer . 50 2.3.5 JupyterHub . 53 2.3.6 Calling Mikrokosmos from Javascript . 53 2.4 Programming environment . 54 2.4.1 Cabal, Stack and Haddock . 54 2.4.2 Testing . 54 2.4.3 Version control and continuous integration . 56 2.5 Programming in untyped λ-calculus . 57 2.5.1 Basic syntax . 57 2.5.2 A technique on inductive data encoding . 58 2.5.3 Booleans . 58 2.5.4 Natural numbers . 59 2.5.5 The predecessor function and predicates on numbers . 60 2.5.6 Lists and trees . 60 2.5.7 Fixed points . 62 2.6 Programming in the simply typed λ-calculus . 63 2.6.1 Function types and typeable terms . 63 2.6.2 Product, union, unit and void types . 64 2.6.3 A proof in intuitionistic logic . 65 3 Category theory 67 3.1 Categories . 67 3.1.1 Definition of category . 67 3.1.2 Morphisms . 68 3.1.3 Products and sums . 69 3.1.4 Examples of categories . 70 3.2 Functors and natural transformations . 71 3.2.1 Functors . 71 3.2.2 Natural transformations . 72 3.2.3 Composition of natural transformations . 73 3.3 Constructions on categories . 75 3.3.1 Product categories . 75 3.3.2 Opposite categories and contravariant functors . 76 3.3.3 Functor categories . 77 3.4 Universality and limits . 78 3.4.1 Universal arrows . 78 3.4.2 Representability . 79 3.4.3 Yoneda Lemma . 79 3.4.4 Limits . 81 3.4.5 Examples of limits . 82 3.4.6 Colimits . 84 3.4.7 Examples of colimits . 85 3.5 Adjoints, monads and algebras . 86 3.5.1 Adjunctions . 86 3.5.2 Examples of adjoints . 90 2 3.5.3 Monads . 91 3.5.4 Algebras . 92 4 Categorical logic 95 4.1 Presheaves . 95 4.2 Cartesian closed categories and lambda calculus . 96 4.2.1 Lawvere theories . 96 4.2.2 Cartesian closed categories . 98 4.2.3 Simply-typed λ-theories . 99 4.2.4 Syntactic categories and internal languages . 100 4.3 Working in cartesian closed categories . 102 4.3.1 Diagonal arguments . 102 4.3.2 Bicartesian closed categories . 103 4.3.3 Inductive types . 104 4.4 Locally cartesian closed categories and dependent types . 105 4.4.1 Quantifiers and subsets . 105 4.4.2 Locally cartesian closed categories . 107 4.4.3 Dependent types . 109 4.4.4 Dependent pairs . 110 4.4.5 Dependent functions . 111 4.5 Working in locally cartesian closed categories . 112 4.5.1 Examples of dependent types . 112 4.5.2 Equality types . 114 4.5.3 Subobject classifier and propositions . 115 4.5.4 Propositional truncation . 115 4.6 Topoi . 116 4.6.1 Motivation . 116 4.6.2 An Elementary Theory of the Category of Sets . 117 5.
Recommended publications
  • Lecture Notes on the Lambda Calculus 2.4 Introduction to Β-Reduction
    2.2 Free and bound variables, α-equivalence. 8 2.3 Substitution ............................. 10 Lecture Notes on the Lambda Calculus 2.4 Introduction to β-reduction..................... 12 2.5 Formal definitions of β-reduction and β-equivalence . 13 Peter Selinger 3 Programming in the untyped lambda calculus 14 3.1 Booleans .............................. 14 Department of Mathematics and Statistics 3.2 Naturalnumbers........................... 15 Dalhousie University, Halifax, Canada 3.3 Fixedpointsandrecursivefunctions . 17 3.4 Other data types: pairs, tuples, lists, trees, etc. ....... 20 Abstract This is a set of lecture notes that developed out of courses on the lambda 4 The Church-Rosser Theorem 22 calculus that I taught at the University of Ottawa in 2001 and at Dalhousie 4.1 Extensionality, η-equivalence, and η-reduction. 22 University in 2007 and 2013. Topics covered in these notes include the un- typed lambda calculus, the Church-Rosser theorem, combinatory algebras, 4.2 Statement of the Church-Rosser Theorem, and some consequences 23 the simply-typed lambda calculus, the Curry-Howard isomorphism, weak 4.3 Preliminary remarks on the proof of the Church-Rosser Theorem . 25 and strong normalization, polymorphism, type inference, denotational se- mantics, complete partial orders, and the language PCF. 4.4 ProofoftheChurch-RosserTheorem. 27 4.5 Exercises .............................. 32 Contents 5 Combinatory algebras 34 5.1 Applicativestructures. 34 1 Introduction 1 5.2 Combinatorycompleteness . 35 1.1 Extensionalvs. intensionalviewoffunctions . ... 1 5.3 Combinatoryalgebras. 37 1.2 Thelambdacalculus ........................ 2 5.4 The failure of soundnessforcombinatoryalgebras . .... 38 1.3 Untypedvs.typedlambda-calculi . 3 5.5 Lambdaalgebras .......................... 40 1.4 Lambdacalculusandcomputability . 4 5.6 Extensionalcombinatoryalgebras . 44 1.5 Connectionstocomputerscience .
    [Show full text]
  • Arxiv:2011.02915V1 [Math.LO] 3 Nov 2020 the Otniy Ucin Pnst Tctr)Ue Nti Ae R T Are Paper (C 1.1
    REVERSE MATHEMATICS OF THE UNCOUNTABILITY OF R: BAIRE CLASSES, METRIC SPACES, AND UNORDERED SUMS SAM SANDERS Abstract. Dag Normann and the author have recently initiated the study of the logical and computational properties of the uncountability of R formalised as the statement NIN (resp. NBI) that there is no injection (resp. bijection) from [0, 1] to N. On one hand, these principles are hard to prove relative to the usual scale based on comprehension and discontinuous functionals. On the other hand, these principles are among the weakest principles on a new com- plimentary scale based on (classically valid) continuity axioms from Brouwer’s intuitionistic mathematics. We continue the study of NIN and NBI relative to the latter scale, connecting these principles with theorems about Baire classes, metric spaces, and unordered sums. The importance of the first two topics re- quires no explanation, while the final topic’s main theorem, i.e. that when they exist, unordered sums are (countable) series, has the rather unique property of implying NIN formulated with the Cauchy criterion, and (only) NBI when formulated with limits. This study is undertaken within Ulrich Kohlenbach’s framework of higher-order Reverse Mathematics. 1. Introduction The uncountability of R deals with arbitrary mappings with domain R, and is therefore best studied in a language that has such objects as first-class citizens. Obviousness, much more than beauty, is however in the eye of the beholder. Lest we be misunderstood, we formulate a blanket caveat: all notions (computation, continuity, function, open set, et cetera) used in this paper are to be interpreted via their higher-order definitions, also listed below, unless explicitly stated otherwise.
    [Show full text]
  • Lecture Notes on Types for Part II of the Computer Science Tripos
    Q Lecture Notes on Types for Part II of the Computer Science Tripos Prof. Andrew M. Pitts University of Cambridge Computer Laboratory c 2016 A. M. Pitts Contents Learning Guide i 1 Introduction 1 2 ML Polymorphism 6 2.1 Mini-ML type system . 6 2.2 Examples of type inference, by hand . 14 2.3 Principal type schemes . 16 2.4 A type inference algorithm . 18 3 Polymorphic Reference Types 25 3.1 The problem . 25 3.2 Restoring type soundness . 30 4 Polymorphic Lambda Calculus 33 4.1 From type schemes to polymorphic types . 33 4.2 The Polymorphic Lambda Calculus (PLC) type system . 37 4.3 PLC type inference . 42 4.4 Datatypes in PLC . 43 4.5 Existential types . 50 5 Dependent Types 53 5.1 Dependent functions . 53 5.2 Pure Type Systems . 57 5.3 System Fw .............................................. 63 6 Propositions as Types 67 6.1 Intuitionistic logics . 67 6.2 Curry-Howard correspondence . 69 6.3 Calculus of Constructions, lC ................................... 73 6.4 Inductive types . 76 7 Further Topics 81 References 84 Learning Guide These notes and slides are designed to accompany 12 lectures on type systems for Part II of the Cambridge University Computer Science Tripos. The course builds on the techniques intro- duced in the Part IB course on Semantics of Programming Languages for specifying type systems for programming languages and reasoning about their properties. The emphasis here is on type systems for functional languages and their connection to constructive logic. We pay par- ticular attention to the notion of parametric polymorphism (also known as generics), both because it has proven useful in practice and because its theory is quite subtle.
    [Show full text]
  • Plurals and Mereology
    Journal of Philosophical Logic (2021) 50:415–445 https://doi.org/10.1007/s10992-020-09570-9 Plurals and Mereology Salvatore Florio1 · David Nicolas2 Received: 2 August 2019 / Accepted: 5 August 2020 / Published online: 26 October 2020 © The Author(s) 2020 Abstract In linguistics, the dominant approach to the semantics of plurals appeals to mere- ology. However, this approach has received strong criticisms from philosophical logicians who subscribe to an alternative framework based on plural logic. In the first part of the article, we offer a precise characterization of the mereological approach and the semantic background in which the debate can be meaningfully reconstructed. In the second part, we deal with the criticisms and assess their logical, linguistic, and philosophical significance. We identify four main objections and show how each can be addressed. Finally, we compare the strengths and shortcomings of the mereologi- cal approach and plural logic. Our conclusion is that the former remains a viable and well-motivated framework for the analysis of plurals. Keywords Mass nouns · Mereology · Model theory · Natural language semantics · Ontological commitment · Plural logic · Plurals · Russell’s paradox · Truth theory 1 Introduction A prominent tradition in linguistic semantics analyzes plurals by appealing to mere- ology (e.g. Link [40, 41], Landman [32, 34], Gillon [20], Moltmann [50], Krifka [30], Bale and Barner [2], Chierchia [12], Sutton and Filip [76], and Champollion [9]).1 1The historical roots of this tradition include Leonard and Goodman [38], Goodman and Quine [22], Massey [46], and Sharvy [74]. Salvatore Florio [email protected] David Nicolas [email protected] 1 Department of Philosophy, University of Birmingham, Birmingham, United Kingdom 2 Institut Jean Nicod, Departement´ d’etudes´ cognitives, ENS, EHESS, CNRS, PSL University, Paris, France 416 S.
    [Show full text]
  • Computational Lambda-Calculus and Monads
    Computational lambda-calculus and monads Eugenio Moggi∗ LFCS Dept. of Comp. Sci. University of Edinburgh EH9 3JZ Edinburgh, UK [email protected] October 1988 Abstract The λ-calculus is considered an useful mathematical tool in the study of programming languages, since programs can be identified with λ-terms. However, if one goes further and uses βη-conversion to prove equivalence of programs, then a gross simplification1 is introduced, that may jeopardise the applicability of theoretical results to real situations. In this paper we introduce a new calculus based on a categorical semantics for computations. This calculus provides a correct basis for proving equivalence of programs, independent from any specific computational model. 1 Introduction This paper is about logics for reasoning about programs, in particular for proving equivalence of programs. Following a consolidated tradition in theoretical computer science we identify programs with the closed λ-terms, possibly containing extra constants, corresponding to some features of the programming language under con- sideration. There are three approaches to proving equivalence of programs: • The operational approach starts from an operational semantics, e.g. a par- tial function mapping every program (i.e. closed term) to its resulting value (if any), which induces a congruence relation on open terms called operational equivalence (see e.g. [Plo75]). Then the problem is to prove that two terms are operationally equivalent. ∗On leave from Universit`a di Pisa. Research partially supported by the Joint Collaboration Contract # ST2J-0374-C(EDB) of the EEC 1programs are identified with total functions from values to values 1 • The denotational approach gives an interpretation of the (programming) lan- guage in a mathematical structure, the intended model.
    [Show full text]
  • Continuation Calculus
    Eindhoven University of Technology MASTER Continuation calculus Geron, B. Award date: 2013 Link to publication Disclaimer This document contains a student thesis (bachelor's or master's), as authored by a student at Eindhoven University of Technology. Student theses are made available in the TU/e repository upon obtaining the required degree. The grade received is not published on the document as presented in the repository. The required complexity or quality of research of student theses may vary by program, and the required minimum study period may vary in duration. General rights Copyright and moral rights for the publications made accessible in the public portal are retained by the authors and/or other copyright owners and it is a condition of accessing publications that users recognise and abide by the legal requirements associated with these rights. • Users may download and print one copy of any publication from the public portal for the purpose of private study or research. • You may not further distribute the material or use it for any profit-making activity or commercial gain Continuation calculus Master’s thesis Bram Geron Supervised by Herman Geuvers Assessment committee: Herman Geuvers, Hans Zantema, Alexander Serebrenik Final version Contents 1 Introduction 3 1.1 Foreword . 3 1.2 The virtues of continuation calculus . 4 1.2.1 Modeling programs . 4 1.2.2 Ease of implementation . 5 1.2.3 Simplicity . 5 1.3 Acknowledgements . 6 2 The calculus 7 2.1 Introduction . 7 2.2 Definition of continuation calculus . 9 2.3 Categorization of terms . 10 2.4 Reasoning with CC terms .
    [Show full text]
  • 1 Simply-Typed Lambda Calculus
    CS 4110 – Programming Languages and Logics Lecture #18: Simply Typed λ-calculus A type is a collection of computational entities that share some common property. For example, the type int represents all expressions that evaluate to an integer, and the type int ! int represents all functions from integers to integers. The Pascal subrange type [1..100] represents all integers between 1 and 100. You can see types as a static approximation of the dynamic behaviors of terms and programs. Type systems are a lightweight formal method for reasoning about behavior of a program. Uses of type systems include: naming and organizing useful concepts; providing information (to the compiler or programmer) about data manipulated by a program; and ensuring that the run-time behavior of programs meet certain criteria. In this lecture, we’ll consider a type system for the lambda calculus that ensures that values are used correctly; for example, that a program never tries to add an integer to a function. The resulting language (lambda calculus plus the type system) is called the simply-typed lambda calculus (STLC). 1 Simply-typed lambda calculus The syntax of the simply-typed lambda calculus is similar to that of untyped lambda calculus, with the exception of abstractions. Since abstractions define functions tht take an argument, in the simply-typed lambda calculus, we explicitly state what the type of the argument is. That is, in an abstraction λx : τ: e, the τ is the expected type of the argument. The syntax of the simply-typed lambda calculus is as follows. It includes integer literals n, addition e1 + e2, and the unit value ¹º.
    [Show full text]
  • Lambda-Calculus Types and Models
    Jean-Louis Krivine LAMBDA-CALCULUS TYPES AND MODELS Translated from french by René Cori To my daughter Contents Introduction5 1 Substitution and beta-conversion7 Simple substitution ..............................8 Alpha-equivalence and substitution ..................... 12 Beta-conversion ................................ 18 Eta-conversion ................................. 24 2 Representation of recursive functions 29 Head normal forms .............................. 29 Representable functions ............................ 31 Fixed point combinators ........................... 34 The second fixed point theorem ....................... 37 3 Intersection type systems 41 System D­ ................................... 41 System D .................................... 50 Typings for normal terms ........................... 54 4 Normalization and standardization 61 Typings for normalizable terms ........................ 61 Strong normalization ............................. 68 ¯I-reduction ................................. 70 The ¸I-calculus ................................ 72 ¯´-reduction ................................. 74 The finite developments theorem ....................... 77 The standardization theorem ......................... 81 5 The Böhm theorem 87 3 4 CONTENTS 6 Combinatory logic 95 Combinatory algebras ............................. 95 Extensionality axioms ............................. 98 Curry’s equations ............................... 101 Translation of ¸-calculus ........................... 105 7 Models of lambda-calculus 111 Functional
    [Show full text]
  • E.W. Beth Als Logicus
    E.W. Beth als logicus ILLC Dissertation Series 2000-04 For further information about ILLC-publications, please contact Institute for Logic, Language and Computation Universiteit van Amsterdam Plantage Muidergracht 24 1018 TV Amsterdam phone: +31-20-525 6051 fax: +31-20-525 5206 e-mail: [email protected] homepage: http://www.illc.uva.nl/ E.W. Beth als logicus Verbeterde electronische versie (2001) van: Academisch Proefschrift ter verkrijging van de graad van doctor aan de Universiteit van Amsterdam op gezag van de Rector Magni¯cus prof.dr. J.J.M. Franse ten overstaan van een door het college voor promoties ingestelde commissie, in het openbaar te verdedigen in de Aula der Universiteit op dinsdag 26 september 2000, te 10.00 uur door Paul van Ulsen geboren te Diemen Promotores: prof.dr. A.S. Troelstra prof.dr. J.F.A.K. van Benthem Faculteit Natuurwetenschappen, Wiskunde en Informatica Universiteit van Amsterdam Plantage Muidergracht 24 1018 TV Amsterdam Copyright c 2000 by P. van Ulsen Printed and bound by Print Partners Ipskamp. ISBN: 90{5776{052{5 Ter nagedachtenis aan mijn vader v Inhoudsopgave Dankwoord xi 1 Inleiding 1 2 Levensloop 11 2.1 Beginperiode . 12 2.1.1 Leerjaren . 12 2.1.2 Rijpingsproces . 14 2.2 Universitaire carriere . 21 2.2.1 Benoeming . 21 2.2.2 Geleerde genootschappen . 23 2.2.3 Redacteurschappen . 31 2.2.4 Beth naar Berkeley . 32 2.3 Beth op het hoogtepunt van zijn werk . 33 2.3.1 Instituut voor Grondslagenonderzoek . 33 2.3.2 Oprichting van de Centrale Interfaculteit . 37 2.3.3 Logici en historici aan Beths leiband .
    [Show full text]
  • The Lambda Calculus Bharat Jayaraman Department of Computer Science and Engineering University at Buffalo (SUNY) January 2010
    The Lambda Calculus Bharat Jayaraman Department of Computer Science and Engineering University at Buffalo (SUNY) January 2010 The lambda-calculus is of fundamental importance in the study of programming languages. It was founded by Alonzo Church in the 1930s well before programming languages or even electronic computers were invented. Church's thesis is that the computable functions are precisely those that are definable in the lambda-calculus. This is quite amazing, since the entire syntax of the lambda-calculus can be defined in just one line: T ::= V j λV:T j (TT ) The syntactic category T defines the set of well-formed expressions of the lambda-calculus, also referred to as lambda-terms. The syntactic category V stands for a variable; λV:T is called an abstraction, and (TT ) is called an application. We will examine these terms in more detail a little later, but, at the outset, it is remarkable that the lambda-calculus is capable of defining recursive functions even though there is no provision for writing recursive definitions. Indeed, there is no provision for writing named procedures or functions as we know them in conventional languages. Also absent are other familiar programming constructs such as control and data structures. We will therefore examine how the lambda-calculus can encode such constructs, and thereby gain some insight into the power of this little language. In the field of programming languages, John McCarthy was probably the first to rec- ognize the importance of the lambda-calculus, which inspired him in the 1950s to develop the Lisp programming language.
    [Show full text]
  • Requirements and Theories of Meaning
    INTERNATIONAL CONFERENCE ON ENGINEERING DESIGN, ICED07 28-31 AUGUST 2007, CITE DES SCIENCE ET DE L’INDUSTRIE, PARIS, FRANCE REQUIREMENTS AND THEORIES OF MEANING Ichiro Nagasaka Kobe University ABSTRACT In this paper, the fundamental characteristics of the concept of meaning in the traditional theory of design are discussed and the similarities between the traditional theory of design and the truth-conditional theory of meaning are pointed out. The difficulties brought by the interpretation of the model are explained in the context of theory of design and the argument that the sequence-of-use based proof-conditional theory of meaning could resolve the difficulties by changing the notion of the requirement is presented. Finally, based on the ideas of the proof-conditional theory of meaning we show the perspective of the formulation of the sequence-of-use based theory and discuss how the theory deals with the sequence of use in a constructive way. Keywords: Requirements, theories of meaning, constructive theory of design 1 INTRODUCTION As we all know, the requirement or the need has an essential role to play in the process of design. Most of the theories of design proposed since the early 1960s share the view on the requirement. For example: • Design begins with the recognition of a need and the conception of an idea to satisfy this need [1, p.iii]. • The main task of engineers is to apply their scientific and engineering knowledge to the solution of technical problems, and then to optimize those solutions within the requirements and constraints [...] [2, p.1]. • It is widely recognized that any serious attempt to make the environment work, must begin with a statement of user needs.
    [Show full text]
  • Semantic Theory Week 4 – Lambda Calculus
    Semantic Theory Week 4 – Lambda Calculus Noortje Venhuizen University of Groningen/Universität des Saarlandes Summer 2015 1 Compositionality The principle of compositionality: “The meaning of a complex expression is a function of the meanings of its parts and of the syntactic rules by which they are combined” (Partee et al.,1993) Compositional semantics construction: • compute meaning representations for sub-expressions • combine them to obtain a meaning representation for a complex expression. Problematic case: “Not smoking⟨e,t⟩ is healthy⟨⟨e,t⟩,t⟩” ! 2 Lambda abstraction λ-abstraction is an operation that takes an expression and “opens” specific argument positions. Syntactic definition: If α is in WEτ, and x is in VARσ then λx(α) is in WE⟨σ, τ⟩ • The scope of the λ-operator is the smallest WE to its right. Wider scope must be indicated by brackets. • We often use the “dot notation” λx.φ indicating that the λ-operator takes widest possible scope (over φ). 3 Interpretation of Lambda-expressions M,g If α ∈ WEτ and v ∈ VARσ, then ⟦λvα⟧ is that function f : Dσ → Dτ M,g[v/a] such that for all a ∈ Dσ, f(a) = ⟦α⟧ If the λ-expression is applied to some argument, we can simplify the interpretation: • ⟦λvα⟧M,g(A) = ⟦α⟧M,g[v/A] Example: “Bill is a non-smoker” ⟦λx(¬S(x))(b’)⟧M,g = 1 iff ⟦λx(¬S(x))⟧M,g(⟦b’⟧M,g) = 1 iff ⟦¬S(x)⟧M,g[x/⟦b’⟧M,g] = 1 iff ⟦S(x)⟧M,g[x/⟦b’⟧M,g] = 0 iff ⟦S⟧M,g[x/⟦b’⟧M,g](⟦x⟧M,g[x/⟦b’⟧M,g]) = 0 iff VM(S)(VM(b’)) = 0 4 β-Reduction ⟦λv(α)(β)⟧M,g = ⟦α⟧M,g[v/⟦β⟧M,g] ⇒ all (free) occurrences of the λ-variable in α get the interpretation of β as value.
    [Show full text]