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

Commit

Permalink
Merge #32606
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Oct 13, 2021
2 parents 13607cb + 907b57c commit 355dbcb
Show file tree
Hide file tree
Showing 21 changed files with 74 additions and 44 deletions.
4 changes: 2 additions & 2 deletions src/sage/libs/singular/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ from sage.libs.singular.decl cimport rDefault, GFInfo, ZnmInfo, nInitChar, AlgEx
from sage.rings.integer cimport Integer
from sage.rings.integer_ring cimport IntegerRing_class
from sage.rings.integer_ring import ZZ
from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing
import sage.rings.abc
from sage.rings.number_field.number_field_base cimport NumberField
from sage.rings.rational_field import RationalField
from sage.rings.finite_rings.finite_field_base import FiniteField as FiniteField_generic
Expand Down Expand Up @@ -324,7 +324,7 @@ cdef ring *singular_ring_new(base_ring, n, names, term_order) except NULL:

_ring = rDefault (_cf ,nvars, _names, nblcks, _order, _block0, _block1, _wvhdl)

elif is_IntegerModRing(base_ring):
elif isinstance(base_ring, sage.rings.abc.IntegerModRing):

ch = base_ring.characteristic()
if ch < 2:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/matrix/matrix0.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ 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
import sage.rings.abc
from sage.rings.integer_ring import is_IntegerRing

import sage.modules.free_module
Expand Down Expand Up @@ -5749,7 +5749,7 @@ cdef class Matrix(sage.structure.element.Matrix):
R = self.base_ring()
if algorithm is None and R in _Fields:
return ~self
elif algorithm is None and is_IntegerModRing(R):
elif algorithm is None and isinstance(R, sage.rings.abc.IntegerModRing):
# Finite fields are handled above.
# This is "easy" in that we either get an error or
# the right answer. Note that of course there
Expand Down
11 changes: 6 additions & 5 deletions src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ from sage.rings.complex_double import CDF
from sage.rings.real_mpfr import RealField
from sage.rings.complex_mpfr import ComplexField
from sage.rings.finite_rings.integer_mod_ring import IntegerModRing
from sage.misc.derivative import multi_derivative
import sage.rings.abc
from sage.arith.numerical_approx cimport digits_to_bits
from copy import copy

Expand Down Expand Up @@ -822,8 +822,7 @@ cdef class Matrix(Matrix1):
if not K.is_integral_domain():
# The non-integral-domain case is handled almost entirely
# separately.
from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing
if is_IntegerModRing(K):
if isinstance(K, sage.rings.abc.IntegerModRing):
from sage.libs.pari import pari
A = pari(self.lift())
b = pari(B).lift()
Expand Down Expand Up @@ -1985,7 +1984,6 @@ cdef class Matrix(Matrix1):
sage: A.determinant() == B.determinant()
True
"""
from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing
from sage.symbolic.ring import is_SymbolicExpressionRing

cdef Py_ssize_t n
Expand Down Expand Up @@ -2031,7 +2029,7 @@ cdef class Matrix(Matrix1):
return d

# Special case for Z/nZ or GF(p):
if is_IntegerModRing(R) and self.is_dense():
if isinstance(R, sage.rings.abc.IntegerModRing) and self.is_dense():
import sys
# If the characteristic is prime and smaller than a machine
# word, use PARI.
Expand Down Expand Up @@ -14723,6 +14721,8 @@ cdef class Matrix(Matrix1):
for i from 0 <= i < size:
PyList_Append(M,<object>f(<object>PyList_GET_ITEM(L,i)))

from sage.rings.finite_rings.integer_mod_ring import IntegerModRing

return MatrixSpace(IntegerModRing(2),
nrows=self._nrows,ncols=self._ncols).matrix(M)

Expand Down Expand Up @@ -15123,6 +15123,7 @@ cdef class Matrix(Matrix1):
sage: v.derivative(x,x)
(0, 0, 2)
"""
from sage.misc.derivative import multi_derivative
return multi_derivative(self, args)

def exp(self):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/matrix/matrix_rational_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ from sage.rings.integer cimport Integer
from sage.rings.ring import is_Ring
from sage.rings.integer_ring import ZZ, is_IntegerRing
from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF
from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing
import sage.rings.abc
from sage.rings.rational_field import QQ
from sage.arith.all import gcd

Expand Down Expand Up @@ -1487,7 +1487,7 @@ cdef class Matrix_rational_dense(Matrix_dense):
return A

from .matrix_modn_dense_double import MAX_MODULUS
if is_IntegerModRing(R) and R.order() < MAX_MODULUS:
if isinstance(R, sage.rings.abc.IntegerModRing) and R.order() < MAX_MODULUS:
b = R.order()
A, d = self._clear_denom()
if not b.gcd(d).is_one():
Expand Down
4 changes: 2 additions & 2 deletions src/sage/matrix/matrix_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def get_matrix_class(R, nrows, ncols, sparse, implementation):
except ImportError:
pass

if sage.rings.finite_rings.integer_mod_ring.is_IntegerModRing(R):
if isinstance(R, sage.rings.abc.IntegerModRing):
from . import matrix_modn_dense_double, matrix_modn_dense_float
if R.order() < matrix_modn_dense_float.MAX_MODULUS:
return matrix_modn_dense_float.Matrix_modn_dense_float
Expand Down Expand Up @@ -326,7 +326,7 @@ def get_matrix_class(R, nrows, ncols, sparse, implementation):
if implementation is not None:
raise ValueError("cannot choose an implementation for sparse matrices")

if sage.rings.finite_rings.integer_mod_ring.is_IntegerModRing(R) and R.order() < matrix_modn_sparse.MAX_MODULUS:
if isinstance(R, sage.rings.abc.IntegerModRing) and R.order() < matrix_modn_sparse.MAX_MODULUS:
return matrix_modn_sparse.Matrix_modn_sparse

if sage.rings.rational_field.is_RationalField(R):
Expand Down
6 changes: 3 additions & 3 deletions src/sage/modules/free_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
import sage.rings.abc
import sage.rings.integer_ring
import sage.rings.rational_field
import sage.rings.finite_rings.integer_mod_ring
import sage.rings.abc
import sage.rings.infinity
import sage.rings.integer
from sage.categories.principal_ideal_domains import PrincipalIdealDomains
Expand Down Expand Up @@ -254,7 +254,7 @@ def create_object(self, version, key):
elif base_ring in PrincipalIdealDomains():
return FreeModule_ambient_pid(base_ring, rank, sparse=sparse)

elif isinstance(base_ring, sage.rings.number_field.order.Order) \
elif isinstance(base_ring, sage.rings.abc.Order) \
and base_ring.is_maximal() and base_ring.class_number() == 1:
return FreeModule_ambient_pid(base_ring, rank, sparse=sparse)

Expand Down Expand Up @@ -7435,7 +7435,7 @@ def element_class(R, is_sparse):
elif sage.rings.rational_field.is_RationalField(R) and not is_sparse:
from .vector_rational_dense import Vector_rational_dense
return Vector_rational_dense
elif sage.rings.finite_rings.integer_mod_ring.is_IntegerModRing(R) and not is_sparse:
elif isinstance(R, sage.rings.abc.IntegerModRing) and not is_sparse:
from .vector_mod2_dense import Vector_mod2_dense
if R.order() == 2:
return Vector_mod2_dense
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modules/free_module_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ from sage.rings.infinity import Infinity, AnInfinity
from sage.rings.integer_ring import ZZ
from sage.rings.real_double import RDF
from sage.rings.complex_double import CDF
from sage.misc.derivative import multi_derivative

from sage.rings.ring cimport Ring
from sage.rings.integer cimport Integer, smallInteger
Expand Down Expand Up @@ -3968,6 +3967,7 @@ cdef class FreeModuleElement(Vector): # abstract base class
sage: v.derivative(x,x)
(0, 0, 2)
"""
from sage.misc.derivative import multi_derivative
return multi_derivative(self, args)
diff = derivative
Expand Down
7 changes: 5 additions & 2 deletions src/sage/modules/vector_space_morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,10 @@ def linear_transformation(arg0, arg1=None, arg2=None, side='left'):
from sage.modules.module import is_VectorSpace
from sage.modules.free_module import VectorSpace
from sage.categories.homset import Hom
from sage.symbolic.ring import SR
from sage.modules.vector_callable_symbolic_dense import Vector_callable_symbolic_dense
try:
from sage.modules.vector_callable_symbolic_dense import Vector_callable_symbolic_dense
except ImportError:
Vector_callable_symbolic_dense = ()

if not side in ['left', 'right']:
raise ValueError("side must be 'left' or 'right', not {0}".format(side))
Expand Down Expand Up @@ -734,6 +736,7 @@ def linear_transformation(arg0, arg1=None, arg2=None, side='left'):
elif isinstance(arg2, (list, tuple)):
pass
elif isinstance(arg2, Vector_callable_symbolic_dense):
from sage.symbolic.ring import SR
args = arg2.parent().base_ring()._arguments
exprs = arg2.change_ring(SR)
m = len(args)
Expand Down
15 changes: 15 additions & 0 deletions src/sage/rings/abc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,18 @@ cdef class ComplexDoubleField(Field):
"""

pass


class IntegerModRing:
r"""
Abstract base class for :class:`~sage.rings.finite_rings.integer_mod_ring.IntegerModRing_generic`.
"""

pass

class Order:
r"""
Abstract base class for :class:`~sage.rings.number_field.order.Order`.
"""

pass
4 changes: 2 additions & 2 deletions src/sage/rings/finite_rings/finite_field_base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ from sage.misc.persist import register_unpickle_override
from sage.misc.cachefunc import cached_method
from sage.misc.prandom import randrange
from sage.rings.integer cimport Integer
import sage.rings.abc
from sage.misc.superseded import deprecation_cython as deprecation

# Copied from sage.misc.fast_methods, used in __hash__() below.
Expand Down Expand Up @@ -1342,10 +1343,9 @@ cdef class FiniteField(Field):
False
"""
from sage.rings.integer_ring import ZZ
from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing
if R is int or R is long or R is ZZ:
return True
if is_IntegerModRing(R) and self.characteristic().divides(R.characteristic()):
if isinstance(R, sage.rings.abc.IntegerModRing) and self.characteristic().divides(R.characteristic()):
return R.hom((self.one(),), check=False)
if is_FiniteField(R):
if R is self:
Expand Down
13 changes: 12 additions & 1 deletion src/sage/rings/finite_rings/integer_mod_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

from sage.arith.all import factor, primitive_root, CRT_basis
import sage.rings.ring as ring
import sage.rings.abc
from . import integer_mod
import sage.rings.integer as integer
import sage.rings.integer_ring as integer_ring
Expand Down Expand Up @@ -243,11 +244,18 @@ def is_IntegerModRing(x):
"""
Return ``True`` if ``x`` is an integer modulo ring.

This function is deprecated. Use :func:`isinstance` with
:class:`sage.rings.abc.IntegerModRing` instead.

EXAMPLES::

sage: from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing
sage: R = IntegerModRing(17)
sage: is_IntegerModRing(R)
doctest:warning...
DeprecationWarning: the function is_IntegerModRing is deprecated.
Use isinstance(..., sage.rings.abc.IntegerModRing) instead.
See https://trac.sagemath.org/32606 for details.
True
sage: is_IntegerModRing(GF(13))
True
Expand All @@ -258,6 +266,9 @@ def is_IntegerModRing(x):
sage: is_IntegerModRing(ZZ)
False
"""
from sage.misc.superseded import deprecation
deprecation(32606, "the function is_IntegerModRing is deprecated. "
"Use isinstance(..., sage.rings.abc.IntegerModRing) instead.")
return isinstance(x, IntegerModRing_generic)


Expand Down Expand Up @@ -297,7 +308,7 @@ def _unit_gens_primepowercase(p, r):


@richcmp_method
class IntegerModRing_generic(quotient_ring.QuotientRing_generic):
class IntegerModRing_generic(quotient_ring.QuotientRing_generic, sage.rings.abc.IntegerModRing):
"""
The ring of integers modulo `N`.

Expand Down
3 changes: 2 additions & 1 deletion src/sage/rings/number_field/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from sage.rings.ring import IntegralDomain
from sage.structure.sequence import Sequence
from sage.rings.integer_ring import ZZ
import sage.rings.abc
from sage.structure.element import is_Element
from .number_field_element import OrderElement_absolute, OrderElement_relative

Expand Down Expand Up @@ -126,7 +127,7 @@ def EquationOrder(f, names, **kwds):
return K.order(K.gens())


class Order(IntegralDomain):
class Order(IntegralDomain, sage.rings.abc.Order):
r"""
An order in a number field.

Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/polynomial/multi_polynomial_ideal.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
from sage.misc.method_decorator import MethodDecorator

from sage.rings.integer_ring import ZZ
import sage.rings.abc
import sage.rings.polynomial.toy_buchberger as toy_buchberger
import sage.rings.polynomial.toy_variety as toy_variety
import sage.rings.polynomial.toy_d_basis as toy_d_basis
Expand Down Expand Up @@ -4288,7 +4289,6 @@ def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, prot=Fal
sage: I.groebner_basis('magma:GroebnerBasis') # optional - magma
[a + (-60)*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 + (-79/7)*c^2 + 3/7*c, c^4 + (-10/21)*c^3 + 1/84*c^2 + 1/84*c]
"""
from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing
from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing

Expand Down Expand Up @@ -4331,7 +4331,7 @@ def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, prot=Fal
deg_bound=deg_bound, mult_bound=mult_bound,
prot=prot, *args, **kwds)]
elif (R.term_order().is_global()
and is_IntegerModRing(B)
and isinstance(B, sage.rings.abc.IntegerModRing)
and not B.is_field()):
verbose("Warning: falling back to very slow toy implementation.", level=0)

Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/polynomial/multi_polynomial_libsingular.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,14 @@ from sage.rings.polynomial.polydict cimport ETuple
from sage.rings.polynomial.polynomial_ring import is_PolynomialRing

# base ring imports
import sage.rings.abc
from sage.rings.finite_rings.finite_field_prime_modn import FiniteField_prime_modn
from sage.rings.rational cimport Rational
from sage.rings.rational_field import QQ
import sage.rings.abc
from sage.rings.integer_ring import is_IntegerRing, ZZ
from sage.rings.integer cimport Integer
from sage.rings.integer import GCD_list
from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing
from sage.rings.number_field.number_field_base cimport NumberField

from sage.structure.element import coerce_binop
Expand Down Expand Up @@ -1406,7 +1406,7 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base):
elif is_IntegerRing(base_ring):
self.__singular = singular.ring("(integer)", _vars, order=order)

elif is_IntegerModRing(base_ring):
elif isinstance(base_ring, sage.rings.abc.IntegerModRing):
ch = base_ring.characteristic()
if ch.is_power_of(2):
exp = ch.nbits() -1
Expand Down
5 changes: 2 additions & 3 deletions src/sage/rings/polynomial/polynomial_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ from sage.structure.element cimport (parent, have_same_parent,

from sage.rings.rational_field import QQ, is_RationalField
from sage.rings.integer_ring import ZZ, is_IntegerRing
from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing
from sage.rings.integer cimport Integer, smallInteger
from sage.libs.gmp.mpz cimport *
from sage.rings.fraction_field import is_FractionField
Expand Down Expand Up @@ -4446,7 +4445,7 @@ cdef class Polynomial(CommutativeAlgebraElement):

n = None

if is_IntegerModRing(R) or is_IntegerRing(R):
if isinstance(R, sage.rings.abc.IntegerModRing) or is_IntegerRing(R):
try:
G = list(self._pari_with_name().factor())
except PariError:
Expand Down Expand Up @@ -8124,7 +8123,7 @@ cdef class Polynomial(CommutativeAlgebraElement):
if K.is_finite():
if multiplicities:
raise NotImplementedError("root finding with multiplicities for this polynomial not implemented (try the multiplicities=False option)")
elif is_IntegerModRing(K):
elif isinstance(K, sage.rings.abc.IntegerModRing):
# handling via the chinese remainders theorem
N = K.cardinality()
primes = N.prime_divisors()
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/polynomial/polynomial_ring_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import sage.rings.ring as ring
import sage.rings.padics.padic_base_leaves as padic_base_leaves

import sage.rings.abc
from sage.rings.integer import Integer
from sage.rings.finite_rings.finite_field_base import is_FiniteField
from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing

from sage.misc.cachefunc import weak_cached_function

Expand Down Expand Up @@ -694,7 +694,7 @@ def _single_variate(base_ring, name, sparse=None, implementation=None, order=Non

# Specialized implementations
specialized = None
if is_IntegerModRing(base_ring):
if isinstance(base_ring, sage.rings.abc.IntegerModRing):
n = base_ring.order()
if n.is_prime():
specialized = polynomial_ring.PolynomialRing_dense_mod_p
Expand Down
Loading

0 comments on commit 355dbcb

Please sign in to comment.