Also, let \(\displaystyle D_n\) be the debt amount after payment \(n\).

Consider the recursion:

(1) \(\displaystyle D_{n}=(1+i)D_{n-1}-P\)

(2) \(\displaystyle D_{n+1}=(1+i)D_{n}-P\)

Subtracting (1) from (2) yields the homogeneous recursion:

\(\displaystyle D_{n+1}=(2+i)D_{n}-(1+i)D_{n-1}\)

whose associated auxiliary equation is:

\(\displaystyle r^2-(2+i)r+(1+i)=0\)

\(\displaystyle \left(r-(1+i)\right)\left(r-1\right)=0\)

Thus, the closed-form for our recursion is:

\(\displaystyle D_n=k_1(1+i)^n+k_2\)

Using initial values, we may determine the coefficients \(\displaystyle k_i\):

\(\displaystyle D_0=k_1+k_2=A\)

\(\displaystyle D_1=k_1(1+i)+k_2=(1+i)A-P\)

Solving this system, we find:

\(\displaystyle k_1=\frac{Ai-P}{i},\,k_2=\frac{P}{i}\) and so we have:

\(\displaystyle D_n=\left(\frac{Ai-P}{i}\right)(1+i)^n+\left(\frac{P}{i}\right)=\frac{(Ai-P)(1+i)^n+P}{i}\)

Now, equating this to zero, we can solve for P:

\(\displaystyle \frac{(Ai-P)(1+i)^n+P}{i}=0\)

\(\displaystyle (Ai-P)(1+i)^n+P=0\)

\(\displaystyle (P-Ai)(1+i)^n=P\)

\(\displaystyle P\left((1+i)^n-1\right)=Ai(1+i)^n\)

\(\displaystyle P=\frac{Ai(1+i)^n}{(1+i)^n-1}\)

\(\displaystyle P=\frac{Ai}{1-(1+i)^{-n}}\)