       efficient programming problem

• To: mathgroup at smc.vnet.net
• Subject: [mg84143] efficient programming problem
• From: "Michael Weyrauch" <michael.weyrauch at gmx.de>
• Date: Tue, 11 Dec 2007 06:12:35 -0500 (EST)

```Hello,

I am generating a sum of a product of "pairs"  using the following rules
(partly stolen from an earlier post of Carl Woll in this group.)

wick[a_, b_] := pair[a, b];

wick[a_, b__] := Sum[Expand[pair[a, {b}[[i]]]*Delete[Unevaluated[wick[b]], i]], {i, Length[{b}]}];

pair[c[_], c[_]] := 0

pair[d[_], d[_]] := 0

So, when I evaluate

wick[c, c, d, d]

I get

pair[c, d]*pair[c, d] + pair[c, d]*pair[c, d]

which is the desired sum of product of pairs.

Now, I would like to implement an additional rule which holds for my pairs, namely that it is allowed to interchange the parameters
(1,2) or (3,4), so that the above sum of pairs simplifies e.g. to

2*pair[c, d]*pair[c, d]

A more complicated example would be to evaluate

wick[c, c, d, d, c, c, d, d]

which produces a sum of 24 products of pairs. Now if I again implement the additional rule that one is allowed to interchange (1,2)
or (3,4) or (5,6)   ( and so on) one obtains only a sum of 3 products of pairs which reads

4*pair[c, d]*pair[c, d]*pair[c, d]*pair[c, d] +

16*pair[c, d]*pair[c, d]*pair[c, d]*pair[d, c] +

4*pair[c, d]*pair[c, d]*pair[d, c]*pair[d, c]

I am looking for a method which implements this (1,2) (3,4) (5,6)...  interchange symmetry in a memory and time efficient way, so
that Mathematica directly produces the correctly  "reduced" sum of products of pairs as exemplified above for simple cases.

I have now tried two implementations, but both use too much memory and time (this is relevant of course only for much longer
examples which contain say 4 times as many c[] and d[] in wick[] than the examples given), since my methods essentially first
generate the some of all products of pairs generated by the rules given in the beginning of this post and then analyze the sum of
terms and reduce them according to the additional interchange symmetry.

It would be better if this reduction of terms could be done during the recursive generation of the sum of products of pairs. Ideas
in this direction would be welcome...

Thanks,   Michael

```

• Prev by Date: Re: Monitor bug or feature
• Next by Date: Re: From 3D to 2D
• Previous by thread: Re: From 3D to 2D
• Next by thread: Re: efficient programming problem