Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Physics LibreTexts

6.4: D- Numerical Tensor Products

( \newcommand{\kernel}{\mathrm{null}\,}\)

This appendix discusses how tensor products are handled in numerical linear algebra software. We will focus on Python with the Numeric Python (numpy) module. The discussion is also applicable, with minor modifications, to GNU Octave or Matlab. We assume the reader is familiar with the basics of Python/Numpy, e.g. how vectors can be represented by 1D arrays, linear operators (matrices) can be represented by 2D arrays, etc.

Tensor products are implemented by the numpy.kron function, which performs an operation called a Kronecker product. The function takes two inputs, which can be 1D arrays, 2D arrays, or even higher-dimensional arrays (which we won’t discuss). It returns a new array representing the tensor product of the inputs, whose dimensionality depends on that of the inputs. The function can be used to compute products of vectors (|a|b), products of operators (ˆOAˆOB), etc. It can even compute “mixed” products like |aˆOB, which is useful for calculating partial projections and partial traces.

In the next few sections, we will prove that the various tensor products of bras, kets, and operators can be represented using the following Numpy expressions involving numpy.kron:

Definition: Numpy Expressions

 

|a|bkron(a, b)a|b|kron(a.conj(), b.conj())ˆAˆBkron(A, B)|aˆBkron(a, B.T).Ta|ˆBkron(a.conj(), B)ˆA|bkron(A.T, b).TˆAb|kron(A, b.conj())

 

D.1 Products of Vectors

Suppose a and b are both 1D arrays, of length M and N respectively; let their components be (a0,a1,,aM1) and (b0,b1,,bN1). Following Numpy conventions, we do not explicitly distinguish between “row vectors” and “column vectors”, and component indices start from 0. The Kronecker product between a and b generates the following 1D array:

kron(a,b)=(a0b0,,a0bN1,a1b0,,a1bN1,,aM1bN1).

We can think of this as taking each component of a, and multiplying it by the entire b array:

kron(a,b)=(a0b,a1b,,aM1b).

As we shall see, this description of the Kronecker product extends to higher-dimensional arrays as well. In the present case, a and b are both 1D, and the result is a 1D array of MN components, which can be described compactly in index notation by

[kron(a,b)]μ=ambnwhereμ=mN+n.

The index μ is defined so that as we sweep through m=0,,M1 and n=0,,N1, μ runs through the values 0,1,,MN1 without duplication. Note, by the way, that the order of inputs into kron is important: kron(a,b) is not the same as kron(b,a)! The asymmetry between a and b is apparent in the definitions (???) and (???).

In terms of abstract linear algebra (as used in quantum theory), let HA be an M-dimensional space with basis {|m}, and HB be an N-dimensional space with basis {|n}. Any two vectors |aHA and |bHB can be written as

|a=M1m=0am|m,|b=N1n=0bn|n.

A natural basis for the product space HAHB is

{|μ|m|n}where{μ=mN+nm=0,1,,M1n=0,1,,N1.

Using Equation (???), we can show that

|a|b=mnambn|m|n=MN1μ=0[kron(a,b)]μ|μ.

Therefore, we need only remember that the tensor product of two kets is represented by

|a|bkron(a,b).

Likewise, for bras,

a|b|kron(a,b).

 

D.2 Products of Matrices

Let A and B be 2D arrays of size M×M and N×N respectively:

A=[A00A0,M1AM1,0AM1,M1],B=[B00B0,N1BN1,0BN1,N1].

Then the Kronecker product of A and B is an MN×MN array of the form

kron(A,B)=[A00BA0,M1BAM1,0BAM1,M1B].

As before, this can be interpreted as taking each component of A, and multiplying it by B. The result can be written using index notation as

[kron(A,B)]μμ=AmmBnnwhereμ=mN+n,μ=mN+n.

 

In the language of abstract linear algebra, let HA and HB again be spaces with bases {|m} and {|n}. Consider two linear operators ˆA and ˆB acting respectively on these spaces:

ˆA=M1m,m=0|mAmmm|,ˆB=N1n,n=0|nBnnn|.

Then we can show using Equation (???) that

ˆAˆB=mmnn|m|nAmmBnnm|n|=μ,μ|μ[kron(A,B)]μμμ|,

where {|μ} is the basis for HAHB previously defined in Equation (???). Thus,

ˆAˆBkron(A,B).

This result, like Equation (???), is nice because it means that we can relegate the handling of tensor product components entirely to the kron function. So long as we make a particular basis choice for the spaces HA and HB, and keep to that choice, kron will return the vector products and operator products expressed using an appropriate and natural basis for HAHB [i.e., the basis defined in Equation (???)].

D.3 Mixed Products

For “mixed” products of operators with bras or kets, the representation using kron is more complicated, but only slightly. First, consider the 1D array a and 2D array B:

a=(a0,,aM1),B=[B00B0,N1BN1,0BN1,N1].

Then the Kronecker product between the two is

kron(a,B)=(a0B,a1B,,aM1B).

Note that a is explicitly treated as a row vector. In component terms,

kron(a,B)]nμ=amBnn,whereμ=mN+n.

In linear algebraic terms, let

|a=mam|m,ˆB=nn|nBnnn|.

Then

|aˆB=μn|μamBnnn|,μ=mN+n.

This does not quite match Equation (???)! The basic problem is that the Kronecker product treats a a row vector. However, we can patch things up by massaging Equation (???) a bit:

[kron(a,BT)T]μn=[kron(a,BT)]nμ=am(BT)nnwhereμ=mN+n=amBnn.

This is an appropriate match for Equation (6.4.22), so we conclude that

|aˆBkron(a,BT)T.

To take the product using the bra a|, we replace Equation (6.4.22) by

a|ˆB=nμ|namBnnμ|,μ=mN+n.

Comparing this to Equation (???) yields

a|ˆBkron(a,B).

 

Likewise, consider the 2D array A and 1D array b:

A=[A00A0,M1AM1,0AM1,M1],b=(b0,,bN1).

Then the Kronecker product is

kron(A,b)=[A00bA0,M1bAM1,0bAM1,M1b].

Similar to before, b is treated as a row vector. In component terms,

[kron(A,B)]mμ=Ammbn,whereμ=mN+n.

Using the same procedure as before, we can straightforwardly show that

ˆA|b=μm|μ[kron(AT,b)T]μmm|kron(AT,b)TˆAb|=mμ|m[kron(A,b)]mμμ|kron(A,b).

 


This page titled 6.4: D- Numerical Tensor Products is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by Y. D. Chong via source content that was edited to the style and standards of the LibreTexts platform.

Support Center

How can we help?