MLW. Henk Barendregt and Freek Wiedijk assisted by Andrew Polonsky. March 26, Radboud University Nijmegen

Similar documents
Calculus of Inductive Constructions

Mathematics for Computer Scientists 2 (G52MC2)

a brief introduction to (dependent) type theory

Types Summer School Gothenburg Sweden August Dogma oftype Theory. Everything has a type

Theorem Proving Principles, Techniques, Applications Recursion

Martin-Löf s Type Theory

Inductive Definitions, continued

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

On a few open problems of the Calculus of Inductive Constructions and on their practical consequences

Exercise 1 (2+2+2 points)

CSE-321 Programming Languages 2010 Final

CSE-321 Programming Languages 2011 Final

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

Certificates for incremental type checking

Basic Foundations of Isabelle/HOL

Lecture slides & distribution files:

λ calculus is inconsistent

Introduction to the Lambda Calculus. Chris Lomont

Constructing the Propositional Truncation using Non-recursive HITs

Explicit Recursion in Generic Haskell

Certified Programming with Dependent Types

CSE-321 Programming Languages 2012 Midterm

The Next 700 Syntactic Models of Type Theory

The Implicit Calculus of Constructions

Typed Lambda Calculus

4.8 Dependent Types 97

CS 4110 Programming Languages & Logics. Lecture 28 Recursive Types

Dependent Type Theory

Introduction to Homotopy Type Theory

CSE-321 Programming Languages 2010 Midterm

Programming Languages Lecture 14: Sum, Product, Recursive Types

Types and Programming Languages. Lecture 5. Extensions of simple types

On the Logical Foundations of Staged Computation

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

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

Less naive type theory

Concepts of programming languages

Structural polymorphism in Generic Haskell

Dependencies by case or by function?

What s in Main. Tobias Nipkow. December 5, Abstract

Type Theory. Lecture 2: Dependent Types. Andreas Abel. Department of Computer Science and Engineering Chalmers and Gothenburg University

Preuves Interactives et Applications

The University of Nottingham

Embedding logics in Dedukti

Programming in Omega Part 1. Tim Sheard Portland State University

Programming with Dependent Types Interactive programs and Coalgebras

CS 336/CS M36 (part 2)/CS M46 Interactive Theorem Proving

Formalising FinFuns Generating Code for Functions as Data from Isabelle/HOL

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

Lecture 14: Recursive Types

CMSC 336: Type Systems for Programming Languages Lecture 5: Simply Typed Lambda Calculus Acar & Ahmed January 24, 2008

Introduction to Type Theory August 2007 Types Summer School Bertinoro, It. Herman Geuvers Nijmegen NL

Overview. A Compact Introduction to Isabelle/HOL. Tobias Nipkow. System Architecture. Overview of Isabelle/HOL

CS 4110 Programming Languages & Logics. Lecture 27 Recursive Types

We defined congruence rules that determine the order of evaluation, using the following evaluation

CS-XXX: Graduate Programming Languages. Lecture 17 Recursive Types. Dan Grossman 2012

Denotational Semantics. Domain Theory

Exercise 1 ( = 24 points)

Three Applications of Strictness in the Efficient Implementaton of Higher-Order Terms

Inductive data types (I)

Generic Programming With Dependent Types: II

4.5 Pure Linear Functional Programming

Lambda calculus. Chapter 2

Univalent fibrations in type theory and topology

Lecture 9: More Lambda Calculus / Types

- M ::= v (M M) λv. M - Impure versions add constants, but not necessary! - Turing-complete. - true = λ u. λ v. u. - false = λ u. λ v.

Constructing Strictly Positive Families

Programming with Universes, Generically

λ calculus Function application Untyped λ-calculus - Basic Idea Terms, Variables, Syntax β reduction Advanced Formal Methods

Introduction to Lambda Calculus. Lecture 7 CS /08/09

CSE-505: Programming Languages. Lecture 20.5 Recursive Types. Zach Tatlock 2016

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

Type checking in the presence of meta-variables

4. The λ-calc. with Prod. and Conj.

Exercise 1 ( = 18 points)

CITS3211 FUNCTIONAL PROGRAMMING

B2. The Logical Framework

Typed Lambda Calculus for Syntacticians

Combining Proofs and Programs in a Dependently Typed Language. Certification of High-level and Low-level Programs

Dependent types and program equivalence. Stephanie Weirich, University of Pennsylvania with Limin Jia, Jianzhou Zhao, and Vilhelm Sjöberg

Lesson 4 Typed Arithmetic Typed Lambda Calculus

Lambda calculus. Wouter Swierstra and Alejandro Serrano. Advanced functional programming - Lecture 6

Lambda Calculus. Lecture 4 CS /26/10

1 The language χ. Models of Computation

Intuitionistic Type Theory

Introduction to the Lambda Calculus

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

Kripke-Style Contextual Modal Type Theory

An Introduction to Programming and Proving in Agda (incomplete draft)

4.6 Recursive Types. 4.6 Recursive Types 105

An Introduction to Martin-Lof s Constructive Type Theory and a computer implementation of it. p.1/??

Constructive Type Theory and Interactive Theorem Proving. Peter Dybjer Chalmers Tekniska Högskola Göteborg, Sweden

Programming with (co-)inductive types in Coq

Modelling General Recursion in Type Theory

Overview. A normal-order language. Strictness. Recursion. Infinite data structures. Direct denotational semantics. Transition semantics

Isabelle s meta-logic. p.1

Lecture 3: Typed Lambda Calculus and Curry-Howard

Functional Programming with Isabelle/HOL

Programming Up-to-Congruence, Again. WG 2.8 Estes Park

On Agda JAIST/AIST WS CVS/AIST Yoshiki Kinoshita, Yoriyuki Yamagata. Agenda

Transcription:

1 MLW Henk Barendregt and Freek Wiedijk assisted by Andrew Polonsky Radboud University Nijmegen March 26, 2012

inductive types 2

3 inductive types = types consisting of closed terms built from constructors 0 : nat suc : nat nat nat = {0, suc 0, suc (suc 0), suc (suc (suc 0)),... } leaf : tree node : tree tree tree tree = {leaf, node leaf leaf, node (node leaf leaf) leaf,... }

4 terms as data structures the term: node (node leaf leaf) leaf corresponds to the tree data structure: node node leaf leaf leaf

5 constructors can have arguments pair : A B prod A B prod A B = {pair a b a A, b B} pair a b

6... and the disjoint union inl : A sum A B inr : B sum A B sum A B = {inl a a A} {inr b b B} inl a inr b

7 inductive types can be finite true : bool false : bool bool = {true, false} : unit unit = { } empty = {}

8 two kinds of true and false true : bool false : bool bool = {true, false} : True True = { } False = {}

9 lists nil : list cons : nat list list 0, 1 = cons 0 cons suc nil 0

10 inductive predicates = dependent inductive types le refl : Πn : nat. le n n le suc : Πn : nat. Πm : nat. le n m le n (suc m) proof of 0 1: le suc 0 0 (le refl 0) : le 0 (suc 0)

11 Leibniz equality eq : Πa :. a a eq refl : Πa :. Πx : a. eq a x x eq A M N = { {eq refl A M M} if M = N {} if M N eq A M N inhabited M = N

12 defining inductive types impredicative definitions does not work well 0 1 not provable induction principle not provable hardwired into the foundations 0 1 is provable induction principle is provable inductive types are primitive like λ and Π

13 terms in type theory syntax: sorts M ::= x MM λx : M. M Πx : M. M s c constants s ::=... c ::=... nat 0 suc rec...

constants defined constants abbreviating terms: c := M δ-reduction = replacing constant by its definition c δ M constants related to inductive types the type itself constructors recursion principle = eliminator = destructor nat 0, suc rec ι-reduction = destructor applied to a constructor rec... 0... ι... 14

15 two approaches 1 finite number of inductive types hardwired into the system Gödel s T MLW 2 possibility to define arbitrary inductive types constructors determine recursion principle and reduction pcic Coq next time

16 inductive type: four kinds of rules 1 type formation 2 constructor types 3 eliminator type two possibilities: non-dependent eliminator dependent eliminator 4 reduction rules one for every constructor: eliminator acting on constructor ι-reduction: ι first three: typing rules fourth: computation rules

17 what to do with a term? type check proof check compute βδι β-reduction = substitute in a lambda term δ-reduction = unfold definition of a constant ι-reduction = compute in an inductive type η-reduction = dual of β-reduction η-expansion = converse of η-reduction

Gödel s system T 18

19 Gödel s system T = λ + nat syntax: one base type A ::= nat A A M ::= x MM λx : A. M 0 suc rec A

20 typing rules Γ x : A x : A Γ Γ, x : A M : B Γ λx : A. M : A B Γ M : A B Γ N : A Γ MN : B Γ 0 : nat Γ suc : nat nat Γ rec A : A (nat A A) (nat A)

21 computation rules (λx : A. M)N β M[x := N] rec A M F 0 ι M rec A M F (suc N) ι F N (rec A M F N)

22 exercise: define plus and... recursive definition of plus: plus x 0 = x plus x (suc y) = suc (plus x y) plus := λx : nat. rec nat x (λy : nat. λr : nat. suc r)

... and calculate 1 + 1 plus := λx : nat. rec nat x (λy : nat. λr : nat. suc r) rec A M F 0 ι M rec A M F (suc N) ι F N (rec A M F N) 1 + 1 {}}{ plus (suc 0)(suc 0) δ (λx : nat. rec nat x (λy : nat. λr : nat. suc r))(suc 0)(suc 0) β rec nat (suc 0) (λy : nat. λr : nat. suc r)(suc 0) ι (λy : nat. λr : nat. suc r) 0 (rec nat (suc 0) (λy : nat. λr : nat. suc r) 0) β (λr : nat. suc r)(rec nat (suc 0) (λy : nat. λr : nat. suc r) 0) β suc (rec nat (suc 0) (λy : nat. λr : nat. suc r) 0) ι suc(suc 0) }{{}}{{} 1 + 0 2 23

24 rules for nat together 1 type formation: 2 constructor types: nat : 0 : nat suc : nat nat 3 eliminator type: rec : Πa :. a (nat a a) (nat a) rec : Πa : (nat ). a 0 (Πn : nat. a n a (suc n)) Πn : nat. a n 4 reduction rules: rec A M F 0 ι M rec A M F (suc N) ι F N (rec A M F N)

25 how to determine the dependent eliminator type rec : Πa : (nat ). a 0 (Πn : nat. a n a (suc n)) Πn : nat. a n dependent recursion over the datatype Curry-Howard: recursion principle = induction principle for all predicates a on the inductive type...... if this predicate is conserved by all constructors...... then it holds for all objects in the inductive type

26 how to determine the non-dependent eliminator type Πa : (nat ). a 0 (Πn : nat. a n a (suc n)) Πn : nat. a n just erase the dependency on the inductive type! Πa :. a (nat a a) (nat a)

MLW 27

28 Martin-Löf type theory Bengt Nordström, Kent Petersson, Jan M. Smith, Programming in Martin-Löf Type Theory, 1990 Peter Aczel, On relating type theories and set theories, 1998 MLW defined on pp. 3 9 here: just overview many rules! MLW still is much simpler than pcic...

29 type constructions in MLW Πx : A. B Σx : A. B Wx : A. B 0 1 2 inductive types

30 not primitive in MLW, because definable A B := Πx : A. B A B := Σx : A. B A + B := Σx : 2. R2 A B x nat := Wx : 2. R2 01x R 2 is recursion over 2: R 2 A B x = if x then A else B

31 Curry-Howard 0 empty 1 unit 2 bool A B A B A B prod A B A B A + B sum A B A B Πx : A. B x : A. B Σx : A. B sig (λx : A. B) x : A. B Wx : A. B W (λx : A. B)

2 1 type formation: 2 constructor types: 3 eliminator type: 4 reduction rules: 2 : 1 : 2 2 : 2 R 2 : Πa : (2 ). a 0 a 1 Πx : 2. a x R2 : (2 ) R 2 A N 1 N 2 1 ι N 1 R 2 A N 1 N 2 2 ι N 2 R 2 A 1 A 2 1 ι A 1 R 2 A 1 A 2 2 ι A 2 32

33 2 is the Booleans 2 bool 1 true 2 false R 2 A N 1 N 2 M if M then N 1 else N 2 R 2 A 1 A 2 M if M then A 1 else A 2

34 the three finite types 0 = empty = no constructors 1 = unit = : 1 2 = bool 1 : 2 2 : 2

35 A B 1 type formation: prod : 2 constructor types: 3 eliminator type: pair : Πa :. Πb :. a b prod a b π 1 π 2 : Πa :. Πb :. prod a b a : Πa :. Πb :. prod a b b 4 reduction rules: π 1 A B (pair A B M 1 M 2 ) ι M 1 π 2 A B (pair A B M 1 M 2 ) ι M 2

36 Σx : A. B 1 type formation: sig : Πa :. (a ) 2 constructor types: pair : Πa :. Πb : (a ). Πx : a. b x sig a b 3 eliminator type: π 1 : Πa :. Πb : (a ). sig a b a π 2 : Πa :. Πb : (a ). Πx : sig a b. b (π 1 a b x) 4 reduction rules: π 1 A B (pair A B M 1 M 2 ) ι M 1 π 2 A B (pair A B M 1 M 2 ) ι M 2

W-trees 37

38 unlabeled binary trees 1 type formation: 2 constructor types: 3 eliminator type: tree : leaf : tree node : tree tree tree binrec : Πa : (tree ). a leaf (Πt 1 : tree.πt 2 : tree. a t 1 a t 2 a (node t 1 t 2 )) Πt : tree.at 4 reduction rules: binrec AM F leaf ι M binrec AM F (node N 1 N 2 ) ι F N 1 N 2 (binrec AM F N 1 )(binrec AM F N 2 )

39 W-trees = containers Wx : A. B[x] A B[a] type of labeled trees node labels edge labels from node labelled a a 0 b 1 b 2 b 3 b 4 a 1 a 2 a 3 a 4 b 1 b 1 b 1 a 1 a 2 a 3 a 0 : A b i : B[a 0 ] a i : A b i : B[a 3 ] a i : A

40 examples of types defined as W-trees two kinds of nodes tree := Wx : 2. R 2 02x 2 1 2 2 1 1 2 1 1 nat := Wx : 2. R 2 01x

41 Wx : A. B 1 type formation: W : Πa :. (a ) 2 constructor types: sup : Πa :. Πb : (a ). Πx : a. (b x W a b) W a b 3 eliminator type: 4 reduction rules: exercise! exercise!

variations on a theme 42

43 differences with the paper by Peter Aczel W-trees only work well in an extensional type theory MLW MLW ext MLW ext PU <ω Martin-Löf type theory is different: no and in judgments four kind of judgments: Martin-Löf Γ A type Γ M : A PTS Γ A : Γ M : A Γ A 1 = A 2 A 1 = βι A 2 Γ M 1 = M 2 : A M 1 = βι M 2

44 function types are not inductive but... 1 type formation: Πx : A. B : s 2 constructor types: λx : A. M : Πx : A. B 3 eliminator type: MN : B[x := N] 4 reduction rules: (λx : A. M)N β M[x := N]

45 recap 1 inductive types 2 Gödel s system T 3 MLW 4 W-trees 5 variations on a theme