Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoeppe committed Oct 3, 2021
2 parents 7dab237 + 94fd9c5 commit 22a9362
Show file tree
Hide file tree
Showing 24 changed files with 114 additions and 84 deletions.
10 changes: 5 additions & 5 deletions src/sage/dynamics/arithmetic_dynamics/projective_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 is_RealField(v.codomain()) or v.codomain() is RDF:
if isinstance(v.codomain(), (sage.rings.abc.RealField, sage.rings.abc.RealDoubleField)):
dv = R.one()
else:
dv = R(2)
Expand Down
11 changes: 5 additions & 6 deletions src/sage/functions/orthogonal_polys.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,7 @@
from sage.misc.latex import latex
from sage.rings.all import ZZ, QQ, RR, CC
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.real_mpfr import is_RealField
from sage.rings.complex_mpfr import is_ComplexField
import sage.rings.abc

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

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

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

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

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

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

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

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

CC = z.parent()
from sage.rings.complex_mpfr import is_ComplexField
if not is_ComplexField(CC):
if not isinstance(CC, sage.rings.abc.ComplexField):
from sage.rings.complex_mpfr import ComplexField
CC = ComplexField(prec)
try:
z = CC(z)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/matrix/misc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ from sage.rings.rational_field import QQ
from sage.rings.integer cimport Integer
from sage.arith.all import previous_prime, CRT_basis

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


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

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

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

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

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

def phi(t):
return t
Expand Down Expand Up @@ -2138,7 +2138,7 @@ def element(self):
"""
P = self.parent()
M = P._module
if is_ComplexField(P.base_ring()):
if isinstance(P.base_ring(), sage.rings.abc.ComplexField):
zeta = P.zeta()
zeta_argument = zeta.argument()
v = M([int(round(x.argument() / zeta_argument))
Expand Down Expand Up @@ -2607,7 +2607,7 @@ def _zeta_powers(self):
w = [a]
zeta = self.zeta()
zeta_order = self.zeta_order()
if is_ComplexField(R):
if isinstance(R, sage.rings.abc.ComplexField):
for i in range(1, zeta_order):
a = a * zeta
a._set_multiplicative_order(zeta_order / gcd(zeta_order, i))
Expand Down
1 change: 1 addition & 0 deletions src/sage/modules/free_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.abc
Expand Down
6 changes: 4 additions & 2 deletions src/sage/probability/random_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
# https://www.gnu.org/licenses/
# ****************************************************************************

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

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

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

if n < 0:
Expand Down
10 changes: 10 additions & 0 deletions src/sage/rings/complex_double.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,28 @@ from sage.structure.richcmp cimport rich_to_bool
cimport gmpy2
gmpy2.import_gmpy2()


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: 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
"""
from sage.misc.superseded import deprecation
deprecation(32610, 'is_ComplexDoubleField is deprecated; use isinstance(..., sage.rings.abc.ComplexDoubleField) instead')
return isinstance(x, ComplexDoubleField_class)


Expand Down
13 changes: 12 additions & 1 deletion src/sage/rings/complex_mpfr.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,33 @@ def is_ComplexNumber(x):
"""
return isinstance(x, ComplexNumber)


def is_ComplexField(x):
"""
Check if ``x`` is a :class:`complex field <ComplexField_class>`.
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
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
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):
"""
Expand Down Expand Up @@ -543,7 +554,7 @@ class ComplexField_class(sage.rings.abc.ComplexField):
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, ComplexField_class):
if self._prec <= S._prec:
return self._generic_coerce_map(S)
else:
Expand Down
12 changes: 5 additions & 7 deletions src/sage/rings/number_field/number_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 is_ComplexField(codom) 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 is_RealField(codom) 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
Expand Down Expand Up @@ -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.is_RealField(RC) 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:
Expand Down
3 changes: 1 addition & 2 deletions src/sage/rings/number_field/number_field_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3945,8 +3945,7 @@ 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 is_RealField(Kv):
if weighted and not isinstance(Kv, sage.rings.abc.RealField):
ht*=2
return ht

Expand Down
7 changes: 3 additions & 4 deletions src/sage/rings/polynomial/multi_polynomial_libsingular.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ 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
from sage.rings.integer_ring import is_IntegerRing, ZZ
from sage.rings.integer cimport Integer
from sage.rings.integer import GCD_list
Expand Down Expand Up @@ -1366,14 +1365,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()
Expand Down
4 changes: 2 additions & 2 deletions src/sage/rings/polynomial/polynomial_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 22a9362

Please sign in to comment.