Lazy Series Rings#

We provide lazy implementations for various \(\NN\)-graded rings.

LazyLaurentSeriesRing

The ring of lazy Laurent series.

LazyPowerSeriesRing

The ring of (possibly multivariate) lazy Taylor series.

LazyCompletionGradedAlgebra

The completion of a graded algebra consisting of formal series.

LazySymmetricFunctions

The ring of (possibly multivariate) lazy symmetric functions.

LazyDirichletSeriesRing

The ring of lazy Dirichlet series.

Warning

When the halting precision is infinite, the default for bool(f) is True for any lazy series f that is not known to be zero. This could end up resulting in infinite loops:

sage: L.<x> = LazyPowerSeriesRing(ZZ)
sage: f = L(lambda n: 0, valuation=0)
sage: 1 / f  # not tested - infinite loop

See also

The examples of LazyLaurentSeriesRing contain a discussion about the different methods of comparisons the lazy series can use.

AUTHORS:

  • Kwankyu Lee (2019-02-24): initial version

  • Tejasvi Chebrolu, Martin Rubey, Travis Scrimshaw (2021-08): refactored and expanded functionality

class sage.rings.lazy_series_ring.LazyCompletionGradedAlgebra(basis, sparse=True, category=None)#

Bases: LazySeriesRing

The completion of a graded algebra consisting of formal series.

For a graded algebra \(A\), we can form a completion of \(A\) consisting of all formal series of \(A\) such that each homogeneous component is a finite linear combination of basis elements of \(A\).

INPUT:

  • basis – a graded algebra

  • names – name(s) of the alphabets

  • sparse – (default: True) whether we use a sparse or a dense representation

EXAMPLES:

sage: # needs sage.modules
sage: NCSF = NonCommutativeSymmetricFunctions(QQ)
sage: S = NCSF.Complete()
sage: L = S.formal_series_ring(); L
Lazy completion of Non-Commutative Symmetric Functions
 over the Rational Field in the Complete basis
sage: f = 1 / (1 - L(S[1])); f
S[] + S[1] + (S[1,1]) + (S[1,1,1]) + (S[1,1,1,1]) + (S[1,1,1,1,1])
 + (S[1,1,1,1,1,1]) + O^7
sage: g = 1 / (1 - L(S[2])); g
S[] + S[2] + (S[2,2]) + (S[2,2,2]) + O^7
sage: f * g
S[] + S[1] + (S[1,1]+S[2]) + (S[1,1,1]+S[1,2])
 + (S[1,1,1,1]+S[1,1,2]+S[2,2]) + (S[1,1,1,1,1]+S[1,1,1,2]+S[1,2,2])
 + (S[1,1,1,1,1,1]+S[1,1,1,1,2]+S[1,1,2,2]+S[2,2,2]) + O^7
sage: g * f
S[] + S[1] + (S[1,1]+S[2]) + (S[1,1,1]+S[2,1])
 + (S[1,1,1,1]+S[2,1,1]+S[2,2]) + (S[1,1,1,1,1]+S[2,1,1,1]+S[2,2,1])
 + (S[1,1,1,1,1,1]+S[2,1,1,1,1]+S[2,2,1,1]+S[2,2,2]) + O^7
sage: f * g - g * f
(S[1,2]-S[2,1]) + (S[1,1,2]-S[2,1,1])
 + (S[1,1,1,2]+S[1,2,2]-S[2,1,1,1]-S[2,2,1])
 + (S[1,1,1,1,2]+S[1,1,2,2]-S[2,1,1,1,1]-S[2,2,1,1]) + O^7
Element#

alias of LazyCompletionGradedAlgebraElement

some_elements()#

Return a list of elements of self.

EXAMPLES:

sage: m = SymmetricFunctions(GF(5)).m()                                     # needs sage.modules
sage: L = LazySymmetricFunctions(m)                                         # needs sage.modules
sage: L.some_elements()[:5]                                                 # needs sage.modules
[0, m[], 2*m[] + 2*m[1] + 3*m[2], 2*m[1] + 3*m[2],
 3*m[] + 2*m[1] + (m[1,1]+m[2])
       + (2*m[1,1,1]+m[3])
       + (2*m[1,1,1,1]+4*m[2,1,1]+2*m[2,2])
       + (3*m[2,1,1,1]+3*m[3,1,1]+4*m[3,2]+m[5])
       + (2*m[2,2,1,1]+m[2,2,2]+2*m[3,2,1]+2*m[3,3]+m[4,1,1]+3*m[4,2]+4*m[5,1]+4*m[6])
       + O^7]

sage: # needs sage.modules
sage: NCSF = NonCommutativeSymmetricFunctions(QQ)
sage: S = NCSF.Complete()
sage: L = S.formal_series_ring()
sage: L.some_elements()[:4]
[0, S[], 2*S[] + 2*S[1] + (3*S[1,1]), 2*S[1] + (3*S[1,1])]
class sage.rings.lazy_series_ring.LazyDirichletSeriesRing(base_ring, names, sparse=True, category=None)#

Bases: LazySeriesRing

The ring of lazy Dirichlet series.

INPUT:

  • base_ring – base ring of this Dirichlet series ring

  • names – name of the generator of this Dirichlet series ring

  • sparse – (default: True) whether this series is sparse or not

Unlike formal univariate Laurent/power series (over a field), the ring of formal Dirichlet series is not a Wikipedia article discrete_valuation_ring. On the other hand, it is a Wikipedia article local_ring. The unique maximal ideal consists of all non-invertible series, i.e., series with vanishing constant term.

Todo

According to the answers in https://mathoverflow.net/questions/5522/dirichlet-series-with-integer-coefficients-as-a-ufd, (which, in particular, references arXiv math/0105219) the ring of formal Dirichlet series is actually a Wikipedia article Unique_factorization_domain over \(\ZZ\).

Note

An interesting valuation is described in Emil Daniel Schwab; Gheorghe Silberberg A note on some discrete valuation rings of arithmetical functions, Archivum Mathematicum, Vol. 36 (2000), No. 2, 103-109, http://dml.cz/dmlcz/107723. Let \(J_k\) be the ideal of Dirichlet series whose coefficient \(f[n]\) of \(n^s\) vanishes if \(n\) has less than \(k\) prime factors, counting multiplicities. For any Dirichlet series \(f\), let \(D(f)\) be the largest integer \(k\) such that \(f\) is in \(J_k\). Then \(D\) is surjective, \(D(f g) = D(f) + D(g)\) for nonzero \(f\) and \(g\), and \(D(f + g) \geq \min(D(f), D(g))\) provided that \(f + g\) is nonzero.

For example, \(J_1\) are series with no constant term, and \(J_2\) are series such that \(f[1]\) and \(f[p]\) for prime \(p\) vanish.

Since this is a chain of increasing ideals, the ring of formal Dirichlet series is not a Wikipedia article Noetherian_ring.

Evidently, this valuation cannot be computed for a given series.

EXAMPLES:

sage: LazyDirichletSeriesRing(ZZ, 't')
Lazy Dirichlet Series Ring in t over Integer Ring

The ideal generated by \(2^-s\) and \(3^-s\) is not principal:

sage: L = LazyDirichletSeriesRing(QQ, 's')
sage: L in PrincipalIdealDomains
False
Element#

alias of LazyDirichletSeries

one()#

Return the constant series \(1\).

EXAMPLES:

sage: L = LazyDirichletSeriesRing(ZZ, 'z')
sage: L.one()                                                               # needs sage.symbolic
1
sage: ~L.one()                                                              # needs sage.symbolic
1 + O(1/(8^z))
some_elements()#

Return a list of elements of self.

EXAMPLES:

sage: L = LazyDirichletSeriesRing(ZZ, 'z')
sage: l = L.some_elements()
sage: l                                                                     # needs sage.symbolic
[0, 1,
 1/(4^z) + 1/(5^z) + 1/(6^z) + O(1/(7^z)),
 1/(2^z) - 1/(3^z) + 2/4^z - 2/5^z + 3/6^z - 3/7^z + 4/8^z - 4/9^z,
 1/(2^z) - 1/(3^z) + 2/4^z - 2/5^z + 3/6^z - 3/7^z + 4/8^z - 4/9^z + 1/(10^z) + 1/(11^z) + 1/(12^z) + O(1/(13^z)),
 1 + 4/2^z + 9/3^z + 16/4^z + 25/5^z + 36/6^z + 49/7^z + O(1/(8^z))]

sage: L = LazyDirichletSeriesRing(QQ, 'z')
sage: l = L.some_elements()
sage: l                                                                     # needs sage.symbolic
[0, 1,
 1/2/4^z + 1/2/5^z + 1/2/6^z + O(1/(7^z)),
 1/2 - 1/2/2^z + 2/3^z - 2/4^z + 1/(6^z) - 1/(7^z) + 42/8^z + 2/3/9^z,
 1/2 - 1/2/2^z + 2/3^z - 2/4^z + 1/(6^z) - 1/(7^z) + 42/8^z + 2/3/9^z + 1/2/10^z + 1/2/11^z + 1/2/12^z + O(1/(13^z)),
 1 + 4/2^z + 9/3^z + 16/4^z + 25/5^z + 36/6^z + 49/7^z + O(1/(8^z))]
class sage.rings.lazy_series_ring.LazyLaurentSeriesRing(base_ring, names, sparse=True, category=None)#

Bases: LazySeriesRing

The ring of lazy Laurent series.

The ring of Laurent series over a ring with the usual arithmetic where the coefficients are computed lazily.

INPUT:

  • base_ring – base ring

  • names – name of the generator

  • sparse – (default: True) whether the implementation of the series is sparse or not

EXAMPLES:

sage: L.<z> = LazyLaurentSeriesRing(QQ)
sage: 1 / (1 - z)
1 + z + z^2 + O(z^3)
sage: 1 / (1 - z) == 1 / (1 - z)
True
sage: L in Fields
True

Lazy Laurent series ring over a finite field:

sage: # needs sage.rings.finite_rings
sage: L.<z> = LazyLaurentSeriesRing(GF(3)); L
Lazy Laurent Series Ring in z over Finite Field of size 3
sage: e = 1 / (1 + z)
sage: e.coefficient(100)
1
sage: e.coefficient(100).parent()
Finite Field of size 3

Series can be defined by specifying a coefficient function and a valuation:

sage: R.<x,y> = QQ[]
sage: L.<z> = LazyLaurentSeriesRing(R)
sage: def coeff(n):
....:     if n < 0:
....:         return -2 + n
....:     if n == 0:
....:         return 6
....:     return x + y^n
sage: f = L(coeff, valuation=-5)
sage: f
-7*z^-5 - 6*z^-4 - 5*z^-3 - 4*z^-2 - 3*z^-1 + 6 + (x + y)*z + O(z^2)
sage: 1 / (1 - f)
1/7*z^5 - 6/49*z^6 + 1/343*z^7 + 8/2401*z^8 + 64/16807*z^9
 + 17319/117649*z^10 + (1/49*x + 1/49*y - 180781/823543)*z^11 + O(z^12)
sage: L(coeff, valuation=-3, degree=3, constant=x)
-5*z^-3 - 4*z^-2 - 3*z^-1 + 6 + (x + y)*z + (y^2 + x)*z^2
 + x*z^3 + x*z^4 + x*z^5 + O(z^6)

We can also specify a polynomial or the initial coefficients. Additionally, we may specify that all coefficients are equal to a given constant, beginning at a given degree:

sage: L([1, x, y, 0, x+y])
1 + x*z + y*z^2 + (x + y)*z^4
sage: L([1, x, y, 0, x+y], constant=2)
1 + x*z + y*z^2 + (x + y)*z^4 + 2*z^5 + 2*z^6 + 2*z^7 + O(z^8)
sage: L([1, x, y, 0, x+y], degree=7, constant=2)
1 + x*z + y*z^2 + (x + y)*z^4 + 2*z^7 + 2*z^8 + 2*z^9 + O(z^10)
sage: L([1, x, y, 0, x+y], valuation=-2)
z^-2 + x*z^-1 + y + (x + y)*z^2
sage: L([1, x, y, 0, x+y], valuation=-2, constant=3)
z^-2 + x*z^-1 + y + (x + y)*z^2 + 3*z^3 + 3*z^4 + 3*z^5 + O(z^6)
sage: L([1, x, y, 0, x+y], valuation=-2, degree=4, constant=3)
z^-2 + x*z^-1 + y + (x + y)*z^2 + 3*z^4 + 3*z^5 + 3*z^6 + O(z^7)

Some additional examples over the integer ring:

sage: L.<z> = LazyLaurentSeriesRing(ZZ)
sage: L in Fields
False
sage: 1 / (1 - 2*z)^3
1 + 6*z + 24*z^2 + 80*z^3 + 240*z^4 + 672*z^5 + 1792*z^6 + O(z^7)

sage: R.<x> = LaurentPolynomialRing(ZZ)
sage: L(x^-2 + 3 + x)
z^-2 + 3 + z
sage: L(x^-2 + 3 + x, valuation=-5, constant=2)
z^-5 + 3*z^-3 + z^-2 + 2*z^-1 + 2 + 2*z + O(z^2)
sage: L(x^-2 + 3 + x, valuation=-5, degree=0, constant=2)
z^-5 + 3*z^-3 + z^-2 + 2 + 2*z + 2*z^2 + O(z^3)

We can truncate a series, shift its coefficients, or replace all coefficients beginning with a given degree by a constant:

sage: f = 1 / (z + z^2)
sage: f
z^-1 - 1 + z - z^2 + z^3 - z^4 + z^5 + O(z^6)
sage: L(f, valuation=2)
z^2 - z^3 + z^4 - z^5 + z^6 - z^7 + z^8 + O(z^9)
sage: L(f, degree=3)
z^-1 - 1 + z - z^2
sage: L(f, degree=3, constant=2)
z^-1 - 1 + z - z^2 + 2*z^3 + 2*z^4 + 2*z^5 + O(z^6)
sage: L(f, valuation=1, degree=4)
z - z^2 + z^3
sage: L(f, valuation=1, degree=4, constant=5)
z - z^2 + z^3 + 5*z^4 + 5*z^5 + 5*z^6 + O(z^7)

Power series can be defined recursively (see sage.rings.lazy_series.LazyModuleElement.define() for more examples):

sage: L.<z> = LazyLaurentSeriesRing(ZZ)
sage: s = L.undefined(valuation=0)
sage: s.define(1 + z*s^2)
sage: s
1 + z + 2*z^2 + 5*z^3 + 14*z^4 + 42*z^5 + 132*z^6 + O(z^7)

By default, any two series f and g that are not known to be equal are considered to be different:

sage: f = L(lambda n: 0, valuation=0)
sage: f == 0
False

sage: f = L(constant=1, valuation=0).derivative(); f
1 + 2*z + 3*z^2 + 4*z^3 + 5*z^4 + 6*z^5 + 7*z^6 + O(z^7)
sage: g = L(lambda n: (n+1), valuation=0); g
1 + 2*z + 3*z^2 + 4*z^3 + 5*z^4 + 6*z^5 + 7*z^6 + O(z^7)
sage: f == g
False

Warning

We have imposed that (f == g) == not (f != g), and so f != g returning True might not mean that the two series are actually different:

sage: f = L(lambda n: 0, valuation=0)
sage: g = L.zero()
sage: f != g
True

This can be verified by is_nonzero(), which only returns True if the series is known to be nonzero:

sage: (f - g).is_nonzero()
False

The implementation of the ring can be either be a sparse or a dense one. The default is a sparse implementation:

sage: L.<z> = LazyLaurentSeriesRing(ZZ)
sage: L.is_sparse()
True
sage: L.<z> = LazyLaurentSeriesRing(ZZ, sparse=False)
sage: L.is_sparse()
False

We additionally provide two other methods of performing comparisons. The first is raising a ValueError and the second uses a check up to a (user set) finite precision. These behaviors are set using the options secure and halting_precision. In particular, this applies to series that are not specified by a finite number of initial coefficients and a constant for the remaining coefficients. Equality checking will depend on the coefficients which have already been computed. If this information is not enough to check that two series are different, then if L.options.secure is set to True, then we raise a ValueError:

sage: L.options.secure = True
sage: f = 1 / (z + z^2); f
z^-1 - 1 + z - z^2 + z^3 - z^4 + z^5 + O(z^6)
sage: f2 = f * 2  # currently no coefficients computed
sage: f3 = f * 3  # currently no coefficients computed
sage: f2 == f3
Traceback (most recent call last):
...
ValueError: undecidable
sage: f2  # computes some of the coefficients of f2
2*z^-1 - 2 + 2*z - 2*z^2 + 2*z^3 - 2*z^4 + 2*z^5 + O(z^6)
sage: f3  # computes some of the coefficients of f3
3*z^-1 - 3 + 3*z - 3*z^2 + 3*z^3 - 3*z^4 + 3*z^5 + O(z^6)
sage: f2 == f3
False
sage: f2a = f + f
sage: f2 == f2a
Traceback (most recent call last):
...
ValueError: undecidable
sage: zf = L(lambda n: 0, valuation=0)
sage: zf == 0
Traceback (most recent call last):
...
ValueError: undecidable

For boolean checks, an error is raised when it is not known to be nonzero:

sage: bool(zf)
Traceback (most recent call last):
...
ValueError: undecidable

If the halting precision is set to a finite number \(p\) (for unlimited precision, it is set to None), then it will check up to \(p\) values from the current position:

sage: L.options.halting_precision = 20
sage: f2 = f * 2  # currently no coefficients computed
sage: f3 = f * 3  # currently no coefficients computed
sage: f2 == f3
False
sage: f2a = f + f
sage: f2 == f2a
True
sage: zf = L(lambda n: 0, valuation=0)
sage: zf == 0
True
Element#

alias of LazyLaurentSeries

euler()#

Return the Euler function as an element of self.

The Euler function is defined as

\[\phi(z) = (z; z)_{\infty} = \sum_{n=0}^{\infty} (-1)^n q^{(3n^2-n)/2}.\]

EXAMPLES:

sage: L.<q> = LazyLaurentSeriesRing(ZZ)
sage: phi = q.euler()
sage: phi
1 - q - q^2 + q^5 + O(q^7)

We verify that \(1 / phi\) gives the generating function for all partitions:

sage: P = 1 / phi; P
1 + q + 2*q^2 + 3*q^3 + 5*q^4 + 7*q^5 + 11*q^6 + O(q^7)
sage: P[:20] == [Partitions(n).cardinality() for n in range(20)]            # needs sage.libs.flint
True

REFERENCES:

gen(n=0)#

Return the n-th generator of self.

EXAMPLES:

sage: L = LazyLaurentSeriesRing(ZZ, 'z')
sage: L.gen()
z
sage: L.gen(3)
Traceback (most recent call last):
...
IndexError: there is only one generator
gens()#

Return the generators of self.

EXAMPLES:

sage: L.<z> = LazyLaurentSeriesRing(ZZ)
sage: L.gens()
(z,)
sage: 1/(1 - z)
1 + z + z^2 + O(z^3)
ngens()#

Return the number of generators of self.

This is always 1.

EXAMPLES:

sage: L.<z> = LazyLaurentSeriesRing(ZZ)
sage: L.ngens()
1
q_pochhammer(q=None)#

Return the infinite q-Pochhammer symbol \((a; q)_{\infty}\), where \(a\) is the variable of self.

This is also one version of the quantum dilogarithm or the \(q\)-Exponential function.

INPUT:

  • q – (default: \(q \in \QQ(q)\)) the parameter \(q\)

EXAMPLES:

sage: q = ZZ['q'].fraction_field().gen()
sage: L.<z> = LazyLaurentSeriesRing(q.parent())
sage: qpoch = L.q_pochhammer(q)
sage: qpoch
1
 + (-1/(-q + 1))*z
 + (q/(q^3 - q^2 - q + 1))*z^2
 + (-q^3/(-q^6 + q^5 + q^4 - q^2 - q + 1))*z^3
 + (q^6/(q^10 - q^9 - q^8 + 2*q^5 - q^2 - q + 1))*z^4
 + (-q^10/(-q^15 + q^14 + q^13 - q^10 - q^9 - q^8 + q^7 + q^6 + q^5 - q^2 - q + 1))*z^5
 + (q^15/(q^21 - q^20 - q^19 + q^16 + 2*q^14 - q^12 - q^11 - q^10 - q^9 + 2*q^7 + q^5 - q^2 - q + 1))*z^6
 + O(z^7)

We show that \((z; q)_n = \frac{(z; q)_{\infty}}{(q^n z; q)_{\infty}}\):

sage: qpoch / qpoch(q*z)
1 - z + O(z^7)
sage: qpoch / qpoch(q^2*z)
1 + (-q - 1)*z + q*z^2 + O(z^7)
sage: qpoch / qpoch(q^3*z)
1 + (-q^2 - q - 1)*z + (q^3 + q^2 + q)*z^2 - q^3*z^3 + O(z^7)
sage: qpoch / qpoch(q^4*z)
1 + (-q^3 - q^2 - q - 1)*z + (q^5 + q^4 + 2*q^3 + q^2 + q)*z^2
 + (-q^6 - q^5 - q^4 - q^3)*z^3 + q^6*z^4 + O(z^7)

We can also construct part of Euler’s function:

sage: M.<a> = LazyLaurentSeriesRing(QQ)
sage: phi = sum(qpoch[i](q=a)*a^i for i in range(10))
sage: phi[:20] == M.euler()[:20]
True

REFERENCES:

residue_field()#

Return the residue field of the ring of integers of self.

EXAMPLES:

sage: L = LazyLaurentSeriesRing(QQ, 'z')
sage: L.residue_field()
Rational Field
series(coefficient, valuation, degree=None, constant=None)#

Return a lazy Laurent series.

INPUT:

  • coefficient – Python function that computes coefficients or a list

  • valuation – integer; approximate valuation of the series

  • degree – (optional) integer

  • constant – (optional) an element of the base ring

Let the coefficient of index \(i\) mean the coefficient of the term of the series with exponent \(i\).

Python function coefficient returns the value of the coefficient of index \(i\) from input \(s\) and \(i\) where \(s\) is the series itself.

Let valuation be \(n\). All coefficients of index below \(n\) are zero. If constant is not specified, then the coefficient function is responsible to compute the values of all coefficients of index \(\ge n\). If degree or constant is a pair \((c,m)\), then the coefficient function is responsible to compute the values of all coefficients of index \(\ge n\) and \(< m\) and all the coefficients of index \(\ge m\) is the constant \(c\).

EXAMPLES:

sage: L = LazyLaurentSeriesRing(ZZ, 'z')
sage: L.series(lambda s, i: i, 5, (1,10))
5*z^5 + 6*z^6 + 7*z^7 + 8*z^8 + 9*z^9 + z^10 + z^11 + z^12 + O(z^13)

sage: def g(s, i):
....:     if i < 0:
....:         return 1
....:     else:
....:         return s.coefficient(i - 1) + i
sage: e = L.series(g, -5); e
z^-5 + z^-4 + z^-3 + z^-2 + z^-1 + 1 + 2*z + O(z^2)
sage: f = e^-1; f
z^5 - z^6 - z^11 + O(z^12)
sage: f.coefficient(10)
0
sage: f.coefficient(20)
9
sage: f.coefficient(30)
-219

Alternatively, the coefficient can be a list of elements of the base ring. Then these elements are read as coefficients of the terms of degrees starting from the valuation. In this case, constant may be just an element of the base ring instead of a tuple or can be simply omitted if it is zero.

sage: L = LazyLaurentSeriesRing(ZZ, 'z')
sage: f = L.series([1,2,3,4], -5); f
z^-5 + 2*z^-4 + 3*z^-3 + 4*z^-2
sage: g = L.series([1,3,5,7,9], 5, constant=-1); g
z^5 + 3*z^6 + 5*z^7 + 7*z^8 + 9*z^9 - z^10 - z^11 - z^12 + O(z^13)
some_elements()#

Return a list of elements of self.

EXAMPLES:

sage: L = LazyLaurentSeriesRing(ZZ, 'z')
sage: L.some_elements()[:7]
[0, 1, z,
 -3*z^-4 + z^-3 - 12*z^-2 - 2*z^-1 - 10 - 8*z + z^2 + z^3,
 z^-2 + z^3 + z^4 + z^5 + O(z^6),
 -2*z^-3 - 2*z^-2 + 4*z^-1 + 11 - z - 34*z^2 - 31*z^3 + O(z^4),
 4*z^-2 + z^-1 + z + 4*z^2 + 9*z^3 + 16*z^4 + O(z^5)]

sage: L = LazyLaurentSeriesRing(GF(2), 'z')
sage: L.some_elements()[:7]
[0, 1, z,
 z^-4 + z^-3 + z^2 + z^3,
 z^-2,
 1 + z + z^3 + z^4 + z^6 + O(z^7),
 z^-1 + z + z^3 + O(z^5)]

sage: L = LazyLaurentSeriesRing(GF(3), 'z')
sage: L.some_elements()[:7]
[0, 1, z,
 z^-3 + z^-1 + 2 + z + z^2 + z^3,
 z^-2,
 z^-3 + z^-2 + z^-1 + 2 + 2*z + 2*z^2 + O(z^3),
 z^-2 + z^-1 + z + z^2 + z^4 + O(z^5)]
taylor(f)#

Return the Taylor expansion around \(0\) of the function f.

INPUT:

  • f – a function such that one of the following works:

    • the substitution \(f(z)\), where \(z\) is a generator of self

    • \(f\) is a function of a single variable with no poles at \(0\) and has a derivative method

EXAMPLES:

sage: L.<z> = LazyLaurentSeriesRing(QQ)
sage: x = SR.var('x')
sage: f(x) = (1 + x) / (1 - x^2)
sage: L.taylor(f)
1 + z + z^2 + z^3 + z^4 + z^5 + z^6 + O(z^7)

For inputs as symbolic functions/expressions, the function must not have any poles at \(0\):

sage: f(x) = (1 + x^2) / sin(x^2)
sage: L.taylor(f)
<repr(...) failed: ValueError: power::eval(): division by zero>
sage: def g(a): return (1 + a^2) / sin(a^2)
sage: L.taylor(g)
z^-2 + 1 + 1/6*z^2 + 1/6*z^4 + O(z^5)
uniformizer()#

Return a uniformizer of self..

EXAMPLES:

sage: L = LazyLaurentSeriesRing(QQ, 'z')
sage: L.uniformizer()
z
class sage.rings.lazy_series_ring.LazyPowerSeriesRing(base_ring, names, sparse=True, category=None)#

Bases: LazySeriesRing

The ring of (possibly multivariate) lazy Taylor series.

INPUT:

  • base_ring – base ring of this Taylor series ring

  • names – name(s) of the generator of this Taylor series ring

  • sparse – (default: True) whether this series is sparse or not

EXAMPLES:

sage: LazyPowerSeriesRing(ZZ, 't')
Lazy Taylor Series Ring in t over Integer Ring

sage: L.<x, y> = LazyPowerSeriesRing(QQ); L
Multivariate Lazy Taylor Series Ring in x, y over Rational Field
Element#

alias of LazyPowerSeries

fraction_field()#

Return the fraction field of self.

If this is with a single variable over a field, then the fraction field is the field of (lazy) formal Laurent series.

Todo

Implement other fraction fields.

EXAMPLES:

sage: L.<x> = LazyPowerSeriesRing(QQ)
sage: L.fraction_field()
Lazy Laurent Series Ring in x over Rational Field
gen(n=0)#

Return the n-th generator of self.

EXAMPLES:

sage: L = LazyPowerSeriesRing(ZZ, 'z')
sage: L.gen()
z
sage: L.gen(3)
Traceback (most recent call last):
...
IndexError: there is only one generator
gens()#

Return the generators of self.

EXAMPLES:

sage: L = LazyPowerSeriesRing(ZZ, 'x,y')
sage: L.gens()
(x, y)
ngens()#

Return the number of generators of self.

EXAMPLES:

sage: L.<z> = LazyPowerSeriesRing(ZZ)
sage: L.ngens()
1
residue_field()#

Return the residue field of the ring of integers of self.

EXAMPLES:

sage: L = LazyPowerSeriesRing(QQ, 'x')
sage: L.residue_field()
Rational Field
some_elements()#

Return a list of elements of self.

EXAMPLES:

sage: L = LazyPowerSeriesRing(ZZ, 'z')
sage: L.some_elements()[:6]
[0, 1, z + z^2 + z^3 + O(z^4),
 -12 - 8*z + z^2 + z^3,
 1 + z - 2*z^2 - 7*z^3 - z^4 + 20*z^5 + 23*z^6 + O(z^7),
 z + 4*z^2 + 9*z^3 + 16*z^4 + 25*z^5 + 36*z^6 + O(z^7)]

sage: L = LazyPowerSeriesRing(GF(3)["q"], 'z')
sage: L.some_elements()[:6]
[0, 1, z + q*z^2 + q*z^3 + q*z^4 + O(z^5),
 z + z^2 + z^3,
 1 + z + z^2 + 2*z^3 + 2*z^4 + 2*z^5 + O(z^6),
 z + z^2 + z^4 + z^5 + O(z^7)]

sage: L = LazyPowerSeriesRing(GF(3), 'q, t')
sage: L.some_elements()[:6]
[0, 1, q,
 q + q^2 + q^3,
 1 + q + q^2 + (-q^3) + (-q^4) + (-q^5) + (-q^6) + O(q,t)^7,
 1 + (q+t) + (q^2-q*t+t^2) + (q^3+t^3)
   + (q^4+q^3*t+q*t^3+t^4)
   + (q^5-q^4*t+q^3*t^2+q^2*t^3-q*t^4+t^5)
   + (q^6-q^3*t^3+t^6) + O(q,t)^7]
taylor(f)#

Return the Taylor expansion around \(0\) of the function f.

INPUT:

  • f – a function such that one of the following works:

    • the substitution \(f(z_1, \ldots, z_n)\), where \((z_1, \ldots, z_n)\) are the generators of self

    • \(f\) is a function with no poles at \(0\) and has a derivative method

Warning

For inputs as symbolic functions/expressions, this does not check that the function does not have poles at \(0\).

EXAMPLES:

sage: L.<z> = LazyPowerSeriesRing(QQ)
sage: x = SR.var('x')
sage: f(x) = (1 + x) / (1 - x^3)
sage: L.taylor(f)
1 + z + z^3 + z^4 + z^6 + O(z^7)
sage: (1 + z) / (1 - z^3)
1 + z + z^3 + z^4 + z^6 + O(z^7)
sage: f(x) = cos(x + pi/2)
sage: L.taylor(f)
-z + 1/6*z^3 - 1/120*z^5 + O(z^7)

For inputs as symbolic functions/expressions, the function must not have any poles at \(0\):

sage: L.<z> = LazyPowerSeriesRing(QQ, sparse=True)
sage: f = 1 / sin(x)
sage: L.taylor(f)
<repr(...) failed: ValueError: power::eval(): division by zero>

Different multivariate inputs:

sage: L.<a,b> = LazyPowerSeriesRing(QQ)
sage: def f(x, y): return (1 + x) / (1 + y)
sage: L.taylor(f)
1 + (a-b) + (-a*b+b^2) + (a*b^2-b^3) + (-a*b^3+b^4) + (a*b^4-b^5) + (-a*b^5+b^6) + O(a,b)^7
sage: g(w, z) = (1 + w) / (1 + z)
sage: L.taylor(g)
1 + (a-b) + (-a*b+b^2) + (a*b^2-b^3) + (-a*b^3+b^4) + (a*b^4-b^5) + (-a*b^5+b^6) + O(a,b)^7
sage: y = SR.var('y')
sage: h = (1 + x) / (1 + y)
sage: L.taylor(h)
1 + (a-b) + (-a*b+b^2) + (a*b^2-b^3) + (-a*b^3+b^4) + (a*b^4-b^5) + (-a*b^5+b^6) + O(a,b)^7
uniformizer()#

Return a uniformizer of self.

EXAMPLES:

sage: L = LazyPowerSeriesRing(QQ, 'x')
sage: L.uniformizer()
x
class sage.rings.lazy_series_ring.LazySeriesRing#

Bases: UniqueRepresentation, Parent

Abstract base class for lazy series.

characteristic()#

Return the characteristic of this lazy power series ring, which is the same as the characteristic of its base ring.

EXAMPLES:

sage: L.<t> = LazyLaurentSeriesRing(ZZ)
sage: L.characteristic()
0

sage: R.<w> = LazyLaurentSeriesRing(GF(11)); R
Lazy Laurent Series Ring in w over Finite Field of size 11
sage: R.characteristic()
11

sage: R.<x, y> = LazyPowerSeriesRing(GF(7)); R
Multivariate Lazy Taylor Series Ring in x, y over Finite Field of size 7
sage: R.characteristic()
7

sage: L = LazyDirichletSeriesRing(ZZ, "s")
sage: L.characteristic()
0
is_exact()#

Return if self is exact or not.

EXAMPLES:

sage: L = LazyLaurentSeriesRing(ZZ, 'z')
sage: L.is_exact()
True
sage: L = LazyLaurentSeriesRing(RR, 'z')
sage: L.is_exact()
False
is_sparse()#

Return whether self is sparse or not.

EXAMPLES:

sage: L = LazyLaurentSeriesRing(ZZ, 'z', sparse=False)
sage: L.is_sparse()
False

sage: L = LazyLaurentSeriesRing(ZZ, 'z', sparse=True)
sage: L.is_sparse()
True
one()#

Return the constant series \(1\).

EXAMPLES:

sage: L = LazyLaurentSeriesRing(ZZ, 'z')
sage: L.one()
1

sage: L = LazyPowerSeriesRing(ZZ, 'z')
sage: L.one()
1

sage: m = SymmetricFunctions(ZZ).m()                                        # needs sage.modules
sage: L = LazySymmetricFunctions(m)                                         # needs sage.modules
sage: L.one()                                                               # needs sage.modules
m[]
options = Current options for lazy series rings   - constant_length:   3   - display_length:    7   - halting_precision: None   - secure:            False#
prod(f, a=None, b=+Infinity, add_one=False)#

The product of elements of self.

INPUT:

  • f – a list (or iterable) of elements of self

  • a, b – optional arguments

  • add_one – (default: False); if True, then converts a lazy series \(p_i\) from args into \(1 + p_i\) for the product

If a and b are both integers, then this returns the product \(\prod_{i=a}^b f(i)\), where \(f(i) = p_i\) if add_one=False or \(f(i) = 1 + p_i\) otherwise. If b is not specified, then we consider \(b = \infty\). Note this corresponds to the Python range(a, b+1).

If \(a\) is any other iterable, then this returns the product \(\prod_{i \in a} f(i)\), where \(f(i) = p_i\) if add_one=False or \(f(i) = 1 + p_i\).

Note

For infinite products, it is faster to use add_one=True since the implementation is based on \(p_i\) in \(\prod_i (1 + p_i)\).

Warning

When f is an infinite generator, then the first argument a must be True. Otherwise this will loop forever.

Warning

For an infinite product of the form \(\prod_i (1 + p_i)\), if \(p_i = 0\), then this will loop forever.

EXAMPLES:

sage: L.<t> = LazyLaurentSeriesRing(QQ)
sage: euler = L.prod(lambda n: 1 - t^n, PositiveIntegers())
sage: euler
1 - t - t^2 + t^5 + O(t^7)
sage: 1 / euler
1 + t + 2*t^2 + 3*t^3 + 5*t^4 + 7*t^5 + 11*t^6 + O(t^7)
sage: euler - L.euler()
O(t^7)
sage: L.prod(lambda n: -t^n, 1, add_one=True)
1 - t - t^2 + t^5 + O(t^7)

sage: L.prod((1 - t^n for n in PositiveIntegers()), True)
1 - t - t^2 + t^5 + O(t^7)
sage: L.prod((-t^n for n in PositiveIntegers()), True, add_one=True)
1 - t - t^2 + t^5 + O(t^7)

sage: L.prod((1 + t^(n-3) for n in PositiveIntegers()), True)
2*t^-3 + 4*t^-2 + 4*t^-1 + 4 + 6*t + 10*t^2 + 16*t^3 + O(t^4)

sage: L.prod(lambda n: 2 + t^n, -3, 5)
96*t^-6 + 240*t^-5 + 336*t^-4 + 840*t^-3 + 984*t^-2 + 1248*t^-1
 + 1980 + 1668*t + 1824*t^2 + 1872*t^3 + 1782*t^4 + 1710*t^5
 + 1314*t^6 + 1122*t^7 + 858*t^8 + 711*t^9 + 438*t^10 + 282*t^11
 + 210*t^12 + 84*t^13 + 60*t^14 + 24*t^15
sage: L.prod(lambda n: t^n / (1 + abs(n)), -2, 2, add_one=True)
1/3*t^-3 + 5/6*t^-2 + 13/9*t^-1 + 25/9 + 13/9*t + 5/6*t^2 + 1/3*t^3
sage: L.prod(lambda n: t^-2 + t^n / n, -4, -2)
1/24*t^-9 - 1/8*t^-8 - 1/6*t^-7 + 1/2*t^-6

sage: D = LazyDirichletSeriesRing(QQ, "s")
sage: D.prod(lambda p: (1+D(1, valuation=p)).inverse(), Primes())
1 - 1/(2^s) - 1/(3^s) + 1/(4^s) - 1/(5^s) + 1/(6^s) - 1/(7^s) + O(1/(8^s))

sage: D.prod(lambda p: D(1, valuation=p), Primes(), add_one=True)
1 + 1/(2^s) + 1/(3^s) + 1/(5^s) + 1/(6^s) + 1/(7^s) + O(1/(8^s))
sum(f, a=None, b=+Infinity)#

The sum of elements of self.

INPUT:

  • f – a list (or iterable or function) of elements of self

  • a, b – optional arguments

If a and b are both integers, then this returns the sum \(\sum_{i=a}^b f(i)\). If b is not specified, then we consider \(b = \infty\). Note this corresponds to the Python range(a, b+1).

If \(a\) is any other iterable, then this returns the sum \(\sum{i \in a} f(i)\).

Warning

When f is an infinite generator, then the first argument a must be True. Otherwise this will loop forever.

Warning

For an infinite sum of the form \(\sum_i s_i\), if \(s_i = 0\), then this will loop forever.

EXAMPLES:

sage: L.<t> = LazyLaurentSeriesRing(QQ)
sage: L.sum(lambda n: t^n / (n+1), PositiveIntegers())
1/2*t + 1/3*t^2 + 1/4*t^3 + 1/5*t^4 + 1/6*t^5 + 1/7*t^6 + 1/8*t^7 + O(t^8)

sage: L.<z> = LazyPowerSeriesRing(QQ)
sage: T = L.undefined(1)
sage: D = L.undefined(0)
sage: H = L.sum(lambda k: T(z^k)/k, 2)
sage: T.define(z*exp(T)*D)
sage: D.define(exp(H))
sage: T
z + z^2 + 2*z^3 + 4*z^4 + 9*z^5 + 20*z^6 + 48*z^7 + O(z^8)
sage: D
1 + 1/2*z^2 + 1/3*z^3 + 7/8*z^4 + 11/30*z^5 + 281/144*z^6 + O(z^7)

We verify the Rogers-Ramanujan identities up to degree 100:

sage: L.<q> = LazyPowerSeriesRing(QQ)
sage: Gpi = L.prod(lambda k: -q^(1+5*k), 0, oo, add_one=True)
sage: Gpi *= L.prod(lambda k: -q^(4+5*k), 0, oo, add_one=True)
sage: Gp = 1 / Gpi
sage: G = L.sum(lambda n: q^(n^2) / prod(1 - q^(k+1) for k in range(n)), 0, oo)
sage: G - Gp
O(q^7)
sage: all(G[k] == Gp[k] for k in range(100))
True

sage: Hpi = L.prod(lambda k: -q^(2+5*k), 0, oo, add_one=True)
sage: Hpi *= L.prod(lambda k: -q^(3+5*k), 0, oo, add_one=True)
sage: Hp = 1 / Hpi
sage: H = L.sum(lambda n: q^(n^2+n) / prod(1 - q^(k+1) for k in range(n)), 0, oo)
sage: H - Hp
O(q^7)
sage: all(H[k] == Hp[k] for k in range(100))
True
sage: D = LazyDirichletSeriesRing(QQ, "s")
sage: D.sum(lambda p: D(1, valuation=p), Primes())
1/(2^s) + 1/(3^s) + 1/(5^s) + 1/(7^s) + O(1/(9^s))
undefined(valuation=None)#

Return an uninitialized series.

INPUT:

  • valuation – integer; a lower bound for the valuation of the series

Power series can be defined recursively (see sage.rings.lazy_series.LazyModuleElement.define() for more examples).

EXAMPLES:

sage: L.<z> = LazyPowerSeriesRing(QQ)
sage: s = L.undefined(1)
sage: s.define(z + (s^2+s(z^2))/2)
sage: s
z + z^2 + z^3 + 2*z^4 + 3*z^5 + 6*z^6 + 11*z^7 + O(z^8)

Alternatively:

sage: L.<z> = LazyLaurentSeriesRing(QQ)
sage: f = L(None, valuation=-1)
sage: f.define(z^-1 + z^2*f^2)
sage: f
z^-1 + 1 + 2*z + 5*z^2 + 14*z^3 + 42*z^4 + 132*z^5 + O(z^6)
unknown(valuation=None)#

Return an uninitialized series.

INPUT:

  • valuation – integer; a lower bound for the valuation of the series

Power series can be defined recursively (see sage.rings.lazy_series.LazyModuleElement.define() for more examples).

EXAMPLES:

sage: L.<z> = LazyPowerSeriesRing(QQ)
sage: s = L.undefined(1)
sage: s.define(z + (s^2+s(z^2))/2)
sage: s
z + z^2 + z^3 + 2*z^4 + 3*z^5 + 6*z^6 + 11*z^7 + O(z^8)

Alternatively:

sage: L.<z> = LazyLaurentSeriesRing(QQ)
sage: f = L(None, valuation=-1)
sage: f.define(z^-1 + z^2*f^2)
sage: f
z^-1 + 1 + 2*z + 5*z^2 + 14*z^3 + 42*z^4 + 132*z^5 + O(z^6)
zero()#

Return the zero series.

EXAMPLES:

sage: L = LazyLaurentSeriesRing(ZZ, 'z')
sage: L.zero()
0

sage: s = SymmetricFunctions(ZZ).s()                                        # needs sage.modules
sage: L = LazySymmetricFunctions(s)                                         # needs sage.modules
sage: L.zero()                                                              # needs sage.modules
0

sage: L = LazyDirichletSeriesRing(ZZ, 'z')
sage: L.zero()
0

sage: L = LazyPowerSeriesRing(ZZ, 'z')
sage: L.zero()
0
class sage.rings.lazy_series_ring.LazySymmetricFunctions(basis, sparse=True, category=None)#

Bases: LazyCompletionGradedAlgebra

The ring of lazy symmetric functions.

INPUT:

  • basis – the ring of symmetric functions

  • names – name(s) of the alphabets

  • sparse – (default: True) whether we use a sparse or a dense representation

EXAMPLES:

sage: s = SymmetricFunctions(ZZ).s()                                            # needs sage.modules
sage: LazySymmetricFunctions(s)                                                 # needs sage.modules
Lazy completion of Symmetric Functions over Integer Ring in the Schur basis

sage: m = SymmetricFunctions(ZZ).m()                                            # needs sage.modules
sage: LazySymmetricFunctions(tensor([s, m]))                                    # needs sage.modules
Lazy completion of
 Symmetric Functions over Integer Ring in the Schur basis
  # Symmetric Functions over Integer Ring in the monomial basis
Element#

alias of LazySymmetricFunction