Ask Your Question

Revision history [back]

Here is an example:

sage: a = 26 / 7
sage: c = continued_fraction(a)
sage: c
[3; 1, 2, 2]

From there one can explore the convergents:

sage: c.convergent(0)
3
sage: c.convergent(1)
4
sage: c.convergent(2)
11/3
sage: c.convergent(3)
26/7

The numerator and denominator of a convergent can be called using the methods numerator and denominator or p and q.

sage: c.numerator(2)
11
sage: c.denominator(2)
3
sage: c.p(2)
11
sage: c.q(2)
3

One can also start from a list:

sage: c = continued_fraction([3, 1, 2, 2])
sage: c
[3; 1, 2, 2]

etc.