The Mathematica Journal
Feature Articles
New Products
New Publications
News Bulletins
Write Us
About the Journal
Staff and Contributors
Back Issues
Download this Issue

Object-Oriented Quantum Mechanics

Frank J. Kampas

One of the fundamental principles of object-oriented programming is that the internal structures of objects are private (hidden). The response of the objects to "messages" passed to them is independent of their internal structures. This is similar to the fact that measurements upon quantum mechanical states give definite results independent of the various ways in which the states may be represented (e.g., wave functions, vectors in a Hilbert space). This similarity is illustrated here by constructing objects which represent both the states of a quantum mechanical harmonic oscillator and the operators associated with measurements on those states.

Object-oriented programming can be implemented in Mathematica using Roman Maeder's package Classes.m (available from, which is described in [1, p. 60] and [2, p. 293]. First we load the package.


Now we can construct the simple harmonic oscillator class, sho. The class members are states of definite energy, described by two instance variables: a complex amplitude a and a nonnegative integer quantum number n.

· new is the constructor.
· amp and num return the amplitude and quantum number of the object.
· mult multiplies the amplitude of the state by a constant.
· raise and lower increase and decrease the quantum number, respectively.
· The energy function corresponds to measuring the energy of the state and returns the state multiplied by its energy. [Graphics:../Images/index_gr_23.gif] is Planck's constant divided by [Graphics:../Images/index_gr_24.gif], and [Graphics:../Images/index_gr_25.gif] is the radial frequency of the corresponding classical harmonic oscillator.
· inprd returns the inner product of two states. The inner product of states [Graphics:../Images/index_gr_26.gif] and [Graphics:../Images/index_gr_27.gif] is designated by [Graphics:../Images/index_gr_28.gif] in Dirac bracket notation [3, p. 19].

Note that the raising and lowering operators do not correspond to physical variables, but will be useful for defining other functions. Also note that the states are not normalized unless the magnitude of a is 1.


We use a simple trick for computing the complex conjugate of complex expressions involving real variables using a replacement rule.


The Dirac bracket notation can be implemented using the Notation package.


It is also useful to have a notation for mult.


The following steps illustrate the construction of a state s with an amplitude of 1 and a quantum number of 2, and the determination of the expectation value of its energy, which is [Graphics:../Images/index_gr_37.gif] in Dirac notation.


The next step is the construction of a class whose members are linear combinations of states with definite energy. Members of class lincom are sequences of objects of type sho.

· new is the constructor.
· states returns a list of the sho components making up a variable of type lincom.
· mult and inprd are similar to the functions in class sho and are based upon them.
· The functions x and p are the position and momentum operators, respectively.

Using the two classes, it is possible to calculate the matrix elements of the x and p operators, which are defined as [Graphics:../Images/index_gr_42.gif] and [Graphics:../Images/index_gr_43.gif], where [Graphics:../Images/index_gr_44.gif] and [Graphics:../Images/index_gr_45.gif] are states with amplitude 1 and quantum numbers [Graphics:../Images/index_gr_46.gif] and [Graphics:../Images/index_gr_47.gif], respectively.

Single energy state members of the class lincom are constructed first.


The following are scaled matrix representations of x and p (see [4, p. 103]).


It is also possible to construct time-dependent states s(i, t) after constructing a function [Graphics:../Images/index_gr_53.gif] which gives the energy of a state with quantum number i.


Constructing an equal mixture of the two states s(0, t) and s(1, t),


we compute the expectation value of the position operator, [Graphics:../Images/index_gr_57.gif].


We see that [Graphics:../Images/index_gr_60.gif] oscillates back and forth at frequency [Graphics:../Images/index_gr_61.gif].

Converted by Mathematica      

[Article Index] [Prev Page][Next Page]