Skip to content
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
2 changes: 0 additions & 2 deletions src/doc/en/thematic_tutorials/coercion_and_categories.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ This base class provides a lot more methods than a general parent::
'is_commutative',
'is_field',
'is_integrally_closed',
'is_prime_field',
'is_subring',
'krull_dimension',
'localization',
'ngens',
Expand Down
72 changes: 72 additions & 0 deletions src/sage/categories/rings.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,30 @@ def is_noetherian(self):
"""
return False

def is_prime_field(self):
r"""
Return ``True`` if this ring is one of the prime fields `\QQ` or
`\GF{p}`.

EXAMPLES::

sage: QQ.is_prime_field()
True
sage: GF(3).is_prime_field()
True
sage: GF(9, 'a').is_prime_field() # needs sage.rings.finite_rings
False
sage: ZZ.is_prime_field()
False
sage: QQ['x'].is_prime_field()
False
sage: Qp(19).is_prime_field() # needs sage.rings.padics
False
"""
# the case of QQ is handled by QQ itself
from sage.categories.finite_fields import FiniteFields
return self in FiniteFields() and self.degree() == 1

def is_zero(self) -> bool:
"""
Return ``True`` if this is the zero ring.
Expand All @@ -457,6 +481,54 @@ def is_zero(self) -> bool:
"""
return self.one() == self.zero()

def is_subring(self, other):
"""
Return ``True`` if the canonical map from ``self`` to ``other`` is
injective.

This raises a :exc:`NotImplementedError` if not known.

EXAMPLES::

sage: ZZ.is_subring(QQ)
True
sage: ZZ.is_subring(GF(19))
False

TESTS::

sage: QQ.is_subring(QQ['x'])
True
sage: QQ.is_subring(GF(7))
False
sage: QQ.is_subring(CyclotomicField(7)) # needs sage.rings.number_field
True
sage: QQ.is_subring(ZZ)
False

Every ring is a subring of itself, :issue:`17287`::

sage: QQbar.is_subring(QQbar) # needs sage.rings.number_field
True
sage: RR.is_subring(RR)
True
sage: CC.is_subring(CC) # needs sage.rings.real_mpfr
True
sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^3 - x + 1/10) # needs sage.rings.number_field
sage: K.is_subring(K) # needs sage.rings.number_field
True
sage: R.<x> = RR[]
sage: R.is_subring(R)
True
"""
if self is other:
return True
try:
return self.Hom(other).natural_map().is_injective()
except (TypeError, AttributeError):
return False

def bracket(self, x, y):
"""
Return the Lie bracket `[x, y] = x y - y x` of `x` and `y`.
Expand Down
4 changes: 3 additions & 1 deletion src/sage/rings/morphism.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
25 changes: 20 additions & 5 deletions src/sage/rings/number_field/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -665,7 +666,7 @@ def krull_dimension(self):
sage: O2.krull_dimension()
1
"""
return ZZ(1)
return ZZ.one()

def integral_closure(self):
r"""
Expand Down Expand Up @@ -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.<a> = 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.
Expand Down
70 changes: 0 additions & 70 deletions src/sage/rings/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -652,76 +652,6 @@ cdef class Ring(ParentWithGens):
"""
return True

def is_subring(self, other):
"""
Return ``True`` if the canonical map from ``self`` to ``other`` is
injective.

Raises a :exc:`NotImplementedError` if not known.

EXAMPLES::

sage: ZZ.is_subring(QQ)
True
sage: ZZ.is_subring(GF(19))
False

TESTS::

sage: QQ.is_subring(QQ['x'])
True
sage: QQ.is_subring(GF(7))
False
sage: QQ.is_subring(CyclotomicField(7)) # needs sage.rings.number_field
True
sage: QQ.is_subring(ZZ)
False

Every ring is a subring of itself, :issue:`17287`::

sage: QQbar.is_subring(QQbar) # needs sage.rings.number_field
True
sage: RR.is_subring(RR)
True
sage: CC.is_subring(CC) # needs sage.rings.real_mpfr
True
sage: x = polygen(ZZ, 'x')
sage: K.<a> = NumberField(x^3 - x + 1/10) # needs sage.rings.number_field
sage: K.is_subring(K) # needs sage.rings.number_field
True
sage: R.<x> = RR[]
sage: R.is_subring(R)
True
"""
if self is other:
return True
try:
return self.Hom(other).natural_map().is_injective()
except (TypeError, AttributeError):
return False

def is_prime_field(self):
r"""
Return ``True`` if this ring is one of the prime fields `\QQ` or
`\GF{p}`.

EXAMPLES::

sage: QQ.is_prime_field()
True
sage: GF(3).is_prime_field()
True
sage: GF(9, 'a').is_prime_field() # needs sage.rings.finite_rings
False
sage: ZZ.is_prime_field()
False
sage: QQ['x'].is_prime_field()
False
sage: Qp(19).is_prime_field() # needs sage.rings.padics
False
"""
return False

def order(self):
"""
The number of elements of ``self``.
Expand Down
17 changes: 9 additions & 8 deletions src/sage/rings/ring_extension.pxd
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)


Expand All @@ -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
Loading
Loading