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

Sage silently accepts symbolic expressions with two comparison operators #24726

Closed
sagetrac-tmonteil mannequin opened this issue Feb 13, 2018 · 8 comments
Closed

Sage silently accepts symbolic expressions with two comparison operators #24726

sagetrac-tmonteil mannequin opened this issue Feb 13, 2018 · 8 comments

Comments

@sagetrac-tmonteil
Copy link
Mannequin

sagetrac-tmonteil mannequin commented Feb 13, 2018

See the following example:

sage: 0 <= x <= 1/2
0 <= x

This should raise an error. Note that it can create confusion when used in assumptions:

sage: assume(0 <= x <= 1/2)
sage: bool(x <= 1/2)
False

This has been reported on this ask question.

CC: @rwst @slel

Component: symbolics

Issue created by migration from https://trac.sagemath.org/ticket/24726

@sagetrac-tmonteil sagetrac-tmonteil mannequin added this to the sage-8.2 milestone Feb 13, 2018
@jdemeyer
Copy link

comment:1

This is not a solvable problem. The problem is that Python treats

0 <= x <= 1/2

as

(0 <= x) and (x <= 1/2)

Since bool(0 <= x) is False, this returns (0 <= x).

There is proposal at PEP 535 to fix this, but it's not clear whether it will be accepted.

@sagetrac-tmonteil
Copy link
Mannequin Author

sagetrac-tmonteil mannequin commented Feb 13, 2018

comment:3

I got your point, but it is not clear for me that this implies that there is nothing to do on the symbolic ring to mitigate the issue.

@jdemeyer
Copy link

comment:4

Replying to @sagetrac-tmonteil:

I got your point, but it is not clear for me that this implies that there is nothing to do on the symbolic ring to mitigate the issue.

As long as bool(0 <= x) returns False, it is not possible to fix this.

@slel
Copy link
Member

slel commented Feb 14, 2018

comment:5

We could let the Sage preparser turn multiple inequalities in assume statements into multiple assumptions.

@rwst
Copy link

rwst commented Feb 14, 2018

comment:6

That's an interesting idea. And it could raise an error outside assumptions. Let's at least wait for that PEP before closing this.

@rwst rwst added this to the sage-8.2 milestone Feb 14, 2018
@slel slel changed the title Sage silenly accepts symbolic expressions with two comparison operators Sage silently accepts symbolic expressions with two comparison operators Feb 14, 2018
@jdemeyer
Copy link

comment:8

Replying to @slel:

We could let the Sage preparser turn multiple inequalities in assume statements into multiple assumptions.

Why special-case assume? The problem already occurs before calling assume:

sage: 0 <= x <= 1/2
0 <= x

@jdemeyer
Copy link

comment:9

And if you do want to hack the preparser for that, I would do it with the PEP 535 semantics.

@jdemeyer
Copy link

comment:10

Since PEP 535 is not particularly likely to come soon, I suggest to close this as "wontfix".

@jdemeyer jdemeyer removed this from the sage-8.2 milestone Jan 11, 2019
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

3 participants