Opened 16 months ago

Closed 5 months 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 16 months ago by jdemeyer

  • Milestone changed from sage-8.2 to sage-duplicate/invalid/wontfix
  • Status changed from new to needs_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 16 months ago by jdemeyer

  • Status changed from needs_review to positive_review

comment:3 follow-up: Changed 16 months ago by 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.

comment:4 in reply to: ↑ 3 Changed 16 months ago by jdemeyer

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: Changed 16 months ago by slelievre

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

comment:6 Changed 16 months ago by rws

  • 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 16 months ago by slelievre

  • 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 16 months ago by jdemeyer

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 16 months ago by jdemeyer

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

comment:10 Changed 5 months ago by jdemeyer

  • 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".

Note: See TracTickets for help on using tickets.