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

Σχετικά έγγραφα
The Simply Typed Lambda Calculus

Proving with Computer Assistance Lecture 2. Herman Geuvers

Formal Semantics. 1 Type Logic

C.S. 430 Assignment 6, Sample Solutions

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

A Lambda Model Characterizing Computational Behaviours of Terms

Ordinal Arithmetic: Addition, Multiplication, Exponentiation and Limit

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

The challenges of non-stable predicates

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

Lambda calculus. Part II Lambda Calculi with Types

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;

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

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

2 Composition. Invertible Mappings

Αλγόριθμοι και πολυπλοκότητα NP-Completeness (2)

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

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

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

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

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

Reminders: linear functions

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

Matrices and Determinants

5. Choice under Uncertainty

derivation of the Laplacian from rectangular to spherical coordinates

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

Other Test Constructions: Likelihood Ratio & Bayes Tests

Congruence Classes of Invertible Matrices of Order 3 over F 2

Second Order Partial Differential Equations

Lecture 2. Soundness and completeness of propositional logic

CRASH COURSE IN PRECALCULUS

Example Sheet 3 Solutions

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

The ε-pseudospectrum of a Matrix

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

ANSWERSHEET (TOPIC = DIFFERENTIAL CALCULUS) COLLECTION #2. h 0 h h 0 h h 0 ( ) g k = g 0 + g 1 + g g 2009 =?

Abstract Storage Devices

Section 8.3 Trigonometric Equations

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

4.6 Autoregressive Moving Average Model ARMA(1,1)

Homework 8 Model Solution Section

Inverse trigonometric functions & General Solution of Trigonometric Equations

Section 9.2 Polar Equations and Graphs

Statistical Inference I Locally most powerful tests

Math 6 SL Probability Distributions Practice Test Mark Scheme

Bounding Nonsplitting Enumeration Degrees

Chapter 3: Ordinal Numbers

Finite Field Problems: Solutions

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

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

ORDINAL ARITHMETIC JULIAN J. SCHLÖDER

Solutions to Exercise Sheet 5

Fractional Colorings and Zykov Products of graphs

DESIGN OF MACHINERY SOLUTION MANUAL h in h 4 0.

SOLUTIONS TO MATH38181 EXTREME VALUES AND FINANCIAL RISK EXAM

Lecture 34 Bootstrap confidence intervals

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

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

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

Math 446 Homework 3 Solutions. (1). (i): Reverse triangle inequality for metrics: Let (X, d) be a metric space and let x, y, z X.

ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΥΠΡΟΥ ΤΜΗΜΑ ΠΛΗΡΟΦΟΡΙΚΗΣ. ΕΠΛ342: Βάσεις Δεδομένων. Χειμερινό Εξάμηνο Φροντιστήριο 10 ΛΥΣΕΙΣ. Επερωτήσεις SQL

Quadratic Expressions

SOLUTIONS TO MATH38181 EXTREME VALUES AND FINANCIAL RISK EXAM

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

Jesse Maassen and Mark Lundstrom Purdue University November 25, 2013

Testing for Indeterminacy: An Application to U.S. Monetary Policy. Technical Appendix

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

2. Let H 1 and H 2 be Hilbert spaces and let T : H 1 H 2 be a bounded linear operator. Prove that [T (H 1 )] = N (T ). (6p)

MINIMAL CLOSED SETS AND MAXIMAL CLOSED SETS

ST5224: Advanced Statistical Theory II

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

ΕΛΛΗΝΙΚΗ ΔΗΜΟΚΡΑΤΙΑ ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΡΗΤΗΣ. Ψηφιακή Οικονομία. Διάλεξη 7η: Consumer Behavior Mαρίνα Μπιτσάκη Τμήμα Επιστήμης Υπολογιστών

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

Trigonometric Formula Sheet

T λx. (λy. x) F λx. (λy. y) if λpca. pca

Solution Series 9. i=1 x i and i=1 x i.

Tridiagonal matrices. Gérard MEURANT. October, 2008

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

Uniform Convergence of Fourier Series Michael Taylor

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

Numerical Analysis FMN011

Math221: HW# 1 solutions

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

Lecture 15 - Root System Axiomatics

Capacitors - Capacitance, Charge and Potential Difference

Solutions to the Schrodinger equation atomic orbitals. Ψ 1 s Ψ 2 s Ψ 2 px Ψ 2 py Ψ 2 pz

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

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

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

Instruction Execution Times

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

CHAPTER 25 SOLVING EQUATIONS BY ITERATIVE METHODS

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

12. Radon-Nikodym Theorem

Section 7.6 Double and Half Angle Formulas

F19MC2 Solutions 9 Complex Analysis

An Inventory of Continuous Distributions

Section 1: Listening and responding. Presenter: Niki Farfara MGTAV VCE Seminar 7 August 2016

Transcript:

About these lecture notes Simply Typed λ-calculus Akim Demaille akim@lrde.epita.fr EPITA École Pour l Informatique et les Techniques Avancées Many of these slides are largely inspired from Andrew D. Ker s lecture notes [Ker, 2005a, Ker, 2005b]. Some slides are even straightforward copies. June 14, 2016 A. Demaille Simply Typed λ-calculus 2 / 46 Simply Typed λ-calculus Untyped λ-calculus Paradoxes Church vs. Curry A. Demaille Simply Typed λ-calculus 3 / 46 A. Demaille Simply Typed λ-calculus 4 / 46

first appeared with Curry (1934) for Combinatory Logic Church (1940) are syntactic objects assigned to terms: M : A M has type A For instance: I : A A Alonzo Church (1903 1995) Haskell Curry (1900 1982) A. Demaille Simply Typed λ-calculus 5 / 46 A. Demaille Simply Typed λ-calculus 6 / 46 Untyped λ-calculus λ-terms Untyped λ-calculus Paradoxes Church vs. Curry Λ, set of λ-terms x V x Λ M Λ N Λ (MN) Λ M Λ x V (λx M) Λ A. Demaille Simply Typed λ-calculus 7 / 46 A. Demaille Simply Typed λ-calculus 8 / 46

λβ Properties of λβ The λβ Formal System M = N M = N N = L M = M N = M M = L M = M N = N M = N MN = M N λx M = λx N (λx M)N = [N/x]M β-reduction is Church-Rosser. Any term has (at most) a unique NF. β-reduction is not normalizing. Some terms have no NF (Ω). A. Demaille Simply Typed λ-calculus 9 / 46 A. Demaille Simply Typed λ-calculus 10 / 46 Paradoxes Self application Untyped λ-calculus Paradoxes Church vs. Curry What is the computational meaning of λx xx? Stop considering anything can be applied to anything A function and its argument have different behaviors A. Demaille Simply Typed λ-calculus 11 / 46 A. Demaille Simply Typed λ-calculus 12 / 46

Church vs. Curry Simple Untyped λ-calculus Paradoxes Church vs. Curry A set of type variables α, β,... A symbol for functions α α, α (β γ), (α β) γ,... Possibly constants for primitive types ι for integers, etc. A. Demaille Simply Typed λ-calculus 13 / 46 A. Demaille Simply Typed λ-calculus 14 / 46 Simple Alonzo Style, or Haskell Way? By convention is right-associative: α β γ = α (β γ) This matches the right-associativity of λ: λx λy M = λx (λy M) Church: Typed λ-calculus x : α λx α x : α α Curry: λ-calculus with x : α λx x : α α A. Demaille Simply Typed λ-calculus 15 / 46 A. Demaille Simply Typed λ-calculus 16 / 46

λ : Type Assignments Reducibility Reducibility A. Demaille Simply Typed λ-calculus 17 / 46 A. Demaille Simply Typed λ-calculus 18 / 46 Simple Type Contexts T V a set of type variables α, β,... Simple The set T of types σ, τ,...: α T V α T σ T τ T (σ τ) T Statement A statement M : σ is a pair with M Λ, σ T. M is the subject, σ the predicate. Type Context, Basis A type context Γ is a finite set of statements over distinct variables {x 1 : σ 1,...}. Assignment The variable x is assigned the type σ in Γ iff x : σ Γ. A. Demaille Simply Typed λ-calculus 19 / 46 A. Demaille Simply Typed λ-calculus 20 / 46

Type Contexts Type Context Restrictions Γ x is the Γ with all assignment x : σ removed. Γ M is Γ FV(M). Reducibility A. Demaille Simply Typed λ-calculus 21 / 46 A. Demaille Simply Typed λ-calculus 22 / 46 A Natural Presentation Type Statement Type derivations are trees built from the following nodes. [x : σ] M : σ τ N : σ MN : τ M : τ λx M : σ τ Type Statement A statement M : σ is derivable from the type context Γ, Γ M : σ if there is a derivation of M : σ whose non-canceled assumptions are in Γ. A. Demaille Simply Typed λ-calculus 23 / 46 A. Demaille Simply Typed λ-calculus 24 / 46

Type Statements Type Statements Prove λfx f (fx) : (σ σ) σ σ Prove λxy x : σ τ σ (2) [f : σ σ] [f : σ σ] (2) f (fx) : σ (1) λx f (fx) : σ σ fx : σ λfx f (fx) : (σ σ) σ σ [x : σ] (1) (2) [x : σ] (1) λy x : τ σ (1) λxy x : σ τ σ A. Demaille Simply Typed λ-calculus 25 / 46 A. Demaille Simply Typed λ-calculus 26 / 46 Alternative Presentation of Type Derivations Type Statements Type Derivations {x : σ} x : σ Γ M : σ τ N : σ Γ MN : τ Γ M : τ Γ \ {x : σ} λx M : σ τ Γ M : τ Γ, M : τ Γ, consistent Γ, {x : σ} consistent Prove λxy x : σ τ σ {x : σ} x : σ [x : σ] (1) {x : σ} λy x : τ σ λy x : τ σ (1) λxy x : σ τ σ λxy x : σ τ σ A. Demaille Simply Typed λ-calculus 27 / 46 A. Demaille Simply Typed λ-calculus 28 / 46

Type Statements Type ω = λx xx. λx xx : σ {x : σ 1 } xx : σ 2 σ = σ1 σ 2 λx xx : σ A term M is typable if there exists a type σ such that M : σ. ω, Ω are not typable. S, K, I are typable. Y is not typable! {x : σ 1 } x : τ σ 2 {x : σ 1 } x : τ {x : σ 1 } xx : σ 2 σ = σ1 σ 2 λx xx : σ A. Demaille Simply Typed λ-calculus 29 / 46 A. Demaille Simply Typed λ-calculus 30 / 46 Subject Construction Lemma I Subject Construction Lemma I Consider the derivation π for M : σ. If M = x, then Γ = {x : σ} and π = {x : σ} x : σ If M = NL, then π = Γ N N : τ σ Γ L L : τ Γ NL : σ Consider the derivation π for M : σ. If M = λx N, then σ = σ 1 σ 2 and If x FV(N) If x FV(N) π = Γ {x : σ 1} N : σ 2 Γ λx N : σ 1 σ 2 Γ N : σ 2 π = Γ λx N : σ 1 σ 2 A. Demaille Simply Typed λ-calculus 31 / 46 A. Demaille Simply Typed λ-calculus 32 / 46

Derivations are not Unique They are for β-normal forms. Reducibility A. Demaille Simply Typed λ-calculus 33 / 46 A. Demaille Simply Typed λ-calculus 34 / 46 Conversions and α-invariance If Γ M : σ and M α N then Γ N : σ. Substitution If then Γ {x : τ} M : σ, N : τ, Γ, consistent, x FV(N) Γ [N/x]M : σ If Γ M : σ and M β N then Γ N : σ. What about the converse? Subject Expansion If Γ N : σ and M β N then Γ M : σ. Ω is not typable, but KI Ω I. A. Demaille Simply Typed λ-calculus 35 / 46 A. Demaille Simply Typed λ-calculus 36 / 46

Reducibility and Normalization Reducibility λ is Strongly Normalizing All typable terms are β-strongly normalizing. A. Demaille Simply Typed λ-calculus 37 / 46 A. Demaille Simply Typed λ-calculus 38 / 46 M : σ suffices Reducibility Note that with Γ = {x 1 : σ 1,..., x n : σ n } Γ M : τ is equivalent to λx 1... x n M : σ 1... σ n τ A. Demaille Simply Typed λ-calculus 39 / 46 A. Demaille Simply Typed λ-calculus 40 / 46

Decidability of Type Assignment Decidability of Type Assignment Type checking Given M, σ, does M : σ? M : σ? Given M, does there exist σ such that M : σ? M :? Inhabitation Given σ, does there exist M such that M : σ? Type Checking is Decidable It is decidable whether a statement of λ is provable. is Decidable It is decidable whether a term of λ has a type.? : σ A. Demaille Simply Typed λ-calculus 41 / 46 A. Demaille Simply Typed λ-calculus 42 / 46 are not Unique... are not Unique... but some are more Unique than others... Typable terms do not have unique types. {x : σ} x : σ {x : σ} λy x : τ σ K : σ τ σ is valid for any σ, τ, including σ = σ σ, τ = (τ τ ) τ etc. All the types of K are instances of σ τ σ. A. Demaille Simply Typed λ-calculus 43 / 46 A. Demaille Simply Typed λ-calculus 44 / 46

Bibliography Notes Bibliography I [Ker, 2005a] Complete and readable lecture notes on λ-calculus. Uses conventions different from ours. [Ker, 2005b] Additional information, including slides. [Barendregt and Barendsen, 2000] A classical introduction to λ-calculus. Barendregt, H. and Barendsen, E. (2000). Introduction to lambda calculus. http: //www.cs.ru.nl/~erikb/onderwijs/t3/materiaal/lambda.pdf. Ker, A. D. (2005a). Lambda calculus and types. http://web.comlab.ox.ac.uk/oucl/work/andrew.ker/ lambda-calculus-notes-full-v3.pdf. Ker, A. D. (2005b). Lambda calculus notes. http://web.comlab.ox.ac.uk/oucl/work/andrew.ker/. A. Demaille Simply Typed λ-calculus 45 / 46 A. Demaille Simply Typed λ-calculus 46 / 46