def _sympy_(self): r""" Return an instance of a subclass of SymPy ``Set`` corresponding to ``self``. EXAMPLES:: sage: predicate(x, y, z) = sqrt(x^2 + y^2 + z^2) < 12; predicate (x, y, z) |--> sqrt(x^2 + y^2 + z^2) < 12 sage: SmallTriples = ConditionSet(ZZ^3, predicate); SmallTriples { (x, y, z) ∈ Ambient free module of rank 3 over the principal ideal domain Integer Ring : sqrt(x^2 + y^2 + z^2) < 12 } sage: ST = SmallTriples._sympy_(); ST ConditionSet((x, y, z), sqrt(x**2 + y**2 + z**2) < 12, ProductSet(Integers, Integers, Integers)) sage: (1, 3, 5) in ST True sage: (5, 7, 9) in ST False sage: Interval = ConditionSet(RR, x >= -7, x <= 4, vars=[x]); Interval { x ∈ Real Field with 53 bits of precision : x >= -7, x <= 4 } sage: Interval._sympy_() ConditionSet(x, (x >= -7) & (x <= 4), SageSet(Real Field with 53 bits of precision)) If a predicate is not symbolic, we fall back to creating a wrapper:: sage: Evens = ConditionSet(ZZ, is_even); Evens { x ∈ Integer Ring : <function is_even at 0x...>(x) } sage: Evens._sympy_() SageSet({ x ∈ Integer Ring : <function is_even at 0x...>(x) }) """ from sage.interfaces.sympy import sympy_init sympy_init() import sympy args = self.arguments() single_arg = len(args) == 1 if single_arg: args = args[0] try: conditions = [ self._call_predicate(predicate, args) for predicate in self._predicates ] sym = tuple(x._sympy_() for x in self.arguments()) if single_arg: sym = sym[0] result = sympy.ConditionSet( sym, sympy.And(*[condition._sympy_() for condition in conditions]), base_set=self._universe._sympy_()) result._sage_object = self return result except TypeError: # Fall back to creating a wrapper return super()._sympy_()
def _sympy_(self): r""" Return the SymPy set ``Naturals``. EXAMPLES:: sage: PositiveIntegers()._sympy_() Naturals """ from sympy import Naturals from sage.interfaces.sympy import sympy_init sympy_init() return Naturals
def _sympy_(self): r""" Return the SymPy set ``Rationals``. EXAMPLES:: sage: QQ._sympy_() Rationals """ from sympy import Rationals from sage.interfaces.sympy import sympy_init sympy_init() return Rationals
def _sympy_(self): r""" Return the SymPy set ``Naturals0``. EXAMPLES:: sage: NN = NonNegativeIntegers() sage: NN._sympy_() Naturals0 """ from sympy import Naturals0 from sage.interfaces.sympy import sympy_init sympy_init() return Naturals0
def _start(self): """ Start up the Mathics interpreter and sets the initial prompt and options. This is called the first time the Mathics interface is actually used. EXAMPLES:: sage: mathics._start() # optional - mathics sage: type(mathics._session) # optional - mathics <class 'mathics.session.MathicsSession'> """ if not self._session: from mathics.session import MathicsSession self._session = MathicsSession() from sage.interfaces.sympy import sympy_init sympy_init() from sympy import Symbol from sympy.core.relational import Relational Symbol._sage_ = _mathics_sympysage_symbol