From natural numbers to the lambda calculus

Similar documents
From signatures to monads in UniMath

An introduction to Homotopy Type Theory

Modular dependent induction in Coq, Mendler-style. Paolo Torrini

a brief introduction to (dependent) type theory

Generalized Iteration and Coiteration for Higher-Order Nested Datatypes

A NEW PROOF-ASSISTANT THAT REVISITS HOMOTOPY TYPE THEORY THE THEORETICAL FOUNDATIONS OF COQ USING NICOLAS TABAREAU

Unfolding FOLDS. Matthew Weaver and Dimitris Tsementzis. HoTT/UF Workshop. Sept. 9, 2017

The three faces of homotopy type theory. Type theory and category theory. Minicourse plan. Typing judgments. Michael Shulman.

Theorem Proving Principles, Techniques, Applications Recursion

Univalent fibrations in type theory and topology

Categorical models of type theory

Nonuniform (Co)datatypes

Universes. Universes for Data. Peter Morris. University of Nottingham. November 12, 2009

Representing Cyclic Structures as Nested Datatypes. Makoto Hamana

Analysis of dependent types in Coq through the deletion of the largest node of a binary search tree

An Algebra of Dependent Data Types

3.7 Denotational Semantics

Inductive Types for Free

λ calculus is inconsistent

Natural Numbers. We will use natural numbers to illustrate several ideas that will apply to Haskell data types in general.

Calculus of Inductive Constructions

Synthesis of distributed mobile programs using monadic types in Coq

Nested Abstract Syntax in Coq

Cubical sets as a classifying topos

Explicit Substitutions and Higher-Order Syntax

Programming Languages Fall 2014

Introduction to dependent types in Coq

Using Agda to Explore Path-Oriented Models of Type Theory

Lesson 4 Typed Arithmetic Typed Lambda Calculus

Equations: a tool for dependent pattern-matching

A Simple Supercompiler Formally Verified in Coq

An experiment with variable binding, denotational semantics, and logical relations in Coq. Adam Chlipala University of California, Berkeley

Computational Higher-Dimensional Type Theory

Introduction to Homotopy Type Theory

Inductive Definitions, continued

Inductive datatypes in HOL. lessons learned in Formal-Logic Engineering

Generic Programming With Dependent Types: II

Towards the syntax and semantics of higher dimensional type theory

Combining Programming with Theorem Proving

Contractive Signatures with Recursive Types, Type Parameters, and Abstract Types

Importing HOL-Light into Coq

Refinements for free! 1

type classes & locales

Dependent Polymorphism. Makoto Hamana

n n Try tutorial on front page to get started! n spring13/ n Stack Overflow!

Program Calculus Calculational Programming

Generic Programming with Adjunctions

Comp 411 Principles of Programming Languages Lecture 7 Meta-interpreters. Corky Cartwright January 26, 2018

Programming Languages Third Edition

Coq. LASER 2011 Summerschool Elba Island, Italy. Christine Paulin-Mohring

Proof Pearl: Substitution Revisited, Again

Topic 3: Propositions as types

Meta-programming with Names and Necessity p.1

Recent Work in Homotopy Type Theory

Denotational Semantics. Domain Theory

CIS 500: Software Foundations

Embedding logics in Dedukti

Using context and model categories to define directed homotopies

An introduction to Category Theory for Software Engineers*

THE AGDA STANDARD LIBRARY

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Sections p.

Coq projects for type theory 2018

Disciplined, efficient, generalised folds for nested datatypes

Autosubst Manual. May 20, 2016

Dependent Types and Irrelevance

Game Semantics for Dependent Types

CIS 500: Software Foundations

Initiality for Typed Syntax and Semantics

Computational Higher Type Theory

Lecture Notes on Data Representation

Automated Reasoning. Natural Deduction in First-Order Logic

Haskell Programming with Nested Types: A Principled Approach

CS 4110 Programming Languages & Logics. Lecture 28 Recursive Types

Introduction to Co-Induction in Coq

CMSC 330: Organization of Programming Languages. Operational Semantics

A CONSTRUCTIVE SEMANTICS FOR REWRITING LOGIC MICHAEL N. KAPLAN

Type Inference Systems. Type Judgments. Deriving a Type Judgment. Deriving a Judgment. Hypothetical Type Judgments CS412/CS413

HIGHER-ORDER ABSTRACT SYNTAX IN TYPE THEORY

CSCC24 Functional Programming Scheme Part 2

Introduction to Functional Programming in Haskell 1 / 56

A NEW PROOF-ASSISTANT THAT REVISITS HOMOTOPY TYPE THEORY THE THEORETICAL FOUNDATIONS OF COQ USING NICOLAS TABAREAU

HOL DEFINING HIGHER ORDER LOGIC LAST TIME ON HOL CONTENT. Slide 3. Slide 1. Slide 4. Slide 2 WHAT IS HIGHER ORDER LOGIC? 2 LAST TIME ON HOL 1

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 4 MODULE, SPRING SEMESTER MATHEMATICAL FOUNDATIONS OF PROGRAMMING ANSWERS

Univalent Foundations Project (a modified version of an NSF grant application)

Tracing Ambiguity in GADT Type Inference

Interleaving data and effects

Contents. Chapter 1 SPECIFYING SYNTAX 1

Representability of Homotopy Groups in Type Theory

Verification of Programs on Truly Nested Datatypes in Intensional Type Theory

COMP 4161 NICTA Advanced Course. Advanced Topics in Software Verification. Toby Murray, June Andronick, Gerwin Klein

Programming with Math and Logic

Inductive data types (I)

Leinster s globular theory of weak -categories

Type Theory in Type Theory using Quotient Inductive Types

Inductive data types

Mathematics for Computer Scientists 2 (G52MC2)

Dynamic Logic David Harel, The Weizmann Institute Dexter Kozen, Cornell University Jerzy Tiuryn, University of Warsaw The MIT Press, Cambridge, Massac

3.4 Deduction and Evaluation: Tools Conditional-Equational Logic

DRAFT. Dependent types. Chapter The power of and

First-Class Type Classes

Transcription:

From natural numbers to the lambda calculus Benedikt Ahrens joint work with Ralph Matthes and Anders Mörtberg

Outline 1 About UniMath 2 Signatures and associated syntax

Outline 1 About UniMath 2 Signatures and associated syntax

UniMath as a language UniMath stands for Univalent Mathematics Goal: have a core language of dependent types rich enough to formalize mathematics simple enough to allow for a proof of (equi-)consistency In practice, the UniMath language is a fragment of the Calculus of Inductive Constructions implemented in the Coq proof assistant.

Overview: types in UniMath Type former Notation (special case) Inhabitant a : A Dependent type x : A B(x) Sigma type (x:a) B(x) Product type (x:a) B(x) Coproduct type Identity type Universe Nat, Bool A + B Id A (a, b), a = b U A B A B and some axioms: function extensionality, univalence

Overview: what UniMath does not have record types general inductive types general HITs In this talk we discuss the construction of some inductive types from the other type formers

UniMath as a library General purpose libraries: Foundations Number systems Algebra Category theory Specialized libraries: Categories in FOLDS style Substitution systems (discussed later)

Outline 1 About UniMath 2 Signatures and associated syntax

What are inductive types? Inductive types are types of tree-like data. Usage: containers for data, e.g., lists of elements of a fixed type Inductive list (X : Type) := nil : list X cons : X -> list X -> list X. representations of mathematically interesting objects, e.g., N and lambda terms Inductive LC (X : Type) := Var : X -> LC X App : LC X * LC X -> LC X Abs : LC (option X) -> LC X

Formal definition of inductive types What are inductive types? Two characterizations: external via inference rules internal via universal property as initial algebra Related work: AGS 12 compare universal property definition with internal version of external characterization Our goal We are interested in internally characterized inductive types, and their construction in the UniMath language.

Why the need for a systematic construction? Some inductive types are easily constructed, e.g., lists over a given base type: Vect(A, n) := A n List(A) := (n:n) Vect(A, n) But: it is not always that easy. Exercise The terms of the lambda calculus can be defined as a nested inductive data type, say, using Coq s Inductive: Inductive LC (X : Type) := Var : X -> LC X App : LC X * LC X -> LC X Abs : LC (option X) -> LC X Define an equivalent type using just the UniMath language.

Signatures and inductive types In order to say what an inductive type is, we need to specify a notion of signature. A signature specifies the shape of the trees by specifying type of nodes number of subtrees of a node Various notions of signature in the literature, for different classes of inductive types: polynomial functors containers strengthened signatures (rank 2) for W -types for type families

Two notions of signature for variable binding Binding signature a type A of constructors (nodes) decidable equality (x,y:a)(x = y) + (x = y) a map arity : A List(Nat) Signature à la Matthes & Uustalu a functor H : [C, C] [C, C] a natural transformation θ : (H ) U H( U ) satisfying some axioms θ explains how to do substitution

The lambda calculus Inductive LC (X : Type) := Var : X -> LC X App : LC X * LC X -> LC X Abs : LC (option X) -> LC X Binding signature of the lambda calculus: A := {app, abs} app [0, 0] abs [1] Signature à la M&U of the lambda calculus: H(F ) := F F + F option θ :=... Remark: The constructor var is taken for granted, not mentioned explicitly

Achieved goals We construct 1 a signature à la M&U from a binding signature 2 the data type (functor on Set) specified by a binding signature 3 a model ( substitution system ) of a signature à la M&U on the data type constructed in item (2) equips the datatype with a substitution operation 4 a monad from any substitution system shows that the substitution constructed in (3) satisfies monadic laws Items 3 and 4 were done on paper in [MU 04]. Item 2 is a well-known category-theoretic construction.

Construction of initial algebras in UniMath Initial algebra of F : C C (Adámek) If F is ω-cocontinuous, then the colimit of is an initial F -algebra. 0 F 0 F 2 0... Can construct colimits from coproducts and coequalizers in plain type theory we have coproducts in univalent type theory, additionally have set quotients a.k.a. coequalizers in Set Restriction This approach only allows construction of inductive sets.

Construction of a substitution operation via Generalized Mendler Iteration asserts the unique existence of a morphism making some diagram commute the iterator comes with a suitable fusion law: when is a composition of an iterator with a function again an iterator see work by Mendler, Bird & Paterson

Example: binding signature of MLTT Definition PiSig : GenSig := mkgensig (isdeceqstn 3) (three_rec [0,1] [1] [0,0]). Definition SigmaSig : GenSig := mkgensig (isdeceqstn 3) (three_rec [0,1] [0,0] [0,2]). Definition SumSig : GenSig := mkgensig (isdeceqstn 4) (four_rec [0,0] [0] [0] [0,1,1]). Definition IdSig : GenSig := mkgensig (isdeceqstn 3) (three_rec [0,0,0] [] [0,0]). (* Define the arity of the eliminators for Fin by recursion *) Definition FinSigElim (n : nat) : list nat. Proof. induction n as [ n ih]. - apply [0]. - apply (0 :: ih). Defined. (* Define the signature of the constructors for Fin by recursion *) Definition FinSigConstructors (n : nat) : stn n -> list nat := fun _ => []. (* Uncurried version of the FinSig family *) Definition FinSigFun : (Sigma n : nat, unit + (stn n + unit)) -> list nat. Proof. induction 1 as [n p]. induction p as [_ p]. - apply []. - induction p as [p ]. + apply (FinSigConstructors _ p). + apply (FinSigElim n). Defined. Lemma isdeceqfinsig : isdeceq (Sigma n, unit + (stn n + unit)). Proof. intros [n p] [m q]. induction (isdeceqnat n m) as [h h]. - induction h. + destruct (isdeceqcoprod isdecequnit

Future goals Recall: Goal Constructions 1-4 yield a monad from a binding signature The datatype constructed from a binding signature satisfies a universal property (initial algebra) Show that the datatype together with the constructed substitution operation is initial in a category of algebras with substitution. This is a rephrasing of a result by Hirschowitz & Maggesi, who prove a similar result, but rely on Coq s inductive types for constructing the datatype.

Future goals Recall: Goal Constructions 1-4 yield a monad from a binding signature The datatype constructed from a binding signature satisfies a universal property (initial algebra) Show that the datatype together with the constructed substitution operation is initial in a category of algebras with substitution. This is a rephrasing of a result by Hirschowitz & Maggesi, who prove a similar result, but rely on Coq s inductive types for constructing the datatype. The end thanks for your attention!

References Adámek: Free algebras and automata realizations in the language of categories, CMUC, 1974 Altenkirch, Reus: Monadic presentations of lambda terms using generalized inductive types, CSL 99 Awodey, Gambino, Sojakova: Inductive types in homotopy type theory, LiCS 12 Bird, Paterson: Generalised folds for nested datatypes, JFP, 1999 Hirschowitz, Maggesi: Initial Semantics for Strengthened Signatures, FiCS 12 Hirschowitz, Maggesi: Modules over Monads and Linearity, WoLLIC 07 Matthes, Uustalu: Substitution in non-wellfounded syntax with variable binding, TCS, 2004