1
$\begingroup$

I have a memoizing, recursive function whose MWE looks like this (the two fake inputs/ICs are from 'K' and 'Bfun2', the latter just a quick way to check the results coming out of the Residue.:

K[z0_, z1_] := K

Bfun2[z0_, z1_, z2_, z3_] := 
  Normal[Series[1/Exp[z0*z1*z2*z3], {z0, 1, 9}]]/(z0*z1*z2*z3)^5 // 
  ExpandAll

ClearAll[wgn2g];

wgn2g[g_Integer, n_Integer, zp___List] :=
 wgn2g[g, n, zp] =
  Sum[
   Module[{z, tmp1, tmp1b, tmp2, asso, T1},
    Assuming[
     Flatten[Join[{z}, Drop[zp, -Length[zp]/2]]] \[Element] 
      Complexes,
     Which[
      g < 0, 0,
      n < 0, 0,
      2*g - 2 + n == -4, 0,
      2*g - 2 + n == -3, 0,
      2*g - 2 + n == -2, 0,
      2*g - 2 + n == -1, 0,
      2*g - 2 + n == 0, 
        Bfun2[zp[[1]], zp[[2]], zp[[3]], zp[[4]], ch],
      2*g - 2 + n >= 1,
      (
       tmp1 = Rest[Drop[zp, -Length[zp]/2]];
       tmp1b = Rest[Drop[zp, Length[zp]/2]];
       tmp2 = If[n >= 2, Complement[Subsets[tmp1, n - 2], {{}}], {}];
       asso = AssociationThread[tmp1, tmp1b];
       T1 = 
        Table[{tmp2[[o]], Complement[tmp1, tmp2[[o]]]}, {o, 1, 
          Length[tmp2]}];
       Residue[
        K[z, First[zp], j, First[Drop[zp, Length[zp]/2]], ch]
         *
         (
          wgn2g[g - 1, n + 1,
            Flatten[List[
              Join[
               {z, -z},
               Rest[Drop[zp, -Length[zp]/2]],
               {j, j},
               Rest[Drop[zp, Length[zp]/2]]
               ]
              ]]
            ]
           +
           (
            If[
             Length[T1] > 0,
             (
              Sum[
               Sum[
                (
                  wgn2g[h, 1 + Length[T1[[wc]][[1]]],
                   Flatten[List[
                    Join[
                    {z},
                    T1[[wc]][[1]],
                    {j},
                    asso /@ T1[[wc]][[1]]
                    ]
                    ]]
                   ]
                  )  
                 *
                 (
                  wgn2g[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], 1}]
              ),
             0,
             Print["shouldn't be here"]
             ]
            )   
          )
        , {z, 0}]
       )
      ](*close which*)
     ]
    ]
   , {j, 1, Nbps, 1}]

Because every time it "recursed" it need to re-create a bunch of things, I utilized 'local variables' from the Module[] tool.

Before wrapping the argument of Module[] with Assuming[], I was getting conditional expressions. But now I still get them - the Assuming[] function should pass assumptions to every new local variable, right?

For instance, with the real input functions (that are too long to post), I get this output;

-((I (-13624934400 + 1703116800 z0^4 - 149022720 z0^8 + 
        12235520 z0^12 - 1029160 z0^16 + 
        90041 z0^20) (185638837404303360000 - 
        23204854675537920000 z1^4 + 2030424784109568000 z1^8 - 
        166708157349888000 z1^12 + 14022237487104000 z1^16 - 
        1226802718310400 z1^20 - 23204854675537920000 z2^4 + 
        2900606834442240000 z1^4 z2^4 - 
        253803098013696000 z1^8 z2^4 + 20838519668736000 z1^12 z2^4 - 
        1752779685888000 z1^16 z2^4 + 153350339788800 z1^20 z2^4 + 
        2030424784109568000 z2^8 - 253803098013696000 z1^4 z2^8 + 
        22207771076198400 z1^8 z2^8 - 1823370471014400 z1^12 z2^8 + 
        153368222515200 z1^16 z2^8 - 13418154731520 z1^20 z2^8 - 
        166708157349888000 z2^12 + 20838519668736000 z1^4 z2^12 - 
        1823370471014400 z1^8 z2^12 + 149707949670400 z1^12 z2^12 - 
        12592307763200 z1^16 z2^12 + 1101698456320 z1^20 z2^12 + 
        14022237487104000 z2^16 - 1752779685888000 z1^4 z2^16 + 
        153368222515200 z1^8 z2^16 - 12592307763200 z1^12 z2^16 + 
        1059170305600 z1^16 z2^16 - 92666595560 z1^20 z2^16 - 
        1226802718310400 z2^20 + 153350339788800 z1^4 z2^20 - 
        13418154731520 z1^8 z2^20 + 1101698456320 z1^12 z2^20 - 
        92666595560 z1^16 z2^20 + 
        8107381681 z1^20 z2^20))/(1264658490862949778849792000000 \
Sqrt[2] z0^2 z1^2 z2^2)) + 
 Residue[ConditionalExpression[0, 
   Im[z$39445] == 0 && 
Re[z$39445] > 
     0 && (Im[z0] != 
       0 || (Re[z0] < 0 && Re[z0] + Re[z$39445] < 0) || (Re[z0] > 0 &&
     Re[z0] > Re[z$39445]))], {z$39445, 0}]

which tells me I get an additional '0' if certain conditions apply ;)

(The call is wgn2g[g,n,{z0,z1,...,zn,i0,i1,...,in}], not that I think it is needed...)

However, I do get other ones that are not so simple and I wonder how I can pass additional assumptions on to the local variables to avoid this.

I know how to use Assuming[] and Simplify[%,Assumptions->blah blah], but is there a way to make an assumption on the current z wrt the previous z? I've noticed that I've had to do things like this - the big problem being that the z$#### local variables change name and are unpredictable to do ahead of time;

Simplify[Out[104], 
 Assumptions -> 
  Re[z$1757641/z$1961753] > 1 && Re[z$1756741/z$1961753] > 1 && 
   Re[z$1756741/z$1771944] > 1 && Re[z$1756741/z$1810064] > 1 && 
   Re[z$1756741/z$1847663] > 1 && Re[z$1756741/z$1885817] > 1 && 
   Re[z$1756741/z$1923887] > 1 && Re[z$1756741/z$1771944] > 1 && 
   Re[z$1756741/z$1847663] > 1 ]

For clarity, these z's are simply local coordinates on a Riemann surface, so I don't want to necessarily constrain them to be purely real, imaginary, whatever - like Im[z$39445] == 0 above - but they could be of course...

$\endgroup$
  • 1
    $\begingroup$ Assumptions (whether specified in $Assumptions or Assuming) have no effect except within functions that take the option Assumptions (e.g., Simplify, FullSimplify, Integrate, Refine, FunctionExpand, Limit). $\endgroup$ – Bob Hanlon Nov 15 '18 at 6:25
  • $\begingroup$ I cannot see how to reproduce the behavior. $\endgroup$ – Daniel Lichtblau Nov 15 '18 at 16:57
  • $\begingroup$ well it does make sense one cannot reproduce the behavior, at afaik because I only have a model of the core recursion, without the real input functions... I think I have a way to build assumptions of prior z's with current ones. utilizing a global variable and assuming on that... $\endgroup$ – nate Nov 17 '18 at 5:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.