#
# the Riemman Zeta function
#
#  Zeta(s) = sum( 1/i^s, i=1..infinity )
#
#				Gaston H. Gonnet (Oct 1992)
#	approximations recomputed	GhG (Aug 1998)
#
Zeta := proc( s:numeric )

if s > 16 then
     if s < 25 then r := 1/10^s+1/9^s+1/8^s+1/7^s+1/6^s else r := 0 fi;
     r := r + 1/5^s+1/4^s+1/3^s+1/2^s;
     r+1

elif s < 0 then
     if mod(s,2)=0 then 0
     else (2*Pi)^s/Pi * sin(Pi/2*s) * Gamma(1-s) * Zeta(1-s) fi

elif s <= 6 then
    if s = 1 then error( 'singularity encountered' ) fi;

    # Digits := 80:  kernelopts(gcfreq=10^7);
    # with(orthopoly):  plotsetup(x11);
    # lo := 0:  hi := 6:
    # macro( appr = 591*(s-1)/1024+1 );
    # f := proc(s) if s-1=0 then 0 else (s-1)*Zeta(s) - appr fi end:
    # t := numapprox[chebpade]( f, lo .. hi, [8,8] );
    # t1 := convert( t(s), horner ):  t2 := evalf(t1,20);
    # plot( (s-1)*Zeta(s)-(t2+appr), s=lo..hi );
    # lprint( t2/(s-1) + 591/1024 + 1/(s-1) );

    (.29738625672221953482e-1+(-.53820840055862190921e-1+
    (.18900410623180462942e-1+(.47076837296310007331e-2+
    (.44295808721805815325e-3+(.28639552319525311894e-4+
    (.24865492159077319919e-5+(.34053755484253062464e-7+
    .17883197890889474790e-8*s)*s)*s)*s)*s)*s)*s)*s)/
    (.38547281883994008847+(.92870030209699878385e-1+
    (.14533756710038344674e-1+(.13762346353673650159e-2+
    (.10125660912729750673e-3+(.46806172485489769401e-5+
    (.17589619240148613027e-6+(.19709846294311260592e-8+
    .27004098178827918006e-10*s)*s)*s)*s)*s)*s)*s)*s)/(s-1)+591/1024+1/(s-1)

else
    # lo := 6:  hi := 16.01:  sh := 11:
    # t := numapprox[chebpade]( s->Zeta(s+sh)-1, lo-sh .. hi-sh, [8,8] );
    # t1 := convert( t(s), horner ):  t2 := evalf(t1,20);
    # plot( Zeta(s+sh)-t2-1, s=lo-sh..hi-sh );
    # printf( `    t := s-%d;`, sh );  lprint( subs(s=t,t2) + 1 );

    t := s-11;
    (.28068724800604047723e-3+(-.99302779058743803149e-4+
    (.16413123315343904925e-4+(-.16627325347571578932e-5+
    (.11348743625564689072e-6+(-.53743399173211710602e-8+
    (.17354913034277732394e-9+(-.35188528263333789906e-11+
    .34562419095847465603e-13*t)*t)*t)*t)*t)*t)*t)*t)/
    (.56797596234773844435+(.19559647656083421383+
    (.30742135361219556941e-1+(.29448023648094087378e-2+
    (.18795527078153307662e-3+(.82009163273306485235e-5+
    (.23723895069361350004e-6+(.41117586051472906134e-8+
    .29954815600767754053e-10*t)*t)*t)*t)*t)*t)*t)*t) + 1

    fi
end:
