λ calculus is inconsistent

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

type classes & locales

Theorem Proving Principles, Techniques, Applications Recursion

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

A CRASH COURSE IN SEMANTICS

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

The Typed λ Calculus and Type Inferencing in ML

Integration of SMT Solvers with ITPs There and Back Again

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

Concepts of programming languages

Basic Foundations of Isabelle/HOL

Review. CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Let bindings (CBV) Adding Stuff. Booleans and Conditionals

locales ISAR IS BASED ON CONTEXTS CONTENT Slide 3 Slide 1 proof - fix x assume Ass: A. x and Ass are visible Slide 2 Slide 4 inside this context

Organisatorials. About us. Binary Search (java.util.arrays) When Tue 9:00 10:30 Thu 9:00 10:30. COMP 4161 NICTA Advanced Course

Formal Systems and their Applications

COMP4161: Advanced Topics in Software Verification. fun. Gerwin Klein, June Andronick, Ramana Kumar S2/2016. data61.csiro.au

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages. Lambda calculus

Lambda Calculus and Type Inference

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

Lambda Calculus. Variables and Functions. cs3723 1

Exercise 1 (2+2+2 points)

CSE-321 Programming Languages 2011 Final

Harvard School of Engineering and Applied Sciences Computer Science 152

Lecture 9: More Lambda Calculus / Types

- M ::= v (M M) λv. M - Impure versions add constants, but not necessary! - Turing-complete. - true = λ u. λ v. u. - false = λ u. λ v.

Exercise 1 ( = 22 points)

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

CSE505, Fall 2012, Midterm Examination October 30, 2012

CS 4110 Programming Languages & Logics. Lecture 17 Programming in the λ-calculus

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.

Programming Language Concepts: Lecture 19

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

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

Goal. CS152: Programming Languages. Lecture 15 Parametric Polymorphism. What the Library Likes. What The Client Likes. Start simpler.

Grades. 10% - participation & exercises. 90% - term paper

11/6/17. Outline. FP Foundations, Scheme. Imperative Languages. Functional Programming. Mathematical Foundations. Mathematical Foundations

Programming Languages Lecture 14: Sum, Product, Recursive Types

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

COMP 4161 Data61 Advanced Course. Advanced Topics in Software Verification. Gerwin Klein, June Andronick, Christine Rizkallah, Miki Tanaka

5. Introduction to the Lambda Calculus. Oscar Nierstrasz

Exercise 1 ( = 24 points)

Recursive Definitions, Fixed Points and the Combinator

The Untyped Lambda Calculus

λ-calculus Lecture 1 Venanzio Capretta MGS Nottingham

Functional Languages and Higher-Order Functions

CITS3211 FUNCTIONAL PROGRAMMING

Introduction to the Lambda Calculus. Chris Lomont

We defined congruence rules that determine the order of evaluation, using the following evaluation

The Polymorphic Blame Calculus and Parametricity

The Untyped Lambda Calculus

9/23/2014. Why study? Lambda calculus. Church Rosser theorem Completeness of Lambda Calculus: Turing Complete

If a program is well-typed, then a type can be inferred. For example, consider the program

Lambda Calculus and Extensions as Foundation of Functional Programming

CSE-321 Programming Languages 2012 Midterm

CS 4110 Programming Languages & Logics. Lecture 28 Recursive Types

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

Programming Languages

Untyped Lambda Calculus

Introduction to System F. Lecture 18 CS 565 4/20/09

Lecture slides & distribution files:

Preuves Interactives et Applications

Second-Order Type Systems

Lambda Calculus and Type Inference

1 Introduction. 3 Syntax

Introduction to the Lambda Calculus

Introduction to Lambda Calculus. Lecture 7 CS /08/09

Calculus of Inductive Constructions

Untyped Lambda Calculus

4. The λ-calc. with Prod. and Conj.

Activity. CSCI 334: Principles of Programming Languages. Lecture 4: Fundamentals II. What is computable? What is computable?

CSE-321 Programming Languages 2014 Final

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

CSE-321 Programming Languages 2010 Midterm

Polymorphism. Lecture 19 CS 565 4/17/08

Pure Lambda Calculus. Lecture 17

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

CSE-321 Programming Languages 2010 Final

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

Programming Language Features. CMSC 330: Organization of Programming Languages. Turing Completeness. Turing Machine.

CMSC 330: Organization of Programming Languages

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

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

lambda calculus History 11/28/13 Jianguo Lu A formal system designed to inves:gate func:on defini:on, func:on applica:on, and recursion.

1 Scope, Bound and Free Occurrences, Closed Terms

Exercise 1 ( = 18 points)

Mechanized metatheory revisited

CSE 3302 Programming Languages Lecture 8: Functional Programming

First-Class Type Classes

Polymorphism and Type Inference

CSE 505: Concepts of Programming Languages

Chapter 5: The Untyped Lambda Calculus

Coq with Classes. Matthieu Sozeau. Journées PPS 2011 September 5th 2011 Trouville, France. Project Team πr 2 INRIA Paris

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

Kripke-Style Contextual Modal Type Theory

上海交通大学试卷 ( A 卷 ) ( 2015 至 2016 学年第 2 学期 )

CMPUT 325 : Lambda Calculus Basics. Lambda Calculus. Dr. B. Price and Dr. R. Greiner. 13th October 2004

Lambda Calculus. Concepts in Programming Languages Recitation 6:

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

Type assignment for intersections and unions in call-by-value languages

> module Lambda where > import Data.List -- I need some standard list functions

Transcription:

Content Rough timeline COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification Gerwin Klein, June Andronick, Toby Murray λ Intro & motivation, getting started [1] Foundations & Principles Lambda Calculus, natural deduction [2,3,4 a ] Higher Order Logic [5,6 b,7] Term rewriting [8,9,10 c ] Proof & Specification Techniques Isar [11,12 d ] Inductively defined sets, rule induction [13 e,15] Datatypes, recursion, induction [16,17 f,18,19] Calculational reasoning, mathematics style proofs [20] Hoare logic, proofs about programs [21 g,22,23] a a1 out; b a1 due; c a2 out; d a2 due; e session break; f a3 out; g a3 due Slide 1 Slide 3 Exercises from last time λ calculus is inconsistent Reduce (λx. y (λv. x v)) (λy. v y) to βη normal form. Find an encoding for function fs, sn, and pair such that fs (pair a b) = β a and sn (pair a b) = β b. (harder) Find an encoding of list objects, i.e. for the function cons and nil. Then find an encoding for map (that is, map f [x 1,...,x n] = [f x 1,...,f x n]), and for foldl (that is, foldl f i [x 1,...,x n] = f x 1 (f x 2 (f x 3 (...(f x n i)))...)) Can find term R such that R R = β not(r R) There are more terms that do not make sense: 1 2, true false, etc. Solution: rule out ill-formed terms by using types. (Church 1940) Slide 2 Slide 4 1 2

Introducing types Idea: assign a type to each sensible λ term. Examples: for term t has type α write t :: α if x has type α then λx. x is a function from α to α Write: (λx. x) :: α a for s t to be sensible: s must be function t must be right type for parameter NOW FORMALLY AGAIN If s :: α β and t :: α then (s t) :: β Slide 5 Slide 7 Syntax for λ Terms: t ::= v c (t t) (λx. t) v,x V, c C, V,C sets of names Types: τ ::= b ν τ τ b {bool, int,...} base types ν {α,β,...} type variables THAT S ABOUT IT α β γ = α (β γ) Context Γ: Γ: function from variable and constant names to types. Term t has type τ in context Γ: Γ t :: τ Slide 6 Slide 8 3 4

Examples Example Type Derivation: Γ (λx. x) :: α α [y int] y :: int [z bool] (λy. y) z :: bool [] λf x. f x :: (α β) α β A term t is well typed or type correct if there are Γ and τ such that Γ t :: τ [x α,y β] x :: α [x α] λy. x :: β α [] λx y. x :: α β α Slide 9 Slide 11 Type Checking Rules More complex Example Variables: Application: Abstraction: Γ x :: Γ(x) Γ t 1 :: τ 2 τ 1 Γ t 2 :: τ 2 Γ (t 1 t 2 ) :: τ 1 Γ[x τ 1 ] t :: τ 2 Γ (λx. t) :: τ 1 τ 2 Γ f :: α (α β) Γ x :: α Γ f x :: α β Γ x :: α Γ f x x :: β [f α α β] λx. f x x :: α β [] λf x. f x x :: (α α β) α β Γ = [f α α β,x α] Slide 10 Slide 12 5 6

More general Types A term can have more than one type. What about β reduction? Definition of β reduction stays the same. Example: [] λx. x :: bool bool [] λx. x :: α α Fact: Well typed terms stay well typed during β reduction Some types are more general than others: Formally: Γ s :: τ s β t = Γ t :: τ τ σ if there is a substitution S such that τ = S(σ) This property is called subject reduction Examples: int bool α β β α α α Slide 13 Slide 15 Most general Types Fact: each type correct term has a most general type What about termination? β reduction inλ always terminates. Formally: Γ t :: τ = σ. Γ t :: σ ( σ. Γ t :: σ = σ σ) It can be found by executing the typing rules backwards. type checking: checking if Γ t :: τ for given Γ and τ type inference: computing Γ and τ such that Γ t :: τ Type checking and type inference on λ are decidable. (Alan Turing, 1942) = β is decidable To decide if s = β t, reduce s and t to normal form (always exists, because β terminates), and compare result. = αβη is decidable This is why Isabelle can automatically reduce each term to βη normal form. Slide 14 Slide 16 7 8

What does this mean for Expressiveness? Type Classes Not all computable functions can be expressed in λ! How can typed functional languages then be turing complete? Fact: Each computable function can be encoded as closed, type correct λ term using Y :: (τ τ) τ with Y t β t (Y t) as only constant. Y is called fix point operator used for recursion lose decidability (what does Y (λx.x) reduce to?) similar to Haskell s type classes, but with semantic properties axclass order < ord order refl: x x order trans: [[x y;y z]] = x z... theorems can be proved in the abstract lemma order less trans: x :: a :: order. [[x < y;y < z]] = x < z can be used for subtyping axclass linorder < order linorder linear: x y y x can be instantiated instance nat :: {order, linorder} by... Slide 17 Slide 19 Types and Terms in Isabelle Types: τ ::= b ν ν :: C τ τ (τ,...,τ) K b {bool, int,...} base types ν {α,β,...} type variables K {set, list,...} type constructors C {order, linord,...} type classes Terms: t ::= v c?v (t t) (λx. t) v,x V, c C, V,C sets of names type constructors: construct a new type out of a parameter type. Example: int list type classes: restrict type variables to a class defined by axioms. Example: α :: order schematic variables: variables that can be instantiated. Schematic Variables X Y X Y X and Y must be instantiated to apply the rule But: x is free convention: lemma must be true for all x during the proof, x must not be instantiated lemma x+0 = 0+x Solution: Isabelle has free (x), bound (x), and schematic (?X) variables. Only schematic variables can be instantiated. Free converted into schematic after proof is finished. Slide 18 Slide 20 9 10

Higher Order Unification We have learned so far... Unification: Find substitution σ on variables for terms s,t such that σ(s) = σ(t) In Isabelle: Find substitution σ on schematic variables such that σ(s) = αβη σ(t) Examples:?X?Y = αβη x x [?X x,?y x]?p x = αβη x x [?P λx. x x] P (?f x) = αβη?y x [?f λx. x,?y P] Simply typed lambda calculus: λ Typing rules for λ, type variables, type contexts β-reduction in λ satisfies subject reduction β-reduction in λ always terminates Types and terms in Isabelle Higher Order: schematic variables can be functions. Slide 21 Slide 23 Higher Order Unification Exercises Unification modulo αβ (Higher Order Unification) is semi-decidable Unification modulo αβη is undecidable Higher Order Unification has possibly infinitely many solutions Construct a type derivation tree for the term λx y z. z x (y x) Find a unifier (substitution) such that λx y z.?f y z = λx y z. z (?G x y) But: Most cases are well-behaved Important fragments (like Higher Order Patterns) are decidable Higher Order Pattern: is a term in β normal form where each occurrence of a schematic variable is of the from?f t 1... t n and the t 1... t n are η-convertible into n distinct bound variables Slide 22 Slide 24 11 12