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

Size: px
Start display at page:

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

Transcription

1 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 strategies exist based on β-reduction: (λx.e) e β [e /x] e The Diamond Property Languages defined by nondeterministic rules: Logic programming languages Expert systems Constraint satisfaction systems Make Useful to know if systems have diamond property! If so, a unique result is guaranteed Equality = β : symmetric, reflexive, transitive closure of β = β is ( β β ) * So e 1 = β e 2 if e 1 converts to e 2 via a seq of forward and backward β : e 1 e 2 The Church-Rosser Theorem If e 1 = β e 2 then exists e s.t. e 1 β* e and e 2 β* e e Proof (informal): apply the diamond property as many times as necessary. e 1 e 2 Corollaries If e 1 = β e 2 and e 1, e 2 are normal forms then e 1 e 2 Proof: From CR we have e. e 1 * β e and e 2 * β e As e 1, e 2 are normal forms they are e If e * β e 1 and e * β e 2 and e 1, e 2 are normal forms then e 1 e 2 Proof? Significance: Each term reduces to one normal form 1

2 Evaluation Strategies Q: Which β-redex should be picked? Good news, Church-Rosser Theorem: independent of strategy, there is at most one normal form Bad news, some strategies may fail to find a normal form: (λx. y) ((λy.y y) (λy.y y)) (λx. y) ((λy.y y) (λy.y y)) (λx. y) ((λy.y y) (λy.y y)) y Normal-Order Reduction outermost redex: a redex not contained inside another redex (λe. λf. e) ((λa.λb. a) x y) ((λc.λd. c) u v) Outermost: We consider three strategies: normal call-by-name call-by-value Normal order: leftmost outermost redex first Theorem: If e has a normal form e then normal order reduction will reduce e to e. Weak vs Strong Reduction In most PL, functions considered fully evaluated Weak Reduction: No reduction done under lambdas i.e. inside a function body Strong Reduction: Reduction is done under lambdas Partial evaluation of function, other optimizations Normal order reduces under lambda λx.((λy.y y) (λy.y y)) λx.((λy.y y) (λy.y y)) Not always desired Call-by-Name Reduction Don t reduce under λ Don t evaluate the argument to a function call Directly substitute; evaluate when reducing body Demand-driven an expression is not evaluated unless needed in body Normalizing it converges whenever normal order converges but does not always evaluate to a normal form Call-by-Name Example (λy. (λx. x) y) ((λu. u) (λv. v)) β (λy. y) ((λu. u) (λv. v)) β (λu. u) (λv. v) β λv. v Call-by-Value Reduction Don t reduce under lambda Do evaluate argument to function call Most languages are call-by-value Not normalizing (λx. y) ((λy.y y) (λy.y y)) diverges, but normal order (or CBN) converges 2

3 Call-by-Value Example: Evaluate arg (λy. (λx. x) y) ((λu. u) (λv. v)) β (λy. (λx. x) y) (λv. v) β (λy. y) (λv. v) β λv. v CBV vs. CBN Call-by-value: Easy to implement May diverge Call-by-name: More difficult to implement must pass unevaluated expressions Args multiply-evaluated inside function body Simpler theory than call-by-value Terminates more often (always if normal form exists) e.g. if arg is non-terminating, but not used Various other reduction strategies Programming with the λ-calculus How does the λ-calculus relate to real programming languages? Bools? If-then-else? Integers? Recursion? Functions: well, those we have Functional Programming λ-calculus = prototypical functional PL: no side effects, several evaluation strategies, lots of functions, nothing but functions Q: How can we program with functions? Are they a sufficient abstraction? Functional Programming Lisp, Scheme, ML, Haskell Pure: No locations, update, (side) effects Functions as args to/results from other functions: Higher-order programming Some impure functional languages permit side-effects (e.g., Lisp, Scheme, ML, OCaml) references (pointers), arrays, exceptions Variables in Functional Languages We can introduce new variables: let x = e 1 in e 2 x is bound by let i.e., x is statically scoped in e 2 essentially like (λx. e 2 ) e 1 Variables are never updated just names for expressions e.g., x is a name for the value denoted by e 1 in e 2 Equivalent to meaning of let in mathematics 3

4 Why? Referential Transparency Enables reasoning equationally, by substitution: let x = e 1 in e 2 [e 1 /x]e 2 Imp. langs: side-effects in e 1 invalidate equation evaluation of e_1 can alter semantics of e_2 Expressiveness of λ-calculus λ calculus can express: data types (ints, bools, pairs, lists, trees, ) branching Recursion (f e_1) and (f e_2) can produce different results even if e_1 and e 2 evaluate to the same thing! FP: function s behavior depends only on arguments Doesn t matter how function was called/used before! No state, like a mathematical function Localizes, simplifies understanding, reasoning about FP Enough to encode Turing machines Corollary: e = β e is undecidable But how to encode using only λ? Idea: encode the behavior of values Encoding Booleans in λ-calculus Q: What can we do with a boolean? A: Make a binary choice Q: So, how can you view this as a function? A: Bool = fun that takes two choices, returns one true = def λx. λy. x false = def λx. λy. y if E 1 then E 2 else E 3 = def E 1 E 2 E 3 Example: if true then u else v is (λx. λy. x) u v β (λy. u) v β u Boolean Operations Boolean operations: not Function takes b: returns function takes x,y: returns opposite of b s return not = def λb.(λx.λy. b y x) Boolean operations: or Function takes b 1, b 2 : returns function takes x,y: returns (if b 1 then x else (if b 2 then x else y)) or = def λb 1.λb 2.(λx.λy. b 1 x (b 2 x y)) Encoding Pairs (and so, Records) Q: What can we do with a pair? A: We can select one of its elements Pair: function takes a bool, returns the left or the right element mkpair e 1 e 2 = def λb. b e 1 e 2 Note: pair encoded as λ-abstraction, waiting for bool fst p = def p true snd p = def p false Ex: fst (mkpair x y) (mkpair x y) true true x y x Encoding Natural Numbers Q: What can we do with a natural number? A: Iterate a number of times over some function Nat: function that takes fun f, starting value s: returns: f applied to s a number of times 0 = def λf. λs. s 1 = def λf. λs. f s 2 = def λf. λs. f (f s) M Called Church numerals, unary representation Note: (n f s) : apply f to s n times, i.e. f n (s) 4

5 Operating on Natural Numbers Testing equality with 0 iszero n = def n (λb. false) true iszero = def λn.(λ b.false) true The successor function succ n = def λf. λs. f (n f s) succ = def λn. λf. λs. f (n f s) Addition add n 1 n 2 = def n 1 succ n 2 add = def λn 1.λn 2. n 1 succ n 2 Multiplication mult n 1 n 2 = def n 1 (add n 2 ) 0 mult = def λn 1.λn 2. n 1 (add n 2 ) 0 Ex: Computing with Naturals What is the result of add 0? (λn 1. λn 2. n 1 succ n 2 ) 0 β λn 2. 0 succ n 2 = λn 2. (λf. λs. s) succ n 2 β λn 2. n 2 = λx. x Ex: Computing with Naturals mult (add 2) 0 (add 2) ((add 2) 0) 2 succ (add 2 0) 2 succ (2 succ 0) succ (succ (succ (succ 0))) succ (succ (succ (λf. λs. f (0 f s)))) succ (succ (succ (λf. λs. f s))) succ (succ (λg. λy. g ((λf. λs. f s) g y))) succ (succ (λg. λy. g (g y))) * λg. λy. g (g (g (g y))) = 4 Encoding Recursion Write a function find that: takes predicate P, natural n, returns smallest nat., larger than n, satisfying P find can encode all recursion but how to write it? Encoding Recursion find satisfies the equation: find p n = if p n then n else find p (succ n) Define: F = λf.λp.λn.(p n) n (f p (succ n)) A fixpoint of F is an x s.t. x = F x find is a fixpoint of F! as find p n = F find p n so find = F find Q: Given λ-term F, how to write its fixpoint? The Y-Combinator Define: Y = def λf. (λy.f(y y)) (λx. F(x x)) Called the fixpoint combinator because Y F β (λy.f (y y)) (λx. F (x x)) β F ((λx.f (x x))(λz. F (z z))) β F(YF) i.e. Y F = β F (Y F) Can write fixpoint for any λ-calculus function Define: F = λf.λp.λn.(p n) n (f p (succ n)) find = Y F 5

6 Whoa! Define: F = λf.λp.λn.(p n) n (f p (succ n)) and: find = Y F Whats going on? find p n = β Y F p n = β F (Y F) p n = β F find p n = β (p n) n (find p (succ n)) Fixpoint Combinators Y = def λf. (λy.f(y y)) (λx. F(x x)) How does this mix with Call-by-Value? Y F β (λy.f (y y)) (λx. F (x x)) β F ((λx.f (x x))(λz. F (z z))) β F (F ((λx.f (x x))(λz. F (z z)))) β F (F (F ((λx.f (x x))(λz. F (z z))))) β Many other fixpoint combinators Including those that work for CBV See upcoming HW Including Klop s Combinator: Y k = def (L L L L L L L L L L L L L L L L L L L L L L L L L L) where: L = def λaλbλcλdλeλfλgλhλiλjλkλlλmλnλoλpλqλsλtλuλvλwλxλyλzλr. r (t h i s i s a f i x p o i n t c o m b i n a t o r) Expressiveness of λ-calculus Encodings are fun but programming in pure λ-calculus is not Encodings complicate static analysis Know the λ-calculus encodes them, so we add 0,1,2,,true,false,if-then-else to language Next, we will add types 6

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

The Lambda Calculus. Stephen A. Edwards. Fall Columbia University

The Lambda Calculus. Stephen A. Edwards. Fall Columbia University The Lambda Calculus Stephen A. Edwards Columbia University Fall 2014 Lambda Expressions Function application written in prefix form. Add four and five is (+ 4 5) Evaluation: select a redex and evaluate

More information

Type Systems. Lecture 2 Oct. 27th, 2004 Sebastian Maneth.

Type Systems. Lecture 2 Oct. 27th, 2004 Sebastian Maneth. Type Systems Lecture 2 Oct. 27th, 2004 Sebastian Maneth http://lampwww.epfl.ch/teaching/typesystems/2004 Today 1. What is the Lambda Calculus? 2. Its Syntax and Semantics 3. Church Booleans and Church

More information

Lambda-Calculus (cont): Fixpoints, Naming. Lecture 10 CS 565 2/10/08

Lambda-Calculus (cont): Fixpoints, Naming. Lecture 10 CS 565 2/10/08 Lambda-Calculus (cont): Fixpoints, Naming Lecture 10 CS 565 2/10/08 Recursion and Divergence Consider the application: Ω ((λ x. (x x)) (λ x. (x x))) Ω evaluates to itself in one step. It has no normal

More information

Type Systems. Today. 1. What is the Lambda Calculus. 1. What is the Lambda Calculus. Lecture 2 Oct. 27th, 2004 Sebastian Maneth

Type Systems. Today. 1. What is the Lambda Calculus. 1. What is the Lambda Calculus. Lecture 2 Oct. 27th, 2004 Sebastian Maneth Today 1. What is the Lambda Calculus? Type Systems 2. Its Syntax and Semantics 3. Church Booleans and Church Numerals 4. Lazy vs. Eager Evaluation (call-by-name vs. call-by-value) Lecture 2 Oct. 27th,

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

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

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

3.2 Equivalence, Evaluation and Reduction Strategies

3.2 Equivalence, Evaluation and Reduction Strategies 3.2 Equivalence, Evaluation and Reduction Strategies The λ-calculus can be seen as an equational theory. More precisely, we have rules i.e., α and reductions, for proving that two terms are intensionally

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

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

COMP6463: λ-calculus

COMP6463: λ-calculus COMP6463: λ-calculus 1. Basics Michael Norrish Michael.Norrish@nicta.com.au Canberra Research Lab., NICTA Semester 2, 2015 Outline Introduction Lambda Calculus Terms Alpha Equivalence Substitution Dynamics

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

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

CSE 505, Fall 2009, Midterm Examination 5 November Please do not turn the page until everyone is ready.

CSE 505, Fall 2009, Midterm Examination 5 November Please do not turn the page until everyone is ready. CSE 505, Fall 2009, Midterm Examination 5 November 2009 Please do not turn the page until everyone is ready Rules: The exam is closed-book, closed-note, except for one side of one 85x11in piece of paper

More information

Element x is R-minimal in X if y X. R(y, x).

Element x is R-minimal in X if y X. R(y, x). CMSC 22100/32100: Programming Languages Final Exam M. Blume December 11, 2008 1. (Well-founded sets and induction principles) (a) State the mathematical induction principle and justify it informally. 1

More information

Lambda Calculus. Andrés Sicard-Ramírez. Semester Universidad EAFIT

Lambda Calculus. Andrés Sicard-Ramírez. Semester Universidad EAFIT Lambda Calculus Andrés Sicard-Ramírez Universidad EAFIT Semester 2010-2 Bibliography Textbook: Hindley, J. R. and Seldin, J. (2008). Lambda-Calculus and Combinators. An Introduction. Cambridge University

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

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

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

Programming Language Concepts: Lecture 18

Programming Language Concepts: Lecture 18 Programming Language Concepts: Lecture 18 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in http://www.cmi.ac.in/~madhavan/courses/pl2009 PLC 2009, Lecture 18, 30 March 2009 One step reduction

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

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

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages Lecture 03 Theoretical Foundations 1 Domains Semantic model of a data type: semantic domain! Examples: Integer, Natural, Truth-Value Domains D are more than a set of

More information

Introduction to lambda calculus Part 2

Introduction to lambda calculus Part 2 Introduction to lambda calculus Part 2 Antti-Juhani Kaijanaho 2017-01-24... 1 Untyped lambda calculus 1.1 Syntax... x, y, z Var t, u Term t, u ::= x t u λx t... In this document, I will be using the following

More information

CSE 505, Fall 2005, Midterm Examination 8 November Please do not turn the page until everyone is ready.

CSE 505, Fall 2005, Midterm Examination 8 November Please do not turn the page until everyone is ready. CSE 505, Fall 2005, Midterm Examination 8 November 2005 Please do not turn the page until everyone is ready. Rules: The exam is closed-book, closed-note, except for one side of one 8.5x11in piece of paper.

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

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

1. Object Calculus. Object calculus is to OO languages what lambda calculus is to functional languages

1. Object Calculus. Object calculus is to OO languages what lambda calculus is to functional languages 1. Object Calculus In this section we will introduce a calculus of objects that gives a simple but powerful mathematical model to study object based languages. Object calculus is to OO languages what lambda

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

Recursion Theorem. Ziv Scully Ziv Scully Recursion Theorem / 28

Recursion Theorem. Ziv Scully Ziv Scully Recursion Theorem / 28 Recursion Theorem Ziv Scully 18.504 Ziv Scully Recursion Theorem 18.504 1 / 28 A very λ-calculus appetizer P-p-p-plot twist! λ Ziv Scully Recursion Theorem 18.504 2 / 28 A very λ-calculus appetizer The

More information

Lecture 2. Lambda calculus. Iztok Savnik, FAMNIT. March, 2018.

Lecture 2. Lambda calculus. Iztok Savnik, FAMNIT. March, 2018. Lecture 2 Lambda calculus Iztok Savnik, FAMNIT March, 2018. 1 Literature Henk Barendregt, Erik Barendsen, Introduction to Lambda Calculus, March 2000. Lambda calculus Leibniz had as ideal the following

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

EDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach

EDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach EDA045F: Program Analysis LECTURE 10: TYPES 1 Christoph Reichenbach In the last lecture... Performance Counters Challenges in Dynamic Performance Analysis Taint Analysis Binary Instrumentation 2 / 44 Types

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

CS294-9 September 14, 2006 Adam Chlipala UC Berkeley

CS294-9 September 14, 2006 Adam Chlipala UC Berkeley Interactive Computer Theorem Proving Lecture 4: Inductively- Defined Predicates CS294-9 September 14, 2006 Adam Chlipala UC Berkeley 1 Administrivia The course registration database has been updated so

More information

Lambda Calculus! Gunnar Gotshalks! LC-1

Lambda Calculus! Gunnar Gotshalks! LC-1 Lambda Calculus! LC-1 λ Calculus History! Developed by Alonzo Church during mid 1930 s! One fundamental goal was to describe what can be computed.! Full definition of λ-calculus is equivalent in power

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

First-Order Logic First-Order Theories. Roopsha Samanta. Partly based on slides by Aaron Bradley and Isil Dillig

First-Order Logic First-Order Theories. Roopsha Samanta. Partly based on slides by Aaron Bradley and Isil Dillig First-Order Logic First-Order Theories Roopsha Samanta Partly based on slides by Aaron Bradley and Isil Dillig Roadmap Review: propositional logic Syntax and semantics of first-order logic (FOL) Semantic

More information

Domain theory and denotational semantics of functional programming

Domain theory and denotational semantics of functional programming Domain theory and denotational semantics of functional programming Martín Escardó School of Computer Science, Birmingham University MGS 2007, Nottingham, version of April 20, 2007 17:26 What is denotational

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

ITP Programming Languages Lambda Calculus Lesson 0 Functional Programming and Lambda Calculus Lesson 1 Introduction to the Lambda Calculus

ITP Programming Languages Lambda Calculus Lesson 0 Functional Programming and Lambda Calculus Lesson 1 Introduction to the Lambda Calculus ITP 20005 Programming Languages Lambda Calculus Lesson 0 Functional Programming and Lambda Calculus Lesson 1 Introduction to the Lambda Calculus Lesson 2 Boolean Logic in the Lambda Calculus Lesson 3 Function

More information

Hoare Logic: Reasoning About Imperative Programs

Hoare Logic: Reasoning About Imperative Programs Hoare Logic: Reasoning About Imperative Programs COMP1600 / COMP6260 Dirk Pattinson Australian National University Semester 2, 2018 Programming Paradigms Functional. (Haskell, SML, OCaml,... ) main paradigm:

More information

Jones-Optimal Partial Evaluation by Specialization-Safe Normalization

Jones-Optimal Partial Evaluation by Specialization-Safe Normalization Jones-Optimal Partial Evaluation by Specialization-Safe Normalization MATT BROWN, University of California Los Angeles, USA JENS PALSBERG, University of California Los Angeles, USA We present partial evaluation

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

Reasoning About Imperative Programs. COS 441 Slides 10b

Reasoning About Imperative Programs. COS 441 Slides 10b Reasoning About Imperative Programs COS 441 Slides 10b Last time Hoare Logic: { P } C { Q } Agenda If P is true in the initial state s. And C in state s evaluates to s. Then Q must be true in s. Program

More information

Equivalent Computers. Lecture 39: Lambda Calculus. Lambda Calculus. What is Calculus? Real Definition. Why?

Equivalent Computers. Lecture 39: Lambda Calculus. Lambda Calculus. What is Calculus? Real Definition. Why? #,, - Lecture 39: Lambda Calculus Equivalent Computers z z z... term = variable term term (term) λ variable. term λy. M α λv. (M [y α v]) where v does not occur in M. (λx. M)N β M [ x α N ] Turing Machine

More information

Origin in Mathematical Logic

Origin in Mathematical Logic Lambda Calculus Origin in Mathematical Logic Foundation of mathematics was very much an issue in the early decades of 20th century. Cantor, Frege, Russel s Paradox, Principia Mathematica, NBG/ZF Origin

More information

Simply Typed Lambda Calculus

Simply Typed Lambda Calculus Simply Typed Lambda Calculus Language (ver1) Lambda calculus with boolean values t ::= x variable x : T.t abstraction tt application true false boolean values if ttt conditional expression Values v ::=

More information

Lecture 3. Lambda calculus. Iztok Savnik, FAMNIT. October, 2015.

Lecture 3. Lambda calculus. Iztok Savnik, FAMNIT. October, 2015. Lecture 3 Lambda calculus Iztok Savnik, FAMNIT October, 2015. 1 Literature Henk Barendregt, Erik Barendsen, Introduction to Lambda Calculus, March 2000. Lambda calculus Leibniz had as ideal the following

More information

Tutorial on Semantics Part I

Tutorial on Semantics Part I Tutorial on Semantics Part I Basic Concepts Prakash Panangaden 1 1 School of Computer Science McGill University on sabbatical leave at Department of Computer Science Oxford University Fields Institute,

More information

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

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

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

Operational Semantics

Operational Semantics Operational Semantics Semantics and applications to verification Xavier Rival École Normale Supérieure Xavier Rival Operational Semantics 1 / 50 Program of this first lecture Operational semantics Mathematical

More information

Formal Techniques for Software Engineering: Denotational Semantics

Formal Techniques for Software Engineering: Denotational Semantics Formal Techniques for Software Engineering: Denotational Semantics Rocco De Nicola IMT Institute for Advanced Studies, Lucca rocco.denicola@imtlucca.it May 2013 Lesson 4 R. De Nicola (IMT-Lucca) FoTSE@LMU

More information

Models of Computation,

Models of Computation, Models of Computation, 2010 1 The Lambda Calculus A brief history of mathematical notation. Our notation for numbers was introduced in the Western World in the Renaissance (around 1200) by people like

More information

Continuations, Processes, and Sharing. Paul Downen, Luke Maurer, Zena M. Ariola, Daniele Varacca. September 8, 2014

Continuations, Processes, and Sharing. Paul Downen, Luke Maurer, Zena M. Ariola, Daniele Varacca. September 8, 2014 Continuations, Processes, and Sharing Paul Downen, Luke Maurer, Zena M. Ariola, Daniele Varacca University of Oregon, Université Paris Diderot September 8, 2014 The plethora of semantic artifacts Many

More information

Logic and Probability Lecture 3: Beyond Boolean Logic

Logic and Probability Lecture 3: Beyond Boolean Logic Logic and Probability Lecture 3: Beyond Boolean Logic Wesley Holliday & Thomas Icard UC Berkeley & Stanford August 13, 2014 ESSLLI, Tübingen Wesley Holliday & Thomas Icard: Logic and Probability, Lecture

More information

1 Problem 1. (20 pts)

1 Problem 1. (20 pts) CS 336 Programming Languages Homework Solution 4 Winter 2005 Due 2/24/05 1 Problem 1. (20 pts) Do Exercise 18.6.2. We define a meta-operation + on types as follows: If R is a record type with labels given

More information

Lecture 2: Self-interpretation in the Lambda-calculus

Lecture 2: Self-interpretation in the Lambda-calculus Lecture 2: Self-interpretation in the Lambda-calculus H. Geuvers Nijmegen, NL 21st Estonian Winter School in Computer Science Winter 2016 H. Geuvers - Radboud Univ. EWSCS 2016 Self-interpretation in λ-calculus

More information

Charles Wells 1. February 25, 1999

Charles Wells 1. February 25, 1999 NOTES ON THE λ-calculus Charles Wells 1 February 25, 1999 Department of Mathematics Case Western Reserve University 10900 Euclid Ave. Cleveland, OH 44106-7058 USA charles@freude.com http://www.cwru.edu/artsci/math/wells/home.html

More information

Computability Theory. CS215, Lecture 6,

Computability Theory. CS215, Lecture 6, Computability Theory CS215, Lecture 6, 2000 1 The Birth of Turing Machines At the end of the 19th century, Gottlob Frege conjectured that mathematics could be built from fundamental logic In 1900 David

More information

Semantics of Higher-Order Functional Programming

Semantics of Higher-Order Functional Programming Semantics of Higher-Order Functional Programming Petros Barbagiannis µ λ July 14, 2014 Petros Barbagiannis Semantics of Higher-Order Functional Programming July 14, 2014 1 / 18 Introduction Higher-order

More information

Non deterministic classical logic: the λµ ++ -calculus

Non deterministic classical logic: the λµ ++ -calculus Paru dans : Mathematical Logic Quarterly, 48, pp. 357-366, 2002 Non deterministic classical logic: the λµ ++ -calculus Karim NOUR LAMA - Equipe de Logique, Université de Savoie 73376 Le Bourget du Lac

More information

Programming Languages

Programming Languages CSE 230: Winter 2008 Principles of Programming Languages Lecture 6: Axiomatic Semantics Deriv. Rules for Hoare Logic `{A} c {B} Rules for each language construct ` {A} c 1 {B} ` {B} c 2 {C} ` {A} skip

More information

Beyond First-Order Logic

Beyond First-Order Logic Beyond First-Order Logic Software Formal Verification Maria João Frade Departmento de Informática Universidade do Minho 2008/2009 Maria João Frade (DI-UM) Beyond First-Order Logic MFES 2008/09 1 / 37 FOL

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

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

CS156: The Calculus of Computation

CS156: The Calculus of Computation Page 1 of 31 CS156: The Calculus of Computation Zohar Manna Winter 2010 Chapter 3: First-Order Theories Page 2 of 31 First-Order Theories I First-order theory T consists of Signature Σ T - set of constant,

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

CBV and CBN. Eduardo Bonelli. TP para LP 2012C1 1/55

CBV and CBN. Eduardo Bonelli. TP para LP 2012C1 1/55 CBV and CBN Eduardo Bonelli TP para LP 2012C1 1/55 Reduction Strategies Call-By-Value Call-by-Name Relating CBN and CBV λ-calculus Continuation Passing Style Bibliography 2/55 Reduction Strategies Reduction

More information

A λ-calculus with Constants and Let-blocks

A λ-calculus with Constants and Let-blocks A λ-calculus with Constants and Let-blocks Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. September 19, 2006 September 19, 2006 http://www.csg.csail.mit.edu/6.827 L04-1 Outline Recursion

More information

Informal Statement Calculus

Informal Statement Calculus FOUNDATIONS OF MATHEMATICS Branches of Logic 1. Theory of Computations (i.e. Recursion Theory). 2. Proof Theory. 3. Model Theory. 4. Set Theory. Informal Statement Calculus STATEMENTS AND CONNECTIVES Example

More information

Programming Language Concepts: Lecture 16

Programming Language Concepts: Lecture 16 Programming Language Concepts: Lecture 16 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in http://www.cmi.ac.in/~madhavan/courses/pl2009 PLC 2009, Lecture 16, 23 March 2009 λ-calculus:

More information

The Lambda-Calculus Reduction System

The Lambda-Calculus Reduction System 2 The Lambda-Calculus Reduction System 2.1 Reduction Systems In this section we present basic notions on reduction systems. For a more detailed study see [Klop, 1992, Dershowitz and Jouannaud, 1990]. Definition

More information

Quantum Functional Programming Language & Its Denotational Semantics

Quantum Functional Programming Language & Its Denotational Semantics Quantum Functional Programming Language & Its Denotational Semantics Ichiro Hasuo Dept. Computer Science University of Tokyo Naohiko Hoshino Research Inst. for Math. Sci. Kyoto University Talk based on:

More information

Computational Models Lecture 8 1

Computational Models Lecture 8 1 Computational Models Lecture 8 1 Handout Mode Nachum Dershowitz & Yishay Mansour. Tel Aviv University. May 17 22, 2017 1 Based on frames by Benny Chor, Tel Aviv University, modifying frames by Maurice

More information

Computational Models Lecture 8 1

Computational Models Lecture 8 1 Computational Models Lecture 8 1 Handout Mode Ronitt Rubinfeld and Iftach Haitner. Tel Aviv University. May 11/13, 2015 1 Based on frames by Benny Chor, Tel Aviv University, modifying frames by Maurice

More information

Elaborating evaluation-order polymorphism

Elaborating evaluation-order polymorphism Elaborating evaluation-order polymorphism Joshua Dunfield University of British Columbia ICFP 2015 1 (prologue) ICFP in Canada for the first time since 2008 2 (prologue) ICFP in Canada for the first time

More information

CSE 311 Lecture 28: Undecidability of the Halting Problem. Emina Torlak and Kevin Zatloukal

CSE 311 Lecture 28: Undecidability of the Halting Problem. Emina Torlak and Kevin Zatloukal CSE 311 Lecture 28: Undecidability of the Halting Problem Emina Torlak and Kevin Zatloukal 1 Topics Final exam Logistics, format, and topics. Countability and uncomputability A quick recap of Lecture 27.

More information

Axiomatic Semantics. Lecture 9 CS 565 2/12/08

Axiomatic Semantics. Lecture 9 CS 565 2/12/08 Axiomatic Semantics Lecture 9 CS 565 2/12/08 Axiomatic Semantics Operational semantics describes the meaning of programs in terms of the execution steps taken by an abstract machine Denotational semantics

More information

an efficient procedure for the decision problem. We illustrate this phenomenon for the Satisfiability problem.

an efficient procedure for the decision problem. We illustrate this phenomenon for the Satisfiability problem. 1 More on NP In this set of lecture notes, we examine the class NP in more detail. We give a characterization of NP which justifies the guess and verify paradigm, and study the complexity of solving search

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

The Knaster-Tarski Fixed Point Theorem for Complete Partial Orders

The Knaster-Tarski Fixed Point Theorem for Complete Partial Orders The Knaster-Tarski Fixed Point Theorem for Complete Partial Orders Stephen Forrest October 31, 2005 Complete Lattices Let (X, ) be a be partially ordered set, and let S X. Then S ( the meet of S ) denotes

More information

6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, Class 10 Nancy Lynch

6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, Class 10 Nancy Lynch 6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, 2010 Class 10 Nancy Lynch Today Final topic in computability theory: Self-Reference and the Recursion

More information

The complexity of recursive constraint satisfaction problems.

The complexity of recursive constraint satisfaction problems. The complexity of recursive constraint satisfaction problems. Victor W. Marek Department of Computer Science University of Kentucky Lexington, KY 40506, USA marek@cs.uky.edu Jeffrey B. Remmel Department

More information

Logic. Propositional Logic: Syntax. Wffs

Logic. Propositional Logic: Syntax. Wffs Logic Propositional Logic: Syntax Logic is a tool for formalizing reasoning. There are lots of different logics: probabilistic logic: for reasoning about probability temporal logic: for reasoning about

More information

Undecibability. Hilbert's 10th Problem: Give an algorithm that given a polynomial decides if the polynomial has integer roots or not.

Undecibability. Hilbert's 10th Problem: Give an algorithm that given a polynomial decides if the polynomial has integer roots or not. Undecibability Hilbert's 10th Problem: Give an algorithm that given a polynomial decides if the polynomial has integer roots or not. The problem was posed in 1900. In 1970 it was proved that there can

More information

Origin in Mathematical Logic

Origin in Mathematical Logic Lambda Calculus Origin in Mathematical Logic Foundation of mathematics was very much an issue in the early decades of 20th century. Cantor, Frege, Russel s Paradox, Principia Mathematica, NBG/ZF The Combinatory

More information

Refined Environment Classifiers

Refined Environment Classifiers Refined Environment Classifiers Type- and Scope-safe Code Generation with Mutable Cells Oleg Kiselyov Yukiyoshi Kameyama Yuto Sudo Tohoku University University of Tsukuba APLAS 2016 November 22, 2016 Region

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Winter 2017 Lecture 2b Andrew Tolmach Portland State University 1994-2017 Semantics Informal vs. Formal Informal semantics Descriptions in English (or other natural language)

More information

Functional Programming with F# Overview and Basic Concepts

Functional Programming with F# Overview and Basic Concepts Functional Programming with F# Overview and Basic Concepts Radu Nicolescu Department of Computer Science University of Auckland 27 Sep 2017 1 / 52 1 Background 2 Overview 3 Type System and Type Inference

More information

The Safe λ-calculus. William Blum. Joint work with C.-H. Luke Ong. Lunch-time meeting, 14 May Oxford University Computing Laboratory

The Safe λ-calculus. William Blum. Joint work with C.-H. Luke Ong. Lunch-time meeting, 14 May Oxford University Computing Laboratory The Safe λ-calculus William Blum Joint work with C.-H. Luke Ong Oxford University Computing Laboratory Lunch-time meeting, 14 May 2007 Overview Safety is originally a syntactic restriction for higher-order

More information

(a) Definition of TMs. First Problem of URMs

(a) Definition of TMs. First Problem of URMs Sec. 4: Turing Machines First Problem of URMs (a) Definition of the Turing Machine. (b) URM computable functions are Turing computable. (c) Undecidability of the Turing Halting Problem That incrementing

More information

Advanced Lambda Calculus. Henk Barendregt & Giulio Manzonetto ICIS Faculty of Science Radboud University Nijmegen, The Netherlands

Advanced Lambda Calculus. Henk Barendregt & Giulio Manzonetto ICIS Faculty of Science Radboud University Nijmegen, The Netherlands Advanced Lambda Calculus Henk Barendregt & Giulio Manzonetto ICIS Faculty of Science Radboud University Nijmegen, The Netherlands Form of the course Ordinary lecture Seminar form Exam: working out an exercise

More information

Nunchaku: Flexible Model Finding for Higher-Order Logic

Nunchaku: Flexible Model Finding for Higher-Order Logic Nunchaku: Flexible Model Finding for Higher-Order Logic Simon Cruanes, Jasmin Blanchette, Andrew Reynolds Veridis, Inria Nancy https://cedeela.fr/~simon/ April 7th, 2016 1 / 21 Summary Introduction Nunchaku

More information

PROOFS IN PREDICATE LOGIC AND COMPLETENESS; WHAT DECIDABILITY MEANS HUTH AND RYAN 2.3, SUPPLEMENTARY NOTES 2

PROOFS IN PREDICATE LOGIC AND COMPLETENESS; WHAT DECIDABILITY MEANS HUTH AND RYAN 2.3, SUPPLEMENTARY NOTES 2 PROOFS IN PREDICATE LOGIC AND COMPLETENESS; WHAT DECIDABILITY MEANS HUTH AND RYAN 2.3, SUPPLEMENTARY NOTES 2 Neil D. Jones DIKU 2005 12 September, 2005 Some slides today new, some based on logic 2004 (Nils

More information