# Given the first $n$ terms of a sequence, can we find a function which would generate any infinite sequence we like that has the same first $n$ terms?

I was thinking about questions you sometimes see of the form

Find the next $3$ terms of the sequence $$2, 3, 5, 7, ...$$

Presumably this example would want us to find the next three prime numbers, but it occurred to me that this could also be the sequence of roots, in ascending order, of the polynomial $$(x-2)(x-3)(x-5)(x-7)...$$ in which case the answer is any three numbers I darn well feel like as long as they are greater than 7 and in ascending order.

I am wondering if there are more general ways to do this where, given $n$ terms of a sequence, I can find a function $f:\mathbb{N}\rightarrow \mathbb{N}$ such that $f(i)$ for $i\leq n$ is the $i$th term of the given sequence, and for $i>n$ it's whatever I want. Polynomial roots don't work because there are finitely many of them, and I would like my sequence to be infinite. I imagine that maybe we would have to incorporate trigonometric functions.

I tried searching around on the internet but I didn't know what to search for. Anyone know if this is a thing?

-
Have you considered to look at the similar questions here in MSE and the given answers? – Gottfried Helms Dec 5 '12 at 8:37
@GottfriedHelms I tried searching a bit but I didn't know what to search for. Can you recommend anything? – crf Dec 5 '12 at 8:38
This is a very similar question. – JSchlather Dec 5 '12 at 8:39
@JacobSchlather yes it is, thank you. I have to read a little bit about these Legrange Polynomials. I feel like that's the answer to my question. – crf Dec 5 '12 at 8:47
@crf: there are a lot of questions of this kind here. Here I've two links to answers of mine, perhaps you find them interesting, but it's just a random sample: math.stackexchange.com/questions/240115/240220#240220 math.stackexchange.com/questions/206733/207022#207022 – Gottfried Helms Dec 5 '12 at 11:12

Suppose it is given $f(i)=b_i$ for $1\leq i\leq n$. Now let us assume the function is given by a polynomial namely, $f(i)=a_1+a_2i+a_3i^2+\cdots+a_ni^{n-1}$ for all $i$. Then equating $f(i)=b_i$ for $i=1,\ldots ,n$ one can have a system of $n$ linear equation, which can be solved to get the values of $a_i$. Hence we know a function $f$ which assumes the given values at first $n$ points.

-
Awesome. Are there restrictions we need to put on the $b_i$'s to make sure that there is a solution? I guess the matrix formed by the values of $i$ has to be invertible but I'm a bit of a linear algebra noob and don't think I see what exactly that says about $i$. Is there a name for this kind of matrix—I had never thought of using this method to solve for coefficients of a polynomial before, even though in retrospect it seems simple. – crf Dec 5 '12 at 8:56
Wait actually, I might have this. Do we require that no i is equal to any other? – crf Dec 5 '12 at 9:02
@crf: Doesn't $i$ correspond to the $i$ th term of the sequence ? then how can two $i$'s be same ? The rows of the matrix are of the form $(1,i,\ldots ,i^{n-1})$ and they are linearly independent, so the matrix is invertible and surely this does not depend on the choice of $b_i$'s. – pritam Dec 5 '12 at 9:14
sorry, I meant the given $b_i$'s. But that was incorrect. I see that now, this is very cool. Thank you for your answer. – crf Dec 5 '12 at 9:16

Since you're asking about functions that take values in the natural numbers, the answer is "yes" and you can even take your function to be analytic outside of maybe a finite number of points.

Let $(a_n)$ be a sequence of natural numbers. If $a_n \to +\infty$, then there exists a holomorphic function $f$ on $\mathbb C$ such that $f(n) = a_n$. This is a theorem of Mittag-Leffler and uses somewhat sophisticated machinery of complex analysis in one variable, but nothing that isn't within reach of undergraduates.

If $a_n$ does not tend to infinity, there should still exist a meromorphic function $f$ on $\mathbb C$ that interpolates the sequence, but the proof might be a little harder.

-