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 - headers - pariinl.h (source / functions) Hit Total Coverage
Test: PARI/GP v2.12.1 lcov report (development 24215-a79de5b25) Lines: 1301 1468 88.6 %
Date: 2019-08-24 05:50:50 Functions: 573 649 88.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (C) 2000-2010  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             : /*******************************************************************/
      15             : /*                                                                 */
      16             : /*                          CONSTRUCTORS                           */
      17             : /*                                                                 */
      18             : /*******************************************************************/
      19             : #define retmkfrac(x,y)\
      20             :   do { GEN _v = cgetg(3, t_FRAC);\
      21             :        gel(_v,1) = (x);\
      22             :        gel(_v,2) = (y); return _v; } while(0)
      23             : #define retmkrfrac(x,y)\
      24             :   do { GEN _v = cgetg(3, t_RFRAC);\
      25             :        gel(_v,1) = (x);\
      26             :        gel(_v,2) = (y); return _v; } while(0)
      27             : #define retmkintmod(x,y)\
      28             :   do { GEN _v = cgetg(3, t_INTMOD);\
      29             :        gel(_v,1) = (y);\
      30             :        gel(_v,2) = (x); return _v; } while(0)
      31             : #define retmkcomplex(x,y)\
      32             :   do { GEN _v = cgetg(3, t_COMPLEX);\
      33             :        gel(_v,1) = (x);\
      34             :        gel(_v,2) = (y); return _v; } while(0)
      35             : #define retmkpolmod(x,y)\
      36             :   do { GEN _v = cgetg(3, t_POLMOD);\
      37             :        gel(_v,1) = (y);\
      38             :        gel(_v,2) = (x); return _v; } while(0)
      39             : #define retmkvec(x)\
      40             :   do { GEN _v = cgetg(2, t_VEC);\
      41             :        gel(_v,1) = (x); return _v; } while(0)
      42             : #define retmkvec2(x,y)\
      43             :   do { GEN _v = cgetg(3, t_VEC);\
      44             :        gel(_v,1) = (x);\
      45             :        gel(_v,2) = (y); return _v; } while(0)
      46             : #define retmkvec3(x,y,z)\
      47             :   do { GEN _v = cgetg(4, t_VEC);\
      48             :        gel(_v,1) = (x);\
      49             :        gel(_v,2) = (y);\
      50             :        gel(_v,3) = (z); return _v; } while(0)
      51             : #define retmkqfi(x,y,z)\
      52             :   do { GEN _v = cgetg(4, t_QFI);\
      53             :        gel(_v,1) = (x);\
      54             :        gel(_v,2) = (y);\
      55             :        gel(_v,3) = (z); return _v; } while(0)
      56             : #define retmkqfr(x,y,z,d)\
      57             :   do { GEN _v = cgetg(5, t_QFR);\
      58             :        gel(_v,1) = (x);\
      59             :        gel(_v,2) = (y);\
      60             :        gel(_v,3) = (z);\
      61             :        gel(_v,4) = (d); return _v; } while(0)
      62             : #define retmkquad(x,y,z)\
      63             :   do { GEN _v = cgetg(4, t_QUAD);\
      64             :        gel(_v,1) = (x);\
      65             :        gel(_v,2) = (y);\
      66             :        gel(_v,3) = (z); return _v; } while(0)
      67             : #define retmkvec4(x,y,z,t)\
      68             :   do { GEN _v = cgetg(5, t_VEC);\
      69             :        gel(_v,1) = (x);\
      70             :        gel(_v,2) = (y);\
      71             :        gel(_v,3) = (z);\
      72             :        gel(_v,4) = (t); return _v; } while(0)
      73             : #define retmkvec5(x,y,z,t,u)\
      74             :   do { GEN _v = cgetg(6, t_VEC);\
      75             :        gel(_v,1) = (x);\
      76             :        gel(_v,2) = (y);\
      77             :        gel(_v,3) = (z);\
      78             :        gel(_v,4) = (t);\
      79             :        gel(_v,5) = (u); return _v; } while(0)
      80             : #define retmkcol(x)\
      81             :   do { GEN _v = cgetg(2, t_COL);\
      82             :        gel(_v,1) = (x); return _v; } while(0)
      83             : #define retmkcol2(x,y)\
      84             :   do { GEN _v = cgetg(3, t_COL);\
      85             :        gel(_v,1) = (x);\
      86             :        gel(_v,2) = (y); return _v; } while(0)
      87             : #define retmkcol3(x,y,z)\
      88             :   do { GEN _v = cgetg(4, t_COL);\
      89             :        gel(_v,1) = (x);\
      90             :        gel(_v,2) = (y);\
      91             :        gel(_v,3) = (z); return _v; } while(0)
      92             : #define retmkcol4(x,y,z,t)\
      93             :   do { GEN _v = cgetg(5, t_COL);\
      94             :        gel(_v,1) = (x);\
      95             :        gel(_v,2) = (y);\
      96             :        gel(_v,3) = (z);\
      97             :        gel(_v,4) = (t); return _v; } while(0)
      98             : #define retmkcol5(x,y,z,t,u)\
      99             :   do { GEN _v = cgetg(6, t_COL);\
     100             :        gel(_v,1) = (x);\
     101             :        gel(_v,2) = (y);\
     102             :        gel(_v,3) = (z);\
     103             :        gel(_v,4) = (t);\
     104             :        gel(_v,5) = (u); return _v; } while(0)
     105             : #define retmkcol6(x,y,z,t,u,v)\
     106             :   do { GEN _v = cgetg(7, t_COL);\
     107             :        gel(_v,1) = (x);\
     108             :        gel(_v,2) = (y);\
     109             :        gel(_v,3) = (z);\
     110             :        gel(_v,4) = (t);\
     111             :        gel(_v,5) = (u);\
     112             :        gel(_v,6) = (v); return _v; } while(0)
     113             : #define retmkmat(x)\
     114             :   do { GEN _v = cgetg(2, t_MAT);\
     115             :        gel(_v,1) = (x); return _v; } while(0)
     116             : #define retmkmat2(x,y)\
     117             :   do { GEN _v = cgetg(3, t_MAT);\
     118             :        gel(_v,1) = (x);\
     119             :        gel(_v,2) = (y); return _v; } while(0)
     120             : #define retmkmat3(x,y,z)\
     121             :   do { GEN _v = cgetg(4, t_MAT);\
     122             :        gel(_v,1) = (x);\
     123             :        gel(_v,2) = (y);\
     124             :        gel(_v,3) = (z); return _v; } while(0)
     125             : #define retmkmat4(x,y,z,t)\
     126             :   do { GEN _v = cgetg(5, t_MAT);\
     127             :        gel(_v,1) = (x);\
     128             :        gel(_v,2) = (y);\
     129             :        gel(_v,3) = (z);\
     130             :        gel(_v,4) = (t); return _v; } while(0)
     131             : #define retmkmat5(x,y,z,t,u)\
     132             :   do { GEN _v = cgetg(6, t_MAT);\
     133             :        gel(_v,1) = (x);\
     134             :        gel(_v,2) = (y);\
     135             :        gel(_v,3) = (z);\
     136             :        gel(_v,4) = (t);\
     137             :        gel(_v,5) = (u); return _v; } while(0)
     138             : 
     139             : INLINE GEN
     140     3192119 : mkintmod(GEN x, GEN y) { retmkintmod(x,y); }
     141             : INLINE GEN
     142        4830 : mkintmodu(ulong x, ulong y) {
     143        4830 :   GEN v = cgetg(3,t_INTMOD);
     144        4830 :   gel(v,1) = utoipos(y);
     145        4830 :   gel(v,2) = utoi(x); return v;
     146             : }
     147             : INLINE GEN
     148     2967237 : mkpolmod(GEN x, GEN y) { retmkpolmod(x,y); }
     149             : INLINE GEN
     150    22586323 : mkfrac(GEN x, GEN y) { retmkfrac(x,y); }
     151             : INLINE GEN
     152       32011 : mkfracss(long x, long y) { retmkfrac(stoi(x),utoipos(y)); }
     153             : /* q = n/d a t_FRAC or t_INT; recover (n,d) */
     154             : INLINE void
     155       13566 : Qtoss(GEN q, long *n, long *d)
     156             : {
     157       13566 :   if (typ(q) == t_INT) { *n = itos(q); *d = 1; }
     158        2527 :   else { *n = itos(gel(q,1)); *d = itou(gel(q,2)); }
     159       13566 : }
     160             : INLINE GEN
     161    71394304 : sstoQ(long n, long d)
     162             : {
     163             :   ulong r;
     164             :   long g, q;
     165    71394304 :   if (!n)
     166             :   {
     167      100121 :     if (!d) pari_err_INV("sstoQ",gen_0);
     168      100121 :     return gen_0;
     169             :   }
     170    71294183 :   if (d < 0) { d = -d; n = -n; }
     171    71294183 :   if (d == 1) return stoi(n);
     172    71282192 :   q = udivuu_rem(labs(n),d,&r);
     173    71282192 :   if (!r) return n > 0? utoipos(q): utoineg(q);
     174     3642368 :   g = ugcd(d,r); /* gcd(n,d) */
     175     3642368 :   if (g != 1) { n /= g; d /= g; }
     176     3642368 :   retmkfrac(stoi(n), utoi(d));
     177             : }
     178             : 
     179             : INLINE GEN
     180    15549406 : mkfraccopy(GEN x, GEN y) { retmkfrac(icopy(x), icopy(y)); }
     181             : INLINE GEN
     182          35 : mkrfrac(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     183          35 :   gel(v,1) = x; gel(v,2) = y; return v; }
     184             : INLINE GEN
     185           7 : mkrfraccopy(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     186           7 :   gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     187             : INLINE GEN
     188    10559769 : mkcomplex(GEN x, GEN y) { retmkcomplex(x,y); }
     189             : INLINE GEN
     190      452625 : gen_I(void) { return mkcomplex(gen_0, gen_1); }
     191             : INLINE GEN
     192      270463 : cgetc(long l) { retmkcomplex(cgetr(l), cgetr(l)); }
     193             : INLINE GEN
     194         105 : mkquad(GEN n, GEN x, GEN y) { GEN v = cgetg(4, t_QUAD);
     195         105 :   gel(v,1) = n; gel(v,2) = x; gel(v,3) = y; return v; }
     196             : /* vecsmall */
     197             : INLINE GEN
     198    65847101 : mkvecsmall(long x) { GEN v = cgetg(2, t_VECSMALL); v[1] = x; return v; }
     199             : INLINE GEN
     200   113353544 : mkvecsmall2(long x,long y) { GEN v = cgetg(3, t_VECSMALL);
     201   113371580 :   v[1]=x; v[2]=y; return v; }
     202             : INLINE GEN
     203    57319516 : mkvecsmall3(long x,long y,long z) { GEN v = cgetg(4, t_VECSMALL);
     204    57313683 :   v[1]=x; v[2]=y; v[3]=z; return v; }
     205             : INLINE GEN
     206    11958494 : mkvecsmall4(long x,long y,long z,long t) { GEN v = cgetg(5, t_VECSMALL);
     207    11947096 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; return v; }
     208             : INLINE GEN
     209      466836 : mkvecsmall5(long x,long y,long z,long t,long u) { GEN v = cgetg(6, t_VECSMALL);
     210      466836 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; v[5]=u; return v; }
     211             : 
     212             : INLINE GEN
     213      158116 : mkqfi(GEN x, GEN y, GEN z) { retmkqfi(x,y,z); }
     214             : /* vec */
     215             : INLINE GEN
     216    19853741 : mkvec(GEN x) { retmkvec(x); }
     217             : INLINE GEN
     218   104999086 : mkvec2(GEN x, GEN y) { retmkvec2(x,y); }
     219             : INLINE GEN
     220    85541542 : mkvec3(GEN x, GEN y, GEN z) { retmkvec3(x,y,z); }
     221             : INLINE GEN
     222     7373298 : mkvec4(GEN x, GEN y, GEN z, GEN t) { retmkvec4(x,y,z,t); }
     223             : INLINE GEN
     224    12179773 : mkvec5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkvec5(x,y,z,t,u); }
     225             : INLINE GEN
     226         105 : mkvecs(long x) { retmkvec(stoi(x)); }
     227             : INLINE GEN
     228       23917 : mkvec2s(long x, long y) { retmkvec2(stoi(x),stoi(y)); }
     229             : INLINE GEN
     230      492724 : mkvec3s(long x, long y, long z) { retmkvec3(stoi(x),stoi(y),stoi(z)); }
     231             : INLINE GEN
     232          21 : mkvec4s(long x, long y, long z, long t) { retmkvec4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     233             : INLINE GEN
     234       35350 : mkveccopy(GEN x) { GEN v = cgetg(2, t_VEC); gel(v,1) = gcopy(x); return v; }
     235             : INLINE GEN
     236      100655 : mkvec2copy(GEN x, GEN y) {
     237      100655 :   GEN v = cgetg(3,t_VEC); gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     238             : /* col */
     239             : INLINE GEN
     240     2577997 : mkcol(GEN x) { retmkcol(x); }
     241             : INLINE GEN
     242    26095614 : mkcol2(GEN x, GEN y) { retmkcol2(x,y); }
     243             : INLINE GEN
     244       42371 : mkcol3(GEN x, GEN y, GEN z) { retmkcol3(x,y,z); }
     245             : INLINE GEN
     246           0 : mkcol4(GEN x, GEN y, GEN z, GEN t) { retmkcol4(x,y,z,t); }
     247             : INLINE GEN
     248           0 : mkcol5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkcol5(x,y,z,t,u); }
     249             : INLINE GEN
     250        9033 : mkcol6(GEN x, GEN y, GEN z, GEN t, GEN u, GEN v) { retmkcol6(x,y,z,t,u,v); }
     251             : INLINE GEN
     252         273 : mkcols(long x) { retmkcol(stoi(x)); }
     253             : INLINE GEN
     254     2179660 : mkcol2s(long x, long y) { retmkcol2(stoi(x),stoi(y)); }
     255             : INLINE GEN
     256           0 : mkcol3s(long x, long y, long z) { retmkcol3(stoi(x),stoi(y),stoi(z)); }
     257             : INLINE GEN
     258           0 : mkcol4s(long x, long y, long z, long t) { retmkcol4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     259             : INLINE GEN
     260       52573 : mkcolcopy(GEN x) { GEN v = cgetg(2, t_COL); gel(v,1) = gcopy(x); return v; }
     261             : /* mat */
     262             : INLINE GEN
     263     2806595 : mkmat(GEN x) { retmkmat(x); }
     264             : INLINE GEN
     265    32318804 : mkmat2(GEN x, GEN y) { retmkmat2(x,y); }
     266             : INLINE GEN
     267        2329 : mkmat3(GEN x, GEN y, GEN z) { retmkmat3(x,y,z); }
     268             : INLINE GEN
     269           0 : mkmat4(GEN x, GEN y, GEN z, GEN t) { retmkmat4(x,y,z,t); }
     270             : INLINE GEN
     271           0 : mkmat5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkmat5(x,y,z,t,u); }
     272             : INLINE GEN
     273       24329 : mkmatcopy(GEN x) { GEN v = cgetg(2, t_MAT); gel(v,1) = gcopy(x); return v; }
     274             : INLINE GEN
     275           0 : mkerr(long x) { GEN v = cgetg(2, t_ERROR); v[1] = x; return v; }
     276             : INLINE GEN
     277       97952 : mkoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_1; return v; }
     278             : INLINE GEN
     279       18151 : mkmoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_m1; return v; }
     280             : INLINE long
     281      136092 : inf_get_sign(GEN x) { return signe(gel(x,1)); }
     282             : INLINE GEN
     283       12418 : mkmat22s(long a, long b, long c, long d) {retmkmat2(mkcol2s(a,c),mkcol2s(b,d));}
     284             : INLINE GEN
     285     1533273 : mkmat22(GEN a, GEN b, GEN c, GEN d) { retmkmat2(mkcol2(a,c),mkcol2(b,d)); }
     286             : 
     287             : /* pol */
     288             : INLINE GEN
     289     1012623 : pol_x(long v) {
     290     1012623 :   GEN p = cgetg(4, t_POL);
     291     1012623 :   p[1] = evalsigne(1)|evalvarn(v);
     292     1012623 :   gel(p,2) = gen_0;
     293     1012623 :   gel(p,3) = gen_1; return p;
     294             : }
     295             : /* x^n, assume n >= 0 */
     296             : INLINE GEN
     297     1695694 : pol_xn(long n, long v) {
     298     1695694 :   long i, a = n+2;
     299     1695694 :   GEN p = cgetg(a+1, t_POL);
     300     1695694 :   p[1] = evalsigne(1)|evalvarn(v);
     301     1695694 :   for (i = 2; i < a; i++) gel(p,i) = gen_0;
     302     1695694 :   gel(p,a) = gen_1; return p;
     303             : }
     304             : /* x^n, no assumption on n */
     305             : INLINE GEN
     306         287 : pol_xnall(long n, long v)
     307             : {
     308         287 :   if (n < 0) retmkrfrac(gen_1, pol_xn(-n,v));
     309         280 :   return pol_xn(n, v);
     310             : }
     311             : INLINE GEN
     312     1594856 : pol_1(long v) {
     313     1594856 :   GEN p = cgetg(3, t_POL);
     314     1594852 :   p[1] = evalsigne(1)|evalvarn(v);
     315     1594852 :   gel(p,2) = gen_1; return p;
     316             : }
     317             : INLINE GEN
     318    32987215 : pol_0(long v)
     319             : {
     320    32987215 :   GEN x = cgetg(2,t_POL);
     321    32987215 :   x[1] = evalvarn(v); return x;
     322             : }
     323             : #define retconst_vec(n,x)\
     324             :   do { long _i, _n = (n);\
     325             :        GEN _v = cgetg(_n+1, t_VEC), _x = (x);\
     326             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     327             :        return _v; } while(0)
     328             : INLINE GEN
     329     9147641 : const_vec(long n, GEN x) { retconst_vec(n, x); }
     330             : #define retconst_col(n,x)\
     331             :   do { long _i, _n = (n);\
     332             :        GEN _v = cgetg(_n+1, t_COL), _x = (x);\
     333             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     334             :        return _v; } while(0)
     335             : INLINE GEN
     336     8689341 : const_col(long n, GEN x) { retconst_col(n, x); }
     337             : INLINE GEN
     338     8665227 : const_vecsmall(long n, long c)
     339             : {
     340             :   long i;
     341     8665227 :   GEN V = cgetg(n+1,t_VECSMALL);
     342     8665461 :   for(i=1;i<=n;i++) V[i] = c;
     343     8665461 :   return V;
     344             : }
     345             : 
     346             : /***   ZERO   ***/
     347             : /* O(p^e) */
     348             : INLINE GEN
     349      363585 : zeropadic(GEN p, long e)
     350             : {
     351      363585 :   GEN y = cgetg(5,t_PADIC);
     352      363585 :   gel(y,4) = gen_0;
     353      363585 :   gel(y,3) = gen_1;
     354      363585 :   gel(y,2) = icopy(p);
     355      363585 :   y[1] = evalvalp(e) | _evalprecp(0);
     356      363585 :   return y;
     357             : }
     358             : INLINE GEN
     359         966 : zeropadic_shallow(GEN p, long e)
     360             : {
     361         966 :   GEN y = cgetg(5,t_PADIC);
     362         966 :   gel(y,4) = gen_0;
     363         966 :   gel(y,3) = gen_1;
     364         966 :   gel(y,2) = p;
     365         966 :   y[1] = evalvalp(e) | _evalprecp(0);
     366         966 :   return y;
     367             : }
     368             : /* O(pol_x(v)^e) */
     369             : INLINE GEN
     370      144263 : zeroser(long v, long e)
     371             : {
     372      144263 :   GEN x = cgetg(2, t_SER);
     373      144263 :   x[1] = evalvalp(e) | evalvarn(v); return x;
     374             : }
     375             : INLINE int
     376     5471151 : ser_isexactzero(GEN x)
     377             : {
     378     5471151 :   if (!signe(x)) switch(lg(x))
     379             :   {
     380      136738 :     case 2: return 1;
     381         854 :     case 3: return isexactzero(gel(x,2));
     382             :   }
     383     5333559 :   return 0;
     384             : }
     385             : /* 0 * pol_x(v) */
     386             : INLINE GEN
     387    15562127 : zeropol(long v) { return pol_0(v); }
     388             : /* vector(n) */
     389             : INLINE GEN
     390    38883653 : zerocol(long n)
     391             : {
     392    38883653 :   GEN y = cgetg(n+1,t_COL);
     393    38883937 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     394    38883937 :   return y;
     395             : }
     396             : /* vectorv(n) */
     397             : INLINE GEN
     398    25183598 : zerovec(long n)
     399             : {
     400    25183598 :   GEN y = cgetg(n+1,t_VEC);
     401    25183607 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     402    25183607 :   return y;
     403             : }
     404             : /* matrix(m, n) */
     405             : INLINE GEN
     406       23453 : zeromat(long m, long n)
     407             : {
     408       23453 :   GEN y = cgetg(n+1,t_MAT);
     409       23453 :   GEN v = zerocol(m);
     410       23453 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     411       23453 :   return y;
     412             : }
     413             : /* = zero_zx, sv is a evalvarn()*/
     414             : INLINE GEN
     415      929295 : zero_Flx(long sv) { return pol0_Flx(sv); }
     416             : INLINE GEN
     417    34320542 : zero_Flv(long n)
     418             : {
     419    34320542 :   GEN y = cgetg(n+1,t_VECSMALL);
     420    34321789 :   long i; for (i=1; i<=n; i++) y[i] = 0;
     421    34321789 :   return y;
     422             : }
     423             : /* matrix(m, n) */
     424             : INLINE GEN
     425     1106103 : zero_Flm(long m, long n)
     426             : {
     427     1106103 :   GEN y = cgetg(n+1,t_MAT);
     428     1106083 :   GEN v = zero_Flv(m);
     429     1106068 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     430     1106068 :   return y;
     431             : }
     432             : /* matrix(m, n) */
     433             : INLINE GEN
     434      111568 : zero_Flm_copy(long m, long n)
     435             : {
     436      111568 :   GEN y = cgetg(n+1,t_MAT);
     437      111551 :   long i; for (i=1; i<=n; i++) gel(y,i) = zero_Flv(m);
     438      111572 :   return y;
     439             : }
     440             : 
     441             : INLINE GEN
     442      914640 : zero_F2v(long m)
     443             : {
     444      914640 :   long l = nbits2nlong(m);
     445      914640 :   GEN v  = zero_Flv(l+1);
     446      914640 :   v[1] = m;
     447      914640 :   return v;
     448             : }
     449             : 
     450             : INLINE GEN
     451           0 : zero_F2m(long m, long n)
     452             : {
     453             :   long i;
     454           0 :   GEN M = cgetg(n+1, t_MAT);
     455           0 :   GEN v = zero_F2v(m);
     456           0 :   for (i = 1; i <= n; i++)
     457           0 :     gel(M,i) = v;
     458           0 :   return M;
     459             : }
     460             : 
     461             : 
     462             : INLINE GEN
     463      303980 : zero_F2m_copy(long m, long n)
     464             : {
     465             :   long i;
     466      303980 :   GEN M = cgetg(n+1, t_MAT);
     467      926898 :   for (i = 1; i <= n; i++)
     468      622918 :     gel(M,i)= zero_F2v(m);
     469      303980 :   return M;
     470             : }
     471             : 
     472             : /* matrix(m, n) */
     473             : INLINE GEN
     474     5082697 : zeromatcopy(long m, long n)
     475             : {
     476     5082697 :   GEN y = cgetg(n+1,t_MAT);
     477     5082697 :   long i; for (i=1; i<=n; i++) gel(y,i) = zerocol(m);
     478     5082697 :   return y;
     479             : }
     480             : 
     481             : INLINE GEN
     482       17605 : zerovec_block(long len)
     483             : {
     484             :   long i;
     485       17605 :   GEN blk = cgetg_block(len + 1, t_VEC);
     486      580965 :   for (i = 1; i <= len; ++i)
     487      563360 :     gel(blk, i) = gen_0;
     488       17605 :   return blk;
     489             : }
     490             : 
     491             : /* i-th vector in the standard basis */
     492             : INLINE GEN
     493     1523907 : col_ei(long n, long i) { GEN e = zerocol(n); gel(e,i) = gen_1; return e; }
     494             : INLINE GEN
     495      348079 : vec_ei(long n, long i) { GEN e = zerovec(n); gel(e,i) = gen_1; return e; }
     496             : INLINE GEN
     497          42 : F2v_ei(long n, long i) { GEN e = zero_F2v(n); F2v_set(e,i); return e; }
     498             : INLINE GEN
     499       78035 : vecsmall_ei(long n, long i) { GEN e = zero_zv(n); e[i] = 1; return e; }
     500             : INLINE GEN
     501      708732 : Rg_col_ei(GEN x, long n, long i) { GEN e = zerocol(n); gel(e,i) = x; return e; }
     502             : 
     503             : INLINE GEN
     504    12993454 : shallowcopy(GEN x)
     505    12993454 : { return typ(x) == t_MAT ? RgM_shallowcopy(x): leafcopy(x); }
     506             : 
     507             : /* routines for naive growarrays */
     508             : INLINE GEN
     509    12375043 : vectrunc_init(long l)
     510             : {
     511    12375043 :   GEN z = new_chunk(l);
     512    12374952 :   z[0] = evaltyp(t_VEC) | _evallg(1); return z;
     513             : }
     514             : INLINE GEN
     515      347046 : coltrunc_init(long l)
     516             : {
     517      347046 :   GEN z = new_chunk(l);
     518      347046 :   z[0] = evaltyp(t_COL) | _evallg(1); return z;
     519             : }
     520             : INLINE void
     521   261916714 : lg_increase(GEN x) { x[0]++; }
     522             : INLINE void
     523    51353332 : vectrunc_append(GEN x, GEN t) { gel(x, lg(x)) = t; lg_increase(x); }
     524             : INLINE void
     525       10416 : vectrunc_append_batch(GEN x, GEN y)
     526             : {
     527       10416 :   long i, l = lg(x), ly = lg(y);
     528       10416 :   GEN z = x + l-1;
     529       10416 :   for (i = 1; i < ly; i++) gel(z,i) = gel(y,i);
     530       10416 :   setlg(x, l+ly-1);
     531       10416 : }
     532             : INLINE GEN
     533    86321877 : vecsmalltrunc_init(long l)
     534             : {
     535    86321877 :   GEN z = new_chunk(l);
     536    86321877 :   z[0] = evaltyp(t_VECSMALL) | _evallg(1); return z;
     537             : }
     538             : INLINE void
     539    33204302 : vecsmalltrunc_append(GEN x, long t) { x[ lg(x) ] = t; lg_increase(x); }
     540             : 
     541             : /*******************************************************************/
     542             : /*                                                                 */
     543             : /*                    STRING HASH FUNCTIONS                        */
     544             : /*                                                                 */
     545             : /*******************************************************************/
     546             : INLINE ulong
     547     2002796 : hash_str(const char *str)
     548             : {
     549     2002796 :   ulong hash = 5381UL, c;
     550    21821334 :   while ( (c = (ulong)*str++) )
     551    17815742 :     hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
     552     2002796 :   return hash;
     553             : }
     554             : INLINE ulong
     555     9890996 : hash_str_len(const char *str, long len)
     556             : {
     557     9890996 :   ulong hash = 5381UL;
     558             :   long i;
     559    74434785 :   for (i = 0; i < len; i++)
     560             :   {
     561    64543789 :     ulong c = (ulong)*str++;
     562    64543789 :     hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
     563             :   }
     564     9890996 :   return hash;
     565             : }
     566             : 
     567             : /*******************************************************************/
     568             : /*                                                                 */
     569             : /*                        VEC / COL / VECSMALL                     */
     570             : /*                                                                 */
     571             : /*******************************************************************/
     572             : /* shallow*/
     573             : INLINE GEN
     574           0 : vec_shorten(GEN v, long n)
     575             : {
     576             :   long i;
     577           0 :   GEN V = cgetg(n+1,t_VEC);
     578           0 :   for(i=1;i<=n;i++) gel(V,i) = gel(v,i);
     579           0 :   return V;
     580             : }
     581             : /* shallow*/
     582             : INLINE GEN
     583       13731 : vec_lengthen(GEN v, long n)
     584             : {
     585             :   long i;
     586       13731 :   long l=lg(v);
     587       13731 :   GEN V = cgetg(n+1,t_VEC);
     588       13731 :   for(i=1;i<l;i++) gel(V,i) = gel(v,i);
     589       13731 :   return V;
     590             : }
     591             : /* shallow*/
     592             : INLINE GEN
     593       92303 : vec_append(GEN V, GEN s)
     594             : {
     595       92303 :   long i, l2 = lg(V);
     596       92303 :   GEN res = cgetg(l2+1, typ(V));
     597       92303 :   for (i = 1; i < l2; ++i) gel(res, i) = gel(V,i);
     598       92303 :   gel(res,l2) = s; return res;
     599             : }
     600             : /* shallow*/
     601             : INLINE GEN
     602        3758 : vec_prepend(GEN v, GEN s)
     603             : {
     604        3758 :   long i, l = lg(v);
     605        3758 :   GEN w = cgetg(l+1, typ(v));
     606        3758 :   gel(w,1) = s;
     607        3758 :   for (i = 2; i <= l; ++i) gel(w,i) = gel(v,i-1);
     608        3758 :   return w;
     609             : }
     610             : /* shallow*/
     611             : INLINE GEN
     612           0 : vec_setconst(GEN v, GEN x)
     613             : {
     614           0 :   long i, l = lg(v);
     615           0 :   for (i = 1; i < l; i++) gel(v,i) = x;
     616           0 :   return v;
     617             : }
     618             : INLINE GEN
     619       62687 : vecsmall_shorten(GEN v, long n)
     620             : {
     621             :   long i;
     622       62687 :   GEN V = cgetg(n+1,t_VECSMALL);
     623       62690 :   for(i=1;i<=n;i++) V[i] = v[i];
     624       62690 :   return V;
     625             : }
     626             : INLINE GEN
     627          21 : vecsmall_lengthen(GEN v, long n)
     628             : {
     629          21 :   long i, l = lg(v);
     630          21 :   GEN V = cgetg(n+1,t_VECSMALL);
     631          21 :   for(i=1;i<l;i++) V[i] = v[i];
     632          21 :   return V;
     633             : }
     634             : 
     635             : INLINE GEN
     636     3323969 : vec_to_vecsmall(GEN x)
     637     3323969 : { pari_APPLY_long(itos(gel(x,i))) }
     638             : INLINE GEN
     639      137053 : vecsmall_to_vec(GEN x)
     640      137053 : { pari_APPLY_type(t_VEC, stoi(x[i])) }
     641             : INLINE GEN
     642         742 : vecsmall_to_vec_inplace(GEN z)
     643             : {
     644         742 :   long i, l = lg(z);
     645         742 :   for (i=1; i<l; i++) gel(z,i) = stoi(z[i]);
     646         742 :   settyp(z, t_VEC); return z;
     647             : }
     648             : INLINE GEN
     649     5255064 : vecsmall_to_col(GEN x)
     650     5255064 : { pari_APPLY_type(t_COL, stoi(x[i])) }
     651             : 
     652             : INLINE int
     653     8335166 : vecsmall_lexcmp(GEN x, GEN y)
     654             : {
     655             :   long lx,ly,l,i;
     656     8335166 :   lx = lg(x);
     657     8335166 :   ly = lg(y); l = minss(lx,ly);
     658    40359414 :   for (i=1; i<l; i++)
     659    38310666 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     660     2048748 :   if (lx == ly) return 0;
     661       30578 :   return (lx < ly)? -1 : 1;
     662             : }
     663             : 
     664             : INLINE int
     665    85155882 : vecsmall_prefixcmp(GEN x, GEN y)
     666             : {
     667    85155882 :   long i, lx = lg(x), ly = lg(y), l = minss(lx,ly);
     668   394028124 :   for (i=1; i<l; i++)
     669   374395413 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     670    19632711 :   return 0;
     671             : }
     672             : 
     673             : /*Can be used on t_VEC, but coeffs not gcopy-ed*/
     674             : INLINE GEN
     675       23415 : vecsmall_prepend(GEN V, long s)
     676             : {
     677       23415 :   long i, l2 = lg(V);
     678       23415 :   GEN res = cgetg(l2+1, typ(V));
     679       23415 :   res[1] = s;
     680       23415 :   for (i = 2; i <= l2; ++i) res[i] = V[i - 1];
     681       23415 :   return res;
     682             : }
     683             : 
     684             : INLINE GEN
     685     3138543 : vecsmall_append(GEN V, long s)
     686             : {
     687     3138543 :   long i, l2 = lg(V);
     688     3138543 :   GEN res = cgetg(l2+1, t_VECSMALL);
     689     3138542 :   for (i = 1; i < l2; ++i) res[i] = V[i];
     690     3138542 :   res[l2] = s; return res;
     691             : }
     692             : 
     693             : INLINE GEN
     694     1001604 : vecsmall_concat(GEN u, GEN v)
     695             : {
     696     1001604 :   long i, l1 = lg(u)-1, l2 = lg(v)-1;
     697     1001604 :   GEN res = cgetg(l1+l2+1, t_VECSMALL);
     698     1001604 :   for (i = 1; i <= l1; ++i) res[i]    = u[i];
     699     1001604 :   for (i = 1; i <= l2; ++i) res[i+l1] = v[i];
     700     1001604 :   return res;
     701             : }
     702             : 
     703             : /* return the number of indices where u and v are equal */
     704             : INLINE long
     705           0 : vecsmall_coincidence(GEN u, GEN v)
     706             : {
     707           0 :   long i, s = 0, l = minss(lg(u),lg(v));
     708           0 :   for(i=1; i<l; i++)
     709           0 :     if(u[i] == v[i]) s++;
     710           0 :   return s;
     711             : }
     712             : 
     713             : /* returns the first index i<=n such that x=v[i] if it exists, 0 otherwise */
     714             : INLINE long
     715           0 : vecsmall_isin(GEN v, long x)
     716             : {
     717           0 :   long i, l = lg(v);
     718           0 :   for (i = 1; i < l; i++)
     719           0 :     if (v[i] == x) return i;
     720           0 :   return 0;
     721             : }
     722             : 
     723             : INLINE long
     724          84 : vecsmall_pack(GEN V, long base, long mod)
     725             : {
     726          84 :   long i, s = 0;
     727          84 :   for(i=1; i<lg(V); i++) s = (base*s + V[i]) % mod;
     728          84 :   return s;
     729             : }
     730             : 
     731             : INLINE long
     732          14 : vecsmall_indexmax(GEN x)
     733             : {
     734          14 :   long i, i0 = 1, t = x[1], lx = lg(x);
     735          56 :   for (i=2; i<lx; i++)
     736          42 :     if (x[i] > t) t = x[i0=i];
     737          14 :   return i0;
     738             : }
     739             : 
     740             : INLINE long
     741      203176 : vecsmall_max(GEN x)
     742             : {
     743      203176 :   long i, t = x[1], lx = lg(x);
     744      694668 :   for (i=2; i<lx; i++)
     745      491492 :     if (x[i] > t) t = x[i];
     746      203176 :   return t;
     747             : }
     748             : 
     749             : INLINE long
     750          14 : vecsmall_indexmin(GEN x)
     751             : {
     752          14 :   long i, i0 = 1, t = x[1], lx =lg(x);
     753          56 :   for (i=2; i<lx; i++)
     754          42 :     if (x[i] < t) t = x[i0=i];
     755          14 :   return i0;
     756             : }
     757             : 
     758             : INLINE long
     759        1421 : vecsmall_min(GEN x)
     760             : {
     761        1421 :   long i, t = x[1], lx =lg(x);
     762        9947 :   for (i=2; i<lx; i++)
     763        8526 :     if (x[i] < t) t = x[i];
     764        1421 :   return t;
     765             : }
     766             : 
     767             : INLINE int
     768     5216725 : ZV_isscalar(GEN x)
     769             : {
     770     5216725 :   long l = lg(x);
     771    14987693 :   while (--l > 1)
     772     8619970 :     if (signe(gel(x, l))) return 0;
     773     1150998 :   return 1;
     774             : }
     775             : INLINE int
     776    21641508 : QV_isscalar(GEN x)
     777             : {
     778    21641508 :   long lx = lg(x),i;
     779    23323891 :   for (i=2; i<lx; i++)
     780    22694722 :     if (!isintzero(gel(x, i))) return 0;
     781      629169 :   return 1;
     782             : }
     783             : INLINE int
     784        7812 : RgV_isscalar(GEN x)
     785             : {
     786        7812 :   long lx = lg(x),i;
     787       11649 :   for (i=2; i<lx; i++)
     788       10264 :     if (!gequal0(gel(x, i))) return 0;
     789        1385 :   return 1;
     790             : }
     791             : INLINE int
     792           0 : RgX_isscalar(GEN x)
     793             : {
     794             :   long i;
     795           0 :   for (i=lg(x)-1; i>2; i--)
     796           0 :     if (!gequal0(gel(x, i))) return 0;
     797           0 :   return 1;
     798             : }
     799             : INLINE long
     800    28847398 : RgX_equal_var(GEN x, GEN y) { return varn(x) == varn(y) && RgX_equal(x,y); }
     801             : 
     802             : INLINE int
     803        7638 : RgX_is_rational(GEN x)
     804             : {
     805             :   long i;
     806       34739 :   for (i = lg(x)-1; i > 1; i--)
     807       32239 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     808        2500 :   return 1;
     809             : }
     810             : INLINE int
     811     4704306 : RgX_is_ZX(GEN x)
     812             : {
     813             :   long i;
     814    20342196 :   for (i = lg(x)-1; i > 1; i--)
     815    15690493 :     if (typ(gel(x,i)) != t_INT) return 0;
     816     4651703 :   return 1;
     817             : }
     818             : INLINE int
     819      273742 : RgX_is_QX(GEN x)
     820             : {
     821      273742 :   long k = lg(x)-1;
     822     1001925 :   for ( ; k>1; k--)
     823      728456 :     if (!is_rational_t(typ(gel(x,k)))) return 0;
     824      273469 :   return 1;
     825             : }
     826             : INLINE int
     827     2346076 : RgX_is_monomial(GEN x)
     828             : {
     829             :   long i;
     830     2346076 :   if (!signe(x)) return 0;
     831     5855799 :   for (i=lg(x)-2; i>1; i--)
     832     3562363 :     if (!isexactzero(gel(x,i))) return 0;
     833     2293436 :   return 1;
     834             : }
     835             : INLINE int
     836    27494732 : RgV_is_ZV(GEN x)
     837             : {
     838             :   long i;
     839   112659066 :   for (i = lg(x)-1; i > 0; i--)
     840    85166833 :     if (typ(gel(x,i)) != t_INT) return 0;
     841    27492233 :   return 1;
     842             : }
     843             : INLINE int
     844       23313 : RgV_is_QV(GEN x)
     845             : {
     846             :   long i;
     847      104038 :   for (i = lg(x)-1; i > 0; i--)
     848       82356 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     849       21682 :   return 1;
     850             : }
     851             : INLINE long
     852       22162 : RgV_isin_i(GEN v, GEN x, long n)
     853             : {
     854             :   long i;
     855      409010 :   for (i = 1; i <= n; i++)
     856      408597 :     if (gequal(gel(v,i), x)) return i;
     857         413 :   return 0;
     858             : }
     859             : INLINE long
     860       21917 : RgV_isin(GEN v, GEN x) { return RgV_isin_i(v, x, lg(v)-1); }
     861             : 
     862             : /********************************************************************/
     863             : /**                                                                **/
     864             : /**            Dynamic arrays implementation                       **/
     865             : /**                                                                **/
     866             : /********************************************************************/
     867             : INLINE void **
     868   463299290 : pari_stack_base(pari_stack *s) { return s->data; }
     869             : 
     870             : INLINE void
     871     2360141 : pari_stack_init(pari_stack *s, size_t size, void **data)
     872             : {
     873     2360141 :   s->data = data;
     874     2360141 :   *data = NULL;
     875     2360141 :   s->n = 0;
     876     2360141 :   s->alloc = 0;
     877     2360141 :   s->size = size;
     878     2360141 : }
     879             : 
     880             : INLINE void
     881   461170718 : pari_stack_alloc(pari_stack *s, long nb)
     882             : {
     883   461170718 :   void **sdat = pari_stack_base(s);
     884   461098974 :   long alloc = s->alloc;
     885   461098974 :   if (s->n+nb <= alloc) return;
     886      955744 :   if (!alloc)
     887      894782 :     alloc = nb;
     888             :   else
     889             :   {
     890       60962 :     while (s->n+nb > alloc) alloc <<= 1;
     891             :   }
     892      955744 :   *sdat = pari_realloc(*sdat,alloc*s->size);
     893      957041 :   s->alloc = alloc;
     894             : }
     895             : 
     896             : INLINE long
     897   379843551 : pari_stack_new(pari_stack *s) { pari_stack_alloc(s, 1); return s->n++; }
     898             : 
     899             : INLINE void
     900     2156468 : pari_stack_delete(pari_stack *s)
     901             : {
     902     2156468 :   void **sdat = pari_stack_base(s);
     903     2151222 :   if (*sdat) pari_free(*sdat);
     904     2166675 : }
     905             : 
     906             : INLINE void
     907        4871 : pari_stack_pushp(pari_stack *s, void *u)
     908             : {
     909        4871 :   long n = pari_stack_new(s);
     910        4871 :   void **sdat =(void**) *pari_stack_base(s);
     911        4871 :   sdat[n] = u;
     912        4871 : }
     913             : 
     914             : /*******************************************************************/
     915             : /*                                                                 */
     916             : /*                            EXTRACT                              */
     917             : /*                                                                 */
     918             : /*******************************************************************/
     919             : INLINE GEN
     920   304635353 : vecslice(GEN A, long y1, long y2)
     921             : {
     922   304635353 :   long i,lB = y2 - y1 + 2;
     923   304635353 :   GEN B = cgetg(lB, typ(A));
     924   304685410 :   for (i=1; i<lB; i++) B[i] = A[y1-1+i];
     925   304685410 :   return B;
     926             : }
     927             : INLINE GEN
     928      958915 : vecslicepermute(GEN A, GEN p, long y1, long y2)
     929             : {
     930      958915 :   long i,lB = y2 - y1 + 2;
     931      958915 :   GEN B = cgetg(lB, typ(A));
     932      958939 :   for (i=1; i<lB; i++) B[i] = A[p[y1-1+i]];
     933      958939 :   return B;
     934             : }
     935             : /* rowslice(rowpermute(A,p), x1, x2) */
     936             : INLINE GEN
     937       44180 : rowslicepermute(GEN x, GEN p, long j1, long j2)
     938       44180 : { pari_APPLY_same(vecslicepermute(gel(x,i),p,j1,j2)) }
     939             : 
     940             : INLINE GEN
     941    30131564 : rowslice(GEN x, long j1, long j2)
     942    30131564 : { pari_APPLY_same(vecslice(gel(x,i), j1, j2)) }
     943             : 
     944             : INLINE GEN
     945     8049454 : matslice(GEN A, long x1, long x2, long y1, long y2)
     946     8049454 : { return rowslice(vecslice(A, y1, y2), x1, x2); }
     947             : 
     948             : /* shallow, remove coeff of index j */
     949             : INLINE GEN
     950         133 : rowsplice(GEN x, long j)
     951         133 : { pari_APPLY_same(vecsplice(gel(x,i), j)) }
     952             : 
     953             : /* shallow, remove coeff of index j */
     954             : INLINE GEN
     955      264783 : vecsplice(GEN a, long j)
     956             : {
     957      264783 :   long i, k, l = lg(a);
     958             :   GEN b;
     959      264783 :   if (l == 1) pari_err(e_MISC, "incorrect component in vecsplice");
     960      264783 :   b = cgetg(l-1, typ(a));
     961     1056576 :   for (i = k = 1; i < l; i++)
     962      791793 :     if (i != j) gel(b, k++) = gel(a,i);
     963      264783 :   return b;
     964             : }
     965             : /* shallow */
     966             : INLINE GEN
     967         833 : RgM_minor(GEN a, long i, long j)
     968             : {
     969         833 :   GEN b = vecsplice(a, j);
     970         833 :   long k, l = lg(b);
     971         833 :   for (k = 1; k < l; k++) gel(b,k) = vecsplice(gel(b,k), i);
     972         833 :   return b;
     973             : }
     974             : 
     975             : /* A[x0,] */
     976             : INLINE GEN
     977      390532 : row(GEN x, long j)
     978      390532 : { pari_APPLY_type(t_VEC, gcoeff(x, j, i)) }
     979             : INLINE GEN
     980     4299949 : Flm_row(GEN x, long j)
     981     4299949 : { pari_APPLY_ulong((ulong)coeff(x, j, i)) }
     982             : /* A[x0,] */
     983             : INLINE GEN
     984      204834 : rowcopy(GEN x, long j)
     985      204834 : { pari_APPLY_type(t_VEC, gcopy(gcoeff(x, j, i))) }
     986             : /* A[x0, x1..x2] */
     987             : INLINE GEN
     988        3038 : row_i(GEN A, long x0, long x1, long x2)
     989             : {
     990        3038 :   long i, lB = x2 - x1 + 2;
     991        3038 :   GEN B  = cgetg(lB, t_VEC);
     992        3038 :   for (i=x1; i<=x2; i++) gel(B, i) = gcoeff(A, x0, i);
     993        3038 :   return B;
     994             : }
     995             : 
     996             : INLINE GEN
     997     5830581 : vecreverse(GEN A)
     998             : {
     999             :   long i, l;
    1000     5830581 :   GEN B = cgetg_copy(A, &l);
    1001     5830581 :   for (i=1; i<l; i++) gel(B, i) = gel(A, l-i);
    1002     5830581 :   return B;
    1003             : }
    1004             : 
    1005             : INLINE GEN
    1006         539 : vecsmall_reverse(GEN A)
    1007             : {
    1008             :   long i, l;
    1009         539 :   GEN B = cgetg_copy(A, &l);
    1010         539 :   for (i=1; i<l; i++) B[i] = A[l-i];
    1011         539 :   return B;
    1012             : }
    1013             : 
    1014             : INLINE void
    1015         253 : vecreverse_inplace(GEN y)
    1016             : {
    1017         253 :   long l = lg(y), lim = l>>1, i;
    1018         717 :   for (i = 1; i <= lim; i++)
    1019             :   {
    1020         464 :     GEN z = gel(y,i);
    1021         464 :     gel(y,i)    = gel(y,l-i);
    1022         464 :     gel(y,l-i) = z;
    1023             :   }
    1024         253 : }
    1025             : 
    1026             : INLINE GEN
    1027    50822555 : vecsmallpermute(GEN A, GEN p) { return perm_mul(A, p); }
    1028             : 
    1029             : INLINE GEN
    1030     6499777 : vecpermute(GEN A, GEN x)
    1031     6499777 : { pari_APPLY_type(typ(A), gel(A, x[i])) }
    1032             : 
    1033             : INLINE GEN
    1034     3475895 : rowpermute(GEN x, GEN p)
    1035     3475895 : { pari_APPLY_same(typ(gel(x,i)) == t_VECSMALL ? vecsmallpermute(gel(x, i), p)
    1036             :                                               : vecpermute(gel(x, i), p))
    1037             : }
    1038             : /*******************************************************************/
    1039             : /*                                                                 */
    1040             : /*                          PERMUTATIONS                           */
    1041             : /*                                                                 */
    1042             : /*******************************************************************/
    1043             : INLINE GEN
    1044      816424 : identity_zv(long n)
    1045             : {
    1046      816424 :   GEN v = cgetg(n+1, t_VECSMALL);
    1047             :   long i;
    1048      816402 :   for (i = 1; i <= n; i++) v[i] = i;
    1049      816402 :   return v;
    1050             : }
    1051             : INLINE GEN
    1052        2177 : identity_ZV(long n)
    1053             : {
    1054        2177 :   GEN v = cgetg(n+1, t_VEC);
    1055             :   long i;
    1056        2177 :   for (i = 1; i <= n; i++) gel(v,i) = utoipos(i);
    1057        2177 :   return v;
    1058             : }
    1059             : /* identity permutation */
    1060             : INLINE GEN
    1061      815929 : identity_perm(long n) { return identity_zv(n); }
    1062             : 
    1063             : /* assume d <= n */
    1064             : INLINE GEN
    1065       98434 : cyclic_perm(long n, long d)
    1066             : {
    1067       98434 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1068             :   long i;
    1069       98434 :   for (i = 1; i <= n-d; i++) perm[i] = i+d;
    1070       98434 :   for (     ; i <= n;   i++) perm[i] = i-n+d;
    1071       98434 :   return perm;
    1072             : }
    1073             : 
    1074             : /* Multiply (compose) two permutations */
    1075             : INLINE GEN
    1076    52149271 : perm_mul(GEN s, GEN x)
    1077    52149271 : { pari_APPLY_long(s[x[i]]) }
    1078             : 
    1079             : /* Compute the inverse (reciprocal) of a permutation. */
    1080             : INLINE GEN
    1081     1260019 : perm_inv(GEN x)
    1082             : {
    1083             :   long i, lx;
    1084     1260019 :   GEN y = cgetg_copy(x, &lx);
    1085     1260019 :   for (i=1; i<lx; i++) y[ x[i] ] = i;
    1086     1260019 :   return y;
    1087             : }
    1088             : /* Return s*t*s^-1 */
    1089             : INLINE GEN
    1090      416976 : perm_conj(GEN s, GEN t)
    1091             : {
    1092             :   long i, l;
    1093      416976 :   GEN v = cgetg_copy(s, &l);
    1094      416976 :   for (i = 1; i < l; i++) v[ s[i] ] = s[ t[i] ];
    1095      416976 :   return v;
    1096             : }
    1097             : 
    1098             : /*********************************************************************/
    1099             : /*                       MALLOC/FREE WRAPPERS                        */
    1100             : /*********************************************************************/
    1101             : #define BLOCK_SIGALRM_START          \
    1102             : {                                    \
    1103             :   int block=PARI_SIGINT_block;       \
    1104             :   PARI_SIGINT_block = 2;             \
    1105             :   MT_SIGINT_BLOCK(block);
    1106             : 
    1107             : #define BLOCK_SIGINT_START           \
    1108             : {                                    \
    1109             :   int block=PARI_SIGINT_block;       \
    1110             :   PARI_SIGINT_block = 1;             \
    1111             :   MT_SIGINT_BLOCK(block);
    1112             : 
    1113             : #define BLOCK_SIGINT_END             \
    1114             :   PARI_SIGINT_block = block;         \
    1115             :   MT_SIGINT_UNBLOCK(block);          \
    1116             :   if (!block && PARI_SIGINT_pending) \
    1117             :   {                                  \
    1118             :     int sig = PARI_SIGINT_pending;   \
    1119             :     PARI_SIGINT_pending = 0;         \
    1120             :     raise(sig);                      \
    1121             :   }                                  \
    1122             : }
    1123             : 
    1124             : INLINE void
    1125    97953738 : pari_free(void *pointer)
    1126             : {
    1127    97953738 :   BLOCK_SIGINT_START;
    1128    97983599 :   free(pointer);
    1129    97983599 :   BLOCK_SIGINT_END;
    1130    97977921 : }
    1131             : INLINE void*
    1132   308236067 : pari_malloc(size_t size)
    1133             : {
    1134   308236067 :   if (size)
    1135             :   {
    1136             :     char *tmp;
    1137   308236067 :     BLOCK_SIGINT_START;
    1138   308241472 :     tmp = (char*)malloc(size);
    1139   308241472 :     BLOCK_SIGINT_END;
    1140   308240509 :     if (!tmp) pari_err(e_MEM);
    1141   308240509 :     return tmp;
    1142             :   }
    1143           0 :   return NULL;
    1144             : }
    1145             : INLINE void*
    1146      970484 : pari_realloc(void *pointer, size_t size)
    1147             : {
    1148             :   char *tmp;
    1149             : 
    1150      970484 :   BLOCK_SIGINT_START;
    1151      975359 :   if (!pointer) tmp = (char *) malloc(size);
    1152       65352 :   else tmp = (char *) realloc(pointer,size);
    1153      975359 :   BLOCK_SIGINT_END;
    1154      973412 :   if (!tmp) pari_err(e_MEM);
    1155      973412 :   return tmp;
    1156             : }
    1157             : INLINE void*
    1158       37589 : pari_calloc(size_t size)
    1159             : {
    1160       37589 :   void *t = pari_malloc(size);
    1161       37589 :   memset(t, 0, size); return t;
    1162             : }
    1163             : INLINE GEN
    1164        5873 : cgetalloc(long t, size_t l)
    1165             : { /* evallg may raise e_OVERFLOW, which would leak x */
    1166        5873 :   ulong x0 = evaltyp(t) | evallg(l);
    1167        5873 :   GEN x = (GEN)pari_malloc(l * sizeof(long));
    1168        5873 :   x[0] = x0; return x;
    1169             : }
    1170             : 
    1171             : /*******************************************************************/
    1172             : /*                                                                 */
    1173             : /*                       GARBAGE COLLECTION                        */
    1174             : /*                                                                 */
    1175             : /*******************************************************************/
    1176             : /* copy integer x as if we had set_avma(av) */
    1177             : INLINE GEN
    1178  3986272864 : icopy_avma(GEN x, pari_sp av)
    1179             : {
    1180  3986272864 :   long i = lgefint(x), lx = i;
    1181  3986272864 :   GEN y = ((GEN)av) - i;
    1182  3986272864 :   while (--i > 0) y[i] = x[i];
    1183  3986272864 :   y[0] = evaltyp(t_INT)|evallg(lx);
    1184  3985979689 :   return y;
    1185             : }
    1186             : /* copy leaf x as if we had set_avma(av) */
    1187             : INLINE GEN
    1188   188627022 : leafcopy_avma(GEN x, pari_sp av)
    1189             : {
    1190   188627022 :   long i = lg(x);
    1191   188627022 :   GEN y = ((GEN)av) - i;
    1192   188627022 :   while (--i > 0) y[i] = x[i];
    1193   188627022 :   y[0] = x[0] & (~CLONEBIT);
    1194   188627022 :   return y;
    1195             : }
    1196             : INLINE GEN
    1197   672639966 : gerepileuptoleaf(pari_sp av, GEN x)
    1198             : {
    1199             :   long lx;
    1200             :   GEN q;
    1201             : 
    1202   672639966 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1203   672584643 :   lx = lg(x);
    1204   672584643 :   q = ((GEN)av) - lx;
    1205   672584643 :   set_avma((pari_sp)q);
    1206   673691238 :   while (--lx >= 0) q[lx] = x[lx];
    1207   673691238 :   return q;
    1208             : }
    1209             : INLINE GEN
    1210  1425136383 : gerepileuptoint(pari_sp av, GEN x)
    1211             : {
    1212  1425136383 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1213  1248232440 :   set_avma((pari_sp)icopy_avma(x, av));
    1214  1250318743 :   return (GEN)avma;
    1215             : }
    1216             : INLINE GEN
    1217   780306094 : gerepileupto(pari_sp av, GEN x)
    1218             : {
    1219   780306094 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1220   703789038 :   switch(typ(x))
    1221             :   { /* non-default = !is_recursive_t(tq) */
    1222   229292633 :     case t_INT: return gerepileuptoint(av, x);
    1223             :     case t_REAL:
    1224             :     case t_STR:
    1225   150063130 :     case t_VECSMALL: return gerepileuptoleaf(av,x);
    1226             :     default:
    1227             :       /* NB: x+i --> ((long)x) + i*sizeof(long) */
    1228   324433275 :       return gerepile(av, (pari_sp) (x+lg(x)), x);
    1229             :   }
    1230             : }
    1231             : INLINE double
    1232     2603595 : gc_double(pari_sp av, double d) { set_avma(av); return d; }
    1233             : INLINE long
    1234   112398057 : gc_long(pari_sp av, long s) { set_avma(av); return s; }
    1235             : INLINE ulong
    1236    13891450 : gc_ulong(pari_sp av, ulong s) { set_avma(av); return s; }
    1237             : INLINE int
    1238    23559727 : gc_bool(pari_sp av, int s) { set_avma(av); return s; }
    1239             : INLINE int
    1240     3382345 : gc_int(pari_sp av, int s) { set_avma(av); return s; }
    1241             : INLINE GEN
    1242     1700997 : gc_NULL(pari_sp av) { set_avma(av); return NULL; }
    1243             : 
    1244             : /* gerepileupto(av, gcopy(x)) */
    1245             : INLINE GEN
    1246    64876921 : gerepilecopy(pari_sp av, GEN x)
    1247             : {
    1248    64876921 :   if (is_recursive_t(typ(x)))
    1249             :   {
    1250    60193976 :     GENbin *p = copy_bin(x);
    1251    60194652 :     set_avma(av); return bin_copy(p);
    1252             :   }
    1253             :   else
    1254             :   {
    1255     4682953 :     set_avma(av);
    1256     4682957 :     if (x < (GEN)av) {
    1257     3195410 :       if (x < (GEN)pari_mainstack->bot) new_chunk(lg(x));
    1258     3195410 :       x = leafcopy_avma(x, av);
    1259     3195427 :       set_avma((pari_sp)x);
    1260             :     } else
    1261     1487547 :       x = leafcopy(x);
    1262     4682969 :     return x;
    1263             :   }
    1264             : }
    1265             : 
    1266             : INLINE void
    1267    29177633 : guncloneNULL(GEN x) { if (x) gunclone(x); }
    1268             : INLINE void
    1269      198220 : guncloneNULL_deep(GEN x) { if (x) gunclone_deep(x); }
    1270             : 
    1271             : /* Takes an array of pointers to GENs, of length n. Copies all
    1272             :  * objects to contiguous locations and cleans up the stack between
    1273             :  * av and avma. */
    1274             : INLINE void
    1275      203212 : gerepilemany(pari_sp av, GEN* gptr[], int n)
    1276             : {
    1277             :   int i;
    1278      203212 :   for (i=0; i<n; i++) *gptr[i] = (GEN)copy_bin(*gptr[i]);
    1279      203212 :   set_avma(av);
    1280      203212 :   for (i=0; i<n; i++) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1281      203212 : }
    1282             : 
    1283             : INLINE void
    1284    14530189 : gerepileall(pari_sp av, int n, ...)
    1285             : {
    1286             :   int i;
    1287    14530189 :   va_list a; va_start(a, n);
    1288    14530189 :   if (n < 10)
    1289             :   {
    1290             :     GEN *gptr[10];
    1291    42567340 :     for (i=0; i<n; i++)
    1292    28037083 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1293    14530257 :     set_avma(av);
    1294    14530168 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1295             : 
    1296             :   }
    1297             :   else
    1298             :   {
    1299           0 :     GEN **gptr = (GEN**)  pari_malloc(n*sizeof(GEN*));
    1300           0 :     for (i=0; i<n; i++)
    1301           0 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1302           0 :     set_avma(av);
    1303           0 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1304           0 :     pari_free(gptr);
    1305             :   }
    1306    14530351 :   va_end(a);
    1307    14530351 : }
    1308             : 
    1309             : INLINE void
    1310           6 : gerepilecoeffs(pari_sp av, GEN x, int n)
    1311             : {
    1312             :   int i;
    1313           6 :   for (i=0; i<n; i++) gel(x,i) = (GEN)copy_bin(gel(x,i));
    1314           6 :   set_avma(av);
    1315           6 :   for (i=0; i<n; i++) gel(x,i) = bin_copy((GENbin*)x[i]);
    1316           6 : }
    1317             : 
    1318             : /* p from copy_bin. Copy p->x back to stack, then destroy p */
    1319             : INLINE GEN
    1320    88872374 : bin_copy(GENbin *p)
    1321             : {
    1322             :   GEN x, y, base;
    1323             :   long dx, len;
    1324             : 
    1325    88872374 :   x   = p->x; if (!x) { pari_free(p); return gen_0; }
    1326    88865105 :   len = p->len;
    1327    88865105 :   base= p->base; dx = x - base;
    1328    88865105 :   y = (GEN)memcpy((void*)new_chunk(len), (void*)GENbinbase(p), len*sizeof(long));
    1329    88864982 :   y += dx;
    1330    88864982 :   p->rebase(y, ((ulong)y-(ulong)x));
    1331    88864967 :   pari_free(p); return y;
    1332             : }
    1333             : 
    1334             : INLINE GEN
    1335   177738012 : GENbinbase(GENbin *p) { return (GEN)(p + 1); }
    1336             : 
    1337             : INLINE void
    1338    32498230 : cgiv(GEN x)
    1339             : {
    1340    32498230 :   pari_sp av = (pari_sp)(x+lg(x));
    1341    32498230 :   if (isonstack((GEN)av)) set_avma(av);
    1342    32497943 : }
    1343             : 
    1344             : INLINE void
    1345     1317383 : killblock(GEN x) { gunclone(x); }
    1346             : 
    1347             : INLINE int
    1348    29417927 : is_universal_constant(GEN x) { return (x >= gen_0 && x <= ghalf); }
    1349             : 
    1350             : /*******************************************************************/
    1351             : /*                                                                 */
    1352             : /*                    CONVERSION / ASSIGNMENT                      */
    1353             : /*                                                                 */
    1354             : /*******************************************************************/
    1355             : /* z is a type which may be a t_COMPLEX component (not a t_QUAD) */
    1356             : INLINE GEN
    1357     3796879 : cxcompotor(GEN z, long prec)
    1358             : {
    1359     3796879 :   switch(typ(z))
    1360             :   {
    1361     2151524 :     case t_INT:  return itor(z, prec);
    1362      136668 :     case t_FRAC: return fractor(z, prec);
    1363     1508687 :     case t_REAL: return rtor(z, prec);
    1364           0 :     default: pari_err_TYPE("cxcompotor",z);
    1365             :              return NULL; /* LCOV_EXCL_LINE */
    1366             :   }
    1367             : }
    1368             : INLINE GEN
    1369     1884342 : cxtofp(GEN x, long prec)
    1370     1884342 : { retmkcomplex(cxcompotor(gel(x,1),prec), cxcompotor(gel(x,2),prec)); }
    1371             : 
    1372             : INLINE GEN
    1373      262724 : cxtoreal(GEN q)
    1374      262724 : { return (typ(q) == t_COMPLEX && gequal0(gel(q,2)))? gel(q,1): q; }
    1375             : 
    1376             : INLINE double
    1377    28107136 : gtodouble(GEN x)
    1378             : {
    1379    28107136 :   if (typ(x)!=t_REAL) {
    1380     5753750 :     pari_sp av = avma;
    1381     5753750 :     x = gtofp(x, DEFAULTPREC);
    1382     5753144 :     if (typ(x)!=t_REAL) pari_err_TYPE("gtodouble [t_REAL expected]", x);
    1383     5753144 :     set_avma(av);
    1384             :   }
    1385    28106350 :   return rtodbl(x);
    1386             : }
    1387             : INLINE long
    1388    73430620 : gtos(GEN x) {
    1389    73430620 :   if (typ(x) != t_INT) pari_err_TYPE("gtos [integer expected]",x);
    1390    73430613 :   return itos(x);
    1391             : }
    1392             : 
    1393             : INLINE ulong
    1394      152392 : gtou(GEN x) {
    1395      152392 :   if (typ(x) != t_INT || signe(x)<0)
    1396           0 :     pari_err_TYPE("gtou [integer >=0 expected]",x);
    1397      152411 :   return itou(x);
    1398             : }
    1399             : 
    1400             : INLINE GEN
    1401    23891453 : absfrac(GEN x)
    1402             : {
    1403    23891453 :   GEN y = cgetg(3, t_FRAC);
    1404    23891453 :   gel(y,1) = absi(gel(x,1));
    1405    23891453 :   gel(y,2) = icopy(gel(x,2)); return y;
    1406             : }
    1407             : INLINE GEN
    1408       38594 : absfrac_shallow(GEN x)
    1409       38594 : { return signe(gel(x,1))>0? x: mkfrac(negi(gel(x,1)), gel(x,2)); }
    1410             : INLINE GEN
    1411     7879478 : Q_abs(GEN x) { return (typ(x) == t_INT)? absi(x): absfrac(x); }
    1412             : INLINE GEN
    1413      141111 : Q_abs_shallow(GEN x)
    1414      141111 : { return (typ(x) == t_INT)? absi_shallow(x): absfrac_shallow(x); }
    1415             : INLINE GEN
    1416       12600 : R_abs_shallow(GEN x)
    1417       12600 : { return (typ(x) == t_FRAC)? absfrac_shallow(x): mpabs_shallow(x); }
    1418             : INLINE GEN
    1419           0 : R_abs(GEN x)
    1420           0 : { return (typ(x) == t_FRAC)? absfrac(x): mpabs(x); }
    1421             : 
    1422             : /* Force z to be of type real/complex with floating point components */
    1423             : INLINE GEN
    1424    33186489 : gtofp(GEN z, long prec)
    1425             : {
    1426    33186489 :   switch(typ(z))
    1427             :   {
    1428    21233099 :     case t_INT:  return itor(z, prec);
    1429     4301974 :     case t_FRAC: return fractor(z, prec);
    1430     6003671 :     case t_REAL: return rtor(z, prec);
    1431             :     case t_COMPLEX: {
    1432     1647745 :       GEN a = gel(z,1), b = gel(z,2);
    1433     1647745 :       if (isintzero(b)) return cxcompotor(a, prec);
    1434     1645014 :       if (isintzero(a)) {
    1435        3214 :         GEN y = cgetg(3, t_COMPLEX);
    1436        3214 :         b = cxcompotor(b, prec);
    1437        3214 :         gel(y,1) = real_0_bit(expo(b) - prec2nbits(prec));
    1438        3214 :         gel(y,2) = b; return y;
    1439             :       }
    1440     1641800 :       return cxtofp(z, prec);
    1441             :     }
    1442           0 :     case t_QUAD: return quadtofp(z, prec);
    1443           0 :     default: pari_err_TYPE("gtofp",z);
    1444             :              return NULL; /* LCOV_EXCL_LINE */
    1445             :   }
    1446             : }
    1447             : /* Force z to be of type real / int */
    1448             : INLINE GEN
    1449       22428 : gtomp(GEN z, long prec)
    1450             : {
    1451       22428 :   switch(typ(z))
    1452             :   {
    1453          42 :     case t_INT:  return z;
    1454       22386 :     case t_FRAC: return fractor(z, prec);
    1455           0 :     case t_REAL: return rtor(z, prec);
    1456           0 :     case t_QUAD: z = quadtofp(z, prec);
    1457           0 :                  if (typ(z) == t_REAL) return z;
    1458           0 :     default: pari_err_TYPE("gtomp",z);
    1459             :              return NULL; /* LCOV_EXCL_LINE */
    1460             :   }
    1461             : }
    1462             : 
    1463             : INLINE GEN
    1464      866718 : RgX_gtofp(GEN x, long prec)
    1465             : {
    1466             :   long l;
    1467      866718 :   GEN y = cgetg_copy(x, &l);
    1468      866718 :   while (--l > 1) gel(y,l) = gtofp(gel(x,l), prec);
    1469      866718 :   y[1] = x[1]; return y;
    1470             : }
    1471             : INLINE GEN
    1472     1210234 : RgC_gtofp(GEN x, long prec)
    1473     1210234 : { pari_APPLY_type(t_COL, gtofp(gel(x,i), prec)) }
    1474             : 
    1475             : INLINE GEN
    1476          42 : RgV_gtofp(GEN x, long prec)
    1477          42 : { pari_APPLY_type(t_VEC, gtofp(gel(x,i), prec)) }
    1478             : 
    1479             : INLINE GEN
    1480      137277 : RgM_gtofp(GEN x, long prec)
    1481      137277 : { pari_APPLY_same(RgC_gtofp(gel(x,i), prec)) }
    1482             : 
    1483             : INLINE GEN
    1484         574 : RgC_gtomp(GEN x, long prec)
    1485         574 : { pari_APPLY_type(t_COL, gtomp(gel(x,i), prec)) }
    1486             : 
    1487             : INLINE GEN
    1488          21 : RgM_gtomp(GEN x, long prec)
    1489          21 : { pari_APPLY_same(RgC_gtomp(gel(x,i), prec)) }
    1490             : 
    1491             : INLINE GEN
    1492       10011 : RgX_fpnorml2(GEN x, long prec)
    1493             : {
    1494       10011 :   pari_sp av = avma;
    1495       10011 :   return gerepileupto(av, gnorml2(RgX_gtofp(x, prec)));
    1496             : }
    1497             : INLINE GEN
    1498      189862 : RgC_fpnorml2(GEN x, long prec)
    1499             : {
    1500      189862 :   pari_sp av = avma;
    1501      189862 :   return gerepileupto(av, gnorml2(RgC_gtofp(x, prec)));
    1502             : }
    1503             : INLINE GEN
    1504        4146 : RgM_fpnorml2(GEN x, long prec)
    1505             : {
    1506        4146 :   pari_sp av = avma;
    1507        4146 :   return gerepileupto(av, gnorml2(RgM_gtofp(x, prec)));
    1508             : }
    1509             : 
    1510             : /* y a t_REAL */
    1511             : INLINE void
    1512      216244 : affgr(GEN x, GEN y)
    1513             : {
    1514             :   pari_sp av;
    1515      216244 :   switch(typ(x)) {
    1516        5992 :     case t_INT:  affir(x,y); break;
    1517      210252 :     case t_REAL: affrr(x,y); break;
    1518           0 :     case t_FRAC: rdiviiz(gel(x,1),gel(x,2), y); break;
    1519           0 :     case t_QUAD: av = avma; affgr(quadtofp(x,realprec(y)), y); set_avma(av); break;
    1520           0 :     default: pari_err_TYPE2("=",x,y);
    1521             :   }
    1522      216244 : }
    1523             : 
    1524             : INLINE GEN
    1525      232495 : affc_fixlg(GEN x, GEN res)
    1526             : {
    1527      232495 :   if (typ(x) == t_COMPLEX)
    1528             :   {
    1529      207529 :     affrr_fixlg(gel(x,1), gel(res,1));
    1530      207529 :     affrr_fixlg(gel(x,2), gel(res,2));
    1531             :   }
    1532             :   else
    1533             :   {
    1534       24966 :     set_avma((pari_sp)(res+3));
    1535       24966 :     res = cgetr(realprec(gel(res,1)));
    1536       24966 :     affrr_fixlg(x, res);
    1537             :   }
    1538      232495 :   return res;
    1539             : }
    1540             : 
    1541             : INLINE GEN
    1542           0 : trunc_safe(GEN x) { long e; return gcvtoi(x,&e); }
    1543             : 
    1544             : /*******************************************************************/
    1545             : /*                                                                 */
    1546             : /*                          LENGTH CONVERSIONS                     */
    1547             : /*                                                                 */
    1548             : /*******************************************************************/
    1549             : INLINE long
    1550       32891 : ndec2nlong(long x) { return 1 + (long)((x)*(LOG2_10/BITS_IN_LONG)); }
    1551             : INLINE long
    1552       24403 : ndec2prec(long x) { return 2 + ndec2nlong(x); }
    1553             : INLINE long
    1554        8488 : ndec2nbits(long x) { return ndec2nlong(x) << TWOPOTBITS_IN_LONG; }
    1555             : /* Fast implementation of ceil(x / (8*sizeof(long))); typecast to (ulong)
    1556             :  * to avoid overflow. Faster than 1 + ((x-1)>>TWOPOTBITS_IN_LONG)) :
    1557             :  *   addl, shrl instead of subl, sarl, addl */
    1558             : INLINE long
    1559     1260692 : nbits2nlong(long x) {
    1560     1260692 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1561             : }
    1562             : 
    1563             : INLINE long
    1564   299525163 : nbits2extraprec(long x) {
    1565   299525163 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1566             : }
    1567             : 
    1568             : /* Fast implementation of 2 + nbits2nlong(x) */
    1569             : INLINE long
    1570   111375860 : nbits2prec(long x) {
    1571   111375860 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1572             : }
    1573             : INLINE long
    1574    21394868 : nbits2lg(long x) {
    1575    21394868 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1576             : }
    1577             : /* ceil(x / sizeof(long)) */
    1578             : INLINE long
    1579    15342836 : nchar2nlong(long x) {
    1580    15342836 :   return (long)(((ulong)x+sizeof(long)-1) >> (TWOPOTBITS_IN_LONG-3L));
    1581             : }
    1582             : INLINE long
    1583  1187309001 : prec2nbits(long x) { return (x-2) * BITS_IN_LONG; }
    1584             : INLINE double
    1585      520810 : bit_accuracy_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1586             : INLINE double
    1587      258700 : prec2nbits_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1588             : INLINE long
    1589    34476162 : bit_prec(GEN x) { return prec2nbits(realprec(x)); }
    1590             : INLINE long
    1591  1071288132 : bit_accuracy(long x) { return prec2nbits(x); }
    1592             : INLINE long
    1593       12476 : prec2ndec(long x) { return (long)prec2nbits_mul(x, LOG10_2); }
    1594             : INLINE long
    1595         200 : nbits2ndec(long x) { return (long)(x * LOG10_2); }
    1596             : INLINE long
    1597        3289 : precdbl(long x) {return (x - 1) << 1;}
    1598             : INLINE long
    1599  3529382241 : divsBIL(long n) { return n >> TWOPOTBITS_IN_LONG; }
    1600             : INLINE long
    1601  3483472197 : remsBIL(long n) { return n & (BITS_IN_LONG-1); }
    1602             : 
    1603             : /*********************************************************************/
    1604             : /**                                                                 **/
    1605             : /**                      OPERATIONS MODULO m                        **/
    1606             : /**                                                                 **/
    1607             : /*********************************************************************/
    1608             : /* Assume m > 0, more efficient if 0 <= a, b < m */
    1609             : 
    1610             : INLINE GEN
    1611    37866504 : Fp_red(GEN a, GEN m) { return modii(a, m); }
    1612             : INLINE GEN
    1613    93224906 : Fp_add(GEN a, GEN b, GEN m)
    1614             : {
    1615    93224906 :   pari_sp av=avma;
    1616    93224906 :   GEN p = addii(a,b);
    1617    91758580 :   long s = signe(p);
    1618    91758580 :   if (!s) return p; /* = gen_0 */
    1619    80496408 :   if (s > 0) /* general case */
    1620             :   {
    1621    80270038 :     GEN t = subii(p, m);
    1622    81273391 :     s = signe(t);
    1623    81273391 :     if (!s) { set_avma(av); return gen_0; }
    1624    72549540 :     if (s < 0) { set_avma((pari_sp)p); return p; }
    1625    30899420 :     if (cmpii(t, m) < 0) return gerepileuptoint(av, t); /* general case ! */
    1626     1115028 :     p = remii(t, m);
    1627             :   }
    1628             :   else
    1629      226370 :     p = modii(p, m);
    1630     1341398 :   return gerepileuptoint(av, p);
    1631             : }
    1632             : INLINE GEN
    1633    60539818 : Fp_sub(GEN a, GEN b, GEN m)
    1634             : {
    1635    60539818 :   pari_sp av=avma;
    1636    60539818 :   GEN p = subii(a,b);
    1637    59862471 :   long s = signe(p);
    1638    59862471 :   if (!s) return p; /* = gen_0 */
    1639    52215288 :   if (s > 0)
    1640             :   {
    1641    25228878 :     if (cmpii(p, m) < 0) return p; /* general case ! */
    1642     1123895 :     p = remii(p, m);
    1643             :   }
    1644             :   else
    1645             :   {
    1646    26986410 :     GEN t = addii(p, m);
    1647    26926364 :     if (!s) { set_avma(av); return gen_0; }
    1648    26926364 :     if (s > 0) return gerepileuptoint(av, t); /* general case ! */
    1649    26926364 :     p = modii(t, m);
    1650             :   }
    1651    28584647 :   return gerepileuptoint(av, p);
    1652             : }
    1653             : INLINE GEN
    1654    13675087 : Fp_neg(GEN b, GEN m)
    1655             : {
    1656    13675087 :   pari_sp av = avma;
    1657    13675087 :   long s = signe(b);
    1658             :   GEN p;
    1659    13675087 :   if (!s) return gen_0;
    1660    10173245 :   if (s > 0)
    1661             :   {
    1662     9972866 :     p = subii(m, b);
    1663     9969257 :     if (signe(p) >= 0) return p; /* general case ! */
    1664      104951 :     p = modii(p, m);
    1665             :   } else
    1666      200379 :     p = remii(negi(b), m);
    1667      305330 :   return gerepileuptoint(av, p);
    1668             : }
    1669             : 
    1670             : INLINE GEN
    1671       23613 : Fp_halve(GEN a, GEN p)
    1672             : {
    1673       23613 :   if (mpodd(a)) a = addii(a,p);
    1674       23613 :   return shifti(a,-1);
    1675             : }
    1676             : 
    1677             : /* assume 0 <= u < p and ps2 = p>>1 */
    1678             : INLINE GEN
    1679    22543704 : Fp_center(GEN u, GEN p, GEN ps2)
    1680    22543704 : { return abscmpii(u,ps2)<=0? icopy(u): subii(u,p); }
    1681             : /* same without copy */
    1682             : INLINE GEN
    1683    14772674 : Fp_center_i(GEN u, GEN p, GEN ps2)
    1684    14772674 : { return abscmpii(u,ps2)<=0? u: subii(u,p); }
    1685             : 
    1686             : /* x + y*z mod p */
    1687             : INLINE GEN
    1688     5938216 : Fp_addmul(GEN x, GEN y, GEN z, GEN p)
    1689             : {
    1690             :   pari_sp av;
    1691     5938216 :   if (!signe(y) || !signe(z)) return Fp_red(x, p);
    1692     5639916 :   if (!signe(x)) return Fp_mul(z,y, p);
    1693     5325461 :   av = avma;
    1694     5325461 :   return gerepileuptoint(av, modii(addii(x, mulii(y,z)), p));
    1695             : }
    1696             : 
    1697             : INLINE GEN
    1698    97059200 : Fp_mul(GEN a, GEN b, GEN m)
    1699             : {
    1700    97059200 :   pari_sp av=avma;
    1701             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1702    97059200 :   (void)new_chunk(lg(a)+lg(b)+(lg(m)<<1));
    1703    97061662 :   p = mulii(a,b);
    1704    97183442 :   set_avma(av); return modii(p,m);
    1705             : }
    1706             : INLINE GEN
    1707    34528642 : Fp_sqr(GEN a, GEN m)
    1708             : {
    1709    34528642 :   pari_sp av=avma;
    1710             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1711    34528642 :   (void)new_chunk((lg(a)+lg(m))<<1);
    1712    34507613 :   p = sqri(a);
    1713    31328803 :   set_avma(av); return remii(p,m); /*Use remii: p >= 0 */
    1714             : }
    1715             : INLINE GEN
    1716    68278754 : Fp_mulu(GEN a, ulong b, GEN m)
    1717             : {
    1718    68278754 :   long l = lgefint(m);
    1719    68278754 :   if (l == 3)
    1720             :   {
    1721    42183158 :     ulong mm = m[2];
    1722    42183158 :     return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1723             :   } else {
    1724    26095596 :     pari_sp av = avma;
    1725             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1726    26095596 :     (void)new_chunk(lg(a)+1+(l<<1));
    1727    26072441 :     p = muliu(a,b);
    1728    24438547 :     set_avma(av); return modii(p,m);
    1729             :   }
    1730             : }
    1731             : INLINE GEN
    1732           0 : Fp_muls(GEN a, long b, GEN m)
    1733             : {
    1734           0 :   long l = lgefint(m);
    1735           0 :   if (l == 3)
    1736             :   {
    1737           0 :     ulong mm = m[2];
    1738           0 :     if (b < 0)
    1739             :     {
    1740           0 :       ulong t = Fl_mul(umodiu(a, mm), -b, mm);
    1741           0 :       return t? utoipos(mm - t): gen_0;
    1742             :     }
    1743             :     else
    1744           0 :       return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1745             :   } else {
    1746           0 :     pari_sp av = avma;
    1747             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1748           0 :     (void)new_chunk(lg(a)+1+(l<<1));
    1749           0 :     p = mulis(a,b);
    1750           0 :     set_avma(av); return modii(p,m);
    1751             :   }
    1752             : }
    1753             : 
    1754             : INLINE GEN
    1755    10224111 : Fp_inv(GEN a, GEN m)
    1756             : {
    1757             :   GEN res;
    1758    10224111 :   if (! invmod(a,m,&res)) pari_err_INV("Fp_inv", mkintmod(res,m));
    1759    10223575 :   return res;
    1760             : }
    1761             : INLINE GEN
    1762      330150 : Fp_invsafe(GEN a, GEN m)
    1763             : {
    1764             :   GEN res;
    1765      330150 :   if (! invmod(a,m,&res)) return NULL;
    1766      330150 :   return res;
    1767             : }
    1768             : INLINE GEN
    1769     1721925 : Fp_div(GEN a, GEN b, GEN m)
    1770             : {
    1771     1721925 :   pari_sp av = avma;
    1772             :   GEN p;
    1773     1721925 :   if (lgefint(b) == 3)
    1774             :   {
    1775      734591 :     a = Fp_divu(a, b[2], m);
    1776      734591 :     if (signe(b) < 0) a = Fp_neg(a, m);
    1777      734591 :     return a;
    1778             :   }
    1779             :   /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1780      987334 :   (void)new_chunk(lg(a)+(lg(m)<<1));
    1781      987334 :   p = mulii(a, Fp_inv(b,m));
    1782      987334 :   set_avma(av); return modii(p,m);
    1783             : }
    1784             : INLINE GEN
    1785     1846193 : Fp_divu(GEN x, ulong a, GEN p)
    1786             : {
    1787     1846193 :   pari_sp av = avma;
    1788             :   ulong b;
    1789     1846193 :   if (lgefint(p) == 3)
    1790             :   {
    1791     1427842 :     ulong pp = p[2], xp = umodiu(x, pp);
    1792     1427842 :     return xp? utoipos(Fl_div(xp, a % pp, pp)): gen_0;
    1793             :   }
    1794      418351 :   x = Fp_red(x, p);
    1795      418351 :   b = Fl_neg(Fl_div(umodiu(x,a), umodiu(p,a), a), a); /* x + pb = 0 (mod a) */
    1796      418359 :   return gerepileuptoint(av, diviuexact(addmuliu(x, p, b), a));
    1797             : }
    1798             : 
    1799             : INLINE GEN
    1800      847844 : Flx_mulu(GEN x, ulong a, ulong p) { return Flx_Fl_mul(x,a%p,p); }
    1801             : 
    1802             : INLINE GEN
    1803     1833993 : get_F2x_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1804             : 
    1805             : INLINE long
    1806     2251715 : get_F2x_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1807             : 
    1808             : INLINE long
    1809     1901926 : get_F2x_degree(GEN T) { return typ(T)==t_VEC? F2x_degree(gel(T,2)): F2x_degree(T); }
    1810             : 
    1811             : INLINE GEN
    1812         399 : get_F2xqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1813             : 
    1814             : INLINE long
    1815      376761 : get_F2xqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1816             : 
    1817             : INLINE long
    1818      201845 : get_F2xqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1819             : 
    1820             : INLINE GEN
    1821     7708566 : get_Flx_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1822             : 
    1823             : INLINE long
    1824    20595214 : get_Flx_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1825             : 
    1826             : INLINE long
    1827    39271774 : get_Flx_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1828             : 
    1829             : INLINE GEN
    1830        2482 : get_FlxqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1831             : 
    1832             : INLINE long
    1833      222159 : get_FlxqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1834             : 
    1835             : INLINE long
    1836      277937 : get_FlxqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1837             : 
    1838             : INLINE GEN
    1839     1662413 : get_FpX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1840             : 
    1841             : INLINE long
    1842     4114479 : get_FpX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1843             : 
    1844             : INLINE long
    1845     2912193 : get_FpX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1846             : 
    1847             : INLINE GEN
    1848      142586 : get_FpXQX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1849             : 
    1850             : INLINE long
    1851       57495 : get_FpXQX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1852             : 
    1853             : INLINE long
    1854        2259 : get_FpXQX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1855             : 
    1856             : /*******************************************************************/
    1857             : /*                                                                 */
    1858             : /*                        ADDMULII / SUBMULII                      */
    1859             : /*                                                                 */
    1860             : /*******************************************************************/
    1861             : /* x - y*z */
    1862             : INLINE GEN
    1863      341046 : submulii(GEN x, GEN y, GEN z)
    1864             : {
    1865      341046 :   long lx = lgefint(x), ly, lz;
    1866             :   pari_sp av;
    1867             :   GEN t;
    1868      341046 :   if (lx == 2) { t = mulii(z,y); togglesign(t); return t; }
    1869      297169 :   ly = lgefint(y);
    1870      297169 :   if (ly == 2) return icopy(x);
    1871      250104 :   lz = lgefint(z);
    1872      250104 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1873      250104 :   t = mulii(z, y);
    1874      250104 :   set_avma(av); return subii(x,t);
    1875             : }
    1876             : /* y*z - x */
    1877             : INLINE GEN
    1878     1375295 : mulsubii(GEN y, GEN z, GEN x)
    1879             : {
    1880     1375295 :   long lx = lgefint(x), ly, lz;
    1881             :   pari_sp av;
    1882             :   GEN t;
    1883     1375295 :   if (lx == 2) return mulii(z,y);
    1884      862784 :   ly = lgefint(y);
    1885      862784 :   if (ly == 2) return negi(x);
    1886      790614 :   lz = lgefint(z);
    1887      790614 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1888      790614 :   t = mulii(z, y);
    1889      790614 :   set_avma(av); return subii(t,x);
    1890             : }
    1891             : 
    1892             : /* x - u*y */
    1893             : INLINE GEN
    1894        7595 : submuliu(GEN x, GEN y, ulong u)
    1895             : {
    1896             :   pari_sp av;
    1897        7595 :   long ly = lgefint(y);
    1898        7595 :   if (ly == 2) return icopy(x);
    1899        7595 :   av = avma;
    1900        7595 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1901        7595 :   y = mului(u,y);
    1902        7595 :   set_avma(av); return subii(x, y);
    1903             : }
    1904             : /* x + u*y */
    1905             : INLINE GEN
    1906      426315 : addmuliu(GEN x, GEN y, ulong u)
    1907             : {
    1908             :   pari_sp av;
    1909      426315 :   long ly = lgefint(y);
    1910      426315 :   if (ly == 2) return icopy(x);
    1911      426315 :   av = avma;
    1912      426315 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1913      426315 :   y = mului(u,y);
    1914      426309 :   set_avma(av); return addii(x, y);
    1915             : }
    1916             : /* x - u*y */
    1917             : INLINE GEN
    1918   126125667 : submuliu_inplace(GEN x, GEN y, ulong u)
    1919             : {
    1920             :   pari_sp av;
    1921   126125667 :   long ly = lgefint(y);
    1922   126125667 :   if (ly == 2) return x;
    1923   100922956 :   av = avma;
    1924   100922956 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1925   100922956 :   y = mului(u,y);
    1926   100922956 :   set_avma(av); return subii(x, y);
    1927             : }
    1928             : /* x + u*y */
    1929             : INLINE GEN
    1930   124481698 : addmuliu_inplace(GEN x, GEN y, ulong u)
    1931             : {
    1932             :   pari_sp av;
    1933   124481698 :   long ly = lgefint(y);
    1934   124481698 :   if (ly == 2) return x;
    1935   100751486 :   av = avma;
    1936   100751486 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1937   100751486 :   y = mului(u,y);
    1938   100751486 :   set_avma(av); return addii(x, y);
    1939             : }
    1940             : /* ux + vy */
    1941             : INLINE GEN
    1942    21945620 : lincombii(GEN u, GEN v, GEN x, GEN y)
    1943             : {
    1944    21945620 :   long lx = lgefint(x), ly;
    1945             :   GEN p1, p2;
    1946             :   pari_sp av;
    1947    21945620 :   if (lx == 2) return mulii(v,y);
    1948    15398875 :   ly = lgefint(y);
    1949    15398875 :   if (ly == 2) return mulii(u,x);
    1950    14122285 :   av = avma; (void)new_chunk(lx+ly+lgefint(u)+lgefint(v)); /* HACK */
    1951    14122291 :   p1 = mulii(u,x);
    1952    14122035 :   p2 = mulii(v,y);
    1953    14122018 :   set_avma(av); return addii(p1,p2);
    1954             : }
    1955             : 
    1956             : /*******************************************************************/
    1957             : /*                                                                 */
    1958             : /*                          GEN SUBTYPES                           */
    1959             : /*                                                                 */
    1960             : /*******************************************************************/
    1961             : 
    1962             : INLINE int
    1963  1268331648 : is_const_t(long t) { return (t < t_POLMOD); }
    1964             : INLINE int
    1965        6767 : is_extscalar_t(long t) { return (t <= t_POL); }
    1966             : INLINE int
    1967     1255945 : is_intreal_t(long t) { return (t <= t_REAL); }
    1968             : INLINE int
    1969   414487916 : is_matvec_t(long t) { return (t >= t_VEC && t <= t_MAT); }
    1970             : INLINE int
    1971    60474241 : is_noncalc_t(long tx) { return (tx) >= t_LIST; }
    1972             : INLINE int
    1973     1314105 : is_rational_t(long t) { return (t == t_INT || t == t_FRAC); }
    1974             : INLINE int
    1975      524702 : is_real_t(long t) { return (t == t_INT || t == t_REAL || t == t_FRAC); }
    1976             : INLINE int
    1977  3234785874 : is_recursive_t(long t) { return lontyp[t]; }
    1978             : INLINE int
    1979   173256669 : is_scalar_t(long t) { return (t < t_POL); }
    1980             : INLINE int
    1981     1545530 : is_vec_t(long t) { return (t == t_VEC || t == t_COL); }
    1982             : 
    1983             : /*******************************************************************/
    1984             : /*                                                                 */
    1985             : /*                         TRANSCENDENTAL                          */
    1986             : /*                                                                 */
    1987             : /*******************************************************************/
    1988             : INLINE GEN
    1989    21566226 : sqrtr(GEN x) {
    1990    21566226 :   long s = signe(x);
    1991    21566226 :   if (s == 0) return real_0_bit(expo(x) >> 1);
    1992    21532796 :   if (s >= 0) return sqrtr_abs(x);
    1993       38082 :   retmkcomplex(gen_0, sqrtr_abs(x));
    1994             : }
    1995             : INLINE GEN
    1996           0 : cbrtr_abs(GEN x) { return sqrtnr_abs(x, 3); }
    1997             : INLINE GEN
    1998           0 : cbrtr(GEN x) {
    1999           0 :   long s = signe(x);
    2000             :   GEN r;
    2001           0 :   if (s == 0) return real_0_bit(expo(x) / 3);
    2002           0 :   r = cbrtr_abs(x);
    2003           0 :   if (s < 0) togglesign(r);
    2004           0 :   return r;
    2005             : }
    2006             : INLINE GEN
    2007      469676 : sqrtnr(GEN x, long n) {
    2008      469676 :   long s = signe(x);
    2009             :   GEN r;
    2010      469676 :   if (s == 0) return real_0_bit(expo(x) / n);
    2011      469676 :   r = sqrtnr_abs(x, n);
    2012      469676 :   if (s < 0) pari_err_IMPL("sqrtnr for x < 0");
    2013      469676 :   return r;
    2014             : }
    2015             : INLINE long
    2016      229869 : logint(GEN B, GEN y) { return logintall(B,y,NULL); }
    2017             : INLINE ulong
    2018     2002442 : ulogint(ulong B, ulong y)
    2019             : {
    2020             :   ulong r;
    2021             :   long e;
    2022     2002442 :   if (y == 2) return expu(B);
    2023     1984298 :   r = y;
    2024     6404167 :   for (e=1;; e++)
    2025             :   { /* here, r = y^e, r2 = y^(e-1) */
    2026    10824036 :     if (r >= B) return r == B? e: e-1;
    2027     4419864 :     r = umuluu_or_0(y, r);
    2028     4419869 :     if (!r) return e;
    2029             :   }
    2030             : }
    2031             : 
    2032             : /*******************************************************************/
    2033             : /*                                                                 */
    2034             : /*                         MISCELLANEOUS                           */
    2035             : /*                                                                 */
    2036             : /*******************************************************************/
    2037     1255868 : INLINE int ismpzero(GEN x) { return is_intreal_t(typ(x)) && !signe(x); }
    2038   733527162 : INLINE int isintzero(GEN x) { return typ(x) == t_INT && !signe(x); }
    2039     5771386 : INLINE int isint1(GEN x) { return typ(x)==t_INT && equali1(x); }
    2040        4711 : INLINE int isintm1(GEN x){ return typ(x)==t_INT && equalim1(x);}
    2041   728939279 : INLINE int equali1(GEN n)
    2042   728939279 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(1)) && n[2] == 1; }
    2043    61468039 : INLINE int equalim1(GEN n)
    2044    61468039 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(-1)) && n[2] == 1; }
    2045             : /* works only for POSITIVE integers */
    2046  1067386546 : INLINE int is_pm1(GEN n)
    2047  1067386546 : { return lgefint(n) == 3 && n[2] == 1; }
    2048   244069548 : INLINE int is_bigint(GEN n)
    2049   244069548 : { long l = lgefint(n); return l > 3 || (l == 3 && (n[2] & HIGHBIT)); }
    2050             : 
    2051  2067880497 : INLINE int odd(long x) { return x & 1; }
    2052    29164685 : INLINE int both_odd(long x, long y) { return x & y & 1; }
    2053             : 
    2054             : INLINE int
    2055  2910271728 : isonstack(GEN x)
    2056  2910271728 : { return ((pari_sp)x >= pari_mainstack->bot
    2057  2910271728 :        && (pari_sp)x <  pari_mainstack->top); }
    2058             : 
    2059             : /* assume x != 0 and x t_REAL, return an approximation to log2(|x|) */
    2060             : INLINE double
    2061    22196788 : dbllog2r(GEN x)
    2062    22196788 : { return log2((double)(ulong)x[2]) + (double)(expo(x) - (BITS_IN_LONG-1)); }
    2063             : 
    2064             : INLINE GEN
    2065      402662 : mul_content(GEN cx, GEN cy)
    2066             : {
    2067      402662 :   if (!cx) return cy;
    2068      147631 :   if (!cy) return cx;
    2069      103417 :   return gmul(cx,cy);
    2070             : }
    2071             : INLINE GEN
    2072       11873 : inv_content(GEN c) { return c? ginv(c): NULL; }
    2073             : INLINE GEN
    2074     1820832 : mul_denom(GEN dx, GEN dy)
    2075             : {
    2076     1820832 :   if (!dx) return dy;
    2077     1219688 :   if (!dy) return dx;
    2078      385425 :   return mulii(dx,dy);
    2079             : }
    2080             : 
    2081             : /* POLYNOMIALS */
    2082             : INLINE GEN
    2083    17949649 : constant_coeff(GEN x) { return signe(x)? gel(x,2): gen_0; }
    2084             : INLINE GEN
    2085    84633101 : leading_coeff(GEN x) { return lg(x) == 2? gen_0: gel(x,lg(x)-1); }
    2086             : INLINE ulong
    2087      492299 : Flx_lead(GEN x) { return lg(x) == 2? 0: x[lg(x)-1]; }
    2088             : INLINE ulong
    2089       12252 : Flx_constant(GEN x) { return lg(x) == 2? 0: x[2]; }
    2090             : INLINE long
    2091  2930996907 : degpol(GEN x) { return lg(x)-3; }
    2092             : INLINE long
    2093  1472334339 : lgpol(GEN x) { return lg(x)-2; }
    2094             : INLINE long
    2095   136594742 : lgcols(GEN x) { return lg(gel(x,1)); }
    2096             : INLINE long
    2097    37751623 : nbrows(GEN x) { return lg(gel(x,1))-1; }
    2098             : INLINE GEN
    2099           0 : truecoef(GEN x, long n) { return polcoef(x,n,-1); }
    2100             : 
    2101             : INLINE GEN
    2102      574137 : ZXQ_mul(GEN y, GEN x, GEN T) { return ZX_rem(ZX_mul(y, x), T); }
    2103             : INLINE GEN
    2104      286540 : ZXQ_sqr(GEN x, GEN T) { return ZX_rem(ZX_sqr(x), T); }
    2105             : 
    2106             : INLINE GEN
    2107    95025802 : RgX_copy(GEN x)
    2108             : {
    2109             :   long lx, i;
    2110    95025802 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
    2111    95025799 :   for (i = 2; i<lx; i++) gel(y,i) = gcopy(gel(x,i));
    2112    95025802 :   return y;
    2113             : }
    2114             : /* have to use ulong to avoid silly warnings from gcc "assuming signed
    2115             :  * overflow does not occur" */
    2116             : INLINE GEN
    2117     2992004 : RgX_coeff(GEN x, long n)
    2118             : {
    2119     2992004 :   ulong l = lg(x);
    2120     2992004 :   return (n < 0 || ((ulong)n+3) > l)? gen_0: gel(x,n+2);
    2121             : }
    2122             : INLINE GEN
    2123      368623 : RgX_renormalize(GEN x) { return RgX_renormalize_lg(x, lg(x)); }
    2124             : INLINE GEN
    2125     6809344 : RgX_div(GEN x, GEN y) { return RgX_divrem(x,y,NULL); }
    2126             : INLINE GEN
    2127        1792 : RgXQX_div(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,NULL); }
    2128             : INLINE GEN
    2129       69600 : RgXQX_rem(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,ONLY_REM); }
    2130             : INLINE GEN
    2131     1039997 : FpX_div(GEN x, GEN y, GEN p) { return FpX_divrem(x,y,p, NULL); }
    2132             : INLINE GEN
    2133     5282505 : Flx_div(GEN x, GEN y, ulong p) { return Flx_divrem(x,y,p, NULL); }
    2134             : INLINE GEN
    2135      820057 : F2x_div(GEN x, GEN y) { return F2x_divrem(x,y, NULL); }
    2136             : INLINE GEN
    2137           0 : FpV_FpC_mul(GEN x, GEN y, GEN p) { return FpV_dotproduct(x,y,p); }
    2138             : INLINE GEN
    2139    50714644 : pol0_Flx(long sv) { return mkvecsmall(sv); }
    2140             : INLINE GEN
    2141    16097857 : pol1_Flx(long sv) { return mkvecsmall2(sv, 1); }
    2142             : INLINE GEN
    2143    18196051 : polx_Flx(long sv) { return mkvecsmall3(sv, 0, 1); }
    2144             : INLINE GEN
    2145           0 : zero_zx(long sv) { return zero_Flx(sv); }
    2146             : INLINE GEN
    2147           0 : polx_zx(long sv) { return polx_Flx(sv); }
    2148             : INLINE GEN
    2149           0 : zx_shift(GEN x, long n) { return Flx_shift(x,n); }
    2150             : INLINE GEN
    2151           0 : zx_renormalize(GEN x, long l) { return Flx_renormalize(x,l); }
    2152             : INLINE GEN
    2153        1341 : zero_F2x(long sv) { return zero_Flx(sv); }
    2154             : INLINE GEN
    2155    11194493 : pol0_F2x(long sv) { return pol0_Flx(sv); }
    2156             : INLINE GEN
    2157     2887871 : pol1_F2x(long sv) { return pol1_Flx(sv); }
    2158             : INLINE GEN
    2159      688446 : polx_F2x(long sv) { return mkvecsmall2(sv, 2); }
    2160             : INLINE int
    2161      846225 : F2x_equal1(GEN x) { return Flx_equal1(x); }
    2162             : INLINE int
    2163     3128857 : F2x_equal(GEN V, GEN W) { return Flx_equal(V,W); }
    2164             : INLINE GEN
    2165    54386270 : F2x_copy(GEN x) { return leafcopy(x); }
    2166             : INLINE GEN
    2167           0 : F2v_copy(GEN x) { return leafcopy(x); }
    2168             : INLINE GEN
    2169     2280397 : Flv_copy(GEN x) { return leafcopy(x); }
    2170             : INLINE GEN
    2171    86572736 : Flx_copy(GEN x) { return leafcopy(x); }
    2172             : INLINE GEN
    2173     1964710 : vecsmall_copy(GEN x) { return leafcopy(x); }
    2174             : INLINE int
    2175     4985853 : Flx_equal1(GEN x) { return degpol(x)==0 && x[2] == 1; }
    2176             : INLINE int
    2177       18233 : ZX_equal1(GEN x) { return degpol(x)==0 && equali1(gel(x,2)); }
    2178             : INLINE int
    2179     5549332 : ZX_is_monic(GEN x) { return equali1(leading_coeff(x)); }
    2180             : 
    2181             : INLINE GEN
    2182    53004560 : ZX_renormalize(GEN x, long lx)    { return ZXX_renormalize(x,lx); }
    2183             : INLINE GEN
    2184    74962595 : FpX_renormalize(GEN x, long lx)   { return ZXX_renormalize(x,lx); }
    2185             : INLINE GEN
    2186      789828 : FpXX_renormalize(GEN x, long lx)  { return ZXX_renormalize(x,lx); }
    2187             : INLINE GEN
    2188     1255760 : FpXQX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
    2189             : INLINE GEN
    2190   108528204 : F2x_renormalize(GEN x, long lx)   { return Flx_renormalize(x,lx); }
    2191             : INLINE GEN
    2192       32410 : F2v_to_F2x(GEN x, long sv) {
    2193       32410 :   GEN y = leafcopy(x);
    2194       32410 :   y[1] = sv; F2x_renormalize(y, lg(y)); return y;
    2195             : }
    2196             : 
    2197             : INLINE long
    2198           0 : sturm(GEN x) { return sturmpart(x, NULL, NULL); }
    2199             : 
    2200             : INLINE long
    2201        7168 : gval(GEN x, long v) {
    2202        7168 :   pari_sp av = avma;
    2203        7168 :   long n = gvaluation(x, pol_x(v));
    2204        7168 :   set_avma(av); return n;
    2205             : }
    2206             : 
    2207             : INLINE void
    2208      471452 : RgX_shift_inplace_init(long v)
    2209      471452 : { if (v) (void)cgetg(v, t_VECSMALL); }
    2210             : /* shift polynomial in place. assume v free cells have been left before x */
    2211             : INLINE GEN
    2212      471452 : RgX_shift_inplace(GEN x, long v)
    2213             : {
    2214             :   long i, lx;
    2215             :   GEN y, z;
    2216      471452 :   if (!v) return x;
    2217      253227 :   lx = lg(x);
    2218      253227 :   if (lx == 2) return x;
    2219      253227 :   y = x + v;
    2220      253227 :   z = x + lx;
    2221             :   /* stackdummy from normalizepol: move it up */
    2222      253227 :   if (lg(z) != v) x[lx + v] = z[0];
    2223      253227 :   for (i = lx-1; i >= 2; i--) gel(y,i) = gel(x,i);
    2224      253227 :   for (i = v+1;  i >= 2; i--) gel(x,i) = gen_0;
    2225             :   /* leave x[1] alone: it is correct */
    2226      253227 :   x[0] = evaltyp(t_POL) | evallg(lx+v); return x;
    2227             : }
    2228             : 
    2229             : 
    2230             : /* LINEAR ALGEBRA */
    2231             : INLINE GEN
    2232      133469 : zv_to_ZV(GEN x) { return vecsmall_to_vec(x); }
    2233             : INLINE GEN
    2234     5236031 : zc_to_ZC(GEN x) { return vecsmall_to_col(x); }
    2235             : INLINE GEN
    2236     3300778 : ZV_to_zv(GEN x) { return vec_to_vecsmall(x); }
    2237             : INLINE GEN
    2238           0 : zx_to_zv(GEN x, long N) { return Flx_to_Flv(x,N); }
    2239             : INLINE GEN
    2240           0 : zv_to_zx(GEN x, long sv) { return Flv_to_Flx(x,sv); }
    2241             : INLINE GEN
    2242           0 : zm_to_zxV(GEN x, long sv) { return Flm_to_FlxV(x,sv); }
    2243             : INLINE GEN
    2244           0 : zero_zm(long x, long y) { return zero_Flm(x,y); }
    2245             : INLINE GEN
    2246    17709775 : zero_zv(long x) { return zero_Flv(x); }
    2247             : INLINE GEN
    2248         238 : zm_transpose(GEN x) { return Flm_transpose(x); }
    2249             : INLINE GEN
    2250           0 : zm_copy(GEN x) { return Flm_copy(x); }
    2251             : INLINE GEN
    2252     1907156 : zv_copy(GEN x) { return Flv_copy(x); }
    2253             : INLINE GEN
    2254           0 : zm_row(GEN x, long i) { return Flm_row(x,i); }
    2255             : 
    2256             : INLINE GEN
    2257      981851 : ZC_hnfrem(GEN x, GEN y) { return ZC_hnfremdiv(x,y,NULL); }
    2258             : INLINE GEN
    2259       50350 : ZM_hnfrem(GEN x, GEN y) { return ZM_hnfdivrem(x,y,NULL); }
    2260             : INLINE GEN
    2261     2513335 : ZM_lll(GEN x, double D, long f) { return ZM_lll_norms(x,D,f,NULL); }
    2262             : INLINE void
    2263     6430214 : RgM_dimensions(GEN x, long *m, long *n) { *n = lg(x)-1; *m = *n? nbrows(x): 0; }
    2264             : INLINE GEN
    2265    10552950 : RgM_shallowcopy(GEN x)
    2266             : {
    2267             :   long l;
    2268    10552950 :   GEN y = cgetg_copy(x, &l);
    2269    10552970 :   while (--l > 0) gel(y,l) = leafcopy(gel(x,l));
    2270    10552959 :   return y;
    2271             : }
    2272             : INLINE GEN
    2273       20141 : F2m_copy(GEN x) { return RgM_shallowcopy(x); }
    2274             : 
    2275             : INLINE GEN
    2276     1546952 : Flm_copy(GEN x) { return RgM_shallowcopy(x); }
    2277             : 
    2278             : /* divisibility: return 1 if y[i] | x[i] for all i, 0 otherwise. Assume
    2279             :  * x,y are ZV of the same length */
    2280             : INLINE int
    2281       23198 : ZV_dvd(GEN x, GEN y)
    2282             : {
    2283       23198 :   long i, l = lg(x);
    2284       36652 :   for (i=1; i < l; i++)
    2285       29519 :     if ( ! dvdii( gel(x,i), gel(y,i) ) ) return 0;
    2286        7133 :   return 1;
    2287             : }
    2288             : 
    2289             : /* Fq */
    2290             : INLINE GEN
    2291     2508081 : Fq_red(GEN x, GEN T, GEN p)
    2292     2508081 : { return typ(x)==t_INT? Fp_red(x,p): FpXQ_red(x,T,p); }
    2293             : INLINE GEN
    2294       99511 : Fq_to_FpXQ(GEN x, GEN T, GEN p /*unused*/)
    2295             : {
    2296             :   (void) p;
    2297       99511 :   return typ(x)==t_INT ? scalarpol(x, get_FpX_var(T)): x;
    2298             : }
    2299             : INLINE GEN
    2300         756 : Rg_to_Fq(GEN x, GEN T, GEN p) { return T? Rg_to_FpXQ(x,T,p): Rg_to_Fp(x,p); }
    2301             : 
    2302             : INLINE GEN
    2303        2345 : gener_Fq_local(GEN T, GEN p, GEN L)
    2304             : { return T? gener_FpXQ_local(T,p, L)
    2305        2345 :           : pgener_Fp_local(p, L); }
    2306             : 
    2307             : /* FpXQX */
    2308             : INLINE GEN
    2309        4403 : FpXQX_div(GEN x, GEN y, GEN T, GEN p) { return FpXQX_divrem(x, y, T, p, NULL); }
    2310             : INLINE GEN
    2311       35235 : FlxqX_div(GEN x, GEN y, GEN T, ulong p) { return FlxqX_divrem(x, y, T, p, NULL); }
    2312             : INLINE GEN
    2313       33334 : F2xqX_div(GEN x, GEN y, GEN T) { return F2xqX_divrem(x, y, T, NULL); }
    2314             : 
    2315             : /* FqX */
    2316             : INLINE GEN
    2317       25452 : FqX_red(GEN z, GEN T, GEN p) { return T? FpXQX_red(z, T, p): FpX_red(z, p); }
    2318             : INLINE GEN
    2319      957187 : FqX_add(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2320             : INLINE GEN
    2321       17404 : FqX_neg(GEN x,GEN T,GEN p) { return T? FpXX_neg(x,p): FpX_neg(x,p); }
    2322             : INLINE GEN
    2323        3234 : FqX_sub(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2324             : INLINE GEN
    2325      668382 : FqX_Fp_mul(GEN P, GEN u, GEN T, GEN p)
    2326      668382 : { return T? FpXX_Fp_mul(P, u, p): FpX_Fp_mul(P, u, p); }
    2327             : INLINE GEN
    2328      588227 : FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p)
    2329      588227 : { return typ(U)==t_INT ? FqX_Fp_mul(P, U, T, p): FpXQX_FpXQ_mul(P, U, T, p); }
    2330             : INLINE GEN
    2331      100966 : FqX_mul(GEN x, GEN y, GEN T, GEN p)
    2332      100966 : { return T? FpXQX_mul(x, y, T, p): FpX_mul(x, y, p); }
    2333             : INLINE GEN
    2334      489744 : FqX_mulu(GEN x, ulong y, GEN T, GEN p)
    2335      489744 : { return T? FpXX_mulu(x, y, p): FpX_mulu(x, y, p); }
    2336             : INLINE GEN
    2337        6468 : FqX_sqr(GEN x, GEN T, GEN p)
    2338        6468 : { return T? FpXQX_sqr(x, T, p): FpX_sqr(x, p); }
    2339             : INLINE GEN
    2340        1288 : FqX_powu(GEN x, ulong n, GEN T, GEN p)
    2341        1288 : { return T? FpXQX_powu(x, n, T, p): FpX_powu(x, n, p); }
    2342             : INLINE GEN
    2343           0 : FqX_halve(GEN x, GEN T, GEN p)
    2344           0 : { return T? FpXX_halve(x, p): FpX_halve(x, p); }
    2345             : INLINE GEN
    2346        5964 : FqX_div(GEN x, GEN y, GEN T, GEN p)
    2347        5964 : { return T? FpXQX_divrem(x,y,T,p,NULL): FpX_divrem(x,y,p,NULL); }
    2348             : INLINE GEN
    2349        6095 : FqX_get_red(GEN S, GEN T, GEN p)
    2350        6095 : { return T? FpXQX_get_red(S,T,p): FpX_get_red(S,p); }
    2351             : INLINE GEN
    2352       53108 : FqX_rem(GEN x, GEN y, GEN T, GEN p)
    2353       53108 : { return T? FpXQX_rem(x,y,T,p): FpX_rem(x,y,p); }
    2354             : INLINE GEN
    2355           0 : FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2356           0 : { return T? FpXQX_divrem(x,y,T,p,z): FpX_divrem(x,y,p,z); }
    2357             : INLINE GEN
    2358        5936 : FqX_div_by_X_x(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2359        5936 : { return T? FpXQX_div_by_X_x(x,y,T,p,z): FpX_div_by_X_x(x,y,p,z); }
    2360             : INLINE GEN
    2361           0 : FqX_halfgcd(GEN P,GEN Q,GEN T,GEN p)
    2362           0 : {return T? FpXQX_halfgcd(P,Q,T,p): FpX_halfgcd(P,Q,p);}
    2363             : INLINE GEN
    2364      259833 : FqX_gcd(GEN P,GEN Q,GEN T,GEN p)
    2365      259833 : {return T? FpXQX_gcd(P,Q,T,p): FpX_gcd(P,Q,p);}
    2366             : INLINE GEN
    2367       94207 : FqX_extgcd(GEN P,GEN Q,GEN T,GEN p, GEN *U, GEN *V)
    2368       94207 : { return T? FpXQX_extgcd(P,Q,T,p,U,V): FpX_extgcd(P,Q,p,U,V); }
    2369             : INLINE GEN
    2370        3437 : FqX_normalize(GEN z, GEN T, GEN p)
    2371        3437 : { return T? FpXQX_normalize(z, T, p): FpX_normalize(z, p); }
    2372             : INLINE GEN
    2373      273175 : FqX_deriv(GEN f, GEN T, GEN p) { return T? FpXX_deriv(f, p): FpX_deriv(f, p); }
    2374             : INLINE GEN
    2375           0 : FqX_integ(GEN f, GEN T, GEN p) { return T? FpXX_integ(f, p): FpX_integ(f, p); }
    2376             : INLINE GEN
    2377       74837 : FqX_factor(GEN f, GEN T, GEN p)
    2378       74837 : { return T?FpXQX_factor(f, T, p): FpX_factor(f, p); }
    2379             : INLINE GEN
    2380           7 : FqX_factor_squarefree(GEN f, GEN T, GEN p)
    2381           7 : { return T ? FpXQX_factor_squarefree(f, T, p): FpX_factor_squarefree(f, p); }
    2382             : INLINE GEN
    2383           7 : FqX_ddf(GEN f, GEN T, GEN p)
    2384           7 : { return T ? FpXQX_ddf(f, T, p): FpX_ddf(f, p); }
    2385             : INLINE GEN
    2386          42 : FqX_degfact(GEN f, GEN T, GEN p)
    2387          42 : { return T?FpXQX_degfact(f, T, p): FpX_degfact(f, p); }
    2388             : INLINE GEN
    2389        7140 : FqX_roots(GEN f, GEN T, GEN p)
    2390        7140 : { return T?FpXQX_roots(f, T, p): FpX_roots(f, p); }
    2391             : INLINE GEN
    2392         203 : FqX_to_mod(GEN f, GEN T, GEN p)
    2393         203 : { return T?FpXQX_to_mod(f, T, p): FpX_to_mod(f, p); }
    2394             : 
    2395             : /*FqXQ*/
    2396             : INLINE GEN
    2397           0 : FqXQ_add(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2398           0 : { (void)S; return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2399             : INLINE GEN
    2400           0 : FqXQ_sub(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2401           0 : { (void)S; return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2402             : INLINE GEN
    2403           0 : FqXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p)
    2404           0 : { return T? FpXQXQ_div(x,y,S,T,p): FpXQ_div(x,y,S,p); }
    2405             : INLINE GEN
    2406           0 : FqXQ_inv(GEN x, GEN S, GEN T, GEN p)
    2407           0 : { return T? FpXQXQ_inv(x,S,T,p): FpXQ_inv(x,S,p); }
    2408             : INLINE GEN
    2409           0 : FqXQ_invsafe(GEN x, GEN S, GEN T, GEN p)
    2410           0 : { return T? FpXQXQ_invsafe(x,S,T,p): FpXQ_inv(x,S,p); }
    2411             : INLINE GEN
    2412       22348 : FqXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p)
    2413       22348 : { return T? FpXQXQ_mul(x,y,S,T,p): FpXQ_mul(x,y,S,p); }
    2414             : INLINE GEN
    2415           0 : FqXQ_sqr(GEN x, GEN S, GEN T, GEN p)
    2416           0 : { return T? FpXQXQ_sqr(x,S,T,p): FpXQ_sqr(x,S,p); }
    2417             : INLINE GEN
    2418           0 : FqXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p)
    2419           0 : { return T? FpXQXQ_pow(x,n,S,T,p): FpXQ_pow(x,n,S,p); }
    2420             : 
    2421             : /*FqXn*/
    2422             : INLINE GEN
    2423           0 : FqXn_exp(GEN x, long n, GEN T, GEN p)
    2424           0 : { return T? FpXQXn_exp(x,n,T,p): FpXn_exp(x,n,p); }
    2425             : INLINE GEN
    2426           0 : FqXn_inv(GEN x, long n, GEN T, GEN p)
    2427           0 : { return T? FpXQXn_inv(x,n,T,p): FpXn_inv(x,n,p); }
    2428             : INLINE GEN
    2429           0 : FqXn_mul(GEN x, GEN y, long n, GEN T, GEN p)
    2430           0 : { return T? FpXQXn_mul(x, y, n, T, p): FpXn_mul(x, y, n, p); }
    2431             : INLINE GEN
    2432           0 : FqXn_sqr(GEN x, long n, GEN T, GEN p)
    2433           0 : { return T? FpXQXn_sqr(x,n,T,p): FpXn_sqr(x,n,p); }
    2434             : 
    2435             : /*FpXQ*/
    2436             : INLINE GEN
    2437           0 : FpXQ_add(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2438           0 : { (void)T; return FpX_add(x,y,p); }
    2439             : INLINE GEN
    2440           0 : FpXQ_sub(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2441           0 : { (void)T; return FpX_sub(x,y,p); }
    2442             : 
    2443             : /*Flxq*/
    2444             : INLINE GEN
    2445           0 : Flxq_add(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2446           0 : { (void)T; return Flx_add(x,y,p); }
    2447             : INLINE GEN
    2448           0 : Flxq_sub(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2449           0 : { (void)T; return Flx_sub(x,y,p); }
    2450             : 
    2451             : /* F2x */
    2452             : 
    2453             : INLINE ulong
    2454   128342441 : F2x_coeff(GEN x,long v)
    2455             : {
    2456   128342441 :    ulong u=(ulong)x[2+divsBIL(v)];
    2457   128341038 :    return (u>>remsBIL(v))&1UL;
    2458             : }
    2459             : 
    2460             : INLINE void
    2461     5280159 : F2x_clear(GEN x,long v)
    2462             : {
    2463     5280159 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2464     5280157 :    *u&=~(1UL<<remsBIL(v));
    2465     5280158 : }
    2466             : 
    2467             : INLINE void
    2468    32972175 : F2x_set(GEN x,long v)
    2469             : {
    2470    32972175 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2471    32940861 :    *u|=1UL<<remsBIL(v);
    2472    32923251 : }
    2473             : 
    2474             : INLINE void
    2475     1502379 : F2x_flip(GEN x,long v)
    2476             : {
    2477     1502379 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2478     1502379 :    *u^=1UL<<remsBIL(v);
    2479     1502379 : }
    2480             : 
    2481             : /* F2v */
    2482             : 
    2483             : INLINE ulong
    2484   123693930 : F2v_coeff(GEN x,long v) { return F2x_coeff(x,v-1); }
    2485             : 
    2486             : INLINE void
    2487     5280159 : F2v_clear(GEN x,long v) { F2x_clear(x,v-1); }
    2488             : 
    2489             : INLINE void
    2490     9040392 : F2v_set(GEN x,long v)   { F2x_set(x,v-1); }
    2491             : 
    2492             : INLINE void
    2493     1502379 : F2v_flip(GEN x,long v) { F2x_flip(x,v-1); }
    2494             : 
    2495             : /* F2m */
    2496             : 
    2497             : INLINE ulong
    2498    11151521 : F2m_coeff(GEN x, long a, long b) { return F2v_coeff(gel(x,b), a); }
    2499             : 
    2500             : INLINE void
    2501           0 : F2m_clear(GEN x, long a, long b) { F2v_clear(gel(x,b), a); }
    2502             : 
    2503             : INLINE void
    2504     1900969 : F2m_set(GEN x, long a, long b) { F2v_set(gel(x,b), a); }
    2505             : 
    2506             : INLINE void
    2507     1502379 : F2m_flip(GEN x, long a, long b) { F2v_flip(gel(x,b), a); }
    2508             : 
    2509             : /* ARITHMETIC */
    2510             : INLINE GEN
    2511        1071 : matpascal(long n) { return matqpascal(n, NULL); }
    2512             : INLINE long
    2513     2334914 : Z_issquare(GEN x) { return Z_issquareall(x, NULL); }
    2514             : INLINE long
    2515          14 : Z_ispower(GEN x, ulong k) { return Z_ispowerall(x, k, NULL); }
    2516             : INLINE GEN
    2517     5803749 : sqrti(GEN x) { return sqrtremi(x,NULL); }
    2518             : INLINE GEN
    2519     5629444 : gaddgs(GEN y, long s) { return gaddsg(s,y); }
    2520             : INLINE int
    2521       72155 : gcmpgs(GEN y, long s) { return -gcmpsg(s,y); }
    2522             : INLINE int
    2523       24542 : gequalgs(GEN y, long s) { return gequalsg(s,y); }
    2524             : INLINE GEN
    2525           0 : gmaxsg(long s, GEN y) { return gmaxgs(y,s); }
    2526             : INLINE GEN
    2527           0 : gminsg(long s, GEN y) { return gmings(y,s); }
    2528             : INLINE GEN
    2529    15122191 : gmulgs(GEN y, long s) { return gmulsg(s,y); }
    2530             : INLINE GEN
    2531      934292 : gsubgs(GEN y, long s) { return gaddgs(y, -s); }
    2532             : INLINE GEN
    2533      681248 : gdivsg(long s, GEN y) { return gdiv(stoi(s), y); }
    2534             : 
    2535             : /* x t_COMPLEX */
    2536             : INLINE GEN
    2537    14132060 : cxnorm(GEN x) { return gadd(gsqr(gel(x,1)), gsqr(gel(x,2))); }
    2538             : /* q t_QUAD */
    2539             : INLINE GEN
    2540         966 : quadnorm(GEN q)
    2541             : {
    2542         966 :   GEN X = gel(q,1), b = gel(X,3), c = gel(X,2);
    2543         966 :   GEN z, u = gel(q,3), v = gel(q,2);
    2544         966 :   if (typ(u) == t_INT && typ(v) == t_INT) /* generic case */
    2545             :   {
    2546         651 :     z = signe(b)? mulii(v, addii(u,v)): sqri(v);
    2547         651 :     return addii(z, mulii(c, sqri(u)));
    2548             :   }
    2549             :   else
    2550             :   {
    2551         315 :     z = signe(b)? gmul(v, gadd(u,v)): gsqr(v);
    2552         315 :     return gadd(z, gmul(c, gsqr(u)));
    2553             :   }
    2554             : }
    2555             : /* x a t_QUAD, return the attached discriminant */
    2556             : INLINE GEN
    2557        1001 : quad_disc(GEN x)
    2558             : {
    2559        1001 :   GEN Q = gel(x,1), b = gel(Q,3), c = gel(Q,2), c4 = shifti(c,2);
    2560        1001 :   if (is_pm1(b)) return subsi(1, c4);
    2561         147 :   togglesign_safe(&c4); return c4;
    2562             : }
    2563             : INLINE GEN
    2564     6386709 : qfb_disc3(GEN x, GEN y, GEN z) { return subii(sqri(y), shifti(mulii(x,z),2)); }
    2565             : INLINE GEN
    2566     6305775 : qfb_disc(GEN x) { return qfb_disc3(gel(x,1), gel(x,2), gel(x,3)); }
    2567             : 
    2568             : INLINE GEN
    2569     1304093 : sqrfrac(GEN x)
    2570             : {
    2571     1304093 :   GEN z = cgetg(3,t_FRAC);
    2572     1304093 :   gel(z,1) = sqri(gel(x,1));
    2573     1304093 :   gel(z,2) = sqri(gel(x,2)); return z;
    2574             : }
    2575             : 
    2576             : INLINE void
    2577    32500645 : normalize_frac(GEN z) {
    2578    32500645 :   if (signe(gel(z,2)) < 0) { togglesign(gel(z,1)); setabssign(gel(z,2)); }
    2579    32500645 : }
    2580             : 
    2581             : INLINE GEN
    2582      271292 : powii(GEN x, GEN n)
    2583             : {
    2584      271292 :   long ln = lgefint(n);
    2585      271292 :   if (ln == 3) {
    2586             :     GEN z;
    2587      266875 :     if (signe(n) > 0) return powiu(x, n[2]);
    2588        8344 :     z = cgetg(3, t_FRAC);
    2589        8344 :     gel(z,1) = gen_1;
    2590        8344 :     gel(z,2) = powiu(x, n[2]);
    2591        8344 :     return z;
    2592             :   }
    2593        4417 :   if (ln == 2) return gen_1; /* rare */
    2594             :   /* should never happen */
    2595           0 :   return powgi(x, n); /* overflow unless x = 0, 1, -1 */
    2596             : }
    2597             : INLINE GEN
    2598        1337 : powIs(long n) {
    2599        1337 :   switch(n & 3)
    2600             :   {
    2601          63 :     case 1: return mkcomplex(gen_0,gen_1);
    2602         378 :     case 2: return gen_m1;
    2603         553 :     case 3: return mkcomplex(gen_0,gen_m1);
    2604             :   }
    2605         343 :   return gen_1;
    2606             : }
    2607             : 
    2608             : /*******************************************************************/
    2609             : /*                                                                 */
    2610             : /*                             ASSIGNMENTS                         */
    2611             : /*                                                                 */
    2612             : /*******************************************************************/
    2613           0 : INLINE void mpexpz(GEN x, GEN z)
    2614           0 : { pari_sp av = avma; gaffect(mpexp(x), z); set_avma(av); }
    2615           0 : INLINE void mplogz(GEN x, GEN z)
    2616           0 : { pari_sp av = avma; gaffect(mplog(x), z); set_avma(av); }
    2617           0 : INLINE void mpcosz(GEN x, GEN z)
    2618           0 : { pari_sp av = avma; gaffect(mpcos(x), z); set_avma(av); }
    2619           0 : INLINE void mpsinz(GEN x, GEN z)
    2620           0 : { pari_sp av = avma; gaffect(mpsin(x), z); set_avma(av); }
    2621           0 : INLINE void gnegz(GEN x, GEN z)
    2622           0 : { pari_sp av = avma; gaffect(gneg(x), z); set_avma(av); }
    2623           0 : INLINE void gabsz(GEN x, long prec, GEN z)
    2624           0 : { pari_sp av = avma; gaffect(gabs(x,prec), z); set_avma(av); }
    2625           0 : INLINE void gaddz(GEN x, GEN y, GEN z)
    2626           0 : { pari_sp av = avma; gaffect(gadd(x,y), z); set_avma(av); }
    2627           0 : INLINE void gsubz(GEN x, GEN y, GEN z)
    2628           0 : { pari_sp av = avma; gaffect(gsub(x,y), z); set_avma(av); }
    2629           0 : INLINE void gmulz(GEN x, GEN y, GEN z)
    2630           0 : { pari_sp av = avma; gaffect(gmul(x,y), z); set_avma(av); }
    2631           0 : INLINE void gdivz(GEN x, GEN y, GEN z)
    2632           0 : { pari_sp av = avma; gaffect(gdiv(x,y), z); set_avma(av); }
    2633           0 : INLINE void gdiventz(GEN x, GEN y, GEN z)
    2634           0 : { pari_sp av = avma; gaffect(gdivent(x,y), z); set_avma(av); }
    2635           0 : INLINE void gmodz(GEN x, GEN y, GEN z)
    2636           0 : { pari_sp av = avma; gaffect(gmod(x,y), z); set_avma(av); }
    2637           0 : INLINE void gmul2nz(GEN x, long s, GEN z)
    2638           0 : { pari_sp av = avma; gaffect(gmul2n(x,s), z); set_avma(av); }
    2639           0 : INLINE void gshiftz(GEN x, long s, GEN z)
    2640           0 : { pari_sp av = avma; gaffect(gshift(x,s), z); set_avma(av); }
    2641             : 
    2642             : /*******************************************************************/
    2643             : /*                                                                 */
    2644             : /*                       ELLIPTIC CURVES                           */
    2645             : /*                                                                 */
    2646             : /*******************************************************************/
    2647     3983147 : INLINE GEN ell_get_a1(GEN e) { return gel(e,1); }
    2648     3097806 : INLINE GEN ell_get_a2(GEN e) { return gel(e,2); }
    2649     3864855 : INLINE GEN ell_get_a3(GEN e) { return gel(e,3); }
    2650     3890745 : INLINE GEN ell_get_a4(GEN e) { return gel(e,4); }
    2651     4707414 : INLINE GEN ell_get_a6(GEN e) { return gel(e,5); }
    2652     3320951 : INLINE GEN ell_get_b2(GEN e) { return gel(e,6); }
    2653     1026050 : INLINE GEN ell_get_b4(GEN e) { return gel(e,7); }
    2654     1631991 : INLINE GEN ell_get_b6(GEN e) { return gel(e,8); }
    2655     1464631 : INLINE GEN ell_get_b8(GEN e) { return gel(e,9); }
    2656     6174014 : INLINE GEN ell_get_c4(GEN e) { return gel(e,10); }
    2657     7409353 : INLINE GEN ell_get_c6(GEN e) { return gel(e,11); }
    2658     9660937 : INLINE GEN ell_get_disc(GEN e) { return gel(e,12); }
    2659     1029581 : INLINE GEN ell_get_j(GEN e) { return gel(e,13); }
    2660    11462668 : INLINE long ell_get_type(GEN e) { return mael(e,14,1); }
    2661     1571762 : INLINE GEN ellff_get_field(GEN x) { return gmael(x, 15, 1); }
    2662      683473 : INLINE GEN ellff_get_a4a6(GEN x)  { return gmael(x, 15, 2); }
    2663        1407 : INLINE GEN ellQp_get_zero(GEN x) { return gmael(x, 15, 1); }
    2664         287 : INLINE long ellQp_get_prec(GEN E) { GEN z = ellQp_get_zero(E); return valp(z); }
    2665        1085 : INLINE GEN ellQp_get_p(GEN E) { GEN z = ellQp_get_zero(E); return gel(z,2); }
    2666       37296 : INLINE long ellR_get_prec(GEN x) { return nbits2prec(mael3(x, 15, 1, 1)); }
    2667       12656 : INLINE long ellR_get_sign(GEN x) { return mael3(x, 15, 1, 2); }
    2668      700956 : INLINE GEN ellnf_get_nf(GEN x) { return checknf_i(gmael(x,15,1)); }
    2669          56 : INLINE GEN ellnf_get_bnf(GEN x) { return checkbnf_i(gmael(x,15,1)); }
    2670             : 
    2671     4627515 : INLINE int checkell_i(GEN e) { return typ(e) == t_VEC && lg(e) == 17; }
    2672    33988936 : INLINE int ell_is_inf(GEN z) { return lg(z) == 2; }
    2673      810472 : INLINE GEN ellinf(void) { return mkvec(gen_0); }
    2674             : 
    2675             : /*******************************************************************/
    2676             : /*                                                                 */
    2677             : /*                    ALGEBRAIC NUMBER THEORY                      */
    2678             : /*                                                                 */
    2679             : /*******************************************************************/
    2680     8614002 : INLINE GEN modpr_get_pr(GEN x)  { return gel(x,3); }
    2681      610167 : INLINE GEN modpr_get_p(GEN x)  { return pr_get_p(modpr_get_pr(x)); }
    2682     2755117 : INLINE GEN modpr_get_T(GEN x)  { return lg(x) == 4? NULL: gel(x,4); }
    2683             : 
    2684    20829796 : INLINE GEN pr_get_p(GEN pr)  { return gel(pr,1); }
    2685     7088805 : INLINE GEN pr_get_gen(GEN pr){ return gel(pr,2); }
    2686             : /* .[2] instead of itos works: e and f are small positive integers */
    2687     2423054 : INLINE long pr_get_e(GEN pr) { return gel(pr,3)[2]; }
    2688     9800554 : INLINE long pr_get_f(GEN pr) { return gel(pr,4)[2]; }
    2689     6674798 : INLINE GEN pr_get_tau(GEN pr){ return gel(pr,5); }
    2690             : INLINE int
    2691     3340518 : pr_is_inert(GEN P) { return pr_get_f(P) == lg(pr_get_gen(P))-1; }
    2692             : INLINE GEN
    2693      243456 : pr_norm(GEN pr) { return powiu(pr_get_p(pr), pr_get_f(pr)); }
    2694             : INLINE ulong
    2695       48083 : upr_norm(GEN pr) { return upowuu(pr_get_p(pr)[2], pr_get_f(pr)); }
    2696             : 
    2697             : /* assume nf a genuine nf */
    2698             : INLINE long
    2699      395254 : nf_get_varn(GEN nf) { return varn(gel(nf,1)); }
    2700             : INLINE GEN
    2701    34549015 : nf_get_pol(GEN nf) { return gel(nf,1); }
    2702             : INLINE long
    2703    27521995 : nf_get_degree(GEN nf) { return degpol( nf_get_pol(nf) ); }
    2704             : INLINE long
    2705     4214979 : nf_get_r1(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,1)); }
    2706             : INLINE long
    2707        1680 : nf_get_r2(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,2)); }
    2708             : INLINE GEN
    2709       59504 : nf_get_disc(GEN nf) { return gel(nf,3); }
    2710             : INLINE GEN
    2711      882015 : nf_get_index(GEN nf) { return gel(nf,4); }
    2712             : INLINE GEN
    2713     2897491 : nf_get_M(GEN nf) { return gmael(nf,5,1); }
    2714             : INLINE GEN
    2715       87382 : nf_get_G(GEN nf) { return gmael(nf,5,2); }
    2716             : INLINE GEN
    2717      427447 : nf_get_roundG(GEN nf) { return gmael(nf,5,3); }
    2718             : INLINE GEN
    2719       24367 : nf_get_Tr(GEN nf) { return gmael(nf,5,4); }
    2720             : INLINE GEN
    2721        2324 : nf_get_diff(GEN nf) { return gmael(nf,5,5); }
    2722             : INLINE GEN
    2723        2079 : nf_get_ramified_primes(GEN nf) { return gmael(nf,5,8); }
    2724             : INLINE GEN
    2725      386315 : nf_get_roots(GEN nf) { return gel(nf,6); }
    2726             : INLINE GEN
    2727         112 : nf_get_zk(GEN nf)
    2728             : {
    2729         112 :   GEN y = gel(nf,7), D = gel(y, 1);
    2730         112 :   if (typ(D) == t_POL) D = gel(D, 2);
    2731         112 :   if (!equali1(D)) y = gdiv(y, D);
    2732         112 :   return y;
    2733             : }
    2734             : INLINE GEN
    2735      283677 : nf_get_zkprimpart(GEN nf)
    2736             : {
    2737      283677 :   GEN y = gel(nf,7);
    2738             :   /* test for old format of nf.zk: non normalized */
    2739      283677 :   if (!equali1(gel(nf,4)) && gequal1(gel(y,1))) y = Q_remove_denom(y,NULL);
    2740      283676 :   return y;
    2741             : }
    2742             : INLINE GEN
    2743      285020 : nf_get_zkden(GEN nf)
    2744             : {
    2745      285020 :   GEN y = gel(nf,7), D = gel(y,1);
    2746      285020 :   if (typ(D) == t_POL) D = gel(D,2);
    2747             :   /* test for old format of nf.zk: non normalized */
    2748      285020 :   if (!equali1(gel(nf,4)) && equali1(D)) D = Q_denom(y);
    2749      285018 :   return D;
    2750             : }
    2751             : INLINE GEN
    2752     2713072 : nf_get_invzk(GEN nf) { return gel(nf,8); }
    2753             : INLINE void
    2754       23855 : nf_get_sign(GEN nf, long *r1, long *r2)
    2755             : {
    2756       23855 :   GEN x = gel(nf,2);
    2757       23855 :   *r1 = itou(gel(x,1));
    2758       23855 :   *r2 = itou(gel(x,2));
    2759       23855 : }
    2760             : 
    2761             : INLINE GEN
    2762       95019 : abgrp_get_no(GEN x) { return gel(x,1); }
    2763             : INLINE GEN
    2764     2519257 : abgrp_get_cyc(GEN x) { return gel(x,2); }
    2765             : INLINE GEN
    2766      459896 : abgrp_get_gen(GEN x) { return gel(x,3); }
    2767             : INLINE GEN
    2768     2314438 : bnf_get_nf(GEN bnf) { return gel(bnf,7); }
    2769             : INLINE GEN
    2770      908935 : bnf_get_clgp(GEN bnf) { return gmael(bnf,8,1); }
    2771             : INLINE GEN
    2772        7112 : bnf_get_no(GEN bnf) { return abgrp_get_no(bnf_get_clgp(bnf)); }
    2773             : INLINE GEN
    2774      489639 : bnf_get_cyc(GEN bnf) { return abgrp_get_cyc(bnf_get_clgp(bnf)); }
    2775             : INLINE GEN
    2776      411855 : bnf_get_gen(GEN bnf)  { return abgrp_get_gen(bnf_get_clgp(bnf)); }
    2777             : INLINE GEN
    2778         846 : bnf_get_reg(GEN bnf) { return gmael(bnf,8,2); }
    2779             : INLINE GEN
    2780      511472 : bnf_get_logfu(GEN bnf) { return gel(bnf,3); }
    2781             : INLINE GEN
    2782        8835 : bnf_get_tuU(GEN bnf) { return gmael3(bnf,8,4,2); }
    2783             : INLINE long
    2784       41965 : bnf_get_tuN(GEN bnf) { return gmael3(bnf,8,4,1)[2]; }
    2785             : INLINE GEN
    2786        1778 : bnf_get_fu(GEN bnf) {
    2787        1778 :   GEN fu = bnf_get_fu_nocheck(bnf);
    2788        1778 :   if (typ(fu) == t_MAT) pari_err(e_MISC,"missing units in bnf");
    2789        1778 :   return fu;
    2790             : }
    2791             : INLINE GEN
    2792       10172 : bnf_get_fu_nocheck(GEN bnf) { return gmael(bnf,8,5); }
    2793             : 
    2794             : INLINE GEN
    2795      909263 : bnr_get_bnf(GEN bnr) { return gel(bnr,1); }
    2796             : INLINE GEN
    2797      465492 : bnr_get_bid(GEN bnr) { return gel(bnr,2); }
    2798             : INLINE GEN
    2799       20202 : bnr_get_mod(GEN bnr) { return gmael(bnr,2,1); }
    2800             : INLINE GEN
    2801       36897 : bnr_get_nf(GEN bnr) { return gmael(bnr,1,7); }
    2802             : INLINE GEN
    2803      712501 : bnr_get_clgp(GEN bnr) { return gel(bnr,5); }
    2804             : INLINE GEN
    2805       84140 : bnr_get_no(GEN bnr) { return abgrp_get_no(bnr_get_clgp(bnr)); }
    2806             : INLINE GEN
    2807      612065 : bnr_get_cyc(GEN bnr) { return abgrp_get_cyc(bnr_get_clgp(bnr)); }
    2808             : INLINE GEN
    2809          70 : bnr_get_gen_nocheck(GEN bnr) { return abgrp_get_gen(bnr_get_clgp(bnr)); }
    2810             : INLINE GEN
    2811       14931 : bnr_get_gen(GEN bnr) {
    2812       14931 :   GEN G = bnr_get_clgp(bnr);
    2813       14931 :   if (lg(G) !=  4)
    2814           0 :     pari_err(e_MISC,"missing bnr generators: please use bnrinit(,,1)");
    2815       14931 :   return gel(G,3);
    2816             : }
    2817             : 
    2818             : INLINE GEN
    2819      337966 : bid_get_mod(GEN bid) { return gel(bid,1); }
    2820             : INLINE GEN
    2821       68054 : bid_get_ideal(GEN bid) { return gmael(bid,1,1); }
    2822             : INLINE GEN
    2823        1260 : bid_get_arch(GEN bid) { return gmael(bid,1,2); }
    2824             : INLINE GEN
    2825     1275222 : bid_get_grp(GEN bid) { return gel(bid,2); }
    2826             : INLINE GEN
    2827      507254 : bid_get_fact(GEN bid) { return gmael(bid,3,1); }
    2828             : INLINE GEN
    2829      436960 : bid_get_fact2(GEN bid) { return gmael(bid,3,2); }
    2830             : INLINE GEN
    2831      436008 : bid_get_sprk(GEN bid) { return gmael(bid,4,1); }
    2832             : INLINE GEN
    2833       49189 : bid_get_sarch(GEN bid) { return gmael(bid,4,2); }
    2834             : INLINE GEN
    2835      472233 : bid_get_archp(GEN bid) { return gmael3(bid,4,2,2); }
    2836             : INLINE GEN
    2837      774205 : bid_get_U(GEN bid) { return gel(bid,5); }
    2838             : INLINE GEN
    2839           0 : bid_get_no(GEN bid) { return abgrp_get_no(bid_get_grp(bid)); }
    2840             : INLINE GEN
    2841     1228175 : bid_get_cyc(GEN bid) { return abgrp_get_cyc(bid_get_grp(bid)); }
    2842             : INLINE GEN
    2843           0 : bid_get_gen_nocheck(GEN bid)  { return abgrp_get_gen(bid_get_grp(bid)); }
    2844             : INLINE GEN
    2845       46452 : bid_get_gen(GEN bid) {
    2846       46452 :   GEN G = bid_get_grp(bid);
    2847       46452 :   if (lg(G) != 4) pari_err(e_MISC,"missing bid generators. Use idealstar(,,2)");
    2848       46452 :   return abgrp_get_gen(G);
    2849             : }
    2850             : 
    2851             : INLINE GEN
    2852    25974025 : znstar_get_N(GEN G) { return gmael(G,1,1); }
    2853             : INLINE GEN
    2854     2898560 : znstar_get_faN(GEN G) { return gel(G,3); }
    2855             : INLINE GEN
    2856           7 : znstar_get_no(GEN G) { return abgrp_get_no(gel(G,2)); }
    2857             : INLINE GEN
    2858      187957 : znstar_get_cyc(GEN G) { return abgrp_get_cyc(gel(G,2)); }
    2859             : INLINE GEN
    2860           7 : znstar_get_gen(GEN G) { return abgrp_get_gen(gel(G,2)); }
    2861             : INLINE GEN
    2862     3575320 : znstar_get_conreycyc(GEN G) { return gmael(G,4,5); }
    2863             : INLINE GEN
    2864     1232007 : znstar_get_conreygen(GEN G) { return gmael(G,4,4); }
    2865             : INLINE GEN
    2866       45927 : znstar_get_Ui(GEN G) { return gmael(G,4,3); }
    2867             : INLINE GEN
    2868      118237 : znstar_get_U(GEN G) { return gel(G,5); }
    2869             : INLINE GEN
    2870      837347 : znstar_get_pe(GEN G) { return gmael(G,4,1); }
    2871             : INLINE GEN
    2872       19950 : gal_get_pol(GEN gal) { return gel(gal,1); }
    2873             : INLINE GEN
    2874        1330 : gal_get_p(GEN gal) { return gmael(gal,2,1); }
    2875             : INLINE GEN
    2876          84 : gal_get_e(GEN gal) { return gmael(gal,2,2); }
    2877             : INLINE GEN
    2878       16009 : gal_get_mod(GEN gal) { return gmael(gal,2,3); }
    2879             : INLINE GEN
    2880       16387 : gal_get_roots(GEN gal) { return gel(gal,3); }
    2881             : INLINE GEN
    2882       15960 : gal_get_invvdm(GEN gal) { return gel(gal,4); }
    2883             : INLINE GEN
    2884       15960 : gal_get_den(GEN gal) { return gel(gal,5); }
    2885             : INLINE GEN
    2886       67153 : gal_get_group(GEN gal) { return gel(gal,6); }
    2887             : INLINE GEN
    2888        1743 : gal_get_gen(GEN gal) { return gel(gal,7); }
    2889             : INLINE GEN
    2890        1386 : gal_get_orders(GEN gal) { return gel(gal,8); }
    2891             : 
    2892             : /* assume rnf a genuine rnf */
    2893             : INLINE long
    2894     1233848 : rnf_get_degree(GEN rnf) { return degpol(rnf_get_pol(rnf)); }
    2895             : INLINE long
    2896       16681 : rnf_get_nfdegree(GEN rnf) { return degpol(nf_get_pol(rnf_get_nf(rnf))); }
    2897             : INLINE long
    2898      775698 : rnf_get_absdegree(GEN rnf) { return degpol(gmael(rnf,11,1)); }
    2899             : INLINE GEN
    2900         700 : rnf_get_idealdisc(GEN rnf) { return gmael(rnf,3,1); }
    2901             : INLINE GEN
    2902         742 : rnf_get_k(GEN rnf) { return gmael(rnf,11,3); }
    2903             : INLINE GEN
    2904         798 : rnf_get_alpha(GEN rnf) { return gmael(rnf, 11, 2); }
    2905             : INLINE GEN
    2906      430360 : rnf_get_nf(GEN rnf) { return gel(rnf,10); }
    2907             : INLINE GEN
    2908        3808 : rnf_get_nfzk(GEN rnf) { return gel(rnf,2); }
    2909             : INLINE GEN
    2910      215152 : rnf_get_polabs(GEN rnf) { return gmael(rnf,11,1); }
    2911             : INLINE GEN
    2912     1480059 : rnf_get_pol(GEN rnf) { return gel(rnf,1); }
    2913             : INLINE GEN
    2914         175 : rnf_get_disc(GEN rnf) { return gel(rnf,3); }
    2915             : INLINE GEN
    2916         105 : rnf_get_index(GEN rnf) { return gel(rnf,4); }
    2917             : INLINE GEN
    2918        1561 : rnf_get_ramified_primes(GEN rnf) { return gel(rnf,5); }
    2919             : INLINE long
    2920           0 : rnf_get_varn(GEN rnf) { return varn(gel(rnf,1)); }
    2921             : INLINE GEN
    2922      188580 : rnf_get_nfpol(GEN rnf) { return gmael(rnf,10,1); }
    2923             : INLINE long
    2924        3325 : rnf_get_nfvarn(GEN rnf) { return varn(gmael(rnf,10,1)); }
    2925             : INLINE GEN
    2926        3500 : rnf_get_zk(GEN rnf) { return gel(rnf,7); }
    2927             : INLINE GEN
    2928       97335 : rnf_get_map(GEN rnf) { return gel(rnf,11); }
    2929             : INLINE GEN
    2930        1197 : rnf_get_invzk(GEN rnf) { return gel(rnf,8); }
    2931             : 
    2932             : /* I integral ZM (not HNF), G ZM, rounded Cholesky form of a weighted
    2933             :  * T2 matrix. Reduce I wrt G */
    2934             : INLINE GEN
    2935       21973 : idealpseudored(GEN I, GEN G)
    2936       21973 : { return ZM_mul(I, ZM_lll(ZM_mul(G, I), 0.99, LLL_IM)); }
    2937             : 
    2938             : /* I integral (not necessarily HNF), G ZM, rounded Cholesky form of a weighted
    2939             :  * T2 matrix. Return m in I with T2(m) small */
    2940             : INLINE GEN
    2941      146067 : idealpseudomin(GEN I, GEN G)
    2942             : {
    2943      146067 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2944      146067 :   return ZM_ZC_mul(I, gel(u,1));
    2945             : }
    2946             : /* I, G as in idealpseudomin. Return an irrational m in I with T2(m) small */
    2947             : INLINE GEN
    2948      315222 : idealpseudomin_nonscalar(GEN I, GEN G)
    2949             : {
    2950      315222 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2951      315222 :   GEN m = ZM_ZC_mul(I, gel(u,1));
    2952      315222 :   if (ZV_isscalar(m) && lg(u) > 2) m = ZM_ZC_mul(I, gel(u,2));
    2953      315222 :   return m;
    2954             : }
    2955             : 
    2956             : INLINE GEN
    2957         938 : idealred_elt(GEN nf, GEN I) {
    2958         938 :   pari_sp av = avma;
    2959         938 :   GEN u = idealpseudomin(I, nf_get_roundG(nf));
    2960         938 :   return gerepileupto(av, u);
    2961             : }
    2962             : INLINE GEN
    2963      128023 : idealred(GEN nf, GEN I) { return idealred0(nf, I, NULL); }
    2964             : 
    2965             : INLINE GEN
    2966        2058 : idealchineseinit(GEN nf, GEN x)
    2967        2058 : { return idealchinese(nf,x,NULL); }
    2968             : 
    2969             : /*******************************************************************/
    2970             : /*                                                                 */
    2971             : /*                              CLOSURES                           */
    2972             : /*                                                                 */
    2973             : /*******************************************************************/
    2974   232341337 : INLINE long closure_arity(GEN C)          { return ((ulong)C[1])&ARITYBITS; }
    2975    35703129 : INLINE long closure_is_variadic(GEN C) { return !!(((ulong)C[1])&VARARGBITS); }
    2976   193067065 : INLINE const char *closure_codestr(GEN C)  { return GSTR(gel(C,2))-1; }
    2977           0 : INLINE GEN closure_get_code(GEN C)  { return gel(C,2); }
    2978   193045679 : INLINE GEN closure_get_oper(GEN C)  { return gel(C,3); }
    2979   193028341 : INLINE GEN closure_get_data(GEN C)  { return gel(C,4); }
    2980        9922 : INLINE GEN closure_get_dbg(GEN C)   { return gel(C,5); }
    2981       23806 : INLINE GEN closure_get_text(GEN C)  { return gel(C,6); }
    2982     4691808 : INLINE GEN closure_get_frame(GEN C) { return gel(C,7); }
    2983             : 
    2984             : /*******************************************************************/
    2985             : /*                                                                 */
    2986             : /*                               ERRORS                            */
    2987             : /*                                                                 */
    2988             : /*******************************************************************/
    2989             : INLINE long
    2990       53592 : err_get_num(GEN e) { return e[1]; }
    2991             : INLINE GEN
    2992         105 : err_get_compo(GEN e, long i) { return gel(e, i+1); }
    2993             : 
    2994             : INLINE void
    2995          14 : pari_err_BUG(const char *f) { pari_err(e_BUG,f); }
    2996             : INLINE void
    2997           7 : pari_err_CONSTPOL(const char *f) { pari_err(e_CONSTPOL, f); }
    2998             : INLINE void
    2999          63 : pari_err_COPRIME(const char *f, GEN x, GEN y) { pari_err(e_COPRIME, f,x,y); }
    3000             : INLINE void
    3001         494 : pari_err_DIM(const char *f) { pari_err(e_DIM, f); }
    3002             : INLINE void
    3003           0 : pari_err_FILE(const char *f, const char *g) { pari_err(e_FILE, f,g); }
    3004             : INLINE void
    3005           0 : pari_err_FILEDESC(const char *f, long n) { pari_err(e_FILEDESC, f,n); }
    3006             : INLINE void
    3007          77 : pari_err_FLAG(const char *f) { pari_err(e_FLAG,f); }
    3008             : INLINE void
    3009         434 : pari_err_IMPL(const char *f) { pari_err(e_IMPL,f); }
    3010             : INLINE void
    3011       19751 : pari_err_INV(const char *f, GEN x) { pari_err(e_INV,f,x); }
    3012             : INLINE void
    3013          42 : pari_err_IRREDPOL(const char *f, GEN x) { pari_err(e_IRREDPOL, f,x); }
    3014             : INLINE void
    3015        2113 : pari_err_DOMAIN(const char *f, const char *v, const char *op, GEN l, GEN x) { pari_err(e_DOMAIN, f,v,op,l,x); }
    3016             : INLINE void
    3017         200 : pari_err_COMPONENT(const char *f, const char *op, GEN l, GEN x) { pari_err(e_COMPONENT, f,op,l,x); }
    3018             : INLINE void
    3019           0 : pari_err_MAXPRIME(ulong c) { pari_err(e_MAXPRIME, c); }
    3020             : INLINE void
    3021         364 : pari_err_OP(const char *f, GEN x, GEN y) { pari_err(e_OP, f,x,y); }
    3022             : INLINE void
    3023         100 : pari_err_OVERFLOW(const char *f) { pari_err(e_OVERFLOW, f); }
    3024             : INLINE void
    3025         225 : pari_err_PREC(const char *f) { pari_err(e_PREC,f); }
    3026             : INLINE void
    3027           0 : pari_err_PACKAGE(const char *f) { pari_err(e_PACKAGE,f); }
    3028             : INLINE void
    3029          70 : pari_err_PRIME(const char *f, GEN x) { pari_err(e_PRIME, f,x); }
    3030             : INLINE void
    3031         749 : pari_err_MODULUS(const char *f, GEN x, GEN y) { pari_err(e_MODULUS, f,x,y); }
    3032             : INLINE void
    3033          49 : pari_err_ROOTS0(const char *f) { pari_err(e_ROOTS0, f); }
    3034             : INLINE void
    3035          84 : pari_err_SQRTN(const char *f, GEN x) { pari_err(e_SQRTN, f,x); }
    3036             : INLINE void
    3037       12741 : pari_err_TYPE(const char *f, GEN x) { pari_err(e_TYPE, f,x); }
    3038             : INLINE void
    3039        3381 : pari_err_TYPE2(const char *f, GEN x, GEN y) { pari_err(e_TYPE2, f,x,y); }
    3040             : INLINE void
    3041         280 : pari_err_VAR(const char *f, GEN x, GEN y) { pari_err(e_VAR, f,x,y); }
    3042             : INLINE void
    3043         196 : pari_err_PRIORITY(const char *f, GEN x, const char *op, long v)
    3044         196 : { pari_err(e_PRIORITY, f,x,op,v); }

Generated by: LCOV version 1.13