# Inner function with Kronecker products

I am trying to calculate $\sigma_1 \otimes \sigma_2 + \sigma_2 \otimes \sigma_1$ as a inner product. My attempt

Inner[KroneckerProduct, {PauliMatrix[1], PauliMatrix[2]}, {PauliMatrix[2], PauliMatrix[1]}, Plus]


does not work. Any idea why?

• Inner strips all list levels from {PauliMatrix[1], PauliMatrix[2]}, not just the outer braces. Since Inner does not have a level option, I would say it is not suitable for the task. – Felix Mar 16 '17 at 19:47
• You could do Inner[KroneckerProduct, {a, b}, {b, a}, Plus] /. {a -> PauliMatrix[1], b -> PauliMatrix[2] }. – march Mar 17 '17 at 3:43
• ... also Plus @@ MapThread[ KroneckerProduct, {{PauliMatrix[1], PauliMatrix[2]}, {PauliMatrix[2], PauliMatrix[1]}}] – kglr Mar 26 '17 at 22:32

Utilizing march's comment.

You want to first construct an inner product, then insert Pauli matrices:

f[a_, b_] = Inner[KroneckerProduct, {a, b}, {b, a}, Plus]
f[PauliMatrix[1], PauliMatrix[2]] // MatrixForm


Note the usage of Set (=) instead of the usual SetDelayed (:=).

Some Inactive[] trickery gets the job done:

With[{p1 = Inactive[PauliMatrix][1], p2 = Inactive[PauliMatrix][2]},
Inner[Inactive[KroneckerProduct], {p1, p2}, {p2, p1}, Plus] // Activate]
{{0, 0, 0, -2 I}, {0, 0, 0, 0}, {0, 0, 0, 0}, {2 I, 0, 0, 0}}


(Use Hold[]/ReleaseHold[] in earlier versions.)

Plus @@ MapThread[KroneckerProduct, {#, Reverse@#} &[PauliMatrix /@ {1, 2}]] // MatrixForm