# Trouble with RecurrenceTable using elements from a previously computed list

When I use RecurrenceTable to solve a recursion relations, I encounter a problem, which is perhaps simple, but I do not understand why it is complaining. Here is a simple example. First, let's create a list

alist = Table[2^i, {i, 1, 100}]


and next evaluate

RecurrenceTable[{b[n] == alist[[n]] + b[n - 1], b[1] == 2}, b, {n, 1, 10}]


Then the results are

Part::pkspec1: The expression n cannot be used as a part specification. >>
Part::pkspec1: The expression 1+n cannot be used as a part specification. >>
Part::pkspec1: The expression 1+#1 cannot be used as a part specification. >>
General::stop: Further output of Part::pkspec1 will be suppressed during this calculation. >>

{2, 6, 14, 30, 62, 126, 254, 510, 1022, 2046}


Does anyone know where things go wrong and how to solve it?

In general I would like to know how to use the ReccurenceTable when the recursion relation depends on values from another precomputed list.

It appears that RecurrenceTable does some symbolic processing that leads to the unevaluated symbol n being given to Part as its 2nd argument. But Part only accepts integers as its 2nd argument. A work-around is:

Do[a[i] = 2^i, {i, 1, 10}]
RecurrenceTable[{b[n] == a[n] + b[n - 1], b[1] == 2}, b, {n, 1, 10}]


{2, 6, 14, 30, 62, 126, 254, 510, 1022, 2046}

• Thank you. Maybe I am using a earlier version of Mathematica. When I evaluate the code in your answer, it has the same problem! – Wenzhe May 11 '19 at 1:40
• @Wenzhe. What do you by "it has the same problem"?. There is no way my cod can produce an error message from Part. It make no use of Part. – m_goldberg May 11 '19 at 3:31
• Thank you. I shut down Mathematica and restart it, and the problem disappears. It works now. – Wenzhe May 11 '19 at 3:52
• Table[2^n - 2, {n, 2, 11}] – Gilmar Rodriguez Pierluissi Oct 25 '19 at 15:12