<s>[INST] Find sequence function and general rule the function $$a_{n+2}=3a_{n+1}-2a_n+2$$
is given, and $$a_0=a_1=1, (a_n)_{n\ge0}$$
multiplying everything by $$/\sum_{n=0}^\infty x^{n+2}$$
also adding $$\sum_{n=0}^\infty (a_{n+2}x^{n+2}+a_1x+a_0)-a_1x-a_0=\sum_{n=0}^\infty (3a_{n+1}x^{n+2}+a_0)-a_0-\sum_{n=0}^\infty 2a_nx^{n+2}+\sum_{n=0}^\infty 2x^{n+2}$$
we get $$R(X)-2x-1=3x(R(X)-1)-2x^2R(X)+\frac{2x^2}{1-x}$$
$$R(X)(1-3x+2x^2)+x-1=\frac{2x^2}{1-x}$$
$$R(X)(1-3x+2x^2)=\frac{3x^2-2x+1}{1-x}$$
$$R(X)=\frac{3x^2-2x+1}{(1-x)^2(1-2x)}=\frac{A}{(1-x)^2}+\frac{B}{1-2x}$$
so $$3x^2-2x+1=A(1-2x)+B(1-x)^2$$
$$3x^2-2x+1=x^2(B)+x(-2A-2B)+A+B$$
B=3
-2A-2B=-2
A+B=1$$\quad\Longrightarrow\quad A=-2, B=3$$
$$R(X)=\frac{-2}{(1-x)^2}+\frac{3}{1-2x}=-2\sum_{n=0}^\infty nx^{n-1}+3\sum_{n=0}^\infty (2x)^2=$$
how to proceed?
 [/INST] The generating function I'm getting is:
$
\begin{align}
R(x) &= \dfrac{1-3\, x+4\, x^2}{1-4\, x+5\, x^2-2\, x^3}\\
 &= \dfrac{2}{1-2 \, x} + \dfrac{1}{1-x} - \dfrac{2}{{\left(1-x\right)}^{2}}\\
 &= \sum_{n\ge 0} \left(2^{n+1}-2\, n-1\right)\, x^n
\end{align}
$
</s>