47
Lambda Calculus History and Syntax

Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Embed Size (px)

Citation preview

Page 1: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Lambda Calculus

History and Syntax

Page 2: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

History

The lambda calculus is a formal system designed to investigate function definition, function application and recursion.

It was introduced by Alonzo Church and Stephen Cole Kleene in the 1930s

Lambda calculus has greatly influenced functional programming languages, especially Lisp.

Church used the lambda calculus in 1936 to give a negative answer to the Entscheidungsproblem

Page 3: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

John McCarthy, AI Lab, Stanford

Alonzo Church, Princeton

⋋-Calculus - 1930

LISP - 1950

C - 1970

Dennis Ritchie, Bell Labs

Page 4: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

General Proof Machine

Gottfried Leibniz asked if we can make a machine to validate all mathematical statemanets

He realized that the first step would have to be a clean formal language

Page 5: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Entscheidungsproblem

German: decision problem

In 1900, at a mathematical conference in Paris, David Hilbert presented his famous 23 unsolved problems of Mathematics.

Question that whether it was possible to determine the truth of any mathematical statement

Page 6: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Entscheidungsproblem

In 1931 Kurt Gödel, in his incompleteness Theorem, showed that there exist mathematical statements that are true but cannot be proved as true within the framework of a formal system.

The incompleteness theorem showed that mathematics was incomplete

Page 7: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Entscheidungsproblem

all that remained to be done was to find a way that would decide whether it was possible to decide whether a given function could be solved mechanically or not

Page 8: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Entscheidungsproblem

The negative answer to the Entscheidungsproblem was then given by Alonzo Church in 1936 and independently shortly thereafter by Alan Turing

Turing reduced the Entscheidungsproblem to the halting problem for Turing machines

Page 9: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

λ – Calculus Origins

Originally, Church had tried to construct a complete formal system for the foundations of mathematics

System turned out to be susceptible to the analog of Russell's paradox

He separated out the lambda calculus and used it to study computability

Page 10: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Lambda Calculus, Definition

Provides a mathematical model for computation using recursive functions.

Shows that recursive functions have the same computing power as Turing machines.

Serves as the basis for functional programming languages like Haskell and ML

Page 11: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Some Informal Definitions

Consider definition in mathematic notations : ƒ(x) = x * x + 2

In λ–Calculus we denote This in form of

λx.(x*x + 2)And if we have ƒ(5) return number is 27In λ–Calculus λx.(x*x + 2)(5) we replace

x by 5 : λx.(x*x + 2)(5) = (5*5 + 2) = 27

Page 12: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Some informal definitions

introduce variables ranging over valuesdefine functions by (λ-) abstracting over

variablesapply functions to values

x + 1

x. x + 1

(x. x + 1) 2

Page 13: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

-ExpressionsA lambda expression is any of the following:

1. Variable: x, y, z, … A variable denotes an abstraction to which it is bound, or denotes itself if it is not bound.

2. Function application: if x and y are -expressions, then (x y) is a -expression called function application. It denotes the result of applying the function x to the argument y.

Page 14: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

-Expressions

3. Abstraction or function: If x is a variable and y is a -expression, then ( x . y) is an abstraction or function with dummy variable x and body y. ( x . y) denotes the function which when applied to argument a returns as result the abstraction (( x . y) a) = y [ a | x ]

Page 15: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Examples of -expressions

( x . x) is the identity function. (( x . x) y) y is a function application

returning a variable y. ( f . ( x . ( f x))) is a function returning a

function as value, since its body which is to be returned, ( x . ( f x)), is a function.

( ( f . ( x . ( f x))) w) ( x . (w x)) is a function application returning a function.

Page 16: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Formal Definition

Formal Definition of λ expression is : <expr> ::= <identifier> <expr> ::= (λ <identifier> . <expr>) <expr> ::= (<expr> <expr>)

Where identifier is a member of countable infinite set like {a, b, c, ..., x, y, z, x1, x2, ...}

Page 17: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Notational Conventions

1. Function application is left-associative.

w x means (w x)

w x y means ((w x) y)

w x y z means (((w x) y) z)

2. The scope of the dummy variable extends as far to the right as possible.

w . x y z means ( w . ((x y) z))

Page 18: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Notational Conventions

3. ‘.’ is right associative.

w . x . y . z means

( w . ( x . ( y . z)))

4. distributes up to the ‘.’.

w x y . z means w . x . y . z which in turn means ( w . ( x . ( y . z)))

Page 19: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Example Notational Shortcuts

1. x y . f y x means

( x . ( y . ((f y) x))), a function.

2. ( x . y x)( y . x y) means

( ( x . (y x))( y . (x y)) ),

a function application.

Page 20: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Bound Variables

Def. A variable x occurs bound in a -expression if there is an enclosing abstraction of which x is the dummy variable.

( x . ( f … x … ))

dummy bound

Page 21: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Free Variables

Def. An occurrence of a variable y is free if it is not bound -- that is, in the scope of the dummy variable x, it is not the variable x.

(x . (y …. x))

free bound

Page 22: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

ExampleBound and free variables

x y . u x y = ( x . (y . ((u x) y) ))

u is free

x and y are bound

Page 23: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

-Conversion

Def. The variable x in ( x . … x … ) can be renamed in x and in all of its bound occurrences to a new variable u, giving ( u . … u … ). To denote this renaming, we write:

( x . y) (u . (y [ u | x ] )

where y [ u | x ] means all occurrences of x bound by x are replaced by u. The variable u must be fresh, and must not get bound when substituted in y, except by u.

Page 24: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

-Conversion, Examples

x . w x u . w u

2. x . w x w . w w is not true since the original w becomes bound.

3. x . ( u . u) x u . ( u . u) u is okay

y . ( u . u) y is better.

4. x . ( u . w u x ) u . ( u . w u u ) is not true, since u becomes bound.

y . ( u . w u y ) is better.

Page 25: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

-Conversion, Examples

w . x . w x ) x w . u . w u ) x since the outer x is not in scope of x.

6. w . w x w . w u is not correct since x is not the dummy variable.

Page 26: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Evaluating -expressions: -reduction

-reduction describes how to evaluate an application of a function to its actual argument.

Page 27: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Function Application

Def. Function application is carried out as follows:

(x B [ A | x ]

where B [ A | x ] means all occurrences of x not bound by other inside the body B are replaced by A. Further, the free variables occurring in A can not become bound when substituted in A.

Page 28: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

-Redex

Rem. A -expressionconsisting of a function applied to an argument is called a

-reducible expression or is a -redex.

Page 29: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

-reduction, Examples

1. (x . x) a a

2. (x . y . x) a b (y . a) b a

3. (x . x a) (x . x) (x . x) a a

4. (x . y . x y) y (x . z . x z) y (z . y z)

Page 30: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

-Functions

Def. A -function is a name given to a -expression. Whenever the -expression is needed, we can use the name instead. It is a shortcut or macro for the -expression.

Example: Some -functions are true, false, not, and, or, 0, 1, 2, .., n, iszero, suc, and add.

Page 31: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

-Functions

1. true = x y . x

2. false = x y . y

3. (x?y:z) = x y z

4. not = x . x false true

5. and = x y . x y false

6. or = x y . x true y

Page 32: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

-Functions

7. 0 = f x . x

8. 1 = f x . f x

9. 2 = f x . f (f x)

10. n = f x . f n x

11. iszero = n . n (x . false) true

12. succ = n f x . n f (f x)

13. add = m n f x . m f (n f x)

Page 33: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

-Reduction

Any abstraction of the form x . (E x) in which x has no free occurrences in E can be reduced to E. For example

x . (succ x) succ

An abstraction which is -reducible is called an -redex.

Page 34: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Rationale for -Reduction

If x has no free occurrences in E, then

x . (E x)) A) (E x) [ A | x ]

= (E A)

Thus the effect of x . (E x)) on A is the same as the effect of E on A.

Page 35: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Normal Forms

Def. A -expression is in normal form if it contains no -redexes or -redexes.

A -expression has a normal form if there exists a finite sequence of reduction steps that results in a nromal form.

Page 36: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Examples of Normal Forms

1. x is in normal form

2. (x . x x(y . y is not in normal form but has a normal form, since

(x . x x(y . y (y . y(y . y (y . y

Page 37: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Examples of Normal Forms

3. (x . x x(y . y yis not in normal form and has no normal form, since the reduction sequence does not terminate:

(x . x x(y . y y

(y . y y(y . y y . . .

Page 38: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Reduction Order

A -expression can contain several redexes. For example,

(x . (y . y) (z . z)) (u . u)

1 5

An outer redex starts at character 1. An inner redex starts at character 5. In this case, more than one reduction sequence is possible.

Page 39: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Reduction Sequences

Inner redex: (x . (y . y) (z . z)) (u . u) (x . (z . z)) (u . u)

(z . z)

Outer redex: (x . (y . y) (z . z)) (u . u)

(y . y) (z . z)

(z . z)

The normal form is the same for the two.

Page 40: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Reduction Sequences, Example 2

Inner redex:

(y . z . z) ((x . x x) (x . x x))

(y . z . z) ((x . x x) (x . x x)) . . .

Outer redex:

(y . z . z) ((x . x x) (x . x x))

(z . z)

1st sequence is infinite. 2nd has normal form.

Page 41: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Reduction Strategies

1. Normal order strategy - repeatedly reduce the leftmost-outermost redex.

2. Applicative order strategy - repeatedly reduce the leftmost-innermost redex.

Page 42: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Normalization Theorem

If a -expressionhas a normal form, then the normal order strategy will terminate in a normal form. (Curry & Feys, 1958)

Page 43: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Church-Rosser Corollary

The normal form of a -expression, if it exists, is unique.

Page 44: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Church’s Thesis

The class of effectively computable functions is the same as the class of functions that can be defined in -calculus (1936)

Page 45: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Church’s Theorem

The class of Turing-computable functions is the same as the class of -definable functions.

Page 46: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

New Models

Australian Mathematician, published a paper16 in late 2001 that stated that “incomputable” problems can be computed by exploiting the laws of Quantum Mechanics

A Quantum computer would be able to perform an infinite search in a finite amount of time and hence would solve the halting problem and would show the computability of incomputable functions.

Page 47: Lambda Calculus History and Syntax. History The lambda calculus is a formal system designed to investigate function definition, function application and

Question