Skip to content

Commit d59117f

Browse files
author
Release Manager
committed
gh-41031: some details in multi_power_series_rings small details, including the removal of one method now provided by the category ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #41031 Reported by: Frédéric Chapoton Reviewer(s): Frédéric Chapoton, Martin Rubey, user202729
2 parents 1167270 + bd552c7 commit d59117f

File tree

2 files changed

+62
-64
lines changed

2 files changed

+62
-64
lines changed

src/sage/rings/multi_power_series_ring.py

Lines changed: 56 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,15 @@
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

206206
import sage.misc.latex as latex
207207

@@ -216,18 +216,15 @@
216216
from sage.structure.nonexact import Nonexact
217217
from sage.structure.parent import Parent
218218

219+
from sage.rings.laurent_series_ring import LaurentSeriesRing
219220
from sage.categories.commutative_rings import CommutativeRings
220-
_CommutativeRings = CommutativeRings()
221-
222221
from 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

233230
def is_MPowerSeriesRing(x):
@@ -272,7 +269,9 @@ def is_MPowerSeriesRing(x):
272269

273270
class 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
@@ -547,7 +538,7 @@ def construction(self):
547538
True
548539
"""
549540
from sage.categories.pushout import CompletionFunctor
550-
extras = {'order':self.term_order(), 'num_gens':self.ngens()}
541+
extras = {'order': self.term_order(), 'num_gens': self.ngens()}
551542
if self.is_sparse():
552543
extras['sparse'] = True
553544
return (CompletionFunctor(self._names, self.default_prec(),
@@ -557,6 +548,7 @@ def construction(self):
557548
def change_ring(self, R):
558549
"""
559550
Return the power series ring over `R` in the same variable as ``self``.
551+
560552
This function ignores the question of whether the base ring of self
561553
is or can extend to the base ring of `R`; for the latter, use
562554
``base_extend``.
@@ -613,11 +605,11 @@ def remove_var(self, *var):
613605
vars = list(self.variable_names())
614606
for v in var:
615607
vars.remove(str(v))
616-
if len(vars) == 0:
608+
if not vars:
617609
return self.base_ring()
618610
return PowerSeriesRing(self.base_ring(), names=vars)
619611

620-
## this is defined in PowerSeriesRing_generic
612+
# this is defined in PowerSeriesRing_generic
621613
# def __call__(self, f, prec=infinity):
622614
# """
623615
# Coerce object to this multivariate power series ring.
@@ -682,7 +674,7 @@ def _coerce_impl(self, f):
682674
else:
683675
return self(self.base_ring().coerce(f))
684676

685-
def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None):
677+
def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None) -> bool:
686678
"""
687679
Replacement for method of PowerSeriesRing_generic.
688680
@@ -902,14 +894,14 @@ def laurent_series_ring(self):
902894
Traceback (most recent call last):
903895
...
904896
NotImplementedError: Laurent series not implemented for
905-
multivariate power series.
897+
multivariate power series
906898
"""
907-
raise NotImplementedError("Laurent series not implemented for multivariate power series.")
899+
raise NotImplementedError("Laurent series not implemented for multivariate power series")
908900

909901
def _poly_ring(self, x=None):
910902
"""
911903
Return the underlying polynomial ring used to represent elements of
912-
this power series ring. If given an input x, returns x coerced
904+
this power series ring. If given an input ``x``, returns ``x`` coerced
913905
into this polynomial ring.
914906
915907
EXAMPLES::
@@ -922,8 +914,7 @@ def _poly_ring(self, x=None):
922914
"""
923915
if x is None:
924916
return self._poly_ring_
925-
else:
926-
return self._poly_ring_(x)
917+
return self._poly_ring_(x)
927918

928919
def _mpoly_ring(self, x=None):
929920
"""
@@ -955,10 +946,9 @@ def _bg_ps_ring(self, x=None):
955946
"""
956947
if x is None:
957948
return self._bg_power_series_ring
958-
else:
959-
return self._bg_power_series_ring(x)
949+
return self._bg_power_series_ring(x)
960950

961-
def is_sparse(self):
951+
def is_sparse(self) -> bool:
962952
"""
963953
Check whether ``self`` is sparse.
964954
@@ -975,7 +965,7 @@ def is_sparse(self):
975965
"""
976966
return self._is_sparse
977967

978-
def is_dense(self):
968+
def is_dense(self) -> bool:
979969
"""
980970
Is ``self`` dense? (opposite of sparse)
981971
@@ -1003,8 +993,8 @@ def gen(self, n=0):
1003993
v6
1004994
"""
1005995
if n < 0 or n >= self._ngens:
1006-
raise ValueError("Generator not defined.")
1007-
#return self(self._poly_ring().gens()[int(n)])
996+
raise IndexError("generator not defined")
997+
# return self(self._poly_ring().gens()[int(n)])
1008998
return self.element_class(parent=self, x=self._poly_ring().gens()[int(n)], is_gen=True)
1009999

10101000
def ngens(self):
@@ -1033,9 +1023,10 @@ def gens(self) -> tuple:
10331023

10341024
def prec_ideal(self):
10351025
"""
1036-
Return the ideal which determines precision; this is the ideal
1037-
generated by all of the generators of our background polynomial
1038-
ring.
1026+
Return the ideal which determines precision.
1027+
1028+
This is the ideal generated by all of the generators of our
1029+
background polynomial ring.
10391030
10401031
EXAMPLES::
10411032
@@ -1048,7 +1039,9 @@ def prec_ideal(self):
10481039

10491040
def bigoh(self, prec):
10501041
"""
1051-
Return big oh with precision ``prec``. The function ``O`` does the same thing.
1042+
Return big oh with precision ``prec``.
1043+
1044+
The function ``O`` does the same thing.
10521045
10531046
EXAMPLES::
10541047
@@ -1063,7 +1056,9 @@ def bigoh(self, prec):
10631056

10641057
def O(self, prec):
10651058
"""
1066-
Return big oh with precision ``prec``. This function is an alias for ``bigoh``.
1059+
Return big oh with precision ``prec``.
1060+
1061+
This function is an alias for ``bigoh``.
10671062
10681063
EXAMPLES::
10691064
@@ -1091,12 +1086,12 @@ def _send_to_bg(self, f):
10911086
sage: M._send_to_bg(bg)
10921087
Traceback (most recent call last):
10931088
...
1094-
TypeError: Cannot coerce input to polynomial ring.
1089+
TypeError: cannot coerce input to polynomial ring
10951090
"""
10961091
try:
10971092
f = self._poly_ring(f)
10981093
except TypeError:
1099-
raise TypeError("Cannot coerce input to polynomial ring.")
1094+
raise TypeError("cannot coerce input to polynomial ring")
11001095
return self._bg_ps_ring(f.homogeneous_components())
11011096

11021097
def _send_to_fg(self, f):
@@ -1136,4 +1131,5 @@ def unpickle_multi_power_series_ring_v0(base_ring, num_gens, names, order, defau
11361131
sage: loads(dumps(P)) == P # indirect doctest
11371132
True
11381133
"""
1139-
return PowerSeriesRing(base_ring, num_gens=num_gens, names=names, order=order, default_prec=default_prec, sparse=sparse)
1134+
return PowerSeriesRing(base_ring, num_gens=num_gens, names=names,
1135+
order=order, default_prec=default_prec, sparse=sparse)

src/sage/rings/multi_power_series_ring_element.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def __init__(self, parent, x=0, prec=infinity, is_gen=False, check=False):
350350
sage: B(z)
351351
Traceback (most recent call last):
352352
...
353-
TypeError: Cannot coerce input to polynomial ring.
353+
TypeError: cannot coerce input to polynomial ring
354354
355355
sage: D.<s> = PowerSeriesRing(QQ)
356356
sage: s.parent() is D
@@ -366,19 +366,21 @@ def __init__(self, parent, x=0, prec=infinity, is_gen=False, check=False):
366366
self._PowerSeries__is_gen = is_gen
367367

368368
try:
369-
prec = min(prec, x.prec()) # use precision of input, if defined
369+
prec = min(prec, x.prec()) # use precision of input, if defined
370370
except AttributeError:
371371
pass
372372

373373
# set the correct background value, depending on what type of input x is
374374
try:
375-
xparent = x.parent() # 'int' types have no parent
375+
xparent = x.parent() # 'int' types have no parent
376376
except AttributeError:
377377
xparent = None
378378

379379
# test whether x coerces to background univariate
380380
# power series ring of parent
381-
if isinstance(xparent, (PowerSeriesRing_generic, MPowerSeriesRing_generic, LazyPowerSeriesRing)):
381+
if isinstance(xparent, (PowerSeriesRing_generic,
382+
MPowerSeriesRing_generic,
383+
LazyPowerSeriesRing)):
382384
# x is either a multivariate or univariate power series
383385
#
384386
# test whether x coerces directly to designated parent

0 commit comments

Comments
 (0)