On 5/29/07, Timothy Clemans <[EMAIL PROTECTED]> wrote:
> HI,
>
> Could you implement a way to get a list or dictionary of a symbolic
> expression if it contains only one variable?
>
> sage: g = 6*x^2 - 5
> sage: list(g)
> [6,0,-5]
> sage: dict(g)
> {2:6,1:0,0:-5}
>
> sage: g = 5*x^4 - x + 4
> sage: list(g)
> [5,0,0,-1,4]
> sage: dict(g)
> {4:5,3:0,2:0,1:-1,0:4}
>
You might want to consider using the coeffs method
instead, since it will allow you to do what you want,
or first convert to a polynomial and use list/dict. Here
are some examples:
sage: g = 6*x^2 - 5
sage: g.coeffs()
[[-5, 0], [6, 2]]
sage: list(g.polynomial(QQ))
[-5, 0, 6]
sage: g.polynomial(QQ).dict()
{0: -5, 1: 0, 2: 6}
sage: g.polynomial(QQ).list()
[-5, 0, 6]
sage: g = 6*x^2 - 5
sage: g.coeffs()
[[-5, 0], [6, 2]]
sage: g.polynomial(QQ).list()
[-5, 0, 6]
sage: g.polynomial(QQ).dict()
{0: -5, 1: 0, 2: 6}
William
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/
-~----------~----~----~----~------~----~------~--~---