Skip to content

Commit 31725f0

Browse files
committed
replace optional keyword parameter check with checking for uninitialized series
1 parent c306b71 commit 31725f0

File tree

1 file changed

+31
-39
lines changed

1 file changed

+31
-39
lines changed

src/sage/rings/lazy_series.py

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ def define(self, s):
13811381
sage: E = L(lambda n: s[n], valuation=0)
13821382
sage: X = L(s[1])
13831383
sage: A = L.undefined()
1384-
sage: A.define(X*E(A, check=False))
1384+
sage: A.define(X*E(A))
13851385
sage: A[:6]
13861386
[m[1],
13871387
2*m[1, 1] + m[2],
@@ -3632,7 +3632,7 @@ def exp(self):
36323632
P = self.parent()
36333633
R = self.base_ring()
36343634
coeff_stream = self._coeff_stream
3635-
# TODO: coefficients should not be checked here, it prevents
3635+
# coefficients must not be checked here, it prevents
36363636
# us from using self.define in some cases!
36373637
if ((not coeff_stream.is_uninitialized())
36383638
and any(coeff_stream[i] for i in range(coeff_stream._approximate_order, 1))):
@@ -3685,7 +3685,7 @@ def log(self):
36853685
P = self.parent()
36863686
R = self.base_ring()
36873687
coeff_stream = self._coeff_stream
3688-
# TODO: coefficients should not be checked here, it prevents
3688+
# coefficients must not be checked here, it prevents
36893689
# us from using self.define in some cases!
36903690
if ((not coeff_stream.is_uninitialized())
36913691
and (any(coeff_stream[i] for i in range(coeff_stream._approximate_order, 0))
@@ -3827,7 +3827,7 @@ def _im_gens_(self, codomain, im_gens, base_map=None):
38273827

38283828
return codomain(self.map_coefficients(base_map)(im_gens[0]))
38293829

3830-
def __call__(self, g, *, check=True):
3830+
def __call__(self, g):
38313831
r"""
38323832
Return the composition of ``self`` with ``g``.
38333833
@@ -4221,18 +4221,18 @@ def __call__(self, g, *, check=True):
42214221
raise NotImplementedError("can only compose with a lazy series")
42224222

42234223
# Perhaps we just don't yet know if the valuation is positive
4224-
if check:
4225-
if g._coeff_stream._approximate_order <= 0:
4226-
if any(g._coeff_stream[i] for i in range(g._coeff_stream._approximate_order, 1)):
4227-
raise ValueError("can only compose with a positive valuation series")
4228-
g._coeff_stream._approximate_order = 1
4224+
if g._coeff_stream._approximate_order <= 0:
4225+
if (not g._coeff_stream.is_uninitialized()
4226+
and any(g._coeff_stream[i] for i in range(g._coeff_stream._approximate_order, 1))):
4227+
raise ValueError("can only compose with a positive valuation series")
4228+
g._coeff_stream._approximate_order = 1
42294229

42304230
if isinstance(g, LazyDirichletSeries):
4231-
if check:
4232-
if g._coeff_stream._approximate_order == 1:
4233-
if g._coeff_stream[1] != 0:
4234-
raise ValueError("can only compose with a positive valuation series")
4235-
g._coeff_stream._approximate_order = 2
4231+
if g._coeff_stream._approximate_order == 1:
4232+
if (not g._coeff_stream.is_uninitialized()
4233+
and g._coeff_stream[1] != 0):
4234+
raise ValueError("can only compose with a positive valuation series")
4235+
g._coeff_stream._approximate_order = 2
42364236
# we assume that the valuation of self[i](g) is at least i
42374237

42384238
def coefficient(n):
@@ -4815,7 +4815,7 @@ def _im_gens_(self, codomain, im_gens, base_map=None):
48154815

48164816
return codomain(self.map_coefficients(base_map)(*im_gens))
48174817

4818-
def __call__(self, *g, check=True):
4818+
def __call__(self, *g):
48194819
r"""
48204820
Return the composition of ``self`` with ``g``.
48214821
@@ -5068,18 +5068,17 @@ def __call__(self, *g, check=True):
50685068
g = [P(h) for h in g]
50695069
R = P._internal_poly_ring.base_ring()
50705070

5071-
if check:
5072-
for h in g:
5073-
if h._coeff_stream._approximate_order == 0:
5074-
if h[0]:
5075-
raise ValueError("can only compose with a positive valuation series")
5076-
h._coeff_stream._approximate_order = 1
5071+
for h in g:
5072+
if h._coeff_stream._approximate_order == 0:
5073+
if not h._coeff_stream.is_uninitialized() and h[0]:
5074+
raise ValueError("can only compose with a positive valuation series")
5075+
h._coeff_stream._approximate_order = 1
50775076

5078-
if isinstance(h, LazyDirichletSeries):
5079-
if h._coeff_stream._approximate_order == 1:
5080-
if h._coeff_stream[1] != 0:
5081-
raise ValueError("can only compose with a positive valuation series")
5082-
h._coeff_stream._approximate_order = 2
5077+
if isinstance(h, LazyDirichletSeries):
5078+
if h._coeff_stream._approximate_order == 1:
5079+
if not h._coeff_stream.is_uninitialized() and h._coeff_stream[1] != 0:
5080+
raise ValueError("can only compose with a positive valuation series")
5081+
h._coeff_stream._approximate_order = 2
50835082

50845083
# We now have that every element of g has a _coeff_stream
50855084
sorder = self._coeff_stream._approximate_order
@@ -5812,7 +5811,7 @@ def is_unit(self):
58125811
return False
58135812
return self[0].is_unit()
58145813

5815-
def __call__(self, *args, check=True):
5814+
def __call__(self, *args):
58165815
r"""
58175816
Return the composition of ``self`` with ``g``.
58185817
@@ -5998,10 +5997,10 @@ def __call__(self, *args, check=True):
59985997
P = LazySymmetricFunctions(R)
59995998
g = P(g)
60005999

6001-
if check and not (isinstance(self._coeff_stream, Stream_exact)
6002-
and not self._coeff_stream._constant):
6000+
if not (isinstance(self._coeff_stream, Stream_exact)
6001+
and not self._coeff_stream._constant):
60036002
if g._coeff_stream._approximate_order == 0:
6004-
if g[0]:
6003+
if not g._coeff_stream.is_uninitialized() and g[0]:
60056004
raise ValueError("can only compose with a positive valuation series")
60066005
g._coeff_stream._approximate_order = 1
60076006

@@ -6401,7 +6400,7 @@ def coefficient(n):
64016400
else:
64026401
raise NotImplementedError("only implemented for arity 1")
64036402

6404-
def arithmetic_product(self, *args, check=True):
6403+
def arithmetic_product(self, *args):
64056404
r"""
64066405
Return the arithmetic product of ``self`` with ``g``.
64076406
@@ -6450,9 +6449,6 @@ def arithmetic_product(self, *args, check=True):
64506449
64516450
- ``g`` -- a cycle index series having the same parent as ``self``
64526451
6453-
- ``check`` -- (default: ``True``) a Boolean which, when set
6454-
to ``False``, will cause input checks to be skipped
6455-
64566452
OUTPUT:
64576453
64586454
The arithmetic product of ``self`` with ``g``.
@@ -6596,15 +6592,11 @@ def arithmetic_product(self, *args, check=True):
65966592
and not g._coeff_stream._constant):
65976593
gs = g.symmetric_function()
65986594
c += self[0].arithmetic_product(gs)
6599-
elif check:
6600-
raise ValueError("can only take the arithmetic product with a positive valuation series")
66016595
if g[0]:
66026596
if (isinstance(self._coeff_stream, Stream_exact)
66036597
and not self._coeff_stream._constant):
66046598
fs = self.symmetric_function()
66056599
c += fs.arithmetic_product(g[0])
6606-
elif check:
6607-
raise ValueError("can only take the arithmetic product with a positive valuation series")
66086600

66096601
p = R.realization_of().p()
66106602
# TODO: does the following introduce a memory leak?
@@ -6879,7 +6871,7 @@ def __invert__(self):
68796871
return P.element_class(P, Stream_dirichlet_invert(self._coeff_stream,
68806872
P.is_sparse()))
68816873

6882-
def __call__(self, p, *, check=True):
6874+
def __call__(self, p):
68836875
r"""
68846876
Return the composition of ``self`` with a linear polynomial ``p``.
68856877

0 commit comments

Comments
 (0)