Skip to content

Commit

Permalink
sagemathgh-38290: Deprecate is_LaurentSeriesRing, `is_MPowerSeriesR…
Browse files Browse the repository at this point in the history
…ing`, `is_PowerSeriesRing`

    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

Part of
- sagemath#32414

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [ ] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->

- Depends on sagemath#38266 (merged here)
    
URL: sagemath#38290
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee
  • Loading branch information
Release Manager committed Aug 2, 2024
2 parents ef4d199 + 1fe1648 commit 8bc2d84
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 74 deletions.
10 changes: 6 additions & 4 deletions src/sage/modular/modform_hecketriangle/abstract_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@
from sage.rings.infinity import infinity
from sage.rings.integer import Integer
from sage.rings.integer_ring import ZZ
from sage.rings.laurent_series_ring import is_LaurentSeriesRing
from sage.rings.laurent_series_ring import LaurentSeriesRing
from sage.rings.polynomial.polynomial_ring import PolynomialRing_general
from sage.rings.power_series_ring import is_PowerSeriesRing
from sage.rings.power_series_ring import PowerSeriesRing_generic
from sage.rings.rational_field import QQ
from sage.structure.element import parent

from .abstract_ring import FormsRing_abstract

lazy_import('sage.rings.imaginary_unit', 'I')
lazy_import('sage.rings.lazy_series_ring', ('LazyLaurentSeriesRing', 'LazyPowerSeriesRing'))
lazy_import('sage.rings.qqbar', 'QQbar')


Expand Down Expand Up @@ -254,8 +255,9 @@ def _element_constructor_(self, el):
# can be changed in construct_form
# resp. construct_quasi_form))
P = parent(el)
if is_LaurentSeriesRing(P) or is_PowerSeriesRing(P):
if (self.is_modular()):
if isinstance(P, (LaurentSeriesRing, PowerSeriesRing_generic,
LazyLaurentSeriesRing, LazyPowerSeriesRing)):
if self.is_modular():
return self.construct_form(el)
else:
return self.construct_quasi_form(el)
Expand Down
23 changes: 14 additions & 9 deletions src/sage/rings/asymptotic/asymptotic_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,24 @@
# https://www.gnu.org/licenses/
# *****************************************************************************

import sage.rings.abc

from sage.categories.pushout import ConstructionFunctor
from sage.misc.defaults import series_precision
from sage.misc.lazy_import import lazy_import
from sage.rings.real_mpfi import RIF
from sage.structure.element import CommutativeAlgebraElement
from sage.structure.parent import Parent
from sage.structure.unique_representation import UniqueRepresentation
from sage.misc.defaults import series_precision
from sage.categories.pushout import ConstructionFunctor
import sage.rings.abc
from sage.rings.real_mpfi import RIF

from .misc import WithLocals

lazy_import('sage.rings.lazy_series_ring', 'LazyPowerSeriesRing')
lazy_import('sage.rings.polynomial.multi_polynomial_ring_base', 'MPolynomialRing_base')
lazy_import('sage.rings.polynomial.polynomial_ring', 'PolynomialRing_general')
lazy_import('sage.rings.power_series_ring', 'PowerSeriesRing_generic')
lazy_import('sage.symbolic.ring', 'SymbolicRing')


class NoConvergenceError(RuntimeError):
r"""
Expand Down Expand Up @@ -3988,10 +3997,6 @@ def _element_constructor_(self, data, simplify=True, convert=True):
return self.create_summand('exact', data)

from .misc import combine_exceptions
from sage.symbolic.ring import SymbolicRing
from sage.rings.polynomial.polynomial_ring import PolynomialRing_general
from sage.rings.polynomial.multi_polynomial_ring_base import MPolynomialRing_base
from sage.rings.power_series_ring import is_PowerSeriesRing

if isinstance(P, SymbolicRing):
from sage.symbolic.operators import add_vararg
Expand Down Expand Up @@ -4028,7 +4033,7 @@ def _element_constructor_(self, data, simplify=True, convert=True):
raise combine_exceptions(
ValueError('Polynomial %s is not in %s' % (data, self)), e)

elif is_PowerSeriesRing(P):
elif isinstance(P, (PowerSeriesRing_generic, LazyPowerSeriesRing)):
raise NotImplementedError(
'cannot convert %s from the %s to an asymptotic expansion '
'in %s, since growths at other points than +oo are not yet '
Expand Down
16 changes: 9 additions & 7 deletions src/sage/rings/asymptotic/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,15 @@
# ****************************************************************************

from sage.misc.cachefunc import cached_method
from sage.misc.lazy_import import lazy_import
from sage.structure.sage_object import SageObject

lazy_import('sage.rings.lazy_series_ring', 'LazyPowerSeriesRing')
lazy_import('sage.rings.multi_power_series_ring', 'MPowerSeriesRing_generic')
lazy_import('sage.rings.polynomial.multi_polynomial_ring_base', 'MPolynomialRing_base')
lazy_import('sage.rings.polynomial.polynomial_ring', 'PolynomialRing_general')
lazy_import('sage.rings.power_series_ring', 'PowerSeriesRing_generic')


def repr_short_to_parent(s):
r"""
Expand Down Expand Up @@ -145,9 +152,6 @@ def parent_to_repr_short(P):
from sage.rings.real_mpfi import RIF
from sage.rings.real_mpfr import RR
from sage.symbolic.ring import SR
from sage.rings.polynomial.polynomial_ring import PolynomialRing_general
from sage.rings.polynomial.multi_polynomial_ring_base import MPolynomialRing_base
from sage.rings.power_series_ring import is_PowerSeriesRing

def abbreviate(P):
try:
Expand All @@ -164,10 +168,8 @@ def abbreviate(P):
pass
raise ValueError('Cannot abbreviate %s.' % (P,))

poly = isinstance(P, PolynomialRing_general) or isinstance(P, MPolynomialRing_base)
from sage.rings import multi_power_series_ring
power = is_PowerSeriesRing(P) or \
multi_power_series_ring.is_MPowerSeriesRing(P)
poly = isinstance(P, (PolynomialRing_general, MPolynomialRing_base))
power = isinstance(P, (PowerSeriesRing_generic, MPowerSeriesRing_generic, LazyPowerSeriesRing))

if poly or power:
if poly:
Expand Down
39 changes: 23 additions & 16 deletions src/sage/rings/laurent_series_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from sage.categories.integral_domains import IntegralDomains
from sage.categories.rings import Rings
from sage.misc.cachefunc import cached_method
from sage.misc.lazy_import import lazy_import
from sage.rings.infinity import infinity
from sage.rings.integer_ring import ZZ
from sage.rings.laurent_series_ring_element import LaurentSeries
Expand All @@ -49,6 +50,11 @@
except ImportError:
pari_gen = ()

lazy_import('sage.rings.polynomial.laurent_polynomial_ring_base', 'LaurentPolynomialRing_generic')
lazy_import('sage.rings.lazy_series_ring', ('LazyPowerSeriesRing', 'LazyLaurentSeriesRing'))
lazy_import('sage.rings.polynomial.polynomial_ring', 'PolynomialRing_general')
lazy_import('sage.rings.power_series_ring', 'PowerSeriesRing_generic')


def is_LaurentSeriesRing(x):
"""
Expand All @@ -62,12 +68,19 @@ def is_LaurentSeriesRing(x):
sage: from sage.rings.laurent_series_ring import is_LaurentSeriesRing
sage: K.<q> = LaurentSeriesRing(QQ)
sage: is_LaurentSeriesRing(K)
doctest:warning...
DeprecationWarning: The function is_LaurentSeriesRing is deprecated;
use 'isinstance(..., (LaurentSeriesRing, LazyLaurentSeriesRing))' instead.
See https://github.com/sagemath/sage/issues/38290 for details.
True
sage: L.<z> = LazyLaurentSeriesRing(QQ)
sage: is_LaurentSeriesRing(L)
True
"""
from sage.rings.lazy_series_ring import LazyLaurentSeriesRing
from sage.misc.superseded import deprecation
deprecation(38290,
"The function is_LaurentSeriesRing is deprecated; "
"use 'isinstance(..., (LaurentSeriesRing, LazyLaurentSeriesRing))' instead.")
return isinstance(x, (LaurentSeriesRing, LazyLaurentSeriesRing))


Expand Down Expand Up @@ -207,9 +220,9 @@ def __classcall__(cls, *args, **kwds):
sage: L.variable_name()
'q'
"""
from .power_series_ring import PowerSeriesRing, is_PowerSeriesRing
from .power_series_ring import PowerSeriesRing

if not kwds and len(args) == 1 and is_PowerSeriesRing(args[0]):
if not kwds and len(args) == 1 and isinstance(args[0], (PowerSeriesRing_generic, LazyPowerSeriesRing)):
power_series = args[0]
else:
power_series = PowerSeriesRing(*args, **kwds)
Expand Down Expand Up @@ -675,18 +688,12 @@ def _coerce_map_from_(self, P):
True
"""
A = self.base_ring()
from sage.rings.polynomial.laurent_polynomial_ring_base import (
LaurentPolynomialRing_generic,
)
from sage.rings.polynomial.polynomial_ring import PolynomialRing_general
from sage.rings.power_series_ring import is_PowerSeriesRing

if ((is_LaurentSeriesRing(P) or
isinstance(P, LaurentPolynomialRing_generic) or
is_PowerSeriesRing(P) or
isinstance(P, PolynomialRing_general))
and P.variable_name() == self.variable_name()
and A.has_coerce_map_from(P.base_ring())):
if (isinstance(P, (LaurentSeriesRing, LazyLaurentSeriesRing,
LaurentPolynomialRing_generic,
PowerSeriesRing_generic, LazyPowerSeriesRing,
PolynomialRing_general))
and P.variable_name() == self.variable_name()
and A.has_coerce_map_from(P.base_ring())):
return True

def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None):
Expand Down Expand Up @@ -721,7 +728,7 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None):
if base_map is None and not codomain.has_coerce_map_from(self.base_ring()):
return False
# Note that 0 is not a *ring* homomorphism, and you cannot map to a power series ring
if is_LaurentSeriesRing(codomain):
if isinstance(codomain, (LaurentSeriesRing, LazyLaurentSeriesRing)):
return im_gens[0].valuation() > 0 and im_gens[0].is_unit()
return False

Expand Down
30 changes: 23 additions & 7 deletions src/sage/rings/multi_power_series_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,14 @@

import sage.misc.latex as latex

from sage.misc.lazy_import import lazy_import
from sage.rings.infinity import infinity
from sage.rings.multi_power_series_ring_element import MPowerSeries
from sage.rings.polynomial.polynomial_ring import PolynomialRing_general
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.polynomial.multi_polynomial_ring import MPolynomialRing_base
from sage.rings.polynomial.term_order import TermOrder
from sage.rings.power_series_ring import PowerSeriesRing, PowerSeriesRing_generic, is_PowerSeriesRing
from sage.rings.power_series_ring import PowerSeriesRing, PowerSeriesRing_generic
from sage.rings.ring import CommutativeRing
from sage.structure.nonexact import Nonexact

Expand All @@ -226,6 +227,8 @@
except ImportError:
LaurentSeriesRing = ()

lazy_import('sage.rings.lazy_series_ring', ('LazyPowerSeriesRing', 'LazyLaurentSeriesRing'))


def is_MPowerSeriesRing(x):
"""
Expand All @@ -237,8 +240,16 @@ def is_MPowerSeriesRing(x):
sage: from sage.rings.multi_power_series_ring import is_MPowerSeriesRing
sage: M = PowerSeriesRing(ZZ, 4, 'v')
sage: is_PowerSeriesRing(M)
doctest:warning...
DeprecationWarning: The function is_PowerSeriesRing is deprecated;
use 'isinstance(..., (PowerSeriesRing_generic, LazyPowerSeriesRing) and ....ngens() == 1)' instead.
See https://github.com/sagemath/sage/issues/38290 for details.
False
sage: is_MPowerSeriesRing(M)
doctest:warning...
DeprecationWarning: The function is_MPowerSeriesRing is deprecated;
use 'isinstance(..., (MPowerSeriesRing_generic, LazyPowerSeriesRing))' instead.
See https://github.com/sagemath/sage/issues/38290 for details.
True
sage: T = PowerSeriesRing(RR, 'v')
sage: is_PowerSeriesRing(T)
Expand All @@ -252,7 +263,10 @@ def is_MPowerSeriesRing(x):
sage: is_MPowerSeriesRing(L)
True
"""
from sage.rings.lazy_series_ring import LazyPowerSeriesRing
from sage.misc.superseded import deprecation
deprecation(38290,
"The function is_MPowerSeriesRing is deprecated; "
"use 'isinstance(..., (MPowerSeriesRing_generic, LazyPowerSeriesRing))' instead.")
return isinstance(x, (MPowerSeriesRing_generic, LazyPowerSeriesRing))


Expand Down Expand Up @@ -659,8 +673,9 @@ def _coerce_impl(self, f):
True
"""
P = f.parent()
if isinstance(P, MPolynomialRing_base) or is_MPowerSeriesRing(P) \
or isinstance(P, PolynomialRing_general) or is_PowerSeriesRing(P):
if isinstance(P, (PolynomialRing_general, MPolynomialRing_base,
PowerSeriesRing_generic, MPowerSeriesRing_generic,
LazyPowerSeriesRing)):
if set(P.variable_names()).issubset(set(self.variable_names())):
if self.has_coerce_map_from(P.base_ring()):
return self(f)
Expand Down Expand Up @@ -738,7 +753,8 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None):
if all(v == 0 for v in im_gens):
return True

if is_MPowerSeriesRing(codomain) or is_PowerSeriesRing(codomain) or isinstance(codomain, LaurentSeriesRing):
if isinstance(codomain, (PowerSeriesRing_generic, MPowerSeriesRing_generic, LazyPowerSeriesRing,
LaurentSeriesRing, LazyLaurentSeriesRing)):
try:
B = all(v.valuation() > 0 or v.is_nilpotent() for v in im_gens)
except NotImplementedError:
Expand Down Expand Up @@ -823,8 +839,8 @@ def _coerce_map_from_(self, P):
sage: R.has_coerce_map_from(L)
True
"""
if isinstance(P, MPolynomialRing_base) or is_MPowerSeriesRing(P) \
or isinstance(P, PolynomialRing_general) or is_PowerSeriesRing(P):
if isinstance(P, (MPolynomialRing_base, MPowerSeriesRing_generic, LazyPowerSeriesRing,
PolynomialRing_general, PowerSeriesRing_generic)):
if set(P.variable_names()).issubset(set(self.variable_names())):
if self.has_coerce_map_from(P.base_ring()):
return True
Expand Down
12 changes: 7 additions & 5 deletions src/sage/rings/multi_power_series_ring_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,17 @@
# https://www.gnu.org/licenses/
# ****************************************************************************

from sage.structure.richcmp import richcmp

from sage.misc.lazy_import import lazy_import
from sage.rings.finite_rings.integer_mod_ring import Zmod
from sage.rings.infinity import infinity, InfinityElement
from sage.rings.integer import Integer
from sage.rings.polynomial.polynomial_ring import PolynomialRing_general
from sage.rings.power_series_ring import is_PowerSeriesRing
from sage.rings.power_series_ring_element import PowerSeries
from sage.structure.richcmp import richcmp

lazy_import('sage.rings.lazy_series_ring', 'LazyPowerSeriesRing')
lazy_import('sage.rings.multi_power_series_ring', 'MPowerSeriesRing_generic')
lazy_import('sage.rings.power_series_ring', 'PowerSeriesRing_generic')


def is_MPowerSeries(f):
Expand Down Expand Up @@ -375,8 +378,7 @@ def __init__(self, parent, x=0, prec=infinity, is_gen=False, check=False):

# test whether x coerces to background univariate
# power series ring of parent
from sage.rings.multi_power_series_ring import is_MPowerSeriesRing
if is_PowerSeriesRing(xparent) or is_MPowerSeriesRing(xparent):
if isinstance(xparent, (PowerSeriesRing_generic, MPowerSeriesRing_generic, LazyPowerSeriesRing)):
# x is either a multivariate or univariate power series
#
# test whether x coerces directly to designated parent
Expand Down
9 changes: 6 additions & 3 deletions src/sage/rings/polynomial/polynomial_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7945,13 +7945,16 @@ cdef class Polynomial(CommutativePolynomial):
4 + 4*T + O(T^2)
"""
# Late import to avoid cyclic dependencies:
from sage.rings.power_series_ring import is_PowerSeriesRing
from sage.rings.power_series_ring import PowerSeriesRing_generic
try:
from sage.rings.lazy_series_ring import LazyPowerSeriesRing
except ImportError:
LazyPowerSeriesRing = ()
if self.is_zero():
return self # return 0
n = self.degree()
base_ring = self._parent.base_ring()
if (isinstance(base_ring, MPolynomialRing_base) or
is_PowerSeriesRing(base_ring)):
if isinstance(base_ring, (MPolynomialRing_base, PowerSeriesRing_generic, LazyPowerSeriesRing)):
# It is often cheaper to compute discriminant of simple
# multivariate polynomial and substitute the real
# coefficients into that result (see #16014).
Expand Down
Loading

0 comments on commit 8bc2d84

Please sign in to comment.