Recursive definition

From HandWiki
Revision as of 13:50, 6 February 2024 by MainAI5 (talk | contribs) (update)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Short description: Defining elements of a set in terms of other elements in the set
Four stages in the construction of a Koch snowflake. As with many other fractals, the stages are obtained via a 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 (Aczel 1977:740ff). 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 (usually smaller) inputs. For example, the factorial function n! is defined by the rules

[math]\displaystyle{ \begin{align} & 0! = 1. \\ & (n+1)! = (n+1) \cdot n!. \end{align} }[/math]

This definition is valid for each natural number n, 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 n!, starting from n = 0 and proceeding onwards with n = 1, 2, 3 etc.

The recursion theorem states that such a definition indeed defines a function that is unique. The proof uses mathematical induction.[1]

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 [math]\displaystyle{ \N }[/math] of natural numbers is:

  1. 1 is in [math]\displaystyle{ \N. }[/math]
  2. If an element n is in [math]\displaystyle{ \N }[/math] then n + 1 is in [math]\displaystyle{ \N. }[/math]
  3. [math]\displaystyle{ \N }[/math] is the intersection of all sets satisfying (1) and (2).

There are many sets that satisfy (1) and (2) – for example, the set {1, 1.649, 2, 2.649, 3, 3.649, …} satisfies the definition. However, condition (3) specifies the set of natural numbers by removing the sets with extraneous members. Note that this definition assumes that [math]\displaystyle{ \N }[/math] is contained in a larger set (such as the set of real numbers) — in which the operation + is defined.

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 (or 1), and the property holds of n + 1 whenever it holds of n, then the property holds of all natural numbers (Aczel 1977:742).

Form of recursive definitions

Most recursive definitions have two foundations: a base case (basis) 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 (i.e., closer to those base cases that terminate the recursion) — a rule also known as "recur only with a simpler case".[2]

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.[3] Where the domain of the function is the natural numbers, sufficient conditions for the definition to be valid are that the value of f(0) (i.e., base case) is given, and that for n > 0, an algorithm is given for determining f(n) in terms of n, [math]\displaystyle{ f(0), f(1), \dots, f(n-1) }[/math] (i.e., inductive clause).

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 (domain is restricted to the positive integers instead of any well-ordered set) of the general recursive definition will be given below.[4]

Principle of recursive definition

Let A be a set and let a0 be an element of A. If ρ is a function which assigns to each function f mapping a nonempty section of the positive integers into A, an element of A, then there exists a unique function [math]\displaystyle{ h : \Z_+ \to A }[/math] such that

[math]\displaystyle{ \begin{align} h(1) &= a_0 \\ h(i) &= \rho \left(h|_{\{1,2,\ldots,i-1\}}\right) \text{ for } i\gt 1. \end{align} }[/math]

Examples of recursive definitions

Elementary functions

Addition is defined recursively based on counting as

[math]\displaystyle{ \begin{align} & 0 + a = a, \\ & (1+n) + a = 1 + (n+a). \end{align} }[/math]

Multiplication is defined recursively as

[math]\displaystyle{ \begin{align} & 0 \cdot a = 0, \\ & (1+n) \cdot a = a + n \cdot a. \end{align} }[/math]

Exponentiation is defined recursively as

[math]\displaystyle{ \begin{align} & a^0 = 1, \\ & a^{1+n} = a \cdot a^n. \end{align} }[/math]

Binomial coefficients can be defined recursively as

[math]\displaystyle{ \begin{align} & \binom{a}{0} = 1, \\ & \binom{1+a}{1+n} = \frac{(1+a)\binom{a}{n}}{1+n}. \end{align} }[/math]

Prime numbers

The set of prime numbers can be defined as the unique set of positive integers satisfying

  • 1 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.

The primality of the integer 1 is the base case; checking the primality of any larger integer X by this definition requires knowing the primality of every integer between 1 and X, which is well defined by this definition. That last point can be proved by induction on X, for which it is essential that the second clause says "if and only if"; if it had just said "if", the primality of, for instance, the number 4 would not be clear, and the further application of the second clause would be impossible.

Non-negative even numbers

The even numbers can be defined as consisting of

  • 0 is in the set E of non-negative evens (basis clause),
  • For any element x in the set E, x + 2 is in E (inductive clause),
  • Nothing is in E unless it is obtained from the basis and inductive clauses (extremal clause).

Well formed formulas

It is chiefly in logic or computer programming that recursive definitions are found. For example, a well-formed formula (wff) can be defined as:

  1. a symbol which stands for a proposition – like p means "Connor is a lawyer."
  2. The negation symbol (¬), followed by a wff – like ¬ p means "It is not true that Connor is a lawyer."
  3. Any of the four binary connectivesnegation (¬), conjunction (), disjunction (), and implication () – followed by two wffs. The symbol ∧ (AND) means "both are true", so pq may mean "Connor is a lawyer, and Mary likes music."

The value of such a recursive definition is that it can be used to determine whether any particular string of symbols is "well formed".

  • pq is well formed, because it is AND () followed by the atomic wffs p, q.
  • ¬ (pq) is well formed, because it is NOT (¬) followed by pq, which is in turn a wff.
  • p) ∧ (¬ q) is AND () followed by ¬ p and ¬ q; and both ¬ p and ¬ p are wffs.

See also

Notes

  1. Henkin, Leon (1960). "On Mathematical Induction". The American Mathematical Monthly 67 (4): 323–338. doi:10.2307/2308975. ISSN 0002-9890. 
  2. "All About Recursion". https://www.cis.upenn.edu/~matuszek/cis554-2011/Pages/recursion.html. 
  3. For a proof of Recursion Theorem, see On Mathematical Induction (1960) by Leon Henkin.
  4. Munkres, James (1975). Topology, a first course (1st ed.). New Jersey: Prentice-Hall. p. 68, exercises 10 and 12. ISBN 0-13-925495-1. https://archive.org/details/topologyfirstcou00munk_0/page/68. 

References