# Kronecker product $n$ matrices

I would like to write code to realize the Kronecker Product of $$n$$ matrices, for instance when $$n=4$$ and the matrices are Pauli matrices

KroneckerProduct[PauliMatrix[1], PauliMatrix[1], PauliMatrix[1], PauliMatrix[1]]


Is there a convenient way to first incorporate the general $$n$$ in the code, so that I don't have to write the code each time I change $$n$$?

Sequence[ ] would be the go-to, but it flattens out the list.

Plan B: You can create a new operator that will 'fold' up the list.

Create the operator

kronk = Fold[KroneckerProduct];


Get your list of arbitrary length:

n = 4; res = Table[PauliMatrix[1], n];


Use your operator on the list

kronk[res] == KroneckerProduct[PauliMatrix[1], PauliMatrix[1], PauliMatrix[1], PauliMatrix[1]]
(* True *)

• @MilkY thank you! Dec 14, 2018 at 0:00
kronkPauli[ind_List] := KroneckerProduct @@ PauliMatrix[ind]

kronkPauli[{1, 1, 1, 1}]


Update

Above kronkPauli accepts any combinations of PauliMatrixes (for $$i=0,1,2,3$$). But if you want only a couple of ones with $$i=1$$, the resultant matrix is just an antidiagonal one, with all $$1$$s located at the antidiagonal positions.

For that special kind of matrixes, it can, at least, be realized by below two methods:

matrix[n_] := SparseArray[{i_, j_} /; i + j == 2^n + 1 -> 1, 2^{n, n}]
matrix2[n_] := IdentityMatrix[2^n] // Reverse

• Doh...must be a pathological thing with me and Apply[ ], just never use it much. Dec 14, 2018 at 19:47
• @MikeY Why it is so, may I ask? Dec 16, 2018 at 7:24
• Just a mental block, I guess. I think of a List as a fundamental data type that gets passed as an argument rather than the head of an expression that can be replaced to magically co-opt it. My loss, but I am working on it! Dec 16, 2018 at 16:37

I have been searching for the same problem and I solved it in an easier way to perform the same task.

n = 4;
NUf = PauliMatrix[1];
For[i = 1, i <= n - 1, i++, {
NUf = KroneckerProduct[NUf, PauliMatrix[1]];
}]


the matrix form of the result