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

Similar documents
Lecture 3: Typed Lambda Calculus and Curry-Howard

Calculus of Inductive Constructions

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

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

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 slides & distribution files:

Toward explicit rewrite rules in the λπ-calculus modulo

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

λ calculus is inconsistent

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

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

Programming Language Concepts: Lecture 19

CSE-321 Programming Languages 2010 Midterm

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

CSE-321 Programming Languages 2012 Midterm

Lambda Calculus and Type Inference

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

Typed Lambda Calculus

Typed Lambda Calculus for Syntacticians

Lambda Calculus. Type Systems, Lectures 3. Jevgeni Kabanov Tartu,

CSE-321 Programming Languages 2011 Final

Basic Foundations of Isabelle/HOL

n λxy.x n y, [inc] [add] [mul] [exp] λn.λxy.x(nxy) λmn.m[inc]0 λmn.m([add]n)0 λmn.n([mul]m)1

Logical Verification Course Notes. Femke van Raamsdonk Vrije Universiteit Amsterdam

Importing HOL-Light into Coq

Refinement Types as Proof Irrelevance. William Lovas with Frank Pfenning

The Formal Semantics of Programming Languages An Introduction. Glynn Winskel. The MIT Press Cambridge, Massachusetts London, England

Mechanizing Metatheory with LF and Twelf

Lambda Calculus and Type Inference

The Typed λ Calculus and Type Inferencing in ML

Introduction to dependent types in Coq

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

Lesson 4 Typed Arithmetic Typed Lambda Calculus

HIGHER-ORDER ABSTRACT SYNTAX IN TYPE THEORY

CSE-321 Programming Languages 2014 Final

Symmetry in Type Theory

PARSIFAL Summer 2011 Internship Report Logically validating logic programs

Dependent Object Types - A foundation for Scala s type system

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

Normalization by hereditary substitutions

CIS 500 Software Foundations Midterm I

Theorem proving. PVS theorem prover. Hoare style verification PVS. More on embeddings. What if. Abhik Roychoudhury CS 6214

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

Programming Languages

Subsumption. Principle of safe substitution

Type Theory in Type Theory using Quotient Inductive Types

From Types to Sets in Isabelle/HOL

Pure Lambda Calculus. Lecture 17

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

1.3. Conditional expressions To express case distinctions like

Subsets in type theory

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

Reducibility method: an overview

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

Less naive type theory

Elementary Recursive Function Theory

First-Class Type Classes

1 Introduction. 3 Syntax

Axiom 3 Z(pos(Z) X(X intersection of Z P(X)))

CS 6110 S11 Lecture 25 Typed λ-calculus 6 April 2011

Mechanized metatheory revisited

CS 4110 Programming Languages & Logics. Lecture 28 Recursive Types

The Untyped Lambda Calculus

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

Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1

Embedding logics in Dedukti

Introduction to the Lambda Calculus. Chris Lomont

1. M,M sequential composition: try tactic M; if it succeeds try tactic M. sequential composition (, )

Inductive Definitions, continued

Foundational Aspects of Syntax 1

Proofs are Programs. Prof. Clarkson Fall Today s music: Two Sides to Every Story by Dyan Cannon and Willie Nelson

More Untyped Lambda Calculus & Simply Typed Lambda Calculus

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

SMT Proof Checking Using a Logical Framework

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

Concepts of programming languages

Formal Systems and their Applications

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

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

Mikiβ : A General GUI Library for Visualizing Proof Trees

The Next 700 Syntactic Models of Type Theory

Game Semantics for Dependent Types

We begin the chapter by looking at a few representative examples of where type-term dependency occurs naturally.

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

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

Sets. Sets. Subset, universe. Specifying sets, membership. Examples: Specifying a set using a predicate. Examples

the application rule M : x:a: B N : A M N : (x:a: B) N and the reduction rule (x: A: B) N! Bfx := Ng. Their algorithm is not fully satisfactory in the

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

Parametricity and Dependent Types

INCREMENTAL SOFTWARE CONSTRUCTION WITH REFINEMENT DIAGRAMS

Note that in this definition, n + m denotes the syntactic expression with three symbols n, +, and m, not to the number that is the sum of n and m.

dynamically typed dynamically scoped

Programming Languages and Compilers (CS 421)

Programming Languages Fall 2014

c constructor P, Q terms used as propositions G, H hypotheses scope identifier for a notation scope M, module identifiers t, u arbitrary terms

Coq quick reference. Category Example Description. Inductive type with instances defined by constructors, including y of type Y. Inductive X : Univ :=

One of a number of approaches to a mathematical challenge at the time (1930): Constructibility

The Implicit Calculus of Constructions

Efficient Substitution in Hoare Logic Expressions

Transcription:

Introduction to Type Theory August 2007 Types Summer School Bertinoro, It Herman Geuvers Nijmegen NL Lecture 2: Dependent Type Theory, Logical Framework 1

For λ : Direct representation (shallow embedding) of logic in type theory. Connectives each have a counterpart in the type theory: implication arrow type Logical rules have their direct counterpart in type theory λ-abstraction implication introduction application implication elimination Context declares assumptions 2

Second way of interpreting logic in type theory De Bruijn: Logical framework encoding or deep embedding of logic in type theory. Type theory used as a meta system for encoding ones own logic. Choose an appropriate context Γ L, in which the logic L (including its proof rules) is declared. Context used as a signature for the logic. Use the type system as the meta calculus for dealing with substitution and binding. 3

proof formula shallow embedding λx:a.x A A deep embedding imp intr A A λx:t A.x T(A A) Needed: : prop prop prop T : prop type imp intr : (A, B : prop)(t A T B) T(A B) imp el : (A, B : prop)t(a B) T A T B. Close to a Gödel like encoding of predicate logic in IN: Define a coding fuction for formulas and define Bew( ϕ, n) Define mp : IN IN IN such that x, y.bew( ϕ, x) Bew( ϕ ψ, y) Bew( ψ, mp(x, y) ) 4

Direct representation One type system : One logic Logical rules type theoretic rules Deep encoding One type system : Many logics Logical rules context declarations Plan: First show examples of logics in a logical framework Then define precisely the type theory of the logical framework Use type to denote the universe of types. The encoding of logics in a logical framework is shown by three examples: 1. Minimal proposition logic 2. Minimal predicate logic (just {, }) 3. Untyped λ-calculus 5

Minimal propositional logic Fix the signature (context) of minimal propositional logic. prop : type Notation: A B for imp A B imp : prop prop prop The type prop is the type of names of propositions. NB: A term of type prop can t be inhabited (proved), as it s not a type. We lift a name p : prop to the type of its proofs by introducing the following map: T : prop type. Intended meaning of Tp is the type of proofs of p. We interpret p is valid by Tp is inhabited. 6

To derive Tp we also encode the logical derivation rules imp intr : Πp, q : prop.(tp Tq) T(p q), imp el : Πp, q : prop.t(p q) Tp Tq. New phenomenon: Π-type: Πx:A.B(x) the type of functions f such that f a : B(a) for all a:a imp intr takes two (names of) propositions p and q and a term f : T p T q and returns a term of type T(p q) Indeed A A, becomes valid: imp intra A(λx:T A.x) : T(A A) Exercise: Construct a term of type T(A (B A)) 7

Define Σ PROP to be the signature for minimal proposition logic, PROP. Desired properties of the encoding: Adequacy (soundness) of the encoding: PROP A Σ PROP, a 1 :prop,...,a n :prop p : T A for some p. {a,...,a n } is the set of proposition variables in A. Proof by induction on the derivation of PROP A. Faithfulness (or completeness) is the converse. It also holds, but more involved to prove. 8

Minimal predicate logic over one domain A (just and Signature: prop : type, A : type, T : prop type f : A A, R : A A prop, : prop prop prop, imp intr : Πp, q : prop.(tp Tq) T(p q), imp el : Πp, q : prop.t(p q) Tp Tq. Now encode : takes a P : A prop and returns a proposition, so: : (A prop) prop 9

Minimal predicate logic over one domain A (just and Signature: Σ PRED prop : type, A : type,. : prop prop prop, imp intr : Πp, q : prop.(tp Tq) T(p q), imp el : Πp, q : prop.t(p q) Tp Tq. Now encode : takes a P : A prop and returns a proposition, so: : (A prop) prop Universal quantification is translated as follows. x:a.(p x) (λx:a.(p x)) 10

Intro and elim rules for : The proof of : (A prop) prop, intr : ΠP:A prop.(πx:a.t(p x)) T( P), elim : is now mirrored by the proof-term ΠP:A prop.t( P) Πx:A.T(P x). z:a( x, y:a.rxy) Rzz intr[ ]( λz:a.imp intr[ ][ ](λh:t( x, y:a.rxy). elim[ ]( elim[ ]hz)z) ) We have replaced the instantiations of the Π-type by [ ]. This term is of type T( (λz:a.imp( (λx:a.( (λy:a.rxy))))(rzz))) 11

Intro and elim rules for : : (A prop) prop, intr : ΠP:A prop.(πx:a.t(p x)) T( P), elim : ΠP:A prop.t( P) Πx:A.T(P x). The proof of z:a( x, y:a.rxy) Rzz is now mirrored by the proof-term intr[ ]( λz:a.imp intr[ ][ ](λh:t( x, y:a.rxy). elim[ ]( elim[ ]hz)z) ) Exercise: Construct a proof-term that mirrors the (obvious) proof of x(p x Q x) x.p x x.q x 12

Again one can prove adequacy PRED ϕ Σ PRED, x 1 :A,...,x n :A p : Tϕ, for some p, where {x 1,...,x n } is the set of free variables in ϕ. Faithfulness can be proved as well. 13

Logical Framework, LF, or λp Derive judgements of the form Γ M : B Γ is a context M and B are terms taken from the set of pseudoterms T ::= Var type kind TT λx:t.t Πx:T.T, Auxiliary judgement Γ denoting that Γ is a correct context. 14

Derivation rules of LF. (s ranges over {type,kind}.) (base) (ctxt) Γ A : s Γ, x:a if x not in Γ (ax) Γ Γ type : kind (proj) Γ Γ x : A if x:a Γ (Π) Γ, x:a B : s Γ A : type Γ Πx:A.B : s (λ) Γ, x:a M : B Γ Πx:A.B : s Γ λx:a.m : Πx:A.B (app) Γ M : Πx:A.B Γ N : A Γ MN : B[N/x] (conv) Γ M : B Γ A : s Γ M : A A = βη B Notation: write A B for Πx:A.B if x / FV(B). 15

The contexts Σ PROP and Σ PRED are well-formed. The Π rule allows to form two forms of function types. Γ, x:a B : s Γ A : type (Π) Γ Πx:A.B : s With s = type, we can form D D and Πx:D.x = x, etc. With s = kind, we can form D D type and prop type. 16

Untyped λ-calculus. Signature Σ lambda : D : app : abs : type; D (D D); (D D) D. Encoding of λ-terms as terms of type D. A variable x in λ-calculus becomes x : D in the type system. The translation [ ] : Λ Term(D) is defined as follows. [x] = x; [PQ] = app [P] [Q]; [λx.p] = abs (λx:d.[p]). Examples: [λx.xx] := abs(λx:d.app x x) [(λx.xx)(λy.y)] := app(abs(λx:d.app x x))(abs(λy:d.y)). 17

Introducing β-equality in Σ lambda : Notation P = Q for eq P Q. eq:d D type. Rules for proving equalities. refl : Πx:D.x = x, sym : Πx, y:d.x = y y = x, trans : Πx, y, z:d.x = y y = z x = z, mon : Πx, x, z, z :D.x = x z = z (app z x) = (app z x ), xi : Πf, g:d D.(Πx:D.(fx) = (gx)) (abs f) = (abs g), beta : Πf:D D.Πx:D.(app(abs f)x) = (f x). 18

Adequacy: P = β Q Σ lambda, x 1 :D,...,x n :D p : [P] = [Q], for some p. Here, x 1,...,x n are the free variables in PQ Faithfulness also holds. 19

Signature Σ lambda : D : type sym : Πx, y:d.x = y y = x, app : D (D D) trans : Πx, y, z:d.x = y y = z x = z, abs : (D D) D, mon : Πx, x, z, z :D.x = x z = z (app z x) = (ap eq : D D type, xi : Πf, g:d D.(Πx:D.(f x) = (gx)) (abs f) = (ab refl : Πx:D.x = x, beta : Πf:D D.Πx:D.(app(abs f)x) = (f x). Exercise: Prove (i.e. find a proof term of the associated type) (λx.x)y = β y Add an axiom for η-equality (λx.px = η P if x / FV(P)) to the context and the extensionality rule ( N(MN = PN M = N)) Prove that η follows from extensionality. 20

Properties of λp. Uniqueness of types If Γ M : σ and Γ M : τ, then σ= βη τ. Subject Reduction If Γ M : σ and M βη N, then Γ N : σ. Strong Normalization If Γ M : σ, then all βη-reductions from M terminate. Proof of SN is by defining a reduction preserving map from λp to λ. 21

Decidability Questions: Γ M : σ? Γ M :? Γ? : σ TCP TSP TIP For λp: TIP is undecidable TCP/TSP: simultaneously with Context checking 22

Type Checking Define algorithms Ok( ) and Type ( ) simultaneously: Ok( ) takes a context and returns true or false Type ( ) takes a context and a term and returns a term or false. The type synthesis algorithm Type ( ) is sound if Type Γ (M) = A Γ M : A for all Γ and M. The type synthesis algorithm Type ( ) is complete if Γ M : A Type Γ (M) = βη A for all Γ, M and A. 23

Ok(<>) = true Ok(Γ, x:a) = Type Γ (A) {type,kind}, Type Γ (x) = if Ok(Γ) and x:a Γ then A else false, Type Γ (type) = if Ok(Γ)then kind else false, Type Γ (MN) = if Type Γ (M) = C and Type Γ (N) = D then else if C β Πx:A.B and A = β D then B[N/x] else false false, 24

Type Γ (λx:a.m) = if Type Γ,x:A (M) = B then if Type Γ (Πx:A.B) {type,kind} then Πx:A.B else false else false, Type Γ (Πx:A.B) = if Type Γ (A) = type and Type Γ,x:A (B) = s then s else false 25

Soundness Completeness Type Γ (M) = A Γ M : A Γ M : A Type Γ (M) = βη A As a consequence: Type Γ (M) = false M is not typable in Γ NB 1. Completeness implies that Type terminates on all well-typed terms. We want that Type terminates on all pseudo terms. NB 2. Completeness only makes sense if we have uniqueness of types (Otherwise: let Type ( ) generate a set of possible types) 26

Termination: we want Type ( ) to terminate on all inputs. Interesting cases: λ-abstraction and application: Type Γ (λx:a.m) = if Type Γ,x:A (M) = B then else false, if Type Γ (Πx:A.B) {type,kind} then Πx:A.B else false! Recursive call is not on a smaller term! Replace the side condition if Type Γ (Πx:A.B) {type,kind} by and prove equivalent. if Type Γ (A) {type} 27

Termination: we want Type ( ) to terminate on all inputs. Interesting cases: λ-abstraction and application: Type Γ (MN) = if Type Γ (M) = C and Type Γ (N) = D then else if C β Πx:A.B and A = β D then B[N/x] else false false,! Need to decide β-reduction and β-equality! For this case, termination follows from soundness of Type and the decidability of equality on well-typed terms (using SN and CR). 28

Direct representation (shallow embedding) of PRED into λp Represent both the domains of the logic and the formulas as types. A : type, P : A type, R : A A type, Now is represented as and is represented as Π: x:a.p x Πx:A.P x Intro and elim rules are just λ-abstraction and application 29

Example A : type, R : A A type λz:a.λh:(πx, y:a.r xy).h z z : Πz:A.(Πx, y:a.r xy) R z z Exercise: Find terms of the following types (NB binds strongest) (Πx:A.P x Q x) (Πx:A.P x) Πx:A.Q x and (Πx:A.P x Πz.R z z) (Πx:A.P x) Πz:A.R z z). Also write down the contexts in which these terms are typed. 30