Skip to content

Commit

Permalink
sage.rings: Modularization fixes for imports of power series
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Dec 20, 2023
1 parent b85f760 commit 1907696
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 20 deletions.
21 changes: 13 additions & 8 deletions src/sage/rings/multi_power_series_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,24 +204,29 @@
# http://www.gnu.org/licenses/
#*****************************************************************************

import sage.misc.latex as latex

from sage.rings.ring import CommutativeRing
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.infinity import infinity
from sage.rings.multi_power_series_ring_element import MPowerSeries
from sage.rings.polynomial.polynomial_ring import is_PolynomialRing
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.polynomial.multi_polynomial_ring import is_MPolynomialRing
from sage.rings.polynomial.term_order import TermOrder
from sage.rings.power_series_ring import PowerSeriesRing, PowerSeriesRing_generic, is_PowerSeriesRing

from sage.rings.infinity import infinity
import sage.misc.latex as latex
from sage.rings.ring import CommutativeRing
from sage.structure.nonexact import Nonexact

from sage.rings.multi_power_series_ring_element import MPowerSeries
from sage.categories.commutative_rings import CommutativeRings
_CommutativeRings = CommutativeRings()

from sage.categories.integral_domains import IntegralDomains
_IntegralDomains = IntegralDomains()

try:
from sage.rings.laurent_series_ring import LaurentSeriesRing
except ImportError:
LaurentSeriesRing = ()


def is_MPowerSeriesRing(x):
"""
Expand Down Expand Up @@ -731,8 +736,8 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None):
return False
if all(v == 0 for v in im_gens):
return True
from .laurent_series_ring import is_LaurentSeriesRing
if is_MPowerSeriesRing(codomain) or is_PowerSeriesRing(codomain) or is_LaurentSeriesRing(codomain):

if is_MPowerSeriesRing(codomain) or is_PowerSeriesRing(codomain) or isinstance(codomain, LaurentSeriesRing):
try:
B = all(v.valuation() > 0 or v.is_nilpotent() for v in im_gens)
except NotImplementedError:
Expand Down
2 changes: 2 additions & 0 deletions src/sage/rings/polynomial/polynomial_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5451,6 +5451,8 @@ cdef class Polynomial(CommutativePolynomial):
if self.degree() <= 1:
return R.fraction_field()

from sage.rings.number_field.number_field import is_NumberField, NumberField

if is_IntegerRing(R):
from sage.rings.number_field.number_field import NumberField
return NumberField(self, names)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/polynomial/polynomial_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ def _coerce_map_from_base_ring(self):
To: Univariate Polynomial Ring in x over Rational Field
sage: R.coerce_map_from(GF(7))
"""
from .polynomial_element import PolynomialBaseringInjection
from sage.rings.polynomial.polynomial_element import PolynomialBaseringInjection

return PolynomialBaseringInjection(self.base_ring(), self)

Expand Down
6 changes: 6 additions & 0 deletions src/sage/rings/power_series_mpoly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ from sage.rings.polynomial.multi_polynomial_ring_base import is_MPolynomialRing
from sage.rings import power_series_poly


try:
from sage.libs.pari.all import PariError
except ImportError:
PariError = ()


cdef class PowerSeries_mpoly(PowerSeries):

def __init__(self, parent, f=0, prec=infinity, int check=1, is_gen=0):
Expand Down
7 changes: 6 additions & 1 deletion src/sage/rings/power_series_poly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ The class ``PowerSeries_poly`` provides additional methods for univariate power
from sage.rings.power_series_ring_element cimport PowerSeries
from sage.structure.element cimport Element
from sage.rings.infinity import infinity
from sage.libs.pari.all import pari_gen, PariError

try:
from sage.libs.pari.all import pari_gen, PariError
except ImportError:
pari_gen = ()
PariError = ()


cdef class PowerSeries_poly(PowerSeries):
Expand Down
29 changes: 19 additions & 10 deletions src/sage/rings/power_series_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@

from sage.categories.complete_discrete_valuation import CompleteDiscreteValuationRings

try:
from .laurent_series_ring import LaurentSeriesRing
from .laurent_series_ring_element import LaurentSeries
except ImportError:
LaurentSeriesRing = ()
LaurentSeries = ()


def PowerSeriesRing(base_ring, name=None, arg2=None, names=None,
sparse=False, default_prec=None, order='negdeglex',
Expand Down Expand Up @@ -536,11 +543,11 @@ def __init__(self, base_ring, name=None, default_prec=None, sparse=False,
ValueError: default_prec (= -5) must be non-negative
"""
from sage.rings.finite_rings.finite_field_pari_ffelt import (
FiniteField_pari_ffelt,
)

if implementation is None:
try:
from sage.rings.finite_rings.finite_field_pari_ffelt import FiniteField_pari_ffelt
except ImportError:
FiniteField_pari_ffelt = ()
if isinstance(base_ring, FiniteField_pari_ffelt):
implementation = 'pari'
else:
Expand Down Expand Up @@ -570,6 +577,7 @@ def __init__(self, base_ring, name=None, default_prec=None, sparse=False,
assert is_MPolynomialRing(self.__mpoly_ring)
self.Element = power_series_mpoly.PowerSeries_mpoly
elif implementation == 'pari':
from .power_series_pari import PowerSeries_pari
self.Element = PowerSeries_pari
else:
raise ValueError('unknown power series implementation: %r' % implementation)
Expand All @@ -578,7 +586,7 @@ def __init__(self, base_ring, name=None, default_prec=None, sparse=False,
category=getattr(self, '_default_category',
_CommutativeRings))
Nonexact.__init__(self, default_prec)
if self.Element is PowerSeries_pari:
if implementation == 'pari':
self.__generator = self.element_class(self, R.gen().__pari__())
else:
self.__generator = self.element_class(self, R.gen(), is_gen=True)
Expand Down Expand Up @@ -804,7 +812,7 @@ def _element_constructor_(self, f, prec=infinity, check=True):
if prec >= f.prec():
return f
f = f.truncate(prec)
elif isinstance(f, laurent_series_ring_element.LaurentSeries) and f.parent().power_series_ring() is self:
elif isinstance(f, LaurentSeries) and f.parent().power_series_ring() is self:
return self(f.power_series(), prec, check=check)
elif isinstance(f, MagmaElement) and str(f.Type()) == 'RngSerPowElt':
v = sage_eval(f.Eltseq())
Expand Down Expand Up @@ -952,9 +960,8 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None):
return True # this is allowed.
if base_map is None and not codomain.has_coerce_map_from(self.base_ring()):
return False
from .laurent_series_ring import is_LaurentSeriesRing
v = im_gens[0]
if is_PowerSeriesRing(codomain) or is_LaurentSeriesRing(codomain):
if is_PowerSeriesRing(codomain) or isinstance(codomain, LaurentSeriesRing):
try:
return v.valuation() > 0 or v.is_nilpotent()
except NotImplementedError:
Expand Down Expand Up @@ -1269,8 +1276,10 @@ def laurent_series_ring(self):
try:
return self.__laurent_series_ring
except AttributeError:
self.__laurent_series_ring = laurent_series_ring.LaurentSeriesRing(
self.base_ring(), self.variable_name(), default_prec=self.default_prec(), sparse=self.is_sparse())
from .laurent_series_ring import LaurentSeriesRing

self.__laurent_series_ring = LaurentSeriesRing(
self.base_ring(), self.variable_name(), default_prec=self.default_prec(), sparse=self.is_sparse())
return self.__laurent_series_ring


Expand Down

0 comments on commit 1907696

Please sign in to comment.