2

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.

martin
  • 8,678
  • 4
  • 23
  • 70

2 Answers2

4

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]]]]]
Kris
  • 543
  • 2
  • 10
1
Last @ Nest[{ #[[1]] - 1,  f1[ ff[ #[[1]], #[[2]] ] ] } &,
            {n, list}, 
            3]
f1[ff[-2 + n, f1[ff[-1 + n, f1[ff[n, list]]]]]]
Kuba
  • 136,707
  • 13
  • 279
  • 740