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 - lambert.c (source / functions) Hit Total Coverage
Test: PARI/GP v2.14.0 lcov report (development 27775-aca467eab2) Lines: 233 260 89.6 %
Date: 2022-07-03 07:33:15 Functions: 18 22 81.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (C) 2021  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; either version 2 of the License, or (at your option) any later
       8             : version. It is distributed in the hope that it will be useful, but WITHOUT
       9             : ANY WARRANTY WHATSOEVER.
      10             : 
      11             : Check the License for details. You should have received a copy of it, along
      12             : with the package; see the file 'COPYING'. If not, write to the Free Software
      13             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
      14             : 
      15             : #include "pari.h"
      16             : #include "paripriv.h"
      17             : 
      18             : /***********************************************************************/
      19             : /**                 LAMBERT's W_K FUNCTIONS                           **/
      20             : /***********************************************************************/
      21             : /* roughly follows Veberic, https://arxiv.org/abs/1003.1628 */
      22             : 
      23             : static double
      24          21 : dblL1L2(double L1)
      25             : {
      26          21 :   double L2 = log(-L1), LI = 1 / L1, N2, N3, N4, N5;
      27          21 :   N2 = (L2-2.)/2.; N3 = (6.+L2*(-9.+2.*L2))/6.;
      28          21 :   N4 = (-12.+L2*(36.+L2*(-22.+3*L2)))/12.;
      29          21 :   N5 = (60.+L2*(-300.+L2*(350.+L2*(-125.+12*L2))))/60.;
      30          21 :   return L1-L2+L2*LI*(1+LI*(N2+LI*(N3+LI*(N4+LI*N5))));
      31             : }
      32             : 
      33             : /* rough approximation to W0(a > -1/e), < 1% relative error */
      34             : double
      35      441416 : dbllambertW0(double a)
      36             : {
      37      441416 :   if (a < -0.2583)
      38             :   {
      39           0 :     const double c2 = -1./3, c3 = 11./72, c4 = -43./540, c5 = 769./17280;
      40           0 :     double p = sqrt(2 * (M_E * a + 1));
      41           0 :     if (a < -0.3243) return -1+p*(1+p*(c2+p*c3));
      42           0 :     return -1+p*(1+p*(c2+p*(c3+p*(c4+p*c5))));
      43             :   }
      44             :   else
      45             :   {
      46      441416 :     double Wd = log(1.+a);
      47      441416 :     Wd *= (1.-log(Wd/a))/(1.+Wd);
      48      441416 :     if (a < 0.6482 && a > -0.1838) return Wd;
      49      387622 :     return Wd*(1.-log(Wd/a))/(1.+Wd);
      50             :   }
      51             : }
      52             : /* uniform approximation to W0, at least 15 bits. */
      53             : static double
      54         532 : dbllambertW0init(double a)
      55             : {
      56         532 :   if (a < -0.323581)
      57             :   {
      58          35 :     const double c2 = 1./3., c3 = 11./72., c4 = 43./540., c5 = 769./17280.;
      59          35 :     const double c6 = 221./8505., c7 = 680863./43545600.;
      60          35 :     const double c8 = 1963./204120., c9 = 226287557./37623398400.;
      61          35 :     double p = M_E * a + 1;
      62          35 :     if (p <= 0) return -1;
      63          21 :     p = -sqrt(2 * p);
      64          21 :     return -(1.+p*(1.+p*(c2+p*(c3+p*(c4+p*(c5+p*(c6+p*(c7+p*(c8+p*c9)))))))));
      65             :   }
      66         497 :   if (a < 0.145469)
      67             :   {
      68         112 :     const double a1 = 5.931375, a2 = 11.392205, a3 = 7.338883, a4 = 0.653449;
      69         112 :     const double b1 = 6.931373, b2 = 16.823494, b3 = 16.430723, b4 = 5.115235;
      70         112 :     double n = 1.+a*(a1+a*(a2+a*(a3+a*a4)));
      71         112 :     double d = 1.+a*(b1+a*(b2+a*(b3+a*b4)));
      72         112 :     return a * n / d;
      73             :   }
      74         385 :   if (a < 8.706658)
      75             :   {
      76         378 :     const double a1 = 2.445053, a2 = 1.343664, a3 = 0.148440, a4 = 0.000804;
      77         378 :     const double b1 = 3.444708, b2 = 3.292489, b3 = 0.916460, b4 = 0.053068;
      78         378 :     double n = 1.+a*(a1+a*(a2+a*(a3+a*a4)));
      79         378 :     double d = 1.+a*(b1+a*(b2+a*(b3+a*b4)));
      80         378 :     return a * n / d;
      81             :   }
      82             :   else
      83             :   {
      84           7 :     double w = log(1.+a);
      85           7 :     w *= (1.-log(w/a)) / (1.+w);
      86           7 :     return w * (1.-log(w/a)) / (1.+w);
      87             :   }
      88             : }
      89             : 
      90             : /* rough approximation to W_{-1}(0 > a > -1/e), < 1% relative error */
      91             : double
      92       66934 : dbllambertW_1(double a)
      93             : {
      94       66934 :   if (a < -0.2464)
      95             :   {
      96         280 :     const double c2 = -1./3, c3 = 11./72, c4 = -43./540, c5 = 769./17280;
      97         280 :     double p = -sqrt(2 * (M_E * a + 1));
      98         280 :     if (a < -0.3243) return -1+p*(1+p*(c2+p*c3));
      99         175 :     return -1+p*(1+p*(c2+p*(c3+p*(c4+p*c5))));
     100             :   }
     101             :   else
     102             :   {
     103             :     double Wd;
     104       66654 :     a = -a; Wd = -log(a);
     105       66654 :     Wd *= (1.-log(Wd/a))/(1.-Wd);
     106       66654 :     if (a < 0.0056) return -Wd;
     107         658 :     return -Wd*(1.-log(Wd/a))/(1.-Wd);
     108             :   }
     109             : }
     110             : /* uniform approximation to W_{-1}, at least 15 bits. */
     111             : static double
     112         112 : dbllambertW_1init(double a)
     113             : {
     114         112 :   if (a < -0.302985)
     115             :   {
     116          21 :     const double c2 = 1./3., c3 = 11./72., c4 = 43./540., c5 = 769./17280.;
     117          21 :     const double c6 = 221./8505., c7 = 680863./43545600.;
     118          21 :     const double c8 = 1963./204120., c9 = 226287557./37623398400.;
     119          21 :     double p = M_E * a + 1;
     120          21 :     if (p <= 0) return -1;
     121          21 :     p = sqrt(2 * p);
     122          21 :     return -(1.+p*(1.+p*(c2+p*(c3+p*(c4+p*(c5+p*(c6+p*(c7+p*(c8+p*c9)))))))));
     123             :   }
     124          91 :   if (a <= -0.051012)
     125             :   {
     126          77 :     const double a0 = -7.814176, a1 = 253.888101, a2 = 657.949317;
     127          77 :     const double b1 = -60.439587, b2 = 99.985670, b3 = 682.607399;
     128          77 :     const double b4 = 962.178439, b5 = 1477.934128;
     129          77 :     double n = a0+a*(a1+a*a2);
     130          77 :     double d = 1+a*(b1+a*(b2+a*(b3+a*(b4+a*b5))));
     131          77 :     return n / d;
     132             :   }
     133          14 :   return dblL1L2(log(-a));
     134             : }
     135             : 
     136             : /* uniform approximation to more than 46 bits, 50 bits away from -1/e. */
     137             : static double
     138         644 : dbllambertWfritsch(double a, int branch)
     139             : {
     140         644 :   double z, w1, q, w = branch? dbllambertW_1init(a): dbllambertW0init(a);
     141         644 :   if (w == -1.|| w == 0.) return w;
     142         630 :   z = log(a / w) - w; w1 = 1. + w;
     143         630 :   q = 2. * w1 * (w1 + (2./3.) * z);
     144         630 :   return w * (1 + (z / w1) * (q - z) / (q - 2 * z));
     145             : }
     146             : 
     147             : static double
     148           7 : dbllambertWhalleyspec(double loga)
     149             : {
     150           7 :   double w = dblL1L2(loga);
     151             :   for(;;)
     152           0 :   {
     153           7 :     double n = w + log(-w) - loga, d = 1 - w, r = n / (d + n / d);
     154           7 :     w *= 1 - r; if (r < 2.e-15) return w;
     155             :   }
     156             : }
     157             : /* k = 0 or -1. */
     158             : static GEN
     159         651 : lambertW(GEN z, long k, long prec)
     160             : {
     161         651 :   pari_sp av = avma;
     162         651 :   long bit = prec2nbits(prec), L = -(bit / 3 + 10), ct = 0, p, pb;
     163             :   double wd;
     164             :   GEN w, vp;
     165             : 
     166         651 :   if (gequal0(z) && !k) return real_0(prec);
     167         651 :   z = gtofp(z, prec);
     168         651 :   if (k == -1)
     169             :   {
     170         119 :     long e = expo(z);
     171         119 :     if (signe(z) >= 0) pari_err_DOMAIN("lambertw", "z", ">", gen_0, z);
     172         119 :     wd = e < -512? dbllambertWhalleyspec(dbllog2(z) * M_LN2)
     173         119 :                  : dbllambertWfritsch(rtodbl(z), -1);
     174             :   }
     175             :   else
     176         532 :     wd = dbllambertWfritsch(rtodbl(z), 0);
     177         651 :   if (fabs(wd + 1) < 1e-5)
     178             :   {
     179          14 :     long prec2 = prec + EXTRAPRECWORD;
     180          14 :     GEN Z = rtor(z, prec2);
     181          14 :     GEN t = addrs(mulrr(Z, gexp(gen_1, prec2)), 1);
     182          14 :     if (signe(t) <= 0) { set_avma(av); return real_m1(prec); }
     183           0 :     if (realprec(t) < prec)
     184             :     {
     185           0 :       prec2 += prec - realprec(t);
     186           0 :       Z = rtor(z, prec2);
     187           0 :       t = addrs(mulrr(Z, gexp(gen_1, prec2)), 1);
     188             :     }
     189           0 :     t = sqrtr(shiftr(t, 1));
     190           0 :     w = gprec_w(k == -1? subsr(-1, t) : subrs(t, 1), prec);
     191           0 :     p = prec - 2; vp = NULL;
     192             :   }
     193             :   else
     194             :   { /* away from -1/e: can reduce accuracy and self-correct */
     195         637 :     w = wd == 0.? z: dbltor(wd);
     196         637 :     vp = cgetg(30, t_VECSMALL); ct = 0; pb = bit;
     197        1410 :     while (pb > BITS_IN_LONG * 3/4)
     198         773 :     { vp[++ct] = (pb + BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG; pb = (pb + 2) / 3; }
     199         637 :     p = vp[ct]; w = gprec_w(w, p + 2);
     200             :   }
     201         728 :   if ((k == -1 && (bit < 192 || bit > 640)) || (k == 0 && bit > 1024))
     202             :   {
     203             :     for(;;)
     204          13 :     {
     205             :       GEN t, ew, n, d;
     206         104 :       ew = mplog(divrr(w, z)); n = addrr(w, ew); d = addrs(w, 1);
     207         104 :       t = divrr(n, shiftr(d, 1));
     208         104 :       w = mulrr(w, subsr(1, divrr(n, addrr(d, t))));
     209         104 :       if (p >= prec-2 && expo(n) - expo(d) - expo(w) <= L) break;
     210          13 :       if (vp) { if (--ct) p = vp[ct]; w = gprec_w(w, ct? p + 2: prec); }
     211             :     }
     212             :   }
     213             :   else
     214             :   {
     215             :     for(;;)
     216         178 :     {
     217             :       GEN t, ew, wew, n, d;
     218         724 :       ew = mpexp(w); wew = mulrr(w, ew); n = subrr(wew, z); d = addrr(ew, wew);
     219         724 :       t = divrr(mulrr(addrs(w, 2), n), shiftr(addrs(w, 1), 1));
     220         724 :       w = subrr(w, divrr(n, subrr(d, t)));
     221         724 :       if (p >= prec-2 && expo(n) - expo(d) - expo(w) <= L) break;
     222         178 :       if (vp) { if (--ct) p = vp[ct]; w = gprec_w(w, ct? p + 2: prec); }
     223             :     }
     224             :   }
     225         637 :   return gerepileupto(av, w);
     226             : }
     227             : 
     228             : /*********************************************************************/
     229             : /*                       Complex branches                            */
     230             : /*********************************************************************/
     231             : 
     232             : /* x *= (1 - (x + log(x) - L) / (x + 1)); L = log(z) + 2IPi * k */
     233             : static GEN
     234      632752 : lamaux(GEN x, GEN L, long *pe, long prec)
     235             : {
     236      632752 :   GEN n = gsub(gadd(x, glog(x, prec)), L);
     237      632752 :   if (pe) *pe = maxss(4, -gexpo(n));
     238      632752 :   if (gequal0(imag_i(n))) n = real_i(n);
     239      632752 :   return gmul(x, gsubsg(1, gdiv(n, gaddsg(1, x))));
     240             : }
     241             : 
     242             : /* Complex branches, experimental */
     243             : static GEN
     244       78428 : lambertWC(GEN z, long branch, long prec)
     245             : {
     246       78428 :   pari_sp av = avma;
     247             :   GEN w, pii2k, zl, lzl, L, Lz;
     248       78428 :   long bit0, si, j, fl = 0, lim = 6, lp = DEFAULTPREC, bit = prec2nbits(prec);
     249             : 
     250       78428 :   si = gsigne(imag_i(z)); if (!si) z = real_i(z);
     251       78428 :   pii2k = gmulsg(branch, PiI2(lp));
     252       78428 :   zl = gtofp(z, lp); lzl = glog(zl, lp);
     253             :   /* From here */
     254       78428 :   if (branch == 0 || branch * si < 0
     255       26579 :       || (si == 0 && gsigne(z) < 0 && branch == -1))
     256             :   {
     257       51989 :     GEN lnzl1 = gaddsg(1, glog(gneg(zl), lp));
     258       51989 :     if (si == 0) si = gsigne(lnzl1);
     259       51989 :     if ((branch == 0 || branch * si < 0) && gexpo(lnzl1) < -1)
     260             :     { /* close to -1/e */
     261        2408 :       w = gaddsg(1, gmul(z, gexp(gen_1, prec)));
     262        2408 :       w = gprec_wtrunc(w, lp);
     263        2408 :       w = gsqrt(gmul2n(w, 1), lp);
     264        2408 :       w = branch * si < 0? gsubsg(-1, w): gaddsg(-1, w);
     265        2408 :       lim = 10; fl = 1;
     266             :     }
     267       51989 :     if (branch == 0 && !fl && gexpo(lzl) < 0) { w = zl; fl = 1; }
     268             :   }
     269       78428 :   if (!fl)
     270             :   {
     271       68152 :     if (branch)
     272             :     {
     273       51212 :       GEN lr = glog(pii2k, lp);
     274       51212 :       w = gadd(gsub(gadd(pii2k, lzl), lr), gdiv(gsub(lr, lzl), pii2k));
     275             :     }
     276             :     else
     277             :     {
     278       16940 :       GEN p = gaddsg(1, gmul(z, gexp(gen_1, lp)));
     279       16940 :       w = gexpo(p) > 0? lzl: gaddgs(gsqrt(p, lp), -1);
     280             :     }
     281             :   }
     282             :   /* to here: heuristic */
     283       78428 :   L = gadd(lzl, pii2k);
     284      480200 :   for (j = 1; j < lim; j++) w = lamaux(w, L, NULL, lp);
     285       78428 :   Lz = NULL;
     286       78428 :   if (branch == 0 || branch == -1)
     287             :   {
     288       52199 :     Lz = glog(z, prec);
     289       52199 :     if (branch == -1)
     290             :     {
     291       25970 :       long flag = 1;
     292       25970 :       if (!si && signe(z) <= 0 && signe(addrs(Lz, 1))) flag = 0;
     293       25970 :       if (flag) Lz = gsub(Lz, PiI2(prec));
     294             :     }
     295             :   }
     296       78428 :   w = lamaux(w, L, &bit0, lp);
     297      230980 :   while (bit0 < bit || (Lz && gexpo(gsub(gadd(w, glog(w, prec)), Lz)) > 16-bit))
     298             :   {
     299      152552 :     long p = nbits2prec(bit0 <<= 1);
     300      152552 :     L = gadd(gmulsg(branch, PiI2(p)), glog(gprec_w(z, p), p));
     301      152552 :     w = lamaux(gprec_w(w, p), L, NULL, p);
     302             :   }
     303       78428 :   return gerepilecopy(av, gprec_w(w, nbits2prec(bit)));
     304             : }
     305             : 
     306             : /* exp(t (1 + O(t^n))), n >= 0 */
     307             : static GEN
     308         154 : serexp0(long v, long n)
     309             : {
     310         154 :   GEN y = cgetg(n+3, t_SER), t;
     311             :   long i;
     312         154 :   y[1] = evalsigne(1) | evalvarn(v) | evalvalp(0);
     313         154 :   gel(y,2) = gen_1; if (!n) return y;
     314         147 :   gel(y,3) = gen_1; if (n == 1) return y;
     315        1295 :   for (i=2, t = gen_2; i < n; i++, t = muliu(t,i)) gel(y,i+2) = mkfrac(gen_1,t);
     316         119 :   gel(y,i+2) = mkfrac(gen_1,t); return y;
     317             : }
     318             : 
     319             : /* series expansion of W at -1/e */
     320             : static GEN
     321           7 : Wbra(long N)
     322             : {
     323           7 :   GEN v = cgetg(N + 2, t_VEC);
     324             :   long n;
     325           7 :   gel(v, 1) = gen_m1;
     326           7 :   gel(v, 2) = gen_1;
     327          56 :   for (n = 2; n <= N; n++)
     328             :   {
     329          49 :     GEN t = gel(v,n), a = gen_0;
     330          49 :     long k, K = (n - 1) >> 1;
     331         133 :     for (k = 1; k <= K; k++) t = gadd(t, gmul2n(gel(v,n-2*k), -k));
     332         196 :     for (k = 2; k < n; k++) a = gadd(a, gmul(gel(v,k+1), gel(v,n+2-k)));
     333          49 :     gel(v,n+1) = gsub(gdivgs(t, -n-1), gmul2n(a, -1));
     334             :   }
     335           7 :   return RgV_to_RgX(v, 0);
     336             : }
     337             : 
     338             : static GEN
     339         154 : reverse(GEN y)
     340             : {
     341         154 :   GEN z = ser2rfrac_i(y);
     342         154 :   long l = lg(z);
     343         154 :   return RgX_to_ser(RgXn_reverse(z, l-2), l-1);
     344             : }
     345             : static GEN
     346         182 : serlambertW(GEN y, long branch, long prec)
     347             : {
     348             :   long n, vy, val, v;
     349         182 :   GEN t = NULL;
     350             : 
     351         182 :   if (!signe(y)) return gcopy(y);
     352         182 :   v = valp(y);
     353         182 :   if (v < 0) pari_err_DOMAIN("lambertw","valuation", "<", gen_0, y);
     354         175 :   if (v > 0 && branch)
     355           0 :     pari_err_DOMAIN("lambertw [k != 0]", "x", "~", gen_0, y);
     356         175 :   vy = varn(y); n = lg(y)-3;
     357         483 :   for (val = 1; val < n; val++)
     358         434 :     if (!gequal0(polcoef_i(y, val, vy))) break;
     359         175 :   if (v)
     360             :   {
     361          70 :     t = serexp0(vy, n / val);
     362          70 :     setvalp(t, 1); t = reverse(t); /* rev(x exp(x)) */
     363             :   }
     364             :   else
     365             :   {
     366         105 :     GEN y0 = gel(y,2), x = glambertW(y0, branch, prec);
     367         105 :     if (val > n) return scalarser(x, vy, n+1);
     368          98 :     y = serchop0(y);
     369          98 :     if (gequalm1(x))
     370             :     { /* y0 ~ -1/e, branch = 0 or -1 */
     371          14 :       GEN p = gmul(shiftr(gexp(gen_1,prec), 1), y);
     372          14 :       if (odd(val)) pari_err(e_MISC, "odd valuation at branch point");
     373           7 :       p = gsqrt(p, prec); if (odd(branch)) p = gneg(p);
     374           7 :       n -= val >> 1;
     375           7 :       t = RgXn_eval(Wbra(n), ser2rfrac_i(p), n);
     376           7 :       return gtoser(t, varn(t), lg(p));
     377             :     }
     378          84 :     t = serexp0(vy, n / val);
     379             :     /* (x + t) exp(x + t) = (y0 + t y0/x) * exp(t) */
     380          84 :     t = gmul(deg1pol_shallow(gdiv(y0,x), y0, vy), t);
     381          84 :     t = gadd(x, reverse(serchop0(t)));
     382             :   }
     383         154 :   return normalizeser(gsubst(t, vy, y));
     384             : }
     385             : 
     386             : static GEN
     387          14 : lambertp(GEN x)
     388             : {
     389          14 :   pari_sp av = avma;
     390             :   long k;
     391             :   GEN y;
     392             : 
     393          14 :   if (gequal0(x)) return gcopy(x);
     394          14 :   if (!valp(x)) { x = leafcopy(x); setvalp(x, 1); }
     395          14 :   k = Qp_exp_prec(x);
     396          14 :   if (k < 0) return NULL;
     397          14 :   y = gpowgs(cvstop2(k, x), k - 1);
     398         266 :   for (k--; k; k--)
     399         252 :     y = gsub(gpowgs(cvstop2(k, x), k - 1), gdivgu(gmul(x, y), k + 1));
     400          14 :   return gerepileupto(av, gmul(x, y));
     401             : }
     402             : 
     403             : /* y a t_REAL */
     404             : static int
     405        2212 : useC(GEN y, long k)
     406             : {
     407        2212 :   if (signe(y) > 0 || (k && k != -1)) return k ? 1: 0;
     408         980 :   return gsigne(addsr(1, logr_abs(y))) > 0;
     409             : }
     410             : static GEN
     411       80794 : glambertW_i(void *E, GEN y, long prec)
     412             : {
     413             :   pari_sp av;
     414       80794 :   long k = (long)E, p;
     415             :   GEN z;
     416       80794 :   if (gequal0(y))
     417             :   {
     418          21 :     if (k) pari_err_DOMAIN("glambertW","argument","",gen_0,y);
     419          14 :     return gcopy(y);
     420             :   }
     421       80773 :   switch(typ(y))
     422             :   {
     423        2212 :     case t_REAL:
     424        2212 :       p = minss(prec, realprec(y));
     425        2212 :       return useC(y, k)? lambertWC(y, k, p): lambertW(y, k, p);
     426          14 :     case t_PADIC: z = lambertp(y);
     427          14 :       if (!z) pari_err_DOMAIN("glambertW(t_PADIC)","argument","",gen_0,y);
     428          14 :       return z;
     429       76867 :     case t_COMPLEX:
     430       76867 :       p = precision(y);
     431       76867 :       return lambertWC(y, k, p? p: prec);
     432        1680 :     default:
     433        1680 :       av = avma; if (!(z = toser_i(y))) break;
     434         182 :       return gerepileupto(av, serlambertW(z, k, prec));
     435             :   }
     436        1498 :   return trans_evalgen("lambert", E, glambertW_i, y, prec);
     437             : }
     438             : 
     439             : GEN
     440       79296 : glambertW(GEN y, long k, long prec)
     441             : {
     442       79296 :   return glambertW_i((void*)k, y, prec);
     443             : }
     444             : GEN
     445           0 : mplambertW(GEN y, long prec) { return lambertW(y, 0, prec); }
     446             : 
     447             : /*********************************************************************/
     448             : /*                        Application                                */
     449             : /*********************************************************************/
     450             : /* Solve x - a * log(x) = b with a > 0 and b >= a * (1 - log(a)). */
     451             : GEN
     452           0 : mplambertx_logx(GEN a, GEN b, long bit)
     453             : {
     454           0 :   pari_sp av = avma;
     455           0 :   GEN e = gexp(gneg(gdiv(b, a)), nbits2prec(bit));
     456           0 :   return gerepileupto(av, gmul(gneg(a), lambertW(gneg(gdiv(e, a)), -1, bit)));
     457             : }
     458             : /* Special case a = 1, b = log(y): solve e^x / x = y with y >= exp(1). */
     459             : GEN
     460           0 : mplambertX(GEN y, long bit)
     461             : {
     462           0 :   pari_sp av = avma;
     463           0 :   return gerepileupto(av, gneg(lambertW(gneg(ginv(y)), -1, bit)));
     464             : }
     465             : 
     466             : /* Solve x * log(x) - a * x = b; if b < 0, assume a >= 1 + log |b|. */
     467             : GEN
     468           0 : mplambertxlogx_x(GEN a, GEN b, long bit)
     469             : {
     470           0 :   pari_sp av = avma;
     471           0 :   long s = gsigne(b);
     472             :   GEN e;
     473           0 :   if (!s) return gen_0;
     474           0 :   e = gexp(gneg(a), nbits2prec(bit));
     475           0 :   return gerepileupto(av, gdiv(b, lambertW(gmul(b, e), s > 0? 0: -1, bit)));
     476             : }

Generated by: LCOV version 1.13