Lecture slides & distribution files:

Similar documents
Formal Semantics in Modern Type Theories: Is It Model-Theoretic, Proof-Theoretic or Both?

Overview. These lectures. Proposal. I. Typing and Modern Type Theories. Type-Theoretical Lexical Semantics

MTT-semantics is both model-theoretic and proof-theoretic. Zhaohui Luo Royal Holloway University of London

Calculus of Inductive Constructions

MTT-semantics is both model-theoretic and proof-theoretic. Zhaohui Luo Royal Holloway University of London

Dependent Record Types Revisited

Automata and Formal Languages - CM0081 Introduction to Agda

Programming Language Concepts: Lecture 19

Less naive type theory

Symmetry in Type Theory

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

Lecture 3: Typed Lambda Calculus and Curry-Howard

II. Judgements and -polymorphism

Programming Proofs and Proving Programs. Nick Benton Microsoft Research, Cambridge

Introduction to dependent types in Coq

λ calculus is inconsistent

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

ABriefOverviewofAgda A Functional Language with Dependent Types

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

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

Type checking in the presence of meta-variables

Dependent Record Types Revisited

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

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

Mathematics for Computer Scientists 2 (G52MC2)

Univalent fibrations in type theory and topology

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

Computer Science 190 (Autumn Term, 2010) Semantics of Programming Languages

The Implicit Calculus of Constructions

Lecture 5: The Untyped λ-calculus

5. Introduction to the Lambda Calculus. Oscar Nierstrasz

Combining Programming with Theorem Proving

Proofs-Programs correspondance and Security

Lexicografie computationala Feb., 2012

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

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

An Introduction to Polymorphic Lambda Calculus with Subtyping.

Reducibility method: an overview

Linear Dependent Types

The Untyped Lambda Calculus

Introduction to the Lambda Calculus. Chris Lomont

Embedding logics in Dedukti

As Natural as 0, 1, 2. Philip Wadler University of Edinburgh

Martin-Löf s Type Theory

Lambda Calculus. Concepts in Programming Languages Recitation 6:

The Untyped Lambda Calculus

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

VU Semantik von Programmiersprachen

Parametricity and Dependent Types

The Untyped Lambda Calculus

CITS3211 FUNCTIONAL PROGRAMMING

A Modern Perspective on Type Theory

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

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

Kripke-Style Contextual Modal Type Theory

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

CS-XXX: Graduate Programming Languages. Lecture 9 Simply Typed Lambda Calculus. Dan Grossman 2012

Using Signatures in Type Theory to Represent Situations

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...

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

A MECHANIZATION OF TYPE THEORY. Gerard P. HUBT IRIA - LABORIA Rocquencourt FRANCE

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

J. Barkley Rosser, 81, a professor emeritus of mathematics and computer science at the University of Wisconsin who had served in government, died

The Typed λ Calculus and Type Inferencing in ML

More Untyped Lambda Calculus & Simply Typed Lambda Calculus

Lecture 5 - Axiomatic semantics

Programming with Dependent Types Interactive programs and Coalgebras

COMP 1130 Lambda Calculus. based on slides by Jeff Foster, U Maryland

Eta-equivalence in Core Dependent Haskell

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

Typed Lambda Calculus for Syntacticians

Basic Foundations of Isabelle/HOL

Logical Verification Course Notes. Femke van Raamsdonk Vrije Universiteit Amsterdam

Introduction to Homotopy Type Theory

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

JOURNAL OF OBJECT TECHNOLOGY

Intuitionistic Type Theory

Sharing in the weak lambda-calculus

The type system of Axiom

Proof Documents: Presentation and Representation

Software System Design and Implementation

Lesson 11 Universal Types. Universal Types and System F

A Prolog-based Proof Tool for Type Theory TA λ and Implicational Intuitionistic-Logic

2.1 The λ-calculus Syntax

Types, Categories & Logic

Second-Order Type Systems

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

CS3110 Spring 2017 Lecture 9 Inductive proofs of specifications

The Logical Basis of Evaluation Order & Pattern-Matching

4.8 Dependent Types 97

Negations in Refinement Type Systems

A BRIEF INTRODUCTION TO TYPE THEORY AND THE UNIVALENCE AXIOM

Type Checking and Inference Are Equivalent in Lambda Calculi with Existential Types

1.3. Conditional expressions To express case distinctions like

A Quick Overview. CAS 701 Class Presentation 18 November Department of Computing & Software McMaster University. Church s Lambda Calculus

Typed Lambda Calculus

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

Runtime Behavior of Conversion Interpretation of Subtyping

Introduction to the λ-calculus

Mechanized metatheory revisited

Transcription:

Type Theory Lecture slides & distribution files: http://www.cs.rhul.ac.uk/home/zhaohui/ttlectures.html Zhaohui Luo Department of Computer Science Royal Holloway, University of London April 2011 2 Type theories as Type theory: a foundational and practical language for the working computer scientist. Logic + Computation Two fundamental features in single language Rich structural mechanisms Abstraction and modularisation Nice properties Basis for simple semantics and implementations Logical systems propositional, first-order, higher-order, intuitionaistic, classical,... Programming languages Functional programming (via λ-functions and computation) Modular programming (via rich type structures) Mathematical modelling calculus Formalisation of mathematics Natural language semantics April 2011 3 April 2011 4 Some applications of type theory Historical remarks Proof assistants for interactive theorem proving ALF/Agda (Sweden), Coq (France), Lego/Plastic (UK), Matita (Italy), NuPRL (USA),... Formalisation of mathematics (eg, four-colour theorem) Verification (eg, of security protocols) Dependently-typed programming Agda/Cayenne (Sweden), DML (USA), Epigram (UK), Dependent, richer types in programming languages Modelling in type theories Eg, linguistic reasoning with type-theoretical semantics (Leverhulme research project at Royal Holloway) Early development (from early 1900 s) Logical paradoxes (eg, S S if S = { x x x }?) Ramified type theory (Russell) Simple type theory (Ramsay 1926 & Church 1940) Modern development (since 1970 s) Martin-Löf s predicative type theory (Martin-Löf 1973, 1984) Impredicative type theories (with type Prop of all propositions) Polymorphic λ-calculi (F & F ω, Girard 1972, Reynolds 1974) Calculus of Constructions (CC, Coquand & Huet 1988) Unifying Theory of dependent Types (ECC/UTT, Luo 1989/1994) Calculus of Inductive Constructions (CIC, implemented in Coq) April 2011 5 April 2011 6

This lecture series Basics of type theory Introduction Embedded logics in type theories Inductive data types and universes Subtyping in type theory Coercive subtyping theory and implementation Applications (eg, in proof development and linguistic semantics) We shall start from the simplest TT the simply typed λ-calculus. I. Typed λ-calculi Type-free v.s. typed λ-calculi Type-free λ-calculus (Barendregt 1980) Type-free terms: x, λx.m, MN eg, Ω (λx.xx)(λx.xx) and Ω > β Ω. Typed λ-calculi Only well-typed terms are legal (eg, λx:a.x : A A). eg, Self-applications such as (λx:a.xx)(λx:a.xx) are not well-typed. Typed λ-calculus basis of type theory Example calculi: function types, dependent types, April 2011 7 April 2011 8 Simply typed λ-calculus: syntax Types ::= σ A B Intuitively, an object of A B is a function from A to B (eg, λ-functions). Terms ::= x λx:a.b f(a) Judgement Γ a : A means a is an object of type A under assumptions Γ, where Γ, called a context, is a finite set of entries of the form x:t. Eg, λx:nat.x : Nat Nat x:nat x+2 : Nat f : Nat Nat f(0) : Nat (?) f : Nat Nat f(f) : Nat Here, the first three are correct, not the fourth governed by the rules. Simply typed λ-calculus: inference rules Inference rules Correctness is given by derivability. A judgement J is derivable if there is a sequence of judgements J 1,, J n with J n J such that, for 1 i n, J i is the conclusion of some instance of a rule whose premises are all in {J j j < i }. Eg, f : Nat Nat f(0) : Nat is derivable; f : Nat Nat f(f) : Nat is not derivable. April 2011 9 April 2011 10 Computation: β-reduction Compatible relation >: If M > N, then λx:a.m > λx:a.n, M(a) > N(a), and f(m) > f(n). β-reduction > β is the reflexive and transitive closure of the least compatible relation satisfying (β): (β) (λx:a.b)(a) > β [a/x]b Eg, (λx:a. x+2)(3) > β 3+2 β-conversion = β is the corresponding equivalence. Meta-theoretic properties Properties of typing, computation and their relationship. Remarks: Properties held for all well-behaving calculi, but only illustrated here for the simply typed λ-calculus. These properties are the basis for Simple operational semantics (see canonical objects later) Implementations (of, eg, proof assistants) We now explain some example properties. April 2011 11 April 2011 12

Church-Rosser (CR) Subject reduction (SR) If M = β N, then P. M > β P and N > β P. Diamond property: an alternative formulation Equivalence between the two formulations Uniqueness of values (if they exist)! Remark: CR as a property of raw terms For some calculi, CR only holds for well-typed terms. Eg, for dependent types with type labels and βη-reduction, λx:a.(λy:b.y)(x) is not CR as a raw term, but CR if well-typed. If a : A and a > β b, then b : A. Computation preserves typing! When performing computation, there is no need to check well-typedness. Important for implementation April 2011 13 April 2011 14 Strong normalisation (SN) If a : A, then a is strongly normalisable. Every reduction sequence starting from any welltyped term is finite. Proof in Appendix 2 of (Hindley & Seldin 1986) Every computation terminates! Implications Usually implying logical consistency, ie, false is not provable. (cf, in FP languages: no consistent logic) Decidability and others Decidability Decidability of Type checking: Γ a : A? Type inference: Γ a :? Basis for implementations (of, eg, proof assistants) Remarks Compare this with the undecidability of a A in set theory. For dependent TTs, the above two problems are equivalent type checking requires type inference. April 2011 15 April 2011 16 More sophisticated types: higher-order Remark Higher-order types System F 2 nd -order polymorphic λ-calculus (Girard 1972, Reynolds 1974) 2 nd -order type X.X (or X:Type.X/ X:Prop.X), where X ranges over all types/propositions) Logical constant false System F ω (Girard 1972) Higher-order types: quantifications over connectives as well as propositions (eg, C:Prop Prop Prop. ) For (non-dependent) higher-order types, we still have Separation (syntactically) between terms and types (terms cannot occur in types/propositions). Eg, we cannot have P:Nat Prop.P(m) P(n) (ie, m and n are Leibniz equal.) To do this, we need dependen types. April 2011 17 April 2011 18

More sophisticated types: dependency Families of types types dependent on terms Per Martin-Löf 1970s-1980s (1973, 1984) Vect(n) type of lists of exactly n elements, a type depending on n : Nat m n proposition that depends on m, n : Nat. Π-types Informally, Πx:A.B(x) = { f for any a : A, f(a) : B(a) } (formal rules later) λx:nat.[1,,x] : Πx:Nat.Vect(x) x:nat.0 x Combining dependency & higher-order, we can have: P:Nat Prop.P(m) P(n). April 2011 19 April 2011 20 Σ-types Informally, Σx:A.B(x) = { (a,b) a : A & b : B(a) } Types of modules such as S : type, f : S S S : ΣS:type. S S S, where type is a type of types ( universe see later) Curry-style typed λ-calculus So far: Church-style Curry-style: an equivalent presentation for simply typed λ- calculus Terms ::= x λx.b f(a) (Var)(App) are the same, except Type assignment Eg, λx.x can be assigned α α for any type α (cf, in Church-style, λx:a.x must be of type A A.) Terms can be assigned many types or overloaded. Adopted in various programming languages such as ML/Haskell/ These are two very different styles. Only equivalent for simpler calculi, not for others April 2011 21 April 2011 22 Church-style v.s. Curry-style Revision Questions In appearance, only a syntactic difference of type labels: between λx:a.b and λx.b. In fact, much deeper two different views of types! Curry-style type assignment systems Objects exist first types are then assigned to objects. Overloading λ-terms, which may reside in different types. Church-style type theories with canonical objects Types and their objects co-exist. This is the kind of TTs we are about to study What are Simple types? Higher-order types? Dependent types? What are the meta-theoretic properties such CR, SR and SN? What are their theoretical and practical implications? What are the differences between type-free λ-calculus and typed λ-calculi? Church-style and Curry-style λ-calculi? April 2011 23 April 2011 24

Selected References H.P. Barendregt. The Lambda Calculus, Its Syntax and Semantics. Studies in Logic and the Foundations of Mathematics, Volume 103. 1980. H.P. Barendregt. Lambda-calculus with types. In Handbook of Logic in Computer Science. OUP, 1992. Th. Coquand and G. Huet. The calculus of constructions. Infor and Comp 76(2-3). 1988. J.-Y. Girard. PhD thesis,1972. J. Hindley and J. Seldin. Introduction to Combinators and λ-calculus. CUP, 1986. (2 nd edition in 2008 with a slightly different title) Z. Luo. Computation and Reasoning: A Type Theory for Computer Science. OUP, 1994. P. Martin-Löf. Intuitionistic Type Theory. Bibliopolis, 1984. J.C. Reynolds. Towards a theory of type structure. LNCS 19, 1974. M. Sorensen and P. Urzyczyn. Lectures on the Curry-Howard Isomorphism. Studies in Logic and the Foundations of Mathematics, Vol 149. Elsevier, 2006. April 2011 25