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.8.0 lcov report (development 19369-efd6c3d) Lines: 1192 1341 88.9 %
Date: 2016-08-29 06:11:50 Functions: 505 569 88.8 %
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 retmkintmod(x,y)\
      24             :   do { GEN _v = cgetg(3, t_INTMOD);\
      25             :        gel(_v,1) = (y);\
      26             :        gel(_v,2) = (x); return _v; } while(0)
      27             : #define retmkcomplex(x,y)\
      28             :   do { GEN _v = cgetg(3, t_COMPLEX);\
      29             :        gel(_v,1) = (x);\
      30             :        gel(_v,2) = (y); return _v; } while(0)
      31             : #define retmkpolmod(x,y)\
      32             :   do { GEN _v = cgetg(3, t_POLMOD);\
      33             :        gel(_v,1) = (y);\
      34             :        gel(_v,2) = (x); return _v; } while(0)
      35             : #define retmkvec(x)\
      36             :   do { GEN _v = cgetg(2, t_VEC);\
      37             :        gel(_v,1) = (x); return _v; } while(0)
      38             : #define retmkvec2(x,y)\
      39             :   do { GEN _v = cgetg(3, t_VEC);\
      40             :        gel(_v,1) = (x);\
      41             :        gel(_v,2) = (y); return _v; } while(0)
      42             : #define retmkvec3(x,y,z)\
      43             :   do { GEN _v = cgetg(4, t_VEC);\
      44             :        gel(_v,1) = (x);\
      45             :        gel(_v,2) = (y);\
      46             :        gel(_v,3) = (z); return _v; } while(0)
      47             : #define retmkqfi(x,y,z)\
      48             :   do { GEN _v = cgetg(4, t_QFI);\
      49             :        gel(_v,1) = (x);\
      50             :        gel(_v,2) = (y);\
      51             :        gel(_v,3) = (z); return _v; } while(0)
      52             : #define retmkqfr(x,y,z,d)\
      53             :   do { GEN _v = cgetg(5, t_QFR);\
      54             :        gel(_v,1) = (x);\
      55             :        gel(_v,2) = (y);\
      56             :        gel(_v,3) = (z);\
      57             :        gel(_v,4) = (d); return _v; } while(0)
      58             : #define retmkquad(x,y,z)\
      59             :   do { GEN _v = cgetg(4, t_QUAD);\
      60             :        gel(_v,1) = (x);\
      61             :        gel(_v,2) = (y);\
      62             :        gel(_v,3) = (z); return _v; } while(0)
      63             : #define retmkvec4(x,y,z,t)\
      64             :   do { GEN _v = cgetg(5, t_VEC);\
      65             :        gel(_v,1) = (x);\
      66             :        gel(_v,2) = (y);\
      67             :        gel(_v,3) = (z);\
      68             :        gel(_v,4) = (t); return _v; } while(0)
      69             : #define retmkvec5(x,y,z,t,u)\
      70             :   do { GEN _v = cgetg(6, t_VEC);\
      71             :        gel(_v,1) = (x);\
      72             :        gel(_v,2) = (y);\
      73             :        gel(_v,3) = (z);\
      74             :        gel(_v,4) = (t);\
      75             :        gel(_v,5) = (u); return _v; } while(0)
      76             : #define retmkcol(x)\
      77             :   do { GEN _v = cgetg(2, t_COL);\
      78             :        gel(_v,1) = (x); return _v; } while(0)
      79             : #define retmkcol2(x,y)\
      80             :   do { GEN _v = cgetg(3, t_COL);\
      81             :        gel(_v,1) = (x);\
      82             :        gel(_v,2) = (y); return _v; } while(0)
      83             : #define retmkcol3(x,y,z)\
      84             :   do { GEN _v = cgetg(4, t_COL);\
      85             :        gel(_v,1) = (x);\
      86             :        gel(_v,2) = (y);\
      87             :        gel(_v,3) = (z); return _v; } while(0)
      88             : #define retmkcol4(x,y,z,t)\
      89             :   do { GEN _v = cgetg(5, t_COL);\
      90             :        gel(_v,1) = (x);\
      91             :        gel(_v,2) = (y);\
      92             :        gel(_v,3) = (z);\
      93             :        gel(_v,4) = (t); return _v; } while(0)
      94             : #define retmkcol5(x,y,z,t,u)\
      95             :   do { GEN _v = cgetg(6, t_COL);\
      96             :        gel(_v,1) = (x);\
      97             :        gel(_v,2) = (y);\
      98             :        gel(_v,3) = (z);\
      99             :        gel(_v,4) = (t);\
     100             :        gel(_v,5) = (u); return _v; } while(0)
     101             : #define retmkcol6(x,y,z,t,u,v)\
     102             :   do { GEN _v = cgetg(7, t_COL);\
     103             :        gel(_v,1) = (x);\
     104             :        gel(_v,2) = (y);\
     105             :        gel(_v,3) = (z);\
     106             :        gel(_v,4) = (t);\
     107             :        gel(_v,5) = (u);\
     108             :        gel(_v,6) = (v); return _v; } while(0)
     109             : #define retmkmat(x)\
     110             :   do { GEN _v = cgetg(2, t_MAT);\
     111             :        gel(_v,1) = (x); return _v; } while(0)
     112             : #define retmkmat2(x,y)\
     113             :   do { GEN _v = cgetg(3, t_MAT);\
     114             :        gel(_v,1) = (x);\
     115             :        gel(_v,2) = (y); return _v; } while(0)
     116             : #define retmkmat3(x,y,z)\
     117             :   do { GEN _v = cgetg(4, t_MAT);\
     118             :        gel(_v,1) = (x);\
     119             :        gel(_v,2) = (y);\
     120             :        gel(_v,3) = (z); return _v; } while(0)
     121             : #define retmkmat4(x,y,z,t)\
     122             :   do { GEN _v = cgetg(5, t_MAT);\
     123             :        gel(_v,1) = (x);\
     124             :        gel(_v,2) = (y);\
     125             :        gel(_v,3) = (z);\
     126             :        gel(_v,4) = (t); return _v; } while(0)
     127             : #define retmkmat5(x,y,z,t,u)\
     128             :   do { GEN _v = cgetg(6, t_MAT);\
     129             :        gel(_v,1) = (x);\
     130             :        gel(_v,2) = (y);\
     131             :        gel(_v,3) = (z);\
     132             :        gel(_v,4) = (t);\
     133             :        gel(_v,5) = (u); return _v; } while(0)
     134             : 
     135             : INLINE GEN
     136      330864 : mkintmod(GEN x, GEN y) { retmkintmod(x,y); }
     137             : INLINE GEN
     138        3780 : mkintmodu(ulong x, ulong y) {
     139        3780 :   GEN v = cgetg(3,t_INTMOD);
     140        3780 :   gel(v,1) = utoipos(y);
     141        3780 :   gel(v,2) = utoi(x); return v;
     142             : }
     143             : INLINE GEN
     144      247966 : mkpolmod(GEN x, GEN y) { retmkpolmod(x,y); }
     145             : INLINE GEN
     146     1370524 : mkfrac(GEN x, GEN y) { retmkfrac(x,y); }
     147             : INLINE GEN
     148     2423783 : mkfraccopy(GEN x, GEN y) { retmkfrac(icopy(x), icopy(y)); }
     149             : INLINE GEN
     150        4984 : mkrfrac(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     151        4984 :   gel(v,1) = x; gel(v,2) = y; return v; }
     152             : INLINE GEN
     153          14 : mkrfraccopy(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     154          14 :   gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     155             : INLINE GEN
     156     2970936 : mkcomplex(GEN x, GEN y) { retmkcomplex(x,y); }
     157             : INLINE GEN
     158      425084 : gen_I(void) { return mkcomplex(gen_0, gen_1); }
     159             : INLINE GEN
     160      193758 : cgetc(long l) { retmkcomplex(cgetr(l), cgetr(l)); }
     161             : INLINE GEN
     162          42 : mkquad(GEN n, GEN x, GEN y) { GEN v = cgetg(4, t_QUAD);
     163          42 :   gel(v,1) = n; gel(v,2) = x; gel(v,3) = y; return v; }
     164             : /* vecsmall */
     165             : INLINE GEN
     166    47635704 : mkvecsmall(long x) { GEN v = cgetg(2, t_VECSMALL); v[1] = x; return v; }
     167             : INLINE GEN
     168   105600818 : mkvecsmall2(long x,long y) { GEN v = cgetg(3, t_VECSMALL);
     169   105605783 :   v[1]=x; v[2]=y; return v; }
     170             : INLINE GEN
     171    66030224 : mkvecsmall3(long x,long y,long z) { GEN v = cgetg(4, t_VECSMALL);
     172    66025755 :   v[1]=x; v[2]=y; v[3]=z; return v; }
     173             : INLINE GEN
     174     9503534 : mkvecsmall4(long x,long y,long z,long t) { GEN v = cgetg(5, t_VECSMALL);
     175     9498757 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; return v; }
     176             : INLINE GEN
     177      611369 : mkvecsmall5(long x,long y,long z,long t,long u) { GEN v = cgetg(6, t_VECSMALL);
     178      611369 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; v[5]=u; return v; }
     179             : 
     180             : INLINE GEN
     181      158123 : mkqfi(GEN x, GEN y, GEN z) { retmkqfi(x,y,z); }
     182             : /* vec */
     183             : INLINE GEN
     184     3203350 : mkvec(GEN x) { retmkvec(x); }
     185             : INLINE GEN
     186    20886362 : mkvec2(GEN x, GEN y) { retmkvec2(x,y); }
     187             : INLINE GEN
     188    65093981 : mkvec3(GEN x, GEN y, GEN z) { retmkvec3(x,y,z); }
     189             : INLINE GEN
     190     7280479 : mkvec4(GEN x, GEN y, GEN z, GEN t) { retmkvec4(x,y,z,t); }
     191             : INLINE GEN
     192    11755918 : mkvec5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkvec5(x,y,z,t,u); }
     193             : INLINE GEN
     194           7 : mkvecs(long x) { retmkvec(stoi(x)); }
     195             : INLINE GEN
     196       11564 : mkvec2s(long x, long y) { retmkvec2(stoi(x),stoi(y)); }
     197             : INLINE GEN
     198      492702 : mkvec3s(long x, long y, long z) { retmkvec3(stoi(x),stoi(y),stoi(z)); }
     199             : INLINE GEN
     200           7 : mkvec4s(long x, long y, long z, long t) { retmkvec4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     201             : INLINE GEN
     202       33187 : mkveccopy(GEN x) { GEN v = cgetg(2, t_VEC); gel(v,1) = gcopy(x); return v; }
     203             : INLINE GEN
     204      257744 : mkvec2copy(GEN x, GEN y) {
     205      257744 :   GEN v = cgetg(3,t_VEC); gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     206             : /* col */
     207             : INLINE GEN
     208     2142526 : mkcol(GEN x) { retmkcol(x); }
     209             : INLINE GEN
     210    14751125 : mkcol2(GEN x, GEN y) { retmkcol2(x,y); }
     211             : INLINE GEN
     212       41615 : mkcol3(GEN x, GEN y, GEN z) { retmkcol3(x,y,z); }
     213             : INLINE GEN
     214           0 : mkcol4(GEN x, GEN y, GEN z, GEN t) { retmkcol4(x,y,z,t); }
     215             : INLINE GEN
     216           0 : mkcol5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkcol5(x,y,z,t,u); }
     217             : INLINE GEN
     218         680 : mkcol6(GEN x, GEN y, GEN z, GEN t, GEN u, GEN v) { retmkcol6(x,y,z,t,u,v); }
     219             : INLINE GEN
     220        6202 : mkcols(long x) { retmkcol(stoi(x)); }
     221             : INLINE GEN
     222     1189972 : mkcol2s(long x, long y) { retmkcol2(stoi(x),stoi(y)); }
     223             : INLINE GEN
     224           0 : mkcol3s(long x, long y, long z) { retmkcol3(stoi(x),stoi(y),stoi(z)); }
     225             : INLINE GEN
     226           0 : mkcol4s(long x, long y, long z, long t) { retmkcol4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     227             : INLINE GEN
     228       27149 : mkcolcopy(GEN x) { GEN v = cgetg(2, t_COL); gel(v,1) = gcopy(x); return v; }
     229             : /* mat */
     230             : INLINE GEN
     231      559455 : mkmat(GEN x) { retmkmat(x); }
     232             : INLINE GEN
     233    16633729 : mkmat2(GEN x, GEN y) { retmkmat2(x,y); }
     234             : INLINE GEN
     235        2352 : mkmat3(GEN x, GEN y, GEN z) { retmkmat3(x,y,z); }
     236             : INLINE GEN
     237           0 : mkmat4(GEN x, GEN y, GEN z, GEN t) { retmkmat4(x,y,z,t); }
     238             : INLINE GEN
     239           0 : mkmat5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkmat5(x,y,z,t,u); }
     240             : INLINE GEN
     241        6020 : mkmatcopy(GEN x) { GEN v = cgetg(2, t_MAT); gel(v,1) = gcopy(x); return v; }
     242             : INLINE GEN
     243           0 : mkerr(long x) { GEN v = cgetg(2, t_ERROR); v[1] = x; return v; }
     244             : INLINE GEN
     245       11750 : mkoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_1; return v; }
     246             : INLINE GEN
     247        7322 : mkmoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_m1; return v; }
     248             : INLINE long
     249       25824 : inf_get_sign(GEN x) { return signe(gel(x,1)); }
     250             : /* pol */
     251             : INLINE GEN
     252      666384 : pol_x(long v) {
     253      666384 :   GEN p = cgetg(4, t_POL);
     254      666384 :   p[1] = evalsigne(1)|evalvarn(v);
     255      666384 :   gel(p,2) = gen_0;
     256      666384 :   gel(p,3) = gen_1; return p;
     257             : }
     258             : INLINE GEN
     259     1175715 : pol_1(long v) {
     260     1175715 :   GEN p = cgetg(3, t_POL);
     261     1175715 :   p[1] = evalsigne(1)|evalvarn(v);
     262     1175715 :   gel(p,2) = gen_1; return p;
     263             : }
     264             : INLINE GEN
     265    12947951 : pol_0(long v)
     266             : {
     267    12947951 :   GEN x = cgetg(2,t_POL);
     268    12947951 :   x[1] = evalvarn(v); return x;
     269             : }
     270             : #define retconst_vec(n,x)\
     271             :   do { long _i, _n = (n);\
     272             :        GEN _v = cgetg(_n+1, t_VEC), _x = (x);\
     273             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     274             :        return _v; } while(0)
     275             : INLINE GEN
     276    10579630 : const_vec(long n, GEN x) { retconst_vec(n, x); }
     277             : #define retconst_col(n,x)\
     278             :   do { long _i, _n = (n);\
     279             :        GEN _v = cgetg(_n+1, t_COL), _x = (x);\
     280             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     281             :        return _v; } while(0)
     282             : INLINE GEN
     283       24732 : const_col(long n, GEN x) { retconst_col(n, x); }
     284             : INLINE GEN
     285     5793421 : const_vecsmall(long n, long c)
     286             : {
     287             :   long i;
     288     5793421 :   GEN V = cgetg(n+1,t_VECSMALL);
     289     5793421 :   for(i=1;i<=n;i++) V[i] = c;
     290     5793421 :   return V;
     291             : }
     292             : 
     293             : /***   ZERO   ***/
     294             : /* O(p^e) */
     295             : INLINE GEN
     296      292264 : zeropadic(GEN p, long e)
     297             : {
     298      292264 :   GEN y = cgetg(5,t_PADIC);
     299      292264 :   gel(y,4) = gen_0;
     300      292264 :   gel(y,3) = gen_1;
     301      292264 :   gel(y,2) = icopy(p);
     302      292264 :   y[1] = evalvalp(e) | _evalprecp(0);
     303      292264 :   return y;
     304             : }
     305             : INLINE GEN
     306         329 : zeropadic_shallow(GEN p, long e)
     307             : {
     308         329 :   GEN y = cgetg(5,t_PADIC);
     309         329 :   gel(y,4) = gen_0;
     310         329 :   gel(y,3) = gen_1;
     311         329 :   gel(y,2) = p;
     312         329 :   y[1] = evalvalp(e) | _evalprecp(0);
     313         329 :   return y;
     314             : }
     315             : /* O(pol_x(v)^e) */
     316             : INLINE GEN
     317       12075 : zeroser(long v, long e)
     318             : {
     319       12075 :   GEN x = cgetg(2, t_SER);
     320       12075 :   x[1] = evalvalp(e) | evalvarn(v); return x;
     321             : }
     322             : INLINE int
     323     3809661 : ser_isexactzero(GEN x)
     324             : {
     325     3809661 :   if (!signe(x)) switch(lg(x))
     326             :   {
     327       10472 :     case 2: return 1;
     328         252 :     case 3: return isexactzero(gel(x,2));
     329             :   }
     330     3798937 :   return 0;
     331             : }
     332             : /* 0 * pol_x(v) */
     333             : INLINE GEN
     334     4209632 : zeropol(long v) { return pol_0(v); }
     335             : /* vector(n) */
     336             : INLINE GEN
     337    27909290 : zerocol(long n)
     338             : {
     339    27909290 :   GEN y = cgetg(n+1,t_COL);
     340    27909290 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     341    27909290 :   return y;
     342             : }
     343             : /* vectorv(n) */
     344             : INLINE GEN
     345     7896891 : zerovec(long n)
     346             : {
     347     7896891 :   GEN y = cgetg(n+1,t_VEC);
     348     7896891 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     349     7896891 :   return y;
     350             : }
     351             : /* matrix(m, n) */
     352             : INLINE GEN
     353        6419 : zeromat(long m, long n)
     354             : {
     355        6419 :   GEN y = cgetg(n+1,t_MAT);
     356        6419 :   GEN v = zerocol(m);
     357        6419 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     358        6419 :   return y;
     359             : }
     360             : /* = zero_zx, sv is a evalvarn()*/
     361             : INLINE GEN
     362      290871 : zero_Flx(long sv) { return pol0_Flx(sv); }
     363             : INLINE GEN
     364    28136178 : zero_Flv(long n)
     365             : {
     366    28136178 :   GEN y = cgetg(n+1,t_VECSMALL);
     367    28136169 :   long i; for (i=1; i<=n; i++) y[i] = 0;
     368    28136169 :   return y;
     369             : }
     370             : /* matrix(m, n) */
     371             : INLINE GEN
     372         175 : zero_Flm(long m, long n)
     373             : {
     374         175 :   GEN y = cgetg(n+1,t_MAT);
     375         175 :   GEN v = zero_Flv(m);
     376         175 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     377         175 :   return y;
     378             : }
     379             : /* matrix(m, n) */
     380             : INLINE GEN
     381      103746 : zero_Flm_copy(long m, long n)
     382             : {
     383      103746 :   GEN y = cgetg(n+1,t_MAT);
     384      103756 :   long i; for (i=1; i<=n; i++) gel(y,i) = zero_Flv(m);
     385      103751 :   return y;
     386             : }
     387             : 
     388             : INLINE GEN
     389      577179 : zero_F2v(long m)
     390             : {
     391      577179 :   long l = nbits2nlong(m);
     392      577179 :   GEN v  = zero_Flv(l+1);
     393      577179 :   v[1] = m;
     394      577179 :   return v;
     395             : }
     396             : 
     397             : INLINE GEN
     398           0 : zero_F2m(long m, long n)
     399             : {
     400             :   long i;
     401           0 :   GEN M = cgetg(n+1, t_MAT);
     402           0 :   GEN v = zero_F2v(m);
     403           0 :   for (i = 1; i <= n; i++)
     404           0 :     gel(M,i) = v;
     405           0 :   return M;
     406             : }
     407             : 
     408             : 
     409             : INLINE GEN
     410      103443 : zero_F2m_copy(long m, long n)
     411             : {
     412             :   long i;
     413      103443 :   GEN M = cgetg(n+1, t_MAT);
     414      437428 :   for (i = 1; i <= n; i++)
     415      333985 :     gel(M,i)= zero_F2v(m);
     416      103443 :   return M;
     417             : }
     418             : 
     419             : /* matrix(m, n) */
     420             : INLINE GEN
     421     2236400 : zeromatcopy(long m, long n)
     422             : {
     423     2236400 :   GEN y = cgetg(n+1,t_MAT);
     424     2236400 :   long i; for (i=1; i<=n; i++) gel(y,i) = zerocol(m);
     425     2236400 :   return y;
     426             : }
     427             : 
     428             : /* i-th vector in the standard basis */
     429             : INLINE GEN
     430     2261688 : col_ei(long n, long i) { GEN e = zerocol(n); gel(e,i) = gen_1; return e; }
     431             : INLINE GEN
     432      300959 : vec_ei(long n, long i) { GEN e = zerovec(n); gel(e,i) = gen_1; return e; }
     433             : INLINE GEN
     434           7 : F2v_ei(long n, long i) { GEN e = zero_F2v(n); F2v_set(e,i); return e; }
     435             : INLINE GEN
     436        9170 : vecsmall_ei(long n, long i) { GEN e = zero_zv(n); e[i] = 1; return e; }
     437             : INLINE GEN
     438     3930294 : Rg_col_ei(GEN x, long n, long i) { GEN e = zerocol(n); gel(e,i) = x; return e; }
     439             : 
     440             : INLINE GEN
     441     1496902 : shallowcopy(GEN x)
     442     1496902 : { return typ(x) == t_MAT ? RgM_shallowcopy(x): leafcopy(x); }
     443             : 
     444             : /* routines for naive growarrays */
     445             : INLINE GEN
     446    11521951 : vectrunc_init(long l)
     447             : {
     448    11521951 :   GEN z = new_chunk(l);
     449    11522504 :   z[0] = evaltyp(t_VEC) | _evallg(1); return z;
     450             : }
     451             : INLINE void
     452    43058840 : vectrunc_append(GEN x, GEN t)
     453    43058840 : { long l = lg(x); gel(x,l) = t; setlg(x, l+1); }
     454             : INLINE void
     455           0 : vectrunc_append_batch(GEN x, GEN y)
     456             : {
     457           0 :   long i, l = lg(x), ly = lg(y);
     458           0 :   GEN z = x + l-1;
     459           0 :   for (i = 1; i < ly; i++) gel(z,i) = gel(y,i);
     460           0 :   setlg(x, l+ly-1);
     461           0 : }
     462             : INLINE GEN
     463     1303481 : vecsmalltrunc_init(long l)
     464             : {
     465     1303481 :   GEN z = new_chunk(l);
     466     1303481 :   z[0] = evaltyp(t_VECSMALL) | _evallg(1); return z;
     467             : }
     468             : INLINE void
     469     2568437 : vecsmalltrunc_append(GEN x, long t)
     470     2568437 : { long l = lg(x); x[l] = t; setlg(x, l+1); }
     471             : 
     472             : /*******************************************************************/
     473             : /*                                                                 */
     474             : /*                        VEC / COL / VECSMALL                     */
     475             : /*                                                                 */
     476             : /*******************************************************************/
     477             : /* shallow*/
     478             : INLINE GEN
     479           0 : vec_shorten(GEN v, long n)
     480             : {
     481             :   long i;
     482           0 :   GEN V = cgetg(n+1,t_VEC);
     483           0 :   for(i=1;i<=n;i++) gel(V,i) = gel(v,i);
     484           0 :   return V;
     485             : }
     486             : /* shallow*/
     487             : INLINE GEN
     488       10584 : vec_lengthen(GEN v, long n)
     489             : {
     490             :   long i;
     491       10584 :   long l=lg(v);
     492       10584 :   GEN V = cgetg(n+1,t_VEC);
     493       10584 :   for(i=1;i<l;i++) gel(V,i) = gel(v,i);
     494       10584 :   return V;
     495             : }
     496             : /* shallow*/
     497             : INLINE GEN
     498       56021 : vec_append(GEN V, GEN s)
     499             : {
     500       56021 :   long i, l2 = lg(V);
     501       56021 :   GEN res = cgetg(l2+1, typ(V));
     502       56021 :   for (i = 1; i < l2; ++i) gel(res, i) = gel(V,i);
     503       56021 :   gel(res,l2) = s; return res;
     504             : }
     505             : /* shallow*/
     506             : INLINE GEN
     507        1729 : vec_setconst(GEN v, GEN x)
     508             : {
     509        1729 :   long i, l = lg(v);
     510        1729 :   for (i = 1; i < l; i++) gel(v,i) = x;
     511        1729 :   return v;
     512             : }
     513             : INLINE GEN
     514      132855 : vecsmall_shorten(GEN v, long n)
     515             : {
     516             :   long i;
     517      132855 :   GEN V = cgetg(n+1,t_VECSMALL);
     518      132858 :   for(i=1;i<=n;i++) V[i] = v[i];
     519      132858 :   return V;
     520             : }
     521             : INLINE GEN
     522          21 : vecsmall_lengthen(GEN v, long n)
     523             : {
     524          21 :   long i, l = lg(v);
     525          21 :   GEN V = cgetg(n+1,t_VECSMALL);
     526          21 :   for(i=1;i<l;i++) V[i] = v[i];
     527          21 :   return V;
     528             : }
     529             : 
     530             : INLINE GEN
     531      235107 : vec_to_vecsmall(GEN z)
     532             : {
     533      235107 :   long i, l = lg(z);
     534      235107 :   GEN x = cgetg(l, t_VECSMALL);
     535      235107 :   for (i=1; i<l; i++) x[i] = itos(gel(z,i));
     536      235107 :   return x;
     537             : }
     538             : INLINE GEN
     539       15239 : vecsmall_to_vec(GEN z)
     540             : {
     541       15239 :   long i, l = lg(z);
     542       15239 :   GEN x = cgetg(l,t_VEC);
     543       15239 :   for (i=1; i<l; i++) gel(x,i) = stoi(z[i]);
     544       15239 :   return x;
     545             : }
     546             : INLINE GEN
     547     1128234 : vecsmall_to_col(GEN z)
     548             : {
     549     1128234 :   long i, l = lg(z);
     550     1128234 :   GEN x = cgetg(l,t_COL);
     551     1128234 :   for (i=1; i<l; i++) gel(x,i) = stoi(z[i]);
     552     1128234 :   return x;
     553             : }
     554             : 
     555             : INLINE int
     556     2763075 : vecsmall_lexcmp(GEN x, GEN y)
     557             : {
     558             :   long lx,ly,l,i;
     559     2763075 :   lx = lg(x);
     560     2763075 :   ly = lg(y); l = minss(lx,ly);
     561    15179787 :   for (i=1; i<l; i++)
     562    14495488 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     563      684299 :   if (lx == ly) return 0;
     564           0 :   return (lx < ly)? -1 : 1;
     565             : }
     566             : 
     567             : INLINE int
     568    47066978 : vecsmall_prefixcmp(GEN x, GEN y)
     569             : {
     570    47066978 :   long i, lx = lg(x), ly = lg(y), l = minss(lx,ly);
     571   148811348 :   for (i=1; i<l; i++)
     572   134951817 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     573    13859531 :   return 0;
     574             : }
     575             : 
     576             : /*Can be used on t_VEC, but coeffs not gcopy-ed*/
     577             : INLINE GEN
     578        1127 : vecsmall_prepend(GEN V, long s)
     579             : {
     580        1127 :   long i, l2 = lg(V);
     581        1127 :   GEN res = cgetg(l2+1, typ(V));
     582        1127 :   res[1] = s;
     583        1127 :   for (i = 2; i <= l2; ++i) res[i] = V[i - 1];
     584        1127 :   return res;
     585             : }
     586             : 
     587             : INLINE GEN
     588      356748 : vecsmall_append(GEN V, long s)
     589             : {
     590      356748 :   long i, l2 = lg(V);
     591      356748 :   GEN res = cgetg(l2+1, t_VECSMALL);
     592      356748 :   for (i = 1; i < l2; ++i) res[i] = V[i];
     593      356748 :   res[l2] = s; return res;
     594             : }
     595             : 
     596             : INLINE GEN
     597      235116 : vecsmall_concat(GEN u, GEN v)
     598             : {
     599      235116 :   long i, l1 = lg(u)-1, l2 = lg(v)-1;
     600      235116 :   GEN res = cgetg(l1+l2+1, t_VECSMALL);
     601      235116 :   for (i = 1; i <= l1; ++i) res[i]    = u[i];
     602      235116 :   for (i = 1; i <= l2; ++i) res[i+l1] = v[i];
     603      235116 :   return res;
     604             : }
     605             : 
     606             : /* return the number of indices where u and v are equal */
     607             : INLINE long
     608           0 : vecsmall_coincidence(GEN u, GEN v)
     609             : {
     610           0 :   long i, s = 0, l = minss(lg(u),lg(v));
     611           0 :   for(i=1; i<l; i++)
     612           0 :     if(u[i] == v[i]) s++;
     613           0 :   return s;
     614             : }
     615             : 
     616             : /* returns the first index i<=n such that x=v[i] if it exists, 0 otherwise */
     617             : INLINE long
     618           0 : vecsmall_isin(GEN v, long x)
     619             : {
     620           0 :   long i, l = lg(v);
     621           0 :   for (i = 1; i < l; i++)
     622           0 :     if (v[i] == x) return i;
     623           0 :   return 0;
     624             : }
     625             : 
     626             : INLINE long
     627          84 : vecsmall_pack(GEN V, long base, long mod)
     628             : {
     629          84 :   long i, s = 0;
     630          84 :   for(i=1; i<lg(V); i++) s = (base*s + V[i]) % mod;
     631          84 :   return s;
     632             : }
     633             : 
     634             : INLINE long
     635          14 : vecsmall_indexmax(GEN x)
     636             : {
     637          14 :   long i, i0 = 1, t = x[1], lx = lg(x);
     638          56 :   for (i=2; i<lx; i++)
     639          42 :     if (x[i] > t) t = x[i0=i];
     640          14 :   return i0;
     641             : }
     642             : 
     643             : INLINE long
     644       35732 : vecsmall_max(GEN x)
     645             : {
     646       35732 :   long i, t = x[1], lx = lg(x);
     647       61160 :   for (i=2; i<lx; i++)
     648       25428 :     if (x[i] > t) t = x[i];
     649       35732 :   return t;
     650             : }
     651             : 
     652             : INLINE long
     653          14 : vecsmall_indexmin(GEN x)
     654             : {
     655          14 :   long i, i0 = 1, t = x[1], lx =lg(x);
     656          56 :   for (i=2; i<lx; i++)
     657          42 :     if (x[i] < t) t = x[i0=i];
     658          14 :   return i0;
     659             : }
     660             : 
     661             : INLINE long
     662         133 : vecsmall_min(GEN x)
     663             : {
     664         133 :   long i, t = x[1], lx =lg(x);
     665         959 :   for (i=2; i<lx; i++)
     666         826 :     if (x[i] < t) t = x[i];
     667         133 :   return t;
     668             : }
     669             : 
     670             : INLINE int
     671     1927246 : ZV_isscalar(GEN x)
     672             : {
     673     1927246 :   long l = lg(x);
     674     7175526 :   while (--l > 1)
     675     4866411 :     if (signe(gel(x, l))) return 0;
     676      381869 :   return 1;
     677             : }
     678             : INLINE int
     679     8039032 : QV_isscalar(GEN x)
     680             : {
     681     8039032 :   long lx = lg(x),i;
     682    10242379 :   for (i=2; i<lx; i++)
     683     9628146 :     if (!isintzero(gel(x, i))) return 0;
     684      614233 :   return 1;
     685             : }
     686             : INLINE int
     687        4573 : RgV_isscalar(GEN x)
     688             : {
     689        4573 :   long lx = lg(x),i;
     690        7660 :   for (i=2; i<lx; i++)
     691        6498 :     if (!gequal0(gel(x, i))) return 0;
     692        1162 :   return 1;
     693             : }
     694             : INLINE int
     695           0 : RgX_isscalar(GEN x)
     696             : {
     697             :   long i;
     698           0 :   for (i=lg(x)-1; i>2; i--)
     699           0 :     if (!gequal0(gel(x, i))) return 0;
     700           0 :   return 1;
     701             : }
     702             : INLINE long
     703     4044777 : RgX_equal_var(GEN x, GEN y) { return varn(x) == varn(y) && RgX_equal(x,y); }
     704             : 
     705             : INLINE int
     706        2688 : RgX_is_rational(GEN x)
     707             : {
     708             :   long i;
     709       24759 :   for (i = lg(x)-1; i > 1; i--)
     710       23303 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     711        1456 :   return 1;
     712             : }
     713             : INLINE int
     714    55150536 : RgX_is_ZX(GEN x)
     715             : {
     716             :   long i;
     717   246750220 :   for (i = lg(x)-1; i > 1; i--)
     718   196814044 :     if (typ(gel(x,i)) != t_INT) return 0;
     719    49936176 :   return 1;
     720             : }
     721             : INLINE int
     722      161536 : RgX_is_QX(GEN x)
     723             : {
     724      161536 :   long k = lg(x)-1;
     725      633327 :   for ( ; k>1; k--)
     726      472645 :     if (!is_rational_t(typ(gel(x,k)))) return 0;
     727      160682 :   return 1;
     728             : }
     729             : INLINE int
     730    15102767 : RgX_is_monomial(GEN x)
     731             : {
     732             :   long i;
     733    15102767 :   if (!signe(x)) return 0;
     734    24281663 :   for (i=lg(x)-2; i>1; i--)
     735    16781419 :     if (!isexactzero(gel(x,i))) return 0;
     736     7500244 :   return 1;
     737             : }
     738             : INLINE int
     739     2443208 : RgV_is_ZV(GEN x)
     740             : {
     741             :   long i;
     742     8657627 :   for (i = lg(x)-1; i > 0; i--)
     743     6215084 :     if (typ(gel(x,i)) != t_INT) return 0;
     744     2442543 :   return 1;
     745             : }
     746             : INLINE int
     747         147 : RgV_is_QV(GEN x)
     748             : {
     749             :   long i;
     750         413 :   for (i = lg(x)-1; i > 0; i--)
     751         280 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     752         133 :   return 1;
     753             : }
     754             : 
     755             : /********************************************************************/
     756             : /**                                                                **/
     757             : /**            Dynamic arrays implementation                       **/
     758             : /**                                                                **/
     759             : /********************************************************************/
     760             : INLINE void **
     761   333113664 : pari_stack_base(pari_stack *s) { return s->data; }
     762             : 
     763             : INLINE void
     764     2957887 : pari_stack_init(pari_stack *s, size_t size, void **data)
     765             : {
     766     2957887 :   s->data = data;
     767     2957887 :   *data = NULL;
     768     2957887 :   s->n = 0;
     769     2957887 :   s->alloc = 0;
     770     2957887 :   s->size = size;
     771     2957887 : }
     772             : 
     773             : INLINE void
     774   330487991 : pari_stack_alloc(pari_stack *s, long nb)
     775             : {
     776   330487991 :   void **sdat = pari_stack_base(s);
     777   661173605 :   if (s->n+nb <= s->alloc) return;
     778      793229 :   if (!s->alloc)
     779      748871 :     s->alloc = nb;
     780             :   else
     781             :   {
     782       44358 :     while (s->n+nb > s->alloc) s->alloc <<= 1;
     783             :   }
     784      793229 :   *sdat = pari_realloc(*sdat,s->alloc*s->size);
     785             : }
     786             : 
     787             : INLINE long
     788   276658292 : pari_stack_new(pari_stack *s) { pari_stack_alloc(s, 1); return s->n++; }
     789             : 
     790             : INLINE void
     791     2543943 : pari_stack_delete(pari_stack *s)
     792             : {
     793     2543943 :   void **sdat = pari_stack_base(s);
     794     2544637 :   if (*sdat) pari_free(*sdat);
     795     2545039 : }
     796             : 
     797             : INLINE void
     798        5481 : pari_stack_pushp(pari_stack *s, void *u)
     799             : {
     800        5481 :   long n = pari_stack_new(s);
     801        5481 :   void **sdat =(void**) *pari_stack_base(s);
     802        5481 :   sdat[n] = u;
     803        5481 : }
     804             : 
     805             : /*******************************************************************/
     806             : /*                                                                 */
     807             : /*                            EXTRACT                              */
     808             : /*                                                                 */
     809             : /*******************************************************************/
     810             : INLINE GEN
     811     4302708 : vecslice(GEN A, long y1, long y2)
     812             : {
     813     4302708 :   long i,lB = y2 - y1 + 2;
     814     4302708 :   GEN B = cgetg(lB, typ(A));
     815     4302708 :   for (i=1; i<lB; i++) B[i] = A[y1-1+i];
     816     4302708 :   return B;
     817             : }
     818             : INLINE GEN
     819      133630 : vecslicepermute(GEN A, GEN p, long y1, long y2)
     820             : {
     821      133630 :   long i,lB = y2 - y1 + 2;
     822      133630 :   GEN B = cgetg(lB, typ(A));
     823      133630 :   for (i=1; i<lB; i++) B[i] = A[p[y1-1+i]];
     824      133630 :   return B;
     825             : }
     826             : /* rowslice(rowpermute(A,p), x1, x2) */
     827             : INLINE GEN
     828       33462 : rowslicepermute(GEN A, GEN p, long x1, long x2)
     829             : {
     830       33462 :   long i, lB = lg(A);
     831       33462 :   GEN B = cgetg(lB, typ(A));
     832       33462 :   for (i=1; i<lB; i++) gel(B,i) = vecslicepermute(gel(A,i),p,x1,x2);
     833       33462 :   return B;
     834             : }
     835             : INLINE GEN
     836      187422 : rowslice(GEN A, long x1, long x2)
     837             : {
     838      187422 :   long i, lB = lg(A);
     839      187422 :   GEN B = cgetg(lB, typ(A));
     840      187422 :   for (i=1; i<lB; i++) gel(B,i) = vecslice(gel(A,i),x1,x2);
     841      187422 :   return B;
     842             : }
     843             : 
     844             : INLINE GEN
     845      102389 : matslice(GEN A, long x1, long x2, long y1, long y2)
     846             : {
     847      102389 :   return rowslice(vecslice(A, y1, y2), x1, x2);
     848             : }
     849             : 
     850             : /* shallow, remove coeff of index j */
     851             : INLINE GEN
     852        8610 : vecsplice(GEN a, long j)
     853             : {
     854        8610 :   long i, k, l = lg(a);
     855             :   GEN b;
     856        8610 :   if (l == 1) pari_err(e_MISC, "incorrect component in vecsplice");
     857        8610 :   b = cgetg(l-1, typ(a));
     858       47684 :   for (i = k = 1; i < l; i++)
     859       39074 :     if (i != j) gel(b, k++) = gel(a,i);
     860        8610 :   return b;
     861             : }
     862             : /* shallow */
     863             : INLINE GEN
     864        1008 : RgM_minor(GEN a, long i, long j)
     865             : {
     866        1008 :   GEN b = vecsplice(a, j);
     867        1008 :   long k, l = lg(b);
     868        1008 :   for (k = 1; k < l; k++) gel(b,k) = vecsplice(gel(b,k), i);
     869        1008 :   return b;
     870             : }
     871             : 
     872             : /* A[x0,] */
     873             : INLINE GEN
     874      115625 : row(GEN A, long x0)
     875             : {
     876      115625 :   long i, lB = lg(A);
     877      115625 :   GEN B  = cgetg(lB, t_VEC);
     878      115625 :   for (i=1; i<lB; i++) gel(B, i) = gcoeff(A, x0, i);
     879      115625 :   return B;
     880             : }
     881             : INLINE GEN
     882       23399 : Flm_row(GEN A, long x0)
     883             : {
     884       23399 :   long i, lB = lg(A);
     885       23399 :   GEN B  = cgetg(lB, t_VECSMALL);
     886       23395 :   for (i=1; i<lB; i++) B[i] = coeff(A, x0, i);
     887       23395 :   return B;
     888             : }
     889             : /* A[x0,] */
     890             : INLINE GEN
     891          56 : rowcopy(GEN A, long x0)
     892             : {
     893          56 :   long i, lB = lg(A);
     894          56 :   GEN B  = cgetg(lB, t_VEC);
     895          56 :   for (i=1; i<lB; i++) gel(B, i) = gcopy(gcoeff(A, x0, i));
     896          56 :   return B;
     897             : }
     898             : /* A[x0, x1..x2] */
     899             : INLINE GEN
     900        2177 : row_i(GEN A, long x0, long x1, long x2)
     901             : {
     902        2177 :   long i, lB = x2 - x1 + 2;
     903        2177 :   GEN B  = cgetg(lB, t_VEC);
     904        2177 :   for (i=x1; i<=x2; i++) gel(B, i) = gcoeff(A, x0, i);
     905        2177 :   return B;
     906             : }
     907             : 
     908             : INLINE GEN
     909     4759623 : vecreverse(GEN A)
     910             : {
     911             :   long i, l;
     912     4759623 :   GEN B = cgetg_copy(A, &l);
     913     4759623 :   for (i=1; i<l; i++) gel(B, i) = gel(A, l-i);
     914     4759623 :   return B;
     915             : }
     916             : 
     917             : INLINE GEN
     918         252 : vecsmall_reverse(GEN A)
     919             : {
     920             :   long i, l;
     921         252 :   GEN B = cgetg_copy(A, &l);
     922         252 :   for (i=1; i<l; i++) B[i] = A[l-i];
     923         252 :   return B;
     924             : }
     925             : 
     926             : INLINE void
     927         232 : vecreverse_inplace(GEN y)
     928             : {
     929         232 :   long ly = lg(y), lim = ly>>1, i;
     930         640 :   for (i = 1; i <= lim; i++)
     931             :   {
     932         408 :     GEN z = gel(y,i);
     933         408 :     gel(y,i)    = gel(y,ly-i);
     934         408 :     gel(y,ly-i) = z;
     935             :   }
     936         232 : }
     937             : 
     938             : INLINE GEN
     939    20073805 : vecsmallpermute(GEN A, GEN p) { return perm_mul(A, p); }
     940             : 
     941             : INLINE GEN
     942     4901988 : vecpermute(GEN A, GEN p)
     943             : {
     944     4901988 :   long i,lB = lg(p);
     945     4901988 :   GEN B = cgetg(lB, typ(A));
     946     4901988 :   for (i=1; i<lB; i++) gel(B, i) = gel(A, p[i]);
     947     4901988 :   return B;
     948             : }
     949             : INLINE GEN
     950      198737 : rowpermute(GEN A, GEN p)
     951             : {
     952      198737 :   long i, lB = lg(A);
     953      198737 :   GEN B = cgetg(lB, typ(A));
     954     2111189 :   for (i=1; i<lB; i++)
     955     3786453 :     gel(B, i) = typ(gel(A,i)) == t_VECSMALL ? vecsmallpermute(gel(A, i), p):
     956     1874001 :                                                     vecpermute(gel(A, i), p);
     957      198737 :   return B;
     958             : }
     959             : /*******************************************************************/
     960             : /*                                                                 */
     961             : /*                          PERMUTATIONS                           */
     962             : /*                                                                 */
     963             : /*******************************************************************/
     964             : /* identity permutation */
     965             : INLINE GEN
     966       66605 : identity_perm(long n)
     967             : {
     968       66605 :   GEN perm = cgetg(n+1, t_VECSMALL);
     969             :   long i;
     970       66605 :   for (i = 1; i <= n; i++) perm[i] = i;
     971       66605 :   return perm;
     972             : }
     973             : 
     974             : /* assume d <= n */
     975             : INLINE GEN
     976           0 : cyclic_perm(long n, long d)
     977             : {
     978           0 :   GEN perm = cgetg(n+1, t_VECSMALL);
     979             :   long i;
     980           0 :   for (i = 1; i <= n-d; i++) perm[i] = i+d;
     981           0 :   for (     ; i <= n;   i++) perm[i] = i-n+d;
     982           0 :   return perm;
     983             : }
     984             : 
     985             : /* Multiply (compose) two permutations */
     986             : INLINE GEN
     987    20490837 : perm_mul(GEN s, GEN t)
     988             : {
     989             :   GEN u;
     990    20490837 :   long i, l = lg(t);
     991    20490837 :   u = cgetg(l, t_VECSMALL);
     992    20490837 :   for (i = 1; i < l; i++) u[i] = s[ t[i] ];
     993    20490837 :   return u;
     994             : }
     995             : /* Compute the inverse (reciprocal) of a permutation. */
     996             : INLINE GEN
     997        3815 : perm_inv(GEN x)
     998             : {
     999             :   long i, lx;
    1000        3815 :   GEN y = cgetg_copy(x, &lx);
    1001        3815 :   for (i=1; i<lx; i++) y[ x[i] ] = i;
    1002        3815 :   return y;
    1003             : }
    1004             : /* Return s*t*s^-1 */
    1005             : INLINE GEN
    1006          35 : perm_conj(GEN s, GEN t)
    1007             : {
    1008             :   long i, l;
    1009          35 :   GEN v = cgetg_copy(s, &l);
    1010          35 :   for (i = 1; i < l; i++) v[ s[i] ] = s[ t[i] ];
    1011          35 :   return v;
    1012             : }
    1013             : 
    1014             : /*********************************************************************/
    1015             : /*                       MALLOC/FREE WRAPPERS                        */
    1016             : /*********************************************************************/
    1017             : #define BLOCK_SIGALRM_START          \
    1018             : {                                    \
    1019             :   int block=PARI_SIGINT_block;       \
    1020             :   PARI_SIGINT_block = 2;             \
    1021             :   MT_SIGINT_BLOCK(block);
    1022             : 
    1023             : #define BLOCK_SIGINT_START           \
    1024             : {                                    \
    1025             :   int block=PARI_SIGINT_block;       \
    1026             :   PARI_SIGINT_block = 1;             \
    1027             :   MT_SIGINT_BLOCK(block);
    1028             : 
    1029             : #define BLOCK_SIGINT_END             \
    1030             :   PARI_SIGINT_block = block;         \
    1031             :   MT_SIGINT_UNBLOCK(block);          \
    1032             :   if (!block && PARI_SIGINT_pending) \
    1033             :   {                                  \
    1034             :     int sig = PARI_SIGINT_pending;   \
    1035             :     PARI_SIGINT_pending = 0;         \
    1036             :     raise(sig);                      \
    1037             :   }                                  \
    1038             : }
    1039             : 
    1040             : INLINE void
    1041    47565558 : pari_free(void *pointer)
    1042             : {
    1043    47565558 :   BLOCK_SIGINT_START;
    1044    47567527 :   free(pointer);
    1045    47567527 :   BLOCK_SIGINT_END;
    1046    47567073 : }
    1047             : INLINE void*
    1048   184915517 : pari_malloc(size_t size)
    1049             : {
    1050   184915517 :   if (size)
    1051             :   {
    1052             :     char *tmp;
    1053   184915517 :     BLOCK_SIGINT_START;
    1054   184917586 :     tmp = (char*)malloc(size);
    1055   184917586 :     BLOCK_SIGINT_END;
    1056   184917632 :     if (!tmp) pari_err(e_MEM);
    1057   184917632 :     return tmp;
    1058             :   }
    1059           0 :   if (DEBUGMEM) pari_warn(warner,"mallocing NULL object");
    1060           0 :   return NULL;
    1061             : }
    1062             : INLINE void*
    1063      798532 : pari_realloc(void *pointer, size_t size)
    1064             : {
    1065             :   char *tmp;
    1066             : 
    1067      798532 :   BLOCK_SIGINT_START;
    1068      800797 :   if (!pointer) tmp = (char *) malloc(size);
    1069       47745 :   else tmp = (char *) realloc(pointer,size);
    1070      800797 :   BLOCK_SIGINT_END;
    1071      800071 :   if (!tmp) pari_err(e_MEM);
    1072      800071 :   return tmp;
    1073             : }
    1074             : INLINE void*
    1075       28712 : pari_calloc(size_t size)
    1076             : {
    1077       28712 :   void *t = pari_malloc(size);
    1078       28712 :   memset(t, 0, size); return t;
    1079             : }
    1080             : INLINE GEN
    1081        4863 : cgetalloc(long t, size_t l)
    1082             : {
    1083        4863 :   GEN x = (GEN)pari_malloc(l * sizeof(long));
    1084        4863 :   x[0] = evaltyp(t) | evallg(l); return x;
    1085             : }
    1086             : 
    1087             : /*******************************************************************/
    1088             : /*                                                                 */
    1089             : /*                       GARBAGE COLLECTION                        */
    1090             : /*                                                                 */
    1091             : /*******************************************************************/
    1092             : /* copy integer x as if we had avma = av */
    1093             : INLINE GEN
    1094  3677845536 : icopy_avma(GEN x, pari_sp av)
    1095             : {
    1096  3677845536 :   long i = lgefint(x), lx = i;
    1097  3677845536 :   GEN y = ((GEN)av) - i;
    1098  3677845536 :   while (--i > 0) y[i] = x[i];
    1099  3677845536 :   y[0] = evaltyp(t_INT)|evallg(lx);
    1100  3677748642 :   return y;
    1101             : }
    1102             : /* copy leaf x as if we had avma = av */
    1103             : INLINE GEN
    1104    91434070 : leafcopy_avma(GEN x, pari_sp av)
    1105             : {
    1106    91434070 :   long i = lg(x);
    1107    91434070 :   GEN y = ((GEN)av) - i;
    1108    91434070 :   while (--i > 0) y[i] = x[i];
    1109    91434070 :   y[0] = x[0] & (~CLONEBIT);
    1110    91434070 :   return y;
    1111             : }
    1112             : INLINE GEN
    1113   520615154 : gerepileuptoleaf(pari_sp av, GEN x)
    1114             : {
    1115             :   long lx;
    1116             :   GEN q;
    1117             : 
    1118   520615154 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1119   521322033 :   lx = lg(x);
    1120   521322033 :   q = ((GEN)av) - lx;
    1121   521322033 :   avma = (pari_sp)q;
    1122   521322033 :   while (--lx >= 0) q[lx] = x[lx];
    1123   521322033 :   return q;
    1124             : }
    1125             : INLINE GEN
    1126  1101495398 : gerepileuptoint(pari_sp av, GEN x)
    1127             : {
    1128  1101495398 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1129   843203763 :   avma = (pari_sp)icopy_avma(x, av);
    1130   843463666 :   return (GEN)avma;
    1131             : }
    1132             : INLINE GEN
    1133   622889212 : gerepileupto(pari_sp av, GEN x)
    1134             : {
    1135   622889212 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1136   558235512 :   switch(typ(x))
    1137             :   { /* non-default = !is_recursive_t(tq) */
    1138   170459878 :     case t_INT: return gerepileuptoint(av, x);
    1139             :     case t_REAL:
    1140             :     case t_STR:
    1141   109433273 :     case t_VECSMALL: return gerepileuptoleaf(av,x);
    1142             :     default:
    1143             :       /* NB: x+i --> ((long)x) + i*sizeof(long) */
    1144   278342361 :       return gerepile(av, (pari_sp) (x+lg(x)), x);
    1145             :   }
    1146             : }
    1147             : 
    1148             : /* gerepileupto(av, gcopy(x)) */
    1149             : INLINE GEN
    1150    34585464 : gerepilecopy(pari_sp av, GEN x)
    1151             : {
    1152    34585464 :   if (is_recursive_t(typ(x)))
    1153             :   {
    1154    28412972 :     GENbin *p = copy_bin(x);
    1155    28412974 :     avma = av; return bin_copy(p);
    1156             :   }
    1157             :   else
    1158             :   {
    1159     6174781 :     avma = av;
    1160     6174781 :     if (x < (GEN)av) {
    1161     4846161 :       if (x < (GEN)pari_mainstack->bot) new_chunk(lg(x));
    1162     4846161 :       x = leafcopy_avma(x, av);
    1163     4852907 :       avma = (pari_sp)x;
    1164             :     } else
    1165     1328620 :       x = leafcopy(x);
    1166     6184486 :     return x;
    1167             :   }
    1168             : }
    1169             : 
    1170             : /* Takes an array of pointers to GENs, of length n. Copies all
    1171             :  * objects to contiguous locations and cleans up the stack between
    1172             :  * av and avma. */
    1173             : INLINE void
    1174       68288 : gerepilemany(pari_sp av, GEN* gptr[], int n)
    1175             : {
    1176             :   int i;
    1177       68288 :   for (i=0; i<n; i++) *gptr[i] = (GEN)copy_bin(*gptr[i]);
    1178       68288 :   avma = av;
    1179       68288 :   for (i=0; i<n; i++) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1180       68288 : }
    1181             : 
    1182             : INLINE void
    1183     4831601 : gerepileall(pari_sp av, int n, ...)
    1184             : {
    1185             :   int i;
    1186     4831601 :   va_list a; va_start(a, n);
    1187     4831601 :   if (n < 10)
    1188             :   {
    1189             :     GEN *gptr[10];
    1190    14730171 :     for (i=0; i<n; i++)
    1191     9898554 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1192     4831617 :     avma = av;
    1193     4831617 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1194             : 
    1195             :   }
    1196             :   else
    1197             :   {
    1198           0 :     GEN **gptr = (GEN**)  pari_malloc(n*sizeof(GEN*));
    1199           0 :     for (i=0; i<n; i++)
    1200           0 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1201           0 :     avma = av;
    1202           0 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1203           0 :     pari_free(gptr);
    1204             :   }
    1205     4831613 : }
    1206             : 
    1207             : INLINE void
    1208           8 : gerepilecoeffs(pari_sp av, GEN x, int n)
    1209             : {
    1210             :   int i;
    1211           8 :   for (i=0; i<n; i++) gel(x,i) = (GEN)copy_bin(gel(x,i));
    1212           8 :   avma = av;
    1213           8 :   for (i=0; i<n; i++) gel(x,i) = bin_copy((GENbin*)x[i]);
    1214           8 : }
    1215             : 
    1216             : /* p from copy_bin. Copy p->x back to stack, then destroy p */
    1217             : INLINE GEN
    1218    38487276 : bin_copy(GENbin *p)
    1219             : {
    1220             :   GEN x, y, base;
    1221             :   long dx, len;
    1222             : 
    1223    38487276 :   x   = p->x; if (!x) { pari_free(p); return gen_0; }
    1224    38485300 :   len = p->len;
    1225    38485300 :   base= p->base; dx = x - base;
    1226    38485300 :   y = (GEN)memcpy((void*)new_chunk(len), (void*)GENbinbase(p), len*sizeof(long));
    1227    38485297 :   y += dx;
    1228    38485297 :   p->rebase(y, ((ulong)y-(ulong)x));
    1229    38485301 :   pari_free(p); return y;
    1230             : }
    1231             : 
    1232             : INLINE GEN
    1233    76972589 : GENbinbase(GENbin *p) { return (GEN)(p + 1); }
    1234             : 
    1235             : INLINE void
    1236    28247812 : cgiv(GEN x)
    1237             : {
    1238    28247812 :   pari_sp av = (pari_sp)(x+lg(x));
    1239    28247812 :   if (isonstack((GEN)av)) avma = av;
    1240    28247812 : }
    1241             : 
    1242             : INLINE void
    1243     1375837 : killblock(GEN x) { gunclone(x); }
    1244             : 
    1245             : INLINE int
    1246    17573473 : is_universal_constant(GEN x) { return (x >= gen_0 && x <= ghalf); }
    1247             : 
    1248             : /*******************************************************************/
    1249             : /*                                                                 */
    1250             : /*                    CONVERSION / ASSIGNMENT                      */
    1251             : /*                                                                 */
    1252             : /*******************************************************************/
    1253             : /* z is a type which may be a t_COMPLEX component (not a t_QUAD) */
    1254             : INLINE GEN
    1255     2059180 : cxcompotor(GEN z, long prec)
    1256             : {
    1257     2059180 :   switch(typ(z))
    1258             :   {
    1259     1020736 :     case t_INT:  return itor(z, prec);
    1260      134120 :     case t_FRAC: return fractor(z, prec);
    1261      904324 :     case t_REAL: return rtor(z, prec);
    1262           0 :     default: pari_err_TYPE("cxcompotor",z); return NULL; /* not reached */
    1263             :   }
    1264             : }
    1265             : INLINE GEN
    1266     1027895 : cxtofp(GEN x, long prec)
    1267     1027895 : { retmkcomplex(cxcompotor(gel(x,1),prec), cxcompotor(gel(x,2),prec)); }
    1268             : 
    1269             : INLINE double
    1270    25451883 : gtodouble(GEN x)
    1271             : {
    1272    25451883 :   if (typ(x)!=t_REAL) {
    1273     4791131 :     pari_sp av = avma;
    1274     4791131 :     x = gtofp(x, DEFAULTPREC);
    1275     4791131 :     if (typ(x)!=t_REAL) pari_err_TYPE("gtodouble [t_REAL expected]", x);
    1276     4791131 :     avma = av;
    1277             :   }
    1278    25451883 :   return rtodbl(x);
    1279             : }
    1280             : INLINE long
    1281    64430943 : gtos(GEN x) {
    1282    64430943 :   if (typ(x) != t_INT) pari_err_TYPE("gtos [integer expected]",x);
    1283    64430936 :   return itos(x);
    1284             : }
    1285             : 
    1286             : INLINE ulong
    1287       83191 : gtou(GEN x) {
    1288       83191 :   if (typ(x) != t_INT || signe(x)<0)
    1289           0 :     pari_err_TYPE("gtou [integer >=0 expected]",x);
    1290       83388 :   return itou(x);
    1291             : }
    1292             : 
    1293             : INLINE GEN
    1294     1867656 : absfrac(GEN x)
    1295             : {
    1296     1867656 :   GEN y = cgetg(3, t_FRAC);
    1297     1867656 :   gel(y,1) = absi(gel(x,1));
    1298     1867656 :   gel(y,2) = icopy(gel(x,2)); return y;
    1299             : }
    1300             : INLINE GEN
    1301       11480 : absfrac_shallow(GEN x)
    1302       11480 : { return signe(gel(x,1))>0? x: mkfrac(negi(gel(x,1)), gel(x,2)); }
    1303             : INLINE GEN
    1304      594383 : Q_abs(GEN x) { return (typ(x) == t_INT)? absi(x): absfrac(x); }
    1305             : INLINE GEN
    1306       37912 : Q_abs_shallow(GEN x)
    1307       37912 : { return (typ(x) == t_INT)? absi_shallow(x): absfrac_shallow(x); }
    1308             : INLINE GEN
    1309         322 : R_abs_shallow(GEN x)
    1310         322 : { return (typ(x) == t_FRAC)? absfrac_shallow(x): mpabs_shallow(x); }
    1311             : INLINE GEN
    1312           0 : R_abs(GEN x)
    1313           0 : { return (typ(x) == t_FRAC)? absfrac(x): mpabs(x); }
    1314             : 
    1315             : /* Force z to be of type real/complex with floating point components */
    1316             : INLINE GEN
    1317    19901636 : gtofp(GEN z, long prec)
    1318             : {
    1319    19901636 :   switch(typ(z))
    1320             :   {
    1321     9837677 :     case t_INT:  return itor(z, prec);
    1322     4952745 :     case t_FRAC: return fractor(z, prec);
    1323     4255202 :     case t_REAL: return rtor(z, prec);
    1324             :     case t_COMPLEX: {
    1325      856012 :       GEN a = gel(z,1), b = gel(z,2);
    1326      856012 :       if (isintzero(b)) return cxcompotor(a, prec);
    1327      854304 :       if (isintzero(a)) {
    1328        1640 :         GEN y = cgetg(3, t_COMPLEX);
    1329        1640 :         b = cxcompotor(b, prec);
    1330        1640 :         gel(y,1) = real_0_bit(expo(b) - prec2nbits(prec));
    1331        1640 :         gel(y,2) = b; return y;
    1332             :       }
    1333      852664 :       return cxtofp(z, prec);
    1334             :     }
    1335           0 :     case t_QUAD: return quadtofp(z, prec);
    1336           0 :     default: pari_err_TYPE("gtofp",z); return NULL; /* not reached */
    1337             :   }
    1338             : }
    1339             : /* Force z to be of type real / int */
    1340             : INLINE GEN
    1341       22400 : gtomp(GEN z, long prec)
    1342             : {
    1343       22400 :   switch(typ(z))
    1344             :   {
    1345          14 :     case t_INT:  return z;
    1346       22386 :     case t_FRAC: return fractor(z, prec);
    1347           0 :     case t_REAL: return rtor(z, prec);
    1348           0 :     case t_QUAD: z = quadtofp(z, prec);
    1349           0 :                  if (typ(z) == t_REAL) return z;
    1350           0 :     default: pari_err_TYPE("gtomp",z); return NULL; /* not reached */
    1351             :   }
    1352             : }
    1353             : 
    1354             : INLINE GEN
    1355      476188 : RgX_gtofp(GEN x, long prec)
    1356             : {
    1357             :   long l;
    1358      476188 :   GEN y = cgetg_copy(x, &l);
    1359      476188 :   while (--l > 1) gel(y,l) = gtofp(gel(x,l), prec);
    1360      476188 :   y[1] = x[1]; return y;
    1361             : }
    1362             : INLINE GEN
    1363      383612 : RgC_gtofp(GEN x, long prec)
    1364             : {
    1365      383612 :   long l = lg(x);
    1366      383612 :   GEN y = cgetg(l, t_COL);
    1367      383612 :   while (--l > 0) gel(y,l) = gtofp(gel(x,l), prec);
    1368      383612 :   return y;
    1369             : }
    1370             : INLINE GEN
    1371       19074 : RgM_gtofp(GEN x, long prec)
    1372             : {
    1373             :   long l;
    1374       19074 :   GEN y = cgetg_copy(x, &l);
    1375       19074 :   while (--l > 0) gel(y,l) = RgC_gtofp(gel(x,l), prec);
    1376       19074 :   return y;
    1377             : }
    1378             : INLINE GEN
    1379         560 : RgC_gtomp(GEN x, long prec)
    1380             : {
    1381         560 :   long l = lg(x);
    1382         560 :   GEN y = cgetg(l, t_COL);
    1383         560 :   while (--l > 0) gel(y,l) = gtomp(gel(x,l), prec);
    1384         560 :   return y;
    1385             : }
    1386             : INLINE GEN
    1387          14 : RgM_gtomp(GEN x, long prec)
    1388             : {
    1389             :   long l;
    1390          14 :   GEN y = cgetg_copy(x, &l);
    1391          14 :   while (--l > 0) gel(y,l) = RgC_gtomp(gel(x,l), prec);
    1392          14 :   return y;
    1393             : }
    1394             : 
    1395             : INLINE GEN
    1396        6265 : RgX_fpnorml2(GEN x, long prec)
    1397             : {
    1398        6265 :   pari_sp av = avma;
    1399        6265 :   return gerepileupto(av, gnorml2(RgX_gtofp(x, prec)));
    1400             : }
    1401             : INLINE GEN
    1402      248442 : RgC_fpnorml2(GEN x, long prec)
    1403             : {
    1404      248442 :   pari_sp av = avma;
    1405      248442 :   return gerepileupto(av, gnorml2(RgC_gtofp(x, prec)));
    1406             : }
    1407             : INLINE GEN
    1408        1645 : RgM_fpnorml2(GEN x, long prec)
    1409             : {
    1410        1645 :   pari_sp av = avma;
    1411        1645 :   return gerepileupto(av, gnorml2(RgM_gtofp(x, prec)));
    1412             : }
    1413             : 
    1414             : /* y a t_REAL */
    1415             : INLINE void
    1416      180734 : affgr(GEN x, GEN y)
    1417             : {
    1418             :   pari_sp av;
    1419      180734 :   switch(typ(x)) {
    1420         512 :     case t_INT:  affir(x,y); break;
    1421      180222 :     case t_REAL: affrr(x,y); break;
    1422           0 :     case t_FRAC: rdiviiz(gel(x,1),gel(x,2), y); break;
    1423           0 :     case t_QUAD: av = avma; affgr(quadtofp(x,realprec(y)), y); avma = av; break;
    1424           0 :     default: pari_err_TYPE2("=",x,y);
    1425             :   }
    1426      180734 : }
    1427             : 
    1428             : INLINE GEN
    1429      183802 : affc_fixlg(GEN x, GEN res)
    1430             : {
    1431      183802 :   if (typ(x) == t_COMPLEX)
    1432             :   {
    1433      175308 :     affrr_fixlg(gel(x,1), gel(res,1));
    1434      175308 :     affrr_fixlg(gel(x,2), gel(res,2));
    1435             :   }
    1436             :   else
    1437             :   {
    1438        8494 :     avma = (pari_sp)(res+3);
    1439        8494 :     res = cgetr(realprec(gel(res,1)));
    1440        8494 :     affrr_fixlg(x, res);
    1441             :   }
    1442      183802 :   return res;
    1443             : }
    1444             : 
    1445             : INLINE GEN
    1446           0 : trunc_safe(GEN x) { long e; return gcvtoi(x,&e); }
    1447             : 
    1448             : /*******************************************************************/
    1449             : /*                                                                 */
    1450             : /*                          LENGTH CONVERSIONS                     */
    1451             : /*                                                                 */
    1452             : /*******************************************************************/
    1453             : INLINE long
    1454       22316 : ndec2nlong(long x) { return 1 + (long)((x)*(LOG2_10/BITS_IN_LONG)); }
    1455             : INLINE long
    1456       21873 : ndec2prec(long x) { return 2 + ndec2nlong(x); }
    1457             : INLINE long
    1458         443 : ndec2nbits(long x) { return ndec2nlong(x) << TWOPOTBITS_IN_LONG; }
    1459             : /* Fast implementation of ceil(x / (8*sizeof(long))); typecast to (ulong)
    1460             :  * to avoid overflow. Faster than 1 + ((x-1)>>TWOPOTBITS_IN_LONG)) :
    1461             :  *   addl, shrl instead of subl, sarl, addl */
    1462             : INLINE long
    1463      798626 : nbits2nlong(long x) {
    1464      798626 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1465             : }
    1466             : 
    1467             : INLINE long
    1468   271509395 : nbits2extraprec(long x) {
    1469   271509395 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1470             : }
    1471             : 
    1472             : /* Fast implementation of 2 + nbits2nlong(x) */
    1473             : INLINE long
    1474    80482950 : nbits2prec(long x) {
    1475    80482950 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1476             : }
    1477             : INLINE long
    1478     3326105 : nbits2lg(long x) {
    1479     3326105 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1480             : }
    1481             : /* ceil(x / sizeof(long)) */
    1482             : INLINE long
    1483     6991130 : nchar2nlong(long x) {
    1484     6991130 :   return (long)(((ulong)x+sizeof(long)-1) >> (TWOPOTBITS_IN_LONG-3L));
    1485             : }
    1486             : INLINE long
    1487  1164178378 : prec2nbits(long x) { return (x-2) * BITS_IN_LONG; }
    1488             : INLINE double
    1489      450737 : bit_accuracy_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1490             : INLINE double
    1491      224374 : prec2nbits_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1492             : INLINE long
    1493    26484343 : bit_prec(GEN x) { return prec2nbits(realprec(x)); }
    1494             : INLINE long
    1495  1078124266 : bit_accuracy(long x) { return prec2nbits(x); }
    1496             : INLINE long
    1497       12001 : prec2ndec(long x) { return (long)prec2nbits_mul(x, LOG10_2); }
    1498             : INLINE long
    1499         165 : nbits2ndec(long x) { return (long)(x * LOG10_2); }
    1500             : INLINE long
    1501        1691 : precdbl(long x) {return (x - 1) << 1;}
    1502             : INLINE long
    1503  3576464471 : divsBIL(long n) { return n >> TWOPOTBITS_IN_LONG; }
    1504             : INLINE long
    1505  3506780608 : remsBIL(long n) { return n & (BITS_IN_LONG-1); }
    1506             : 
    1507             : /*********************************************************************/
    1508             : /**                                                                 **/
    1509             : /**                      OPERATIONS MODULO m                        **/
    1510             : /**                                                                 **/
    1511             : /*********************************************************************/
    1512             : /* Assume m > 0, more efficient if 0 <= a, b < m */
    1513             : 
    1514             : INLINE GEN
    1515     1210226 : Fp_red(GEN a, GEN m) { return modii(a, m); }
    1516             : INLINE GEN
    1517   359746315 : Fp_add(GEN a, GEN b, GEN m)
    1518             : {
    1519   359746315 :   pari_sp av=avma;
    1520   359746315 :   GEN p = addii(a,b);
    1521   359727266 :   long s = signe(p);
    1522   359727266 :   if (!s) return p; /* = gen_0 */
    1523   172517364 :   if (s > 0) /* general case */
    1524             :   {
    1525   172299419 :     GEN t = subii(p, m);
    1526   172313279 :     s = signe(t);
    1527   172313279 :     if (!s) { avma = av; return gen_0; }
    1528   159569858 :     if (s < 0) { avma = (pari_sp)p; return p; }
    1529    27231669 :     if (cmpii(t, m) < 0) return gerepileuptoint(av, t); /* general case ! */
    1530     1091537 :     p = remii(t, m);
    1531             :   }
    1532             :   else
    1533      217945 :     p = modii(p, m);
    1534     1309482 :   return gerepileuptoint(av, p);
    1535             : }
    1536             : INLINE GEN
    1537    45900510 : Fp_sub(GEN a, GEN b, GEN m)
    1538             : {
    1539    45900510 :   pari_sp av=avma;
    1540    45900510 :   GEN p = subii(a,b);
    1541    45973672 :   long s = signe(p);
    1542    45973672 :   if (!s) return p; /* = gen_0 */
    1543    39004482 :   if (s > 0)
    1544             :   {
    1545    18964508 :     if (cmpii(p, m) < 0) return p; /* general case ! */
    1546      742252 :     p = remii(p, m);
    1547             :   }
    1548             :   else
    1549             :   {
    1550    20039974 :     GEN t = addii(p, m);
    1551    20024971 :     if (!s) { avma = av; return gen_0; }
    1552    20024971 :     if (s > 0) return gerepileuptoint(av, t); /* general case ! */
    1553    20024971 :     p = modii(t, m);
    1554             :   }
    1555    20773529 :   return gerepileuptoint(av, p);
    1556             : }
    1557             : INLINE GEN
    1558     9960602 : Fp_neg(GEN b, GEN m)
    1559             : {
    1560     9960602 :   pari_sp av = avma;
    1561     9960602 :   long s = signe(b);
    1562             :   GEN p;
    1563     9960602 :   if (!s) return gen_0;
    1564     7149310 :   if (s > 0)
    1565             :   {
    1566     7148610 :     p = subii(m, b);
    1567     7148427 :     if (signe(p) >= 0) return p; /* general case ! */
    1568       37760 :     p = modii(p, m);
    1569             :   } else
    1570         700 :     p = remii(negi(b), m);
    1571       38460 :   return gerepileuptoint(av, p);
    1572             : }
    1573             : 
    1574             : INLINE GEN
    1575       19591 : Fp_halve(GEN a, GEN p)
    1576             : {
    1577       19591 :   if (mpodd(a)) a = addii(a,p);
    1578       19591 :   return shifti(a,-1);
    1579             : }
    1580             : 
    1581             : /* assume 0 <= u < p and ps2 = p>>1 */
    1582             : INLINE GEN
    1583     5744747 : Fp_center(GEN u, GEN p, GEN ps2)
    1584     5744747 : { return abscmpii(u,ps2)<=0? icopy(u): subii(u,p); }
    1585             : 
    1586             : /* x + y*z mod p */
    1587             : INLINE GEN
    1588     2142266 : Fp_addmul(GEN x, GEN y, GEN z, GEN p)
    1589             : {
    1590             :   pari_sp av;
    1591     2142266 :   if (!signe(y) || !signe(z)) return Fp_red(x, p);
    1592     2057027 :   if (!signe(x)) return Fp_mul(z,y, p);
    1593     1770419 :   av = avma;
    1594     1770419 :   return gerepileuptoint(av, modii(addii(x, mulii(y,z)), p));
    1595             : }
    1596             : 
    1597             : INLINE GEN
    1598   341919748 : Fp_mul(GEN a, GEN b, GEN m)
    1599             : {
    1600   341919748 :   pari_sp av=avma;
    1601             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1602   341919748 :   (void)new_chunk(lg(a)+lg(b)+(lg(m)<<1));
    1603   341920510 :   p = mulii(a,b);
    1604   341920842 :   avma = av; return modii(p,m);
    1605             : }
    1606             : INLINE GEN
    1607     6964103 : Fp_sqr(GEN a, GEN m)
    1608             : {
    1609     6964103 :   pari_sp av=avma;
    1610             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1611     6964103 :   (void)new_chunk((lg(a)+lg(m))<<1);
    1612     6994942 :   p = sqri(a);
    1613     7024352 :   avma = av; return modii(p,m);
    1614             : }
    1615             : INLINE GEN
    1616    52708765 : Fp_mulu(GEN a, ulong b, GEN m)
    1617             : {
    1618    52708765 :   long l = lgefint(m);
    1619    52708765 :   if (l == 3)
    1620             :   {
    1621    35688913 :     ulong mm = m[2];
    1622    35688913 :     return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1623             :   } else {
    1624    17019852 :     pari_sp av = avma;
    1625             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1626    17019852 :     (void)new_chunk(lg(a)+1+(l<<1));
    1627    17041295 :     p = muliu(a,b);
    1628    16797138 :     avma = av; return modii(p,m);
    1629             :   }
    1630             : }
    1631             : INLINE GEN
    1632           0 : Fp_muls(GEN a, long b, GEN m)
    1633             : {
    1634           0 :   long l = lgefint(m);
    1635           0 :   if (l == 3)
    1636             :   {
    1637           0 :     ulong mm = m[2];
    1638           0 :     if (b < 0)
    1639             :     {
    1640           0 :       ulong t = Fl_mul(umodiu(a, mm), -b, mm);
    1641           0 :       return t? utoipos(mm - t): gen_0;
    1642             :     }
    1643             :     else
    1644           0 :       return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1645             :   } else {
    1646           0 :     pari_sp av = avma;
    1647             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1648           0 :     (void)new_chunk(lg(a)+1+(l<<1));
    1649           0 :     p = mulis(a,b);
    1650           0 :     avma = av; return modii(p,m);
    1651             :   }
    1652             : }
    1653             : 
    1654             : INLINE GEN
    1655     7616605 : Fp_inv(GEN a, GEN m)
    1656             : {
    1657             :   GEN res;
    1658     7616605 :   if (! invmod(a,m,&res)) pari_err_INV("Fp_inv", mkintmod(res,m));
    1659     7600425 :   return res;
    1660             : }
    1661             : INLINE GEN
    1662      285309 : Fp_invsafe(GEN a, GEN m)
    1663             : {
    1664             :   GEN res;
    1665      285309 :   if (! invmod(a,m,&res)) return NULL;
    1666      285309 :   return res;
    1667             : }
    1668             : INLINE GEN
    1669     4548426 : Fp_div(GEN a, GEN b, GEN m)
    1670             : {
    1671     4548426 :   pari_sp av=avma;
    1672             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1673     4548426 :   (void)new_chunk(lg(a)+(lg(m)<<1));
    1674     4558211 :   p = mulii(a, Fp_inv(b,m));
    1675     4561329 :   avma = av; return modii(p,m);
    1676             : }
    1677             : 
    1678             : INLINE GEN
    1679      665265 : Flx_mulu(GEN x, ulong a, ulong p) { return Flx_Fl_mul(x,a%p,p); }
    1680             : 
    1681             : /*******************************************************************/
    1682             : /*                                                                 */
    1683             : /*                        ADDMULII / SUBMULII                      */
    1684             : /*                                                                 */
    1685             : /*******************************************************************/
    1686             : /* x - y*z */
    1687             : INLINE GEN
    1688    41326573 : submulii(GEN x, GEN y, GEN z)
    1689             : {
    1690    41326573 :   long lx = lgefint(x), ly, lz;
    1691             :   pari_sp av;
    1692             :   GEN t;
    1693    41326573 :   if (lx == 2) { t = mulii(z,y); togglesign(t); return t; }
    1694    35199508 :   ly = lgefint(y);
    1695    35199508 :   if (ly == 2) return icopy(x);
    1696    33793700 :   lz = lgefint(z);
    1697    33793700 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1698    33793700 :   t = mulii(z, y);
    1699    33793700 :   avma = av; return subii(x,t);
    1700             : }
    1701             : /* y*z - x */
    1702             : INLINE GEN
    1703     2148436 : mulsubii(GEN y, GEN z, GEN x)
    1704             : {
    1705     2148436 :   long lx = lgefint(x), ly, lz;
    1706             :   pari_sp av;
    1707             :   GEN t;
    1708     2148436 :   if (lx == 2) return mulii(z,y);
    1709     1363663 :   ly = lgefint(y);
    1710     1363663 :   if (ly == 2) return negi(x);
    1711     1314683 :   lz = lgefint(z);
    1712     1314683 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1713     1314683 :   t = mulii(z, y);
    1714     1314683 :   avma = av; return subii(t,x);
    1715             : }
    1716             : 
    1717             : /* x - u*y */
    1718             : INLINE GEN
    1719        7000 : submuliu(GEN x, GEN y, ulong u)
    1720             : {
    1721             :   pari_sp av;
    1722        7000 :   long ly = lgefint(y);
    1723        7000 :   if (ly == 2) return icopy(x);
    1724        7000 :   av = avma;
    1725        7000 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1726        7000 :   y = mului(u,y);
    1727        7000 :   avma = av; return subii(x, y);
    1728             : }
    1729             : /* x + u*y */
    1730             : INLINE GEN
    1731        7000 : addmuliu(GEN x, GEN y, ulong u)
    1732             : {
    1733             :   pari_sp av;
    1734        7000 :   long ly = lgefint(y);
    1735        7000 :   if (ly == 2) return icopy(x);
    1736        7000 :   av = avma;
    1737        7000 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1738        7000 :   y = mului(u,y);
    1739        7000 :   avma = av; return addii(x, y);
    1740             : }
    1741             : /* x - u*y */
    1742             : INLINE GEN
    1743   256966971 : submuliu_inplace(GEN x, GEN y, ulong u)
    1744             : {
    1745             :   pari_sp av;
    1746   256966971 :   long ly = lgefint(y);
    1747   256966971 :   if (ly == 2) return x;
    1748   219843872 :   av = avma;
    1749   219843872 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1750   219843872 :   y = mului(u,y);
    1751   219843872 :   avma = av; return subii(x, y);
    1752             : }
    1753             : /* x + u*y */
    1754             : INLINE GEN
    1755   256353325 : addmuliu_inplace(GEN x, GEN y, ulong u)
    1756             : {
    1757             :   pari_sp av;
    1758   256353325 :   long ly = lgefint(y);
    1759   256353325 :   if (ly == 2) return x;
    1760   220062331 :   av = avma;
    1761   220062331 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1762   220062331 :   y = mului(u,y);
    1763   220062331 :   avma = av; return addii(x, y);
    1764             : }
    1765             : /* ux + vy */
    1766             : INLINE GEN
    1767    25222635 : lincombii(GEN u, GEN v, GEN x, GEN y)
    1768             : {
    1769    25222635 :   long lx = lgefint(x), ly;
    1770             :   GEN p1, p2;
    1771             :   pari_sp av;
    1772    25222635 :   if (lx == 2) return mulii(v,y);
    1773    15456200 :   ly = lgefint(y);
    1774    15456200 :   if (ly == 2) return mulii(u,x);
    1775    14140438 :   av = avma; (void)new_chunk(lx+ly+lgefint(u)+lgefint(v)); /* HACK */
    1776    14140438 :   p1 = mulii(u,x);
    1777    14140438 :   p2 = mulii(v,y);
    1778    14140438 :   avma = av; return addii(p1,p2);
    1779             : }
    1780             : 
    1781             : /*******************************************************************/
    1782             : /*                                                                 */
    1783             : /*                          GEN SUBTYPES                           */
    1784             : /*                                                                 */
    1785             : /*******************************************************************/
    1786             : 
    1787             : INLINE int
    1788   919287046 : is_const_t(long t) { return (t < t_POLMOD); }
    1789             : INLINE int
    1790      362239 : is_extscalar_t(long t) { return (t <= t_POL); }
    1791             : INLINE int
    1792      826943 : is_intreal_t(long t) { return (t <= t_REAL); }
    1793             : INLINE int
    1794   351323021 : is_matvec_t(long t) { return (t >= t_VEC && t <= t_MAT); }
    1795             : INLINE int
    1796    51979126 : is_noncalc_t(long tx) { return (tx) >= t_LIST; }
    1797             : INLINE int
    1798      580726 : is_rational_t(long t) { return (t == t_INT || t == t_FRAC); }
    1799             : INLINE int
    1800       53431 : is_real_t(long t) { return (t == t_INT || t == t_REAL || t == t_FRAC); }
    1801             : INLINE int
    1802  2517032043 : is_recursive_t(long t) { return lontyp[t]; }
    1803             : INLINE int
    1804   152280792 : is_scalar_t(long t) { return (t < t_POL); }
    1805             : INLINE int
    1806      399023 : is_vec_t(long t) { return (t == t_VEC || t == t_COL); }
    1807             : 
    1808             : /*******************************************************************/
    1809             : /*                                                                 */
    1810             : /*                         TRANSCENDENTAL                          */
    1811             : /*                                                                 */
    1812             : /*******************************************************************/
    1813             : INLINE GEN
    1814    14797854 : sqrtr(GEN x) {
    1815    14797854 :   long s = signe(x);
    1816    14797854 :   if (s == 0) return real_0_bit(expo(x) >> 1);
    1817    14764369 :   if (s >= 0) return sqrtr_abs(x);
    1818       12912 :   retmkcomplex(gen_0, sqrtr_abs(x));
    1819             : }
    1820             : INLINE GEN
    1821       11963 : cbrtr(GEN x) {
    1822       11963 :   long s = signe(x);
    1823             :   GEN r;
    1824       11963 :   if (s == 0) return real_0_bit(expo(x) / 3);
    1825       11963 :   r = cbrtr_abs(x);
    1826       11963 :   if (s < 0) togglesign(r);
    1827       11963 :   return r;
    1828             : }
    1829             : /* x^(1/n) */
    1830             : INLINE GEN
    1831       34404 : sqrtnr(GEN x, long n) {
    1832       34404 :   switch(n)
    1833             :   {
    1834         595 :     case 1: return rcopy(x);
    1835        5291 :     case 2: return sqrtr(x);
    1836       11963 :     case 3: return cbrtr(x);
    1837             :   }
    1838       16555 :   return mpexp(divrs(mplog(x), n));
    1839             : }
    1840             : INLINE long
    1841      397250 : logint(GEN B, GEN y) { return logintall(B,y,NULL); }
    1842             : 
    1843             : /*******************************************************************/
    1844             : /*                                                                 */
    1845             : /*                         MISCELLANEOUS                           */
    1846             : /*                                                                 */
    1847             : /*******************************************************************/
    1848      826866 : INLINE int ismpzero(GEN x) { return is_intreal_t(typ(x)) && !signe(x); }
    1849   351241228 : INLINE int isintzero(GEN x) { return typ(x) == t_INT && !signe(x); }
    1850     6070415 : INLINE int isint1(GEN x) { return typ(x)==t_INT && equali1(x); }
    1851         301 : INLINE int isintm1(GEN x){ return typ(x)==t_INT && equalim1(x);}
    1852   214098205 : INLINE int equali1(GEN n)
    1853   214098205 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(1)) && n[2] == 1; }
    1854    23572537 : INLINE int equalim1(GEN n)
    1855    23572537 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(-1)) && n[2] == 1; }
    1856             : /* works only for POSITIVE integers */
    1857  1491078448 : INLINE int is_pm1(GEN n)
    1858  1491078448 : { return lgefint(n) == 3 && n[2] == 1; }
    1859   131330341 : INLINE int is_bigint(GEN n)
    1860   131330341 : { long l = lgefint(n); return l > 3 || (l == 3 && (n[2] & HIGHBIT)); }
    1861             : 
    1862  1410776331 : INLINE int odd(long x) { return x & 1; }
    1863    14371150 : INLINE int both_odd(long x, long y) { return x & y & 1; }
    1864             : 
    1865             : INLINE int
    1866  2273312614 : isonstack(GEN x)
    1867  4546625228 : { return ((pari_sp)x >= pari_mainstack->bot
    1868  2273312614 :        && (pari_sp)x <  pari_mainstack->top); }
    1869             : 
    1870             : /* assume x != 0 and x t_REAL, return an approximation to log2(|x|) */
    1871             : INLINE double
    1872    16829751 : dbllog2r(GEN x)
    1873    16829751 : { return log2((double)(ulong)x[2]) + (double)(expo(x) - (BITS_IN_LONG-1)); }
    1874             : 
    1875             : INLINE GEN
    1876      272362 : mul_content(GEN cx, GEN cy)
    1877             : {
    1878      272362 :   if (!cx) return cy;
    1879       58655 :   if (!cy) return cx;
    1880       36836 :   return gmul(cx,cy);
    1881             : }
    1882             : INLINE GEN
    1883      444884 : mul_denom(GEN dx, GEN dy)
    1884             : {
    1885      444884 :   if (!dx) return dy;
    1886      310343 :   if (!dy) return dx;
    1887      120175 :   return mulii(dx,dy);
    1888             : }
    1889             : 
    1890             : /* POLYNOMIALS */
    1891             : INLINE GEN
    1892    17547453 : constant_coeff(GEN x) { return signe(x)? gel(x,2): gen_0; }
    1893             : INLINE GEN
    1894    75717239 : leading_coeff(GEN x) { return lg(x) == 2? gen_0: gel(x,lg(x)-1); }
    1895             : INLINE ulong
    1896      418001 : Flx_lead(GEN x) { return lg(x) == 2? 0: x[lg(x)-1]; }
    1897             : INLINE long
    1898  2583828716 : degpol(GEN x) { return lg(x)-3; }
    1899             : INLINE long
    1900  1236552382 : lgpol(GEN x) { return lg(x)-2; }
    1901             : INLINE long
    1902    59612585 : lgcols(GEN x) { return lg(gel(x,1)); }
    1903             : INLINE long
    1904    15337455 : nbrows(GEN x) { return lg(gel(x,1))-1; }
    1905             : INLINE GEN
    1906           0 : truecoeff(GEN x, long n) { return polcoeff0(x,n,-1); }
    1907             : 
    1908             : INLINE GEN
    1909      432345 : RgXQ_mul(GEN y, GEN x, GEN T) { return RgX_rem(RgX_mul(y, x), T); }
    1910             : INLINE GEN
    1911      212282 : RgXQ_sqr(GEN x, GEN T) { return RgX_rem(RgX_sqr(x), T); }
    1912             : 
    1913             : INLINE GEN
    1914      114667 : ZXQ_mul(GEN y, GEN x, GEN T) { return ZX_rem(ZX_mul(y, x), T); }
    1915             : INLINE GEN
    1916       19824 : ZXQ_sqr(GEN x, GEN T) { return ZX_rem(ZX_sqr(x), T); }
    1917             : 
    1918             : INLINE GEN
    1919    61841954 : RgX_copy(GEN x)
    1920             : {
    1921             :   long lx, i;
    1922    61841954 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
    1923    61841954 :   for (i = 2; i<lx; i++) gel(y,i) = gcopy(gel(x,i));
    1924    61841954 :   return y;
    1925             : }
    1926             : /* have to use ulong to avoid silly warnings from gcc "assuming signed
    1927             :  * overflow does not occur" */
    1928             : INLINE GEN
    1929     2219792 : RgX_coeff(GEN x, long n)
    1930             : {
    1931     2219792 :   ulong l = lg(x);
    1932     2219792 :   return (n < 0 || ((ulong)n+3) > l)? gen_0: gel(x,n+2);
    1933             : }
    1934             : INLINE GEN
    1935      310625 : RgX_renormalize(GEN x) { return RgX_renormalize_lg(x, lg(x)); }
    1936             : INLINE GEN
    1937     6102770 : RgX_div(GEN x, GEN y) { return RgX_divrem(x,y,NULL); }
    1938             : INLINE GEN
    1939     2470774 : RgX_rem(GEN x, GEN y) { return RgX_divrem(x,y,ONLY_REM); }
    1940             : INLINE GEN
    1941           7 : RgXQX_div(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,NULL); }
    1942             : INLINE GEN
    1943       25130 : RgXQX_rem(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,ONLY_REM); }
    1944             : INLINE GEN
    1945      714781 : FpX_div(GEN x, GEN y, GEN p) { return FpX_divrem(x,y,p, NULL); }
    1946             : INLINE GEN
    1947     2860598 : Flx_div(GEN x, GEN y, ulong p) { return Flx_divrem(x,y,p, NULL); }
    1948             : INLINE GEN
    1949     1148119 : F2x_div(GEN x, GEN y) { return F2x_divrem(x,y, NULL); }
    1950             : INLINE GEN
    1951           0 : FpV_FpC_mul(GEN x, GEN y, GEN p) { return FpV_dotproduct(x,y,p); }
    1952             : INLINE GEN
    1953    42837303 : pol0_Flx(long sv) { return mkvecsmall(sv); }
    1954             : INLINE GEN
    1955    16430012 : pol1_Flx(long sv) { return mkvecsmall2(sv, 1); }
    1956             : INLINE GEN
    1957    17083115 : polx_Flx(long sv) { return mkvecsmall3(sv, 0, 1); }
    1958             : INLINE GEN
    1959           0 : zero_zx(long sv) { return zero_Flx(sv); }
    1960             : INLINE GEN
    1961           0 : polx_zx(long sv) { return polx_Flx(sv); }
    1962             : INLINE GEN
    1963           0 : zx_shift(GEN x, long n) { return Flx_shift(x,n); }
    1964             : INLINE GEN
    1965           0 : zx_renormalize(GEN x, long l) { return Flx_renormalize(x,l); }
    1966             : INLINE GEN
    1967          56 : zero_F2x(long sv) { return zero_Flx(sv); }
    1968             : INLINE GEN
    1969     7230081 : pol0_F2x(long sv) { return pol0_Flx(sv); }
    1970             : INLINE GEN
    1971     1780197 : pol1_F2x(long sv) { return pol1_Flx(sv); }
    1972             : INLINE GEN
    1973      277686 : polx_F2x(long sv) { return mkvecsmall2(sv, 2); }
    1974             : INLINE int
    1975      712103 : F2x_equal1(GEN x) { return Flx_equal1(x); }
    1976             : INLINE int
    1977     1272537 : F2x_equal(GEN V, GEN W) { return Flx_equal(V,W); }
    1978             : INLINE GEN
    1979    35751266 : F2x_copy(GEN x) { return leafcopy(x); }
    1980             : INLINE GEN
    1981           0 : F2v_copy(GEN x) { return leafcopy(x); }
    1982             : INLINE GEN
    1983     1820209 : Flv_copy(GEN x) { return leafcopy(x); }
    1984             : INLINE GEN
    1985    83751303 : Flx_copy(GEN x) { return leafcopy(x); }
    1986             : INLINE GEN
    1987     2051870 : vecsmall_copy(GEN x) { return leafcopy(x); }
    1988             : INLINE int
    1989     4652974 : Flx_equal1(GEN x) { return degpol(x)==0 && x[2] == 1; }
    1990             : INLINE int
    1991       17711 : ZX_equal1(GEN x) { return degpol(x)==0 && equali1(gel(x,2)); }
    1992             : 
    1993             : INLINE GEN
    1994    74562290 : ZX_renormalize(GEN x, long lx)    { return ZXX_renormalize(x,lx); }
    1995             : INLINE GEN
    1996    91575553 : FpX_renormalize(GEN x, long lx)   { return ZXX_renormalize(x,lx); }
    1997             : INLINE GEN
    1998      949431 : FpXX_renormalize(GEN x, long lx)  { return ZXX_renormalize(x,lx); }
    1999             : INLINE GEN
    2000     1112062 : FpXQX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
    2001             : INLINE GEN
    2002    80354205 : F2x_renormalize(GEN x, long lx)   { return Flx_renormalize(x,lx); }
    2003             : INLINE GEN
    2004        6671 : F2v_to_F2x(GEN x, long sv) {
    2005        6671 :   GEN y = leafcopy(x);
    2006        6671 :   y[1] = sv; F2x_renormalize(y, lg(y)); return y;
    2007             : }
    2008             : 
    2009             : INLINE GEN
    2010           0 : ZX_ZXY_resultant(GEN a, GEN b) { return ZX_ZXY_rnfequation(a,b,NULL); }
    2011             : INLINE long
    2012         441 : sturm(GEN x) { return sturmpart(x, NULL, NULL); }
    2013             : INLINE GEN
    2014       25486 : resultant(GEN x, GEN y) { return resultant_all(x,y,NULL); }
    2015             : 
    2016             : INLINE long
    2017        2051 : gval(GEN x, long v) {
    2018        2051 :   pari_sp av = avma;
    2019        2051 :   long n = gvaluation(x, pol_x(v));
    2020        2051 :   avma = av; return n;
    2021             : }
    2022             : 
    2023             : INLINE void
    2024      577588 : RgX_shift_inplace_init(long v)
    2025      577588 : { if (v) (void)cgetg(v, t_VECSMALL); }
    2026             : /* shift polynomial in place. assume v free cells have been left before x */
    2027             : INLINE GEN
    2028      577589 : RgX_shift_inplace(GEN x, long v)
    2029             : {
    2030             :   long i, lx;
    2031             :   GEN y, z;
    2032      577589 :   if (!v) return x;
    2033      258109 :   lx = lg(x);
    2034      258109 :   if (lx == 2) return x;
    2035      258109 :   y = x + v;
    2036      258109 :   z = x + lx;
    2037             :   /* stackdummy from normalizepol: move it up */
    2038      258109 :   if (lg(z) != v) x[lx + v] = z[0];
    2039      258109 :   for (i = lx-1; i >= 2; i--) gel(y,i) = gel(x,i);
    2040      258109 :   for (i = v+1;  i >= 2; i--) gel(x,i) = gen_0;
    2041             :   /* leave x[1] alone: it is correct */
    2042      258109 :   x[0] = evaltyp(t_POL) | evallg(lx+v); return x;
    2043             : }
    2044             : 
    2045             : 
    2046             : /* LINEAR ALGEBRA */
    2047             : INLINE GEN
    2048        8428 : zv_to_ZV(GEN x) { return vecsmall_to_vec(x); }
    2049             : INLINE GEN
    2050     1090679 : zc_to_ZC(GEN x) { return vecsmall_to_col(x); }
    2051             : INLINE GEN
    2052      224789 : ZV_to_zv(GEN x) { return vec_to_vecsmall(x); }
    2053             : INLINE GEN
    2054           0 : zx_to_zv(GEN x, long N) { return Flx_to_Flv(x,N); }
    2055             : INLINE GEN
    2056           0 : zv_to_zx(GEN x, long sv) { return Flv_to_Flx(x,sv); }
    2057             : INLINE GEN
    2058           0 : zm_to_zxV(GEN x, long sv) { return Flm_to_FlxV(x,sv); }
    2059             : INLINE GEN
    2060           0 : zero_zm(long x, long y) { return zero_Flm(x,y); }
    2061             : INLINE GEN
    2062    14739615 : zero_zv(long x) { return zero_Flv(x); }
    2063             : INLINE GEN
    2064         168 : zm_transpose(GEN x) { return Flm_transpose(x); }
    2065             : INLINE GEN
    2066           0 : zm_copy(GEN x) { return Flm_copy(x); }
    2067             : INLINE GEN
    2068     1357748 : zv_copy(GEN x) { return Flv_copy(x); }
    2069             : INLINE GEN
    2070           0 : zm_row(GEN x, long i) { return Flm_row(x,i); }
    2071             : 
    2072             : INLINE GEN
    2073      822050 : ZC_hnfrem(GEN x, GEN y) { return ZC_hnfremdiv(x,y,NULL); }
    2074             : INLINE GEN
    2075       56957 : ZM_hnfrem(GEN x, GEN y) { return ZM_hnfdivrem(x,y,NULL); }
    2076             : INLINE GEN
    2077     1355026 : ZM_lll(GEN x, double D, long f) { return ZM_lll_norms(x,D,f,NULL); }
    2078             : INLINE void
    2079      117417 : RgM_dimensions(GEN x, long *m, long *n) { *n = lg(x)-1; *m = *n? nbrows(x): 0; }
    2080             : INLINE GEN
    2081       30501 : RgM_inv(GEN a) { return RgM_solve(a, NULL); }
    2082             : INLINE GEN
    2083     6345715 : RgM_shallowcopy(GEN x)
    2084             : {
    2085             :   long l;
    2086     6345715 :   GEN y = cgetg_copy(x, &l);
    2087     6345715 :   while (--l > 0) gel(y,l) = leafcopy(gel(x,l));
    2088     6345715 :   return y;
    2089             : }
    2090             : INLINE GEN
    2091        1631 : F2m_copy(GEN x) { return RgM_shallowcopy(x); }
    2092             : 
    2093             : INLINE GEN
    2094      320093 : Flm_copy(GEN x) { return RgM_shallowcopy(x); }
    2095             : 
    2096             : /* divisibility: return 1 if y[i] | x[i] for all i, 0 otherwise. Assume
    2097             :  * x,y are ZV of the same length */
    2098             : INLINE int
    2099       23198 : ZV_dvd(GEN x, GEN y)
    2100             : {
    2101       23198 :   long i, l = lg(x);
    2102       36652 :   for (i=1; i < l; i++)
    2103       29519 :     if ( ! dvdii( gel(x,i), gel(y,i) ) ) return 0;
    2104        7133 :   return 1;
    2105             : }
    2106             : 
    2107             : /* Fq */
    2108             : INLINE GEN
    2109     1360646 : Fq_red(GEN x, GEN T, GEN p)
    2110     1360646 : { return typ(x)==t_INT? Fp_red(x,p): FpXQ_red(x,T,p); }
    2111             : INLINE GEN
    2112       10955 : Fq_to_FpXQ(GEN x, GEN T, GEN p /*unused*/)
    2113             : {
    2114             :   (void) p;
    2115       10955 :   return typ(x)==t_INT ? scalarpol(x, get_FpX_var(T)): x;
    2116             : }
    2117             : 
    2118             : INLINE GEN
    2119         511 : gener_Fq_local(GEN T, GEN p, GEN L)
    2120         511 : { return T? gener_FpXQ_local(T,p, L)
    2121         511 :           : pgener_Fp_local(p, L); }
    2122             : 
    2123             : /* FpXQX */
    2124             : INLINE GEN
    2125         917 : FpXQX_div(GEN x, GEN y, GEN T, GEN p) { return FpXQX_divrem(x, y, T, p, NULL); }
    2126             : INLINE GEN
    2127       32326 : FlxqX_div(GEN x, GEN y, GEN T, ulong p) { return FlxqX_divrem(x, y, T, p, NULL); }
    2128             : INLINE GEN
    2129       29631 : F2xqX_div(GEN x, GEN y, GEN T) { return F2xqX_divrem(x, y, T, NULL); }
    2130             : 
    2131             : /* FqX */
    2132             : INLINE GEN
    2133        9541 : FqX_red(GEN z, GEN T, GEN p) { return T? FpXQX_red(z, T, p): FpX_red(z, p); }
    2134             : INLINE GEN
    2135      904235 : FqX_add(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2136             : INLINE GEN
    2137       16438 : FqX_neg(GEN x,GEN T,GEN p) { return T? FpXX_neg(x,p): FpX_neg(x,p); }
    2138             : INLINE GEN
    2139        2380 : FqX_sub(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2140             : INLINE GEN
    2141      531048 : FqX_Fp_mul(GEN P, GEN u, GEN T, GEN p)
    2142      531048 : { return T? FpXX_Fp_mul(P, u, p): FpX_Fp_mul(P, u, p); }
    2143             : INLINE GEN
    2144      553861 : FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p)
    2145      553861 : { return typ(U)==t_INT ? FqX_Fp_mul(P, U, T, p): FpXQX_FpXQ_mul(P, U, T, p); }
    2146             : INLINE GEN
    2147       84034 : FqX_mul(GEN x, GEN y, GEN T, GEN p)
    2148       84034 : { return T? FpXQX_mul(x, y, T, p): FpX_mul(x, y, p); }
    2149             : INLINE GEN
    2150      459861 : FqX_mulu(GEN x, ulong y, GEN T, GEN p)
    2151      459861 : { return T? FpXX_mulu(x, y, p): FpX_mulu(x, y, p); }
    2152             : INLINE GEN
    2153        4928 : FqX_sqr(GEN x, GEN T, GEN p)
    2154        4928 : { return T? FpXQX_sqr(x, T, p): FpX_sqr(x, p); }
    2155             : INLINE GEN
    2156        1428 : FqX_powu(GEN x, ulong n, GEN T, GEN p)
    2157        1428 : { return T? FpXQX_powu(x, n, T, p): FpX_powu(x, n, p); }
    2158             : INLINE GEN
    2159        6244 : FqX_div(GEN x, GEN y, GEN T, GEN p)
    2160        6244 : { return T? FpXQX_divrem(x,y,T,p,NULL): FpX_divrem(x,y,p,NULL); }
    2161             : INLINE GEN
    2162        5605 : FqX_get_red(GEN S, GEN T, GEN p)
    2163        5605 : { return T? FpXQX_get_red(S,T,p): FpX_get_red(S,p); }
    2164             : INLINE GEN
    2165       48289 : FqX_rem(GEN x, GEN y, GEN T, GEN p)
    2166       48289 : { return T? FpXQX_rem(x,y,T,p): FpX_rem(x,y,p); }
    2167             : INLINE GEN
    2168         329 : FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2169         329 : { return T? FpXQX_divrem(x,y,T,p,z): FpX_divrem(x,y,p,z); }
    2170             : INLINE GEN
    2171        5957 : FqX_div_by_X_x(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2172        5957 : { return T? FpXQX_div_by_X_x(x,y,T,p,z): FpX_div_by_X_x(x,y,p,z); }
    2173             : INLINE GEN
    2174      258538 : FqX_gcd(GEN P,GEN Q,GEN T,GEN p)
    2175      258538 : {return T? FpXQX_gcd(P,Q,T,p): FpX_gcd(P,Q,p);}
    2176             : INLINE GEN
    2177       39748 : FqX_extgcd(GEN P,GEN Q,GEN T,GEN p, GEN *U, GEN *V)
    2178       39748 : { return T? FpXQX_extgcd(P,Q,T,p,U,V): FpX_extgcd(P,Q,p,U,V); }
    2179             : INLINE GEN
    2180       11427 : FqX_normalize(GEN z, GEN T, GEN p) { return T? FpXQX_normalize(z, T, p): FpX_normalize(z, p); }
    2181             : INLINE GEN
    2182      266868 : FqX_deriv(GEN f, /*unused*/GEN T, GEN p) { (void)T; return FpXX_deriv(f, p); }
    2183             : INLINE GEN
    2184       70665 : FqX_factor(GEN f, GEN T, GEN p) { return T?FpXQX_factor(f, T, p): FpX_factor(f, p); }
    2185             : INLINE GEN
    2186        3500 : FqX_roots(GEN f, GEN T, GEN p) { return T?FpXQX_roots(f, T, p): FpX_roots(f, p); }
    2187             : 
    2188             : /*FqXQ*/
    2189             : INLINE GEN
    2190           0 : FqXQ_add(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2191           0 : { (void)S; return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2192             : INLINE GEN
    2193           0 : FqXQ_sub(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2194           0 : { (void)S; return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2195             : INLINE GEN
    2196           0 : FqXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p)
    2197           0 : { return T? FpXQXQ_div(x,y,S,T,p): FpXQ_div(x,y,S,p); }
    2198             : INLINE GEN
    2199           0 : FqXQ_inv(GEN x, GEN S, GEN T, GEN p)
    2200           0 : { return T? FpXQXQ_inv(x,S,T,p): FpXQ_inv(x,S,p); }
    2201             : INLINE GEN
    2202           0 : FqXQ_invsafe(GEN x, GEN S, GEN T, GEN p)
    2203           0 : { return T? FpXQXQ_invsafe(x,S,T,p): FpXQ_inv(x,S,p); }
    2204             : INLINE GEN
    2205       21018 : FqXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p)
    2206       21018 : { return T? FpXQXQ_mul(x,y,S,T,p): FpXQ_mul(x,y,S,p); }
    2207             : INLINE GEN
    2208           0 : FqXQ_sqr(GEN x, GEN S, GEN T, GEN p)
    2209           0 : { return T? FpXQXQ_sqr(x,S,T,p): FpXQ_sqr(x,S,p); }
    2210             : INLINE GEN
    2211           0 : FqXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p)
    2212           0 : { return T? FpXQXQ_pow(x,n,S,T,p): FpXQ_pow(x,n,S,p); }
    2213             : 
    2214             : /*FpXQ*/
    2215             : INLINE GEN
    2216           0 : FpXQ_add(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2217           0 : { (void)T; return FpX_add(x,y,p); }
    2218             : INLINE GEN
    2219           0 : FpXQ_sub(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2220           0 : { (void)T; return FpX_sub(x,y,p); }
    2221             : 
    2222             : /*Flxq*/
    2223             : INLINE GEN
    2224           0 : Flxq_add(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2225           0 : { (void)T; return Flx_add(x,y,p); }
    2226             : INLINE GEN
    2227           0 : Flxq_sub(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2228           0 : { (void)T; return Flx_sub(x,y,p); }
    2229             : 
    2230             : /* F2x */
    2231             : 
    2232             : INLINE ulong
    2233   104425278 : F2x_coeff(GEN x,long v)
    2234             : {
    2235   104425278 :    ulong u=(ulong)x[2+divsBIL(v)];
    2236   104425614 :    return (u>>remsBIL(v))&1UL;
    2237             : }
    2238             : 
    2239             : INLINE void
    2240     2164299 : F2x_clear(GEN x,long v)
    2241             : {
    2242     2164299 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2243     2164299 :    *u&=~(1UL<<remsBIL(v));
    2244     2164299 : }
    2245             : 
    2246             : INLINE void
    2247    33573319 : F2x_set(GEN x,long v)
    2248             : {
    2249    33573319 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2250    33573306 :    *u|=1UL<<remsBIL(v);
    2251    33573210 : }
    2252             : 
    2253             : INLINE void
    2254      356059 : F2x_flip(GEN x,long v)
    2255             : {
    2256      356059 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2257      356059 :    *u^=1UL<<remsBIL(v);
    2258      356059 : }
    2259             : 
    2260             : /* F2v */
    2261             : 
    2262             : INLINE ulong
    2263   100875761 : F2v_coeff(GEN x,long v) { return F2x_coeff(x,v-1); }
    2264             : 
    2265             : INLINE void
    2266     2164299 : F2v_clear(GEN x,long v) { F2x_clear(x,v-1); }
    2267             : 
    2268             : INLINE void
    2269    13697829 : F2v_set(GEN x,long v)   { F2x_set(x,v-1); }
    2270             : 
    2271             : INLINE void
    2272      356059 : F2v_flip(GEN x,long v) { F2x_flip(x,v-1); }
    2273             : 
    2274             : /* F2m */
    2275             : 
    2276             : INLINE ulong
    2277    12073918 : F2m_coeff(GEN x, long a, long b) { return F2v_coeff(gel(x,b), a); }
    2278             : 
    2279             : INLINE void
    2280           0 : F2m_clear(GEN x, long a, long b) { F2v_clear(gel(x,b), a); }
    2281             : 
    2282             : INLINE void
    2283     1603119 : F2m_set(GEN x, long a, long b) { F2v_set(gel(x,b), a); }
    2284             : 
    2285             : INLINE void
    2286      356059 : F2m_flip(GEN x, long a, long b) { F2v_flip(gel(x,b), a); }
    2287             : 
    2288             : /* ARITHMETIC */
    2289             : INLINE GEN
    2290         938 : matpascal(long n) { return matqpascal(n, NULL); }
    2291             : INLINE long
    2292     1975097 : Z_issquare(GEN x) { return Z_issquareall(x, NULL); }
    2293             : INLINE long
    2294          14 : Z_ispower(GEN x, ulong k) { return Z_ispowerall(x, k, NULL); }
    2295             : INLINE GEN
    2296     4547626 : sqrti(GEN x) { return sqrtremi(x,NULL); }
    2297             : INLINE GEN
    2298     7315349 : gaddgs(GEN y, long s) { return gaddsg(s,y); }
    2299             : INLINE int
    2300       24114 : gcmpgs(GEN y, long s) { return -gcmpsg(s,y); }
    2301             : INLINE int
    2302       22960 : gequalgs(GEN y, long s) { return gequalsg(s,y); }
    2303             : INLINE GEN
    2304           0 : gmaxsg(long s, GEN y) { return gmaxgs(y,s); }
    2305             : INLINE GEN
    2306           0 : gminsg(long s, GEN y) { return gmings(y,s); }
    2307             : INLINE GEN
    2308     5766490 : gmulgs(GEN y, long s) { return gmulsg(s,y); }
    2309             : INLINE GEN
    2310      613982 : gsubgs(GEN y, long s) { return gaddgs(y, -s); }
    2311             : INLINE GEN
    2312      436034 : gdivsg(long s, GEN y) { return gdiv(stoi(s), y); }
    2313             : 
    2314             : /* x t_COMPLEX */
    2315             : INLINE GEN
    2316     8182008 : cxnorm(GEN x) { return gadd(gsqr(gel(x,1)), gsqr(gel(x,2))); }
    2317             : /* q t_QUAD */
    2318             : INLINE GEN
    2319         623 : quadnorm(GEN q)
    2320             : {
    2321         623 :   GEN X = gel(q,1), b = gel(X,3), c = gel(X,2);
    2322         623 :   GEN z, u = gel(q,3), v = gel(q,2);
    2323         623 :   if (typ(u) == t_INT && typ(v) == t_INT) /* generic case */
    2324             :   {
    2325         308 :     z = signe(b)? mulii(v, addii(u,v)): sqri(v);
    2326         308 :     return addii(z, mulii(c, sqri(u)));
    2327             :   }
    2328             :   else
    2329             :   {
    2330         315 :     z = signe(b)? gmul(v, gadd(u,v)): gsqr(v);
    2331         315 :     return gadd(z, gmul(c, gsqr(u)));
    2332             :   }
    2333             : }
    2334             : /* x a t_QUAD, return the attached discriminant */
    2335             : INLINE GEN
    2336         252 : quad_disc(GEN x)
    2337             : {
    2338         252 :   GEN Q = gel(x,1), b = gel(Q,3), c = gel(Q,2), c4;
    2339         252 :   if (is_pm1(b))
    2340             :   {
    2341         196 :     pari_sp av = avma; (void)new_chunk(lgefint(c) + 1);
    2342         196 :     c4 = shifti(c,2); avma = av; return subsi(1, c4);
    2343             :   }
    2344          56 :   c4 = shifti(c,2); togglesign_safe(&c4); return c4;
    2345             : }
    2346             : INLINE GEN
    2347     6011782 : qfb_disc3(GEN x, GEN y, GEN z) { return subii(sqri(y), shifti(mulii(x,z),2)); }
    2348             : INLINE GEN
    2349     5919942 : qfb_disc(GEN x) { return qfb_disc3(gel(x,1), gel(x,2), gel(x,3)); }
    2350             : 
    2351             : INLINE GEN
    2352     1006315 : sqrfrac(GEN x)
    2353             : {
    2354     1006315 :   GEN z = cgetg(3,t_FRAC);
    2355     1006315 :   gel(z,1) = sqri(gel(x,1));
    2356     1006315 :   gel(z,2) = sqri(gel(x,2)); return z;
    2357             : }
    2358             : 
    2359             : INLINE void
    2360     8254075 : normalize_frac(GEN z) {
    2361     8254075 :   if (signe(gel(z,2)) < 0) { togglesign(gel(z,1)); setabssign(gel(z,2)); }
    2362     8254075 : }
    2363             : 
    2364             : INLINE GEN
    2365      382153 : powii(GEN x, GEN n)
    2366             : {
    2367      382153 :   long ln = lgefint(n);
    2368      382153 :   if (ln == 3) {
    2369             :     GEN z;
    2370      379423 :     if (signe(n) > 0) return powiu(x, n[2]);
    2371        2387 :     z = cgetg(3, t_FRAC);
    2372        2387 :     gel(z,1) = gen_1;
    2373        2387 :     gel(z,2) = powiu(x, n[2]);
    2374        2387 :     return z;
    2375             :   }
    2376        2730 :   if (ln == 2) return gen_1; /* rare */
    2377             :   /* should never happen */
    2378           0 :   return powgi(x, n); /* overflow unless x = 0, 1, -1 */
    2379             : }
    2380             : INLINE GEN
    2381         819 : powIs(long n) {
    2382         819 :   switch(n & 3)
    2383             :   {
    2384           7 :     case 1: return mkcomplex(gen_0,gen_1);
    2385         315 :     case 2: return gen_m1;
    2386         448 :     case 3: return mkcomplex(gen_0,gen_m1);
    2387             :   }
    2388          49 :   return gen_1;
    2389             : }
    2390             : 
    2391             : /*******************************************************************/
    2392             : /*                                                                 */
    2393             : /*                             ASSIGNMENTS                         */
    2394             : /*                                                                 */
    2395             : /*******************************************************************/
    2396           0 : INLINE void mpexpz(GEN x, GEN z)
    2397           0 : { pari_sp av = avma; gaffect(mpexp(x), z); avma = av; }
    2398           0 : INLINE void mplogz(GEN x, GEN z)
    2399           0 : { pari_sp av = avma; gaffect(mplog(x), z); avma = av; }
    2400           0 : INLINE void mpcosz(GEN x, GEN z)
    2401           0 : { pari_sp av = avma; gaffect(mpcos(x), z); avma = av; }
    2402           0 : INLINE void mpsinz(GEN x, GEN z)
    2403           0 : { pari_sp av = avma; gaffect(mpsin(x), z); avma = av; }
    2404           0 : INLINE void gnegz(GEN x, GEN z)
    2405           0 : { pari_sp av = avma; gaffect(gneg(x), z); avma = av; }
    2406           0 : INLINE void gabsz(GEN x, long prec, GEN z)
    2407           0 : { pari_sp av = avma; gaffect(gabs(x,prec), z); avma = av; }
    2408       23318 : INLINE void gaddz(GEN x, GEN y, GEN z)
    2409       23318 : { pari_sp av = avma; gaffect(gadd(x,y), z); avma = av; }
    2410           0 : INLINE void gsubz(GEN x, GEN y, GEN z)
    2411           0 : { pari_sp av = avma; gaffect(gsub(x,y), z); avma = av; }
    2412       11673 : INLINE void gmulz(GEN x, GEN y, GEN z)
    2413       11673 : { pari_sp av = avma; gaffect(gmul(x,y), z); avma = av; }
    2414           0 : INLINE void gdivz(GEN x, GEN y, GEN z)
    2415           0 : { pari_sp av = avma; gaffect(gdiv(x,y), z); avma = av; }
    2416           0 : INLINE void gdiventz(GEN x, GEN y, GEN z)
    2417           0 : { pari_sp av = avma; gaffect(gdivent(x,y), z); avma = av; }
    2418           0 : INLINE void gmodz(GEN x, GEN y, GEN z)
    2419           0 : { pari_sp av = avma; gaffect(gmod(x,y), z); avma = av; }
    2420           0 : INLINE void gmul2nz(GEN x, long s, GEN z)
    2421           0 : { pari_sp av = avma; gaffect(gmul2n(x,s), z); avma = av; }
    2422           0 : INLINE void gshiftz(GEN x, long s, GEN z)
    2423           0 : { pari_sp av = avma; gaffect(gshift(x,s), z); avma = av; }
    2424             : 
    2425             : /*******************************************************************/
    2426             : /*                                                                 */
    2427             : /*                       ELLIPTIC CURVES                           */
    2428             : /*                                                                 */
    2429             : /*******************************************************************/
    2430     4961610 : INLINE GEN ell_get_a1(GEN e) { return gel(e,1); }
    2431     3255478 : INLINE GEN ell_get_a2(GEN e) { return gel(e,2); }
    2432     4434939 : INLINE GEN ell_get_a3(GEN e) { return gel(e,3); }
    2433     4053919 : INLINE GEN ell_get_a4(GEN e) { return gel(e,4); }
    2434     4627121 : INLINE GEN ell_get_a6(GEN e) { return gel(e,5); }
    2435     3946164 : INLINE GEN ell_get_b2(GEN e) { return gel(e,6); }
    2436     1008239 : INLINE GEN ell_get_b4(GEN e) { return gel(e,7); }
    2437     1611611 : INLINE GEN ell_get_b6(GEN e) { return gel(e,8); }
    2438     1455972 : INLINE GEN ell_get_b8(GEN e) { return gel(e,9); }
    2439     6320356 : INLINE GEN ell_get_c4(GEN e) { return gel(e,10); }
    2440     8302287 : INLINE GEN ell_get_c6(GEN e) { return gel(e,11); }
    2441     9781975 : INLINE GEN ell_get_disc(GEN e) { return gel(e,12); }
    2442     1173683 : INLINE GEN ell_get_j(GEN e) { return gel(e,13); }
    2443     7479016 : INLINE long ell_get_type(GEN e) { return mael(e,14,1); }
    2444      795837 : INLINE GEN ellff_get_field(GEN x) { return gmael(x, 15, 1); }
    2445      314068 : INLINE GEN ellff_get_a4a6(GEN x)  { return gmael(x, 15, 2); }
    2446         637 : INLINE GEN ellQp_get_zero(GEN x) { return gmael(x, 15, 1); }
    2447         147 : INLINE long ellQp_get_prec(GEN E) { GEN z = ellQp_get_zero(E); return valp(z); }
    2448         483 : INLINE GEN ellQp_get_p(GEN E) { GEN z = ellQp_get_zero(E); return gel(z,2); }
    2449       36512 : INLINE long ellR_get_prec(GEN x) { return nbits2prec(mael3(x, 15, 1, 1)); }
    2450        1318 : INLINE long ellR_get_sign(GEN x) { return mael3(x, 15, 1, 2); }
    2451      521038 : INLINE GEN ellnf_get_nf(GEN x) { return checknf_i(gmael(x,15,1)); }
    2452          28 : INLINE GEN ellnf_get_bnf(GEN x) { return checkbnf_i(gmael(x,15,1)); }
    2453             : 
    2454    31299688 : INLINE int ell_is_inf(GEN z) { return lg(z) == 2; }
    2455      625080 : INLINE GEN ellinf(void) { return mkvec(gen_0); }
    2456             : 
    2457             : /*******************************************************************/
    2458             : /*                                                                 */
    2459             : /*                    ALGEBRAIC NUMBER THEORY                      */
    2460             : /*                                                                 */
    2461             : /*******************************************************************/
    2462     6668675 : INLINE GEN modpr_get_pr(GEN x)  { return gel(x,3); }
    2463      602258 : INLINE GEN modpr_get_p(GEN x)  { return pr_get_p(modpr_get_pr(x)); }
    2464     1944341 : INLINE GEN modpr_get_T(GEN x)  { return lg(x) == 4? NULL: gel(x,4); }
    2465             : 
    2466    16212222 : INLINE GEN pr_get_p(GEN pr)  { return gel(pr,1); }
    2467     2147789 : INLINE GEN pr_get_gen(GEN pr){ return gel(pr,2); }
    2468             : /* .[2] instead of itos works: e and f are small positive integers */
    2469     3040435 : INLINE long pr_get_e(GEN pr) { return gel(pr,3)[2]; }
    2470     6443278 : INLINE long pr_get_f(GEN pr) { return gel(pr,4)[2]; }
    2471     5314521 : INLINE GEN pr_get_tau(GEN pr){ return gel(pr,5); }
    2472             : INLINE int
    2473      640301 : pr_is_inert(GEN P) { return pr_get_f(P) == lg(pr_get_gen(P))-1; }
    2474             : INLINE GEN
    2475      357904 : pr_norm(GEN pr) { return powiu(pr_get_p(pr), pr_get_f(pr)); }
    2476             : 
    2477             : /* assume nf a genuine nf */
    2478             : INLINE long
    2479        7363 : nf_get_varn(GEN nf) { return varn(gel(nf,1)); }
    2480             : INLINE GEN
    2481     8765098 : nf_get_pol(GEN nf) { return gel(nf,1); }
    2482             : INLINE long
    2483     4169133 : nf_get_degree(GEN nf) { return degpol( nf_get_pol(nf) ); }
    2484             : INLINE long
    2485     1074887 : nf_get_r1(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,1)); }
    2486             : INLINE long
    2487        1057 : nf_get_r2(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,2)); }
    2488             : INLINE GEN
    2489       23620 : nf_get_disc(GEN nf) { return gel(nf,3); }
    2490             : INLINE GEN
    2491      738884 : nf_get_index(GEN nf) { return gel(nf,4); }
    2492             : INLINE GEN
    2493      971322 : nf_get_M(GEN nf) { return gmael(nf,5,1); }
    2494             : INLINE GEN
    2495       43943 : nf_get_G(GEN nf) { return gmael(nf,5,2); }
    2496             : INLINE GEN
    2497      377899 : nf_get_roundG(GEN nf) { return gmael(nf,5,3); }
    2498             : INLINE GEN
    2499         798 : nf_get_Tr(GEN nf) { return gmael(nf,5,4); }
    2500             : INLINE GEN
    2501         812 : nf_get_diff(GEN nf) { return gmael(nf,5,5); }
    2502             : INLINE GEN
    2503          21 : nf_get_ramified_primes(GEN nf) { return gmael(nf,5,8); }
    2504             : INLINE GEN
    2505       97918 : nf_get_roots(GEN nf) { return gel(nf,6); }
    2506             : INLINE GEN
    2507     8548639 : nf_get_zk(GEN nf) { return gel(nf,7); }
    2508             : INLINE GEN
    2509     1770276 : nf_get_invzk(GEN nf) { return gel(nf,8); }
    2510             : INLINE void
    2511        5988 : nf_get_sign(GEN nf, long *r1, long *r2)
    2512             : {
    2513        5988 :   GEN x = gel(nf,2);
    2514        5988 :   *r1 = itou(gel(x,1));
    2515        5988 :   *r2 = itou(gel(x,2));
    2516        5988 : }
    2517             : 
    2518             : INLINE GEN
    2519       10052 : abgrp_get_no(GEN x) { return gel(x,1); }
    2520             : INLINE GEN
    2521     1028311 : abgrp_get_cyc(GEN x) { return gel(x,2); }
    2522             : INLINE GEN
    2523      273153 : abgrp_get_gen(GEN x) { return gel(x,3); }
    2524             : INLINE GEN
    2525     1184319 : bnf_get_nf(GEN bnf) { return gel(bnf,7); }
    2526             : INLINE GEN
    2527      560117 : bnf_get_clgp(GEN bnf) { return gmael(bnf,8,1); }
    2528             : INLINE GEN
    2529         987 : bnf_get_no(GEN bnf) { return abgrp_get_no(bnf_get_clgp(bnf)); }
    2530             : INLINE GEN
    2531      293313 : bnf_get_cyc(GEN bnf) { return abgrp_get_cyc(bnf_get_clgp(bnf)); }
    2532             : INLINE GEN
    2533      265663 : bnf_get_gen(GEN bnf)  { return abgrp_get_gen(bnf_get_clgp(bnf)); }
    2534             : INLINE GEN
    2535         671 : bnf_get_reg(GEN bnf) { return gmael(bnf,8,2); }
    2536             : INLINE GEN
    2537      429392 : bnf_get_logfu(GEN bnf) { return gel(bnf,3); }
    2538             : INLINE GEN
    2539        2450 : bnf_get_tuU(GEN bnf) { return gmael3(bnf,8,4,2); }
    2540             : INLINE long
    2541        8519 : bnf_get_tuN(GEN bnf) { return gmael3(bnf,8,4,1)[2]; }
    2542             : INLINE GEN
    2543        1631 : bnf_get_fu(GEN bnf) {
    2544        1631 :   GEN fu = bnf_get_fu_nocheck(bnf);
    2545        1631 :   if (typ(fu) == t_MAT) pari_err(e_MISC,"missing units in bnf");
    2546        1631 :   return fu;
    2547             : }
    2548             : INLINE GEN
    2549        3437 : bnf_get_fu_nocheck(GEN bnf) { return gmael(bnf,8,5); }
    2550             : 
    2551             : INLINE GEN
    2552      400886 : bnr_get_bnf(GEN bnr) { return gel(bnr,1); }
    2553             : INLINE GEN
    2554      198420 : bnr_get_bid(GEN bnr) { return gel(bnr,2); }
    2555             : INLINE GEN
    2556       10990 : bnr_get_mod(GEN bnr) { return gmael(bnr,2,1); }
    2557             : INLINE GEN
    2558        3955 : bnr_get_nf(GEN bnr) { return gmael(bnr,1,7); }
    2559             : INLINE GEN
    2560      231082 : bnr_get_clgp(GEN bnr) { return gel(bnr,5); }
    2561             : INLINE GEN
    2562        9065 : bnr_get_no(GEN bnr) { return abgrp_get_no(bnr_get_clgp(bnr)); }
    2563             : INLINE GEN
    2564      219385 : bnr_get_cyc(GEN bnr) { return abgrp_get_cyc(bnr_get_clgp(bnr)); }
    2565             : INLINE GEN
    2566          70 : bnr_get_gen_nocheck(GEN bnr) { return abgrp_get_gen(bnr_get_clgp(bnr)); }
    2567             : INLINE GEN
    2568        2562 : bnr_get_gen(GEN bnr) {
    2569        2562 :   GEN G = bnr_get_clgp(bnr);
    2570        2562 :   if (lg(G) !=  4)
    2571           0 :     pari_err(e_MISC,"missing bnr generators: please use bnrinit(,,1)");
    2572        2562 :   return gel(G,3);
    2573             : }
    2574             : 
    2575             : INLINE GEN
    2576      367359 : bid_get_mod(GEN bid) { return gel(bid,1); }
    2577             : INLINE GEN
    2578       83742 : bid_get_ideal(GEN bid) { return gmael(bid,1,1); }
    2579             : INLINE GEN
    2580       96037 : bid_get_arch(GEN bid) { return gmael(bid,1,2); }
    2581             : INLINE GEN
    2582      520961 : bid_get_grp(GEN bid) { return gel(bid,2); }
    2583             : INLINE GEN
    2584      140764 : bid_get_fact(GEN bid) { return gel(bid,3); }
    2585             : INLINE GEN
    2586      421655 : bid_get_U(GEN bid) { return gel(bid,5); }
    2587             : INLINE GEN
    2588           0 : bid_get_no(GEN bid) { return abgrp_get_no(bid_get_grp(bid)); }
    2589             : INLINE GEN
    2590      514318 : bid_get_cyc(GEN bid) { return abgrp_get_cyc(bid_get_grp(bid)); }
    2591             : INLINE GEN
    2592           0 : bid_get_gen_nocheck(GEN bid)  { return abgrp_get_gen(bid_get_grp(bid)); }
    2593             : INLINE GEN
    2594        6125 : bid_get_gen(GEN bid) {
    2595        6125 :   GEN G = bid_get_grp(bid);
    2596        6125 :   if (lg(G) != 4) pari_err(e_MISC,"missing bid generators. Use idealstar(,,2)");
    2597        6125 :   return abgrp_get_gen(G);
    2598             : }
    2599             : INLINE GEN
    2600         973 : gal_get_pol(GEN gal) { return gel(gal,1); }
    2601             : INLINE GEN
    2602         980 : gal_get_p(GEN gal) { return gmael(gal,2,1); }
    2603             : INLINE GEN
    2604          56 : gal_get_e(GEN gal) { return gmael(gal,2,2); }
    2605             : INLINE GEN
    2606        1813 : gal_get_mod(GEN gal) { return gmael(gal,2,3); }
    2607             : INLINE GEN
    2608        2191 : gal_get_roots(GEN gal) { return gel(gal,3); }
    2609             : INLINE GEN
    2610        1820 : gal_get_invvdm(GEN gal) { return gel(gal,4); }
    2611             : INLINE GEN
    2612        1820 : gal_get_den(GEN gal) { return gel(gal,5); }
    2613             : INLINE GEN
    2614        3829 : gal_get_group(GEN gal) { return gel(gal,6); }
    2615             : INLINE GEN
    2616        1218 : gal_get_gen(GEN gal) { return gel(gal,7); }
    2617             : INLINE GEN
    2618         763 : gal_get_orders(GEN gal) { return gel(gal,8); }
    2619             : 
    2620             : /* assume rnf a genuine rnf */
    2621             : INLINE long
    2622      310751 : rnf_get_degree(GEN rnf) { return degpol(rnf_get_pol(rnf)); }
    2623             : INLINE long
    2624       14728 : rnf_get_nfdegree(GEN rnf) { return degpol(nf_get_pol(rnf_get_nf(rnf))); }
    2625             : INLINE long
    2626      156254 : rnf_get_absdegree(GEN rnf) { return degpol(gmael(rnf,11,1)); }
    2627             : INLINE GEN
    2628         427 : rnf_get_idealdisc(GEN rnf) { return gmael(rnf,3,1); }
    2629             : INLINE GEN
    2630         455 : rnf_get_k(GEN rnf) { return gmael(rnf,11,3); }
    2631             : INLINE GEN
    2632         455 : rnf_get_alpha(GEN rnf) { return gmael(rnf, 11, 2); }
    2633             : INLINE GEN
    2634      123319 : rnf_get_nf(GEN rnf) { return gel(rnf,10); }
    2635             : INLINE void
    2636        1652 : rnf_get_nfzk(GEN rnf, GEN *b, GEN *cb) {*b=gmael(rnf,2,1); *cb=gmael(rnf,2,2);}
    2637             : INLINE GEN
    2638       93408 : rnf_get_polabs(GEN rnf) { return gmael(rnf,11,1); }
    2639             : INLINE GEN
    2640      462119 : rnf_get_pol(GEN rnf) { return gel(rnf,1); }
    2641             : INLINE GEN
    2642          63 : rnf_get_disc(GEN rnf) { return gel(rnf,3); }
    2643             : INLINE GEN
    2644         105 : rnf_get_index(GEN rnf) { return gel(rnf,4); }
    2645             : INLINE long
    2646           0 : rnf_get_varn(GEN rnf) { return varn(gel(rnf,1)); }
    2647             : INLINE GEN
    2648      106295 : rnf_get_nfpol(GEN rnf) { return gmael(rnf,10,1); }
    2649             : INLINE long
    2650         490 : rnf_get_nfvarn(GEN rnf) { return varn(gmael(rnf,10,1)); }
    2651             : INLINE GEN
    2652        2415 : rnf_get_zk(GEN rnf) { return gel(rnf,7); }
    2653             : INLINE GEN
    2654       33936 : rnf_get_map(GEN rnf) { return gel(rnf,11); }
    2655             : INLINE GEN
    2656        1190 : rnf_get_invzk(GEN rnf) { return gel(rnf,8); }
    2657             : 
    2658             : /* I integral ZM (not HNF), G ZM, rounded Cholesky form of a weighted
    2659             :  * T2 matrix. Reduce I wrt G */
    2660             : INLINE GEN
    2661        1316 : idealpseudored(GEN I, GEN G)
    2662        1316 : { return ZM_mul(I, ZM_lll(ZM_mul(G, I), 0.99, LLL_IM)); }
    2663             : 
    2664             : /* I integral (not necessarily HNF), G ZM, rounded Cholesky form of a weighted
    2665             :  * T2 matrix. Return m in I with T2(m) small */
    2666             : INLINE GEN
    2667      162170 : idealpseudomin(GEN I, GEN G)
    2668             : {
    2669      162170 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2670      162170 :   return ZM_ZC_mul(I, gel(u,1));
    2671             : }
    2672             : /* I, G as in idealpseudomin. Return an irrational m in I with T2(m) small */
    2673             : INLINE GEN
    2674      252067 : idealpseudomin_nonscalar(GEN I, GEN G)
    2675             : {
    2676      252067 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2677      252067 :   GEN m = ZM_ZC_mul(I, gel(u,1));
    2678      252067 :   if (ZV_isscalar(m) && lg(u) > 2) m = ZM_ZC_mul(I, gel(u,2));
    2679      252067 :   return m;
    2680             : }
    2681             : 
    2682             : INLINE GEN
    2683         238 : idealred_elt(GEN nf, GEN I) {
    2684         238 :   pari_sp av = avma;
    2685         238 :   GEN u = idealpseudomin(I, nf_get_roundG(nf));
    2686         238 :   return gerepileupto(av, u);
    2687             : }
    2688             : INLINE GEN
    2689      166903 : idealred(GEN nf, GEN I) { return idealred0(nf, I, NULL); }
    2690             : 
    2691             : INLINE GEN
    2692        1197 : idealchineseinit(GEN nf, GEN x)
    2693        1197 : { return idealchinese(nf,x,NULL); }
    2694             : 
    2695             : /*******************************************************************/
    2696             : /*                                                                 */
    2697             : /*                              CLOSURES                           */
    2698             : /*                                                                 */
    2699             : /*******************************************************************/
    2700   186201585 : INLINE long closure_arity(GEN C)          { return ((ulong)C[1])&ARITYBITS; }
    2701    34410608 : INLINE long closure_is_variadic(GEN C) { return !!(((ulong)C[1])&VARARGBITS); }
    2702   151618267 : INLINE const char *closure_codestr(GEN C)  { return GSTR(gel(C,2))-1; }
    2703           0 : INLINE GEN closure_get_code(GEN C)  { return gel(C,2); }
    2704   151586876 : INLINE GEN closure_get_oper(GEN C)  { return gel(C,3); }
    2705   151560232 : INLINE GEN closure_get_data(GEN C)  { return gel(C,4); }
    2706       16260 : INLINE GEN closure_get_dbg(GEN C)   { return gel(C,5); }
    2707       34473 : INLINE GEN closure_get_text(GEN C)  { return gel(C,6); }
    2708      607459 : INLINE GEN closure_get_frame(GEN C) { return gel(C,7); }
    2709             : 
    2710             : /*******************************************************************/
    2711             : /*                                                                 */
    2712             : /*                               ERRORS                            */
    2713             : /*                                                                 */
    2714             : /*******************************************************************/
    2715             : INLINE long
    2716       45997 : err_get_num(GEN e) { return e[1]; }
    2717             : INLINE GEN
    2718          70 : err_get_compo(GEN e, long i) { return gel(e, i+1); }
    2719             : 
    2720             : INLINE void
    2721          14 : pari_err_BUG(const char *f) { pari_err(e_BUG,f); }
    2722             : INLINE void
    2723           7 : pari_err_CONSTPOL(const char *f) { pari_err(e_CONSTPOL, f); }
    2724             : INLINE void
    2725          63 : pari_err_COPRIME(const char *f, GEN x, GEN y) { pari_err(e_COPRIME, f,x,y); }
    2726             : INLINE void
    2727         890 : pari_err_DIM(const char *f) { pari_err(e_DIM, f); }
    2728             : INLINE void
    2729           0 : pari_err_FILE(const char *f, const char *g) { pari_err(e_FILE, f,g); }
    2730             : INLINE void
    2731          21 : pari_err_FLAG(const char *f) { pari_err(e_FLAG,f); }
    2732             : INLINE void
    2733         238 : pari_err_IMPL(const char *f) { pari_err(e_IMPL,f); }
    2734             : INLINE void
    2735         571 : pari_err_INV(const char *f, GEN x) { pari_err(e_INV,f,x); }
    2736             : INLINE void
    2737          14 : pari_err_IRREDPOL(const char *f, GEN x) { pari_err(e_IRREDPOL, f,x); }
    2738             : INLINE void
    2739        5096 : 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); }
    2740             : INLINE void
    2741         224 : pari_err_COMPONENT(const char *f, const char *op, GEN l, GEN x) { pari_err(e_COMPONENT, f,op,l,x); }
    2742             : INLINE void
    2743           0 : pari_err_MAXPRIME(ulong c) { pari_err(e_MAXPRIME, c); }
    2744             : INLINE void
    2745         294 : pari_err_OP(const char *f, GEN x, GEN y) { pari_err(e_OP, f,x,y); }
    2746             : INLINE void
    2747          63 : pari_err_OVERFLOW(const char *f) { pari_err(e_OVERFLOW, f); }
    2748             : INLINE void
    2749         225 : pari_err_PREC(const char *f) { pari_err(e_PREC,f); }
    2750             : INLINE void
    2751           0 : pari_err_PACKAGE(const char *f) { pari_err(e_PACKAGE,f); }
    2752             : INLINE void
    2753          56 : pari_err_PRIME(const char *f, GEN x) { pari_err(e_PRIME, f,x); }
    2754             : INLINE void
    2755         721 : pari_err_MODULUS(const char *f, GEN x, GEN y) { pari_err(e_MODULUS, f,x,y); }
    2756             : INLINE void
    2757          35 : pari_err_ROOTS0(const char *f) { pari_err(e_ROOTS0, f); }
    2758             : INLINE void
    2759          77 : pari_err_SQRTN(const char *f, GEN x) { pari_err(e_SQRTN, f,x); }
    2760             : INLINE void
    2761       24159 : pari_err_TYPE(const char *f, GEN x) { pari_err(e_TYPE, f,x); }
    2762             : INLINE void
    2763        3010 : pari_err_TYPE2(const char *f, GEN x, GEN y) { pari_err(e_TYPE2, f,x,y); }
    2764             : INLINE void
    2765         196 : pari_err_VAR(const char *f, GEN x, GEN y) { pari_err(e_VAR, f,x,y); }
    2766             : INLINE void
    2767         119 : pari_err_PRIORITY(const char *f, GEN x, const char *op, long v)
    2768         119 : { pari_err(e_PRIORITY, f,x,op,v); }

Generated by: LCOV version 1.11