9
$\begingroup$

Is there a way of obtaining the matrix matFinal quickly by avoiding the following long procedure?

    s1 = PauliMatrix[1]; s2 = PauliMatrix[2]; s3 = PauliMatrix[3];
u = {{a^2, 0, 0, 0, 0, 0, 0, a b}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0,
     0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0,
    0}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {a b, 0,
    0, 0, 0, 0, 0, b^2}};
m11 = Tr[u.KroneckerProduct[s1, s1, s1]];
m12 = Tr[u.KroneckerProduct[s1, s1, s2]];
m13 = Tr[u.KroneckerProduct[s1, s1, s3]];
m14 = Tr[u.KroneckerProduct[s1, s2, s1]];
m15 = Tr[u.KroneckerProduct[s1, s2, s2]];
m16 = Tr[u.KroneckerProduct[s1, s2, s3]];
m17 = Tr[u.KroneckerProduct[s1, s3, s1]];
m18 = Tr[u.KroneckerProduct[s1, s3, s2]];
m19 = Tr[u.KroneckerProduct[s1, s3, s3]];

m21 = Tr[u.KroneckerProduct[s2, s1, s1]];
m22 = Tr[u.KroneckerProduct[s2, s1, s2]];
m23 = Tr[u.KroneckerProduct[s2, s1, s3]];
m24 = Tr[u.KroneckerProduct[s2, s2, s1]];
m25 = Tr[u.KroneckerProduct[s2, s2, s2]];
m26 = Tr[u.KroneckerProduct[s2, s2, s3]];
m27 = Tr[u.KroneckerProduct[s2, s3, s1]];
m28 = Tr[u.KroneckerProduct[s2, s3, s2]];
m29 = Tr[u.KroneckerProduct[s2, s3, s3]];

m31 = Tr[u.KroneckerProduct[s3, s1, s1]];
m32 = Tr[u.KroneckerProduct[s3, s1, s2]];
m33 = Tr[u.KroneckerProduct[s3, s1, s3]];
m34 = Tr[u.KroneckerProduct[s3, s2, s1]];
m35 = Tr[u.KroneckerProduct[s3, s2, s2]];
m36 = Tr[u.KroneckerProduct[s3, s2, s3]];
m37 = Tr[u.KroneckerProduct[s3, s3, s1]];
m38 = Tr[u.KroneckerProduct[s3, s3, s2]];
m39 = Tr[u.KroneckerProduct[s3, s3, s3]];

matFinal = {{m11, m12, m13, m14, m15, m16, m17, m18,
   m19},        {m21, m22, m23, m24, m25, m26, m27, m28, m29}, {m31,
   m32, m33, m34, m35, m36, m37, m38, m39}}

Note that mi(jk) = Tr[u.KroneckerProduct[si, sj, sk]].

$\endgroup$

2 Answers 2

11
$\begingroup$
matFinal2 = Join @@@ Array[Tr[u. KroneckerProduct @@ (PauliMatrix /@ {##})] &, {3, 3, 3}]
{{2 a b, 0, 0, 0, -2 a b, 0, 0, 0, 0}, 
 {0, -2 a b, 0, -2 a b, 0, 0, 0, 0, 0}, 
 {0, 0, 0, 0, 0, 0, 0, 0, a^2 - b^2}}
TeXForm @ MatrixForm @ matFinal2

$\left( \begin{array}{ccccccccc} 2 a b & 0 & 0 & 0 & -2 a b & 0 & 0 & 0 & 0 \\ 0 & -2 a b & 0 & -2 a b & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & a^2-b^2 \\ \end{array} \right)$

Alternative version without @, @@, @@@, /@, ##:

matFinal3 = Map[Flatten][
   Table[Tr[u.KroneckerProduct[PauliMatrix[i], PauliMatrix[j], PauliMatrix[k]]], 
     {i, 3}, {j, 3}, {k, 3}]];

matFinal3 == matFinal2 == matFinal
True
$\endgroup$
4
  • $\begingroup$ Thanks a lot!, but this notation @, @@, @@@, /@, ## is too compact and I am not able to understand what is happening:) $\endgroup$
    – User101
    Jan 11, 2022 at 20:26
  • $\begingroup$ Could you write in couple of lines on how this works? $\endgroup$
    – User101
    Jan 11, 2022 at 20:27
  • 6
    $\begingroup$ Read the documentation for Prefix, Function, Map, and Apply. In general, in Mathematica highlight a symbol or operator that you don't understand (e.g., @@) and press F1 for help. $\endgroup$
    – Bob Hanlon
    Jan 11, 2022 at 20:33
  • $\begingroup$ @User101, see if the alternative version using Table is easier to follow. $\endgroup$
    – kglr
    Jan 11, 2022 at 20:35
6
$\begingroup$

Similar to kglr's answer:

Clear["Global`*"]

s = Array[PauliMatrix, 3];

u = SparseArray[{{1, 1} -> a^2, {1, 8} -> a b, {8, 1} -> a b,
  {8, 8} -> b^2}];

(matFinal =
   Partition[Tr[u . KroneckerProduct[##]] & @@@ Tuples[s, 3],
    9]) // MatrixForm

Enter image description here

$\endgroup$

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.