Fibonacci Sequence Generator & Calculator
Generate Fibonacci sequences up to 2,000 terms or calculate any Nth term instantly. Get exact BigInt results, custom output formats, and Fibonacci number lookup.
Fibonacci Sequence Generator & Calculator
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181
| Index (n) | Ratio Equation | Calculated Ratio (F_n / F_n-1) | Difference from Phi (|Ratio - φ|) |
|---|---|---|---|
| n = 2 | 1 / 1 | 1.0000000000 | 6.1803e-1 |
| n = 3 | 2 / 1 | 2.0000000000 | 3.8197e-1 |
| n = 4 | 3 / 2 | 1.5000000000 | 1.1803e-1 |
| n = 5 | 5 / 3 | 1.6666666667 | 4.8633e-2 |
| n = 6 | 8 / 5 | 1.6000000000 | 1.8034e-2 |
| n = 7 | 13 / 8 | 1.6250000000 | 6.9660e-3 |
| n = 8 | 21 / 13 | 1.6153846154 | 2.6494e-3 |
| n = 9 | 34 / 21 | 1.6190476190 | 1.0136e-3 |
| n = 10 | 55 / 34 | 1.6176470588 | 3.8693e-4 |
| n = 11 | 89 / 55 | 1.6181818182 | 1.4783e-4 |
| Step | Recurrence Addition Equation | Resulting Term Value |
|---|---|---|
| F(2) | F(2) = 1 + 0 = 1 | 1 |
| F(3) | F(3) = 1 + 1 = 2 | 2 |
| F(4) | F(4) = 2 + 1 = 3 | 3 |
| F(5) | F(5) = 3 + 2 = 5 | 5 |
| F(6) | F(6) = 5 + 3 = 8 | 8 |
| F(7) | F(7) = 8 + 5 = 13 | 13 |
| F(8) | F(8) = 13 + 8 = 21 | 21 |
| F(9) | F(9) = 21 + 13 = 34 | 34 |
| F(10) | F(10) = 34 + 21 = 55 | 55 |
| F(11) | F(11) = 55 + 34 = 89 | 89 |
| F(12) | F(12) = 89 + 55 = 144 | 144 |
| F(13) | F(13) = 144 + 89 = 233 | 233 |
| F(14) | F(14) = 233 + 144 = 377 | 377 |
| F(15) | F(15) = 377 + 233 = 610 | 610 |
| F(16) | F(16) = 610 + 377 = 987 | 987 |
| F(17) | F(17) = 987 + 610 = 1597 | 1597 |
| F(18) | F(18) = 1597 + 987 = 2584 | 2584 |
| F(19) | F(19) = 2584 + 1597 = 4181 | 4181 |
Overview: How to Generate a Fibonacci Sequence
The Fibonacci sequence is one of the most famous mathematical patterns in number theory, computer science, and nature. It begins with 0 and 1, and each subsequent term is calculated by adding the two preceding terms:
The ToolMono Fibonacci Sequence Generator & Calculator satisfies three distinct user intents in one interface: generating sequential series, calculating exact Nth terms (e.g. F(100)), and checking Fibonacci membership for any input integer. Explore companion math tools: Online Calculator, Scientific Calculator, Prime Number Checker, GCD & LCM Calculator, Numerical Methods, Binary ↔ Decimal Converter, Decimal ↔ Hex Converter, and Decimal ↔ Octal Converter.
How to Use the Generator & Calculator
Select First N Terms to generate an ordered list up to 2,000 BigInt terms with custom output formatting (Comma, JSON, CSV, Markdown).
Select Nth Term Calculator to compute any single Fibonacci term F(n) instantly with 100% BigInt integer precision.
Select Fibonacci Membership Checker to test if a number (e.g. 144) is Fibonacci via exact 5x² ± 4 perfect square tests.
Toggle between standard zero-indexed F(0)=0, F(1)=1 and legacy F(1)=1, F(2)=1 conventions.
Fibonacci Sequence Formula and Recurrence Relation
The Fibonacci sequence is defined mathematically by the linear recurrence relation:
with initial seed conditions:
How to Calculate the Nth Fibonacci Number
There are several computational methods to calculate the $n$-th Fibonacci term:
| Method | Time Complexity | Space Complexity | Precision & Memory Characteristics |
|---|---|---|---|
| Fast Doubling | O(log N) | O(log N) | Fastest exact BigInt method for large indices |
| Iterative Loop | O(N) | O(1) | Ideal for generating full sequential output arrays |
| Matrix Exponentiation | O(log N) | O(1) | Uses matrix powers [[1,1],[1,0]]^n |
| Binet's Formula | O(1) | O(1) | Closed-form floating point (loses precision beyond n > 70) |
Binet's Formula and Exact Fibonacci Calculations
Binet's formula provides a closed-form expression for calculating $F(n)$ directly using the Golden Ratio:
where:
While Binet's formula is mathematically exact in real numbers, computing it using 64-bit floating-point numbers causes rounding errors for $n > 70$. ToolMono uses native JavaScript BigInt arithmetic for $100\%$ exact integer output up to thousands of digits.
Fibonacci Numbers and the Golden Ratio (Phi φ)
The ratio of consecutive Fibonacci numbers approaches the Golden Ratio $\phi$ as the index increases:
| Index (n) | Ratio Equation | Calculated Ratio | Difference from φ |
|---|---|---|---|
| n = 2 | 1 / 1 | 1.0000000000 | 0.6180 |
| n = 5 | 5 / 3 | 1.6666666667 | 0.0486 |
| n = 10 | 55 / 34 | 1.6176470588 | 0.00038 |
| n = 20 | 6765 / 4181 | 1.6180339887 | 0.000000002 |
Sum of Fibonacci Terms
The sum of the first $n$ Fibonacci terms satisfies the elegant identity:
Fibonacci Quick Reference Table
Exact values for key Fibonacci terms verified against BigInt calculations:
| Index (n) | F(n) Exact Value | Digit Length |
|---|---|---|
| n = 0 | 0 | 1 digits |
| n = 1 | 1 | 1 digits |
| n = 2 | 1 | 1 digits |
| n = 3 | 2 | 1 digits |
| n = 4 | 3 | 1 digits |
| n = 5 | 5 | 1 digits |
| n = 10 | 55 | 2 digits |
| n = 20 | 6765 | 4 digits |
| n = 30 | 832040 | 6 digits |
| n = 50 | 12586269025 | 11 digits |
| n = 78 | 8944394323791464 | 16 digits |
| n = 79 | 14472334024676221 | 17 digits |
| n = 100 | 354224848179261915075 | 21 digits |
Fibonacci Indexing: F(0) vs F(1)
Two primary indexing conventions exist in literature and software:
F(0) = 0, F(1) = 1, F(2) = 1, F(3) = 2. Used in computer science and modern university mathematics.
F(1) = 1, F(2) = 1, F(3) = 2, F(4) = 3. Used in some school textbooks and classical number theory texts.
Fibonacci Number Edge Cases & Membership
- Is 0 a Fibonacci number? Yes, under standard zero-indexing F(0) = 0.
- Is 1 a Fibonacci number? Yes, it appears twice as F(1) = 1 and F(2) = 1.
- Negative Fibonacci Indices (Negafibonacci): Extends Fibonacci to negative indices via F(-n) = (-1)^(n+1) × F(n). E.g. F(-1) = 1, F(-2) = -1, F(-3) = 2.
Fibonacci Membership Algorithm (5x² ± 4 Test)
To test whether an integer $x$ is a Fibonacci number without generating the sequence, use Gessel's Theorem:
Example for x = 144:
Production Code Implementations
export function fibonacciSequence(n) {
if (n <= 0) return [];
const seq = [0n];
if (n === 1) return seq;
seq.push(1n);
for (let i = 2; i < n; i++) {
seq.push(seq[i - 1] + seq[i - 2]);
}
return seq;
}export function fastDoublingBigInt(n) {
if (n === 0n) return [0n, 1n];
const [a, b] = fastDoublingBigInt(n >> 1n);
const c = a * (2n * b - a);
const d = a * a + b * b;
return (n & 1n) === 0n ? [c, d] : [d, c + d];
}def fibonacci_sequence(n: int) -> list[int]:
if n <= 0:
return []
seq = [0, 1]
for i in range(2, n):
seq.append(seq[-1] + seq[-2])
return seq[:n]def fast_doubling(n: int) -> tuple[int, int]:
if n == 0:
return (0, 1)
a, b = fast_doubling(n >> 1)
c = a * (2 * b - a)
d = a * a + b * b
if n & 1:
return (d, c + d)
else:
return (c, d)public static BigInteger[] fibonacci(int n) {
BigInteger[] seq = new BigInteger[n];
if (n > 0) seq[0] = BigInteger.ZERO;
if (n > 1) seq[1] = BigInteger.ONE;
for (int i = 2; i < n; i++) {
seq[i] = seq[i - 1].add(seq[i - 2]);
}
return seq;
}public static BigInteger[] fastDoubling(int n) {
if (n == 0) return new BigInteger[]{BigInteger.ZERO, BigInteger.ONE};
BigInteger[] prev = fastDoubling(n >> 1);
BigInteger a = prev[0], b = prev[1];
BigInteger c = a.multiply(b.multiply(BigInteger.valueOf(2)).subtract(a));
BigInteger d = a.multiply(a).add(b.multiply(b));
return (n & 1) == 0 ? new BigInteger[]{c, d} : new BigInteger[]{d, c.add(d)};
}package main
import "math/big"
func Fibonacci(n int) []*big.Int {
seq := make([]*big.Int, n)
if n > 0 { seq[0] = big.NewInt(0) }
if n > 1 { seq[1] = big.NewInt(1) }
for i := 2; i < n; i++ {
seq[i] = new(big.Int).Add(seq[i-1], seq[i-2])
}
return seq
}func FastDoubling(n int64) (*big.Int, *big.Int) {
if n == 0 { return big.NewInt(0), big.NewInt(1) }
a, b := FastDoubling(n >> 1)
twoB := new(big.Int).Mul(big.NewInt(2), b)
c := new(big.Int).Mul(a, new(big.Int).Sub(twoB, a))
d := new(big.Int).Add(new(big.Int).Mul(a, a), new(big.Int).Mul(b, b))
if n&1 == 0 { return c, d }
return d, new(big.Int).Add(c, d)
}#include <vector>
#include <iostream>
std::vector<long long> fibonacci(int n) {
if (n <= 0) return {};
std::vector<long long> seq = {0, 1};
for (int i = 2; i < n; i++) {
seq.push_back(seq[i - 1] + seq[i - 2]);
}
return seq;
}// Returns {F(n), F(n+1)} in O(log n) time
std::pair<long long, long long> fastDoubling(long long n) {
if (n == 0) return {0, 1};
auto [a, b] = fastDoubling(n >> 1);
long long c = a * (2 * b - a);
long long d = a * a + b * b;
if (n & 1) return {d, c + d};
return {c, d};
}fn fibonacci(n: usize) -> Vec<u128> {
if n == 0 { return vec![]; }
let mut seq = vec![0, 1];
for i in 2..n {
let next = seq[i - 1] + seq[i - 2];
seq.push(next);
}
seq.truncate(n);
seq
}fn fast_doubling(n: u64) -> (u128, u128) {
if n == 0 { return (0, 1); }
let (a, b) = fast_doubling(n >> 1);
let c = a * (2 * b - a);
let d = a * a + b * b;
if n & 1 == 1 { (d, c + d) } else { (c, d) }
}Common Mathematical & Coding Errors
- Using Standard Floats for Large N: JavaScript
Numberloses integer precision for F(n) when n > 78. Always useBigInt. - Naive Recursion Overhead: Computing F(n) recursively without memoization runs in exponential time $O(2^N)$, causing stack overflow for $n > 40$.
- Confusing Term Count with Maximum Index: Generating "10 terms" produces F(0) through F(9), whereas generating "through index 10" produces 11 terms.
Performance & Complexity Analysis
- Time Complexity: Fast Doubling operates in $O(\log N)$ bitwise operations.
- Space Complexity: $O(1)$ auxiliary space for single-term calculation.
- Browser Safety: Client-side BigInt execution prevents browser UI freezes.
Best Practices
Always use BigInt in JavaScript for $n \ge 78$ to prevent numeric precision loss.
Use $O(\log N)$ Fast Doubling when fetching isolated $N$-th terms without needing previous terms.
Frequently Asked Questions
References & Standards
NIST Digital Library of Mathematical Functions
NIST reference for Fibonacci sequences and Binet's formula.
ISO 80000-2: Mathematics Notation Standard
ISO standard for mathematical sequences and recurrence relations.
ECMAScript BigInt Specification
Official specification for arbitrary-precision integer calculations.
Related Tools
Browse all toolsOnline Calculator
Free online calculator for quick everyday math, complex expressions, parentheses, percentages, and powers. Includes keyboard input and local calculation history.
Scientific Calculator
Use ToolMono's free Scientific Calculator for advanced mathematical calculations. Supports trigonometric, inverse, hyperbolic, logarithmic, exponential, factorial, scientific notation, degree/radian modes, calculation history, and 100% client-side processing.
Prime Checker
Enter a whole number to check whether it is prime or composite. Get a clear result, inspect the available factorization details, and understand how primality testing works.
GCD & LCM Calculator
Enter two or more integers to calculate their greatest common divisor (GCD) and least common multiple (LCM). View the results and, where supported, follow the calculation steps to understand how they are obtained.
Numerical Methods Calculator
Interactive engineering workspace for Bisection, Newton-Raphson, Secant, Simpson's, Gaussian Elimination, and RK4.
Percentage Calculator
Calculate percentages instantly with ToolMono's free online percentage calculator. Find X% of Y, calculate what percent X is of Y, and solve reverse percentages.
Binary to Decimal Converter
Free online binary to decimal and decimal to binary converter. Supports BigInt arbitrary precision, signed two's complement, bit width validation, and step-by-step breakdowns.
Decimal ↔ Hex Converter
Free online Decimal to Hex Converter. Convert base-10 to base-16 hexadecimal instantly. Supports BigInt, two's complement, 8–64 bit signed/unsigned, and live steps.