function y=sgpolylog(dig,n,a)
%SGPOLYLOG Generalized polylogarithm. 
%   S=SGPOLYLOG(DIG,N,A) computes in DIG-digit arithmetic
%   the generalized polylogarithm function S_{N,2)(A),
%   0 < A <= 1. 
%Reference: Eq.(2.9) in K.S. Koelbig, Nielsen's generalized 
%polylogarithms, SIAM J. Math. Anal. 17 (1986), 1232-1258.

digits(dig); a=vpa(a); s1=vpa(1); y=vpa(0);
eps0=.5*10^(-dig);
err=s1; nu=0; h=s1;
while double(err)>eps0
  y0=y;
  nu=nu+1;
  t=h*a^(nu+1)/(vpa(nu+1)^(n+1));
  y=y0+t;
  err=abs(t/y);
  h=h+s1/vpa(nu+1);
end
%nu
