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

Commit

Permalink
Make the Dirichlet series input only convert Dirichlet series.
Browse files Browse the repository at this point in the history
  • Loading branch information
tscrim committed Sep 21, 2021
1 parent 30d3804 commit 3cea7f1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
6 changes: 4 additions & 2 deletions src/sage/rings/lazy_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@


from sage.rings.infinity import infinity
from sage.structure.element import Element
from sage.structure.element import Element, parent
from sage.rings.integer_ring import ZZ
from sage.structure.richcmp import op_EQ, op_NE
from sage.arith.power import generic_power
Expand Down Expand Up @@ -1782,6 +1782,8 @@ def __call__(self, g):
z^-6 + 4*z^-5 + 12*z^-4 + 33*z^-3 + 82*z^-2 + 196*z^-1 + 457 + O(z)
sage: g^2 + 1 + g
z^-6 + 4*z^-5 + 12*z^-4 + 33*z^-3 + 82*z^-2 + 196*z^-1 + 457 + O(z)
sage: f(int(2))
7
sage: f = z^-2 + z + 4*z^3
sage: f(f)
Expand Down Expand Up @@ -2027,7 +2029,7 @@ def __call__(self, g):
# f = self and compute f(g)
from sage.structure.element import get_coercion_model
cm = get_coercion_model()
P = cm.common_parent(self.base_ring(), g.parent())
P = cm.common_parent(self.base_ring(), parent(g))

# f = 0
if isinstance(self._coeff_stream, Stream_zero):
Expand Down
30 changes: 18 additions & 12 deletions src/sage/rings/lazy_series_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No
raise ValueError("the valuation must be specified")
return self.element_class(self, Stream_uninitialized(self._sparse, valuation))

if coefficients is not None and (not isinstance(x, int) or x):
if coefficients is not None and (x is not None and (not isinstance(x, int) or x)):
raise ValueError("coefficients must be None if x is provided")

BR = self.base_ring()
Expand Down Expand Up @@ -1112,8 +1112,8 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No
sage: L.<z> = LazyLaurentSeriesRing(QQ)
sage: D = LazyDirichletSeriesRing(QQ, 't')
sage: D(z+z^2)
1 + 1/(2^t)
sage: D(L.one())
1 + 1/(2^t) + 1/(3^t) + 1/(4^t) + 1/(5^t) + 1/(6^t) + 1/(7^t) + O(1/(8^t))
sage: R.<z> = LaurentPolynomialRing(QQ)
sage: D = LazyDirichletSeriesRing(QQ, 't')
Expand All @@ -1132,18 +1132,24 @@ def _element_constructor_(self, x=None, valuation=None, degree=None, constant=No
x = p
else:
x = p.shift(1)
elif not isinstance(x, LazyModuleElement) and valuation is None:
valuation = 1
else:
if valuation is None:
valuation = 1

if valuation is not None and (valuation not in ZZ or valuation <= 0):
raise ValueError("the valuation must be a positive integer")
if coefficients is not None:
return super()._element_constructor_(x, valuation, degree, constant, coefficients)

if coefficients is not None:
return super()._element_constructor_(x, valuation, degree, constant, coefficients)
BR = self.base_ring()
if x in BR:
x = BR(x)
if (isinstance(x, LazyModuleElement) and not isinstance(x, LazyDirichletSeries)) or callable(x):
if coefficients is not None:
raise ValueError("coefficients must be None if x is provided")
coefficients = x
x = None

BR = self.base_ring()
if x in BR:
x = BR(x)
if valuation is not None and (valuation not in ZZ or valuation <= 0):
raise ValueError("the valuation must be a positive integer")

return super()._element_constructor_(x, valuation, degree, constant, coefficients)

Expand Down

0 comments on commit 3cea7f1

Please sign in to comment.