From 608148900e8764bb654ddcdcdb15a1e890acba94 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 2 Oct 2021 10:17:24 -0700 Subject: [PATCH 01/17] git grep -l -E 'is_(Real|Complex)(Double)?Field' | xargs sed -E -i.bak 's/^from sage[.]rings.*import is_((Real|Complex)(Double)?Field) *$/import sage.rings.abc/;s/is_((Real|Complex)(Double)?Field)[(]([^)]*)[)]/isinstance(\4, sage.rings.abc.\1)/g;' --- .../arithmetic_dynamics/projective_ds.py | 2 +- src/sage/functions/orthogonal_polys.py | 12 +++--- src/sage/functions/special.py | 2 +- src/sage/matrix/misc.pyx | 2 +- src/sage/modular/dirichlet.py | 12 +++--- src/sage/modules/free_module.py | 4 +- src/sage/probability/random_variable.py | 2 +- src/sage/quadratic_forms/special_values.py | 4 +- src/sage/rings/complex_double.pyx | 6 +-- src/sage/rings/complex_mpfr.pyx | 4 +- src/sage/rings/number_field/number_field.py | 6 +-- .../number_field/number_field_element.pyx | 2 +- .../multi_polynomial_libsingular.pyx | 8 ++-- .../rings/polynomial/polynomial_element.pyx | 40 +++++++++---------- src/sage/rings/polynomial/polynomial_ring.py | 4 +- .../polynomial_singular_interface.py | 24 +++++------ src/sage/rings/real_double.pyx | 6 +-- src/sage/rings/real_mpfr.pyx | 6 +-- src/sage/schemes/elliptic_curves/ell_field.py | 8 ++-- .../elliptic_curves/ell_number_field.py | 2 +- src/sage/schemes/elliptic_curves/ell_point.py | 8 ++-- .../schemes/elliptic_curves/period_lattice.py | 14 +++---- src/sage/schemes/plane_conics/con_field.py | 8 ++-- .../plane_conics/con_rational_field.py | 6 +-- src/sage/symbolic/expression.pyx | 6 +-- 25 files changed, 99 insertions(+), 99 deletions(-) diff --git a/src/sage/dynamics/arithmetic_dynamics/projective_ds.py b/src/sage/dynamics/arithmetic_dynamics/projective_ds.py index 164c4c35f47..e5f2b9225cf 100644 --- a/src/sage/dynamics/arithmetic_dynamics/projective_ds.py +++ b/src/sage/dynamics/arithmetic_dynamics/projective_ds.py @@ -2065,7 +2065,7 @@ def canonical_height(self, P, **kwds): # 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. for v in emb: - if is_RealField(v.codomain()) or v.codomain() is RDF: + if isinstance(v.codomain(, sage.rings.abc.RealField)) or v.codomain() is RDF: dv = R.one() else: dv = R(2) diff --git a/src/sage/functions/orthogonal_polys.py b/src/sage/functions/orthogonal_polys.py index 9b5636f3fdc..c879cd6c8fe 100644 --- a/src/sage/functions/orthogonal_polys.py +++ b/src/sage/functions/orthogonal_polys.py @@ -304,8 +304,8 @@ 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 +import sage.rings.abc from sage.symbolic.function import BuiltinFunction, GinacFunction from sage.symbolic.expression import Expression @@ -672,7 +672,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) and not isinstance(real_parent, sage.rings.abc.ComplexField): # parent is not a real or complex field: figure out a good parent if x in RR: x = RR(x) @@ -681,7 +681,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) and not isinstance(real_parent, sage.rings.abc.ComplexField): raise TypeError("cannot evaluate chebyshev_T with parent {}".format(real_parent)) from sage.libs.mpmath.all import call as mpcall @@ -1031,7 +1031,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) and not isinstance(real_parent, sage.rings.abc.ComplexField): # parent is not a real or complex field: figure out a good parent if x in RR: x = RR(x) @@ -1040,7 +1040,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) and not isinstance(real_parent, sage.rings.abc.ComplexField): raise TypeError("cannot evaluate chebyshev_U with parent {}".format(real_parent)) from sage.libs.mpmath.all import call as mpcall diff --git a/src/sage/functions/special.py b/src/sage/functions/special.py index d48208a21d0..c409631f392 100644 --- a/src/sage/functions/special.py +++ b/src/sage/functions/special.py @@ -365,7 +365,7 @@ def elliptic_j(z, prec=53): CC = z.parent() from sage.rings.complex_mpfr import is_ComplexField - if not is_ComplexField(CC): + if not isinstance(CC, sage.rings.abc.ComplexField): CC = ComplexField(prec) try: z = CC(z) diff --git a/src/sage/matrix/misc.pyx b/src/sage/matrix/misc.pyx index 9008edf5920..a70a9a0f711 100644 --- a/src/sage/matrix/misc.pyx +++ b/src/sage/matrix/misc.pyx @@ -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(, sage.rings.abc.RealField)): raise TypeError("A must have base field an mpfr real field.") cdef RealNumber a, b diff --git a/src/sage/modular/dirichlet.py b/src/sage/modular/dirichlet.py index 53492ad517f..f71ef1e6f17 100644 --- a/src/sage/modular/dirichlet.py +++ b/src/sage/modular/dirichlet.py @@ -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 @@ -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] @@ -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 @@ -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 @@ -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)) @@ -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)) diff --git a/src/sage/modules/free_module.py b/src/sage/modules/free_module.py index 57c10114174..6288e77cf76 100644 --- a/src/sage/modules/free_module.py +++ b/src/sage/modules/free_module.py @@ -7443,9 +7443,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 sage.rings.real_double.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 sage.rings.complex_double.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 diff --git a/src/sage/probability/random_variable.py b/src/sage/probability/random_variable.py index 5355636aa56..ea2c4c86b2f 100644 --- a/src/sage/probability/random_variable.py +++ b/src/sage/probability/random_variable.py @@ -338,7 +338,7 @@ def __init__(self, X, P, codomain=None, check=False): """ if codomain is None: 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()) diff --git a/src/sage/quadratic_forms/special_values.py b/src/sage/quadratic_forms/special_values.py index 47f8ec3008f..5c7e3a1ccfe 100644 --- a/src/sage/quadratic_forms/special_values.py +++ b/src/sage/quadratic_forms/special_values.py @@ -15,7 +15,7 @@ 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 ------------------ @@ -278,7 +278,7 @@ 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: R = RealField() diff --git a/src/sage/rings/complex_double.pyx b/src/sage/rings/complex_double.pyx index 3c47faf4344..7621cc043c2 100644 --- a/src/sage/rings/complex_double.pyx +++ b/src/sage/rings/complex_double.pyx @@ -111,16 +111,16 @@ from sage.structure.richcmp cimport rich_to_bool cimport gmpy2 gmpy2.import_gmpy2() -def is_ComplexDoubleField(x): +def isinstance(x, sage.rings.abc.ComplexDoubleField): """ Return ``True`` if ``x`` is the complex double field. EXAMPLES:: sage: from sage.rings.complex_double import is_ComplexDoubleField - sage: is_ComplexDoubleField(CDF) + sage: isinstance(CDF, sage.rings.abc.ComplexDoubleField) True - sage: is_ComplexDoubleField(ComplexField(53)) + sage: isinstance(ComplexField(53, sage.rings.abc.ComplexDoubleField)) False """ return isinstance(x, ComplexDoubleField_class) diff --git a/src/sage/rings/complex_mpfr.pyx b/src/sage/rings/complex_mpfr.pyx index d121e29d537..d3d32b69de5 100644 --- a/src/sage/rings/complex_mpfr.pyx +++ b/src/sage/rings/complex_mpfr.pyx @@ -157,7 +157,7 @@ def is_ComplexNumber(x): """ return isinstance(x, ComplexNumber) -def is_ComplexField(x): +def isinstance(x, sage.rings.abc.ComplexField): """ Check if ``x`` is a :class:`complex field `. @@ -543,7 +543,7 @@ class ComplexField_class(ring.Field): RR = self._real_field() if RR.has_coerce_map_from(S): return RRtoCC(RR, self) * RR._internal_coerce_map_from(S) - if is_ComplexField(S): + if isinstance(S, sage.rings.abc.ComplexField): if self._prec <= S._prec: return self._generic_coerce_map(S) else: diff --git a/src/sage/rings/number_field/number_field.py b/src/sage/rings/number_field/number_field.py index 3ad7ffa26ef..bc626635105 100644 --- a/src/sage/rings/number_field/number_field.py +++ b/src/sage/rings/number_field/number_field.py @@ -9949,12 +9949,12 @@ def hilbert_symbol(self, a, b, P = None): from sage.rings.complex_interval_field import is_ComplexIntervalField from sage.rings.real_mpfr import is_RealField from sage.rings.all import (AA, CDF, QQbar, RDF) - if is_ComplexField(codom) or is_ComplexIntervalField(codom) or \ + if isinstance(codom, sage.rings.abc.ComplexField) or is_ComplexIntervalField(codom) or \ codom is CDF or codom is QQbar: if P(self.gen()).imag() == 0: raise ValueError("Possibly real place (=%s) given as complex embedding in hilbert_symbol. Is it real or complex?" % P) return 1 - if is_RealField(codom) or codom is RDF or codom is AA: + if isinstance(codom, sage.rings.abc.RealField) or codom is RDF or codom is AA: if P(a) > 0 or P(b) > 0: return 1 return -1 @@ -12317,7 +12317,7 @@ def refine_embedding(e, prec=None): return e # We first compute all the embeddings at the new precision: - if sage.rings.real_mpfr.is_RealField(RC) or RC in (RDF, RLF): + if sage.rings.real_mpfr.isinstance(RC, sage.rings.abc.RealField) or RC in (RDF, RLF): if prec == Infinity: elist = K.embeddings(sage.rings.qqbar.AA) else: diff --git a/src/sage/rings/number_field/number_field_element.pyx b/src/sage/rings/number_field/number_field_element.pyx index 37af865e4f5..4ee3d048f07 100644 --- a/src/sage/rings/number_field/number_field_element.pyx +++ b/src/sage/rings/number_field/number_field_element.pyx @@ -3946,7 +3946,7 @@ cdef class NumberFieldElement(FieldElement): return Kv.zero() ht = a.log() from sage.rings.real_mpfr import is_RealField - if weighted and not is_RealField(Kv): + if weighted and not isinstance(Kv, sage.rings.abc.RealField): ht*=2 return ht diff --git a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx index ec706f3129d..f32e42d83f3 100644 --- a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx @@ -224,8 +224,8 @@ from sage.rings.polynomial.polynomial_ring import is_PolynomialRing 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 -from sage.rings.complex_mpfr import is_ComplexField -from sage.rings.real_mpfr import is_RealField +import sage.rings.abc +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 @@ -1366,14 +1366,14 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): base_ring = self.base_ring() - if is_RealField(base_ring): + if isinstance(base_ring, sage.rings.abc.RealField): # singular converts to bits from base_10 in mpr_complex.cc by: # size_t bits = 1 + (size_t) ((float)digits * 3.5); precision = base_ring.precision() digits = ceil((2*precision - 2)/7.0) self.__singular = singular.ring("(real,%d,0)"%digits, _vars, order=order) - elif is_ComplexField(base_ring): + elif isinstance(base_ring, sage.rings.abc.ComplexField): # singular converts to bits from base_10 in mpr_complex.cc by: # size_t bits = 1 + (size_t) ((float)digits * 3.5); precision = base_ring.precision() diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index dabc030c828..70f026179a4 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -7912,25 +7912,25 @@ cdef class Polynomial(CommutativeAlgebraElement): late_import() - input_fp = (is_RealField(K) - or is_ComplexField(K) - or is_RealDoubleField(K) - or is_ComplexDoubleField(K)) - output_fp = (is_RealField(L) - or is_ComplexField(L) - or is_RealDoubleField(L) - or is_ComplexDoubleField(L)) - input_complex = (is_ComplexField(K) - or is_ComplexDoubleField(K)) - output_complex = (is_ComplexField(L) - or is_ComplexDoubleField(L)) + input_fp = (isinstance(K, sage.rings.abc.RealField) + or isinstance(K, sage.rings.abc.ComplexField) + or isinstance(K, sage.rings.abc.RealDoubleField) + or isinstance(K, sage.rings.abc.ComplexDoubleField)) + output_fp = (isinstance(L, sage.rings.abc.RealField) + or isinstance(L, sage.rings.abc.ComplexField) + or isinstance(L, sage.rings.abc.RealDoubleField) + or isinstance(L, sage.rings.abc.ComplexDoubleField)) + input_complex = (isinstance(K, sage.rings.abc.ComplexField) + or isinstance(K, sage.rings.abc.ComplexDoubleField)) + output_complex = (isinstance(L, sage.rings.abc.ComplexField) + or isinstance(L, sage.rings.abc.ComplexDoubleField)) input_gaussian = (isinstance(K, NumberField_quadratic) and list(K.polynomial()) == [1, 0, 1]) if input_fp and output_fp: # allow for possibly using a fast but less reliable # floating point algorithm from numpy - low_prec = is_RealDoubleField(K) or is_ComplexDoubleField(K) + low_prec = isinstance(K, sage.rings.abc.RealDoubleField) or isinstance(K, sage.rings.abc.ComplexDoubleField) if algorithm is None: if low_prec: algorithm = 'either' @@ -7943,8 +7943,8 @@ cdef class Polynomial(CommutativeAlgebraElement): # We should support GSL, too. We could also support PARI's # old Newton-iteration algorithm. - input_arbprec = (is_RealField(K) or - is_ComplexField(K)) + input_arbprec = (isinstance(K, sage.rings.abc.RealField) or + isinstance(K, sage.rings.abc.ComplexField)) if algorithm == 'numpy' or algorithm == 'either': if K.prec() > 53 and L.prec() > 53: @@ -8082,7 +8082,7 @@ cdef class Polynomial(CommutativeAlgebraElement): # If we want the complex roots, and the input is not # floating point, we convert to a real polynomial # (except when the input coefficients are Gaussian rationals). - if is_ComplexDoubleField(L): + if isinstance(L, sage.rings.abc.ComplexDoubleField): real_field = RDF else: real_field = RealField(L.prec()) @@ -8250,7 +8250,7 @@ cdef class Polynomial(CommutativeAlgebraElement): True """ K = self.base_ring() - if is_RealField(K) or is_RealDoubleField(K): + if isinstance(K, sage.rings.abc.RealField) or isinstance(K, sage.rings.abc.RealDoubleField): return self.roots(multiplicities=False) return self.roots(ring=RR, multiplicities=False) @@ -8292,11 +8292,11 @@ cdef class Polynomial(CommutativeAlgebraElement): True """ K = self.base_ring() - if is_RealField(K): + if isinstance(K, sage.rings.abc.RealField): return self.roots(ring=ComplexField(K.prec()), multiplicities=False) - if is_RealDoubleField(K): + if isinstance(K, sage.rings.abc.RealDoubleField): return self.roots(ring=CDF, multiplicities=False) - if is_ComplexField(K) or is_ComplexDoubleField(K): + if isinstance(K, sage.rings.abc.ComplexField) or isinstance(K, sage.rings.abc.ComplexDoubleField): return self.roots(multiplicities=False) return self.roots(ring=CC, multiplicities=False) diff --git a/src/sage/rings/polynomial/polynomial_ring.py b/src/sage/rings/polynomial/polynomial_ring.py index 7cef097c1a8..b480bd09ff0 100644 --- a/src/sage/rings/polynomial/polynomial_ring.py +++ b/src/sage/rings/polynomial/polynomial_ring.py @@ -165,7 +165,7 @@ from sage.misc.cachefunc import cached_method from sage.misc.lazy_attribute import lazy_attribute -from sage.rings.real_mpfr import is_RealField +import sage.rings.abc from sage.rings.fraction_field_element import FractionFieldElement from sage.rings.finite_rings.element_base import FiniteRingElement @@ -1995,7 +1995,7 @@ def __init__(self, base_ring, name="x", sparse=False, element_class=None, catego else: from sage.rings.polynomial.polynomial_number_field import Polynomial_relative_number_field_dense element_class = Polynomial_relative_number_field_dense - elif is_RealField(base_ring): + elif isinstance(base_ring, sage.rings.abc.RealField): element_class = PolynomialRealDense elif isinstance(base_ring, sage.rings.complex_arb.ComplexBallField): from sage.rings.polynomial.polynomial_complex_arb import Polynomial_complex_arb diff --git a/src/sage/rings/polynomial/polynomial_singular_interface.py b/src/sage/rings/polynomial/polynomial_singular_interface.py index 61777d5556a..256bb0997cc 100644 --- a/src/sage/rings/polynomial/polynomial_singular_interface.py +++ b/src/sage/rings/polynomial/polynomial_singular_interface.py @@ -41,11 +41,11 @@ import sage.rings.number_field as number_field from sage.interfaces.all import singular -from sage.rings.complex_mpfr import is_ComplexField -from sage.rings.real_mpfr import is_RealField -from sage.rings.complex_double import is_ComplexDoubleField +import sage.rings.abc +import sage.rings.abc +import sage.rings.abc from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing -from sage.rings.real_double import is_RealDoubleField +import sage.rings.abc from sage.rings.rational_field import is_RationalField from sage.rings.function_field.function_field import RationalFunctionField from sage.rings.finite_rings.finite_field_base import is_FiniteField @@ -257,26 +257,26 @@ def _singular_init_(self, singular=singular): base_ring = self.base_ring() - if is_RealField(base_ring): + if isinstance(base_ring, sage.rings.abc.RealField): # singular converts to bits from base_10 in mpr_complex.cc by: # size_t bits = 1 + (size_t) ((float)digits * 3.5); precision = base_ring.precision() digits = sage.arith.all.integer_ceil((2*precision - 2)/7.0) self.__singular = singular.ring("(real,%d,0)"%digits, _vars, order=order, check=False) - elif is_ComplexField(base_ring): + elif isinstance(base_ring, sage.rings.abc.ComplexField): # singular converts to bits from base_10 in mpr_complex.cc by: # size_t bits = 1 + (size_t) ((float)digits * 3.5); precision = base_ring.precision() digits = sage.arith.all.integer_ceil((2*precision - 2)/7.0) self.__singular = singular.ring("(complex,%d,0,I)"%digits, _vars, order=order, check=False) - elif is_RealDoubleField(base_ring): + elif isinstance(base_ring, sage.rings.abc.RealDoubleField): # singular converts to bits from base_10 in mpr_complex.cc by: # size_t bits = 1 + (size_t) ((float)digits * 3.5); self.__singular = singular.ring("(real,15,0)", _vars, order=order, check=False) - elif is_ComplexDoubleField(base_ring): + elif isinstance(base_ring, sage.rings.abc.ComplexDoubleField): # singular converts to bits from base_10 in mpr_complex.cc by: # size_t bits = 1 + (size_t) ((float)digits * 3.5); self.__singular = singular.ring("(complex,15,0,I)", _vars, order=order, check=False) @@ -389,10 +389,10 @@ def can_convert_to_singular(R): or sage.rings.finite_rings.finite_field_constructor.is_FiniteField(base_ring) or is_RationalField(base_ring) or is_IntegerModRing(base_ring) - or is_RealField(base_ring) - or is_ComplexField(base_ring) - or is_RealDoubleField(base_ring) - or is_ComplexDoubleField(base_ring)): + or isinstance(base_ring, sage.rings.abc.RealField) + or isinstance(base_ring, sage.rings.abc.ComplexField) + or isinstance(base_ring, sage.rings.abc.RealDoubleField) + or isinstance(base_ring, sage.rings.abc.ComplexDoubleField)): return True elif base_ring.is_prime_field(): return base_ring.characteristic() <= 2147483647 diff --git a/src/sage/rings/real_double.pyx b/src/sage/rings/real_double.pyx index a967e8f9e7e..750adf89b72 100644 --- a/src/sage/rings/real_double.pyx +++ b/src/sage/rings/real_double.pyx @@ -73,16 +73,16 @@ from sage.arith.constants cimport * cimport gmpy2 -def is_RealDoubleField(x): +def isinstance(x, sage.rings.abc.RealDoubleField): """ Returns ``True`` if ``x`` is the field of real double precision numbers. EXAMPLES:: sage: from sage.rings.real_double import is_RealDoubleField - sage: is_RealDoubleField(RDF) + sage: isinstance(RDF, sage.rings.abc.RealDoubleField) True - sage: is_RealDoubleField(RealField(53)) + sage: isinstance(RealField(53, sage.rings.abc.RealDoubleField)) False """ return isinstance(x, RealDoubleField_class) diff --git a/src/sage/rings/real_mpfr.pyx b/src/sage/rings/real_mpfr.pyx index 69568a5fb9d..cb9851fc8f9 100644 --- a/src/sage/rings/real_mpfr.pyx +++ b/src/sage/rings/real_mpfr.pyx @@ -5896,15 +5896,15 @@ def create_RealNumber(s, int base=10, int pad=0, rnd="RNDN", int min_prec=53): return RealLiteral(R, s, base) -def is_RealField(x): +def isinstance(x, sage.rings.abc.RealField): """ Returns ``True`` if ``x`` is technically of a Python real field type. EXAMPLES:: - sage: sage.rings.real_mpfr.is_RealField(RR) + sage: sage.rings.real_mpfr.isinstance(RR, sage.rings.abc.RealField) True - sage: sage.rings.real_mpfr.is_RealField(CC) + sage: sage.rings.real_mpfr.isinstance(CC, sage.rings.abc.RealField) False """ return isinstance(x, RealField_class) diff --git a/src/sage/schemes/elliptic_curves/ell_field.py b/src/sage/schemes/elliptic_curves/ell_field.py index bd7a8027b0c..55bd2790b08 100644 --- a/src/sage/schemes/elliptic_curves/ell_field.py +++ b/src/sage/schemes/elliptic_curves/ell_field.py @@ -13,8 +13,8 @@ #***************************************************************************** import sage.rings.all as rings -from sage.rings.complex_mpfr import is_ComplexField -from sage.rings.real_mpfr import is_RealField +import sage.rings.abc +import sage.rings.abc from sage.schemes.elliptic_curves.ell_point import EllipticCurvePoint_field from sage.schemes.curves.projective_curve import ProjectivePlaneCurve_field @@ -1069,9 +1069,9 @@ def isogenies_prime_degree(self, l=None, max_l=31): ValueError: 4 is not prime. """ F = self.base_ring() - if is_RealField(F): + if isinstance(F, sage.rings.abc.RealField): raise NotImplementedError("This code could be implemented for general real fields, but has not been yet.") - if is_ComplexField(F): + if isinstance(F, sage.rings.abc.ComplexField): raise NotImplementedError("This code could be implemented for general complex fields, but has not been yet.") if F is rings.QQbar: raise NotImplementedError("This code could be implemented for QQbar, but has not been yet.") diff --git a/src/sage/schemes/elliptic_curves/ell_number_field.py b/src/sage/schemes/elliptic_curves/ell_number_field.py index 821d2e96639..322b24f9540 100644 --- a/src/sage/schemes/elliptic_curves/ell_number_field.py +++ b/src/sage/schemes/elliptic_curves/ell_number_field.py @@ -2616,7 +2616,7 @@ def real_components(self, embedding): try: if not embedding.domain() is self.base_field(): raise ValueError("invalid embedding specified: should have domain {}".format(self.base_field())) - if not is_RealField(embedding.codomain()): + if not isinstance(embedding.codomain(, sage.rings.abc.RealField)): raise ValueError("invalid embedding specified: should be real") except AttributeError: raise ValueError("invalid embedding") diff --git a/src/sage/schemes/elliptic_curves/ell_point.py b/src/sage/schemes/elliptic_curves/ell_point.py index 7edafee118a..068ea589b3d 100644 --- a/src/sage/schemes/elliptic_curves/ell_point.py +++ b/src/sage/schemes/elliptic_curves/ell_point.py @@ -125,7 +125,7 @@ from sage.rings.padics.precision_error import PrecisionError import sage.rings.all as rings -from sage.rings.real_mpfr import is_RealField +import sage.rings.abc from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ import sage.groups.generic as generic @@ -2219,7 +2219,7 @@ def is_on_identity_component(self, embedding=None): e = embedding # It is also trivially true if we have a complex embedding if e is not None: - if not is_RealField(e.codomain()): + if not isinstance(e.codomain(, sage.rings.abc.RealField)): return True # find a suitable embedding if none was supplied: @@ -2232,7 +2232,7 @@ def is_on_identity_component(self, embedding=None): e = K.embeddings(rings.ComplexField())[0] # If there is only one component, the result is True: - if not is_RealField(e.codomain()): # complex embedding + if not isinstance(e.codomain(, sage.rings.abc.RealField)): # complex embedding return True if e(E.discriminant()) < 0: # only one component return True @@ -3237,7 +3237,7 @@ def elliptic_logarithm(self, embedding=None, precision=100, L = E.period_lattice(emb) - if algorithm == 'sage' or not is_RealField(emb.codomain): + if algorithm == 'sage' or not isinstance(emb.codomain, sage.rings.abc.RealField): return L.elliptic_logarithm(self, precision) if algorithm != 'pari': diff --git a/src/sage/schemes/elliptic_curves/period_lattice.py b/src/sage/schemes/elliptic_curves/period_lattice.py index fe1899f647c..974f560c4db 100644 --- a/src/sage/schemes/elliptic_curves/period_lattice.py +++ b/src/sage/schemes/elliptic_curves/period_lattice.py @@ -100,7 +100,7 @@ from sage.modules.free_module import FreeModule_generic_pid from sage.rings.all import ZZ, QQ, RealField, ComplexField, QQbar, AA -from sage.rings.real_mpfr import is_RealField +import sage.rings.abc from sage.rings.complex_mpfr import ComplexNumber, is_ComplexField from sage.rings.real_mpfr import RealNumber as RealNumber from sage.rings.number_field.number_field import refine_embedding @@ -1169,11 +1169,11 @@ def coordinates(self, z, rounding=None): (12, 23) """ C = z.parent() - if is_RealField(C): + if isinstance(C, sage.rings.abc.RealField): C = ComplexField(C.precision()) z = C(z) else: - if is_ComplexField(C): + if isinstance(C, sage.rings.abc.ComplexField): pass else: try: @@ -1233,10 +1233,10 @@ def reduce(self, z): 0.958696500380444 """ C = z.parent() - if is_RealField(C): + if isinstance(C, sage.rings.abc.RealField): C = ComplexField(C.precision()) z = C(z) - elif is_ComplexField(C): + elif isinstance(C, sage.rings.abc.ComplexField): pass else: try: @@ -1789,12 +1789,12 @@ def elliptic_exponential(self, z, to_curve=True): """ C = z.parent() z_is_real = False - if is_RealField(C): + if isinstance(C, sage.rings.abc.RealField): z_is_real = True C = ComplexField(C.precision()) z = C(z) else: - if is_ComplexField(C): + if isinstance(C, sage.rings.abc.ComplexField): z_is_real = z.is_real() else: try: diff --git a/src/sage/schemes/plane_conics/con_field.py b/src/sage/schemes/plane_conics/con_field.py index 04ee419f880..ad2273cc99d 100644 --- a/src/sage/schemes/plane_conics/con_field.py +++ b/src/sage/schemes/plane_conics/con_field.py @@ -26,8 +26,8 @@ from sage.rings.all import PolynomialRing -from sage.rings.complex_mpfr import is_ComplexField -from sage.rings.real_mpfr import is_RealField +import sage.rings.abc +import sage.rings.abc from sage.modules.free_module_element import vector from sage.structure.sequence import Sequence @@ -517,7 +517,7 @@ def has_rational_point(self, point = False, if algorithm != 'default': raise ValueError("Unknown algorithm: %s" % algorithm) - if is_ComplexField(B): + if isinstance(B, sage.rings.abc.ComplexField): if point: [_,_,_,d,e,f] = self._coefficients if d == 0: @@ -525,7 +525,7 @@ def has_rational_point(self, point = False, return True, self.point([0, ((e**2-4*d*f).sqrt()-e)/(2*d), 1], check = False) return True - if is_RealField(B): + if isinstance(B, sage.rings.abc.RealField): D, T = self.diagonal_matrix() [a, b, c] = [D[0,0], D[1,1], D[2,2]] if a == 0: diff --git a/src/sage/schemes/plane_conics/con_rational_field.py b/src/sage/schemes/plane_conics/con_rational_field.py index e8b1d824cbd..4ff7cc39a61 100644 --- a/src/sage/schemes/plane_conics/con_rational_field.py +++ b/src/sage/schemes/plane_conics/con_rational_field.py @@ -26,7 +26,7 @@ from sage.rings.all import (PolynomialRing, ZZ, QQ) -from sage.rings.real_mpfr import is_RealField +import sage.rings.abc from sage.structure.sequence import Sequence from sage.schemes.projective.projective_space import ProjectiveSpace @@ -230,11 +230,11 @@ def is_locally_solvable(self, p) -> bool: return True a = -abc[0] / abc[2] b = -abc[1] / abc[2] - if is_RealField(p) or isinstance(p, InfinityElement): + if isinstance(p, sage.rings.abc.RealField) or isinstance(p, InfinityElement): p = -1 elif isinstance(p, Map) and p.category_for().is_subcategory(Rings()): # p is a morphism of Rings - if p.domain() is QQ and is_RealField(p.codomain()): + if p.domain() is QQ and isinstance(p.codomain(, sage.rings.abc.RealField)): p = -1 else: raise TypeError("p (=%s) needs to be a prime of base field " diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx index de4720f90a7..beab2ce78ca 100644 --- a/src/sage/symbolic/expression.pyx +++ b/src/sage/symbolic/expression.pyx @@ -395,7 +395,7 @@ from sage.misc.latex import latex_variable_name from sage.rings.infinity import AnInfinity, infinity, minus_infinity, unsigned_infinity from sage.rings.integer_ring import ZZ from sage.rings.real_mpfr import RR -from sage.rings.complex_mpfr import is_ComplexField +import sage.rings.abc from sage.misc.decorators import rename_keyword from sage.structure.dynamic_class import dynamic_class from sage.structure.element cimport CommutativeRingElement @@ -13830,7 +13830,7 @@ cdef unsigned sage_domain_to_ginac_domain(object domain) except? 3474701533: return domain_real elif domain == 'positive': return domain_positive - elif is_ComplexField(domain) or domain == 'complex': + elif isinstance(domain, sage.rings.abc.ComplexField) or domain == 'complex': return domain_complex elif domain is ZZ or domain == 'integer': return domain_integer @@ -13844,7 +13844,7 @@ cdef void send_sage_domain_to_maxima(Expression v, object domain) except +: assume(v, 'real') elif domain == 'positive': assume(v>0) - elif is_ComplexField(domain) or domain == 'complex': + elif isinstance(domain, sage.rings.abc.ComplexField) or domain == 'complex': assume(v, 'complex') elif domain is ZZ or domain == 'integer': assume(v, 'integer') From 28e328a995088c574c1e1ab3fc31f613d273b725 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 2 Oct 2021 11:05:20 -0700 Subject: [PATCH 02/17] Remove repeated imports of sage.rings.abc --- src/sage/functions/orthogonal_polys.py | 1 - src/sage/modules/free_module.py | 4 ++-- src/sage/rings/polynomial/multi_polynomial_libsingular.pyx | 1 - src/sage/rings/polynomial/polynomial_singular_interface.py | 3 --- src/sage/schemes/elliptic_curves/ell_field.py | 1 - src/sage/schemes/plane_conics/con_field.py | 1 - 6 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/sage/functions/orthogonal_polys.py b/src/sage/functions/orthogonal_polys.py index c879cd6c8fe..67c0381b541 100644 --- a/src/sage/functions/orthogonal_polys.py +++ b/src/sage/functions/orthogonal_polys.py @@ -305,7 +305,6 @@ from sage.rings.all import ZZ, QQ, RR, CC from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing import sage.rings.abc -import sage.rings.abc from sage.symbolic.function import BuiltinFunction, GinacFunction from sage.symbolic.expression import Expression diff --git a/src/sage/modules/free_module.py b/src/sage/modules/free_module.py index 6288e77cf76..57c10114174 100644 --- a/src/sage/modules/free_module.py +++ b/src/sage/modules/free_module.py @@ -7443,9 +7443,9 @@ def element_class(R, is_sparse): return Vector_modn_dense else: return free_module_element.FreeModuleElement_generic_dense - elif sage.rings.real_double.isinstance(R, sage.rings.abc.RealDoubleField) and not is_sparse: + elif sage.rings.real_double.is_RealDoubleField(R) and not is_sparse: return sage.modules.vector_real_double_dense.Vector_real_double_dense - elif sage.rings.complex_double.isinstance(R, sage.rings.abc.ComplexDoubleField) and not is_sparse: + elif sage.rings.complex_double.is_ComplexDoubleField(R) 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 diff --git a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx index f32e42d83f3..03f8015f7ea 100644 --- a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx @@ -225,7 +225,6 @@ from sage.rings.finite_rings.finite_field_prime_modn import FiniteField_prime_mo from sage.rings.rational cimport Rational from sage.rings.rational_field import QQ import sage.rings.abc -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 diff --git a/src/sage/rings/polynomial/polynomial_singular_interface.py b/src/sage/rings/polynomial/polynomial_singular_interface.py index 256bb0997cc..0a472405790 100644 --- a/src/sage/rings/polynomial/polynomial_singular_interface.py +++ b/src/sage/rings/polynomial/polynomial_singular_interface.py @@ -42,10 +42,7 @@ from sage.interfaces.all import singular import sage.rings.abc -import sage.rings.abc -import sage.rings.abc from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing -import sage.rings.abc from sage.rings.rational_field import is_RationalField from sage.rings.function_field.function_field import RationalFunctionField from sage.rings.finite_rings.finite_field_base import is_FiniteField diff --git a/src/sage/schemes/elliptic_curves/ell_field.py b/src/sage/schemes/elliptic_curves/ell_field.py index 55bd2790b08..d972c4e1fc9 100644 --- a/src/sage/schemes/elliptic_curves/ell_field.py +++ b/src/sage/schemes/elliptic_curves/ell_field.py @@ -14,7 +14,6 @@ import sage.rings.all as rings import sage.rings.abc -import sage.rings.abc from sage.schemes.elliptic_curves.ell_point import EllipticCurvePoint_field from sage.schemes.curves.projective_curve import ProjectivePlaneCurve_field diff --git a/src/sage/schemes/plane_conics/con_field.py b/src/sage/schemes/plane_conics/con_field.py index ad2273cc99d..0d5eb412034 100644 --- a/src/sage/schemes/plane_conics/con_field.py +++ b/src/sage/schemes/plane_conics/con_field.py @@ -26,7 +26,6 @@ from sage.rings.all import PolynomialRing -import sage.rings.abc import sage.rings.abc from sage.modules.free_module_element import vector From 45cc21ad1afb7c06cc2a61a65adeeb9b2e8664f9 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 2 Oct 2021 11:07:17 -0700 Subject: [PATCH 03/17] is_Real[Double]Field, is_Complex[Double]Field: Undo automatic edits, deprecate --- src/sage/rings/complex_double.pyx | 12 +++++++++--- src/sage/rings/complex_mpfr.pyx | 11 +++++++++-- src/sage/rings/real_double.pyx | 12 +++++++++--- src/sage/rings/real_mpfr.pyx | 12 +++++++++--- 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/sage/rings/complex_double.pyx b/src/sage/rings/complex_double.pyx index 7621cc043c2..a1a2ae29a29 100644 --- a/src/sage/rings/complex_double.pyx +++ b/src/sage/rings/complex_double.pyx @@ -111,18 +111,24 @@ from sage.structure.richcmp cimport rich_to_bool cimport gmpy2 gmpy2.import_gmpy2() -def isinstance(x, sage.rings.abc.ComplexDoubleField): + +def is_ComplexDoubleField(x): """ Return ``True`` if ``x`` is the complex double field. + This function is deprecated. Use :func:`isinstance` with + :class:`~sage.rings.abc.ComplexDoubleField` instead. + EXAMPLES:: sage: from sage.rings.complex_double import is_ComplexDoubleField - sage: isinstance(CDF, sage.rings.abc.ComplexDoubleField) + sage: is_ComplexDoubleField(CDF) True - sage: isinstance(ComplexField(53, sage.rings.abc.ComplexDoubleField)) + sage: is_ComplexDoubleField(ComplexField(53)) False """ + from sage.misc.superseded import deprecation + deprecation(32610, 'is_ComplexDoubleField is deprecated; use isinstance(..., sage.rings.abc.ComplexDoubleField) instead') return isinstance(x, ComplexDoubleField_class) diff --git a/src/sage/rings/complex_mpfr.pyx b/src/sage/rings/complex_mpfr.pyx index d3d32b69de5..e3d73b4a268 100644 --- a/src/sage/rings/complex_mpfr.pyx +++ b/src/sage/rings/complex_mpfr.pyx @@ -157,10 +157,14 @@ def is_ComplexNumber(x): """ return isinstance(x, ComplexNumber) -def isinstance(x, sage.rings.abc.ComplexField): + +def is_ComplexField(x): """ Check if ``x`` is a :class:`complex field `. + This function is deprecated. Use :func:`isinstance` with + :class:`~sage.rings.abc.ComplexField` instead. + EXAMPLES:: sage: from sage.rings.complex_mpfr import is_ComplexField as is_CF @@ -171,8 +175,11 @@ def isinstance(x, sage.rings.abc.ComplexField): sage: is_CF(CC) True """ + from sage.misc.superseded import deprecation + deprecation(32610, 'is_ComplexField is deprecated; use isinstance(..., sage.rings.abc.ComplexField) instead') return isinstance(x, ComplexField_class) + cache = {} def ComplexField(prec=53, names=None): """ @@ -543,7 +550,7 @@ class ComplexField_class(ring.Field): RR = self._real_field() if RR.has_coerce_map_from(S): return RRtoCC(RR, self) * RR._internal_coerce_map_from(S) - if isinstance(S, sage.rings.abc.ComplexField): + if isinstance(S, ComplexField_class): if self._prec <= S._prec: return self._generic_coerce_map(S) else: diff --git a/src/sage/rings/real_double.pyx b/src/sage/rings/real_double.pyx index 750adf89b72..5be63115735 100644 --- a/src/sage/rings/real_double.pyx +++ b/src/sage/rings/real_double.pyx @@ -73,20 +73,26 @@ from sage.arith.constants cimport * cimport gmpy2 -def isinstance(x, sage.rings.abc.RealDoubleField): +def is_RealDoubleField(x): """ Returns ``True`` if ``x`` is the field of real double precision numbers. + This function is deprecated. Use :func:`isinstance` with + :class:`~sage.rings.abc.RealDoubleField` instead. + EXAMPLES:: sage: from sage.rings.real_double import is_RealDoubleField - sage: isinstance(RDF, sage.rings.abc.RealDoubleField) + sage: is_RealDoubleField(RDF) True - sage: isinstance(RealField(53, sage.rings.abc.RealDoubleField)) + sage: is_RealDoubleField(RealField(53)) False """ + from sage.misc.superseded import deprecation + deprecation(32610, 'is_RealDoubleField is deprecated; use isinstance(..., sage.rings.abc.RealDoubleField) instead') return isinstance(x, RealDoubleField_class) + cdef class RealDoubleField_class(Field): """ An approximation to the field of real numbers using double diff --git a/src/sage/rings/real_mpfr.pyx b/src/sage/rings/real_mpfr.pyx index cb9851fc8f9..f0d2eb5919b 100644 --- a/src/sage/rings/real_mpfr.pyx +++ b/src/sage/rings/real_mpfr.pyx @@ -5896,19 +5896,25 @@ def create_RealNumber(s, int base=10, int pad=0, rnd="RNDN", int min_prec=53): return RealLiteral(R, s, base) -def isinstance(x, sage.rings.abc.RealField): +def is_RealField(x): """ Returns ``True`` if ``x`` is technically of a Python real field type. + This function is deprecated. Use :func:`isinstance` with + :class:`~sage.rings.abc.RealField` instead. + EXAMPLES:: - sage: sage.rings.real_mpfr.isinstance(RR, sage.rings.abc.RealField) + sage: sage.rings.real_mpfr.is_RealField(RR) True - sage: sage.rings.real_mpfr.isinstance(CC, sage.rings.abc.RealField) + sage: sage.rings.real_mpfr.is_RealField(CC) False """ + from sage.misc.superseded import deprecation + deprecation(32610, 'is_RealField is deprecated; use isinstance(..., sage.rings.abc.RealField) instead') return isinstance(x, RealField_class) + def is_RealNumber(x): """ Return ``True`` if ``x`` is of type :class:`RealNumber`, meaning that it From e003603ebb665c064a459f55b9ad4731d9900424 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 2 Oct 2021 11:08:33 -0700 Subject: [PATCH 04/17] sage.dynamics: Fix up replacement of is_{Real,Complex}[Double]Field --- src/sage/dynamics/arithmetic_dynamics/projective_ds.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/sage/dynamics/arithmetic_dynamics/projective_ds.py b/src/sage/dynamics/arithmetic_dynamics/projective_ds.py index e5f2b9225cf..3c56fd3885b 100644 --- a/src/sage/dynamics/arithmetic_dynamics/projective_ds.py +++ b/src/sage/dynamics/arithmetic_dynamics/projective_ds.py @@ -88,8 +88,8 @@ class initialization directly. 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 ( @@ -2062,10 +2062,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 isinstance(v.codomain(, sage.rings.abc.RealField)) or v.codomain() is RDF: + if isinstance(v.codomain(), (sage.rings.abc.RealField, sage.rings.abc.RealDoubleField)): dv = R.one() else: dv = R(2) From 4adc553551b756d2cb177055359a55c6bd4691e6 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 2 Oct 2021 11:08:50 -0700 Subject: [PATCH 05/17] sage.functions: Fix up replacement of is_{Real,Complex}[Double]Field --- src/sage/functions/orthogonal_polys.py | 8 ++++---- src/sage/functions/special.py | 4 +--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/sage/functions/orthogonal_polys.py b/src/sage/functions/orthogonal_polys.py index 67c0381b541..0e965c57da6 100644 --- a/src/sage/functions/orthogonal_polys.py +++ b/src/sage/functions/orthogonal_polys.py @@ -671,7 +671,7 @@ def _evalf_(self, n, x, **kwds): except KeyError: real_parent = parent(x) - if not isinstance(real_parent, sage.rings.abc.RealField) and not isinstance(real_parent, sage.rings.abc.ComplexField): + 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) @@ -680,7 +680,7 @@ def _evalf_(self, n, x, **kwds): x = CC(x) real_parent = CC - if not isinstance(real_parent, sage.rings.abc.RealField) and not isinstance(real_parent, sage.rings.abc.ComplexField): + 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 @@ -1030,7 +1030,7 @@ def _evalf_(self, n, x, **kwds): except KeyError: real_parent = parent(x) - if not isinstance(real_parent, sage.rings.abc.RealField) and not isinstance(real_parent, sage.rings.abc.ComplexField): + 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) @@ -1039,7 +1039,7 @@ def _evalf_(self, n, x, **kwds): x = CC(x) real_parent = CC - if not isinstance(real_parent, sage.rings.abc.RealField) and not isinstance(real_parent, sage.rings.abc.ComplexField): + 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 diff --git a/src/sage/functions/special.py b/src/sage/functions/special.py index c409631f392..bc43c362141 100644 --- a/src/sage/functions/special.py +++ b/src/sage/functions/special.py @@ -159,7 +159,6 @@ # **************************************************************************** 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 @@ -362,10 +361,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 isinstance(CC, sage.rings.abc.ComplexField): + from sage.rings.complex_mpfr import ComplexField CC = ComplexField(prec) try: z = CC(z) From 5b988c69369a02eea230d61303742195f3ba4a36 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 2 Oct 2021 11:09:11 -0700 Subject: [PATCH 06/17] sage.schemes: Fix up replacement of is_{Real,Complex}[Double]Field --- src/sage/schemes/elliptic_curves/ell_number_field.py | 3 +-- src/sage/schemes/elliptic_curves/ell_point.py | 4 ++-- src/sage/schemes/elliptic_curves/period_lattice.py | 2 +- src/sage/schemes/plane_conics/con_rational_field.py | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/sage/schemes/elliptic_curves/ell_number_field.py b/src/sage/schemes/elliptic_curves/ell_number_field.py index 322b24f9540..f0bcda573df 100644 --- a/src/sage/schemes/elliptic_curves/ell_number_field.py +++ b/src/sage/schemes/elliptic_curves/ell_number_field.py @@ -2612,11 +2612,10 @@ def real_components(self, embedding): ... ValueError: invalid embedding specified: should have domain ... """ - from sage.rings.real_mpfr import is_RealField try: if not embedding.domain() is self.base_field(): raise ValueError("invalid embedding specified: should have domain {}".format(self.base_field())) - if not isinstance(embedding.codomain(, sage.rings.abc.RealField)): + if not isinstance(embedding.codomain(), sage.rings.abc.RealField): raise ValueError("invalid embedding specified: should be real") except AttributeError: raise ValueError("invalid embedding") diff --git a/src/sage/schemes/elliptic_curves/ell_point.py b/src/sage/schemes/elliptic_curves/ell_point.py index 068ea589b3d..63b027eae62 100644 --- a/src/sage/schemes/elliptic_curves/ell_point.py +++ b/src/sage/schemes/elliptic_curves/ell_point.py @@ -2219,7 +2219,7 @@ def is_on_identity_component(self, embedding=None): e = embedding # It is also trivially true if we have a complex embedding if e is not None: - if not isinstance(e.codomain(, sage.rings.abc.RealField)): + if not isinstance(e.codomain(), sage.rings.abc.RealField): return True # find a suitable embedding if none was supplied: @@ -2232,7 +2232,7 @@ def is_on_identity_component(self, embedding=None): e = K.embeddings(rings.ComplexField())[0] # If there is only one component, the result is True: - if not isinstance(e.codomain(, sage.rings.abc.RealField)): # complex embedding + if not isinstance(e.codomain(), sage.rings.abc.RealField): # complex embedding return True if e(E.discriminant()) < 0: # only one component return True diff --git a/src/sage/schemes/elliptic_curves/period_lattice.py b/src/sage/schemes/elliptic_curves/period_lattice.py index 974f560c4db..01a96c37627 100644 --- a/src/sage/schemes/elliptic_curves/period_lattice.py +++ b/src/sage/schemes/elliptic_curves/period_lattice.py @@ -101,7 +101,7 @@ from sage.modules.free_module import FreeModule_generic_pid from sage.rings.all import ZZ, QQ, RealField, ComplexField, QQbar, AA import sage.rings.abc -from sage.rings.complex_mpfr import ComplexNumber, is_ComplexField +from sage.rings.complex_mpfr import ComplexNumber from sage.rings.real_mpfr import RealNumber as RealNumber from sage.rings.number_field.number_field import refine_embedding from sage.rings.infinity import Infinity diff --git a/src/sage/schemes/plane_conics/con_rational_field.py b/src/sage/schemes/plane_conics/con_rational_field.py index 4ff7cc39a61..d24bd59898c 100644 --- a/src/sage/schemes/plane_conics/con_rational_field.py +++ b/src/sage/schemes/plane_conics/con_rational_field.py @@ -234,7 +234,7 @@ def is_locally_solvable(self, p) -> bool: p = -1 elif isinstance(p, Map) and p.category_for().is_subcategory(Rings()): # p is a morphism of Rings - if p.domain() is QQ and isinstance(p.codomain(, sage.rings.abc.RealField)): + if p.domain() is QQ and isinstance(p.codomain(), sage.rings.abc.RealField): p = -1 else: raise TypeError("p (=%s) needs to be a prime of base field " From 402dbec95818340a31e0b1d1790fc5ba31690480 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 2 Oct 2021 11:10:11 -0700 Subject: [PATCH 07/17] sage.rings.number_field: Fix up replacement of is_{Real,Complex}[Double]Field --- src/sage/rings/number_field/number_field.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/sage/rings/number_field/number_field.py b/src/sage/rings/number_field/number_field.py index bc626635105..863fbd8aad8 100644 --- a/src/sage/rings/number_field/number_field.py +++ b/src/sage/rings/number_field/number_field.py @@ -9945,16 +9945,14 @@ def hilbert_symbol(self, a, b, P = None): if P.domain() is not self: raise ValueError("Domain of P (=%s) should be self (=%s) in self.hilbert_symbol" % (P, self)) codom = P.codomain() - from sage.rings.complex_mpfr import is_ComplexField from sage.rings.complex_interval_field import is_ComplexIntervalField - from sage.rings.real_mpfr import is_RealField - from sage.rings.all import (AA, CDF, QQbar, RDF) - if isinstance(codom, sage.rings.abc.ComplexField) or is_ComplexIntervalField(codom) or \ - codom is CDF or codom is QQbar: + from sage.rings.all import (AA, QQbar) + if isinstance(codom, (sage.rings.abc.ComplexField, sage.rings.abc.ComplexDoubleField) or is_ComplexIntervalField(codom) or \ + codom is QQbar: if P(self.gen()).imag() == 0: raise ValueError("Possibly real place (=%s) given as complex embedding in hilbert_symbol. Is it real or complex?" % P) return 1 - if isinstance(codom, sage.rings.abc.RealField) or codom is RDF or codom is AA: + if isinstance(codom, (sage.rings.abc.RealField, sage.rings.abc.RealDoubleField) or codom is AA: if P(a) > 0 or P(b) > 0: return 1 return -1 @@ -12317,7 +12315,7 @@ def refine_embedding(e, prec=None): return e # We first compute all the embeddings at the new precision: - if sage.rings.real_mpfr.isinstance(RC, sage.rings.abc.RealField) or RC in (RDF, RLF): + if isinstance(RC, (sage.rings.abc.RealField, sage.rings.abc.RealDoubleField)) or RC == RLF: if prec == Infinity: elist = K.embeddings(sage.rings.qqbar.AA) else: From e82709c128895eb1d9c0d127ee878c2830ffaef3 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 2 Oct 2021 11:10:24 -0700 Subject: [PATCH 08/17] sage.rings.polynomial: Fix up replacement of is_{Real,Complex}[Double]Field --- .../rings/polynomial/polynomial_element.pyx | 36 ++++++++----------- .../polynomial_singular_interface.py | 6 ++-- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index 70f026179a4..add33c68590 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -51,7 +51,7 @@ TESTS:: # https://www.gnu.org/licenses/ # **************************************************************************** -cdef is_FractionField, is_RealField, is_ComplexField +cdef is_FractionField cdef ZZ, QQ, RR, CC, RDF, CDF cimport cython @@ -64,6 +64,7 @@ import re from sage.cpython.wrapperdescr cimport wrapperdescr_fastcall import sage.rings.rational import sage.rings.integer +import sage.rings.abc from . import polynomial_ring import sage.rings.integer_ring import sage.rings.rational_field @@ -84,13 +85,13 @@ from sage.structure.richcmp cimport (richcmp, richcmp_item, from sage.interfaces.singular import singular as singular_default, is_SingularElement from sage.libs.all import pari, pari_gen, PariError -from sage.rings.real_mpfr import RealField, is_RealField, RR +from sage.rings.real_mpfr import RealField, RR -from sage.rings.complex_mpfr import is_ComplexField, ComplexField +from sage.rings.complex_mpfr import ComplexField CC = ComplexField() -from sage.rings.real_double import is_RealDoubleField, RDF -from sage.rings.complex_double import is_ComplexDoubleField, CDF +from sage.rings.real_double import RDF +from sage.rings.complex_double import CDF from sage.rings.real_mpfi import is_RealIntervalField from sage.structure.coerce cimport coercion_model @@ -7912,18 +7913,12 @@ cdef class Polynomial(CommutativeAlgebraElement): late_import() - input_fp = (isinstance(K, sage.rings.abc.RealField) - or isinstance(K, sage.rings.abc.ComplexField) - or isinstance(K, sage.rings.abc.RealDoubleField) - or isinstance(K, sage.rings.abc.ComplexDoubleField)) - output_fp = (isinstance(L, sage.rings.abc.RealField) - or isinstance(L, sage.rings.abc.ComplexField) - or isinstance(L, sage.rings.abc.RealDoubleField) - or isinstance(L, sage.rings.abc.ComplexDoubleField)) - input_complex = (isinstance(K, sage.rings.abc.ComplexField) - or isinstance(K, sage.rings.abc.ComplexDoubleField)) - output_complex = (isinstance(L, sage.rings.abc.ComplexField) - or isinstance(L, sage.rings.abc.ComplexDoubleField)) + input_fp = isinstance(K, (sage.rings.abc.RealField, sage.rings.abc.ComplexField, + sage.rings.abc.RealDoubleField, sage.rings.abc.ComplexDoubleField)) + output_fp = isinstance(L, (sage.rings.abc.RealField, sage.rings.abc.ComplexField, + sage.rings.abc.RealDoubleField, sage.rings.abc.ComplexDoubleField)) + input_complex = isinstance(K, (sage.rings.abc.ComplexField, sage.rings.abc.ComplexDoubleField)) + output_complex = isinstance(L, (sage.rings.abc.ComplexField, sage.rings.abc.ComplexDoubleField)) input_gaussian = (isinstance(K, NumberField_quadratic) and list(K.polynomial()) == [1, 0, 1]) @@ -7943,8 +7938,7 @@ cdef class Polynomial(CommutativeAlgebraElement): # We should support GSL, too. We could also support PARI's # old Newton-iteration algorithm. - input_arbprec = (isinstance(K, sage.rings.abc.RealField) or - isinstance(K, sage.rings.abc.ComplexField)) + input_arbprec = isinstance(K, (sage.rings.abc.RealField, sage.rings.abc.ComplexField)) if algorithm == 'numpy' or algorithm == 'either': if K.prec() > 53 and L.prec() > 53: @@ -8250,7 +8244,7 @@ cdef class Polynomial(CommutativeAlgebraElement): True """ K = self.base_ring() - if isinstance(K, sage.rings.abc.RealField) or isinstance(K, sage.rings.abc.RealDoubleField): + if isinstance(K, (sage.rings.abc.RealField, sage.rings.abc.RealDoubleField)): return self.roots(multiplicities=False) return self.roots(ring=RR, multiplicities=False) @@ -8296,7 +8290,7 @@ cdef class Polynomial(CommutativeAlgebraElement): return self.roots(ring=ComplexField(K.prec()), multiplicities=False) if isinstance(K, sage.rings.abc.RealDoubleField): return self.roots(ring=CDF, multiplicities=False) - if isinstance(K, sage.rings.abc.ComplexField) or isinstance(K, sage.rings.abc.ComplexDoubleField): + if isinstance(K, (sage.rings.abc.ComplexField, sage.rings.abc.ComplexDoubleField)): return self.roots(multiplicities=False) return self.roots(ring=CC, multiplicities=False) diff --git a/src/sage/rings/polynomial/polynomial_singular_interface.py b/src/sage/rings/polynomial/polynomial_singular_interface.py index 0a472405790..419eab22f40 100644 --- a/src/sage/rings/polynomial/polynomial_singular_interface.py +++ b/src/sage/rings/polynomial/polynomial_singular_interface.py @@ -386,10 +386,8 @@ def can_convert_to_singular(R): or sage.rings.finite_rings.finite_field_constructor.is_FiniteField(base_ring) or is_RationalField(base_ring) or is_IntegerModRing(base_ring) - or isinstance(base_ring, sage.rings.abc.RealField) - or isinstance(base_ring, sage.rings.abc.ComplexField) - or isinstance(base_ring, sage.rings.abc.RealDoubleField) - or isinstance(base_ring, sage.rings.abc.ComplexDoubleField)): + or isinstance(base_ring, (sage.rings.abc.RealField, sage.rings.abc.ComplexField, + sage.rings.abc.RealDoubleField, sage.rings.abc.ComplexDoubleField)): return True elif base_ring.is_prime_field(): return base_ring.characteristic() <= 2147483647 From 1d2956914662cf5b6390e381aa16a574cb804d58 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 2 Oct 2021 11:10:56 -0700 Subject: [PATCH 09/17] sage.{modular,quadratic_forms}: Fix up replacement of is_{Real,Complex}[Double]Field --- src/sage/modular/dirichlet.py | 4 ++-- src/sage/quadratic_forms/special_values.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sage/modular/dirichlet.py b/src/sage/modular/dirichlet.py index f71ef1e6f17..22c632c9789 100644 --- a/src/sage/modular/dirichlet.py +++ b/src/sage/modular/dirichlet.py @@ -1153,7 +1153,7 @@ def _pari_init_(self): # now compute the input for pari (list of exponents) P = self.parent() - if isinstance(P.base_ring(, sage.rings.abc.ComplexField)): + 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] @@ -2138,7 +2138,7 @@ def element(self): """ P = self.parent() M = P._module - if isinstance(P.base_ring(, sage.rings.abc.ComplexField)): + if isinstance(P.base_ring(), sage.rings.abc.ComplexField): zeta = P.zeta() zeta_argument = zeta.argument() v = M([int(round(x.argument() / zeta_argument)) diff --git a/src/sage/quadratic_forms/special_values.py b/src/sage/quadratic_forms/special_values.py index 5c7e3a1ccfe..e7b4c425866 100644 --- a/src/sage/quadratic_forms/special_values.py +++ b/src/sage/quadratic_forms/special_values.py @@ -9,7 +9,6 @@ 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 @@ -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 isinstance(n.parent(, sage.rings.abc.RealField)): + if isinstance(n.parent(), sage.rings.abc.RealField): R = n.parent() else: + from sage.rings.real_mpfr import RealField R = RealField() if n < 0: From a4ad3d4a21062fe99408d71d49bd8e21e10c63c4 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 2 Oct 2021 11:11:08 -0700 Subject: [PATCH 10/17] sage.matrix: Fix up replacement of is_{Real,Complex}[Double]Field --- src/sage/matrix/misc.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/matrix/misc.pyx b/src/sage/matrix/misc.pyx index a70a9a0f711..c7fc1c70161 100644 --- a/src/sage/matrix/misc.pyx +++ b/src/sage/matrix/misc.pyx @@ -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 @@ -510,7 +510,7 @@ def hadamard_row_bound_mpfr(Matrix A): ... OverflowError: cannot convert float infinity to integer """ - if not isinstance(A.base_ring(, sage.rings.abc.RealField)): + if not isinstance(A.base_ring(), RealField_class): raise TypeError("A must have base field an mpfr real field.") cdef RealNumber a, b From c7aa947e4bd2437c872477176eab735d2d835f9e Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 2 Oct 2021 12:40:48 -0700 Subject: [PATCH 11/17] sage.probability: Fix up replacement of is_{Real,Complex}[Double]Field --- src/sage/probability/random_variable.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sage/probability/random_variable.py b/src/sage/probability/random_variable.py index ea2c4c86b2f..bdb666dfeab 100644 --- a/src/sage/probability/random_variable.py +++ b/src/sage/probability/random_variable.py @@ -18,7 +18,6 @@ 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 @@ -83,6 +82,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 @@ -337,6 +337,7 @@ 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 isinstance(codomain, sage.rings.abc.RealField) and not is_RationalField(codomain): raise TypeError("Argument codomain (= %s) must be the reals or rationals" % codomain) From b8691cc3154217d0ec0fa555403d6e88d31fd275 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 2 Oct 2021 12:41:03 -0700 Subject: [PATCH 12/17] src/sage/rings/number_field/number_field_element.pyx: Remove unused import --- src/sage/rings/number_field/number_field_element.pyx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sage/rings/number_field/number_field_element.pyx b/src/sage/rings/number_field/number_field_element.pyx index 4ee3d048f07..67d8274d4c6 100644 --- a/src/sage/rings/number_field/number_field_element.pyx +++ b/src/sage/rings/number_field/number_field_element.pyx @@ -3945,7 +3945,6 @@ cdef class NumberFieldElement(FieldElement): if a <= Kv.one(): return Kv.zero() ht = a.log() - from sage.rings.real_mpfr import is_RealField if weighted and not isinstance(Kv, sage.rings.abc.RealField): ht*=2 return ht From abbe26dcc98ef905e3b70d1ef6cfd874181345df Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 2 Oct 2021 12:46:28 -0700 Subject: [PATCH 13/17] src/sage/modules/free_module.py: Remove another use of is_... functions --- src/sage/modules/free_module.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sage/modules/free_module.py b/src/sage/modules/free_module.py index 57c10114174..c28a31707a7 100644 --- a/src/sage/modules/free_module.py +++ b/src/sage/modules/free_module.py @@ -170,6 +170,7 @@ 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 @@ -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 From 65e9b9833bc8e4e837f775c8b867755271dedbe4 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 2 Oct 2021 14:07:52 -0700 Subject: [PATCH 14/17] src/sage/rings/polynomial/polynomial_singular_interface.py: Fixup --- src/sage/rings/polynomial/polynomial_singular_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/polynomial/polynomial_singular_interface.py b/src/sage/rings/polynomial/polynomial_singular_interface.py index 419eab22f40..2fd1ac24b2b 100644 --- a/src/sage/rings/polynomial/polynomial_singular_interface.py +++ b/src/sage/rings/polynomial/polynomial_singular_interface.py @@ -387,7 +387,7 @@ def can_convert_to_singular(R): or is_RationalField(base_ring) or is_IntegerModRing(base_ring) or isinstance(base_ring, (sage.rings.abc.RealField, sage.rings.abc.ComplexField, - sage.rings.abc.RealDoubleField, sage.rings.abc.ComplexDoubleField)): + sage.rings.abc.RealDoubleField, sage.rings.abc.ComplexDoubleField))): return True elif base_ring.is_prime_field(): return base_ring.characteristic() <= 2147483647 From a00d97a6da3193a8d12f7fb01488eb81ce13aa40 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 2 Oct 2021 16:24:14 -0700 Subject: [PATCH 15/17] src/sage/rings/number_field/number_field.py: Fixup --- src/sage/rings/number_field/number_field.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/rings/number_field/number_field.py b/src/sage/rings/number_field/number_field.py index 863fbd8aad8..f8cadacb0d0 100644 --- a/src/sage/rings/number_field/number_field.py +++ b/src/sage/rings/number_field/number_field.py @@ -9947,12 +9947,12 @@ def hilbert_symbol(self, a, b, P = None): codom = P.codomain() from sage.rings.complex_interval_field import is_ComplexIntervalField from sage.rings.all import (AA, QQbar) - if isinstance(codom, (sage.rings.abc.ComplexField, sage.rings.abc.ComplexDoubleField) or is_ComplexIntervalField(codom) or \ + if isinstance(codom, (sage.rings.abc.ComplexField, sage.rings.abc.ComplexDoubleField)) or is_ComplexIntervalField(codom) or \ codom is QQbar: if P(self.gen()).imag() == 0: raise ValueError("Possibly real place (=%s) given as complex embedding in hilbert_symbol. Is it real or complex?" % P) return 1 - if isinstance(codom, (sage.rings.abc.RealField, sage.rings.abc.RealDoubleField) or codom is AA: + if isinstance(codom, (sage.rings.abc.RealField, sage.rings.abc.RealDoubleField)) or codom is AA: if P(a) > 0 or P(b) > 0: return 1 return -1 From fa79b1020329a8a616be4a315451db2cc85c88f0 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 3 Oct 2021 09:45:38 -0700 Subject: [PATCH 16/17] Add missing imports of sage.rings.abc --- src/sage/functions/special.py | 1 + src/sage/probability/random_variable.py | 1 + 2 files changed, 2 insertions(+) diff --git a/src/sage/functions/special.py b/src/sage/functions/special.py index bc43c362141..63083a617a0 100644 --- a/src/sage/functions/special.py +++ b/src/sage/functions/special.py @@ -158,6 +158,7 @@ # https://www.gnu.org/licenses/ # **************************************************************************** +import sage.rings.abc from sage.rings.integer import Integer from sage.misc.latex import latex from sage.rings.all import ZZ diff --git a/src/sage/probability/random_variable.py b/src/sage/probability/random_variable.py index bdb666dfeab..47d108996f0 100644 --- a/src/sage/probability/random_variable.py +++ b/src/sage/probability/random_variable.py @@ -15,6 +15,7 @@ # 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 94fd9c52828b628f2417aa85ce2fe694545424a6 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 3 Oct 2021 09:48:50 -0700 Subject: [PATCH 17/17] is_{Real,Complex}[Double]Field: In doctests, add deprecation warning to expected output --- src/sage/rings/complex_double.pyx | 4 ++++ src/sage/rings/complex_mpfr.pyx | 4 ++++ src/sage/rings/real_double.pyx | 4 ++++ src/sage/rings/real_mpfr.pyx | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/src/sage/rings/complex_double.pyx b/src/sage/rings/complex_double.pyx index 6977939b789..7a2d45d1028 100644 --- a/src/sage/rings/complex_double.pyx +++ b/src/sage/rings/complex_double.pyx @@ -123,6 +123,10 @@ def is_ComplexDoubleField(x): sage: from sage.rings.complex_double import is_ComplexDoubleField sage: is_ComplexDoubleField(CDF) + doctest:warning... + DeprecationWarning: is_ComplexDoubleField is deprecated; + use isinstance(..., sage.rings.abc.ComplexDoubleField) instead + See https://trac.sagemath.org/32610 for details. True sage: is_ComplexDoubleField(ComplexField(53)) False diff --git a/src/sage/rings/complex_mpfr.pyx b/src/sage/rings/complex_mpfr.pyx index d51bbdbc469..3021ab5d177 100644 --- a/src/sage/rings/complex_mpfr.pyx +++ b/src/sage/rings/complex_mpfr.pyx @@ -169,6 +169,10 @@ def is_ComplexField(x): sage: from sage.rings.complex_mpfr import is_ComplexField as is_CF sage: is_CF(ComplexField()) + doctest:warning... + DeprecationWarning: is_ComplexField is deprecated; + use isinstance(..., sage.rings.abc.ComplexField) instead + See https://trac.sagemath.org/32610 for details. True sage: is_CF(ComplexField(12)) True diff --git a/src/sage/rings/real_double.pyx b/src/sage/rings/real_double.pyx index bccbc382bff..d3ad8ecfb0e 100644 --- a/src/sage/rings/real_double.pyx +++ b/src/sage/rings/real_double.pyx @@ -84,6 +84,10 @@ def is_RealDoubleField(x): sage: from sage.rings.real_double import is_RealDoubleField sage: is_RealDoubleField(RDF) + doctest:warning... + DeprecationWarning: is_RealDoubleField is deprecated; + use isinstance(..., sage.rings.abc.RealDoubleField) instead + See https://trac.sagemath.org/32610 for details. True sage: is_RealDoubleField(RealField(53)) False diff --git a/src/sage/rings/real_mpfr.pyx b/src/sage/rings/real_mpfr.pyx index cefe99b6c1c..bd9b7931463 100644 --- a/src/sage/rings/real_mpfr.pyx +++ b/src/sage/rings/real_mpfr.pyx @@ -5906,6 +5906,10 @@ def is_RealField(x): EXAMPLES:: sage: sage.rings.real_mpfr.is_RealField(RR) + doctest:warning... + DeprecationWarning: is_RealField is deprecated; + use isinstance(..., sage.rings.abc.RealField) instead + See https://trac.sagemath.org/32610 for details. True sage: sage.rings.real_mpfr.is_RealField(CC) False