# Nest function n times

A trivial example would be

f[x_]:=x
Nest[f, 7, n]


which would of course be 7 because it is independent of n, but Nest requires a machine integer for n.

A little reading took me to RsolveValue

RSolveValue[{x[n + 1] == f[x[n]], x[0] == 7}, x[n], n]


which gives me 7, hooray!

Unfortunately, if I change f:

f[x_]:=0
RSolveValue[{x[n + 1] == f[x[n]], x[0] == 7}, x[n], n]


gives me RSolveValue[{x[1 + n] == 0, x[0] == 7}, x[n], n] and the error For some branches of the general solution, the given boundary conditions lead to an empty solution

I guess it's right to complain, because my boundary condition violates the difference equation. But what I'm looking for is the answer 0

So how can I make this work?

The ultimate goal I have is finding the n'th repeated application of arbitrary operators on a given starting expression.

• "finding the n'th repeated application of arbitrary operators on a given starting expression" is exactly what Nest does, but you have to provide a value for n. Not clear what you are trying to do that is different from that. – Rohit Namjoshi Feb 26 at 14:31
• @RohitNamjoshi I am trying to find the answer for any n, i.e. an expression in terms of n – John_C Feb 26 at 14:47