Skip to content

Commit

Permalink
Trac #32599: sage.structure, sage.sets: Remove hard dependencies on t…
Browse files Browse the repository at this point in the history
…he symbolic ring / polynomial rings

(partially cherry-picked from #32432)

URL: https://trac.sagemath.org/32599
Reported by: mkoeppe
Ticket author(s): Matthias Koeppe
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Oct 12, 2021
2 parents 25abdd9 + 73aabd2 commit 12f3702
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
11 changes: 8 additions & 3 deletions src/sage/sets/condition_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
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.symbolic.callable import is_CallableSymbolicExpression
from sage.symbolic.ring import SR

try:
from sage.symbolic.expression import is_Expression
from sage.symbolic.callable import is_CallableSymbolicExpression
except ImportError:
is_CallableSymbolicExpression = is_Expression = lambda x: False

from .set import Set, Set_base, Set_boolean_operators, Set_add_sub_operators

Expand Down Expand Up @@ -169,6 +172,7 @@ def __classcall_private__(cls, universe, *predicates, vars=None, names=None, cat
if names is None:
raise TypeError('use callable symbolic expressions or provide variable names')
if vars is None:
from sage.symbolic.ring import SR
vars = tuple(SR.var(name) for name in names)
callable_symbolic_predicates.append(predicate.function(*vars))
else:
Expand Down Expand Up @@ -291,6 +295,7 @@ def arguments(self):
sage: args[0].parent()
Symbolic Ring
"""
from sage.symbolic.ring import SR
return SR.var(self.variable_names())

def _element_constructor_(self, *args, **kwds):
Expand Down
41 changes: 24 additions & 17 deletions src/sage/structure/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,19 @@ def Sequence(x, universe=None, check=True, immutable=False, cr=False, cr_str=Non
...
TypeError: unable to convert a to an element of Integer Ring
"""
from sage.rings.polynomial.multi_polynomial_ideal import MPolynomialIdeal

if isinstance(x, Sequence_generic) and universe is None:
universe = x.universe()
x = list(x)

if isinstance(x, MPolynomialIdeal) and universe is None:
universe = x.ring()
x = x.gens()
if universe is None:
if isinstance(x, Sequence_generic):
universe = x.universe()
x = list(x)
else:
try:
from sage.rings.polynomial.multi_polynomial_ideal import MPolynomialIdeal
except ImportError:
pass
else:
if isinstance(x, MPolynomialIdeal):
universe = x.ring()
x = x.gens()

if universe is None:
orig_x = x
Expand All @@ -248,15 +252,18 @@ def Sequence(x, universe=None, check=True, immutable=False, cr=False, cr_str=Non
if universe is None: # no type errors raised.
universe = sage.structure.element.parent(x[len(x)-1])

from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence
from sage.rings.polynomial.pbori.pbori import BooleanMonomialMonoid
from sage.rings.polynomial.multi_polynomial_ring import is_MPolynomialRing
from sage.rings.quotient_ring import is_QuotientRing

if is_MPolynomialRing(universe) or isinstance(universe, BooleanMonomialMonoid) or (is_QuotientRing(universe) and is_MPolynomialRing(universe.cover_ring())):
return PolynomialSequence(x, universe, immutable=immutable, cr=cr, cr_str=cr_str)
try:
from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence
from sage.rings.polynomial.pbori.pbori import BooleanMonomialMonoid
from sage.rings.polynomial.multi_polynomial_ring import is_MPolynomialRing
from sage.rings.quotient_ring import is_QuotientRing
except ImportError:
pass
else:
return Sequence_generic(x, universe, check, immutable, cr, cr_str, use_sage_types)
if is_MPolynomialRing(universe) or isinstance(universe, BooleanMonomialMonoid) or (is_QuotientRing(universe) and is_MPolynomialRing(universe.cover_ring())):
return PolynomialSequence(x, universe, immutable=immutable, cr=cr, cr_str=cr_str)

return Sequence_generic(x, universe, check, immutable, cr, cr_str, use_sage_types)


class Sequence_generic(sage.structure.sage_object.SageObject, list):
Expand Down

0 comments on commit 12f3702

Please sign in to comment.