2
$\begingroup$

How to implement a commutator of matrices composed of operators?

Background:

Let $\hat A_{ij}$, $\hat B_{kl}$ be some sets of some operators. $\hat I$ is the identity operator. Their commutators are defined as usual $[\hat A_{ij},\hat B_{kl}]=\hat A_{ij}\hat B_{kl}-\hat B_{kl}\hat A_{ij}$. Out of these operators two matrices $mH$ and $mQ$ (both can be sparse) are constructed. I would like to compute a commutator $mC=[mH,mQ]$ and express (where possible) the elements of $mC$ in terms of commutators $[\hat A_{ij},\hat B_{kl}]$.

Example:

Define $mH$ and $mQ$ as $2\times 2$ matrices:

Clear[mH, mQ]
mH = {{h, v},{v, h + i}};
mQ = {{q0, p},{p, q1}};

Define $f$ as non-commutative but distributive operation; $i$ is the identity operator

f[a_ + b_, c_] := f[a, c] + f[b, c]
f[c_, a_ + b_] := f[c, a] + f[c, b]
f[i, a_] := a;
f[a_, i] := a;

Dot only works for the normal multiplication operation, therefore, compute the commutator using Inner

Clear[mC]
mC[0] = Inner[f, mH, mQ, Plus] - Inner[f, mQ, mH, Plus];

Express matrix elements in terms of commutators (denoted as c). This part is not working properly...

mC[1] = mC[0] /. {f[a_, b_] - f[b_, a_] -> c[a, b]};
MatrixForm[mC[1]]

$\left( \begin{array}{cc} c(h,\text{q0})-f(p,v)+f(v,p) & -p+c(h,p)-f(\text{q0},v)+f(v,\text{q1}) \\ p+c(h,p)-f(\text{q1},v)+f(v,\text{q0}) & c(h,\text{q1})-f(p,v)+f(v,p) \\ \end{array} \right)$

Problem:

We can see that some diagonal entries can still be expressed in terms of commutators. The FullForm reveals the reason. However, I do not know a nice way to solve this problem. Your help is very much appreciated!

$\endgroup$

1 Answer 1

2
$\begingroup$

You can use ReplaceRepeated:

mC[1] = mC[0] //. {f[a_, b_] - f[b_, a_] :> c[a, b]};
MatrixForm[mC[1]] // TeXForm

$\left( \begin{array}{cc} c(h,\text{q0})+c(v,p) & c(h,p)-f(\text{q0},v)+f(v,\text{q1})-p \\ c(h,p)+f(v,\text{q0})-f(\text{q1},v)+p & c(h,\text{q1})+c(v,p) \\ \end{array} \right)$

$\endgroup$

Your Answer

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

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