Recursive definition
In mathematics and computer science, a recursive definition, or inductive definition, is used to define the elements in a set in terms of other elements in the set. Some examples of recursively definable objects include factorials, natural numbers, Fibonacci numbers, and the Cantor ternary set.
A recursive definition of a function defines values of the function for some inputs in terms of the values of the same function for other inputs. For example, the factorial function is defined by the rules
This definition is valid for each natural number, because the recursion eventually reaches the base case of 0. The definition may also be thought of as giving a procedure for computing the value of the function , starting from and proceeding onwards with etc.
The recursion theorem states that such a definition indeed defines a function that is unique. The proof uses mathematical induction.
An inductive definition of a set describes the elements in a set in terms of other elements in the set. For example, one definition of the set of natural numbers is:
- 0 is in
- If an element n is in then is in
- is the smallest set satisfying and.
Properties of recursively defined functions and sets can often be proved by an induction principle that follows the recursive definition. For example, the definition of the natural numbers presented here directly implies the principle of mathematical induction for natural numbers: if a property holds of the natural number 0, and the property holds of whenever it holds of, then the property holds of all natural numbers.
Form of recursive definitions
Most recursive definitions have two foundations: a base case and an inductive clause.The difference between a circular definition and a recursive definition is that a recursive definition must always have base cases, cases that satisfy the definition without being defined in terms of the definition itself, and that all other instances in the inductive clauses must be "smaller" in some sense — a rule also known as "recur only with a simpler case".
In contrast, a circular definition may have no base case, and even may define the value of a function in terms of that value itself — rather than on other values of the function. Such a situation would lead to an infinite regress.
That recursive definitions are valid – meaning that a recursive definition identifies a unique function – is a theorem of set theory known as the recursion theorem, the proof of which is non-trivial. Where the domain of the function is the natural numbers, sufficient conditions for the definition to be valid are that the value of is given, and that for, an algorithm is given for determining in terms of, .
More generally, recursive definitions of functions can be made whenever the domain is a well-ordered set, using the principle of transfinite recursion. The formal criteria for what constitutes a valid recursive definition are more complex for the general case. An outline of the general proof and the criteria can be found in James Munkres' Topology. However, a specific case of the general recursive definition will be given below.
Principle of recursive definition
Let be a set and let be an element of. If is a function which assigns to each function mapping a nonempty section of the positive integers into, an element of, then there exists a unique function such thatExamples of recursive definitions
Elementary functions
is defined recursively based on counting asMultiplication is defined recursively as
Exponentiation is defined recursively as
Binomial coefficients can be defined recursively as
Prime numbers
The set of prime numbers can be defined as the unique set of positive integers satisfying- 2 is a prime number,
- any other positive integer is a prime number if and only if it is not divisible by any prime number smaller than itself.
Non-negative even numbers
The even numbers can be defined as consisting of- 0 is in the set of non-negative evens,
- For any element in the set, is in ,
- Nothing is in unless it is obtained from the basis and inductive clauses.
Well formed formula
- is a wff if is a propositional variable.
- is a wff if is a wff.
- is a wff if and are wffs and • is one of the logical connectives ∨, ∧, →, or ↔.
- is a wff, because the propositional variables and are wffs and is a logical connective.
- is a wff, because is a wff.
- is a wff, because and are wffs and is a logical connective.
Recursive definitions as logic programs
even.
even :- even.
Here
The logic programming language Prolog uses backward reasoning to solve goals and answer queries. For example, given the query
The program can be used not only to check whether a query is true, but also to generate answers that are true. For example:
?- even.
X = 0
X = s
X = s)
X = s)))
.....
Logic programs significantly extend recursive definitions by including the use of negative conditions, implemented by negation as failure, as in the definition:
even.
even :- not.