# Is it possible to find a function from first few terms in the expansion

Is it possible to find a function if first few terms of the expansion is known. For example if I have this series $f(x)=\frac{k^3 x^2}{6}-\frac{k^5 x^4}{120}+\frac{k^7 x^6}{5040}-\frac{k^9 x^8}{362880}+\frac{k^{11} x^{10}}{39916800}+\cdots$, is it possible to find what would be the full function? (answer: $k- \sin(kx)/x$).

One suggestion I find for a problem close to this is to use GeneratingFunction, but for that It is necessary to know the form the $n^\text{th}$ term in terms of the exponent of different variable which is often quite difficult. What I am looking for is an algorithm which can guess a possible form of the full function if first few terms are given.

FindSequenceFunction and FindGeneratingFunction can do this. They won't immediately work every time. This is what I did:

First notice that if we find $f(x)$ for $k=1$ then the solution for arbitrary $k$ is just $k \,f(kx)$.

Then, write the coefficients into a list ...

coeffs = {0, 1/6, 0, -1/120, 0, 1/5040, 0, -1/362880, 0, 1/39916800}


... and try FindGeneratingFunction and FindSequenceFunction on it. It doesn't give a result in Mathematica 9.

So I tried to simplify the sequence by taking out the $n!$ from the expansion, removing the interleaved zeros and the alternating signs.

First step, remove the $n!$ part:

coeffs (Range@Length[coeffs]!)

(* ==> {0, 1/3, 0, -(1/5), 0, 1/7, 0, -(1/9), 0, 1/11} *)


At this point it's already clear that we can stop. The pattern is obvious:

((1 + (-1)^n) (-1)^(n/2 + 1))/(2 (n + 1) (n!))


If this were not obvious by looking at the sequence, I'd try FindSequenceFunction again.

This pattern is valid for $n \ge 1$, but not for $n=0$. That'll be easy to correct for later though. Now we can use GeneratingFunction:

GeneratingFunction[((1 + (-1)^n) (-1)^(n/2 + 1))/(2 (n + 1) (n!)), n, x]

(* ==> 1/2 ((I (-1 + E^(I x)))/x + (I E^(-I x) (-1 + E^(I x)))/x) *)

FullSimplify[%]

(* ==> -Sin[x]/x *)


We need to correct for the order 0 term associated with $n=0$. This is $-1$ so we just add 1 to the result:

$$f(x) = 1 - (\sin x)/x$$