570 likes | 819 Views
Lambda Calculus. History and Syntax. 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
E N D
Lambda Calculus History and Syntax
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
⋋-Calculus - 1930 LISP - 1950 Alonzo Church, Princeton John McCarthy, AI Lab, Stanford C - 1970 Dennis Ritchie, Bell Labs
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
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
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
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
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
λ – 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
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
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 27 • In λ–Calculus λx.(x*x + 2)(5) we replace x by 5 : λx.(x*x + 2)(5) = (5*5 + 2) = 27
Some informal definitions • introduce variables ranging over values • define functions by (λ-) abstracting over variables • apply functions to values x + 1 x. x + 1 (x. x + 1) 2
-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.
-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 ]
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.
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, ...}
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))
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)))
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.
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
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
ExampleBound and free variables • x y . u x y = ( x . ( y . ((u x) y) )) u is free x and y are bound
-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.
-Conversion, Examples 1. 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.
-Conversion, Examples 5.( 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.
Evaluating -expressions: -reduction -reduction describes how to evaluate an application of a function to its actual argument.
Function Application Def. Function application is carried out as follows: ( x . B ) 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.
-Redex Rem. A -expressionconsisting of a function applied to an argument is called a -reducible expression or is a -redex.
-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)
-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.
-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
-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 (nf x)
-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.
Rationale for -Reduction If x has no free occurrences in E, then (( x . (E x)) A) b(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.
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.
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)
Examples of Normal Forms 3. ( x . x x) ( y . y y) is 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) . . .
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.
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.
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.
Reduction Strategies 1. Normal order strategy - repeatedly reduce the leftmost-outermost redex. 2. Applicative order strategy - repeatedly reduce the leftmost-innermost redex.
Normalization Theorem If a -expression E has a normal form, then the normal order strategy will terminate in a normal form. (Curry & Feys, 1958)
Church-Rosser Corollary The normal form of a -expression, if it exists, is unique.
Church’s Thesis The class of effectively computable functions is the same as the class of functions that can be defined in -calculus (1936)
Church’s Theorem The class of Turing-computable functions is the same as the class of -definable functions.
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.