Opened 2 years ago

Last modified 2 years ago

#26492 new defect

symbolic constant e reverses relations

Reported by: tmonteil Owned by:
Priority: major Milestone: sage-8.4
Component: symbolics Keywords:
Cc: rws Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: #18077 Stopgaps:

Status badges

Description

As discussed on this ask question:

sage: x == e
e == x
sage: x > e
e < x
sage: x <= e
e >= x

Note that it only happens with e, this constant is handled in the dedicated SAGE_ROOT/src/sage/symbolic/constants_c.pyx.

This does not happen with the symbolic expression e:

sage: x == e*1
x == e
sage: x > e*1
x > e
sage: x <= e*1
x <= e

Change History (6)

comment:1 Changed 2 years ago by tmonteil

  • Cc rws added

comment:2 follow-up: Changed 2 years ago by jdemeyer

The reason is that constant_E is a subclass. When Python sees a < b where type(b) is a strict subclass of type(a), it instead evaluates b > a.

So this gives us basically the following options:

  1. Consider this not a bug and move on.
  1. Ensure that type(e) is the same as type(x).
  1. Ensure that type(e) and type(x) are both subtypes of a common subclass.
Last edited 2 years ago by jdemeyer (previous) (diff)

comment:3 in reply to: ↑ 2 ; follow-ups: Changed 2 years ago by tmonteil

Replying to jdemeyer:

The reason is that constant_E is a subclass. When Python sees a < b where type(b) is a strict subclass of type(a), it instead evaluates b > a.

Aha, so it is at the Python level, thanks for the hint, i could not find the explanation within Sage source code.

So this gives us basically the following options:

  1. Consider this not a bug and move on.

The problem comes from #26490, so in this case, we should do more parsing to replace lines such as tempic=tempic+","+(dvar==ics[1])._maxima_().str() to something that hardcodes maxima's "=" symbol. Also, from a user perspective, one could program something with rhs and lhs and get confused when such unexpected case appears.

  1. Ensure that type(e) is the same as type(x).

Would replacing

e = E()

with

e = E() * 1

in SAGE_ROOT/src/sage/symbolic/constants.py be considered as a correct fix ?

  1. Ensure that type(e) and type(x) are both subtypes of a common subclass.

comment:4 in reply to: ↑ 3 Changed 2 years ago by jdemeyer

Replying to tmonteil:

Would replacing

e = E()

with

e = E() * 1

in SAGE_ROOT/src/sage/symbolic/constants.py be considered as a correct fix ?

If you want to do that, then why do we need the constant_E class in the first place? My guess is that it's mainly for documentation, such that e? gives information about e as opposed to generic expressions.

comment:5 in reply to: ↑ 3 Changed 2 years ago by jdemeyer

Replying to tmonteil:

Aha, so it is at the Python level, thanks for the hint, i could not find the explanation within Sage source code.

To elaborate on this: for arithmetic operators like __add__, there is a reversed version like __radd__. But the reversed version of __le__ is just __gt__. So user code cannot make a difference between a < b and b > a.

comment:6 Changed 2 years ago by jdemeyer

  • Dependencies set to #18077
Note: See TracTickets for help on using tickets.