# Prevent Plus from threading InterpolatingFunction

For an InterpolatingFunction $y:\ \mathbb{R}\to\mathbb{R}^2$, Plus is unaware of this, so when I do any modifications to it in an unevaluated form, it breaks the result

y = Interpolation[Table[{i, RandomReal[{0, 1}, 2]}, {i, 1, 10}]];
y[t]
y[t] + {1, 2}

(* InterpolatingFunction[{{1.,10.}},<>][t]
{1+InterpolatingFunction[{{1.,10.}},<>][t],2+InterpolatingFunction[{{1.,10.}},<>][t]} *)


I ran into it doing things like:

y = Interpolation[Table[{i, RandomReal[{0, 1}, 2]}, {i, 1, 10}]];
f[t_] := Piecewise[{{ {1, 2} + y[t], t < 5}}];
df[t_] := Evaluate[D[f[t], t]]
df[t]
df


And I can't figure out how to prevent expressions like {1,2} + y[t] from being evaluated while still being able to differentiate them. If Plus just realized that y[t] is $\mathbb{R}^2$ valued, I think that would simplify everything for me. Is there some way to set this property?

• I suppose y[t_] = {Interpolation[Table[{i, RandomReal[{0, 1}]}, {i, 1, 10}]][t], Interpolation[Table[{i, RandomReal[{0, 1}]}, {i, 1, 10}]][t]} is not what you're looking for? Nov 12 '12 at 21:13
• Started rewriting my code to split everything up like that, but was hoping for some Hold magic :)
– ssch
Nov 12 '12 at 21:23

Using the InterpolatingFunctionAnatomy package one can implement the threading explicitly.

y = Interpolation[Table[{i, RandomReal[{0, 1}, 2]}, {i, 1, 10}]];

<< DifferentialEquationsInterpolatingFunctionAnatomy

yy = Interpolation[
List, {InterpolatingFunctionGrid[y], {1, 2} + # & /@
InterpolatingFunctionValuesOnGrid[y]}],
InterpolationOrder ->
First[InterpolatingFunctionInterpolationOrder[y]]] • Nice! Trying to override Plus Unprotect[Plus]; Plus[c_List, f_InterpolatingFunction] := Interpolation[ MapThread[ List, {InterpolatingFunctionGrid[f], c + # & /@ InterpolatingFunctionValuesOnGrid[f]}], InterpolationOrder -> First[InterpolatingFunctionInterpolationOrder[f]]]; But I think I have to hunt the documentation a bit to see how to do it properly
– ssch
Nov 12 '12 at 21:31
• (Of course, if you're aware of the direct way to access those properties (e.g. y["Grid"] and y["ValuesOnGrid"]), you don't need to load the package...) Nov 12 '12 at 22:02
• @J.M. ...and there's one of those features I didn't know about. What other "properties" of InterpolatingFunction are there? Nov 12 '12 at 22:04
• It seems the answer to my question is: "Coordinates", "DerivativeOrder", "Domain", "Evaluate", "Grid", "InterpolationOrder", "MethodInformation", "Methods", "Properties", "ValuesOnGrid" Nov 12 '12 at 22:11
• @Mr.Wizard, for reference, y["Methods"] will return that list of properties supported by an InterpolatingFunction[]`. Nov 13 '12 at 16:16