# How to import functions to program?

Hello, Sory for stupid question. Im new to sage and I would like to import a class/base that will allow me to use convergent() and numerator() functions. How could I do that?

I found class sage.rings.continued_fraction.ContinuedFraction_base Bases: sage.structure.sage_object.SageObject

However when trying something like import, it doesn't work ..

edit retag close merge delete

Sort by » oldest newest most voted

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.

more