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 21041-7a7d034) Lines: 1266 1443 87.7 %
Date: 2017-09-20 06:24:43 Functions: 542 616 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     2064399 : 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     1513316 : 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     5427040 : 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    54940583 : mkvecsmall(long x) { GEN v = cgetg(2, t_VECSMALL); v[1] = x; return v; }
     193             : INLINE GEN
     194   110278986 : mkvecsmall2(long x,long y) { GEN v = cgetg(3, t_VECSMALL);
     195   110273765 :   v[1]=x; v[2]=y; return v; }
     196             : INLINE GEN
     197    65049918 : mkvecsmall3(long x,long y,long z) { GEN v = cgetg(4, t_VECSMALL);
     198    65046818 :   v[1]=x; v[2]=y; v[3]=z; return v; }
     199             : INLINE GEN
     200    23742583 : mkvecsmall4(long x,long y,long z,long t) { GEN v = cgetg(5, t_VECSMALL);
     201    23732573 :   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    12577184 : mkvec(GEN x) { retmkvec(x); }
     211             : INLINE GEN
     212   132253308 : mkvec2(GEN x, GEN y) { retmkvec2(x,y); }
     213             : INLINE GEN
     214    74104721 : mkvec3(GEN x, GEN y, GEN z) { retmkvec3(x,y,z); }
     215             : INLINE GEN
     216     7749982 : mkvec4(GEN x, GEN y, GEN z, GEN t) { retmkvec4(x,y,z,t); }
     217             : INLINE GEN
     218    11954698 : 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     2222779 : mkcol(GEN x) { retmkcol(x); }
     235             : INLINE GEN
     236    14954122 : 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    16242696 : 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      735911 : pol_x(long v) {
     279      735911 :   GEN p = cgetg(4, t_POL);
     280      735911 :   p[1] = evalsigne(1)|evalvarn(v);
     281      735911 :   gel(p,2) = gen_0;
     282      735911 :   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     1271246 : pol_1(long v) {
     302     1271246 :   GEN p = cgetg(3, t_POL);
     303     1271249 :   p[1] = evalsigne(1)|evalvarn(v);
     304     1271249 :   gel(p,2) = gen_1; return p;
     305             : }
     306             : INLINE GEN
     307    18769997 : pol_0(long v)
     308             : {
     309    18769997 :   GEN x = cgetg(2,t_POL);
     310    18769997 :   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     7572818 : 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     4687422 : const_vecsmall(long n, long c)
     328             : {
     329             :   long i;
     330     4687422 :   GEN V = cgetg(n+1,t_VECSMALL);
     331     4687423 :   for(i=1;i<=n;i++) V[i] = c;
     332     4687423 :   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     6421195 : zeropol(long v) { return pol_0(v); }
     377             : /* vector(n) */
     378             : INLINE GEN
     379    28313431 : zerocol(long n)
     380             : {
     381    28313431 :   GEN y = cgetg(n+1,t_COL);
     382    28313431 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     383    28313431 :   return y;
     384             : }
     385             : /* vectorv(n) */
     386             : INLINE GEN
     387    18225323 : zerovec(long n)
     388             : {
     389    18225323 :   GEN y = cgetg(n+1,t_VEC);
     390    18225324 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     391    18225324 :   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      791745 : zero_Flx(long sv) { return pol0_Flx(sv); }
     405             : INLINE GEN
     406    32309219 : zero_Flv(long n)
     407             : {
     408    32309219 :   GEN y = cgetg(n+1,t_VECSMALL);
     409    32309411 :   long i; for (i=1; i<=n; i++) y[i] = 0;
     410    32309411 :   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       93243 : zero_Flm_copy(long m, long n)
     424             : {
     425       93243 :   GEN y = cgetg(n+1,t_MAT);
     426       93248 :   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     2653449 : shallowcopy(GEN x)
     494     2653449 : { return typ(x) == t_MAT ? RgM_shallowcopy(x): leafcopy(x); }
     495             : 
     496             : /* routines for naive growarrays */
     497             : INLINE GEN
     498    12711377 : vectrunc_init(long l)
     499             : {
     500    12711377 :   GEN z = new_chunk(l);
     501    12711706 :   z[0] = evaltyp(t_VEC) | _evallg(1); return z;
     502             : }
     503             : INLINE void
     504   507093524 : lg_increase(GEN x) { x[0]++; }
     505             : INLINE void
     506    49284760 : 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      178884 : vecsmall_shorten(GEN v, long n)
     577             : {
     578             :   long i;
     579      178884 :   GEN V = cgetg(n+1,t_VECSMALL);
     580      178886 :   for(i=1;i<=n;i++) V[i] = v[i];
     581      178886 :   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     3765628 : vecsmall_append(GEN V, long s)
     658             : {
     659     3765628 :   long i, l2 = lg(V);
     660     3765628 :   GEN res = cgetg(l2+1, t_VECSMALL);
     661     3765628 :   for (i = 1; i < l2; ++i) res[i] = V[i];
     662     3765628 :   res[l2] = s; return res;
     663             : }
     664             : 
     665             : INLINE GEN
     666      774720 : vecsmall_concat(GEN u, GEN v)
     667             : {
     668      774720 :   long i, l1 = lg(u)-1, l2 = lg(v)-1;
     669      774720 :   GEN res = cgetg(l1+l2+1, t_VECSMALL);
     670      774720 :   for (i = 1; i <= l1; ++i) res[i]    = u[i];
     671      774720 :   for (i = 1; i <= l2; ++i) res[i+l1] = v[i];
     672      774720 :   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    17394252 : QV_isscalar(GEN x)
     749             : {
     750    17394252 :   long lx = lg(x),i;
     751    18858484 :   for (i=2; i<lx; i++)
     752    18331302 :     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    24887050 : 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     2827509 : RgX_is_ZX(GEN x)
     784             : {
     785             :   long i;
     786    11751611 :   for (i = lg(x)-1; i > 1; i--)
     787     8932703 :     if (typ(gel(x,i)) != t_INT) return 0;
     788     2818908 :   return 1;
     789             : }
     790             : INLINE int
     791      124799 : RgX_is_QX(GEN x)
     792             : {
     793      124799 :   long k = lg(x)-1;
     794      463127 :   for ( ; k>1; k--)
     795      340036 :     if (!is_rational_t(typ(gel(x,k)))) return 0;
     796      123091 :   return 1;
     797             : }
     798             : INLINE int
     799    15518073 : RgX_is_monomial(GEN x)
     800             : {
     801             :   long i;
     802    15518073 :   if (!signe(x)) return 0;
     803    25658424 :   for (i=lg(x)-2; i>1; i--)
     804    17734077 :     if (!isexactzero(gel(x,i))) return 0;
     805     7924347 :   return 1;
     806             : }
     807             : INLINE int
     808    18293918 : RgV_is_ZV(GEN x)
     809             : {
     810             :   long i;
     811    74712276 :   for (i = lg(x)-1; i > 0; i--)
     812    56419471 :     if (typ(gel(x,i)) != t_INT) return 0;
     813    18292805 :   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   408095604 : pari_stack_base(pari_stack *s) { return s->data; }
     831             : 
     832             : INLINE void
     833      923605 : pari_stack_init(pari_stack *s, size_t size, void **data)
     834             : {
     835      923605 :   s->data = data;
     836      923605 :   *data = NULL;
     837      923605 :   s->n = 0;
     838      923605 :   s->alloc = 0;
     839      923605 :   s->size = size;
     840      923605 : }
     841             : 
     842             : INLINE void
     843   407195981 : pari_stack_alloc(pari_stack *s, long nb)
     844             : {
     845   407195981 :   void **sdat = pari_stack_base(s);
     846   407382326 :   long alloc = s->alloc;
     847   814766109 :   if (s->n+nb <= alloc) return;
     848      391079 :   if (!alloc)
     849      342829 :     alloc = nb;
     850             :   else
     851             :   {
     852       48250 :     while (s->n+nb > alloc) alloc <<= 1;
     853             :   }
     854      391079 :   *sdat = pari_realloc(*sdat,alloc*s->size);
     855      392536 :   s->alloc = alloc;
     856             : }
     857             : 
     858             : INLINE long
     859   339230801 : pari_stack_new(pari_stack *s) { pari_stack_alloc(s, 1); return s->n++; }
     860             : 
     861             : INLINE void
     862      795102 : pari_stack_delete(pari_stack *s)
     863             : {
     864      795102 :   void **sdat = pari_stack_base(s);
     865      794616 :   if (*sdat) pari_free(*sdat);
     866      794911 : }
     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     4481603 : Flm_row(GEN A, long x0)
     963             : {
     964     4481603 :   long i, lB = lg(A);
     965     4481603 :   GEN B  = cgetg(lB, t_VECSMALL);
     966     4481602 :   for (i=1; i<lB; i++) B[i] = coeff(A, x0, i);
     967     4481602 :   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    44970610 : 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    46601346 : perm_mul(GEN s, GEN t)
    1068             : {
    1069             :   GEN u;
    1070    46601346 :   long i, l = lg(t);
    1071    46601346 :   u = cgetg(l, t_VECSMALL);
    1072    46601346 :   for (i = 1; i < l; i++) u[i] = s[ t[i] ];
    1073    46601346 :   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    53707997 : pari_free(void *pointer)
    1122             : {
    1123    53707997 :   BLOCK_SIGINT_START;
    1124    53709419 :   free(pointer);
    1125    53709419 :   BLOCK_SIGINT_END;
    1126    53708956 : }
    1127             : INLINE void*
    1128   234586187 : pari_malloc(size_t size)
    1129             : {
    1130   234586187 :   if (size)
    1131             :   {
    1132             :     char *tmp;
    1133   234586187 :     BLOCK_SIGINT_START;
    1134   234588861 :     tmp = (char*)malloc(size);
    1135   234588861 :     BLOCK_SIGINT_END;
    1136   234588653 :     if (!tmp) pari_err(e_MEM);
    1137   234588653 :     return tmp;
    1138             :   }
    1139           0 :   if (DEBUGMEM) pari_warn(warner,"mallocing NULL object");
    1140           0 :   return NULL;
    1141             : }
    1142             : INLINE void*
    1143      403194 : pari_realloc(void *pointer, size_t size)
    1144             : {
    1145             :   char *tmp;
    1146             : 
    1147      403194 :   BLOCK_SIGINT_START;
    1148      404909 :   if (!pointer) tmp = (char *) malloc(size);
    1149       51869 :   else tmp = (char *) realloc(pointer,size);
    1150      404909 :   BLOCK_SIGINT_END;
    1151      404267 :   if (!tmp) pari_err(e_MEM);
    1152      404267 :   return tmp;
    1153             : }
    1154             : INLINE void*
    1155       32512 : pari_calloc(size_t size)
    1156             : {
    1157       32512 :   void *t = pari_malloc(size);
    1158       32512 :   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  3663320579 : icopy_avma(GEN x, pari_sp av)
    1175             : {
    1176  3663320579 :   long i = lgefint(x), lx = i;
    1177  3663320579 :   GEN y = ((GEN)av) - i;
    1178  3663320579 :   while (--i > 0) y[i] = x[i];
    1179  3663320579 :   y[0] = evaltyp(t_INT)|evallg(lx);
    1180  3663138015 :   return y;
    1181             : }
    1182             : /* copy leaf x as if we had avma = av */
    1183             : INLINE GEN
    1184   156143352 : leafcopy_avma(GEN x, pari_sp av)
    1185             : {
    1186   156143352 :   long i = lg(x);
    1187   156143352 :   GEN y = ((GEN)av) - i;
    1188   156143352 :   while (--i > 0) y[i] = x[i];
    1189   156143352 :   y[0] = x[0] & (~CLONEBIT);
    1190   156143352 :   return y;
    1191             : }
    1192             : INLINE GEN
    1193   593853900 : gerepileuptoleaf(pari_sp av, GEN x)
    1194             : {
    1195             :   long lx;
    1196             :   GEN q;
    1197             : 
    1198   593853900 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1199   594865575 :   lx = lg(x);
    1200   594865575 :   q = ((GEN)av) - lx;
    1201   594865575 :   avma = (pari_sp)q;
    1202   594865575 :   while (--lx >= 0) q[lx] = x[lx];
    1203   594865575 :   return q;
    1204             : }
    1205             : INLINE GEN
    1206  1214033508 : gerepileuptoint(pari_sp av, GEN x)
    1207             : {
    1208  1214033508 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1209  1069686097 :   avma = (pari_sp)icopy_avma(x, av);
    1210  1070288129 :   return (GEN)avma;
    1211             : }
    1212             : INLINE GEN
    1213   753038714 : gerepileupto(pari_sp av, GEN x)
    1214             : {
    1215   753038714 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1216   651790781 :   switch(typ(x))
    1217             :   { /* non-default = !is_recursive_t(tq) */
    1218   238441859 :     case t_INT: return gerepileuptoint(av, x);
    1219             :     case t_REAL:
    1220             :     case t_STR:
    1221   116820658 :     case t_VECSMALL: return gerepileuptoleaf(av,x);
    1222             :     default:
    1223             :       /* NB: x+i --> ((long)x) + i*sizeof(long) */
    1224   296528264 :       return gerepile(av, (pari_sp) (x+lg(x)), x);
    1225             :   }
    1226             : }
    1227             : 
    1228             : /* gerepileupto(av, gcopy(x)) */
    1229             : INLINE GEN
    1230    40776011 : gerepilecopy(pari_sp av, GEN x)
    1231             : {
    1232    40776011 :   if (is_recursive_t(typ(x)))
    1233             :   {
    1234    33247492 :     GENbin *p = copy_bin(x);
    1235    33247503 :     avma = av; return bin_copy(p);
    1236             :   }
    1237             :   else
    1238             :   {
    1239     7528528 :     avma = av;
    1240     7528528 :     if (x < (GEN)av) {
    1241     6111674 :       if (x < (GEN)pari_mainstack->bot) new_chunk(lg(x));
    1242     6111674 :       x = leafcopy_avma(x, av);
    1243     6111681 :       avma = (pari_sp)x;
    1244             :     } else
    1245     1416854 :       x = leafcopy(x);
    1246     7528536 :     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     5724932 : gerepileall(pari_sp av, int n, ...)
    1264             : {
    1265             :   int i;
    1266     5724932 :   va_list a; va_start(a, n);
    1267     5724932 :   if (n < 10)
    1268             :   {
    1269             :     GEN *gptr[10];
    1270    17392181 :     for (i=0; i<n; i++)
    1271    11667261 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1272     5724920 :     avma = av;
    1273     5724920 :     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     5724903 :   va_end(a);
    1286     5724903 : }
    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    45322456 : bin_copy(GENbin *p)
    1300             : {
    1301             :   GEN x, y, base;
    1302             :   long dx, len;
    1303             : 
    1304    45322456 :   x   = p->x; if (!x) { pari_free(p); return gen_0; }
    1305    45315629 :   len = p->len;
    1306    45315629 :   base= p->base; dx = x - base;
    1307    45315629 :   y = (GEN)memcpy((void*)new_chunk(len), (void*)GENbinbase(p), len*sizeof(long));
    1308    45315625 :   y += dx;
    1309    45315625 :   p->rebase(y, ((ulong)y-(ulong)x));
    1310    45315616 :   pari_free(p); return y;
    1311             : }
    1312             : 
    1313             : INLINE GEN
    1314    90638152 : GENbinbase(GENbin *p) { return (GEN)(p + 1); }
    1315             : 
    1316             : INLINE void
    1317    27361357 : cgiv(GEN x)
    1318             : {
    1319    27361357 :   pari_sp av = (pari_sp)(x+lg(x));
    1320    27361357 :   if (isonstack((GEN)av)) avma = av;
    1321    27361261 : }
    1322             : 
    1323             : INLINE void
    1324     1184209 : killblock(GEN x) { gunclone(x); }
    1325             : 
    1326             : INLINE int
    1327    17745741 : 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    67227261 : gtos(GEN x) {
    1364    67227261 :   if (typ(x) != t_INT) pari_err_TYPE("gtos [integer expected]",x);
    1365    67227254 :   return itos(x);
    1366             : }
    1367             : 
    1368             : INLINE ulong
    1369      136514 : gtou(GEN x) {
    1370      136514 :   if (typ(x) != t_INT || signe(x)<0)
    1371           0 :     pari_err_TYPE("gtou [integer >=0 expected]",x);
    1372      136936 :   return itou(x);
    1373             : }
    1374             : 
    1375             : INLINE GEN
    1376     7731764 : absfrac(GEN x)
    1377             : {
    1378     7731764 :   GEN y = cgetg(3, t_FRAC);
    1379     7731764 :   gel(y,1) = absi(gel(x,1));
    1380     7731764 :   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     1496218 : 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     1134490 : nbits2nlong(long x) {
    1556     1134490 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1557             : }
    1558             : 
    1559             : INLINE long
    1560   243786043 : nbits2extraprec(long x) {
    1561   243786043 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1562             : }
    1563             : 
    1564             : /* Fast implementation of 2 + nbits2nlong(x) */
    1565             : INLINE long
    1566    78347870 : nbits2prec(long x) {
    1567    78347870 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1568             : }
    1569             : INLINE long
    1570     6561840 : nbits2lg(long x) {
    1571     6561840 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1572             : }
    1573             : /* ceil(x / sizeof(long)) */
    1574             : INLINE long
    1575     8253476 : nchar2nlong(long x) {
    1576     8253476 :   return (long)(((ulong)x+sizeof(long)-1) >> (TWOPOTBITS_IN_LONG-3L));
    1577             : }
    1578             : INLINE long
    1579  1056929843 : 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    25963841 : bit_prec(GEN x) { return prec2nbits(realprec(x)); }
    1586             : INLINE long
    1587   974509059 : 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  3081669005 : divsBIL(long n) { return n >> TWOPOTBITS_IN_LONG; }
    1596             : INLINE long
    1597  3047346314 : 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     2439556 : Fp_red(GEN a, GEN m) { return modii(a, m); }
    1608             : INLINE GEN
    1609    87072552 : Fp_add(GEN a, GEN b, GEN m)
    1610             : {
    1611    87072552 :   pari_sp av=avma;
    1612    87072552 :   GEN p = addii(a,b);
    1613    87072837 :   long s = signe(p);
    1614    87072837 :   if (!s) return p; /* = gen_0 */
    1615    76357511 :   if (s > 0) /* general case */
    1616             :   {
    1617    76134308 :     GEN t = subii(p, m);
    1618    76217449 :     s = signe(t);
    1619    76217449 :     if (!s) { avma = av; return gen_0; }
    1620    70736720 :     if (s < 0) { avma = (pari_sp)p; return p; }
    1621    31053361 :     if (cmpii(t, m) < 0) return gerepileuptoint(av, t); /* general case ! */
    1622     1122130 :     p = remii(t, m);
    1623             :   }
    1624             :   else
    1625      223203 :     p = modii(p, m);
    1626     1345333 :   return gerepileuptoint(av, p);
    1627             : }
    1628             : INLINE GEN
    1629    75878568 : Fp_sub(GEN a, GEN b, GEN m)
    1630             : {
    1631    75878568 :   pari_sp av=avma;
    1632    75878568 :   GEN p = subii(a,b);
    1633    76143372 :   long s = signe(p);
    1634    76143372 :   if (!s) return p; /* = gen_0 */
    1635    68275364 :   if (s > 0)
    1636             :   {
    1637    32972328 :     if (cmpii(p, m) < 0) return p; /* general case ! */
    1638     1315325 :     p = remii(p, m);
    1639             :   }
    1640             :   else
    1641             :   {
    1642    35303036 :     GEN t = addii(p, m);
    1643    35292839 :     if (!s) { avma = av; return gen_0; }
    1644    35292839 :     if (s > 0) return gerepileuptoint(av, t); /* general case ! */
    1645    35292839 :     p = modii(t, m);
    1646             :   }
    1647    36617564 :   return gerepileuptoint(av, p);
    1648             : }
    1649             : INLINE GEN
    1650    10978197 : Fp_neg(GEN b, GEN m)
    1651             : {
    1652    10978197 :   pari_sp av = avma;
    1653    10978197 :   long s = signe(b);
    1654             :   GEN p;
    1655    10978197 :   if (!s) return gen_0;
    1656     7580087 :   if (s > 0)
    1657             :   {
    1658     7377829 :     p = subii(m, b);
    1659     7377575 :     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     5863935 : Fp_center(GEN u, GEN p, GEN ps2)
    1676     5863935 : { return abscmpii(u,ps2)<=0? icopy(u): subii(u,p); }
    1677             : 
    1678             : /* x + y*z mod p */
    1679             : INLINE GEN
    1680     7867585 : Fp_addmul(GEN x, GEN y, GEN z, GEN p)
    1681             : {
    1682             :   pari_sp av;
    1683     7867585 :   if (!signe(y) || !signe(z)) return Fp_red(x, p);
    1684     7444180 :   if (!signe(x)) return Fp_mul(z,y, p);
    1685     7143303 :   av = avma;
    1686     7143303 :   return gerepileuptoint(av, modii(addii(x, mulii(y,z)), p));
    1687             : }
    1688             : 
    1689             : INLINE GEN
    1690    64330201 : Fp_mul(GEN a, GEN b, GEN m)
    1691             : {
    1692    64330201 :   pari_sp av=avma;
    1693             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1694    64330201 :   (void)new_chunk(lg(a)+lg(b)+(lg(m)<<1));
    1695    64339178 :   p = mulii(a,b);
    1696    64339727 :   avma = av; return modii(p,m);
    1697             : }
    1698             : INLINE GEN
    1699    61888217 : Fp_sqr(GEN a, GEN m)
    1700             : {
    1701    61888217 :   pari_sp av=avma;
    1702             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1703    61888217 :   (void)new_chunk((lg(a)+lg(m))<<1);
    1704    62180089 :   p = sqri(a);
    1705    62469996 :   avma = av; return remii(p,m); /*Use remii: p >= 0 */
    1706             : }
    1707             : INLINE GEN
    1708    80299188 : Fp_mulu(GEN a, ulong b, GEN m)
    1709             : {
    1710    80299188 :   long l = lgefint(m);
    1711    80299188 :   if (l == 3)
    1712             :   {
    1713    43148287 :     ulong mm = m[2];
    1714    43148287 :     return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1715             :   } else {
    1716    37150901 :     pari_sp av = avma;
    1717             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1718    37150901 :     (void)new_chunk(lg(a)+1+(l<<1));
    1719    37178862 :     p = muliu(a,b);
    1720    36856834 :     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     8456368 : Fp_inv(GEN a, GEN m)
    1748             : {
    1749             :   GEN res;
    1750     8456368 :   if (! invmod(a,m,&res)) pari_err_INV("Fp_inv", mkintmod(res,m));
    1751     8456257 :   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     2296154 : Fp_div(GEN a, GEN b, GEN m)
    1762             : {
    1763     2296154 :   pari_sp av=avma;
    1764             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1765     2296154 :   (void)new_chunk(lg(a)+(lg(m)<<1));
    1766     2296154 :   p = mulii(a, Fp_inv(b,m));
    1767     2296154 :   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      448050 : 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         273 : 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     5976212 : get_Flx_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1793             : 
    1794             : INLINE long
    1795    16090852 : get_Flx_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1796             : 
    1797             : INLINE long
    1798    30142775 : get_Flx_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1799             : 
    1800             : INLINE GEN
    1801         982 : 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      405911 : get_FpX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1811             : 
    1812             : INLINE long
    1813     1488922 : get_FpX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1814             : 
    1815             : INLINE long
    1816     1543565 : 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  1281959673 : is_const_t(long t) { return (t < t_POLMOD); }
    1935             : INLINE int
    1936       53689 : 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   380708637 : is_matvec_t(long t) { return (t >= t_VEC && t <= t_MAT); }
    1941             : INLINE int
    1942    50327897 : is_noncalc_t(long tx) { return (tx) >= t_LIST; }
    1943             : INLINE int
    1944      768281 : 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  2815485630 : is_recursive_t(long t) { return lontyp[t]; }
    1949             : INLINE int
    1950   171589920 : 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      211330 : 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   520100947 : INLINE int isintzero(GEN x) { return typ(x) == t_INT && !signe(x); }
    2010    10092929 : 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   283750902 : INLINE int equali1(GEN n)
    2013   283750902 : { 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  1621375746 : INLINE int is_pm1(GEN n)
    2018  1621375746 : { return lgefint(n) == 3 && n[2] == 1; }
    2019   581768194 : INLINE int is_bigint(GEN n)
    2020   581768194 : { long l = lgefint(n); return l > 3 || (l == 3 && (n[2] & HIGHBIT)); }
    2021             : 
    2022  2121571601 : INLINE int odd(long x) { return x & 1; }
    2023    28523016 : INLINE int both_odd(long x, long y) { return x & y & 1; }
    2024             : 
    2025             : INLINE int
    2026  2588438855 : isonstack(GEN x)
    2027  5176877710 : { return ((pari_sp)x >= pari_mainstack->bot
    2028  2588438855 :        && (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    17883504 : dbllog2r(GEN x)
    2033    17883504 : { 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    74670619 : leading_coeff(GEN x) { return lg(x) == 2? gen_0: gel(x,lg(x)-1); }
    2055             : INLINE ulong
    2056      412763 : Flx_lead(GEN x) { return lg(x) == 2? 0: x[lg(x)-1]; }
    2057             : INLINE long
    2058  2782374143 : degpol(GEN x) { return lg(x)-3; }
    2059             : INLINE long
    2060  1370706693 : lgpol(GEN x) { return lg(x)-2; }
    2061             : INLINE long
    2062    98707528 : lgcols(GEN x) { return lg(gel(x,1)); }
    2063             : INLINE long
    2064    20822546 : 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      482578 : RgXQ_mul(GEN y, GEN x, GEN T) { return RgX_rem(RgX_mul(y, x), T); }
    2070             : INLINE GEN
    2071      277949 : 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    89841544 : RgX_copy(GEN x)
    2080             : {
    2081             :   long lx, i;
    2082    89841544 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
    2083    89841566 :   for (i = 2; i<lx; i++) gel(y,i) = gcopy(gel(x,i));
    2084    89841546 :   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     5554246 : RgX_rem(GEN x, GEN y) { return RgX_divrem(x,y,ONLY_REM); }
    2100             : INLINE GEN
    2101        1792 : RgXQX_div(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,NULL); }
    2102             : INLINE GEN
    2103       19460 : RgXQX_rem(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,ONLY_REM); }
    2104             : INLINE GEN
    2105      827319 : FpX_div(GEN x, GEN y, GEN p) { return FpX_divrem(x,y,p, NULL); }
    2106             : INLINE GEN
    2107     3525594 : Flx_div(GEN x, GEN y, ulong p) { return Flx_divrem(x,y,p, NULL); }
    2108             : INLINE GEN
    2109     2996389 : F2x_div(GEN x, GEN y) { return F2x_divrem(x,y, NULL); }
    2110             : INLINE GEN
    2111           0 : FpV_FpC_mul(GEN x, GEN y, GEN p) { return FpV_dotproduct(x,y,p); }
    2112             : INLINE GEN
    2113    44729782 : pol0_Flx(long sv) { return mkvecsmall(sv); }
    2114             : INLINE GEN
    2115    18420631 : pol1_Flx(long sv) { return mkvecsmall2(sv, 1); }
    2116             : INLINE GEN
    2117    18102317 : polx_Flx(long sv) { return mkvecsmall3(sv, 0, 1); }
    2118             : INLINE GEN
    2119           0 : zero_zx(long sv) { return zero_Flx(sv); }
    2120             : INLINE GEN
    2121           0 : polx_zx(long sv) { return polx_Flx(sv); }
    2122             : INLINE GEN
    2123           0 : zx_shift(GEN x, long n) { return Flx_shift(x,n); }
    2124             : INLINE GEN
    2125           0 : zx_renormalize(GEN x, long l) { return Flx_renormalize(x,l); }
    2126             : INLINE GEN
    2127        1082 : zero_F2x(long sv) { return zero_Flx(sv); }
    2128             : INLINE GEN
    2129    11379072 : pol0_F2x(long sv) { return pol0_Flx(sv); }
    2130             : INLINE GEN
    2131     2801749 : pol1_F2x(long sv) { return pol1_Flx(sv); }
    2132             : INLINE GEN
    2133      672505 : polx_F2x(long sv) { return mkvecsmall2(sv, 2); }
    2134             : INLINE int
    2135      815323 : F2x_equal1(GEN x) { return Flx_equal1(x); }
    2136             : INLINE int
    2137     3553744 : F2x_equal(GEN V, GEN W) { return Flx_equal(V,W); }
    2138             : INLINE GEN
    2139    69600345 : F2x_copy(GEN x) { return leafcopy(x); }
    2140             : INLINE GEN
    2141           0 : F2v_copy(GEN x) { return leafcopy(x); }
    2142             : INLINE GEN
    2143     2347047 : Flv_copy(GEN x) { return leafcopy(x); }
    2144             : INLINE GEN
    2145    74699221 : Flx_copy(GEN x) { return leafcopy(x); }
    2146             : INLINE GEN
    2147     1658206 : vecsmall_copy(GEN x) { return leafcopy(x); }
    2148             : INLINE int
    2149     4741083 : Flx_equal1(GEN x) { return degpol(x)==0 && x[2] == 1; }
    2150             : INLINE int
    2151       17635 : ZX_equal1(GEN x) { return degpol(x)==0 && equali1(gel(x,2)); }
    2152             : 
    2153             : INLINE GEN
    2154    43146411 : ZX_renormalize(GEN x, long lx)    { return ZXX_renormalize(x,lx); }
    2155             : INLINE GEN
    2156    54853781 : FpX_renormalize(GEN x, long lx)   { return ZXX_renormalize(x,lx); }
    2157             : INLINE GEN
    2158      961806 : FpXX_renormalize(GEN x, long lx)  { return ZXX_renormalize(x,lx); }
    2159             : INLINE GEN
    2160      993773 : FpXQX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
    2161             : INLINE GEN
    2162   122799849 : F2x_renormalize(GEN x, long lx)   { return Flx_renormalize(x,lx); }
    2163             : INLINE GEN
    2164        8744 : F2v_to_F2x(GEN x, long sv) {
    2165        8744 :   GEN y = leafcopy(x);
    2166        8744 :   y[1] = sv; F2x_renormalize(y, lg(y)); return y;
    2167             : }
    2168             : 
    2169             : INLINE long
    2170         455 : sturm(GEN x) { return sturmpart(x, NULL, NULL); }
    2171             : 
    2172             : INLINE long
    2173        2429 : gval(GEN x, long v) {
    2174        2429 :   pari_sp av = avma;
    2175        2429 :   long n = gvaluation(x, pol_x(v));
    2176        2429 :   avma = av; return n;
    2177             : }
    2178             : 
    2179             : INLINE void
    2180      485426 : RgX_shift_inplace_init(long v)
    2181      485426 : { if (v) (void)cgetg(v, t_VECSMALL); }
    2182             : /* shift polynomial in place. assume v free cells have been left before x */
    2183             : INLINE GEN
    2184      485426 : RgX_shift_inplace(GEN x, long v)
    2185             : {
    2186             :   long i, lx;
    2187             :   GEN y, z;
    2188      485426 :   if (!v) return x;
    2189      253272 :   lx = lg(x);
    2190      253272 :   if (lx == 2) return x;
    2191      253272 :   y = x + v;
    2192      253272 :   z = x + lx;
    2193             :   /* stackdummy from normalizepol: move it up */
    2194      253272 :   if (lg(z) != v) x[lx + v] = z[0];
    2195      253272 :   for (i = lx-1; i >= 2; i--) gel(y,i) = gel(x,i);
    2196      253272 :   for (i = v+1;  i >= 2; i--) gel(x,i) = gen_0;
    2197             :   /* leave x[1] alone: it is correct */
    2198      253272 :   x[0] = evaltyp(t_POL) | evallg(lx+v); return x;
    2199             : }
    2200             : 
    2201             : 
    2202             : /* LINEAR ALGEBRA */
    2203             : INLINE GEN
    2204       68075 : zv_to_ZV(GEN x) { return vecsmall_to_vec(x); }
    2205             : INLINE GEN
    2206     1282798 : zc_to_ZC(GEN x) { return vecsmall_to_col(x); }
    2207             : INLINE GEN
    2208      392124 : ZV_to_zv(GEN x) { return vec_to_vecsmall(x); }
    2209             : INLINE GEN
    2210           0 : zx_to_zv(GEN x, long N) { return Flx_to_Flv(x,N); }
    2211             : INLINE GEN
    2212           0 : zv_to_zx(GEN x, long sv) { return Flv_to_Flx(x,sv); }
    2213             : INLINE GEN
    2214           0 : zm_to_zxV(GEN x, long sv) { return Flm_to_FlxV(x,sv); }
    2215             : INLINE GEN
    2216           0 : zero_zm(long x, long y) { return zero_Flm(x,y); }
    2217             : INLINE GEN
    2218    18065895 : zero_zv(long x) { return zero_Flv(x); }
    2219             : INLINE GEN
    2220         168 : zm_transpose(GEN x) { return Flm_transpose(x); }
    2221             : INLINE GEN
    2222           0 : zm_copy(GEN x) { return Flm_copy(x); }
    2223             : INLINE GEN
    2224     2002551 : zv_copy(GEN x) { return Flv_copy(x); }
    2225             : INLINE GEN
    2226           0 : zm_row(GEN x, long i) { return Flm_row(x,i); }
    2227             : 
    2228             : INLINE GEN
    2229      840045 : ZC_hnfrem(GEN x, GEN y) { return ZC_hnfremdiv(x,y,NULL); }
    2230             : INLINE GEN
    2231       35604 : ZM_hnfrem(GEN x, GEN y) { return ZM_hnfdivrem(x,y,NULL); }
    2232             : INLINE GEN
    2233     1162823 : ZM_lll(GEN x, double D, long f) { return ZM_lll_norms(x,D,f,NULL); }
    2234             : INLINE void
    2235      191759 : RgM_dimensions(GEN x, long *m, long *n) { *n = lg(x)-1; *m = *n? nbrows(x): 0; }
    2236             : INLINE GEN
    2237       43912 : RgM_inv(GEN a) { return RgM_solve(a, NULL); }
    2238             : INLINE GEN
    2239     6776812 : RgM_shallowcopy(GEN x)
    2240             : {
    2241             :   long l;
    2242     6776812 :   GEN y = cgetg_copy(x, &l);
    2243     6776812 :   while (--l > 0) gel(y,l) = leafcopy(gel(x,l));
    2244     6776812 :   return y;
    2245             : }
    2246             : INLINE GEN
    2247         362 : F2m_copy(GEN x) { return RgM_shallowcopy(x); }
    2248             : 
    2249             : INLINE GEN
    2250     1383748 : Flm_copy(GEN x) { return RgM_shallowcopy(x); }
    2251             : 
    2252             : /* divisibility: return 1 if y[i] | x[i] for all i, 0 otherwise. Assume
    2253             :  * x,y are ZV of the same length */
    2254             : INLINE int
    2255       23198 : ZV_dvd(GEN x, GEN y)
    2256             : {
    2257       23198 :   long i, l = lg(x);
    2258       36652 :   for (i=1; i < l; i++)
    2259       29519 :     if ( ! dvdii( gel(x,i), gel(y,i) ) ) return 0;
    2260        7133 :   return 1;
    2261             : }
    2262             : 
    2263             : /* Fq */
    2264             : INLINE GEN
    2265     2223566 : Fq_red(GEN x, GEN T, GEN p)
    2266     2223566 : { return typ(x)==t_INT? Fp_red(x,p): FpXQ_red(x,T,p); }
    2267             : INLINE GEN
    2268       11499 : Fq_to_FpXQ(GEN x, GEN T, GEN p /*unused*/)
    2269             : {
    2270             :   (void) p;
    2271       11499 :   return typ(x)==t_INT ? scalarpol(x, get_FpX_var(T)): x;
    2272             : }
    2273             : 
    2274             : INLINE GEN
    2275         833 : gener_Fq_local(GEN T, GEN p, GEN L)
    2276         833 : { return T? gener_FpXQ_local(T,p, L)
    2277         833 :           : pgener_Fp_local(p, L); }
    2278             : 
    2279             : /* FpXQX */
    2280             : INLINE GEN
    2281        1396 : FpXQX_div(GEN x, GEN y, GEN T, GEN p) { return FpXQX_divrem(x, y, T, p, NULL); }
    2282             : INLINE GEN
    2283       33186 : FlxqX_div(GEN x, GEN y, GEN T, ulong p) { return FlxqX_divrem(x, y, T, p, NULL); }
    2284             : INLINE GEN
    2285       30779 : F2xqX_div(GEN x, GEN y, GEN T) { return F2xqX_divrem(x, y, T, NULL); }
    2286             : 
    2287             : /* FqX */
    2288             : INLINE GEN
    2289       27419 : FqX_red(GEN z, GEN T, GEN p) { return T? FpXQX_red(z, T, p): FpX_red(z, p); }
    2290             : INLINE GEN
    2291      903749 : FqX_add(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2292             : INLINE GEN
    2293       16438 : FqX_neg(GEN x,GEN T,GEN p) { return T? FpXX_neg(x,p): FpX_neg(x,p); }
    2294             : INLINE GEN
    2295        2380 : FqX_sub(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2296             : INLINE GEN
    2297      617158 : FqX_Fp_mul(GEN P, GEN u, GEN T, GEN p)
    2298      617158 : { return T? FpXX_Fp_mul(P, u, p): FpX_Fp_mul(P, u, p); }
    2299             : INLINE GEN
    2300      552395 : FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p)
    2301      552395 : { return typ(U)==t_INT ? FqX_Fp_mul(P, U, T, p): FpXQX_FpXQ_mul(P, U, T, p); }
    2302             : INLINE GEN
    2303       87634 : FqX_mul(GEN x, GEN y, GEN T, GEN p)
    2304       87634 : { return T? FpXQX_mul(x, y, T, p): FpX_mul(x, y, p); }
    2305             : INLINE GEN
    2306      459889 : FqX_mulu(GEN x, ulong y, GEN T, GEN p)
    2307      459889 : { return T? FpXX_mulu(x, y, p): FpX_mulu(x, y, p); }
    2308             : INLINE GEN
    2309        4760 : FqX_sqr(GEN x, GEN T, GEN p)
    2310        4760 : { return T? FpXQX_sqr(x, T, p): FpX_sqr(x, p); }
    2311             : INLINE GEN
    2312        1428 : FqX_powu(GEN x, ulong n, GEN T, GEN p)
    2313        1428 : { return T? FpXQX_powu(x, n, T, p): FpX_powu(x, n, p); }
    2314             : INLINE GEN
    2315        5145 : FqX_div(GEN x, GEN y, GEN T, GEN p)
    2316        5145 : { return T? FpXQX_divrem(x,y,T,p,NULL): FpX_divrem(x,y,p,NULL); }
    2317             : INLINE GEN
    2318        5605 : FqX_get_red(GEN S, GEN T, GEN p)
    2319        5605 : { return T? FpXQX_get_red(S,T,p): FpX_get_red(S,p); }
    2320             : INLINE GEN
    2321       47767 : FqX_rem(GEN x, GEN y, GEN T, GEN p)
    2322       47767 : { return T? FpXQX_rem(x,y,T,p): FpX_rem(x,y,p); }
    2323             : INLINE GEN
    2324         329 : FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2325         329 : { return T? FpXQX_divrem(x,y,T,p,z): FpX_divrem(x,y,p,z); }
    2326             : INLINE GEN
    2327        5957 : FqX_div_by_X_x(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2328        5957 : { return T? FpXQX_div_by_X_x(x,y,T,p,z): FpX_div_by_X_x(x,y,p,z); }
    2329             : INLINE GEN
    2330           0 : FqX_halfgcd(GEN P,GEN Q,GEN T,GEN p)
    2331           0 : {return T? FpXQX_halfgcd(P,Q,T,p): FpX_halfgcd(P,Q,p);}
    2332             : INLINE GEN
    2333      257866 : FqX_gcd(GEN P,GEN Q,GEN T,GEN p)
    2334      257866 : {return T? FpXQX_gcd(P,Q,T,p): FpX_gcd(P,Q,p);}
    2335             : INLINE GEN
    2336       85302 : FqX_extgcd(GEN P,GEN Q,GEN T,GEN p, GEN *U, GEN *V)
    2337       85302 : { return T? FpXQX_extgcd(P,Q,T,p,U,V): FpX_extgcd(P,Q,p,U,V); }
    2338             : INLINE GEN
    2339        3122 : FqX_normalize(GEN z, GEN T, GEN p) { return T? FpXQX_normalize(z, T, p): FpX_normalize(z, p); }
    2340             : INLINE GEN
    2341      270081 : FqX_deriv(GEN f, /*unused*/GEN T, GEN p) { (void)T; return FpXX_deriv(f, p); }
    2342             : INLINE GEN
    2343       72961 : FqX_factor(GEN f, GEN T, GEN p) { return T?FpXQX_factor(f, T, p): FpX_factor(f, p); }
    2344             : INLINE GEN
    2345        6391 : FqX_roots(GEN f, GEN T, GEN p) { return T?FpXQX_roots(f, T, p): FpX_roots(f, p); }
    2346             : 
    2347             : /*FqXQ*/
    2348             : INLINE GEN
    2349           0 : FqXQ_add(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2350           0 : { (void)S; return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2351             : INLINE GEN
    2352           0 : FqXQ_sub(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2353           0 : { (void)S; return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2354             : INLINE GEN
    2355           0 : FqXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p)
    2356           0 : { return T? FpXQXQ_div(x,y,S,T,p): FpXQ_div(x,y,S,p); }
    2357             : INLINE GEN
    2358           0 : FqXQ_inv(GEN x, GEN S, GEN T, GEN p)
    2359           0 : { return T? FpXQXQ_inv(x,S,T,p): FpXQ_inv(x,S,p); }
    2360             : INLINE GEN
    2361           0 : FqXQ_invsafe(GEN x, GEN S, GEN T, GEN p)
    2362           0 : { return T? FpXQXQ_invsafe(x,S,T,p): FpXQ_inv(x,S,p); }
    2363             : INLINE GEN
    2364       21018 : FqXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p)
    2365       21018 : { return T? FpXQXQ_mul(x,y,S,T,p): FpXQ_mul(x,y,S,p); }
    2366             : INLINE GEN
    2367           0 : FqXQ_sqr(GEN x, GEN S, GEN T, GEN p)
    2368           0 : { return T? FpXQXQ_sqr(x,S,T,p): FpXQ_sqr(x,S,p); }
    2369             : INLINE GEN
    2370           0 : FqXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p)
    2371           0 : { return T? FpXQXQ_pow(x,n,S,T,p): FpXQ_pow(x,n,S,p); }
    2372             : 
    2373             : /*FpXQ*/
    2374             : INLINE GEN
    2375           0 : FpXQ_add(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2376           0 : { (void)T; return FpX_add(x,y,p); }
    2377             : INLINE GEN
    2378           0 : FpXQ_sub(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2379           0 : { (void)T; return FpX_sub(x,y,p); }
    2380             : 
    2381             : /*Flxq*/
    2382             : INLINE GEN
    2383           0 : Flxq_add(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2384           0 : { (void)T; return Flx_add(x,y,p); }
    2385             : INLINE GEN
    2386           0 : Flxq_sub(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2387           0 : { (void)T; return Flx_sub(x,y,p); }
    2388             : 
    2389             : /* F2x */
    2390             : 
    2391             : INLINE ulong
    2392   168900899 : F2x_coeff(GEN x,long v)
    2393             : {
    2394   168900899 :    ulong u=(ulong)x[2+divsBIL(v)];
    2395   168899987 :    return (u>>remsBIL(v))&1UL;
    2396             : }
    2397             : 
    2398             : INLINE void
    2399     4180114 : F2x_clear(GEN x,long v)
    2400             : {
    2401     4180114 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2402     4180114 :    *u&=~(1UL<<remsBIL(v));
    2403     4180114 : }
    2404             : 
    2405             : INLINE void
    2406    38822342 : F2x_set(GEN x,long v)
    2407             : {
    2408    38822342 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2409    38816613 :    *u|=1UL<<remsBIL(v);
    2410    38821289 : }
    2411             : 
    2412             : INLINE void
    2413     1360015 : F2x_flip(GEN x,long v)
    2414             : {
    2415     1360015 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2416     1360015 :    *u^=1UL<<remsBIL(v);
    2417     1360015 : }
    2418             : 
    2419             : /* F2v */
    2420             : 
    2421             : INLINE ulong
    2422   162417728 : F2v_coeff(GEN x,long v) { return F2x_coeff(x,v-1); }
    2423             : 
    2424             : INLINE void
    2425     4180114 : F2v_clear(GEN x,long v) { F2x_clear(x,v-1); }
    2426             : 
    2427             : INLINE void
    2428    12561215 : F2v_set(GEN x,long v)   { F2x_set(x,v-1); }
    2429             : 
    2430             : INLINE void
    2431     1360015 : F2v_flip(GEN x,long v) { F2x_flip(x,v-1); }
    2432             : 
    2433             : /* F2m */
    2434             : 
    2435             : INLINE ulong
    2436    19319262 : F2m_coeff(GEN x, long a, long b) { return F2v_coeff(gel(x,b), a); }
    2437             : 
    2438             : INLINE void
    2439           0 : F2m_clear(GEN x, long a, long b) { F2v_clear(gel(x,b), a); }
    2440             : 
    2441             : INLINE void
    2442     2352087 : F2m_set(GEN x, long a, long b) { F2v_set(gel(x,b), a); }
    2443             : 
    2444             : INLINE void
    2445     1360015 : F2m_flip(GEN x, long a, long b) { F2v_flip(gel(x,b), a); }
    2446             : 
    2447             : /* ARITHMETIC */
    2448             : INLINE GEN
    2449        1029 : matpascal(long n) { return matqpascal(n, NULL); }
    2450             : INLINE long
    2451     2225428 : Z_issquare(GEN x) { return Z_issquareall(x, NULL); }
    2452             : INLINE long
    2453          14 : Z_ispower(GEN x, ulong k) { return Z_ispowerall(x, k, NULL); }
    2454             : INLINE GEN
    2455     5425292 : sqrti(GEN x) { return sqrtremi(x,NULL); }
    2456             : INLINE GEN
    2457     7403535 : gaddgs(GEN y, long s) { return gaddsg(s,y); }
    2458             : INLINE int
    2459       23890 : gcmpgs(GEN y, long s) { return -gcmpsg(s,y); }
    2460             : INLINE int
    2461       24367 : gequalgs(GEN y, long s) { return gequalsg(s,y); }
    2462             : INLINE GEN
    2463           0 : gmaxsg(long s, GEN y) { return gmaxgs(y,s); }
    2464             : INLINE GEN
    2465           0 : gminsg(long s, GEN y) { return gmings(y,s); }
    2466             : INLINE GEN
    2467    13262836 : gmulgs(GEN y, long s) { return gmulsg(s,y); }
    2468             : INLINE GEN
    2469      558170 : gsubgs(GEN y, long s) { return gaddgs(y, -s); }
    2470             : INLINE GEN
    2471      462774 : gdivsg(long s, GEN y) { return gdiv(stoi(s), y); }
    2472             : 
    2473             : /* x t_COMPLEX */
    2474             : INLINE GEN
    2475     9741721 : cxnorm(GEN x) { return gadd(gsqr(gel(x,1)), gsqr(gel(x,2))); }
    2476             : /* q t_QUAD */
    2477             : INLINE GEN
    2478         623 : quadnorm(GEN q)
    2479             : {
    2480         623 :   GEN X = gel(q,1), b = gel(X,3), c = gel(X,2);
    2481         623 :   GEN z, u = gel(q,3), v = gel(q,2);
    2482         623 :   if (typ(u) == t_INT && typ(v) == t_INT) /* generic case */
    2483             :   {
    2484         308 :     z = signe(b)? mulii(v, addii(u,v)): sqri(v);
    2485         308 :     return addii(z, mulii(c, sqri(u)));
    2486             :   }
    2487             :   else
    2488             :   {
    2489         315 :     z = signe(b)? gmul(v, gadd(u,v)): gsqr(v);
    2490         315 :     return gadd(z, gmul(c, gsqr(u)));
    2491             :   }
    2492             : }
    2493             : /* x a t_QUAD, return the attached discriminant */
    2494             : INLINE GEN
    2495         252 : quad_disc(GEN x)
    2496             : {
    2497         252 :   GEN Q = gel(x,1), b = gel(Q,3), c = gel(Q,2), c4;
    2498         252 :   if (is_pm1(b))
    2499             :   {
    2500         196 :     pari_sp av = avma; (void)new_chunk(lgefint(c) + 1);
    2501         196 :     c4 = shifti(c,2); avma = av; return subsi(1, c4);
    2502             :   }
    2503          56 :   c4 = shifti(c,2); togglesign_safe(&c4); return c4;
    2504             : }
    2505             : INLINE GEN
    2506     6345364 : qfb_disc3(GEN x, GEN y, GEN z) { return subii(sqri(y), shifti(mulii(x,z),2)); }
    2507             : INLINE GEN
    2508     6264528 : qfb_disc(GEN x) { return qfb_disc3(gel(x,1), gel(x,2), gel(x,3)); }
    2509             : 
    2510             : INLINE GEN
    2511     1244967 : sqrfrac(GEN x)
    2512             : {
    2513     1244967 :   GEN z = cgetg(3,t_FRAC);
    2514     1244967 :   gel(z,1) = sqri(gel(x,1));
    2515     1244967 :   gel(z,2) = sqri(gel(x,2)); return z;
    2516             : }
    2517             : 
    2518             : INLINE void
    2519    17527129 : normalize_frac(GEN z) {
    2520    17527129 :   if (signe(gel(z,2)) < 0) { togglesign(gel(z,1)); setabssign(gel(z,2)); }
    2521    17527129 : }
    2522             : 
    2523             : INLINE GEN
    2524      231714 : powii(GEN x, GEN n)
    2525             : {
    2526      231714 :   long ln = lgefint(n);
    2527      231714 :   if (ln == 3) {
    2528             :     GEN z;
    2529      228501 :     if (signe(n) > 0) return powiu(x, n[2]);
    2530        4956 :     z = cgetg(3, t_FRAC);
    2531        4956 :     gel(z,1) = gen_1;
    2532        4956 :     gel(z,2) = powiu(x, n[2]);
    2533        4956 :     return z;
    2534             :   }
    2535        3213 :   if (ln == 2) return gen_1; /* rare */
    2536             :   /* should never happen */
    2537           0 :   return powgi(x, n); /* overflow unless x = 0, 1, -1 */
    2538             : }
    2539             : INLINE GEN
    2540        1477 : powIs(long n) {
    2541        1477 :   switch(n & 3)
    2542             :   {
    2543           7 :     case 1: return mkcomplex(gen_0,gen_1);
    2544         364 :     case 2: return gen_m1;
    2545         455 :     case 3: return mkcomplex(gen_0,gen_m1);
    2546             :   }
    2547         651 :   return gen_1;
    2548             : }
    2549             : 
    2550             : /*******************************************************************/
    2551             : /*                                                                 */
    2552             : /*                             ASSIGNMENTS                         */
    2553             : /*                                                                 */
    2554             : /*******************************************************************/
    2555           0 : INLINE void mpexpz(GEN x, GEN z)
    2556           0 : { pari_sp av = avma; gaffect(mpexp(x), z); avma = av; }
    2557           0 : INLINE void mplogz(GEN x, GEN z)
    2558           0 : { pari_sp av = avma; gaffect(mplog(x), z); avma = av; }
    2559           0 : INLINE void mpcosz(GEN x, GEN z)
    2560           0 : { pari_sp av = avma; gaffect(mpcos(x), z); avma = av; }
    2561           0 : INLINE void mpsinz(GEN x, GEN z)
    2562           0 : { pari_sp av = avma; gaffect(mpsin(x), z); avma = av; }
    2563           0 : INLINE void gnegz(GEN x, GEN z)
    2564           0 : { pari_sp av = avma; gaffect(gneg(x), z); avma = av; }
    2565           0 : INLINE void gabsz(GEN x, long prec, GEN z)
    2566           0 : { pari_sp av = avma; gaffect(gabs(x,prec), z); avma = av; }
    2567       23318 : INLINE void gaddz(GEN x, GEN y, GEN z)
    2568       23318 : { pari_sp av = avma; gaffect(gadd(x,y), z); avma = av; }
    2569           0 : INLINE void gsubz(GEN x, GEN y, GEN z)
    2570           0 : { pari_sp av = avma; gaffect(gsub(x,y), z); avma = av; }
    2571       11673 : INLINE void gmulz(GEN x, GEN y, GEN z)
    2572       11673 : { pari_sp av = avma; gaffect(gmul(x,y), z); avma = av; }
    2573           0 : INLINE void gdivz(GEN x, GEN y, GEN z)
    2574           0 : { pari_sp av = avma; gaffect(gdiv(x,y), z); avma = av; }
    2575           0 : INLINE void gdiventz(GEN x, GEN y, GEN z)
    2576           0 : { pari_sp av = avma; gaffect(gdivent(x,y), z); avma = av; }
    2577           0 : INLINE void gmodz(GEN x, GEN y, GEN z)
    2578           0 : { pari_sp av = avma; gaffect(gmod(x,y), z); avma = av; }
    2579           0 : INLINE void gmul2nz(GEN x, long s, GEN z)
    2580           0 : { pari_sp av = avma; gaffect(gmul2n(x,s), z); avma = av; }
    2581           0 : INLINE void gshiftz(GEN x, long s, GEN z)
    2582           0 : { pari_sp av = avma; gaffect(gshift(x,s), z); avma = av; }
    2583             : 
    2584             : /*******************************************************************/
    2585             : /*                                                                 */
    2586             : /*                       ELLIPTIC CURVES                           */
    2587             : /*                                                                 */
    2588             : /*******************************************************************/
    2589     5287707 : INLINE GEN ell_get_a1(GEN e) { return gel(e,1); }
    2590     3095168 : INLINE GEN ell_get_a2(GEN e) { return gel(e,2); }
    2591     4515896 : INLINE GEN ell_get_a3(GEN e) { return gel(e,3); }
    2592     3888002 : INLINE GEN ell_get_a4(GEN e) { return gel(e,4); }
    2593     4704349 : INLINE GEN ell_get_a6(GEN e) { return gel(e,5); }
    2594     3968890 : INLINE GEN ell_get_b2(GEN e) { return gel(e,6); }
    2595     1021637 : INLINE GEN ell_get_b4(GEN e) { return gel(e,7); }
    2596     1627613 : INLINE GEN ell_get_b6(GEN e) { return gel(e,8); }
    2597     1464204 : INLINE GEN ell_get_b8(GEN e) { return gel(e,9); }
    2598     5899338 : INLINE GEN ell_get_c4(GEN e) { return gel(e,10); }
    2599     7931178 : INLINE GEN ell_get_c6(GEN e) { return gel(e,11); }
    2600     9365458 : INLINE GEN ell_get_disc(GEN e) { return gel(e,12); }
    2601     1027341 : INLINE GEN ell_get_j(GEN e) { return gel(e,13); }
    2602     7907934 : INLINE long ell_get_type(GEN e) { return mael(e,14,1); }
    2603     1561487 : INLINE GEN ellff_get_field(GEN x) { return gmael(x, 15, 1); }
    2604      678307 : INLINE GEN ellff_get_a4a6(GEN x)  { return gmael(x, 15, 2); }
    2605         917 : INLINE GEN ellQp_get_zero(GEN x) { return gmael(x, 15, 1); }
    2606         287 : INLINE long ellQp_get_prec(GEN E) { GEN z = ellQp_get_zero(E); return valp(z); }
    2607         623 : INLINE GEN ellQp_get_p(GEN E) { GEN z = ellQp_get_zero(E); return gel(z,2); }
    2608       36960 : INLINE long ellR_get_prec(GEN x) { return nbits2prec(mael3(x, 15, 1, 1)); }
    2609        8262 : INLINE long ellR_get_sign(GEN x) { return mael3(x, 15, 1, 2); }
    2610      501578 : INLINE GEN ellnf_get_nf(GEN x) { return checknf_i(gmael(x,15,1)); }
    2611          49 : INLINE GEN ellnf_get_bnf(GEN x) { return checkbnf_i(gmael(x,15,1)); }
    2612             : 
    2613    21510912 : INLINE int ell_is_inf(GEN z) { return lg(z) == 2; }
    2614      787451 : INLINE GEN ellinf(void) { return mkvec(gen_0); }
    2615             : 
    2616             : /*******************************************************************/
    2617             : /*                                                                 */
    2618             : /*                    ALGEBRAIC NUMBER THEORY                      */
    2619             : /*                                                                 */
    2620             : /*******************************************************************/
    2621     8123299 : INLINE GEN modpr_get_pr(GEN x)  { return gel(x,3); }
    2622      609916 : INLINE GEN modpr_get_p(GEN x)  { return pr_get_p(modpr_get_pr(x)); }
    2623     2520002 : INLINE GEN modpr_get_T(GEN x)  { return lg(x) == 4? NULL: gel(x,4); }
    2624             : 
    2625    18283512 : INLINE GEN pr_get_p(GEN pr)  { return gel(pr,1); }
    2626     4838267 : INLINE GEN pr_get_gen(GEN pr){ return gel(pr,2); }
    2627             : /* .[2] instead of itos works: e and f are small positive integers */
    2628     2226406 : INLINE long pr_get_e(GEN pr) { return gel(pr,3)[2]; }
    2629     7775028 : INLINE long pr_get_f(GEN pr) { return gel(pr,4)[2]; }
    2630     5792168 : INLINE GEN pr_get_tau(GEN pr){ return gel(pr,5); }
    2631             : INLINE int
    2632     2344284 : pr_is_inert(GEN P) { return pr_get_f(P) == lg(pr_get_gen(P))-1; }
    2633             : INLINE GEN
    2634      206850 : pr_norm(GEN pr) { return powiu(pr_get_p(pr), pr_get_f(pr)); }
    2635             : INLINE ulong
    2636       40873 : upr_norm(GEN pr) { return upowuu(pr_get_p(pr)[2], pr_get_f(pr)); }
    2637             : 
    2638             : /* assume nf a genuine nf */
    2639             : INLINE long
    2640        4185 : nf_get_varn(GEN nf) { return varn(gel(nf,1)); }
    2641             : INLINE GEN
    2642    27098035 : nf_get_pol(GEN nf) { return gel(nf,1); }
    2643             : INLINE long
    2644    21248956 : nf_get_degree(GEN nf) { return degpol( nf_get_pol(nf) ); }
    2645             : INLINE long
    2646     1274407 : nf_get_r1(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,1)); }
    2647             : INLINE long
    2648        8197 : nf_get_r2(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,2)); }
    2649             : INLINE GEN
    2650       46797 : nf_get_disc(GEN nf) { return gel(nf,3); }
    2651             : INLINE GEN
    2652      751941 : nf_get_index(GEN nf) { return gel(nf,4); }
    2653             : INLINE GEN
    2654     1215467 : nf_get_M(GEN nf) { return gmael(nf,5,1); }
    2655             : INLINE GEN
    2656       60567 : nf_get_G(GEN nf) { return gmael(nf,5,2); }
    2657             : INLINE GEN
    2658      440320 : nf_get_roundG(GEN nf) { return gmael(nf,5,3); }
    2659             : INLINE GEN
    2660       24339 : nf_get_Tr(GEN nf) { return gmael(nf,5,4); }
    2661             : INLINE GEN
    2662        2191 : nf_get_diff(GEN nf) { return gmael(nf,5,5); }
    2663             : INLINE GEN
    2664          28 : nf_get_ramified_primes(GEN nf) { return gmael(nf,5,8); }
    2665             : INLINE GEN
    2666      158004 : nf_get_roots(GEN nf) { return gel(nf,6); }
    2667             : INLINE GEN
    2668          77 : nf_get_zk(GEN nf)
    2669             : {
    2670          77 :   GEN y = gel(nf,7), D = nf_get_zkden(nf);
    2671          77 :   if (!equali1(D)) y = gdiv(y, D);
    2672          77 :   return y;
    2673             : }
    2674             : INLINE GEN
    2675      219876 : nf_get_zkprimpart(GEN nf)
    2676             : {
    2677      219876 :   GEN y = gel(nf,7);
    2678             :   /* test for old format of nf.zk: non normalized */
    2679      219876 :   if (!equali1(gel(nf,4)) && gequal1(gel(y,1))) y = Q_remove_denom(y,NULL);
    2680      219876 :   return y;
    2681             : }
    2682             : INLINE GEN
    2683      222473 : nf_get_zkden(GEN nf)
    2684             : {
    2685      222473 :   GEN y = gel(nf,7), D = gel(y,1);
    2686      222473 :   if (typ(D) == t_POL) D = gel(D,2);
    2687             :   /* test for old format of nf.zk: non normalized */
    2688      222473 :   if (!equali1(gel(nf,4)) && equali1(D)) D = Q_denom(y);
    2689      222473 :   return D;
    2690             : }
    2691             : INLINE GEN
    2692     2176445 : nf_get_invzk(GEN nf) { return gel(nf,8); }
    2693             : INLINE void
    2694       13734 : nf_get_sign(GEN nf, long *r1, long *r2)
    2695             : {
    2696       13734 :   GEN x = gel(nf,2);
    2697       13734 :   *r1 = itou(gel(x,1));
    2698       13734 :   *r2 = itou(gel(x,2));
    2699       13734 : }
    2700             : 
    2701             : INLINE GEN
    2702       49616 : abgrp_get_no(GEN x) { return gel(x,1); }
    2703             : INLINE GEN
    2704     2033778 : abgrp_get_cyc(GEN x) { return gel(x,2); }
    2705             : INLINE GEN
    2706      396461 : abgrp_get_gen(GEN x) { return gel(x,3); }
    2707             : INLINE GEN
    2708     2064067 : bnf_get_nf(GEN bnf) { return gel(bnf,7); }
    2709             : INLINE GEN
    2710      806355 : bnf_get_clgp(GEN bnf) { return gmael(bnf,8,1); }
    2711             : INLINE GEN
    2712        4536 : bnf_get_no(GEN bnf) { return abgrp_get_no(bnf_get_clgp(bnf)); }
    2713             : INLINE GEN
    2714      434282 : bnf_get_cyc(GEN bnf) { return abgrp_get_cyc(bnf_get_clgp(bnf)); }
    2715             : INLINE GEN
    2716      367208 : bnf_get_gen(GEN bnf)  { return abgrp_get_gen(bnf_get_clgp(bnf)); }
    2717             : INLINE GEN
    2718         860 : bnf_get_reg(GEN bnf) { return gmael(bnf,8,2); }
    2719             : INLINE GEN
    2720      482141 : bnf_get_logfu(GEN bnf) { return gel(bnf,3); }
    2721             : INLINE GEN
    2722        5867 : bnf_get_tuU(GEN bnf) { return gmael3(bnf,8,4,2); }
    2723             : INLINE long
    2724       24535 : bnf_get_tuN(GEN bnf) { return gmael3(bnf,8,4,1)[2]; }
    2725             : INLINE GEN
    2726        1806 : bnf_get_fu(GEN bnf) {
    2727        1806 :   GEN fu = bnf_get_fu_nocheck(bnf);
    2728        1806 :   if (typ(fu) == t_MAT) pari_err(e_MISC,"missing units in bnf");
    2729        1806 :   return fu;
    2730             : }
    2731             : INLINE GEN
    2732        7134 : bnf_get_fu_nocheck(GEN bnf) { return gmael(bnf,8,5); }
    2733             : 
    2734             : INLINE GEN
    2735      747465 : bnr_get_bnf(GEN bnr) { return gel(bnr,1); }
    2736             : INLINE GEN
    2737      384509 : bnr_get_bid(GEN bnr) { return gel(bnr,2); }
    2738             : INLINE GEN
    2739       18102 : bnr_get_mod(GEN bnr) { return gmael(bnr,2,1); }
    2740             : INLINE GEN
    2741       27104 : bnr_get_nf(GEN bnr) { return gmael(bnr,1,7); }
    2742             : INLINE GEN
    2743      520568 : bnr_get_clgp(GEN bnr) { return gel(bnr,5); }
    2744             : INLINE GEN
    2745       45080 : bnr_get_no(GEN bnr) { return abgrp_get_no(bnr_get_clgp(bnr)); }
    2746             : INLINE GEN
    2747      463560 : bnr_get_cyc(GEN bnr) { return abgrp_get_cyc(bnr_get_clgp(bnr)); }
    2748             : INLINE GEN
    2749          70 : bnr_get_gen_nocheck(GEN bnr) { return abgrp_get_gen(bnr_get_clgp(bnr)); }
    2750             : INLINE GEN
    2751       11025 : bnr_get_gen(GEN bnr) {
    2752       11025 :   GEN G = bnr_get_clgp(bnr);
    2753       11025 :   if (lg(G) !=  4)
    2754           0 :     pari_err(e_MISC,"missing bnr generators: please use bnrinit(,,1)");
    2755       11025 :   return gel(G,3);
    2756             : }
    2757             : 
    2758             : INLINE GEN
    2759      302504 : bid_get_mod(GEN bid) { return gel(bid,1); }
    2760             : INLINE GEN
    2761       44681 : bid_get_ideal(GEN bid) { return gmael(bid,1,1); }
    2762             : INLINE GEN
    2763         448 : bid_get_arch(GEN bid) { return gmael(bid,1,2); }
    2764             : INLINE GEN
    2765     1061330 : bid_get_grp(GEN bid) { return gel(bid,2); }
    2766             : INLINE GEN
    2767      395912 : bid_get_fact(GEN bid) { return gmael(bid,3,1); }
    2768             : INLINE GEN
    2769      354612 : bid_get_fact2(GEN bid) { return gmael(bid,3,2); }
    2770             : INLINE GEN
    2771      354682 : bid_get_sprk(GEN bid) { return gmael(bid,4,1); }
    2772             : INLINE GEN
    2773       29813 : bid_get_sarch(GEN bid) { return gmael(bid,4,2); }
    2774             : INLINE GEN
    2775      375262 : bid_get_archp(GEN bid) { return gmael3(bid,4,2,2); }
    2776             : INLINE GEN
    2777      657396 : bid_get_U(GEN bid) { return gel(bid,5); }
    2778             : INLINE GEN
    2779           0 : bid_get_no(GEN bid) { return abgrp_get_no(bid_get_grp(bid)); }
    2780             : INLINE GEN
    2781     1033043 : bid_get_cyc(GEN bid) { return abgrp_get_cyc(bid_get_grp(bid)); }
    2782             : INLINE GEN
    2783           0 : bid_get_gen_nocheck(GEN bid)  { return abgrp_get_gen(bid_get_grp(bid)); }
    2784             : INLINE GEN
    2785       27692 : bid_get_gen(GEN bid) {
    2786       27692 :   GEN G = bid_get_grp(bid);
    2787       27692 :   if (lg(G) != 4) pari_err(e_MISC,"missing bid generators. Use idealstar(,,2)");
    2788       27692 :   return abgrp_get_gen(G);
    2789             : }
    2790             : 
    2791             : INLINE GEN
    2792     2519832 : znstar_get_N(GEN G) { return gmael(G,1,1); }
    2793             : INLINE GEN
    2794     2800315 : znstar_get_faN(GEN G) { return gel(G,3); }
    2795             : INLINE GEN
    2796           0 : znstar_get_no(GEN G) { return abgrp_get_no(gel(G,2)); }
    2797             : INLINE GEN
    2798      101479 : znstar_get_cyc(GEN G) { return abgrp_get_cyc(gel(G,2)); }
    2799             : INLINE GEN
    2800           0 : znstar_get_gen(GEN G) { return abgrp_get_gen(gel(G,2)); }
    2801             : INLINE GEN
    2802     2735887 : znstar_get_conreycyc(GEN G) { return gmael(G,4,5); }
    2803             : INLINE GEN
    2804     1260686 : znstar_get_conreygen(GEN G) { return gmael(G,4,4); }
    2805             : INLINE GEN
    2806       40103 : znstar_get_Ui(GEN G) { return gmael(G,4,3); }
    2807             : INLINE GEN
    2808       28322 : znstar_get_U(GEN G) { return gel(G,5); }
    2809             : INLINE GEN
    2810     1223516 : znstar_get_pe(GEN G) { return gmael(G,4,1); }
    2811             : INLINE GEN
    2812       19152 : gal_get_pol(GEN gal) { return gel(gal,1); }
    2813             : INLINE GEN
    2814        1225 : gal_get_p(GEN gal) { return gmael(gal,2,1); }
    2815             : INLINE GEN
    2816          63 : gal_get_e(GEN gal) { return gmael(gal,2,2); }
    2817             : INLINE GEN
    2818       15631 : gal_get_mod(GEN gal) { return gmael(gal,2,3); }
    2819             : INLINE GEN
    2820       16009 : gal_get_roots(GEN gal) { return gel(gal,3); }
    2821             : INLINE GEN
    2822       15631 : gal_get_invvdm(GEN gal) { return gel(gal,4); }
    2823             : INLINE GEN
    2824       15631 : gal_get_den(GEN gal) { return gel(gal,5); }
    2825             : INLINE GEN
    2826       61516 : gal_get_group(GEN gal) { return gel(gal,6); }
    2827             : INLINE GEN
    2828        3927 : gal_get_gen(GEN gal) { return gel(gal,7); }
    2829             : INLINE GEN
    2830        3577 : gal_get_orders(GEN gal) { return gel(gal,8); }
    2831             : 
    2832             : /* assume rnf a genuine rnf */
    2833             : INLINE long
    2834      944804 : rnf_get_degree(GEN rnf) { return degpol(rnf_get_pol(rnf)); }
    2835             : INLINE long
    2836       15274 : rnf_get_nfdegree(GEN rnf) { return degpol(nf_get_pol(rnf_get_nf(rnf))); }
    2837             : INLINE long
    2838      763693 : rnf_get_absdegree(GEN rnf) { return degpol(gmael(rnf,11,1)); }
    2839             : INLINE GEN
    2840         462 : rnf_get_idealdisc(GEN rnf) { return gmael(rnf,3,1); }
    2841             : INLINE GEN
    2842         448 : rnf_get_k(GEN rnf) { return gmael(rnf,11,3); }
    2843             : INLINE GEN
    2844         448 : rnf_get_alpha(GEN rnf) { return gmael(rnf, 11, 2); }
    2845             : INLINE GEN
    2846      128744 : rnf_get_nf(GEN rnf) { return gel(rnf,10); }
    2847             : INLINE void
    2848        2485 : rnf_get_nfzk(GEN rnf, GEN *b, GEN *cb) {*b=gmael(rnf,2,1); *cb=gmael(rnf,2,2);}
    2849             : INLINE GEN
    2850       97384 : rnf_get_polabs(GEN rnf) { return gmael(rnf,11,1); }
    2851             : INLINE GEN
    2852     1099035 : rnf_get_pol(GEN rnf) { return gel(rnf,1); }
    2853             : INLINE GEN
    2854          63 : rnf_get_disc(GEN rnf) { return gel(rnf,3); }
    2855             : INLINE GEN
    2856         105 : rnf_get_index(GEN rnf) { return gel(rnf,4); }
    2857             : INLINE long
    2858           0 : rnf_get_varn(GEN rnf) { return varn(gel(rnf,1)); }
    2859             : INLINE GEN
    2860      108150 : rnf_get_nfpol(GEN rnf) { return gmael(rnf,10,1); }
    2861             : INLINE long
    2862         595 : rnf_get_nfvarn(GEN rnf) { return varn(gmael(rnf,10,1)); }
    2863             : INLINE GEN
    2864        2856 : rnf_get_zk(GEN rnf) { return gel(rnf,7); }
    2865             : INLINE GEN
    2866       35287 : rnf_get_map(GEN rnf) { return gel(rnf,11); }
    2867             : INLINE GEN
    2868        1190 : rnf_get_invzk(GEN rnf) { return gel(rnf,8); }
    2869             : 
    2870             : /* I integral ZM (not HNF), G ZM, rounded Cholesky form of a weighted
    2871             :  * T2 matrix. Reduce I wrt G */
    2872             : INLINE GEN
    2873       13132 : idealpseudored(GEN I, GEN G)
    2874       13132 : { return ZM_mul(I, ZM_lll(ZM_mul(G, I), 0.99, LLL_IM)); }
    2875             : 
    2876             : /* I integral (not necessarily HNF), G ZM, rounded Cholesky form of a weighted
    2877             :  * T2 matrix. Return m in I with T2(m) small */
    2878             : INLINE GEN
    2879      157002 : idealpseudomin(GEN I, GEN G)
    2880             : {
    2881      157002 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2882      157002 :   return ZM_ZC_mul(I, gel(u,1));
    2883             : }
    2884             : /* I, G as in idealpseudomin. Return an irrational m in I with T2(m) small */
    2885             : INLINE GEN
    2886      300506 : idealpseudomin_nonscalar(GEN I, GEN G)
    2887             : {
    2888      300506 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2889      300506 :   GEN m = ZM_ZC_mul(I, gel(u,1));
    2890      300506 :   if (ZV_isscalar(m) && lg(u) > 2) m = ZM_ZC_mul(I, gel(u,2));
    2891      300506 :   return m;
    2892             : }
    2893             : 
    2894             : INLINE GEN
    2895           0 : idealred_elt(GEN nf, GEN I) {
    2896           0 :   pari_sp av = avma;
    2897           0 :   GEN u = idealpseudomin(I, nf_get_roundG(nf));
    2898           0 :   return gerepileupto(av, u);
    2899             : }
    2900             : INLINE GEN
    2901      162736 : idealred(GEN nf, GEN I) { return idealred0(nf, I, NULL); }
    2902             : 
    2903             : INLINE GEN
    2904        1302 : idealchineseinit(GEN nf, GEN x)
    2905        1302 : { return idealchinese(nf,x,NULL); }
    2906             : 
    2907             : /*******************************************************************/
    2908             : /*                                                                 */
    2909             : /*                              CLOSURES                           */
    2910             : /*                                                                 */
    2911             : /*******************************************************************/
    2912   248954992 : INLINE long closure_arity(GEN C)          { return ((ulong)C[1])&ARITYBITS; }
    2913    34811268 : INLINE long closure_is_variadic(GEN C) { return !!(((ulong)C[1])&VARARGBITS); }
    2914   213921703 : INLINE const char *closure_codestr(GEN C)  { return GSTR(gel(C,2))-1; }
    2915           0 : INLINE GEN closure_get_code(GEN C)  { return gel(C,2); }
    2916   213867927 : INLINE GEN closure_get_oper(GEN C)  { return gel(C,3); }
    2917   213840549 : INLINE GEN closure_get_data(GEN C)  { return gel(C,4); }
    2918        8413 : INLINE GEN closure_get_dbg(GEN C)   { return gel(C,5); }
    2919       20375 : INLINE GEN closure_get_text(GEN C)  { return gel(C,6); }
    2920      813038 : INLINE GEN closure_get_frame(GEN C) { return gel(C,7); }
    2921             : 
    2922             : /*******************************************************************/
    2923             : /*                                                                 */
    2924             : /*                               ERRORS                            */
    2925             : /*                                                                 */
    2926             : /*******************************************************************/
    2927             : INLINE long
    2928       30463 : err_get_num(GEN e) { return e[1]; }
    2929             : INLINE GEN
    2930          70 : err_get_compo(GEN e, long i) { return gel(e, i+1); }
    2931             : 
    2932             : INLINE void
    2933          14 : pari_err_BUG(const char *f) { pari_err(e_BUG,f); }
    2934             : INLINE void
    2935           7 : pari_err_CONSTPOL(const char *f) { pari_err(e_CONSTPOL, f); }
    2936             : INLINE void
    2937          63 : pari_err_COPRIME(const char *f, GEN x, GEN y) { pari_err(e_COPRIME, f,x,y); }
    2938             : INLINE void
    2939         445 : pari_err_DIM(const char *f) { pari_err(e_DIM, f); }
    2940             : INLINE void
    2941           0 : pari_err_FILE(const char *f, const char *g) { pari_err(e_FILE, f,g); }
    2942             : INLINE void
    2943          28 : pari_err_FLAG(const char *f) { pari_err(e_FLAG,f); }
    2944             : INLINE void
    2945         357 : pari_err_IMPL(const char *f) { pari_err(e_IMPL,f); }
    2946             : INLINE void
    2947         705 : pari_err_INV(const char *f, GEN x) { pari_err(e_INV,f,x); }
    2948             : INLINE void
    2949          21 : pari_err_IRREDPOL(const char *f, GEN x) { pari_err(e_IRREDPOL, f,x); }
    2950             : INLINE void
    2951        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); }
    2952             : INLINE void
    2953         245 : pari_err_COMPONENT(const char *f, const char *op, GEN l, GEN x) { pari_err(e_COMPONENT, f,op,l,x); }
    2954             : INLINE void
    2955           0 : pari_err_MAXPRIME(ulong c) { pari_err(e_MAXPRIME, c); }
    2956             : INLINE void
    2957         287 : pari_err_OP(const char *f, GEN x, GEN y) { pari_err(e_OP, f,x,y); }
    2958             : INLINE void
    2959          84 : pari_err_OVERFLOW(const char *f) { pari_err(e_OVERFLOW, f); }
    2960             : INLINE void
    2961         219 : pari_err_PREC(const char *f) { pari_err(e_PREC,f); }
    2962             : INLINE void
    2963           0 : pari_err_PACKAGE(const char *f) { pari_err(e_PACKAGE,f); }
    2964             : INLINE void
    2965          56 : pari_err_PRIME(const char *f, GEN x) { pari_err(e_PRIME, f,x); }
    2966             : INLINE void
    2967         735 : pari_err_MODULUS(const char *f, GEN x, GEN y) { pari_err(e_MODULUS, f,x,y); }
    2968             : INLINE void
    2969          42 : pari_err_ROOTS0(const char *f) { pari_err(e_ROOTS0, f); }
    2970             : INLINE void
    2971          77 : pari_err_SQRTN(const char *f, GEN x) { pari_err(e_SQRTN, f,x); }
    2972             : INLINE void
    2973       11383 : pari_err_TYPE(const char *f, GEN x) { pari_err(e_TYPE, f,x); }
    2974             : INLINE void
    2975        3045 : pari_err_TYPE2(const char *f, GEN x, GEN y) { pari_err(e_TYPE2, f,x,y); }
    2976             : INLINE void
    2977         203 : pari_err_VAR(const char *f, GEN x, GEN y) { pari_err(e_VAR, f,x,y); }
    2978             : INLINE void
    2979         147 : pari_err_PRIORITY(const char *f, GEN x, const char *op, long v)
    2980         147 : { pari_err(e_PRIORITY, f,x,op,v); }

Generated by: LCOV version 1.11