Introduction to Type Theory February 2008 Alpha Lernet Summer School Piriapolis, Uruguay. Herman Geuvers Nijmegen & Eindhoven, NL

Σχετικά έγγραφα
Proving with Computer Assistance Lecture 2. Herman Geuvers

About these lecture notes. Simply Typed λ-calculus. Types

Type Theory and Coq. Herman Geuvers. Principal Types and Type Checking

The Simply Typed Lambda Calculus

C.S. 430 Assignment 6, Sample Solutions

The λ-calculus. Lecturer: John Wickerson. Phil Wadler

Introduction to Type Theory February 2008 Alpha Lernet Summer School Piriapolis, Uruguay. Herman Geuvers Nijmegen & Eindhoven, NL

Lecture 2. Soundness and completeness of propositional logic

Overview. Transition Semantics. Configurations and the transition relation. Executions and computation

2 Composition. Invertible Mappings

EE512: Error Control Coding

λρ-calculus 1. each λ-variable is a λρ-term, called an atom or atomic term; 2. if M and N are λρ-term then (MN) is a λρ-term called an application;

3.4 SUM AND DIFFERENCE FORMULAS. NOTE: cos(α+β) cos α + cos β cos(α-β) cos α -cos β

HOMEWORK 4 = G. In order to plot the stress versus the stretch we define a normalized stretch:

Formal Semantics. 1 Type Logic

Finite Field Problems: Solutions

Dynamic types, Lambda calculus machines Section and Practice Problems Apr 21 22, 2016

A Lambda Model Characterizing Computational Behaviours of Terms

Foundations of Computer Science ENGR 3520 Fall 2013 Thursday, Nov 21, 2013

derivation of the Laplacian from rectangular to spherical coordinates

Section 8.3 Trigonometric Equations

From the finite to the transfinite: Λµ-terms and streams

Lecture 2: Dirac notation and a review of linear algebra Read Sakurai chapter 1, Baym chatper 3

Sequent Calculi for the Modal µ-calculus over S5. Luca Alberucci, University of Berne. Logic Colloquium Berne, July 4th 2008

CRASH COURSE IN PRECALCULUS

Fourier Series. MATH 211, Calculus II. J. Robert Buchanan. Spring Department of Mathematics

Ordinal Arithmetic: Addition, Multiplication, Exponentiation and Limit

4.6 Autoregressive Moving Average Model ARMA(1,1)

Section 7.6 Double and Half Angle Formulas

The challenges of non-stable predicates

Every set of first-order formulas is equivalent to an independent set

Finitary proof systems for Kozen s µ

CS-XXX: Graduate Programming Languages. Lecture 27 Higher-Order Polymorphism. Matthew Fluet 2012

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 19/5/2007

Fractional Colorings and Zykov Products of graphs

Problem Set 3: Solutions

Homework 3 Solutions

Εγχειρίδια Μαθηµατικών και Χταποδάκι στα Κάρβουνα

Arithmetical applications of lagrangian interpolation. Tanguy Rivoal. Institut Fourier CNRS and Université de Grenoble 1

Homomorphism in Intuitionistic Fuzzy Automata

Solutions to Exercise Sheet 5

Math221: HW# 1 solutions

Areas and Lengths in Polar Coordinates

Instruction Execution Times

Congruence Classes of Invertible Matrices of Order 3 over F 2

Phys460.nb Solution for the t-dependent Schrodinger s equation How did we find the solution? (not required)

The ε-pseudospectrum of a Matrix

Tridiagonal matrices. Gérard MEURANT. October, 2008

Jesse Maassen and Mark Lundstrom Purdue University November 25, 2013

Other Test Constructions: Likelihood Ratio & Bayes Tests

Lambda calculus. Part II Lambda Calculi with Types

Commutative Monoids in Intuitionistic Fuzzy Sets

ω ω ω ω ω ω+2 ω ω+2 + ω ω ω ω+2 + ω ω+1 ω ω+2 2 ω ω ω ω ω ω ω ω+1 ω ω2 ω ω2 + ω ω ω2 + ω ω ω ω2 + ω ω+1 ω ω2 + ω ω+1 + ω ω ω ω2 + ω

Statistical Inference I Locally most powerful tests

Chapter 6: Systems of Linear Differential. be continuous functions on the interval

Lecture 34 Bootstrap confidence intervals

Section 9.2 Polar Equations and Graphs

Abstract Storage Devices

6.3 Forecasting ARMA processes

Areas and Lengths in Polar Coordinates

Concrete Mathematics Exercises from 30 September 2016

Galatia SIL Keyboard Information

A Note on Intuitionistic Fuzzy. Equivalence Relation

Chapter 3: Ordinal Numbers

CHAPTER 25 SOLVING EQUATIONS BY ITERATIVE METHODS

Matrices and Determinants

CHAPTER 48 APPLICATIONS OF MATRICES AND DETERMINANTS

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 6/5/2006

Block Ciphers Modes. Ramki Thurimella

Απόκριση σε Μοναδιαία Ωστική Δύναμη (Unit Impulse) Απόκριση σε Δυνάμεις Αυθαίρετα Μεταβαλλόμενες με το Χρόνο. Απόστολος Σ.

Numerical Analysis FMN011

Homework 8 Model Solution Section

Nowhere-zero flows Let be a digraph, Abelian group. A Γ-circulation in is a mapping : such that, where, and : tail in X, head in

Durbin-Levinson recursive method

Second Order Partial Differential Equations

PARTIAL NOTES for 6.1 Trigonometric Identities

Approximation of distance between locations on earth given by latitude and longitude

LAP 2013 Problems in formulating the consecution calculus of contraction less relevant logics

5. Choice under Uncertainty

Affine Weyl Groups. Gabriele Nebe. Summerschool GRK 1632, September Lehrstuhl D für Mathematik

Partial Differential Equations in Biology The boundary element method. March 26, 2013

Econ 2110: Fall 2008 Suggested Solutions to Problem Set 8 questions or comments to Dan Fetter 1

TMA4115 Matematikk 3

Main source: "Discrete-time systems and computer control" by Α. ΣΚΟΔΡΑΣ ΨΗΦΙΑΚΟΣ ΕΛΕΓΧΟΣ ΔΙΑΛΕΞΗ 4 ΔΙΑΦΑΝΕΙΑ 1

Srednicki Chapter 55

Types and Logics. Programming Languages CS442. David Toman. School of Computer Science University of Waterloo

ADVANCED STRUCTURAL MECHANICS

b. Use the parametrization from (a) to compute the area of S a as S a ds. Be sure to substitute for ds!

If we restrict the domain of y = sin x to [ π, π ], the restrict function. y = sin x, π 2 x π 2

Distances in Sierpiński Triangle Graphs

SCITECH Volume 13, Issue 2 RESEARCH ORGANISATION Published online: March 29, 2018

ΓΡΑΜΜΙΚΟΣ & ΔΙΚΤΥΑΚΟΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ

Inverse trigonometric functions & General Solution of Trigonometric Equations

If we restrict the domain of y = sin x to [ π 2, π 2

Συντακτικές λειτουργίες

Lecture 15 - Root System Axiomatics

k A = [k, k]( )[a 1, a 2 ] = [ka 1,ka 2 ] 4For the division of two intervals of confidence in R +

ΕΠΙΧΕΙΡΗΣΙΑΚΗ ΑΛΛΗΛΟΓΡΑΦΙΑ ΚΑΙ ΕΠΙΚΟΙΝΩΝΙΑ ΣΤΗΝ ΑΓΓΛΙΚΗ ΓΛΩΣΣΑ

forms This gives Remark 1. How to remember the above formulas: Substituting these into the equation we obtain with

LTL to Buchi. Overview. Buchi Model Checking LTL Translating LTL into Buchi. Ralf Huuck. Buchi Automata. Example

Transcript:

Introduction to Type Theory February 2008 Alpha Lernet Summer School Piriapolis, Uruguay Herman Geuvers Nijmegen & Eindhoven, NL Lecture 1: Introduction, Overview, Simple Type Theory 1

Types and sets Types are not sets. Types are a bit like sets, but:... types give syntactic information 3 + (7 8) 5 : nat sets give semantic information 3 {n IN x, y, z IN + (x n + y n z n )} 2

Sets are about semantics 3 {n IN x, y, z IN + (x n + y n z n )} because there are no positive x, y, z such that x n + y n = z n [Wiles; Fermat s last Theorem ] set theory talks about what things exist (semantics, ontology). A set X such that for all sets Y with Y < X, 2 Y < X? sets are extensional: {n IN x, y, z IN + (x n + y n = z n )} = {0, 1, 2} sets are collections of things. membership is undecidable 3

Types are about syntax 3 + (7 8) 5 : nat because 3, 7, 8 are of type nat and the operations take objects of type nat to nat. 1 2 Σ n=02 n : IN is not a typing judgment. type theory talks about how things can be constructed (syntax, formal language, expressions) types are intensional {n x, y, z nat + (x n +y n z n )} {n n = 0 n = 1 n = 2} typing (and type checking) is decidable 4

Overview What I will be doing in these lectures. Problem: there are so many type systems and so many ways of defining them... Central theme: two readings of typing judments M : A M is a term (program, expression) of the data type A M is a proof (derivation) of the formula A Curry-Howard isomorphism of formulas-as-types (and proofs-as-terms) 5

Overview of these lectures 1. Simply typed λ-calculus (Simple Type Theory) and Curry Howard isomorphism 2. Simple Type Theory: Curry type assignment, principle type algorithm and normalization 3. Polymorphic type theory: full polymorphism and ML style polymorphism 4. Dependent type theory: logical framework and type checking algorithm 5. Higher order logic, inductive types and proof assistants based on type theory. 6

Simplest system: λ or STT Just arrow types Typ := TVar (Typ Typ) Examples: (α β) α, (α β) ((β γ) (α γ)) Brackets associate to the right and outside brackets are omitted: (α β) (β γ) α γ denotes (α β) ((β γ) (α γ)) Types are denoted by σ, τ,.... Terms: typed variables x σ 1, x σ 2,..., countably many for every σ. application: if M : σ τ and N : σ, then (MN) : τ abstraction: if P : τ, then (λx σ.p) : σ τ 7

Examples I σ := λx σ.x : σ σ K στ := λx σ.λy τ.x : σ τ σ λx α β.λy β γ.λz α.y(xz) : (α β) (β γ) α γ λx α.λy (β α) α.y(λz β.x) : α ((β α) α) α For λx α β.λy β γ.λz α.y(xz): If x : α β, y : β γ and z : α, then xz : β, so y(xz) : γ, so λz α.y(xz) : α γ, so λy β γ.λz α.y(xz) : (β γ) α γ, so λx α β.λy β γ.λz α.y(xz) : (α β) (β γ) α γ 8

Notation In λ-calculus (and type theory) we have some special notational conventions: λ-abstraction: - we write λx σ.λy τ.m or even λx σ y τ.m for λx σ.(λy σ.m) Function application: - we write (F M) (and not F(M))! - in multiple applications, F M N denotes (F M) N (and not F (M N)). Brackets associate to the left in applications. Types: - we write σ τ ρ for σ (τ ρ). Brackets associate to the right in types. 9

Notation Conventions about types and applications fit together nicely: If F : σ τ ρ, M : σ and P : τ, then F M : τ ρ and F M P : ρ NB Every type of STT can be written as with α a type variable σ 1 σ 2... α NB Functions of multiple arguments are dealt with by Currying: We don t have F : σ τ ρ but instead we use F : σ τ ρ 10

Computation A λ-term of the form (λx σ.m)p is a β-redex (reducible expression). A redex can be contracted: (λx σ.m)p β M[x := P] M[x := P] denotes M with P substituted for x Example (λx σ.λy τ.x)p β λy τ.p But what if P = y? then This is clearly not what we want. (λx σ.λy τ.x)y β λy τ.y!! The λ is a binder and we have to make sure that free variables don t get bound by a substitution. Solution: Remaning of bound variables before substitution 11

Free and bound variables and α-conversion FV(x) = {x} BV(x) = FV(MN) = FV(M) FV(N) BV(MN) = BV(M) BV(N) FV(λx σ.m) = FV(M) \ {x} BV(λx σ.m) = BV(M) {x} Definition M N or M = α N if M is equal to N modulo renaming of bound variables Examples: λx σ.λy τ.x λx σ.λz τ.x λx σ.λy τ.x λy σ.λx τ.y NB also: λx σ.λy τ.y λx σ.λx τ.x 12

We work modulo α-conversion We consider terms modulo α-equality, so we don t distinguish between λx σ.λy τ.x and λx σ.λz τ.x. In examples we always rename bound variables such that no clashes can arise. This is known as the Barendregt convention Before reduction or substitution, we rename (if necessary): (λx σ.λy τ.x)y (λx σ.λz τ.x)y β λz τ.y Notation: β is the transitive reflexive closure of β, = β is the transitive reflexive symmetric closure of β. 13

Examples of computation with simple typed terms The type (σ σ) σ σ is called the type of numerals over σ: n := λf σ σ.λx σ.f n (x) where So 2 := λf σ σ.λx σ.f(f x) f n (x) denotes f(...f(f }{{} n times f x)) λz σ. 2I σ z λz σ.(λf σ σ.λx σ.f(f x))i σ z β λz σ.(λx σ.i σ (I σ x))z β λz σ.i σ (I σ z) β β λz σ.i σ z λz σ.z I σ 14

Examples of computation with simple typed terms S := λx σ σ σ.λy σ σ.λz σ.xz(y z) : (σ σ σ) (σ σ) σ σ Then SK σσ I σ : σ σ and SK σσ I σ β (λy σ σ.λz σ.k σσ z(y z))i σ There are several ways of reducing this term further: (λy σ σ.λz σ.k σσ z(y z))i σ K σσ z is a redex is a redex 15

Example ctd (λy σ σ.λz σ.k σσ z(y z))i σ β λz σ.k σσ z(i σ z) λz σ.(λp σ, q σ.p) z(i σ z) β λz σ.(λq σ.z) (I σ z) Call by Value β λz σ.(λq σ.z)z β λz σ.z But also (λy σ σ.λz σ.k σσ z(y z))i σ (λy σ σ.λz σ.(λp σ, q σ.p) z(y z))i σ β (λy σ σ.λz σ.(λq σ.z)(y z)i σ Call by Name β (λy σ σ.λz σ.z)i σ β λz σ.z 16

Properties of reduction in STT Subject Reduction If M : σ and M β P, then P : σ. Church-Rosser If M is well-typed and M β P and M β N, then there is a Q such that P β Q and N β Q. Strong Normalisation If M is well-typed, then there is no infinite β-reduction path starting from M. 17

Different presentations of STT Inductive definition of the terms: typed variables x σ 1, x σ 2,..., countably many for every σ. application: if M : σ τ and N : σ, then (MN) : τ abstraction: if P : τ, then (λx σ.p) : σ τ Alternative: Inductive definition of the terms in rule form: x σ : σ M : σ τ N : σ MN : τ P : τ λx σ.p : σ τ Advantage: We also have a derivation tree, a proof of the fact that the term has that type. We can reason over derivations. 18

Simple type theory a la Church Formulation with contexts to declare the free variables: x 1 : σ 1, x 2 : σ 2,...,x n : σ n is a context, usually denoted by Γ. Derivation rules of λ (à la Church): x:σ Γ Γ x : σ Γ M : σ τ Γ N : σ Γ MN : τ Γ, x:σ P : τ Γ λx:σ.p : σ τ Γ λ M : σ if there is a derivation using these rules with conclusion Γ M : σ 19

Formulas-as-Types (Curry, Howard) There are two readings of a judgement M : σ 1. term as algorithm/program, type as specification: M is a function of type σ 2. type as a proposition, term as its proof: M is a proof of the proposition σ There is a one-to-one correspondence: typable terms in λ derivations in minimal proposition logic The judgement x 1 : τ 1, x 2 : τ 2,...,x n : τ n M : σ can be read as M is a proof of σ from the assumptions τ 1, τ 2,...,τ n. 20

Example [α β γ] 3 [α] 1 β γ γ 1 α γ (α β) α γ [α β] 2 [α] 1 β (α β γ) (α β) α γ 2 3 λx:α β γ.λy:α β.λz:α.xz(yz) : (α β γ) (α β) α γ 21

Example [x : α β γ] 3 [z : α] 1 xz : β γ xz(yz) : γ λz:α.xz(yz) : α γ [y : α β] 2 [z : α] 1 1 yz : β λy:α β.λz:α.xz(yz) : (α β) α γ λx:α β γ.λy:α β.λz:α.xz(yz) : (α β γ) (α β) α γ Exercise: Add types to the λ-abstractions) and give the derivation that corresponds to λx.λy.y(λz.y x) : (γ ε) ((γ ε) ε) ε 2 3 22

Computation Cut-elimination in minimal logic = β-reduction in λ. [σ] 1 D 1 τ 1 σ τ τ [x : σ] 1 D 1 D 2 σ M : τ D 2 1 λx:σ.m : σ τ P : σ (λx:σ.m)p : τ β D 2 σ D 1 τ D 2 P : σ D 1 M[x := P] : τ 23

Example: Proof of A A B, (A B) A B [A] 1 A A B [A] 1 A B B A B (A B) A [A] 1 A A B [A] 1 A B A B A B It contains a cut: a -i directly followed by an -e. B 24

Example: Proof of A A B, (A B) A B after reduction [A] 1 A A B [A] 1 A B [A] 1 A A B [A] 1 A B B B (A B) A A B (A B) A A B A A A B A A B B 25

Example: Proof of A A B, (A B) A B with term information [x : A] 1 p : A A B [x : A] 1 p x : A B p xx : B λx:a.p xx : A B q : (A B) A (λx:a.p xx)(q(λx:a.p xx)) : B Term contains a β-redex: (λx:a.p x x) (q(λx:a.p x x)) [x : A] 1 p : A A B [x : A] 1 p x : A B p xx : B λx:a.p xx : A B q(λx:a.p xx) : A 26

Example: Reduced proof of A A B, (A B) A B with term info [x : A] 1 p : A A B [x : A] 1 p : A A B [x : A] 1 p x : A B [x : A] 1 p x : A B p x x : B p x x : B q : (A B) A λx:a.p x x : A B q : (A B) A λx:a.p x x : A B q(λx:a.p x x) : A p : A A B q(λx:a.p x x) : A p(q(λx:a.p x x)) : A B p(q(λx:a.p x x))(q(λx:a.p x x)) : B 27