Let's start with something that works:
restart:
with(Physics):
Setup(noncommutativeprefix = {A, B}):
expand((A+B)^2);
gives
A^2+A*B+B*A+B^2
Maple recognizes the A and B don't commute. Now, let's expand their sum in a taylor series, and expand that:
restart:
with(Physics):
Setup(noncommutativeprefix = {A, B}):
S := convert(taylor(exp((A+B)*delta), delta = 0, 3), polynom);
gives
1 2 2
S := 1 + (A + B) delta + - (A + B) delta
2
and then
expand(S);
gives
1 2 2 2 1 2 2
1 + delta A + delta B + - A delta + A B delta + - B delta
2 2
Maple no longer recognizes that A and B don't commute. Clearly(?) I don't know how to use maple properly. How do I get maple to recognize that A and B don't commute in this context? there is discussion of this here: http://www.mapleprimes.com/questions/95808-Noncommutative-Operators, in the maple help, and elsewhere, I'm sure..
I should add, (obviously), that the following works, but it gets ugly. there must be a better way:
restart;
unassign(`&*`); define(`&*`, multilinear, zero = 0, identity = 1, flat);
constants := constants, lambda;
No := 3;
S := convert(taylor(exp((A+B)*delta), delta = 0, No), polynom);
1 2 2
S := 1 + (A + B) delta + - (A + B) delta
2
S := subs((A+B)^2 = `&*`(A+B, A+B), (A+B)^3 = `&*`(`&*`(A+B, A+B), A+B), (A+B)^4 = `&*`(`&*`(`&*`(A+B, A+B), A+B), A+B), S);
S := 1 + (A + B) delta
1 2
+ - (A &* A + A &* B + B &* A + B &* B) delta
2
simplify(S);
1 2 1 2
1 + delta A + delta B + - delta (A &* A) + - delta (A &* B)
2 2
1 2 1 2
+ - delta (B &* A) + - delta (B &* B)
2 2
definemore(`&*`, `&*`(A, A) = A^2, `&*`(B, B) = B^2, `&*`(A, B) = AB, `&*`(B, A) = BA);
simplify(S);
1 2 2 1 2 2 1 2
1 + delta A + delta B + - A delta + - B delta + - AB delta
2 2 2
1 2
+ - BA delta
2
I'm now using maple 17.
Edit: Here is a continuation of the above question, now with edgardo's feedback:
I am trying to perform the following calculation, using Gtaylor:
with(Physics);
Setup(noncommutativeprefix = {A, B});
exp3 := convert(Gtaylor(exp((a-I*b))*delta*B), delta = 0, No), polynom);
exp5 := convert(Gtaylor(exp((a-I*b))*delta*A), delta = 0, No), polynom);
expansion := coeff(simplify(subs(delta = lambda, exp1*exp2*exp1*exp3*exp5*exp3)), lambda, No-1);
not all the code is included. exp5 &3 are examples of what all the other exp's look like. No is set to 5, and and b are fractions. This code works (haven't confirmed with independent code but let's assume it does), but it takes a -very- long time. Is there any way to speed it up?