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

Commit 9d6579b

Browse files
committedAug 11, 2022
improve documentation, move zero, one, characteristic, etc. to ABC
1 parent c74fd71 commit 9d6579b

File tree

3 files changed

+179
-277
lines changed

3 files changed

+179
-277
lines changed
 

‎src/sage/data_structures/stream.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ class Stream_exact(Stream):
505505
"""
506506
def __init__(self, initial_coefficients, is_sparse, constant=None, degree=None, order=None):
507507
"""
508-
Initialize a series that is known to be eventually geometric.
508+
Initialize a stream with eventually constant coefficients.
509509
510510
TESTS::
511511

‎src/sage/rings/lazy_series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ def define(self, s):
723723
sage: L = LazySymmetricFunctions(m)
724724
sage: E = L(lambda n: s[n], valuation=0)
725725
sage: X = L(s[1])
726-
sage: A = L(None); A.define(X*E(A))
726+
sage: A = L(None); A.define(X*E(A, check=False))
727727
sage: A
728728
m[1] + (2*m[1,1]+m[2]) + (9*m[1,1,1]+5*m[2,1]+2*m[3]) + (64*m[1,1,1,1]+34*m[2,1,1]+18*m[2,2]+13*m[3,1]+4*m[4]) + (625*m[1,1,1,1,1]+326*m[2,1,1,1]+171*m[2,2,1]+119*m[3,1,1]+63*m[3,2]+35*m[4,1]+9*m[5]) + (7776*m[1,1,1,1,1,1]+4016*m[2,1,1,1,1]+2078*m[2,2,1,1]+1077*m[2,2,2]+1433*m[3,1,1,1]+744*m[3,2,1]+268*m[3,3]+401*m[4,1,1]+209*m[4,2]+95*m[5,1]+20*m[6]) + O^7
729729

‎src/sage/rings/lazy_series_ring.py

+177-275
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No
441441

442442
raise ValueError(f"unable to convert {x} into {self}")
443443

444-
def unknown(self, valuation=None):
444+
def undefined(self, valuation=None):
445445
"""
446446
Return an uninitialized series.
447447
@@ -456,13 +456,15 @@ def unknown(self, valuation=None):
456456
EXAMPLES::
457457
458458
sage: L.<z> = LazyTaylorSeriesRing(QQ)
459-
sage: s = L.unknown(1)
459+
sage: s = L.undefined(1)
460460
sage: s.define(z + (s^2+s(z^2))/2)
461461
sage: s
462462
z + z^2 + z^3 + 2*z^4 + 3*z^5 + 6*z^6 + 11*z^7 + O(z^8)
463463
"""
464464
return self(None, valuation=valuation)
465465

466+
unknown = undefined
467+
466468
class options(GlobalOptions):
467469
r"""
468470
Set and display the options for Lazy Laurent series.
@@ -478,6 +480,11 @@ class options(GlobalOptions):
478480
EXAMPLES::
479481
480482
sage: LLS.<z> = LazyLaurentSeriesRing(QQ)
483+
sage: LLS.options
484+
Current options for lazy series rings
485+
- constant_length: 3
486+
- display_length: 7
487+
481488
sage: LLS.options.display_length
482489
7
483490
sage: f = 1 / (1 + z)
@@ -501,7 +508,7 @@ class options(GlobalOptions):
501508
sage: LazyLaurentSeriesRing.options.display_length
502509
7
503510
"""
504-
# NAME = 'LazyLaurentSeriesRing'
511+
NAME = 'lazy series rings'
505512
module = 'sage.rings.lazy_series_ring'
506513
display_length = dict(default=7,
507514
description='the number of coefficients to display from the valuation',
@@ -510,6 +517,161 @@ class options(GlobalOptions):
510517
description='the number of coefficients to display for nonzero constant series',
511518
checker=lambda x: x in ZZ and x > 0)
512519

520+
@cached_method
521+
def one(self):
522+
r"""
523+
Return the constant series `1`.
524+
525+
EXAMPLES::
526+
527+
sage: L = LazyLaurentSeriesRing(ZZ, 'z')
528+
sage: L.one()
529+
1
530+
531+
sage: L = LazyTaylorSeriesRing(ZZ, 'z')
532+
sage: L.one()
533+
1
534+
535+
sage: m = SymmetricFunctions(ZZ).m()
536+
sage: L = LazySymmetricFunctions(m)
537+
sage: L.one()
538+
m[]
539+
540+
"""
541+
R = self.base_ring()
542+
coeff_stream = Stream_exact([R.one()], self._sparse, constant=R.zero(), order=0)
543+
return self.element_class(self, coeff_stream)
544+
545+
@cached_method
546+
def zero(self):
547+
r"""
548+
Return the zero series.
549+
550+
EXAMPLES::
551+
552+
sage: L = LazyLaurentSeriesRing(ZZ, 'z')
553+
sage: L.zero()
554+
0
555+
556+
sage: s = SymmetricFunctions(ZZ).s()
557+
sage: L = LazySymmetricFunctions(s)
558+
sage: L.zero()
559+
0
560+
561+
sage: L = LazyDirichletSeriesRing(ZZ, 'z')
562+
sage: L.zero()
563+
0
564+
565+
sage: L = LazyTaylorSeriesRing(ZZ, 'z')
566+
sage: L.zero()
567+
0
568+
"""
569+
return self.element_class(self, Stream_zero(self._sparse))
570+
571+
def characteristic(self):
572+
"""
573+
Return the characteristic of this lazy power series ring, which
574+
is the same as the characteristic of its base ring.
575+
576+
EXAMPLES::
577+
578+
sage: L.<t> = LazyLaurentSeriesRing(ZZ)
579+
sage: L.characteristic()
580+
0
581+
582+
sage: R.<w> = LazyLaurentSeriesRing(GF(11)); R
583+
Lazy Laurent Series Ring in w over Finite Field of size 11
584+
sage: R.characteristic()
585+
11
586+
587+
sage: R.<x, y> = LazyTaylorSeriesRing(GF(7)); R
588+
Multivariate Lazy Taylor Series Ring in x, y over Finite Field of size 7
589+
sage: R.characteristic()
590+
7
591+
592+
sage: L = LazyDirichletSeriesRing(ZZ, "s")
593+
sage: L.characteristic()
594+
0
595+
"""
596+
return self.base_ring().characteristic()
597+
598+
def _coerce_map_from_(self, S):
599+
"""
600+
Return ``True`` if a coercion from ``S`` exists.
601+
602+
EXAMPLES::
603+
604+
sage: L = LazyLaurentSeriesRing(GF(2), 'z')
605+
sage: L.has_coerce_map_from(ZZ)
606+
True
607+
sage: L.has_coerce_map_from(GF(2))
608+
True
609+
610+
sage: L = LazyTaylorSeriesRing(GF(2), 'z')
611+
sage: L.has_coerce_map_from(ZZ)
612+
True
613+
sage: L.has_coerce_map_from(GF(2))
614+
True
615+
616+
sage: s = SymmetricFunctions(GF(2)).s()
617+
sage: L = LazySymmetricFunctions(s)
618+
sage: L.has_coerce_map_from(ZZ)
619+
True
620+
sage: L.has_coerce_map_from(GF(2))
621+
True
622+
"""
623+
if self.base_ring().has_coerce_map_from(S):
624+
return True
625+
626+
R = self._laurent_poly_ring
627+
return R.has_coerce_map_from(S)
628+
629+
def _coerce_map_from_base_ring(self):
630+
"""
631+
Return a coercion map from the base ring of ``self``.
632+
633+
EXAMPLES::
634+
635+
sage: L = LazyLaurentSeriesRing(QQ, 'z')
636+
sage: phi = L._coerce_map_from_base_ring()
637+
sage: phi(2)
638+
2
639+
sage: phi(2, valuation=-2)
640+
2*z^-2
641+
sage: phi(2, valuation=-2, constant=3, degree=1)
642+
2*z^-2 + 3*z + 3*z^2 + 3*z^3 + O(z^4)
643+
644+
sage: L = LazyDirichletSeriesRing(QQ, 'z')
645+
sage: phi = L._coerce_map_from_base_ring()
646+
sage: phi(2)
647+
2
648+
sage: phi(2, valuation=2)
649+
2/2^z
650+
sage: phi(2, valuation=2, constant=4)
651+
2/2^z + 4/3^z + 4/4^z + 4/5^z + O(1/(6^z))
652+
"""
653+
# Return a DefaultConvertMap_unique; this can pass additional
654+
# arguments to _element_constructor_, unlike the map returned
655+
# by UnitalAlgebras.ParentMethods._coerce_map_from_base_ring.
656+
return self._generic_coerce_map(self.base_ring())
657+
658+
def is_sparse(self):
659+
"""
660+
Return whether ``self`` is sparse or not.
661+
662+
EXAMPLES::
663+
664+
sage: L = LazyLaurentSeriesRing(ZZ, 'z', sparse=False)
665+
sage: L.is_sparse()
666+
False
667+
668+
sage: L = LazyLaurentSeriesRing(ZZ, 'z', sparse=True)
669+
sage: L.is_sparse()
670+
True
671+
"""
672+
return self._sparse
673+
674+
513675
class LazyLaurentSeriesRing(LazySeriesRing):
514676
"""
515677
The ring of lazy Laurent series.
@@ -732,40 +894,6 @@ def _latex_(self):
732894
from sage.misc.latex import latex
733895
return latex(self.base_ring()) + r"(\!({})\!)".format(self.variable_name())
734896

735-
def characteristic(self):
736-
"""
737-
Return the characteristic of this lazy power series ring, which
738-
is the same as the characteristic of its base ring.
739-
740-
EXAMPLES::
741-
742-
sage: L.<t> = LazyLaurentSeriesRing(ZZ)
743-
sage: L.characteristic()
744-
0
745-
sage: R.<w> = LazyLaurentSeriesRing(GF(11)); R
746-
Lazy Laurent Series Ring in w over Finite Field of size 11
747-
sage: R.characteristic()
748-
11
749-
750-
"""
751-
return self.base_ring().characteristic()
752-
753-
def is_sparse(self):
754-
"""
755-
Return whether ``self`` is sparse or not.
756-
757-
EXAMPLES::
758-
759-
sage: L = LazyLaurentSeriesRing(ZZ, 'z', sparse=False)
760-
sage: L.is_sparse()
761-
False
762-
763-
sage: L = LazyLaurentSeriesRing(ZZ, 'z', sparse=True)
764-
sage: L.is_sparse()
765-
True
766-
"""
767-
return self._sparse
768-
769897
@cached_method
770898
def gen(self, n=0):
771899
r"""
@@ -817,44 +945,6 @@ def gens(self):
817945
"""
818946
return tuple([self.gen(n) for n in range(self.ngens())])
819947

820-
def _coerce_map_from_(self, S):
821-
"""
822-
Return ``True`` if a coercion from ``S`` exists.
823-
824-
EXAMPLES::
825-
826-
sage: L = LazyLaurentSeriesRing(GF(2), 'z')
827-
sage: L.has_coerce_map_from(ZZ)
828-
True
829-
sage: L.has_coerce_map_from(GF(2))
830-
True
831-
"""
832-
if self.base_ring().has_coerce_map_from(S):
833-
return True
834-
835-
R = self._laurent_poly_ring
836-
return R.has_coerce_map_from(S)
837-
838-
def _coerce_map_from_base_ring(self):
839-
"""
840-
Return a coercion map from the base ring of ``self``.
841-
842-
EXAMPLES::
843-
844-
sage: L = LazyLaurentSeriesRing(QQ, 'z')
845-
sage: phi = L._coerce_map_from_base_ring()
846-
sage: phi(2)
847-
2
848-
sage: phi(2, valuation=-2)
849-
2*z^-2
850-
sage: phi(2, valuation=-2, constant=3, degree=1)
851-
2*z^-2 + 3*z + 3*z^2 + 3*z^3 + O(z^4)
852-
"""
853-
# Return a DefaultConvertMap_unique; this can pass additional
854-
# arguments to _element_constructor_, unlike the map returned
855-
# by UnitalAlgebras.ParentMethods._coerce_map_from_base_ring.
856-
return self._generic_coerce_map(self.base_ring())
857-
858948
def _an_element_(self):
859949
"""
860950
Return a Laurent series in ``self``.
@@ -905,34 +995,6 @@ def some_elements(self):
905995
(1 - 2*z**-3)/(1 - z + 3*z**2), self(lambda n: n**2, valuation=-2)]
906996
return elts
907997

908-
@cached_method
909-
def one(self):
910-
r"""
911-
Return the constant series `1`.
912-
913-
EXAMPLES::
914-
915-
sage: L = LazyLaurentSeriesRing(ZZ, 'z')
916-
sage: L.one()
917-
1
918-
"""
919-
R = self.base_ring()
920-
coeff_stream = Stream_exact([R.one()], self._sparse, constant=R.zero(), degree=1)
921-
return self.element_class(self, coeff_stream)
922-
923-
@cached_method
924-
def zero(self):
925-
r"""
926-
Return the zero series.
927-
928-
EXAMPLES::
929-
930-
sage: L = LazyLaurentSeriesRing(ZZ, 'z')
931-
sage: L.zero()
932-
0
933-
"""
934-
return self.element_class(self, Stream_zero(self._sparse))
935-
936998
def series(self, coefficient, valuation, degree=None, constant=None):
937999
r"""
9381000
Return a lazy Laurent series.
@@ -1188,34 +1250,6 @@ def gens(self):
11881250
"""
11891251
return tuple([self.gen(n) for n in range(self.ngens())])
11901252

1191-
def _coerce_map_from_(self, S):
1192-
"""
1193-
Return ``True`` if a coercion from ``S`` exists.
1194-
1195-
EXAMPLES::
1196-
1197-
sage: L = LazyTaylorSeriesRing(GF(2), 'z')
1198-
sage: L.has_coerce_map_from(ZZ)
1199-
True
1200-
sage: L.has_coerce_map_from(GF(2))
1201-
True
1202-
"""
1203-
if self.base_ring().has_coerce_map_from(S):
1204-
return True
1205-
1206-
R = self._laurent_poly_ring
1207-
return R.has_coerce_map_from(S)
1208-
1209-
def _coerce_map_from_base_ring(self):
1210-
"""
1211-
Return a coercion map from the base ring of ``self``.
1212-
1213-
"""
1214-
# Return a DefaultConvertMap_unique; this can pass additional
1215-
# arguments to _element_constructor_, unlike the map returned
1216-
# by UnitalAlgebras.ParentMethods._coerce_map_from_base_ring.
1217-
return self._generic_coerce_map(self.base_ring())
1218-
12191253
def _element_constructor_(self, x=None, valuation=None, constant=None, degree=None, check=True):
12201254
"""
12211255
Construct a Taylor series from ``x``.
@@ -1426,33 +1460,6 @@ def _an_element_(self):
14261460
coeff_stream = Stream_exact([R.one()], self._sparse, order=1, constant=c)
14271461
return self.element_class(self, coeff_stream)
14281462

1429-
@cached_method
1430-
def one(self):
1431-
r"""
1432-
Return the constant series `1`.
1433-
1434-
EXAMPLES::
1435-
1436-
sage: L = LazyTaylorSeriesRing(ZZ, 'z')
1437-
sage: L.one()
1438-
1
1439-
"""
1440-
R = self._laurent_poly_ring
1441-
coeff_stream = Stream_exact([R.one()], self._sparse, constant=ZZ.zero(), degree=1)
1442-
return self.element_class(self, coeff_stream)
1443-
1444-
@cached_method
1445-
def zero(self):
1446-
r"""
1447-
Return the zero series.
1448-
1449-
EXAMPLES::
1450-
1451-
sage: L = LazyTaylorSeriesRing(ZZ, 'z')
1452-
sage: L.zero()
1453-
0
1454-
"""
1455-
return self.element_class(self, Stream_zero(self._sparse))
14561463

14571464
######################################################################
14581465

@@ -1554,35 +1561,6 @@ def _monomial(self, c, n):
15541561
L = self._laurent_poly_ring
15551562
return L(c)
15561563

1557-
def _coerce_map_from_(self, S):
1558-
"""
1559-
Return ``True`` if a coercion from ``S`` exists.
1560-
1561-
EXAMPLES::
1562-
1563-
sage: s = SymmetricFunctions(GF(2)).s()
1564-
sage: L = LazySymmetricFunctions(s)
1565-
sage: L.has_coerce_map_from(ZZ)
1566-
True
1567-
sage: L.has_coerce_map_from(GF(2))
1568-
True
1569-
"""
1570-
if self.base_ring().has_coerce_map_from(S):
1571-
return True
1572-
1573-
R = self._laurent_poly_ring
1574-
return R.has_coerce_map_from(S)
1575-
1576-
def _coerce_map_from_base_ring(self):
1577-
"""
1578-
Return a coercion map from the base ring of ``self``.
1579-
1580-
"""
1581-
# Return a DefaultConvertMap_unique; this can pass additional
1582-
# arguments to _element_constructor_, unlike the map returned
1583-
# by UnitalAlgebras.ParentMethods._coerce_map_from_base_ring.
1584-
return self._generic_coerce_map(self.base_ring())
1585-
15861564
def _element_constructor_(self, x=None, valuation=None, degree=None, check=True):
15871565
"""
15881566
Construct a lazy symmetric function from ``x``.
@@ -1774,36 +1752,6 @@ def _an_element_(self):
17741752
coeff_stream = Stream_exact([R.one()], self._sparse, order=1, constant=0)
17751753
return self.element_class(self, coeff_stream)
17761754

1777-
@cached_method
1778-
def one(self):
1779-
r"""
1780-
Return the constant `1`.
1781-
1782-
EXAMPLES::
1783-
1784-
sage: m = SymmetricFunctions(ZZ).m()
1785-
sage: L = LazySymmetricFunctions(m)
1786-
sage: L.one()
1787-
m[]
1788-
"""
1789-
R = self._laurent_poly_ring
1790-
coeff_stream = Stream_exact([R.one()], self._sparse, constant=ZZ.zero(), degree=1)
1791-
return self.element_class(self, coeff_stream)
1792-
1793-
@cached_method
1794-
def zero(self):
1795-
r"""
1796-
Return the zero series.
1797-
1798-
EXAMPLES::
1799-
1800-
sage: s = SymmetricFunctions(ZZ).s()
1801-
sage: L = LazySymmetricFunctions(s)
1802-
sage: L.zero()
1803-
0
1804-
"""
1805-
return self.element_class(self, Stream_zero(self._sparse))
1806-
18071755
######################################################################
18081756

18091757
class LazyDirichletSeriesRing(LazySeriesRing):
@@ -1860,18 +1808,22 @@ def _repr_(self):
18601808
"""
18611809
return "Lazy Dirichlet Series Ring in {} over {}".format(self.variable_name(), self.base_ring())
18621810

1863-
def characteristic(self):
1864-
"""
1865-
Return the characteristic of this lazy power series ring, which
1866-
is the same as the characteristic of its base ring.
1811+
@cached_method
1812+
def one(self):
1813+
r"""
1814+
Return the constant series `1`.
18671815
18681816
EXAMPLES::
18691817
1870-
sage: L = LazyDirichletSeriesRing(ZZ, "s")
1871-
sage: L.characteristic()
1872-
0
1818+
sage: L = LazyDirichletSeriesRing(ZZ, 'z')
1819+
sage: L.one()
1820+
1
1821+
sage: ~L.one()
1822+
1 + O(1/(8^z))
18731823
"""
1874-
return self.base_ring().characteristic()
1824+
R = self.base_ring()
1825+
coeff_stream = Stream_exact([R.one()], self._sparse, constant=R.zero(), order=1)
1826+
return self.element_class(self, coeff_stream)
18751827

18761828
def _coerce_map_from_(self, S):
18771829
"""
@@ -1887,29 +1839,8 @@ def _coerce_map_from_(self, S):
18871839
"""
18881840
if self.base_ring().has_coerce_map_from(S):
18891841
return True
1890-
18911842
return False
18921843

1893-
def _coerce_map_from_base_ring(self):
1894-
r"""
1895-
Return a coercion map from the base ring of ``self``.
1896-
1897-
EXAMPLES::
1898-
1899-
sage: L = LazyDirichletSeriesRing(QQ, 'z')
1900-
sage: phi = L._coerce_map_from_base_ring()
1901-
sage: phi(2)
1902-
2
1903-
sage: phi(2, valuation=2)
1904-
2/2^z
1905-
sage: phi(2, valuation=2, constant=4)
1906-
2/2^z + 4/3^z + 4/4^z + 4/5^z + O(1/(6^z))
1907-
"""
1908-
# Return a DefaultConvertMap_unique; this can pass additional
1909-
# arguments to _element_constructor_, unlike the map returned
1910-
# by UnitalAlgebras.ParentMethods._coerce_map_from_base_ring.
1911-
return self._generic_coerce_map(self.base_ring())
1912-
19131844
def _element_constructor_(self, x=None, valuation=None, degree=None, constant=None, coefficients=None):
19141845
r"""
19151846
Construct a Dirichlet series from ``x``.
@@ -2037,35 +1968,6 @@ def _an_element_(self):
20371968
c = self.base_ring().an_element()
20381969
return self.element_class(self, Stream_exact([], self._sparse, constant=c, order=4))
20391970

2040-
@cached_method
2041-
def one(self):
2042-
"""
2043-
Return the constant series `1`.
2044-
2045-
EXAMPLES::
2046-
2047-
sage: L = LazyDirichletSeriesRing(ZZ, 'z')
2048-
sage: L.one()
2049-
1
2050-
sage: ~L.one()
2051-
1 + O(1/(8^z))
2052-
"""
2053-
R = self.base_ring()
2054-
return self.element_class(self, Stream_exact([R.one()], self._sparse, order=1))
2055-
2056-
@cached_method
2057-
def zero(self):
2058-
"""
2059-
Return the zero series.
2060-
2061-
EXAMPLES::
2062-
2063-
sage: L = LazyDirichletSeriesRing(ZZ, 'z')
2064-
sage: L.zero()
2065-
0
2066-
"""
2067-
return self.element_class(self, Stream_zero(self._sparse))
2068-
20691971
def _monomial(self, c, n):
20701972
r"""
20711973
Return the interpretation of the coefficient ``c`` at index ``n``.

0 commit comments

Comments
 (0)
This repository has been archived.