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 23011-59c7027a2) Lines: 1264 1433 88.2 %
Date: 2018-09-22 05:37:52 Functions: 561 639 87.8 %
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     2740783 : mkintmod(GEN x, GEN y) { retmkintmod(x,y); }
     141             : INLINE GEN
     142        3948 : mkintmodu(ulong x, ulong y) {
     143        3948 :   GEN v = cgetg(3,t_INTMOD);
     144        3948 :   gel(v,1) = utoipos(y);
     145        3948 :   gel(v,2) = utoi(x); return v;
     146             : }
     147             : INLINE GEN
     148     2541147 : mkpolmod(GEN x, GEN y) { retmkpolmod(x,y); }
     149             : INLINE GEN
     150    22980931 : mkfrac(GEN x, GEN y) { retmkfrac(x,y); }
     151             : INLINE GEN
     152       31822 : 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       12215 : Qtoss(GEN q, long *n, long *d)
     156             : {
     157       12215 :   if (typ(q) == t_INT) { *n = itos(q); *d = 1; }
     158        2443 :   else { *n = itos(gel(q,1)); *d = itou(gel(q,2)); }
     159       12215 : }
     160             : INLINE GEN
     161    37068493 : sstoQ(long n, long d)
     162             : {
     163             :   ulong r;
     164             :   long g, q;
     165    37068493 :   if (!n)
     166             :   {
     167       59276 :     if (!d) pari_err_INV("sstoQ",gen_0);
     168       59276 :     return gen_0;
     169             :   }
     170    37009217 :   if (d < 0) { d = -d; n = -n; }
     171    37009217 :   if (d == 1) return stoi(n);
     172    37006004 :   q = udivuu_rem(labs(n),d,&r);
     173    37006004 :   if (!r) return n > 0? utoipos(q): utoineg(q);
     174     1517831 :   g = ugcd(d,r); /* gcd(n,d) */
     175     1517831 :   if (g != 1) { n /= g; d /= g; }
     176     1517831 :   retmkfrac(stoi(n), utoi(d));
     177             : }
     178             : 
     179             : INLINE GEN
     180     6635608 : mkfraccopy(GEN x, GEN y) { retmkfrac(icopy(x), icopy(y)); }
     181             : INLINE GEN
     182           7 : mkrfrac(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     183           7 :   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     8944820 : mkcomplex(GEN x, GEN y) { retmkcomplex(x,y); }
     189             : INLINE GEN
     190      448819 : gen_I(void) { return mkcomplex(gen_0, gen_1); }
     191             : INLINE GEN
     192      296268 : 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    62381783 : mkvecsmall(long x) { GEN v = cgetg(2, t_VECSMALL); v[1] = x; return v; }
     199             : INLINE GEN
     200   113050043 : mkvecsmall2(long x,long y) { GEN v = cgetg(3, t_VECSMALL);
     201   113045892 :   v[1]=x; v[2]=y; return v; }
     202             : INLINE GEN
     203    57698213 : mkvecsmall3(long x,long y,long z) { GEN v = cgetg(4, t_VECSMALL);
     204    57695360 :   v[1]=x; v[2]=y; v[3]=z; return v; }
     205             : INLINE GEN
     206    11930206 : mkvecsmall4(long x,long y,long z,long t) { GEN v = cgetg(5, t_VECSMALL);
     207    11922714 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; return v; }
     208             : INLINE GEN
     209      466226 : mkvecsmall5(long x,long y,long z,long t,long u) { GEN v = cgetg(6, t_VECSMALL);
     210      466226 :   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    14111823 : mkvec(GEN x) { retmkvec(x); }
     217             : INLINE GEN
     218    95714398 : mkvec2(GEN x, GEN y) { retmkvec2(x,y); }
     219             : INLINE GEN
     220    71785712 : mkvec3(GEN x, GEN y, GEN z) { retmkvec3(x,y,z); }
     221             : INLINE GEN
     222     7254867 : mkvec4(GEN x, GEN y, GEN z, GEN t) { retmkvec4(x,y,z,t); }
     223             : INLINE GEN
     224    11968294 : 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       19794 : 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       35084 : mkveccopy(GEN x) { GEN v = cgetg(2, t_VEC); gel(v,1) = gcopy(x); return v; }
     235             : INLINE GEN
     236       91324 : mkvec2copy(GEN x, GEN y) {
     237       91324 :   GEN v = cgetg(3,t_VEC); gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     238             : /* col */
     239             : INLINE GEN
     240     2417874 : mkcol(GEN x) { retmkcol(x); }
     241             : INLINE GEN
     242    23606124 : 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     2176146 : 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       46031 : mkcolcopy(GEN x) { GEN v = cgetg(2, t_COL); gel(v,1) = gcopy(x); return v; }
     261             : /* mat */
     262             : INLINE GEN
     263     2513300 : mkmat(GEN x) { retmkmat(x); }
     264             : INLINE GEN
     265    28845235 : 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       21998 : 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       62364 : mkoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_1; return v; }
     278             : INLINE GEN
     279       14098 : mkmoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_m1; return v; }
     280             : INLINE long
     281       88716 : inf_get_sign(GEN x) { return signe(gel(x,1)); }
     282             : INLINE GEN
     283       10661 : mkmat22s(long a, long b, long c, long d) {retmkmat2(mkcol2s(a,c),mkcol2s(b,d));}
     284             : INLINE GEN
     285     1533049 : mkmat22(GEN a, GEN b, GEN c, GEN d) { retmkmat2(mkcol2(a,c),mkcol2(b,d)); }
     286             : 
     287             : /* pol */
     288             : INLINE GEN
     289      972236 : pol_x(long v) {
     290      972236 :   GEN p = cgetg(4, t_POL);
     291      972236 :   p[1] = evalsigne(1)|evalvarn(v);
     292      972236 :   gel(p,2) = gen_0;
     293      972236 :   gel(p,3) = gen_1; return p;
     294             : }
     295             : /* x^n, assume n >= 0 */
     296             : INLINE GEN
     297     2699935 : pol_xn(long n, long v) {
     298     2699935 :   long i, a = n+2;
     299     2699935 :   GEN p = cgetg(a+1, t_POL);
     300     2699935 :   p[1] = evalsigne(1)|evalvarn(v);
     301     2699935 :   for (i = 2; i < a; i++) gel(p,i) = gen_0;
     302     2699935 :   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     1502064 : pol_1(long v) {
     313     1502064 :   GEN p = cgetg(3, t_POL);
     314     1502064 :   p[1] = evalsigne(1)|evalvarn(v);
     315     1502064 :   gel(p,2) = gen_1; return p;
     316             : }
     317             : INLINE GEN
     318    29081756 : pol_0(long v)
     319             : {
     320    29081756 :   GEN x = cgetg(2,t_POL);
     321    29081756 :   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     8348885 : 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     8663086 : const_col(long n, GEN x) { retconst_col(n, x); }
     337             : INLINE GEN
     338     8242262 : const_vecsmall(long n, long c)
     339             : {
     340             :   long i;
     341     8242262 :   GEN V = cgetg(n+1,t_VECSMALL);
     342     8242272 :   for(i=1;i<=n;i++) V[i] = c;
     343     8242272 :   return V;
     344             : }
     345             : 
     346             : /***   ZERO   ***/
     347             : /* O(p^e) */
     348             : INLINE GEN
     349      302747 : zeropadic(GEN p, long e)
     350             : {
     351      302747 :   GEN y = cgetg(5,t_PADIC);
     352      302747 :   gel(y,4) = gen_0;
     353      302747 :   gel(y,3) = gen_1;
     354      302747 :   gel(y,2) = icopy(p);
     355      302747 :   y[1] = evalvalp(e) | _evalprecp(0);
     356      302747 :   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      143493 : zeroser(long v, long e)
     371             : {
     372      143493 :   GEN x = cgetg(2, t_SER);
     373      143493 :   x[1] = evalvalp(e) | evalvarn(v); return x;
     374             : }
     375             : INLINE int
     376     5743466 : ser_isexactzero(GEN x)
     377             : {
     378     5743466 :   if (!signe(x)) switch(lg(x))
     379             :   {
     380      136136 :     case 2: return 1;
     381         854 :     case 3: return isexactzero(gel(x,2));
     382             :   }
     383     5606476 :   return 0;
     384             : }
     385             : /* 0 * pol_x(v) */
     386             : INLINE GEN
     387    14102666 : zeropol(long v) { return pol_0(v); }
     388             : /* vector(n) */
     389             : INLINE GEN
     390    35992180 : zerocol(long n)
     391             : {
     392    35992180 :   GEN y = cgetg(n+1,t_COL);
     393    35992180 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     394    35992180 :   return y;
     395             : }
     396             : /* vectorv(n) */
     397             : INLINE GEN
     398    18812310 : zerovec(long n)
     399             : {
     400    18812310 :   GEN y = cgetg(n+1,t_VEC);
     401    18812316 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     402    18812316 :   return y;
     403             : }
     404             : /* matrix(m, n) */
     405             : INLINE GEN
     406       16107 : zeromat(long m, long n)
     407             : {
     408       16107 :   GEN y = cgetg(n+1,t_MAT);
     409       16107 :   GEN v = zerocol(m);
     410       16107 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     411       16107 :   return y;
     412             : }
     413             : /* = zero_zx, sv is a evalvarn()*/
     414             : INLINE GEN
     415      931135 : zero_Flx(long sv) { return pol0_Flx(sv); }
     416             : INLINE GEN
     417    33304087 : zero_Flv(long n)
     418             : {
     419    33304087 :   GEN y = cgetg(n+1,t_VECSMALL);
     420    33305671 :   long i; for (i=1; i<=n; i++) y[i] = 0;
     421    33305671 :   return y;
     422             : }
     423             : /* matrix(m, n) */
     424             : INLINE GEN
     425      912953 : zero_Flm(long m, long n)
     426             : {
     427      912953 :   GEN y = cgetg(n+1,t_MAT);
     428      912942 :   GEN v = zero_Flv(m);
     429      912949 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     430      912949 :   return y;
     431             : }
     432             : /* matrix(m, n) */
     433             : INLINE GEN
     434      104213 : zero_Flm_copy(long m, long n)
     435             : {
     436      104213 :   GEN y = cgetg(n+1,t_MAT);
     437      104208 :   long i; for (i=1; i<=n; i++) gel(y,i) = zero_Flv(m);
     438      104215 :   return y;
     439             : }
     440             : 
     441             : INLINE GEN
     442      793137 : zero_F2v(long m)
     443             : {
     444      793137 :   long l = nbits2nlong(m);
     445      793137 :   GEN v  = zero_Flv(l+1);
     446      793137 :   v[1] = m;
     447      793137 :   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      276546 : zero_F2m_copy(long m, long n)
     464             : {
     465             :   long i;
     466      276546 :   GEN M = cgetg(n+1, t_MAT);
     467      806069 :   for (i = 1; i <= n; i++)
     468      529523 :     gel(M,i)= zero_F2v(m);
     469      276546 :   return M;
     470             : }
     471             : 
     472             : /* matrix(m, n) */
     473             : INLINE GEN
     474     4751963 : zeromatcopy(long m, long n)
     475             : {
     476     4751963 :   GEN y = cgetg(n+1,t_MAT);
     477     4751963 :   long i; for (i=1; i<=n; i++) gel(y,i) = zerocol(m);
     478     4751963 :   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     1311348 : col_ei(long n, long i) { GEN e = zerocol(n); gel(e,i) = gen_1; return e; }
     494             : INLINE GEN
     495      326509 : 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       71379 : vecsmall_ei(long n, long i) { GEN e = zero_zv(n); e[i] = 1; return e; }
     500             : INLINE GEN
     501      657808 : Rg_col_ei(GEN x, long n, long i) { GEN e = zerocol(n); gel(e,i) = x; return e; }
     502             : 
     503             : INLINE GEN
     504    12488431 : shallowcopy(GEN x)
     505    12488431 : { return typ(x) == t_MAT ? RgM_shallowcopy(x): leafcopy(x); }
     506             : 
     507             : /* routines for naive growarrays */
     508             : INLINE GEN
     509    12698559 : vectrunc_init(long l)
     510             : {
     511    12698559 :   GEN z = new_chunk(l);
     512    12698829 :   z[0] = evaltyp(t_VEC) | _evallg(1); return z;
     513             : }
     514             : INLINE GEN
     515          28 : coltrunc_init(long l)
     516             : {
     517          28 :   GEN z = new_chunk(l);
     518          28 :   z[0] = evaltyp(t_COL) | _evallg(1); return z;
     519             : }
     520             : INLINE void
     521   253345192 : lg_increase(GEN x) { x[0]++; }
     522             : INLINE void
     523    51301072 : 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    82748119 : vecsmalltrunc_init(long l)
     534             : {
     535    82748119 :   GEN z = new_chunk(l);
     536    82748119 :   z[0] = evaltyp(t_VECSMALL) | _evallg(1); return z;
     537             : }
     538             : INLINE void
     539    33040635 : vecsmalltrunc_append(GEN x, long t) { x[ lg(x) ] = t; lg_increase(x); }
     540             : 
     541             : /*******************************************************************/
     542             : /*                                                                 */
     543             : /*                        VEC / COL / VECSMALL                     */
     544             : /*                                                                 */
     545             : /*******************************************************************/
     546             : /* shallow*/
     547             : INLINE GEN
     548           0 : vec_shorten(GEN v, long n)
     549             : {
     550             :   long i;
     551           0 :   GEN V = cgetg(n+1,t_VEC);
     552           0 :   for(i=1;i<=n;i++) gel(V,i) = gel(v,i);
     553           0 :   return V;
     554             : }
     555             : /* shallow*/
     556             : INLINE GEN
     557       13710 : vec_lengthen(GEN v, long n)
     558             : {
     559             :   long i;
     560       13710 :   long l=lg(v);
     561       13710 :   GEN V = cgetg(n+1,t_VEC);
     562       13710 :   for(i=1;i<l;i++) gel(V,i) = gel(v,i);
     563       13710 :   return V;
     564             : }
     565             : /* shallow*/
     566             : INLINE GEN
     567       61173 : vec_append(GEN V, GEN s)
     568             : {
     569       61173 :   long i, l2 = lg(V);
     570       61173 :   GEN res = cgetg(l2+1, typ(V));
     571       61173 :   for (i = 1; i < l2; ++i) gel(res, i) = gel(V,i);
     572       61173 :   gel(res,l2) = s; return res;
     573             : }
     574             : /* shallow*/
     575             : INLINE GEN
     576        1785 : vec_prepend(GEN v, GEN s)
     577             : {
     578        1785 :   long i, l = lg(v);
     579        1785 :   GEN w = cgetg(l+1, typ(v));
     580        1785 :   gel(w,1) = s;
     581        1785 :   for (i = 2; i <= l; ++i) gel(w,i) = gel(v,i-1);
     582        1785 :   return w;
     583             : }
     584             : /* shallow*/
     585             : INLINE GEN
     586           0 : vec_setconst(GEN v, GEN x)
     587             : {
     588           0 :   long i, l = lg(v);
     589           0 :   for (i = 1; i < l; i++) gel(v,i) = x;
     590           0 :   return v;
     591             : }
     592             : INLINE GEN
     593      732358 : vecsmall_shorten(GEN v, long n)
     594             : {
     595             :   long i;
     596      732358 :   GEN V = cgetg(n+1,t_VECSMALL);
     597      732362 :   for(i=1;i<=n;i++) V[i] = v[i];
     598      732362 :   return V;
     599             : }
     600             : INLINE GEN
     601          21 : vecsmall_lengthen(GEN v, long n)
     602             : {
     603          21 :   long i, l = lg(v);
     604          21 :   GEN V = cgetg(n+1,t_VECSMALL);
     605          21 :   for(i=1;i<l;i++) V[i] = v[i];
     606          21 :   return V;
     607             : }
     608             : 
     609             : INLINE GEN
     610      457763 : vec_to_vecsmall(GEN x)
     611      457763 : { pari_APPLY_long(itos(gel(x,i))) }
     612             : INLINE GEN
     613      135396 : vecsmall_to_vec(GEN x)
     614      135396 : { pari_APPLY_type(t_VEC, stoi(x[i])) }
     615             : INLINE GEN
     616        1617 : vecsmall_to_vec_inplace(GEN z)
     617             : {
     618        1617 :   long i, l = lg(z);
     619        1617 :   for (i=1; i<l; i++) gel(z,i) = stoi(z[i]);
     620        1617 :   settyp(z, t_VEC); return z;
     621             : }
     622             : INLINE GEN
     623     5210063 : vecsmall_to_col(GEN x)
     624     5210063 : { pari_APPLY_type(t_COL, stoi(x[i])) }
     625             : 
     626             : INLINE int
     627     8065780 : vecsmall_lexcmp(GEN x, GEN y)
     628             : {
     629             :   long lx,ly,l,i;
     630     8065780 :   lx = lg(x);
     631     8065780 :   ly = lg(y); l = minss(lx,ly);
     632    39684887 :   for (i=1; i<l; i++)
     633    37752457 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     634     1932430 :   if (lx == ly) return 0;
     635          14 :   return (lx < ly)? -1 : 1;
     636             : }
     637             : 
     638             : INLINE int
     639    85155511 : vecsmall_prefixcmp(GEN x, GEN y)
     640             : {
     641    85155511 :   long i, lx = lg(x), ly = lg(y), l = minss(lx,ly);
     642   394027655 :   for (i=1; i<l; i++)
     643   374395014 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     644    19632641 :   return 0;
     645             : }
     646             : 
     647             : /*Can be used on t_VEC, but coeffs not gcopy-ed*/
     648             : INLINE GEN
     649       14162 : vecsmall_prepend(GEN V, long s)
     650             : {
     651       14162 :   long i, l2 = lg(V);
     652       14162 :   GEN res = cgetg(l2+1, typ(V));
     653       14162 :   res[1] = s;
     654       14162 :   for (i = 2; i <= l2; ++i) res[i] = V[i - 1];
     655       14162 :   return res;
     656             : }
     657             : 
     658             : INLINE GEN
     659     2552995 : vecsmall_append(GEN V, long s)
     660             : {
     661     2552995 :   long i, l2 = lg(V);
     662     2552995 :   GEN res = cgetg(l2+1, t_VECSMALL);
     663     2552995 :   for (i = 1; i < l2; ++i) res[i] = V[i];
     664     2552995 :   res[l2] = s; return res;
     665             : }
     666             : 
     667             : INLINE GEN
     668      782116 : vecsmall_concat(GEN u, GEN v)
     669             : {
     670      782116 :   long i, l1 = lg(u)-1, l2 = lg(v)-1;
     671      782116 :   GEN res = cgetg(l1+l2+1, t_VECSMALL);
     672      782116 :   for (i = 1; i <= l1; ++i) res[i]    = u[i];
     673      782116 :   for (i = 1; i <= l2; ++i) res[i+l1] = v[i];
     674      782116 :   return res;
     675             : }
     676             : 
     677             : /* return the number of indices where u and v are equal */
     678             : INLINE long
     679           0 : vecsmall_coincidence(GEN u, GEN v)
     680             : {
     681           0 :   long i, s = 0, l = minss(lg(u),lg(v));
     682           0 :   for(i=1; i<l; i++)
     683           0 :     if(u[i] == v[i]) s++;
     684           0 :   return s;
     685             : }
     686             : 
     687             : /* returns the first index i<=n such that x=v[i] if it exists, 0 otherwise */
     688             : INLINE long
     689           0 : vecsmall_isin(GEN v, long x)
     690             : {
     691           0 :   long i, l = lg(v);
     692           0 :   for (i = 1; i < l; i++)
     693           0 :     if (v[i] == x) return i;
     694           0 :   return 0;
     695             : }
     696             : 
     697             : INLINE long
     698          84 : vecsmall_pack(GEN V, long base, long mod)
     699             : {
     700          84 :   long i, s = 0;
     701          84 :   for(i=1; i<lg(V); i++) s = (base*s + V[i]) % mod;
     702          84 :   return s;
     703             : }
     704             : 
     705             : INLINE long
     706          14 : vecsmall_indexmax(GEN x)
     707             : {
     708          14 :   long i, i0 = 1, t = x[1], lx = lg(x);
     709          56 :   for (i=2; i<lx; i++)
     710          42 :     if (x[i] > t) t = x[i0=i];
     711          14 :   return i0;
     712             : }
     713             : 
     714             : INLINE long
     715      154223 : vecsmall_max(GEN x)
     716             : {
     717      154223 :   long i, t = x[1], lx = lg(x);
     718      559244 :   for (i=2; i<lx; i++)
     719      405021 :     if (x[i] > t) t = x[i];
     720      154223 :   return t;
     721             : }
     722             : 
     723             : INLINE long
     724          14 : vecsmall_indexmin(GEN x)
     725             : {
     726          14 :   long i, i0 = 1, t = x[1], lx =lg(x);
     727          56 :   for (i=2; i<lx; i++)
     728          42 :     if (x[i] < t) t = x[i0=i];
     729          14 :   return i0;
     730             : }
     731             : 
     732             : INLINE long
     733        1421 : vecsmall_min(GEN x)
     734             : {
     735        1421 :   long i, t = x[1], lx =lg(x);
     736        9947 :   for (i=2; i<lx; i++)
     737        8526 :     if (x[i] < t) t = x[i];
     738        1421 :   return t;
     739             : }
     740             : 
     741             : INLINE int
     742     4976051 : ZV_isscalar(GEN x)
     743             : {
     744     4976051 :   long l = lg(x);
     745    14205343 :   while (--l > 1)
     746     8140566 :     if (signe(gel(x, l))) return 0;
     747     1088726 :   return 1;
     748             : }
     749             : INLINE int
     750    19351595 : QV_isscalar(GEN x)
     751             : {
     752    19351595 :   long lx = lg(x),i;
     753    20867286 :   for (i=2; i<lx; i++)
     754    20320577 :     if (!isintzero(gel(x, i))) return 0;
     755      546709 :   return 1;
     756             : }
     757             : INLINE int
     758        7501 : RgV_isscalar(GEN x)
     759             : {
     760        7501 :   long lx = lg(x),i;
     761       10891 :   for (i=2; i<lx; i++)
     762        9809 :     if (!gequal0(gel(x, i))) return 0;
     763        1082 :   return 1;
     764             : }
     765             : INLINE int
     766           0 : RgX_isscalar(GEN x)
     767             : {
     768             :   long i;
     769           0 :   for (i=lg(x)-1; i>2; i--)
     770           0 :     if (!gequal0(gel(x, i))) return 0;
     771           0 :   return 1;
     772             : }
     773             : INLINE long
     774     4502657 : RgX_equal_var(GEN x, GEN y) { return varn(x) == varn(y) && RgX_equal(x,y); }
     775             : 
     776             : INLINE int
     777        5909 : RgX_is_rational(GEN x)
     778             : {
     779             :   long i;
     780       28875 :   for (i = lg(x)-1; i > 1; i--)
     781       26879 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     782        1996 :   return 1;
     783             : }
     784             : INLINE int
     785     4308706 : RgX_is_ZX(GEN x)
     786             : {
     787             :   long i;
     788    18652926 :   for (i = lg(x)-1; i > 1; i--)
     789    14396426 :     if (typ(gel(x,i)) != t_INT) return 0;
     790     4256500 :   return 1;
     791             : }
     792             : INLINE int
     793      262241 : RgX_is_QX(GEN x)
     794             : {
     795      262241 :   long k = lg(x)-1;
     796      926254 :   for ( ; k>1; k--)
     797      664258 :     if (!is_rational_t(typ(gel(x,k)))) return 0;
     798      261996 :   return 1;
     799             : }
     800             : INLINE int
     801    16160498 : RgX_is_monomial(GEN x)
     802             : {
     803             :   long i;
     804    16160498 :   if (!signe(x)) return 0;
     805    26705625 :   for (i=lg(x)-2; i>1; i--)
     806    18325823 :     if (!isexactzero(gel(x,i))) return 0;
     807     8379802 :   return 1;
     808             : }
     809             : INLINE int
     810    27032589 : RgV_is_ZV(GEN x)
     811             : {
     812             :   long i;
     813   111360440 :   for (i = lg(x)-1; i > 0; i--)
     814    84330056 :     if (typ(gel(x,i)) != t_INT) return 0;
     815    27030384 :   return 1;
     816             : }
     817             : INLINE int
     818       15677 : RgV_is_QV(GEN x)
     819             : {
     820             :   long i;
     821       69411 :   for (i = lg(x)-1; i > 0; i--)
     822       54406 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     823       15005 :   return 1;
     824             : }
     825             : 
     826             : /********************************************************************/
     827             : /**                                                                **/
     828             : /**            Dynamic arrays implementation                       **/
     829             : /**                                                                **/
     830             : /********************************************************************/
     831             : INLINE void **
     832   404190115 : pari_stack_base(pari_stack *s) { return s->data; }
     833             : 
     834             : INLINE void
     835     1709626 : pari_stack_init(pari_stack *s, size_t size, void **data)
     836             : {
     837     1709626 :   s->data = data;
     838     1709626 :   *data = NULL;
     839     1709626 :   s->n = 0;
     840     1709626 :   s->alloc = 0;
     841     1709626 :   s->size = size;
     842     1709626 : }
     843             : 
     844             : INLINE void
     845   402531854 : pari_stack_alloc(pari_stack *s, long nb)
     846             : {
     847   402531854 :   void **sdat = pari_stack_base(s);
     848   402535442 :   long alloc = s->alloc;
     849   402535442 :   if (s->n+nb <= alloc) return;
     850      632173 :   if (!alloc)
     851      580258 :     alloc = nb;
     852             :   else
     853             :   {
     854       51915 :     while (s->n+nb > alloc) alloc <<= 1;
     855             :   }
     856      632173 :   *sdat = pari_realloc(*sdat,alloc*s->size);
     857      632904 :   s->alloc = alloc;
     858             : }
     859             : 
     860             : INLINE long
     861   324736766 : pari_stack_new(pari_stack *s) { pari_stack_alloc(s, 1); return s->n++; }
     862             : 
     863             : INLINE void
     864     1654352 : pari_stack_delete(pari_stack *s)
     865             : {
     866     1654352 :   void **sdat = pari_stack_base(s);
     867     1651374 :   if (*sdat) pari_free(*sdat);
     868     1663561 : }
     869             : 
     870             : INLINE void
     871        4794 : pari_stack_pushp(pari_stack *s, void *u)
     872             : {
     873        4794 :   long n = pari_stack_new(s);
     874        4794 :   void **sdat =(void**) *pari_stack_base(s);
     875        4794 :   sdat[n] = u;
     876        4794 : }
     877             : 
     878             : /*******************************************************************/
     879             : /*                                                                 */
     880             : /*                            EXTRACT                              */
     881             : /*                                                                 */
     882             : /*******************************************************************/
     883             : INLINE GEN
     884   198830884 : vecslice(GEN A, long y1, long y2)
     885             : {
     886   198830884 :   long i,lB = y2 - y1 + 2;
     887   198830884 :   GEN B = cgetg(lB, typ(A));
     888   198831803 :   for (i=1; i<lB; i++) B[i] = A[y1-1+i];
     889   198831803 :   return B;
     890             : }
     891             : INLINE GEN
     892      805083 : vecslicepermute(GEN A, GEN p, long y1, long y2)
     893             : {
     894      805083 :   long i,lB = y2 - y1 + 2;
     895      805083 :   GEN B = cgetg(lB, typ(A));
     896      805085 :   for (i=1; i<lB; i++) B[i] = A[p[y1-1+i]];
     897      805085 :   return B;
     898             : }
     899             : /* rowslice(rowpermute(A,p), x1, x2) */
     900             : INLINE GEN
     901       38458 : rowslicepermute(GEN x, GEN p, long j1, long j2)
     902       38458 : { pari_APPLY_same(vecslicepermute(gel(x,i),p,j1,j2)) }
     903             : 
     904             : INLINE GEN
     905    22007820 : rowslice(GEN x, long j1, long j2)
     906    22007820 : { pari_APPLY_same(vecslice(gel(x,i), j1, j2)) }
     907             : 
     908             : INLINE GEN
     909     3627977 : matslice(GEN A, long x1, long x2, long y1, long y2)
     910     3627977 : { return rowslice(vecslice(A, y1, y2), x1, x2); }
     911             : 
     912             : /* shallow, remove coeff of index j */
     913             : INLINE GEN
     914         133 : rowsplice(GEN x, long j)
     915         133 : { pari_APPLY_same(vecsplice(gel(x,i), j)) }
     916             : 
     917             : /* shallow, remove coeff of index j */
     918             : INLINE GEN
     919      252938 : vecsplice(GEN a, long j)
     920             : {
     921      252938 :   long i, k, l = lg(a);
     922             :   GEN b;
     923      252938 :   if (l == 1) pari_err(e_MISC, "incorrect component in vecsplice");
     924      252938 :   b = cgetg(l-1, typ(a));
     925     1007489 :   for (i = k = 1; i < l; i++)
     926      754551 :     if (i != j) gel(b, k++) = gel(a,i);
     927      252938 :   return b;
     928             : }
     929             : /* shallow */
     930             : INLINE GEN
     931         833 : RgM_minor(GEN a, long i, long j)
     932             : {
     933         833 :   GEN b = vecsplice(a, j);
     934         833 :   long k, l = lg(b);
     935         833 :   for (k = 1; k < l; k++) gel(b,k) = vecsplice(gel(b,k), i);
     936         833 :   return b;
     937             : }
     938             : 
     939             : /* A[x0,] */
     940             : INLINE GEN
     941      390121 : row(GEN x, long j)
     942      390121 : { pari_APPLY_type(t_VEC, gcoeff(x, j, i)) }
     943             : INLINE GEN
     944     3713290 : Flm_row(GEN x, long j)
     945     3713290 : { pari_APPLY_ulong((ulong)coeff(x, j, i)) }
     946             : /* A[x0,] */
     947             : INLINE GEN
     948      204820 : rowcopy(GEN x, long j)
     949      204820 : { pari_APPLY_type(t_VEC, gcopy(gcoeff(x, j, i))) }
     950             : /* A[x0, x1..x2] */
     951             : INLINE GEN
     952        2177 : row_i(GEN A, long x0, long x1, long x2)
     953             : {
     954        2177 :   long i, lB = x2 - x1 + 2;
     955        2177 :   GEN B  = cgetg(lB, t_VEC);
     956        2177 :   for (i=x1; i<=x2; i++) gel(B, i) = gcoeff(A, x0, i);
     957        2177 :   return B;
     958             : }
     959             : 
     960             : INLINE GEN
     961     5830336 : vecreverse(GEN A)
     962             : {
     963             :   long i, l;
     964     5830336 :   GEN B = cgetg_copy(A, &l);
     965     5830336 :   for (i=1; i<l; i++) gel(B, i) = gel(A, l-i);
     966     5830336 :   return B;
     967             : }
     968             : 
     969             : INLINE GEN
     970         252 : vecsmall_reverse(GEN A)
     971             : {
     972             :   long i, l;
     973         252 :   GEN B = cgetg_copy(A, &l);
     974         252 :   for (i=1; i<l; i++) B[i] = A[l-i];
     975         252 :   return B;
     976             : }
     977             : 
     978             : INLINE void
     979         260 : vecreverse_inplace(GEN y)
     980             : {
     981         260 :   long l = lg(y), lim = l>>1, i;
     982         724 :   for (i = 1; i <= lim; i++)
     983             :   {
     984         464 :     GEN z = gel(y,i);
     985         464 :     gel(y,i)    = gel(y,l-i);
     986         464 :     gel(y,l-i) = z;
     987             :   }
     988         260 : }
     989             : 
     990             : INLINE GEN
     991    44959825 : vecsmallpermute(GEN A, GEN p) { return perm_mul(A, p); }
     992             : 
     993             : INLINE GEN
     994     6215155 : vecpermute(GEN A, GEN x)
     995     6215155 : { pari_APPLY_type(typ(A), gel(A, x[i])) }
     996             : 
     997             : INLINE GEN
     998     2965281 : rowpermute(GEN x, GEN p)
     999     2965281 : { pari_APPLY_same(typ(gel(x,i)) == t_VECSMALL ? vecsmallpermute(gel(x, i), p)
    1000             :                                               : vecpermute(gel(x, i), p))
    1001             : }
    1002             : /*******************************************************************/
    1003             : /*                                                                 */
    1004             : /*                          PERMUTATIONS                           */
    1005             : /*                                                                 */
    1006             : /*******************************************************************/
    1007             : /* identity permutation */
    1008             : INLINE GEN
    1009      721198 : identity_perm(long n)
    1010             : {
    1011      721198 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1012             :   long i;
    1013      721191 :   for (i = 1; i <= n; i++) perm[i] = i;
    1014      721191 :   return perm;
    1015             : }
    1016             : 
    1017             : /* assume d <= n */
    1018             : INLINE GEN
    1019       98434 : cyclic_perm(long n, long d)
    1020             : {
    1021       98434 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1022             :   long i;
    1023       98434 :   for (i = 1; i <= n-d; i++) perm[i] = i+d;
    1024       98434 :   for (     ; i <= n;   i++) perm[i] = i-n+d;
    1025       98434 :   return perm;
    1026             : }
    1027             : 
    1028             : /* Multiply (compose) two permutations */
    1029             : INLINE GEN
    1030    46200117 : perm_mul(GEN s, GEN x)
    1031    46200117 : { pari_APPLY_long(s[x[i]]) }
    1032             : 
    1033             : /* Compute the inverse (reciprocal) of a permutation. */
    1034             : INLINE GEN
    1035     1155219 : perm_inv(GEN x)
    1036             : {
    1037             :   long i, lx;
    1038     1155219 :   GEN y = cgetg_copy(x, &lx);
    1039     1155218 :   for (i=1; i<lx; i++) y[ x[i] ] = i;
    1040     1155218 :   return y;
    1041             : }
    1042             : /* Return s*t*s^-1 */
    1043             : INLINE GEN
    1044      416934 : perm_conj(GEN s, GEN t)
    1045             : {
    1046             :   long i, l;
    1047      416934 :   GEN v = cgetg_copy(s, &l);
    1048      416934 :   for (i = 1; i < l; i++) v[ s[i] ] = s[ t[i] ];
    1049      416934 :   return v;
    1050             : }
    1051             : 
    1052             : /*********************************************************************/
    1053             : /*                       MALLOC/FREE WRAPPERS                        */
    1054             : /*********************************************************************/
    1055             : #define BLOCK_SIGALRM_START          \
    1056             : {                                    \
    1057             :   int block=PARI_SIGINT_block;       \
    1058             :   PARI_SIGINT_block = 2;             \
    1059             :   MT_SIGINT_BLOCK(block);
    1060             : 
    1061             : #define BLOCK_SIGINT_START           \
    1062             : {                                    \
    1063             :   int block=PARI_SIGINT_block;       \
    1064             :   PARI_SIGINT_block = 1;             \
    1065             :   MT_SIGINT_BLOCK(block);
    1066             : 
    1067             : #define BLOCK_SIGINT_END             \
    1068             :   PARI_SIGINT_block = block;         \
    1069             :   MT_SIGINT_UNBLOCK(block);          \
    1070             :   if (!block && PARI_SIGINT_pending) \
    1071             :   {                                  \
    1072             :     int sig = PARI_SIGINT_pending;   \
    1073             :     PARI_SIGINT_pending = 0;         \
    1074             :     raise(sig);                      \
    1075             :   }                                  \
    1076             : }
    1077             : 
    1078             : INLINE void
    1079    65657799 : pari_free(void *pointer)
    1080             : {
    1081    65657799 :   BLOCK_SIGINT_START;
    1082    65676995 :   free(pointer);
    1083    65676995 :   BLOCK_SIGINT_END;
    1084    65673961 : }
    1085             : INLINE void*
    1086   277512392 : pari_malloc(size_t size)
    1087             : {
    1088   277512392 :   if (size)
    1089             :   {
    1090             :     char *tmp;
    1091   277512392 :     BLOCK_SIGINT_START;
    1092   277514839 :     tmp = (char*)malloc(size);
    1093   277514839 :     BLOCK_SIGINT_END;
    1094   277514663 :     if (!tmp) pari_err(e_MEM);
    1095   277514663 :     return tmp;
    1096             :   }
    1097           0 :   return NULL;
    1098             : }
    1099             : INLINE void*
    1100      643833 : pari_realloc(void *pointer, size_t size)
    1101             : {
    1102             :   char *tmp;
    1103             : 
    1104      643833 :   BLOCK_SIGINT_START;
    1105      645391 :   if (!pointer) tmp = (char *) malloc(size);
    1106       55708 :   else tmp = (char *) realloc(pointer,size);
    1107      645391 :   BLOCK_SIGINT_END;
    1108      644923 :   if (!tmp) pari_err(e_MEM);
    1109      644923 :   return tmp;
    1110             : }
    1111             : INLINE void*
    1112       35410 : pari_calloc(size_t size)
    1113             : {
    1114       35410 :   void *t = pari_malloc(size);
    1115       35410 :   memset(t, 0, size); return t;
    1116             : }
    1117             : INLINE GEN
    1118        5785 : cgetalloc(long t, size_t l)
    1119             : {
    1120        5785 :   GEN x = (GEN)pari_malloc(l * sizeof(long));
    1121        5785 :   x[0] = evaltyp(t) | evallg(l); return x;
    1122             : }
    1123             : 
    1124             : /*******************************************************************/
    1125             : /*                                                                 */
    1126             : /*                       GARBAGE COLLECTION                        */
    1127             : /*                                                                 */
    1128             : /*******************************************************************/
    1129             : /* copy integer x as if we had set_avma(av) */
    1130             : INLINE GEN
    1131  3728914173 : icopy_avma(GEN x, pari_sp av)
    1132             : {
    1133  3728914173 :   long i = lgefint(x), lx = i;
    1134  3728914173 :   GEN y = ((GEN)av) - i;
    1135  3728914173 :   while (--i > 0) y[i] = x[i];
    1136  3728914173 :   y[0] = evaltyp(t_INT)|evallg(lx);
    1137  3728612438 :   return y;
    1138             : }
    1139             : /* copy leaf x as if we had set_avma(av) */
    1140             : INLINE GEN
    1141   172970703 : leafcopy_avma(GEN x, pari_sp av)
    1142             : {
    1143   172970703 :   long i = lg(x);
    1144   172970703 :   GEN y = ((GEN)av) - i;
    1145   172970703 :   while (--i > 0) y[i] = x[i];
    1146   172970703 :   y[0] = x[0] & (~CLONEBIT);
    1147   172970703 :   return y;
    1148             : }
    1149             : INLINE GEN
    1150   640552565 : gerepileuptoleaf(pari_sp av, GEN x)
    1151             : {
    1152             :   long lx;
    1153             :   GEN q;
    1154             : 
    1155   640552565 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1156   642295952 :   lx = lg(x);
    1157   642295952 :   q = ((GEN)av) - lx;
    1158   642295952 :   avma = (pari_sp)q;
    1159   642295952 :   while (--lx >= 0) q[lx] = x[lx];
    1160   642295952 :   return q;
    1161             : }
    1162             : INLINE GEN
    1163  1224973645 : gerepileuptoint(pari_sp av, GEN x)
    1164             : {
    1165  1224973645 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1166  1078964887 :   avma = (pari_sp)icopy_avma(x, av);
    1167  1080867596 :   return (GEN)avma;
    1168             : }
    1169             : INLINE GEN
    1170   770077237 : gerepileupto(pari_sp av, GEN x)
    1171             : {
    1172   770077237 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1173   680451972 :   switch(typ(x))
    1174             :   { /* non-default = !is_recursive_t(tq) */
    1175   223927053 :     case t_INT: return gerepileuptoint(av, x);
    1176             :     case t_REAL:
    1177             :     case t_STR:
    1178   148320837 :     case t_VECSMALL: return gerepileuptoleaf(av,x);
    1179             :     default:
    1180             :       /* NB: x+i --> ((long)x) + i*sizeof(long) */
    1181   308204082 :       return gerepile(av, (pari_sp) (x+lg(x)), x);
    1182             :   }
    1183             : }
    1184             : INLINE double
    1185     2184614 : gc_double(pari_sp av, double d) { set_avma(av); return d; }
    1186             : INLINE long
    1187   112609105 : gc_long(pari_sp av, long s) { set_avma(av); return s; }
    1188             : INLINE ulong
    1189    15130133 : gc_ulong(pari_sp av, ulong s) { set_avma(av); return s; }
    1190             : INLINE int
    1191    19002329 : gc_bool(pari_sp av, int s) { set_avma(av); return s; }
    1192             : INLINE int
    1193      389563 : gc_int(pari_sp av, int s) { set_avma(av); return s; }
    1194             : INLINE GEN
    1195     1089289 : gc_NULL(pari_sp av) { set_avma(av); return NULL; }
    1196             : 
    1197             : /* gerepileupto(av, gcopy(x)) */
    1198             : INLINE GEN
    1199    47057732 : gerepilecopy(pari_sp av, GEN x)
    1200             : {
    1201    47057732 :   if (is_recursive_t(typ(x)))
    1202             :   {
    1203    42457490 :     GENbin *p = copy_bin(x);
    1204    42457503 :     set_avma(av); return bin_copy(p);
    1205             :   }
    1206             :   else
    1207             :   {
    1208     4600243 :     set_avma(av);
    1209     4600246 :     if (x < (GEN)av) {
    1210     3112795 :       if (x < (GEN)pari_mainstack->bot) new_chunk(lg(x));
    1211     3112795 :       x = leafcopy_avma(x, av);
    1212     3112796 :       avma = (pari_sp)x;
    1213             :     } else
    1214     1487451 :       x = leafcopy(x);
    1215     4600247 :     return x;
    1216             :   }
    1217             : }
    1218             : 
    1219             : /* Takes an array of pointers to GENs, of length n. Copies all
    1220             :  * objects to contiguous locations and cleans up the stack between
    1221             :  * av and avma. */
    1222             : INLINE void
    1223      136131 : gerepilemany(pari_sp av, GEN* gptr[], int n)
    1224             : {
    1225             :   int i;
    1226      136131 :   for (i=0; i<n; i++) *gptr[i] = (GEN)copy_bin(*gptr[i]);
    1227      136131 :   set_avma(av);
    1228      136131 :   for (i=0; i<n; i++) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1229      136131 : }
    1230             : 
    1231             : INLINE void
    1232     7487945 : gerepileall(pari_sp av, int n, ...)
    1233             : {
    1234             :   int i;
    1235     7487945 :   va_list a; va_start(a, n);
    1236     7487945 :   if (n < 10)
    1237             :   {
    1238             :     GEN *gptr[10];
    1239    21650229 :     for (i=0; i<n; i++)
    1240    14162303 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1241     7487926 :     set_avma(av);
    1242     7487819 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1243             : 
    1244             :   }
    1245             :   else
    1246             :   {
    1247           0 :     GEN **gptr = (GEN**)  pari_malloc(n*sizeof(GEN*));
    1248           0 :     for (i=0; i<n; i++)
    1249           0 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1250           0 :     set_avma(av);
    1251           0 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1252           0 :     pari_free(gptr);
    1253             :   }
    1254     7488051 :   va_end(a);
    1255     7488051 : }
    1256             : 
    1257             : INLINE void
    1258           6 : gerepilecoeffs(pari_sp av, GEN x, int n)
    1259             : {
    1260             :   int i;
    1261           6 :   for (i=0; i<n; i++) gel(x,i) = (GEN)copy_bin(gel(x,i));
    1262           6 :   set_avma(av);
    1263           6 :   for (i=0; i<n; i++) gel(x,i) = bin_copy((GENbin*)x[i]);
    1264           6 : }
    1265             : 
    1266             : /* p from copy_bin. Copy p->x back to stack, then destroy p */
    1267             : INLINE GEN
    1268    57043191 : bin_copy(GENbin *p)
    1269             : {
    1270             :   GEN x, y, base;
    1271             :   long dx, len;
    1272             : 
    1273    57043191 :   x   = p->x; if (!x) { pari_free(p); return gen_0; }
    1274    57036069 :   len = p->len;
    1275    57036069 :   base= p->base; dx = x - base;
    1276    57036069 :   y = (GEN)memcpy((void*)new_chunk(len), (void*)GENbinbase(p), len*sizeof(long));
    1277    57036031 :   y += dx;
    1278    57036031 :   p->rebase(y, ((ulong)y-(ulong)x));
    1279    57035958 :   pari_free(p); return y;
    1280             : }
    1281             : 
    1282             : INLINE GEN
    1283   114079572 : GENbinbase(GENbin *p) { return (GEN)(p + 1); }
    1284             : 
    1285             : INLINE void
    1286    31508337 : cgiv(GEN x)
    1287             : {
    1288    31508337 :   pari_sp av = (pari_sp)(x+lg(x));
    1289    31508337 :   if (isonstack((GEN)av)) set_avma(av);
    1290    31507990 : }
    1291             : 
    1292             : INLINE void
    1293     1273841 : killblock(GEN x) { gunclone(x); }
    1294             : 
    1295             : INLINE int
    1296    24166091 : is_universal_constant(GEN x) { return (x >= gen_0 && x <= ghalf); }
    1297             : 
    1298             : /*******************************************************************/
    1299             : /*                                                                 */
    1300             : /*                    CONVERSION / ASSIGNMENT                      */
    1301             : /*                                                                 */
    1302             : /*******************************************************************/
    1303             : /* z is a type which may be a t_COMPLEX component (not a t_QUAD) */
    1304             : INLINE GEN
    1305     3351805 : cxcompotor(GEN z, long prec)
    1306             : {
    1307     3351805 :   switch(typ(z))
    1308             :   {
    1309     1813602 :     case t_INT:  return itor(z, prec);
    1310      136164 :     case t_FRAC: return fractor(z, prec);
    1311     1402039 :     case t_REAL: return rtor(z, prec);
    1312           0 :     default: pari_err_TYPE("cxcompotor",z);
    1313             :              return NULL; /* LCOV_EXCL_LINE */
    1314             :   }
    1315             : }
    1316             : INLINE GEN
    1317     1662557 : cxtofp(GEN x, long prec)
    1318     1662557 : { retmkcomplex(cxcompotor(gel(x,1),prec), cxcompotor(gel(x,2),prec)); }
    1319             : 
    1320             : INLINE GEN
    1321      289289 : cxtoreal(GEN q)
    1322      289289 : { return (typ(q) == t_COMPLEX && gequal0(gel(q,2)))? gel(q,1): q; }
    1323             : 
    1324             : INLINE double
    1325    33616432 : gtodouble(GEN x)
    1326             : {
    1327    33616432 :   if (typ(x)!=t_REAL) {
    1328     7433443 :     pari_sp av = avma;
    1329     7433443 :     x = gtofp(x, DEFAULTPREC);
    1330     7433443 :     if (typ(x)!=t_REAL) pari_err_TYPE("gtodouble [t_REAL expected]", x);
    1331     7433443 :     set_avma(av);
    1332             :   }
    1333    33616432 :   return rtodbl(x);
    1334             : }
    1335             : INLINE long
    1336    73016791 : gtos(GEN x) {
    1337    73016791 :   if (typ(x) != t_INT) pari_err_TYPE("gtos [integer expected]",x);
    1338    73016784 :   return itos(x);
    1339             : }
    1340             : 
    1341             : INLINE ulong
    1342      122987 : gtou(GEN x) {
    1343      122987 :   if (typ(x) != t_INT || signe(x)<0)
    1344           0 :     pari_err_TYPE("gtou [integer >=0 expected]",x);
    1345      122999 :   return itou(x);
    1346             : }
    1347             : 
    1348             : INLINE GEN
    1349    21959129 : absfrac(GEN x)
    1350             : {
    1351    21959129 :   GEN y = cgetg(3, t_FRAC);
    1352    21959129 :   gel(y,1) = absi(gel(x,1));
    1353    21959129 :   gel(y,2) = icopy(gel(x,2)); return y;
    1354             : }
    1355             : INLINE GEN
    1356       32434 : absfrac_shallow(GEN x)
    1357       32434 : { return signe(gel(x,1))>0? x: mkfrac(negi(gel(x,1)), gel(x,2)); }
    1358             : INLINE GEN
    1359     7547343 : Q_abs(GEN x) { return (typ(x) == t_INT)? absi(x): absfrac(x); }
    1360             : INLINE GEN
    1361      113706 : Q_abs_shallow(GEN x)
    1362      113706 : { return (typ(x) == t_INT)? absi_shallow(x): absfrac_shallow(x); }
    1363             : INLINE GEN
    1364         322 : R_abs_shallow(GEN x)
    1365         322 : { return (typ(x) == t_FRAC)? absfrac_shallow(x): mpabs_shallow(x); }
    1366             : INLINE GEN
    1367           0 : R_abs(GEN x)
    1368           0 : { return (typ(x) == t_FRAC)? absfrac(x): mpabs(x); }
    1369             : 
    1370             : /* Force z to be of type real/complex with floating point components */
    1371             : INLINE GEN
    1372    35308514 : gtofp(GEN z, long prec)
    1373             : {
    1374    35308514 :   switch(typ(z))
    1375             :   {
    1376    22128572 :     case t_INT:  return itor(z, prec);
    1377     4306503 :     case t_FRAC: return fractor(z, prec);
    1378     7442638 :     case t_REAL: return rtor(z, prec);
    1379             :     case t_COMPLEX: {
    1380     1430801 :       GEN a = gel(z,1), b = gel(z,2);
    1381     1430801 :       if (isintzero(b)) return cxcompotor(a, prec);
    1382     1428390 :       if (isintzero(a)) {
    1383        2086 :         GEN y = cgetg(3, t_COMPLEX);
    1384        2086 :         b = cxcompotor(b, prec);
    1385        2086 :         gel(y,1) = real_0_bit(expo(b) - prec2nbits(prec));
    1386        2086 :         gel(y,2) = b; return y;
    1387             :       }
    1388     1426304 :       return cxtofp(z, prec);
    1389             :     }
    1390           0 :     case t_QUAD: return quadtofp(z, prec);
    1391           0 :     default: pari_err_TYPE("gtofp",z);
    1392             :              return NULL; /* LCOV_EXCL_LINE */
    1393             :   }
    1394             : }
    1395             : /* Force z to be of type real / int */
    1396             : INLINE GEN
    1397       22400 : gtomp(GEN z, long prec)
    1398             : {
    1399       22400 :   switch(typ(z))
    1400             :   {
    1401          14 :     case t_INT:  return z;
    1402       22386 :     case t_FRAC: return fractor(z, prec);
    1403           0 :     case t_REAL: return rtor(z, prec);
    1404           0 :     case t_QUAD: z = quadtofp(z, prec);
    1405           0 :                  if (typ(z) == t_REAL) return z;
    1406           0 :     default: pari_err_TYPE("gtomp",z);
    1407             :              return NULL; /* LCOV_EXCL_LINE */
    1408             :   }
    1409             : }
    1410             : 
    1411             : INLINE GEN
    1412      732494 : RgX_gtofp(GEN x, long prec)
    1413             : {
    1414             :   long l;
    1415      732494 :   GEN y = cgetg_copy(x, &l);
    1416      732494 :   while (--l > 1) gel(y,l) = gtofp(gel(x,l), prec);
    1417      732494 :   y[1] = x[1]; return y;
    1418             : }
    1419             : INLINE GEN
    1420     1177203 : RgC_gtofp(GEN x, long prec)
    1421     1177203 : { pari_APPLY_type(t_COL, gtofp(gel(x,i), prec)) }
    1422             : 
    1423             : INLINE GEN
    1424          42 : RgV_gtofp(GEN x, long prec)
    1425          42 : { pari_APPLY_type(t_VEC, gtofp(gel(x,i), prec)) }
    1426             : 
    1427             : INLINE GEN
    1428      133962 : RgM_gtofp(GEN x, long prec)
    1429      133962 : { pari_APPLY_same(RgC_gtofp(gel(x,i), prec)) }
    1430             : 
    1431             : INLINE GEN
    1432         560 : RgC_gtomp(GEN x, long prec)
    1433         560 : { pari_APPLY_type(t_COL, gtomp(gel(x,i), prec)) }
    1434             : 
    1435             : INLINE GEN
    1436          14 : RgM_gtomp(GEN x, long prec)
    1437          14 : { pari_APPLY_same(RgC_gtomp(gel(x,i), prec)) }
    1438             : 
    1439             : INLINE GEN
    1440        9150 : RgX_fpnorml2(GEN x, long prec)
    1441             : {
    1442        9150 :   pari_sp av = avma;
    1443        9150 :   return gerepileupto(av, gnorml2(RgX_gtofp(x, prec)));
    1444             : }
    1445             : INLINE GEN
    1446      177877 : RgC_fpnorml2(GEN x, long prec)
    1447             : {
    1448      177877 :   pari_sp av = avma;
    1449      177877 :   return gerepileupto(av, gnorml2(RgC_gtofp(x, prec)));
    1450             : }
    1451             : INLINE GEN
    1452        3804 : RgM_fpnorml2(GEN x, long prec)
    1453             : {
    1454        3804 :   pari_sp av = avma;
    1455        3804 :   return gerepileupto(av, gnorml2(RgM_gtofp(x, prec)));
    1456             : }
    1457             : 
    1458             : /* y a t_REAL */
    1459             : INLINE void
    1460      216244 : affgr(GEN x, GEN y)
    1461             : {
    1462             :   pari_sp av;
    1463      216244 :   switch(typ(x)) {
    1464        5992 :     case t_INT:  affir(x,y); break;
    1465      210252 :     case t_REAL: affrr(x,y); break;
    1466           0 :     case t_FRAC: rdiviiz(gel(x,1),gel(x,2), y); break;
    1467           0 :     case t_QUAD: av = avma; affgr(quadtofp(x,realprec(y)), y); set_avma(av); break;
    1468           0 :     default: pari_err_TYPE2("=",x,y);
    1469             :   }
    1470      216244 : }
    1471             : 
    1472             : INLINE GEN
    1473      259074 : affc_fixlg(GEN x, GEN res)
    1474             : {
    1475      259074 :   if (typ(x) == t_COMPLEX)
    1476             :   {
    1477      207515 :     affrr_fixlg(gel(x,1), gel(res,1));
    1478      207515 :     affrr_fixlg(gel(x,2), gel(res,2));
    1479             :   }
    1480             :   else
    1481             :   {
    1482       51559 :     avma = (pari_sp)(res+3);
    1483       51559 :     res = cgetr(realprec(gel(res,1)));
    1484       51559 :     affrr_fixlg(x, res);
    1485             :   }
    1486      259074 :   return res;
    1487             : }
    1488             : 
    1489             : INLINE GEN
    1490           0 : trunc_safe(GEN x) { long e; return gcvtoi(x,&e); }
    1491             : 
    1492             : /*******************************************************************/
    1493             : /*                                                                 */
    1494             : /*                          LENGTH CONVERSIONS                     */
    1495             : /*                                                                 */
    1496             : /*******************************************************************/
    1497             : INLINE long
    1498       28576 : ndec2nlong(long x) { return 1 + (long)((x)*(LOG2_10/BITS_IN_LONG)); }
    1499             : INLINE long
    1500       28085 : ndec2prec(long x) { return 2 + ndec2nlong(x); }
    1501             : INLINE long
    1502         491 : ndec2nbits(long x) { return ndec2nlong(x) << TWOPOTBITS_IN_LONG; }
    1503             : /* Fast implementation of ceil(x / (8*sizeof(long))); typecast to (ulong)
    1504             :  * to avoid overflow. Faster than 1 + ((x-1)>>TWOPOTBITS_IN_LONG)) :
    1505             :  *   addl, shrl instead of subl, sarl, addl */
    1506             : INLINE long
    1507     1188724 : nbits2nlong(long x) {
    1508     1188724 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1509             : }
    1510             : 
    1511             : INLINE long
    1512   312800393 : nbits2extraprec(long x) {
    1513   312800393 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1514             : }
    1515             : 
    1516             : /* Fast implementation of 2 + nbits2nlong(x) */
    1517             : INLINE long
    1518   108433380 : nbits2prec(long x) {
    1519   108433380 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1520             : }
    1521             : INLINE long
    1522     7635716 : nbits2lg(long x) {
    1523     7635716 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1524             : }
    1525             : /* ceil(x / sizeof(long)) */
    1526             : INLINE long
    1527     8620846 : nchar2nlong(long x) {
    1528     8620846 :   return (long)(((ulong)x+sizeof(long)-1) >> (TWOPOTBITS_IN_LONG-3L));
    1529             : }
    1530             : INLINE long
    1531  1148226792 : prec2nbits(long x) { return (x-2) * BITS_IN_LONG; }
    1532             : INLINE double
    1533      563943 : bit_accuracy_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1534             : INLINE double
    1535      300131 : prec2nbits_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1536             : INLINE long
    1537    32093944 : bit_prec(GEN x) { return prec2nbits(realprec(x)); }
    1538             : INLINE long
    1539  1035656051 : bit_accuracy(long x) { return prec2nbits(x); }
    1540             : INLINE long
    1541       12379 : prec2ndec(long x) { return (long)prec2nbits_mul(x, LOG10_2); }
    1542             : INLINE long
    1543         193 : nbits2ndec(long x) { return (long)(x * LOG10_2); }
    1544             : INLINE long
    1545        1771 : precdbl(long x) {return (x - 1) << 1;}
    1546             : INLINE long
    1547  3407850563 : divsBIL(long n) { return n >> TWOPOTBITS_IN_LONG; }
    1548             : INLINE long
    1549  3362541870 : remsBIL(long n) { return n & (BITS_IN_LONG-1); }
    1550             : 
    1551             : /*********************************************************************/
    1552             : /**                                                                 **/
    1553             : /**                      OPERATIONS MODULO m                        **/
    1554             : /**                                                                 **/
    1555             : /*********************************************************************/
    1556             : /* Assume m > 0, more efficient if 0 <= a, b < m */
    1557             : 
    1558             : INLINE GEN
    1559    33685459 : Fp_red(GEN a, GEN m) { return modii(a, m); }
    1560             : INLINE GEN
    1561    72430955 : Fp_add(GEN a, GEN b, GEN m)
    1562             : {
    1563    72430955 :   pari_sp av=avma;
    1564    72430955 :   GEN p = addii(a,b);
    1565    70627248 :   long s = signe(p);
    1566    70627248 :   if (!s) return p; /* = gen_0 */
    1567    63019565 :   if (s > 0) /* general case */
    1568             :   {
    1569    62793128 :     GEN t = subii(p, m);
    1570    63898720 :     s = signe(t);
    1571    63898720 :     if (!s) { set_avma(av); return gen_0; }
    1572    58115164 :     if (s < 0) { avma = (pari_sp)p; return p; }
    1573    24526294 :     if (cmpii(t, m) < 0) return gerepileuptoint(av, t); /* general case ! */
    1574     1106122 :     p = remii(t, m);
    1575             :   }
    1576             :   else
    1577      226437 :     p = modii(p, m);
    1578     1332559 :   return gerepileuptoint(av, p);
    1579             : }
    1580             : INLINE GEN
    1581    57560874 : Fp_sub(GEN a, GEN b, GEN m)
    1582             : {
    1583    57560874 :   pari_sp av=avma;
    1584    57560874 :   GEN p = subii(a,b);
    1585    56071588 :   long s = signe(p);
    1586    56071588 :   if (!s) return p; /* = gen_0 */
    1587    49809610 :   if (s > 0)
    1588             :   {
    1589    24076719 :     if (cmpii(p, m) < 0) return p; /* general case ! */
    1590     1129471 :     p = remii(p, m);
    1591             :   }
    1592             :   else
    1593             :   {
    1594    25732891 :     GEN t = addii(p, m);
    1595    25654681 :     if (!s) { set_avma(av); return gen_0; }
    1596    25654681 :     if (s > 0) return gerepileuptoint(av, t); /* general case ! */
    1597    25654681 :     p = modii(t, m);
    1598             :   }
    1599    27550991 :   return gerepileuptoint(av, p);
    1600             : }
    1601             : INLINE GEN
    1602    11621655 : Fp_neg(GEN b, GEN m)
    1603             : {
    1604    11621655 :   pari_sp av = avma;
    1605    11621655 :   long s = signe(b);
    1606             :   GEN p;
    1607    11621655 :   if (!s) return gen_0;
    1608     8189630 :   if (s > 0)
    1609             :   {
    1610     7989505 :     p = subii(m, b);
    1611     7987398 :     if (signe(p) >= 0) return p; /* general case ! */
    1612       92070 :     p = modii(p, m);
    1613             :   } else
    1614      200125 :     p = remii(negi(b), m);
    1615      292195 :   return gerepileuptoint(av, p);
    1616             : }
    1617             : 
    1618             : INLINE GEN
    1619       23592 : Fp_halve(GEN a, GEN p)
    1620             : {
    1621       23592 :   if (mpodd(a)) a = addii(a,p);
    1622       23592 :   return shifti(a,-1);
    1623             : }
    1624             : 
    1625             : /* assume 0 <= u < p and ps2 = p>>1 */
    1626             : INLINE GEN
    1627    16435266 : Fp_center(GEN u, GEN p, GEN ps2)
    1628    16435266 : { return abscmpii(u,ps2)<=0? icopy(u): subii(u,p); }
    1629             : /* same without copy */
    1630             : INLINE GEN
    1631    14930479 : Fp_center_i(GEN u, GEN p, GEN ps2)
    1632    14930479 : { return abscmpii(u,ps2)<=0? u: subii(u,p); }
    1633             : 
    1634             : /* x + y*z mod p */
    1635             : INLINE GEN
    1636     5170825 : Fp_addmul(GEN x, GEN y, GEN z, GEN p)
    1637             : {
    1638             :   pari_sp av;
    1639     5170825 :   if (!signe(y) || !signe(z)) return Fp_red(x, p);
    1640     4876445 :   if (!signe(x)) return Fp_mul(z,y, p);
    1641     4575606 :   av = avma;
    1642     4575606 :   return gerepileuptoint(av, modii(addii(x, mulii(y,z)), p));
    1643             : }
    1644             : 
    1645             : INLINE GEN
    1646    91053384 : Fp_mul(GEN a, GEN b, GEN m)
    1647             : {
    1648    91053384 :   pari_sp av=avma;
    1649             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1650    91053384 :   (void)new_chunk(lg(a)+lg(b)+(lg(m)<<1));
    1651    91049160 :   p = mulii(a,b);
    1652    91169663 :   set_avma(av); return modii(p,m);
    1653             : }
    1654             : INLINE GEN
    1655    34908138 : Fp_sqr(GEN a, GEN m)
    1656             : {
    1657    34908138 :   pari_sp av=avma;
    1658             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1659    34908138 :   (void)new_chunk((lg(a)+lg(m))<<1);
    1660    34809673 :   p = sqri(a);
    1661    30974604 :   set_avma(av); return remii(p,m); /*Use remii: p >= 0 */
    1662             : }
    1663             : INLINE GEN
    1664    65560271 : Fp_mulu(GEN a, ulong b, GEN m)
    1665             : {
    1666    65560271 :   long l = lgefint(m);
    1667    65560271 :   if (l == 3)
    1668             :   {
    1669    39096578 :     ulong mm = m[2];
    1670    39096578 :     return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1671             :   } else {
    1672    26463693 :     pari_sp av = avma;
    1673             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1674    26463693 :     (void)new_chunk(lg(a)+1+(l<<1));
    1675    26365790 :     p = muliu(a,b);
    1676    24549564 :     set_avma(av); return modii(p,m);
    1677             :   }
    1678             : }
    1679             : INLINE GEN
    1680           0 : Fp_muls(GEN a, long b, GEN m)
    1681             : {
    1682           0 :   long l = lgefint(m);
    1683           0 :   if (l == 3)
    1684             :   {
    1685           0 :     ulong mm = m[2];
    1686           0 :     if (b < 0)
    1687             :     {
    1688           0 :       ulong t = Fl_mul(umodiu(a, mm), -b, mm);
    1689           0 :       return t? utoipos(mm - t): gen_0;
    1690             :     }
    1691             :     else
    1692           0 :       return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1693             :   } else {
    1694           0 :     pari_sp av = avma;
    1695             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1696           0 :     (void)new_chunk(lg(a)+1+(l<<1));
    1697           0 :     p = mulis(a,b);
    1698           0 :     set_avma(av); return modii(p,m);
    1699             :   }
    1700             : }
    1701             : 
    1702             : INLINE GEN
    1703     8717051 : Fp_inv(GEN a, GEN m)
    1704             : {
    1705             :   GEN res;
    1706     8717051 :   if (! invmod(a,m,&res)) pari_err_INV("Fp_inv", mkintmod(res,m));
    1707     8716892 :   return res;
    1708             : }
    1709             : INLINE GEN
    1710      313889 : Fp_invsafe(GEN a, GEN m)
    1711             : {
    1712             :   GEN res;
    1713      313889 :   if (! invmod(a,m,&res)) return NULL;
    1714      313889 :   return res;
    1715             : }
    1716             : INLINE GEN
    1717     2366859 : Fp_div(GEN a, GEN b, GEN m)
    1718             : {
    1719     2366859 :   pari_sp av=avma;
    1720             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1721     2366859 :   (void)new_chunk(lg(a)+(lg(m)<<1));
    1722     2366859 :   p = mulii(a, Fp_inv(b,m));
    1723     2366855 :   set_avma(av); return modii(p,m);
    1724             : }
    1725             : 
    1726             : INLINE GEN
    1727      842951 : Flx_mulu(GEN x, ulong a, ulong p) { return Flx_Fl_mul(x,a%p,p); }
    1728             : 
    1729             : INLINE GEN
    1730           0 : get_F2x_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1731             : 
    1732             : INLINE long
    1733      448468 : get_F2x_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1734             : 
    1735             : INLINE long
    1736      121548 : get_F2x_degree(GEN T) { return typ(T)==t_VEC? F2x_degree(gel(T,2)): F2x_degree(T); }
    1737             : 
    1738             : INLINE GEN
    1739         378 : get_F2xqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1740             : 
    1741             : INLINE long
    1742      376495 : get_F2xqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1743             : 
    1744             : INLINE long
    1745      201684 : get_F2xqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1746             : 
    1747             : INLINE GEN
    1748     7447658 : get_Flx_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1749             : 
    1750             : INLINE long
    1751    16390428 : get_Flx_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1752             : 
    1753             : INLINE long
    1754    35654613 : get_Flx_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1755             : 
    1756             : INLINE GEN
    1757        2258 : get_FlxqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1758             : 
    1759             : INLINE long
    1760      368931 : get_FlxqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1761             : 
    1762             : INLINE long
    1763      155787 : get_FlxqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1764             : 
    1765             : INLINE GEN
    1766     1608414 : get_FpX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1767             : 
    1768             : INLINE long
    1769     2891021 : get_FpX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1770             : 
    1771             : INLINE long
    1772     1881815 : get_FpX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1773             : 
    1774             : INLINE GEN
    1775      142586 : get_FpXQX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1776             : 
    1777             : INLINE long
    1778       57357 : get_FpXQX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1779             : 
    1780             : INLINE long
    1781        2187 : get_FpXQX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1782             : 
    1783             : /*******************************************************************/
    1784             : /*                                                                 */
    1785             : /*                        ADDMULII / SUBMULII                      */
    1786             : /*                                                                 */
    1787             : /*******************************************************************/
    1788             : /* x - y*z */
    1789             : INLINE GEN
    1790    13409985 : submulii(GEN x, GEN y, GEN z)
    1791             : {
    1792    13409985 :   long lx = lgefint(x), ly, lz;
    1793             :   pari_sp av;
    1794             :   GEN t;
    1795    13409985 :   if (lx == 2) { t = mulii(z,y); togglesign(t); return t; }
    1796    11599849 :   ly = lgefint(y);
    1797    11599849 :   if (ly == 2) return icopy(x);
    1798    10471602 :   lz = lgefint(z);
    1799    10471602 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1800    10471602 :   t = mulii(z, y);
    1801    10471602 :   set_avma(av); return subii(x,t);
    1802             : }
    1803             : /* y*z - x */
    1804             : INLINE GEN
    1805     1188646 : mulsubii(GEN y, GEN z, GEN x)
    1806             : {
    1807     1188646 :   long lx = lgefint(x), ly, lz;
    1808             :   pari_sp av;
    1809             :   GEN t;
    1810     1188646 :   if (lx == 2) return mulii(z,y);
    1811      759394 :   ly = lgefint(y);
    1812      759394 :   if (ly == 2) return negi(x);
    1813      703302 :   lz = lgefint(z);
    1814      703302 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1815      703302 :   t = mulii(z, y);
    1816      703302 :   set_avma(av); return subii(t,x);
    1817             : }
    1818             : 
    1819             : /* x - u*y */
    1820             : INLINE GEN
    1821        7595 : submuliu(GEN x, GEN y, ulong u)
    1822             : {
    1823             :   pari_sp av;
    1824        7595 :   long ly = lgefint(y);
    1825        7595 :   if (ly == 2) return icopy(x);
    1826        7595 :   av = avma;
    1827        7595 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1828        7595 :   y = mului(u,y);
    1829        7595 :   set_avma(av); return subii(x, y);
    1830             : }
    1831             : /* x + u*y */
    1832             : INLINE GEN
    1833        7595 : addmuliu(GEN x, GEN y, ulong u)
    1834             : {
    1835             :   pari_sp av;
    1836        7595 :   long ly = lgefint(y);
    1837        7595 :   if (ly == 2) return icopy(x);
    1838        7595 :   av = avma;
    1839        7595 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1840        7595 :   y = mului(u,y);
    1841        7595 :   set_avma(av); return addii(x, y);
    1842             : }
    1843             : /* x - u*y */
    1844             : INLINE GEN
    1845   120901232 : submuliu_inplace(GEN x, GEN y, ulong u)
    1846             : {
    1847             :   pari_sp av;
    1848   120901232 :   long ly = lgefint(y);
    1849   120901232 :   if (ly == 2) return x;
    1850    96727077 :   av = avma;
    1851    96727077 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1852    96727077 :   y = mului(u,y);
    1853    96727077 :   set_avma(av); return subii(x, y);
    1854             : }
    1855             : /* x + u*y */
    1856             : INLINE GEN
    1857   119298819 : addmuliu_inplace(GEN x, GEN y, ulong u)
    1858             : {
    1859             :   pari_sp av;
    1860   119298819 :   long ly = lgefint(y);
    1861   119298819 :   if (ly == 2) return x;
    1862    96551444 :   av = avma;
    1863    96551444 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1864    96551444 :   y = mului(u,y);
    1865    96551444 :   set_avma(av); return addii(x, y);
    1866             : }
    1867             : /* ux + vy */
    1868             : INLINE GEN
    1869    20302930 : lincombii(GEN u, GEN v, GEN x, GEN y)
    1870             : {
    1871    20302930 :   long lx = lgefint(x), ly;
    1872             :   GEN p1, p2;
    1873             :   pari_sp av;
    1874    20302930 :   if (lx == 2) return mulii(v,y);
    1875    14352655 :   ly = lgefint(y);
    1876    14352655 :   if (ly == 2) return mulii(u,x);
    1877    13211514 :   av = avma; (void)new_chunk(lx+ly+lgefint(u)+lgefint(v)); /* HACK */
    1878    13211514 :   p1 = mulii(u,x);
    1879    13211514 :   p2 = mulii(v,y);
    1880    13211514 :   set_avma(av); return addii(p1,p2);
    1881             : }
    1882             : 
    1883             : /*******************************************************************/
    1884             : /*                                                                 */
    1885             : /*                          GEN SUBTYPES                           */
    1886             : /*                                                                 */
    1887             : /*******************************************************************/
    1888             : 
    1889             : INLINE int
    1890  1226082059 : is_const_t(long t) { return (t < t_POLMOD); }
    1891             : INLINE int
    1892        5437 : is_extscalar_t(long t) { return (t <= t_POL); }
    1893             : INLINE int
    1894     1137343 : is_intreal_t(long t) { return (t <= t_REAL); }
    1895             : INLINE int
    1896   395920226 : is_matvec_t(long t) { return (t >= t_VEC && t <= t_MAT); }
    1897             : INLINE int
    1898    60235213 : is_noncalc_t(long tx) { return (tx) >= t_LIST; }
    1899             : INLINE int
    1900     1184512 : is_rational_t(long t) { return (t == t_INT || t == t_FRAC); }
    1901             : INLINE int
    1902      416587 : is_real_t(long t) { return (t == t_INT || t == t_REAL || t == t_FRAC); }
    1903             : INLINE int
    1904  2912125847 : is_recursive_t(long t) { return lontyp[t]; }
    1905             : INLINE int
    1906   184768853 : is_scalar_t(long t) { return (t < t_POL); }
    1907             : INLINE int
    1908     1187922 : is_vec_t(long t) { return (t == t_VEC || t == t_COL); }
    1909             : 
    1910             : /*******************************************************************/
    1911             : /*                                                                 */
    1912             : /*                         TRANSCENDENTAL                          */
    1913             : /*                                                                 */
    1914             : /*******************************************************************/
    1915             : INLINE GEN
    1916    21888771 : sqrtr(GEN x) {
    1917    21888771 :   long s = signe(x);
    1918    21888771 :   if (s == 0) return real_0_bit(expo(x) >> 1);
    1919    21855104 :   if (s >= 0) return sqrtr_abs(x);
    1920       29356 :   retmkcomplex(gen_0, sqrtr_abs(x));
    1921             : }
    1922             : INLINE GEN
    1923           0 : cbrtr_abs(GEN x) { return sqrtnr_abs(x, 3); }
    1924             : INLINE GEN
    1925           0 : cbrtr(GEN x) {
    1926           0 :   long s = signe(x);
    1927             :   GEN r;
    1928           0 :   if (s == 0) return real_0_bit(expo(x) / 3);
    1929           0 :   r = cbrtr_abs(x);
    1930           0 :   if (s < 0) togglesign(r);
    1931           0 :   return r;
    1932             : }
    1933             : INLINE GEN
    1934      412022 : sqrtnr(GEN x, long n) {
    1935      412022 :   long s = signe(x);
    1936             :   GEN r;
    1937      412022 :   if (s == 0) return real_0_bit(expo(x) / n);
    1938      412022 :   r = sqrtnr_abs(x, n);
    1939      412022 :   if (s < 0) pari_err_IMPL("sqrtnr for x < 0");
    1940      412022 :   return r;
    1941             : }
    1942             : INLINE long
    1943      212480 : logint(GEN B, GEN y) { return logintall(B,y,NULL); }
    1944             : INLINE ulong
    1945     1811262 : ulogint(ulong B, ulong y)
    1946             : {
    1947             :   ulong r;
    1948             :   long e;
    1949     1811262 :   if (y == 2) return expu(B);
    1950     1793167 :   r = y;
    1951     6012476 :   for (e=1;; e++)
    1952             :   { /* here, r = y^e, r2 = y^(e-1) */
    1953    10231785 :     if (r >= B) return r == B? e: e-1;
    1954     4219309 :     r = umuluu_or_0(y, r);
    1955     4219309 :     if (!r) return e;
    1956             :   }
    1957             : }
    1958             : 
    1959             : /*******************************************************************/
    1960             : /*                                                                 */
    1961             : /*                         MISCELLANEOUS                           */
    1962             : /*                                                                 */
    1963             : /*******************************************************************/
    1964     1137266 : INLINE int ismpzero(GEN x) { return is_intreal_t(typ(x)) && !signe(x); }
    1965   641782657 : INLINE int isintzero(GEN x) { return typ(x) == t_INT && !signe(x); }
    1966     7013084 : INLINE int isint1(GEN x) { return typ(x)==t_INT && equali1(x); }
    1967        4613 : INLINE int isintm1(GEN x){ return typ(x)==t_INT && equalim1(x);}
    1968   694934452 : INLINE int equali1(GEN n)
    1969   694934452 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(1)) && n[2] == 1; }
    1970    62133210 : INLINE int equalim1(GEN n)
    1971    62133210 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(-1)) && n[2] == 1; }
    1972             : /* works only for POSITIVE integers */
    1973   950858481 : INLINE int is_pm1(GEN n)
    1974   950858481 : { return lgefint(n) == 3 && n[2] == 1; }
    1975   238507258 : INLINE int is_bigint(GEN n)
    1976   238507258 : { long l = lgefint(n); return l > 3 || (l == 3 && (n[2] & HIGHBIT)); }
    1977             : 
    1978  2055853465 : INLINE int odd(long x) { return x & 1; }
    1979    29054384 : INLINE int both_odd(long x, long y) { return x & y & 1; }
    1980             : 
    1981             : INLINE int
    1982  2666793322 : isonstack(GEN x)
    1983  2666793322 : { return ((pari_sp)x >= pari_mainstack->bot
    1984  2666793322 :        && (pari_sp)x <  pari_mainstack->top); }
    1985             : 
    1986             : /* assume x != 0 and x t_REAL, return an approximation to log2(|x|) */
    1987             : INLINE double
    1988    22913054 : dbllog2r(GEN x)
    1989    22913054 : { return log2((double)(ulong)x[2]) + (double)(expo(x) - (BITS_IN_LONG-1)); }
    1990             : 
    1991             : INLINE GEN
    1992      308688 : mul_content(GEN cx, GEN cy)
    1993             : {
    1994      308688 :   if (!cx) return cy;
    1995      108114 :   if (!cy) return cx;
    1996       79214 :   return gmul(cx,cy);
    1997             : }
    1998             : INLINE GEN
    1999        5901 : inv_content(GEN c) { return c? ginv(c): NULL; }
    2000             : INLINE GEN
    2001     1603364 : mul_denom(GEN dx, GEN dy)
    2002             : {
    2003     1603364 :   if (!dx) return dy;
    2004     1060357 :   if (!dy) return dx;
    2005      334397 :   return mulii(dx,dy);
    2006             : }
    2007             : 
    2008             : /* POLYNOMIALS */
    2009             : INLINE GEN
    2010    17566877 : constant_coeff(GEN x) { return signe(x)? gel(x,2): gen_0; }
    2011             : INLINE GEN
    2012    80735685 : leading_coeff(GEN x) { return lg(x) == 2? gen_0: gel(x,lg(x)-1); }
    2013             : INLINE ulong
    2014      477524 : Flx_lead(GEN x) { return lg(x) == 2? 0: x[lg(x)-1]; }
    2015             : INLINE ulong
    2016       12348 : Flx_constant(GEN x) { return lg(x) == 2? 0: x[2]; }
    2017             : INLINE long
    2018  2785770956 : degpol(GEN x) { return lg(x)-3; }
    2019             : INLINE long
    2020  1380477513 : lgpol(GEN x) { return lg(x)-2; }
    2021             : INLINE long
    2022   120102311 : lgcols(GEN x) { return lg(gel(x,1)); }
    2023             : INLINE long
    2024    33484003 : nbrows(GEN x) { return lg(gel(x,1))-1; }
    2025             : INLINE GEN
    2026           0 : truecoef(GEN x, long n) { return polcoef(x,n,-1); }
    2027             : 
    2028             : INLINE GEN
    2029      556213 : ZXQ_mul(GEN y, GEN x, GEN T) { return ZX_rem(ZX_mul(y, x), T); }
    2030             : INLINE GEN
    2031      278004 : ZXQ_sqr(GEN x, GEN T) { return ZX_rem(ZX_sqr(x), T); }
    2032             : 
    2033             : INLINE GEN
    2034    57835841 : RgX_copy(GEN x)
    2035             : {
    2036             :   long lx, i;
    2037    57835841 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
    2038    57835841 :   for (i = 2; i<lx; i++) gel(y,i) = gcopy(gel(x,i));
    2039    57835841 :   return y;
    2040             : }
    2041             : /* have to use ulong to avoid silly warnings from gcc "assuming signed
    2042             :  * overflow does not occur" */
    2043             : INLINE GEN
    2044     2957130 : RgX_coeff(GEN x, long n)
    2045             : {
    2046     2957130 :   ulong l = lg(x);
    2047     2957130 :   return (n < 0 || ((ulong)n+3) > l)? gen_0: gel(x,n+2);
    2048             : }
    2049             : INLINE GEN
    2050      353293 : RgX_renormalize(GEN x) { return RgX_renormalize_lg(x, lg(x)); }
    2051             : INLINE GEN
    2052     6740160 : RgX_div(GEN x, GEN y) { return RgX_divrem(x,y,NULL); }
    2053             : INLINE GEN
    2054        1792 : RgXQX_div(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,NULL); }
    2055             : INLINE GEN
    2056       65162 : RgXQX_rem(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,ONLY_REM); }
    2057             : INLINE GEN
    2058      884963 : FpX_div(GEN x, GEN y, GEN p) { return FpX_divrem(x,y,p, NULL); }
    2059             : INLINE GEN
    2060     4350414 : Flx_div(GEN x, GEN y, ulong p) { return Flx_divrem(x,y,p, NULL); }
    2061             : INLINE GEN
    2062     2593329 : F2x_div(GEN x, GEN y) { return F2x_divrem(x,y, NULL); }
    2063             : INLINE GEN
    2064           0 : FpV_FpC_mul(GEN x, GEN y, GEN p) { return FpV_dotproduct(x,y,p); }
    2065             : INLINE GEN
    2066    48247393 : pol0_Flx(long sv) { return mkvecsmall(sv); }
    2067             : INLINE GEN
    2068    14769000 : pol1_Flx(long sv) { return mkvecsmall2(sv, 1); }
    2069             : INLINE GEN
    2070    17653106 : polx_Flx(long sv) { return mkvecsmall3(sv, 0, 1); }
    2071             : INLINE GEN
    2072           0 : zero_zx(long sv) { return zero_Flx(sv); }
    2073             : INLINE GEN
    2074           0 : polx_zx(long sv) { return polx_Flx(sv); }
    2075             : INLINE GEN
    2076           0 : zx_shift(GEN x, long n) { return Flx_shift(x,n); }
    2077             : INLINE GEN
    2078           0 : zx_renormalize(GEN x, long l) { return Flx_renormalize(x,l); }
    2079             : INLINE GEN
    2080        1474 : zero_F2x(long sv) { return zero_Flx(sv); }
    2081             : INLINE GEN
    2082    11148215 : pol0_F2x(long sv) { return pol0_Flx(sv); }
    2083             : INLINE GEN
    2084     2868998 : pol1_F2x(long sv) { return pol1_Flx(sv); }
    2085             : INLINE GEN
    2086      683448 : polx_F2x(long sv) { return mkvecsmall2(sv, 2); }
    2087             : INLINE int
    2088      812381 : F2x_equal1(GEN x) { return Flx_equal1(x); }
    2089             : INLINE int
    2090     3106308 : F2x_equal(GEN V, GEN W) { return Flx_equal(V,W); }
    2091             : INLINE GEN
    2092    59236901 : F2x_copy(GEN x) { return leafcopy(x); }
    2093             : INLINE GEN
    2094           0 : F2v_copy(GEN x) { return leafcopy(x); }
    2095             : INLINE GEN
    2096     2273195 : Flv_copy(GEN x) { return leafcopy(x); }
    2097             : INLINE GEN
    2098    73971640 : Flx_copy(GEN x) { return leafcopy(x); }
    2099             : INLINE GEN
    2100     1863876 : vecsmall_copy(GEN x) { return leafcopy(x); }
    2101             : INLINE int
    2102     4854502 : Flx_equal1(GEN x) { return degpol(x)==0 && x[2] == 1; }
    2103             : INLINE int
    2104       18205 : ZX_equal1(GEN x) { return degpol(x)==0 && equali1(gel(x,2)); }
    2105             : INLINE int
    2106     4629094 : ZX_is_monic(GEN x) { return equali1(leading_coeff(x)); }
    2107             : 
    2108             : INLINE GEN
    2109    50603134 : ZX_renormalize(GEN x, long lx)    { return ZXX_renormalize(x,lx); }
    2110             : INLINE GEN
    2111    67225900 : FpX_renormalize(GEN x, long lx)   { return ZXX_renormalize(x,lx); }
    2112             : INLINE GEN
    2113      771228 : FpXX_renormalize(GEN x, long lx)  { return ZXX_renormalize(x,lx); }
    2114             : INLINE GEN
    2115     1237233 : FpXQX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
    2116             : INLINE GEN
    2117   111322394 : F2x_renormalize(GEN x, long lx)   { return Flx_renormalize(x,lx); }
    2118             : INLINE GEN
    2119       32315 : F2v_to_F2x(GEN x, long sv) {
    2120       32315 :   GEN y = leafcopy(x);
    2121       32315 :   y[1] = sv; F2x_renormalize(y, lg(y)); return y;
    2122             : }
    2123             : 
    2124             : INLINE long
    2125           0 : sturm(GEN x) { return sturmpart(x, NULL, NULL); }
    2126             : 
    2127             : INLINE long
    2128        7042 : gval(GEN x, long v) {
    2129        7042 :   pari_sp av = avma;
    2130        7042 :   long n = gvaluation(x, pol_x(v));
    2131        7042 :   set_avma(av); return n;
    2132             : }
    2133             : 
    2134             : INLINE void
    2135      469122 : RgX_shift_inplace_init(long v)
    2136      469122 : { if (v) (void)cgetg(v, t_VECSMALL); }
    2137             : /* shift polynomial in place. assume v free cells have been left before x */
    2138             : INLINE GEN
    2139      469122 : RgX_shift_inplace(GEN x, long v)
    2140             : {
    2141             :   long i, lx;
    2142             :   GEN y, z;
    2143      469122 :   if (!v) return x;
    2144      253227 :   lx = lg(x);
    2145      253227 :   if (lx == 2) return x;
    2146      253227 :   y = x + v;
    2147      253227 :   z = x + lx;
    2148             :   /* stackdummy from normalizepol: move it up */
    2149      253227 :   if (lg(z) != v) x[lx + v] = z[0];
    2150      253227 :   for (i = lx-1; i >= 2; i--) gel(y,i) = gel(x,i);
    2151      253227 :   for (i = v+1;  i >= 2; i--) gel(x,i) = gen_0;
    2152             :   /* leave x[1] alone: it is correct */
    2153      253227 :   x[0] = evaltyp(t_POL) | evallg(lx+v); return x;
    2154             : }
    2155             : 
    2156             : 
    2157             : /* LINEAR ALGEBRA */
    2158             : INLINE GEN
    2159      131784 : zv_to_ZV(GEN x) { return vecsmall_to_vec(x); }
    2160             : INLINE GEN
    2161     5191030 : zc_to_ZC(GEN x) { return vecsmall_to_col(x); }
    2162             : INLINE GEN
    2163      438842 : ZV_to_zv(GEN x) { return vec_to_vecsmall(x); }
    2164             : INLINE GEN
    2165           0 : zx_to_zv(GEN x, long N) { return Flx_to_Flv(x,N); }
    2166             : INLINE GEN
    2167           0 : zv_to_zx(GEN x, long sv) { return Flv_to_Flx(x,sv); }
    2168             : INLINE GEN
    2169           0 : zm_to_zxV(GEN x, long sv) { return Flm_to_FlxV(x,sv); }
    2170             : INLINE GEN
    2171           0 : zero_zm(long x, long y) { return zero_Flm(x,y); }
    2172             : INLINE GEN
    2173    17148979 : zero_zv(long x) { return zero_Flv(x); }
    2174             : INLINE GEN
    2175         210 : zm_transpose(GEN x) { return Flm_transpose(x); }
    2176             : INLINE GEN
    2177           0 : zm_copy(GEN x) { return Flm_copy(x); }
    2178             : INLINE GEN
    2179     1903271 : zv_copy(GEN x) { return Flv_copy(x); }
    2180             : INLINE GEN
    2181           0 : zm_row(GEN x, long i) { return Flm_row(x,i); }
    2182             : 
    2183             : INLINE GEN
    2184      843568 : ZC_hnfrem(GEN x, GEN y) { return ZC_hnfremdiv(x,y,NULL); }
    2185             : INLINE GEN
    2186       35594 : ZM_hnfrem(GEN x, GEN y) { return ZM_hnfdivrem(x,y,NULL); }
    2187             : INLINE GEN
    2188     2380888 : ZM_lll(GEN x, double D, long f) { return ZM_lll_norms(x,D,f,NULL); }
    2189             : INLINE void
    2190     5649816 : RgM_dimensions(GEN x, long *m, long *n) { *n = lg(x)-1; *m = *n? nbrows(x): 0; }
    2191             : INLINE GEN
    2192     9921975 : RgM_shallowcopy(GEN x)
    2193             : {
    2194             :   long l;
    2195     9921975 :   GEN y = cgetg_copy(x, &l);
    2196     9921975 :   while (--l > 0) gel(y,l) = leafcopy(gel(x,l));
    2197     9921975 :   return y;
    2198             : }
    2199             : INLINE GEN
    2200         302 : F2m_copy(GEN x) { return RgM_shallowcopy(x); }
    2201             : 
    2202             : INLINE GEN
    2203     1313793 : Flm_copy(GEN x) { return RgM_shallowcopy(x); }
    2204             : 
    2205             : /* divisibility: return 1 if y[i] | x[i] for all i, 0 otherwise. Assume
    2206             :  * x,y are ZV of the same length */
    2207             : INLINE int
    2208       23198 : ZV_dvd(GEN x, GEN y)
    2209             : {
    2210       23198 :   long i, l = lg(x);
    2211       36652 :   for (i=1; i < l; i++)
    2212       29519 :     if ( ! dvdii( gel(x,i), gel(y,i) ) ) return 0;
    2213        7133 :   return 1;
    2214             : }
    2215             : 
    2216             : /* Fq */
    2217             : INLINE GEN
    2218     2798419 : Fq_red(GEN x, GEN T, GEN p)
    2219     2798419 : { return typ(x)==t_INT? Fp_red(x,p): FpXQ_red(x,T,p); }
    2220             : INLINE GEN
    2221       43439 : Fq_to_FpXQ(GEN x, GEN T, GEN p /*unused*/)
    2222             : {
    2223             :   (void) p;
    2224       43439 :   return typ(x)==t_INT ? scalarpol(x, get_FpX_var(T)): x;
    2225             : }
    2226             : INLINE GEN
    2227         756 : Rg_to_Fq(GEN x, GEN T, GEN p) { return T? Rg_to_FpXQ(x,T,p): Rg_to_Fp(x,p); }
    2228             : 
    2229             : INLINE GEN
    2230         903 : gener_Fq_local(GEN T, GEN p, GEN L)
    2231             : { return T? gener_FpXQ_local(T,p, L)
    2232         903 :           : pgener_Fp_local(p, L); }
    2233             : 
    2234             : /* FpXQX */
    2235             : INLINE GEN
    2236        4347 : FpXQX_div(GEN x, GEN y, GEN T, GEN p) { return FpXQX_divrem(x, y, T, p, NULL); }
    2237             : INLINE GEN
    2238       34803 : FlxqX_div(GEN x, GEN y, GEN T, ulong p) { return FlxqX_divrem(x, y, T, p, NULL); }
    2239             : INLINE GEN
    2240       33278 : F2xqX_div(GEN x, GEN y, GEN T) { return F2xqX_divrem(x, y, T, NULL); }
    2241             : 
    2242             : /* FqX */
    2243             : INLINE GEN
    2244       25431 : FqX_red(GEN z, GEN T, GEN p) { return T? FpXQX_red(z, T, p): FpX_red(z, p); }
    2245             : INLINE GEN
    2246      957187 : FqX_add(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2247             : INLINE GEN
    2248       17404 : FqX_neg(GEN x,GEN T,GEN p) { return T? FpXX_neg(x,p): FpX_neg(x,p); }
    2249             : INLINE GEN
    2250        3234 : FqX_sub(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2251             : INLINE GEN
    2252      656080 : FqX_Fp_mul(GEN P, GEN u, GEN T, GEN p)
    2253      656080 : { return T? FpXX_Fp_mul(P, u, p): FpX_Fp_mul(P, u, p); }
    2254             : INLINE GEN
    2255      587707 : FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p)
    2256      587707 : { return typ(U)==t_INT ? FqX_Fp_mul(P, U, T, p): FpXQX_FpXQ_mul(P, U, T, p); }
    2257             : INLINE GEN
    2258       96027 : FqX_mul(GEN x, GEN y, GEN T, GEN p)
    2259       96027 : { return T? FpXQX_mul(x, y, T, p): FpX_mul(x, y, p); }
    2260             : INLINE GEN
    2261      489744 : FqX_mulu(GEN x, ulong y, GEN T, GEN p)
    2262      489744 : { return T? FpXX_mulu(x, y, p): FpX_mulu(x, y, p); }
    2263             : INLINE GEN
    2264        6468 : FqX_sqr(GEN x, GEN T, GEN p)
    2265        6468 : { return T? FpXQX_sqr(x, T, p): FpX_sqr(x, p); }
    2266             : INLINE GEN
    2267        1288 : FqX_powu(GEN x, ulong n, GEN T, GEN p)
    2268        1288 : { return T? FpXQX_powu(x, n, T, p): FpX_powu(x, n, p); }
    2269             : INLINE GEN
    2270           0 : FqX_halve(GEN x, GEN T, GEN p)
    2271           0 : { return T? FpXX_halve(x, p): FpX_halve(x, p); }
    2272             : INLINE GEN
    2273        5523 : FqX_div(GEN x, GEN y, GEN T, GEN p)
    2274        5523 : { return T? FpXQX_divrem(x,y,T,p,NULL): FpX_divrem(x,y,p,NULL); }
    2275             : INLINE GEN
    2276        6095 : FqX_get_red(GEN S, GEN T, GEN p)
    2277        6095 : { return T? FpXQX_get_red(S,T,p): FpX_get_red(S,p); }
    2278             : INLINE GEN
    2279       53108 : FqX_rem(GEN x, GEN y, GEN T, GEN p)
    2280       53108 : { return T? FpXQX_rem(x,y,T,p): FpX_rem(x,y,p); }
    2281             : INLINE GEN
    2282           0 : FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2283           0 : { return T? FpXQX_divrem(x,y,T,p,z): FpX_divrem(x,y,p,z); }
    2284             : INLINE GEN
    2285        5936 : FqX_div_by_X_x(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2286        5936 : { return T? FpXQX_div_by_X_x(x,y,T,p,z): FpX_div_by_X_x(x,y,p,z); }
    2287             : INLINE GEN
    2288           0 : FqX_halfgcd(GEN P,GEN Q,GEN T,GEN p)
    2289           0 : {return T? FpXQX_halfgcd(P,Q,T,p): FpX_halfgcd(P,Q,p);}
    2290             : INLINE GEN
    2291      259098 : FqX_gcd(GEN P,GEN Q,GEN T,GEN p)
    2292      259098 : {return T? FpXQX_gcd(P,Q,T,p): FpX_gcd(P,Q,p);}
    2293             : INLINE GEN
    2294       87043 : FqX_extgcd(GEN P,GEN Q,GEN T,GEN p, GEN *U, GEN *V)
    2295       87043 : { return T? FpXQX_extgcd(P,Q,T,p,U,V): FpX_extgcd(P,Q,p,U,V); }
    2296             : INLINE GEN
    2297        3178 : FqX_normalize(GEN z, GEN T, GEN p)
    2298        3178 : { return T? FpXQX_normalize(z, T, p): FpX_normalize(z, p); }
    2299             : INLINE GEN
    2300      272895 : FqX_deriv(GEN f, GEN T, GEN p) { return T? FpXX_deriv(f, p): FpX_deriv(f, p); }
    2301             : INLINE GEN
    2302           0 : FqX_integ(GEN f, GEN T, GEN p) { return T? FpXX_integ(f, p): FpX_integ(f, p); }
    2303             : INLINE GEN
    2304       74459 : FqX_factor(GEN f, GEN T, GEN p)
    2305       74459 : { return T?FpXQX_factor(f, T, p): FpX_factor(f, p); }
    2306             : INLINE GEN
    2307           7 : FqX_factor_squarefree(GEN f, GEN T, GEN p)
    2308           7 : { return T ? FpXQX_factor_squarefree(f, T, p): FpX_factor_squarefree(f, p); }
    2309             : INLINE GEN
    2310           7 : FqX_ddf(GEN f, GEN T, GEN p)
    2311           7 : { return T ? FpXQX_ddf(f, T, p): FpX_ddf(f, p); }
    2312             : INLINE GEN
    2313          42 : FqX_degfact(GEN f, GEN T, GEN p)
    2314          42 : { return T?FpXQX_degfact(f, T, p): FpX_degfact(f, p); }
    2315             : INLINE GEN
    2316        7126 : FqX_roots(GEN f, GEN T, GEN p)
    2317        7126 : { return T?FpXQX_roots(f, T, p): FpX_roots(f, p); }
    2318             : INLINE GEN
    2319         203 : FqX_to_mod(GEN f, GEN T, GEN p)
    2320         203 : { return T?FpXQX_to_mod(f, T, p): FpX_to_mod(f, p); }
    2321             : 
    2322             : /*FqXQ*/
    2323             : INLINE GEN
    2324           0 : FqXQ_add(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2325           0 : { (void)S; return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2326             : INLINE GEN
    2327           0 : FqXQ_sub(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2328           0 : { (void)S; return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2329             : INLINE GEN
    2330           0 : FqXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p)
    2331           0 : { return T? FpXQXQ_div(x,y,S,T,p): FpXQ_div(x,y,S,p); }
    2332             : INLINE GEN
    2333           0 : FqXQ_inv(GEN x, GEN S, GEN T, GEN p)
    2334           0 : { return T? FpXQXQ_inv(x,S,T,p): FpXQ_inv(x,S,p); }
    2335             : INLINE GEN
    2336           0 : FqXQ_invsafe(GEN x, GEN S, GEN T, GEN p)
    2337           0 : { return T? FpXQXQ_invsafe(x,S,T,p): FpXQ_inv(x,S,p); }
    2338             : INLINE GEN
    2339       22348 : FqXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p)
    2340       22348 : { return T? FpXQXQ_mul(x,y,S,T,p): FpXQ_mul(x,y,S,p); }
    2341             : INLINE GEN
    2342           0 : FqXQ_sqr(GEN x, GEN S, GEN T, GEN p)
    2343           0 : { return T? FpXQXQ_sqr(x,S,T,p): FpXQ_sqr(x,S,p); }
    2344             : INLINE GEN
    2345           0 : FqXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p)
    2346           0 : { return T? FpXQXQ_pow(x,n,S,T,p): FpXQ_pow(x,n,S,p); }
    2347             : 
    2348             : /*FqXn*/
    2349             : INLINE GEN
    2350           0 : FqXn_exp(GEN x, long n, GEN T, GEN p)
    2351           0 : { return T? FpXQXn_exp(x,n,T,p): FpXn_exp(x,n,p); }
    2352             : INLINE GEN
    2353           0 : FqXn_inv(GEN x, long n, GEN T, GEN p)
    2354           0 : { return T? FpXQXn_inv(x,n,T,p): FpXn_inv(x,n,p); }
    2355             : INLINE GEN
    2356           0 : FqXn_mul(GEN x, GEN y, long n, GEN T, GEN p)
    2357           0 : { return T? FpXQXn_mul(x, y, n, T, p): FpXn_mul(x, y, n, p); }
    2358             : INLINE GEN
    2359           0 : FqXn_sqr(GEN x, long n, GEN T, GEN p)
    2360           0 : { return T? FpXQXn_sqr(x,n,T,p): FpXn_sqr(x,n,p); }
    2361             : 
    2362             : /*FpXQ*/
    2363             : INLINE GEN
    2364           0 : FpXQ_add(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2365           0 : { (void)T; return FpX_add(x,y,p); }
    2366             : INLINE GEN
    2367           0 : FpXQ_sub(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2368           0 : { (void)T; return FpX_sub(x,y,p); }
    2369             : 
    2370             : /*Flxq*/
    2371             : INLINE GEN
    2372           0 : Flxq_add(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2373           0 : { (void)T; return Flx_add(x,y,p); }
    2374             : INLINE GEN
    2375           0 : Flxq_sub(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2376           0 : { (void)T; return Flx_sub(x,y,p); }
    2377             : 
    2378             : /* F2x */
    2379             : 
    2380             : INLINE ulong
    2381   100443820 : F2x_coeff(GEN x,long v)
    2382             : {
    2383   100443820 :    ulong u=(ulong)x[2+divsBIL(v)];
    2384   100441550 :    return (u>>remsBIL(v))&1UL;
    2385             : }
    2386             : 
    2387             : INLINE void
    2388     4710245 : F2x_clear(GEN x,long v)
    2389             : {
    2390     4710245 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2391     4710245 :    *u&=~(1UL<<remsBIL(v));
    2392     4710245 : }
    2393             : 
    2394             : INLINE void
    2395    32715384 : F2x_set(GEN x,long v)
    2396             : {
    2397    32715384 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2398    32694750 :    *u|=1UL<<remsBIL(v);
    2399    32690295 : }
    2400             : 
    2401             : INLINE void
    2402     1501266 : F2x_flip(GEN x,long v)
    2403             : {
    2404     1501266 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2405     1501266 :    *u^=1UL<<remsBIL(v);
    2406     1501266 : }
    2407             : 
    2408             : /* F2v */
    2409             : 
    2410             : INLINE ulong
    2411    95878532 : F2v_coeff(GEN x,long v) { return F2x_coeff(x,v-1); }
    2412             : 
    2413             : INLINE void
    2414     4710245 : F2v_clear(GEN x,long v) { F2x_clear(x,v-1); }
    2415             : 
    2416             : INLINE void
    2417     8950420 : F2v_set(GEN x,long v)   { F2x_set(x,v-1); }
    2418             : 
    2419             : INLINE void
    2420     1501266 : F2v_flip(GEN x,long v) { F2x_flip(x,v-1); }
    2421             : 
    2422             : /* F2m */
    2423             : 
    2424             : INLINE ulong
    2425    11668689 : F2m_coeff(GEN x, long a, long b) { return F2v_coeff(gel(x,b), a); }
    2426             : 
    2427             : INLINE void
    2428           0 : F2m_clear(GEN x, long a, long b) { F2v_clear(gel(x,b), a); }
    2429             : 
    2430             : INLINE void
    2431     1362615 : F2m_set(GEN x, long a, long b) { F2v_set(gel(x,b), a); }
    2432             : 
    2433             : INLINE void
    2434     1501266 : F2m_flip(GEN x, long a, long b) { F2v_flip(gel(x,b), a); }
    2435             : 
    2436             : /* ARITHMETIC */
    2437             : INLINE GEN
    2438        1071 : matpascal(long n) { return matqpascal(n, NULL); }
    2439             : INLINE long
    2440     2330804 : Z_issquare(GEN x) { return Z_issquareall(x, NULL); }
    2441             : INLINE long
    2442          14 : Z_ispower(GEN x, ulong k) { return Z_ispowerall(x, k, NULL); }
    2443             : INLINE GEN
    2444     5678647 : sqrti(GEN x) { return sqrtremi(x,NULL); }
    2445             : INLINE GEN
    2446     4654827 : gaddgs(GEN y, long s) { return gaddsg(s,y); }
    2447             : INLINE int
    2448       41894 : gcmpgs(GEN y, long s) { return -gcmpsg(s,y); }
    2449             : INLINE int
    2450       24570 : gequalgs(GEN y, long s) { return gequalsg(s,y); }
    2451             : INLINE GEN
    2452           0 : gmaxsg(long s, GEN y) { return gmaxgs(y,s); }
    2453             : INLINE GEN
    2454           0 : gminsg(long s, GEN y) { return gmings(y,s); }
    2455             : INLINE GEN
    2456    13320314 : gmulgs(GEN y, long s) { return gmulsg(s,y); }
    2457             : INLINE GEN
    2458     1368594 : gsubgs(GEN y, long s) { return gaddgs(y, -s); }
    2459             : INLINE GEN
    2460      678134 : gdivsg(long s, GEN y) { return gdiv(stoi(s), y); }
    2461             : 
    2462             : /* x t_COMPLEX */
    2463             : INLINE GEN
    2464    12564580 : cxnorm(GEN x) { return gadd(gsqr(gel(x,1)), gsqr(gel(x,2))); }
    2465             : /* q t_QUAD */
    2466             : INLINE GEN
    2467         623 : quadnorm(GEN q)
    2468             : {
    2469         623 :   GEN X = gel(q,1), b = gel(X,3), c = gel(X,2);
    2470         623 :   GEN z, u = gel(q,3), v = gel(q,2);
    2471         623 :   if (typ(u) == t_INT && typ(v) == t_INT) /* generic case */
    2472             :   {
    2473         308 :     z = signe(b)? mulii(v, addii(u,v)): sqri(v);
    2474         308 :     return addii(z, mulii(c, sqri(u)));
    2475             :   }
    2476             :   else
    2477             :   {
    2478         315 :     z = signe(b)? gmul(v, gadd(u,v)): gsqr(v);
    2479         315 :     return gadd(z, gmul(c, gsqr(u)));
    2480             :   }
    2481             : }
    2482             : /* x a t_QUAD, return the attached discriminant */
    2483             : INLINE GEN
    2484         273 : quad_disc(GEN x)
    2485             : {
    2486         273 :   GEN Q = gel(x,1), b = gel(Q,3), c = gel(Q,2), c4;
    2487         273 :   if (is_pm1(b))
    2488             :   {
    2489         217 :     pari_sp av = avma; (void)new_chunk(lgefint(c) + 1);
    2490         217 :     c4 = shifti(c,2); set_avma(av); return subsi(1, c4);
    2491             :   }
    2492          56 :   c4 = shifti(c,2); togglesign_safe(&c4); return c4;
    2493             : }
    2494             : INLINE GEN
    2495     6480663 : qfb_disc3(GEN x, GEN y, GEN z) { return subii(sqri(y), shifti(mulii(x,z),2)); }
    2496             : INLINE GEN
    2497     6399785 : qfb_disc(GEN x) { return qfb_disc3(gel(x,1), gel(x,2), gel(x,3)); }
    2498             : 
    2499             : INLINE GEN
    2500     1401789 : sqrfrac(GEN x)
    2501             : {
    2502     1401789 :   GEN z = cgetg(3,t_FRAC);
    2503     1401789 :   gel(z,1) = sqri(gel(x,1));
    2504     1401789 :   gel(z,2) = sqri(gel(x,2)); return z;
    2505             : }
    2506             : 
    2507             : INLINE void
    2508    21986742 : normalize_frac(GEN z) {
    2509    21986742 :   if (signe(gel(z,2)) < 0) { togglesign(gel(z,1)); setabssign(gel(z,2)); }
    2510    21986742 : }
    2511             : 
    2512             : INLINE GEN
    2513      251224 : powii(GEN x, GEN n)
    2514             : {
    2515      251224 :   long ln = lgefint(n);
    2516      251224 :   if (ln == 3) {
    2517             :     GEN z;
    2518      248606 :     if (signe(n) > 0) return powiu(x, n[2]);
    2519        5852 :     z = cgetg(3, t_FRAC);
    2520        5852 :     gel(z,1) = gen_1;
    2521        5852 :     gel(z,2) = powiu(x, n[2]);
    2522        5852 :     return z;
    2523             :   }
    2524        2618 :   if (ln == 2) return gen_1; /* rare */
    2525             :   /* should never happen */
    2526           0 :   return powgi(x, n); /* overflow unless x = 0, 1, -1 */
    2527             : }
    2528             : INLINE GEN
    2529        1246 : powIs(long n) {
    2530        1246 :   switch(n & 3)
    2531             :   {
    2532          28 :     case 1: return mkcomplex(gen_0,gen_1);
    2533         378 :     case 2: return gen_m1;
    2534         518 :     case 3: return mkcomplex(gen_0,gen_m1);
    2535             :   }
    2536         322 :   return gen_1;
    2537             : }
    2538             : 
    2539             : /*******************************************************************/
    2540             : /*                                                                 */
    2541             : /*                             ASSIGNMENTS                         */
    2542             : /*                                                                 */
    2543             : /*******************************************************************/
    2544           0 : INLINE void mpexpz(GEN x, GEN z)
    2545           0 : { pari_sp av = avma; gaffect(mpexp(x), z); set_avma(av); }
    2546           0 : INLINE void mplogz(GEN x, GEN z)
    2547           0 : { pari_sp av = avma; gaffect(mplog(x), z); set_avma(av); }
    2548           0 : INLINE void mpcosz(GEN x, GEN z)
    2549           0 : { pari_sp av = avma; gaffect(mpcos(x), z); set_avma(av); }
    2550           0 : INLINE void mpsinz(GEN x, GEN z)
    2551           0 : { pari_sp av = avma; gaffect(mpsin(x), z); set_avma(av); }
    2552           0 : INLINE void gnegz(GEN x, GEN z)
    2553           0 : { pari_sp av = avma; gaffect(gneg(x), z); set_avma(av); }
    2554           0 : INLINE void gabsz(GEN x, long prec, GEN z)
    2555           0 : { pari_sp av = avma; gaffect(gabs(x,prec), z); set_avma(av); }
    2556           0 : INLINE void gaddz(GEN x, GEN y, GEN z)
    2557           0 : { pari_sp av = avma; gaffect(gadd(x,y), z); set_avma(av); }
    2558           0 : INLINE void gsubz(GEN x, GEN y, GEN z)
    2559           0 : { pari_sp av = avma; gaffect(gsub(x,y), z); set_avma(av); }
    2560           0 : INLINE void gmulz(GEN x, GEN y, GEN z)
    2561           0 : { pari_sp av = avma; gaffect(gmul(x,y), z); set_avma(av); }
    2562           0 : INLINE void gdivz(GEN x, GEN y, GEN z)
    2563           0 : { pari_sp av = avma; gaffect(gdiv(x,y), z); set_avma(av); }
    2564           0 : INLINE void gdiventz(GEN x, GEN y, GEN z)
    2565           0 : { pari_sp av = avma; gaffect(gdivent(x,y), z); set_avma(av); }
    2566           0 : INLINE void gmodz(GEN x, GEN y, GEN z)
    2567           0 : { pari_sp av = avma; gaffect(gmod(x,y), z); set_avma(av); }
    2568           0 : INLINE void gmul2nz(GEN x, long s, GEN z)
    2569           0 : { pari_sp av = avma; gaffect(gmul2n(x,s), z); set_avma(av); }
    2570           0 : INLINE void gshiftz(GEN x, long s, GEN z)
    2571           0 : { pari_sp av = avma; gaffect(gshift(x,s), z); set_avma(av); }
    2572             : 
    2573             : /*******************************************************************/
    2574             : /*                                                                 */
    2575             : /*                       ELLIPTIC CURVES                           */
    2576             : /*                                                                 */
    2577             : /*******************************************************************/
    2578     3979762 : INLINE GEN ell_get_a1(GEN e) { return gel(e,1); }
    2579     3095796 : INLINE GEN ell_get_a2(GEN e) { return gel(e,2); }
    2580     3861712 : INLINE GEN ell_get_a3(GEN e) { return gel(e,3); }
    2581     3888741 : INLINE GEN ell_get_a4(GEN e) { return gel(e,4); }
    2582     4704920 : INLINE GEN ell_get_a6(GEN e) { return gel(e,5); }
    2583     3318542 : INLINE GEN ell_get_b2(GEN e) { return gel(e,6); }
    2584     1024949 : INLINE GEN ell_get_b4(GEN e) { return gel(e,7); }
    2585     1630617 : INLINE GEN ell_get_b6(GEN e) { return gel(e,8); }
    2586     1464001 : INLINE GEN ell_get_b8(GEN e) { return gel(e,9); }
    2587     6167392 : INLINE GEN ell_get_c4(GEN e) { return gel(e,10); }
    2588     7403867 : INLINE GEN ell_get_c6(GEN e) { return gel(e,11); }
    2589     9654117 : INLINE GEN ell_get_disc(GEN e) { return gel(e,12); }
    2590     1028909 : INLINE GEN ell_get_j(GEN e) { return gel(e,13); }
    2591    11456590 : INLINE long ell_get_type(GEN e) { return mael(e,14,1); }
    2592     1570443 : INLINE GEN ellff_get_field(GEN x) { return gmael(x, 15, 1); }
    2593      683132 : INLINE GEN ellff_get_a4a6(GEN x)  { return gmael(x, 15, 2); }
    2594        1407 : INLINE GEN ellQp_get_zero(GEN x) { return gmael(x, 15, 1); }
    2595         287 : INLINE long ellQp_get_prec(GEN E) { GEN z = ellQp_get_zero(E); return valp(z); }
    2596        1085 : INLINE GEN ellQp_get_p(GEN E) { GEN z = ellQp_get_zero(E); return gel(z,2); }
    2597       37156 : INLINE long ellR_get_prec(GEN x) { return nbits2prec(mael3(x, 15, 1, 1)); }
    2598       12106 : INLINE long ellR_get_sign(GEN x) { return mael3(x, 15, 1, 2); }
    2599      699475 : INLINE GEN ellnf_get_nf(GEN x) { return checknf_i(gmael(x,15,1)); }
    2600          56 : INLINE GEN ellnf_get_bnf(GEN x) { return checkbnf_i(gmael(x,15,1)); }
    2601             : 
    2602     4625083 : INLINE int checkell_i(GEN e) { return typ(e) == t_VEC && lg(e) == 17; }
    2603    33935288 : INLINE int ell_is_inf(GEN z) { return lg(z) == 2; }
    2604      809800 : INLINE GEN ellinf(void) { return mkvec(gen_0); }
    2605             : 
    2606             : /*******************************************************************/
    2607             : /*                                                                 */
    2608             : /*                    ALGEBRAIC NUMBER THEORY                      */
    2609             : /*                                                                 */
    2610             : /*******************************************************************/
    2611     8126888 : INLINE GEN modpr_get_pr(GEN x)  { return gel(x,3); }
    2612      609537 : INLINE GEN modpr_get_p(GEN x)  { return pr_get_p(modpr_get_pr(x)); }
    2613     2520393 : INLINE GEN modpr_get_T(GEN x)  { return lg(x) == 4? NULL: gel(x,4); }
    2614             : 
    2615    19371035 : INLINE GEN pr_get_p(GEN pr)  { return gel(pr,1); }
    2616     6273244 : INLINE GEN pr_get_gen(GEN pr){ return gel(pr,2); }
    2617             : /* .[2] instead of itos works: e and f are small positive integers */
    2618     2266368 : INLINE long pr_get_e(GEN pr) { return gel(pr,3)[2]; }
    2619     8716225 : INLINE long pr_get_f(GEN pr) { return gel(pr,4)[2]; }
    2620     6141813 : INLINE GEN pr_get_tau(GEN pr){ return gel(pr,5); }
    2621             : INLINE int
    2622     3051851 : pr_is_inert(GEN P) { return pr_get_f(P) == lg(pr_get_gen(P))-1; }
    2623             : INLINE GEN
    2624      217505 : pr_norm(GEN pr) { return powiu(pr_get_p(pr), pr_get_f(pr)); }
    2625             : INLINE ulong
    2626       39487 : upr_norm(GEN pr) { return upowuu(pr_get_p(pr)[2], pr_get_f(pr)); }
    2627             : 
    2628             : /* assume nf a genuine nf */
    2629             : INLINE long
    2630        4528 : nf_get_varn(GEN nf) { return varn(gel(nf,1)); }
    2631             : INLINE GEN
    2632    30918941 : nf_get_pol(GEN nf) { return gel(nf,1); }
    2633             : INLINE long
    2634    24711013 : nf_get_degree(GEN nf) { return degpol( nf_get_pol(nf) ); }
    2635             : INLINE long
    2636     4092354 : nf_get_r1(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,1)); }
    2637             : INLINE long
    2638        1673 : nf_get_r2(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,2)); }
    2639             : INLINE GEN
    2640       49826 : nf_get_disc(GEN nf) { return gel(nf,3); }
    2641             : INLINE GEN
    2642      765959 : nf_get_index(GEN nf) { return gel(nf,4); }
    2643             : INLINE GEN
    2644     2821420 : nf_get_M(GEN nf) { return gmael(nf,5,1); }
    2645             : INLINE GEN
    2646       73824 : nf_get_G(GEN nf) { return gmael(nf,5,2); }
    2647             : INLINE GEN
    2648      385499 : nf_get_roundG(GEN nf) { return gmael(nf,5,3); }
    2649             : INLINE GEN
    2650       24367 : nf_get_Tr(GEN nf) { return gmael(nf,5,4); }
    2651             : INLINE GEN
    2652        2324 : nf_get_diff(GEN nf) { return gmael(nf,5,5); }
    2653             : INLINE GEN
    2654          84 : nf_get_ramified_primes(GEN nf) { return gmael(nf,5,8); }
    2655             : INLINE GEN
    2656      291043 : nf_get_roots(GEN nf) { return gel(nf,6); }
    2657             : INLINE GEN
    2658          91 : nf_get_zk(GEN nf)
    2659             : {
    2660          91 :   GEN y = gel(nf,7), D = gel(y, 1);
    2661          91 :   if (typ(D) == t_POL) D = gel(D, 2);
    2662          91 :   if (!equali1(D)) y = gdiv(y, D);
    2663          91 :   return y;
    2664             : }
    2665             : INLINE GEN
    2666      247685 : nf_get_zkprimpart(GEN nf)
    2667             : {
    2668      247685 :   GEN y = gel(nf,7);
    2669             :   /* test for old format of nf.zk: non normalized */
    2670      247685 :   if (!equali1(gel(nf,4)) && gequal1(gel(y,1))) y = Q_remove_denom(y,NULL);
    2671      247685 :   return y;
    2672             : }
    2673             : INLINE GEN
    2674      248813 : nf_get_zkden(GEN nf)
    2675             : {
    2676      248813 :   GEN y = gel(nf,7), D = gel(y,1);
    2677      248813 :   if (typ(D) == t_POL) D = gel(D,2);
    2678             :   /* test for old format of nf.zk: non normalized */
    2679      248813 :   if (!equali1(gel(nf,4)) && equali1(D)) D = Q_denom(y);
    2680      248813 :   return D;
    2681             : }
    2682             : INLINE GEN
    2683     2337048 : nf_get_invzk(GEN nf) { return gel(nf,8); }
    2684             : INLINE void
    2685       19819 : nf_get_sign(GEN nf, long *r1, long *r2)
    2686             : {
    2687       19819 :   GEN x = gel(nf,2);
    2688       19819 :   *r1 = itou(gel(x,1));
    2689       19819 :   *r2 = itou(gel(x,2));
    2690       19819 : }
    2691             : 
    2692             : INLINE GEN
    2693       53411 : abgrp_get_no(GEN x) { return gel(x,1); }
    2694             : INLINE GEN
    2695     2094351 : abgrp_get_cyc(GEN x) { return gel(x,2); }
    2696             : INLINE GEN
    2697      396512 : abgrp_get_gen(GEN x) { return gel(x,3); }
    2698             : INLINE GEN
    2699     2062709 : bnf_get_nf(GEN bnf) { return gel(bnf,7); }
    2700             : INLINE GEN
    2701      806275 : bnf_get_clgp(GEN bnf) { return gmael(bnf,8,1); }
    2702             : INLINE GEN
    2703        4564 : bnf_get_no(GEN bnf) { return abgrp_get_no(bnf_get_clgp(bnf)); }
    2704             : INLINE GEN
    2705      434249 : bnf_get_cyc(GEN bnf) { return abgrp_get_cyc(bnf_get_clgp(bnf)); }
    2706             : INLINE GEN
    2707      367133 : bnf_get_gen(GEN bnf)  { return abgrp_get_gen(bnf_get_clgp(bnf)); }
    2708             : INLINE GEN
    2709         846 : bnf_get_reg(GEN bnf) { return gmael(bnf,8,2); }
    2710             : INLINE GEN
    2711      481743 : bnf_get_logfu(GEN bnf) { return gel(bnf,3); }
    2712             : INLINE GEN
    2713        5868 : bnf_get_tuU(GEN bnf) { return gmael3(bnf,8,4,2); }
    2714             : INLINE long
    2715       24682 : bnf_get_tuN(GEN bnf) { return gmael3(bnf,8,4,1)[2]; }
    2716             : INLINE GEN
    2717        1778 : bnf_get_fu(GEN bnf) {
    2718        1778 :   GEN fu = bnf_get_fu_nocheck(bnf);
    2719        1778 :   if (typ(fu) == t_MAT) pari_err(e_MISC,"missing units in bnf");
    2720        1778 :   return fu;
    2721             : }
    2722             : INLINE GEN
    2723        7170 : bnf_get_fu_nocheck(GEN bnf) { return gmael(bnf,8,5); }
    2724             : 
    2725             : INLINE GEN
    2726      746961 : bnr_get_bnf(GEN bnr) { return gel(bnr,1); }
    2727             : INLINE GEN
    2728      384712 : bnr_get_bid(GEN bnr) { return gel(bnr,2); }
    2729             : INLINE GEN
    2730       18130 : bnr_get_mod(GEN bnr) { return gmael(bnr,2,1); }
    2731             : INLINE GEN
    2732       27811 : bnr_get_nf(GEN bnr) { return gmael(bnr,1,7); }
    2733             : INLINE GEN
    2734      516571 : bnr_get_clgp(GEN bnr) { return gel(bnr,5); }
    2735             : INLINE GEN
    2736       45080 : bnr_get_no(GEN bnr) { return abgrp_get_no(bnr_get_clgp(bnr)); }
    2737             : INLINE GEN
    2738      459598 : bnr_get_cyc(GEN bnr) { return abgrp_get_cyc(bnr_get_clgp(bnr)); }
    2739             : INLINE GEN
    2740          70 : bnr_get_gen_nocheck(GEN bnr) { return abgrp_get_gen(bnr_get_clgp(bnr)); }
    2741             : INLINE GEN
    2742       11032 : bnr_get_gen(GEN bnr) {
    2743       11032 :   GEN G = bnr_get_clgp(bnr);
    2744       11032 :   if (lg(G) !=  4)
    2745           0 :     pari_err(e_MISC,"missing bnr generators: please use bnrinit(,,1)");
    2746       11032 :   return gel(G,3);
    2747             : }
    2748             : 
    2749             : INLINE GEN
    2750      301888 : bid_get_mod(GEN bid) { return gel(bid,1); }
    2751             : INLINE GEN
    2752       46361 : bid_get_ideal(GEN bid) { return gmael(bid,1,1); }
    2753             : INLINE GEN
    2754         518 : bid_get_arch(GEN bid) { return gmael(bid,1,2); }
    2755             : INLINE GEN
    2756     1059923 : bid_get_grp(GEN bid) { return gel(bid,2); }
    2757             : INLINE GEN
    2758      395527 : bid_get_fact(GEN bid) { return gmael(bid,3,1); }
    2759             : INLINE GEN
    2760      354031 : bid_get_fact2(GEN bid) { return gmael(bid,3,2); }
    2761             : INLINE GEN
    2762      354031 : bid_get_sprk(GEN bid) { return gmael(bid,4,1); }
    2763             : INLINE GEN
    2764       29939 : bid_get_sarch(GEN bid) { return gmael(bid,4,2); }
    2765             : INLINE GEN
    2766      374695 : bid_get_archp(GEN bid) { return gmael3(bid,4,2,2); }
    2767             : INLINE GEN
    2768      656129 : bid_get_U(GEN bid) { return gel(bid,5); }
    2769             : INLINE GEN
    2770           0 : bid_get_no(GEN bid) { return abgrp_get_no(bid_get_grp(bid)); }
    2771             : INLINE GEN
    2772     1031538 : bid_get_cyc(GEN bid) { return abgrp_get_cyc(bid_get_grp(bid)); }
    2773             : INLINE GEN
    2774           0 : bid_get_gen_nocheck(GEN bid)  { return abgrp_get_gen(bid_get_grp(bid)); }
    2775             : INLINE GEN
    2776       27790 : bid_get_gen(GEN bid) {
    2777       27790 :   GEN G = bid_get_grp(bid);
    2778       27790 :   if (lg(G) != 4) pari_err(e_MISC,"missing bid generators. Use idealstar(,,2)");
    2779       27790 :   return abgrp_get_gen(G);
    2780             : }
    2781             : 
    2782             : INLINE GEN
    2783    21723009 : znstar_get_N(GEN G) { return gmael(G,1,1); }
    2784             : INLINE GEN
    2785     2239825 : znstar_get_faN(GEN G) { return gel(G,3); }
    2786             : INLINE GEN
    2787           7 : znstar_get_no(GEN G) { return abgrp_get_no(gel(G,2)); }
    2788             : INLINE GEN
    2789      167545 : znstar_get_cyc(GEN G) { return abgrp_get_cyc(gel(G,2)); }
    2790             : INLINE GEN
    2791           7 : znstar_get_gen(GEN G) { return abgrp_get_gen(gel(G,2)); }
    2792             : INLINE GEN
    2793     2888921 : znstar_get_conreycyc(GEN G) { return gmael(G,4,5); }
    2794             : INLINE GEN
    2795      887698 : znstar_get_conreygen(GEN G) { return gmael(G,4,4); }
    2796             : INLINE GEN
    2797       28518 : znstar_get_Ui(GEN G) { return gmael(G,4,3); }
    2798             : INLINE GEN
    2799      118160 : znstar_get_U(GEN G) { return gel(G,5); }
    2800             : INLINE GEN
    2801      521612 : znstar_get_pe(GEN G) { return gmael(G,4,1); }
    2802             : INLINE GEN
    2803       19880 : gal_get_pol(GEN gal) { return gel(gal,1); }
    2804             : INLINE GEN
    2805        1309 : gal_get_p(GEN gal) { return gmael(gal,2,1); }
    2806             : INLINE GEN
    2807          84 : gal_get_e(GEN gal) { return gmael(gal,2,2); }
    2808             : INLINE GEN
    2809       15946 : gal_get_mod(GEN gal) { return gmael(gal,2,3); }
    2810             : INLINE GEN
    2811       16324 : gal_get_roots(GEN gal) { return gel(gal,3); }
    2812             : INLINE GEN
    2813       15904 : gal_get_invvdm(GEN gal) { return gel(gal,4); }
    2814             : INLINE GEN
    2815       15904 : gal_get_den(GEN gal) { return gel(gal,5); }
    2816             : INLINE GEN
    2817       66983 : gal_get_group(GEN gal) { return gel(gal,6); }
    2818             : INLINE GEN
    2819        1715 : gal_get_gen(GEN gal) { return gel(gal,7); }
    2820             : INLINE GEN
    2821        1365 : gal_get_orders(GEN gal) { return gel(gal,8); }
    2822             : 
    2823             : /* assume rnf a genuine rnf */
    2824             : INLINE long
    2825     1233638 : rnf_get_degree(GEN rnf) { return degpol(rnf_get_pol(rnf)); }
    2826             : INLINE long
    2827       16394 : rnf_get_nfdegree(GEN rnf) { return degpol(nf_get_pol(rnf_get_nf(rnf))); }
    2828             : INLINE long
    2829      775698 : rnf_get_absdegree(GEN rnf) { return degpol(gmael(rnf,11,1)); }
    2830             : INLINE GEN
    2831         700 : rnf_get_idealdisc(GEN rnf) { return gmael(rnf,3,1); }
    2832             : INLINE GEN
    2833         742 : rnf_get_k(GEN rnf) { return gmael(rnf,11,3); }
    2834             : INLINE GEN
    2835         609 : rnf_get_alpha(GEN rnf) { return gmael(rnf, 11, 2); }
    2836             : INLINE GEN
    2837      384706 : rnf_get_nf(GEN rnf) { return gel(rnf,10); }
    2838             : INLINE GEN
    2839        3087 : rnf_get_nfzk(GEN rnf) { return gel(rnf,2); }
    2840             : INLINE GEN
    2841      205170 : rnf_get_polabs(GEN rnf) { return gmael(rnf,11,1); }
    2842             : INLINE GEN
    2843     1479849 : rnf_get_pol(GEN rnf) { return gel(rnf,1); }
    2844             : INLINE GEN
    2845          63 : rnf_get_disc(GEN rnf) { return gel(rnf,3); }
    2846             : INLINE GEN
    2847         105 : rnf_get_index(GEN rnf) { return gel(rnf,4); }
    2848             : INLINE long
    2849           0 : rnf_get_varn(GEN rnf) { return varn(gel(rnf,1)); }
    2850             : INLINE GEN
    2851      188580 : rnf_get_nfpol(GEN rnf) { return gmael(rnf,10,1); }
    2852             : INLINE long
    2853        3325 : rnf_get_nfvarn(GEN rnf) { return varn(gmael(rnf,10,1)); }
    2854             : INLINE GEN
    2855        3213 : rnf_get_zk(GEN rnf) { return gel(rnf,7); }
    2856             : INLINE GEN
    2857       96775 : rnf_get_map(GEN rnf) { return gel(rnf,11); }
    2858             : INLINE GEN
    2859        1197 : rnf_get_invzk(GEN rnf) { return gel(rnf,8); }
    2860             : 
    2861             : /* I integral ZM (not HNF), G ZM, rounded Cholesky form of a weighted
    2862             :  * T2 matrix. Reduce I wrt G */
    2863             : INLINE GEN
    2864       14077 : idealpseudored(GEN I, GEN G)
    2865       14077 : { return ZM_mul(I, ZM_lll(ZM_mul(G, I), 0.99, LLL_IM)); }
    2866             : 
    2867             : /* I integral (not necessarily HNF), G ZM, rounded Cholesky form of a weighted
    2868             :  * T2 matrix. Return m in I with T2(m) small */
    2869             : INLINE GEN
    2870      127731 : idealpseudomin(GEN I, GEN G)
    2871             : {
    2872      127731 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2873      127731 :   return ZM_ZC_mul(I, gel(u,1));
    2874             : }
    2875             : /* I, G as in idealpseudomin. Return an irrational m in I with T2(m) small */
    2876             : INLINE GEN
    2877      297163 : idealpseudomin_nonscalar(GEN I, GEN G)
    2878             : {
    2879      297163 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2880      297163 :   GEN m = ZM_ZC_mul(I, gel(u,1));
    2881      297163 :   if (ZV_isscalar(m) && lg(u) > 2) m = ZM_ZC_mul(I, gel(u,2));
    2882      297163 :   return m;
    2883             : }
    2884             : 
    2885             : INLINE GEN
    2886         770 : idealred_elt(GEN nf, GEN I) {
    2887         770 :   pari_sp av = avma;
    2888         770 :   GEN u = idealpseudomin(I, nf_get_roundG(nf));
    2889         770 :   return gerepileupto(av, u);
    2890             : }
    2891             : INLINE GEN
    2892      109444 : idealred(GEN nf, GEN I) { return idealred0(nf, I, NULL); }
    2893             : 
    2894             : INLINE GEN
    2895        2058 : idealchineseinit(GEN nf, GEN x)
    2896        2058 : { return idealchinese(nf,x,NULL); }
    2897             : 
    2898             : /*******************************************************************/
    2899             : /*                                                                 */
    2900             : /*                              CLOSURES                           */
    2901             : /*                                                                 */
    2902             : /*******************************************************************/
    2903   227680147 : INLINE long closure_arity(GEN C)          { return ((ulong)C[1])&ARITYBITS; }
    2904    35447916 : INLINE long closure_is_variadic(GEN C) { return !!(((ulong)C[1])&VARARGBITS); }
    2905   191921202 : INLINE const char *closure_codestr(GEN C)  { return GSTR(gel(C,2))-1; }
    2906           0 : INLINE GEN closure_get_code(GEN C)  { return gel(C,2); }
    2907   191897602 : INLINE GEN closure_get_oper(GEN C)  { return gel(C,3); }
    2908   191885870 : INLINE GEN closure_get_data(GEN C)  { return gel(C,4); }
    2909        9393 : INLINE GEN closure_get_dbg(GEN C)   { return gel(C,5); }
    2910       22524 : INLINE GEN closure_get_text(GEN C)  { return gel(C,6); }
    2911     1171748 : INLINE GEN closure_get_frame(GEN C) { return gel(C,7); }
    2912             : 
    2913             : /*******************************************************************/
    2914             : /*                                                                 */
    2915             : /*                               ERRORS                            */
    2916             : /*                                                                 */
    2917             : /*******************************************************************/
    2918             : INLINE long
    2919       52184 : err_get_num(GEN e) { return e[1]; }
    2920             : INLINE GEN
    2921          77 : err_get_compo(GEN e, long i) { return gel(e, i+1); }
    2922             : 
    2923             : INLINE void
    2924          14 : pari_err_BUG(const char *f) { pari_err(e_BUG,f); }
    2925             : INLINE void
    2926           7 : pari_err_CONSTPOL(const char *f) { pari_err(e_CONSTPOL, f); }
    2927             : INLINE void
    2928          63 : pari_err_COPRIME(const char *f, GEN x, GEN y) { pari_err(e_COPRIME, f,x,y); }
    2929             : INLINE void
    2930         487 : pari_err_DIM(const char *f) { pari_err(e_DIM, f); }
    2931             : INLINE void
    2932           0 : pari_err_FILE(const char *f, const char *g) { pari_err(e_FILE, f,g); }
    2933             : INLINE void
    2934           0 : pari_err_FILEDESC(const char *f, long n) { pari_err(e_FILEDESC, f,n); }
    2935             : INLINE void
    2936          42 : pari_err_FLAG(const char *f) { pari_err(e_FLAG,f); }
    2937             : INLINE void
    2938         434 : pari_err_IMPL(const char *f) { pari_err(e_IMPL,f); }
    2939             : INLINE void
    2940       19716 : pari_err_INV(const char *f, GEN x) { pari_err(e_INV,f,x); }
    2941             : INLINE void
    2942          28 : pari_err_IRREDPOL(const char *f, GEN x) { pari_err(e_IRREDPOL, f,x); }
    2943             : INLINE void
    2944        2003 : 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); }
    2945             : INLINE void
    2946         203 : pari_err_COMPONENT(const char *f, const char *op, GEN l, GEN x) { pari_err(e_COMPONENT, f,op,l,x); }
    2947             : INLINE void
    2948           0 : pari_err_MAXPRIME(ulong c) { pari_err(e_MAXPRIME, c); }
    2949             : INLINE void
    2950         350 : pari_err_OP(const char *f, GEN x, GEN y) { pari_err(e_OP, f,x,y); }
    2951             : INLINE void
    2952          84 : pari_err_OVERFLOW(const char *f) { pari_err(e_OVERFLOW, f); }
    2953             : INLINE void
    2954         218 : pari_err_PREC(const char *f) { pari_err(e_PREC,f); }
    2955             : INLINE void
    2956           0 : pari_err_PACKAGE(const char *f) { pari_err(e_PACKAGE,f); }
    2957             : INLINE void
    2958          70 : pari_err_PRIME(const char *f, GEN x) { pari_err(e_PRIME, f,x); }
    2959             : INLINE void
    2960         749 : pari_err_MODULUS(const char *f, GEN x, GEN y) { pari_err(e_MODULUS, f,x,y); }
    2961             : INLINE void
    2962          49 : pari_err_ROOTS0(const char *f) { pari_err(e_ROOTS0, f); }
    2963             : INLINE void
    2964          77 : pari_err_SQRTN(const char *f, GEN x) { pari_err(e_SQRTN, f,x); }
    2965             : INLINE void
    2966       12503 : pari_err_TYPE(const char *f, GEN x) { pari_err(e_TYPE, f,x); }
    2967             : INLINE void
    2968        3073 : pari_err_TYPE2(const char *f, GEN x, GEN y) { pari_err(e_TYPE2, f,x,y); }
    2969             : INLINE void
    2970         203 : pari_err_VAR(const char *f, GEN x, GEN y) { pari_err(e_VAR, f,x,y); }
    2971             : INLINE void
    2972         175 : pari_err_PRIORITY(const char *f, GEN x, const char *op, long v)
    2973         175 : { pari_err(e_PRIORITY, f,x,op,v); }

Generated by: LCOV version 1.13