Opened 5 years ago

Closed 4 years ago

#24726 closed defect (wontfix)

Sage silently accepts symbolic expressions with two comparison operators

Reported by: Thierry Monteil Owned by:
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: symbolics Keywords:
Cc: Ralf Stephan, Samuel Lelièvre Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

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 5 years ago by Jeroen Demeyer

Milestone: sage-8.2sage-duplicate/invalid/wontfix
Status: newneeds_review

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.

comment:2 Changed 5 years ago by Jeroen Demeyer

Status: needs_reviewpositive_review

comment:3 Changed 5 years ago by Thierry Monteil

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 5 years ago by Jeroen Demeyer

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 Changed 5 years ago by Samuel Lelièvre

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

comment:6 Changed 5 years ago by Ralf Stephan

Milestone: sage-duplicate/invalid/wontfixsage-8.2
Status: positive_reviewneeds_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 5 years ago by Samuel Lelièvre

Cc: Samuel Lelièvre added
Summary: Sage silenly accepts symbolic expressions with two comparison operatorsSage silently accepts symbolic expressions with two comparison operators

comment:8 in reply to:  5 Changed 5 years ago by Jeroen Demeyer

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 5 years ago by Jeroen Demeyer

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

comment:10 Changed 4 years ago by Jeroen Demeyer

Milestone: sage-8.2sage-duplicate/invalid/wontfix
Resolution: wontfix
Status: needs_infoclosed

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

Note: See TracTickets for help on using tickets.