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.0 lcov report (development 23690-5d6e28857) Lines: 1295 1463 88.5 %
Date: 2019-03-18 05:43:21 Functions: 569 646 88.1 %
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     3154178 : mkintmod(GEN x, GEN y) { retmkintmod(x,y); }
     141             : INLINE GEN
     142        4760 : mkintmodu(ulong x, ulong y) {
     143        4760 :   GEN v = cgetg(3,t_INTMOD);
     144        4760 :   gel(v,1) = utoipos(y);
     145        4760 :   gel(v,2) = utoi(x); return v;
     146             : }
     147             : INLINE GEN
     148     2954007 : mkpolmod(GEN x, GEN y) { retmkpolmod(x,y); }
     149             : INLINE GEN
     150    23323038 : mkfrac(GEN x, GEN y) { retmkfrac(x,y); }
     151             : INLINE GEN
     152       32137 : 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       12488 : Qtoss(GEN q, long *n, long *d)
     156             : {
     157       12488 :   if (typ(q) == t_INT) { *n = itos(q); *d = 1; }
     158        2443 :   else { *n = itos(gel(q,1)); *d = itou(gel(q,2)); }
     159       12488 : }
     160             : INLINE GEN
     161    71382264 : sstoQ(long n, long d)
     162             : {
     163             :   ulong r;
     164             :   long g, q;
     165    71382264 :   if (!n)
     166             :   {
     167       98644 :     if (!d) pari_err_INV("sstoQ",gen_0);
     168       98644 :     return gen_0;
     169             :   }
     170    71283620 :   if (d < 0) { d = -d; n = -n; }
     171    71283620 :   if (d == 1) return stoi(n);
     172    71271629 :   q = udivuu_rem(labs(n),d,&r);
     173    71271629 :   if (!r) return n > 0? utoipos(q): utoineg(q);
     174     3642228 :   g = ugcd(d,r); /* gcd(n,d) */
     175     3642228 :   if (g != 1) { n /= g; d /= g; }
     176     3642228 :   retmkfrac(stoi(n), utoi(d));
     177             : }
     178             : 
     179             : INLINE GEN
     180    15980770 : 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    10335686 : mkcomplex(GEN x, GEN y) { retmkcomplex(x,y); }
     189             : INLINE GEN
     190      450883 : gen_I(void) { return mkcomplex(gen_0, gen_1); }
     191             : INLINE GEN
     192      298779 : 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    71316380 : mkvecsmall(long x) { GEN v = cgetg(2, t_VECSMALL); v[1] = x; return v; }
     199             : INLINE GEN
     200   114650947 : mkvecsmall2(long x,long y) { GEN v = cgetg(3, t_VECSMALL);
     201   114624525 :   v[1]=x; v[2]=y; return v; }
     202             : INLINE GEN
     203    58426424 : mkvecsmall3(long x,long y,long z) { GEN v = cgetg(4, t_VECSMALL);
     204    58417445 :   v[1]=x; v[2]=y; v[3]=z; return v; }
     205             : INLINE GEN
     206    11930058 : mkvecsmall4(long x,long y,long z,long t) { GEN v = cgetg(5, t_VECSMALL);
     207    11898763 :   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      466833 :   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    15112006 : mkvec(GEN x) { retmkvec(x); }
     217             : INLINE GEN
     218   102484895 : mkvec2(GEN x, GEN y) { retmkvec2(x,y); }
     219             : INLINE GEN
     220    78690108 : mkvec3(GEN x, GEN y, GEN z) { retmkvec3(x,y,z); }
     221             : INLINE GEN
     222     7275657 : mkvec4(GEN x, GEN y, GEN z, GEN t) { retmkvec4(x,y,z,t); }
     223             : INLINE GEN
     224    12164467 : mkvec5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkvec5(x,y,z,t,u); }
     225             : INLINE GEN
     226          84 : mkvecs(long x) { retmkvec(stoi(x)); }
     227             : INLINE GEN
     228       23798 : 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      100200 : mkvec2copy(GEN x, GEN y) {
     237      100200 :   GEN v = cgetg(3,t_VEC); gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     238             : /* col */
     239             : INLINE GEN
     240     2545440 : mkcol(GEN x) { retmkcol(x); }
     241             : INLINE GEN
     242    25662484 : 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        8716 : 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     2179632 : 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       52717 : mkcolcopy(GEN x) { GEN v = cgetg(2, t_COL); gel(v,1) = gcopy(x); return v; }
     261             : /* mat */
     262             : INLINE GEN
     263     2558746 : mkmat(GEN x) { retmkmat(x); }
     264             : INLINE GEN
     265    32221036 : 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       23944 : 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       97378 : mkoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_1; return v; }
     278             : INLINE GEN
     279       17871 : mkmoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_m1; return v; }
     280             : INLINE long
     281      135091 : inf_get_sign(GEN x) { return signe(gel(x,1)); }
     282             : INLINE GEN
     283       12404 : mkmat22s(long a, long b, long c, long d) {retmkmat2(mkcol2s(a,c),mkcol2s(b,d));}
     284             : INLINE GEN
     285     1533098 : mkmat22(GEN a, GEN b, GEN c, GEN d) { retmkmat2(mkcol2(a,c),mkcol2(b,d)); }
     286             : 
     287             : /* pol */
     288             : INLINE GEN
     289     1007715 : pol_x(long v) {
     290     1007715 :   GEN p = cgetg(4, t_POL);
     291     1007714 :   p[1] = evalsigne(1)|evalvarn(v);
     292     1007714 :   gel(p,2) = gen_0;
     293     1007714 :   gel(p,3) = gen_1; return p;
     294             : }
     295             : /* x^n, assume n >= 0 */
     296             : INLINE GEN
     297     8779182 : pol_xn(long n, long v) {
     298     8779182 :   long i, a = n+2;
     299     8779182 :   GEN p = cgetg(a+1, t_POL);
     300     8779182 :   p[1] = evalsigne(1)|evalvarn(v);
     301     8779182 :   for (i = 2; i < a; i++) gel(p,i) = gen_0;
     302     8779182 :   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     1445556 : pol_1(long v) {
     313     1445556 :   GEN p = cgetg(3, t_POL);
     314     1445554 :   p[1] = evalsigne(1)|evalvarn(v);
     315     1445554 :   gel(p,2) = gen_1; return p;
     316             : }
     317             : INLINE GEN
     318    32620845 : pol_0(long v)
     319             : {
     320    32620845 :   GEN x = cgetg(2,t_POL);
     321    32620845 :   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     9081410 : 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     8688467 : const_col(long n, GEN x) { retconst_col(n, x); }
     337             : INLINE GEN
     338     8762106 : const_vecsmall(long n, long c)
     339             : {
     340             :   long i;
     341     8762106 :   GEN V = cgetg(n+1,t_VECSMALL);
     342     8762306 :   for(i=1;i<=n;i++) V[i] = c;
     343     8762306 :   return V;
     344             : }
     345             : 
     346             : /***   ZERO   ***/
     347             : /* O(p^e) */
     348             : INLINE GEN
     349      363703 : zeropadic(GEN p, long e)
     350             : {
     351      363703 :   GEN y = cgetg(5,t_PADIC);
     352      363703 :   gel(y,4) = gen_0;
     353      363703 :   gel(y,3) = gen_1;
     354      363703 :   gel(y,2) = icopy(p);
     355      363703 :   y[1] = evalvalp(e) | _evalprecp(0);
     356      363703 :   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      143920 : zeroser(long v, long e)
     371             : {
     372      143920 :   GEN x = cgetg(2, t_SER);
     373      143920 :   x[1] = evalvalp(e) | evalvarn(v); return x;
     374             : }
     375             : INLINE int
     376     5751691 : ser_isexactzero(GEN x)
     377             : {
     378     5751691 :   if (!signe(x)) switch(lg(x))
     379             :   {
     380      136423 :     case 2: return 1;
     381         854 :     case 3: return isexactzero(gel(x,2));
     382             :   }
     383     5614414 :   return 0;
     384             : }
     385             : /* 0 * pol_x(v) */
     386             : INLINE GEN
     387    15549433 : zeropol(long v) { return pol_0(v); }
     388             : /* vector(n) */
     389             : INLINE GEN
     390    37565003 : zerocol(long n)
     391             : {
     392    37565003 :   GEN y = cgetg(n+1,t_COL);
     393    37565244 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     394    37565244 :   return y;
     395             : }
     396             : /* vectorv(n) */
     397             : INLINE GEN
     398    21848963 : zerovec(long n)
     399             : {
     400    21848963 :   GEN y = cgetg(n+1,t_VEC);
     401    21848966 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     402    21848966 :   return y;
     403             : }
     404             : /* matrix(m, n) */
     405             : INLINE GEN
     406       23870 : zeromat(long m, long n)
     407             : {
     408       23870 :   GEN y = cgetg(n+1,t_MAT);
     409       23870 :   GEN v = zerocol(m);
     410       23870 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     411       23870 :   return y;
     412             : }
     413             : /* = zero_zx, sv is a evalvarn()*/
     414             : INLINE GEN
     415      930116 : zero_Flx(long sv) { return pol0_Flx(sv); }
     416             : INLINE GEN
     417    34073695 : zero_Flv(long n)
     418             : {
     419    34073695 :   GEN y = cgetg(n+1,t_VECSMALL);
     420    34074920 :   long i; for (i=1; i<=n; i++) y[i] = 0;
     421    34074920 :   return y;
     422             : }
     423             : /* matrix(m, n) */
     424             : INLINE GEN
     425      981502 : zero_Flm(long m, long n)
     426             : {
     427      981502 :   GEN y = cgetg(n+1,t_MAT);
     428      981480 :   GEN v = zero_Flv(m);
     429      981474 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     430      981474 :   return y;
     431             : }
     432             : /* matrix(m, n) */
     433             : INLINE GEN
     434      111474 : zero_Flm_copy(long m, long n)
     435             : {
     436      111474 :   GEN y = cgetg(n+1,t_MAT);
     437      111465 :   long i; for (i=1; i<=n; i++) gel(y,i) = zero_Flv(m);
     438      111486 :   return y;
     439             : }
     440             : 
     441             : INLINE GEN
     442      869490 : zero_F2v(long m)
     443             : {
     444      869490 :   long l = nbits2nlong(m);
     445      869490 :   GEN v  = zero_Flv(l+1);
     446      869490 :   v[1] = m;
     447      869490 :   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      299723 : zero_F2m_copy(long m, long n)
     464             : {
     465             :   long i;
     466      299723 :   GEN M = cgetg(n+1, t_MAT);
     467      889191 :   for (i = 1; i <= n; i++)
     468      589468 :     gel(M,i)= zero_F2v(m);
     469      299723 :   return M;
     470             : }
     471             : 
     472             : /* matrix(m, n) */
     473             : INLINE GEN
     474     4907139 : zeromatcopy(long m, long n)
     475             : {
     476     4907139 :   GEN y = cgetg(n+1,t_MAT);
     477     4907139 :   long i; for (i=1; i<=n; i++) gel(y,i) = zerocol(m);
     478     4907139 :   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     1501645 : col_ei(long n, long i) { GEN e = zerocol(n); gel(e,i) = gen_1; return e; }
     494             : INLINE GEN
     495      349357 : 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       75103 : vecsmall_ei(long n, long i) { GEN e = zero_zv(n); e[i] = 1; return e; }
     500             : INLINE GEN
     501      707827 : Rg_col_ei(GEN x, long n, long i) { GEN e = zerocol(n); gel(e,i) = x; return e; }
     502             : 
     503             : INLINE GEN
     504    12800048 : shallowcopy(GEN x)
     505    12800048 : { return typ(x) == t_MAT ? RgM_shallowcopy(x): leafcopy(x); }
     506             : 
     507             : /* routines for naive growarrays */
     508             : INLINE GEN
     509    12718092 : vectrunc_init(long l)
     510             : {
     511    12718092 :   GEN z = new_chunk(l);
     512    12717930 :   z[0] = evaltyp(t_VEC) | _evallg(1); return z;
     513             : }
     514             : INLINE GEN
     515         203 : coltrunc_init(long l)
     516             : {
     517         203 :   GEN z = new_chunk(l);
     518         203 :   z[0] = evaltyp(t_COL) | _evallg(1); return z;
     519             : }
     520             : INLINE void
     521   257711672 : lg_increase(GEN x) { x[0]++; }
     522             : INLINE void
     523    51342105 : 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    84565019 : vecsmalltrunc_init(long l)
     534             : {
     535    84565019 :   GEN z = new_chunk(l);
     536    84565019 :   z[0] = evaltyp(t_VECSMALL) | _evallg(1); return z;
     537             : }
     538             : INLINE void
     539    33191324 : 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     1966310 : hash_str(const char *str)
     548             : {
     549     1966310 :   ulong hash = 5381UL, c;
     550    21334740 :   while ( (c = (ulong)*str++) )
     551    17402120 :     hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
     552     1966310 :   return hash;
     553             : }
     554             : INLINE ulong
     555     6596047 : hash_str_len(const char *str, long len)
     556             : {
     557     6596047 :   ulong hash = 5381UL;
     558             :   long i;
     559    25102987 :   for (i = 0; i < len; i++)
     560             :   {
     561    18506940 :     ulong c = (ulong)*str++;
     562    18506940 :     hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
     563             :   }
     564     6596047 :   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       13710 : vec_lengthen(GEN v, long n)
     584             : {
     585             :   long i;
     586       13710 :   long l=lg(v);
     587       13710 :   GEN V = cgetg(n+1,t_VEC);
     588       13710 :   for(i=1;i<l;i++) gel(V,i) = gel(v,i);
     589       13710 :   return V;
     590             : }
     591             : /* shallow*/
     592             : INLINE GEN
     593       64596 : vec_append(GEN V, GEN s)
     594             : {
     595       64596 :   long i, l2 = lg(V);
     596       64596 :   GEN res = cgetg(l2+1, typ(V));
     597       64596 :   for (i = 1; i < l2; ++i) gel(res, i) = gel(V,i);
     598       64596 :   gel(res,l2) = s; return res;
     599             : }
     600             : /* shallow*/
     601             : INLINE GEN
     602        1785 : vec_prepend(GEN v, GEN s)
     603             : {
     604        1785 :   long i, l = lg(v);
     605        1785 :   GEN w = cgetg(l+1, typ(v));
     606        1785 :   gel(w,1) = s;
     607        1785 :   for (i = 2; i <= l; ++i) gel(w,i) = gel(v,i-1);
     608        1785 :   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       41782 : vecsmall_shorten(GEN v, long n)
     620             : {
     621             :   long i;
     622       41782 :   GEN V = cgetg(n+1,t_VECSMALL);
     623       41785 :   for(i=1;i<=n;i++) V[i] = v[i];
     624       41785 :   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     3323829 : vec_to_vecsmall(GEN x)
     637     3323829 : { pari_APPLY_long(itos(gel(x,i))) }
     638             : INLINE GEN
     639      135823 : vecsmall_to_vec(GEN x)
     640      135823 : { pari_APPLY_type(t_VEC, stoi(x[i])) }
     641             : INLINE GEN
     642        1617 : vecsmall_to_vec_inplace(GEN z)
     643             : {
     644        1617 :   long i, l = lg(z);
     645        1617 :   for (i=1; i<l; i++) gel(z,i) = stoi(z[i]);
     646        1617 :   settyp(z, t_VEC); return z;
     647             : }
     648             : INLINE GEN
     649     5247902 : vecsmall_to_col(GEN x)
     650     5247902 : { pari_APPLY_type(t_COL, stoi(x[i])) }
     651             : 
     652             : INLINE int
     653     8141631 : vecsmall_lexcmp(GEN x, GEN y)
     654             : {
     655             :   long lx,ly,l,i;
     656     8141631 :   lx = lg(x);
     657     8141631 :   ly = lg(y); l = minss(lx,ly);
     658    39708479 :   for (i=1; i<l; i++)
     659    37836550 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     660     1871929 :   if (lx == ly) return 0;
     661          14 :   return (lx < ly)? -1 : 1;
     662             : }
     663             : 
     664             : INLINE int
     665    85155511 : vecsmall_prefixcmp(GEN x, GEN y)
     666             : {
     667    85155511 :   long i, lx = lg(x), ly = lg(y), l = minss(lx,ly);
     668   394027655 :   for (i=1; i<l; i++)
     669   374395014 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     670    19632641 :   return 0;
     671             : }
     672             : 
     673             : /*Can be used on t_VEC, but coeffs not gcopy-ed*/
     674             : INLINE GEN
     675       21449 : vecsmall_prepend(GEN V, long s)
     676             : {
     677       21449 :   long i, l2 = lg(V);
     678       21449 :   GEN res = cgetg(l2+1, typ(V));
     679       21449 :   res[1] = s;
     680       21449 :   for (i = 2; i <= l2; ++i) res[i] = V[i - 1];
     681       21449 :   return res;
     682             : }
     683             : 
     684             : INLINE GEN
     685     3132233 : vecsmall_append(GEN V, long s)
     686             : {
     687     3132233 :   long i, l2 = lg(V);
     688     3132233 :   GEN res = cgetg(l2+1, t_VECSMALL);
     689     3132232 :   for (i = 1; i < l2; ++i) res[i] = V[i];
     690     3132232 :   res[l2] = s; return res;
     691             : }
     692             : 
     693             : INLINE GEN
     694      841393 : vecsmall_concat(GEN u, GEN v)
     695             : {
     696      841393 :   long i, l1 = lg(u)-1, l2 = lg(v)-1;
     697      841393 :   GEN res = cgetg(l1+l2+1, t_VECSMALL);
     698      841393 :   for (i = 1; i <= l1; ++i) res[i]    = u[i];
     699      841393 :   for (i = 1; i <= l2; ++i) res[i+l1] = v[i];
     700      841393 :   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      178182 : vecsmall_max(GEN x)
     742             : {
     743      178182 :   long i, t = x[1], lx = lg(x);
     744      639575 :   for (i=2; i<lx; i++)
     745      461393 :     if (x[i] > t) t = x[i];
     746      178182 :   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     5113911 : ZV_isscalar(GEN x)
     769             : {
     770     5113911 :   long l = lg(x);
     771    14613790 :   while (--l > 1)
     772     8381276 :     if (signe(gel(x, l))) return 0;
     773     1118603 :   return 1;
     774             : }
     775             : INLINE int
     776    21523708 : QV_isscalar(GEN x)
     777             : {
     778    21523708 :   long lx = lg(x),i;
     779    23182745 :   for (i=2; i<lx; i++)
     780    22560856 :     if (!isintzero(gel(x, i))) return 0;
     781      621889 :   return 1;
     782             : }
     783             : INLINE int
     784        7823 : RgV_isscalar(GEN x)
     785             : {
     786        7823 :   long lx = lg(x),i;
     787       11689 :   for (i=2; i<lx; i++)
     788       10285 :     if (!gequal0(gel(x, i))) return 0;
     789        1404 :   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    28825624 : RgX_equal_var(GEN x, GEN y) { return varn(x) == varn(y) && RgX_equal(x,y); }
     801             : 
     802             : INLINE int
     803        7575 : RgX_is_rational(GEN x)
     804             : {
     805             :   long i;
     806       34398 :   for (i = lg(x)-1; i > 1; i--)
     807       31940 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     808        2458 :   return 1;
     809             : }
     810             : INLINE int
     811     4687088 : RgX_is_ZX(GEN x)
     812             : {
     813             :   long i;
     814    20274883 :   for (i = lg(x)-1; i > 1; i--)
     815    15640381 :     if (typ(gel(x,i)) != t_INT) return 0;
     816     4634502 :   return 1;
     817             : }
     818             : INLINE int
     819      266539 : RgX_is_QX(GEN x)
     820             : {
     821      266539 :   long k = lg(x)-1;
     822      945215 :   for ( ; k>1; k--)
     823      678921 :     if (!is_rational_t(typ(gel(x,k)))) return 0;
     824      266294 :   return 1;
     825             : }
     826             : INLINE int
     827     2347690 : RgX_is_monomial(GEN x)
     828             : {
     829             :   long i;
     830     2347690 :   if (!signe(x)) return 0;
     831     5857580 :   for (i=lg(x)-2; i>1; i--)
     832     3565036 :     if (!isexactzero(gel(x,i))) return 0;
     833     2292544 :   return 1;
     834             : }
     835             : INLINE int
     836    27460985 : RgV_is_ZV(GEN x)
     837             : {
     838             :   long i;
     839   112583117 :   for (i = lg(x)-1; i > 0; i--)
     840    85124617 :     if (typ(gel(x,i)) != t_INT) return 0;
     841    27458500 :   return 1;
     842             : }
     843             : INLINE int
     844       23034 : RgV_is_QV(GEN x)
     845             : {
     846             :   long i;
     847      101149 :   for (i = lg(x)-1; i > 0; i--)
     848       79746 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     849       21403 :   return 1;
     850             : }
     851             : 
     852             : /********************************************************************/
     853             : /**                                                                **/
     854             : /**            Dynamic arrays implementation                       **/
     855             : /**                                                                **/
     856             : /********************************************************************/
     857             : INLINE void **
     858   403181327 : pari_stack_base(pari_stack *s) { return s->data; }
     859             : 
     860             : INLINE void
     861     1972955 : pari_stack_init(pari_stack *s, size_t size, void **data)
     862             : {
     863     1972955 :   s->data = data;
     864     1972955 :   *data = NULL;
     865     1972955 :   s->n = 0;
     866     1972955 :   s->alloc = 0;
     867     1972955 :   s->size = size;
     868     1972955 : }
     869             : 
     870             : INLINE void
     871   401384983 : pari_stack_alloc(pari_stack *s, long nb)
     872             : {
     873   401384983 :   void **sdat = pari_stack_base(s);
     874   401376872 :   long alloc = s->alloc;
     875   401376872 :   if (s->n+nb <= alloc) return;
     876      809261 :   if (!alloc)
     877      749579 :     alloc = nb;
     878             :   else
     879             :   {
     880       59682 :     while (s->n+nb > alloc) alloc <<= 1;
     881             :   }
     882      809261 :   *sdat = pari_realloc(*sdat,alloc*s->size);
     883      810141 :   s->alloc = alloc;
     884             : }
     885             : 
     886             : INLINE long
     887   323573514 : pari_stack_new(pari_stack *s) { pari_stack_alloc(s, 1); return s->n++; }
     888             : 
     889             : INLINE void
     890     1801313 : pari_stack_delete(pari_stack *s)
     891             : {
     892     1801313 :   void **sdat = pari_stack_base(s);
     893     1797014 :   if (*sdat) pari_free(*sdat);
     894     1809437 : }
     895             : 
     896             : INLINE void
     897        4829 : pari_stack_pushp(pari_stack *s, void *u)
     898             : {
     899        4829 :   long n = pari_stack_new(s);
     900        4829 :   void **sdat =(void**) *pari_stack_base(s);
     901        4829 :   sdat[n] = u;
     902        4829 : }
     903             : 
     904             : /*******************************************************************/
     905             : /*                                                                 */
     906             : /*                            EXTRACT                              */
     907             : /*                                                                 */
     908             : /*******************************************************************/
     909             : INLINE GEN
     910   210292032 : vecslice(GEN A, long y1, long y2)
     911             : {
     912   210292032 :   long i,lB = y2 - y1 + 2;
     913   210292032 :   GEN B = cgetg(lB, typ(A));
     914   210292935 :   for (i=1; i<lB; i++) B[i] = A[y1-1+i];
     915   210292935 :   return B;
     916             : }
     917             : INLINE GEN
     918      861293 : vecslicepermute(GEN A, GEN p, long y1, long y2)
     919             : {
     920      861293 :   long i,lB = y2 - y1 + 2;
     921      861293 :   GEN B = cgetg(lB, typ(A));
     922      861290 :   for (i=1; i<lB; i++) B[i] = A[p[y1-1+i]];
     923      861290 :   return B;
     924             : }
     925             : /* rowslice(rowpermute(A,p), x1, x2) */
     926             : INLINE GEN
     927       42894 : rowslicepermute(GEN x, GEN p, long j1, long j2)
     928       42894 : { pari_APPLY_same(vecslicepermute(gel(x,i),p,j1,j2)) }
     929             : 
     930             : INLINE GEN
     931    23694247 : rowslice(GEN x, long j1, long j2)
     932    23694247 : { pari_APPLY_same(vecslice(gel(x,i), j1, j2)) }
     933             : 
     934             : INLINE GEN
     935     3855582 : matslice(GEN A, long x1, long x2, long y1, long y2)
     936     3855582 : { return rowslice(vecslice(A, y1, y2), x1, x2); }
     937             : 
     938             : /* shallow, remove coeff of index j */
     939             : INLINE GEN
     940         133 : rowsplice(GEN x, long j)
     941         133 : { pari_APPLY_same(vecsplice(gel(x,i), j)) }
     942             : 
     943             : /* shallow, remove coeff of index j */
     944             : INLINE GEN
     945      264286 : vecsplice(GEN a, long j)
     946             : {
     947      264286 :   long i, k, l = lg(a);
     948             :   GEN b;
     949      264286 :   if (l == 1) pari_err(e_MISC, "incorrect component in vecsplice");
     950      264286 :   b = cgetg(l-1, typ(a));
     951     1055722 :   for (i = k = 1; i < l; i++)
     952      791436 :     if (i != j) gel(b, k++) = gel(a,i);
     953      264286 :   return b;
     954             : }
     955             : /* shallow */
     956             : INLINE GEN
     957         833 : RgM_minor(GEN a, long i, long j)
     958             : {
     959         833 :   GEN b = vecsplice(a, j);
     960         833 :   long k, l = lg(b);
     961         833 :   for (k = 1; k < l; k++) gel(b,k) = vecsplice(gel(b,k), i);
     962         833 :   return b;
     963             : }
     964             : 
     965             : /* A[x0,] */
     966             : INLINE GEN
     967      391394 : row(GEN x, long j)
     968      391394 : { pari_APPLY_type(t_VEC, gcoeff(x, j, i)) }
     969             : INLINE GEN
     970     4046199 : Flm_row(GEN x, long j)
     971     4046199 : { pari_APPLY_ulong((ulong)coeff(x, j, i)) }
     972             : /* A[x0,] */
     973             : INLINE GEN
     974      204834 : rowcopy(GEN x, long j)
     975      204834 : { pari_APPLY_type(t_VEC, gcopy(gcoeff(x, j, i))) }
     976             : /* A[x0, x1..x2] */
     977             : INLINE GEN
     978        2989 : row_i(GEN A, long x0, long x1, long x2)
     979             : {
     980        2989 :   long i, lB = x2 - x1 + 2;
     981        2989 :   GEN B  = cgetg(lB, t_VEC);
     982        2989 :   for (i=x1; i<=x2; i++) gel(B, i) = gcoeff(A, x0, i);
     983        2989 :   return B;
     984             : }
     985             : 
     986             : INLINE GEN
     987     5830574 : vecreverse(GEN A)
     988             : {
     989             :   long i, l;
     990     5830574 :   GEN B = cgetg_copy(A, &l);
     991     5830574 :   for (i=1; i<l; i++) gel(B, i) = gel(A, l-i);
     992     5830574 :   return B;
     993             : }
     994             : 
     995             : INLINE GEN
     996         525 : vecsmall_reverse(GEN A)
     997             : {
     998             :   long i, l;
     999         525 :   GEN B = cgetg_copy(A, &l);
    1000         525 :   for (i=1; i<l; i++) B[i] = A[l-i];
    1001         525 :   return B;
    1002             : }
    1003             : 
    1004             : INLINE void
    1005         253 : vecreverse_inplace(GEN y)
    1006             : {
    1007         253 :   long l = lg(y), lim = l>>1, i;
    1008         717 :   for (i = 1; i <= lim; i++)
    1009             :   {
    1010         464 :     GEN z = gel(y,i);
    1011         464 :     gel(y,i)    = gel(y,l-i);
    1012         464 :     gel(y,l-i) = z;
    1013             :   }
    1014         253 : }
    1015             : 
    1016             : INLINE GEN
    1017    47027650 : vecsmallpermute(GEN A, GEN p) { return perm_mul(A, p); }
    1018             : 
    1019             : INLINE GEN
    1020     6834659 : vecpermute(GEN A, GEN x)
    1021     6834659 : { pari_APPLY_type(typ(A), gel(A, x[i])) }
    1022             : 
    1023             : INLINE GEN
    1024     3265303 : rowpermute(GEN x, GEN p)
    1025     3265303 : { pari_APPLY_same(typ(gel(x,i)) == t_VECSMALL ? vecsmallpermute(gel(x, i), p)
    1026             :                                               : vecpermute(gel(x, i), p))
    1027             : }
    1028             : /*******************************************************************/
    1029             : /*                                                                 */
    1030             : /*                          PERMUTATIONS                           */
    1031             : /*                                                                 */
    1032             : /*******************************************************************/
    1033             : INLINE GEN
    1034      763196 : identity_zv(long n)
    1035             : {
    1036      763196 :   GEN v = cgetg(n+1, t_VECSMALL);
    1037             :   long i;
    1038      763174 :   for (i = 1; i <= n; i++) v[i] = i;
    1039      763174 :   return v;
    1040             : }
    1041             : INLINE GEN
    1042        1834 : identity_ZV(long n)
    1043             : {
    1044        1834 :   GEN v = cgetg(n+1, t_VEC);
    1045             :   long i;
    1046        1834 :   for (i = 1; i <= n; i++) gel(v,i) = utoipos(i);
    1047        1834 :   return v;
    1048             : }
    1049             : /* identity permutation */
    1050             : INLINE GEN
    1051      762706 : identity_perm(long n) { return identity_zv(n); }
    1052             : 
    1053             : /* assume d <= n */
    1054             : INLINE GEN
    1055       98434 : cyclic_perm(long n, long d)
    1056             : {
    1057       98434 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1058             :   long i;
    1059       98434 :   for (i = 1; i <= n-d; i++) perm[i] = i+d;
    1060       98434 :   for (     ; i <= n;   i++) perm[i] = i-n+d;
    1061       98434 :   return perm;
    1062             : }
    1063             : 
    1064             : /* Multiply (compose) two permutations */
    1065             : INLINE GEN
    1066    48303773 : perm_mul(GEN s, GEN x)
    1067    48303773 : { pari_APPLY_long(s[x[i]]) }
    1068             : 
    1069             : /* Compute the inverse (reciprocal) of a permutation. */
    1070             : INLINE GEN
    1071     1219153 : perm_inv(GEN x)
    1072             : {
    1073             :   long i, lx;
    1074     1219153 :   GEN y = cgetg_copy(x, &lx);
    1075     1219152 :   for (i=1; i<lx; i++) y[ x[i] ] = i;
    1076     1219152 :   return y;
    1077             : }
    1078             : /* Return s*t*s^-1 */
    1079             : INLINE GEN
    1080      416976 : perm_conj(GEN s, GEN t)
    1081             : {
    1082             :   long i, l;
    1083      416976 :   GEN v = cgetg_copy(s, &l);
    1084      416976 :   for (i = 1; i < l; i++) v[ s[i] ] = s[ t[i] ];
    1085      416976 :   return v;
    1086             : }
    1087             : 
    1088             : /*********************************************************************/
    1089             : /*                       MALLOC/FREE WRAPPERS                        */
    1090             : /*********************************************************************/
    1091             : #define BLOCK_SIGALRM_START          \
    1092             : {                                    \
    1093             :   int block=PARI_SIGINT_block;       \
    1094             :   PARI_SIGINT_block = 2;             \
    1095             :   MT_SIGINT_BLOCK(block);
    1096             : 
    1097             : #define BLOCK_SIGINT_START           \
    1098             : {                                    \
    1099             :   int block=PARI_SIGINT_block;       \
    1100             :   PARI_SIGINT_block = 1;             \
    1101             :   MT_SIGINT_BLOCK(block);
    1102             : 
    1103             : #define BLOCK_SIGINT_END             \
    1104             :   PARI_SIGINT_block = block;         \
    1105             :   MT_SIGINT_UNBLOCK(block);          \
    1106             :   if (!block && PARI_SIGINT_pending) \
    1107             :   {                                  \
    1108             :     int sig = PARI_SIGINT_pending;   \
    1109             :     PARI_SIGINT_pending = 0;         \
    1110             :     raise(sig);                      \
    1111             :   }                                  \
    1112             : }
    1113             : 
    1114             : INLINE void
    1115    73564941 : pari_free(void *pointer)
    1116             : {
    1117    73564941 :   BLOCK_SIGINT_START;
    1118    73590472 :   free(pointer);
    1119    73590472 :   BLOCK_SIGINT_END;
    1120    73584162 : }
    1121             : INLINE void*
    1122   280561813 : pari_malloc(size_t size)
    1123             : {
    1124   280561813 :   if (size)
    1125             :   {
    1126             :     char *tmp;
    1127   280561813 :     BLOCK_SIGINT_START;
    1128   280565029 :     tmp = (char*)malloc(size);
    1129   280565029 :     BLOCK_SIGINT_END;
    1130   280564236 :     if (!tmp) pari_err(e_MEM);
    1131   280564236 :     return tmp;
    1132             :   }
    1133           0 :   return NULL;
    1134             : }
    1135             : INLINE void*
    1136      823989 : pari_realloc(void *pointer, size_t size)
    1137             : {
    1138             :   char *tmp;
    1139             : 
    1140      823989 :   BLOCK_SIGINT_START;
    1141      827757 :   if (!pointer) tmp = (char *) malloc(size);
    1142       63885 :   else tmp = (char *) realloc(pointer,size);
    1143      827757 :   BLOCK_SIGINT_END;
    1144      826277 :   if (!tmp) pari_err(e_MEM);
    1145      826277 :   return tmp;
    1146             : }
    1147             : INLINE void*
    1148       37762 : pari_calloc(size_t size)
    1149             : {
    1150       37762 :   void *t = pari_malloc(size);
    1151       37762 :   memset(t, 0, size); return t;
    1152             : }
    1153             : INLINE GEN
    1154        5831 : cgetalloc(long t, size_t l)
    1155             : {
    1156        5831 :   GEN x = (GEN)pari_malloc(l * sizeof(long));
    1157        5831 :   x[0] = evaltyp(t) | evallg(l); return x;
    1158             : }
    1159             : 
    1160             : /*******************************************************************/
    1161             : /*                                                                 */
    1162             : /*                       GARBAGE COLLECTION                        */
    1163             : /*                                                                 */
    1164             : /*******************************************************************/
    1165             : /* copy integer x as if we had set_avma(av) */
    1166             : INLINE GEN
    1167  3848288794 : icopy_avma(GEN x, pari_sp av)
    1168             : {
    1169  3848288794 :   long i = lgefint(x), lx = i;
    1170  3848288794 :   GEN y = ((GEN)av) - i;
    1171  3848288794 :   while (--i > 0) y[i] = x[i];
    1172  3848288794 :   y[0] = evaltyp(t_INT)|evallg(lx);
    1173  3847978276 :   return y;
    1174             : }
    1175             : /* copy leaf x as if we had set_avma(av) */
    1176             : INLINE GEN
    1177   187423495 : leafcopy_avma(GEN x, pari_sp av)
    1178             : {
    1179   187423495 :   long i = lg(x);
    1180   187423495 :   GEN y = ((GEN)av) - i;
    1181   187423495 :   while (--i > 0) y[i] = x[i];
    1182   187423495 :   y[0] = x[0] & (~CLONEBIT);
    1183   187423495 :   return y;
    1184             : }
    1185             : INLINE GEN
    1186   666828341 : gerepileuptoleaf(pari_sp av, GEN x)
    1187             : {
    1188             :   long lx;
    1189             :   GEN q;
    1190             : 
    1191   666828341 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1192   666679490 :   lx = lg(x);
    1193   666679490 :   q = ((GEN)av) - lx;
    1194   666679490 :   set_avma((pari_sp)q);
    1195   668538959 :   while (--lx >= 0) q[lx] = x[lx];
    1196   668538959 :   return q;
    1197             : }
    1198             : INLINE GEN
    1199  1312392248 : gerepileuptoint(pari_sp av, GEN x)
    1200             : {
    1201  1312392248 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1202  1159447721 :   set_avma((pari_sp)icopy_avma(x, av));
    1203  1161014554 :   return (GEN)avma;
    1204             : }
    1205             : INLINE GEN
    1206   831513030 : gerepileupto(pari_sp av, GEN x)
    1207             : {
    1208   831513030 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1209   740180138 :   switch(typ(x))
    1210             :   { /* non-default = !is_recursive_t(tq) */
    1211   256779777 :     case t_INT: return gerepileuptoint(av, x);
    1212             :     case t_REAL:
    1213             :     case t_STR:
    1214   153317326 :     case t_VECSMALL: return gerepileuptoleaf(av,x);
    1215             :     default:
    1216             :       /* NB: x+i --> ((long)x) + i*sizeof(long) */
    1217   330083035 :       return gerepile(av, (pari_sp) (x+lg(x)), x);
    1218             :   }
    1219             : }
    1220             : INLINE double
    1221     2517383 : gc_double(pari_sp av, double d) { set_avma(av); return d; }
    1222             : INLINE long
    1223   113092738 : gc_long(pari_sp av, long s) { set_avma(av); return s; }
    1224             : INLINE ulong
    1225    15321606 : gc_ulong(pari_sp av, ulong s) { set_avma(av); return s; }
    1226             : INLINE int
    1227    22702606 : gc_bool(pari_sp av, int s) { set_avma(av); return s; }
    1228             : INLINE int
    1229     3366960 : gc_int(pari_sp av, int s) { set_avma(av); return s; }
    1230             : INLINE GEN
    1231     1661713 : gc_NULL(pari_sp av) { set_avma(av); return NULL; }
    1232             : 
    1233             : /* gerepileupto(av, gcopy(x)) */
    1234             : INLINE GEN
    1235    54266131 : gerepilecopy(pari_sp av, GEN x)
    1236             : {
    1237    54266131 :   if (is_recursive_t(typ(x)))
    1238             :   {
    1239    49613188 :     GENbin *p = copy_bin(x);
    1240    49613983 :     set_avma(av); return bin_copy(p);
    1241             :   }
    1242             :   else
    1243             :   {
    1244     4652966 :     set_avma(av);
    1245     4652971 :     if (x < (GEN)av) {
    1246     3165451 :       if (x < (GEN)pari_mainstack->bot) new_chunk(lg(x));
    1247     3165451 :       x = leafcopy_avma(x, av);
    1248     3165466 :       set_avma((pari_sp)x);
    1249             :     } else
    1250     1487520 :       x = leafcopy(x);
    1251     4652991 :     return x;
    1252             :   }
    1253             : }
    1254             : 
    1255             : INLINE void
    1256    28739673 : guncloneNULL(GEN x) { if (x) gunclone(x); }
    1257             : INLINE void
    1258      174035 : guncloneNULL_deep(GEN x) { if (x) gunclone_deep(x); }
    1259             : 
    1260             : /* Takes an array of pointers to GENs, of length n. Copies all
    1261             :  * objects to contiguous locations and cleans up the stack between
    1262             :  * av and avma. */
    1263             : INLINE void
    1264      202680 : gerepilemany(pari_sp av, GEN* gptr[], int n)
    1265             : {
    1266             :   int i;
    1267      202680 :   for (i=0; i<n; i++) *gptr[i] = (GEN)copy_bin(*gptr[i]);
    1268      202680 :   set_avma(av);
    1269      202680 :   for (i=0; i<n; i++) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1270      202680 : }
    1271             : 
    1272             : INLINE void
    1273     7646780 : gerepileall(pari_sp av, int n, ...)
    1274             : {
    1275             :   int i;
    1276     7646780 :   va_list a; va_start(a, n);
    1277     7646780 :   if (n < 10)
    1278             :   {
    1279             :     GEN *gptr[10];
    1280    22169562 :     for (i=0; i<n; i++)
    1281    14522782 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1282     7646780 :     set_avma(av);
    1283     7646739 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1284             : 
    1285             :   }
    1286             :   else
    1287             :   {
    1288           0 :     GEN **gptr = (GEN**)  pari_malloc(n*sizeof(GEN*));
    1289           0 :     for (i=0; i<n; i++)
    1290           0 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1291           0 :     set_avma(av);
    1292           0 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1293           0 :     pari_free(gptr);
    1294             :   }
    1295     7646882 :   va_end(a);
    1296     7646882 : }
    1297             : 
    1298             : INLINE void
    1299           6 : gerepilecoeffs(pari_sp av, GEN x, int n)
    1300             : {
    1301             :   int i;
    1302           6 :   for (i=0; i<n; i++) gel(x,i) = (GEN)copy_bin(gel(x,i));
    1303           6 :   set_avma(av);
    1304           6 :   for (i=0; i<n; i++) gel(x,i) = bin_copy((GENbin*)x[i]);
    1305           6 : }
    1306             : 
    1307             : /* p from copy_bin. Copy p->x back to stack, then destroy p */
    1308             : INLINE GEN
    1309    64759449 : bin_copy(GENbin *p)
    1310             : {
    1311             :   GEN x, y, base;
    1312             :   long dx, len;
    1313             : 
    1314    64759449 :   x   = p->x; if (!x) { pari_free(p); return gen_0; }
    1315    64752225 :   len = p->len;
    1316    64752225 :   base= p->base; dx = x - base;
    1317    64752225 :   y = (GEN)memcpy((void*)new_chunk(len), (void*)GENbinbase(p), len*sizeof(long));
    1318    64752086 :   y += dx;
    1319    64752086 :   p->rebase(y, ((ulong)y-(ulong)x));
    1320    64752074 :   pari_free(p); return y;
    1321             : }
    1322             : 
    1323             : INLINE GEN
    1324   129511975 : GENbinbase(GENbin *p) { return (GEN)(p + 1); }
    1325             : 
    1326             : INLINE void
    1327    32535114 : cgiv(GEN x)
    1328             : {
    1329    32535114 :   pari_sp av = (pari_sp)(x+lg(x));
    1330    32535114 :   if (isonstack((GEN)av)) set_avma(av);
    1331    32534512 : }
    1332             : 
    1333             : INLINE void
    1334     1267760 : killblock(GEN x) { gunclone(x); }
    1335             : 
    1336             : INLINE int
    1337    25960600 : is_universal_constant(GEN x) { return (x >= gen_0 && x <= ghalf); }
    1338             : 
    1339             : /*******************************************************************/
    1340             : /*                                                                 */
    1341             : /*                    CONVERSION / ASSIGNMENT                      */
    1342             : /*                                                                 */
    1343             : /*******************************************************************/
    1344             : /* z is a type which may be a t_COMPLEX component (not a t_QUAD) */
    1345             : INLINE GEN
    1346     3745899 : cxcompotor(GEN z, long prec)
    1347             : {
    1348     3745899 :   switch(typ(z))
    1349             :   {
    1350     2117222 :     case t_INT:  return itor(z, prec);
    1351      136682 :     case t_FRAC: return fractor(z, prec);
    1352     1491995 :     case t_REAL: return rtor(z, prec);
    1353           0 :     default: pari_err_TYPE("cxcompotor",z);
    1354             :              return NULL; /* LCOV_EXCL_LINE */
    1355             :   }
    1356             : }
    1357             : INLINE GEN
    1358     1858845 : cxtofp(GEN x, long prec)
    1359     1858845 : { retmkcomplex(cxcompotor(gel(x,1),prec), cxcompotor(gel(x,2),prec)); }
    1360             : 
    1361             : INLINE GEN
    1362      291228 : cxtoreal(GEN q)
    1363      291228 : { return (typ(q) == t_COMPLEX && gequal0(gel(q,2)))? gel(q,1): q; }
    1364             : 
    1365             : INLINE double
    1366    34673429 : gtodouble(GEN x)
    1367             : {
    1368    34673429 :   if (typ(x)!=t_REAL) {
    1369     7455939 :     pari_sp av = avma;
    1370     7455939 :     x = gtofp(x, DEFAULTPREC);
    1371     7455939 :     if (typ(x)!=t_REAL) pari_err_TYPE("gtodouble [t_REAL expected]", x);
    1372     7455939 :     set_avma(av);
    1373             :   }
    1374    34673429 :   return rtodbl(x);
    1375             : }
    1376             : INLINE long
    1377    73377299 : gtos(GEN x) {
    1378    73377299 :   if (typ(x) != t_INT) pari_err_TYPE("gtos [integer expected]",x);
    1379    73377292 :   return itos(x);
    1380             : }
    1381             : 
    1382             : INLINE ulong
    1383      152210 : gtou(GEN x) {
    1384      152210 :   if (typ(x) != t_INT || signe(x)<0)
    1385           0 :     pari_err_TYPE("gtou [integer >=0 expected]",x);
    1386      152218 :   return itou(x);
    1387             : }
    1388             : 
    1389             : INLINE GEN
    1390    23268407 : absfrac(GEN x)
    1391             : {
    1392    23268407 :   GEN y = cgetg(3, t_FRAC);
    1393    23268407 :   gel(y,1) = absi(gel(x,1));
    1394    23268407 :   gel(y,2) = icopy(gel(x,2)); return y;
    1395             : }
    1396             : INLINE GEN
    1397       36557 : absfrac_shallow(GEN x)
    1398       36557 : { return signe(gel(x,1))>0? x: mkfrac(negi(gel(x,1)), gel(x,2)); }
    1399             : INLINE GEN
    1400     7782458 : Q_abs(GEN x) { return (typ(x) == t_INT)? absi(x): absfrac(x); }
    1401             : INLINE GEN
    1402      140516 : Q_abs_shallow(GEN x)
    1403      140516 : { return (typ(x) == t_INT)? absi_shallow(x): absfrac_shallow(x); }
    1404             : INLINE GEN
    1405         322 : R_abs_shallow(GEN x)
    1406         322 : { return (typ(x) == t_FRAC)? absfrac_shallow(x): mpabs_shallow(x); }
    1407             : INLINE GEN
    1408           0 : R_abs(GEN x)
    1409           0 : { return (typ(x) == t_FRAC)? absfrac(x): mpabs(x); }
    1410             : 
    1411             : /* Force z to be of type real/complex with floating point components */
    1412             : INLINE GEN
    1413    36425967 : gtofp(GEN z, long prec)
    1414             : {
    1415    36425967 :   switch(typ(z))
    1416             :   {
    1417    22748367 :     case t_INT:  return itor(z, prec);
    1418     4311634 :     case t_FRAC: return fractor(z, prec);
    1419     7739566 :     case t_REAL: return rtor(z, prec);
    1420             :     case t_COMPLEX: {
    1421     1626400 :       GEN a = gel(z,1), b = gel(z,2);
    1422     1626400 :       if (isintzero(b)) return cxcompotor(a, prec);
    1423     1623662 :       if (isintzero(a)) {
    1424        3277 :         GEN y = cgetg(3, t_COMPLEX);
    1425        3277 :         b = cxcompotor(b, prec);
    1426        3277 :         gel(y,1) = real_0_bit(expo(b) - prec2nbits(prec));
    1427        3277 :         gel(y,2) = b; return y;
    1428             :       }
    1429     1620385 :       return cxtofp(z, prec);
    1430             :     }
    1431           0 :     case t_QUAD: return quadtofp(z, prec);
    1432           0 :     default: pari_err_TYPE("gtofp",z);
    1433             :              return NULL; /* LCOV_EXCL_LINE */
    1434             :   }
    1435             : }
    1436             : /* Force z to be of type real / int */
    1437             : INLINE GEN
    1438       22400 : gtomp(GEN z, long prec)
    1439             : {
    1440       22400 :   switch(typ(z))
    1441             :   {
    1442          14 :     case t_INT:  return z;
    1443       22386 :     case t_FRAC: return fractor(z, prec);
    1444           0 :     case t_REAL: return rtor(z, prec);
    1445           0 :     case t_QUAD: z = quadtofp(z, prec);
    1446           0 :                  if (typ(z) == t_REAL) return z;
    1447           0 :     default: pari_err_TYPE("gtomp",z);
    1448             :              return NULL; /* LCOV_EXCL_LINE */
    1449             :   }
    1450             : }
    1451             : 
    1452             : INLINE GEN
    1453      831955 : RgX_gtofp(GEN x, long prec)
    1454             : {
    1455             :   long l;
    1456      831955 :   GEN y = cgetg_copy(x, &l);
    1457      831955 :   while (--l > 1) gel(y,l) = gtofp(gel(x,l), prec);
    1458      831955 :   y[1] = x[1]; return y;
    1459             : }
    1460             : INLINE GEN
    1461     1204927 : RgC_gtofp(GEN x, long prec)
    1462     1204927 : { pari_APPLY_type(t_COL, gtofp(gel(x,i), prec)) }
    1463             : 
    1464             : INLINE GEN
    1465          42 : RgV_gtofp(GEN x, long prec)
    1466          42 : { pari_APPLY_type(t_VEC, gtofp(gel(x,i), prec)) }
    1467             : 
    1468             : INLINE GEN
    1469      136393 : RgM_gtofp(GEN x, long prec)
    1470      136393 : { pari_APPLY_same(RgC_gtofp(gel(x,i), prec)) }
    1471             : 
    1472             : INLINE GEN
    1473         560 : RgC_gtomp(GEN x, long prec)
    1474         560 : { pari_APPLY_type(t_COL, gtomp(gel(x,i), prec)) }
    1475             : 
    1476             : INLINE GEN
    1477          14 : RgM_gtomp(GEN x, long prec)
    1478          14 : { pari_APPLY_same(RgC_gtomp(gel(x,i), prec)) }
    1479             : 
    1480             : INLINE GEN
    1481        9948 : RgX_fpnorml2(GEN x, long prec)
    1482             : {
    1483        9948 :   pari_sp av = avma;
    1484        9948 :   return gerepileupto(av, gnorml2(RgX_gtofp(x, prec)));
    1485             : }
    1486             : INLINE GEN
    1487      189329 : RgC_fpnorml2(GEN x, long prec)
    1488             : {
    1489      189329 :   pari_sp av = avma;
    1490      189329 :   return gerepileupto(av, gnorml2(RgC_gtofp(x, prec)));
    1491             : }
    1492             : INLINE GEN
    1493        4084 : RgM_fpnorml2(GEN x, long prec)
    1494             : {
    1495        4084 :   pari_sp av = avma;
    1496        4084 :   return gerepileupto(av, gnorml2(RgM_gtofp(x, prec)));
    1497             : }
    1498             : 
    1499             : /* y a t_REAL */
    1500             : INLINE void
    1501      216244 : affgr(GEN x, GEN y)
    1502             : {
    1503             :   pari_sp av;
    1504      216244 :   switch(typ(x)) {
    1505        5992 :     case t_INT:  affir(x,y); break;
    1506      210252 :     case t_REAL: affrr(x,y); break;
    1507           0 :     case t_FRAC: rdiviiz(gel(x,1),gel(x,2), y); break;
    1508           0 :     case t_QUAD: av = avma; affgr(quadtofp(x,realprec(y)), y); set_avma(av); break;
    1509           0 :     default: pari_err_TYPE2("=",x,y);
    1510             :   }
    1511      216244 : }
    1512             : 
    1513             : INLINE GEN
    1514      261013 : affc_fixlg(GEN x, GEN res)
    1515             : {
    1516      261013 :   if (typ(x) == t_COMPLEX)
    1517             :   {
    1518      207529 :     affrr_fixlg(gel(x,1), gel(res,1));
    1519      207529 :     affrr_fixlg(gel(x,2), gel(res,2));
    1520             :   }
    1521             :   else
    1522             :   {
    1523       53484 :     set_avma((pari_sp)(res+3));
    1524       53484 :     res = cgetr(realprec(gel(res,1)));
    1525       53484 :     affrr_fixlg(x, res);
    1526             :   }
    1527      261013 :   return res;
    1528             : }
    1529             : 
    1530             : INLINE GEN
    1531           0 : trunc_safe(GEN x) { long e; return gcvtoi(x,&e); }
    1532             : 
    1533             : /*******************************************************************/
    1534             : /*                                                                 */
    1535             : /*                          LENGTH CONVERSIONS                     */
    1536             : /*                                                                 */
    1537             : /*******************************************************************/
    1538             : INLINE long
    1539       32413 : ndec2nlong(long x) { return 1 + (long)((x)*(LOG2_10/BITS_IN_LONG)); }
    1540             : INLINE long
    1541       23934 : ndec2prec(long x) { return 2 + ndec2nlong(x); }
    1542             : INLINE long
    1543        8479 : ndec2nbits(long x) { return ndec2nlong(x) << TWOPOTBITS_IN_LONG; }
    1544             : /* Fast implementation of ceil(x / (8*sizeof(long))); typecast to (ulong)
    1545             :  * to avoid overflow. Faster than 1 + ((x-1)>>TWOPOTBITS_IN_LONG)) :
    1546             :  *   addl, shrl instead of subl, sarl, addl */
    1547             : INLINE long
    1548     1264496 : nbits2nlong(long x) {
    1549     1264496 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1550             : }
    1551             : 
    1552             : INLINE long
    1553   320987616 : nbits2extraprec(long x) {
    1554   320987616 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1555             : }
    1556             : 
    1557             : /* Fast implementation of 2 + nbits2nlong(x) */
    1558             : INLINE long
    1559   112442113 : nbits2prec(long x) {
    1560   112442113 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1561             : }
    1562             : INLINE long
    1563    20967625 : nbits2lg(long x) {
    1564    20967625 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1565             : }
    1566             : /* ceil(x / sizeof(long)) */
    1567             : INLINE long
    1568    10135289 : nchar2nlong(long x) {
    1569    10135289 :   return (long)(((ulong)x+sizeof(long)-1) >> (TWOPOTBITS_IN_LONG-3L));
    1570             : }
    1571             : INLINE long
    1572  1178224136 : prec2nbits(long x) { return (x-2) * BITS_IN_LONG; }
    1573             : INLINE double
    1574      566482 : bit_accuracy_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1575             : INLINE double
    1576      302125 : prec2nbits_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1577             : INLINE long
    1578    34021680 : bit_prec(GEN x) { return prec2nbits(realprec(x)); }
    1579             : INLINE long
    1580  1061440271 : bit_accuracy(long x) { return prec2nbits(x); }
    1581             : INLINE long
    1582       12455 : prec2ndec(long x) { return (long)prec2nbits_mul(x, LOG10_2); }
    1583             : INLINE long
    1584         193 : nbits2ndec(long x) { return (long)(x * LOG10_2); }
    1585             : INLINE long
    1586        3143 : precdbl(long x) {return (x - 1) << 1;}
    1587             : INLINE long
    1588  3592257173 : divsBIL(long n) { return n >> TWOPOTBITS_IN_LONG; }
    1589             : INLINE long
    1590  3547113020 : remsBIL(long n) { return n & (BITS_IN_LONG-1); }
    1591             : 
    1592             : /*********************************************************************/
    1593             : /**                                                                 **/
    1594             : /**                      OPERATIONS MODULO m                        **/
    1595             : /**                                                                 **/
    1596             : /*********************************************************************/
    1597             : /* Assume m > 0, more efficient if 0 <= a, b < m */
    1598             : 
    1599             : INLINE GEN
    1600    35079541 : Fp_red(GEN a, GEN m) { return modii(a, m); }
    1601             : INLINE GEN
    1602    74839901 : Fp_add(GEN a, GEN b, GEN m)
    1603             : {
    1604    74839901 :   pari_sp av=avma;
    1605    74839901 :   GEN p = addii(a,b);
    1606    73536002 :   long s = signe(p);
    1607    73536002 :   if (!s) return p; /* = gen_0 */
    1608    65746908 :   if (s > 0) /* general case */
    1609             :   {
    1610    65520669 :     GEN t = subii(p, m);
    1611    66465490 :     s = signe(t);
    1612    66465490 :     if (!s) { set_avma(av); return gen_0; }
    1613    60618642 :     if (s < 0) { set_avma((pari_sp)p); return p; }
    1614    25802829 :     if (cmpii(t, m) < 0) return gerepileuptoint(av, t); /* general case ! */
    1615     1112599 :     p = remii(t, m);
    1616             :   }
    1617             :   else
    1618      226239 :     p = modii(p, m);
    1619     1338838 :   return gerepileuptoint(av, p);
    1620             : }
    1621             : INLINE GEN
    1622    56880615 : Fp_sub(GEN a, GEN b, GEN m)
    1623             : {
    1624    56880615 :   pari_sp av=avma;
    1625    56880615 :   GEN p = subii(a,b);
    1626    56298140 :   long s = signe(p);
    1627    56298140 :   if (!s) return p; /* = gen_0 */
    1628    50044118 :   if (s > 0)
    1629             :   {
    1630    24175477 :     if (cmpii(p, m) < 0) return p; /* general case ! */
    1631     1121927 :     p = remii(p, m);
    1632             :   }
    1633             :   else
    1634             :   {
    1635    25868641 :     GEN t = addii(p, m);
    1636    25810746 :     if (!s) { set_avma(av); return gen_0; }
    1637    25810746 :     if (s > 0) return gerepileuptoint(av, t); /* general case ! */
    1638    25810746 :     p = modii(t, m);
    1639             :   }
    1640    27747543 :   return gerepileuptoint(av, p);
    1641             : }
    1642             : INLINE GEN
    1643    13589781 : Fp_neg(GEN b, GEN m)
    1644             : {
    1645    13589781 :   pari_sp av = avma;
    1646    13589781 :   long s = signe(b);
    1647             :   GEN p;
    1648    13589781 :   if (!s) return gen_0;
    1649    10095618 :   if (s > 0)
    1650             :   {
    1651     9867883 :     p = subii(m, b);
    1652     9864636 :     if (signe(p) >= 0) return p; /* general case ! */
    1653      104389 :     p = modii(p, m);
    1654             :   } else
    1655      227735 :     p = remii(negi(b), m);
    1656      332124 :   return gerepileuptoint(av, p);
    1657             : }
    1658             : 
    1659             : INLINE GEN
    1660       23613 : Fp_halve(GEN a, GEN p)
    1661             : {
    1662       23613 :   if (mpodd(a)) a = addii(a,p);
    1663       23613 :   return shifti(a,-1);
    1664             : }
    1665             : 
    1666             : /* assume 0 <= u < p and ps2 = p>>1 */
    1667             : INLINE GEN
    1668    16774539 : Fp_center(GEN u, GEN p, GEN ps2)
    1669    16774539 : { return abscmpii(u,ps2)<=0? icopy(u): subii(u,p); }
    1670             : /* same without copy */
    1671             : INLINE GEN
    1672    15743674 : Fp_center_i(GEN u, GEN p, GEN ps2)
    1673    15743674 : { return abscmpii(u,ps2)<=0? u: subii(u,p); }
    1674             : 
    1675             : /* x + y*z mod p */
    1676             : INLINE GEN
    1677     5106400 : Fp_addmul(GEN x, GEN y, GEN z, GEN p)
    1678             : {
    1679             :   pari_sp av;
    1680     5106400 :   if (!signe(y) || !signe(z)) return Fp_red(x, p);
    1681     4806108 :   if (!signe(x)) return Fp_mul(z,y, p);
    1682     4501021 :   av = avma;
    1683     4501021 :   return gerepileuptoint(av, modii(addii(x, mulii(y,z)), p));
    1684             : }
    1685             : 
    1686             : INLINE GEN
    1687    93220834 : Fp_mul(GEN a, GEN b, GEN m)
    1688             : {
    1689    93220834 :   pari_sp av=avma;
    1690             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1691    93220834 :   (void)new_chunk(lg(a)+lg(b)+(lg(m)<<1));
    1692    93201001 :   p = mulii(a,b);
    1693    93371274 :   set_avma(av); return modii(p,m);
    1694             : }
    1695             : INLINE GEN
    1696    33715284 : Fp_sqr(GEN a, GEN m)
    1697             : {
    1698    33715284 :   pari_sp av=avma;
    1699             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1700    33715284 :   (void)new_chunk((lg(a)+lg(m))<<1);
    1701    33318771 :   p = sqri(a);
    1702    30814353 :   set_avma(av); return remii(p,m); /*Use remii: p >= 0 */
    1703             : }
    1704             : INLINE GEN
    1705    67250907 : Fp_mulu(GEN a, ulong b, GEN m)
    1706             : {
    1707    67250907 :   long l = lgefint(m);
    1708    67250907 :   if (l == 3)
    1709             :   {
    1710    41435606 :     ulong mm = m[2];
    1711    41435606 :     return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1712             :   } else {
    1713    25815301 :     pari_sp av = avma;
    1714             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1715    25815301 :     (void)new_chunk(lg(a)+1+(l<<1));
    1716    25704036 :     p = muliu(a,b);
    1717    24380780 :     set_avma(av); return modii(p,m);
    1718             :   }
    1719             : }
    1720             : INLINE GEN
    1721           0 : Fp_muls(GEN a, long b, GEN m)
    1722             : {
    1723           0 :   long l = lgefint(m);
    1724           0 :   if (l == 3)
    1725             :   {
    1726           0 :     ulong mm = m[2];
    1727           0 :     if (b < 0)
    1728             :     {
    1729           0 :       ulong t = Fl_mul(umodiu(a, mm), -b, mm);
    1730           0 :       return t? utoipos(mm - t): gen_0;
    1731             :     }
    1732             :     else
    1733           0 :       return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1734             :   } else {
    1735           0 :     pari_sp av = avma;
    1736             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1737           0 :     (void)new_chunk(lg(a)+1+(l<<1));
    1738           0 :     p = mulis(a,b);
    1739           0 :     set_avma(av); return modii(p,m);
    1740             :   }
    1741             : }
    1742             : 
    1743             : INLINE GEN
    1744     9818290 : Fp_inv(GEN a, GEN m)
    1745             : {
    1746             :   GEN res;
    1747     9818290 :   if (! invmod(a,m,&res)) pari_err_INV("Fp_inv", mkintmod(res,m));
    1748     9817854 :   return res;
    1749             : }
    1750             : INLINE GEN
    1751      324865 : Fp_invsafe(GEN a, GEN m)
    1752             : {
    1753             :   GEN res;
    1754      324865 :   if (! invmod(a,m,&res)) return NULL;
    1755      324865 :   return res;
    1756             : }
    1757             : INLINE GEN
    1758     1656337 : Fp_div(GEN a, GEN b, GEN m)
    1759             : {
    1760     1656337 :   pari_sp av = avma;
    1761             :   GEN p;
    1762     1656337 :   if (lgefint(b) == 3)
    1763             :   {
    1764      669003 :     a = Fp_divu(a, b[2], m);
    1765      669003 :     if (signe(b) < 0) a = Fp_neg(a, m);
    1766      669003 :     return a;
    1767             :   }
    1768             :   /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1769      987334 :   (void)new_chunk(lg(a)+(lg(m)<<1));
    1770      987334 :   p = mulii(a, Fp_inv(b,m));
    1771      987334 :   set_avma(av); return modii(p,m);
    1772             : }
    1773             : INLINE GEN
    1774     1402591 : Fp_divu(GEN x, ulong a, GEN p)
    1775             : {
    1776     1402591 :   pari_sp av = avma;
    1777             :   ulong b;
    1778     1402591 :   if (lgefint(p) == 3)
    1779             :   {
    1780      984744 :     ulong pp = p[2], xp = umodiu(x, pp);
    1781      984744 :     return xp? utoipos(Fl_div(xp, a % pp, pp)): gen_0;
    1782             :   }
    1783      417847 :   x = Fp_red(x, p);
    1784      417852 :   b = Fl_neg(Fl_div(umodiu(x,a), umodiu(p,a), a), a); /* x + pb = 0 (mod a) */
    1785      417853 :   return gerepileuptoint(av, diviuexact(addmuliu(x, p, b), a));
    1786             : }
    1787             : 
    1788             : INLINE GEN
    1789      847795 : Flx_mulu(GEN x, ulong a, ulong p) { return Flx_Fl_mul(x,a%p,p); }
    1790             : 
    1791             : INLINE GEN
    1792           0 : get_F2x_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1793             : 
    1794             : INLINE long
    1795      449700 : get_F2x_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1796             : 
    1797             : INLINE long
    1798      121576 : get_F2x_degree(GEN T) { return typ(T)==t_VEC? F2x_degree(gel(T,2)): F2x_degree(T); }
    1799             : 
    1800             : INLINE GEN
    1801         385 : get_F2xqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1802             : 
    1803             : INLINE long
    1804      376943 : get_F2xqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1805             : 
    1806             : INLINE long
    1807      201859 : get_F2xqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1808             : 
    1809             : INLINE GEN
    1810     8004031 : get_Flx_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1811             : 
    1812             : INLINE long
    1813    17664697 : get_Flx_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1814             : 
    1815             : INLINE long
    1816    38293339 : get_Flx_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1817             : 
    1818             : INLINE GEN
    1819        2475 : get_FlxqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1820             : 
    1821             : INLINE long
    1822      221861 : get_FlxqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1823             : 
    1824             : INLINE long
    1825      277632 : get_FlxqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1826             : 
    1827             : INLINE GEN
    1828     1639768 : get_FpX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1829             : 
    1830             : INLINE long
    1831     3947538 : get_FpX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1832             : 
    1833             : INLINE long
    1834     2897389 : get_FpX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1835             : 
    1836             : INLINE GEN
    1837      142586 : get_FpXQX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1838             : 
    1839             : INLINE long
    1840       57357 : get_FpXQX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1841             : 
    1842             : INLINE long
    1843        2187 : get_FpXQX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1844             : 
    1845             : /*******************************************************************/
    1846             : /*                                                                 */
    1847             : /*                        ADDMULII / SUBMULII                      */
    1848             : /*                                                                 */
    1849             : /*******************************************************************/
    1850             : /* x - y*z */
    1851             : INLINE GEN
    1852      337480 : submulii(GEN x, GEN y, GEN z)
    1853             : {
    1854      337480 :   long lx = lgefint(x), ly, lz;
    1855             :   pari_sp av;
    1856             :   GEN t;
    1857      337480 :   if (lx == 2) { t = mulii(z,y); togglesign(t); return t; }
    1858      294310 :   ly = lgefint(y);
    1859      294310 :   if (ly == 2) return icopy(x);
    1860      247102 :   lz = lgefint(z);
    1861      247102 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1862      247102 :   t = mulii(z, y);
    1863      247102 :   set_avma(av); return subii(x,t);
    1864             : }
    1865             : /* y*z - x */
    1866             : INLINE GEN
    1867     1291224 : mulsubii(GEN y, GEN z, GEN x)
    1868             : {
    1869     1291224 :   long lx = lgefint(x), ly, lz;
    1870             :   pari_sp av;
    1871             :   GEN t;
    1872     1291224 :   if (lx == 2) return mulii(z,y);
    1873      823978 :   ly = lgefint(y);
    1874      823978 :   if (ly == 2) return negi(x);
    1875      756105 :   lz = lgefint(z);
    1876      756105 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1877      756105 :   t = mulii(z, y);
    1878      756105 :   set_avma(av); return subii(t,x);
    1879             : }
    1880             : 
    1881             : /* x - u*y */
    1882             : INLINE GEN
    1883        7595 : submuliu(GEN x, GEN y, ulong u)
    1884             : {
    1885             :   pari_sp av;
    1886        7595 :   long ly = lgefint(y);
    1887        7595 :   if (ly == 2) return icopy(x);
    1888        7595 :   av = avma;
    1889        7595 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1890        7595 :   y = mului(u,y);
    1891        7595 :   set_avma(av); return subii(x, y);
    1892             : }
    1893             : /* x + u*y */
    1894             : INLINE GEN
    1895      425448 : addmuliu(GEN x, GEN y, ulong u)
    1896             : {
    1897             :   pari_sp av;
    1898      425448 :   long ly = lgefint(y);
    1899      425448 :   if (ly == 2) return icopy(x);
    1900      425448 :   av = avma;
    1901      425448 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1902      425448 :   y = mului(u,y);
    1903      425442 :   set_avma(av); return addii(x, y);
    1904             : }
    1905             : /* x - u*y */
    1906             : INLINE GEN
    1907   125065220 : submuliu_inplace(GEN x, GEN y, ulong u)
    1908             : {
    1909             :   pari_sp av;
    1910   125065220 :   long ly = lgefint(y);
    1911   125065220 :   if (ly == 2) return x;
    1912   100101448 :   av = avma;
    1913   100101448 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1914   100101448 :   y = mului(u,y);
    1915   100101448 :   set_avma(av); return subii(x, y);
    1916             : }
    1917             : /* x + u*y */
    1918             : INLINE GEN
    1919   123449810 : addmuliu_inplace(GEN x, GEN y, ulong u)
    1920             : {
    1921             :   pari_sp av;
    1922   123449810 :   long ly = lgefint(y);
    1923   123449810 :   if (ly == 2) return x;
    1924    99927824 :   av = avma;
    1925    99927824 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1926    99927824 :   y = mului(u,y);
    1927    99927824 :   set_avma(av); return addii(x, y);
    1928             : }
    1929             : /* ux + vy */
    1930             : INLINE GEN
    1931    21186228 : lincombii(GEN u, GEN v, GEN x, GEN y)
    1932             : {
    1933    21186228 :   long lx = lgefint(x), ly;
    1934             :   GEN p1, p2;
    1935             :   pari_sp av;
    1936    21186228 :   if (lx == 2) return mulii(v,y);
    1937    14933598 :   ly = lgefint(y);
    1938    14933598 :   if (ly == 2) return mulii(u,x);
    1939    13669408 :   av = avma; (void)new_chunk(lx+ly+lgefint(u)+lgefint(v)); /* HACK */
    1940    13669412 :   p1 = mulii(u,x);
    1941    13669231 :   p2 = mulii(v,y);
    1942    13669241 :   set_avma(av); return addii(p1,p2);
    1943             : }
    1944             : 
    1945             : /*******************************************************************/
    1946             : /*                                                                 */
    1947             : /*                          GEN SUBTYPES                           */
    1948             : /*                                                                 */
    1949             : /*******************************************************************/
    1950             : 
    1951             : INLINE int
    1952  1304280167 : is_const_t(long t) { return (t < t_POLMOD); }
    1953             : INLINE int
    1954        5479 : is_extscalar_t(long t) { return (t <= t_POL); }
    1955             : INLINE int
    1956     1254628 : is_intreal_t(long t) { return (t <= t_REAL); }
    1957             : INLINE int
    1958   417166309 : is_matvec_t(long t) { return (t >= t_VEC && t <= t_MAT); }
    1959             : INLINE int
    1960    60146051 : is_noncalc_t(long tx) { return (tx) >= t_LIST; }
    1961             : INLINE int
    1962     1253675 : is_rational_t(long t) { return (t == t_INT || t == t_FRAC); }
    1963             : INLINE int
    1964      504618 : is_real_t(long t) { return (t == t_INT || t == t_REAL || t == t_FRAC); }
    1965             : INLINE int
    1966  3142991121 : is_recursive_t(long t) { return lontyp[t]; }
    1967             : INLINE int
    1968   174077053 : is_scalar_t(long t) { return (t < t_POL); }
    1969             : INLINE int
    1970     1516437 : is_vec_t(long t) { return (t == t_VEC || t == t_COL); }
    1971             : 
    1972             : /*******************************************************************/
    1973             : /*                                                                 */
    1974             : /*                         TRANSCENDENTAL                          */
    1975             : /*                                                                 */
    1976             : /*******************************************************************/
    1977             : INLINE GEN
    1978    22801828 : sqrtr(GEN x) {
    1979    22801828 :   long s = signe(x);
    1980    22801828 :   if (s == 0) return real_0_bit(expo(x) >> 1);
    1981    22768160 :   if (s >= 0) return sqrtr_abs(x);
    1982       37165 :   retmkcomplex(gen_0, sqrtr_abs(x));
    1983             : }
    1984             : INLINE GEN
    1985           0 : cbrtr_abs(GEN x) { return sqrtnr_abs(x, 3); }
    1986             : INLINE GEN
    1987           0 : cbrtr(GEN x) {
    1988           0 :   long s = signe(x);
    1989             :   GEN r;
    1990           0 :   if (s == 0) return real_0_bit(expo(x) / 3);
    1991           0 :   r = cbrtr_abs(x);
    1992           0 :   if (s < 0) togglesign(r);
    1993           0 :   return r;
    1994             : }
    1995             : INLINE GEN
    1996      464671 : sqrtnr(GEN x, long n) {
    1997      464671 :   long s = signe(x);
    1998             :   GEN r;
    1999      464671 :   if (s == 0) return real_0_bit(expo(x) / n);
    2000      464671 :   r = sqrtnr_abs(x, n);
    2001      464671 :   if (s < 0) pari_err_IMPL("sqrtnr for x < 0");
    2002      464671 :   return r;
    2003             : }
    2004             : INLINE long
    2005      222266 : logint(GEN B, GEN y) { return logintall(B,y,NULL); }
    2006             : INLINE ulong
    2007     1997387 : ulogint(ulong B, ulong y)
    2008             : {
    2009             :   ulong r;
    2010             :   long e;
    2011     1997387 :   if (y == 2) return expu(B);
    2012     1979264 :   r = y;
    2013     6389224 :   for (e=1;; e++)
    2014             :   { /* here, r = y^e, r2 = y^(e-1) */
    2015    10799184 :     if (r >= B) return r == B? e: e-1;
    2016     4409934 :     r = umuluu_or_0(y, r);
    2017     4409960 :     if (!r) return e;
    2018             :   }
    2019             : }
    2020             : 
    2021             : /*******************************************************************/
    2022             : /*                                                                 */
    2023             : /*                         MISCELLANEOUS                           */
    2024             : /*                                                                 */
    2025             : /*******************************************************************/
    2026     1254551 : INLINE int ismpzero(GEN x) { return is_intreal_t(typ(x)) && !signe(x); }
    2027   734904737 : INLINE int isintzero(GEN x) { return typ(x) == t_INT && !signe(x); }
    2028     5747809 : INLINE int isint1(GEN x) { return typ(x)==t_INT && equali1(x); }
    2029        4697 : INLINE int isintm1(GEN x){ return typ(x)==t_INT && equalim1(x);}
    2030   706577169 : INLINE int equali1(GEN n)
    2031   706577169 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(1)) && n[2] == 1; }
    2032    61450711 : INLINE int equalim1(GEN n)
    2033    61450711 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(-1)) && n[2] == 1; }
    2034             : /* works only for POSITIVE integers */
    2035  1062784620 : INLINE int is_pm1(GEN n)
    2036  1062784620 : { return lgefint(n) == 3 && n[2] == 1; }
    2037   247225549 : INLINE int is_bigint(GEN n)
    2038   247225549 : { long l = lgefint(n); return l > 3 || (l == 3 && (n[2] & HIGHBIT)); }
    2039             : 
    2040  2075631271 : INLINE int odd(long x) { return x & 1; }
    2041    29399900 : INLINE int both_odd(long x, long y) { return x & y & 1; }
    2042             : 
    2043             : INLINE int
    2044  2842747122 : isonstack(GEN x)
    2045  2842747122 : { return ((pari_sp)x >= pari_mainstack->bot
    2046  2842747122 :        && (pari_sp)x <  pari_mainstack->top); }
    2047             : 
    2048             : /* assume x != 0 and x t_REAL, return an approximation to log2(|x|) */
    2049             : INLINE double
    2050    23830302 : dbllog2r(GEN x)
    2051    23830302 : { return log2((double)(ulong)x[2]) + (double)(expo(x) - (BITS_IN_LONG-1)); }
    2052             : 
    2053             : INLINE GEN
    2054      393742 : mul_content(GEN cx, GEN cy)
    2055             : {
    2056      393742 :   if (!cx) return cy;
    2057      146207 :   if (!cy) return cx;
    2058      102229 :   return gmul(cx,cy);
    2059             : }
    2060             : INLINE GEN
    2061        6748 : inv_content(GEN c) { return c? ginv(c): NULL; }
    2062             : INLINE GEN
    2063     1818421 : mul_denom(GEN dx, GEN dy)
    2064             : {
    2065     1818421 :   if (!dx) return dy;
    2066     1212402 :   if (!dy) return dx;
    2067      379414 :   return mulii(dx,dy);
    2068             : }
    2069             : 
    2070             : /* POLYNOMIALS */
    2071             : INLINE GEN
    2072    17948938 : constant_coeff(GEN x) { return signe(x)? gel(x,2): gen_0; }
    2073             : INLINE GEN
    2074    95515044 : leading_coeff(GEN x) { return lg(x) == 2? gen_0: gel(x,lg(x)-1); }
    2075             : INLINE ulong
    2076      481393 : Flx_lead(GEN x) { return lg(x) == 2? 0: x[lg(x)-1]; }
    2077             : INLINE ulong
    2078       12313 : Flx_constant(GEN x) { return lg(x) == 2? 0: x[2]; }
    2079             : INLINE long
    2080  2927201550 : degpol(GEN x) { return lg(x)-3; }
    2081             : INLINE long
    2082  1437752280 : lgpol(GEN x) { return lg(x)-2; }
    2083             : INLINE long
    2084   126905133 : lgcols(GEN x) { return lg(gel(x,1)); }
    2085             : INLINE long
    2086    36174752 : nbrows(GEN x) { return lg(gel(x,1))-1; }
    2087             : INLINE GEN
    2088           0 : truecoef(GEN x, long n) { return polcoef(x,n,-1); }
    2089             : 
    2090             : INLINE GEN
    2091      573878 : ZXQ_mul(GEN y, GEN x, GEN T) { return ZX_rem(ZX_mul(y, x), T); }
    2092             : INLINE GEN
    2093      286062 : ZXQ_sqr(GEN x, GEN T) { return ZX_rem(ZX_sqr(x), T); }
    2094             : 
    2095             : INLINE GEN
    2096    81540331 : RgX_copy(GEN x)
    2097             : {
    2098             :   long lx, i;
    2099    81540331 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
    2100    81540329 :   for (i = 2; i<lx; i++) gel(y,i) = gcopy(gel(x,i));
    2101    81540326 :   return y;
    2102             : }
    2103             : /* have to use ulong to avoid silly warnings from gcc "assuming signed
    2104             :  * overflow does not occur" */
    2105             : INLINE GEN
    2106     2967049 : RgX_coeff(GEN x, long n)
    2107             : {
    2108     2967049 :   ulong l = lg(x);
    2109     2967049 :   return (n < 0 || ((ulong)n+3) > l)? gen_0: gel(x,n+2);
    2110             : }
    2111             : INLINE GEN
    2112      368623 : RgX_renormalize(GEN x) { return RgX_renormalize_lg(x, lg(x)); }
    2113             : INLINE GEN
    2114     6808252 : RgX_div(GEN x, GEN y) { return RgX_divrem(x,y,NULL); }
    2115             : INLINE GEN
    2116        1792 : RgXQX_div(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,NULL); }
    2117             : INLINE GEN
    2118       69621 : RgXQX_rem(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,ONLY_REM); }
    2119             : INLINE GEN
    2120     1030248 : FpX_div(GEN x, GEN y, GEN p) { return FpX_divrem(x,y,p, NULL); }
    2121             : INLINE GEN
    2122     4915526 : Flx_div(GEN x, GEN y, ulong p) { return Flx_divrem(x,y,p, NULL); }
    2123             : INLINE GEN
    2124     2604250 : F2x_div(GEN x, GEN y) { return F2x_divrem(x,y, NULL); }
    2125             : INLINE GEN
    2126           0 : FpV_FpC_mul(GEN x, GEN y, GEN p) { return FpV_dotproduct(x,y,p); }
    2127             : INLINE GEN
    2128    56215508 : pol0_Flx(long sv) { return mkvecsmall(sv); }
    2129             : INLINE GEN
    2130    15525558 : pol1_Flx(long sv) { return mkvecsmall2(sv, 1); }
    2131             : INLINE GEN
    2132    18082398 : polx_Flx(long sv) { return mkvecsmall3(sv, 0, 1); }
    2133             : INLINE GEN
    2134           0 : zero_zx(long sv) { return zero_Flx(sv); }
    2135             : INLINE GEN
    2136           0 : polx_zx(long sv) { return polx_Flx(sv); }
    2137             : INLINE GEN
    2138           0 : zx_shift(GEN x, long n) { return Flx_shift(x,n); }
    2139             : INLINE GEN
    2140           0 : zx_renormalize(GEN x, long l) { return Flx_renormalize(x,l); }
    2141             : INLINE GEN
    2142        1341 : zero_F2x(long sv) { return zero_Flx(sv); }
    2143             : INLINE GEN
    2144    11202917 : pol0_F2x(long sv) { return pol0_Flx(sv); }
    2145             : INLINE GEN
    2146     2888608 : pol1_F2x(long sv) { return pol1_Flx(sv); }
    2147             : INLINE GEN
    2148      692263 : polx_F2x(long sv) { return mkvecsmall2(sv, 2); }
    2149             : INLINE int
    2150      843936 : F2x_equal1(GEN x) { return Flx_equal1(x); }
    2151             : INLINE int
    2152     3132944 : F2x_equal(GEN V, GEN W) { return Flx_equal(V,W); }
    2153             : INLINE GEN
    2154    59939329 : F2x_copy(GEN x) { return leafcopy(x); }
    2155             : INLINE GEN
    2156           0 : F2v_copy(GEN x) { return leafcopy(x); }
    2157             : INLINE GEN
    2158     2276239 : Flv_copy(GEN x) { return leafcopy(x); }
    2159             : INLINE GEN
    2160    87134158 : Flx_copy(GEN x) { return leafcopy(x); }
    2161             : INLINE GEN
    2162     1913311 : vecsmall_copy(GEN x) { return leafcopy(x); }
    2163             : INLINE int
    2164     4923616 : Flx_equal1(GEN x) { return degpol(x)==0 && x[2] == 1; }
    2165             : INLINE int
    2166       18261 : ZX_equal1(GEN x) { return degpol(x)==0 && equali1(gel(x,2)); }
    2167             : INLINE int
    2168     5539537 : ZX_is_monic(GEN x) { return equali1(leading_coeff(x)); }
    2169             : 
    2170             : INLINE GEN
    2171    52522682 : ZX_renormalize(GEN x, long lx)    { return ZXX_renormalize(x,lx); }
    2172             : INLINE GEN
    2173    73913616 : FpX_renormalize(GEN x, long lx)   { return ZXX_renormalize(x,lx); }
    2174             : INLINE GEN
    2175      772518 : FpXX_renormalize(GEN x, long lx)  { return ZXX_renormalize(x,lx); }
    2176             : INLINE GEN
    2177     1251678 : FpXQX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
    2178             : INLINE GEN
    2179   112147089 : F2x_renormalize(GEN x, long lx)   { return Flx_renormalize(x,lx); }
    2180             : INLINE GEN
    2181       32385 : F2v_to_F2x(GEN x, long sv) {
    2182       32385 :   GEN y = leafcopy(x);
    2183       32385 :   y[1] = sv; F2x_renormalize(y, lg(y)); return y;
    2184             : }
    2185             : 
    2186             : INLINE long
    2187           0 : sturm(GEN x) { return sturmpart(x, NULL, NULL); }
    2188             : 
    2189             : INLINE long
    2190        7168 : gval(GEN x, long v) {
    2191        7168 :   pari_sp av = avma;
    2192        7168 :   long n = gvaluation(x, pol_x(v));
    2193        7168 :   set_avma(av); return n;
    2194             : }
    2195             : 
    2196             : INLINE void
    2197      471235 : RgX_shift_inplace_init(long v)
    2198      471235 : { if (v) (void)cgetg(v, t_VECSMALL); }
    2199             : /* shift polynomial in place. assume v free cells have been left before x */
    2200             : INLINE GEN
    2201      471235 : RgX_shift_inplace(GEN x, long v)
    2202             : {
    2203             :   long i, lx;
    2204             :   GEN y, z;
    2205      471235 :   if (!v) return x;
    2206      253227 :   lx = lg(x);
    2207      253227 :   if (lx == 2) return x;
    2208      253227 :   y = x + v;
    2209      253227 :   z = x + lx;
    2210             :   /* stackdummy from normalizepol: move it up */
    2211      253227 :   if (lg(z) != v) x[lx + v] = z[0];
    2212      253227 :   for (i = lx-1; i >= 2; i--) gel(y,i) = gel(x,i);
    2213      253227 :   for (i = v+1;  i >= 2; i--) gel(x,i) = gen_0;
    2214             :   /* leave x[1] alone: it is correct */
    2215      253227 :   x[0] = evaltyp(t_POL) | evallg(lx+v); return x;
    2216             : }
    2217             : 
    2218             : 
    2219             : /* LINEAR ALGEBRA */
    2220             : INLINE GEN
    2221      132603 : zv_to_ZV(GEN x) { return vecsmall_to_vec(x); }
    2222             : INLINE GEN
    2223     5228869 : zc_to_ZC(GEN x) { return vecsmall_to_col(x); }
    2224             : INLINE GEN
    2225     3300253 : ZV_to_zv(GEN x) { return vec_to_vecsmall(x); }
    2226             : INLINE GEN
    2227           0 : zx_to_zv(GEN x, long N) { return Flx_to_Flv(x,N); }
    2228             : INLINE GEN
    2229           0 : zv_to_zx(GEN x, long sv) { return Flv_to_Flx(x,sv); }
    2230             : INLINE GEN
    2231           0 : zm_to_zxV(GEN x, long sv) { return Flm_to_FlxV(x,sv); }
    2232             : INLINE GEN
    2233           0 : zero_zm(long x, long y) { return zero_Flm(x,y); }
    2234             : INLINE GEN
    2235    17661482 : zero_zv(long x) { return zero_Flv(x); }
    2236             : INLINE GEN
    2237         210 : zm_transpose(GEN x) { return Flm_transpose(x); }
    2238             : INLINE GEN
    2239           0 : zm_copy(GEN x) { return Flm_copy(x); }
    2240             : INLINE GEN
    2241     1903412 : zv_copy(GEN x) { return Flv_copy(x); }
    2242             : INLINE GEN
    2243           0 : zm_row(GEN x, long i) { return Flm_row(x,i); }
    2244             : 
    2245             : INLINE GEN
    2246      948749 : ZC_hnfrem(GEN x, GEN y) { return ZC_hnfremdiv(x,y,NULL); }
    2247             : INLINE GEN
    2248       50392 : ZM_hnfrem(GEN x, GEN y) { return ZM_hnfdivrem(x,y,NULL); }
    2249             : INLINE GEN
    2250     2470076 : ZM_lll(GEN x, double D, long f) { return ZM_lll_norms(x,D,f,NULL); }
    2251             : INLINE void
    2252     5677187 : RgM_dimensions(GEN x, long *m, long *n) { *n = lg(x)-1; *m = *n? nbrows(x): 0; }
    2253             : INLINE GEN
    2254    10608404 : RgM_shallowcopy(GEN x)
    2255             : {
    2256             :   long l;
    2257    10608404 :   GEN y = cgetg_copy(x, &l);
    2258    10608424 :   while (--l > 0) gel(y,l) = leafcopy(gel(x,l));
    2259    10608423 :   return y;
    2260             : }
    2261             : INLINE GEN
    2262       18954 : F2m_copy(GEN x) { return RgM_shallowcopy(x); }
    2263             : 
    2264             : INLINE GEN
    2265     1488807 : Flm_copy(GEN x) { return RgM_shallowcopy(x); }
    2266             : 
    2267             : /* divisibility: return 1 if y[i] | x[i] for all i, 0 otherwise. Assume
    2268             :  * x,y are ZV of the same length */
    2269             : INLINE int
    2270       23198 : ZV_dvd(GEN x, GEN y)
    2271             : {
    2272       23198 :   long i, l = lg(x);
    2273       36652 :   for (i=1; i < l; i++)
    2274       29519 :     if ( ! dvdii( gel(x,i), gel(y,i) ) ) return 0;
    2275        7133 :   return 1;
    2276             : }
    2277             : 
    2278             : /* Fq */
    2279             : INLINE GEN
    2280     2502266 : Fq_red(GEN x, GEN T, GEN p)
    2281     2502266 : { return typ(x)==t_INT? Fp_red(x,p): FpXQ_red(x,T,p); }
    2282             : INLINE GEN
    2283       99427 : Fq_to_FpXQ(GEN x, GEN T, GEN p /*unused*/)
    2284             : {
    2285             :   (void) p;
    2286       99427 :   return typ(x)==t_INT ? scalarpol(x, get_FpX_var(T)): x;
    2287             : }
    2288             : INLINE GEN
    2289         756 : Rg_to_Fq(GEN x, GEN T, GEN p) { return T? Rg_to_FpXQ(x,T,p): Rg_to_Fp(x,p); }
    2290             : 
    2291             : INLINE GEN
    2292        2289 : gener_Fq_local(GEN T, GEN p, GEN L)
    2293             : { return T? gener_FpXQ_local(T,p, L)
    2294        2289 :           : pgener_Fp_local(p, L); }
    2295             : 
    2296             : /* FpXQX */
    2297             : INLINE GEN
    2298        4347 : FpXQX_div(GEN x, GEN y, GEN T, GEN p) { return FpXQX_divrem(x, y, T, p, NULL); }
    2299             : INLINE GEN
    2300       35090 : FlxqX_div(GEN x, GEN y, GEN T, ulong p) { return FlxqX_divrem(x, y, T, p, NULL); }
    2301             : INLINE GEN
    2302       33299 : F2xqX_div(GEN x, GEN y, GEN T) { return F2xqX_divrem(x, y, T, NULL); }
    2303             : 
    2304             : /* FqX */
    2305             : INLINE GEN
    2306       25431 : FqX_red(GEN z, GEN T, GEN p) { return T? FpXQX_red(z, T, p): FpX_red(z, p); }
    2307             : INLINE GEN
    2308      957187 : FqX_add(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2309             : INLINE GEN
    2310       17404 : FqX_neg(GEN x,GEN T,GEN p) { return T? FpXX_neg(x,p): FpX_neg(x,p); }
    2311             : INLINE GEN
    2312        3234 : FqX_sub(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2313             : INLINE GEN
    2314      661750 : FqX_Fp_mul(GEN P, GEN u, GEN T, GEN p)
    2315      661750 : { return T? FpXX_Fp_mul(P, u, p): FpX_Fp_mul(P, u, p); }
    2316             : INLINE GEN
    2317      588211 : FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p)
    2318      588211 : { return typ(U)==t_INT ? FqX_Fp_mul(P, U, T, p): FpXQX_FpXQ_mul(P, U, T, p); }
    2319             : INLINE GEN
    2320       98666 : FqX_mul(GEN x, GEN y, GEN T, GEN p)
    2321       98666 : { return T? FpXQX_mul(x, y, T, p): FpX_mul(x, y, p); }
    2322             : INLINE GEN
    2323      489744 : FqX_mulu(GEN x, ulong y, GEN T, GEN p)
    2324      489744 : { return T? FpXX_mulu(x, y, p): FpX_mulu(x, y, p); }
    2325             : INLINE GEN
    2326        6468 : FqX_sqr(GEN x, GEN T, GEN p)
    2327        6468 : { return T? FpXQX_sqr(x, T, p): FpX_sqr(x, p); }
    2328             : INLINE GEN
    2329        1288 : FqX_powu(GEN x, ulong n, GEN T, GEN p)
    2330        1288 : { return T? FpXQX_powu(x, n, T, p): FpX_powu(x, n, p); }
    2331             : INLINE GEN
    2332           0 : FqX_halve(GEN x, GEN T, GEN p)
    2333           0 : { return T? FpXX_halve(x, p): FpX_halve(x, p); }
    2334             : INLINE GEN
    2335        5964 : FqX_div(GEN x, GEN y, GEN T, GEN p)
    2336        5964 : { return T? FpXQX_divrem(x,y,T,p,NULL): FpX_divrem(x,y,p,NULL); }
    2337             : INLINE GEN
    2338        6095 : FqX_get_red(GEN S, GEN T, GEN p)
    2339        6095 : { return T? FpXQX_get_red(S,T,p): FpX_get_red(S,p); }
    2340             : INLINE GEN
    2341       53108 : FqX_rem(GEN x, GEN y, GEN T, GEN p)
    2342       53108 : { return T? FpXQX_rem(x,y,T,p): FpX_rem(x,y,p); }
    2343             : INLINE GEN
    2344           0 : FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2345           0 : { return T? FpXQX_divrem(x,y,T,p,z): FpX_divrem(x,y,p,z); }
    2346             : INLINE GEN
    2347        5936 : FqX_div_by_X_x(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2348        5936 : { return T? FpXQX_div_by_X_x(x,y,T,p,z): FpX_div_by_X_x(x,y,p,z); }
    2349             : INLINE GEN
    2350           0 : FqX_halfgcd(GEN P,GEN Q,GEN T,GEN p)
    2351           0 : {return T? FpXQX_halfgcd(P,Q,T,p): FpX_halfgcd(P,Q,p);}
    2352             : INLINE GEN
    2353      259616 : FqX_gcd(GEN P,GEN Q,GEN T,GEN p)
    2354      259616 : {return T? FpXQX_gcd(P,Q,T,p): FpX_gcd(P,Q,p);}
    2355             : INLINE GEN
    2356       90627 : FqX_extgcd(GEN P,GEN Q,GEN T,GEN p, GEN *U, GEN *V)
    2357       90627 : { return T? FpXQX_extgcd(P,Q,T,p,U,V): FpX_extgcd(P,Q,p,U,V); }
    2358             : INLINE GEN
    2359        3437 : FqX_normalize(GEN z, GEN T, GEN p)
    2360        3437 : { return T? FpXQX_normalize(z, T, p): FpX_normalize(z, p); }
    2361             : INLINE GEN
    2362      272895 : FqX_deriv(GEN f, GEN T, GEN p) { return T? FpXX_deriv(f, p): FpX_deriv(f, p); }
    2363             : INLINE GEN
    2364           0 : FqX_integ(GEN f, GEN T, GEN p) { return T? FpXX_integ(f, p): FpX_integ(f, p); }
    2365             : INLINE GEN
    2366       74760 : FqX_factor(GEN f, GEN T, GEN p)
    2367       74760 : { return T?FpXQX_factor(f, T, p): FpX_factor(f, p); }
    2368             : INLINE GEN
    2369           7 : FqX_factor_squarefree(GEN f, GEN T, GEN p)
    2370           7 : { return T ? FpXQX_factor_squarefree(f, T, p): FpX_factor_squarefree(f, p); }
    2371             : INLINE GEN
    2372           7 : FqX_ddf(GEN f, GEN T, GEN p)
    2373           7 : { return T ? FpXQX_ddf(f, T, p): FpX_ddf(f, p); }
    2374             : INLINE GEN
    2375          42 : FqX_degfact(GEN f, GEN T, GEN p)
    2376          42 : { return T?FpXQX_degfact(f, T, p): FpX_degfact(f, p); }
    2377             : INLINE GEN
    2378        7126 : FqX_roots(GEN f, GEN T, GEN p)
    2379        7126 : { return T?FpXQX_roots(f, T, p): FpX_roots(f, p); }
    2380             : INLINE GEN
    2381         203 : FqX_to_mod(GEN f, GEN T, GEN p)
    2382         203 : { return T?FpXQX_to_mod(f, T, p): FpX_to_mod(f, p); }
    2383             : 
    2384             : /*FqXQ*/
    2385             : INLINE GEN
    2386           0 : FqXQ_add(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2387           0 : { (void)S; return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2388             : INLINE GEN
    2389           0 : FqXQ_sub(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2390           0 : { (void)S; return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2391             : INLINE GEN
    2392           0 : FqXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p)
    2393           0 : { return T? FpXQXQ_div(x,y,S,T,p): FpXQ_div(x,y,S,p); }
    2394             : INLINE GEN
    2395           0 : FqXQ_inv(GEN x, GEN S, GEN T, GEN p)
    2396           0 : { return T? FpXQXQ_inv(x,S,T,p): FpXQ_inv(x,S,p); }
    2397             : INLINE GEN
    2398           0 : FqXQ_invsafe(GEN x, GEN S, GEN T, GEN p)
    2399           0 : { return T? FpXQXQ_invsafe(x,S,T,p): FpXQ_inv(x,S,p); }
    2400             : INLINE GEN
    2401       22348 : FqXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p)
    2402       22348 : { return T? FpXQXQ_mul(x,y,S,T,p): FpXQ_mul(x,y,S,p); }
    2403             : INLINE GEN
    2404           0 : FqXQ_sqr(GEN x, GEN S, GEN T, GEN p)
    2405           0 : { return T? FpXQXQ_sqr(x,S,T,p): FpXQ_sqr(x,S,p); }
    2406             : INLINE GEN
    2407           0 : FqXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p)
    2408           0 : { return T? FpXQXQ_pow(x,n,S,T,p): FpXQ_pow(x,n,S,p); }
    2409             : 
    2410             : /*FqXn*/
    2411             : INLINE GEN
    2412           0 : FqXn_exp(GEN x, long n, GEN T, GEN p)
    2413           0 : { return T? FpXQXn_exp(x,n,T,p): FpXn_exp(x,n,p); }
    2414             : INLINE GEN
    2415           0 : FqXn_inv(GEN x, long n, GEN T, GEN p)
    2416           0 : { return T? FpXQXn_inv(x,n,T,p): FpXn_inv(x,n,p); }
    2417             : INLINE GEN
    2418           0 : FqXn_mul(GEN x, GEN y, long n, GEN T, GEN p)
    2419           0 : { return T? FpXQXn_mul(x, y, n, T, p): FpXn_mul(x, y, n, p); }
    2420             : INLINE GEN
    2421           0 : FqXn_sqr(GEN x, long n, GEN T, GEN p)
    2422           0 : { return T? FpXQXn_sqr(x,n,T,p): FpXn_sqr(x,n,p); }
    2423             : 
    2424             : /*FpXQ*/
    2425             : INLINE GEN
    2426           0 : FpXQ_add(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2427           0 : { (void)T; return FpX_add(x,y,p); }
    2428             : INLINE GEN
    2429           0 : FpXQ_sub(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2430           0 : { (void)T; return FpX_sub(x,y,p); }
    2431             : 
    2432             : /*Flxq*/
    2433             : INLINE GEN
    2434           0 : Flxq_add(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2435           0 : { (void)T; return Flx_add(x,y,p); }
    2436             : INLINE GEN
    2437           0 : Flxq_sub(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2438           0 : { (void)T; return Flx_sub(x,y,p); }
    2439             : 
    2440             : /* F2x */
    2441             : 
    2442             : INLINE ulong
    2443   102839507 : F2x_coeff(GEN x,long v)
    2444             : {
    2445   102839507 :    ulong u=(ulong)x[2+divsBIL(v)];
    2446   102837178 :    return (u>>remsBIL(v))&1UL;
    2447             : }
    2448             : 
    2449             : INLINE void
    2450     5066848 : F2x_clear(GEN x,long v)
    2451             : {
    2452     5066848 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2453     5066847 :    *u&=~(1UL<<remsBIL(v));
    2454     5066846 : }
    2455             : 
    2456             : INLINE void
    2457    33174853 : F2x_set(GEN x,long v)
    2458             : {
    2459    33174853 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2460    33159704 :    *u|=1UL<<remsBIL(v);
    2461    33153952 : }
    2462             : 
    2463             : INLINE void
    2464     1502171 : F2x_flip(GEN x,long v)
    2465             : {
    2466     1502171 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2467     1502171 :    *u^=1UL<<remsBIL(v);
    2468     1502172 : }
    2469             : 
    2470             : /* F2v */
    2471             : 
    2472             : INLINE ulong
    2473    98158773 : F2v_coeff(GEN x,long v) { return F2x_coeff(x,v-1); }
    2474             : 
    2475             : INLINE void
    2476     5066836 : F2v_clear(GEN x,long v) { F2x_clear(x,v-1); }
    2477             : 
    2478             : INLINE void
    2479     9279433 : F2v_set(GEN x,long v)   { F2x_set(x,v-1); }
    2480             : 
    2481             : INLINE void
    2482     1502171 : F2v_flip(GEN x,long v) { F2x_flip(x,v-1); }
    2483             : 
    2484             : /* F2m */
    2485             : 
    2486             : INLINE ulong
    2487    12242338 : F2m_coeff(GEN x, long a, long b) { return F2v_coeff(gel(x,b), a); }
    2488             : 
    2489             : INLINE void
    2490           0 : F2m_clear(GEN x, long a, long b) { F2v_clear(gel(x,b), a); }
    2491             : 
    2492             : INLINE void
    2493     1362615 : F2m_set(GEN x, long a, long b) { F2v_set(gel(x,b), a); }
    2494             : 
    2495             : INLINE void
    2496     1502171 : F2m_flip(GEN x, long a, long b) { F2v_flip(gel(x,b), a); }
    2497             : 
    2498             : /* ARITHMETIC */
    2499             : INLINE GEN
    2500        1071 : matpascal(long n) { return matqpascal(n, NULL); }
    2501             : INLINE long
    2502     2334539 : Z_issquare(GEN x) { return Z_issquareall(x, NULL); }
    2503             : INLINE long
    2504          14 : Z_ispower(GEN x, ulong k) { return Z_ispowerall(x, k, NULL); }
    2505             : INLINE GEN
    2506     5912882 : sqrti(GEN x) { return sqrtremi(x,NULL); }
    2507             : INLINE GEN
    2508     6090927 : gaddgs(GEN y, long s) { return gaddsg(s,y); }
    2509             : INLINE int
    2510       59870 : gcmpgs(GEN y, long s) { return -gcmpsg(s,y); }
    2511             : INLINE int
    2512       24570 : gequalgs(GEN y, long s) { return gequalsg(s,y); }
    2513             : INLINE GEN
    2514           0 : gmaxsg(long s, GEN y) { return gmaxgs(y,s); }
    2515             : INLINE GEN
    2516           0 : gminsg(long s, GEN y) { return gmings(y,s); }
    2517             : INLINE GEN
    2518    15106309 : gmulgs(GEN y, long s) { return gmulsg(s,y); }
    2519             : INLINE GEN
    2520     1353377 : gsubgs(GEN y, long s) { return gaddgs(y, -s); }
    2521             : INLINE GEN
    2522      690844 : gdivsg(long s, GEN y) { return gdiv(stoi(s), y); }
    2523             : 
    2524             : /* x t_COMPLEX */
    2525             : INLINE GEN
    2526    14038802 : cxnorm(GEN x) { return gadd(gsqr(gel(x,1)), gsqr(gel(x,2))); }
    2527             : /* q t_QUAD */
    2528             : INLINE GEN
    2529         623 : quadnorm(GEN q)
    2530             : {
    2531         623 :   GEN X = gel(q,1), b = gel(X,3), c = gel(X,2);
    2532         623 :   GEN z, u = gel(q,3), v = gel(q,2);
    2533         623 :   if (typ(u) == t_INT && typ(v) == t_INT) /* generic case */
    2534             :   {
    2535         308 :     z = signe(b)? mulii(v, addii(u,v)): sqri(v);
    2536         308 :     return addii(z, mulii(c, sqri(u)));
    2537             :   }
    2538             :   else
    2539             :   {
    2540         315 :     z = signe(b)? gmul(v, gadd(u,v)): gsqr(v);
    2541         315 :     return gadd(z, gmul(c, gsqr(u)));
    2542             :   }
    2543             : }
    2544             : /* x a t_QUAD, return the attached discriminant */
    2545             : INLINE GEN
    2546         273 : quad_disc(GEN x)
    2547             : {
    2548         273 :   GEN Q = gel(x,1), b = gel(Q,3), c = gel(Q,2), c4;
    2549         273 :   if (is_pm1(b))
    2550             :   {
    2551         217 :     pari_sp av = avma; (void)new_chunk(lgefint(c) + 1);
    2552         217 :     c4 = shifti(c,2); set_avma(av); return subsi(1, c4);
    2553             :   }
    2554          56 :   c4 = shifti(c,2); togglesign_safe(&c4); return c4;
    2555             : }
    2556             : INLINE GEN
    2557     6386709 : qfb_disc3(GEN x, GEN y, GEN z) { return subii(sqri(y), shifti(mulii(x,z),2)); }
    2558             : INLINE GEN
    2559     6305775 : qfb_disc(GEN x) { return qfb_disc3(gel(x,1), gel(x,2), gel(x,3)); }
    2560             : 
    2561             : INLINE GEN
    2562     1286702 : sqrfrac(GEN x)
    2563             : {
    2564     1286702 :   GEN z = cgetg(3,t_FRAC);
    2565     1286702 :   gel(z,1) = sqri(gel(x,1));
    2566     1286702 :   gel(z,2) = sqri(gel(x,2)); return z;
    2567             : }
    2568             : 
    2569             : INLINE void
    2570    34480664 : normalize_frac(GEN z) {
    2571    34480664 :   if (signe(gel(z,2)) < 0) { togglesign(gel(z,1)); setabssign(gel(z,2)); }
    2572    34480664 : }
    2573             : 
    2574             : INLINE GEN
    2575      270579 : powii(GEN x, GEN n)
    2576             : {
    2577      270579 :   long ln = lgefint(n);
    2578      270579 :   if (ln == 3) {
    2579             :     GEN z;
    2580      266141 :     if (signe(n) > 0) return powiu(x, n[2]);
    2581        8344 :     z = cgetg(3, t_FRAC);
    2582        8344 :     gel(z,1) = gen_1;
    2583        8344 :     gel(z,2) = powiu(x, n[2]);
    2584        8344 :     return z;
    2585             :   }
    2586        4438 :   if (ln == 2) return gen_1; /* rare */
    2587             :   /* should never happen */
    2588           0 :   return powgi(x, n); /* overflow unless x = 0, 1, -1 */
    2589             : }
    2590             : INLINE GEN
    2591        1246 : powIs(long n) {
    2592        1246 :   switch(n & 3)
    2593             :   {
    2594          28 :     case 1: return mkcomplex(gen_0,gen_1);
    2595         378 :     case 2: return gen_m1;
    2596         518 :     case 3: return mkcomplex(gen_0,gen_m1);
    2597             :   }
    2598         322 :   return gen_1;
    2599             : }
    2600             : 
    2601             : /*******************************************************************/
    2602             : /*                                                                 */
    2603             : /*                             ASSIGNMENTS                         */
    2604             : /*                                                                 */
    2605             : /*******************************************************************/
    2606           0 : INLINE void mpexpz(GEN x, GEN z)
    2607           0 : { pari_sp av = avma; gaffect(mpexp(x), z); set_avma(av); }
    2608           0 : INLINE void mplogz(GEN x, GEN z)
    2609           0 : { pari_sp av = avma; gaffect(mplog(x), z); set_avma(av); }
    2610           0 : INLINE void mpcosz(GEN x, GEN z)
    2611           0 : { pari_sp av = avma; gaffect(mpcos(x), z); set_avma(av); }
    2612           0 : INLINE void mpsinz(GEN x, GEN z)
    2613           0 : { pari_sp av = avma; gaffect(mpsin(x), z); set_avma(av); }
    2614           0 : INLINE void gnegz(GEN x, GEN z)
    2615           0 : { pari_sp av = avma; gaffect(gneg(x), z); set_avma(av); }
    2616           0 : INLINE void gabsz(GEN x, long prec, GEN z)
    2617           0 : { pari_sp av = avma; gaffect(gabs(x,prec), z); set_avma(av); }
    2618           0 : INLINE void gaddz(GEN x, GEN y, GEN z)
    2619           0 : { pari_sp av = avma; gaffect(gadd(x,y), z); set_avma(av); }
    2620           0 : INLINE void gsubz(GEN x, GEN y, GEN z)
    2621           0 : { pari_sp av = avma; gaffect(gsub(x,y), z); set_avma(av); }
    2622           0 : INLINE void gmulz(GEN x, GEN y, GEN z)
    2623           0 : { pari_sp av = avma; gaffect(gmul(x,y), z); set_avma(av); }
    2624           0 : INLINE void gdivz(GEN x, GEN y, GEN z)
    2625           0 : { pari_sp av = avma; gaffect(gdiv(x,y), z); set_avma(av); }
    2626           0 : INLINE void gdiventz(GEN x, GEN y, GEN z)
    2627           0 : { pari_sp av = avma; gaffect(gdivent(x,y), z); set_avma(av); }
    2628           0 : INLINE void gmodz(GEN x, GEN y, GEN z)
    2629           0 : { pari_sp av = avma; gaffect(gmod(x,y), z); set_avma(av); }
    2630           0 : INLINE void gmul2nz(GEN x, long s, GEN z)
    2631           0 : { pari_sp av = avma; gaffect(gmul2n(x,s), z); set_avma(av); }
    2632           0 : INLINE void gshiftz(GEN x, long s, GEN z)
    2633           0 : { pari_sp av = avma; gaffect(gshift(x,s), z); set_avma(av); }
    2634             : 
    2635             : /*******************************************************************/
    2636             : /*                                                                 */
    2637             : /*                       ELLIPTIC CURVES                           */
    2638             : /*                                                                 */
    2639             : /*******************************************************************/
    2640     3980923 : INLINE GEN ell_get_a1(GEN e) { return gel(e,1); }
    2641     3096017 : INLINE GEN ell_get_a2(GEN e) { return gel(e,2); }
    2642     3862763 : INLINE GEN ell_get_a3(GEN e) { return gel(e,3); }
    2643     3888900 : INLINE GEN ell_get_a4(GEN e) { return gel(e,4); }
    2644     4705037 : INLINE GEN ell_get_a6(GEN e) { return gel(e,5); }
    2645     3319174 : INLINE GEN ell_get_b2(GEN e) { return gel(e,6); }
    2646     1025005 : INLINE GEN ell_get_b4(GEN e) { return gel(e,7); }
    2647     1630673 : INLINE GEN ell_get_b6(GEN e) { return gel(e,8); }
    2648     1464043 : INLINE GEN ell_get_b8(GEN e) { return gel(e,9); }
    2649     6168456 : INLINE GEN ell_get_c4(GEN e) { return gel(e,10); }
    2650     7404240 : INLINE GEN ell_get_c6(GEN e) { return gel(e,11); }
    2651     9654856 : INLINE GEN ell_get_disc(GEN e) { return gel(e,12); }
    2652     1028909 : INLINE GEN ell_get_j(GEN e) { return gel(e,13); }
    2653    11457114 : INLINE long ell_get_type(GEN e) { return mael(e,14,1); }
    2654     1571754 : INLINE GEN ellff_get_field(GEN x) { return gmael(x, 15, 1); }
    2655      683460 : INLINE GEN ellff_get_a4a6(GEN x)  { return gmael(x, 15, 2); }
    2656        1407 : INLINE GEN ellQp_get_zero(GEN x) { return gmael(x, 15, 1); }
    2657         287 : INLINE long ellQp_get_prec(GEN E) { GEN z = ellQp_get_zero(E); return valp(z); }
    2658        1085 : INLINE GEN ellQp_get_p(GEN E) { GEN z = ellQp_get_zero(E); return gel(z,2); }
    2659       37156 : INLINE long ellR_get_prec(GEN x) { return nbits2prec(mael3(x, 15, 1, 1)); }
    2660       12106 : INLINE long ellR_get_sign(GEN x) { return mael3(x, 15, 1, 2); }
    2661      700060 : INLINE GEN ellnf_get_nf(GEN x) { return checknf_i(gmael(x,15,1)); }
    2662          56 : INLINE GEN ellnf_get_bnf(GEN x) { return checkbnf_i(gmael(x,15,1)); }
    2663             : 
    2664     4626258 : INLINE int checkell_i(GEN e) { return typ(e) == t_VEC && lg(e) == 17; }
    2665    33987537 : INLINE int ell_is_inf(GEN z) { return lg(z) == 2; }
    2666      810472 : INLINE GEN ellinf(void) { return mkvec(gen_0); }
    2667             : 
    2668             : /*******************************************************************/
    2669             : /*                                                                 */
    2670             : /*                    ALGEBRAIC NUMBER THEORY                      */
    2671             : /*                                                                 */
    2672             : /*******************************************************************/
    2673     8605334 : INLINE GEN modpr_get_pr(GEN x)  { return gel(x,3); }
    2674      609840 : INLINE GEN modpr_get_p(GEN x)  { return pr_get_p(modpr_get_pr(x)); }
    2675     2751668 : INLINE GEN modpr_get_T(GEN x)  { return lg(x) == 4? NULL: gel(x,4); }
    2676             : 
    2677    20621848 : INLINE GEN pr_get_p(GEN pr)  { return gel(pr,1); }
    2678     6957493 : INLINE GEN pr_get_gen(GEN pr){ return gel(pr,2); }
    2679             : /* .[2] instead of itos works: e and f are small positive integers */
    2680     2412885 : INLINE long pr_get_e(GEN pr) { return gel(pr,3)[2]; }
    2681     9599293 : INLINE long pr_get_f(GEN pr) { return gel(pr,4)[2]; }
    2682     6538742 : INLINE GEN pr_get_tau(GEN pr){ return gel(pr,5); }
    2683             : INLINE int
    2684     3289328 : pr_is_inert(GEN P) { return pr_get_f(P) == lg(pr_get_gen(P))-1; }
    2685             : INLINE GEN
    2686      240189 : pr_norm(GEN pr) { return powiu(pr_get_p(pr), pr_get_f(pr)); }
    2687             : INLINE ulong
    2688       48083 : upr_norm(GEN pr) { return upowuu(pr_get_p(pr)[2], pr_get_f(pr)); }
    2689             : 
    2690             : /* assume nf a genuine nf */
    2691             : INLINE long
    2692      394763 : nf_get_varn(GEN nf) { return varn(gel(nf,1)); }
    2693             : INLINE GEN
    2694    34326819 : nf_get_pol(GEN nf) { return gel(nf,1); }
    2695             : INLINE long
    2696    27342079 : nf_get_degree(GEN nf) { return degpol( nf_get_pol(nf) ); }
    2697             : INLINE long
    2698     4176642 : nf_get_r1(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,1)); }
    2699             : INLINE long
    2700        1680 : nf_get_r2(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,2)); }
    2701             : INLINE GEN
    2702       58394 : nf_get_disc(GEN nf) { return gel(nf,3); }
    2703             : INLINE GEN
    2704      876883 : nf_get_index(GEN nf) { return gel(nf,4); }
    2705             : INLINE GEN
    2706     2899044 : nf_get_M(GEN nf) { return gmael(nf,5,1); }
    2707             : INLINE GEN
    2708       85794 : nf_get_G(GEN nf) { return gmael(nf,5,2); }
    2709             : INLINE GEN
    2710      426779 : nf_get_roundG(GEN nf) { return gmael(nf,5,3); }
    2711             : INLINE GEN
    2712       24367 : nf_get_Tr(GEN nf) { return gmael(nf,5,4); }
    2713             : INLINE GEN
    2714        2331 : nf_get_diff(GEN nf) { return gmael(nf,5,5); }
    2715             : INLINE GEN
    2716         196 : nf_get_ramified_primes(GEN nf) { return gmael(nf,5,8); }
    2717             : INLINE GEN
    2718      383401 : nf_get_roots(GEN nf) { return gel(nf,6); }
    2719             : INLINE GEN
    2720          98 : nf_get_zk(GEN nf)
    2721             : {
    2722          98 :   GEN y = gel(nf,7), D = gel(y, 1);
    2723          98 :   if (typ(D) == t_POL) D = gel(D, 2);
    2724          98 :   if (!equali1(D)) y = gdiv(y, D);
    2725          98 :   return y;
    2726             : }
    2727             : INLINE GEN
    2728      287346 : nf_get_zkprimpart(GEN nf)
    2729             : {
    2730      287346 :   GEN y = gel(nf,7);
    2731             :   /* test for old format of nf.zk: non normalized */
    2732      287346 :   if (!equali1(gel(nf,4)) && gequal1(gel(y,1))) y = Q_remove_denom(y,NULL);
    2733      287345 :   return y;
    2734             : }
    2735             : INLINE GEN
    2736      288653 : nf_get_zkden(GEN nf)
    2737             : {
    2738      288653 :   GEN y = gel(nf,7), D = gel(y,1);
    2739      288653 :   if (typ(D) == t_POL) D = gel(D,2);
    2740             :   /* test for old format of nf.zk: non normalized */
    2741      288653 :   if (!equali1(gel(nf,4)) && equali1(D)) D = Q_denom(y);
    2742      288651 :   return D;
    2743             : }
    2744             : INLINE GEN
    2745     2694422 : nf_get_invzk(GEN nf) { return gel(nf,8); }
    2746             : INLINE void
    2747       23480 : nf_get_sign(GEN nf, long *r1, long *r2)
    2748             : {
    2749       23480 :   GEN x = gel(nf,2);
    2750       23480 :   *r1 = itou(gel(x,1));
    2751       23480 :   *r2 = itou(gel(x,2));
    2752       23480 : }
    2753             : 
    2754             : INLINE GEN
    2755       94921 : abgrp_get_no(GEN x) { return gel(x,1); }
    2756             : INLINE GEN
    2757     2510802 : abgrp_get_cyc(GEN x) { return gel(x,2); }
    2758             : INLINE GEN
    2759      457804 : abgrp_get_gen(GEN x) { return gel(x,3); }
    2760             : INLINE GEN
    2761     2305917 : bnf_get_nf(GEN bnf) { return gel(bnf,7); }
    2762             : INLINE GEN
    2763      904905 : bnf_get_clgp(GEN bnf) { return gmael(bnf,8,1); }
    2764             : INLINE GEN
    2765        7091 : bnf_get_no(GEN bnf) { return abgrp_get_no(bnf_get_clgp(bnf)); }
    2766             : INLINE GEN
    2767      487666 : bnf_get_cyc(GEN bnf) { return abgrp_get_cyc(bnf_get_clgp(bnf)); }
    2768             : INLINE GEN
    2769      409819 : bnf_get_gen(GEN bnf)  { return abgrp_get_gen(bnf_get_clgp(bnf)); }
    2770             : INLINE GEN
    2771         846 : bnf_get_reg(GEN bnf) { return gmael(bnf,8,2); }
    2772             : INLINE GEN
    2773      510247 : bnf_get_logfu(GEN bnf) { return gel(bnf,3); }
    2774             : INLINE GEN
    2775        8738 : bnf_get_tuU(GEN bnf) { return gmael3(bnf,8,4,2); }
    2776             : INLINE long
    2777       41853 : bnf_get_tuN(GEN bnf) { return gmael3(bnf,8,4,1)[2]; }
    2778             : INLINE GEN
    2779        1778 : bnf_get_fu(GEN bnf) {
    2780        1778 :   GEN fu = bnf_get_fu_nocheck(bnf);
    2781        1778 :   if (typ(fu) == t_MAT) pari_err(e_MISC,"missing units in bnf");
    2782        1778 :   return fu;
    2783             : }
    2784             : INLINE GEN
    2785       10103 : bnf_get_fu_nocheck(GEN bnf) { return gmael(bnf,8,5); }
    2786             : 
    2787             : INLINE GEN
    2788      904986 : bnr_get_bnf(GEN bnr) { return gel(bnr,1); }
    2789             : INLINE GEN
    2790      463154 : bnr_get_bid(GEN bnr) { return gel(bnr,2); }
    2791             : INLINE GEN
    2792       20125 : bnr_get_mod(GEN bnr) { return gmael(bnr,2,1); }
    2793             : INLINE GEN
    2794       34510 : bnr_get_nf(GEN bnr) { return gmael(bnr,1,7); }
    2795             : INLINE GEN
    2796      709435 : bnr_get_clgp(GEN bnr) { return gel(bnr,5); }
    2797             : INLINE GEN
    2798       84063 : bnr_get_no(GEN bnr) { return abgrp_get_no(bnr_get_clgp(bnr)); }
    2799             : INLINE GEN
    2800      609076 : bnr_get_cyc(GEN bnr) { return abgrp_get_cyc(bnr_get_clgp(bnr)); }
    2801             : INLINE GEN
    2802          70 : bnr_get_gen_nocheck(GEN bnr) { return abgrp_get_gen(bnr_get_clgp(bnr)); }
    2803             : INLINE GEN
    2804       14931 : bnr_get_gen(GEN bnr) {
    2805       14931 :   GEN G = bnr_get_clgp(bnr);
    2806       14931 :   if (lg(G) !=  4)
    2807           0 :     pari_err(e_MISC,"missing bnr generators: please use bnrinit(,,1)");
    2808       14931 :   return gel(G,3);
    2809             : }
    2810             : 
    2811             : INLINE GEN
    2812      337266 : bid_get_mod(GEN bid) { return gel(bid,1); }
    2813             : INLINE GEN
    2814       67634 : bid_get_ideal(GEN bid) { return gmael(bid,1,1); }
    2815             : INLINE GEN
    2816        1246 : bid_get_arch(GEN bid) { return gmael(bid,1,2); }
    2817             : INLINE GEN
    2818     1271932 : bid_get_grp(GEN bid) { return gel(bid,2); }
    2819             : INLINE GEN
    2820      506428 : bid_get_fact(GEN bid) { return gmael(bid,3,1); }
    2821             : INLINE GEN
    2822      436183 : bid_get_fact2(GEN bid) { return gmael(bid,3,2); }
    2823             : INLINE GEN
    2824      435252 : bid_get_sprk(GEN bid) { return gmael(bid,4,1); }
    2825             : INLINE GEN
    2826       49322 : bid_get_sarch(GEN bid) { return gmael(bid,4,2); }
    2827             : INLINE GEN
    2828      471442 : bid_get_archp(GEN bid) { return gmael3(bid,4,2,2); }
    2829             : INLINE GEN
    2830      772749 : bid_get_U(GEN bid) { return gel(bid,5); }
    2831             : INLINE GEN
    2832           0 : bid_get_no(GEN bid) { return abgrp_get_no(bid_get_grp(bid)); }
    2833             : INLINE GEN
    2834     1224941 : bid_get_cyc(GEN bid) { return abgrp_get_cyc(bid_get_grp(bid)); }
    2835             : INLINE GEN
    2836           0 : bid_get_gen_nocheck(GEN bid)  { return abgrp_get_gen(bid_get_grp(bid)); }
    2837             : INLINE GEN
    2838       46396 : bid_get_gen(GEN bid) {
    2839       46396 :   GEN G = bid_get_grp(bid);
    2840       46396 :   if (lg(G) != 4) pari_err(e_MISC,"missing bid generators. Use idealstar(,,2)");
    2841       46396 :   return abgrp_get_gen(G);
    2842             : }
    2843             : 
    2844             : INLINE GEN
    2845    25486258 : znstar_get_N(GEN G) { return gmael(G,1,1); }
    2846             : INLINE GEN
    2847     2838927 : znstar_get_faN(GEN G) { return gel(G,3); }
    2848             : INLINE GEN
    2849           7 : znstar_get_no(GEN G) { return abgrp_get_no(gel(G,2)); }
    2850             : INLINE GEN
    2851      187698 : znstar_get_cyc(GEN G) { return abgrp_get_cyc(gel(G,2)); }
    2852             : INLINE GEN
    2853           7 : znstar_get_gen(GEN G) { return abgrp_get_gen(gel(G,2)); }
    2854             : INLINE GEN
    2855     3513202 : znstar_get_conreycyc(GEN G) { return gmael(G,4,5); }
    2856             : INLINE GEN
    2857     1202845 : znstar_get_conreygen(GEN G) { return gmael(G,4,4); }
    2858             : INLINE GEN
    2859       45920 : znstar_get_Ui(GEN G) { return gmael(G,4,3); }
    2860             : INLINE GEN
    2861      118202 : znstar_get_U(GEN G) { return gel(G,5); }
    2862             : INLINE GEN
    2863      811391 : znstar_get_pe(GEN G) { return gmael(G,4,1); }
    2864             : INLINE GEN
    2865       19922 : gal_get_pol(GEN gal) { return gel(gal,1); }
    2866             : INLINE GEN
    2867        1330 : gal_get_p(GEN gal) { return gmael(gal,2,1); }
    2868             : INLINE GEN
    2869          84 : gal_get_e(GEN gal) { return gmael(gal,2,2); }
    2870             : INLINE GEN
    2871       15981 : gal_get_mod(GEN gal) { return gmael(gal,2,3); }
    2872             : INLINE GEN
    2873       16359 : gal_get_roots(GEN gal) { return gel(gal,3); }
    2874             : INLINE GEN
    2875       15932 : gal_get_invvdm(GEN gal) { return gel(gal,4); }
    2876             : INLINE GEN
    2877       15932 : gal_get_den(GEN gal) { return gel(gal,5); }
    2878             : INLINE GEN
    2879       67158 : gal_get_group(GEN gal) { return gel(gal,6); }
    2880             : INLINE GEN
    2881        1750 : gal_get_gen(GEN gal) { return gel(gal,7); }
    2882             : INLINE GEN
    2883        1386 : gal_get_orders(GEN gal) { return gel(gal,8); }
    2884             : 
    2885             : /* assume rnf a genuine rnf */
    2886             : INLINE long
    2887     1233841 : rnf_get_degree(GEN rnf) { return degpol(rnf_get_pol(rnf)); }
    2888             : INLINE long
    2889       16674 : rnf_get_nfdegree(GEN rnf) { return degpol(nf_get_pol(rnf_get_nf(rnf))); }
    2890             : INLINE long
    2891      775698 : rnf_get_absdegree(GEN rnf) { return degpol(gmael(rnf,11,1)); }
    2892             : INLINE GEN
    2893         700 : rnf_get_idealdisc(GEN rnf) { return gmael(rnf,3,1); }
    2894             : INLINE GEN
    2895         742 : rnf_get_k(GEN rnf) { return gmael(rnf,11,3); }
    2896             : INLINE GEN
    2897         791 : rnf_get_alpha(GEN rnf) { return gmael(rnf, 11, 2); }
    2898             : INLINE GEN
    2899      427735 : rnf_get_nf(GEN rnf) { return gel(rnf,10); }
    2900             : INLINE GEN
    2901        3787 : rnf_get_nfzk(GEN rnf) { return gel(rnf,2); }
    2902             : INLINE GEN
    2903      214886 : rnf_get_polabs(GEN rnf) { return gmael(rnf,11,1); }
    2904             : INLINE GEN
    2905     1480052 : rnf_get_pol(GEN rnf) { return gel(rnf,1); }
    2906             : INLINE GEN
    2907          63 : rnf_get_disc(GEN rnf) { return gel(rnf,3); }
    2908             : INLINE GEN
    2909         105 : rnf_get_index(GEN rnf) { return gel(rnf,4); }
    2910             : INLINE long
    2911           0 : rnf_get_varn(GEN rnf) { return varn(gel(rnf,1)); }
    2912             : INLINE GEN
    2913      188580 : rnf_get_nfpol(GEN rnf) { return gmael(rnf,10,1); }
    2914             : INLINE long
    2915        3325 : rnf_get_nfvarn(GEN rnf) { return varn(gmael(rnf,10,1)); }
    2916             : INLINE GEN
    2917        3493 : rnf_get_zk(GEN rnf) { return gel(rnf,7); }
    2918             : INLINE GEN
    2919       97321 : rnf_get_map(GEN rnf) { return gel(rnf,11); }
    2920             : INLINE GEN
    2921        1197 : rnf_get_invzk(GEN rnf) { return gel(rnf,8); }
    2922             : 
    2923             : /* I integral ZM (not HNF), G ZM, rounded Cholesky form of a weighted
    2924             :  * T2 matrix. Reduce I wrt G */
    2925             : INLINE GEN
    2926       21966 : idealpseudored(GEN I, GEN G)
    2927       21966 : { return ZM_mul(I, ZM_lll(ZM_mul(G, I), 0.99, LLL_IM)); }
    2928             : 
    2929             : /* I integral (not necessarily HNF), G ZM, rounded Cholesky form of a weighted
    2930             :  * T2 matrix. Return m in I with T2(m) small */
    2931             : INLINE GEN
    2932      145876 : idealpseudomin(GEN I, GEN G)
    2933             : {
    2934      145876 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2935      145876 :   return ZM_ZC_mul(I, gel(u,1));
    2936             : }
    2937             : /* I, G as in idealpseudomin. Return an irrational m in I with T2(m) small */
    2938             : INLINE GEN
    2939      313936 : idealpseudomin_nonscalar(GEN I, GEN G)
    2940             : {
    2941      313936 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2942      313936 :   GEN m = ZM_ZC_mul(I, gel(u,1));
    2943      313936 :   if (ZV_isscalar(m) && lg(u) > 2) m = ZM_ZC_mul(I, gel(u,2));
    2944      313936 :   return m;
    2945             : }
    2946             : 
    2947             : INLINE GEN
    2948         938 : idealred_elt(GEN nf, GEN I) {
    2949         938 :   pari_sp av = avma;
    2950         938 :   GEN u = idealpseudomin(I, nf_get_roundG(nf));
    2951         938 :   return gerepileupto(av, u);
    2952             : }
    2953             : INLINE GEN
    2954      127932 : idealred(GEN nf, GEN I) { return idealred0(nf, I, NULL); }
    2955             : 
    2956             : INLINE GEN
    2957        2058 : idealchineseinit(GEN nf, GEN x)
    2958        2058 : { return idealchinese(nf,x,NULL); }
    2959             : 
    2960             : /*******************************************************************/
    2961             : /*                                                                 */
    2962             : /*                              CLOSURES                           */
    2963             : /*                                                                 */
    2964             : /*******************************************************************/
    2965   225595824 : INLINE long closure_arity(GEN C)          { return ((ulong)C[1])&ARITYBITS; }
    2966    35537228 : INLINE long closure_is_variadic(GEN C) { return !!(((ulong)C[1])&VARARGBITS); }
    2967   189732516 : INLINE const char *closure_codestr(GEN C)  { return GSTR(gel(C,2))-1; }
    2968           0 : INLINE GEN closure_get_code(GEN C)  { return gel(C,2); }
    2969   189710615 : INLINE GEN closure_get_oper(GEN C)  { return gel(C,3); }
    2970   189693705 : INLINE GEN closure_get_data(GEN C)  { return gel(C,4); }
    2971        9817 : INLINE GEN closure_get_dbg(GEN C)   { return gel(C,5); }
    2972       23484 : INLINE GEN closure_get_text(GEN C)  { return gel(C,6); }
    2973     1275539 : INLINE GEN closure_get_frame(GEN C) { return gel(C,7); }
    2974             : 
    2975             : /*******************************************************************/
    2976             : /*                                                                 */
    2977             : /*                               ERRORS                            */
    2978             : /*                                                                 */
    2979             : /*******************************************************************/
    2980             : INLINE long
    2981       53095 : err_get_num(GEN e) { return e[1]; }
    2982             : INLINE GEN
    2983         105 : err_get_compo(GEN e, long i) { return gel(e, i+1); }
    2984             : 
    2985             : INLINE void
    2986          14 : pari_err_BUG(const char *f) { pari_err(e_BUG,f); }
    2987             : INLINE void
    2988           7 : pari_err_CONSTPOL(const char *f) { pari_err(e_CONSTPOL, f); }
    2989             : INLINE void
    2990          63 : pari_err_COPRIME(const char *f, GEN x, GEN y) { pari_err(e_COPRIME, f,x,y); }
    2991             : INLINE void
    2992         494 : pari_err_DIM(const char *f) { pari_err(e_DIM, f); }
    2993             : INLINE void
    2994           0 : pari_err_FILE(const char *f, const char *g) { pari_err(e_FILE, f,g); }
    2995             : INLINE void
    2996           0 : pari_err_FILEDESC(const char *f, long n) { pari_err(e_FILEDESC, f,n); }
    2997             : INLINE void
    2998          77 : pari_err_FLAG(const char *f) { pari_err(e_FLAG,f); }
    2999             : INLINE void
    3000         434 : pari_err_IMPL(const char *f) { pari_err(e_IMPL,f); }
    3001             : INLINE void
    3002       19751 : pari_err_INV(const char *f, GEN x) { pari_err(e_INV,f,x); }
    3003             : INLINE void
    3004          42 : pari_err_IRREDPOL(const char *f, GEN x) { pari_err(e_IRREDPOL, f,x); }
    3005             : INLINE void
    3006        2092 : 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); }
    3007             : INLINE void
    3008         200 : pari_err_COMPONENT(const char *f, const char *op, GEN l, GEN x) { pari_err(e_COMPONENT, f,op,l,x); }
    3009             : INLINE void
    3010           0 : pari_err_MAXPRIME(ulong c) { pari_err(e_MAXPRIME, c); }
    3011             : INLINE void
    3012         350 : pari_err_OP(const char *f, GEN x, GEN y) { pari_err(e_OP, f,x,y); }
    3013             : INLINE void
    3014          93 : pari_err_OVERFLOW(const char *f) { pari_err(e_OVERFLOW, f); }
    3015             : INLINE void
    3016         218 : pari_err_PREC(const char *f) { pari_err(e_PREC,f); }
    3017             : INLINE void
    3018           0 : pari_err_PACKAGE(const char *f) { pari_err(e_PACKAGE,f); }
    3019             : INLINE void
    3020          77 : pari_err_PRIME(const char *f, GEN x) { pari_err(e_PRIME, f,x); }
    3021             : INLINE void
    3022         749 : pari_err_MODULUS(const char *f, GEN x, GEN y) { pari_err(e_MODULUS, f,x,y); }
    3023             : INLINE void
    3024          49 : pari_err_ROOTS0(const char *f) { pari_err(e_ROOTS0, f); }
    3025             : INLINE void
    3026          84 : pari_err_SQRTN(const char *f, GEN x) { pari_err(e_SQRTN, f,x); }
    3027             : INLINE void
    3028       12720 : pari_err_TYPE(const char *f, GEN x) { pari_err(e_TYPE, f,x); }
    3029             : INLINE void
    3030        3045 : pari_err_TYPE2(const char *f, GEN x, GEN y) { pari_err(e_TYPE2, f,x,y); }
    3031             : INLINE void
    3032         280 : pari_err_VAR(const char *f, GEN x, GEN y) { pari_err(e_VAR, f,x,y); }
    3033             : INLINE void
    3034         182 : pari_err_PRIORITY(const char *f, GEN x, const char *op, long v)
    3035         182 : { pari_err(e_PRIORITY, f,x,op,v); }

Generated by: LCOV version 1.13