Constructing Matrix Kronecker Products

The Wolfram Mathematica command

?KroneckerProduct

Allows us to easily construct direct products of qubits in order to assemble a multi-qubit register.

We define the matrix representation for the qubit basis vectors |0 ⟩, |1 ⟩ in the usual way;

ClearAll["Global`*"]
zeroket={1,0};
oneket={0,1};

To construct the direct products |0 ⟩ ⊗ |0 ⟩, |0 ⟩ ⊗ |1 ⟩, |1 ⟩ ⊗ |0 ⟩, |1 ⟩ ⊗ |1 ⟩ we use a combination of the Wolfram KroneckerProduct and Flatten commands, as in

state00=Flatten[KroneckerProduct[zeroket,zeroket]];
state01=Flatten[KroneckerProduct[zeroket,oneket]];
state10=Flatten[KroneckerProduct[oneket,zeroket]];
state11=Flatten[KroneckerProduct[oneket,oneket]];

Or

state00 // MatrixForm

state01 // MatrixForm

state10 // MatrixForm

state11 // MatrixForm

In agreement with Eqs. (2.55), (2.56) in the text.

Let’s define the 3-qubit function

threeQ[qubit3_,qubit2_,qubit1_]:=Flatten[KroneckerProduct[qubit3,qubit2,qubit1]];

Exercises

(1) Use the function threeQ to construct the eight basis vectors that span a 3-qubit register.

(2) Define a function that inputs 5 qubits and allows construction of their (matrix representation) direct products. Use the latter to find the matrix representation of the state

({{({{(|00101⟩}})- i  |10000 ⟩+  |10101 ⟩)/(Sqrt[3])}})

Operators

We know that the matrix representation of single qubit operators are 2 × 2 square matrices, as for example the Pauli gates, σX,σY,σZ

PauliX={{0,1},{1,0}};
PauliY={{0,-I},{I,0}};
PauliZ={{1,0},{0,-1}};

Let’s also include the unit operator

unit={{1,0},{0,1}};

We wish to construct the matrix representations of two-qubit operators, e.g. σX ⊗σY. In Mathematica this is accomplished with the KroneckerProduct command as in

operatorXY=KroneckerProduct[PauliX,PauliY] ;

and which should be expressed as a 2×2 matrix; indeed

operatorXY // MatrixForm

Lets check if this matrix, when acting on a 2-qubit state, transform the column matrix in a way that is isomorphic to the transformation in ket space. As an example we consider the operation

({{({{σX ⊗ σY |01 ⟩}})}})

Using the definitions introduced in Chapter 1 of the text, the above is equivalent to

({{({{σX |0 ⟩ ⊗ σY |1 ⟩ = |1 ⟩⊗ (-i |0 ⟩) = -i |10 ⟩}})}})

Using the matrix representations,

output=operatorXY.state01

output==-I state10

And so, the matrix representation for σX ⊗ σY acting on the matrix representation of |01⟩  is isomorphic to the result obtained in ket space.

Exercises

(1) Construct the matrix representations of the following 3-qubit operators (here 1 represents the qubit identity operator)
     (a)  σX ⊗ 1⊗ σY
     (b) σX  ⊗ σY ⊗ 1

(2) Apply the above matrix operators to the matrix vector corresponding to state |000⟩. Evaluate the result, first using the Dirac ket formalism, and compare with the result obtained with the matrix representation.

(3) Construct the matrix representation for the single-qubit Hadamard gate H. Construct the matrix operator H⊗H⊗H, and let it operate on state |000 ⟩. Comment.