Streams¶
This module provides lazy implementations of basic operators on streams. The classes implemented in this module can be used to build up more complex streams for different kinds of series (Laurent, Dirichlet, etc.).
EXAMPLES:
Streams can be used as data structure for lazy Laurent series:
sage: L.<z> = LazyLaurentSeriesRing(ZZ)
sage: f = L(lambda n: n, valuation=0)
sage: f
z + 2*z^2 + 3*z^3 + 4*z^4 + 5*z^5 + 6*z^6 + O(z^7)
sage: type(f._coeff_stream)
<class 'sage.data_structures.stream.Stream_function'>
>>> from sage.all import *
>>> L = LazyLaurentSeriesRing(ZZ, names=('z',)); (z,) = L._first_ngens(1)
>>> f = L(lambda n: n, valuation=Integer(0))
>>> f
z + 2*z^2 + 3*z^3 + 4*z^4 + 5*z^5 + 6*z^6 + O(z^7)
>>> type(f._coeff_stream)
<class 'sage.data_structures.stream.Stream_function'>
There are basic unary and binary operators available for streams. For example, we can add two streams:
sage: from sage.data_structures.stream import *
sage: f = Stream_function(lambda n: n, True, 0)
sage: [f[i] for i in range(10)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
sage: g = Stream_function(lambda n: 1, True, 0)
sage: [g[i] for i in range(10)]
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
sage: h = Stream_add(f, g, True)
sage: [h[i] for i in range(10)]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> from sage.all import *
>>> from sage.data_structures.stream import *
>>> f = Stream_function(lambda n: n, True, Integer(0))
>>> [f[i] for i in range(Integer(10))]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> g = Stream_function(lambda n: Integer(1), True, Integer(0))
>>> [g[i] for i in range(Integer(10))]
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
>>> h = Stream_add(f, g, True)
>>> [h[i] for i in range(Integer(10))]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
We can subtract one stream from another:
sage: h = Stream_sub(f, g, True)
sage: [h[i] for i in range(10)]
[-1, 0, 1, 2, 3, 4, 5, 6, 7, 8]
>>> from sage.all import *
>>> h = Stream_sub(f, g, True)
>>> [h[i] for i in range(Integer(10))]
[-1, 0, 1, 2, 3, 4, 5, 6, 7, 8]
There is a Cauchy product on streams:
sage: h = Stream_cauchy_mul(f, g, True)
sage: [h[i] for i in range(10)]
[0, 1, 3, 6, 10, 15, 21, 28, 36, 45]
>>> from sage.all import *
>>> h = Stream_cauchy_mul(f, g, True)
>>> [h[i] for i in range(Integer(10))]
[0, 1, 3, 6, 10, 15, 21, 28, 36, 45]
We can compute the inverse corresponding to the Cauchy product:
sage: ginv = Stream_cauchy_invert(g)
sage: h = Stream_cauchy_mul(f, ginv, True)
sage: [h[i] for i in range(10)]
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1]
>>> from sage.all import *
>>> ginv = Stream_cauchy_invert(g)
>>> h = Stream_cauchy_mul(f, ginv, True)
>>> [h[i] for i in range(Integer(10))]
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1]
Two streams can be composed:
sage: g = Stream_function(lambda n: n, True, 1)
sage: h = Stream_cauchy_compose(f, g, True)
sage: [h[i] for i in range(10)]
[0, 1, 4, 14, 46, 145, 444, 1331, 3926, 11434]
>>> from sage.all import *
>>> g = Stream_function(lambda n: n, True, Integer(1))
>>> h = Stream_cauchy_compose(f, g, True)
>>> [h[i] for i in range(Integer(10))]
[0, 1, 4, 14, 46, 145, 444, 1331, 3926, 11434]
There is a unary negation operator:
sage: h = Stream_neg(f, True)
sage: [h[i] for i in range(10)]
[0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
>>> from sage.all import *
>>> h = Stream_neg(f, True)
>>> [h[i] for i in range(Integer(10))]
[0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
More generally, we can multiply by a scalar:
sage: h = Stream_lmul(f, 2, True)
sage: [h[i] for i in range(10)]
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
>>> from sage.all import *
>>> h = Stream_lmul(f, Integer(2), True)
>>> [h[i] for i in range(Integer(10))]
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
Finally, we can apply an arbitrary functions to the elements of a stream:
sage: h = Stream_map_coefficients(f, lambda n: n^2, True)
sage: [h[i] for i in range(10)]
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
>>> from sage.all import *
>>> h = Stream_map_coefficients(f, lambda n: n**Integer(2), True)
>>> [h[i] for i in range(Integer(10))]
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
AUTHORS:
- Kwankyu Lee (2019-02-24): initial version 
- Tejasvi Chebrolu, Martin Rubey, Travis Scrimshaw (2021-08): refactored and expanded functionality 
- class sage.data_structures.stream.CoefficientRing(base_ring)[source]¶
- Bases: - UniqueRepresentation,- FractionField_generic- The class of unknown coefficients in a stream. - gen(i)[source]¶
- Return the - n-th generator of- self.- The name of the generator is not to be relied on. - EXAMPLES: - sage: from sage.data_structures.stream import CoefficientRing sage: PF = CoefficientRing(ZZ["q"]) sage: PF.gen(0) FESDUMMY_0 - >>> from sage.all import * >>> from sage.data_structures.stream import CoefficientRing >>> PF = CoefficientRing(ZZ["q"]) >>> PF.gen(Integer(0)) FESDUMMY_0 
 
- class sage.data_structures.stream.DominatingAction[source]¶
- Bases: - Action- The action defined by - Gacting on- Sby any operation such that the result is either in- Gif- Sis in the base ring of- Gor- Gis the coefficient ring of- Sotherwise.- This is meant specifically for use by - CoefficientRingas part of the function solver. This is not a mathematically defined action of- Gon- Ssince the result might not be in- S.
- class sage.data_structures.stream.Stream(true_order)[source]¶
- Bases: - object- Abstract base class for all streams. - INPUT: - true_order– boolean; if the approximate order is the actual order
 - Note - An implementation of a stream class depending on other stream classes must not access coefficients or the approximate order of these, in order not to interfere with lazy definitions for - Stream_uninitialized.- If an approximate order or even the true order is known, it must be set after calling - super().__init__.- Otherwise, a lazy attribute - _approximate_orderhas to be defined. Any initialization code depending on the approximate orders of input streams can be put into this definition.- However, keep in mind that (trivially) this initialization code is not executed if - _approximate_orderis set to a value before it is accessed.- input_streams()[source]¶
- Return the list of streams which are used to compute the coefficients of - self.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_zero sage: z = Stream_zero() sage: z.input_streams() [] - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_zero >>> z = Stream_zero() >>> z.input_streams() [] 
 - is_nonzero()[source]¶
- Return - Trueif and only if this stream is known to be nonzero.- The default implementation is - False.- EXAMPLES: - sage: from sage.data_structures.stream import Stream sage: CS = Stream(1) sage: CS.is_nonzero() False - >>> from sage.all import * >>> from sage.data_structures.stream import Stream >>> CS = Stream(Integer(1)) >>> CS.is_nonzero() False 
 - is_uninitialized()[source]¶
- Return - Trueif- selfis an uninitialized stream.- The default implementation is - False.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_zero sage: zero = Stream_zero() sage: zero.is_uninitialized() False - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_zero >>> zero = Stream_zero() >>> zero.is_uninitialized() False 
 - order()[source]¶
- Return the order of - self, which is the minimum index- nsuch that- self[n]is non-zero.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_function sage: f = Stream_function(lambda n: n, True, 0) sage: f.order() 1 - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_function >>> f = Stream_function(lambda n: n, True, Integer(0)) >>> f.order() 1 
 
- class sage.data_structures.stream.Stream_add(left, right, is_sparse)[source]¶
- Bases: - Stream_binaryCommutative- Operator for addition of two coefficient streams. - INPUT: - left–- Streamof coefficients on the left side of the operator
- right–- Streamof coefficients on the right side of the operator
- is_sparse– boolean; whether the implementation of the stream is sparse
 - EXAMPLES: - sage: from sage.data_structures.stream import (Stream_add, Stream_function) sage: f = Stream_function(lambda n: n, True, 0) sage: g = Stream_function(lambda n: 1, True, 0) sage: h = Stream_add(f, g, True) sage: [h[i] for i in range(10)] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] sage: u = Stream_add(g, f, True) sage: [u[i] for i in range(10)] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_add, Stream_function) >>> f = Stream_function(lambda n: n, True, Integer(0)) >>> g = Stream_function(lambda n: Integer(1), True, Integer(0)) >>> h = Stream_add(f, g, True) >>> [h[i] for i in range(Integer(10))] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> u = Stream_add(g, f, True) >>> [u[i] for i in range(Integer(10))] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - get_coefficient(n)[source]¶
- Return the - n-th coefficient of- self.- INPUT: - n– integer; the degree for the coefficient
 - EXAMPLES: - sage: from sage.data_structures.stream import (Stream_function, Stream_add) sage: f = Stream_function(lambda n: n, True, 0) sage: g = Stream_function(lambda n: n^2, True, 0) sage: h = Stream_add(f, g, True) sage: h.get_coefficient(5) 30 sage: [h.get_coefficient(i) for i in range(10)] [0, 2, 6, 12, 20, 30, 42, 56, 72, 90] - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_function, Stream_add) >>> f = Stream_function(lambda n: n, True, Integer(0)) >>> g = Stream_function(lambda n: n**Integer(2), True, Integer(0)) >>> h = Stream_add(f, g, True) >>> h.get_coefficient(Integer(5)) 30 >>> [h.get_coefficient(i) for i in range(Integer(10))] [0, 2, 6, 12, 20, 30, 42, 56, 72, 90] 
 
- class sage.data_structures.stream.Stream_binary(left, right, is_sparse)[source]¶
- Bases: - Stream_inexact- Base class for binary operators on coefficient streams. - INPUT: - EXAMPLES: - sage: from sage.data_structures.stream import (Stream_function, Stream_add, Stream_sub) sage: f = Stream_function(lambda n: 2*n, True, 0) sage: g = Stream_function(lambda n: n, True, 1) sage: h = Stream_add(f, g, True) sage: [h[i] for i in range(10)] [0, 3, 6, 9, 12, 15, 18, 21, 24, 27] sage: h = Stream_sub(f, g, True) sage: [h[i] for i in range(10)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_function, Stream_add, Stream_sub) >>> f = Stream_function(lambda n: Integer(2)*n, True, Integer(0)) >>> g = Stream_function(lambda n: n, True, Integer(1)) >>> h = Stream_add(f, g, True) >>> [h[i] for i in range(Integer(10))] [0, 3, 6, 9, 12, 15, 18, 21, 24, 27] >>> h = Stream_sub(f, g, True) >>> [h[i] for i in range(Integer(10))] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - input_streams()[source]¶
- Return the list of streams which are used to compute the coefficients of - self.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_function, Stream_add sage: l = Stream_function(lambda n: n, False, 1) sage: r = Stream_function(lambda n: n^2, False, 1) sage: M = Stream_add(l, r, False) sage: M.input_streams() [<sage.data_structures.stream.Stream_function object at ...>, <sage.data_structures.stream.Stream_function object at ...>] - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_function, Stream_add >>> l = Stream_function(lambda n: n, False, Integer(1)) >>> r = Stream_function(lambda n: n**Integer(2), False, Integer(1)) >>> M = Stream_add(l, r, False) >>> M.input_streams() [<sage.data_structures.stream.Stream_function object at ...>, <sage.data_structures.stream.Stream_function object at ...>] 
 - is_uninitialized()[source]¶
- Return - Trueif- selfis an uninitialized stream.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_uninitialized, Stream_sub, Stream_function sage: C = Stream_uninitialized(0) sage: F = Stream_function(lambda n: n, True, 0) sage: B = Stream_sub(F, C, True) sage: B.is_uninitialized() True sage: Bp = Stream_sub(F, F, True) sage: Bp.is_uninitialized() False - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_uninitialized, Stream_sub, Stream_function >>> C = Stream_uninitialized(Integer(0)) >>> F = Stream_function(lambda n: n, True, Integer(0)) >>> B = Stream_sub(F, C, True) >>> B.is_uninitialized() True >>> Bp = Stream_sub(F, F, True) >>> Bp.is_uninitialized() False 
 
- class sage.data_structures.stream.Stream_binaryCommutative(left, right, is_sparse)[source]¶
- Bases: - Stream_binary- Base class for commutative binary operators on coefficient streams. - EXAMPLES: - sage: from sage.data_structures.stream import (Stream_function, Stream_add) sage: f = Stream_function(lambda n: 2*n, True, 0) sage: g = Stream_function(lambda n: n, True, 1) sage: h = Stream_add(f, g, True) sage: [h[i] for i in range(10)] [0, 3, 6, 9, 12, 15, 18, 21, 24, 27] sage: u = Stream_add(g, f, True) sage: [u[i] for i in range(10)] [0, 3, 6, 9, 12, 15, 18, 21, 24, 27] sage: h == u True - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_function, Stream_add) >>> f = Stream_function(lambda n: Integer(2)*n, True, Integer(0)) >>> g = Stream_function(lambda n: n, True, Integer(1)) >>> h = Stream_add(f, g, True) >>> [h[i] for i in range(Integer(10))] [0, 3, 6, 9, 12, 15, 18, 21, 24, 27] >>> u = Stream_add(g, f, True) >>> [u[i] for i in range(Integer(10))] [0, 3, 6, 9, 12, 15, 18, 21, 24, 27] >>> h == u True 
- class sage.data_structures.stream.Stream_cauchy_compose(f, g, is_sparse)[source]¶
- Bases: - Stream_binary- Return - fcomposed by- g.- This is the composition \((f \circ g)(z) = f(g(z))\). - INPUT: - EXAMPLES: - sage: from sage.data_structures.stream import Stream_cauchy_compose, Stream_function sage: f = Stream_function(lambda n: n, True, 1) sage: g = Stream_function(lambda n: 1, True, 1) sage: h = Stream_cauchy_compose(f, g, True) sage: [h[i] for i in range(10)] [0, 1, 3, 8, 20, 48, 112, 256, 576, 1280] sage: u = Stream_cauchy_compose(g, f, True) sage: [u[i] for i in range(10)] [0, 1, 3, 8, 21, 55, 144, 377, 987, 2584] - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_cauchy_compose, Stream_function >>> f = Stream_function(lambda n: n, True, Integer(1)) >>> g = Stream_function(lambda n: Integer(1), True, Integer(1)) >>> h = Stream_cauchy_compose(f, g, True) >>> [h[i] for i in range(Integer(10))] [0, 1, 3, 8, 20, 48, 112, 256, 576, 1280] >>> u = Stream_cauchy_compose(g, f, True) >>> [u[i] for i in range(Integer(10))] [0, 1, 3, 8, 21, 55, 144, 377, 987, 2584] - get_coefficient(n)[source]¶
- Return the - n-th coefficient of- self.- INPUT: - n– integer; the degree for the coefficient
 - EXAMPLES: - sage: from sage.data_structures.stream import Stream_function, Stream_cauchy_compose sage: f = Stream_function(lambda n: n, True, 1) sage: g = Stream_function(lambda n: n^2, True, 1) sage: h = Stream_cauchy_compose(f, g, True) sage: h[5] # indirect doctest 527 sage: [h[i] for i in range(10)] # indirect doctest [0, 1, 6, 28, 124, 527, 2172, 8755, 34704, 135772] - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_function, Stream_cauchy_compose >>> f = Stream_function(lambda n: n, True, Integer(1)) >>> g = Stream_function(lambda n: n**Integer(2), True, Integer(1)) >>> h = Stream_cauchy_compose(f, g, True) >>> h[Integer(5)] # indirect doctest 527 >>> [h[i] for i in range(Integer(10))] # indirect doctest [0, 1, 6, 28, 124, 527, 2172, 8755, 34704, 135772] 
 
- class sage.data_structures.stream.Stream_cauchy_invert(series, approximate_order=None)[source]¶
- Bases: - Stream_unary- Operator for multiplicative inverse of the stream. - INPUT: - series– a- Stream
- approximate_order–- None, or a lower bound on the order of the resulting stream
 - Instances of this class are always dense, because of mathematical necessities. - EXAMPLES: - sage: from sage.data_structures.stream import (Stream_cauchy_invert, Stream_function) sage: f = Stream_function(lambda n: 1, True, 1) sage: g = Stream_cauchy_invert(f) sage: [g[i] for i in range(10)] [-1, 0, 0, 0, 0, 0, 0, 0, 0, 0] - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_cauchy_invert, Stream_function) >>> f = Stream_function(lambda n: Integer(1), True, Integer(1)) >>> g = Stream_cauchy_invert(f) >>> [g[i] for i in range(Integer(10))] [-1, 0, 0, 0, 0, 0, 0, 0, 0, 0] - is_nonzero()[source]¶
- Return - Trueif and only if this stream is known to be nonzero.- An assumption of this class is that it is nonzero. - EXAMPLES: - sage: from sage.data_structures.stream import (Stream_cauchy_invert, Stream_function) sage: f = Stream_function(lambda n: n^2, False, 1) sage: g = Stream_cauchy_invert(f) sage: g.is_nonzero() True - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_cauchy_invert, Stream_function) >>> f = Stream_function(lambda n: n**Integer(2), False, Integer(1)) >>> g = Stream_cauchy_invert(f) >>> g.is_nonzero() True 
 - iterate_coefficients()[source]¶
- A generator for the coefficients of - self.- EXAMPLES: - sage: from sage.data_structures.stream import (Stream_cauchy_invert, Stream_function) sage: f = Stream_function(lambda n: n^2, False, 1) sage: g = Stream_cauchy_invert(f) sage: n = g.iterate_coefficients() sage: [next(n) for i in range(10)] [1, -4, 7, -8, 8, -8, 8, -8, 8, -8] - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_cauchy_invert, Stream_function) >>> f = Stream_function(lambda n: n**Integer(2), False, Integer(1)) >>> g = Stream_cauchy_invert(f) >>> n = g.iterate_coefficients() >>> [next(n) for i in range(Integer(10))] [1, -4, 7, -8, 8, -8, 8, -8, 8, -8] 
 
- class sage.data_structures.stream.Stream_cauchy_mul(left, right, is_sparse)[source]¶
- Bases: - Stream_binary- Operator for multiplication of two coefficient streams using the Cauchy product. - We are not assuming commutativity of the coefficient ring here, only that the coefficient ring commutes with the (implicit) variable. - INPUT: - left–- Streamof coefficients on the left side of the operator
- right–- Streamof coefficients on the right side of the operator
- is_sparse– boolean; whether the implementation of the stream is sparse
 - EXAMPLES: - sage: from sage.data_structures.stream import (Stream_cauchy_mul, Stream_function) sage: f = Stream_function(lambda n: n, True, 0) sage: g = Stream_function(lambda n: 1, True, 0) sage: h = Stream_cauchy_mul(f, g, True) sage: [h[i] for i in range(10)] [0, 1, 3, 6, 10, 15, 21, 28, 36, 45] sage: u = Stream_cauchy_mul(g, f, True) sage: [u[i] for i in range(10)] [0, 1, 3, 6, 10, 15, 21, 28, 36, 45] - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_cauchy_mul, Stream_function) >>> f = Stream_function(lambda n: n, True, Integer(0)) >>> g = Stream_function(lambda n: Integer(1), True, Integer(0)) >>> h = Stream_cauchy_mul(f, g, True) >>> [h[i] for i in range(Integer(10))] [0, 1, 3, 6, 10, 15, 21, 28, 36, 45] >>> u = Stream_cauchy_mul(g, f, True) >>> [u[i] for i in range(Integer(10))] [0, 1, 3, 6, 10, 15, 21, 28, 36, 45] - get_coefficient(n)[source]¶
- Return the - n-th coefficient of- self.- INPUT: - n– integer; the degree for the coefficient
 - EXAMPLES: - sage: from sage.data_structures.stream import (Stream_function, Stream_cauchy_mul) sage: f = Stream_function(lambda n: n, True, 0) sage: g = Stream_function(lambda n: n^2, True, 0) sage: h = Stream_cauchy_mul(f, g, True) sage: h.get_coefficient(5) 50 sage: [h.get_coefficient(i) for i in range(10)] [0, 0, 1, 6, 20, 50, 105, 196, 336, 540] - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_function, Stream_cauchy_mul) >>> f = Stream_function(lambda n: n, True, Integer(0)) >>> g = Stream_function(lambda n: n**Integer(2), True, Integer(0)) >>> h = Stream_cauchy_mul(f, g, True) >>> h.get_coefficient(Integer(5)) 50 >>> [h.get_coefficient(i) for i in range(Integer(10))] [0, 0, 1, 6, 20, 50, 105, 196, 336, 540] 
 - is_nonzero()[source]¶
- Return - Trueif and only if this stream is known to be nonzero.- EXAMPLES: - sage: from sage.data_structures.stream import (Stream_function, ....: Stream_cauchy_mul, Stream_cauchy_invert) sage: f = Stream_function(lambda n: n, True, 1) sage: g = Stream_cauchy_mul(f, f, True) sage: g.is_nonzero() False sage: fi = Stream_cauchy_invert(f) sage: h = Stream_cauchy_mul(fi, fi, True) sage: h.is_nonzero() True - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_function, ... Stream_cauchy_mul, Stream_cauchy_invert) >>> f = Stream_function(lambda n: n, True, Integer(1)) >>> g = Stream_cauchy_mul(f, f, True) >>> g.is_nonzero() False >>> fi = Stream_cauchy_invert(f) >>> h = Stream_cauchy_mul(fi, fi, True) >>> h.is_nonzero() True 
 
- class sage.data_structures.stream.Stream_cauchy_mul_commutative(left, right, is_sparse)[source]¶
- Bases: - Stream_cauchy_mul,- Stream_binaryCommutative- Operator for multiplication of two coefficient streams using the Cauchy product for commutative multiplication of coefficients. 
- class sage.data_structures.stream.Stream_derivative(series, shift, is_sparse)[source]¶
- Bases: - Stream_unary- Operator for taking derivatives of a non-exact stream. - Instances of this class share the cache with its input stream. - INPUT: - series– a- Stream
- shift– positive integer
- is_sparse– boolean
 - is_nonzero()[source]¶
- Return - Trueif and only if this stream is known to be nonzero.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_exact, Stream_derivative sage: f = Stream_exact([1,2]) sage: Stream_derivative(f, 1, True).is_nonzero() True sage: Stream_derivative(f, 2, True).is_nonzero() # it might be nice if this gave False True - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_exact, Stream_derivative >>> f = Stream_exact([Integer(1),Integer(2)]) >>> Stream_derivative(f, Integer(1), True).is_nonzero() True >>> Stream_derivative(f, Integer(2), True).is_nonzero() # it might be nice if this gave False True 
 
- class sage.data_structures.stream.Stream_dirichlet_convolve(left, right, is_sparse)[source]¶
- Bases: - Stream_binary- Operator for the Dirichlet convolution of two streams. - INPUT: - left–- Streamof coefficients on the left side of the operator
- right–- Streamof coefficients on the right side of the operator
 - The coefficient of \(n^{-s}\) in the convolution of \(l\) and \(r\) equals \(\sum_{k | n} l_k r_{n/k}\). - EXAMPLES: - sage: from sage.data_structures.stream import (Stream_dirichlet_convolve, Stream_function, Stream_exact) sage: f = Stream_function(lambda n: n, True, 1) sage: g = Stream_exact([0], constant=1) sage: h = Stream_dirichlet_convolve(f, g, True) sage: [h[i] for i in range(1, 10)] [1, 3, 4, 7, 6, 12, 8, 15, 13] sage: [sigma(n) for n in range(1, 10)] [1, 3, 4, 7, 6, 12, 8, 15, 13] sage: u = Stream_dirichlet_convolve(g, f, True) sage: [u[i] for i in range(1, 10)] [1, 3, 4, 7, 6, 12, 8, 15, 13] - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_dirichlet_convolve, Stream_function, Stream_exact) >>> f = Stream_function(lambda n: n, True, Integer(1)) >>> g = Stream_exact([Integer(0)], constant=Integer(1)) >>> h = Stream_dirichlet_convolve(f, g, True) >>> [h[i] for i in range(Integer(1), Integer(10))] [1, 3, 4, 7, 6, 12, 8, 15, 13] >>> [sigma(n) for n in range(Integer(1), Integer(10))] [1, 3, 4, 7, 6, 12, 8, 15, 13] >>> u = Stream_dirichlet_convolve(g, f, True) >>> [u[i] for i in range(Integer(1), Integer(10))] [1, 3, 4, 7, 6, 12, 8, 15, 13] - get_coefficient(n)[source]¶
- Return the - n-th coefficient of- self.- INPUT: - n– integer; the degree for the coefficient
 - EXAMPLES: - sage: from sage.data_structures.stream import (Stream_dirichlet_convolve, Stream_function, Stream_exact) sage: f = Stream_function(lambda n: n, True, 1) sage: g = Stream_exact([0], constant=1) sage: h = Stream_dirichlet_convolve(f, g, True) sage: h.get_coefficient(7) 8 sage: [h[i] for i in range(1, 10)] [1, 3, 4, 7, 6, 12, 8, 15, 13] - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_dirichlet_convolve, Stream_function, Stream_exact) >>> f = Stream_function(lambda n: n, True, Integer(1)) >>> g = Stream_exact([Integer(0)], constant=Integer(1)) >>> h = Stream_dirichlet_convolve(f, g, True) >>> h.get_coefficient(Integer(7)) 8 >>> [h[i] for i in range(Integer(1), Integer(10))] [1, 3, 4, 7, 6, 12, 8, 15, 13] 
 
- class sage.data_structures.stream.Stream_dirichlet_invert(series, is_sparse)[source]¶
- Bases: - Stream_unary- Operator for inverse with respect to Dirichlet convolution of the stream. - INPUT: - series– a- Stream
 - EXAMPLES: - sage: from sage.data_structures.stream import (Stream_dirichlet_invert, Stream_function) sage: f = Stream_function(lambda n: 1, True, 1) sage: g = Stream_dirichlet_invert(f, True) sage: [g[i] for i in range(10)] [0, 1, -1, -1, 0, -1, 1, -1, 0, 0] sage: [moebius(i) for i in range(10)] # needs sage.libs.pari [0, 1, -1, -1, 0, -1, 1, -1, 0, 0] - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_dirichlet_invert, Stream_function) >>> f = Stream_function(lambda n: Integer(1), True, Integer(1)) >>> g = Stream_dirichlet_invert(f, True) >>> [g[i] for i in range(Integer(10))] [0, 1, -1, -1, 0, -1, 1, -1, 0, 0] >>> [moebius(i) for i in range(Integer(10))] # needs sage.libs.pari [0, 1, -1, -1, 0, -1, 1, -1, 0, 0] - get_coefficient(n)[source]¶
- Return the - n-th coefficient of- self.- INPUT: - n– integer; the degree for the coefficient
 - EXAMPLES: - sage: from sage.data_structures.stream import (Stream_exact, Stream_dirichlet_invert) sage: f = Stream_exact([0, 3], constant=2) sage: g = Stream_dirichlet_invert(f, True) sage: g.get_coefficient(6) 2/27 sage: [g[i] for i in range(8)] [0, 1/3, -2/9, -2/9, -2/27, -2/9, 2/27, -2/9] - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_exact, Stream_dirichlet_invert) >>> f = Stream_exact([Integer(0), Integer(3)], constant=Integer(2)) >>> g = Stream_dirichlet_invert(f, True) >>> g.get_coefficient(Integer(6)) 2/27 >>> [g[i] for i in range(Integer(8))] [0, 1/3, -2/9, -2/9, -2/27, -2/9, 2/27, -2/9] 
 
- class sage.data_structures.stream.Stream_exact(initial_coefficients, constant=None, degree=None, order=None)[source]¶
- Bases: - Stream- A stream of eventually constant coefficients. - INPUT: - initial_values– list of initial values
- is_sparse– boolean; specifies whether the stream is sparse
- order– integer (default: 0); determining the degree of the first element of- initial_values
- degree– integer (optional); determining the degree of the first element which is known to be equal to- constant
- constant– integer (default: 0); the coefficient of every index larger than or equal to- degree
 - Warning - The convention for - orderis different to the one in- sage.rings.lazy_series_ring.LazySeriesRing, where the input is shifted to have the prescribed order.- is_nonzero()[source]¶
- Return - Trueif and only if this stream is known to be nonzero.- An assumption of this class is that it is nonzero. - EXAMPLES: - sage: from sage.data_structures.stream import Stream_exact sage: s = Stream_exact([2], order=-1, degree=2, constant=1) sage: s.is_nonzero() True - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_exact >>> s = Stream_exact([Integer(2)], order=-Integer(1), degree=Integer(2), constant=Integer(1)) >>> s.is_nonzero() True 
 - order()[source]¶
- Return the order of - self, which is the minimum index- nsuch that- self[n]is nonzero.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_exact sage: s = Stream_exact([1]) sage: s.order() 0 - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_exact >>> s = Stream_exact([Integer(1)]) >>> s.order() 0 
 
- class sage.data_structures.stream.Stream_function(function, is_sparse, approximate_order, true_order=False)[source]¶
- Bases: - Stream_inexact- Class that creates a stream from a function on the integers. - INPUT: - function– a function that generates the coefficients of the stream
- is_sparse– boolean; specifies whether the stream is sparse
- approximate_order– integer; a lower bound for the order of the stream
 - Note - We assume for equality that - functionis a function in the mathematical sense.- Warning - To make - sage.rings.lazy_series_ring.LazySeriesRing.define_implicitly()work any streams used in- functionmust appear in its- __closure__as instances of- Stream, as opposed to, for example, as instances of- LazyPowerSeries.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_function sage: f = Stream_function(lambda n: n^2, False, 1) sage: f[3] 9 sage: [f[i] for i in range(10)] [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] sage: f = Stream_function(lambda n: 1, False, 0) sage: n = f.iterate_coefficients() sage: [next(n) for _ in range(10)] [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] sage: f = Stream_function(lambda n: n, True, 0) sage: f[4] 4 - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_function >>> f = Stream_function(lambda n: n**Integer(2), False, Integer(1)) >>> f[Integer(3)] 9 >>> [f[i] for i in range(Integer(10))] [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] >>> f = Stream_function(lambda n: Integer(1), False, Integer(0)) >>> n = f.iterate_coefficients() >>> [next(n) for _ in range(Integer(10))] [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] >>> f = Stream_function(lambda n: n, True, Integer(0)) >>> f[Integer(4)] 4 - input_streams()[source]¶
- Return the list of streams which are used to compute the coefficients of - self, as provided.- EXAMPLES: - Only streams that appear in the closure are detected: - sage: from sage.data_structures.stream import Stream_function, Stream_exact sage: f = Stream_exact([1,3,5], constant=7) sage: g = Stream_function(lambda n: f[n]^2, False, 0) sage: g.input_streams() [] sage: def fun(): ....: f = Stream_exact([1,3,5], constant=7) ....: g = Stream_function(lambda n: f[n]^2, False, 0) ....: return g.input_streams() sage: fun() [<sage.data_structures.stream.Stream_exact object at 0x...>] - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_function, Stream_exact >>> f = Stream_exact([Integer(1),Integer(3),Integer(5)], constant=Integer(7)) >>> g = Stream_function(lambda n: f[n]**Integer(2), False, Integer(0)) >>> g.input_streams() [] >>> def fun(): ... f = Stream_exact([Integer(1),Integer(3),Integer(5)], constant=Integer(7)) ... g = Stream_function(lambda n: f[n]**Integer(2), False, Integer(0)) ... return g.input_streams() >>> fun() [<sage.data_structures.stream.Stream_exact object at 0x...>] 
 
- class sage.data_structures.stream.Stream_inexact(is_sparse, true_order)[source]¶
- Bases: - Stream- An abstract base class for the stream when we do not know it is eventually constant. - In particular, a cache is provided. - INPUT: - is_sparse– boolean; whether the implementation of the stream is sparse
- true_order– boolean; if the approximate order is the actual order
 - If the cache is dense, it begins with the first nonzero term. - is_nonzero()[source]¶
- Return - Trueif and only if the cache contains a nonzero element.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_function sage: CS = Stream_function(lambda n: 1/n, False, 1) sage: CS.is_nonzero() False sage: CS[1] 1 sage: CS.is_nonzero() True - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_function >>> CS = Stream_function(lambda n: Integer(1)/n, False, Integer(1)) >>> CS.is_nonzero() False >>> CS[Integer(1)] 1 >>> CS.is_nonzero() True 
 - iterate_coefficients()[source]¶
- A generator for the coefficients of - self.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_function, Stream_cauchy_compose sage: f = Stream_function(lambda n: 1, False, 1) sage: g = Stream_function(lambda n: n^3, False, 1) sage: h = Stream_cauchy_compose(f, g, True) sage: n = h.iterate_coefficients() sage: [next(n) for i in range(10)] [1, 9, 44, 207, 991, 4752, 22769, 109089, 522676, 2504295] - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_function, Stream_cauchy_compose >>> f = Stream_function(lambda n: Integer(1), False, Integer(1)) >>> g = Stream_function(lambda n: n**Integer(3), False, Integer(1)) >>> h = Stream_cauchy_compose(f, g, True) >>> n = h.iterate_coefficients() >>> [next(n) for i in range(Integer(10))] [1, 9, 44, 207, 991, 4752, 22769, 109089, 522676, 2504295] 
 
- class sage.data_structures.stream.Stream_infinite_operator(iterator)[source]¶
- Bases: - Stream- Stream defined by applying an operator an infinite number of times. - The - iteratorreturns elements \(s_i\) to compute an infinite operator. The valuation of \(s_i\) is weakly increasing as we iterate over \(I\) and there are only finitely many terms with any fixed valuation. In particular, this assumes the result is nonzero.- Warning - This does not check that the input is valid. - INPUT: - iterator– the iterator for the factors
 - is_nonzero()[source]¶
- Return - Trueif and only if this stream is known to be nonzero.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_infinite_sum sage: L.<t> = LazyLaurentSeriesRing(QQ) sage: it = (t^n / (1 - t) for n in PositiveIntegers()) sage: f = Stream_infinite_sum(it) sage: f.is_nonzero() True - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_infinite_sum >>> L = LazyLaurentSeriesRing(QQ, names=('t',)); (t,) = L._first_ngens(1) >>> it = (t**n / (Integer(1) - t) for n in PositiveIntegers()) >>> f = Stream_infinite_sum(it) >>> f.is_nonzero() True 
 - order()[source]¶
- Return the order of - self, which is the minimum index- nsuch that- self[n]is nonzero.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_infinite_sum sage: L.<t> = LazyLaurentSeriesRing(QQ) sage: it = (t^(5+n) / (1 - t) for n in PositiveIntegers()) sage: f = Stream_infinite_sum(it) sage: f.order() 6 - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_infinite_sum >>> L = LazyLaurentSeriesRing(QQ, names=('t',)); (t,) = L._first_ngens(1) >>> it = (t**(Integer(5)+n) / (Integer(1) - t) for n in PositiveIntegers()) >>> f = Stream_infinite_sum(it) >>> f.order() 6 
 
- class sage.data_structures.stream.Stream_infinite_product(iterator)[source]¶
- Bases: - Stream_infinite_operator- Stream defined by an infinite product. - The - iteratorreturns elements \(p_i\) to compute the product \(\prod_{i \in I} (1 + p_i)\). See- Stream_infinite_operatorfor restrictions on the \(p_i\).- INPUT: - iterator– the iterator for the factors
 - apply_operator(next_obj)[source]¶
- Apply the operator to - next_obj.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_infinite_product sage: L.<t> = LazyLaurentSeriesRing(QQ) sage: it = (t^n / (1 - t) for n in PositiveIntegers()) sage: f = Stream_infinite_product(it) sage: f._advance() sage: f._advance() # indirect doctest sage: f._cur 1 + t + 2*t^2 + 4*t^3 + 6*t^4 + 9*t^5 + 13*t^6 + O(t^7) - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_infinite_product >>> L = LazyLaurentSeriesRing(QQ, names=('t',)); (t,) = L._first_ngens(1) >>> it = (t**n / (Integer(1) - t) for n in PositiveIntegers()) >>> f = Stream_infinite_product(it) >>> f._advance() >>> f._advance() # indirect doctest >>> f._cur 1 + t + 2*t^2 + 4*t^3 + 6*t^4 + 9*t^5 + 13*t^6 + O(t^7) 
 - initial(obj)[source]¶
- Set the initial data. - EXAMPLES: - sage: from sage.data_structures.stream import Stream_infinite_product sage: L.<t> = LazyLaurentSeriesRing(QQ) sage: it = (t^n / (1 - t) for n in PositiveIntegers()) sage: f = Stream_infinite_product(it) sage: f._cur is None True sage: f._advance() # indirect doctest sage: f._cur 1 + t + 2*t^2 + 3*t^3 + 4*t^4 + 5*t^5 + 6*t^6 + O(t^7) - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_infinite_product >>> L = LazyLaurentSeriesRing(QQ, names=('t',)); (t,) = L._first_ngens(1) >>> it = (t**n / (Integer(1) - t) for n in PositiveIntegers()) >>> f = Stream_infinite_product(it) >>> f._cur is None True >>> f._advance() # indirect doctest >>> f._cur 1 + t + 2*t^2 + 3*t^3 + 4*t^4 + 5*t^5 + 6*t^6 + O(t^7) 
 
- class sage.data_structures.stream.Stream_infinite_sum(iterator)[source]¶
- Bases: - Stream_infinite_operator- Stream defined by an infinite sum. - The - iteratorreturns elements \(s_i\) to compute the product \(\sum_{i \in I} s_i\). See- Stream_infinite_operatorfor restrictions on the \(s_i\).- INPUT: - iterator– the iterator for the factors
 - apply_operator(next_obj)[source]¶
- Apply the operator to - next_obj.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_infinite_sum sage: L.<t> = LazyLaurentSeriesRing(QQ) sage: it = (t^(n//2) / (1 - t) for n in PositiveIntegers()) sage: f = Stream_infinite_sum(it) sage: f._advance() sage: f._advance() # indirect doctest sage: f._cur 1 + 3*t + 4*t^2 + 4*t^3 + 4*t^4 + O(t^5) - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_infinite_sum >>> L = LazyLaurentSeriesRing(QQ, names=('t',)); (t,) = L._first_ngens(1) >>> it = (t**(n//Integer(2)) / (Integer(1) - t) for n in PositiveIntegers()) >>> f = Stream_infinite_sum(it) >>> f._advance() >>> f._advance() # indirect doctest >>> f._cur 1 + 3*t + 4*t^2 + 4*t^3 + 4*t^4 + O(t^5) 
 - initial(obj)[source]¶
- Set the initial data. - EXAMPLES: - sage: from sage.data_structures.stream import Stream_infinite_sum sage: L.<t> = LazyLaurentSeriesRing(QQ) sage: it = (t^n / (1 - t) for n in PositiveIntegers()) sage: f = Stream_infinite_sum(it) sage: f._cur is None True sage: f._advance() # indirect doctest sage: f._cur t + 2*t^2 + 2*t^3 + 2*t^4 + O(t^5) - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_infinite_sum >>> L = LazyLaurentSeriesRing(QQ, names=('t',)); (t,) = L._first_ngens(1) >>> it = (t**n / (Integer(1) - t) for n in PositiveIntegers()) >>> f = Stream_infinite_sum(it) >>> f._cur is None True >>> f._advance() # indirect doctest >>> f._cur t + 2*t^2 + 2*t^3 + 2*t^4 + O(t^5) 
 
- class sage.data_structures.stream.Stream_integral(series, integration_constants, is_sparse)[source]¶
- Bases: - Stream_unary- Operator for taking integrals of a non-exact stream. - INPUT: - series– a- Stream
- integration_constants– list of integration constants
- is_sparse– boolean
 - get_coefficient(n)[source]¶
- Return the - n-th coefficient of- self.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_function, Stream_integral sage: f = Stream_function(lambda n: n + 1, True, -3) sage: [f[i] for i in range(-3, 4)] [-2, -1, 0, 1, 2, 3, 4] sage: f2 = Stream_integral(f, [0], True) sage: [f2.get_coefficient(i) for i in range(-3, 5)] [0, 1, 1, 0, 1, 1, 1, 1] sage: f = Stream_function(lambda n: (n + 1)*(n+2), True, 2) sage: [f[i] for i in range(-1, 4)] [0, 0, 0, 12, 20] sage: f2 = Stream_integral(f, [-1, -1, -1], True) sage: [f2.get_coefficient(i) for i in range(-1, 7)] [0, -1, -1, -1/2, 0, 0, 1/5, 1/6] - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_function, Stream_integral >>> f = Stream_function(lambda n: n + Integer(1), True, -Integer(3)) >>> [f[i] for i in range(-Integer(3), Integer(4))] [-2, -1, 0, 1, 2, 3, 4] >>> f2 = Stream_integral(f, [Integer(0)], True) >>> [f2.get_coefficient(i) for i in range(-Integer(3), Integer(5))] [0, 1, 1, 0, 1, 1, 1, 1] >>> f = Stream_function(lambda n: (n + Integer(1))*(n+Integer(2)), True, Integer(2)) >>> [f[i] for i in range(-Integer(1), Integer(4))] [0, 0, 0, 12, 20] >>> f2 = Stream_integral(f, [-Integer(1), -Integer(1), -Integer(1)], True) >>> [f2.get_coefficient(i) for i in range(-Integer(1), Integer(7))] [0, -1, -1, -1/2, 0, 0, 1/5, 1/6] 
 - is_nonzero()[source]¶
- Return - Trueif and only if this stream is known to be nonzero.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_function, Stream_integral sage: f = Stream_function(lambda n: 2*n, True, 1) sage: f[1] 2 sage: f.is_nonzero() True sage: Stream_integral(f, [0], True).is_nonzero() True sage: f = Stream_function(lambda n: 0, False, 1) sage: Stream_integral(f, [0, 0, 0], False).is_nonzero() False sage: Stream_integral(f, [0, 2], False).is_nonzero() True - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_function, Stream_integral >>> f = Stream_function(lambda n: Integer(2)*n, True, Integer(1)) >>> f[Integer(1)] 2 >>> f.is_nonzero() True >>> Stream_integral(f, [Integer(0)], True).is_nonzero() True >>> f = Stream_function(lambda n: Integer(0), False, Integer(1)) >>> Stream_integral(f, [Integer(0), Integer(0), Integer(0)], False).is_nonzero() False >>> Stream_integral(f, [Integer(0), Integer(2)], False).is_nonzero() True 
 
- class sage.data_structures.stream.Stream_iterator(iter, approximate_order, true_order=False)[source]¶
- Bases: - Stream_inexact- Class that creates a stream from an iterator. - INPUT: - iter– a function that generates the coefficients of the stream
- approximate_order– integer; a lower bound for the order of the stream
 - Instances of this class are always dense. - EXAMPLES: - sage: from sage.data_structures.stream import Stream_iterator sage: f = Stream_iterator(iter(NonNegativeIntegers()), 0) sage: [f[i] for i in range(10)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] sage: f = Stream_iterator(iter(NonNegativeIntegers()), 1) sage: [f[i] for i in range(10)] [0, 0, 1, 2, 3, 4, 5, 6, 7, 8] - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_iterator >>> f = Stream_iterator(iter(NonNegativeIntegers()), Integer(0)) >>> [f[i] for i in range(Integer(10))] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> f = Stream_iterator(iter(NonNegativeIntegers()), Integer(1)) >>> [f[i] for i in range(Integer(10))] [0, 0, 1, 2, 3, 4, 5, 6, 7, 8] 
- class sage.data_structures.stream.Stream_lmul(series, scalar, is_sparse)[source]¶
- Bases: - Stream_scalar- Operator for multiplying a coefficient stream with a scalar as - self * scalar.- INPUT: - series– a- Stream
- scalar– a nonzero, non-one scalar
 - EXAMPLES: - sage: # needs sage.modules sage: from sage.data_structures.stream import (Stream_lmul, Stream_function) sage: W = algebras.DifferentialWeyl(QQ, names=('x',)) sage: x, dx = W.gens() sage: f = Stream_function(lambda n: x^n, True, 1) sage: g = Stream_lmul(f, dx, True) sage: [g[i] for i in range(5)] [0, x*dx, x^2*dx, x^3*dx, x^4*dx] - >>> from sage.all import * >>> # needs sage.modules >>> from sage.data_structures.stream import (Stream_lmul, Stream_function) >>> W = algebras.DifferentialWeyl(QQ, names=('x',)) >>> x, dx = W.gens() >>> f = Stream_function(lambda n: x**n, True, Integer(1)) >>> g = Stream_lmul(f, dx, True) >>> [g[i] for i in range(Integer(5))] [0, x*dx, x^2*dx, x^3*dx, x^4*dx] - get_coefficient(n)[source]¶
- Return the - n-th coefficient of- self.- INPUT: - n– integer; the degree for the coefficient
 - EXAMPLES: - sage: from sage.data_structures.stream import (Stream_lmul, Stream_function) sage: f = Stream_function(lambda n: n, True, 1) sage: g = Stream_lmul(f, 3, True) sage: g.get_coefficient(5) 15 sage: [g.get_coefficient(i) for i in range(10)] [0, 3, 6, 9, 12, 15, 18, 21, 24, 27] - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_lmul, Stream_function) >>> f = Stream_function(lambda n: n, True, Integer(1)) >>> g = Stream_lmul(f, Integer(3), True) >>> g.get_coefficient(Integer(5)) 15 >>> [g.get_coefficient(i) for i in range(Integer(10))] [0, 3, 6, 9, 12, 15, 18, 21, 24, 27] 
 
- class sage.data_structures.stream.Stream_map_coefficients(series, function, is_sparse, approximate_order=None, true_order=False)[source]¶
- Bases: - Stream_unary- The stream with - functionapplied to each nonzero coefficient of- series.- INPUT: - series– a- Stream
- function– a function that modifies the elements of the stream
 - Note - We assume for equality that - functionis a function in the mathematical sense.- EXAMPLES: - sage: from sage.data_structures.stream import (Stream_map_coefficients, Stream_function) sage: f = Stream_function(lambda n: 1, True, 1) sage: g = Stream_map_coefficients(f, lambda n: -n, True) sage: [g[i] for i in range(10)] [0, -1, -1, -1, -1, -1, -1, -1, -1, -1] - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_map_coefficients, Stream_function) >>> f = Stream_function(lambda n: Integer(1), True, Integer(1)) >>> g = Stream_map_coefficients(f, lambda n: -n, True) >>> [g[i] for i in range(Integer(10))] [0, -1, -1, -1, -1, -1, -1, -1, -1, -1] - get_coefficient(n)[source]¶
- Return the - n-th coefficient of- self.- INPUT: - n– integer; the degree for the coefficient
 - EXAMPLES: - sage: from sage.data_structures.stream import (Stream_map_coefficients, Stream_function) sage: f = Stream_function(lambda n: n, True, -1) sage: g = Stream_map_coefficients(f, lambda n: n^2 + 1, True) sage: g.get_coefficient(5) 26 sage: [g.get_coefficient(i) for i in range(-1, 10)] [2, 0, 2, 5, 10, 17, 26, 37, 50, 65, 82] sage: R.<x,y> = ZZ[] sage: f = Stream_function(lambda n: n, True, -1) sage: g = Stream_map_coefficients(f, lambda n: R(n).degree() + 1, True) sage: [g.get_coefficient(i) for i in range(-1, 3)] [1, 0, 1, 1] - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_map_coefficients, Stream_function) >>> f = Stream_function(lambda n: n, True, -Integer(1)) >>> g = Stream_map_coefficients(f, lambda n: n**Integer(2) + Integer(1), True) >>> g.get_coefficient(Integer(5)) 26 >>> [g.get_coefficient(i) for i in range(-Integer(1), Integer(10))] [2, 0, 2, 5, 10, 17, 26, 37, 50, 65, 82] >>> R = ZZ['x, y']; (x, y,) = R._first_ngens(2) >>> f = Stream_function(lambda n: n, True, -Integer(1)) >>> g = Stream_map_coefficients(f, lambda n: R(n).degree() + Integer(1), True) >>> [g.get_coefficient(i) for i in range(-Integer(1), Integer(3))] [1, 0, 1, 1] 
 
- class sage.data_structures.stream.Stream_neg(series, is_sparse)[source]¶
- Bases: - Stream_unary- Operator for negative of the stream. - INPUT: - series– a- Stream
 - EXAMPLES: - sage: from sage.data_structures.stream import (Stream_neg, Stream_function) sage: f = Stream_function(lambda n: 1, True, 1) sage: g = Stream_neg(f, True) sage: [g[i] for i in range(10)] [0, -1, -1, -1, -1, -1, -1, -1, -1, -1] - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_neg, Stream_function) >>> f = Stream_function(lambda n: Integer(1), True, Integer(1)) >>> g = Stream_neg(f, True) >>> [g[i] for i in range(Integer(10))] [0, -1, -1, -1, -1, -1, -1, -1, -1, -1] - get_coefficient(n)[source]¶
- Return the - n-th coefficient of- self.- INPUT: - n– integer; the degree for the coefficient
 - EXAMPLES: - sage: from sage.data_structures.stream import (Stream_neg, Stream_function) sage: f = Stream_function(lambda n: n, True, 1) sage: g = Stream_neg(f, True) sage: g.get_coefficient(5) -5 sage: [g.get_coefficient(i) for i in range(10)] [0, -1, -2, -3, -4, -5, -6, -7, -8, -9] - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_neg, Stream_function) >>> f = Stream_function(lambda n: n, True, Integer(1)) >>> g = Stream_neg(f, True) >>> g.get_coefficient(Integer(5)) -5 >>> [g.get_coefficient(i) for i in range(Integer(10))] [0, -1, -2, -3, -4, -5, -6, -7, -8, -9] 
 - is_nonzero()[source]¶
- Return - Trueif and only if this stream is known to be nonzero.- EXAMPLES: - sage: from sage.data_structures.stream import (Stream_neg, Stream_function) sage: f = Stream_function(lambda n: n, True, 1) sage: g = Stream_neg(f, True) sage: g.is_nonzero() False sage: from sage.data_structures.stream import Stream_cauchy_invert sage: fi = Stream_cauchy_invert(f) sage: g = Stream_neg(fi, True) sage: g.is_nonzero() True - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_neg, Stream_function) >>> f = Stream_function(lambda n: n, True, Integer(1)) >>> g = Stream_neg(f, True) >>> g.is_nonzero() False >>> from sage.data_structures.stream import Stream_cauchy_invert >>> fi = Stream_cauchy_invert(f) >>> g = Stream_neg(fi, True) >>> g.is_nonzero() True 
 
- class sage.data_structures.stream.Stream_plethysm(f, g, is_sparse, p, ring=None, include=None, exclude=None)[source]¶
- Bases: - Stream_binary- Return the plethysm of - fcomposed by- g.- This is the plethysm \(f \circ g = f(g)\) when \(g\) is an element of a ring of symmetric functions. - INPUT: - f– a- Stream
- g– a- Streamwith positive order, unless- fis of- Stream_exact
- p– the ring of powersum symmetric functions containing- g
- ring– (default:- None) the ring the result should be in, by default- p
- include– list of variables to be treated as degree one elements instead of the default degree one elements
- exclude– list of variables to be excluded from the default degree one elements
 - EXAMPLES: - sage: # needs sage.modules sage: from sage.data_structures.stream import Stream_function, Stream_plethysm sage: s = SymmetricFunctions(QQ).s() sage: p = SymmetricFunctions(QQ).p() sage: f = Stream_function(lambda n: s[n], True, 1) sage: g = Stream_function(lambda n: s[[1]*n], True, 1) sage: h = Stream_plethysm(f, g, True, p, s) sage: [h[i] for i in range(5)] [0, s[1], s[1, 1] + s[2], 2*s[1, 1, 1] + s[2, 1] + s[3], 3*s[1, 1, 1, 1] + 2*s[2, 1, 1] + s[2, 2] + s[3, 1] + s[4]] sage: u = Stream_plethysm(g, f, True, p, s) sage: [u[i] for i in range(5)] [0, s[1], s[1, 1] + s[2], s[1, 1, 1] + s[2, 1] + 2*s[3], s[1, 1, 1, 1] + s[2, 1, 1] + 3*s[3, 1] + 2*s[4]] - >>> from sage.all import * >>> # needs sage.modules >>> from sage.data_structures.stream import Stream_function, Stream_plethysm >>> s = SymmetricFunctions(QQ).s() >>> p = SymmetricFunctions(QQ).p() >>> f = Stream_function(lambda n: s[n], True, Integer(1)) >>> g = Stream_function(lambda n: s[[Integer(1)]*n], True, Integer(1)) >>> h = Stream_plethysm(f, g, True, p, s) >>> [h[i] for i in range(Integer(5))] [0, s[1], s[1, 1] + s[2], 2*s[1, 1, 1] + s[2, 1] + s[3], 3*s[1, 1, 1, 1] + 2*s[2, 1, 1] + s[2, 2] + s[3, 1] + s[4]] >>> u = Stream_plethysm(g, f, True, p, s) >>> [u[i] for i in range(Integer(5))] [0, s[1], s[1, 1] + s[2], s[1, 1, 1] + s[2, 1] + 2*s[3], s[1, 1, 1, 1] + s[2, 1, 1] + 3*s[3, 1] + 2*s[4]] - This class also handles the plethysm of an exact stream with a stream of order \(0\): - sage: # needs sage.modules sage: from sage.data_structures.stream import Stream_exact sage: f = Stream_exact([s[1]], order=1) sage: g = Stream_function(lambda n: s[n], True, 0) sage: r = Stream_plethysm(f, g, True, p, s) sage: [r[n] for n in range(3)] [s[], s[1], s[2]] - >>> from sage.all import * >>> # needs sage.modules >>> from sage.data_structures.stream import Stream_exact >>> f = Stream_exact([s[Integer(1)]], order=Integer(1)) >>> g = Stream_function(lambda n: s[n], True, Integer(0)) >>> r = Stream_plethysm(f, g, True, p, s) >>> [r[n] for n in range(Integer(3))] [s[], s[1], s[2]] - compute_product(n, la)[source]¶
- Compute the product - p[la](self._right)in degree- n.- EXAMPLES: - sage: # needs sage.modules sage: from sage.data_structures.stream import Stream_plethysm, Stream_exact, Stream_function, Stream_zero sage: s = SymmetricFunctions(QQ).s() sage: p = SymmetricFunctions(QQ).p() sage: f = Stream_exact([1]) # irrelevant for this test sage: g = Stream_exact([s[2], s[3]], 0, 4, 2) sage: h = Stream_plethysm(f, g, True, p) sage: A = h.compute_product(7, Partition([2, 1])); A 1/12*p[2, 2, 1, 1, 1] + 1/4*p[2, 2, 2, 1] + 1/6*p[3, 2, 2] + 1/12*p[4, 1, 1, 1] + 1/4*p[4, 2, 1] + 1/6*p[4, 3] sage: A == p[2, 1](s[2] + s[3]).homogeneous_component(7) True sage: # needs sage.modules sage: p2 = tensor([p, p]) sage: f = Stream_exact([1]) # irrelevant for this test sage: g = Stream_function(lambda n: sum(tensor([p[k], p[n-k]]) ....: for k in range(n+1)), True, 1) sage: h = Stream_plethysm(f, g, True, p2) sage: A = h.compute_product(7, Partition([2, 1])) sage: B = p[2, 1](sum(g[n] for n in range(7))) sage: B = p2.element_class(p2, {m: c for m, c in B ....: if sum(mu.size() for mu in m) == 7}) sage: A == B True sage: # needs sage.modules sage: f = Stream_exact([1]) # irrelevant for this test sage: g = Stream_function(lambda n: s[n], True, 0) sage: h = Stream_plethysm(f, g, True, p) sage: B = p[2, 2, 1](sum(p(s[i]) for i in range(7))) sage: all(h.compute_product(k, Partition([2, 2, 1])) ....: == B.restrict_degree(k) for k in range(7)) True - >>> from sage.all import * >>> # needs sage.modules >>> from sage.data_structures.stream import Stream_plethysm, Stream_exact, Stream_function, Stream_zero >>> s = SymmetricFunctions(QQ).s() >>> p = SymmetricFunctions(QQ).p() >>> f = Stream_exact([Integer(1)]) # irrelevant for this test >>> g = Stream_exact([s[Integer(2)], s[Integer(3)]], Integer(0), Integer(4), Integer(2)) >>> h = Stream_plethysm(f, g, True, p) >>> A = h.compute_product(Integer(7), Partition([Integer(2), Integer(1)])); A 1/12*p[2, 2, 1, 1, 1] + 1/4*p[2, 2, 2, 1] + 1/6*p[3, 2, 2] + 1/12*p[4, 1, 1, 1] + 1/4*p[4, 2, 1] + 1/6*p[4, 3] >>> A == p[Integer(2), Integer(1)](s[Integer(2)] + s[Integer(3)]).homogeneous_component(Integer(7)) True >>> # needs sage.modules >>> p2 = tensor([p, p]) >>> f = Stream_exact([Integer(1)]) # irrelevant for this test >>> g = Stream_function(lambda n: sum(tensor([p[k], p[n-k]]) ... for k in range(n+Integer(1))), True, Integer(1)) >>> h = Stream_plethysm(f, g, True, p2) >>> A = h.compute_product(Integer(7), Partition([Integer(2), Integer(1)])) >>> B = p[Integer(2), Integer(1)](sum(g[n] for n in range(Integer(7)))) >>> B = p2.element_class(p2, {m: c for m, c in B ... if sum(mu.size() for mu in m) == Integer(7)}) >>> A == B True >>> # needs sage.modules >>> f = Stream_exact([Integer(1)]) # irrelevant for this test >>> g = Stream_function(lambda n: s[n], True, Integer(0)) >>> h = Stream_plethysm(f, g, True, p) >>> B = p[Integer(2), Integer(2), Integer(1)](sum(p(s[i]) for i in range(Integer(7)))) >>> all(h.compute_product(k, Partition([Integer(2), Integer(2), Integer(1)])) ... == B.restrict_degree(k) for k in range(Integer(7))) True 
 - get_coefficient(n)[source]¶
- Return the - n-th coefficient of- self.- INPUT: - n– integer; the degree for the coefficient
 - EXAMPLES: - sage: # needs sage.modules sage: from sage.data_structures.stream import Stream_function, Stream_plethysm sage: s = SymmetricFunctions(QQ).s() sage: p = SymmetricFunctions(QQ).p() sage: f = Stream_function(lambda n: s[n], True, 1) sage: g = Stream_function(lambda n: s[[1]*n], True, 1) sage: h = Stream_plethysm(f, g, True, p) sage: s(h.get_coefficient(5)) 4*s[1, 1, 1, 1, 1] + 4*s[2, 1, 1, 1] + 2*s[2, 2, 1] + 2*s[3, 1, 1] + s[3, 2] + s[4, 1] + s[5] sage: [s(h.get_coefficient(i)) for i in range(6)] [0, s[1], s[1, 1] + s[2], 2*s[1, 1, 1] + s[2, 1] + s[3], 3*s[1, 1, 1, 1] + 2*s[2, 1, 1] + s[2, 2] + s[3, 1] + s[4], 4*s[1, 1, 1, 1, 1] + 4*s[2, 1, 1, 1] + 2*s[2, 2, 1] + 2*s[3, 1, 1] + s[3, 2] + s[4, 1] + s[5]] - >>> from sage.all import * >>> # needs sage.modules >>> from sage.data_structures.stream import Stream_function, Stream_plethysm >>> s = SymmetricFunctions(QQ).s() >>> p = SymmetricFunctions(QQ).p() >>> f = Stream_function(lambda n: s[n], True, Integer(1)) >>> g = Stream_function(lambda n: s[[Integer(1)]*n], True, Integer(1)) >>> h = Stream_plethysm(f, g, True, p) >>> s(h.get_coefficient(Integer(5))) 4*s[1, 1, 1, 1, 1] + 4*s[2, 1, 1, 1] + 2*s[2, 2, 1] + 2*s[3, 1, 1] + s[3, 2] + s[4, 1] + s[5] >>> [s(h.get_coefficient(i)) for i in range(Integer(6))] [0, s[1], s[1, 1] + s[2], 2*s[1, 1, 1] + s[2, 1] + s[3], 3*s[1, 1, 1, 1] + 2*s[2, 1, 1] + s[2, 2] + s[3, 1] + s[4], 4*s[1, 1, 1, 1, 1] + 4*s[2, 1, 1, 1] + 2*s[2, 2, 1] + 2*s[3, 1, 1] + s[3, 2] + s[4, 1] + s[5]] 
 - input_streams()[source]¶
- Return the list of streams which are used to compute the coefficients of - self.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_function, Stream_plethysm sage: s = SymmetricFunctions(QQ).s() sage: p = SymmetricFunctions(QQ).p() sage: f = Stream_function(lambda n: s[n], True, 1) sage: g = Stream_function(lambda n: s[n-1,1], True, 2) sage: h = Stream_plethysm(f, g, True, p) sage: h.input_streams() [<sage.data_structures.stream.Stream_map_coefficients object at ...>] sage: [h[i] for i in range(1, 5)] [0, 1/2*p[1, 1] - 1/2*p[2], 1/3*p[1, 1, 1] - 1/3*p[3], 1/4*p[1, 1, 1, 1] + 1/4*p[2, 2] - 1/2*p[4]] sage: h.input_streams() [<sage.data_structures.stream.Stream_map_coefficients object at ...>, <sage.data_structures.stream.Stream_cauchy_mul object at ...>] - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_function, Stream_plethysm >>> s = SymmetricFunctions(QQ).s() >>> p = SymmetricFunctions(QQ).p() >>> f = Stream_function(lambda n: s[n], True, Integer(1)) >>> g = Stream_function(lambda n: s[n-Integer(1),Integer(1)], True, Integer(2)) >>> h = Stream_plethysm(f, g, True, p) >>> h.input_streams() [<sage.data_structures.stream.Stream_map_coefficients object at ...>] >>> [h[i] for i in range(Integer(1), Integer(5))] [0, 1/2*p[1, 1] - 1/2*p[2], 1/3*p[1, 1, 1] - 1/3*p[3], 1/4*p[1, 1, 1, 1] + 1/4*p[2, 2] - 1/2*p[4]] >>> h.input_streams() [<sage.data_structures.stream.Stream_map_coefficients object at ...>, <sage.data_structures.stream.Stream_cauchy_mul object at ...>] 
 - stretched_power_restrict_degree(i, m, d)[source]¶
- Return the degree - d*ipart of- p([i]*m)(g)in terms of- self._basis.- INPUT: - i,- m– positive integers
- d– integer
 - EXAMPLES: - sage: # needs sage.modules sage: from sage.data_structures.stream import Stream_plethysm, Stream_exact, Stream_function, Stream_zero sage: s = SymmetricFunctions(QQ).s() sage: p = SymmetricFunctions(QQ).p() sage: f = Stream_exact([1]) # irrelevant for this test sage: g = Stream_exact([s[2], s[3]], 0, 4, 2) sage: h = Stream_plethysm(f, g, True, p) sage: A = h.stretched_power_restrict_degree(2, 3, 6) sage: A == p[2,2,2](s[2] + s[3]).homogeneous_component(12) True sage: # needs sage.modules sage: p2 = tensor([p, p]) sage: f = Stream_exact([1]) # irrelevant for this test sage: g = Stream_function(lambda n: sum(tensor([p[k], p[n-k]]) ....: for k in range(n+1)), True, 1) sage: h = Stream_plethysm(f, g, True, p2) sage: A = h.stretched_power_restrict_degree(2, 3, 6) sage: B = p[2,2,2](sum(g[n] for n in range(7))) # long time sage: B = p2.element_class(p2, {m: c for m, c in B # long time ....: if sum(mu.size() for mu in m) == 12}) sage: A == B # long time True - >>> from sage.all import * >>> # needs sage.modules >>> from sage.data_structures.stream import Stream_plethysm, Stream_exact, Stream_function, Stream_zero >>> s = SymmetricFunctions(QQ).s() >>> p = SymmetricFunctions(QQ).p() >>> f = Stream_exact([Integer(1)]) # irrelevant for this test >>> g = Stream_exact([s[Integer(2)], s[Integer(3)]], Integer(0), Integer(4), Integer(2)) >>> h = Stream_plethysm(f, g, True, p) >>> A = h.stretched_power_restrict_degree(Integer(2), Integer(3), Integer(6)) >>> A == p[Integer(2),Integer(2),Integer(2)](s[Integer(2)] + s[Integer(3)]).homogeneous_component(Integer(12)) True >>> # needs sage.modules >>> p2 = tensor([p, p]) >>> f = Stream_exact([Integer(1)]) # irrelevant for this test >>> g = Stream_function(lambda n: sum(tensor([p[k], p[n-k]]) ... for k in range(n+Integer(1))), True, Integer(1)) >>> h = Stream_plethysm(f, g, True, p2) >>> A = h.stretched_power_restrict_degree(Integer(2), Integer(3), Integer(6)) >>> B = p[Integer(2),Integer(2),Integer(2)](sum(g[n] for n in range(Integer(7)))) # long time >>> B = p2.element_class(p2, {m: c for m, c in B # long time ... if sum(mu.size() for mu in m) == Integer(12)}) >>> A == B # long time True 
 
- class sage.data_structures.stream.Stream_rmul(series, scalar, is_sparse)[source]¶
- Bases: - Stream_scalar- Operator for multiplying a coefficient stream with a scalar as - scalar * self.- INPUT: - series– a- Stream
- scalar– a nonzero, non-one scalar
 - EXAMPLES: - sage: # needs sage.modules sage: from sage.data_structures.stream import (Stream_rmul, Stream_function) sage: W = algebras.DifferentialWeyl(QQ, names=('x',)) sage: x, dx = W.gens() sage: f = Stream_function(lambda n: x^n, True, 1) sage: g = Stream_rmul(f, dx, True) sage: [g[i] for i in range(5)] [0, x*dx + 1, x^2*dx + 2*x, x^3*dx + 3*x^2, x^4*dx + 4*x^3] - >>> from sage.all import * >>> # needs sage.modules >>> from sage.data_structures.stream import (Stream_rmul, Stream_function) >>> W = algebras.DifferentialWeyl(QQ, names=('x',)) >>> x, dx = W.gens() >>> f = Stream_function(lambda n: x**n, True, Integer(1)) >>> g = Stream_rmul(f, dx, True) >>> [g[i] for i in range(Integer(5))] [0, x*dx + 1, x^2*dx + 2*x, x^3*dx + 3*x^2, x^4*dx + 4*x^3] - get_coefficient(n)[source]¶
- Return the - n-th coefficient of- self.- INPUT: - n– integer; the degree for the coefficient
 - EXAMPLES: - sage: from sage.data_structures.stream import (Stream_rmul, Stream_function) sage: f = Stream_function(lambda n: n, True, 1) sage: g = Stream_rmul(f, 3, True) sage: g.get_coefficient(5) 15 sage: [g.get_coefficient(i) for i in range(10)] [0, 3, 6, 9, 12, 15, 18, 21, 24, 27] - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_rmul, Stream_function) >>> f = Stream_function(lambda n: n, True, Integer(1)) >>> g = Stream_rmul(f, Integer(3), True) >>> g.get_coefficient(Integer(5)) 15 >>> [g.get_coefficient(i) for i in range(Integer(10))] [0, 3, 6, 9, 12, 15, 18, 21, 24, 27] 
 
- class sage.data_structures.stream.Stream_scalar(series, scalar, is_sparse)[source]¶
- Bases: - Stream_unary- Base class for operators multiplying a coefficient stream by a scalar. - INPUT: - series– a- Stream
- scalar– a nonzero, non-one scalar
- is_sparse– boolean
 - is_nonzero()[source]¶
- Return - Trueif and only if this stream is known to be nonzero.- EXAMPLES: - sage: from sage.data_structures.stream import (Stream_rmul, Stream_function) sage: f = Stream_function(lambda n: n, True, 1) sage: g = Stream_rmul(f, 2, True) sage: g.is_nonzero() False sage: from sage.data_structures.stream import Stream_cauchy_invert sage: fi = Stream_cauchy_invert(f) sage: g = Stream_rmul(fi, 2, True) sage: g.is_nonzero() True - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_rmul, Stream_function) >>> f = Stream_function(lambda n: n, True, Integer(1)) >>> g = Stream_rmul(f, Integer(2), True) >>> g.is_nonzero() False >>> from sage.data_structures.stream import Stream_cauchy_invert >>> fi = Stream_cauchy_invert(f) >>> g = Stream_rmul(fi, Integer(2), True) >>> g.is_nonzero() True 
 
- class sage.data_structures.stream.Stream_shift(series, shift)[source]¶
- Bases: - Stream- Operator for shifting a nonzero, non-exact stream. - Instances of this class share the cache with its input stream. - INPUT: - series– a- Stream
- shift– integer
 - is_nonzero()[source]¶
- Return - Trueif and only if this stream is known to be nonzero.- An assumption of this class is that it is nonzero. - EXAMPLES: - sage: from sage.data_structures.stream import (Stream_cauchy_invert, Stream_function) sage: f = Stream_function(lambda n: n^2, False, 1) sage: g = Stream_cauchy_invert(f) sage: g.is_nonzero() True - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_cauchy_invert, Stream_function) >>> f = Stream_function(lambda n: n**Integer(2), False, Integer(1)) >>> g = Stream_cauchy_invert(f) >>> g.is_nonzero() True 
 - is_uninitialized()[source]¶
- Return - Trueif- selfis an uninitialized stream.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_uninitialized, Stream_shift sage: C = Stream_uninitialized(0) sage: S = Stream_shift(C, 5) sage: S.is_uninitialized() True - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_uninitialized, Stream_shift >>> C = Stream_uninitialized(Integer(0)) >>> S = Stream_shift(C, Integer(5)) >>> S.is_uninitialized() True 
 - order()[source]¶
- Return the order of - self, which is the minimum index- nsuch that- self[n]is nonzero.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_function, Stream_shift sage: s = Stream_shift(Stream_function(lambda n: n, True, 0), 2) sage: s.order() 3 - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_function, Stream_shift >>> s = Stream_shift(Stream_function(lambda n: n, True, Integer(0)), Integer(2)) >>> s.order() 3 
 
- class sage.data_structures.stream.Stream_sub(left, right, is_sparse)[source]¶
- Bases: - Stream_binary- Operator for subtraction of two coefficient streams. - INPUT: - left–- Streamof coefficients on the left side of the operator
- right–- Streamof coefficients on the right side of the operator
- is_sparse– boolean; whether the implementation of the stream is sparse
 - EXAMPLES: - sage: from sage.data_structures.stream import (Stream_sub, Stream_function) sage: f = Stream_function(lambda n: n, True, 0) sage: g = Stream_function(lambda n: 1, True, 0) sage: h = Stream_sub(f, g, True) sage: [h[i] for i in range(10)] [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8] sage: u = Stream_sub(g, f, True) sage: [u[i] for i in range(10)] [1, 0, -1, -2, -3, -4, -5, -6, -7, -8] - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_sub, Stream_function) >>> f = Stream_function(lambda n: n, True, Integer(0)) >>> g = Stream_function(lambda n: Integer(1), True, Integer(0)) >>> h = Stream_sub(f, g, True) >>> [h[i] for i in range(Integer(10))] [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8] >>> u = Stream_sub(g, f, True) >>> [u[i] for i in range(Integer(10))] [1, 0, -1, -2, -3, -4, -5, -6, -7, -8] - get_coefficient(n)[source]¶
- Return the - n-th coefficient of- self.- INPUT: - n– integer; the degree for the coefficient
 - EXAMPLES: - sage: from sage.data_structures.stream import (Stream_function, Stream_sub) sage: f = Stream_function(lambda n: n, True, 0) sage: g = Stream_function(lambda n: n^2, True, 0) sage: h = Stream_sub(f, g, True) sage: h.get_coefficient(5) -20 sage: [h.get_coefficient(i) for i in range(10)] [0, 0, -2, -6, -12, -20, -30, -42, -56, -72] - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_function, Stream_sub) >>> f = Stream_function(lambda n: n, True, Integer(0)) >>> g = Stream_function(lambda n: n**Integer(2), True, Integer(0)) >>> h = Stream_sub(f, g, True) >>> h.get_coefficient(Integer(5)) -20 >>> [h.get_coefficient(i) for i in range(Integer(10))] [0, 0, -2, -6, -12, -20, -30, -42, -56, -72] 
 
- class sage.data_structures.stream.Stream_taylor(function, is_sparse)[source]¶
- Bases: - Stream_inexact- Class that returns a stream for the Taylor series of a function. - INPUT: - function– a function that has a- derivativemethod and takes a single input
- is_sparse– boolean; specifies whether the stream is sparse
 - EXAMPLES: - sage: from sage.data_structures.stream import Stream_taylor sage: g(x) = sin(x) sage: f = Stream_taylor(g, False) sage: f[3] -1/6 sage: [f[i] for i in range(10)] [0, 1, 0, -1/6, 0, 1/120, 0, -1/5040, 0, 1/362880] sage: g(y) = cos(y) sage: f = Stream_taylor(g, False) sage: n = f.iterate_coefficients() sage: [next(n) for _ in range(10)] [1, 0, -1/2, 0, 1/24, 0, -1/720, 0, 1/40320, 0] sage: g(z) = 1 / (1 - 2*z) sage: f = Stream_taylor(g, True) sage: [f[i] for i in range(4)] [1, 2, 4, 8] - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_taylor >>> __tmp__=var("x"); g = symbolic_expression(sin(x)).function(x) >>> f = Stream_taylor(g, False) >>> f[Integer(3)] -1/6 >>> [f[i] for i in range(Integer(10))] [0, 1, 0, -1/6, 0, 1/120, 0, -1/5040, 0, 1/362880] >>> __tmp__=var("y"); g = symbolic_expression(cos(y)).function(y) >>> f = Stream_taylor(g, False) >>> n = f.iterate_coefficients() >>> [next(n) for _ in range(Integer(10))] [1, 0, -1/2, 0, 1/24, 0, -1/720, 0, 1/40320, 0] >>> __tmp__=var("z"); g = symbolic_expression(Integer(1) / (Integer(1) - Integer(2)*z)).function(z) >>> f = Stream_taylor(g, True) >>> [f[i] for i in range(Integer(4))] [1, 2, 4, 8] - get_coefficient(n)[source]¶
- Return the - n-th coefficient of- self.- INPUT: - n– integer; the degree for the coefficient
 - EXAMPLES: - sage: from sage.data_structures.stream import Stream_taylor sage: g(x) = exp(x) sage: f = Stream_taylor(g, True) sage: f.get_coefficient(5) 1/120 sage: from sage.data_structures.stream import Stream_taylor sage: y = SR.var('y') sage: f = Stream_taylor(sin(y), True) sage: f.get_coefficient(0) 0 sage: f.get_coefficient(5) 1/120 - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_taylor >>> __tmp__=var("x"); g = symbolic_expression(exp(x)).function(x) >>> f = Stream_taylor(g, True) >>> f.get_coefficient(Integer(5)) 1/120 >>> from sage.data_structures.stream import Stream_taylor >>> y = SR.var('y') >>> f = Stream_taylor(sin(y), True) >>> f.get_coefficient(Integer(0)) 0 >>> f.get_coefficient(Integer(5)) 1/120 
 - iterate_coefficients()[source]¶
- A generator for the coefficients of - self.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_taylor sage: x = polygen(QQ, 'x') sage: f = Stream_taylor(x^3, False) sage: it = f.iterate_coefficients() sage: [next(it) for _ in range(10)] [0, 0, 0, 1, 0, 0, 0, 0, 0, 0] sage: y = SR.var('y') sage: f = Stream_taylor(y^3, False) sage: it = f.iterate_coefficients() sage: [next(it) for _ in range(10)] [0, 0, 0, 1, 0, 0, 0, 0, 0, 0] - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_taylor >>> x = polygen(QQ, 'x') >>> f = Stream_taylor(x**Integer(3), False) >>> it = f.iterate_coefficients() >>> [next(it) for _ in range(Integer(10))] [0, 0, 0, 1, 0, 0, 0, 0, 0, 0] >>> y = SR.var('y') >>> f = Stream_taylor(y**Integer(3), False) >>> it = f.iterate_coefficients() >>> [next(it) for _ in range(Integer(10))] [0, 0, 0, 1, 0, 0, 0, 0, 0, 0] 
 
- class sage.data_structures.stream.Stream_truncated(series, shift, minimal_valuation)[source]¶
- Bases: - Stream_unary- Operator for shifting a nonzero, non-exact stream that has been shifted below its minimal valuation. - Instances of this class share the cache with its input stream. - INPUT: - series– a- Stream_inexact
- shift– integer
- minimal_valuation– integer; this is also the approximate order
 - is_nonzero()[source]¶
- Return - Trueif and only if this stream is known to be nonzero.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_function, Stream_truncated sage: def fun(n): return 1 if ZZ(n).is_power_of(2) else 0 sage: f = Stream_function(fun, False, 0) sage: [f[i] for i in range(4)] [0, 1, 1, 0] sage: f._cache [1, 1, 0] sage: s = Stream_truncated(f, -5, 0) sage: s.is_nonzero() False sage: [f[i] for i in range(7,10)] # updates the cache of s [0, 1, 0] sage: s.is_nonzero() True sage: f = Stream_function(fun, True, 0) sage: [f[i] for i in range(4)] [0, 1, 1, 0] sage: f._cache {1: 1, 2: 1, 3: 0} sage: s = Stream_truncated(f, -5, 0) sage: s.is_nonzero() False sage: [f[i] for i in range(7,10)] # updates the cache of s [0, 1, 0] sage: s.is_nonzero() True - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_function, Stream_truncated >>> def fun(n): return Integer(1) if ZZ(n).is_power_of(Integer(2)) else Integer(0) >>> f = Stream_function(fun, False, Integer(0)) >>> [f[i] for i in range(Integer(4))] [0, 1, 1, 0] >>> f._cache [1, 1, 0] >>> s = Stream_truncated(f, -Integer(5), Integer(0)) >>> s.is_nonzero() False >>> [f[i] for i in range(Integer(7),Integer(10))] # updates the cache of s [0, 1, 0] >>> s.is_nonzero() True >>> f = Stream_function(fun, True, Integer(0)) >>> [f[i] for i in range(Integer(4))] [0, 1, 1, 0] >>> f._cache {1: 1, 2: 1, 3: 0} >>> s = Stream_truncated(f, -Integer(5), Integer(0)) >>> s.is_nonzero() False >>> [f[i] for i in range(Integer(7),Integer(10))] # updates the cache of s [0, 1, 0] >>> s.is_nonzero() True 
 - order()[source]¶
- Return the order of - self, which is the minimum index- nsuch that- self[n]is nonzero.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_function, Stream_truncated sage: def fun(n): return 1 if ZZ(n).is_power_of(2) else 0 sage: s = Stream_truncated(Stream_function(fun, True, 0), -5, 0) sage: s.order() 3 sage: s = Stream_truncated(Stream_function(fun, False, 0), -5, 0) sage: s.order() 3 - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_function, Stream_truncated >>> def fun(n): return Integer(1) if ZZ(n).is_power_of(Integer(2)) else Integer(0) >>> s = Stream_truncated(Stream_function(fun, True, Integer(0)), -Integer(5), Integer(0)) >>> s.order() 3 >>> s = Stream_truncated(Stream_function(fun, False, Integer(0)), -Integer(5), Integer(0)) >>> s.order() 3 - Check that it also worked properly with the cache partially filled: - sage: f = Stream_function(fun, True, 0) sage: dummy = [f[i] for i in range(10)] sage: s = Stream_truncated(f, -5, 0) sage: s.order() 3 sage: f = Stream_function(fun, False, 0) sage: dummy = [f[i] for i in range(10)] sage: s = Stream_truncated(f, -5, 0) sage: s.order() 3 - >>> from sage.all import * >>> f = Stream_function(fun, True, Integer(0)) >>> dummy = [f[i] for i in range(Integer(10))] >>> s = Stream_truncated(f, -Integer(5), Integer(0)) >>> s.order() 3 >>> f = Stream_function(fun, False, Integer(0)) >>> dummy = [f[i] for i in range(Integer(10))] >>> s = Stream_truncated(f, -Integer(5), Integer(0)) >>> s.order() 3 
 
- class sage.data_structures.stream.Stream_unary(series, is_sparse, true_order=False)[source]¶
- Bases: - Stream_inexact- Base class for unary operators on coefficient streams. - INPUT: - series–- Streamthe operator acts on
- is_sparse– boolean
- true_order– boolean (default:- False); if the approximate order is the actual order
 - EXAMPLES: - sage: from sage.data_structures.stream import (Stream_function, Stream_cauchy_invert, Stream_lmul) sage: f = Stream_function(lambda n: 2*n, False, 1) sage: g = Stream_cauchy_invert(f) sage: [g[i] for i in range(10)] [-1, 1/2, 0, 0, 0, 0, 0, 0, 0, 0] sage: g = Stream_lmul(f, 2, True) sage: [g[i] for i in range(10)] [0, 4, 8, 12, 16, 20, 24, 28, 32, 36] - >>> from sage.all import * >>> from sage.data_structures.stream import (Stream_function, Stream_cauchy_invert, Stream_lmul) >>> f = Stream_function(lambda n: Integer(2)*n, False, Integer(1)) >>> g = Stream_cauchy_invert(f) >>> [g[i] for i in range(Integer(10))] [-1, 1/2, 0, 0, 0, 0, 0, 0, 0, 0] >>> g = Stream_lmul(f, Integer(2), True) >>> [g[i] for i in range(Integer(10))] [0, 4, 8, 12, 16, 20, 24, 28, 32, 36] - input_streams()[source]¶
- Return the list of streams which are used to compute the coefficients of - self.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_function, Stream_neg sage: h = Stream_function(lambda n: n, False, 1) sage: M = Stream_neg(h, False) sage: M.input_streams() [<sage.data_structures.stream.Stream_function object at ...>] - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_function, Stream_neg >>> h = Stream_function(lambda n: n, False, Integer(1)) >>> M = Stream_neg(h, False) >>> M.input_streams() [<sage.data_structures.stream.Stream_function object at ...>] 
 - is_uninitialized()[source]¶
- Return - Trueif- selfis an uninitialized stream.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_uninitialized, Stream_unary sage: C = Stream_uninitialized(0) sage: M = Stream_unary(C, True) sage: M.is_uninitialized() True - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_uninitialized, Stream_unary >>> C = Stream_uninitialized(Integer(0)) >>> M = Stream_unary(C, True) >>> M.is_uninitialized() True 
 
- class sage.data_structures.stream.Stream_uninitialized(approximate_order, true_order=False, name=None)[source]¶
- Bases: - Stream- Coefficient stream for an uninitialized series. - INPUT: - approximate_order– integer; a lower bound for the order of the stream
- true_order– boolean; if the approximate order is the actual order
- name– string; a name that refers to the undefined stream in error messages
 - Instances of this class are always dense. - Todo - Should instances of this class share the cache with its - _target?- EXAMPLES: - sage: from sage.data_structures.stream import Stream_uninitialized sage: from sage.data_structures.stream import Stream_exact sage: one = Stream_exact([1]) sage: C = Stream_uninitialized(0) sage: C._target sage: C.define(one) sage: C[4] 0 - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_uninitialized >>> from sage.data_structures.stream import Stream_exact >>> one = Stream_exact([Integer(1)]) >>> C = Stream_uninitialized(Integer(0)) >>> C._target >>> C.define(one) >>> C[Integer(4)] 0 - define(target)[source]¶
- Define - selfvia- self = target.- INPUT: - target– a stream
 - EXAMPLES: - sage: from sage.data_structures.stream import Stream_uninitialized, Stream_exact, Stream_cauchy_mul, Stream_add sage: x = Stream_exact([1], order=1) sage: C = Stream_uninitialized(1) sage: C.define(Stream_add(x, Stream_cauchy_mul(C, C, True), True)) sage: C[6] 42 - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_uninitialized, Stream_exact, Stream_cauchy_mul, Stream_add >>> x = Stream_exact([Integer(1)], order=Integer(1)) >>> C = Stream_uninitialized(Integer(1)) >>> C.define(Stream_add(x, Stream_cauchy_mul(C, C, True), True)) >>> C[Integer(6)] 42 
 - define_implicitly(series, initial_values, equations, base_ring, coefficient_ring, terms_of_degree, max_lookahead=1)[source]¶
- Define - selfvia- equations == 0.- INPUT: - series– a list of series
- equations– a list of equations defining the series
- initial_values– a list specifying- self[0], self[1], ...
- base_ring– the base ring
- coefficient_ring– the ring containing the elements of the stream (after substitution)
- terms_of_degree– a function returning the list of terms of a given degree
- max_lookahead– a positive integer specifying how many elements beyond the approximate order of each equation to extract linear equations from
 - EXAMPLES: - sage: from sage.data_structures.stream import Stream_uninitialized, Stream_exact, Stream_cauchy_mul, Stream_add, Stream_sub sage: terms_of_degree = lambda n, R: [R.one()] sage: x = Stream_exact([1], order=1) sage: C = Stream_uninitialized(1) sage: D = Stream_add(x, Stream_cauchy_mul(C, C, True), True) sage: eq = Stream_sub(C, D, True) sage: C.define_implicitly([C], [], [eq], QQ, QQ, terms_of_degree) sage: C[6] 42 - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_uninitialized, Stream_exact, Stream_cauchy_mul, Stream_add, Stream_sub >>> terms_of_degree = lambda n, R: [R.one()] >>> x = Stream_exact([Integer(1)], order=Integer(1)) >>> C = Stream_uninitialized(Integer(1)) >>> D = Stream_add(x, Stream_cauchy_mul(C, C, True), True) >>> eq = Stream_sub(C, D, True) >>> C.define_implicitly([C], [], [eq], QQ, QQ, terms_of_degree) >>> C[Integer(6)] 42 
 - input_streams()[source]¶
- Return the list of streams which are used to compute the coefficients of - self.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_uninitialized, Stream_function sage: h = Stream_function(lambda n: n, False, 1) sage: M = Stream_uninitialized(0) sage: M.input_streams() [] sage: M._target = h sage: [h[i] for i in range(5)] [0, 1, 2, 3, 4] sage: M.input_streams() [<sage.data_structures.stream.Stream_function object at ...>] - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_uninitialized, Stream_function >>> h = Stream_function(lambda n: n, False, Integer(1)) >>> M = Stream_uninitialized(Integer(0)) >>> M.input_streams() [] >>> M._target = h >>> [h[i] for i in range(Integer(5))] [0, 1, 2, 3, 4] >>> M.input_streams() [<sage.data_structures.stream.Stream_function object at ...>] 
 - is_uninitialized()[source]¶
- Return - Trueif- selfis an uninitialized stream.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_uninitialized sage: C = Stream_uninitialized(0) sage: C.is_uninitialized() True - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_uninitialized >>> C = Stream_uninitialized(Integer(0)) >>> C.is_uninitialized() True - A more subtle uninitialized series: - sage: L.<z> = LazyPowerSeriesRing(QQ) sage: T = L.undefined(1) sage: D = L.undefined(0) sage: T.define(z * exp(T) * D) sage: T._coeff_stream.is_uninitialized() True - >>> from sage.all import * >>> L = LazyPowerSeriesRing(QQ, names=('z',)); (z,) = L._first_ngens(1) >>> T = L.undefined(Integer(1)) >>> D = L.undefined(Integer(0)) >>> T.define(z * exp(T) * D) >>> T._coeff_stream.is_uninitialized() True 
 - iterate_coefficients()[source]¶
- A generator for the coefficients of - self.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_uninitialized sage: from sage.data_structures.stream import Stream_exact sage: z = Stream_exact([1], order=1) sage: C = Stream_uninitialized(0) sage: C._target sage: C._target = z sage: n = C.iterate_coefficients() sage: [next(n) for _ in range(10)] [0, 1, 0, 0, 0, 0, 0, 0, 0, 0] - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_uninitialized >>> from sage.data_structures.stream import Stream_exact >>> z = Stream_exact([Integer(1)], order=Integer(1)) >>> C = Stream_uninitialized(Integer(0)) >>> C._target >>> C._target = z >>> n = C.iterate_coefficients() >>> [next(n) for _ in range(Integer(10))] [0, 1, 0, 0, 0, 0, 0, 0, 0, 0] 
 
- class sage.data_structures.stream.Stream_zero[source]¶
- Bases: - Stream- A coefficient stream that is exactly equal to zero. - EXAMPLES: - sage: from sage.data_structures.stream import Stream_zero sage: s = Stream_zero() sage: s[5] 0 - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_zero >>> s = Stream_zero() >>> s[Integer(5)] 0 - order()[source]¶
- Return the order of - self, which is- infinity.- EXAMPLES: - sage: from sage.data_structures.stream import Stream_zero sage: s = Stream_zero() sage: s.order() +Infinity - >>> from sage.all import * >>> from sage.data_structures.stream import Stream_zero >>> s = Stream_zero() >>> s.order() +Infinity 
 
- class sage.data_structures.stream.VariablePool(ring)[source]¶
- Bases: - UniqueRepresentation- A class to keep track of used and unused variables in an - InfinitePolynomialRing.- INPUT: - ring–- InfinitePolynomialRing
 - del_variable(v)[source]¶
- Remove - vfrom the pool.- EXAMPLES: - sage: from sage.data_structures.stream import VariablePool sage: R.<a> = InfinitePolynomialRing(QQ) sage: P = VariablePool(R) sage: v = P.new_variable(); v a_1 sage: P.del_variable(v) sage: v = P.new_variable(); v a_1 - >>> from sage.all import * >>> from sage.data_structures.stream import VariablePool >>> R = InfinitePolynomialRing(QQ, names=('a',)); (a,) = R._first_ngens(1) >>> P = VariablePool(R) >>> v = P.new_variable(); v a_1 >>> P.del_variable(v) >>> v = P.new_variable(); v a_1 
 - new_variable(data=None)[source]¶
- Return an unused variable. - EXAMPLES: - sage: from sage.data_structures.stream import VariablePool sage: R.<a> = InfinitePolynomialRing(QQ) sage: P = VariablePool(R) sage: P.new_variable() a_0 - >>> from sage.all import * >>> from sage.data_structures.stream import VariablePool >>> R = InfinitePolynomialRing(QQ, names=('a',)); (a,) = R._first_ngens(1) >>> P = VariablePool(R) >>> P.new_variable() a_0 
 - variables()[source]¶
- Return the dictionary mapping variables to data. - EXAMPLES: - sage: from sage.data_structures.stream import VariablePool sage: R.<a> = InfinitePolynomialRing(QQ) sage: P = VariablePool(R) sage: P.new_variable("my new variable") a_2 sage: P.variables() {a_0: None, a_1: None, a_2: 'my new variable'} - >>> from sage.all import * >>> from sage.data_structures.stream import VariablePool >>> R = InfinitePolynomialRing(QQ, names=('a',)); (a,) = R._first_ngens(1) >>> P = VariablePool(R) >>> P.new_variable("my new variable") a_2 >>> P.variables() {a_0: None, a_1: None, a_2: 'my new variable'}