COMP80 Lambda Calculus Programming Languages Slides Courtesy of Prof. Sam Guyer Tufts University Computer Science History Big ideas Examples:


 Ilene Garrison
 1 years ago
 Views:
Transcription
1 COMP80 Programming Languages Slides Courtesy of Prof. Sam Guyer Lambda Calculus Formal system with three parts Notation for functions Proof system for equations Calculation rules called reduction Idea: What is the simplest possible programming language that is still capable of expressing any program? Tufts University Computer Science 2 History Alonzo Church, Created calculus in the 30 s Study of functions Definition, application Question: what things are computable? calculus is equivalent to Turing Machines Important part of CS history and current theory Influenced design of Lisp, ML, Haskell, Big ideas Lambda calculus Simplest possible programming language Almost nothing is built in Provides a model for computability Question: what is it possible to compute? Examples: Easy: what is nth fibonacci number? Hard: what are the prime factors of a number? Undecidable: do two BNFs produce the same language? Turns out: Decidable (computable) functions are those that can be expressed using lambda calculus Tufts University Computer Science 3 Tufts University Computer Science 4 Expressions and Functions Definitions Expressions x + y x + 2*y + z calculus is a formal notation for defining functions expressions in this notation are called expressions every expression denotes a function Functions x. (x + y) z. (x + 2*y + z) Application (x. (x + y)) 3 (z. (x + 2*y + z)) y x + 2*y + 5 A expression consists of 3 kinds of terms: Variables: x, y, z, we use V for arbitrary variables Abstractions: V.E Where V is some variable and E is another term Applications: E 1 E 2 Where E 1 and E 2 are terms Tufts University Computer Science 5 Tufts University Computer Science 6 1
2 Formal Syntax Formal Syntax in BNF Term ::= Variable Variable. Term Term Term ( Term ) Variable ::= x y z Or, more compactly: E ::= V V.E E E (E) V ::= x y z Application is juxtaposition (no operator) Application has higher precedence than Application is leftassociative Tufts University Computer Science 7 Highly ambiguous Again: E ::= V V.E E E (E) V ::= x y z Application is juxtaposition (no operator) Application has higher precedence than Application is leftassociative Examples x. x y z x.x y.y f. f(y.y) g(z) f(g)(h x) x. (x(y))(z) x. (x(y.y)) f. f(y.y) (g(z)) f(g)(h(x)) Tufts University Computer Science 8 Abstractions V.E is an abstraction V is a bound variable over the body E An abstraction represents a function V is the head and E is the body. For example the abstraction: I = x.x is the identity function Applications E 1 E 2 is an application Apply the function E 1 to the argument E 2 calculus only has singleargument functions For example, given the identity function, I = x.x some applications using it (x.x)1 1 (x.x)a a (x.x)(y.y) (y.y) Tufts University Computer Science 9 Tufts University Computer Science 10 Reduction Basic computation rule is reduction (x. e 1 ) e 2 [e 2 /x]e 1 Reduction Apply reduction to any subexpression Repeat until no more reductions possible Result is called normal form Confluence ChurchRosser theorem Final result (if there is one) is uniquely determined Two functions compute the same thing iff they reduce to the same normal form Tufts University Computer Science 11 Free and Bound Variables Bound variable is placeholder Variable x is bound in x.(x+y) Function x.(x+y) is same function as z.(z+y) Compare x+y dx = z+y dz x P(x) = z P(z) Name of free (=unbound) variable does matter Variable y is free in x.(x+y) Function x.(x+y) is not same as x.(x+z) Occurrences y is free and bound in x. ((y. y+2) x) + y Tufts University Computer Science 12 2
3 Rename Bound Variables Function application (f. x. f (f x)) (y. y+x) Substitute blindly x. [(y. y+x) ((y. y+x) x)] = x. x+x+x Rename bound variables (f. z. f (f z)) (y. y+x) = z. [(y. y+x) ((y. y+x) z))] = z. z+x+x Easy rule: always rename variables to be distinct Substitution [N/x]E means replace x with N in E Variables [N/x]x [N/x]y Application N y [N/x](M 1 M 2 ) ([N/x]M 1 ) ([N/x]M 2 ) Abstraction [N/x] x.m x.m [N/x] y.m y.[n/x]m where y not free in N Tufts University Computer Science 13 Tufts University Computer Science 14 Conversion/reduction rules conversion x.e y.[y/x]e where y not free in E Rename bound variables to avoid naming conflicts reduction (x.m)n [N/x]M Function application defined by substitution conversion v.ev E where v is not free in E Remove redundant abstractions Proof: (x. f x) y = f y therefore x. f x = f HigherOrder Functions Given function f, return function f f f. x. f (f x) How does this work? (f. x. f (f x)) (y. y+1) = x. (y. y+1) ((y. y+1) x) = x. (y. y+1) (x+1) = x. (x+1)+1 Tufts University Computer Science 15 Tufts University Computer Science 16 Programming calculus calculus is Turing complete What does that mean? Equivalent to any other complete programming language How to make Booleans and conditional functions numerals and arithmetic functions data structures, such as ordered pairs, lists, etc. recursion For convenience x.y.m is written xy.m cuts down on number of s Church Booleans We define Booleans and logical operators in the calculus as functions: True = t. f. t False = t. f. f And = x. y. x y (t.f. f) = x y. x y False Or = x.y. x (t.f. t) y = x y. x True y Neg = x. x (u.v. v) (a.b. a) = x. x False True Example: NEG True = (x.x(uv.v)(ab.a))(tf.t) (t.f.t)(uv.v)(ab.a) (f.(uv.v)) (ab.a) (uv.v) = False Tufts University Computer Science 17 Tufts University Computer Science 18 3
4 Church Booleans: If statements Given True = tf.t False = tf.f Define a conditional test function if C then X else Y If C X Y If = cxy.cxy If True X Y True X Y X If False X Y False X Y Y Note If = c.x.(y.(cx)y) c.(x.cx) c.c = I by conversion Booleans are if functions Church Numerals The natural numbers may be defined using zero and the successor function: 0, 1=succ(0), 2=succ(succ(0)),, etc. In the calculus, we only have functions Define the natural numbers as functions: 0 = fx.x What else has this definition? 1 = fx.f(x) 2 = fx.f(f(x)) 3 = fx.f(f(f(x)))) n = fx.f n (x) Idea: we represent a number as a lambda expression that applies some function (doesn t matter what function) that number of times. Tufts University Computer Science 19 Tufts University Computer Science 20 Successor function So how do we write a successor function? S = n.fx.f (n f x) Let s test it on zero = gy.y S 0 = (n.fx.f (n f x)) (gy.y) fx.f((gy.y) f x) fx.f((y.y) x) fx.f(x) 1 beta reduction eta conversion beta reduction Note that yx.y(x) = fx.f(z) by conversion bound variables names are dummy variables More Arithmetic: PLUS := m n f x. n f (m f x) Interpretation: m, n are functions that apply f n times To add them together, start with m, and use the function n to apply f n more times Lists: CONS := f. s. b. b f s CAR := p. p TRUE CDR := p. p FALSE NIL := x.true Tufts University Computer Science 21 Tufts University Computer Science 22 Recursive Functions How to represent recursive functions? let Fact(n) = if (n=0) then 1 else n*fact(n1) in Fact(5) Write this as calculus expression P = (Fact. Fact(5)) (n. If (Eq n 0) 1 (Mult n (Fact (Sub n 1)))) assuming definitions for Eq, Mult, Sub What s the problem? Fact is a free variable in the second part of P Cannot use a function before it is defined Tufts University Computer Science 23 Recursive Functions Back up & focus on the recursive definition Fact = n. if (n=0) then 1 else n * Fact(n1) Abstract Fact to make nonrecursive generator G( f ) = n. if (n=0) then 1 else n * f(n1) performs 1 step of factorial computation, then calls f G = f. n. if (n=0) then 1 else n * f(n1) How do we compute more steps? Two steps: G(G(f)) Three steps: G(G(G(f))) Actually, we want f = G Intuitively: call G recursively as many times as it takes Tufts University Computer Science 24 4
5 Fixed point function Called a fixpoint Keep calling G recursively until stops When will that happen? G( 0 ) = n. if (n=0) then 1 else n * G(n1) How do we make this work in calculus? Idea: a function that computes the fixpoint of other functions Called a combinator Example: Y combinator Y = f. (x. f(x x)) (x. f(x x)) Fixed point function Y combinator in calculus: Y = f. (x. f(x x)) (x. f(x x)) Has special property that Y( G ) = G( Y(G) ) = G ( G ( Y (G) ) ) = G ( G ( G ( G (... )))) Uses selfapplication in (x x) Y = f. (x. f (x x)) (y. f(y y)) = f. f ( (y. f(y y)) (y. f(y y)) ) = f. f ( (y. f(y y)) (y. f(y y)) ) = f. f ( f ( (y. f(y y)) (y. f(y y)) ) We will see selfapplication again when we talk about objects Tufts University Computer Science 25 Tufts University Computer Science 26 Reduction Order Reduction strategy An way of defining which reduction to perform Normal order: always perform leftmost reduction Applicative order: reduce arguments before application Confluence All reduction strategies that return a normal form return the same normal form but some strategies may not terminate, while others do Cost Different reduction strategies can involve different number of reduction steps What is a functional language? Functional languages have Functions as firstclass values A data type is firstclass if it can be used anywhere: passed to and returned from functions, assigned to variables May also have imperative constructs Examples: Lisp, Scheme, ML, Erlang Pure functional languages Have no implicit side effects or other imperative features Example: Miranda, Haskell Tufts University Computer Science 27 Tufts University Computer Science 28 Functional languages Two big ideas: Functions as data A program can create and manipulate functions on the fly Higherorder functions Twice and compose Currying: customize a function for one input No sideeffects Given the same inputs, a function always returns the same result A function has no effects other than producing the return value Variables don t change value there s no store operation We can reason mathematically about functional programs Goal: Translate a program into a mathematic expression Get rid of syntactic details Give a meaning that is completely unambiguous Often: generate a functional program (e.g. in lambda calculus) How is this useful? Systematic conversion into formal notation We can reason about the correctness In practice Most programming languages have informal semantics Example: A break statement terminates the nearest enclosing loop or switch statement Tufts University Computer Science 29 Tufts University Computer Science 30 5
6 Example Syntax B ::= 0 1 N ::= B N B E ::= N E + E value function : E number [[ 0 ]] = 0 [[ 1 ]] = 1 [[ N B ]] = 2 * [[ N ]] + [[ B ]] [[ E 1 + E 2 ]] = [[ E 1 ]] + [[ E 2 ]] Key ideas: Gives a meaning to the syntax Eliminates syntactic details Example: 001 = 01 = 1 Tufts University Computer Science 31 Denotational semantics Idea: Translate a program into a function More mathematical, more precise Program s meaning: Translate each construct into a function from inputs to outputs Compose functions for a program into a large function that computes the whole thing Roughly like compilation Translation to assembly code => for execution We will compile down to lambda calculus => for reasoning Tufts University Computer Science 32 Translation into functions Translating a program into a function How do we do that? Translate each primitive construct into a function Define rules to assemble these functions What kinds of constructs? Assignment: x = y + 5; Conditional: if (c < 10) z = 20; Loops: while (z!= 0) z; How to represent these things as functions? Example: what does assignment do? Updates a location in memory (whose name is x ) Tufts University Computer Science 33 Statements as functions Statement: x = 5; Meaning: Update the memory location called x with value 5 How do I represent x=5 as a function? Mapping from one program state to another What is a program state? Typically: a mapping from variables to values Example: s = { (x=0), (y=10), (z=999) } Key: Each function produces a new state never modify a state Now we re functional Tufts University Computer Science 34 Example Statement x = 5; : [[ x=5 ]]: state state Start state: s = { (x=0), (y=10), (z=999) } Next state: this is a function t = [[ x=5 ]] (s) = { (x=5), (y=10), (z=999) } Voila: no store operation, no sideeffects Basic principle of denotational semantics Compositionality The meaning of a compound program must be defined from the meanings of its parts (not the syntax of its parts). Syntax guides translation to functions Tells us how to compose the functions of the parts Example { P; Q; } composition of two functions, state state Q : state state and P : state state Complete function: Q ( P ( start state ) ) Tufts University Computer Science 35 Tufts University Computer Science 36 6
7 of Imperative Programs Syntax P ::= x := E P; P if E then P else P while E do P : Program (State State) State = Variable Value = v. (give me the value of v) of Assignment Assignment [[ x := E ]] : state state change state with x updated to new value [[ x := E ]]s = s where s = v. IF ( v=x ) ( [[ E ]]s )( s(v) ) s : variable value state = (variable value) s is identical to s except for value of variable x Tufts University Computer Science 37 Tufts University Computer Science 38 Expressions More straightforward [[ E ]]s : [[ E + E ]]s =? = [[ E ]]s + [[ E ]]s [[ E / E ]]s =? = [[ E ]]s / [[ E ]]s [[ (E) ]]s =? = [[ E ]]s [[ v ]]s =? = s(v) of Sequences Sequence [[ P 1 ; P 2 ]] : state state Perform changes from P 1, then perform changes in P 2 [[ P 1 ; P 2 ]] s = [[ P 2 ]] ( [[ P 1 ]] s ) [[ P 1 ; P 2 ]] = s.[[ P 2 ]] ( [[ P 1 ]] s ) [[ P 1 ; P 2 ]] = [[ P 2 ]] [[ P 1 ]] Where is function composition F G = s.f(g(s)) Tufts University Computer Science 39 Tufts University Computer Science 40 of Conditional Conditional [[ if B then P else Q ]] : state state test B in input state, then perform either P or Q on state [[ if B then P else Q ]] s = = IF ( [[ B ]]s ) ( [[ P ]]s ) ( [[ Q ]]s ) Simplification: assume B does not have side effects What would we have to do if B had side effects? Tufts University Computer Science 41 of Iteration Iteration [[ while B do P ]] : state state test B in input state, if true do P, then while B do P Two parts: [[ B ]] the evaluation of expression B [[ P ]] the translation of the body P What do iterations look like? One: if [[ B ]]s then [[ P ]]s else s Two: if [[ B ]]s then let s = [[ P ]]s in (if [[ B ]]s then [[ P ]]s else s ) else s Tufts University Computer Science 42 7
8 of Iteration Generalize: [[ while B do P ]] = the function f such that f(s) = IF ( [[ B ]]s ) ( f( [[ P ]]s ) ) ( s ) What does this look like? I want X, such that X(P) = f(x(p)) = f(f(x(p))) Yep, it s defined by the Y combinator This is what we expect, right? Iteration (e.g., while) becomes recursion Recursion is defined as a fixpoint on the body of the loop How does this help me? Problem: Real languages have many constructs They can be combined in wacky ways Need a clear understanding of what they mean Examples: x = i i; a = b = c = 0; while (*p++ = *q++) ; Tufts University Computer Science 43 Tufts University Computer Science 44 Example Statement: x = 5; y = f(10) + x; What if f modifies x? int f(int a) { x = a; return a; } What about: y = x + f(10); How can I explain this? [[ f ]]s produces a new state s [[ f(10) + x ]] = let s = [[ t = f(10) ]]s in [[ t + x ]]s Tufts University Computer Science 45 8
9/23/2014. Why study? Lambda calculus. Church Rosser theorem Completeness of Lambda Calculus: Turing Complete
Dr A Sahu Dept of Computer Science & Engineering IIT Guwahati Why study? Lambda calculus Syntax Evaluation Relationship to programming languages Church Rosser theorem Completeness of Lambda Calculus: Turing
More informationLambda Calculus. CS 550 Programming Languages Jeremy Johnson
Lambda Calculus CS 550 Programming Languages Jeremy Johnson 1 Lambda Calculus The semantics of a pure functional programming language can be mathematically described by a substitution process that mimics
More informationConstraintbased Analysis. Harry Xu CS 253/INF 212 Spring 2013
Constraintbased Analysis Harry Xu CS 253/INF 212 Spring 2013 Acknowledgements Many slides in this file were taken from Prof. Crista Lope s slides on functional programming as well as slides provided by
More informationLambda Calculus.
Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky, S. Tanimoto, Stephen A. Edwards) Benjamin Pierce Types and Programming Languages http://www.cs.cornell.edu/courses/cs3110/2008fa/recitations/rec26.html
More informationThe Untyped Lambda Calculus
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... paste or by selection, annotation, or rewording. [Järvi] is in turn
More information1 Scope, Bound and Free Occurrences, Closed Terms
CS 6110 S18 Lecture 2 The λcalculus Last time we introduced the λcalculus, a mathematical system for studying the interaction of functional abstraction and functional application. We discussed the syntax
More informationCOMP 1130 Lambda Calculus. based on slides by Jeff Foster, U Maryland
COMP 1130 Lambda Calculus based on slides by Jeff Foster, U Maryland Motivation Commonlyused programming languages are large and complex ANSI C99 standard: 538 pages ANSI C++ standard: 714 pages Java
More informationThe Untyped Lambda Calculus
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... paste or by selection, annotation, or rewording. [Järvi] is in turn
More informationFundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP)
Fundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP) Prof. Dekai Wu Department of Computer Science and Engineering The Hong Kong University of Science and Technology
More informationCSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGrawHill Companies, Inc.
CSC312 Principles of Programming Languages : Functional Programming Language Overview of Functional Languages They emerged in the 1960 s with Lisp Functional programming mirrors mathematical functions:
More informationIntroduction to Lambda Calculus. Lecture 7 CS /08/09
Introduction to Lambda Calculus Lecture 7 CS 565 02/08/09 Lambda Calculus So far, we ve explored some simple but noninteresting languages language of arithmetic expressions IMP (arithmetic + while loops)
More informationIntroduction to the Lambda Calculus. Chris Lomont
Introduction to the Lambda Calculus Chris Lomont 2010 2011 2012 www.lomont.org Leibniz (16461716) Create a universal language in which all possible problems can be stated Find a decision method to solve
More informationINF 212 ANALYSIS OF PROG. LANGS LAMBDA CALCULUS. Instructors: Crista Lopes Copyright Instructors.
INF 212 ANALYSIS OF PROG. LANGS LAMBDA CALCULUS Instructors: Crista Lopes Copyright Instructors. History Formal mathematical system Simplest programming language Intended for studying functions, recursion
More informationCIS 500 Software Foundations Fall September 25
CIS 500 Software Foundations Fall 2006 September 25 The Lambda Calculus The lambdacalculus If our previous language of arithmetic expressions was the simplest nontrivial programming language, then the
More informationIntroduction to the lcalculus
Introduction to the lcalculus CS345  Programming Languages Dr. Greg Lavender Department of Computer Sciences The University of Texas at Austin lcalculus in Computer Science a formal notation, theory,
More informationPrinciples of Programming Languages COMP251: Functional Programming in Scheme (and LISP)
Principles of Programming Languages COMP251: Functional Programming in Scheme (and LISP) Prof. Dekai Wu Department of Computer Science and Engineering The Hong Kong University of Science and Technology
More informationλ calculus Function application Untyped λcalculus  Basic Idea Terms, Variables, Syntax β reduction Advanced Formal Methods
Course 2D1453, 200607 Advanced Formal Methods Lecture 2: Lambda calculus Mads Dam KTH/CSC Some material from B. Pierce: TAPL + some from G. Klein, NICTA Alonzo Church, 19031995 ChurchTuring thesis First
More informationPart I. Historical Origins
Introduction to the λcalculus Part I CS 209  Functional Programming Dr. Greg Lavender Department of Computer Science Stanford University Historical Origins Foundations of Mathematics (18791936) Paradoxes
More informationLambda Calculus. Type Systems, Lectures 3. Jevgeni Kabanov Tartu,
Lambda Calculus Type Systems, Lectures 3 Jevgeni Kabanov Tartu, 13.02.2006 PREVIOUSLY ON TYPE SYSTEMS Arithmetical expressions and Booleans Evaluation semantics Normal forms & Values Getting stuck Safety
More informationFunctional Programming. Pure Functional Languages
Functional Programming Pure functional PLs Sexpressions cons, car, cdr Defining functions readevalprint loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure
More informationOrganization of Programming Languages CS3200/5200N. Lecture 11
Organization of Programming Languages CS3200/5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Functional vs. Imperative The design of the imperative languages
More informationFormal Semantics. Aspects to formalize. Lambda calculus. Approach
Formal Semantics Aspects to formalize Why formalize? some language features are tricky, e.g. generalizable type variables, nested functions some features have subtle interactions, e.g. polymorphism and
More informationMore Untyped Lambda Calculus & Simply Typed Lambda Calculus
Concepts in Programming Languages Recitation 6: More Untyped Lambda Calculus & Simply Typed Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky,
More informationFunctional Programming. Pure Functional Languages
Functional Programming Pure functional PLs Sexpressions cons, car, cdr Defining functions readevalprint loop of Lisp interpreter Examples of recursive functions Shallow, deep Equality testing 1 Pure
More informationIntroduction to Lambda Calculus. Lecture 5 CS 565 1/24/08
Introduction to Lambda Calculus Lecture 5 CS 565 1/24/08 Lambda Calculus So far, we ve explored some simple but noninteresting languages language of arithmetic expressions IMP (arithmetic + while loops)
More informationPROGRAMMING IN HASKELL. Chapter 2  First Steps
PROGRAMMING IN HASKELL Chapter 2  First Steps 0 The Hugs System Hugs is an implementation of Haskell 98, and is the most widely used Haskell system; The interactive nature of Hugs makes it well suited
More informationFunctional Programming
Functional Programming COMS W4115 Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science Original version by Prof. Simon Parsons Functional vs. Imperative Imperative programming
More informationCMSC 330: Organization of Programming Languages. Lambda Calculus Encodings
CMSC 330: Organization of Programming Languages Lambda Calculus Encodings CMSC330 Spring 2018 1 The Power of Lambdas Despite its simplicity, the lambda calculus is quite expressive: it is Turing complete!
More informationScheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7
Scheme Textbook, Sections 13.1 13.3, 13.7 1 Functional Programming Based on mathematical functions Take argument, return value Only function call, no assignment Functions are firstclass values E.g., functions
More informationRedefinition of an identifier is OK, but this is redefinition not assignment; Thus
Redefinition of an identifier is OK, but this is redefinition not assignment; Thus val x = 100; val x = (x=100); is fine; there is no type error even though the first x is an integer and then it is a boolean.
More informationCMSC330. Objects, Functional Programming, and lambda calculus
CMSC330 Objects, Functional Programming, and lambda calculus 1 OOP vs. FP Objectoriented programming (OOP) Computation as interactions between objects Objects encapsulate mutable data (state) Accessed
More informationMore Lambda Calculus and Intro to Type Systems
More Lambda Calculus and Intro to Type Systems Plan Heavy Class Participation Thus, wake up! Lambda Calculus How is it related to real life? Encodings Fixed points Type Systems Overview Static, Dyamic
More informationDenotational Semantics. Domain Theory
Denotational Semantics and Domain Theory 1 / 51 Outline Denotational Semantics Basic Domain Theory Introduction and history Primitive and lifted domains Sum and product domains Function domains Meaning
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Lambda Calculus Encodings CMSC 330 Spring 2017 1 Review A lambda calculus expression is defined as e ::= x variable λx.e abstraction (fun def) e e application
More informationCSCE 314 Programming Languages
CSCE 314 Programming Languages Haskell 101 Dr. Hyunyoung Lee 1 Contents 1. Historical Background of Haskell 2. Lazy, Pure, and Functional Language 3. Using ghc and ghci 4. Functions 5. Haskell Scripts
More informationCMSC 336: Type Systems for Programming Languages Lecture 4: Programming in the Lambda Calculus Acar & Ahmed 22 January 2008.
CMSC 336: Type Systems for Programming Languages Lecture 4: Programming in the Lambda Calculus Acar & Ahmed 22 January 2008 Contents 1 Announcements 1 2 Solution to the Eercise 1 3 Introduction 1 4 Multiple
More informationCSE 3302 Programming Languages Lecture 8: Functional Programming
CSE 3302 Programming Languages Lecture 8: Functional Programming (based on the slides by Tim Sheard) Leonidas Fegaras University of Texas at Arlington CSE 3302 L8 Spring 2011 1 Functional Programming Languages
More informationIntroduction to the λcalculus
Announcements Prelim #2 issues: o Problem 5 grading guide out shortly o Problem 3 (hashing) issues Will be on final! Friday RDZ office hours are 1112 not 1:302:30 1 Introduction to the λcalculus Today
More informationCS152: Programming Languages. Lecture 7 Lambda Calculus. Dan Grossman Spring 2011
CS152: Programming Languages Lecture 7 Lambda Calculus Dan Grossman Spring 2011 Where we are Done: Syntax, semantics, and equivalence For a language with little more than loops and global variables Now:
More informationλ calculus is inconsistent
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
More informationWhereweare. CSXXX: Graduate Programming Languages. Lecture 7 Lambda Calculus. Adding data structures. Data + Code. What about functions
Whereweare CSXXX: Graduate Programming Languages Lecture 7 Lambda Calculus Done: Syntax, semantics, and equivalence For a language with little more than loops and global variables Now: Didn t IMP leave
More informationJ. Barkley Rosser, 81, a professor emeritus of mathematics and computer science at the University of Wisconsin who had served in government, died
ChurchRosser J. Barkley Rosser, 81, a professor emeritus of mathematics and computer science at the University of Wisconsin who had served in government, died Sept. 5, 1989. Along with Alan Turing and
More informationProcessadors de Llenguatge II. Functional Paradigm. Pratt A.7 Robert Harper s SML tutorial (Sec II)
Processadors de Llenguatge II Functional Paradigm Pratt A.7 Robert Harper s SML tutorial (Sec II) Rafael Ramirez Dep Tecnologia Universitat Pompeu Fabra Paradigm Shift Imperative Paradigm State Machine
More informationPolymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy
0602552 Princ. of Progr. Languages (and Extended ) The University of Birmingham Spring Semester 201617 School of Computer Science c Uday Reddy201617 Handout 6: Polymorphic Type Systems 1. Polymorphic
More informationChapter 2 The Language PCF
Chapter 2 The Language PCF We will illustrate the various styles of semantics of programming languages with an example: the language PCF Programming language for computable functions, also called MiniML.
More informationChapter 5: The Untyped Lambda Calculus
Chapter 5: The Untyped Lambda Calculus What is lambda calculus for? Basics: syntax and operational semantics Programming in the Lambda Calculus Formalities (formal definitions) What is Lambda calculus
More informationProgramming with Math and Logic
.. Programming with Math and Logic an invitation to functional programming Ed Morehouse Wesleyan University The Plan why fp? terms types interfaces The What and Why of Functional Programming Computing
More informationScope, Functions, and Storage Management
Scope, Functions, and Storage Management Implementing Functions and Blocks cs3723 1 Simplified Machine Model (Compare To List Abstract Machine) Registers Code Data Program Counter (current instruction)
More informationSCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015
SCHEME 7 COMPUTER SCIENCE 61A October 29, 2015 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationFundamental Concepts. Chapter 1
Chapter 1 Fundamental Concepts This book is about the mathematical foundations of programming, with a special attention on computing with infinite objects. How can mathematics help in programming? There
More informationTo figure this out we need a more precise understanding of how ML works
Announcements: What are the following numbers: 52/37/19/6 (2:30,3:35,11:15,7:30) PS2 due Thursday 9/22 11:59PM Quiz #1 back in section Monday Quiz #2 at start of class on Thursday 9/22 o HOP s, and lots
More informationSpring 2018 Discussion 7: March 21, Introduction. 2 Primitives
CS 61A Scheme Spring 2018 Discussion 7: March 21, 2018 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme
More informationMore Lambda Calculus and Intro to Type Systems
#1 More Lambda Calculus and Intro to Type Systems #2 Plan Heavy Class Participation Thus, wake up! (not actually kidding) Lambda Calculus How is it related to real life? Encodings Fixed points Type Systems
More informationRecursive Functions of Symbolic Expressions and Their Application, Part I
Recursive Functions of Symbolic Expressions and Their Application, Part I JOHN MCCARTHY Review: Amit Kirschenbaum Seminar in Programming Languages Recursive Functions of Symbolic Expressions and Their
More informationCSE 505. Lecture #9. October 1, Lambda Calculus. Recursion and Fixedpoints. Typed Lambda Calculi. Least Fixed Point
Lambda Calculus CSE 505 Lecture #9 October 1, 2012 Expr ::= Var λ Var. Expr (Expr Expr) Key Concepts: Bound and Free Occurrences Substitution, Reduction Rules: α, β, η Confluence and Unique Normal Form
More informationFall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives
CS 6A Scheme Fall 207 Discussion 7: October 25, 207 Solutions Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write
More informationLambda Calculus alpharenaming, beta reduction, applicative and normal evaluation orders, ChurchRosser theorem, combinators
Lambda Calculus alpharenaming, beta reduction, applicative and normal evaluation orders, ChurchRosser theorem, combinators Carlos Varela Rennselaer Polytechnic Institute February 11, 2010 C. Varela 1
More informationFunctional Languages and HigherOrder Functions
Functional Languages and HigherOrder Functions Leonidas Fegaras CSE 5317/4305 L12: HigherOrder Functions 1 FirstClass Functions Values of some type are firstclass if They can be assigned to local variables
More informationStop coding Pascal. Saturday, April 6, 13
Stop coding Pascal...emotional sketch about past, present and future of programming languages, Python, compilers, developers, Life, Universe and Everything Alexey Kachayev CTO at KitApps Inc. Open source
More informationIntroduction to Functional Programming in Haskell 1 / 56
Introduction to Functional Programming in Haskell 1 / 56 Outline Why learn functional programming? The essence of functional programming What is a function? Equational reasoning Firstorder vs. higherorder
More informationCSCI 3155: Principles of Programming Languages Exam preparation #1 2007
CSCI 3155: Principles of Programming Languages Exam preparation #1 2007 Exercise 1. Consider the ifthenelse construct of Pascal, as in the following example: IF 1 = 2 THEN PRINT X ELSE PRINT Y (a) Assume
More informationScheme: Data. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, Glenn G.
Scheme: Data CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, April 3, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks ggchappell@alaska.edu
More informationRecursion. Lecture 6: More Lambda Calculus Programming. Fixed Points. Recursion
Recursion Lecture 6: More Lambda Calculus Programming CSC 131! Fall, 2014!! Kim Bruce Recursive definitions are handy!  fact = λn. cond (iszero n) 1 (Mult n (fact (Pred n)))!  Not a legal definition
More informationReview. CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Let bindings (CBV) Adding Stuff. Booleans and Conditionals
Review CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics e ::= λx. e x ee c v ::= λx. e c (λx. e) v e[v/x] e 1 e 2 e 1 e 2 τ ::= int τ τ Γ ::= Γ,x : τ e 2 e 2 ve 2 ve 2 e[e /x]:
More informationCHAPTER 4. COMPUTABILITY AND DECIDABILITY
CHAPTER 4. COMPUTABILITY AND DECIDABILITY 1. Introduction By definition, an nary function F on N assigns to every ntuple k 1,...,k n of elements of N a unique l N which is the value of F at k 1,...,k
More informationThoughts on Assignment 4 Haskell: Flow of Control
Thoughts on Assignment 4 Haskell: Flow of Control CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, February 27, 2017 Glenn G. Chappell Department of Computer
More informationImperative Paradigm. Syntax. Role of Programming Languages. Expressions. Expressions. Role of Programming Languages. Symbols.
Imperative Paradigm Syntax Rupesh Nasre. CS3100 Paradigms of Programming IIT Madras Jul 2014 Symbols int, cs12b063, function Expressions 10 * x, abs(x y), ++x Constructs ifelse, while {, functionbeginend
More information7. Introduction to Denotational Semantics. Oscar Nierstrasz
7. Introduction to Denotational Semantics Oscar Nierstrasz Roadmap > Syntax and Semantics > Semantics of Expressions > Semantics of Assignment > Other Issues References > D. A. Schmidt, Denotational Semantics,
More informationLecture 9: Typed Lambda Calculus
Advanced Topics in Programming Languages Spring Semester, 2012 Lecture 9: Typed Lambda Calculus May 8, 2012 Lecturer: Mooly Sagiv Scribe: Guy Golan Gueta and Shachar Itzhaky 1 Defining a Type System for
More informationData Types The ML Type System
7 Data Types 7.2.4 The ML Type System The following is an ML version of the tailrecursive Fibonacci function introduced Fibonacci function in ML in Section 6.6.1: EXAMPLE 7.96 1. fun fib (n) = 2. let
More informationThe Metalanguage λprolog and Its Implementation
The Metalanguage λprolog and Its Implementation Gopalan Nadathur Computer Science Department University of Minnesota (currently visiting INRIA and LIX) 1 The Role of Metalanguages Many computational tasks
More informationTHE CALCULATOR SYNTAX
TH CALCULATOR After looking at the basics of the denotational method with the binary numerals we will take chmidt s example of a calculator to bring us one step closer to looking at the semantics of a
More informationModule 6. Knowledge Representation and Logic (First Order Logic) Version 2 CSE IIT, Kharagpur
Module 6 Knowledge Representation and Logic (First Order Logic) 6.1 Instructional Objective Students should understand the advantages of first order logic as a knowledge representation language Students
More informationCS 415 Midterm Exam Spring 2002
CS 415 Midterm Exam Spring 2002 Name KEY Email Address Student ID # Pledge: This exam is closed note, closed book. Good Luck! Score Fortran Algol 60 Compilation Names, Bindings, Scope Functional Programming
More informationPrinciples of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003
Principles of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003 CS 314, LS, LTM: Functional Programming 1 Scheme A program is an expression to be evaluated (in
More informationCOMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking
Agenda COMP 181 Type checking October 21, 2009 Next week OOPSLA: Objectoriented Programming Systems Languages and Applications One of the top PL conferences Monday (Oct 26 th ) Inclass midterm Review
More informationCONVENTIONAL EXECUTABLE SEMANTICS. Grigore Rosu CS422 Programming Language Semantics
CONVENTIONAL EXECUTABLE SEMANTICS Grigore Rosu CS422 Programming Language Semantics Conventional Semantic Approaches A language designer should understand the existing design approaches, techniques and
More informationPrinciples of Programming Languages
Principles of Programming Languages www.cs.bgu.ac.il/~ppl172 Lesson 6  Defining a Programming Language Bottom Up Collaboration and Management  Elements of Programming Dana Fisman 1 What we accomplished
More informationCMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics
Recall Architecture of Compilers, Interpreters CMSC 330: Organization of Programming Languages Source Scanner Parser Static Analyzer Operational Semantics Intermediate Representation Front End Back End
More informationSOFTWARE ARCHITECTURE 6. LISP
1 SOFTWARE ARCHITECTURE 6. LISP Tatsuya Hagino hagino@sfc.keio.ac.jp slides URL https://vu5.sfc.keio.ac.jp/sa/ 2 Compiler vs Interpreter Compiler Translate programs into machine languages Compilers are
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2016 Lecture 6a Andrew Tolmach Portland State University 19942016 Functional Programming An alternative paradigm to imperative programming Firstclass functions Emphasis
More informationIntroduction to Concepts in Functional Programming. CS16: Introduction to Data Structures & Algorithms Spring 2017
Introduction to Concepts in Functional Programming CS16: Introduction to Data Structures & Algorithms Spring 2017 Outline Functions State Functions as building blocks Higher order functions Map Reduce
More informationA Theory of Parallel Computation The πcalculus
A Theory of Parallel Computation The πcalculus Background DFAs, NFAs, pushdown automata, Turing machines... All are mathematical entities that model computation. These abstract systems have concrete,
More informationLesson 4 Typed Arithmetic Typed Lambda Calculus
Lesson 4 Typed Arithmetic Typed Lambda 1/28/03 Chapters 8, 9, 10 Outline Types for Arithmetic types the typing relation safety = progress + preservation The simply typed lambda calculus Function types
More information3.1 λcalculus: Syntax
3 The Lambda Calculus The Lambda calculus, or λcalculus, is a model of computation based on the idea that algorithms can be seen as mathematical functions mapping inputs to outputs. It was introduced
More informationProgram certification with computational
Program certification with computational effects Burak Ekici j.w.w. JeanGuillaume Dumas, Dominique Duval, Damien Pous y LJK, University Joseph Fourier, Grenoble y LIP, ENSLyon November 5, 2014 JNCF 14,
More information3.4 Deduction and Evaluation: Tools ConditionalEquational Logic
3.4 Deduction and Evaluation: Tools 3.4.1 ConditionalEquational Logic The general definition of a formal specification from above was based on the existence of a precisely defined semantics for the syntax
More informationDining Philosophers with πcalculus
Dining Philosophers with πcalculus Matthew Johnson January 28, 2015 Overview The primary goal of this project was to explore the πcalculus by implementing a deadlockfree solution to the dining philosophers
More informationFUNCTIONAL PROGRAMMING (1) PROF. SIMON PARSONS
FUNCTIONAL PROGRAMMING (1) PROF. SIMON PARSONS Imperative programming is concerned with how. Functional or applicative programming is, by contrast, concerned with what. It is based on the mathematics of
More informationProgramming Languages. Dr. Philip Cannata 1
Programming Languages Dr. Philip Cannata 1 10 High Level Languages This Course Jython in Java Java (Object Oriented) ACL2 (Propositional Induction) Relation Algorithmic Information Theory (Information
More informationProgramming Languages Fall 2014
Programming Languages Fall 2014 Lecture 7: Simple Types and SimplyTyped Lambda Calculus Prof. Liang Huang huang@qc.cs.cuny.edu 1 Types stuck terms? how to fix it? 2 Plan First I For today, we ll go back
More informationProgramming Languages Fall 2013
Programming Languages Fall 2013 Lecture 7: Simple Types and SimplyTyped Lambda Calculus Prof. Liang Huang huang@qc.cs.cuny.edu Types stuck terms? how to fix it? Plan First I For today, we ll go back to
More informationCS 314 Principles of Programming Languages. Lecture 16
CS 314 Principles of Programming Languages Lecture 16 Zheng Zhang Department of Computer Science Rutgers University Friday 28 th October, 2016 Zheng Zhang 1 CS@Rutgers University Class Information Reminder:
More informationProgramming Languages Third Edition. Chapter 9 Control I Expressions and Statements
Programming Languages Third Edition Chapter 9 Control I Expressions and Statements Objectives Understand expressions Understand conditional statements and guards Understand loops and variation on WHILE
More informationCS422  Programming Language Design
1 CS422  Programming Language Design Denotational Semantics Grigore Roşu Department of Computer Science University of Illinois at UrbanaChampaign 2 Denotational semantics, alsoknownasfixpoint semantics,
More informationComplexity of Algorithms
CSCE 222 Discrete Structures for Computing Complexity of Algorithms Dr. Hyunyoung Lee Based on slides by Andreas Klappenecker 1 Overview Example  Fibonacci Motivating Asymptotic Run Time Analysis Asymptotic
More informationCS 209 Functional Programming
CS 209 Functional Programming Lecture 03  Intro to Monads Dr. Greg Lavender Department of Computer Science Stanford University "The most important thing in a programming language is the name. A language
More informationA Tutorial Introduction to the Lambda Calculus
A Tutorial Introduction to the Lambda Calculus Raúl Rojas FU Berlin, WS97/98 Abstract This paper is a short and painless introduction to the λ calculus. Originally developed in order to study some mathematical
More informationConversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = "Hello";
Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). In Java, this is legal: Object x = "Hello";
More informationPart II. Hoare Logic and Program Verification. Why specify programs? Specification and Verification. Code Verification. Why verify programs?
Part II. Hoare Logic and Program Verification Part II. Hoare Logic and Program Verification Dilian Gurov Props: Models: Specs: Method: Tool: safety of data manipulation source code logic assertions Hoare
More information