# Using a function inside a recurrence table index

I have a recurrence relation with a complicated index pattern. However, even simple examples fail. For example, consider

RecurrenceTable[{a[n + 1] == a[n - Floor[Sqrt[n]]], a[0] == 1}, a, {n, 0, 10}]


This gives the error

"All arguments in position 1 of a[1+n]==a[n-Floor[Sqrt[n]]] should be in the form n + integer."


When I look at the type for Floor[Sqrt[n]], Mathematica tells me it is an integer, but it doesn't seem to recognize n-Floor[Sqrt[n]] as an integer. How can I use a function like Floor inside the indices for a recurrence table?

• Isn't the answer just a[n]=1 for all n? – bill s Aug 11 '17 at 18:26
• It might be for this one. This is just an simple example to see the error. – Trevor Aug 11 '17 at 18:27

## 1 Answer

I would not use RecurrenceTable for this... just define it recursively:

a[n_] := a[n - 1 - Floor[Sqrt[n - 1]]];
a[0] = 1;


You can verify that for this particular recursion, a[n]=1 for any n you care to chose. To see why RecurrenceTable does not work, note that the help says: "The eqns can involve objects of the form a[n+i] where i is any fixed integer." In this case, i is an integer, but it is not fixed.

• This is a classic example of something not working until I ask about it. I did try what you suggested based on another answer, but I must have typed something wrong somewhere. It worked this time. The question still remains about why it won't work within RecurrenceTable. – Trevor Aug 11 '17 at 18:35
• Looking at the help for RecurrenceTable, it says: "The eqns can involve objects of the form a[n+i] where i is any fixed integer." In your case, i is an integer, but it is not fixed. – bill s Aug 11 '17 at 18:44
• @bills I'd include the contents of your last comment in your answer, as it seems very relevant to the original question as it had been posed. – MarcoB Aug 11 '17 at 20:26