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

Commit

Permalink
Merge #32612
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Oct 8, 2021
2 parents 52915b6 + 362f5c0 commit ce8687b
Show file tree
Hide file tree
Showing 52 changed files with 346 additions and 184 deletions.
11 changes: 5 additions & 6 deletions src/sage/dynamics/arithmetic_dynamics/projective_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,15 @@ class initialization directly.
from sage.rings.polynomial.flatten import FlatteningMorphism, UnflatteningMorphism
from sage.rings.morphism import RingHomomorphism_im_gens
from sage.rings.number_field.number_field_ideal import NumberFieldFractionalIdeal
from sage.rings.number_field.number_field import is_NumberField
from sage.rings.padics.all import Qp
from sage.rings.polynomial.multi_polynomial_ring_base import is_MPolynomialRing
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.polynomial.polynomial_ring import is_PolynomialRing
from sage.rings.qqbar import QQbar, number_field_elements_from_algebraics
from sage.rings.quotient_ring import QuotientRing_generic
from sage.rings.rational_field import QQ
from sage.rings.real_double import RDF
from sage.rings.real_mpfr import (RealField, is_RealField)
import sage.rings.abc
from sage.rings.real_mpfr import RealField
from sage.schemes.generic.morphism import SchemeMorphism_polynomial
from sage.schemes.projective.projective_subscheme import AlgebraicScheme_subscheme_projective
from sage.schemes.projective.projective_morphism import (
Expand Down Expand Up @@ -2062,10 +2061,10 @@ def canonical_height(self, P, **kwds):

# Archimedean local heights
# :: WARNING: If places is fed the default Sage precision of 53 bits,
# it uses Real or Complex Double Field in place of RealField(prec) or ComplexField(prec)
# the function is_RealField does not identify RDF as real, so we test for that ourselves.
# it uses Real or Complex Double Field in place of RealField(prec) or ComplexField(prec).
# RDF is an instance of a separate class.
for v in emb:
if is_RealField(v.codomain()) or v.codomain() is RDF:
if isinstance(v.codomain(), (sage.rings.abc.RealField, sage.rings.abc.RealDoubleField)):
dv = R.one()
else:
dv = R(2)
Expand Down
11 changes: 5 additions & 6 deletions src/sage/functions/orthogonal_polys.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,7 @@
from sage.misc.latex import latex
from sage.rings.all import ZZ, QQ, RR, CC
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.real_mpfr import is_RealField
from sage.rings.complex_mpfr import is_ComplexField
import sage.rings.abc

from sage.symbolic.function import BuiltinFunction, GinacFunction
from sage.symbolic.expression import Expression
Expand Down Expand Up @@ -672,7 +671,7 @@ def _evalf_(self, n, x, **kwds):
except KeyError:
real_parent = parent(x)

if not is_RealField(real_parent) and not is_ComplexField(real_parent):
if not isinstance(real_parent, (sage.rings.abc.RealField, sage.rings.abc.ComplexField)):
# parent is not a real or complex field: figure out a good parent
if x in RR:
x = RR(x)
Expand All @@ -681,7 +680,7 @@ def _evalf_(self, n, x, **kwds):
x = CC(x)
real_parent = CC

if not is_RealField(real_parent) and not is_ComplexField(real_parent):
if not isinstance(real_parent, (sage.rings.abc.RealField, sage.rings.abc.ComplexField)):
raise TypeError("cannot evaluate chebyshev_T with parent {}".format(real_parent))

from sage.libs.mpmath.all import call as mpcall
Expand Down Expand Up @@ -1031,7 +1030,7 @@ def _evalf_(self, n, x, **kwds):
except KeyError:
real_parent = parent(x)

if not is_RealField(real_parent) and not is_ComplexField(real_parent):
if not isinstance(real_parent, (sage.rings.abc.RealField, sage.rings.abc.ComplexField)):
# parent is not a real or complex field: figure out a good parent
if x in RR:
x = RR(x)
Expand All @@ -1040,7 +1039,7 @@ def _evalf_(self, n, x, **kwds):
x = CC(x)
real_parent = CC

if not is_RealField(real_parent) and not is_ComplexField(real_parent):
if not isinstance(real_parent, (sage.rings.abc.RealField, sage.rings.abc.ComplexField)):
raise TypeError("cannot evaluate chebyshev_U with parent {}".format(real_parent))

from sage.libs.mpmath.all import call as mpcall
Expand Down
7 changes: 3 additions & 4 deletions src/sage/functions/special.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@
# https://www.gnu.org/licenses/
# ****************************************************************************

import sage.rings.abc
from sage.rings.integer import Integer
from sage.rings.complex_mpfr import ComplexField
from sage.misc.latex import latex
from sage.rings.all import ZZ
from sage.symbolic.constants import pi
Expand Down Expand Up @@ -362,10 +362,9 @@ def elliptic_j(z, prec=53):
sage: (-elliptic_j(tau, 100).real().round())^(1/3)
640320
"""

CC = z.parent()
from sage.rings.complex_mpfr import is_ComplexField
if not is_ComplexField(CC):
if not isinstance(CC, sage.rings.abc.ComplexField):
from sage.rings.complex_mpfr import ComplexField
CC = ComplexField(prec)
try:
z = CC(z)
Expand Down
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
9 changes: 5 additions & 4 deletions src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ 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 +823,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 +1985,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 +2030,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 +14722,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
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
4 changes: 2 additions & 2 deletions src/sage/matrix/misc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ from sage.rings.rational_field import QQ
from sage.rings.integer cimport Integer
from sage.arith.all import previous_prime, CRT_basis

from sage.rings.real_mpfr import is_RealField
from sage.rings.real_mpfr cimport RealField_class
from sage.rings.real_mpfr cimport RealNumber


Expand Down Expand Up @@ -510,7 +510,7 @@ def hadamard_row_bound_mpfr(Matrix A):
...
OverflowError: cannot convert float infinity to integer
"""
if not is_RealField(A.base_ring()):
if not isinstance(A.base_ring(), RealField_class):
raise TypeError("A must have base field an mpfr real field.")

cdef RealNumber a, b
Expand Down
12 changes: 6 additions & 6 deletions src/sage/modular/dirichlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

from sage.categories.map import Map
from sage.rings.rational_field import is_RationalField
from sage.rings.complex_mpfr import is_ComplexField
import sage.rings.abc
from sage.rings.qqbar import is_AlgebraicField
from sage.rings.ring import is_Ring

Expand Down Expand Up @@ -1153,7 +1153,7 @@ def _pari_init_(self):

# now compute the input for pari (list of exponents)
P = self.parent()
if is_ComplexField(P.base_ring()):
if isinstance(P.base_ring(), sage.rings.abc.ComplexField):
zeta = P.zeta()
zeta_argument = zeta.argument()
v = [int(x.argument() / zeta_argument) for x in values_on_gens]
Expand Down Expand Up @@ -1345,7 +1345,7 @@ def gauss_sum(self, a=1):
K = G.base_ring()
chi = self
m = G.modulus()
if is_ComplexField(K):
if isinstance(K, sage.rings.abc.ComplexField):
return self.gauss_sum_numerical(a=a)
elif is_AlgebraicField(K):
L = K
Expand Down Expand Up @@ -1422,7 +1422,7 @@ def gauss_sum_numerical(self, prec=53, a=1):
"""
G = self.parent()
K = G.base_ring()
if is_ComplexField(K):
if isinstance(K, sage.rings.abc.ComplexField):

def phi(t):
return t
Expand Down Expand Up @@ -2138,7 +2138,7 @@ def element(self):
"""
P = self.parent()
M = P._module
if is_ComplexField(P.base_ring()):
if isinstance(P.base_ring(), sage.rings.abc.ComplexField):
zeta = P.zeta()
zeta_argument = zeta.argument()
v = M([int(round(x.argument() / zeta_argument))
Expand Down Expand Up @@ -2607,7 +2607,7 @@ def _zeta_powers(self):
w = [a]
zeta = self.zeta()
zeta_order = self.zeta_order()
if is_ComplexField(R):
if isinstance(R, sage.rings.abc.ComplexField):
for i in range(1, zeta_order):
a = a * zeta
a._set_multiplicative_order(zeta_order / gcd(zeta_order, i))
Expand Down
11 changes: 6 additions & 5 deletions src/sage/modules/free_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@
from sage.modules.module import Module
import sage.rings.finite_rings.finite_field_constructor as finite_field
import sage.rings.ring as ring
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 @@ -253,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 @@ -7434,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 All @@ -7443,9 +7444,9 @@ def element_class(R, is_sparse):
return Vector_modn_dense
else:
return free_module_element.FreeModuleElement_generic_dense
elif sage.rings.real_double.is_RealDoubleField(R) and not is_sparse:
elif isinstance(R, sage.rings.abc.RealDoubleField) and not is_sparse:
return sage.modules.vector_real_double_dense.Vector_real_double_dense
elif sage.rings.complex_double.is_ComplexDoubleField(R) and not is_sparse:
elif isinstance(R, sage.rings.abc.ComplexDoubleField) and not is_sparse:
return sage.modules.vector_complex_double_dense.Vector_complex_double_dense
elif sage.symbolic.ring.is_SymbolicExpressionRing(R) and not is_sparse:
import sage.modules.vector_symbolic_dense
Expand Down
6 changes: 4 additions & 2 deletions src/sage/probability/random_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
# https://www.gnu.org/licenses/
# ****************************************************************************

import sage.rings.abc
from sage.structure.parent import Parent
from sage.functions.log import log
from sage.functions.all import sqrt
from sage.rings.real_mpfr import (RealField, is_RealField)
from sage.rings.rational_field import is_RationalField
from sage.sets.set import Set
from pprint import pformat
Expand Down Expand Up @@ -83,6 +83,7 @@ def __init__(self, X, f, codomain=None, check=False):
if check:
raise NotImplementedError("Not implemented")
if codomain is None:
from sage.rings.real_mpfr import RealField
RR = RealField()
else:
RR = codomain
Expand Down Expand Up @@ -337,8 +338,9 @@ def __init__(self, X, P, codomain=None, check=False):
1.50000000000000
"""
if codomain is None:
from sage.rings.real_mpfr import RealField
codomain = RealField()
if not is_RealField(codomain) and not is_RationalField(codomain):
if not isinstance(codomain, sage.rings.abc.RealField) and not is_RationalField(codomain):
raise TypeError("Argument codomain (= %s) must be the reals or rationals" % codomain)
if check:
one = sum(P.values())
Expand Down
6 changes: 3 additions & 3 deletions src/sage/quadratic_forms/special_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@

from sage.combinat.combinat import bernoulli_polynomial
from sage.misc.functional import denominator
from sage.rings.all import RealField
from sage.arith.all import kronecker_symbol, bernoulli, factorial, fundamental_discriminant
from sage.rings.infinity import infinity
from sage.rings.integer_ring import ZZ
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.rational_field import QQ
from sage.rings.real_mpfr import is_RealField
import sage.rings.abc
from sage.symbolic.constants import pi, I

# ---------------- The Gamma Function ------------------
Expand Down Expand Up @@ -278,9 +277,10 @@ def quadratic_L_function__numerical(n, d, num_terms=1000):
....: print("Oops! We have a problem at d = {}: exact = {}, numerical = {}".format(d, RR(quadratic_L_function__exact(1, d)), RR(quadratic_L_function__numerical(1, d))))
"""
# Set the correct precision if it is given (for n).
if is_RealField(n.parent()):
if isinstance(n.parent(), sage.rings.abc.RealField):
R = n.parent()
else:
from sage.rings.real_mpfr import RealField
R = RealField()

if n < 0:
Expand Down
Loading

0 comments on commit ce8687b

Please sign in to comment.