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 23861-3a0b89ade) Lines: 1294 1462 88.5 %
Date: 2019-05-21 05:44:45 Functions: 569 646 88.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (C) 2000-2010  The PARI group.
       2             : 
       3             : This file is part of the PARI/GP package.
       4             : 
       5             : PARI/GP is free software; you can redistribute it and/or modify it under the
       6             : terms of the GNU General Public License as published by the Free Software
       7             : Foundation. It is distributed in the hope that it will be useful, but WITHOUT
       8             : ANY WARRANTY WHATSOEVER.
       9             : 
      10             : Check the License for details. You should have received a copy of it, along
      11             : with the package; see the file 'COPYING'. If not, write to the Free Software
      12             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
      13             : 
      14             : /*******************************************************************/
      15             : /*                                                                 */
      16             : /*                          CONSTRUCTORS                           */
      17             : /*                                                                 */
      18             : /*******************************************************************/
      19             : #define retmkfrac(x,y)\
      20             :   do { GEN _v = cgetg(3, t_FRAC);\
      21             :        gel(_v,1) = (x);\
      22             :        gel(_v,2) = (y); return _v; } while(0)
      23             : #define retmkrfrac(x,y)\
      24             :   do { GEN _v = cgetg(3, t_RFRAC);\
      25             :        gel(_v,1) = (x);\
      26             :        gel(_v,2) = (y); return _v; } while(0)
      27             : #define retmkintmod(x,y)\
      28             :   do { GEN _v = cgetg(3, t_INTMOD);\
      29             :        gel(_v,1) = (y);\
      30             :        gel(_v,2) = (x); return _v; } while(0)
      31             : #define retmkcomplex(x,y)\
      32             :   do { GEN _v = cgetg(3, t_COMPLEX);\
      33             :        gel(_v,1) = (x);\
      34             :        gel(_v,2) = (y); return _v; } while(0)
      35             : #define retmkpolmod(x,y)\
      36             :   do { GEN _v = cgetg(3, t_POLMOD);\
      37             :        gel(_v,1) = (y);\
      38             :        gel(_v,2) = (x); return _v; } while(0)
      39             : #define retmkvec(x)\
      40             :   do { GEN _v = cgetg(2, t_VEC);\
      41             :        gel(_v,1) = (x); return _v; } while(0)
      42             : #define retmkvec2(x,y)\
      43             :   do { GEN _v = cgetg(3, t_VEC);\
      44             :        gel(_v,1) = (x);\
      45             :        gel(_v,2) = (y); return _v; } while(0)
      46             : #define retmkvec3(x,y,z)\
      47             :   do { GEN _v = cgetg(4, t_VEC);\
      48             :        gel(_v,1) = (x);\
      49             :        gel(_v,2) = (y);\
      50             :        gel(_v,3) = (z); return _v; } while(0)
      51             : #define retmkqfi(x,y,z)\
      52             :   do { GEN _v = cgetg(4, t_QFI);\
      53             :        gel(_v,1) = (x);\
      54             :        gel(_v,2) = (y);\
      55             :        gel(_v,3) = (z); return _v; } while(0)
      56             : #define retmkqfr(x,y,z,d)\
      57             :   do { GEN _v = cgetg(5, t_QFR);\
      58             :        gel(_v,1) = (x);\
      59             :        gel(_v,2) = (y);\
      60             :        gel(_v,3) = (z);\
      61             :        gel(_v,4) = (d); return _v; } while(0)
      62             : #define retmkquad(x,y,z)\
      63             :   do { GEN _v = cgetg(4, t_QUAD);\
      64             :        gel(_v,1) = (x);\
      65             :        gel(_v,2) = (y);\
      66             :        gel(_v,3) = (z); return _v; } while(0)
      67             : #define retmkvec4(x,y,z,t)\
      68             :   do { GEN _v = cgetg(5, t_VEC);\
      69             :        gel(_v,1) = (x);\
      70             :        gel(_v,2) = (y);\
      71             :        gel(_v,3) = (z);\
      72             :        gel(_v,4) = (t); return _v; } while(0)
      73             : #define retmkvec5(x,y,z,t,u)\
      74             :   do { GEN _v = cgetg(6, t_VEC);\
      75             :        gel(_v,1) = (x);\
      76             :        gel(_v,2) = (y);\
      77             :        gel(_v,3) = (z);\
      78             :        gel(_v,4) = (t);\
      79             :        gel(_v,5) = (u); return _v; } while(0)
      80             : #define retmkcol(x)\
      81             :   do { GEN _v = cgetg(2, t_COL);\
      82             :        gel(_v,1) = (x); return _v; } while(0)
      83             : #define retmkcol2(x,y)\
      84             :   do { GEN _v = cgetg(3, t_COL);\
      85             :        gel(_v,1) = (x);\
      86             :        gel(_v,2) = (y); return _v; } while(0)
      87             : #define retmkcol3(x,y,z)\
      88             :   do { GEN _v = cgetg(4, t_COL);\
      89             :        gel(_v,1) = (x);\
      90             :        gel(_v,2) = (y);\
      91             :        gel(_v,3) = (z); return _v; } while(0)
      92             : #define retmkcol4(x,y,z,t)\
      93             :   do { GEN _v = cgetg(5, t_COL);\
      94             :        gel(_v,1) = (x);\
      95             :        gel(_v,2) = (y);\
      96             :        gel(_v,3) = (z);\
      97             :        gel(_v,4) = (t); return _v; } while(0)
      98             : #define retmkcol5(x,y,z,t,u)\
      99             :   do { GEN _v = cgetg(6, t_COL);\
     100             :        gel(_v,1) = (x);\
     101             :        gel(_v,2) = (y);\
     102             :        gel(_v,3) = (z);\
     103             :        gel(_v,4) = (t);\
     104             :        gel(_v,5) = (u); return _v; } while(0)
     105             : #define retmkcol6(x,y,z,t,u,v)\
     106             :   do { GEN _v = cgetg(7, t_COL);\
     107             :        gel(_v,1) = (x);\
     108             :        gel(_v,2) = (y);\
     109             :        gel(_v,3) = (z);\
     110             :        gel(_v,4) = (t);\
     111             :        gel(_v,5) = (u);\
     112             :        gel(_v,6) = (v); return _v; } while(0)
     113             : #define retmkmat(x)\
     114             :   do { GEN _v = cgetg(2, t_MAT);\
     115             :        gel(_v,1) = (x); return _v; } while(0)
     116             : #define retmkmat2(x,y)\
     117             :   do { GEN _v = cgetg(3, t_MAT);\
     118             :        gel(_v,1) = (x);\
     119             :        gel(_v,2) = (y); return _v; } while(0)
     120             : #define retmkmat3(x,y,z)\
     121             :   do { GEN _v = cgetg(4, t_MAT);\
     122             :        gel(_v,1) = (x);\
     123             :        gel(_v,2) = (y);\
     124             :        gel(_v,3) = (z); return _v; } while(0)
     125             : #define retmkmat4(x,y,z,t)\
     126             :   do { GEN _v = cgetg(5, t_MAT);\
     127             :        gel(_v,1) = (x);\
     128             :        gel(_v,2) = (y);\
     129             :        gel(_v,3) = (z);\
     130             :        gel(_v,4) = (t); return _v; } while(0)
     131             : #define retmkmat5(x,y,z,t,u)\
     132             :   do { GEN _v = cgetg(6, t_MAT);\
     133             :        gel(_v,1) = (x);\
     134             :        gel(_v,2) = (y);\
     135             :        gel(_v,3) = (z);\
     136             :        gel(_v,4) = (t);\
     137             :        gel(_v,5) = (u); return _v; } while(0)
     138             : 
     139             : INLINE GEN
     140     3186708 : mkintmod(GEN x, GEN y) { retmkintmod(x,y); }
     141             : INLINE GEN
     142        4760 : mkintmodu(ulong x, ulong y) {
     143        4760 :   GEN v = cgetg(3,t_INTMOD);
     144        4760 :   gel(v,1) = utoipos(y);
     145        4760 :   gel(v,2) = utoi(x); return v;
     146             : }
     147             : INLINE GEN
     148     2954224 : mkpolmod(GEN x, GEN y) { retmkpolmod(x,y); }
     149             : INLINE GEN
     150    23354192 : mkfrac(GEN x, GEN y) { retmkfrac(x,y); }
     151             : INLINE GEN
     152       31983 : 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       13181 : Qtoss(GEN q, long *n, long *d)
     156             : {
     157       13181 :   if (typ(q) == t_INT) { *n = itos(q); *d = 1; }
     158        2464 :   else { *n = itos(gel(q,1)); *d = itou(gel(q,2)); }
     159       13181 : }
     160             : INLINE GEN
     161    71390265 : sstoQ(long n, long d)
     162             : {
     163             :   ulong r;
     164             :   long g, q;
     165    71390265 :   if (!n)
     166             :   {
     167       99715 :     if (!d) pari_err_INV("sstoQ",gen_0);
     168       99715 :     return gen_0;
     169             :   }
     170    71290550 :   if (d < 0) { d = -d; n = -n; }
     171    71290550 :   if (d == 1) return stoi(n);
     172    71278559 :   q = udivuu_rem(labs(n),d,&r);
     173    71278559 :   if (!r) return n > 0? utoipos(q): utoineg(q);
     174     3639470 :   g = ugcd(d,r); /* gcd(n,d) */
     175     3639470 :   if (g != 1) { n /= g; d /= g; }
     176     3639470 :   retmkfrac(stoi(n), utoi(d));
     177             : }
     178             : 
     179             : INLINE GEN
     180    15881855 : mkfraccopy(GEN x, GEN y) { retmkfrac(icopy(x), icopy(y)); }
     181             : INLINE GEN
     182          35 : mkrfrac(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     183          35 :   gel(v,1) = x; gel(v,2) = y; return v; }
     184             : INLINE GEN
     185           7 : mkrfraccopy(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     186           7 :   gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     187             : INLINE GEN
     188    10483582 : mkcomplex(GEN x, GEN y) { retmkcomplex(x,y); }
     189             : INLINE GEN
     190      451319 : gen_I(void) { return mkcomplex(gen_0, gen_1); }
     191             : INLINE GEN
     192      299003 : 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    71357545 : mkvecsmall(long x) { GEN v = cgetg(2, t_VECSMALL); v[1] = x; return v; }
     199             : INLINE GEN
     200   114789541 : mkvecsmall2(long x,long y) { GEN v = cgetg(3, t_VECSMALL);
     201   114797368 :   v[1]=x; v[2]=y; return v; }
     202             : INLINE GEN
     203    58482385 : mkvecsmall3(long x,long y,long z) { GEN v = cgetg(4, t_VECSMALL);
     204    58479011 :   v[1]=x; v[2]=y; v[3]=z; return v; }
     205             : INLINE GEN
     206    11964449 : mkvecsmall4(long x,long y,long z,long t) { GEN v = cgetg(5, t_VECSMALL);
     207    11954199 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; return v; }
     208             : INLINE GEN
     209      466832 : mkvecsmall5(long x,long y,long z,long t,long u) { GEN v = cgetg(6, t_VECSMALL);
     210      466834 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; v[5]=u; return v; }
     211             : 
     212             : INLINE GEN
     213      158116 : mkqfi(GEN x, GEN y, GEN z) { retmkqfi(x,y,z); }
     214             : /* vec */
     215             : INLINE GEN
     216    15005092 : mkvec(GEN x) { retmkvec(x); }
     217             : INLINE GEN
     218   103572813 : mkvec2(GEN x, GEN y) { retmkvec2(x,y); }
     219             : INLINE GEN
     220    78793806 : mkvec3(GEN x, GEN y, GEN z) { retmkvec3(x,y,z); }
     221             : INLINE GEN
     222     7277581 : mkvec4(GEN x, GEN y, GEN z, GEN t) { retmkvec4(x,y,z,t); }
     223             : INLINE GEN
     224    12168728 : mkvec5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkvec5(x,y,z,t,u); }
     225             : INLINE GEN
     226         105 : mkvecs(long x) { retmkvec(stoi(x)); }
     227             : INLINE GEN
     228       23875 : mkvec2s(long x, long y) { retmkvec2(stoi(x),stoi(y)); }
     229             : INLINE GEN
     230      492724 : mkvec3s(long x, long y, long z) { retmkvec3(stoi(x),stoi(y),stoi(z)); }
     231             : INLINE GEN
     232          21 : mkvec4s(long x, long y, long z, long t) { retmkvec4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     233             : INLINE GEN
     234       35350 : mkveccopy(GEN x) { GEN v = cgetg(2, t_VEC); gel(v,1) = gcopy(x); return v; }
     235             : INLINE GEN
     236      100263 : mkvec2copy(GEN x, GEN y) {
     237      100263 :   GEN v = cgetg(3,t_VEC); gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     238             : /* col */
     239             : INLINE GEN
     240     2560868 : mkcol(GEN x) { retmkcol(x); }
     241             : INLINE GEN
     242    25664833 : mkcol2(GEN x, GEN y) { retmkcol2(x,y); }
     243             : INLINE GEN
     244       42371 : mkcol3(GEN x, GEN y, GEN z) { retmkcol3(x,y,z); }
     245             : INLINE GEN
     246           0 : mkcol4(GEN x, GEN y, GEN z, GEN t) { retmkcol4(x,y,z,t); }
     247             : INLINE GEN
     248           0 : mkcol5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkcol5(x,y,z,t,u); }
     249             : INLINE GEN
     250        8900 : 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     2179646 : mkcol2s(long x, long y) { retmkcol2(stoi(x),stoi(y)); }
     255             : INLINE GEN
     256           0 : mkcol3s(long x, long y, long z) { retmkcol3(stoi(x),stoi(y),stoi(z)); }
     257             : INLINE GEN
     258           0 : mkcol4s(long x, long y, long z, long t) { retmkcol4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     259             : INLINE GEN
     260       52717 : mkcolcopy(GEN x) { GEN v = cgetg(2, t_COL); gel(v,1) = gcopy(x); return v; }
     261             : /* mat */
     262             : INLINE GEN
     263     2559145 : mkmat(GEN x) { retmkmat(x); }
     264             : INLINE GEN
     265    32236510 : mkmat2(GEN x, GEN y) { retmkmat2(x,y); }
     266             : INLINE GEN
     267        2329 : mkmat3(GEN x, GEN y, GEN z) { retmkmat3(x,y,z); }
     268             : INLINE GEN
     269           0 : mkmat4(GEN x, GEN y, GEN z, GEN t) { retmkmat4(x,y,z,t); }
     270             : INLINE GEN
     271           0 : mkmat5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkmat5(x,y,z,t,u); }
     272             : INLINE GEN
     273       23951 : 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       97685 : mkoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_1; return v; }
     278             : INLINE GEN
     279       18060 : mkmoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_m1; return v; }
     280             : INLINE long
     281      135706 : inf_get_sign(GEN x) { return signe(gel(x,1)); }
     282             : INLINE GEN
     283       12411 : mkmat22s(long a, long b, long c, long d) {retmkmat2(mkcol2s(a,c),mkcol2s(b,d));}
     284             : INLINE GEN
     285     1533140 : mkmat22(GEN a, GEN b, GEN c, GEN d) { retmkmat2(mkcol2(a,c),mkcol2(b,d)); }
     286             : 
     287             : /* pol */
     288             : INLINE GEN
     289     1008719 : pol_x(long v) {
     290     1008719 :   GEN p = cgetg(4, t_POL);
     291     1008718 :   p[1] = evalsigne(1)|evalvarn(v);
     292     1008718 :   gel(p,2) = gen_0;
     293     1008718 :   gel(p,3) = gen_1; return p;
     294             : }
     295             : /* x^n, assume n >= 0 */
     296             : INLINE GEN
     297     8780266 : pol_xn(long n, long v) {
     298     8780266 :   long i, a = n+2;
     299     8780266 :   GEN p = cgetg(a+1, t_POL);
     300     8780266 :   p[1] = evalsigne(1)|evalvarn(v);
     301     8780266 :   for (i = 2; i < a; i++) gel(p,i) = gen_0;
     302     8780266 :   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     1445820 : pol_1(long v) {
     313     1445820 :   GEN p = cgetg(3, t_POL);
     314     1445818 :   p[1] = evalsigne(1)|evalvarn(v);
     315     1445818 :   gel(p,2) = gen_1; return p;
     316             : }
     317             : INLINE GEN
     318    32623421 : pol_0(long v)
     319             : {
     320    32623421 :   GEN x = cgetg(2,t_POL);
     321    32623421 :   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     9132893 : 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     8688971 : const_col(long n, GEN x) { retconst_col(n, x); }
     337             : INLINE GEN
     338     8753130 : const_vecsmall(long n, long c)
     339             : {
     340             :   long i;
     341     8753130 :   GEN V = cgetg(n+1,t_VECSMALL);
     342     8753384 :   for(i=1;i<=n;i++) V[i] = c;
     343     8753384 :   return V;
     344             : }
     345             : 
     346             : /***   ZERO   ***/
     347             : /* O(p^e) */
     348             : INLINE GEN
     349      363738 : zeropadic(GEN p, long e)
     350             : {
     351      363738 :   GEN y = cgetg(5,t_PADIC);
     352      363738 :   gel(y,4) = gen_0;
     353      363738 :   gel(y,3) = gen_1;
     354      363738 :   gel(y,2) = icopy(p);
     355      363738 :   y[1] = evalvalp(e) | _evalprecp(0);
     356      363738 :   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      144235 : zeroser(long v, long e)
     371             : {
     372      144235 :   GEN x = cgetg(2, t_SER);
     373      144235 :   x[1] = evalvalp(e) | evalvarn(v); return x;
     374             : }
     375             : INLINE int
     376     5470766 : ser_isexactzero(GEN x)
     377             : {
     378     5470766 :   if (!signe(x)) switch(lg(x))
     379             :   {
     380      136717 :     case 2: return 1;
     381         854 :     case 3: return isexactzero(gel(x,2));
     382             :   }
     383     5333195 :   return 0;
     384             : }
     385             : /* 0 * pol_x(v) */
     386             : INLINE GEN
     387    15550532 : zeropol(long v) { return pol_0(v); }
     388             : /* vector(n) */
     389             : INLINE GEN
     390    38038383 : zerocol(long n)
     391             : {
     392    38038383 :   GEN y = cgetg(n+1,t_COL);
     393    38038636 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     394    38038636 :   return y;
     395             : }
     396             : /* vectorv(n) */
     397             : INLINE GEN
     398    21799997 : zerovec(long n)
     399             : {
     400    21799997 :   GEN y = cgetg(n+1,t_VEC);
     401    21800000 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     402    21800000 :   return y;
     403             : }
     404             : /* matrix(m, n) */
     405             : INLINE GEN
     406       23877 : zeromat(long m, long n)
     407             : {
     408       23877 :   GEN y = cgetg(n+1,t_MAT);
     409       23877 :   GEN v = zerocol(m);
     410       23877 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     411       23877 :   return y;
     412             : }
     413             : /* = zero_zx, sv is a evalvarn()*/
     414             : INLINE GEN
     415      930143 : zero_Flx(long sv) { return pol0_Flx(sv); }
     416             : INLINE GEN
     417    34080999 : zero_Flv(long n)
     418             : {
     419    34080999 :   GEN y = cgetg(n+1,t_VECSMALL);
     420    34082205 :   long i; for (i=1; i<=n; i++) y[i] = 0;
     421    34082205 :   return y;
     422             : }
     423             : /* matrix(m, n) */
     424             : INLINE GEN
     425      980637 : zero_Flm(long m, long n)
     426             : {
     427      980637 :   GEN y = cgetg(n+1,t_MAT);
     428      980616 :   GEN v = zero_Flv(m);
     429      980634 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     430      980634 :   return y;
     431             : }
     432             : /* matrix(m, n) */
     433             : INLINE GEN
     434      111529 : zero_Flm_copy(long m, long n)
     435             : {
     436      111529 :   GEN y = cgetg(n+1,t_MAT);
     437      111520 :   long i; for (i=1; i<=n; i++) gel(y,i) = zero_Flv(m);
     438      111533 :   return y;
     439             : }
     440             : 
     441             : INLINE GEN
     442      869995 : zero_F2v(long m)
     443             : {
     444      869995 :   long l = nbits2nlong(m);
     445      869995 :   GEN v  = zero_Flv(l+1);
     446      869995 :   v[1] = m;
     447      869995 :   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      299820 : zero_F2m_copy(long m, long n)
     464             : {
     465             :   long i;
     466      299820 :   GEN M = cgetg(n+1, t_MAT);
     467      889681 :   for (i = 1; i <= n; i++)
     468      589861 :     gel(M,i)= zero_F2v(m);
     469      299820 :   return M;
     470             : }
     471             : 
     472             : /* matrix(m, n) */
     473             : INLINE GEN
     474     4977910 : zeromatcopy(long m, long n)
     475             : {
     476     4977910 :   GEN y = cgetg(n+1,t_MAT);
     477     4977910 :   long i; for (i=1; i<=n; i++) gel(y,i) = zerocol(m);
     478     4977910 :   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     1502512 : col_ei(long n, long i) { GEN e = zerocol(n); gel(e,i) = gen_1; return e; }
     494             : INLINE GEN
     495      349420 : 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       75145 : vecsmall_ei(long n, long i) { GEN e = zero_zv(n); e[i] = 1; return e; }
     500             : INLINE GEN
     501      708443 : Rg_col_ei(GEN x, long n, long i) { GEN e = zerocol(n); gel(e,i) = x; return e; }
     502             : 
     503             : INLINE GEN
     504    12834784 : shallowcopy(GEN x)
     505    12834784 : { return typ(x) == t_MAT ? RgM_shallowcopy(x): leafcopy(x); }
     506             : 
     507             : /* routines for naive growarrays */
     508             : INLINE GEN
     509    12375014 : vectrunc_init(long l)
     510             : {
     511    12375014 :   GEN z = new_chunk(l);
     512    12375129 :   z[0] = evaltyp(t_VEC) | _evallg(1); return z;
     513             : }
     514             : INLINE GEN
     515      346899 : coltrunc_init(long l)
     516             : {
     517      346899 :   GEN z = new_chunk(l);
     518      346899 :   z[0] = evaltyp(t_COL) | _evallg(1); return z;
     519             : }
     520             : INLINE void
     521   261906889 : lg_increase(GEN x) { x[0]++; }
     522             : INLINE void
     523    51348999 : 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    86318309 : vecsmalltrunc_init(long l)
     534             : {
     535    86318309 :   GEN z = new_chunk(l);
     536    86318309 :   z[0] = evaltyp(t_VECSMALL) | _evallg(1); return z;
     537             : }
     538             : INLINE void
     539    33198828 : 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     1971022 : hash_str(const char *str)
     548             : {
     549     1971022 :   ulong hash = 5381UL, c;
     550    21377061 :   while ( (c = (ulong)*str++) )
     551    17435017 :     hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
     552     1971022 :   return hash;
     553             : }
     554             : INLINE ulong
     555     6602538 : hash_str_len(const char *str, long len)
     556             : {
     557     6602538 :   ulong hash = 5381UL;
     558             :   long i;
     559    25131349 :   for (i = 0; i < len; i++)
     560             :   {
     561    18528811 :     ulong c = (ulong)*str++;
     562    18528811 :     hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
     563             :   }
     564     6602538 :   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       13827 : vec_lengthen(GEN v, long n)
     584             : {
     585             :   long i;
     586       13827 :   long l=lg(v);
     587       13827 :   GEN V = cgetg(n+1,t_VEC);
     588       13827 :   for(i=1;i<l;i++) gel(V,i) = gel(v,i);
     589       13827 :   return V;
     590             : }
     591             : /* shallow*/
     592             : INLINE GEN
     593       79576 : vec_append(GEN V, GEN s)
     594             : {
     595       79576 :   long i, l2 = lg(V);
     596       79576 :   GEN res = cgetg(l2+1, typ(V));
     597       79576 :   for (i = 1; i < l2; ++i) gel(res, i) = gel(V,i);
     598       79576 :   gel(res,l2) = s; return res;
     599             : }
     600             : /* shallow*/
     601             : INLINE GEN
     602        2050 : vec_prepend(GEN v, GEN s)
     603             : {
     604        2050 :   long i, l = lg(v);
     605        2050 :   GEN w = cgetg(l+1, typ(v));
     606        2050 :   gel(w,1) = s;
     607        2050 :   for (i = 2; i <= l; ++i) gel(w,i) = gel(v,i-1);
     608        2050 :   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       41793 : vecsmall_shorten(GEN v, long n)
     620             : {
     621             :   long i;
     622       41793 :   GEN V = cgetg(n+1,t_VECSMALL);
     623       41793 :   for(i=1;i<=n;i++) V[i] = v[i];
     624       41793 :   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     3324305 : vec_to_vecsmall(GEN x)
     637     3324305 : { pari_APPLY_long(itos(gel(x,i))) }
     638             : INLINE GEN
     639      135879 : vecsmall_to_vec(GEN x)
     640      135879 : { pari_APPLY_type(t_VEC, stoi(x[i])) }
     641             : INLINE GEN
     642        1624 : vecsmall_to_vec_inplace(GEN z)
     643             : {
     644        1624 :   long i, l = lg(z);
     645        1624 :   for (i=1; i<l; i++) gel(z,i) = stoi(z[i]);
     646        1624 :   settyp(z, t_VEC); return z;
     647             : }
     648             : INLINE GEN
     649     5252648 : vecsmall_to_col(GEN x)
     650     5252648 : { pari_APPLY_type(t_COL, stoi(x[i])) }
     651             : 
     652             : INLINE int
     653     8141687 : vecsmall_lexcmp(GEN x, GEN y)
     654             : {
     655             :   long lx,ly,l,i;
     656     8141687 :   lx = lg(x);
     657     8141687 :   ly = lg(y); l = minss(lx,ly);
     658    39708542 :   for (i=1; i<l; i++)
     659    37836613 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     660     1871929 :   if (lx == ly) return 0;
     661          14 :   return (lx < ly)? -1 : 1;
     662             : }
     663             : 
     664             : INLINE int
     665    85155882 : vecsmall_prefixcmp(GEN x, GEN y)
     666             : {
     667    85155882 :   long i, lx = lg(x), ly = lg(y), l = minss(lx,ly);
     668   394028124 :   for (i=1; i<l; i++)
     669   374395413 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     670    19632711 :   return 0;
     671             : }
     672             : 
     673             : /*Can be used on t_VEC, but coeffs not gcopy-ed*/
     674             : INLINE GEN
     675       21449 : vecsmall_prepend(GEN V, long s)
     676             : {
     677       21449 :   long i, l2 = lg(V);
     678       21449 :   GEN res = cgetg(l2+1, typ(V));
     679       21449 :   res[1] = s;
     680       21449 :   for (i = 2; i <= l2; ++i) res[i] = V[i - 1];
     681       21449 :   return res;
     682             : }
     683             : 
     684             : INLINE GEN
     685     3134235 : vecsmall_append(GEN V, long s)
     686             : {
     687     3134235 :   long i, l2 = lg(V);
     688     3134235 :   GEN res = cgetg(l2+1, t_VECSMALL);
     689     3134235 :   for (i = 1; i < l2; ++i) res[i] = V[i];
     690     3134235 :   res[l2] = s; return res;
     691             : }
     692             : 
     693             : INLINE GEN
     694      841428 : vecsmall_concat(GEN u, GEN v)
     695             : {
     696      841428 :   long i, l1 = lg(u)-1, l2 = lg(v)-1;
     697      841428 :   GEN res = cgetg(l1+l2+1, t_VECSMALL);
     698      841428 :   for (i = 1; i <= l1; ++i) res[i]    = u[i];
     699      841428 :   for (i = 1; i <= l2; ++i) res[i+l1] = v[i];
     700      841428 :   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      180411 : vecsmall_max(GEN x)
     742             : {
     743      180411 :   long i, t = x[1], lx = lg(x);
     744      636858 :   for (i=2; i<lx; i++)
     745      456447 :     if (x[i] > t) t = x[i];
     746      180411 :   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     5190316 : ZV_isscalar(GEN x)
     769             : {
     770     5190316 :   long l = lg(x);
     771    14874953 :   while (--l > 1)
     772     8533946 :     if (signe(gel(x, l))) return 0;
     773     1150691 :   return 1;
     774             : }
     775             : INLINE int
     776    21593551 : QV_isscalar(GEN x)
     777             : {
     778    21593551 :   long lx = lg(x),i;
     779    23253152 :   for (i=2; i<lx; i++)
     780    22631221 :     if (!isintzero(gel(x, i))) return 0;
     781      621931 :   return 1;
     782             : }
     783             : INLINE int
     784        7823 : RgV_isscalar(GEN x)
     785             : {
     786        7823 :   long lx = lg(x),i;
     787       11689 :   for (i=2; i<lx; i++)
     788       10285 :     if (!gequal0(gel(x, i))) return 0;
     789        1404 :   return 1;
     790             : }
     791             : INLINE int
     792           0 : RgX_isscalar(GEN x)
     793             : {
     794             :   long i;
     795           0 :   for (i=lg(x)-1; i>2; i--)
     796           0 :     if (!gequal0(gel(x, i))) return 0;
     797           0 :   return 1;
     798             : }
     799             : INLINE long
     800    28828558 : RgX_equal_var(GEN x, GEN y) { return varn(x) == varn(y) && RgX_equal(x,y); }
     801             : 
     802             : INLINE int
     803        7610 : RgX_is_rational(GEN x)
     804             : {
     805             :   long i;
     806       34566 :   for (i = lg(x)-1; i > 1; i--)
     807       32087 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     808        2479 :   return 1;
     809             : }
     810             : INLINE int
     811     4689158 : RgX_is_ZX(GEN x)
     812             : {
     813             :   long i;
     814    20250289 :   for (i = lg(x)-1; i > 1; i--)
     815    15613732 :     if (typ(gel(x,i)) != t_INT) return 0;
     816     4636557 :   return 1;
     817             : }
     818             : INLINE int
     819      273622 : RgX_is_QX(GEN x)
     820             : {
     821      273622 :   long k = lg(x)-1;
     822     1001391 :   for ( ; k>1; k--)
     823      728021 :     if (!is_rational_t(typ(gel(x,k)))) return 0;
     824      273370 :   return 1;
     825             : }
     826             : INLINE int
     827     2347851 : RgX_is_monomial(GEN x)
     828             : {
     829             :   long i;
     830     2347851 :   if (!signe(x)) return 0;
     831     5857900 :   for (i=lg(x)-2; i>1; i--)
     832     3565202 :     if (!isexactzero(gel(x,i))) return 0;
     833     2292698 :   return 1;
     834             : }
     835             : INLINE int
     836    27477941 : RgV_is_ZV(GEN x)
     837             : {
     838             :   long i;
     839   112615748 :   for (i = lg(x)-1; i > 0; i--)
     840    85140292 :     if (typ(gel(x,i)) != t_INT) return 0;
     841    27475456 :   return 1;
     842             : }
     843             : INLINE int
     844       23153 : RgV_is_QV(GEN x)
     845             : {
     846             :   long i;
     847      101842 :   for (i = lg(x)-1; i > 0; i--)
     848       80320 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     849       21522 :   return 1;
     850             : }
     851             : 
     852             : /********************************************************************/
     853             : /**                                                                **/
     854             : /**            Dynamic arrays implementation                       **/
     855             : /**                                                                **/
     856             : /********************************************************************/
     857             : INLINE void **
     858   405003438 : pari_stack_base(pari_stack *s) { return s->data; }
     859             : 
     860             : INLINE void
     861     1961359 : pari_stack_init(pari_stack *s, size_t size, void **data)
     862             : {
     863     1961359 :   s->data = data;
     864     1961359 :   *data = NULL;
     865     1961359 :   s->n = 0;
     866     1961359 :   s->alloc = 0;
     867     1961359 :   s->size = size;
     868     1961359 : }
     869             : 
     870             : INLINE void
     871   403250999 : pari_stack_alloc(pari_stack *s, long nb)
     872             : {
     873   403250999 :   void **sdat = pari_stack_base(s);
     874   403157593 :   long alloc = s->alloc;
     875   403157593 :   if (s->n+nb <= alloc) return;
     876      803967 :   if (!alloc)
     877      743912 :     alloc = nb;
     878             :   else
     879             :   {
     880       60055 :     while (s->n+nb > alloc) alloc <<= 1;
     881             :   }
     882      803967 :   *sdat = pari_realloc(*sdat,alloc*s->size);
     883      805627 :   s->alloc = alloc;
     884             : }
     885             : 
     886             : INLINE long
     887   325432972 : pari_stack_new(pari_stack *s) { pari_stack_alloc(s, 1); return s->n++; }
     888             : 
     889             : INLINE void
     890     1786599 : pari_stack_delete(pari_stack *s)
     891             : {
     892     1786599 :   void **sdat = pari_stack_base(s);
     893     1783141 :   if (*sdat) pari_free(*sdat);
     894     1799004 : }
     895             : 
     896             : INLINE void
     897        4829 : pari_stack_pushp(pari_stack *s, void *u)
     898             : {
     899        4829 :   long n = pari_stack_new(s);
     900        4829 :   void **sdat =(void**) *pari_stack_base(s);
     901        4829 :   sdat[n] = u;
     902        4829 : }
     903             : 
     904             : /*******************************************************************/
     905             : /*                                                                 */
     906             : /*                            EXTRACT                              */
     907             : /*                                                                 */
     908             : /*******************************************************************/
     909             : INLINE GEN
     910   209734650 : vecslice(GEN A, long y1, long y2)
     911             : {
     912   209734650 :   long i,lB = y2 - y1 + 2;
     913   209734650 :   GEN B = cgetg(lB, typ(A));
     914   209734019 :   for (i=1; i<lB; i++) B[i] = A[y1-1+i];
     915   209734019 :   return B;
     916             : }
     917             : INLINE GEN
     918      864372 : vecslicepermute(GEN A, GEN p, long y1, long y2)
     919             : {
     920      864372 :   long i,lB = y2 - y1 + 2;
     921      864372 :   GEN B = cgetg(lB, typ(A));
     922      864377 :   for (i=1; i<lB; i++) B[i] = A[p[y1-1+i]];
     923      864377 :   return B;
     924             : }
     925             : /* rowslice(rowpermute(A,p), x1, x2) */
     926             : INLINE GEN
     927       43286 : rowslicepermute(GEN x, GEN p, long j1, long j2)
     928       43286 : { pari_APPLY_same(vecslicepermute(gel(x,i),p,j1,j2)) }
     929             : 
     930             : INLINE GEN
     931    23647798 : rowslice(GEN x, long j1, long j2)
     932    23647798 : { pari_APPLY_same(vecslice(gel(x,i), j1, j2)) }
     933             : 
     934             : INLINE GEN
     935     3847300 : matslice(GEN A, long x1, long x2, long y1, long y2)
     936     3847300 : { 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      264216 : vecsplice(GEN a, long j)
     946             : {
     947      264216 :   long i, k, l = lg(a);
     948             :   GEN b;
     949      264216 :   if (l == 1) pari_err(e_MISC, "incorrect component in vecsplice");
     950      264216 :   b = cgetg(l-1, typ(a));
     951     1054889 :   for (i = k = 1; i < l; i++)
     952      790673 :     if (i != j) gel(b, k++) = gel(a,i);
     953      264216 :   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      391870 : row(GEN x, long j)
     968      391870 : { pari_APPLY_type(t_VEC, gcoeff(x, j, i)) }
     969             : INLINE GEN
     970     4046045 : Flm_row(GEN x, long j)
     971     4046045 : { pari_APPLY_ulong((ulong)coeff(x, j, i)) }
     972             : /* A[x0,] */
     973             : INLINE GEN
     974      204834 : rowcopy(GEN x, long j)
     975      204834 : { pari_APPLY_type(t_VEC, gcopy(gcoeff(x, j, i))) }
     976             : /* A[x0, x1..x2] */
     977             : INLINE GEN
     978        2989 : row_i(GEN A, long x0, long x1, long x2)
     979             : {
     980        2989 :   long i, lB = x2 - x1 + 2;
     981        2989 :   GEN B  = cgetg(lB, t_VEC);
     982        2989 :   for (i=x1; i<=x2; i++) gel(B, i) = gcoeff(A, x0, i);
     983        2989 :   return B;
     984             : }
     985             : 
     986             : INLINE GEN
     987     5830581 : vecreverse(GEN A)
     988             : {
     989             :   long i, l;
     990     5830581 :   GEN B = cgetg_copy(A, &l);
     991     5830581 :   for (i=1; i<l; i++) gel(B, i) = gel(A, l-i);
     992     5830581 :   return B;
     993             : }
     994             : 
     995             : INLINE GEN
     996         525 : vecsmall_reverse(GEN A)
     997             : {
     998             :   long i, l;
     999         525 :   GEN B = cgetg_copy(A, &l);
    1000         525 :   for (i=1; i<l; i++) B[i] = A[l-i];
    1001         525 :   return B;
    1002             : }
    1003             : 
    1004             : INLINE void
    1005         253 : vecreverse_inplace(GEN y)
    1006             : {
    1007         253 :   long l = lg(y), lim = l>>1, i;
    1008         717 :   for (i = 1; i <= lim; i++)
    1009             :   {
    1010         464 :     GEN z = gel(y,i);
    1011         464 :     gel(y,i)    = gel(y,l-i);
    1012         464 :     gel(y,l-i) = z;
    1013             :   }
    1014         253 : }
    1015             : 
    1016             : INLINE GEN
    1017    47063077 : vecsmallpermute(GEN A, GEN p) { return perm_mul(A, p); }
    1018             : 
    1019             : INLINE GEN
    1020     6894236 : vecpermute(GEN A, GEN x)
    1021     6894236 : { pari_APPLY_type(typ(A), gel(A, x[i])) }
    1022             : 
    1023             : INLINE GEN
    1024     3263954 : rowpermute(GEN x, GEN p)
    1025     3263954 : { pari_APPLY_same(typ(gel(x,i)) == t_VECSMALL ? vecsmallpermute(gel(x, i), p)
    1026             :                                               : vecpermute(gel(x, i), p))
    1027             : }
    1028             : /*******************************************************************/
    1029             : /*                                                                 */
    1030             : /*                          PERMUTATIONS                           */
    1031             : /*                                                                 */
    1032             : /*******************************************************************/
    1033             : INLINE GEN
    1034      762405 : identity_zv(long n)
    1035             : {
    1036      762405 :   GEN v = cgetg(n+1, t_VECSMALL);
    1037             :   long i;
    1038      762413 :   for (i = 1; i <= n; i++) v[i] = i;
    1039      762413 :   return v;
    1040             : }
    1041             : INLINE GEN
    1042        2114 : identity_ZV(long n)
    1043             : {
    1044        2114 :   GEN v = cgetg(n+1, t_VEC);
    1045             :   long i;
    1046        2114 :   for (i = 1; i <= n; i++) gel(v,i) = utoipos(i);
    1047        2114 :   return v;
    1048             : }
    1049             : /* identity permutation */
    1050             : INLINE GEN
    1051      761912 : identity_perm(long n) { return identity_zv(n); }
    1052             : 
    1053             : /* assume d <= n */
    1054             : INLINE GEN
    1055       98434 : cyclic_perm(long n, long d)
    1056             : {
    1057       98434 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1058             :   long i;
    1059       98434 :   for (i = 1; i <= n-d; i++) perm[i] = i+d;
    1060       98434 :   for (     ; i <= n;   i++) perm[i] = i-n+d;
    1061       98434 :   return perm;
    1062             : }
    1063             : 
    1064             : /* Multiply (compose) two permutations */
    1065             : INLINE GEN
    1066    48339251 : perm_mul(GEN s, GEN x)
    1067    48339251 : { pari_APPLY_long(s[x[i]]) }
    1068             : 
    1069             : /* Compute the inverse (reciprocal) of a permutation. */
    1070             : INLINE GEN
    1071     1218819 : perm_inv(GEN x)
    1072             : {
    1073             :   long i, lx;
    1074     1218819 :   GEN y = cgetg_copy(x, &lx);
    1075     1218821 :   for (i=1; i<lx; i++) y[ x[i] ] = i;
    1076     1218821 :   return y;
    1077             : }
    1078             : /* Return s*t*s^-1 */
    1079             : INLINE GEN
    1080      416976 : perm_conj(GEN s, GEN t)
    1081             : {
    1082             :   long i, l;
    1083      416976 :   GEN v = cgetg_copy(s, &l);
    1084      416976 :   for (i = 1; i < l; i++) v[ s[i] ] = s[ t[i] ];
    1085      416976 :   return v;
    1086             : }
    1087             : 
    1088             : /*********************************************************************/
    1089             : /*                       MALLOC/FREE WRAPPERS                        */
    1090             : /*********************************************************************/
    1091             : #define BLOCK_SIGALRM_START          \
    1092             : {                                    \
    1093             :   int block=PARI_SIGINT_block;       \
    1094             :   PARI_SIGINT_block = 2;             \
    1095             :   MT_SIGINT_BLOCK(block);
    1096             : 
    1097             : #define BLOCK_SIGINT_START           \
    1098             : {                                    \
    1099             :   int block=PARI_SIGINT_block;       \
    1100             :   PARI_SIGINT_block = 1;             \
    1101             :   MT_SIGINT_BLOCK(block);
    1102             : 
    1103             : #define BLOCK_SIGINT_END             \
    1104             :   PARI_SIGINT_block = block;         \
    1105             :   MT_SIGINT_UNBLOCK(block);          \
    1106             :   if (!block && PARI_SIGINT_pending) \
    1107             :   {                                  \
    1108             :     int sig = PARI_SIGINT_pending;   \
    1109             :     PARI_SIGINT_pending = 0;         \
    1110             :     raise(sig);                      \
    1111             :   }                                  \
    1112             : }
    1113             : 
    1114             : INLINE void
    1115    73910325 : pari_free(void *pointer)
    1116             : {
    1117    73910325 :   BLOCK_SIGINT_START;
    1118    73932661 :   free(pointer);
    1119    73932661 :   BLOCK_SIGINT_END;
    1120    73929329 : }
    1121             : INLINE void*
    1122   280920786 : pari_malloc(size_t size)
    1123             : {
    1124   280920786 :   if (size)
    1125             :   {
    1126             :     char *tmp;
    1127   280920786 :     BLOCK_SIGINT_START;
    1128   280923296 :     tmp = (char*)malloc(size);
    1129   280923296 :     BLOCK_SIGINT_END;
    1130   280923024 :     if (!tmp) pari_err(e_MEM);
    1131   280923024 :     return tmp;
    1132             :   }
    1133           0 :   return NULL;
    1134             : }
    1135             : INLINE void*
    1136      819192 : pari_realloc(void *pointer, size_t size)
    1137             : {
    1138             :   char *tmp;
    1139             : 
    1140      819192 :   BLOCK_SIGINT_START;
    1141      822314 :   if (!pointer) tmp = (char *) malloc(size);
    1142       63998 :   else tmp = (char *) realloc(pointer,size);
    1143      822314 :   BLOCK_SIGINT_END;
    1144      821511 :   if (!tmp) pari_err(e_MEM);
    1145      821511 :   return tmp;
    1146             : }
    1147             : INLINE void*
    1148       37344 : pari_calloc(size_t size)
    1149             : {
    1150       37344 :   void *t = pari_malloc(size);
    1151       37344 :   memset(t, 0, size); return t;
    1152             : }
    1153             : INLINE GEN
    1154        5845 : cgetalloc(long t, size_t l)
    1155             : { /* evallg may raise e_OVERFLOW, which would leak x */
    1156        5845 :   ulong x0 = evaltyp(t) | evallg(l);
    1157        5845 :   GEN x = (GEN)pari_malloc(l * sizeof(long));
    1158        5845 :   x[0] = x0; return x;
    1159             : }
    1160             : 
    1161             : /*******************************************************************/
    1162             : /*                                                                 */
    1163             : /*                       GARBAGE COLLECTION                        */
    1164             : /*                                                                 */
    1165             : /*******************************************************************/
    1166             : /* copy integer x as if we had set_avma(av) */
    1167             : INLINE GEN
    1168  3852982611 : icopy_avma(GEN x, pari_sp av)
    1169             : {
    1170  3852982611 :   long i = lgefint(x), lx = i;
    1171  3852982611 :   GEN y = ((GEN)av) - i;
    1172  3852982611 :   while (--i > 0) y[i] = x[i];
    1173  3852982611 :   y[0] = evaltyp(t_INT)|evallg(lx);
    1174  3852753122 :   return y;
    1175             : }
    1176             : /* copy leaf x as if we had set_avma(av) */
    1177             : INLINE GEN
    1178   189254875 : leafcopy_avma(GEN x, pari_sp av)
    1179             : {
    1180   189254875 :   long i = lg(x);
    1181   189254875 :   GEN y = ((GEN)av) - i;
    1182   189254875 :   while (--i > 0) y[i] = x[i];
    1183   189254875 :   y[0] = x[0] & (~CLONEBIT);
    1184   189254875 :   return y;
    1185             : }
    1186             : INLINE GEN
    1187   672954301 : gerepileuptoleaf(pari_sp av, GEN x)
    1188             : {
    1189             :   long lx;
    1190             :   GEN q;
    1191             : 
    1192   672954301 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1193   672983000 :   lx = lg(x);
    1194   672983000 :   q = ((GEN)av) - lx;
    1195   672983000 :   set_avma((pari_sp)q);
    1196   674502960 :   while (--lx >= 0) q[lx] = x[lx];
    1197   674502960 :   return q;
    1198             : }
    1199             : INLINE GEN
    1200  1314752485 : gerepileuptoint(pari_sp av, GEN x)
    1201             : {
    1202  1314752485 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1203  1160910826 :   set_avma((pari_sp)icopy_avma(x, av));
    1204  1163101281 :   return (GEN)avma;
    1205             : }
    1206             : INLINE GEN
    1207   831941911 : gerepileupto(pari_sp av, GEN x)
    1208             : {
    1209   831941911 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1210   740603558 :   switch(typ(x))
    1211             :   { /* non-default = !is_recursive_t(tq) */
    1212   256957291 :     case t_INT: return gerepileuptoint(av, x);
    1213             :     case t_REAL:
    1214             :     case t_STR:
    1215   157318823 :     case t_VECSMALL: return gerepileuptoleaf(av,x);
    1216             :     default:
    1217             :       /* NB: x+i --> ((long)x) + i*sizeof(long) */
    1218   326327444 :       return gerepile(av, (pari_sp) (x+lg(x)), x);
    1219             :   }
    1220             : }
    1221             : INLINE double
    1222     2522076 : gc_double(pari_sp av, double d) { set_avma(av); return d; }
    1223             : INLINE long
    1224   113104406 : gc_long(pari_sp av, long s) { set_avma(av); return s; }
    1225             : INLINE ulong
    1226    13848363 : gc_ulong(pari_sp av, ulong s) { set_avma(av); return s; }
    1227             : INLINE int
    1228    22696998 : gc_bool(pari_sp av, int s) { set_avma(av); return s; }
    1229             : INLINE int
    1230     3357905 : gc_int(pari_sp av, int s) { set_avma(av); return s; }
    1231             : INLINE GEN
    1232     1691541 : gc_NULL(pari_sp av) { set_avma(av); return NULL; }
    1233             : 
    1234             : /* gerepileupto(av, gcopy(x)) */
    1235             : INLINE GEN
    1236    54617542 : gerepilecopy(pari_sp av, GEN x)
    1237             : {
    1238    54617542 :   if (is_recursive_t(typ(x)))
    1239             :   {
    1240    49959718 :     GENbin *p = copy_bin(x);
    1241    49960304 :     set_avma(av); return bin_copy(p);
    1242             :   }
    1243             :   else
    1244             :   {
    1245     4657834 :     set_avma(av);
    1246     4657838 :     if (x < (GEN)av) {
    1247     3170312 :       if (x < (GEN)pari_mainstack->bot) new_chunk(lg(x));
    1248     3170312 :       x = leafcopy_avma(x, av);
    1249     3170326 :       set_avma((pari_sp)x);
    1250             :     } else
    1251     1487526 :       x = leafcopy(x);
    1252     4657848 :     return x;
    1253             :   }
    1254             : }
    1255             : 
    1256             : INLINE void
    1257    28854648 : guncloneNULL(GEN x) { if (x) gunclone(x); }
    1258             : INLINE void
    1259      173016 : guncloneNULL_deep(GEN x) { if (x) gunclone_deep(x); }
    1260             : 
    1261             : /* Takes an array of pointers to GENs, of length n. Copies all
    1262             :  * objects to contiguous locations and cleans up the stack between
    1263             :  * av and avma. */
    1264             : INLINE void
    1265      202778 : gerepilemany(pari_sp av, GEN* gptr[], int n)
    1266             : {
    1267             :   int i;
    1268      202778 :   for (i=0; i<n; i++) *gptr[i] = (GEN)copy_bin(*gptr[i]);
    1269      202778 :   set_avma(av);
    1270      202778 :   for (i=0; i<n; i++) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1271      202778 : }
    1272             : 
    1273             : INLINE void
    1274     7672532 : gerepileall(pari_sp av, int n, ...)
    1275             : {
    1276             :   int i;
    1277     7672532 :   va_list a; va_start(a, n);
    1278     7672532 :   if (n < 10)
    1279             :   {
    1280             :     GEN *gptr[10];
    1281    22239084 :     for (i=0; i<n; i++)
    1282    14566413 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1283     7672671 :     set_avma(av);
    1284     7672508 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1285             : 
    1286             :   }
    1287             :   else
    1288             :   {
    1289           0 :     GEN **gptr = (GEN**)  pari_malloc(n*sizeof(GEN*));
    1290           0 :     for (i=0; i<n; i++)
    1291           0 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1292           0 :     set_avma(av);
    1293           0 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1294           0 :     pari_free(gptr);
    1295             :   }
    1296     7672785 :   va_end(a);
    1297     7672785 : }
    1298             : 
    1299             : INLINE void
    1300           6 : gerepilecoeffs(pari_sp av, GEN x, int n)
    1301             : {
    1302             :   int i;
    1303           6 :   for (i=0; i<n; i++) gel(x,i) = (GEN)copy_bin(gel(x,i));
    1304           6 :   set_avma(av);
    1305           6 :   for (i=0; i<n; i++) gel(x,i) = bin_copy((GENbin*)x[i]);
    1306           6 : }
    1307             : 
    1308             : /* p from copy_bin. Copy p->x back to stack, then destroy p */
    1309             : INLINE GEN
    1310    65149666 : bin_copy(GENbin *p)
    1311             : {
    1312             :   GEN x, y, base;
    1313             :   long dx, len;
    1314             : 
    1315    65149666 :   x   = p->x; if (!x) { pari_free(p); return gen_0; }
    1316    65142442 :   len = p->len;
    1317    65142442 :   base= p->base; dx = x - base;
    1318    65142442 :   y = (GEN)memcpy((void*)new_chunk(len), (void*)GENbinbase(p), len*sizeof(long));
    1319    65142301 :   y += dx;
    1320    65142301 :   p->rebase(y, ((ulong)y-(ulong)x));
    1321    65142395 :   pari_free(p); return y;
    1322             : }
    1323             : 
    1324             : INLINE GEN
    1325   130292480 : GENbinbase(GENbin *p) { return (GEN)(p + 1); }
    1326             : 
    1327             : INLINE void
    1328    32592518 : cgiv(GEN x)
    1329             : {
    1330    32592518 :   pari_sp av = (pari_sp)(x+lg(x));
    1331    32592518 :   if (isonstack((GEN)av)) set_avma(av);
    1332    32592088 : }
    1333             : 
    1334             : INLINE void
    1335     1266892 : killblock(GEN x) { gunclone(x); }
    1336             : 
    1337             : INLINE int
    1338    25959194 : is_universal_constant(GEN x) { return (x >= gen_0 && x <= ghalf); }
    1339             : 
    1340             : /*******************************************************************/
    1341             : /*                                                                 */
    1342             : /*                    CONVERSION / ASSIGNMENT                      */
    1343             : /*                                                                 */
    1344             : /*******************************************************************/
    1345             : /* z is a type which may be a t_COMPLEX component (not a t_QUAD) */
    1346             : INLINE GEN
    1347     3753293 : cxcompotor(GEN z, long prec)
    1348             : {
    1349     3753293 :   switch(typ(z))
    1350             :   {
    1351     2118076 :     case t_INT:  return itor(z, prec);
    1352      136668 :     case t_FRAC: return fractor(z, prec);
    1353     1498549 :     case t_REAL: return rtor(z, prec);
    1354           0 :     default: pari_err_TYPE("cxcompotor",z);
    1355             :              return NULL; /* LCOV_EXCL_LINE */
    1356             :   }
    1357             : }
    1358             : INLINE GEN
    1359     1862514 : cxtofp(GEN x, long prec)
    1360     1862514 : { retmkcomplex(cxcompotor(gel(x,1),prec), cxcompotor(gel(x,2),prec)); }
    1361             : 
    1362             : INLINE GEN
    1363      291452 : cxtoreal(GEN q)
    1364      291452 : { return (typ(q) == t_COMPLEX && gequal0(gel(q,2)))? gel(q,1): q; }
    1365             : 
    1366             : INLINE double
    1367    35085659 : gtodouble(GEN x)
    1368             : {
    1369    35085659 :   if (typ(x)!=t_REAL) {
    1370     7619660 :     pari_sp av = avma;
    1371     7619660 :     x = gtofp(x, DEFAULTPREC);
    1372     7619660 :     if (typ(x)!=t_REAL) pari_err_TYPE("gtodouble [t_REAL expected]", x);
    1373     7619660 :     set_avma(av);
    1374             :   }
    1375    35085659 :   return rtodbl(x);
    1376             : }
    1377             : INLINE long
    1378    73377918 : gtos(GEN x) {
    1379    73377918 :   if (typ(x) != t_INT) pari_err_TYPE("gtos [integer expected]",x);
    1380    73377911 :   return itos(x);
    1381             : }
    1382             : 
    1383             : INLINE ulong
    1384      152654 : gtou(GEN x) {
    1385      152654 :   if (typ(x) != t_INT || signe(x)<0)
    1386           0 :     pari_err_TYPE("gtou [integer >=0 expected]",x);
    1387      152671 :   return itou(x);
    1388             : }
    1389             : 
    1390             : INLINE GEN
    1391    23376093 : absfrac(GEN x)
    1392             : {
    1393    23376093 :   GEN y = cgetg(3, t_FRAC);
    1394    23376093 :   gel(y,1) = absi(gel(x,1));
    1395    23376093 :   gel(y,2) = icopy(gel(x,2)); return y;
    1396             : }
    1397             : INLINE GEN
    1398       38489 : absfrac_shallow(GEN x)
    1399       38489 : { return signe(gel(x,1))>0? x: mkfrac(negi(gel(x,1)), gel(x,2)); }
    1400             : INLINE GEN
    1401     7848468 : Q_abs(GEN x) { return (typ(x) == t_INT)? absi(x): absfrac(x); }
    1402             : INLINE GEN
    1403      140544 : Q_abs_shallow(GEN x)
    1404      140544 : { return (typ(x) == t_INT)? absi_shallow(x): absfrac_shallow(x); }
    1405             : INLINE GEN
    1406       12558 : R_abs_shallow(GEN x)
    1407       12558 : { return (typ(x) == t_FRAC)? absfrac_shallow(x): mpabs_shallow(x); }
    1408             : INLINE GEN
    1409           0 : R_abs(GEN x)
    1410           0 : { return (typ(x) == t_FRAC)? absfrac(x): mpabs(x); }
    1411             : 
    1412             : /* Force z to be of type real/complex with floating point components */
    1413             : INLINE GEN
    1414    36621648 : gtofp(GEN z, long prec)
    1415             : {
    1416    36621648 :   switch(typ(z))
    1417             :   {
    1418    22939992 :     case t_INT:  return itor(z, prec);
    1419      375254 :     case t_FRAC: return fractor(z, prec);
    1420    11679260 :     case t_REAL: return rtor(z, prec);
    1421             :     case t_COMPLEX: {
    1422     1627142 :       GEN a = gel(z,1), b = gel(z,2);
    1423     1627142 :       if (isintzero(b)) return cxcompotor(a, prec);
    1424     1624404 :       if (isintzero(a)) {
    1425        3277 :         GEN y = cgetg(3, t_COMPLEX);
    1426        3277 :         b = cxcompotor(b, prec);
    1427        3277 :         gel(y,1) = real_0_bit(expo(b) - prec2nbits(prec));
    1428        3277 :         gel(y,2) = b; return y;
    1429             :       }
    1430     1621127 :       return cxtofp(z, prec);
    1431             :     }
    1432           0 :     case t_QUAD: return quadtofp(z, prec);
    1433           0 :     default: pari_err_TYPE("gtofp",z);
    1434             :              return NULL; /* LCOV_EXCL_LINE */
    1435             :   }
    1436             : }
    1437             : /* Force z to be of type real / int */
    1438             : INLINE GEN
    1439       22400 : gtomp(GEN z, long prec)
    1440             : {
    1441       22400 :   switch(typ(z))
    1442             :   {
    1443          14 :     case t_INT:  return z;
    1444       22386 :     case t_FRAC: return fractor(z, prec);
    1445           0 :     case t_REAL: return rtor(z, prec);
    1446           0 :     case t_QUAD: z = quadtofp(z, prec);
    1447           0 :                  if (typ(z) == t_REAL) return z;
    1448           0 :     default: pari_err_TYPE("gtomp",z);
    1449             :              return NULL; /* LCOV_EXCL_LINE */
    1450             :   }
    1451             : }
    1452             : 
    1453             : INLINE GEN
    1454      834496 : RgX_gtofp(GEN x, long prec)
    1455             : {
    1456             :   long l;
    1457      834496 :   GEN y = cgetg_copy(x, &l);
    1458      834496 :   while (--l > 1) gel(y,l) = gtofp(gel(x,l), prec);
    1459      834496 :   y[1] = x[1]; return y;
    1460             : }
    1461             : INLINE GEN
    1462     1207615 : RgC_gtofp(GEN x, long prec)
    1463     1207615 : { pari_APPLY_type(t_COL, gtofp(gel(x,i), prec)) }
    1464             : 
    1465             : INLINE GEN
    1466          42 : RgV_gtofp(GEN x, long prec)
    1467          42 : { pari_APPLY_type(t_VEC, gtofp(gel(x,i), prec)) }
    1468             : 
    1469             : INLINE GEN
    1470      136785 : RgM_gtofp(GEN x, long prec)
    1471      136785 : { pari_APPLY_same(RgC_gtofp(gel(x,i), prec)) }
    1472             : 
    1473             : INLINE GEN
    1474         560 : RgC_gtomp(GEN x, long prec)
    1475         560 : { pari_APPLY_type(t_COL, gtomp(gel(x,i), prec)) }
    1476             : 
    1477             : INLINE GEN
    1478          14 : RgM_gtomp(GEN x, long prec)
    1479          14 : { pari_APPLY_same(RgC_gtomp(gel(x,i), prec)) }
    1480             : 
    1481             : INLINE GEN
    1482        9969 : RgX_fpnorml2(GEN x, long prec)
    1483             : {
    1484        9969 :   pari_sp av = avma;
    1485        9969 :   return gerepileupto(av, gnorml2(RgX_gtofp(x, prec)));
    1486             : }
    1487             : INLINE GEN
    1488      189700 : RgC_fpnorml2(GEN x, long prec)
    1489             : {
    1490      189700 :   pari_sp av = avma;
    1491      189700 :   return gerepileupto(av, gnorml2(RgC_gtofp(x, prec)));
    1492             : }
    1493             : INLINE GEN
    1494        4119 : RgM_fpnorml2(GEN x, long prec)
    1495             : {
    1496        4119 :   pari_sp av = avma;
    1497        4119 :   return gerepileupto(av, gnorml2(RgM_gtofp(x, prec)));
    1498             : }
    1499             : 
    1500             : /* y a t_REAL */
    1501             : INLINE void
    1502      216244 : affgr(GEN x, GEN y)
    1503             : {
    1504             :   pari_sp av;
    1505      216244 :   switch(typ(x)) {
    1506        5992 :     case t_INT:  affir(x,y); break;
    1507      210252 :     case t_REAL: affrr(x,y); break;
    1508           0 :     case t_FRAC: rdiviiz(gel(x,1),gel(x,2), y); break;
    1509           0 :     case t_QUAD: av = avma; affgr(quadtofp(x,realprec(y)), y); set_avma(av); break;
    1510           0 :     default: pari_err_TYPE2("=",x,y);
    1511             :   }
    1512      216244 : }
    1513             : 
    1514             : INLINE GEN
    1515      261223 : affc_fixlg(GEN x, GEN res)
    1516             : {
    1517      261223 :   if (typ(x) == t_COMPLEX)
    1518             :   {
    1519      207529 :     affrr_fixlg(gel(x,1), gel(res,1));
    1520      207529 :     affrr_fixlg(gel(x,2), gel(res,2));
    1521             :   }
    1522             :   else
    1523             :   {
    1524       53694 :     set_avma((pari_sp)(res+3));
    1525       53694 :     res = cgetr(realprec(gel(res,1)));
    1526       53694 :     affrr_fixlg(x, res);
    1527             :   }
    1528      261223 :   return res;
    1529             : }
    1530             : 
    1531             : INLINE GEN
    1532           0 : trunc_safe(GEN x) { long e; return gcvtoi(x,&e); }
    1533             : 
    1534             : /*******************************************************************/
    1535             : /*                                                                 */
    1536             : /*                          LENGTH CONVERSIONS                     */
    1537             : /*                                                                 */
    1538             : /*******************************************************************/
    1539             : INLINE long
    1540       32616 : ndec2nlong(long x) { return 1 + (long)((x)*(LOG2_10/BITS_IN_LONG)); }
    1541             : INLINE long
    1542       24130 : ndec2prec(long x) { return 2 + ndec2nlong(x); }
    1543             : INLINE long
    1544        8486 : ndec2nbits(long x) { return ndec2nlong(x) << TWOPOTBITS_IN_LONG; }
    1545             : /* Fast implementation of ceil(x / (8*sizeof(long))); typecast to (ulong)
    1546             :  * to avoid overflow. Faster than 1 + ((x-1)>>TWOPOTBITS_IN_LONG)) :
    1547             :  *   addl, shrl instead of subl, sarl, addl */
    1548             : INLINE long
    1549     1241404 : nbits2nlong(long x) {
    1550     1241404 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1551             : }
    1552             : 
    1553             : INLINE long
    1554   321966344 : nbits2extraprec(long x) {
    1555   321966344 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1556             : }
    1557             : 
    1558             : /* Fast implementation of 2 + nbits2nlong(x) */
    1559             : INLINE long
    1560   112629618 : nbits2prec(long x) {
    1561   112629618 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1562             : }
    1563             : INLINE long
    1564    20966740 : nbits2lg(long x) {
    1565    20966740 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1566             : }
    1567             : /* ceil(x / sizeof(long)) */
    1568             : INLINE long
    1569     9817075 : nchar2nlong(long x) {
    1570     9817075 :   return (long)(((ulong)x+sizeof(long)-1) >> (TWOPOTBITS_IN_LONG-3L));
    1571             : }
    1572             : INLINE long
    1573  1178569768 : prec2nbits(long x) { return (x-2) * BITS_IN_LONG; }
    1574             : INLINE double
    1575      520489 : bit_accuracy_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1576             : INLINE double
    1577      287281 : prec2nbits_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1578             : INLINE long
    1579    34083701 : bit_prec(GEN x) { return prec2nbits(realprec(x)); }
    1580             : INLINE long
    1581  1061458812 : bit_accuracy(long x) { return prec2nbits(x); }
    1582             : INLINE long
    1583       12462 : prec2ndec(long x) { return (long)prec2nbits_mul(x, LOG10_2); }
    1584             : INLINE long
    1585         200 : nbits2ndec(long x) { return (long)(x * LOG10_2); }
    1586             : INLINE long
    1587        3275 : precdbl(long x) {return (x - 1) << 1;}
    1588             : INLINE long
    1589  3603152705 : divsBIL(long n) { return n >> TWOPOTBITS_IN_LONG; }
    1590             : INLINE long
    1591  3553749832 : remsBIL(long n) { return n & (BITS_IN_LONG-1); }
    1592             : 
    1593             : /*********************************************************************/
    1594             : /**                                                                 **/
    1595             : /**                      OPERATIONS MODULO m                        **/
    1596             : /**                                                                 **/
    1597             : /*********************************************************************/
    1598             : /* Assume m > 0, more efficient if 0 <= a, b < m */
    1599             : 
    1600             : INLINE GEN
    1601    35079064 : Fp_red(GEN a, GEN m) { return modii(a, m); }
    1602             : INLINE GEN
    1603    75344226 : Fp_add(GEN a, GEN b, GEN m)
    1604             : {
    1605    75344226 :   pari_sp av=avma;
    1606    75344226 :   GEN p = addii(a,b);
    1607    73931257 :   long s = signe(p);
    1608    73931257 :   if (!s) return p; /* = gen_0 */
    1609    66141886 :   if (s > 0) /* general case */
    1610             :   {
    1611    65915481 :     GEN t = subii(p, m);
    1612    66897528 :     s = signe(t);
    1613    66897528 :     if (!s) { set_avma(av); return gen_0; }
    1614    61050645 :     if (s < 0) { set_avma((pari_sp)p); return p; }
    1615    26019764 :     if (cmpii(t, m) < 0) return gerepileuptoint(av, t); /* general case ! */
    1616     1112607 :     p = remii(t, m);
    1617             :   }
    1618             :   else
    1619      226405 :     p = modii(p, m);
    1620     1339012 :   return gerepileuptoint(av, p);
    1621             : }
    1622             : INLINE GEN
    1623    57322706 : Fp_sub(GEN a, GEN b, GEN m)
    1624             : {
    1625    57322706 :   pari_sp av=avma;
    1626    57322706 :   GEN p = subii(a,b);
    1627    56799546 :   long s = signe(p);
    1628    56799546 :   if (!s) return p; /* = gen_0 */
    1629    50546394 :   if (s > 0)
    1630             :   {
    1631    24427414 :     if (cmpii(p, m) < 0) return p; /* general case ! */
    1632     1128563 :     p = remii(p, m);
    1633             :   }
    1634             :   else
    1635             :   {
    1636    26118980 :     GEN t = addii(p, m);
    1637    26066039 :     if (!s) { set_avma(av); return gen_0; }
    1638    26066039 :     if (s > 0) return gerepileuptoint(av, t); /* general case ! */
    1639    26066039 :     p = modii(t, m);
    1640             :   }
    1641    27731581 :   return gerepileuptoint(av, p);
    1642             : }
    1643             : INLINE GEN
    1644    13587578 : Fp_neg(GEN b, GEN m)
    1645             : {
    1646    13587578 :   pari_sp av = avma;
    1647    13587578 :   long s = signe(b);
    1648             :   GEN p;
    1649    13587578 :   if (!s) return gen_0;
    1650    10093966 :   if (s > 0)
    1651             :   {
    1652     9866231 :     p = subii(m, b);
    1653     9864074 :     if (signe(p) >= 0) return p; /* general case ! */
    1654      104389 :     p = modii(p, m);
    1655             :   } else
    1656      227735 :     p = remii(negi(b), m);
    1657      332124 :   return gerepileuptoint(av, p);
    1658             : }
    1659             : 
    1660             : INLINE GEN
    1661       23613 : Fp_halve(GEN a, GEN p)
    1662             : {
    1663       23613 :   if (mpodd(a)) a = addii(a,p);
    1664       23613 :   return shifti(a,-1);
    1665             : }
    1666             : 
    1667             : /* assume 0 <= u < p and ps2 = p>>1 */
    1668             : INLINE GEN
    1669    16833064 : Fp_center(GEN u, GEN p, GEN ps2)
    1670    16833064 : { return abscmpii(u,ps2)<=0? icopy(u): subii(u,p); }
    1671             : /* same without copy */
    1672             : INLINE GEN
    1673    15770397 : Fp_center_i(GEN u, GEN p, GEN ps2)
    1674    15770397 : { return abscmpii(u,ps2)<=0? u: subii(u,p); }
    1675             : 
    1676             : /* x + y*z mod p */
    1677             : INLINE GEN
    1678     5190908 : Fp_addmul(GEN x, GEN y, GEN z, GEN p)
    1679             : {
    1680             :   pari_sp av;
    1681     5190908 :   if (!signe(y) || !signe(z)) return Fp_red(x, p);
    1682     4892774 :   if (!signe(x)) return Fp_mul(z,y, p);
    1683     4587666 :   av = avma;
    1684     4587666 :   return gerepileuptoint(av, modii(addii(x, mulii(y,z)), p));
    1685             : }
    1686             : 
    1687             : INLINE GEN
    1688    93678541 : Fp_mul(GEN a, GEN b, GEN m)
    1689             : {
    1690    93678541 :   pari_sp av=avma;
    1691             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1692    93678541 :   (void)new_chunk(lg(a)+lg(b)+(lg(m)<<1));
    1693    93686730 :   p = mulii(a,b);
    1694    93822742 :   set_avma(av); return modii(p,m);
    1695             : }
    1696             : INLINE GEN
    1697    34455492 : Fp_sqr(GEN a, GEN m)
    1698             : {
    1699    34455492 :   pari_sp av=avma;
    1700             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1701    34455492 :   (void)new_chunk((lg(a)+lg(m))<<1);
    1702    34361794 :   p = sqri(a);
    1703    31371132 :   set_avma(av); return remii(p,m); /*Use remii: p >= 0 */
    1704             : }
    1705             : INLINE GEN
    1706    67820127 : Fp_mulu(GEN a, ulong b, GEN m)
    1707             : {
    1708    67820127 :   long l = lgefint(m);
    1709    67820127 :   if (l == 3)
    1710             :   {
    1711    41437998 :     ulong mm = m[2];
    1712    41437998 :     return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1713             :   } else {
    1714    26382129 :     pari_sp av = avma;
    1715             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1716    26382129 :     (void)new_chunk(lg(a)+1+(l<<1));
    1717    26342459 :     p = muliu(a,b);
    1718    24655847 :     set_avma(av); return modii(p,m);
    1719             :   }
    1720             : }
    1721             : INLINE GEN
    1722           0 : Fp_muls(GEN a, long b, GEN m)
    1723             : {
    1724           0 :   long l = lgefint(m);
    1725           0 :   if (l == 3)
    1726             :   {
    1727           0 :     ulong mm = m[2];
    1728           0 :     if (b < 0)
    1729             :     {
    1730           0 :       ulong t = Fl_mul(umodiu(a, mm), -b, mm);
    1731           0 :       return t? utoipos(mm - t): gen_0;
    1732             :     }
    1733             :     else
    1734           0 :       return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1735             :   } else {
    1736           0 :     pari_sp av = avma;
    1737             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1738           0 :     (void)new_chunk(lg(a)+1+(l<<1));
    1739           0 :     p = mulis(a,b);
    1740           0 :     set_avma(av); return modii(p,m);
    1741             :   }
    1742             : }
    1743             : 
    1744             : INLINE GEN
    1745     9902843 : Fp_inv(GEN a, GEN m)
    1746             : {
    1747             :   GEN res;
    1748     9902843 :   if (! invmod(a,m,&res)) pari_err_INV("Fp_inv", mkintmod(res,m));
    1749     9902496 :   return res;
    1750             : }
    1751             : INLINE GEN
    1752      324886 : Fp_invsafe(GEN a, GEN m)
    1753             : {
    1754             :   GEN res;
    1755      324886 :   if (! invmod(a,m,&res)) return NULL;
    1756      324886 :   return res;
    1757             : }
    1758             : INLINE GEN
    1759     1656441 : Fp_div(GEN a, GEN b, GEN m)
    1760             : {
    1761     1656441 :   pari_sp av = avma;
    1762             :   GEN p;
    1763     1656441 :   if (lgefint(b) == 3)
    1764             :   {
    1765      669107 :     a = Fp_divu(a, b[2], m);
    1766      669107 :     if (signe(b) < 0) a = Fp_neg(a, m);
    1767      669107 :     return a;
    1768             :   }
    1769             :   /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1770      987334 :   (void)new_chunk(lg(a)+(lg(m)<<1));
    1771      987334 :   p = mulii(a, Fp_inv(b,m));
    1772      987334 :   set_avma(av); return modii(p,m);
    1773             : }
    1774             : INLINE GEN
    1775     1402582 : Fp_divu(GEN x, ulong a, GEN p)
    1776             : {
    1777     1402582 :   pari_sp av = avma;
    1778             :   ulong b;
    1779     1402582 :   if (lgefint(p) == 3)
    1780             :   {
    1781      985109 :     ulong pp = p[2], xp = umodiu(x, pp);
    1782      985109 :     return xp? utoipos(Fl_div(xp, a % pp, pp)): gen_0;
    1783             :   }
    1784      417473 :   x = Fp_red(x, p);
    1785      417472 :   b = Fl_neg(Fl_div(umodiu(x,a), umodiu(p,a), a), a); /* x + pb = 0 (mod a) */
    1786      417476 :   return gerepileuptoint(av, diviuexact(addmuliu(x, p, b), a));
    1787             : }
    1788             : 
    1789             : INLINE GEN
    1790      847844 : Flx_mulu(GEN x, ulong a, ulong p) { return Flx_Fl_mul(x,a%p,p); }
    1791             : 
    1792             : INLINE GEN
    1793           0 : get_F2x_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1794             : 
    1795             : INLINE long
    1796      449777 : get_F2x_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1797             : 
    1798             : INLINE long
    1799      275803 : get_F2x_degree(GEN T) { return typ(T)==t_VEC? F2x_degree(gel(T,2)): F2x_degree(T); }
    1800             : 
    1801             : INLINE GEN
    1802         399 : get_F2xqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1803             : 
    1804             : INLINE long
    1805      377013 : get_F2xqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1806             : 
    1807             : INLINE long
    1808      201929 : get_F2xqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1809             : 
    1810             : INLINE GEN
    1811     7520653 : get_Flx_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1812             : 
    1813             : INLINE long
    1814    19647460 : get_Flx_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1815             : 
    1816             : INLINE long
    1817    38329321 : get_Flx_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1818             : 
    1819             : INLINE GEN
    1820        2482 : get_FlxqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1821             : 
    1822             : INLINE long
    1823      221973 : get_FlxqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1824             : 
    1825             : INLINE long
    1826      277751 : get_FlxqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1827             : 
    1828             : INLINE GEN
    1829     1639803 : get_FpX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1830             : 
    1831             : INLINE long
    1832     3947806 : get_FpX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1833             : 
    1834             : INLINE long
    1835     2897410 : get_FpX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1836             : 
    1837             : INLINE GEN
    1838      142586 : get_FpXQX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1839             : 
    1840             : INLINE long
    1841       57357 : get_FpXQX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1842             : 
    1843             : INLINE long
    1844        2187 : get_FpXQX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1845             : 
    1846             : /*******************************************************************/
    1847             : /*                                                                 */
    1848             : /*                        ADDMULII / SUBMULII                      */
    1849             : /*                                                                 */
    1850             : /*******************************************************************/
    1851             : /* x - y*z */
    1852             : INLINE GEN
    1853      337576 : submulii(GEN x, GEN y, GEN z)
    1854             : {
    1855      337576 :   long lx = lgefint(x), ly, lz;
    1856             :   pari_sp av;
    1857             :   GEN t;
    1858      337576 :   if (lx == 2) { t = mulii(z,y); togglesign(t); return t; }
    1859      294404 :   ly = lgefint(y);
    1860      294404 :   if (ly == 2) return icopy(x);
    1861      247184 :   lz = lgefint(z);
    1862      247184 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1863      247184 :   t = mulii(z, y);
    1864      247184 :   set_avma(av); return subii(x,t);
    1865             : }
    1866             : /* y*z - x */
    1867             : INLINE GEN
    1868     1291805 : mulsubii(GEN y, GEN z, GEN x)
    1869             : {
    1870     1291805 :   long lx = lgefint(x), ly, lz;
    1871             :   pari_sp av;
    1872             :   GEN t;
    1873     1291805 :   if (lx == 2) return mulii(z,y);
    1874      824377 :   ly = lgefint(y);
    1875      824377 :   if (ly == 2) return negi(x);
    1876      756476 :   lz = lgefint(z);
    1877      756476 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1878      756476 :   t = mulii(z, y);
    1879      756476 :   set_avma(av); return subii(t,x);
    1880             : }
    1881             : 
    1882             : /* x - u*y */
    1883             : INLINE GEN
    1884        7595 : submuliu(GEN x, GEN y, ulong u)
    1885             : {
    1886             :   pari_sp av;
    1887        7595 :   long ly = lgefint(y);
    1888        7595 :   if (ly == 2) return icopy(x);
    1889        7595 :   av = avma;
    1890        7595 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1891        7595 :   y = mului(u,y);
    1892        7595 :   set_avma(av); return subii(x, y);
    1893             : }
    1894             : /* x + u*y */
    1895             : INLINE GEN
    1896      425071 : addmuliu(GEN x, GEN y, ulong u)
    1897             : {
    1898             :   pari_sp av;
    1899      425071 :   long ly = lgefint(y);
    1900      425071 :   if (ly == 2) return icopy(x);
    1901      425071 :   av = avma;
    1902      425071 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1903      425071 :   y = mului(u,y);
    1904      425068 :   set_avma(av); return addii(x, y);
    1905             : }
    1906             : /* x - u*y */
    1907             : INLINE GEN
    1908   125088546 : submuliu_inplace(GEN x, GEN y, ulong u)
    1909             : {
    1910             :   pari_sp av;
    1911   125088546 :   long ly = lgefint(y);
    1912   125088546 :   if (ly == 2) return x;
    1913   100120721 :   av = avma;
    1914   100120721 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1915   100120721 :   y = mului(u,y);
    1916   100120721 :   set_avma(av); return subii(x, y);
    1917             : }
    1918             : /* x + u*y */
    1919             : INLINE GEN
    1920   123472212 : addmuliu_inplace(GEN x, GEN y, ulong u)
    1921             : {
    1922             :   pari_sp av;
    1923   123472212 :   long ly = lgefint(y);
    1924   123472212 :   if (ly == 2) return x;
    1925    99947877 :   av = avma;
    1926    99947877 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1927    99947877 :   y = mului(u,y);
    1928    99947877 :   set_avma(av); return addii(x, y);
    1929             : }
    1930             : /* ux + vy */
    1931             : INLINE GEN
    1932    21407847 : lincombii(GEN u, GEN v, GEN x, GEN y)
    1933             : {
    1934    21407847 :   long lx = lgefint(x), ly;
    1935             :   GEN p1, p2;
    1936             :   pari_sp av;
    1937    21407847 :   if (lx == 2) return mulii(v,y);
    1938    15106298 :   ly = lgefint(y);
    1939    15106298 :   if (ly == 2) return mulii(u,x);
    1940    13836185 :   av = avma; (void)new_chunk(lx+ly+lgefint(u)+lgefint(v)); /* HACK */
    1941    13836198 :   p1 = mulii(u,x);
    1942    13836046 :   p2 = mulii(v,y);
    1943    13836044 :   set_avma(av); return addii(p1,p2);
    1944             : }
    1945             : 
    1946             : /*******************************************************************/
    1947             : /*                                                                 */
    1948             : /*                          GEN SUBTYPES                           */
    1949             : /*                                                                 */
    1950             : /*******************************************************************/
    1951             : 
    1952             : INLINE int
    1953  1326391167 : is_const_t(long t) { return (t < t_POLMOD); }
    1954             : INLINE int
    1955        5479 : is_extscalar_t(long t) { return (t <= t_POL); }
    1956             : INLINE int
    1957     1262958 : is_intreal_t(long t) { return (t <= t_REAL); }
    1958             : INLINE int
    1959   418650074 : is_matvec_t(long t) { return (t >= t_VEC && t <= t_MAT); }
    1960             : INLINE int
    1961    60500859 : is_noncalc_t(long tx) { return (tx) >= t_LIST; }
    1962             : INLINE int
    1963     1304543 : is_rational_t(long t) { return (t == t_INT || t == t_FRAC); }
    1964             : INLINE int
    1965      522195 : is_real_t(long t) { return (t == t_INT || t == t_REAL || t == t_FRAC); }
    1966             : INLINE int
    1967  3142369574 : is_recursive_t(long t) { return lontyp[t]; }
    1968             : INLINE int
    1969   173427884 : is_scalar_t(long t) { return (t < t_POL); }
    1970             : INLINE int
    1971     1518895 : is_vec_t(long t) { return (t == t_VEC || t == t_COL); }
    1972             : 
    1973             : /*******************************************************************/
    1974             : /*                                                                 */
    1975             : /*                         TRANSCENDENTAL                          */
    1976             : /*                                                                 */
    1977             : /*******************************************************************/
    1978             : INLINE GEN
    1979    22907928 : sqrtr(GEN x) {
    1980    22907928 :   long s = signe(x);
    1981    22907928 :   if (s == 0) return real_0_bit(expo(x) >> 1);
    1982    22874253 :   if (s >= 0) return sqrtr_abs(x);
    1983       37408 :   retmkcomplex(gen_0, sqrtr_abs(x));
    1984             : }
    1985             : INLINE GEN
    1986           0 : cbrtr_abs(GEN x) { return sqrtnr_abs(x, 3); }
    1987             : INLINE GEN
    1988           0 : cbrtr(GEN x) {
    1989           0 :   long s = signe(x);
    1990             :   GEN r;
    1991           0 :   if (s == 0) return real_0_bit(expo(x) / 3);
    1992           0 :   r = cbrtr_abs(x);
    1993           0 :   if (s < 0) togglesign(r);
    1994           0 :   return r;
    1995             : }
    1996             : INLINE GEN
    1997      466159 : sqrtnr(GEN x, long n) {
    1998      466159 :   long s = signe(x);
    1999             :   GEN r;
    2000      466159 :   if (s == 0) return real_0_bit(expo(x) / n);
    2001      466159 :   r = sqrtnr_abs(x, n);
    2002      466159 :   if (s < 0) pari_err_IMPL("sqrtnr for x < 0");
    2003      466159 :   return r;
    2004             : }
    2005             : INLINE long
    2006      222824 : logint(GEN B, GEN y) { return logintall(B,y,NULL); }
    2007             : INLINE ulong
    2008     2002086 : ulogint(ulong B, ulong y)
    2009             : {
    2010             :   ulong r;
    2011             :   long e;
    2012     2002086 :   if (y == 2) return expu(B);
    2013     1983942 :   r = y;
    2014     6404018 :   for (e=1;; e++)
    2015             :   { /* here, r = y^e, r2 = y^(e-1) */
    2016    10824094 :     if (r >= B) return r == B? e: e-1;
    2017     4420070 :     r = umuluu_or_0(y, r);
    2018     4420076 :     if (!r) return e;
    2019             :   }
    2020             : }
    2021             : 
    2022             : /*******************************************************************/
    2023             : /*                                                                 */
    2024             : /*                         MISCELLANEOUS                           */
    2025             : /*                                                                 */
    2026             : /*******************************************************************/
    2027     1262881 : INLINE int ismpzero(GEN x) { return is_intreal_t(typ(x)) && !signe(x); }
    2028   738711489 : INLINE int isintzero(GEN x) { return typ(x) == t_INT && !signe(x); }
    2029     5748901 : INLINE int isint1(GEN x) { return typ(x)==t_INT && equali1(x); }
    2030        4704 : INLINE int isintm1(GEN x){ return typ(x)==t_INT && equalim1(x);}
    2031   702563895 : INLINE int equali1(GEN n)
    2032   702563895 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(1)) && n[2] == 1; }
    2033    61456169 : INLINE int equalim1(GEN n)
    2034    61456169 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(-1)) && n[2] == 1; }
    2035             : /* works only for POSITIVE integers */
    2036  1063663275 : INLINE int is_pm1(GEN n)
    2037  1063663275 : { return lgefint(n) == 3 && n[2] == 1; }
    2038   243774491 : INLINE int is_bigint(GEN n)
    2039   243774491 : { long l = lgefint(n); return l > 3 || (l == 3 && (n[2] & HIGHBIT)); }
    2040             : 
    2041  2071573280 : INLINE int odd(long x) { return x & 1; }
    2042    29071582 : INLINE int both_odd(long x, long y) { return x & y & 1; }
    2043             : 
    2044             : INLINE int
    2045  2851923241 : isonstack(GEN x)
    2046  2851923241 : { return ((pari_sp)x >= pari_mainstack->bot
    2047  2851923241 :        && (pari_sp)x <  pari_mainstack->top); }
    2048             : 
    2049             : /* assume x != 0 and x t_REAL, return an approximation to log2(|x|) */
    2050             : INLINE double
    2051    23887380 : dbllog2r(GEN x)
    2052    23887380 : { return log2((double)(ulong)x[2]) + (double)(expo(x) - (BITS_IN_LONG-1)); }
    2053             : 
    2054             : INLINE GEN
    2055      400994 : mul_content(GEN cx, GEN cy)
    2056             : {
    2057      400994 :   if (!cx) return cy;
    2058      146396 :   if (!cy) return cx;
    2059      102369 :   return gmul(cx,cy);
    2060             : }
    2061             : INLINE GEN
    2062       11719 : inv_content(GEN c) { return c? ginv(c): NULL; }
    2063             : INLINE GEN
    2064     1817125 : mul_denom(GEN dx, GEN dy)
    2065             : {
    2066     1817125 :   if (!dx) return dy;
    2067     1215361 :   if (!dy) return dx;
    2068      382282 :   return mulii(dx,dy);
    2069             : }
    2070             : 
    2071             : /* POLYNOMIALS */
    2072             : INLINE GEN
    2073    17949162 : constant_coeff(GEN x) { return signe(x)? gel(x,2): gen_0; }
    2074             : INLINE GEN
    2075    95504220 : leading_coeff(GEN x) { return lg(x) == 2? gen_0: gel(x,lg(x)-1); }
    2076             : INLINE ulong
    2077      480973 : Flx_lead(GEN x) { return lg(x) == 2? 0: x[lg(x)-1]; }
    2078             : INLINE ulong
    2079       12293 : Flx_constant(GEN x) { return lg(x) == 2? 0: x[2]; }
    2080             : INLINE long
    2081  2934638911 : degpol(GEN x) { return lg(x)-3; }
    2082             : INLINE long
    2083  1443053967 : lgpol(GEN x) { return lg(x)-2; }
    2084             : INLINE long
    2085   127404051 : lgcols(GEN x) { return lg(gel(x,1)); }
    2086             : INLINE long
    2087    36386868 : nbrows(GEN x) { return lg(gel(x,1))-1; }
    2088             : INLINE GEN
    2089           0 : truecoef(GEN x, long n) { return polcoef(x,n,-1); }
    2090             : 
    2091             : INLINE GEN
    2092      574081 : ZXQ_mul(GEN y, GEN x, GEN T) { return ZX_rem(ZX_mul(y, x), T); }
    2093             : INLINE GEN
    2094      286263 : ZXQ_sqr(GEN x, GEN T) { return ZX_rem(ZX_sqr(x), T); }
    2095             : 
    2096             : INLINE GEN
    2097    81548240 : RgX_copy(GEN x)
    2098             : {
    2099             :   long lx, i;
    2100    81548240 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
    2101    81548241 :   for (i = 2; i<lx; i++) gel(y,i) = gcopy(gel(x,i));
    2102    81548240 :   return y;
    2103             : }
    2104             : /* have to use ulong to avoid silly warnings from gcc "assuming signed
    2105             :  * overflow does not occur" */
    2106             : INLINE GEN
    2107     2991297 : RgX_coeff(GEN x, long n)
    2108             : {
    2109     2991297 :   ulong l = lg(x);
    2110     2991297 :   return (n < 0 || ((ulong)n+3) > l)? gen_0: gel(x,n+2);
    2111             : }
    2112             : INLINE GEN
    2113      368623 : RgX_renormalize(GEN x) { return RgX_renormalize_lg(x, lg(x)); }
    2114             : INLINE GEN
    2115     6808601 : RgX_div(GEN x, GEN y) { return RgX_divrem(x,y,NULL); }
    2116             : INLINE GEN
    2117        1792 : RgXQX_div(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,NULL); }
    2118             : INLINE GEN
    2119       69642 : RgXQX_rem(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,ONLY_REM); }
    2120             : INLINE GEN
    2121     1034188 : FpX_div(GEN x, GEN y, GEN p) { return FpX_divrem(x,y,p, NULL); }
    2122             : INLINE GEN
    2123     4930458 : Flx_div(GEN x, GEN y, ulong p) { return Flx_divrem(x,y,p, NULL); }
    2124             : INLINE GEN
    2125     2598874 : F2x_div(GEN x, GEN y) { return F2x_divrem(x,y, NULL); }
    2126             : INLINE GEN
    2127           0 : FpV_FpC_mul(GEN x, GEN y, GEN p) { return FpV_dotproduct(x,y,p); }
    2128             : INLINE GEN
    2129    56246462 : pol0_Flx(long sv) { return mkvecsmall(sv); }
    2130             : INLINE GEN
    2131    15559148 : pol1_Flx(long sv) { return mkvecsmall2(sv, 1); }
    2132             : INLINE GEN
    2133    18102898 : polx_Flx(long sv) { return mkvecsmall3(sv, 0, 1); }
    2134             : INLINE GEN
    2135           0 : zero_zx(long sv) { return zero_Flx(sv); }
    2136             : INLINE GEN
    2137           0 : polx_zx(long sv) { return polx_Flx(sv); }
    2138             : INLINE GEN
    2139           0 : zx_shift(GEN x, long n) { return Flx_shift(x,n); }
    2140             : INLINE GEN
    2141           0 : zx_renormalize(GEN x, long l) { return Flx_renormalize(x,l); }
    2142             : INLINE GEN
    2143        1341 : zero_F2x(long sv) { return zero_Flx(sv); }
    2144             : INLINE GEN
    2145    11198336 : pol0_F2x(long sv) { return pol0_Flx(sv); }
    2146             : INLINE GEN
    2147     2887368 : pol1_F2x(long sv) { return pol1_Flx(sv); }
    2148             : INLINE GEN
    2149      691492 : polx_F2x(long sv) { return mkvecsmall2(sv, 2); }
    2150             : INLINE int
    2151      844041 : F2x_equal1(GEN x) { return Flx_equal1(x); }
    2152             : INLINE int
    2153     3122990 : F2x_equal(GEN V, GEN W) { return Flx_equal(V,W); }
    2154             : INLINE GEN
    2155    59787784 : F2x_copy(GEN x) { return leafcopy(x); }
    2156             : INLINE GEN
    2157           0 : F2v_copy(GEN x) { return leafcopy(x); }
    2158             : INLINE GEN
    2159     2276320 : Flv_copy(GEN x) { return leafcopy(x); }
    2160             : INLINE GEN
    2161    87232475 : Flx_copy(GEN x) { return leafcopy(x); }
    2162             : INLINE GEN
    2163     1913431 : vecsmall_copy(GEN x) { return leafcopy(x); }
    2164             : INLINE int
    2165     4924050 : Flx_equal1(GEN x) { return degpol(x)==0 && x[2] == 1; }
    2166             : INLINE int
    2167       18261 : ZX_equal1(GEN x) { return degpol(x)==0 && equali1(gel(x,2)); }
    2168             : INLINE int
    2169     5544304 : ZX_is_monic(GEN x) { return equali1(leading_coeff(x)); }
    2170             : 
    2171             : INLINE GEN
    2172    52568902 : ZX_renormalize(GEN x, long lx)    { return ZXX_renormalize(x,lx); }
    2173             : INLINE GEN
    2174    73896854 : FpX_renormalize(GEN x, long lx)   { return ZXX_renormalize(x,lx); }
    2175             : INLINE GEN
    2176      772616 : FpXX_renormalize(GEN x, long lx)  { return ZXX_renormalize(x,lx); }
    2177             : INLINE GEN
    2178     1251699 : FpXQX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
    2179             : INLINE GEN
    2180   111980625 : F2x_renormalize(GEN x, long lx)   { return Flx_renormalize(x,lx); }
    2181             : INLINE GEN
    2182       32367 : F2v_to_F2x(GEN x, long sv) {
    2183       32367 :   GEN y = leafcopy(x);
    2184       32367 :   y[1] = sv; F2x_renormalize(y, lg(y)); return y;
    2185             : }
    2186             : 
    2187             : INLINE long
    2188           0 : sturm(GEN x) { return sturmpart(x, NULL, NULL); }
    2189             : 
    2190             : INLINE long
    2191        7168 : gval(GEN x, long v) {
    2192        7168 :   pari_sp av = avma;
    2193        7168 :   long n = gvaluation(x, pol_x(v));
    2194        7168 :   set_avma(av); return n;
    2195             : }
    2196             : 
    2197             : INLINE void
    2198      471230 : RgX_shift_inplace_init(long v)
    2199      471230 : { if (v) (void)cgetg(v, t_VECSMALL); }
    2200             : /* shift polynomial in place. assume v free cells have been left before x */
    2201             : INLINE GEN
    2202      471230 : RgX_shift_inplace(GEN x, long v)
    2203             : {
    2204             :   long i, lx;
    2205             :   GEN y, z;
    2206      471230 :   if (!v) return x;
    2207      253227 :   lx = lg(x);
    2208      253227 :   if (lx == 2) return x;
    2209      253227 :   y = x + v;
    2210      253227 :   z = x + lx;
    2211             :   /* stackdummy from normalizepol: move it up */
    2212      253227 :   if (lg(z) != v) x[lx + v] = z[0];
    2213      253227 :   for (i = lx-1; i >= 2; i--) gel(y,i) = gel(x,i);
    2214      253227 :   for (i = v+1;  i >= 2; i--) gel(x,i) = gen_0;
    2215             :   /* leave x[1] alone: it is correct */
    2216      253227 :   x[0] = evaltyp(t_POL) | evallg(lx+v); return x;
    2217             : }
    2218             : 
    2219             : 
    2220             : /* LINEAR ALGEBRA */
    2221             : INLINE GEN
    2222      132659 : zv_to_ZV(GEN x) { return vecsmall_to_vec(x); }
    2223             : INLINE GEN
    2224     5233615 : zc_to_ZC(GEN x) { return vecsmall_to_col(x); }
    2225             : INLINE GEN
    2226     3300645 : ZV_to_zv(GEN x) { return vec_to_vecsmall(x); }
    2227             : INLINE GEN
    2228           0 : zx_to_zv(GEN x, long N) { return Flx_to_Flv(x,N); }
    2229             : INLINE GEN
    2230           0 : zv_to_zx(GEN x, long sv) { return Flv_to_Flx(x,sv); }
    2231             : INLINE GEN
    2232           0 : zm_to_zxV(GEN x, long sv) { return Flm_to_FlxV(x,sv); }
    2233             : INLINE GEN
    2234           0 : zero_zm(long x, long y) { return zero_Flm(x,y); }
    2235             : INLINE GEN
    2236    17664745 : zero_zv(long x) { return zero_Flv(x); }
    2237             : INLINE GEN
    2238         238 : zm_transpose(GEN x) { return Flm_transpose(x); }
    2239             : INLINE GEN
    2240           0 : zm_copy(GEN x) { return Flm_copy(x); }
    2241             : INLINE GEN
    2242     1903493 : zv_copy(GEN x) { return Flv_copy(x); }
    2243             : INLINE GEN
    2244           0 : zm_row(GEN x, long i) { return Flm_row(x,i); }
    2245             : 
    2246             : INLINE GEN
    2247      948749 : ZC_hnfrem(GEN x, GEN y) { return ZC_hnfremdiv(x,y,NULL); }
    2248             : INLINE GEN
    2249       50392 : ZM_hnfrem(GEN x, GEN y) { return ZM_hnfdivrem(x,y,NULL); }
    2250             : INLINE GEN
    2251     2505665 : ZM_lll(GEN x, double D, long f) { return ZM_lll_norms(x,D,f,NULL); }
    2252             : INLINE void
    2253     5677201 : RgM_dimensions(GEN x, long *m, long *n) { *n = lg(x)-1; *m = *n? nbrows(x): 0; }
    2254             : INLINE GEN
    2255    10681313 : RgM_shallowcopy(GEN x)
    2256             : {
    2257             :   long l;
    2258    10681313 :   GEN y = cgetg_copy(x, &l);
    2259    10681304 :   while (--l > 0) gel(y,l) = leafcopy(gel(x,l));
    2260    10681321 :   return y;
    2261             : }
    2262             : INLINE GEN
    2263       18981 : F2m_copy(GEN x) { return RgM_shallowcopy(x); }
    2264             : 
    2265             : INLINE GEN
    2266     1492753 : Flm_copy(GEN x) { return RgM_shallowcopy(x); }
    2267             : 
    2268             : /* divisibility: return 1 if y[i] | x[i] for all i, 0 otherwise. Assume
    2269             :  * x,y are ZV of the same length */
    2270             : INLINE int
    2271       23198 : ZV_dvd(GEN x, GEN y)
    2272             : {
    2273       23198 :   long i, l = lg(x);
    2274       36652 :   for (i=1; i < l; i++)
    2275       29519 :     if ( ! dvdii( gel(x,i), gel(y,i) ) ) return 0;
    2276        7133 :   return 1;
    2277             : }
    2278             : 
    2279             : /* Fq */
    2280             : INLINE GEN
    2281     2503224 : Fq_red(GEN x, GEN T, GEN p)
    2282     2503224 : { return typ(x)==t_INT? Fp_red(x,p): FpXQ_red(x,T,p); }
    2283             : INLINE GEN
    2284       99427 : Fq_to_FpXQ(GEN x, GEN T, GEN p /*unused*/)
    2285             : {
    2286             :   (void) p;
    2287       99427 :   return typ(x)==t_INT ? scalarpol(x, get_FpX_var(T)): x;
    2288             : }
    2289             : INLINE GEN
    2290         756 : Rg_to_Fq(GEN x, GEN T, GEN p) { return T? Rg_to_FpXQ(x,T,p): Rg_to_Fp(x,p); }
    2291             : 
    2292             : INLINE GEN
    2293        2289 : gener_Fq_local(GEN T, GEN p, GEN L)
    2294             : { return T? gener_FpXQ_local(T,p, L)
    2295        2289 :           : pgener_Fp_local(p, L); }
    2296             : 
    2297             : /* FpXQX */
    2298             : INLINE GEN
    2299        4347 : FpXQX_div(GEN x, GEN y, GEN T, GEN p) { return FpXQX_divrem(x, y, T, p, NULL); }
    2300             : INLINE GEN
    2301       35097 : FlxqX_div(GEN x, GEN y, GEN T, ulong p) { return FlxqX_divrem(x, y, T, p, NULL); }
    2302             : INLINE GEN
    2303       33313 : F2xqX_div(GEN x, GEN y, GEN T) { return F2xqX_divrem(x, y, T, NULL); }
    2304             : 
    2305             : /* FqX */
    2306             : INLINE GEN
    2307       25438 : FqX_red(GEN z, GEN T, GEN p) { return T? FpXQX_red(z, T, p): FpX_red(z, p); }
    2308             : INLINE GEN
    2309      957187 : FqX_add(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2310             : INLINE GEN
    2311       17404 : FqX_neg(GEN x,GEN T,GEN p) { return T? FpXX_neg(x,p): FpX_neg(x,p); }
    2312             : INLINE GEN
    2313        3234 : FqX_sub(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2314             : INLINE GEN
    2315      661960 : FqX_Fp_mul(GEN P, GEN u, GEN T, GEN p)
    2316      661960 : { return T? FpXX_Fp_mul(P, u, p): FpX_Fp_mul(P, u, p); }
    2317             : INLINE GEN
    2318      588211 : FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p)
    2319      588211 : { return typ(U)==t_INT ? FqX_Fp_mul(P, U, T, p): FpXQX_FpXQ_mul(P, U, T, p); }
    2320             : INLINE GEN
    2321       98687 : FqX_mul(GEN x, GEN y, GEN T, GEN p)
    2322       98687 : { return T? FpXQX_mul(x, y, T, p): FpX_mul(x, y, p); }
    2323             : INLINE GEN
    2324      489744 : FqX_mulu(GEN x, ulong y, GEN T, GEN p)
    2325      489744 : { return T? FpXX_mulu(x, y, p): FpX_mulu(x, y, p); }
    2326             : INLINE GEN
    2327        6468 : FqX_sqr(GEN x, GEN T, GEN p)
    2328        6468 : { return T? FpXQX_sqr(x, T, p): FpX_sqr(x, p); }
    2329             : INLINE GEN
    2330        1288 : FqX_powu(GEN x, ulong n, GEN T, GEN p)
    2331        1288 : { return T? FpXQX_powu(x, n, T, p): FpX_powu(x, n, p); }
    2332             : INLINE GEN
    2333           0 : FqX_halve(GEN x, GEN T, GEN p)
    2334           0 : { return T? FpXX_halve(x, p): FpX_halve(x, p); }
    2335             : INLINE GEN
    2336        5964 : FqX_div(GEN x, GEN y, GEN T, GEN p)
    2337        5964 : { return T? FpXQX_divrem(x,y,T,p,NULL): FpX_divrem(x,y,p,NULL); }
    2338             : INLINE GEN
    2339        6095 : FqX_get_red(GEN S, GEN T, GEN p)
    2340        6095 : { return T? FpXQX_get_red(S,T,p): FpX_get_red(S,p); }
    2341             : INLINE GEN
    2342       53108 : FqX_rem(GEN x, GEN y, GEN T, GEN p)
    2343       53108 : { return T? FpXQX_rem(x,y,T,p): FpX_rem(x,y,p); }
    2344             : INLINE GEN
    2345           0 : FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2346           0 : { return T? FpXQX_divrem(x,y,T,p,z): FpX_divrem(x,y,p,z); }
    2347             : INLINE GEN
    2348        5936 : FqX_div_by_X_x(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2349        5936 : { return T? FpXQX_div_by_X_x(x,y,T,p,z): FpX_div_by_X_x(x,y,p,z); }
    2350             : INLINE GEN
    2351           0 : FqX_halfgcd(GEN P,GEN Q,GEN T,GEN p)
    2352           0 : {return T? FpXQX_halfgcd(P,Q,T,p): FpX_halfgcd(P,Q,p);}
    2353             : INLINE GEN
    2354      259833 : FqX_gcd(GEN P,GEN Q,GEN T,GEN p)
    2355      259833 : {return T? FpXQX_gcd(P,Q,T,p): FpX_gcd(P,Q,p);}
    2356             : INLINE GEN
    2357       90746 : FqX_extgcd(GEN P,GEN Q,GEN T,GEN p, GEN *U, GEN *V)
    2358       90746 : { return T? FpXQX_extgcd(P,Q,T,p,U,V): FpX_extgcd(P,Q,p,U,V); }
    2359             : INLINE GEN
    2360        3437 : FqX_normalize(GEN z, GEN T, GEN p)
    2361        3437 : { return T? FpXQX_normalize(z, T, p): FpX_normalize(z, p); }
    2362             : INLINE GEN
    2363      273119 : FqX_deriv(GEN f, GEN T, GEN p) { return T? FpXX_deriv(f, p): FpX_deriv(f, p); }
    2364             : INLINE GEN
    2365           0 : FqX_integ(GEN f, GEN T, GEN p) { return T? FpXX_integ(f, p): FpX_integ(f, p); }
    2366             : INLINE GEN
    2367       74837 : FqX_factor(GEN f, GEN T, GEN p)
    2368       74837 : { return T?FpXQX_factor(f, T, p): FpX_factor(f, p); }
    2369             : INLINE GEN
    2370           7 : FqX_factor_squarefree(GEN f, GEN T, GEN p)
    2371           7 : { return T ? FpXQX_factor_squarefree(f, T, p): FpX_factor_squarefree(f, p); }
    2372             : INLINE GEN
    2373           7 : FqX_ddf(GEN f, GEN T, GEN p)
    2374           7 : { return T ? FpXQX_ddf(f, T, p): FpX_ddf(f, p); }
    2375             : INLINE GEN
    2376          42 : FqX_degfact(GEN f, GEN T, GEN p)
    2377          42 : { return T?FpXQX_degfact(f, T, p): FpX_degfact(f, p); }
    2378             : INLINE GEN
    2379        7126 : FqX_roots(GEN f, GEN T, GEN p)
    2380        7126 : { return T?FpXQX_roots(f, T, p): FpX_roots(f, p); }
    2381             : INLINE GEN
    2382         203 : FqX_to_mod(GEN f, GEN T, GEN p)
    2383         203 : { return T?FpXQX_to_mod(f, T, p): FpX_to_mod(f, p); }
    2384             : 
    2385             : /*FqXQ*/
    2386             : INLINE GEN
    2387           0 : FqXQ_add(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2388           0 : { (void)S; return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2389             : INLINE GEN
    2390           0 : FqXQ_sub(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2391           0 : { (void)S; return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2392             : INLINE GEN
    2393           0 : FqXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p)
    2394           0 : { return T? FpXQXQ_div(x,y,S,T,p): FpXQ_div(x,y,S,p); }
    2395             : INLINE GEN
    2396           0 : FqXQ_inv(GEN x, GEN S, GEN T, GEN p)
    2397           0 : { return T? FpXQXQ_inv(x,S,T,p): FpXQ_inv(x,S,p); }
    2398             : INLINE GEN
    2399           0 : FqXQ_invsafe(GEN x, GEN S, GEN T, GEN p)
    2400           0 : { return T? FpXQXQ_invsafe(x,S,T,p): FpXQ_inv(x,S,p); }
    2401             : INLINE GEN
    2402       22348 : FqXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p)
    2403       22348 : { return T? FpXQXQ_mul(x,y,S,T,p): FpXQ_mul(x,y,S,p); }
    2404             : INLINE GEN
    2405           0 : FqXQ_sqr(GEN x, GEN S, GEN T, GEN p)
    2406           0 : { return T? FpXQXQ_sqr(x,S,T,p): FpXQ_sqr(x,S,p); }
    2407             : INLINE GEN
    2408           0 : FqXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p)
    2409           0 : { return T? FpXQXQ_pow(x,n,S,T,p): FpXQ_pow(x,n,S,p); }
    2410             : 
    2411             : /*FqXn*/
    2412             : INLINE GEN
    2413           0 : FqXn_exp(GEN x, long n, GEN T, GEN p)
    2414           0 : { return T? FpXQXn_exp(x,n,T,p): FpXn_exp(x,n,p); }
    2415             : INLINE GEN
    2416           0 : FqXn_inv(GEN x, long n, GEN T, GEN p)
    2417           0 : { return T? FpXQXn_inv(x,n,T,p): FpXn_inv(x,n,p); }
    2418             : INLINE GEN
    2419           0 : FqXn_mul(GEN x, GEN y, long n, GEN T, GEN p)
    2420           0 : { return T? FpXQXn_mul(x, y, n, T, p): FpXn_mul(x, y, n, p); }
    2421             : INLINE GEN
    2422           0 : FqXn_sqr(GEN x, long n, GEN T, GEN p)
    2423           0 : { return T? FpXQXn_sqr(x,n,T,p): FpXn_sqr(x,n,p); }
    2424             : 
    2425             : /*FpXQ*/
    2426             : INLINE GEN
    2427           0 : FpXQ_add(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2428           0 : { (void)T; return FpX_add(x,y,p); }
    2429             : INLINE GEN
    2430           0 : FpXQ_sub(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2431           0 : { (void)T; return FpX_sub(x,y,p); }
    2432             : 
    2433             : /*Flxq*/
    2434             : INLINE GEN
    2435           0 : Flxq_add(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2436           0 : { (void)T; return Flx_add(x,y,p); }
    2437             : INLINE GEN
    2438           0 : Flxq_sub(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2439           0 : { (void)T; return Flx_sub(x,y,p); }
    2440             : 
    2441             : /* F2x */
    2442             : 
    2443             : INLINE ulong
    2444   102640661 : F2x_coeff(GEN x,long v)
    2445             : {
    2446   102640661 :    ulong u=(ulong)x[2+divsBIL(v)];
    2447   102640923 :    return (u>>remsBIL(v))&1UL;
    2448             : }
    2449             : 
    2450             : INLINE void
    2451     5067781 : F2x_clear(GEN x,long v)
    2452             : {
    2453     5067781 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2454     5067781 :    *u&=~(1UL<<remsBIL(v));
    2455     5067781 : }
    2456             : 
    2457             : INLINE void
    2458    32849231 : F2x_set(GEN x,long v)
    2459             : {
    2460    32849231 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2461    32833951 :    *u|=1UL<<remsBIL(v);
    2462    32832719 : }
    2463             : 
    2464             : INLINE void
    2465     1502090 : F2x_flip(GEN x,long v)
    2466             : {
    2467     1502090 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2468     1502090 :    *u^=1UL<<remsBIL(v);
    2469     1502090 : }
    2470             : 
    2471             : /* F2v */
    2472             : 
    2473             : INLINE ulong
    2474    98036974 : F2v_coeff(GEN x,long v) { return F2x_coeff(x,v-1); }
    2475             : 
    2476             : INLINE void
    2477     5067781 : F2v_clear(GEN x,long v) { F2x_clear(x,v-1); }
    2478             : 
    2479             : INLINE void
    2480     9029057 : F2v_set(GEN x,long v)   { F2x_set(x,v-1); }
    2481             : 
    2482             : INLINE void
    2483     1502090 : F2v_flip(GEN x,long v) { F2x_flip(x,v-1); }
    2484             : 
    2485             : /* F2m */
    2486             : 
    2487             : INLINE ulong
    2488    12396810 : F2m_coeff(GEN x, long a, long b) { return F2v_coeff(gel(x,b), a); }
    2489             : 
    2490             : INLINE void
    2491           0 : F2m_clear(GEN x, long a, long b) { F2v_clear(gel(x,b), a); }
    2492             : 
    2493             : INLINE void
    2494     1358597 : F2m_set(GEN x, long a, long b) { F2v_set(gel(x,b), a); }
    2495             : 
    2496             : INLINE void
    2497     1502090 : F2m_flip(GEN x, long a, long b) { F2v_flip(gel(x,b), a); }
    2498             : 
    2499             : /* ARITHMETIC */
    2500             : INLINE GEN
    2501        1071 : matpascal(long n) { return matqpascal(n, NULL); }
    2502             : INLINE long
    2503     2334707 : Z_issquare(GEN x) { return Z_issquareall(x, NULL); }
    2504             : INLINE long
    2505          14 : Z_ispower(GEN x, ulong k) { return Z_ispowerall(x, k, NULL); }
    2506             : INLINE GEN
    2507     5928634 : sqrti(GEN x) { return sqrtremi(x,NULL); }
    2508             : INLINE GEN
    2509     5674679 : gaddgs(GEN y, long s) { return gaddsg(s,y); }
    2510             : INLINE int
    2511       72148 : gcmpgs(GEN y, long s) { return -gcmpsg(s,y); }
    2512             : INLINE int
    2513       24514 : gequalgs(GEN y, long s) { return gequalsg(s,y); }
    2514             : INLINE GEN
    2515           0 : gmaxsg(long s, GEN y) { return gmaxgs(y,s); }
    2516             : INLINE GEN
    2517           0 : gminsg(long s, GEN y) { return gmings(y,s); }
    2518             : INLINE GEN
    2519    15118013 : gmulgs(GEN y, long s) { return gmulsg(s,y); }
    2520             : INLINE GEN
    2521      932753 : gsubgs(GEN y, long s) { return gaddgs(y, -s); }
    2522             : INLINE GEN
    2523      692104 : gdivsg(long s, GEN y) { return gdiv(stoi(s), y); }
    2524             : 
    2525             : /* x t_COMPLEX */
    2526             : INLINE GEN
    2527    14105447 : cxnorm(GEN x) { return gadd(gsqr(gel(x,1)), gsqr(gel(x,2))); }
    2528             : /* q t_QUAD */
    2529             : INLINE GEN
    2530         623 : quadnorm(GEN q)
    2531             : {
    2532         623 :   GEN X = gel(q,1), b = gel(X,3), c = gel(X,2);
    2533         623 :   GEN z, u = gel(q,3), v = gel(q,2);
    2534         623 :   if (typ(u) == t_INT && typ(v) == t_INT) /* generic case */
    2535             :   {
    2536         308 :     z = signe(b)? mulii(v, addii(u,v)): sqri(v);
    2537         308 :     return addii(z, mulii(c, sqri(u)));
    2538             :   }
    2539             :   else
    2540             :   {
    2541         315 :     z = signe(b)? gmul(v, gadd(u,v)): gsqr(v);
    2542         315 :     return gadd(z, gmul(c, gsqr(u)));
    2543             :   }
    2544             : }
    2545             : /* x a t_QUAD, return the attached discriminant */
    2546             : INLINE GEN
    2547         280 : quad_disc(GEN x)
    2548             : {
    2549         280 :   GEN Q = gel(x,1), b = gel(Q,3), c = gel(Q,2), c4 = shifti(c,2);
    2550         280 :   if (is_pm1(b)) return subsi(1, c4);
    2551          56 :   togglesign_safe(&c4); return c4;
    2552             : }
    2553             : INLINE GEN
    2554     6386709 : qfb_disc3(GEN x, GEN y, GEN z) { return subii(sqri(y), shifti(mulii(x,z),2)); }
    2555             : INLINE GEN
    2556     6305775 : qfb_disc(GEN x) { return qfb_disc3(gel(x,1), gel(x,2), gel(x,3)); }
    2557             : 
    2558             : INLINE GEN
    2559     1267459 : sqrfrac(GEN x)
    2560             : {
    2561     1267459 :   GEN z = cgetg(3,t_FRAC);
    2562     1267459 :   gel(z,1) = sqri(gel(x,1));
    2563     1267459 :   gel(z,2) = sqri(gel(x,2)); return z;
    2564             : }
    2565             : 
    2566             : INLINE void
    2567    34440906 : normalize_frac(GEN z) {
    2568    34440906 :   if (signe(gel(z,2)) < 0) { togglesign(gel(z,1)); setabssign(gel(z,2)); }
    2569    34440906 : }
    2570             : 
    2571             : INLINE GEN
    2572      270642 : powii(GEN x, GEN n)
    2573             : {
    2574      270642 :   long ln = lgefint(n);
    2575      270642 :   if (ln == 3) {
    2576             :     GEN z;
    2577      266204 :     if (signe(n) > 0) return powiu(x, n[2]);
    2578        8344 :     z = cgetg(3, t_FRAC);
    2579        8344 :     gel(z,1) = gen_1;
    2580        8344 :     gel(z,2) = powiu(x, n[2]);
    2581        8344 :     return z;
    2582             :   }
    2583        4438 :   if (ln == 2) return gen_1; /* rare */
    2584             :   /* should never happen */
    2585           0 :   return powgi(x, n); /* overflow unless x = 0, 1, -1 */
    2586             : }
    2587             : INLINE GEN
    2588        1267 : powIs(long n) {
    2589        1267 :   switch(n & 3)
    2590             :   {
    2591          49 :     case 1: return mkcomplex(gen_0,gen_1);
    2592         378 :     case 2: return gen_m1;
    2593         518 :     case 3: return mkcomplex(gen_0,gen_m1);
    2594             :   }
    2595         322 :   return gen_1;
    2596             : }
    2597             : 
    2598             : /*******************************************************************/
    2599             : /*                                                                 */
    2600             : /*                             ASSIGNMENTS                         */
    2601             : /*                                                                 */
    2602             : /*******************************************************************/
    2603           0 : INLINE void mpexpz(GEN x, GEN z)
    2604           0 : { pari_sp av = avma; gaffect(mpexp(x), z); set_avma(av); }
    2605           0 : INLINE void mplogz(GEN x, GEN z)
    2606           0 : { pari_sp av = avma; gaffect(mplog(x), z); set_avma(av); }
    2607           0 : INLINE void mpcosz(GEN x, GEN z)
    2608           0 : { pari_sp av = avma; gaffect(mpcos(x), z); set_avma(av); }
    2609           0 : INLINE void mpsinz(GEN x, GEN z)
    2610           0 : { pari_sp av = avma; gaffect(mpsin(x), z); set_avma(av); }
    2611           0 : INLINE void gnegz(GEN x, GEN z)
    2612           0 : { pari_sp av = avma; gaffect(gneg(x), z); set_avma(av); }
    2613           0 : INLINE void gabsz(GEN x, long prec, GEN z)
    2614           0 : { pari_sp av = avma; gaffect(gabs(x,prec), z); set_avma(av); }
    2615           0 : INLINE void gaddz(GEN x, GEN y, GEN z)
    2616           0 : { pari_sp av = avma; gaffect(gadd(x,y), z); set_avma(av); }
    2617           0 : INLINE void gsubz(GEN x, GEN y, GEN z)
    2618           0 : { pari_sp av = avma; gaffect(gsub(x,y), z); set_avma(av); }
    2619           0 : INLINE void gmulz(GEN x, GEN y, GEN z)
    2620           0 : { pari_sp av = avma; gaffect(gmul(x,y), z); set_avma(av); }
    2621           0 : INLINE void gdivz(GEN x, GEN y, GEN z)
    2622           0 : { pari_sp av = avma; gaffect(gdiv(x,y), z); set_avma(av); }
    2623           0 : INLINE void gdiventz(GEN x, GEN y, GEN z)
    2624           0 : { pari_sp av = avma; gaffect(gdivent(x,y), z); set_avma(av); }
    2625           0 : INLINE void gmodz(GEN x, GEN y, GEN z)
    2626           0 : { pari_sp av = avma; gaffect(gmod(x,y), z); set_avma(av); }
    2627           0 : INLINE void gmul2nz(GEN x, long s, GEN z)
    2628           0 : { pari_sp av = avma; gaffect(gmul2n(x,s), z); set_avma(av); }
    2629           0 : INLINE void gshiftz(GEN x, long s, GEN z)
    2630           0 : { pari_sp av = avma; gaffect(gshift(x,s), z); set_avma(av); }
    2631             : 
    2632             : /*******************************************************************/
    2633             : /*                                                                 */
    2634             : /*                       ELLIPTIC CURVES                           */
    2635             : /*                                                                 */
    2636             : /*******************************************************************/
    2637     3982406 : INLINE GEN ell_get_a1(GEN e) { return gel(e,1); }
    2638     3097459 : INLINE GEN ell_get_a2(GEN e) { return gel(e,2); }
    2639     3864325 : INLINE GEN ell_get_a3(GEN e) { return gel(e,3); }
    2640     3890398 : INLINE GEN ell_get_a4(GEN e) { return gel(e,4); }
    2641     4707130 : INLINE GEN ell_get_a6(GEN e) { return gel(e,5); }
    2642     3320181 : INLINE GEN ell_get_b2(GEN e) { return gel(e,6); }
    2643     1025539 : INLINE GEN ell_get_b4(GEN e) { return gel(e,7); }
    2644     1631480 : INLINE GEN ell_get_b6(GEN e) { return gel(e,8); }
    2645     1464498 : INLINE GEN ell_get_b8(GEN e) { return gel(e,9); }
    2646     6172492 : INLINE GEN ell_get_c4(GEN e) { return gel(e,10); }
    2647     7408187 : INLINE GEN ell_get_c6(GEN e) { return gel(e,11); }
    2648     9659110 : INLINE GEN ell_get_disc(GEN e) { return gel(e,12); }
    2649     1029217 : INLINE GEN ell_get_j(GEN e) { return gel(e,13); }
    2650    11461333 : INLINE long ell_get_type(GEN e) { return mael(e,14,1); }
    2651     1571730 : INLINE GEN ellff_get_field(GEN x) { return gmael(x, 15, 1); }
    2652      683464 : INLINE GEN ellff_get_a4a6(GEN x)  { return gmael(x, 15, 2); }
    2653        1407 : INLINE GEN ellQp_get_zero(GEN x) { return gmael(x, 15, 1); }
    2654         287 : INLINE long ellQp_get_prec(GEN E) { GEN z = ellQp_get_zero(E); return valp(z); }
    2655        1085 : INLINE GEN ellQp_get_p(GEN E) { GEN z = ellQp_get_zero(E); return gel(z,2); }
    2656       37163 : INLINE long ellR_get_prec(GEN x) { return nbits2prec(mael3(x, 15, 1, 1)); }
    2657       12390 : INLINE long ellR_get_sign(GEN x) { return mael3(x, 15, 1, 2); }
    2658      701046 : INLINE GEN ellnf_get_nf(GEN x) { return checknf_i(gmael(x,15,1)); }
    2659          56 : INLINE GEN ellnf_get_bnf(GEN x) { return checkbnf_i(gmael(x,15,1)); }
    2660             : 
    2661     4628159 : INLINE int checkell_i(GEN e) { return typ(e) == t_VEC && lg(e) == 17; }
    2662    33989510 : INLINE int ell_is_inf(GEN z) { return lg(z) == 2; }
    2663      810475 : INLINE GEN ellinf(void) { return mkvec(gen_0); }
    2664             : 
    2665             : /*******************************************************************/
    2666             : /*                                                                 */
    2667             : /*                    ALGEBRAIC NUMBER THEORY                      */
    2668             : /*                                                                 */
    2669             : /*******************************************************************/
    2670     8610557 : INLINE GEN modpr_get_pr(GEN x)  { return gel(x,3); }
    2671      610424 : INLINE GEN modpr_get_p(GEN x)  { return pr_get_p(modpr_get_pr(x)); }
    2672     2753726 : INLINE GEN modpr_get_T(GEN x)  { return lg(x) == 4? NULL: gel(x,4); }
    2673             : 
    2674    20700479 : INLINE GEN pr_get_p(GEN pr)  { return gel(pr,1); }
    2675     7040215 : INLINE GEN pr_get_gen(GEN pr){ return gel(pr,2); }
    2676             : /* .[2] instead of itos works: e and f are small positive integers */
    2677     2417826 : INLINE long pr_get_e(GEN pr) { return gel(pr,3)[2]; }
    2678     9671100 : INLINE long pr_get_f(GEN pr) { return gel(pr,4)[2]; }
    2679     6568407 : INLINE GEN pr_get_tau(GEN pr){ return gel(pr,5); }
    2680             : INLINE int
    2681     3329651 : pr_is_inert(GEN P) { return pr_get_f(P) == lg(pr_get_gen(P))-1; }
    2682             : INLINE GEN
    2683      242800 : pr_norm(GEN pr) { return powiu(pr_get_p(pr), pr_get_f(pr)); }
    2684             : INLINE ulong
    2685       48083 : upr_norm(GEN pr) { return upowuu(pr_get_p(pr)[2], pr_get_f(pr)); }
    2686             : 
    2687             : /* assume nf a genuine nf */
    2688             : INLINE long
    2689      394990 : nf_get_varn(GEN nf) { return varn(gel(nf,1)); }
    2690             : INLINE GEN
    2691    34458510 : nf_get_pol(GEN nf) { return gel(nf,1); }
    2692             : INLINE long
    2693    27449200 : nf_get_degree(GEN nf) { return degpol( nf_get_pol(nf) ); }
    2694             : INLINE long
    2695     4212068 : nf_get_r1(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,1)); }
    2696             : INLINE long
    2697        1680 : nf_get_r2(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,2)); }
    2698             : INLINE GEN
    2699       58926 : nf_get_disc(GEN nf) { return gel(nf,3); }
    2700             : INLINE GEN
    2701      879448 : nf_get_index(GEN nf) { return gel(nf,4); }
    2702             : INLINE GEN
    2703     2899506 : nf_get_M(GEN nf) { return gmael(nf,5,1); }
    2704             : INLINE GEN
    2705       86312 : nf_get_G(GEN nf) { return gmael(nf,5,2); }
    2706             : INLINE GEN
    2707      426793 : nf_get_roundG(GEN nf) { return gmael(nf,5,3); }
    2708             : INLINE GEN
    2709       24367 : nf_get_Tr(GEN nf) { return gmael(nf,5,4); }
    2710             : INLINE GEN
    2711        2331 : nf_get_diff(GEN nf) { return gmael(nf,5,5); }
    2712             : INLINE GEN
    2713         210 : nf_get_ramified_primes(GEN nf) { return gmael(nf,5,8); }
    2714             : INLINE GEN
    2715      384038 : nf_get_roots(GEN nf) { return gel(nf,6); }
    2716             : INLINE GEN
    2717         112 : nf_get_zk(GEN nf)
    2718             : {
    2719         112 :   GEN y = gel(nf,7), D = gel(y, 1);
    2720         112 :   if (typ(D) == t_POL) D = gel(D, 2);
    2721         112 :   if (!equali1(D)) y = gdiv(y, D);
    2722         112 :   return y;
    2723             : }
    2724             : INLINE GEN
    2725      281905 : nf_get_zkprimpart(GEN nf)
    2726             : {
    2727      281905 :   GEN y = gel(nf,7);
    2728             :   /* test for old format of nf.zk: non normalized */
    2729      281905 :   if (!equali1(gel(nf,4)) && gequal1(gel(y,1))) y = Q_remove_denom(y,NULL);
    2730      281903 :   return y;
    2731             : }
    2732             : INLINE GEN
    2733      283220 : nf_get_zkden(GEN nf)
    2734             : {
    2735      283220 :   GEN y = gel(nf,7), D = gel(y,1);
    2736      283220 :   if (typ(D) == t_POL) D = gel(D,2);
    2737             :   /* test for old format of nf.zk: non normalized */
    2738      283220 :   if (!equali1(gel(nf,4)) && equali1(D)) D = Q_denom(y);
    2739      283217 :   return D;
    2740             : }
    2741             : INLINE GEN
    2742     2703559 : nf_get_invzk(GEN nf) { return gel(nf,8); }
    2743             : INLINE void
    2744       23830 : nf_get_sign(GEN nf, long *r1, long *r2)
    2745             : {
    2746       23830 :   GEN x = gel(nf,2);
    2747       23830 :   *r1 = itou(gel(x,1));
    2748       23830 :   *r2 = itou(gel(x,2));
    2749       23830 : }
    2750             : 
    2751             : INLINE GEN
    2752       94928 : abgrp_get_no(GEN x) { return gel(x,1); }
    2753             : INLINE GEN
    2754     2514113 : abgrp_get_cyc(GEN x) { return gel(x,2); }
    2755             : INLINE GEN
    2756      458868 : abgrp_get_gen(GEN x) { return gel(x,3); }
    2757             : INLINE GEN
    2758     2310175 : bnf_get_nf(GEN bnf) { return gel(bnf,7); }
    2759             : INLINE GEN
    2760      907026 : bnf_get_clgp(GEN bnf) { return gmael(bnf,8,1); }
    2761             : INLINE GEN
    2762        7098 : bnf_get_no(GEN bnf) { return abgrp_get_no(bnf_get_clgp(bnf)); }
    2763             : INLINE GEN
    2764      488723 : bnf_get_cyc(GEN bnf) { return abgrp_get_cyc(bnf_get_clgp(bnf)); }
    2765             : INLINE GEN
    2766      410876 : bnf_get_gen(GEN bnf)  { return abgrp_get_gen(bnf_get_clgp(bnf)); }
    2767             : INLINE GEN
    2768         846 : bnf_get_reg(GEN bnf) { return gmael(bnf,8,2); }
    2769             : INLINE GEN
    2770      510247 : bnf_get_logfu(GEN bnf) { return gel(bnf,3); }
    2771             : INLINE GEN
    2772        8738 : bnf_get_tuU(GEN bnf) { return gmael3(bnf,8,4,2); }
    2773             : INLINE long
    2774       41853 : bnf_get_tuN(GEN bnf) { return gmael3(bnf,8,4,1)[2]; }
    2775             : INLINE GEN
    2776        1778 : bnf_get_fu(GEN bnf) {
    2777        1778 :   GEN fu = bnf_get_fu_nocheck(bnf);
    2778        1778 :   if (typ(fu) == t_MAT) pari_err(e_MISC,"missing units in bnf");
    2779        1778 :   return fu;
    2780             : }
    2781             : INLINE GEN
    2782       10103 : bnf_get_fu_nocheck(GEN bnf) { return gmael(bnf,8,5); }
    2783             : 
    2784             : INLINE GEN
    2785      907086 : bnr_get_bnf(GEN bnr) { return gel(bnr,1); }
    2786             : INLINE GEN
    2787      464652 : bnr_get_bid(GEN bnr) { return gel(bnr,2); }
    2788             : INLINE GEN
    2789       20125 : bnr_get_mod(GEN bnr) { return gmael(bnr,2,1); }
    2790             : INLINE GEN
    2791       34958 : bnr_get_nf(GEN bnr) { return gmael(bnr,1,7); }
    2792             : INLINE GEN
    2793      710485 : bnr_get_clgp(GEN bnr) { return gel(bnr,5); }
    2794             : INLINE GEN
    2795       84063 : bnr_get_no(GEN bnr) { return abgrp_get_no(bnr_get_clgp(bnr)); }
    2796             : INLINE GEN
    2797      610126 : bnr_get_cyc(GEN bnr) { return abgrp_get_cyc(bnr_get_clgp(bnr)); }
    2798             : INLINE GEN
    2799          70 : bnr_get_gen_nocheck(GEN bnr) { return abgrp_get_gen(bnr_get_clgp(bnr)); }
    2800             : INLINE GEN
    2801       14931 : bnr_get_gen(GEN bnr) {
    2802       14931 :   GEN G = bnr_get_clgp(bnr);
    2803       14931 :   if (lg(G) !=  4)
    2804           0 :     pari_err(e_MISC,"missing bnr generators: please use bnrinit(,,1)");
    2805       14931 :   return gel(G,3);
    2806             : }
    2807             : 
    2808             : INLINE GEN
    2809      337266 : bid_get_mod(GEN bid) { return gel(bid,1); }
    2810             : INLINE GEN
    2811       68089 : bid_get_ideal(GEN bid) { return gmael(bid,1,1); }
    2812             : INLINE GEN
    2813        1246 : bid_get_arch(GEN bid) { return gmael(bid,1,2); }
    2814             : INLINE GEN
    2815     1272996 : bid_get_grp(GEN bid) { return gel(bid,2); }
    2816             : INLINE GEN
    2817      506435 : bid_get_fact(GEN bid) { return gmael(bid,3,1); }
    2818             : INLINE GEN
    2819      436183 : bid_get_fact2(GEN bid) { return gmael(bid,3,2); }
    2820             : INLINE GEN
    2821      435252 : bid_get_sprk(GEN bid) { return gmael(bid,4,1); }
    2822             : INLINE GEN
    2823       49322 : bid_get_sarch(GEN bid) { return gmael(bid,4,2); }
    2824             : INLINE GEN
    2825      471442 : bid_get_archp(GEN bid) { return gmael3(bid,4,2,2); }
    2826             : INLINE GEN
    2827      772749 : bid_get_U(GEN bid) { return gel(bid,5); }
    2828             : INLINE GEN
    2829           0 : bid_get_no(GEN bid) { return abgrp_get_no(bid_get_grp(bid)); }
    2830             : INLINE GEN
    2831     1225998 : bid_get_cyc(GEN bid) { return abgrp_get_cyc(bid_get_grp(bid)); }
    2832             : INLINE GEN
    2833           0 : bid_get_gen_nocheck(GEN bid)  { return abgrp_get_gen(bid_get_grp(bid)); }
    2834             : INLINE GEN
    2835       46403 : bid_get_gen(GEN bid) {
    2836       46403 :   GEN G = bid_get_grp(bid);
    2837       46403 :   if (lg(G) != 4) pari_err(e_MISC,"missing bid generators. Use idealstar(,,2)");
    2838       46403 :   return abgrp_get_gen(G);
    2839             : }
    2840             : 
    2841             : INLINE GEN
    2842    25919068 : znstar_get_N(GEN G) { return gmael(G,1,1); }
    2843             : INLINE GEN
    2844     2872555 : znstar_get_faN(GEN G) { return gel(G,3); }
    2845             : INLINE GEN
    2846           7 : znstar_get_no(GEN G) { return abgrp_get_no(gel(G,2)); }
    2847             : INLINE GEN
    2848      187845 : znstar_get_cyc(GEN G) { return abgrp_get_cyc(gel(G,2)); }
    2849             : INLINE GEN
    2850           7 : znstar_get_gen(GEN G) { return abgrp_get_gen(gel(G,2)); }
    2851             : INLINE GEN
    2852     3548293 : znstar_get_conreycyc(GEN G) { return gmael(G,4,5); }
    2853             : INLINE GEN
    2854     1219295 : znstar_get_conreygen(GEN G) { return gmael(G,4,4); }
    2855             : INLINE GEN
    2856       45927 : znstar_get_Ui(GEN G) { return gmael(G,4,3); }
    2857             : INLINE GEN
    2858      118237 : znstar_get_U(GEN G) { return gel(G,5); }
    2859             : INLINE GEN
    2860      825699 : znstar_get_pe(GEN G) { return gmael(G,4,1); }
    2861             : INLINE GEN
    2862       19922 : gal_get_pol(GEN gal) { return gel(gal,1); }
    2863             : INLINE GEN
    2864        1330 : gal_get_p(GEN gal) { return gmael(gal,2,1); }
    2865             : INLINE GEN
    2866          84 : gal_get_e(GEN gal) { return gmael(gal,2,2); }
    2867             : INLINE GEN
    2868       15981 : gal_get_mod(GEN gal) { return gmael(gal,2,3); }
    2869             : INLINE GEN
    2870       16359 : gal_get_roots(GEN gal) { return gel(gal,3); }
    2871             : INLINE GEN
    2872       15932 : gal_get_invvdm(GEN gal) { return gel(gal,4); }
    2873             : INLINE GEN
    2874       15932 : gal_get_den(GEN gal) { return gel(gal,5); }
    2875             : INLINE GEN
    2876       67162 : gal_get_group(GEN gal) { return gel(gal,6); }
    2877             : INLINE GEN
    2878        1750 : gal_get_gen(GEN gal) { return gel(gal,7); }
    2879             : INLINE GEN
    2880        1386 : gal_get_orders(GEN gal) { return gel(gal,8); }
    2881             : 
    2882             : /* assume rnf a genuine rnf */
    2883             : INLINE long
    2884     1233841 : rnf_get_degree(GEN rnf) { return degpol(rnf_get_pol(rnf)); }
    2885             : INLINE long
    2886       16674 : rnf_get_nfdegree(GEN rnf) { return degpol(nf_get_pol(rnf_get_nf(rnf))); }
    2887             : INLINE long
    2888      775698 : rnf_get_absdegree(GEN rnf) { return degpol(gmael(rnf,11,1)); }
    2889             : INLINE GEN
    2890         700 : rnf_get_idealdisc(GEN rnf) { return gmael(rnf,3,1); }
    2891             : INLINE GEN
    2892         742 : rnf_get_k(GEN rnf) { return gmael(rnf,11,3); }
    2893             : INLINE GEN
    2894         791 : rnf_get_alpha(GEN rnf) { return gmael(rnf, 11, 2); }
    2895             : INLINE GEN
    2896      427735 : rnf_get_nf(GEN rnf) { return gel(rnf,10); }
    2897             : INLINE GEN
    2898        3787 : rnf_get_nfzk(GEN rnf) { return gel(rnf,2); }
    2899             : INLINE GEN
    2900      214886 : rnf_get_polabs(GEN rnf) { return gmael(rnf,11,1); }
    2901             : INLINE GEN
    2902     1480052 : rnf_get_pol(GEN rnf) { return gel(rnf,1); }
    2903             : INLINE GEN
    2904          63 : rnf_get_disc(GEN rnf) { return gel(rnf,3); }
    2905             : INLINE GEN
    2906         105 : rnf_get_index(GEN rnf) { return gel(rnf,4); }
    2907             : INLINE long
    2908           0 : rnf_get_varn(GEN rnf) { return varn(gel(rnf,1)); }
    2909             : INLINE GEN
    2910      188580 : rnf_get_nfpol(GEN rnf) { return gmael(rnf,10,1); }
    2911             : INLINE long
    2912        3325 : rnf_get_nfvarn(GEN rnf) { return varn(gmael(rnf,10,1)); }
    2913             : INLINE GEN
    2914        3493 : rnf_get_zk(GEN rnf) { return gel(rnf,7); }
    2915             : INLINE GEN
    2916       97321 : rnf_get_map(GEN rnf) { return gel(rnf,11); }
    2917             : INLINE GEN
    2918        1197 : rnf_get_invzk(GEN rnf) { return gel(rnf,8); }
    2919             : 
    2920             : /* I integral ZM (not HNF), G ZM, rounded Cholesky form of a weighted
    2921             :  * T2 matrix. Reduce I wrt G */
    2922             : INLINE GEN
    2923       21966 : idealpseudored(GEN I, GEN G)
    2924       21966 : { return ZM_mul(I, ZM_lll(ZM_mul(G, I), 0.99, LLL_IM)); }
    2925             : 
    2926             : /* I integral (not necessarily HNF), G ZM, rounded Cholesky form of a weighted
    2927             :  * T2 matrix. Return m in I with T2(m) small */
    2928             : INLINE GEN
    2929      145890 : idealpseudomin(GEN I, GEN G)
    2930             : {
    2931      145890 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2932      145890 :   return ZM_ZC_mul(I, gel(u,1));
    2933             : }
    2934             : /* I, G as in idealpseudomin. Return an irrational m in I with T2(m) small */
    2935             : INLINE GEN
    2936      313936 : idealpseudomin_nonscalar(GEN I, GEN G)
    2937             : {
    2938      313936 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2939      313936 :   GEN m = ZM_ZC_mul(I, gel(u,1));
    2940      313936 :   if (ZV_isscalar(m) && lg(u) > 2) m = ZM_ZC_mul(I, gel(u,2));
    2941      313936 :   return m;
    2942             : }
    2943             : 
    2944             : INLINE GEN
    2945         938 : idealred_elt(GEN nf, GEN I) {
    2946         938 :   pari_sp av = avma;
    2947         938 :   GEN u = idealpseudomin(I, nf_get_roundG(nf));
    2948         938 :   return gerepileupto(av, u);
    2949             : }
    2950             : INLINE GEN
    2951      127946 : idealred(GEN nf, GEN I) { return idealred0(nf, I, NULL); }
    2952             : 
    2953             : INLINE GEN
    2954        2058 : idealchineseinit(GEN nf, GEN x)
    2955        2058 : { return idealchinese(nf,x,NULL); }
    2956             : 
    2957             : /*******************************************************************/
    2958             : /*                                                                 */
    2959             : /*                              CLOSURES                           */
    2960             : /*                                                                 */
    2961             : /*******************************************************************/
    2962   226650130 : INLINE long closure_arity(GEN C)          { return ((ulong)C[1])&ARITYBITS; }
    2963    35529322 : INLINE long closure_is_variadic(GEN C) { return !!(((ulong)C[1])&VARARGBITS); }
    2964   190851353 : INLINE const char *closure_codestr(GEN C)  { return GSTR(gel(C,2))-1; }
    2965           0 : INLINE GEN closure_get_code(GEN C)  { return gel(C,2); }
    2966   190792243 : INLINE GEN closure_get_oper(GEN C)  { return gel(C,3); }
    2967   190768541 : INLINE GEN closure_get_data(GEN C)  { return gel(C,4); }
    2968        9880 : INLINE GEN closure_get_dbg(GEN C)   { return gel(C,5); }
    2969       23722 : INLINE GEN closure_get_text(GEN C)  { return gel(C,6); }
    2970     1267983 : INLINE GEN closure_get_frame(GEN C) { return gel(C,7); }
    2971             : 
    2972             : /*******************************************************************/
    2973             : /*                                                                 */
    2974             : /*                               ERRORS                            */
    2975             : /*                                                                 */
    2976             : /*******************************************************************/
    2977             : INLINE long
    2978       53179 : err_get_num(GEN e) { return e[1]; }
    2979             : INLINE GEN
    2980         105 : err_get_compo(GEN e, long i) { return gel(e, i+1); }
    2981             : 
    2982             : INLINE void
    2983          14 : pari_err_BUG(const char *f) { pari_err(e_BUG,f); }
    2984             : INLINE void
    2985           7 : pari_err_CONSTPOL(const char *f) { pari_err(e_CONSTPOL, f); }
    2986             : INLINE void
    2987          63 : pari_err_COPRIME(const char *f, GEN x, GEN y) { pari_err(e_COPRIME, f,x,y); }
    2988             : INLINE void
    2989         494 : pari_err_DIM(const char *f) { pari_err(e_DIM, f); }
    2990             : INLINE void
    2991           0 : pari_err_FILE(const char *f, const char *g) { pari_err(e_FILE, f,g); }
    2992             : INLINE void
    2993           0 : pari_err_FILEDESC(const char *f, long n) { pari_err(e_FILEDESC, f,n); }
    2994             : INLINE void
    2995          77 : pari_err_FLAG(const char *f) { pari_err(e_FLAG,f); }
    2996             : INLINE void
    2997         434 : pari_err_IMPL(const char *f) { pari_err(e_IMPL,f); }
    2998             : INLINE void
    2999       19751 : pari_err_INV(const char *f, GEN x) { pari_err(e_INV,f,x); }
    3000             : INLINE void
    3001          42 : pari_err_IRREDPOL(const char *f, GEN x) { pari_err(e_IRREDPOL, f,x); }
    3002             : INLINE void
    3003        2099 : 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); }
    3004             : INLINE void
    3005         200 : pari_err_COMPONENT(const char *f, const char *op, GEN l, GEN x) { pari_err(e_COMPONENT, f,op,l,x); }
    3006             : INLINE void
    3007           0 : pari_err_MAXPRIME(ulong c) { pari_err(e_MAXPRIME, c); }
    3008             : INLINE void
    3009         350 : pari_err_OP(const char *f, GEN x, GEN y) { pari_err(e_OP, f,x,y); }
    3010             : INLINE void
    3011         100 : pari_err_OVERFLOW(const char *f) { pari_err(e_OVERFLOW, f); }
    3012             : INLINE void
    3013         225 : pari_err_PREC(const char *f) { pari_err(e_PREC,f); }
    3014             : INLINE void
    3015           0 : pari_err_PACKAGE(const char *f) { pari_err(e_PACKAGE,f); }
    3016             : INLINE void
    3017          77 : pari_err_PRIME(const char *f, GEN x) { pari_err(e_PRIME, f,x); }
    3018             : INLINE void
    3019         749 : pari_err_MODULUS(const char *f, GEN x, GEN y) { pari_err(e_MODULUS, f,x,y); }
    3020             : INLINE void
    3021          49 : pari_err_ROOTS0(const char *f) { pari_err(e_ROOTS0, f); }
    3022             : INLINE void
    3023          84 : pari_err_SQRTN(const char *f, GEN x) { pari_err(e_SQRTN, f,x); }
    3024             : INLINE void
    3025       12741 : pari_err_TYPE(const char *f, GEN x) { pari_err(e_TYPE, f,x); }
    3026             : INLINE void
    3027        3045 : pari_err_TYPE2(const char *f, GEN x, GEN y) { pari_err(e_TYPE2, f,x,y); }
    3028             : INLINE void
    3029         280 : pari_err_VAR(const char *f, GEN x, GEN y) { pari_err(e_VAR, f,x,y); }
    3030             : INLINE void
    3031         182 : pari_err_PRIORITY(const char *f, GEN x, const char *op, long v)
    3032         182 : { pari_err(e_PRIORITY, f,x,op,v); }

Generated by: LCOV version 1.13