Formal Methods Lecture 8. (B. Pierce's slides for the book Types and Programming Languages )

Size: px
Start display at page:

Download "Formal Methods Lecture 8. (B. Pierce's slides for the book Types and Programming Languages )"

Transcription

1 Formal Methods Lecture 8 (B. Pierce's slides for the book Types and Programming Languages )

2 Erasure and Typability

3 Erasure We can transform terms in λ to terms of the untyped lambda-calculus simply by erasing type annotations on lambda-abstractions. erase(x) erase(λx:t 1. t 2 ) erase(t 1 t 2 ) = x = λx. erase(t 2 ) = erase(t 1 ) erase(t 2 )

4 Typability Conversely, an untyped λ-term m is said to be typable if there is some term t in the simply typed lambda-calculus, some type T, and some context Γ such that erase(t ) = m and Γ t : T. This process is called type reconstruction or type inference.

5 Typability Conversely, an untyped λ-term m is said to be typable if there is some term t in the simply typed lambda-calculus, some type T, and some context Γ such that erase(t ) = m and Γ t : T. This process is called type reconstruction or type inference. Example: Is the term λx. x x typable?

6 The Curry-Howard Correspondence

7 Intro vs. elim forms An introduction form for a given type gives us a way of constructing elements of this type. An elimination form for a type gives us a way of using elements of this type.

8 T he Curry-Howard Correspondence In constructive logics, a proof of P must provide evidence for P. law of the excluded middle P P not recognized. A proof of P Q is a pair of evidence for P and evidence for Q. A proof of P Q is a procedure for transforming evidence for P into evidence for Q.

9 Propositions as Types Lo g ic propositions proposition P Q proposition P Q proof of proposition P proposition P is provable proof simplification (a.k.a. cut elimination ) P r o g r a mmin g l a n g u a g e s types type P Q type P Q term t of type P type P is inhabited (by some term) evaluation

10 On to real programming languages...

11 Base types Up to now, we ve formulated base types (e.g. Nat) by adding them to the syntax of types, extending the syntax of terms with associated constants (zero) and operators (succ, etc.) and adding appropriate typing and evaluation rules. We can do this for as many base types as we like. For more theoretical discussions (as opposed to programming) we can often ignore the term-level inhabitants of base types, and just treat these types as uninterpreted constants. E.g., suppose B and C are some base types. Then we can ask (without knowing anything more about B or C) whether there are any types S and T such that the term ( λf : S. λg:t. f g) ( λx:b. x) is well typed.

12 The Uni t type T ::=... Unit New typing rules types unit type Γ t : T Γ unit : Unit (T -Unit )

13 Sequencing t ::=... t 1 ; t 2 terms

14 Sequencing t ::=... t 1 ; t 2 terms t 1 t 1 t 1 ; t 2 t ; t 2 1 (E -Se q ) u n i t ; t 2 t 2 (E -Se q Ne x t ) Γ t 1 : Unit Γ t 2 : T 2 Γ t 1 ; t 2 : T 2 (T -Se q )

15 Derived forms Syntatic sugar Internal language vs. external (surface) language

16 Sequencing as a derived form t 1 ; t 2 def = ( λx: Unit.t 2 ) t 1 where x FV(t 2 )

17 Ascription New syntactic forms t ::=... t as T New evaluation rules terms ascription t t New typing rules v 1 as T v 1 t 1 t 1 t 1 as T t 1 Γ t 1 : T as T Γ t 1 as T : T (E -Asc r ibe) (E -Asc r ibe1) Γ t : T (T -Asc r ibe)

18 Ascription as a derived form def t as T = ( λx:t. x) t

19 Let-bindings New syntactic forms t ::=... l e t x=t in t New evaluation rules terms let binding t t l e t x=v 1 in t 2 [x v 1 ]t 2 (E -Le t V) New typing rules t 1 t 1 l e t x=t 1 in t 2 l e t x=t in t 2 1 (E -Le t ) Γ t : T Γ t 1 : T 1 Γ, x:t 1 t 2 : T 2 Γ l e t x=t 1 in t 2 : T 2 (T -Le t )

20 Pairs, tuples, and records

21 Pairs t. 1 t. 2 first projection second projection

22 Evaluation rules for pairs {v 1, v 2 }.1 v 1 {v 1, v 2 }.2 v 2 t 1 t 1 t 1.1 t.1 1 t 1 t 1 t 1.2 t.2 1 t 1 t 1 { t 1, t 2 } { t, t 2 } 1 t 2 t 2 {v 1, t 2 } {v 1, t } 2 (E -Pa ir B e t a 1) (E -Pa ir B e t a 2) (E -P r o j 1) (E -P r o j 2) (E -Pa ir 1) (E -Pa ir 2)

23 Typing rules for pairs Γ t 1 : T 1 Γ t 2 : T 2 Γ { t 1, t 2 } : T 1 T 2 (T -Pa ir ) Γ t 1 : T 11 T 12 Γ t 1.1 : T 11 (T -P r o j 1) Γ t 1 : T 11 T 12 Γ t 1.2 : T 12 (T -P r o j 2)

24 Tuples t ::=... { t i i 1..n } t. i v ::=... { v i i 1..n } T ::=... {T i i 1..n } terms tuple projection values tuple value types tuple type

25

26 Typing rules for tuples for each i Γ t i : T i i 1..n i 1..n Γ { t i } : {T i } (T -T u pl e ) Γ t 1 : {T i i 1..n } Γ t 1. j : T j (T -P r o j )

27 Records t ::=... { l i =t i i 1..n } t. l v ::=... { l i =v i i 1..n } T ::=... { l i :T i i 1..n } terms record projection values record value types type of records

28

29 Typing rules for records for each i Γ t i : T i Γ { l i =t i i 1..n } : { l i :T i i 1..n } (T -R c d ) Γ t 1 : { l i :T i i 1..n } Γ t 1. l j : T j (T -P r o j )

30 Sums and variants

31 Sums motivating example PhysicalAddr = { f i r s t l a s t : S t r i n g, addr:string} VirtualAddr = {name:string, em ail: String} Addr = PhysicalAddr + VirtualAddr i n l : PhysicalAddr PhysicalAddr+VirtualAddr i n r : VirtualAddr PhysicalAddr+VirtualAddr getname = λa:addr. case a of i n l x x. f i r s t l a s t i n r y y.name;

32 New syntactic forms t ::=... i n l t i n r t case t of i n l x t i n r x t terms tagging (left) tagging (right) case v ::=... i n l v i n r v values tagged value (left) tagged value (right) T 1 +T 2 is a disjoint union of T 1 and T 2 (the tags i n l and i n r ensure disjointness)

33

34 New typing rules Γ t : T Γ t 1 : T 1 Γ i n l t 1 : T 1 +T 2 (T -In l ) Γ t 1 : T 2 Γ i n r t 1 : T 1 +T 2 (T -In r ) Γ t 0 : T 1 +T 2 Γ, x 1 :T 1 t 1 : T Γ, x 2 :T 2 t 2 : T Γ case t 0 of i n l x 1 t 1 i n r x 2 t 2 : T (T -C a se )

35 Sums and Uniqueness of Types Problem: If t has type T, then inl t has type T+U for every U. I.e., we ve lost uniqueness of types. Possible solutions: Infer U as needed during typechecking Give constructors different names and only allow each name to appear in one sum type (requires generalization to variants, which we ll see next) OCaml s solution Annotate each i n l and i n r with the intended sum type. For simplicity, let s choose the third.

36 New syntactic forms t ::=... i n l t as T i n r t as T v ::=... i n l v as T i n r v as T terms tagging (left) tagging (right) values tagged value (left) tagged value (right) Note that as T here is not the ascription operator that we saw before i.e., not a separate syntactic form: in essence, there is an ascription built into every use of i n l or i n r.

37 New typing rules Γ t : T Γ t 1 : T 1 Γ i n l t 1 as T 1 +T 2 : T 1 +T 2 (T -In l ) Γ t 1 : T 2 Γ i n r t 1 as T 1 +T 2 : T 1 +T 2 (T -In r )

38 Evaluation rules ignore annotations: t t case ( i n l v 0 as T 0 ) of i n l x 1 t 1 i n r x 2 t 2 [x 1 v 0 ]t 1 (E -C a se In l ) case ( i n r v 0 as T 0 ) of i n l x 1 t 1 i n r x 2 t 2 [x 2 v 0 ]t 2 (E -C a se In r ) t 1 t 1 i n l t 1 as T 2 i n l t 1 as T 2 (E -In l ) t 1 t 1 i n r t 1 as T 2 i n r t 1 as T 2 (E -In r )

39 Variants Just as we generalized binary products to labeled records, we can generalize binary sums to labeled variants.

40 New syntactic forms t ::=... <l=t> as T case t of <l i =x i > t i i 1..n T ::=... < l i :T i i 1..n > terms tagging case types type of variants

41 New evaluation rules t t case ( < l j =v j > as T) of <l i =x i > t i i 1..n [x j v j ]t j (E -C a se Va r ia n t ) t 0 t 0 i 1..n case t 0 of <l i =x i > t i case t i 1..n of <l i =x i > t i 0 t i t i <l i =t i > as T <l i =t > as T i (E -C a se ) (E -Va r ia n t )

42 New typing rules Γ t j : T j Γ <l j =t j > as <l i :T i i 1..n > : <l i :T i i 1..n > i 1..n Γ t 0 : <l i :T i > for each i Γ, x i :T i t i : T Γ case t 0 of <l i =x i > t i i 1..n : T Γ t : T (T -Va r ia n t ) (T -C a se )

43 Example Addr = <physical:physicaladdr, virt ual: Virt ualadd r>; a = <physical=pa> as Addr; getname = λa:addr. case a of <physical=x> x. f i r s t l a s t <virtual=y> y.name;

44 Options Just like in OCaml... OptionalNat = <none:unit, some:nat>; Table = Nat OptionalNat; emptytable = λn:nat. <none=unit> as OptionalNat; extendtable = λt:table. λm:nat. λv:nat. λn:nat. i f equal n m then <some=v> as OptionalNat else t n; x = case t ( 5 ) of <none=u> 999 <some=v> v;

45 Enumerations Weekday = <monday:unit, tuesday:unit, wednesday:unit, thursday:unit, friday:unit>; nextbusinessday = λw:weekday. case w of <monday=x> <tuesday=unit> as Weekday <tuesday=x> <wednesday=unit> as Weekday <wednesday=x> <thursday=unit> as Weekday <thursday=x> <friday=unit> as Weekday <friday=x> <monday=unit> as Weekday;

46 Recursion

47 Recursion in λ In λ, all programs terminate. Hence, untyped terms like omega and f i x are not typable. But we can extend the system with a (typed) fixed-point operator...

48 Example f f = λie:nat Bool. λx:nat. i f iszero x then true else i f iszero (pred x) then false else i e (pred (pred x ) ) ; iseven = f i x f f ; iseven 7;

49 New syntactic forms t ::=... f i x t terms fixed point of t New evaluation rules t t f i x ( λx:t 1. t 2 ) [x ( f i x ( λx:t 1. t 2 ) ) ]t 2 (E -F ix B e t a ) t 1 t 1 f i x t 1 f i x t 1 (E -F ix )

50 New typing rules Γ t : T Γ t 1 : T 1 T 1 Γ f i x t 1 : T 1 (T -F ix )

51 A more convenient form def letrec x:t 1 =t 1 in t 2 = l e t x = f i x ( λx:t 1. t 1 ) in t 2 letrec iseven : Nat Bool = λx:nat. i f iszero x then true else i f iszero (pred x) then false else iseven (pred (pred x ) ) i n iseven 7;

Type Systems Winter Semester 2006

Type Systems Winter Semester 2006 Type Systems Winter Semester 2006 Week 7 November 29 November 29, 2006 - version 1.0 Plan PREVIOUSLY: 1. type safety as progress and preservation 2. typed arithmetic expressions 3. simply typed lambda

More information

Simple Type Extensions

Simple Type Extensions Simple Type Extensions Type Systems, Lecture 4 Jevgeni Kabanov Tartu, 14.02.2006 PREVIOUSLY ON TYPE SYSTEMS Lambda Calculus Embedded Booleans and Arithmetical expressions Fixpoints and Recursion Simple

More information

Typed Arithmetic Expressions

Typed Arithmetic Expressions Typed Arithmetic Expressions CS 550 Programming Languages Jeremy Johnson TAPL Chapters 3 and 5 1 Types and Safety Evaluation rules provide operational semantics for programming languages. The rules provide

More information

1 Introduction. 2 Recap The Typed λ-calculus λ. 3 Simple Data Structures

1 Introduction. 2 Recap The Typed λ-calculus λ. 3 Simple Data Structures CS 6110 S18 Lecture 21 Products, Sums, and Other Datatypes 1 Introduction In this lecture, we add constructs to the typed λ-calculus that allow working with more complicated data structures, such as pairs,

More information

CIS 500 Software Foundations Midterm II Answer key November 17, 2004

CIS 500 Software Foundations Midterm II Answer key November 17, 2004 CIS 500 Software Foundations Midterm II Answer key November 17, 2004 Simply typed lambda-calculus The following questions refer to the simply typed lambda-calculus with booleans and error. The syntax,

More information

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

CS 4110 Programming Languages & Logics. Lecture 16 Programming in the λ-calculus CS 4110 Programming Languages & Logics Lecture 16 Programming in the λ-calculus 30 September 2016 Review: Church Booleans 2 We can encode TRUE, FALSE, and IF, as: TRUE λx. λy. x FALSE λx. λy. y IF λb.

More information

Typing λ-terms. Types. Typed λ-terms. Base Types. The Typing Relation. Advanced Formal Methods. Lecture 3: Simply Typed Lambda calculus

Typing λ-terms. Types. Typed λ-terms. Base Types. The Typing Relation. Advanced Formal Methods. Lecture 3: Simply Typed Lambda calculus Course 2D1453, 200607 Advanced Formal Methods Lecture 3: Simply Typed Lambda calculus Mads Dam KTH/CSC Some material from B. Pierce: TAPL + some from G. Klein, NICTA Typing λterms The uptyped λcalculus

More information

Categories, Proofs and Programs

Categories, Proofs and Programs Categories, Proofs and Programs Samson Abramsky and Nikos Tzevelekos Lecture 4: Curry-Howard Correspondence and Cartesian Closed Categories In A Nutshell Logic Computation 555555555555555555 5 Categories

More information

CS Lecture 19: Logic To Truth through Proof. Prof. Clarkson Fall Today s music: Theme from Sherlock

CS Lecture 19: Logic To Truth through Proof. Prof. Clarkson Fall Today s music: Theme from Sherlock CS 3110 Lecture 19: Logic To Truth through Proof Prof. Clarkson Fall 2014 Today s music: Theme from Sherlock Review Current topic: How to reason about correctness of code Last week: informal arguments

More information

Extending the Lambda Calculus: An Eager Functional Language

Extending the Lambda Calculus: An Eager Functional Language Syntax of the basic constructs: Extending the Lambda Calculus: An Eager Functional Language canonical forms z cfm ::= intcfm boolcfm funcfm tuplecfm altcfm intcfm ::= 0 1-1... boolcfm ::= boolconst funcfm

More information

Type Theory and Constructive Mathematics. Type Theory and Constructive Mathematics Thierry Coquand. University of Gothenburg

Type Theory and Constructive Mathematics. Type Theory and Constructive Mathematics Thierry Coquand. University of Gothenburg Type Theory and Constructive Mathematics Type Theory and Constructive Mathematics Thierry Coquand University of Gothenburg Content An introduction to Voevodsky s Univalent Foundations of Mathematics The

More information

Lecture Notes on Data Abstraction

Lecture Notes on Data Abstraction Lecture Notes on Data Abstraction 15-814: Types and Programming Languages Frank Pfenning Lecture 14 October 23, 2018 1 Introduction Since we have moved from the pure λ-calculus to functional programming

More information

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications NICTA Advanced Course Theorem Proving Principles, Techniques, Applications λ 1 CONTENT Intro & motivation, getting started with Isabelle Foundations & Principles Lambda Calculus Higher Order Logic, natural

More information

Consistency of a Programming Logic for a Version of PCF Using Domain Theory

Consistency of a Programming Logic for a Version of PCF Using Domain Theory Consistency of a Programming Logic for a Version of PCF Using Domain Theory Andrés Sicard-Ramírez EAFIT University Logic and Computation Seminar EAFIT University 5 April, 3 May 2013 A Core Functional Programming

More information

Introduction to Metalogic

Introduction to Metalogic Introduction to Metalogic Hans Halvorson September 21, 2016 Logical grammar Definition. A propositional signature Σ is a collection of items, which we call propositional constants. Sometimes these propositional

More information

λ Slide 1 Content Exercises from last time λ-calculus COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification

λ Slide 1 Content Exercises from last time λ-calculus COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification Content COMP 4161 NICTA Advanced Course Advanced Topics in Software Verification Toby Murray, June Andronick, Gerwin Klein λ Slide 1 Intro & motivation, getting started [1] Foundations & Principles Lambda

More information

CSCI 490 problem set 6

CSCI 490 problem set 6 CSCI 490 problem set 6 Due Tuesday, March 1 Revision 1: compiled Tuesday 23 rd February, 2016 at 21:21 Rubric For full credit, your solutions should demonstrate a proficient understanding of the following

More information

Formal Methods Lecture 6. (B. Pierce's slides for the book Types and Programming Languages )

Formal Methods Lecture 6. (B. Pierce's slides for the book Types and Programming Languages ) Formal Methods Lecture 6 (B. Pierce's slides for the book Types and Programming Languages ) This Saturday, 10 November 2018, room 335 (FSEGA), we will recover the following activities: 1 Formal Methods

More information

Static Program Analysis

Static Program Analysis Static Program Analysis Xiangyu Zhang The slides are compiled from Alex Aiken s Michael D. Ernst s Sorin Lerner s A Scary Outline Type-based analysis Data-flow analysis Abstract interpretation Theorem

More information

Consequence Relations and Natural Deduction

Consequence Relations and Natural Deduction Consequence Relations and Natural Deduction Joshua D. Guttman Worcester Polytechnic Institute September 9, 2010 Contents 1 Consequence Relations 1 2 A Derivation System for Natural Deduction 3 3 Derivations

More information

Models of computation

Models of computation Lambda-Calculus (I) jean-jacques.levy@inria.fr 2nd Asian-Pacific Summer School on Formal ethods Tsinghua University, August 23, 2010 Plan computation models lambda-notation bound variables odels of computation

More information

Type Inference. For the Simply-Typed Lambda Calculus. Peter Thiemann, Manuel Geffken. Albert-Ludwigs-Universität Freiburg. University of Freiburg

Type Inference. For the Simply-Typed Lambda Calculus. Peter Thiemann, Manuel Geffken. Albert-Ludwigs-Universität Freiburg. University of Freiburg Type Inference For the Simply-Typed Lambda Calculus Albert-Ludwigs-Universität Freiburg Peter Thiemann, Manuel Geffken University of Freiburg 24. Januar 2013 Outline 1 Introduction 2 Applied Lambda Calculus

More information

(2) (15pts) Using Prolog, implement a type-checker for the following small subset of System F:

(2) (15pts) Using Prolog, implement a type-checker for the following small subset of System F: CS 6371 Advanced Programming Languages Sample Spring 2018 Final Exam This sample final exam is LONGER than a real final exam (to give you more practice problems) and has a medium difficulty level. You

More information

Midterm Exam Types and Programming Languages Frank Pfenning. October 18, 2018

Midterm Exam Types and Programming Languages Frank Pfenning. October 18, 2018 Midterm Exam 15-814 Types and Programming Languages Frank Pfenning October 18, 2018 Name: Andrew ID: Instructions This exam is closed-book, closed-notes. You have 80 minutes to complete the exam. There

More information

Formal Methods Lecture 6. (B. Pierce's slides for the book Types and Programming Languages )

Formal Methods Lecture 6. (B. Pierce's slides for the book Types and Programming Languages ) Formal Methods Lecture 6 (B. Pierce's slides for the book Types and Programming Languages ) Programming in the Lambda-Calculus, Continued Testing booleans Recall: tru = λt. λf. t fls = λt. λf. f We showed

More information

CS522 - Programming Language Semantics

CS522 - Programming Language Semantics 1 CS522 - Programming Language Semantics Simply Typed Lambda Calculus Grigore Roşu Department of Computer Science University of Illinois at Urbana-Champaign 2 We now discuss a non-trivial extension of

More information

Lambda-Calculus (I) 2nd Asian-Pacific Summer School on Formal Methods Tsinghua University, August 23, 2010

Lambda-Calculus (I) 2nd Asian-Pacific Summer School on Formal Methods Tsinghua University, August 23, 2010 Lambda-Calculus (I) jean-jacques.levy@inria.fr 2nd Asian-Pacific Summer School on Formal Methods Tsinghua University, August 23, 2010 Plan computation models lambda-notation bound variables conversion

More information

CS611 Lecture 25 Solving Domain Equations 22 October 2007 Lecturer: Andrew Myers

CS611 Lecture 25 Solving Domain Equations 22 October 2007 Lecturer: Andrew Myers CS611 Lecture 25 Solving Domain Equations 22 October 2007 Lecturer: Andrew Myers To develop a denotational semantics for a language with recursive types, or to give a denotational semantics for the untyped

More information

Logical Preliminaries

Logical Preliminaries Logical Preliminaries Johannes C. Flieger Scheme UK March 2003 Abstract Survey of intuitionistic and classical propositional logic; introduction to the computational interpretation of intuitionistic logic

More information

Programming Languages and Types

Programming Languages and Types Programming Languages and Types Klaus Ostermann based on slides by Benjamin C. Pierce Subtyping Motivation With our usual typing rule for applications the term is not well typed. ` t 1 : T 11!T 12 ` t

More information

Extending higher-order logic with predicate subtyping: application to PVS

Extending higher-order logic with predicate subtyping: application to PVS Extending higher-order logic with predicate subtyping: application to PVS Frédéric Gilbert To cite this version: Frédéric Gilbert. Extending higher-order logic with predicate subtyping: application to

More information

The Curry-Howard Isomorphism

The Curry-Howard Isomorphism The Curry-Howard Isomorphism Software Formal Verification Maria João Frade Departmento de Informática Universidade do Minho 2008/2009 Maria João Frade (DI-UM) The Curry-Howard Isomorphism MFES 2008/09

More information

CMSC 336: Type Systems for Programming Languages Lecture 10: Polymorphism Acar & Ahmed 19 February 2008

CMSC 336: Type Systems for Programming Languages Lecture 10: Polymorphism Acar & Ahmed 19 February 2008 CMSC 336: Type Systems for Programming Languages Lecture 10: Polymorphism Acar & Ahmed 19 February 2008 Contents 1 Polymorphism 1 2 Polymorphic λ-calculus: Syntax 1 3 Static Semantics 2 4 Dynamic Semantics

More information

Review. Principles of Programming Languages. Equality. The Diamond Property. The Church-Rosser Theorem. Corollaries. CSE 230: Winter 2007

Review. Principles of Programming Languages. Equality. The Diamond Property. The Church-Rosser Theorem. Corollaries. CSE 230: Winter 2007 CSE 230: Winter 2007 Principles of Programming Languages Lecture 12: The λ-calculus Ranjit Jhala UC San Diego Review The lambda calculus is a calculus of functions: e := x λx. e e 1 e 2 Several evaluation

More information

Simply Typed λ-calculus

Simply Typed λ-calculus Simply Typed λ-calculus Lecture 1 Jeremy Dawson The Australian National University Semester 2, 2017 Jeremy Dawson (ANU) COMP4630,Lecture 1 Semester 2, 2017 1 / 23 A Brief History of Type Theory First developed

More information

Simply Typed Lambda Calculus

Simply Typed Lambda Calculus Simply Typed Lambda Calculus Mathias Vorreiter Pedersen November 13, 2015 1 Recalling the untyped lambda calculus 1.1 Syntax t ::= x λ x. t t t 1.2 Evaluation x x t t λx.t λx.t t 1 t 1 t 2 t 2 t 1 t 2

More information

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

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 17 Tuesday, April 2, 2013 1 There is a strong connection between types in programming languages and propositions

More information

Lecture Notes on The Curry-Howard Isomorphism

Lecture Notes on The Curry-Howard Isomorphism Lecture Notes on The Curry-Howard Isomorphism 15-312: Foundations of Programming Languages Frank Pfenning Lecture 27 ecember 4, 2003 In this lecture we explore an interesting connection between logic and

More information

Structure. Background. them to their higher order equivalents. functionals in Standard ML source code and converts

Structure. Background. them to their higher order equivalents. functionals in Standard ML source code and converts Introduction 3 Background functionals factor out common behaviour map applies a function to every element of a list fun map [ ] = [ ] map f ( x : : xs ) = f x : : map f xs filter keeps only those elements

More information

4.4 Contracting Proofs to Programs

4.4 Contracting Proofs to Programs 4.4 Contracting Proofs to Programs 75 We close this section with the formal version of the proof above. Note the use of the conversion rule conv. [ x : nat; [ ~ 0 = 0; 0 = 0; F; s(pred(0)) = 0 ]; ~ 0 =

More information

Notes from Yesterday s Discussion. Big Picture. CIS 500 Software Foundations Fall November 1. Some lessons.

Notes from Yesterday s  Discussion. Big Picture. CIS 500 Software Foundations Fall November 1. Some lessons. CIS 500 Software Foundations Fall 2006 Notes from Yesterday s Email Discussion November 1 Some lessons This is generally a crunch-time in the semester Slow down a little and give people a chance to catch

More information

CIS 500 Software Foundations Final Exam Answer key December 20, 2004

CIS 500 Software Foundations Final Exam Answer key December 20, 2004 CIS 500 Software Foundations Final Exam Answer key December 20, 2004 True/False questions For each of the following statements, circle T if the sentence is true or F otherwise. 1. (10 points) (a) T F The

More information

Type Systems. Lecture 9: Classical Logic. Neel Krishnaswami University of Cambridge

Type Systems. Lecture 9: Classical Logic. Neel Krishnaswami University of Cambridge Type Systems Lecture 9: Classical Logic Neel Krishnaswami University of Cambridge Where We Are We have seen the Curry Howard correspondence: Intuitionistic propositional logic Simply-typed lambda calculus

More information

Simply Typed Lambda-Calculi (II)

Simply Typed Lambda-Calculi (II) THEORY AND PRACTICE OF FUNCTIONAL PROGRAMMING Simply Typed Lambda-Calculi (II) Dr. ZHANG Yu Institute of Software, Chinese Academy of Sciences Fall term, 2011 GUCAS, Beijing Introduction PCF Programming

More information

CIS 500 Software Foundations Final Exam. Answer key. December 20, 2006

CIS 500 Software Foundations Final Exam. Answer key. December 20, 2006 CIS 500 Software Foundations Final Exam Answer key December 20, 2006 Instructions This is a closed-book exam. You have 120 minutes to answer all of the questions. The entire exam is worth 120 points. Questions

More information

CMSC 631 Program Analysis and Understanding Fall Type Systems

CMSC 631 Program Analysis and Understanding Fall Type Systems Program Analysis and Understanding Fall 2017 Type Systems Type Systems A type system is a tractable syntactic method for proving the absence of certain program behaviors by classifying phrases according

More information

Lambda calculus. (Advanced Functional Programming) Jeremy Yallop. January Computer Laboratory University of Cambridge 1/ 29

Lambda calculus. (Advanced Functional Programming) Jeremy Yallop. January Computer Laboratory University of Cambridge 1/ 29 1/ 29 Lambda calculus (Advanced Functional Programming) Jeremy Yallop Computer Laboratory University of Cambridge January 2015 Course outline 2/ 29 3/ 29 Books OCaml from the very beginning John Whitington

More information

Programming Languages

Programming Languages CSE 230: Winter 2010 Principles of Programming Languages Lecture 10: Programming in λ-calculusc l l Ranjit Jhala UC San Diego Review The lambda calculus is a calculus of functions: e := x λx. e e 1 e 2

More information

CS 6110 Lecture 35 Solving Domain Equations 19 April 2013 Lecturer: Andrew Myers

CS 6110 Lecture 35 Solving Domain Equations 19 April 2013 Lecturer: Andrew Myers CS 6110 Lecture 35 Solving Domain Equations 19 April 2013 Lecturer: Andrew Myers To develop a denotational semantics for a language with recursive types, or to give a denotational semantics for the untyped

More information

Kleene realizability and negative translations

Kleene realizability and negative translations Q E I U G I C Kleene realizability and negative translations Alexandre Miquel O P. D E. L Ō A U D E L A R April 21th, IMERL Plan 1 Kleene realizability 2 Gödel-Gentzen negative translation 3 Lafont-Reus-Streicher

More information

Propositional Logic. CS 3234: Logic and Formal Systems. Martin Henz and Aquinas Hobor. August 26, Generated on Tuesday 31 August, 2010, 16:54

Propositional Logic. CS 3234: Logic and Formal Systems. Martin Henz and Aquinas Hobor. August 26, Generated on Tuesday 31 August, 2010, 16:54 Propositional Logic CS 3234: Logic and Formal Systems Martin Henz and Aquinas Hobor August 26, 2010 Generated on Tuesday 31 August, 2010, 16:54 1 Motivation In traditional logic, terms represent sets,

More information

CSE-433 Logic in Computer Science 2007 Final exam Sample Solution

CSE-433 Logic in Computer Science 2007 Final exam Sample Solution Name: Hemos ID: CSE-433 Logic in Computer Science 2007 Final exam Sample Solution This is a closed-book exam No other material is permitted It consists of 4 problems worth a total of 175 points There are

More information

References. 7 November. Fall Software Foundations CIS 500. Another example. Announcements. Homework 7 out today, due November 14.

References. 7 November. Fall Software Foundations CIS 500. Another example. Announcements. Homework 7 out today, due November 14. CIS 500 Software Foundations Fall 2005 7 November CIS 500, 7 November 1 References CIS 500, 7 November 3 Announcements Midterm II is one week from Wednesday (November 16). It will cover TAPL chapters 8-14

More information

The Calculus of Inductive Constructions

The Calculus of Inductive Constructions The Calculus of Inductive Constructions Hugo Herbelin 10th Oregon Programming Languages Summer School Eugene, Oregon, June 16-July 1, 2011 1 Outline - A bit of history, leading to the Calculus of Inductive

More information

Hoare Examples & Proof Theory. COS 441 Slides 11

Hoare Examples & Proof Theory. COS 441 Slides 11 Hoare Examples & Proof Theory COS 441 Slides 11 The last several lectures: Agenda Denotational semantics of formulae in Haskell Reasoning using Hoare Logic This lecture: Exercises A further introduction

More information

Lecture 4 Nondeterministic Finite Accepters

Lecture 4 Nondeterministic Finite Accepters Lecture 4 Nondeterministic Finite Accepters COT 4420 Theory of Computation Section 2.2, 2.3 Nondeterminism A nondeterministic finite automaton can go to several states at once. Transitions from one state

More information

Rules and derivations in an elementary logic course arxiv: v1 [cs.lo] 7 Jan 2016

Rules and derivations in an elementary logic course arxiv: v1 [cs.lo] 7 Jan 2016 Rules and derivations in an elementary logic course arxiv:160101483v1 [cslo] 7 Jan 2016 Gilles Dowek Inria, 23 avenue d Italie, CS 81321, 75214 Paris Cedex 13, France gillesdowek@inriafr When teaching

More information

Introduction to lambda calculus Part 6

Introduction to lambda calculus Part 6 Introduction to lambda calculus Part 6 Antti-Juhani Kaijanaho 2017-02-16 1 Untyped lambda calculus 2 Typed lambda calculi 2.1 Dynamically typed lambda calculus with integers 2.2 A model of Lisp 2.3 Simply

More information

Non-Idempotent Typing Operators, beyond the λ-calculus

Non-Idempotent Typing Operators, beyond the λ-calculus Non-Idempotent Typing Operators, beyond the λ-calculus Soutenance de thèse Pierre VIAL IRIF (Univ. Paris Diderot and CNRS) December 7, 2017 Non-idempotent typing operators P. Vial 0 1 /46 Certification

More information

Safety Analysis versus Type Inference

Safety Analysis versus Type Inference Information and Computation, 118(1):128 141, 1995. Safety Analysis versus Type Inference Jens Palsberg palsberg@daimi.aau.dk Michael I. Schwartzbach mis@daimi.aau.dk Computer Science Department, Aarhus

More information

Consequence Relations and Natural Deduction

Consequence Relations and Natural Deduction Consequence Relations and Natural Deduction Joshua D Guttman Worcester Polytechnic Institute September 16, 2010 Contents 1 Consequence Relations 1 2 A Derivation System for Natural Deduction 3 3 Derivations

More information

Focusing on Binding and Computation

Focusing on Binding and Computation Focusing on Binding and Computation Dan Licata Joint work with Noam Zeilberger and Robert Harper Carnegie Mellon University 1 Programming with Proofs Represent syntax, judgements, and proofs Reason about

More information

Artificial Intelligence Knowledge Representation I

Artificial Intelligence Knowledge Representation I rtificial Intelligence Knowledge Representation I Lecture 6 Issues in Knowledge Representation 1. How to represent knowledge 2. How to manipulate/process knowledge (2) Can be rephrased as: how to make

More information

Section 2.2 Set Operations. Propositional calculus and set theory are both instances of an algebraic system called a. Boolean Algebra.

Section 2.2 Set Operations. Propositional calculus and set theory are both instances of an algebraic system called a. Boolean Algebra. Section 2.2 Set Operations Propositional calculus and set theory are both instances of an algebraic system called a Boolean Algebra. The operators in set theory are defined in terms of the corresponding

More information

On Modal Logics of Partial Recursive Functions

On Modal Logics of Partial Recursive Functions arxiv:cs/0407031v1 [cs.lo] 12 Jul 2004 On Modal Logics of Partial Recursive Functions Pavel Naumov Computer Science Pennsylvania State University Middletown, PA 17057 naumov@psu.edu June 14, 2018 Abstract

More information

Fully-Abstract Compilation by Approximate Back-Translation Technical Appendix

Fully-Abstract Compilation by Approximate Back-Translation Technical Appendix Fully-Abstract Compilation by Approximate Back-Translation Technical Appendix Abstract This technical appendix provides the full formalisation and proofs for its paper 1 Contents 1 The Source Language

More information

Local Representations of Binding

Local Representations of Binding Local Representations of Binding Randy Pollack LFCS, University of Edinburgh Joint work with James McKinna, Christian Urban, Arthur Charguéraud, Brian Aydemir, Benjamin Pierce, Stephanie Weirich Version

More information

Programming Languages Fall 2013

Programming Languages Fall 2013 Programming Languages Fall 2013 Lecture 11: Subtyping Prof Liang Huang huang@qccscunyedu Big Picture Part I: Fundamentals Functional Programming and Basic Haskell Proof by Induction and Structural Induction

More information

Why Knowledge Representation?

Why Knowledge Representation? CSE 3401: Intro to AI & LP Knowledge Representation & First-Order Logic Required Readings: R & N Chapter 8 Optional: If you need more background: 7.1-7.3 Motivation for logic, basic introduction to semantics.

More information

INTRODUCTION TO PREDICATE LOGIC HUTH AND RYAN 2.1, 2.2, 2.4

INTRODUCTION TO PREDICATE LOGIC HUTH AND RYAN 2.1, 2.2, 2.4 INTRODUCTION TO PREDICATE LOGIC HUTH AND RYAN 2.1, 2.2, 2.4 Neil D. Jones DIKU 2005 Some slides today new, some based on logic 2004 (Nils Andersen), some based on kernebegreber (NJ 2005) PREDICATE LOGIC:

More information

Introduction to λ-calculus

Introduction to λ-calculus p.1/65 Introduction to λ-calculus Ken-etsu FUJITA fujita@cs.gunma-u.ac.jp http://www.comp.cs.gunma-u.ac.jp/ fujita/ Department of Computer Science Gunma University :Church 32, 36, 40; Curry 34 1. Universal

More information

Introduction to type theory and homotopy theory

Introduction to type theory and homotopy theory Introduction to type theory and homotopy theory Michael Shulman January 24, 2012 1 / 47 Homotopy theory Homotopy type theory types have a homotopy theory Intensional type theory New perspectives on extensional

More information

1 / A bird s-eye view of type theory. 2 A bird s-eye view of homotopy theory. 3 Path spaces and identity types. 4 Homotopy type theory

1 / A bird s-eye view of type theory. 2 A bird s-eye view of homotopy theory. 3 Path spaces and identity types. 4 Homotopy type theory Introduction to type theory and homotopy theory Michael Shulman January 24, 2012 Homotopy theory Homotopy type theory types have a homotopy theory New perspectives on extensional vs. intensional Intensional

More information

Inductive Definitions with Inference Rules 1 / 27

Inductive Definitions with Inference Rules 1 / 27 Inductive Definitions with Inference Rules 1 / 27 Outline Introduction Specifying inductive definitions Inference rules in action Judgments, axioms, and rules Reasoning about inductive definitions Direct

More information

Why Knowledge Representation? Example. Example. CSE 3401: Intro to AI & LP Knowledge Representation & First-Order Logic

Why Knowledge Representation? Example. Example. CSE 3401: Intro to AI & LP Knowledge Representation & First-Order Logic CSE 3401: Intro to AI & LP Knowledge Representation & First-Order Logic Required Readings: Chapter 8 Optional: If you need more background: Why Knowledge Representation? Consider the task of understanding

More information

Semantics for Propositional Logic

Semantics for Propositional Logic Semantics for Propositional Logic An interpretation (also truth-assignment, valuation) of a set of propositional formulas S is a function that assigns elements of {f,t} to the propositional variables in

More information

FIXED POINTS AND EXTENSIONALITY IN TYPED FUNCTIONAL PROGRAMMING LANGUAGES

FIXED POINTS AND EXTENSIONALITY IN TYPED FUNCTIONAL PROGRAMMING LANGUAGES FIXED POINTS AND EXTENSIONALITY IN TYPED FUNCTIONAL PROGRAMMING LANGUAGES a dissertation submitted to the department of computer science and the committee on graduate studies of stanford university in

More information

Dependent types. Paul Stansifer. March 16, 2012

Dependent types. Paul Stansifer. March 16, 2012 Dependent types Paul Stansifer March 16, 2012 1 You ve seen this before I hope you like abstraction, because we re about to use it a lot. Here s the simply-typed lambda calculus with built-in list operations

More information

What is logic, the topic of this course? There are at least two answers to that question.

What is logic, the topic of this course? There are at least two answers to that question. Applied Logic Lecture 1 CS 486 Spring 2005 Tuesday, January 25, 2005 What is Logic? What is logic, the topic of this course? There are at least two answers to that question. General logic: critical examination

More information

Outline. Overview. Syntax Semantics. Introduction Hilbert Calculus Natural Deduction. 1 Introduction. 2 Language: Syntax and Semantics

Outline. Overview. Syntax Semantics. Introduction Hilbert Calculus Natural Deduction. 1 Introduction. 2 Language: Syntax and Semantics Introduction Arnd Poetzsch-Heffter Software Technology Group Fachbereich Informatik Technische Universität Kaiserslautern Sommersemester 2010 Arnd Poetzsch-Heffter ( Software Technology Group Fachbereich

More information

Ling 130 Notes: Syntax and Semantics of Propositional Logic

Ling 130 Notes: Syntax and Semantics of Propositional Logic Ling 130 Notes: Syntax and Semantics of Propositional Logic Sophia A. Malamud January 21, 2011 1 Preliminaries. Goals: Motivate propositional logic syntax and inferencing. Feel comfortable manipulating

More information

The lambda calculus with constructors

The lambda calculus with constructors The lambda calculus with constructors Categorical semantic and Continuations Barbara Petit Focus - Univ. Bologna CaCos 2012 Barbara Petit (Focus - Univ. Bologna) The lambda calculus with constructors 1

More information

Functional Programming with Coq. Yuxin Deng East China Normal University

Functional Programming with Coq. Yuxin Deng East China Normal University Functional Programming with Coq Yuxin Deng East China Normal University http://basics.sjtu.edu.cn/ yuxin/ September 10, 2017 Functional Programming Y. Deng@ECNU 1 Reading materials 1. The Coq proof assistant.

More information

Logic for Computer Science - Week 4 Natural Deduction

Logic for Computer Science - Week 4 Natural Deduction Logic for Computer Science - Week 4 Natural Deduction 1 Introduction In the previous lecture we have discussed some important notions about the semantics of propositional logic. 1. the truth value of a

More information

Programming Languages and Types

Programming Languages and Types Programming Languages and Types Klaus Ostermann based on slides by Benjamin C. Pierce Where we re going Type Systems... Type systems are one of the most fascinating and powerful aspects of programming

More information

September 14. Fall Software Foundations CIS 500

September 14. Fall Software Foundations CIS 500 CIS 500 Software Foundations Fall 2005 September 14 CIS 500, September 14 1 Announcements I will be away September 19-October 5. I will be reachable by email. Fastest response cis500@cis.upenn.edu No office

More information

COMP4141 Theory of Computation

COMP4141 Theory of Computation COMP4141 Theory of Computation Lecture 4 Regular Languages cont. Ron van der Meyden CSE, UNSW Revision: 2013/03/14 (Credits: David Dill, Thomas Wilke, Kai Engelhardt, Peter Höfner, Rob van Glabbeek) Regular

More information

Type Systems Winter Semester 2006

Type Systems Winter Semester 2006 Type Systems Winter Semester 2006 Week 5 November 15 November 15, 2006 - version 1.0 Programming in the Lambda-Calculus, Continued Testing booleans Recall: tru = λt. λf. t fls = λt. λf. f We showed last

More information

A brief introduction to Logic. (slides from

A brief introduction to Logic. (slides from A brief introduction to Logic (slides from http://www.decision-procedures.org/) 1 A Brief Introduction to Logic - Outline Propositional Logic :Syntax Propositional Logic :Semantics Satisfiability and validity

More information

An Introduction to Logical Relations Proving Program Properties Using Logical Relations

An Introduction to Logical Relations Proving Program Properties Using Logical Relations An Introduction to Logical Relations Proving Program Properties Using Logical Relations Lau Skorstengaard lask@cs.au.dk July 27, 2018 Contents 1 Introduction 2 1.1 Simply Typed Lambda Calculus....................

More information

Denotational semantics

Denotational semantics Denotational semantics Semantics and Application to Program Verification Antoine Miné École normale supérieure, Paris year 2015 2016 Course 4 4 March 2016 Course 4 Denotational semantics Antoine Miné p.

More information

Surface Reasoning Lecture 2: Logic and Grammar

Surface Reasoning Lecture 2: Logic and Grammar Surface Reasoning Lecture 2: Logic and Grammar Thomas Icard June 18-22, 2012 Thomas Icard: Surface Reasoning, Lecture 2: Logic and Grammar 1 Categorial Grammar Combinatory Categorial Grammar Lambek Calculus

More information

Applied Logic. Lecture 1 - Propositional logic. Marcin Szczuka. Institute of Informatics, The University of Warsaw

Applied Logic. Lecture 1 - Propositional logic. Marcin Szczuka. Institute of Informatics, The University of Warsaw Applied Logic Lecture 1 - Propositional logic Marcin Szczuka Institute of Informatics, The University of Warsaw Monographic lecture, Spring semester 2017/2018 Marcin Szczuka (MIMUW) Applied Logic 2018

More information

Structural Induction

Structural Induction Structural Induction In this lecture we ll extend the applicability of induction to many universes, ones where we can define certain kinds of objects by induction, in addition to proving their properties

More information

CIS 500: Software Foundations

CIS 500: Software Foundations CIS 500: Software Foundations Midterm I October 3, 2017 Directions: This exam booklet contains both the standard and advanced track questions. Questions with no annotation are for both tracks. Other questions

More information

Functional Database Query Languages as. Typed Lambda Calculi of Fixed Order. Gerd G. Hillebrand and Paris C. Kanellakis

Functional Database Query Languages as. Typed Lambda Calculi of Fixed Order. Gerd G. Hillebrand and Paris C. Kanellakis Functional Database Query Languages as Typed Lambda Calculi of Fixed Order Gerd G. Hillebrand and Paris C. Kanellakis Department of Computer Science Brown University Providence, Rhode Island 02912 CS-94-26

More information

COMP 2600: Formal Methods for Software Engineeing

COMP 2600: Formal Methods for Software Engineeing COMP 2600: Formal Methods for Software Engineeing Dirk Pattinson Semester 2, 2013 What do we mean by FORMAL? Oxford Dictionary in accordance with convention or etiquette or denoting a style of writing

More information

Advanced Topics in LP and FP

Advanced Topics in LP and FP Lecture 1: Prolog and Summary of this lecture 1 Introduction to Prolog 2 3 Truth value evaluation 4 Prolog Logic programming language Introduction to Prolog Introduced in the 1970s Program = collection

More information

CSE 311 Lecture 25: Relating NFAs, DFAs, and Regular Expressions. Emina Torlak and Kevin Zatloukal

CSE 311 Lecture 25: Relating NFAs, DFAs, and Regular Expressions. Emina Torlak and Kevin Zatloukal CSE 3 Lecture 25: Relating NFAs, DFAs, and Regular Expressions Emina Torlak and Kevin Zatloukal Topics From regular expressions to NFAs Theorem, algorithm, and examples. From NFAs to DFAs Theorem, algorithm,

More information

Motivation. From Propositions To Fuzzy Logic and Rules. Propositional Logic What is a proposition anyway? Outline

Motivation. From Propositions To Fuzzy Logic and Rules. Propositional Logic What is a proposition anyway? Outline Harvard-MIT Division of Health Sciences and Technology HST.951J: Medical Decision Support, Fall 2005 Instructors: Professor Lucila Ohno-Machado and Professor Staal Vinterbo Motivation From Propositions

More information