# Define a functional and nest it with its arguments

I'm looking for a definition of a functional f which works correctly with varying arguments t while it will be nested.

For example, I've the following code

f[g__[t__]] := g[t] + g[t - s]


For an input function in[t] I'll get

f[in[t]]=in[t]+in[t-s]


So far so good. But I want to nest the functional like f[f[in[t]] and I'm expecting

in[t]+2in[t-s]+in[t-2s]


as result. But what I get with the above definition is -s + 2 in[t] + 2 in[-s + t]. My application is a cascaded FIR digital filter. The output of the first FIR is the input of the next one and so on.

maybe do something like this:

f[ fn_Function ] := (fn[#] + fn[# - s]) &

f[in[#] &][t]


in[t] + in[-s + t]

f[f[in[#] &]][t]


in[t] + in[-2 s + t] + 2 in[-s + t]

The problem is that your function $f$ does not act on the number $g(t)$, it acts on the function $g$. I don't have Mathematica at hand, but

f[g_][t_]:=g[t]+g[t-s];


should work. (Note that you will need to adjust your examples as

f[in][t] (*gives in[t]+in[t-s]*)
f[f[in]][t] (*gives in[t]+2in[t-s]+in[t-2s]*)


to make them work with this definition.)

• There is a little mistake in your definition. You have swapped the argument t-s. But your solution works fine. – Drakonomikon Jun 28 '17 at 21:58
• @Drakonomikon Fixed, thanks! – Jacob Manaker Jun 29 '17 at 18:32