Skip to content

Commit

Permalink
Better uninitialized checking; fixing doctests.
Browse files Browse the repository at this point in the history
  • Loading branch information
tscrim committed Sep 12, 2023
1 parent 041cea6 commit 297c980
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/sage/combinat/species/recursive_species.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def _gs(self, series_ring, base_ring):
sage: F = CombinatorialSpecies()
sage: F.generating_series()
Uninitialized Lazy Laurent Series
Uninitialized Lazy Series
"""
if base_ring not in self._generating_series:
self._generating_series[base_ring] = series_ring.undefined(valuation=(0 if self._min is None else self._min))
Expand All @@ -247,7 +247,7 @@ def _itgs(self, series_ring, base_ring):
sage: F = CombinatorialSpecies()
sage: F.isotype_generating_series()
Uninitialized Lazy Laurent Series
Uninitialized Lazy Series
"""
if base_ring not in self._isotype_generating_series:
self._isotype_generating_series[base_ring] = series_ring.undefined(valuation=(0 if self._min is None else self._min))
Expand All @@ -264,7 +264,7 @@ def _cis(self, series_ring, base_ring):
sage: F = CombinatorialSpecies()
sage: F.cycle_index_series()
Uninitialized Lazy Laurent Series
Uninitialized Lazy Series
"""
if base_ring not in self._cycle_index_series:
self._cycle_index_series[base_ring] = series_ring.undefined(valuation=(0 if self._min is None else self._min))
Expand Down
11 changes: 10 additions & 1 deletion src/sage/data_structures/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,7 @@ def __init__(self, approximate_order, true_order=False):
raise ValueError("the valuation must be specified for undefined series")
super().__init__(False, true_order)
self._approximate_order = approximate_order
self._initializing = False

def iterate_coefficients(self):
"""
Expand Down Expand Up @@ -1113,7 +1114,15 @@ def is_uninitialized(self):
sage: C.is_uninitialized()
True
"""
return self._target is None
if self._target is None:
return True
if self._initializing:
return False
# We implement semaphore-like behavior for coupled (undefined) series
self._initializing = True
result = self._target.is_uninitialized()
self._initializing = False
return result


class Stream_unary(Stream_inexact):
Expand Down
8 changes: 5 additions & 3 deletions src/sage/rings/lazy_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3605,7 +3605,8 @@ def exp(self):
coeff_stream = self._coeff_stream
# TODO: coefficients should not be checked here, it prevents
# us from using self.define in some cases!
if any(coeff_stream[i] for i in range(coeff_stream._approximate_order, 1)):
if ((not coeff_stream.is_uninitialized())
and any(coeff_stream[i] for i in range(coeff_stream._approximate_order, 1))):
raise ValueError("can only compose with a positive valuation series")
# WARNING: d_self need not be a proper element of P, e.g. for
# multivariate power series
Expand Down Expand Up @@ -3657,8 +3658,9 @@ def log(self):
coeff_stream = self._coeff_stream
# TODO: coefficients should not be checked here, it prevents
# us from using self.define in some cases!
if (any(coeff_stream[i] for i in range(coeff_stream._approximate_order, 0))
or coeff_stream[0] != R.one()):
if ((not coeff_stream.is_uninitialized())
and (any(coeff_stream[i] for i in range(coeff_stream._approximate_order, 0))
or coeff_stream[0] != R.one())):
raise ValueError("can only compose with a positive valuation series")
# WARNING: d_self need not be a proper element of P, e.g. for
# multivariate power series
Expand Down

0 comments on commit 297c980

Please sign in to comment.