Ejemplo n.º 1
0
def image_set_definition(self, reverse=False):
    image_set = self.image_set()
    if image_set is None:
        return

    expr, variables, base_set = image_set
    from sympy.tensor.indexed import Slice
    from sympy.core.relational import Equality
    from sympy.concrete.expr_with_limits import ForAll, Exists

    if isinstance(base_set, Symbol):
        if reverse:
            return ForAll(Contains(expr, self), (variables, base_set))

        element_symbol = self.element_symbol()
        assert expr.dtype == element_symbol.dtype
        condition = Equality(expr, element_symbol)
        return ForAll(Exists(condition, (variables, base_set)), (element_symbol, self))

    else:
        if not isinstance(base_set, ConditionSet):
            return

    variable = base_set.variable
    if isinstance(variable, Symbol):
        ...
    elif isinstance(variable, Slice):
        condition = base_set.condition
        element_symbol = self.element_symbol()
        assert expr.dtype == element_symbol.dtype

        exists = Exists(condition.func(*condition.args), (variables, Equality(expr, element_symbol)))
        return ForAll(exists, (element_symbol, self))
Ejemplo n.º 2
0
    def definition(self):
        e, S = self.args

        from sympy.concrete.expr_with_limits import Exists

        condition_set = S.condition_set()
        if condition_set:
            condition = condition_set.condition
            if condition_set.variable != e:
                condition = condition._subs(condition_set.variable, e)
            return And(condition,
                       self.func(e, condition_set.base_set),
                       equivalent=self)

        image_set = S.image_set()
        if image_set is not None:
            expr, variables, base_set = image_set
            from sympy import Wild
            variables_ = Wild(variables.name, **variables.dtype.dict)
            assert variables_.shape == variables.shape
            e = e.subs_limits_with_epitome(expr)
            dic = e.match(expr.subs(variables, variables_))
            if dic:
                variables_ = dic[variables_]
                if variables.dtype != variables_.dtype:
                    assert len(variables.shape) == 1
                    variables_ = variables_[:variables.shape[-1]]
                return Contains(variables_, base_set, equivalent=self)

            if e._has(variables):
                _variables = base_set.element_symbol(e.free_symbols)
                assert _variables.dtype == variables.dtype
                expr = expr._subs(variables, _variables)
                variables = _variables
            assert not e._has(variables)
            return Exists(Equality(e, expr, evaluate=False),
                          (variables, base_set),
                          equivalent=self)

        if S.is_UNION:
            for v in S.variables:
                if self.lhs._has(v):
                    _v = v.generate_free_symbol(self.free_symbols,
                                                **v.dtype.dict)
                    S = S.limits_subs(v, _v)

            contains = Contains(self.lhs, S.function).simplify()
            contains.equivalent = None
            return Exists(contains, *S.limits, equivalent=self).simplify()

        return self
Ejemplo n.º 3
0
def apply(*given):
    x, y, z = extract(*given)

    theta = Symbol.theta(real=True)
    return Exists(Equality(z**2, x**2 + y**2 - 2 * x * y * cos(theta)),
                  (theta, Interval(pi / 3, pi, right_open=True)),
                  given=given)
Ejemplo n.º 4
0
def apply(given):
    assert given.is_Equality
    lhs, rhs = given.args
    
    assert lhs.is_MatMul
    * x, p_polynomial = lhs.args
    
    assert rhs.is_MatMul
    * y, _p_polynomial = rhs.args
    
    assert p_polynomial == _p_polynomial
    
    assert p_polynomial.is_LAMBDA
    assert p_polynomial.shape    
    assert len(p_polynomial.shape) == 1
    
    x = MatMul(*x)
    y = MatMul(*y)
    
    assert x.shape == y.shape
    assert len(x.shape) == 2
#     n = p_polynomial.shape[0]
    k = p_polynomial.variable
    polynomial = p_polynomial.function
    assert polynomial.is_Power
    
    b, e = polynomial.as_base_exp()    
    assert not b.has(k)
    assert e.as_poly(k).degree() == 1
    
    if given.is_Exists:
        return Exists(Equality(x, y), (x,), (y,), given=given)
    else:
        return Equality(x, y, given=given)
Ejemplo n.º 5
0
 def simplify(self, deep=False):
     from sympy.concrete.expr_with_limits import Exists
     if self.rhs.is_UNION:
         return Exists(self.func(self.lhs, self.rhs.function),
                       *self.rhs.limits,
                       equivalent=self).simplify()
     return self
Ejemplo n.º 6
0
def apply(given):
    assert given.is_Equality
    S_abs, one = given.args

    assert S_abs.is_Abs and one == 1
    S = S_abs.arg
    x = S.element_symbol()
    return Exists(Equality(x.set, S), (x, ), given=given)
Ejemplo n.º 7
0
 def assertion(self):
     from sympy.concrete.expr_with_limits import Exists
     from sympy import Unequality
     s = self.arg
     if not s.is_set:
         return
     x = s.element_symbol()
     y = s.element_symbol({x})
     return (self <= 1) | Exists(Unequality(x, y), (x, s), (y, s))
Ejemplo n.º 8
0
    def simplify(self, deep=False):
        if self.lhs.is_UNION:
            from sympy.concrete.expr_with_limits import Exists
            return Exists(self.func(self.lhs.function, self.rhs),
                          *self.lhs.limits,
                          equivalent=self)

        if self.lhs.is_FiniteSet and len(self.lhs) == 1:
            return NotContains(self.lhs.arg, self.rhs,
                               equivalent=self).simplify()

        return self
Ejemplo n.º 9
0
def apply(given):
    assert given.is_ForAll
    assert given.function.is_Equality
    assert given.function.lhs.is_Limit
    f, z, xi, direction = given.function.lhs.args
    assert direction.name == '+-'
    assert len(given.limits) == 1
    limit = given.limits[0]
    _xi, a, b = limit
    assert xi == _xi
    _f = f._subs(z, xi)
    assert given.function.rhs == _f

    return Exists(Equality(Integral(f, (z, a, b)), (b - a) * _f),
                  limit,
                  given=given)
def apply(given):
    assert given.is_ForAll
    assert given.function.is_Equality
    assert given.function.lhs.is_Limit
    f, z, xi, direction = given.function.lhs.args
    assert direction.name == '+-'
    assert len(given.limits) == 1
    limit = given.limits[0]
    _xi, a, b = limit
    assert xi == _xi
    _f = f._subs(z, xi)
    assert given.function.rhs == _f

    y = Symbol.y(real=True)
    return ForAll(Exists(Equality(f, y), (z, a, b)),
                  (y, MIN(f, (z, a, b)), MAX(f, (z, a, b))),
                  given=given)
Ejemplo n.º 11
0
 def definition(self):
     A, B = self.args
     from sympy.concrete.expr_with_limits import Exists
     e = B.element_symbol(A.free_symbols)
     return Exists(NotContains(e, B), (e, A), equivalent=self).simplify()
Ejemplo n.º 12
0
 def assertion(self):
     from sympy.concrete.expr_with_limits import Exists
     e, S = self.args
     x = S.element_symbol(self.free_symbols)
     assert x.dtype == e.dtype
     return Exists(Equality(x, e), (x, S), equivalent=self)