2
$\begingroup$

I would like to implement a function with variable numbers of arguments that generates

$\sigma_{j_1}\otimes\ldots \otimes\sigma_{j_L}$

where $\otimes$ is the Kronecker Product and $\sigma_j$ are the PauliMatrix[j]. I realize this function with

f[val__] := First@With[{lvar = Table[Symbol["j" <> ToString@k], {k, 
   Length@val}]}, (KroneckerProduct @@ 
  PauliMatrix /@ lvar) /. {MapThread[#1 -> #2 &, {lvar, val}]}]

For instance for obtaining $\sigma_1\otimes\sigma_1\otimes \sigma_2$ I write

f[{1, 1, 2}] 

It there a more easier way to do it?

$\endgroup$
0

1 Answer 1

2
$\begingroup$

Since PauliMatrix is Listable, you can simplify your definition to:

Clear[f2]
f2[list_List] := KroneckerProduct @@ PauliMatrix[list]

f[{1, 1, 2}] == f2[{1, 1, 2}]
(* True *)
$\endgroup$
2
  • $\begingroup$ Thank you very much! $\endgroup$
    – Galuoises
    Commented Jul 19, 2017 at 16:39
  • $\begingroup$ @Galuoises You are very welcome! $\endgroup$
    – MarcoB
    Commented Jul 19, 2017 at 16:39

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.