1
$\begingroup$

I am trying to solve physic problem on operators which are not commute. However, I am not good at coding, so I am having some problem with Mathematica code.

Let's define my list such that

b[0] a[1] a[0] a[0]

The rules are that b and a are commute, same elements are commute(a[0] and a[0]), but a[1] and a[0] or b[1] and b[0] are not commute.

a[0] a[1] = a[1] a[0] + 1        
b[0] b[1] = b[1] b[0] + 1

My goal is place b at the end, and place element with [1] at the end.

b[0]a[1]a[0]a[0] -> b[0] (a[0]a[1] + 1) a[0] -> b[0]a[0]a[1]a[0] + b[0]a[0]
-> b[0]a[0] (a[0]a[1] + 1) + b[0]a[0] -> b[0]a[0]a[0]a[1] + 2 b[0]a[0]
-> a[0]a[0]a[1]b[0] + 2 a[0]b[0]

I thought it might be good for me to use list-manipulation.

{b[0], a[1], a[0], a[0] } ->  { a[0], a[0], a[1], b[0] } + 2 { a[0] , b[0] }

Similarly

{b[1], b[0], a[0], a[0]} -> { a[0], a[0], b[0], b[1] } +{a[0] a[0]}

{b[1], b[1], b[0], a[0]} -> { a[0], b[0], b[1], b[1] } + 2 {a[0] b[1]}

{a[1], a[1], a[1], a[0]} -> { a[0], a[1], a[1], a[1]} +3 {a[1],a[1]}

{a[1], a[1], a[0], a[0]} -> { a[0], a[0], a[1], a[1]} +2 {a[1],a[0]} +2 {a[0]+a[1]} 
->{ a[0], a[0], a[1], a[1]} + 4{a[0]+a[1]} + 2

Anyone can suggest me what command shall I use? I think I can use If[], MemberQ[] and Select[]. However, I am not sure where to start.

Thank you

$\endgroup$
4
  • $\begingroup$ For me your example is a bit too cryptic. Can't you come up with a more simple/clear example? $\endgroup$
    – Kay
    Apr 14, 2016 at 15:31
  • 2
    $\begingroup$ You should look up NonCommutativeMultiply and the many questions about boson algebra on this site. For instance, this one and this one. $\endgroup$
    – march
    Apr 14, 2016 at 15:52
  • $\begingroup$ Start with this example rule = {{h___, b[n_], a[m_], t___} -> {h, a[m], b[n], t}, {h___, a[n_], a[m_], t___} /; n < m -> {h, a[m], a[n], 1, t}, {h___, b[n_], b[m_], t___} /; n < m -> {h, b[m], b[n], 1, t}, {h___, 1, a[n_], t___} -> {h, a[n], 1, t}, {h___, 1, b[n_], t___} -> {h, b[n], 1, t}}; {b[0], a[0], a[1], a[0]} //. rule and study this to understand it. Try this on various lists. Then edit your post to show how you used this and examples where more rules are needed. $\endgroup$
    – Bill
    Apr 14, 2016 at 16:01
  • $\begingroup$ Thank you @bill for the generous guide! $\endgroup$
    – Saesun Kim
    Apr 14, 2016 at 20:55

1 Answer 1

3
$\begingroup$

You could use NonCommutativeMultiply. For instance:

Unprotect[NonCommutativeMultiply];

o_ ** 1 := o;
1 ** o_ := o;

o_ ** p_Plus := Plus @@ (o ** # & /@ p);
p_Plus ** o_ := Plus @@ (# ** o & /@ p);

o1_ ** Times[k : Except[_a | _b], o2_] := k o1 ** o2;
Times[k : Except[_a | _b], o1_] ** o2_ := k o1 ** o2;

o1_b ** o2_a := o2 ** o1;

MakeBoxes[NonCommutativeMultiply[e1_, e2_], StandardForm] := 
       RowBox[{MakeBoxes[e1, StandardForm], MakeBoxes[e2, StandardForm]}];

Protect[NonCommutativeMultiply];

a /: a[1] ** a[0] := a[0] ** a[1] + 1;
b /: b[1] ** b[0] := b[0] ** b[1] + 1;

Taking your examples:

b[0] ** a[1] ** a[0] ** a[0]
(* 2 (a[0] b[0]) + a[0] a[0] a[1] b[0] *)

b[1] ** b[0] ** a[0] ** a[0]
(* a[0] a[0] + a[0] a[0] b[0] b[1] *)

b[1] ** b[1] ** b[0] ** a[0]
(* 2 (a[0] b[1]) + a[0] b[0] b[1] b[1] *)

a[1] ** a[1] ** a[1] ** a[0]
(* 3 (a[1] a[1]) + a[0] a[1] a[1] a[1] *)

a[1] ** a[1] ** a[0] ** a[0]
% // Expand
(* 2 (a[0] a[1]) + 2 (1 + a[0] a[1]) + a[0] a[0] a[1] a[1] *)
(* 2 + 4 (a[0] a[1]) + a[0] a[0] a[1] a[1] *)
$\endgroup$
1
  • $\begingroup$ @SaesunKim Thanks for the accept! :-) $\endgroup$
    – user31159
    Apr 14, 2016 at 21:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.