Hi Rajeev, On 22 Mai, 20:25, Rajeev <[email protected]> wrote: > I wish to simplify some calculation that appear in quantum mechanics. To > begin we use non-commutative variables as - > > sage: R.<a,b> = FreeAlgebra(QQ, 2) > sage: (a+b)^3 + a*(a+b) > a^2 + a*b + a^3 + a^2*b + a*b*a + a*b^2 + b*a^2 + b*a*b + b^2*a + b^3 > > I want to impose the commutation relation [a,b]=1 and bring the expression > to normal form (i.e. in all terms b appears before a, e.g. a*b gets replaced > by b*a + 1). Is it possible to do this?
Well, if you start with a free algebra generated by a and b, and you mod out the commutator of a and b, then you obtain the polynomial ring generated by a and b, up to isomorphism. Hence, you could create a polynomial ring and convert your free algebra elements into a polynomial like this: sage: R.<a,b> = FreeAlgebra(QQ, 2) sage: p = (a+b)^3 + a*(a+b); p a^2 + a*b + a^3 + a^2*b + a*b*a + a*b^2 + b*a^2 + b*a*b + b^2*a + b^3 sage: P = QQ['a','b'] sage: P(p) a^3 + 3*a^2*b + 3*a*b^2 + b^3 + a^2 + a*b You say that you want to appear b before a, but that should merely by a choice of order: sage: P2 = QQ['b','a'] sage: P2(p) b^3 + 3*b^2*a + 3*b*a^2 + a^3 + b*a + a^2 Both P1 and P2 have a degree lexicographic order. If you want pure lexicographic, it can be done as well: sage: P3 = PolynomialRing(QQ, ['b','a'], order='lex') sage: P3(p) b^3 + 3*b^2*a + 3*b*a^2 + b*a + a^3 + a^2 sage: P4 = PolynomialRing(QQ, ['a','b'], order='lex') sage: P4(p) a^3 + 3*a^2*b + a^2 + 3*a*b^2 + a*b + b^3 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
