arrow-left

All pages
gitbookPowered by GitBook
1 of 1

Loading...

Continued Fractions

hashtag
Continued Fractions

Continued fractions are a way of representing a number as a sum of an integer and a fraction.

Mathematically, a continued fraction is a representation

a0+b0a1+b1a2+b2β‹±a_{0} + \frac{b_{0}}{ a_{1} + \frac{b_{1}}{ a_{2} + \frac{b_{2}}{ \ddots }}}a0​+a1​+a2​+β‹±b2​​b1​​b0​​

ai,bia_{i}, b_{i}ai​,bi​are complex numbers. The continued fraction with bi=1Β βˆ€ib_{i} = 1\ \forall ibi​=1Β βˆ€i is called a simple continued fraction and continued fractions with finite number of aia_{i}ai​ are called finite continued fractions.

Consider example rational numbers,

the continued fractions could be written as

hashtag
Notation

A simple continued fraction is represented as a list of coefficients() i.e

for the above example

hashtag
Computation of simple continued fractions

Given a number , the coefficients() in its continued fraction representation can be calculated recursively using

The above notation might not be obvious. Observing the structure of continued fraction with few coefficients will make them more evident:

SageMath provides functions continued_fraction and continued_fraction_list to work with continued fractions. Below is presented a simple implementation of continued_fractions.

hashtag
Convergents of continued fraction

The convergent of a continued fractionis the numerical value or approximation calculated using the firstcoefficients of the continued fraction. The firstconvergents are

One of the immediate applications of the convergents is that they give rational approximations given the continued fraction of a number. This allows finding rational approximations to irrational numbers.

Convergents of continued fractions can be calculated in sage

Continued fractions have many other applications. One such applicable in cryptology is based on Legendre's theorem in diophantine approximations.

Theorem: if, thenis a convergent of.

Wiener's attack on the RSA cryptosystem works by proving that under certain conditions, an equation of the formcould be derived whereis entirely made up of public information andis made up of private information. Under assumed conditions, the inequalityis statisfied, and the value(private information) is calculated from convergents of(public information), consequently breaking the RSA cryptosystem.

1711=1+611116=1+5665=1+1551=5+0\frac{17}{11} = 1 + \frac{6}{11} \\[10pt] \frac{11}{6} = 1 + \frac{5}{6} \\[10pt] \frac{6}{5} = 1 + \frac{1}{5} \\[10pt] \frac{5}{1} = 5 + 01117​=1+116​611​=1+65​56​=1+51​15​=5+0
51=565=1+15116=1+56=1+165=1+11+151711=1+611=1+1116=1+11+11+15\frac{5}{1} =5 \\[10pt] \frac{6}{5} = 1 + \frac{1}{5} \\[10pt] \frac{11}{6} = 1 + \frac{5}{6} = 1 + \frac{1}{\frac{6}{5}} = 1 + \frac{1}{1 + \frac{1}{5}} \\[10pt] \frac{17}{11} = 1 + \frac{6}{11} = 1 + \frac{1}{\frac{11}{6}} = 1 + \frac{1}{1 + \frac{1}{1 + \frac{1}{5}}}15​=556​=1+51​611​=1+65​=1+56​1​=1+1+51​1​1117​=1+116​=1+611​1​=1+1+1+51​1​1​
a0+1a1+1a2+1β‹±a_{0} + \frac{1}{ a_{1} + \frac{1}{ a_{2} + \frac{1}{ \ddots }}}a0​+a1​+a2​+β‹±1​1​1​
aia_{i}ai​
x=[a0;Β a1,Β a2,Β a3,Β a4,Β a5,Β a6, …]x = [a_{0};\ a_{1},\ a_{2},\ a_{3},\ a_{4},\ a_{5},\ a_{6},\ \ldots]x=[a0​;Β a1​,Β a2​,Β a3​,Β a4​,Β a5​,Β a6​, …]
1711=[1;Β 1,Β 1,Β 5]Β Β ,116=[1;Β 1,Β 5]Β Β ,65=[1;5]Β Β ,51=[5;] \frac{17}{11} = [1;\ 1,\ 1,\ 5]\ \ ,\frac{11}{6} = [1;\ 1,\ 5]\ \ ,\frac{6}{5} = [1; 5]\ \ ,\frac{5}{1} = [5;]1117​=[1;Β 1,Β 1,Β 5]Β Β ,611​=[1;Β 1,Β 5]Β Β ,56​=[1;5]Β Β ,15​=[5;]
xxx
aia_{i}ai​
x0=xai=⌊xiβŒ‹xi+1=1xiβˆ’aix_{0} = x \\[4pt] a_{i} = \lfloor x_{i} \rfloor \\[4pt] x_{i+1} = \frac{1}{x_{i} - a_{i}}x0​=xai​=⌊xiβ€‹βŒ‹xi+1​=xiβ€‹βˆ’ai​1​
x0=a0+1a1+1a2,Β Β Β x1=a1+1a2,Β Β Β x2=a2xi=ai+1xi+1xi+1=1xiβˆ’aix_{0} = a_{0} + \frac{1}{a_{1} + \frac{1}{a_{2}}},\ \ \ x_{1} = a_{1} + \frac{1}{a_{2}}, \ \ \ x_{2} = a_{2} \\[10pt] x_{i} = a_{i} + \frac{1}{x_{i+1}} \\[10pt] x_{i+1} = \frac{1}{x_{i} - a_{i}}x0​=a0​+a1​+a2​1​1​,Β Β Β x1​=a1​+a2​1​,Β Β Β x2​=a2​xi​=ai​+xi+1​1​xi+1​=xiβ€‹βˆ’ai​1​
kthk^{th}kth
x=[a0;a1,Β a2,Β a3,Β a4,…]x = [a_{0}; a_{1},\ a_{2},\ a_{3},\ a_{4},\ldots] x=[a0​;a1​,Β a2​,Β a3​,Β a4​,…]
kβˆ’1k - 1kβˆ’1
kkk
a01,Β Β Β a0+1a1,Β Β Β a0+1a1+1a2, …,Β a0+1a1+β‹±akβˆ’2+1akβˆ’1\frac{a_{0}}{1},\ \ \ a_{0} + \frac{1}{a_{1}}, \ \ \ a_{0} + \frac{1}{a_{1} + \frac{1}{a_{2}}}, \ \ldots,\ a_{0} + \frac{1}{a_{1} + \frac{\ddots} {a_{k-2} + \frac{1}{a_{k-1}}}}1a0​​,Β Β Β a0​+a1​1​,Β Β Β a0​+a1​+a2​1​1​, …,Β a0​+a1​+akβˆ’2​+akβˆ’1​1​⋱​1​
∣xβˆ’ab∣<1b2\mid x - \frac{a}{b} \mid < \frac{1}{b^{2}}∣xβˆ’baβ€‹βˆ£<b21​
ab\frac{a}{b}ba​
xxx
∣xβˆ’ab∣\mid x - \frac{a}{b} \mid∣xβˆ’baβ€‹βˆ£
xxx
ab\frac{a}{b}ba​
∣xβˆ’ab∣<1b2\mid x - \frac{a}{b} \mid < \frac{1}{b^{2}}∣xβˆ’baβ€‹βˆ£<b21​
ab\frac{a}{b}ba​
xxx
def continued_fraction_list(xi):
    ai = floor(xi)
    if xi == ai: # last coefficient
        return [ai]
    return [ai] + continued_fraction_list(1/(x - ai))
sage: cf = continued_fraction(17/11)
sage: convergents = cf.convergents()
sage: cf
[1; 1, 1, 5]
sage: convergents
[1, 2, 3/2, 17/11]