# Continued Fractions

# 1 Concept

x=a0+1a1+1a2+1a3+x = a_0 + \frac{1}{a_1 + \frac{1}{a_2 + \frac{1}{a_3 + \cdots}}}

Often written

x=[a0;a1,a2,a3,]x = [a_0; a_1, a_2, a_3, \ldots]

a0a_0 can be any integer, the other aia_i are positive integers.

Rationals have a terminating expansion (implicitly the next term would be \infty).

Terminating expansions represent rational numbers.

# 2 Conversion

x0xanxnxn+11xnan\begin{aligned} x_0 &\gets x \\ a_n &\gets \left\lfloor x_n \right\rfloor \\ x_{n+1} &\gets \frac{1}{x_n - a_n} \end{aligned}

# 3 Arithmetic

See:

Bill Gosper, “Continued Fraction Arithmetic”, unpublished, circa 1978 – https://perl.plover.com/yak/cftalk/INFO/gosper.txt

which also introduces continued logarithms, which have different space/time tradeoffs.