Multiplying out (noncommutative) exponentials




> This isn't hugely important, but I was wondering if there is a way to
>convince Maxima to "multiply out" exponentials. That is, convert

>  (%i1) (a . x) ^^ 2;
>                                               <2>
>  (%o1)                             (a . x)


A start at such a function (notice the dotexptsimp flag)

(%i53) expand_ncexpt(e) := subst("^^" = lambda([x,n], block([z : 1, dotexptsimp : false
], if integerp(n) and n > 1 then (
     for k : 1 thru n do z : x . z, 
   z) else funmake("^^", [x,n]))), e);
(%o53) expand_ncexpt(e):=subst("^^"=lambda([x,n],block([z:1,dotexptsimp:false],if integerp(n) and n>1 then (for k thru n do z:x . z,z) else funmake("^^",[x,n]))),e)

(%i54) expand_ncexpt((a+x)^^4);
(%o54) (x+a) . (x+a) . (x+a) . (x+a)

(%i55) expand(%);
(%o55) (x . a)^^2+x^^3 . a+x^^2 . a^^2+x^^2 . a . x+x . a^^3+x . a^^2 . x+x . a . x^^2+x^^4+(a . x)^^2+a^^3 . x+a^^2 . x^^2+a^^2 . x . a+a . x^^3+a . x^^2 . a+a . x . a^^2+a^^4

oops--gotta do exand_ncexpt twice :(

(%i56) expand_ncexpt(%);
(%o56) x^^3 . a+x^^2 . a^^2+x^^2 . a . x+x . x . x . x+x . a^^2 . x+x . a . x . x+x . a . x . a+x . a . a . a+a^^3 . x+a^^2 . x^^2+a^^2 . x . a+a . x^^2 . a+a . x . x . x+a . x . a . x+a . x . a . a+a . a . a . a


-Barton