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?
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI 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?
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
Inner
strips all list levels from{PauliMatrix[1], PauliMatrix[2]}
, not just the outer braces. SinceInner
does not have a level option, I would say it is not suitable for the task. $\endgroup$Inner[KroneckerProduct, {a, b}, {b, a}, Plus] /. {a -> PauliMatrix[1], b -> PauliMatrix[2] }
. $\endgroup$Plus @@ MapThread[ KroneckerProduct, {{PauliMatrix[1], PauliMatrix[2]}, {PauliMatrix[2], PauliMatrix[1]}}]
$\endgroup$