# Interpolating functions and Look-up tables

This is just a general question about how InterpolatingFunctions work:

If I have a complicated function that I don't want to have to evaluate many times over, does turning it into an InterpolatingFunction make it behave more like a lookup table, or will every call to an InterpolatingFunction still have to do a complicated calculation?

Does adding NumericQ to the argument of this function have an effect on this aspect of its behavior?

• "...does turning it into an InterpolatingFunction make it behave more like a lookup table?" - more or less; the function will use piecewise polynomials to "connect the dots". Commented Jul 26, 2016 at 15:25

I ran a simple scenario:

func[x_] := x^3

AbsoluteTiming[func[192999292992292992];]
Output: {0.000019737327747406418, Null}

AbsoluteTiming[func[155];]
Output: {9.47391731875508*^-6, Null}

pts = Table[{i, func[i]}, {i, 1, 200}];
intfunc = Interpolation[pts];

AbsoluteTiming[intfunc[192999292992292992];]
Output: {0.005909355927573481, Null}

AbsoluteTiming[intfunc[155];]
Output: {0.00004500110726408663, Null}

So as you can see, using the original function should take a shorter time, especially when the Interpolation has to extrapolate data.

Of course, I don't know how complex your function is, so try running an AbsoluteTiming on both cases if you're curious.

• Well sure, for a simple polynomial function, Interpolation[] is slow; that's not what it's really intended for. More illustrative would be to use a (complicated) transcendental function. Commented Jul 26, 2016 at 17:47
• The function has a polynomial in the numerator and the denominator is a sum of terms that have polynomial exponents. The InterpolatingFunction appears to be about 50 times faster. Thanks! Commented Jul 26, 2016 at 18:10
• @basementDweller Is accuracy at all a concern, or only speed? Commented Jul 27, 2016 at 2:36
• @MichaelE2 Right now speed is more important, but obviously I don't want to scrap accuracy altogether...Why do you ask? Commented Jul 27, 2016 at 17:34
• @basementDweller InterpolatingFunction will usually be fast, slowing down somewhat as the InterpolationOrder (degree of the polynomials used) increases and as the number of interpolation nodes/points increases, but one does not usually need to sacrifice accuracy for speed here. There are a few methods for constructing an IF, depending on the function, FunctionInterpolation[] and NDSolve[] being common. See, for instance, this, this, or this. Commented Jul 27, 2016 at 20:09