Recursion
by aoum, Apr 17, 2025, 12:11 AM
Recursion: A Foundational Principle in Mathematics and Computer Science
Recursion is a method of defining functions, sequences, and structures in terms of themselves. It is both a powerful conceptual framework and a computational technique that appears throughout mathematics, computer science, and logic.
1. Recursive Definitions
A definition is recursive if it defines an object in terms of smaller or simpler instances of itself. To ensure that recursion is well-defined, it must contain:
2. Example: Factorial Function
A classic example is the factorial function
, defined recursively by:

This definition satisfies:
We compute
as:

3. Recursive Sequences: The Fibonacci Numbers
Defined by:


this sequence grows rapidly and is deeply connected with the golden ratio
. The closed-form expression (Binet’s formula) is:

4. Recursion in Proof: Mathematical Induction
Mathematical induction is the natural tool for proving properties of recursively defined objects. For example, to prove:

we use induction:
5. Recursive Algorithms
Recursive functions in programming directly reflect mathematical recursion. For example, a recursive algorithm for factorial:
Recursive algorithms are concise, but may be inefficient if not optimized (e.g. naive recursive Fibonacci has exponential time).
6. Recurrence Relations
A recurrence relation expresses a term
in terms of earlier terms. For instance:

This can be solved using characteristic equations. Let
, then:

Solving yields roots
and
, so:

Constants
and
are found using initial conditions.
7. Recursive Structures: Fractals
Recursion underlies self-similar geometries like the Sierpiński triangle and Koch snowflake. Each stage is constructed by recursively applying transformation rules.
Example of a Sierpinski triangle using Asymptote:
![[asy]
void sierpinski(pair A, pair B, pair C, int depth) {
if (depth == 0) {
draw(A--B--C--cycle);
} else {
pair AB = midpoint(A--B);
pair AC = midpoint(A--C);
pair BC = midpoint(B--C);
sierpinski(A, AB, AC, depth - 1);
sierpinski(AB, B, BC, depth - 1);
sierpinski(AC, BC, C, depth - 1);
}
}
sierpinski((0,0), (2,0), (1,sqrt(3)), 4);
[/asy]](//latex.artofproblemsolving.com/4/d/8/4d8a22d8ba28225ec7a96d2177132a1d4a2ca6d7.png)
8. Mutual and Structural Recursion
Mutual recursion involves two or more functions defined in terms of each other.
Structural recursion refers to definitions that follow the structure of data types. For example, recursively summing a list:
9. Theoretical Insights
Recursion is essential in:
10. Recursive vs Iterative
While recursion and iteration can often achieve the same results, recursion emphasizes definition by self-reference, whereas iteration emphasizes repetition through control structures. Some recursive problems can be transformed into iterative solutions and vice versa.
References
Recursion is a method of defining functions, sequences, and structures in terms of themselves. It is both a powerful conceptual framework and a computational technique that appears throughout mathematics, computer science, and logic.
1. Recursive Definitions
A definition is recursive if it defines an object in terms of smaller or simpler instances of itself. To ensure that recursion is well-defined, it must contain:
- A base case: the simplest instance of the definition that does not involve recursion.
- A recursive step: which reduces a general case to one or more simpler cases.
2. Example: Factorial Function
A classic example is the factorial function


This definition satisfies:
- Base case:
- Recursive case:
We compute


3. Recursive Sequences: The Fibonacci Numbers
Defined by:


this sequence grows rapidly and is deeply connected with the golden ratio


4. Recursion in Proof: Mathematical Induction
Mathematical induction is the natural tool for proving properties of recursively defined objects. For example, to prove:

we use induction:
- Base case:
- Inductive step: Assume
and
Then:
5. Recursive Algorithms
Recursive functions in programming directly reflect mathematical recursion. For example, a recursive algorithm for factorial:
def factorial(n): if n == 0: return 1 return n * factorial(n - 1) # Example usage: print(factorial(5)) # This will print the factorial of 5
Recursive algorithms are concise, but may be inefficient if not optimized (e.g. naive recursive Fibonacci has exponential time).
6. Recurrence Relations
A recurrence relation expresses a term


This can be solved using characteristic equations. Let


Solving yields roots



Constants


7. Recursive Structures: Fractals
Recursion underlies self-similar geometries like the Sierpiński triangle and Koch snowflake. Each stage is constructed by recursively applying transformation rules.
Example of a Sierpinski triangle using Asymptote:
![[asy]
void sierpinski(pair A, pair B, pair C, int depth) {
if (depth == 0) {
draw(A--B--C--cycle);
} else {
pair AB = midpoint(A--B);
pair AC = midpoint(A--C);
pair BC = midpoint(B--C);
sierpinski(A, AB, AC, depth - 1);
sierpinski(AB, B, BC, depth - 1);
sierpinski(AC, BC, C, depth - 1);
}
}
sierpinski((0,0), (2,0), (1,sqrt(3)), 4);
[/asy]](http://latex.artofproblemsolving.com/4/d/8/4d8a22d8ba28225ec7a96d2177132a1d4a2ca6d7.png)
8. Mutual and Structural Recursion
Mutual recursion involves two or more functions defined in terms of each other.
Structural recursion refers to definitions that follow the structure of data types. For example, recursively summing a list:
def sum(L): if not L: # Check if the list is empty return 0 return L[0] + sum(L[1:]) # Recursively sum the list # Example usage: result = sum([1, 2, 3, 4, 5]) print(result) # This will print the sum of the list
9. Theoretical Insights
Recursion is essential in:
- Set theory: Defining ordinals and cardinals recursively
- Formal languages: Recursive grammars generate infinite languages
- Logic: Gödel numbering and recursive functions in computability theory
- Category theory: Fixed points and recursive objects
10. Recursive vs Iterative
While recursion and iteration can often achieve the same results, recursion emphasizes definition by self-reference, whereas iteration emphasizes repetition through control structures. Some recursive problems can be transformed into iterative solutions and vice versa.
References
- AoPS Wiki: Recursion
- Graham, Knuth, Patashnik – Concrete Mathematics
- Grimaldi – Discrete and Combinatorial Mathematics
- Sipser – Introduction to the Theory of Computation
- Wikipedia: Recursion (Mathematics)