Recursively defined functions
Functions whose domains can be recursively defined can be given recursive definitions patterned after the recursive definition of their domain.
The canonical example of a recursively defined function is
the following definition of the factorial function f(n):
- f(0) = 1
- f(n) = n · f(n-1) for any natural number n > 0
Given this definition, also called a recurrence relation, we work out f(3) as follows:
f(3) = 3 · f(3-1)
= 3 · f(2)
= 3 · 2 · f(2-1)
= 3 · 2 · f(1)
= 3 · 2 · 1 · f(1-1)
= 3 · 2 · 1 · f(0)
= 3 · 2 · 1 · 1
= 6
Another example is the definition of