The package Spinors.m

Bernd Thaller
Institute of Mathematics
University of Graz
Austria
2006-08-08

Abstract

The package VQM`Spinors defines basic operations in the two-dimensional complex Hilbert space of a qubit. It defines the Pauli matrices and provides tools to visualize pure and mixed states of a qubit. This package is part of the VQM packages which can be obtained here:  http://www.uni-graz.at/imawww/vqm/software.html (free download). The VQM packages are part of the Visual Quantum Mechanics project, see http://www.uni-graz.at/imawww/vqm/. In particular, these packages are distributed with the book Advanced Visual Quantum Mechanics, Springer-Verlag New York, 2004.

Load package

<<VQM`Spinors`

This also loads the package "VQM`VisualizeVector", which in turn loads the standard packages "Geometry`Rotations`" and "Calculus`VectorAnalysis`".

Bases

A spinor is a complex two-dimensional vector {(Subscript[c, 1]), (Subscript[c, 2])}, (Subscript[c, i]) ϵ ℂ, that is, an element of the linear space (ℂ^2). The spinors are usually defined with respect to a reference basis in (ℂ^2). The package defines the canonical standard basis

$QSpinBasis

The basis spinors are interpreted as "spin-up" and "spin-down" with respect to the z-axis of a Cartesian basis in (ℝ^3).

Other standard bases provided by the package are QxBasis, QyBasis, and QzBasis (QzBasis is equal to $QSpinBasis). For example, QxBasis consists of up and down spinors with respect to the x-axis:

QxBasis

Note that the symbols defined by the VQM packages all start with the letter Q in order to prevent conflicts with existing symbols defined in Mathematica or in other third-party packages.

The package also defines QSpinBasis as a default basis for some basis-dependent commands. It is initially equal to $QSpinBasis, but can be changed with the command QSetSpinBasis[{basespinor1,basespinor2}]. This influences how the components of spinors are calculated.

QSetSpinBasis[QxBasis];
QSpinBasis

An example of an operation that depends on the chosen basis is the calculation of the components of a spinor with respect to that basis. This is done with the command QSpinorToComponents. The spinor psi is given with respect to the reference basis $QSpinBasis. QSpinorToComponents[psi] calculates the components of psi with respect to the basis QSpinBasis. This gives the components of the spinor {1,0} with respect to the previously set QSpinBasis:

components = QSpinorToComponents[{1,0}]

components.QSpinBasis returns the original spinor. More generally, QComponentsToSpinor takes two complex coefficients and forms the corresponding linear combination of the basis vectors in QSpinBasis. The result is the spinor in the canonical standard basis.

QComponentsToSpinor[components]

QProjectUp[psi] projects a spinor psi into the direction of the first basis vector of QSpinBasis,

QProjectUp[{1, 0}]

QProjectDown[psi] gives the part proportional to the second basis vector. The sum of the two projections is the identity, that is,

sp  =  {1, I};
QProjectUp[sp] + QProjectDown[sp]  ==  sp

QProbabilityUp[psi] gives the probability that the spinor has spin-up with respect to the QSpinBasis, QProbabilityDown[psi] gives the probability for spin down.

A natural method for the visualization of a spinor is to represent its components with respect to a basis by a bar diagram. The height of the bars gives the absolute value, and the color gives the phase of the component.

QSpinorBarDiagram[{1,0}]

Note that the image above shows the components {(Subscript[c, 1]), (Subscript[c, 2])} of the spinor with respect to the chosen QSpinBasis (= QxBasis). Let us restore the default setting. The following image then gives the components of the same spinor with respect to the canonical standard basis $QSpinBasis = QzBasis.

QSetSpinBasis[$QSpinBasis];
QSpinorBarDiagram[{1,0}]

All the commands above accept the option QUseBasis. You can use this option when you want use a particular basis just for one command. The following command gives the spin-up part with respect to the QyBasis of the spinor {1,-1}.

QProjectUp[{1,-1},QUseBasis->QyBasis]

QSpinorToComponents[{1,-1}, QUseBasis->QxBasis]

QSpinorBarDiagram[{1,-1}, QUseBasis->QyBasis]

You can compute the norm of a spinor with

Norm[{2,-I}]

and QNormalize returns a spinor with norm 1

QNormalize[{2,-I}]

Norm[%]

The function QNormalize can also be used to normalize arbitrary vectors

QNormalize[{1,2,3}]

Some matrices

The package "VQM`Spinors" also defines the some important operators. First of all, we have the Pauli spin matrices QPauliSigma1, QPauliSigma2, and QPauliSigma3. Moreover, QPauliSigmaV is a vector with the three Pauli matrices as components

QPauliSigma2//MatrixForm

QPauliSigmaV

The two-by-two identity matrix is QIdentity2. The Pauli sigma matrices are the quantum-mechanical observables for the spin measured with respect to the x-, y-, and z-axis of the reference coordinate system in (ℝ^3). The spin-observable with respect to an arbitrary axis (represented by a vector kv) is QSpinHamiltonian[kv]. This matrix is obtained as
 QPauliSigma1.kv[[1]]+QPauliSigma2.kv[[2]]+QPauliSigma3.kv[[3]]

This is a three-dimensional vector with symbolic components

Clear[k0, k1, k2, k3, kv];
kv = {k1,k2,k3};

hs=QSpinHamiltonian[kv]

A density matrix is a hermitian matrix with trace 1. It is also determined by a vector in (ℝ^3):

This is the density matrix describing spin in the direction of kv

ma = QVectorToDensityMatrix[kv]

ma // MatrixForm

A four-vector {k0,k1,k2,k3} can be converted into a Hermitian matrix by:

QVectorToHermitianMatrix[{k0,k1,k2,k3}]

and a three-vector {k1,k2,k3} by

QVectorToHermitianMatrix[{k1,k2,k3}]

which is the same as QSpinHamiltonian[{k1,k2,k3}]

There is also an inverse operation which determines the vector from a Hermitian matrix:

QHermitianMatrixToVector is inverse to QVectorToHermitianMatrix:

QDensityMatrixToVector is inverse to QVectorToDensityMatrix:

QHermitianMatrixToVector[QVectorToHermitianMatrix[{k0,k1,k2,k3}]] // Simplify

QDensityMatrixToVector[QVectorToDensityMatrix[{k1,k2,k3}]] // Simplify

ma == QVectorToDensityMatrix[QDensityMatrixToVector[ma]] //Simplify

The spinors QSpinorUp and QSpinorDown

The package defines two basis spinors for each direction in (ℝ^3). These spinors are QSpinorUp[vector] and QSpinorDown[vector]. Here 'vector ' defines the direction. These spinors are eigenvectors of the matrix QVectorToMatrix[vector].

Clear[k1, k2, k3, kv]; kv = {k1,k2,k3};

QVectorToDensityMatrix[kv].QSpinorUp[kv] == Sqrt[kv.kv] QSpinorUp[kv]//Simplify

QVectorToHermitianMatrix[kv].QSpinorDown[kv] == -Sqrt[kv.kv] QSpinorDown[kv]//Simplify

Hence, for example, QSpinorUp[vector] is the state with spin-up in the direction of 'vector'. The two spinors form an orthonormal basis in (ℂ^2). For example,

QConjSpinorUp[kv].QSpinorUp[kv]//Simplify

QConjSpinorDown[kv].QSpinorUp[kv]//Simplify

The conjugate comples spinors QConjSpinorUp[kv] and QConjSpinorDown[kv] have been defined for convenience.

We also note that QSpinorUp[kv] has a phase discontinuity on the negative z-axis, and QSpinorDown[kv] has a phase discontinuity on the positive z-axis.

QSpinorUp[{0,0,-1}]

Limit[QSpinorUp[{eps,0,-1}],eps->0]

Limit[QSpinorUp[{-eps,0,-1}],eps->0]

Limit[QSpinorUp[{0,eps,-1}],eps->0]

Spinors and Vectors

Consider the unit vector in three-dimensional space

vec = {-4/9,8/9,-1/9}

It defines a direction in space. The state which is "spin-up" with respect to this direction is

sp = QSpinorUp[vec]

We can convert this spinor back to the vector

QSpinorToVector[sp]

The norm (length) of the three-dimensional real vector QSpinorToVector[spinor] is equal to  Norm[spinor]^2, that is

Norm[QSpinorToVector[{3,2}]] == Norm[{3,2}]^2

The command QSpinorToVector accepts the option QVectorLength

QSpinorToVector[psi, QVectorLength->n] with
n=1			generates a unit vector
n=2			generates a vector with norm Norm[psi]^2 (default)
n=3			generates a vector with norm Norm[psi]

There is also an inverse command QVectorToSpinor that accepts the same option.

QVectorToSpinor[vec, QVectorLength->n] with the option
n=1			generates a unit spinor
n=2			generates a vector with norm Norm[vec]^1/2 (default)
n=3			generates a vector with norm Norm[vec]

We have QVectorToSpinor[vec, QVectorLength->1] == QSpinorUp[vec].

QExtractPhase

Note that the relation between spinors and vectors is not one-to-one. Here is another normalized spinor that gives the same vector than the spinor sp above:

sp2 =  {2/3,2 I/3-1/3}

QSpinorToVector[sp2]

Generally, two spinors differing by a phase, sp1=Exp[I phi] sp2, lead to the same vector.

QExtractPhase[psi] returns a real number for any nonzero psi={z1,z2}. This number is a phase determined from comparison with QSpinorUp, where QSpinorUp is taken with respect to the spin-up direction defined by psi. Let us illustrate this with an example:

psi = QNormalize[{-2 I,1}]

This spinor has the spin-up direction (unit vector)

dir = QSpinorToVector[psi]

Note, however, that QSpinorUp[dir] is different from psi

QSpinorUp[dir]

but the difference is only a phase factor. The phase can be obtained with QExtractPhase:

ph = QExtractPhase[psi]

psi can now be recovered by multiplying QSpinorUp[dir] with the appropriate phase factor

Exp[I ph] QSpinorUp[dir]

Any spinor psi is thus uniquely determined by a three-dimensional vector together with phase factor.

Rotations

QRotationSO3[vector] and QRotationSU2[vector] define rotations around the axis given by vector through an angle given by Norm[vector]. The matrix QRotationSO3[vector] is an orthogonal 3x3-matrix. QRotationSU2[vector] is a unitary 2x2 matrix realizing the 'spinor representation' of the rotation group.

For example,

QRotationSU2[{2 Pi,0,0}]//MatrixForm

QRotationSU2[{1,1,1}]//MatrixForm

The textbook-form of the SU(2)-rotation matrix can be obtained as follows. Let us first define a unit vector with symbolic components.

Clear[nv,n1,n2,n3];
nv = {n1,n2,n3}; (* should be a unit vector *)

QRotationSU2[phi nv] // Simplify[#,{phi>0,nv.nv==1}]&

This matrix is the same as the following:

MatrixExp[-I phi/2 QVectorToHermitianMatrix[nv]] // ExpToTrig // Simplify[#,{phi>0,nv.nv==1}]&

Any unitary 2x2-matrix may be considered a SU(2) rotation. The following example shows the connection with a basis transformation

Clear[a,b];
T=QRotationSU2[{1,1,1}];
newBasis={T.QzBasis[[1]], T.QzBasis[[2]]};
QSpinorToComponents[{a,b},QUseBasis->newBasis] == Inverse[T].{a,b} // Simplify

The connection between rotations in SO(3) and rotations in SU(2) is the following:

rotV = {1, 0.5, -1};
R = QRotationSO3[rotV];
T = QRotationSU2[rotV];

QVectorToSpinor[ R . {1,0,0} ] == T . QVectorToSpinor[{1,0,0}]

QVectorToHermitianMatrix[ R . {1,0,0} ] == Chop[T . QVectorToHermitianMatrix[{1,0,0}] . Inverse[T]]

Visualization

Since spinors and Hermitian matrices can be converted into vectors, we can visualize them

Show[Graphics3D[QSpinorToArrow[{1,1}]],PlotRange->All]

The package VQM`VisualizeVector (which is loaded automatically by VQM`Spinors) provides all necessary commands for visualizing vectors. These commands are also used by VQM`Spinors for the visualization of spinors and Hermitian matrices..

The  commands QVectorToArrow and QSpinorToArrow return a 3D-graphics primitive describing an arrow whose properties are determined by the following options

Options[QVectorToArrow]

QArrowHead->True (default) causes the vector to be drawn with an arrow head. QArrowHead->Automatic draws the vector with a point of size 2*QLinePointSize instead of the QArrowHead. Otherwise the vector is just represented by a line segment.

QMinLength->0.1 (default) specifies that vectors of length less than 0.1 are to be drawn as points of size QLinePointSize.

QArrowShape->{n,k}: The head of the arrow is a cone with half height h = k * Norm[vector] and radius r = h/(2 GoldenRatio) drawn using n polygons. If k is negative, then h = -k. Default is (1,1/6)

QArrowScale-> k scales the length of the arrow by the factor k.

QHeadColor->colordirective: The arrow appears in the color specified by colordirective. Turn Lighting off to see the effect.

QLinePointSize->pt  causes the shaft of the arrow to be drawn with relative pointsize pt. Default is  pt = 0.001.

QSpinorToArrow draws the arrow head by default in a color determined by the complex phase of the spinor. The options QHeadColor->QExtractPhase is also accepted. The complex phase factor Exp[I phase] is mapped to colors according to Hue[phase/(2 Pi)] (this is the standard color map of complex numbers).

Here are some examples:

Show[Graphics3D[
	QVectorToArrow[{1,1,-1},
		QArrowShape->{12,1/3}, QLinePointSize->0.02]
], PlotRange->All]

Show[Graphics3D[
	QVectorToArrow[{1,1,-1},
		QArrowShape->{12,1/3}, QLinePointSize->0.02,
		QHeadColor->RGBColor[0,0.,1.]]
], PlotRange->All, Lighting->False]

Show[Graphics3D[ QSpinorToArrow[Exp[I Pi/4]{1,1}] ], Lighting->False, PlotRange->All]

Finally, there are the commands QVisualizeVector, QVisualizeSpinor, and QVisualizeOperator. They convert their argument into an arrow which is then shown together with auxiliary graphics elements. The appearance of those auxiliary graphics elements is controlled by the following options

Options[QVisualizeVector]

Options[QVisualizeSpinor]

This shows a spinor as a vector on the surface of the Bloch-sphere. The size and shape of the arrow is controlled by Options[QArrowToVector] as described above.

QVisualizeSpinor[QNormalize[(-1+I) {1 , 1+I}]]

QVisualizeSpinor[QNormalize[(-1+I) {1 , 1+I}], QNeedleStyle->False]

Additional graphics elements may sometimes be helpful

QVisualizeVector[{1,1,1}/Sqrt[3], QCoordinateCube->True, QCoordinateCircles->False, QDrawUnitSphere->10, QDrawAxes->{True,False,True}]

A Density matrix can also be visualized as a vector.

dm  =  
      QVectorToDensityMatrix[{1. , - .5, 2} // QNormalize]

QVisualizeDensityMatrix[dm, QArrowShape->{6,1/3}, QLinePointSize->.01]

Options for QVisualizeVector, etc.

QDrawUnitSphere->n 		draws the outline of the unit sphere by plotting n (default: 20) circles.
QDrawAxes->True 			or, for example, QDrawAxes->{True, False, True} adds gray coordinate axes.
QCoordinateCube->->True 		adds a green cube indicating the components of the vector (default: False).
QCoordinateCircles->True 		adds blue coordinate lines indicating the polar coordinates of the vector.
QHeadColor->QExtractPhase	works only with QVisualizeSpinor, see QSpinorToArrow
QHeadColor->color			draws the vector with the given color