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 23, 2021
2 parents c8b9aaf + 341337a commit 1ee09aa
Show file tree
Hide file tree
Showing 17 changed files with 120 additions and 62 deletions.
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
7 changes: 2 additions & 5 deletions src/sage/ext/fast_callable.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -426,19 +426,16 @@ 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:
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:
Expand All @@ -447,7 +444,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
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: 1 addition & 3 deletions src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1985,8 +1985,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

Expand Down Expand Up @@ -2075,7 +2073,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
8 changes: 4 additions & 4 deletions src/sage/modules/free_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/sage/modules/free_module_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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

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
Expand Down Expand Up @@ -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.")
Expand Down
4 changes: 2 additions & 2 deletions src/sage/plot/contour_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 2 additions & 4 deletions src/sage/plot/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions src/sage/plot/plot3d/plot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/sage/rings/abc.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .ring cimport Field
from .ring cimport CommutativeRing, Field

cdef class RealField(Field):

Expand All @@ -23,3 +23,8 @@ cdef class ComplexField(Field):
cdef class ComplexDoubleField(Field):

pass


cdef class SymbolicRing(CommutativeRing):

pass
16 changes: 16 additions & 0 deletions src/sage/rings/abc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,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
25 changes: 20 additions & 5 deletions src/sage/schemes/elliptic_curves/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.<x,y> = QQ[]
sage: E is EllipticCurve(y^2 + y - ( x^3 + x - 9 ))
True
"""
R = None
if is_Ring(x):
Expand All @@ -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):
Expand Down
13 changes: 4 additions & 9 deletions src/sage/sets/condition_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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()):
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions src/sage/symbolic/callable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -81,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):
Expand Down Expand Up @@ -267,7 +274,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:
Expand Down Expand Up @@ -300,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_class):
args = self.arguments()
if all(a in args for a in R.arguments()):
return True
Expand Down
Loading

0 comments on commit 1ee09aa

Please sign in to comment.