Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoeppe committed Oct 4, 2021
2 parents bb5ef16 + 1e5a6aa commit 168fa62
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 23 deletions.
32 changes: 32 additions & 0 deletions src/sage/rings/abc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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`.
Expand Down
2 changes: 2 additions & 0 deletions src/sage/rings/complex_arb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/sage/rings/complex_interval_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions src/sage/rings/number_field/number_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/sage/rings/polynomial/polynomial_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/qqbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()))
Expand Down
3 changes: 2 additions & 1 deletion src/sage/rings/real_arb.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/real_interval_absolute.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ cdef class RealIntervalAbsoluteField_class(Field):
"""
if isinstance(R, RealIntervalAbsoluteField_class):
return self._absprec < (<RealIntervalAbsoluteField_class>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)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/real_mpfi.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ 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
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.
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/real_mpfi.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/sage/schemes/elliptic_curves/ell_number_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/sage/symbolic/expression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -3620,7 +3620,7 @@ cdef class Expression(CommutativeRingElement):
eq_count += <bint>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...
Expand Down
7 changes: 4 additions & 3 deletions src/sage/symbolic/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions src/sage/symbolic/subring.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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():
Expand Down

0 comments on commit 168fa62

Please sign in to comment.