# assume causes a solving failure

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 close merge delete

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

( 2021-06-10 17:37:24 +0200 )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]

( 2021-06-10 21:23:32 +0200 )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 ??

( 2021-06-15 19:58:35 +0200 )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

( 2021-06-15 20:04:23 +0200 )edit

Emmanuel, thanks for your detailed examination.

( 2021-06-16 11:05:27 +0200 )edit