From 9e74b6a96bbd946a6944a5e078e411dc0a412cf3 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 28 Sep 2021 18:31:15 -0700 Subject: [PATCH 01/61] sage.rings.abc: Add IntegerModRing, Order; use them in sage.matrix, sage.modules --- src/sage/matrix/matrix0.pyx | 4 ++-- src/sage/modules/free_module.py | 6 +++--- src/sage/rings/abc.pyx | 15 +++++++++++++++ src/sage/rings/finite_rings/integer_mod_ring.py | 2 +- src/sage/rings/number_field/order.py | 3 ++- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/sage/matrix/matrix0.pyx b/src/sage/matrix/matrix0.pyx index 41b8da5f415..92c87e3a2ec 100644 --- a/src/sage/matrix/matrix0.pyx +++ b/src/sage/matrix/matrix0.pyx @@ -44,7 +44,7 @@ from sage.categories.integral_domains import IntegralDomains from sage.rings.ring cimport CommutativeRing from sage.rings.ring import is_Ring -from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing +import sage.rings.abc from sage.rings.integer_ring import is_IntegerRing import sage.modules.free_module @@ -5749,7 +5749,7 @@ cdef class Matrix(sage.structure.element.Matrix): R = self.base_ring() if algorithm is None and R in _Fields: return ~self - elif algorithm is None and is_IntegerModRing(R): + elif algorithm is None and isinstance(R, sage.rings.abc.IntegerModRing): # Finite fields are handled above. # This is "easy" in that we either get an error or # the right answer. Note that of course there diff --git a/src/sage/modules/free_module.py b/src/sage/modules/free_module.py index 57c10114174..4ff7ec743a1 100644 --- a/src/sage/modules/free_module.py +++ b/src/sage/modules/free_module.py @@ -172,7 +172,7 @@ import sage.rings.ring as ring import sage.rings.integer_ring import sage.rings.rational_field -import sage.rings.finite_rings.integer_mod_ring +import sage.rings.abc import sage.rings.infinity import sage.rings.integer from sage.categories.principal_ideal_domains import PrincipalIdealDomains @@ -253,7 +253,7 @@ def create_object(self, version, key): elif base_ring in PrincipalIdealDomains(): return FreeModule_ambient_pid(base_ring, rank, sparse=sparse) - elif isinstance(base_ring, sage.rings.number_field.order.Order) \ + elif isinstance(base_ring, sage.rings.abc.Order) \ and base_ring.is_maximal() and base_ring.class_number() == 1: return FreeModule_ambient_pid(base_ring, rank, sparse=sparse) @@ -7434,7 +7434,7 @@ def element_class(R, is_sparse): elif sage.rings.rational_field.is_RationalField(R) and not is_sparse: from .vector_rational_dense import Vector_rational_dense return Vector_rational_dense - elif sage.rings.finite_rings.integer_mod_ring.is_IntegerModRing(R) and not is_sparse: + elif isinstance(R, sage.rings.abc.IntegerModRing) and not is_sparse: from .vector_mod2_dense import Vector_mod2_dense if R.order() == 2: return Vector_mod2_dense diff --git a/src/sage/rings/abc.pyx b/src/sage/rings/abc.pyx index c65e03d9ed0..147dcb4f089 100644 --- a/src/sage/rings/abc.pyx +++ b/src/sage/rings/abc.pyx @@ -32,3 +32,18 @@ cdef class ComplexDoubleField(Field): """ pass + + +class IntegerModRing: + r""" + Abstract base class for :class:`~sage.rings.finite_rings.integer_mod_ring.IntegerModRing_generic`. + """ + + pass + +class Order: + r""" + Abstract base class for :class:`~sage.rings.number_field.order.Order`. + """ + + pass diff --git a/src/sage/rings/finite_rings/integer_mod_ring.py b/src/sage/rings/finite_rings/integer_mod_ring.py index c704b2a2eb7..c225d412a11 100644 --- a/src/sage/rings/finite_rings/integer_mod_ring.py +++ b/src/sage/rings/finite_rings/integer_mod_ring.py @@ -297,7 +297,7 @@ def _unit_gens_primepowercase(p, r): @richcmp_method -class IntegerModRing_generic(quotient_ring.QuotientRing_generic): +class IntegerModRing_generic(quotient_ring.QuotientRing_generic, IntegerModRing): """ The ring of integers modulo `N`. diff --git a/src/sage/rings/number_field/order.py b/src/sage/rings/number_field/order.py index 56ef3d550bb..ec128df7834 100644 --- a/src/sage/rings/number_field/order.py +++ b/src/sage/rings/number_field/order.py @@ -47,6 +47,7 @@ from sage.rings.ring import IntegralDomain from sage.structure.sequence import Sequence from sage.rings.integer_ring import ZZ +import sage.rings.abc from sage.structure.element import is_Element from .number_field_element import OrderElement_absolute, OrderElement_relative @@ -126,7 +127,7 @@ def EquationOrder(f, names, **kwds): return K.order(K.gens()) -class Order(IntegralDomain): +class Order(IntegralDomain, sage.rings.abc.Order): r""" An order in a number field. From 8ef2b356025c3bc055f3bed1d63bce65956cb221 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 28 Sep 2021 19:08:25 -0700 Subject: [PATCH 02/61] sage.structure, sage.rings, sage.matrix: Use sage.rings.abc for IntegerModRing --- src/sage/matrix/matrix2.pyx | 9 +++++---- src/sage/matrix/matrix_space.py | 4 ++-- src/sage/rings/finite_rings/finite_field_base.pyx | 4 ++-- src/sage/structure/parent.pyx | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/sage/matrix/matrix2.pyx b/src/sage/matrix/matrix2.pyx index d4a8ec9d3a1..74e01aa7241 100644 --- a/src/sage/matrix/matrix2.pyx +++ b/src/sage/matrix/matrix2.pyx @@ -95,6 +95,7 @@ from sage.rings.real_mpfr import RealField from sage.rings.complex_mpfr import ComplexField from sage.rings.finite_rings.integer_mod_ring import IntegerModRing from sage.misc.derivative import multi_derivative +import sage.rings.abc from sage.arith.numerical_approx cimport digits_to_bits from copy import copy @@ -822,8 +823,7 @@ cdef class Matrix(Matrix1): if not K.is_integral_domain(): # The non-integral-domain case is handled almost entirely # separately. - from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing - if is_IntegerModRing(K): + if isinstance(K, sage.rings.abc.IntegerModRing): from sage.libs.pari import pari A = pari(self.lift()) b = pari(B).lift() @@ -1985,7 +1985,6 @@ cdef class Matrix(Matrix1): sage: A.determinant() == B.determinant() True """ - from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing from sage.symbolic.ring import is_SymbolicExpressionRing cdef Py_ssize_t n @@ -2031,7 +2030,7 @@ cdef class Matrix(Matrix1): return d # Special case for Z/nZ or GF(p): - if is_IntegerModRing(R) and self.is_dense(): + if isinstance(R, sage.rings.abc.IntegerModRing) and self.is_dense(): import sys # If the characteristic is prime and smaller than a machine # word, use PARI. @@ -14723,6 +14722,8 @@ cdef class Matrix(Matrix1): for i from 0 <= i < size: PyList_Append(M,f(PyList_GET_ITEM(L,i))) + from sage.rings.finite_rings.integer_mod_ring import IntegerModRing + return MatrixSpace(IntegerModRing(2), nrows=self._nrows,ncols=self._ncols).matrix(M) diff --git a/src/sage/matrix/matrix_space.py b/src/sage/matrix/matrix_space.py index 47766db0c46..eabba820926 100644 --- a/src/sage/matrix/matrix_space.py +++ b/src/sage/matrix/matrix_space.py @@ -236,7 +236,7 @@ def get_matrix_class(R, nrows, ncols, sparse, implementation): except ImportError: pass - if sage.rings.finite_rings.integer_mod_ring.is_IntegerModRing(R): + if isinstance(R, sage.rings.abc.IntegerModRing): from . import matrix_modn_dense_double, matrix_modn_dense_float if R.order() < matrix_modn_dense_float.MAX_MODULUS: return matrix_modn_dense_float.Matrix_modn_dense_float @@ -326,7 +326,7 @@ def get_matrix_class(R, nrows, ncols, sparse, implementation): if implementation is not None: raise ValueError("cannot choose an implementation for sparse matrices") - if sage.rings.finite_rings.integer_mod_ring.is_IntegerModRing(R) and R.order() < matrix_modn_sparse.MAX_MODULUS: + if isinstance(R, sage.rings.abc.IntegerModRing) and R.order() < matrix_modn_sparse.MAX_MODULUS: return matrix_modn_sparse.Matrix_modn_sparse if sage.rings.rational_field.is_RationalField(R): diff --git a/src/sage/rings/finite_rings/finite_field_base.pyx b/src/sage/rings/finite_rings/finite_field_base.pyx index 91f69730fee..f3183df44aa 100644 --- a/src/sage/rings/finite_rings/finite_field_base.pyx +++ b/src/sage/rings/finite_rings/finite_field_base.pyx @@ -40,6 +40,7 @@ from sage.misc.persist import register_unpickle_override from sage.misc.cachefunc import cached_method from sage.misc.prandom import randrange from sage.rings.integer cimport Integer +import sage.rings.abc from sage.misc.superseded import deprecation_cython as deprecation # Copied from sage.misc.fast_methods, used in __hash__() below. @@ -1342,10 +1343,9 @@ cdef class FiniteField(Field): False """ from sage.rings.integer_ring import ZZ - from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing if R is int or R is long or R is ZZ: return True - if is_IntegerModRing(R) and self.characteristic().divides(R.characteristic()): + if isinstance(R, sage.rings.abc.IntegerModRing) and self.characteristic().divides(R.characteristic()): return R.hom((self.one(),), check=False) if is_FiniteField(R): if R is self: diff --git a/src/sage/structure/parent.pyx b/src/sage/structure/parent.pyx index 4559972c94f..9d7527b913a 100644 --- a/src/sage/structure/parent.pyx +++ b/src/sage/structure/parent.pyx @@ -2642,8 +2642,8 @@ cdef class Parent(sage.structure.category_object.CategoryObject): elif self_on_left and op is operator.pow: S_is_int = parent_is_integers(S) if not S_is_int: - from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing - if is_IntegerModRing(S): + from sage.rings.abc import IntegerModRing + if isinstance(S, IntegerModRing): # We allow powering by an IntegerMod by treating it # as an integer. # From 335cd3e8f0b6b16195c5b59cfa806582b61248fa Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Thu, 30 Sep 2021 21:45:17 -0700 Subject: [PATCH 03/61] Replace all uses of is_IntegerModRing by isinstance(..., sage.rings.abc.IntegerModRing) --- src/sage/libs/singular/ring.pyx | 4 ++-- src/sage/matrix/matrix_rational_dense.pyx | 4 ++-- src/sage/rings/polynomial/multi_polynomial_ideal.py | 4 ++-- src/sage/rings/polynomial/multi_polynomial_libsingular.pyx | 4 ++-- src/sage/rings/polynomial/polynomial_element.pyx | 5 ++--- src/sage/rings/polynomial/polynomial_ring_constructor.py | 4 ++-- src/sage/rings/polynomial/polynomial_singular_interface.py | 6 +++--- src/sage/schemes/elliptic_curves/constructor.py | 4 ++-- src/sage/schemes/elliptic_curves/ell_generic.py | 4 ++-- src/sage/symbolic/ring.pyx | 4 ++-- 10 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/sage/libs/singular/ring.pyx b/src/sage/libs/singular/ring.pyx index 63b63070cd2..2f9ece4d055 100644 --- a/src/sage/libs/singular/ring.pyx +++ b/src/sage/libs/singular/ring.pyx @@ -31,7 +31,7 @@ from sage.libs.singular.decl cimport rDefault, GFInfo, ZnmInfo, nInitChar, AlgEx from sage.rings.integer cimport Integer from sage.rings.integer_ring cimport IntegerRing_class from sage.rings.integer_ring import ZZ -from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing +import sage.rings.abc from sage.rings.number_field.number_field_base cimport NumberField from sage.rings.rational_field import RationalField from sage.rings.finite_rings.finite_field_base import FiniteField as FiniteField_generic @@ -324,7 +324,7 @@ cdef ring *singular_ring_new(base_ring, n, names, term_order) except NULL: _ring = rDefault (_cf ,nvars, _names, nblcks, _order, _block0, _block1, _wvhdl) - elif is_IntegerModRing(base_ring): + elif isinstance(base_ring, sage.rings.abc.IntegerModRing): ch = base_ring.characteristic() if ch < 2: diff --git a/src/sage/matrix/matrix_rational_dense.pyx b/src/sage/matrix/matrix_rational_dense.pyx index d67529c0a7e..3432de8c349 100644 --- a/src/sage/matrix/matrix_rational_dense.pyx +++ b/src/sage/matrix/matrix_rational_dense.pyx @@ -109,7 +109,7 @@ from sage.rings.integer cimport Integer from sage.rings.ring import is_Ring from sage.rings.integer_ring import ZZ, is_IntegerRing from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF -from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing +import sage.rings.abc from sage.rings.rational_field import QQ from sage.arith.all import gcd @@ -1487,7 +1487,7 @@ cdef class Matrix_rational_dense(Matrix_dense): return A from .matrix_modn_dense_double import MAX_MODULUS - if is_IntegerModRing(R) and R.order() < MAX_MODULUS: + if isinstance(R, sage.rings.abc.IntegerModRing) and R.order() < MAX_MODULUS: b = R.order() A, d = self._clear_denom() if not b.gcd(d).is_one(): diff --git a/src/sage/rings/polynomial/multi_polynomial_ideal.py b/src/sage/rings/polynomial/multi_polynomial_ideal.py index da88a329bc6..65e5e7ee7a1 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ideal.py +++ b/src/sage/rings/polynomial/multi_polynomial_ideal.py @@ -249,6 +249,7 @@ from sage.misc.method_decorator import MethodDecorator from sage.rings.integer_ring import ZZ +import sage.rings.abc import sage.rings.polynomial.toy_buchberger as toy_buchberger import sage.rings.polynomial.toy_variety as toy_variety import sage.rings.polynomial.toy_d_basis as toy_d_basis @@ -4288,7 +4289,6 @@ def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, prot=Fal sage: I.groebner_basis('magma:GroebnerBasis') # optional - magma [a + (-60)*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 + (-79/7)*c^2 + 3/7*c, c^4 + (-10/21)*c^3 + 1/84*c^2 + 1/84*c] """ - from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing @@ -4331,7 +4331,7 @@ def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, prot=Fal deg_bound=deg_bound, mult_bound=mult_bound, prot=prot, *args, **kwds)] elif (R.term_order().is_global() - and is_IntegerModRing(B) + and isinstance(B, sage.rings.abc.IntegerModRing) and not B.is_field()): verbose("Warning: falling back to very slow toy implementation.", level=0) diff --git a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx index ec706f3129d..9380bffc850 100644 --- a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx @@ -221,6 +221,7 @@ from sage.rings.polynomial.polydict cimport ETuple from sage.rings.polynomial.polynomial_ring import is_PolynomialRing # base ring imports +import sage.rings.abc 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 @@ -229,7 +230,6 @@ from sage.rings.real_mpfr import is_RealField from sage.rings.integer_ring import is_IntegerRing, ZZ from sage.rings.integer cimport Integer from sage.rings.integer import GCD_list -from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing from sage.rings.number_field.number_field_base cimport NumberField from sage.structure.element import coerce_binop @@ -1407,7 +1407,7 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): elif is_IntegerRing(base_ring): self.__singular = singular.ring("(integer)", _vars, order=order) - elif is_IntegerModRing(base_ring): + elif isinstance(base_ring, sage.rings.abc.IntegerModRing): ch = base_ring.characteristic() if ch.is_power_of(2): exp = ch.nbits() -1 diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index f7807221d55..1e948372613 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -101,7 +101,6 @@ from sage.structure.element cimport (parent, have_same_parent, from sage.rings.rational_field import QQ, is_RationalField from sage.rings.integer_ring import ZZ, is_IntegerRing -from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing from sage.rings.integer cimport Integer, smallInteger from sage.libs.gmp.mpz cimport * from sage.rings.fraction_field import is_FractionField @@ -4446,7 +4445,7 @@ cdef class Polynomial(CommutativeAlgebraElement): n = None - if is_IntegerModRing(R) or is_IntegerRing(R): + if isinstance(R, sage.rings.abc.IntegerModRing) or is_IntegerRing(R): try: G = list(self._pari_with_name().factor()) except PariError: @@ -8124,7 +8123,7 @@ cdef class Polynomial(CommutativeAlgebraElement): if K.is_finite(): if multiplicities: raise NotImplementedError("root finding with multiplicities for this polynomial not implemented (try the multiplicities=False option)") - elif is_IntegerModRing(K): + elif isinstance(K, sage.rings.abc.IntegerModRing): # handling via the chinese remainders theorem N = K.cardinality() primes = N.prime_divisors() diff --git a/src/sage/rings/polynomial/polynomial_ring_constructor.py b/src/sage/rings/polynomial/polynomial_ring_constructor.py index c88f6705ccd..603bdaff2ec 100644 --- a/src/sage/rings/polynomial/polynomial_ring_constructor.py +++ b/src/sage/rings/polynomial/polynomial_ring_constructor.py @@ -27,9 +27,9 @@ import sage.rings.ring as ring import sage.rings.padics.padic_base_leaves as padic_base_leaves +import sage.rings.abc from sage.rings.integer import Integer from sage.rings.finite_rings.finite_field_base import is_FiniteField -from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing from sage.misc.cachefunc import weak_cached_function @@ -694,7 +694,7 @@ def _single_variate(base_ring, name, sparse=None, implementation=None, order=Non # Specialized implementations specialized = None - if is_IntegerModRing(base_ring): + if isinstance(base_ring, sage.rings.abc.IntegerModRing): n = base_ring.order() if n.is_prime(): specialized = polynomial_ring.PolynomialRing_dense_mod_p diff --git a/src/sage/rings/polynomial/polynomial_singular_interface.py b/src/sage/rings/polynomial/polynomial_singular_interface.py index 61777d5556a..d8b537789be 100644 --- a/src/sage/rings/polynomial/polynomial_singular_interface.py +++ b/src/sage/rings/polynomial/polynomial_singular_interface.py @@ -38,13 +38,13 @@ ###################################################################### import sage.rings.fraction_field +import sage.rings.abc 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 -from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing from sage.rings.real_double import is_RealDoubleField from sage.rings.rational_field import is_RationalField from sage.rings.function_field.function_field import RationalFunctionField @@ -336,7 +336,7 @@ def _singular_init_(self, singular=singular): gen = str(base_ring.gen()) self.__singular = singular.ring( "(%s,%s)"%(base_ring.characteristic(),gen), _vars, order=order, check=False) - elif is_IntegerModRing(base_ring): + elif isinstance(base_ring, sage.rings.abc.IntegerModRing): ch = base_ring.characteristic() if ch.is_power_of(2): exp = ch.nbits() -1 @@ -388,7 +388,7 @@ def can_convert_to_singular(R): if (base_ring is ZZ 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.IntegerModRing) or is_RealField(base_ring) or is_ComplexField(base_ring) or is_RealDoubleField(base_ring) diff --git a/src/sage/schemes/elliptic_curves/constructor.py b/src/sage/schemes/elliptic_curves/constructor.py index e9320cc174b..90bc4519082 100644 --- a/src/sage/schemes/elliptic_curves/constructor.py +++ b/src/sage/schemes/elliptic_curves/constructor.py @@ -25,7 +25,7 @@ import sage.rings.all as rings -from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing +import sage.rings.abc from sage.rings.polynomial.multi_polynomial_ring import is_MPolynomialRing from sage.rings.finite_rings.finite_field_constructor import is_FiniteField from sage.rings.number_field.number_field import is_NumberField @@ -464,7 +464,7 @@ def create_object(self, version, key, **kwds): elif rings.is_pAdicField(R): from .ell_padic_field import EllipticCurve_padic_field return EllipticCurve_padic_field(R, x) - elif is_FiniteField(R) or (is_IntegerModRing(R) and R.characteristic().is_prime()): + elif is_FiniteField(R) or (isinstance(R, sage.rings.abc.IntegerModRing) and R.characteristic().is_prime()): from .ell_finite_field import EllipticCurve_finite_field return EllipticCurve_finite_field(R, x) elif R in _Fields: diff --git a/src/sage/schemes/elliptic_curves/ell_generic.py b/src/sage/schemes/elliptic_curves/ell_generic.py index 912496bca28..b5207f513f0 100644 --- a/src/sage/schemes/elliptic_curves/ell_generic.py +++ b/src/sage/schemes/elliptic_curves/ell_generic.py @@ -46,6 +46,7 @@ import math +import sage.rings.abc from sage.rings.all import PolynomialRing from sage.rings.polynomial.polynomial_ring import polygen, polygens import sage.groups.additive_abelian.additive_abelian_group as groups @@ -156,8 +157,7 @@ def __init__(self, K, ainvs): # EllipticCurvePoint_finite_field for finite rings, so that we # can do some arithmetic on points over Z/NZ, for teaching # purposes. - from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing - if is_IntegerModRing(K): + if isinstance(K, sage.rings.abc.IntegerModRing): self._point = ell_point.EllipticCurvePoint_finite_field _point = ell_point.EllipticCurvePoint diff --git a/src/sage/symbolic/ring.pyx b/src/sage/symbolic/ring.pyx index ffe8d7443f2..9bc5c1db7a1 100644 --- a/src/sage/symbolic/ring.pyx +++ b/src/sage/symbolic/ring.pyx @@ -47,6 +47,7 @@ from sage.structure.element cimport Element from sage.categories.morphism cimport Morphism from sage.structure.coerce cimport is_numpy_type +import sage.rings.abc from sage.rings.integer_ring import ZZ # is_SymbolicVariable used to be defined here; re-export it @@ -205,7 +206,6 @@ cdef class SymbolicRing(CommutativeRing): from sage.rings.real_mpfr import mpfr_prec_min from sage.rings.fraction_field import is_FractionField - from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing from sage.rings.real_mpfi import is_RealIntervalField from sage.rings.complex_interval_field import is_ComplexIntervalField from sage.rings.real_arb import RealBallField @@ -234,7 +234,7 @@ cdef class SymbolicRing(CommutativeRing): or is_RealIntervalField(R) or is_ComplexIntervalField(R) or isinstance(R, RealBallField) or isinstance(R, ComplexBallField) - or is_IntegerModRing(R) or is_FiniteField(R)): + or isinstance(R, sage.rings.abc.IntegerModRing) or is_FiniteField(R)): return True elif isinstance(R, GenericSymbolicSubring): return True From f596395836a4c6e3f7a42b56acc4a805c8633abf Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 28 Sep 2021 21:14:44 -0700 Subject: [PATCH 04/61] sage.rings.finite_rings.integer_mod_ring: Fixup --- src/sage/rings/finite_rings/integer_mod_ring.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sage/rings/finite_rings/integer_mod_ring.py b/src/sage/rings/finite_rings/integer_mod_ring.py index c225d412a11..27ea7f424fc 100644 --- a/src/sage/rings/finite_rings/integer_mod_ring.py +++ b/src/sage/rings/finite_rings/integer_mod_ring.py @@ -64,6 +64,7 @@ from sage.arith.all import factor, primitive_root, CRT_basis import sage.rings.ring as ring +import sage.rings.abc from . import integer_mod import sage.rings.integer as integer import sage.rings.integer_ring as integer_ring @@ -297,7 +298,7 @@ def _unit_gens_primepowercase(p, r): @richcmp_method -class IntegerModRing_generic(quotient_ring.QuotientRing_generic, IntegerModRing): +class IntegerModRing_generic(quotient_ring.QuotientRing_generic, sage.rings.abc.IntegerModRing): """ The ring of integers modulo `N`. From af06e5b43bd15181de7b1f6123dda5839f248699 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 1 Oct 2021 09:02:22 -0700 Subject: [PATCH 05/61] is_IntegerModRing: Deprecate --- src/sage/rings/finite_rings/integer_mod_ring.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/sage/rings/finite_rings/integer_mod_ring.py b/src/sage/rings/finite_rings/integer_mod_ring.py index 27ea7f424fc..28fb2736491 100644 --- a/src/sage/rings/finite_rings/integer_mod_ring.py +++ b/src/sage/rings/finite_rings/integer_mod_ring.py @@ -244,11 +244,18 @@ def is_IntegerModRing(x): """ Return ``True`` if ``x`` is an integer modulo ring. + This function is deprecated. Use :func:`isinstance` with + :class:`sage.rings.abc.IntegerModRing` instead. + EXAMPLES:: sage: from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing sage: R = IntegerModRing(17) sage: is_IntegerModRing(R) + doctest:warning... + DeprecationWarning: the function is_IntegerModRing is deprecated. + Use isinstance(..., sage.rings.abc.IntegerModRing) instead. + See https://trac.sagemath.org/32606 for details. True sage: is_IntegerModRing(GF(13)) True @@ -259,6 +266,9 @@ def is_IntegerModRing(x): sage: is_IntegerModRing(ZZ) False """ + from sage.misc.superseded import deprecation + deprecation(32606, "the function is_IntegerModRing is deprecated. " + "Use isinstance(..., sage.rings.abc.IntegerModRing) instead.") return isinstance(x, IntegerModRing_generic) From 608148900e8764bb654ddcdcdb15a1e890acba94 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 2 Oct 2021 10:17:24 -0700 Subject: [PATCH 06/61] 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 07/61] 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 08/61] 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 09/61] 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 10/61] 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 11/61] 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 12/61] 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 13/61] 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 14/61] 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 15/61] 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 16/61] 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 17/61] 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 18/61] 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 19/61] 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 20/61] 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 21/61] 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 22/61] 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 From dd7e96c442e45b509ee607a6cbd96f2ff7bbefdc Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 3 Oct 2021 14:45:50 -0700 Subject: [PATCH 23/61] src/sage/schemes/elliptic_curves/ell_number_field.py: Add missing import --- src/sage/schemes/elliptic_curves/ell_number_field.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sage/schemes/elliptic_curves/ell_number_field.py b/src/sage/schemes/elliptic_curves/ell_number_field.py index f0bcda573df..097ca89624d 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 From d6c6e90f5d4e8653fcd776bc534aa06aa2effdd9 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 3 Oct 2021 17:26:27 -0700 Subject: [PATCH 24/61] sage.rings.abc: Add {Real,Complex}{Ball,Interval}Field --- src/sage/rings/abc.pyx | 32 ++++++++++++++++++++++++ src/sage/rings/complex_arb.pyx | 4 ++- src/sage/rings/complex_interval_field.py | 3 ++- src/sage/rings/real_arb.pyx | 3 ++- src/sage/rings/real_mpfi.pxd | 4 +-- src/sage/rings/real_mpfi.pyx | 2 +- 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/sage/rings/abc.pyx b/src/sage/rings/abc.pyx index c65e03d9ed0..66ad7030fc7 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 2fc0a3bb420..2e2643946da 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 @@ -301,7 +302,8 @@ cdef int acb_calc_func_callback(acb_ptr out, const acb_t inp, void * param, finally: sig_on() -class ComplexBallField(UniqueRepresentation, Field): + +class ComplexBallField(UniqueRepresentation, sage.rings.abc.ComplexBallField): r""" An approximation of the field of complex numbers using pairs of mid-rad intervals. diff --git a/src/sage/rings/complex_interval_field.py b/src/sage/rings/complex_interval_field.py index cee580b22a3..e046891c437 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 @@ -93,7 +94,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/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_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. From 7ce73e69d0042961c557756bbbbf25f4427445e9 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 3 Oct 2021 17:40:39 -0700 Subject: [PATCH 25/61] git grep -l -E 'is_(Real|Complex)(Interval|Ball)Field' | xargs sed -E -i.bak 's/^from sage[.]rings.*import is_((Real|Complex)(Interval|Ball)Field) *$/import sage.rings.abc/;s/is_((Real|Complex)(Interval|Ball)Field)[(]([^)]*)[)]/isinstance(\4, sage.rings.abc.\1)/g;' --- src/sage/rings/complex_interval_field.py | 2 +- src/sage/rings/number_field/number_field.py | 2 +- src/sage/rings/polynomial/polynomial_element.pyx | 8 ++++---- src/sage/rings/qqbar.py | 4 ++-- src/sage/rings/real_interval_absolute.pyx | 2 +- src/sage/rings/real_interval_field.py | 2 +- src/sage/rings/real_mpfi.pyx | 6 +++--- src/sage/symbolic/expression.pyx | 6 +++--- src/sage/symbolic/ring.pyx | 2 +- src/sage/symbolic/subring.py | 2 +- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/sage/rings/complex_interval_field.py b/src/sage/rings/complex_interval_field.py index e046891c437..ff7830505d0 100644 --- a/src/sage/rings/complex_interval_field.py +++ b/src/sage/rings/complex_interval_field.py @@ -49,7 +49,7 @@ from sage.misc.cachefunc import cached_method -def is_ComplexIntervalField(x): +def isinstance(x, sage.rings.abc.ComplexIntervalField): """ Check if ``x`` is a :class:`ComplexIntervalField`. diff --git a/src/sage/rings/number_field/number_field.py b/src/sage/rings/number_field/number_field.py index 3ad7ffa26ef..1752d3fb214 100644 --- a/src/sage/rings/number_field/number_field.py +++ b/src/sage/rings/number_field/number_field.py @@ -9949,7 +9949,7 @@ 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 is_ComplexField(codom) or isinstance(codom, sage.rings.abc.ComplexIntervalField) 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) 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_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_interval_field.py b/src/sage/rings/real_interval_field.py index 97a32ae67cc..8a00d507bc4 100644 --- a/src/sage/rings/real_interval_field.py +++ b/src/sage/rings/real_interval_field.py @@ -7,7 +7,7 @@ from sage.rings.real_mpfi import RealIntervalField_class, RealIntervalFieldElement -def is_RealIntervalField(x): +def isinstance(x, sage.rings.abc.RealIntervalField): """ Check if ``x`` is a :class:`RealIntervalField_class`. diff --git a/src/sage/rings/real_mpfi.pyx b/src/sage/rings/real_mpfi.pyx index ce83e1ddf4e..4bc459f2695 100644 --- a/src/sage/rings/real_mpfi.pyx +++ b/src/sage/rings/real_mpfi.pyx @@ -5317,15 +5317,15 @@ def RealInterval(s, upper=None, int base=10, int pad=0, min_prec=53): # The default real interval field, with precision 53 bits RIF = RealIntervalField() -def is_RealIntervalField(x): +def isinstance(x, sage.rings.abc.RealIntervalField): """ Check if ``x`` is a :class:`RealIntervalField_class`. EXAMPLES:: - sage: sage.rings.real_mpfi.is_RealIntervalField(RIF) + sage: sage.rings.real_mpfi.isinstance(RIF, sage.rings.abc.RealIntervalField) True - sage: sage.rings.real_mpfi.is_RealIntervalField(RealIntervalField(200)) + sage: sage.rings.real_mpfi.isinstance(RealIntervalField(200, sage.rings.abc.RealIntervalField)) True """ return isinstance(x, RealIntervalField_class) diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx index de4720f90a7..52fa2d2e5a3 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) + or isinstance(domain, 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 ffe8d7443f2..18174ae3212 100644 --- a/src/sage/symbolic/ring.pyx +++ b/src/sage/symbolic/ring.pyx @@ -231,7 +231,7 @@ 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, sage.rings.abc.RealIntervalField) or isinstance(R, sage.rings.abc.ComplexIntervalField) or isinstance(R, RealBallField) or isinstance(R, ComplexBallField) or is_IntegerModRing(R) or is_FiniteField(R)): diff --git a/src/sage/symbolic/subring.py b/src/sage/symbolic/subring.py index 060ad32a5ed..832d75236bc 100644 --- a/src/sage/symbolic/subring.py +++ b/src/sage/symbolic/subring.py @@ -425,7 +425,7 @@ 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) or isinstance(P, sage.rings.abc.ComplexIntervalField)): return True elif P._is_numerical(): From a8432f910c2b61ef4f4e4d681e531e11551d64ea Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 3 Oct 2021 17:50:01 -0700 Subject: [PATCH 26/61] is_{Real,Complex}{Ball,Interval}Field: Undo automatic edits --- src/sage/rings/complex_interval_field.py | 5 ++++- src/sage/rings/real_interval_field.py | 2 +- src/sage/rings/real_mpfi.pyx | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/sage/rings/complex_interval_field.py b/src/sage/rings/complex_interval_field.py index ff7830505d0..3c37e000154 100644 --- a/src/sage/rings/complex_interval_field.py +++ b/src/sage/rings/complex_interval_field.py @@ -49,7 +49,7 @@ from sage.misc.cachefunc import cached_method -def isinstance(x, sage.rings.abc.ComplexIntervalField): +def is_ComplexIntervalField(x): """ Check if ``x`` is a :class:`ComplexIntervalField`. @@ -61,8 +61,11 @@ def isinstance(x, sage.rings.abc.ComplexIntervalField): 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): """ diff --git a/src/sage/rings/real_interval_field.py b/src/sage/rings/real_interval_field.py index 8a00d507bc4..97a32ae67cc 100644 --- a/src/sage/rings/real_interval_field.py +++ b/src/sage/rings/real_interval_field.py @@ -7,7 +7,7 @@ from sage.rings.real_mpfi import RealIntervalField_class, RealIntervalFieldElement -def isinstance(x, sage.rings.abc.RealIntervalField): +def is_RealIntervalField(x): """ Check if ``x`` is a :class:`RealIntervalField_class`. diff --git a/src/sage/rings/real_mpfi.pyx b/src/sage/rings/real_mpfi.pyx index 4bc459f2695..ce83e1ddf4e 100644 --- a/src/sage/rings/real_mpfi.pyx +++ b/src/sage/rings/real_mpfi.pyx @@ -5317,15 +5317,15 @@ def RealInterval(s, upper=None, int base=10, int pad=0, min_prec=53): # The default real interval field, with precision 53 bits RIF = RealIntervalField() -def isinstance(x, sage.rings.abc.RealIntervalField): +def is_RealIntervalField(x): """ Check if ``x`` is a :class:`RealIntervalField_class`. EXAMPLES:: - sage: sage.rings.real_mpfi.isinstance(RIF, sage.rings.abc.RealIntervalField) + sage: sage.rings.real_mpfi.is_RealIntervalField(RIF) True - sage: sage.rings.real_mpfi.isinstance(RealIntervalField(200, sage.rings.abc.RealIntervalField)) + sage: sage.rings.real_mpfi.is_RealIntervalField(RealIntervalField(200)) True """ return isinstance(x, RealIntervalField_class) From 6209c1fdab2879e042970014628459ccbdda7e7f Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 3 Oct 2021 18:03:22 -0700 Subject: [PATCH 27/61] src/sage/rings/complex_interval_field.py: Add deprecation warning to doctest output --- src/sage/rings/complex_interval_field.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/sage/rings/complex_interval_field.py b/src/sage/rings/complex_interval_field.py index 3c37e000154..05758d9956b 100644 --- a/src/sage/rings/complex_interval_field.py +++ b/src/sage/rings/complex_interval_field.py @@ -56,6 +56,10 @@ 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) From 5cb3d59d6724546ff37e3329cd28fe239e95fb5a Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 3 Oct 2021 18:04:23 -0700 Subject: [PATCH 28/61] Fix imports, consolidate isinstance calls --- src/sage/rings/number_field/number_field.py | 1 - src/sage/symbolic/expression.pyx | 4 ++-- src/sage/symbolic/ring.pyx | 7 ++++--- src/sage/symbolic/subring.py | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/sage/rings/number_field/number_field.py b/src/sage/rings/number_field/number_field.py index 1752d3fb214..d6694f1bb9a 100644 --- a/src/sage/rings/number_field/number_field.py +++ b/src/sage/rings/number_field/number_field.py @@ -9946,7 +9946,6 @@ def hilbert_symbol(self, a, b, P = None): 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 isinstance(codom, sage.rings.abc.ComplexIntervalField) or \ diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx index 52fa2d2e5a3..0d2d194560c 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 = (isinstance(domain, sage.rings.abc.RealIntervalField) - or isinstance(domain, sage.rings.abc.ComplexIntervalField) + is_interval = (isinstance(domain, (sage.rings.abc.RealIntervalField, + sage.rings.abc.ComplexIntervalField)) or is_AlgebraicField(domain) or is_AlgebraicRealField(domain)) zero = domain(0) diff --git a/src/sage/symbolic/ring.pyx b/src/sage/symbolic/ring.pyx index 18174ae3212..d0022b060d9 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 isinstance(R, sage.rings.abc.RealIntervalField) or isinstance(R, sage.rings.abc.ComplexIntervalField) - 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 832d75236bc..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 - isinstance(P, sage.rings.abc.RealIntervalField) or isinstance(P, sage.rings.abc.ComplexIntervalField)): + isinstance(P, (sage.rings.abc.RealIntervalField, + sage.rings.abc.ComplexIntervalField))): return True elif P._is_numerical(): From be1db022c9bb35ca0875a5c7bdd8a99ede246d97 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 3 Oct 2021 19:32:26 -0700 Subject: [PATCH 29/61] src/sage/rings/abc.pxd: Add cdef class RealIntervalField --- src/sage/rings/abc.pxd | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/sage/rings/abc.pxd b/src/sage/rings/abc.pxd index ea998549070..5b2aec37eff 100644 --- a/src/sage/rings/abc.pxd +++ b/src/sage/rings/abc.pxd @@ -5,6 +5,11 @@ cdef class RealField(Field): pass +cdef class RealIntervalField(Field): + + pass + + cdef class RealDoubleField(Field): pass From 13607cb249da2bdedaee511a7741b744bd439ca6 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 3 Oct 2021 19:43:01 -0700 Subject: [PATCH 30/61] src/sage/dynamics/arithmetic_dynamics/projective_ds.py: Remove unused import --- src/sage/dynamics/arithmetic_dynamics/projective_ds.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sage/dynamics/arithmetic_dynamics/projective_ds.py b/src/sage/dynamics/arithmetic_dynamics/projective_ds.py index 3c56fd3885b..96df43c2d8d 100644 --- a/src/sage/dynamics/arithmetic_dynamics/projective_ds.py +++ b/src/sage/dynamics/arithmetic_dynamics/projective_ds.py @@ -80,7 +80,6 @@ class initialization directly. from sage.rings.polynomial.flatten import FlatteningMorphism, UnflatteningMorphism from sage.rings.morphism import RingHomomorphism_im_gens from sage.rings.number_field.number_field_ideal import NumberFieldFractionalIdeal -from sage.rings.number_field.number_field import is_NumberField from sage.rings.padics.all import Qp from sage.rings.polynomial.multi_polynomial_ring_base import is_MPolynomialRing from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing From 271e04420c0868f1d9630e7c3feb68b2c83003c7 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 3 Oct 2021 20:55:33 -0700 Subject: [PATCH 31/61] src/sage/rings/real_interval_absolute.pyx: Fix imports --- src/sage/rings/real_interval_absolute.pyx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sage/rings/real_interval_absolute.pyx b/src/sage/rings/real_interval_absolute.pyx index 16a275aab2b..7b39d84b5fa 100644 --- a/src/sage/rings/real_interval_absolute.pyx +++ b/src/sage/rings/real_interval_absolute.pyx @@ -10,12 +10,13 @@ from sage.structure.factory import UniqueFactory from sage.structure.element cimport RingElement, ModuleElement, Element, FieldElement from sage.rings.ring cimport Field from sage.rings.integer cimport Integer +import sage.rings.abc from sage.structure.parent cimport Parent from sage.structure.element cimport parent from sage.rings.real_mpfr import RR_min_prec -from sage.rings.real_mpfi import RealIntervalField, RealIntervalFieldElement, is_RealIntervalField +from sage.rings.real_mpfi import RealIntervalField, RealIntervalFieldElement from sage.rings.rational_field import QQ cdef Integer zero = Integer(0) From fc039f12c354c9f0c3cb55373bcabaa897500e91 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 3 Oct 2021 20:57:07 -0700 Subject: [PATCH 32/61] src/sage/symbolic/ring.pyx: Fix imports --- src/sage/symbolic/ring.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/symbolic/ring.pyx b/src/sage/symbolic/ring.pyx index d0022b060d9..7e899398a9b 100644 --- a/src/sage/symbolic/ring.pyx +++ b/src/sage/symbolic/ring.pyx @@ -32,6 +32,7 @@ The symbolic ring # **************************************************************************** from sage.rings.integer cimport Integer +import sage.rings.abc from sage.symbolic.expression cimport ( is_Expression, @@ -207,7 +208,6 @@ cdef class SymbolicRing(CommutativeRing): from sage.rings.fraction_field import is_FractionField from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing from sage.rings.real_mpfi import is_RealIntervalField - from sage.rings.complex_interval_field import is_ComplexIntervalField from sage.rings.real_arb import RealBallField from sage.rings.complex_arb import ComplexBallField from sage.rings.polynomial.polynomial_ring import is_PolynomialRing From 19ac6fd5e7826aa726a555bf73dfcde0f753e579 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 4 Oct 2021 00:00:40 -0700 Subject: [PATCH 33/61] src/sage/rings/complex_interval_field.py: Fixup deprecation warning in doctest output --- src/sage/rings/complex_interval_field.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/complex_interval_field.py b/src/sage/rings/complex_interval_field.py index 05758d9956b..013977aa338 100644 --- a/src/sage/rings/complex_interval_field.py +++ b/src/sage/rings/complex_interval_field.py @@ -56,11 +56,11 @@ def is_ComplexIntervalField(x): EXAMPLES:: sage: from sage.rings.complex_interval_field import is_ComplexIntervalField as is_CIF + sage: is_CIF(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 f31deb3c73264040962e0d7b9f43bc0d38d07d8c Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Mon, 4 Oct 2021 08:49:16 -0700 Subject: [PATCH 34/61] src/sage/rings/qqbar.py: Remove unused import --- src/sage/rings/qqbar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/qqbar.py b/src/sage/rings/qqbar.py index a36b5de3c72..63b566f47f2 100644 --- a/src/sage/rings/qqbar.py +++ b/src/sage/rings/qqbar.py @@ -566,7 +566,7 @@ from sage.rings.real_mpfr import RR from sage.rings.real_mpfi import RealIntervalField, RIF, is_RealIntervalFieldElement, RealIntervalField_class from sage.rings.complex_mpfr import ComplexField -from sage.rings.complex_interval_field import ComplexIntervalField, is_ComplexIntervalField +from sage.rings.complex_interval_field import ComplexIntervalField from sage.rings.complex_interval import is_ComplexIntervalFieldElement from sage.rings.polynomial.all import PolynomialRing from sage.rings.polynomial.polynomial_element import is_Polynomial From 37ee682cde696bd9a49b61b2f5081f042d4b3f68 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 5 Oct 2021 16:34:57 -0700 Subject: [PATCH 35/61] sage.structure.element.Expression: New abc for sage.symbolic.expression.Expression --- src/sage/structure/element.pxd | 4 +++- src/sage/structure/element.pyx | 11 +++++++++++ src/sage/symbolic/expression.pyx | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/sage/structure/element.pxd b/src/sage/structure/element.pxd index 3cc480aa18c..5c6e295a4b8 100644 --- a/src/sage/structure/element.pxd +++ b/src/sage/structure/element.pxd @@ -236,9 +236,11 @@ cdef class AlgebraElement(RingElement): cdef class CommutativeAlgebraElement(CommutativeRingElement): pass -cdef class InfinityElement(RingElement): +cdef class Expression(CommutativeRingElement): pass +cdef class InfinityElement(RingElement): + pass cdef class Vector(ModuleElementWithMutability): cdef Py_ssize_t _degree diff --git a/src/sage/structure/element.pyx b/src/sage/structure/element.pyx index d610bbb71cc..2e12a318981 100644 --- a/src/sage/structure/element.pyx +++ b/src/sage/structure/element.pyx @@ -47,6 +47,7 @@ abstract base classes. EuclideanDomainElement FieldElement CommutativeAlgebraElement + Expression AlgebraElement Matrix InfinityElement @@ -3254,6 +3255,16 @@ cdef class CommutativeRingElement(RingElement): ############################################## +cdef class Expression(CommutativeRingElement): + + r""" + Abstract base class for :class:`~sage.symbolic.expression.Expression`. + """ + + pass + + ############################################## + cdef class Vector(ModuleElementWithMutability): cdef bint is_sparse_c(self): raise NotImplementedError diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx index de4720f90a7..5f49c78a260 100644 --- a/src/sage/symbolic/expression.pyx +++ b/src/sage/symbolic/expression.pyx @@ -385,6 +385,7 @@ from cpython.object cimport Py_EQ, Py_NE, Py_LE, Py_GE, Py_LT, Py_GT from sage.cpython.string cimport str_to_bytes, char_to_str from sage.structure.element cimport RingElement, Element, Matrix +from sage.structure.element cimport Expression as Expression_abc from sage.symbolic.complexity_measures import string_length from sage.symbolic.function cimport SymbolicFunction from sage.rings.rational import Rational @@ -694,7 +695,7 @@ def _subs_fun_make_dict(s): raise TypeError(msg.format(s)) -cdef class Expression(CommutativeRingElement): +cdef class Expression(Expression_abc): cdef GEx _gobj From 56d1c36fbe3862ed104560137442774594ad8dab Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 5 Oct 2021 16:49:41 -0700 Subject: [PATCH 36/61] git grep -l -E 'is_Expression' | xargs sed -E -i.bak 's/sage[.]symbolic.*import is_Expression *$/sage.structure.element import Expression/;s/is_Expression[(]([^)]*)[)]/isinstance(\1, Expression)/g;' --- src/sage/calculus/all.py | 4 ++-- src/sage/calculus/integration.pyx | 4 ++-- src/sage/ext/fast_callable.pyx | 8 +++---- src/sage/plot/contour_plot.py | 14 ++++++------ src/sage/plot/plot3d/plot3d.py | 4 ++-- src/sage/rings/padics/factory.py | 12 +++++----- .../schemes/berkovich/berkovich_cp_element.py | 22 +++++++++---------- src/sage/sets/condition_set.py | 4 ++-- src/sage/structure/parent.pyx | 4 ++-- src/sage/symbolic/callable.py | 4 ++-- src/sage/symbolic/comparison_impl.pxi | 14 ++++++------ src/sage/symbolic/expression.pxd | 2 +- src/sage/symbolic/expression.pyx | 14 ++++++------ src/sage/symbolic/function.pyx | 4 ++-- src/sage/symbolic/relation.py | 12 +++++----- src/sage/symbolic/ring.pyx | 2 +- 16 files changed, 64 insertions(+), 64 deletions(-) diff --git a/src/sage/calculus/all.py b/src/sage/calculus/all.py index 1f89c3f7ffe..4cd480570fd 100644 --- a/src/sage/calculus/all.py +++ b/src/sage/calculus/all.py @@ -58,8 +58,8 @@ def symbolic_expression(x): 2*x^2 + 3 sage: type(a) - sage: from sage.symbolic.expression import is_Expression - sage: is_Expression(a) + sage: from sage.structure.element import Expression + sage: isinstance(a, Expression) True sage: a in SR True diff --git a/src/sage/calculus/integration.pyx b/src/sage/calculus/integration.pyx index 56456173632..508ad2d6537 100644 --- a/src/sage/calculus/integration.pyx +++ b/src/sage/calculus/integration.pyx @@ -612,8 +612,8 @@ def monte_carlo_integral(func, xl, xu, size_t calls, algorithm='plain', "more items in upper and lower limits" ).format(len(vars), tuple(vars), target_dim)) - from sage.symbolic.expression import is_Expression - if is_Expression(func): + from sage.structure.element import Expression + if isinstance(func, Expression): if params: to_sub = dict(zip(vars[-len(params):], params)) func = func.subs(to_sub) diff --git a/src/sage/ext/fast_callable.pyx b/src/sage/ext/fast_callable.pyx index 11d4b652ceb..fb26e1f2d50 100644 --- a/src/sage/ext/fast_callable.pyx +++ b/src/sage/ext/fast_callable.pyx @@ -428,7 +428,7 @@ def fast_callable(x, domain=None, vars=None, vars = et._etb._vars else: from sage.symbolic.callable import is_CallableSymbolicExpression - from sage.symbolic.expression import is_Expression + from sage.structure.element import Expression if not vars: # fast_float passes empty list/tuple @@ -439,7 +439,7 @@ def fast_callable(x, domain=None, vars=None, vars = x.arguments() if expect_one_var and len(vars) != 1: raise ValueError(f"passed expect_one_var=True, but the callable expression takes {len(vars)} arguments") - elif is_Expression(x): + elif isinstance(x, Expression): from sage.symbolic.ring import is_SymbolicVariable if vars is None: vars = x.variables() @@ -999,8 +999,8 @@ cdef class Expression: return ExpressionIPow(es._etb, s, o) else: # I really don't like this, but I can't think of a better way - from sage.symbolic.expression import is_Expression - if is_Expression(o) and o in ZZ: + from sage.structure.element import Expression + if isinstance(o, Expression) and o in ZZ: es = s return ExpressionIPow(es._etb, s, ZZ(o)) else: diff --git a/src/sage/plot/contour_plot.py b/src/sage/plot/contour_plot.py index b1d9533c90f..27577d396d6 100644 --- a/src/sage/plot/contour_plot.py +++ b/src/sage/plot/contour_plot.py @@ -1217,8 +1217,8 @@ def f(x,y): options.pop('contours', None) incol = options.pop('fillcolor', 'blue') bordercol = options.pop('cmap', [None])[0] - from sage.symbolic.expression import is_Expression - if not is_Expression(f): + from sage.structure.element import Expression + if not isinstance(f, Expression): return region_plot(lambda x, y: f(x, y) < 0, xrange, yrange, borderwidth=linewidths, borderstyle=linestyles, incol=incol, bordercol=bordercol, @@ -1499,7 +1499,7 @@ def region_plot(f, xrange, yrange, plot_points, incol, outcol, bordercol, """ from sage.plot.all import Graphics from sage.plot.misc import setup_for_eval_on_grid - from sage.symbolic.expression import is_Expression + from sage.structure.element import Expression from warnings import warn import numpy @@ -1507,10 +1507,10 @@ def region_plot(f, xrange, yrange, plot_points, incol, outcol, bordercol, f = [f] feqs = [equify(g) for g in f - if is_Expression(g) and g.operator() is operator.eq + if isinstance(g, Expression) and g.operator() is operator.eq and not equify(g).is_zero()] f = [equify(g) for g in f - if not (is_Expression(g) and g.operator() is operator.eq)] + if not (isinstance(g, Expression) and g.operator() is operator.eq)] neqs = len(feqs) if neqs > 1: warn("There are at least 2 equations; " @@ -1620,8 +1620,8 @@ def equify(f): -1 """ from sage.calculus.all import symbolic_expression - from sage.symbolic.expression import is_Expression - if not is_Expression(f): + from sage.structure.element import Expression + if not isinstance(f, Expression): return lambda x, y: -1 if f(x, y) else 1 op = f.operator() diff --git a/src/sage/plot/plot3d/plot3d.py b/src/sage/plot/plot3d/plot3d.py index d5951640950..d95d332bf18 100644 --- a/src/sage/plot/plot3d/plot3d.py +++ b/src/sage/plot/plot3d/plot3d.py @@ -306,10 +306,10 @@ def to_cartesian(self, func, params=None): Graphics3d Object """ - from sage.symbolic.expression import is_Expression + from sage.structure.element import Expression from sage.rings.real_mpfr import is_RealNumber from sage.rings.integer import is_Integer - if params is not None and (is_Expression(func) or is_RealNumber(func) or is_Integer(func)): + if params is not None and (isinstance(func, Expression) or is_RealNumber(func) or is_Integer(func)): return self.transform(**{ self.dep_var: func, self.indep_vars[0]: params[0], diff --git a/src/sage/rings/padics/factory.py b/src/sage/rings/padics/factory.py index 90c54a2524a..abfce6c44c9 100644 --- a/src/sage/rings/padics/factory.py +++ b/src/sage/rings/padics/factory.py @@ -2534,8 +2534,8 @@ def Zq(q, prec = None, type = 'capped-rel', modulus = None, names=None, prec = Integer(prec) if isinstance(names, (list, tuple)): names = names[0] - from sage.symbolic.expression import is_Expression - if not (modulus is None or is_Polynomial(modulus) or is_Expression(modulus)): + from sage.structure.element import Expression + if not (modulus is None or is_Polynomial(modulus) or isinstance(modulus, Expression)): raise TypeError("modulus must be a polynomial") if names is not None and not isinstance(names, str): names = str(names) @@ -3271,9 +3271,9 @@ def create_key_and_extra_args(self, base, modulus, prec = None, print_mode = Non if print_max_terse_terms is None: print_max_terse_terms = base._printer._max_terse_terms() show_prec = _canonicalize_show_prec(base._prec_type(), print_mode, show_prec) - from sage.symbolic.expression import is_Expression + from sage.structure.element import Expression if check: - if is_Expression(modulus): + if isinstance(modulus, Expression): if len(modulus.variables()) != 1: raise ValueError("symbolic expression must be in only one variable") exact_modulus = modulus.polynomial(base.exact_field()) @@ -3378,8 +3378,8 @@ def create_object(self, version, key, approx_modulus=None, shift_seed=None): if version[0] < 8: (polytype, base, premodulus, approx_modulus, names, prec, halt, print_mode, print_pos, print_sep, print_alphabet, print_max_ram_terms, print_max_unram_terms, print_max_terse_terms, implementation) = key - from sage.symbolic.expression import is_Expression - if is_Expression(premodulus): + from sage.structure.element import Expression + if isinstance(premodulus, Expression): exact_modulus = premodulus.polynomial(base.exact_field()) elif is_Polynomial(premodulus): exact_modulus = premodulus.change_ring(base.exact_field()) diff --git a/src/sage/schemes/berkovich/berkovich_cp_element.py b/src/sage/schemes/berkovich/berkovich_cp_element.py index 9c730a31626..ef419c0b50a 100644 --- a/src/sage/schemes/berkovich/berkovich_cp_element.py +++ b/src/sage/schemes/berkovich/berkovich_cp_element.py @@ -34,7 +34,7 @@ # ***************************************************************************** from sage.structure.element import Element -from sage.symbolic.expression import is_Expression +from sage.structure.element import Expression from sage.rings.real_mpfr import RR, is_RealNumber from sage.rings.padics.padic_generic_element import pAdicGenericElement from sage.rings.padics.padic_base_generic import pAdicBaseGeneric @@ -118,16 +118,16 @@ def __init__(self, parent, center, radius=None, power=None, prec=20, space_type= # check if the radius and the center are functions center_func_check = is_FunctionFieldElement(center) or is_Polynomial(center) or\ - isinstance(center, FractionFieldElement_1poly_field) or is_Expression(center) + isinstance(center, FractionFieldElement_1poly_field) or isinstance(center, Expression) radius_func_check = is_FunctionFieldElement(radius) or is_Polynomial(radius) or\ - isinstance(radius, FractionFieldElement_1poly_field) or is_Expression(radius) + isinstance(radius, FractionFieldElement_1poly_field) or isinstance(radius, Expression) if center_func_check: # check that both center and radii are supported univariate function center_expr_check = False radius_expr_check = False if error_check: - if is_Expression(center): + if isinstance(center, Expression): if len(center.variables()) != 1: raise ValueError("an expression with %s " % (len(center.variables())) + "variables cannot define the centers approximating a type IV point") @@ -136,16 +136,16 @@ def __init__(self, parent, center, radius=None, power=None, prec=20, space_type= center_expr_check = True if not radius_func_check: raise TypeError("center was passed a function but radius was not a function") - if is_Expression(radius): + if isinstance(radius, Expression): if len(radius.variables()) != 1: raise ValueError("an expression with %s " % (len(radius.variables())) + "variables cannot define the radii approximating a type IV point") else: radius_expr_check = True else: - if is_Expression(center): + if isinstance(center, Expression): center_expr_check = True - if is_Expression(radius): + if isinstance(radius, Expression): radius_expr_check = True self._type = 4 self._prec = prec @@ -216,7 +216,7 @@ def __init__(self, parent, center, radius=None, power=None, prec=20, space_type= center.normalize_coordinates() # make sure the radius coerces into the reals if not is_RealNumber(radius): - if is_Expression(radius): + if isinstance(radius, Expression): radius = RR(radius) elif RR.has_coerce_map_from(radius.parent()): radius = RR(radius) @@ -259,7 +259,7 @@ def __init__(self, parent, center, radius=None, power=None, prec=20, space_type= raise ValueError('could not convert %s to %s' % (center, self._base_space)) # make sure the radius coerces into the reals if not is_RealNumber(radius): - if is_Expression(radius): + if isinstance(radius, Expression): radius = RR(radius) elif RR.has_coerce_map_from(radius.parent()): radius = RR(radius) @@ -375,7 +375,7 @@ def __init__(self, parent, center, radius=None, power=None, prec=20, space_type= self._type = 2 return if radius is not None: - if is_Expression(radius): + if isinstance(radius, Expression): try: power = QQ(radius.log(self._p).expand_log()) except TypeError: @@ -659,7 +659,7 @@ def diameter(self, basepoint=Infinity): from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing R = PolynomialRing(QQ, names="x") x = R.gens()[0] - if is_Expression(self._radius_func): + if isinstance(self._radius_func, Expression): radius_func_variable = self._radius_func.variables()[0] radius_expr = self._radius_func.subs({radius_func_variable: x}) else: diff --git a/src/sage/sets/condition_set.py b/src/sage/sets/condition_set.py index 757014ace6c..2660a52077b 100644 --- a/src/sage/sets/condition_set.py +++ b/src/sage/sets/condition_set.py @@ -19,7 +19,7 @@ from sage.categories.enumerated_sets import EnumeratedSets from sage.misc.cachefunc import cached_method from sage.misc.misc import _stable_uniq -from sage.symbolic.expression import is_Expression +from sage.structure.element import Expression from sage.symbolic.callable import is_CallableSymbolicExpression from sage.symbolic.ring import SR @@ -165,7 +165,7 @@ def __classcall_private__(cls, universe, *predicates, vars=None, names=None, cat if vars is None: vars = predicate.args() callable_symbolic_predicates.append(predicate) - elif is_Expression(predicate): + elif isinstance(predicate, Expression): if names is None: raise TypeError('use callable symbolic expressions or provide variable names') if vars is None: diff --git a/src/sage/structure/parent.pyx b/src/sage/structure/parent.pyx index 4559972c94f..53df4273f29 100644 --- a/src/sage/structure/parent.pyx +++ b/src/sage/structure/parent.pyx @@ -1169,8 +1169,8 @@ cdef class Parent(sage.structure.category_object.CategoryObject): elif EQ: return True else: - from sage.symbolic.expression import is_Expression - return is_Expression(EQ) + from sage.structure.element import Expression + return isinstance(EQ, Expression) # if comparing gives an Expression, then it must be an equation. # We return *true* here, even though the equation # EQ must have evaluated to False for us to get to diff --git a/src/sage/symbolic/callable.py b/src/sage/symbolic/callable.py index 758fa7ff790..f1a45811db8 100644 --- a/src/sage/symbolic/callable.py +++ b/src/sage/symbolic/callable.py @@ -109,8 +109,8 @@ def is_CallableSymbolicExpression(x): sage: is_CallableSymbolicExpression(foo) False """ - from sage.symbolic.expression import is_Expression - return is_Expression(x) and isinstance(x.parent(), CallableSymbolicExpressionRing_class) + from sage.structure.element import Expression + return isinstance(x, Expression) and isinstance(x.parent(), CallableSymbolicExpressionRing_class) class CallableSymbolicExpressionFunctor(ConstructionFunctor): def __init__(self, arguments): diff --git a/src/sage/symbolic/comparison_impl.pxi b/src/sage/symbolic/comparison_impl.pxi index 9d73c7359fe..2b112b271cd 100644 --- a/src/sage/symbolic/comparison_impl.pxi +++ b/src/sage/symbolic/comparison_impl.pxi @@ -79,9 +79,9 @@ cpdef int print_order(lhs, rhs) except -2: sage: print_order(SR(oo), sqrt(2)) 1 """ - if not is_Expression(lhs): + if not isinstance(lhs, Expression): lhs = SR(lhs) - if not is_Expression(rhs): + if not isinstance(rhs, Expression): rhs = SR(rhs) return print_order_c(lhs, rhs) @@ -103,7 +103,7 @@ class _print_key(object): sage: _print_key(1) """ - self.ex = ex if is_Expression(ex) else SR(ex) + self.ex = ex if isinstance(ex, Expression) else SR(ex) def __lt__(self, other): """ @@ -171,7 +171,7 @@ class _math_key(object): sage: _math_key(1) """ - self.ex = ex if is_Expression(ex) else SR(ex) + self.ex = ex if isinstance(ex, Expression) else SR(ex) def __lt__(self, other): """ @@ -283,9 +283,9 @@ cpdef int mixed_order(lhs, rhs) except -2: """ if lhs is rhs: return 0 - if not is_Expression(lhs): + if not isinstance(lhs, Expression): lhs = SR(lhs) - if not is_Expression(rhs): + if not isinstance(rhs, Expression): rhs = SR(rhs) less_than = _mixed_key(lhs) < _mixed_key(rhs) if less_than: @@ -318,7 +318,7 @@ class _mixed_key(object): sage: _mixed_key(1) """ - self.ex = ex if is_Expression(ex) else SR(ex) + self.ex = ex if isinstance(ex, Expression) else SR(ex) def __lt__(self, other): """ diff --git a/src/sage/symbolic/expression.pxd b/src/sage/symbolic/expression.pxd index 1fa578d43c3..be27fb8b224 100644 --- a/src/sage/symbolic/expression.pxd +++ b/src/sage/symbolic/expression.pxd @@ -1,4 +1,4 @@ -cpdef bint is_Expression(x) +cpdef bint isinstance(x, Expression) cpdef _repr_Expression(x) cpdef _latex_Expression(x) cpdef new_Expression(parent, x) diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx index 5f49c78a260..ed615c42429 100644 --- a/src/sage/symbolic/expression.pyx +++ b/src/sage/symbolic/expression.pyx @@ -406,18 +406,18 @@ include "pynac.pxi" include "pynac_impl.pxi" -cpdef bint is_Expression(x): +cpdef bint isinstance(x, Expression): """ Return True if *x* is a symbolic Expression. EXAMPLES:: - sage: from sage.symbolic.expression import is_Expression - sage: is_Expression(x) + sage: from sage.structure.element import Expression + sage: isinstance(x, Expression) True - sage: is_Expression(2) + sage: isinstance(2, Expression) False - sage: is_Expression(SR(2)) + sage: isinstance(SR(2, Expression)) True """ return isinstance(x, Expression) @@ -473,7 +473,7 @@ cpdef bint _is_SymbolicVariable(x): sage: ZZ['x'] Univariate Polynomial Ring in x over Integer Ring """ - return is_Expression(x) and is_a_symbol((x)._gobj) + return isinstance(x, Expression) and is_a_symbol((x)._gobj) def _dict_update_check_duplicate(dict d1, dict d2): @@ -13579,7 +13579,7 @@ cpdef new_Expression(parent, x): x + 1 """ cdef GEx exp - if is_Expression(x): + if isinstance(x, Expression): return new_Expression_from_GEx(parent, (x)._gobj) if hasattr(x, '_symbolic_'): return x._symbolic_(parent) diff --git a/src/sage/symbolic/function.pyx b/src/sage/symbolic/function.pyx index 7feef512673..15fe84b3195 100644 --- a/src/sage/symbolic/function.pyx +++ b/src/sage/symbolic/function.pyx @@ -334,7 +334,7 @@ cdef class Function(SageObject): try: evalf = self._evalf_ # catch AttributeError early if any(self._is_numerical(x) for x in args): - if not any(is_Expression(x) for x in args): + if not any(isinstance(x, Expression) for x in args): p = coercion_model.common_parent(*args) return evalf(*args, parent=p) except Exception: @@ -553,7 +553,7 @@ cdef class Function(SageObject): else: # coerce == False for a in args: - if not is_Expression(a): + if not isinstance(a, Expression): raise TypeError("arguments must be symbolic expressions") return call_registered_function(self._serial, self._nargs, args, hold, diff --git a/src/sage/symbolic/relation.py b/src/sage/symbolic/relation.py index 28b1bce0301..698eed45d0e 100644 --- a/src/sage/symbolic/relation.py +++ b/src/sage/symbolic/relation.py @@ -1058,14 +1058,14 @@ def solve(f, *args, **kwds): if isinstance(f, (list, tuple)) and len(f) == 1: # f is a list with a single element - if is_Expression(f[0]): + if isinstance(f[0], Expression): f = f[0] else: raise TypeError("The first argument to solve() should be a " "symbolic expression or a list of symbolic " "expressions.") - if is_Expression(f): # f is a single expression + if isinstance(f, Expression): # f is a single expression return _solve_expression(f, x, explicit_solutions, multiplicities, to_poly_solve, solution_dict, algorithm, domain) if not isinstance(f, (list, tuple)): @@ -1095,7 +1095,7 @@ def solve(f, *args, **kwds): if algorithm == 'sympy': from sympy import solve as ssolve from sage.interfaces.sympy import sympy_set_to_list - if is_Expression(f): # f is a single expression + if isinstance(f, Expression): # f is a single expression sympy_f = f._sympy_() else: sympy_f = [s._sympy_() for s in f] @@ -1103,7 +1103,7 @@ def solve(f, *args, **kwds): sympy_vars = (x._sympy_(),) else: sympy_vars = tuple([v._sympy_() for v in x]) - if len(sympy_vars) > 1 or not is_Expression(f): + if len(sympy_vars) > 1 or not isinstance(f, Expression): ret = ssolve(sympy_f, sympy_vars, dict=True) if isinstance(ret, dict): if solution_dict: @@ -1569,14 +1569,14 @@ def solve_mod(eqns, modulus, solution_dict=False): """ from sage.rings.all import Integer, Integers, crt_basis - from sage.symbolic.expression import is_Expression + from sage.structure.element import Expression from sage.misc.all import cartesian_product_iterator from sage.modules.all import vector from sage.matrix.all import matrix if not isinstance(eqns, (list, tuple)): eqns = [eqns] - eqns = [eq if is_Expression(eq) else (eq.lhs() - eq.rhs()) for eq in eqns] + eqns = [eq if isinstance(eq, Expression) else (eq.lhs() - eq.rhs()) for eq in eqns] modulus = Integer(modulus) if modulus < 1: raise ValueError("the modulus must be a positive integer") diff --git a/src/sage/symbolic/ring.pyx b/src/sage/symbolic/ring.pyx index ffe8d7443f2..cca5dec8fee 100644 --- a/src/sage/symbolic/ring.pyx +++ b/src/sage/symbolic/ring.pyx @@ -870,7 +870,7 @@ cdef class SymbolicRing(CommutativeRing): ... ValueError: cannot specify n for multiple symbol names """ - if is_Expression(name): + if isinstance(name, Expression): return name if not isinstance(name, (basestring, list, tuple)): name = repr(name) From 08bf900dd929f3859110130c98155e4fbe1d95e4 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 5 Oct 2021 16:54:12 -0700 Subject: [PATCH 37/61] is_Expression: Undo automatic edit of the definition; deprecate --- src/sage/symbolic/expression.pyx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx index ed615c42429..3f6cb7b0f3d 100644 --- a/src/sage/symbolic/expression.pyx +++ b/src/sage/symbolic/expression.pyx @@ -406,20 +406,24 @@ include "pynac.pxi" include "pynac_impl.pxi" -cpdef bint isinstance(x, Expression): +cpdef bint is_Expression(x): """ Return True if *x* is a symbolic Expression. EXAMPLES:: - sage: from sage.structure.element import Expression - sage: isinstance(x, Expression) + sage: from sage.symbolic.expression import is_Expression + sage: is_Expression(x) + DeprecationWarning: is_Expression is deprecated; + use isinstance(..., sage.structure.element.Expression) instead True - sage: isinstance(2, Expression) + sage: is_Expression(2) False - sage: isinstance(SR(2, Expression)) + sage: is_Expression(SR(2)) True """ + from sage.misc.superseded import deprecation + deprecation(32638, 'is_Expression is deprecated; use isinstance(..., sage.structure.element.Expression) instead') return isinstance(x, Expression) From 4e5fe35817b7bc335af222e540e367b7704e2661 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 5 Oct 2021 18:56:37 -0700 Subject: [PATCH 38/61] src/sage/symbolic/expression.pxd: Undo automatic edit --- src/sage/symbolic/expression.pxd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/symbolic/expression.pxd b/src/sage/symbolic/expression.pxd index be27fb8b224..1fa578d43c3 100644 --- a/src/sage/symbolic/expression.pxd +++ b/src/sage/symbolic/expression.pxd @@ -1,4 +1,4 @@ -cpdef bint isinstance(x, Expression) +cpdef bint is_Expression(x) cpdef _repr_Expression(x) cpdef _latex_Expression(x) cpdef new_Expression(parent, x) From e14259b90bb05950c575731090220f08f41f563f Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 5 Oct 2021 19:14:48 -0700 Subject: [PATCH 39/61] src/sage/ext/fast_callable.pyx: Fix up clash of sage.ext.fast_callable.Expression and sage.structure.element.Expression --- src/sage/ext/fast_callable.pyx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/sage/ext/fast_callable.pyx b/src/sage/ext/fast_callable.pyx index fb26e1f2d50..50fb5e21f7a 100644 --- a/src/sage/ext/fast_callable.pyx +++ b/src/sage/ext/fast_callable.pyx @@ -308,6 +308,7 @@ from sage.rings.all import RDF, CDF from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ from sage.structure.element cimport parent +from sage.structure.element cimport Expression as Expression_abc def fast_callable(x, domain=None, vars=None, @@ -428,7 +429,6 @@ def fast_callable(x, domain=None, vars=None, vars = et._etb._vars else: from sage.symbolic.callable import is_CallableSymbolicExpression - from sage.structure.element import Expression if not vars: # fast_float passes empty list/tuple @@ -439,7 +439,7 @@ def fast_callable(x, domain=None, vars=None, vars = x.arguments() if expect_one_var and len(vars) != 1: raise ValueError(f"passed expect_one_var=True, but the callable expression takes {len(vars)} arguments") - elif isinstance(x, Expression): + elif isinstance(x, Expression_abc): from sage.symbolic.ring import is_SymbolicVariable if vars is None: vars = x.variables() @@ -999,8 +999,7 @@ cdef class Expression: return ExpressionIPow(es._etb, s, o) else: # I really don't like this, but I can't think of a better way - from sage.structure.element import Expression - if isinstance(o, Expression) and o in ZZ: + if isinstance(o, Expression_abc) and o in ZZ: es = s return ExpressionIPow(es._etb, s, ZZ(o)) else: From daed11ede2e3dd63897eb16cda2a23d56b0dc220 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 5 Oct 2021 21:20:17 -0700 Subject: [PATCH 40/61] src/sage/symbolic/function.pyx: Update imports --- src/sage/symbolic/function.pyx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/sage/symbolic/function.pyx b/src/sage/symbolic/function.pyx index 15fe84b3195..7d7773163b8 100644 --- a/src/sage/symbolic/function.pyx +++ b/src/sage/symbolic/function.pyx @@ -139,12 +139,11 @@ is attempted, and after that ``sin()`` which succeeds:: #***************************************************************************** from sage.structure.sage_object cimport SageObject -from sage.structure.element cimport Element, parent +from sage.structure.element cimport Element, parent, Expression from sage.misc.lazy_attribute import lazy_attribute from .expression import ( call_registered_function, find_registered_function, register_or_update_function, - get_sfunction_from_hash, - is_Expression + get_sfunction_from_hash ) from .expression import get_sfunction_from_serial as get_sfunction_from_serial From c52251b59f888d3d9a2821ee5189daff95d056a9 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 5 Oct 2021 21:21:18 -0700 Subject: [PATCH 41/61] src/sage/symbolic/ring.pyx: Update imports --- src/sage/symbolic/ring.pyx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sage/symbolic/ring.pyx b/src/sage/symbolic/ring.pyx index cca5dec8fee..512c996a8d3 100644 --- a/src/sage/symbolic/ring.pyx +++ b/src/sage/symbolic/ring.pyx @@ -34,7 +34,6 @@ The symbolic ring from sage.rings.integer cimport Integer from sage.symbolic.expression cimport ( - is_Expression, _latex_Expression, _repr_Expression, new_Expression, @@ -43,7 +42,7 @@ from sage.symbolic.expression cimport ( new_Expression_symbol, ) -from sage.structure.element cimport Element +from sage.structure.element cimport Element, Expression from sage.categories.morphism cimport Morphism from sage.structure.coerce cimport is_numpy_type From 0f305308bcb2c5860f88ab6e687b3d5b614c6d85 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 6 Oct 2021 09:15:18 -0700 Subject: [PATCH 42/61] src/sage/misc/sageinspect.py: Fix up a doctest on the source code of src/sage/symbolic/expression.pyx --- src/sage/misc/sageinspect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/misc/sageinspect.py b/src/sage/misc/sageinspect.py index 72c9cdf1d22..be7d50783bc 100644 --- a/src/sage/misc/sageinspect.py +++ b/src/sage/misc/sageinspect.py @@ -2308,7 +2308,7 @@ def sage_getsourcelines(obj): ...) sage: x = var('x') sage: lines, lineno = sage_getsourcelines(x); lines[0:5] - ['cdef class Expression(CommutativeRingElement):\n', + ['cdef class Expression(...):\n', '\n', ' cdef GEx _gobj\n', '\n', From 2a81e0f5a362bafa6612bab4fb4f31ddccc731cd Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 6 Oct 2021 09:15:31 -0700 Subject: [PATCH 43/61] src/sage/symbolic/expression.pyx: Fix markup of doctest output --- src/sage/symbolic/expression.pyx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx index 3f6cb7b0f3d..518ea825d1e 100644 --- a/src/sage/symbolic/expression.pyx +++ b/src/sage/symbolic/expression.pyx @@ -414,6 +414,7 @@ cpdef bint is_Expression(x): sage: from sage.symbolic.expression import is_Expression sage: is_Expression(x) + doctest:warning... DeprecationWarning: is_Expression is deprecated; use isinstance(..., sage.structure.element.Expression) instead True From 88886ee09c6e402de41ddd415cae0e48d807ce13 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 6 Oct 2021 15:17:03 -0700 Subject: [PATCH 44/61] src/sage/symbolic/expression.pyx: Fix doctest output --- src/sage/symbolic/expression.pyx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx index 518ea825d1e..8a75c1c435c 100644 --- a/src/sage/symbolic/expression.pyx +++ b/src/sage/symbolic/expression.pyx @@ -408,7 +408,10 @@ include "pynac_impl.pxi" cpdef bint is_Expression(x): """ - Return True if *x* is a symbolic Expression. + Return True if ``x`` is a symbolic expression. + + This method is deprecated. Use :func:`isinstance` with + :class:`sage.structure.element.Expression` instead. EXAMPLES:: @@ -417,6 +420,7 @@ cpdef bint is_Expression(x): doctest:warning... DeprecationWarning: is_Expression is deprecated; use isinstance(..., sage.structure.element.Expression) instead + See https://trac.sagemath.org/32638 for details. True sage: is_Expression(2) False From cf9b75a008388ceaa019e28a3eda883350ba7ee1 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 6 Oct 2021 21:25:22 -0700 Subject: [PATCH 45/61] src/sage/symbolic/relation.py: Remove unused import; use sage.structure.element.Expression for isinstance --- src/sage/symbolic/relation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/symbolic/relation.py b/src/sage/symbolic/relation.py index 698eed45d0e..62eabb3b356 100644 --- a/src/sage/symbolic/relation.py +++ b/src/sage/symbolic/relation.py @@ -1029,7 +1029,7 @@ def solve(f, *args, **kwds): or a list of symbolic expressions. """ from sage.symbolic.ring import is_SymbolicVariable - from sage.symbolic.expression import Expression, is_Expression + from sage.structure.element import Expression explicit_solutions = kwds.get('explicit_solutions', None) multiplicities = kwds.get('multiplicities', None) to_poly_solve = kwds.get('to_poly_solve', None) From 8cc350081bebd83ea605e62adde3bb07347bbfca Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Wed, 13 Oct 2021 14:35:27 -0700 Subject: [PATCH 46/61] src/sage/rings/polynomial/polynomial_singular_interface.py: Fixup merge --- src/sage/rings/polynomial/polynomial_singular_interface.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sage/rings/polynomial/polynomial_singular_interface.py b/src/sage/rings/polynomial/polynomial_singular_interface.py index b0e067f1f78..cd0ff7a33a1 100644 --- a/src/sage/rings/polynomial/polynomial_singular_interface.py +++ b/src/sage/rings/polynomial/polynomial_singular_interface.py @@ -384,7 +384,6 @@ def can_convert_to_singular(R): if (base_ring is ZZ 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, sage.rings.abc.ComplexField, sage.rings.abc.RealDoubleField, sage.rings.abc.ComplexDoubleField, sage.rings.abc.IntegerModRing))): From 49dc68abd409d07fb0b73cc7c1cc159c7439b810 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 16 Oct 2021 20:19:36 -0700 Subject: [PATCH 47/61] sage.rings.abc: Add SymbolicRing, CallableSymbolicExpressionRing --- src/sage/rings/abc.pyx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/sage/rings/abc.pyx b/src/sage/rings/abc.pyx index 147dcb4f089..530408d1b18 100644 --- a/src/sage/rings/abc.pyx +++ b/src/sage/rings/abc.pyx @@ -47,3 +47,19 @@ class Order: """ pass + + +cdef class SymbolicRing(CommutativeRing): + r""" + Abstract base class for :class:`~sage.rings.symbolic.ring.SymbolicRing`. + """ + + pass + + +class CallableSymbolicExpressionRing(SymbolicRing): + r""" + Abstract base class for :class:`~sage.rings.symbolic.callable.CallableSymbolicExpressionRing_class`. + """ + + pass From 5d50f092e297e92f014584fe2165ce4ae01c867b Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 16 Oct 2021 20:19:06 -0700 Subject: [PATCH 48/61] sage.symbolic: Use sage.rings.abc.{SymbolicRing,CallableSymbolicExpressionRing} --- src/sage/symbolic/callable.py | 3 ++- src/sage/symbolic/ring.pxd | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sage/symbolic/callable.py b/src/sage/symbolic/callable.py index f1a45811db8..dd0c5e1f67b 100644 --- a/src/sage/symbolic/callable.py +++ b/src/sage/symbolic/callable.py @@ -61,6 +61,7 @@ SyntaxError: can...t assign to function call """ +import sage.rings.abc from sage.symbolic.ring import SymbolicRing, SR from sage.categories.pushout import ConstructionFunctor @@ -267,7 +268,7 @@ def unify_arguments(self, x): return tuple(new_list) -class CallableSymbolicExpressionRing_class(SymbolicRing): +class CallableSymbolicExpressionRing_class(SymbolicRing, sage.rings.abc.CallableSymbolicExpressionRing): def __init__(self, arguments): """ EXAMPLES: diff --git a/src/sage/symbolic/ring.pxd b/src/sage/symbolic/ring.pxd index ed358c4a3c7..9e628098dd1 100644 --- a/src/sage/symbolic/ring.pxd +++ b/src/sage/symbolic/ring.pxd @@ -1,4 +1,4 @@ -from sage.rings.ring cimport CommutativeRing +cimport sage.rings.abc -cdef class SymbolicRing(CommutativeRing): +cdef class SymbolicRing(sage.rings.abc.SymbolicRing): cdef public dict symbols From a862442d66f3fcfebb310c9a264fb274a26965d0 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 16 Oct 2021 20:20:17 -0700 Subject: [PATCH 49/61] src/sage/dynamics/arithmetic_dynamics/affine_ds.py: Use sage.rings.abc.SymbolicRing --- src/sage/dynamics/arithmetic_dynamics/affine_ds.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/sage/dynamics/arithmetic_dynamics/affine_ds.py b/src/sage/dynamics/arithmetic_dynamics/affine_ds.py index 116ee4e12b9..84ddb002252 100644 --- a/src/sage/dynamics/arithmetic_dynamics/affine_ds.py +++ b/src/sage/dynamics/arithmetic_dynamics/affine_ds.py @@ -56,9 +56,9 @@ class initialization directly. from sage.schemes.affine.affine_subscheme import AlgebraicScheme_subscheme_affine from sage.schemes.generic.morphism import SchemeMorphism_polynomial from sage.structure.element import get_coercion_model -from sage.symbolic.ring import is_SymbolicExpressionRing -from sage.symbolic.ring import var -from sage.symbolic.ring import SR + +import sage.rings.abc + class DynamicalSystem_affine(SchemeMorphism_polynomial_affine_space, DynamicalSystem): @@ -275,7 +275,7 @@ def __classcall_private__(cls, morphism_or_polys, domain=None): else: polys = [PR(poly) for poly in polys] if domain is None: - if PR is SR: + if isinstance(PR, sage.rings.abc.SymbolicRing): raise TypeError("Symbolic Ring cannot be the base ring") if fraction_field: PR = PR.ring() @@ -292,7 +292,7 @@ def __classcall_private__(cls, morphism_or_polys, domain=None): if len(polys) != domain.ambient_space().coordinate_ring().ngens(): raise ValueError('Number of polys does not match dimension of {}'.format(domain)) R = domain.base_ring() - if R is SR: + if isinstance(R, sage.rings.abc.SymbolicRing): raise TypeError("Symbolic Ring cannot be the base ring") if not is_AffineSpace(domain) and not isinstance(domain, AlgebraicScheme_subscheme_affine): raise ValueError('"domain" must be an affine scheme') @@ -529,7 +529,8 @@ def dynatomic_polynomial(self, period): F = G.dynatomic_polynomial(period) T = G.domain().coordinate_ring() S = self.domain().coordinate_ring() - if is_SymbolicExpressionRing(F.parent()): + if isinstance(F.parent(), sage.rings.abc.SymbolicRing): + from sage.symbolic.ring import var u = var(self.domain().coordinate_ring().variable_name()) return F.subs({F.variables()[0]:u,F.variables()[1]:1}) elif T(F.denominator()).degree() == 0: From 24cd270773ef77900747bb0d5a6cbf7683b79a64 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 16 Oct 2021 20:20:31 -0700 Subject: [PATCH 50/61] src/sage/matrix/matrix2.pyx: Use sage.rings.abc.SymbolicRing --- src/sage/matrix/matrix2.pyx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/sage/matrix/matrix2.pyx b/src/sage/matrix/matrix2.pyx index f94e77474c8..ae7be68d55a 100644 --- a/src/sage/matrix/matrix2.pyx +++ b/src/sage/matrix/matrix2.pyx @@ -1984,8 +1984,6 @@ cdef class Matrix(Matrix1): sage: A.determinant() == B.determinant() True """ - from sage.symbolic.ring import is_SymbolicExpressionRing - cdef Py_ssize_t n n = self._ncols @@ -2074,7 +2072,7 @@ cdef class Matrix(Matrix1): # is then assumed to not be a variable in the symbolic ring. But this # resulted in further exceptions/ errors. - var = 'A0123456789' if is_SymbolicExpressionRing(R) else 'x' + var = 'A0123456789' if isinstance(R, sage.rings.abc.SymbolicRing) else 'x' try: charp = self.charpoly(var, algorithm="df") except ValueError: From 5fb862e568f0635c93267847079adc8695e83295 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 16 Oct 2021 20:49:07 -0700 Subject: [PATCH 51/61] Deprecate is_[Callable]SymbolicExpressionRing, replace uses by isinstance(..., sage.rings.abc....) --- src/sage/modules/free_module.py | 8 ++++---- src/sage/modules/free_module_element.pyx | 6 +++--- src/sage/symbolic/callable.py | 8 +++++++- src/sage/symbolic/expression.pyx | 5 ++--- src/sage/symbolic/ring.pyx | 10 +++++++++- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/sage/modules/free_module.py b/src/sage/modules/free_module.py index 1e3c73da128..ba5e1eb6ccb 100644 --- a/src/sage/modules/free_module.py +++ b/src/sage/modules/free_module.py @@ -7448,12 +7448,12 @@ def element_class(R, is_sparse): return sage.modules.vector_real_double_dense.Vector_real_double_dense 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 - return sage.modules.vector_symbolic_dense.Vector_symbolic_dense - elif sage.symbolic.callable.is_CallableSymbolicExpressionRing(R) and not is_sparse: + elif isinstance(R, sage.rings.abc.CallableSymbolicExpressionRing) and not is_sparse: import sage.modules.vector_callable_symbolic_dense return sage.modules.vector_callable_symbolic_dense.Vector_callable_symbolic_dense + elif isinstance(R, sage.rings.abc.SymbolicRing) and not is_sparse: + import sage.modules.vector_symbolic_dense + return sage.modules.vector_symbolic_dense.Vector_symbolic_dense else: if is_sparse: return free_module_element.FreeModuleElement_generic_sparse diff --git a/src/sage/modules/free_module_element.pyx b/src/sage/modules/free_module_element.pyx index 21d898c117c..4be7ff4ede4 100644 --- a/src/sage/modules/free_module_element.pyx +++ b/src/sage/modules/free_module_element.pyx @@ -118,6 +118,7 @@ from sage.structure.element cimport Element, ModuleElement, RingElement, Vector from sage.structure.element import canonical_coercion from sage.structure.richcmp cimport richcmp_not_equal, richcmp, rich_to_bool +cimport sage.rings.abc from sage.rings.ring import is_Ring from sage.rings.infinity import Infinity, AnInfinity from sage.rings.integer_ring import ZZ @@ -3933,9 +3934,8 @@ cdef class FreeModuleElement(Vector): # abstract base class (r, theta) |--> r*cos(theta)^2 + r*sin(theta)^2 """ if var is None: - from sage.symbolic.callable import is_CallableSymbolicExpressionRing - from sage.calculus.all import jacobian - if is_CallableSymbolicExpressionRing(self.coordinate_ring()): + if isinstance(self.coordinate_ring(), sage.rings.abc.CallableSymbolicExpressionRing): + from sage.calculus.all import jacobian return jacobian(self, self.coordinate_ring().arguments()) else: raise ValueError("No differentiation variable specified.") diff --git a/src/sage/symbolic/callable.py b/src/sage/symbolic/callable.py index dd0c5e1f67b..42d24bbce5f 100644 --- a/src/sage/symbolic/callable.py +++ b/src/sage/symbolic/callable.py @@ -82,12 +82,18 @@ def is_CallableSymbolicExpressionRing(x): sage: from sage.symbolic.callable import is_CallableSymbolicExpressionRing sage: is_CallableSymbolicExpressionRing(QQ) + doctest:warning... + DeprecationWarning: is_CallableSymbolicExpressionRing is deprecated; + use isinstance(..., sage.rings.abc.CallableSymbolicExpressionRing instead + See https://trac.sagemath.org/32665 for details. False sage: var('x,y,z') (x, y, z) sage: is_CallableSymbolicExpressionRing(CallableSymbolicExpressionRing((x,y,z))) True """ + from sage.misc.superseded import deprecation + deprecation(32665, 'is_CallableSymbolicExpressionRing is deprecated; use isinstance(..., sage.rings.abc.CallableSymbolicExpressionRing instead') return isinstance(x, CallableSymbolicExpressionRing_class) def is_CallableSymbolicExpression(x): @@ -301,7 +307,7 @@ def _coerce_map_from_(self, R): sage: g.parent().has_coerce_map_from(f.parent()) True """ - if is_CallableSymbolicExpressionRing(R): + if isinstance(R, CallableSymbolicExpressionRing): args = self.arguments() if all(a in args for a in R.arguments()): return True diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx index d7932ea3486..6966a183590 100644 --- a/src/sage/symbolic/expression.pyx +++ b/src/sage/symbolic/expression.pyx @@ -13080,10 +13080,8 @@ cdef class Expression(Expression_abc): """ from sage.symbolic.integration.integral import \ integral, _normalize_integral_input - from sage.symbolic.callable import \ - CallableSymbolicExpressionRing, is_CallableSymbolicExpressionRing R = self._parent - if is_CallableSymbolicExpressionRing(R): + if isinstance(R, sage.rings.abc.CallableSymbolicExpressionRing): f = SR(self) f, v, a, b = _normalize_integral_input(f, *args) # Definite integral with respect to a positional variable. @@ -13092,6 +13090,7 @@ cdef class Expression(Expression_abc): arguments.remove(v) if arguments: arguments = tuple(arguments) + from sage.symbolic.callable import CallableSymbolicExpressionRing R = CallableSymbolicExpressionRing(arguments, check=False) else: # all arguments are gone R = SR diff --git a/src/sage/symbolic/ring.pyx b/src/sage/symbolic/ring.pyx index ae1efb6e0aa..b5f53c07cf0 100644 --- a/src/sage/symbolic/ring.pyx +++ b/src/sage/symbolic/ring.pyx @@ -1309,7 +1309,13 @@ def the_SymbolicRing(): def is_SymbolicExpressionRing(R): """ - Returns True if *R* is the symbolic expression ring. + Returns True if ``R`` is the symbolic expression ring. + + This function is deprecated. Instead, either use ``R is SR`` (to + test whether ``R`` is the unique symbolic ring ``SR``); or + ``isinstance`` with :class:`~sage.rings.abc.SymbolicRing` + (when also symbolic subrings and callable symbolic rings should + be accepted). EXAMPLES:: @@ -1319,6 +1325,8 @@ def is_SymbolicExpressionRing(R): sage: is_SymbolicExpressionRing(SR) True """ + from sage.misc.superseded import deprecation + deprecation(32665, 'is_SymbolicExpressionRing is deprecated; use "... is SR" or isinstance(..., sage.rings.abc.SymbolicRing instead') return R is SR def var(name, **kwds): From ee4bd52cfa12357872281a57ec96f63eb2b96a18 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 16 Oct 2021 21:27:05 -0700 Subject: [PATCH 52/61] sage.rings.abc, sage.symbolic.ring: Fixup --- src/sage/modules/free_module_element.pyx | 2 +- src/sage/rings/abc.pxd | 7 ++++++- src/sage/symbolic/ring.pyx | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/sage/modules/free_module_element.pyx b/src/sage/modules/free_module_element.pyx index 4be7ff4ede4..0e3e55f4a23 100644 --- a/src/sage/modules/free_module_element.pyx +++ b/src/sage/modules/free_module_element.pyx @@ -118,7 +118,7 @@ from sage.structure.element cimport Element, ModuleElement, RingElement, Vector from sage.structure.element import canonical_coercion from sage.structure.richcmp cimport richcmp_not_equal, richcmp, rich_to_bool -cimport sage.rings.abc +import sage.rings.abc from sage.rings.ring import is_Ring from sage.rings.infinity import Infinity, AnInfinity from sage.rings.integer_ring import ZZ diff --git a/src/sage/rings/abc.pxd b/src/sage/rings/abc.pxd index 5b2aec37eff..a53b512d62f 100644 --- a/src/sage/rings/abc.pxd +++ b/src/sage/rings/abc.pxd @@ -1,4 +1,4 @@ -from .ring cimport Field +from .ring cimport CommutativeRing, Field cdef class RealField(Field): @@ -23,3 +23,8 @@ cdef class ComplexField(Field): cdef class ComplexDoubleField(Field): pass + + +cdef class SymbolicRing(CommutativeRing): + + pass diff --git a/src/sage/symbolic/ring.pyx b/src/sage/symbolic/ring.pyx index b5f53c07cf0..128ff05a8e1 100644 --- a/src/sage/symbolic/ring.pyx +++ b/src/sage/symbolic/ring.pyx @@ -32,6 +32,8 @@ The symbolic ring # **************************************************************************** from sage.rings.integer cimport Integer +from sage.rings.ring cimport CommutativeRing + import sage.rings.abc from sage.symbolic.expression cimport ( @@ -61,7 +63,7 @@ KEYWORDS = set(keyword.kwlist).union(['exec', 'print', 'None', 'True', 'False', 'nonlocal']) -cdef class SymbolicRing(CommutativeRing): +cdef class SymbolicRing(sage.rings.abc.SymbolicRing): """ Symbolic Ring, parent object for all symbolic expressions. """ From b484d51976ddc0aebd6072faa9986512a8090d53 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 16 Oct 2021 21:55:56 -0700 Subject: [PATCH 53/61] src/sage/symbolic/callable.py: Fixup --- src/sage/symbolic/callable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/symbolic/callable.py b/src/sage/symbolic/callable.py index 42d24bbce5f..5f3a7bea659 100644 --- a/src/sage/symbolic/callable.py +++ b/src/sage/symbolic/callable.py @@ -307,7 +307,7 @@ def _coerce_map_from_(self, R): sage: g.parent().has_coerce_map_from(f.parent()) True """ - if isinstance(R, CallableSymbolicExpressionRing): + if isinstance(R, CallableSymbolicExpressionRing_class): args = self.arguments() if all(a in args for a in R.arguments()): return True From fad87c08a90d8b13ba4a48102b2faca3911c4cf6 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 16 Oct 2021 21:56:17 -0700 Subject: [PATCH 54/61] Expression.is_callable: New --- src/sage/symbolic/expression.pyx | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx index 6966a183590..c43196f4b48 100644 --- a/src/sage/symbolic/expression.pyx +++ b/src/sage/symbolic/expression.pyx @@ -3124,6 +3124,22 @@ cdef class Expression(Expression_abc): return obj.is_square() + def is_callable(self): + r""" + Return ``True`` if ``self`` is a callable symbolic expression. + + EXAMPLES:: + + sage: var('a x y z') + (a, x, y, z) + sage: f(x, y) = a + 2*x + 3*y + z + sage: f.is_callable() + True + sage: (a+2*x).is_callable() + False + """ + return isinstance(self.parent(), sage.rings.abc.CallableSymbolicExpressionRing) + def left_hand_side(self): """ If self is a relational expression, return the left hand side @@ -4632,7 +4648,7 @@ cdef class Expression(Expression_abc): symb = vars[0] elif len(vars) == 0: return self._parent(0) - elif sage.symbolic.callable.is_CallableSymbolicExpression(self): + elif self.is_callable(): return self.gradient() else: raise ValueError("No differentiation variable specified.") @@ -12714,7 +12730,6 @@ cdef class Expression(Expression_abc): sage: plot(f,0,1) Graphics object consisting of 1 graphics primitive """ - from sage.symbolic.callable import is_CallableSymbolicExpression from sage.symbolic.ring import is_SymbolicVariable from sage.plot.plot import plot @@ -12730,7 +12745,7 @@ cdef class Expression(Expression_abc): break if param is None: - if is_CallableSymbolicExpression(self): + if self.is_callable(): A = self.arguments() if len(A) == 0: raise ValueError("function has no input arguments") From 4bc059ba6807fb35cdfc04bf4d0b5a51bd9def20 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sat, 16 Oct 2021 21:59:07 -0700 Subject: [PATCH 55/61] src/sage/ext/fast_callable.pyx: Remove use of is_CallableSymbolicExpression --- src/sage/ext/fast_callable.pyx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/sage/ext/fast_callable.pyx b/src/sage/ext/fast_callable.pyx index d54d501226c..da1ad9ed5b3 100644 --- a/src/sage/ext/fast_callable.pyx +++ b/src/sage/ext/fast_callable.pyx @@ -428,13 +428,11 @@ def fast_callable(x, domain=None, vars=None, et = x vars = et._etb._vars else: - from sage.symbolic.callable import is_CallableSymbolicExpression - if not vars: # fast_float passes empty list/tuple vars = None - if is_CallableSymbolicExpression(x): + if isinstance(x, Expression_abc) and x.is_callable(): if vars is None: vars = x.arguments() if expect_one_var and len(vars) != 1: From 8624925fadce22241a0e7abdc9952ee4bbcf4a0a Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 17 Oct 2021 09:20:31 -0700 Subject: [PATCH 56/61] src/sage/symbolic/ring.pyx: Update doctest output with deprecation warning --- src/sage/symbolic/ring.pyx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/sage/symbolic/ring.pyx b/src/sage/symbolic/ring.pyx index 128ff05a8e1..115c1361791 100644 --- a/src/sage/symbolic/ring.pyx +++ b/src/sage/symbolic/ring.pyx @@ -1323,6 +1323,10 @@ def is_SymbolicExpressionRing(R): sage: from sage.symbolic.ring import is_SymbolicExpressionRing sage: is_SymbolicExpressionRing(ZZ) + doctest:warning... + DeprecationWarning: is_SymbolicExpressionRing is deprecated; + use "... is SR" or isinstance(..., sage.rings.abc.SymbolicRing instead + See https://trac.sagemath.org/32665 for details. False sage: is_SymbolicExpressionRing(SR) True From 37da733abd71b634e542334ec2d460bff002e444 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 17 Oct 2021 09:24:05 -0700 Subject: [PATCH 57/61] src/sage/sets/condition_set.py: Remove use of is_CallableSymbolicExpression --- src/sage/sets/condition_set.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/sage/sets/condition_set.py b/src/sage/sets/condition_set.py index 80ff63d2260..34265775dd3 100644 --- a/src/sage/sets/condition_set.py +++ b/src/sage/sets/condition_set.py @@ -20,14 +20,9 @@ from sage.misc.cachefunc import cached_method from sage.misc.misc import _stable_uniq from sage.structure.element import Expression - -try: - from sage.symbolic.callable import is_CallableSymbolicExpression -except ImportError: - is_CallableSymbolicExpression = lambda x: False - from .set import Set, Set_base, Set_boolean_operators, Set_add_sub_operators + class ConditionSet(Set_generic, Set_base, Set_boolean_operators, Set_add_sub_operators, UniqueRepresentation): r""" @@ -160,7 +155,7 @@ def __classcall_private__(cls, universe, *predicates, vars=None, names=None, cat other_predicates = [] for predicate in predicates: - if is_CallableSymbolicExpression(predicate): + if isinstance(predicate, Expression) and predicate.is_callable(): if names is None: names = tuple(str(var) for var in predicate.args()) elif len(names) != len(predicate.args()): @@ -271,7 +266,7 @@ def _repr_condition(self, predicate): sage: ZeroDimButNotNullary._repr_condition(ZeroDimButNotNullary._predicates[0]) 't > 0' """ - if is_CallableSymbolicExpression(predicate): + if isinstance(predicate, Expression) and predicate.is_callable(): args = self.arguments() if len(args) == 1: args = args[0] @@ -364,7 +359,7 @@ def _call_predicate(self, predicate, element): sage: Nullary._call_predicate(predicate, element) t > 0 """ - if is_CallableSymbolicExpression(predicate): + if isinstance(predicate, Expression) and predicate.is_callable(): if len(predicate.arguments()) != 1: return predicate(*element) return predicate(element) From 80a8f9ec657528c814767bfd0da0500a7d650f2f Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 17 Oct 2021 09:36:35 -0700 Subject: [PATCH 58/61] sage.plot: Remove use of is_CallableSymbolicExpression, is_SymbolicEquation --- src/sage/plot/contour_plot.py | 4 ++-- src/sage/plot/misc.py | 6 ++---- src/sage/plot/plot3d/plot3d.py | 6 +++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/sage/plot/contour_plot.py b/src/sage/plot/contour_plot.py index 27577d396d6..690311744e7 100644 --- a/src/sage/plot/contour_plot.py +++ b/src/sage/plot/contour_plot.py @@ -1195,8 +1195,8 @@ def f(x,y): ... ValueError: only one of color or rgbcolor should be specified """ - from sage.symbolic.expression import is_SymbolicEquation - if is_SymbolicEquation(f): + from sage.structure.element import Expression + if isinstance(f, Expression) and f.is_relational(): if f.operator() != operator.eq: raise ValueError("input to implicit plot must be function " "or equation") diff --git a/src/sage/plot/misc.py b/src/sage/plot/misc.py index b57976552b6..edab4ce4183 100644 --- a/src/sage/plot/misc.py +++ b/src/sage/plot/misc.py @@ -15,7 +15,7 @@ from sage.ext.fast_eval import fast_float -from sage.structure.element import is_Vector +from sage.structure.element import is_Vector, Expression def setup_for_eval_on_grid(funcs, ranges, plot_points=None, return_vars=False): """ @@ -187,15 +187,13 @@ def unify_arguments(funcs): sage: sage.plot.misc.unify_arguments((x+y,x-y)) ((x, y), (x, y)) """ - from sage.symbolic.callable import is_CallableSymbolicExpression - vars=set() free_variables=set() if not isinstance(funcs, (list, tuple)): funcs = [funcs] for f in funcs: - if is_CallableSymbolicExpression(f): + if isinstance(f, Expression) and f.is_callable(): f_args = set(f.arguments()) vars.update(f_args) else: diff --git a/src/sage/plot/plot3d/plot3d.py b/src/sage/plot/plot3d/plot3d.py index 9678373657c..0fccc9cb1ec 100644 --- a/src/sage/plot/plot3d/plot3d.py +++ b/src/sage/plot/plot3d/plot3d.py @@ -1046,13 +1046,13 @@ def plot3d(f, urange, vrange, adaptive=False, transformation=None, **kwds): Graphics3d Object """ if transformation is not None: - params=None - from sage.symbolic.callable import is_CallableSymbolicExpression + params = None + from sage.structure.element import Expression # First, determine the parameters for f (from the first item of urange # and vrange, preferably). if len(urange) == 3 and len(vrange) == 3: params = (urange[0], vrange[0]) - elif is_CallableSymbolicExpression(f): + elif isinstance(f, Expression) and f.is_callable(): params = f.variables() from sage.modules.vector_callable_symbolic_dense import Vector_callable_symbolic_dense From a287531e1dd03d32d554735a26966852c3c56057 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 17 Oct 2021 09:51:50 -0700 Subject: [PATCH 59/61] src/sage/schemes/elliptic_curves/constructor.py: Remove use of SR, is_SymbolicEquation; add test for symbolic input --- .../schemes/elliptic_curves/constructor.py | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/sage/schemes/elliptic_curves/constructor.py b/src/sage/schemes/elliptic_curves/constructor.py index 90bc4519082..bd7cfc8239d 100644 --- a/src/sage/schemes/elliptic_curves/constructor.py +++ b/src/sage/schemes/elliptic_curves/constructor.py @@ -36,10 +36,8 @@ _Fields = Fields() from sage.structure.sequence import Sequence -from sage.structure.element import parent +from sage.structure.element import parent, Expression from sage.structure.factory import UniqueFactory -from sage.symbolic.ring import SR -from sage.symbolic.expression import is_SymbolicEquation class EllipticCurveFactory(UniqueFactory): @@ -385,6 +383,20 @@ def create_key_and_extra_args(self, x=None, y=None, j=None, minimal_twist=True, incorrect data may lead to wrong results of computations instead of errors or warnings. + TESTS:: + + sage: var('x', 'y', 'v', 'w') + (x, y, v, w) + sage: EllipticCurve(y^2 + y > x^3 + x - 9) + Traceback (most recent call last): + ... + ValueError: no symbolic relations other than equalities are allowed + sage: E = EllipticCurve(y^2 + y == x^3 + x - 9) + sage: E is EllipticCurve(y^2 + y - ( x^3 + x - 9 )) + True + sage: R. = QQ[] + sage: E is EllipticCurve(y^2 + y - ( x^3 + x - 9 )) + True """ R = None if is_Ring(x): @@ -400,10 +412,13 @@ def create_key_and_extra_args(self, x=None, y=None, j=None, minimal_twist=True, raise ValueError("First parameter (if present) must be a ring when j is specified") x = coefficients_from_j(j, minimal_twist) - if is_SymbolicEquation(x): + if isinstance(x, Expression) and x.is_relational(): + import operator + if x.operator() != operator.eq: + raise ValueError("no symbolic relations other than equalities are allowed") x = x.lhs() - x.rhs() - if parent(x) is SR: + if isinstance(parent(x), sage.rings.abc.SymbolicRing): x = x._polynomial_(rings.QQ['x', 'y']) if is_MPolynomial(x): From c9861d16af2e435985ab77239f6eb5b0c775fa6b Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 17 Oct 2021 10:05:46 -0700 Subject: [PATCH 60/61] src/sage/interfaces/qepcad.py: Remove use of is_SymbolicEquation --- src/sage/interfaces/qepcad.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/sage/interfaces/qepcad.py b/src/sage/interfaces/qepcad.py index 29baa767b4e..9317b166608 100644 --- a/src/sage/interfaces/qepcad.py +++ b/src/sage/interfaces/qepcad.py @@ -1924,11 +1924,9 @@ def atomic(self, lhs, op='=', rhs=0): if isinstance(lhs, qformula): return lhs - from sage.symbolic.expression import is_SymbolicEquation - if is_SymbolicEquation(lhs): - rhs = lhs.rhs() - op = lhs.operator() - lhs = lhs.lhs() + from sage.structure.element import Expression + if isinstance(lhs, Expression) and lhs.is_relational(): + lhs, op, rhs = lhs.lhs(), lhs.operator(), lhs.rhs() op = self._normalize_op(op) From 341337a0089d9f27f759f2c5a3f5b33ee795a75c Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 17 Oct 2021 10:08:01 -0700 Subject: [PATCH 61/61] src/sage/ext/fast_callable.pyx: Remove use of is_SymbolicVariable --- src/sage/ext/fast_callable.pyx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sage/ext/fast_callable.pyx b/src/sage/ext/fast_callable.pyx index da1ad9ed5b3..10acc5e3649 100644 --- a/src/sage/ext/fast_callable.pyx +++ b/src/sage/ext/fast_callable.pyx @@ -438,7 +438,6 @@ def fast_callable(x, domain=None, vars=None, if expect_one_var and len(vars) != 1: raise ValueError(f"passed expect_one_var=True, but the callable expression takes {len(vars)} arguments") elif isinstance(x, Expression_abc): - from sage.symbolic.ring import is_SymbolicVariable if vars is None: vars = x.variables() if expect_one_var and len(vars) <= 1: @@ -447,7 +446,7 @@ def fast_callable(x, domain=None, vars=None, else: raise ValueError("list of variables must be specified for symbolic expressions") def to_var(var): - if is_SymbolicVariable(var): + if isinstance(var, Expression_abc) and var.is_symbol(): return var from sage.symbolic.ring import SR return SR.var(var)