# Convert, using the Pauli matrices, an $n \times m$ matrix of quaternions into a $2 n \times 2 m$ matrix with complex entries, and vice versa

I'd like to go between $n \times m$ matrices with quaternionic entries to (using, it would seem, the Pauli matrix conversion scheme) to $2 n \times 2 m$ matrices with complex entries, and vice versa. I'd appreciate some efficient coding to accomplish this pair of tasks.

Say we have an $n \times m$ matrix the $n m$ entries of which are quaternions. We want to generate a $2 n \times 2 m$ matrix through the rule

Quaternion[a_, b_, c_, d_] ->
(a IdentityMatrix - b PauliMatrix - c PauliMatrix - d PauliMatrix)


So, it seems that we have to appropriately reshape the resultant array (using, presumably, ArrayReshape) to the desired $2 n \times 2 m$ form.

Then, what off-hand seems more challenging, we want to be able to perform the inverse operation (going from the $2 n \times 2 m$ form to the [quaternionic-entry] $n \times m$ form]). Such an inverse operation would assume that the matrix to be transformed back possesses the indicated special (Pauli matrix) structure.

As some background to this problem, what I am really interested in accomplishing is finding the appropriate way to generate random quaternionic $4 \times 4$ density matrices with respect to Hilbert-Schmidt measure. The manner of accomplishing this for random complex $4 \times 4$ density matrices and random real $4 \times 4$ density matrices is presented in

https://arxiv.org/pdf/0909.5094.pdf

(see eq. (1) and bot. p. 9 there). It seems that I may have to convert the $4 \times 4$ quaternionic-entry matrices to $8 \times 8$ form and use the developed rule for complex-entry matrices.

Some background references to the general quaternionic/Pauli matrix topic are (the amazingly detailed)

https://physics.stackexchange.com/questions/271419/why-is-there-this-relationship-between-quaternions-and-pauli-matrices

and

http://mathworld.wolfram.com/Quaternion.html

which has a very explicit (eqs. (2)-(5)) straightforward treatment pertaining to the issue raised.

As well as wikipedia,

https://en.wikipedia.org/wiki/Pauli_matrices#Quaternions

• Please post any code you have tried and point out where exactly you're having difficulties. Without that, it will be difficult to write an answer that meets your needs. – Jens Jun 21 '17 at 21:17
• Thanks, Jens! Well, I was hoping for some code that would avoid having to go entry-by-entry, but rather work in some more "global" (presumably, more efficient) blockwise manner, possibly using the Partition (ArrayReshape?) command. Actually, I'm most interested in $4 \times 4$ and $2 \times 2$ matrices with quaternionic entries. – Paul B. Slater Jun 21 '17 at 22:55
• I think this will suffer the fate of all-too many questions that may be interesting but don't contain enough information to attract the attention of other Mathematica users. Remember this is a Mathematica and not a physics site. The form of the end result is actually quite ambiguous, I think. – Jens Jun 22 '17 at 0:22
• Please take your time to edit into this question an example of the 2x2 and 4x4 matrices and define what the Pauli matrix conversion scheme is. As a physicist and a user of MMA I'll be happy to learn something outside of my field and to try solving a problem with my favorite tool. Once these details are included, I'll be more than willing to vote to reopen. VTC for now. – LLlAMnYP Jun 22 '17 at 6:06
• My guess is you need KroneckerProduct, similar to this question. But it's only a guess until the desired input and output forms are described in more detail. – Jens Jun 22 '17 at 15:44

Here are some functions to convert back and forth between quaternions and Pauli matrices:

basis = {IdentityMatrix, -PauliMatrix, -PauliMatrix, -PauliMatrix};
$ProjectionMatrices = Transpose[basis, {3,1,2}]/2; toQuant[m_] := Quaternion @@ Simplify @ Tr[m .$ProjectionMatrices, Plus, 2]
fromQuant[Quaternion[a_, b_, c_, d_]] := {a, b, c, d} . basis


So, a function to convert a matrix of quaternions to and from a "Pauli form" could be:

toPauli[m_] := ArrayFlatten[m /. q_Quaternion :> fromQuant[q]]

fromPauli[m_] := Map[toQuant, Partition[m, {2, 2}], {-3}]


For example:

m = Apply[Quaternion,RandomInteger[10,{4,4,4}],{2}]


{{Quaternion[2, 3, 9, 4], Quaternion[1, 10, 9, 5], Quaternion[10, 0, 4, 9], Quaternion[0, 0, 8, 7]}, {Quaternion[10, 5, 6, 7], Quaternion[0, 5, 5, 8], Quaternion[8, 8, 1, 0], Quaternion[3, 3, 5, 10]}, {Quaternion[0, 7, 1, 4], Quaternion[5, 1, 3, 3], Quaternion[0, 0, 9, 8], Quaternion[4, 8, 1, 5]}, {Quaternion[6, 0, 4, 4], Quaternion[9, 7, 8, 3], Quaternion[1, 4, 6, 0], Quaternion[5, 2, 6, 10]}}

p = toPauli[m];
p //TeXForm


$\left( \begin{array}{cccccccc} -2 & -3+9 i & -4 & -10+9 i & 1 & 4 i & -7 & 8 i \\ -3-9 i & 6 & -10-9 i & 6 & -4 i & 19 & -8 i & 7 \\ 3 & -5+6 i & -8 & -5+5 i & 8 & -8+i & -7 & -3+5 i \\ -5-6 i & 17 & -5-5 i & 8 & -8-i & 8 & -3-5 i & 13 \\ -4 & -7+i & 2 & -1+3 i & -8 & 9 i & -1 & -8+i \\ -7-i & 4 & -1-3 i & 8 & -9 i & 8 & -8-i & 9 \\ 2 & 4 i & 6 & -7+8 i & 1 & -4+6 i & -5 & -2+6 i \\ -4 i & 10 & -7-8 i & 12 & -4-6 i & 1 & -2-6 i & 15 \\ \end{array} \right)$

m == fromPauli[p]


True