On 04/22/2010 12:41 AM, Mike Hansen wrote:
On Wed, Apr 21, 2010 at 8:06 PM, Elizabeth<papag...@earthlink.net>  wrote:
I'd like to know if there is a way to define a variable in Sage as non-
commuting.
I am trying to multiply a few matrices together and take the trace,
*but* the matrix entries are non-commuting elements.  So, I need Sage
to leave a term like  a*x*a as-is and not change it to x*a^2.

You could work over the FreeAlgebra:

sage: R.<a,b>  = FreeAlgebra(QQ, 2)
sage: a*b + b*a
a*b + b*a
sage: s = matrix(R)
sage: s = matrix(R, [[a,b],[b,a]]); s
[a b]
[b a]
sage: s*s
[a^2 + b^2 a*b + b*a]
[a*b + b*a a^2 + b^2]
sage: b*s*s
[  b*a^2 + b^3 b*a*b + b^2*a]
[b*a*b + b^2*a   b*a^2 + b^3]



Nice!  I've added the above example to the FAQ.

Thanks,

Jason


--
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