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 23219-221e4f55f) Lines: 1275 1444 88.3 %
Date: 2018-11-14 05:40:44 Functions: 563 641 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     3281614 : mkintmod(GEN x, GEN y) { retmkintmod(x,y); }
     141             : INLINE GEN
     142        4074 : mkintmodu(ulong x, ulong y) {
     143        4074 :   GEN v = cgetg(3,t_INTMOD);
     144        4074 :   gel(v,1) = utoipos(y);
     145        4074 :   gel(v,2) = utoi(x); return v;
     146             : }
     147             : INLINE GEN
     148     2927680 : mkpolmod(GEN x, GEN y) { retmkpolmod(x,y); }
     149             : INLINE GEN
     150    23176109 : mkfrac(GEN x, GEN y) { retmkfrac(x,y); }
     151             : INLINE GEN
     152       32137 : mkfracss(long x, long y) { retmkfrac(stoi(x),utoipos(y)); }
     153             : /* q = n/d a t_FRAC or t_INT; recover (n,d) */
     154             : INLINE void
     155       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    71228362 : sstoQ(long n, long d)
     162             : {
     163             :   ulong r;
     164             :   long g, q;
     165    71228362 :   if (!n)
     166             :   {
     167       88781 :     if (!d) pari_err_INV("sstoQ",gen_0);
     168       88781 :     return gen_0;
     169             :   }
     170    71139581 :   if (d < 0) { d = -d; n = -n; }
     171    71139581 :   if (d == 1) return stoi(n);
     172    71127989 :   q = udivuu_rem(labs(n),d,&r);
     173    71127989 :   if (!r) return n > 0? utoipos(q): utoineg(q);
     174     3612352 :   g = ugcd(d,r); /* gcd(n,d) */
     175     3612352 :   if (g != 1) { n /= g; d /= g; }
     176     3612352 :   retmkfrac(stoi(n), utoi(d));
     177             : }
     178             : 
     179             : INLINE GEN
     180     6675220 : 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     9073395 : mkcomplex(GEN x, GEN y) { retmkcomplex(x,y); }
     189             : INLINE GEN
     190      449472 : gen_I(void) { return mkcomplex(gen_0, gen_1); }
     191             : INLINE GEN
     192      298639 : 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    63420102 : mkvecsmall(long x) { GEN v = cgetg(2, t_VECSMALL); v[1] = x; return v; }
     199             : INLINE GEN
     200   114070412 : mkvecsmall2(long x,long y) { GEN v = cgetg(3, t_VECSMALL);
     201   114052629 :   v[1]=x; v[2]=y; return v; }
     202             : INLINE GEN
     203    58020610 : mkvecsmall3(long x,long y,long z) { GEN v = cgetg(4, t_VECSMALL);
     204    58014005 :   v[1]=x; v[2]=y; v[3]=z; return v; }
     205             : INLINE GEN
     206    11951850 : mkvecsmall4(long x,long y,long z,long t) { GEN v = cgetg(5, t_VECSMALL);
     207    11932693 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; return v; }
     208             : INLINE GEN
     209      466537 : mkvecsmall5(long x,long y,long z,long t,long u) { GEN v = cgetg(6, t_VECSMALL);
     210      466538 :   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    15039432 : mkvec(GEN x) { retmkvec(x); }
     217             : INLINE GEN
     218   102019808 : mkvec2(GEN x, GEN y) { retmkvec2(x,y); }
     219             : INLINE GEN
     220    74664034 : mkvec3(GEN x, GEN y, GEN z) { retmkvec3(x,y,z); }
     221             : INLINE GEN
     222     7271787 : mkvec4(GEN x, GEN y, GEN z, GEN t) { retmkvec4(x,y,z,t); }
     223             : INLINE GEN
     224    12082191 : 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       23028 : mkvec2s(long x, long y) { retmkvec2(stoi(x),stoi(y)); }
     229             : INLINE GEN
     230      492724 : mkvec3s(long x, long y, long z) { retmkvec3(stoi(x),stoi(y),stoi(z)); }
     231             : INLINE GEN
     232          21 : mkvec4s(long x, long y, long z, long t) { retmkvec4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     233             : INLINE GEN
     234       35091 : mkveccopy(GEN x) { GEN v = cgetg(2, t_VEC); gel(v,1) = gcopy(x); return v; }
     235             : INLINE GEN
     236       96861 : mkvec2copy(GEN x, GEN y) {
     237       96861 :   GEN v = cgetg(3,t_VEC); gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     238             : /* col */
     239             : INLINE GEN
     240     2534642 : mkcol(GEN x) { retmkcol(x); }
     241             : INLINE GEN
     242    25643557 : mkcol2(GEN x, GEN y) { retmkcol2(x,y); }
     243             : INLINE GEN
     244       42385 : mkcol3(GEN x, GEN y, GEN z) { retmkcol3(x,y,z); }
     245             : INLINE GEN
     246           0 : mkcol4(GEN x, GEN y, GEN z, GEN t) { retmkcol4(x,y,z,t); }
     247             : INLINE GEN
     248           0 : mkcol5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkcol5(x,y,z,t,u); }
     249             : INLINE GEN
     250        8716 : mkcol6(GEN x, GEN y, GEN z, GEN t, GEN u, GEN v) { retmkcol6(x,y,z,t,u,v); }
     251             : INLINE GEN
     252         273 : mkcols(long x) { retmkcol(stoi(x)); }
     253             : INLINE GEN
     254     2176216 : mkcol2s(long x, long y) { retmkcol2(stoi(x),stoi(y)); }
     255             : INLINE GEN
     256           0 : mkcol3s(long x, long y, long z) { retmkcol3(stoi(x),stoi(y),stoi(z)); }
     257             : INLINE GEN
     258           0 : mkcol4s(long x, long y, long z, long t) { retmkcol4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     259             : INLINE GEN
     260       50553 : mkcolcopy(GEN x) { GEN v = cgetg(2, t_COL); gel(v,1) = gcopy(x); return v; }
     261             : /* mat */
     262             : INLINE GEN
     263     2536125 : mkmat(GEN x) { retmkmat(x); }
     264             : INLINE GEN
     265    32199223 : 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       22383 : 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       95999 : mkoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_1; return v; }
     278             : INLINE GEN
     279       16919 : mkmoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_m1; return v; }
     280             : INLINE long
     281      132494 : inf_get_sign(GEN x) { return signe(gel(x,1)); }
     282             : INLINE GEN
     283       10696 : mkmat22s(long a, long b, long c, long d) {retmkmat2(mkcol2s(a,c),mkcol2s(b,d));}
     284             : INLINE GEN
     285     1533070 : mkmat22(GEN a, GEN b, GEN c, GEN d) { retmkmat2(mkcol2(a,c),mkcol2(b,d)); }
     286             : 
     287             : /* pol */
     288             : INLINE GEN
     289      989071 : pol_x(long v) {
     290      989071 :   GEN p = cgetg(4, t_POL);
     291      989071 :   p[1] = evalsigne(1)|evalvarn(v);
     292      989071 :   gel(p,2) = gen_0;
     293      989071 :   gel(p,3) = gen_1; return p;
     294             : }
     295             : /* x^n, assume n >= 0 */
     296             : INLINE GEN
     297     2710533 : pol_xn(long n, long v) {
     298     2710533 :   long i, a = n+2;
     299     2710533 :   GEN p = cgetg(a+1, t_POL);
     300     2710531 :   p[1] = evalsigne(1)|evalvarn(v);
     301     2710531 :   for (i = 2; i < a; i++) gel(p,i) = gen_0;
     302     2710531 :   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     1507362 : pol_1(long v) {
     313     1507362 :   GEN p = cgetg(3, t_POL);
     314     1507361 :   p[1] = evalsigne(1)|evalvarn(v);
     315     1507361 :   gel(p,2) = gen_1; return p;
     316             : }
     317             : INLINE GEN
     318    32857689 : pol_0(long v)
     319             : {
     320    32857689 :   GEN x = cgetg(2,t_POL);
     321    32857689 :   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     8745964 : 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     8679095 : const_col(long n, GEN x) { retconst_col(n, x); }
     337             : INLINE GEN
     338     8602091 : const_vecsmall(long n, long c)
     339             : {
     340             :   long i;
     341     8602091 :   GEN V = cgetg(n+1,t_VECSMALL);
     342     8602260 :   for(i=1;i<=n;i++) V[i] = c;
     343     8602260 :   return V;
     344             : }
     345             : 
     346             : /***   ZERO   ***/
     347             : /* O(p^e) */
     348             : INLINE GEN
     349      302754 : zeropadic(GEN p, long e)
     350             : {
     351      302754 :   GEN y = cgetg(5,t_PADIC);
     352      302754 :   gel(y,4) = gen_0;
     353      302754 :   gel(y,3) = gen_1;
     354      302754 :   gel(y,2) = icopy(p);
     355      302754 :   y[1] = evalvalp(e) | _evalprecp(0);
     356      302754 :   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      143472 : zeroser(long v, long e)
     371             : {
     372      143472 :   GEN x = cgetg(2, t_SER);
     373      143472 :   x[1] = evalvalp(e) | evalvarn(v); return x;
     374             : }
     375             : INLINE int
     376     5745062 : ser_isexactzero(GEN x)
     377             : {
     378     5745062 :   if (!signe(x)) switch(lg(x))
     379             :   {
     380      136129 :     case 2: return 1;
     381         854 :     case 3: return isexactzero(gel(x,2));
     382             :   }
     383     5608079 :   return 0;
     384             : }
     385             : /* 0 * pol_x(v) */
     386             : INLINE GEN
     387    15599147 : zeropol(long v) { return pol_0(v); }
     388             : /* vector(n) */
     389             : INLINE GEN
     390    37588077 : zerocol(long n)
     391             : {
     392    37588077 :   GEN y = cgetg(n+1,t_COL);
     393    37588224 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     394    37588224 :   return y;
     395             : }
     396             : /* vectorv(n) */
     397             : INLINE GEN
     398    21782928 : zerovec(long n)
     399             : {
     400    21782928 :   GEN y = cgetg(n+1,t_VEC);
     401    21782934 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     402    21782934 :   return y;
     403             : }
     404             : /* matrix(m, n) */
     405             : INLINE GEN
     406       23548 : zeromat(long m, long n)
     407             : {
     408       23548 :   GEN y = cgetg(n+1,t_MAT);
     409       23548 :   GEN v = zerocol(m);
     410       23548 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     411       23548 :   return y;
     412             : }
     413             : /* = zero_zx, sv is a evalvarn()*/
     414             : INLINE GEN
     415      931007 : zero_Flx(long sv) { return pol0_Flx(sv); }
     416             : INLINE GEN
     417    33638765 : zero_Flv(long n)
     418             : {
     419    33638765 :   GEN y = cgetg(n+1,t_VECSMALL);
     420    33640400 :   long i; for (i=1; i<=n; i++) y[i] = 0;
     421    33640400 :   return y;
     422             : }
     423             : /* matrix(m, n) */
     424             : INLINE GEN
     425      923001 : zero_Flm(long m, long n)
     426             : {
     427      923001 :   GEN y = cgetg(n+1,t_MAT);
     428      922983 :   GEN v = zero_Flv(m);
     429      922998 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     430      922998 :   return y;
     431             : }
     432             : /* matrix(m, n) */
     433             : INLINE GEN
     434      110202 : zero_Flm_copy(long m, long n)
     435             : {
     436      110202 :   GEN y = cgetg(n+1,t_MAT);
     437      110197 :   long i; for (i=1; i<=n; i++) gel(y,i) = zero_Flv(m);
     438      110205 :   return y;
     439             : }
     440             : 
     441             : INLINE GEN
     442      797111 : zero_F2v(long m)
     443             : {
     444      797111 :   long l = nbits2nlong(m);
     445      797111 :   GEN v  = zero_Flv(l+1);
     446      797111 :   v[1] = m;
     447      797111 :   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      277574 : zero_F2m_copy(long m, long n)
     464             : {
     465             :   long i;
     466      277574 :   GEN M = cgetg(n+1, t_MAT);
     467      808236 :   for (i = 1; i <= n; i++)
     468      530662 :     gel(M,i)= zero_F2v(m);
     469      277574 :   return M;
     470             : }
     471             : 
     472             : /* matrix(m, n) */
     473             : INLINE GEN
     474     4890129 : zeromatcopy(long m, long n)
     475             : {
     476     4890129 :   GEN y = cgetg(n+1,t_MAT);
     477     4890129 :   long i; for (i=1; i<=n; i++) gel(y,i) = zerocol(m);
     478     4890129 :   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     1422076 : col_ei(long n, long i) { GEN e = zerocol(n); gel(e,i) = gen_1; return e; }
     494             : INLINE GEN
     495      336187 : 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       71428 : vecsmall_ei(long n, long i) { GEN e = zero_zv(n); e[i] = 1; return e; }
     500             : INLINE GEN
     501      683087 : Rg_col_ei(GEN x, long n, long i) { GEN e = zerocol(n); gel(e,i) = x; return e; }
     502             : 
     503             : INLINE GEN
     504    12709139 : shallowcopy(GEN x)
     505    12709139 : { return typ(x) == t_MAT ? RgM_shallowcopy(x): leafcopy(x); }
     506             : 
     507             : /* routines for naive growarrays */
     508             : INLINE GEN
     509    12714563 : vectrunc_init(long l)
     510             : {
     511    12714563 :   GEN z = new_chunk(l);
     512    12714730 :   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   257578458 : lg_increase(GEN x) { x[0]++; }
     522             : INLINE void
     523    51326607 : 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    84513454 : vecsmalltrunc_init(long l)
     534             : {
     535    84513454 :   GEN z = new_chunk(l);
     536    84513454 :   z[0] = evaltyp(t_VECSMALL) | _evallg(1); return z;
     537             : }
     538             : INLINE void
     539    33067344 : vecsmalltrunc_append(GEN x, long t) { x[ lg(x) ] = t; lg_increase(x); }
     540             : 
     541             : /*******************************************************************/
     542             : /*                                                                 */
     543             : /*                    STRING HASH FUNCTIONS                        */
     544             : /*                                                                 */
     545             : /*******************************************************************/
     546             : INLINE ulong
     547     1931379 : hash_str(const char *str)
     548             : {
     549     1931379 :   ulong hash = 5381UL, c;
     550    20949064 :   while ( (c = (ulong)*str++) )
     551    17086306 :     hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
     552     1931379 :   return hash;
     553             : }
     554             : INLINE ulong
     555     6575201 : hash_str_len(const char *str, long len)
     556             : {
     557     6575201 :   ulong hash = 5381UL;
     558             :   long i;
     559    24847507 :   for (i = 0; i < len; i++)
     560             :   {
     561    18272306 :     ulong c = (ulong)*str++;
     562    18272306 :     hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
     563             :   }
     564     6575201 :   return hash;
     565             : }
     566             : 
     567             : /*******************************************************************/
     568             : /*                                                                 */
     569             : /*                        VEC / COL / VECSMALL                     */
     570             : /*                                                                 */
     571             : /*******************************************************************/
     572             : /* shallow*/
     573             : INLINE GEN
     574           0 : vec_shorten(GEN v, long n)
     575             : {
     576             :   long i;
     577           0 :   GEN V = cgetg(n+1,t_VEC);
     578           0 :   for(i=1;i<=n;i++) gel(V,i) = gel(v,i);
     579           0 :   return V;
     580             : }
     581             : /* shallow*/
     582             : INLINE GEN
     583       13710 : vec_lengthen(GEN v, long n)
     584             : {
     585             :   long i;
     586       13710 :   long l=lg(v);
     587       13710 :   GEN V = cgetg(n+1,t_VEC);
     588       13710 :   for(i=1;i<l;i++) gel(V,i) = gel(v,i);
     589       13710 :   return V;
     590             : }
     591             : /* shallow*/
     592             : INLINE GEN
     593       62706 : vec_append(GEN V, GEN s)
     594             : {
     595       62706 :   long i, l2 = lg(V);
     596       62706 :   GEN res = cgetg(l2+1, typ(V));
     597       62706 :   for (i = 1; i < l2; ++i) gel(res, i) = gel(V,i);
     598       62706 :   gel(res,l2) = s; return res;
     599             : }
     600             : /* shallow*/
     601             : INLINE GEN
     602        1785 : vec_prepend(GEN v, GEN s)
     603             : {
     604        1785 :   long i, l = lg(v);
     605        1785 :   GEN w = cgetg(l+1, typ(v));
     606        1785 :   gel(w,1) = s;
     607        1785 :   for (i = 2; i <= l; ++i) gel(w,i) = gel(v,i-1);
     608        1785 :   return w;
     609             : }
     610             : /* shallow*/
     611             : INLINE GEN
     612           0 : vec_setconst(GEN v, GEN x)
     613             : {
     614           0 :   long i, l = lg(v);
     615           0 :   for (i = 1; i < l; i++) gel(v,i) = x;
     616           0 :   return v;
     617             : }
     618             : INLINE GEN
     619      750188 : vecsmall_shorten(GEN v, long n)
     620             : {
     621             :   long i;
     622      750188 :   GEN V = cgetg(n+1,t_VECSMALL);
     623      750096 :   for(i=1;i<=n;i++) V[i] = v[i];
     624      750096 :   return V;
     625             : }
     626             : INLINE GEN
     627          21 : vecsmall_lengthen(GEN v, long n)
     628             : {
     629          21 :   long i, l = lg(v);
     630          21 :   GEN V = cgetg(n+1,t_VECSMALL);
     631          21 :   for(i=1;i<l;i++) V[i] = v[i];
     632          21 :   return V;
     633             : }
     634             : 
     635             : INLINE GEN
     636     3365332 : vec_to_vecsmall(GEN x)
     637     3365332 : { pari_APPLY_long(itos(gel(x,i))) }
     638             : INLINE GEN
     639      135172 : vecsmall_to_vec(GEN x)
     640      135172 : { pari_APPLY_type(t_VEC, stoi(x[i])) }
     641             : INLINE GEN
     642        1617 : vecsmall_to_vec_inplace(GEN z)
     643             : {
     644        1617 :   long i, l = lg(z);
     645        1617 :   for (i=1; i<l; i++) gel(z,i) = stoi(z[i]);
     646        1617 :   settyp(z, t_VEC); return z;
     647             : }
     648             : INLINE GEN
     649     5227133 : vecsmall_to_col(GEN x)
     650     5227133 : { pari_APPLY_type(t_COL, stoi(x[i])) }
     651             : 
     652             : INLINE int
     653     8141461 : vecsmall_lexcmp(GEN x, GEN y)
     654             : {
     655             :   long lx,ly,l,i;
     656     8141461 :   lx = lg(x);
     657     8141461 :   ly = lg(y); l = minss(lx,ly);
     658    39719125 :   for (i=1; i<l; i++)
     659    37847303 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     660     1871822 :   if (lx == ly) return 0;
     661          14 :   return (lx < ly)? -1 : 1;
     662             : }
     663             : 
     664             : INLINE int
     665    85155511 : vecsmall_prefixcmp(GEN x, GEN y)
     666             : {
     667    85155511 :   long i, lx = lg(x), ly = lg(y), l = minss(lx,ly);
     668   394027655 :   for (i=1; i<l; i++)
     669   374395014 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     670    19632641 :   return 0;
     671             : }
     672             : 
     673             : /*Can be used on t_VEC, but coeffs not gcopy-ed*/
     674             : INLINE GEN
     675       21414 : vecsmall_prepend(GEN V, long s)
     676             : {
     677       21414 :   long i, l2 = lg(V);
     678       21414 :   GEN res = cgetg(l2+1, typ(V));
     679       21414 :   res[1] = s;
     680       21414 :   for (i = 2; i <= l2; ++i) res[i] = V[i - 1];
     681       21414 :   return res;
     682             : }
     683             : 
     684             : INLINE GEN
     685     3128712 : vecsmall_append(GEN V, long s)
     686             : {
     687     3128712 :   long i, l2 = lg(V);
     688     3128712 :   GEN res = cgetg(l2+1, t_VECSMALL);
     689     3128711 :   for (i = 1; i < l2; ++i) res[i] = V[i];
     690     3128711 :   res[l2] = s; return res;
     691             : }
     692             : 
     693             : INLINE GEN
     694      786495 : vecsmall_concat(GEN u, GEN v)
     695             : {
     696      786495 :   long i, l1 = lg(u)-1, l2 = lg(v)-1;
     697      786495 :   GEN res = cgetg(l1+l2+1, t_VECSMALL);
     698      786496 :   for (i = 1; i <= l1; ++i) res[i]    = u[i];
     699      786496 :   for (i = 1; i <= l2; ++i) res[i+l1] = v[i];
     700      786496 :   return res;
     701             : }
     702             : 
     703             : /* return the number of indices where u and v are equal */
     704             : INLINE long
     705           0 : vecsmall_coincidence(GEN u, GEN v)
     706             : {
     707           0 :   long i, s = 0, l = minss(lg(u),lg(v));
     708           0 :   for(i=1; i<l; i++)
     709           0 :     if(u[i] == v[i]) s++;
     710           0 :   return s;
     711             : }
     712             : 
     713             : /* returns the first index i<=n such that x=v[i] if it exists, 0 otherwise */
     714             : INLINE long
     715           0 : vecsmall_isin(GEN v, long x)
     716             : {
     717           0 :   long i, l = lg(v);
     718           0 :   for (i = 1; i < l; i++)
     719           0 :     if (v[i] == x) return i;
     720           0 :   return 0;
     721             : }
     722             : 
     723             : INLINE long
     724          84 : vecsmall_pack(GEN V, long base, long mod)
     725             : {
     726          84 :   long i, s = 0;
     727          84 :   for(i=1; i<lg(V); i++) s = (base*s + V[i]) % mod;
     728          84 :   return s;
     729             : }
     730             : 
     731             : INLINE long
     732          14 : vecsmall_indexmax(GEN x)
     733             : {
     734          14 :   long i, i0 = 1, t = x[1], lx = lg(x);
     735          56 :   for (i=2; i<lx; i++)
     736          42 :     if (x[i] > t) t = x[i0=i];
     737          14 :   return i0;
     738             : }
     739             : 
     740             : INLINE long
     741      179196 : vecsmall_max(GEN x)
     742             : {
     743      179196 :   long i, t = x[1], lx = lg(x);
     744      641674 :   for (i=2; i<lx; i++)
     745      462478 :     if (x[i] > t) t = x[i];
     746      179196 :   return t;
     747             : }
     748             : 
     749             : INLINE long
     750          14 : vecsmall_indexmin(GEN x)
     751             : {
     752          14 :   long i, i0 = 1, t = x[1], lx =lg(x);
     753          56 :   for (i=2; i<lx; i++)
     754          42 :     if (x[i] < t) t = x[i0=i];
     755          14 :   return i0;
     756             : }
     757             : 
     758             : INLINE long
     759        1421 : vecsmall_min(GEN x)
     760             : {
     761        1421 :   long i, t = x[1], lx =lg(x);
     762        9947 :   for (i=2; i<lx; i++)
     763        8526 :     if (x[i] < t) t = x[i];
     764        1421 :   return t;
     765             : }
     766             : 
     767             : INLINE int
     768     5045407 : ZV_isscalar(GEN x)
     769             : {
     770     5045407 :   long l = lg(x);
     771    14375695 :   while (--l > 1)
     772     8216439 :     if (signe(gel(x, l))) return 0;
     773     1113849 :   return 1;
     774             : }
     775             : INLINE int
     776    19658249 : QV_isscalar(GEN x)
     777             : {
     778    19658249 :   long lx = lg(x),i;
     779    21251162 :   for (i=2; i<lx; i++)
     780    20637120 :     if (!isintzero(gel(x, i))) return 0;
     781      614042 :   return 1;
     782             : }
     783             : INLINE int
     784        7676 : RgV_isscalar(GEN x)
     785             : {
     786        7676 :   long lx = lg(x),i;
     787       11255 :   for (i=2; i<lx; i++)
     788        9998 :     if (!gequal0(gel(x, i))) return 0;
     789        1257 :   return 1;
     790             : }
     791             : INLINE int
     792           0 : RgX_isscalar(GEN x)
     793             : {
     794             :   long i;
     795           0 :   for (i=lg(x)-1; i>2; i--)
     796           0 :     if (!gequal0(gel(x, i))) return 0;
     797           0 :   return 1;
     798             : }
     799             : INLINE long
     800    28786089 : RgX_equal_var(GEN x, GEN y) { return varn(x) == varn(y) && RgX_equal(x,y); }
     801             : 
     802             : INLINE int
     803        6259 : RgX_is_rational(GEN x)
     804             : {
     805             :   long i;
     806       29883 :   for (i = lg(x)-1; i > 1; i--)
     807       27901 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     808        1982 :   return 1;
     809             : }
     810             : INLINE int
     811     4451436 : RgX_is_ZX(GEN x)
     812             : {
     813             :   long i;
     814    19084627 :   for (i = lg(x)-1; i > 1; i--)
     815    14685642 :     if (typ(gel(x,i)) != t_INT) return 0;
     816     4398985 :   return 1;
     817             : }
     818             : INLINE int
     819      262577 : RgX_is_QX(GEN x)
     820             : {
     821      262577 :   long k = lg(x)-1;
     822      928107 :   for ( ; k>1; k--)
     823      665775 :     if (!is_rational_t(typ(gel(x,k)))) return 0;
     824      262332 :   return 1;
     825             : }
     826             : INLINE int
     827    16173623 : RgX_is_monomial(GEN x)
     828             : {
     829             :   long i;
     830    16173623 :   if (!signe(x)) return 0;
     831    26721442 :   for (i=lg(x)-2; i>1; i--)
     832    18332722 :     if (!isexactzero(gel(x,i))) return 0;
     833     8388720 :   return 1;
     834             : }
     835             : INLINE int
     836    27445544 : RgV_is_ZV(GEN x)
     837             : {
     838             :   long i;
     839   112529688 :   for (i = lg(x)-1; i > 0; i--)
     840    85086405 :     if (typ(gel(x,i)) != t_INT) return 0;
     841    27443283 :   return 1;
     842             : }
     843             : INLINE int
     844       21109 : RgV_is_QV(GEN x)
     845             : {
     846             :   long i;
     847       84923 :   for (i = lg(x)-1; i > 0; i--)
     848       65417 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     849       19506 :   return 1;
     850             : }
     851             : 
     852             : /********************************************************************/
     853             : /**                                                                **/
     854             : /**            Dynamic arrays implementation                       **/
     855             : /**                                                                **/
     856             : /********************************************************************/
     857             : INLINE void **
     858   403392007 : pari_stack_base(pari_stack *s) { return s->data; }
     859             : 
     860             : INLINE void
     861     1788155 : pari_stack_init(pari_stack *s, size_t size, void **data)
     862             : {
     863     1788155 :   s->data = data;
     864     1788155 :   *data = NULL;
     865     1788155 :   s->n = 0;
     866     1788155 :   s->alloc = 0;
     867     1788155 :   s->size = size;
     868     1788155 : }
     869             : 
     870             : INLINE void
     871   401651149 : pari_stack_alloc(pari_stack *s, long nb)
     872             : {
     873   401651149 :   void **sdat = pari_stack_base(s);
     874   401667739 :   long alloc = s->alloc;
     875   401667739 :   if (s->n+nb <= alloc) return;
     876      659258 :   if (!alloc)
     877      606171 :     alloc = nb;
     878             :   else
     879             :   {
     880       53087 :     while (s->n+nb > alloc) alloc <<= 1;
     881             :   }
     882      659258 :   *sdat = pari_realloc(*sdat,alloc*s->size);
     883      660061 :   s->alloc = alloc;
     884             : }
     885             : 
     886             : INLINE long
     887   323963110 : pari_stack_new(pari_stack *s) { pari_stack_alloc(s, 1); return s->n++; }
     888             : 
     889             : INLINE void
     890     1730858 : pari_stack_delete(pari_stack *s)
     891             : {
     892     1730858 :   void **sdat = pari_stack_base(s);
     893     1727258 :   if (*sdat) pari_free(*sdat);
     894     1739605 : }
     895             : 
     896             : INLINE void
     897        4815 : pari_stack_pushp(pari_stack *s, void *u)
     898             : {
     899        4815 :   long n = pari_stack_new(s);
     900        4815 :   void **sdat =(void**) *pari_stack_base(s);
     901        4815 :   sdat[n] = u;
     902        4815 : }
     903             : 
     904             : /*******************************************************************/
     905             : /*                                                                 */
     906             : /*                            EXTRACT                              */
     907             : /*                                                                 */
     908             : /*******************************************************************/
     909             : INLINE GEN
     910   202212497 : vecslice(GEN A, long y1, long y2)
     911             : {
     912   202212497 :   long i,lB = y2 - y1 + 2;
     913   202212497 :   GEN B = cgetg(lB, typ(A));
     914   202213166 :   for (i=1; i<lB; i++) B[i] = A[y1-1+i];
     915   202213166 :   return B;
     916             : }
     917             : INLINE GEN
     918      816388 : vecslicepermute(GEN A, GEN p, long y1, long y2)
     919             : {
     920      816388 :   long i,lB = y2 - y1 + 2;
     921      816388 :   GEN B = cgetg(lB, typ(A));
     922      816397 :   for (i=1; i<lB; i++) B[i] = A[p[y1-1+i]];
     923      816397 :   return B;
     924             : }
     925             : /* rowslice(rowpermute(A,p), x1, x2) */
     926             : INLINE GEN
     927       40668 : rowslicepermute(GEN x, GEN p, long j1, long j2)
     928       40668 : { pari_APPLY_same(vecslicepermute(gel(x,i),p,j1,j2)) }
     929             : 
     930             : INLINE GEN
     931    22366668 : rowslice(GEN x, long j1, long j2)
     932    22366668 : { pari_APPLY_same(vecslice(gel(x,i), j1, j2)) }
     933             : 
     934             : INLINE GEN
     935     3703684 : matslice(GEN A, long x1, long x2, long y1, long y2)
     936     3703684 : { return rowslice(vecslice(A, y1, y2), x1, x2); }
     937             : 
     938             : /* shallow, remove coeff of index j */
     939             : INLINE GEN
     940         133 : rowsplice(GEN x, long j)
     941         133 : { pari_APPLY_same(vecsplice(gel(x,i), j)) }
     942             : 
     943             : /* shallow, remove coeff of index j */
     944             : INLINE GEN
     945      264453 : vecsplice(GEN a, long j)
     946             : {
     947      264453 :   long i, k, l = lg(a);
     948             :   GEN b;
     949      264453 :   if (l == 1) pari_err(e_MISC, "incorrect component in vecsplice");
     950      264453 :   b = cgetg(l-1, typ(a));
     951     1056062 :   for (i = k = 1; i < l; i++)
     952      791609 :     if (i != j) gel(b, k++) = gel(a,i);
     953      264453 :   return b;
     954             : }
     955             : /* shallow */
     956             : INLINE GEN
     957         833 : RgM_minor(GEN a, long i, long j)
     958             : {
     959         833 :   GEN b = vecsplice(a, j);
     960         833 :   long k, l = lg(b);
     961         833 :   for (k = 1; k < l; k++) gel(b,k) = vecsplice(gel(b,k), i);
     962         833 :   return b;
     963             : }
     964             : 
     965             : /* A[x0,] */
     966             : INLINE GEN
     967      390422 : row(GEN x, long j)
     968      390422 : { pari_APPLY_type(t_VEC, gcoeff(x, j, i)) }
     969             : INLINE GEN
     970     3758949 : Flm_row(GEN x, long j)
     971     3758949 : { pari_APPLY_ulong((ulong)coeff(x, j, i)) }
     972             : /* A[x0,] */
     973             : INLINE GEN
     974      204820 : rowcopy(GEN x, long j)
     975      204820 : { pari_APPLY_type(t_VEC, gcopy(gcoeff(x, j, i))) }
     976             : /* A[x0, x1..x2] */
     977             : INLINE GEN
     978        2303 : row_i(GEN A, long x0, long x1, long x2)
     979             : {
     980        2303 :   long i, lB = x2 - x1 + 2;
     981        2303 :   GEN B  = cgetg(lB, t_VEC);
     982        2303 :   for (i=x1; i<=x2; i++) gel(B, i) = gcoeff(A, x0, i);
     983        2303 :   return B;
     984             : }
     985             : 
     986             : INLINE GEN
     987     5830483 : vecreverse(GEN A)
     988             : {
     989             :   long i, l;
     990     5830483 :   GEN B = cgetg_copy(A, &l);
     991     5830483 :   for (i=1; i<l; i++) gel(B, i) = gel(A, l-i);
     992     5830483 :   return B;
     993             : }
     994             : 
     995             : INLINE GEN
     996         329 : vecsmall_reverse(GEN A)
     997             : {
     998             :   long i, l;
     999         329 :   GEN B = cgetg_copy(A, &l);
    1000         329 :   for (i=1; i<l; i++) B[i] = A[l-i];
    1001         329 :   return B;
    1002             : }
    1003             : 
    1004             : INLINE void
    1005         253 : vecreverse_inplace(GEN y)
    1006             : {
    1007         253 :   long l = lg(y), lim = l>>1, i;
    1008         717 :   for (i = 1; i <= lim; i++)
    1009             :   {
    1010         464 :     GEN z = gel(y,i);
    1011         464 :     gel(y,i)    = gel(y,l-i);
    1012         464 :     gel(y,l-i) = z;
    1013             :   }
    1014         253 : }
    1015             : 
    1016             : INLINE GEN
    1017    45407301 : vecsmallpermute(GEN A, GEN p) { return perm_mul(A, p); }
    1018             : 
    1019             : INLINE GEN
    1020     6509599 : vecpermute(GEN A, GEN x)
    1021     6509599 : { pari_APPLY_type(typ(A), gel(A, x[i])) }
    1022             : 
    1023             : INLINE GEN
    1024     3011018 : rowpermute(GEN x, GEN p)
    1025     3011018 : { pari_APPLY_same(typ(gel(x,i)) == t_VECSMALL ? vecsmallpermute(gel(x, i), p)
    1026             :                                               : vecpermute(gel(x, i), p))
    1027             : }
    1028             : /*******************************************************************/
    1029             : /*                                                                 */
    1030             : /*                          PERMUTATIONS                           */
    1031             : /*                                                                 */
    1032             : /*******************************************************************/
    1033             : /* identity permutation */
    1034             : INLINE GEN
    1035      728152 : identity_perm(long n)
    1036             : {
    1037      728152 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1038             :   long i;
    1039      728148 :   for (i = 1; i <= n; i++) perm[i] = i;
    1040      728148 :   return perm;
    1041             : }
    1042             : 
    1043             : /* assume d <= n */
    1044             : INLINE GEN
    1045       98434 : cyclic_perm(long n, long d)
    1046             : {
    1047       98434 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1048             :   long i;
    1049       98434 :   for (i = 1; i <= n-d; i++) perm[i] = i+d;
    1050       98434 :   for (     ; i <= n;   i++) perm[i] = i-n+d;
    1051       98434 :   return perm;
    1052             : }
    1053             : 
    1054             : /* Multiply (compose) two permutations */
    1055             : INLINE GEN
    1056    46651212 : perm_mul(GEN s, GEN x)
    1057    46651212 : { pari_APPLY_long(s[x[i]]) }
    1058             : 
    1059             : /* Compute the inverse (reciprocal) of a permutation. */
    1060             : INLINE GEN
    1061     1161956 : perm_inv(GEN x)
    1062             : {
    1063             :   long i, lx;
    1064     1161956 :   GEN y = cgetg_copy(x, &lx);
    1065     1161955 :   for (i=1; i<lx; i++) y[ x[i] ] = i;
    1066     1161955 :   return y;
    1067             : }
    1068             : /* Return s*t*s^-1 */
    1069             : INLINE GEN
    1070      416934 : perm_conj(GEN s, GEN t)
    1071             : {
    1072             :   long i, l;
    1073      416934 :   GEN v = cgetg_copy(s, &l);
    1074      416934 :   for (i = 1; i < l; i++) v[ s[i] ] = s[ t[i] ];
    1075      416934 :   return v;
    1076             : }
    1077             : 
    1078             : /*********************************************************************/
    1079             : /*                       MALLOC/FREE WRAPPERS                        */
    1080             : /*********************************************************************/
    1081             : #define BLOCK_SIGALRM_START          \
    1082             : {                                    \
    1083             :   int block=PARI_SIGINT_block;       \
    1084             :   PARI_SIGINT_block = 2;             \
    1085             :   MT_SIGINT_BLOCK(block);
    1086             : 
    1087             : #define BLOCK_SIGINT_START           \
    1088             : {                                    \
    1089             :   int block=PARI_SIGINT_block;       \
    1090             :   PARI_SIGINT_block = 1;             \
    1091             :   MT_SIGINT_BLOCK(block);
    1092             : 
    1093             : #define BLOCK_SIGINT_END             \
    1094             :   PARI_SIGINT_block = block;         \
    1095             :   MT_SIGINT_UNBLOCK(block);          \
    1096             :   if (!block && PARI_SIGINT_pending) \
    1097             :   {                                  \
    1098             :     int sig = PARI_SIGINT_pending;   \
    1099             :     PARI_SIGINT_pending = 0;         \
    1100             :     raise(sig);                      \
    1101             :   }                                  \
    1102             : }
    1103             : 
    1104             : INLINE void
    1105    72147809 : pari_free(void *pointer)
    1106             : {
    1107    72147809 :   BLOCK_SIGINT_START;
    1108    72168450 :   free(pointer);
    1109    72168450 :   BLOCK_SIGINT_END;
    1110    72163833 : }
    1111             : INLINE void*
    1112   279143828 : pari_malloc(size_t size)
    1113             : {
    1114   279143828 :   if (size)
    1115             :   {
    1116             :     char *tmp;
    1117   279143828 :     BLOCK_SIGINT_START;
    1118   279147321 :     tmp = (char*)malloc(size);
    1119   279147321 :     BLOCK_SIGINT_END;
    1120   279146939 :     if (!tmp) pari_err(e_MEM);
    1121   279146939 :     return tmp;
    1122             :   }
    1123           0 :   return NULL;
    1124             : }
    1125             : INLINE void*
    1126      673959 : pari_realloc(void *pointer, size_t size)
    1127             : {
    1128             :   char *tmp;
    1129             : 
    1130      673959 :   BLOCK_SIGINT_START;
    1131      675705 :   if (!pointer) tmp = (char *) malloc(size);
    1132       56864 :   else tmp = (char *) realloc(pointer,size);
    1133      675705 :   BLOCK_SIGINT_END;
    1134      675130 :   if (!tmp) pari_err(e_MEM);
    1135      675130 :   return tmp;
    1136             : }
    1137             : INLINE void*
    1138       35683 : pari_calloc(size_t size)
    1139             : {
    1140       35683 :   void *t = pari_malloc(size);
    1141       35683 :   memset(t, 0, size); return t;
    1142             : }
    1143             : INLINE GEN
    1144        5813 : cgetalloc(long t, size_t l)
    1145             : {
    1146        5813 :   GEN x = (GEN)pari_malloc(l * sizeof(long));
    1147        5813 :   x[0] = evaltyp(t) | evallg(l); return x;
    1148             : }
    1149             : 
    1150             : /*******************************************************************/
    1151             : /*                                                                 */
    1152             : /*                       GARBAGE COLLECTION                        */
    1153             : /*                                                                 */
    1154             : /*******************************************************************/
    1155             : /* copy integer x as if we had set_avma(av) */
    1156             : INLINE GEN
    1157  3812592563 : icopy_avma(GEN x, pari_sp av)
    1158             : {
    1159  3812592563 :   long i = lgefint(x), lx = i;
    1160  3812592563 :   GEN y = ((GEN)av) - i;
    1161  3812592563 :   while (--i > 0) y[i] = x[i];
    1162  3812592563 :   y[0] = evaltyp(t_INT)|evallg(lx);
    1163  3812364030 :   return y;
    1164             : }
    1165             : /* copy leaf x as if we had set_avma(av) */
    1166             : INLINE GEN
    1167   177549511 : leafcopy_avma(GEN x, pari_sp av)
    1168             : {
    1169   177549511 :   long i = lg(x);
    1170   177549511 :   GEN y = ((GEN)av) - i;
    1171   177549511 :   while (--i > 0) y[i] = x[i];
    1172   177549511 :   y[0] = x[0] & (~CLONEBIT);
    1173   177549511 :   return y;
    1174             : }
    1175             : INLINE GEN
    1176   638319543 : gerepileuptoleaf(pari_sp av, GEN x)
    1177             : {
    1178             :   long lx;
    1179             :   GEN q;
    1180             : 
    1181   638319543 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1182   638222046 :   lx = lg(x);
    1183   638222046 :   q = ((GEN)av) - lx;
    1184   638222046 :   set_avma((pari_sp)q);
    1185   640063297 :   while (--lx >= 0) q[lx] = x[lx];
    1186   640063297 :   return q;
    1187             : }
    1188             : INLINE GEN
    1189  1285700157 : gerepileuptoint(pari_sp av, GEN x)
    1190             : {
    1191  1285700157 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1192  1137631537 :   set_avma((pari_sp)icopy_avma(x, av));
    1193  1139169756 :   return (GEN)avma;
    1194             : }
    1195             : INLINE GEN
    1196   812912162 : gerepileupto(pari_sp av, GEN x)
    1197             : {
    1198   812912162 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1199   723406932 :   switch(typ(x))
    1200             :   { /* non-default = !is_recursive_t(tq) */
    1201   258988041 :     case t_INT: return gerepileuptoint(av, x);
    1202             :     case t_REAL:
    1203             :     case t_STR:
    1204   145498528 :     case t_VECSMALL: return gerepileuptoleaf(av,x);
    1205             :     default:
    1206             :       /* NB: x+i --> ((long)x) + i*sizeof(long) */
    1207   318920363 :       return gerepile(av, (pari_sp) (x+lg(x)), x);
    1208             :   }
    1209             : }
    1210             : INLINE double
    1211     2269412 : gc_double(pari_sp av, double d) { set_avma(av); return d; }
    1212             : INLINE long
    1213   112961134 : gc_long(pari_sp av, long s) { set_avma(av); return s; }
    1214             : INLINE ulong
    1215    15269264 : gc_ulong(pari_sp av, ulong s) { set_avma(av); return s; }
    1216             : INLINE int
    1217    21966149 : gc_bool(pari_sp av, int s) { set_avma(av); return s; }
    1218             : INLINE int
    1219     3366387 : gc_int(pari_sp av, int s) { set_avma(av); return s; }
    1220             : INLINE GEN
    1221     1610927 : gc_NULL(pari_sp av) { set_avma(av); return NULL; }
    1222             : 
    1223             : /* gerepileupto(av, gcopy(x)) */
    1224             : INLINE GEN
    1225    53160162 : gerepilecopy(pari_sp av, GEN x)
    1226             : {
    1227    53160162 :   if (is_recursive_t(typ(x)))
    1228             :   {
    1229    48544508 :     GENbin *p = copy_bin(x);
    1230    48545012 :     set_avma(av); return bin_copy(p);
    1231             :   }
    1232             :   else
    1233             :   {
    1234     4615641 :     set_avma(av);
    1235     4615647 :     if (x < (GEN)av) {
    1236     3128191 :       if (x < (GEN)pari_mainstack->bot) new_chunk(lg(x));
    1237     3128191 :       x = leafcopy_avma(x, av);
    1238     3128197 :       set_avma((pari_sp)x);
    1239             :     } else
    1240     1487456 :       x = leafcopy(x);
    1241     4615653 :     return x;
    1242             :   }
    1243             : }
    1244             : 
    1245             : /* Takes an array of pointers to GENs, of length n. Copies all
    1246             :  * objects to contiguous locations and cleans up the stack between
    1247             :  * av and avma. */
    1248             : INLINE void
    1249      199411 : gerepilemany(pari_sp av, GEN* gptr[], int n)
    1250             : {
    1251             :   int i;
    1252      199411 :   for (i=0; i<n; i++) *gptr[i] = (GEN)copy_bin(*gptr[i]);
    1253      199411 :   set_avma(av);
    1254      199411 :   for (i=0; i<n; i++) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1255      199411 : }
    1256             : 
    1257             : INLINE void
    1258     7560473 : gerepileall(pari_sp av, int n, ...)
    1259             : {
    1260             :   int i;
    1261     7560473 :   va_list a; va_start(a, n);
    1262     7560473 :   if (n < 10)
    1263             :   {
    1264             :     GEN *gptr[10];
    1265    21891819 :     for (i=0; i<n; i++)
    1266    14331313 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1267     7560506 :     set_avma(av);
    1268     7560416 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1269             : 
    1270             :   }
    1271             :   else
    1272             :   {
    1273           0 :     GEN **gptr = (GEN**)  pari_malloc(n*sizeof(GEN*));
    1274           0 :     for (i=0; i<n; i++)
    1275           0 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1276           0 :     set_avma(av);
    1277           0 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1278           0 :     pari_free(gptr);
    1279             :   }
    1280     7560607 :   va_end(a);
    1281     7560607 : }
    1282             : 
    1283             : INLINE void
    1284           6 : gerepilecoeffs(pari_sp av, GEN x, int n)
    1285             : {
    1286             :   int i;
    1287           6 :   for (i=0; i<n; i++) gel(x,i) = (GEN)copy_bin(gel(x,i));
    1288           6 :   set_avma(av);
    1289           6 :   for (i=0; i<n; i++) gel(x,i) = bin_copy((GENbin*)x[i]);
    1290           6 : }
    1291             : 
    1292             : /* p from copy_bin. Copy p->x back to stack, then destroy p */
    1293             : INLINE GEN
    1294    63489604 : bin_copy(GENbin *p)
    1295             : {
    1296             :   GEN x, y, base;
    1297             :   long dx, len;
    1298             : 
    1299    63489604 :   x   = p->x; if (!x) { pari_free(p); return gen_0; }
    1300    63482407 :   len = p->len;
    1301    63482407 :   base= p->base; dx = x - base;
    1302    63482407 :   y = (GEN)memcpy((void*)new_chunk(len), (void*)GENbinbase(p), len*sizeof(long));
    1303    63482291 :   y += dx;
    1304    63482291 :   p->rebase(y, ((ulong)y-(ulong)x));
    1305    63482270 :   pari_free(p); return y;
    1306             : }
    1307             : 
    1308             : INLINE GEN
    1309   126972276 : GENbinbase(GENbin *p) { return (GEN)(p + 1); }
    1310             : 
    1311             : INLINE void
    1312    31940396 : cgiv(GEN x)
    1313             : {
    1314    31940396 :   pari_sp av = (pari_sp)(x+lg(x));
    1315    31940396 :   if (isonstack((GEN)av)) set_avma(av);
    1316    31939818 : }
    1317             : 
    1318             : INLINE void
    1319     1286320 : killblock(GEN x) { gunclone(x); }
    1320             : 
    1321             : INLINE int
    1322    25903131 : is_universal_constant(GEN x) { return (x >= gen_0 && x <= ghalf); }
    1323             : 
    1324             : /*******************************************************************/
    1325             : /*                                                                 */
    1326             : /*                    CONVERSION / ASSIGNMENT                      */
    1327             : /*                                                                 */
    1328             : /*******************************************************************/
    1329             : /* z is a type which may be a t_COMPLEX component (not a t_QUAD) */
    1330             : INLINE GEN
    1331     3422600 : cxcompotor(GEN z, long prec)
    1332             : {
    1333     3422600 :   switch(typ(z))
    1334             :   {
    1335     1867585 :     case t_INT:  return itor(z, prec);
    1336      136234 :     case t_FRAC: return fractor(z, prec);
    1337     1418781 :     case t_REAL: return rtor(z, prec);
    1338           0 :     default: pari_err_TYPE("cxcompotor",z);
    1339             :              return NULL; /* LCOV_EXCL_LINE */
    1340             :   }
    1341             : }
    1342             : INLINE GEN
    1343     1697888 : cxtofp(GEN x, long prec)
    1344     1697888 : { retmkcomplex(cxcompotor(gel(x,1),prec), cxcompotor(gel(x,2),prec)); }
    1345             : 
    1346             : INLINE GEN
    1347      291102 : cxtoreal(GEN q)
    1348      291102 : { return (typ(q) == t_COMPLEX && gequal0(gel(q,2)))? gel(q,1): q; }
    1349             : 
    1350             : INLINE double
    1351    33825061 : gtodouble(GEN x)
    1352             : {
    1353    33825061 :   if (typ(x)!=t_REAL) {
    1354     7447611 :     pari_sp av = avma;
    1355     7447611 :     x = gtofp(x, DEFAULTPREC);
    1356     7447611 :     if (typ(x)!=t_REAL) pari_err_TYPE("gtodouble [t_REAL expected]", x);
    1357     7447611 :     set_avma(av);
    1358             :   }
    1359    33825061 :   return rtodbl(x);
    1360             : }
    1361             : INLINE long
    1362    73376507 : gtos(GEN x) {
    1363    73376507 :   if (typ(x) != t_INT) pari_err_TYPE("gtos [integer expected]",x);
    1364    73376500 :   return itos(x);
    1365             : }
    1366             : 
    1367             : INLINE ulong
    1368      152303 : gtou(GEN x) {
    1369      152303 :   if (typ(x) != t_INT || signe(x)<0)
    1370           0 :     pari_err_TYPE("gtou [integer >=0 expected]",x);
    1371      152313 :   return itou(x);
    1372             : }
    1373             : 
    1374             : INLINE GEN
    1375    23163898 : absfrac(GEN x)
    1376             : {
    1377    23163898 :   GEN y = cgetg(3, t_FRAC);
    1378    23163898 :   gel(y,1) = absi(gel(x,1));
    1379    23163898 :   gel(y,2) = icopy(gel(x,2)); return y;
    1380             : }
    1381             : INLINE GEN
    1382       32658 : absfrac_shallow(GEN x)
    1383       32658 : { return signe(gel(x,1))>0? x: mkfrac(negi(gel(x,1)), gel(x,2)); }
    1384             : INLINE GEN
    1385     7733307 : Q_abs(GEN x) { return (typ(x) == t_INT)? absi(x): absfrac(x); }
    1386             : INLINE GEN
    1387      130744 : Q_abs_shallow(GEN x)
    1388      130744 : { return (typ(x) == t_INT)? absi_shallow(x): absfrac_shallow(x); }
    1389             : INLINE GEN
    1390         322 : R_abs_shallow(GEN x)
    1391         322 : { return (typ(x) == t_FRAC)? absfrac_shallow(x): mpabs_shallow(x); }
    1392             : INLINE GEN
    1393           0 : R_abs(GEN x)
    1394           0 : { return (typ(x) == t_FRAC)? absfrac(x): mpabs(x); }
    1395             : 
    1396             : /* Force z to be of type real/complex with floating point components */
    1397             : INLINE GEN
    1398    35750132 : gtofp(GEN z, long prec)
    1399             : {
    1400    35750132 :   switch(typ(z))
    1401             :   {
    1402    22450256 :     case t_INT:  return itor(z, prec);
    1403     4310668 :     case t_FRAC: return fractor(z, prec);
    1404     7523099 :     case t_REAL: return rtor(z, prec);
    1405             :     case t_COMPLEX: {
    1406     1466109 :       GEN a = gel(z,1), b = gel(z,2);
    1407     1466109 :       if (isintzero(b)) return cxcompotor(a, prec);
    1408     1463593 :       if (isintzero(a)) {
    1409        2114 :         GEN y = cgetg(3, t_COMPLEX);
    1410        2114 :         b = cxcompotor(b, prec);
    1411        2114 :         gel(y,1) = real_0_bit(expo(b) - prec2nbits(prec));
    1412        2114 :         gel(y,2) = b; return y;
    1413             :       }
    1414     1461479 :       return cxtofp(z, prec);
    1415             :     }
    1416           0 :     case t_QUAD: return quadtofp(z, prec);
    1417           0 :     default: pari_err_TYPE("gtofp",z);
    1418             :              return NULL; /* LCOV_EXCL_LINE */
    1419             :   }
    1420             : }
    1421             : /* Force z to be of type real / int */
    1422             : INLINE GEN
    1423       22400 : gtomp(GEN z, long prec)
    1424             : {
    1425       22400 :   switch(typ(z))
    1426             :   {
    1427          14 :     case t_INT:  return z;
    1428       22386 :     case t_FRAC: return fractor(z, prec);
    1429           0 :     case t_REAL: return rtor(z, prec);
    1430           0 :     case t_QUAD: z = quadtofp(z, prec);
    1431           0 :                  if (typ(z) == t_REAL) return z;
    1432           0 :     default: pari_err_TYPE("gtomp",z);
    1433             :              return NULL; /* LCOV_EXCL_LINE */
    1434             :   }
    1435             : }
    1436             : 
    1437             : INLINE GEN
    1438      757234 : RgX_gtofp(GEN x, long prec)
    1439             : {
    1440             :   long l;
    1441      757234 :   GEN y = cgetg_copy(x, &l);
    1442      757234 :   while (--l > 1) gel(y,l) = gtofp(gel(x,l), prec);
    1443      757234 :   y[1] = x[1]; return y;
    1444             : }
    1445             : INLINE GEN
    1446     1192113 : RgC_gtofp(GEN x, long prec)
    1447     1192113 : { pari_APPLY_type(t_COL, gtofp(gel(x,i), prec)) }
    1448             : 
    1449             : INLINE GEN
    1450          42 : RgV_gtofp(GEN x, long prec)
    1451          42 : { pari_APPLY_type(t_VEC, gtofp(gel(x,i), prec)) }
    1452             : 
    1453             : INLINE GEN
    1454      134571 : RgM_gtofp(GEN x, long prec)
    1455      134571 : { pari_APPLY_same(RgC_gtofp(gel(x,i), prec)) }
    1456             : 
    1457             : INLINE GEN
    1458         560 : RgC_gtomp(GEN x, long prec)
    1459         560 : { pari_APPLY_type(t_COL, gtomp(gel(x,i), prec)) }
    1460             : 
    1461             : INLINE GEN
    1462          14 : RgM_gtomp(GEN x, long prec)
    1463          14 : { pari_APPLY_same(RgC_gtomp(gel(x,i), prec)) }
    1464             : 
    1465             : INLINE GEN
    1466        9304 : RgX_fpnorml2(GEN x, long prec)
    1467             : {
    1468        9304 :   pari_sp av = avma;
    1469        9304 :   return gerepileupto(av, gnorml2(RgX_gtofp(x, prec)));
    1470             : }
    1471             : INLINE GEN
    1472      187187 : RgC_fpnorml2(GEN x, long prec)
    1473             : {
    1474      187187 :   pari_sp av = avma;
    1475      187187 :   return gerepileupto(av, gnorml2(RgC_gtofp(x, prec)));
    1476             : }
    1477             : INLINE GEN
    1478        3846 : RgM_fpnorml2(GEN x, long prec)
    1479             : {
    1480        3846 :   pari_sp av = avma;
    1481        3846 :   return gerepileupto(av, gnorml2(RgM_gtofp(x, prec)));
    1482             : }
    1483             : 
    1484             : /* y a t_REAL */
    1485             : INLINE void
    1486      216244 : affgr(GEN x, GEN y)
    1487             : {
    1488             :   pari_sp av;
    1489      216244 :   switch(typ(x)) {
    1490        5992 :     case t_INT:  affir(x,y); break;
    1491      210252 :     case t_REAL: affrr(x,y); break;
    1492           0 :     case t_FRAC: rdiviiz(gel(x,1),gel(x,2), y); break;
    1493           0 :     case t_QUAD: av = avma; affgr(quadtofp(x,realprec(y)), y); set_avma(av); break;
    1494           0 :     default: pari_err_TYPE2("=",x,y);
    1495             :   }
    1496      216244 : }
    1497             : 
    1498             : INLINE GEN
    1499      260887 : affc_fixlg(GEN x, GEN res)
    1500             : {
    1501      260887 :   if (typ(x) == t_COMPLEX)
    1502             :   {
    1503      207515 :     affrr_fixlg(gel(x,1), gel(res,1));
    1504      207515 :     affrr_fixlg(gel(x,2), gel(res,2));
    1505             :   }
    1506             :   else
    1507             :   {
    1508       53372 :     set_avma((pari_sp)(res+3));
    1509       53372 :     res = cgetr(realprec(gel(res,1)));
    1510       53372 :     affrr_fixlg(x, res);
    1511             :   }
    1512      260887 :   return res;
    1513             : }
    1514             : 
    1515             : INLINE GEN
    1516           0 : trunc_safe(GEN x) { long e; return gcvtoi(x,&e); }
    1517             : 
    1518             : /*******************************************************************/
    1519             : /*                                                                 */
    1520             : /*                          LENGTH CONVERSIONS                     */
    1521             : /*                                                                 */
    1522             : /*******************************************************************/
    1523             : INLINE long
    1524       28793 : ndec2nlong(long x) { return 1 + (long)((x)*(LOG2_10/BITS_IN_LONG)); }
    1525             : INLINE long
    1526       20336 : ndec2prec(long x) { return 2 + ndec2nlong(x); }
    1527             : INLINE long
    1528        8457 : ndec2nbits(long x) { return ndec2nlong(x) << TWOPOTBITS_IN_LONG; }
    1529             : /* Fast implementation of ceil(x / (8*sizeof(long))); typecast to (ulong)
    1530             :  * to avoid overflow. Faster than 1 + ((x-1)>>TWOPOTBITS_IN_LONG)) :
    1531             :  *   addl, shrl instead of subl, sarl, addl */
    1532             : INLINE long
    1533     1190948 : nbits2nlong(long x) {
    1534     1190948 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1535             : }
    1536             : 
    1537             : INLINE long
    1538   317253660 : nbits2extraprec(long x) {
    1539   317253660 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1540             : }
    1541             : 
    1542             : /* Fast implementation of 2 + nbits2nlong(x) */
    1543             : INLINE long
    1544   109695768 : nbits2prec(long x) {
    1545   109695768 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1546             : }
    1547             : INLINE long
    1548     7698469 : nbits2lg(long x) {
    1549     7698469 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1550             : }
    1551             : /* ceil(x / sizeof(long)) */
    1552             : INLINE long
    1553     8746994 : nchar2nlong(long x) {
    1554     8746994 :   return (long)(((ulong)x+sizeof(long)-1) >> (TWOPOTBITS_IN_LONG-3L));
    1555             : }
    1556             : INLINE long
    1557  1162996978 : prec2nbits(long x) { return (x-2) * BITS_IN_LONG; }
    1558             : INLINE double
    1559      564469 : bit_accuracy_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1560             : INLINE double
    1561      302019 : prec2nbits_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1562             : INLINE long
    1563    32640826 : bit_prec(GEN x) { return prec2nbits(realprec(x)); }
    1564             : INLINE long
    1565  1049397402 : bit_accuracy(long x) { return prec2nbits(x); }
    1566             : INLINE long
    1567       12399 : prec2ndec(long x) { return (long)prec2nbits_mul(x, LOG10_2); }
    1568             : INLINE long
    1569         193 : nbits2ndec(long x) { return (long)(x * LOG10_2); }
    1570             : INLINE long
    1571        3108 : precdbl(long x) {return (x - 1) << 1;}
    1572             : INLINE long
    1573  3478264647 : divsBIL(long n) { return n >> TWOPOTBITS_IN_LONG; }
    1574             : INLINE long
    1575  3433518568 : remsBIL(long n) { return n & (BITS_IN_LONG-1); }
    1576             : 
    1577             : /*********************************************************************/
    1578             : /**                                                                 **/
    1579             : /**                      OPERATIONS MODULO m                        **/
    1580             : /**                                                                 **/
    1581             : /*********************************************************************/
    1582             : /* Assume m > 0, more efficient if 0 <= a, b < m */
    1583             : 
    1584             : INLINE GEN
    1585    35042505 : Fp_red(GEN a, GEN m) { return modii(a, m); }
    1586             : INLINE GEN
    1587    71731497 : Fp_add(GEN a, GEN b, GEN m)
    1588             : {
    1589    71731497 :   pari_sp av=avma;
    1590    71731497 :   GEN p = addii(a,b);
    1591    70457875 :   long s = signe(p);
    1592    70457875 :   if (!s) return p; /* = gen_0 */
    1593    62850073 :   if (s > 0) /* general case */
    1594             :   {
    1595    62623657 :     GEN t = subii(p, m);
    1596    63567174 :     s = signe(t);
    1597    63567174 :     if (!s) { set_avma(av); return gen_0; }
    1598    57783618 :     if (s < 0) { set_avma((pari_sp)p); return p; }
    1599    24393898 :     if (cmpii(t, m) < 0) return gerepileuptoint(av, t); /* general case ! */
    1600     1112584 :     p = remii(t, m);
    1601             :   }
    1602             :   else
    1603      226416 :     p = modii(p, m);
    1604     1339000 :   return gerepileuptoint(av, p);
    1605             : }
    1606             : INLINE GEN
    1607    56632143 : Fp_sub(GEN a, GEN b, GEN m)
    1608             : {
    1609    56632143 :   pari_sp av=avma;
    1610    56632143 :   GEN p = subii(a,b);
    1611    56225018 :   long s = signe(p);
    1612    56225018 :   if (!s) return p; /* = gen_0 */
    1613    49961976 :   if (s > 0)
    1614             :   {
    1615    24147142 :     if (cmpii(p, m) < 0) return p; /* general case ! */
    1616     1121338 :     p = remii(p, m);
    1617             :   }
    1618             :   else
    1619             :   {
    1620    25814834 :     GEN t = addii(p, m);
    1621    25759792 :     if (!s) { set_avma(av); return gen_0; }
    1622    25759792 :     if (s > 0) return gerepileuptoint(av, t); /* general case ! */
    1623    25759792 :     p = modii(t, m);
    1624             :   }
    1625    27632277 :   return gerepileuptoint(av, p);
    1626             : }
    1627             : INLINE GEN
    1628    13458883 : Fp_neg(GEN b, GEN m)
    1629             : {
    1630    13458883 :   pari_sp av = avma;
    1631    13458883 :   long s = signe(b);
    1632             :   GEN p;
    1633    13458883 :   if (!s) return gen_0;
    1634     9988031 :   if (s > 0)
    1635             :   {
    1636     9766073 :     p = subii(m, b);
    1637     9764126 :     if (signe(p) >= 0) return p; /* general case ! */
    1638      114617 :     p = modii(p, m);
    1639             :   } else
    1640      221958 :     p = remii(negi(b), m);
    1641      336575 :   return gerepileuptoint(av, p);
    1642             : }
    1643             : 
    1644             : INLINE GEN
    1645       23592 : Fp_halve(GEN a, GEN p)
    1646             : {
    1647       23592 :   if (mpodd(a)) a = addii(a,p);
    1648       23592 :   return shifti(a,-1);
    1649             : }
    1650             : 
    1651             : /* assume 0 <= u < p and ps2 = p>>1 */
    1652             : INLINE GEN
    1653    16689613 : Fp_center(GEN u, GEN p, GEN ps2)
    1654    16689613 : { return abscmpii(u,ps2)<=0? icopy(u): subii(u,p); }
    1655             : /* same without copy */
    1656             : INLINE GEN
    1657    15262646 : Fp_center_i(GEN u, GEN p, GEN ps2)
    1658    15262646 : { return abscmpii(u,ps2)<=0? u: subii(u,p); }
    1659             : 
    1660             : /* x + y*z mod p */
    1661             : INLINE GEN
    1662     5063607 : Fp_addmul(GEN x, GEN y, GEN z, GEN p)
    1663             : {
    1664             :   pari_sp av;
    1665     5063607 :   if (!signe(y) || !signe(z)) return Fp_red(x, p);
    1666     4766331 :   if (!signe(x)) return Fp_mul(z,y, p);
    1667     4462885 :   av = avma;
    1668     4462885 :   return gerepileuptoint(av, modii(addii(x, mulii(y,z)), p));
    1669             : }
    1670             : 
    1671             : INLINE GEN
    1672    92042882 : Fp_mul(GEN a, GEN b, GEN m)
    1673             : {
    1674    92042882 :   pari_sp av=avma;
    1675             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1676    92042882 :   (void)new_chunk(lg(a)+lg(b)+(lg(m)<<1));
    1677    92046518 :   p = mulii(a,b);
    1678    92195967 :   set_avma(av); return modii(p,m);
    1679             : }
    1680             : INLINE GEN
    1681    33524688 : Fp_sqr(GEN a, GEN m)
    1682             : {
    1683    33524688 :   pari_sp av=avma;
    1684             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1685    33524688 :   (void)new_chunk((lg(a)+lg(m))<<1);
    1686    33551381 :   p = sqri(a);
    1687    30737889 :   set_avma(av); return remii(p,m); /*Use remii: p >= 0 */
    1688             : }
    1689             : INLINE GEN
    1690    64689291 : Fp_mulu(GEN a, ulong b, GEN m)
    1691             : {
    1692    64689291 :   long l = lgefint(m);
    1693    64689291 :   if (l == 3)
    1694             :   {
    1695    38795981 :     ulong mm = m[2];
    1696    38795981 :     return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1697             :   } else {
    1698    25893310 :     pari_sp av = avma;
    1699             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1700    25893310 :     (void)new_chunk(lg(a)+1+(l<<1));
    1701    25941588 :     p = muliu(a,b);
    1702    24466085 :     set_avma(av); return modii(p,m);
    1703             :   }
    1704             : }
    1705             : INLINE GEN
    1706           0 : Fp_muls(GEN a, long b, GEN m)
    1707             : {
    1708           0 :   long l = lgefint(m);
    1709           0 :   if (l == 3)
    1710             :   {
    1711           0 :     ulong mm = m[2];
    1712           0 :     if (b < 0)
    1713             :     {
    1714           0 :       ulong t = Fl_mul(umodiu(a, mm), -b, mm);
    1715           0 :       return t? utoipos(mm - t): gen_0;
    1716             :     }
    1717             :     else
    1718           0 :       return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1719             :   } else {
    1720           0 :     pari_sp av = avma;
    1721             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1722           0 :     (void)new_chunk(lg(a)+1+(l<<1));
    1723           0 :     p = mulis(a,b);
    1724           0 :     set_avma(av); return modii(p,m);
    1725             :   }
    1726             : }
    1727             : 
    1728             : INLINE GEN
    1729    10972867 : Fp_inv(GEN a, GEN m)
    1730             : {
    1731             :   GEN res;
    1732    10972867 :   if (! invmod(a,m,&res)) pari_err_INV("Fp_inv", mkintmod(res,m));
    1733    10972540 :   return res;
    1734             : }
    1735             : INLINE GEN
    1736      315415 : Fp_invsafe(GEN a, GEN m)
    1737             : {
    1738             :   GEN res;
    1739      315415 :   if (! invmod(a,m,&res)) return NULL;
    1740      315415 :   return res;
    1741             : }
    1742             : INLINE GEN
    1743     2367113 : Fp_div(GEN a, GEN b, GEN m)
    1744             : {
    1745     2367113 :   pari_sp av=avma;
    1746             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1747     2367113 :   (void)new_chunk(lg(a)+(lg(m)<<1));
    1748     2367113 :   p = mulii(a, Fp_inv(b,m));
    1749     2367110 :   set_avma(av); return modii(p,m);
    1750             : }
    1751             : 
    1752             : INLINE GEN
    1753      847298 : Flx_mulu(GEN x, ulong a, ulong p) { return Flx_Fl_mul(x,a%p,p); }
    1754             : 
    1755             : INLINE GEN
    1756           0 : get_F2x_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1757             : 
    1758             : INLINE long
    1759      448517 : get_F2x_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1760             : 
    1761             : INLINE long
    1762      121548 : get_F2x_degree(GEN T) { return typ(T)==t_VEC? F2x_degree(gel(T,2)): F2x_degree(T); }
    1763             : 
    1764             : INLINE GEN
    1765         378 : get_F2xqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1766             : 
    1767             : INLINE long
    1768      376495 : get_F2xqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1769             : 
    1770             : INLINE long
    1771      201684 : get_F2xqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1772             : 
    1773             : INLINE GEN
    1774     7571148 : get_Flx_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1775             : 
    1776             : INLINE long
    1777    16813533 : get_Flx_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1778             : 
    1779             : INLINE long
    1780    35937010 : get_Flx_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1781             : 
    1782             : INLINE GEN
    1783        2461 : get_FlxqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1784             : 
    1785             : INLINE long
    1786      368931 : get_FlxqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1787             : 
    1788             : INLINE long
    1789      155787 : get_FlxqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1790             : 
    1791             : INLINE GEN
    1792     1614100 : get_FpX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1793             : 
    1794             : INLINE long
    1795     2918202 : get_FpX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1796             : 
    1797             : INLINE long
    1798     1891848 : get_FpX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1799             : 
    1800             : INLINE GEN
    1801      142586 : get_FpXQX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1802             : 
    1803             : INLINE long
    1804       57357 : get_FpXQX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1805             : 
    1806             : INLINE long
    1807        2187 : get_FpXQX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1808             : 
    1809             : /*******************************************************************/
    1810             : /*                                                                 */
    1811             : /*                        ADDMULII / SUBMULII                      */
    1812             : /*                                                                 */
    1813             : /*******************************************************************/
    1814             : /* x - y*z */
    1815             : INLINE GEN
    1816    13447814 : submulii(GEN x, GEN y, GEN z)
    1817             : {
    1818    13447814 :   long lx = lgefint(x), ly, lz;
    1819             :   pari_sp av;
    1820             :   GEN t;
    1821    13447814 :   if (lx == 2) { t = mulii(z,y); togglesign(t); return t; }
    1822    11634755 :   ly = lgefint(y);
    1823    11634755 :   if (ly == 2) return icopy(x);
    1824    10498508 :   lz = lgefint(z);
    1825    10498508 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1826    10498508 :   t = mulii(z, y);
    1827    10498508 :   set_avma(av); return subii(x,t);
    1828             : }
    1829             : /* y*z - x */
    1830             : INLINE GEN
    1831     1238672 : mulsubii(GEN y, GEN z, GEN x)
    1832             : {
    1833     1238672 :   long lx = lgefint(x), ly, lz;
    1834             :   pari_sp av;
    1835             :   GEN t;
    1836     1238672 :   if (lx == 2) return mulii(z,y);
    1837      788797 :   ly = lgefint(y);
    1838      788797 :   if (ly == 2) return negi(x);
    1839      723511 :   lz = lgefint(z);
    1840      723511 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1841      723511 :   t = mulii(z, y);
    1842      723511 :   set_avma(av); return subii(t,x);
    1843             : }
    1844             : 
    1845             : /* x - u*y */
    1846             : INLINE GEN
    1847        7595 : submuliu(GEN x, GEN y, ulong u)
    1848             : {
    1849             :   pari_sp av;
    1850        7595 :   long ly = lgefint(y);
    1851        7595 :   if (ly == 2) return icopy(x);
    1852        7595 :   av = avma;
    1853        7595 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1854        7595 :   y = mului(u,y);
    1855        7595 :   set_avma(av); return subii(x, y);
    1856             : }
    1857             : /* x + u*y */
    1858             : INLINE GEN
    1859        7595 : addmuliu(GEN x, GEN y, ulong u)
    1860             : {
    1861             :   pari_sp av;
    1862        7595 :   long ly = lgefint(y);
    1863        7595 :   if (ly == 2) return icopy(x);
    1864        7595 :   av = avma;
    1865        7595 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1866        7595 :   y = mului(u,y);
    1867        7595 :   set_avma(av); return addii(x, y);
    1868             : }
    1869             : /* x - u*y */
    1870             : INLINE GEN
    1871   122920241 : submuliu_inplace(GEN x, GEN y, ulong u)
    1872             : {
    1873             :   pari_sp av;
    1874   122920241 :   long ly = lgefint(y);
    1875   122920241 :   if (ly == 2) return x;
    1876    98460711 :   av = avma;
    1877    98460711 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1878    98460711 :   y = mului(u,y);
    1879    98460711 :   set_avma(av); return subii(x, y);
    1880             : }
    1881             : /* x + u*y */
    1882             : INLINE GEN
    1883   121400177 : addmuliu_inplace(GEN x, GEN y, ulong u)
    1884             : {
    1885             :   pari_sp av;
    1886   121400177 :   long ly = lgefint(y);
    1887   121400177 :   if (ly == 2) return x;
    1888    98345046 :   av = avma;
    1889    98345046 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1890    98345046 :   y = mului(u,y);
    1891    98345046 :   set_avma(av); return addii(x, y);
    1892             : }
    1893             : /* ux + vy */
    1894             : INLINE GEN
    1895    20674200 : lincombii(GEN u, GEN v, GEN x, GEN y)
    1896             : {
    1897    20674200 :   long lx = lgefint(x), ly;
    1898             :   GEN p1, p2;
    1899             :   pari_sp av;
    1900    20674200 :   if (lx == 2) return mulii(v,y);
    1901    14585905 :   ly = lgefint(y);
    1902    14585905 :   if (ly == 2) return mulii(u,x);
    1903    13360667 :   av = avma; (void)new_chunk(lx+ly+lgefint(u)+lgefint(v)); /* HACK */
    1904    13360669 :   p1 = mulii(u,x);
    1905    13360571 :   p2 = mulii(v,y);
    1906    13360564 :   set_avma(av); return addii(p1,p2);
    1907             : }
    1908             : 
    1909             : /*******************************************************************/
    1910             : /*                                                                 */
    1911             : /*                          GEN SUBTYPES                           */
    1912             : /*                                                                 */
    1913             : /*******************************************************************/
    1914             : 
    1915             : INLINE int
    1916  1254970307 : is_const_t(long t) { return (t < t_POLMOD); }
    1917             : INLINE int
    1918        5437 : is_extscalar_t(long t) { return (t <= t_POL); }
    1919             : INLINE int
    1920     1224255 : is_intreal_t(long t) { return (t <= t_REAL); }
    1921             : INLINE int
    1922   423245398 : is_matvec_t(long t) { return (t >= t_VEC && t <= t_MAT); }
    1923             : INLINE int
    1924    60302785 : is_noncalc_t(long tx) { return (tx) >= t_LIST; }
    1925             : INLINE int
    1926     1206174 : is_rational_t(long t) { return (t == t_INT || t == t_FRAC); }
    1927             : INLINE int
    1928      504331 : is_real_t(long t) { return (t == t_INT || t == t_REAL || t == t_FRAC); }
    1929             : INLINE int
    1930  3056939267 : is_recursive_t(long t) { return lontyp[t]; }
    1931             : INLINE int
    1932   197150484 : is_scalar_t(long t) { return (t < t_POL); }
    1933             : INLINE int
    1934     1499382 : is_vec_t(long t) { return (t == t_VEC || t == t_COL); }
    1935             : 
    1936             : /*******************************************************************/
    1937             : /*                                                                 */
    1938             : /*                         TRANSCENDENTAL                          */
    1939             : /*                                                                 */
    1940             : /*******************************************************************/
    1941             : INLINE GEN
    1942    22376861 : sqrtr(GEN x) {
    1943    22376861 :   long s = signe(x);
    1944    22376861 :   if (s == 0) return real_0_bit(expo(x) >> 1);
    1945    22343194 :   if (s >= 0) return sqrtr_abs(x);
    1946       34597 :   retmkcomplex(gen_0, sqrtr_abs(x));
    1947             : }
    1948             : INLINE GEN
    1949           0 : cbrtr_abs(GEN x) { return sqrtnr_abs(x, 3); }
    1950             : INLINE GEN
    1951           0 : cbrtr(GEN x) {
    1952           0 :   long s = signe(x);
    1953             :   GEN r;
    1954           0 :   if (s == 0) return real_0_bit(expo(x) / 3);
    1955           0 :   r = cbrtr_abs(x);
    1956           0 :   if (s < 0) togglesign(r);
    1957           0 :   return r;
    1958             : }
    1959             : INLINE GEN
    1960      462351 : sqrtnr(GEN x, long n) {
    1961      462351 :   long s = signe(x);
    1962             :   GEN r;
    1963      462351 :   if (s == 0) return real_0_bit(expo(x) / n);
    1964      462351 :   r = sqrtnr_abs(x, n);
    1965      462351 :   if (s < 0) pari_err_IMPL("sqrtnr for x < 0");
    1966      462351 :   return r;
    1967             : }
    1968             : INLINE long
    1969      221034 : logint(GEN B, GEN y) { return logintall(B,y,NULL); }
    1970             : INLINE ulong
    1971     1997441 : ulogint(ulong B, ulong y)
    1972             : {
    1973             :   ulong r;
    1974             :   long e;
    1975     1997441 :   if (y == 2) return expu(B);
    1976     1979339 :   r = y;
    1977     6389368 :   for (e=1;; e++)
    1978             :   { /* here, r = y^e, r2 = y^(e-1) */
    1979    10799397 :     if (r >= B) return r == B? e: e-1;
    1980     4410036 :     r = umuluu_or_0(y, r);
    1981     4410029 :     if (!r) return e;
    1982             :   }
    1983             : }
    1984             : 
    1985             : /*******************************************************************/
    1986             : /*                                                                 */
    1987             : /*                         MISCELLANEOUS                           */
    1988             : /*                                                                 */
    1989             : /*******************************************************************/
    1990     1224178 : INLINE int ismpzero(GEN x) { return is_intreal_t(typ(x)) && !signe(x); }
    1991   657604590 : INLINE int isintzero(GEN x) { return typ(x) == t_INT && !signe(x); }
    1992     9112743 : INLINE int isint1(GEN x) { return typ(x)==t_INT && equali1(x); }
    1993        4641 : INLINE int isintm1(GEN x){ return typ(x)==t_INT && equalim1(x);}
    1994   713498396 : INLINE int equali1(GEN n)
    1995   713498396 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(1)) && n[2] == 1; }
    1996    61421475 : INLINE int equalim1(GEN n)
    1997    61421475 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(-1)) && n[2] == 1; }
    1998             : /* works only for POSITIVE integers */
    1999   970439222 : INLINE int is_pm1(GEN n)
    2000   970439222 : { return lgefint(n) == 3 && n[2] == 1; }
    2001   241615551 : INLINE int is_bigint(GEN n)
    2002   241615551 : { long l = lgefint(n); return l > 3 || (l == 3 && (n[2] & HIGHBIT)); }
    2003             : 
    2004  2069730321 : INLINE int odd(long x) { return x & 1; }
    2005    28858171 : INLINE int both_odd(long x, long y) { return x & y & 1; }
    2006             : 
    2007             : INLINE int
    2008  2768396167 : isonstack(GEN x)
    2009  2768396167 : { return ((pari_sp)x >= pari_mainstack->bot
    2010  2768396167 :        && (pari_sp)x <  pari_mainstack->top); }
    2011             : 
    2012             : /* assume x != 0 and x t_REAL, return an approximation to log2(|x|) */
    2013             : INLINE double
    2014    23270947 : dbllog2r(GEN x)
    2015    23270947 : { return log2((double)(ulong)x[2]) + (double)(expo(x) - (BITS_IN_LONG-1)); }
    2016             : 
    2017             : INLINE GEN
    2018      362897 : mul_content(GEN cx, GEN cy)
    2019             : {
    2020      362897 :   if (!cx) return cy;
    2021      132999 :   if (!cy) return cx;
    2022       91485 :   return gmul(cx,cy);
    2023             : }
    2024             : INLINE GEN
    2025        6034 : inv_content(GEN c) { return c? ginv(c): NULL; }
    2026             : INLINE GEN
    2027     1627337 : mul_denom(GEN dx, GEN dy)
    2028             : {
    2029     1627337 :   if (!dx) return dy;
    2030     1074042 :   if (!dy) return dx;
    2031      338492 :   return mulii(dx,dy);
    2032             : }
    2033             : 
    2034             : /* POLYNOMIALS */
    2035             : INLINE GEN
    2036    17947377 : constant_coeff(GEN x) { return signe(x)? gel(x,2): gen_0; }
    2037             : INLINE GEN
    2038    81760353 : leading_coeff(GEN x) { return lg(x) == 2? gen_0: gel(x,lg(x)-1); }
    2039             : INLINE ulong
    2040      479520 : Flx_lead(GEN x) { return lg(x) == 2? 0: x[lg(x)-1]; }
    2041             : INLINE ulong
    2042       12298 : Flx_constant(GEN x) { return lg(x) == 2? 0: x[2]; }
    2043             : INLINE long
    2044  2805402346 : degpol(GEN x) { return lg(x)-3; }
    2045             : INLINE long
    2046  1388440996 : lgpol(GEN x) { return lg(x)-2; }
    2047             : INLINE long
    2048   122833823 : lgcols(GEN x) { return lg(gel(x,1)); }
    2049             : INLINE long
    2050    34540447 : nbrows(GEN x) { return lg(gel(x,1))-1; }
    2051             : INLINE GEN
    2052           0 : truecoef(GEN x, long n) { return polcoef(x,n,-1); }
    2053             : 
    2054             : INLINE GEN
    2055      557581 : ZXQ_mul(GEN y, GEN x, GEN T) { return ZX_rem(ZX_mul(y, x), T); }
    2056             : INLINE GEN
    2057      281752 : ZXQ_sqr(GEN x, GEN T) { return ZX_rem(ZX_sqr(x), T); }
    2058             : 
    2059             : INLINE GEN
    2060    81498010 : RgX_copy(GEN x)
    2061             : {
    2062             :   long lx, i;
    2063    81498010 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
    2064    81498008 :   for (i = 2; i<lx; i++) gel(y,i) = gcopy(gel(x,i));
    2065    81498015 :   return y;
    2066             : }
    2067             : /* have to use ulong to avoid silly warnings from gcc "assuming signed
    2068             :  * overflow does not occur" */
    2069             : INLINE GEN
    2070     2961743 : RgX_coeff(GEN x, long n)
    2071             : {
    2072     2961743 :   ulong l = lg(x);
    2073     2961743 :   return (n < 0 || ((ulong)n+3) > l)? gen_0: gel(x,n+2);
    2074             : }
    2075             : INLINE GEN
    2076      368654 : RgX_renormalize(GEN x) { return RgX_renormalize_lg(x, lg(x)); }
    2077             : INLINE GEN
    2078     6743898 : RgX_div(GEN x, GEN y) { return RgX_divrem(x,y,NULL); }
    2079             : INLINE GEN
    2080        1792 : RgXQX_div(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,NULL); }
    2081             : INLINE GEN
    2082       67619 : RgXQX_rem(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,ONLY_REM); }
    2083             : INLINE GEN
    2084      947693 : FpX_div(GEN x, GEN y, GEN p) { return FpX_divrem(x,y,p, NULL); }
    2085             : INLINE GEN
    2086     4486842 : Flx_div(GEN x, GEN y, ulong p) { return Flx_divrem(x,y,p, NULL); }
    2087             : INLINE GEN
    2088     2608052 : F2x_div(GEN x, GEN y) { return F2x_divrem(x,y, NULL); }
    2089             : INLINE GEN
    2090           0 : FpV_FpC_mul(GEN x, GEN y, GEN p) { return FpV_dotproduct(x,y,p); }
    2091             : INLINE GEN
    2092    48498087 : pol0_Flx(long sv) { return mkvecsmall(sv); }
    2093             : INLINE GEN
    2094    15094564 : pol1_Flx(long sv) { return mkvecsmall2(sv, 1); }
    2095             : INLINE GEN
    2096    17831321 : polx_Flx(long sv) { return mkvecsmall3(sv, 0, 1); }
    2097             : INLINE GEN
    2098           0 : zero_zx(long sv) { return zero_Flx(sv); }
    2099             : INLINE GEN
    2100           0 : polx_zx(long sv) { return polx_Flx(sv); }
    2101             : INLINE GEN
    2102           0 : zx_shift(GEN x, long n) { return Flx_shift(x,n); }
    2103             : INLINE GEN
    2104           0 : zx_renormalize(GEN x, long l) { return Flx_renormalize(x,l); }
    2105             : INLINE GEN
    2106        1474 : zero_F2x(long sv) { return zero_Flx(sv); }
    2107             : INLINE GEN
    2108    11169563 : pol0_F2x(long sv) { return pol0_Flx(sv); }
    2109             : INLINE GEN
    2110     2874681 : pol1_F2x(long sv) { return pol1_Flx(sv); }
    2111             : INLINE GEN
    2112      687301 : polx_F2x(long sv) { return mkvecsmall2(sv, 2); }
    2113             : INLINE int
    2114      826227 : F2x_equal1(GEN x) { return Flx_equal1(x); }
    2115             : INLINE int
    2116     3135431 : F2x_equal(GEN V, GEN W) { return Flx_equal(V,W); }
    2117             : INLINE GEN
    2118    59355348 : F2x_copy(GEN x) { return leafcopy(x); }
    2119             : INLINE GEN
    2120           0 : F2v_copy(GEN x) { return leafcopy(x); }
    2121             : INLINE GEN
    2122     2274954 : Flv_copy(GEN x) { return leafcopy(x); }
    2123             : INLINE GEN
    2124    74530475 : Flx_copy(GEN x) { return leafcopy(x); }
    2125             : INLINE GEN
    2126     1871354 : vecsmall_copy(GEN x) { return leafcopy(x); }
    2127             : INLINE int
    2128     4887966 : Flx_equal1(GEN x) { return degpol(x)==0 && x[2] == 1; }
    2129             : INLINE int
    2130       18205 : ZX_equal1(GEN x) { return degpol(x)==0 && equali1(gel(x,2)); }
    2131             : INLINE int
    2132     5435578 : ZX_is_monic(GEN x) { return equali1(leading_coeff(x)); }
    2133             : 
    2134             : INLINE GEN
    2135    51035752 : ZX_renormalize(GEN x, long lx)    { return ZXX_renormalize(x,lx); }
    2136             : INLINE GEN
    2137    67479958 : FpX_renormalize(GEN x, long lx)   { return ZXX_renormalize(x,lx); }
    2138             : INLINE GEN
    2139      771564 : FpXX_renormalize(GEN x, long lx)  { return ZXX_renormalize(x,lx); }
    2140             : INLINE GEN
    2141     1249023 : FpXQX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
    2142             : INLINE GEN
    2143   111654665 : F2x_renormalize(GEN x, long lx)   { return Flx_renormalize(x,lx); }
    2144             : INLINE GEN
    2145       32321 : F2v_to_F2x(GEN x, long sv) {
    2146       32321 :   GEN y = leafcopy(x);
    2147       32321 :   y[1] = sv; F2x_renormalize(y, lg(y)); return y;
    2148             : }
    2149             : 
    2150             : INLINE long
    2151           0 : sturm(GEN x) { return sturmpart(x, NULL, NULL); }
    2152             : 
    2153             : INLINE long
    2154        7042 : gval(GEN x, long v) {
    2155        7042 :   pari_sp av = avma;
    2156        7042 :   long n = gvaluation(x, pol_x(v));
    2157        7042 :   set_avma(av); return n;
    2158             : }
    2159             : 
    2160             : INLINE void
    2161      470874 : RgX_shift_inplace_init(long v)
    2162      470874 : { if (v) (void)cgetg(v, t_VECSMALL); }
    2163             : /* shift polynomial in place. assume v free cells have been left before x */
    2164             : INLINE GEN
    2165      470874 : RgX_shift_inplace(GEN x, long v)
    2166             : {
    2167             :   long i, lx;
    2168             :   GEN y, z;
    2169      470874 :   if (!v) return x;
    2170      253227 :   lx = lg(x);
    2171      253227 :   if (lx == 2) return x;
    2172      253227 :   y = x + v;
    2173      253227 :   z = x + lx;
    2174             :   /* stackdummy from normalizepol: move it up */
    2175      253227 :   if (lg(z) != v) x[lx + v] = z[0];
    2176      253227 :   for (i = lx-1; i >= 2; i--) gel(y,i) = gel(x,i);
    2177      253227 :   for (i = v+1;  i >= 2; i--) gel(x,i) = gen_0;
    2178             :   /* leave x[1] alone: it is correct */
    2179      253227 :   x[0] = evaltyp(t_POL) | evallg(lx+v); return x;
    2180             : }
    2181             : 
    2182             : 
    2183             : /* LINEAR ALGEBRA */
    2184             : INLINE GEN
    2185      131966 : zv_to_ZV(GEN x) { return vecsmall_to_vec(x); }
    2186             : INLINE GEN
    2187     5208100 : zc_to_ZC(GEN x) { return vecsmall_to_col(x); }
    2188             : INLINE GEN
    2189     3343009 : ZV_to_zv(GEN x) { return vec_to_vecsmall(x); }
    2190             : INLINE GEN
    2191           0 : zx_to_zv(GEN x, long N) { return Flx_to_Flv(x,N); }
    2192             : INLINE GEN
    2193           0 : zv_to_zx(GEN x, long sv) { return Flv_to_Flx(x,sv); }
    2194             : INLINE GEN
    2195           0 : zm_to_zxV(GEN x, long sv) { return Flm_to_FlxV(x,sv); }
    2196             : INLINE GEN
    2197           0 : zero_zm(long x, long y) { return zero_Flm(x,y); }
    2198             : INLINE GEN
    2199    17404991 : zero_zv(long x) { return zero_Flv(x); }
    2200             : INLINE GEN
    2201         210 : zm_transpose(GEN x) { return Flm_transpose(x); }
    2202             : INLINE GEN
    2203           0 : zm_copy(GEN x) { return Flm_copy(x); }
    2204             : INLINE GEN
    2205     1903177 : zv_copy(GEN x) { return Flv_copy(x); }
    2206             : INLINE GEN
    2207           0 : zm_row(GEN x, long i) { return Flm_row(x,i); }
    2208             : 
    2209             : INLINE GEN
    2210      901843 : ZC_hnfrem(GEN x, GEN y) { return ZC_hnfremdiv(x,y,NULL); }
    2211             : INLINE GEN
    2212       48866 : ZM_hnfrem(GEN x, GEN y) { return ZM_hnfdivrem(x,y,NULL); }
    2213             : INLINE GEN
    2214     2438929 : ZM_lll(GEN x, double D, long f) { return ZM_lll_norms(x,D,f,NULL); }
    2215             : INLINE void
    2216     5673623 : RgM_dimensions(GEN x, long *m, long *n) { *n = lg(x)-1; *m = *n? nbrows(x): 0; }
    2217             : INLINE GEN
    2218    10336894 : RgM_shallowcopy(GEN x)
    2219             : {
    2220             :   long l;
    2221    10336894 :   GEN y = cgetg_copy(x, &l);
    2222    10336907 :   while (--l > 0) gel(y,l) = leafcopy(gel(x,l));
    2223    10336908 :   return y;
    2224             : }
    2225             : INLINE GEN
    2226         303 : F2m_copy(GEN x) { return RgM_shallowcopy(x); }
    2227             : 
    2228             : INLINE GEN
    2229     1375002 : Flm_copy(GEN x) { return RgM_shallowcopy(x); }
    2230             : 
    2231             : /* divisibility: return 1 if y[i] | x[i] for all i, 0 otherwise. Assume
    2232             :  * x,y are ZV of the same length */
    2233             : INLINE int
    2234       23198 : ZV_dvd(GEN x, GEN y)
    2235             : {
    2236       23198 :   long i, l = lg(x);
    2237       36652 :   for (i=1; i < l; i++)
    2238       29519 :     if ( ! dvdii( gel(x,i), gel(y,i) ) ) return 0;
    2239        7133 :   return 1;
    2240             : }
    2241             : 
    2242             : /* Fq */
    2243             : INLINE GEN
    2244     2802247 : Fq_red(GEN x, GEN T, GEN p)
    2245     2802247 : { return typ(x)==t_INT? Fp_red(x,p): FpXQ_red(x,T,p); }
    2246             : INLINE GEN
    2247       43439 : Fq_to_FpXQ(GEN x, GEN T, GEN p /*unused*/)
    2248             : {
    2249             :   (void) p;
    2250       43439 :   return typ(x)==t_INT ? scalarpol(x, get_FpX_var(T)): x;
    2251             : }
    2252             : INLINE GEN
    2253         756 : Rg_to_Fq(GEN x, GEN T, GEN p) { return T? Rg_to_FpXQ(x,T,p): Rg_to_Fp(x,p); }
    2254             : 
    2255             : INLINE GEN
    2256        1253 : gener_Fq_local(GEN T, GEN p, GEN L)
    2257             : { return T? gener_FpXQ_local(T,p, L)
    2258        1253 :           : pgener_Fp_local(p, L); }
    2259             : 
    2260             : /* FpXQX */
    2261             : INLINE GEN
    2262        4347 : FpXQX_div(GEN x, GEN y, GEN T, GEN p) { return FpXQX_divrem(x, y, T, p, NULL); }
    2263             : INLINE GEN
    2264       35055 : FlxqX_div(GEN x, GEN y, GEN T, ulong p) { return FlxqX_divrem(x, y, T, p, NULL); }
    2265             : INLINE GEN
    2266       33278 : F2xqX_div(GEN x, GEN y, GEN T) { return F2xqX_divrem(x, y, T, NULL); }
    2267             : 
    2268             : /* FqX */
    2269             : INLINE GEN
    2270       25431 : FqX_red(GEN z, GEN T, GEN p) { return T? FpXQX_red(z, T, p): FpX_red(z, p); }
    2271             : INLINE GEN
    2272      957187 : FqX_add(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2273             : INLINE GEN
    2274       17404 : FqX_neg(GEN x,GEN T,GEN p) { return T? FpXX_neg(x,p): FpX_neg(x,p); }
    2275             : INLINE GEN
    2276        3234 : FqX_sub(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2277             : INLINE GEN
    2278      657480 : FqX_Fp_mul(GEN P, GEN u, GEN T, GEN p)
    2279      657480 : { return T? FpXX_Fp_mul(P, u, p): FpX_Fp_mul(P, u, p); }
    2280             : INLINE GEN
    2281      588211 : FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p)
    2282      588211 : { return typ(U)==t_INT ? FqX_Fp_mul(P, U, T, p): FpXQX_FpXQ_mul(P, U, T, p); }
    2283             : INLINE GEN
    2284       96748 : FqX_mul(GEN x, GEN y, GEN T, GEN p)
    2285       96748 : { return T? FpXQX_mul(x, y, T, p): FpX_mul(x, y, p); }
    2286             : INLINE GEN
    2287      489744 : FqX_mulu(GEN x, ulong y, GEN T, GEN p)
    2288      489744 : { return T? FpXX_mulu(x, y, p): FpX_mulu(x, y, p); }
    2289             : INLINE GEN
    2290        6468 : FqX_sqr(GEN x, GEN T, GEN p)
    2291        6468 : { return T? FpXQX_sqr(x, T, p): FpX_sqr(x, p); }
    2292             : INLINE GEN
    2293        1288 : FqX_powu(GEN x, ulong n, GEN T, GEN p)
    2294        1288 : { return T? FpXQX_powu(x, n, T, p): FpX_powu(x, n, p); }
    2295             : INLINE GEN
    2296           0 : FqX_halve(GEN x, GEN T, GEN p)
    2297           0 : { return T? FpXX_halve(x, p): FpX_halve(x, p); }
    2298             : INLINE GEN
    2299        5586 : FqX_div(GEN x, GEN y, GEN T, GEN p)
    2300        5586 : { return T? FpXQX_divrem(x,y,T,p,NULL): FpX_divrem(x,y,p,NULL); }
    2301             : INLINE GEN
    2302        6095 : FqX_get_red(GEN S, GEN T, GEN p)
    2303        6095 : { return T? FpXQX_get_red(S,T,p): FpX_get_red(S,p); }
    2304             : INLINE GEN
    2305       53108 : FqX_rem(GEN x, GEN y, GEN T, GEN p)
    2306       53108 : { return T? FpXQX_rem(x,y,T,p): FpX_rem(x,y,p); }
    2307             : INLINE GEN
    2308           0 : FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2309           0 : { return T? FpXQX_divrem(x,y,T,p,z): FpX_divrem(x,y,p,z); }
    2310             : INLINE GEN
    2311        5936 : FqX_div_by_X_x(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2312        5936 : { return T? FpXQX_div_by_X_x(x,y,T,p,z): FpX_div_by_X_x(x,y,p,z); }
    2313             : INLINE GEN
    2314           0 : FqX_halfgcd(GEN P,GEN Q,GEN T,GEN p)
    2315           0 : {return T? FpXQX_halfgcd(P,Q,T,p): FpX_halfgcd(P,Q,p);}
    2316             : INLINE GEN
    2317      259224 : FqX_gcd(GEN P,GEN Q,GEN T,GEN p)
    2318      259224 : {return T? FpXQX_gcd(P,Q,T,p): FpX_gcd(P,Q,p);}
    2319             : INLINE GEN
    2320       88128 : FqX_extgcd(GEN P,GEN Q,GEN T,GEN p, GEN *U, GEN *V)
    2321       88128 : { return T? FpXQX_extgcd(P,Q,T,p,U,V): FpX_extgcd(P,Q,p,U,V); }
    2322             : INLINE GEN
    2323        3241 : FqX_normalize(GEN z, GEN T, GEN p)
    2324        3241 : { return T? FpXQX_normalize(z, T, p): FpX_normalize(z, p); }
    2325             : INLINE GEN
    2326      272895 : FqX_deriv(GEN f, GEN T, GEN p) { return T? FpXX_deriv(f, p): FpX_deriv(f, p); }
    2327             : INLINE GEN
    2328           0 : FqX_integ(GEN f, GEN T, GEN p) { return T? FpXX_integ(f, p): FpX_integ(f, p); }
    2329             : INLINE GEN
    2330       74536 : FqX_factor(GEN f, GEN T, GEN p)
    2331       74536 : { return T?FpXQX_factor(f, T, p): FpX_factor(f, p); }
    2332             : INLINE GEN
    2333           7 : FqX_factor_squarefree(GEN f, GEN T, GEN p)
    2334           7 : { return T ? FpXQX_factor_squarefree(f, T, p): FpX_factor_squarefree(f, p); }
    2335             : INLINE GEN
    2336           7 : FqX_ddf(GEN f, GEN T, GEN p)
    2337           7 : { return T ? FpXQX_ddf(f, T, p): FpX_ddf(f, p); }
    2338             : INLINE GEN
    2339          42 : FqX_degfact(GEN f, GEN T, GEN p)
    2340          42 : { return T?FpXQX_degfact(f, T, p): FpX_degfact(f, p); }
    2341             : INLINE GEN
    2342        7126 : FqX_roots(GEN f, GEN T, GEN p)
    2343        7126 : { return T?FpXQX_roots(f, T, p): FpX_roots(f, p); }
    2344             : INLINE GEN
    2345         203 : FqX_to_mod(GEN f, GEN T, GEN p)
    2346         203 : { return T?FpXQX_to_mod(f, T, p): FpX_to_mod(f, p); }
    2347             : 
    2348             : /*FqXQ*/
    2349             : INLINE GEN
    2350           0 : FqXQ_add(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2351           0 : { (void)S; return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2352             : INLINE GEN
    2353           0 : FqXQ_sub(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2354           0 : { (void)S; return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2355             : INLINE GEN
    2356           0 : FqXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p)
    2357           0 : { return T? FpXQXQ_div(x,y,S,T,p): FpXQ_div(x,y,S,p); }
    2358             : INLINE GEN
    2359           0 : FqXQ_inv(GEN x, GEN S, GEN T, GEN p)
    2360           0 : { return T? FpXQXQ_inv(x,S,T,p): FpXQ_inv(x,S,p); }
    2361             : INLINE GEN
    2362           0 : FqXQ_invsafe(GEN x, GEN S, GEN T, GEN p)
    2363           0 : { return T? FpXQXQ_invsafe(x,S,T,p): FpXQ_inv(x,S,p); }
    2364             : INLINE GEN
    2365       22348 : FqXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p)
    2366       22348 : { return T? FpXQXQ_mul(x,y,S,T,p): FpXQ_mul(x,y,S,p); }
    2367             : INLINE GEN
    2368           0 : FqXQ_sqr(GEN x, GEN S, GEN T, GEN p)
    2369           0 : { return T? FpXQXQ_sqr(x,S,T,p): FpXQ_sqr(x,S,p); }
    2370             : INLINE GEN
    2371           0 : FqXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p)
    2372           0 : { return T? FpXQXQ_pow(x,n,S,T,p): FpXQ_pow(x,n,S,p); }
    2373             : 
    2374             : /*FqXn*/
    2375             : INLINE GEN
    2376           0 : FqXn_exp(GEN x, long n, GEN T, GEN p)
    2377           0 : { return T? FpXQXn_exp(x,n,T,p): FpXn_exp(x,n,p); }
    2378             : INLINE GEN
    2379           0 : FqXn_inv(GEN x, long n, GEN T, GEN p)
    2380           0 : { return T? FpXQXn_inv(x,n,T,p): FpXn_inv(x,n,p); }
    2381             : INLINE GEN
    2382           0 : FqXn_mul(GEN x, GEN y, long n, GEN T, GEN p)
    2383           0 : { return T? FpXQXn_mul(x, y, n, T, p): FpXn_mul(x, y, n, p); }
    2384             : INLINE GEN
    2385           0 : FqXn_sqr(GEN x, long n, GEN T, GEN p)
    2386           0 : { return T? FpXQXn_sqr(x,n,T,p): FpXn_sqr(x,n,p); }
    2387             : 
    2388             : /*FpXQ*/
    2389             : INLINE GEN
    2390           0 : FpXQ_add(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2391           0 : { (void)T; return FpX_add(x,y,p); }
    2392             : INLINE GEN
    2393           0 : FpXQ_sub(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2394           0 : { (void)T; return FpX_sub(x,y,p); }
    2395             : 
    2396             : /*Flxq*/
    2397             : INLINE GEN
    2398           0 : Flxq_add(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2399           0 : { (void)T; return Flx_add(x,y,p); }
    2400             : INLINE GEN
    2401           0 : Flxq_sub(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2402           0 : { (void)T; return Flx_sub(x,y,p); }
    2403             : 
    2404             : /* F2x */
    2405             : 
    2406             : INLINE ulong
    2407   100485311 : F2x_coeff(GEN x,long v)
    2408             : {
    2409   100485311 :    ulong u=(ulong)x[2+divsBIL(v)];
    2410   100484838 :    return (u>>remsBIL(v))&1UL;
    2411             : }
    2412             : 
    2413             : INLINE void
    2414     4728488 : F2x_clear(GEN x,long v)
    2415             : {
    2416     4728488 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2417     4728488 :    *u&=~(1UL<<remsBIL(v));
    2418     4728487 : }
    2419             : 
    2420             : INLINE void
    2421    32741169 : F2x_set(GEN x,long v)
    2422             : {
    2423    32741169 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2424    32720655 :    *u|=1UL<<remsBIL(v);
    2425    32710513 : }
    2426             : 
    2427             : INLINE void
    2428     1501777 : F2x_flip(GEN x,long v)
    2429             : {
    2430     1501777 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2431     1501777 :    *u^=1UL<<remsBIL(v);
    2432     1501777 : }
    2433             : 
    2434             : /* F2v */
    2435             : 
    2436             : INLINE ulong
    2437    95954011 : F2v_coeff(GEN x,long v) { return F2x_coeff(x,v-1); }
    2438             : 
    2439             : INLINE void
    2440     4728488 : F2v_clear(GEN x,long v) { F2x_clear(x,v-1); }
    2441             : 
    2442             : INLINE void
    2443     8964070 : F2v_set(GEN x,long v)   { F2x_set(x,v-1); }
    2444             : 
    2445             : INLINE void
    2446     1501777 : F2v_flip(GEN x,long v) { F2x_flip(x,v-1); }
    2447             : 
    2448             : /* F2m */
    2449             : 
    2450             : INLINE ulong
    2451    11672001 : F2m_coeff(GEN x, long a, long b) { return F2v_coeff(gel(x,b), a); }
    2452             : 
    2453             : INLINE void
    2454           0 : F2m_clear(GEN x, long a, long b) { F2v_clear(gel(x,b), a); }
    2455             : 
    2456             : INLINE void
    2457     1362615 : F2m_set(GEN x, long a, long b) { F2v_set(gel(x,b), a); }
    2458             : 
    2459             : INLINE void
    2460     1501777 : F2m_flip(GEN x, long a, long b) { F2v_flip(gel(x,b), a); }
    2461             : 
    2462             : /* ARITHMETIC */
    2463             : INLINE GEN
    2464        1071 : matpascal(long n) { return matqpascal(n, NULL); }
    2465             : INLINE long
    2466     2334531 : Z_issquare(GEN x) { return Z_issquareall(x, NULL); }
    2467             : INLINE long
    2468          14 : Z_ispower(GEN x, ulong k) { return Z_ispowerall(x, k, NULL); }
    2469             : INLINE GEN
    2470     5868317 : sqrti(GEN x) { return sqrtremi(x,NULL); }
    2471             : INLINE GEN
    2472     6168550 : gaddgs(GEN y, long s) { return gaddsg(s,y); }
    2473             : INLINE int
    2474       48712 : gcmpgs(GEN y, long s) { return -gcmpsg(s,y); }
    2475             : INLINE int
    2476       24570 : gequalgs(GEN y, long s) { return gequalsg(s,y); }
    2477             : INLINE GEN
    2478           0 : gmaxsg(long s, GEN y) { return gmaxgs(y,s); }
    2479             : INLINE GEN
    2480           0 : gminsg(long s, GEN y) { return gmings(y,s); }
    2481             : INLINE GEN
    2482    15177317 : gmulgs(GEN y, long s) { return gmulsg(s,y); }
    2483             : INLINE GEN
    2484     1354063 : gsubgs(GEN y, long s) { return gaddgs(y, -s); }
    2485             : INLINE GEN
    2486      682458 : gdivsg(long s, GEN y) { return gdiv(stoi(s), y); }
    2487             : 
    2488             : /* x t_COMPLEX */
    2489             : INLINE GEN
    2490    12986450 : cxnorm(GEN x) { return gadd(gsqr(gel(x,1)), gsqr(gel(x,2))); }
    2491             : /* q t_QUAD */
    2492             : INLINE GEN
    2493         623 : quadnorm(GEN q)
    2494             : {
    2495         623 :   GEN X = gel(q,1), b = gel(X,3), c = gel(X,2);
    2496         623 :   GEN z, u = gel(q,3), v = gel(q,2);
    2497         623 :   if (typ(u) == t_INT && typ(v) == t_INT) /* generic case */
    2498             :   {
    2499         308 :     z = signe(b)? mulii(v, addii(u,v)): sqri(v);
    2500         308 :     return addii(z, mulii(c, sqri(u)));
    2501             :   }
    2502             :   else
    2503             :   {
    2504         315 :     z = signe(b)? gmul(v, gadd(u,v)): gsqr(v);
    2505         315 :     return gadd(z, gmul(c, gsqr(u)));
    2506             :   }
    2507             : }
    2508             : /* x a t_QUAD, return the attached discriminant */
    2509             : INLINE GEN
    2510         273 : quad_disc(GEN x)
    2511             : {
    2512         273 :   GEN Q = gel(x,1), b = gel(Q,3), c = gel(Q,2), c4;
    2513         273 :   if (is_pm1(b))
    2514             :   {
    2515         217 :     pari_sp av = avma; (void)new_chunk(lgefint(c) + 1);
    2516         217 :     c4 = shifti(c,2); set_avma(av); return subsi(1, c4);
    2517             :   }
    2518          56 :   c4 = shifti(c,2); togglesign_safe(&c4); return c4;
    2519             : }
    2520             : INLINE GEN
    2521     6386709 : qfb_disc3(GEN x, GEN y, GEN z) { return subii(sqri(y), shifti(mulii(x,z),2)); }
    2522             : INLINE GEN
    2523     6305775 : qfb_disc(GEN x) { return qfb_disc3(gel(x,1), gel(x,2), gel(x,3)); }
    2524             : 
    2525             : INLINE GEN
    2526     1283958 : sqrfrac(GEN x)
    2527             : {
    2528     1283958 :   GEN z = cgetg(3,t_FRAC);
    2529     1283958 :   gel(z,1) = sqri(gel(x,1));
    2530     1283958 :   gel(z,2) = sqri(gel(x,2)); return z;
    2531             : }
    2532             : 
    2533             : INLINE void
    2534    21509780 : normalize_frac(GEN z) {
    2535    21509780 :   if (signe(gel(z,2)) < 0) { togglesign(gel(z,1)); setabssign(gel(z,2)); }
    2536    21509780 : }
    2537             : 
    2538             : INLINE GEN
    2539      265482 : powii(GEN x, GEN n)
    2540             : {
    2541      265482 :   long ln = lgefint(n);
    2542      265482 :   if (ln == 3) {
    2543             :     GEN z;
    2544      261093 :     if (signe(n) > 0) return powiu(x, n[2]);
    2545        8078 :     z = cgetg(3, t_FRAC);
    2546        8078 :     gel(z,1) = gen_1;
    2547        8078 :     gel(z,2) = powiu(x, n[2]);
    2548        8078 :     return z;
    2549             :   }
    2550        4389 :   if (ln == 2) return gen_1; /* rare */
    2551             :   /* should never happen */
    2552           0 :   return powgi(x, n); /* overflow unless x = 0, 1, -1 */
    2553             : }
    2554             : INLINE GEN
    2555        1246 : powIs(long n) {
    2556        1246 :   switch(n & 3)
    2557             :   {
    2558          28 :     case 1: return mkcomplex(gen_0,gen_1);
    2559         378 :     case 2: return gen_m1;
    2560         518 :     case 3: return mkcomplex(gen_0,gen_m1);
    2561             :   }
    2562         322 :   return gen_1;
    2563             : }
    2564             : 
    2565             : /*******************************************************************/
    2566             : /*                                                                 */
    2567             : /*                             ASSIGNMENTS                         */
    2568             : /*                                                                 */
    2569             : /*******************************************************************/
    2570           0 : INLINE void mpexpz(GEN x, GEN z)
    2571           0 : { pari_sp av = avma; gaffect(mpexp(x), z); set_avma(av); }
    2572           0 : INLINE void mplogz(GEN x, GEN z)
    2573           0 : { pari_sp av = avma; gaffect(mplog(x), z); set_avma(av); }
    2574           0 : INLINE void mpcosz(GEN x, GEN z)
    2575           0 : { pari_sp av = avma; gaffect(mpcos(x), z); set_avma(av); }
    2576           0 : INLINE void mpsinz(GEN x, GEN z)
    2577           0 : { pari_sp av = avma; gaffect(mpsin(x), z); set_avma(av); }
    2578           0 : INLINE void gnegz(GEN x, GEN z)
    2579           0 : { pari_sp av = avma; gaffect(gneg(x), z); set_avma(av); }
    2580           0 : INLINE void gabsz(GEN x, long prec, GEN z)
    2581           0 : { pari_sp av = avma; gaffect(gabs(x,prec), z); set_avma(av); }
    2582           0 : INLINE void gaddz(GEN x, GEN y, GEN z)
    2583           0 : { pari_sp av = avma; gaffect(gadd(x,y), z); set_avma(av); }
    2584           0 : INLINE void gsubz(GEN x, GEN y, GEN z)
    2585           0 : { pari_sp av = avma; gaffect(gsub(x,y), z); set_avma(av); }
    2586           0 : INLINE void gmulz(GEN x, GEN y, GEN z)
    2587           0 : { pari_sp av = avma; gaffect(gmul(x,y), z); set_avma(av); }
    2588           0 : INLINE void gdivz(GEN x, GEN y, GEN z)
    2589           0 : { pari_sp av = avma; gaffect(gdiv(x,y), z); set_avma(av); }
    2590           0 : INLINE void gdiventz(GEN x, GEN y, GEN z)
    2591           0 : { pari_sp av = avma; gaffect(gdivent(x,y), z); set_avma(av); }
    2592           0 : INLINE void gmodz(GEN x, GEN y, GEN z)
    2593           0 : { pari_sp av = avma; gaffect(gmod(x,y), z); set_avma(av); }
    2594           0 : INLINE void gmul2nz(GEN x, long s, GEN z)
    2595           0 : { pari_sp av = avma; gaffect(gmul2n(x,s), z); set_avma(av); }
    2596           0 : INLINE void gshiftz(GEN x, long s, GEN z)
    2597           0 : { pari_sp av = avma; gaffect(gshift(x,s), z); set_avma(av); }
    2598             : 
    2599             : /*******************************************************************/
    2600             : /*                                                                 */
    2601             : /*                       ELLIPTIC CURVES                           */
    2602             : /*                                                                 */
    2603             : /*******************************************************************/
    2604     3979743 : INLINE GEN ell_get_a1(GEN e) { return gel(e,1); }
    2605     3095790 : INLINE GEN ell_get_a2(GEN e) { return gel(e,2); }
    2606     3861697 : INLINE GEN ell_get_a3(GEN e) { return gel(e,3); }
    2607     3888736 : INLINE GEN ell_get_a4(GEN e) { return gel(e,4); }
    2608     4704915 : INLINE GEN ell_get_a6(GEN e) { return gel(e,5); }
    2609     3318531 : INLINE GEN ell_get_b2(GEN e) { return gel(e,6); }
    2610     1024949 : INLINE GEN ell_get_b4(GEN e) { return gel(e,7); }
    2611     1630617 : INLINE GEN ell_get_b6(GEN e) { return gel(e,8); }
    2612     1464001 : INLINE GEN ell_get_b8(GEN e) { return gel(e,9); }
    2613     6167072 : INLINE GEN ell_get_c4(GEN e) { return gel(e,10); }
    2614     7403595 : INLINE GEN ell_get_c6(GEN e) { return gel(e,11); }
    2615     9653761 : INLINE GEN ell_get_disc(GEN e) { return gel(e,12); }
    2616     1028909 : INLINE GEN ell_get_j(GEN e) { return gel(e,13); }
    2617    11455565 : INLINE long ell_get_type(GEN e) { return mael(e,14,1); }
    2618     1570438 : INLINE GEN ellff_get_field(GEN x) { return gmael(x, 15, 1); }
    2619      683125 : INLINE GEN ellff_get_a4a6(GEN x)  { return gmael(x, 15, 2); }
    2620        1407 : INLINE GEN ellQp_get_zero(GEN x) { return gmael(x, 15, 1); }
    2621         287 : INLINE long ellQp_get_prec(GEN E) { GEN z = ellQp_get_zero(E); return valp(z); }
    2622        1085 : INLINE GEN ellQp_get_p(GEN E) { GEN z = ellQp_get_zero(E); return gel(z,2); }
    2623       37156 : INLINE long ellR_get_prec(GEN x) { return nbits2prec(mael3(x, 15, 1, 1)); }
    2624       12106 : INLINE long ellR_get_sign(GEN x) { return mael3(x, 15, 1, 2); }
    2625      699393 : INLINE GEN ellnf_get_nf(GEN x) { return checknf_i(gmael(x,15,1)); }
    2626          56 : INLINE GEN ellnf_get_bnf(GEN x) { return checkbnf_i(gmael(x,15,1)); }
    2627             : 
    2628     4624907 : INLINE int checkell_i(GEN e) { return typ(e) == t_VEC && lg(e) == 17; }
    2629    33981036 : INLINE int ell_is_inf(GEN z) { return lg(z) == 2; }
    2630      809822 : INLINE GEN ellinf(void) { return mkvec(gen_0); }
    2631             : 
    2632             : /*******************************************************************/
    2633             : /*                                                                 */
    2634             : /*                    ALGEBRAIC NUMBER THEORY                      */
    2635             : /*                                                                 */
    2636             : /*******************************************************************/
    2637     8420034 : INLINE GEN modpr_get_pr(GEN x)  { return gel(x,3); }
    2638      609506 : INLINE GEN modpr_get_p(GEN x)  { return pr_get_p(modpr_get_pr(x)); }
    2639     2681211 : INLINE GEN modpr_get_T(GEN x)  { return lg(x) == 4? NULL: gel(x,4); }
    2640             : 
    2641    20066568 : INLINE GEN pr_get_p(GEN pr)  { return gel(pr,1); }
    2642     6618028 : INLINE GEN pr_get_gen(GEN pr){ return gel(pr,2); }
    2643             : /* .[2] instead of itos works: e and f are small positive integers */
    2644     2376598 : INLINE long pr_get_e(GEN pr) { return gel(pr,3)[2]; }
    2645     9158781 : INLINE long pr_get_f(GEN pr) { return gel(pr,4)[2]; }
    2646     6300022 : INLINE GEN pr_get_tau(GEN pr){ return gel(pr,5); }
    2647             : INLINE int
    2648     3188919 : pr_is_inert(GEN P) { return pr_get_f(P) == lg(pr_get_gen(P))-1; }
    2649             : INLINE GEN
    2650      232221 : pr_norm(GEN pr) { return powiu(pr_get_p(pr), pr_get_f(pr)); }
    2651             : INLINE ulong
    2652       48083 : upr_norm(GEN pr) { return upowuu(pr_get_p(pr)[2], pr_get_f(pr)); }
    2653             : 
    2654             : /* assume nf a genuine nf */
    2655             : INLINE long
    2656        4675 : nf_get_varn(GEN nf) { return varn(gel(nf,1)); }
    2657             : INLINE GEN
    2658    31827705 : nf_get_pol(GEN nf) { return gel(nf,1); }
    2659             : INLINE long
    2660    25311029 : nf_get_degree(GEN nf) { return degpol( nf_get_pol(nf) ); }
    2661             : INLINE long
    2662     4136913 : nf_get_r1(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,1)); }
    2663             : INLINE long
    2664        1673 : nf_get_r2(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,2)); }
    2665             : INLINE GEN
    2666       53137 : nf_get_disc(GEN nf) { return gel(nf,3); }
    2667             : INLINE GEN
    2668      828822 : nf_get_index(GEN nf) { return gel(nf,4); }
    2669             : INLINE GEN
    2670     2864897 : nf_get_M(GEN nf) { return gmael(nf,5,1); }
    2671             : INLINE GEN
    2672       81489 : nf_get_G(GEN nf) { return gmael(nf,5,2); }
    2673             : INLINE GEN
    2674      408060 : nf_get_roundG(GEN nf) { return gmael(nf,5,3); }
    2675             : INLINE GEN
    2676       24367 : nf_get_Tr(GEN nf) { return gmael(nf,5,4); }
    2677             : INLINE GEN
    2678        2324 : nf_get_diff(GEN nf) { return gmael(nf,5,5); }
    2679             : INLINE GEN
    2680          91 : nf_get_ramified_primes(GEN nf) { return gmael(nf,5,8); }
    2681             : INLINE GEN
    2682      332826 : nf_get_roots(GEN nf) { return gel(nf,6); }
    2683             : INLINE GEN
    2684          91 : nf_get_zk(GEN nf)
    2685             : {
    2686          91 :   GEN y = gel(nf,7), D = gel(y, 1);
    2687          91 :   if (typ(D) == t_POL) D = gel(D, 2);
    2688          91 :   if (!equali1(D)) y = gdiv(y, D);
    2689          91 :   return y;
    2690             : }
    2691             : INLINE GEN
    2692      278996 : nf_get_zkprimpart(GEN nf)
    2693             : {
    2694      278996 :   GEN y = gel(nf,7);
    2695             :   /* test for old format of nf.zk: non normalized */
    2696      278996 :   if (!equali1(gel(nf,4)) && gequal1(gel(y,1))) y = Q_remove_denom(y,NULL);
    2697      278995 :   return y;
    2698             : }
    2699             : INLINE GEN
    2700      280150 : nf_get_zkden(GEN nf)
    2701             : {
    2702      280150 :   GEN y = gel(nf,7), D = gel(y,1);
    2703      280150 :   if (typ(D) == t_POL) D = gel(D,2);
    2704             :   /* test for old format of nf.zk: non normalized */
    2705      280150 :   if (!equali1(gel(nf,4)) && equali1(D)) D = Q_denom(y);
    2706      280148 :   return D;
    2707             : }
    2708             : INLINE GEN
    2709     2486872 : nf_get_invzk(GEN nf) { return gel(nf,8); }
    2710             : INLINE void
    2711       22843 : nf_get_sign(GEN nf, long *r1, long *r2)
    2712             : {
    2713       22843 :   GEN x = gel(nf,2);
    2714       22843 :   *r1 = itou(gel(x,1));
    2715       22843 :   *r2 = itou(gel(x,2));
    2716       22843 : }
    2717             : 
    2718             : INLINE GEN
    2719       92758 : abgrp_get_no(GEN x) { return gel(x,1); }
    2720             : INLINE GEN
    2721     2600822 : abgrp_get_cyc(GEN x) { return gel(x,2); }
    2722             : INLINE GEN
    2723      437924 : abgrp_get_gen(GEN x) { return gel(x,3); }
    2724             : INLINE GEN
    2725     2315220 : bnf_get_nf(GEN bnf) { return gel(bnf,7); }
    2726             : INLINE GEN
    2727      896050 : bnf_get_clgp(GEN bnf) { return gmael(bnf,8,1); }
    2728             : INLINE GEN
    2729        6713 : bnf_get_no(GEN bnf) { return abgrp_get_no(bnf_get_clgp(bnf)); }
    2730             : INLINE GEN
    2731      498019 : bnf_get_cyc(GEN bnf) { return abgrp_get_cyc(bnf_get_clgp(bnf)); }
    2732             : INLINE GEN
    2733      390989 : bnf_get_gen(GEN bnf)  { return abgrp_get_gen(bnf_get_clgp(bnf)); }
    2734             : INLINE GEN
    2735         846 : bnf_get_reg(GEN bnf) { return gmael(bnf,8,2); }
    2736             : INLINE GEN
    2737      502386 : bnf_get_logfu(GEN bnf) { return gel(bnf,3); }
    2738             : INLINE GEN
    2739        7443 : bnf_get_tuU(GEN bnf) { return gmael3(bnf,8,4,2); }
    2740             : INLINE long
    2741       40201 : bnf_get_tuN(GEN bnf) { return gmael3(bnf,8,4,1)[2]; }
    2742             : INLINE GEN
    2743        1778 : bnf_get_fu(GEN bnf) {
    2744        1778 :   GEN fu = bnf_get_fu_nocheck(bnf);
    2745        1778 :   if (typ(fu) == t_MAT) pari_err(e_MISC,"missing units in bnf");
    2746        1778 :   return fu;
    2747             : }
    2748             : INLINE GEN
    2749        8878 : bnf_get_fu_nocheck(GEN bnf) { return gmael(bnf,8,5); }
    2750             : 
    2751             : INLINE GEN
    2752      927533 : bnr_get_bnf(GEN bnr) { return gel(bnr,1); }
    2753             : INLINE GEN
    2754      474711 : bnr_get_bid(GEN bnr) { return gel(bnr,2); }
    2755             : INLINE GEN
    2756       18648 : bnr_get_mod(GEN bnr) { return gmael(bnr,2,1); }
    2757             : INLINE GEN
    2758       32557 : bnr_get_nf(GEN bnr) { return gmael(bnr,1,7); }
    2759             : INLINE GEN
    2760      716428 : bnr_get_clgp(GEN bnr) { return gel(bnr,5); }
    2761             : INLINE GEN
    2762       82278 : bnr_get_no(GEN bnr) { return abgrp_get_no(bnr_get_clgp(bnr)); }
    2763             : INLINE GEN
    2764      618106 : bnr_get_cyc(GEN bnr) { return abgrp_get_cyc(bnr_get_clgp(bnr)); }
    2765             : INLINE GEN
    2766          70 : bnr_get_gen_nocheck(GEN bnr) { return abgrp_get_gen(bnr_get_clgp(bnr)); }
    2767             : INLINE GEN
    2768       14931 : bnr_get_gen(GEN bnr) {
    2769       14931 :   GEN G = bnr_get_clgp(bnr);
    2770       14931 :   if (lg(G) !=  4)
    2771           0 :     pari_err(e_MISC,"missing bnr generators: please use bnrinit(,,1)");
    2772       14931 :   return gel(G,3);
    2773             : }
    2774             : 
    2775             : INLINE GEN
    2776      361227 : bid_get_mod(GEN bid) { return gel(bid,1); }
    2777             : INLINE GEN
    2778       65947 : bid_get_ideal(GEN bid) { return gmael(bid,1,1); }
    2779             : INLINE GEN
    2780         707 : bid_get_arch(GEN bid) { return gmael(bid,1,2); }
    2781             : INLINE GEN
    2782     1330683 : bid_get_grp(GEN bid) { return gel(bid,2); }
    2783             : INLINE GEN
    2784      528282 : bid_get_fact(GEN bid) { return gmael(bid,3,1); }
    2785             : INLINE GEN
    2786      458373 : bid_get_fact2(GEN bid) { return gmael(bid,3,2); }
    2787             : INLINE GEN
    2788      458184 : bid_get_sprk(GEN bid) { return gmael(bid,4,1); }
    2789             : INLINE GEN
    2790       49203 : bid_get_sarch(GEN bid) { return gmael(bid,4,2); }
    2791             : INLINE GEN
    2792      493975 : bid_get_archp(GEN bid) { return gmael3(bid,4,2,2); }
    2793             : INLINE GEN
    2794      819621 : bid_get_U(GEN bid) { return gel(bid,5); }
    2795             : INLINE GEN
    2796           0 : bid_get_no(GEN bid) { return abgrp_get_no(bid_get_grp(bid)); }
    2797             : INLINE GEN
    2798     1284742 : bid_get_cyc(GEN bid) { return abgrp_get_cyc(bid_get_grp(bid)); }
    2799             : INLINE GEN
    2800           0 : bid_get_gen_nocheck(GEN bid)  { return abgrp_get_gen(bid_get_grp(bid)); }
    2801             : INLINE GEN
    2802       45346 : bid_get_gen(GEN bid) {
    2803       45346 :   GEN G = bid_get_grp(bid);
    2804       45346 :   if (lg(G) != 4) pari_err(e_MISC,"missing bid generators. Use idealstar(,,2)");
    2805       45346 :   return abgrp_get_gen(G);
    2806             : }
    2807             : 
    2808             : INLINE GEN
    2809    22263563 : znstar_get_N(GEN G) { return gmael(G,1,1); }
    2810             : INLINE GEN
    2811     2820783 : znstar_get_faN(GEN G) { return gel(G,3); }
    2812             : INLINE GEN
    2813           7 : znstar_get_no(GEN G) { return abgrp_get_no(gel(G,2)); }
    2814             : INLINE GEN
    2815      198534 : znstar_get_cyc(GEN G) { return abgrp_get_cyc(gel(G,2)); }
    2816             : INLINE GEN
    2817           7 : znstar_get_gen(GEN G) { return abgrp_get_gen(gel(G,2)); }
    2818             : INLINE GEN
    2819     3495527 : znstar_get_conreycyc(GEN G) { return gmael(G,4,5); }
    2820             : INLINE GEN
    2821     1201494 : znstar_get_conreygen(GEN G) { return gmael(G,4,4); }
    2822             : INLINE GEN
    2823       45920 : znstar_get_Ui(GEN G) { return gmael(G,4,3); }
    2824             : INLINE GEN
    2825      118160 : znstar_get_U(GEN G) { return gel(G,5); }
    2826             : INLINE GEN
    2827      799701 : znstar_get_pe(GEN G) { return gmael(G,4,1); }
    2828             : INLINE GEN
    2829       19894 : gal_get_pol(GEN gal) { return gel(gal,1); }
    2830             : INLINE GEN
    2831        1323 : gal_get_p(GEN gal) { return gmael(gal,2,1); }
    2832             : INLINE GEN
    2833          84 : gal_get_e(GEN gal) { return gmael(gal,2,2); }
    2834             : INLINE GEN
    2835       15960 : gal_get_mod(GEN gal) { return gmael(gal,2,3); }
    2836             : INLINE GEN
    2837       16338 : gal_get_roots(GEN gal) { return gel(gal,3); }
    2838             : INLINE GEN
    2839       15918 : gal_get_invvdm(GEN gal) { return gel(gal,4); }
    2840             : INLINE GEN
    2841       15918 : gal_get_den(GEN gal) { return gel(gal,5); }
    2842             : INLINE GEN
    2843       66990 : gal_get_group(GEN gal) { return gel(gal,6); }
    2844             : INLINE GEN
    2845        1743 : gal_get_gen(GEN gal) { return gel(gal,7); }
    2846             : INLINE GEN
    2847        1379 : gal_get_orders(GEN gal) { return gel(gal,8); }
    2848             : 
    2849             : /* assume rnf a genuine rnf */
    2850             : INLINE long
    2851     1233344 : rnf_get_degree(GEN rnf) { return degpol(rnf_get_pol(rnf)); }
    2852             : INLINE long
    2853       16436 : rnf_get_nfdegree(GEN rnf) { return degpol(nf_get_pol(rnf_get_nf(rnf))); }
    2854             : INLINE long
    2855      775670 : rnf_get_absdegree(GEN rnf) { return degpol(gmael(rnf,11,1)); }
    2856             : INLINE GEN
    2857         700 : rnf_get_idealdisc(GEN rnf) { return gmael(rnf,3,1); }
    2858             : INLINE GEN
    2859         742 : rnf_get_k(GEN rnf) { return gmael(rnf,11,3); }
    2860             : INLINE GEN
    2861         609 : rnf_get_alpha(GEN rnf) { return gmael(rnf, 11, 2); }
    2862             : INLINE GEN
    2863      384125 : rnf_get_nf(GEN rnf) { return gel(rnf,10); }
    2864             : INLINE GEN
    2865        3171 : rnf_get_nfzk(GEN rnf) { return gel(rnf,2); }
    2866             : INLINE GEN
    2867      205107 : rnf_get_polabs(GEN rnf) { return gmael(rnf,11,1); }
    2868             : INLINE GEN
    2869     1478575 : rnf_get_pol(GEN rnf) { return gel(rnf,1); }
    2870             : INLINE GEN
    2871          63 : rnf_get_disc(GEN rnf) { return gel(rnf,3); }
    2872             : INLINE GEN
    2873         105 : rnf_get_index(GEN rnf) { return gel(rnf,4); }
    2874             : INLINE long
    2875           0 : rnf_get_varn(GEN rnf) { return varn(gel(rnf,1)); }
    2876             : INLINE GEN
    2877      188062 : rnf_get_nfpol(GEN rnf) { return gmael(rnf,10,1); }
    2878             : INLINE long
    2879        3325 : rnf_get_nfvarn(GEN rnf) { return varn(gmael(rnf,10,1)); }
    2880             : INLINE GEN
    2881        3283 : rnf_get_zk(GEN rnf) { return gel(rnf,7); }
    2882             : INLINE GEN
    2883       96922 : rnf_get_map(GEN rnf) { return gel(rnf,11); }
    2884             : INLINE GEN
    2885        1197 : rnf_get_invzk(GEN rnf) { return gel(rnf,8); }
    2886             : 
    2887             : /* I integral ZM (not HNF), G ZM, rounded Cholesky form of a weighted
    2888             :  * T2 matrix. Reduce I wrt G */
    2889             : INLINE GEN
    2890       21784 : idealpseudored(GEN I, GEN G)
    2891       21784 : { return ZM_mul(I, ZM_lll(ZM_mul(G, I), 0.99, LLL_IM)); }
    2892             : 
    2893             : /* I integral (not necessarily HNF), G ZM, rounded Cholesky form of a weighted
    2894             :  * T2 matrix. Return m in I with T2(m) small */
    2895             : INLINE GEN
    2896      140667 : idealpseudomin(GEN I, GEN G)
    2897             : {
    2898      140667 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2899      140667 :   return ZM_ZC_mul(I, gel(u,1));
    2900             : }
    2901             : /* I, G as in idealpseudomin. Return an irrational m in I with T2(m) small */
    2902             : INLINE GEN
    2903      298542 : idealpseudomin_nonscalar(GEN I, GEN G)
    2904             : {
    2905      298542 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2906      298542 :   GEN m = ZM_ZC_mul(I, gel(u,1));
    2907      298542 :   if (ZV_isscalar(m) && lg(u) > 2) m = ZM_ZC_mul(I, gel(u,2));
    2908      298542 :   return m;
    2909             : }
    2910             : 
    2911             : INLINE GEN
    2912         819 : idealred_elt(GEN nf, GEN I) {
    2913         819 :   pari_sp av = avma;
    2914         819 :   GEN u = idealpseudomin(I, nf_get_roundG(nf));
    2915         819 :   return gerepileupto(av, u);
    2916             : }
    2917             : INLINE GEN
    2918      122877 : idealred(GEN nf, GEN I) { return idealred0(nf, I, NULL); }
    2919             : 
    2920             : INLINE GEN
    2921        2058 : idealchineseinit(GEN nf, GEN x)
    2922        2058 : { return idealchinese(nf,x,NULL); }
    2923             : 
    2924             : /*******************************************************************/
    2925             : /*                                                                 */
    2926             : /*                              CLOSURES                           */
    2927             : /*                                                                 */
    2928             : /*******************************************************************/
    2929   226023266 : INLINE long closure_arity(GEN C)          { return ((ulong)C[1])&ARITYBITS; }
    2930    35495839 : INLINE long closure_is_variadic(GEN C) { return !!(((ulong)C[1])&VARARGBITS); }
    2931   190240371 : INLINE const char *closure_codestr(GEN C)  { return GSTR(gel(C,2))-1; }
    2932           0 : INLINE GEN closure_get_code(GEN C)  { return gel(C,2); }
    2933   190198380 : INLINE GEN closure_get_oper(GEN C)  { return gel(C,3); }
    2934   190172792 : INLINE GEN closure_get_data(GEN C)  { return gel(C,4); }
    2935        9589 : INLINE GEN closure_get_dbg(GEN C)   { return gel(C,5); }
    2936       22930 : INLINE GEN closure_get_text(GEN C)  { return gel(C,6); }
    2937     1225868 : INLINE GEN closure_get_frame(GEN C) { return gel(C,7); }
    2938             : 
    2939             : /*******************************************************************/
    2940             : /*                                                                 */
    2941             : /*                               ERRORS                            */
    2942             : /*                                                                 */
    2943             : /*******************************************************************/
    2944             : INLINE long
    2945       52597 : err_get_num(GEN e) { return e[1]; }
    2946             : INLINE GEN
    2947          77 : err_get_compo(GEN e, long i) { return gel(e, i+1); }
    2948             : 
    2949             : INLINE void
    2950          14 : pari_err_BUG(const char *f) { pari_err(e_BUG,f); }
    2951             : INLINE void
    2952           7 : pari_err_CONSTPOL(const char *f) { pari_err(e_CONSTPOL, f); }
    2953             : INLINE void
    2954          63 : pari_err_COPRIME(const char *f, GEN x, GEN y) { pari_err(e_COPRIME, f,x,y); }
    2955             : INLINE void
    2956         487 : pari_err_DIM(const char *f) { pari_err(e_DIM, f); }
    2957             : INLINE void
    2958           0 : pari_err_FILE(const char *f, const char *g) { pari_err(e_FILE, f,g); }
    2959             : INLINE void
    2960           0 : pari_err_FILEDESC(const char *f, long n) { pari_err(e_FILEDESC, f,n); }
    2961             : INLINE void
    2962          63 : pari_err_FLAG(const char *f) { pari_err(e_FLAG,f); }
    2963             : INLINE void
    2964         434 : pari_err_IMPL(const char *f) { pari_err(e_IMPL,f); }
    2965             : INLINE void
    2966       19716 : pari_err_INV(const char *f, GEN x) { pari_err(e_INV,f,x); }
    2967             : INLINE void
    2968          28 : pari_err_IRREDPOL(const char *f, GEN x) { pari_err(e_IRREDPOL, f,x); }
    2969             : INLINE void
    2970        2043 : 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); }
    2971             : INLINE void
    2972         203 : pari_err_COMPONENT(const char *f, const char *op, GEN l, GEN x) { pari_err(e_COMPONENT, f,op,l,x); }
    2973             : INLINE void
    2974           0 : pari_err_MAXPRIME(ulong c) { pari_err(e_MAXPRIME, c); }
    2975             : INLINE void
    2976         350 : pari_err_OP(const char *f, GEN x, GEN y) { pari_err(e_OP, f,x,y); }
    2977             : INLINE void
    2978          86 : pari_err_OVERFLOW(const char *f) { pari_err(e_OVERFLOW, f); }
    2979             : INLINE void
    2980         218 : pari_err_PREC(const char *f) { pari_err(e_PREC,f); }
    2981             : INLINE void
    2982           0 : pari_err_PACKAGE(const char *f) { pari_err(e_PACKAGE,f); }
    2983             : INLINE void
    2984          70 : pari_err_PRIME(const char *f, GEN x) { pari_err(e_PRIME, f,x); }
    2985             : INLINE void
    2986         749 : pari_err_MODULUS(const char *f, GEN x, GEN y) { pari_err(e_MODULUS, f,x,y); }
    2987             : INLINE void
    2988          49 : pari_err_ROOTS0(const char *f) { pari_err(e_ROOTS0, f); }
    2989             : INLINE void
    2990          77 : pari_err_SQRTN(const char *f, GEN x) { pari_err(e_SQRTN, f,x); }
    2991             : INLINE void
    2992       12650 : pari_err_TYPE(const char *f, GEN x) { pari_err(e_TYPE, f,x); }
    2993             : INLINE void
    2994        3073 : pari_err_TYPE2(const char *f, GEN x, GEN y) { pari_err(e_TYPE2, f,x,y); }
    2995             : INLINE void
    2996         203 : pari_err_VAR(const char *f, GEN x, GEN y) { pari_err(e_VAR, f,x,y); }
    2997             : INLINE void
    2998         175 : pari_err_PRIORITY(const char *f, GEN x, const char *op, long v)
    2999         175 : { pari_err(e_PRIORITY, f,x,op,v); }

Generated by: LCOV version 1.13