ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 19 Dec 2018 17:05:54 -0600How to import functions to program?https://ask.sagemath.org/question/44713/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 ..
Wed, 19 Dec 2018 14:26:09 -0600https://ask.sagemath.org/question/44713/how-to-import-functions-to-program/Answer by slelievre for <p>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?</p>
<p>I found class sage.rings.continued_fraction.ContinuedFraction_base
Bases: sage.structure.sage_object.SageObject</p>
<p>However when trying something like import, it doesn't work ..</p>
https://ask.sagemath.org/question/44713/how-to-import-functions-to-program/?answer=44715#post-id-44715Here 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.Wed, 19 Dec 2018 17:05:54 -0600https://ask.sagemath.org/question/44713/how-to-import-functions-to-program/?answer=44715#post-id-44715