You have a black box function to which you can give real number inputs and from which you can receive real number outputs. How would you test whether it is likely to be a polynomial?
One expensive idea is to use finite differences:
- Choose a maximum degree n of the "polynomial" you are testing.
- Choose a consecutive sequence with random step size, and evaluate the function there to get an output sequence. E.g., $$[ 2, 2.3, 2.6, 2.9,\dots] \to [ 4.81, 5.02, 5.05, 4.90,\dots]$$
- Using the output sequence as S[0], define S[n] so that its k^th entry S[n][k] = S[n-1][k+1]-S[n-1][k]. E.g. S[1] = [5.02-4.81,5.05-5.02,4.90-5.05,...] = [0.21,0.03,-0.15,...]
- If the function is a polynomial (of degree at most n), then the sequence S[n+1] should be all zeros.
Some issues about programming this method:
- Would be expensive for large n
- If S[0] has large values, computer arithmetic will produce bad results for S[1] and beyond.
I think the largest problem here is that given things like Taylor series, every function can eventually be closely approximated as a polynomial. As such, even a finite range of measured outputs of a blackbox representing a sine function will might yield a polynomial. Measuring a large range is computationally difficult as higher powers tend to yield very large values for increasing inputs. Anyway, this is what I would do: Suppose you an input set $x\in \mathbb{R}^{n+1\times1}$ and the corresponding output set $S\in \mathbb{R}^{n+1\times1}$, where $n$ is the estimated polynomial order (or better, larger than). Then the polynomial itself can be estimated as follows:
If the black box does represent a perfect polynomial, the resulting $A$ vector should be unique and every entry with a higher order than this polynomial should be a flat zero (or approaching floating precision). The uniqueness can be verified by plugging in various different input sets.
This method can become just as troublesome for very large orders of $n$ and can yield just an estimated Taylor series of the function (at least I tested it with a sine function and it did return the Taylor series expansion of it, where the even powers had a parameters smaller than $1e^{-7}$).