diff --git a/src/sage/rings/morphism.pyx b/src/sage/rings/morphism.pyx index 594e2ff0a3e..3079bfa3974 100644 --- a/src/sage/rings/morphism.pyx +++ b/src/sage/rings/morphism.pyx @@ -2879,8 +2879,10 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): over Finite Field of size 5 """ from sage.rings.ring import CommutativeRing + from sage.categories.commutative_rings import CommutativeRings from sage.categories.homset import Hom - if not isinstance(domain, CommutativeRing): + if not (domain in CommutativeRings() or + isinstance(domain, CommutativeRing)): # TODO: remove this line raise TypeError("The base ring must be a commutative ring") self._p = domain.characteristic() if not self._p.is_prime(): diff --git a/src/sage/rings/number_field/order.py b/src/sage/rings/number_field/order.py index 55db3bbbcbf..9dee6a8a481 100644 --- a/src/sage/rings/number_field/order.py +++ b/src/sage/rings/number_field/order.py @@ -77,8 +77,9 @@ # https://www.gnu.org/licenses/ # **************************************************************************** +from sage.categories.integral_domains import IntegralDomains from sage.misc.cachefunc import cached_method -from sage.rings.ring import IntegralDomain +from sage.structure.parent import Parent from sage.structure.sequence import Sequence from sage.rings.integer_ring import ZZ import sage.rings.abc @@ -426,7 +427,7 @@ def EquationOrder(f, names, **kwds): return K.order(K.gens()) -class Order(IntegralDomain, sage.rings.abc.Order): +class Order(Parent, sage.rings.abc.Order): r""" An order in a number field. @@ -478,8 +479,8 @@ def __init__(self, K): 0.0535229072603327 + 1.20934552493846*I """ self._K = K - IntegralDomain.__init__(self, ZZ, names=K.variable_names(), - normalize=False) + Parent.__init__(self, base=ZZ, names=K.variable_names(), + normalize=False, category=IntegralDomains()) self._populate_coercion_lists_(embedding=self.number_field()) if self.absolute_degree() == 2: self.is_maximal() # cache @@ -665,7 +666,7 @@ def krull_dimension(self): sage: O2.krull_dimension() 1 """ - return ZZ(1) + return ZZ.one() def integral_closure(self): r""" @@ -733,6 +734,20 @@ def ngens(self): """ return self.absolute_degree() + def gens(self) -> tuple: + """ + Return the generators as a tuple. + + EXAMPLES:: + + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x^3 + x^2 - 2*x + 8) + sage: O = K.maximal_order() + sage: O.gens() + (1, 1/2*a^2 + 1/2*a, a^2) + """ + return tuple(self.gen(i) for i in range(self.absolute_degree())) + def basis(self): # this must be defined in derived class r""" Return a basis over `\ZZ` of this order. diff --git a/src/sage/rings/ring_extension.pxd b/src/sage/rings/ring_extension.pxd index 478bd6eef75..68c2dd0e974 100644 --- a/src/sage/rings/ring_extension.pxd +++ b/src/sage/rings/ring_extension.pxd @@ -1,8 +1,8 @@ from sage.categories.map cimport Map -from sage.rings.ring cimport CommutativeRing +from sage.structure.parent cimport Parent -cdef class RingExtension_generic(CommutativeRing): +cdef class RingExtension_generic(Parent): cdef _type cdef _backend cdef _defining_morphism @@ -15,10 +15,10 @@ cdef class RingExtension_generic(CommutativeRing): cdef type _fraction_field_type cpdef is_defined_over(self, base) - cpdef CommutativeRing _check_base(self, CommutativeRing base) - cpdef _degree_over(self, CommutativeRing base) - cpdef _is_finite_over(self, CommutativeRing base) - cpdef _is_free_over(self, CommutativeRing base) + cpdef Parent _check_base(self, Parent base) + cpdef _degree_over(self, Parent base) + cpdef _is_finite_over(self, Parent base) + cpdef _is_free_over(self, Parent base) cdef Map _defining_morphism_fraction_field(self, bint extend_base) @@ -31,10 +31,11 @@ cdef class RingExtensionWithBasis(RingExtension_generic): cdef _basis_names cdef _basis_latex_names - cpdef _basis_over(self, CommutativeRing base) - # cpdef _free_module(self, CommutativeRing base, bint map) + cpdef _basis_over(self, Parent base) + # cpdef _free_module(self, Parent base, bint map) cdef class RingExtensionWithGen(RingExtensionWithBasis): cdef _gen cdef _name + cdef public object _latex_names diff --git a/src/sage/rings/ring_extension.pyx b/src/sage/rings/ring_extension.pyx index 174af6dd415..0b376794b76 100644 --- a/src/sage/rings/ring_extension.pyx +++ b/src/sage/rings/ring_extension.pyx @@ -117,12 +117,12 @@ from sage.cpython.getattr import dir_with_other_class from sage.misc.latex import latex, latex_variable_name from sage.structure.factory import UniqueFactory +from sage.structure.parent cimport Parent from sage.structure.element cimport Element from sage.structure.category_object import normalize_names from sage.categories.map cimport Map from sage.categories.commutative_rings import CommutativeRings from sage.categories.fields import Fields -from sage.rings.ring cimport CommutativeRing from sage.rings.integer_ring import ZZ from sage.rings.infinity import Infinity @@ -497,7 +497,7 @@ RingExtension = RingExtensionFactory("sage.rings.ring_extension.RingExtension") # General extensions #################### -cdef class RingExtension_generic(CommutativeRing): +cdef class RingExtension_generic(Parent): r""" A generic class for all ring extensions. @@ -564,8 +564,8 @@ cdef class RingExtension_generic(CommutativeRing): ... ValueError: exotic defining morphism between two rings in the tower; consider using another variable name """ - cdef CommutativeRing base, ring - cdef CommutativeRing b, backend + cdef Parent base, ring + cdef Parent b, backend cdef Map f base = defining_morphism.domain() @@ -575,7 +575,7 @@ cdef class RingExtension_generic(CommutativeRing): # but CommutativeRings() seems safer, especially when dealing with # morphisms which do not need to preserve the base category = CommutativeRings() - CommutativeRing.__init__(self, ZZ, category=category) + Parent.__init__(self, ZZ, category=category) self._base = base self._backend = ring self._backend_defining_morphism = defining_morphism @@ -1197,14 +1197,14 @@ cdef class RingExtension_generic(CommutativeRing): :meth:`base`, :meth:`bases`, :meth:`absolute_base` """ - cdef CommutativeRing b + cdef Parent b b = self while isinstance(b, RingExtension_generic): if b is base or (b)._backend is base: return True b = (b)._base return b is base - cpdef CommutativeRing _check_base(self, CommutativeRing base): + cpdef Parent _check_base(self, Parent base): r""" Check if ``base`` is one of the successive bases of this extension and, if it is, normalize it. @@ -1243,7 +1243,7 @@ cdef class RingExtension_generic(CommutativeRing): sage: L._check_base(None) is L.base() # needs sage.rings.finite_rings True """ - cdef CommutativeRing b + cdef Parent b if base is None: return self._base b = self @@ -1450,7 +1450,7 @@ cdef class RingExtension_generic(CommutativeRing): base = self._check_base(base) return self._degree_over(base) - cpdef _degree_over(self, CommutativeRing base): + cpdef _degree_over(self, Parent base): r""" Return the degree of this extension over ``base``. @@ -1572,7 +1572,7 @@ cdef class RingExtension_generic(CommutativeRing): sage: L.is_finite_over() # needs sage.rings.finite_rings True """ - cdef CommutativeRing b + cdef Parent b base = self._check_base(base) if base is self: return True @@ -1590,7 +1590,7 @@ cdef class RingExtension_generic(CommutativeRing): b = (b)._base raise NotImplementedError - cpdef _is_finite_over(self, CommutativeRing base): + cpdef _is_finite_over(self, Parent base): r""" Return whether or not this extension is finite over ``base``. @@ -1635,7 +1635,7 @@ cdef class RingExtension_generic(CommutativeRing): sage: L.is_free_over() # needs sage.rings.finite_rings True """ - cdef CommutativeRing b + cdef Parent b base = self._check_base(base) if base is self or base.is_field(): return True @@ -1653,7 +1653,7 @@ cdef class RingExtension_generic(CommutativeRing): b = (b)._base raise NotImplementedError - cpdef _is_free_over(self, CommutativeRing base): + cpdef _is_free_over(self, Parent base): r""" Return whether or not this extension is finite over ``base``. @@ -2191,7 +2191,7 @@ cdef class RingExtensionWithBasis(RingExtension_generic): b = b.base_ring() return base - cpdef _degree_over(self, CommutativeRing base): + cpdef _degree_over(self, Parent base): r""" Return the degree of this extension over ``base``. @@ -2218,7 +2218,7 @@ cdef class RingExtensionWithBasis(RingExtension_generic): else: return len(self._basis) * self._base._degree_over(base) - cpdef _is_finite_over(self, CommutativeRing base): + cpdef _is_finite_over(self, Parent base): r""" Return whether or not this extension is finite over ``base``. @@ -2237,7 +2237,7 @@ cdef class RingExtensionWithBasis(RingExtension_generic): return True return self._base._is_finite_over(base) - cpdef _is_free_over(self, CommutativeRing base): + cpdef _is_free_over(self, Parent base): r""" Return whether or not this extension is free over ``base``. @@ -2298,7 +2298,7 @@ cdef class RingExtensionWithBasis(RingExtension_generic): base = self._check_base(base) return self._basis_over(base) - cpdef _basis_over(self, CommutativeRing base): + cpdef _basis_over(self, Parent base): r""" Return a basis of this extension over ``base``. @@ -2588,7 +2588,6 @@ cdef class RingExtensionWithGen(RingExtensionWithBasis): RingExtensionWithBasis.__init__(self, defining_morphism, basis, basis_names, check, **kwargs) self._gen = self._backend(gen) self._names = (self._name,) - self._latex_names = (latex_variable_name(self._name),) self._basis_latex_names = basis_latex_names def _repr_topring(self, **options): diff --git a/src/sage/rings/ring_extension_element.pxd b/src/sage/rings/ring_extension_element.pxd index 6b62ad58c06..9bd662f3d0f 100644 --- a/src/sage/rings/ring_extension_element.pxd +++ b/src/sage/rings/ring_extension_element.pxd @@ -1,4 +1,4 @@ -from sage.rings.ring cimport CommutativeRing +from sage.structure.parent cimport Parent from sage.structure.element cimport Element from sage.structure.element cimport CommutativeAlgebraElement from sage.rings.ring_extension cimport RingExtension_generic @@ -13,10 +13,10 @@ cdef class RingExtensionFractionFieldElement(RingExtensionElement): pass cdef class RingExtensionWithBasisElement(RingExtensionElement): - cdef _vector(self, CommutativeRing base) - cdef _matrix(self, CommutativeRing base) - cdef _trace(self, CommutativeRing base) - cdef _norm(self, CommutativeRing base) + cdef _vector(self, Parent base) + cdef _matrix(self, Parent base) + cdef _trace(self, Parent base) + cdef _norm(self, Parent base) cpdef minpoly(self, base=*, var=*) diff --git a/src/sage/rings/ring_extension_element.pyx b/src/sage/rings/ring_extension_element.pyx index 67b6aa90879..e3184503d77 100644 --- a/src/sage/rings/ring_extension_element.pyx +++ b/src/sage/rings/ring_extension_element.pyx @@ -24,6 +24,7 @@ from sage.misc.latex import latex from sage.structure.category_object import normalize_names from sage.structure.element cimport CommutativeAlgebraElement +from sage.structure.parent cimport Parent from sage.rings.integer_ring import ZZ from sage.categories.fields import Fields from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing @@ -1033,7 +1034,7 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): base = (self._parent)._check_base(base) return self._vector(base) - cdef _vector(self, CommutativeRing base): + cdef _vector(self, Parent base): r""" Return the vector of coordinates of this element over ``base`` (in the basis output by the method :meth:`basis_over`). @@ -1198,7 +1199,7 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): raise ValueError("the extension is not finite free") return self._matrix(base) - cdef _matrix(self, CommutativeRing base): + cdef _matrix(self, Parent base): r""" Return the matrix of the multiplication by this element (in the basis output by :meth:`basis_over`). @@ -1286,7 +1287,7 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): raise ValueError("the extension is not finite free") return self._trace(base) - cdef _trace(self, CommutativeRing base): + cdef _trace(self, Parent base): r""" Return the trace of this element over ``base``. @@ -1314,7 +1315,7 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): ....: assert((x+y).trace(base) == x.trace(base) + y.trace(base)) """ cdef RingExtensionWithBasis parent = self._parent - cdef CommutativeRing b + cdef Parent b if base is parent: return self b = parent._base @@ -1379,7 +1380,7 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): raise ValueError("the extension is not finite free") return self._norm(base) - cdef _norm(self, CommutativeRing base): + cdef _norm(self, Parent base): r""" Return the norm of this element over ``base``. @@ -1407,7 +1408,7 @@ cdef class RingExtensionWithBasisElement(RingExtensionElement): ....: assert((x*y).norm(base) == x.norm(base) * y.norm(base)) """ cdef RingExtensionWithBasis parent = self._parent - cdef CommutativeRing b + cdef Parent b if base is parent: return self b = parent._base diff --git a/src/sage/rings/ring_extension_morphism.pyx b/src/sage/rings/ring_extension_morphism.pyx index 2768bdac81c..d4aad7f8253 100644 --- a/src/sage/rings/ring_extension_morphism.pyx +++ b/src/sage/rings/ring_extension_morphism.pyx @@ -21,7 +21,7 @@ from sage.structure.richcmp import op_EQ, op_NE from sage.structure.element cimport Element from sage.categories.map import Map -from sage.rings.ring cimport CommutativeRing +from sage.structure.parent cimport Parent from sage.rings.morphism cimport RingMap from sage.rings.ring_extension cimport RingExtension_generic, RingExtensionWithBasis from sage.rings.ring_extension_element cimport RingExtensionElement @@ -57,7 +57,7 @@ cdef are_equal_morphisms(f, g): sage: H(f^2) == H(g^2) # indirect doctest True """ - cdef CommutativeRing b + cdef Parent b cdef tuple gens if f is None and g is None: return True @@ -821,7 +821,7 @@ cdef class MapRelativeRingToFreeModule(Map): From: Field in z6 with defining polynomial x^2 + (10*z3^2 + z3 + 6)*x + z3 over its base To: Vector space of dimension 2 over Finite Field in z3 of size 11^3 """ - cdef CommutativeRing L, base + cdef Parent L, base self._degree = (E)._degree_over(K) self._basis = [ (x)._backend for x in E.basis_over(K) ]