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:
  • 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 $n!$, defined recursively by:

$$
n! = \begin{cases}
1 & \text{if } n = 0, \\
n \cdot (n-1)! & \text{if } n > 0.
\end{cases}
$$
This definition satisfies:
  • Base case: $0! = 1$
  • Recursive case: $n! = n \cdot (n - 1)!$

We compute $5!$ as:
$$
5! = 5 \cdot 4! = 5 \cdot 4 \cdot 3! = 5 \cdot 4 \cdot 3 \cdot 2! = \dots = 120.
$$
3. Recursive Sequences: The Fibonacci Numbers

Defined by:

$$
F_0 = 0, \quad F_1 = 1,
$$$$
F_n = F_{n-1} + F_{n-2} \quad \text{for } n \geq 2,
$$
this sequence grows rapidly and is deeply connected with the golden ratio $\varphi = \frac{1 + \sqrt{5}}{2}$. The closed-form expression (Binet’s formula) is:

$$
F_n = \frac{\varphi^n - (1 - \varphi)^n}{\sqrt{5}}.
$$
4. Recursion in Proof: Mathematical Induction

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

$$
F_n < 2^n \quad \text{for all } n \geq 1,
$$
we use induction:
  • Base case: $F_1 = 1 < 2$
  • Inductive step: Assume $F_k < 2^k$ and $F_{k-1} < 2^{k-1}$
    Then:

    $$
F_{k+1} = F_k + F_{k-1} < 2^k + 2^{k-1} = 2^{k-1}(2 + 1) = 3 \cdot 2^{k-1} < 2^{k+1}.
$$

5. Recursive Algorithms

Recursive functions in programming directly reflect mathematical recursion. For example, a recursive algorithm for factorial:

  1. def factorial(n):
  2. if n == 0:
  3. return 1
  4. return n * factorial(n - 1)
  5.  
  6. # Example usage:
  7. 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 $a_n$ in terms of earlier terms. For instance:

$$
a_n = 3a_{n-1} + 4a_{n-2}, \quad a_0 = 2, \ a_1 = 5.
$$
This can be solved using characteristic equations. Let $a_n = r^n$, then:

$$
r^n = 3r^{n-1} + 4r^{n-2} \Rightarrow r^2 = 3r + 4 \Rightarrow r^2 - 3r - 4 = 0.
$$
Solving yields roots $r = 4$ and $r = -1$, so:

$$
a_n = \alpha \cdot 4^n + \beta \cdot (-1)^n.
$$
Constants $\alpha$ and $\beta$ 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]

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:

  1. def sum(L):
  2. if not L: # Check if the list is empty
  3. return 0
  4. return L[0] + sum(L[1:]) # Recursively sum the list
  5.  
  6. # Example usage:
  7. result = sum([1, 2, 3, 4, 5])
  8. 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

Comment

0 Comments

Fun with math!

avatar

aoum
Archives
+ March 2025
Shouts
Submit
  • I have initiated a mass removal of shouts related to AI-related allegations.

    by aoum, May 4, 2025, 8:03 PM

  • krish6_9 has been permanently banned.

    by aoum, May 3, 2025, 3:03 PM

  • If you leave a comment on one of my posts—especially older ones—I might not see it right away.

    by aoum, May 2, 2025, 11:55 PM

  • 100 posts!

    by aoum, Apr 21, 2025, 9:11 PM

  • Very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very cool (The maximum of the factorial machine is 7228!

    by Coin1, Apr 21, 2025, 4:44 AM

  • cool blog and good content but it looks eerily similar to chatgpt

    by SirAppel, Apr 17, 2025, 1:28 AM

  • 1,000 views!

    by aoum, Apr 17, 2025, 12:25 AM

  • Excellent blog. Contribute?

    by zhenghua, Apr 10, 2025, 1:27 AM

  • Are you asking to contribute or to be notified whenever a post is published?

    by aoum, Apr 10, 2025, 12:20 AM

  • nice blog! love the dedication c:
    can i have contrib to be notified whenever you post?

    by akliu, Apr 10, 2025, 12:08 AM

  • WOAH I JUST CAME HERE, CSS IS CRAZY

    by HacheB2031, Apr 8, 2025, 5:05 AM

  • Thanks! I'm happy to hear that! How is the new CSS? If you don't like it, I can go back.

    by aoum, Apr 8, 2025, 12:42 AM

  • This is such a cool blog! Just a suggestion, but I feel like it would look a bit better if the entries were wider. They're really skinny right now, which makes the posts seem a lot longer.

    by Catcumber, Apr 4, 2025, 11:16 PM

  • The first few posts for April are out!

    by aoum, Apr 1, 2025, 11:51 PM

  • Sure! I understand that it would be quite a bit to take in.

    by aoum, Apr 1, 2025, 11:08 PM

61 shouts
Contributors
Tags
Problem of the Day
Fractals
geometry
combinatorics
Millennium Prize Problems
poll
Riemann Hypothesis
calculus
Collatz Conjecture
Factorials
graph theory
infinity
pi
Sir Issac Newton
AMC
Bernoulli numbers
Chudnovsky Algorithm
Exponents
Gauss-Legendre Algorithm
Goldbach Conjecture
Koch snowflake
MAA
Mandelbrot Set
Mastering AMC 1012
MATHCOUNTS
Matroids
Nilakantha Series
number theory
P vs NP Problem
P-adic Analysis
paradoxes
Polynomials
probability
Ramsey Theory
1d
2D
3d
4d
algebra
Algorithmic Applications
AMC 10
AMC 8
angle bisector theorem
Angle trisection
Applications in Various Fields
Arc Sine Formula
Archimedes Method
Banach-Tarski Paradox
Basel Problem
Basic Reproduction Number
Bayes Theorem
Bell Curve
Bertrand s Box Paradox
binomial theorem
Birthday Attack
Birthday Problem
buffon s needle
Cantor s Infinite Sets
cardinality
catalan numbers
Chicken McNugget Theorem
Circumference
Coin Rotation Paradox
computer science
conditional probability
conic sections
Conjectures
Cryptography
Cyclic Numbers
Cyclic Sieving Phenomenon
Different Sizes of Infinity
Diophantine Equations
Diophantinve Approximation
Dirichlets Approximation
Diseases
Double Factorials
Drake Equation
epidemiology
euclidean geometry
Euler Characteristic
Euler s Formula for Polyhedra
Euler s Identity
Euler s totient function
Euler-Lagrange Equation
Fermat s Factoring Method
fermat s last theorem
Fibonacci sequence
finite
First Dimenstion
four color theorem
Fourth dimension
Fractals and Chaos Theory
free books
Gamma function
Golden Ratio
Graham s Number
Graph Minor Theorem
gravity
Greedoids
Gregory-Liebniz Series
Hailstone Problem
Heron s Formula
Higher Dimensions
Hilbert s Hotel
Hilberts Hotel
Hodge Conjecture
ideal gas law
Inclusion-exclusion
infinite
Irrational numbers
Kruskals Tree Theorem
Laplace s Equation
Law of Force and Acceleration
legendre s theorem
Leibniz Formula
logarithms
logic
Mastering AMC 8
Matrices
Menger Sponge
Minkowskis Theorem
modular arithmetic
Multinomial Theorem
Multiples of 24
National Science Bowl
Newton s First Law of Motion
Newton s Second Law of Motion
Newton s Third Law of Motion
normal distribution
Parabolas
Paradox
Penrose Tilings
physical chemistry
pie
pigeonhole principle
platonic solids
Price s Equation
prime numbers
primes
Ptolemys Theorem
Pythagorean Theorem
Python
Ramsey s Theorem
recursion
Reproduction Rate of Diseases
Riemann Zeta Function
Second Dimension
Sequences
Sequences of Binomial Type
Sets
Sierpinski Triangle
Sierpiski Carpet
Sierpiski Triangle
Simon s Factoring Trick
statistics
Sums of Like Powers
Taylor series
The Birthday Problem
The Book of Formulas
The HalesJewett Theorem
The Law of Action and Reaction
The Law of Inertia
The Lost Boarding Pass Problem
thermodynamics
Third Dimension
Topological Insights
triangle inequality
trigonometry
twin prime conjecture
Umbral Calculus
Van der Waerdens Theorem
venn diagram
Wallis Product
Zeno s Paradoxes
About Owner
  • Posts: 0
  • Joined: Nov 2, 2024
Blog Stats
  • Blog created: Mar 1, 2025
  • Total entries: 112
  • Total visits: 1346
  • Total comments: 39
Search Blog
a