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 19199-979caa2) Lines: 1190 1340 88.8 %
Date: 2016-07-24 07:10:30 Functions: 503 568 88.6 %
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      336396 : 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      355306 : mkpolmod(GEN x, GEN y) { retmkpolmod(x,y); }
     145             : INLINE GEN
     146      327530 : mkfrac(GEN x, GEN y) { retmkfrac(x,y); }
     147             : INLINE GEN
     148     2387564 : 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     2918901 : mkcomplex(GEN x, GEN y) { retmkcomplex(x,y); }
     157             : INLINE GEN
     158      424998 : gen_I(void) { return mkcomplex(gen_0, gen_1); }
     159             : INLINE GEN
     160      193356 : 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    55879748 : mkvecsmall(long x) { GEN v = cgetg(2, t_VECSMALL); v[1] = x; return v; }
     167             : INLINE GEN
     168   109347678 : mkvecsmall2(long x,long y) { GEN v = cgetg(3, t_VECSMALL);
     169   109354677 :   v[1]=x; v[2]=y; return v; }
     170             : INLINE GEN
     171    65638640 : mkvecsmall3(long x,long y,long z) { GEN v = cgetg(4, t_VECSMALL);
     172    65632589 :   v[1]=x; v[2]=y; v[3]=z; return v; }
     173             : INLINE GEN
     174     9501724 : mkvecsmall4(long x,long y,long z,long t) { GEN v = cgetg(5, t_VECSMALL);
     175     9495652 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; return v; }
     176             : INLINE GEN
     177      584985 : mkvecsmall5(long x,long y,long z,long t,long u) { GEN v = cgetg(6, t_VECSMALL);
     178      584986 :   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     3188427 : mkvec(GEN x) { retmkvec(x); }
     185             : INLINE GEN
     186    20568042 : mkvec2(GEN x, GEN y) { retmkvec2(x,y); }
     187             : INLINE GEN
     188    65077550 : mkvec3(GEN x, GEN y, GEN z) { retmkvec3(x,y,z); }
     189             : INLINE GEN
     190     7546731 : mkvec4(GEN x, GEN y, GEN z, GEN t) { retmkvec4(x,y,z,t); }
     191             : INLINE GEN
     192    11763807 : 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       11543 : 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      258395 : mkvec2copy(GEN x, GEN y) {
     205      258395 :   GEN v = cgetg(3,t_VEC); gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     206             : /* col */
     207             : INLINE GEN
     208     2122018 : mkcol(GEN x) { retmkcol(x); }
     209             : INLINE GEN
     210    14760235 : 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           0 : 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       27078 : mkcolcopy(GEN x) { GEN v = cgetg(2, t_COL); gel(v,1) = gcopy(x); return v; }
     229             : /* mat */
     230             : INLINE GEN
     231      218031 : mkmat(GEN x) { retmkmat(x); }
     232             : INLINE GEN
     233    16634388 : 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        7616 : 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       11687 : mkoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_1; return v; }
     246             : INLINE GEN
     247        7287 : mkmoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_m1; return v; }
     248             : INLINE long
     249       25733 : inf_get_sign(GEN x) { return signe(gel(x,1)); }
     250             : /* pol */
     251             : INLINE GEN
     252      700369 : pol_x(long v) {
     253      700369 :   GEN p = cgetg(4, t_POL);
     254      700369 :   p[1] = evalsigne(1)|evalvarn(v);
     255      700369 :   gel(p,2) = gen_0;
     256      700369 :   gel(p,3) = gen_1; return p;
     257             : }
     258             : INLINE GEN
     259     1209101 : pol_1(long v) {
     260     1209101 :   GEN p = cgetg(3, t_POL);
     261     1209101 :   p[1] = evalsigne(1)|evalvarn(v);
     262     1209101 :   gel(p,2) = gen_1; return p;
     263             : }
     264             : INLINE GEN
     265    14058457 : pol_0(long v)
     266             : {
     267    14058457 :   GEN x = cgetg(2,t_POL);
     268    14058457 :   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     9525437 : 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       23886 : const_col(long n, GEN x) { retconst_col(n, x); }
     284             : INLINE GEN
     285     5114945 : const_vecsmall(long n, long c)
     286             : {
     287             :   long i;
     288     5114945 :   GEN V = cgetg(n+1,t_VECSMALL);
     289     5114945 :   for(i=1;i<=n;i++) V[i] = c;
     290     5114945 :   return V;
     291             : }
     292             : 
     293             : /***   ZERO   ***/
     294             : /* O(p^e) */
     295             : INLINE GEN
     296      292124 : zeropadic(GEN p, long e)
     297             : {
     298      292124 :   GEN y = cgetg(5,t_PADIC);
     299      292124 :   gel(y,4) = gen_0;
     300      292124 :   gel(y,3) = gen_1;
     301      292124 :   gel(y,2) = icopy(p);
     302      292124 :   y[1] = evalvalp(e) | _evalprecp(0);
     303      292124 :   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       12054 : zeroser(long v, long e)
     318             : {
     319       12054 :   GEN x = cgetg(2, t_SER);
     320       12054 :   x[1] = evalvalp(e) | evalvarn(v); return x;
     321             : }
     322             : INLINE int
     323     3752278 : ser_isexactzero(GEN x)
     324             : {
     325     3752278 :   if (!signe(x)) switch(lg(x))
     326             :   {
     327       10458 :     case 2: return 1;
     328         252 :     case 3: return isexactzero(gel(x,2));
     329             :   }
     330     3741568 :   return 0;
     331             : }
     332             : /* 0 * pol_x(v) */
     333             : INLINE GEN
     334     4668476 : zeropol(long v) { return pol_0(v); }
     335             : /* vector(n) */
     336             : INLINE GEN
     337    26723138 : zerocol(long n)
     338             : {
     339    26723138 :   GEN y = cgetg(n+1,t_COL);
     340    26723138 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     341    26723138 :   return y;
     342             : }
     343             : /* vectorv(n) */
     344             : INLINE GEN
     345     7608326 : zerovec(long n)
     346             : {
     347     7608326 :   GEN y = cgetg(n+1,t_VEC);
     348     7608329 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     349     7608329 :   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      290856 : zero_Flx(long sv) { return pol0_Flx(sv); }
     363             : INLINE GEN
     364    27128165 : zero_Flv(long n)
     365             : {
     366    27128165 :   GEN y = cgetg(n+1,t_VECSMALL);
     367    27128178 :   long i; for (i=1; i<=n; i++) y[i] = 0;
     368    27128178 :   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      103717 : zero_Flm_copy(long m, long n)
     382             : {
     383      103717 :   GEN y = cgetg(n+1,t_MAT);
     384      103721 :   long i; for (i=1; i<=n; i++) gel(y,i) = zero_Flv(m);
     385      103724 :   return y;
     386             : }
     387             : 
     388             : INLINE GEN
     389      581850 : zero_F2v(long m)
     390             : {
     391      581850 :   long l = nbits2nlong(m);
     392      581850 :   GEN v  = zero_Flv(l+1);
     393      581850 :   v[1] = m;
     394      581850 :   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      107073 : zero_F2m_copy(long m, long n)
     411             : {
     412             :   long i;
     413      107073 :   GEN M = cgetg(n+1, t_MAT);
     414      445144 :   for (i = 1; i <= n; i++)
     415      338071 :     gel(M,i)= zero_F2v(m);
     416      107073 :   return M;
     417             : }
     418             : 
     419             : /* matrix(m, n) */
     420             : INLINE GEN
     421     2362671 : zeromatcopy(long m, long n)
     422             : {
     423     2362671 :   GEN y = cgetg(n+1,t_MAT);
     424     2362671 :   long i; for (i=1; i<=n; i++) gel(y,i) = zerocol(m);
     425     2362671 :   return y;
     426             : }
     427             : 
     428             : /* i-th vector in the standard basis */
     429             : INLINE GEN
     430     1943242 : col_ei(long n, long i) { GEN e = zerocol(n); gel(e,i) = gen_1; return e; }
     431             : INLINE GEN
     432      300931 : 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     3619093 : Rg_col_ei(GEN x, long n, long i) { GEN e = zerocol(n); gel(e,i) = x; return e; }
     439             : 
     440             : INLINE GEN
     441     1496310 : shallowcopy(GEN x)
     442     1496310 : { return typ(x) == t_MAT ? RgM_shallowcopy(x): leafcopy(x); }
     443             : 
     444             : /* routines for naive growarrays */
     445             : INLINE GEN
     446    11522804 : vectrunc_init(long l)
     447             : {
     448    11522804 :   GEN z = new_chunk(l);
     449    11523025 :   z[0] = evaltyp(t_VEC) | _evallg(1); return z;
     450             : }
     451             : INLINE void
     452    43058447 : vectrunc_append(GEN x, GEN t)
     453    43058447 : { 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     1299372 : vecsmalltrunc_init(long l)
     464             : {
     465     1299372 :   GEN z = new_chunk(l);
     466     1299372 :   z[0] = evaltyp(t_VECSMALL) | _evallg(1); return z;
     467             : }
     468             : INLINE void
     469     2552250 : vecsmalltrunc_append(GEN x, long t)
     470     2552250 : { 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       10570 : vec_lengthen(GEN v, long n)
     489             : {
     490             :   long i;
     491       10570 :   long l=lg(v);
     492       10570 :   GEN V = cgetg(n+1,t_VEC);
     493       10570 :   for(i=1;i<l;i++) gel(V,i) = gel(v,i);
     494       10570 :   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      132518 : vecsmall_shorten(GEN v, long n)
     515             : {
     516             :   long i;
     517      132518 :   GEN V = cgetg(n+1,t_VECSMALL);
     518      132520 :   for(i=1;i<=n;i++) V[i] = v[i];
     519      132520 :   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      231684 : vec_to_vecsmall(GEN z)
     532             : {
     533      231684 :   long i, l = lg(z);
     534      231684 :   GEN x = cgetg(l, t_VECSMALL);
     535      231684 :   for (i=1; i<l; i++) x[i] = itos(gel(z,i));
     536      231684 :   return x;
     537             : }
     538             : INLINE GEN
     539       15218 : vecsmall_to_vec(GEN z)
     540             : {
     541       15218 :   long i, l = lg(z);
     542       15218 :   GEN x = cgetg(l,t_VEC);
     543       15218 :   for (i=1; i<l; i++) gel(x,i) = stoi(z[i]);
     544       15218 :   return x;
     545             : }
     546             : INLINE GEN
     547     1130724 : vecsmall_to_col(GEN z)
     548             : {
     549     1130724 :   long i, l = lg(z);
     550     1130724 :   GEN x = cgetg(l,t_COL);
     551     1130724 :   for (i=1; i<l; i++) gel(x,i) = stoi(z[i]);
     552     1130724 :   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        1120 : vecsmall_prepend(GEN V, long s)
     579             : {
     580        1120 :   long i, l2 = lg(V);
     581        1120 :   GEN res = cgetg(l2+1, typ(V));
     582        1120 :   res[1] = s;
     583        1120 :   for (i = 2; i <= l2; ++i) res[i] = V[i - 1];
     584        1120 :   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       50968 : vecsmall_max(GEN x)
     645             : {
     646       50968 :   long i, t = x[1], lx = lg(x);
     647       80347 :   for (i=2; i<lx; i++)
     648       29379 :     if (x[i] > t) t = x[i];
     649       50968 :   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     1476534 : ZV_isscalar(GEN x)
     672             : {
     673     1476534 :   long l = lg(x);
     674     5638409 :   while (--l > 1)
     675     3781724 :     if (signe(gel(x, l))) return 0;
     676      380151 :   return 1;
     677             : }
     678             : INLINE int
     679     6439228 : QV_isscalar(GEN x)
     680             : {
     681     6439228 :   long lx = lg(x),i;
     682     8692650 :   for (i=2; i<lx; i++)
     683     8032371 :     if (!isintzero(gel(x, i))) return 0;
     684      660279 :   return 1;
     685             : }
     686             : INLINE int
     687        8196 : RgV_isscalar(GEN x)
     688             : {
     689        8196 :   long lx = lg(x),i;
     690       17373 :   for (i=2; i<lx; i++)
     691       12291 :     if (!gequal0(gel(x, i))) return 0;
     692        5082 :   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     7316612 : RgX_equal_var(GEN x, GEN y) { return varn(x) == varn(y) && RgX_equal(x,y); }
     704             : 
     705             : INLINE int
     706        2667 : RgX_is_rational(GEN x)
     707             : {
     708             :   long i;
     709       24717 :   for (i = lg(x)-1; i > 1; i--)
     710       23261 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     711        1456 :   return 1;
     712             : }
     713             : INLINE int
     714    57485717 : RgX_is_ZX(GEN x)
     715             : {
     716             :   long i;
     717   251114944 :   for (i = lg(x)-1; i > 1; i--)
     718   199179577 :     if (typ(gel(x,i)) != t_INT) return 0;
     719    51935367 :   return 1;
     720             : }
     721             : INLINE int
     722      159365 : RgX_is_QX(GEN x)
     723             : {
     724      159365 :   long k = lg(x)-1;
     725      628633 :   for ( ; k>1; k--)
     726      470122 :     if (!is_rational_t(typ(gel(x,k)))) return 0;
     727      158511 :   return 1;
     728             : }
     729             : INLINE int
     730    15102998 : RgX_is_monomial(GEN x)
     731             : {
     732             :   long i;
     733    15102998 :   if (!signe(x)) return 0;
     734    24282517 :   for (i=lg(x)-2; i>1; i--)
     735    16782133 :     if (!isexactzero(gel(x,i))) return 0;
     736     7500384 :   return 1;
     737             : }
     738             : INLINE int
     739     2426461 : RgV_is_ZV(GEN x)
     740             : {
     741             :   long i;
     742     8599069 :   for (i = lg(x)-1; i > 0; i--)
     743     6173273 :     if (typ(gel(x,i)) != t_INT) return 0;
     744     2425796 :   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   330447352 : pari_stack_base(pari_stack *s) { return s->data; }
     762             : 
     763             : INLINE void
     764     2819369 : pari_stack_init(pari_stack *s, size_t size, void **data)
     765             : {
     766     2819369 :   s->data = data;
     767     2819369 :   *data = NULL;
     768     2819369 :   s->n = 0;
     769     2819369 :   s->alloc = 0;
     770     2819369 :   s->size = size;
     771     2819369 : }
     772             : 
     773             : INLINE void
     774   327936403 : pari_stack_alloc(pari_stack *s, long nb)
     775             : {
     776   327936403 :   void **sdat = pari_stack_base(s);
     777   656080886 :   if (s->n+nb <= s->alloc) return;
     778      760928 :   if (!s->alloc)
     779      716979 :     s->alloc = nb;
     780             :   else
     781             :   {
     782       43949 :     while (s->n+nb > s->alloc) s->alloc <<= 1;
     783             :   }
     784      760928 :   *sdat = pari_realloc(*sdat,s->alloc*s->size);
     785             : }
     786             : 
     787             : INLINE long
     788   274180482 : pari_stack_new(pari_stack *s) { pari_stack_alloc(s, 1); return s->n++; }
     789             : 
     790             : INLINE void
     791     2425150 : pari_stack_delete(pari_stack *s)
     792             : {
     793     2425150 :   void **sdat = pari_stack_base(s);
     794     2424584 :   if (*sdat) free(*sdat);
     795     2424584 : }
     796             : 
     797             : INLINE void
     798        5452 : pari_stack_pushp(pari_stack *s, void *u)
     799             : {
     800        5452 :   long n = pari_stack_new(s);
     801        5452 :   void **sdat =(void**) *pari_stack_base(s);
     802        5452 :   sdat[n] = u;
     803        5452 : }
     804             : 
     805             : /*******************************************************************/
     806             : /*                                                                 */
     807             : /*                            EXTRACT                              */
     808             : /*                                                                 */
     809             : /*******************************************************************/
     810             : INLINE GEN
     811     4060942 : vecslice(GEN A, long y1, long y2)
     812             : {
     813     4060942 :   long i,lB = y2 - y1 + 2;
     814     4060942 :   GEN B = cgetg(lB, typ(A));
     815     4060942 :   for (i=1; i<lB; i++) B[i] = A[y1-1+i];
     816     4060942 :   return B;
     817             : }
     818             : INLINE GEN
     819      130350 : vecslicepermute(GEN A, GEN p, long y1, long y2)
     820             : {
     821      130350 :   long i,lB = y2 - y1 + 2;
     822      130350 :   GEN B = cgetg(lB, typ(A));
     823      130350 :   for (i=1; i<lB; i++) B[i] = A[p[y1-1+i]];
     824      130350 :   return B;
     825             : }
     826             : /* rowslice(rowpermute(A,p), x1, x2) */
     827             : INLINE GEN
     828       32670 : rowslicepermute(GEN A, GEN p, long x1, long x2)
     829             : {
     830       32670 :   long i, lB = lg(A);
     831       32670 :   GEN B = cgetg(lB, typ(A));
     832       32670 :   for (i=1; i<lB; i++) gel(B,i) = vecslicepermute(gel(A,i),p,x1,x2);
     833       32670 :   return B;
     834             : }
     835             : INLINE GEN
     836      186987 : rowslice(GEN A, long x1, long x2)
     837             : {
     838      186987 :   long i, lB = lg(A);
     839      186987 :   GEN B = cgetg(lB, typ(A));
     840      186987 :   for (i=1; i<lB; i++) gel(B,i) = vecslice(gel(A,i),x1,x2);
     841      186987 :   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      115618 : row(GEN A, long x0)
     875             : {
     876      115618 :   long i, lB = lg(A);
     877      115618 :   GEN B  = cgetg(lB, t_VEC);
     878      115618 :   for (i=1; i<lB; i++) gel(B, i) = gcoeff(A, x0, i);
     879      115618 :   return B;
     880             : }
     881             : INLINE GEN
     882       23502 : Flm_row(GEN A, long x0)
     883             : {
     884       23502 :   long i, lB = lg(A);
     885       23502 :   GEN B  = cgetg(lB, t_VECSMALL);
     886       23502 :   for (i=1; i<lB; i++) B[i] = coeff(A, x0, i);
     887       23502 :   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     4759630 : vecreverse(GEN A)
     910             : {
     911             :   long i, l;
     912     4759630 :   GEN B = cgetg_copy(A, &l);
     913     4759630 :   for (i=1; i<l; i++) gel(B, i) = gel(A, l-i);
     914     4759630 :   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    20074387 : vecsmallpermute(GEN A, GEN p) { return perm_mul(A, p); }
     940             : 
     941             : INLINE GEN
     942     4954242 : vecpermute(GEN A, GEN p)
     943             : {
     944     4954242 :   long i,lB = lg(p);
     945     4954242 :   GEN B = cgetg(lB, typ(A));
     946     4954242 :   for (i=1; i<lB; i++) gel(B, i) = gel(A, p[i]);
     947     4954242 :   return B;
     948             : }
     949             : INLINE GEN
     950      244047 : rowpermute(GEN A, GEN p)
     951             : {
     952      244047 :   long i, lB = lg(A);
     953      244047 :   GEN B = cgetg(lB, typ(A));
     954     2212318 :   for (i=1; i<lB; i++)
     955     3898245 :     gel(B, i) = typ(gel(A,i)) == t_VECSMALL ? vecsmallpermute(gel(A, i), p):
     956     1929974 :                                                     vecpermute(gel(A, i), p);
     957      244047 :   return B;
     958             : }
     959             : /*******************************************************************/
     960             : /*                                                                 */
     961             : /*                          PERMUTATIONS                           */
     962             : /*                                                                 */
     963             : /*******************************************************************/
     964             : /* identity permutation */
     965             : INLINE GEN
     966       67284 : identity_perm(long n)
     967             : {
     968       67284 :   GEN perm = cgetg(n+1, t_VECSMALL);
     969             :   long i;
     970       67284 :   for (i = 1; i <= n; i++) perm[i] = i;
     971       67284 :   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    20514729 : perm_mul(GEN s, GEN t)
     988             : {
     989             :   GEN u;
     990    20514729 :   long i, l = lg(t);
     991    20514729 :   u = cgetg(l, t_VECSMALL);
     992    20514729 :   for (i = 1; i < l; i++) u[i] = s[ t[i] ];
     993    20514729 :   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    54955818 : pari_free(void *pointer)
    1042             : {
    1043    54955818 :   BLOCK_SIGINT_START;
    1044    54955849 :   free(pointer);
    1045    54955849 :   BLOCK_SIGINT_END;
    1046    54955847 : }
    1047             : INLINE void*
    1048   192773293 : pari_malloc(size_t size)
    1049             : {
    1050   192773293 :   if (size)
    1051             :   {
    1052             :     char *tmp;
    1053   192773293 :     BLOCK_SIGINT_START;
    1054   192775772 :     tmp = (char*)malloc(size);
    1055   192775772 :     BLOCK_SIGINT_END;
    1056   192775814 :     if (!tmp) pari_err(e_MEM);
    1057   192775814 :     return tmp;
    1058             :   }
    1059           0 :   if (DEBUGMEM) pari_warn(warner,"mallocing NULL object");
    1060           0 :   return NULL;
    1061             : }
    1062             : INLINE void*
    1063      765779 : pari_realloc(void *pointer, size_t size)
    1064             : {
    1065             :   char *tmp;
    1066             : 
    1067      765779 :   BLOCK_SIGINT_START;
    1068      768254 :   if (!pointer) tmp = (char *) malloc(size);
    1069       47290 :   else tmp = (char *) realloc(pointer,size);
    1070      768254 :   BLOCK_SIGINT_END;
    1071      767448 :   if (!tmp) pari_err(e_MEM);
    1072      767448 :   return tmp;
    1073             : }
    1074             : INLINE void*
    1075       28544 : pari_calloc(size_t size)
    1076             : {
    1077       28544 :   void *t = pari_malloc(size);
    1078       28544 :   memset(t, 0, size); return t;
    1079             : }
    1080             : INLINE GEN
    1081        4847 : cgetalloc(long t, size_t l)
    1082             : {
    1083        4847 :   GEN x = (GEN)pari_malloc(l * sizeof(long));
    1084        4847 :   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  3658050538 : icopy_avma(GEN x, pari_sp av)
    1095             : {
    1096  3658050538 :   long i = lgefint(x), lx = i;
    1097  3658050538 :   GEN y = ((GEN)av) - i;
    1098  3658050538 :   while (--i > 0) y[i] = x[i];
    1099  3658050538 :   y[0] = evaltyp(t_INT)|evallg(lx);
    1100  3657955556 :   return y;
    1101             : }
    1102             : /* copy leaf x as if we had avma = av */
    1103             : INLINE GEN
    1104    99205570 : leafcopy_avma(GEN x, pari_sp av)
    1105             : {
    1106    99205570 :   long i = lg(x);
    1107    99205570 :   GEN y = ((GEN)av) - i;
    1108    99205570 :   while (--i > 0) y[i] = x[i];
    1109    99205570 :   y[0] = x[0] & (~CLONEBIT);
    1110    99205570 :   return y;
    1111             : }
    1112             : INLINE GEN
    1113   557789907 : gerepileuptoleaf(pari_sp av, GEN x)
    1114             : {
    1115             :   long lx;
    1116             :   GEN q;
    1117             : 
    1118   557789907 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1119   558524939 :   lx = lg(x);
    1120   558524939 :   q = ((GEN)av) - lx;
    1121   558524939 :   avma = (pari_sp)q;
    1122   558524939 :   while (--lx >= 0) q[lx] = x[lx];
    1123   558524939 :   return q;
    1124             : }
    1125             : INLINE GEN
    1126  1082545165 : gerepileuptoint(pari_sp av, GEN x)
    1127             : {
    1128  1082545165 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1129   826159973 :   avma = (pari_sp)icopy_avma(x, av);
    1130   826442366 :   return (GEN)avma;
    1131             : }
    1132             : INLINE GEN
    1133   627182724 : gerepileupto(pari_sp av, GEN x)
    1134             : {
    1135   627182724 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1136   565607857 :   switch(typ(x))
    1137             :   { /* non-default = !is_recursive_t(tq) */
    1138   167444683 :     case t_INT: return gerepileuptoint(av, x);
    1139             :     case t_REAL:
    1140             :     case t_STR:
    1141   115471365 :     case t_VECSMALL: return gerepileuptoleaf(av,x);
    1142             :     default:
    1143             :       /* NB: x+i --> ((long)x) + i*sizeof(long) */
    1144   282691809 :       return gerepile(av, (pari_sp) (x+lg(x)), x);
    1145             :   }
    1146             : }
    1147             : 
    1148             : /* gerepileupto(av, gcopy(x)) */
    1149             : INLINE GEN
    1150    34347904 : gerepilecopy(pari_sp av, GEN x)
    1151             : {
    1152    34347904 :   if (is_recursive_t(typ(x)))
    1153             :   {
    1154    28224875 :     GENbin *p = copy_bin(x);
    1155    28224877 :     avma = av; return bin_copy(p);
    1156             :   }
    1157             :   else
    1158             :   {
    1159     6123882 :     avma = av;
    1160     6123882 :     if (x < (GEN)av) {
    1161     4802031 :       if (x < (GEN)pari_mainstack->bot) new_chunk(lg(x));
    1162     4802031 :       x = leafcopy_avma(x, av);
    1163     4813185 :       avma = (pari_sp)x;
    1164             :     } else
    1165     1321851 :       x = leafcopy(x);
    1166     6137870 :     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       68267 : gerepilemany(pari_sp av, GEN* gptr[], int n)
    1175             : {
    1176             :   int i;
    1177       68267 :   for (i=0; i<n; i++) *gptr[i] = (GEN)copy_bin(*gptr[i]);
    1178       68267 :   avma = av;
    1179       68267 :   for (i=0; i<n; i++) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1180       68267 : }
    1181             : 
    1182             : INLINE void
    1183     8995546 : gerepileall(pari_sp av, int n, ...)
    1184             : {
    1185             :   int i;
    1186     8995546 :   va_list a; va_start(a, n);
    1187     8995546 :   if (n < 10)
    1188             :   {
    1189             :     GEN *gptr[10];
    1190    27222601 :     for (i=0; i<n; i++)
    1191    18227047 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1192     8995554 :     avma = av;
    1193     8995554 :     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     8995556 : }
    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    46628345 : bin_copy(GENbin *p)
    1219             : {
    1220             :   GEN x, y, base;
    1221             :   long dx, len;
    1222             : 
    1223    46628345 :   x   = p->x; if (!x) { pari_free(p); return gen_0; }
    1224    46626369 :   len = p->len;
    1225    46626369 :   base= p->base; dx = x - base;
    1226    46626369 :   y = (GEN)memcpy((void*)new_chunk(len), (void*)GENbinbase(p), len*sizeof(long));
    1227    46626375 :   y += dx;
    1228    46626375 :   p->rebase(y, ((ulong)y-(ulong)x));
    1229    46626383 :   pari_free(p); return y;
    1230             : }
    1231             : 
    1232             : INLINE GEN
    1233    93254728 : GENbinbase(GENbin *p) { return (GEN)(p + 1); }
    1234             : 
    1235             : INLINE void
    1236    27730469 : cgiv(GEN x)
    1237             : {
    1238    27730469 :   pari_sp av = (pari_sp)(x+lg(x));
    1239    27730469 :   if (isonstack((GEN)av)) avma = av;
    1240    27730469 : }
    1241             : 
    1242             : INLINE void
    1243     1364127 : killblock(GEN x) { gunclone(x); }
    1244             : 
    1245             : INLINE int
    1246    17166105 : 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     1979878 : cxcompotor(GEN z, long prec)
    1256             : {
    1257     1979878 :   switch(typ(z))
    1258             :   {
    1259     1015096 :     case t_INT:  return itor(z, prec);
    1260      134120 :     case t_FRAC: return fractor(z, prec);
    1261      830662 :     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      988255 : cxtofp(GEN x, long prec)
    1267      988255 : { retmkcomplex(cxcompotor(gel(x,1),prec), cxcompotor(gel(x,2),prec)); }
    1268             : 
    1269             : INLINE double
    1270    25456040 : gtodouble(GEN x)
    1271             : {
    1272    25456040 :   if (typ(x)!=t_REAL) {
    1273     4897749 :     pari_sp av = avma;
    1274     4897749 :     x = gtofp(x, DEFAULTPREC);
    1275     4897749 :     if (typ(x)!=t_REAL) pari_err_TYPE("gtodouble [t_REAL expected]", x);
    1276     4897749 :     avma = av;
    1277             :   }
    1278    25456040 :   return rtodbl(x);
    1279             : }
    1280             : INLINE long
    1281    64432827 : gtos(GEN x) {
    1282    64432827 :   if (typ(x) != t_INT) pari_err_TYPE("gtos [integer expected]",x);
    1283    64432820 :   return itos(x);
    1284             : }
    1285             : 
    1286             : INLINE ulong
    1287       83195 : gtou(GEN x) {
    1288       83195 :   if (typ(x) != t_INT || signe(x)<0)
    1289           0 :     pari_err_TYPE("gtou [integer >=0 expected]",x);
    1290       83384 :   return itou(x);
    1291             : }
    1292             : 
    1293             : INLINE GEN
    1294     1918422 : absfrac(GEN x)
    1295             : {
    1296     1918422 :   GEN y = cgetg(3, t_FRAC);
    1297     1918422 :   gel(y,1) = absi(gel(x,1));
    1298     1918422 :   gel(y,2) = icopy(gel(x,2)); return y;
    1299             : }
    1300             : INLINE GEN
    1301       11473 : absfrac_shallow(GEN x)
    1302       11473 : { return signe(gel(x,1))>0? x: mkfrac(negi(gel(x,1)), gel(x,2)); }
    1303             : INLINE GEN
    1304      618081 : Q_abs(GEN x) { return (typ(x) == t_INT)? absi(x): absfrac(x); }
    1305             : INLINE GEN
    1306       38310 : Q_abs_shallow(GEN x)
    1307       38310 : { 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    20144197 : gtofp(GEN z, long prec)
    1318             : {
    1319    20144197 :   switch(typ(z))
    1320             :   {
    1321     9937104 :     case t_INT:  return itor(z, prec);
    1322     4965645 :     case t_FRAC: return fractor(z, prec);
    1323     4425098 :     case t_REAL: return rtor(z, prec);
    1324             :     case t_COMPLEX: {
    1325      816350 :       GEN a = gel(z,1), b = gel(z,2);
    1326      816350 :       if (isintzero(b)) return cxcompotor(a, prec);
    1327      814664 :       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      813024 :       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      480523 : RgX_gtofp(GEN x, long prec)
    1356             : {
    1357             :   long l;
    1358      480523 :   GEN y = cgetg_copy(x, &l);
    1359      480523 :   while (--l > 1) gel(y,l) = gtofp(gel(x,l), prec);
    1360      480523 :   y[1] = x[1]; return y;
    1361             : }
    1362             : INLINE GEN
    1363      379967 : RgC_gtofp(GEN x, long prec)
    1364             : {
    1365      379967 :   long l = lg(x);
    1366      379967 :   GEN y = cgetg(l, t_COL);
    1367      379967 :   while (--l > 0) gel(y,l) = gtofp(gel(x,l), prec);
    1368      379967 :   return y;
    1369             : }
    1370             : INLINE GEN
    1371       19277 : RgM_gtofp(GEN x, long prec)
    1372             : {
    1373             :   long l;
    1374       19277 :   GEN y = cgetg_copy(x, &l);
    1375       19277 :   while (--l > 0) gel(y,l) = RgC_gtofp(gel(x,l), prec);
    1376       19277 :   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       10995 : RgX_fpnorml2(GEN x, long prec)
    1397             : {
    1398       10995 :   pari_sp av = avma;
    1399       10995 :   return gerepileupto(av, gnorml2(RgX_gtofp(x, prec)));
    1400             : }
    1401             : INLINE GEN
    1402      243642 : RgC_fpnorml2(GEN x, long prec)
    1403             : {
    1404      243642 :   pari_sp av = avma;
    1405      243642 :   return gerepileupto(av, gnorml2(RgC_gtofp(x, prec)));
    1406             : }
    1407             : INLINE GEN
    1408        1617 : RgM_fpnorml2(GEN x, long prec)
    1409             : {
    1410        1617 :   pari_sp av = avma;
    1411        1617 :   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      183562 : affc_fixlg(GEN x, GEN res)
    1430             : {
    1431      183562 :   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        8254 :     avma = (pari_sp)(res+3);
    1439        8254 :     res = cgetr(realprec(gel(res,1)));
    1440        8254 :     affrr_fixlg(x, res);
    1441             :   }
    1442      183562 :   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       22708 : ndec2nlong(long x) { return 1 + (long)((x)*(LOG2_10/BITS_IN_LONG)); }
    1455             : INLINE long
    1456       22265 : 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      803213 : nbits2nlong(long x) {
    1464      803213 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1465             : }
    1466             : 
    1467             : INLINE long
    1468   268358791 : nbits2extraprec(long x) {
    1469   268358791 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1470             : }
    1471             : 
    1472             : /* Fast implementation of 2 + nbits2nlong(x) */
    1473             : INLINE long
    1474    78831906 : nbits2prec(long x) {
    1475    78831906 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1476             : }
    1477             : INLINE long
    1478     3369380 : nbits2lg(long x) {
    1479     3369380 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1480             : }
    1481             : /* ceil(x / sizeof(long)) */
    1482             : INLINE long
    1483     6897806 : nchar2nlong(long x) {
    1484     6897806 :   return (long)(((ulong)x+sizeof(long)-1) >> (TWOPOTBITS_IN_LONG-3L));
    1485             : }
    1486             : INLINE long
    1487  1156135807 : prec2nbits(long x) { return (x-2) * BITS_IN_LONG; }
    1488             : INLINE double
    1489      450785 : bit_accuracy_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1490             : INLINE double
    1491      253703 : prec2nbits_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1492             : INLINE long
    1493    26177418 : bit_prec(GEN x) { return prec2nbits(realprec(x)); }
    1494             : INLINE long
    1495  1072058383 : 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        1679 : precdbl(long x) {return (x - 1) << 1;}
    1502             : INLINE long
    1503  3565592145 : divsBIL(long n) { return n >> TWOPOTBITS_IN_LONG; }
    1504             : INLINE long
    1505  3496054039 : 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     1210614 : Fp_red(GEN a, GEN m) { return modii(a, m); }
    1516             : INLINE GEN
    1517   302324898 : Fp_add(GEN a, GEN b, GEN m)
    1518             : {
    1519   302324898 :   pari_sp av=avma;
    1520   302324898 :   GEN p = addii(a,b);
    1521   302308898 :   long s = signe(p);
    1522   302308898 :   if (!s) return p; /* = gen_0 */
    1523   148302432 :   if (s > 0) /* general case */
    1524             :   {
    1525   148084487 :     GEN t = subii(p, m);
    1526   148097037 :     s = signe(t);
    1527   148097037 :     if (!s) { avma = av; return gen_0; }
    1528   137661565 :     if (s < 0) { avma = (pari_sp)p; return p; }
    1529    24339452 :     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    45912565 : Fp_sub(GEN a, GEN b, GEN m)
    1538             : {
    1539    45912565 :   pari_sp av=avma;
    1540    45912565 :   GEN p = subii(a,b);
    1541    45987686 :   long s = signe(p);
    1542    45987686 :   if (!s) return p; /* = gen_0 */
    1543    39031765 :   if (s > 0)
    1544             :   {
    1545    18978854 :     if (cmpii(p, m) < 0) return p; /* general case ! */
    1546      742252 :     p = remii(p, m);
    1547             :   }
    1548             :   else
    1549             :   {
    1550    20052911 :     GEN t = addii(p, m);
    1551    20038253 :     if (!s) { avma = av; return gen_0; }
    1552    20038253 :     if (s > 0) return gerepileuptoint(av, t); /* general case ! */
    1553    20038253 :     p = modii(t, m);
    1554             :   }
    1555    20775084 :   return gerepileuptoint(av, p);
    1556             : }
    1557             : INLINE GEN
    1558     9973177 : Fp_neg(GEN b, GEN m)
    1559             : {
    1560     9973177 :   pari_sp av = avma;
    1561     9973177 :   long s = signe(b);
    1562             :   GEN p;
    1563     9973177 :   if (!s) return gen_0;
    1564     7183970 :   if (s > 0)
    1565             :   {
    1566     7183270 :     p = subii(m, b);
    1567     7183010 :     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     5628474 : Fp_center(GEN u, GEN p, GEN ps2)
    1584     5628474 : { return absi_cmp(u,ps2)<=0? icopy(u): subii(u,p); }
    1585             : 
    1586             : /* x + y*z mod p */
    1587             : INLINE GEN
    1588     2143884 : Fp_addmul(GEN x, GEN y, GEN z, GEN p)
    1589             : {
    1590             :   pari_sp av;
    1591     2143884 :   if (!signe(y) || !signe(z)) return Fp_red(x, p);
    1592     2058617 :   if (!signe(x)) return Fp_mul(z,y, p);
    1593     1771085 :   av = avma;
    1594     1771085 :   return gerepileuptoint(av, modii(addii(x, mulii(y,z)), p));
    1595             : }
    1596             : 
    1597             : INLINE GEN
    1598   284735113 : Fp_mul(GEN a, GEN b, GEN m)
    1599             : {
    1600   284735113 :   pari_sp av=avma;
    1601             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1602   284735113 :   (void)new_chunk(lg(a)+lg(b)+(lg(m)<<1));
    1603   284740498 :   p = mulii(a,b);
    1604   284739021 :   avma = av; return modii(p,m);
    1605             : }
    1606             : INLINE GEN
    1607     6862827 : Fp_sqr(GEN a, GEN m)
    1608             : {
    1609     6862827 :   pari_sp av=avma;
    1610             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1611     6862827 :   (void)new_chunk((lg(a)+lg(m))<<1);
    1612     6902657 :   p = sqri(a);
    1613     6922155 :   avma = av; return modii(p,m);
    1614             : }
    1615             : INLINE GEN
    1616    52347716 : Fp_mulu(GEN a, ulong b, GEN m)
    1617             : {
    1618    52347716 :   long l = lgefint(m);
    1619    52347716 :   if (l == 3)
    1620             :   {
    1621    35342931 :     ulong mm = m[2];
    1622    35342931 :     return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1623             :   } else {
    1624    17004785 :     pari_sp av = avma;
    1625             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1626    17004785 :     (void)new_chunk(lg(a)+1+(l<<1));
    1627    17047523 :     p = muliu(a,b);
    1628    16774761 :     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     7597416 : Fp_inv(GEN a, GEN m)
    1656             : {
    1657             :   GEN res;
    1658     7597416 :   if (! invmod(a,m,&res)) pari_err_INV("Fp_inv", mkintmod(res,m));
    1659     7579108 :   return res;
    1660             : }
    1661             : INLINE GEN
    1662      286002 : Fp_invsafe(GEN a, GEN m)
    1663             : {
    1664             :   GEN res;
    1665      286002 :   if (! invmod(a,m,&res)) return NULL;
    1666      286002 :   return res;
    1667             : }
    1668             : INLINE GEN
    1669     4542316 : Fp_div(GEN a, GEN b, GEN m)
    1670             : {
    1671     4542316 :   pari_sp av=avma;
    1672             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1673     4542316 :   (void)new_chunk(lg(a)+(lg(m)<<1));
    1674     4551766 :   p = mulii(a, Fp_inv(b,m));
    1675     4555005 :   avma = av; return modii(p,m);
    1676             : }
    1677             : 
    1678             : INLINE GEN
    1679      790383 : 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    41252254 : submulii(GEN x, GEN y, GEN z)
    1689             : {
    1690    41252254 :   long lx = lgefint(x), ly, lz;
    1691             :   pari_sp av;
    1692             :   GEN t;
    1693    41252254 :   if (lx == 2) { t = mulii(z,y); togglesign(t); return t; }
    1694    35136758 :   ly = lgefint(y);
    1695    35136758 :   if (ly == 2) return icopy(x);
    1696    33730808 :   lz = lgefint(z);
    1697    33730808 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1698    33730808 :   t = mulii(z, y);
    1699    33730808 :   avma = av; return subii(x,t);
    1700             : }
    1701             : /* y*z - x */
    1702             : INLINE GEN
    1703     1642643 : mulsubii(GEN y, GEN z, GEN x)
    1704             : {
    1705     1642643 :   long lx = lgefint(x), ly, lz;
    1706             :   pari_sp av;
    1707             :   GEN t;
    1708     1642643 :   if (lx == 2) return mulii(z,y);
    1709     1100257 :   ly = lgefint(y);
    1710     1100257 :   if (ly == 2) return negi(x);
    1711     1066642 :   lz = lgefint(z);
    1712     1066642 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1713     1066642 :   t = mulii(z, y);
    1714     1066642 :   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   256100329 : submuliu_inplace(GEN x, GEN y, ulong u)
    1744             : {
    1745             :   pari_sp av;
    1746   256100329 :   long ly = lgefint(y);
    1747   256100329 :   if (ly == 2) return x;
    1748   219178668 :   av = avma;
    1749   219178668 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1750   219178668 :   y = mului(u,y);
    1751   219178668 :   avma = av; return subii(x, y);
    1752             : }
    1753             : /* x + u*y */
    1754             : INLINE GEN
    1755   255443020 : addmuliu_inplace(GEN x, GEN y, ulong u)
    1756             : {
    1757             :   pari_sp av;
    1758   255443020 :   long ly = lgefint(y);
    1759   255443020 :   if (ly == 2) return x;
    1760   219297582 :   av = avma;
    1761   219297582 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1762   219297582 :   y = mului(u,y);
    1763   219297582 :   avma = av; return addii(x, y);
    1764             : }
    1765             : /* ux + vy */
    1766             : INLINE GEN
    1767    17982612 : lincombii(GEN u, GEN v, GEN x, GEN y)
    1768             : {
    1769    17982612 :   long lx = lgefint(x), ly;
    1770             :   GEN p1, p2;
    1771             :   pari_sp av;
    1772    17982612 :   if (lx == 2) return mulii(v,y);
    1773    11413255 :   ly = lgefint(y);
    1774    11413255 :   if (ly == 2) return mulii(u,x);
    1775    10481226 :   av = avma; (void)new_chunk(lx+ly+lgefint(u)+lgefint(v)); /* HACK */
    1776    10481226 :   p1 = mulii(u,x);
    1777    10481226 :   p2 = mulii(v,y);
    1778    10481226 :   avma = av; return addii(p1,p2);
    1779             : }
    1780             : 
    1781             : /*******************************************************************/
    1782             : /*                                                                 */
    1783             : /*                          GEN SUBTYPES                           */
    1784             : /*                                                                 */
    1785             : /*******************************************************************/
    1786             : 
    1787             : INLINE int
    1788   890165247 : is_const_t(long t) { return (t < t_POLMOD); }
    1789             : INLINE int
    1790      627575 : is_extscalar_t(long t) { return (t <= t_POL); }
    1791             : INLINE int
    1792      819223 : is_intreal_t(long t) { return (t <= t_REAL); }
    1793             : INLINE int
    1794   356428235 : is_matvec_t(long t) { return (t >= t_VEC && t <= t_MAT); }
    1795             : INLINE int
    1796    52463488 : is_noncalc_t(long tx) { return (tx) >= t_LIST; }
    1797             : INLINE int
    1798      579835 : 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  2572491571 : is_recursive_t(long t) { return lontyp[t]; }
    1803             : INLINE int
    1804   154976540 : is_scalar_t(long t) { return (t < t_POL); }
    1805             : INLINE int
    1806      415639 : is_vec_t(long t) { return (t == t_VEC || t == t_COL); }
    1807             : 
    1808             : /*******************************************************************/
    1809             : /*                                                                 */
    1810             : /*                         TRANSCENDENTAL                          */
    1811             : /*                                                                 */
    1812             : /*******************************************************************/
    1813             : INLINE GEN
    1814    15727643 : sqrtr(GEN x) {
    1815    15727643 :   long s = signe(x);
    1816    15727643 :   if (s == 0) return real_0_bit(expo(x) >> 1);
    1817    15694158 :   if (s >= 0) return sqrtr_abs(x);
    1818       13092 :   retmkcomplex(gen_0, sqrtr_abs(x));
    1819             : }
    1820             : INLINE GEN
    1821       11908 : cbrtr(GEN x) {
    1822       11908 :   long s = signe(x);
    1823             :   GEN r;
    1824       11908 :   if (s == 0) return real_0_bit(expo(x) / 3);
    1825       11908 :   r = cbrtr_abs(x);
    1826       11908 :   if (s < 0) togglesign(r);
    1827       11908 :   return r;
    1828             : }
    1829             : /* x^(1/n) */
    1830             : INLINE GEN
    1831       35028 : sqrtnr(GEN x, long n) {
    1832       35028 :   switch(n)
    1833             :   {
    1834         595 :     case 1: return rcopy(x);
    1835        5991 :     case 2: return sqrtr(x);
    1836       11908 :     case 3: return cbrtr(x);
    1837             :   }
    1838       16534 :   return mpexp(divrs(mplog(x), n));
    1839             : }
    1840             : 
    1841             : /*******************************************************************/
    1842             : /*                                                                 */
    1843             : /*                         MISCELLANEOUS                           */
    1844             : /*                                                                 */
    1845             : /*******************************************************************/
    1846      819146 : INLINE int ismpzero(GEN x) { return is_intreal_t(typ(x)) && !signe(x); }
    1847   342267038 : INLINE int isintzero(GEN x) { return typ(x) == t_INT && !signe(x); }
    1848     5952529 : INLINE int isint1(GEN x) { return typ(x)==t_INT && equali1(x); }
    1849         301 : INLINE int isintm1(GEN x){ return typ(x)==t_INT && equalim1(x);}
    1850   213589231 : INLINE int equali1(GEN n)
    1851   213589231 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(1)) && n[2] == 1; }
    1852    23570786 : INLINE int equalim1(GEN n)
    1853    23570786 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(-1)) && n[2] == 1; }
    1854             : /* works only for POSITIVE integers */
    1855  1512347486 : INLINE int is_pm1(GEN n)
    1856  1512347486 : { return lgefint(n) == 3 && n[2] == 1; }
    1857   129236453 : INLINE int is_bigint(GEN n)
    1858   129236453 : { long l = lgefint(n); return l > 3 || (l == 3 && (n[2] & HIGHBIT)); }
    1859             : 
    1860  1406689472 : INLINE int odd(long x) { return x & 1; }
    1861    15902076 : INLINE int both_odd(long x, long y) { return x & y & 1; }
    1862             : 
    1863             : INLINE int
    1864  2295318350 : isonstack(GEN x)
    1865  4590636700 : { return ((pari_sp)x >= pari_mainstack->bot
    1866  2295318350 :        && (pari_sp)x <  pari_mainstack->top); }
    1867             : 
    1868             : /* assume x != 0 and x t_REAL, return an approximation to log2(|x|) */
    1869             : INLINE double
    1870    16474372 : dbllog2r(GEN x)
    1871    16474372 : { return log2((double)(ulong)x[2]) + (double)(expo(x) - (BITS_IN_LONG-1)); }
    1872             : 
    1873             : INLINE GEN
    1874      242944 : mul_content(GEN cx, GEN cy)
    1875             : {
    1876      242944 :   if (!cx) return cy;
    1877      154742 :   if (!cy) return cx;
    1878       33665 :   return gmul(cx,cy);
    1879             : }
    1880             : INLINE GEN
    1881      168515 : mul_denom(GEN dx, GEN dy)
    1882             : {
    1883      168515 :   if (!dx) return dy;
    1884       99120 :   if (!dy) return dx;
    1885       87633 :   return mulii(dx,dy);
    1886             : }
    1887             : 
    1888             : /* POLYNOMIALS */
    1889             : INLINE GEN
    1890    17518212 : constant_coeff(GEN x) { return signe(x)? gel(x,2): gen_0; }
    1891             : INLINE GEN
    1892    76828772 : leading_coeff(GEN x) { return lg(x) == 2? gen_0: gel(x,lg(x)-1); }
    1893             : INLINE ulong
    1894      441192 : Flx_lead(GEN x) { return lg(x) == 2? 0: x[lg(x)-1]; }
    1895             : INLINE long
    1896  2683993504 : degpol(GEN x) { return lg(x)-3; }
    1897             : INLINE long
    1898  1295021194 : lgpol(GEN x) { return lg(x)-2; }
    1899             : INLINE long
    1900    54879592 : lgcols(GEN x) { return lg(gel(x,1)); }
    1901             : INLINE long
    1902    14031154 : nbrows(GEN x) { return lg(gel(x,1))-1; }
    1903             : INLINE GEN
    1904           0 : truecoeff(GEN x, long n) { return polcoeff0(x,n,-1); }
    1905             : 
    1906             : INLINE GEN
    1907      438918 : RgXQ_mul(GEN y, GEN x, GEN T) { return RgX_rem(RgX_mul(y, x), T); }
    1908             : INLINE GEN
    1909      234556 : RgXQ_sqr(GEN x, GEN T) { return RgX_rem(RgX_sqr(x), T); }
    1910             : 
    1911             : INLINE GEN
    1912      114625 : ZXQ_mul(GEN y, GEN x, GEN T) { return ZX_rem(ZX_mul(y, x), T); }
    1913             : INLINE GEN
    1914       19761 : ZXQ_sqr(GEN x, GEN T) { return ZX_rem(ZX_sqr(x), T); }
    1915             : 
    1916             : INLINE GEN
    1917    67877645 : RgX_copy(GEN x)
    1918             : {
    1919             :   long lx, i;
    1920    67877645 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
    1921    67877645 :   for (i = 2; i<lx; i++) gel(y,i) = gcopy(gel(x,i));
    1922    67877645 :   return y;
    1923             : }
    1924             : /* have to use ulong to avoid silly warnings from gcc "assuming signed
    1925             :  * overflow does not occur" */
    1926             : INLINE GEN
    1927     2191050 : RgX_coeff(GEN x, long n)
    1928             : {
    1929     2191050 :   ulong l = lg(x);
    1930     2191050 :   return (n < 0 || ((ulong)n+3) > l)? gen_0: gel(x,n+2);
    1931             : }
    1932             : INLINE GEN
    1933      309617 : RgX_renormalize(GEN x) { return RgX_renormalize_lg(x, lg(x)); }
    1934             : INLINE GEN
    1935     6102763 : RgX_div(GEN x, GEN y) { return RgX_divrem(x,y,NULL); }
    1936             : INLINE GEN
    1937     2729404 : RgX_rem(GEN x, GEN y) { return RgX_divrem(x,y,ONLY_REM); }
    1938             : INLINE GEN
    1939           7 : RgXQX_div(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,NULL); }
    1940             : INLINE GEN
    1941       34853 : RgXQX_rem(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,ONLY_REM); }
    1942             : INLINE GEN
    1943      674461 : FpX_div(GEN x, GEN y, GEN p) { return FpX_divrem(x,y,p, NULL); }
    1944             : INLINE GEN
    1945     2699340 : Flx_div(GEN x, GEN y, ulong p) { return Flx_divrem(x,y,p, NULL); }
    1946             : INLINE GEN
    1947     1153796 : F2x_div(GEN x, GEN y) { return F2x_divrem(x,y, NULL); }
    1948             : INLINE GEN
    1949           0 : FpV_FpC_mul(GEN x, GEN y, GEN p) { return FpV_dotproduct(x,y,p); }
    1950             : INLINE GEN
    1951    51152277 : pol0_Flx(long sv) { return mkvecsmall(sv); }
    1952             : INLINE GEN
    1953    20238250 : pol1_Flx(long sv) { return mkvecsmall2(sv, 1); }
    1954             : INLINE GEN
    1955    16899481 : polx_Flx(long sv) { return mkvecsmall3(sv, 0, 1); }
    1956             : INLINE GEN
    1957           0 : zero_zx(long sv) { return zero_Flx(sv); }
    1958             : INLINE GEN
    1959           0 : polx_zx(long sv) { return polx_Flx(sv); }
    1960             : INLINE GEN
    1961           0 : zx_shift(GEN x, long n) { return Flx_shift(x,n); }
    1962             : INLINE GEN
    1963           0 : zx_renormalize(GEN x, long l) { return Flx_renormalize(x,l); }
    1964             : INLINE GEN
    1965          56 : zero_F2x(long sv) { return zero_Flx(sv); }
    1966             : INLINE GEN
    1967     7235609 : pol0_F2x(long sv) { return pol0_Flx(sv); }
    1968             : INLINE GEN
    1969     1787600 : pol1_F2x(long sv) { return pol1_Flx(sv); }
    1970             : INLINE GEN
    1971      283483 : polx_F2x(long sv) { return mkvecsmall2(sv, 2); }
    1972             : INLINE int
    1973      712977 : F2x_equal1(GEN x) { return Flx_equal1(x); }
    1974             : INLINE int
    1975     1273070 : F2x_equal(GEN V, GEN W) { return Flx_equal(V,W); }
    1976             : INLINE GEN
    1977    35775477 : F2x_copy(GEN x) { return leafcopy(x); }
    1978             : INLINE GEN
    1979           0 : F2v_copy(GEN x) { return leafcopy(x); }
    1980             : INLINE GEN
    1981     1795203 : Flv_copy(GEN x) { return leafcopy(x); }
    1982             : INLINE GEN
    1983    84924376 : Flx_copy(GEN x) { return leafcopy(x); }
    1984             : INLINE GEN
    1985     2054089 : vecsmall_copy(GEN x) { return leafcopy(x); }
    1986             : INLINE int
    1987     5023233 : Flx_equal1(GEN x) { return degpol(x)==0 && x[2] == 1; }
    1988             : INLINE int
    1989       17711 : ZX_equal1(GEN x) { return degpol(x)==0 && equali1(gel(x,2)); }
    1990             : 
    1991             : INLINE GEN
    1992    74792850 : ZX_renormalize(GEN x, long lx)    { return ZXX_renormalize(x,lx); }
    1993             : INLINE GEN
    1994    91864121 : FpX_renormalize(GEN x, long lx)   { return ZXX_renormalize(x,lx); }
    1995             : INLINE GEN
    1996      828966 : FpXX_renormalize(GEN x, long lx)  { return ZXX_renormalize(x,lx); }
    1997             : INLINE GEN
    1998     1117650 : FpXQX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
    1999             : INLINE GEN
    2000    80410894 : F2x_renormalize(GEN x, long lx)   { return Flx_renormalize(x,lx); }
    2001             : INLINE GEN
    2002        5985 : F2v_to_F2x(GEN x, long sv) {
    2003        5985 :   GEN y = leafcopy(x);
    2004        5985 :   y[1] = sv; F2x_renormalize(y, lg(y)); return y;
    2005             : }
    2006             : 
    2007             : INLINE GEN
    2008           0 : ZX_ZXY_resultant(GEN a, GEN b) { return ZX_ZXY_rnfequation(a,b,NULL); }
    2009             : INLINE long
    2010         441 : sturm(GEN x) { return sturmpart(x, NULL, NULL); }
    2011             : INLINE GEN
    2012       25829 : resultant(GEN x, GEN y) { return resultant_all(x,y,NULL); }
    2013             : 
    2014             : INLINE long
    2015        2044 : gval(GEN x, long v) {
    2016        2044 :   pari_sp av = avma;
    2017        2044 :   long n = gvaluation(x, pol_x(v));
    2018        2044 :   avma = av; return n;
    2019             : }
    2020             : 
    2021             : INLINE void
    2022      578163 : RgX_shift_inplace_init(long v)
    2023      578163 : { if (v) (void)cgetg(v, t_VECSMALL); }
    2024             : /* shift polynomial in place. assume v free cells have been left before x */
    2025             : INLINE GEN
    2026      578167 : RgX_shift_inplace(GEN x, long v)
    2027             : {
    2028             :   long i, lx;
    2029             :   GEN y, z;
    2030      578167 :   if (!v) return x;
    2031      258109 :   lx = lg(x);
    2032      258109 :   if (lx == 2) return x;
    2033      258109 :   y = x + v;
    2034      258109 :   z = x + lx;
    2035             :   /* stackdummy from normalizepol: move it up */
    2036      258109 :   if (lg(z) != v) x[lx + v] = z[0];
    2037      258109 :   for (i = lx-1; i >= 2; i--) gel(y,i) = gel(x,i);
    2038      258109 :   for (i = v+1;  i >= 2; i--) gel(x,i) = gen_0;
    2039             :   /* leave x[1] alone: it is correct */
    2040      258109 :   x[0] = evaltyp(t_POL) | evallg(lx+v); return x;
    2041             : }
    2042             : 
    2043             : 
    2044             : /* LINEAR ALGEBRA */
    2045             : INLINE GEN
    2046        8407 : zv_to_ZV(GEN x) { return vecsmall_to_vec(x); }
    2047             : INLINE GEN
    2048     1093169 : zc_to_ZC(GEN x) { return vecsmall_to_col(x); }
    2049             : INLINE GEN
    2050      219609 : ZV_to_zv(GEN x) { return vec_to_vecsmall(x); }
    2051             : INLINE GEN
    2052           0 : zx_to_zv(GEN x, long N) { return Flx_to_Flv(x,N); }
    2053             : INLINE GEN
    2054           0 : zv_to_zx(GEN x, long sv) { return Flv_to_Flx(x,sv); }
    2055             : INLINE GEN
    2056           0 : zm_to_zxV(GEN x, long sv) { return Flm_to_FlxV(x,sv); }
    2057             : INLINE GEN
    2058           0 : zero_zm(long x, long y) { return zero_Flm(x,y); }
    2059             : INLINE GEN
    2060    13868366 : zero_zv(long x) { return zero_Flv(x); }
    2061             : INLINE GEN
    2062         168 : zm_transpose(GEN x) { return Flm_transpose(x); }
    2063             : INLINE GEN
    2064           0 : zm_copy(GEN x) { return Flm_copy(x); }
    2065             : INLINE GEN
    2066     1332273 : zv_copy(GEN x) { return Flv_copy(x); }
    2067             : INLINE GEN
    2068           0 : zm_row(GEN x, long i) { return Flm_row(x,i); }
    2069             : 
    2070             : INLINE GEN
    2071      885885 : ZC_hnfrem(GEN x, GEN y) { return ZC_hnfremdiv(x,y,NULL); }
    2072             : INLINE GEN
    2073       56957 : ZM_hnfrem(GEN x, GEN y) { return ZM_hnfdivrem(x,y,NULL); }
    2074             : INLINE GEN
    2075     1311652 : ZM_lll(GEN x, double D, long f) { return ZM_lll_norms(x,D,f,NULL); }
    2076             : INLINE void
    2077      116865 : RgM_dimensions(GEN x, long *m, long *n) { *n = lg(x)-1; *m = *n? nbrows(x): 0; }
    2078             : INLINE GEN
    2079       31524 : RgM_inv(GEN a) { return RgM_solve(a, NULL); }
    2080             : INLINE GEN
    2081     5487770 : RgM_shallowcopy(GEN x)
    2082             : {
    2083             :   long l;
    2084     5487770 :   GEN y = cgetg_copy(x, &l);
    2085     5487770 :   while (--l > 0) gel(y,l) = leafcopy(gel(x,l));
    2086     5487770 :   return y;
    2087             : }
    2088             : INLINE GEN
    2089        1631 : F2m_copy(GEN x) { return RgM_shallowcopy(x); }
    2090             : 
    2091             : INLINE GEN
    2092      318871 : Flm_copy(GEN x) { return RgM_shallowcopy(x); }
    2093             : 
    2094             : /* divisibility: return 1 if y[i] | x[i] for all i, 0 otherwise. Assume
    2095             :  * x,y are ZV of the same length */
    2096             : INLINE int
    2097       23198 : ZV_dvd(GEN x, GEN y)
    2098             : {
    2099       23198 :   long i, l = lg(x);
    2100       36652 :   for (i=1; i < l; i++)
    2101       29519 :     if ( ! dvdii( gel(x,i), gel(y,i) ) ) return 0;
    2102        7133 :   return 1;
    2103             : }
    2104             : 
    2105             : /* Fq */
    2106             : INLINE GEN
    2107     1360646 : Fq_red(GEN x, GEN T, GEN p)
    2108     1360646 : { return typ(x)==t_INT? Fp_red(x,p): FpXQ_red(x,T,p); }
    2109             : INLINE GEN
    2110      103411 : Fq_to_FpXQ(GEN x, GEN T, GEN p /*unused*/)
    2111             : {
    2112             :   (void) p;
    2113      103411 :   return typ(x)==t_INT ? scalarpol(x, get_FpX_var(T)): x;
    2114             : }
    2115             : 
    2116             : INLINE GEN
    2117         511 : gener_Fq_local(GEN T, GEN p, GEN L)
    2118         511 : { return T? gener_FpXQ_local(T,p, L)
    2119         511 :           : pgener_Fp_local(p, L); }
    2120             : 
    2121             : /* FpXQX */
    2122             : INLINE GEN
    2123         917 : FpXQX_div(GEN x, GEN y, GEN T, GEN p) { return FpXQX_divrem(x, y, T, p, NULL); }
    2124             : INLINE GEN
    2125       32326 : FlxqX_div(GEN x, GEN y, GEN T, ulong p) { return FlxqX_divrem(x, y, T, p, NULL); }
    2126             : INLINE GEN
    2127       29631 : F2xqX_div(GEN x, GEN y, GEN T) { return F2xqX_divrem(x, y, T, NULL); }
    2128             : 
    2129             : /* FqX */
    2130             : INLINE GEN
    2131        9541 : FqX_red(GEN z, GEN T, GEN p) { return T? FpXQX_red(z, T, p): FpX_red(z, p); }
    2132             : INLINE GEN
    2133      904275 : FqX_add(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2134             : INLINE GEN
    2135       16438 : FqX_neg(GEN x,GEN T,GEN p) { return T? FpXX_neg(x,p): FpX_neg(x,p); }
    2136             : INLINE GEN
    2137        2380 : FqX_sub(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2138             : INLINE GEN
    2139      531902 : FqX_Fp_mul(GEN P, GEN u, GEN T, GEN p)
    2140      531902 : { return T? FpXX_Fp_mul(P, u, p): FpX_Fp_mul(P, u, p); }
    2141             : INLINE GEN
    2142      553901 : FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p)
    2143      553901 : { return typ(U)==t_INT ? FqX_Fp_mul(P, U, T, p): FpXQX_FpXQ_mul(P, U, T, p); }
    2144             : INLINE GEN
    2145       83978 : FqX_mul(GEN x, GEN y, GEN T, GEN p)
    2146       83978 : { return T? FpXQX_mul(x, y, T, p): FpX_mul(x, y, p); }
    2147             : INLINE GEN
    2148      459861 : FqX_mulu(GEN x, ulong y, GEN T, GEN p)
    2149      459861 : { return T? FpXX_mulu(x, y, p): FpX_mulu(x, y, p); }
    2150             : INLINE GEN
    2151        4928 : FqX_sqr(GEN x, GEN T, GEN p)
    2152        4928 : { return T? FpXQX_sqr(x, T, p): FpX_sqr(x, p); }
    2153             : INLINE GEN
    2154        1428 : FqX_powu(GEN x, ulong n, GEN T, GEN p)
    2155        1428 : { return T? FpXQX_powu(x, n, T, p): FpX_powu(x, n, p); }
    2156             : INLINE GEN
    2157        6244 : FqX_div(GEN x, GEN y, GEN T, GEN p)
    2158        6244 : { return T? FpXQX_divrem(x,y,T,p,NULL): FpX_divrem(x,y,p,NULL); }
    2159             : INLINE GEN
    2160        5605 : FqX_get_red(GEN S, GEN T, GEN p)
    2161        5605 : { return T? FpXQX_get_red(S,T,p): FpX_get_red(S,p); }
    2162             : INLINE GEN
    2163       48310 : FqX_rem(GEN x, GEN y, GEN T, GEN p)
    2164       48310 : { return T? FpXQX_rem(x,y,T,p): FpX_rem(x,y,p); }
    2165             : INLINE GEN
    2166         329 : FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2167         329 : { return T? FpXQX_divrem(x,y,T,p,z): FpX_divrem(x,y,p,z); }
    2168             : INLINE GEN
    2169        5761 : FqX_div_by_X_x(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2170        5761 : { return T? FpXQX_div_by_X_x(x,y,T,p,z): FpX_div_by_X_x(x,y,p,z); }
    2171             : INLINE GEN
    2172      138341 : FqX_gcd(GEN P,GEN Q,GEN T,GEN p)
    2173      138341 : {return T? FpXQX_gcd(P,Q,T,p): FpX_gcd(P,Q,p);}
    2174             : INLINE GEN
    2175       40357 : FqX_extgcd(GEN P,GEN Q,GEN T,GEN p, GEN *U, GEN *V)
    2176       40357 : { return T? FpXQX_extgcd(P,Q,T,p,U,V): FpX_extgcd(P,Q,p,U,V); }
    2177             : INLINE GEN
    2178       12092 : FqX_normalize(GEN z, GEN T, GEN p) { return T? FpXQX_normalize(z, T, p): FpX_normalize(z, p); }
    2179             : INLINE GEN
    2180      146664 : FqX_deriv(GEN f, /*unused*/GEN T, GEN p) { (void)T; return FpXX_deriv(f, p); }
    2181             : INLINE GEN
    2182       27972 : FqX_factor(GEN f, GEN T, GEN p) { return T?FpXQX_factor(f, T, p): FpX_factor(f, p); }
    2183             : INLINE GEN
    2184        3500 : FqX_roots(GEN f, GEN T, GEN p) { return T?FpXQX_roots(f, T, p): FpX_roots(f, p); }
    2185             : 
    2186             : /*FqXQ*/
    2187             : INLINE GEN
    2188           0 : FqXQ_add(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2189           0 : { (void)S; return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2190             : INLINE GEN
    2191           0 : FqXQ_sub(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2192           0 : { (void)S; return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2193             : INLINE GEN
    2194           0 : FqXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p)
    2195           0 : { return T? FpXQXQ_div(x,y,S,T,p): FpXQ_div(x,y,S,p); }
    2196             : INLINE GEN
    2197           0 : FqXQ_inv(GEN x, GEN S, GEN T, GEN p)
    2198           0 : { return T? FpXQXQ_inv(x,S,T,p): FpXQ_inv(x,S,p); }
    2199             : INLINE GEN
    2200           0 : FqXQ_invsafe(GEN x, GEN S, GEN T, GEN p)
    2201           0 : { return T? FpXQXQ_invsafe(x,S,T,p): FpXQ_inv(x,S,p); }
    2202             : INLINE GEN
    2203       21018 : FqXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p)
    2204       21018 : { return T? FpXQXQ_mul(x,y,S,T,p): FpXQ_mul(x,y,S,p); }
    2205             : INLINE GEN
    2206           0 : FqXQ_sqr(GEN x, GEN S, GEN T, GEN p)
    2207           0 : { return T? FpXQXQ_sqr(x,S,T,p): FpXQ_sqr(x,S,p); }
    2208             : INLINE GEN
    2209           0 : FqXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p)
    2210           0 : { return T? FpXQXQ_pow(x,n,S,T,p): FpXQ_pow(x,n,S,p); }
    2211             : 
    2212             : /*FpXQ*/
    2213             : INLINE GEN
    2214           0 : FpXQ_add(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2215           0 : { (void)T; return FpX_add(x,y,p); }
    2216             : INLINE GEN
    2217           0 : FpXQ_sub(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2218           0 : { (void)T; return FpX_sub(x,y,p); }
    2219             : 
    2220             : /*Flxq*/
    2221             : INLINE GEN
    2222           0 : Flxq_add(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2223           0 : { (void)T; return Flx_add(x,y,p); }
    2224             : INLINE GEN
    2225           0 : Flxq_sub(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2226           0 : { (void)T; return Flx_sub(x,y,p); }
    2227             : 
    2228             : /* F2x */
    2229             : 
    2230             : INLINE ulong
    2231   104626009 : F2x_coeff(GEN x,long v)
    2232             : {
    2233   104626009 :    ulong u=(ulong)x[2+divsBIL(v)];
    2234   104625802 :    return (u>>remsBIL(v))&1UL;
    2235             : }
    2236             : 
    2237             : INLINE void
    2238     2198318 : F2x_clear(GEN x,long v)
    2239             : {
    2240     2198318 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2241     2198318 :    *u&=~(1UL<<remsBIL(v));
    2242     2198318 : }
    2243             : 
    2244             : INLINE void
    2245    33653187 : F2x_set(GEN x,long v)
    2246             : {
    2247    33653187 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2248    33653152 :    *u|=1UL<<remsBIL(v);
    2249    33653044 : }
    2250             : 
    2251             : INLINE void
    2252      371168 : F2x_flip(GEN x,long v)
    2253             : {
    2254      371168 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2255      371168 :    *u^=1UL<<remsBIL(v);
    2256      371168 : }
    2257             : 
    2258             : /* F2v */
    2259             : 
    2260             : INLINE ulong
    2261   101010515 : F2v_coeff(GEN x,long v) { return F2x_coeff(x,v-1); }
    2262             : 
    2263             : INLINE void
    2264     2198318 : F2v_clear(GEN x,long v) { F2x_clear(x,v-1); }
    2265             : 
    2266             : INLINE void
    2267    13727279 : F2v_set(GEN x,long v)   { F2x_set(x,v-1); }
    2268             : 
    2269             : INLINE void
    2270      371168 : F2v_flip(GEN x,long v) { F2x_flip(x,v-1); }
    2271             : 
    2272             : /* F2m */
    2273             : 
    2274             : INLINE ulong
    2275    12090851 : F2m_coeff(GEN x, long a, long b) { return F2v_coeff(gel(x,b), a); }
    2276             : 
    2277             : INLINE void
    2278           0 : F2m_clear(GEN x, long a, long b) { F2v_clear(gel(x,b), a); }
    2279             : 
    2280             : INLINE void
    2281     1603119 : F2m_set(GEN x, long a, long b) { F2v_set(gel(x,b), a); }
    2282             : 
    2283             : INLINE void
    2284      371168 : F2m_flip(GEN x, long a, long b) { F2v_flip(gel(x,b), a); }
    2285             : 
    2286             : /* ARITHMETIC */
    2287             : INLINE GEN
    2288         938 : matpascal(long n) { return matqpascal(n, NULL); }
    2289             : INLINE long
    2290     1975097 : Z_issquare(GEN x) { return Z_issquareall(x, NULL); }
    2291             : INLINE long
    2292          14 : Z_ispower(GEN x, ulong k) { return Z_ispowerall(x, k, NULL); }
    2293             : INLINE GEN
    2294     4233363 : sqrti(GEN x) { return sqrtremi(x,NULL); }
    2295             : INLINE GEN
    2296     7309808 : gaddgs(GEN y, long s) { return gaddsg(s,y); }
    2297             : INLINE int
    2298       24114 : gcmpgs(GEN y, long s) { return -gcmpsg(s,y); }
    2299             : INLINE int
    2300       22960 : gequalgs(GEN y, long s) { return gequalsg(s,y); }
    2301             : INLINE GEN
    2302           0 : gmaxsg(long s, GEN y) { return gmaxgs(y,s); }
    2303             : INLINE GEN
    2304           0 : gminsg(long s, GEN y) { return gmings(y,s); }
    2305             : INLINE GEN
    2306     5744949 : gmulgs(GEN y, long s) { return gmulsg(s,y); }
    2307             : INLINE GEN
    2308      613916 : gsubgs(GEN y, long s) { return gaddgs(y, -s); }
    2309             : INLINE GEN
    2310      447839 : gdivsg(long s, GEN y) { return gdiv(stoi(s), y); }
    2311             : 
    2312             : /* x t_COMPLEX */
    2313             : INLINE GEN
    2314     7437923 : cxnorm(GEN x) { return gadd(gsqr(gel(x,1)), gsqr(gel(x,2))); }
    2315             : /* q t_QUAD */
    2316             : INLINE GEN
    2317         623 : quadnorm(GEN q)
    2318             : {
    2319         623 :   GEN X = gel(q,1), b = gel(X,3), c = gel(X,2);
    2320         623 :   GEN z, u = gel(q,3), v = gel(q,2);
    2321         623 :   if (typ(u) == t_INT && typ(v) == t_INT) /* generic case */
    2322             :   {
    2323         308 :     z = signe(b)? mulii(v, addii(u,v)): sqri(v);
    2324         308 :     return addii(z, mulii(c, sqri(u)));
    2325             :   }
    2326             :   else
    2327             :   {
    2328         315 :     z = signe(b)? gmul(v, gadd(u,v)): gsqr(v);
    2329         315 :     return gadd(z, gmul(c, gsqr(u)));
    2330             :   }
    2331             : }
    2332             : /* x a t_QUAD, return the attached discriminant */
    2333             : INLINE GEN
    2334         252 : quad_disc(GEN x)
    2335             : {
    2336         252 :   GEN Q = gel(x,1), b = gel(Q,3), c = gel(Q,2), c4;
    2337         252 :   if (is_pm1(b))
    2338             :   {
    2339         196 :     pari_sp av = avma; (void)new_chunk(lgefint(c) + 1);
    2340         196 :     c4 = shifti(c,2); avma = av; return subsi(1, c4);
    2341             :   }
    2342          56 :   c4 = shifti(c,2); togglesign_safe(&c4); return c4;
    2343             : }
    2344             : INLINE GEN
    2345     6011782 : qfb_disc3(GEN x, GEN y, GEN z) { return subii(sqri(y), shifti(mulii(x,z),2)); }
    2346             : INLINE GEN
    2347     5919942 : qfb_disc(GEN x) { return qfb_disc3(gel(x,1), gel(x,2), gel(x,3)); }
    2348             : 
    2349             : INLINE GEN
    2350      240928 : sqrfrac(GEN x)
    2351             : {
    2352      240928 :   GEN z = cgetg(3,t_FRAC);
    2353      240928 :   gel(z,1) = sqri(gel(x,1));
    2354      240928 :   gel(z,2) = sqri(gel(x,2)); return z;
    2355             : }
    2356             : 
    2357             : INLINE void
    2358     8048876 : normalize_frac(GEN z) {
    2359     8048876 :   if (signe(gel(z,2)) < 0) { togglesign(gel(z,1)); setabssign(gel(z,2)); }
    2360     8048876 : }
    2361             : 
    2362             : INLINE GEN
    2363      339276 : powii(GEN x, GEN n)
    2364             : {
    2365      339276 :   long ln = lgefint(n);
    2366      339276 :   if (ln == 3) {
    2367             :     GEN z;
    2368      337925 :     if (signe(n) > 0) return powiu(x, n[2]);
    2369        1596 :     z = cgetg(3, t_FRAC);
    2370        1596 :     gel(z,1) = gen_1;
    2371        1596 :     gel(z,2) = powiu(x, n[2]);
    2372        1596 :     return z;
    2373             :   }
    2374        1351 :   if (ln == 2) return gen_1; /* rare */
    2375             :   /* should never happen */
    2376           0 :   return powgi(x, n); /* overflow unless x = 0, 1, -1 */
    2377             : }
    2378             : INLINE GEN
    2379         819 : powIs(long n) {
    2380         819 :   switch(n & 3)
    2381             :   {
    2382           7 :     case 1: return mkcomplex(gen_0,gen_1);
    2383         315 :     case 2: return gen_m1;
    2384         448 :     case 3: return mkcomplex(gen_0,gen_m1);
    2385             :   }
    2386          49 :   return gen_1;
    2387             : }
    2388             : 
    2389             : /*******************************************************************/
    2390             : /*                                                                 */
    2391             : /*                             ASSIGNMENTS                         */
    2392             : /*                                                                 */
    2393             : /*******************************************************************/
    2394           0 : INLINE void mpexpz(GEN x, GEN z)
    2395           0 : { pari_sp av = avma; gaffect(mpexp(x), z); avma = av; }
    2396           0 : INLINE void mplogz(GEN x, GEN z)
    2397           0 : { pari_sp av = avma; gaffect(mplog(x), z); avma = av; }
    2398           0 : INLINE void mpcosz(GEN x, GEN z)
    2399           0 : { pari_sp av = avma; gaffect(mpcos(x), z); avma = av; }
    2400           0 : INLINE void mpsinz(GEN x, GEN z)
    2401           0 : { pari_sp av = avma; gaffect(mpsin(x), z); avma = av; }
    2402           0 : INLINE void gnegz(GEN x, GEN z)
    2403           0 : { pari_sp av = avma; gaffect(gneg(x), z); avma = av; }
    2404           0 : INLINE void gabsz(GEN x, long prec, GEN z)
    2405           0 : { pari_sp av = avma; gaffect(gabs(x,prec), z); avma = av; }
    2406       23318 : INLINE void gaddz(GEN x, GEN y, GEN z)
    2407       23318 : { pari_sp av = avma; gaffect(gadd(x,y), z); avma = av; }
    2408           0 : INLINE void gsubz(GEN x, GEN y, GEN z)
    2409           0 : { pari_sp av = avma; gaffect(gsub(x,y), z); avma = av; }
    2410       11673 : INLINE void gmulz(GEN x, GEN y, GEN z)
    2411       11673 : { pari_sp av = avma; gaffect(gmul(x,y), z); avma = av; }
    2412           0 : INLINE void gdivz(GEN x, GEN y, GEN z)
    2413           0 : { pari_sp av = avma; gaffect(gdiv(x,y), z); avma = av; }
    2414           0 : INLINE void gdiventz(GEN x, GEN y, GEN z)
    2415           0 : { pari_sp av = avma; gaffect(gdivent(x,y), z); avma = av; }
    2416           0 : INLINE void gmodz(GEN x, GEN y, GEN z)
    2417           0 : { pari_sp av = avma; gaffect(gmod(x,y), z); avma = av; }
    2418           0 : INLINE void gmul2nz(GEN x, long s, GEN z)
    2419           0 : { pari_sp av = avma; gaffect(gmul2n(x,s), z); avma = av; }
    2420           0 : INLINE void gshiftz(GEN x, long s, GEN z)
    2421           0 : { pari_sp av = avma; gaffect(gshift(x,s), z); avma = av; }
    2422             : 
    2423             : /*******************************************************************/
    2424             : /*                                                                 */
    2425             : /*                       ELLIPTIC CURVES                           */
    2426             : /*                                                                 */
    2427             : /*******************************************************************/
    2428     3822234 : INLINE GEN ell_get_a1(GEN e) { return gel(e,1); }
    2429     1943956 : INLINE GEN ell_get_a2(GEN e) { return gel(e,2); }
    2430     3160272 : INLINE GEN ell_get_a3(GEN e) { return gel(e,3); }
    2431     2576049 : INLINE GEN ell_get_a4(GEN e) { return gel(e,4); }
    2432     3023104 : INLINE GEN ell_get_a6(GEN e) { return gel(e,5); }
    2433     3105616 : INLINE GEN ell_get_b2(GEN e) { return gel(e,6); }
    2434      558720 : INLINE GEN ell_get_b4(GEN e) { return gel(e,7); }
    2435     1011095 : INLINE GEN ell_get_b6(GEN e) { return gel(e,8); }
    2436      855484 : INLINE GEN ell_get_b8(GEN e) { return gel(e,9); }
    2437     6043968 : INLINE GEN ell_get_c4(GEN e) { return gel(e,10); }
    2438     8072945 : INLINE GEN ell_get_c6(GEN e) { return gel(e,11); }
    2439     9552475 : INLINE GEN ell_get_disc(GEN e) { return gel(e,12); }
    2440      950943 : INLINE GEN ell_get_j(GEN e) { return gel(e,13); }
    2441     7406920 : INLINE long ell_get_type(GEN e) { return mael(e,14,1); }
    2442      795792 : INLINE GEN ellff_get_field(GEN x) { return gmael(x, 15, 1); }
    2443      314039 : INLINE GEN ellff_get_a4a6(GEN x)  { return gmael(x, 15, 2); }
    2444         539 : INLINE GEN ellQp_get_zero(GEN x) { return gmael(x, 15, 1); }
    2445          98 : INLINE long ellQp_get_prec(GEN E) { GEN z = ellQp_get_zero(E); return valp(z); }
    2446         434 : INLINE GEN ellQp_get_p(GEN E) { GEN z = ellQp_get_zero(E); return gel(z,2); }
    2447         721 : INLINE long ellR_get_prec(GEN x) { return nbits2prec(mael3(x, 15, 1, 1)); }
    2448        1318 : INLINE long ellR_get_sign(GEN x) { return mael3(x, 15, 1, 2); }
    2449      486738 : INLINE GEN ellnf_get_nf(GEN x) { return checknf_i(gmael(x,15,1)); }
    2450          28 : INLINE GEN ellnf_get_bnf(GEN x) { return checkbnf_i(gmael(x,15,1)); }
    2451             : 
    2452    37334979 : INLINE int ell_is_inf(GEN z) { return lg(z) == 2; }
    2453      638170 : INLINE GEN ellinf(void) { return mkvec(gen_0); }
    2454             : 
    2455             : /*******************************************************************/
    2456             : /*                                                                 */
    2457             : /*                    ALGEBRAIC NUMBER THEORY                      */
    2458             : /*                                                                 */
    2459             : /*******************************************************************/
    2460     4368998 : INLINE GEN modpr_get_pr(GEN x)  { return gel(x,3); }
    2461      143297 : INLINE GEN modpr_get_p(GEN x)  { return pr_get_p(modpr_get_pr(x)); }
    2462     1903367 : INLINE GEN modpr_get_T(GEN x)  { return lg(x) == 4? NULL: gel(x,4); }
    2463             : 
    2464    12022006 : INLINE GEN pr_get_p(GEN pr)  { return gel(pr,1); }
    2465     2189278 : INLINE GEN pr_get_gen(GEN pr){ return gel(pr,2); }
    2466             : /* .[2] instead of itos works: e and f are small positive integers */
    2467     2254779 : INLINE long pr_get_e(GEN pr) { return gel(pr,3)[2]; }
    2468     5785177 : INLINE long pr_get_f(GEN pr) { return gel(pr,4)[2]; }
    2469     3913639 : INLINE GEN pr_get_tau(GEN pr){ return gel(pr,5); }
    2470             : INLINE int
    2471      560932 : pr_is_inert(GEN P) { return pr_get_f(P) == lg(pr_get_gen(P))-1; }
    2472             : INLINE GEN
    2473      368579 : pr_norm(GEN pr) { return powiu(pr_get_p(pr), pr_get_f(pr)); }
    2474             : 
    2475             : /* assume nf a genuine nf */
    2476             : INLINE long
    2477        7363 : nf_get_varn(GEN nf) { return varn(gel(nf,1)); }
    2478             : INLINE GEN
    2479    10867171 : nf_get_pol(GEN nf) { return gel(nf,1); }
    2480             : INLINE long
    2481     4194804 : nf_get_degree(GEN nf) { return degpol( nf_get_pol(nf) ); }
    2482             : INLINE long
    2483     1062368 : nf_get_r1(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,1)); }
    2484             : INLINE long
    2485        1057 : nf_get_r2(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,2)); }
    2486             : INLINE GEN
    2487       22919 : nf_get_disc(GEN nf) { return gel(nf,3); }
    2488             : INLINE GEN
    2489      748472 : nf_get_index(GEN nf) { return gel(nf,4); }
    2490             : INLINE GEN
    2491      966018 : nf_get_M(GEN nf) { return gmael(nf,5,1); }
    2492             : INLINE GEN
    2493       42262 : nf_get_G(GEN nf) { return gmael(nf,5,2); }
    2494             : INLINE GEN
    2495      378162 : nf_get_roundG(GEN nf) { return gmael(nf,5,3); }
    2496             : INLINE GEN
    2497         798 : nf_get_Tr(GEN nf) { return gmael(nf,5,4); }
    2498             : INLINE GEN
    2499         812 : nf_get_diff(GEN nf) { return gmael(nf,5,5); }
    2500             : INLINE GEN
    2501          21 : nf_get_ramified_primes(GEN nf) { return gmael(nf,5,8); }
    2502             : INLINE GEN
    2503       90959 : nf_get_roots(GEN nf) { return gel(nf,6); }
    2504             : INLINE GEN
    2505     7029179 : nf_get_zk(GEN nf) { return gel(nf,7); }
    2506             : INLINE GEN
    2507     1832243 : nf_get_invzk(GEN nf) { return gel(nf,8); }
    2508             : INLINE void
    2509        5960 : nf_get_sign(GEN nf, long *r1, long *r2)
    2510             : {
    2511        5960 :   GEN x = gel(nf,2);
    2512        5960 :   *r1 = itou(gel(x,1));
    2513        5960 :   *r2 = itou(gel(x,2));
    2514        5960 : }
    2515             : 
    2516             : INLINE GEN
    2517       10052 : abgrp_get_no(GEN x) { return gel(x,1); }
    2518             : INLINE GEN
    2519     1025829 : abgrp_get_cyc(GEN x) { return gel(x,2); }
    2520             : INLINE GEN
    2521      272687 : abgrp_get_gen(GEN x) { return gel(x,3); }
    2522             : INLINE GEN
    2523     1103421 : bnf_get_nf(GEN bnf) { return gel(bnf,7); }
    2524             : INLINE GEN
    2525      559185 : bnf_get_clgp(GEN bnf) { return gmael(bnf,8,1); }
    2526             : INLINE GEN
    2527         987 : bnf_get_no(GEN bnf) { return abgrp_get_no(bnf_get_clgp(bnf)); }
    2528             : INLINE GEN
    2529      292847 : bnf_get_cyc(GEN bnf) { return abgrp_get_cyc(bnf_get_clgp(bnf)); }
    2530             : INLINE GEN
    2531      265197 : bnf_get_gen(GEN bnf)  { return abgrp_get_gen(bnf_get_clgp(bnf)); }
    2532             : INLINE GEN
    2533         671 : bnf_get_reg(GEN bnf) { return gmael(bnf,8,2); }
    2534             : INLINE GEN
    2535      426570 : bnf_get_logfu(GEN bnf) { return gel(bnf,3); }
    2536             : INLINE GEN
    2537        6825 : bnf_get_tuU(GEN bnf) { return gmael3(bnf,8,4,2); }
    2538             : INLINE long
    2539        8519 : bnf_get_tuN(GEN bnf) { return gmael3(bnf,8,4,1)[2]; }
    2540             : INLINE GEN
    2541        7895 : bnf_get_fu(GEN bnf) {
    2542        7895 :   GEN fu = bnf_get_fu_nocheck(bnf);
    2543        7895 :   if (typ(fu) == t_MAT) pari_err(e_MISC,"missing units in bnf");
    2544        7895 :   return fu;
    2545             : }
    2546             : INLINE GEN
    2547       14034 : bnf_get_fu_nocheck(GEN bnf) { return gmael(bnf,8,5); }
    2548             : 
    2549             : INLINE GEN
    2550      399626 : bnr_get_bnf(GEN bnr) { return gel(bnr,1); }
    2551             : INLINE GEN
    2552      198014 : bnr_get_bid(GEN bnr) { return gel(bnr,2); }
    2553             : INLINE GEN
    2554       10990 : bnr_get_mod(GEN bnr) { return gmael(bnr,2,1); }
    2555             : INLINE GEN
    2556        3955 : bnr_get_nf(GEN bnr) { return gmael(bnr,1,7); }
    2557             : INLINE GEN
    2558      230242 : bnr_get_clgp(GEN bnr) { return gel(bnr,5); }
    2559             : INLINE GEN
    2560        9065 : bnr_get_no(GEN bnr) { return abgrp_get_no(bnr_get_clgp(bnr)); }
    2561             : INLINE GEN
    2562      218545 : bnr_get_cyc(GEN bnr) { return abgrp_get_cyc(bnr_get_clgp(bnr)); }
    2563             : INLINE GEN
    2564          70 : bnr_get_gen_nocheck(GEN bnr) { return abgrp_get_gen(bnr_get_clgp(bnr)); }
    2565             : INLINE GEN
    2566        2562 : bnr_get_gen(GEN bnr) {
    2567        2562 :   GEN G = bnr_get_clgp(bnr);
    2568        2562 :   if (lg(G) !=  4)
    2569           0 :     pari_err(e_MISC,"missing bnr generators: please use bnrinit(,,1)");
    2570        2562 :   return gel(G,3);
    2571             : }
    2572             : 
    2573             : INLINE GEN
    2574      366904 : bid_get_mod(GEN bid) { return gel(bid,1); }
    2575             : INLINE GEN
    2576       83385 : bid_get_ideal(GEN bid) { return gmael(bid,1,1); }
    2577             : INLINE GEN
    2578       95680 : bid_get_arch(GEN bid) { return gmael(bid,1,2); }
    2579             : INLINE GEN
    2580      519785 : bid_get_grp(GEN bid) { return gel(bid,2); }
    2581             : INLINE GEN
    2582      140715 : bid_get_fact(GEN bid) { return gel(bid,3); }
    2583             : INLINE GEN
    2584      420836 : bid_get_U(GEN bid) { return gel(bid,5); }
    2585             : INLINE GEN
    2586           0 : bid_get_no(GEN bid) { return abgrp_get_no(bid_get_grp(bid)); }
    2587             : INLINE GEN
    2588      513142 : bid_get_cyc(GEN bid) { return abgrp_get_cyc(bid_get_grp(bid)); }
    2589             : INLINE GEN
    2590           0 : bid_get_gen_nocheck(GEN bid)  { return abgrp_get_gen(bid_get_grp(bid)); }
    2591             : INLINE GEN
    2592        6125 : bid_get_gen(GEN bid) {
    2593        6125 :   GEN G = bid_get_grp(bid);
    2594        6125 :   if (lg(G) != 4) pari_err(e_MISC,"missing bid generators. Use idealstar(,,2)");
    2595        6125 :   return abgrp_get_gen(G);
    2596             : }
    2597             : INLINE GEN
    2598         973 : gal_get_pol(GEN gal) { return gel(gal,1); }
    2599             : INLINE GEN
    2600         980 : gal_get_p(GEN gal) { return gmael(gal,2,1); }
    2601             : INLINE GEN
    2602          56 : gal_get_e(GEN gal) { return gmael(gal,2,2); }
    2603             : INLINE GEN
    2604        1806 : gal_get_mod(GEN gal) { return gmael(gal,2,3); }
    2605             : INLINE GEN
    2606        2170 : gal_get_roots(GEN gal) { return gel(gal,3); }
    2607             : INLINE GEN
    2608        1799 : gal_get_invvdm(GEN gal) { return gel(gal,4); }
    2609             : INLINE GEN
    2610        1799 : gal_get_den(GEN gal) { return gel(gal,5); }
    2611             : INLINE GEN
    2612        3829 : gal_get_group(GEN gal) { return gel(gal,6); }
    2613             : INLINE GEN
    2614        1211 : gal_get_gen(GEN gal) { return gel(gal,7); }
    2615             : INLINE GEN
    2616         763 : gal_get_orders(GEN gal) { return gel(gal,8); }
    2617             : 
    2618             : /* assume rnf a genuine rnf */
    2619             : INLINE long
    2620      310751 : rnf_get_degree(GEN rnf) { return degpol(rnf_get_pol(rnf)); }
    2621             : INLINE long
    2622       14728 : rnf_get_nfdegree(GEN rnf) { return degpol(nf_get_pol(rnf_get_nf(rnf))); }
    2623             : INLINE long
    2624      156254 : rnf_get_absdegree(GEN rnf) { return degpol(gmael(rnf,11,1)); }
    2625             : INLINE GEN
    2626         427 : rnf_get_idealdisc(GEN rnf) { return gmael(rnf,3,1); }
    2627             : INLINE GEN
    2628         455 : rnf_get_k(GEN rnf) { return gmael(rnf,11,3); }
    2629             : INLINE GEN
    2630         455 : rnf_get_alpha(GEN rnf) { return gmael(rnf, 11, 2); }
    2631             : INLINE GEN
    2632      124271 : rnf_get_nf(GEN rnf) { return gel(rnf,10); }
    2633             : INLINE void
    2634        1652 : rnf_get_nfzk(GEN rnf, GEN *b, GEN *cb) {*b=gmael(rnf,2,1); *cb=gmael(rnf,2,2);}
    2635             : INLINE GEN
    2636       93905 : rnf_get_polabs(GEN rnf) { return gmael(rnf,11,1); }
    2637             : INLINE GEN
    2638      462147 : rnf_get_pol(GEN rnf) { return gel(rnf,1); }
    2639             : INLINE GEN
    2640          63 : rnf_get_disc(GEN rnf) { return gel(rnf,3); }
    2641             : INLINE GEN
    2642         105 : rnf_get_index(GEN rnf) { return gel(rnf,4); }
    2643             : INLINE long
    2644           0 : rnf_get_varn(GEN rnf) { return varn(gel(rnf,1)); }
    2645             : INLINE GEN
    2646      106323 : rnf_get_nfpol(GEN rnf) { return gmael(rnf,10,1); }
    2647             : INLINE long
    2648         490 : rnf_get_nfvarn(GEN rnf) { return varn(gmael(rnf,10,1)); }
    2649             : INLINE GEN
    2650        2415 : rnf_get_zk(GEN rnf) { return gel(rnf,7); }
    2651             : INLINE GEN
    2652       33474 : rnf_get_map(GEN rnf) { return gel(rnf,11); }
    2653             : INLINE GEN
    2654        1190 : rnf_get_invzk(GEN rnf) { return gel(rnf,8); }
    2655             : 
    2656             : /* I integral ZM (not HNF), G ZM, rounded Cholesky form of a weighted
    2657             :  * T2 matrix. Reduce I wrt G */
    2658             : INLINE GEN
    2659        1316 : idealpseudored(GEN I, GEN G)
    2660        1316 : { return ZM_mul(I, ZM_lll(ZM_mul(G, I), 0.99, LLL_IM)); }
    2661             : 
    2662             : /* I integral (not necessarily HNF), G ZM, rounded Cholesky form of a weighted
    2663             :  * T2 matrix. Return m in I with T2(m) small */
    2664             : INLINE GEN
    2665      168933 : idealpseudomin(GEN I, GEN G)
    2666             : {
    2667      168933 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2668      168933 :   return ZM_ZC_mul(I, gel(u,1));
    2669             : }
    2670             : /* I, G as in idealpseudomin. Return an irrational m in I with T2(m) small */
    2671             : INLINE GEN
    2672      252473 : idealpseudomin_nonscalar(GEN I, GEN G)
    2673             : {
    2674      252473 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2675      252473 :   GEN m = ZM_ZC_mul(I, gel(u,1));
    2676      252473 :   if (ZV_isscalar(m) && lg(u) > 2) m = ZM_ZC_mul(I, gel(u,2));
    2677      252473 :   return m;
    2678             : }
    2679             : 
    2680             : INLINE GEN
    2681         336 : idealred_elt(GEN nf, GEN I) {
    2682         336 :   pari_sp av = avma;
    2683         336 :   GEN u = idealpseudomin(I, nf_get_roundG(nf));
    2684         336 :   return gerepileupto(av, u);
    2685             : }
    2686             : INLINE GEN
    2687      166505 : idealred(GEN nf, GEN I) { return idealred0(nf, I, NULL); }
    2688             : 
    2689             : INLINE GEN
    2690        1197 : idealchineseinit(GEN nf, GEN x)
    2691        1197 : { return idealchinese(nf,x,NULL); }
    2692             : 
    2693             : /*******************************************************************/
    2694             : /*                                                                 */
    2695             : /*                              CLOSURES                           */
    2696             : /*                                                                 */
    2697             : /*******************************************************************/
    2698   185939690 : INLINE long closure_arity(GEN C)          { return ((ulong)C[1])&ARITYBITS; }
    2699    34372755 : INLINE long closure_is_variadic(GEN C) { return !!(((ulong)C[1])&VARARGBITS); }
    2700   151393319 : INLINE const char *closure_codestr(GEN C)  { return GSTR(gel(C,2))-1; }
    2701           0 : INLINE GEN closure_get_code(GEN C)  { return gel(C,2); }
    2702   151361756 : INLINE GEN closure_get_oper(GEN C)  { return gel(C,3); }
    2703   151345269 : INLINE GEN closure_get_data(GEN C)  { return gel(C,4); }
    2704       16211 : INLINE GEN closure_get_dbg(GEN C)   { return gel(C,5); }
    2705       34396 : INLINE GEN closure_get_text(GEN C)  { return gel(C,6); }
    2706      568682 : INLINE GEN closure_get_frame(GEN C) { return gel(C,7); }
    2707             : 
    2708             : /*******************************************************************/
    2709             : /*                                                                 */
    2710             : /*                               ERRORS                            */
    2711             : /*                                                                 */
    2712             : /*******************************************************************/
    2713             : INLINE long
    2714       46648 : err_get_num(GEN e) { return e[1]; }
    2715             : INLINE GEN
    2716          70 : err_get_compo(GEN e, long i) { return gel(e, i+1); }
    2717             : 
    2718             : INLINE void
    2719          14 : pari_err_BUG(const char *f) { pari_err(e_BUG,f); }
    2720             : INLINE void
    2721           7 : pari_err_CONSTPOL(const char *f) { pari_err(e_CONSTPOL, f); }
    2722             : INLINE void
    2723          70 : pari_err_COPRIME(const char *f, GEN x, GEN y) { pari_err(e_COPRIME, f,x,y); }
    2724             : INLINE void
    2725         890 : pari_err_DIM(const char *f) { pari_err(e_DIM, f); }
    2726             : INLINE void
    2727           0 : pari_err_FILE(const char *f, const char *g) { pari_err(e_FILE, f,g); }
    2728             : INLINE void
    2729          21 : pari_err_FLAG(const char *f) { pari_err(e_FLAG,f); }
    2730             : INLINE void
    2731         238 : pari_err_IMPL(const char *f) { pari_err(e_IMPL,f); }
    2732             : INLINE void
    2733         732 : pari_err_INV(const char *f, GEN x) { pari_err(e_INV,f,x); }
    2734             : INLINE void
    2735          14 : pari_err_IRREDPOL(const char *f, GEN x) { pari_err(e_IRREDPOL, f,x); }
    2736             : INLINE void
    2737        5082 : 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); }
    2738             : INLINE void
    2739         224 : pari_err_COMPONENT(const char *f, const char *op, GEN l, GEN x) { pari_err(e_COMPONENT, f,op,l,x); }
    2740             : INLINE void
    2741           0 : pari_err_MAXPRIME(ulong c) { pari_err(e_MAXPRIME, c); }
    2742             : INLINE void
    2743         294 : pari_err_OP(const char *f, GEN x, GEN y) { pari_err(e_OP, f,x,y); }
    2744             : INLINE void
    2745          63 : pari_err_OVERFLOW(const char *f) { pari_err(e_OVERFLOW, f); }
    2746             : INLINE void
    2747         225 : pari_err_PREC(const char *f) { pari_err(e_PREC,f); }
    2748             : INLINE void
    2749           0 : pari_err_PACKAGE(const char *f) { pari_err(e_PACKAGE,f); }
    2750             : INLINE void
    2751          49 : pari_err_PRIME(const char *f, GEN x) { pari_err(e_PRIME, f,x); }
    2752             : INLINE void
    2753         721 : pari_err_MODULUS(const char *f, GEN x, GEN y) { pari_err(e_MODULUS, f,x,y); }
    2754             : INLINE void
    2755          35 : pari_err_ROOTS0(const char *f) { pari_err(e_ROOTS0, f); }
    2756             : INLINE void
    2757          77 : pari_err_SQRTN(const char *f, GEN x) { pari_err(e_SQRTN, f,x); }
    2758             : INLINE void
    2759       24418 : pari_err_TYPE(const char *f, GEN x) { pari_err(e_TYPE, f,x); }
    2760             : INLINE void
    2761        3010 : pari_err_TYPE2(const char *f, GEN x, GEN y) { pari_err(e_TYPE2, f,x,y); }
    2762             : INLINE void
    2763         490 : pari_err_VAR(const char *f, GEN x, GEN y) { pari_err(e_VAR, f,x,y); }
    2764             : INLINE void
    2765         112 : pari_err_PRIORITY(const char *f, GEN x, const char *op, long v)
    2766         112 : { pari_err(e_PRIORITY, f,x,op,v); }

Generated by: LCOV version 1.11