Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
15714: cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
rwst committed Jun 6, 2015
1 parent a31adf7 commit a0aba76
Showing 1 changed file with 70 additions and 70 deletions.
140 changes: 70 additions & 70 deletions src/sage/rings/cfinite_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,86 +170,86 @@ def CFiniteSequences(base_ring, names = None, category = None):

class CFiniteSequence(FieldElement):
r"""
Create a C-finite sequence given its ordinary generating function.
Create a C-finite sequence given its ordinary generating function.
INPUT:
- ``ogf`` -- a rational function, the ordinary generating function
(can be a an element from the symbolic ring, fraction field or polynomial
ring)
OUTPUT:
- A CFiniteSequence object
EXAMPLES::
sage: CFiniteSequence((2-x)/(1-x-x^2)) # the Lucas sequence
C-finite sequence, generated by (-x + 2)/(-x^2 - x + 1)
sage: CFiniteSequence(x/(1-x)^3) # triangular numbers
C-finite sequence, generated by x/(-x^3 + 3*x^2 - 3*x + 1)
INPUT:
Polynomials are interpreted as finite sequences, or recurrences of degree 0::
- ``ogf`` -- a rational function, the ordinary generating function
(can be a an element from the symbolic ring, fraction field or polynomial
ring)
sage: CFiniteSequence(x^2-4*x^5)
Finite sequence [1, 0, 0, -4], offset = 2
sage: CFiniteSequence(1)
Finite sequence [1], offset = 0
OUTPUT:
This implementation allows any polynomial fraction as o.g.f. by interpreting
any power of `x` dividing the o.g.f. numerator or denominator as a right or left shift
of the sequence offset::
- A CFiniteSequence object
sage: CFiniteSequence(x^2+3/x)
Finite sequence [3, 0, 0, 1], offset = -1
sage: CFiniteSequence(1/x+4/x^3)
Finite sequence [4, 0, 1], offset = -3
sage: P = LaurentPolynomialRing(QQ.fraction_field(), 'X')
sage: X=P.gen()
sage: CFiniteSequence(1/(1-X))
C-finite sequence, generated by 1/(-X + 1)
EXAMPLES::
The o.g.f. is always normalized to get a denominator constant coefficient of `+1`::
sage: CFiniteSequence((2-x)/(1-x-x^2)) # the Lucas sequence
C-finite sequence, generated by (-x + 2)/(-x^2 - x + 1)
sage: CFiniteSequence(x/(1-x)^3) # triangular numbers
C-finite sequence, generated by x/(-x^3 + 3*x^2 - 3*x + 1)
sage: CFiniteSequence(1/(x-2))
C-finite sequence, generated by -1/2/(-1/2*x + 1)
Polynomials are interpreted as finite sequences, or recurrences of degree 0::
The given ``ogf`` is used to create an appropriate parent: it can
be a symbolic expression, a polynomial , or a fraction field element
as long as it can be coerced into a proper fraction field over the
rationals::
sage: CFiniteSequence(x^2-4*x^5)
Finite sequence [1, 0, 0, -4], offset = 2
sage: CFiniteSequence(1)
Finite sequence [1], offset = 0
sage: var('x')
x
sage: f1 = CFiniteSequence((2-x)/(1-x-x^2))
sage: P.<x> = QQ[]
sage: f2 = CFiniteSequence((2-x)/(1-x-x^2))
sage: f1 == f2
True
sage: f1.parent()
The ring of C-Finite sequences in x over Rational Field
sage: f1.ogf().parent()
Fraction Field of Univariate Polynomial Ring in x over Rational Field
sage: CFiniteSequence(log(x))
Traceback (most recent call last):
...
TypeError: unable to convert log(x) to a rational
This implementation allows any polynomial fraction as o.g.f. by interpreting
any power of `x` dividing the o.g.f. numerator or denominator as a right or left shift
of the sequence offset::
sage: CFiniteSequence(x^2+3/x)
Finite sequence [3, 0, 0, 1], offset = -1
sage: CFiniteSequence(1/x+4/x^3)
Finite sequence [4, 0, 1], offset = -3
sage: P = LaurentPolynomialRing(QQ.fraction_field(), 'X')
sage: X=P.gen()
sage: CFiniteSequence(1/(1-X))
C-finite sequence, generated by 1/(-X + 1)
The o.g.f. is always normalized to get a denominator constant coefficient of `+1`::
sage: CFiniteSequence(1/(x-2))
C-finite sequence, generated by -1/2/(-1/2*x + 1)
The given ``ogf`` is used to create an appropriate parent: it can
be a symbolic expression, a polynomial , or a fraction field element
as long as it can be coerced into a proper fraction field over the
rationals::
sage: var('x')
x
sage: f1 = CFiniteSequence((2-x)/(1-x-x^2))
sage: P.<x> = QQ[]
sage: f2 = CFiniteSequence((2-x)/(1-x-x^2))
sage: f1 == f2
True
sage: f1.parent()
The ring of C-Finite sequences in x over Rational Field
sage: f1.ogf().parent()
Fraction Field of Univariate Polynomial Ring in x over Rational Field
sage: CFiniteSequence(log(x))
Traceback (most recent call last):
...
TypeError: unable to convert log(x) to a rational
TESTS::
TESTS::
sage: P.<x> = QQ[]
sage: CFiniteSequence(0.1/(1-x))
C-finite sequence, generated by 1/10/(-x + 1)
sage: CFiniteSequence(pi/(1-x))
Traceback (most recent call last):
...
TypeError: unable to convert -pi to a rational
sage: P.<x,y> = QQ[]
sage: CFiniteSequence(x*y)
Traceback (most recent call last):
...
NotImplementedError: Multidimensional o.g.f. not implemented.
"""
sage: P.<x> = QQ[]
sage: CFiniteSequence(0.1/(1-x))
C-finite sequence, generated by 1/10/(-x + 1)
sage: CFiniteSequence(pi/(1-x))
Traceback (most recent call last):
...
TypeError: unable to convert -pi to a rational
sage: P.<x,y> = QQ[]
sage: CFiniteSequence(x*y)
Traceback (most recent call last):
...
NotImplementedError: Multidimensional o.g.f. not implemented.
"""


__metaclass__ = ClasscallMetaclass # Needed for __classcall_private__
Expand Down Expand Up @@ -896,7 +896,7 @@ def an_element(self):
OUTPUT:
The Luca sequence.
The Lucas sequence.
EXAMPLES::
Expand Down

0 comments on commit a0aba76

Please sign in to comment.