Unexpected result when substituting expression with minus

29 views
Skip to first unread message

Marcus A.

unread,
Jul 22, 2021, 2:16:39 PM7/22/21
to sage-devel
Hi all,

I think I found a bug when substituting "-a == 0" into "a". The result is not "0" but "a". This also happens when I assume that "a" is real. (see below)

sage: var('a')
a
sage: a.substitute(a == 0)
0
sage: a.substitute(-a == 0) # bug?
a
sage: (-a).substitute(a == 0)
0
sage: (-a).substitute(-a == 0)
0
sage: assume(a, 'real')
sage: a.substitute(a == 0)
0
sage: a.substitute(-a == 0) # bug?
a
sage: (-a).substitute(a == 0)
0
sage: (-a).substitute(-a == 0)
0


This issue happens for me with SageMath 9.2 on Ubuntu 20.04 and also on CoCalc with SageMath 9.3.

Michael Orlitzky

unread,
Jul 22, 2021, 4:07:58 PM7/22/21
to sage-...@googlegroups.com
On Thu, 2021-07-22 at 10:08 -0700, Marcus A. wrote:
> Hi all,
>
> I think I found a bug when substituting "-a == 0" into "a". The result is
> not "0" but "a". This also happens when I assume that "a" is real. (see
> below)
>
> sage: var('a')
> a
> sage: a.substitute(a == 0)
> 0
> sage: a.substitute(-a == 0) # bug?
> a
>

This is trying to replace the "-a" in the expression "a" with "0".
Since there is no "-a" in "a", nothing happens.

The expression/substitution stuff is not very smart and doesn't realize
that it could just multiply both sides by -1 and then proceed as
before.

Reply all
Reply to author
Forward
0 new messages