Is it possible to reverse engineer a function?

1k Views Asked by At

So I had a question in my mind: if given some specific no. of outputs, can you reverse engineer a function that will give you those values? For eg, if you have sequence of outputs $2, 3, 7, 17$, can you find a function that gives $f(1)=2, f(2)=3, f(3)=7, f(4)=17$?

Is it always possible to do so, or impossible to do, or should the given outputs satisfy a condition to do it systematically without guessing functions at random?

I have somewhat limited math knowledge, so I don't even know how to approach such a problem. If someone can explain it simply, that would be very much appreciated. Thanks in advance!

3

There are 3 best solutions below

2
On

Try $f(x)=\dfrac{(x-2)(x-3)(x-4)}{(1-2)(1-3)(1-4)}2+\dfrac{(x-1)(x-3)(x-4)}{(2-1)(2-3)(2-4)}3+$

$\dfrac{(x-1)(x-2)(x-4)}{(3-1)(3-2)(3-4)}7+\dfrac{(x-1)(x-2)(x-3)}{(4-1)(4-2)(4-3)}17.$

0
On

If you have integer data, in addition to polynomial interpolation which has already been mentioned, you can also search the OEIS database; this may give you polynomial as well as other types of candidate functions.

0
On

Another way to find a polynomial that gives the desired values is to look at the differences:

$\begin{matrix}\color{blue}2&\color{orange}1&3&\color{violet}3\\3&4&6&\\7&10\\17\end{matrix}$

(Here the first column has your outputs,

and each subsequent column has the differences of successive entries in the previous column.)

The last column is $\color{violet}3$. The third column is $3n$.

The second column is $\color{orange}1+3\dfrac{n(n-1)}2=1-\dfrac32n+\dfrac32n^2.$

The first column is $\color{blue}2+(n-1)-\dfrac32\dfrac{n(n-1)}2+\dfrac32\dfrac{(n-1)n(2n-1)}{6}$,

which is $1+n-\dfrac32n^2+\dfrac12n^3$.