Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement relational operations <=, ==, >=, <, > #1087

Closed
certik opened this issue Oct 4, 2016 · 4 comments
Closed

Implement relational operations <=, ==, >=, <, > #1087

certik opened this issue Oct 4, 2016 · 4 comments

Comments

@certik
Copy link
Contributor

certik commented Oct 4, 2016

For example, this:

 auto formula = parse("((x>=y) & (y>=z))*sign(x-y)")

Would work like the following:

 result = formula.lambda(x=3, y=2.5, z=1.5) = ((1.0)&(1.0))*1.0 = 1.0
 result = formula.lambda(x=3, y=3.5, z=1.5) = ((0.0)&(1.0))*1.0 = 0.0

In SymPy, you can do things like:

In [1]: x <= y
Out[1]: x ≤ y
@isuruf
Copy link
Member

isuruf commented Oct 5, 2016

You can do this with Piecewise
Piecewise( ((x-y in [0, inf)) and (y-z in [0, inf)), (x-y)/abs(x-y)), (True, 0))

@bjodah
Copy link
Contributor

bjodah commented Oct 25, 2016

FWIW, relationals in symengine would help a use-case I just encountered for Lambdify:

>>> cb = symengine.Lambdify([x, y], [x>=0, y>=0])
...
SympifyError: sympy2symengine: Cannot convert 'x >= 0' to a symengine type.

Where I would like to have this eventually:

>>> np.allclose(cb([2, -1]), [1.0, 0.0])
True

@isuruf
Copy link
Member

isuruf commented Oct 25, 2016

See symengine/symengine.py#90. In it I used intervals (which was already implemented) and contains. to_contains can convert x >= 0 to a symengine expression.
Now that And, Or, Not are all there, after implementing relationals, we don't need contains at all.

@ShikharJ
Copy link
Member

Fixed via #1276.

@isuruf isuruf closed this as completed May 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants