Skip to content

Commit c7e2e48

Browse files
author
Release Manager
committed
gh-38942: deprecate is_generator for is_gen as part of #35523 ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. URL: #38942 Reported by: Frédéric Chapoton Reviewer(s): Kwankyu Lee
2 parents 78e68ab + a8cbe30 commit c7e2e48

File tree

4 files changed

+42
-19
lines changed

4 files changed

+42
-19
lines changed

src/sage/rings/polynomial/multi_polynomial.pyx

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ Base class for elements of multivariate polynomial rings
1111
# (at your option) any later version.
1212
# https://www.gnu.org/licenses/
1313
# ********************************************************************
14+
from itertools import chain
1415

1516
from sage.rings.integer cimport Integer
1617
from sage.rings.integer_ring import ZZ
1718
from sage.structure.coerce cimport coercion_model
1819
from sage.misc.derivative import multi_derivative
19-
from itertools import chain
20-
2120
from sage.misc.misc_c import prod
21+
from sage.misc.superseded import deprecated_function_alias
2222

2323

2424
def is_MPolynomial(x):
@@ -1284,28 +1284,39 @@ cdef class MPolynomial(CommutativePolynomial):
12841284
"""
12851285
return self.base_ring().ideal(self.coefficients())
12861286

1287-
def is_generator(self):
1287+
def is_gen(self):
12881288
r"""
12891289
Return ``True`` if this polynomial is a generator of its parent.
12901290
12911291
EXAMPLES::
12921292
12931293
sage: R.<x,y> = ZZ[]
1294-
sage: x.is_generator()
1294+
sage: x.is_gen()
12951295
True
1296-
sage: (x + y - y).is_generator()
1296+
sage: (x + y - y).is_gen()
12971297
True
1298-
sage: (x*y).is_generator()
1298+
sage: (x*y).is_gen()
12991299
False
13001300
sage: R.<x,y> = QQ[]
1301-
sage: x.is_generator()
1301+
sage: x.is_gen()
13021302
True
1303-
sage: (x + y - y).is_generator()
1303+
sage: (x + y - y).is_gen()
13041304
True
1305-
sage: (x*y).is_generator()
1305+
sage: (x*y).is_gen()
13061306
False
1307+
1308+
TESTS::
1309+
1310+
sage: R.<x,y> = ZZ[]
1311+
sage: x.is_generator()
1312+
doctest:warning...:
1313+
DeprecationWarning: is_generator is deprecated. Please use is_gen instead.
1314+
See https://github.com/sagemath/sage/issues/38942 for details.
1315+
True
13071316
"""
1308-
return (self in self.parent().gens())
1317+
return self in self.parent().gens()
1318+
1319+
is_generator = deprecated_function_alias(38942, is_gen)
13091320

13101321
def map_coefficients(self, f, new_base_ring=None):
13111322
r"""

src/sage/rings/polynomial/multi_polynomial_element.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
from .multi_polynomial import MPolynomial, is_MPolynomial
7171
from sage.categories.morphism import Morphism
7272
from sage.misc.lazy_attribute import lazy_attribute
73-
73+
from sage.misc.superseded import deprecated_function_alias
7474
from sage.rings.rational_field import QQ
7575
from sage.rings.fraction_field import FractionField
7676

@@ -693,7 +693,7 @@ def degree(self, x=None, std_grading=False):
693693
x = self.parent().coerce(x)
694694
except TypeError:
695695
raise TypeError("x must canonically coerce to parent")
696-
if not x.is_generator():
696+
if not x.is_gen():
697697
raise TypeError("x must be one of the generators of the parent")
698698
else:
699699
raise TypeError("x must be one of the generators of the parent")
@@ -1349,27 +1349,39 @@ def _homogenize(self, var):
13491349
R = self.parent()
13501350
return R(X)
13511351

1352-
def is_generator(self):
1352+
def is_gen(self) -> bool:
13531353
"""
13541354
Return ``True`` if ``self`` is a generator of its parent.
13551355
13561356
EXAMPLES::
13571357
13581358
sage: # needs sage.rings.number_field
13591359
sage: R.<x,y> = QQbar[]
1360-
sage: x.is_generator()
1360+
sage: x.is_gen()
13611361
True
1362-
sage: (x + y - y).is_generator()
1362+
sage: (x + y - y).is_gen()
13631363
True
1364-
sage: (x*y).is_generator()
1364+
sage: (x*y).is_gen()
13651365
False
1366+
1367+
TESTS::
1368+
1369+
sage: # needs sage.rings.number_field
1370+
sage: R.<x,y> = QQbar[]
1371+
sage: x.is_generator()
1372+
doctest:warning...:
1373+
DeprecationWarning: is_generator is deprecated. Please use is_gen instead.
1374+
See https://github.com/sagemath/sage/issues/38942 for details.
1375+
True
13661376
"""
13671377
elt = self.element()
13681378
if len(elt) == 1:
13691379
(e, c), = elt.dict().items()
13701380
return e.nonzero_values() == [1] and c.is_one()
13711381
return False
13721382

1383+
is_generator = deprecated_function_alias(38942, is_gen)
1384+
13731385
def is_monomial(self):
13741386
"""
13751387
Return ``True`` if ``self`` is a monomial, which we define to be a

src/sage/rings/polynomial/multi_polynomial_libsingular.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2700,7 +2700,7 @@ cdef class MPolynomial_libsingular(MPolynomial_libsingular_base):
27002700
x = self.parent().coerce(x)
27012701
except TypeError:
27022702
raise TypeError("argument is not coercible to the parent")
2703-
if not x.is_generator():
2703+
if not x.is_gen():
27042704
raise TypeError("argument is not a generator")
27052705

27062706
return Integer(singular_polynomial_deg(p, x._poly, r))

src/sage/rings/polynomial/polynomial_element.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13078,7 +13078,7 @@ cpdef bint polynomial_is_variable(x) noexcept:
1307813078
.. SEEALSO::
1307913079
1308013080
- :meth:`sage.rings.polynomial.polynomial_element.Polynomial.is_gen`
13081-
- :meth:`sage.rings.polynomial.multi_polynomial.MPolynomial.is_generator`
13081+
- :meth:`sage.rings.polynomial.multi_polynomial.MPolynomial.is_gen`
1308213082
1308313083
EXAMPLES::
1308413084
@@ -13116,5 +13116,5 @@ cpdef bint polynomial_is_variable(x) noexcept:
1311613116
return (x.is_gen()
1311713117
or (x.degree() == 1 and x[0].is_zero() and x[1].is_one()))
1311813118
if isinstance(x, MPolynomial):
13119-
return x.is_generator()
13119+
return x.is_gen()
1312013120
return False

0 commit comments

Comments
 (0)