Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge #32665
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Oct 18, 2021
2 parents 1e907fd + 341337a commit 2c02ba9
Show file tree
Hide file tree
Showing 69 changed files with 466 additions and 282 deletions.
4 changes: 2 additions & 2 deletions src/sage/calculus/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def symbolic_expression(x):
2*x^2 + 3
sage: type(a)
<class 'sage.symbolic.expression.Expression'>
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
Expand Down
4 changes: 2 additions & 2 deletions src/sage/calculus/integration.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,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)
Expand Down
13 changes: 7 additions & 6 deletions src/sage/dynamics/arithmetic_dynamics/affine_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand All @@ -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')
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 5 additions & 6 deletions src/sage/dynamics/arithmetic_dynamics/projective_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,15 @@ 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 sage.rings.polynomial.polynomial_ring import is_PolynomialRing
from sage.rings.qqbar import QQbar, number_field_elements_from_algebraics
from sage.rings.quotient_ring import QuotientRing_generic
from sage.rings.rational_field import QQ
from sage.rings.real_double import RDF
from sage.rings.real_mpfr import (RealField, is_RealField)
import sage.rings.abc
from sage.rings.real_mpfr import RealField
from sage.schemes.generic.morphism import SchemeMorphism_polynomial
from sage.schemes.projective.projective_subscheme import AlgebraicScheme_subscheme_projective
from sage.schemes.projective.projective_morphism import (
Expand Down Expand Up @@ -2062,10 +2061,10 @@ def canonical_height(self, P, **kwds):

# Archimedean local heights
# :: WARNING: If places is fed the default Sage precision of 53 bits,
# it uses Real or Complex Double Field in place of RealField(prec) or ComplexField(prec)
# the function is_RealField does not identify RDF as real, so we test for that ourselves.
# it uses Real or Complex Double Field in place of RealField(prec) or ComplexField(prec).
# RDF is an instance of a separate class.
for v in emb:
if is_RealField(v.codomain()) or v.codomain() is RDF:
if isinstance(v.codomain(), (sage.rings.abc.RealField, sage.rings.abc.RealDoubleField)):
dv = R.one()
else:
dv = R(2)
Expand Down
14 changes: 5 additions & 9 deletions src/sage/ext/fast_callable.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -427,20 +428,16 @@ def fast_callable(x, domain=None, vars=None,
et = x
vars = et._etb._vars
else:
from sage.symbolic.callable import is_CallableSymbolicExpression
from sage.symbolic.expression import is_Expression

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:
raise ValueError(f"passed expect_one_var=True, but the callable expression takes {len(vars)} arguments")
elif is_Expression(x):
from sage.symbolic.ring import is_SymbolicVariable
elif isinstance(x, Expression_abc):
if vars is None:
vars = x.variables()
if expect_one_var and len(vars) <= 1:
Expand All @@ -449,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)
Expand Down Expand Up @@ -999,8 +996,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.symbolic.expression import is_Expression
if is_Expression(o) and o in ZZ:
if isinstance(o, Expression_abc) and o in ZZ:
es = s
return ExpressionIPow(es._etb, s, ZZ(o))
else:
Expand Down
11 changes: 5 additions & 6 deletions src/sage/functions/orthogonal_polys.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,7 @@
from sage.misc.latex import latex
from sage.rings.all import ZZ, QQ, RR, CC
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.real_mpfr import is_RealField
from sage.rings.complex_mpfr import is_ComplexField
import sage.rings.abc

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

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

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

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

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

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

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

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

CC = z.parent()
from sage.rings.complex_mpfr import is_ComplexField
if not is_ComplexField(CC):
if not isinstance(CC, sage.rings.abc.ComplexField):
from sage.rings.complex_mpfr import ComplexField
CC = ComplexField(prec)
try:
z = CC(z)
Expand Down
8 changes: 3 additions & 5 deletions src/sage/interfaces/qepcad.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/sage/libs/singular/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/sage/matrix/matrix0.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ from sage.rings.complex_double import CDF
from sage.rings.real_mpfr import RealField
from sage.rings.complex_mpfr import ComplexField
from sage.rings.finite_rings.integer_mod_ring import IntegerModRing
import sage.rings.abc
from sage.arith.numerical_approx cimport digits_to_bits
from copy import copy

Expand Down Expand Up @@ -821,8 +822,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()
Expand Down Expand Up @@ -1984,9 +1984,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
n = self._ncols

Expand Down Expand Up @@ -2030,7 +2027,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.
Expand Down Expand Up @@ -2075,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:
Expand Down Expand Up @@ -14722,6 +14719,8 @@ cdef class Matrix(Matrix1):
for i from 0 <= i < size:
PyList_Append(M,<object>f(<object>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)

Expand Down
4 changes: 2 additions & 2 deletions src/sage/matrix/matrix_rational_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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():
Expand Down
4 changes: 2 additions & 2 deletions src/sage/matrix/matrix_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/matrix/misc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ from sage.rings.rational_field import QQ
from sage.rings.integer cimport Integer
from sage.arith.all import previous_prime, CRT_basis

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


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

cdef RealNumber a, b
Expand Down
2 changes: 1 addition & 1 deletion src/sage/misc/sageinspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2317,7 +2317,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',
Expand Down
Loading

0 comments on commit 2c02ba9

Please sign in to comment.