MathsDiscrete Math

Sequence
analyzer.

Paste a list of numbers to get its nth-term rule, the next terms and the working.

How it's worked out

The tool tries six kinds of rule in a fixed order and keeps the first one that fits every term exactly: constant, arithmetic, geometric, a polynomial of degree 2 to 4, a rule built from the two terms before, and a power of n. The letter n is the position of a term, so the first number you type is a1a_1.

Arithmetic. The same number d is added each time. OpenStax calls d the common difference.

an\displaystyle a_n=a1+d(n−1)\displaystyle {}= a_1 + d(n - 1)

Geometric. Each term is the one before times the same ratio r. The tool only tests this when no term is 0, since you cannot divide by 0.

an\displaystyle a_n=a1⋅rn−1\displaystyle {}= a_1 \cdot r^{n - 1}

Polynomial. Subtract each term from the next to get the first differences, then do the same to those, and so on. That triangle of numbers is the difference table. When the numbers in row k are all equal, the terms come from a polynomial of degree k. Newton's forward-difference form then rebuilds the rule from the first number in each row.

an\displaystyle a_n=a1+Δa1(n−11)\displaystyle {}= a_1 + \Delta a_1 \binom{n-1}{1}+Δ2a1(n−12)+⋯\displaystyle {}+ \Delta^2 a_1 \binom{n-1}{2} + \cdots

Here Δka1\Delta^k a_1 is the first number in row k, and (n−1k)\binom{n-1}{k} is a binomial coefficient: the number of ways to pick k items from n − 1. Multiplying out gives the rule in powers of n. For the squares 1, 4, 9 and 16, the second differences are 2, 2, and the rule comes out as aₙ = n².

Two terms before. When no polynomial of degree 4 or less fits, the tool tests whether each term is p times the one before plus q times the one before that. It solves for p and q from the first four terms, then checks every later term. The Fibonacci numbers pass with aₙ = 1·aₙ₋₁ + 1·aₙ₋₂.

an\displaystyle a_n=pan−1+qan−2\displaystyle {}= p\,a_{n-1} + q\,a_{n-2}

A polynomial of degree k needs at least k + 2 terms, so that one term is left over to test the fit. Four terms are enough for a quadratic and five for a cubic.

Worked examples

Maya counts handshakes at a meeting

Maya notes how many handshakes happen when everyone greets everyone once: 0, 1, 3, 6, 10 for 1 to 5 people. The first differences are 1, 2, 3, 4, and the second differences are all 1, so the rule is quadratic. The decimal form is aₙ = 0.5n² − 0.5n, and the exact form is easier to read:

an\displaystyle a_n=12n2−12n\displaystyle {}= \frac{1}{2}n^{2} - \frac{1}{2}n

With 12 people there are 66 handshakes. Going the other way, 45 handshakes means term 10, so 10 people. These are the triangular numbers, shifted by one place because her list starts with 1 person and 0 handshakes.

Open this example in the tool

Leo plans the seats in a sloped hall

The front rows of a hall hold 4, 9, 14, 19, 24 seats. Each row adds 5, so the rule is arithmetic: aₙ = 4 + (n − 1)·5 = 5n − 1. Row 12 holds 59 seats.

Leo wonders whether some row holds exactly 401 seats. It does not, because 401 − 4 is not a multiple of 5. The first row with more is row 81, which holds 404.

Open this example in the tool

Sam tests a puzzle that looks like doubling

A puzzle book lists 1, 2, 4, 8, 16, 31. The first five numbers alone read as doubling: the tool calls 1, 2, 4, 8, 16 geometric and predicts 32 next. The sixth number, 31, breaks that, and the fourth differences are all 1, so the rule is quartic.

an\displaystyle a_n=124n4\displaystyle {}= \frac{1}{24}n^{4}−14n3\displaystyle {}- \frac{1}{4}n^{3}+2324n2\displaystyle {}+ \frac{23}{24}n^{2}−34n\displaystyle {}- \frac{3}{4}n+1\displaystyle {}+ 1

The next term is 57. The doubling guess of 32 is not a term at all: the first term past it is term 7. This is the largest number of regions you get by joining n points on a circle with straight lines, and OEIS lists 57 after 31 too.

Open this example in the tool

Reading your result

n starts at 1. The first number you type is term 1. If your book counts from term 0, put n + 1 wherever the rule has n, or add the missing first term to your list.

The next terms are a forecast. They come from the rule that fits, and they are only right if the list keeps following it. The tool prefers the simplest rule in its order, so a list that fits a ratio is never reported as a quartic.

No simple rule can mean a typo. The primes 2, 3, 5, 7, 11, 13 get "No simple pattern", which is correct: no rule of these six kinds makes them. But type 18 in place of 17 in 2, 5, 10, 17, 26 and the first differences become 3, 5, 8, 8, with a jump where the typo sits. Read the difference table before you trust or reject a list.

Exact or decimal. A coefficient such as 0.041667 is shown as a fraction when one with a bottom of 1,000 or less matches it, here one twenty-fourth. When none does, the decimal stays, so a rule with a coefficient like 0.3 typed as 0.33 is read as it was typed.

Common mistakes

  • Trusting four terms for a cubic. Any four numbers fit some cubic exactly, so four terms cannot test one. The tool waits for five terms before it reports a cubic and six for a quartic.
  • Counting the wrong row. The degree is the number of the row that is constant, not the number of rows in the table. Constant second differences mean a quadratic.
  • Halving the second difference for every rule. The coefficient of n² is half the constant second difference only for a quadratic. For a cubic, the third difference is 6 times the coefficient of n³.
  • Mixing up the ratio and the difference. 5, 10, 20, 40, 80 has differences that double, which can look like a polynomial at first. Its ratios are all 2, and the tool reports aₙ = 5 · 2ⁿ⁻¹.

Questions people ask

Subtract each term from the next. If the answers match, it is arithmetic. If not, divide each term by the one before; matching answers mean geometric, and if neither test passes it is neither, though it may still follow a quadratic or another rule.

Sources