Opened 12 months ago
Closed 6 weeks ago
#24726 closed defect (wontfix)
Sage silently accepts symbolic expressions with two comparison operators
Reported by: | tmonteil | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-duplicate/invalid/wontfix |
Component: | symbolics | Keywords: | |
Cc: | rws, slelievre | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
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.
Change History (10)
comment:1 Changed 12 months ago by
- Milestone changed from sage-8.2 to sage-duplicate/invalid/wontfix
- Status changed from new to needs_review
comment:2 Changed 12 months ago by
- Status changed from needs_review to positive_review
comment:3 follow-up: ↓ 4 Changed 12 months ago by
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.
comment:4 in reply to: ↑ 3 Changed 12 months ago by
Replying to 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.
comment:5 follow-up: ↓ 8 Changed 12 months ago by
We could let the Sage preparser turn multiple inequalities in assume
statements into multiple assumptions.
comment:6 Changed 12 months ago by
- Milestone changed from sage-duplicate/invalid/wontfix to sage-8.2
- Status changed from positive_review to needs_info
That's an interesting idea. And it could raise an error outside assumptions. Let's at least wait for that PEP before closing this.
comment:7 Changed 12 months ago by
- Cc slelievre added
- Summary changed from Sage silenly accepts symbolic expressions with two comparison operators to Sage silently accepts symbolic expressions with two comparison operators
comment:8 in reply to: ↑ 5 Changed 12 months ago by
Replying to slelievre:
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
comment:9 Changed 12 months ago by
And if you do want to hack the preparser for that, I would do it with the PEP 535 semantics.
comment:10 Changed 6 weeks ago by
- Milestone changed from sage-8.2 to sage-duplicate/invalid/wontfix
- Resolution set to wontfix
- Status changed from needs_info to closed
Since PEP 535 is not particularly likely to come soon, I suggest to close this as "wontfix".
This is not a solvable problem. The problem is that Python treats
as
Since
bool(0 <= x)
isFalse
, this returns(0 <= x)
.There is proposal at PEP 535 to fix this, but it's not clear whether it will be accepted.