On Wed, May 25, 2011 at 11:55 AM, Simon King <[email protected]> wrote:

> Hi Rajeev,
>
> On 25 Mai, 06:14, Rajeev Singh <[email protected]> wrote:
> > 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?
>
> I thought that for many parents R holds that R(list(p))==p, but
> apparently I was mistaken.
>
> However, for example, in the case of polynomials, one has
>  sage: P.<x,y> = QQ[]
>  sage: p = P.random_element()
>  sage: p
>  x*y + 5*y^2 - x + 1
>  sage: p.dict()
>  {(1, 0): -1, (0, 0): 1, (1, 1): 1, (0, 2): 5}
>  sage: P(p.dict()) == p
>  True
>
> But apparently that does not hold for free algebras. Here is a work-
> around using the 'add' function:
>   sage: R.<a,b> = FreeAlgebra(QQ, 2)
>  sage: p = a*(a+2*b)
>   sage: L = list(p)
>  sage: add([c*R(m) for c,m in L], R(0))
>  a^2 + 2*a*b
>
> Cheers,
> Simon
>
> --
> 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
> URL: http://www.sagemath.org
>

Thanks Simon,

One small querry -

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

Why is the order of terms in the list not the same that in string of p (a^2
in string appears before a*b and the opposite happens for the list) ? What
can I do to make them in same order?

Rajeev

-- 
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
URL: http://www.sagemath.org

Reply via email to