One should really use commutator
rather than Commutator
for future-proofing concerns, but I have some bad habits...
Clear[Commutator]
(* Manually implement the algebra of interest: *)
Commutator[L1, L2] = I L3; Commutator[L2, L1] = -I L3;
Commutator[L2, L3] = I L1; Commutator[L3, L2] = -I L1;
Commutator[L3, L1] = I L2; Commutator[L1, L3] = -I L2;
(* Implement linearity, so that numbers can be pulled out. *)
Commutator[Times[c_, A__], B_] := c Commutator[Times[A], B] /; NumericQ[c]
Commutator[A_, Times[c_, B__]] := c Commutator[A, Times[B]] /; NumericQ[c]
(* Linearity
[A+B+...,C] = [A,C]+[B,C]+... and [A,B+C+...] = [A,B]+[A,C]+...
*)
Commutator[Plus[A_, Addends__], B_]:=Commutator[A, B] + Commutator[Plus[Addends], B]
Commutator[A_, Plus[B_, Bddends__]]:=Commutator[A, B] + Commutator[A, Plus[Bddends]]
(* Note the reversed ordering! *)
hadamard[order_] := Sum[1/k! Fold[Commutator[#2, #1] &, B, Table[A, {k}]], {k, 0, order}]
NumericQ[\[Phi]] = True;
hadamard[10] /. {B -> L1, A -> I \[Phi] L2}
It is possible to make Commutator
naturally antisymmetric in its arguments, but it takes more thinking. If you've got an algebra already it's probably worth writing out explicitly.
We can implement additional rules, but it requires a general implementation of noncommutative multiply. Mathematica has a built-in NonCommutativeMultiply
which we can write as an infix operator **
. But it requires some additional structure:
Unprotect[NonCommutativeMultiply];
Clear[NonCommutativeMultiply];
(* Flatness causes infinite loop problems for the pattern matcher *)
ClearAttributes[NonCommutativeMultiply, Flat];
(* But one-way flatness is fine. *)
NonCommutativeMultiply[A___, NonCommutativeMultiply[B__], C___] := NonCommutativeMultiply[A, B, C]
(* And if there's only one argument, you can get rid of the NCM wrapper *)
NonCommutativeMultiply[A_] := A
(* And if NCM has nothing in it, evaluate to the empty product. *)
NonCommutativeMultiply[] := 1
(* Distribution of ** over + *)
NonCommutativeMultiply[A___, Plus[B_, Bddends__], C___] := NonCommutativeMultiply[A, B, C] + NonCommutativeMultiply[A, Plus[Bddends], C]
(* Numeric things commute. *)
NonCommutativeMultiply[A___, c_, B___] := c NonCommutativeMultiply[A, B] /; NumericQ[c]
NonCommutativeMultiply[A___, Times[b_, B___], C___] := b NonCommutativeMultiply[A, Times[B], C]/; NumericQ[b]
(* Leibniz rule [AB,C] = A[B,C] + [A,C]B and [A,BC]=B[A,C]+[A,B]C *)
Commutator[NonCommutativeMultiply[A_, B__], C_] := Commutator[A, C] ** NonCommutativeMultiply[B] + A ** Commutator[NonCommutativeMultiply[B], C]
Commutator[A_, NonCommutativeMultiply[B__, C_]] := Commutator[A, NonCommutativeMultiply[B]] ** C + NonCommutativeMultiply[B] ** Commutator[A, C]
You further can add additional rules too, like
Commutator[A_, A_] := 0
Commutator[A_, B_] := A**B - B**A
which allows you to arrive at conclusions like
Commutator[L1, L2 ** L3]
(* I L1 ** L1 - I L2 ** L2 *)
using the above definitions for the specific Commutator
s given by the specified algebra. Note that you can't derive that it's zero without an additional explicit assumption. This also could let you define products L1**L2
rather than Commutator[L1,L2]
if you so desired.
At this point I should point out that this answer is converging towards my answer to https://mathematica.stackexchange.com/a/63880/7936 but also that there's a bug there that I never tracked down.