Matrix Manipulations and Operations with Mathematica

Introduction

In Chapter 2 of the text we introduced three types of matrices; column, row and square matrices. In general a so-called m × n matrix contains m rows and n columns. So a 2×3 matrix would look something like this

(({{a, b}, {c, d}, {e, f}}))

We will only be working with matrices of the type 1× n, n ×1, and n × n.  Kets are represented by column matrices and in Mathematica they are expressed as a list

?List

A single qubit e.g.  (({{a}, {b}}))  is represented by the Mathematica list

ket1={a,b}

A two-qubit state   (({{a}, {b}, {c}, {d}}))  would be represented by

ket2={a,b,c,d}

You might ask yourself; the list expressions given above do not look at all like column matrices. If anything, they resemble row matrices. However, as we will see in the examples below, in operations involving matrices the Mathematica kernel treats these lists as if they are
column matrices. If you still feel uncomfortable with this notation, you can apply the

?MatrixForm

operation on the above lists.  So

MatrixForm[ket1]

MatrixForm[ket2]

They look just like the column matrices you intended them to be.  So how are row matrices, represented bra vectors, expressed ? Answer:  Exactly in the same way!  So the row matrices

(({{a, b}}))   and    (({{a, b, c, d}}))    

are given by

bra1={a,b}
bra2={a,b,c,d}

How does Mathematica know the difference between column and row (ket and bra vectors) matrices?  Answer: Through context. Before we elaborate on this answer, lets quickly review how we introduce n × n square matrices.
Example: Consider the following 3 × 3 matrix

(({{a, b, c}, {d, e, f}, {g, h, i}}))

Mathematica ``sees’’ this construct as three lists  {a,b,c}, {d,e,f}, {g,h,i} stacked on top of each other or a ``list of  lists”,
i.e.

squarematrix={{a,b,c},{d,e,f},{g,h,i}}

If we apply

MatrixForm[squarematrix]

We indeed recognize the standard matrix form of this list of lists.

Matrix operations

Remember, in the the text, we introduced two ways of multiplying column matrices with row matrices. So, according to our definitions, the expression

          (({{c}, {d}}))
(({{a, b}})) 

should evaluate to a scalar product, as a row matrix (bra vector) is positioned to the left of the column matrix (ket vector).
The Mathematica command for this (scala) product is

{a,b}.{c,d}

Note that, internally, Mathematica did indeed treat {a,b} as a row matrix, and {c,d} as a column matrix. What if we position the row matrix to the right of the column matrix?, i.e.

      (({{a, b}}))
(({{c}, {d}}))

We learned that this product should be represented, since it corresponds, to an outer product of a ket vector with a bra vector, as the square  matrix

(({{c a, c b}, {d a, d b}}))

In Mathematica we use the

?KroneckerProduct

command to facilitate the outer product of a bra (row matrix)  with a ket  (column matrix). Thus

kronprod=KroneckerProduct[{c,d},{a,b}]

MatrixForm[kronprod]

Notice that  KroneckerProduct[{c,d},{a,b}] ≠ KroneckerProduct[{a,b},{c,d}]

With these definitions we can now perform all the matrix operations introduced in Chapter 2 discussions.
Below are  few examples.

Example 1:  Multiplication of a square matrix (operator) on a column (ket vector) should produce another ket vector (column matrix)
e.g. what is the following product

(({{a, b, c, d}, {e, f, g, h}, {i, j, k, l}, {m, n, o, p}}))(({{α}, {β}, {γ}, {δ}})) = ?

Answer

matrixoperator={{a,b,c,d},{e,f,g,h},{i,j,k,l},{m,n,o,p}}
MatrixForm[matrixoperator]

ket={α,β,γ,δ}
MatrixForm[ket]

productket=matrixoperator.ket
MatrixForm[productket]

Likewise, the operation

(({{α, β, γ, δ}}))(({{a, b, c, d}, {e, f, g, h}, {i, j, k, l}, {m, n, o, p}}))

is given by

bra={α,β,γ,δ}

bra.matrixoperator

produces the correct bra (row) vector.

Finally we want to perform operations such as

(({{a, b, c}, {d, e, f}, {g, h, i}}))(({{α, β, γ}, {δ, ϵ, ζ}, {η, θ, κ}}))

Which should produce another 3×3 square matrix.

matrix1={{a,b,c},{d,e,f},{g,h,i}}
MatrixForm[matrix1]

matrix2={{α,β,γ},{δ,ϵ,ζ},{η,θ,κ}}
MatrixForm[matrix1]

matrix1.matrix2
MatrixForm[%]

Problem: Evaluate

(({{α, β, γ}, {δ, ϵ, ζ}, {η, θ, κ}}))(({{a, b, c}, {d, e, f}, {g, h, i}}))