# Computing with the residue in Sagemath

I have done the following computation to calculate $W12(z1,z2)$ I am expecting the result

\begin{aligned} W_{1,2}(z_1 , z_2) &= Res_{z =0}\, K(z)\frac{1}{z-z_1} \left( W_{0,3}(z,-z,z_2) + W_{0,2}(z,z_2)W_{1,1}(-z)+ W_{0,2}(-z,z_2)W_{1,1}(z)\right) \\ &= 1/8\, {\frac { \left( 2\,a{{\it z1}}^{2}+5\,{a}^{2} \right) {{\it z2}}^ {4}+ \left( 2\,a{{\it z1}}^{4}+3\,{a}^{2}{{\it z1}}^{2} \right) {{\it z2}}^{2}+5\,{a}^{2}{{\it z1}}^{4}}{{{\it z1}}^{6}{{\it z2}}^{6}}} \end{aligned} I got the correct result for W11, W03 with the code. For computing W12 I have to use the subsitution function, but at the end I not getting the correct result. I got the result I have computed in Maple. So please let me know what mistake I am making in the following code.

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

assume(b > 0);

y = lambda z: 2*arcsinh( z / (sqrt(2)*b) ) / sqrt(z^2 + 2*b^2)

K = lambda z: 1 / (z*(y(z) - y(-z)))

W02 = lambda z1, z2: 1/(z1 - z2)^2

W11 = lambda z1: ( K(z) / (z - z1) * (W02(z1,z2).substitute(z1==z, z2==-z))*derivative(-z,z) ).residue(z == 0).canonicalize_radical()

W03 = lambda z1, z2, z3 : ( K(z) / (z - z1) *( W02(z, z2)*W02(-z,z3)+W02(z, z3)*W02(-z,z2))*derivative(-z,z)

W12 = lambda z1, z2: ( K(z) / (z - z1) *(W03(z1,z2,z2).substitute(z1==z , z2==-z, z3 ==z2)
+W02(z1, z2).substitute(z1==z)*W11(z1).substitute(z1==-z)
+W02(z1, z2).substitute(z1==-z)*W11(z1).substitute(z1==z))

edit retag close merge delete

Would you mind defining $W_{i, j}(z_1, z_2)$ ?

( 2022-05-31 17:02:17 +0100 )edit

It's a recursive definition $W_{g,n}(z_1 , \ldots ,z_n) = Res_{z=0} \left ( W_{g-1 , n+1}(z,-z,z2,\ldots z_n) +\sum_{g_1 + g_2 = g , n_1 + n_2 = n-1 }W_{g1 , n1}()W_{g_2, n_2}() \right)$$. I writing the recursive code in general. So it might be more with that progarmme, but I am stuck here. ( 2022-06-01 06:00:14 +0100 )edit Your definition isn't complete : • It doesn't give the initial definitions for starting values of$g$and$n$. • it doesn't specify the use of the arguments$z_1,\dots z_p$. • The term$W_{g-1 , n+1}(z,-z,z2,\ldots z_n)$isn't specially clear, introducing a new argument$z$and missing (?)$z_1$. • By$\sum_{g_1 + g_2 = g , n_1 + n_2 = n-1 }W_{g1 , n1}()W_{g_2, n_2}() $, do you mean •$ \sum_{g_1 + g_2 = g} \sum_{n_1 + n_2 = n-1 } W_{g1 , n1} (z_1,\dots z_p)W_{g_2, n_2}(z_1,\dots z_p) $• or something else ? • In the latter, what about$z$? This might be due to LaTeX mistyping or cunt n' paste mishaps. Could you clarify by writing complete definitions, avoiding any abbreviation ? I'm not especially good at divination... ( 2022-06-01 07:08:37 +0100 )edit In my thesis https://bridges.monash.edu/articles/t... Page 30 eq 3.6 have the expression So in this case$x(z) = z^2y(z)$as I have defined in the code.$k(z)$I have defined in the code Page 31 I gave a picture to make the understanding clear. So the initial data given is$w_{0,1}$and$w_{0,2}$and the rest we compute by the recursion. I am writing a code for this recursion. I have computed it in the maple files, I don't know how to share it here. ( 2022-06-01 14:09:37 +0100 )edit ## 1 Answer Sort by » oldest newest most voted 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)  more ## Comments Thanks a lot, will follow your suggestion. I am wondering why my code didn't give the same answer. I will try to do it for general$Wgn\$ for g\geq 0 and n>0.

( 2022-06-04 04:32:46 +0100 )edit