Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

It is very, very hard to digest the question, the objects of the question, and the complications involved in implementing them in the code. Please try to use clean code. If you have only some very special $W$-functions, introduced without recursion, it would be a good idea to give at least parallel to the recursion also the explicit formulas for them, as they are implemented. There is no start for the recursion, so the reader of the code has no bridge from $K$ to the $W$-functions. There is no $b$ in the expected formula, but an $a$, and in the code we get that b with a needles assumed condition on it.

If this question is a follow-up-question, please mention the initial question. Potential answerers may combine the information and ask for more pointed details. I answered something related last days, but had to start over again. I vaguely remember the relation $a=b^2$.

This being said, here is the way i was rewriting the code

var('b,z1,z2,z3');

def y(z):
    return 2*arcsinh( z / (sqrt(2)*b) ) / sqrt(z^2 + 2*b^2)

def K(z):
    return 1 / z / (y(z) - y(-z))

def W02(z1, z2):
    return 1 / (z1 - z2)^2

def W03(z1, z2, z3):
    var('w03')    # use w03 only locally inside this function
    E = ( K(w03) / (w03 - z1) \
          * ( W02(w03, z2) * W02(-w03, z3) +
              W02(w03, z3) * W02(-w03, z2) )
         )
    return E.residue(w03 == 0).canonicalize_radical()

def W11(z1):
    var('w11')    # use w11 only locally inside this function
    E = K(w11) / (w11 - z1) * W02(w11, -w11)
    return E.residue(w11 == 0).canonicalize_radical()

def W12(z1, z2):
    var('w12')    # use w only locally inside this function
    E = ( K(w12) / (w12 - z1) \
          * ( W03(w12, -w12, z2)
              + W02( w12, z2) * W11(-w12)
              + W02(-w12, z2) * W11( w12) )
         )
    return E.residue(w12 == 0).canonicalize_radical()

It gives:

sage: W12(z1, z2)
1/8*(5*b^4*z1^4 + (5*b^4 + 2*b^2*z1^2)*z2^4 + (3*b^4*z1^2 + 2*b^2*z1^4)*z2^2)/(z1^6*z2^6)