# 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