Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: efficient programming problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84155] Re: efficient programming problem
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Wed, 12 Dec 2007 01:15:01 -0500 (EST)
  • References: <3584443.1197383067825.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

Here's a simpler version of the second rule for "prod":

prod[pair[z1_[w_], z2_[x_]], pair[z3_[y_], z2_[z_]]] /; z == x + 1 :=
prod[pair[z1[w], z2[z]], pair[z3[y], z2[x]]]

Bobby

................

Maybe you should use your own "product" function; you can always change it
to Times when everything else is done. (And you don't need Unevaluated.)
Your application may need more rules or a more general version of the
second rule I added for "prod", but maybe this will get you down the road
a bit:

Clear[wick, pair, prod]
prod[___, 0, ___] = 0;
prod[pair[z1_[w_], z2_[x_]], pair[z3_[y_], z4_[z_]]] /;
    z == x + 1 && z2 == z4 :=
   prod[pair[z1[w], z2[z]], pair[z3[y], z4[x]]]
wick[a_, b_] := pair[a, b];
wick[a_, b__] :=
    Sum[prod[pair[a, {b}[[i]]], wick @@ Delete[{b}, i]], {i,
      Length@{b}}];
pair[c[_], c[_]] := 0
pair[d[_], d[_]] := 0
wick[c[1], c[2], d[3], d[4]] /. prod -> Times

2 pair[c[1], d[4]] pair[c[2], d[3]]

Bobby

On Tue, 11 Dec 2007 05:12:35 -0600, Michael Weyrauch
<michael.weyrauch at gmx.de> wrote:

> 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[1], c[2], d[3], d[4]]
>
> I get
>
> pair[c[1], d[4]]*pair[c[2], d[3]] + pair[c[1], d[3]]*pair[c[2], d[4]]
>
> 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[1], d[4]]*pair[c[2], d[3]]
>
> A more complicated example would be to evaluate
>
> wick[c[1], c[2], d[3], d[4], c[5], c[6], d[7], d[8]]
>
> 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[1], d[3]]*pair[c[2], d[4]]*pair[c[5], d[7]]*pair[c[6], d[8]] +
>
> 16*pair[c[1], d[7]]*pair[c[2], d[3]]*pair[c[5], d[8]]*pair[d[4], c[6]] +
>
> 4*pair[c[1], d[7]]*pair[c[2], d[8]]*pair[d[3], c[5]]*pair[d[4], c[6]]
>
> 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
>
>
>



-- 

DrMajorBob at bigfoot.com


  • Prev by Date: Re: Vertical tick labels in BarChart
  • Next by Date: Re: Re: Prefix Forms on the BasicMath Palette
  • Previous by thread: Re: efficient programming problem
  • Next by thread: Re: Export figures with tooltips