1
$\begingroup$

I have the following code for normal ordering of two Boson operators $a(x),\,b(y)$:

Unprotect[NonCommutativeMultiply]; ClearAll[NonCommutativeMultiply] NonCommutativeMultiply[] := 1 NonCommutativeMultiply[a_] := a SetAttributes[NonCommutativeMultiply, {OneIdentity, Flat}] Protect[NonCommutativeMultiply]; NO[x___] := NonCommutativeMultiply[x]; NO[] := 1 NO[x_] := x NO[left___ ** a[x_] ** SuperDagger[a][y_] ** right___] := NO[left ** SuperDagger[a][y] ** a[x] ** right] + left ** right*KroneckerDelta[x - y] NO[left___ ** b[x_] ** SuperDagger[b][y_] ** right___] := NO[left ** SuperDagger[b][y] ** b[x] ** right] + left ** right*KroneckerDelta[x - y] NO[left___ ** a[x_] ** SuperDagger[b][y_] ** right___] := NO[left ** SuperDagger[b][y] ** a[x] ** right] NO[left___ ** b[x_] ** SuperDagger[a][y_] ** right___] := NO[left ** SuperDagger[a][y] ** b[x] ** right] NO[left___ ** a[x_] ** b[y_] ** right___] := NO[left ** b[y] ** a[x] ** right] NO[left___ ** SuperDagger[a][x_] ** SuperDagger[b][y_] ** right___] := NO[left ** SuperDagger[b][y] ** SuperDagger[a][x] ** right] NO[Times[u_, y___]] := u NO[y] 

which works fine, e.g:

NO[b[q] ** a[k] ** SuperDagger[a][q]] (*=> b[q] KroneckerDelta[k - q] + SuperDagger[a][q] ** b[q] ** a[k]) 

The problem is if the operators product is multiplied by scalars. NO[Times[u_, y___]] := u NO[y] takes care of the problem if you have one scalar e.g:

NO[u b[q] ** a[k] ** SuperDagger[a][q]] (*=> u (b[q] KroneckerDelta[k - q] + SuperDagger[a][q] ** b[q] ** a[k]) ) 

However I am stuck on how to make it work in case you have many different scalars mutliplying the operators, e.g:

NO[u v w b[q] ** a[k] ** SuperDagger[a][q]] 
$\endgroup$

1 Answer 1

1
$\begingroup$
NO[Times[x__, y_NonCommutativeMultiply, z___]] := x z NO[y] NO[Times[x___, y_NonCommutativeMultiply, z__]] := x z NO[y] 

should do the trick in all situations:

enter image description here

Depending of the canonical ordering of Times it might not be necessary to include both versions but better save then sorry.

$\endgroup$
2
  • $\begingroup$ thanks! Seems to do the trick, NO[Times[x___, y_NonCommutativeMultiply, z__]] := x z NO[y] wouldn't be sufficient? x___ covers x__, doesn't it? $\endgroup$ Commented Jan 6, 2021 at 23:13
  • 1
    $\begingroup$ Yes but in the case x___ one needs an expression matching a non empty sequence for z__ which might not be given. Depending on the kind of products and expression ordering of Times NO[Times[x__, y_NonCommutativeMultiply, z___]] := x z NO[y] might not cover cases where like a ** b*Z[c]*... just to be save I would keep both. Allowing empty sequences for both x and z might be the cleanest solution NO[Times[x___, y_NonCommutativeMultiply, z___]] := x z NO[y] after all but when I wrote the answer I was not sure wether this would work. I think it does now. $\endgroup$ Commented Jan 7, 2021 at 0:09

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.