Input Parsing of Complicated Expressions

• To: mathgroup at smc.vnet.net
• Subject: [mg3497] Input Parsing of Complicated Expressions
• From: "T. Daniel Crawford" <crawdad at zopyros.ccqc.uga.edu>
• Date: Mon, 18 Mar 1996 00:57:24 -0500
• Organization: Center for Computational Quantum Chemistry
• Sender: owner-wri-mathgroup at wolfram.com

```To the Mathematica Gurus:

I am attempting to write a Mathematica program that will solve
what are known in Molecular Quantum Mechanics as Second-Quantization
Equations.  In particular I am trying to construct perturbation theory
and coupled-cluster theory equations via the Generalized Wick's
Theorem.  These equations involve strings of non-commuting operators
which must be permuted in various ways to eliminate redundancies
in the strings.

My approach (while probably not the best) is to take an expression
from the user involving these strings collected as arguments of a
function I've called norm[].  I look through the expression finding
these arguments and work through the necessary manipulations required
by Wick's theorem.

For example, I may pass the function (called wick[]) the expression:

wick[ (t1[i,a] norm[i,a]) ** ((1/4) w[p,q,r,s] norm[p,q,s,r])];

where t1[] and w[] are dummy functions and the symbols I need
are found as arguments of the two norm[] functions.

My problem is this: in order for my method of "input parsing" to
work, the Head[] of the user-supplied expression must be
NonCommutativeMultiply, as above.  However, I would like to be able
to deal with long expressions, perhaps sums of the strings, with
constant prefactors multiplied in, etc.  Now, I know that if I have a
sum of these operator products (e.g. A ** B + C ** D), then I could
use the Distribute[] function to apply my function to each addend.
But this is not as flexible as I need it to be.  For example, if
I wanted to deal with the expression A ** B - C ** D, the Head[] of the
second term is Times, not NonCommutativeMultiply.  To write a long
input parsing program for this sort of thing doesn't seem to me to be
within the "spirit" of Mathematica.

If anyone out there can understand my ramblings here, I would very much
appreciate any advice you have to offer!

Thanks,
-Daniel
--
T. Daniel Crawford			Center for Computational Quantum