lineintegralC1(f,df,R,N):= /* 線分 [0,R] に沿う線積分 */
  block (s:0, z1:0, dz:R/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))$
lineintegralC2(f,df,R,N,pi):= /* 4半円周 Re^{it}, 0<t<pi/2 に沿う線積分 */       block(s:0, t:0, dt:pi/2/N, z1:float(R*cos(t)+R*%i*sin(t)),
    for j: 1 thru N
      do (w:rectform(df(z1)/f(z1)),t:t+dt,
        z2:float(R*cos(t)+R*%i*sin(t)),s:rectform(s+w*(z2-z1)),z1:z2),
  return(s))$
lineintegralC3(f,df,R,N):= /* 線分 [0,Ri] に沿う逆向き線積分 */
  block (s:0, z1:%i*R, dz:-z1/N,
    for j: 1 thru N
      do (w:rectform(df(z1)/f(z1)),z2:z1+dz,
        s:rectform(s+w*(z2-z1)), z1:z2), 
  return(s))$
lineintegralS1(f,df,R,N,pi):=
  block(s1:lineintegralC1(f,df,R,N),
        s2:lineintegralC2(f,df,R,N,pi),
        s3:lineintegralC3(f,df,R,N),
        print(s1),print(s2),print(s3),
        s:rectform((s1+s2+s3)/2/pi/%i),
        return(s))$
f(z):=z^3-z+5$
df(z):=''(diff(f(z),z))$
R:2.0$
N:1000$
pi:3.1416$
lineintegralS1(f,df,R,N,pi);
