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 20838-243a3c2) Lines: 1237 1408 87.9 %
Date: 2017-07-28 06:22:09 Functions: 524 596 87.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (C) 2000-2010  The PARI group.
       2             : 
       3             : This file is part of the PARI/GP package.
       4             : 
       5             : PARI/GP is free software; you can redistribute it and/or modify it under the
       6             : terms of the GNU General Public License as published by the Free Software
       7             : Foundation. It is distributed in the hope that it will be useful, but WITHOUT
       8             : ANY WARRANTY WHATSOEVER.
       9             : 
      10             : Check the License for details. You should have received a copy of it, along
      11             : with the package; see the file 'COPYING'. If not, write to the Free Software
      12             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
      13             : 
      14             : /*******************************************************************/
      15             : /*                                                                 */
      16             : /*                          CONSTRUCTORS                           */
      17             : /*                                                                 */
      18             : /*******************************************************************/
      19             : #define retmkfrac(x,y)\
      20             :   do { GEN _v = cgetg(3, t_FRAC);\
      21             :        gel(_v,1) = (x);\
      22             :        gel(_v,2) = (y); return _v; } while(0)
      23             : #define retmkrfrac(x,y)\
      24             :   do { GEN _v = cgetg(3, t_RFRAC);\
      25             :        gel(_v,1) = (x);\
      26             :        gel(_v,2) = (y); return _v; } while(0)
      27             : #define retmkintmod(x,y)\
      28             :   do { GEN _v = cgetg(3, t_INTMOD);\
      29             :        gel(_v,1) = (y);\
      30             :        gel(_v,2) = (x); return _v; } while(0)
      31             : #define retmkcomplex(x,y)\
      32             :   do { GEN _v = cgetg(3, t_COMPLEX);\
      33             :        gel(_v,1) = (x);\
      34             :        gel(_v,2) = (y); return _v; } while(0)
      35             : #define retmkpolmod(x,y)\
      36             :   do { GEN _v = cgetg(3, t_POLMOD);\
      37             :        gel(_v,1) = (y);\
      38             :        gel(_v,2) = (x); return _v; } while(0)
      39             : #define retmkvec(x)\
      40             :   do { GEN _v = cgetg(2, t_VEC);\
      41             :        gel(_v,1) = (x); return _v; } while(0)
      42             : #define retmkvec2(x,y)\
      43             :   do { GEN _v = cgetg(3, t_VEC);\
      44             :        gel(_v,1) = (x);\
      45             :        gel(_v,2) = (y); return _v; } while(0)
      46             : #define retmkvec3(x,y,z)\
      47             :   do { GEN _v = cgetg(4, t_VEC);\
      48             :        gel(_v,1) = (x);\
      49             :        gel(_v,2) = (y);\
      50             :        gel(_v,3) = (z); return _v; } while(0)
      51             : #define retmkqfi(x,y,z)\
      52             :   do { GEN _v = cgetg(4, t_QFI);\
      53             :        gel(_v,1) = (x);\
      54             :        gel(_v,2) = (y);\
      55             :        gel(_v,3) = (z); return _v; } while(0)
      56             : #define retmkqfr(x,y,z,d)\
      57             :   do { GEN _v = cgetg(5, t_QFR);\
      58             :        gel(_v,1) = (x);\
      59             :        gel(_v,2) = (y);\
      60             :        gel(_v,3) = (z);\
      61             :        gel(_v,4) = (d); return _v; } while(0)
      62             : #define retmkquad(x,y,z)\
      63             :   do { GEN _v = cgetg(4, t_QUAD);\
      64             :        gel(_v,1) = (x);\
      65             :        gel(_v,2) = (y);\
      66             :        gel(_v,3) = (z); return _v; } while(0)
      67             : #define retmkvec4(x,y,z,t)\
      68             :   do { GEN _v = cgetg(5, t_VEC);\
      69             :        gel(_v,1) = (x);\
      70             :        gel(_v,2) = (y);\
      71             :        gel(_v,3) = (z);\
      72             :        gel(_v,4) = (t); return _v; } while(0)
      73             : #define retmkvec5(x,y,z,t,u)\
      74             :   do { GEN _v = cgetg(6, t_VEC);\
      75             :        gel(_v,1) = (x);\
      76             :        gel(_v,2) = (y);\
      77             :        gel(_v,3) = (z);\
      78             :        gel(_v,4) = (t);\
      79             :        gel(_v,5) = (u); return _v; } while(0)
      80             : #define retmkcol(x)\
      81             :   do { GEN _v = cgetg(2, t_COL);\
      82             :        gel(_v,1) = (x); return _v; } while(0)
      83             : #define retmkcol2(x,y)\
      84             :   do { GEN _v = cgetg(3, t_COL);\
      85             :        gel(_v,1) = (x);\
      86             :        gel(_v,2) = (y); return _v; } while(0)
      87             : #define retmkcol3(x,y,z)\
      88             :   do { GEN _v = cgetg(4, t_COL);\
      89             :        gel(_v,1) = (x);\
      90             :        gel(_v,2) = (y);\
      91             :        gel(_v,3) = (z); return _v; } while(0)
      92             : #define retmkcol4(x,y,z,t)\
      93             :   do { GEN _v = cgetg(5, t_COL);\
      94             :        gel(_v,1) = (x);\
      95             :        gel(_v,2) = (y);\
      96             :        gel(_v,3) = (z);\
      97             :        gel(_v,4) = (t); return _v; } while(0)
      98             : #define retmkcol5(x,y,z,t,u)\
      99             :   do { GEN _v = cgetg(6, t_COL);\
     100             :        gel(_v,1) = (x);\
     101             :        gel(_v,2) = (y);\
     102             :        gel(_v,3) = (z);\
     103             :        gel(_v,4) = (t);\
     104             :        gel(_v,5) = (u); return _v; } while(0)
     105             : #define retmkcol6(x,y,z,t,u,v)\
     106             :   do { GEN _v = cgetg(7, t_COL);\
     107             :        gel(_v,1) = (x);\
     108             :        gel(_v,2) = (y);\
     109             :        gel(_v,3) = (z);\
     110             :        gel(_v,4) = (t);\
     111             :        gel(_v,5) = (u);\
     112             :        gel(_v,6) = (v); return _v; } while(0)
     113             : #define retmkmat(x)\
     114             :   do { GEN _v = cgetg(2, t_MAT);\
     115             :        gel(_v,1) = (x); return _v; } while(0)
     116             : #define retmkmat2(x,y)\
     117             :   do { GEN _v = cgetg(3, t_MAT);\
     118             :        gel(_v,1) = (x);\
     119             :        gel(_v,2) = (y); return _v; } while(0)
     120             : #define retmkmat3(x,y,z)\
     121             :   do { GEN _v = cgetg(4, t_MAT);\
     122             :        gel(_v,1) = (x);\
     123             :        gel(_v,2) = (y);\
     124             :        gel(_v,3) = (z); return _v; } while(0)
     125             : #define retmkmat4(x,y,z,t)\
     126             :   do { GEN _v = cgetg(5, t_MAT);\
     127             :        gel(_v,1) = (x);\
     128             :        gel(_v,2) = (y);\
     129             :        gel(_v,3) = (z);\
     130             :        gel(_v,4) = (t); return _v; } while(0)
     131             : #define retmkmat5(x,y,z,t,u)\
     132             :   do { GEN _v = cgetg(6, t_MAT);\
     133             :        gel(_v,1) = (x);\
     134             :        gel(_v,2) = (y);\
     135             :        gel(_v,3) = (z);\
     136             :        gel(_v,4) = (t);\
     137             :        gel(_v,5) = (u); return _v; } while(0)
     138             : 
     139             : INLINE GEN
     140     1453551 : 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      264318 : mkpolmod(GEN x, GEN y) { retmkpolmod(x,y); }
     149             : INLINE GEN
     150     2396675 : mkfrac(GEN x, GEN y) { retmkfrac(x,y); }
     151             : INLINE GEN
     152     3955098 : mkfraccopy(GEN x, GEN y) { retmkfrac(icopy(x), icopy(y)); }
     153             : INLINE GEN
     154           7 : mkrfrac(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     155           7 :   gel(v,1) = x; gel(v,2) = y; return v; }
     156             : INLINE GEN
     157           7 : mkrfraccopy(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     158           7 :   gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     159             : INLINE GEN
     160     3091819 : mkcomplex(GEN x, GEN y) { retmkcomplex(x,y); }
     161             : INLINE GEN
     162      435535 : gen_I(void) { return mkcomplex(gen_0, gen_1); }
     163             : INLINE GEN
     164      204387 : cgetc(long l) { retmkcomplex(cgetr(l), cgetr(l)); }
     165             : INLINE GEN
     166          42 : mkquad(GEN n, GEN x, GEN y) { GEN v = cgetg(4, t_QUAD);
     167          42 :   gel(v,1) = n; gel(v,2) = x; gel(v,3) = y; return v; }
     168             : /* vecsmall */
     169             : INLINE GEN
     170    54608936 : mkvecsmall(long x) { GEN v = cgetg(2, t_VECSMALL); v[1] = x; return v; }
     171             : INLINE GEN
     172   109614320 : mkvecsmall2(long x,long y) { GEN v = cgetg(3, t_VECSMALL);
     173   109606825 :   v[1]=x; v[2]=y; return v; }
     174             : INLINE GEN
     175    64947099 : mkvecsmall3(long x,long y,long z) { GEN v = cgetg(4, t_VECSMALL);
     176    64944615 :   v[1]=x; v[2]=y; v[3]=z; return v; }
     177             : INLINE GEN
     178    23713036 : mkvecsmall4(long x,long y,long z,long t) { GEN v = cgetg(5, t_VECSMALL);
     179    23698931 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; return v; }
     180             : INLINE GEN
     181      702726 : mkvecsmall5(long x,long y,long z,long t,long u) { GEN v = cgetg(6, t_VECSMALL);
     182      702726 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; v[5]=u; return v; }
     183             : 
     184             : INLINE GEN
     185      158123 : mkqfi(GEN x, GEN y, GEN z) { retmkqfi(x,y,z); }
     186             : /* vec */
     187             : INLINE GEN
     188     3662334 : mkvec(GEN x) { retmkvec(x); }
     189             : INLINE GEN
     190   131690496 : mkvec2(GEN x, GEN y) { retmkvec2(x,y); }
     191             : INLINE GEN
     192    74449636 : mkvec3(GEN x, GEN y, GEN z) { retmkvec3(x,y,z); }
     193             : INLINE GEN
     194     7740271 : mkvec4(GEN x, GEN y, GEN z, GEN t) { retmkvec4(x,y,z,t); }
     195             : INLINE GEN
     196    11954197 : mkvec5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkvec5(x,y,z,t,u); }
     197             : INLINE GEN
     198           7 : mkvecs(long x) { retmkvec(stoi(x)); }
     199             : INLINE GEN
     200       19885 : mkvec2s(long x, long y) { retmkvec2(stoi(x),stoi(y)); }
     201             : INLINE GEN
     202      492702 : mkvec3s(long x, long y, long z) { retmkvec3(stoi(x),stoi(y),stoi(z)); }
     203             : INLINE GEN
     204           0 : mkvec4s(long x, long y, long z, long t) { retmkvec4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     205             : INLINE GEN
     206       33460 : mkveccopy(GEN x) { GEN v = cgetg(2, t_VEC); gel(v,1) = gcopy(x); return v; }
     207             : INLINE GEN
     208      109129 : mkvec2copy(GEN x, GEN y) {
     209      109129 :   GEN v = cgetg(3,t_VEC); gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     210             : /* col */
     211             : INLINE GEN
     212     2203381 : mkcol(GEN x) { retmkcol(x); }
     213             : INLINE GEN
     214    14935339 : mkcol2(GEN x, GEN y) { retmkcol2(x,y); }
     215             : INLINE GEN
     216       41615 : mkcol3(GEN x, GEN y, GEN z) { retmkcol3(x,y,z); }
     217             : INLINE GEN
     218           0 : mkcol4(GEN x, GEN y, GEN z, GEN t) { retmkcol4(x,y,z,t); }
     219             : INLINE GEN
     220           0 : mkcol5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkcol5(x,y,z,t,u); }
     221             : INLINE GEN
     222        4208 : mkcol6(GEN x, GEN y, GEN z, GEN t, GEN u, GEN v) { retmkcol6(x,y,z,t,u,v); }
     223             : INLINE GEN
     224         728 : mkcols(long x) { retmkcol(stoi(x)); }
     225             : INLINE GEN
     226     1181376 : mkcol2s(long x, long y) { retmkcol2(stoi(x),stoi(y)); }
     227             : INLINE GEN
     228           0 : mkcol3s(long x, long y, long z) { retmkcol3(stoi(x),stoi(y),stoi(z)); }
     229             : INLINE GEN
     230           0 : mkcol4s(long x, long y, long z, long t) { retmkcol4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     231             : INLINE GEN
     232       28804 : mkcolcopy(GEN x) { GEN v = cgetg(2, t_COL); gel(v,1) = gcopy(x); return v; }
     233             : /* mat */
     234             : INLINE GEN
     235      730466 : mkmat(GEN x) { retmkmat(x); }
     236             : INLINE GEN
     237    16239402 : mkmat2(GEN x, GEN y) { retmkmat2(x,y); }
     238             : INLINE GEN
     239        2352 : mkmat3(GEN x, GEN y, GEN z) { retmkmat3(x,y,z); }
     240             : INLINE GEN
     241           0 : mkmat4(GEN x, GEN y, GEN z, GEN t) { retmkmat4(x,y,z,t); }
     242             : INLINE GEN
     243           0 : mkmat5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkmat5(x,y,z,t,u); }
     244             : INLINE GEN
     245        7404 : mkmatcopy(GEN x) { GEN v = cgetg(2, t_MAT); gel(v,1) = gcopy(x); return v; }
     246             : INLINE GEN
     247           0 : mkerr(long x) { GEN v = cgetg(2, t_ERROR); v[1] = x; return v; }
     248             : INLINE GEN
     249       24192 : mkoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_1; return v; }
     250             : INLINE GEN
     251       13867 : mkmoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_m1; return v; }
     252             : INLINE long
     253       47286 : inf_get_sign(GEN x) { return signe(gel(x,1)); }
     254             : /* pol */
     255             : INLINE GEN
     256      711142 : pol_x(long v) {
     257      711142 :   GEN p = cgetg(4, t_POL);
     258      711142 :   p[1] = evalsigne(1)|evalvarn(v);
     259      711142 :   gel(p,2) = gen_0;
     260      711142 :   gel(p,3) = gen_1; return p;
     261             : }
     262             : /* x^n, assume n >= 0 */
     263             : INLINE GEN
     264     2473669 : pol_xn(long n, long v) {
     265     2473669 :   long i, a = n+2;
     266     2473669 :   GEN p = cgetg(a+1, t_POL);
     267     2473669 :   p[1] = evalsigne(1)|evalvarn(v);
     268     2473669 :   for (i = 2; i < a; i++) gel(p,i) = gen_0;
     269     2473669 :   gel(p,a) = gen_1; return p;
     270             : }
     271             : /* x^n, no assumption on n */
     272             : INLINE GEN
     273          42 : pol_xnall(long n, long v)
     274             : {
     275          42 :   if (n < 0) retmkrfrac(gen_1, pol_xn(-n,v));
     276          42 :   return pol_xn(n, v);
     277             : }
     278             : INLINE GEN
     279     1199867 : pol_1(long v) {
     280     1199867 :   GEN p = cgetg(3, t_POL);
     281     1199867 :   p[1] = evalsigne(1)|evalvarn(v);
     282     1199867 :   gel(p,2) = gen_1; return p;
     283             : }
     284             : INLINE GEN
     285    18065159 : pol_0(long v)
     286             : {
     287    18065159 :   GEN x = cgetg(2,t_POL);
     288    18065159 :   x[1] = evalvarn(v); return x;
     289             : }
     290             : #define retconst_vec(n,x)\
     291             :   do { long _i, _n = (n);\
     292             :        GEN _v = cgetg(_n+1, t_VEC), _x = (x);\
     293             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     294             :        return _v; } while(0)
     295             : INLINE GEN
     296     7356325 : const_vec(long n, GEN x) { retconst_vec(n, x); }
     297             : #define retconst_col(n,x)\
     298             :   do { long _i, _n = (n);\
     299             :        GEN _v = cgetg(_n+1, t_COL), _x = (x);\
     300             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     301             :        return _v; } while(0)
     302             : INLINE GEN
     303       93426 : const_col(long n, GEN x) { retconst_col(n, x); }
     304             : INLINE GEN
     305     4532924 : const_vecsmall(long n, long c)
     306             : {
     307             :   long i;
     308     4532924 :   GEN V = cgetg(n+1,t_VECSMALL);
     309     4532925 :   for(i=1;i<=n;i++) V[i] = c;
     310     4532925 :   return V;
     311             : }
     312             : 
     313             : /***   ZERO   ***/
     314             : /* O(p^e) */
     315             : INLINE GEN
     316      301252 : zeropadic(GEN p, long e)
     317             : {
     318      301252 :   GEN y = cgetg(5,t_PADIC);
     319      301252 :   gel(y,4) = gen_0;
     320      301252 :   gel(y,3) = gen_1;
     321      301252 :   gel(y,2) = icopy(p);
     322      301252 :   y[1] = evalvalp(e) | _evalprecp(0);
     323      301252 :   return y;
     324             : }
     325             : INLINE GEN
     326         532 : zeropadic_shallow(GEN p, long e)
     327             : {
     328         532 :   GEN y = cgetg(5,t_PADIC);
     329         532 :   gel(y,4) = gen_0;
     330         532 :   gel(y,3) = gen_1;
     331         532 :   gel(y,2) = p;
     332         532 :   y[1] = evalvalp(e) | _evalprecp(0);
     333         532 :   return y;
     334             : }
     335             : /* O(pol_x(v)^e) */
     336             : INLINE GEN
     337       14959 : zeroser(long v, long e)
     338             : {
     339       14959 :   GEN x = cgetg(2, t_SER);
     340       14959 :   x[1] = evalvalp(e) | evalvarn(v); return x;
     341             : }
     342             : INLINE int
     343     3702019 : ser_isexactzero(GEN x)
     344             : {
     345     3702019 :   if (!signe(x)) switch(lg(x))
     346             :   {
     347       13230 :     case 2: return 1;
     348         840 :     case 3: return isexactzero(gel(x,2));
     349             :   }
     350     3687949 :   return 0;
     351             : }
     352             : /* 0 * pol_x(v) */
     353             : INLINE GEN
     354     7064698 : zeropol(long v) { return pol_0(v); }
     355             : /* vector(n) */
     356             : INLINE GEN
     357    23679328 : zerocol(long n)
     358             : {
     359    23679328 :   GEN y = cgetg(n+1,t_COL);
     360    23679328 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     361    23679328 :   return y;
     362             : }
     363             : /* vectorv(n) */
     364             : INLINE GEN
     365    18169806 : zerovec(long n)
     366             : {
     367    18169806 :   GEN y = cgetg(n+1,t_VEC);
     368    18169806 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     369    18169806 :   return y;
     370             : }
     371             : /* matrix(m, n) */
     372             : INLINE GEN
     373       15470 : zeromat(long m, long n)
     374             : {
     375       15470 :   GEN y = cgetg(n+1,t_MAT);
     376       15470 :   GEN v = zerocol(m);
     377       15470 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     378       15470 :   return y;
     379             : }
     380             : /* = zero_zx, sv is a evalvarn()*/
     381             : INLINE GEN
     382      798909 : zero_Flx(long sv) { return pol0_Flx(sv); }
     383             : INLINE GEN
     384    32052929 : zero_Flv(long n)
     385             : {
     386    32052929 :   GEN y = cgetg(n+1,t_VECSMALL);
     387    32053175 :   long i; for (i=1; i<=n; i++) y[i] = 0;
     388    32053175 :   return y;
     389             : }
     390             : /* matrix(m, n) */
     391             : INLINE GEN
     392      890800 : zero_Flm(long m, long n)
     393             : {
     394      890800 :   GEN y = cgetg(n+1,t_MAT);
     395      890800 :   GEN v = zero_Flv(m);
     396      890800 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     397      890800 :   return y;
     398             : }
     399             : /* matrix(m, n) */
     400             : INLINE GEN
     401       93242 : zero_Flm_copy(long m, long n)
     402             : {
     403       93242 :   GEN y = cgetg(n+1,t_MAT);
     404       93239 :   long i; for (i=1; i<=n; i++) gel(y,i) = zero_Flv(m);
     405       93242 :   return y;
     406             : }
     407             : 
     408             : INLINE GEN
     409      789149 : zero_F2v(long m)
     410             : {
     411      789149 :   long l = nbits2nlong(m);
     412      789149 :   GEN v  = zero_Flv(l+1);
     413      789149 :   v[1] = m;
     414      789149 :   return v;
     415             : }
     416             : 
     417             : INLINE GEN
     418           0 : zero_F2m(long m, long n)
     419             : {
     420             :   long i;
     421           0 :   GEN M = cgetg(n+1, t_MAT);
     422           0 :   GEN v = zero_F2v(m);
     423           0 :   for (i = 1; i <= n; i++)
     424           0 :     gel(M,i) = v;
     425           0 :   return M;
     426             : }
     427             : 
     428             : 
     429             : INLINE GEN
     430      280015 : zero_F2m_copy(long m, long n)
     431             : {
     432             :   long i;
     433      280015 :   GEN M = cgetg(n+1, t_MAT);
     434      858705 :   for (i = 1; i <= n; i++)
     435      578690 :     gel(M,i)= zero_F2v(m);
     436      280015 :   return M;
     437             : }
     438             : 
     439             : /* matrix(m, n) */
     440             : INLINE GEN
     441     1787013 : zeromatcopy(long m, long n)
     442             : {
     443     1787013 :   GEN y = cgetg(n+1,t_MAT);
     444     1787013 :   long i; for (i=1; i<=n; i++) gel(y,i) = zerocol(m);
     445     1787013 :   return y;
     446             : }
     447             : 
     448             : INLINE GEN
     449       16919 : zerovec_block(long len)
     450             : {
     451             :   long i;
     452       16919 :   GEN blk = cgetg_block(len + 1, t_VEC);
     453      558327 :   for (i = 1; i <= len; ++i)
     454      541408 :     gel(blk, i) = gen_0;
     455       16919 :   return blk;
     456             : }
     457             : 
     458             : /* i-th vector in the standard basis */
     459             : INLINE GEN
     460     1388919 : col_ei(long n, long i) { GEN e = zerocol(n); gel(e,i) = gen_1; return e; }
     461             : INLINE GEN
     462      308540 : vec_ei(long n, long i) { GEN e = zerovec(n); gel(e,i) = gen_1; return e; }
     463             : INLINE GEN
     464           7 : F2v_ei(long n, long i) { GEN e = zero_F2v(n); F2v_set(e,i); return e; }
     465             : INLINE GEN
     466       69271 : vecsmall_ei(long n, long i) { GEN e = zero_zv(n); e[i] = 1; return e; }
     467             : INLINE GEN
     468     1168038 : Rg_col_ei(GEN x, long n, long i) { GEN e = zerocol(n); gel(e,i) = x; return e; }
     469             : 
     470             : INLINE GEN
     471     2637472 : shallowcopy(GEN x)
     472     2637472 : { return typ(x) == t_MAT ? RgM_shallowcopy(x): leafcopy(x); }
     473             : 
     474             : /* routines for naive growarrays */
     475             : INLINE GEN
     476    12707545 : vectrunc_init(long l)
     477             : {
     478    12707545 :   GEN z = new_chunk(l);
     479    12707937 :   z[0] = evaltyp(t_VEC) | _evallg(1); return z;
     480             : }
     481             : INLINE void
     482   507085710 : lg_increase(GEN x) { x[0]++; }
     483             : INLINE void
     484    49275809 : vectrunc_append(GEN x, GEN t) { gel(x, lg(x)) = t; lg_increase(x); }
     485             : INLINE void
     486           0 : vectrunc_append_batch(GEN x, GEN y)
     487             : {
     488           0 :   long i, l = lg(x), ly = lg(y);
     489           0 :   GEN z = x + l-1;
     490           0 :   for (i = 1; i < ly; i++) gel(z,i) = gel(y,i);
     491           0 :   setlg(x, l+ly-1);
     492           0 : }
     493             : INLINE GEN
     494   168349482 : vecsmalltrunc_init(long l)
     495             : {
     496   168349482 :   GEN z = new_chunk(l);
     497   168349482 :   z[0] = evaltyp(t_VECSMALL) | _evallg(1); return z;
     498             : }
     499             : INLINE void
     500    25859876 : vecsmalltrunc_append(GEN x, long t) { x[ lg(x) ] = t; lg_increase(x); }
     501             : 
     502             : /*******************************************************************/
     503             : /*                                                                 */
     504             : /*                        VEC / COL / VECSMALL                     */
     505             : /*                                                                 */
     506             : /*******************************************************************/
     507             : /* shallow*/
     508             : INLINE GEN
     509           0 : vec_shorten(GEN v, long n)
     510             : {
     511             :   long i;
     512           0 :   GEN V = cgetg(n+1,t_VEC);
     513           0 :   for(i=1;i<=n;i++) gel(V,i) = gel(v,i);
     514           0 :   return V;
     515             : }
     516             : /* shallow*/
     517             : INLINE GEN
     518       10906 : vec_lengthen(GEN v, long n)
     519             : {
     520             :   long i;
     521       10906 :   long l=lg(v);
     522       10906 :   GEN V = cgetg(n+1,t_VEC);
     523       10906 :   for(i=1;i<l;i++) gel(V,i) = gel(v,i);
     524       10906 :   return V;
     525             : }
     526             : /* shallow*/
     527             : INLINE GEN
     528       59332 : vec_append(GEN V, GEN s)
     529             : {
     530       59332 :   long i, l2 = lg(V);
     531       59332 :   GEN res = cgetg(l2+1, typ(V));
     532       59332 :   for (i = 1; i < l2; ++i) gel(res, i) = gel(V,i);
     533       59332 :   gel(res,l2) = s; return res;
     534             : }
     535             : /* shallow*/
     536             : INLINE GEN
     537           0 : vec_setconst(GEN v, GEN x)
     538             : {
     539           0 :   long i, l = lg(v);
     540           0 :   for (i = 1; i < l; i++) gel(v,i) = x;
     541           0 :   return v;
     542             : }
     543             : INLINE GEN
     544      178028 : vecsmall_shorten(GEN v, long n)
     545             : {
     546             :   long i;
     547      178028 :   GEN V = cgetg(n+1,t_VECSMALL);
     548      178029 :   for(i=1;i<=n;i++) V[i] = v[i];
     549      178029 :   return V;
     550             : }
     551             : INLINE GEN
     552          21 : vecsmall_lengthen(GEN v, long n)
     553             : {
     554          21 :   long i, l = lg(v);
     555          21 :   GEN V = cgetg(n+1,t_VECSMALL);
     556          21 :   for(i=1;i<l;i++) V[i] = v[i];
     557          21 :   return V;
     558             : }
     559             : 
     560             : INLINE GEN
     561      410016 : vec_to_vecsmall(GEN z)
     562             : {
     563      410016 :   long i, l = lg(z);
     564      410016 :   GEN x = cgetg(l, t_VECSMALL);
     565      410016 :   for (i=1; i<l; i++) x[i] = itos(gel(z,i));
     566      410016 :   return x;
     567             : }
     568             : INLINE GEN
     569       71218 : vecsmall_to_vec(GEN z)
     570             : {
     571       71218 :   long i, l = lg(z);
     572       71218 :   GEN x = cgetg(l,t_VEC);
     573       71218 :   for (i=1; i<l; i++) gel(x,i) = stoi(z[i]);
     574       71218 :   return x;
     575             : }
     576             : INLINE GEN
     577         938 : vecsmall_to_vec_inplace(GEN z)
     578             : {
     579         938 :   long i, l = lg(z);
     580         938 :   for (i=1; i<l; i++) gel(z,i) = stoi(z[i]);
     581         938 :   settyp(z, t_VEC); return z;
     582             : }
     583             : INLINE GEN
     584     1302413 : vecsmall_to_col(GEN z)
     585             : {
     586     1302413 :   long i, l = lg(z);
     587     1302413 :   GEN x = cgetg(l,t_COL);
     588     1302413 :   for (i=1; i<l; i++) gel(x,i) = stoi(z[i]);
     589     1302413 :   return x;
     590             : }
     591             : 
     592             : INLINE int
     593     9456367 : vecsmall_lexcmp(GEN x, GEN y)
     594             : {
     595             :   long lx,ly,l,i;
     596     9456367 :   lx = lg(x);
     597     9456367 :   ly = lg(y); l = minss(lx,ly);
     598    56689298 :   for (i=1; i<l; i++)
     599    54634366 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     600     2054932 :   if (lx == ly) return 0;
     601          14 :   return (lx < ly)? -1 : 1;
     602             : }
     603             : 
     604             : INLINE int
     605    47066978 : vecsmall_prefixcmp(GEN x, GEN y)
     606             : {
     607    47066978 :   long i, lx = lg(x), ly = lg(y), l = minss(lx,ly);
     608   148811348 :   for (i=1; i<l; i++)
     609   134951817 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     610    13859531 :   return 0;
     611             : }
     612             : 
     613             : /*Can be used on t_VEC, but coeffs not gcopy-ed*/
     614             : INLINE GEN
     615       12663 : vecsmall_prepend(GEN V, long s)
     616             : {
     617       12663 :   long i, l2 = lg(V);
     618       12663 :   GEN res = cgetg(l2+1, typ(V));
     619       12663 :   res[1] = s;
     620       12663 :   for (i = 2; i <= l2; ++i) res[i] = V[i - 1];
     621       12663 :   return res;
     622             : }
     623             : 
     624             : INLINE GEN
     625     3765602 : vecsmall_append(GEN V, long s)
     626             : {
     627     3765602 :   long i, l2 = lg(V);
     628     3765602 :   GEN res = cgetg(l2+1, t_VECSMALL);
     629     3765602 :   for (i = 1; i < l2; ++i) res[i] = V[i];
     630     3765602 :   res[l2] = s; return res;
     631             : }
     632             : 
     633             : INLINE GEN
     634      784810 : vecsmall_concat(GEN u, GEN v)
     635             : {
     636      784810 :   long i, l1 = lg(u)-1, l2 = lg(v)-1;
     637      784810 :   GEN res = cgetg(l1+l2+1, t_VECSMALL);
     638      784810 :   for (i = 1; i <= l1; ++i) res[i]    = u[i];
     639      784810 :   for (i = 1; i <= l2; ++i) res[i+l1] = v[i];
     640      784810 :   return res;
     641             : }
     642             : 
     643             : /* return the number of indices where u and v are equal */
     644             : INLINE long
     645           0 : vecsmall_coincidence(GEN u, GEN v)
     646             : {
     647           0 :   long i, s = 0, l = minss(lg(u),lg(v));
     648           0 :   for(i=1; i<l; i++)
     649           0 :     if(u[i] == v[i]) s++;
     650           0 :   return s;
     651             : }
     652             : 
     653             : /* returns the first index i<=n such that x=v[i] if it exists, 0 otherwise */
     654             : INLINE long
     655           0 : vecsmall_isin(GEN v, long x)
     656             : {
     657           0 :   long i, l = lg(v);
     658           0 :   for (i = 1; i < l; i++)
     659           0 :     if (v[i] == x) return i;
     660           0 :   return 0;
     661             : }
     662             : 
     663             : INLINE long
     664          84 : vecsmall_pack(GEN V, long base, long mod)
     665             : {
     666          84 :   long i, s = 0;
     667          84 :   for(i=1; i<lg(V); i++) s = (base*s + V[i]) % mod;
     668          84 :   return s;
     669             : }
     670             : 
     671             : INLINE long
     672          14 : vecsmall_indexmax(GEN x)
     673             : {
     674          14 :   long i, i0 = 1, t = x[1], lx = lg(x);
     675          56 :   for (i=2; i<lx; i++)
     676          42 :     if (x[i] > t) t = x[i0=i];
     677          14 :   return i0;
     678             : }
     679             : 
     680             : INLINE long
     681       42799 : vecsmall_max(GEN x)
     682             : {
     683       42799 :   long i, t = x[1], lx = lg(x);
     684       78161 :   for (i=2; i<lx; i++)
     685       35362 :     if (x[i] > t) t = x[i];
     686       42799 :   return t;
     687             : }
     688             : 
     689             : INLINE long
     690          14 : vecsmall_indexmin(GEN x)
     691             : {
     692          14 :   long i, i0 = 1, t = x[1], lx =lg(x);
     693          56 :   for (i=2; i<lx; i++)
     694          42 :     if (x[i] < t) t = x[i0=i];
     695          14 :   return i0;
     696             : }
     697             : 
     698             : INLINE long
     699           0 : vecsmall_min(GEN x)
     700             : {
     701           0 :   long i, t = x[1], lx =lg(x);
     702           0 :   for (i=2; i<lx; i++)
     703           0 :     if (x[i] < t) t = x[i];
     704           0 :   return t;
     705             : }
     706             : 
     707             : INLINE int
     708     2127333 : ZV_isscalar(GEN x)
     709             : {
     710     2127333 :   long l = lg(x);
     711     7488398 :   while (--l > 1)
     712     4981062 :     if (signe(gel(x, l))) return 0;
     713      380003 :   return 1;
     714             : }
     715             : INLINE int
     716    17397561 : QV_isscalar(GEN x)
     717             : {
     718    17397561 :   long lx = lg(x),i;
     719    18863123 :   for (i=2; i<lx; i++)
     720    18336333 :     if (!isintzero(gel(x, i))) return 0;
     721      526790 :   return 1;
     722             : }
     723             : INLINE int
     724        3864 : RgV_isscalar(GEN x)
     725             : {
     726        3864 :   long lx = lg(x),i;
     727        7343 :   for (i=2; i<lx; i++)
     728        6244 :     if (!gequal0(gel(x, i))) return 0;
     729        1099 :   return 1;
     730             : }
     731             : INLINE int
     732           0 : RgX_isscalar(GEN x)
     733             : {
     734             :   long i;
     735           0 :   for (i=lg(x)-1; i>2; i--)
     736           0 :     if (!gequal0(gel(x, i))) return 0;
     737           0 :   return 1;
     738             : }
     739             : INLINE long
     740    25588414 : RgX_equal_var(GEN x, GEN y) { return varn(x) == varn(y) && RgX_equal(x,y); }
     741             : 
     742             : INLINE int
     743        3886 : RgX_is_rational(GEN x)
     744             : {
     745             :   long i;
     746       20097 :   for (i = lg(x)-1; i > 1; i--)
     747       18836 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     748        1261 :   return 1;
     749             : }
     750             : INLINE int
     751    64413290 : RgX_is_ZX(GEN x)
     752             : {
     753             :   long i;
     754   277135961 :   for (i = lg(x)-1; i > 1; i--)
     755   218261609 :     if (typ(gel(x,i)) != t_INT) return 0;
     756    58874352 :   return 1;
     757             : }
     758             : INLINE int
     759      116447 : RgX_is_QX(GEN x)
     760             : {
     761      116447 :   long k = lg(x)-1;
     762      437754 :   for ( ; k>1; k--)
     763      323008 :     if (!is_rational_t(typ(gel(x,k)))) return 0;
     764      114746 :   return 1;
     765             : }
     766             : INLINE int
     767    15307692 : RgX_is_monomial(GEN x)
     768             : {
     769             :   long i;
     770    15307692 :   if (!signe(x)) return 0;
     771    25389647 :   for (i=lg(x)-2; i>1; i--)
     772    17486448 :     if (!isexactzero(gel(x,i))) return 0;
     773     7903199 :   return 1;
     774             : }
     775             : INLINE int
     776    18293780 : RgV_is_ZV(GEN x)
     777             : {
     778             :   long i;
     779    74712063 :   for (i = lg(x)-1; i > 0; i--)
     780    56419347 :     if (typ(gel(x,i)) != t_INT) return 0;
     781    18292716 :   return 1;
     782             : }
     783             : INLINE int
     784        4200 : RgV_is_QV(GEN x)
     785             : {
     786             :   long i;
     787       96334 :   for (i = lg(x)-1; i > 0; i--)
     788       94759 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     789        1575 :   return 1;
     790             : }
     791             : 
     792             : /********************************************************************/
     793             : /**                                                                **/
     794             : /**            Dynamic arrays implementation                       **/
     795             : /**                                                                **/
     796             : /********************************************************************/
     797             : INLINE void **
     798   406271732 : pari_stack_base(pari_stack *s) { return s->data; }
     799             : 
     800             : INLINE void
     801      467026 : pari_stack_init(pari_stack *s, size_t size, void **data)
     802             : {
     803      467026 :   s->data = data;
     804      467026 :   *data = NULL;
     805      467026 :   s->n = 0;
     806      467026 :   s->alloc = 0;
     807      467026 :   s->size = size;
     808      467026 : }
     809             : 
     810             : INLINE void
     811   405771150 : pari_stack_alloc(pari_stack *s, long nb)
     812             : {
     813   405771150 :   void **sdat = pari_stack_base(s);
     814   405941962 :   long alloc = s->alloc;
     815   811885093 :   if (s->n+nb <= alloc) return;
     816      226455 :   if (!alloc)
     817      178412 :     alloc = nb;
     818             :   else
     819             :   {
     820       48043 :     while (s->n+nb > alloc) alloc <<= 1;
     821             :   }
     822      226455 :   *sdat = pari_realloc(*sdat,alloc*s->size);
     823      227624 :   s->alloc = alloc;
     824             : }
     825             : 
     826             : INLINE long
     827   338261517 : pari_stack_new(pari_stack *s) { pari_stack_alloc(s, 1); return s->n++; }
     828             : 
     829             : INLINE void
     830      402659 : pari_stack_delete(pari_stack *s)
     831             : {
     832      402659 :   void **sdat = pari_stack_base(s);
     833      402457 :   if (*sdat) pari_free(*sdat);
     834      402667 : }
     835             : 
     836             : INLINE void
     837        4649 : pari_stack_pushp(pari_stack *s, void *u)
     838             : {
     839        4649 :   long n = pari_stack_new(s);
     840        4649 :   void **sdat =(void**) *pari_stack_base(s);
     841        4649 :   sdat[n] = u;
     842        4649 : }
     843             : 
     844             : /*******************************************************************/
     845             : /*                                                                 */
     846             : /*                            EXTRACT                              */
     847             : /*                                                                 */
     848             : /*******************************************************************/
     849             : INLINE GEN
     850   202557584 : vecslice(GEN A, long y1, long y2)
     851             : {
     852   202557584 :   long i,lB = y2 - y1 + 2;
     853   202557584 :   GEN B = cgetg(lB, typ(A));
     854   202557584 :   for (i=1; i<lB; i++) B[i] = A[y1-1+i];
     855   202557584 :   return B;
     856             : }
     857             : INLINE GEN
     858      738136 : vecslicepermute(GEN A, GEN p, long y1, long y2)
     859             : {
     860      738136 :   long i,lB = y2 - y1 + 2;
     861      738136 :   GEN B = cgetg(lB, typ(A));
     862      738136 :   for (i=1; i<lB; i++) B[i] = A[p[y1-1+i]];
     863      738136 :   return B;
     864             : }
     865             : /* rowslice(rowpermute(A,p), x1, x2) */
     866             : INLINE GEN
     867       34472 : rowslicepermute(GEN A, GEN p, long x1, long x2)
     868             : {
     869       34472 :   long i, lB = lg(A);
     870       34472 :   GEN B = cgetg(lB, typ(A));
     871       34472 :   for (i=1; i<lB; i++) gel(B,i) = vecslicepermute(gel(A,i),p,x1,x2);
     872       34472 :   return B;
     873             : }
     874             : INLINE GEN
     875    20368958 : rowslice(GEN A, long x1, long x2)
     876             : {
     877    20368958 :   long i, lB = lg(A);
     878    20368958 :   GEN B = cgetg(lB, typ(A));
     879    20368958 :   for (i=1; i<lB; i++) gel(B,i) = vecslice(gel(A,i),x1,x2);
     880    20368958 :   return B;
     881             : }
     882             : 
     883             : INLINE GEN
     884      212458 : matslice(GEN A, long x1, long x2, long y1, long y2)
     885             : {
     886      212458 :   return rowslice(vecslice(A, y1, y2), x1, x2);
     887             : }
     888             : 
     889             : /* shallow, remove coeff of index j */
     890             : INLINE GEN
     891         133 : rowsplice(GEN a, long j)
     892             : {
     893             :   long i, l;
     894         133 :   GEN b = cgetg_copy(a,&l);
     895         133 :   for (i = 1; i < l; i++) gel(b,i) = vecsplice(gel(a,i), j);
     896         133 :   return b;
     897             : }
     898             : /* shallow, remove coeff of index j */
     899             : INLINE GEN
     900       45164 : vecsplice(GEN a, long j)
     901             : {
     902       45164 :   long i, k, l = lg(a);
     903             :   GEN b;
     904       45164 :   if (l == 1) pari_err(e_MISC, "incorrect component in vecsplice");
     905       45164 :   b = cgetg(l-1, typ(a));
     906      190323 :   for (i = k = 1; i < l; i++)
     907      145159 :     if (i != j) gel(b, k++) = gel(a,i);
     908       45164 :   return b;
     909             : }
     910             : /* shallow */
     911             : INLINE GEN
     912         756 : RgM_minor(GEN a, long i, long j)
     913             : {
     914         756 :   GEN b = vecsplice(a, j);
     915         756 :   long k, l = lg(b);
     916         756 :   for (k = 1; k < l; k++) gel(b,k) = vecsplice(gel(b,k), i);
     917         756 :   return b;
     918             : }
     919             : 
     920             : /* A[x0,] */
     921             : INLINE GEN
     922      178650 : row(GEN A, long x0)
     923             : {
     924      178650 :   long i, lB = lg(A);
     925      178650 :   GEN B  = cgetg(lB, t_VEC);
     926      178650 :   for (i=1; i<lB; i++) gel(B, i) = gcoeff(A, x0, i);
     927      178650 :   return B;
     928             : }
     929             : INLINE GEN
     930     4531535 : Flm_row(GEN A, long x0)
     931             : {
     932     4531535 :   long i, lB = lg(A);
     933     4531535 :   GEN B  = cgetg(lB, t_VECSMALL);
     934     4531540 :   for (i=1; i<lB; i++) B[i] = coeff(A, x0, i);
     935     4531540 :   return B;
     936             : }
     937             : /* A[x0,] */
     938             : INLINE GEN
     939          56 : rowcopy(GEN A, long x0)
     940             : {
     941          56 :   long i, lB = lg(A);
     942          56 :   GEN B  = cgetg(lB, t_VEC);
     943          56 :   for (i=1; i<lB; i++) gel(B, i) = gcopy(gcoeff(A, x0, i));
     944          56 :   return B;
     945             : }
     946             : /* A[x0, x1..x2] */
     947             : INLINE GEN
     948        2177 : row_i(GEN A, long x0, long x1, long x2)
     949             : {
     950        2177 :   long i, lB = x2 - x1 + 2;
     951        2177 :   GEN B  = cgetg(lB, t_VEC);
     952        2177 :   for (i=x1; i<=x2; i++) gel(B, i) = gcoeff(A, x0, i);
     953        2177 :   return B;
     954             : }
     955             : 
     956             : INLINE GEN
     957     5491522 : vecreverse(GEN A)
     958             : {
     959             :   long i, l;
     960     5491522 :   GEN B = cgetg_copy(A, &l);
     961     5491522 :   for (i=1; i<l; i++) gel(B, i) = gel(A, l-i);
     962     5491522 :   return B;
     963             : }
     964             : 
     965             : INLINE GEN
     966         252 : vecsmall_reverse(GEN A)
     967             : {
     968             :   long i, l;
     969         252 :   GEN B = cgetg_copy(A, &l);
     970         252 :   for (i=1; i<l; i++) B[i] = A[l-i];
     971         252 :   return B;
     972             : }
     973             : 
     974             : INLINE void
     975         232 : vecreverse_inplace(GEN y)
     976             : {
     977         232 :   long ly = lg(y), lim = ly>>1, i;
     978         640 :   for (i = 1; i <= lim; i++)
     979             :   {
     980         408 :     GEN z = gel(y,i);
     981         408 :     gel(y,i)    = gel(y,ly-i);
     982         408 :     gel(y,ly-i) = z;
     983             :   }
     984         232 : }
     985             : 
     986             : INLINE GEN
     987    45223254 : vecsmallpermute(GEN A, GEN p) { return perm_mul(A, p); }
     988             : 
     989             : INLINE GEN
     990     5421882 : vecpermute(GEN A, GEN p)
     991             : {
     992     5421882 :   long i,lB = lg(p);
     993     5421882 :   GEN B = cgetg(lB, typ(A));
     994     5421882 :   for (i=1; i<lB; i++) gel(B, i) = gel(A, p[i]);
     995     5421882 :   return B;
     996             : }
     997             : INLINE GEN
     998     2880174 : rowpermute(GEN A, GEN p)
     999             : {
    1000     2880174 :   long i, lB = lg(A);
    1001     2880174 :   GEN B = cgetg(lB, typ(A));
    1002    28927671 :   for (i=1; i<lB; i++)
    1003    27519341 :     gel(B, i) = typ(gel(A,i)) == t_VECSMALL ? vecsmallpermute(gel(A, i), p):
    1004     1471844 :                                                     vecpermute(gel(A, i), p);
    1005     2880174 :   return B;
    1006             : }
    1007             : /*******************************************************************/
    1008             : /*                                                                 */
    1009             : /*                          PERMUTATIONS                           */
    1010             : /*                                                                 */
    1011             : /*******************************************************************/
    1012             : /* identity permutation */
    1013             : INLINE GEN
    1014      611193 : identity_perm(long n)
    1015             : {
    1016      611193 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1017             :   long i;
    1018      611193 :   for (i = 1; i <= n; i++) perm[i] = i;
    1019      611193 :   return perm;
    1020             : }
    1021             : 
    1022             : /* assume d <= n */
    1023             : INLINE GEN
    1024           0 : cyclic_perm(long n, long d)
    1025             : {
    1026           0 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1027             :   long i;
    1028           0 :   for (i = 1; i <= n-d; i++) perm[i] = i+d;
    1029           0 :   for (     ; i <= n;   i++) perm[i] = i-n+d;
    1030           0 :   return perm;
    1031             : }
    1032             : 
    1033             : /* Multiply (compose) two permutations */
    1034             : INLINE GEN
    1035    46860550 : perm_mul(GEN s, GEN t)
    1036             : {
    1037             :   GEN u;
    1038    46860550 :   long i, l = lg(t);
    1039    46860550 :   u = cgetg(l, t_VECSMALL);
    1040    46860550 :   for (i = 1; i < l; i++) u[i] = s[ t[i] ];
    1041    46860550 :   return u;
    1042             : }
    1043             : /* Compute the inverse (reciprocal) of a permutation. */
    1044             : INLINE GEN
    1045      604063 : perm_inv(GEN x)
    1046             : {
    1047             :   long i, lx;
    1048      604063 :   GEN y = cgetg_copy(x, &lx);
    1049      604063 :   for (i=1; i<lx; i++) y[ x[i] ] = i;
    1050      604063 :   return y;
    1051             : }
    1052             : /* Return s*t*s^-1 */
    1053             : INLINE GEN
    1054      506639 : perm_conj(GEN s, GEN t)
    1055             : {
    1056             :   long i, l;
    1057      506639 :   GEN v = cgetg_copy(s, &l);
    1058      506639 :   for (i = 1; i < l; i++) v[ s[i] ] = s[ t[i] ];
    1059      506639 :   return v;
    1060             : }
    1061             : 
    1062             : /*********************************************************************/
    1063             : /*                       MALLOC/FREE WRAPPERS                        */
    1064             : /*********************************************************************/
    1065             : #define BLOCK_SIGALRM_START          \
    1066             : {                                    \
    1067             :   int block=PARI_SIGINT_block;       \
    1068             :   PARI_SIGINT_block = 2;             \
    1069             :   MT_SIGINT_BLOCK(block);
    1070             : 
    1071             : #define BLOCK_SIGINT_START           \
    1072             : {                                    \
    1073             :   int block=PARI_SIGINT_block;       \
    1074             :   PARI_SIGINT_block = 1;             \
    1075             :   MT_SIGINT_BLOCK(block);
    1076             : 
    1077             : #define BLOCK_SIGINT_END             \
    1078             :   PARI_SIGINT_block = block;         \
    1079             :   MT_SIGINT_UNBLOCK(block);          \
    1080             :   if (!block && PARI_SIGINT_pending) \
    1081             :   {                                  \
    1082             :     int sig = PARI_SIGINT_pending;   \
    1083             :     PARI_SIGINT_pending = 0;         \
    1084             :     raise(sig);                      \
    1085             :   }                                  \
    1086             : }
    1087             : 
    1088             : INLINE void
    1089    50501832 : pari_free(void *pointer)
    1090             : {
    1091    50501832 :   BLOCK_SIGINT_START;
    1092    50502625 :   free(pointer);
    1093    50502625 :   BLOCK_SIGINT_END;
    1094    50502352 : }
    1095             : INLINE void*
    1096   230869474 : pari_malloc(size_t size)
    1097             : {
    1098   230869474 :   if (size)
    1099             :   {
    1100             :     char *tmp;
    1101   230869474 :     BLOCK_SIGINT_START;
    1102   230870948 :     tmp = (char*)malloc(size);
    1103   230870948 :     BLOCK_SIGINT_END;
    1104   230870887 :     if (!tmp) pari_err(e_MEM);
    1105   230870887 :     return tmp;
    1106             :   }
    1107           0 :   if (DEBUGMEM) pari_warn(warner,"mallocing NULL object");
    1108           0 :   return NULL;
    1109             : }
    1110             : INLINE void*
    1111      238217 : pari_realloc(void *pointer, size_t size)
    1112             : {
    1113             :   char *tmp;
    1114             : 
    1115      238217 :   BLOCK_SIGINT_START;
    1116      240019 :   if (!pointer) tmp = (char *) malloc(size);
    1117       51641 :   else tmp = (char *) realloc(pointer,size);
    1118      240019 :   BLOCK_SIGINT_END;
    1119      239307 :   if (!tmp) pari_err(e_MEM);
    1120      239307 :   return tmp;
    1121             : }
    1122             : INLINE void*
    1123       32106 : pari_calloc(size_t size)
    1124             : {
    1125       32106 :   void *t = pari_malloc(size);
    1126       32106 :   memset(t, 0, size); return t;
    1127             : }
    1128             : INLINE GEN
    1129        4186 : cgetalloc(long t, size_t l)
    1130             : {
    1131        4186 :   GEN x = (GEN)pari_malloc(l * sizeof(long));
    1132        4186 :   x[0] = evaltyp(t) | evallg(l); return x;
    1133             : }
    1134             : 
    1135             : /*******************************************************************/
    1136             : /*                                                                 */
    1137             : /*                       GARBAGE COLLECTION                        */
    1138             : /*                                                                 */
    1139             : /*******************************************************************/
    1140             : /* copy integer x as if we had avma = av */
    1141             : INLINE GEN
    1142  3526643158 : icopy_avma(GEN x, pari_sp av)
    1143             : {
    1144  3526643158 :   long i = lgefint(x), lx = i;
    1145  3526643158 :   GEN y = ((GEN)av) - i;
    1146  3526643158 :   while (--i > 0) y[i] = x[i];
    1147  3526643158 :   y[0] = evaltyp(t_INT)|evallg(lx);
    1148  3526484848 :   return y;
    1149             : }
    1150             : /* copy leaf x as if we had avma = av */
    1151             : INLINE GEN
    1152   154412004 : leafcopy_avma(GEN x, pari_sp av)
    1153             : {
    1154   154412004 :   long i = lg(x);
    1155   154412004 :   GEN y = ((GEN)av) - i;
    1156   154412004 :   while (--i > 0) y[i] = x[i];
    1157   154412004 :   y[0] = x[0] & (~CLONEBIT);
    1158   154412004 :   return y;
    1159             : }
    1160             : INLINE GEN
    1161   563951679 : gerepileuptoleaf(pari_sp av, GEN x)
    1162             : {
    1163             :   long lx;
    1164             :   GEN q;
    1165             : 
    1166   563951679 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1167   564953756 :   lx = lg(x);
    1168   564953756 :   q = ((GEN)av) - lx;
    1169   564953756 :   avma = (pari_sp)q;
    1170   564953756 :   while (--lx >= 0) q[lx] = x[lx];
    1171   564953756 :   return q;
    1172             : }
    1173             : INLINE GEN
    1174  1139526395 : gerepileuptoint(pari_sp av, GEN x)
    1175             : {
    1176  1139526395 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1177  1005156901 :   avma = (pari_sp)icopy_avma(x, av);
    1178  1005806843 :   return (GEN)avma;
    1179             : }
    1180             : INLINE GEN
    1181   778619853 : gerepileupto(pari_sp av, GEN x)
    1182             : {
    1183   778619853 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1184   683684324 :   switch(typ(x))
    1185             :   { /* non-default = !is_recursive_t(tq) */
    1186   253593944 :     case t_INT: return gerepileuptoint(av, x);
    1187             :     case t_REAL:
    1188             :     case t_STR:
    1189   113772738 :     case t_VECSMALL: return gerepileuptoleaf(av,x);
    1190             :     default:
    1191             :       /* NB: x+i --> ((long)x) + i*sizeof(long) */
    1192   316317642 :       return gerepile(av, (pari_sp) (x+lg(x)), x);
    1193             :   }
    1194             : }
    1195             : 
    1196             : /* gerepileupto(av, gcopy(x)) */
    1197             : INLINE GEN
    1198    38811737 : gerepilecopy(pari_sp av, GEN x)
    1199             : {
    1200    38811737 :   if (is_recursive_t(typ(x)))
    1201             :   {
    1202    31286434 :     GENbin *p = copy_bin(x);
    1203    31286441 :     avma = av; return bin_copy(p);
    1204             :   }
    1205             :   else
    1206             :   {
    1207     7525299 :     avma = av;
    1208     7525299 :     if (x < (GEN)av) {
    1209     6108600 :       if (x < (GEN)pari_mainstack->bot) new_chunk(lg(x));
    1210     6108600 :       x = leafcopy_avma(x, av);
    1211     6108611 :       avma = (pari_sp)x;
    1212             :     } else
    1213     1416699 :       x = leafcopy(x);
    1214     7525310 :     return x;
    1215             :   }
    1216             : }
    1217             : 
    1218             : /* Takes an array of pointers to GENs, of length n. Copies all
    1219             :  * objects to contiguous locations and cleans up the stack between
    1220             :  * av and avma. */
    1221             : INLINE void
    1222      136899 : gerepilemany(pari_sp av, GEN* gptr[], int n)
    1223             : {
    1224             :   int i;
    1225      136899 :   for (i=0; i<n; i++) *gptr[i] = (GEN)copy_bin(*gptr[i]);
    1226      136899 :   avma = av;
    1227      136899 :   for (i=0; i<n; i++) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1228      136899 : }
    1229             : 
    1230             : INLINE void
    1231     5188649 : gerepileall(pari_sp av, int n, ...)
    1232             : {
    1233             :   int i;
    1234     5188649 :   va_list a; va_start(a, n);
    1235     5188649 :   if (n < 10)
    1236             :   {
    1237             :     GEN *gptr[10];
    1238    15823707 :     for (i=0; i<n; i++)
    1239    10635084 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1240     5188623 :     avma = av;
    1241     5188623 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1242             : 
    1243             :   }
    1244             :   else
    1245             :   {
    1246           0 :     GEN **gptr = (GEN**)  pari_malloc(n*sizeof(GEN*));
    1247           0 :     for (i=0; i<n; i++)
    1248           0 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1249           0 :     avma = av;
    1250           0 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1251           0 :     pari_free(gptr);
    1252             :   }
    1253     5188653 :   va_end(a);
    1254     5188653 : }
    1255             : 
    1256             : INLINE void
    1257           8 : gerepilecoeffs(pari_sp av, GEN x, int n)
    1258             : {
    1259             :   int i;
    1260           8 :   for (i=0; i<n; i++) gel(x,i) = (GEN)copy_bin(gel(x,i));
    1261           8 :   avma = av;
    1262           8 :   for (i=0; i<n; i++) gel(x,i) = bin_copy((GENbin*)x[i]);
    1263           8 : }
    1264             : 
    1265             : /* p from copy_bin. Copy p->x back to stack, then destroy p */
    1266             : INLINE GEN
    1267    42329090 : bin_copy(GENbin *p)
    1268             : {
    1269             :   GEN x, y, base;
    1270             :   long dx, len;
    1271             : 
    1272    42329090 :   x   = p->x; if (!x) { pari_free(p); return gen_0; }
    1273    42322264 :   len = p->len;
    1274    42322264 :   base= p->base; dx = x - base;
    1275    42322264 :   y = (GEN)memcpy((void*)new_chunk(len), (void*)GENbinbase(p), len*sizeof(long));
    1276    42322247 :   y += dx;
    1277    42322247 :   p->rebase(y, ((ulong)y-(ulong)x));
    1278    42322249 :   pari_free(p); return y;
    1279             : }
    1280             : 
    1281             : INLINE GEN
    1282    84651406 : GENbinbase(GENbin *p) { return (GEN)(p + 1); }
    1283             : 
    1284             : INLINE void
    1285    26695428 : cgiv(GEN x)
    1286             : {
    1287    26695428 :   pari_sp av = (pari_sp)(x+lg(x));
    1288    26695428 :   if (isonstack((GEN)av)) avma = av;
    1289    26695310 : }
    1290             : 
    1291             : INLINE void
    1292     1117889 : killblock(GEN x) { gunclone(x); }
    1293             : 
    1294             : INLINE int
    1295    16953803 : is_universal_constant(GEN x) { return (x >= gen_0 && x <= ghalf); }
    1296             : 
    1297             : /*******************************************************************/
    1298             : /*                                                                 */
    1299             : /*                    CONVERSION / ASSIGNMENT                      */
    1300             : /*                                                                 */
    1301             : /*******************************************************************/
    1302             : /* z is a type which may be a t_COMPLEX component (not a t_QUAD) */
    1303             : INLINE GEN
    1304     2537330 : cxcompotor(GEN z, long prec)
    1305             : {
    1306     2537330 :   switch(typ(z))
    1307             :   {
    1308     1344818 :     case t_INT:  return itor(z, prec);
    1309      134120 :     case t_FRAC: return fractor(z, prec);
    1310     1058392 :     case t_REAL: return rtor(z, prec);
    1311           0 :     default: pari_err_TYPE("cxcompotor",z);
    1312             :              return NULL; /* LCOV_EXCL_LINE */
    1313             :   }
    1314             : }
    1315             : INLINE GEN
    1316     1261313 : cxtofp(GEN x, long prec)
    1317     1261313 : { retmkcomplex(cxcompotor(gel(x,1),prec), cxcompotor(gel(x,2),prec)); }
    1318             : 
    1319             : INLINE double
    1320    16984787 : gtodouble(GEN x)
    1321             : {
    1322    16984787 :   if (typ(x)!=t_REAL) {
    1323     3205977 :     pari_sp av = avma;
    1324     3205977 :     x = gtofp(x, DEFAULTPREC);
    1325     3205977 :     if (typ(x)!=t_REAL) pari_err_TYPE("gtodouble [t_REAL expected]", x);
    1326     3205977 :     avma = av;
    1327             :   }
    1328    16984787 :   return rtodbl(x);
    1329             : }
    1330             : INLINE long
    1331    67160337 : gtos(GEN x) {
    1332    67160337 :   if (typ(x) != t_INT) pari_err_TYPE("gtos [integer expected]",x);
    1333    67160330 :   return itos(x);
    1334             : }
    1335             : 
    1336             : INLINE ulong
    1337      117053 : gtou(GEN x) {
    1338      117053 :   if (typ(x) != t_INT || signe(x)<0)
    1339           0 :     pari_err_TYPE("gtou [integer >=0 expected]",x);
    1340      117622 :   return itou(x);
    1341             : }
    1342             : 
    1343             : INLINE GEN
    1344     1348677 : absfrac(GEN x)
    1345             : {
    1346     1348677 :   GEN y = cgetg(3, t_FRAC);
    1347     1348677 :   gel(y,1) = absi(gel(x,1));
    1348     1348677 :   gel(y,2) = icopy(gel(x,2)); return y;
    1349             : }
    1350             : INLINE GEN
    1351       32378 : absfrac_shallow(GEN x)
    1352       32378 : { return signe(gel(x,1))>0? x: mkfrac(negi(gel(x,1)), gel(x,2)); }
    1353             : INLINE GEN
    1354      487923 : Q_abs(GEN x) { return (typ(x) == t_INT)? absi(x): absfrac(x); }
    1355             : INLINE GEN
    1356      105943 : Q_abs_shallow(GEN x)
    1357      105943 : { return (typ(x) == t_INT)? absi_shallow(x): absfrac_shallow(x); }
    1358             : INLINE GEN
    1359         322 : R_abs_shallow(GEN x)
    1360         322 : { return (typ(x) == t_FRAC)? absfrac_shallow(x): mpabs_shallow(x); }
    1361             : INLINE GEN
    1362           0 : R_abs(GEN x)
    1363           0 : { return (typ(x) == t_FRAC)? absfrac(x): mpabs(x); }
    1364             : 
    1365             : /* Force z to be of type real/complex with floating point components */
    1366             : INLINE GEN
    1367    17772371 : gtofp(GEN z, long prec)
    1368             : {
    1369    17772371 :   switch(typ(z))
    1370             :   {
    1371     8138988 :     case t_INT:  return itor(z, prec);
    1372     4257450 :     case t_FRAC: return fractor(z, prec);
    1373     4298184 :     case t_REAL: return rtor(z, prec);
    1374             :     case t_COMPLEX: {
    1375     1077749 :       GEN a = gel(z,1), b = gel(z,2);
    1376     1077749 :       if (isintzero(b)) return cxcompotor(a, prec);
    1377     1075845 :       if (isintzero(a)) {
    1378        1838 :         GEN y = cgetg(3, t_COMPLEX);
    1379        1838 :         b = cxcompotor(b, prec);
    1380        1838 :         gel(y,1) = real_0_bit(expo(b) - prec2nbits(prec));
    1381        1838 :         gel(y,2) = b; return y;
    1382             :       }
    1383     1074007 :       return cxtofp(z, prec);
    1384             :     }
    1385           0 :     case t_QUAD: return quadtofp(z, prec);
    1386           0 :     default: pari_err_TYPE("gtofp",z);
    1387             :              return NULL; /* LCOV_EXCL_LINE */
    1388             :   }
    1389             : }
    1390             : /* Force z to be of type real / int */
    1391             : INLINE GEN
    1392       22400 : gtomp(GEN z, long prec)
    1393             : {
    1394       22400 :   switch(typ(z))
    1395             :   {
    1396          14 :     case t_INT:  return z;
    1397       22386 :     case t_FRAC: return fractor(z, prec);
    1398           0 :     case t_REAL: return rtor(z, prec);
    1399           0 :     case t_QUAD: z = quadtofp(z, prec);
    1400           0 :                  if (typ(z) == t_REAL) return z;
    1401           0 :     default: pari_err_TYPE("gtomp",z);
    1402             :              return NULL; /* LCOV_EXCL_LINE */
    1403             :   }
    1404             : }
    1405             : 
    1406             : INLINE GEN
    1407      595609 : RgX_gtofp(GEN x, long prec)
    1408             : {
    1409             :   long l;
    1410      595609 :   GEN y = cgetg_copy(x, &l);
    1411      595609 :   while (--l > 1) gel(y,l) = gtofp(gel(x,l), prec);
    1412      595609 :   y[1] = x[1]; return y;
    1413             : }
    1414             : INLINE GEN
    1415      289412 : RgC_gtofp(GEN x, long prec)
    1416             : {
    1417      289412 :   long l = lg(x);
    1418      289412 :   GEN y = cgetg(l, t_COL);
    1419      289412 :   while (--l > 0) gel(y,l) = gtofp(gel(x,l), prec);
    1420      289412 :   return y;
    1421             : }
    1422             : INLINE GEN
    1423          42 : RgV_gtofp(GEN x, long prec)
    1424             : {
    1425          42 :   long l = lg(x);
    1426          42 :   GEN y = cgetg(l, t_VEC);
    1427          42 :   while (--l > 0) gel(y,l) = gtofp(gel(x,l), prec);
    1428          42 :   return y;
    1429             : }
    1430             : INLINE GEN
    1431       19146 : RgM_gtofp(GEN x, long prec)
    1432             : {
    1433             :   long l;
    1434       19146 :   GEN y = cgetg_copy(x, &l);
    1435       19146 :   while (--l > 0) gel(y,l) = RgC_gtofp(gel(x,l), prec);
    1436       19146 :   return y;
    1437             : }
    1438             : INLINE GEN
    1439         560 : RgC_gtomp(GEN x, long prec)
    1440             : {
    1441         560 :   long l = lg(x);
    1442         560 :   GEN y = cgetg(l, t_COL);
    1443         560 :   while (--l > 0) gel(y,l) = gtomp(gel(x,l), prec);
    1444         560 :   return y;
    1445             : }
    1446             : INLINE GEN
    1447          14 : RgM_gtomp(GEN x, long prec)
    1448             : {
    1449             :   long l;
    1450          14 :   GEN y = cgetg_copy(x, &l);
    1451          14 :   while (--l > 0) gel(y,l) = RgC_gtomp(gel(x,l), prec);
    1452          14 :   return y;
    1453             : }
    1454             : 
    1455             : INLINE GEN
    1456        7701 : RgX_fpnorml2(GEN x, long prec)
    1457             : {
    1458        7701 :   pari_sp av = avma;
    1459        7701 :   return gerepileupto(av, gnorml2(RgX_gtofp(x, prec)));
    1460             : }
    1461             : INLINE GEN
    1462      154967 : RgC_fpnorml2(GEN x, long prec)
    1463             : {
    1464      154967 :   pari_sp av = avma;
    1465      154967 :   return gerepileupto(av, gnorml2(RgC_gtofp(x, prec)));
    1466             : }
    1467             : INLINE GEN
    1468        1843 : RgM_fpnorml2(GEN x, long prec)
    1469             : {
    1470        1843 :   pari_sp av = avma;
    1471        1843 :   return gerepileupto(av, gnorml2(RgM_gtofp(x, prec)));
    1472             : }
    1473             : 
    1474             : /* y a t_REAL */
    1475             : INLINE void
    1476      190202 : affgr(GEN x, GEN y)
    1477             : {
    1478             :   pari_sp av;
    1479      190202 :   switch(typ(x)) {
    1480        5992 :     case t_INT:  affir(x,y); break;
    1481      184210 :     case t_REAL: affrr(x,y); break;
    1482           0 :     case t_FRAC: rdiviiz(gel(x,1),gel(x,2), y); break;
    1483           0 :     case t_QUAD: av = avma; affgr(quadtofp(x,realprec(y)), y); avma = av; break;
    1484           0 :     default: pari_err_TYPE2("=",x,y);
    1485             :   }
    1486      190202 : }
    1487             : 
    1488             : INLINE GEN
    1489      186840 : affc_fixlg(GEN x, GEN res)
    1490             : {
    1491      186840 :   if (typ(x) == t_COMPLEX)
    1492             :   {
    1493      175616 :     affrr_fixlg(gel(x,1), gel(res,1));
    1494      175616 :     affrr_fixlg(gel(x,2), gel(res,2));
    1495             :   }
    1496             :   else
    1497             :   {
    1498       11224 :     avma = (pari_sp)(res+3);
    1499       11224 :     res = cgetr(realprec(gel(res,1)));
    1500       11224 :     affrr_fixlg(x, res);
    1501             :   }
    1502      186840 :   return res;
    1503             : }
    1504             : 
    1505             : INLINE GEN
    1506           0 : trunc_safe(GEN x) { long e; return gcvtoi(x,&e); }
    1507             : 
    1508             : /*******************************************************************/
    1509             : /*                                                                 */
    1510             : /*                          LENGTH CONVERSIONS                     */
    1511             : /*                                                                 */
    1512             : /*******************************************************************/
    1513             : INLINE long
    1514       24496 : ndec2nlong(long x) { return 1 + (long)((x)*(LOG2_10/BITS_IN_LONG)); }
    1515             : INLINE long
    1516       24032 : ndec2prec(long x) { return 2 + ndec2nlong(x); }
    1517             : INLINE long
    1518         464 : ndec2nbits(long x) { return ndec2nlong(x) << TWOPOTBITS_IN_LONG; }
    1519             : /* Fast implementation of ceil(x / (8*sizeof(long))); typecast to (ulong)
    1520             :  * to avoid overflow. Faster than 1 + ((x-1)>>TWOPOTBITS_IN_LONG)) :
    1521             :  *   addl, shrl instead of subl, sarl, addl */
    1522             : INLINE long
    1523     1049791 : nbits2nlong(long x) {
    1524     1049791 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1525             : }
    1526             : 
    1527             : INLINE long
    1528   241704909 : nbits2extraprec(long x) {
    1529   241704909 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1530             : }
    1531             : 
    1532             : /* Fast implementation of 2 + nbits2nlong(x) */
    1533             : INLINE long
    1534    78210696 : nbits2prec(long x) {
    1535    78210696 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1536             : }
    1537             : INLINE long
    1538     4143707 : nbits2lg(long x) {
    1539     4143707 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1540             : }
    1541             : /* ceil(x / sizeof(long)) */
    1542             : INLINE long
    1543     8163193 : nchar2nlong(long x) {
    1544     8163193 :   return (long)(((ulong)x+sizeof(long)-1) >> (TWOPOTBITS_IN_LONG-3L));
    1545             : }
    1546             : INLINE long
    1547  1233289971 : prec2nbits(long x) { return (x-2) * BITS_IN_LONG; }
    1548             : INLINE double
    1549      448414 : bit_accuracy_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1550             : INLINE double
    1551      231036 : prec2nbits_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1552             : INLINE long
    1553    25092911 : bit_prec(GEN x) { return prec2nbits(realprec(x)); }
    1554             : INLINE long
    1555  1152101750 : bit_accuracy(long x) { return prec2nbits(x); }
    1556             : INLINE long
    1557       12148 : prec2ndec(long x) { return (long)prec2nbits_mul(x, LOG10_2); }
    1558             : INLINE long
    1559         179 : nbits2ndec(long x) { return (long)(x * LOG10_2); }
    1560             : INLINE long
    1561        1651 : precdbl(long x) {return (x - 1) << 1;}
    1562             : INLINE long
    1563  3089576178 : divsBIL(long n) { return n >> TWOPOTBITS_IN_LONG; }
    1564             : INLINE long
    1565  3024736015 : remsBIL(long n) { return n & (BITS_IN_LONG-1); }
    1566             : 
    1567             : /*********************************************************************/
    1568             : /**                                                                 **/
    1569             : /**                      OPERATIONS MODULO m                        **/
    1570             : /**                                                                 **/
    1571             : /*********************************************************************/
    1572             : /* Assume m > 0, more efficient if 0 <= a, b < m */
    1573             : 
    1574             : INLINE GEN
    1575     2440035 : Fp_red(GEN a, GEN m) { return modii(a, m); }
    1576             : INLINE GEN
    1577    86280910 : Fp_add(GEN a, GEN b, GEN m)
    1578             : {
    1579    86280910 :   pari_sp av=avma;
    1580    86280910 :   GEN p = addii(a,b);
    1581    86299123 :   long s = signe(p);
    1582    86299123 :   if (!s) return p; /* = gen_0 */
    1583    75589056 :   if (s > 0) /* general case */
    1584             :   {
    1585    75365959 :     GEN t = subii(p, m);
    1586    75428311 :     s = signe(t);
    1587    75428311 :     if (!s) { avma = av; return gen_0; }
    1588    69961096 :     if (s < 0) { avma = (pari_sp)p; return p; }
    1589    30696918 :     if (cmpii(t, m) < 0) return gerepileuptoint(av, t); /* general case ! */
    1590     1115251 :     p = remii(t, m);
    1591             :   }
    1592             :   else
    1593      223097 :     p = modii(p, m);
    1594     1338348 :   return gerepileuptoint(av, p);
    1595             : }
    1596             : INLINE GEN
    1597    75418461 : Fp_sub(GEN a, GEN b, GEN m)
    1598             : {
    1599    75418461 :   pari_sp av=avma;
    1600    75418461 :   GEN p = subii(a,b);
    1601    75699071 :   long s = signe(p);
    1602    75699071 :   if (!s) return p; /* = gen_0 */
    1603    67837894 :   if (s > 0)
    1604             :   {
    1605    32757000 :     if (cmpii(p, m) < 0) return p; /* general case ! */
    1606     1316889 :     p = remii(p, m);
    1607             :   }
    1608             :   else
    1609             :   {
    1610    35080894 :     GEN t = addii(p, m);
    1611    35067289 :     if (!s) { avma = av; return gen_0; }
    1612    35067289 :     if (s > 0) return gerepileuptoint(av, t); /* general case ! */
    1613    35067289 :     p = modii(t, m);
    1614             :   }
    1615    36393864 :   return gerepileuptoint(av, p);
    1616             : }
    1617             : INLINE GEN
    1618    10848939 : Fp_neg(GEN b, GEN m)
    1619             : {
    1620    10848939 :   pari_sp av = avma;
    1621    10848939 :   long s = signe(b);
    1622             :   GEN p;
    1623    10848939 :   if (!s) return gen_0;
    1624     7451961 :   if (s > 0)
    1625             :   {
    1626     7250155 :     p = subii(m, b);
    1627     7249990 :     if (signe(p) >= 0) return p; /* general case ! */
    1628       92399 :     p = modii(p, m);
    1629             :   } else
    1630      201806 :     p = remii(negi(b), m);
    1631      294205 :   return gerepileuptoint(av, p);
    1632             : }
    1633             : 
    1634             : INLINE GEN
    1635       19996 : Fp_halve(GEN a, GEN p)
    1636             : {
    1637       19996 :   if (mpodd(a)) a = addii(a,p);
    1638       19996 :   return shifti(a,-1);
    1639             : }
    1640             : 
    1641             : /* assume 0 <= u < p and ps2 = p>>1 */
    1642             : INLINE GEN
    1643     5791913 : Fp_center(GEN u, GEN p, GEN ps2)
    1644     5791913 : { return abscmpii(u,ps2)<=0? icopy(u): subii(u,p); }
    1645             : 
    1646             : /* x + y*z mod p */
    1647             : INLINE GEN
    1648     7889401 : Fp_addmul(GEN x, GEN y, GEN z, GEN p)
    1649             : {
    1650             :   pari_sp av;
    1651     7889401 :   if (!signe(y) || !signe(z)) return Fp_red(x, p);
    1652     7466420 :   if (!signe(x)) return Fp_mul(z,y, p);
    1653     7165548 :   av = avma;
    1654     7165548 :   return gerepileuptoint(av, modii(addii(x, mulii(y,z)), p));
    1655             : }
    1656             : 
    1657             : INLINE GEN
    1658    65115411 : Fp_mul(GEN a, GEN b, GEN m)
    1659             : {
    1660    65115411 :   pari_sp av=avma;
    1661             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1662    65115411 :   (void)new_chunk(lg(a)+lg(b)+(lg(m)<<1));
    1663    65127351 :   p = mulii(a,b);
    1664    65127011 :   avma = av; return modii(p,m);
    1665             : }
    1666             : INLINE GEN
    1667    62173763 : Fp_sqr(GEN a, GEN m)
    1668             : {
    1669    62173763 :   pari_sp av=avma;
    1670             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1671    62173763 :   (void)new_chunk((lg(a)+lg(m))<<1);
    1672    62421627 :   p = sqri(a);
    1673    62607686 :   avma = av; return remii(p,m); /*Use remii: p >= 0 */
    1674             : }
    1675             : INLINE GEN
    1676    80651388 : Fp_mulu(GEN a, ulong b, GEN m)
    1677             : {
    1678    80651388 :   long l = lgefint(m);
    1679    80651388 :   if (l == 3)
    1680             :   {
    1681    43406142 :     ulong mm = m[2];
    1682    43406142 :     return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1683             :   } else {
    1684    37245246 :     pari_sp av = avma;
    1685             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1686    37245246 :     (void)new_chunk(lg(a)+1+(l<<1));
    1687    37254372 :     p = muliu(a,b);
    1688    36996498 :     avma = av; return modii(p,m);
    1689             :   }
    1690             : }
    1691             : INLINE GEN
    1692           0 : Fp_muls(GEN a, long b, GEN m)
    1693             : {
    1694           0 :   long l = lgefint(m);
    1695           0 :   if (l == 3)
    1696             :   {
    1697           0 :     ulong mm = m[2];
    1698           0 :     if (b < 0)
    1699             :     {
    1700           0 :       ulong t = Fl_mul(umodiu(a, mm), -b, mm);
    1701           0 :       return t? utoipos(mm - t): gen_0;
    1702             :     }
    1703             :     else
    1704           0 :       return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1705             :   } else {
    1706           0 :     pari_sp av = avma;
    1707             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1708           0 :     (void)new_chunk(lg(a)+1+(l<<1));
    1709           0 :     p = mulis(a,b);
    1710           0 :     avma = av; return modii(p,m);
    1711             :   }
    1712             : }
    1713             : 
    1714             : INLINE GEN
    1715     8119520 : Fp_inv(GEN a, GEN m)
    1716             : {
    1717             :   GEN res;
    1718     8119520 :   if (! invmod(a,m,&res)) pari_err_INV("Fp_inv", mkintmod(res,m));
    1719     8119413 :   return res;
    1720             : }
    1721             : INLINE GEN
    1722      291868 : Fp_invsafe(GEN a, GEN m)
    1723             : {
    1724             :   GEN res;
    1725      291868 :   if (! invmod(a,m,&res)) return NULL;
    1726      291868 :   return res;
    1727             : }
    1728             : INLINE GEN
    1729     2296135 : Fp_div(GEN a, GEN b, GEN m)
    1730             : {
    1731     2296135 :   pari_sp av=avma;
    1732             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1733     2296135 :   (void)new_chunk(lg(a)+(lg(m)<<1));
    1734     2296135 :   p = mulii(a, Fp_inv(b,m));
    1735     2296135 :   avma = av; return modii(p,m);
    1736             : }
    1737             : 
    1738             : INLINE GEN
    1739      681892 : Flx_mulu(GEN x, ulong a, ulong p) { return Flx_Fl_mul(x,a%p,p); }
    1740             : 
    1741             : /*******************************************************************/
    1742             : /*                                                                 */
    1743             : /*                        ADDMULII / SUBMULII                      */
    1744             : /*                                                                 */
    1745             : /*******************************************************************/
    1746             : /* x - y*z */
    1747             : INLINE GEN
    1748    13177423 : submulii(GEN x, GEN y, GEN z)
    1749             : {
    1750    13177423 :   long lx = lgefint(x), ly, lz;
    1751             :   pari_sp av;
    1752             :   GEN t;
    1753    13177423 :   if (lx == 2) { t = mulii(z,y); togglesign(t); return t; }
    1754    11393637 :   ly = lgefint(y);
    1755    11393637 :   if (ly == 2) return icopy(x);
    1756    10402721 :   lz = lgefint(z);
    1757    10402721 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1758    10402721 :   t = mulii(z, y);
    1759    10402721 :   avma = av; return subii(x,t);
    1760             : }
    1761             : /* y*z - x */
    1762             : INLINE GEN
    1763     1399990 : mulsubii(GEN y, GEN z, GEN x)
    1764             : {
    1765     1399990 :   long lx = lgefint(x), ly, lz;
    1766             :   pari_sp av;
    1767             :   GEN t;
    1768     1399990 :   if (lx == 2) return mulii(z,y);
    1769      873763 :   ly = lgefint(y);
    1770      873763 :   if (ly == 2) return negi(x);
    1771      838615 :   lz = lgefint(z);
    1772      838615 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1773      838615 :   t = mulii(z, y);
    1774      838615 :   avma = av; return subii(t,x);
    1775             : }
    1776             : 
    1777             : /* x - u*y */
    1778             : INLINE GEN
    1779        7371 : submuliu(GEN x, GEN y, ulong u)
    1780             : {
    1781             :   pari_sp av;
    1782        7371 :   long ly = lgefint(y);
    1783        7371 :   if (ly == 2) return icopy(x);
    1784        7371 :   av = avma;
    1785        7371 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1786        7371 :   y = mului(u,y);
    1787        7371 :   avma = av; return subii(x, y);
    1788             : }
    1789             : /* x + u*y */
    1790             : INLINE GEN
    1791        7371 : addmuliu(GEN x, GEN y, ulong u)
    1792             : {
    1793             :   pari_sp av;
    1794        7371 :   long ly = lgefint(y);
    1795        7371 :   if (ly == 2) return icopy(x);
    1796        7371 :   av = avma;
    1797        7371 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1798        7371 :   y = mului(u,y);
    1799        7371 :   avma = av; return addii(x, y);
    1800             : }
    1801             : /* x - u*y */
    1802             : INLINE GEN
    1803   112298196 : submuliu_inplace(GEN x, GEN y, ulong u)
    1804             : {
    1805             :   pari_sp av;
    1806   112298196 :   long ly = lgefint(y);
    1807   112298196 :   if (ly == 2) return x;
    1808    89375975 :   av = avma;
    1809    89375975 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1810    89375975 :   y = mului(u,y);
    1811    89375975 :   avma = av; return subii(x, y);
    1812             : }
    1813             : /* x + u*y */
    1814             : INLINE GEN
    1815   110943235 : addmuliu_inplace(GEN x, GEN y, ulong u)
    1816             : {
    1817             :   pari_sp av;
    1818   110943235 :   long ly = lgefint(y);
    1819   110943235 :   if (ly == 2) return x;
    1820    88991076 :   av = avma;
    1821    88991076 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1822    88991076 :   y = mului(u,y);
    1823    88991076 :   avma = av; return addii(x, y);
    1824             : }
    1825             : /* ux + vy */
    1826             : INLINE GEN
    1827    19304068 : lincombii(GEN u, GEN v, GEN x, GEN y)
    1828             : {
    1829    19304068 :   long lx = lgefint(x), ly;
    1830             :   GEN p1, p2;
    1831             :   pari_sp av;
    1832    19304068 :   if (lx == 2) return mulii(v,y);
    1833    12274330 :   ly = lgefint(y);
    1834    12274330 :   if (ly == 2) return mulii(u,x);
    1835    11541559 :   av = avma; (void)new_chunk(lx+ly+lgefint(u)+lgefint(v)); /* HACK */
    1836    11541559 :   p1 = mulii(u,x);
    1837    11541559 :   p2 = mulii(v,y);
    1838    11541559 :   avma = av; return addii(p1,p2);
    1839             : }
    1840             : 
    1841             : /*******************************************************************/
    1842             : /*                                                                 */
    1843             : /*                          GEN SUBTYPES                           */
    1844             : /*                                                                 */
    1845             : /*******************************************************************/
    1846             : 
    1847             : INLINE int
    1848  1090205017 : is_const_t(long t) { return (t < t_POLMOD); }
    1849             : INLINE int
    1850       51797 : is_extscalar_t(long t) { return (t <= t_POL); }
    1851             : INLINE int
    1852     1023598 : is_intreal_t(long t) { return (t <= t_REAL); }
    1853             : INLINE int
    1854   378994977 : is_matvec_t(long t) { return (t >= t_VEC && t <= t_MAT); }
    1855             : INLINE int
    1856    45072483 : is_noncalc_t(long tx) { return (tx) >= t_LIST; }
    1857             : INLINE int
    1858      744182 : is_rational_t(long t) { return (t == t_INT || t == t_FRAC); }
    1859             : INLINE int
    1860      277665 : is_real_t(long t) { return (t == t_INT || t == t_REAL || t == t_FRAC); }
    1861             : INLINE int
    1862  2818955882 : is_recursive_t(long t) { return lontyp[t]; }
    1863             : INLINE int
    1864   167851657 : is_scalar_t(long t) { return (t < t_POL); }
    1865             : INLINE int
    1866      864399 : is_vec_t(long t) { return (t == t_VEC || t == t_COL); }
    1867             : 
    1868             : /*******************************************************************/
    1869             : /*                                                                 */
    1870             : /*                         TRANSCENDENTAL                          */
    1871             : /*                                                                 */
    1872             : /*******************************************************************/
    1873             : INLINE GEN
    1874    16302644 : sqrtr(GEN x) {
    1875    16302644 :   long s = signe(x);
    1876    16302644 :   if (s == 0) return real_0_bit(expo(x) >> 1);
    1877    16268957 :   if (s >= 0) return sqrtr_abs(x);
    1878       25314 :   retmkcomplex(gen_0, sqrtr_abs(x));
    1879             : }
    1880             : INLINE GEN
    1881           0 : cbrtr_abs(GEN x) { return sqrtnr_abs(x, 3); }
    1882             : INLINE GEN
    1883           0 : cbrtr(GEN x) {
    1884           0 :   long s = signe(x);
    1885             :   GEN r;
    1886           0 :   if (s == 0) return real_0_bit(expo(x) / 3);
    1887           0 :   r = cbrtr_abs(x);
    1888           0 :   if (s < 0) togglesign(r);
    1889           0 :   return r;
    1890             : }
    1891             : INLINE GEN
    1892      281522 : sqrtnr(GEN x, long n) {
    1893      281522 :   long s = signe(x);
    1894             :   GEN r;
    1895      281522 :   if (s == 0) return real_0_bit(expo(x) / n);
    1896      281522 :   r = sqrtnr_abs(x, n);
    1897      281522 :   if (s < 0) pari_err_IMPL("sqrtnr for x < 0");
    1898      281522 :   return r;
    1899             : }
    1900             : INLINE long
    1901      211267 : logint(GEN B, GEN y) { return logintall(B,y,NULL); }
    1902             : INLINE ulong
    1903     8269363 : ulogint(ulong B, ulong y)
    1904             : {
    1905             :   ulong r;
    1906             :   long e;
    1907     8269363 :   if (y == 2) return expu(B);
    1908     8192379 :   r = y;
    1909    27488328 :   for (e=1;; e++)
    1910             :   { /* here, r = y^e, r2 = y^(e-1) */
    1911    27488328 :     if (r >= B) return r == B? e: e-1;
    1912    19295949 :     r = umuluu_or_0(y, r);
    1913    19295949 :     if (!r) return e;
    1914    19295949 :   }
    1915             : }
    1916             : 
    1917             : /*******************************************************************/
    1918             : /*                                                                 */
    1919             : /*                         MISCELLANEOUS                           */
    1920             : /*                                                                 */
    1921             : /*******************************************************************/
    1922     1023521 : INLINE int ismpzero(GEN x) { return is_intreal_t(typ(x)) && !signe(x); }
    1923   514042056 : INLINE int isintzero(GEN x) { return typ(x) == t_INT && !signe(x); }
    1924    11553982 : INLINE int isint1(GEN x) { return typ(x)==t_INT && equali1(x); }
    1925        5082 : INLINE int isintm1(GEN x){ return typ(x)==t_INT && equalim1(x);}
    1926   275175710 : INLINE int equali1(GEN n)
    1927   275175710 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(1)) && n[2] == 1; }
    1928    51589624 : INLINE int equalim1(GEN n)
    1929    51589624 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(-1)) && n[2] == 1; }
    1930             : /* works only for POSITIVE integers */
    1931  1762685888 : INLINE int is_pm1(GEN n)
    1932  1762685888 : { return lgefint(n) == 3 && n[2] == 1; }
    1933   168187505 : INLINE int is_bigint(GEN n)
    1934   168187505 : { long l = lgefint(n); return l > 3 || (l == 3 && (n[2] & HIGHBIT)); }
    1935             : 
    1936  2102693318 : INLINE int odd(long x) { return x & 1; }
    1937     7348800 : INLINE int both_odd(long x, long y) { return x & y & 1; }
    1938             : 
    1939             : INLINE int
    1940  2509046959 : isonstack(GEN x)
    1941  5018093918 : { return ((pari_sp)x >= pari_mainstack->bot
    1942  2509046959 :        && (pari_sp)x <  pari_mainstack->top); }
    1943             : 
    1944             : /* assume x != 0 and x t_REAL, return an approximation to log2(|x|) */
    1945             : INLINE double
    1946    17623597 : dbllog2r(GEN x)
    1947    17623597 : { return log2((double)(ulong)x[2]) + (double)(expo(x) - (BITS_IN_LONG-1)); }
    1948             : 
    1949             : INLINE GEN
    1950      276464 : mul_content(GEN cx, GEN cy)
    1951             : {
    1952      276464 :   if (!cx) return cy;
    1953       93072 :   if (!cy) return cx;
    1954       70215 :   return gmul(cx,cy);
    1955             : }
    1956             : INLINE GEN
    1957     1535429 : mul_denom(GEN dx, GEN dy)
    1958             : {
    1959     1535429 :   if (!dx) return dy;
    1960     1018868 :   if (!dy) return dx;
    1961      315868 :   return mulii(dx,dy);
    1962             : }
    1963             : 
    1964             : /* POLYNOMIALS */
    1965             : INLINE GEN
    1966    17562838 : constant_coeff(GEN x) { return signe(x)? gel(x,2): gen_0; }
    1967             : INLINE GEN
    1968    73876959 : leading_coeff(GEN x) { return lg(x) == 2? gen_0: gel(x,lg(x)-1); }
    1969             : INLINE ulong
    1970      403099 : Flx_lead(GEN x) { return lg(x) == 2? 0: x[lg(x)-1]; }
    1971             : INLINE long
    1972  2668054581 : degpol(GEN x) { return lg(x)-3; }
    1973             : INLINE long
    1974  1385510550 : lgpol(GEN x) { return lg(x)-2; }
    1975             : INLINE long
    1976    96476655 : lgcols(GEN x) { return lg(gel(x,1)); }
    1977             : INLINE long
    1978    20403374 : nbrows(GEN x) { return lg(gel(x,1))-1; }
    1979             : INLINE GEN
    1980           0 : truecoeff(GEN x, long n) { return polcoeff0(x,n,-1); }
    1981             : 
    1982             : INLINE GEN
    1983      525009 : RgXQ_mul(GEN y, GEN x, GEN T) { return RgX_rem(RgX_mul(y, x), T); }
    1984             : INLINE GEN
    1985      273058 : RgXQ_sqr(GEN x, GEN T) { return RgX_rem(RgX_sqr(x), T); }
    1986             : 
    1987             : INLINE GEN
    1988      141771 : ZXQ_mul(GEN y, GEN x, GEN T) { return ZX_rem(ZX_mul(y, x), T); }
    1989             : INLINE GEN
    1990       34839 : ZXQ_sqr(GEN x, GEN T) { return ZX_rem(ZX_sqr(x), T); }
    1991             : 
    1992             : INLINE GEN
    1993    92334069 : RgX_copy(GEN x)
    1994             : {
    1995             :   long lx, i;
    1996    92334069 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
    1997    92334081 :   for (i = 2; i<lx; i++) gel(y,i) = gcopy(gel(x,i));
    1998    92334074 :   return y;
    1999             : }
    2000             : /* have to use ulong to avoid silly warnings from gcc "assuming signed
    2001             :  * overflow does not occur" */
    2002             : INLINE GEN
    2003     2220422 : RgX_coeff(GEN x, long n)
    2004             : {
    2005     2220422 :   ulong l = lg(x);
    2006     2220422 :   return (n < 0 || ((ulong)n+3) > l)? gen_0: gel(x,n+2);
    2007             : }
    2008             : INLINE GEN
    2009      315497 : RgX_renormalize(GEN x) { return RgX_renormalize_lg(x, lg(x)); }
    2010             : INLINE GEN
    2011     6424883 : RgX_div(GEN x, GEN y) { return RgX_divrem(x,y,NULL); }
    2012             : INLINE GEN
    2013     3641500 : RgX_rem(GEN x, GEN y) { return RgX_divrem(x,y,ONLY_REM); }
    2014             : INLINE GEN
    2015           7 : RgXQX_div(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,NULL); }
    2016             : INLINE GEN
    2017       17808 : RgXQX_rem(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,ONLY_REM); }
    2018             : INLINE GEN
    2019      827879 : FpX_div(GEN x, GEN y, GEN p) { return FpX_divrem(x,y,p, NULL); }
    2020             : INLINE GEN
    2021     3501057 : Flx_div(GEN x, GEN y, ulong p) { return Flx_divrem(x,y,p, NULL); }
    2022             : INLINE GEN
    2023     2989160 : F2x_div(GEN x, GEN y) { return F2x_divrem(x,y, NULL); }
    2024             : INLINE GEN
    2025           0 : FpV_FpC_mul(GEN x, GEN y, GEN p) { return FpV_dotproduct(x,y,p); }
    2026             : INLINE GEN
    2027    44757094 : pol0_Flx(long sv) { return mkvecsmall(sv); }
    2028             : INLINE GEN
    2029    18207180 : pol1_Flx(long sv) { return mkvecsmall2(sv, 1); }
    2030             : INLINE GEN
    2031    18074276 : polx_Flx(long sv) { return mkvecsmall3(sv, 0, 1); }
    2032             : INLINE GEN
    2033           0 : zero_zx(long sv) { return zero_Flx(sv); }
    2034             : INLINE GEN
    2035           0 : polx_zx(long sv) { return polx_Flx(sv); }
    2036             : INLINE GEN
    2037           0 : zx_shift(GEN x, long n) { return Flx_shift(x,n); }
    2038             : INLINE GEN
    2039           0 : zx_renormalize(GEN x, long l) { return Flx_renormalize(x,l); }
    2040             : INLINE GEN
    2041          35 : zero_F2x(long sv) { return zero_Flx(sv); }
    2042             : INLINE GEN
    2043    11373132 : pol0_F2x(long sv) { return pol0_Flx(sv); }
    2044             : INLINE GEN
    2045     2766878 : pol1_F2x(long sv) { return pol1_Flx(sv); }
    2046             : INLINE GEN
    2047      671530 : polx_F2x(long sv) { return mkvecsmall2(sv, 2); }
    2048             : INLINE int
    2049      816781 : F2x_equal1(GEN x) { return Flx_equal1(x); }
    2050             : INLINE int
    2051     3545521 : F2x_equal(GEN V, GEN W) { return Flx_equal(V,W); }
    2052             : INLINE GEN
    2053    69047767 : F2x_copy(GEN x) { return leafcopy(x); }
    2054             : INLINE GEN
    2055           0 : F2v_copy(GEN x) { return leafcopy(x); }
    2056             : INLINE GEN
    2057     2343946 : Flv_copy(GEN x) { return leafcopy(x); }
    2058             : INLINE GEN
    2059    78089286 : Flx_copy(GEN x) { return leafcopy(x); }
    2060             : INLINE GEN
    2061     1756115 : vecsmall_copy(GEN x) { return leafcopy(x); }
    2062             : INLINE int
    2063     4720636 : Flx_equal1(GEN x) { return degpol(x)==0 && x[2] == 1; }
    2064             : INLINE int
    2065       17509 : ZX_equal1(GEN x) { return degpol(x)==0 && equali1(gel(x,2)); }
    2066             : 
    2067             : INLINE GEN
    2068    74127239 : ZX_renormalize(GEN x, long lx)    { return ZXX_renormalize(x,lx); }
    2069             : INLINE GEN
    2070    88296189 : FpX_renormalize(GEN x, long lx)   { return ZXX_renormalize(x,lx); }
    2071             : INLINE GEN
    2072      949403 : FpXX_renormalize(GEN x, long lx)  { return ZXX_renormalize(x,lx); }
    2073             : INLINE GEN
    2074      973385 : FpXQX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
    2075             : INLINE GEN
    2076   130725008 : F2x_renormalize(GEN x, long lx)   { return Flx_renormalize(x,lx); }
    2077             : INLINE GEN
    2078        8758 : F2v_to_F2x(GEN x, long sv) {
    2079        8758 :   GEN y = leafcopy(x);
    2080        8758 :   y[1] = sv; F2x_renormalize(y, lg(y)); return y;
    2081             : }
    2082             : 
    2083             : INLINE GEN
    2084           0 : ZX_ZXY_resultant(GEN a, GEN b) { return ZX_ZXY_rnfequation(a,b,NULL); }
    2085             : INLINE long
    2086         448 : sturm(GEN x) { return sturmpart(x, NULL, NULL); }
    2087             : INLINE GEN
    2088       36873 : resultant(GEN x, GEN y) { return resultant_all(x,y,NULL); }
    2089             : 
    2090             : INLINE long
    2091        2429 : gval(GEN x, long v) {
    2092        2429 :   pari_sp av = avma;
    2093        2429 :   long n = gvaluation(x, pol_x(v));
    2094        2429 :   avma = av; return n;
    2095             : }
    2096             : 
    2097             : INLINE void
    2098      675412 : RgX_shift_inplace_init(long v)
    2099      675412 : { if (v) (void)cgetg(v, t_VECSMALL); }
    2100             : /* shift polynomial in place. assume v free cells have been left before x */
    2101             : INLINE GEN
    2102      675414 : RgX_shift_inplace(GEN x, long v)
    2103             : {
    2104             :   long i, lx;
    2105             :   GEN y, z;
    2106      675414 :   if (!v) return x;
    2107      261991 :   lx = lg(x);
    2108      261991 :   if (lx == 2) return x;
    2109      261991 :   y = x + v;
    2110      261991 :   z = x + lx;
    2111             :   /* stackdummy from normalizepol: move it up */
    2112      261991 :   if (lg(z) != v) x[lx + v] = z[0];
    2113      261991 :   for (i = lx-1; i >= 2; i--) gel(y,i) = gel(x,i);
    2114      261991 :   for (i = v+1;  i >= 2; i--) gel(x,i) = gen_0;
    2115             :   /* leave x[1] alone: it is correct */
    2116      261991 :   x[0] = evaltyp(t_POL) | evallg(lx+v); return x;
    2117             : }
    2118             : 
    2119             : 
    2120             : /* LINEAR ALGEBRA */
    2121             : INLINE GEN
    2122       68061 : zv_to_ZV(GEN x) { return vecsmall_to_vec(x); }
    2123             : INLINE GEN
    2124     1283408 : zc_to_ZC(GEN x) { return vecsmall_to_col(x); }
    2125             : INLINE GEN
    2126      392124 : ZV_to_zv(GEN x) { return vec_to_vecsmall(x); }
    2127             : INLINE GEN
    2128           0 : zx_to_zv(GEN x, long N) { return Flx_to_Flv(x,N); }
    2129             : INLINE GEN
    2130           0 : zv_to_zx(GEN x, long sv) { return Flv_to_Flx(x,sv); }
    2131             : INLINE GEN
    2132           0 : zm_to_zxV(GEN x, long sv) { return Flm_to_FlxV(x,sv); }
    2133             : INLINE GEN
    2134           0 : zero_zm(long x, long y) { return zero_Flm(x,y); }
    2135             : INLINE GEN
    2136    17821280 : zero_zv(long x) { return zero_Flv(x); }
    2137             : INLINE GEN
    2138         168 : zm_transpose(GEN x) { return Flm_transpose(x); }
    2139             : INLINE GEN
    2140           0 : zm_copy(GEN x) { return Flm_copy(x); }
    2141             : INLINE GEN
    2142     2002560 : zv_copy(GEN x) { return Flv_copy(x); }
    2143             : INLINE GEN
    2144           0 : zm_row(GEN x, long i) { return Flm_row(x,i); }
    2145             : 
    2146             : INLINE GEN
    2147      840091 : ZC_hnfrem(GEN x, GEN y) { return ZC_hnfremdiv(x,y,NULL); }
    2148             : INLINE GEN
    2149       35604 : ZM_hnfrem(GEN x, GEN y) { return ZM_hnfdivrem(x,y,NULL); }
    2150             : INLINE GEN
    2151     1162218 : ZM_lll(GEN x, double D, long f) { return ZM_lll_norms(x,D,f,NULL); }
    2152             : INLINE void
    2153      142980 : RgM_dimensions(GEN x, long *m, long *n) { *n = lg(x)-1; *m = *n? nbrows(x): 0; }
    2154             : INLINE GEN
    2155       35482 : RgM_inv(GEN a) { return RgM_solve(a, NULL); }
    2156             : INLINE GEN
    2157     6618833 : RgM_shallowcopy(GEN x)
    2158             : {
    2159             :   long l;
    2160     6618833 :   GEN y = cgetg_copy(x, &l);
    2161     6618833 :   while (--l > 0) gel(y,l) = leafcopy(gel(x,l));
    2162     6618833 :   return y;
    2163             : }
    2164             : INLINE GEN
    2165         362 : F2m_copy(GEN x) { return RgM_shallowcopy(x); }
    2166             : 
    2167             : INLINE GEN
    2168     1394047 : Flm_copy(GEN x) { return RgM_shallowcopy(x); }
    2169             : 
    2170             : /* divisibility: return 1 if y[i] | x[i] for all i, 0 otherwise. Assume
    2171             :  * x,y are ZV of the same length */
    2172             : INLINE int
    2173       23198 : ZV_dvd(GEN x, GEN y)
    2174             : {
    2175       23198 :   long i, l = lg(x);
    2176       36652 :   for (i=1; i < l; i++)
    2177       29519 :     if ( ! dvdii( gel(x,i), gel(y,i) ) ) return 0;
    2178        7133 :   return 1;
    2179             : }
    2180             : 
    2181             : /* Fq */
    2182             : INLINE GEN
    2183     2166408 : Fq_red(GEN x, GEN T, GEN p)
    2184     2166408 : { return typ(x)==t_INT? Fp_red(x,p): FpXQ_red(x,T,p); }
    2185             : INLINE GEN
    2186       10855 : Fq_to_FpXQ(GEN x, GEN T, GEN p /*unused*/)
    2187             : {
    2188             :   (void) p;
    2189       10855 :   return typ(x)==t_INT ? scalarpol(x, get_FpX_var(T)): x;
    2190             : }
    2191             : 
    2192             : INLINE GEN
    2193         833 : gener_Fq_local(GEN T, GEN p, GEN L)
    2194         833 : { return T? gener_FpXQ_local(T,p, L)
    2195         833 :           : pgener_Fp_local(p, L); }
    2196             : 
    2197             : /* FpXQX */
    2198             : INLINE GEN
    2199         961 : FpXQX_div(GEN x, GEN y, GEN T, GEN p) { return FpXQX_divrem(x, y, T, p, NULL); }
    2200             : INLINE GEN
    2201       31785 : FlxqX_div(GEN x, GEN y, GEN T, ulong p) { return FlxqX_divrem(x, y, T, p, NULL); }
    2202             : INLINE GEN
    2203       30632 : F2xqX_div(GEN x, GEN y, GEN T) { return F2xqX_divrem(x, y, T, NULL); }
    2204             : 
    2205             : /* FqX */
    2206             : INLINE GEN
    2207       27419 : FqX_red(GEN z, GEN T, GEN p) { return T? FpXQX_red(z, T, p): FpX_red(z, p); }
    2208             : INLINE GEN
    2209      903963 : FqX_add(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2210             : INLINE GEN
    2211       16438 : FqX_neg(GEN x,GEN T,GEN p) { return T? FpXX_neg(x,p): FpX_neg(x,p); }
    2212             : INLINE GEN
    2213        2380 : FqX_sub(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2214             : INLINE GEN
    2215      613238 : FqX_Fp_mul(GEN P, GEN u, GEN T, GEN p)
    2216      613238 : { return T? FpXX_Fp_mul(P, u, p): FpX_Fp_mul(P, u, p); }
    2217             : INLINE GEN
    2218      552476 : FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p)
    2219      552476 : { return typ(U)==t_INT ? FqX_Fp_mul(P, U, T, p): FpXQX_FpXQ_mul(P, U, T, p); }
    2220             : INLINE GEN
    2221       87431 : FqX_mul(GEN x, GEN y, GEN T, GEN p)
    2222       87431 : { return T? FpXQX_mul(x, y, T, p): FpX_mul(x, y, p); }
    2223             : INLINE GEN
    2224      459889 : FqX_mulu(GEN x, ulong y, GEN T, GEN p)
    2225      459889 : { return T? FpXX_mulu(x, y, p): FpX_mulu(x, y, p); }
    2226             : INLINE GEN
    2227        4760 : FqX_sqr(GEN x, GEN T, GEN p)
    2228        4760 : { return T? FpXQX_sqr(x, T, p): FpX_sqr(x, p); }
    2229             : INLINE GEN
    2230        1428 : FqX_powu(GEN x, ulong n, GEN T, GEN p)
    2231        1428 : { return T? FpXQX_powu(x, n, T, p): FpX_powu(x, n, p); }
    2232             : INLINE GEN
    2233        5126 : FqX_div(GEN x, GEN y, GEN T, GEN p)
    2234        5126 : { return T? FpXQX_divrem(x,y,T,p,NULL): FpX_divrem(x,y,p,NULL); }
    2235             : INLINE GEN
    2236        5605 : FqX_get_red(GEN S, GEN T, GEN p)
    2237        5605 : { return T? FpXQX_get_red(S,T,p): FpX_get_red(S,p); }
    2238             : INLINE GEN
    2239       47875 : FqX_rem(GEN x, GEN y, GEN T, GEN p)
    2240       47875 : { return T? FpXQX_rem(x,y,T,p): FpX_rem(x,y,p); }
    2241             : INLINE GEN
    2242         329 : FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2243         329 : { return T? FpXQX_divrem(x,y,T,p,z): FpX_divrem(x,y,p,z); }
    2244             : INLINE GEN
    2245        5957 : FqX_div_by_X_x(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2246        5957 : { return T? FpXQX_div_by_X_x(x,y,T,p,z): FpX_div_by_X_x(x,y,p,z); }
    2247             : INLINE GEN
    2248           0 : FqX_halfgcd(GEN P,GEN Q,GEN T,GEN p)
    2249           0 : {return T? FpXQX_halfgcd(P,Q,T,p): FpX_halfgcd(P,Q,p);}
    2250             : INLINE GEN
    2251      257791 : FqX_gcd(GEN P,GEN Q,GEN T,GEN p)
    2252      257791 : {return T? FpXQX_gcd(P,Q,T,p): FpX_gcd(P,Q,p);}
    2253             : INLINE GEN
    2254       82936 : FqX_extgcd(GEN P,GEN Q,GEN T,GEN p, GEN *U, GEN *V)
    2255       82936 : { return T? FpXQX_extgcd(P,Q,T,p,U,V): FpX_extgcd(P,Q,p,U,V); }
    2256             : INLINE GEN
    2257        3066 : FqX_normalize(GEN z, GEN T, GEN p) { return T? FpXQX_normalize(z, T, p): FpX_normalize(z, p); }
    2258             : INLINE GEN
    2259      270081 : FqX_deriv(GEN f, /*unused*/GEN T, GEN p) { (void)T; return FpXX_deriv(f, p); }
    2260             : INLINE GEN
    2261       72891 : FqX_factor(GEN f, GEN T, GEN p) { return T?FpXQX_factor(f, T, p): FpX_factor(f, p); }
    2262             : INLINE GEN
    2263        5810 : FqX_roots(GEN f, GEN T, GEN p) { return T?FpXQX_roots(f, T, p): FpX_roots(f, p); }
    2264             : 
    2265             : /*FqXQ*/
    2266             : INLINE GEN
    2267           0 : FqXQ_add(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2268           0 : { (void)S; return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2269             : INLINE GEN
    2270           0 : FqXQ_sub(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2271           0 : { (void)S; return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2272             : INLINE GEN
    2273           0 : FqXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p)
    2274           0 : { return T? FpXQXQ_div(x,y,S,T,p): FpXQ_div(x,y,S,p); }
    2275             : INLINE GEN
    2276           0 : FqXQ_inv(GEN x, GEN S, GEN T, GEN p)
    2277           0 : { return T? FpXQXQ_inv(x,S,T,p): FpXQ_inv(x,S,p); }
    2278             : INLINE GEN
    2279           0 : FqXQ_invsafe(GEN x, GEN S, GEN T, GEN p)
    2280           0 : { return T? FpXQXQ_invsafe(x,S,T,p): FpXQ_inv(x,S,p); }
    2281             : INLINE GEN
    2282       21018 : FqXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p)
    2283       21018 : { return T? FpXQXQ_mul(x,y,S,T,p): FpXQ_mul(x,y,S,p); }
    2284             : INLINE GEN
    2285           0 : FqXQ_sqr(GEN x, GEN S, GEN T, GEN p)
    2286           0 : { return T? FpXQXQ_sqr(x,S,T,p): FpXQ_sqr(x,S,p); }
    2287             : INLINE GEN
    2288           0 : FqXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p)
    2289           0 : { return T? FpXQXQ_pow(x,n,S,T,p): FpXQ_pow(x,n,S,p); }
    2290             : 
    2291             : /*FpXQ*/
    2292             : INLINE GEN
    2293           0 : FpXQ_add(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2294           0 : { (void)T; return FpX_add(x,y,p); }
    2295             : INLINE GEN
    2296           0 : FpXQ_sub(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2297           0 : { (void)T; return FpX_sub(x,y,p); }
    2298             : 
    2299             : /*Flxq*/
    2300             : INLINE GEN
    2301           0 : Flxq_add(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2302           0 : { (void)T; return Flx_add(x,y,p); }
    2303             : INLINE GEN
    2304         264 : Flxq_sub(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2305         264 : { (void)T; return Flx_sub(x,y,p); }
    2306             : 
    2307             : /* F2x */
    2308             : 
    2309             : INLINE ulong
    2310   168860493 : F2x_coeff(GEN x,long v)
    2311             : {
    2312   168860493 :    ulong u=(ulong)x[2+divsBIL(v)];
    2313   168859931 :    return (u>>remsBIL(v))&1UL;
    2314             : }
    2315             : 
    2316             : INLINE void
    2317     4180338 : F2x_clear(GEN x,long v)
    2318             : {
    2319     4180338 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2320     4180338 :    *u&=~(1UL<<remsBIL(v));
    2321     4180338 : }
    2322             : 
    2323             : INLINE void
    2324    38796801 : F2x_set(GEN x,long v)
    2325             : {
    2326    38796801 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2327    38798627 :    *u|=1UL<<remsBIL(v);
    2328    38801745 : }
    2329             : 
    2330             : INLINE void
    2331     1360407 : F2x_flip(GEN x,long v)
    2332             : {
    2333     1360407 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2334     1360407 :    *u^=1UL<<remsBIL(v);
    2335     1360407 : }
    2336             : 
    2337             : /* F2v */
    2338             : 
    2339             : INLINE ulong
    2340   162409916 : F2v_coeff(GEN x,long v) { return F2x_coeff(x,v-1); }
    2341             : 
    2342             : INLINE void
    2343     4180338 : F2v_clear(GEN x,long v) { F2x_clear(x,v-1); }
    2344             : 
    2345             : INLINE void
    2346    12561299 : F2v_set(GEN x,long v)   { F2x_set(x,v-1); }
    2347             : 
    2348             : INLINE void
    2349     1360407 : F2v_flip(GEN x,long v) { F2x_flip(x,v-1); }
    2350             : 
    2351             : /* F2m */
    2352             : 
    2353             : INLINE ulong
    2354    19319885 : F2m_coeff(GEN x, long a, long b) { return F2v_coeff(gel(x,b), a); }
    2355             : 
    2356             : INLINE void
    2357           0 : F2m_clear(GEN x, long a, long b) { F2v_clear(gel(x,b), a); }
    2358             : 
    2359             : INLINE void
    2360     2352087 : F2m_set(GEN x, long a, long b) { F2v_set(gel(x,b), a); }
    2361             : 
    2362             : INLINE void
    2363     1360407 : F2m_flip(GEN x, long a, long b) { F2v_flip(gel(x,b), a); }
    2364             : 
    2365             : /* ARITHMETIC */
    2366             : INLINE GEN
    2367        1029 : matpascal(long n) { return matqpascal(n, NULL); }
    2368             : INLINE long
    2369     2225428 : Z_issquare(GEN x) { return Z_issquareall(x, NULL); }
    2370             : INLINE long
    2371          14 : Z_ispower(GEN x, ulong k) { return Z_ispowerall(x, k, NULL); }
    2372             : INLINE GEN
    2373     5426576 : sqrti(GEN x) { return sqrtremi(x,NULL); }
    2374             : INLINE GEN
    2375     7478021 : gaddgs(GEN y, long s) { return gaddsg(s,y); }
    2376             : INLINE int
    2377       23890 : gcmpgs(GEN y, long s) { return -gcmpsg(s,y); }
    2378             : INLINE int
    2379       22841 : gequalgs(GEN y, long s) { return gequalsg(s,y); }
    2380             : INLINE GEN
    2381           0 : gmaxsg(long s, GEN y) { return gmaxgs(y,s); }
    2382             : INLINE GEN
    2383           0 : gminsg(long s, GEN y) { return gmings(y,s); }
    2384             : INLINE GEN
    2385    13266538 : gmulgs(GEN y, long s) { return gmulsg(s,y); }
    2386             : INLINE GEN
    2387      558103 : gsubgs(GEN y, long s) { return gaddgs(y, -s); }
    2388             : INLINE GEN
    2389      462973 : gdivsg(long s, GEN y) { return gdiv(stoi(s), y); }
    2390             : 
    2391             : /* x t_COMPLEX */
    2392             : INLINE GEN
    2393     9529913 : cxnorm(GEN x) { return gadd(gsqr(gel(x,1)), gsqr(gel(x,2))); }
    2394             : /* q t_QUAD */
    2395             : INLINE GEN
    2396         623 : quadnorm(GEN q)
    2397             : {
    2398         623 :   GEN X = gel(q,1), b = gel(X,3), c = gel(X,2);
    2399         623 :   GEN z, u = gel(q,3), v = gel(q,2);
    2400         623 :   if (typ(u) == t_INT && typ(v) == t_INT) /* generic case */
    2401             :   {
    2402         308 :     z = signe(b)? mulii(v, addii(u,v)): sqri(v);
    2403         308 :     return addii(z, mulii(c, sqri(u)));
    2404             :   }
    2405             :   else
    2406             :   {
    2407         315 :     z = signe(b)? gmul(v, gadd(u,v)): gsqr(v);
    2408         315 :     return gadd(z, gmul(c, gsqr(u)));
    2409             :   }
    2410             : }
    2411             : /* x a t_QUAD, return the attached discriminant */
    2412             : INLINE GEN
    2413         252 : quad_disc(GEN x)
    2414             : {
    2415         252 :   GEN Q = gel(x,1), b = gel(Q,3), c = gel(Q,2), c4;
    2416         252 :   if (is_pm1(b))
    2417             :   {
    2418         196 :     pari_sp av = avma; (void)new_chunk(lgefint(c) + 1);
    2419         196 :     c4 = shifti(c,2); avma = av; return subsi(1, c4);
    2420             :   }
    2421          56 :   c4 = shifti(c,2); togglesign_safe(&c4); return c4;
    2422             : }
    2423             : INLINE GEN
    2424     6345364 : qfb_disc3(GEN x, GEN y, GEN z) { return subii(sqri(y), shifti(mulii(x,z),2)); }
    2425             : INLINE GEN
    2426     6264528 : qfb_disc(GEN x) { return qfb_disc3(gel(x,1), gel(x,2), gel(x,3)); }
    2427             : 
    2428             : INLINE GEN
    2429     1289120 : sqrfrac(GEN x)
    2430             : {
    2431     1289120 :   GEN z = cgetg(3,t_FRAC);
    2432     1289120 :   gel(z,1) = sqri(gel(x,1));
    2433     1289120 :   gel(z,2) = sqri(gel(x,2)); return z;
    2434             : }
    2435             : 
    2436             : INLINE void
    2437    12715818 : normalize_frac(GEN z) {
    2438    12715818 :   if (signe(gel(z,2)) < 0) { togglesign(gel(z,1)); setabssign(gel(z,2)); }
    2439    12715818 : }
    2440             : 
    2441             : INLINE GEN
    2442      231460 : powii(GEN x, GEN n)
    2443             : {
    2444      231460 :   long ln = lgefint(n);
    2445      231460 :   if (ln == 3) {
    2446             :     GEN z;
    2447      228331 :     if (signe(n) > 0) return powiu(x, n[2]);
    2448        4935 :     z = cgetg(3, t_FRAC);
    2449        4935 :     gel(z,1) = gen_1;
    2450        4935 :     gel(z,2) = powiu(x, n[2]);
    2451        4935 :     return z;
    2452             :   }
    2453        3129 :   if (ln == 2) return gen_1; /* rare */
    2454             :   /* should never happen */
    2455           0 :   return powgi(x, n); /* overflow unless x = 0, 1, -1 */
    2456             : }
    2457             : INLINE GEN
    2458         840 : powIs(long n) {
    2459         840 :   switch(n & 3)
    2460             :   {
    2461           7 :     case 1: return mkcomplex(gen_0,gen_1);
    2462         315 :     case 2: return gen_m1;
    2463         455 :     case 3: return mkcomplex(gen_0,gen_m1);
    2464             :   }
    2465          63 :   return gen_1;
    2466             : }
    2467             : 
    2468             : /*******************************************************************/
    2469             : /*                                                                 */
    2470             : /*                             ASSIGNMENTS                         */
    2471             : /*                                                                 */
    2472             : /*******************************************************************/
    2473           0 : INLINE void mpexpz(GEN x, GEN z)
    2474           0 : { pari_sp av = avma; gaffect(mpexp(x), z); avma = av; }
    2475           0 : INLINE void mplogz(GEN x, GEN z)
    2476           0 : { pari_sp av = avma; gaffect(mplog(x), z); avma = av; }
    2477           0 : INLINE void mpcosz(GEN x, GEN z)
    2478           0 : { pari_sp av = avma; gaffect(mpcos(x), z); avma = av; }
    2479           0 : INLINE void mpsinz(GEN x, GEN z)
    2480           0 : { pari_sp av = avma; gaffect(mpsin(x), z); avma = av; }
    2481           0 : INLINE void gnegz(GEN x, GEN z)
    2482           0 : { pari_sp av = avma; gaffect(gneg(x), z); avma = av; }
    2483           0 : INLINE void gabsz(GEN x, long prec, GEN z)
    2484           0 : { pari_sp av = avma; gaffect(gabs(x,prec), z); avma = av; }
    2485       23318 : INLINE void gaddz(GEN x, GEN y, GEN z)
    2486       23318 : { pari_sp av = avma; gaffect(gadd(x,y), z); avma = av; }
    2487           0 : INLINE void gsubz(GEN x, GEN y, GEN z)
    2488           0 : { pari_sp av = avma; gaffect(gsub(x,y), z); avma = av; }
    2489       11673 : INLINE void gmulz(GEN x, GEN y, GEN z)
    2490       11673 : { pari_sp av = avma; gaffect(gmul(x,y), z); avma = av; }
    2491           0 : INLINE void gdivz(GEN x, GEN y, GEN z)
    2492           0 : { pari_sp av = avma; gaffect(gdiv(x,y), z); avma = av; }
    2493           0 : INLINE void gdiventz(GEN x, GEN y, GEN z)
    2494           0 : { pari_sp av = avma; gaffect(gdivent(x,y), z); avma = av; }
    2495           0 : INLINE void gmodz(GEN x, GEN y, GEN z)
    2496           0 : { pari_sp av = avma; gaffect(gmod(x,y), z); avma = av; }
    2497           0 : INLINE void gmul2nz(GEN x, long s, GEN z)
    2498           0 : { pari_sp av = avma; gaffect(gmul2n(x,s), z); avma = av; }
    2499           0 : INLINE void gshiftz(GEN x, long s, GEN z)
    2500           0 : { pari_sp av = avma; gaffect(gshift(x,s), z); avma = av; }
    2501             : 
    2502             : /*******************************************************************/
    2503             : /*                                                                 */
    2504             : /*                       ELLIPTIC CURVES                           */
    2505             : /*                                                                 */
    2506             : /*******************************************************************/
    2507     5284895 : INLINE GEN ell_get_a1(GEN e) { return gel(e,1); }
    2508     3093263 : INLINE GEN ell_get_a2(GEN e) { return gel(e,2); }
    2509     4513419 : INLINE GEN ell_get_a3(GEN e) { return gel(e,3); }
    2510     3886097 : INLINE GEN ell_get_a4(GEN e) { return gel(e,4); }
    2511     4702780 : INLINE GEN ell_get_a6(GEN e) { return gel(e,5); }
    2512     3964637 : INLINE GEN ell_get_b2(GEN e) { return gel(e,6); }
    2513     1018683 : INLINE GEN ell_get_b4(GEN e) { return gel(e,7); }
    2514     1624869 : INLINE GEN ell_get_b6(GEN e) { return gel(e,8); }
    2515     1464197 : INLINE GEN ell_get_b8(GEN e) { return gel(e,9); }
    2516     5897304 : INLINE GEN ell_get_c4(GEN e) { return gel(e,10); }
    2517     7929144 : INLINE GEN ell_get_c6(GEN e) { return gel(e,11); }
    2518     9362792 : INLINE GEN ell_get_disc(GEN e) { return gel(e,12); }
    2519     1026081 : INLINE GEN ell_get_j(GEN e) { return gel(e,13); }
    2520     7906380 : INLINE long ell_get_type(GEN e) { return mael(e,14,1); }
    2521     1561487 : INLINE GEN ellff_get_field(GEN x) { return gmael(x, 15, 1); }
    2522      678309 : INLINE GEN ellff_get_a4a6(GEN x)  { return gmael(x, 15, 2); }
    2523         917 : INLINE GEN ellQp_get_zero(GEN x) { return gmael(x, 15, 1); }
    2524         287 : INLINE long ellQp_get_prec(GEN E) { GEN z = ellQp_get_zero(E); return valp(z); }
    2525         623 : INLINE GEN ellQp_get_p(GEN E) { GEN z = ellQp_get_zero(E); return gel(z,2); }
    2526       36960 : INLINE long ellR_get_prec(GEN x) { return nbits2prec(mael3(x, 15, 1, 1)); }
    2527        8262 : INLINE long ellR_get_sign(GEN x) { return mael3(x, 15, 1, 2); }
    2528      500353 : INLINE GEN ellnf_get_nf(GEN x) { return checknf_i(gmael(x,15,1)); }
    2529          49 : INLINE GEN ellnf_get_bnf(GEN x) { return checkbnf_i(gmael(x,15,1)); }
    2530             : 
    2531    21499333 : INLINE int ell_is_inf(GEN z) { return lg(z) == 2; }
    2532      787016 : INLINE GEN ellinf(void) { return mkvec(gen_0); }
    2533             : 
    2534             : /*******************************************************************/
    2535             : /*                                                                 */
    2536             : /*                    ALGEBRAIC NUMBER THEORY                      */
    2537             : /*                                                                 */
    2538             : /*******************************************************************/
    2539     8119836 : INLINE GEN modpr_get_pr(GEN x)  { return gel(x,3); }
    2540      609916 : INLINE GEN modpr_get_p(GEN x)  { return pr_get_p(modpr_get_pr(x)); }
    2541     2518408 : INLINE GEN modpr_get_T(GEN x)  { return lg(x) == 4? NULL: gel(x,4); }
    2542             : 
    2543    18290176 : INLINE GEN pr_get_p(GEN pr)  { return gel(pr,1); }
    2544     4846125 : INLINE GEN pr_get_gen(GEN pr){ return gel(pr,2); }
    2545             : /* .[2] instead of itos works: e and f are small positive integers */
    2546     2230750 : INLINE long pr_get_e(GEN pr) { return gel(pr,3)[2]; }
    2547     7787651 : INLINE long pr_get_f(GEN pr) { return gel(pr,4)[2]; }
    2548     5803107 : INLINE GEN pr_get_tau(GEN pr){ return gel(pr,5); }
    2549             : INLINE int
    2550     2346053 : pr_is_inert(GEN P) { return pr_get_f(P) == lg(pr_get_gen(P))-1; }
    2551             : INLINE GEN
    2552      204456 : pr_norm(GEN pr) { return powiu(pr_get_p(pr), pr_get_f(pr)); }
    2553             : INLINE ulong
    2554       40873 : upr_norm(GEN pr) { return upowuu(pr_get_p(pr)[2], pr_get_f(pr)); }
    2555             : 
    2556             : /* assume nf a genuine nf */
    2557             : INLINE long
    2558        4178 : nf_get_varn(GEN nf) { return varn(gel(nf,1)); }
    2559             : INLINE GEN
    2560    27063798 : nf_get_pol(GEN nf) { return gel(nf,1); }
    2561             : INLINE long
    2562    21250278 : nf_get_degree(GEN nf) { return degpol( nf_get_pol(nf) ); }
    2563             : INLINE long
    2564     1279808 : nf_get_r1(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,1)); }
    2565             : INLINE long
    2566        8197 : nf_get_r2(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,2)); }
    2567             : INLINE GEN
    2568       43854 : nf_get_disc(GEN nf) { return gel(nf,3); }
    2569             : INLINE GEN
    2570      745236 : nf_get_index(GEN nf) { return gel(nf,4); }
    2571             : INLINE GEN
    2572     1221669 : nf_get_M(GEN nf) { return gmael(nf,5,1); }
    2573             : INLINE GEN
    2574       60449 : nf_get_G(GEN nf) { return gmael(nf,5,2); }
    2575             : INLINE GEN
    2576      440110 : nf_get_roundG(GEN nf) { return gmael(nf,5,3); }
    2577             : INLINE GEN
    2578       24339 : nf_get_Tr(GEN nf) { return gmael(nf,5,4); }
    2579             : INLINE GEN
    2580        2191 : nf_get_diff(GEN nf) { return gmael(nf,5,5); }
    2581             : INLINE GEN
    2582          28 : nf_get_ramified_primes(GEN nf) { return gmael(nf,5,8); }
    2583             : INLINE GEN
    2584      152833 : nf_get_roots(GEN nf) { return gel(nf,6); }
    2585             : INLINE GEN
    2586          77 : nf_get_zk(GEN nf)
    2587             : {
    2588          77 :   GEN y = gel(nf,7), D = nf_get_zkden(nf);
    2589          77 :   if (!equali1(D)) y = gdiv(y, D);
    2590          77 :   return y;
    2591             : }
    2592             : INLINE GEN
    2593      217523 : nf_get_zkprimpart(GEN nf)
    2594             : {
    2595      217523 :   GEN y = gel(nf,7);
    2596             :   /* test for old format of nf.zk: non normalized */
    2597      217523 :   if (!equali1(gel(nf,4)) && gequal1(gel(y,1))) y = Q_remove_denom(y,NULL);
    2598      217523 :   return y;
    2599             : }
    2600             : INLINE GEN
    2601      220120 : nf_get_zkden(GEN nf)
    2602             : {
    2603      220120 :   GEN y = gel(nf,7), D = gel(y,1);
    2604      220120 :   if (typ(D) == t_POL) D = gel(D,2);
    2605             :   /* test for old format of nf.zk: non normalized */
    2606      220120 :   if (!equali1(gel(nf,4)) && equali1(D)) D = Q_denom(y);
    2607      220120 :   return D;
    2608             : }
    2609             : INLINE GEN
    2610     2167517 : nf_get_invzk(GEN nf) { return gel(nf,8); }
    2611             : INLINE void
    2612       13734 : nf_get_sign(GEN nf, long *r1, long *r2)
    2613             : {
    2614       13734 :   GEN x = gel(nf,2);
    2615       13734 :   *r1 = itou(gel(x,1));
    2616       13734 :   *r2 = itou(gel(x,2));
    2617       13734 : }
    2618             : 
    2619             : INLINE GEN
    2620       49616 : abgrp_get_no(GEN x) { return gel(x,1); }
    2621             : INLINE GEN
    2622     2033639 : abgrp_get_cyc(GEN x) { return gel(x,2); }
    2623             : INLINE GEN
    2624      396427 : abgrp_get_gen(GEN x) { return gel(x,3); }
    2625             : INLINE GEN
    2626     2063935 : bnf_get_nf(GEN bnf) { return gel(bnf,7); }
    2627             : INLINE GEN
    2628      806287 : bnf_get_clgp(GEN bnf) { return gmael(bnf,8,1); }
    2629             : INLINE GEN
    2630        4536 : bnf_get_no(GEN bnf) { return abgrp_get_no(bnf_get_clgp(bnf)); }
    2631             : INLINE GEN
    2632      434248 : bnf_get_cyc(GEN bnf) { return abgrp_get_cyc(bnf_get_clgp(bnf)); }
    2633             : INLINE GEN
    2634      367174 : bnf_get_gen(GEN bnf)  { return abgrp_get_gen(bnf_get_clgp(bnf)); }
    2635             : INLINE GEN
    2636         860 : bnf_get_reg(GEN bnf) { return gmael(bnf,8,2); }
    2637             : INLINE GEN
    2638      482157 : bnf_get_logfu(GEN bnf) { return gel(bnf,3); }
    2639             : INLINE GEN
    2640        5867 : bnf_get_tuU(GEN bnf) { return gmael3(bnf,8,4,2); }
    2641             : INLINE long
    2642       24535 : bnf_get_tuN(GEN bnf) { return gmael3(bnf,8,4,1)[2]; }
    2643             : INLINE GEN
    2644        1806 : bnf_get_fu(GEN bnf) {
    2645        1806 :   GEN fu = bnf_get_fu_nocheck(bnf);
    2646        1806 :   if (typ(fu) == t_MAT) pari_err(e_MISC,"missing units in bnf");
    2647        1806 :   return fu;
    2648             : }
    2649             : INLINE GEN
    2650        7134 : bnf_get_fu_nocheck(GEN bnf) { return gmael(bnf,8,5); }
    2651             : 
    2652             : INLINE GEN
    2653      747381 : bnr_get_bnf(GEN bnr) { return gel(bnr,1); }
    2654             : INLINE GEN
    2655      384460 : bnr_get_bid(GEN bnr) { return gel(bnr,2); }
    2656             : INLINE GEN
    2657       18102 : bnr_get_mod(GEN bnr) { return gmael(bnr,2,1); }
    2658             : INLINE GEN
    2659       27097 : bnr_get_nf(GEN bnr) { return gmael(bnr,1,7); }
    2660             : INLINE GEN
    2661      520526 : bnr_get_clgp(GEN bnr) { return gel(bnr,5); }
    2662             : INLINE GEN
    2663       45080 : bnr_get_no(GEN bnr) { return abgrp_get_no(bnr_get_clgp(bnr)); }
    2664             : INLINE GEN
    2665      463518 : bnr_get_cyc(GEN bnr) { return abgrp_get_cyc(bnr_get_clgp(bnr)); }
    2666             : INLINE GEN
    2667          70 : bnr_get_gen_nocheck(GEN bnr) { return abgrp_get_gen(bnr_get_clgp(bnr)); }
    2668             : INLINE GEN
    2669       11025 : bnr_get_gen(GEN bnr) {
    2670       11025 :   GEN G = bnr_get_clgp(bnr);
    2671       11025 :   if (lg(G) !=  4)
    2672           0 :     pari_err(e_MISC,"missing bnr generators: please use bnrinit(,,1)");
    2673       11025 :   return gel(G,3);
    2674             : }
    2675             : 
    2676             : INLINE GEN
    2677      302497 : bid_get_mod(GEN bid) { return gel(bid,1); }
    2678             : INLINE GEN
    2679       44968 : bid_get_ideal(GEN bid) { return gmael(bid,1,1); }
    2680             : INLINE GEN
    2681         448 : bid_get_arch(GEN bid) { return gmael(bid,1,2); }
    2682             : INLINE GEN
    2683     1061274 : bid_get_grp(GEN bid) { return gel(bid,2); }
    2684             : INLINE GEN
    2685      395905 : bid_get_fact(GEN bid) { return gmael(bid,3,1); }
    2686             : INLINE GEN
    2687      354605 : bid_get_fact2(GEN bid) { return gmael(bid,3,2); }
    2688             : INLINE GEN
    2689      354675 : bid_get_sprk(GEN bid) { return gmael(bid,4,1); }
    2690             : INLINE GEN
    2691       29813 : bid_get_sarch(GEN bid) { return gmael(bid,4,2); }
    2692             : INLINE GEN
    2693      375255 : bid_get_archp(GEN bid) { return gmael3(bid,4,2,2); }
    2694             : INLINE GEN
    2695      657382 : bid_get_U(GEN bid) { return gel(bid,5); }
    2696             : INLINE GEN
    2697           0 : bid_get_no(GEN bid) { return abgrp_get_no(bid_get_grp(bid)); }
    2698             : INLINE GEN
    2699     1032987 : bid_get_cyc(GEN bid) { return abgrp_get_cyc(bid_get_grp(bid)); }
    2700             : INLINE GEN
    2701           0 : bid_get_gen_nocheck(GEN bid)  { return abgrp_get_gen(bid_get_grp(bid)); }
    2702             : INLINE GEN
    2703       27692 : bid_get_gen(GEN bid) {
    2704       27692 :   GEN G = bid_get_grp(bid);
    2705       27692 :   if (lg(G) != 4) pari_err(e_MISC,"missing bid generators. Use idealstar(,,2)");
    2706       27692 :   return abgrp_get_gen(G);
    2707             : }
    2708             : 
    2709             : INLINE GEN
    2710     2522030 : znstar_get_N(GEN G) { return gmael(G,1,1); }
    2711             : INLINE GEN
    2712     2805866 : znstar_get_faN(GEN G) { return gel(G,3); }
    2713             : INLINE GEN
    2714           0 : znstar_get_no(GEN G) { return abgrp_get_no(gel(G,2)); }
    2715             : INLINE GEN
    2716      101472 : znstar_get_cyc(GEN G) { return abgrp_get_cyc(gel(G,2)); }
    2717             : INLINE GEN
    2718           0 : znstar_get_gen(GEN G) { return abgrp_get_gen(gel(G,2)); }
    2719             : INLINE GEN
    2720     2738365 : znstar_get_conreycyc(GEN G) { return gmael(G,4,5); }
    2721             : INLINE GEN
    2722     1263185 : znstar_get_conreygen(GEN G) { return gmael(G,4,4); }
    2723             : INLINE GEN
    2724       40103 : znstar_get_Ui(GEN G) { return gmael(G,4,3); }
    2725             : INLINE GEN
    2726       28322 : znstar_get_U(GEN G) { return gel(G,5); }
    2727             : INLINE GEN
    2728     1226309 : znstar_get_pe(GEN G) { return gmael(G,4,1); }
    2729             : INLINE GEN
    2730       19152 : gal_get_pol(GEN gal) { return gel(gal,1); }
    2731             : INLINE GEN
    2732        1225 : gal_get_p(GEN gal) { return gmael(gal,2,1); }
    2733             : INLINE GEN
    2734          63 : gal_get_e(GEN gal) { return gmael(gal,2,2); }
    2735             : INLINE GEN
    2736       15631 : gal_get_mod(GEN gal) { return gmael(gal,2,3); }
    2737             : INLINE GEN
    2738       16009 : gal_get_roots(GEN gal) { return gel(gal,3); }
    2739             : INLINE GEN
    2740       15631 : gal_get_invvdm(GEN gal) { return gel(gal,4); }
    2741             : INLINE GEN
    2742       15631 : gal_get_den(GEN gal) { return gel(gal,5); }
    2743             : INLINE GEN
    2744       61516 : gal_get_group(GEN gal) { return gel(gal,6); }
    2745             : INLINE GEN
    2746        3927 : gal_get_gen(GEN gal) { return gel(gal,7); }
    2747             : INLINE GEN
    2748        3577 : gal_get_orders(GEN gal) { return gel(gal,8); }
    2749             : 
    2750             : /* assume rnf a genuine rnf */
    2751             : INLINE long
    2752      311458 : rnf_get_degree(GEN rnf) { return degpol(rnf_get_pol(rnf)); }
    2753             : INLINE long
    2754       15169 : rnf_get_nfdegree(GEN rnf) { return degpol(nf_get_pol(rnf_get_nf(rnf))); }
    2755             : INLINE long
    2756      156499 : rnf_get_absdegree(GEN rnf) { return degpol(gmael(rnf,11,1)); }
    2757             : INLINE GEN
    2758         434 : rnf_get_idealdisc(GEN rnf) { return gmael(rnf,3,1); }
    2759             : INLINE GEN
    2760         448 : rnf_get_k(GEN rnf) { return gmael(rnf,11,3); }
    2761             : INLINE GEN
    2762         448 : rnf_get_alpha(GEN rnf) { return gmael(rnf, 11, 2); }
    2763             : INLINE GEN
    2764      126063 : rnf_get_nf(GEN rnf) { return gel(rnf,10); }
    2765             : INLINE void
    2766        2387 : rnf_get_nfzk(GEN rnf, GEN *b, GEN *cb) {*b=gmael(rnf,2,1); *cb=gmael(rnf,2,2);}
    2767             : INLINE GEN
    2768       95865 : rnf_get_polabs(GEN rnf) { return gmael(rnf,11,1); }
    2769             : INLINE GEN
    2770      463260 : rnf_get_pol(GEN rnf) { return gel(rnf,1); }
    2771             : INLINE GEN
    2772          63 : rnf_get_disc(GEN rnf) { return gel(rnf,3); }
    2773             : INLINE GEN
    2774         105 : rnf_get_index(GEN rnf) { return gel(rnf,4); }
    2775             : INLINE long
    2776           0 : rnf_get_varn(GEN rnf) { return varn(gel(rnf,1)); }
    2777             : INLINE GEN
    2778      106624 : rnf_get_nfpol(GEN rnf) { return gmael(rnf,10,1); }
    2779             : INLINE long
    2780         595 : rnf_get_nfvarn(GEN rnf) { return varn(gmael(rnf,10,1)); }
    2781             : INLINE GEN
    2782        2807 : rnf_get_zk(GEN rnf) { return gel(rnf,7); }
    2783             : INLINE GEN
    2784       34629 : rnf_get_map(GEN rnf) { return gel(rnf,11); }
    2785             : INLINE GEN
    2786        1190 : rnf_get_invzk(GEN rnf) { return gel(rnf,8); }
    2787             : 
    2788             : /* I integral ZM (not HNF), G ZM, rounded Cholesky form of a weighted
    2789             :  * T2 matrix. Reduce I wrt G */
    2790             : INLINE GEN
    2791       13048 : idealpseudored(GEN I, GEN G)
    2792       13048 : { return ZM_mul(I, ZM_lll(ZM_mul(G, I), 0.99, LLL_IM)); }
    2793             : 
    2794             : /* I integral (not necessarily HNF), G ZM, rounded Cholesky form of a weighted
    2795             :  * T2 matrix. Return m in I with T2(m) small */
    2796             : INLINE GEN
    2797      156926 : idealpseudomin(GEN I, GEN G)
    2798             : {
    2799      156926 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2800      156926 :   return ZM_ZC_mul(I, gel(u,1));
    2801             : }
    2802             : /* I, G as in idealpseudomin. Return an irrational m in I with T2(m) small */
    2803             : INLINE GEN
    2804      300359 : idealpseudomin_nonscalar(GEN I, GEN G)
    2805             : {
    2806      300359 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2807      300359 :   GEN m = ZM_ZC_mul(I, gel(u,1));
    2808      300359 :   if (ZV_isscalar(m) && lg(u) > 2) m = ZM_ZC_mul(I, gel(u,2));
    2809      300359 :   return m;
    2810             : }
    2811             : 
    2812             : INLINE GEN
    2813           0 : idealred_elt(GEN nf, GEN I) {
    2814           0 :   pari_sp av = avma;
    2815           0 :   GEN u = idealpseudomin(I, nf_get_roundG(nf));
    2816           0 :   return gerepileupto(av, u);
    2817             : }
    2818             : INLINE GEN
    2819      162624 : idealred(GEN nf, GEN I) { return idealred0(nf, I, NULL); }
    2820             : 
    2821             : INLINE GEN
    2822        1218 : idealchineseinit(GEN nf, GEN x)
    2823        1218 : { return idealchinese(nf,x,NULL); }
    2824             : 
    2825             : /*******************************************************************/
    2826             : /*                                                                 */
    2827             : /*                              CLOSURES                           */
    2828             : /*                                                                 */
    2829             : /*******************************************************************/
    2830   248142463 : INLINE long closure_arity(GEN C)          { return ((ulong)C[1])&ARITYBITS; }
    2831    34478829 : INLINE long closure_is_variadic(GEN C) { return !!(((ulong)C[1])&VARARGBITS); }
    2832   213428454 : INLINE const char *closure_codestr(GEN C)  { return GSTR(gel(C,2))-1; }
    2833           0 : INLINE GEN closure_get_code(GEN C)  { return gel(C,2); }
    2834   213371144 : INLINE GEN closure_get_oper(GEN C)  { return gel(C,3); }
    2835   213355907 : INLINE GEN closure_get_data(GEN C)  { return gel(C,4); }
    2836        8343 : INLINE GEN closure_get_dbg(GEN C)   { return gel(C,5); }
    2837       20235 : INLINE GEN closure_get_text(GEN C)  { return gel(C,6); }
    2838      479858 : INLINE GEN closure_get_frame(GEN C) { return gel(C,7); }
    2839             : 
    2840             : /*******************************************************************/
    2841             : /*                                                                 */
    2842             : /*                               ERRORS                            */
    2843             : /*                                                                 */
    2844             : /*******************************************************************/
    2845             : INLINE long
    2846       30302 : err_get_num(GEN e) { return e[1]; }
    2847             : INLINE GEN
    2848          70 : err_get_compo(GEN e, long i) { return gel(e, i+1); }
    2849             : 
    2850             : INLINE void
    2851          14 : pari_err_BUG(const char *f) { pari_err(e_BUG,f); }
    2852             : INLINE void
    2853           7 : pari_err_CONSTPOL(const char *f) { pari_err(e_CONSTPOL, f); }
    2854             : INLINE void
    2855          63 : pari_err_COPRIME(const char *f, GEN x, GEN y) { pari_err(e_COPRIME, f,x,y); }
    2856             : INLINE void
    2857         438 : pari_err_DIM(const char *f) { pari_err(e_DIM, f); }
    2858             : INLINE void
    2859           0 : pari_err_FILE(const char *f, const char *g) { pari_err(e_FILE, f,g); }
    2860             : INLINE void
    2861          28 : pari_err_FLAG(const char *f) { pari_err(e_FLAG,f); }
    2862             : INLINE void
    2863         371 : pari_err_IMPL(const char *f) { pari_err(e_IMPL,f); }
    2864             : INLINE void
    2865         698 : pari_err_INV(const char *f, GEN x) { pari_err(e_INV,f,x); }
    2866             : INLINE void
    2867          21 : pari_err_IRREDPOL(const char *f, GEN x) { pari_err(e_IRREDPOL, f,x); }
    2868             : INLINE void
    2869        1674 : 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); }
    2870             : INLINE void
    2871         245 : pari_err_COMPONENT(const char *f, const char *op, GEN l, GEN x) { pari_err(e_COMPONENT, f,op,l,x); }
    2872             : INLINE void
    2873           0 : pari_err_MAXPRIME(ulong c) { pari_err(e_MAXPRIME, c); }
    2874             : INLINE void
    2875         287 : pari_err_OP(const char *f, GEN x, GEN y) { pari_err(e_OP, f,x,y); }
    2876             : INLINE void
    2877          70 : pari_err_OVERFLOW(const char *f) { pari_err(e_OVERFLOW, f); }
    2878             : INLINE void
    2879         219 : pari_err_PREC(const char *f) { pari_err(e_PREC,f); }
    2880             : INLINE void
    2881           0 : pari_err_PACKAGE(const char *f) { pari_err(e_PACKAGE,f); }
    2882             : INLINE void
    2883          56 : pari_err_PRIME(const char *f, GEN x) { pari_err(e_PRIME, f,x); }
    2884             : INLINE void
    2885         735 : pari_err_MODULUS(const char *f, GEN x, GEN y) { pari_err(e_MODULUS, f,x,y); }
    2886             : INLINE void
    2887          42 : pari_err_ROOTS0(const char *f) { pari_err(e_ROOTS0, f); }
    2888             : INLINE void
    2889          77 : pari_err_SQRTN(const char *f, GEN x) { pari_err(e_SQRTN, f,x); }
    2890             : INLINE void
    2891       11334 : pari_err_TYPE(const char *f, GEN x) { pari_err(e_TYPE, f,x); }
    2892             : INLINE void
    2893        3045 : pari_err_TYPE2(const char *f, GEN x, GEN y) { pari_err(e_TYPE2, f,x,y); }
    2894             : INLINE void
    2895         203 : pari_err_VAR(const char *f, GEN x, GEN y) { pari_err(e_VAR, f,x,y); }
    2896             : INLINE void
    2897         126 : pari_err_PRIORITY(const char *f, GEN x, const char *op, long v)
    2898         126 : { pari_err(e_PRIORITY, f,x,op,v); }

Generated by: LCOV version 1.11