Thanks Simon,

i think list of lists and tuples are good enough for me.

sage: R.<a,b> = FreeAlgebra(QQ, 2)
> sage: p = a*(a+2*b)
> sage: list(p)
> [(2, a*b), (1, a^2)]
>

is there a simple way to reverse this last step?

just for information - i asked this same question at the sympy mailing list
and i give below parts of the answer which would be important for people
using sage -

The parts below are from the replies of Aaron S. Meurer (asmeu...@gmail.com)
-

> Just a heads up, starting in the next release, symbols('xy') will create
one symbol named xy, not two symbols x and y.  To get around this, you
should do symbols('x y') or symbols('x, y') (this works in the older release
too, so you can start to change your code now).

> In [9]: x, y = symbols('x y', commutative=False)

> In [10]: a = expand((x + y)**3)

> In [11]: a
> Out[11]:
>            2    2      3              2    2      3
> x⋅y⋅x + x⋅y  + x ⋅y + x  + y⋅x⋅y + y⋅x  + y ⋅x + y

> In [12]: a.subs(x*y, y*x + 1)
> Out[12]:
>                3      2                  2      3

> x⋅(1 + y⋅x) + x  + y⋅x  + y⋅(1 + y⋅x) + y ⋅x + y  + (1 + y⋅x)⋅x + (1 +
y⋅x)⋅y

> Actually, it looks like if you are using SymPy 0.6.7, there is a bug that
makes this return a wrong result:

For people using sympy in sage, this last point seems important. I actually
checked and we use SymPy 0.6.4

Rajeev

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to