예제 #1
0
def test_is_eq():
    class PowTest(Expr):
        def __new__(cls, base, exp):
            return Basic.__new__(cls, _sympify(base), _sympify(exp))

    @dispatch(PowTest, PowTest)
    def _eval_is_eq(lhs, rhs):
        if type(lhs) == PowTest and type(rhs) == PowTest:
            return fuzzy_and([
                is_eq(lhs.args[0], rhs.args[0]),
                is_eq(lhs.args[1], rhs.args[1])
            ])

    assert is_eq(PowTest(3, 4), PowTest(3, 4))
    assert is_eq(PowTest(3, 4), _sympify(4)) is None
    assert is_neq(PowTest(3, 4), PowTest(3, 7))
예제 #2
0
 def __bool__(self):
     # this only distinguishes between definite null range
     # and non-null/unknown null; getting True doesn't mean
     # that it actually is not null
     b = is_eq(self.start, self.stop)
     if b is None:
         raise ValueError('cannot tell if Range is null or not')
     return not bool(b)
예제 #3
0
def test_EvalEq():
    """

    This test exists to ensure backwards compatibility.
    The method to use is _eval_is_eq
    """
    from sympy.core.expr import Expr

    class PowTest(Expr):
        def __new__(cls, base, exp):
            return Basic.__new__(PowTest, _sympify(base), _sympify(exp))

        def _eval_Eq(lhs, rhs):
            if type(lhs) == PowTest and type(rhs) == PowTest:
                return lhs.args[0] == rhs.args[0] and lhs.args[1] == rhs.args[1]

    assert is_eq(PowTest(3, 4), PowTest(3, 4))
    assert is_eq(PowTest(3, 4), _sympify(4)) is None
    assert is_neq(PowTest(3, 4), PowTest(3, 7))
예제 #4
0
def test_is_eq():
    # test assumptions
    assert is_eq(x, y, Q.infinite(x) & Q.finite(y)) is False
    assert is_eq(
        x, y,
        Q.infinite(x) & Q.infinite(y) & Q.extended_real(x)
        & ~Q.extended_real(y)) is False
    assert is_eq(
        x, y,
        Q.infinite(x) & Q.infinite(y) & Q.extended_positive(x)
        & Q.extended_negative(y)) is False

    assert is_eq(x + I, y + I, Q.infinite(x) & Q.finite(y)) is False
    assert is_eq(1 + x * I, 1 + y * I, Q.infinite(x) & Q.finite(y)) is False

    assert is_eq(x, S(0), assumptions=Q.zero(x))
    assert is_eq(x, S(0), assumptions=~Q.zero(x)) is False
    assert is_eq(x, S(0), assumptions=Q.nonzero(x)) is False
    assert is_neq(x, S(0), assumptions=Q.zero(x)) is False
    assert is_neq(x, S(0), assumptions=~Q.zero(x))
    assert is_neq(x, S(0), assumptions=Q.nonzero(x))

    # test registration
    class PowTest(Expr):
        def __new__(cls, base, exp):
            return Basic.__new__(cls, _sympify(base), _sympify(exp))

    @dispatch(PowTest, PowTest)
    def _eval_is_eq(lhs, rhs):
        if type(lhs) == PowTest and type(rhs) == PowTest:
            return fuzzy_and([
                is_eq(lhs.args[0], rhs.args[0]),
                is_eq(lhs.args[1], rhs.args[1])
            ])

    assert is_eq(PowTest(3, 4), PowTest(3, 4))
    assert is_eq(PowTest(3, 4), _sympify(4)) is None
    assert is_neq(PowTest(3, 4), PowTest(3, 7))
예제 #5
0
def test_is_eq():
    # test assumption
    assert not is_eq(x, y, Q.infinite(x) & Q.finite(y))
    # uncomment after Q.infinite(y) & ~Q.extended_real(y) is fixed to be valid assumption (which is true for zoo)
    # assert not is_eq(x, y, Q.infinite(x) & Q.infinite(y) & Q.extended_real(x) & ~Q.extended_real(y))
    assert not is_eq(x+I, y+I, Q.infinite(x) & Q.finite(y))
    assert not is_eq(1+x*I, 1+y*I, Q.infinite(x) & Q.finite(y))
    assert is_eq(x, S(0), assumptions=Q.zero(x))

    # test registration
    class PowTest(Expr):
        def __new__(cls, base, exp):
            return Basic.__new__(cls, _sympify(base), _sympify(exp))

    @dispatch(PowTest, PowTest)
    def _eval_is_eq(lhs, rhs):
        if type(lhs) == PowTest and type(rhs) == PowTest:
            return fuzzy_and([is_eq(lhs.args[0], rhs.args[0]), is_eq(lhs.args[1], rhs.args[1])])

    assert is_eq(PowTest(3, 4), PowTest(3,4))
    assert is_eq(PowTest(3, 4), _sympify(4)) is None
    assert is_neq(PowTest(3, 4), PowTest(3,7))
예제 #6
0
 def _eval_is_eq(lhs, rhs):
     if type(lhs) == PowTest and type(rhs) == PowTest:
         return fuzzy_and([
             is_eq(lhs.args[0], rhs.args[0]),
             is_eq(lhs.args[1], rhs.args[1])
         ])
예제 #7
0
 def eval(self, args, assumptions=True):
     return is_eq(*args)
예제 #8
0
def _eval_is_eq(lhs, rhs): # noqa: F811
    if len(lhs.sets) != len(rhs.sets):
        return False

    eqs = (is_eq(x, y) for x, y in zip(lhs.sets, rhs.sets))
    return tfn[fuzzy_and(map(fuzzy_bool, eqs))]
예제 #9
0
파일: integers.py 프로젝트: sidhu1012/sympy
def _eval_is_eq(lhs, rhs):  # noqa:F811
    return is_eq(lhs.rewrite(floor), rhs) or is_eq(lhs.rewrite(frac), rhs)
예제 #10
0
파일: integers.py 프로젝트: sidhu1012/sympy
def _eval_is_eq(lhs, rhs):  # noqa:F811
    return is_eq(lhs.rewrite(ceiling), rhs) or \
         is_eq(lhs.rewrite(frac),rhs)
예제 #11
0
 def eval(self, args, assumptions=True):
     if assumptions == True:
         # default assumptions for is_eq is None
         assumptions = None
     return is_eq(*args, assumptions)