Anonymous recursion
You must add a |reason=
parameter to this Cleanup template – replace it with {{Cleanup|November 2005|reason=<Fill reason here>}}
, or remove the Cleanup template.
Anonymous recursion is used in the construction and existence of anonymously recursive functions. Given an n-argument recursive function f defined in terms of itself, it is possible to define an equivalent recursive anonymous function which is not defined in terms of itself. One possible procedure is the following:
- Define an (n + 1)-argument function h in terms of f the same way that f was defined in terms of itself, and let h's last argument be f. (Function h inherits its first n arguments from f.)
- Change f, the last argument of h, from an n-argument function to an (n + 1)-argument function by feeding f to itself as f′s last argument for all instances of f within the definition of h. (This puts function h and its last argument f on an equal footing.)
- Pass on h to itself as h′s own last argument, and let this be the definition of the desired n-argument recursive anonymous function :
where
- in terms of
in the same way as
- in terms of
Example
Given
The function f is defined in terms of itself: such circular definitions are not allowed in anonymous recursion (because functions are not bound to labels). To start with a solution, define a function h(x,f) in exactly the same way that f(x) was defined above:
Second step: change in the definition to :
so that the function f passed on to h will have the same number of arguments as h itself.
Third step: the factorial function of x can now be defined as:
Relation to the use of the Y combinator
The above approach to constructing anonymous recursion differs, but is related to, the use of fixed point combinators. To see how they are related, perform a variation of the above steps. Starting from the recursive definition (using the language of lambda calculus):
First step,
Second step,
where . Note that the variation consists of defining in terms of instead of in terms of .
Third step: let a "Z combinator" be defined by
such that
Here, is passed to itself right before a number is fed to it, so for any Church number n.
Note that , i.e. .
Now an extra fourth step: notice that
(see first and second steps) so that
Let the Y combinator be defined by
so that
See also
External links
- The Lambda Calculus: notes by Don Blaheta (PDF file). See the section titled "What's left? Recursion", for the genesis of the Y combinator.