diff --git a/src/sage/rings/abc.pyx b/src/sage/rings/abc.pyx index eb471a6c34d..e776559d81a 100644 --- a/src/sage/rings/abc.pyx +++ b/src/sage/rings/abc.pyx @@ -10,6 +10,22 @@ cdef class RealField(Field): pass +class RealBallField(Field): + r""" + Abstract base class for :class:`~sage.rings.real_arb.RealBallField`. + """ + + pass + + +cdef class RealIntervalField(Field): + r""" + Abstract base class for :class:`~sage.rings.real_mpfi.RealIntervalField_class`. + """ + + pass + + cdef class RealDoubleField(Field): r""" Abstract base class for :class:`~sage.rings.real_double.RealDoubleField_class`. @@ -26,6 +42,22 @@ cdef class ComplexField(Field): pass +class ComplexBallField(Field): + r""" + Abstract base class for :class:`~sage.rings.complex_arb.ComplexBallField`. + """ + + pass + + +class ComplexIntervalField(Field): + r""" + Abstract base class for :class:`~sage.rings.complex_interval_field.ComplexIntervalField_class`. + """ + + pass + + cdef class ComplexDoubleField(Field): r""" Abstract base class for :class:`~sage.rings.complex_double.ComplexDoubleField_class`. diff --git a/src/sage/rings/complex_arb.pyx b/src/sage/rings/complex_arb.pyx index 977580a2926..bc3b7f8e792 100644 --- a/src/sage/rings/complex_arb.pyx +++ b/src/sage/rings/complex_arb.pyx @@ -147,6 +147,7 @@ from cysignals.signals cimport sig_on, sig_str, sig_off, sig_error import sage.categories.fields +cimport sage.rings.abc cimport sage.rings.rational from cpython.float cimport PyFloat_AS_DOUBLE @@ -302,6 +303,7 @@ cdef int acb_calc_func_callback(acb_ptr out, const acb_t inp, void * param, finally: sig_on() + class ComplexBallField(UniqueRepresentation, sage.rings.abc.ComplexBallField): r""" An approximation of the field of complex numbers using pairs of mid-rad diff --git a/src/sage/rings/complex_interval_field.py b/src/sage/rings/complex_interval_field.py index cee580b22a3..05758d9956b 100644 --- a/src/sage/rings/complex_interval_field.py +++ b/src/sage/rings/complex_interval_field.py @@ -40,6 +40,7 @@ from .integer_ring import ZZ from .rational_field import QQ from .ring import Field +import sage.rings.abc from . import integer from . import complex_interval import weakref @@ -55,13 +56,20 @@ def is_ComplexIntervalField(x): EXAMPLES:: sage: from sage.rings.complex_interval_field import is_ComplexIntervalField as is_CIF + doctest:warning... + DeprecationWarning: is_ComplexIntervalField is deprecated; + use isinstance(..., sage.rings.abc.ComplexIntervalField) instead + See https://trac.sagemath.org/32612 for details. sage: is_CIF(CIF) True sage: is_CIF(CC) False """ + from sage.misc.superseded import deprecation + deprecation(32612, 'is_ComplexIntervalField is deprecated; use isinstance(..., sage.rings.abc.ComplexIntervalField) instead') return isinstance(x, ComplexIntervalField_class) + cache = {} def ComplexIntervalField(prec=53, names=None): """ @@ -93,7 +101,7 @@ def ComplexIntervalField(prec=53, names=None): return C -class ComplexIntervalField_class(Field): +class ComplexIntervalField_class(sage.rings.abc.ComplexIntervalField): """ The field of complex (interval) numbers. diff --git a/src/sage/rings/number_field/number_field.py b/src/sage/rings/number_field/number_field.py index f8cadacb0d0..4b188823ac3 100644 --- a/src/sage/rings/number_field/number_field.py +++ b/src/sage/rings/number_field/number_field.py @@ -9945,9 +9945,8 @@ 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_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, sage.rings.abc.ComplexIntervalField)) 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) diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index f7807221d55..0d2cfda744d 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -92,7 +92,7 @@ CC = ComplexField() from sage.rings.real_double import RDF from sage.rings.complex_double import CDF -from sage.rings.real_mpfi import is_RealIntervalField +import sage.rings.abc from sage.structure.coerce cimport coercion_model from sage.structure.element import coerce_binop @@ -8030,7 +8030,7 @@ cdef class Polynomial(CommutativeAlgebraElement): # and complex root isolation and for p-adic factorization if (is_IntegerRing(K) or is_RationalField(K) or is_AlgebraicRealField(K)) and \ - (is_AlgebraicRealField(L) or is_RealIntervalField(L)): + (is_AlgebraicRealField(L) or isinstance(L, sage.rings.abc.RealIntervalField)): from sage.rings.polynomial.real_roots import real_roots @@ -8060,11 +8060,11 @@ cdef class Polynomial(CommutativeAlgebraElement): if (is_IntegerRing(K) or is_RationalField(K) or is_AlgebraicField_common(K) or input_gaussian) and \ - (is_ComplexIntervalField(L) or is_AlgebraicField_common(L)): + (isinstance(L, sage.rings.abc.ComplexIntervalField) or is_AlgebraicField_common(L)): from sage.rings.polynomial.complex_roots import complex_roots - if is_ComplexIntervalField(L): + if isinstance(L, sage.rings.abc.ComplexIntervalField): rts = complex_roots(self, min_prec=L.prec()) elif is_AlgebraicField(L): rts = complex_roots(self, retval='algebraic') diff --git a/src/sage/rings/qqbar.py b/src/sage/rings/qqbar.py index a63315f93b1..a36b5de3c72 100644 --- a/src/sage/rings/qqbar.py +++ b/src/sage/rings/qqbar.py @@ -5013,7 +5013,7 @@ def interval_exact(self, field): sage: (a - b).interval_exact(CIF) 0 """ - if not is_ComplexIntervalField(field): + if not isinstance(field, sage.rings.abc.ComplexIntervalField): raise ValueError("AlgebraicNumber interval_exact requires a ComplexIntervalField") rfld = field._real_field() re = self.real().interval_exact(rfld) @@ -5910,7 +5910,7 @@ def _complex_mpfr_field_(self, field): sage: AA(golden_ratio)._complex_mpfr_field_(ComplexField(100)) 1.6180339887498948482045868344 """ - if is_ComplexIntervalField(field): + if isinstance(field, sage.rings.abc.ComplexIntervalField): return field(self.interval(field._real_field())) else: return field(self.real_number(field._real_field())) diff --git a/src/sage/rings/real_arb.pyx b/src/sage/rings/real_arb.pyx index 66a9d7bda06..43b6b6da5fd 100644 --- a/src/sage/rings/real_arb.pyx +++ b/src/sage/rings/real_arb.pyx @@ -219,6 +219,7 @@ from sage.libs.mpfr cimport MPFR_RNDN, MPFR_RNDU, MPFR_RNDD, MPFR_RNDZ from sage.structure.element cimport Element, ModuleElement, RingElement from sage.rings.ring cimport Field +import sage.rings.abc from sage.rings.integer cimport Integer from sage.rings.rational cimport Rational from sage.rings.real_double cimport RealDoubleElement @@ -320,7 +321,7 @@ cdef int arb_to_mpfi(mpfi_t target, arb_t source, const long precision) except - mpfr_clear(right) -class RealBallField(UniqueRepresentation, Field): +class RealBallField(UniqueRepresentation, sage.rings.abc.RealBallField): r""" An approximation of the field of real numbers using mid-rad intervals, also known as balls. diff --git a/src/sage/rings/real_interval_absolute.pyx b/src/sage/rings/real_interval_absolute.pyx index 2b193145eb3..16a275aab2b 100644 --- a/src/sage/rings/real_interval_absolute.pyx +++ b/src/sage/rings/real_interval_absolute.pyx @@ -185,7 +185,7 @@ cdef class RealIntervalAbsoluteField_class(Field): """ if isinstance(R, RealIntervalAbsoluteField_class): return self._absprec < (R)._absprec - elif is_RealIntervalField(R): + elif isinstance(R, sage.rings.abc.RealIntervalField): return True else: return RR_min_prec.has_coerce_map_from(R) diff --git a/src/sage/rings/real_mpfi.pxd b/src/sage/rings/real_mpfi.pxd index c32dcc959d0..5466a5f575f 100644 --- a/src/sage/rings/real_mpfi.pxd +++ b/src/sage/rings/real_mpfi.pxd @@ -2,7 +2,7 @@ from sage.libs.mpfr.types cimport mpfr_prec_t from sage.libs.mpfi.types cimport mpfi_t from sage.rings.ring cimport Field - +cimport sage.rings.abc from sage.structure.element cimport RingElement from .rational cimport Rational @@ -10,7 +10,7 @@ from .real_mpfr cimport RealField_class cdef class RealIntervalFieldElement(RingElement) # forward decl -cdef class RealIntervalField_class(Field): +cdef class RealIntervalField_class(sage.rings.abc.RealIntervalField): cdef mpfr_prec_t __prec cdef bint sci_not # Cache RealField instances for the lower, upper, and middle bounds. diff --git a/src/sage/rings/real_mpfi.pyx b/src/sage/rings/real_mpfi.pyx index 2bfdc5f2512..ce83e1ddf4e 100644 --- a/src/sage/rings/real_mpfi.pyx +++ b/src/sage/rings/real_mpfi.pyx @@ -345,7 +345,7 @@ cpdef RealIntervalField_class RealIntervalField(prec=53, sci_not=False): return R -cdef class RealIntervalField_class(Field): +cdef class RealIntervalField_class(sage.rings.abc.RealIntervalField): """ Class of the real interval field. diff --git a/src/sage/schemes/elliptic_curves/ell_number_field.py b/src/sage/schemes/elliptic_curves/ell_number_field.py index 638b0305a0c..576e670d0eb 100644 --- a/src/sage/schemes/elliptic_curves/ell_number_field.py +++ b/src/sage/schemes/elliptic_curves/ell_number_field.py @@ -85,6 +85,7 @@ # https://www.gnu.org/licenses/ # **************************************************************************** +import sage.rings.abc from .ell_field import EllipticCurve_field from .ell_generic import is_EllipticCurve from .ell_point import EllipticCurvePoint_number_field diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx index be2bbd065a8..de14f5c2d22 100644 --- a/src/sage/symbolic/expression.pyx +++ b/src/sage/symbolic/expression.pyx @@ -3565,8 +3565,8 @@ cdef class Expression(CommutativeRingElement): else: domain = RIF else: - is_interval = (is_RealIntervalField(domain) - or is_ComplexIntervalField(domain) + is_interval = (isinstance(domain, (sage.rings.abc.RealIntervalField, + sage.rings.abc.ComplexIntervalField)) or is_AlgebraicField(domain) or is_AlgebraicRealField(domain)) zero = domain(0) @@ -3620,7 +3620,7 @@ cdef class Expression(CommutativeRingElement): eq_count += val.contains_zero() except (TypeError, ValueError, ArithmeticError, AttributeError) as ex: errors += 1 - if k == errors > 3 and is_ComplexIntervalField(domain): + if k == errors > 3 and isinstance(domain, sage.rings.abc.ComplexIntervalField): domain = RIF.to_prec(domain.prec()) # we are plugging in random values above, don't be surprised # if something goes wrong... diff --git a/src/sage/symbolic/ring.pyx b/src/sage/symbolic/ring.pyx index 7b90d56d0e3..0f3a8b9fc07 100644 --- a/src/sage/symbolic/ring.pyx +++ b/src/sage/symbolic/ring.pyx @@ -231,9 +231,10 @@ cdef class SymbolicRing(CommutativeRing): base = R.base_ring() return base is not self and self.has_coerce_map_from(base) elif (R is InfinityRing or R is UnsignedInfinityRing - or is_RealIntervalField(R) or is_ComplexIntervalField(R) - or isinstance(R, RealBallField) - or isinstance(R, ComplexBallField) + or isinstance(R, (sage.rings.abc.RealIntervalField, + sage.rings.abc.ComplexIntervalField, + sage.rings.abc.RealBallField, + sage.rings.abc.ComplexBallField)) or is_IntegerModRing(R) or is_FiniteField(R)): return True elif isinstance(R, GenericSymbolicSubring): diff --git a/src/sage/symbolic/subring.py b/src/sage/symbolic/subring.py index 060ad32a5ed..c1eb48e16ae 100644 --- a/src/sage/symbolic/subring.py +++ b/src/sage/symbolic/subring.py @@ -97,6 +97,7 @@ # http://www.gnu.org/licenses/ #***************************************************************************** +import sage.rings.abc from .ring import SymbolicRing, SR from sage.categories.pushout import ConstructionFunctor from sage.structure.factory import UniqueFactory @@ -412,8 +413,6 @@ def _coerce_map_from_(self, P): return False from sage.rings.all import RLF, CLF, AA, QQbar, InfinityRing - from sage.rings.real_mpfi import is_RealIntervalField - from sage.rings.complex_interval_field import is_ComplexIntervalField if isinstance(P, type): return SR._coerce_map_from_(P) @@ -425,7 +424,8 @@ def _coerce_map_from_(self, P): return True elif (P is InfinityRing or - is_RealIntervalField(P) or is_ComplexIntervalField(P)): + isinstance(P, (sage.rings.abc.RealIntervalField, + sage.rings.abc.ComplexIntervalField))): return True elif P._is_numerical():