# Trolling "Whats the next number of this sequence"

I looked at Predict next number from a series and Next number in series but I did not found the answer I was looking for.

Is it possible to construct a rule for a sequence, that generates arbitrary elements?

For example $x_1, x_2, x_3, x_4$ are given and I have to find $x_5$. Can I come up with a rule which produces $x_{1-4}$ and any possible integer for $x_5$?

• This could be relevant. Dec 15, 2014 at 7:18

In Lagrange interpolation you can create polynomials that are $1$ at one value of $x$ and $0$ at other values. For your example, we have five of them, which will be of fourth degree. We have $p_i(j)=\delta_{ij}$, where $\delta_{ij}$ is the Kroenecker delta, $1$ if $i=j$ and $0$ otherwise. Let $y_i$ be the desired value of the sequence at $x=i$. Then $y=\sum_{i=1}^5 y_ip_i$ is the polynomial you want. There are many other functions that satisfy this. You can add any number times $(x-1)(x-2)\ldots (x-5)$. Instead of polynomials you can use trig functions.
For a polynomial example $f(x)=\dfrac{y_1(x-2)}{1-2}+\dfrac{y_2(x-1)}{2-1} +\lambda(x-1)(x-2)$ This takes values $y_1,y_2$ at 1 and 2 and a value depend on $\lambda$ at 3,4,etc.
We can have $f(1)=y_1,f(2)=y_2\dots$ and so on with all the other numbers taking whatever value you want. This is not generally polynomial.
You can generate a function which generates arbitrary $x_5$ for given $x_{1-4}$ (hint- look at polynomials of a certain degree.)