diff --git a/src/sage/combinat/species/generating_series.py b/src/sage/combinat/species/generating_series.py index e7f7c8ee978..2b378dccba3 100644 --- a/src/sage/combinat/species/generating_series.py +++ b/src/sage/combinat/species/generating_series.py @@ -545,7 +545,7 @@ class CycleIndexSeriesRing(LazySymmetricFunctions): We test to make sure that caching works:: - sage: R is CycleIndexSeriesRing(QQ) + sage: R is CycleIndexSeriesRing(QQ) # optional - sage.modules True """ Element = CycleIndexSeries diff --git a/src/sage/rings/lazy_series.py b/src/sage/rings/lazy_series.py index e81bb2fedb0..661d0ea0532 100644 --- a/src/sage/rings/lazy_series.py +++ b/src/sage/rings/lazy_series.py @@ -171,30 +171,35 @@ ....: yield n ....: n += 1 - sage: L. = LazyLaurentSeriesRing(GF(2)) # optional - sage.rings.finite_rings - sage: check(L, lambda n: n, valuation=-5) # optional - sage.rings.finite_rings - sage: check(L, gen(), valuation=-5) # optional - sage.rings.finite_rings - - sage: L = LazyDirichletSeriesRing(QQbar, "s") # optional - sage.rings.number_field - sage: check(L, lambda n: n, valuation=2) # optional - sage.rings.number_field - sage: check(L, gen(), valuation=2) # optional - sage.rings.number_field - - sage: L. = LazyPowerSeriesRing(GF(2)) # optional - sage.rings.finite_rings - sage: check(L, lambda n: n, valuation=0) # optional - sage.rings.finite_rings - sage: check(L, gen(), valuation=0) # optional - sage.rings.finite_rings - - sage: L. = LazyPowerSeriesRing(GF(2)) # optional - sage.rings.finite_rings - sage: check(L, lambda n: (x + y)^n, valuation=None) # optional - sage.rings.finite_rings - sage: def gen(): # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: L. = LazyLaurentSeriesRing(GF(2)) + sage: check(L, lambda n: n, valuation=-5) + sage: check(L, gen(), valuation=-5) + + sage: # needs sage.rings.number_field + sage: L = LazyDirichletSeriesRing(QQbar, "s") + sage: check(L, lambda n: n, valuation=2) + sage: check(L, gen(), valuation=2) + + sage: # needs sage.rings.finite_rings + sage: L. = LazyPowerSeriesRing(GF(2)) + sage: check(L, lambda n: n, valuation=0) + sage: check(L, gen(), valuation=0) + + sage: # needs sage.rings.finite_rings + sage: L. = LazyPowerSeriesRing(GF(2)) + sage: check(L, lambda n: (x + y)^n, valuation=None) + sage: def gen(): ....: n = 0 ....: while True: ....: yield (x+y)^n ....: n += 1 - sage: check(L, gen(), valuation=None) # optional - sage.rings.finite_rings + sage: check(L, gen(), valuation=None) - sage: s = SymmetricFunctions(GF(2)).s() # optional - sage.combinat sage.rings.finite_rings - sage: L = LazySymmetricFunctions(s) # optional - sage.combinat sage.rings.finite_rings - sage: check(L, lambda n: sum(k*s(la) for k, la in enumerate(Partitions(n))), # optional - sage.combinat sage.rings.finite_rings + sage: # needs sage.combinat sage.rings.finite_rings + sage: s = SymmetricFunctions(GF(2)).s() + sage: L = LazySymmetricFunctions(s) + sage: check(L, lambda n: sum(k*s(la) for k, la in enumerate(Partitions(n))), ....: valuation=0) Check that we can invert matrices:: @@ -535,12 +540,13 @@ def map_coefficients(self, f): Similarly for lazy symmetric functions:: - sage: p = SymmetricFunctions(QQ).p() # optional - sage.combinat - sage: L = LazySymmetricFunctions(p) # optional - sage.combinat - sage: f = 1/(1-2*L(p[1])); f # optional - sage.combinat + sage: # needs sage.combinat + sage: p = SymmetricFunctions(QQ).p() + sage: L = LazySymmetricFunctions(p) + sage: f = 1/(1-2*L(p[1])); f p[] + 2*p[1] + (4*p[1,1]) + (8*p[1,1,1]) + (16*p[1,1,1,1]) + (32*p[1,1,1,1,1]) + (64*p[1,1,1,1,1,1]) + O^7 - sage: f.map_coefficients(lambda c: log(c, 2)) # optional - sage.combinat + sage: f.map_coefficients(lambda c: log(c, 2)) p[1] + (2*p[1,1]) + (3*p[1,1,1]) + (4*p[1,1,1,1]) + (5*p[1,1,1,1,1]) + (6*p[1,1,1,1,1,1]) + O^7 @@ -994,56 +1000,57 @@ def __bool__(self): TESTS:: - sage: L. = LazyLaurentSeriesRing(GF(2)) # optional - sage.rings.finite_rings - sage: bool(z - z) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: L. = LazyLaurentSeriesRing(GF(2)) + sage: bool(z - z) False - sage: f = 1/(1 - z) # optional - sage.rings.finite_rings - sage: bool(f) # optional - sage.rings.finite_rings + sage: f = 1/(1 - z) + sage: bool(f) True - sage: M = L(lambda n: n, valuation=0); M # optional - sage.rings.finite_rings + sage: M = L(lambda n: n, valuation=0); M z + z^3 + z^5 + O(z^7) - sage: M.is_zero() # optional - sage.rings.finite_rings + sage: M.is_zero() False - sage: M = L(lambda n: 2*n if n < 10 else 1, valuation=0); M # optional - sage.rings.finite_rings + sage: M = L(lambda n: 2*n if n < 10 else 1, valuation=0); M O(z^7) - sage: bool(M) # optional - sage.rings.finite_rings + sage: bool(M) True - sage: M[15] # optional - sage.rings.finite_rings + sage: M[15] 1 - sage: bool(M) # optional - sage.rings.finite_rings + sage: bool(M) True - sage: L. = LazyLaurentSeriesRing(GF(2), sparse=True) # optional - sage.rings.finite_rings - sage: M = L(lambda n: 2*n if n < 10 else 1, valuation=0); M # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: L. = LazyLaurentSeriesRing(GF(2), sparse=True) + sage: M = L(lambda n: 2*n if n < 10 else 1, valuation=0); M O(z^7) sage: bool(M) True - sage: M[15] # optional - sage.rings.finite_rings + sage: M[15] 1 - sage: bool(M) # optional - sage.rings.finite_rings + sage: bool(M) True Uninitialized series:: - sage: g = L.undefined(valuation=0) # optional - sage.rings.finite_rings - sage: bool(g) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: g = L.undefined(valuation=0) + sage: bool(g) True - sage: g.define(0) # optional - sage.rings.finite_rings - sage: bool(g) # optional - sage.rings.finite_rings + sage: g.define(0) + sage: bool(g) False - - sage: g = L.undefined(valuation=0) # optional - sage.rings.finite_rings - sage: bool(g) # optional - sage.rings.finite_rings + sage: g = L.undefined(valuation=0) + sage: bool(g) True - sage: g.define(1 + z) # optional - sage.rings.finite_rings - sage: bool(g) # optional - sage.rings.finite_rings + sage: g.define(1 + z) + sage: bool(g) True - - sage: g = L.undefined(valuation=0) # optional - sage.rings.finite_rings - sage: bool(g) # optional - sage.rings.finite_rings + sage: g = L.undefined(valuation=0) + sage: bool(g) True - sage: g.define(1 + z*g) # optional - sage.rings.finite_rings - sage: bool(g) # optional - sage.rings.finite_rings + sage: g.define(1 + z*g) + sage: bool(g) True """ return bool(self._coeff_stream) @@ -1156,14 +1163,15 @@ def define(self, s): We can compute the Frobenius character of unlabeled trees:: - sage: m = SymmetricFunctions(QQ).m() # optional - sage.combinat - sage: s = SymmetricFunctions(QQ).s() # optional - sage.combinat - sage: L = LazySymmetricFunctions(m) # optional - sage.combinat - sage: E = L(lambda n: s[n], valuation=0) # optional - sage.combinat - sage: X = L(s[1]) # optional - sage.combinat - sage: A = L.undefined() # optional - sage.combinat - sage: A.define(X*E(A, check=False)) # optional - sage.combinat - sage: A[:6] # optional - sage.combinat + sage: # needs sage.combinat + sage: m = SymmetricFunctions(QQ).m() + sage: s = SymmetricFunctions(QQ).s() + sage: L = LazySymmetricFunctions(m) + sage: E = L(lambda n: s[n], valuation=0) + sage: X = L(s[1]) + sage: A = L.undefined() + sage: A.define(X*E(A, check=False)) + sage: A[:6] [m[1], 2*m[1, 1] + m[2], 9*m[1, 1, 1] + 5*m[2, 1] + 2*m[3], @@ -1278,11 +1286,12 @@ def define(self, s): sage: f 1 + 2*t + 12*t^3 + 32*t^4 + 368*t^5 + 2192*t^6 + O(t^7) - sage: s = SymmetricFunctions(QQ).s() # optional - sage.combinat - sage: L = LazySymmetricFunctions(s) # optional - sage.combinat - sage: f = L.undefined() # optional - sage.combinat - sage: f.define(1+(s[1]*f).revert()) # optional - sage.combinat - sage: f # optional - sage.combinat + sage: # needs sage.combinat + sage: s = SymmetricFunctions(QQ).s() + sage: L = LazySymmetricFunctions(s) + sage: f = L.undefined() + sage: f.define(1+(s[1]*f).revert()) + sage: f s[] + s[1] + (-s[1,1]-s[2]) + (3*s[1,1,1]+6*s[2,1]+3*s[3]) + (-13*s[1,1,1,1]-39*s[2,1,1]-26*s[2,2]-39*s[3,1]-13*s[4]) @@ -1413,12 +1422,13 @@ def _ascii_art_(self): EXAMPLES:: - sage: e = SymmetricFunctions(QQ).e() # optional - sage.combinat - sage: L. = LazyLaurentSeriesRing(e) # optional - sage.combinat - sage: L.options.display_length = 3 # optional - sage.combinat - sage: ascii_art(1 / (1 - e[1]*z)) # optional - sage.combinat + sage: # needs sage.combinat + sage: e = SymmetricFunctions(QQ).e() + sage: L. = LazyLaurentSeriesRing(e) + sage: L.options.display_length = 3 + sage: ascii_art(1 / (1 - e[1]*z)) e[] + e[1]*z + e[1, 1]*z^2 + O(e[]*z^3) - sage: L.options._reset() # optional - sage.combinat + sage: L.options._reset() """ from sage.typeset.ascii_art import ascii_art, AsciiArt if isinstance(self._coeff_stream, Stream_zero): @@ -1433,12 +1443,13 @@ def _unicode_art_(self): EXAMPLES:: - sage: e = SymmetricFunctions(QQ).e() # optional - sage.combinat - sage: L. = LazyLaurentSeriesRing(e) # optional - sage.combinat - sage: L.options.display_length = 3 # optional - sage.combinat - sage: unicode_art(1 / (1 - e[1]*z)) # optional - sage.combinat + sage: # needs sage.combinat + sage: e = SymmetricFunctions(QQ).e() + sage: L. = LazyLaurentSeriesRing(e) + sage: L.options.display_length = 3 + sage: unicode_art(1 / (1 - e[1]*z)) e[] + e[1]*z + e[1, 1]*z^2 + O(e[]*z^3) - sage: L.options._reset() # optional - sage.combinat + sage: L.options._reset() """ from sage.typeset.unicode_art import unicode_art, UnicodeArt if isinstance(self._coeff_stream, Stream_zero): diff --git a/src/sage/rings/lazy_series_ring.py b/src/sage/rings/lazy_series_ring.py index b989747a54c..3dfe4f302a5 100644 --- a/src/sage/rings/lazy_series_ring.py +++ b/src/sage/rings/lazy_series_ring.py @@ -287,21 +287,23 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No Converting various series from a univariate power series:: - sage: L = LazyLaurentSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings - sage: R = LazyPowerSeriesRing(ZZ, 'z') # optional - sage.rings.finite_rings - sage: L.has_coerce_map_from(R) # optional - sage.rings.finite_rings + + sage: # needs sage.rings.finite_rings + sage: L = LazyLaurentSeriesRing(GF(2), 'z') + sage: R = LazyPowerSeriesRing(ZZ, 'z') + sage: L.has_coerce_map_from(R) True - sage: L(R(lambda n: n)) # optional - sage.rings.finite_rings + sage: L(R(lambda n: n)) z + z^3 + z^5 + z^7 + O(z^8) - sage: L(R([2,4,6])) == L.zero() # optional - sage.rings.finite_rings + sage: L(R([2,4,6])) == L.zero() True - sage: L(R([2,4,6], valuation=2, constant=4)) == L.zero() # optional - sage.rings.finite_rings + sage: L(R([2,4,6], valuation=2, constant=4)) == L.zero() True - sage: L(R([2,4,6], valuation=2, constant=5)) # optional - sage.rings.finite_rings + sage: L(R([2,4,6], valuation=2, constant=5)) z^5 + z^6 + z^7 + O(z^8) - sage: L(R([2,3,4], valuation=2, constant=4)) # optional - sage.rings.finite_rings + sage: L(R([2,3,4], valuation=2, constant=4)) z^3 - sage: L(R([2,3,4], valuation=2, constant=5)) # optional - sage.rings.finite_rings + sage: L(R([2,3,4], valuation=2, constant=5)) z^3 + z^5 + z^6 + z^7 + O(z^8) Can only convert from known to be constant multivariate power series:: @@ -781,13 +783,14 @@ def _coerce_map_from_(self, S): EXAMPLES:: - sage: L = LazyLaurentSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings - sage: L.has_coerce_map_from(ZZ) # optional - sage.rings.finite_rings + sage: # optional - sage.rings.finite_rings + sage: L = LazyLaurentSeriesRing(GF(2), 'z') + sage: L.has_coerce_map_from(ZZ) True - sage: L.has_coerce_map_from(GF(2)) # optional - sage.rings.finite_rings + sage: L.has_coerce_map_from(GF(2)) True sage: R = LazyPowerSeriesRing(ZZ, 'z') - sage: L.has_coerce_map_from(R) # optional - sage.rings.finite_rings + sage: L.has_coerce_map_from(R) True sage: L = LazyLaurentSeriesRing(QQ, 'z') @@ -801,17 +804,17 @@ def _coerce_map_from_(self, S): sage: L.has_coerce_map_from(R) False - sage: L = LazyPowerSeriesRing(GF(2), 'z') # optional - sage.rings.finite_rings - sage: L.has_coerce_map_from(ZZ) # optional - sage.rings.finite_rings + sage: # optional - sage.rings.finite_rings + sage: L = LazyPowerSeriesRing(GF(2), 'z') + sage: L.has_coerce_map_from(ZZ) True - sage: L.has_coerce_map_from(GF(2)) # optional - sage.rings.finite_rings + sage: L.has_coerce_map_from(GF(2)) True - - sage: s = SymmetricFunctions(GF(2)).s() # optional - sage.rings.finite_rings - sage: L = LazySymmetricFunctions(s) # optional - sage.rings.finite_rings - sage: L.has_coerce_map_from(ZZ) # optional - sage.rings.finite_rings + sage: s = SymmetricFunctions(GF(2)).s() + sage: L = LazySymmetricFunctions(s) + sage: L.has_coerce_map_from(ZZ) True - sage: L.has_coerce_map_from(GF(2)) # optional - sage.rings.finite_rings + sage: L.has_coerce_map_from(GF(2)) True """ if self.base_ring().has_coerce_map_from(S): @@ -1050,12 +1053,13 @@ class LazyLaurentSeriesRing(LazySeriesRing): Lazy Laurent series ring over a finite field:: - sage: L. = LazyLaurentSeriesRing(GF(3)); L # optional - sage.rings.finite_rings + sage: # optional - sage.rings.finite_rings + sage: L. = LazyLaurentSeriesRing(GF(3)); L Lazy Laurent Series Ring in z over Finite Field of size 3 - sage: e = 1 / (1 + z) # optional - sage.rings.finite_rings - sage: e.coefficient(100) # optional - sage.rings.finite_rings + sage: e = 1 / (1 + z) + sage: e.coefficient(100) 1 - sage: e.coefficient(100).parent() # optional - sage.rings.finite_rings + sage: e.coefficient(100).parent() Finite Field of size 3 Series can be defined by specifying a coefficient function @@ -2393,11 +2397,12 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No EXAMPLES:: - sage: m = SymmetricFunctions(GF(2)).m() # optional - sage.rings.finite_rings - sage: L = LazySymmetricFunctions(m) # optional - sage.rings.finite_rings - sage: L(2) # optional - sage.rings.finite_rings + sage: # optional - sage.rings.finite_rings + sage: m = SymmetricFunctions(GF(2)).m() + sage: L = LazySymmetricFunctions(m) + sage: L(2) 0 - sage: L(3) # optional - sage.rings.finite_rings + sage: L(3) m[] sage: m = SymmetricFunctions(ZZ).m() @@ -3005,11 +3010,12 @@ def _skip_leading_zeros(iterator): sage: [x for x, _ in zip(_skip_leading_zeros(it), range(10))] [10, 11, 12, 13, 14, 15, 16, 17, 18, 19] - sage: it = map(GF(3), NN) # optional - sage.rings.finite_rings - sage: [x for x, _ in zip(it, range(10))] # optional - sage.rings.finite_rings + sage: # optional - sage.rings.finite_rings + sage: it = map(GF(3), NN) + sage: [x for x, _ in zip(it, range(10))] [0, 1, 2, 0, 1, 2, 0, 1, 2, 0] - sage: it = map(GF(3), NN) # optional - sage.rings.finite_rings - sage: [x for x, _ in zip(_skip_leading_zeros(it), range(10))] # optional - sage.rings.finite_rings + sage: it = map(GF(3), NN) + sage: [x for x, _ in zip(_skip_leading_zeros(it), range(10))] [1, 2, 0, 1, 2, 0, 1, 2, 0, 1] """ while True: