Code coverage tests

This page documents the degree to which the PARI/GP source code is tested by our public test suite, distributed with the source distribution in directory src/test/. This is measured by the gcov utility; we then process gcov output using the lcov frond-end.

We test a few variants depending on Configure flags on the pari.math.u-bordeaux.fr machine (x86_64 architecture), and agregate them in the final report:

The target is to exceed 90% coverage for all mathematical modules (given that branches depending on DEBUGLEVEL or DEBUGMEM are not covered). This script is run to produce the results below.

LCOV - code coverage report
Current view: top level - basemath - lfunlarge.c (source / functions) Hit Total Coverage
Test: PARI/GP v2.18.0 lcov report (development 29732-95c6201d93) Lines: 476 514 92.6 %
Date: 2024-11-21 09:08:54 Functions: 73 75 97.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (C) 2000  The PARI group.
       2             : 
       3             : This file is part of the PARI/GP package.
       4             : 
       5             : PARI/GP is free software; you can redistribute it and/or modify it under the
       6             : terms of the GNU General Public License as published by the Free Software
       7             : Foundation. It is distributed in the hope that it will be useful, but WITHOUT
       8             : ANY WARRANTY WHATSOEVER.
       9             : 
      10             : Check the License for details. You should have received a copy of it, along
      11             : with the package; see the file 'COPYING'. If not, write to the Free Software
      12             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
      13             : 
      14             : #include "pari.h"
      15             : #include "paripriv.h"
      16             : 
      17             : /*****************************************************************/
      18             : /*             Program to compute L(chi,s)                       */
      19             : /*      for Im(s) large, chi primitive Dirichlet character       */
      20             : /*      In the present branch, only Tyagi's method is used      */
      21             : /*****************************************************************/
      22             : /* In addition, C can also be a polynomial defining an abelian
      23             :  * extension of Q. */
      24             : 
      25             : /*****************************************************************/
      26             : /*                      Character programs                       */
      27             : /*****************************************************************/
      28             : /* A character, always assumed primitive can be given in the following formats:
      29             :  * - omitted or 0: special to zetaRS,
      30             :  * - a t_INT: assumed to be a discriminant,
      31             :  * - a t_INTMOD: a conrey character,
      32             :  * - a pair [G,chi] or [bnr,chi],
      33             :  * - [C1,C2,...]~ where the Ci are characters as above with same moduli. */
      34             : 
      35             : /* Given a list of linit/ldata for chars of same conductor F, return
      36             :  * [Vecan, F, Parities, Gaussums] */
      37             : static GEN
      38        1127 : mycharinit(GEN C, long bit)
      39             : {
      40             :   GEN L, LVC, LE, LGA;
      41        1127 :   long F = 0, i, j, lc = lg(C), prec;
      42             : 
      43        1127 :   bit += 64; prec = nbits2prec(bit);
      44        1127 :   L = cgetg(lc, t_VEC);
      45        1127 :   LE = cgetg(lc, t_VECSMALL);
      46        1127 :   LGA = cgetg(lc, t_VEC);
      47        2289 :   for (i = 1; i < lc; i++)
      48             :   {
      49        1162 :     GEN gv, ga, gm, ro, ldata = gel(C, i);
      50             :     long e;
      51        1162 :     if (is_linit(ldata)) ldata = linit_get_ldata(ldata);
      52        1162 :     gv = ldata_get_gammavec(ldata); e = itou(gel(gv, 1));
      53        1162 :     gm = ldata_get_conductor(ldata);
      54        1162 :     ro = ldata_get_rootno(ldata);
      55        1162 :     if (isintzero(ro)) ro = lfunrootno(ldata, bit);
      56        1162 :     ga = gmul(ro, gsqrt(gm, prec)); if (e) ga = mulcxI(ga);
      57        1162 :     gel(LGA, i) = ga;
      58        1162 :     LE[i] = e;
      59        1162 :     if (i == 1) F = itos(gm); /* constant */
      60        1162 :     gel(L, i) = lfunan(ldata, F, prec);
      61             :   }
      62        1127 :   if (lc == 2 && is_vec_t(typ(gmael(L,1,1))))
      63             :   { /* multichar */
      64           7 :     LGA = gel(LGA,1); lc = lg(LGA);
      65           7 :     LVC = gel(L,1);
      66           7 :     LE = const_vecsmall(lc-1, LE[1]); /* FIXME: can handle mixed values */
      67             :   }
      68             :   else
      69             :   {
      70        1120 :     LVC = cgetg(F + 1, t_VEC);
      71        4627 :     for (j = 1; j <= F; j++)
      72             :     {
      73        3507 :       GEN v = cgetg(lc, t_VEC);
      74        7301 :       for (i = 1; i < lc; i++) gel(v, i) = gmael(L, i, j);
      75        3507 :       gel(LVC, j) = v;
      76             :     }
      77             :   }
      78        1127 :   return mkvec5(LVC, stoi(F), LE, LGA, grootsof1(2*F, prec));
      79             : }
      80             : 
      81             : /* n >= 1 and #VC = F, the conductor of the character or multicharacter X.
      82             :  * VC contains [X(1),X(2),...X(F)] */
      83             : static GEN
      84      636923 : mycall(GEN VC, long n)
      85             : {
      86      636923 :   long F = lg(VC) - 1;
      87      636923 :   GEN z = n <= F ? gel(VC, n) : gel(VC, ((n - 1) % F) + 1);
      88      636923 :   return gequal0(z)? NULL: z;
      89             : }
      90             : 
      91      205578 : static GEN get_chivec(GEN VCALL) { return gel(VCALL, 1); }
      92      805484 : static long get_modulus(GEN VCALL) { return itos(gel(VCALL, 2)); }
      93      204171 : static GEN get_signat(GEN VCALL) { return gel(VCALL, 3); }
      94          21 : static GEN get_gauss(GEN VCALL) { return gel(VCALL, 4); }
      95      202841 : static GEN get_chiZ(GEN VCALL) { return gel(VCALL, 5); }
      96             : 
      97             : /* (-1)^A[i] * conj(B[i]) */
      98             : static GEN
      99           7 : gnegconj(GEN A, GEN B)
     100             : {
     101           7 :   long i, l = lg(A);
     102           7 :   GEN W = cgetg(l, t_VEC);
     103          14 :   for (i = 1; i < l; i++)
     104           7 :   { GEN b = gconj(gel(B,i)); gel(W,i) = A[i]? gneg(b): b; }
     105           7 :   return W;
     106             : }
     107             : /* g(conj(CHI)) */
     108             : static GEN
     109           7 : gaussconj(GEN VCALL)
     110           7 : { return gnegconj(get_signat(VCALL), get_gauss(VCALL)); }
     111             : 
     112             : static GEN
     113           7 : myinitconj(GEN VCALL)
     114             : {
     115           7 :   GEN CONJ = shallowcopy(VCALL);
     116           7 :   gel(CONJ, 1) = gconj(get_chivec(VCALL));
     117           7 :   gel(CONJ, 4) = gaussconj(VCALL); return CONJ;
     118             : }
     119             : 
     120             : /********************************************************************/
     121             : /*                          Driver Program                          */
     122             : /********************************************************************/
     123             : 
     124             : /* assume |Im(s)| >> 1, in particular s is not a negative integer */
     125             : static GEN
     126          14 : applyfuneq(GEN gau, GEN s, GEN z, long odd, long q, long bitprec)
     127             : {
     128             :   GEN t, S;
     129             :   long prec;
     130          14 :   if (!gequal0(s)) bitprec += maxss(gexpo(s), 0);
     131          14 :   prec = nbits2prec(bitprec);
     132          14 :   if (odd) gau = mulcxmI(gau);
     133          14 :   S = gmul(Pi2n(-1, prec), gsubgs(s, odd));
     134          14 :   t = ginv(gmul2n(gmul(gcos(S, prec), ggamma(s, prec)), 1));
     135          14 :   t = gmul(gpow(gdivgs(Pi2n(1, prec), q), s, prec), t);
     136          14 :   return gmul(gmul(gau, t), z);
     137             : }
     138             : 
     139             : static GEN RZchi(GEN VCALL, GEN s, long prec);
     140             : 
     141             : /* VCALL already initialized */
     142             : static GEN
     143        1127 : lfunlarge_char(GEN VCALL, GEN s, long bitprec)
     144             : {
     145        1127 :   pari_sp av = avma;
     146             :   GEN sig, tau, z;
     147        1127 :   long funeq = 0, ts = typ(s), stau, flconj, q;
     148        1127 :   if (!is_real_t(ts) && ts != t_COMPLEX) pari_err_TYPE("lfunlarge_char", s);
     149        1127 :   sig = real_i(s); tau = imag_i(s);
     150        1127 :   if (gexpo(tau) < 1) pari_err_DOMAIN("lfun","im(s)", "<", gen_2, tau);
     151        1127 :   stau = gsigne(tau);
     152        1127 :   if (stau < 0) { tau = gneg(tau); VCALL = myinitconj(VCALL); }
     153        1127 :   if (gcmp(sig, ghalf) < 0) { funeq = 1; sig = gsubsg(1, sig); }
     154        1127 :   flconj = ((stau > 0 && funeq) || (stau < 0 && !funeq));
     155        1127 :   q = get_modulus(VCALL); bitprec += gexpo(stoi(q));
     156        1127 :   z = RZchi(VCALL, mkcomplex(sig, tau), nbits2prec(bitprec));
     157        1127 :   if (flconj) z = gconj(z);
     158        1127 :   if (funeq)
     159             :   {
     160          14 :     GEN odd = get_signat(VCALL), gau = get_gauss(VCALL), Vz;
     161          14 :     long lC = lg(gau), j;
     162          14 :     Vz = cgetg(lC, t_VEC);
     163          28 :     for (j = 1; j < lC; j++)
     164          14 :       gel(Vz,j) = applyfuneq(gel(gau,j), s, gel(z,j), odd[j], q, bitprec);
     165          14 :     z = Vz;
     166             :   }
     167        1127 :   return gerepilecopy(av, z);
     168             : }
     169             : 
     170             : static GEN
     171          14 : lfungetchars(GEN pol)
     172             : {
     173          14 :   GEN L, F, v, bnf = Buchall(pol_x(1), 0, LOWDEFAULTPREC);
     174             :   GEN w, condall, bnr;
     175             :   long i, l, lc;
     176          14 :   condall = rnfconductor(bnf, pol); bnr = gel(condall, 2);
     177          14 :   L = bnrchar(bnr, gel(condall, 3), NULL); lc = lg(L);
     178          14 :   F = cgetg(lc, t_VEC);
     179          77 :   for (i = 1; i < lc; i++)
     180             :   {
     181          63 :     GEN chi = gel(L, i), cond = bnrconductor_raw(bnr, chi);
     182          63 :     gel(F, i) = gcoeff(gel(cond,1), 1, 1);
     183             :   }
     184          14 :   w = vec_equiv(F); l = lg(w); v = cgetg(l, t_COL);
     185          42 :   for (i = 1; i < l; i++)
     186             :   {
     187          28 :     GEN wi = gel(w, i), vi;
     188          28 :     long j, li = lg(wi);
     189          28 :     gel(v,i) = vi = cgetg(li, t_VEC);
     190          28 :     if (li == 2 && equali1(gel(F, wi[1]))) /* common conductor is 1 */
     191          14 :       gel(vi,1) = lfunmisc_to_ldata_shallow(gen_1);
     192             :     else
     193             :     {
     194          63 :       for (j = 1; j < li; j++)
     195          49 :         gel(vi,j) = lfunmisc_to_ldata_shallow(mkvec2(bnr, gel(L, wi[j])));
     196             :     }
     197             :   }
     198          14 :   return v;
     199             : }
     200             : 
     201             : /********************************************************************/
     202             : /*            NEW RS IMPLEMENTATION FROM SANDEEP TYAGI              */
     203             : /********************************************************************/
     204             : /* See arXiv:2203.02509v2 */
     205             : 
     206        5775 : static long m_n0(GEN sel) { return itos(gel(sel, 1)); }
     207      599514 : static GEN m_r0(GEN sel) { return gel(sel, 2); }
     208        1127 : static GEN m_al(GEN sel) { return gel(sel, 3); }
     209      599514 : static GEN m_aleps(GEN sel) { return gel(sel, 4); }
     210        4606 : static GEN m_h(GEN sel) { return gel(sel, 5); }
     211        1176 : static GEN m_lin(GEN sel) { return gel(sel, 6); }
     212        1176 : static long m_np(GEN sel) { return itou(gel(sel, 7)); }
     213             : 
     214             : static GEN
     215        3444 : phi_hat(GEN x, long prec)
     216             : {
     217             :   GEN y;
     218        3444 :   if (gsigne(imag_i(x)) > 0)
     219        1141 :     y = gneg(gexpm1(gneg(gmul(PiI2(prec), x)), prec));
     220             :   else
     221        2303 :     y = gexpm1(gmul(PiI2(prec), x), prec);
     222        3444 :   return ginv(y);
     223             : }
     224             : 
     225             : static GEN
     226        3388 : phi_hat_h0(GEN sel, long k, long prec)
     227             : {
     228        3388 :   GEN t = gdiv(gsubsg(m_n0(sel) + k, m_r0(sel)), m_aleps(sel));
     229        3388 :   return phi_hat(gdiv(gasinh(t, prec), m_h(sel)), prec);
     230             : }
     231             : 
     232             : /* v[i] = A[i] * (a + (-1)^E[i] b) */
     233             : static GEN
     234      630952 : mul_addsub(GEN A, GEN a, GEN b, GEN E)
     235             : {
     236      630952 :   long i, l = lg(E);
     237      630952 :   GEN v = cgetg(l, t_VEC);
     238     1345352 :   for (i = 1; i < l; i++)
     239      714400 :     gel(v,i) = gmul(gel(A,i), E[i]? gsub(a, b): gadd(a, b));
     240      630952 :   return v;
     241             : }
     242             : 
     243             : static GEN
     244      202841 : wd(GEN VCALL, GEN pmd, GEN x, long prec)
     245             : {
     246      202841 :   GEN VC = get_chivec(VCALL), E = get_signat(VCALL), Z = get_chiZ(VCALL);
     247      202841 :   GEN ex, emx, xpmd = gmul(x, pmd), y = NULL;
     248      202841 :   long md = get_modulus(VCALL), N = 2*md, k;
     249      202841 :   ex = gexp(mulcxI(xpmd), prec); emx = ginv(ex);
     250      833793 :   for (k = 1; k <= (md-1) / 2; k++)
     251             :   {
     252      630952 :     GEN xc = mycall(VC, k);
     253      630952 :     if (xc)
     254             :     {
     255      630952 :       GEN p3, p2, p1 = gmul(xc, gel(Z, Fl_neg(Fl_sqr(k,N), N) + 1));
     256      630952 :       GEN a = gmul(ex, gel(Z, N - k + 1)), b = gmul(emx, gel(Z, k + 1));
     257      630952 :       GEN c = gmul(ex, gel(Z, k + 1)), d = gmul(emx, gel(Z, N - k + 1));
     258      630952 :       if (odd(md))
     259             :       {
     260      594831 :         p2 = ginv(mulcxmI(gmul2n(gsub(a,b), -1))); /* 1 / sin(xpmd - kpmd) */
     261      594831 :         p3 = ginv(mulcxmI(gmul2n(gsub(c,d), -1))); /* 1 / sin(xpmd + kpmd) */
     262             :       }
     263             :       else
     264             :       {
     265       36121 :         p2 = mulcxI(gdiv(gadd(a,b), gsub(a,b))); /* cotan(xpmd - kpmd) */
     266       36121 :         p3 = mulcxI(gdiv(gadd(c,d), gsub(c,d))); /* cotan(xpmd + kpmd) */
     267             :       }
     268      630952 :       p1 = mul_addsub(p1, p2, p3, E);
     269      630952 :       y = y ? gadd(y, p1) : p1;
     270             :     }
     271             :   }
     272      202841 :   return mulcxmI(gdivgs(y, N));
     273             : }
     274             : 
     275             : static GEN
     276        1127 : series_h0(long n0, GEN s, GEN VCALL, long fl, long prec)
     277             : {
     278        1127 :   GEN C = get_modulus(VCALL) == 1? NULL: get_chivec(VCALL);
     279        1127 :   GEN R = pardirpowerssumfun(C, n0, gneg(s), fl, prec);
     280        1127 :   if (C) return R;
     281         700 :   if (fl) return mkvec2(mkvec(gel(R,1)), mkvec(gel(R,2)));
     282         665 :   return mkvec(R);
     283             : }
     284             : 
     285             : static GEN
     286        1176 : series_residues_h0(GEN sel, GEN s, GEN VCALL, long prec)
     287             : {
     288        1176 :   long n0 = m_n0(sel), np = m_np(sel), k;
     289        1176 :   GEN val = gen_0, VC = get_chivec(VCALL);
     290        4676 :   for (k = maxss(1 - np, 1 - n0); k <= 1 + np; k++)
     291             :   {
     292        3500 :     GEN nk = mycall(VC, n0 + k); /* n0 + k > 0 */
     293        3500 :     if (nk) val = gadd(val, gmul(gmul(phi_hat_h0(sel, k, prec), nk),
     294             :                                  gpow(stoi(n0 + k), gneg(s), prec)));
     295             :   }
     296        1176 :   return val;
     297             : }
     298             : 
     299             : static GEN
     300      596126 : integrand_h0(GEN sel, GEN s, GEN VCALL, GEN x, long prec)
     301             : {
     302      596126 :   pari_sp av = avma;
     303      596126 :   long md = get_modulus(VCALL);
     304      596126 :   GEN r0 = m_r0(sel), aleps = m_aleps(sel), zn, p1;
     305      596126 :   GEN pmd = divru(mppi(prec), md), ix = ginv(x);
     306      596126 :   zn = gadd(r0, gdivgs(gmul(aleps, gsub(x, ix)), 2));
     307      596126 :   p1 = gmul(expIxy(pmd, gsqr(zn), prec),
     308             :             gmul(gpow(zn, gneg(s), prec), gmul(aleps, gadd(x, ix))));
     309      596126 :   if (md == 1)
     310      393285 :     p1 = gdiv(mkvec(mulcxI(p1)), gmul2n(gsin(gmul(pmd, zn), prec), 2));
     311             :   else
     312      202841 :     p1 = gdivgs(gmul(p1, wd(VCALL, pmd, zn, prec)), -2);
     313      596126 :   return gerepileupto(av, p1);
     314             : }
     315             : 
     316             : static GEN
     317        1176 : integral_h0(GEN sel, GEN s, GEN VCALL, long prec)
     318             : {
     319        1176 :   GEN lin_grid = m_lin(sel), S = gen_0;
     320        1176 :   pari_sp av = avma;
     321        1176 :   long j, l = lg(lin_grid);
     322      592794 :   for (j = 1; j < l; j++)
     323             :   {
     324      591618 :     S = gadd(S, integrand_h0(sel, s, VCALL, gel(lin_grid, j), prec));
     325      591618 :     if ((j & 0xff) == 0) S = gerepileupto(av, S);
     326             :   }
     327        1176 :   return gerepileupto(av, gmul(m_h(sel), S));
     328             : }
     329             : 
     330             : /* a + log |x|, a t_REAL, low accuracy */
     331             : static GEN
     332        4676 : addrlogabs(GEN a, GEN x)
     333             : {
     334        4676 :   long prec = DEFAULTPREC;
     335        4676 :   if (gequal0(x)) return real_m2n(64, prec); /* -oo */
     336        4550 :   switch(typ(x))
     337             :   {
     338        4550 :     case t_COMPLEX: return gmul2n(glog(cxnorm(x), prec), -1);
     339           0 :     case t_REAL: break;
     340           0 :     default: x = gtofp(x, prec);
     341             :   }
     342           0 :   return addrr(a, logr_abs(x));
     343             : }
     344             : 
     345             : struct fun_q_t { GEN sel, s, VCALL, B; };
     346             : static GEN
     347        4508 : fun_q(void *E, GEN x)
     348             : {
     349        4508 :   struct fun_q_t *S = (struct fun_q_t *)E;
     350        4508 :   GEN z = integrand_h0(S->sel,S->s,S->VCALL, gexp(x,DEFAULTPREC), DEFAULTPREC);
     351        4508 :   if (typ(z) == t_VEC) z = vecsum(z);
     352        4508 :   return addrlogabs(S->B, z);
     353             : }
     354             : static GEN
     355        2338 : brent_q(void *E, GEN (*f)(void*,GEN), GEN q_low, GEN q_hi)
     356             : {
     357        2338 :   if (gsigne(f(E, q_low)) * gsigne(f(E, q_hi)) >= 0) return NULL;
     358           0 :   return zbrent(E, f, q_low, q_hi, LOWDEFAULTPREC);
     359             : }
     360             : static GEN
     361        1169 : findq(void *E, GEN (*f)(void*,GEN), GEN lq, long prec)
     362             : {
     363        1169 :   GEN q_low, q_hi, q_right, q_left, q_est = gasinh(lq, LOWDEFAULTPREC);
     364        1169 :   q_low = gdivgs(gmulsg(4, q_est), 5);
     365        1169 :   q_hi = gdivgs(gmulsg(3, q_est), 2);
     366        1169 :   q_right = brent_q(E, f, q_low, q_hi); if (!q_right) q_right = q_est;
     367        1169 :   q_left = brent_q(E, f, gneg(q_low), gneg(q_hi)); if (!q_left) q_left = q_est;
     368        1169 :   return gprec_w(gmax(q_right, q_left), prec);
     369             : }
     370             : 
     371             : static GEN
     372        1127 : set_q_value(GEN sel, GEN s, GEN VCALL, long prec)
     373             : {
     374             :   struct fun_q_t E;
     375        1127 :   GEN al = m_al(sel), lq;
     376        1127 :   long md = get_modulus(VCALL), LD = DEFAULTPREC;
     377        1127 :   E.sel = sel; E.s = s; E.VCALL = VCALL, E.B = mulur(prec, mplog2(LD));
     378        1127 :   lq = gdiv(gsqrt(gdiv(gmulsg(md, E.B), Pi2n(1, LD)), LD), al);
     379        1127 :   return findq((void*)&E, &fun_q, lq, prec);
     380             : }
     381             : 
     382             : static GEN
     383        1141 : setlin_grid_exp(GEN h, long m, long prec)
     384             : {
     385        1141 :   GEN w, vex = gpowers(gexp(h, prec), (m - 1)/2);
     386             :   long i;
     387        1141 :   w = cgetg(m+1, t_VEC); gel(w, (m + 1)/2) = gen_1;
     388      290838 :   for (i = (m + 3)/2; i <= m; i++)
     389             :   {
     390      289697 :     GEN t1 = gel(vex, i - ((m - 1)/2));
     391      289697 :     gel(w, i) = t1; gel(w, (m + 1) - i) = ginv(t1);
     392             :   }
     393        1141 :   return w;
     394             : }
     395             : 
     396             : static long
     397        1141 : get_m(GEN q, long prec)
     398             : {
     399        1141 :   GEN t = divrr(mulur(4 * prec, mplog2(prec)), sqrr(mppi(prec)));
     400        1141 :   return 2*itos(gfloor(mulrr(q, t))) + 1;
     401             : }
     402             : 
     403             : static GEN
     404        1127 : RZinit(GEN s, GEN VCALL, GEN numpoles, long prec)
     405             : {
     406             :   GEN sel, al, aleps, n0, r0, q, h;
     407        1127 :   long md = get_modulus(VCALL), m;
     408        1127 :   al = gcmpgs(gabs(imag_i(s), prec), 100) < 0 ? ginv(stoi(4)) : gen_1;
     409        1127 :   r0 = gsqrt(gdiv(gmulgs(s, md), PiI2(prec)), prec);
     410        1127 :   n0 = gfloor(gsub(real_i(r0), imag_i(r0)));
     411        1127 :   aleps = gmul(al, gexp(PiI2n(-2, prec), prec));
     412        1127 :   sel = mkvecn(7, n0, r0, al, aleps, NULL, NULL, numpoles);
     413        1127 :   q = set_q_value(sel, s, VCALL, prec);
     414        1127 :   m = get_m(q, prec);
     415        1127 :   gel(sel,5) = h = divru(q, (m - 1) >> 1);
     416        1127 :   gel(sel,6) = setlin_grid_exp(h, m, prec);
     417        1127 :   return sel;
     418             : }
     419             : 
     420             : static GEN
     421         469 : xpquo_one(GEN s, GEN cs, GEN ga, long odd, long md, long prec)
     422             : {
     423         469 :   GEN rho, a = odd? gen_1: gen_0, z = divsr(md, mppi(prec));
     424         469 :   rho = gmul(gdiv(gpow(gen_I(), gdivgs(gneg(a), 2), prec), gsqrt(ga, prec)),
     425             :              gpow(stoi(md), ginv(stoi(4)), prec));
     426         469 :   return gmul(gdiv(gconj(gmul(rho, gpow(z, gdivgs(cs, 2), prec))),
     427             :                    gmul(rho, gpow(z, gdivgs(s, 2), prec))),
     428             :               gexp(gsub(gconj(glngamma(gdivgs(gadd(cs, a), 2), prec)),
     429             :                         glngamma(gdivgs(gadd(s, a), 2), prec)), prec));
     430             : }
     431             : 
     432             : static GEN
     433        1127 : xpquo(GEN s, GEN VCALL, long prec)
     434             : {
     435        1127 :   long md = get_modulus(VCALL), n, lve, i;
     436        1127 :   GEN cd = NULL, z, pz, cs, VC = get_chivec(VCALL), ve, R;
     437        1127 :   if (!gequal0(s)) prec = nbits2prec(prec + maxss(gexpo(s), 0));
     438        1127 :   z = gexp(gdivgs(PiI2(prec), -md), prec);
     439        1127 :   if (md == 1)
     440         700 :     return gmul(gpow(mppi(prec), gsub(s, ghalf), prec),
     441             :                 gexp(gsub(glngamma(gdivgs(gsubsg(1, s), 2), prec),
     442             :                           glngamma(gdivgs(s, 2), prec)), prec));
     443         427 :   pz = gpowers(z, md - 1);
     444        2898 :   for (n = 1; n < md; n++)
     445             :   {
     446        2471 :     GEN xn = mycall(VC, n);
     447        2471 :     if (xn)
     448             :     {
     449        2408 :       GEN tmp = gmul(xn, gel(pz, n + 1));
     450        2408 :       cd = cd ? gadd(cd, tmp) : tmp;
     451             :     }
     452             :   }
     453         427 :   cs = gsubsg(1, gconj(s));
     454         427 :   ve = get_signat(VCALL); lve = lg(ve); R = cgetg(lve, t_VEC);
     455         896 :   for (i = 1; i < lve; i++)
     456         469 :     gel(R, i) = xpquo_one(s, cs, gel(cd, i), ve[i], md, prec);
     457         427 :   if (lve == 2) R = gel(R, 1);
     458         427 :   return R;
     459             : }
     460             : 
     461             : static GEN
     462        1176 : total_value(GEN serh0, GEN sel, GEN s, GEN VCALL, long prec)
     463             : {
     464        1176 :   return gadd(integral_h0(sel, s, VCALL, prec),
     465             :               gsub(serh0, series_residues_h0(sel, s, VCALL, prec)));
     466             : }
     467             : static GEN
     468        1127 : dirichlet_ours(GEN s, GEN VCALL, long prec)
     469             : {
     470        1127 :   int fl = !gequal(real_i(s), ghalf);
     471        1127 :   GEN sel = RZinit(s, VCALL, gen_1, prec);
     472        1127 :   GEN S1, S2, serh0 = series_h0(m_n0(sel), s, VCALL, fl, prec);
     473        1127 :   if (!fl)
     474        1078 :     S2 = S1 = total_value(serh0, sel, s, VCALL, prec);
     475             :   else
     476             :   {
     477          49 :     S1 = total_value(gel(serh0,1), sel, s, VCALL, prec);
     478          49 :     S2 = total_value(gconj(gel(serh0,2)), sel, gsubsg(1, gconj(s)), VCALL, prec);
     479             :   }
     480        1127 :   return gadd(S1, vecmul(xpquo(s, VCALL, prec), gconj(S2)));
     481             : }
     482             : 
     483             : /* assume |Im(s)| > 2^-bitprec */
     484             : static GEN
     485        1127 : RZchi(GEN VCALL, GEN s, long prec)
     486             : {
     487        1127 :   long prec2 = prec + EXTRAPREC64;
     488        1127 :   return gprec_wtrunc(dirichlet_ours(gprec_w(s, prec2), VCALL, prec2), prec);
     489             : }
     490             : 
     491             : /********************************************************************/
     492             : /*                         Utility Functions                        */
     493             : /********************************************************************/
     494             : /* lam = 0, return L(s); else Lambda(s) */
     495             : static GEN
     496        1127 : lfuncharall(GEN VCALL, GEN s, long lam, long bitprec)
     497             : {
     498        1127 :   GEN ve, P, Q, R, z = lfunlarge_char(VCALL, s, bitprec);
     499             :   long l, i, q, prec;
     500        1127 :   if (!lam) return z;
     501         882 :   ve = get_signat(VCALL); l = lg(ve);
     502         882 :   q = get_modulus(VCALL); prec = nbits2prec(bitprec);
     503         882 :   R = cgetg(l, t_VEC);
     504         882 :   Q = divur(q, mppi(prec));
     505         882 :   P = (q == 1 || zv_equal0(ve))? NULL: gsqrt(utoipos(q), prec);
     506        1764 :   for (i = 1; i < l; i++)
     507             :   {
     508         882 :     GEN se = gmul2n(gaddgs(s, ve[i]), -1), r;
     509         882 :     if (lam == 1)
     510             :     {
     511           0 :       r = gmul(gpow(Q, se, prec), ggamma(se, prec));
     512           0 :       if (P && ve[i]) r = gdiv(r, P);
     513             :     }
     514             :     else
     515             :     {
     516         882 :       r = gadd(gmul(se, glog(Q, prec)), glngamma(se, prec));
     517         882 :       if (P && ve[i]) r = gsub(r, glog(P, prec));
     518             :     }
     519         882 :     gel(R, i) = r;
     520             :   }
     521         882 :   return lam == 1 ? vecmul(R, z) : gadd(R, glog(z, prec));
     522             : }
     523             : 
     524             : static GEN
     525          28 : lfunlargeall_from_chars(GEN v, GEN s, long lam, long bit)
     526             : {
     527          28 :   long i, l = lg(v);
     528          84 :   for (i = 1; i < l; i++)
     529             :   {
     530          56 :     GEN w = mycharinit(gel(v, i), bit), L = lfuncharall(w, s, lam, bit);
     531          56 :     gel(v, i) = lam==-1 ? vecsum(L): vecprod(L);
     532             :   }
     533          28 :   return lam==-1 ? vecsum(v): vecprod(v);
     534             : }
     535             : static GEN
     536        1099 : lfunlargeall(GEN ldata, GEN s, long lam, long bit)
     537             : {
     538             :   GEN w, an;
     539        1099 :   if (lg(ldata) == 2)
     540             :   { /* HACK: ldata[1] a t_DESC_PRODUCT from lfunabelianrelinit / Q */
     541          14 :     GEN v = lfunprod_get_fact(linit_get_tech(gel(ldata,1)));
     542             :     long i, l;
     543          14 :     v = shallowcopy(gel(v,1)); l = lg(v);
     544          42 :     for (i = 1; i < l; i++) gel(v,i) = mkvec(gel(v,i));
     545          14 :     return lfunlargeall_from_chars(v, s, lam, bit);
     546             :   }
     547        1085 :   an = gel(ldata_get_an(ldata), 2);
     548        1085 :   switch(ldata_get_type(ldata))
     549             :   {
     550          14 :     case t_LFUN_NF:
     551             :     {
     552          14 :       GEN v = lfungetchars(nf_get_pol(an));
     553          14 :       return lfunlargeall_from_chars(v, s, lam, bit);
     554             :     }
     555           7 :     case t_LFUN_CHIGEN:
     556             :     {
     557           7 :       GEN chi = gmael(an, 2, 2);
     558           7 :       if (lg(chi) > 1 && is_vec_t(typ(gel(chi,1))))
     559             :       { /* multi char */
     560           7 :         w = mycharinit(mkcol(ldata), bit);
     561           7 :         return lfuncharall(w, s, lam, bit);
     562             :       }
     563             :     }
     564             :     default: /* single char */
     565        1064 :       w = mycharinit(mkcol(ldata), bit);
     566        1064 :       return gel(lfuncharall(w, s, lam, bit), 1);
     567             :   }
     568             : }
     569             : 
     570             : GEN
     571         231 : lfunlarge(GEN CHI, GEN s, long bit)
     572         231 : { return lfunlargeall(CHI, s, 0, bit); }
     573             : 
     574             : GEN
     575           0 : lfunlambdalarge(GEN CHI, GEN s, long bit)
     576           0 : { return lfunlargeall(CHI, s, 1, bit); }
     577             : 
     578             : GEN
     579         868 : lfunloglambdalarge(GEN CHI, GEN s, long bit)
     580         868 : { return lfunlargeall(CHI, s, -1, bit); }
     581             : 
     582             : /********************************************************************/
     583             : /*           LERCH RS IMPLEMENTATION FROM SANDEEP TYAGI             */
     584             : /********************************************************************/
     585             : 
     586             : static GEN
     587          56 : double_exp_residue_pos_h(GEN selsm, long k, long ind, long prec)
     588             : {
     589          56 :   long nk = itos(gel(selsm, 1)) + k;
     590          56 :   GEN r = gel(selsm, 2), ale = gel(selsm, 3), aor = gel(selsm, 4);
     591          56 :   GEN h = gel(selsm, 5), t = gen_0;
     592          56 :   switch(ind)
     593             :   {
     594          28 :     case 0: t = gaddsg(nk, aor); break;
     595           0 :     case 1: t = gneg(gaddsg(nk, aor)); break;
     596          28 :     case 2: t = gsubsg(nk, aor); break;
     597             :   }
     598          56 :   return gdiv(gasinh(gdiv(gsub(t, r), ale), prec), h);
     599             : }
     600             : 
     601             : static GEN
     602          56 : phi_hat_h(GEN selsm, long m, long ind, long prec)
     603          56 : { return phi_hat(double_exp_residue_pos_h(selsm, m, ind, prec), prec); }
     604             : 
     605             : static long
     606          56 : myex(GEN is) { return gequal0(is) ? 0 : maxss(0, 2 + gexpo(is)); }
     607             : static GEN
     608          56 : gaminus(GEN s, long prec)
     609             : {
     610          56 :   GEN is = imag_i(s), tmp;
     611             :   long prec2;
     612          56 :   if (gcmpgs(is, -5*prec) < 0) return gen_0;
     613          56 :   prec2 = nbits2prec(prec + myex(is));
     614          56 :   tmp = gexp(gsub(glngamma(s, prec2), gmul(PiI2n(-1, prec2), s)), prec2);
     615          56 :   return gprec_w(tmp, prec);
     616             : }
     617             : static GEN
     618          28 : gaplus(GEN s, long prec)
     619             : {
     620          28 :   GEN is = imag_i(s), tmp;
     621             :   long prec2;
     622          28 :   if (gcmpgs(is, 5*prec) > 0) return gen_0;
     623           0 :   prec2 = nbits2prec(prec + myex(is));
     624           0 :   tmp = gexp(gadd(glngamma(s, prec2), gmul(PiI2n(-1, prec2), s)), prec2);
     625           0 :   return gprec_w(tmp, prec);
     626             : }
     627             : 
     628             : GEN
     629        3508 : serh_worker(GEN k, GEN z, GEN a, GEN ns, GEN gprec)
     630             : {
     631        3508 :   long prec = itou(gprec);
     632        3509 :   return gmul(gpow(z, k, prec), gpow(gadd(a, k), ns, prec));
     633             : }
     634             : 
     635             : static void
     636          28 : set_arg(GEN worker, GEN z, GEN a, GEN ns, long prec)
     637          28 : { gel(worker, 7) = mkvec4(z, a, ns, utoi(prec)); }
     638             : 
     639             : 
     640             : static GEN
     641          14 : series_h0l(GEN worker, long n0, GEN s, GEN a, GEN lam, long prec)
     642             : {
     643          14 :   GEN z = typ(lam) == t_INT ? gen_1 : gexp(gmul(PiI2(prec), lam), prec);
     644          14 :   set_arg(worker, z, a, gneg(s), prec);
     645          14 :   return parsum(gen_0, utoi(n0), worker);
     646             : }
     647             : 
     648             : static GEN
     649          14 : series_h1(GEN worker, long n1, GEN s, GEN a, GEN lam, long prec)
     650             : {
     651          14 :   GEN mP, pre_factor, z, sn = gsubgs(s, 1);
     652          14 :   GEN ini = gequal0(lam) ? gen_1 : gen_0;
     653          14 :   pre_factor = gaplus(gneg(sn), prec);
     654          14 :   if (gequal0(pre_factor)) return gen_0;
     655           0 :   mP = gneg(PiI2(prec));
     656           0 :   pre_factor = gmul(gmul(pre_factor, gexp(gmul(mP, gmul(a, lam)), prec)),
     657             :                     gpow(Pi2n(1, prec), sn, prec));
     658           0 :   z = typ(a) == t_INT ? gen_1 : gexp(gmul(mP, a), prec);
     659           0 :   set_arg(worker, z, lam, sn, prec);
     660           0 :   return gmul(pre_factor,  parsum(ini, stoi(n1 - 1), worker));
     661             : }
     662             : 
     663             : static GEN
     664          14 : series_h2(GEN worker, long n2, GEN s, GEN a, GEN lam, long prec)
     665             : {
     666          14 :   GEN P, pre_factor, z, sn = gsubgs(s, 1);
     667          14 :   pre_factor = gaminus(gneg(sn), prec);
     668          14 :   if (gequal0(pre_factor)) return gen_0;
     669          14 :   P = PiI2(prec);
     670          14 :   pre_factor = gmul(gmul(pre_factor, gexp(gmul(gneg(P), gmul(a, lam)), prec)),
     671             :                     gpow(Pi2n(1, prec), sn, prec));
     672          14 :   z = typ(a) == t_INT ? gen_1 : gexp(gmul(P, a), prec);
     673          14 :   set_arg(worker, z, gneg(lam), sn, prec);
     674          14 :   return gmul(pre_factor, parsum(gen_1, stoi(n2), worker));
     675             : }
     676             : 
     677             : static GEN
     678          14 : series_residues_h0l(long numpoles, GEN selsm0, GEN s, GEN a, GEN lam, long prec)
     679             : {
     680          14 :   GEN P, val = gen_0, ra = real_i(a);
     681          14 :   long n0 = m_n0(selsm0), k;
     682          14 :   P = PiI2(prec);
     683          42 :   for (k = -numpoles + 1; k <= numpoles; k++)
     684          28 :     if (gsigne(gaddsg(n0 + k, ra)) > 0)
     685          28 :       val = gadd(val, gmul(gmul(phi_hat_h(selsm0, k, 0, prec),
     686             :                                 gexp(gmul(P, gmulgs(lam, n0 + k)), prec)),
     687             :                            gpow(gaddsg(n0 + k, a), gneg(s), prec)));
     688          14 :   return val;
     689             : }
     690             : 
     691             : static GEN
     692          14 : series_residues_h1(long numpoles, GEN selsm1, GEN s, GEN a, GEN lam, long prec)
     693             : {
     694          14 :   GEN mP, val = gen_0, rlam = real_i(lam), pre_factor, sn = gsubgs(s, 1);
     695          14 :   long n1 = m_n0(selsm1), k;
     696          14 :   pre_factor = gaplus(gneg(sn), prec);
     697          14 :   if (gequal0(pre_factor)) return gen_0;
     698           0 :   mP = gneg(PiI2(prec));
     699           0 :   pre_factor = gmul(gmul(pre_factor, gexp(gmul(mP, gmul(a, lam)), prec)),
     700             :                     gpow(Pi2n(1, prec), sn, prec));
     701           0 :   for (k = -numpoles; k <= numpoles - 1; k++)
     702           0 :     if (gsigne(gaddsg(n1 + k, rlam)) > 0)
     703           0 :       val = gadd(val, gmul(gmul(phi_hat_h(selsm1, k, 1, prec),
     704             :                                 gexp(gmul(mP, gmulgs(a, n1 + k)), prec)),
     705             :                            gpow(gaddsg(n1 + k, lam), sn, prec)));
     706           0 :   return gmul(pre_factor, val);
     707             : }
     708             : 
     709             : static GEN
     710          14 : series_residues_h2(long numpoles, GEN selsm2, GEN s, GEN a, GEN lam, long prec)
     711             : {
     712          14 :   GEN P, val = gen_0, rlam = real_i(lam), pre_factor, sn = gsubgs(s, 1);
     713          14 :   long n2 = m_n0(selsm2), k;
     714          14 :   pre_factor = gaminus(gneg(sn), prec);
     715          14 :   if (gequal0(pre_factor)) return gen_0;
     716          14 :   P = PiI2(prec);
     717          14 :   pre_factor = gmul(gmul(pre_factor, gexp(gmul(gneg(P), gmul(a, lam)), prec)),
     718             :                     gpow(Pi2n(1, prec), sn, prec));
     719          42 :   for (k = -numpoles + 1; k <= numpoles; k++)
     720          28 :     if (gsigne(gsubsg(n2 + k, rlam)) > 0)
     721          28 :       val = gsub(val, gmul(gmul(phi_hat_h(selsm2, k, 2, prec),
     722             :                                 gexp(gmul(P, gmulgs(a, n2 + k)), prec)),
     723             :                            gpow(gsubsg(n2 + k, lam), sn, prec)));
     724          14 :   return gmul(pre_factor, val);
     725             : }
     726             : 
     727             : static GEN
     728        3430 : integrand_h0l(GEN selsm0, GEN s, GEN alam1, GEN x, long prec)
     729             : {
     730        3430 :   GEN r0 = gel(selsm0, 2), ale = gel(selsm0, 3), a = gel(selsm0, 4);
     731        3430 :   GEN ix = ginv(x), zn = gadd(r0, gmul2n(gmul(ale, gsub(x, ix)), -1));
     732        3430 :   GEN P = PiI2n(0, prec), den, num;
     733        3430 :   den = gexpm1(gmul(P, gmul2n(gsub(zn,a), 1)), prec);
     734        3430 :   num = gexp(gmul(gmul(P, zn), gsub(alam1, zn)), prec);
     735        3430 :   num = gmul(gmul(gmul(num, ale), gmul2n(gadd(x, ix), -1)),
     736             :              gpow(zn, gneg(s), prec));
     737        3430 :   return gdiv(num, den);
     738             : }
     739             : 
     740             : static GEN
     741        6860 : integrand_h12(GEN selsm1, GEN s, GEN alam1, GEN x, long prec)
     742             : {
     743        6860 :   GEN r1 = gel(selsm1, 2), ale = gel(selsm1, 3), lam = gel(selsm1, 4);
     744        6860 :   GEN ix = ginv(x), zn = gadd(r1, gmul2n(gmul(ale, gsub(x, ix)), -1));
     745        6860 :   GEN P = PiI2n(0, prec), den, num, y;
     746        6860 :   den = gexpm1(gmul(P, gmul2n(gadd(zn,lam), 1)), prec);
     747        6860 :   num = gexp(gmul(gmul(P, zn), gadd(alam1, zn)), prec);
     748        6860 :   num = gmul(gmul(gmul(num, ale), gmul2n(gadd(x, ix), -1)),
     749             :              gpow(zn, gsubgs(s, 1), prec));
     750        6860 :   y = gdiv(num, den);
     751        6860 :   if (gcmp(garg(zn, prec), Pi2n(-2, prec)) > 0)
     752        1722 :     y = gmul(y, gexp(gmul(PiI2(prec), gsubsg(1, s)), prec));
     753        6860 :   return y;
     754             : }
     755             : 
     756             : static GEN
     757          14 : integral_h0l(GEN lin_grid, GEN selsm0, GEN s, GEN a, GEN lam, long prec)
     758             : {
     759          14 :   GEN A = gaddgs(gmul2n(gadd(a, lam),1), 1), S = gen_0;
     760          14 :   pari_sp av = avma;
     761          14 :   long j, l = lg(lin_grid);
     762             : 
     763        3388 :   for (j = 1; j < l; j++)
     764             :   {
     765        3374 :     S = gadd(S, integrand_h0l(selsm0, s, A, gel(lin_grid, j), prec));
     766        3374 :     if ((j & 0xff) == 0) S = gerepileupto(av, S);
     767             :   }
     768          14 :   S = gmul(m_h(selsm0), S);
     769          14 :   A = gmul(a, gaddsg(1, gadd(a, gmul2n(lam, 1))));
     770          14 :   return gmul(S, gexp(gneg(gmul(PiI2n(0, prec), A)), prec));
     771             : }
     772             : 
     773             : /* do not forget a minus sign for index 2 */
     774             : static GEN
     775          28 : integral_h12(GEN lin_grid, GEN selsm1, GEN s, GEN a, GEN lam, long prec)
     776             : {
     777          28 :   GEN A, E, S = gen_0, ga = gaminus(gsubsg(1, s), prec);
     778          28 :   pari_sp av = avma;
     779          28 :   long j, l = lg(lin_grid);
     780             : 
     781          28 :   if (gequal0(ga)) return S;
     782          28 :   A = gaddgs(gmul2n(gadd(a,lam), 1), 1);
     783        6776 :   for (j = 1; j < l; j++)
     784             :   {
     785        6748 :     S = gadd(S, integrand_h12(selsm1, s, A, gel(lin_grid, j), prec));
     786        6748 :     if ((j & 0xff) == 0) S = gerepileupto(av, S);
     787             :   }
     788          28 :   if (gequal0(S)) return gen_0;
     789          28 :   S = gmul(m_h(selsm1), S);
     790          28 :   E = gexp(gmul(PiI2n(0, prec), gmul(lam, gaddgs(lam, 1))), prec);
     791          28 :   return gmul(gmul(gmul(S, ga), E), gpow(Pi2n(1, prec), gsubgs(s, 1), prec));
     792             : }
     793             : 
     794             : struct _fun_q0_t { GEN sel, s, alam1, B; };
     795             : static GEN
     796          56 : _fun_q0(void *E, GEN x)
     797             : {
     798          56 :   struct _fun_q0_t *S = (struct _fun_q0_t*)E;
     799          56 :   GEN z = integrand_h0l(S->sel, S->s, S->alam1, x, DEFAULTPREC);
     800          56 :   return addrlogabs(S->B, z);
     801             : }
     802             : static GEN
     803         112 : _fun_q12(void *E, GEN x)
     804             : {
     805         112 :   struct _fun_q0_t *S = (struct _fun_q0_t*)E;
     806         112 :   GEN z = integrand_h12(S->sel, S->s, S->alam1, x, DEFAULTPREC);
     807         112 :   return addrlogabs(S->B, z);
     808             : }
     809             : 
     810             : static GEN
     811          14 : RZLERinit(GEN s, GEN a, GEN lam, GEN al, GEN numpoles, long prec)
     812             : {
     813             :   GEN eps, r0, r1, r2, h, lin_grid, q, q0, q1, q2, sel0, sel1, sel2, lq;
     814          14 :   GEN pinv = ginv(PiI2(prec)), c = gmul2n(gadd(a, lam), -1), n0, n1, n2, c2;
     815             :   long m;
     816             :   struct _fun_q0_t E;
     817             : 
     818          14 :   if (!al || gequal0(al))
     819           0 :     al = gcmpgs(gabs(imag_i(s), prec), 100) < 0 ? ginv(stoi(4)) : gen_1;
     820          14 :   c2 = gsub(gsqr(c), gmul(s, pinv));
     821          14 :   r0 = gadd(c, gsqrt(c2, prec));
     822          14 :   r1 = gsqrt(gadd(c2, pinv), prec);
     823          14 :   r2 = gsub(r1, c);
     824          14 :   r1 = gneg(gadd(r1, c));
     825          14 :   n0 = gfloor(gsub(gadd(real_i(r0), imag_i(r0)), a));
     826          14 :   n1 = gneg(gfloor(gadd(gsub(real_i(r1), imag_i(r1)), real_i(lam))));
     827          14 :   n2 = gfloor(gadd(gsub(real_i(r2), imag_i(r2)), real_i(lam)));
     828             : 
     829          14 :   E.s = s; E.alam1 = gaddgs(gmul2n(gadd(a, lam), 1), 1);
     830          14 :   E.B = mulur(prec, mplog2(prec));
     831          14 :   lq = gmul(al, sqrtr_abs(mulrr(divsr(prec, Pi2n(1, DEFAULTPREC)),
     832             :                                 mplog2(DEFAULTPREC))));
     833          14 :   eps = gexp(PiI2n(-2, prec), prec);
     834          14 :   E.sel = sel0 = mkvec5(n0, r0, gdiv(al, eps), a, gen_0);
     835          14 :   q0 = findq(&E, &_fun_q0, lq, prec);
     836             : 
     837          14 :   if (!gequal1(al)) lq = gdiv(lq, gsqr(al));
     838          14 :   E.sel = sel1 = mkvec5(n1, r1, gmul(al, eps), lam, gen_0);
     839          14 :   q1 = findq(&E, &_fun_q12, lq, prec);
     840          14 :   E.sel = sel2 = mkvec5(n2, r2, gmul(al, eps), lam, gen_0);
     841          14 :   q2 = findq(&E, &_fun_q12, lq, prec);
     842          14 :   q = vecmax(mkvec3(q0, q1, q2)); m = get_m(q, prec);
     843          14 :   gel(sel0, 5) = gel(sel1, 5) = gel(sel2, 5) = h = divru(q, (m-1) >> 1);
     844          14 :   lin_grid = setlin_grid_exp(h, m, prec);
     845          14 :   if (!numpoles) numpoles = gen_1;
     846          14 :   return mkvec5(sel0, sel1, sel2, lin_grid, numpoles);
     847             : }
     848             : 
     849          42 : static GEN add3(GEN x, GEN y, GEN z) { return gadd(x, gadd(y,z)); }
     850          14 : static GEN addsub(GEN x, GEN y, GEN z) { return gadd(x, gsub(y,z)); }
     851             : 
     852             : static GEN
     853          14 : lerch_ours(GEN sel, GEN s, GEN a, GEN lam, long prec)
     854             : {
     855          14 :   GEN selsm0 = gel(sel, 1), selsm1 = gel(sel, 2), selsm2 = gel(sel, 3);
     856          14 :   GEN lin_grid = gel(sel, 4), v0, v1, v2;
     857          14 :   long numpoles = itos(gel(sel, 5));
     858          14 :   GEN worker = snm_closure(is_entry("_serh_worker"),
     859             :                            mkvec4(NULL, NULL, NULL, NULL));
     860          14 :   v0 = add3(series_h0l(worker, m_n0(selsm0), s, a, lam, prec),
     861             :             series_residues_h0l(numpoles, selsm0, s, a, lam, prec),
     862             :             integral_h0l(lin_grid, selsm0, s, a, lam, prec));
     863          14 :   v1 = add3(series_h1(worker, m_n0(selsm1), s, a, lam, prec),
     864             :             series_residues_h1(numpoles, selsm1, s, a, lam, prec),
     865             :             integral_h12(lin_grid, selsm1, s, a, lam, prec));
     866          14 :   v2 = addsub(series_h2(worker, m_n0(selsm2), s, a, lam, prec),
     867             :             series_residues_h2(numpoles, selsm2, s, a, lam, prec),
     868             :             integral_h12(lin_grid, selsm2, s, a, lam, prec));
     869          14 :   return add3(v0, v1, v2);
     870             : }
     871             : 
     872             : static GEN
     873           0 : RZlerch_easy(GEN s, GEN a, GEN lam, long prec)
     874             : {
     875           0 :   pari_sp av = avma;
     876             :   GEN z, y, N;
     877           0 :   N = gdiv(gmulsg(prec + 5, mplog2(LOWDEFAULTPREC)),
     878             :            gmul(Pi2n(1, LOWDEFAULTPREC), imag_i(lam)));
     879           0 :   if (gexpo(N) > 40) pari_err_IMPL("precision too large in lerchzeta");
     880           0 :   N = gceil(N); prec += EXTRAPREC64;
     881           0 :   z = typ(lam) == t_INT ? gen_1 : gexp(gmul(PiI2(prec), lam), prec);
     882           0 :   y = parsum(gen_0, N, snm_closure(is_entry("_serh_worker"),
     883             :                                    mkvec4(z, a, gneg(s), stoi(prec))));
     884           0 :   return gerepilecopy(av, gprec_wtrunc(y, prec));
     885             : }
     886             : 
     887             : static GEN
     888          14 : mygfrac(GEN z)
     889           0 : { return typ(z) == t_COMPLEX ? mkcomplex(gfrac(real_i(z)), imag_i(z))
     890          14 :                              : gfrac(z); }
     891             : 
     892             : static GEN
     893          42 : lerchlarge(GEN s, GEN a, GEN lam, GEN al, GEN numpoles, long prec)
     894             : {
     895          42 :   pari_sp av = avma;
     896          42 :   GEN val, sel, imlam = imag_i(lam);
     897             :   long prec2;
     898          42 :   switch(gsigne(imlam))
     899             :   {
     900           0 :     case -1: pari_err_IMPL("imag(lam) < 0");
     901           0 :     case  1: if (gexpo(imlam) >= -16) return RZlerch_easy(s, a, lam, prec);
     902             :   }
     903          42 :   if (gcmpgs(real_i(a), 1) < 0)
     904             :   {
     905          14 :     GEN P = gexp(gmul(PiI2(prec), lam), prec);
     906          14 :     GEN L = lerchlarge(s, gaddgs(a, 1), lam, al, numpoles, prec);
     907          14 :     return gerepileupto(av, gadd(gpow(a, gneg(s), prec), gmul(P, L)));
     908             :   }
     909          28 :   if (gcmpgs(real_i(a), 2) >= 0)
     910             :   {
     911           0 :     GEN L, P = gexp(gneg(gmul(PiI2(prec), lam)), prec);
     912           0 :     a = gsubgs(a, 1); L = lerchlarge(s, a, lam, al, numpoles, prec);
     913           0 :     return gerepileupto(av, gmul(P, gsub(L, gpow(a, gneg(s), prec))));
     914             :   }
     915          28 :   if (gsigne(imag_i(s)) > 0)
     916             :   {
     917             :     GEN L;
     918          14 :     lam = mygfrac(gneg(gconj(lam)));
     919          14 :     L = lerchlarge(gconj(s), a, lam, al, numpoles, prec);
     920          14 :     return gerepileupto(av, gconj(L));
     921             :   }
     922          14 :   prec2 = prec + EXTRAPREC64;
     923          14 :   a = gprec_w(a, prec2);
     924          14 :   s = gprec_w(s, prec2);
     925          14 :   lam = gprec_w(lam, prec2);
     926          14 :   sel = RZLERinit(s, a, lam, al, numpoles, prec2);
     927          14 :   val = lerch_ours(sel, s, a, lam, prec2);
     928          14 :   return gerepilecopy(av, gprec_wtrunc(val, prec));
     929             : }
     930             : 
     931             : GEN
     932           7 : zetahurwitzlarge(GEN s, GEN a, long prec)
     933           7 : { return lerchlarge(s, a, gen_0, gen_1, gen_1, prec); }
     934             : 
     935             : GEN
     936           7 : lerchzetalarge(GEN s, GEN a, GEN lam, long prec)
     937           7 : { return lerchlarge(s, a, lam, gen_1, gen_1, prec); }

Generated by: LCOV version 1.16