# 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, PauliMatrix}, {PauliMatrix, PauliMatrix}, Plus]


does not work. Any idea why?

• Inner strips all list levels from {PauliMatrix, PauliMatrix}, not just the outer braces. Since Inner does not have a level option, I would say it is not suitable for the task. Mar 16, 2017 at 19:47
• You could do Inner[KroneckerProduct, {a, b}, {b, a}, Plus] /. {a -> PauliMatrix, b -> PauliMatrix }. Mar 17, 2017 at 3:43
• ... also Plus @@ MapThread[ KroneckerProduct, {{PauliMatrix, PauliMatrix}, {PauliMatrix, PauliMatrix}}]
– kglr
Mar 26, 2017 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, PauliMatrix] // MatrixForm Note the usage of Set (=) instead of the usual SetDelayed (:=).

Some Inactive[] trickery gets the job done:

With[{p1 = Inactive[PauliMatrix], p2 = Inactive[PauliMatrix]},
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 