193193- Simon King (2012-08, 2013-02): Use category and coercion framework, :issue:`13412` and :issue:`14084`
194194"""
195195
196- #** ***************************************************************************
196+ # ***************************************************************************
197197# Copyright (C) 2010 Niles Johnson <[email protected] > 198198#
199199# This program is free software: you can redistribute it and/or modify
200200# it under the terms of the GNU General Public License as published by
201201# the Free Software Foundation, either version 2 of the License, or
202202# (at your option) any later version.
203- # http ://www.gnu.org/licenses/
204- #** ***************************************************************************
203+ # https ://www.gnu.org/licenses/
204+ # ***************************************************************************
205205
206206import sage .misc .latex as latex
207207
216216from sage .structure .nonexact import Nonexact
217217from sage .structure .parent import Parent
218218
219+ from sage .rings .laurent_series_ring import LaurentSeriesRing
219220from sage .categories .commutative_rings import CommutativeRings
220- _CommutativeRings = CommutativeRings ()
221-
222221from sage .categories .integral_domains import IntegralDomains
222+ _CommutativeRings = CommutativeRings ()
223223_IntegralDomains = IntegralDomains ()
224224
225- try :
226- from sage .rings .laurent_series_ring import LaurentSeriesRing
227- except ImportError :
228- LaurentSeriesRing = ()
229225
230- lazy_import ('sage.rings.lazy_series_ring' , ('LazyPowerSeriesRing' , 'LazyLaurentSeriesRing' ))
226+ lazy_import ('sage.rings.lazy_series_ring' , ('LazyPowerSeriesRing' ,
227+ 'LazyLaurentSeriesRing' ))
231228
232229
233230def is_MPowerSeriesRing (x ):
@@ -272,7 +269,9 @@ def is_MPowerSeriesRing(x):
272269
273270class MPowerSeriesRing_generic (PowerSeriesRing_generic , Nonexact ):
274271 r"""
275- A multivariate power series ring. This class is implemented as a
272+ A multivariate power series ring.
273+
274+ This class is implemented as a
276275 single variable power series ring in the variable ``T`` over a
277276 multivariable polynomial ring in the specified generators. Each
278277 generator ``g`` of the multivariable polynomial ring (called the
@@ -283,7 +282,7 @@ class MPowerSeriesRing_generic(PowerSeriesRing_generic, Nonexact):
283282
284283 For usage and examples, see above, and :meth:`PowerSeriesRing`.
285284 """
286- ### methods from PowerSeriesRing_generic that we *don't* override:
285+ # ## methods from PowerSeriesRing_generic that we *don't* override:
287286 #
288287 # variable_names_recursive : works just fine
289288 #
@@ -302,14 +301,14 @@ class MPowerSeriesRing_generic(PowerSeriesRing_generic, Nonexact):
302301 # __setitem__ : works just fine
303302 #
304303 #
305- #### notes
304+ # ### notes
306305 #
307306 # sparse setting may not be implemented completely
308307 Element = MPowerSeries
309308
310309 @staticmethod
311310 def __classcall__ (cls , base_ring , num_gens , name_list ,
312- order = 'negdeglex' , default_prec = 10 , sparse = False ):
311+ order = 'negdeglex' , default_prec = 10 , sparse = False ):
313312 """
314313 Preprocessing of arguments: The term order can be given as string
315314 or as a :class:`~sage.rings.polynomial.term_order.TermOrder` instance.
@@ -326,7 +325,7 @@ def __classcall__(cls, base_ring, num_gens, name_list,
326325 order , default_prec , sparse )
327326
328327 def __init__ (self , base_ring , num_gens , name_list ,
329- order = 'negdeglex' , default_prec = 10 , sparse = False ):
328+ order = 'negdeglex' , default_prec = 10 , sparse = False ) -> None :
330329 """
331330 Initialize a multivariate power series ring. See PowerSeriesRing
332331 for complete documentation.
@@ -371,6 +370,11 @@ def __init__(self, base_ring, num_gens, name_list,
371370 Category of integral domains
372371 sage: TestSuite(P).run()
373372
373+ sage: M = PowerSeriesRing(QQ,4,'v'); M
374+ Multivariate Power Series Ring in v0, v1, v2, v3 over Rational Field
375+ sage: M.is_integral_domain()
376+ True
377+
374378 Otherwise, it belongs to the category of commutative rings::
375379
376380 sage: P = Integers(15)[['x','y']]
@@ -385,10 +389,10 @@ def __init__(self, base_ring, num_gens, name_list,
385389 if n < 0 :
386390 raise ValueError ("Multivariate Polynomial Rings must have more than 0 variables." )
387391 self ._ngens = n
388- self ._has_singular = False # cannot convert to Singular by default
392+ self ._has_singular = False # cannot convert to Singular by default
389393 # Multivariate power series rings inherit from power series rings. But
390394 # apparently we can not call their initialisation. Instead, initialise
391- # CommutativeRing and Nonexact:
395+ # Parent and Nonexact:
392396 Parent .__init__ (self , base = base_ring , names = name_list ,
393397 category = _IntegralDomains if base_ring in
394398 _IntegralDomains else _CommutativeRings )
@@ -405,10 +409,10 @@ def __init__(self, base_ring, num_gens, name_list,
405409
406410 self ._is_sparse = sparse
407411 self ._params = (base_ring , num_gens , name_list ,
408- order , default_prec , sparse )
412+ order , default_prec , sparse )
409413 self ._populate_coercion_lists_ ()
410414
411- def _repr_ (self ):
415+ def _repr_ (self ) -> str :
412416 """
413417 Print out a multivariate power series ring.
414418
@@ -431,7 +435,7 @@ def _repr_(self):
431435 s = 'Sparse ' + s
432436 return s
433437
434- def _latex_ (self ):
438+ def _latex_ (self ) -> str :
435439 """
436440 Return latex representation of power series ring.
437441
@@ -445,21 +449,7 @@ def _latex_(self):
445449 generators_latex = ", " .join (self .latex_variable_names ())
446450 return "%s[[%s]]" % (latex .latex (self .base_ring ()), generators_latex )
447451
448- def is_integral_domain (self , proof = False ):
449- """
450- Return ``True`` if the base ring is an integral domain; otherwise
451- return False.
452-
453- EXAMPLES::
454-
455- sage: M = PowerSeriesRing(QQ,4,'v'); M
456- Multivariate Power Series Ring in v0, v1, v2, v3 over Rational Field
457- sage: M.is_integral_domain()
458- True
459- """
460- return self .base_ring ().is_integral_domain ()
461-
462- def is_noetherian (self , proof = False ):
452+ def is_noetherian (self , proof = False ) -> bool :
463453 """
464454 Power series over a Noetherian ring are Noetherian.
465455
@@ -478,8 +468,9 @@ def is_noetherian(self, proof=False):
478468
479469 def term_order (self ):
480470 """
481- Print term ordering of ``self``. Term orderings are implemented by the
482- TermOrder class.
471+ Return the term ordering of ``self``.
472+
473+ Term orderings are implemented by the ``TermOrder`` class.
483474
484475 EXAMPLES::
485476
@@ -548,7 +539,7 @@ def construction(self):
548539 True
549540 """
550541 from sage .categories .pushout import CompletionFunctor
551- extras = {'order' :self .term_order (), 'num_gens' :self .ngens ()}
542+ extras = {'order' : self .term_order (), 'num_gens' : self .ngens ()}
552543 if self .is_sparse ():
553544 extras ['sparse' ] = True
554545 return (CompletionFunctor (self ._names , self .default_prec (),
@@ -558,6 +549,7 @@ def construction(self):
558549 def change_ring (self , R ):
559550 """
560551 Return the power series ring over `R` in the same variable as ``self``.
552+
561553 This function ignores the question of whether the base ring of self
562554 is or can extend to the base ring of `R`; for the latter, use
563555 ``base_extend``.
@@ -614,11 +606,11 @@ def remove_var(self, *var):
614606 vars = list (self .variable_names ())
615607 for v in var :
616608 vars .remove (str (v ))
617- if len ( vars ) == 0 :
609+ if not vars :
618610 return self .base_ring ()
619611 return PowerSeriesRing (self .base_ring (), names = vars )
620612
621- ## this is defined in PowerSeriesRing_generic
613+ # this is defined in PowerSeriesRing_generic
622614 # def __call__(self, f, prec=infinity):
623615 # """
624616 # Coerce object to this multivariate power series ring.
@@ -680,10 +672,10 @@ def _coerce_impl(self, f):
680672 if set (P .variable_names ()).issubset (set (self .variable_names ())):
681673 if self .has_coerce_map_from (P .base_ring ()):
682674 return self (f )
683- else :
684- return self (self .base_ring ().coerce (f ))
685675
686- def _is_valid_homomorphism_ (self , codomain , im_gens , base_map = None ):
676+ return self (self .base_ring ().coerce (f ))
677+
678+ def _is_valid_homomorphism_ (self , codomain , im_gens , base_map = None ) -> bool :
687679 """
688680 Replacement for method of PowerSeriesRing_generic.
689681
@@ -903,14 +895,14 @@ def laurent_series_ring(self):
903895 Traceback (most recent call last):
904896 ...
905897 NotImplementedError: Laurent series not implemented for
906- multivariate power series.
898+ multivariate power series
907899 """
908- raise NotImplementedError ("Laurent series not implemented for multivariate power series. " )
900+ raise NotImplementedError ("Laurent series not implemented for multivariate power series" )
909901
910902 def _poly_ring (self , x = None ):
911903 """
912904 Return the underlying polynomial ring used to represent elements of
913- this power series ring. If given an input x , returns x coerced
905+ this power series ring. If given an input ``x`` , returns ``x`` coerced
914906 into this polynomial ring.
915907
916908 EXAMPLES::
@@ -923,8 +915,7 @@ def _poly_ring(self, x=None):
923915 """
924916 if x is None :
925917 return self ._poly_ring_
926- else :
927- return self ._poly_ring_ (x )
918+ return self ._poly_ring_ (x )
928919
929920 def _mpoly_ring (self , x = None ):
930921 """
@@ -956,10 +947,9 @@ def _bg_ps_ring(self, x=None):
956947 """
957948 if x is None :
958949 return self ._bg_power_series_ring
959- else :
960- return self ._bg_power_series_ring (x )
950+ return self ._bg_power_series_ring (x )
961951
962- def is_sparse (self ):
952+ def is_sparse (self ) -> bool :
963953 """
964954 Check whether ``self`` is sparse.
965955
@@ -976,7 +966,7 @@ def is_sparse(self):
976966 """
977967 return self ._is_sparse
978968
979- def is_dense (self ):
969+ def is_dense (self ) -> bool :
980970 """
981971 Is ``self`` dense? (opposite of sparse)
982972
@@ -1004,8 +994,8 @@ def gen(self, n=0):
1004994 v6
1005995 """
1006996 if n < 0 or n >= self ._ngens :
1007- raise ValueError ( "Generator not defined. " )
1008- #return self(self._poly_ring().gens()[int(n)])
997+ raise IndexError ( "generator not defined" )
998+ # return self(self._poly_ring().gens()[int(n)])
1009999 return self .element_class (parent = self , x = self ._poly_ring ().gens ()[int (n )], is_gen = True )
10101000
10111001 def ngens (self ):
@@ -1034,9 +1024,10 @@ def gens(self) -> tuple:
10341024
10351025 def prec_ideal (self ):
10361026 """
1037- Return the ideal which determines precision; this is the ideal
1038- generated by all of the generators of our background polynomial
1039- ring.
1027+ Return the ideal which determines precision.
1028+
1029+ This is the ideal generated by all of the generators of our
1030+ background polynomial ring.
10401031
10411032 EXAMPLES::
10421033
@@ -1049,7 +1040,9 @@ def prec_ideal(self):
10491040
10501041 def bigoh (self , prec ):
10511042 """
1052- Return big oh with precision ``prec``. The function ``O`` does the same thing.
1043+ Return big oh with precision ``prec``.
1044+
1045+ The function ``O`` does the same thing.
10531046
10541047 EXAMPLES::
10551048
@@ -1064,7 +1057,9 @@ def bigoh(self, prec):
10641057
10651058 def O (self , prec ):
10661059 """
1067- Return big oh with precision ``prec``. This function is an alias for ``bigoh``.
1060+ Return big oh with precision ``prec``.
1061+
1062+ This function is an alias for ``bigoh``.
10681063
10691064 EXAMPLES::
10701065
@@ -1092,12 +1087,12 @@ def _send_to_bg(self, f):
10921087 sage: M._send_to_bg(bg)
10931088 Traceback (most recent call last):
10941089 ...
1095- TypeError: Cannot coerce input to polynomial ring.
1090+ TypeError: cannot coerce input to polynomial ring
10961091 """
10971092 try :
10981093 f = self ._poly_ring (f )
10991094 except TypeError :
1100- raise TypeError ("Cannot coerce input to polynomial ring. " )
1095+ raise TypeError ("cannot coerce input to polynomial ring" )
11011096 return self ._bg_ps_ring (f .homogeneous_components ())
11021097
11031098 def _send_to_fg (self , f ):
@@ -1137,4 +1132,5 @@ def unpickle_multi_power_series_ring_v0(base_ring, num_gens, names, order, defau
11371132 sage: loads(dumps(P)) == P # indirect doctest
11381133 True
11391134 """
1140- return PowerSeriesRing (base_ring , num_gens = num_gens , names = names , order = order , default_prec = default_prec , sparse = sparse )
1135+ return PowerSeriesRing (base_ring , num_gens = num_gens , names = names ,
1136+ order = order , default_prec = default_prec , sparse = sparse )
0 commit comments