assume causes a solving failure

asked 2021-06-10 11:33:47 +0100

po gravatar image

This code

var("a b")
assume(a, "real")
equation=[a+b==0]
s=solve(equation, a, b)
print(s)

causes an AttributeError :

AttributeError: 'list' object has no attribute 'lhs'

The problem comes from the assumption in line 2. Can somebody explain?

edit retag flag offensive close merge delete

Comments

I have always a sens of unlegitimity in answering a question, but your problem comes more certainly from the fact that you hve one equation and two unknowns. It works if you use a or b

Cyrille gravatar imageCyrille ( 2021-06-10 17:37:24 +0100 )edit

Cyrille, I think the question is still valid because if we rule out the assumption line, the code yields an answer with a free variable as

[a == -r1, b == r1]
tolga gravatar imagetolga ( 2021-06-10 21:23:32 +0100 )edit

solve has two positional arguments :

  • a (list of) equation(s) to solve, and

  • a (list of) variable(s) to solve for.

Your call passes a list of one equation, which confuses solve. A (very old, AFAICT) bug...

Your call also pass three arguments to solve : another source of confusion... A second bug ?

But I checked that the assumption introduced yet another error. A third bug ??

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2021-06-15 19:58:35 +0100 )edit
1

These bugs seem mutually independent :

sage: var("a, b")
(a, b)
sage: assume(a, "real")
sage: equation=[a+b==0]
sage: solve(equation, a, b)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

[ Snip...]

AttributeError: 'list' object has no attribute 'lhs'

sage: var("a, b")
(a, b)
sage: equation=[a+b==0]
sage: var("a, b")
(a, b)
sage: assume(a, "real")
sage: equation=[a+b==0]
sage: solve(equation, [a, b])
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)

[ Snip...]

AttributeError: 'list' object has no attribute
Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2021-06-15 20:04:23 +0100 )edit

Emmanuel, thanks for your detailed examination.

po gravatar imagepo ( 2021-06-16 11:05:27 +0100 )edit