diff --git a/src/sage/modular/dirichlet.py b/src/sage/modular/dirichlet.py index 74345c67e5d..c35e712de21 100644 --- a/src/sage/modular/dirichlet.py +++ b/src/sage/modular/dirichlet.py @@ -69,7 +69,6 @@ from sage.categories.map import Map from sage.rings.rational_field import is_RationalField import sage.rings.abc -from sage.rings.qqbar import is_AlgebraicField from sage.rings.ring import is_Ring from sage.misc.functional import round @@ -1347,7 +1346,7 @@ def gauss_sum(self, a=1): m = G.modulus() if isinstance(K, sage.rings.abc.ComplexField): return self.gauss_sum_numerical(a=a) - elif is_AlgebraicField(K): + elif isinstance(K, sage.rings.abc.AlgebraicField): L = K zeta = L.zeta(m) elif number_field.is_CyclotomicField(K) or is_RationalField(K): @@ -1427,7 +1426,7 @@ def gauss_sum_numerical(self, prec=53, a=1): def phi(t): return t CC = K - elif is_AlgebraicField(K): + elif isinstance(K, sage.rings.abc.AlgebraicField): from sage.rings.complex_mpfr import ComplexField CC = ComplexField(prec) phi = CC.coerce_map_from(K) diff --git a/src/sage/rings/abc.pyx b/src/sage/rings/abc.pyx index 2c5e2253150..15e195a4e1a 100644 --- a/src/sage/rings/abc.pyx +++ b/src/sage/rings/abc.pyx @@ -2,6 +2,30 @@ Abstract base classes for rings """ +class AlgebraicField_common(Field): + r""" + Abstract base class for :class:`~sage.rings.qqbar.AlgebraicField_common`. + """ + + pass + + +class AlgebraicField(AlgebraicField_common): + r""" + Abstract base class for :class:`~sage.rings.qqbar.AlgebraicField`. + """ + + pass + + +class AlgebraicRealField(AlgebraicField_common): + r""" + Abstract base class for :class:`~sage.rings.qqbar.AlgebraicRealField`. + """ + + pass + + cdef class RealField(Field): r""" Abstract base class for :class:`~sage.rings.real_mpfr.RealField_class`. diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index 3b944b50ce6..7d47f0dbeb1 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -171,31 +171,17 @@ from .polynomial_compiled cimport CompiledPolynomialFunction from sage.rings.polynomial.polydict cimport ETuple -cdef object is_AlgebraicRealField -cdef object is_AlgebraicField -cdef object is_AlgebraicField_common cdef object NumberField_quadratic -cdef object is_ComplexIntervalField cdef void late_import(): # A hack to avoid circular imports. - global is_AlgebraicRealField - global is_AlgebraicField - global is_AlgebraicField_common global NumberField_quadratic - global is_ComplexIntervalField - if is_AlgebraicRealField is not None: + if NumberField_quadratic is not None: return - import sage.rings.qqbar - is_AlgebraicRealField = sage.rings.qqbar.is_AlgebraicRealField - is_AlgebraicField = sage.rings.qqbar.is_AlgebraicField - is_AlgebraicField_common = sage.rings.qqbar.is_AlgebraicField_common import sage.rings.number_field.number_field NumberField_quadratic = sage.rings.number_field.number_field.NumberField_quadratic - import sage.rings.complex_interval_field - is_ComplexIntervalField = sage.rings.complex_interval_field.is_ComplexIntervalField cdef class Polynomial(CommutativeAlgebraElement): @@ -7964,16 +7950,16 @@ cdef class Polynomial(CommutativeAlgebraElement): else: return [rt.rhs() for rt in rts] - if L != K or is_AlgebraicField_common(L): + if L != K or isinstance(L, sage.rings.abc.AlgebraicField_common): # So far, the only "special" implementations are for real # 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 isinstance(L, sage.rings.abc.RealIntervalField)): + or isinstance(K, sage.rings.abc.AlgebraicRealField)) and \ + isinstance(L, (sage.rings.abc.AlgebraicRealField, sage.rings.abc.RealIntervalField)): from sage.rings.polynomial.real_roots import real_roots - if is_AlgebraicRealField(L): + if isinstance(L, sage.rings.abc.AlgebraicRealField): rts = real_roots(self, retval='algebraic_real') else: diam = ~(ZZ(1) << L.prec()) @@ -7998,14 +7984,14 @@ cdef class Polynomial(CommutativeAlgebraElement): return [rt for (rt, mult) in rts] if (is_IntegerRing(K) or is_RationalField(K) - or is_AlgebraicField_common(K) or input_gaussian) and \ - (isinstance(L, sage.rings.abc.ComplexIntervalField) or is_AlgebraicField_common(L)): + or isinstance(K, sage.rings.abc.AlgebraicField_common) or input_gaussian) and \ + isinstance(L, (sage.rings.abc.ComplexIntervalField, sage.rings.abc.AlgebraicField_common)): from sage.rings.polynomial.complex_roots import complex_roots if isinstance(L, sage.rings.abc.ComplexIntervalField): rts = complex_roots(self, min_prec=L.prec()) - elif is_AlgebraicField(L): + elif isinstance(L, sage.rings.abc.AlgebraicField): rts = complex_roots(self, retval='algebraic') else: rts = complex_roots(self, retval='algebraic_real') diff --git a/src/sage/rings/qqbar.py b/src/sage/rings/qqbar.py index 3c3343e5354..3e7b39c896e 100644 --- a/src/sage/rings/qqbar.py +++ b/src/sage/rings/qqbar.py @@ -555,6 +555,7 @@ import operator import sage.rings.ring +import sage.rings.abc import sage.rings.number_field.number_field_base from sage.misc.fast_methods import Singleton from sage.misc.cachefunc import cached_method @@ -583,7 +584,7 @@ CC = ComplexField() CIF = ComplexIntervalField() -class AlgebraicField_common(sage.rings.ring.Field): +class AlgebraicField_common(sage.rings.abc.AlgebraicField_common): r""" Common base class for the classes :class:`~AlgebraicRealField` and :class:`~AlgebraicField`. @@ -1013,7 +1014,7 @@ def NF_elem_map(e): return Factorization(factorization, unit = f.lc() / trial.lc()) -class AlgebraicRealField(Singleton, AlgebraicField_common): +class AlgebraicRealField(Singleton, AlgebraicField_common, sage.rings.abc.AlgebraicRealField): r""" The field of algebraic reals. @@ -1449,12 +1450,21 @@ def is_AlgebraicRealField(F): r""" Check whether ``F`` is an :class:`~AlgebraicRealField` instance. For internal use. + This function is deprecated. Use :func:`isinstance` with + :class:`~sage.rings.abc.AlgebraicRealField` instead. + EXAMPLES:: sage: from sage.rings.qqbar import is_AlgebraicRealField sage: [is_AlgebraicRealField(x) for x in [AA, QQbar, None, 0, "spam"]] + doctest:warning... + DeprecationWarning: is_AlgebraicRealField is deprecated; + use isinstance(..., sage.rings.abc.AlgebraicRealField instead + See https://trac.sagemath.org/32660 for details. [True, False, False, False, False] """ + from sage.misc.superseded import deprecation + deprecation(32660, 'is_AlgebraicRealField is deprecated; use isinstance(..., sage.rings.abc.AlgebraicRealField instead') return isinstance(F, AlgebraicRealField) @@ -1462,7 +1472,7 @@ def is_AlgebraicRealField(F): AA = AlgebraicRealField() -class AlgebraicField(Singleton, AlgebraicField_common): +class AlgebraicField(Singleton, AlgebraicField_common, sage.rings.abc.AlgebraicField): """ The field of all algebraic complex numbers. """ @@ -1993,12 +2003,21 @@ def is_AlgebraicField(F): r""" Check whether ``F`` is an :class:`~AlgebraicField` instance. + This function is deprecated. Use :func:`isinstance` with + :class:`~sage.rings.abc.AlgebraicField` instead. + EXAMPLES:: sage: from sage.rings.qqbar import is_AlgebraicField sage: [is_AlgebraicField(x) for x in [AA, QQbar, None, 0, "spam"]] + doctest:warning... + DeprecationWarning: is_AlgebraicField is deprecated; + use isinstance(..., sage.rings.abc.AlgebraicField instead + See https://trac.sagemath.org/32660 for details. [False, True, False, False, False] """ + from sage.misc.superseded import deprecation + deprecation(32660, 'is_AlgebraicField is deprecated; use isinstance(..., sage.rings.abc.AlgebraicField instead') return isinstance(F, AlgebraicField) @@ -2010,12 +2029,21 @@ def is_AlgebraicField_common(F): r""" Check whether ``F`` is an :class:`~AlgebraicField_common` instance. + This function is deprecated. Use :func:`isinstance` with + :class:`~sage.rings.abc.AlgebraicField_common` instead. + EXAMPLES:: sage: from sage.rings.qqbar import is_AlgebraicField_common sage: [is_AlgebraicField_common(x) for x in [AA, QQbar, None, 0, "spam"]] + doctest:warning... + DeprecationWarning: is_AlgebraicField_common is deprecated; + use isinstance(..., sage.rings.abc.AlgebraicField_common) instead + See https://trac.sagemath.org/32610 for details. [True, True, False, False, False] """ + from sage.misc.superseded import deprecation + deprecation(32610, 'is_AlgebraicField_common is deprecated; use isinstance(..., sage.rings.abc.AlgebraicField_common) instead') return isinstance(F, AlgebraicField_common) @@ -6551,7 +6579,7 @@ def __init__(self, poly): poly = QQy(poly) complex = False elif isinstance(B, AlgebraicField_common): - complex = is_AlgebraicField(poly.base_ring()) + complex = isinstance(poly.base_ring(), AlgebraicField) else: try: poly = poly.change_ring(AA) diff --git a/src/sage/rings/qqbar_decorators.py b/src/sage/rings/qqbar_decorators.py index 621e5ded0d7..e18fac73cdc 100644 --- a/src/sage/rings/qqbar_decorators.py +++ b/src/sage/rings/qqbar_decorators.py @@ -87,12 +87,12 @@ def wrapper(*args, **kwds): from sage.rings.polynomial.multi_polynomial import MPolynomial from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence, is_PolynomialSequence from sage.rings.ideal import Ideal, Ideal_generic - from sage.rings.qqbar import is_AlgebraicField_common, number_field_elements_from_algebraics + from sage.rings.qqbar import AlgebraicField_common, number_field_elements_from_algebraics if not any(isinstance(a, (Polynomial, MPolynomial, Ideal_generic)) - and is_AlgebraicField_common(a.base_ring()) + and isinstance(a.base_ring(), AlgebraicField_common) or is_PolynomialSequence(a) - and is_AlgebraicField_common(a.ring().base_ring()) for a in args): + and isinstance(a.ring().base_ring(), AlgebraicField_common) for a in args): return func(*args, **kwds) polynomials = [] diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx index 5aab78bcb7b..4d7bd8f22cd 100644 --- a/src/sage/symbolic/expression.pyx +++ b/src/sage/symbolic/expression.pyx @@ -1524,8 +1524,9 @@ cdef class Expression(CommutativeRingElement): ValueError: cannot convert sqrt(-3) to int """ from sage.functions.all import floor, ceil + from sage.rings.real_mpfi import RIF try: - rif_self = sage.rings.all.RIF(self) + rif_self = RIF(self) except TypeError: raise ValueError("cannot convert %s to int" % self) if rif_self > 0 or (rif_self.contains_zero() and self > 0): @@ -3548,27 +3549,22 @@ cdef class Expression(CommutativeRingElement): if not self.is_relational(): raise ValueError("self must be a relation") cdef operators op = relational_operator(self._gobj) - from sage.rings.real_mpfi import is_RealIntervalField - from sage.rings.complex_interval_field import is_ComplexIntervalField - from sage.rings.all import RIF, CIF - from sage.rings.qqbar import is_AlgebraicField, is_AlgebraicRealField, AA, QQbar if domain is None: is_interval = True if self.lhs().is_algebraic() and self.rhs().is_algebraic(): if op == equal or op == not_equal: - domain = QQbar + from sage.rings.qqbar import QQbar as domain else: - domain = AA + from sage.rings.qqbar import AA as domain else: if op == equal or op == not_equal: - domain = CIF + from sage.rings.qqbar import CIF as domain else: - domain = RIF + from sage.rings.real_mpfi import RIF as domain else: - is_interval = (isinstance(domain, (sage.rings.abc.RealIntervalField, - sage.rings.abc.ComplexIntervalField)) - or is_AlgebraicField(domain) - or is_AlgebraicRealField(domain)) + is_interval = isinstance(domain, (sage.rings.abc.RealIntervalField, + sage.rings.abc.ComplexIntervalField, + sage.rings.abc.AlgebraicField_common)) zero = domain(0) diff = self.lhs() - self.rhs() vars = diff.variables() @@ -3621,6 +3617,7 @@ cdef class Expression(CommutativeRingElement): except (TypeError, ValueError, ArithmeticError, AttributeError) as ex: errors += 1 if k == errors > 3 and isinstance(domain, sage.rings.abc.ComplexIntervalField): + from sage.rings.real_mpfi import RIF domain = RIF.to_prec(domain.prec()) # we are plugging in random values above, don't be surprised # if something goes wrong... @@ -6644,8 +6641,9 @@ cdef class Expression(CommutativeRingElement): except (TypeError, AttributeError): pass from sage.functions.all import floor, ceil + from sage.rings.real_mpfi import RIF try: - rif_self = sage.rings.all.RIF(self) + rif_self = RIF(self) except TypeError: raise ValueError("could not convert %s to a real number" % self) half = 1 / sage.rings.integer.Integer(2)