Skip to content

Commit

Permalink
move is_subring to category
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed Oct 29, 2024
1 parent 0314517 commit df30ad5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 48 deletions.
48 changes: 48 additions & 0 deletions src/sage/categories/rings.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,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
48 changes: 0 additions & 48 deletions src/sage/rings/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -652,54 +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
Expand Down

0 comments on commit df30ad5

Please sign in to comment.