A Quick Overview. CAS 701 Class Presentation 18 November Department of Computing & Software McMaster University. Church s Lambda Calculus

Similar documents
VU Semantik von Programmiersprachen

Lambda Calculus. CS 550 Programming Languages Jeremy Johnson

One of a number of approaches to a mathematical challenge at the time (1930): Constructibility

Last class. CS Principles of Programming Languages. Introduction. Outline

Pure Lambda Calculus. Lecture 17

Programming Language Features. CMSC 330: Organization of Programming Languages. Turing Completeness. Turing Machine.

CMSC 330: Organization of Programming Languages

Recursive Definitions, Fixed Points and the Combinator

CMSC 330: Organization of Programming Languages

Lambda Calculus. Lecture 4 CS /26/10

n λxy.x n y, [inc] [add] [mul] [exp] λn.λxy.x(nxy) λmn.m[inc]0 λmn.m([add]n)0 λmn.n([mul]m)1

Introduction to Lambda Calculus. Lecture 7 CS /08/09

dynamically typed dynamically scoped

Lambda Calculus. Lambda Calculus

CMSC 330: Organization of Programming Languages. Lambda Calculus

λ calculus Function application Untyped λ-calculus - Basic Idea Terms, Variables, Syntax β reduction Advanced Formal Methods

CMSC330. Objects, Functional Programming, and lambda calculus

Introduction to the λ-calculus

Lecture 5: The Untyped λ-calculus

Functions as data. Massimo Merro. 9 November Massimo Merro The Lambda language 1 / 21

11/6/17. Outline. FP Foundations, Scheme. Imperative Languages. Functional Programming. Mathematical Foundations. Mathematical Foundations

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages. Lambda Calculus

INF 212 ANALYSIS OF PROG. LANGS LAMBDA CALCULUS. Instructors: Crista Lopes Copyright Instructors.

Part I. Historical Origins

Untyped Lambda Calculus

Chapter 5: The Untyped Lambda Calculus

Introduction to Lambda Calculus. Lecture 5 CS 565 1/24/08

A short introduction to the Lambda Calculus

COMP 1130 Lambda Calculus. based on slides by Jeff Foster, U Maryland

Untyped Lambda Calculus

CMSC 330: Organization of Programming Languages. Lambda Calculus Encodings

Lambda Calculus and Extensions as Foundation of Functional Programming

The Untyped Lambda Calculus

5. Introduction to the Lambda Calculus. Oscar Nierstrasz

CMSC 330: Organization of Programming Languages

λ-calculus Lecture 1 Venanzio Capretta MGS Nottingham

Type Systems Winter Semester 2006

Lambda Calculus. Adrian Groza. Department of Computer Science Technical University of Cluj-Napoca

Lecture 9: More Lambda Calculus / Types

- M ::= v (M M) λv. M - Impure versions add constants, but not necessary! - Turing-complete. - true = λ u. λ v. u. - false = λ u. λ v.

Formal Semantics. Aspects to formalize. Lambda calculus. Approach

CS 6110 S14 Lecture 1 Introduction 24 January 2014

A Tutorial Introduction to the Lambda Calculus

3.1 λ-calculus: Syntax

CMSC 330: Organization of Programming Languages

Fundamentals and lambda calculus. Deian Stefan (adopted from my & Edward Yang s CSE242 slides)

Pure (Untyped) λ-calculus. Andrey Kruglyak, 2010

Fundamentals and lambda calculus

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

lambda calculus History 11/28/13 Jianguo Lu A formal system designed to inves:gate func:on defini:on, func:on applica:on, and recursion.

Programming Language Concepts: Lecture 19

Lexicografie computationala Feb., 2012

Activity. CSCI 334: Principles of Programming Languages. Lecture 4: Fundamentals II. What is computable? What is computable?

Constraint-based Analysis. Harry Xu CS 253/INF 212 Spring 2013

Introduction to the Lambda Calculus. Chris Lomont

Lambda Calculus.

Recursion. Lecture 6: More Lambda Calculus Programming. Fixed Points. Recursion

CS 314 Principles of Programming Languages. Lecture 21

Concepts of programming languages

Introduction to the Lambda Calculus

1 Scope, Bound and Free Occurrences, Closed Terms

The Untyped Lambda Calculus

Lambda Calculus. Type Systems, Lectures 3. Jevgeni Kabanov Tartu,

CITS3211 FUNCTIONAL PROGRAMMING

The Untyped Lambda Calculus

Simple Lisp. Alonzo Church. John McCarthy. Turing. David Hilbert, Jules Richard, G. G. Berry, Georg Cantor, Bertrand Russell, Kurt Gödel, Alan

Introductory Example

Lambda Calculus alpha-renaming, beta reduction, applicative and normal evaluation orders, Church-Rosser theorem, combinators

Chapter 5: The Untyped Lambda Calculus

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

Functional Programming and λ Calculus. Amey Karkare Dept of CSE, IIT Kanpur

M. Snyder, George Mason University LAMBDA CALCULUS. (untyped)

Introduction to the l-calculus

9/23/2014. Why study? Lambda calculus. Church Rosser theorem Completeness of Lambda Calculus: Turing Complete

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

Lecture Notes on Data Representation

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 4 MODULE, SPRING SEMESTER MATHEMATICAL FOUNDATIONS OF PROGRAMMING ANSWERS

Graphical Untyped Lambda Calculus Interactive Interpreter

CIS 500 Software Foundations Fall September 25

> module Lambda where > import Data.List -- I need some standard list functions

Computer Science 203 Programming Languages Fall Lecture 10. Bindings, Procedures, Functions, Functional Programming, and the Lambda Calculus

CS522 - Programming Language Semantics

Homework. Lecture 7: Parsers & Lambda Calculus. Rewrite Grammar. Problems

COMP 4161 NICTA Advanced Course. Advanced Topics in Software Verification. Toby Murray, June Andronick, Gerwin Klein

An Introduction to the Lambda Calculus

Lambda Calculus. Concepts in Programming Languages Recitation 6:

Lambda Calculus and Type Inference

The Untyped Lambda Calculus

Elixir, functional programming and the Lambda calculus.

More Lambda Calculus and Intro to Type Systems

Lambda Calculus. Variables and Functions. cs3723 1

Lambda calculus. Wouter Swierstra and Alejandro Serrano. Advanced functional programming - Lecture 6

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

CSCI.4430/6969 Programming Languages Lecture Notes

λ calculus is inconsistent

MATH Iris Loeb.

10.6 Theoretical Foundations

The Lambda Calculus. 27 September. Fall Software Foundations CIS 500. The lambda-calculus. Announcements

Programming Languages. Programming with λ-calculus. Lecture 11: Type Systems. Special Hour to discuss HW? if-then-else int

Transcription:

A Quick Overview CAS 701 Class Presentation 18 November 2008 Lambda Department of Computing & Software McMaster University 1.1

Outline 1 2 3 Lambda 4 5 6 7 Type Problem Lambda 1.2

Lambda calculus is a formal system designed to investigate function definition, application and recursion. Proposed by Alonzo Church and Stephen Cole Kleene in the 1930s. Intended to investigate the foundations of mathematics, but has emerged as a useful tool in the investigation of problems in computability or recursion theory, and forms the basis of functional programming. Lambda calculus raised implementation issue for stack-based programming languages as it treats functions as first-class objects. Programming languages such as Lisp, Pascal, C++, Smalltalk and Effel have notions to support Lambda calculus. Lambda 1.3

A name or variable can be any letter a, b, c,... The grammar is defined based on expression, where expression is: < expression >:=< name > < function > < application > < function >:= λ < name >. < expression > < application >:=< expression >< expression >. Abbreviation Ex. the function f (x, y) = x y would be written as λx.λy.x y. A common convention is to abbreviate curried functions as λxy.x y. Lambda 1.4

Functions can be applied to expressions. Ex. (λx.x)y. Function applications are evaluated by reduction rules. Function application associates from the left, i.e. the expression E 1 E 2 E 3...E n is evaluated as: (...((E 1 E 2 )E 3 )...E n ). Lambda 1.5

Variables A variable <name> is free in an expression if one of the following three cases holds: <name> is free in <name> <name> is free in λ <name 1 >.<exp> if the identifier <name> <name 1 > and <name> is free in <exp> <name> is free in E 1 E 2 if <name> is free in E 1 or if it is free in E 2. A variable is bound if one of two cases holds: <name> is bound in λ<name 1 >.<exp> if the identifier <name>=<name 1 > or if <name> is bound in <exp> <name> is bound in E 1 E 2 if <name> is bound in E 1 or if it is bound in E 2. Lambda 1.6

(1/2) : the process of evaluating a lambda expression. α-conversion: allows bound variable names to be changed. Ex. α-conversion of λx.x would be λy.y. η-conversion: two functions are the same if and only if they give the same result for all arguments. η-conversion converts between λx.fx and f whenever x does not appear free in f. Lambda 1.7

(2/2) Substitution: perform variable substitution for free variables. The precise definition must be careful in order to avoid accidental variable capture and is recursively defined as follows: x[x N] N y[x N] y, if x y (M1M2)[x N] (M1[x N])(M2[x N]) (λy.m)[x N] λy.(m[x N]), if x y and!y fv(n) β-reduction: expresses the idea of function application. The beta reduction of ((λv.e)e ) is simply E[V E ]. Lambda 1.8

Normal Form Applying reduction rules does not always stop. The following is an example, which always reduces to itself: (λx.xx)(λx.xx). If a sequence of reductions has come to an end where no further reductions are possible, we say that the term has been reduced to normal form. As illustrated, not every term has a normal form. Lambda 1.9

Church numerals define numbers as follows: 0 := λ f x. x 1 := λ f x. f x 2 := λ f x. f (f x) 3 := λ f x. f (f (f x)) We define the successor function as: SUCC := λ n f x. f (n f x) Lambda 1.10

Addition: λ m n f x. n f (m f x) λ n m. m SUCC n Multiplication: λ m n f. m (n f) λ m n. m (PLUS n) 0 Predecessor function is defined as PERD = λ n f x. n (λ g h. h (g f)) (λ u. x) (λ u. u). Substraction function is defined as λ m n. n PRED m. Lambda 1.11

TRUE := λ x y. x FALSE := λ x y. y Logical Operators: AND := λ p q. p q p OR := λ p q. p p q NOT := λ p. λ a b. p b a IF THEN ELSE := λ p a b. p a b As an example: Lambda AND TRUE FALSE (λ p q. p q p) TRUE FALSE β TRUE FALSE TRUE (λ x y. x) FALSE TRUE β FALSE 1.12

Let us now construct a term for iteration to perform I n f x = f (f (f... (f x)... )) I = λ n f x.zero? n x (I (PRED n) f (f x)) If n = 0 then zero? n x M will evaluate to x. If n > 0 then we iterate f (n - 1)-times on the argument (f x). This definition of I uses I itself in the body. It does nothing else but add one further iteration to an assumed (n - 1)-fold iteration. Lambda 1.13

We change the term on the right into a function which turns n - 1-iterator into n-iterator : Let S be λ M.(λn f x.zero? n x (M (PRED n) f (f x))) What we now seek is a term which is a fixpoint for S,i.e. I = S I There are terms Y which construct a fixpoint for any term M, that is, they satisfy Y M = M (Y M) Lambda 1.14

In order to come up with a semantic, a set D should be found that is isomorphic to the function space D D, of functions on itself. The first set-theoratical model for untyped lambda calculus was made by Dana Scott in 1970s He introduced continuos lattices, that are Algebraically: those complete lattices D where for every y D, y = W { V U y U and U is Scott-open and U D} Topologically: those T 0 -spaces such that every continuos f : X D from a subspace X Y can be extended to a continuos f : Y D. This work formed the basis for the denotational semantics of programming languages, fixed point combinators, and the domain theory. Lambda 1.15

& Decidability A function F : N N of natural numbers is a computable function iff there exists a lambda expression f such that for every pair of x, y in N, F (x) = y iff f x β y, where x and y are the Church numerals corresponding to x and y, respectively and β meaning equivalence with β-reduction. Equivalent to Turing machines. A calculus is Turing-complete if it allows one to define all computable functions from N to N. Undecidability of equivalence. Lambda 1.16

: the result of a computation is independent from the order of reduction. Theorem (Church-Rosser) If a term M can be reduced (in several steps) to terms N and P, then there exists a term Q to which both N and P can be reduced (in several steps). β-reduction is confluent. Every λ-term has at most one normal form. Lambda 1.17

Type Problem It is possible to write sin log, where the sine function is applied not to a number but to the logarithm function. Such terms do not make any sense at all, and any sensible programming language compiler would reject them as ill-formed. What is missing in the calculus is a notion of type. The type of a term should tell us what kind of arguments the term would accept and what kind of result it will produce. For example, the type of the sine function should be accepts real numbers and produces real number. Lambda 1.18

References A Tutorial to the Lambda, Raul Rojas. A short introduction to the Lambda, Achim Jung. Lecture Notes on the Lambda, Peter Selinger. History of lambda-calculus and combinatory logic, Felice Cardone and J. Roger Hindley. http://www.csse.monash.edu.au/ lloyd/tildefp/lambda. http://www.wikipedia.org. Lambda 1.19