I am using difference equations to solve SDOF systems.

I have the system $$m\ddot{y_i}+c\dot{y_i} + ky_i = x_i$$

Using the difference equation results for the derivatives, I am meant to end up with

$$y_i =(2-\frac{c\Delta t}{m}- \frac{k\Delta t^2}{m})y_{i-2}+(\frac{c\Delta t}{m} -1)y_{i-2}+\frac{\Delta t^2}{m}x_{i-1}$$

The main thing I am not understanding is how to go from $x_i$ to $x_{i-1}$ and in general the rearrangement. Is there some rule or property at work in changing the iteration step?

Also I have another system with an $y_i^3$ that ends up as a $y^3_{i-1}$ and again I am not sure how that change was made.