Unit – 3 :LAMBDA CALCULUS AND FUNCTIONAL PROGRAMMING

Slides:



Advertisements
Similar presentations
Computational Models The exam. Models of computation. –The Turing machine. –The Von Neumann machine. –The calculus. –The predicate calculus. Turing.
Advertisements

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
Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
Class 39: Universality cs1120 Fall 2009 David Evans University of Virginia.
Catriel Beeri Pls/Winter 2004/5 functional-language 1 Substitution Semantics of FL – a simple functional language FL is EL + (non-recursive) function creation.
Foundations of Programming Languages: Introduction to Lambda Calculus
6. Introduction to the Lambda Calculus. © O. Nierstrasz PS — Introduction to the Lambda Calculus 6.2 Roadmap  What is Computability? — Church’s Thesis.
School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 3 LECTURE: LAMBDA CALCULUS PRACTICAL/TUTORIAL: (i) Do exercises given out.
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.
C. Varela1 Lambda Calculus alpha-renaming, beta reduction, applicative and normal evaluation orders, Church-Rosser theorem, combinators Carlos Varela Rennselaer.
David Evans CS200: Computer Science University of Virginia Computer Science Class 31: Universal Turing Machines.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
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.
Lexicografie computationala Feb., 2012 Anca Dinu University of Bucharest.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
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.
Principles of programming languages 9: Lambda calculus Isao Sasano Department of Information Science and Engineering.
Lambda Calculus CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University
CS321 Functional Programming 2 © JAS The λ Calculus This is a formal system to capture the ideas of function abstraction and application introduced.
6/21/20161 Programming Languages and Compilers (CS 421) Reza Zamani Based in part on slides by Mattox Beckman,
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L03-1 September 14, 2006http:// -calculus: A Basis for.
A LISP interepreter for the Lambda Calculus Functional Programming
Functional Programming
Chapter 2: Lambda Calculus
CS5205: Foundations in Programming Languages
Functional Programming
CS 3723 Programming Languages
Introduction to the λ-Calculus and Functional Programming Languages
CS 550 Programming Languages Jeremy Johnson
CS 3304 Comparative Languages
Lecture 6: Lambda Calculus
Lambda Calculus CSE 340 – Principles of Programming Languages
Carlos Varela Rennselaer Polytechnic Institute September 5, 2017
Copyright © Cengage Learning. All rights reserved.
More on Lambda Calculus
CS 611: Lecture 9 More Lambda Calculus: Recursion, Scope, and Substitution September 17, 1999 Cornell University Computer Science Department Andrew Myers.
September 4, 1997 Programming Languages (CS 550) Lecture 6 Summary Operational Semantics of Scheme using Substitution Jeremy R. Johnson TexPoint fonts.
Corky Cartwright January 18, 2017
CS 320 Principles of Programming Languages
Lesson 4 Typed Arithmetic Typed Lambda Calculus
Introduction To Logarithms
Lesson2 Lambda Calculus Basics
Carlos Varela Rennselaer Polytechnic Institute September 4, 2015
Programming Languages and Compilers (CS 421)
FP Foundations, Scheme In Text: Chapter 14.
Unification Algorithm ChuChen
CSE341: Programming Languages Lecture 12 Equivalence
CSE341: Programming Languages Lecture 12 Equivalence
CSE341: Programming Languages Lecture 12 Equivalence
Announcements Quiz 6 HW7 due Tuesday, October 30
CS 611: Lecture 10 More Lambda Calculus September 20, 1999
Material in the textbook Sections to 1.2.1
Introduction to Functional Programming in Racket
Announcements Exam 2 on Friday, November 2nd Topics
L Calculus.
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Class 31: Universal Turing Machines CS200: Computer Science
CSE341: Programming Languages Lecture 12 Equivalence
CSE S. Tanimoto Lambda Calculus
CS 611: Lecture 10 More Lambda Calculus September 20, 1999
Programming Languages
CSE341: Programming Languages Lecture 12 Equivalence
COMPILER CONSTRUCTION
CSE341: Programming Languages Lecture 12 Equivalence
Carlos Varela Rennselaer Polytechnic Institute September 6, 2019
Presentation transcript:

Unit – 3 :LAMBDA CALCULUS AND FUNCTIONAL PROGRAMMING Syllabus: Lambda notation for functions – syntax – curried functions – parametric polymorphism – lambda reduction – alpha reduction – beta reduction – beta abstraction – extensionality theorem – delta reduction – reduction strategies – normal forms Church-Rosser Theorems – pure lambda calculus – constants – arithmetic – conditionals Iteration – recursion – introduction to functional programming

 x . x — is a function taking an argument x, and returning x The Lambda Calculus was invented by Alonzo Church [1932] as a mathematical formalism for expressing computation by functions. Syntax: e ::= x a variable |  x . e an abstraction (function) | e1 e2 a (function) application Examples:  x . x — is a function taking an argument x, and returning x f x — is a function f applied to an argument x

Lambda notation for functions A lambda abstraction is just an anonymous function. Consider the Haskell function: The value of compose is the anonymous lambda abstraction:  f g x . f (g x) NB: This is the same as:  f .  g .  x . f (g x)

The lambda calculus can be viewed as the simplest possible pure functional programming language.

Lambda extends as far as possible to the right  f.x y   f.(x y) Application is left-associative x y z  (x y) z Multiple lambdas may be suppressed  f g.x   f .  g.x

Syntax Only three kinds of expressions E ::= x variables | E1 E2 function application | lx. E function creation The form lx. E is also called lambda abstraction, or simply abstraction E are called l-terms or l-expressions

(x.x) y (x.f x) x y (x.x) (x.x) (x.x y) z (x y.x) t f (x y z.z x y) a b (x y.x) (f g.f g) (x.x) (x.x) z (x y.x y) y (x y.x y) (x.x) (x.x) (x y.x y) ((x.x) (x.x))

Curried Functions Since a lambda abstraction only binds a single variable, functions with multiple parameters must be modelled as Curried higher-order functions. As we have seen, to improve readability, multiple lambdas are suppressed, so:  x y . x =  x .  y . x  b x y . b x y =  b .  x .  y . ( b x ) y

Parametric Polymorphism

Lambda Reduction λ-reduction The key notion of the λ-calculus is that it is possible to arrive at a logically equivalent expression by means of a process called λ-reduction. In the usual case, λ-reduction is actually a combination of three distinct reduction operations, each of which is discussed below. The key operation, the one that does the heavy lifting, is called β-reduction, and that is operation we will discuss first. By the way, some people say "λ-conversion" instead of λ-reduction; others reserve "λ-conversion" to refer specifically to a single step in a series of reductions. This tutorial is trying not to be overly pedantic, so for present purposes I don't care.

(λ x (λ y (x (+ y x)))) (λ z (λ y (z (+ y z)))) alpha reduction The solution is to make use of alphabetic variants. Roughly, two expressions are "alphabetic variants" if they are identical except perhaps for the choice of variable symbols. For instance, the following expressions are alphabetic variants of one another: (λ x (λ y (x (+ y x))))  (λ z (λ y (z (+ y z)))) To create an alphabetic variant for an expression of the form "(λ var body)", simply replace each free occurrence of "var" in the expression with "new", where "new" is a variable symbol not occurring anywhere in "body". (Since expressions have finite length, as long as there is an infinite supply of variable symbols, it will always be possible to find a suitable variable to serve the role of "new".) This transformation is called α-reduction. The crucial property of the reduced form is that each λ operator binds the same number of variables in the same positions within its body

beta reduction

beta abstraction The conversion of an expression to an application of a lambda abstraction to anargument expression.  Some subterm of the original expression becomes the argument of the abstractionand the rest becomes its body.  E.g.  4+1 --> (\ x . x+1) 4  The opposite of beta abstraction is beta reduction. These are the two kinds of beta conversion.

Extensionality theorem In logic, extensionality, or extensional equality refers to principles that judge objects to be equal if they have the same external properties. It stands in contrast to the concept of intensionality, which is concerned with whether the internal definitions of objects are the same. Consider the two functions f and g mapping from and to natural numbers, defined as follows: To find f(n), first add 5 to n, then multiply by 2. To find g(n), first multiply n by 2, then add 10. These functions are extensionally equal; given the same input, both functions always produce the same value. But the definitions of the functions are not equal, and in that intensional sense the functions are not the same.

Delta Reduction A delta redex is matched against the left hand side of alldelta rules and is replaced by the right hand side of the (first) matching rule. There is notionally one deltarule for each possible combination of function and arguments. Where this implies an infinite number of rules,the result is usually defined by reference to some external system such as mathematical addition or thehardware operations of some computer.

Reduction Strategies

Normal Forms A lambda expression is in normal form if it can no longer be reduced by beta or eta reduction rules. Not all lambda expressions have normal forms!  = ( x . x x) ( x . x x)  [ ( x . x x) / x ] ( x x ) = ( x . x x) ( x . x x)  reduction  ( x . x x) ( x . x x)  reduction  ... Reduction of a lambda expression to a normal form is analogous to a Turing machine halting or a program terminating.

Church-Rosser Theorems

Pure Lambda Calculus Lambda-calculus with no constants, only functions expressed as lambda abstractions.

constants

arithmetic

Iteration conditionals Every procedural programming language has conditional statements (if-statements) and iterative statements (loops). The block. if-statement. if-else statement. while-loop. for-loop.

Recursion

Introduction to functional programming