Anonymous recursion

Anonymous recursion

In computer science, anonymous recursion is a recursion technique that uses anonymous functions.

Construction

Suppose that "f" is an "n"-argument recursive function defined in terms of itself:: f(x_1, x_2, dots, x_n) := mbox{expression in terms of } x_1, x_2, dots, x_n mbox{ and } f(dots). We want to define an equivalent recursive anonymous function f^* which is not defined in terms of itself. One possible procedure is the following:
# Define a ("n" + 1)-argument function "h" like "f", except that "h" takes one extra argument, which is the function "f" itself. (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.) The functions "f" and "h" are now defined by
#: f(x_1, x_2, dots, x_n, f) := mbox{expression in terms of } x_1, x_2, dots, x_n mbox{ and } f(dots,f).
#: h(x_1, x_2, dots, x_n, f) := mbox{expression in terms of } x_1, x_2, dots, x_n mbox{ and } f(dots,f).
# 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 f^*:
#:f^* (x_1, x_2, dots, x_n) := h(x_1, x_2, dots , x_n, h)

Example

Given: f(x):= egin{cases} 1 & mbox{if} x = 0 \ x cdot f(x - 1) & mbox{otherwise} end{cases} 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:: h(x,f) := egin{cases} 1 & mbox{if} x = 0 \ x cdot f(x - 1) & mbox{otherwise} end{cases}

Second step: change f(x - 1) in the definition to f(x - 1, f) :: h(x,f):=egin{cases} 1 & mbox{if} x = 0 \ x cdot f(x-1, f) & mbox{otherwise} end{cases}so that the function "f" passed on to "h" will have the same number of arguments as "h" itself.

Third step: the factorial function f^* of "x" can now be defined as:: f^*(x) := h(x, h). ,

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):

: ar f := (lambda n. , mbox{if}(n = 0, 1, n cdot ar f (n - 1))).

First step,

: ar h:= (lambda f. lambda n. , mbox{if} (n = 0, 1, n cdot f (n - 1))).

Second step,

: ar g:= (lambda g. lambda n. mbox{if} (n = 0, 1, n cdot g (g) (n-1)))

where g (g) (n - 1) equiv g (g, n - 1) . Note that the variation consists of defining ar g in terms of g (g, n-1) instead of in terms of g(n-1, g).

Third step: let a "Z combinator" be defined by

: Z:= (lambda g. (g g))

such that

: ar f^* := Z ar g.

Here, ar g is passed to itself right before a number is fed to it, so ar f^* n equiv n! for any Church number "n".

Note that g (g) n equiv (g (g)) n equiv (g g) n, i.e. g (g) equiv (g g).

Now an extra fourth step: notice that

: ar g equiv (lambda g. ar h (g g))

(see first and second steps) so that

: ar f^* equiv (lambda. , g (g g)) (lambda g. , ar h (g g))

:: equiv (lambda h. , (lambda g., (g g)) (lambda g., h (g g))) ar h.

Let the "Y" combinator be defined by

: Y:= (lambda h. , (lambda g., h (g g)) (lambda g., h (g g)))

so that

: Z ar g equiv Y ar h.

External links

* [http://www.cs.brown.edu/courses/cs173/2001/Lectures/2001-10-25.pdf The Lambda Calculus: notes by Don Blaheta] (PDF file). "See the section titled "What's left? Recursion", for the genesis of the Y combinator."


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать реферат

Look at other dictionaries:

  • Recursion (computer science) — Recursion in computer science is a way of thinking about and solving problems. It is, in fact, one of the central ideas of computer science. [cite book last = Epp first = Susanna title = Discrete Mathematics with Applications year=1995… …   Wikipedia

  • Anonymous function — In computing, an anonymous function is a function (or a subroutine) defined, and possibly called, without being bound to a name. In lambda calculus, all functions are anonymous. The Y combinator can be utilised in these circumstances to provide… …   Wikipedia

  • Fixed-point combinator — Y combinator redirects here. For the technology venture capital firm, see Y Combinator (company). In computer science, a fixed point combinator (or fixpoint combinator[1] ) is a higher order function that computes a fixed point of other functions …   Wikipedia

  • Lambda calculus — In mathematical logic and computer science, lambda calculus, also written as λ calculus, is a formal system designed to investigate function definition, function application and recursion. It was introduced by Alonzo Church and Stephen Cole… …   Wikipedia

  • Fixed point combinator — A fixed point combinator (or fixed point operator) is a higher order function that computes a fixed point of other functions. This operation is relevant in programming language theory because it allows the implementation of recursion in the form… …   Wikipedia

  • Cálculo lambda — Artículo parcialmente traducido: Contiene texto en inglés. Ayuda a terminarlo. El cálculo lambda es un sistema formal diseñado para investigar la definición de función, la noción de aplicación de funciones y la recursión. Fue introducido por… …   Wikipedia Español

  • Categorical abstract machine — (CAM) is the model of computation of a program [ Cousineau G., Curien P. L., Mauny M. The categorical abstract machine. LNCS, 201, Functional programming languages computer architecture. 1985, pp. 50 64.] , which preserves the abilities of… …   Wikipedia

  • Common Lisp — Paradigm(s) Multi paradigm: procedural, functional, object oriented, meta, reflective, generic Appeared in 1984, 1994 for ANSI Common Lisp Developer ANSI X3J13 committee Typing discipline …   Wikipedia

  • Python syntax and semantics — The syntax of the Python programming language is the set of rules that defines how a Python program will be written and interpreted (by both the runtime system and by human readers). Python was designed to be a highly readable language. It aims… …   Wikipedia

  • C++11 — C++11, also formerly known as C++0x,[1] is the name of the most recent iteration of the C++ programming language, replacing C++TR1, approved by the ISO as of 12 August 2011.[2] The name is derived from the tradition of naming language versions by …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”