CMSC 330: Organization of Programming Languages Lambda Calculus Introduction.

Slides:



Advertisements
Similar presentations
Substitution & Evaluation Order cos 441 David Walker.
Advertisements

Some non-recursive tricks. The Lambda expression. More on Let, Let*, apply and funcall.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Part B.
The lambda calculus David Walker CS 441. the lambda calculus Originally, the lambda calculus was developed as a logic by Alonzo Church in 1932 –Church.
Elements of Lambda Calculus Functional Programming Academic Year Alessandro Cimatti
Recap 1.Programmer enters expression 2.ML checks if expression is “well-typed” Using a precise set of rules, ML tries to find a unique type for the expression.
1 541: Relational Calculus. 2 Relational Calculus  Comes in two flavours: Tuple relational calculus (TRC) and Domain relational calculus (DRC).  Calculus.
Principles of programming languages 4: Parameter passing, Scope rules Department of Information Science and Engineering Isao Sasano.
INF 212 ANALYSIS OF PROG. LANGS LAMBDA CALCULUS Instructors: Crista Lopes Copyright © Instructors.
Catriel Beeri Pls/Winter 2004/5 functional-language 1 Substitution Semantics of FL – a simple functional language FL is EL + (non-recursive) function creation.
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Fall 2011.
Foundations of Programming Languages: Introduction to Lambda Calculus
LING 364: Introduction to Formal Semantics Lecture 10 February 14th.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
6. Introduction to the Lambda Calculus. © O. Nierstrasz PS — Introduction to the Lambda Calculus 6.2 Roadmap  What is Computability? — Church’s Thesis.
The lambda calculus David Walker CS 441. the lambda calculus Originally, the lambda calculus was developed as a logic by Alonzo Church in 1932 –Church.
Comp 205: Comparative Programming Languages Semantics of Functional Languages Term- and Graph-Rewriting The λ-calculus Lecture notes, exercises, etc.,
C. Varela1 Lambda Calculus alpha-renaming, beta reduction, applicative and normal evaluation orders, Church-Rosser theorem, combinators Carlos Varela Rennselaer.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Introduction Even though the syntax of Scheme is simple, it can be very difficult to determine the semantics of an expression. Hacker’s approach: Run it.
Rutgers University Relational Calculus 198:541 Rutgers University.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
1 Relational Algebra and Calculus Chapter 4. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.
OCaml The PL for the discerning hacker.. Hello. I’m Zach, one of Sorin’s students.
CMSC 330: Organization of Programming Languages Lambda Calculus Introduction λ.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Section 4.3.
CSE S. Tanimoto Lambda Calculus 1 Lambda Calculus What is the simplest functional language that is still Turing complete? Where do functional languages.
Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Lambda Calculus1 The Untyped Lambda-Calculus Hossein Hojjat University of Tehran Formal Methods Laboratory.
Introduction So far we have seen a function f of a variable x represented by f(x). We have graphed f(x) and learned that its range is dependent on its.
1 ML fun x -> e e 1 e 2 0, 1, 2,..., +, -,... true, false, if e then e else e patterns datatypes exceptions structures functors let f x = e variables These.
1 Relational Algebra and Calculas Chapter 4, Part A.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
A Third Look At ML Chapter NineModern Programming Languages, 2nd ed.1.
CSE 230 The -Calculus. Background Developed in 1930’s by Alonzo Church Studied in logic and computer science Test bed for procedural and functional PLs.
Types and Programming Languages Lecture 6 Simon Gay Department of Computing Science University of Glasgow 2006/07.
1 Formal Semantics. 2 Why formalize? ML is tricky, particularly in corner cases generalizable type variables? polymorphic references? exceptions? Some.
Principles of programming languages 9: Lambda calculus Isao Sasano Department of Information Science and Engineering.
Lambda Calculus Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 11.
CMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Functional Programming with OCaml.
-Calculus Kangwon National University 임현승 Programming Languages These slides are based on the slides by Prof. Sungwoo Park at POSTECH.
CMSC 330: Organization of Programming Languages Operational Semantics a.k.a. “WTF is Project 4, Part 3?”
Lecture on Set! And Local CS 2135 Copyright Kathi Fisler, 2002 This material requires Advanced Language Level.
CMSC 330: Organization of Programming Languages Lambda Calculus and Types.
CMSC 330: Organization of Programming Languages Operational Semantics.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4, Part B.
CSE-321 Programming Languages -Calculus (II) POSTECH March 26, 2007 박성우.
CSE 425: Functional Programming I Programs as Functions Some programs act like mathematical functions –Associate a set of input values from the function’s.
C H A P T E R E I G H T Functional Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
6/21/20161 Programming Languages and Compilers (CS 421) Reza Zamani Based in part on slides by Mattox Beckman,
Relational Calculus Chapter 4, Section 4.3.
CS 550 Programming Languages Jeremy Johnson
Carlos Varela Rennselaer Polytechnic Institute September 6, 2016
Carlos Varela Rennselaer Polytechnic Institute September 4, 2015
Programming Languages and Compilers (CS 421)
Scoping and Binding of Variables
Announcements Quiz 6 HW7 due Tuesday, October 30
Carlos Varela Rennselaer Polytechnic Institute September 8, 2017
L Calculus.
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
CSE S. Tanimoto Lambda Calculus
Relational Calculus Chapter 4, Part B 7/1/2019.
Carlos Varela Rennselaer Polytechnic Institute September 8, 2015
Carlos Varela Rennselaer Polytechnic Institute September 10, 2019
Presentation transcript:

CMSC 330: Organization of Programming Languages Lambda Calculus Introduction

CMSC 3302 Introduction We’ve seen that several language conveniences aren’t strictly necessary –Multi-argument functions: use currying or tuples –Loops: use recursion –Side-effects: we don't need them either Goal: come up with a “core” language that’s as small as possible and still Turing complete –This will give a way of illustrating important language features and algorithms

CMSC 3303 Lambda Calculus A lambda calculus expression is defined as e ::= xvariable | λx.efunction | e efunction application λx.e is like (fun x -> e) in OCaml That’s it! Only higher-order functions

CMSC 3304 Intuitive Understanding Before we work more with the mathematical notation of lambda calculus, we’re going to play a puzzle game! From:

CMSC 3305 Puzzle Pieces Hungry alligators: eat and guard family Old alligators: guard family Eggs: hatch into new family

CMSC 3306 Example Families Families are shown in columns Alligators guard families below them

CMSC 3307 Puzzle Rule 1: The Eating Rule If families are side-by-side the top left alligator eats the entire family to her right The top left alligator dies Any eggs she was guarding of the same color hatch into what she just ate

CMSC 3308 Eating Rule Practice What happens to these alligators? Puzzle 1:

CMSC 3309

10

CMSC 33011

CMSC 33012

CMSC 33013

CMSC 33014

CMSC 33015

CMSC 33016

CMSC 33017

CMSC 33018

CMSC Eating Rule Practice What happens to these alligators? Puzzle 1:Puzzle 2: Answer 1:Answer 2:

CMSC Puzzle Rule 2: The Color Rule If an alligator is about to eat a family and a color appears in both families then we need to change that color in one of the families. –In the picture below, green and red appear in both the first and second families. So, in the second family, we switch all of the greens to cyan, and all of the reds to blue. If a color appears in both families, but only as an egg, no color change is made.

CMSC Puzzle Rule 3: The Old Alligator Rule An old alligator that is guarding only one family dies.

CMSC Challenging Puzzles! Try to reduce these groups of alligators as much as possible using the three puzzle rules: Challenge your neighbors with puzzles of your own.

CMSC Another Puzzle

CMSC YAP (Yet Another Puzzle)‏

CMSC Naming Families When Family Not eats Family True it becomes Family False and when Not eats False it becomes True

CMSC Lambda Calculus A lambda calculus expression is defined as e ::= xvariable (e: egg)‏ | λx.efunction (λx: alligator)‏ | e efunction application (adjacency of families)‏ λx.e is like (fun x -> e) in OCaml That’s it! Only higher-order functions

CMSC Three Conveniences Syntactic sugar for local declarations –let x = e1 in e2 is short for (λx.e2) e1 The scope of λ extends as far to the right as possible –λx.λy.x y is λx.(λy.(x y))‏ Function application is left-associative –x y z is (x y) z –Same rule as OCaml

CMSC Operational Semantics All we’ve got are functions, so all we can do is call them To evaluate (λx.e1) e2 –Evaluate e1 with x bound to e2 This application is called “beta-reduction” –(λx.e1) e2 → e1[x/e2](the eating rule)‏ e1[x/e2] is e1 where occurrences of x are replaced by e2 Slightly different than the environments we saw for Ocaml –Substitutions instead of environments

CMSC Examples (λx.x) z → (λx.y) z → (λx.x y) z → –A function that applies its argument to y (λx.x y) (λz.z) → (λx.λy.x y) z → –A curried function of two arguments that applies its first argument to its second (λx.λy.x y) (λz.z z) x → z y (λz.z) y → y z y λy.z y λy.((λz.z z)y)x → (λz.z z)x → x x

CMSC Static Scoping and Alpha Conversion Lambda calculus uses static scoping Consider the following –(λx.x (λx.x)) z → ? The rightmost “x” refers to the second binding –This is a function that takes its argument and applies it to the identity function This function is “the same” as (λx.x (λy.y))‏ –Renaming bound variables consistently is allowed This is called alpha-renaming or alpha conversion (color rule)‏ –Ex. λx.x = λy.y = λz.z λy.λx.y = λz.λx.z

CMSC Static Scoping (cont’d)‏ How about the following? –(λx.λy.x y) y → ? –When we replace y inside, we don’t want it to be “captured” by the inner binding of y This function is “the same” as (λx.λz.x z)‏