FractionSequence and SequenceRingOfFraction

Ring of fractions of a sequence ring.

Defines a ring which is the total ring of fractions of a sequence ring. I.e., elements in this ring are fractions of two sequences where the sequence in the denominator has no zero terms.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: a = QC(C([3,0,-1], [1,3]), C([2,-1], [1]))
sage: a
Fraction sequence:
> Numerator: C-finite sequence a(n): (3)*a(n) + (-1)*a(n+2) = 0 
and a(0)=1 , a(1)=3
> Denominator: C-finite sequence a(n): (2)*a(n) + (-1)*a(n+1) = 0 and a(0)=1
sage: b = QC(C([1,-1], [2]))

sage: c = a*b
sage: c[:10]
[2, 3, 3/2, 9/4, 9/8, 27/16, 27/32, 81/64, 81/128, 243/256]
sage: a_inv = ~a
sage: a_inv*a == 1
True
class rec_sequences.SequenceRingOfFraction.FractionSequence(parent, numerator, denominator, name='a', is_gen=False, construct=False, cache=True)

Bases: sage.structure.element.CommutativeAlgebraElement

A fraction sequence, i.e. a fraction where both numerator and denominator are coming from a ring of sequences.

__eq__(right)

Return whether the two fractions self and right are equal. More precisely it is tested if the difference of self and right equals 0.

INPUT:

  • right - a FractionSequence

OUTPUT:

True if the sequences are equal and False otherwise.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: c = C([1,1,-1], [0,1])
sage: d = C([3,1], [1])
sage: a = QC(c*d, d)
sage: b = QC(c, C(1))
sage: a == b
True
sage: b == c
True
sage: a+1 == b
False
__getitem__(n)

Return the n-th term of self.

INPUT:

  • n – a natural number or a slice object

OUTPUT:

The n-th sequence term of self (starting with the 0-th, i.e. to get the first term one has to call self[0]) if n is a natural number. If n is a slice object, the corresponding section of the sequence is returned.

An error is raised if no upper bound in the slice object is specified.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: c = C([1,1,-1], [0,1])
sage: d = C([3,1], [1])
sage: a = QC(c, d)
sage: b = QC(c, C(1))
sage: a[5]
-5/243
sage: b[:10] == c[:10]
True
__init__(parent, numerator, denominator, name='a', is_gen=False, construct=False, cache=True)

Construct a fraction sequence numerator/denominator.

Note

It is not checked whether the denominator contains any zero terms.

INPUT:

  • parent – a SequenceRingOfFraction

  • numerator – the numerator of the fraction

  • denominator – the denominator of the fraction which is non-zero at every term

  • name (default “a”) – a name for the sequence

OUTPUT:

A fraction sequence numerator/denominator.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: QC(C([3,-1], [1]), C([2,-1], [1]))
Fraction sequence:
> Numerator: C-finite sequence a(n): (3)*a(n) + (-1)*a(n+1) = 0 
and a(0)=1
> Denominator: C-finite sequence a(n): (2)*a(n) + (-1)*a(n+1) = 0
and a(0)=1
__invert__()

Tries to compute the multiplicative inverse, if this is possible. Such an inverse exists if and only if the numerator does not contain any zero terms.

The method can be called by ~self or self.inverse_of_unit().

Note

Only some initial terms are checked to see whether a sequence is invertible, cf. is_unit() (this is only checked if the option strict in the construction of the parent ring is True; it is by default).

OUTPUT:

The multiplicative inverse of the sequence if it exists. Raises an ValueError if the sequence is not invertible.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: c = C([1,1,-1], [0,1])
sage: d = C([3,1], [1])
sage: a = QC(c, d)
sage: b = QC(c.shift(), d)
sage: ~a
Traceback (most recent call last):
...
ValueError: Sequence is not invertible
sage: ~b*b == 1
True
_add_(right)

Return the sum of self and right.

INPUTS:

  • right – a FractionSequence

OUTPUTS:

The addition of self with right.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: c = C([1,1,-1], [0,1])
sage: d = C([3,1], [1])
sage: a = QC(c, d)
sage: b = QC(c.shift(), d)
sage: s = a+b
sage: s[:10] == [a[i]+b[i] for i in range(10)]
True
_latex_()

Creates a latex representation of the sequence. This is done by using the fraction of the latex representation of the numerator and denominator.

OUTPUT:

A latex representation showing the closed form of the sequences.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: print(latex(QC(C([2,1], [1]), C([2,-1], [1]))))
\frac{\left(-2\right)^{n}}{2^{n}}
_mul_(right)

Return the product of self and right.

INPUTS:

  • right – a FractionSequence

OUTPUTS:

The product of self with right.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: c = C([1,1,-1], [0,1])
sage: d = C([3,1], [1])
sage: a = QC(c, d)
sage: b = QC(c.shift(), d)
sage: p = a*b
sage: p[:10] == [a[i]*b[i] for i in range(10)]
True
_repr_()

Produces a string representation of the sequence.

OUTPUT:

A string representation of the sequence consisting of the numerator and the denominator of the sequence.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: QC(C([2,1], [1]), C([2,-1], [1]))
Fraction sequence:
> Numerator: C-finite sequence a(n): (2)*a(n) + (1)*a(n+1) = 0 
and a(0)=1
> Denominator: C-finite sequence a(n): (2)*a(n) + (-1)*a(n+1) = 0
and a(0)=1
base()

OUTPUT:

Return the base of the parent of self.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: c = C([1,1,-1], [0,1])
sage: d = C([3,1], [1])
sage: a = QC(c, d)
sage: a.base() == C
True
base_ring()

OUTPUT:

Return the base field of the parent of self.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: c = C([1,1,-1], [0,1])
sage: d = C([3,1], [1])
sage: a = QC(c, d)
sage: a.base_ring() == QQ
True
d()

Alias of denominator().

denominator()

OUTPUT:

Return the denominator

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: c = C([1,1,-1], [0,1])
sage: d = C([3,1], [1])
sage: a = QC(c, d)
sage: a.denominator() == d
True
interlace(*others)

Returns the interlaced sequence of self with others.

INPUT:

  • others – other sequences over the same SequenceRingOfFraction

OUTPUT:

The interlaced sequence of self with others.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: c = C([1,1,-1], [0,1])
sage: d = C([3,1], [1])
sage: e = C([2,-3],[2])
sage: a = QC(c, d)
sage: a[:5]
[0, -1/3, 1/9, -2/27, 1/27]
sage: b = QC(e, C(1))
sage: b[:5]
[2, 4/3, 8/9, 16/27, 32/81]
sage: a.interlace(b)[:6]
[0, 2, -1/3, 4/3, 1/9, 8/9]
is_gen()

OUTPUT:

Return False; the parent ring is not finitely generated.

is_unit()

Check whether sequence is multiplicative unit.

OUTPUT:

Return True if self is a unit. This is the case if the numerator has no zeros. We check this empirically by checking the first 100 values.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: c = C([1,1,-1], [0,1])
sage: d = C([3,1], [1])
sage: a = QC(c, d)
sage: b = QC(c, C(1))
sage: a.is_unit()
False
sage: b.is_unit()
False
sage: (a+1).is_unit()
True
n()

Alias of numerator().

numerator()

OUTPUT:

Return the numerator.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: c = C([1,1,-1], [0,1])
sage: d = C([3,1], [1])
sage: a = QC(c, d)
sage: a.numerator() == c
True
order()

OUTPUT:

Return the order of the recurrence of self which is the maximum of the orders of the numerator and denominator.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: c = C([1,1,-1], [0,1])
sage: d = C([3,1], [1])
sage: QC(c, d).order()
2
sage: QC(d, c).order()
2
sage: QC(c, c).order()
2
prec()

OUTPUT:

The precision of these objects is infinite.

prepend(values)

Prepends the given values to the sequence.

Input:

  • values – list of values in the base ring

OUTPUT:

A sequence having the same terms with the additional values at the beginning.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: c = C([1,1,-1], [0,1])
sage: d = C([3,1], [1])
sage: a = QC(c, d)
sage: a[:5]
[0, -1/3, 1/9, -2/27, 1/27]
sage: a.prepend([1,3])[:7]
[1, 3, 0, -1/3, 1/9, -2/27, 1/27]
shift(k=1)

Shifts self k-times.

INPUT:

  • k (default: 1) – an integer

OUTPUT:

The sequence \((a(n+k))_{k \in \mathbb{N}}\).

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: c = C([1,1,-1], [0,1])
sage: d = C([3,1], [1])
sage: a = QC(c, d)
sage: a[1:11] == a.shift()[:10]
True
simplified()

Computes terms of the sequence and tries to guess a sequence in the base ring from these that is equal to self and tries to prove this.

OUTPUT:

An identical sequence with possible trivial denominator if possible.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: c = C([1,1,-1], [0,1])
sage: d = C([3,1], [1])
sage: a = QC(c*d, d)
sage: a.denominator() == 1
False
sage: a.simplified().denominator() == 1
True
subsequence(u, v=0)

Returns the sequence self[floor(u*n+v)].

INPUT:

  • u – a rational number

  • v (optional) – a rational number

OUTPUT:

The sequence self[floor(u*n+v)].

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: c = C([1,1,-1], [0,1])
sage: d = C([3,1], [1])
sage: a = QC(c, d)
sage: b = a.subsequence(2, 3)
sage: b[:10] == [a[2*i+3] for i in range(10)]
True
zeros(*args, **kwds)

Computes the zeros of the sequence. The sequence is zero if and only if the numerator sequence is zero at that term. Any arguments are passed to the zeros method of the numerator.

OUTPUT:

The indices where the sequence is zero.

class rec_sequences.SequenceRingOfFraction.SequenceRingOfFraction(base, strict=True, name=None, element_class=None, category=None)

Bases: sage.structure.unique_representation.UniqueRepresentation, sage.rings.ring.CommutativeAlgebra

The ring of fractions over a ring of sequences.

Element

alias of rec_sequences.SequenceRingOfFraction.FractionSequence

__init__(base, strict=True, name=None, element_class=None, category=None)

Constructor for a sequence ring of fractions.

INPUT:

  • base – a base ring which represents a sequence ring

  • strict (default: True) – if True elements in the ring can only be inverted if they do not contain any zero terms

OUTPUT:

A sequence ring of fraction over the given base.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: SequenceRingOfFraction(C)
Sequence ring of fractions over Ring of C-finite sequences over 
Rational Field
_element_constructor_(x, y=None, check=True, is_gen=False, construct=False, **kwds)

Tries to construct a fraction sequence element.

This is possible if:

  • x is already a fraction sequence element

  • x is an element in the base and y is an element in the base, then x/y is constructed

  • x is an element in the base and y is None, then x/1 is constructed

  • x and y can be used to construct a sequence element, then this element over 1 is constructed

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: fib = C([1,1,-1], [0,1])
sage: luc = C([1,1,-1], [2,1])
sage: c = QC(fib, luc)
sage: c*luc == fib
True

sage: d = QC(fib)
sage: d == fib
True
_latex_()

OUTPUT:

A latex representation of the sequence ring of fractions.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)
sage: print(latex(QC))
Q(\mathcal{C}(\Bold{Q}))
_repr_()

OUTPUT:

A string representation of the sequence ring of fractions.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: SequenceRingOfFraction(C)
Sequence ring of fractions over Ring of C-finite sequences over 
Rational Field
base()

OUTPUT:

Return the base over which the ring of fractions is defined.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)
sage: QC.base() == C
True
base_ring()

OUTPUT:

Return the base field over which the ring of fractions is defined

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)
sage: QC.base_ring() == QQ
True
change_base_ring(R)

OUTPUT:

Return a copy of self but with the base \(R\)

construction()

Shows how the given ring can be constructed using functors.

OUTPUT:

A functor F and a ring R such that F(R)==self

is_commutative()

Returns whether self is a commutative ring. This is the case.

OUTPUT:

True

is_exact()

Returns whether self is an exact ring. This is the case.

OUTPUT:

True

is_field(proof=True)

Returns whether self is a field. This is not the case.

OUTPUT:

False

is_finite()

Returns whether self is a finite ring. This is not the case.

OUTPUT:

False

is_integral_domain(proof=True)

Returns whether self is an integral domain. This is not the case.

OUTPUT:

False

is_noetherian()

Returns whether self is a Noetherian ring. This is not the case.

OUTPUT:

False

one()

OUTPUT:

The constant sequence \(1,1,\dots\).

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: QC.one() == C.one()
True

sage: QC.one()[:10]
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
random_element(*args, **kwds)

OUTPUT:

Return a random fraction sequence. This is done by creating a random numerator and random denominator (iteratively until a denominator which is a unit is found). Any additional arguments are passed to the random_element method of the base ring.

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)
sage: QC.random_element()[:5] # random
[-8/3, 2, -81/28, 99/112, -1269/896]
zero()

OUTPUT:

The constant sequence \(0,0,\dots\).

EXAMPLES:

sage: from rec_sequences.SequenceRingOfFraction import *
sage: from rec_sequences.CFiniteSequenceRing import *

sage: C = CFiniteSequenceRing(QQ)
sage: QC = SequenceRingOfFraction(C)

sage: QC.zero() == C.zero()
True

sage: QC.zero()[:10]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
class rec_sequences.SequenceRingOfFraction.SequenceRingOfFractionFunctor

Bases: sage.categories.pushout.ConstructionFunctor

__eq__(other)

Equality here means that they are mathematically equivalent, though they may have specific implementation data. This method will usually be overloaded in subclasses. by default, only the types of the functors are compared. Also see the merge() function.

TESTS:

sage: from sage.categories.pushout import IdentityConstructionFunctor
sage: I = IdentityConstructionFunctor()
sage: F = QQ.construction()[0]
sage: P = ZZ['t'].construction()[0]
sage: I == F        # indirect doctest
False
sage: I == I        # indirect doctest
True
__init__()

Constructs a SequenceRingOfFractionFunctor.

_repr_()

Returns a string representation of the functor.

OUTPUT:

The string “SequenceRingOfFraction(*)” .

merge(other)

Merge self with another construction functor, or return None.

Note

The default is to merge only if the two functors coincide. But this may be overloaded for subclasses, such as the quotient functor.

EXAMPLES:

sage: F = QQ.construction()[0]
sage: P = ZZ['t'].construction()[0]
sage: F.merge(F)
FractionField
sage: F.merge(P)
sage: P.merge(F)
sage: P.merge(P)
Poly[t]