Finite simple continued fractions¶
Sage implements the field ContinuedFractionField
(or CFF
for short) of finite simple continued fractions. This is really
isomorphic to the field \(\QQ\) of rational numbers, but with different
printing and semantics. It should be possible to use this field in
most cases where one could use \(\QQ\), except arithmetic is much slower.
EXAMPLES:
We can create matrices, polynomials, vectors, etc., over the continued fraction field:
sage: a = random_matrix(CFF, 4)
doctest:...: DeprecationWarning: CFF (ContinuedFractionField) is deprecated, use QQ instead
See http://trac.sagemath.org/20012 for details.
sage: a
[ [-1; 2] [-1; 1, 94] [0; 2] [-12]]
[ [-1] [0; 2] [-1; 1, 3] [0; 1, 2]]
[ [-3; 2] [0] [0; 1, 2] [-1]]
[ [1] [-1] [0; 3] [1]]
sage: f = a.charpoly()
doctest:...: DeprecationWarning: CFF (ContinuedFractionField) is deprecated, use QQ instead
See http://trac.sagemath.org/20012 for details.
sage: f
[1]*x^4 + ([-2; 3])*x^3 + [14; 1, 1, 1, 9, 1, 8]*x^2 + ([-13; 4, 1, 2, 1, 1, 1, 1, 1, 2, 2])*x + [-6; 1, 5, 9, 1, 5]
sage: f(a)
[[0] [0] [0] [0]]
[[0] [0] [0] [0]]
[[0] [0] [0] [0]]
[[0] [0] [0] [0]]
sage: vector(CFF, [1/2, 2/3, 3/4, 4/5])
([0; 2], [0; 1, 2], [0; 1, 3], [0; 1, 4])
AUTHORS:
- Niles Johnson (2010-08):
random_element()
should pass on*args
and**kwds
(trac ticket #3893).
-
class
sage.rings.contfrac.
ContinuedFractionField
¶ Bases:
sage.structure.unique_representation.UniqueRepresentation
,sage.rings.ring.Field
The field of rational implemented as continued fraction.
The code here is deprecated since in all situations it is better to use
QQ
.See also
EXAMPLES:
sage: CFF QQ as continued fractions sage: CFF([0,1,3,2]) [0; 1, 3, 2] sage: CFF(133/25) [5; 3, 8] sage: CFF.category() Category of fields
The continued fraction field inherits from the base class
sage.rings.ring.Field
. However it was initialised as such only since trac ticket trac ticket #11900:sage: CFF.category() Category of fields
-
class
Element
(x1, x2=None)¶ Bases:
sage.rings.continued_fraction.ContinuedFraction_periodic
,sage.structure.element.FieldElement
A continued fraction of a rational number.
EXAMPLES:
sage: CFF(1/3) [0; 3] sage: CFF([1,2,3]) [1; 2, 3]
-
ContinuedFractionField.
an_element
()¶ Returns a continued fraction.
EXAMPLES:
sage: CFF.an_element() [-1; 2, 3]
-
ContinuedFractionField.
characteristic
()¶ Return 0, since the continued fraction field has characteristic 0.
EXAMPLES:
sage: c = CFF.characteristic(); c 0 sage: parent(c) Integer Ring
-
ContinuedFractionField.
is_exact
()¶ Return True.
EXAMPLES:
sage: CFF.is_exact() True
-
ContinuedFractionField.
is_field
(proof=True)¶ Return True.
EXAMPLES:
sage: CFF.is_field() True
-
ContinuedFractionField.
is_finite
()¶ Return False, since the continued fraction field is not finite.
EXAMPLES:
sage: CFF.is_finite() False
-
ContinuedFractionField.
order
()¶ EXAMPLES:
sage: CFF.order() +Infinity
-
ContinuedFractionField.
random_element
(*args, **kwds)¶ Return a somewhat random continued fraction (the result is either finite or ultimately periodic).
INPUT:
args
,kwds
- arguments passed toQQ.random_element
EXAMPLES:
sage: CFF.random_element() # random [0; 4, 7]
-
ContinuedFractionField.
some_elements
()¶ Return some continued fractions.
EXAMPLES:
sage: CFF.some_elements() ([0], [1], [1], [-1; 2], [3; 1, 2, 3])
-
class