Skip to content

trying to move Laurent rings to use Parent only #40257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 39 additions & 29 deletions src/sage/rings/polynomial/laurent_polynomial_ring_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,20 @@
# https://www.gnu.org/licenses/
# ****************************************************************************


from sage.combinat.integer_vector import IntegerVectors
from sage.misc.cachefunc import cached_method
from sage.rings.infinity import infinity
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.ring import CommutativeRing
from sage.structure.parent import Parent
from sage.combinat.integer_vector import IntegerVectors


class LaurentPolynomialRing_generic(CommutativeRing, Parent):
class LaurentPolynomialRing_generic(Parent):
"""
Laurent polynomial ring (base class).

EXAMPLES:

This base class inherits from :class:`~sage.rings.ring.CommutativeRing`.
Since :issue:`11900`, it is also initialised as such::
Since :issue:`11900`, it is in the category of commutative rings::

sage: R.<x1,x2> = LaurentPolynomialRing(QQ)
sage: R.category()
Expand All @@ -50,7 +48,7 @@ class LaurentPolynomialRing_generic(CommutativeRing, Parent):
and Category of infinite sets
sage: TestSuite(R).run()
"""
def __init__(self, R):
def __init__(self, R) -> None:
"""
EXAMPLES::

Expand All @@ -62,15 +60,16 @@ def __init__(self, R):
self._R = R
names = R.variable_names()
self._one_element = self.element_class(self, R.one())
CommutativeRing.__init__(self, R.base_ring(), names=names,
category=R.category())
Parent.__init__(self, base=R.base_ring(), names=names,
category=R.category())
ernames = []
for n in names:
ernames.append(n)
ernames.append(n + "inv")
ER = PolynomialRing(R.base_ring(), ernames)
self._extended_ring = ER
self._extended_ring_ideal = ER.ideal([ER.gen(2*i)*ER.gen(2*i+1)-1 for i in range(self._n)])
self._extended_ring_ideal = ER.ideal([ER.gen(2*i) * ER.gen(2*i+1) - 1
for i in range(self._n)])

def ngens(self):
"""
Expand All @@ -85,10 +84,25 @@ def ngens(self):
"""
return self._n

@cached_method
def gens(self) -> tuple:
"""
Return the tuple of generators of ``self``.

EXAMPLES::

sage: LaurentPolynomialRing(ZZ, 2, 'x').gens()
(x0, x1)
sage: LaurentPolynomialRing(QQ, 1, 'x').gens()
(x,)
"""
return tuple(self(x) for x in self._R.gens())

def gen(self, i=0):
r"""
Return the `i`-th generator of ``self``. If `i` is not specified, then
the first generator will be returned.
Return the `i`-th generator of ``self``.

If `i` is not specified, then the first generator will be returned.

EXAMPLES::

Expand All @@ -108,13 +122,9 @@ def gen(self, i=0):
"""
if i < 0 or i >= self._n:
raise ValueError("generator not defined")
try:
return self.__generators[i]
except AttributeError:
self.__generators = tuple(self(x) for x in self._R.gens())
return self.__generators[i]
return self.gens()[i]

def variable_names_recursive(self, depth=infinity):
def variable_names_recursive(self, depth=infinity) -> tuple[str]:
r"""
Return the list of variable names of this ring and its base rings,
as if it were a single multi-variate Laurent polynomial.
Expand Down Expand Up @@ -145,7 +155,7 @@ def variable_names_recursive(self, depth=infinity):
except AttributeError:
return my_vars

def is_integral_domain(self, proof=True):
def is_integral_domain(self, proof=True) -> bool:
"""
Return ``True`` if ``self`` is an integral domain.

Expand All @@ -163,7 +173,7 @@ def is_integral_domain(self, proof=True):
"""
return self.base_ring().is_integral_domain(proof)

def is_noetherian(self):
def is_noetherian(self) -> bool:
"""
Return ``True`` if ``self`` is Noetherian.

Expand Down Expand Up @@ -286,10 +296,10 @@ def _coerce_map_from_(self, R):
if f is not None:
return f
if (isinstance(R, LaurentPolynomialRing_generic)
and self._R.has_coerce_map_from(R._R)):
and self._R.has_coerce_map_from(R._R)):
return self._generic_coerce_map(R)

def __eq__(self, right):
def __eq__(self, right) -> bool:
"""
Check whether ``self`` is equal to ``right``.

Expand All @@ -312,7 +322,7 @@ def __eq__(self, right):
return False
return self._R == right._R

def __ne__(self, other):
def __ne__(self, other) -> bool:
"""
Check whether ``self`` is not equal to ``other``.

Expand All @@ -333,7 +343,7 @@ def __ne__(self, other):
"""
return not (self == other)

def __hash__(self):
def __hash__(self) -> int:
"""
Return the hash of ``self``.

Expand All @@ -348,7 +358,7 @@ def __hash__(self):
"""
return hash(self._R) ^ 12059065606945654693

def _latex_(self):
def _latex_(self) -> str:
r"""
EXAMPLES::

Expand Down Expand Up @@ -392,7 +402,7 @@ def ideal(self, *args, **kwds):
from sage.rings.polynomial.laurent_polynomial_ideal import LaurentPolynomialIdeal
return LaurentPolynomialIdeal(self, *args, **kwds)

def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None):
def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None) -> bool:
"""
EXAMPLES::

Expand Down Expand Up @@ -429,7 +439,7 @@ def term_order(self):
"""
return self._R.term_order()

def is_finite(self):
def is_finite(self) -> bool:
"""
EXAMPLES::

Expand All @@ -438,7 +448,7 @@ def is_finite(self):
"""
return False

def is_field(self, proof=True):
def is_field(self, proof=True) -> bool:
"""
EXAMPLES::

Expand Down Expand Up @@ -643,7 +653,7 @@ def random_element(self, min_valuation=-2, max_degree=2, *args, **kwds):
s = ~s
return f * s

def is_exact(self):
def is_exact(self) -> bool:
"""
Return ``True`` if the base ring is exact.

Expand Down
9 changes: 4 additions & 5 deletions src/sage/rings/power_series_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,18 +518,17 @@ def __init__(self, base_ring, name=None, default_prec=None, sparse=False,
If the base ring is a polynomial ring, then the option
``implementation='mpoly'`` causes computations to be done with
multivariate polynomials instead of a univariate polynomial
ring over the base ring. Only use this for dense power series
where you won't do too much arithmetic, but the arithmetic you
ring over the base ring. Only use this for dense power series
where you will not do too much arithmetic, but the arithmetic you
do must be fast. You must explicitly call
``f.do_truncation()`` on an element for it to truncate away
higher order terms (this is called automatically before
printing).

EXAMPLES:

This base class inherits from :class:`~sage.rings.ring.CommutativeRing`.
Since :issue:`11900`, it is also initialised as such, and since :issue:`14084`
it is actually initialised as an integral domain::
Since :issue:`11900`, it is in the category of commutative rings,
and since :issue:`14084` it is actually an integral domain::

sage: R.<x> = ZZ[[]]
sage: R.category()
Expand Down
Loading