I want define a function of n variables as follows $$f(x_1, ..., x_n)= KroneckerProduct[\sigma^{x_1}, ..., \sigma^{x_n}]$$ where $\sigma^{x_i}=PauliMatrix[x_i]$. Given a number $n$, I can explicitly write down an expression. For example, for $n=3$, I can write down

f[i1_, i2_, i3_] :=KroneckerProduct[PauliMatrix[i1], PauliMatrix[i2],PauliMatrix[i3]]; 

However, how to write down a generic expression in terms of arbitrary $n$, so that I don't have to rewrite the expression for every choice of $n$? Thanks!

f[i__] := KroneckerProduct @@ PauliMatrix[{i}]

f[1, 2, 3] == KroneckerProduct[PauliMatrix[1], PauliMatrix[2], PauliMatrix[3]]
(*    True    *)

Do you need special cases for zero or one Pauli matrix, or do these cases never occur for you?

  • $\begingroup$ Thank you Roman! Zero and One Pauli matrix are not within my consideration. So it should be fine. $\endgroup$
    – user34104
    Jun 1 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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