Advanced mathematics · Recursion

Recursive Function Visualizer

Explore recursively defined mathematical functions. Follow recurrence relations step by step, inspect sequence values, and visualize how recursive functions grow.

Choose a recursive function

Select a function and input value to see its recurrence, evaluation steps, sequence and visual representation.

Current selection: Factorial, n = 8 · Share this result

Function definition

Factorial
n!

Multiplies all positive integers from 1 to n.

RECURRENCE RELATION
F(0) = 1; F(n) = n × F(n − 1)

Calculation result

Calculated value
40,320

n! evaluated at the selected input.

Selected input
8

Input parameter for the selected recurrence.

Visual sequence

Each bar represents a calculated term. The bar widths are scaled relative to the largest displayed value, so the visualization is illustrative rather than a linear comparison between different functions.

0
1
1
1
2
2
3
6
4
24
5
120
6
720
7
5,040
8
40,320

The sequence chart displays the calculated steps for the selected function. It does not imply that different mathematical functions share the same scale.

Recursive evaluation steps

Follow the recurrence from its initial values to the selected result.

Step Recursive expression Value
1 F(0) = 1 1
2 F(1) = 1 × F(0) 1
3 F(2) = 2 × F(1) 2
4 F(3) = 3 × F(2) 6
5 F(4) = 4 × F(3) 24
6 F(5) = 5 × F(4) 120
7 F(6) = 6 × F(5) 720
8 F(7) = 7 × F(6) 5,040
9 F(8) = 8 × F(7) 40,320

How recursive functions work

A recursive function defines a value using one or more previously defined values of the same function. Instead of specifying every possible output independently, it gives a rule for building new outputs from earlier ones.

Base case

F(0) = initial value

The base case provides the starting point of the recurrence. Without a suitable base case, recursive evaluation may not terminate.

Recursive rule

F(n) = expression involving earlier values

The recursive rule describes how to calculate a new term using earlier terms or other function values.

Frequently asked questions

1. What is a recursively defined function?

A recursively defined function is described using one or more initial values and a rule that defines later values in terms of earlier values. This lets a function be built step by step.

2. What is a base case?

A base case is an initial value that does not need further recursive evaluation. For example, factorial uses 0! = 1. Base cases prevent a recursive definition from continuing indefinitely.

3. How does the Fibonacci recurrence work?

The Fibonacci sequence starts with 0 and 1. Each later term is the sum of the two preceding terms: Fib(n) = Fib(n − 1) + Fib(n − 2).

4. Why is the Ackermann function important?

The Ackermann function is a classic example of a computable function that grows faster than primitive recursive functions. Its nested recursion makes it an important example in mathematical logic and computability theory.

5. Does this visualizer calculate every recursive function?

No. It evaluates a selected collection of supported functions with defined input limits. Arbitrary recursive programs can require much more sophisticated evaluation and resource controls.

6. Why does the visualizer use iterative code?

Some simple recursive definitions can be evaluated with loops that follow the same recurrence. This avoids unnecessary PHP call-stack depth while preserving the mathematical sequence of values.

Related calculators and explorers

Explore more recurrence relations, rapidly growing functions and advanced mathematical sequences.