Example #1
0
    def __new__(cls, variable, expr, **kwargs):
        evaluate = kwargs.pop('evaluate', global_evaluate[0])
        variable = repack_if_can(sympify(unpack_if_can(variable)))

        for v in pack_if_not(variable):
            if not is_Symbol(v):
                raise TypeError('variable is not a symbol or matrix symbol: %s' % v)
        if not is_Boolean(expr):
            raise TypeError('expression is not boolean or relational: %r' % expr)

        if evaluate:
            return Exist.eval(variable, expr)
        return Application.__new__(cls, variable, expr, **kwargs)
Example #2
0
    def __new__(cls, variable, expr, **kwargs):
        """create AbstractSet by variable and expression

        >>> from sympy import *
        >>> from symplus.strplus import init_mprinting
        >>> init_mprinting()
        >>> x, y = symbols('x y')
        >>> AbstractSet(x, abs(x)>1)
        {x | |x| > 1}
        >>> AbstractSet((x,), abs(x)>1)
        {x | |x| > 1}
        >>> AbstractSet((x, y), abs(x-y)>1)
        {(x, y) | |x - y| > 1}
        >>> AbstractSet([x, y], abs(x-y)>1)
        {(x, y) | |x - y| > 1}
        >>> m, n = MatrixSymbol('m', 2, 2), MatrixSymbol('n', 2, 2)
        >>> AbstractSet(m, Eq(m[0,0]+m[1,1],0))
        {m | 0 == m[0, 0] + m[1, 1]}
        >>> AbstractSet((m, x), Eq(det(m),x))
        {(m, x) | x == ||m||}
        >>> AbstractSet(x, (x>1)&(x<3))
        {x | (x < 3) /\ (x > 1)}
        >>> AbstractSet(x, x>y)
        {x | x > y}
        >>> AbstractSet(1, x>y)
        Traceback (most recent call last):
            ...
        TypeError: variable is not a symbol or matrix symbol: 1
        >>> AbstractSet(x, x+y)
        Traceback (most recent call last):
            ...
        TypeError: expression is not boolean or relational: x + y
        """
        variable = repack_if_can(sympify(unpack_if_can(variable)))
        for v in pack_if_not(variable):
            if not is_Symbol(v):
                raise TypeError("variable is not a symbol or matrix symbol: %s" % v)
        if not is_Boolean(expr):
            raise TypeError("expression is not boolean or relational: %r" % expr)

        return Set.__new__(cls, variable, expr, **kwargs)