I am working with a recursive algorithm and I have realized that in each step it computes something equivalent to:
$A_{0}=\frac{a}{b}$
$A_{1}=a/(b-\frac{a^{2}}{b})$
$A_{2}=a/(b-\frac{a^{2}}{b-\frac{a^{2}}{b}})$
$\vdots$
$A_{n+1}=a/(b-aA_{n})$
And so on. I was wondering if there could exist some closed form for $A_{n}$ to avoid unnecessary iterations
The closed form does exist, I found it with Mathematica and it's amazing, to use in a program I mean.
I found it with this function
Set: $$ \begin{cases} D=\sqrt{b^2-4 a^2}\\ x=\frac{b-D}{a}\\ y=\frac{b+D}{a}\\ \end{cases} $$ Then $$A_n=\frac{a (b+D ) y^n-a (b-D ) x^n}{x^n \left(2 a^2-b (b-D )\right)+y^n \left(b (b+D )-2 a^2\right)}$$
You will surely find a way to optimize better this formula in order to use it in a program.
Edit
This is the formula as output by Mathematica $$A_n=\frac{a \left(b \left(\frac{\sqrt{b^2-4 a^2}+b}{a}\right)^n+\sqrt{b^2-4 a^2} \left(\frac{\sqrt{b^2-4 a^2}+b}{a}\right)^n+(-b) \left(-\frac{\sqrt{b^2-4 a^2}-b}{a}\right)^n+\sqrt{b^2-4 a^2} \left(-\frac{\sqrt{b^2-4 a^2}-b}{a}\right)^n\right)}{-2 a^2 \left(\frac{\sqrt{b^2-4 a^2}+b}{a}\right)^n+b^2 \left(\frac{\sqrt{b^2-4 a^2}+b}{a}\right)^n+b \sqrt{b^2-4 a^2} \left(\frac{\sqrt{b^2-4 a^2}+b}{a}\right)^n-b^2 \left(-\frac{\sqrt{b^2-4 a^2}-b}{a}\right)^n+2 a^2 \left(-\frac{\sqrt{b^2-4 a^2}-b}{a}\right)^n+b \sqrt{b^2-4 a^2} \left(-\frac{\sqrt{b^2-4 a^2}-b}{a}\right)^n}$$