Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
first draft
Browse files Browse the repository at this point in the history
  • Loading branch information
mjungmath committed Apr 24, 2021
1 parent de32db6 commit 04f0ec6
Show file tree
Hide file tree
Showing 13 changed files with 239 additions and 267 deletions.
192 changes: 192 additions & 0 deletions src/sage/categories/rings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from sage.categories.rngs import Rngs
from sage.structure.element import Element
from functools import reduce
from sage.misc.abstract_method import abstract_method


class Rings(CategoryWithAxiom):
Expand Down Expand Up @@ -331,6 +332,55 @@ def is_ring(self):
"""
return True

def is_field(self, proof=True):
"""
Return ``True`` if this ring is a field.
INPUT:
- ``proof`` -- (default: ``True``) Determines what to do in unknown
cases
ALGORITHM:
If the parameter ``proof`` is set to ``True``, the returned value is
correct but the method might throw an error. Otherwise, if it is set
to ``False``, the method returns True if it can establish that self is
a field and False otherwise.
EXAMPLES::
sage: QQ.is_field()
True
sage: GF(9,'a').is_field()
True
sage: ZZ.is_field()
False
sage: QQ['x'].is_field()
False
sage: Frac(QQ['x']).is_field()
True
This illustrates the use of the ``proof`` parameter::
sage: R.<a,b> = QQ[]
sage: S.<x,y> = R.quo((b^3))
sage: S.is_field(proof = True)
Traceback (most recent call last):
...
NotImplementedError
sage: S.is_field(proof = False)
False
"""
if self.is_zero():
return False

if proof:
raise NotImplementedError(
"No way to prove that %s is an integral domain!" % self)
else:
return False

def is_zero(self):
"""
Return ``True`` if this is the zero ring.
Expand All @@ -354,6 +404,148 @@ def is_zero(self):
"""
return self.one() == self.zero()

def is_integral_domain(self, proof=True):
"""
Return ``True`` if this ring is an integral domain.
INPUT:
- ``proof`` -- (default: ``True``) Determines what to do in unknown
cases
ALGORITHM:
If the parameter ``proof`` is set to ``True``, the returned value is
correct but the method might throw an error. Otherwise, if it is set
to ``False``, the method returns ``True`` if it can establish that self
is an integral domain and ``False`` otherwise.
EXAMPLES::
sage: QQ.is_integral_domain()
True
sage: ZZ.is_integral_domain()
True
sage: ZZ['x,y,z'].is_integral_domain()
True
sage: Integers(8).is_integral_domain()
False
sage: Zp(7).is_integral_domain()
True
sage: Qp(7).is_integral_domain()
True
sage: R.<a,b> = QQ[]
sage: S.<x,y> = R.quo((b^3))
sage: S.is_integral_domain()
False
This illustrates the use of the ``proof`` parameter::
sage: R.<a,b> = ZZ[]
sage: S.<x,y> = R.quo((b^3))
sage: S.is_integral_domain(proof = True)
Traceback (most recent call last):
...
NotImplementedError
sage: S.is_integral_domain(proof = False)
False
TESTS:
Make sure :trac:`10481` is fixed::
sage: var('x')
x
sage: R.<a> = ZZ['x'].quo(x^2)
sage: R.fraction_field()
Traceback (most recent call last):
...
NotImplementedError
sage: R.is_integral_domain()
Traceback (most recent call last):
...
NotImplementedError
Forward the proof flag to ``is_field``, see :trac:`22910`::
sage: R1.<x> = GF(5)[]
sage: F1 = R1.quotient_ring(x^2+x+1)
sage: R2.<x> = F1[]
sage: F2 = R2.quotient_ring(x^2+x+1)
sage: F2.is_integral_domain(False)
False
"""
if self.is_field(proof):
return True

if self.is_zero():
return False

if proof:
raise NotImplementedError
else:
return False

@abstract_method(optional=True)
def is_noetherian(self):
"""
Return ``True`` if this ring is Noetherian.
EXAMPLES::
sage: QQ.is_noetherian()
True
sage: ZZ.is_noetherian()
True
"""

def is_subring(self, other):
"""
Return ``True`` if the canonical map from ``self`` to ``other`` is
injective.
Raises a ``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))
True
sage: QQ.is_subring(ZZ)
False
Every ring is a subring of itself, :trac:`17287`::
sage: QQbar.is_subring(QQbar)
True
sage: RR.is_subring(RR)
True
sage: CC.is_subring(CC)
True
sage: K.<a> = NumberField(x^3-x+1/10)
sage: K.is_subring(K)
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):
"""
Returns the Lie bracket `[x, y] = x y - y x` of `x` and `y`.
Expand Down
12 changes: 3 additions & 9 deletions src/sage/matrix/matrix0.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ from sage.structure.element cimport ModuleElement, Element, RingElement, Vector
from sage.structure.mutability cimport Mutability
from sage.misc.misc_c cimport normalize_index

from sage.categories.fields import Fields
from sage.categories.integral_domains import IntegralDomains

from sage.rings.ring cimport CommutativeRing
from sage.rings.ring import is_Ring
from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing
Expand All @@ -51,9 +48,6 @@ import sage.modules.free_module

from .matrix_misc import row_iterator

_Fields = Fields()
_IntegralDomains = IntegralDomains()

cdef class Matrix(sage.structure.element.Matrix):
r"""
A generic matrix.
Expand Down Expand Up @@ -5597,8 +5591,8 @@ cdef class Matrix(sage.structure.element.Matrix):
return self

R = self.base_ring()
if R not in _Fields:
if R in _IntegralDomains:
if not R.is_field(proof=False):
if R.is_integral_domain(proof=False):
return ~self.matrix_over_field()
else:
return self.inverse_of_unit()
Expand Down Expand Up @@ -5706,7 +5700,7 @@ cdef class Matrix(sage.structure.element.Matrix):
raise ArithmeticError("self must be a square matrix")

R = self.base_ring()
if algorithm is None and R in _Fields:
if algorithm is None and R.is_field(proof=False):
return ~self
elif algorithm is None and is_IntegerModRing(R):
# Finite fields are handled above.
Expand Down
Loading

0 comments on commit 04f0ec6

Please sign in to comment.