Recursive Sequence Calculator – Generate Any Recurrence Relation
A recurrence relation defines each term of a sequence as a function of one or more preceding terms, plus one or more seed values to get started. Fibonacci's a(n) = a(n-1) + a(n-2) is the most famous example, but recurrences show up constantly in computer science (analyzing recursive algorithms), finance (recursive interest and deposit schedules), and dynamical systems (chaotic maps). This calculator generates any recurrence of order 1 to 3, jumps directly to a specific term, tracks partial sums and consecutive-term ratios, and automatically classifies the sequence's long-term behavior.
Recurrence Order and Seed Terms
The order of a recurrence is how many prior terms each new term depends on. A 1st-order recurrence like a(n) = 1.05·a(n-1) + 10 needs one seed, a(0). A 2nd-order recurrence like Fibonacci needs two seeds, a(0) and a(1). A 3rd-order recurrence such as the Tribonacci sequence, a(n) = a(n-1) + a(n-2) + a(n-3), needs three. Enter exactly as many seed values as the selected order requires — the calculator iterates forward from there, computing each new term in constant time per step.
Linear Shortcuts vs. Custom Formulas
Most recurrences encountered in coursework and finance are linear: a(n) = c1·a(n-1) + c2·a(n-2) + ... + d. For these, the coefficient fields (c1, c2, c3, and the constant d) are a fast way to describe the recurrence without typing an expression. For anything else — nonlinear growth, chaotic maps like the logistic equation a(n) = r·a(n-1)·(1-a(n-1)), or recurrences that also reference the index n — switch to the custom formula mode and write the expression directly using a(n-1), a(n-2), and a(n-3) as needed.
Safe Formula Evaluation
Custom formulas are never passed to JavaScript's eval. Instead, each expression is parsed into a syntax tree and checked against a strict whitelist of allowed tokens — the index n, the permitted prior-term references, and a fixed set of standard math functions like sin, sqrt, and abs. Any other identifier is rejected before evaluation ever runs, so the input box can't be used to execute arbitrary code.
Exact Results with Big-Integer Mode
Floating-point numbers lose precision once a value exceeds Number.MAX_SAFE_INTEGER (about 9 quadrillion). For whole-number linear recurrences — Fibonacci, Tribonacci, Lucas numbers, and similar — turning on Big-Integer Mode switches the engine to native BigInt arithmetic, so even the 200th or 500th term comes back exact, digit for digit. This mode also supports an optional modulo, useful for competitive-programming style problems that ask for a huge term reduced modulo a large prime.
Partial Sums, Ratios, and Growth Classification
Alongside each generated term, the results table shows the cumulative sum of all terms so far and the ratio of each term to the one before it — useful for spotting convergence, such as the Fibonacci ratio's well-known drift toward the golden ratio, φ ≈ 1.618. The calculator also auto-labels the sequence's overall behavior — constant, convergent, exponential growth, decaying toward zero, oscillating, or chaotic — based on the trend across the last several computed terms.
Jumping Directly to a Term
If you only need one far-out value, like the 200th term of a recurrence, there's no need to scroll through a long table. Switch to Evaluate a specific term mode, enter the index, and the calculator iterates only as far as that term before returning the result.