lineintegralR(f,df,x1,y1,x2,y2,N):= /* 長方形(x1,y1)-(x2,y2)の周に沿う線積分 */
  block (s:0, z1:x1+%i*y1, dz:(x2-x1)/N,
    for j: 1 thru N
      do (w:rectform(df(z1)/f(z1)),z2:z1+dz,
        s:rectform(s+w*dz), z1:z2), 
    dz:(y2-y1)*%i/N,
    for j: 1 thru N
      do (w:rectform(df(z1)/f(z1)),z2:z1+dz,
        s:rectform(s+w*dz), z1:z2), 
    dz:(x1-x2)/N,
    for j: 1 thru N
      do (w:rectform(df(z1)/f(z1)),z2:z1+dz,
        s:rectform(s+w*dz), z1:z2),
    dz:(y1-y2)*%i/N,
    for j: 1 thru N
      do (w:rectform(df(z1)/f(z1)),z2:z1+dz,
        s:rectform(s+w*dz), z1:z2),
     return(s));
f(z):=z^5-z+2;
df(z):=''(diff(f(z),z));
N:100$
s:lineintegralR(f,df,-2.0,0.1,0.0,2.0,N);
pi:3.1416$
print(rectform(s/2/pi/%i));
sb:lineintegralR(f,df,-2.0,-0.1,0.0,2.0,N);
print(rectform(sb/2/pi/%i));
