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 23346-507fdfd83) Lines: 1287 1456 88.4 %
Date: 2018-12-13 05:42:04 Functions: 564 642 87.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (C) 2000-2010  The PARI group.
       2             : 
       3             : This file is part of the PARI/GP package.
       4             : 
       5             : PARI/GP is free software; you can redistribute it and/or modify it under the
       6             : terms of the GNU General Public License as published by the Free Software
       7             : Foundation. It is distributed in the hope that it will be useful, but WITHOUT
       8             : ANY WARRANTY WHATSOEVER.
       9             : 
      10             : Check the License for details. You should have received a copy of it, along
      11             : with the package; see the file 'COPYING'. If not, write to the Free Software
      12             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
      13             : 
      14             : /*******************************************************************/
      15             : /*                                                                 */
      16             : /*                          CONSTRUCTORS                           */
      17             : /*                                                                 */
      18             : /*******************************************************************/
      19             : #define retmkfrac(x,y)\
      20             :   do { GEN _v = cgetg(3, t_FRAC);\
      21             :        gel(_v,1) = (x);\
      22             :        gel(_v,2) = (y); return _v; } while(0)
      23             : #define retmkrfrac(x,y)\
      24             :   do { GEN _v = cgetg(3, t_RFRAC);\
      25             :        gel(_v,1) = (x);\
      26             :        gel(_v,2) = (y); return _v; } while(0)
      27             : #define retmkintmod(x,y)\
      28             :   do { GEN _v = cgetg(3, t_INTMOD);\
      29             :        gel(_v,1) = (y);\
      30             :        gel(_v,2) = (x); return _v; } while(0)
      31             : #define retmkcomplex(x,y)\
      32             :   do { GEN _v = cgetg(3, t_COMPLEX);\
      33             :        gel(_v,1) = (x);\
      34             :        gel(_v,2) = (y); return _v; } while(0)
      35             : #define retmkpolmod(x,y)\
      36             :   do { GEN _v = cgetg(3, t_POLMOD);\
      37             :        gel(_v,1) = (y);\
      38             :        gel(_v,2) = (x); return _v; } while(0)
      39             : #define retmkvec(x)\
      40             :   do { GEN _v = cgetg(2, t_VEC);\
      41             :        gel(_v,1) = (x); return _v; } while(0)
      42             : #define retmkvec2(x,y)\
      43             :   do { GEN _v = cgetg(3, t_VEC);\
      44             :        gel(_v,1) = (x);\
      45             :        gel(_v,2) = (y); return _v; } while(0)
      46             : #define retmkvec3(x,y,z)\
      47             :   do { GEN _v = cgetg(4, t_VEC);\
      48             :        gel(_v,1) = (x);\
      49             :        gel(_v,2) = (y);\
      50             :        gel(_v,3) = (z); return _v; } while(0)
      51             : #define retmkqfi(x,y,z)\
      52             :   do { GEN _v = cgetg(4, t_QFI);\
      53             :        gel(_v,1) = (x);\
      54             :        gel(_v,2) = (y);\
      55             :        gel(_v,3) = (z); return _v; } while(0)
      56             : #define retmkqfr(x,y,z,d)\
      57             :   do { GEN _v = cgetg(5, t_QFR);\
      58             :        gel(_v,1) = (x);\
      59             :        gel(_v,2) = (y);\
      60             :        gel(_v,3) = (z);\
      61             :        gel(_v,4) = (d); return _v; } while(0)
      62             : #define retmkquad(x,y,z)\
      63             :   do { GEN _v = cgetg(4, t_QUAD);\
      64             :        gel(_v,1) = (x);\
      65             :        gel(_v,2) = (y);\
      66             :        gel(_v,3) = (z); return _v; } while(0)
      67             : #define retmkvec4(x,y,z,t)\
      68             :   do { GEN _v = cgetg(5, t_VEC);\
      69             :        gel(_v,1) = (x);\
      70             :        gel(_v,2) = (y);\
      71             :        gel(_v,3) = (z);\
      72             :        gel(_v,4) = (t); return _v; } while(0)
      73             : #define retmkvec5(x,y,z,t,u)\
      74             :   do { GEN _v = cgetg(6, t_VEC);\
      75             :        gel(_v,1) = (x);\
      76             :        gel(_v,2) = (y);\
      77             :        gel(_v,3) = (z);\
      78             :        gel(_v,4) = (t);\
      79             :        gel(_v,5) = (u); return _v; } while(0)
      80             : #define retmkcol(x)\
      81             :   do { GEN _v = cgetg(2, t_COL);\
      82             :        gel(_v,1) = (x); return _v; } while(0)
      83             : #define retmkcol2(x,y)\
      84             :   do { GEN _v = cgetg(3, t_COL);\
      85             :        gel(_v,1) = (x);\
      86             :        gel(_v,2) = (y); return _v; } while(0)
      87             : #define retmkcol3(x,y,z)\
      88             :   do { GEN _v = cgetg(4, t_COL);\
      89             :        gel(_v,1) = (x);\
      90             :        gel(_v,2) = (y);\
      91             :        gel(_v,3) = (z); return _v; } while(0)
      92             : #define retmkcol4(x,y,z,t)\
      93             :   do { GEN _v = cgetg(5, t_COL);\
      94             :        gel(_v,1) = (x);\
      95             :        gel(_v,2) = (y);\
      96             :        gel(_v,3) = (z);\
      97             :        gel(_v,4) = (t); return _v; } while(0)
      98             : #define retmkcol5(x,y,z,t,u)\
      99             :   do { GEN _v = cgetg(6, t_COL);\
     100             :        gel(_v,1) = (x);\
     101             :        gel(_v,2) = (y);\
     102             :        gel(_v,3) = (z);\
     103             :        gel(_v,4) = (t);\
     104             :        gel(_v,5) = (u); return _v; } while(0)
     105             : #define retmkcol6(x,y,z,t,u,v)\
     106             :   do { GEN _v = cgetg(7, t_COL);\
     107             :        gel(_v,1) = (x);\
     108             :        gel(_v,2) = (y);\
     109             :        gel(_v,3) = (z);\
     110             :        gel(_v,4) = (t);\
     111             :        gel(_v,5) = (u);\
     112             :        gel(_v,6) = (v); return _v; } while(0)
     113             : #define retmkmat(x)\
     114             :   do { GEN _v = cgetg(2, t_MAT);\
     115             :        gel(_v,1) = (x); return _v; } while(0)
     116             : #define retmkmat2(x,y)\
     117             :   do { GEN _v = cgetg(3, t_MAT);\
     118             :        gel(_v,1) = (x);\
     119             :        gel(_v,2) = (y); return _v; } while(0)
     120             : #define retmkmat3(x,y,z)\
     121             :   do { GEN _v = cgetg(4, t_MAT);\
     122             :        gel(_v,1) = (x);\
     123             :        gel(_v,2) = (y);\
     124             :        gel(_v,3) = (z); return _v; } while(0)
     125             : #define retmkmat4(x,y,z,t)\
     126             :   do { GEN _v = cgetg(5, t_MAT);\
     127             :        gel(_v,1) = (x);\
     128             :        gel(_v,2) = (y);\
     129             :        gel(_v,3) = (z);\
     130             :        gel(_v,4) = (t); return _v; } while(0)
     131             : #define retmkmat5(x,y,z,t,u)\
     132             :   do { GEN _v = cgetg(6, t_MAT);\
     133             :        gel(_v,1) = (x);\
     134             :        gel(_v,2) = (y);\
     135             :        gel(_v,3) = (z);\
     136             :        gel(_v,4) = (t);\
     137             :        gel(_v,5) = (u); return _v; } while(0)
     138             : 
     139             : INLINE GEN
     140     3120442 : 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     2940301 : mkpolmod(GEN x, GEN y) { retmkpolmod(x,y); }
     149             : INLINE GEN
     150    23138938 : mkfrac(GEN x, GEN y) { retmkfrac(x,y); }
     151             : INLINE GEN
     152       32137 : mkfracss(long x, long y) { retmkfrac(stoi(x),utoipos(y)); }
     153             : /* q = n/d a t_FRAC or t_INT; recover (n,d) */
     154             : INLINE void
     155       12208 : Qtoss(GEN q, long *n, long *d)
     156             : {
     157       12208 :   if (typ(q) == t_INT) { *n = itos(q); *d = 1; }
     158        2443 :   else { *n = itos(gel(q,1)); *d = itou(gel(q,2)); }
     159       12208 : }
     160             : INLINE GEN
     161    71228544 : sstoQ(long n, long d)
     162             : {
     163             :   ulong r;
     164             :   long g, q;
     165    71228544 :   if (!n)
     166             :   {
     167       88767 :     if (!d) pari_err_INV("sstoQ",gen_0);
     168       88767 :     return gen_0;
     169             :   }
     170    71139777 :   if (d < 0) { d = -d; n = -n; }
     171    71139777 :   if (d == 1) return stoi(n);
     172    71128185 :   q = udivuu_rem(labs(n),d,&r);
     173    71128185 :   if (!r) return n > 0? utoipos(q): utoineg(q);
     174     3612450 :   g = ugcd(d,r); /* gcd(n,d) */
     175     3612450 :   if (g != 1) { n /= g; d /= g; }
     176     3612450 :   retmkfrac(stoi(n), utoi(d));
     177             : }
     178             : 
     179             : INLINE GEN
     180     6675263 : 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     9069819 : mkcomplex(GEN x, GEN y) { retmkcomplex(x,y); }
     189             : INLINE GEN
     190      449514 : gen_I(void) { return mkcomplex(gen_0, gen_1); }
     191             : INLINE GEN
     192      298716 : 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    69566951 : mkvecsmall(long x) { GEN v = cgetg(2, t_VECSMALL); v[1] = x; return v; }
     199             : INLINE GEN
     200   114111011 : mkvecsmall2(long x,long y) { GEN v = cgetg(3, t_VECSMALL);
     201   114121690 :   v[1]=x; v[2]=y; return v; }
     202             : INLINE GEN
     203    58022384 : mkvecsmall3(long x,long y,long z) { GEN v = cgetg(4, t_VECSMALL);
     204    58020534 :   v[1]=x; v[2]=y; v[3]=z; return v; }
     205             : INLINE GEN
     206    11957538 : mkvecsmall4(long x,long y,long z,long t) { GEN v = cgetg(5, t_VECSMALL);
     207    11950772 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; return v; }
     208             : INLINE GEN
     209      466531 : mkvecsmall5(long x,long y,long z,long t,long u) { GEN v = cgetg(6, t_VECSMALL);
     210      466534 :   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    15033067 : mkvec(GEN x) { retmkvec(x); }
     217             : INLINE GEN
     218   102016419 : mkvec2(GEN x, GEN y) { retmkvec2(x,y); }
     219             : INLINE GEN
     220    76330092 : mkvec3(GEN x, GEN y, GEN z) { retmkvec3(x,y,z); }
     221             : INLINE GEN
     222     7270044 : mkvec4(GEN x, GEN y, GEN z, GEN t) { retmkvec4(x,y,z,t); }
     223             : INLINE GEN
     224    12081893 : 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       23042 : mkvec2s(long x, long y) { retmkvec2(stoi(x),stoi(y)); }
     229             : INLINE GEN
     230      492724 : mkvec3s(long x, long y, long z) { retmkvec3(stoi(x),stoi(y),stoi(z)); }
     231             : INLINE GEN
     232          21 : mkvec4s(long x, long y, long z, long t) { retmkvec4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     233             : INLINE GEN
     234       35091 : mkveccopy(GEN x) { GEN v = cgetg(2, t_VEC); gel(v,1) = gcopy(x); return v; }
     235             : INLINE GEN
     236       96868 : mkvec2copy(GEN x, GEN y) {
     237       96868 :   GEN v = cgetg(3,t_VEC); gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     238             : /* col */
     239             : INLINE GEN
     240     2534722 : mkcol(GEN x) { retmkcol(x); }
     241             : INLINE GEN
     242    25641737 : 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     2536167 : mkmat(GEN x) { retmkmat(x); }
     264             : INLINE GEN
     265    32198644 : mkmat2(GEN x, GEN y) { retmkmat2(x,y); }
     266             : INLINE GEN
     267        2331 : mkmat3(GEN x, GEN y, GEN z) { retmkmat3(x,y,z); }
     268             : INLINE GEN
     269           0 : mkmat4(GEN x, GEN y, GEN z, GEN t) { retmkmat4(x,y,z,t); }
     270             : INLINE GEN
     271           0 : mkmat5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkmat5(x,y,z,t,u); }
     272             : INLINE GEN
     273       22341 : mkmatcopy(GEN x) { GEN v = cgetg(2, t_MAT); gel(v,1) = gcopy(x); return v; }
     274             : INLINE GEN
     275           0 : mkerr(long x) { GEN v = cgetg(2, t_ERROR); v[1] = x; return v; }
     276             : INLINE GEN
     277       96160 : mkoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_1; return v; }
     278             : INLINE GEN
     279       17010 : mkmoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_m1; return v; }
     280             : INLINE long
     281      132886 : 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      989389 : pol_x(long v) {
     290      989389 :   GEN p = cgetg(4, t_POL);
     291      989391 :   p[1] = evalsigne(1)|evalvarn(v);
     292      989391 :   gel(p,2) = gen_0;
     293      989391 :   gel(p,3) = gen_1; return p;
     294             : }
     295             : /* x^n, assume n >= 0 */
     296             : INLINE GEN
     297     8770747 : pol_xn(long n, long v) {
     298     8770747 :   long i, a = n+2;
     299     8770747 :   GEN p = cgetg(a+1, t_POL);
     300     8770746 :   p[1] = evalsigne(1)|evalvarn(v);
     301     8770746 :   for (i = 2; i < a; i++) gel(p,i) = gen_0;
     302     8770746 :   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     1429257 : pol_1(long v) {
     313     1429257 :   GEN p = cgetg(3, t_POL);
     314     1429263 :   p[1] = evalsigne(1)|evalvarn(v);
     315     1429263 :   gel(p,2) = gen_1; return p;
     316             : }
     317             : INLINE GEN
     318    32822528 : pol_0(long v)
     319             : {
     320    32822528 :   GEN x = cgetg(2,t_POL);
     321    32822528 :   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     8746428 : 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     8679186 : const_col(long n, GEN x) { retconst_col(n, x); }
     337             : INLINE GEN
     338     8602675 : const_vecsmall(long n, long c)
     339             : {
     340             :   long i;
     341     8602675 :   GEN V = cgetg(n+1,t_VECSMALL);
     342     8602846 :   for(i=1;i<=n;i++) V[i] = c;
     343     8602846 :   return V;
     344             : }
     345             : 
     346             : /***   ZERO   ***/
     347             : /* O(p^e) */
     348             : INLINE GEN
     349      363745 : zeropadic(GEN p, long e)
     350             : {
     351      363745 :   GEN y = cgetg(5,t_PADIC);
     352      363745 :   gel(y,4) = gen_0;
     353      363745 :   gel(y,3) = gen_1;
     354      363745 :   gel(y,2) = icopy(p);
     355      363745 :   y[1] = evalvalp(e) | _evalprecp(0);
     356      363745 :   return y;
     357             : }
     358             : INLINE GEN
     359         966 : zeropadic_shallow(GEN p, long e)
     360             : {
     361         966 :   GEN y = cgetg(5,t_PADIC);
     362         966 :   gel(y,4) = gen_0;
     363         966 :   gel(y,3) = gen_1;
     364         966 :   gel(y,2) = p;
     365         966 :   y[1] = evalvalp(e) | _evalprecp(0);
     366         966 :   return y;
     367             : }
     368             : /* O(pol_x(v)^e) */
     369             : INLINE GEN
     370      143591 : zeroser(long v, long e)
     371             : {
     372      143591 :   GEN x = cgetg(2, t_SER);
     373      143591 :   x[1] = evalvalp(e) | evalvarn(v); return x;
     374             : }
     375             : INLINE int
     376     5750158 : ser_isexactzero(GEN x)
     377             : {
     378     5750158 :   if (!signe(x)) switch(lg(x))
     379             :   {
     380      136206 :     case 2: return 1;
     381         854 :     case 3: return isexactzero(gel(x,2));
     382             :   }
     383     5613098 :   return 0;
     384             : }
     385             : /* 0 * pol_x(v) */
     386             : INLINE GEN
     387    15543007 : zeropol(long v) { return pol_0(v); }
     388             : /* vector(n) */
     389             : INLINE GEN
     390    37586889 : zerocol(long n)
     391             : {
     392    37586889 :   GEN y = cgetg(n+1,t_COL);
     393    37587140 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     394    37587140 :   return y;
     395             : }
     396             : /* vectorv(n) */
     397             : INLINE GEN
     398    21784327 : zerovec(long n)
     399             : {
     400    21784327 :   GEN y = cgetg(n+1,t_VEC);
     401    21784331 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     402    21784331 :   return y;
     403             : }
     404             : /* matrix(m, n) */
     405             : INLINE GEN
     406       23555 : zeromat(long m, long n)
     407             : {
     408       23555 :   GEN y = cgetg(n+1,t_MAT);
     409       23555 :   GEN v = zerocol(m);
     410       23555 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     411       23555 :   return y;
     412             : }
     413             : /* = zero_zx, sv is a evalvarn()*/
     414             : INLINE GEN
     415      932946 : zero_Flx(long sv) { return pol0_Flx(sv); }
     416             : INLINE GEN
     417    33653730 : zero_Flv(long n)
     418             : {
     419    33653730 :   GEN y = cgetg(n+1,t_VECSMALL);
     420    33654905 :   long i; for (i=1; i<=n; i++) y[i] = 0;
     421    33654905 :   return y;
     422             : }
     423             : /* matrix(m, n) */
     424             : INLINE GEN
     425      922980 : zero_Flm(long m, long n)
     426             : {
     427      922980 :   GEN y = cgetg(n+1,t_MAT);
     428      922971 :   GEN v = zero_Flv(m);
     429      922972 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     430      922972 :   return y;
     431             : }
     432             : /* matrix(m, n) */
     433             : INLINE GEN
     434      110201 : zero_Flm_copy(long m, long n)
     435             : {
     436      110201 :   GEN y = cgetg(n+1,t_MAT);
     437      110191 :   long i; for (i=1; i<=n; i++) gel(y,i) = zero_Flv(m);
     438      110205 :   return y;
     439             : }
     440             : 
     441             : INLINE GEN
     442      797113 : zero_F2v(long m)
     443             : {
     444      797113 :   long l = nbits2nlong(m);
     445      797113 :   GEN v  = zero_Flv(l+1);
     446      797113 :   v[1] = m;
     447      797113 :   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      277568 : zero_F2m_copy(long m, long n)
     464             : {
     465             :   long i;
     466      277568 :   GEN M = cgetg(n+1, t_MAT);
     467      808204 :   for (i = 1; i <= n; i++)
     468      530636 :     gel(M,i)= zero_F2v(m);
     469      277568 :   return M;
     470             : }
     471             : 
     472             : /* matrix(m, n) */
     473             : INLINE GEN
     474     4890262 : zeromatcopy(long m, long n)
     475             : {
     476     4890262 :   GEN y = cgetg(n+1,t_MAT);
     477     4890262 :   long i; for (i=1; i<=n; i++) gel(y,i) = zerocol(m);
     478     4890262 :   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     1422169 : col_ei(long n, long i) { GEN e = zerocol(n); gel(e,i) = gen_1; return e; }
     494             : INLINE GEN
     495      336194 : 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      683115 : Rg_col_ei(GEN x, long n, long i) { GEN e = zerocol(n); gel(e,i) = x; return e; }
     502             : 
     503             : INLINE GEN
     504    12705509 : shallowcopy(GEN x)
     505    12705509 : { return typ(x) == t_MAT ? RgM_shallowcopy(x): leafcopy(x); }
     506             : 
     507             : /* routines for naive growarrays */
     508             : INLINE GEN
     509    12712023 : vectrunc_init(long l)
     510             : {
     511    12712023 :   GEN z = new_chunk(l);
     512    12712097 :   z[0] = evaltyp(t_VEC) | _evallg(1); return z;
     513             : }
     514             : INLINE GEN
     515         203 : coltrunc_init(long l)
     516             : {
     517         203 :   GEN z = new_chunk(l);
     518         203 :   z[0] = evaltyp(t_COL) | _evallg(1); return z;
     519             : }
     520             : INLINE void
     521   257579128 : lg_increase(GEN x) { x[0]++; }
     522             : INLINE void
     523    51327623 : 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    84513463 : vecsmalltrunc_init(long l)
     534             : {
     535    84513463 :   GEN z = new_chunk(l);
     536    84513463 :   z[0] = evaltyp(t_VECSMALL) | _evallg(1); return z;
     537             : }
     538             : INLINE void
     539    33067368 : 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     1945613 : hash_str(const char *str)
     548             : {
     549     1945613 :   ulong hash = 5381UL, c;
     550    21115327 :   while ( (c = (ulong)*str++) )
     551    17224101 :     hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
     552     1945613 :   return hash;
     553             : }
     554             : INLINE ulong
     555     6583180 : hash_str_len(const char *str, long len)
     556             : {
     557     6583180 :   ulong hash = 5381UL;
     558             :   long i;
     559    24911181 :   for (i = 0; i < len; i++)
     560             :   {
     561    18328001 :     ulong c = (ulong)*str++;
     562    18328001 :     hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
     563             :   }
     564     6583180 :   return hash;
     565             : }
     566             : 
     567             : /*******************************************************************/
     568             : /*                                                                 */
     569             : /*                        VEC / COL / VECSMALL                     */
     570             : /*                                                                 */
     571             : /*******************************************************************/
     572             : /* shallow*/
     573             : INLINE GEN
     574           0 : vec_shorten(GEN v, long n)
     575             : {
     576             :   long i;
     577           0 :   GEN V = cgetg(n+1,t_VEC);
     578           0 :   for(i=1;i<=n;i++) gel(V,i) = gel(v,i);
     579           0 :   return V;
     580             : }
     581             : /* shallow*/
     582             : INLINE GEN
     583       13710 : vec_lengthen(GEN v, long n)
     584             : {
     585             :   long i;
     586       13710 :   long l=lg(v);
     587       13710 :   GEN V = cgetg(n+1,t_VEC);
     588       13710 :   for(i=1;i<l;i++) gel(V,i) = gel(v,i);
     589       13710 :   return V;
     590             : }
     591             : /* shallow*/
     592             : INLINE GEN
     593       63399 : vec_append(GEN V, GEN s)
     594             : {
     595       63399 :   long i, l2 = lg(V);
     596       63399 :   GEN res = cgetg(l2+1, typ(V));
     597       63399 :   for (i = 1; i < l2; ++i) gel(res, i) = gel(V,i);
     598       63399 :   gel(res,l2) = s; return res;
     599             : }
     600             : /* shallow*/
     601             : INLINE GEN
     602        1785 : vec_prepend(GEN v, GEN s)
     603             : {
     604        1785 :   long i, l = lg(v);
     605        1785 :   GEN w = cgetg(l+1, typ(v));
     606        1785 :   gel(w,1) = s;
     607        1785 :   for (i = 2; i <= l; ++i) gel(w,i) = gel(v,i-1);
     608        1785 :   return w;
     609             : }
     610             : /* shallow*/
     611             : INLINE GEN
     612           0 : vec_setconst(GEN v, GEN x)
     613             : {
     614           0 :   long i, l = lg(v);
     615           0 :   for (i = 1; i < l; i++) gel(v,i) = x;
     616           0 :   return v;
     617             : }
     618             : INLINE GEN
     619       41517 : vecsmall_shorten(GEN v, long n)
     620             : {
     621             :   long i;
     622       41517 :   GEN V = cgetg(n+1,t_VECSMALL);
     623       41519 :   for(i=1;i<=n;i++) V[i] = v[i];
     624       41519 :   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     3365444 : vec_to_vecsmall(GEN x)
     637     3365444 : { pari_APPLY_long(itos(gel(x,i))) }
     638             : INLINE GEN
     639      135186 : vecsmall_to_vec(GEN x)
     640      135186 : { pari_APPLY_type(t_VEC, stoi(x[i])) }
     641             : INLINE GEN
     642        1617 : vecsmall_to_vec_inplace(GEN z)
     643             : {
     644        1617 :   long i, l = lg(z);
     645        1617 :   for (i=1; i<l; i++) gel(z,i) = stoi(z[i]);
     646        1617 :   settyp(z, t_VEC); return z;
     647             : }
     648             : INLINE GEN
     649     5227140 : vecsmall_to_col(GEN x)
     650     5227140 : { 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    39719101 :   for (i=1; i<l; i++)
     659    37847279 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     660     1871822 :   if (lx == ly) return 0;
     661          14 :   return (lx < ly)? -1 : 1;
     662             : }
     663             : 
     664             : INLINE int
     665    85155511 : vecsmall_prefixcmp(GEN x, GEN y)
     666             : {
     667    85155511 :   long i, lx = lg(x), ly = lg(y), l = minss(lx,ly);
     668   394027655 :   for (i=1; i<l; i++)
     669   374395014 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     670    19632641 :   return 0;
     671             : }
     672             : 
     673             : /*Can be used on t_VEC, but coeffs not gcopy-ed*/
     674             : INLINE GEN
     675       21176 : vecsmall_prepend(GEN V, long s)
     676             : {
     677       21176 :   long i, l2 = lg(V);
     678       21176 :   GEN res = cgetg(l2+1, typ(V));
     679       21176 :   res[1] = s;
     680       21176 :   for (i = 2; i <= l2; ++i) res[i] = V[i - 1];
     681       21176 :   return res;
     682             : }
     683             : 
     684             : INLINE GEN
     685     3128821 : vecsmall_append(GEN V, long s)
     686             : {
     687     3128821 :   long i, l2 = lg(V);
     688     3128821 :   GEN res = cgetg(l2+1, t_VECSMALL);
     689     3128821 :   for (i = 1; i < l2; ++i) res[i] = V[i];
     690     3128821 :   res[l2] = s; return res;
     691             : }
     692             : 
     693             : INLINE GEN
     694      786515 : vecsmall_concat(GEN u, GEN v)
     695             : {
     696      786515 :   long i, l1 = lg(u)-1, l2 = lg(v)-1;
     697      786515 :   GEN res = cgetg(l1+l2+1, t_VECSMALL);
     698      786515 :   for (i = 1; i <= l1; ++i) res[i]    = u[i];
     699      786515 :   for (i = 1; i <= l2; ++i) res[i+l1] = v[i];
     700      786515 :   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      178823 : vecsmall_max(GEN x)
     742             : {
     743      178823 :   long i, t = x[1], lx = lg(x);
     744      640767 :   for (i=2; i<lx; i++)
     745      461944 :     if (x[i] > t) t = x[i];
     746      178823 :   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    19658392 : QV_isscalar(GEN x)
     777             : {
     778    19658392 :   long lx = lg(x),i;
     779    21251330 :   for (i=2; i<lx; i++)
     780    20637288 :     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    28786651 : RgX_equal_var(GEN x, GEN y) { return varn(x) == varn(y) && RgX_equal(x,y); }
     801             : 
     802             : INLINE int
     803        6511 : RgX_is_rational(GEN x)
     804             : {
     805             :   long i;
     806       30520 :   for (i = lg(x)-1; i > 1; i--)
     807       28405 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     808        2115 :   return 1;
     809             : }
     810             : INLINE int
     811     4466827 : RgX_is_ZX(GEN x)
     812             : {
     813             :   long i;
     814    19188432 :   for (i = lg(x)-1; i > 1; i--)
     815    14774158 :     if (typ(gel(x,i)) != t_INT) return 0;
     816     4414274 :   return 1;
     817             : }
     818             : INLINE int
     819      263284 : RgX_is_QX(GEN x)
     820             : {
     821      263284 :   long k = lg(x)-1;
     822      930361 :   for ( ; k>1; k--)
     823      667322 :     if (!is_rational_t(typ(gel(x,k)))) return 0;
     824      263039 :   return 1;
     825             : }
     826             : INLINE int
     827     2348319 : RgX_is_monomial(GEN x)
     828             : {
     829             :   long i;
     830     2348319 :   if (!signe(x)) return 0;
     831     5858916 :   for (i=lg(x)-2; i>1; i--)
     832     3565548 :     if (!isexactzero(gel(x,i))) return 0;
     833     2293368 :   return 1;
     834             : }
     835             : INLINE int
     836    27439555 : RgV_is_ZV(GEN x)
     837             : {
     838             :   long i;
     839   112521280 :   for (i = lg(x)-1; i > 0; i--)
     840    85083993 :     if (typ(gel(x,i)) != t_INT) return 0;
     841    27437287 :   return 1;
     842             : }
     843             : INLINE int
     844       21130 : RgV_is_QV(GEN x)
     845             : {
     846             :   long i;
     847       84951 :   for (i = lg(x)-1; i > 0; i--)
     848       65445 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     849       19506 :   return 1;
     850             : }
     851             : 
     852             : /********************************************************************/
     853             : /**                                                                **/
     854             : /**            Dynamic arrays implementation                       **/
     855             : /**                                                                **/
     856             : /********************************************************************/
     857             : INLINE void **
     858   403429805 : pari_stack_base(pari_stack *s) { return s->data; }
     859             : 
     860             : INLINE void
     861     1789242 : pari_stack_init(pari_stack *s, size_t size, void **data)
     862             : {
     863     1789242 :   s->data = data;
     864     1789242 :   *data = NULL;
     865     1789242 :   s->n = 0;
     866     1789242 :   s->alloc = 0;
     867     1789242 :   s->size = size;
     868     1789242 : }
     869             : 
     870             : INLINE void
     871   401688220 : pari_stack_alloc(pari_stack *s, long nb)
     872             : {
     873   401688220 :   void **sdat = pari_stack_base(s);
     874   401688959 :   long alloc = s->alloc;
     875   401688959 :   if (s->n+nb <= alloc) return;
     876      659838 :   if (!alloc)
     877      606615 :     alloc = nb;
     878             :   else
     879             :   {
     880       53223 :     while (s->n+nb > alloc) alloc <<= 1;
     881             :   }
     882      659838 :   *sdat = pari_realloc(*sdat,alloc*s->size);
     883      660730 :   s->alloc = alloc;
     884             : }
     885             : 
     886             : INLINE long
     887   323956000 : pari_stack_new(pari_stack *s) { pari_stack_alloc(s, 1); return s->n++; }
     888             : 
     889             : INLINE void
     890     1740600 : pari_stack_delete(pari_stack *s)
     891             : {
     892     1740600 :   void **sdat = pari_stack_base(s);
     893     1738651 :   if (*sdat) pari_free(*sdat);
     894     1748741 : }
     895             : 
     896             : INLINE void
     897        4808 : pari_stack_pushp(pari_stack *s, void *u)
     898             : {
     899        4808 :   long n = pari_stack_new(s);
     900        4808 :   void **sdat =(void**) *pari_stack_base(s);
     901        4808 :   sdat[n] = u;
     902        4808 : }
     903             : 
     904             : /*******************************************************************/
     905             : /*                                                                 */
     906             : /*                            EXTRACT                              */
     907             : /*                                                                 */
     908             : /*******************************************************************/
     909             : INLINE GEN
     910   202285761 : vecslice(GEN A, long y1, long y2)
     911             : {
     912   202285761 :   long i,lB = y2 - y1 + 2;
     913   202285761 :   GEN B = cgetg(lB, typ(A));
     914   202283317 :   for (i=1; i<lB; i++) B[i] = A[y1-1+i];
     915   202283317 :   return B;
     916             : }
     917             : INLINE GEN
     918      816368 : vecslicepermute(GEN A, GEN p, long y1, long y2)
     919             : {
     920      816368 :   long i,lB = y2 - y1 + 2;
     921      816368 :   GEN B = cgetg(lB, typ(A));
     922      816366 :   for (i=1; i<lB; i++) B[i] = A[p[y1-1+i]];
     923      816366 :   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    22367966 : rowslice(GEN x, long j1, long j2)
     932    22367966 : { pari_APPLY_same(vecslice(gel(x,i), j1, j2)) }
     933             : 
     934             : INLINE GEN
     935     3703609 : matslice(GEN A, long x1, long x2, long y1, long y2)
     936     3703609 : { 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      263753 : vecsplice(GEN a, long j)
     946             : {
     947      263753 :   long i, k, l = lg(a);
     948             :   GEN b;
     949      263753 :   if (l == 1) pari_err(e_MISC, "incorrect component in vecsplice");
     950      263753 :   b = cgetg(l-1, typ(a));
     951     1053934 :   for (i = k = 1; i < l; i++)
     952      790181 :     if (i != j) gel(b, k++) = gel(a,i);
     953      263753 :   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     3759425 : Flm_row(GEN x, long j)
     971     3759425 : { pari_APPLY_ulong((ulong)coeff(x, j, i)) }
     972             : /* A[x0,] */
     973             : INLINE GEN
     974      204820 : rowcopy(GEN x, long j)
     975      204820 : { pari_APPLY_type(t_VEC, gcopy(gcoeff(x, j, i))) }
     976             : /* A[x0, x1..x2] */
     977             : INLINE GEN
     978        2303 : row_i(GEN A, long x0, long x1, long x2)
     979             : {
     980        2303 :   long i, lB = x2 - x1 + 2;
     981        2303 :   GEN B  = cgetg(lB, t_VEC);
     982        2303 :   for (i=x1; i<=x2; i++) gel(B, i) = gcoeff(A, x0, i);
     983        2303 :   return B;
     984             : }
     985             : 
     986             : INLINE GEN
     987     5830525 : vecreverse(GEN A)
     988             : {
     989             :   long i, l;
     990     5830525 :   GEN B = cgetg_copy(A, &l);
     991     5830525 :   for (i=1; i<l; i++) gel(B, i) = gel(A, l-i);
     992     5830525 :   return B;
     993             : }
     994             : 
     995             : INLINE GEN
     996         329 : vecsmall_reverse(GEN A)
     997             : {
     998             :   long i, l;
     999         329 :   GEN B = cgetg_copy(A, &l);
    1000         329 :   for (i=1; i<l; i++) B[i] = A[l-i];
    1001         329 :   return B;
    1002             : }
    1003             : 
    1004             : INLINE void
    1005         253 : vecreverse_inplace(GEN y)
    1006             : {
    1007         253 :   long l = lg(y), lim = l>>1, i;
    1008         717 :   for (i = 1; i <= lim; i++)
    1009             :   {
    1010         464 :     GEN z = gel(y,i);
    1011         464 :     gel(y,i)    = gel(y,l-i);
    1012         464 :     gel(y,l-i) = z;
    1013             :   }
    1014         253 : }
    1015             : 
    1016             : INLINE GEN
    1017    45409224 : vecsmallpermute(GEN A, GEN p) { return perm_mul(A, p); }
    1018             : 
    1019             : INLINE GEN
    1020     6508520 : vecpermute(GEN A, GEN x)
    1021     6508520 : { pari_APPLY_type(typ(A), gel(A, x[i])) }
    1022             : 
    1023             : INLINE GEN
    1024     3011330 : rowpermute(GEN x, GEN p)
    1025     3011330 : { 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      728166 : identity_perm(long n)
    1036             : {
    1037      728166 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1038             :   long i;
    1039      728164 :   for (i = 1; i <= n; i++) perm[i] = i;
    1040      728164 :   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    46653137 : perm_mul(GEN s, GEN x)
    1057    46653137 : { pari_APPLY_long(s[x[i]]) }
    1058             : 
    1059             : /* Compute the inverse (reciprocal) of a permutation. */
    1060             : INLINE GEN
    1061     1161997 : perm_inv(GEN x)
    1062             : {
    1063             :   long i, lx;
    1064     1161997 :   GEN y = cgetg_copy(x, &lx);
    1065     1161997 :   for (i=1; i<lx; i++) y[ x[i] ] = i;
    1066     1161997 :   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    72236392 : pari_free(void *pointer)
    1106             : {
    1107    72236392 :   BLOCK_SIGINT_START;
    1108    72253433 :   free(pointer);
    1109    72253433 :   BLOCK_SIGINT_END;
    1110    72249500 : }
    1111             : INLINE void*
    1112   279240340 : pari_malloc(size_t size)
    1113             : {
    1114   279240340 :   if (size)
    1115             :   {
    1116             :     char *tmp;
    1117   279240340 :     BLOCK_SIGINT_START;
    1118   279243543 :     tmp = (char*)malloc(size);
    1119   279243543 :     BLOCK_SIGINT_END;
    1120   279243183 :     if (!tmp) pari_err(e_MEM);
    1121   279243183 :     return tmp;
    1122             :   }
    1123           0 :   return NULL;
    1124             : }
    1125             : INLINE void*
    1126      674560 : pari_realloc(void *pointer, size_t size)
    1127             : {
    1128             :   char *tmp;
    1129             : 
    1130      674560 :   BLOCK_SIGINT_START;
    1131      676320 :   if (!pointer) tmp = (char *) malloc(size);
    1132       57043 :   else tmp = (char *) realloc(pointer,size);
    1133      676320 :   BLOCK_SIGINT_END;
    1134      675798 :   if (!tmp) pari_err(e_MEM);
    1135      675798 :   return tmp;
    1136             : }
    1137             : INLINE void*
    1138       37321 : pari_calloc(size_t size)
    1139             : {
    1140       37321 :   void *t = pari_malloc(size);
    1141       37321 :   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  3806273330 : icopy_avma(GEN x, pari_sp av)
    1158             : {
    1159  3806273330 :   long i = lgefint(x), lx = i;
    1160  3806273330 :   GEN y = ((GEN)av) - i;
    1161  3806273330 :   while (--i > 0) y[i] = x[i];
    1162  3806273330 :   y[0] = evaltyp(t_INT)|evallg(lx);
    1163  3806119310 :   return y;
    1164             : }
    1165             : /* copy leaf x as if we had set_avma(av) */
    1166             : INLINE GEN
    1167   177554730 : leafcopy_avma(GEN x, pari_sp av)
    1168             : {
    1169   177554730 :   long i = lg(x);
    1170   177554730 :   GEN y = ((GEN)av) - i;
    1171   177554730 :   while (--i > 0) y[i] = x[i];
    1172   177554730 :   y[0] = x[0] & (~CLONEBIT);
    1173   177554730 :   return y;
    1174             : }
    1175             : INLINE GEN
    1176   651790314 : gerepileuptoleaf(pari_sp av, GEN x)
    1177             : {
    1178             :   long lx;
    1179             :   GEN q;
    1180             : 
    1181   651790314 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1182   651834163 :   lx = lg(x);
    1183   651834163 :   q = ((GEN)av) - lx;
    1184   651834163 :   set_avma((pari_sp)q);
    1185   653060169 :   while (--lx >= 0) q[lx] = x[lx];
    1186   653060169 :   return q;
    1187             : }
    1188             : INLINE GEN
    1189  1280147878 : gerepileuptoint(pari_sp av, GEN x)
    1190             : {
    1191  1280147878 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1192  1132081011 :   set_avma((pari_sp)icopy_avma(x, av));
    1193  1134438318 :   return (GEN)avma;
    1194             : }
    1195             : INLINE GEN
    1196   806468040 : gerepileupto(pari_sp av, GEN x)
    1197             : {
    1198   806468040 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1199   716959124 :   switch(typ(x))
    1200             :   { /* non-default = !is_recursive_t(tq) */
    1201   252557883 :     case t_INT: return gerepileuptoint(av, x);
    1202             :     case t_REAL:
    1203             :     case t_STR:
    1204   145568868 :     case t_VECSMALL: return gerepileuptoleaf(av,x);
    1205             :     default:
    1206             :       /* NB: x+i --> ((long)x) + i*sizeof(long) */
    1207   318832373 :       return gerepile(av, (pari_sp) (x+lg(x)), x);
    1208             :   }
    1209             : }
    1210             : INLINE double
    1211     2270182 : gc_double(pari_sp av, double d) { set_avma(av); return d; }
    1212             : INLINE long
    1213   112961398 : gc_long(pari_sp av, long s) { set_avma(av); return s; }
    1214             : INLINE ulong
    1215    15279026 : gc_ulong(pari_sp av, ulong s) { set_avma(av); return s; }
    1216             : INLINE int
    1217    21949956 : gc_bool(pari_sp av, int s) { set_avma(av); return s; }
    1218             : INLINE int
    1219     3366417 : gc_int(pari_sp av, int s) { set_avma(av); return s; }
    1220             : INLINE GEN
    1221     1613275 : gc_NULL(pari_sp av) { set_avma(av); return NULL; }
    1222             : 
    1223             : /* gerepileupto(av, gcopy(x)) */
    1224             : INLINE GEN
    1225    53206747 : gerepilecopy(pari_sp av, GEN x)
    1226             : {
    1227    53206747 :   if (is_recursive_t(typ(x)))
    1228             :   {
    1229    48590878 :     GENbin *p = copy_bin(x);
    1230    48591318 :     set_avma(av); return bin_copy(p);
    1231             :   }
    1232             :   else
    1233             :   {
    1234     4615874 :     set_avma(av);
    1235     4615874 :     if (x < (GEN)av) {
    1236     3128444 :       if (x < (GEN)pari_mainstack->bot) new_chunk(lg(x));
    1237     3128444 :       x = leafcopy_avma(x, av);
    1238     3128445 :       set_avma((pari_sp)x);
    1239             :     } else
    1240     1487430 :       x = leafcopy(x);
    1241     4615874 :     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      199026 : gerepilemany(pari_sp av, GEN* gptr[], int n)
    1250             : {
    1251             :   int i;
    1252      199026 :   for (i=0; i<n; i++) *gptr[i] = (GEN)copy_bin(*gptr[i]);
    1253      199026 :   set_avma(av);
    1254      199026 :   for (i=0; i<n; i++) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1255      199026 : }
    1256             : 
    1257             : INLINE void
    1258     7578172 : gerepileall(pari_sp av, int n, ...)
    1259             : {
    1260             :   int i;
    1261     7578172 :   va_list a; va_start(a, n);
    1262     7578172 :   if (n < 10)
    1263             :   {
    1264             :     GEN *gptr[10];
    1265    21944868 :     for (i=0; i<n; i++)
    1266    14366652 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1267     7578216 :     set_avma(av);
    1268     7578115 :     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     7578316 :   va_end(a);
    1281     7578316 : }
    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    63570035 : bin_copy(GENbin *p)
    1295             : {
    1296             :   GEN x, y, base;
    1297             :   long dx, len;
    1298             : 
    1299    63570035 :   x   = p->x; if (!x) { pari_free(p); return gen_0; }
    1300    63562838 :   len = p->len;
    1301    63562838 :   base= p->base; dx = x - base;
    1302    63562838 :   y = (GEN)memcpy((void*)new_chunk(len), (void*)GENbinbase(p), len*sizeof(long));
    1303    63562853 :   y += dx;
    1304    63562853 :   p->rebase(y, ((ulong)y-(ulong)x));
    1305    63562922 :   pari_free(p); return y;
    1306             : }
    1307             : 
    1308             : INLINE GEN
    1309   127133154 : GENbinbase(GENbin *p) { return (GEN)(p + 1); }
    1310             : 
    1311             : INLINE void
    1312    31941412 : cgiv(GEN x)
    1313             : {
    1314    31941412 :   pari_sp av = (pari_sp)(x+lg(x));
    1315    31941412 :   if (isonstack((GEN)av)) set_avma(av);
    1316    31940931 : }
    1317             : 
    1318             : INLINE void
    1319     1287529 : killblock(GEN x) { gunclone(x); }
    1320             : 
    1321             : INLINE int
    1322    25905467 : 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     3427590 : cxcompotor(GEN z, long prec)
    1332             : {
    1333     3427590 :   switch(typ(z))
    1334             :   {
    1335     1867963 :     case t_INT:  return itor(z, prec);
    1336      136234 :     case t_FRAC: return fractor(z, prec);
    1337     1423393 :     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     1700376 : cxtofp(GEN x, long prec)
    1344     1700376 : { retmkcomplex(cxcompotor(gel(x,1),prec), cxcompotor(gel(x,2),prec)); }
    1345             : 
    1346             : INLINE GEN
    1347      291144 : cxtoreal(GEN q)
    1348      291144 : { return (typ(q) == t_COMPLEX && gequal0(gel(q,2)))? gel(q,1): q; }
    1349             : 
    1350             : INLINE double
    1351    33832985 : gtodouble(GEN x)
    1352             : {
    1353    33832985 :   if (typ(x)!=t_REAL) {
    1354     7449634 :     pari_sp av = avma;
    1355     7449634 :     x = gtofp(x, DEFAULTPREC);
    1356     7449634 :     if (typ(x)!=t_REAL) pari_err_TYPE("gtodouble [t_REAL expected]", x);
    1357     7449634 :     set_avma(av);
    1358             :   }
    1359    33832985 :   return rtodbl(x);
    1360             : }
    1361             : INLINE long
    1362    73368736 : gtos(GEN x) {
    1363    73368736 :   if (typ(x) != t_INT) pari_err_TYPE("gtos [integer expected]",x);
    1364    73368729 :   return itos(x);
    1365             : }
    1366             : 
    1367             : INLINE ulong
    1368      152327 : gtou(GEN x) {
    1369      152327 :   if (typ(x) != t_INT || signe(x)<0)
    1370           0 :     pari_err_TYPE("gtou [integer >=0 expected]",x);
    1371      152339 :   return itou(x);
    1372             : }
    1373             : 
    1374             : INLINE GEN
    1375    23087107 : absfrac(GEN x)
    1376             : {
    1377    23087107 :   GEN y = cgetg(3, t_FRAC);
    1378    23087107 :   gel(y,1) = absi(gel(x,1));
    1379    23087107 :   gel(y,2) = icopy(gel(x,2)); return y;
    1380             : }
    1381             : INLINE GEN
    1382       32665 : absfrac_shallow(GEN x)
    1383       32665 : { return signe(gel(x,1))>0? x: mkfrac(negi(gel(x,1)), gel(x,2)); }
    1384             : INLINE GEN
    1385     7765031 : Q_abs(GEN x) { return (typ(x) == t_INT)? absi(x): absfrac(x); }
    1386             : INLINE GEN
    1387      130772 : Q_abs_shallow(GEN x)
    1388      130772 : { 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    35757098 : gtofp(GEN z, long prec)
    1399             : {
    1400    35757098 :   switch(typ(z))
    1401             :   {
    1402    22453462 :     case t_INT:  return itor(z, prec);
    1403     4311151 :     case t_FRAC: return fractor(z, prec);
    1404     7524031 :     case t_REAL: return rtor(z, prec);
    1405             :     case t_COMPLEX: {
    1406     1468454 :       GEN a = gel(z,1), b = gel(z,2);
    1407     1468454 :       if (isintzero(b)) return cxcompotor(a, prec);
    1408     1465938 :       if (isintzero(a)) {
    1409        2128 :         GEN y = cgetg(3, t_COMPLEX);
    1410        2128 :         b = cxcompotor(b, prec);
    1411        2128 :         gel(y,1) = real_0_bit(expo(b) - prec2nbits(prec));
    1412        2128 :         gel(y,2) = b; return y;
    1413             :       }
    1414     1463810 :       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      757416 : RgX_gtofp(GEN x, long prec)
    1439             : {
    1440             :   long l;
    1441      757416 :   GEN y = cgetg_copy(x, &l);
    1442      757416 :   while (--l > 1) gel(y,l) = gtofp(gel(x,l), prec);
    1443      757416 :   y[1] = x[1]; return y;
    1444             : }
    1445             : INLINE GEN
    1446     1192232 : RgC_gtofp(GEN x, long prec)
    1447     1192232 : { 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      134578 : RgM_gtofp(GEN x, long prec)
    1455      134578 : { 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      187194 : RgC_fpnorml2(GEN x, long prec)
    1473             : {
    1474      187194 :   pari_sp av = avma;
    1475      187194 :   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      260929 : affc_fixlg(GEN x, GEN res)
    1500             : {
    1501      260929 :   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       53414 :     set_avma((pari_sp)(res+3));
    1509       53414 :     res = cgetr(realprec(gel(res,1)));
    1510       53414 :     affrr_fixlg(x, res);
    1511             :   }
    1512      260929 :   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       28947 : ndec2nlong(long x) { return 1 + (long)((x)*(LOG2_10/BITS_IN_LONG)); }
    1525             : INLINE long
    1526       20469 : ndec2prec(long x) { return 2 + ndec2nlong(x); }
    1527             : INLINE long
    1528        8478 : 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     1191972 : nbits2nlong(long x) {
    1534     1191972 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1535             : }
    1536             : 
    1537             : INLINE long
    1538   316911604 : nbits2extraprec(long x) {
    1539   316911604 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1540             : }
    1541             : 
    1542             : /* Fast implementation of 2 + nbits2nlong(x) */
    1543             : INLINE long
    1544   109501037 : nbits2prec(long x) {
    1545   109501037 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1546             : }
    1547             : INLINE long
    1548     7699696 : nbits2lg(long x) {
    1549     7699696 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1550             : }
    1551             : /* ceil(x / sizeof(long)) */
    1552             : INLINE long
    1553     9966008 : nchar2nlong(long x) {
    1554     9966008 :   return (long)(((ulong)x+sizeof(long)-1) >> (TWOPOTBITS_IN_LONG-3L));
    1555             : }
    1556             : INLINE long
    1557  1164121995 : prec2nbits(long x) { return (x-2) * BITS_IN_LONG; }
    1558             : INLINE double
    1559      564559 : bit_accuracy_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1560             : INLINE double
    1561      302041 : prec2nbits_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1562             : INLINE long
    1563    32642587 : bit_prec(GEN x) { return prec2nbits(realprec(x)); }
    1564             : INLINE long
    1565  1050225164 : bit_accuracy(long x) { return prec2nbits(x); }
    1566             : INLINE long
    1567       12448 : 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        3143 : precdbl(long x) {return (x - 1) << 1;}
    1572             : INLINE long
    1573  3478418000 : divsBIL(long n) { return n >> TWOPOTBITS_IN_LONG; }
    1574             : INLINE long
    1575  3433652649 : 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    35460446 : Fp_red(GEN a, GEN m) { return modii(a, m); }
    1586             : INLINE GEN
    1587    72442503 : Fp_add(GEN a, GEN b, GEN m)
    1588             : {
    1589    72442503 :   pari_sp av=avma;
    1590    72442503 :   GEN p = addii(a,b);
    1591    70900139 :   long s = signe(p);
    1592    70900139 :   if (!s) return p; /* = gen_0 */
    1593    63111387 :   if (s > 0) /* general case */
    1594             :   {
    1595    62884950 :     GEN t = subii(p, m);
    1596    63854933 :     s = signe(t);
    1597    63854933 :     if (!s) { set_avma(av); return gen_0; }
    1598    58022769 :     if (s < 0) { set_avma((pari_sp)p); return p; }
    1599    24505258 :     if (cmpii(t, m) < 0) return gerepileuptoint(av, t); /* general case ! */
    1600     1112566 :     p = remii(t, m);
    1601             :   }
    1602             :   else
    1603      226437 :     p = modii(p, m);
    1604     1339003 :   return gerepileuptoint(av, p);
    1605             : }
    1606             : INLINE GEN
    1607    57067368 : Fp_sub(GEN a, GEN b, GEN m)
    1608             : {
    1609    57067368 :   pari_sp av=avma;
    1610    57067368 :   GEN p = subii(a,b);
    1611    56366272 :   long s = signe(p);
    1612    56366272 :   if (!s) return p; /* = gen_0 */
    1613    50116098 :   if (s > 0)
    1614             :   {
    1615    24223963 :     if (cmpii(p, m) < 0) return p; /* general case ! */
    1616     1120757 :     p = remii(p, m);
    1617             :   }
    1618             :   else
    1619             :   {
    1620    25892135 :     GEN t = addii(p, m);
    1621    25822470 :     if (!s) { set_avma(av); return gen_0; }
    1622    25822470 :     if (s > 0) return gerepileuptoint(av, t); /* general case ! */
    1623    25822470 :     p = modii(t, m);
    1624             :   }
    1625    27231905 :   return gerepileuptoint(av, p);
    1626             : }
    1627             : INLINE GEN
    1628    13562410 : Fp_neg(GEN b, GEN m)
    1629             : {
    1630    13562410 :   pari_sp av = avma;
    1631    13562410 :   long s = signe(b);
    1632             :   GEN p;
    1633    13562410 :   if (!s) return gen_0;
    1634    10076071 :   if (s > 0)
    1635             :   {
    1636     9854113 :     p = subii(m, b);
    1637     9850941 :     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    16713803 : Fp_center(GEN u, GEN p, GEN ps2)
    1654    16713803 : { return abscmpii(u,ps2)<=0? icopy(u): subii(u,p); }
    1655             : /* same without copy */
    1656             : INLINE GEN
    1657    15267723 : Fp_center_i(GEN u, GEN p, GEN ps2)
    1658    15267723 : { return abscmpii(u,ps2)<=0? u: subii(u,p); }
    1659             : 
    1660             : /* x + y*z mod p */
    1661             : INLINE GEN
    1662     5058203 : Fp_addmul(GEN x, GEN y, GEN z, GEN p)
    1663             : {
    1664             :   pari_sp av;
    1665     5058203 :   if (!signe(y) || !signe(z)) return Fp_red(x, p);
    1666     4760916 :   if (!signe(x)) return Fp_mul(z,y, p);
    1667     4457473 :   av = avma;
    1668     4457473 :   return gerepileuptoint(av, modii(addii(x, mulii(y,z)), p));
    1669             : }
    1670             : 
    1671             : INLINE GEN
    1672    92221687 : Fp_mul(GEN a, GEN b, GEN m)
    1673             : {
    1674    92221687 :   pari_sp av=avma;
    1675             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1676    92221687 :   (void)new_chunk(lg(a)+lg(b)+(lg(m)<<1));
    1677    92246851 :   p = mulii(a,b);
    1678    92316321 :   set_avma(av); return modii(p,m);
    1679             : }
    1680             : INLINE GEN
    1681    34125240 : Fp_sqr(GEN a, GEN m)
    1682             : {
    1683    34125240 :   pari_sp av=avma;
    1684             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1685    34125240 :   (void)new_chunk((lg(a)+lg(m))<<1);
    1686    34424692 :   p = sqri(a);
    1687    30887814 :   set_avma(av); return remii(p,m); /*Use remii: p >= 0 */
    1688             : }
    1689             : INLINE GEN
    1690    66099345 : Fp_mulu(GEN a, ulong b, GEN m)
    1691             : {
    1692    66099345 :   long l = lgefint(m);
    1693    66099345 :   if (l == 3)
    1694             :   {
    1695    39898949 :     ulong mm = m[2];
    1696    39898949 :     return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1697             :   } else {
    1698    26200396 :     pari_sp av = avma;
    1699             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1700    26200396 :     (void)new_chunk(lg(a)+1+(l<<1));
    1701    26238309 :     p = muliu(a,b);
    1702    24345733 :     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     9623477 : Fp_inv(GEN a, GEN m)
    1730             : {
    1731             :   GEN res;
    1732     9623477 :   if (! invmod(a,m,&res)) pari_err_INV("Fp_inv", mkintmod(res,m));
    1733     9623193 :   return res;
    1734             : }
    1735             : INLINE GEN
    1736      318439 : Fp_invsafe(GEN a, GEN m)
    1737             : {
    1738             :   GEN res;
    1739      318439 :   if (! invmod(a,m,&res)) return NULL;
    1740      318439 :   return res;
    1741             : }
    1742             : INLINE GEN
    1743     1655633 : Fp_div(GEN a, GEN b, GEN m)
    1744             : {
    1745     1655633 :   pari_sp av = avma;
    1746             :   GEN p;
    1747     1655633 :   if (lgefint(b) == 3)
    1748             :   {
    1749      668261 :     a = Fp_divu(a, b[2], m);
    1750      668261 :     if (signe(b) < 0) a = Fp_neg(a, m);
    1751      668261 :     return a;
    1752             :   }
    1753             :   /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1754      987372 :   (void)new_chunk(lg(a)+(lg(m)<<1));
    1755      987372 :   p = mulii(a, Fp_inv(b,m));
    1756      987372 :   set_avma(av); return modii(p,m);
    1757             : }
    1758             : INLINE GEN
    1759     1401785 : Fp_divu(GEN x, ulong a, GEN p)
    1760             : {
    1761     1401785 :   pari_sp av = avma;
    1762             :   ulong b;
    1763     1401785 :   if (lgefint(p) == 3)
    1764             :   {
    1765      984012 :     ulong pp = p[2], xp = umodiu(x, pp);
    1766      984012 :     return xp? utoipos(Fl_div(xp, a % pp, pp)): gen_0;
    1767             :   }
    1768      417773 :   x = Fp_red(x, p);
    1769      417773 :   b = Fl_neg(Fl_div(umodiu(x,a), umodiu(p,a), a), a); /* x + pb = 0 (mod a) */
    1770      417775 :   return gerepileuptoint(av, diviuexact(addmuliu(x, p, b), a));
    1771             : }
    1772             : 
    1773             : INLINE GEN
    1774      847368 : Flx_mulu(GEN x, ulong a, ulong p) { return Flx_Fl_mul(x,a%p,p); }
    1775             : 
    1776             : INLINE GEN
    1777           0 : get_F2x_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1778             : 
    1779             : INLINE long
    1780      448552 : get_F2x_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1781             : 
    1782             : INLINE long
    1783      121548 : get_F2x_degree(GEN T) { return typ(T)==t_VEC? F2x_degree(gel(T,2)): F2x_degree(T); }
    1784             : 
    1785             : INLINE GEN
    1786         378 : get_F2xqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1787             : 
    1788             : INLINE long
    1789      376495 : get_F2xqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1790             : 
    1791             : INLINE long
    1792      201684 : get_F2xqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1793             : 
    1794             : INLINE GEN
    1795     7585745 : get_Flx_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1796             : 
    1797             : INLINE long
    1798    16822901 : get_Flx_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1799             : 
    1800             : INLINE long
    1801    36489508 : get_Flx_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1802             : 
    1803             : INLINE GEN
    1804        2461 : get_FlxqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1805             : 
    1806             : INLINE long
    1807      368938 : get_FlxqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1808             : 
    1809             : INLINE long
    1810      155787 : get_FlxqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1811             : 
    1812             : INLINE GEN
    1813     1631497 : get_FpX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1814             : 
    1815             : INLINE long
    1816     3672336 : get_FpX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1817             : 
    1818             : INLINE long
    1819     2627881 : get_FpX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1820             : 
    1821             : INLINE GEN
    1822      142586 : get_FpXQX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1823             : 
    1824             : INLINE long
    1825       57364 : get_FpXQX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1826             : 
    1827             : INLINE long
    1828        2187 : get_FpXQX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1829             : 
    1830             : /*******************************************************************/
    1831             : /*                                                                 */
    1832             : /*                        ADDMULII / SUBMULII                      */
    1833             : /*                                                                 */
    1834             : /*******************************************************************/
    1835             : /* x - y*z */
    1836             : INLINE GEN
    1837    13447187 : submulii(GEN x, GEN y, GEN z)
    1838             : {
    1839    13447187 :   long lx = lgefint(x), ly, lz;
    1840             :   pari_sp av;
    1841             :   GEN t;
    1842    13447187 :   if (lx == 2) { t = mulii(z,y); togglesign(t); return t; }
    1843    11634187 :   ly = lgefint(y);
    1844    11634187 :   if (ly == 2) return icopy(x);
    1845    10497978 :   lz = lgefint(z);
    1846    10497978 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1847    10497978 :   t = mulii(z, y);
    1848    10497978 :   set_avma(av); return subii(x,t);
    1849             : }
    1850             : /* y*z - x */
    1851             : INLINE GEN
    1852     1238672 : mulsubii(GEN y, GEN z, GEN x)
    1853             : {
    1854     1238672 :   long lx = lgefint(x), ly, lz;
    1855             :   pari_sp av;
    1856             :   GEN t;
    1857     1238672 :   if (lx == 2) return mulii(z,y);
    1858      788797 :   ly = lgefint(y);
    1859      788797 :   if (ly == 2) return negi(x);
    1860      723511 :   lz = lgefint(z);
    1861      723511 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1862      723511 :   t = mulii(z, y);
    1863      723511 :   set_avma(av); return subii(t,x);
    1864             : }
    1865             : 
    1866             : /* x - u*y */
    1867             : INLINE GEN
    1868        7595 : submuliu(GEN x, GEN y, ulong u)
    1869             : {
    1870             :   pari_sp av;
    1871        7595 :   long ly = lgefint(y);
    1872        7595 :   if (ly == 2) return icopy(x);
    1873        7595 :   av = avma;
    1874        7595 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1875        7595 :   y = mului(u,y);
    1876        7595 :   set_avma(av); return subii(x, y);
    1877             : }
    1878             : /* x + u*y */
    1879             : INLINE GEN
    1880      425370 : addmuliu(GEN x, GEN y, ulong u)
    1881             : {
    1882             :   pari_sp av;
    1883      425370 :   long ly = lgefint(y);
    1884      425370 :   if (ly == 2) return icopy(x);
    1885      425370 :   av = avma;
    1886      425370 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1887      425370 :   y = mului(u,y);
    1888      425367 :   set_avma(av); return addii(x, y);
    1889             : }
    1890             : /* x - u*y */
    1891             : INLINE GEN
    1892   122920269 : submuliu_inplace(GEN x, GEN y, ulong u)
    1893             : {
    1894             :   pari_sp av;
    1895   122920269 :   long ly = lgefint(y);
    1896   122920269 :   if (ly == 2) return x;
    1897    98460332 :   av = avma;
    1898    98460332 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1899    98460332 :   y = mului(u,y);
    1900    98460332 :   set_avma(av); return subii(x, y);
    1901             : }
    1902             : /* x + u*y */
    1903             : INLINE GEN
    1904   121400247 : addmuliu_inplace(GEN x, GEN y, ulong u)
    1905             : {
    1906             :   pari_sp av;
    1907   121400247 :   long ly = lgefint(y);
    1908   121400247 :   if (ly == 2) return x;
    1909    98344774 :   av = avma;
    1910    98344774 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1911    98344774 :   y = mului(u,y);
    1912    98344774 :   set_avma(av); return addii(x, y);
    1913             : }
    1914             : /* ux + vy */
    1915             : INLINE GEN
    1916    20674261 : lincombii(GEN u, GEN v, GEN x, GEN y)
    1917             : {
    1918    20674261 :   long lx = lgefint(x), ly;
    1919             :   GEN p1, p2;
    1920             :   pari_sp av;
    1921    20674261 :   if (lx == 2) return mulii(v,y);
    1922    14585996 :   ly = lgefint(y);
    1923    14585996 :   if (ly == 2) return mulii(u,x);
    1924    13360636 :   av = avma; (void)new_chunk(lx+ly+lgefint(u)+lgefint(v)); /* HACK */
    1925    13360650 :   p1 = mulii(u,x);
    1926    13360519 :   p2 = mulii(v,y);
    1927    13360528 :   set_avma(av); return addii(p1,p2);
    1928             : }
    1929             : 
    1930             : /*******************************************************************/
    1931             : /*                                                                 */
    1932             : /*                          GEN SUBTYPES                           */
    1933             : /*                                                                 */
    1934             : /*******************************************************************/
    1935             : 
    1936             : INLINE int
    1937  1255194802 : is_const_t(long t) { return (t < t_POLMOD); }
    1938             : INLINE int
    1939        5479 : is_extscalar_t(long t) { return (t <= t_POL); }
    1940             : INLINE int
    1941     1224304 : is_intreal_t(long t) { return (t <= t_REAL); }
    1942             : INLINE int
    1943   416923508 : is_matvec_t(long t) { return (t >= t_VEC && t <= t_MAT); }
    1944             : INLINE int
    1945    60096902 : is_noncalc_t(long tx) { return (tx) >= t_LIST; }
    1946             : INLINE int
    1947     1208372 : is_rational_t(long t) { return (t == t_INT || t == t_FRAC); }
    1948             : INLINE int
    1949      504275 : is_real_t(long t) { return (t == t_INT || t == t_REAL || t == t_FRAC); }
    1950             : INLINE int
    1951  3047596459 : is_recursive_t(long t) { return lontyp[t]; }
    1952             : INLINE int
    1953   191142903 : is_scalar_t(long t) { return (t < t_POL); }
    1954             : INLINE int
    1955     1499606 : is_vec_t(long t) { return (t == t_VEC || t == t_COL); }
    1956             : 
    1957             : /*******************************************************************/
    1958             : /*                                                                 */
    1959             : /*                         TRANSCENDENTAL                          */
    1960             : /*                                                                 */
    1961             : /*******************************************************************/
    1962             : INLINE GEN
    1963    22377330 : sqrtr(GEN x) {
    1964    22377330 :   long s = signe(x);
    1965    22377330 :   if (s == 0) return real_0_bit(expo(x) >> 1);
    1966    22343662 :   if (s >= 0) return sqrtr_abs(x);
    1967       34618 :   retmkcomplex(gen_0, sqrtr_abs(x));
    1968             : }
    1969             : INLINE GEN
    1970           0 : cbrtr_abs(GEN x) { return sqrtnr_abs(x, 3); }
    1971             : INLINE GEN
    1972           0 : cbrtr(GEN x) {
    1973           0 :   long s = signe(x);
    1974             :   GEN r;
    1975           0 :   if (s == 0) return real_0_bit(expo(x) / 3);
    1976           0 :   r = cbrtr_abs(x);
    1977           0 :   if (s < 0) togglesign(r);
    1978           0 :   return r;
    1979             : }
    1980             : INLINE GEN
    1981      462323 : sqrtnr(GEN x, long n) {
    1982      462323 :   long s = signe(x);
    1983             :   GEN r;
    1984      462323 :   if (s == 0) return real_0_bit(expo(x) / n);
    1985      462323 :   r = sqrtnr_abs(x, n);
    1986      462323 :   if (s < 0) pari_err_IMPL("sqrtnr for x < 0");
    1987      462323 :   return r;
    1988             : }
    1989             : INLINE long
    1990      221139 : logint(GEN B, GEN y) { return logintall(B,y,NULL); }
    1991             : INLINE ulong
    1992     1997406 : ulogint(ulong B, ulong y)
    1993             : {
    1994             :   ulong r;
    1995             :   long e;
    1996     1997406 :   if (y == 2) return expu(B);
    1997     1979304 :   r = y;
    1998     6389342 :   for (e=1;; e++)
    1999             :   { /* here, r = y^e, r2 = y^(e-1) */
    2000    10799380 :     if (r >= B) return r == B? e: e-1;
    2001     4410025 :     r = umuluu_or_0(y, r);
    2002     4410038 :     if (!r) return e;
    2003             :   }
    2004             : }
    2005             : 
    2006             : /*******************************************************************/
    2007             : /*                                                                 */
    2008             : /*                         MISCELLANEOUS                           */
    2009             : /*                                                                 */
    2010             : /*******************************************************************/
    2011     1224227 : INLINE int ismpzero(GEN x) { return is_intreal_t(typ(x)) && !signe(x); }
    2012   657496359 : INLINE int isintzero(GEN x) { return typ(x) == t_INT && !signe(x); }
    2013     5711901 : INLINE int isint1(GEN x) { return typ(x)==t_INT && equali1(x); }
    2014        4697 : INLINE int isintm1(GEN x){ return typ(x)==t_INT && equalim1(x);}
    2015   698124883 : INLINE int equali1(GEN n)
    2016   698124883 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(1)) && n[2] == 1; }
    2017    61422644 : INLINE int equalim1(GEN n)
    2018    61422644 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(-1)) && n[2] == 1; }
    2019             : /* works only for POSITIVE integers */
    2020   981267467 : INLINE int is_pm1(GEN n)
    2021   981267467 : { return lgefint(n) == 3 && n[2] == 1; }
    2022   245805278 : INLINE int is_bigint(GEN n)
    2023   245805278 : { long l = lgefint(n); return l > 3 || (l == 3 && (n[2] & HIGHBIT)); }
    2024             : 
    2025  2074995826 : INLINE int odd(long x) { return x & 1; }
    2026    29133803 : INLINE int both_odd(long x, long y) { return x & y & 1; }
    2027             : 
    2028             : INLINE int
    2029  2770189863 : isonstack(GEN x)
    2030  2770189863 : { return ((pari_sp)x >= pari_mainstack->bot
    2031  2770189863 :        && (pari_sp)x <  pari_mainstack->top); }
    2032             : 
    2033             : /* assume x != 0 and x t_REAL, return an approximation to log2(|x|) */
    2034             : INLINE double
    2035    23254833 : dbllog2r(GEN x)
    2036    23254833 : { return log2((double)(ulong)x[2]) + (double)(expo(x) - (BITS_IN_LONG-1)); }
    2037             : 
    2038             : INLINE GEN
    2039      362953 : mul_content(GEN cx, GEN cy)
    2040             : {
    2041      362953 :   if (!cx) return cy;
    2042      133020 :   if (!cy) return cx;
    2043       91499 :   return gmul(cx,cy);
    2044             : }
    2045             : INLINE GEN
    2046        6048 : inv_content(GEN c) { return c? ginv(c): NULL; }
    2047             : INLINE GEN
    2048     1627421 : mul_denom(GEN dx, GEN dy)
    2049             : {
    2050     1627421 :   if (!dx) return dy;
    2051     1074077 :   if (!dy) return dx;
    2052      338520 :   return mulii(dx,dy);
    2053             : }
    2054             : 
    2055             : /* POLYNOMIALS */
    2056             : INLINE GEN
    2057    17947377 : constant_coeff(GEN x) { return signe(x)? gel(x,2): gen_0; }
    2058             : INLINE GEN
    2059    93818825 : leading_coeff(GEN x) { return lg(x) == 2? gen_0: gel(x,lg(x)-1); }
    2060             : INLINE ulong
    2061      479672 : Flx_lead(GEN x) { return lg(x) == 2? 0: x[lg(x)-1]; }
    2062             : INLINE ulong
    2063       12312 : Flx_constant(GEN x) { return lg(x) == 2? 0: x[2]; }
    2064             : INLINE long
    2065  2861352320 : degpol(GEN x) { return lg(x)-3; }
    2066             : INLINE long
    2067  1414408919 : lgpol(GEN x) { return lg(x)-2; }
    2068             : INLINE long
    2069   122830483 : lgcols(GEN x) { return lg(gel(x,1)); }
    2070             : INLINE long
    2071    34541136 : nbrows(GEN x) { return lg(gel(x,1))-1; }
    2072             : INLINE GEN
    2073           0 : truecoef(GEN x, long n) { return polcoef(x,n,-1); }
    2074             : 
    2075             : INLINE GEN
    2076      559853 : ZXQ_mul(GEN y, GEN x, GEN T) { return ZX_rem(ZX_mul(y, x), T); }
    2077             : INLINE GEN
    2078      281959 : ZXQ_sqr(GEN x, GEN T) { return ZX_rem(ZX_sqr(x), T); }
    2079             : 
    2080             : INLINE GEN
    2081    81470668 : RgX_copy(GEN x)
    2082             : {
    2083             :   long lx, i;
    2084    81470668 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
    2085    81470667 :   for (i = 2; i<lx; i++) gel(y,i) = gcopy(gel(x,i));
    2086    81470669 :   return y;
    2087             : }
    2088             : /* have to use ulong to avoid silly warnings from gcc "assuming signed
    2089             :  * overflow does not occur" */
    2090             : INLINE GEN
    2091     2961582 : RgX_coeff(GEN x, long n)
    2092             : {
    2093     2961582 :   ulong l = lg(x);
    2094     2961582 :   return (n < 0 || ((ulong)n+3) > l)? gen_0: gel(x,n+2);
    2095             : }
    2096             : INLINE GEN
    2097      368623 : RgX_renormalize(GEN x) { return RgX_renormalize_lg(x, lg(x)); }
    2098             : INLINE GEN
    2099     6862149 : RgX_div(GEN x, GEN y) { return RgX_divrem(x,y,NULL); }
    2100             : INLINE GEN
    2101        1792 : RgXQX_div(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,NULL); }
    2102             : INLINE GEN
    2103       67885 : RgXQX_rem(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,ONLY_REM); }
    2104             : INLINE GEN
    2105      947724 : FpX_div(GEN x, GEN y, GEN p) { return FpX_divrem(x,y,p, NULL); }
    2106             : INLINE GEN
    2107     4485422 : Flx_div(GEN x, GEN y, ulong p) { return Flx_divrem(x,y,p, NULL); }
    2108             : INLINE GEN
    2109     2597695 : F2x_div(GEN x, GEN y) { return F2x_divrem(x,y, NULL); }
    2110             : INLINE GEN
    2111           0 : FpV_FpC_mul(GEN x, GEN y, GEN p) { return FpV_dotproduct(x,y,p); }
    2112             : INLINE GEN
    2113    54633719 : pol0_Flx(long sv) { return mkvecsmall(sv); }
    2114             : INLINE GEN
    2115    15115928 : pol1_Flx(long sv) { return mkvecsmall2(sv, 1); }
    2116             : INLINE GEN
    2117    17830509 : polx_Flx(long sv) { return mkvecsmall3(sv, 0, 1); }
    2118             : INLINE GEN
    2119           0 : zero_zx(long sv) { return zero_Flx(sv); }
    2120             : INLINE GEN
    2121           0 : polx_zx(long sv) { return polx_Flx(sv); }
    2122             : INLINE GEN
    2123           0 : zx_shift(GEN x, long n) { return Flx_shift(x,n); }
    2124             : INLINE GEN
    2125           0 : zx_renormalize(GEN x, long l) { return Flx_renormalize(x,l); }
    2126             : INLINE GEN
    2127        1327 : zero_F2x(long sv) { return zero_Flx(sv); }
    2128             : INLINE GEN
    2129    11179922 : pol0_F2x(long sv) { return pol0_Flx(sv); }
    2130             : INLINE GEN
    2131     2876977 : pol1_F2x(long sv) { return pol1_Flx(sv); }
    2132             : INLINE GEN
    2133      687073 : polx_F2x(long sv) { return mkvecsmall2(sv, 2); }
    2134             : INLINE int
    2135      826472 : F2x_equal1(GEN x) { return Flx_equal1(x); }
    2136             : INLINE int
    2137     3127481 : F2x_equal(GEN V, GEN W) { return Flx_equal(V,W); }
    2138             : INLINE GEN
    2139    59817552 : F2x_copy(GEN x) { return leafcopy(x); }
    2140             : INLINE GEN
    2141           0 : F2v_copy(GEN x) { return leafcopy(x); }
    2142             : INLINE GEN
    2143     2274993 : Flv_copy(GEN x) { return leafcopy(x); }
    2144             : INLINE GEN
    2145    84196329 : Flx_copy(GEN x) { return leafcopy(x); }
    2146             : INLINE GEN
    2147     1873892 : vecsmall_copy(GEN x) { return leafcopy(x); }
    2148             : INLINE int
    2149     4889992 : Flx_equal1(GEN x) { return degpol(x)==0 && x[2] == 1; }
    2150             : INLINE int
    2151       18205 : ZX_equal1(GEN x) { return degpol(x)==0 && equali1(gel(x,2)); }
    2152             : INLINE int
    2153     5499208 : ZX_is_monic(GEN x) { return equali1(leading_coeff(x)); }
    2154             : 
    2155             : INLINE GEN
    2156    51151370 : ZX_renormalize(GEN x, long lx)    { return ZXX_renormalize(x,lx); }
    2157             : INLINE GEN
    2158    73149259 : FpX_renormalize(GEN x, long lx)   { return ZXX_renormalize(x,lx); }
    2159             : INLINE GEN
    2160      772497 : FpXX_renormalize(GEN x, long lx)  { return ZXX_renormalize(x,lx); }
    2161             : INLINE GEN
    2162     1251664 : FpXQX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
    2163             : INLINE GEN
    2164   111958246 : F2x_renormalize(GEN x, long lx)   { return Flx_renormalize(x,lx); }
    2165             : INLINE GEN
    2166       32335 : F2v_to_F2x(GEN x, long sv) {
    2167       32335 :   GEN y = leafcopy(x);
    2168       32334 :   y[1] = sv; F2x_renormalize(y, lg(y)); return y;
    2169             : }
    2170             : 
    2171             : INLINE long
    2172           0 : sturm(GEN x) { return sturmpart(x, NULL, NULL); }
    2173             : 
    2174             : INLINE long
    2175        7077 : gval(GEN x, long v) {
    2176        7077 :   pari_sp av = avma;
    2177        7077 :   long n = gvaluation(x, pol_x(v));
    2178        7077 :   set_avma(av); return n;
    2179             : }
    2180             : 
    2181             : INLINE void
    2182      470874 : RgX_shift_inplace_init(long v)
    2183      470874 : { if (v) (void)cgetg(v, t_VECSMALL); }
    2184             : /* shift polynomial in place. assume v free cells have been left before x */
    2185             : INLINE GEN
    2186      470874 : RgX_shift_inplace(GEN x, long v)
    2187             : {
    2188             :   long i, lx;
    2189             :   GEN y, z;
    2190      470874 :   if (!v) return x;
    2191      253227 :   lx = lg(x);
    2192      253227 :   if (lx == 2) return x;
    2193      253227 :   y = x + v;
    2194      253227 :   z = x + lx;
    2195             :   /* stackdummy from normalizepol: move it up */
    2196      253227 :   if (lg(z) != v) x[lx + v] = z[0];
    2197      253227 :   for (i = lx-1; i >= 2; i--) gel(y,i) = gel(x,i);
    2198      253227 :   for (i = v+1;  i >= 2; i--) gel(x,i) = gen_0;
    2199             :   /* leave x[1] alone: it is correct */
    2200      253227 :   x[0] = evaltyp(t_POL) | evallg(lx+v); return x;
    2201             : }
    2202             : 
    2203             : 
    2204             : /* LINEAR ALGEBRA */
    2205             : INLINE GEN
    2206      131980 : zv_to_ZV(GEN x) { return vecsmall_to_vec(x); }
    2207             : INLINE GEN
    2208     5208107 : zc_to_ZC(GEN x) { return vecsmall_to_col(x); }
    2209             : INLINE GEN
    2210     3343107 : ZV_to_zv(GEN x) { return vec_to_vecsmall(x); }
    2211             : INLINE GEN
    2212           0 : zx_to_zv(GEN x, long N) { return Flx_to_Flv(x,N); }
    2213             : INLINE GEN
    2214           0 : zv_to_zx(GEN x, long sv) { return Flv_to_Flx(x,sv); }
    2215             : INLINE GEN
    2216           0 : zm_to_zxV(GEN x, long sv) { return Flm_to_FlxV(x,sv); }
    2217             : INLINE GEN
    2218           0 : zero_zm(long x, long y) { return zero_Flm(x,y); }
    2219             : INLINE GEN
    2220    17417745 : zero_zv(long x) { return zero_Flv(x); }
    2221             : INLINE GEN
    2222         210 : zm_transpose(GEN x) { return Flm_transpose(x); }
    2223             : INLINE GEN
    2224           0 : zm_copy(GEN x) { return Flm_copy(x); }
    2225             : INLINE GEN
    2226     1903231 : zv_copy(GEN x) { return Flv_copy(x); }
    2227             : INLINE GEN
    2228           0 : zm_row(GEN x, long i) { return Flm_row(x,i); }
    2229             : 
    2230             : INLINE GEN
    2231      901843 : ZC_hnfrem(GEN x, GEN y) { return ZC_hnfremdiv(x,y,NULL); }
    2232             : INLINE GEN
    2233       48866 : ZM_hnfrem(GEN x, GEN y) { return ZM_hnfdivrem(x,y,NULL); }
    2234             : INLINE GEN
    2235     2438964 : ZM_lll(GEN x, double D, long f) { return ZM_lll_norms(x,D,f,NULL); }
    2236             : INLINE void
    2237     5673623 : RgM_dimensions(GEN x, long *m, long *n) { *n = lg(x)-1; *m = *n? nbrows(x): 0; }
    2238             : INLINE GEN
    2239    10337144 : RgM_shallowcopy(GEN x)
    2240             : {
    2241             :   long l;
    2242    10337144 :   GEN y = cgetg_copy(x, &l);
    2243    10337152 :   while (--l > 0) gel(y,l) = leafcopy(gel(x,l));
    2244    10337173 :   return y;
    2245             : }
    2246             : INLINE GEN
    2247         303 : F2m_copy(GEN x) { return RgM_shallowcopy(x); }
    2248             : 
    2249             : INLINE GEN
    2250     1375092 : Flm_copy(GEN x) { return RgM_shallowcopy(x); }
    2251             : 
    2252             : /* divisibility: return 1 if y[i] | x[i] for all i, 0 otherwise. Assume
    2253             :  * x,y are ZV of the same length */
    2254             : INLINE int
    2255       23198 : ZV_dvd(GEN x, GEN y)
    2256             : {
    2257       23198 :   long i, l = lg(x);
    2258       36652 :   for (i=1; i < l; i++)
    2259       29519 :     if ( ! dvdii( gel(x,i), gel(y,i) ) ) return 0;
    2260        7133 :   return 1;
    2261             : }
    2262             : 
    2263             : /* Fq */
    2264             : INLINE GEN
    2265     2802942 : Fq_red(GEN x, GEN T, GEN p)
    2266     2802942 : { return typ(x)==t_INT? Fp_red(x,p): FpXQ_red(x,T,p); }
    2267             : INLINE GEN
    2268       43439 : Fq_to_FpXQ(GEN x, GEN T, GEN p /*unused*/)
    2269             : {
    2270             :   (void) p;
    2271       43439 :   return typ(x)==t_INT ? scalarpol(x, get_FpX_var(T)): x;
    2272             : }
    2273             : INLINE GEN
    2274         756 : Rg_to_Fq(GEN x, GEN T, GEN p) { return T? Rg_to_FpXQ(x,T,p): Rg_to_Fp(x,p); }
    2275             : 
    2276             : INLINE GEN
    2277        1253 : gener_Fq_local(GEN T, GEN p, GEN L)
    2278             : { return T? gener_FpXQ_local(T,p, L)
    2279        1253 :           : pgener_Fp_local(p, L); }
    2280             : 
    2281             : /* FpXQX */
    2282             : INLINE GEN
    2283        4347 : FpXQX_div(GEN x, GEN y, GEN T, GEN p) { return FpXQX_divrem(x, y, T, p, NULL); }
    2284             : INLINE GEN
    2285       35076 : FlxqX_div(GEN x, GEN y, GEN T, ulong p) { return FlxqX_divrem(x, y, T, p, NULL); }
    2286             : INLINE GEN
    2287       33285 : F2xqX_div(GEN x, GEN y, GEN T) { return F2xqX_divrem(x, y, T, NULL); }
    2288             : 
    2289             : /* FqX */
    2290             : INLINE GEN
    2291       25431 : FqX_red(GEN z, GEN T, GEN p) { return T? FpXQX_red(z, T, p): FpX_red(z, p); }
    2292             : INLINE GEN
    2293      957187 : FqX_add(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2294             : INLINE GEN
    2295       17404 : FqX_neg(GEN x,GEN T,GEN p) { return T? FpXX_neg(x,p): FpX_neg(x,p); }
    2296             : INLINE GEN
    2297        3234 : FqX_sub(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2298             : INLINE GEN
    2299      657480 : FqX_Fp_mul(GEN P, GEN u, GEN T, GEN p)
    2300      657480 : { return T? FpXX_Fp_mul(P, u, p): FpX_Fp_mul(P, u, p); }
    2301             : INLINE GEN
    2302      588211 : FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p)
    2303      588211 : { return typ(U)==t_INT ? FqX_Fp_mul(P, U, T, p): FpXQX_FpXQ_mul(P, U, T, p); }
    2304             : INLINE GEN
    2305       96748 : FqX_mul(GEN x, GEN y, GEN T, GEN p)
    2306       96748 : { return T? FpXQX_mul(x, y, T, p): FpX_mul(x, y, p); }
    2307             : INLINE GEN
    2308      489744 : FqX_mulu(GEN x, ulong y, GEN T, GEN p)
    2309      489744 : { return T? FpXX_mulu(x, y, p): FpX_mulu(x, y, p); }
    2310             : INLINE GEN
    2311        6468 : FqX_sqr(GEN x, GEN T, GEN p)
    2312        6468 : { return T? FpXQX_sqr(x, T, p): FpX_sqr(x, p); }
    2313             : INLINE GEN
    2314        1288 : FqX_powu(GEN x, ulong n, GEN T, GEN p)
    2315        1288 : { return T? FpXQX_powu(x, n, T, p): FpX_powu(x, n, p); }
    2316             : INLINE GEN
    2317           0 : FqX_halve(GEN x, GEN T, GEN p)
    2318           0 : { return T? FpXX_halve(x, p): FpX_halve(x, p); }
    2319             : INLINE GEN
    2320        5600 : FqX_div(GEN x, GEN y, GEN T, GEN p)
    2321        5600 : { return T? FpXQX_divrem(x,y,T,p,NULL): FpX_divrem(x,y,p,NULL); }
    2322             : INLINE GEN
    2323        6095 : FqX_get_red(GEN S, GEN T, GEN p)
    2324        6095 : { return T? FpXQX_get_red(S,T,p): FpX_get_red(S,p); }
    2325             : INLINE GEN
    2326       53108 : FqX_rem(GEN x, GEN y, GEN T, GEN p)
    2327       53108 : { return T? FpXQX_rem(x,y,T,p): FpX_rem(x,y,p); }
    2328             : INLINE GEN
    2329           0 : FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2330           0 : { return T? FpXQX_divrem(x,y,T,p,z): FpX_divrem(x,y,p,z); }
    2331             : INLINE GEN
    2332        5936 : FqX_div_by_X_x(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2333        5936 : { return T? FpXQX_div_by_X_x(x,y,T,p,z): FpX_div_by_X_x(x,y,p,z); }
    2334             : INLINE GEN
    2335           0 : FqX_halfgcd(GEN P,GEN Q,GEN T,GEN p)
    2336           0 : {return T? FpXQX_halfgcd(P,Q,T,p): FpX_halfgcd(P,Q,p);}
    2337             : INLINE GEN
    2338      259238 : FqX_gcd(GEN P,GEN Q,GEN T,GEN p)
    2339      259238 : {return T? FpXQX_gcd(P,Q,T,p): FpX_gcd(P,Q,p);}
    2340             : INLINE GEN
    2341       88128 : FqX_extgcd(GEN P,GEN Q,GEN T,GEN p, GEN *U, GEN *V)
    2342       88128 : { return T? FpXQX_extgcd(P,Q,T,p,U,V): FpX_extgcd(P,Q,p,U,V); }
    2343             : INLINE GEN
    2344        3248 : FqX_normalize(GEN z, GEN T, GEN p)
    2345        3248 : { return T? FpXQX_normalize(z, T, p): FpX_normalize(z, p); }
    2346             : INLINE GEN
    2347      272895 : FqX_deriv(GEN f, GEN T, GEN p) { return T? FpXX_deriv(f, p): FpX_deriv(f, p); }
    2348             : INLINE GEN
    2349           0 : FqX_integ(GEN f, GEN T, GEN p) { return T? FpXX_integ(f, p): FpX_integ(f, p); }
    2350             : INLINE GEN
    2351       74543 : FqX_factor(GEN f, GEN T, GEN p)
    2352       74543 : { return T?FpXQX_factor(f, T, p): FpX_factor(f, p); }
    2353             : INLINE GEN
    2354           7 : FqX_factor_squarefree(GEN f, GEN T, GEN p)
    2355           7 : { return T ? FpXQX_factor_squarefree(f, T, p): FpX_factor_squarefree(f, p); }
    2356             : INLINE GEN
    2357           7 : FqX_ddf(GEN f, GEN T, GEN p)
    2358           7 : { return T ? FpXQX_ddf(f, T, p): FpX_ddf(f, p); }
    2359             : INLINE GEN
    2360          42 : FqX_degfact(GEN f, GEN T, GEN p)
    2361          42 : { return T?FpXQX_degfact(f, T, p): FpX_degfact(f, p); }
    2362             : INLINE GEN
    2363        7126 : FqX_roots(GEN f, GEN T, GEN p)
    2364        7126 : { return T?FpXQX_roots(f, T, p): FpX_roots(f, p); }
    2365             : INLINE GEN
    2366         203 : FqX_to_mod(GEN f, GEN T, GEN p)
    2367         203 : { return T?FpXQX_to_mod(f, T, p): FpX_to_mod(f, p); }
    2368             : 
    2369             : /*FqXQ*/
    2370             : INLINE GEN
    2371           0 : FqXQ_add(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2372           0 : { (void)S; return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2373             : INLINE GEN
    2374           0 : FqXQ_sub(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2375           0 : { (void)S; return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2376             : INLINE GEN
    2377           0 : FqXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p)
    2378           0 : { return T? FpXQXQ_div(x,y,S,T,p): FpXQ_div(x,y,S,p); }
    2379             : INLINE GEN
    2380           0 : FqXQ_inv(GEN x, GEN S, GEN T, GEN p)
    2381           0 : { return T? FpXQXQ_inv(x,S,T,p): FpXQ_inv(x,S,p); }
    2382             : INLINE GEN
    2383           0 : FqXQ_invsafe(GEN x, GEN S, GEN T, GEN p)
    2384           0 : { return T? FpXQXQ_invsafe(x,S,T,p): FpXQ_inv(x,S,p); }
    2385             : INLINE GEN
    2386       22348 : FqXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p)
    2387       22348 : { return T? FpXQXQ_mul(x,y,S,T,p): FpXQ_mul(x,y,S,p); }
    2388             : INLINE GEN
    2389           0 : FqXQ_sqr(GEN x, GEN S, GEN T, GEN p)
    2390           0 : { return T? FpXQXQ_sqr(x,S,T,p): FpXQ_sqr(x,S,p); }
    2391             : INLINE GEN
    2392           0 : FqXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p)
    2393           0 : { return T? FpXQXQ_pow(x,n,S,T,p): FpXQ_pow(x,n,S,p); }
    2394             : 
    2395             : /*FqXn*/
    2396             : INLINE GEN
    2397           0 : FqXn_exp(GEN x, long n, GEN T, GEN p)
    2398           0 : { return T? FpXQXn_exp(x,n,T,p): FpXn_exp(x,n,p); }
    2399             : INLINE GEN
    2400           0 : FqXn_inv(GEN x, long n, GEN T, GEN p)
    2401           0 : { return T? FpXQXn_inv(x,n,T,p): FpXn_inv(x,n,p); }
    2402             : INLINE GEN
    2403           0 : FqXn_mul(GEN x, GEN y, long n, GEN T, GEN p)
    2404           0 : { return T? FpXQXn_mul(x, y, n, T, p): FpXn_mul(x, y, n, p); }
    2405             : INLINE GEN
    2406           0 : FqXn_sqr(GEN x, long n, GEN T, GEN p)
    2407           0 : { return T? FpXQXn_sqr(x,n,T,p): FpXn_sqr(x,n,p); }
    2408             : 
    2409             : /*FpXQ*/
    2410             : INLINE GEN
    2411           0 : FpXQ_add(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2412           0 : { (void)T; return FpX_add(x,y,p); }
    2413             : INLINE GEN
    2414           0 : FpXQ_sub(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2415           0 : { (void)T; return FpX_sub(x,y,p); }
    2416             : 
    2417             : /*Flxq*/
    2418             : INLINE GEN
    2419           0 : Flxq_add(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2420           0 : { (void)T; return Flx_add(x,y,p); }
    2421             : INLINE GEN
    2422           0 : Flxq_sub(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2423           0 : { (void)T; return Flx_sub(x,y,p); }
    2424             : 
    2425             : /* F2x */
    2426             : 
    2427             : INLINE ulong
    2428   100566585 : F2x_coeff(GEN x,long v)
    2429             : {
    2430   100566585 :    ulong u=(ulong)x[2+divsBIL(v)];
    2431   100565679 :    return (u>>remsBIL(v))&1UL;
    2432             : }
    2433             : 
    2434             : INLINE void
    2435     4728278 : F2x_clear(GEN x,long v)
    2436             : {
    2437     4728278 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2438     4728278 :    *u&=~(1UL<<remsBIL(v));
    2439     4728278 : }
    2440             : 
    2441             : INLINE void
    2442    32795244 : F2x_set(GEN x,long v)
    2443             : {
    2444    32795244 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2445    32792930 :    *u|=1UL<<remsBIL(v);
    2446    32808758 : }
    2447             : 
    2448             : INLINE void
    2449     1501602 : F2x_flip(GEN x,long v)
    2450             : {
    2451     1501602 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2452     1501604 :    *u^=1UL<<remsBIL(v);
    2453     1501605 : }
    2454             : 
    2455             : /* F2v */
    2456             : 
    2457             : INLINE ulong
    2458    95951702 : F2v_coeff(GEN x,long v) { return F2x_coeff(x,v-1); }
    2459             : 
    2460             : INLINE void
    2461     4728278 : F2v_clear(GEN x,long v) { F2x_clear(x,v-1); }
    2462             : 
    2463             : INLINE void
    2464     8963615 : F2v_set(GEN x,long v)   { F2x_set(x,v-1); }
    2465             : 
    2466             : INLINE void
    2467     1501601 : F2v_flip(GEN x,long v) { F2x_flip(x,v-1); }
    2468             : 
    2469             : /* F2m */
    2470             : 
    2471             : INLINE ulong
    2472    11671538 : F2m_coeff(GEN x, long a, long b) { return F2v_coeff(gel(x,b), a); }
    2473             : 
    2474             : INLINE void
    2475           0 : F2m_clear(GEN x, long a, long b) { F2v_clear(gel(x,b), a); }
    2476             : 
    2477             : INLINE void
    2478     1362615 : F2m_set(GEN x, long a, long b) { F2v_set(gel(x,b), a); }
    2479             : 
    2480             : INLINE void
    2481     1501601 : F2m_flip(GEN x, long a, long b) { F2v_flip(gel(x,b), a); }
    2482             : 
    2483             : /* ARITHMETIC */
    2484             : INLINE GEN
    2485        1071 : matpascal(long n) { return matqpascal(n, NULL); }
    2486             : INLINE long
    2487     2334531 : Z_issquare(GEN x) { return Z_issquareall(x, NULL); }
    2488             : INLINE long
    2489          14 : Z_ispower(GEN x, ulong k) { return Z_ispowerall(x, k, NULL); }
    2490             : INLINE GEN
    2491     5869001 : sqrti(GEN x) { return sqrtremi(x,NULL); }
    2492             : INLINE GEN
    2493     6077383 : gaddgs(GEN y, long s) { return gaddsg(s,y); }
    2494             : INLINE int
    2495       56090 : gcmpgs(GEN y, long s) { return -gcmpsg(s,y); }
    2496             : INLINE int
    2497       24570 : gequalgs(GEN y, long s) { return gequalsg(s,y); }
    2498             : INLINE GEN
    2499           0 : gmaxsg(long s, GEN y) { return gmaxgs(y,s); }
    2500             : INLINE GEN
    2501           0 : gminsg(long s, GEN y) { return gmings(y,s); }
    2502             : INLINE GEN
    2503    15086518 : gmulgs(GEN y, long s) { return gmulsg(s,y); }
    2504             : INLINE GEN
    2505     1353440 : gsubgs(GEN y, long s) { return gaddgs(y, -s); }
    2506             : INLINE GEN
    2507      682472 : gdivsg(long s, GEN y) { return gdiv(stoi(s), y); }
    2508             : 
    2509             : /* x t_COMPLEX */
    2510             : INLINE GEN
    2511    12983314 : cxnorm(GEN x) { return gadd(gsqr(gel(x,1)), gsqr(gel(x,2))); }
    2512             : /* q t_QUAD */
    2513             : INLINE GEN
    2514         623 : quadnorm(GEN q)
    2515             : {
    2516         623 :   GEN X = gel(q,1), b = gel(X,3), c = gel(X,2);
    2517         623 :   GEN z, u = gel(q,3), v = gel(q,2);
    2518         623 :   if (typ(u) == t_INT && typ(v) == t_INT) /* generic case */
    2519             :   {
    2520         308 :     z = signe(b)? mulii(v, addii(u,v)): sqri(v);
    2521         308 :     return addii(z, mulii(c, sqri(u)));
    2522             :   }
    2523             :   else
    2524             :   {
    2525         315 :     z = signe(b)? gmul(v, gadd(u,v)): gsqr(v);
    2526         315 :     return gadd(z, gmul(c, gsqr(u)));
    2527             :   }
    2528             : }
    2529             : /* x a t_QUAD, return the attached discriminant */
    2530             : INLINE GEN
    2531         273 : quad_disc(GEN x)
    2532             : {
    2533         273 :   GEN Q = gel(x,1), b = gel(Q,3), c = gel(Q,2), c4;
    2534         273 :   if (is_pm1(b))
    2535             :   {
    2536         217 :     pari_sp av = avma; (void)new_chunk(lgefint(c) + 1);
    2537         217 :     c4 = shifti(c,2); set_avma(av); return subsi(1, c4);
    2538             :   }
    2539          56 :   c4 = shifti(c,2); togglesign_safe(&c4); return c4;
    2540             : }
    2541             : INLINE GEN
    2542     6386709 : qfb_disc3(GEN x, GEN y, GEN z) { return subii(sqri(y), shifti(mulii(x,z),2)); }
    2543             : INLINE GEN
    2544     6305775 : qfb_disc(GEN x) { return qfb_disc3(gel(x,1), gel(x,2), gel(x,3)); }
    2545             : 
    2546             : INLINE GEN
    2547     1284343 : sqrfrac(GEN x)
    2548             : {
    2549     1284343 :   GEN z = cgetg(3,t_FRAC);
    2550     1284343 :   gel(z,1) = sqri(gel(x,1));
    2551     1284343 :   gel(z,2) = sqri(gel(x,2)); return z;
    2552             : }
    2553             : 
    2554             : INLINE void
    2555    21807539 : normalize_frac(GEN z) {
    2556    21807539 :   if (signe(gel(z,2)) < 0) { togglesign(gel(z,1)); setabssign(gel(z,2)); }
    2557    21807539 : }
    2558             : 
    2559             : INLINE GEN
    2560      265504 : powii(GEN x, GEN n)
    2561             : {
    2562      265504 :   long ln = lgefint(n);
    2563      265504 :   if (ln == 3) {
    2564             :     GEN z;
    2565      261115 :     if (signe(n) > 0) return powiu(x, n[2]);
    2566        8085 :     z = cgetg(3, t_FRAC);
    2567        8085 :     gel(z,1) = gen_1;
    2568        8085 :     gel(z,2) = powiu(x, n[2]);
    2569        8085 :     return z;
    2570             :   }
    2571        4389 :   if (ln == 2) return gen_1; /* rare */
    2572             :   /* should never happen */
    2573           0 :   return powgi(x, n); /* overflow unless x = 0, 1, -1 */
    2574             : }
    2575             : INLINE GEN
    2576        1246 : powIs(long n) {
    2577        1246 :   switch(n & 3)
    2578             :   {
    2579          28 :     case 1: return mkcomplex(gen_0,gen_1);
    2580         378 :     case 2: return gen_m1;
    2581         518 :     case 3: return mkcomplex(gen_0,gen_m1);
    2582             :   }
    2583         322 :   return gen_1;
    2584             : }
    2585             : 
    2586             : /*******************************************************************/
    2587             : /*                                                                 */
    2588             : /*                             ASSIGNMENTS                         */
    2589             : /*                                                                 */
    2590             : /*******************************************************************/
    2591           0 : INLINE void mpexpz(GEN x, GEN z)
    2592           0 : { pari_sp av = avma; gaffect(mpexp(x), z); set_avma(av); }
    2593           0 : INLINE void mplogz(GEN x, GEN z)
    2594           0 : { pari_sp av = avma; gaffect(mplog(x), z); set_avma(av); }
    2595           0 : INLINE void mpcosz(GEN x, GEN z)
    2596           0 : { pari_sp av = avma; gaffect(mpcos(x), z); set_avma(av); }
    2597           0 : INLINE void mpsinz(GEN x, GEN z)
    2598           0 : { pari_sp av = avma; gaffect(mpsin(x), z); set_avma(av); }
    2599           0 : INLINE void gnegz(GEN x, GEN z)
    2600           0 : { pari_sp av = avma; gaffect(gneg(x), z); set_avma(av); }
    2601           0 : INLINE void gabsz(GEN x, long prec, GEN z)
    2602           0 : { pari_sp av = avma; gaffect(gabs(x,prec), z); set_avma(av); }
    2603           0 : INLINE void gaddz(GEN x, GEN y, GEN z)
    2604           0 : { pari_sp av = avma; gaffect(gadd(x,y), z); set_avma(av); }
    2605           0 : INLINE void gsubz(GEN x, GEN y, GEN z)
    2606           0 : { pari_sp av = avma; gaffect(gsub(x,y), z); set_avma(av); }
    2607           0 : INLINE void gmulz(GEN x, GEN y, GEN z)
    2608           0 : { pari_sp av = avma; gaffect(gmul(x,y), z); set_avma(av); }
    2609           0 : INLINE void gdivz(GEN x, GEN y, GEN z)
    2610           0 : { pari_sp av = avma; gaffect(gdiv(x,y), z); set_avma(av); }
    2611           0 : INLINE void gdiventz(GEN x, GEN y, GEN z)
    2612           0 : { pari_sp av = avma; gaffect(gdivent(x,y), z); set_avma(av); }
    2613           0 : INLINE void gmodz(GEN x, GEN y, GEN z)
    2614           0 : { pari_sp av = avma; gaffect(gmod(x,y), z); set_avma(av); }
    2615           0 : INLINE void gmul2nz(GEN x, long s, GEN z)
    2616           0 : { pari_sp av = avma; gaffect(gmul2n(x,s), z); set_avma(av); }
    2617           0 : INLINE void gshiftz(GEN x, long s, GEN z)
    2618           0 : { pari_sp av = avma; gaffect(gshift(x,s), z); set_avma(av); }
    2619             : 
    2620             : /*******************************************************************/
    2621             : /*                                                                 */
    2622             : /*                       ELLIPTIC CURVES                           */
    2623             : /*                                                                 */
    2624             : /*******************************************************************/
    2625     3979746 : INLINE GEN ell_get_a1(GEN e) { return gel(e,1); }
    2626     3095796 : INLINE GEN ell_get_a2(GEN e) { return gel(e,2); }
    2627     3861698 : INLINE GEN ell_get_a3(GEN e) { return gel(e,3); }
    2628     3888743 : INLINE GEN ell_get_a4(GEN e) { return gel(e,4); }
    2629     4704922 : INLINE GEN ell_get_a6(GEN e) { return gel(e,5); }
    2630     3318522 : INLINE GEN ell_get_b2(GEN e) { return gel(e,6); }
    2631     1024949 : INLINE GEN ell_get_b4(GEN e) { return gel(e,7); }
    2632     1630617 : INLINE GEN ell_get_b6(GEN e) { return gel(e,8); }
    2633     1464001 : INLINE GEN ell_get_b8(GEN e) { return gel(e,9); }
    2634     6167025 : INLINE GEN ell_get_c4(GEN e) { return gel(e,10); }
    2635     7403473 : INLINE GEN ell_get_c6(GEN e) { return gel(e,11); }
    2636     9653749 : INLINE GEN ell_get_disc(GEN e) { return gel(e,12); }
    2637     1028909 : INLINE GEN ell_get_j(GEN e) { return gel(e,13); }
    2638    11455527 : INLINE long ell_get_type(GEN e) { return mael(e,14,1); }
    2639     1570458 : INLINE GEN ellff_get_field(GEN x) { return gmael(x, 15, 1); }
    2640      683127 : INLINE GEN ellff_get_a4a6(GEN x)  { return gmael(x, 15, 2); }
    2641        1407 : INLINE GEN ellQp_get_zero(GEN x) { return gmael(x, 15, 1); }
    2642         287 : INLINE long ellQp_get_prec(GEN E) { GEN z = ellQp_get_zero(E); return valp(z); }
    2643        1085 : INLINE GEN ellQp_get_p(GEN E) { GEN z = ellQp_get_zero(E); return gel(z,2); }
    2644       37156 : INLINE long ellR_get_prec(GEN x) { return nbits2prec(mael3(x, 15, 1, 1)); }
    2645       12106 : INLINE long ellR_get_sign(GEN x) { return mael3(x, 15, 1, 2); }
    2646      699411 : INLINE GEN ellnf_get_nf(GEN x) { return checknf_i(gmael(x,15,1)); }
    2647          56 : INLINE GEN ellnf_get_bnf(GEN x) { return checkbnf_i(gmael(x,15,1)); }
    2648             : 
    2649     4624832 : INLINE int checkell_i(GEN e) { return typ(e) == t_VEC && lg(e) == 17; }
    2650    33981460 : INLINE int ell_is_inf(GEN z) { return lg(z) == 2; }
    2651      809820 : INLINE GEN ellinf(void) { return mkvec(gen_0); }
    2652             : 
    2653             : /*******************************************************************/
    2654             : /*                                                                 */
    2655             : /*                    ALGEBRAIC NUMBER THEORY                      */
    2656             : /*                                                                 */
    2657             : /*******************************************************************/
    2658     8420110 : INLINE GEN modpr_get_pr(GEN x)  { return gel(x,3); }
    2659      609528 : INLINE GEN modpr_get_p(GEN x)  { return pr_get_p(modpr_get_pr(x)); }
    2660     2681295 : INLINE GEN modpr_get_T(GEN x)  { return lg(x) == 4? NULL: gel(x,4); }
    2661             : 
    2662    20066707 : INLINE GEN pr_get_p(GEN pr)  { return gel(pr,1); }
    2663     6618270 : INLINE GEN pr_get_gen(GEN pr){ return gel(pr,2); }
    2664             : /* .[2] instead of itos works: e and f are small positive integers */
    2665     2376647 : INLINE long pr_get_e(GEN pr) { return gel(pr,3)[2]; }
    2666     9158966 : INLINE long pr_get_f(GEN pr) { return gel(pr,4)[2]; }
    2667     6300014 : INLINE GEN pr_get_tau(GEN pr){ return gel(pr,5); }
    2668             : INLINE int
    2669     3189021 : pr_is_inert(GEN P) { return pr_get_f(P) == lg(pr_get_gen(P))-1; }
    2670             : INLINE GEN
    2671      232224 : pr_norm(GEN pr) { return powiu(pr_get_p(pr), pr_get_f(pr)); }
    2672             : INLINE ulong
    2673       48083 : upr_norm(GEN pr) { return upowuu(pr_get_p(pr)[2], pr_get_f(pr)); }
    2674             : 
    2675             : /* assume nf a genuine nf */
    2676             : INLINE long
    2677        4675 : nf_get_varn(GEN nf) { return varn(gel(nf,1)); }
    2678             : INLINE GEN
    2679    31829116 : nf_get_pol(GEN nf) { return gel(nf,1); }
    2680             : INLINE long
    2681    25311524 : nf_get_degree(GEN nf) { return degpol( nf_get_pol(nf) ); }
    2682             : INLINE long
    2683     4136913 : nf_get_r1(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,1)); }
    2684             : INLINE long
    2685        1673 : nf_get_r2(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,2)); }
    2686             : INLINE GEN
    2687       53151 : nf_get_disc(GEN nf) { return gel(nf,3); }
    2688             : INLINE GEN
    2689      828861 : nf_get_index(GEN nf) { return gel(nf,4); }
    2690             : INLINE GEN
    2691     2864897 : nf_get_M(GEN nf) { return gmael(nf,5,1); }
    2692             : INLINE GEN
    2693       81489 : nf_get_G(GEN nf) { return gmael(nf,5,2); }
    2694             : INLINE GEN
    2695      408067 : nf_get_roundG(GEN nf) { return gmael(nf,5,3); }
    2696             : INLINE GEN
    2697       24367 : nf_get_Tr(GEN nf) { return gmael(nf,5,4); }
    2698             : INLINE GEN
    2699        2324 : nf_get_diff(GEN nf) { return gmael(nf,5,5); }
    2700             : INLINE GEN
    2701          91 : nf_get_ramified_primes(GEN nf) { return gmael(nf,5,8); }
    2702             : INLINE GEN
    2703      332889 : nf_get_roots(GEN nf) { return gel(nf,6); }
    2704             : INLINE GEN
    2705          98 : nf_get_zk(GEN nf)
    2706             : {
    2707          98 :   GEN y = gel(nf,7), D = gel(y, 1);
    2708          98 :   if (typ(D) == t_POL) D = gel(D, 2);
    2709          98 :   if (!equali1(D)) y = gdiv(y, D);
    2710          98 :   return y;
    2711             : }
    2712             : INLINE GEN
    2713      279032 : nf_get_zkprimpart(GEN nf)
    2714             : {
    2715      279032 :   GEN y = gel(nf,7);
    2716             :   /* test for old format of nf.zk: non normalized */
    2717      279032 :   if (!equali1(gel(nf,4)) && gequal1(gel(y,1))) y = Q_remove_denom(y,NULL);
    2718      279032 :   return y;
    2719             : }
    2720             : INLINE GEN
    2721      280181 : nf_get_zkden(GEN nf)
    2722             : {
    2723      280181 :   GEN y = gel(nf,7), D = gel(y,1);
    2724      280181 :   if (typ(D) == t_POL) D = gel(D,2);
    2725             :   /* test for old format of nf.zk: non normalized */
    2726      280181 :   if (!equali1(gel(nf,4)) && equali1(D)) D = Q_denom(y);
    2727      280179 :   return D;
    2728             : }
    2729             : INLINE GEN
    2730     2486960 : nf_get_invzk(GEN nf) { return gel(nf,8); }
    2731             : INLINE void
    2732       22843 : nf_get_sign(GEN nf, long *r1, long *r2)
    2733             : {
    2734       22843 :   GEN x = gel(nf,2);
    2735       22843 :   *r1 = itou(gel(x,1));
    2736       22843 :   *r2 = itou(gel(x,2));
    2737       22843 : }
    2738             : 
    2739             : INLINE GEN
    2740       92758 : abgrp_get_no(GEN x) { return gel(x,1); }
    2741             : INLINE GEN
    2742     2600822 : abgrp_get_cyc(GEN x) { return gel(x,2); }
    2743             : INLINE GEN
    2744      437924 : abgrp_get_gen(GEN x) { return gel(x,3); }
    2745             : INLINE GEN
    2746     2315510 : bnf_get_nf(GEN bnf) { return gel(bnf,7); }
    2747             : INLINE GEN
    2748      896050 : bnf_get_clgp(GEN bnf) { return gmael(bnf,8,1); }
    2749             : INLINE GEN
    2750        6713 : bnf_get_no(GEN bnf) { return abgrp_get_no(bnf_get_clgp(bnf)); }
    2751             : INLINE GEN
    2752      498019 : bnf_get_cyc(GEN bnf) { return abgrp_get_cyc(bnf_get_clgp(bnf)); }
    2753             : INLINE GEN
    2754      390989 : bnf_get_gen(GEN bnf)  { return abgrp_get_gen(bnf_get_clgp(bnf)); }
    2755             : INLINE GEN
    2756         846 : bnf_get_reg(GEN bnf) { return gmael(bnf,8,2); }
    2757             : INLINE GEN
    2758      502386 : bnf_get_logfu(GEN bnf) { return gel(bnf,3); }
    2759             : INLINE GEN
    2760        7457 : bnf_get_tuU(GEN bnf) { return gmael3(bnf,8,4,2); }
    2761             : INLINE long
    2762       40208 : bnf_get_tuN(GEN bnf) { return gmael3(bnf,8,4,1)[2]; }
    2763             : INLINE GEN
    2764        1778 : bnf_get_fu(GEN bnf) {
    2765        1778 :   GEN fu = bnf_get_fu_nocheck(bnf);
    2766        1778 :   if (typ(fu) == t_MAT) pari_err(e_MISC,"missing units in bnf");
    2767        1778 :   return fu;
    2768             : }
    2769             : INLINE GEN
    2770        8885 : bnf_get_fu_nocheck(GEN bnf) { return gmael(bnf,8,5); }
    2771             : 
    2772             : INLINE GEN
    2773      927533 : bnr_get_bnf(GEN bnr) { return gel(bnr,1); }
    2774             : INLINE GEN
    2775      474711 : bnr_get_bid(GEN bnr) { return gel(bnr,2); }
    2776             : INLINE GEN
    2777       18648 : bnr_get_mod(GEN bnr) { return gmael(bnr,2,1); }
    2778             : INLINE GEN
    2779       32557 : bnr_get_nf(GEN bnr) { return gmael(bnr,1,7); }
    2780             : INLINE GEN
    2781      716428 : bnr_get_clgp(GEN bnr) { return gel(bnr,5); }
    2782             : INLINE GEN
    2783       82278 : bnr_get_no(GEN bnr) { return abgrp_get_no(bnr_get_clgp(bnr)); }
    2784             : INLINE GEN
    2785      618106 : bnr_get_cyc(GEN bnr) { return abgrp_get_cyc(bnr_get_clgp(bnr)); }
    2786             : INLINE GEN
    2787          70 : bnr_get_gen_nocheck(GEN bnr) { return abgrp_get_gen(bnr_get_clgp(bnr)); }
    2788             : INLINE GEN
    2789       14931 : bnr_get_gen(GEN bnr) {
    2790       14931 :   GEN G = bnr_get_clgp(bnr);
    2791       14931 :   if (lg(G) !=  4)
    2792           0 :     pari_err(e_MISC,"missing bnr generators: please use bnrinit(,,1)");
    2793       14931 :   return gel(G,3);
    2794             : }
    2795             : 
    2796             : INLINE GEN
    2797      361227 : bid_get_mod(GEN bid) { return gel(bid,1); }
    2798             : INLINE GEN
    2799       65947 : bid_get_ideal(GEN bid) { return gmael(bid,1,1); }
    2800             : INLINE GEN
    2801         707 : bid_get_arch(GEN bid) { return gmael(bid,1,2); }
    2802             : INLINE GEN
    2803     1330683 : bid_get_grp(GEN bid) { return gel(bid,2); }
    2804             : INLINE GEN
    2805      528282 : bid_get_fact(GEN bid) { return gmael(bid,3,1); }
    2806             : INLINE GEN
    2807      458373 : bid_get_fact2(GEN bid) { return gmael(bid,3,2); }
    2808             : INLINE GEN
    2809      458184 : bid_get_sprk(GEN bid) { return gmael(bid,4,1); }
    2810             : INLINE GEN
    2811       49203 : bid_get_sarch(GEN bid) { return gmael(bid,4,2); }
    2812             : INLINE GEN
    2813      493975 : bid_get_archp(GEN bid) { return gmael3(bid,4,2,2); }
    2814             : INLINE GEN
    2815      819621 : bid_get_U(GEN bid) { return gel(bid,5); }
    2816             : INLINE GEN
    2817           0 : bid_get_no(GEN bid) { return abgrp_get_no(bid_get_grp(bid)); }
    2818             : INLINE GEN
    2819     1284742 : bid_get_cyc(GEN bid) { return abgrp_get_cyc(bid_get_grp(bid)); }
    2820             : INLINE GEN
    2821           0 : bid_get_gen_nocheck(GEN bid)  { return abgrp_get_gen(bid_get_grp(bid)); }
    2822             : INLINE GEN
    2823       45346 : bid_get_gen(GEN bid) {
    2824       45346 :   GEN G = bid_get_grp(bid);
    2825       45346 :   if (lg(G) != 4) pari_err(e_MISC,"missing bid generators. Use idealstar(,,2)");
    2826       45346 :   return abgrp_get_gen(G);
    2827             : }
    2828             : 
    2829             : INLINE GEN
    2830    21944062 : znstar_get_N(GEN G) { return gmael(G,1,1); }
    2831             : INLINE GEN
    2832     2814224 : znstar_get_faN(GEN G) { return gel(G,3); }
    2833             : INLINE GEN
    2834           7 : znstar_get_no(GEN G) { return abgrp_get_no(gel(G,2)); }
    2835             : INLINE GEN
    2836      198534 : znstar_get_cyc(GEN G) { return abgrp_get_cyc(gel(G,2)); }
    2837             : INLINE GEN
    2838           7 : znstar_get_gen(GEN G) { return abgrp_get_gen(gel(G,2)); }
    2839             : INLINE GEN
    2840     3488156 : znstar_get_conreycyc(GEN G) { return gmael(G,4,5); }
    2841             : INLINE GEN
    2842     1201690 : znstar_get_conreygen(GEN G) { return gmael(G,4,4); }
    2843             : INLINE GEN
    2844       45920 : znstar_get_Ui(GEN G) { return gmael(G,4,3); }
    2845             : INLINE GEN
    2846      118160 : znstar_get_U(GEN G) { return gel(G,5); }
    2847             : INLINE GEN
    2848      800366 : znstar_get_pe(GEN G) { return gmael(G,4,1); }
    2849             : INLINE GEN
    2850       19894 : gal_get_pol(GEN gal) { return gel(gal,1); }
    2851             : INLINE GEN
    2852        1323 : gal_get_p(GEN gal) { return gmael(gal,2,1); }
    2853             : INLINE GEN
    2854          84 : gal_get_e(GEN gal) { return gmael(gal,2,2); }
    2855             : INLINE GEN
    2856       15960 : gal_get_mod(GEN gal) { return gmael(gal,2,3); }
    2857             : INLINE GEN
    2858       16338 : gal_get_roots(GEN gal) { return gel(gal,3); }
    2859             : INLINE GEN
    2860       15918 : gal_get_invvdm(GEN gal) { return gel(gal,4); }
    2861             : INLINE GEN
    2862       15918 : gal_get_den(GEN gal) { return gel(gal,5); }
    2863             : INLINE GEN
    2864       66986 : gal_get_group(GEN gal) { return gel(gal,6); }
    2865             : INLINE GEN
    2866        1743 : gal_get_gen(GEN gal) { return gel(gal,7); }
    2867             : INLINE GEN
    2868        1379 : gal_get_orders(GEN gal) { return gel(gal,8); }
    2869             : 
    2870             : /* assume rnf a genuine rnf */
    2871             : INLINE long
    2872     1233638 : rnf_get_degree(GEN rnf) { return degpol(rnf_get_pol(rnf)); }
    2873             : INLINE long
    2874       16471 : rnf_get_nfdegree(GEN rnf) { return degpol(nf_get_pol(rnf_get_nf(rnf))); }
    2875             : INLINE long
    2876      775698 : rnf_get_absdegree(GEN rnf) { return degpol(gmael(rnf,11,1)); }
    2877             : INLINE GEN
    2878         700 : rnf_get_idealdisc(GEN rnf) { return gmael(rnf,3,1); }
    2879             : INLINE GEN
    2880         742 : rnf_get_k(GEN rnf) { return gmael(rnf,11,3); }
    2881             : INLINE GEN
    2882         609 : rnf_get_alpha(GEN rnf) { return gmael(rnf, 11, 2); }
    2883             : INLINE GEN
    2884      384825 : rnf_get_nf(GEN rnf) { return gel(rnf,10); }
    2885             : INLINE GEN
    2886        3178 : rnf_get_nfzk(GEN rnf) { return gel(rnf,2); }
    2887             : INLINE GEN
    2888      205254 : rnf_get_polabs(GEN rnf) { return gmael(rnf,11,1); }
    2889             : INLINE GEN
    2890     1479849 : rnf_get_pol(GEN rnf) { return gel(rnf,1); }
    2891             : INLINE GEN
    2892          63 : rnf_get_disc(GEN rnf) { return gel(rnf,3); }
    2893             : INLINE GEN
    2894         105 : rnf_get_index(GEN rnf) { return gel(rnf,4); }
    2895             : INLINE long
    2896           0 : rnf_get_varn(GEN rnf) { return varn(gel(rnf,1)); }
    2897             : INLINE GEN
    2898      188580 : rnf_get_nfpol(GEN rnf) { return gmael(rnf,10,1); }
    2899             : INLINE long
    2900        3325 : rnf_get_nfvarn(GEN rnf) { return varn(gmael(rnf,10,1)); }
    2901             : INLINE GEN
    2902        3290 : rnf_get_zk(GEN rnf) { return gel(rnf,7); }
    2903             : INLINE GEN
    2904       96915 : rnf_get_map(GEN rnf) { return gel(rnf,11); }
    2905             : INLINE GEN
    2906        1197 : rnf_get_invzk(GEN rnf) { return gel(rnf,8); }
    2907             : 
    2908             : /* I integral ZM (not HNF), G ZM, rounded Cholesky form of a weighted
    2909             :  * T2 matrix. Reduce I wrt G */
    2910             : INLINE GEN
    2911       21784 : idealpseudored(GEN I, GEN G)
    2912       21784 : { return ZM_mul(I, ZM_lll(ZM_mul(G, I), 0.99, LLL_IM)); }
    2913             : 
    2914             : /* I integral (not necessarily HNF), G ZM, rounded Cholesky form of a weighted
    2915             :  * T2 matrix. Return m in I with T2(m) small */
    2916             : INLINE GEN
    2917      140674 : idealpseudomin(GEN I, GEN G)
    2918             : {
    2919      140674 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2920      140674 :   return ZM_ZC_mul(I, gel(u,1));
    2921             : }
    2922             : /* I, G as in idealpseudomin. Return an irrational m in I with T2(m) small */
    2923             : INLINE GEN
    2924      298542 : idealpseudomin_nonscalar(GEN I, GEN G)
    2925             : {
    2926      298542 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2927      298542 :   GEN m = ZM_ZC_mul(I, gel(u,1));
    2928      298542 :   if (ZV_isscalar(m) && lg(u) > 2) m = ZM_ZC_mul(I, gel(u,2));
    2929      298542 :   return m;
    2930             : }
    2931             : 
    2932             : INLINE GEN
    2933         826 : idealred_elt(GEN nf, GEN I) {
    2934         826 :   pari_sp av = avma;
    2935         826 :   GEN u = idealpseudomin(I, nf_get_roundG(nf));
    2936         826 :   return gerepileupto(av, u);
    2937             : }
    2938             : INLINE GEN
    2939      122877 : idealred(GEN nf, GEN I) { return idealred0(nf, I, NULL); }
    2940             : 
    2941             : INLINE GEN
    2942        2058 : idealchineseinit(GEN nf, GEN x)
    2943        2058 : { return idealchinese(nf,x,NULL); }
    2944             : 
    2945             : /*******************************************************************/
    2946             : /*                                                                 */
    2947             : /*                              CLOSURES                           */
    2948             : /*                                                                 */
    2949             : /*******************************************************************/
    2950   225978804 : INLINE long closure_arity(GEN C)          { return ((ulong)C[1])&ARITYBITS; }
    2951    35499077 : INLINE long closure_is_variadic(GEN C) { return !!(((ulong)C[1])&VARARGBITS); }
    2952   190186069 : INLINE const char *closure_codestr(GEN C)  { return GSTR(gel(C,2))-1; }
    2953           0 : INLINE GEN closure_get_code(GEN C)  { return gel(C,2); }
    2954   190148182 : INLINE GEN closure_get_oper(GEN C)  { return gel(C,3); }
    2955   190128623 : INLINE GEN closure_get_data(GEN C)  { return gel(C,4); }
    2956        9666 : INLINE GEN closure_get_dbg(GEN C)   { return gel(C,5); }
    2957       23084 : INLINE GEN closure_get_text(GEN C)  { return gel(C,6); }
    2958     1227648 : INLINE GEN closure_get_frame(GEN C) { return gel(C,7); }
    2959             : 
    2960             : /*******************************************************************/
    2961             : /*                                                                 */
    2962             : /*                               ERRORS                            */
    2963             : /*                                                                 */
    2964             : /*******************************************************************/
    2965             : INLINE long
    2966       52751 : err_get_num(GEN e) { return e[1]; }
    2967             : INLINE GEN
    2968          77 : err_get_compo(GEN e, long i) { return gel(e, i+1); }
    2969             : 
    2970             : INLINE void
    2971          14 : pari_err_BUG(const char *f) { pari_err(e_BUG,f); }
    2972             : INLINE void
    2973           7 : pari_err_CONSTPOL(const char *f) { pari_err(e_CONSTPOL, f); }
    2974             : INLINE void
    2975          63 : pari_err_COPRIME(const char *f, GEN x, GEN y) { pari_err(e_COPRIME, f,x,y); }
    2976             : INLINE void
    2977         487 : pari_err_DIM(const char *f) { pari_err(e_DIM, f); }
    2978             : INLINE void
    2979           0 : pari_err_FILE(const char *f, const char *g) { pari_err(e_FILE, f,g); }
    2980             : INLINE void
    2981           0 : pari_err_FILEDESC(const char *f, long n) { pari_err(e_FILEDESC, f,n); }
    2982             : INLINE void
    2983          63 : pari_err_FLAG(const char *f) { pari_err(e_FLAG,f); }
    2984             : INLINE void
    2985         448 : pari_err_IMPL(const char *f) { pari_err(e_IMPL,f); }
    2986             : INLINE void
    2987       19716 : pari_err_INV(const char *f, GEN x) { pari_err(e_INV,f,x); }
    2988             : INLINE void
    2989          28 : pari_err_IRREDPOL(const char *f, GEN x) { pari_err(e_IRREDPOL, f,x); }
    2990             : INLINE void
    2991        2085 : pari_err_DOMAIN(const char *f, const char *v, const char *op, GEN l, GEN x) { pari_err(e_DOMAIN, f,v,op,l,x); }
    2992             : INLINE void
    2993         203 : pari_err_COMPONENT(const char *f, const char *op, GEN l, GEN x) { pari_err(e_COMPONENT, f,op,l,x); }
    2994             : INLINE void
    2995           0 : pari_err_MAXPRIME(ulong c) { pari_err(e_MAXPRIME, c); }
    2996             : INLINE void
    2997         350 : pari_err_OP(const char *f, GEN x, GEN y) { pari_err(e_OP, f,x,y); }
    2998             : INLINE void
    2999          86 : pari_err_OVERFLOW(const char *f) { pari_err(e_OVERFLOW, f); }
    3000             : INLINE void
    3001         218 : pari_err_PREC(const char *f) { pari_err(e_PREC,f); }
    3002             : INLINE void
    3003           0 : pari_err_PACKAGE(const char *f) { pari_err(e_PACKAGE,f); }
    3004             : INLINE void
    3005          70 : pari_err_PRIME(const char *f, GEN x) { pari_err(e_PRIME, f,x); }
    3006             : INLINE void
    3007         749 : pari_err_MODULUS(const char *f, GEN x, GEN y) { pari_err(e_MODULUS, f,x,y); }
    3008             : INLINE void
    3009          49 : pari_err_ROOTS0(const char *f) { pari_err(e_ROOTS0, f); }
    3010             : INLINE void
    3011          77 : pari_err_SQRTN(const char *f, GEN x) { pari_err(e_SQRTN, f,x); }
    3012             : INLINE void
    3013       12671 : pari_err_TYPE(const char *f, GEN x) { pari_err(e_TYPE, f,x); }
    3014             : INLINE void
    3015        3073 : pari_err_TYPE2(const char *f, GEN x, GEN y) { pari_err(e_TYPE2, f,x,y); }
    3016             : INLINE void
    3017         203 : pari_err_VAR(const char *f, GEN x, GEN y) { pari_err(e_VAR, f,x,y); }
    3018             : INLINE void
    3019         175 : pari_err_PRIORITY(const char *f, GEN x, const char *op, long v)
    3020         175 : { pari_err(e_PRIORITY, f,x,op,v); }

Generated by: LCOV version 1.13