# General question

For a function f[n, a], where a is a list and n is a whole number, what is the correct syntax for

f[n - 5, f[n - 4, f[n - 3, f[n - 2, f[n - 1, f[n, a]]]]]]


?

# Update

All I want to do is

fg[n_, w_] := f1@ff[n, w]
fg[n - 2, fg[n - 1, fg[n, list]]]


as shown above, which works, but I am having to manually write out n-3,n-2,n-1,...

Have tried

fg[n_][w_] := f1@ff[n, w]
NestList[fg[n], list, 3]


but doesn't quite work. I think it needs a #-1 in there somewhere, that is applied to the n, but not sure on syntax.

• Wait ... do you need help with NestList[] or with that code? Nov 18 '14 at 20:57
• @martin I'm also having trouble understanding what you're trying to do here..
– Kris
Nov 18 '14 at 21:00
• @belisarius It is just the last line I need help with - the fg[n - 2, fg[n - 1, fg[n, list]]] bit Nov 18 '14 at 21:05
• @Kris please see update Nov 18 '14 at 21:07
• Nest[fg[#[[1]] - 1, fg @@ ##] &, {n, list}, 2] Nov 18 '14 at 21:13

Last @ Nest[{ #[[1]] - 1,  f1[ ff[ #[[1]], #[[2]] ] ] } &,
{n, list},
3]

f1[ff[-2 + n, f1[ff[-1 + n, f1[ff[n, list]]]]]]

• Great - thank you - I was really struggling there! Nov 18 '14 at 22:03
• ok changed as advised :) Nov 18 '14 at 22:13

Could it be that you're looking for the function Fold rather than Nest?

Fold[f[n - #2, #1] &, a, Range[5]]

f[-5 + n, f[-4 + n, f[-3 + n, f[-2 + n, f[-1 + n, a]]]]]

• +1, maybe better Fold[g[#2, #] &, a, Range[n, n - 2, -1]].
– Kuba
Nov 19 '14 at 12:09
• @Kuma Thanks, I agree that a one-liner is nicer. I updated the answer
– Kris
Nov 19 '14 at 13:52