# Printing a Solved Recurrence at Arbitrary Values

The code below solves the recurrence $$a_{n+1} = a_{n}d - a_{n-1} + 2 - d$$ where $a_{0} = d^2$ and $a_{1} = d^3 - 2d + 1$. The recurrence is solved as I expect it to be solved.

RSolve[{(a[n+1] - a[n]d + a[n - 1]) == 2 - d,a[1] == d^3 - 2 (d) + 1,a[0] == d^2},a[n],n]


I want to print certain values of this recurrence (by value, I mean print $a[m]$ for arbitrary $m$) and manipulate certain values of this recurrence. The code below prints the first 10 entries (I just copied it from wolfram.reference, and I am not sure what %[[1]] does).

TraditionalForm[Table[Together[a[n]/. %[[1]]], {n, 0, 10}]]


I want to be able to print certain entries (say $a[1]$ to $a[9]$) as well as print $a[0] + 1 - d$ to $a[8] + 1 - d$.

RSolve[{(a[n+1] - a[n]d + a[n - 1]) == 2 - d,a[1] == d^3 - 2 (d) + 1,a[0] == d^2},a[n],n]

TraditionalForm[Table[Together[a[n]/. %[[1]]], {n, 0, 10}]]

For[i=1, i<10, i++, Print[Together[a[i]]];Print[Together[a[i-1] + 1 - d]]; Print[ ]].


The last of these lines gives me

a[1]
1-d+a[0]

a[2]
1-d+a[1]

a[3]
1-d+a[2]
a[4]


whereas I expect

d^3 - 2d + 1
d^2 - d + 1

d^4 -3d^2 + 2
d^3 - 3d + 2

d^5 - 4d^3 +3d+1
d^4 -3d^2 - d + 3


Clear[a, d, f, n]

f[d_, n_] =
Simplify[a[n] /.
RSolve[{(a[n + 1] - a[n] d + a[n - 1]) == 2 - d,
a[1] == d^3 - 2 d + 1, a[0] == d^2}, a[n], n][[1]]];


To get a table

{#, f[d, #], f[d, # - 1] + 1 - d} & /@ Range[10] //
Simplify //
Grid[#, Frame -> All, Alignment -> Left] & //


Or a plot

Plot3D[f[d, n], {d, -2, 4}, {n, -10, 10},
PlotRange -> {-10, 10},
PlotPoints -> 50,
ClippingStyle -> None]


This

Clear[a];
a[n_] := Evaluate[a[n] /. RSolve[{(a[n+1]-a[n] d+a[n-1])==2-d,
a[1] == d^3 - 2 (d) + 1, a[0] == d^2}, a[n], n][[1, 1]]]


followed by

{a[0], a[1], a[2], a[3]} // Simplify


or even

TraditionalForm[Table[Together[a[n]], {n, 0, 10}]]