As mentioned in the comments, there is no way to find a defining formula for a infinite sequence from a finite initial segment because given any finite list there are infinitely many ways to extend it.
That said, if you know ahead of time that the mystery sequence is defined by some recurrence and you know something about the structure of that recurrence, you can discover its formula.
For example: Given $a_0=1, a_1=4, a_2=9, a_3=16, \dots$ and the knowledge that our recurrence is a of the form $a_{n}=ba_{n-1}+cn+d$, we get that:
$$4=b(1)+c(0)+d, 9=b(4)+c(1)+d, \mbox{ and } 16=b(9)+c(2)+d$$
Thus $b+d=4$, $4b+c+d=9$, $9b+2c+d=16$.
Solving this (linear) system yields $b=1$, $c=2$, and $d=-1$. So that $a_n = a_{n-1}+2n-1$.
This is essentially the same process as polynomial curve fitting.
The main problem with all of this is knowing what your formula should look like to begin with. Without making some assumption about the shape of your formula, solving such a problem is hopeless (because the problem is ill defined).
Best Answer
OK, with the corrected recursion formula we get:
$$a_1=0\\ a_2=0+(2-1)=0+1\\ a_3=0+(2-1)+(3-1)=0+1+2\\ a_4=0+(2-1)+(3-1)+(4-1)=0+1+2+3\\\vdots\\ a_n=\sum_{k=0}^{n-1}k=\frac{n(n-1)}{2}$$