예제 #1
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))
예제 #2
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))
예제 #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 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))
예제 #5
0
 def eval(self, args, assumptions=True):
     return is_neq(*args)
예제 #6
0
 def eval(self, args, assumptions=True):
     if assumptions == True:
         # default assumptions for is_neq is None
         assumptions = None
     return is_neq(*args, assumptions)