Church's Lambda Calculus

Combinators and Lambda Models for Numbers and Arithmetic

The lower part of this Calculator will evaluate (reduce) Lambda expressions or find an combinator expression which is equivalent using only S K and I combinators. Names of models or combinators can be defined in the top part.

Lambda Models Calculator

Lambda Models C A L C U L A T O R
D E F I N I T I O N S

Model for integer n: Head: Body(0)=
Body(n)=





Lambda expression using Definitions
R E S U L T S


 

The Models

Church showed that using Lambda expressions and reduction alone we could find lambda expressions that 'modelled' mathematics including arithmetic. His 'thesis' is that all of mathematics that is computable can be modelled in the Lambda Calculus. The Lambda Calculus has been shown to be equivalent to a universal Turing machine in that what one can model so can the other. This in a sense defines what we mean by 'computable' mathematics.
The models are as follows:
Math definitionLambda model
name = definition
Arity
#args
Notes and examples
Boolean values and operations
True [true]\a.\b.a0 Boolean values
False [false] \a.\b.b0
Conditional expression [if] \c.\t.\e.cte3
if(condition,thenVal,elseVal) = thenVal, if condition is True
= elseVal, if condition is False
not[not] \a.[if]a[false][true]2Boolean negation
and[and] \a.\b.aba2Boolean conjunction
or[or] \a.\b.aab2Boolean disjunction
nand[nand] \a.\b.[not] (aba)2not(A and B)
nor[nor]\a.\b.[not] (aab)2not(A or B)
Tuples: having a fixed length
pair[pair]\a.\b.\f.fab2Make a tuple (a,b)
Firstfst \p.p(\a.\b.a)1Select the first (a) from a pair (a,b)
Secondsnd \p.p(\a.\b.b)1Select the second (b) from a pair (a,b)
Lists of changeable length
Nil[nil] \l.l(\i.i)0The empty list
Cons[cons]\a.\l.\f.fal2Construct a list from an element and a list
Head[head]\l.l\h.\t.h1Select the first item from a list
Tail[tail]\l.l\h.\t.t1Select the rest of a list after the first item
isNull[isnull]\l.l(\x.\y.\a.\b.a)(\i.i)1boolean: is a list empty?
Numerals
0[0]\f.\x.x0"Apply f N times to x"
Uses a JavaScript function to generate the model
1[1]\f.\x.fx0
2[2]\f.\x.f(fx)0
3[3]\f.\x.f(f(fx))0
...[n]\f.\x.f(f...(fx)..)0
Arithmetic
\n.n=0[iszero]\n.n(\y.[false])[true]1boolean: is a number zero?
\n.n+1[succ] \n.\f.\x.f(nfx)1the successor function
\n.n-1[pred]\n.[snd](n(\p.[pair]([succ]([fst]p))([fst]p))([pair][0][0]))1the number before;
the predecessor of 0 is 0
\a.\b.a+b[sum]\m.\n.\f.\x.mf(nfx)2m + n
\a.\b.a×b[prod]\m.\n.\f.m(nf)2m × n
\a.\p.ap[power]\m.\n.nm2 m n
\a.\b.|a−b|[diff]\m.\n.n[pred]m2the positive difference between A and B
diff(a,b) = a−b, if a>b
= b−a, if a<b
Minimum[min]\m.\n.[diff]m([diff]mn)2
min(a,b) = a, if a≤b
= b, if b<a
Maximum[max]\m.\n.[diff]([sum]mn)([min]mn)2
max(a,b) = a, if a≥b
= b, if b>a
[le]\m.\n.[iszero]([diff]mn)2a ≤ b
[ge]\m.\n.[le]nm2a ≥ b
=[eq]\m.\n.[and]([le]mn)([le]nm)2a = b
[ne]\m.\n.[not]([eq]mn))2a ≠ b
<[lt]\m.\n.[not]([ge]mn)2a < b
>[gt]\m.\n.[not]([le]mn)2a > b
Recursive definitions
Triangular Numbers
T(n)=n(n+1)/2
[tri]Y(\f.\n.[if]([iszero]n)[0]([sum]n(f f ([pred]n))))1 T(n) = 1+2+...+n
T(n) = 0, if n=0
= n+T(n−1), if n>0

For example T(3)=6 and [tri][3] reduces to [6]
Mod[mod]Y (\f.\m.\n.[if]([lt]mn)m(f f ([diff]mn)n))2 a (mod b)
is even?[evenq]\n.[iszero]([mod]n[2])1 n (mod 2)==0
is odd?[oddq]\n.[not]([evenq]n)1 n (mod 2) ≠ 0
÷[div]Y (\f.\m.\n.[if]([lt]mn)[0]([succ](f f ([diff]mn) n))) 2floor(a/b) = integer part of a/b
= (a−(a mod b))/b
Factorial: n![fact] Y (\f.\n.[if]([iszero]n)[1]([prod]n(f f ([pred]n)))) 1 n! = 1×2×...×n, if n>0
0! = 1
IsPrime?[primeq] (f f n ([sum][2]d))) [true] \n.[or]([eq]n[2])([and]([not]([iszero]([modrec][modrec]n[2])))([ptestfrom]n[3]))
where
ptestfrom = Y (\f.\n.\d.[if] ([le]([prod]dd)n) ([and] ([not] ([iszero]([modrec][modrec]nd))) (ffn([sum]d[2]))) [true])
1 is n prime?
Uses an auxiliary recursive function ptestfromrec(a,b) to check odd numbers from b are not factors of a
[primeq][21] -> \a.\b.b = [false]
[primeq][19] -> \a.\b.a = [true]
List Processing
s, ... ,e[range]Y (\f.\s.\e.[if]([gt]es)[nil]([cons]s(ff([succ]s)e)) 2 Makes a list of the numbers from s to e
map[map]Y (\m.\f.\l.[if]([isnull]l)l([cons](f([head]l))(m m f ([tail]l)))) 2 make a new list by applying a function to each element of a list
[map] (W[sum]) ([cons][3]([cons][5][nil]))
will map the "doubling" function W[add] = \x.[sum]xx to each of the elements of list cons(3,cons(5,nil))
to give cons(6,cons(10,nil))
select[select]Y (\f.\p.\l.[if]([isnull]l)[nil](p([head]l)([cons]([head]l)(ffp([tail]l))))) 2 Select all the elements of a list L that have property P (where P applied to any element gives True for those elements to be selected)
[select][evenq]([range][3][6])
-> [cons]4([cons][6][nil])
take while[takewhile]Y ( \w.\p.\l.[if]([isnull]l)[nil]([cons]([head]l)(wwp([tail]l))) 2 Construct a new list by taking the elements of a list in turn so long as they meet a given condition
[takewhile] [evenq] ([cons][2]([cons][0]([cons][7](cons[4][nil]))))
-> [cons][2](cons[0][nil])
foldLeft[foldl]Y (\r.\f.\a.\l.[if]([isnull]l)a(rrf(fa([head]l))([tail]l))) 3 accumulate by combining the elements of a list from the left with a given function f and starting value a
for example: [foldl] f z ([cons]a([cons]b([cons]c[nil]))) → f(f(fza)b)c
foldRight[foldr]Y ( \f.\o.\a.\l.[if]([isnull]l)a(o([head]l)(ffoa([tail]l)) ) 3 reduce a list by combining the elements from the right with a given function f and a given (nil) value z
for example: [foldr] f z ([cons]a([cons]b([cons]c[nil]))) → fa(fb(fcz))

Rules

... coming soon ...
Valid HTML 4.01! © 1996-2016 Dr Ron Knott
Back to Dr Knott's Fibonacci Home page