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 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.10.0 lcov report (development 21348-d75f58f) Lines: 1229 1394 88.2 %
Date: 2017-11-20 06:21:05 Functions: 546 617 88.5 %
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     1540022 : mkintmod(GEN x, GEN y) { retmkintmod(x,y); }
     141             : INLINE GEN
     142        3794 : mkintmodu(ulong x, ulong y) {
     143        3794 :   GEN v = cgetg(3,t_INTMOD);
     144        3794 :   gel(v,1) = utoipos(y);
     145        3794 :   gel(v,2) = utoi(x); return v;
     146             : }
     147             : INLINE GEN
     148     1674354 : mkpolmod(GEN x, GEN y) { retmkpolmod(x,y); }
     149             : INLINE GEN
     150     4748588 : mkfrac(GEN x, GEN y) { retmkfrac(x,y); }
     151             : INLINE GEN
     152         343 : mkfracss(long x, long y) { retmkfrac(stoi(x),stoi(y)); }
     153             : /* q = n/d a t_FRAC or t_INT; recover (n,d) */
     154             : INLINE void
     155       19257 : Qtoss(GEN q, long *n, long *d)
     156             : {
     157       19257 :   if (typ(q) == t_INT) { *n = itos(q); *d = 1; }
     158        4263 :   else { *n = itos(gel(q,1)); *d = itou(gel(q,2)); }
     159       19257 : }
     160             : INLINE GEN
     161    44711051 : sstoQ(long n, long d)
     162             : {
     163             :   long g, r, q;
     164    44711051 :   if (d == 1) return stoi(n);
     165    44706361 :   q = sdivss_rem(n,d,&r);
     166    44706361 :   if (!r) return stoi(q);
     167     1594488 :   g = cgcd(d,r); /* gcd(n,d) */
     168     1594488 :   if (g != 1) { n /= g; d /= g; }
     169     1594488 :   if (d < 0) { d = -d; n = -n; }
     170     1594488 :   retmkfrac(stoi(n), utoi(d));
     171             : }
     172             : 
     173             : INLINE GEN
     174     3908865 : mkfraccopy(GEN x, GEN y) { retmkfrac(icopy(x), icopy(y)); }
     175             : INLINE GEN
     176           7 : mkrfrac(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     177           7 :   gel(v,1) = x; gel(v,2) = y; return v; }
     178             : INLINE GEN
     179           7 : mkrfraccopy(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     180           7 :   gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     181             : INLINE GEN
     182     3214965 : mkcomplex(GEN x, GEN y) { retmkcomplex(x,y); }
     183             : INLINE GEN
     184      443494 : gen_I(void) { return mkcomplex(gen_0, gen_1); }
     185             : INLINE GEN
     186      203662 : cgetc(long l) { retmkcomplex(cgetr(l), cgetr(l)); }
     187             : INLINE GEN
     188          42 : mkquad(GEN n, GEN x, GEN y) { GEN v = cgetg(4, t_QUAD);
     189          42 :   gel(v,1) = n; gel(v,2) = x; gel(v,3) = y; return v; }
     190             : /* vecsmall */
     191             : INLINE GEN
     192    55524566 : mkvecsmall(long x) { GEN v = cgetg(2, t_VECSMALL); v[1] = x; return v; }
     193             : INLINE GEN
     194   112837227 : mkvecsmall2(long x,long y) { GEN v = cgetg(3, t_VECSMALL);
     195   112825870 :   v[1]=x; v[2]=y; return v; }
     196             : INLINE GEN
     197    65439586 : mkvecsmall3(long x,long y,long z) { GEN v = cgetg(4, t_VECSMALL);
     198    65435927 :   v[1]=x; v[2]=y; v[3]=z; return v; }
     199             : INLINE GEN
     200    23913468 : mkvecsmall4(long x,long y,long z,long t) { GEN v = cgetg(5, t_VECSMALL);
     201    23896363 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; return v; }
     202             : INLINE GEN
     203      451580 : mkvecsmall5(long x,long y,long z,long t,long u) { GEN v = cgetg(6, t_VECSMALL);
     204      451580 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; v[5]=u; return v; }
     205             : 
     206             : INLINE GEN
     207      158123 : mkqfi(GEN x, GEN y, GEN z) { retmkqfi(x,y,z); }
     208             : /* vec */
     209             : INLINE GEN
     210    15856991 : mkvec(GEN x) { retmkvec(x); }
     211             : INLINE GEN
     212   110787550 : mkvec2(GEN x, GEN y) { retmkvec2(x,y); }
     213             : INLINE GEN
     214    73976344 : mkvec3(GEN x, GEN y, GEN z) { retmkvec3(x,y,z); }
     215             : INLINE GEN
     216     8465498 : mkvec4(GEN x, GEN y, GEN z, GEN t) { retmkvec4(x,y,z,t); }
     217             : INLINE GEN
     218    11928092 : mkvec5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkvec5(x,y,z,t,u); }
     219             : INLINE GEN
     220           7 : mkvecs(long x) { retmkvec(stoi(x)); }
     221             : INLINE GEN
     222       19850 : mkvec2s(long x, long y) { retmkvec2(stoi(x),stoi(y)); }
     223             : INLINE GEN
     224      492716 : mkvec3s(long x, long y, long z) { retmkvec3(stoi(x),stoi(y),stoi(z)); }
     225             : INLINE GEN
     226          21 : mkvec4s(long x, long y, long z, long t) { retmkvec4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     227             : INLINE GEN
     228       33467 : mkveccopy(GEN x) { GEN v = cgetg(2, t_VEC); gel(v,1) = gcopy(x); return v; }
     229             : INLINE GEN
     230      108339 : mkvec2copy(GEN x, GEN y) {
     231      108339 :   GEN v = cgetg(3,t_VEC); gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     232             : /* col */
     233             : INLINE GEN
     234     2233665 : mkcol(GEN x) { retmkcol(x); }
     235             : INLINE GEN
     236    24491822 : mkcol2(GEN x, GEN y) { retmkcol2(x,y); }
     237             : INLINE GEN
     238       41671 : mkcol3(GEN x, GEN y, GEN z) { retmkcol3(x,y,z); }
     239             : INLINE GEN
     240           0 : mkcol4(GEN x, GEN y, GEN z, GEN t) { retmkcol4(x,y,z,t); }
     241             : INLINE GEN
     242           0 : mkcol5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkcol5(x,y,z,t,u); }
     243             : INLINE GEN
     244        4208 : mkcol6(GEN x, GEN y, GEN z, GEN t, GEN u, GEN v) { retmkcol6(x,y,z,t,u,v); }
     245             : INLINE GEN
     246         735 : mkcols(long x) { retmkcol(stoi(x)); }
     247             : INLINE GEN
     248     1756356 : mkcol2s(long x, long y) { retmkcol2(stoi(x),stoi(y)); }
     249             : INLINE GEN
     250           0 : mkcol3s(long x, long y, long z) { retmkcol3(stoi(x),stoi(y),stoi(z)); }
     251             : INLINE GEN
     252           0 : mkcol4s(long x, long y, long z, long t) { retmkcol4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     253             : INLINE GEN
     254       28809 : mkcolcopy(GEN x) { GEN v = cgetg(2, t_COL); gel(v,1) = gcopy(x); return v; }
     255             : /* mat */
     256             : INLINE GEN
     257     4976489 : mkmat(GEN x) { retmkmat(x); }
     258             : INLINE GEN
     259    19044379 : mkmat2(GEN x, GEN y) { retmkmat2(x,y); }
     260             : INLINE GEN
     261        2352 : mkmat3(GEN x, GEN y, GEN z) { retmkmat3(x,y,z); }
     262             : INLINE GEN
     263           0 : mkmat4(GEN x, GEN y, GEN z, GEN t) { retmkmat4(x,y,z,t); }
     264             : INLINE GEN
     265           0 : mkmat5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkmat5(x,y,z,t,u); }
     266             : INLINE GEN
     267        7459 : mkmatcopy(GEN x) { GEN v = cgetg(2, t_MAT); gel(v,1) = gcopy(x); return v; }
     268             : INLINE GEN
     269           0 : mkerr(long x) { GEN v = cgetg(2, t_ERROR); v[1] = x; return v; }
     270             : INLINE GEN
     271       23527 : mkoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_1; return v; }
     272             : INLINE GEN
     273       14371 : mkmoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_m1; return v; }
     274             : INLINE long
     275       46103 : inf_get_sign(GEN x) { return signe(gel(x,1)); }
     276             : /* pol */
     277             : INLINE GEN
     278     1043008 : pol_x(long v) {
     279     1043008 :   GEN p = cgetg(4, t_POL);
     280     1043008 :   p[1] = evalsigne(1)|evalvarn(v);
     281     1043008 :   gel(p,2) = gen_0;
     282     1043008 :   gel(p,3) = gen_1; return p;
     283             : }
     284             : /* x^n, assume n >= 0 */
     285             : INLINE GEN
     286     2493752 : pol_xn(long n, long v) {
     287     2493752 :   long i, a = n+2;
     288     2493752 :   GEN p = cgetg(a+1, t_POL);
     289     2493752 :   p[1] = evalsigne(1)|evalvarn(v);
     290     2493752 :   for (i = 2; i < a; i++) gel(p,i) = gen_0;
     291     2493752 :   gel(p,a) = gen_1; return p;
     292             : }
     293             : /* x^n, no assumption on n */
     294             : INLINE GEN
     295          42 : pol_xnall(long n, long v)
     296             : {
     297          42 :   if (n < 0) retmkrfrac(gen_1, pol_xn(-n,v));
     298          42 :   return pol_xn(n, v);
     299             : }
     300             : INLINE GEN
     301     1290430 : pol_1(long v) {
     302     1290430 :   GEN p = cgetg(3, t_POL);
     303     1290433 :   p[1] = evalsigne(1)|evalvarn(v);
     304     1290433 :   gel(p,2) = gen_1; return p;
     305             : }
     306             : INLINE GEN
     307    14890150 : pol_0(long v)
     308             : {
     309    14890150 :   GEN x = cgetg(2,t_POL);
     310    14890150 :   x[1] = evalvarn(v); return x;
     311             : }
     312             : #define retconst_vec(n,x)\
     313             :   do { long _i, _n = (n);\
     314             :        GEN _v = cgetg(_n+1, t_VEC), _x = (x);\
     315             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     316             :        return _v; } while(0)
     317             : INLINE GEN
     318     7521077 : const_vec(long n, GEN x) { retconst_vec(n, x); }
     319             : #define retconst_col(n,x)\
     320             :   do { long _i, _n = (n);\
     321             :        GEN _v = cgetg(_n+1, t_COL), _x = (x);\
     322             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     323             :        return _v; } while(0)
     324             : INLINE GEN
     325      130355 : const_col(long n, GEN x) { retconst_col(n, x); }
     326             : INLINE GEN
     327     4848364 : const_vecsmall(long n, long c)
     328             : {
     329             :   long i;
     330     4848364 :   GEN V = cgetg(n+1,t_VECSMALL);
     331     4848384 :   for(i=1;i<=n;i++) V[i] = c;
     332     4848384 :   return V;
     333             : }
     334             : 
     335             : /***   ZERO   ***/
     336             : /* O(p^e) */
     337             : INLINE GEN
     338      302725 : zeropadic(GEN p, long e)
     339             : {
     340      302725 :   GEN y = cgetg(5,t_PADIC);
     341      302725 :   gel(y,4) = gen_0;
     342      302725 :   gel(y,3) = gen_1;
     343      302725 :   gel(y,2) = icopy(p);
     344      302725 :   y[1] = evalvalp(e) | _evalprecp(0);
     345      302725 :   return y;
     346             : }
     347             : INLINE GEN
     348         539 : zeropadic_shallow(GEN p, long e)
     349             : {
     350         539 :   GEN y = cgetg(5,t_PADIC);
     351         539 :   gel(y,4) = gen_0;
     352         539 :   gel(y,3) = gen_1;
     353         539 :   gel(y,2) = p;
     354         539 :   y[1] = evalvalp(e) | _evalprecp(0);
     355         539 :   return y;
     356             : }
     357             : /* O(pol_x(v)^e) */
     358             : INLINE GEN
     359       14511 : zeroser(long v, long e)
     360             : {
     361       14511 :   GEN x = cgetg(2, t_SER);
     362       14511 :   x[1] = evalvalp(e) | evalvarn(v); return x;
     363             : }
     364             : INLINE int
     365     3760616 : ser_isexactzero(GEN x)
     366             : {
     367     3760616 :   if (!signe(x)) switch(lg(x))
     368             :   {
     369       12761 :     case 2: return 1;
     370         847 :     case 3: return isexactzero(gel(x,2));
     371             :   }
     372     3747008 :   return 0;
     373             : }
     374             : /* 0 * pol_x(v) */
     375             : INLINE GEN
     376     5217650 : zeropol(long v) { return pol_0(v); }
     377             : /* vector(n) */
     378             : INLINE GEN
     379    26977748 : zerocol(long n)
     380             : {
     381    26977748 :   GEN y = cgetg(n+1,t_COL);
     382    26977748 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     383    26977748 :   return y;
     384             : }
     385             : /* vectorv(n) */
     386             : INLINE GEN
     387    14449408 : zerovec(long n)
     388             : {
     389    14449408 :   GEN y = cgetg(n+1,t_VEC);
     390    14449411 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     391    14449411 :   return y;
     392             : }
     393             : /* matrix(m, n) */
     394             : INLINE GEN
     395       16079 : zeromat(long m, long n)
     396             : {
     397       16079 :   GEN y = cgetg(n+1,t_MAT);
     398       16079 :   GEN v = zerocol(m);
     399       16079 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     400       16079 :   return y;
     401             : }
     402             : /* = zero_zx, sv is a evalvarn()*/
     403             : INLINE GEN
     404      787137 : zero_Flx(long sv) { return pol0_Flx(sv); }
     405             : INLINE GEN
     406    32101953 : zero_Flv(long n)
     407             : {
     408    32101953 :   GEN y = cgetg(n+1,t_VECSMALL);
     409    32102325 :   long i; for (i=1; i<=n; i++) y[i] = 0;
     410    32102325 :   return y;
     411             : }
     412             : /* matrix(m, n) */
     413             : INLINE GEN
     414      936225 : zero_Flm(long m, long n)
     415             : {
     416      936225 :   GEN y = cgetg(n+1,t_MAT);
     417      936184 :   GEN v = zero_Flv(m);
     418      936262 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     419      936262 :   return y;
     420             : }
     421             : /* matrix(m, n) */
     422             : INLINE GEN
     423       98921 : zero_Flm_copy(long m, long n)
     424             : {
     425       98921 :   GEN y = cgetg(n+1,t_MAT);
     426       98933 :   long i; for (i=1; i<=n; i++) gel(y,i) = zero_Flv(m);
     427       98928 :   return y;
     428             : }
     429             : 
     430             : INLINE GEN
     431      788953 : zero_F2v(long m)
     432             : {
     433      788953 :   long l = nbits2nlong(m);
     434      788953 :   GEN v  = zero_Flv(l+1);
     435      788953 :   v[1] = m;
     436      788953 :   return v;
     437             : }
     438             : 
     439             : INLINE GEN
     440           0 : zero_F2m(long m, long n)
     441             : {
     442             :   long i;
     443           0 :   GEN M = cgetg(n+1, t_MAT);
     444           0 :   GEN v = zero_F2v(m);
     445           0 :   for (i = 1; i <= n; i++)
     446           0 :     gel(M,i) = v;
     447           0 :   return M;
     448             : }
     449             : 
     450             : 
     451             : INLINE GEN
     452      280253 : zero_F2m_copy(long m, long n)
     453             : {
     454             :   long i;
     455      280253 :   GEN M = cgetg(n+1, t_MAT);
     456      858824 :   for (i = 1; i <= n; i++)
     457      578571 :     gel(M,i)= zero_F2v(m);
     458      280253 :   return M;
     459             : }
     460             : 
     461             : /* matrix(m, n) */
     462             : INLINE GEN
     463     2255701 : zeromatcopy(long m, long n)
     464             : {
     465     2255701 :   GEN y = cgetg(n+1,t_MAT);
     466     2255701 :   long i; for (i=1; i<=n; i++) gel(y,i) = zerocol(m);
     467     2255701 :   return y;
     468             : }
     469             : 
     470             : INLINE GEN
     471       16919 : zerovec_block(long len)
     472             : {
     473             :   long i;
     474       16919 :   GEN blk = cgetg_block(len + 1, t_VEC);
     475      558327 :   for (i = 1; i <= len; ++i)
     476      541408 :     gel(blk, i) = gen_0;
     477       16919 :   return blk;
     478             : }
     479             : 
     480             : /* i-th vector in the standard basis */
     481             : INLINE GEN
     482     1266123 : col_ei(long n, long i) { GEN e = zerocol(n); gel(e,i) = gen_1; return e; }
     483             : INLINE GEN
     484      323401 : vec_ei(long n, long i) { GEN e = zerovec(n); gel(e,i) = gen_1; return e; }
     485             : INLINE GEN
     486           7 : F2v_ei(long n, long i) { GEN e = zero_F2v(n); F2v_set(e,i); return e; }
     487             : INLINE GEN
     488       68850 : vecsmall_ei(long n, long i) { GEN e = zero_zv(n); e[i] = 1; return e; }
     489             : INLINE GEN
     490     1225972 : Rg_col_ei(GEN x, long n, long i) { GEN e = zerocol(n); gel(e,i) = x; return e; }
     491             : 
     492             : INLINE GEN
     493     8255250 : shallowcopy(GEN x)
     494     8255250 : { return typ(x) == t_MAT ? RgM_shallowcopy(x): leafcopy(x); }
     495             : 
     496             : /* routines for naive growarrays */
     497             : INLINE GEN
     498    12716471 : vectrunc_init(long l)
     499             : {
     500    12716471 :   GEN z = new_chunk(l);
     501    12716902 :   z[0] = evaltyp(t_VEC) | _evallg(1); return z;
     502             : }
     503             : INLINE void
     504   346483835 : lg_increase(GEN x) { x[0]++; }
     505             : INLINE void
     506    49330615 : vectrunc_append(GEN x, GEN t) { gel(x, lg(x)) = t; lg_increase(x); }
     507             : INLINE void
     508           0 : vectrunc_append_batch(GEN x, GEN y)
     509             : {
     510           0 :   long i, l = lg(x), ly = lg(y);
     511           0 :   GEN z = x + l-1;
     512           0 :   for (i = 1; i < ly; i++) gel(z,i) = gel(y,i);
     513           0 :   setlg(x, l+ly-1);
     514           0 : }
     515             : INLINE GEN
     516   112282443 : vecsmalltrunc_init(long l)
     517             : {
     518   112282443 :   GEN z = new_chunk(l);
     519   112282443 :   z[0] = evaltyp(t_VECSMALL) | _evallg(1); return z;
     520             : }
     521             : INLINE void
     522    25843566 : vecsmalltrunc_append(GEN x, long t) { x[ lg(x) ] = t; lg_increase(x); }
     523             : 
     524             : /*******************************************************************/
     525             : /*                                                                 */
     526             : /*                        VEC / COL / VECSMALL                     */
     527             : /*                                                                 */
     528             : /*******************************************************************/
     529             : /* shallow*/
     530             : INLINE GEN
     531           0 : vec_shorten(GEN v, long n)
     532             : {
     533             :   long i;
     534           0 :   GEN V = cgetg(n+1,t_VEC);
     535           0 :   for(i=1;i<=n;i++) gel(V,i) = gel(v,i);
     536           0 :   return V;
     537             : }
     538             : /* shallow*/
     539             : INLINE GEN
     540       10969 : vec_lengthen(GEN v, long n)
     541             : {
     542             :   long i;
     543       10969 :   long l=lg(v);
     544       10969 :   GEN V = cgetg(n+1,t_VEC);
     545       10969 :   for(i=1;i<l;i++) gel(V,i) = gel(v,i);
     546       10969 :   return V;
     547             : }
     548             : /* shallow*/
     549             : INLINE GEN
     550       60704 : vec_append(GEN V, GEN s)
     551             : {
     552       60704 :   long i, l2 = lg(V);
     553       60704 :   GEN res = cgetg(l2+1, typ(V));
     554       60704 :   for (i = 1; i < l2; ++i) gel(res, i) = gel(V,i);
     555       60704 :   gel(res,l2) = s; return res;
     556             : }
     557             : /* shallow*/
     558             : INLINE GEN
     559        1736 : vec_prepend(GEN v, GEN s)
     560             : {
     561        1736 :   long i, l = lg(v);
     562        1736 :   GEN w = cgetg(l+1, typ(v));
     563        1736 :   gel(w,1) = s;
     564        1736 :   for (i = 2; i <= l; ++i) gel(w,i) = gel(v,i-1);
     565        1736 :   return w;
     566             : }
     567             : /* shallow*/
     568             : INLINE GEN
     569           0 : vec_setconst(GEN v, GEN x)
     570             : {
     571           0 :   long i, l = lg(v);
     572           0 :   for (i = 1; i < l; i++) gel(v,i) = x;
     573           0 :   return v;
     574             : }
     575             : INLINE GEN
     576      141771 : vecsmall_shorten(GEN v, long n)
     577             : {
     578             :   long i;
     579      141771 :   GEN V = cgetg(n+1,t_VECSMALL);
     580      141771 :   for(i=1;i<=n;i++) V[i] = v[i];
     581      141771 :   return V;
     582             : }
     583             : INLINE GEN
     584          21 : vecsmall_lengthen(GEN v, long n)
     585             : {
     586          21 :   long i, l = lg(v);
     587          21 :   GEN V = cgetg(n+1,t_VECSMALL);
     588          21 :   for(i=1;i<l;i++) V[i] = v[i];
     589          21 :   return V;
     590             : }
     591             : 
     592             : INLINE GEN
     593      408007 : vec_to_vecsmall(GEN x)
     594      408007 : { pari_APPLY_long(itos(gel(x,i))) }
     595             : INLINE GEN
     596      407421 : vecsmall_to_vec(GEN x)
     597      407421 : { pari_APPLY_type(t_VEC, stoi(x[i])) }
     598             : INLINE GEN
     599        1022 : vecsmall_to_vec_inplace(GEN z)
     600             : {
     601        1022 :   long i, l = lg(z);
     602        1022 :   for (i=1; i<l; i++) gel(z,i) = stoi(z[i]);
     603        1022 :   settyp(z, t_VEC); return z;
     604             : }
     605             : INLINE GEN
     606      622308 : vecsmall_to_col(GEN x)
     607      622308 : { pari_APPLY_type(t_COL, stoi(x[i])) }
     608             : 
     609             : INLINE int
     610     7373815 : vecsmall_lexcmp(GEN x, GEN y)
     611             : {
     612             :   long lx,ly,l,i;
     613     7373815 :   lx = lg(x);
     614     7373815 :   ly = lg(y); l = minss(lx,ly);
     615    35759932 :   for (i=1; i<l; i++)
     616    34012408 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     617     1747524 :   if (lx == ly) return 0;
     618          14 :   return (lx < ly)? -1 : 1;
     619             : }
     620             : 
     621             : INLINE int
     622    47068252 : vecsmall_prefixcmp(GEN x, GEN y)
     623             : {
     624    47068252 :   long i, lx = lg(x), ly = lg(y), l = minss(lx,ly);
     625   148815065 :   for (i=1; i<l; i++)
     626   134955107 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     627    13859958 :   return 0;
     628             : }
     629             : 
     630             : /*Can be used on t_VEC, but coeffs not gcopy-ed*/
     631             : INLINE GEN
     632       13811 : vecsmall_prepend(GEN V, long s)
     633             : {
     634       13811 :   long i, l2 = lg(V);
     635       13811 :   GEN res = cgetg(l2+1, typ(V));
     636       13811 :   res[1] = s;
     637       13811 :   for (i = 2; i <= l2; ++i) res[i] = V[i - 1];
     638       13811 :   return res;
     639             : }
     640             : 
     641             : INLINE GEN
     642     2646219 : vecsmall_append(GEN V, long s)
     643             : {
     644     2646219 :   long i, l2 = lg(V);
     645     2646219 :   GEN res = cgetg(l2+1, t_VECSMALL);
     646     2646219 :   for (i = 1; i < l2; ++i) res[i] = V[i];
     647     2646219 :   res[l2] = s; return res;
     648             : }
     649             : 
     650             : INLINE GEN
     651      849546 : vecsmall_concat(GEN u, GEN v)
     652             : {
     653      849546 :   long i, l1 = lg(u)-1, l2 = lg(v)-1;
     654      849546 :   GEN res = cgetg(l1+l2+1, t_VECSMALL);
     655      849546 :   for (i = 1; i <= l1; ++i) res[i]    = u[i];
     656      849546 :   for (i = 1; i <= l2; ++i) res[i+l1] = v[i];
     657      849546 :   return res;
     658             : }
     659             : 
     660             : /* return the number of indices where u and v are equal */
     661             : INLINE long
     662           0 : vecsmall_coincidence(GEN u, GEN v)
     663             : {
     664           0 :   long i, s = 0, l = minss(lg(u),lg(v));
     665           0 :   for(i=1; i<l; i++)
     666           0 :     if(u[i] == v[i]) s++;
     667           0 :   return s;
     668             : }
     669             : 
     670             : /* returns the first index i<=n such that x=v[i] if it exists, 0 otherwise */
     671             : INLINE long
     672           0 : vecsmall_isin(GEN v, long x)
     673             : {
     674           0 :   long i, l = lg(v);
     675           0 :   for (i = 1; i < l; i++)
     676           0 :     if (v[i] == x) return i;
     677           0 :   return 0;
     678             : }
     679             : 
     680             : INLINE long
     681          84 : vecsmall_pack(GEN V, long base, long mod)
     682             : {
     683          84 :   long i, s = 0;
     684          84 :   for(i=1; i<lg(V); i++) s = (base*s + V[i]) % mod;
     685          84 :   return s;
     686             : }
     687             : 
     688             : INLINE long
     689          14 : vecsmall_indexmax(GEN x)
     690             : {
     691          14 :   long i, i0 = 1, t = x[1], lx = lg(x);
     692          56 :   for (i=2; i<lx; i++)
     693          42 :     if (x[i] > t) t = x[i0=i];
     694          14 :   return i0;
     695             : }
     696             : 
     697             : INLINE long
     698      104080 : vecsmall_max(GEN x)
     699             : {
     700      104080 :   long i, t = x[1], lx = lg(x);
     701      341924 :   for (i=2; i<lx; i++)
     702      237844 :     if (x[i] > t) t = x[i];
     703      104080 :   return t;
     704             : }
     705             : 
     706             : INLINE long
     707          14 : vecsmall_indexmin(GEN x)
     708             : {
     709          14 :   long i, i0 = 1, t = x[1], lx =lg(x);
     710          56 :   for (i=2; i<lx; i++)
     711          42 :     if (x[i] < t) t = x[i0=i];
     712          14 :   return i0;
     713             : }
     714             : 
     715             : INLINE long
     716           0 : vecsmall_min(GEN x)
     717             : {
     718           0 :   long i, t = x[1], lx =lg(x);
     719           0 :   for (i=2; i<lx; i++)
     720           0 :     if (x[i] < t) t = x[i];
     721           0 :   return t;
     722             : }
     723             : 
     724             : INLINE int
     725     2115392 : ZV_isscalar(GEN x)
     726             : {
     727     2115392 :   long l = lg(x);
     728     7455963 :   while (--l > 1)
     729     4960330 :     if (signe(gel(x, l))) return 0;
     730      380241 :   return 1;
     731             : }
     732             : INLINE int
     733    17381848 : QV_isscalar(GEN x)
     734             : {
     735    17381848 :   long lx = lg(x),i;
     736    18841307 :   for (i=2; i<lx; i++)
     737    18314412 :     if (!isintzero(gel(x, i))) return 0;
     738      526895 :   return 1;
     739             : }
     740             : INLINE int
     741        3850 : RgV_isscalar(GEN x)
     742             : {
     743        3850 :   long lx = lg(x),i;
     744        7305 :   for (i=2; i<lx; i++)
     745        6213 :     if (!gequal0(gel(x, i))) return 0;
     746        1092 :   return 1;
     747             : }
     748             : INLINE int
     749           0 : RgX_isscalar(GEN x)
     750             : {
     751             :   long i;
     752           0 :   for (i=lg(x)-1; i>2; i--)
     753           0 :     if (!gequal0(gel(x, i))) return 0;
     754           0 :   return 1;
     755             : }
     756             : INLINE long
     757     4039803 : RgX_equal_var(GEN x, GEN y) { return varn(x) == varn(y) && RgX_equal(x,y); }
     758             : 
     759             : INLINE int
     760        5300 : RgX_is_rational(GEN x)
     761             : {
     762             :   long i;
     763       23492 :   for (i = lg(x)-1; i > 1; i--)
     764       22133 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     765        1359 :   return 1;
     766             : }
     767             : INLINE int
     768     3911415 : RgX_is_ZX(GEN x)
     769             : {
     770             :   long i;
     771    16959663 :   for (i = lg(x)-1; i > 1; i--)
     772    13060778 :     if (typ(gel(x,i)) != t_INT) return 0;
     773     3898885 :   return 1;
     774             : }
     775             : INLINE int
     776      116130 : RgX_is_QX(GEN x)
     777             : {
     778      116130 :   long k = lg(x)-1;
     779      439362 :   for ( ; k>1; k--)
     780      324226 :     if (!is_rational_t(typ(gel(x,k)))) return 0;
     781      115136 :   return 1;
     782             : }
     783             : INLINE int
     784    15558744 : RgX_is_monomial(GEN x)
     785             : {
     786             :   long i;
     787    15558744 :   if (!signe(x)) return 0;
     788    25739373 :   for (i=lg(x)-2; i>1; i--)
     789    17774691 :     if (!isexactzero(gel(x,i))) return 0;
     790     7964682 :   return 1;
     791             : }
     792             : INLINE int
     793    18177666 : RgV_is_ZV(GEN x)
     794             : {
     795             :   long i;
     796    75266712 :   for (i = lg(x)-1; i > 0; i--)
     797    57090152 :     if (typ(gel(x,i)) != t_INT) return 0;
     798    18176560 :   return 1;
     799             : }
     800             : INLINE int
     801         707 : RgV_is_QV(GEN x)
     802             : {
     803             :   long i;
     804        1085 :   for (i = lg(x)-1; i > 0; i--)
     805         945 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     806         140 :   return 1;
     807             : }
     808             : 
     809             : /********************************************************************/
     810             : /**                                                                **/
     811             : /**            Dynamic arrays implementation                       **/
     812             : /**                                                                **/
     813             : /********************************************************************/
     814             : INLINE void **
     815   415739592 : pari_stack_base(pari_stack *s) { return s->data; }
     816             : 
     817             : INLINE void
     818     1291346 : pari_stack_init(pari_stack *s, size_t size, void **data)
     819             : {
     820     1291346 :   s->data = data;
     821     1291346 :   *data = NULL;
     822     1291346 :   s->n = 0;
     823     1291346 :   s->alloc = 0;
     824     1291346 :   s->size = size;
     825     1291346 : }
     826             : 
     827             : INLINE void
     828   414550643 : pari_stack_alloc(pari_stack *s, long nb)
     829             : {
     830   414550643 :   void **sdat = pari_stack_base(s);
     831   414681489 :   long alloc = s->alloc;
     832   829364848 :   if (s->n+nb <= alloc) return;
     833      526102 :   if (!alloc)
     834      476098 :     alloc = nb;
     835             :   else
     836             :   {
     837       50004 :     while (s->n+nb > alloc) alloc <<= 1;
     838             :   }
     839      526102 :   *sdat = pari_realloc(*sdat,alloc*s->size);
     840      527972 :   s->alloc = alloc;
     841             : }
     842             : 
     843             : INLINE long
     844   345421363 : pari_stack_new(pari_stack *s) { pari_stack_alloc(s, 1); return s->n++; }
     845             : 
     846             : INLINE void
     847     1114643 : pari_stack_delete(pari_stack *s)
     848             : {
     849     1114643 :   void **sdat = pari_stack_base(s);
     850     1113805 :   if (*sdat) pari_free(*sdat);
     851     1114149 : }
     852             : 
     853             : INLINE void
     854        4776 : pari_stack_pushp(pari_stack *s, void *u)
     855             : {
     856        4776 :   long n = pari_stack_new(s);
     857        4776 :   void **sdat =(void**) *pari_stack_base(s);
     858        4776 :   sdat[n] = u;
     859        4776 : }
     860             : 
     861             : /*******************************************************************/
     862             : /*                                                                 */
     863             : /*                            EXTRACT                              */
     864             : /*                                                                 */
     865             : /*******************************************************************/
     866             : INLINE GEN
     867   224420756 : vecslice(GEN A, long y1, long y2)
     868             : {
     869   224420756 :   long i,lB = y2 - y1 + 2;
     870   224420756 :   GEN B = cgetg(lB, typ(A));
     871   224499200 :   for (i=1; i<lB; i++) B[i] = A[y1-1+i];
     872   224499200 :   return B;
     873             : }
     874             : INLINE GEN
     875      799454 : vecslicepermute(GEN A, GEN p, long y1, long y2)
     876             : {
     877      799454 :   long i,lB = y2 - y1 + 2;
     878      799454 :   GEN B = cgetg(lB, typ(A));
     879      799468 :   for (i=1; i<lB; i++) B[i] = A[p[y1-1+i]];
     880      799468 :   return B;
     881             : }
     882             : /* rowslice(rowpermute(A,p), x1, x2) */
     883             : INLINE GEN
     884       34440 : rowslicepermute(GEN x, GEN p, long j1, long j2)
     885       34440 : { pari_APPLY_same(vecslicepermute(gel(x,i),p,j1,j2)) }
     886             : 
     887             : INLINE GEN
     888    23670967 : rowslice(GEN x, long j1, long j2)
     889    23670967 : { pari_APPLY_same(vecslice(gel(x,i), j1, j2)) }
     890             : 
     891             : INLINE GEN
     892     3726055 : matslice(GEN A, long x1, long x2, long y1, long y2)
     893     3726055 : { return rowslice(vecslice(A, y1, y2), x1, x2); }
     894             : 
     895             : /* shallow, remove coeff of index j */
     896             : INLINE GEN
     897         133 : rowsplice(GEN x, long j)
     898         133 : { pari_APPLY_same(vecsplice(gel(x,i), j)) }
     899             : 
     900             : /* shallow, remove coeff of index j */
     901             : INLINE GEN
     902      248297 : vecsplice(GEN a, long j)
     903             : {
     904      248297 :   long i, k, l = lg(a);
     905             :   GEN b;
     906      248297 :   if (l == 1) pari_err(e_MISC, "incorrect component in vecsplice");
     907      248297 :   b = cgetg(l-1, typ(a));
     908      992089 :   for (i = k = 1; i < l; i++)
     909      743792 :     if (i != j) gel(b, k++) = gel(a,i);
     910      248297 :   return b;
     911             : }
     912             : /* shallow */
     913             : INLINE GEN
     914         567 : RgM_minor(GEN a, long i, long j)
     915             : {
     916         567 :   GEN b = vecsplice(a, j);
     917         567 :   long k, l = lg(b);
     918         567 :   for (k = 1; k < l; k++) gel(b,k) = vecsplice(gel(b,k), i);
     919         567 :   return b;
     920             : }
     921             : 
     922             : /* A[x0,] */
     923             : INLINE GEN
     924      177999 : row(GEN x, long j)
     925      177999 : { pari_APPLY_type(t_VEC, gcoeff(x, j, i)) }
     926             : INLINE GEN
     927     3723313 : Flm_row(GEN x, long j)
     928     3723313 : { pari_APPLY_ulong((ulong)coeff(x, j, i)) }
     929             : /* A[x0,] */
     930             : INLINE GEN
     931          63 : rowcopy(GEN x, long j)
     932          63 : { pari_APPLY_type(t_VEC, gcopy(gcoeff(x, j, i))) }
     933             : /* A[x0, x1..x2] */
     934             : INLINE GEN
     935        2177 : row_i(GEN A, long x0, long x1, long x2)
     936             : {
     937        2177 :   long i, lB = x2 - x1 + 2;
     938        2177 :   GEN B  = cgetg(lB, t_VEC);
     939        2177 :   for (i=x1; i<=x2; i++) gel(B, i) = gcoeff(A, x0, i);
     940        2177 :   return B;
     941             : }
     942             : 
     943             : INLINE GEN
     944     5491970 : vecreverse(GEN A)
     945             : {
     946             :   long i, l;
     947     5491970 :   GEN B = cgetg_copy(A, &l);
     948     5491970 :   for (i=1; i<l; i++) gel(B, i) = gel(A, l-i);
     949     5491970 :   return B;
     950             : }
     951             : 
     952             : INLINE GEN
     953         252 : vecsmall_reverse(GEN A)
     954             : {
     955             :   long i, l;
     956         252 :   GEN B = cgetg_copy(A, &l);
     957         252 :   for (i=1; i<l; i++) B[i] = A[l-i];
     958         252 :   return B;
     959             : }
     960             : 
     961             : INLINE void
     962         232 : vecreverse_inplace(GEN y)
     963             : {
     964         232 :   long ly = lg(y), lim = ly>>1, i;
     965         640 :   for (i = 1; i <= lim; i++)
     966             :   {
     967         408 :     GEN z = gel(y,i);
     968         408 :     gel(y,i)    = gel(y,ly-i);
     969         408 :     gel(y,ly-i) = z;
     970             :   }
     971         232 : }
     972             : 
     973             : INLINE GEN
     974    45954499 : vecsmallpermute(GEN A, GEN p) { return perm_mul(A, p); }
     975             : 
     976             : INLINE GEN
     977     6782387 : vecpermute(GEN A, GEN x)
     978     6782387 : { pari_APPLY_type(typ(A), gel(A, x[i])) }
     979             : 
     980             : INLINE GEN
     981     3090761 : rowpermute(GEN x, GEN p)
     982     3090761 : { pari_APPLY_same(typ(gel(x,i)) == t_VECSMALL ? vecsmallpermute(gel(x, i), p)
     983             :                                               : vecpermute(gel(x, i), p))
     984             : }
     985             : /*******************************************************************/
     986             : /*                                                                 */
     987             : /*                          PERMUTATIONS                           */
     988             : /*                                                                 */
     989             : /*******************************************************************/
     990             : /* identity permutation */
     991             : INLINE GEN
     992      698381 : identity_perm(long n)
     993             : {
     994      698381 :   GEN perm = cgetg(n+1, t_VECSMALL);
     995             :   long i;
     996      698386 :   for (i = 1; i <= n; i++) perm[i] = i;
     997      698386 :   return perm;
     998             : }
     999             : 
    1000             : /* assume d <= n */
    1001             : INLINE GEN
    1002       54523 : cyclic_perm(long n, long d)
    1003             : {
    1004       54523 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1005             :   long i;
    1006       54523 :   for (i = 1; i <= n-d; i++) perm[i] = i+d;
    1007       54523 :   for (     ; i <= n;   i++) perm[i] = i-n+d;
    1008       54523 :   return perm;
    1009             : }
    1010             : 
    1011             : /* Multiply (compose) two permutations */
    1012             : INLINE GEN
    1013    47202353 : perm_mul(GEN s, GEN x)
    1014    47202353 : { pari_APPLY_long(s[x[i]]) }
    1015             : 
    1016             : /* Compute the inverse (reciprocal) of a permutation. */
    1017             : INLINE GEN
    1018     1171681 : perm_inv(GEN x)
    1019             : {
    1020             :   long i, lx;
    1021     1171681 :   GEN y = cgetg_copy(x, &lx);
    1022     1171691 :   for (i=1; i<lx; i++) y[ x[i] ] = i;
    1023     1171691 :   return y;
    1024             : }
    1025             : /* Return s*t*s^-1 */
    1026             : INLINE GEN
    1027      402990 : perm_conj(GEN s, GEN t)
    1028             : {
    1029             :   long i, l;
    1030      402990 :   GEN v = cgetg_copy(s, &l);
    1031      402990 :   for (i = 1; i < l; i++) v[ s[i] ] = s[ t[i] ];
    1032      402990 :   return v;
    1033             : }
    1034             : 
    1035             : /*********************************************************************/
    1036             : /*                       MALLOC/FREE WRAPPERS                        */
    1037             : /*********************************************************************/
    1038             : #define BLOCK_SIGALRM_START          \
    1039             : {                                    \
    1040             :   int block=PARI_SIGINT_block;       \
    1041             :   PARI_SIGINT_block = 2;             \
    1042             :   MT_SIGINT_BLOCK(block);
    1043             : 
    1044             : #define BLOCK_SIGINT_START           \
    1045             : {                                    \
    1046             :   int block=PARI_SIGINT_block;       \
    1047             :   PARI_SIGINT_block = 1;             \
    1048             :   MT_SIGINT_BLOCK(block);
    1049             : 
    1050             : #define BLOCK_SIGINT_END             \
    1051             :   PARI_SIGINT_block = block;         \
    1052             :   MT_SIGINT_UNBLOCK(block);          \
    1053             :   if (!block && PARI_SIGINT_pending) \
    1054             :   {                                  \
    1055             :     int sig = PARI_SIGINT_pending;   \
    1056             :     PARI_SIGINT_pending = 0;         \
    1057             :     raise(sig);                      \
    1058             :   }                                  \
    1059             : }
    1060             : 
    1061             : INLINE void
    1062    56218749 : pari_free(void *pointer)
    1063             : {
    1064    56218749 :   BLOCK_SIGINT_START;
    1065    56220743 :   free(pointer);
    1066    56220743 :   BLOCK_SIGINT_END;
    1067    56219981 : }
    1068             : INLINE void*
    1069   239195473 : pari_malloc(size_t size)
    1070             : {
    1071   239195473 :   if (size)
    1072             :   {
    1073             :     char *tmp;
    1074   239195473 :     BLOCK_SIGINT_START;
    1075   239199345 :     tmp = (char*)malloc(size);
    1076   239199345 :     BLOCK_SIGINT_END;
    1077   239199136 :     if (!tmp) pari_err(e_MEM);
    1078   239199136 :     return tmp;
    1079             :   }
    1080           0 :   if (DEBUGMEM) pari_warn(warner,"mallocing NULL object");
    1081           0 :   return NULL;
    1082             : }
    1083             : INLINE void*
    1084      538401 : pari_realloc(void *pointer, size_t size)
    1085             : {
    1086             :   char *tmp;
    1087             : 
    1088      538401 :   BLOCK_SIGINT_START;
    1089      540736 :   if (!pointer) tmp = (char *) malloc(size);
    1090       53694 :   else tmp = (char *) realloc(pointer,size);
    1091      540736 :   BLOCK_SIGINT_END;
    1092      539756 :   if (!tmp) pari_err(e_MEM);
    1093      539756 :   return tmp;
    1094             : }
    1095             : INLINE void*
    1096       34024 : pari_calloc(size_t size)
    1097             : {
    1098       34024 :   void *t = pari_malloc(size);
    1099       34024 :   memset(t, 0, size); return t;
    1100             : }
    1101             : INLINE GEN
    1102        4243 : cgetalloc(long t, size_t l)
    1103             : {
    1104        4243 :   GEN x = (GEN)pari_malloc(l * sizeof(long));
    1105        4243 :   x[0] = evaltyp(t) | evallg(l); return x;
    1106             : }
    1107             : 
    1108             : /*******************************************************************/
    1109             : /*                                                                 */
    1110             : /*                       GARBAGE COLLECTION                        */
    1111             : /*                                                                 */
    1112             : /*******************************************************************/
    1113             : /* copy integer x as if we had avma = av */
    1114             : INLINE GEN
    1115  3532093328 : icopy_avma(GEN x, pari_sp av)
    1116             : {
    1117  3532093328 :   long i = lgefint(x), lx = i;
    1118  3532093328 :   GEN y = ((GEN)av) - i;
    1119  3532093328 :   while (--i > 0) y[i] = x[i];
    1120  3532093328 :   y[0] = evaltyp(t_INT)|evallg(lx);
    1121  3531820863 :   return y;
    1122             : }
    1123             : /* copy leaf x as if we had avma = av */
    1124             : INLINE GEN
    1125   150796802 : leafcopy_avma(GEN x, pari_sp av)
    1126             : {
    1127   150796802 :   long i = lg(x);
    1128   150796802 :   GEN y = ((GEN)av) - i;
    1129   150796802 :   while (--i > 0) y[i] = x[i];
    1130   150796802 :   y[0] = x[0] & (~CLONEBIT);
    1131   150796802 :   return y;
    1132             : }
    1133             : INLINE GEN
    1134   614391368 : gerepileuptoleaf(pari_sp av, GEN x)
    1135             : {
    1136             :   long lx;
    1137             :   GEN q;
    1138             : 
    1139   614391368 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1140   615354493 :   lx = lg(x);
    1141   615354493 :   q = ((GEN)av) - lx;
    1142   615354493 :   avma = (pari_sp)q;
    1143   615354493 :   while (--lx >= 0) q[lx] = x[lx];
    1144   615354493 :   return q;
    1145             : }
    1146             : INLINE GEN
    1147  1139248989 : gerepileuptoint(pari_sp av, GEN x)
    1148             : {
    1149  1139248989 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1150  1021505911 :   avma = (pari_sp)icopy_avma(x, av);
    1151  1022240066 :   return (GEN)avma;
    1152             : }
    1153             : INLINE GEN
    1154   718828958 : gerepileupto(pari_sp av, GEN x)
    1155             : {
    1156   718828958 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1157   628162700 :   switch(typ(x))
    1158             :   { /* non-default = !is_recursive_t(tq) */
    1159   213557995 :     case t_INT: return gerepileuptoint(av, x);
    1160             :     case t_REAL:
    1161             :     case t_STR:
    1162   129710792 :     case t_VECSMALL: return gerepileuptoleaf(av,x);
    1163             :     default:
    1164             :       /* NB: x+i --> ((long)x) + i*sizeof(long) */
    1165   284893913 :       return gerepile(av, (pari_sp) (x+lg(x)), x);
    1166             :   }
    1167             : }
    1168             : 
    1169             : /* gerepileupto(av, gcopy(x)) */
    1170             : INLINE GEN
    1171    38030265 : gerepilecopy(pari_sp av, GEN x)
    1172             : {
    1173    38030265 :   if (is_recursive_t(typ(x)))
    1174             :   {
    1175    33773842 :     GENbin *p = copy_bin(x);
    1176    33773858 :     avma = av; return bin_copy(p);
    1177             :   }
    1178             :   else
    1179             :   {
    1180     4256427 :     avma = av;
    1181     4256427 :     if (x < (GEN)av) {
    1182     2838054 :       if (x < (GEN)pari_mainstack->bot) new_chunk(lg(x));
    1183     2838054 :       x = leafcopy_avma(x, av);
    1184     2838058 :       avma = (pari_sp)x;
    1185             :     } else
    1186     1418373 :       x = leafcopy(x);
    1187     4256432 :     return x;
    1188             :   }
    1189             : }
    1190             : 
    1191             : /* Takes an array of pointers to GENs, of length n. Copies all
    1192             :  * objects to contiguous locations and cleans up the stack between
    1193             :  * av and avma. */
    1194             : INLINE void
    1195      132769 : gerepilemany(pari_sp av, GEN* gptr[], int n)
    1196             : {
    1197             :   int i;
    1198      132769 :   for (i=0; i<n; i++) *gptr[i] = (GEN)copy_bin(*gptr[i]);
    1199      132769 :   avma = av;
    1200      132769 :   for (i=0; i<n; i++) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1201      132769 : }
    1202             : 
    1203             : INLINE void
    1204     7114739 : gerepileall(pari_sp av, int n, ...)
    1205             : {
    1206             :   int i;
    1207     7114739 :   va_list a; va_start(a, n);
    1208     7114739 :   if (n < 10)
    1209             :   {
    1210             :     GEN *gptr[10];
    1211    20600946 :     for (i=0; i<n; i++)
    1212    13486253 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1213     7114693 :     avma = av;
    1214     7114693 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1215             : 
    1216             :   }
    1217             :   else
    1218             :   {
    1219           0 :     GEN **gptr = (GEN**)  pari_malloc(n*sizeof(GEN*));
    1220           0 :     for (i=0; i<n; i++)
    1221           0 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1222           0 :     avma = av;
    1223           0 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1224           0 :     pari_free(gptr);
    1225             :   }
    1226     7114681 :   va_end(a);
    1227     7114681 : }
    1228             : 
    1229             : INLINE void
    1230           8 : gerepilecoeffs(pari_sp av, GEN x, int n)
    1231             : {
    1232             :   int i;
    1233           8 :   for (i=0; i<n; i++) gel(x,i) = (GEN)copy_bin(gel(x,i));
    1234           8 :   avma = av;
    1235           8 :   for (i=0; i<n; i++) gel(x,i) = bin_copy((GENbin*)x[i]);
    1236           8 : }
    1237             : 
    1238             : /* p from copy_bin. Copy p->x back to stack, then destroy p */
    1239             : INLINE GEN
    1240    47674352 : bin_copy(GENbin *p)
    1241             : {
    1242             :   GEN x, y, base;
    1243             :   long dx, len;
    1244             : 
    1245    47674352 :   x   = p->x; if (!x) { pari_free(p); return gen_0; }
    1246    47667512 :   len = p->len;
    1247    47667512 :   base= p->base; dx = x - base;
    1248    47667512 :   y = (GEN)memcpy((void*)new_chunk(len), (void*)GENbinbase(p), len*sizeof(long));
    1249    47667497 :   y += dx;
    1250    47667497 :   p->rebase(y, ((ulong)y-(ulong)x));
    1251    47667513 :   pari_free(p); return y;
    1252             : }
    1253             : 
    1254             : INLINE GEN
    1255    95342036 : GENbinbase(GENbin *p) { return (GEN)(p + 1); }
    1256             : 
    1257             : INLINE void
    1258    27713720 : cgiv(GEN x)
    1259             : {
    1260    27713720 :   pari_sp av = (pari_sp)(x+lg(x));
    1261    27713720 :   if (isonstack((GEN)av)) avma = av;
    1262    27714023 : }
    1263             : 
    1264             : INLINE void
    1265     1240586 : killblock(GEN x) { gunclone(x); }
    1266             : 
    1267             : INLINE int
    1268    23729374 : is_universal_constant(GEN x) { return (x >= gen_0 && x <= ghalf); }
    1269             : 
    1270             : /*******************************************************************/
    1271             : /*                                                                 */
    1272             : /*                    CONVERSION / ASSIGNMENT                      */
    1273             : /*                                                                 */
    1274             : /*******************************************************************/
    1275             : /* z is a type which may be a t_COMPLEX component (not a t_QUAD) */
    1276             : INLINE GEN
    1277     2814088 : cxcompotor(GEN z, long prec)
    1278             : {
    1279     2814088 :   switch(typ(z))
    1280             :   {
    1281     1474266 :     case t_INT:  return itor(z, prec);
    1282      134134 :     case t_FRAC: return fractor(z, prec);
    1283     1205688 :     case t_REAL: return rtor(z, prec);
    1284           0 :     default: pari_err_TYPE("cxcompotor",z);
    1285             :              return NULL; /* LCOV_EXCL_LINE */
    1286             :   }
    1287             : }
    1288             : INLINE GEN
    1289     1399567 : cxtofp(GEN x, long prec)
    1290     1399567 : { retmkcomplex(cxcompotor(gel(x,1),prec), cxcompotor(gel(x,2),prec)); }
    1291             : 
    1292             : INLINE double
    1293    18269173 : gtodouble(GEN x)
    1294             : {
    1295    18269173 :   if (typ(x)!=t_REAL) {
    1296     3436200 :     pari_sp av = avma;
    1297     3436200 :     x = gtofp(x, DEFAULTPREC);
    1298     3436200 :     if (typ(x)!=t_REAL) pari_err_TYPE("gtodouble [t_REAL expected]", x);
    1299     3436200 :     avma = av;
    1300             :   }
    1301    18269173 :   return rtodbl(x);
    1302             : }
    1303             : INLINE long
    1304    68165904 : gtos(GEN x) {
    1305    68165904 :   if (typ(x) != t_INT) pari_err_TYPE("gtos [integer expected]",x);
    1306    68165897 :   return itos(x);
    1307             : }
    1308             : 
    1309             : INLINE ulong
    1310      117417 : gtou(GEN x) {
    1311      117417 :   if (typ(x) != t_INT || signe(x)<0)
    1312           0 :     pari_err_TYPE("gtou [integer >=0 expected]",x);
    1313      117724 :   return itou(x);
    1314             : }
    1315             : 
    1316             : INLINE GEN
    1317    20615789 : absfrac(GEN x)
    1318             : {
    1319    20615789 :   GEN y = cgetg(3, t_FRAC);
    1320    20615789 :   gel(y,1) = absi(gel(x,1));
    1321    20615789 :   gel(y,2) = icopy(gel(x,2)); return y;
    1322             : }
    1323             : INLINE GEN
    1324       32329 : absfrac_shallow(GEN x)
    1325       32329 : { return signe(gel(x,1))>0? x: mkfrac(negi(gel(x,1)), gel(x,2)); }
    1326             : INLINE GEN
    1327     7129113 : Q_abs(GEN x) { return (typ(x) == t_INT)? absi(x): absfrac(x); }
    1328             : INLINE GEN
    1329      106020 : Q_abs_shallow(GEN x)
    1330      106020 : { return (typ(x) == t_INT)? absi_shallow(x): absfrac_shallow(x); }
    1331             : INLINE GEN
    1332         322 : R_abs_shallow(GEN x)
    1333         322 : { return (typ(x) == t_FRAC)? absfrac_shallow(x): mpabs_shallow(x); }
    1334             : INLINE GEN
    1335           0 : R_abs(GEN x)
    1336           0 : { return (typ(x) == t_FRAC)? absfrac(x): mpabs(x); }
    1337             : 
    1338             : /* Force z to be of type real/complex with floating point components */
    1339             : INLINE GEN
    1340    25616411 : gtofp(GEN z, long prec)
    1341             : {
    1342    25616411 :   switch(typ(z))
    1343             :   {
    1344    15519421 :     case t_INT:  return itor(z, prec);
    1345     4261085 :     case t_FRAC: return fractor(z, prec);
    1346     4655903 :     case t_REAL: return rtor(z, prec);
    1347             :     case t_COMPLEX: {
    1348     1180002 :       GEN a = gel(z,1), b = gel(z,2);
    1349     1180002 :       if (isintzero(b)) return cxcompotor(a, prec);
    1350     1177931 :       if (isintzero(a)) {
    1351        1893 :         GEN y = cgetg(3, t_COMPLEX);
    1352        1893 :         b = cxcompotor(b, prec);
    1353        1893 :         gel(y,1) = real_0_bit(expo(b) - prec2nbits(prec));
    1354        1893 :         gel(y,2) = b; return y;
    1355             :       }
    1356     1176038 :       return cxtofp(z, prec);
    1357             :     }
    1358           0 :     case t_QUAD: return quadtofp(z, prec);
    1359           0 :     default: pari_err_TYPE("gtofp",z);
    1360             :              return NULL; /* LCOV_EXCL_LINE */
    1361             :   }
    1362             : }
    1363             : /* Force z to be of type real / int */
    1364             : INLINE GEN
    1365       22400 : gtomp(GEN z, long prec)
    1366             : {
    1367       22400 :   switch(typ(z))
    1368             :   {
    1369          14 :     case t_INT:  return z;
    1370       22386 :     case t_FRAC: return fractor(z, prec);
    1371           0 :     case t_REAL: return rtor(z, prec);
    1372           0 :     case t_QUAD: z = quadtofp(z, prec);
    1373           0 :                  if (typ(z) == t_REAL) return z;
    1374           0 :     default: pari_err_TYPE("gtomp",z);
    1375             :              return NULL; /* LCOV_EXCL_LINE */
    1376             :   }
    1377             : }
    1378             : 
    1379             : INLINE GEN
    1380      637793 : RgX_gtofp(GEN x, long prec)
    1381             : {
    1382             :   long l;
    1383      637793 :   GEN y = cgetg_copy(x, &l);
    1384      637793 :   while (--l > 1) gel(y,l) = gtofp(gel(x,l), prec);
    1385      637793 :   y[1] = x[1]; return y;
    1386             : }
    1387             : INLINE GEN
    1388     1054993 : RgC_gtofp(GEN x, long prec)
    1389     1054993 : { pari_APPLY_type(t_COL, gtofp(gel(x,i), prec)) }
    1390             : 
    1391             : INLINE GEN
    1392          42 : RgV_gtofp(GEN x, long prec)
    1393          42 : { pari_APPLY_type(t_VEC, gtofp(gel(x,i), prec)) }
    1394             : 
    1395             : INLINE GEN
    1396      119380 : RgM_gtofp(GEN x, long prec)
    1397      119380 : { pari_APPLY_same(RgC_gtofp(gel(x,i), prec)) }
    1398             : 
    1399             : INLINE GEN
    1400         560 : RgC_gtomp(GEN x, long prec)
    1401         560 : { pari_APPLY_type(t_COL, gtomp(gel(x,i), prec)) }
    1402             : 
    1403             : INLINE GEN
    1404          14 : RgM_gtomp(GEN x, long prec)
    1405          14 : { pari_APPLY_same(RgC_gtomp(gel(x,i), prec)) }
    1406             : 
    1407             : INLINE GEN
    1408        8443 : RgX_fpnorml2(GEN x, long prec)
    1409             : {
    1410        8443 :   pari_sp av = avma;
    1411        8443 :   return gerepileupto(av, gnorml2(RgX_gtofp(x, prec)));
    1412             : }
    1413             : INLINE GEN
    1414      155310 : RgC_fpnorml2(GEN x, long prec)
    1415             : {
    1416      155310 :   pari_sp av = avma;
    1417      155310 :   return gerepileupto(av, gnorml2(RgC_gtofp(x, prec)));
    1418             : }
    1419             : INLINE GEN
    1420        3222 : RgM_fpnorml2(GEN x, long prec)
    1421             : {
    1422        3222 :   pari_sp av = avma;
    1423        3222 :   return gerepileupto(av, gnorml2(RgM_gtofp(x, prec)));
    1424             : }
    1425             : 
    1426             : /* y a t_REAL */
    1427             : INLINE void
    1428      190202 : affgr(GEN x, GEN y)
    1429             : {
    1430             :   pari_sp av;
    1431      190202 :   switch(typ(x)) {
    1432        5992 :     case t_INT:  affir(x,y); break;
    1433      184210 :     case t_REAL: affrr(x,y); break;
    1434           0 :     case t_FRAC: rdiviiz(gel(x,1),gel(x,2), y); break;
    1435           0 :     case t_QUAD: av = avma; affgr(quadtofp(x,realprec(y)), y); avma = av; break;
    1436           0 :     default: pari_err_TYPE2("=",x,y);
    1437             :   }
    1438      190202 : }
    1439             : 
    1440             : INLINE GEN
    1441      185806 : affc_fixlg(GEN x, GEN res)
    1442             : {
    1443      185806 :   if (typ(x) == t_COMPLEX)
    1444             :   {
    1445      175630 :     affrr_fixlg(gel(x,1), gel(res,1));
    1446      175630 :     affrr_fixlg(gel(x,2), gel(res,2));
    1447             :   }
    1448             :   else
    1449             :   {
    1450       10176 :     avma = (pari_sp)(res+3);
    1451       10176 :     res = cgetr(realprec(gel(res,1)));
    1452       10176 :     affrr_fixlg(x, res);
    1453             :   }
    1454      185806 :   return res;
    1455             : }
    1456             : 
    1457             : INLINE GEN
    1458           0 : trunc_safe(GEN x) { long e; return gcvtoi(x,&e); }
    1459             : 
    1460             : /*******************************************************************/
    1461             : /*                                                                 */
    1462             : /*                          LENGTH CONVERSIONS                     */
    1463             : /*                                                                 */
    1464             : /*******************************************************************/
    1465             : INLINE long
    1466       25942 : ndec2nlong(long x) { return 1 + (long)((x)*(LOG2_10/BITS_IN_LONG)); }
    1467             : INLINE long
    1468       25460 : ndec2prec(long x) { return 2 + ndec2nlong(x); }
    1469             : INLINE long
    1470         482 : ndec2nbits(long x) { return ndec2nlong(x) << TWOPOTBITS_IN_LONG; }
    1471             : /* Fast implementation of ceil(x / (8*sizeof(long))); typecast to (ulong)
    1472             :  * to avoid overflow. Faster than 1 + ((x-1)>>TWOPOTBITS_IN_LONG)) :
    1473             :  *   addl, shrl instead of subl, sarl, addl */
    1474             : INLINE long
    1475     1182767 : nbits2nlong(long x) {
    1476     1182767 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1477             : }
    1478             : 
    1479             : INLINE long
    1480   248462737 : nbits2extraprec(long x) {
    1481   248462737 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1482             : }
    1483             : 
    1484             : /* Fast implementation of 2 + nbits2nlong(x) */
    1485             : INLINE long
    1486    90836106 : nbits2prec(long x) {
    1487    90836106 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1488             : }
    1489             : INLINE long
    1490     6560127 : nbits2lg(long x) {
    1491     6560127 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1492             : }
    1493             : /* ceil(x / sizeof(long)) */
    1494             : INLINE long
    1495     8700632 : nchar2nlong(long x) {
    1496     8700632 :   return (long)(((ulong)x+sizeof(long)-1) >> (TWOPOTBITS_IN_LONG-3L));
    1497             : }
    1498             : INLINE long
    1499  1090888219 : prec2nbits(long x) { return (x-2) * BITS_IN_LONG; }
    1500             : INLINE double
    1501      449414 : bit_accuracy_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1502             : INLINE double
    1503      231836 : prec2nbits_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1504             : INLINE long
    1505    26731779 : bit_prec(GEN x) { return prec2nbits(realprec(x)); }
    1506             : INLINE long
    1507   998874773 : bit_accuracy(long x) { return prec2nbits(x); }
    1508             : INLINE long
    1509       12162 : prec2ndec(long x) { return (long)prec2nbits_mul(x, LOG10_2); }
    1510             : INLINE long
    1511         186 : nbits2ndec(long x) { return (long)(x * LOG10_2); }
    1512             : INLINE long
    1513        1651 : precdbl(long x) {return (x - 1) << 1;}
    1514             : INLINE long
    1515  3183970158 : divsBIL(long n) { return n >> TWOPOTBITS_IN_LONG; }
    1516             : INLINE long
    1517  3147631426 : remsBIL(long n) { return n & (BITS_IN_LONG-1); }
    1518             : 
    1519             : /*********************************************************************/
    1520             : /**                                                                 **/
    1521             : /**                      OPERATIONS MODULO m                        **/
    1522             : /**                                                                 **/
    1523             : /*********************************************************************/
    1524             : /* Assume m > 0, more efficient if 0 <= a, b < m */
    1525             : 
    1526             : INLINE GEN
    1527    80361292 : Fp_red(GEN a, GEN m) { return modii(a, m); }
    1528             : INLINE GEN
    1529    82399857 : Fp_add(GEN a, GEN b, GEN m)
    1530             : {
    1531    82399857 :   pari_sp av=avma;
    1532    82399857 :   GEN p = addii(a,b);
    1533    82406587 :   long s = signe(p);
    1534    82406587 :   if (!s) return p; /* = gen_0 */
    1535    75404199 :   if (s > 0) /* general case */
    1536             :   {
    1537    75181016 :     GEN t = subii(p, m);
    1538    75236774 :     s = signe(t);
    1539    75236774 :     if (!s) { avma = av; return gen_0; }
    1540    69627754 :     if (s < 0) { avma = (pari_sp)p; return p; }
    1541    30744375 :     if (cmpii(t, m) < 0) return gerepileuptoint(av, t); /* general case ! */
    1542     1120038 :     p = remii(t, m);
    1543             :   }
    1544             :   else
    1545      223183 :     p = modii(p, m);
    1546     1343221 :   return gerepileuptoint(av, p);
    1547             : }
    1548             : INLINE GEN
    1549    72489466 : Fp_sub(GEN a, GEN b, GEN m)
    1550             : {
    1551    72489466 :   pari_sp av=avma;
    1552    72489466 :   GEN p = subii(a,b);
    1553    72661944 :   long s = signe(p);
    1554    72661944 :   if (!s) return p; /* = gen_0 */
    1555    68476717 :   if (s > 0)
    1556             :   {
    1557    33055645 :     if (cmpii(p, m) < 0) return p; /* general case ! */
    1558     1316064 :     p = remii(p, m);
    1559             :   }
    1560             :   else
    1561             :   {
    1562    35421072 :     GEN t = addii(p, m);
    1563    35400875 :     if (!s) { avma = av; return gen_0; }
    1564    35400875 :     if (s > 0) return gerepileuptoint(av, t); /* general case ! */
    1565    35400875 :     p = modii(t, m);
    1566             :   }
    1567    36749442 :   return gerepileuptoint(av, p);
    1568             : }
    1569             : INLINE GEN
    1570    12443643 : Fp_neg(GEN b, GEN m)
    1571             : {
    1572    12443643 :   pari_sp av = avma;
    1573    12443643 :   long s = signe(b);
    1574             :   GEN p;
    1575    12443643 :   if (!s) return gen_0;
    1576     9041858 :   if (s > 0)
    1577             :   {
    1578     8840244 :     p = subii(m, b);
    1579     8839852 :     if (signe(p) >= 0) return p; /* general case ! */
    1580       92376 :     p = modii(p, m);
    1581             :   } else
    1582      201614 :     p = remii(negi(b), m);
    1583      293990 :   return gerepileuptoint(av, p);
    1584             : }
    1585             : 
    1586             : INLINE GEN
    1587       20120 : Fp_halve(GEN a, GEN p)
    1588             : {
    1589       20120 :   if (mpodd(a)) a = addii(a,p);
    1590       20120 :   return shifti(a,-1);
    1591             : }
    1592             : 
    1593             : /* assume 0 <= u < p and ps2 = p>>1 */
    1594             : INLINE GEN
    1595    15169826 : Fp_center(GEN u, GEN p, GEN ps2)
    1596    15169826 : { return abscmpii(u,ps2)<=0? icopy(u): subii(u,p); }
    1597             : 
    1598             : /* x + y*z mod p */
    1599             : INLINE GEN
    1600     7878615 : Fp_addmul(GEN x, GEN y, GEN z, GEN p)
    1601             : {
    1602             :   pari_sp av;
    1603     7878615 :   if (!signe(y) || !signe(z)) return Fp_red(x, p);
    1604     7455551 :   if (!signe(x)) return Fp_mul(z,y, p);
    1605     7154683 :   av = avma;
    1606     7154683 :   return gerepileuptoint(av, modii(addii(x, mulii(y,z)), p));
    1607             : }
    1608             : 
    1609             : INLINE GEN
    1610    63587234 : Fp_mul(GEN a, GEN b, GEN m)
    1611             : {
    1612    63587234 :   pari_sp av=avma;
    1613             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1614    63587234 :   (void)new_chunk(lg(a)+lg(b)+(lg(m)<<1));
    1615    63596373 :   p = mulii(a,b);
    1616    63591127 :   avma = av; return modii(p,m);
    1617             : }
    1618             : INLINE GEN
    1619    62126399 : Fp_sqr(GEN a, GEN m)
    1620             : {
    1621    62126399 :   pari_sp av=avma;
    1622             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1623    62126399 :   (void)new_chunk((lg(a)+lg(m))<<1);
    1624    62377345 :   p = sqri(a);
    1625    62492435 :   avma = av; return remii(p,m); /*Use remii: p >= 0 */
    1626             : }
    1627             : INLINE GEN
    1628    80308991 : Fp_mulu(GEN a, ulong b, GEN m)
    1629             : {
    1630    80308991 :   long l = lgefint(m);
    1631    80308991 :   if (l == 3)
    1632             :   {
    1633    43084077 :     ulong mm = m[2];
    1634    43084077 :     return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1635             :   } else {
    1636    37224914 :     pari_sp av = avma;
    1637             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1638    37224914 :     (void)new_chunk(lg(a)+1+(l<<1));
    1639    37264946 :     p = muliu(a,b);
    1640    36928903 :     avma = av; return modii(p,m);
    1641             :   }
    1642             : }
    1643             : INLINE GEN
    1644           0 : Fp_muls(GEN a, long b, GEN m)
    1645             : {
    1646           0 :   long l = lgefint(m);
    1647           0 :   if (l == 3)
    1648             :   {
    1649           0 :     ulong mm = m[2];
    1650           0 :     if (b < 0)
    1651             :     {
    1652           0 :       ulong t = Fl_mul(umodiu(a, mm), -b, mm);
    1653           0 :       return t? utoipos(mm - t): gen_0;
    1654             :     }
    1655             :     else
    1656           0 :       return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1657             :   } else {
    1658           0 :     pari_sp av = avma;
    1659             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1660           0 :     (void)new_chunk(lg(a)+1+(l<<1));
    1661           0 :     p = mulis(a,b);
    1662           0 :     avma = av; return modii(p,m);
    1663             :   }
    1664             : }
    1665             : 
    1666             : INLINE GEN
    1667     8295711 : Fp_inv(GEN a, GEN m)
    1668             : {
    1669             :   GEN res;
    1670     8295711 :   if (! invmod(a,m,&res)) pari_err_INV("Fp_inv", mkintmod(res,m));
    1671     8295604 :   return res;
    1672             : }
    1673             : INLINE GEN
    1674      311688 : Fp_invsafe(GEN a, GEN m)
    1675             : {
    1676             :   GEN res;
    1677      311688 :   if (! invmod(a,m,&res)) return NULL;
    1678      311688 :   return res;
    1679             : }
    1680             : INLINE GEN
    1681     2313559 : Fp_div(GEN a, GEN b, GEN m)
    1682             : {
    1683     2313559 :   pari_sp av=avma;
    1684             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1685     2313559 :   (void)new_chunk(lg(a)+(lg(m)<<1));
    1686     2313559 :   p = mulii(a, Fp_inv(b,m));
    1687     2313559 :   avma = av; return modii(p,m);
    1688             : }
    1689             : 
    1690             : INLINE GEN
    1691      695521 : Flx_mulu(GEN x, ulong a, ulong p) { return Flx_Fl_mul(x,a%p,p); }
    1692             : 
    1693             : INLINE GEN
    1694           0 : get_F2x_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1695             : 
    1696             : INLINE long
    1697      447845 : get_F2x_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1698             : 
    1699             : INLINE long
    1700      121429 : get_F2x_degree(GEN T) { return typ(T)==t_VEC? F2x_degree(gel(T,2)): F2x_degree(T); }
    1701             : 
    1702             : INLINE GEN
    1703         280 : get_F2xqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1704             : 
    1705             : INLINE long
    1706      376026 : get_F2xqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1707             : 
    1708             : INLINE long
    1709      201243 : get_F2xqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1710             : 
    1711             : INLINE GEN
    1712     5987963 : get_Flx_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1713             : 
    1714             : INLINE long
    1715    16113507 : get_Flx_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1716             : 
    1717             : INLINE long
    1718    30084043 : get_Flx_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1719             : 
    1720             : INLINE GEN
    1721        1003 : get_FlxqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1722             : 
    1723             : INLINE long
    1724      356018 : get_FlxqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1725             : 
    1726             : INLINE long
    1727       90131 : get_FlxqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1728             : 
    1729             : INLINE GEN
    1730      541396 : get_FpX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1731             : 
    1732             : INLINE long
    1733     1772029 : get_FpX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1734             : 
    1735             : INLINE long
    1736     1829789 : get_FpX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1737             : 
    1738             : INLINE GEN
    1739      142588 : get_FpXQX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1740             : 
    1741             : INLINE long
    1742       51984 : get_FpXQX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1743             : 
    1744             : INLINE long
    1745        1848 : get_FpXQX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1746             : 
    1747             : /*******************************************************************/
    1748             : /*                                                                 */
    1749             : /*                        ADDMULII / SUBMULII                      */
    1750             : /*                                                                 */
    1751             : /*******************************************************************/
    1752             : /* x - y*z */
    1753             : INLINE GEN
    1754    13740827 : submulii(GEN x, GEN y, GEN z)
    1755             : {
    1756    13740827 :   long lx = lgefint(x), ly, lz;
    1757             :   pari_sp av;
    1758             :   GEN t;
    1759    13740827 :   if (lx == 2) { t = mulii(z,y); togglesign(t); return t; }
    1760    11906533 :   ly = lgefint(y);
    1761    11906533 :   if (ly == 2) return icopy(x);
    1762    10706658 :   lz = lgefint(z);
    1763    10706658 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1764    10706658 :   t = mulii(z, y);
    1765    10706658 :   avma = av; return subii(x,t);
    1766             : }
    1767             : /* y*z - x */
    1768             : INLINE GEN
    1769     2214407 : mulsubii(GEN y, GEN z, GEN x)
    1770             : {
    1771     2214407 :   long lx = lgefint(x), ly, lz;
    1772             :   pari_sp av;
    1773             :   GEN t;
    1774     2214407 :   if (lx == 2) return mulii(z,y);
    1775     1380044 :   ly = lgefint(y);
    1776     1380044 :   if (ly == 2) return negi(x);
    1777     1232765 :   lz = lgefint(z);
    1778     1232765 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1779     1232765 :   t = mulii(z, y);
    1780     1232765 :   avma = av; return subii(t,x);
    1781             : }
    1782             : 
    1783             : /* x - u*y */
    1784             : INLINE GEN
    1785        7371 : submuliu(GEN x, GEN y, ulong u)
    1786             : {
    1787             :   pari_sp av;
    1788        7371 :   long ly = lgefint(y);
    1789        7371 :   if (ly == 2) return icopy(x);
    1790        7371 :   av = avma;
    1791        7371 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1792        7371 :   y = mului(u,y);
    1793        7371 :   avma = av; return subii(x, y);
    1794             : }
    1795             : /* x + u*y */
    1796             : INLINE GEN
    1797        7371 : addmuliu(GEN x, GEN y, ulong u)
    1798             : {
    1799             :   pari_sp av;
    1800        7371 :   long ly = lgefint(y);
    1801        7371 :   if (ly == 2) return icopy(x);
    1802        7371 :   av = avma;
    1803        7371 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1804        7371 :   y = mului(u,y);
    1805        7371 :   avma = av; return addii(x, y);
    1806             : }
    1807             : /* x - u*y */
    1808             : INLINE GEN
    1809   114851997 : submuliu_inplace(GEN x, GEN y, ulong u)
    1810             : {
    1811             :   pari_sp av;
    1812   114851997 :   long ly = lgefint(y);
    1813   114851997 :   if (ly == 2) return x;
    1814    91273999 :   av = avma;
    1815    91273999 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1816    91273999 :   y = mului(u,y);
    1817    91273999 :   avma = av; return subii(x, y);
    1818             : }
    1819             : /* x + u*y */
    1820             : INLINE GEN
    1821   113553708 : addmuliu_inplace(GEN x, GEN y, ulong u)
    1822             : {
    1823             :   pari_sp av;
    1824   113553708 :   long ly = lgefint(y);
    1825   113553708 :   if (ly == 2) return x;
    1826    90905382 :   av = avma;
    1827    90905382 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1828    90905382 :   y = mului(u,y);
    1829    90905382 :   avma = av; return addii(x, y);
    1830             : }
    1831             : /* ux + vy */
    1832             : INLINE GEN
    1833    28202199 : lincombii(GEN u, GEN v, GEN x, GEN y)
    1834             : {
    1835    28202199 :   long lx = lgefint(x), ly;
    1836             :   GEN p1, p2;
    1837             :   pari_sp av;
    1838    28202199 :   if (lx == 2) return mulii(v,y);
    1839    17060806 :   ly = lgefint(y);
    1840    17060806 :   if (ly == 2) return mulii(u,x);
    1841    15615123 :   av = avma; (void)new_chunk(lx+ly+lgefint(u)+lgefint(v)); /* HACK */
    1842    15615123 :   p1 = mulii(u,x);
    1843    15615123 :   p2 = mulii(v,y);
    1844    15615123 :   avma = av; return addii(p1,p2);
    1845             : }
    1846             : 
    1847             : /*******************************************************************/
    1848             : /*                                                                 */
    1849             : /*                          GEN SUBTYPES                           */
    1850             : /*                                                                 */
    1851             : /*******************************************************************/
    1852             : 
    1853             : INLINE int
    1854  1025172646 : is_const_t(long t) { return (t < t_POLMOD); }
    1855             : INLINE int
    1856        5297 : is_extscalar_t(long t) { return (t <= t_POL); }
    1857             : INLINE int
    1858     1018776 : is_intreal_t(long t) { return (t <= t_REAL); }
    1859             : INLINE int
    1860   371005598 : is_matvec_t(long t) { return (t >= t_VEC && t <= t_MAT); }
    1861             : INLINE int
    1862    50581159 : is_noncalc_t(long tx) { return (tx) >= t_LIST; }
    1863             : INLINE int
    1864      763658 : is_rational_t(long t) { return (t == t_INT || t == t_FRAC); }
    1865             : INLINE int
    1866      278793 : is_real_t(long t) { return (t == t_INT || t == t_REAL || t == t_FRAC); }
    1867             : INLINE int
    1868  2659925269 : is_recursive_t(long t) { return lontyp[t]; }
    1869             : INLINE int
    1870   171910916 : is_scalar_t(long t) { return (t < t_POL); }
    1871             : INLINE int
    1872      872547 : is_vec_t(long t) { return (t == t_VEC || t == t_COL); }
    1873             : 
    1874             : /*******************************************************************/
    1875             : /*                                                                 */
    1876             : /*                         TRANSCENDENTAL                          */
    1877             : /*                                                                 */
    1878             : /*******************************************************************/
    1879             : INLINE GEN
    1880    17378532 : sqrtr(GEN x) {
    1881    17378532 :   long s = signe(x);
    1882    17378532 :   if (s == 0) return real_0_bit(expo(x) >> 1);
    1883    17344866 :   if (s >= 0) return sqrtr_abs(x);
    1884       26568 :   retmkcomplex(gen_0, sqrtr_abs(x));
    1885             : }
    1886             : INLINE GEN
    1887           0 : cbrtr_abs(GEN x) { return sqrtnr_abs(x, 3); }
    1888             : INLINE GEN
    1889           0 : cbrtr(GEN x) {
    1890           0 :   long s = signe(x);
    1891             :   GEN r;
    1892           0 :   if (s == 0) return real_0_bit(expo(x) / 3);
    1893           0 :   r = cbrtr_abs(x);
    1894           0 :   if (s < 0) togglesign(r);
    1895           0 :   return r;
    1896             : }
    1897             : INLINE GEN
    1898      286043 : sqrtnr(GEN x, long n) {
    1899      286043 :   long s = signe(x);
    1900             :   GEN r;
    1901      286043 :   if (s == 0) return real_0_bit(expo(x) / n);
    1902      286043 :   r = sqrtnr_abs(x, n);
    1903      286043 :   if (s < 0) pari_err_IMPL("sqrtnr for x < 0");
    1904      286043 :   return r;
    1905             : }
    1906             : INLINE long
    1907      211470 : logint(GEN B, GEN y) { return logintall(B,y,NULL); }
    1908             : INLINE ulong
    1909     4462602 : ulogint(ulong B, ulong y)
    1910             : {
    1911             :   ulong r;
    1912             :   long e;
    1913     4462602 :   if (y == 2) return expu(B);
    1914     4413562 :   r = y;
    1915    14917070 :   for (e=1;; e++)
    1916             :   { /* here, r = y^e, r2 = y^(e-1) */
    1917    14917070 :     if (r >= B) return r == B? e: e-1;
    1918    10503508 :     r = umuluu_or_0(y, r);
    1919    10503508 :     if (!r) return e;
    1920    10503508 :   }
    1921             : }
    1922             : 
    1923             : /*******************************************************************/
    1924             : /*                                                                 */
    1925             : /*                         MISCELLANEOUS                           */
    1926             : /*                                                                 */
    1927             : /*******************************************************************/
    1928     1018699 : INLINE int ismpzero(GEN x) { return is_intreal_t(typ(x)) && !signe(x); }
    1929   525837504 : INLINE int isintzero(GEN x) { return typ(x) == t_INT && !signe(x); }
    1930     6816158 : INLINE int isint1(GEN x) { return typ(x)==t_INT && equali1(x); }
    1931        4473 : INLINE int isintm1(GEN x){ return typ(x)==t_INT && equalim1(x);}
    1932   313457979 : INLINE int equali1(GEN n)
    1933   313457979 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(1)) && n[2] == 1; }
    1934    52404721 : INLINE int equalim1(GEN n)
    1935    52404721 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(-1)) && n[2] == 1; }
    1936             : /* works only for POSITIVE integers */
    1937  1306461611 : INLINE int is_pm1(GEN n)
    1938  1306461611 : { return lgefint(n) == 3 && n[2] == 1; }
    1939   183374160 : INLINE int is_bigint(GEN n)
    1940   183374160 : { long l = lgefint(n); return l > 3 || (l == 3 && (n[2] & HIGHBIT)); }
    1941             : 
    1942  2101078799 : INLINE int odd(long x) { return x & 1; }
    1943    28916422 : INLINE int both_odd(long x, long y) { return x & y & 1; }
    1944             : 
    1945             : INLINE int
    1946  2500474590 : isonstack(GEN x)
    1947  5000949180 : { return ((pari_sp)x >= pari_mainstack->bot
    1948  2500474590 :        && (pari_sp)x <  pari_mainstack->top); }
    1949             : 
    1950             : /* assume x != 0 and x t_REAL, return an approximation to log2(|x|) */
    1951             : INLINE double
    1952    18165626 : dbllog2r(GEN x)
    1953    18165626 : { return log2((double)(ulong)x[2]) + (double)(expo(x) - (BITS_IN_LONG-1)); }
    1954             : 
    1955             : INLINE GEN
    1956      280417 : mul_content(GEN cx, GEN cy)
    1957             : {
    1958      280417 :   if (!cx) return cy;
    1959       96348 :   if (!cy) return cx;
    1960       71300 :   return gmul(cx,cy);
    1961             : }
    1962             : INLINE GEN
    1963         833 : inv_content(GEN c) { return c? ginv(c): NULL; }
    1964             : INLINE GEN
    1965     1559076 : mul_denom(GEN dx, GEN dy)
    1966             : {
    1967     1559076 :   if (!dx) return dy;
    1968     1041331 :   if (!dy) return dx;
    1969      320131 :   return mulii(dx,dy);
    1970             : }
    1971             : 
    1972             : /* POLYNOMIALS */
    1973             : INLINE GEN
    1974    17565498 : constant_coeff(GEN x) { return signe(x)? gel(x,2): gen_0; }
    1975             : INLINE GEN
    1976    80832110 : leading_coeff(GEN x) { return lg(x) == 2? gen_0: gel(x,lg(x)-1); }
    1977             : INLINE ulong
    1978      412332 : Flx_lead(GEN x) { return lg(x) == 2? 0: x[lg(x)-1]; }
    1979             : INLINE long
    1980  2796647332 : degpol(GEN x) { return lg(x)-3; }
    1981             : INLINE long
    1982  1375426464 : lgpol(GEN x) { return lg(x)-2; }
    1983             : INLINE long
    1984    97589681 : lgcols(GEN x) { return lg(gel(x,1)); }
    1985             : INLINE long
    1986    31351210 : nbrows(GEN x) { return lg(gel(x,1))-1; }
    1987             : INLINE GEN
    1988           0 : truecoeff(GEN x, long n) { return polcoeff0(x,n,-1); }
    1989             : 
    1990             : INLINE GEN
    1991      448521 : RgXQ_mul(GEN y, GEN x, GEN T) { return RgX_rem(RgX_mul(y, x), T); }
    1992             : INLINE GEN
    1993      279194 : RgXQ_sqr(GEN x, GEN T) { return RgX_rem(RgX_sqr(x), T); }
    1994             : 
    1995             : INLINE GEN
    1996      143577 : ZXQ_mul(GEN y, GEN x, GEN T) { return ZX_rem(ZX_mul(y, x), T); }
    1997             : INLINE GEN
    1998       35042 : ZXQ_sqr(GEN x, GEN T) { return ZX_rem(ZX_sqr(x), T); }
    1999             : 
    2000             : INLINE GEN
    2001    64002032 : RgX_copy(GEN x)
    2002             : {
    2003             :   long lx, i;
    2004    64002032 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
    2005    64002044 :   for (i = 2; i<lx; i++) gel(y,i) = gcopy(gel(x,i));
    2006    64002038 :   return y;
    2007             : }
    2008             : /* have to use ulong to avoid silly warnings from gcc "assuming signed
    2009             :  * overflow does not occur" */
    2010             : INLINE GEN
    2011     2296435 : RgX_coeff(GEN x, long n)
    2012             : {
    2013     2296435 :   ulong l = lg(x);
    2014     2296435 :   return (n < 0 || ((ulong)n+3) > l)? gen_0: gel(x,n+2);
    2015             : }
    2016             : INLINE GEN
    2017      344785 : RgX_renormalize(GEN x) { return RgX_renormalize_lg(x, lg(x)); }
    2018             : INLINE GEN
    2019     6552749 : RgX_div(GEN x, GEN y) { return RgX_divrem(x,y,NULL); }
    2020             : INLINE GEN
    2021        1792 : RgXQX_div(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,NULL); }
    2022             : INLINE GEN
    2023       53655 : RgXQX_rem(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,ONLY_REM); }
    2024             : INLINE GEN
    2025      824662 : FpX_div(GEN x, GEN y, GEN p) { return FpX_divrem(x,y,p, NULL); }
    2026             : INLINE GEN
    2027     3627356 : Flx_div(GEN x, GEN y, ulong p) { return Flx_divrem(x,y,p, NULL); }
    2028             : INLINE GEN
    2029     2989974 : F2x_div(GEN x, GEN y) { return F2x_divrem(x,y, NULL); }
    2030             : INLINE GEN
    2031           0 : FpV_FpC_mul(GEN x, GEN y, GEN p) { return FpV_dotproduct(x,y,p); }
    2032             : INLINE GEN
    2033    45170757 : pol0_Flx(long sv) { return mkvecsmall(sv); }
    2034             : INLINE GEN
    2035    18551251 : pol1_Flx(long sv) { return mkvecsmall2(sv, 1); }
    2036             : INLINE GEN
    2037    18111399 : polx_Flx(long sv) { return mkvecsmall3(sv, 0, 1); }
    2038             : INLINE GEN
    2039           0 : zero_zx(long sv) { return zero_Flx(sv); }
    2040             : INLINE GEN
    2041           0 : polx_zx(long sv) { return polx_Flx(sv); }
    2042             : INLINE GEN
    2043           0 : zx_shift(GEN x, long n) { return Flx_shift(x,n); }
    2044             : INLINE GEN
    2045           0 : zx_renormalize(GEN x, long l) { return Flx_renormalize(x,l); }
    2046             : INLINE GEN
    2047        1390 : zero_F2x(long sv) { return zero_Flx(sv); }
    2048             : INLINE GEN
    2049    11508299 : pol0_F2x(long sv) { return pol0_Flx(sv); }
    2050             : INLINE GEN
    2051     2826852 : pol1_F2x(long sv) { return pol1_Flx(sv); }
    2052             : INLINE GEN
    2053      672220 : polx_F2x(long sv) { return mkvecsmall2(sv, 2); }
    2054             : INLINE int
    2055      819573 : F2x_equal1(GEN x) { return Flx_equal1(x); }
    2056             : INLINE int
    2057     3546252 : F2x_equal(GEN V, GEN W) { return Flx_equal(V,W); }
    2058             : INLINE GEN
    2059    69863969 : F2x_copy(GEN x) { return leafcopy(x); }
    2060             : INLINE GEN
    2061           0 : F2v_copy(GEN x) { return leafcopy(x); }
    2062             : INLINE GEN
    2063     2324406 : Flv_copy(GEN x) { return leafcopy(x); }
    2064             : INLINE GEN
    2065    74947426 : Flx_copy(GEN x) { return leafcopy(x); }
    2066             : INLINE GEN
    2067     1658614 : vecsmall_copy(GEN x) { return leafcopy(x); }
    2068             : INLINE int
    2069     4752446 : Flx_equal1(GEN x) { return degpol(x)==0 && x[2] == 1; }
    2070             : INLINE int
    2071       18426 : ZX_equal1(GEN x) { return degpol(x)==0 && equali1(gel(x,2)); }
    2072             : INLINE int
    2073     5404975 : ZX_is_monic(GEN x) { return equali1(leading_coeff(x)); }
    2074             : 
    2075             : INLINE GEN
    2076    45945686 : ZX_renormalize(GEN x, long lx)    { return ZXX_renormalize(x,lx); }
    2077             : INLINE GEN
    2078    58677033 : FpX_renormalize(GEN x, long lx)   { return ZXX_renormalize(x,lx); }
    2079             : INLINE GEN
    2080     1031928 : FpXX_renormalize(GEN x, long lx)  { return ZXX_renormalize(x,lx); }
    2081             : INLINE GEN
    2082     1146421 : FpXQX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
    2083             : INLINE GEN
    2084   123270380 : F2x_renormalize(GEN x, long lx)   { return Flx_renormalize(x,lx); }
    2085             : INLINE GEN
    2086        8604 : F2v_to_F2x(GEN x, long sv) {
    2087        8604 :   GEN y = leafcopy(x);
    2088        8604 :   y[1] = sv; F2x_renormalize(y, lg(y)); return y;
    2089             : }
    2090             : 
    2091             : INLINE long
    2092         455 : sturm(GEN x) { return sturmpart(x, NULL, NULL); }
    2093             : 
    2094             : INLINE long
    2095        2408 : gval(GEN x, long v) {
    2096        2408 :   pari_sp av = avma;
    2097        2408 :   long n = gvaluation(x, pol_x(v));
    2098        2408 :   avma = av; return n;
    2099             : }
    2100             : 
    2101             : INLINE void
    2102      468309 : RgX_shift_inplace_init(long v)
    2103      468309 : { if (v) (void)cgetg(v, t_VECSMALL); }
    2104             : /* shift polynomial in place. assume v free cells have been left before x */
    2105             : INLINE GEN
    2106      468309 : RgX_shift_inplace(GEN x, long v)
    2107             : {
    2108             :   long i, lx;
    2109             :   GEN y, z;
    2110      468309 :   if (!v) return x;
    2111      253227 :   lx = lg(x);
    2112      253227 :   if (lx == 2) return x;
    2113      253227 :   y = x + v;
    2114      253227 :   z = x + lx;
    2115             :   /* stackdummy from normalizepol: move it up */
    2116      253227 :   if (lg(z) != v) x[lx + v] = z[0];
    2117      253227 :   for (i = lx-1; i >= 2; i--) gel(y,i) = gel(x,i);
    2118      253227 :   for (i = v+1;  i >= 2; i--) gel(x,i) = gen_0;
    2119             :   /* leave x[1] alone: it is correct */
    2120      253227 :   x[0] = evaltyp(t_POL) | evallg(lx+v); return x;
    2121             : }
    2122             : 
    2123             : 
    2124             : /* LINEAR ALGEBRA */
    2125             : INLINE GEN
    2126      404264 : zv_to_ZV(GEN x) { return vecsmall_to_vec(x); }
    2127             : INLINE GEN
    2128      603303 : zc_to_ZC(GEN x) { return vecsmall_to_col(x); }
    2129             : INLINE GEN
    2130      390136 : ZV_to_zv(GEN x) { return vec_to_vecsmall(x); }
    2131             : INLINE GEN
    2132           0 : zx_to_zv(GEN x, long N) { return Flx_to_Flv(x,N); }
    2133             : INLINE GEN
    2134           0 : zv_to_zx(GEN x, long sv) { return Flv_to_Flx(x,sv); }
    2135             : INLINE GEN
    2136           0 : zm_to_zxV(GEN x, long sv) { return Flm_to_FlxV(x,sv); }
    2137             : INLINE GEN
    2138           0 : zero_zm(long x, long y) { return zero_Flm(x,y); }
    2139             : INLINE GEN
    2140    17740991 : zero_zv(long x) { return zero_Flv(x); }
    2141             : INLINE GEN
    2142         168 : zm_transpose(GEN x) { return Flm_transpose(x); }
    2143             : INLINE GEN
    2144           0 : zm_copy(GEN x) { return Flm_copy(x); }
    2145             : INLINE GEN
    2146     2014580 : zv_copy(GEN x) { return Flv_copy(x); }
    2147             : INLINE GEN
    2148           0 : zm_row(GEN x, long i) { return Flm_row(x,i); }
    2149             : 
    2150             : INLINE GEN
    2151      839660 : ZC_hnfrem(GEN x, GEN y) { return ZC_hnfremdiv(x,y,NULL); }
    2152             : INLINE GEN
    2153       35611 : ZM_hnfrem(GEN x, GEN y) { return ZM_hnfdivrem(x,y,NULL); }
    2154             : INLINE GEN
    2155     1204188 : ZM_lll(GEN x, double D, long f) { return ZM_lll_norms(x,D,f,NULL); }
    2156             : INLINE void
    2157     9936305 : RgM_dimensions(GEN x, long *m, long *n) { *n = lg(x)-1; *m = *n? nbrows(x): 0; }
    2158             : INLINE GEN
    2159     6812015 : RgM_shallowcopy(GEN x)
    2160             : {
    2161             :   long l;
    2162     6812015 :   GEN y = cgetg_copy(x, &l);
    2163     6812015 :   while (--l > 0) gel(y,l) = leafcopy(gel(x,l));
    2164     6812015 :   return y;
    2165             : }
    2166             : INLINE GEN
    2167         362 : F2m_copy(GEN x) { return RgM_shallowcopy(x); }
    2168             : 
    2169             : INLINE GEN
    2170     1338568 : Flm_copy(GEN x) { return RgM_shallowcopy(x); }
    2171             : 
    2172             : /* divisibility: return 1 if y[i] | x[i] for all i, 0 otherwise. Assume
    2173             :  * x,y are ZV of the same length */
    2174             : INLINE int
    2175       23198 : ZV_dvd(GEN x, GEN y)
    2176             : {
    2177       23198 :   long i, l = lg(x);
    2178       36652 :   for (i=1; i < l; i++)
    2179       29519 :     if ( ! dvdii( gel(x,i), gel(y,i) ) ) return 0;
    2180        7133 :   return 1;
    2181             : }
    2182             : 
    2183             : /* Fq */
    2184             : INLINE GEN
    2185     2838007 : Fq_red(GEN x, GEN T, GEN p)
    2186     2838007 : { return typ(x)==t_INT? Fp_red(x,p): FpXQ_red(x,T,p); }
    2187             : INLINE GEN
    2188       43118 : Fq_to_FpXQ(GEN x, GEN T, GEN p /*unused*/)
    2189             : {
    2190             :   (void) p;
    2191       43118 :   return typ(x)==t_INT ? scalarpol(x, get_FpX_var(T)): x;
    2192             : }
    2193             : 
    2194             : INLINE GEN
    2195         833 : gener_Fq_local(GEN T, GEN p, GEN L)
    2196         833 : { return T? gener_FpXQ_local(T,p, L)
    2197         833 :           : pgener_Fp_local(p, L); }
    2198             : 
    2199             : /* FpXQX */
    2200             : INLINE GEN
    2201        4350 : FpXQX_div(GEN x, GEN y, GEN T, GEN p) { return FpXQX_divrem(x, y, T, p, NULL); }
    2202             : INLINE GEN
    2203       35405 : FlxqX_div(GEN x, GEN y, GEN T, ulong p) { return FlxqX_divrem(x, y, T, p, NULL); }
    2204             : INLINE GEN
    2205       33124 : F2xqX_div(GEN x, GEN y, GEN T) { return F2xqX_divrem(x, y, T, NULL); }
    2206             : 
    2207             : /* FqX */
    2208             : INLINE GEN
    2209       27419 : FqX_red(GEN z, GEN T, GEN p) { return T? FpXQX_red(z, T, p): FpX_red(z, p); }
    2210             : INLINE GEN
    2211      903749 : FqX_add(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2212             : INLINE GEN
    2213       16438 : FqX_neg(GEN x,GEN T,GEN p) { return T? FpXX_neg(x,p): FpX_neg(x,p); }
    2214             : INLINE GEN
    2215        2380 : FqX_sub(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2216             : INLINE GEN
    2217      617109 : FqX_Fp_mul(GEN P, GEN u, GEN T, GEN p)
    2218      617109 : { return T? FpXX_Fp_mul(P, u, p): FpX_Fp_mul(P, u, p); }
    2219             : INLINE GEN
    2220      556098 : FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p)
    2221      556098 : { return typ(U)==t_INT ? FqX_Fp_mul(P, U, T, p): FpXQX_FpXQ_mul(P, U, T, p); }
    2222             : INLINE GEN
    2223       87452 : FqX_mul(GEN x, GEN y, GEN T, GEN p)
    2224       87452 : { return T? FpXQX_mul(x, y, T, p): FpX_mul(x, y, p); }
    2225             : INLINE GEN
    2226      459889 : FqX_mulu(GEN x, ulong y, GEN T, GEN p)
    2227      459889 : { return T? FpXX_mulu(x, y, p): FpX_mulu(x, y, p); }
    2228             : INLINE GEN
    2229        4760 : FqX_sqr(GEN x, GEN T, GEN p)
    2230        4760 : { return T? FpXQX_sqr(x, T, p): FpX_sqr(x, p); }
    2231             : INLINE GEN
    2232        1183 : FqX_powu(GEN x, ulong n, GEN T, GEN p)
    2233        1183 : { return T? FpXQX_powu(x, n, T, p): FpX_powu(x, n, p); }
    2234             : INLINE GEN
    2235        5005 : FqX_div(GEN x, GEN y, GEN T, GEN p)
    2236        5005 : { return T? FpXQX_divrem(x,y,T,p,NULL): FpX_divrem(x,y,p,NULL); }
    2237             : INLINE GEN
    2238        5605 : FqX_get_red(GEN S, GEN T, GEN p)
    2239        5605 : { return T? FpXQX_get_red(S,T,p): FpX_get_red(S,p); }
    2240             : INLINE GEN
    2241       47767 : FqX_rem(GEN x, GEN y, GEN T, GEN p)
    2242       47767 : { return T? FpXQX_rem(x,y,T,p): FpX_rem(x,y,p); }
    2243             : INLINE GEN
    2244           0 : FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2245           0 : { return T? FpXQX_divrem(x,y,T,p,z): FpX_divrem(x,y,p,z); }
    2246             : INLINE GEN
    2247        5957 : FqX_div_by_X_x(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2248        5957 : { return T? FpXQX_div_by_X_x(x,y,T,p,z): FpX_div_by_X_x(x,y,p,z); }
    2249             : INLINE GEN
    2250           0 : FqX_halfgcd(GEN P,GEN Q,GEN T,GEN p)
    2251           0 : {return T? FpXQX_halfgcd(P,Q,T,p): FpX_halfgcd(P,Q,p);}
    2252             : INLINE GEN
    2253      257593 : FqX_gcd(GEN P,GEN Q,GEN T,GEN p)
    2254      257593 : {return T? FpXQX_gcd(P,Q,T,p): FpX_gcd(P,Q,p);}
    2255             : INLINE GEN
    2256       85211 : FqX_extgcd(GEN P,GEN Q,GEN T,GEN p, GEN *U, GEN *V)
    2257       85211 : { return T? FpXQX_extgcd(P,Q,T,p,U,V): FpX_extgcd(P,Q,p,U,V); }
    2258             : INLINE GEN
    2259        2807 : FqX_normalize(GEN z, GEN T, GEN p) { return T? FpXQX_normalize(z, T, p): FpX_normalize(z, p); }
    2260             : INLINE GEN
    2261      269885 : FqX_deriv(GEN f, /*unused*/GEN T, GEN p) { (void)T; return FpXX_deriv(f, p); }
    2262             : INLINE GEN
    2263       72968 : FqX_factor(GEN f, GEN T, GEN p) { return T?FpXQX_factor(f, T, p): FpX_factor(f, p); }
    2264             : INLINE GEN
    2265        6391 : FqX_roots(GEN f, GEN T, GEN p) { return T?FpXQX_roots(f, T, p): FpX_roots(f, p); }
    2266             : INLINE GEN
    2267         175 : FqX_to_mod(GEN f, GEN T, GEN p) { return T?FpXQX_to_mod(f, T, p): FpX_to_mod(f, p); }
    2268             : 
    2269             : /*FqXQ*/
    2270             : INLINE GEN
    2271           0 : FqXQ_add(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2272           0 : { (void)S; return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2273             : INLINE GEN
    2274           0 : FqXQ_sub(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2275           0 : { (void)S; return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2276             : INLINE GEN
    2277           0 : FqXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p)
    2278           0 : { return T? FpXQXQ_div(x,y,S,T,p): FpXQ_div(x,y,S,p); }
    2279             : INLINE GEN
    2280           0 : FqXQ_inv(GEN x, GEN S, GEN T, GEN p)
    2281           0 : { return T? FpXQXQ_inv(x,S,T,p): FpXQ_inv(x,S,p); }
    2282             : INLINE GEN
    2283           0 : FqXQ_invsafe(GEN x, GEN S, GEN T, GEN p)
    2284           0 : { return T? FpXQXQ_invsafe(x,S,T,p): FpXQ_inv(x,S,p); }
    2285             : INLINE GEN
    2286       21018 : FqXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p)
    2287       21018 : { return T? FpXQXQ_mul(x,y,S,T,p): FpXQ_mul(x,y,S,p); }
    2288             : INLINE GEN
    2289           0 : FqXQ_sqr(GEN x, GEN S, GEN T, GEN p)
    2290           0 : { return T? FpXQXQ_sqr(x,S,T,p): FpXQ_sqr(x,S,p); }
    2291             : INLINE GEN
    2292           0 : FqXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p)
    2293           0 : { return T? FpXQXQ_pow(x,n,S,T,p): FpXQ_pow(x,n,S,p); }
    2294             : 
    2295             : /*FpXQ*/
    2296             : INLINE GEN
    2297           0 : FpXQ_add(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2298           0 : { (void)T; return FpX_add(x,y,p); }
    2299             : INLINE GEN
    2300           0 : FpXQ_sub(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2301           0 : { (void)T; return FpX_sub(x,y,p); }
    2302             : 
    2303             : /*Flxq*/
    2304             : INLINE GEN
    2305           0 : Flxq_add(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2306           0 : { (void)T; return Flx_add(x,y,p); }
    2307             : INLINE GEN
    2308           0 : Flxq_sub(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2309           0 : { (void)T; return Flx_sub(x,y,p); }
    2310             : 
    2311             : /* F2x */
    2312             : 
    2313             : INLINE ulong
    2314   168510094 : F2x_coeff(GEN x,long v)
    2315             : {
    2316   168510094 :    ulong u=(ulong)x[2+divsBIL(v)];
    2317   168510059 :    return (u>>remsBIL(v))&1UL;
    2318             : }
    2319             : 
    2320             : INLINE void
    2321     4165701 : F2x_clear(GEN x,long v)
    2322             : {
    2323     4165701 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2324     4165701 :    *u&=~(1UL<<remsBIL(v));
    2325     4165701 : }
    2326             : 
    2327             : INLINE void
    2328    38846381 : F2x_set(GEN x,long v)
    2329             : {
    2330    38846381 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2331    38847832 :    *u|=1UL<<remsBIL(v);
    2332    38852001 : }
    2333             : 
    2334             : INLINE void
    2335     1360820 : F2x_flip(GEN x,long v)
    2336             : {
    2337     1360820 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2338     1360820 :    *u^=1UL<<remsBIL(v);
    2339     1360820 : }
    2340             : 
    2341             : /* F2v */
    2342             : 
    2343             : INLINE ulong
    2344   161984813 : F2v_coeff(GEN x,long v) { return F2x_coeff(x,v-1); }
    2345             : 
    2346             : INLINE void
    2347     4165701 : F2v_clear(GEN x,long v) { F2x_clear(x,v-1); }
    2348             : 
    2349             : INLINE void
    2350    12561418 : F2v_set(GEN x,long v)   { F2x_set(x,v-1); }
    2351             : 
    2352             : INLINE void
    2353     1360820 : F2v_flip(GEN x,long v) { F2x_flip(x,v-1); }
    2354             : 
    2355             : /* F2m */
    2356             : 
    2357             : INLINE ulong
    2358    19319598 : F2m_coeff(GEN x, long a, long b) { return F2v_coeff(gel(x,b), a); }
    2359             : 
    2360             : INLINE void
    2361           0 : F2m_clear(GEN x, long a, long b) { F2v_clear(gel(x,b), a); }
    2362             : 
    2363             : INLINE void
    2364     2352087 : F2m_set(GEN x, long a, long b) { F2v_set(gel(x,b), a); }
    2365             : 
    2366             : INLINE void
    2367     1360820 : F2m_flip(GEN x, long a, long b) { F2v_flip(gel(x,b), a); }
    2368             : 
    2369             : /* ARITHMETIC */
    2370             : INLINE GEN
    2371        1029 : matpascal(long n) { return matqpascal(n, NULL); }
    2372             : INLINE long
    2373     2225197 : Z_issquare(GEN x) { return Z_issquareall(x, NULL); }
    2374             : INLINE long
    2375          14 : Z_ispower(GEN x, ulong k) { return Z_ispowerall(x, k, NULL); }
    2376             : INLINE GEN
    2377     5232718 : sqrti(GEN x) { return sqrtremi(x,NULL); }
    2378             : INLINE GEN
    2379     9494267 : gaddgs(GEN y, long s) { return gaddsg(s,y); }
    2380             : INLINE int
    2381       24100 : gcmpgs(GEN y, long s) { return -gcmpsg(s,y); }
    2382             : INLINE int
    2383       24353 : gequalgs(GEN y, long s) { return gequalsg(s,y); }
    2384             : INLINE GEN
    2385           0 : gmaxsg(long s, GEN y) { return gmaxgs(y,s); }
    2386             : INLINE GEN
    2387           0 : gminsg(long s, GEN y) { return gmings(y,s); }
    2388             : INLINE GEN
    2389     9762158 : gmulgs(GEN y, long s) { return gmulsg(s,y); }
    2390             : INLINE GEN
    2391      566569 : gsubgs(GEN y, long s) { return gaddgs(y, -s); }
    2392             : INLINE GEN
    2393      721827 : gdivsg(long s, GEN y) { return gdiv(stoi(s), y); }
    2394             : 
    2395             : /* x t_COMPLEX */
    2396             : INLINE GEN
    2397    10551012 : cxnorm(GEN x) { return gadd(gsqr(gel(x,1)), gsqr(gel(x,2))); }
    2398             : /* q t_QUAD */
    2399             : INLINE GEN
    2400         623 : quadnorm(GEN q)
    2401             : {
    2402         623 :   GEN X = gel(q,1), b = gel(X,3), c = gel(X,2);
    2403         623 :   GEN z, u = gel(q,3), v = gel(q,2);
    2404         623 :   if (typ(u) == t_INT && typ(v) == t_INT) /* generic case */
    2405             :   {
    2406         308 :     z = signe(b)? mulii(v, addii(u,v)): sqri(v);
    2407         308 :     return addii(z, mulii(c, sqri(u)));
    2408             :   }
    2409             :   else
    2410             :   {
    2411         315 :     z = signe(b)? gmul(v, gadd(u,v)): gsqr(v);
    2412         315 :     return gadd(z, gmul(c, gsqr(u)));
    2413             :   }
    2414             : }
    2415             : /* x a t_QUAD, return the attached discriminant */
    2416             : INLINE GEN
    2417         252 : quad_disc(GEN x)
    2418             : {
    2419         252 :   GEN Q = gel(x,1), b = gel(Q,3), c = gel(Q,2), c4;
    2420         252 :   if (is_pm1(b))
    2421             :   {
    2422         196 :     pari_sp av = avma; (void)new_chunk(lgefint(c) + 1);
    2423         196 :     c4 = shifti(c,2); avma = av; return subsi(1, c4);
    2424             :   }
    2425          56 :   c4 = shifti(c,2); togglesign_safe(&c4); return c4;
    2426             : }
    2427             : INLINE GEN
    2428     6345350 : qfb_disc3(GEN x, GEN y, GEN z) { return subii(sqri(y), shifti(mulii(x,z),2)); }
    2429             : INLINE GEN
    2430     6264528 : qfb_disc(GEN x) { return qfb_disc3(gel(x,1), gel(x,2), gel(x,3)); }
    2431             : 
    2432             : INLINE GEN
    2433     1246187 : sqrfrac(GEN x)
    2434             : {
    2435     1246187 :   GEN z = cgetg(3,t_FRAC);
    2436     1246187 :   gel(z,1) = sqri(gel(x,1));
    2437     1246187 :   gel(z,2) = sqri(gel(x,2)); return z;
    2438             : }
    2439             : 
    2440             : INLINE void
    2441    11569486 : normalize_frac(GEN z) {
    2442    11569486 :   if (signe(gel(z,2)) < 0) { togglesign(gel(z,1)); setabssign(gel(z,2)); }
    2443    11569486 : }
    2444             : 
    2445             : INLINE GEN
    2446      231376 : powii(GEN x, GEN n)
    2447             : {
    2448      231376 :   long ln = lgefint(n);
    2449      231376 :   if (ln == 3) {
    2450             :     GEN z;
    2451      228163 :     if (signe(n) > 0) return powiu(x, n[2]);
    2452        4963 :     z = cgetg(3, t_FRAC);
    2453        4963 :     gel(z,1) = gen_1;
    2454        4963 :     gel(z,2) = powiu(x, n[2]);
    2455        4963 :     return z;
    2456             :   }
    2457        3213 :   if (ln == 2) return gen_1; /* rare */
    2458             :   /* should never happen */
    2459           0 :   return powgi(x, n); /* overflow unless x = 0, 1, -1 */
    2460             : }
    2461             : INLINE GEN
    2462        1519 : powIs(long n) {
    2463        1519 :   switch(n & 3)
    2464             :   {
    2465           7 :     case 1: return mkcomplex(gen_0,gen_1);
    2466         364 :     case 2: return gen_m1;
    2467         469 :     case 3: return mkcomplex(gen_0,gen_m1);
    2468             :   }
    2469         679 :   return gen_1;
    2470             : }
    2471             : 
    2472             : /*******************************************************************/
    2473             : /*                                                                 */
    2474             : /*                             ASSIGNMENTS                         */
    2475             : /*                                                                 */
    2476             : /*******************************************************************/
    2477           0 : INLINE void mpexpz(GEN x, GEN z)
    2478           0 : { pari_sp av = avma; gaffect(mpexp(x), z); avma = av; }
    2479           0 : INLINE void mplogz(GEN x, GEN z)
    2480           0 : { pari_sp av = avma; gaffect(mplog(x), z); avma = av; }
    2481           0 : INLINE void mpcosz(GEN x, GEN z)
    2482           0 : { pari_sp av = avma; gaffect(mpcos(x), z); avma = av; }
    2483           0 : INLINE void mpsinz(GEN x, GEN z)
    2484           0 : { pari_sp av = avma; gaffect(mpsin(x), z); avma = av; }
    2485           0 : INLINE void gnegz(GEN x, GEN z)
    2486           0 : { pari_sp av = avma; gaffect(gneg(x), z); avma = av; }
    2487           0 : INLINE void gabsz(GEN x, long prec, GEN z)
    2488           0 : { pari_sp av = avma; gaffect(gabs(x,prec), z); avma = av; }
    2489       23318 : INLINE void gaddz(GEN x, GEN y, GEN z)
    2490       23318 : { pari_sp av = avma; gaffect(gadd(x,y), z); avma = av; }
    2491           0 : INLINE void gsubz(GEN x, GEN y, GEN z)
    2492           0 : { pari_sp av = avma; gaffect(gsub(x,y), z); avma = av; }
    2493       11673 : INLINE void gmulz(GEN x, GEN y, GEN z)
    2494       11673 : { pari_sp av = avma; gaffect(gmul(x,y), z); avma = av; }
    2495           0 : INLINE void gdivz(GEN x, GEN y, GEN z)
    2496           0 : { pari_sp av = avma; gaffect(gdiv(x,y), z); avma = av; }
    2497           0 : INLINE void gdiventz(GEN x, GEN y, GEN z)
    2498           0 : { pari_sp av = avma; gaffect(gdivent(x,y), z); avma = av; }
    2499           0 : INLINE void gmodz(GEN x, GEN y, GEN z)
    2500           0 : { pari_sp av = avma; gaffect(gmod(x,y), z); avma = av; }
    2501           0 : INLINE void gmul2nz(GEN x, long s, GEN z)
    2502           0 : { pari_sp av = avma; gaffect(gmul2n(x,s), z); avma = av; }
    2503           0 : INLINE void gshiftz(GEN x, long s, GEN z)
    2504           0 : { pari_sp av = avma; gaffect(gshift(x,s), z); avma = av; }
    2505             : 
    2506             : /*******************************************************************/
    2507             : /*                                                                 */
    2508             : /*                       ELLIPTIC CURVES                           */
    2509             : /*                                                                 */
    2510             : /*******************************************************************/
    2511     5287799 : INLINE GEN ell_get_a1(GEN e) { return gel(e,1); }
    2512     3095248 : INLINE GEN ell_get_a2(GEN e) { return gel(e,2); }
    2513     4515987 : INLINE GEN ell_get_a3(GEN e) { return gel(e,3); }
    2514     3888082 : INLINE GEN ell_get_a4(GEN e) { return gel(e,4); }
    2515     4704430 : INLINE GEN ell_get_a6(GEN e) { return gel(e,5); }
    2516     3969026 : INLINE GEN ell_get_b2(GEN e) { return gel(e,6); }
    2517     1021770 : INLINE GEN ell_get_b4(GEN e) { return gel(e,7); }
    2518     1627746 : INLINE GEN ell_get_b6(GEN e) { return gel(e,8); }
    2519     1464204 : INLINE GEN ell_get_b8(GEN e) { return gel(e,9); }
    2520     5925262 : INLINE GEN ell_get_c4(GEN e) { return gel(e,10); }
    2521     7957236 : INLINE GEN ell_get_c6(GEN e) { return gel(e,11); }
    2522     9391753 : INLINE GEN ell_get_disc(GEN e) { return gel(e,12); }
    2523     1027425 : INLINE GEN ell_get_j(GEN e) { return gel(e,13); }
    2524     7958966 : INLINE long ell_get_type(GEN e) { return mael(e,14,1); }
    2525     1561502 : INLINE GEN ellff_get_field(GEN x) { return gmael(x, 15, 1); }
    2526      678314 : INLINE GEN ellff_get_a4a6(GEN x)  { return gmael(x, 15, 2); }
    2527         917 : INLINE GEN ellQp_get_zero(GEN x) { return gmael(x, 15, 1); }
    2528         287 : INLINE long ellQp_get_prec(GEN E) { GEN z = ellQp_get_zero(E); return valp(z); }
    2529         623 : INLINE GEN ellQp_get_p(GEN E) { GEN z = ellQp_get_zero(E); return gel(z,2); }
    2530       36960 : INLINE long ellR_get_prec(GEN x) { return nbits2prec(mael3(x, 15, 1, 1)); }
    2531        8262 : INLINE long ellR_get_sign(GEN x) { return mael3(x, 15, 1, 2); }
    2532      501277 : INLINE GEN ellnf_get_nf(GEN x) { return checknf_i(gmael(x,15,1)); }
    2533          49 : INLINE GEN ellnf_get_bnf(GEN x) { return checkbnf_i(gmael(x,15,1)); }
    2534             : 
    2535    21956137 : INLINE int ell_is_inf(GEN z) { return lg(z) == 2; }
    2536      802403 : INLINE GEN ellinf(void) { return mkvec(gen_0); }
    2537             : 
    2538             : /*******************************************************************/
    2539             : /*                                                                 */
    2540             : /*                    ALGEBRAIC NUMBER THEORY                      */
    2541             : /*                                                                 */
    2542             : /*******************************************************************/
    2543     8117175 : INLINE GEN modpr_get_pr(GEN x)  { return gel(x,3); }
    2544      609920 : INLINE GEN modpr_get_p(GEN x)  { return pr_get_p(modpr_get_pr(x)); }
    2545     2516261 : INLINE GEN modpr_get_T(GEN x)  { return lg(x) == 4? NULL: gel(x,4); }
    2546             : 
    2547    18268005 : INLINE GEN pr_get_p(GEN pr)  { return gel(pr,1); }
    2548     4808086 : INLINE GEN pr_get_gen(GEN pr){ return gel(pr,2); }
    2549             : /* .[2] instead of itos works: e and f are small positive integers */
    2550     2231147 : INLINE long pr_get_e(GEN pr) { return gel(pr,3)[2]; }
    2551     7750082 : INLINE long pr_get_f(GEN pr) { return gel(pr,4)[2]; }
    2552     5796501 : INLINE GEN pr_get_tau(GEN pr){ return gel(pr,5); }
    2553             : INLINE int
    2554     2328373 : pr_is_inert(GEN P) { return pr_get_f(P) == lg(pr_get_gen(P))-1; }
    2555             : INLINE GEN
    2556      205352 : pr_norm(GEN pr) { return powiu(pr_get_p(pr), pr_get_f(pr)); }
    2557             : INLINE ulong
    2558       40852 : upr_norm(GEN pr) { return upowuu(pr_get_p(pr)[2], pr_get_f(pr)); }
    2559             : 
    2560             : /* assume nf a genuine nf */
    2561             : INLINE long
    2562        4185 : nf_get_varn(GEN nf) { return varn(gel(nf,1)); }
    2563             : INLINE GEN
    2564    27044734 : nf_get_pol(GEN nf) { return gel(nf,1); }
    2565             : INLINE long
    2566    21228275 : nf_get_degree(GEN nf) { return degpol( nf_get_pol(nf) ); }
    2567             : INLINE long
    2568     1265522 : nf_get_r1(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,1)); }
    2569             : INLINE long
    2570        8197 : nf_get_r2(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,2)); }
    2571             : INLINE GEN
    2572       46729 : nf_get_disc(GEN nf) { return gel(nf,3); }
    2573             : INLINE GEN
    2574      746712 : nf_get_index(GEN nf) { return gel(nf,4); }
    2575             : INLINE GEN
    2576     1206854 : nf_get_M(GEN nf) { return gmael(nf,5,1); }
    2577             : INLINE GEN
    2578       60189 : nf_get_G(GEN nf) { return gmael(nf,5,2); }
    2579             : INLINE GEN
    2580      434139 : nf_get_roundG(GEN nf) { return gmael(nf,5,3); }
    2581             : INLINE GEN
    2582       24332 : nf_get_Tr(GEN nf) { return gmael(nf,5,4); }
    2583             : INLINE GEN
    2584        2191 : nf_get_diff(GEN nf) { return gmael(nf,5,5); }
    2585             : INLINE GEN
    2586          28 : nf_get_ramified_primes(GEN nf) { return gmael(nf,5,8); }
    2587             : INLINE GEN
    2588      156604 : nf_get_roots(GEN nf) { return gel(nf,6); }
    2589             : INLINE GEN
    2590          77 : nf_get_zk(GEN nf)
    2591             : {
    2592          77 :   GEN y = gel(nf,7), D = nf_get_zkden(nf);
    2593          77 :   if (!equali1(D)) y = gdiv(y, D);
    2594          77 :   return y;
    2595             : }
    2596             : INLINE GEN
    2597      218455 : nf_get_zkprimpart(GEN nf)
    2598             : {
    2599      218455 :   GEN y = gel(nf,7);
    2600             :   /* test for old format of nf.zk: non normalized */
    2601      218455 :   if (!equali1(gel(nf,4)) && gequal1(gel(y,1))) y = Q_remove_denom(y,NULL);
    2602      218455 :   return y;
    2603             : }
    2604             : INLINE GEN
    2605      221052 : nf_get_zkden(GEN nf)
    2606             : {
    2607      221052 :   GEN y = gel(nf,7), D = gel(y,1);
    2608      221052 :   if (typ(D) == t_POL) D = gel(D,2);
    2609             :   /* test for old format of nf.zk: non normalized */
    2610      221052 :   if (!equali1(gel(nf,4)) && equali1(D)) D = Q_denom(y);
    2611      221052 :   return D;
    2612             : }
    2613             : INLINE GEN
    2614     2162924 : nf_get_invzk(GEN nf) { return gel(nf,8); }
    2615             : INLINE void
    2616       13503 : nf_get_sign(GEN nf, long *r1, long *r2)
    2617             : {
    2618       13503 :   GEN x = gel(nf,2);
    2619       13503 :   *r1 = itou(gel(x,1));
    2620       13503 :   *r2 = itou(gel(x,2));
    2621       13503 : }
    2622             : 
    2623             : INLINE GEN
    2624       49658 : abgrp_get_no(GEN x) { return gel(x,1); }
    2625             : INLINE GEN
    2626     2071502 : abgrp_get_cyc(GEN x) { return gel(x,2); }
    2627             : INLINE GEN
    2628      391807 : abgrp_get_gen(GEN x) { return gel(x,3); }
    2629             : INLINE GEN
    2630     2041745 : bnf_get_nf(GEN bnf) { return gel(bnf,7); }
    2631             : INLINE GEN
    2632      796382 : bnf_get_clgp(GEN bnf) { return gmael(bnf,8,1); }
    2633             : INLINE GEN
    2634        4578 : bnf_get_no(GEN bnf) { return abgrp_get_no(bnf_get_clgp(bnf)); }
    2635             : INLINE GEN
    2636      428984 : bnf_get_cyc(GEN bnf) { return abgrp_get_cyc(bnf_get_clgp(bnf)); }
    2637             : INLINE GEN
    2638      362491 : bnf_get_gen(GEN bnf)  { return abgrp_get_gen(bnf_get_clgp(bnf)); }
    2639             : INLINE GEN
    2640         860 : bnf_get_reg(GEN bnf) { return gmael(bnf,8,2); }
    2641             : INLINE GEN
    2642      480477 : bnf_get_logfu(GEN bnf) { return gel(bnf,3); }
    2643             : INLINE GEN
    2644        5755 : bnf_get_tuU(GEN bnf) { return gmael3(bnf,8,4,2); }
    2645             : INLINE long
    2646       24556 : bnf_get_tuN(GEN bnf) { return gmael3(bnf,8,4,1)[2]; }
    2647             : INLINE GEN
    2648        1806 : bnf_get_fu(GEN bnf) {
    2649        1806 :   GEN fu = bnf_get_fu_nocheck(bnf);
    2650        1806 :   if (typ(fu) == t_MAT) pari_err(e_MISC,"missing units in bnf");
    2651        1806 :   return fu;
    2652             : }
    2653             : INLINE GEN
    2654        7022 : bnf_get_fu_nocheck(GEN bnf) { return gmael(bnf,8,5); }
    2655             : 
    2656             : INLINE GEN
    2657      736923 : bnr_get_bnf(GEN bnr) { return gel(bnr,1); }
    2658             : INLINE GEN
    2659      379455 : bnr_get_bid(GEN bnr) { return gel(bnr,2); }
    2660             : INLINE GEN
    2661       18123 : bnr_get_mod(GEN bnr) { return gmael(bnr,2,1); }
    2662             : INLINE GEN
    2663       27342 : bnr_get_nf(GEN bnr) { return gmael(bnr,1,7); }
    2664             : INLINE GEN
    2665      511923 : bnr_get_clgp(GEN bnr) { return gel(bnr,5); }
    2666             : INLINE GEN
    2667       45080 : bnr_get_no(GEN bnr) { return abgrp_get_no(bnr_get_clgp(bnr)); }
    2668             : INLINE GEN
    2669      454915 : bnr_get_cyc(GEN bnr) { return abgrp_get_cyc(bnr_get_clgp(bnr)); }
    2670             : INLINE GEN
    2671          70 : bnr_get_gen_nocheck(GEN bnr) { return abgrp_get_gen(bnr_get_clgp(bnr)); }
    2672             : INLINE GEN
    2673       11025 : bnr_get_gen(GEN bnr) {
    2674       11025 :   GEN G = bnr_get_clgp(bnr);
    2675       11025 :   if (lg(G) !=  4)
    2676           0 :     pari_err(e_MISC,"missing bnr generators: please use bnrinit(,,1)");
    2677       11025 :   return gel(G,3);
    2678             : }
    2679             : 
    2680             : INLINE GEN
    2681      300796 : bid_get_mod(GEN bid) { return gel(bid,1); }
    2682             : INLINE GEN
    2683       44982 : bid_get_ideal(GEN bid) { return gmael(bid,1,1); }
    2684             : INLINE GEN
    2685         448 : bid_get_arch(GEN bid) { return gmael(bid,1,2); }
    2686             : INLINE GEN
    2687     1052811 : bid_get_grp(GEN bid) { return gel(bid,2); }
    2688             : INLINE GEN
    2689      394288 : bid_get_fact(GEN bid) { return gmael(bid,3,1); }
    2690             : INLINE GEN
    2691      352904 : bid_get_fact2(GEN bid) { return gmael(bid,3,2); }
    2692             : INLINE GEN
    2693      352974 : bid_get_sprk(GEN bid) { return gmael(bid,4,1); }
    2694             : INLINE GEN
    2695       29855 : bid_get_sarch(GEN bid) { return gmael(bid,4,2); }
    2696             : INLINE GEN
    2697      373575 : bid_get_archp(GEN bid) { return gmael3(bid,4,2,2); }
    2698             : INLINE GEN
    2699      653980 : bid_get_U(GEN bid) { return gel(bid,5); }
    2700             : INLINE GEN
    2701           0 : bid_get_no(GEN bid) { return abgrp_get_no(bid_get_grp(bid)); }
    2702             : INLINE GEN
    2703     1024461 : bid_get_cyc(GEN bid) { return abgrp_get_cyc(bid_get_grp(bid)); }
    2704             : INLINE GEN
    2705           0 : bid_get_gen_nocheck(GEN bid)  { return abgrp_get_gen(bid_get_grp(bid)); }
    2706             : INLINE GEN
    2707       27755 : bid_get_gen(GEN bid) {
    2708       27755 :   GEN G = bid_get_grp(bid);
    2709       27755 :   if (lg(G) != 4) pari_err(e_MISC,"missing bid generators. Use idealstar(,,2)");
    2710       27755 :   return abgrp_get_gen(G);
    2711             : }
    2712             : 
    2713             : INLINE GEN
    2714    23258767 : znstar_get_N(GEN G) { return gmael(G,1,1); }
    2715             : INLINE GEN
    2716     1732213 : znstar_get_faN(GEN G) { return gel(G,3); }
    2717             : INLINE GEN
    2718           0 : znstar_get_no(GEN G) { return abgrp_get_no(gel(G,2)); }
    2719             : INLINE GEN
    2720      161728 : znstar_get_cyc(GEN G) { return abgrp_get_cyc(gel(G,2)); }
    2721             : INLINE GEN
    2722           0 : znstar_get_gen(GEN G) { return abgrp_get_gen(gel(G,2)); }
    2723             : INLINE GEN
    2724     2428762 : znstar_get_conreycyc(GEN G) { return gmael(G,4,5); }
    2725             : INLINE GEN
    2726      663957 : znstar_get_conreygen(GEN G) { return gmael(G,4,4); }
    2727             : INLINE GEN
    2728       28126 : znstar_get_Ui(GEN G) { return gmael(G,4,3); }
    2729             : INLINE GEN
    2730      115304 : znstar_get_U(GEN G) { return gel(G,5); }
    2731             : INLINE GEN
    2732      297031 : znstar_get_pe(GEN G) { return gmael(G,4,1); }
    2733             : INLINE GEN
    2734       19152 : gal_get_pol(GEN gal) { return gel(gal,1); }
    2735             : INLINE GEN
    2736        1225 : gal_get_p(GEN gal) { return gmael(gal,2,1); }
    2737             : INLINE GEN
    2738          63 : gal_get_e(GEN gal) { return gmael(gal,2,2); }
    2739             : INLINE GEN
    2740       15631 : gal_get_mod(GEN gal) { return gmael(gal,2,3); }
    2741             : INLINE GEN
    2742       16009 : gal_get_roots(GEN gal) { return gel(gal,3); }
    2743             : INLINE GEN
    2744       15631 : gal_get_invvdm(GEN gal) { return gel(gal,4); }
    2745             : INLINE GEN
    2746       15631 : gal_get_den(GEN gal) { return gel(gal,5); }
    2747             : INLINE GEN
    2748       65023 : gal_get_group(GEN gal) { return gel(gal,6); }
    2749             : INLINE GEN
    2750        1701 : gal_get_gen(GEN gal) { return gel(gal,7); }
    2751             : INLINE GEN
    2752        1351 : gal_get_orders(GEN gal) { return gel(gal,8); }
    2753             : 
    2754             : /* assume rnf a genuine rnf */
    2755             : INLINE long
    2756      627102 : rnf_get_degree(GEN rnf) { return degpol(rnf_get_pol(rnf)); }
    2757             : INLINE long
    2758       15267 : rnf_get_nfdegree(GEN rnf) { return degpol(nf_get_pol(rnf_get_nf(rnf))); }
    2759             : INLINE long
    2760      459872 : rnf_get_absdegree(GEN rnf) { return degpol(gmael(rnf,11,1)); }
    2761             : INLINE GEN
    2762         462 : rnf_get_idealdisc(GEN rnf) { return gmael(rnf,3,1); }
    2763             : INLINE GEN
    2764         448 : rnf_get_k(GEN rnf) { return gmael(rnf,11,3); }
    2765             : INLINE GEN
    2766         448 : rnf_get_alpha(GEN rnf) { return gmael(rnf, 11, 2); }
    2767             : INLINE GEN
    2768      127225 : rnf_get_nf(GEN rnf) { return gel(rnf,10); }
    2769             : INLINE void
    2770        2478 : rnf_get_nfzk(GEN rnf, GEN *b, GEN *cb) {*b=gmael(rnf,2,1); *cb=gmael(rnf,2,2);}
    2771             : INLINE GEN
    2772       94801 : rnf_get_polabs(GEN rnf) { return gmael(rnf,11,1); }
    2773             : INLINE GEN
    2774      780696 : rnf_get_pol(GEN rnf) { return gel(rnf,1); }
    2775             : INLINE GEN
    2776          63 : rnf_get_disc(GEN rnf) { return gel(rnf,3); }
    2777             : INLINE GEN
    2778         105 : rnf_get_index(GEN rnf) { return gel(rnf,4); }
    2779             : INLINE long
    2780           0 : rnf_get_varn(GEN rnf) { return varn(gel(rnf,1)); }
    2781             : INLINE GEN
    2782      107492 : rnf_get_nfpol(GEN rnf) { return gmael(rnf,10,1); }
    2783             : INLINE long
    2784         595 : rnf_get_nfvarn(GEN rnf) { return varn(gmael(rnf,10,1)); }
    2785             : INLINE GEN
    2786        2849 : rnf_get_zk(GEN rnf) { return gel(rnf,7); }
    2787             : INLINE GEN
    2788       35133 : rnf_get_map(GEN rnf) { return gel(rnf,11); }
    2789             : INLINE GEN
    2790        1190 : rnf_get_invzk(GEN rnf) { return gel(rnf,8); }
    2791             : 
    2792             : /* I integral ZM (not HNF), G ZM, rounded Cholesky form of a weighted
    2793             :  * T2 matrix. Reduce I wrt G */
    2794             : INLINE GEN
    2795       13104 : idealpseudored(GEN I, GEN G)
    2796       13104 : { return ZM_mul(I, ZM_lll(ZM_mul(G, I), 0.99, LLL_IM)); }
    2797             : 
    2798             : /* I integral (not necessarily HNF), G ZM, rounded Cholesky form of a weighted
    2799             :  * T2 matrix. Return m in I with T2(m) small */
    2800             : INLINE GEN
    2801      156162 : idealpseudomin(GEN I, GEN G)
    2802             : {
    2803      156162 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2804      156162 :   return ZM_ZC_mul(I, gel(u,1));
    2805             : }
    2806             : /* I, G as in idealpseudomin. Return an irrational m in I with T2(m) small */
    2807             : INLINE GEN
    2808      295032 : idealpseudomin_nonscalar(GEN I, GEN G)
    2809             : {
    2810      295032 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2811      295032 :   GEN m = ZM_ZC_mul(I, gel(u,1));
    2812      295032 :   if (ZV_isscalar(m) && lg(u) > 2) m = ZM_ZC_mul(I, gel(u,2));
    2813      295032 :   return m;
    2814             : }
    2815             : 
    2816             : INLINE GEN
    2817          14 : idealred_elt(GEN nf, GEN I) {
    2818          14 :   pari_sp av = avma;
    2819          14 :   GEN u = idealpseudomin(I, nf_get_roundG(nf));
    2820          14 :   return gerepileupto(av, u);
    2821             : }
    2822             : INLINE GEN
    2823      161910 : idealred(GEN nf, GEN I) { return idealred0(nf, I, NULL); }
    2824             : 
    2825             : INLINE GEN
    2826        1274 : idealchineseinit(GEN nf, GEN x)
    2827        1274 : { return idealchinese(nf,x,NULL); }
    2828             : 
    2829             : /*******************************************************************/
    2830             : /*                                                                 */
    2831             : /*                              CLOSURES                           */
    2832             : /*                                                                 */
    2833             : /*******************************************************************/
    2834   253179539 : INLINE long closure_arity(GEN C)          { return ((ulong)C[1])&ARITYBITS; }
    2835    35393598 : INLINE long closure_is_variadic(GEN C) { return !!(((ulong)C[1])&VARARGBITS); }
    2836   217378729 : INLINE const char *closure_codestr(GEN C)  { return GSTR(gel(C,2))-1; }
    2837           0 : INLINE GEN closure_get_code(GEN C)  { return gel(C,2); }
    2838   217369881 : INLINE GEN closure_get_oper(GEN C)  { return gel(C,3); }
    2839   217349341 : INLINE GEN closure_get_data(GEN C)  { return gel(C,4); }
    2840        8735 : INLINE GEN closure_get_dbg(GEN C)   { return gel(C,5); }
    2841       21005 : INLINE GEN closure_get_text(GEN C)  { return gel(C,6); }
    2842     1158518 : INLINE GEN closure_get_frame(GEN C) { return gel(C,7); }
    2843             : 
    2844             : /*******************************************************************/
    2845             : /*                                                                 */
    2846             : /*                               ERRORS                            */
    2847             : /*                                                                 */
    2848             : /*******************************************************************/
    2849             : INLINE long
    2850       50142 : err_get_num(GEN e) { return e[1]; }
    2851             : INLINE GEN
    2852          63 : err_get_compo(GEN e, long i) { return gel(e, i+1); }
    2853             : 
    2854             : INLINE void
    2855          14 : pari_err_BUG(const char *f) { pari_err(e_BUG,f); }
    2856             : INLINE void
    2857           7 : pari_err_CONSTPOL(const char *f) { pari_err(e_CONSTPOL, f); }
    2858             : INLINE void
    2859          63 : pari_err_COPRIME(const char *f, GEN x, GEN y) { pari_err(e_COPRIME, f,x,y); }
    2860             : INLINE void
    2861         459 : pari_err_DIM(const char *f) { pari_err(e_DIM, f); }
    2862             : INLINE void
    2863           0 : pari_err_FILE(const char *f, const char *g) { pari_err(e_FILE, f,g); }
    2864             : INLINE void
    2865          42 : pari_err_FLAG(const char *f) { pari_err(e_FLAG,f); }
    2866             : INLINE void
    2867         350 : pari_err_IMPL(const char *f) { pari_err(e_IMPL,f); }
    2868             : INLINE void
    2869       19689 : pari_err_INV(const char *f, GEN x) { pari_err(e_INV,f,x); }
    2870             : INLINE void
    2871          21 : pari_err_IRREDPOL(const char *f, GEN x) { pari_err(e_IRREDPOL, f,x); }
    2872             : INLINE void
    2873        1856 : 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); }
    2874             : INLINE void
    2875         245 : pari_err_COMPONENT(const char *f, const char *op, GEN l, GEN x) { pari_err(e_COMPONENT, f,op,l,x); }
    2876             : INLINE void
    2877           0 : pari_err_MAXPRIME(ulong c) { pari_err(e_MAXPRIME, c); }
    2878             : INLINE void
    2879         287 : pari_err_OP(const char *f, GEN x, GEN y) { pari_err(e_OP, f,x,y); }
    2880             : INLINE void
    2881          84 : pari_err_OVERFLOW(const char *f) { pari_err(e_OVERFLOW, f); }
    2882             : INLINE void
    2883         219 : pari_err_PREC(const char *f) { pari_err(e_PREC,f); }
    2884             : INLINE void
    2885           0 : pari_err_PACKAGE(const char *f) { pari_err(e_PACKAGE,f); }
    2886             : INLINE void
    2887          49 : pari_err_PRIME(const char *f, GEN x) { pari_err(e_PRIME, f,x); }
    2888             : INLINE void
    2889         735 : pari_err_MODULUS(const char *f, GEN x, GEN y) { pari_err(e_MODULUS, f,x,y); }
    2890             : INLINE void
    2891          42 : pari_err_ROOTS0(const char *f) { pari_err(e_ROOTS0, f); }
    2892             : INLINE void
    2893          77 : pari_err_SQRTN(const char *f, GEN x) { pari_err(e_SQRTN, f,x); }
    2894             : INLINE void
    2895       11558 : pari_err_TYPE(const char *f, GEN x) { pari_err(e_TYPE, f,x); }
    2896             : INLINE void
    2897        3073 : pari_err_TYPE2(const char *f, GEN x, GEN y) { pari_err(e_TYPE2, f,x,y); }
    2898             : INLINE void
    2899         203 : pari_err_VAR(const char *f, GEN x, GEN y) { pari_err(e_VAR, f,x,y); }
    2900             : INLINE void
    2901         147 : pari_err_PRIORITY(const char *f, GEN x, const char *op, long v)
    2902         147 : { pari_err(e_PRIORITY, f,x,op,v); }

Generated by: LCOV version 1.11