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: |
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
- Cc rws added
comment:2 follow-up: ↓ 3 Changed 2 years ago by
comment:3 in reply to: ↑ 2 ; follow-ups: ↓ 4 ↓ 5 Changed 2 years ago by
Replying to jdemeyer:
The reason is that
constant_E
is a subclass. When Python seesa < b
wheretype(b)
is a strict subclass oftype(a)
, it instead evaluatesb > 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:
- 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.
- Ensure that
type(e)
is the same astype(x)
.
Would replacing
e = E()
with
e = E() * 1
in SAGE_ROOT/src/sage/symbolic/constants.py
be considered as a correct fix ?
- Ensure that
type(e)
andtype(x)
are both subtypes of a common subclass.
comment:4 in reply to: ↑ 3 Changed 2 years ago by
Replying to tmonteil:
Would replacing
e = E()with
e = E() * 1in
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
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
- Dependencies set to #18077
The reason is that
constant_E
is a subclass. When Python seesa < b
wheretype(b)
is a strict subclass oftype(a)
, it instead evaluatesb > a
.So this gives us basically the following options:
type(e)
is the same astype(x)
.type(e)
andtype(x)
are both subtypes of a common subclass.