# Nested floor functions

I would like to compute a limit involving a particular nested floor function. For example:

Floor[x^2*Floor[x^2*Floor[x^2]]] (3 times)
Floor[x^2*Floor[x^2*Floor[x^2*Floor[x^2]]]] (4 times)
... (n times)


I don't know how to use "Nest" command in order to represent this function nested "n" times.

What each of the following will produce is an expression in x.

Nest[Floor[#*x^2] &, 1, 3]
Fold[Floor[#*x^2] &, 1, {1, 1, 1}]


So, to evaluate these expressions for some x, you'll need to do a ReplaceAll:

Nest[Floor[#*x^2] &, 1, 3] /. x -> 1.5


And furthermore, each x term will actually be x^2, making the expression even larger. In short, if you're really interested in "comput[ing] a limit", and you're hoping to approximate the limit by performing the nesting thousands of times, you might run into a recursion limit while constructing the expression (I saw failures before I hit 8000 nestings). The way to avoid this is to "precompute" x^2.

Also, based on the way you phrased your question, I'm inferring that you want an easy way to vary the parameter n (nesting depth). I'm also kind of suspicious that the exponent might be a parameter. There was really no reason to use x^2 rather than just x unless that might also be something that varies. So, you might adjust the answers previously provided to something like this:

NestedFloorProduct[base_, exp_, count_] := Nest[Floor[#*base^exp] &, 1, count]


This gives you a "function" which is what you asked for, and it also gives you control over all of the parameters.

One final thing to be aware of is that this solution will also eventually get slow if you use infinite precision (like if you set x equal to 3/2 rather than 1.5). I'm not sure how important precision is in your situation (you are Floor-ing at each step after all), but just something to be aware of.

Using Nest to get 3 nested Floor functions:

Nest[Floor[#*x^2] &, 1, 3]


You can also use Fold in the following manner

Fold[Floor[#*x^2] &, 1, {1, 1, 1}]


and a quick check

Fold[Floor[#*x^2] &, 1, {1, 1, 1}] - Floor[x^2*Floor[x^2*Floor[x^2]]]


0

Edit: for the n-case

test[xx_] := Table[1, {i, 1, xx}]


and then

fnctn[xx_] := Fold[Floor[#*x^2] &, 1, test[xx]]