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

Similar documents
Refinement Types as Proof Irrelevance. William Lovas with Frank Pfenning

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

Calculus of Inductive Constructions

Inductive Definitions, continued

CLF: A logical framework for concurrent systems

Lecture 3: Typed Lambda Calculus and Curry-Howard

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

Inductive Beluga: Programming Proofs

Lecture slides & distribution files:

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

Beluga: A Framework for Programming and Reasoning with Deductive Systems (System Description)

Less naive type theory

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

Foundational Aspects of Syntax 1

Theorem Proving Principles, Techniques, Applications Recursion

Basic Foundations of Isabelle/HOL

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

An Implementation of the Language Lambda Prolog Organized around Higher-Order Pattern Unification

Higher-Order Logic. Specification and Verification with Higher-Order Logic

Programming Language Concepts: Lecture 19

Typed Lambda Calculus

A Two-Level Logic Approach to Reasoning about Typed Specification Languages

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

Typed Lambda Calculus for Syntacticians

Normalization by hereditary substitutions

Efficient Substitution in Hoare Logic Expressions

System Description: Twelf A Meta-Logical Framework for Deductive Systems

Pure Lambda Calculus. Lecture 17

λ calculus is inconsistent

4.8 Dependent Types 97

Programming with Universes, Generically

Where is ML type inference headed?

1.3. Conditional expressions To express case distinctions like

Polymorphism and System-F (OV)

Weak Normalization for the Simply-Typed Lambda-Calculus in Twelf

Proof Pearl: The power of higher-order encodings in the logical framework LF

Proofs-Programs correspondance and Security

Extracting the Range of cps from Affine Typing

HIGHER-ORDER ABSTRACT SYNTAX IN TYPE THEORY

Introduction to the Lambda Calculus. Chris Lomont

Lambda Calculus and Extensions as Foundation of Functional Programming

A META LANGUAGE FOR TYPE CHECKING AND INFERENCE An Extended Abstract

CS131 Typed Lambda Calculus Worksheet Due Thursday, April 19th

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

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

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

Polymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy

Small proof witnesses for LF

Mechanized metatheory revisited

Exercise 1 ( = 22 points)

The Typed λ Calculus and Type Inferencing in ML

Proofs for free. Parametricity for dependent types. JEAN-PHILIPPE BERNARDY and PATRIK JANSSON

Expr_annotated.v. Expr_annotated.v. Printed by Zach Tatlock

Mechanizing Metatheory with LF and Twelf

Automated Reasoning. Natural Deduction in First-Order Logic

A Canonical 1 Locally Named Representation of Binding. α -equivalence is identity. Randy Pollack. Masahiko Sato. LFCS, University of Edinburgh

System Description: Delphin A Functional Programming Language for Deductive Systems

Avoiding Spurious Causal Dependencies via Proof Irrelevance in a Concurrent Logical Framework

Proofs are Programs. Prof. Clarkson Fall Today s music: Proof by Paul Simon

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

Specifying and Implementing Theorem Provers in a Higher-Order Logic Programming Language

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

Meta-programming with Names and Necessity p.1

Parametricity and Dependent Types

Lecture Notes on Induction and Recursion

a brief introduction to (dependent) type theory

Fall 2013 Midterm Exam 10/22/13. This is a closed-book, closed-notes exam. Problem Points Score. Various definitions are provided in the exam.

The Untyped Lambda Calculus

A New Proof of P-time Completeness of Linear Lambda Calculus

Type raising, continuations, and classical logic

Type Systems. Parametric Polymorphism. 1. Recall Let-Polymorphism. 1. Recall Let-Polymorphism. Lecture 9 Dec. 15th, 2004 Sebastian Maneth

Introduction to dependent types in Coq

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

arxiv:cs/ v1 [cs.lo] 9 Mar 2004

Implementing Constructive Logics with OCaml

GADTs. Wouter Swierstra and Alejandro Serrano. Advanced functional programming - Lecture 7. [Faculty of Science Information and Computing Sciences]

10 Years of Partiality and General Recursion in Type Theory

Automata and Formal Languages - CM0081 Introduction to Agda

Functional Programming and Modeling

Isabelle s meta-logic. p.1

Lecture Notes on Data Representation

Thesis Proposal: Refinement Types for LF (DRAFT)

Exercise 1 ( = 24 points)

Lecture Notes on Computational Interpretations of Modalities

Resources: The slides of this lecture were derived from [Järvi], with permission of the original author, by copy & x = 1 let x = 1 in...

GADTs. Alejandro Serrano. AFP Summer School. [Faculty of Science Information and Computing Sciences]

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

PARSIFAL Summer 2011 Internship Report Logically validating logic programs

Dependent Polymorphism. Makoto Hamana

Type checking in the presence of meta-variables

A computer implemented philosophy of mathematics

Elf: A Meta-Language for Deductive Systems (System Description)

GADTs. GADTs in Haskell

Static Contract Checking for Haskell

Symmetry in Type Theory

M. Snyder, George Mason University LAMBDA CALCULUS. (untyped)

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

Lambda Calculi With Polymorphism

Comparing Cubes. Steffen van Bakel Luigi Liquori Simona Ronchi della Rocca Paweł Urzyczyn

Epigram Reloaded: A Standalone Typechecker for ETT. James Chapman, Thorsten Altenkirch, Conor McBride

Transcription:

Type Theory Lecture 2: Dependent Types Andreas Abel Department of Computer Science and Engineering Chalmers and Gothenburg University Type Theory Course CM0859 (2017-1) Universidad EAFIT, Medellin, Colombia 6-10 March 2017 Andreas Abel (GU) Type Theory EAFIT 2017 1 / 28

Contents 1 Typed Predicate Logic Formation rules Proof rules 2 Dependent Type Theory Expressions and judgements Dependent function type 3 The Logical Framework A type of types Type conversion Andreas Abel (GU) Type Theory EAFIT 2017 2 / 28

Typed Predicate Logic Typed Predicate Logic Propositional logic: only atomic statements like Socrates is a human. Predicate logic gives a finer structure by decomposing this into a predicate is a human applied to an individual Socrates and can express universal statements such as all humans are mortal. Untyped vs. typed predicate logic: untyped: typed: x. Human(x) Mortal(x) x:human. Mortal Human x Untyped = unityped: a single type for all individuals/objects. Typed: objects are a priori sorted into different types. Andreas Abel (GU) Type Theory EAFIT 2017 3 / 28

Typed Predicate Logic Typed Predicate Logic (ctd.) Mortal Human is a predicate that only applies to objects of type Human. y:dog. Mortal Human y is an ill-formed proposition. What is a type, what a predicate is up to design. z:lifeform. Human LifeForm z Mortal LifeForm z Spoiler: Type theory will give us means to turn predicate into types: HumanLifeForm = Σz:LifeForm. Human LifeForm z Andreas Abel (GU) Type Theory EAFIT 2017 4 / 28

Typed Predicate Logic Formation rules Formulæ of typed predicate logic We extend the grammar for propositions: A, B, C ::= A B A B A B propositional connectives P T t atoms x:t. A universal quantification x:t. A existential quantification Typing context maps variables x to types T. Judgement A prop characterizes well-formed propositions. Andreas Abel (GU) Type Theory EAFIT 2017 5 / 28

Typed Predicate Logic Formation rules Formation rules Atoms: Quantifiers: t : T P T t prop atomf, x:t A prop x:t. A prop F, x:t A prop x:t. A prop F Propositional connectives: A prop A B prop B prop F ( {,, }) prop F prop F Andreas Abel (GU) Type Theory EAFIT 2017 6 / 28

Typed Predicate Logic Formation rules Examples Well-formed formulæ: x:n. y:n. ( N N x, y ) ( N N y, x ) f :Bool Bool. x:bool. Bool Bool f (f (f x)), f x Ill-formed formulæ: f :N N. r:r. Even N (f r) prop x:n. N N x, y prop Andreas Abel (GU) Type Theory EAFIT 2017 7 / 28

Typed Predicate Logic Proof rules Proof rules Judgement Γ A true. (Both Γ and A are scoped in.) Universal quantification: Γ,x:T A true Γ x:t. A true I Γ x:t. A true t : T Γ A[t/x] true E Existential quantification: t : T Γ A[t/x] true Γ x:t. A true I Γ x:t. A true Γ C true Γ, A true,x:t C true E Andreas Abel (GU) Type Theory EAFIT 2017 8 / 28

Typed Predicate Logic Proof rules Proof examples Use of I: 0 : N Even N 0 true x:n. Even N x I Γ 1 := ( x:s. true, y:s. A true). Prove Γ 1 z:s. A true! Exercise: Show A true, x:t. B true x:t. A B true! Exercise: Show x:t. A B true, A true x:t. B true! (Here, A does not depend on x.) Andreas Abel (GU) Type Theory EAFIT 2017 9 / 28

Typed Predicate Logic Proof rules Proof terms Judgement Γ M : A. (All of Γ, M, and A are scoped in.) Universal quantification: Γ,x:T M : A Γ λx.m : x:t. A I Γ M : x:t. A t : T Γ M t : A[t/x] E Existential quantification: t : T Γ M : A[t/x] Γ t, M : x:t. A I Γ M : x:t. A Γ, y:a,x:t N : C Γ let x, y = M in N : C New reduction: E let x, y = t, M in N β N[t/x, M/y] Andreas Abel (GU) Type Theory EAFIT 2017 10 / 28

Typed Predicate Logic Proof rules Strong existentials Proof terms would allow us to extract the witness! Γ M : x:t. A fst M : T E 1 Γ M : x:t. A Γ snd M : A[fst M/x] E 2 However, this would make proving and programming (typing) interdependent. Why not? ;-) Andreas Abel (GU) Type Theory EAFIT 2017 11 / 28

Dependent Type Theory Dependent Type Theory Interpret propositions as sets of their proofs. Rather: proposition = type proof of proposition = inhabitant of type Abolish set as a primitive notion. Instead: types and predicates. Example: set of natural numbers type of natural numbers N set of primes predicate Prime on N Unify types T and propositions A. Unify programs/objects t and proof terms M. Andreas Abel (GU) Type Theory EAFIT 2017 12 / 28

Dependent Type Theory Expressions and judgements Expressions of Dependent Type Theory We no longer distinguish between terms and types a priori. There is a single grammar of expressions. A, B, C, M, N, O ::= c constants x λx.m M N lambda-calculus (x : A) B dependent function type Expressions are sorted into terms and types by judgements: Γ A type Γ M : A in context Γ, expression A is a well-formed type in context Γ, expression M has type A Andreas Abel (GU) Type Theory EAFIT 2017 13 / 28

Dependent Type Theory Dependent function type Dependent function type Formation. Γ A type Γ, x:a B type ΠF Γ (x : A) B type Introduction. Γ, x:a M : B Γ λx.m : (x : A) B ΠI Elimination. Γ M : (x : A) B Γ M N : B[N/x] Γ N : A ΠE Andreas Abel (GU) Type Theory EAFIT 2017 14 / 28

Dependent Type Theory Dependent function type Dependent function type: examples (x : N) N: non-dependent function type N N (x : N) Vec A n: properly dependent function type (p : (x 2)) x 2 > x: implication x 2 x 2 > x (x : N) x 0: universal quantification x:n. x 0. (p : (x > 0)) N: conditional value. div : (x : N) (y : N) (p : (y > 0)) N Andreas Abel (GU) Type Theory EAFIT 2017 15 / 28

Dependent Type Theory Dependent function type Function type interpretations Non-dependent function type A B. B prop B type A prop implication A B conditional value A type void universal quant. _:A. B function Dependent-function type (x : A) B. B prop B type A prop proof-relevant implication proof-rel. cond. value A type universal quant. x:a. B dependent function Andreas Abel (GU) Type Theory EAFIT 2017 16 / 28

The Logical Framework The Logical Framework The Logical Framework (LF) is a minimal dependently typed lambda calculus. It is used to represent programming languages and logics. A mature implementation is Twelf (Pfenning, Schürmann). Andreas Abel (GU) Type Theory EAFIT 2017 17 / 28

The Logical Framework The Logical Framework: representing trees In LF, abstract syntax (e. g., unary numbers) can be represented by adding new type constant(s), e. g., N type adding new term constants targeting the new type constant(s), e. g., zero : N suc : N N Grammar of first order terms f ( t): Three new types Symbol, Tm, ArgList, and constructors app : Symbol ArgList Tm nil : ArgList cons : Tm ArgList ArgList Andreas Abel (GU) Type Theory EAFIT 2017 18 / 28

The Logical Framework The Logical Framework: representing binders Trees with binders are represented by LF binders (HOAS). E. g., first-order logical formulæ: New type Form type, plus Top, Bot : Form And, Or, Imp : Form Form Form Equal : Tm Tm Form Forall, Exists : (Tm Form) Form Given a symbol f : Symbol, we represent the formula x. x f (x) by the expression: Exists λx. Equal x (app f (cons x nil)) So far, we have not used dependent types. Andreas Abel (GU) Type Theory EAFIT 2017 19 / 28

The Logical Framework A type of types The Logical Framework: representing predicates Besides trees, a specification language need predicates/relations. How to represent, e. g., the predicate Even on N? Even n should be a type that is inhabited iff n is even. Even is a function from N to types. With a constant type, a type of types, we can write Even : N type ezero : Even zero esuc : (x : N) Even x Even (suc (suc x)) What should be the rules for type? Andreas Abel (GU) Type Theory EAFIT 2017 20 / 28

The Logical Framework A type of types Is type a type? We drop judgement A type in favor of A : type. Tentative rules for type: Γ type : type typef This rule is inconsistent! Girard s paradox [2]. We introduce a universe kind inhabited by type. Γ type : kind typef Γ A : type Γ, x:a B : kind Γ (x : A) B : kind ΠF The second rule allows us to form types of predicates like N type. Predicate is an interpretation, the technical term is type family. Andreas Abel (GU) Type Theory EAFIT 2017 21 / 28

The Logical Framework A type of types LF example: representing derivations LF allows us to represent judgements as types. Provability of a FO formula can be stated with type family Prf : Form type Prf A is the type of proofs of formula A. Proof rules for conjunction: prfandi : (a : Form) (b : Form) Prf a Prf b Prf (And a b) prfandel : (a : Form) (b : Form) Prf (And a b) Prf a prfander : (a : Form) (b : Form) Prf (And a b) Prf b Andreas Abel (GU) Type Theory EAFIT 2017 22 / 28

The Logical Framework A type of types LF example: representing derivations Proof rules for implication: prfimpi : (a b : Form) (Prf a Prf b) Prf (Imp a b) prfimpe : (a b : Form) Prf (Imp a b) Prf a Prf b Proof rules for universal quantification: prfalli : (p : Tm Form) ((x : Tm) Prf (p x)) Prf (Forall p) prfalle : (p : Tm Form) Prf (Forall p) (t : Tm) Prf (p t) Andreas Abel (GU) Type Theory EAFIT 2017 23 / 28

The Logical Framework Type conversion The need for type conversion prfalle : (p : Tm Form) Prf (Forall p) (t : Tm) Prf (p t) We would expect prfalle (λx. Equal x x) q t : Prf (Equal t t). By ΠE, we only get prfalle (λx. Equal x x) q t : Prf ((λx. Equal x x) t) The types are β-convertible. Andreas Abel (GU) Type Theory EAFIT 2017 24 / 28

The Logical Framework Type conversion Completing LF s rules Grammar for sorts s ::= type kind This allows us to unify the Π-formation rules: Γ A : type Γ, x:a B : s Γ (x : A) B : s ΠF We close with the infamous type conversion rule: Γ M : A Γ M : B Γ A = B : s conv For now, judgement Γ A = B : s is defined as Γ A : s Γ B : s A = βη B Γ A = B : s with = βη the least congruence over β-reduction and η-expansion. Andreas Abel (GU) Type Theory EAFIT 2017 25 / 28

The Logical Framework Type conversion Summary: LF rules (x:a) Γ Γ x : A hyp Γ type : kind typef Γ A : type Γ, x:a B : s Γ (x : A) B : s ΠF Γ, x:a M : B Γ λx.m : (x : A) B ΠI Γ M : (x : A) B Γ N : A Γ M N : B[N/x] ΠE Γ M : A Γ M : B Γ A = B : s conv Andreas Abel (GU) Type Theory EAFIT 2017 26 / 28

The Logical Framework Type conversion LF: discussion LF allows HOAS (Higher Order Abstract Syntax) encodings of programming languages and logics with binders. Adequacy of encodings relies on the parametricity of λ-abstraction. In particular, no case distinction. The term Forall (λx. if x then A B else A B) does not correspond to a formula of predicate logic. LF admits type erasure: Each well-typed term also has a simple type. Normalization can be proven by erasure to simply-typed λ-calculus. [[(x : A) B]] = [[A]] [[B]] [[c M 1... M n ]] = c Andreas Abel (GU) Type Theory EAFIT 2017 27 / 28

The Logical Framework Type conversion References Robert Harper, Furio Honsell, and Gordon Plotkin. A framework for defining logics. JACM, 40(1):143 184, 1993. Antonius J. C. Hurkens. A simplification of Girard s paradox. In TLCA 95, volume 902 of LNCS, pages 266 278. Springer, 1995. Frank Pfenning. Logical frameworks. In Handbook of Automated Reasoning, volume 2, chapter 17, pages 1063 1147. Elsevier and MIT Press, 2001. Andreas Abel (GU) Type Theory EAFIT 2017 28 / 28