Skip to content
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

deprecate is_generator for is_gen #38942

Merged
merged 2 commits into from
Nov 16, 2024
Merged
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
31 changes: 21 additions & 10 deletions src/sage/rings/polynomial/multi_polynomial.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ Base class for elements of multivariate polynomial rings
# (at your option) any later version.
# https://www.gnu.org/licenses/
# ********************************************************************
from itertools import chain

from sage.rings.integer cimport Integer
from sage.rings.integer_ring import ZZ
from sage.structure.coerce cimport coercion_model
from sage.misc.derivative import multi_derivative
from itertools import chain

from sage.misc.misc_c import prod
from sage.misc.superseded import deprecated_function_alias


def is_MPolynomial(x):
Expand Down Expand Up @@ -1284,28 +1284,39 @@ cdef class MPolynomial(CommutativePolynomial):
"""
return self.base_ring().ideal(self.coefficients())

def is_generator(self):
def is_gen(self):
r"""
Return ``True`` if this polynomial is a generator of its parent.

EXAMPLES::

sage: R.<x,y> = ZZ[]
sage: x.is_generator()
sage: x.is_gen()
True
sage: (x + y - y).is_generator()
sage: (x + y - y).is_gen()
True
sage: (x*y).is_generator()
sage: (x*y).is_gen()
False
sage: R.<x,y> = QQ[]
sage: x.is_generator()
sage: x.is_gen()
True
sage: (x + y - y).is_generator()
sage: (x + y - y).is_gen()
True
sage: (x*y).is_generator()
sage: (x*y).is_gen()
False

TESTS::

sage: R.<x,y> = ZZ[]
sage: x.is_generator()
doctest:warning...:
DeprecationWarning: is_generator is deprecated. Please use is_gen instead.
See https://github.com/sagemath/sage/issues/38942 for details.
True
"""
return (self in self.parent().gens())
return self in self.parent().gens()

is_generator = deprecated_function_alias(38942, is_gen)

def map_coefficients(self, f, new_base_ring=None):
r"""
Expand Down
24 changes: 18 additions & 6 deletions src/sage/rings/polynomial/multi_polynomial_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
from .multi_polynomial import MPolynomial, is_MPolynomial
from sage.categories.morphism import Morphism
from sage.misc.lazy_attribute import lazy_attribute

from sage.misc.superseded import deprecated_function_alias
from sage.rings.rational_field import QQ
from sage.rings.fraction_field import FractionField

Expand Down Expand Up @@ -693,7 +693,7 @@ def degree(self, x=None, std_grading=False):
x = self.parent().coerce(x)
except TypeError:
raise TypeError("x must canonically coerce to parent")
if not x.is_generator():
if not x.is_gen():
raise TypeError("x must be one of the generators of the parent")
else:
raise TypeError("x must be one of the generators of the parent")
Expand Down Expand Up @@ -1349,27 +1349,39 @@ def _homogenize(self, var):
R = self.parent()
return R(X)

def is_generator(self):
def is_gen(self) -> bool:
"""
Return ``True`` if ``self`` is a generator of its parent.

EXAMPLES::

sage: # needs sage.rings.number_field
sage: R.<x,y> = QQbar[]
sage: x.is_generator()
sage: x.is_gen()
True
sage: (x + y - y).is_generator()
sage: (x + y - y).is_gen()
True
sage: (x*y).is_generator()
sage: (x*y).is_gen()
False

TESTS::

sage: # needs sage.rings.number_field
sage: R.<x,y> = QQbar[]
sage: x.is_generator()
doctest:warning...:
DeprecationWarning: is_generator is deprecated. Please use is_gen instead.
See https://github.com/sagemath/sage/issues/38942 for details.
True
"""
elt = self.element()
if len(elt) == 1:
(e, c), = elt.dict().items()
return e.nonzero_values() == [1] and c.is_one()
return False

is_generator = deprecated_function_alias(38942, is_gen)

def is_monomial(self):
"""
Return ``True`` if ``self`` is a monomial, which we define to be a
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/polynomial/multi_polynomial_libsingular.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2700,7 +2700,7 @@ cdef class MPolynomial_libsingular(MPolynomial_libsingular_base):
x = self.parent().coerce(x)
except TypeError:
raise TypeError("argument is not coercible to the parent")
if not x.is_generator():
if not x.is_gen():
raise TypeError("argument is not a generator")

return Integer(singular_polynomial_deg(p, x._poly, r))
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/polynomial/polynomial_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -13078,7 +13078,7 @@ cpdef bint polynomial_is_variable(x) noexcept:
.. SEEALSO::

- :meth:`sage.rings.polynomial.polynomial_element.Polynomial.is_gen`
- :meth:`sage.rings.polynomial.multi_polynomial.MPolynomial.is_generator`
- :meth:`sage.rings.polynomial.multi_polynomial.MPolynomial.is_gen`

EXAMPLES::

Expand Down Expand Up @@ -13116,5 +13116,5 @@ cpdef bint polynomial_is_variable(x) noexcept:
return (x.is_gen()
or (x.degree() == 1 and x[0].is_zero() and x[1].is_one()))
if isinstance(x, MPolynomial):
return x.is_generator()
return x.is_gen()
return False
Loading