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 23499-f2b23893a) Lines: 1294 1463 88.4 %
Date: 2019-01-22 05:42:35 Functions: 568 646 87.9 %
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     3120235 : mkintmod(GEN x, GEN y) { retmkintmod(x,y); }
     141             : INLINE GEN
     142        4074 : mkintmodu(ulong x, ulong y) {
     143        4074 :   GEN v = cgetg(3,t_INTMOD);
     144        4074 :   gel(v,1) = utoipos(y);
     145        4074 :   gel(v,2) = utoi(x); return v;
     146             : }
     147             : INLINE GEN
     148     2940392 : mkpolmod(GEN x, GEN y) { retmkpolmod(x,y); }
     149             : INLINE GEN
     150    23145732 : 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       12208 : Qtoss(GEN q, long *n, long *d)
     156             : {
     157       12208 :   if (typ(q) == t_INT) { *n = itos(q); *d = 1; }
     158        2443 :   else { *n = itos(gel(q,1)); *d = itou(gel(q,2)); }
     159       12208 : }
     160             : INLINE GEN
     161    71264496 : sstoQ(long n, long d)
     162             : {
     163             :   ulong r;
     164             :   long g, q;
     165    71264496 :   if (!n)
     166             :   {
     167       98238 :     if (!d) pari_err_INV("sstoQ",gen_0);
     168       98238 :     return gen_0;
     169             :   }
     170    71166258 :   if (d < 0) { d = -d; n = -n; }
     171    71166258 :   if (d == 1) return stoi(n);
     172    71154267 :   q = udivuu_rem(labs(n),d,&r);
     173    71154267 :   if (!r) return n > 0? utoipos(q): utoineg(q);
     174     3634024 :   g = ugcd(d,r); /* gcd(n,d) */
     175     3634024 :   if (g != 1) { n /= g; d /= g; }
     176     3634024 :   retmkfrac(stoi(n), utoi(d));
     177             : }
     178             : 
     179             : INLINE GEN
     180     6681416 : 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     9089184 : mkcomplex(GEN x, GEN y) { retmkcomplex(x,y); }
     189             : INLINE GEN
     190      449696 : gen_I(void) { return mkcomplex(gen_0, gen_1); }
     191             : INLINE GEN
     192      298723 : 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    69601395 : mkvecsmall(long x) { GEN v = cgetg(2, t_VECSMALL); v[1] = x; return v; }
     199             : INLINE GEN
     200   114123522 : mkvecsmall2(long x,long y) { GEN v = cgetg(3, t_VECSMALL);
     201   114127147 :   v[1]=x; v[2]=y; return v; }
     202             : INLINE GEN
     203    58024543 : mkvecsmall3(long x,long y,long z) { GEN v = cgetg(4, t_VECSMALL);
     204    58022719 :   v[1]=x; v[2]=y; v[3]=z; return v; }
     205             : INLINE GEN
     206    11955724 : mkvecsmall4(long x,long y,long z,long t) { GEN v = cgetg(5, t_VECSMALL);
     207    11946282 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; return v; }
     208             : INLINE GEN
     209      466564 : mkvecsmall5(long x,long y,long z,long t,long u) { GEN v = cgetg(6, t_VECSMALL);
     210      466565 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; v[5]=u; return v; }
     211             : 
     212             : INLINE GEN
     213      158123 : mkqfi(GEN x, GEN y, GEN z) { retmkqfi(x,y,z); }
     214             : /* vec */
     215             : INLINE GEN
     216    15046096 : mkvec(GEN x) { retmkvec(x); }
     217             : INLINE GEN
     218   102015783 : mkvec2(GEN x, GEN y) { retmkvec2(x,y); }
     219             : INLINE GEN
     220    74824427 : mkvec3(GEN x, GEN y, GEN z) { retmkvec3(x,y,z); }
     221             : INLINE GEN
     222     7270099 : mkvec4(GEN x, GEN y, GEN z, GEN t) { retmkvec4(x,y,z,t); }
     223             : INLINE GEN
     224    12082045 : mkvec5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkvec5(x,y,z,t,u); }
     225             : INLINE GEN
     226           0 : mkvecs(long x) { retmkvec(stoi(x)); }
     227             : INLINE GEN
     228       23070 : 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       35091 : mkveccopy(GEN x) { GEN v = cgetg(2, t_VEC); gel(v,1) = gcopy(x); return v; }
     235             : INLINE GEN
     236       96868 : mkvec2copy(GEN x, GEN y) {
     237       96868 :   GEN v = cgetg(3,t_VEC); gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     238             : /* col */
     239             : INLINE GEN
     240     2509004 : mkcol(GEN x) { retmkcol(x); }
     241             : INLINE GEN
     242    25643408 : mkcol2(GEN x, GEN y) { retmkcol2(x,y); }
     243             : INLINE GEN
     244       42385 : 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     2176216 : 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       50588 : mkcolcopy(GEN x) { GEN v = cgetg(2, t_COL); gel(v,1) = gcopy(x); return v; }
     261             : /* mat */
     262             : INLINE GEN
     263     2536167 : mkmat(GEN x) { retmkmat(x); }
     264             : INLINE GEN
     265    32198943 : mkmat2(GEN x, GEN y) { retmkmat2(x,y); }
     266             : INLINE GEN
     267        2331 : 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       22341 : 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       96167 : mkoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_1; return v; }
     278             : INLINE GEN
     279       17045 : mkmoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_m1; return v; }
     280             : INLINE long
     281      132935 : inf_get_sign(GEN x) { return signe(gel(x,1)); }
     282             : INLINE GEN
     283       10696 : mkmat22s(long a, long b, long c, long d) {retmkmat2(mkcol2s(a,c),mkcol2s(b,d));}
     284             : INLINE GEN
     285     1533070 : mkmat22(GEN a, GEN b, GEN c, GEN d) { retmkmat2(mkcol2(a,c),mkcol2(b,d)); }
     286             : 
     287             : /* pol */
     288             : INLINE GEN
     289      989409 : pol_x(long v) {
     290      989409 :   GEN p = cgetg(4, t_POL);
     291      989408 :   p[1] = evalsigne(1)|evalvarn(v);
     292      989408 :   gel(p,2) = gen_0;
     293      989408 :   gel(p,3) = gen_1; return p;
     294             : }
     295             : /* x^n, assume n >= 0 */
     296             : INLINE GEN
     297     8769032 : pol_xn(long n, long v) {
     298     8769032 :   long i, a = n+2;
     299     8769032 :   GEN p = cgetg(a+1, t_POL);
     300     8769032 :   p[1] = evalsigne(1)|evalvarn(v);
     301     8769032 :   for (i = 2; i < a; i++) gel(p,i) = gen_0;
     302     8769032 :   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     1429597 : pol_1(long v) {
     313     1429597 :   GEN p = cgetg(3, t_POL);
     314     1429598 :   p[1] = evalsigne(1)|evalvarn(v);
     315     1429598 :   gel(p,2) = gen_1; return p;
     316             : }
     317             : INLINE GEN
     318    32822675 : pol_0(long v)
     319             : {
     320    32822675 :   GEN x = cgetg(2,t_POL);
     321    32822675 :   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     8764334 : 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     8679291 : const_col(long n, GEN x) { retconst_col(n, x); }
     337             : INLINE GEN
     338     8584792 : const_vecsmall(long n, long c)
     339             : {
     340             :   long i;
     341     8584792 :   GEN V = cgetg(n+1,t_VECSMALL);
     342     8584966 :   for(i=1;i<=n;i++) V[i] = c;
     343     8584966 :   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      143591 : zeroser(long v, long e)
     371             : {
     372      143591 :   GEN x = cgetg(2, t_SER);
     373      143591 :   x[1] = evalvalp(e) | evalvarn(v); return x;
     374             : }
     375             : INLINE int
     376     5750158 : ser_isexactzero(GEN x)
     377             : {
     378     5750158 :   if (!signe(x)) switch(lg(x))
     379             :   {
     380      136206 :     case 2: return 1;
     381         854 :     case 3: return isexactzero(gel(x,2));
     382             :   }
     383     5613098 :   return 0;
     384             : }
     385             : /* 0 * pol_x(v) */
     386             : INLINE GEN
     387    15543042 : zeropol(long v) { return pol_0(v); }
     388             : /* vector(n) */
     389             : INLINE GEN
     390    37555117 : zerocol(long n)
     391             : {
     392    37555117 :   GEN y = cgetg(n+1,t_COL);
     393    37555344 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     394    37555344 :   return y;
     395             : }
     396             : /* vectorv(n) */
     397             : INLINE GEN
     398    21786265 : zerovec(long n)
     399             : {
     400    21786265 :   GEN y = cgetg(n+1,t_VEC);
     401    21786264 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     402    21786264 :   return y;
     403             : }
     404             : /* matrix(m, n) */
     405             : INLINE GEN
     406       23555 : zeromat(long m, long n)
     407             : {
     408       23555 :   GEN y = cgetg(n+1,t_MAT);
     409       23555 :   GEN v = zerocol(m);
     410       23555 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     411       23555 :   return y;
     412             : }
     413             : /* = zero_zx, sv is a evalvarn()*/
     414             : INLINE GEN
     415      932954 : zero_Flx(long sv) { return pol0_Flx(sv); }
     416             : INLINE GEN
     417    33665351 : zero_Flv(long n)
     418             : {
     419    33665351 :   GEN y = cgetg(n+1,t_VECSMALL);
     420    33666872 :   long i; for (i=1; i<=n; i++) y[i] = 0;
     421    33666872 :   return y;
     422             : }
     423             : /* matrix(m, n) */
     424             : INLINE GEN
     425      925323 : zero_Flm(long m, long n)
     426             : {
     427      925323 :   GEN y = cgetg(n+1,t_MAT);
     428      925306 :   GEN v = zero_Flv(m);
     429      925316 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     430      925316 :   return y;
     431             : }
     432             : /* matrix(m, n) */
     433             : INLINE GEN
     434      110199 : zero_Flm_copy(long m, long n)
     435             : {
     436      110199 :   GEN y = cgetg(n+1,t_MAT);
     437      110188 :   long i; for (i=1; i<=n; i++) gel(y,i) = zero_Flv(m);
     438      110203 :   return y;
     439             : }
     440             : 
     441             : INLINE GEN
     442      797142 : zero_F2v(long m)
     443             : {
     444      797142 :   long l = nbits2nlong(m);
     445      797142 :   GEN v  = zero_Flv(l+1);
     446      797142 :   v[1] = m;
     447      797142 :   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      277558 : zero_F2m_copy(long m, long n)
     464             : {
     465             :   long i;
     466      277558 :   GEN M = cgetg(n+1, t_MAT);
     467      808223 :   for (i = 1; i <= n; i++)
     468      530665 :     gel(M,i)= zero_F2v(m);
     469      277558 :   return M;
     470             : }
     471             : 
     472             : /* matrix(m, n) */
     473             : INLINE GEN
     474     4890325 : zeromatcopy(long m, long n)
     475             : {
     476     4890325 :   GEN y = cgetg(n+1,t_MAT);
     477     4890325 :   long i; for (i=1; i<=n; i++) gel(y,i) = zerocol(m);
     478     4890325 :   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     1422923 : col_ei(long n, long i) { GEN e = zerocol(n); gel(e,i) = gen_1; return e; }
     494             : INLINE GEN
     495      337447 : 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       71547 : vecsmall_ei(long n, long i) { GEN e = zero_zv(n); e[i] = 1; return e; }
     500             : INLINE GEN
     501      683234 : Rg_col_ei(GEN x, long n, long i) { GEN e = zerocol(n); gel(e,i) = x; return e; }
     502             : 
     503             : INLINE GEN
     504    12703701 : shallowcopy(GEN x)
     505    12703701 : { return typ(x) == t_MAT ? RgM_shallowcopy(x): leafcopy(x); }
     506             : 
     507             : /* routines for naive growarrays */
     508             : INLINE GEN
     509    12709731 : vectrunc_init(long l)
     510             : {
     511    12709731 :   GEN z = new_chunk(l);
     512    12709758 :   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   257571649 : lg_increase(GEN x) { x[0]++; }
     522             : INLINE void
     523    51326203 : 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    84510327 : vecsmalltrunc_init(long l)
     534             : {
     535    84510327 :   GEN z = new_chunk(l);
     536    84510327 :   z[0] = evaltyp(t_VECSMALL) | _evallg(1); return z;
     537             : }
     538             : INLINE void
     539    33067410 : 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     1947176 : hash_str(const char *str)
     548             : {
     549     1947176 :   ulong hash = 5381UL, c;
     550    21130926 :   while ( (c = (ulong)*str++) )
     551    17236574 :     hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
     552     1947176 :   return hash;
     553             : }
     554             : INLINE ulong
     555     6576162 : hash_str_len(const char *str, long len)
     556             : {
     557     6576162 :   ulong hash = 5381UL;
     558             :   long i;
     559    24912770 :   for (i = 0; i < len; i++)
     560             :   {
     561    18336608 :     ulong c = (ulong)*str++;
     562    18336608 :     hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
     563             :   }
     564     6576162 :   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       63399 : vec_append(GEN V, GEN s)
     594             : {
     595       63399 :   long i, l2 = lg(V);
     596       63399 :   GEN res = cgetg(l2+1, typ(V));
     597       63399 :   for (i = 1; i < l2; ++i) gel(res, i) = gel(V,i);
     598       63399 :   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       41513 : vecsmall_shorten(GEN v, long n)
     620             : {
     621             :   long i;
     622       41513 :   GEN V = cgetg(n+1,t_VECSMALL);
     623       41518 :   for(i=1;i<=n;i++) V[i] = v[i];
     624       41518 :   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     3321953 : vec_to_vecsmall(GEN x)
     637     3321953 : { pari_APPLY_long(itos(gel(x,i))) }
     638             : INLINE GEN
     639      135186 : vecsmall_to_vec(GEN x)
     640      135186 : { 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     5227168 : vecsmall_to_col(GEN x)
     650     5227168 : { pari_APPLY_type(t_COL, stoi(x[i])) }
     651             : 
     652             : INLINE int
     653     8141461 : vecsmall_lexcmp(GEN x, GEN y)
     654             : {
     655             :   long lx,ly,l,i;
     656     8141461 :   lx = lg(x);
     657     8141461 :   ly = lg(y); l = minss(lx,ly);
     658    39708083 :   for (i=1; i<l; i++)
     659    37836261 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     660     1871822 :   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       21176 : vecsmall_prepend(GEN V, long s)
     676             : {
     677       21176 :   long i, l2 = lg(V);
     678       21176 :   GEN res = cgetg(l2+1, typ(V));
     679       21176 :   res[1] = s;
     680       21176 :   for (i = 2; i <= l2; ++i) res[i] = V[i - 1];
     681       21176 :   return res;
     682             : }
     683             : 
     684             : INLINE GEN
     685     3128839 : vecsmall_append(GEN V, long s)
     686             : {
     687     3128839 :   long i, l2 = lg(V);
     688     3128839 :   GEN res = cgetg(l2+1, t_VECSMALL);
     689     3128838 :   for (i = 1; i < l2; ++i) res[i] = V[i];
     690     3128838 :   res[l2] = s; return res;
     691             : }
     692             : 
     693             : INLINE GEN
     694      787874 : vecsmall_concat(GEN u, GEN v)
     695             : {
     696      787874 :   long i, l1 = lg(u)-1, l2 = lg(v)-1;
     697      787874 :   GEN res = cgetg(l1+l2+1, t_VECSMALL);
     698      787874 :   for (i = 1; i <= l1; ++i) res[i]    = u[i];
     699      787874 :   for (i = 1; i <= l2; ++i) res[i+l1] = v[i];
     700      787874 :   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      178801 : vecsmall_max(GEN x)
     742             : {
     743      178801 :   long i, t = x[1], lx = lg(x);
     744      640799 :   for (i=2; i<lx; i++)
     745      461998 :     if (x[i] > t) t = x[i];
     746      178801 :   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     5045505 : ZV_isscalar(GEN x)
     769             : {
     770     5045505 :   long l = lg(x);
     771    14375989 :   while (--l > 1)
     772     8216621 :     if (signe(gel(x, l))) return 0;
     773     1113863 :   return 1;
     774             : }
     775             : INLINE int
     776    19627775 : QV_isscalar(GEN x)
     777             : {
     778    19627775 :   long lx = lg(x),i;
     779    21190121 :   for (i=2; i<lx; i++)
     780    20606893 :     if (!isintzero(gel(x, i))) return 0;
     781      583228 :   return 1;
     782             : }
     783             : INLINE int
     784        7676 : RgV_isscalar(GEN x)
     785             : {
     786        7676 :   long lx = lg(x),i;
     787       11255 :   for (i=2; i<lx; i++)
     788        9998 :     if (!gequal0(gel(x, i))) return 0;
     789        1257 :   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    28786684 : RgX_equal_var(GEN x, GEN y) { return varn(x) == varn(y) && RgX_equal(x,y); }
     801             : 
     802             : INLINE int
     803        6539 : RgX_is_rational(GEN x)
     804             : {
     805             :   long i;
     806       30695 :   for (i = lg(x)-1; i > 1; i--)
     807       28566 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     808        2129 :   return 1;
     809             : }
     810             : INLINE int
     811     4467020 : RgX_is_ZX(GEN x)
     812             : {
     813             :   long i;
     814    19190409 :   for (i = lg(x)-1; i > 1; i--)
     815    14775954 :     if (typ(gel(x,i)) != t_INT) return 0;
     816     4414455 :   return 1;
     817             : }
     818             : INLINE int
     819      263326 : RgX_is_QX(GEN x)
     820             : {
     821      263326 :   long k = lg(x)-1;
     822      930536 :   for ( ; k>1; k--)
     823      667455 :     if (!is_rational_t(typ(gel(x,k)))) return 0;
     824      263081 :   return 1;
     825             : }
     826             : INLINE int
     827     2346666 : RgX_is_monomial(GEN x)
     828             : {
     829             :   long i;
     830     2346666 :   if (!signe(x)) return 0;
     831     5855620 :   for (i=lg(x)-2; i>1; i--)
     832     3563897 :     if (!isexactzero(gel(x,i))) return 0;
     833     2291723 :   return 1;
     834             : }
     835             : INLINE int
     836    27439864 : RgV_is_ZV(GEN x)
     837             : {
     838             :   long i;
     839   112522066 :   for (i = lg(x)-1; i > 0; i--)
     840    85084484 :     if (typ(gel(x,i)) != t_INT) return 0;
     841    27437582 :   return 1;
     842             : }
     843             : INLINE int
     844       21130 : RgV_is_QV(GEN x)
     845             : {
     846             :   long i;
     847       84951 :   for (i = lg(x)-1; i > 0; i--)
     848       65445 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     849       19506 :   return 1;
     850             : }
     851             : 
     852             : /********************************************************************/
     853             : /**                                                                **/
     854             : /**            Dynamic arrays implementation                       **/
     855             : /**                                                                **/
     856             : /********************************************************************/
     857             : INLINE void **
     858   404498499 : pari_stack_base(pari_stack *s) { return s->data; }
     859             : 
     860             : INLINE void
     861     1797267 : pari_stack_init(pari_stack *s, size_t size, void **data)
     862             : {
     863     1797267 :   s->data = data;
     864     1797267 :   *data = NULL;
     865     1797267 :   s->n = 0;
     866     1797267 :   s->alloc = 0;
     867     1797267 :   s->size = size;
     868     1797267 : }
     869             : 
     870             : INLINE void
     871   402877519 : pari_stack_alloc(pari_stack *s, long nb)
     872             : {
     873   402877519 :   void **sdat = pari_stack_base(s);
     874   402598692 :   long alloc = s->alloc;
     875   402598692 :   if (s->n+nb <= alloc) return;
     876      662519 :   if (!alloc)
     877      608752 :     alloc = nb;
     878             :   else
     879             :   {
     880       53767 :     while (s->n+nb > alloc) alloc <<= 1;
     881             :   }
     882      662519 :   *sdat = pari_realloc(*sdat,alloc*s->size);
     883      663692 :   s->alloc = alloc;
     884             : }
     885             : 
     886             : INLINE long
     887   325046594 : pari_stack_new(pari_stack *s) { pari_stack_alloc(s, 1); return s->n++; }
     888             : 
     889             : INLINE void
     890     1739691 : pari_stack_delete(pari_stack *s)
     891             : {
     892     1739691 :   void **sdat = pari_stack_base(s);
     893     1736777 :   if (*sdat) pari_free(*sdat);
     894     1749325 : }
     895             : 
     896             : INLINE void
     897        4808 : pari_stack_pushp(pari_stack *s, void *u)
     898             : {
     899        4808 :   long n = pari_stack_new(s);
     900        4808 :   void **sdat =(void**) *pari_stack_base(s);
     901        4808 :   sdat[n] = u;
     902        4808 : }
     903             : 
     904             : /*******************************************************************/
     905             : /*                                                                 */
     906             : /*                            EXTRACT                              */
     907             : /*                                                                 */
     908             : /*******************************************************************/
     909             : INLINE GEN
     910   202702878 : vecslice(GEN A, long y1, long y2)
     911             : {
     912   202702878 :   long i,lB = y2 - y1 + 2;
     913   202702878 :   GEN B = cgetg(lB, typ(A));
     914   202699288 :   for (i=1; i<lB; i++) B[i] = A[y1-1+i];
     915   202699288 :   return B;
     916             : }
     917             : INLINE GEN
     918      817785 : vecslicepermute(GEN A, GEN p, long y1, long y2)
     919             : {
     920      817785 :   long i,lB = y2 - y1 + 2;
     921      817785 :   GEN B = cgetg(lB, typ(A));
     922      817790 :   for (i=1; i<lB; i++) B[i] = A[p[y1-1+i]];
     923      817790 :   return B;
     924             : }
     925             : /* rowslice(rowpermute(A,p), x1, x2) */
     926             : INLINE GEN
     927       40668 : rowslicepermute(GEN x, GEN p, long j1, long j2)
     928       40668 : { pari_APPLY_same(vecslicepermute(gel(x,i),p,j1,j2)) }
     929             : 
     930             : INLINE GEN
     931    22431044 : rowslice(GEN x, long j1, long j2)
     932    22431044 : { pari_APPLY_same(vecslice(gel(x,i), j1, j2)) }
     933             : 
     934             : INLINE GEN
     935     3712546 : matslice(GEN A, long x1, long x2, long y1, long y2)
     936     3712546 : { 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      263760 : vecsplice(GEN a, long j)
     946             : {
     947      263760 :   long i, k, l = lg(a);
     948             :   GEN b;
     949      263760 :   if (l == 1) pari_err(e_MISC, "incorrect component in vecsplice");
     950      263760 :   b = cgetg(l-1, typ(a));
     951     1054018 :   for (i = k = 1; i < l; i++)
     952      790258 :     if (i != j) gel(b, k++) = gel(a,i);
     953      263760 :   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      390422 : row(GEN x, long j)
     968      390422 : { pari_APPLY_type(t_VEC, gcoeff(x, j, i)) }
     969             : INLINE GEN
     970     3771630 : Flm_row(GEN x, long j)
     971     3771630 : { pari_APPLY_ulong((ulong)coeff(x, j, i)) }
     972             : /* A[x0,] */
     973             : INLINE GEN
     974      204820 : rowcopy(GEN x, long j)
     975      204820 : { pari_APPLY_type(t_VEC, gcopy(gcoeff(x, j, i))) }
     976             : /* A[x0, x1..x2] */
     977             : INLINE GEN
     978        2303 : row_i(GEN A, long x0, long x1, long x2)
     979             : {
     980        2303 :   long i, lB = x2 - x1 + 2;
     981        2303 :   GEN B  = cgetg(lB, t_VEC);
     982        2303 :   for (i=x1; i<=x2; i++) gel(B, i) = gcoeff(A, x0, i);
     983        2303 :   return B;
     984             : }
     985             : 
     986             : INLINE GEN
     987     5830525 : vecreverse(GEN A)
     988             : {
     989             :   long i, l;
     990     5830525 :   GEN B = cgetg_copy(A, &l);
     991     5830525 :   for (i=1; i<l; i++) gel(B, i) = gel(A, l-i);
     992     5830525 :   return B;
     993             : }
     994             : 
     995             : INLINE GEN
     996         329 : vecsmall_reverse(GEN A)
     997             : {
     998             :   long i, l;
     999         329 :   GEN B = cgetg_copy(A, &l);
    1000         329 :   for (i=1; i<l; i++) B[i] = A[l-i];
    1001         329 :   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    45484142 : vecsmallpermute(GEN A, GEN p) { return perm_mul(A, p); }
    1018             : 
    1019             : INLINE GEN
    1020     6509480 : vecpermute(GEN A, GEN x)
    1021     6509480 : { pari_APPLY_type(typ(A), gel(A, x[i])) }
    1022             : 
    1023             : INLINE GEN
    1024     3017999 : rowpermute(GEN x, GEN p)
    1025     3017999 : { 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      729618 : identity_zv(long n)
    1035             : {
    1036      729618 :   GEN v = cgetg(n+1, t_VECSMALL);
    1037             :   long i;
    1038      729615 :   for (i = 1; i <= n; i++) v[i] = i;
    1039      729615 :   return v;
    1040             : }
    1041             : INLINE GEN
    1042        1743 : identity_ZV(long n)
    1043             : {
    1044        1743 :   GEN v = cgetg(n+1, t_VEC);
    1045             :   long i;
    1046        1743 :   for (i = 1; i <= n; i++) gel(v,i) = utoipos(i);
    1047        1743 :   return v;
    1048             : }
    1049             : /* identity permutation */
    1050             : INLINE GEN
    1051      729172 : 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    46728893 : perm_mul(GEN s, GEN x)
    1067    46728893 : { pari_APPLY_long(s[x[i]]) }
    1068             : 
    1069             : /* Compute the inverse (reciprocal) of a permutation. */
    1070             : INLINE GEN
    1071     1163377 : perm_inv(GEN x)
    1072             : {
    1073             :   long i, lx;
    1074     1163377 :   GEN y = cgetg_copy(x, &lx);
    1075     1163377 :   for (i=1; i<lx; i++) y[ x[i] ] = i;
    1076     1163377 :   return y;
    1077             : }
    1078             : /* Return s*t*s^-1 */
    1079             : INLINE GEN
    1080      416934 : perm_conj(GEN s, GEN t)
    1081             : {
    1082             :   long i, l;
    1083      416934 :   GEN v = cgetg_copy(s, &l);
    1084      416934 :   for (i = 1; i < l; i++) v[ s[i] ] = s[ t[i] ];
    1085      416934 :   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    72194984 : pari_free(void *pointer)
    1116             : {
    1117    72194984 :   BLOCK_SIGINT_START;
    1118    72214602 :   free(pointer);
    1119    72214602 :   BLOCK_SIGINT_END;
    1120    72210183 : }
    1121             : INLINE void*
    1122   279211224 : pari_malloc(size_t size)
    1123             : {
    1124   279211224 :   if (size)
    1125             :   {
    1126             :     char *tmp;
    1127   279211224 :     BLOCK_SIGINT_START;
    1128   279214782 :     tmp = (char*)malloc(size);
    1129   279214782 :     BLOCK_SIGINT_END;
    1130   279214356 :     if (!tmp) pari_err(e_MEM);
    1131   279214356 :     return tmp;
    1132             :   }
    1133           0 :   return NULL;
    1134             : }
    1135             : INLINE void*
    1136      677223 : pari_realloc(void *pointer, size_t size)
    1137             : {
    1138             :   char *tmp;
    1139             : 
    1140      677223 :   BLOCK_SIGINT_START;
    1141      679394 :   if (!pointer) tmp = (char *) malloc(size);
    1142       57612 :   else tmp = (char *) realloc(pointer,size);
    1143      679394 :   BLOCK_SIGINT_END;
    1144      678786 :   if (!tmp) pari_err(e_MEM);
    1145      678786 :   return tmp;
    1146             : }
    1147             : INLINE void*
    1148       37372 : pari_calloc(size_t size)
    1149             : {
    1150       37372 :   void *t = pari_malloc(size);
    1151       37372 :   memset(t, 0, size); return t;
    1152             : }
    1153             : INLINE GEN
    1154        5813 : cgetalloc(long t, size_t l)
    1155             : {
    1156        5813 :   GEN x = (GEN)pari_malloc(l * sizeof(long));
    1157        5813 :   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  3803859731 : icopy_avma(GEN x, pari_sp av)
    1168             : {
    1169  3803859731 :   long i = lgefint(x), lx = i;
    1170  3803859731 :   GEN y = ((GEN)av) - i;
    1171  3803859731 :   while (--i > 0) y[i] = x[i];
    1172  3803859731 :   y[0] = evaltyp(t_INT)|evallg(lx);
    1173  3803688655 :   return y;
    1174             : }
    1175             : /* copy leaf x as if we had set_avma(av) */
    1176             : INLINE GEN
    1177   177942191 : leafcopy_avma(GEN x, pari_sp av)
    1178             : {
    1179   177942191 :   long i = lg(x);
    1180   177942191 :   GEN y = ((GEN)av) - i;
    1181   177942191 :   while (--i > 0) y[i] = x[i];
    1182   177942191 :   y[0] = x[0] & (~CLONEBIT);
    1183   177942191 :   return y;
    1184             : }
    1185             : INLINE GEN
    1186   649314360 : gerepileuptoleaf(pari_sp av, GEN x)
    1187             : {
    1188             :   long lx;
    1189             :   GEN q;
    1190             : 
    1191   649314360 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1192   649332910 :   lx = lg(x);
    1193   649332910 :   q = ((GEN)av) - lx;
    1194   649332910 :   set_avma((pari_sp)q);
    1195   650900614 :   while (--lx >= 0) q[lx] = x[lx];
    1196   650900614 :   return q;
    1197             : }
    1198             : INLINE GEN
    1199  1280476646 : gerepileuptoint(pari_sp av, GEN x)
    1200             : {
    1201  1280476646 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1202  1132543430 :   set_avma((pari_sp)icopy_avma(x, av));
    1203  1134170930 :   return (GEN)avma;
    1204             : }
    1205             : INLINE GEN
    1206   805528731 : gerepileupto(pari_sp av, GEN x)
    1207             : {
    1208   805528731 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1209   715998033 :   switch(typ(x))
    1210             :   { /* non-default = !is_recursive_t(tq) */
    1211   252649914 :     case t_INT: return gerepileuptoint(av, x);
    1212             :     case t_REAL:
    1213             :     case t_STR:
    1214   145322924 :     case t_VECSMALL: return gerepileuptoleaf(av,x);
    1215             :     default:
    1216             :       /* NB: x+i --> ((long)x) + i*sizeof(long) */
    1217   318025195 :       return gerepile(av, (pari_sp) (x+lg(x)), x);
    1218             :   }
    1219             : }
    1220             : INLINE double
    1221     2286449 : gc_double(pari_sp av, double d) { set_avma(av); return d; }
    1222             : INLINE long
    1223   112937588 : gc_long(pari_sp av, long s) { set_avma(av); return s; }
    1224             : INLINE ulong
    1225    15242232 : gc_ulong(pari_sp av, ulong s) { set_avma(av); return s; }
    1226             : INLINE int
    1227    21961827 : gc_bool(pari_sp av, int s) { set_avma(av); return s; }
    1228             : INLINE int
    1229     3366452 : gc_int(pari_sp av, int s) { set_avma(av); return s; }
    1230             : INLINE GEN
    1231     1610964 : gc_NULL(pari_sp av) { set_avma(av); return NULL; }
    1232             : 
    1233             : /* gerepileupto(av, gcopy(x)) */
    1234             : INLINE GEN
    1235    53158290 : gerepilecopy(pari_sp av, GEN x)
    1236             : {
    1237    53158290 :   if (is_recursive_t(typ(x)))
    1238             :   {
    1239    48542398 :     GENbin *p = copy_bin(x);
    1240    48542892 :     set_avma(av); return bin_copy(p);
    1241             :   }
    1242             :   else
    1243             :   {
    1244     4615918 :     set_avma(av);
    1245     4615922 :     if (x < (GEN)av) {
    1246     3128493 :       if (x < (GEN)pari_mainstack->bot) new_chunk(lg(x));
    1247     3128493 :       x = leafcopy_avma(x, av);
    1248     3128507 :       set_avma((pari_sp)x);
    1249             :     } else
    1250     1487429 :       x = leafcopy(x);
    1251     4615932 :     return x;
    1252             :   }
    1253             : }
    1254             : 
    1255             : INLINE void
    1256    27338438 : guncloneNULL(GEN x) { if (x) gunclone(x); }
    1257             : INLINE void
    1258      170212 : 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      199026 : gerepilemany(pari_sp av, GEN* gptr[], int n)
    1265             : {
    1266             :   int i;
    1267      199026 :   for (i=0; i<n; i++) *gptr[i] = (GEN)copy_bin(*gptr[i]);
    1268      199026 :   set_avma(av);
    1269      199026 :   for (i=0; i<n; i++) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1270      199026 : }
    1271             : 
    1272             : INLINE void
    1273     7581633 : gerepileall(pari_sp av, int n, ...)
    1274             : {
    1275             :   int i;
    1276     7581633 :   va_list a; va_start(a, n);
    1277     7581633 :   if (n < 10)
    1278             :   {
    1279             :     GEN *gptr[10];
    1280    21956488 :     for (i=0; i<n; i++)
    1281    14374760 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1282     7581728 :     set_avma(av);
    1283     7581623 :     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     7581826 :   va_end(a);
    1296     7581826 : }
    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    63529747 : bin_copy(GENbin *p)
    1310             : {
    1311             :   GEN x, y, base;
    1312             :   long dx, len;
    1313             : 
    1314    63529747 :   x   = p->x; if (!x) { pari_free(p); return gen_0; }
    1315    63522538 :   len = p->len;
    1316    63522538 :   base= p->base; dx = x - base;
    1317    63522538 :   y = (GEN)memcpy((void*)new_chunk(len), (void*)GENbinbase(p), len*sizeof(long));
    1318    63522500 :   y += dx;
    1319    63522500 :   p->rebase(y, ((ulong)y-(ulong)x));
    1320    63522592 :   pari_free(p); return y;
    1321             : }
    1322             : 
    1323             : INLINE GEN
    1324   127052652 : GENbinbase(GENbin *p) { return (GEN)(p + 1); }
    1325             : 
    1326             : INLINE void
    1327    31956081 : cgiv(GEN x)
    1328             : {
    1329    31956081 :   pari_sp av = (pari_sp)(x+lg(x));
    1330    31956081 :   if (isonstack((GEN)av)) set_avma(av);
    1331    31955414 : }
    1332             : 
    1333             : INLINE void
    1334     1257623 : killblock(GEN x) { gunclone(x); }
    1335             : 
    1336             : INLINE int
    1337    25930313 : 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     3457103 : cxcompotor(GEN z, long prec)
    1347             : {
    1348     3457103 :   switch(typ(z))
    1349             :   {
    1350     1889544 :     case t_INT:  return itor(z, prec);
    1351      136682 :     case t_FRAC: return fractor(z, prec);
    1352     1430877 :     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     1714653 : cxtofp(GEN x, long prec)
    1359     1714653 : { retmkcomplex(cxcompotor(gel(x,1),prec), cxcompotor(gel(x,2),prec)); }
    1360             : 
    1361             : INLINE GEN
    1362      291172 : cxtoreal(GEN q)
    1363      291172 : { return (typ(q) == t_COMPLEX && gequal0(gel(q,2)))? gel(q,1): q; }
    1364             : 
    1365             : INLINE double
    1366    33880557 : gtodouble(GEN x)
    1367             : {
    1368    33880557 :   if (typ(x)!=t_REAL) {
    1369     7449795 :     pari_sp av = avma;
    1370     7449795 :     x = gtofp(x, DEFAULTPREC);
    1371     7449795 :     if (typ(x)!=t_REAL) pari_err_TYPE("gtodouble [t_REAL expected]", x);
    1372     7449795 :     set_avma(av);
    1373             :   }
    1374    33880557 :   return rtodbl(x);
    1375             : }
    1376             : INLINE long
    1377    73372721 : gtos(GEN x) {
    1378    73372721 :   if (typ(x) != t_INT) pari_err_TYPE("gtos [integer expected]",x);
    1379    73372714 :   return itos(x);
    1380             : }
    1381             : 
    1382             : INLINE ulong
    1383      152295 : gtou(GEN x) {
    1384      152295 :   if (typ(x) != t_INT || signe(x)<0)
    1385           0 :     pari_err_TYPE("gtou [integer >=0 expected]",x);
    1386      152300 :   return itou(x);
    1387             : }
    1388             : 
    1389             : INLINE GEN
    1390    23066660 : absfrac(GEN x)
    1391             : {
    1392    23066660 :   GEN y = cgetg(3, t_FRAC);
    1393    23066660 :   gel(y,1) = absi(gel(x,1));
    1394    23066660 :   gel(y,2) = icopy(gel(x,2)); return y;
    1395             : }
    1396             : INLINE GEN
    1397       32665 : absfrac_shallow(GEN x)
    1398       32665 : { return signe(gel(x,1))>0? x: mkfrac(negi(gel(x,1)), gel(x,2)); }
    1399             : INLINE GEN
    1400     7746180 : Q_abs(GEN x) { return (typ(x) == t_INT)? absi(x): absfrac(x); }
    1401             : INLINE GEN
    1402      130779 : Q_abs_shallow(GEN x)
    1403      130779 : { 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    35818213 : gtofp(GEN z, long prec)
    1414             : {
    1415    35818213 :   switch(typ(z))
    1416             :   {
    1417    22478212 :     case t_INT:  return itor(z, prec);
    1418     4311620 :     case t_FRAC: return fractor(z, prec);
    1419     7544807 :     case t_REAL: return rtor(z, prec);
    1420             :     case t_COMPLEX: {
    1421     1483574 :       GEN a = gel(z,1), b = gel(z,2);
    1422     1483574 :       if (isintzero(b)) return cxcompotor(a, prec);
    1423     1481002 :       if (isintzero(a)) {
    1424        3031 :         GEN y = cgetg(3, t_COMPLEX);
    1425        3031 :         b = cxcompotor(b, prec);
    1426        3031 :         gel(y,1) = real_0_bit(expo(b) - prec2nbits(prec));
    1427        3031 :         gel(y,2) = b; return y;
    1428             :       }
    1429     1477971 :       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      761993 : RgX_gtofp(GEN x, long prec)
    1454             : {
    1455             :   long l;
    1456      761993 :   GEN y = cgetg_copy(x, &l);
    1457      761993 :   while (--l > 1) gel(y,l) = gtofp(gel(x,l), prec);
    1458      761993 :   y[1] = x[1]; return y;
    1459             : }
    1460             : INLINE GEN
    1461     1193079 : RgC_gtofp(GEN x, long prec)
    1462     1193079 : { 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      134662 : RgM_gtofp(GEN x, long prec)
    1470      134662 : { 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        9374 : RgX_fpnorml2(GEN x, long prec)
    1482             : {
    1483        9374 :   pari_sp av = avma;
    1484        9374 :   return gerepileupto(av, gnorml2(RgX_gtofp(x, prec)));
    1485             : }
    1486             : INLINE GEN
    1487      187439 : RgC_fpnorml2(GEN x, long prec)
    1488             : {
    1489      187439 :   pari_sp av = avma;
    1490      187439 :   return gerepileupto(av, gnorml2(RgC_gtofp(x, prec)));
    1491             : }
    1492             : INLINE GEN
    1493        3860 : RgM_fpnorml2(GEN x, long prec)
    1494             : {
    1495        3860 :   pari_sp av = avma;
    1496        3860 :   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      260964 : affc_fixlg(GEN x, GEN res)
    1515             : {
    1516      260964 :   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       53435 :     set_avma((pari_sp)(res+3));
    1524       53435 :     res = cgetr(realprec(gel(res,1)));
    1525       53435 :     affrr_fixlg(x, res);
    1526             :   }
    1527      260964 :   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       32370 : ndec2nlong(long x) { return 1 + (long)((x)*(LOG2_10/BITS_IN_LONG)); }
    1540             : INLINE long
    1541       23892 : ndec2prec(long x) { return 2 + ndec2nlong(x); }
    1542             : INLINE long
    1543        8478 : 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     1191973 : nbits2nlong(long x) {
    1549     1191973 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1550             : }
    1551             : 
    1552             : INLINE long
    1553   317117201 : nbits2extraprec(long x) {
    1554   317117201 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1555             : }
    1556             : 
    1557             : /* Fast implementation of 2 + nbits2nlong(x) */
    1558             : INLINE long
    1559   109745750 : nbits2prec(long x) {
    1560   109745750 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1561             : }
    1562             : INLINE long
    1563     7700484 : nbits2lg(long x) {
    1564     7700484 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1565             : }
    1566             : /* ceil(x / sizeof(long)) */
    1567             : INLINE long
    1568     9994797 : nchar2nlong(long x) {
    1569     9994797 :   return (long)(((ulong)x+sizeof(long)-1) >> (TWOPOTBITS_IN_LONG-3L));
    1570             : }
    1571             : INLINE long
    1572  1164126651 : prec2nbits(long x) { return (x-2) * BITS_IN_LONG; }
    1573             : INLINE double
    1574      566026 : bit_accuracy_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1575             : INLINE double
    1576      302069 : prec2nbits_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1577             : INLINE long
    1578    32725751 : bit_prec(GEN x) { return prec2nbits(realprec(x)); }
    1579             : INLINE long
    1580  1049925723 : bit_accuracy(long x) { return prec2nbits(x); }
    1581             : INLINE long
    1582       12448 : 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  3482070482 : divsBIL(long n) { return n >> TWOPOTBITS_IN_LONG; }
    1589             : INLINE long
    1590  3437551403 : 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    35460548 : Fp_red(GEN a, GEN m) { return modii(a, m); }
    1601             : INLINE GEN
    1602    72073646 : Fp_add(GEN a, GEN b, GEN m)
    1603             : {
    1604    72073646 :   pari_sp av=avma;
    1605    72073646 :   GEN p = addii(a,b);
    1606    70818608 :   long s = signe(p);
    1607    70818608 :   if (!s) return p; /* = gen_0 */
    1608    63029864 :   if (s > 0) /* general case */
    1609             :   {
    1610    62803520 :     GEN t = subii(p, m);
    1611    63693174 :     s = signe(t);
    1612    63693174 :     if (!s) { set_avma(av); return gen_0; }
    1613    57861003 :     if (s < 0) { set_avma((pari_sp)p); return p; }
    1614    24426555 :     if (cmpii(t, m) < 0) return gerepileuptoint(av, t); /* general case ! */
    1615     1112629 :     p = remii(t, m);
    1616             :   }
    1617             :   else
    1618      226344 :     p = modii(p, m);
    1619     1338973 :   return gerepileuptoint(av, p);
    1620             : }
    1621             : INLINE GEN
    1622    56624735 : Fp_sub(GEN a, GEN b, GEN m)
    1623             : {
    1624    56624735 :   pari_sp av=avma;
    1625    56624735 :   GEN p = subii(a,b);
    1626    56130888 :   long s = signe(p);
    1627    56130888 :   if (!s) return p; /* = gen_0 */
    1628    49880608 :   if (s > 0)
    1629             :   {
    1630    24098697 :     if (cmpii(p, m) < 0) return p; /* general case ! */
    1631     1118545 :     p = remii(p, m);
    1632             :   }
    1633             :   else
    1634             :   {
    1635    25781911 :     GEN t = addii(p, m);
    1636    25726267 :     if (!s) { set_avma(av); return gen_0; }
    1637    25726267 :     if (s > 0) return gerepileuptoint(av, t); /* general case ! */
    1638    25726267 :     p = modii(t, m);
    1639             :   }
    1640    27604656 :   return gerepileuptoint(av, p);
    1641             : }
    1642             : INLINE GEN
    1643    13545184 : Fp_neg(GEN b, GEN m)
    1644             : {
    1645    13545184 :   pari_sp av = avma;
    1646    13545184 :   long s = signe(b);
    1647             :   GEN p;
    1648    13545184 :   if (!s) return gen_0;
    1649    10064475 :   if (s > 0)
    1650             :   {
    1651     9842559 :     p = subii(m, b);
    1652     9840296 :     if (signe(p) >= 0) return p; /* general case ! */
    1653      104117 :     p = modii(p, m);
    1654             :   } else
    1655      221916 :     p = remii(negi(b), m);
    1656      326033 :   return gerepileuptoint(av, p);
    1657             : }
    1658             : 
    1659             : INLINE GEN
    1660       23592 : Fp_halve(GEN a, GEN p)
    1661             : {
    1662       23592 :   if (mpodd(a)) a = addii(a,p);
    1663       23592 :   return shifti(a,-1);
    1664             : }
    1665             : 
    1666             : /* assume 0 <= u < p and ps2 = p>>1 */
    1667             : INLINE GEN
    1668    16737401 : Fp_center(GEN u, GEN p, GEN ps2)
    1669    16737401 : { return abscmpii(u,ps2)<=0? icopy(u): subii(u,p); }
    1670             : /* same without copy */
    1671             : INLINE GEN
    1672    15287198 : Fp_center_i(GEN u, GEN p, GEN ps2)
    1673    15287198 : { return abscmpii(u,ps2)<=0? u: subii(u,p); }
    1674             : 
    1675             : /* x + y*z mod p */
    1676             : INLINE GEN
    1677     5033740 : Fp_addmul(GEN x, GEN y, GEN z, GEN p)
    1678             : {
    1679             :   pari_sp av;
    1680     5033740 :   if (!signe(y) || !signe(z)) return Fp_red(x, p);
    1681     4736270 :   if (!signe(x)) return Fp_mul(z,y, p);
    1682     4432823 :   av = avma;
    1683     4432823 :   return gerepileuptoint(av, modii(addii(x, mulii(y,z)), p));
    1684             : }
    1685             : 
    1686             : INLINE GEN
    1687    92171979 : Fp_mul(GEN a, GEN b, GEN m)
    1688             : {
    1689    92171979 :   pari_sp av=avma;
    1690             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1691    92171979 :   (void)new_chunk(lg(a)+lg(b)+(lg(m)<<1));
    1692    92198224 :   p = mulii(a,b);
    1693    92311132 :   set_avma(av); return modii(p,m);
    1694             : }
    1695             : INLINE GEN
    1696    33514710 : Fp_sqr(GEN a, GEN m)
    1697             : {
    1698    33514710 :   pari_sp av=avma;
    1699             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1700    33514710 :   (void)new_chunk((lg(a)+lg(m))<<1);
    1701    33541082 :   p = sqri(a);
    1702    30793843 :   set_avma(av); return remii(p,m); /*Use remii: p >= 0 */
    1703             : }
    1704             : INLINE GEN
    1705    64752851 : Fp_mulu(GEN a, ulong b, GEN m)
    1706             : {
    1707    64752851 :   long l = lgefint(m);
    1708    64752851 :   if (l == 3)
    1709             :   {
    1710    38906430 :     ulong mm = m[2];
    1711    38906430 :     return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1712             :   } else {
    1713    25846421 :     pari_sp av = avma;
    1714             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1715    25846421 :     (void)new_chunk(lg(a)+1+(l<<1));
    1716    25851708 :     p = muliu(a,b);
    1717    24376375 :     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     9629204 : Fp_inv(GEN a, GEN m)
    1745             : {
    1746             :   GEN res;
    1747     9629204 :   if (! invmod(a,m,&res)) pari_err_INV("Fp_inv", mkintmod(res,m));
    1748     9628843 :   return res;
    1749             : }
    1750             : INLINE GEN
    1751      318572 : Fp_invsafe(GEN a, GEN m)
    1752             : {
    1753             :   GEN res;
    1754      318572 :   if (! invmod(a,m,&res)) return NULL;
    1755      318572 :   return res;
    1756             : }
    1757             : INLINE GEN
    1758     1655650 : Fp_div(GEN a, GEN b, GEN m)
    1759             : {
    1760     1655650 :   pari_sp av = avma;
    1761             :   GEN p;
    1762     1655650 :   if (lgefint(b) == 3)
    1763             :   {
    1764      668278 :     a = Fp_divu(a, b[2], m);
    1765      668278 :     if (signe(b) < 0) a = Fp_neg(a, m);
    1766      668278 :     return a;
    1767             :   }
    1768             :   /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1769      987372 :   (void)new_chunk(lg(a)+(lg(m)<<1));
    1770      987372 :   p = mulii(a, Fp_inv(b,m));
    1771      987372 :   set_avma(av); return modii(p,m);
    1772             : }
    1773             : INLINE GEN
    1774     1401803 : Fp_divu(GEN x, ulong a, GEN p)
    1775             : {
    1776     1401803 :   pari_sp av = avma;
    1777             :   ulong b;
    1778     1401803 :   if (lgefint(p) == 3)
    1779             :   {
    1780      984022 :     ulong pp = p[2], xp = umodiu(x, pp);
    1781      984022 :     return xp? utoipos(Fl_div(xp, a % pp, pp)): gen_0;
    1782             :   }
    1783      417781 :   x = Fp_red(x, p);
    1784      417781 :   b = Fl_neg(Fl_div(umodiu(x,a), umodiu(p,a), a), a); /* x + pb = 0 (mod a) */
    1785      417783 :   return gerepileuptoint(av, diviuexact(addmuliu(x, p, b), a));
    1786             : }
    1787             : 
    1788             : INLINE GEN
    1789      847620 : 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      448552 : get_F2x_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1796             : 
    1797             : INLINE long
    1798      121548 : get_F2x_degree(GEN T) { return typ(T)==t_VEC? F2x_degree(gel(T,2)): F2x_degree(T); }
    1799             : 
    1800             : INLINE GEN
    1801         378 : get_F2xqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1802             : 
    1803             : INLINE long
    1804      376495 : get_F2xqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1805             : 
    1806             : INLINE long
    1807      201684 : get_F2xqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1808             : 
    1809             : INLINE GEN
    1810     7588949 : get_Flx_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1811             : 
    1812             : INLINE long
    1813    16833608 : get_Flx_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1814             : 
    1815             : INLINE long
    1816    36002651 : get_Flx_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1817             : 
    1818             : INLINE GEN
    1819        2461 : get_FlxqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1820             : 
    1821             : INLINE long
    1822      369211 : get_FlxqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1823             : 
    1824             : INLINE long
    1825      155864 : get_FlxqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1826             : 
    1827             : INLINE GEN
    1828     1631639 : get_FpX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1829             : 
    1830             : INLINE long
    1831     3672460 : get_FpX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1832             : 
    1833             : INLINE long
    1834     2627896 : 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       57364 : 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    13447367 : submulii(GEN x, GEN y, GEN z)
    1853             : {
    1854    13447367 :   long lx = lgefint(x), ly, lz;
    1855             :   pari_sp av;
    1856             :   GEN t;
    1857    13447367 :   if (lx == 2) { t = mulii(z,y); togglesign(t); return t; }
    1858    11634350 :   ly = lgefint(y);
    1859    11634350 :   if (ly == 2) return icopy(x);
    1860    10498115 :   lz = lgefint(z);
    1861    10498115 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1862    10498115 :   t = mulii(z, y);
    1863    10498115 :   set_avma(av); return subii(x,t);
    1864             : }
    1865             : /* y*z - x */
    1866             : INLINE GEN
    1867     1240544 : mulsubii(GEN y, GEN z, GEN x)
    1868             : {
    1869     1240544 :   long lx = lgefint(x), ly, lz;
    1870             :   pari_sp av;
    1871             :   GEN t;
    1872     1240544 :   if (lx == 2) return mulii(z,y);
    1873      789975 :   ly = lgefint(y);
    1874      789975 :   if (ly == 2) return negi(x);
    1875      724652 :   lz = lgefint(z);
    1876      724652 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1877      724652 :   t = mulii(z, y);
    1878      724652 :   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      425378 : addmuliu(GEN x, GEN y, ulong u)
    1896             : {
    1897             :   pari_sp av;
    1898      425378 :   long ly = lgefint(y);
    1899      425378 :   if (ly == 2) return icopy(x);
    1900      425378 :   av = avma;
    1901      425378 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1902      425379 :   y = mului(u,y);
    1903      425369 :   set_avma(av); return addii(x, y);
    1904             : }
    1905             : /* x - u*y */
    1906             : INLINE GEN
    1907   123076104 : submuliu_inplace(GEN x, GEN y, ulong u)
    1908             : {
    1909             :   pari_sp av;
    1910   123076104 :   long ly = lgefint(y);
    1911   123076104 :   if (ly == 2) return x;
    1912    98595089 :   av = avma;
    1913    98595089 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1914    98595089 :   y = mului(u,y);
    1915    98595089 :   set_avma(av); return subii(x, y);
    1916             : }
    1917             : /* x + u*y */
    1918             : INLINE GEN
    1919   121589991 : addmuliu_inplace(GEN x, GEN y, ulong u)
    1920             : {
    1921             :   pari_sp av;
    1922   121589991 :   long ly = lgefint(y);
    1923   121589991 :   if (ly == 2) return x;
    1924    98506342 :   av = avma;
    1925    98506342 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1926    98506342 :   y = mului(u,y);
    1927    98506342 :   set_avma(av); return addii(x, y);
    1928             : }
    1929             : /* ux + vy */
    1930             : INLINE GEN
    1931    20702209 : lincombii(GEN u, GEN v, GEN x, GEN y)
    1932             : {
    1933    20702209 :   long lx = lgefint(x), ly;
    1934             :   GEN p1, p2;
    1935             :   pari_sp av;
    1936    20702209 :   if (lx == 2) return mulii(v,y);
    1937    14606666 :   ly = lgefint(y);
    1938    14606666 :   if (ly == 2) return mulii(u,x);
    1939    13379951 :   av = avma; (void)new_chunk(lx+ly+lgefint(u)+lgefint(v)); /* HACK */
    1940    13379962 :   p1 = mulii(u,x);
    1941    13379811 :   p2 = mulii(v,y);
    1942    13379807 :   set_avma(av); return addii(p1,p2);
    1943             : }
    1944             : 
    1945             : /*******************************************************************/
    1946             : /*                                                                 */
    1947             : /*                          GEN SUBTYPES                           */
    1948             : /*                                                                 */
    1949             : /*******************************************************************/
    1950             : 
    1951             : INLINE int
    1952  1256255232 : 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     1224304 : is_intreal_t(long t) { return (t <= t_REAL); }
    1957             : INLINE int
    1958   417606501 : is_matvec_t(long t) { return (t >= t_VEC && t <= t_MAT); }
    1959             : INLINE int
    1960    60096903 : is_noncalc_t(long tx) { return (tx) >= t_LIST; }
    1961             : INLINE int
    1962     1208831 : 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  3046347361 : is_recursive_t(long t) { return lontyp[t]; }
    1967             : INLINE int
    1968   173686842 : is_scalar_t(long t) { return (t < t_POL); }
    1969             : INLINE int
    1970     1499668 : is_vec_t(long t) { return (t == t_VEC || t == t_COL); }
    1971             : 
    1972             : /*******************************************************************/
    1973             : /*                                                                 */
    1974             : /*                         TRANSCENDENTAL                          */
    1975             : /*                                                                 */
    1976             : /*******************************************************************/
    1977             : INLINE GEN
    1978    22426070 : sqrtr(GEN x) {
    1979    22426070 :   long s = signe(x);
    1980    22426070 :   if (s == 0) return real_0_bit(expo(x) >> 1);
    1981    22392402 :   if (s >= 0) return sqrtr_abs(x);
    1982       34884 :   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      462496 : sqrtnr(GEN x, long n) {
    1997      462496 :   long s = signe(x);
    1998             :   GEN r;
    1999      462496 :   if (s == 0) return real_0_bit(expo(x) / n);
    2000      462496 :   r = sqrtnr_abs(x, n);
    2001      462496 :   if (s < 0) pari_err_IMPL("sqrtnr for x < 0");
    2002      462496 :   return r;
    2003             : }
    2004             : INLINE long
    2005      221160 : logint(GEN B, GEN y) { return logintall(B,y,NULL); }
    2006             : INLINE ulong
    2007     1997391 : ulogint(ulong B, ulong y)
    2008             : {
    2009             :   ulong r;
    2010             :   long e;
    2011     1997391 :   if (y == 2) return expu(B);
    2012     1979289 :   r = y;
    2013     6389262 :   for (e=1;; e++)
    2014             :   { /* here, r = y^e, r2 = y^(e-1) */
    2015    10799235 :     if (r >= B) return r == B? e: e-1;
    2016     4409959 :     r = umuluu_or_0(y, r);
    2017     4409973 :     if (!r) return e;
    2018             :   }
    2019             : }
    2020             : 
    2021             : /*******************************************************************/
    2022             : /*                                                                 */
    2023             : /*                         MISCELLANEOUS                           */
    2024             : /*                                                                 */
    2025             : /*******************************************************************/
    2026     1224227 : INLINE int ismpzero(GEN x) { return is_intreal_t(typ(x)) && !signe(x); }
    2027   658831147 : INLINE int isintzero(GEN x) { return typ(x) == t_INT && !signe(x); }
    2028     5712138 : 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   698296412 : INLINE int equali1(GEN n)
    2031   698296412 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(1)) && n[2] == 1; }
    2032    61424352 : INLINE int equalim1(GEN n)
    2033    61424352 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(-1)) && n[2] == 1; }
    2034             : /* works only for POSITIVE integers */
    2035   983127448 : INLINE int is_pm1(GEN n)
    2036   983127448 : { return lgefint(n) == 3 && n[2] == 1; }
    2037   245918748 : INLINE int is_bigint(GEN n)
    2038   245918748 : { long l = lgefint(n); return l > 3 || (l == 3 && (n[2] & HIGHBIT)); }
    2039             : 
    2040  2076185396 : INLINE int odd(long x) { return x & 1; }
    2041    29174432 : INLINE int both_odd(long x, long y) { return x & y & 1; }
    2042             : 
    2043             : INLINE int
    2044  2766849951 : isonstack(GEN x)
    2045  2766849951 : { return ((pari_sp)x >= pari_mainstack->bot
    2046  2766849951 :        && (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    23303593 : dbllog2r(GEN x)
    2051    23303593 : { return log2((double)(ulong)x[2]) + (double)(expo(x) - (BITS_IN_LONG-1)); }
    2052             : 
    2053             : INLINE GEN
    2054      363051 : mul_content(GEN cx, GEN cy)
    2055             : {
    2056      363051 :   if (!cx) return cy;
    2057      133090 :   if (!cy) return cx;
    2058       91548 :   return gmul(cx,cy);
    2059             : }
    2060             : INLINE GEN
    2061        6048 : inv_content(GEN c) { return c? ginv(c): NULL; }
    2062             : INLINE GEN
    2063     1629423 : mul_denom(GEN dx, GEN dy)
    2064             : {
    2065     1629423 :   if (!dx) return dy;
    2066     1076009 :   if (!dy) return dx;
    2067      340452 :   return mulii(dx,dy);
    2068             : }
    2069             : 
    2070             : /* POLYNOMIALS */
    2071             : INLINE GEN
    2072    17947601 : constant_coeff(GEN x) { return signe(x)? gel(x,2): gen_0; }
    2073             : INLINE GEN
    2074    93826092 : leading_coeff(GEN x) { return lg(x) == 2? gen_0: gel(x,lg(x)-1); }
    2075             : INLINE ulong
    2076      480539 : Flx_lead(GEN x) { return lg(x) == 2? 0: x[lg(x)-1]; }
    2077             : INLINE ulong
    2078       12302 : Flx_constant(GEN x) { return lg(x) == 2? 0: x[2]; }
    2079             : INLINE long
    2080  2851328455 : degpol(GEN x) { return lg(x)-3; }
    2081             : INLINE long
    2082  1410195669 : lgpol(GEN x) { return lg(x)-2; }
    2083             : INLINE long
    2084   122857030 : lgcols(GEN x) { return lg(gel(x,1)); }
    2085             : INLINE long
    2086    34558216 : 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      561714 : ZXQ_mul(GEN y, GEN x, GEN T) { return ZX_rem(ZX_mul(y, x), T); }
    2092             : INLINE GEN
    2093      282170 : ZXQ_sqr(GEN x, GEN T) { return ZX_rem(ZX_sqr(x), T); }
    2094             : 
    2095             : INLINE GEN
    2096    81470914 : RgX_copy(GEN x)
    2097             : {
    2098             :   long lx, i;
    2099    81470914 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
    2100    81470918 :   for (i = 2; i<lx; i++) gel(y,i) = gcopy(gel(x,i));
    2101    81470924 :   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     2961582 : RgX_coeff(GEN x, long n)
    2107             : {
    2108     2961582 :   ulong l = lg(x);
    2109     2961582 :   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     6857298 : 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       67885 : RgXQX_rem(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,ONLY_REM); }
    2119             : INLINE GEN
    2120      948448 : FpX_div(GEN x, GEN y, GEN p) { return FpX_divrem(x,y,p, NULL); }
    2121             : INLINE GEN
    2122     4495461 : Flx_div(GEN x, GEN y, ulong p) { return Flx_divrem(x,y,p, NULL); }
    2123             : INLINE GEN
    2124     2611740 : 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    54665854 : pol0_Flx(long sv) { return mkvecsmall(sv); }
    2129             : INLINE GEN
    2130    15124390 : pol1_Flx(long sv) { return mkvecsmall2(sv, 1); }
    2131             : INLINE GEN
    2132    17832512 : 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        1327 : zero_F2x(long sv) { return zero_Flx(sv); }
    2143             : INLINE GEN
    2144    11192518 : pol0_F2x(long sv) { return pol0_Flx(sv); }
    2145             : INLINE GEN
    2146     2877373 : pol1_F2x(long sv) { return pol1_Flx(sv); }
    2147             : INLINE GEN
    2148      687811 : polx_F2x(long sv) { return mkvecsmall2(sv, 2); }
    2149             : INLINE int
    2150      826479 : F2x_equal1(GEN x) { return Flx_equal1(x); }
    2151             : INLINE int
    2152     3139659 : F2x_equal(GEN V, GEN W) { return Flx_equal(V,W); }
    2153             : INLINE GEN
    2154    59981441 : F2x_copy(GEN x) { return leafcopy(x); }
    2155             : INLINE GEN
    2156           0 : F2v_copy(GEN x) { return leafcopy(x); }
    2157             : INLINE GEN
    2158     2274999 : Flv_copy(GEN x) { return leafcopy(x); }
    2159             : INLINE GEN
    2160    84222673 : Flx_copy(GEN x) { return leafcopy(x); }
    2161             : INLINE GEN
    2162     1874009 : vecsmall_copy(GEN x) { return leafcopy(x); }
    2163             : INLINE int
    2164     4891030 : Flx_equal1(GEN x) { return degpol(x)==0 && x[2] == 1; }
    2165             : INLINE int
    2166       18205 : ZX_equal1(GEN x) { return degpol(x)==0 && equali1(gel(x,2)); }
    2167             : INLINE int
    2168     5494305 : ZX_is_monic(GEN x) { return equali1(leading_coeff(x)); }
    2169             : 
    2170             : INLINE GEN
    2171    51149427 : ZX_renormalize(GEN x, long lx)    { return ZXX_renormalize(x,lx); }
    2172             : INLINE GEN
    2173    73156397 : FpX_renormalize(GEN x, long lx)   { return ZXX_renormalize(x,lx); }
    2174             : INLINE GEN
    2175      772525 : FpXX_renormalize(GEN x, long lx)  { return ZXX_renormalize(x,lx); }
    2176             : INLINE GEN
    2177     1251699 : FpXQX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
    2178             : INLINE GEN
    2179   112307511 : F2x_renormalize(GEN x, long lx)   { return Flx_renormalize(x,lx); }
    2180             : INLINE GEN
    2181       32362 : F2v_to_F2x(GEN x, long sv) {
    2182       32362 :   GEN y = leafcopy(x);
    2183       32362 :   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        7077 : gval(GEN x, long v) {
    2191        7077 :   pari_sp av = avma;
    2192        7077 :   long n = gvaluation(x, pol_x(v));
    2193        7077 :   set_avma(av); return n;
    2194             : }
    2195             : 
    2196             : INLINE void
    2197      470978 : RgX_shift_inplace_init(long v)
    2198      470978 : { 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      470978 : RgX_shift_inplace(GEN x, long v)
    2202             : {
    2203             :   long i, lx;
    2204             :   GEN y, z;
    2205      470978 :   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      131980 : zv_to_ZV(GEN x) { return vecsmall_to_vec(x); }
    2222             : INLINE GEN
    2223     5208135 : zc_to_ZC(GEN x) { return vecsmall_to_col(x); }
    2224             : INLINE GEN
    2225     3299581 : 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    17427645 : 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     1903236 : 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      901717 : ZC_hnfrem(GEN x, GEN y) { return ZC_hnfremdiv(x,y,NULL); }
    2247             : INLINE GEN
    2248       48866 : ZM_hnfrem(GEN x, GEN y) { return ZM_hnfdivrem(x,y,NULL); }
    2249             : INLINE GEN
    2250     2438999 : ZM_lll(GEN x, double D, long f) { return ZM_lll_norms(x,D,f,NULL); }
    2251             : INLINE void
    2252     5673651 : RgM_dimensions(GEN x, long *m, long *n) { *n = lg(x)-1; *m = *n? nbrows(x): 0; }
    2253             : INLINE GEN
    2254    10340323 : RgM_shallowcopy(GEN x)
    2255             : {
    2256             :   long l;
    2257    10340323 :   GEN y = cgetg_copy(x, &l);
    2258    10340333 :   while (--l > 0) gel(y,l) = leafcopy(gel(x,l));
    2259    10340340 :   return y;
    2260             : }
    2261             : INLINE GEN
    2262         304 : F2m_copy(GEN x) { return RgM_shallowcopy(x); }
    2263             : 
    2264             : INLINE GEN
    2265     1377740 : 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     2802820 : Fq_red(GEN x, GEN T, GEN p)
    2281     2802820 : { return typ(x)==t_INT? Fp_red(x,p): FpXQ_red(x,T,p); }
    2282             : INLINE GEN
    2283       43439 : Fq_to_FpXQ(GEN x, GEN T, GEN p /*unused*/)
    2284             : {
    2285             :   (void) p;
    2286       43439 :   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        1253 : gener_Fq_local(GEN T, GEN p, GEN L)
    2293             : { return T? gener_FpXQ_local(T,p, L)
    2294        1253 :           : 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       35076 : FlxqX_div(GEN x, GEN y, GEN T, ulong p) { return FlxqX_divrem(x, y, T, p, NULL); }
    2301             : INLINE GEN
    2302       33285 : 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      657718 : FqX_Fp_mul(GEN P, GEN u, GEN T, GEN p)
    2315      657718 : { 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       96825 : FqX_mul(GEN x, GEN y, GEN T, GEN p)
    2321       96825 : { 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        5600 : FqX_div(GEN x, GEN y, GEN T, GEN p)
    2336        5600 : { 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      259238 : FqX_gcd(GEN P,GEN Q,GEN T,GEN p)
    2354      259238 : {return T? FpXQX_gcd(P,Q,T,p): FpX_gcd(P,Q,p);}
    2355             : INLINE GEN
    2356       88289 : FqX_extgcd(GEN P,GEN Q,GEN T,GEN p, GEN *U, GEN *V)
    2357       88289 : { return T? FpXQX_extgcd(P,Q,T,p,U,V): FpX_extgcd(P,Q,p,U,V); }
    2358             : INLINE GEN
    2359        3248 : FqX_normalize(GEN z, GEN T, GEN p)
    2360        3248 : { 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       74571 : FqX_factor(GEN f, GEN T, GEN p)
    2367       74571 : { 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   100566886 : F2x_coeff(GEN x,long v)
    2444             : {
    2445   100566886 :    ulong u=(ulong)x[2+divsBIL(v)];
    2446   100565559 :    return (u>>remsBIL(v))&1UL;
    2447             : }
    2448             : 
    2449             : INLINE void
    2450     4728542 : F2x_clear(GEN x,long v)
    2451             : {
    2452     4728542 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2453     4728541 :    *u&=~(1UL<<remsBIL(v));
    2454     4728541 : }
    2455             : 
    2456             : INLINE void
    2457    32852718 : F2x_set(GEN x,long v)
    2458             : {
    2459    32852718 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2460    32825575 :    *u|=1UL<<remsBIL(v);
    2461    32811146 : }
    2462             : 
    2463             : INLINE void
    2464     1501765 : F2x_flip(GEN x,long v)
    2465             : {
    2466     1501765 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2467     1501765 :    *u^=1UL<<remsBIL(v);
    2468     1501765 : }
    2469             : 
    2470             : /* F2v */
    2471             : 
    2472             : INLINE ulong
    2473    95956054 : F2v_coeff(GEN x,long v) { return F2x_coeff(x,v-1); }
    2474             : 
    2475             : INLINE void
    2476     4728542 : F2v_clear(GEN x,long v) { F2x_clear(x,v-1); }
    2477             : 
    2478             : INLINE void
    2479     8964136 : F2v_set(GEN x,long v)   { F2x_set(x,v-1); }
    2480             : 
    2481             : INLINE void
    2482     1501765 : F2v_flip(GEN x,long v) { F2x_flip(x,v-1); }
    2483             : 
    2484             : /* F2m */
    2485             : 
    2486             : INLINE ulong
    2487    11672256 : 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     1501765 : 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     5869110 : sqrti(GEN x) { return sqrtremi(x,NULL); }
    2507             : INLINE GEN
    2508     6081008 : gaddgs(GEN y, long s) { return gaddsg(s,y); }
    2509             : INLINE int
    2510       59821 : 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    15086898 : gmulgs(GEN y, long s) { return gmulsg(s,y); }
    2519             : INLINE GEN
    2520     1352873 : gsubgs(GEN y, long s) { return gaddgs(y, -s); }
    2521             : INLINE GEN
    2522      682451 : gdivsg(long s, GEN y) { return gdiv(stoi(s), y); }
    2523             : 
    2524             : /* x t_COMPLEX */
    2525             : INLINE GEN
    2526    13039219 : 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     1285246 : sqrfrac(GEN x)
    2563             : {
    2564     1285246 :   GEN z = cgetg(3,t_FRAC);
    2565     1285246 :   gel(z,1) = sqri(gel(x,1));
    2566     1285246 :   gel(z,2) = sqri(gel(x,2)); return z;
    2567             : }
    2568             : 
    2569             : INLINE void
    2570    21808722 : normalize_frac(GEN z) {
    2571    21808722 :   if (signe(gel(z,2)) < 0) { togglesign(gel(z,1)); setabssign(gel(z,2)); }
    2572    21808722 : }
    2573             : 
    2574             : INLINE GEN
    2575      265504 : powii(GEN x, GEN n)
    2576             : {
    2577      265504 :   long ln = lgefint(n);
    2578      265504 :   if (ln == 3) {
    2579             :     GEN z;
    2580      261115 :     if (signe(n) > 0) return powiu(x, n[2]);
    2581        8085 :     z = cgetg(3, t_FRAC);
    2582        8085 :     gel(z,1) = gen_1;
    2583        8085 :     gel(z,2) = powiu(x, n[2]);
    2584        8085 :     return z;
    2585             :   }
    2586        4389 :   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     3979909 : INLINE GEN ell_get_a1(GEN e) { return gel(e,1); }
    2641     3095883 : INLINE GEN ell_get_a2(GEN e) { return gel(e,2); }
    2642     3861794 : INLINE GEN ell_get_a3(GEN e) { return gel(e,3); }
    2643     3888787 : INLINE GEN ell_get_a4(GEN e) { return gel(e,4); }
    2644     4704938 : INLINE GEN ell_get_a6(GEN e) { return gel(e,5); }
    2645     3318582 : INLINE GEN ell_get_b2(GEN e) { return gel(e,6); }
    2646     1025012 : INLINE GEN ell_get_b4(GEN e) { return gel(e,7); }
    2647     1630680 : 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     6167079 : INLINE GEN ell_get_c4(GEN e) { return gel(e,10); }
    2650     7403566 : INLINE GEN ell_get_c6(GEN e) { return gel(e,11); }
    2651     9653833 : 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    11455576 : INLINE long ell_get_type(GEN e) { return mael(e,14,1); }
    2654     1570458 : INLINE GEN ellff_get_field(GEN x) { return gmael(x, 15, 1); }
    2655      683125 : 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      699476 : 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     4624979 : INLINE int checkell_i(GEN e) { return typ(e) == t_VEC && lg(e) == 17; }
    2665    33981159 : INLINE int ell_is_inf(GEN z) { return lg(z) == 2; }
    2666      809781 : INLINE GEN ellinf(void) { return mkvec(gen_0); }
    2667             : 
    2668             : /*******************************************************************/
    2669             : /*                                                                 */
    2670             : /*                    ALGEBRAIC NUMBER THEORY                      */
    2671             : /*                                                                 */
    2672             : /*******************************************************************/
    2673     8345398 : INLINE GEN modpr_get_pr(GEN x)  { return gel(x,3); }
    2674      609527 : INLINE GEN modpr_get_p(GEN x)  { return pr_get_p(modpr_get_pr(x)); }
    2675     2643904 : INLINE GEN modpr_get_T(GEN x)  { return lg(x) == 4? NULL: gel(x,4); }
    2676             : 
    2677    19992585 : INLINE GEN pr_get_p(GEN pr)  { return gel(pr,1); }
    2678     6618860 : 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     2376899 : INLINE long pr_get_e(GEN pr) { return gel(pr,3)[2]; }
    2681     9159634 : INLINE long pr_get_f(GEN pr) { return gel(pr,4)[2]; }
    2682     6300186 : INLINE GEN pr_get_tau(GEN pr){ return gel(pr,5); }
    2683             : INLINE int
    2684     3189091 : pr_is_inert(GEN P) { return pr_get_f(P) == lg(pr_get_gen(P))-1; }
    2685             : INLINE GEN
    2686      232224 : 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      388935 : nf_get_varn(GEN nf) { return varn(gel(nf,1)); }
    2693             : INLINE GEN
    2694    31768521 : nf_get_pol(GEN nf) { return gel(nf,1); }
    2695             : INLINE long
    2696    25250638 : nf_get_degree(GEN nf) { return degpol( nf_get_pol(nf) ); }
    2697             : INLINE long
    2698     4136941 : nf_get_r1(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,1)); }
    2699             : INLINE long
    2700        1673 : nf_get_r2(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,2)); }
    2701             : INLINE GEN
    2702       53207 : nf_get_disc(GEN nf) { return gel(nf,3); }
    2703             : INLINE GEN
    2704      828932 : nf_get_index(GEN nf) { return gel(nf,4); }
    2705             : INLINE GEN
    2706     2864911 : nf_get_M(GEN nf) { return gmael(nf,5,1); }
    2707             : INLINE GEN
    2708       81517 : nf_get_G(GEN nf) { return gmael(nf,5,2); }
    2709             : INLINE GEN
    2710      408067 : 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        2324 : 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      332931 : 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      279048 : nf_get_zkprimpart(GEN nf)
    2729             : {
    2730      279048 :   GEN y = gel(nf,7);
    2731             :   /* test for old format of nf.zk: non normalized */
    2732      279048 :   if (!equali1(gel(nf,4)) && gequal1(gel(y,1))) y = Q_remove_denom(y,NULL);
    2733      279045 :   return y;
    2734             : }
    2735             : INLINE GEN
    2736      280194 : nf_get_zkden(GEN nf)
    2737             : {
    2738      280194 :   GEN y = gel(nf,7), D = gel(y,1);
    2739      280194 :   if (typ(D) == t_POL) D = gel(D,2);
    2740             :   /* test for old format of nf.zk: non normalized */
    2741      280194 :   if (!equali1(gel(nf,4)) && equali1(D)) D = Q_denom(y);
    2742      280191 :   return D;
    2743             : }
    2744             : INLINE GEN
    2745     2487038 : nf_get_invzk(GEN nf) { return gel(nf,8); }
    2746             : INLINE void
    2747       22843 : nf_get_sign(GEN nf, long *r1, long *r2)
    2748             : {
    2749       22843 :   GEN x = gel(nf,2);
    2750       22843 :   *r1 = itou(gel(x,1));
    2751       22843 :   *r2 = itou(gel(x,2));
    2752       22843 : }
    2753             : 
    2754             : INLINE GEN
    2755       92758 : abgrp_get_no(GEN x) { return gel(x,1); }
    2756             : INLINE GEN
    2757     2430512 : abgrp_get_cyc(GEN x) { return gel(x,2); }
    2758             : INLINE GEN
    2759      437924 : abgrp_get_gen(GEN x) { return gel(x,3); }
    2760             : INLINE GEN
    2761     2217781 : bnf_get_nf(GEN bnf) { return gel(bnf,7); }
    2762             : INLINE GEN
    2763      863472 : bnf_get_clgp(GEN bnf) { return gmael(bnf,8,1); }
    2764             : INLINE GEN
    2765        6713 : bnf_get_no(GEN bnf) { return abgrp_get_no(bnf_get_clgp(bnf)); }
    2766             : INLINE GEN
    2767      465441 : bnf_get_cyc(GEN bnf) { return abgrp_get_cyc(bnf_get_clgp(bnf)); }
    2768             : INLINE GEN
    2769      390989 : 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      502386 : bnf_get_logfu(GEN bnf) { return gel(bnf,3); }
    2774             : INLINE GEN
    2775        7457 : bnf_get_tuU(GEN bnf) { return gmael3(bnf,8,4,2); }
    2776             : INLINE long
    2777       40208 : 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        8885 : bnf_get_fu_nocheck(GEN bnf) { return gmael(bnf,8,5); }
    2786             : 
    2787             : INLINE GEN
    2788      862377 : bnr_get_bnf(GEN bnr) { return gel(bnr,1); }
    2789             : INLINE GEN
    2790      442133 : bnr_get_bid(GEN bnr) { return gel(bnr,2); }
    2791             : INLINE GEN
    2792       18648 : bnr_get_mod(GEN bnr) { return gmael(bnr,2,1); }
    2793             : INLINE GEN
    2794       32557 : bnr_get_nf(GEN bnr) { return gmael(bnr,1,7); }
    2795             : INLINE GEN
    2796      683850 : bnr_get_clgp(GEN bnr) { return gel(bnr,5); }
    2797             : INLINE GEN
    2798       82278 : bnr_get_no(GEN bnr) { return abgrp_get_no(bnr_get_clgp(bnr)); }
    2799             : INLINE GEN
    2800      585528 : 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      330413 : bid_get_mod(GEN bid) { return gel(bid,1); }
    2813             : INLINE GEN
    2814       65947 : bid_get_ideal(GEN bid) { return gmael(bid,1,1); }
    2815             : INLINE GEN
    2816         707 : bid_get_arch(GEN bid) { return gmael(bid,1,2); }
    2817             : INLINE GEN
    2818     1236477 : bid_get_grp(GEN bid) { return gel(bid,2); }
    2819             : INLINE GEN
    2820      497468 : bid_get_fact(GEN bid) { return gmael(bid,3,1); }
    2821             : INLINE GEN
    2822      427559 : bid_get_fact2(GEN bid) { return gmael(bid,3,2); }
    2823             : INLINE GEN
    2824      427370 : bid_get_sprk(GEN bid) { return gmael(bid,4,1); }
    2825             : INLINE GEN
    2826       49203 : bid_get_sarch(GEN bid) { return gmael(bid,4,2); }
    2827             : INLINE GEN
    2828      463161 : bid_get_archp(GEN bid) { return gmael3(bid,4,2,2); }
    2829             : INLINE GEN
    2830      757993 : 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     1190536 : 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       45346 : bid_get_gen(GEN bid) {
    2839       45346 :   GEN G = bid_get_grp(bid);
    2840       45346 :   if (lg(G) != 4) pari_err(e_MISC,"missing bid generators. Use idealstar(,,2)");
    2841       45346 :   return abgrp_get_gen(G);
    2842             : }
    2843             : 
    2844             : INLINE GEN
    2845    21944062 : znstar_get_N(GEN G) { return gmael(G,1,1); }
    2846             : INLINE GEN
    2847     2814224 : 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      187586 : 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     3488156 : znstar_get_conreycyc(GEN G) { return gmael(G,4,5); }
    2856             : INLINE GEN
    2857     1190742 : 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      118160 : znstar_get_U(GEN G) { return gel(G,5); }
    2862             : INLINE GEN
    2863      800366 : znstar_get_pe(GEN G) { return gmael(G,4,1); }
    2864             : INLINE GEN
    2865       19894 : gal_get_pol(GEN gal) { return gel(gal,1); }
    2866             : INLINE GEN
    2867        1323 : 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       15960 : gal_get_mod(GEN gal) { return gmael(gal,2,3); }
    2872             : INLINE GEN
    2873       16338 : gal_get_roots(GEN gal) { return gel(gal,3); }
    2874             : INLINE GEN
    2875       15918 : gal_get_invvdm(GEN gal) { return gel(gal,4); }
    2876             : INLINE GEN
    2877       15918 : gal_get_den(GEN gal) { return gel(gal,5); }
    2878             : INLINE GEN
    2879       66988 : gal_get_group(GEN gal) { return gel(gal,6); }
    2880             : INLINE GEN
    2881        1743 : gal_get_gen(GEN gal) { return gel(gal,7); }
    2882             : INLINE GEN
    2883        1379 : gal_get_orders(GEN gal) { return gel(gal,8); }
    2884             : 
    2885             : /* assume rnf a genuine rnf */
    2886             : INLINE long
    2887     1233638 : rnf_get_degree(GEN rnf) { return degpol(rnf_get_pol(rnf)); }
    2888             : INLINE long
    2889       16471 : 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         609 : rnf_get_alpha(GEN rnf) { return gmael(rnf, 11, 2); }
    2898             : INLINE GEN
    2899      384825 : rnf_get_nf(GEN rnf) { return gel(rnf,10); }
    2900             : INLINE GEN
    2901        3178 : rnf_get_nfzk(GEN rnf) { return gel(rnf,2); }
    2902             : INLINE GEN
    2903      205254 : rnf_get_polabs(GEN rnf) { return gmael(rnf,11,1); }
    2904             : INLINE GEN
    2905     1479849 : 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        3290 : rnf_get_zk(GEN rnf) { return gel(rnf,7); }
    2918             : INLINE GEN
    2919       96915 : 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       21784 : idealpseudored(GEN I, GEN G)
    2927       21784 : { 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      140674 : idealpseudomin(GEN I, GEN G)
    2933             : {
    2934      140674 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2935      140674 :   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      298542 : idealpseudomin_nonscalar(GEN I, GEN G)
    2940             : {
    2941      298542 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2942      298542 :   GEN m = ZM_ZC_mul(I, gel(u,1));
    2943      298542 :   if (ZV_isscalar(m) && lg(u) > 2) m = ZM_ZC_mul(I, gel(u,2));
    2944      298542 :   return m;
    2945             : }
    2946             : 
    2947             : INLINE GEN
    2948         826 : idealred_elt(GEN nf, GEN I) {
    2949         826 :   pari_sp av = avma;
    2950         826 :   GEN u = idealpseudomin(I, nf_get_roundG(nf));
    2951         826 :   return gerepileupto(av, u);
    2952             : }
    2953             : INLINE GEN
    2954      122877 : 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   226740122 : INLINE long closure_arity(GEN C)          { return ((ulong)C[1])&ARITYBITS; }
    2966    35511278 : INLINE long closure_is_variadic(GEN C) { return !!(((ulong)C[1])&VARARGBITS); }
    2967   190944276 : 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   190889707 : INLINE GEN closure_get_oper(GEN C)  { return gel(C,3); }
    2970   190872574 : INLINE GEN closure_get_data(GEN C)  { return gel(C,4); }
    2971        9729 : INLINE GEN closure_get_dbg(GEN C)   { return gel(C,5); }
    2972       23266 : INLINE GEN closure_get_text(GEN C)  { return gel(C,6); }
    2973     1234412 : INLINE GEN closure_get_frame(GEN C) { return gel(C,7); }
    2974             : 
    2975             : /*******************************************************************/
    2976             : /*                                                                 */
    2977             : /*                               ERRORS                            */
    2978             : /*                                                                 */
    2979             : /*******************************************************************/
    2980             : INLINE long
    2981       52870 : err_get_num(GEN e) { return e[1]; }
    2982             : INLINE GEN
    2983          77 : 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         487 : 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          63 : pari_err_FLAG(const char *f) { pari_err(e_FLAG,f); }
    2999             : INLINE void
    3000         427 : pari_err_IMPL(const char *f) { pari_err(e_IMPL,f); }
    3001             : INLINE void
    3002       19716 : 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        2085 : 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         196 : 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          86 : 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          70 : 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          77 : pari_err_SQRTN(const char *f, GEN x) { pari_err(e_SQRTN, f,x); }
    3027             : INLINE void
    3028       12685 : 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