Collected Lambdas
Collected Lambdas
Common Combinators
K := xy. x X (X (X X)) X X X
S := xyz. (x z) (y z) X (X (X (X X))) X K X (X X) B (B (B W) C) (B B)
I := x. x S K S S K K X X
X := x. x S K also called (iota)
X := x. x K S K
B := xyz. x (y z) S (K S) K function composition
C := xyz. x z y S (S (K (S (K S) K)) S) (K K)
W := xy. x y y S S (K (S K K))
Y := g. (x. g (x x)) (x. g (x x)) S (K (S I I)) (S (S (K S) K) (K (S I I)))
Y := (xy. x y x) (yx. y (x y x)) S S K (S (K (S S (S (S S K)))) K)
:= (xy. y (x x y)) (xy. y (x x y)) called the "Turing fixed-point combinator"
:= x. x x S I I
:=
2 := (x. x x x) (x. x x x)
A fixed point combinator is any function F for which F g g (F g) for all g; examples include Y,
Y, and . Since lambda calculus functions cannot refer to themselves by name, fixed point
combinators are needed to implement recursion. For example, the factorial function can be
implemented using f := gx. ISZERO x 1 (MULT x (g (PRED x))), which takes a function g and a
number x; if x is not zero, it is multiplied by the result of g (PRED x). Defining FACTORIAL :=
Y f (or Y f or f) means that FACTORIAL x Y f x f (Y f) x, and so f is able to recurse on
itself indefinitely.
Natural Numbers
0 := fx. x
1 := fx. f x
2 := fx. f (f x)
3 := fx. f (f (f x))
4 := fx. f (f (f (f x)))
5 := fx. f (f (f (f (f x))))
et cetera
Mathematical Operators
http://jwodder.freeshell.org/lambda.html 1/4
4/6/2017 Collected Lambdas
Booleans
Given a boolean value b, the expression b t f will evaluate to t if b is true and to f if b is false.
This allows conditional expressions to be written simply as a condition applied directly to the two
possible results without the need for an IF function.
TRUE := xy. x K
FALSE := xy. y 0 x. I K I S K X (X X)
AND := pq. p q p
OR := pq. p p q
XOR := pq. p (NOT q) q
NOT := pab. p b a p. p FALSE TRUE
http://jwodder.freeshell.org/lambda.html 2/4
4/6/2017 Collected Lambdas
Pairs and lists are structured the same way that they are in Lisp and its relatives: a pair is
made up of two components, called the car and the cdr, and a list is either NIL (the empty list) or a
pair whose cdr is another list (and whose car is an element of the enclosing list).
PAIR x y create a pair with a car of x and a cdr of y; also called CONS:
PAIR := xyf. f x y
CAR p get the car of pair p; also called FIRST or HEAD:
CAR := p. p TRUE
CDR p get the cdr of pair p; also called SECOND, TAIL, or REST:
CDR := p. p FALSE
The empty list:
NIL := x. TRUE
NULL p evaluates to TRUE if p is NIL or to FALSE if p is a normal pair (all other types are
undefined):
NULL := p. p (xy. FALSE)
List Functions
FILTER := Y (gfx. NULL x NIL (f (CAR x) (PAIR (CAR x)) I (g f (CDR x))))
CROSS f l m evaluates to a list of all values of f a b where a is in the list l and b is in the list
m. To obtain the Cartesian cross product of l and m, supply PAIR (or a similar function) for f.
CROSS := flm. FOLD-LEFT APPEND NIL (MAP (x. MAP (f x) m) l)
FOLD-LEFT f e x Apply f a to each element of the list x, where a is the result of the previous
application (or e for the first application) and return the result of the last application:
FOLD-LEFT := Y (gfex. NULL x e (g f (f e (CAR x)) (CDR x)))
FOLD-RIGHT f e x Apply (y. f y a) to each element of the list x in reverse order, where a is
the result of the previous application (or e for the first application) and return the result of the
last application:
FOLD-RIGHT := fex. Y (gy. NULL y e (f (CAR y) (g (CDR y)))) x
Other
Sources
Main Page
$Id: lambda.html,v 1.3 2014/06/23 01:42:31 jwodder Exp jwodder $
http://jwodder.freeshell.org/lambda.html 4/4