Finding the closed form of a recursive sequence

I am looking mostly for keywords, to search and study on examples and techniques on how one goes on finding the closed form expression on a recursive sequence.

I have a problem to solve, which looks like

$${ a_{n+1} = \frac{ma_n + x}{a_n + y} }$$

(I am not writing the exact values, because I am not looking for a solution, just guidance.)

I have seen a solution here, which is amazing, but I do not understand how one thinks about it.


This is a first-order rational difference equation (have a look here).

$${ a_{n+1} = \frac{ma_n + x}{a_n + y} }=m+\frac{x-m y}{a_n+y}$$ Let $b_n=a_n-m$ to make $$\frac{m y-x}{b_n+m+y}+b_{n+1}=0$$ Let $c_n=b_n+m+y$ to make $$\frac{m y-x}{c_n}+c_{n+1}=m+y$$ Let $p=m y-x$ and $q=m+y$ to make $$\frac{p}{c_n}+c_{n+1}=q$$

If you follow the steps given in the linked page, you should get coething like $$c_n=\frac{A_n}{B_n}$$ with $$A_n=K \left(q^2-2 p\right) \left(\frac{\sqrt{q^2-4 p}-q}{p}\right)^n-K q \sqrt{q^2-4 p} \left(\frac{\sqrt{q^2-4 p}-q}{p}\right)^n+\left(q^2-2 p\right) \left(-\frac{\sqrt{q^2-4 p}+q}{p}\right)^n+q \sqrt{q^2-4 p} \left(-\frac{\sqrt{q^2-4 p}+q}{p}\right)^n$$ and $$B_n=\sqrt{q^2-4 p} \left(\left(-\frac{\sqrt{q^2-4 p}+q}{p}\right)^n-K \left(\frac{\sqrt{q^2-4 p}-q}{p}\right)^n\right)+q \left(K \left(\frac{\sqrt{q^2-4 p}-q}{p}\right)^n+\left(-\frac{\sqrt{q^2-4 p}+q}{p}\right)^n\right)$$