I have looked at a lot of these cases, e.g. Can one identify the design patterns of Mathematica? and the included ones.

My trimmed example, here establishing the ‘initial conditions’ (where the zp___List symbol has 3 underscores) and utilizes only 2 external global functions, `B`

and `K`

;

`wgn[0,0,zp___List]:=0; wgn[0,1,zp___List]:=0; wgn[0,2,zp___List]:=B; wgn[g_Integer/;g<0,npo_Integer,zp___List]:=0; wgn[g_Integer,npo_Integer/;npo<0,zp___List]:=0; `

and then the recursion (I changed a double sum to a `Sum @@ Flatten[Table[`

);

`wgn[g_Integer /; g >= 0, npo_Integer?Positive, zp___List] := wgn[g, npo, zp] = ( Sum[ ( Module[{z, tmp1, tmp1b, tmp2, asso, T1}, tmp1 = Rest[Drop[zp, -Length[zp]/2]]; tmp1b = Rest[Drop[zp, Length[zp]/2]]; tmp2 = Subsets[tmp1, {0, npo - 1}]; asso = AssociationThread[tmp1, tmp1b]; T1 = Table[{tmp2[[o]], Complement[tmp1, tmp2[[o]]]}, {o, 1, Length[tmp2]}]; ( wgn[g - 1, npo + 1, Flatten[List[Join[ {z, -z}, Rest[Drop[zp, -Length[zp]/2]], {j, j}, Rest[Drop[zp, Length[zp]/2]]] ]]] + Total[Flatten[Table[ wgn[h, 1 + Length[T1[[wc]][[1]]], Flatten[ List[Join[{z}, T1[[wc]][[1]], {j}, asso /@ T1[[wc]][[1]]]]]] * wgn[g - h, 1 + Length[T1[[wc]][[2]]], Flatten[ List[Join[{-z}, T1[[wc]][[2]], {j}, asso /@ T1[[wc]][[2]]]]]] , {h, 0, g}, {wc, 1, Length[T1]}]]] ) , {z, 0}] ] ) , {j, 1, 1}] ); `

`tmp1 & tmp1b`

split the 3rd argument into variables and numbers and there is an association – `asso`

– between them. So the 2nd variable and 2nd number are correlated. `tmp2`

calculates all the Subsets of $ $ z_1,\ldots,z_n$ $ and then `T1`

constructs pairs where one element of `tmp2`

at a time is paired with its set-complement, i.e. to make $ $ A \cup B = \{1,\ldots,n\}$ $ , and then summed over in the double sum.

I call it like,

`wgn[2,1,{z01,1}] `

and for this case expect

`wgn[1,2,{z,-z} + w[0,1,{z,j}]*w[2,1,{-z,j}] + w[1,1,{z,j}]*w[1,1,{-z,j}] + w[2,1,{z,j}]*w[0,1,{-z,j}] `

where `j`

would be 1 by the double sum… I mean the `Sum @@ Flatten[Table[...`

. Then the 2 ‘initial conditions’ would fill in the rest, giving (after killing the `w[0,1,{...}]`

terms,

`wgn[1,2,{z,-z} + w[1,1,{z,j}]*w[1,1,{-z,j}] `

Then the recursion would start again, and the `w[1,1,{z01,1}]`

terms would be replaced by,

`~ Res[K*w[0,2,{z,-z,j,j}],{z$ 2,0}] `

and the `wgn[1,2,{z,-z}]`

term replaced by some other terms.

Problem now is that I have the **recursion limit problem** but can’t figure out why, especially since my initial conditions should take care of any runaway negative valued terms.

(One thing, the 2nd variable, `npo`

is half the length of the list `zp`

.)

Here is the formula if it is at all needed,

$ $ w_{g,n+1}^{i_0,i_1,\ldots,i_n}(z_0,z_1,\ldots,z_n) \sim \sum_{j=1}^N Res_{z->0} K * \left( w_{g-1,n+2}^{j,j,i_1,\ldots,i_n}(z,-z,z_1,\ldots,z_n) + \sum_{A\cup B=\{1,\ldots,n\}} \sum_{h=0}^g w_{h,1+|A|}^{j,\vec{i_A}}(z,\vec{z_A}) * w_{g-h,1+|B|}^{j,\vec{i_B}}(-z,\vec{z_B}) \right)$ $

I define `npo := n+1`

. The function `Res`

is just residue but returning zero isn’t too helpful š