Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I am new to sage. So, sorry if my question is trivial.

Not at all! Likely you could have found this by doing a little more reconnaissance, but hopefully others in the same boat will now find this instead.

Incidentally, x is the only predefined variable, so your first line is not needed. Also, the semicolons are not necessary to suppress output.

I hope this example answers your questions.

sage: f = x^2 - 5*x + 6
sage: z = solve(f,x) # f==0 is implicit
sage: z
[x == 3, x == 2]
sage: z[0]
x == 3
sage: z[1]
x == 2
sage: z[0].rhs()
sage: z[0].lhs()

Essentially, Sage returns Python lists, and this is how to extract stuff from them. It returns a symbolic equality, and then the rhs() method gets the "right hand side".

There is another way to get solutions as Python dicts, but that is slightly more advanced so maybe someone else can comment on that.