λ-Calculus: a Turing machine."-Alonzo Church
λ-Calculus: a Turing machine."-Alonzo Church
Calculus
-The goal of calculus is to simplify the notion of computable functions.
-A calculus is a notation that can be manipulated mechanically to achieve some end.
-One reason for developing a calculus is that, by reducing some process to a set of simple
mechanical rules, one decreases the chance of making errors.
Scope
-Scope: where a variable is visible to a range of statements or where the variable can be
accessed.
- is called the binding operator.
-Binding: declared in, accessible, etc
-Bound Identifiers: are often called bound variables
Ex:
Ex:
-bound Identifier is j
-free variable is I
-j is bound by the summation operation () which is called the binding site
Scope Ex:
Scope of x
_|_
{x | x > y }
| | |
| | Free occurrence of y
| Bound occurrence of x
Binding site of x
Ex:
Program
|
Var x
|
Procedure
|
|
Var y
|
|
|
|
|
|_
|
End
|
|_
End
|
|________ |
|
|
|
|
Scope of j |
|______________|
|
Scope of I
_
|
|______Scope of y
|
_|
-Calculus
--Calculus is a theory of functions developed by Alonzo Church.
-In 1920 Moses Schonfinkel developed a theory of functions base of combinations
-In 1930 Haskell Curry rediscovered and extended Schonfinkels theory and showed that it was
equivalent to -Calculus.
-In 1930 Alonzo Church developed -Calculus.
-In 1950 S.C. Kleene showed that -Calculus was a universal computing system(any computable
function can be expressed and evaluated using Calculus).
-In 1950 John Mccarthy who was inspired by -Calculus, invented the programming language
LISP.
- -Calculus is equivalent to Turing machines, but -Calculus emphasizes the use of
transformation rules and doesnt care about the actual machine implementing them.
- -Calculus is more related to software than hardware.
-The -Calculus is a notation for defining functions.
-Any computable function can be expressed and evaluated using -Calculus.
-The central concept in -Calculus is the expression.
-Each expression denotes a function.
-0 is a -expression to represent the number zero.
-There are just 3 kinds of -expression and using BNF, the syntax of -expressions are:
Ex:
denotes the identity function
-Functions can be applied to expressions
[5/x] means that all occurrences of x in the expression must be replaced by the number 5.
Note that the function:
int function timesthree(x: int) { timesthree = 3 * x } can be expressed in -claculus as:
|
|
|
x
. * 3 x x.* 3 x
-Function applications are evaluated by substituting the value of the argument:
(( x.x) E ) (x)[E/x] = E
Ex:
(x. (x) E
If we apply
- Arguments are taken from left to right.
- The meaning of [E/x] = all occurrences of x are substituted by E in the expression to the left.
Ex:
Conversion Rules
-An arithmetic expression like (2+3)*5 can be represent as a -expression and its value 25 can
also be represented as a -expression.
-The process of simplifying (2+3)*5 is called conversion or reduction.
1)Renaming Rule(-conversion or -reduction)
-one expression may be replace to another by changing a bound identifier throughout its scope to
any other identifier that doesnt occur within that scope.
One Abstraction of the form v.E can be converted to v.E[v/v] provided that the substitution v
for v is valid in E
Ex:
Ex:
Ex:
Ex:
Non-valid Examples:
Ex1:
(x.y.add xy)(Square y)
(y.add (Square y)y)
(y.add xy)[(Square y)/x] is not valid because y is free in (Square y) but becomes bound after
substitution for x in (x.y.add xy)
Ex2:
x((y. y + 2 ) x) + y
y is bound in y + 2 but free in the last occurrence.
valid Examples:Ex:
Ex:
Ex:
Ex:
Plusp ( x.x 0)
Minusp ( x.x < 0)
Succ ( x.x+1)
Square ( x.x*x)
Minusp(Succ(2))
( x.x < 0)(Succ(2))
(Succ(2) < 0)
(( x.x+1)2 < 0) ((2+1) < 0) 3 < 0 False
Numerals:
Representing integers as -abstractions:
We define a function that calls another function an specific number of times.
0 =Zero = f.x.x
1 = One = f.x.f x
2 = Two = f.x.f (f x)
3 = Three = f.x.f (f (f x))
The abstraction takes two arguments, say s and x. In general x = ZERO
Example:
ZERO s ZERO
f.x.x) s ZERO
x.x[s/f] ZERO
x.x ZERO x[ZERO/x] ZERO = f.x.x
Exercise:
TWO s ZERO
The successor function:
S = Successor = n.f.x.f (n f x)
Successor ZERO = n.f.x.f (n f x) ZERO
f.x.f (n f x) [ZERO/n]
f.x.f (f.x.x f x)
f.x.f (x.x [f/f] x)
f.x.f (x.x x)
f.x.f (x [x/x])
f.x.f (x) =f.x.f x = 1
Exercise:
Successor ONE
The Church numerals that follow just have additional applications of the successor function:
2 = C2 = f.x.f (f x)
3 = C3 = f.x.f (f (f x))
4 = C4 = f.x.f (f (f ( f x)))
n = Cn = f.x.f n x
Addition:
Ci + j = f.x. Ci f (Cj f x)
Example:
C2 + 3 = f.x. C2 f (C3 f x)
f.x. f2.x2.f2 (f2 x) f (C3 f x)
f.x. f2.x2.f2 (f2 x2) [f/f2] (C3 f x)
f.x. x2.f (f x2) (C3 f x)
f.x. f (f x2) [x2/(C3 f x)]
f.x. f (f (C3 f x))
f.x. f (f (f3.x3.f3(f3 (f3 x3)) f x))
f.x. f (f (x3.f3(f3 (f3 x3)) [f/f3] x))
f.x. f (f (x3.f(f (f x3)) x))
f.x. f (f (x3.f(f (f x3)) [x/x3]))
f.x. f (f (f(f (f x)))) = C5 = 5
Now, we can define a function add that takes two Church numerals M and N and returns the
sum of them:
add ::= M.N. f.x. M f (N f x)
add C2 C3 = C5
Multiplication:
Ci * j = f.x. Ci (Cj f ) x
Recursion:
The Y fixed point combinatory.
The Y combinator was proposed by Curry Haskell.
Y combinatory is a fixed point combinatory or fixed point operator.
A fixed point combinatory is a higher order function that computes a fixed point of other unction.
A fixed point of a function f is a value such that f (x) = x.
In -calculus, fixed points may be defined with the fixed point operator Y.
Y = f.(x.f (x x)) (x.f(x x))
The omega combinatory has a useful generalization called the fixed-point combinator (Y). It is
easy to prove that Y is a fixed-point combinator.
Let E be an arbitrary -term and let us apply Y to E:
Y E = f.(x.f (x x)) (x.f(x x)) E
= > (x.f (x x)) (x.f(x x)) [ E/f ]
= > (x.E (x x)) (x.E (x x))
= > (x.E (x x)) (x.E (x x))
= > E (x x) [ (x.E (x x)) /E]
= > E (x x) (x.E (x x))
= > E ( (x.E (x x)) (x.E (x x)) )
=> E(YE)
E = fn.If (= n 1) 1
( * n (f (- n 1)))
(Y E) 1 = E (Y E) 1
= If (= 1 1) 1 ( * 2 (Y E (- 1 1)))
=1
In general all recursive function definitions are represented in -calculus as application of the Y
combinator.
This gives the -calculus the power of turing machine computations.
Y is not the only combinator that finds fixed points of a function. However, this particular fixedpoint operator play an important role in the history of -calculus.