Next term of the sequence?

Actually, It's 42 (why?)

Why?

What is the next term in the sequence $1, 2, 3, 4, ...$? If you say it's $5$, you're right. But if you say $42$, you are also right. Actually, if you say any number, real or complex, you are completely right.

This kind of question doesn't have a single result, or even a finite set of results. There are infinite sequences that fit into the given points. That's the point of this site: to show at least one non-trivial sequence.

Here, the next term of any given sequence will be $42$, and we'll show which function defines it.

How?

The algorithm in this site performs a curve fitting. It generates a curve (a polynomial one) that fits to the input data. This curve is found by solving a system of linear equations.

For example, let's say the user inputs the sequence $1, 2, 3, 4$. As we want the next term to be $42$, we also add it to the input. Then, we need to find a polynomial $S_n = an^4+bn^3+cn^2+dn+e$ that fits all the data. We know that if $n=1$, then $S_n=1$. Following this rationale, we have the system:

$$\begin{alignat*}{9} a & + b & + & c & +&d & +e & = & 1 \\ 16a & + 8b & + &4c & +&2d & +e & = & 2 \\ 81a & + 27b & +& 9c & +&3d & +e & = & 3 \\ 256a & + 64b & + &16c & +&4d & +e & = & 4 \\ 625a & + 125b & + &25c & +&5d & +e & = & 42 \\ \end{alignat*}$$

The algorithm then solves the system using Gaussian elimination. Initially, the system's matrix looks like this:

$$ \left[ \begin{array}{ccccc|c} 1 & 1 & 1 & 1 & 1 & 1 \\ 16 & 8 & 4 & 2 & 1 & 2 \\ 81 & 27 & 9 & 3 & 1 & 3\\ 256 & 64 & 16 & 4 & 1 & 4\\ 625 & 125 & 25 & 5 & 1 & 42\\ \end{array} \right] $$

But after the Gaussian elimination, we'll have a matrix like this:

$$ \left[ \begin{array}{ccccc|c} 1 & 0 & 0 & 0 & 0 & ^{37}/_{24} \\ 0 & 1 & 0 & 0 & 0 & ^{-185}/_{12} \\ 0 & 0 & 1 & 0 & 0 & ^{1295}/_{24}\\ 0 & 0 & 0 & 1 & 0 & ^{-913}/_{12}\\ 0 & 0 & 0 & 0 & 1 & 37\\ \end{array} \right] $$

This result shows that if $S_{n}=\frac{37}{24} n^{4}-\frac{185}{12} n^{3}+\frac{1295}{24} n^{2}-\frac{913}{12} n+37$ then $S_n$ will fit to all the given points. See it in action.

Loading

Actually, It's 42 is a proof-of-concept created by Juan Lopes.

It has a highly messy javascript code. Feel free to mess around.