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 21064-a7054ad) Lines: 1265 1442 87.7 %
Date: 2017-09-25 06:24:50 Functions: 541 615 88.0 %
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     2156105 : 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     1429277 : mkpolmod(GEN x, GEN y) { retmkpolmod(x,y); }
     149             : INLINE GEN
     150     2397809 : mkfrac(GEN x, GEN y) { retmkfrac(x,y); }
     151             : INLINE GEN
     152         336 : 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           0 : Qtoss(GEN q, long *n, long *d)
     156             : {
     157           0 :   if (typ(q) == t_INT) { *n = itos(q); *d = 1; }
     158           0 :   else { *n = itos(gel(q,1)); *d = itou(gel(q,2)); }
     159           0 : }
     160             : INLINE GEN
     161       18067 : sstoQ(long n, long d)
     162             : {
     163             :   long g, r, q;
     164       18067 :   if (d == 1) return stoi(n);
     165       17878 :   q = sdivss_rem(n,d,&r);
     166       17878 :   if (!r) return stoi(q);
     167       11235 :   g = cgcd(d,r); /* gcd(n,d) */
     168       11235 :   if (g != 1) { n /= g; d /= g; }
     169       11235 :   if (d < 0) { d = -d; n = -n; }
     170       11235 :   retmkfrac(stoi(n), utoi(d));
     171             : }
     172             : 
     173             : INLINE GEN
     174     5437859 : 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     3163536 : mkcomplex(GEN x, GEN y) { retmkcomplex(x,y); }
     183             : INLINE GEN
     184      436032 : gen_I(void) { return mkcomplex(gen_0, gen_1); }
     185             : INLINE GEN
     186      203084 : 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    55101431 : mkvecsmall(long x) { GEN v = cgetg(2, t_VECSMALL); v[1] = x; return v; }
     193             : INLINE GEN
     194   110495410 : mkvecsmall2(long x,long y) { GEN v = cgetg(3, t_VECSMALL);
     195   110489432 :   v[1]=x; v[2]=y; return v; }
     196             : INLINE GEN
     197    65047289 : mkvecsmall3(long x,long y,long z) { GEN v = cgetg(4, t_VECSMALL);
     198    65044608 :   v[1]=x; v[2]=y; v[3]=z; return v; }
     199             : INLINE GEN
     200    23739110 : mkvecsmall4(long x,long y,long z,long t) { GEN v = cgetg(5, t_VECSMALL);
     201    23729454 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; return v; }
     202             : INLINE GEN
     203      702726 : mkvecsmall5(long x,long y,long z,long t,long u) { GEN v = cgetg(6, t_VECSMALL);
     204      702726 :   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    12576478 : mkvec(GEN x) { retmkvec(x); }
     211             : INLINE GEN
     212   132253402 : mkvec2(GEN x, GEN y) { retmkvec2(x,y); }
     213             : INLINE GEN
     214    73870634 : mkvec3(GEN x, GEN y, GEN z) { retmkvec3(x,y,z); }
     215             : INLINE GEN
     216     7750003 : mkvec4(GEN x, GEN y, GEN z, GEN t) { retmkvec4(x,y,z,t); }
     217             : INLINE GEN
     218    11954697 : 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       20046 : mkvec2s(long x, long y) { retmkvec2(stoi(x),stoi(y)); }
     223             : INLINE GEN
     224      492702 : mkvec3s(long x, long y, long z) { retmkvec3(stoi(x),stoi(y),stoi(z)); }
     225             : INLINE GEN
     226           0 : mkvec4s(long x, long y, long z, long t) { retmkvec4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     227             : INLINE GEN
     228       33460 : mkveccopy(GEN x) { GEN v = cgetg(2, t_VEC); gel(v,1) = gcopy(x); return v; }
     229             : INLINE GEN
     230      108962 : mkvec2copy(GEN x, GEN y) {
     231      108962 :   GEN v = cgetg(3,t_VEC); gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     232             : /* col */
     233             : INLINE GEN
     234     2222778 : mkcol(GEN x) { retmkcol(x); }
     235             : INLINE GEN
     236    14953083 : mkcol2(GEN x, GEN y) { retmkcol2(x,y); }
     237             : INLINE GEN
     238       41615 : 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     1181376 : 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       28872 : mkcolcopy(GEN x) { GEN v = cgetg(2, t_COL); gel(v,1) = gcopy(x); return v; }
     255             : /* mat */
     256             : INLINE GEN
     257      730701 : mkmat(GEN x) { retmkmat(x); }
     258             : INLINE GEN
     259    16241926 : 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        7445 : 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       24416 : mkoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_1; return v; }
     272             : INLINE GEN
     273       13979 : mkmoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_m1; return v; }
     274             : INLINE long
     275       47776 : inf_get_sign(GEN x) { return signe(gel(x,1)); }
     276             : /* pol */
     277             : INLINE GEN
     278      735925 : pol_x(long v) {
     279      735925 :   GEN p = cgetg(4, t_POL);
     280      735925 :   p[1] = evalsigne(1)|evalvarn(v);
     281      735925 :   gel(p,2) = gen_0;
     282      735925 :   gel(p,3) = gen_1; return p;
     283             : }
     284             : /* x^n, assume n >= 0 */
     285             : INLINE GEN
     286     2489881 : pol_xn(long n, long v) {
     287     2489881 :   long i, a = n+2;
     288     2489881 :   GEN p = cgetg(a+1, t_POL);
     289     2489881 :   p[1] = evalsigne(1)|evalvarn(v);
     290     2489881 :   for (i = 2; i < a; i++) gel(p,i) = gen_0;
     291     2489881 :   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     1271267 : pol_1(long v) {
     302     1271267 :   GEN p = cgetg(3, t_POL);
     303     1271271 :   p[1] = evalsigne(1)|evalvarn(v);
     304     1271271 :   gel(p,2) = gen_1; return p;
     305             : }
     306             : INLINE GEN
     307    18717699 : pol_0(long v)
     308             : {
     309    18717699 :   GEN x = cgetg(2,t_POL);
     310    18717699 :   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     7572769 : 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       84785 : const_col(long n, GEN x) { retconst_col(n, x); }
     326             : INLINE GEN
     327     4687403 : const_vecsmall(long n, long c)
     328             : {
     329             :   long i;
     330     4687403 :   GEN V = cgetg(n+1,t_VECSMALL);
     331     4687405 :   for(i=1;i<=n;i++) V[i] = c;
     332     4687405 :   return V;
     333             : }
     334             : 
     335             : /***   ZERO   ***/
     336             : /* O(p^e) */
     337             : INLINE GEN
     338      303174 : zeropadic(GEN p, long e)
     339             : {
     340      303174 :   GEN y = cgetg(5,t_PADIC);
     341      303174 :   gel(y,4) = gen_0;
     342      303174 :   gel(y,3) = gen_1;
     343      303174 :   gel(y,2) = icopy(p);
     344      303174 :   y[1] = evalvalp(e) | _evalprecp(0);
     345      303174 :   return y;
     346             : }
     347             : INLINE GEN
     348         532 : zeropadic_shallow(GEN p, long e)
     349             : {
     350         532 :   GEN y = cgetg(5,t_PADIC);
     351         532 :   gel(y,4) = gen_0;
     352         532 :   gel(y,3) = gen_1;
     353         532 :   gel(y,2) = p;
     354         532 :   y[1] = evalvalp(e) | _evalprecp(0);
     355         532 :   return y;
     356             : }
     357             : /* O(pol_x(v)^e) */
     358             : INLINE GEN
     359       14532 : zeroser(long v, long e)
     360             : {
     361       14532 :   GEN x = cgetg(2, t_SER);
     362       14532 :   x[1] = evalvalp(e) | evalvarn(v); return x;
     363             : }
     364             : INLINE int
     365     3700017 : ser_isexactzero(GEN x)
     366             : {
     367     3700017 :   if (!signe(x)) switch(lg(x))
     368             :   {
     369       12761 :     case 2: return 1;
     370         840 :     case 3: return isexactzero(gel(x,2));
     371             :   }
     372     3686416 :   return 0;
     373             : }
     374             : /* 0 * pol_x(v) */
     375             : INLINE GEN
     376     6422783 : zeropol(long v) { return pol_0(v); }
     377             : /* vector(n) */
     378             : INLINE GEN
     379    28313448 : zerocol(long n)
     380             : {
     381    28313448 :   GEN y = cgetg(n+1,t_COL);
     382    28313448 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     383    28313448 :   return y;
     384             : }
     385             : /* vectorv(n) */
     386             : INLINE GEN
     387    18225336 : zerovec(long n)
     388             : {
     389    18225336 :   GEN y = cgetg(n+1,t_VEC);
     390    18225333 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     391    18225333 :   return y;
     392             : }
     393             : /* matrix(m, n) */
     394             : INLINE GEN
     395       15498 : zeromat(long m, long n)
     396             : {
     397       15498 :   GEN y = cgetg(n+1,t_MAT);
     398       15498 :   GEN v = zerocol(m);
     399       15498 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     400       15498 :   return y;
     401             : }
     402             : /* = zero_zx, sv is a evalvarn()*/
     403             : INLINE GEN
     404      792542 : zero_Flx(long sv) { return pol0_Flx(sv); }
     405             : INLINE GEN
     406    32308484 : zero_Flv(long n)
     407             : {
     408    32308484 :   GEN y = cgetg(n+1,t_VECSMALL);
     409    32308640 :   long i; for (i=1; i<=n; i++) y[i] = 0;
     410    32308640 :   return y;
     411             : }
     412             : /* matrix(m, n) */
     413             : INLINE GEN
     414      882112 : zero_Flm(long m, long n)
     415             : {
     416      882112 :   GEN y = cgetg(n+1,t_MAT);
     417      882112 :   GEN v = zero_Flv(m);
     418      882112 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     419      882112 :   return y;
     420             : }
     421             : /* matrix(m, n) */
     422             : INLINE GEN
     423       93238 : zero_Flm_copy(long m, long n)
     424             : {
     425       93238 :   GEN y = cgetg(n+1,t_MAT);
     426       93249 :   long i; for (i=1; i<=n; i++) gel(y,i) = zero_Flv(m);
     427       93243 :   return y;
     428             : }
     429             : 
     430             : INLINE GEN
     431      789520 : zero_F2v(long m)
     432             : {
     433      789520 :   long l = nbits2nlong(m);
     434      789520 :   GEN v  = zero_Flv(l+1);
     435      789520 :   v[1] = m;
     436      789520 :   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      280225 : zero_F2m_copy(long m, long n)
     453             : {
     454             :   long i;
     455      280225 :   GEN M = cgetg(n+1, t_MAT);
     456      859181 :   for (i = 1; i <= n; i++)
     457      578956 :     gel(M,i)= zero_F2v(m);
     458      280225 :   return M;
     459             : }
     460             : 
     461             : /* matrix(m, n) */
     462             : INLINE GEN
     463     2001482 : zeromatcopy(long m, long n)
     464             : {
     465     2001482 :   GEN y = cgetg(n+1,t_MAT);
     466     2001482 :   long i; for (i=1; i<=n; i++) gel(y,i) = zerocol(m);
     467     2001482 :   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     1389431 : col_ei(long n, long i) { GEN e = zerocol(n); gel(e,i) = gen_1; return e; }
     483             : INLINE GEN
     484      337212 : 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       68825 : vecsmall_ei(long n, long i) { GEN e = zero_zv(n); e[i] = 1; return e; }
     489             : INLINE GEN
     490     1170157 : Rg_col_ei(GEN x, long n, long i) { GEN e = zerocol(n); gel(e,i) = x; return e; }
     491             : 
     492             : INLINE GEN
     493     2653456 : shallowcopy(GEN x)
     494     2653456 : { return typ(x) == t_MAT ? RgM_shallowcopy(x): leafcopy(x); }
     495             : 
     496             : /* routines for naive growarrays */
     497             : INLINE GEN
     498    12711125 : vectrunc_init(long l)
     499             : {
     500    12711125 :   GEN z = new_chunk(l);
     501    12711482 :   z[0] = evaltyp(t_VEC) | _evallg(1); return z;
     502             : }
     503             : INLINE void
     504   507093123 : lg_increase(GEN x) { x[0]++; }
     505             : INLINE void
     506    49284454 : 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   168349369 : vecsmalltrunc_init(long l)
     517             : {
     518   168349369 :   GEN z = new_chunk(l);
     519   168349369 :   z[0] = evaltyp(t_VECSMALL) | _evallg(1); return z;
     520             : }
     521             : INLINE void
     522    25858660 : 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       59332 : vec_append(GEN V, GEN s)
     551             : {
     552       59332 :   long i, l2 = lg(V);
     553       59332 :   GEN res = cgetg(l2+1, typ(V));
     554       59332 :   for (i = 1; i < l2; ++i) gel(res, i) = gel(V,i);
     555       59332 :   gel(res,l2) = s; return res;
     556             : }
     557             : /* shallow*/
     558             : INLINE GEN
     559          49 : vec_prepend(GEN v, GEN s)
     560             : {
     561          49 :   long i, l = lg(v);
     562          49 :   GEN w = cgetg(l+1, typ(v));
     563          49 :   gel(w,1) = s;
     564          49 :   for (i = 2; i <= l; ++i) gel(w,i) = gel(v,i-1);
     565          49 :   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      178946 : vecsmall_shorten(GEN v, long n)
     577             : {
     578             :   long i;
     579      178946 :   GEN V = cgetg(n+1,t_VECSMALL);
     580      178949 :   for(i=1;i<=n;i++) V[i] = v[i];
     581      178949 :   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      410163 : vec_to_vecsmall(GEN z)
     594             : {
     595      410163 :   long i, l = lg(z);
     596      410163 :   GEN x = cgetg(l, t_VECSMALL);
     597      410163 :   for (i=1; i<l; i++) x[i] = itos(gel(z,i));
     598      410163 :   return x;
     599             : }
     600             : INLINE GEN
     601       71232 : vecsmall_to_vec(GEN z)
     602             : {
     603       71232 :   long i, l = lg(z);
     604       71232 :   GEN x = cgetg(l,t_VEC);
     605       71232 :   for (i=1; i<l; i++) gel(x,i) = stoi(z[i]);
     606       71232 :   return x;
     607             : }
     608             : INLINE GEN
     609         938 : vecsmall_to_vec_inplace(GEN z)
     610             : {
     611         938 :   long i, l = lg(z);
     612         938 :   for (i=1; i<l; i++) gel(z,i) = stoi(z[i]);
     613         938 :   settyp(z, t_VEC); return z;
     614             : }
     615             : INLINE GEN
     616     1301803 : vecsmall_to_col(GEN z)
     617             : {
     618     1301803 :   long i, l = lg(z);
     619     1301803 :   GEN x = cgetg(l,t_COL);
     620     1301803 :   for (i=1; i<l; i++) gel(x,i) = stoi(z[i]);
     621     1301803 :   return x;
     622             : }
     623             : 
     624             : INLINE int
     625     9456409 : vecsmall_lexcmp(GEN x, GEN y)
     626             : {
     627             :   long lx,ly,l,i;
     628     9456409 :   lx = lg(x);
     629     9456409 :   ly = lg(y); l = minss(lx,ly);
     630    56689382 :   for (i=1; i<l; i++)
     631    54634408 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     632     2054974 :   if (lx == ly) return 0;
     633          14 :   return (lx < ly)? -1 : 1;
     634             : }
     635             : 
     636             : INLINE int
     637    47066978 : vecsmall_prefixcmp(GEN x, GEN y)
     638             : {
     639    47066978 :   long i, lx = lg(x), ly = lg(y), l = minss(lx,ly);
     640   148811348 :   for (i=1; i<l; i++)
     641   134951817 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     642    13859531 :   return 0;
     643             : }
     644             : 
     645             : /*Can be used on t_VEC, but coeffs not gcopy-ed*/
     646             : INLINE GEN
     647       12663 : vecsmall_prepend(GEN V, long s)
     648             : {
     649       12663 :   long i, l2 = lg(V);
     650       12663 :   GEN res = cgetg(l2+1, typ(V));
     651       12663 :   res[1] = s;
     652       12663 :   for (i = 2; i <= l2; ++i) res[i] = V[i - 1];
     653       12663 :   return res;
     654             : }
     655             : 
     656             : INLINE GEN
     657     3765602 : vecsmall_append(GEN V, long s)
     658             : {
     659     3765602 :   long i, l2 = lg(V);
     660     3765602 :   GEN res = cgetg(l2+1, t_VECSMALL);
     661     3765602 :   for (i = 1; i < l2; ++i) res[i] = V[i];
     662     3765602 :   res[l2] = s; return res;
     663             : }
     664             : 
     665             : INLINE GEN
     666      774688 : vecsmall_concat(GEN u, GEN v)
     667             : {
     668      774688 :   long i, l1 = lg(u)-1, l2 = lg(v)-1;
     669      774688 :   GEN res = cgetg(l1+l2+1, t_VECSMALL);
     670      774688 :   for (i = 1; i <= l1; ++i) res[i]    = u[i];
     671      774688 :   for (i = 1; i <= l2; ++i) res[i+l1] = v[i];
     672      774688 :   return res;
     673             : }
     674             : 
     675             : /* return the number of indices where u and v are equal */
     676             : INLINE long
     677           0 : vecsmall_coincidence(GEN u, GEN v)
     678             : {
     679           0 :   long i, s = 0, l = minss(lg(u),lg(v));
     680           0 :   for(i=1; i<l; i++)
     681           0 :     if(u[i] == v[i]) s++;
     682           0 :   return s;
     683             : }
     684             : 
     685             : /* returns the first index i<=n such that x=v[i] if it exists, 0 otherwise */
     686             : INLINE long
     687           0 : vecsmall_isin(GEN v, long x)
     688             : {
     689           0 :   long i, l = lg(v);
     690           0 :   for (i = 1; i < l; i++)
     691           0 :     if (v[i] == x) return i;
     692           0 :   return 0;
     693             : }
     694             : 
     695             : INLINE long
     696          84 : vecsmall_pack(GEN V, long base, long mod)
     697             : {
     698          84 :   long i, s = 0;
     699          84 :   for(i=1; i<lg(V); i++) s = (base*s + V[i]) % mod;
     700          84 :   return s;
     701             : }
     702             : 
     703             : INLINE long
     704          14 : vecsmall_indexmax(GEN x)
     705             : {
     706          14 :   long i, i0 = 1, t = x[1], lx = lg(x);
     707          56 :   for (i=2; i<lx; i++)
     708          42 :     if (x[i] > t) t = x[i0=i];
     709          14 :   return i0;
     710             : }
     711             : 
     712             : INLINE long
     713       42799 : vecsmall_max(GEN x)
     714             : {
     715       42799 :   long i, t = x[1], lx = lg(x);
     716       78161 :   for (i=2; i<lx; i++)
     717       35362 :     if (x[i] > t) t = x[i];
     718       42799 :   return t;
     719             : }
     720             : 
     721             : INLINE long
     722          14 : vecsmall_indexmin(GEN x)
     723             : {
     724          14 :   long i, i0 = 1, t = x[1], lx =lg(x);
     725          56 :   for (i=2; i<lx; i++)
     726          42 :     if (x[i] < t) t = x[i0=i];
     727          14 :   return i0;
     728             : }
     729             : 
     730             : INLINE long
     731           0 : vecsmall_min(GEN x)
     732             : {
     733           0 :   long i, t = x[1], lx =lg(x);
     734           0 :   for (i=2; i<lx; i++)
     735           0 :     if (x[i] < t) t = x[i];
     736           0 :   return t;
     737             : }
     738             : 
     739             : INLINE int
     740     2123118 : ZV_isscalar(GEN x)
     741             : {
     742     2123118 :   long l = lg(x);
     743     7471640 :   while (--l > 1)
     744     4967399 :     if (signe(gel(x, l))) return 0;
     745      381123 :   return 1;
     746             : }
     747             : INLINE int
     748    17394262 : QV_isscalar(GEN x)
     749             : {
     750    17394262 :   long lx = lg(x),i;
     751    18858504 :   for (i=2; i<lx; i++)
     752    18331322 :     if (!isintzero(gel(x, i))) return 0;
     753      527182 :   return 1;
     754             : }
     755             : INLINE int
     756        3864 : RgV_isscalar(GEN x)
     757             : {
     758        3864 :   long lx = lg(x),i;
     759        7340 :   for (i=2; i<lx; i++)
     760        6241 :     if (!gequal0(gel(x, i))) return 0;
     761        1099 :   return 1;
     762             : }
     763             : INLINE int
     764           0 : RgX_isscalar(GEN x)
     765             : {
     766             :   long i;
     767           0 :   for (i=lg(x)-1; i>2; i--)
     768           0 :     if (!gequal0(gel(x, i))) return 0;
     769           0 :   return 1;
     770             : }
     771             : INLINE long
     772    23335040 : RgX_equal_var(GEN x, GEN y) { return varn(x) == varn(y) && RgX_equal(x,y); }
     773             : 
     774             : INLINE int
     775        5293 : RgX_is_rational(GEN x)
     776             : {
     777             :   long i;
     778       23499 :   for (i = lg(x)-1; i > 1; i--)
     779       22140 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     780        1359 :   return 1;
     781             : }
     782             : INLINE int
     783     3503162 : RgX_is_ZX(GEN x)
     784             : {
     785             :   long i;
     786    15184762 :   for (i = lg(x)-1; i > 1; i--)
     787    11690217 :     if (typ(gel(x,i)) != t_INT) return 0;
     788     3494545 :   return 1;
     789             : }
     790             : INLINE int
     791      121275 : RgX_is_QX(GEN x)
     792             : {
     793      121275 :   long k = lg(x)-1;
     794      447419 :   for ( ; k>1; k--)
     795      327152 :     if (!is_rational_t(typ(gel(x,k)))) return 0;
     796      120267 :   return 1;
     797             : }
     798             : INLINE int
     799    15518388 : RgX_is_monomial(GEN x)
     800             : {
     801             :   long i;
     802    15518388 :   if (!signe(x)) return 0;
     803    25658844 :   for (i=lg(x)-2; i>1; i--)
     804    17734511 :     if (!isexactzero(gel(x,i))) return 0;
     805     7924333 :   return 1;
     806             : }
     807             : INLINE int
     808    18293926 : RgV_is_ZV(GEN x)
     809             : {
     810             :   long i;
     811    74712292 :   for (i = lg(x)-1; i > 0; i--)
     812    56419479 :     if (typ(gel(x,i)) != t_INT) return 0;
     813    18292813 :   return 1;
     814             : }
     815             : INLINE int
     816        4200 : RgV_is_QV(GEN x)
     817             : {
     818             :   long i;
     819       96334 :   for (i = lg(x)-1; i > 0; i--)
     820       94759 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     821        1575 :   return 1;
     822             : }
     823             : 
     824             : /********************************************************************/
     825             : /**                                                                **/
     826             : /**            Dynamic arrays implementation                       **/
     827             : /**                                                                **/
     828             : /********************************************************************/
     829             : INLINE void **
     830   407891221 : pari_stack_base(pari_stack *s) { return s->data; }
     831             : 
     832             : INLINE void
     833      923677 : pari_stack_init(pari_stack *s, size_t size, void **data)
     834             : {
     835      923677 :   s->data = data;
     836      923677 :   *data = NULL;
     837      923677 :   s->n = 0;
     838      923677 :   s->alloc = 0;
     839      923677 :   s->size = size;
     840      923677 : }
     841             : 
     842             : INLINE void
     843   406966929 : pari_stack_alloc(pari_stack *s, long nb)
     844             : {
     845   406966929 :   void **sdat = pari_stack_base(s);
     846   407258663 :   long alloc = s->alloc;
     847   814518577 :   if (s->n+nb <= alloc) return;
     848      391424 :   if (!alloc)
     849      343107 :     alloc = nb;
     850             :   else
     851             :   {
     852       48317 :     while (s->n+nb > alloc) alloc <<= 1;
     853             :   }
     854      391424 :   *sdat = pari_realloc(*sdat,alloc*s->size);
     855      392675 :   s->alloc = alloc;
     856             : }
     857             : 
     858             : INLINE long
     859   339025766 : pari_stack_new(pari_stack *s) { pari_stack_alloc(s, 1); return s->n++; }
     860             : 
     861             : INLINE void
     862      794974 : pari_stack_delete(pari_stack *s)
     863             : {
     864      794974 :   void **sdat = pari_stack_base(s);
     865      794561 :   if (*sdat) pari_free(*sdat);
     866      794860 : }
     867             : 
     868             : INLINE void
     869        4671 : pari_stack_pushp(pari_stack *s, void *u)
     870             : {
     871        4671 :   long n = pari_stack_new(s);
     872        4671 :   void **sdat =(void**) *pari_stack_base(s);
     873        4671 :   sdat[n] = u;
     874        4671 : }
     875             : 
     876             : /*******************************************************************/
     877             : /*                                                                 */
     878             : /*                            EXTRACT                              */
     879             : /*                                                                 */
     880             : /*******************************************************************/
     881             : INLINE GEN
     882   201912299 : vecslice(GEN A, long y1, long y2)
     883             : {
     884   201912299 :   long i,lB = y2 - y1 + 2;
     885   201912299 :   GEN B = cgetg(lB, typ(A));
     886   201912299 :   for (i=1; i<lB; i++) B[i] = A[y1-1+i];
     887   201912299 :   return B;
     888             : }
     889             : INLINE GEN
     890      733774 : vecslicepermute(GEN A, GEN p, long y1, long y2)
     891             : {
     892      733774 :   long i,lB = y2 - y1 + 2;
     893      733774 :   GEN B = cgetg(lB, typ(A));
     894      733774 :   for (i=1; i<lB; i++) B[i] = A[p[y1-1+i]];
     895      733774 :   return B;
     896             : }
     897             : /* rowslice(rowpermute(A,p), x1, x2) */
     898             : INLINE GEN
     899       34342 : rowslicepermute(GEN A, GEN p, long x1, long x2)
     900             : {
     901       34342 :   long i, lB = lg(A);
     902       34342 :   GEN B = cgetg(lB, typ(A));
     903       34342 :   for (i=1; i<lB; i++) gel(B,i) = vecslicepermute(gel(A,i),p,x1,x2);
     904       34342 :   return B;
     905             : }
     906             : INLINE GEN
     907    20248028 : rowslice(GEN A, long x1, long x2)
     908             : {
     909    20248028 :   long i, lB = lg(A);
     910    20248028 :   GEN B = cgetg(lB, typ(A));
     911    20248028 :   for (i=1; i<lB; i++) gel(B,i) = vecslice(gel(A,i),x1,x2);
     912    20248028 :   return B;
     913             : }
     914             : 
     915             : INLINE GEN
     916      212362 : matslice(GEN A, long x1, long x2, long y1, long y2)
     917             : {
     918      212362 :   return rowslice(vecslice(A, y1, y2), x1, x2);
     919             : }
     920             : 
     921             : /* shallow, remove coeff of index j */
     922             : INLINE GEN
     923         133 : rowsplice(GEN a, long j)
     924             : {
     925             :   long i, l;
     926         133 :   GEN b = cgetg_copy(a,&l);
     927         133 :   for (i = 1; i < l; i++) gel(b,i) = vecsplice(gel(a,i), j);
     928         133 :   return b;
     929             : }
     930             : /* shallow, remove coeff of index j */
     931             : INLINE GEN
     932       45164 : vecsplice(GEN a, long j)
     933             : {
     934       45164 :   long i, k, l = lg(a);
     935             :   GEN b;
     936       45164 :   if (l == 1) pari_err(e_MISC, "incorrect component in vecsplice");
     937       45164 :   b = cgetg(l-1, typ(a));
     938      190323 :   for (i = k = 1; i < l; i++)
     939      145159 :     if (i != j) gel(b, k++) = gel(a,i);
     940       45164 :   return b;
     941             : }
     942             : /* shallow */
     943             : INLINE GEN
     944         756 : RgM_minor(GEN a, long i, long j)
     945             : {
     946         756 :   GEN b = vecsplice(a, j);
     947         756 :   long k, l = lg(b);
     948         756 :   for (k = 1; k < l; k++) gel(b,k) = vecsplice(gel(b,k), i);
     949         756 :   return b;
     950             : }
     951             : 
     952             : /* A[x0,] */
     953             : INLINE GEN
     954      178650 : row(GEN A, long x0)
     955             : {
     956      178650 :   long i, lB = lg(A);
     957      178650 :   GEN B  = cgetg(lB, t_VEC);
     958      178650 :   for (i=1; i<lB; i++) gel(B, i) = gcoeff(A, x0, i);
     959      178650 :   return B;
     960             : }
     961             : INLINE GEN
     962     4481672 : Flm_row(GEN A, long x0)
     963             : {
     964     4481672 :   long i, lB = lg(A);
     965     4481672 :   GEN B  = cgetg(lB, t_VECSMALL);
     966     4481669 :   for (i=1; i<lB; i++) B[i] = coeff(A, x0, i);
     967     4481669 :   return B;
     968             : }
     969             : /* A[x0,] */
     970             : INLINE GEN
     971          56 : rowcopy(GEN A, long x0)
     972             : {
     973          56 :   long i, lB = lg(A);
     974          56 :   GEN B  = cgetg(lB, t_VEC);
     975          56 :   for (i=1; i<lB; i++) gel(B, i) = gcopy(gcoeff(A, x0, i));
     976          56 :   return B;
     977             : }
     978             : /* A[x0, x1..x2] */
     979             : INLINE GEN
     980        2177 : row_i(GEN A, long x0, long x1, long x2)
     981             : {
     982        2177 :   long i, lB = x2 - x1 + 2;
     983        2177 :   GEN B  = cgetg(lB, t_VEC);
     984        2177 :   for (i=x1; i<=x2; i++) gel(B, i) = gcoeff(A, x0, i);
     985        2177 :   return B;
     986             : }
     987             : 
     988             : INLINE GEN
     989     5491550 : vecreverse(GEN A)
     990             : {
     991             :   long i, l;
     992     5491550 :   GEN B = cgetg_copy(A, &l);
     993     5491550 :   for (i=1; i<l; i++) gel(B, i) = gel(A, l-i);
     994     5491550 :   return B;
     995             : }
     996             : 
     997             : INLINE GEN
     998         252 : vecsmall_reverse(GEN A)
     999             : {
    1000             :   long i, l;
    1001         252 :   GEN B = cgetg_copy(A, &l);
    1002         252 :   for (i=1; i<l; i++) B[i] = A[l-i];
    1003         252 :   return B;
    1004             : }
    1005             : 
    1006             : INLINE void
    1007         232 : vecreverse_inplace(GEN y)
    1008             : {
    1009         232 :   long ly = lg(y), lim = ly>>1, i;
    1010         640 :   for (i = 1; i <= lim; i++)
    1011             :   {
    1012         408 :     GEN z = gel(y,i);
    1013         408 :     gel(y,i)    = gel(y,ly-i);
    1014         408 :     gel(y,ly-i) = z;
    1015             :   }
    1016         232 : }
    1017             : 
    1018             : INLINE GEN
    1019    44970616 : vecsmallpermute(GEN A, GEN p) { return perm_mul(A, p); }
    1020             : 
    1021             : INLINE GEN
    1022     5389204 : vecpermute(GEN A, GEN p)
    1023             : {
    1024     5389204 :   long i,lB = lg(p);
    1025     5389204 :   GEN B = cgetg(lB, typ(A));
    1026     5389204 :   for (i=1; i<lB; i++) gel(B, i) = gel(A, p[i]);
    1027     5389204 :   return B;
    1028             : }
    1029             : INLINE GEN
    1030     2839820 : rowpermute(GEN A, GEN p)
    1031             : {
    1032     2839820 :   long i, lB = lg(A);
    1033     2839820 :   GEN B = cgetg(lB, typ(A));
    1034    28591108 :   for (i=1; i<lB; i++)
    1035    27181166 :     gel(B, i) = typ(gel(A,i)) == t_VECSMALL ? vecsmallpermute(gel(A, i), p):
    1036     1429878 :                                                     vecpermute(gel(A, i), p);
    1037     2839820 :   return B;
    1038             : }
    1039             : /*******************************************************************/
    1040             : /*                                                                 */
    1041             : /*                          PERMUTATIONS                           */
    1042             : /*                                                                 */
    1043             : /*******************************************************************/
    1044             : /* identity permutation */
    1045             : INLINE GEN
    1046      609288 : identity_perm(long n)
    1047             : {
    1048      609288 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1049             :   long i;
    1050      609288 :   for (i = 1; i <= n; i++) perm[i] = i;
    1051      609288 :   return perm;
    1052             : }
    1053             : 
    1054             : /* assume d <= n */
    1055             : INLINE GEN
    1056           0 : cyclic_perm(long n, long d)
    1057             : {
    1058           0 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1059             :   long i;
    1060           0 :   for (i = 1; i <= n-d; i++) perm[i] = i+d;
    1061           0 :   for (     ; i <= n;   i++) perm[i] = i-n+d;
    1062           0 :   return perm;
    1063             : }
    1064             : 
    1065             : /* Multiply (compose) two permutations */
    1066             : INLINE GEN
    1067    46601352 : perm_mul(GEN s, GEN t)
    1068             : {
    1069             :   GEN u;
    1070    46601352 :   long i, l = lg(t);
    1071    46601352 :   u = cgetg(l, t_VECSMALL);
    1072    46601352 :   for (i = 1; i < l; i++) u[i] = s[ t[i] ];
    1073    46601352 :   return u;
    1074             : }
    1075             : /* Compute the inverse (reciprocal) of a permutation. */
    1076             : INLINE GEN
    1077      594800 : perm_inv(GEN x)
    1078             : {
    1079             :   long i, lx;
    1080      594800 :   GEN y = cgetg_copy(x, &lx);
    1081      594800 :   for (i=1; i<lx; i++) y[ x[i] ] = i;
    1082      594800 :   return y;
    1083             : }
    1084             : /* Return s*t*s^-1 */
    1085             : INLINE GEN
    1086      506639 : perm_conj(GEN s, GEN t)
    1087             : {
    1088             :   long i, l;
    1089      506639 :   GEN v = cgetg_copy(s, &l);
    1090      506639 :   for (i = 1; i < l; i++) v[ s[i] ] = s[ t[i] ];
    1091      506639 :   return v;
    1092             : }
    1093             : 
    1094             : /*********************************************************************/
    1095             : /*                       MALLOC/FREE WRAPPERS                        */
    1096             : /*********************************************************************/
    1097             : #define BLOCK_SIGALRM_START          \
    1098             : {                                    \
    1099             :   int block=PARI_SIGINT_block;       \
    1100             :   PARI_SIGINT_block = 2;             \
    1101             :   MT_SIGINT_BLOCK(block);
    1102             : 
    1103             : #define BLOCK_SIGINT_START           \
    1104             : {                                    \
    1105             :   int block=PARI_SIGINT_block;       \
    1106             :   PARI_SIGINT_block = 1;             \
    1107             :   MT_SIGINT_BLOCK(block);
    1108             : 
    1109             : #define BLOCK_SIGINT_END             \
    1110             :   PARI_SIGINT_block = block;         \
    1111             :   MT_SIGINT_UNBLOCK(block);          \
    1112             :   if (!block && PARI_SIGINT_pending) \
    1113             :   {                                  \
    1114             :     int sig = PARI_SIGINT_pending;   \
    1115             :     PARI_SIGINT_pending = 0;         \
    1116             :     raise(sig);                      \
    1117             :   }                                  \
    1118             : }
    1119             : 
    1120             : INLINE void
    1121    53679409 : pari_free(void *pointer)
    1122             : {
    1123    53679409 :   BLOCK_SIGINT_START;
    1124    53681110 :   free(pointer);
    1125    53681110 :   BLOCK_SIGINT_END;
    1126    53680534 : }
    1127             : INLINE void*
    1128   234559160 : pari_malloc(size_t size)
    1129             : {
    1130   234559160 :   if (size)
    1131             :   {
    1132             :     char *tmp;
    1133   234559160 :     BLOCK_SIGINT_START;
    1134   234561505 :     tmp = (char*)malloc(size);
    1135   234561505 :     BLOCK_SIGINT_END;
    1136   234561359 :     if (!tmp) pari_err(e_MEM);
    1137   234561359 :     return tmp;
    1138             :   }
    1139           0 :   if (DEBUGMEM) pari_warn(warner,"mallocing NULL object");
    1140           0 :   return NULL;
    1141             : }
    1142             : INLINE void*
    1143      403387 : pari_realloc(void *pointer, size_t size)
    1144             : {
    1145             :   char *tmp;
    1146             : 
    1147      403387 :   BLOCK_SIGINT_START;
    1148      405110 :   if (!pointer) tmp = (char *) malloc(size);
    1149       51944 :   else tmp = (char *) realloc(pointer,size);
    1150      405110 :   BLOCK_SIGINT_END;
    1151      404514 :   if (!tmp) pari_err(e_MEM);
    1152      404514 :   return tmp;
    1153             : }
    1154             : INLINE void*
    1155       32596 : pari_calloc(size_t size)
    1156             : {
    1157       32596 :   void *t = pari_malloc(size);
    1158       32596 :   memset(t, 0, size); return t;
    1159             : }
    1160             : INLINE GEN
    1161        4194 : cgetalloc(long t, size_t l)
    1162             : {
    1163        4194 :   GEN x = (GEN)pari_malloc(l * sizeof(long));
    1164        4194 :   x[0] = evaltyp(t) | evallg(l); return x;
    1165             : }
    1166             : 
    1167             : /*******************************************************************/
    1168             : /*                                                                 */
    1169             : /*                       GARBAGE COLLECTION                        */
    1170             : /*                                                                 */
    1171             : /*******************************************************************/
    1172             : /* copy integer x as if we had avma = av */
    1173             : INLINE GEN
    1174  3660537989 : icopy_avma(GEN x, pari_sp av)
    1175             : {
    1176  3660537989 :   long i = lgefint(x), lx = i;
    1177  3660537989 :   GEN y = ((GEN)av) - i;
    1178  3660537989 :   while (--i > 0) y[i] = x[i];
    1179  3660537989 :   y[0] = evaltyp(t_INT)|evallg(lx);
    1180  3660297273 :   return y;
    1181             : }
    1182             : /* copy leaf x as if we had avma = av */
    1183             : INLINE GEN
    1184   156144455 : leafcopy_avma(GEN x, pari_sp av)
    1185             : {
    1186   156144455 :   long i = lg(x);
    1187   156144455 :   GEN y = ((GEN)av) - i;
    1188   156144455 :   while (--i > 0) y[i] = x[i];
    1189   156144455 :   y[0] = x[0] & (~CLONEBIT);
    1190   156144455 :   return y;
    1191             : }
    1192             : INLINE GEN
    1193   603517003 : gerepileuptoleaf(pari_sp av, GEN x)
    1194             : {
    1195             :   long lx;
    1196             :   GEN q;
    1197             : 
    1198   603517003 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1199   604515928 :   lx = lg(x);
    1200   604515928 :   q = ((GEN)av) - lx;
    1201   604515928 :   avma = (pari_sp)q;
    1202   604515928 :   while (--lx >= 0) q[lx] = x[lx];
    1203   604515928 :   return q;
    1204             : }
    1205             : INLINE GEN
    1206  1219552471 : gerepileuptoint(pari_sp av, GEN x)
    1207             : {
    1208  1219552471 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1209  1074755796 :   avma = (pari_sp)icopy_avma(x, av);
    1210  1075502873 :   return (GEN)avma;
    1211             : }
    1212             : INLINE GEN
    1213   733693950 : gerepileupto(pari_sp av, GEN x)
    1214             : {
    1215   733693950 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1216   632689046 :   switch(typ(x))
    1217             :   { /* non-default = !is_recursive_t(tq) */
    1218   212082287 :     case t_INT: return gerepileuptoint(av, x);
    1219             :     case t_REAL:
    1220             :     case t_STR:
    1221   125990759 :     case t_VECSMALL: return gerepileuptoleaf(av,x);
    1222             :     default:
    1223             :       /* NB: x+i --> ((long)x) + i*sizeof(long) */
    1224   294616000 :       return gerepile(av, (pari_sp) (x+lg(x)), x);
    1225             :   }
    1226             : }
    1227             : 
    1228             : /* gerepileupto(av, gcopy(x)) */
    1229             : INLINE GEN
    1230    40794399 : gerepilecopy(pari_sp av, GEN x)
    1231             : {
    1232    40794399 :   if (is_recursive_t(typ(x)))
    1233             :   {
    1234    33265861 :     GENbin *p = copy_bin(x);
    1235    33265879 :     avma = av; return bin_copy(p);
    1236             :   }
    1237             :   else
    1238             :   {
    1239     7528543 :     avma = av;
    1240     7528543 :     if (x < (GEN)av) {
    1241     6111689 :       if (x < (GEN)pari_mainstack->bot) new_chunk(lg(x));
    1242     6111689 :       x = leafcopy_avma(x, av);
    1243     6111695 :       avma = (pari_sp)x;
    1244             :     } else
    1245     1416854 :       x = leafcopy(x);
    1246     7528552 :     return x;
    1247             :   }
    1248             : }
    1249             : 
    1250             : /* Takes an array of pointers to GENs, of length n. Copies all
    1251             :  * objects to contiguous locations and cleans up the stack between
    1252             :  * av and avma. */
    1253             : INLINE void
    1254      136927 : gerepilemany(pari_sp av, GEN* gptr[], int n)
    1255             : {
    1256             :   int i;
    1257      136927 :   for (i=0; i<n; i++) *gptr[i] = (GEN)copy_bin(*gptr[i]);
    1258      136927 :   avma = av;
    1259      136927 :   for (i=0; i<n; i++) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1260      136927 : }
    1261             : 
    1262             : INLINE void
    1263     5701704 : gerepileall(pari_sp av, int n, ...)
    1264             : {
    1265             :   int i;
    1266     5701704 :   va_list a; va_start(a, n);
    1267     5701704 :   if (n < 10)
    1268             :   {
    1269             :     GEN *gptr[10];
    1270    17322562 :     for (i=0; i<n; i++)
    1271    11620866 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1272     5701696 :     avma = av;
    1273     5701696 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1274             : 
    1275             :   }
    1276             :   else
    1277             :   {
    1278           0 :     GEN **gptr = (GEN**)  pari_malloc(n*sizeof(GEN*));
    1279           0 :     for (i=0; i<n; i++)
    1280           0 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1281           0 :     avma = av;
    1282           0 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1283           0 :     pari_free(gptr);
    1284             :   }
    1285     5701707 :   va_end(a);
    1286     5701707 : }
    1287             : 
    1288             : INLINE void
    1289           8 : gerepilecoeffs(pari_sp av, GEN x, int n)
    1290             : {
    1291             :   int i;
    1292           8 :   for (i=0; i<n; i++) gel(x,i) = (GEN)copy_bin(gel(x,i));
    1293           8 :   avma = av;
    1294           8 :   for (i=0; i<n; i++) gel(x,i) = bin_copy((GENbin*)x[i]);
    1295           8 : }
    1296             : 
    1297             : /* p from copy_bin. Copy p->x back to stack, then destroy p */
    1298             : INLINE GEN
    1299    45294433 : bin_copy(GENbin *p)
    1300             : {
    1301             :   GEN x, y, base;
    1302             :   long dx, len;
    1303             : 
    1304    45294433 :   x   = p->x; if (!x) { pari_free(p); return gen_0; }
    1305    45287606 :   len = p->len;
    1306    45287606 :   base= p->base; dx = x - base;
    1307    45287606 :   y = (GEN)memcpy((void*)new_chunk(len), (void*)GENbinbase(p), len*sizeof(long));
    1308    45287631 :   y += dx;
    1309    45287631 :   p->rebase(y, ((ulong)y-(ulong)x));
    1310    45287606 :   pari_free(p); return y;
    1311             : }
    1312             : 
    1313             : INLINE GEN
    1314    90582124 : GENbinbase(GENbin *p) { return (GEN)(p + 1); }
    1315             : 
    1316             : INLINE void
    1317    27360019 : cgiv(GEN x)
    1318             : {
    1319    27360019 :   pari_sp av = (pari_sp)(x+lg(x));
    1320    27360019 :   if (isonstack((GEN)av)) avma = av;
    1321    27359616 : }
    1322             : 
    1323             : INLINE void
    1324     1184411 : killblock(GEN x) { gunclone(x); }
    1325             : 
    1326             : INLINE int
    1327    17745784 : is_universal_constant(GEN x) { return (x >= gen_0 && x <= ghalf); }
    1328             : 
    1329             : /*******************************************************************/
    1330             : /*                                                                 */
    1331             : /*                    CONVERSION / ASSIGNMENT                      */
    1332             : /*                                                                 */
    1333             : /*******************************************************************/
    1334             : /* z is a type which may be a t_COMPLEX component (not a t_QUAD) */
    1335             : INLINE GEN
    1336     2680902 : cxcompotor(GEN z, long prec)
    1337             : {
    1338     2680902 :   switch(typ(z))
    1339             :   {
    1340     1470514 :     case t_INT:  return itor(z, prec);
    1341      134120 :     case t_FRAC: return fractor(z, prec);
    1342     1076268 :     case t_REAL: return rtor(z, prec);
    1343           0 :     default: pari_err_TYPE("cxcompotor",z);
    1344             :              return NULL; /* LCOV_EXCL_LINE */
    1345             :   }
    1346             : }
    1347             : INLINE GEN
    1348     1333002 : cxtofp(GEN x, long prec)
    1349     1333002 : { retmkcomplex(cxcompotor(gel(x,1),prec), cxcompotor(gel(x,2),prec)); }
    1350             : 
    1351             : INLINE double
    1352    17290174 : gtodouble(GEN x)
    1353             : {
    1354    17290174 :   if (typ(x)!=t_REAL) {
    1355     3209414 :     pari_sp av = avma;
    1356     3209414 :     x = gtofp(x, DEFAULTPREC);
    1357     3209414 :     if (typ(x)!=t_REAL) pari_err_TYPE("gtodouble [t_REAL expected]", x);
    1358     3209414 :     avma = av;
    1359             :   }
    1360    17290174 :   return rtodbl(x);
    1361             : }
    1362             : INLINE long
    1363    67227352 : gtos(GEN x) {
    1364    67227352 :   if (typ(x) != t_INT) pari_err_TYPE("gtos [integer expected]",x);
    1365    67227345 :   return itos(x);
    1366             : }
    1367             : 
    1368             : INLINE ulong
    1369      136677 : gtou(GEN x) {
    1370      136677 :   if (typ(x) != t_INT || signe(x)<0)
    1371           0 :     pari_err_TYPE("gtou [integer >=0 expected]",x);
    1372      136959 :   return itou(x);
    1373             : }
    1374             : 
    1375             : INLINE GEN
    1376    10348562 : absfrac(GEN x)
    1377             : {
    1378    10348562 :   GEN y = cgetg(3, t_FRAC);
    1379    10348562 :   gel(y,1) = absi(gel(x,1));
    1380    10348562 :   gel(y,2) = icopy(gel(x,2)); return y;
    1381             : }
    1382             : INLINE GEN
    1383       32308 : absfrac_shallow(GEN x)
    1384       32308 : { return signe(gel(x,1))>0? x: mkfrac(negi(gel(x,1)), gel(x,2)); }
    1385             : INLINE GEN
    1386     1492246 : Q_abs(GEN x) { return (typ(x) == t_INT)? absi(x): absfrac(x); }
    1387             : INLINE GEN
    1388      106034 : Q_abs_shallow(GEN x)
    1389      106034 : { return (typ(x) == t_INT)? absi_shallow(x): absfrac_shallow(x); }
    1390             : INLINE GEN
    1391         322 : R_abs_shallow(GEN x)
    1392         322 : { return (typ(x) == t_FRAC)? absfrac_shallow(x): mpabs_shallow(x); }
    1393             : INLINE GEN
    1394           0 : R_abs(GEN x)
    1395           0 : { return (typ(x) == t_FRAC)? absfrac(x): mpabs(x); }
    1396             : 
    1397             : /* Force z to be of type real/complex with floating point components */
    1398             : INLINE GEN
    1399    18138963 : gtofp(GEN z, long prec)
    1400             : {
    1401    18138963 :   switch(typ(z))
    1402             :   {
    1403     8273274 :     case t_INT:  return itor(z, prec);
    1404     4257450 :     case t_FRAC: return fractor(z, prec);
    1405     4458975 :     case t_REAL: return rtor(z, prec);
    1406             :     case t_COMPLEX: {
    1407     1149264 :       GEN a = gel(z,1), b = gel(z,2);
    1408     1149264 :       if (isintzero(b)) return cxcompotor(a, prec);
    1409     1147193 :       if (isintzero(a)) {
    1410        1865 :         GEN y = cgetg(3, t_COMPLEX);
    1411        1865 :         b = cxcompotor(b, prec);
    1412        1865 :         gel(y,1) = real_0_bit(expo(b) - prec2nbits(prec));
    1413        1865 :         gel(y,2) = b; return y;
    1414             :       }
    1415     1145328 :       return cxtofp(z, prec);
    1416             :     }
    1417           0 :     case t_QUAD: return quadtofp(z, prec);
    1418           0 :     default: pari_err_TYPE("gtofp",z);
    1419             :              return NULL; /* LCOV_EXCL_LINE */
    1420             :   }
    1421             : }
    1422             : /* Force z to be of type real / int */
    1423             : INLINE GEN
    1424       22400 : gtomp(GEN z, long prec)
    1425             : {
    1426       22400 :   switch(typ(z))
    1427             :   {
    1428          14 :     case t_INT:  return z;
    1429       22386 :     case t_FRAC: return fractor(z, prec);
    1430           0 :     case t_REAL: return rtor(z, prec);
    1431           0 :     case t_QUAD: z = quadtofp(z, prec);
    1432           0 :                  if (typ(z) == t_REAL) return z;
    1433           0 :     default: pari_err_TYPE("gtomp",z);
    1434             :              return NULL; /* LCOV_EXCL_LINE */
    1435             :   }
    1436             : }
    1437             : 
    1438             : INLINE GEN
    1439      636407 : RgX_gtofp(GEN x, long prec)
    1440             : {
    1441             :   long l;
    1442      636407 :   GEN y = cgetg_copy(x, &l);
    1443      636407 :   while (--l > 1) gel(y,l) = gtofp(gel(x,l), prec);
    1444      636407 :   y[1] = x[1]; return y;
    1445             : }
    1446             : INLINE GEN
    1447      292709 : RgC_gtofp(GEN x, long prec)
    1448             : {
    1449      292709 :   long l = lg(x);
    1450      292709 :   GEN y = cgetg(l, t_COL);
    1451      292709 :   while (--l > 0) gel(y,l) = gtofp(gel(x,l), prec);
    1452      292709 :   return y;
    1453             : }
    1454             : INLINE GEN
    1455          42 : RgV_gtofp(GEN x, long prec)
    1456             : {
    1457          42 :   long l = lg(x);
    1458          42 :   GEN y = cgetg(l, t_VEC);
    1459          42 :   while (--l > 0) gel(y,l) = gtofp(gel(x,l), prec);
    1460          42 :   return y;
    1461             : }
    1462             : INLINE GEN
    1463       20553 : RgM_gtofp(GEN x, long prec)
    1464             : {
    1465             :   long l;
    1466       20553 :   GEN y = cgetg_copy(x, &l);
    1467       20553 :   while (--l > 0) gel(y,l) = RgC_gtofp(gel(x,l), prec);
    1468       20553 :   return y;
    1469             : }
    1470             : INLINE GEN
    1471         560 : RgC_gtomp(GEN x, long prec)
    1472             : {
    1473         560 :   long l = lg(x);
    1474         560 :   GEN y = cgetg(l, t_COL);
    1475         560 :   while (--l > 0) gel(y,l) = gtomp(gel(x,l), prec);
    1476         560 :   return y;
    1477             : }
    1478             : INLINE GEN
    1479          14 : RgM_gtomp(GEN x, long prec)
    1480             : {
    1481             :   long l;
    1482          14 :   GEN y = cgetg_copy(x, &l);
    1483          14 :   while (--l > 0) gel(y,l) = RgC_gtomp(gel(x,l), prec);
    1484          14 :   return y;
    1485             : }
    1486             : 
    1487             : INLINE GEN
    1488        8562 : RgX_fpnorml2(GEN x, long prec)
    1489             : {
    1490        8562 :   pari_sp av = avma;
    1491        8562 :   return gerepileupto(av, gnorml2(RgX_gtofp(x, prec)));
    1492             : }
    1493             : INLINE GEN
    1494      155156 : RgC_fpnorml2(GEN x, long prec)
    1495             : {
    1496      155156 :   pari_sp av = avma;
    1497      155156 :   return gerepileupto(av, gnorml2(RgC_gtofp(x, prec)));
    1498             : }
    1499             : INLINE GEN
    1500        3201 : RgM_fpnorml2(GEN x, long prec)
    1501             : {
    1502        3201 :   pari_sp av = avma;
    1503        3201 :   return gerepileupto(av, gnorml2(RgM_gtofp(x, prec)));
    1504             : }
    1505             : 
    1506             : /* y a t_REAL */
    1507             : INLINE void
    1508      190202 : affgr(GEN x, GEN y)
    1509             : {
    1510             :   pari_sp av;
    1511      190202 :   switch(typ(x)) {
    1512        5992 :     case t_INT:  affir(x,y); break;
    1513      184210 :     case t_REAL: affrr(x,y); break;
    1514           0 :     case t_FRAC: rdiviiz(gel(x,1),gel(x,2), y); break;
    1515           0 :     case t_QUAD: av = avma; affgr(quadtofp(x,realprec(y)), y); avma = av; break;
    1516           0 :     default: pari_err_TYPE2("=",x,y);
    1517             :   }
    1518      190202 : }
    1519             : 
    1520             : INLINE GEN
    1521      185736 : affc_fixlg(GEN x, GEN res)
    1522             : {
    1523      185736 :   if (typ(x) == t_COMPLEX)
    1524             :   {
    1525      175616 :     affrr_fixlg(gel(x,1), gel(res,1));
    1526      175616 :     affrr_fixlg(gel(x,2), gel(res,2));
    1527             :   }
    1528             :   else
    1529             :   {
    1530       10120 :     avma = (pari_sp)(res+3);
    1531       10120 :     res = cgetr(realprec(gel(res,1)));
    1532       10120 :     affrr_fixlg(x, res);
    1533             :   }
    1534      185736 :   return res;
    1535             : }
    1536             : 
    1537             : INLINE GEN
    1538           0 : trunc_safe(GEN x) { long e; return gcvtoi(x,&e); }
    1539             : 
    1540             : /*******************************************************************/
    1541             : /*                                                                 */
    1542             : /*                          LENGTH CONVERSIONS                     */
    1543             : /*                                                                 */
    1544             : /*******************************************************************/
    1545             : INLINE long
    1546       24545 : ndec2nlong(long x) { return 1 + (long)((x)*(LOG2_10/BITS_IN_LONG)); }
    1547             : INLINE long
    1548       24067 : ndec2prec(long x) { return 2 + ndec2nlong(x); }
    1549             : INLINE long
    1550         478 : ndec2nbits(long x) { return ndec2nlong(x) << TWOPOTBITS_IN_LONG; }
    1551             : /* Fast implementation of ceil(x / (8*sizeof(long))); typecast to (ulong)
    1552             :  * to avoid overflow. Faster than 1 + ((x-1)>>TWOPOTBITS_IN_LONG)) :
    1553             :  *   addl, shrl instead of subl, sarl, addl */
    1554             : INLINE long
    1555     1134574 : nbits2nlong(long x) {
    1556     1134574 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1557             : }
    1558             : 
    1559             : INLINE long
    1560   243786212 : nbits2extraprec(long x) {
    1561   243786212 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1562             : }
    1563             : 
    1564             : /* Fast implementation of 2 + nbits2nlong(x) */
    1565             : INLINE long
    1566    78423393 : nbits2prec(long x) {
    1567    78423393 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1568             : }
    1569             : INLINE long
    1570     6562411 : nbits2lg(long x) {
    1571     6562411 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1572             : }
    1573             : /* ceil(x / sizeof(long)) */
    1574             : INLINE long
    1575     8282115 : nchar2nlong(long x) {
    1576     8282115 :   return (long)(((ulong)x+sizeof(long)-1) >> (TWOPOTBITS_IN_LONG-3L));
    1577             : }
    1578             : INLINE long
    1579  1056703552 : prec2nbits(long x) { return (x-2) * BITS_IN_LONG; }
    1580             : INLINE double
    1581      448573 : bit_accuracy_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1582             : INLINE double
    1583      229883 : prec2nbits_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1584             : INLINE long
    1585    25963855 : bit_prec(GEN x) { return prec2nbits(realprec(x)); }
    1586             : INLINE long
    1587   974194274 : bit_accuracy(long x) { return prec2nbits(x); }
    1588             : INLINE long
    1589       12071 : prec2ndec(long x) { return (long)prec2nbits_mul(x, LOG10_2); }
    1590             : INLINE long
    1591         179 : nbits2ndec(long x) { return (long)(x * LOG10_2); }
    1592             : INLINE long
    1593        1651 : precdbl(long x) {return (x - 1) << 1;}
    1594             : INLINE long
    1595  3078927665 : divsBIL(long n) { return n >> TWOPOTBITS_IN_LONG; }
    1596             : INLINE long
    1597  3044533009 : remsBIL(long n) { return n & (BITS_IN_LONG-1); }
    1598             : 
    1599             : /*********************************************************************/
    1600             : /**                                                                 **/
    1601             : /**                      OPERATIONS MODULO m                        **/
    1602             : /**                                                                 **/
    1603             : /*********************************************************************/
    1604             : /* Assume m > 0, more efficient if 0 <= a, b < m */
    1605             : 
    1606             : INLINE GEN
    1607     2439563 : Fp_red(GEN a, GEN m) { return modii(a, m); }
    1608             : INLINE GEN
    1609    87093436 : Fp_add(GEN a, GEN b, GEN m)
    1610             : {
    1611    87093436 :   pari_sp av=avma;
    1612    87093436 :   GEN p = addii(a,b);
    1613    87107893 :   long s = signe(p);
    1614    87107893 :   if (!s) return p; /* = gen_0 */
    1615    76392563 :   if (s > 0) /* general case */
    1616             :   {
    1617    76169395 :     GEN t = subii(p, m);
    1618    76238735 :     s = signe(t);
    1619    76238735 :     if (!s) { avma = av; return gen_0; }
    1620    70758006 :     if (s < 0) { avma = (pari_sp)p; return p; }
    1621    31062821 :     if (cmpii(t, m) < 0) return gerepileuptoint(av, t); /* general case ! */
    1622     1122054 :     p = remii(t, m);
    1623             :   }
    1624             :   else
    1625      223168 :     p = modii(p, m);
    1626     1345222 :   return gerepileuptoint(av, p);
    1627             : }
    1628             : INLINE GEN
    1629    75898193 : Fp_sub(GEN a, GEN b, GEN m)
    1630             : {
    1631    75898193 :   pari_sp av=avma;
    1632    75898193 :   GEN p = subii(a,b);
    1633    76202340 :   long s = signe(p);
    1634    76202340 :   if (!s) return p; /* = gen_0 */
    1635    68333799 :   if (s > 0)
    1636             :   {
    1637    32996331 :     if (cmpii(p, m) < 0) return p; /* general case ! */
    1638     1315908 :     p = remii(p, m);
    1639             :   }
    1640             :   else
    1641             :   {
    1642    35337468 :     GEN t = addii(p, m);
    1643    35320175 :     if (!s) { avma = av; return gen_0; }
    1644    35320175 :     if (s > 0) return gerepileuptoint(av, t); /* general case ! */
    1645    35320175 :     p = modii(t, m);
    1646             :   }
    1647    36651898 :   return gerepileuptoint(av, p);
    1648             : }
    1649             : INLINE GEN
    1650    10979353 : Fp_neg(GEN b, GEN m)
    1651             : {
    1652    10979353 :   pari_sp av = avma;
    1653    10979353 :   long s = signe(b);
    1654             :   GEN p;
    1655    10979353 :   if (!s) return gen_0;
    1656     7580908 :   if (s > 0)
    1657             :   {
    1658     7378650 :     p = subii(m, b);
    1659     7378392 :     if (signe(p) >= 0) return p; /* general case ! */
    1660       92460 :     p = modii(p, m);
    1661             :   } else
    1662      202258 :     p = remii(negi(b), m);
    1663      294718 :   return gerepileuptoint(av, p);
    1664             : }
    1665             : 
    1666             : INLINE GEN
    1667       19996 : Fp_halve(GEN a, GEN p)
    1668             : {
    1669       19996 :   if (mpodd(a)) a = addii(a,p);
    1670       19996 :   return shifti(a,-1);
    1671             : }
    1672             : 
    1673             : /* assume 0 <= u < p and ps2 = p>>1 */
    1674             : INLINE GEN
    1675     5861107 : Fp_center(GEN u, GEN p, GEN ps2)
    1676     5861107 : { return abscmpii(u,ps2)<=0? icopy(u): subii(u,p); }
    1677             : 
    1678             : /* x + y*z mod p */
    1679             : INLINE GEN
    1680     7875652 : Fp_addmul(GEN x, GEN y, GEN z, GEN p)
    1681             : {
    1682             :   pari_sp av;
    1683     7875652 :   if (!signe(y) || !signe(z)) return Fp_red(x, p);
    1684     7452070 :   if (!signe(x)) return Fp_mul(z,y, p);
    1685     7151191 :   av = avma;
    1686     7151191 :   return gerepileuptoint(av, modii(addii(x, mulii(y,z)), p));
    1687             : }
    1688             : 
    1689             : INLINE GEN
    1690    64343929 : Fp_mul(GEN a, GEN b, GEN m)
    1691             : {
    1692    64343929 :   pari_sp av=avma;
    1693             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1694    64343929 :   (void)new_chunk(lg(a)+lg(b)+(lg(m)<<1));
    1695    64354438 :   p = mulii(a,b);
    1696    64351824 :   avma = av; return modii(p,m);
    1697             : }
    1698             : INLINE GEN
    1699    61921229 : Fp_sqr(GEN a, GEN m)
    1700             : {
    1701    61921229 :   pari_sp av=avma;
    1702             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1703    61921229 :   (void)new_chunk((lg(a)+lg(m))<<1);
    1704    62180921 :   p = sqri(a);
    1705    62462176 :   avma = av; return remii(p,m); /*Use remii: p >= 0 */
    1706             : }
    1707             : INLINE GEN
    1708    80184742 : Fp_mulu(GEN a, ulong b, GEN m)
    1709             : {
    1710    80184742 :   long l = lgefint(m);
    1711    80184742 :   if (l == 3)
    1712             :   {
    1713    42993581 :     ulong mm = m[2];
    1714    42993581 :     return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1715             :   } else {
    1716    37191161 :     pari_sp av = avma;
    1717             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1718    37191161 :     (void)new_chunk(lg(a)+1+(l<<1));
    1719    37244085 :     p = muliu(a,b);
    1720    36927424 :     avma = av; return modii(p,m);
    1721             :   }
    1722             : }
    1723             : INLINE GEN
    1724           0 : Fp_muls(GEN a, long b, GEN m)
    1725             : {
    1726           0 :   long l = lgefint(m);
    1727           0 :   if (l == 3)
    1728             :   {
    1729           0 :     ulong mm = m[2];
    1730           0 :     if (b < 0)
    1731             :     {
    1732           0 :       ulong t = Fl_mul(umodiu(a, mm), -b, mm);
    1733           0 :       return t? utoipos(mm - t): gen_0;
    1734             :     }
    1735             :     else
    1736           0 :       return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1737             :   } else {
    1738           0 :     pari_sp av = avma;
    1739             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1740           0 :     (void)new_chunk(lg(a)+1+(l<<1));
    1741           0 :     p = mulis(a,b);
    1742           0 :     avma = av; return modii(p,m);
    1743             :   }
    1744             : }
    1745             : 
    1746             : INLINE GEN
    1747     8456506 : Fp_inv(GEN a, GEN m)
    1748             : {
    1749             :   GEN res;
    1750     8456506 :   if (! invmod(a,m,&res)) pari_err_INV("Fp_inv", mkintmod(res,m));
    1751     8456402 :   return res;
    1752             : }
    1753             : INLINE GEN
    1754      296687 : Fp_invsafe(GEN a, GEN m)
    1755             : {
    1756             :   GEN res;
    1757      296687 :   if (! invmod(a,m,&res)) return NULL;
    1758      296687 :   return res;
    1759             : }
    1760             : INLINE GEN
    1761     2296180 : Fp_div(GEN a, GEN b, GEN m)
    1762             : {
    1763     2296180 :   pari_sp av=avma;
    1764             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1765     2296180 :   (void)new_chunk(lg(a)+(lg(m)<<1));
    1766     2296180 :   p = mulii(a, Fp_inv(b,m));
    1767     2296180 :   avma = av; return modii(p,m);
    1768             : }
    1769             : 
    1770             : INLINE GEN
    1771      682452 : Flx_mulu(GEN x, ulong a, ulong p) { return Flx_Fl_mul(x,a%p,p); }
    1772             : 
    1773             : INLINE GEN
    1774           0 : get_F2x_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1775             : 
    1776             : INLINE long
    1777      448057 : get_F2x_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1778             : 
    1779             : INLINE long
    1780      121401 : get_F2x_degree(GEN T) { return typ(T)==t_VEC? F2x_degree(gel(T,2)): F2x_degree(T); }
    1781             : 
    1782             : INLINE GEN
    1783         280 : get_F2xqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1784             : 
    1785             : INLINE long
    1786      376425 : get_F2xqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1787             : 
    1788             : INLINE long
    1789      201418 : get_F2xqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1790             : 
    1791             : INLINE GEN
    1792     5975752 : get_Flx_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1793             : 
    1794             : INLINE long
    1795    16091047 : get_Flx_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1796             : 
    1797             : INLINE long
    1798    30066043 : get_Flx_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1799             : 
    1800             : INLINE GEN
    1801         996 : get_FlxqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1802             : 
    1803             : INLINE long
    1804      354401 : get_FlxqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1805             : 
    1806             : INLINE long
    1807       89578 : get_FlxqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1808             : 
    1809             : INLINE GEN
    1810      406085 : get_FpX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1811             : 
    1812             : INLINE long
    1813     1489150 : get_FpX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1814             : 
    1815             : INLINE long
    1816     1543568 : get_FpX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1817             : 
    1818             : INLINE GEN
    1819      142588 : get_FpXQX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1820             : 
    1821             : INLINE long
    1822       52012 : get_FpXQX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1823             : 
    1824             : INLINE long
    1825        1806 : get_FpXQX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1826             : 
    1827             : /*******************************************************************/
    1828             : /*                                                                 */
    1829             : /*                        ADDMULII / SUBMULII                      */
    1830             : /*                                                                 */
    1831             : /*******************************************************************/
    1832             : /* x - y*z */
    1833             : INLINE GEN
    1834    13208462 : submulii(GEN x, GEN y, GEN z)
    1835             : {
    1836    13208462 :   long lx = lgefint(x), ly, lz;
    1837             :   pari_sp av;
    1838             :   GEN t;
    1839    13208462 :   if (lx == 2) { t = mulii(z,y); togglesign(t); return t; }
    1840    11421470 :   ly = lgefint(y);
    1841    11421470 :   if (ly == 2) return icopy(x);
    1842    10420286 :   lz = lgefint(z);
    1843    10420286 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1844    10420286 :   t = mulii(z, y);
    1845    10420286 :   avma = av; return subii(x,t);
    1846             : }
    1847             : /* y*z - x */
    1848             : INLINE GEN
    1849     3674306 : mulsubii(GEN y, GEN z, GEN x)
    1850             : {
    1851     3674306 :   long lx = lgefint(x), ly, lz;
    1852             :   pari_sp av;
    1853             :   GEN t;
    1854     3674306 :   if (lx == 2) return mulii(z,y);
    1855     2197528 :   ly = lgefint(y);
    1856     2197528 :   if (ly == 2) return negi(x);
    1857     1464640 :   lz = lgefint(z);
    1858     1464640 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1859     1464640 :   t = mulii(z, y);
    1860     1464640 :   avma = av; return subii(t,x);
    1861             : }
    1862             : 
    1863             : /* x - u*y */
    1864             : INLINE GEN
    1865        7371 : submuliu(GEN x, GEN y, ulong u)
    1866             : {
    1867             :   pari_sp av;
    1868        7371 :   long ly = lgefint(y);
    1869        7371 :   if (ly == 2) return icopy(x);
    1870        7371 :   av = avma;
    1871        7371 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1872        7371 :   y = mului(u,y);
    1873        7371 :   avma = av; return subii(x, y);
    1874             : }
    1875             : /* x + u*y */
    1876             : INLINE GEN
    1877        7371 : addmuliu(GEN x, GEN y, ulong u)
    1878             : {
    1879             :   pari_sp av;
    1880        7371 :   long ly = lgefint(y);
    1881        7371 :   if (ly == 2) return icopy(x);
    1882        7371 :   av = avma;
    1883        7371 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1884        7371 :   y = mului(u,y);
    1885        7371 :   avma = av; return addii(x, y);
    1886             : }
    1887             : /* x - u*y */
    1888             : INLINE GEN
    1889   112742270 : submuliu_inplace(GEN x, GEN y, ulong u)
    1890             : {
    1891             :   pari_sp av;
    1892   112742270 :   long ly = lgefint(y);
    1893   112742270 :   if (ly == 2) return x;
    1894    89715555 :   av = avma;
    1895    89715555 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1896    89715555 :   y = mului(u,y);
    1897    89715555 :   avma = av; return subii(x, y);
    1898             : }
    1899             : /* x + u*y */
    1900             : INLINE GEN
    1901   111349124 : addmuliu_inplace(GEN x, GEN y, ulong u)
    1902             : {
    1903             :   pari_sp av;
    1904   111349124 :   long ly = lgefint(y);
    1905   111349124 :   if (ly == 2) return x;
    1906    89316496 :   av = avma;
    1907    89316496 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1908    89316496 :   y = mului(u,y);
    1909    89316496 :   avma = av; return addii(x, y);
    1910             : }
    1911             : /* ux + vy */
    1912             : INLINE GEN
    1913    41113440 : lincombii(GEN u, GEN v, GEN x, GEN y)
    1914             : {
    1915    41113440 :   long lx = lgefint(x), ly;
    1916             :   GEN p1, p2;
    1917             :   pari_sp av;
    1918    41113440 :   if (lx == 2) return mulii(v,y);
    1919    20885530 :   ly = lgefint(y);
    1920    20885530 :   if (ly == 2) return mulii(u,x);
    1921    17895789 :   av = avma; (void)new_chunk(lx+ly+lgefint(u)+lgefint(v)); /* HACK */
    1922    17895789 :   p1 = mulii(u,x);
    1923    17895789 :   p2 = mulii(v,y);
    1924    17895789 :   avma = av; return addii(p1,p2);
    1925             : }
    1926             : 
    1927             : /*******************************************************************/
    1928             : /*                                                                 */
    1929             : /*                          GEN SUBTYPES                           */
    1930             : /*                                                                 */
    1931             : /*******************************************************************/
    1932             : 
    1933             : INLINE int
    1934  1272075224 : is_const_t(long t) { return (t < t_POLMOD); }
    1935             : INLINE int
    1936        5283 : is_extscalar_t(long t) { return (t <= t_POL); }
    1937             : INLINE int
    1938     1021108 : is_intreal_t(long t) { return (t <= t_REAL); }
    1939             : INLINE int
    1940   378013262 : is_matvec_t(long t) { return (t >= t_VEC && t <= t_MAT); }
    1941             : INLINE int
    1942    50320404 : is_noncalc_t(long tx) { return (tx) >= t_LIST; }
    1943             : INLINE int
    1944      754018 : is_rational_t(long t) { return (t == t_INT || t == t_FRAC); }
    1945             : INLINE int
    1946      276325 : is_real_t(long t) { return (t == t_INT || t == t_REAL || t == t_FRAC); }
    1947             : INLINE int
    1948  2807189801 : is_recursive_t(long t) { return lontyp[t]; }
    1949             : INLINE int
    1950   171408050 : is_scalar_t(long t) { return (t < t_POL); }
    1951             : INLINE int
    1952      862213 : is_vec_t(long t) { return (t == t_VEC || t == t_COL); }
    1953             : 
    1954             : /*******************************************************************/
    1955             : /*                                                                 */
    1956             : /*                         TRANSCENDENTAL                          */
    1957             : /*                                                                 */
    1958             : /*******************************************************************/
    1959             : INLINE GEN
    1960    16559684 : sqrtr(GEN x) {
    1961    16559684 :   long s = signe(x);
    1962    16559684 :   if (s == 0) return real_0_bit(expo(x) >> 1);
    1963    16525997 :   if (s >= 0) return sqrtr_abs(x);
    1964       26939 :   retmkcomplex(gen_0, sqrtr_abs(x));
    1965             : }
    1966             : INLINE GEN
    1967           0 : cbrtr_abs(GEN x) { return sqrtnr_abs(x, 3); }
    1968             : INLINE GEN
    1969           0 : cbrtr(GEN x) {
    1970           0 :   long s = signe(x);
    1971             :   GEN r;
    1972           0 :   if (s == 0) return real_0_bit(expo(x) / 3);
    1973           0 :   r = cbrtr_abs(x);
    1974           0 :   if (s < 0) togglesign(r);
    1975           0 :   return r;
    1976             : }
    1977             : INLINE GEN
    1978      283401 : sqrtnr(GEN x, long n) {
    1979      283401 :   long s = signe(x);
    1980             :   GEN r;
    1981      283401 :   if (s == 0) return real_0_bit(expo(x) / n);
    1982      283401 :   r = sqrtnr_abs(x, n);
    1983      283401 :   if (s < 0) pari_err_IMPL("sqrtnr for x < 0");
    1984      283401 :   return r;
    1985             : }
    1986             : INLINE long
    1987      211344 : logint(GEN B, GEN y) { return logintall(B,y,NULL); }
    1988             : INLINE ulong
    1989     8269363 : ulogint(ulong B, ulong y)
    1990             : {
    1991             :   ulong r;
    1992             :   long e;
    1993     8269363 :   if (y == 2) return expu(B);
    1994     8192379 :   r = y;
    1995    27488328 :   for (e=1;; e++)
    1996             :   { /* here, r = y^e, r2 = y^(e-1) */
    1997    27488328 :     if (r >= B) return r == B? e: e-1;
    1998    19295949 :     r = umuluu_or_0(y, r);
    1999    19295949 :     if (!r) return e;
    2000    19295949 :   }
    2001             : }
    2002             : 
    2003             : /*******************************************************************/
    2004             : /*                                                                 */
    2005             : /*                         MISCELLANEOUS                           */
    2006             : /*                                                                 */
    2007             : /*******************************************************************/
    2008     1021031 : INLINE int ismpzero(GEN x) { return is_intreal_t(typ(x)) && !signe(x); }
    2009   520101186 : INLINE int isintzero(GEN x) { return typ(x) == t_INT && !signe(x); }
    2010    10060720 : INLINE int isint1(GEN x) { return typ(x)==t_INT && equali1(x); }
    2011        5103 : INLINE int isintm1(GEN x){ return typ(x)==t_INT && equalim1(x);}
    2012   287160214 : INLINE int equali1(GEN n)
    2013   287160214 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(1)) && n[2] == 1; }
    2014    51604775 : INLINE int equalim1(GEN n)
    2015    51604775 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(-1)) && n[2] == 1; }
    2016             : /* works only for POSITIVE integers */
    2017  1563258962 : INLINE int is_pm1(GEN n)
    2018  1563258962 : { return lgefint(n) == 3 && n[2] == 1; }
    2019   581765327 : INLINE int is_bigint(GEN n)
    2020   581765327 : { long l = lgefint(n); return l > 3 || (l == 3 && (n[2] & HIGHBIT)); }
    2021             : 
    2022  2121414711 : INLINE int odd(long x) { return x & 1; }
    2023    28994165 : INLINE int both_odd(long x, long y) { return x & y & 1; }
    2024             : 
    2025             : INLINE int
    2026  2584380476 : isonstack(GEN x)
    2027  5168760952 : { return ((pari_sp)x >= pari_mainstack->bot
    2028  2584380476 :        && (pari_sp)x <  pari_mainstack->top); }
    2029             : 
    2030             : /* assume x != 0 and x t_REAL, return an approximation to log2(|x|) */
    2031             : INLINE double
    2032    17883518 : dbllog2r(GEN x)
    2033    17883518 : { return log2((double)(ulong)x[2]) + (double)(expo(x) - (BITS_IN_LONG-1)); }
    2034             : 
    2035             : INLINE GEN
    2036      279694 : mul_content(GEN cx, GEN cy)
    2037             : {
    2038      279694 :   if (!cx) return cy;
    2039       95228 :   if (!cy) return cx;
    2040       70411 :   return gmul(cx,cy);
    2041             : }
    2042             : INLINE GEN
    2043     1536886 : mul_denom(GEN dx, GEN dy)
    2044             : {
    2045     1536886 :   if (!dx) return dy;
    2046     1018896 :   if (!dy) return dx;
    2047      315931 :   return mulii(dx,dy);
    2048             : }
    2049             : 
    2050             : /* POLYNOMIALS */
    2051             : INLINE GEN
    2052    17565372 : constant_coeff(GEN x) { return signe(x)? gel(x,2): gen_0; }
    2053             : INLINE GEN
    2054    78621592 : leading_coeff(GEN x) { return lg(x) == 2? gen_0: gel(x,lg(x)-1); }
    2055             : INLINE ulong
    2056      412643 : Flx_lead(GEN x) { return lg(x) == 2? 0: x[lg(x)-1]; }
    2057             : INLINE long
    2058  2781882802 : degpol(GEN x) { return lg(x)-3; }
    2059             : INLINE long
    2060  1371454463 : lgpol(GEN x) { return lg(x)-2; }
    2061             : INLINE long
    2062    98705966 : lgcols(GEN x) { return lg(gel(x,1)); }
    2063             : INLINE long
    2064    20822561 : nbrows(GEN x) { return lg(gel(x,1))-1; }
    2065             : INLINE GEN
    2066           0 : truecoeff(GEN x, long n) { return polcoeff0(x,n,-1); }
    2067             : 
    2068             : INLINE GEN
    2069      432776 : RgXQ_mul(GEN y, GEN x, GEN T) { return RgX_rem(RgX_mul(y, x), T); }
    2070             : INLINE GEN
    2071      281360 : RgXQ_sqr(GEN x, GEN T) { return RgX_rem(RgX_sqr(x), T); }
    2072             : 
    2073             : INLINE GEN
    2074      143451 : ZXQ_mul(GEN y, GEN x, GEN T) { return ZX_rem(ZX_mul(y, x), T); }
    2075             : INLINE GEN
    2076       35161 : ZXQ_sqr(GEN x, GEN T) { return ZX_rem(ZX_sqr(x), T); }
    2077             : 
    2078             : INLINE GEN
    2079    85006234 : RgX_copy(GEN x)
    2080             : {
    2081             :   long lx, i;
    2082    85006234 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
    2083    85006233 :   for (i = 2; i<lx; i++) gel(y,i) = gcopy(gel(x,i));
    2084    85006232 :   return y;
    2085             : }
    2086             : /* have to use ulong to avoid silly warnings from gcc "assuming signed
    2087             :  * overflow does not occur" */
    2088             : INLINE GEN
    2089     2224202 : RgX_coeff(GEN x, long n)
    2090             : {
    2091     2224202 :   ulong l = lg(x);
    2092     2224202 :   return (n < 0 || ((ulong)n+3) > l)? gen_0: gel(x,n+2);
    2093             : }
    2094             : INLINE GEN
    2095      315497 : RgX_renormalize(GEN x) { return RgX_renormalize_lg(x, lg(x)); }
    2096             : INLINE GEN
    2097     6489392 : RgX_div(GEN x, GEN y) { return RgX_divrem(x,y,NULL); }
    2098             : INLINE GEN
    2099        1792 : RgXQX_div(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,NULL); }
    2100             : INLINE GEN
    2101       52061 : RgXQX_rem(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,ONLY_REM); }
    2102             : INLINE GEN
    2103      827318 : FpX_div(GEN x, GEN y, GEN p) { return FpX_divrem(x,y,p, NULL); }
    2104             : INLINE GEN
    2105     3632187 : Flx_div(GEN x, GEN y, ulong p) { return Flx_divrem(x,y,p, NULL); }
    2106             : INLINE GEN
    2107     2990369 : F2x_div(GEN x, GEN y) { return F2x_divrem(x,y, NULL); }
    2108             : INLINE GEN
    2109           0 : FpV_FpC_mul(GEN x, GEN y, GEN p) { return FpV_dotproduct(x,y,p); }
    2110             : INLINE GEN
    2111    44890697 : pol0_Flx(long sv) { return mkvecsmall(sv); }
    2112             : INLINE GEN
    2113    18528522 : pol1_Flx(long sv) { return mkvecsmall2(sv, 1); }
    2114             : INLINE GEN
    2115    18101624 : polx_Flx(long sv) { return mkvecsmall3(sv, 0, 1); }
    2116             : INLINE GEN
    2117           0 : zero_zx(long sv) { return zero_Flx(sv); }
    2118             : INLINE GEN
    2119           0 : polx_zx(long sv) { return polx_Flx(sv); }
    2120             : INLINE GEN
    2121           0 : zx_shift(GEN x, long n) { return Flx_shift(x,n); }
    2122             : INLINE GEN
    2123           0 : zx_renormalize(GEN x, long l) { return Flx_renormalize(x,l); }
    2124             : INLINE GEN
    2125        1383 : zero_F2x(long sv) { return zero_Flx(sv); }
    2126             : INLINE GEN
    2127    11373102 : pol0_F2x(long sv) { return pol0_Flx(sv); }
    2128             : INLINE GEN
    2129     2801730 : pol1_F2x(long sv) { return pol1_Flx(sv); }
    2130             : INLINE GEN
    2131      671804 : polx_F2x(long sv) { return mkvecsmall2(sv, 2); }
    2132             : INLINE int
    2133      815743 : F2x_equal1(GEN x) { return Flx_equal1(x); }
    2134             : INLINE int
    2135     3547127 : F2x_equal(GEN V, GEN W) { return Flx_equal(V,W); }
    2136             : INLINE GEN
    2137    69615247 : F2x_copy(GEN x) { return leafcopy(x); }
    2138             : INLINE GEN
    2139           0 : F2v_copy(GEN x) { return leafcopy(x); }
    2140             : INLINE GEN
    2141     2347064 : Flv_copy(GEN x) { return leafcopy(x); }
    2142             : INLINE GEN
    2143    74703769 : Flx_copy(GEN x) { return leafcopy(x); }
    2144             : INLINE GEN
    2145     1658252 : vecsmall_copy(GEN x) { return leafcopy(x); }
    2146             : INLINE int
    2147     4742377 : Flx_equal1(GEN x) { return degpol(x)==0 && x[2] == 1; }
    2148             : INLINE int
    2149       17635 : ZX_equal1(GEN x) { return degpol(x)==0 && equali1(gel(x,2)); }
    2150             : 
    2151             : INLINE GEN
    2152    43242149 : ZX_renormalize(GEN x, long lx)    { return ZXX_renormalize(x,lx); }
    2153             : INLINE GEN
    2154    54367100 : FpX_renormalize(GEN x, long lx)   { return ZXX_renormalize(x,lx); }
    2155             : INLINE GEN
    2156      961806 : FpXX_renormalize(GEN x, long lx)  { return ZXX_renormalize(x,lx); }
    2157             : INLINE GEN
    2158      993815 : FpXQX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
    2159             : INLINE GEN
    2160   122784710 : F2x_renormalize(GEN x, long lx)   { return Flx_renormalize(x,lx); }
    2161             : INLINE GEN
    2162        8744 : F2v_to_F2x(GEN x, long sv) {
    2163        8744 :   GEN y = leafcopy(x);
    2164        8744 :   y[1] = sv; F2x_renormalize(y, lg(y)); return y;
    2165             : }
    2166             : 
    2167             : INLINE long
    2168         455 : sturm(GEN x) { return sturmpart(x, NULL, NULL); }
    2169             : 
    2170             : INLINE long
    2171        2429 : gval(GEN x, long v) {
    2172        2429 :   pari_sp av = avma;
    2173        2429 :   long n = gvaluation(x, pol_x(v));
    2174        2429 :   avma = av; return n;
    2175             : }
    2176             : 
    2177             : INLINE void
    2178      485426 : RgX_shift_inplace_init(long v)
    2179      485426 : { if (v) (void)cgetg(v, t_VECSMALL); }
    2180             : /* shift polynomial in place. assume v free cells have been left before x */
    2181             : INLINE GEN
    2182      485426 : RgX_shift_inplace(GEN x, long v)
    2183             : {
    2184             :   long i, lx;
    2185             :   GEN y, z;
    2186      485426 :   if (!v) return x;
    2187      253272 :   lx = lg(x);
    2188      253272 :   if (lx == 2) return x;
    2189      253272 :   y = x + v;
    2190      253272 :   z = x + lx;
    2191             :   /* stackdummy from normalizepol: move it up */
    2192      253272 :   if (lg(z) != v) x[lx + v] = z[0];
    2193      253272 :   for (i = lx-1; i >= 2; i--) gel(y,i) = gel(x,i);
    2194      253272 :   for (i = v+1;  i >= 2; i--) gel(x,i) = gen_0;
    2195             :   /* leave x[1] alone: it is correct */
    2196      253272 :   x[0] = evaltyp(t_POL) | evallg(lx+v); return x;
    2197             : }
    2198             : 
    2199             : 
    2200             : /* LINEAR ALGEBRA */
    2201             : INLINE GEN
    2202       68075 : zv_to_ZV(GEN x) { return vecsmall_to_vec(x); }
    2203             : INLINE GEN
    2204     1282798 : zc_to_ZC(GEN x) { return vecsmall_to_col(x); }
    2205             : INLINE GEN
    2206      392124 : ZV_to_zv(GEN x) { return vec_to_vecsmall(x); }
    2207             : INLINE GEN
    2208           0 : zx_to_zv(GEN x, long N) { return Flx_to_Flv(x,N); }
    2209             : INLINE GEN
    2210           0 : zv_to_zx(GEN x, long sv) { return Flv_to_Flx(x,sv); }
    2211             : INLINE GEN
    2212           0 : zm_to_zxV(GEN x, long sv) { return Flm_to_FlxV(x,sv); }
    2213             : INLINE GEN
    2214           0 : zero_zm(long x, long y) { return zero_Flm(x,y); }
    2215             : INLINE GEN
    2216    18064670 : zero_zv(long x) { return zero_Flv(x); }
    2217             : INLINE GEN
    2218         168 : zm_transpose(GEN x) { return Flm_transpose(x); }
    2219             : INLINE GEN
    2220           0 : zm_copy(GEN x) { return Flm_copy(x); }
    2221             : INLINE GEN
    2222     2002568 : zv_copy(GEN x) { return Flv_copy(x); }
    2223             : INLINE GEN
    2224           0 : zm_row(GEN x, long i) { return Flm_row(x,i); }
    2225             : 
    2226             : INLINE GEN
    2227      840045 : ZC_hnfrem(GEN x, GEN y) { return ZC_hnfremdiv(x,y,NULL); }
    2228             : INLINE GEN
    2229       35604 : ZM_hnfrem(GEN x, GEN y) { return ZM_hnfdivrem(x,y,NULL); }
    2230             : INLINE GEN
    2231     1162823 : ZM_lll(GEN x, double D, long f) { return ZM_lll_norms(x,D,f,NULL); }
    2232             : INLINE void
    2233      191759 : RgM_dimensions(GEN x, long *m, long *n) { *n = lg(x)-1; *m = *n? nbrows(x): 0; }
    2234             : INLINE GEN
    2235       43912 : RgM_inv(GEN a) { return RgM_solve(a, NULL); }
    2236             : INLINE GEN
    2237     6776813 : RgM_shallowcopy(GEN x)
    2238             : {
    2239             :   long l;
    2240     6776813 :   GEN y = cgetg_copy(x, &l);
    2241     6776813 :   while (--l > 0) gel(y,l) = leafcopy(gel(x,l));
    2242     6776813 :   return y;
    2243             : }
    2244             : INLINE GEN
    2245         362 : F2m_copy(GEN x) { return RgM_shallowcopy(x); }
    2246             : 
    2247             : INLINE GEN
    2248     1383749 : Flm_copy(GEN x) { return RgM_shallowcopy(x); }
    2249             : 
    2250             : /* divisibility: return 1 if y[i] | x[i] for all i, 0 otherwise. Assume
    2251             :  * x,y are ZV of the same length */
    2252             : INLINE int
    2253       23198 : ZV_dvd(GEN x, GEN y)
    2254             : {
    2255       23198 :   long i, l = lg(x);
    2256       36652 :   for (i=1; i < l; i++)
    2257       29519 :     if ( ! dvdii( gel(x,i), gel(y,i) ) ) return 0;
    2258        7133 :   return 1;
    2259             : }
    2260             : 
    2261             : /* Fq */
    2262             : INLINE GEN
    2263     2223566 : Fq_red(GEN x, GEN T, GEN p)
    2264     2223566 : { return typ(x)==t_INT? Fp_red(x,p): FpXQ_red(x,T,p); }
    2265             : INLINE GEN
    2266       11499 : Fq_to_FpXQ(GEN x, GEN T, GEN p /*unused*/)
    2267             : {
    2268             :   (void) p;
    2269       11499 :   return typ(x)==t_INT ? scalarpol(x, get_FpX_var(T)): x;
    2270             : }
    2271             : 
    2272             : INLINE GEN
    2273         833 : gener_Fq_local(GEN T, GEN p, GEN L)
    2274         833 : { return T? gener_FpXQ_local(T,p, L)
    2275         833 :           : pgener_Fp_local(p, L); }
    2276             : 
    2277             : /* FpXQX */
    2278             : INLINE GEN
    2279        1396 : FpXQX_div(GEN x, GEN y, GEN T, GEN p) { return FpXQX_divrem(x, y, T, p, NULL); }
    2280             : INLINE GEN
    2281       33186 : FlxqX_div(GEN x, GEN y, GEN T, ulong p) { return FlxqX_divrem(x, y, T, p, NULL); }
    2282             : INLINE GEN
    2283       30779 : F2xqX_div(GEN x, GEN y, GEN T) { return F2xqX_divrem(x, y, T, NULL); }
    2284             : 
    2285             : /* FqX */
    2286             : INLINE GEN
    2287       27419 : FqX_red(GEN z, GEN T, GEN p) { return T? FpXQX_red(z, T, p): FpX_red(z, p); }
    2288             : INLINE GEN
    2289      903749 : FqX_add(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2290             : INLINE GEN
    2291       16438 : FqX_neg(GEN x,GEN T,GEN p) { return T? FpXX_neg(x,p): FpX_neg(x,p); }
    2292             : INLINE GEN
    2293        2380 : FqX_sub(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2294             : INLINE GEN
    2295      617158 : FqX_Fp_mul(GEN P, GEN u, GEN T, GEN p)
    2296      617158 : { return T? FpXX_Fp_mul(P, u, p): FpX_Fp_mul(P, u, p); }
    2297             : INLINE GEN
    2298      552395 : FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p)
    2299      552395 : { return typ(U)==t_INT ? FqX_Fp_mul(P, U, T, p): FpXQX_FpXQ_mul(P, U, T, p); }
    2300             : INLINE GEN
    2301       87634 : FqX_mul(GEN x, GEN y, GEN T, GEN p)
    2302       87634 : { return T? FpXQX_mul(x, y, T, p): FpX_mul(x, y, p); }
    2303             : INLINE GEN
    2304      459889 : FqX_mulu(GEN x, ulong y, GEN T, GEN p)
    2305      459889 : { return T? FpXX_mulu(x, y, p): FpX_mulu(x, y, p); }
    2306             : INLINE GEN
    2307        4760 : FqX_sqr(GEN x, GEN T, GEN p)
    2308        4760 : { return T? FpXQX_sqr(x, T, p): FpX_sqr(x, p); }
    2309             : INLINE GEN
    2310        1428 : FqX_powu(GEN x, ulong n, GEN T, GEN p)
    2311        1428 : { return T? FpXQX_powu(x, n, T, p): FpX_powu(x, n, p); }
    2312             : INLINE GEN
    2313        5145 : FqX_div(GEN x, GEN y, GEN T, GEN p)
    2314        5145 : { return T? FpXQX_divrem(x,y,T,p,NULL): FpX_divrem(x,y,p,NULL); }
    2315             : INLINE GEN
    2316        5605 : FqX_get_red(GEN S, GEN T, GEN p)
    2317        5605 : { return T? FpXQX_get_red(S,T,p): FpX_get_red(S,p); }
    2318             : INLINE GEN
    2319       47767 : FqX_rem(GEN x, GEN y, GEN T, GEN p)
    2320       47767 : { return T? FpXQX_rem(x,y,T,p): FpX_rem(x,y,p); }
    2321             : INLINE GEN
    2322         329 : FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2323         329 : { return T? FpXQX_divrem(x,y,T,p,z): FpX_divrem(x,y,p,z); }
    2324             : INLINE GEN
    2325        5957 : FqX_div_by_X_x(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2326        5957 : { return T? FpXQX_div_by_X_x(x,y,T,p,z): FpX_div_by_X_x(x,y,p,z); }
    2327             : INLINE GEN
    2328           0 : FqX_halfgcd(GEN P,GEN Q,GEN T,GEN p)
    2329           0 : {return T? FpXQX_halfgcd(P,Q,T,p): FpX_halfgcd(P,Q,p);}
    2330             : INLINE GEN
    2331      257866 : FqX_gcd(GEN P,GEN Q,GEN T,GEN p)
    2332      257866 : {return T? FpXQX_gcd(P,Q,T,p): FpX_gcd(P,Q,p);}
    2333             : INLINE GEN
    2334       85302 : FqX_extgcd(GEN P,GEN Q,GEN T,GEN p, GEN *U, GEN *V)
    2335       85302 : { return T? FpXQX_extgcd(P,Q,T,p,U,V): FpX_extgcd(P,Q,p,U,V); }
    2336             : INLINE GEN
    2337        3122 : FqX_normalize(GEN z, GEN T, GEN p) { return T? FpXQX_normalize(z, T, p): FpX_normalize(z, p); }
    2338             : INLINE GEN
    2339      270081 : FqX_deriv(GEN f, /*unused*/GEN T, GEN p) { (void)T; return FpXX_deriv(f, p); }
    2340             : INLINE GEN
    2341       72961 : FqX_factor(GEN f, GEN T, GEN p) { return T?FpXQX_factor(f, T, p): FpX_factor(f, p); }
    2342             : INLINE GEN
    2343        6391 : FqX_roots(GEN f, GEN T, GEN p) { return T?FpXQX_roots(f, T, p): FpX_roots(f, p); }
    2344             : 
    2345             : /*FqXQ*/
    2346             : INLINE GEN
    2347           0 : FqXQ_add(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2348           0 : { (void)S; return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2349             : INLINE GEN
    2350           0 : FqXQ_sub(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2351           0 : { (void)S; return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2352             : INLINE GEN
    2353           0 : FqXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p)
    2354           0 : { return T? FpXQXQ_div(x,y,S,T,p): FpXQ_div(x,y,S,p); }
    2355             : INLINE GEN
    2356           0 : FqXQ_inv(GEN x, GEN S, GEN T, GEN p)
    2357           0 : { return T? FpXQXQ_inv(x,S,T,p): FpXQ_inv(x,S,p); }
    2358             : INLINE GEN
    2359           0 : FqXQ_invsafe(GEN x, GEN S, GEN T, GEN p)
    2360           0 : { return T? FpXQXQ_invsafe(x,S,T,p): FpXQ_inv(x,S,p); }
    2361             : INLINE GEN
    2362       21018 : FqXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p)
    2363       21018 : { return T? FpXQXQ_mul(x,y,S,T,p): FpXQ_mul(x,y,S,p); }
    2364             : INLINE GEN
    2365           0 : FqXQ_sqr(GEN x, GEN S, GEN T, GEN p)
    2366           0 : { return T? FpXQXQ_sqr(x,S,T,p): FpXQ_sqr(x,S,p); }
    2367             : INLINE GEN
    2368           0 : FqXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p)
    2369           0 : { return T? FpXQXQ_pow(x,n,S,T,p): FpXQ_pow(x,n,S,p); }
    2370             : 
    2371             : /*FpXQ*/
    2372             : INLINE GEN
    2373           0 : FpXQ_add(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2374           0 : { (void)T; return FpX_add(x,y,p); }
    2375             : INLINE GEN
    2376           0 : FpXQ_sub(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2377           0 : { (void)T; return FpX_sub(x,y,p); }
    2378             : 
    2379             : /*Flxq*/
    2380             : INLINE GEN
    2381           0 : Flxq_add(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2382           0 : { (void)T; return Flx_add(x,y,p); }
    2383             : INLINE GEN
    2384           0 : Flxq_sub(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2385           0 : { (void)T; return Flx_sub(x,y,p); }
    2386             : 
    2387             : /* F2x */
    2388             : 
    2389             : INLINE ulong
    2390   168914536 : F2x_coeff(GEN x,long v)
    2391             : {
    2392   168914536 :    ulong u=(ulong)x[2+divsBIL(v)];
    2393   168914436 :    return (u>>remsBIL(v))&1UL;
    2394             : }
    2395             : 
    2396             : INLINE void
    2397     4180114 : F2x_clear(GEN x,long v)
    2398             : {
    2399     4180114 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2400     4180114 :    *u&=~(1UL<<remsBIL(v));
    2401     4180114 : }
    2402             : 
    2403             : INLINE void
    2404    38818428 : F2x_set(GEN x,long v)
    2405             : {
    2406    38818428 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2407    38820087 :    *u|=1UL<<remsBIL(v);
    2408    38822519 : }
    2409             : 
    2410             : INLINE void
    2411     1360015 : F2x_flip(GEN x,long v)
    2412             : {
    2413     1360015 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2414     1360015 :    *u^=1UL<<remsBIL(v);
    2415     1360015 : }
    2416             : 
    2417             : /* F2v */
    2418             : 
    2419             : INLINE ulong
    2420   162414928 : F2v_coeff(GEN x,long v) { return F2x_coeff(x,v-1); }
    2421             : 
    2422             : INLINE void
    2423     4180114 : F2v_clear(GEN x,long v) { F2x_clear(x,v-1); }
    2424             : 
    2425             : INLINE void
    2426    12561215 : F2v_set(GEN x,long v)   { F2x_set(x,v-1); }
    2427             : 
    2428             : INLINE void
    2429     1360015 : F2v_flip(GEN x,long v) { F2x_flip(x,v-1); }
    2430             : 
    2431             : /* F2m */
    2432             : 
    2433             : INLINE ulong
    2434    19319262 : F2m_coeff(GEN x, long a, long b) { return F2v_coeff(gel(x,b), a); }
    2435             : 
    2436             : INLINE void
    2437           0 : F2m_clear(GEN x, long a, long b) { F2v_clear(gel(x,b), a); }
    2438             : 
    2439             : INLINE void
    2440     2352087 : F2m_set(GEN x, long a, long b) { F2v_set(gel(x,b), a); }
    2441             : 
    2442             : INLINE void
    2443     1360015 : F2m_flip(GEN x, long a, long b) { F2v_flip(gel(x,b), a); }
    2444             : 
    2445             : /* ARITHMETIC */
    2446             : INLINE GEN
    2447        1029 : matpascal(long n) { return matqpascal(n, NULL); }
    2448             : INLINE long
    2449     2225428 : Z_issquare(GEN x) { return Z_issquareall(x, NULL); }
    2450             : INLINE long
    2451          14 : Z_ispower(GEN x, ulong k) { return Z_ispowerall(x, k, NULL); }
    2452             : INLINE GEN
    2453     5425298 : sqrti(GEN x) { return sqrtremi(x,NULL); }
    2454             : INLINE GEN
    2455     7403535 : gaddgs(GEN y, long s) { return gaddsg(s,y); }
    2456             : INLINE int
    2457       23890 : gcmpgs(GEN y, long s) { return -gcmpsg(s,y); }
    2458             : INLINE int
    2459       24367 : gequalgs(GEN y, long s) { return gequalsg(s,y); }
    2460             : INLINE GEN
    2461           0 : gmaxsg(long s, GEN y) { return gmaxgs(y,s); }
    2462             : INLINE GEN
    2463           0 : gminsg(long s, GEN y) { return gmings(y,s); }
    2464             : INLINE GEN
    2465    13262836 : gmulgs(GEN y, long s) { return gmulsg(s,y); }
    2466             : INLINE GEN
    2467      558170 : gsubgs(GEN y, long s) { return gaddgs(y, -s); }
    2468             : INLINE GEN
    2469      462774 : gdivsg(long s, GEN y) { return gdiv(stoi(s), y); }
    2470             : 
    2471             : /* x t_COMPLEX */
    2472             : INLINE GEN
    2473     9741721 : cxnorm(GEN x) { return gadd(gsqr(gel(x,1)), gsqr(gel(x,2))); }
    2474             : /* q t_QUAD */
    2475             : INLINE GEN
    2476         623 : quadnorm(GEN q)
    2477             : {
    2478         623 :   GEN X = gel(q,1), b = gel(X,3), c = gel(X,2);
    2479         623 :   GEN z, u = gel(q,3), v = gel(q,2);
    2480         623 :   if (typ(u) == t_INT && typ(v) == t_INT) /* generic case */
    2481             :   {
    2482         308 :     z = signe(b)? mulii(v, addii(u,v)): sqri(v);
    2483         308 :     return addii(z, mulii(c, sqri(u)));
    2484             :   }
    2485             :   else
    2486             :   {
    2487         315 :     z = signe(b)? gmul(v, gadd(u,v)): gsqr(v);
    2488         315 :     return gadd(z, gmul(c, gsqr(u)));
    2489             :   }
    2490             : }
    2491             : /* x a t_QUAD, return the attached discriminant */
    2492             : INLINE GEN
    2493         252 : quad_disc(GEN x)
    2494             : {
    2495         252 :   GEN Q = gel(x,1), b = gel(Q,3), c = gel(Q,2), c4;
    2496         252 :   if (is_pm1(b))
    2497             :   {
    2498         196 :     pari_sp av = avma; (void)new_chunk(lgefint(c) + 1);
    2499         196 :     c4 = shifti(c,2); avma = av; return subsi(1, c4);
    2500             :   }
    2501          56 :   c4 = shifti(c,2); togglesign_safe(&c4); return c4;
    2502             : }
    2503             : INLINE GEN
    2504     6345364 : qfb_disc3(GEN x, GEN y, GEN z) { return subii(sqri(y), shifti(mulii(x,z),2)); }
    2505             : INLINE GEN
    2506     6264528 : qfb_disc(GEN x) { return qfb_disc3(gel(x,1), gel(x,2), gel(x,3)); }
    2507             : 
    2508             : INLINE GEN
    2509     1245037 : sqrfrac(GEN x)
    2510             : {
    2511     1245037 :   GEN z = cgetg(3,t_FRAC);
    2512     1245037 :   gel(z,1) = sqri(gel(x,1));
    2513     1245037 :   gel(z,2) = sqri(gel(x,2)); return z;
    2514             : }
    2515             : 
    2516             : INLINE void
    2517    17521003 : normalize_frac(GEN z) {
    2518    17521003 :   if (signe(gel(z,2)) < 0) { togglesign(gel(z,1)); setabssign(gel(z,2)); }
    2519    17521003 : }
    2520             : 
    2521             : INLINE GEN
    2522      231714 : powii(GEN x, GEN n)
    2523             : {
    2524      231714 :   long ln = lgefint(n);
    2525      231714 :   if (ln == 3) {
    2526             :     GEN z;
    2527      228501 :     if (signe(n) > 0) return powiu(x, n[2]);
    2528        4956 :     z = cgetg(3, t_FRAC);
    2529        4956 :     gel(z,1) = gen_1;
    2530        4956 :     gel(z,2) = powiu(x, n[2]);
    2531        4956 :     return z;
    2532             :   }
    2533        3213 :   if (ln == 2) return gen_1; /* rare */
    2534             :   /* should never happen */
    2535           0 :   return powgi(x, n); /* overflow unless x = 0, 1, -1 */
    2536             : }
    2537             : INLINE GEN
    2538        1477 : powIs(long n) {
    2539        1477 :   switch(n & 3)
    2540             :   {
    2541           7 :     case 1: return mkcomplex(gen_0,gen_1);
    2542         364 :     case 2: return gen_m1;
    2543         455 :     case 3: return mkcomplex(gen_0,gen_m1);
    2544             :   }
    2545         651 :   return gen_1;
    2546             : }
    2547             : 
    2548             : /*******************************************************************/
    2549             : /*                                                                 */
    2550             : /*                             ASSIGNMENTS                         */
    2551             : /*                                                                 */
    2552             : /*******************************************************************/
    2553           0 : INLINE void mpexpz(GEN x, GEN z)
    2554           0 : { pari_sp av = avma; gaffect(mpexp(x), z); avma = av; }
    2555           0 : INLINE void mplogz(GEN x, GEN z)
    2556           0 : { pari_sp av = avma; gaffect(mplog(x), z); avma = av; }
    2557           0 : INLINE void mpcosz(GEN x, GEN z)
    2558           0 : { pari_sp av = avma; gaffect(mpcos(x), z); avma = av; }
    2559           0 : INLINE void mpsinz(GEN x, GEN z)
    2560           0 : { pari_sp av = avma; gaffect(mpsin(x), z); avma = av; }
    2561           0 : INLINE void gnegz(GEN x, GEN z)
    2562           0 : { pari_sp av = avma; gaffect(gneg(x), z); avma = av; }
    2563           0 : INLINE void gabsz(GEN x, long prec, GEN z)
    2564           0 : { pari_sp av = avma; gaffect(gabs(x,prec), z); avma = av; }
    2565       23318 : INLINE void gaddz(GEN x, GEN y, GEN z)
    2566       23318 : { pari_sp av = avma; gaffect(gadd(x,y), z); avma = av; }
    2567           0 : INLINE void gsubz(GEN x, GEN y, GEN z)
    2568           0 : { pari_sp av = avma; gaffect(gsub(x,y), z); avma = av; }
    2569       11673 : INLINE void gmulz(GEN x, GEN y, GEN z)
    2570       11673 : { pari_sp av = avma; gaffect(gmul(x,y), z); avma = av; }
    2571           0 : INLINE void gdivz(GEN x, GEN y, GEN z)
    2572           0 : { pari_sp av = avma; gaffect(gdiv(x,y), z); avma = av; }
    2573           0 : INLINE void gdiventz(GEN x, GEN y, GEN z)
    2574           0 : { pari_sp av = avma; gaffect(gdivent(x,y), z); avma = av; }
    2575           0 : INLINE void gmodz(GEN x, GEN y, GEN z)
    2576           0 : { pari_sp av = avma; gaffect(gmod(x,y), z); avma = av; }
    2577           0 : INLINE void gmul2nz(GEN x, long s, GEN z)
    2578           0 : { pari_sp av = avma; gaffect(gmul2n(x,s), z); avma = av; }
    2579           0 : INLINE void gshiftz(GEN x, long s, GEN z)
    2580           0 : { pari_sp av = avma; gaffect(gshift(x,s), z); avma = av; }
    2581             : 
    2582             : /*******************************************************************/
    2583             : /*                                                                 */
    2584             : /*                       ELLIPTIC CURVES                           */
    2585             : /*                                                                 */
    2586             : /*******************************************************************/
    2587     5287715 : INLINE GEN ell_get_a1(GEN e) { return gel(e,1); }
    2588     3095171 : INLINE GEN ell_get_a2(GEN e) { return gel(e,2); }
    2589     4515902 : INLINE GEN ell_get_a3(GEN e) { return gel(e,3); }
    2590     3888005 : INLINE GEN ell_get_a4(GEN e) { return gel(e,4); }
    2591     4704352 : INLINE GEN ell_get_a6(GEN e) { return gel(e,5); }
    2592     3968891 : INLINE GEN ell_get_b2(GEN e) { return gel(e,6); }
    2593     1021637 : INLINE GEN ell_get_b4(GEN e) { return gel(e,7); }
    2594     1627613 : INLINE GEN ell_get_b6(GEN e) { return gel(e,8); }
    2595     1464204 : INLINE GEN ell_get_b8(GEN e) { return gel(e,9); }
    2596     5899340 : INLINE GEN ell_get_c4(GEN e) { return gel(e,10); }
    2597     7931182 : INLINE GEN ell_get_c6(GEN e) { return gel(e,11); }
    2598     9365459 : INLINE GEN ell_get_disc(GEN e) { return gel(e,12); }
    2599     1027341 : INLINE GEN ell_get_j(GEN e) { return gel(e,13); }
    2600     7907941 : INLINE long ell_get_type(GEN e) { return mael(e,14,1); }
    2601     1561498 : INLINE GEN ellff_get_field(GEN x) { return gmael(x, 15, 1); }
    2602      678312 : INLINE GEN ellff_get_a4a6(GEN x)  { return gmael(x, 15, 2); }
    2603         917 : INLINE GEN ellQp_get_zero(GEN x) { return gmael(x, 15, 1); }
    2604         287 : INLINE long ellQp_get_prec(GEN E) { GEN z = ellQp_get_zero(E); return valp(z); }
    2605         623 : INLINE GEN ellQp_get_p(GEN E) { GEN z = ellQp_get_zero(E); return gel(z,2); }
    2606       36960 : INLINE long ellR_get_prec(GEN x) { return nbits2prec(mael3(x, 15, 1, 1)); }
    2607        8262 : INLINE long ellR_get_sign(GEN x) { return mael3(x, 15, 1, 2); }
    2608      501578 : INLINE GEN ellnf_get_nf(GEN x) { return checknf_i(gmael(x,15,1)); }
    2609          49 : INLINE GEN ellnf_get_bnf(GEN x) { return checkbnf_i(gmael(x,15,1)); }
    2610             : 
    2611    21510996 : INLINE int ell_is_inf(GEN z) { return lg(z) == 2; }
    2612      787451 : INLINE GEN ellinf(void) { return mkvec(gen_0); }
    2613             : 
    2614             : /*******************************************************************/
    2615             : /*                                                                 */
    2616             : /*                    ALGEBRAIC NUMBER THEORY                      */
    2617             : /*                                                                 */
    2618             : /*******************************************************************/
    2619     8123314 : INLINE GEN modpr_get_pr(GEN x)  { return gel(x,3); }
    2620      609923 : INLINE GEN modpr_get_p(GEN x)  { return pr_get_p(modpr_get_pr(x)); }
    2621     2520010 : INLINE GEN modpr_get_T(GEN x)  { return lg(x) == 4? NULL: gel(x,4); }
    2622             : 
    2623    18283531 : INLINE GEN pr_get_p(GEN pr)  { return gel(pr,1); }
    2624     4838271 : INLINE GEN pr_get_gen(GEN pr){ return gel(pr,2); }
    2625             : /* .[2] instead of itos works: e and f are small positive integers */
    2626     2226406 : INLINE long pr_get_e(GEN pr) { return gel(pr,3)[2]; }
    2627     7775032 : INLINE long pr_get_f(GEN pr) { return gel(pr,4)[2]; }
    2628     5792168 : INLINE GEN pr_get_tau(GEN pr){ return gel(pr,5); }
    2629             : INLINE int
    2630     2344286 : pr_is_inert(GEN P) { return pr_get_f(P) == lg(pr_get_gen(P))-1; }
    2631             : INLINE GEN
    2632      206850 : pr_norm(GEN pr) { return powiu(pr_get_p(pr), pr_get_f(pr)); }
    2633             : INLINE ulong
    2634       40873 : upr_norm(GEN pr) { return upowuu(pr_get_p(pr)[2], pr_get_f(pr)); }
    2635             : 
    2636             : /* assume nf a genuine nf */
    2637             : INLINE long
    2638        4185 : nf_get_varn(GEN nf) { return varn(gel(nf,1)); }
    2639             : INLINE GEN
    2640    27095341 : nf_get_pol(GEN nf) { return gel(nf,1); }
    2641             : INLINE long
    2642    21248968 : nf_get_degree(GEN nf) { return degpol( nf_get_pol(nf) ); }
    2643             : INLINE long
    2644     1274407 : nf_get_r1(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,1)); }
    2645             : INLINE long
    2646        8197 : nf_get_r2(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,2)); }
    2647             : INLINE GEN
    2648       46797 : nf_get_disc(GEN nf) { return gel(nf,3); }
    2649             : INLINE GEN
    2650      751940 : nf_get_index(GEN nf) { return gel(nf,4); }
    2651             : INLINE GEN
    2652     1215467 : nf_get_M(GEN nf) { return gmael(nf,5,1); }
    2653             : INLINE GEN
    2654       60567 : nf_get_G(GEN nf) { return gmael(nf,5,2); }
    2655             : INLINE GEN
    2656      440320 : nf_get_roundG(GEN nf) { return gmael(nf,5,3); }
    2657             : INLINE GEN
    2658       24339 : nf_get_Tr(GEN nf) { return gmael(nf,5,4); }
    2659             : INLINE GEN
    2660        2191 : nf_get_diff(GEN nf) { return gmael(nf,5,5); }
    2661             : INLINE GEN
    2662          28 : nf_get_ramified_primes(GEN nf) { return gmael(nf,5,8); }
    2663             : INLINE GEN
    2664      158004 : nf_get_roots(GEN nf) { return gel(nf,6); }
    2665             : INLINE GEN
    2666          77 : nf_get_zk(GEN nf)
    2667             : {
    2668          77 :   GEN y = gel(nf,7), D = nf_get_zkden(nf);
    2669          77 :   if (!equali1(D)) y = gdiv(y, D);
    2670          77 :   return y;
    2671             : }
    2672             : INLINE GEN
    2673      219876 : nf_get_zkprimpart(GEN nf)
    2674             : {
    2675      219876 :   GEN y = gel(nf,7);
    2676             :   /* test for old format of nf.zk: non normalized */
    2677      219876 :   if (!equali1(gel(nf,4)) && gequal1(gel(y,1))) y = Q_remove_denom(y,NULL);
    2678      219876 :   return y;
    2679             : }
    2680             : INLINE GEN
    2681      222473 : nf_get_zkden(GEN nf)
    2682             : {
    2683      222473 :   GEN y = gel(nf,7), D = gel(y,1);
    2684      222473 :   if (typ(D) == t_POL) D = gel(D,2);
    2685             :   /* test for old format of nf.zk: non normalized */
    2686      222473 :   if (!equali1(gel(nf,4)) && equali1(D)) D = Q_denom(y);
    2687      222473 :   return D;
    2688             : }
    2689             : INLINE GEN
    2690     2176443 : nf_get_invzk(GEN nf) { return gel(nf,8); }
    2691             : INLINE void
    2692       13734 : nf_get_sign(GEN nf, long *r1, long *r2)
    2693             : {
    2694       13734 :   GEN x = gel(nf,2);
    2695       13734 :   *r1 = itou(gel(x,1));
    2696       13734 :   *r2 = itou(gel(x,2));
    2697       13734 : }
    2698             : 
    2699             : INLINE GEN
    2700       49616 : abgrp_get_no(GEN x) { return gel(x,1); }
    2701             : INLINE GEN
    2702     2033778 : abgrp_get_cyc(GEN x) { return gel(x,2); }
    2703             : INLINE GEN
    2704      396461 : abgrp_get_gen(GEN x) { return gel(x,3); }
    2705             : INLINE GEN
    2706     2064067 : bnf_get_nf(GEN bnf) { return gel(bnf,7); }
    2707             : INLINE GEN
    2708      806355 : bnf_get_clgp(GEN bnf) { return gmael(bnf,8,1); }
    2709             : INLINE GEN
    2710        4536 : bnf_get_no(GEN bnf) { return abgrp_get_no(bnf_get_clgp(bnf)); }
    2711             : INLINE GEN
    2712      434282 : bnf_get_cyc(GEN bnf) { return abgrp_get_cyc(bnf_get_clgp(bnf)); }
    2713             : INLINE GEN
    2714      367208 : bnf_get_gen(GEN bnf)  { return abgrp_get_gen(bnf_get_clgp(bnf)); }
    2715             : INLINE GEN
    2716         860 : bnf_get_reg(GEN bnf) { return gmael(bnf,8,2); }
    2717             : INLINE GEN
    2718      482141 : bnf_get_logfu(GEN bnf) { return gel(bnf,3); }
    2719             : INLINE GEN
    2720        5867 : bnf_get_tuU(GEN bnf) { return gmael3(bnf,8,4,2); }
    2721             : INLINE long
    2722       24535 : bnf_get_tuN(GEN bnf) { return gmael3(bnf,8,4,1)[2]; }
    2723             : INLINE GEN
    2724        1806 : bnf_get_fu(GEN bnf) {
    2725        1806 :   GEN fu = bnf_get_fu_nocheck(bnf);
    2726        1806 :   if (typ(fu) == t_MAT) pari_err(e_MISC,"missing units in bnf");
    2727        1806 :   return fu;
    2728             : }
    2729             : INLINE GEN
    2730        7134 : bnf_get_fu_nocheck(GEN bnf) { return gmael(bnf,8,5); }
    2731             : 
    2732             : INLINE GEN
    2733      747465 : bnr_get_bnf(GEN bnr) { return gel(bnr,1); }
    2734             : INLINE GEN
    2735      384509 : bnr_get_bid(GEN bnr) { return gel(bnr,2); }
    2736             : INLINE GEN
    2737       18102 : bnr_get_mod(GEN bnr) { return gmael(bnr,2,1); }
    2738             : INLINE GEN
    2739       27104 : bnr_get_nf(GEN bnr) { return gmael(bnr,1,7); }
    2740             : INLINE GEN
    2741      520568 : bnr_get_clgp(GEN bnr) { return gel(bnr,5); }
    2742             : INLINE GEN
    2743       45080 : bnr_get_no(GEN bnr) { return abgrp_get_no(bnr_get_clgp(bnr)); }
    2744             : INLINE GEN
    2745      463560 : bnr_get_cyc(GEN bnr) { return abgrp_get_cyc(bnr_get_clgp(bnr)); }
    2746             : INLINE GEN
    2747          70 : bnr_get_gen_nocheck(GEN bnr) { return abgrp_get_gen(bnr_get_clgp(bnr)); }
    2748             : INLINE GEN
    2749       11025 : bnr_get_gen(GEN bnr) {
    2750       11025 :   GEN G = bnr_get_clgp(bnr);
    2751       11025 :   if (lg(G) !=  4)
    2752           0 :     pari_err(e_MISC,"missing bnr generators: please use bnrinit(,,1)");
    2753       11025 :   return gel(G,3);
    2754             : }
    2755             : 
    2756             : INLINE GEN
    2757      302504 : bid_get_mod(GEN bid) { return gel(bid,1); }
    2758             : INLINE GEN
    2759       44681 : bid_get_ideal(GEN bid) { return gmael(bid,1,1); }
    2760             : INLINE GEN
    2761         448 : bid_get_arch(GEN bid) { return gmael(bid,1,2); }
    2762             : INLINE GEN
    2763     1061330 : bid_get_grp(GEN bid) { return gel(bid,2); }
    2764             : INLINE GEN
    2765      395912 : bid_get_fact(GEN bid) { return gmael(bid,3,1); }
    2766             : INLINE GEN
    2767      354612 : bid_get_fact2(GEN bid) { return gmael(bid,3,2); }
    2768             : INLINE GEN
    2769      354682 : bid_get_sprk(GEN bid) { return gmael(bid,4,1); }
    2770             : INLINE GEN
    2771       29813 : bid_get_sarch(GEN bid) { return gmael(bid,4,2); }
    2772             : INLINE GEN
    2773      375262 : bid_get_archp(GEN bid) { return gmael3(bid,4,2,2); }
    2774             : INLINE GEN
    2775      657396 : bid_get_U(GEN bid) { return gel(bid,5); }
    2776             : INLINE GEN
    2777           0 : bid_get_no(GEN bid) { return abgrp_get_no(bid_get_grp(bid)); }
    2778             : INLINE GEN
    2779     1033043 : bid_get_cyc(GEN bid) { return abgrp_get_cyc(bid_get_grp(bid)); }
    2780             : INLINE GEN
    2781           0 : bid_get_gen_nocheck(GEN bid)  { return abgrp_get_gen(bid_get_grp(bid)); }
    2782             : INLINE GEN
    2783       27692 : bid_get_gen(GEN bid) {
    2784       27692 :   GEN G = bid_get_grp(bid);
    2785       27692 :   if (lg(G) != 4) pari_err(e_MISC,"missing bid generators. Use idealstar(,,2)");
    2786       27692 :   return abgrp_get_gen(G);
    2787             : }
    2788             : 
    2789             : INLINE GEN
    2790     2519832 : znstar_get_N(GEN G) { return gmael(G,1,1); }
    2791             : INLINE GEN
    2792     2800315 : znstar_get_faN(GEN G) { return gel(G,3); }
    2793             : INLINE GEN
    2794           0 : znstar_get_no(GEN G) { return abgrp_get_no(gel(G,2)); }
    2795             : INLINE GEN
    2796      101479 : znstar_get_cyc(GEN G) { return abgrp_get_cyc(gel(G,2)); }
    2797             : INLINE GEN
    2798           0 : znstar_get_gen(GEN G) { return abgrp_get_gen(gel(G,2)); }
    2799             : INLINE GEN
    2800     2735887 : znstar_get_conreycyc(GEN G) { return gmael(G,4,5); }
    2801             : INLINE GEN
    2802     1260686 : znstar_get_conreygen(GEN G) { return gmael(G,4,4); }
    2803             : INLINE GEN
    2804       40103 : znstar_get_Ui(GEN G) { return gmael(G,4,3); }
    2805             : INLINE GEN
    2806       28322 : znstar_get_U(GEN G) { return gel(G,5); }
    2807             : INLINE GEN
    2808     1223516 : znstar_get_pe(GEN G) { return gmael(G,4,1); }
    2809             : INLINE GEN
    2810       19152 : gal_get_pol(GEN gal) { return gel(gal,1); }
    2811             : INLINE GEN
    2812        1225 : gal_get_p(GEN gal) { return gmael(gal,2,1); }
    2813             : INLINE GEN
    2814          63 : gal_get_e(GEN gal) { return gmael(gal,2,2); }
    2815             : INLINE GEN
    2816       15631 : gal_get_mod(GEN gal) { return gmael(gal,2,3); }
    2817             : INLINE GEN
    2818       16009 : gal_get_roots(GEN gal) { return gel(gal,3); }
    2819             : INLINE GEN
    2820       15631 : gal_get_invvdm(GEN gal) { return gel(gal,4); }
    2821             : INLINE GEN
    2822       15631 : gal_get_den(GEN gal) { return gel(gal,5); }
    2823             : INLINE GEN
    2824       61516 : gal_get_group(GEN gal) { return gel(gal,6); }
    2825             : INLINE GEN
    2826        3927 : gal_get_gen(GEN gal) { return gel(gal,7); }
    2827             : INLINE GEN
    2828        3577 : gal_get_orders(GEN gal) { return gel(gal,8); }
    2829             : 
    2830             : /* assume rnf a genuine rnf */
    2831             : INLINE long
    2832      944804 : rnf_get_degree(GEN rnf) { return degpol(rnf_get_pol(rnf)); }
    2833             : INLINE long
    2834       15274 : rnf_get_nfdegree(GEN rnf) { return degpol(nf_get_pol(rnf_get_nf(rnf))); }
    2835             : INLINE long
    2836      763693 : rnf_get_absdegree(GEN rnf) { return degpol(gmael(rnf,11,1)); }
    2837             : INLINE GEN
    2838         462 : rnf_get_idealdisc(GEN rnf) { return gmael(rnf,3,1); }
    2839             : INLINE GEN
    2840         448 : rnf_get_k(GEN rnf) { return gmael(rnf,11,3); }
    2841             : INLINE GEN
    2842         448 : rnf_get_alpha(GEN rnf) { return gmael(rnf, 11, 2); }
    2843             : INLINE GEN
    2844      128744 : rnf_get_nf(GEN rnf) { return gel(rnf,10); }
    2845             : INLINE void
    2846        2485 : rnf_get_nfzk(GEN rnf, GEN *b, GEN *cb) {*b=gmael(rnf,2,1); *cb=gmael(rnf,2,2);}
    2847             : INLINE GEN
    2848       97384 : rnf_get_polabs(GEN rnf) { return gmael(rnf,11,1); }
    2849             : INLINE GEN
    2850     1099035 : rnf_get_pol(GEN rnf) { return gel(rnf,1); }
    2851             : INLINE GEN
    2852          63 : rnf_get_disc(GEN rnf) { return gel(rnf,3); }
    2853             : INLINE GEN
    2854         105 : rnf_get_index(GEN rnf) { return gel(rnf,4); }
    2855             : INLINE long
    2856           0 : rnf_get_varn(GEN rnf) { return varn(gel(rnf,1)); }
    2857             : INLINE GEN
    2858      108150 : rnf_get_nfpol(GEN rnf) { return gmael(rnf,10,1); }
    2859             : INLINE long
    2860         595 : rnf_get_nfvarn(GEN rnf) { return varn(gmael(rnf,10,1)); }
    2861             : INLINE GEN
    2862        2856 : rnf_get_zk(GEN rnf) { return gel(rnf,7); }
    2863             : INLINE GEN
    2864       35287 : rnf_get_map(GEN rnf) { return gel(rnf,11); }
    2865             : INLINE GEN
    2866        1190 : rnf_get_invzk(GEN rnf) { return gel(rnf,8); }
    2867             : 
    2868             : /* I integral ZM (not HNF), G ZM, rounded Cholesky form of a weighted
    2869             :  * T2 matrix. Reduce I wrt G */
    2870             : INLINE GEN
    2871       13132 : idealpseudored(GEN I, GEN G)
    2872       13132 : { return ZM_mul(I, ZM_lll(ZM_mul(G, I), 0.99, LLL_IM)); }
    2873             : 
    2874             : /* I integral (not necessarily HNF), G ZM, rounded Cholesky form of a weighted
    2875             :  * T2 matrix. Return m in I with T2(m) small */
    2876             : INLINE GEN
    2877      157002 : idealpseudomin(GEN I, GEN G)
    2878             : {
    2879      157002 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2880      157002 :   return ZM_ZC_mul(I, gel(u,1));
    2881             : }
    2882             : /* I, G as in idealpseudomin. Return an irrational m in I with T2(m) small */
    2883             : INLINE GEN
    2884      300506 : idealpseudomin_nonscalar(GEN I, GEN G)
    2885             : {
    2886      300506 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2887      300506 :   GEN m = ZM_ZC_mul(I, gel(u,1));
    2888      300506 :   if (ZV_isscalar(m) && lg(u) > 2) m = ZM_ZC_mul(I, gel(u,2));
    2889      300506 :   return m;
    2890             : }
    2891             : 
    2892             : INLINE GEN
    2893           0 : idealred_elt(GEN nf, GEN I) {
    2894           0 :   pari_sp av = avma;
    2895           0 :   GEN u = idealpseudomin(I, nf_get_roundG(nf));
    2896           0 :   return gerepileupto(av, u);
    2897             : }
    2898             : INLINE GEN
    2899      162736 : idealred(GEN nf, GEN I) { return idealred0(nf, I, NULL); }
    2900             : 
    2901             : INLINE GEN
    2902        1302 : idealchineseinit(GEN nf, GEN x)
    2903        1302 : { return idealchinese(nf,x,NULL); }
    2904             : 
    2905             : /*******************************************************************/
    2906             : /*                                                                 */
    2907             : /*                              CLOSURES                           */
    2908             : /*                                                                 */
    2909             : /*******************************************************************/
    2910   248959670 : INLINE long closure_arity(GEN C)          { return ((ulong)C[1])&ARITYBITS; }
    2911    34811355 : INLINE long closure_is_variadic(GEN C) { return !!(((ulong)C[1])&VARARGBITS); }
    2912   213839418 : INLINE const char *closure_codestr(GEN C)  { return GSTR(gel(C,2))-1; }
    2913           0 : INLINE GEN closure_get_code(GEN C)  { return gel(C,2); }
    2914   213847586 : INLINE GEN closure_get_oper(GEN C)  { return gel(C,3); }
    2915   213832646 : INLINE GEN closure_get_data(GEN C)  { return gel(C,4); }
    2916        8413 : INLINE GEN closure_get_dbg(GEN C)   { return gel(C,5); }
    2917       20375 : INLINE GEN closure_get_text(GEN C)  { return gel(C,6); }
    2918      813154 : INLINE GEN closure_get_frame(GEN C) { return gel(C,7); }
    2919             : 
    2920             : /*******************************************************************/
    2921             : /*                                                                 */
    2922             : /*                               ERRORS                            */
    2923             : /*                                                                 */
    2924             : /*******************************************************************/
    2925             : INLINE long
    2926       30463 : err_get_num(GEN e) { return e[1]; }
    2927             : INLINE GEN
    2928          70 : err_get_compo(GEN e, long i) { return gel(e, i+1); }
    2929             : 
    2930             : INLINE void
    2931          14 : pari_err_BUG(const char *f) { pari_err(e_BUG,f); }
    2932             : INLINE void
    2933           7 : pari_err_CONSTPOL(const char *f) { pari_err(e_CONSTPOL, f); }
    2934             : INLINE void
    2935          63 : pari_err_COPRIME(const char *f, GEN x, GEN y) { pari_err(e_COPRIME, f,x,y); }
    2936             : INLINE void
    2937         445 : pari_err_DIM(const char *f) { pari_err(e_DIM, f); }
    2938             : INLINE void
    2939           0 : pari_err_FILE(const char *f, const char *g) { pari_err(e_FILE, f,g); }
    2940             : INLINE void
    2941          28 : pari_err_FLAG(const char *f) { pari_err(e_FLAG,f); }
    2942             : INLINE void
    2943         357 : pari_err_IMPL(const char *f) { pari_err(e_IMPL,f); }
    2944             : INLINE void
    2945         705 : pari_err_INV(const char *f, GEN x) { pari_err(e_INV,f,x); }
    2946             : INLINE void
    2947          21 : pari_err_IRREDPOL(const char *f, GEN x) { pari_err(e_IRREDPOL, f,x); }
    2948             : INLINE void
    2949        1688 : 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); }
    2950             : INLINE void
    2951         245 : pari_err_COMPONENT(const char *f, const char *op, GEN l, GEN x) { pari_err(e_COMPONENT, f,op,l,x); }
    2952             : INLINE void
    2953           0 : pari_err_MAXPRIME(ulong c) { pari_err(e_MAXPRIME, c); }
    2954             : INLINE void
    2955         287 : pari_err_OP(const char *f, GEN x, GEN y) { pari_err(e_OP, f,x,y); }
    2956             : INLINE void
    2957          84 : pari_err_OVERFLOW(const char *f) { pari_err(e_OVERFLOW, f); }
    2958             : INLINE void
    2959         219 : pari_err_PREC(const char *f) { pari_err(e_PREC,f); }
    2960             : INLINE void
    2961           0 : pari_err_PACKAGE(const char *f) { pari_err(e_PACKAGE,f); }
    2962             : INLINE void
    2963          56 : pari_err_PRIME(const char *f, GEN x) { pari_err(e_PRIME, f,x); }
    2964             : INLINE void
    2965         735 : pari_err_MODULUS(const char *f, GEN x, GEN y) { pari_err(e_MODULUS, f,x,y); }
    2966             : INLINE void
    2967          42 : pari_err_ROOTS0(const char *f) { pari_err(e_ROOTS0, f); }
    2968             : INLINE void
    2969          77 : pari_err_SQRTN(const char *f, GEN x) { pari_err(e_SQRTN, f,x); }
    2970             : INLINE void
    2971       11383 : pari_err_TYPE(const char *f, GEN x) { pari_err(e_TYPE, f,x); }
    2972             : INLINE void
    2973        3045 : pari_err_TYPE2(const char *f, GEN x, GEN y) { pari_err(e_TYPE2, f,x,y); }
    2974             : INLINE void
    2975         203 : pari_err_VAR(const char *f, GEN x, GEN y) { pari_err(e_VAR, f,x,y); }
    2976             : INLINE void
    2977         147 : pari_err_PRIORITY(const char *f, GEN x, const char *op, long v)
    2978         147 : { pari_err(e_PRIORITY, f,x,op,v); }

Generated by: LCOV version 1.11