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_Algebra, is_CommutativeAlgebra #35253

Merged
merged 7 commits into from
Apr 1, 2023
5 changes: 5 additions & 0 deletions src/sage/algebras/algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ def is_Algebra(x):
sage: from sage.algebras.algebra import is_Algebra
sage: R.<x,y> = FreeAlgebra(QQ,2)
sage: is_Algebra(R)
doctest:warning...
DeprecationWarning: the function is_Algebra is deprecated; use '... in Algebras(base_ring)' instead
See https://github.com/sagemath/sage/issues/35253 for details.
True
"""
from sage.misc.superseded import deprecation
deprecation(35253, "the function is_Algebra is deprecated; use '... in Algebras(base_ring)' instead")
try:
return isinstance(x, Algebra) or x in Algebras(x.base_ring())
except Exception:
Expand Down
17 changes: 12 additions & 5 deletions src/sage/categories/algebra_ideals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
# https://www.gnu.org/licenses/
# *****************************************************************************

from .category_types import Category_ideal
from .algebra_modules import AlgebraModules
from .algebras import Algebras
from .rings import Rings
from .category_types import Category_ideal


class AlgebraIdeals(Category_ideal):
Expand Down Expand Up @@ -48,9 +50,14 @@ def __init__(self, A):

sage: TestSuite(AlgebraIdeals(QQ['a'])).run()
"""
from sage.algebras.algebra import is_Algebra
if not is_Algebra(A): # A not in Algebras() ?
raise TypeError("A (=%s) must be an algebra"%A)
try:
base_ring = A.base_ring()
except AttributeError:
raise TypeError(f"A (={A}) must be an algebra")
else:
if base_ring not in Rings() or A not in Algebras(base_ring.category()):
raise TypeError(f"A (={A}) must be an algebra")

Category_ideal.__init__(self, A)

def algebra(self):
Expand Down Expand Up @@ -82,6 +89,6 @@ def super_categories(self):
try:
if R.is_commutative():
return [AlgebraModules(R)]
except (AttributeError,NotImplementedError):
except (AttributeError, NotImplementedError):
pass
return []
13 changes: 10 additions & 3 deletions src/sage/categories/algebra_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#******************************************************************************

from .category_types import Category_module
from .commutative_algebras import CommutativeAlgebras
from .commutative_rings import CommutativeRings
from .modules import Modules

class AlgebraModules(Category_module):
Expand Down Expand Up @@ -50,9 +52,14 @@ def __init__(self, A):

sage: TestSuite(AlgebraModules(QQ['a'])).run()
"""
from sage.categories.commutative_algebras import CommutativeAlgebras
if not hasattr(A, "base_ring") or A not in CommutativeAlgebras(A.base_ring()):
raise TypeError("A (=%s) must be a commutative algebra" % A)
try:
base_ring = A.base_ring()
except AttributeError:
raise TypeError(f"A (={A}) must be a commutative algebra")
else:
if base_ring not in CommutativeRings() or A not in CommutativeAlgebras(base_ring.category()):
raise TypeError(f"A (={A}) must be a commutative algebra")

Category_module.__init__(self, A)

@classmethod
Expand Down
17 changes: 12 additions & 5 deletions src/sage/categories/commutative_algebra_ideals.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
# http://www.gnu.org/licenses/
#******************************************************************************

from .category_types import Category_ideal, Category_in_ambient
from .algebra_ideals import AlgebraIdeals
from .category_types import Category_ideal, Category_in_ambient
from .commutative_algebras import CommutativeAlgebras
from .commutative_rings import CommutativeRings


class CommutativeAlgebraIdeals(Category_ideal):
"""
Expand Down Expand Up @@ -51,10 +54,14 @@ def __init__(self, A):
"""
# TODO: replace by ``A in CommutativeAlgebras(*)`` once a
# suitable mantra has been implemented for this.
from sage.algebras.algebra import is_Algebra
from sage.rings.ring import CommutativeRing
if not (is_Algebra(A) and isinstance(A, CommutativeRing)):
raise TypeError("A (=%s) must be a commutative algebra"%A)
try:
base_ring = A.base_ring()
except AttributeError:
raise TypeError(f"A (={A}) must be a commutative algebra")
else:
if base_ring not in CommutativeRings() or A not in CommutativeAlgebras(base_ring.category()):
raise TypeError(f"A (={A}) must be a commutative algebra")

Category_in_ambient.__init__(self, A)

def algebra(self):
Expand Down
5 changes: 5 additions & 0 deletions src/sage/rings/commutative_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def is_CommutativeAlgebra(x):
sage: from sage.rings.commutative_algebra import is_CommutativeAlgebra
sage: from sage.rings.ring import CommutativeAlgebra
sage: is_CommutativeAlgebra(CommutativeAlgebra(ZZ))
doctest:warning...
DeprecationWarning: the function is_CommutativeAlgebra is deprecated; use '... in Algebras(base_ring).Commutative()' instead
See https://github.com/sagemath/sage/issues/35253 for details.
True
"""
from sage.misc.superseded import deprecation
deprecation(35253, "the function is_CommutativeAlgebra is deprecated; use '... in Algebras(base_ring).Commutative()' instead")
return isinstance(x, CommutativeAlgebra)