Skip to content

Commit

Permalink
Relational Parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikharJ committed Jun 22, 2017
1 parent ef0a45a commit 8ea8e6b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
17 changes: 8 additions & 9 deletions symengine/lib/symengine_wrapper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ cdef c2py(RCP[const symengine.Basic] o):
else:
r = BooleanAtom.__new__(BooleanFalse)
elif (symengine.is_a_Equality(deref(o))):
r = Equality.__new__(Equality)
r = Relational.__new__(Equality)
elif (symengine.is_a_Unequality(deref(o))):
r = Unequality.__new__(Unequality)
r = Relational.__new__(Unequality)
elif (symengine.is_a_LessThan(deref(o))):
r = LessThan.__new__(LessThan)
r = Relational.__new__(LessThan)
elif (symengine.is_a_StrictLessThan(deref(o))):
r = StrictLessThan.__new__(StrictLessThan)
r = Relational.__new__(StrictLessThan)
elif (symengine.is_a_Gamma(deref(o))):
r = Function.__new__(Gamma)
elif (symengine.is_a_Derivative(deref(o))):
Expand Down Expand Up @@ -587,15 +587,14 @@ cdef class Basic(object):
return symengine.eq(deref(A.thisptr), deref(B.thisptr))
elif (op == 3):
return symengine.neq(deref(A.thisptr), deref(B.thisptr))
from sympy import Rel
if (op == 0):
return Rel(A, B, '<')
return c2py(<RCP[const symengine.Basic]>(symengine.Lt(A.thisptr, B.thisptr)))
elif (op == 1):
return Rel(A, B, '<=')
return c2py(<RCP[const symengine.Basic]>(symengine.Le(A.thisptr, B.thisptr)))
elif (op == 4):
return Rel(A, B, '>')
return c2py(<RCP[const symengine.Basic]>(symengine.Gt(A.thisptr, B.thisptr)))
elif (op == 5):
return Rel(A, B, '>=')
return c2py(<RCP[const symengine.Basic]>(symengine.Ge(A.thisptr, B.thisptr)))

def expand(Basic self not None):
return c2py(symengine.expand(self.thisptr))
Expand Down
9 changes: 9 additions & 0 deletions symengine/tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
Ge, Gt, Le, Lt, Symbol, I)

x = Symbol("x")
y = Symbol("y")

def test_relationals():
assert Eq(0) == true
assert Eq(1) == false
assert Eq(x, x) == true
assert Eq(0, 0) == true
assert Eq(1, 0) == false
Expand All @@ -22,3 +25,9 @@ def test_relationals():
assert Ge(1, 1) == true
assert Eq(I, 2) == false
assert Ne(I, 2) == true

def test_rich_cmp():
assert (x < y) == Lt(x, y)
assert (x <= y) == Le(x, y)
assert (x > y) == Gt(x, y)
assert (x >= y) == Ge(x, y)

0 comments on commit 8ea8e6b

Please sign in to comment.