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 19608-b7b365e) Lines: 1206 1360 88.7 %
Date: 2016-09-26 05:54:43 Functions: 511 577 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 retmkrfrac(x,y)\
      24             :   do { GEN _v = cgetg(3, t_RFRAC);\
      25             :        gel(_v,1) = (x);\
      26             :        gel(_v,2) = (y); return _v; } while(0)
      27             : #define retmkintmod(x,y)\
      28             :   do { GEN _v = cgetg(3, t_INTMOD);\
      29             :        gel(_v,1) = (y);\
      30             :        gel(_v,2) = (x); return _v; } while(0)
      31             : #define retmkcomplex(x,y)\
      32             :   do { GEN _v = cgetg(3, t_COMPLEX);\
      33             :        gel(_v,1) = (x);\
      34             :        gel(_v,2) = (y); return _v; } while(0)
      35             : #define retmkpolmod(x,y)\
      36             :   do { GEN _v = cgetg(3, t_POLMOD);\
      37             :        gel(_v,1) = (y);\
      38             :        gel(_v,2) = (x); return _v; } while(0)
      39             : #define retmkvec(x)\
      40             :   do { GEN _v = cgetg(2, t_VEC);\
      41             :        gel(_v,1) = (x); return _v; } while(0)
      42             : #define retmkvec2(x,y)\
      43             :   do { GEN _v = cgetg(3, t_VEC);\
      44             :        gel(_v,1) = (x);\
      45             :        gel(_v,2) = (y); return _v; } while(0)
      46             : #define retmkvec3(x,y,z)\
      47             :   do { GEN _v = cgetg(4, t_VEC);\
      48             :        gel(_v,1) = (x);\
      49             :        gel(_v,2) = (y);\
      50             :        gel(_v,3) = (z); return _v; } while(0)
      51             : #define retmkqfi(x,y,z)\
      52             :   do { GEN _v = cgetg(4, t_QFI);\
      53             :        gel(_v,1) = (x);\
      54             :        gel(_v,2) = (y);\
      55             :        gel(_v,3) = (z); return _v; } while(0)
      56             : #define retmkqfr(x,y,z,d)\
      57             :   do { GEN _v = cgetg(5, t_QFR);\
      58             :        gel(_v,1) = (x);\
      59             :        gel(_v,2) = (y);\
      60             :        gel(_v,3) = (z);\
      61             :        gel(_v,4) = (d); return _v; } while(0)
      62             : #define retmkquad(x,y,z)\
      63             :   do { GEN _v = cgetg(4, t_QUAD);\
      64             :        gel(_v,1) = (x);\
      65             :        gel(_v,2) = (y);\
      66             :        gel(_v,3) = (z); return _v; } while(0)
      67             : #define retmkvec4(x,y,z,t)\
      68             :   do { GEN _v = cgetg(5, t_VEC);\
      69             :        gel(_v,1) = (x);\
      70             :        gel(_v,2) = (y);\
      71             :        gel(_v,3) = (z);\
      72             :        gel(_v,4) = (t); return _v; } while(0)
      73             : #define retmkvec5(x,y,z,t,u)\
      74             :   do { GEN _v = cgetg(6, t_VEC);\
      75             :        gel(_v,1) = (x);\
      76             :        gel(_v,2) = (y);\
      77             :        gel(_v,3) = (z);\
      78             :        gel(_v,4) = (t);\
      79             :        gel(_v,5) = (u); return _v; } while(0)
      80             : #define retmkcol(x)\
      81             :   do { GEN _v = cgetg(2, t_COL);\
      82             :        gel(_v,1) = (x); return _v; } while(0)
      83             : #define retmkcol2(x,y)\
      84             :   do { GEN _v = cgetg(3, t_COL);\
      85             :        gel(_v,1) = (x);\
      86             :        gel(_v,2) = (y); return _v; } while(0)
      87             : #define retmkcol3(x,y,z)\
      88             :   do { GEN _v = cgetg(4, t_COL);\
      89             :        gel(_v,1) = (x);\
      90             :        gel(_v,2) = (y);\
      91             :        gel(_v,3) = (z); return _v; } while(0)
      92             : #define retmkcol4(x,y,z,t)\
      93             :   do { GEN _v = cgetg(5, t_COL);\
      94             :        gel(_v,1) = (x);\
      95             :        gel(_v,2) = (y);\
      96             :        gel(_v,3) = (z);\
      97             :        gel(_v,4) = (t); return _v; } while(0)
      98             : #define retmkcol5(x,y,z,t,u)\
      99             :   do { GEN _v = cgetg(6, t_COL);\
     100             :        gel(_v,1) = (x);\
     101             :        gel(_v,2) = (y);\
     102             :        gel(_v,3) = (z);\
     103             :        gel(_v,4) = (t);\
     104             :        gel(_v,5) = (u); return _v; } while(0)
     105             : #define retmkcol6(x,y,z,t,u,v)\
     106             :   do { GEN _v = cgetg(7, t_COL);\
     107             :        gel(_v,1) = (x);\
     108             :        gel(_v,2) = (y);\
     109             :        gel(_v,3) = (z);\
     110             :        gel(_v,4) = (t);\
     111             :        gel(_v,5) = (u);\
     112             :        gel(_v,6) = (v); return _v; } while(0)
     113             : #define retmkmat(x)\
     114             :   do { GEN _v = cgetg(2, t_MAT);\
     115             :        gel(_v,1) = (x); return _v; } while(0)
     116             : #define retmkmat2(x,y)\
     117             :   do { GEN _v = cgetg(3, t_MAT);\
     118             :        gel(_v,1) = (x);\
     119             :        gel(_v,2) = (y); return _v; } while(0)
     120             : #define retmkmat3(x,y,z)\
     121             :   do { GEN _v = cgetg(4, t_MAT);\
     122             :        gel(_v,1) = (x);\
     123             :        gel(_v,2) = (y);\
     124             :        gel(_v,3) = (z); return _v; } while(0)
     125             : #define retmkmat4(x,y,z,t)\
     126             :   do { GEN _v = cgetg(5, t_MAT);\
     127             :        gel(_v,1) = (x);\
     128             :        gel(_v,2) = (y);\
     129             :        gel(_v,3) = (z);\
     130             :        gel(_v,4) = (t); return _v; } while(0)
     131             : #define retmkmat5(x,y,z,t,u)\
     132             :   do { GEN _v = cgetg(6, t_MAT);\
     133             :        gel(_v,1) = (x);\
     134             :        gel(_v,2) = (y);\
     135             :        gel(_v,3) = (z);\
     136             :        gel(_v,4) = (t);\
     137             :        gel(_v,5) = (u); return _v; } while(0)
     138             : 
     139             : INLINE GEN
     140      332070 : mkintmod(GEN x, GEN y) { retmkintmod(x,y); }
     141             : INLINE GEN
     142        3780 : mkintmodu(ulong x, ulong y) {
     143        3780 :   GEN v = cgetg(3,t_INTMOD);
     144        3780 :   gel(v,1) = utoipos(y);
     145        3780 :   gel(v,2) = utoi(x); return v;
     146             : }
     147             : INLINE GEN
     148      247915 : mkpolmod(GEN x, GEN y) { retmkpolmod(x,y); }
     149             : INLINE GEN
     150     1774253 : mkfrac(GEN x, GEN y) { retmkfrac(x,y); }
     151             : INLINE GEN
     152     2433166 : mkfraccopy(GEN x, GEN y) { retmkfrac(icopy(x), icopy(y)); }
     153             : INLINE GEN
     154        5019 : mkrfrac(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     155        5019 :   gel(v,1) = x; gel(v,2) = y; return v; }
     156             : INLINE GEN
     157          14 : mkrfraccopy(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     158          14 :   gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     159             : INLINE GEN
     160     2894006 : mkcomplex(GEN x, GEN y) { retmkcomplex(x,y); }
     161             : INLINE GEN
     162      425245 : gen_I(void) { return mkcomplex(gen_0, gen_1); }
     163             : INLINE GEN
     164      200592 : cgetc(long l) { retmkcomplex(cgetr(l), cgetr(l)); }
     165             : INLINE GEN
     166          42 : mkquad(GEN n, GEN x, GEN y) { GEN v = cgetg(4, t_QUAD);
     167          42 :   gel(v,1) = n; gel(v,2) = x; gel(v,3) = y; return v; }
     168             : /* vecsmall */
     169             : INLINE GEN
     170    48866193 : mkvecsmall(long x) { GEN v = cgetg(2, t_VECSMALL); v[1] = x; return v; }
     171             : INLINE GEN
     172   106833338 : mkvecsmall2(long x,long y) { GEN v = cgetg(3, t_VECSMALL);
     173   106837671 :   v[1]=x; v[2]=y; return v; }
     174             : INLINE GEN
     175    66060301 : mkvecsmall3(long x,long y,long z) { GEN v = cgetg(4, t_VECSMALL);
     176    66055651 :   v[1]=x; v[2]=y; v[3]=z; return v; }
     177             : INLINE GEN
     178     9442259 : mkvecsmall4(long x,long y,long z,long t) { GEN v = cgetg(5, t_VECSMALL);
     179     9437674 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; return v; }
     180             : INLINE GEN
     181      611369 : mkvecsmall5(long x,long y,long z,long t,long u) { GEN v = cgetg(6, t_VECSMALL);
     182      611369 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; v[5]=u; return v; }
     183             : 
     184             : INLINE GEN
     185      158123 : mkqfi(GEN x, GEN y, GEN z) { retmkqfi(x,y,z); }
     186             : /* vec */
     187             : INLINE GEN
     188     3560174 : mkvec(GEN x) { retmkvec(x); }
     189             : INLINE GEN
     190    22962321 : mkvec2(GEN x, GEN y) { retmkvec2(x,y); }
     191             : INLINE GEN
     192    65149493 : mkvec3(GEN x, GEN y, GEN z) { retmkvec3(x,y,z); }
     193             : INLINE GEN
     194     7335373 : mkvec4(GEN x, GEN y, GEN z, GEN t) { retmkvec4(x,y,z,t); }
     195             : INLINE GEN
     196    11767410 : mkvec5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkvec5(x,y,z,t,u); }
     197             : INLINE GEN
     198           7 : mkvecs(long x) { retmkvec(stoi(x)); }
     199             : INLINE GEN
     200       11774 : mkvec2s(long x, long y) { retmkvec2(stoi(x),stoi(y)); }
     201             : INLINE GEN
     202      492702 : mkvec3s(long x, long y, long z) { retmkvec3(stoi(x),stoi(y),stoi(z)); }
     203             : INLINE GEN
     204           0 : mkvec4s(long x, long y, long z, long t) { retmkvec4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     205             : INLINE GEN
     206       33264 : mkveccopy(GEN x) { GEN v = cgetg(2, t_VEC); gel(v,1) = gcopy(x); return v; }
     207             : INLINE GEN
     208      259204 : mkvec2copy(GEN x, GEN y) {
     209      259204 :   GEN v = cgetg(3,t_VEC); gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     210             : /* col */
     211             : INLINE GEN
     212     2120661 : mkcol(GEN x) { retmkcol(x); }
     213             : INLINE GEN
     214    14755330 : mkcol2(GEN x, GEN y) { retmkcol2(x,y); }
     215             : INLINE GEN
     216       41615 : mkcol3(GEN x, GEN y, GEN z) { retmkcol3(x,y,z); }
     217             : INLINE GEN
     218           0 : mkcol4(GEN x, GEN y, GEN z, GEN t) { retmkcol4(x,y,z,t); }
     219             : INLINE GEN
     220           0 : mkcol5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkcol5(x,y,z,t,u); }
     221             : INLINE GEN
     222         687 : mkcol6(GEN x, GEN y, GEN z, GEN t, GEN u, GEN v) { retmkcol6(x,y,z,t,u,v); }
     223             : INLINE GEN
     224        6615 : mkcols(long x) { retmkcol(stoi(x)); }
     225             : INLINE GEN
     226     1189972 : mkcol2s(long x, long y) { retmkcol2(stoi(x),stoi(y)); }
     227             : INLINE GEN
     228           0 : mkcol3s(long x, long y, long z) { retmkcol3(stoi(x),stoi(y),stoi(z)); }
     229             : INLINE GEN
     230           0 : mkcol4s(long x, long y, long z, long t) { retmkcol4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     231             : INLINE GEN
     232       27703 : mkcolcopy(GEN x) { GEN v = cgetg(2, t_COL); gel(v,1) = gcopy(x); return v; }
     233             : /* mat */
     234             : INLINE GEN
     235      654805 : mkmat(GEN x) { retmkmat(x); }
     236             : INLINE GEN
     237    14976684 : mkmat2(GEN x, GEN y) { retmkmat2(x,y); }
     238             : INLINE GEN
     239        2352 : mkmat3(GEN x, GEN y, GEN z) { retmkmat3(x,y,z); }
     240             : INLINE GEN
     241           0 : mkmat4(GEN x, GEN y, GEN z, GEN t) { retmkmat4(x,y,z,t); }
     242             : INLINE GEN
     243           0 : mkmat5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkmat5(x,y,z,t,u); }
     244             : INLINE GEN
     245        7096 : mkmatcopy(GEN x) { GEN v = cgetg(2, t_MAT); gel(v,1) = gcopy(x); return v; }
     246             : INLINE GEN
     247           0 : mkerr(long x) { GEN v = cgetg(2, t_ERROR); v[1] = x; return v; }
     248             : INLINE GEN
     249       11862 : mkoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_1; return v; }
     250             : INLINE GEN
     251        7350 : mkmoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_m1; return v; }
     252             : INLINE long
     253       25922 : inf_get_sign(GEN x) { return signe(gel(x,1)); }
     254             : /* pol */
     255             : INLINE GEN
     256      683632 : pol_x(long v) {
     257      683632 :   GEN p = cgetg(4, t_POL);
     258      683632 :   p[1] = evalsigne(1)|evalvarn(v);
     259      683632 :   gel(p,2) = gen_0;
     260      683632 :   gel(p,3) = gen_1; return p;
     261             : }
     262             : /* x^n, assume n >= 0 */
     263             : INLINE GEN
     264     2307177 : pol_xn(long n, long v) {
     265     2307177 :   long i, a = n+2;
     266     2307177 :   GEN p = cgetg(a+1, t_POL);
     267     2307177 :   p[1] = evalsigne(1)|evalvarn(v);
     268     2307177 :   for (i = 2; i < a; i++) gel(p,i) = gen_0;
     269     2307177 :   gel(p,a) = gen_1; return p;
     270             : }
     271             : /* x^n, no assumption on n */
     272             : INLINE GEN
     273          98 : pol_xnall(long n, long v)
     274             : {
     275          98 :   if (n < 0) retmkrfrac(gen_1, pol_xn(-n,v));
     276          42 :   return pol_xn(n, v);
     277             : }
     278             : INLINE GEN
     279     1184618 : pol_1(long v) {
     280     1184618 :   GEN p = cgetg(3, t_POL);
     281     1184618 :   p[1] = evalsigne(1)|evalvarn(v);
     282     1184618 :   gel(p,2) = gen_1; return p;
     283             : }
     284             : INLINE GEN
     285    12987745 : pol_0(long v)
     286             : {
     287    12987745 :   GEN x = cgetg(2,t_POL);
     288    12987745 :   x[1] = evalvarn(v); return x;
     289             : }
     290             : #define retconst_vec(n,x)\
     291             :   do { long _i, _n = (n);\
     292             :        GEN _v = cgetg(_n+1, t_VEC), _x = (x);\
     293             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     294             :        return _v; } while(0)
     295             : INLINE GEN
     296    11104102 : const_vec(long n, GEN x) { retconst_vec(n, x); }
     297             : #define retconst_col(n,x)\
     298             :   do { long _i, _n = (n);\
     299             :        GEN _v = cgetg(_n+1, t_COL), _x = (x);\
     300             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     301             :        return _v; } while(0)
     302             : INLINE GEN
     303       25243 : const_col(long n, GEN x) { retconst_col(n, x); }
     304             : INLINE GEN
     305     5875437 : const_vecsmall(long n, long c)
     306             : {
     307             :   long i;
     308     5875437 :   GEN V = cgetg(n+1,t_VECSMALL);
     309     5875437 :   for(i=1;i<=n;i++) V[i] = c;
     310     5875437 :   return V;
     311             : }
     312             : 
     313             : /***   ZERO   ***/
     314             : /* O(p^e) */
     315             : INLINE GEN
     316      303786 : zeropadic(GEN p, long e)
     317             : {
     318      303786 :   GEN y = cgetg(5,t_PADIC);
     319      303786 :   gel(y,4) = gen_0;
     320      303786 :   gel(y,3) = gen_1;
     321      303786 :   gel(y,2) = icopy(p);
     322      303786 :   y[1] = evalvalp(e) | _evalprecp(0);
     323      303786 :   return y;
     324             : }
     325             : INLINE GEN
     326         476 : zeropadic_shallow(GEN p, long e)
     327             : {
     328         476 :   GEN y = cgetg(5,t_PADIC);
     329         476 :   gel(y,4) = gen_0;
     330         476 :   gel(y,3) = gen_1;
     331         476 :   gel(y,2) = p;
     332         476 :   y[1] = evalvalp(e) | _evalprecp(0);
     333         476 :   return y;
     334             : }
     335             : /* O(pol_x(v)^e) */
     336             : INLINE GEN
     337       12082 : zeroser(long v, long e)
     338             : {
     339       12082 :   GEN x = cgetg(2, t_SER);
     340       12082 :   x[1] = evalvalp(e) | evalvarn(v); return x;
     341             : }
     342             : INLINE int
     343     3817881 : ser_isexactzero(GEN x)
     344             : {
     345     3817881 :   if (!signe(x)) switch(lg(x))
     346             :   {
     347       10479 :     case 2: return 1;
     348         252 :     case 3: return isexactzero(gel(x,2));
     349             :   }
     350     3807150 :   return 0;
     351             : }
     352             : /* 0 * pol_x(v) */
     353             : INLINE GEN
     354     4203636 : zeropol(long v) { return pol_0(v); }
     355             : /* vector(n) */
     356             : INLINE GEN
     357    28192560 : zerocol(long n)
     358             : {
     359    28192560 :   GEN y = cgetg(n+1,t_COL);
     360    28192560 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     361    28192560 :   return y;
     362             : }
     363             : /* vectorv(n) */
     364             : INLINE GEN
     365     7997068 : zerovec(long n)
     366             : {
     367     7997068 :   GEN y = cgetg(n+1,t_VEC);
     368     7997071 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     369     7997071 :   return y;
     370             : }
     371             : /* matrix(m, n) */
     372             : INLINE GEN
     373        6636 : zeromat(long m, long n)
     374             : {
     375        6636 :   GEN y = cgetg(n+1,t_MAT);
     376        6636 :   GEN v = zerocol(m);
     377        6636 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     378        6636 :   return y;
     379             : }
     380             : /* = zero_zx, sv is a evalvarn()*/
     381             : INLINE GEN
     382      759905 : zero_Flx(long sv) { return pol0_Flx(sv); }
     383             : INLINE GEN
     384    29554796 : zero_Flv(long n)
     385             : {
     386    29554796 :   GEN y = cgetg(n+1,t_VECSMALL);
     387    29554804 :   long i; for (i=1; i<=n; i++) y[i] = 0;
     388    29554804 :   return y;
     389             : }
     390             : /* matrix(m, n) */
     391             : INLINE GEN
     392         175 : zero_Flm(long m, long n)
     393             : {
     394         175 :   GEN y = cgetg(n+1,t_MAT);
     395         175 :   GEN v = zero_Flv(m);
     396         175 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     397         175 :   return y;
     398             : }
     399             : /* matrix(m, n) */
     400             : INLINE GEN
     401      104015 : zero_Flm_copy(long m, long n)
     402             : {
     403      104015 :   GEN y = cgetg(n+1,t_MAT);
     404      104028 :   long i; for (i=1; i<=n; i++) gel(y,i) = zero_Flv(m);
     405      104020 :   return y;
     406             : }
     407             : 
     408             : INLINE GEN
     409      763187 : zero_F2v(long m)
     410             : {
     411      763187 :   long l = nbits2nlong(m);
     412      763187 :   GEN v  = zero_Flv(l+1);
     413      763187 :   v[1] = m;
     414      763187 :   return v;
     415             : }
     416             : 
     417             : INLINE GEN
     418           0 : zero_F2m(long m, long n)
     419             : {
     420             :   long i;
     421           0 :   GEN M = cgetg(n+1, t_MAT);
     422           0 :   GEN v = zero_F2v(m);
     423           0 :   for (i = 1; i <= n; i++)
     424           0 :     gel(M,i) = v;
     425           0 :   return M;
     426             : }
     427             : 
     428             : 
     429             : INLINE GEN
     430      277480 : zero_F2m_copy(long m, long n)
     431             : {
     432             :   long i;
     433      277480 :   GEN M = cgetg(n+1, t_MAT);
     434      788586 :   for (i = 1; i <= n; i++)
     435      511106 :     gel(M,i)= zero_F2v(m);
     436      277480 :   return M;
     437             : }
     438             : 
     439             : /* matrix(m, n) */
     440             : INLINE GEN
     441     2274194 : zeromatcopy(long m, long n)
     442             : {
     443     2274194 :   GEN y = cgetg(n+1,t_MAT);
     444     2274194 :   long i; for (i=1; i<=n; i++) gel(y,i) = zerocol(m);
     445     2274194 :   return y;
     446             : }
     447             : 
     448             : /* i-th vector in the standard basis */
     449             : INLINE GEN
     450     2059449 : col_ei(long n, long i) { GEN e = zerocol(n); gel(e,i) = gen_1; return e; }
     451             : INLINE GEN
     452      302184 : vec_ei(long n, long i) { GEN e = zerovec(n); gel(e,i) = gen_1; return e; }
     453             : INLINE GEN
     454           7 : F2v_ei(long n, long i) { GEN e = zero_F2v(n); F2v_set(e,i); return e; }
     455             : INLINE GEN
     456        9226 : vecsmall_ei(long n, long i) { GEN e = zero_zv(n); e[i] = 1; return e; }
     457             : INLINE GEN
     458     4017138 : Rg_col_ei(GEN x, long n, long i) { GEN e = zerocol(n); gel(e,i) = x; return e; }
     459             : 
     460             : INLINE GEN
     461     1515548 : shallowcopy(GEN x)
     462     1515548 : { return typ(x) == t_MAT ? RgM_shallowcopy(x): leafcopy(x); }
     463             : 
     464             : /* routines for naive growarrays */
     465             : INLINE GEN
     466    11523194 : vectrunc_init(long l)
     467             : {
     468    11523194 :   GEN z = new_chunk(l);
     469    11523623 :   z[0] = evaltyp(t_VEC) | _evallg(1); return z;
     470             : }
     471             : INLINE void
     472    43061144 : vectrunc_append(GEN x, GEN t)
     473    43061144 : { long l = lg(x); gel(x,l) = t; setlg(x, l+1); }
     474             : INLINE void
     475           0 : vectrunc_append_batch(GEN x, GEN y)
     476             : {
     477           0 :   long i, l = lg(x), ly = lg(y);
     478           0 :   GEN z = x + l-1;
     479           0 :   for (i = 1; i < ly; i++) gel(z,i) = gel(y,i);
     480           0 :   setlg(x, l+ly-1);
     481           0 : }
     482             : INLINE GEN
     483     1336600 : vecsmalltrunc_init(long l)
     484             : {
     485     1336600 :   GEN z = new_chunk(l);
     486     1336600 :   z[0] = evaltyp(t_VECSMALL) | _evallg(1); return z;
     487             : }
     488             : INLINE void
     489     2714989 : vecsmalltrunc_append(GEN x, long t)
     490     2714989 : { long l = lg(x); x[l] = t; setlg(x, l+1); }
     491             : 
     492             : /*******************************************************************/
     493             : /*                                                                 */
     494             : /*                        VEC / COL / VECSMALL                     */
     495             : /*                                                                 */
     496             : /*******************************************************************/
     497             : /* shallow*/
     498             : INLINE GEN
     499           0 : vec_shorten(GEN v, long n)
     500             : {
     501             :   long i;
     502           0 :   GEN V = cgetg(n+1,t_VEC);
     503           0 :   for(i=1;i<=n;i++) gel(V,i) = gel(v,i);
     504           0 :   return V;
     505             : }
     506             : /* shallow*/
     507             : INLINE GEN
     508       10584 : vec_lengthen(GEN v, long n)
     509             : {
     510             :   long i;
     511       10584 :   long l=lg(v);
     512       10584 :   GEN V = cgetg(n+1,t_VEC);
     513       10584 :   for(i=1;i<l;i++) gel(V,i) = gel(v,i);
     514       10584 :   return V;
     515             : }
     516             : /* shallow*/
     517             : INLINE GEN
     518       56021 : vec_append(GEN V, GEN s)
     519             : {
     520       56021 :   long i, l2 = lg(V);
     521       56021 :   GEN res = cgetg(l2+1, typ(V));
     522       56021 :   for (i = 1; i < l2; ++i) gel(res, i) = gel(V,i);
     523       56021 :   gel(res,l2) = s; return res;
     524             : }
     525             : /* shallow*/
     526             : INLINE GEN
     527        1736 : vec_setconst(GEN v, GEN x)
     528             : {
     529        1736 :   long i, l = lg(v);
     530        1736 :   for (i = 1; i < l; i++) gel(v,i) = x;
     531        1736 :   return v;
     532             : }
     533             : INLINE GEN
     534      136467 : vecsmall_shorten(GEN v, long n)
     535             : {
     536             :   long i;
     537      136467 :   GEN V = cgetg(n+1,t_VECSMALL);
     538      136467 :   for(i=1;i<=n;i++) V[i] = v[i];
     539      136467 :   return V;
     540             : }
     541             : INLINE GEN
     542          21 : vecsmall_lengthen(GEN v, long n)
     543             : {
     544          21 :   long i, l = lg(v);
     545          21 :   GEN V = cgetg(n+1,t_VECSMALL);
     546          21 :   for(i=1;i<l;i++) V[i] = v[i];
     547          21 :   return V;
     548             : }
     549             : 
     550             : INLINE GEN
     551      235261 : vec_to_vecsmall(GEN z)
     552             : {
     553      235261 :   long i, l = lg(z);
     554      235261 :   GEN x = cgetg(l, t_VECSMALL);
     555      235261 :   for (i=1; i<l; i++) x[i] = itos(gel(z,i));
     556      235261 :   return x;
     557             : }
     558             : INLINE GEN
     559       15477 : vecsmall_to_vec(GEN z)
     560             : {
     561       15477 :   long i, l = lg(z);
     562       15477 :   GEN x = cgetg(l,t_VEC);
     563       15477 :   for (i=1; i<l; i++) gel(x,i) = stoi(z[i]);
     564       15477 :   return x;
     565             : }
     566             : INLINE GEN
     567     1133400 : vecsmall_to_col(GEN z)
     568             : {
     569     1133400 :   long i, l = lg(z);
     570     1133400 :   GEN x = cgetg(l,t_COL);
     571     1133400 :   for (i=1; i<l; i++) gel(x,i) = stoi(z[i]);
     572     1133400 :   return x;
     573             : }
     574             : 
     575             : INLINE int
     576     2763075 : vecsmall_lexcmp(GEN x, GEN y)
     577             : {
     578             :   long lx,ly,l,i;
     579     2763075 :   lx = lg(x);
     580     2763075 :   ly = lg(y); l = minss(lx,ly);
     581    15179787 :   for (i=1; i<l; i++)
     582    14495488 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     583      684299 :   if (lx == ly) return 0;
     584           0 :   return (lx < ly)? -1 : 1;
     585             : }
     586             : 
     587             : INLINE int
     588    47066978 : vecsmall_prefixcmp(GEN x, GEN y)
     589             : {
     590    47066978 :   long i, lx = lg(x), ly = lg(y), l = minss(lx,ly);
     591   148811348 :   for (i=1; i<l; i++)
     592   134951817 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     593    13859531 :   return 0;
     594             : }
     595             : 
     596             : /*Can be used on t_VEC, but coeffs not gcopy-ed*/
     597             : INLINE GEN
     598        1218 : vecsmall_prepend(GEN V, long s)
     599             : {
     600        1218 :   long i, l2 = lg(V);
     601        1218 :   GEN res = cgetg(l2+1, typ(V));
     602        1218 :   res[1] = s;
     603        1218 :   for (i = 2; i <= l2; ++i) res[i] = V[i - 1];
     604        1218 :   return res;
     605             : }
     606             : 
     607             : INLINE GEN
     608      356748 : vecsmall_append(GEN V, long s)
     609             : {
     610      356748 :   long i, l2 = lg(V);
     611      356748 :   GEN res = cgetg(l2+1, t_VECSMALL);
     612      356748 :   for (i = 1; i < l2; ++i) res[i] = V[i];
     613      356748 :   res[l2] = s; return res;
     614             : }
     615             : 
     616             : INLINE GEN
     617      235116 : vecsmall_concat(GEN u, GEN v)
     618             : {
     619      235116 :   long i, l1 = lg(u)-1, l2 = lg(v)-1;
     620      235116 :   GEN res = cgetg(l1+l2+1, t_VECSMALL);
     621      235116 :   for (i = 1; i <= l1; ++i) res[i]    = u[i];
     622      235116 :   for (i = 1; i <= l2; ++i) res[i+l1] = v[i];
     623      235116 :   return res;
     624             : }
     625             : 
     626             : /* return the number of indices where u and v are equal */
     627             : INLINE long
     628           0 : vecsmall_coincidence(GEN u, GEN v)
     629             : {
     630           0 :   long i, s = 0, l = minss(lg(u),lg(v));
     631           0 :   for(i=1; i<l; i++)
     632           0 :     if(u[i] == v[i]) s++;
     633           0 :   return s;
     634             : }
     635             : 
     636             : /* returns the first index i<=n such that x=v[i] if it exists, 0 otherwise */
     637             : INLINE long
     638           0 : vecsmall_isin(GEN v, long x)
     639             : {
     640           0 :   long i, l = lg(v);
     641           0 :   for (i = 1; i < l; i++)
     642           0 :     if (v[i] == x) return i;
     643           0 :   return 0;
     644             : }
     645             : 
     646             : INLINE long
     647          84 : vecsmall_pack(GEN V, long base, long mod)
     648             : {
     649          84 :   long i, s = 0;
     650          84 :   for(i=1; i<lg(V); i++) s = (base*s + V[i]) % mod;
     651          84 :   return s;
     652             : }
     653             : 
     654             : INLINE long
     655          14 : vecsmall_indexmax(GEN x)
     656             : {
     657          14 :   long i, i0 = 1, t = x[1], lx = lg(x);
     658          56 :   for (i=2; i<lx; i++)
     659          42 :     if (x[i] > t) t = x[i0=i];
     660          14 :   return i0;
     661             : }
     662             : 
     663             : INLINE long
     664       35732 : vecsmall_max(GEN x)
     665             : {
     666       35732 :   long i, t = x[1], lx = lg(x);
     667       61160 :   for (i=2; i<lx; i++)
     668       25428 :     if (x[i] > t) t = x[i];
     669       35732 :   return t;
     670             : }
     671             : 
     672             : INLINE long
     673          14 : vecsmall_indexmin(GEN x)
     674             : {
     675          14 :   long i, i0 = 1, t = x[1], lx =lg(x);
     676          56 :   for (i=2; i<lx; i++)
     677          42 :     if (x[i] < t) t = x[i0=i];
     678          14 :   return i0;
     679             : }
     680             : 
     681             : INLINE long
     682         686 : vecsmall_min(GEN x)
     683             : {
     684         686 :   long i, t = x[1], lx =lg(x);
     685        2723 :   for (i=2; i<lx; i++)
     686        2037 :     if (x[i] < t) t = x[i];
     687         686 :   return t;
     688             : }
     689             : 
     690             : INLINE int
     691     2028986 : ZV_isscalar(GEN x)
     692             : {
     693     2028986 :   long l = lg(x);
     694     7738153 :   while (--l > 1)
     695     5323900 :     if (signe(gel(x, l))) return 0;
     696      385267 :   return 1;
     697             : }
     698             : INLINE int
     699     7088572 : QV_isscalar(GEN x)
     700             : {
     701     7088572 :   long lx = lg(x),i;
     702     8387321 :   for (i=2; i<lx; i++)
     703     7785534 :     if (!isintzero(gel(x, i))) return 0;
     704      601787 :   return 1;
     705             : }
     706             : INLINE int
     707        5307 : RgV_isscalar(GEN x)
     708             : {
     709        5307 :   long lx = lg(x),i;
     710        9524 :   for (i=2; i<lx; i++)
     711        8110 :     if (!gequal0(gel(x, i))) return 0;
     712        1414 :   return 1;
     713             : }
     714             : INLINE int
     715           0 : RgX_isscalar(GEN x)
     716             : {
     717             :   long i;
     718           0 :   for (i=lg(x)-1; i>2; i--)
     719           0 :     if (!gequal0(gel(x, i))) return 0;
     720           0 :   return 1;
     721             : }
     722             : INLINE long
     723     3798851 : RgX_equal_var(GEN x, GEN y) { return varn(x) == varn(y) && RgX_equal(x,y); }
     724             : 
     725             : INLINE int
     726        2745 : RgX_is_rational(GEN x)
     727             : {
     728             :   long i;
     729       25095 :   for (i = lg(x)-1; i > 1; i--)
     730       23610 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     731        1485 :   return 1;
     732             : }
     733             : INLINE int
     734    55010023 : RgX_is_ZX(GEN x)
     735             : {
     736             :   long i;
     737   245553179 :   for (i = lg(x)-1; i > 1; i--)
     738   195772137 :     if (typ(gel(x,i)) != t_INT) return 0;
     739    49781042 :   return 1;
     740             : }
     741             : INLINE int
     742      161747 : RgX_is_QX(GEN x)
     743             : {
     744      161747 :   long k = lg(x)-1;
     745      634178 :   for ( ; k>1; k--)
     746      473285 :     if (!is_rational_t(typ(gel(x,k)))) return 0;
     747      160893 :   return 1;
     748             : }
     749             : INLINE int
     750    15106017 : RgX_is_monomial(GEN x)
     751             : {
     752             :   long i;
     753    15106017 :   if (!signe(x)) return 0;
     754    24286794 :   for (i=lg(x)-2; i>1; i--)
     755    16784518 :     if (!isexactzero(gel(x,i))) return 0;
     756     7502276 :   return 1;
     757             : }
     758             : INLINE int
     759     2445296 : RgV_is_ZV(GEN x)
     760             : {
     761             :   long i;
     762     8662545 :   for (i = lg(x)-1; i > 0; i--)
     763     6217935 :     if (typ(gel(x,i)) != t_INT) return 0;
     764     2444610 :   return 1;
     765             : }
     766             : INLINE int
     767         147 : RgV_is_QV(GEN x)
     768             : {
     769             :   long i;
     770         413 :   for (i = lg(x)-1; i > 0; i--)
     771         280 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     772         133 :   return 1;
     773             : }
     774             : 
     775             : /********************************************************************/
     776             : /**                                                                **/
     777             : /**            Dynamic arrays implementation                       **/
     778             : /**                                                                **/
     779             : /********************************************************************/
     780             : INLINE void **
     781   333422310 : pari_stack_base(pari_stack *s) { return s->data; }
     782             : 
     783             : INLINE void
     784     2847479 : pari_stack_init(pari_stack *s, size_t size, void **data)
     785             : {
     786     2847479 :   s->data = data;
     787     2847479 :   *data = NULL;
     788     2847479 :   s->n = 0;
     789     2847479 :   s->alloc = 0;
     790     2847479 :   s->size = size;
     791     2847479 : }
     792             : 
     793             : INLINE void
     794   330876733 : pari_stack_alloc(pari_stack *s, long nb)
     795             : {
     796   330876733 :   void **sdat = pari_stack_base(s);
     797   661982561 :   if (s->n+nb <= s->alloc) return;
     798      768770 :   if (!s->alloc)
     799      723905 :     s->alloc = nb;
     800             :   else
     801             :   {
     802       44865 :     while (s->n+nb > s->alloc) s->alloc <<= 1;
     803             :   }
     804      768770 :   *sdat = pari_realloc(*sdat,s->alloc*s->size);
     805             : }
     806             : 
     807             : INLINE long
     808   277013100 : pari_stack_new(pari_stack *s) { pari_stack_alloc(s, 1); return s->n++; }
     809             : 
     810             : INLINE void
     811     2448037 : pari_stack_delete(pari_stack *s)
     812             : {
     813     2448037 :   void **sdat = pari_stack_base(s);
     814     2447509 :   if (*sdat) pari_free(*sdat);
     815     2448241 : }
     816             : 
     817             : INLINE void
     818        5544 : pari_stack_pushp(pari_stack *s, void *u)
     819             : {
     820        5544 :   long n = pari_stack_new(s);
     821        5544 :   void **sdat =(void**) *pari_stack_base(s);
     822        5544 :   sdat[n] = u;
     823        5544 : }
     824             : 
     825             : /*******************************************************************/
     826             : /*                                                                 */
     827             : /*                            EXTRACT                              */
     828             : /*                                                                 */
     829             : /*******************************************************************/
     830             : INLINE GEN
     831     4422828 : vecslice(GEN A, long y1, long y2)
     832             : {
     833     4422828 :   long i,lB = y2 - y1 + 2;
     834     4422828 :   GEN B = cgetg(lB, typ(A));
     835     4422828 :   for (i=1; i<lB; i++) B[i] = A[y1-1+i];
     836     4422828 :   return B;
     837             : }
     838             : INLINE GEN
     839      140114 : vecslicepermute(GEN A, GEN p, long y1, long y2)
     840             : {
     841      140114 :   long i,lB = y2 - y1 + 2;
     842      140114 :   GEN B = cgetg(lB, typ(A));
     843      140114 :   for (i=1; i<lB; i++) B[i] = A[p[y1-1+i]];
     844      140114 :   return B;
     845             : }
     846             : /* rowslice(rowpermute(A,p), x1, x2) */
     847             : INLINE GEN
     848       35014 : rowslicepermute(GEN A, GEN p, long x1, long x2)
     849             : {
     850       35014 :   long i, lB = lg(A);
     851       35014 :   GEN B = cgetg(lB, typ(A));
     852       35014 :   for (i=1; i<lB; i++) gel(B,i) = vecslicepermute(gel(A,i),p,x1,x2);
     853       35014 :   return B;
     854             : }
     855             : INLINE GEN
     856      197916 : rowslice(GEN A, long x1, long x2)
     857             : {
     858      197916 :   long i, lB = lg(A);
     859      197916 :   GEN B = cgetg(lB, typ(A));
     860      197916 :   for (i=1; i<lB; i++) gel(B,i) = vecslice(gel(A,i),x1,x2);
     861      197916 :   return B;
     862             : }
     863             : 
     864             : INLINE GEN
     865      102438 : matslice(GEN A, long x1, long x2, long y1, long y2)
     866             : {
     867      102438 :   return rowslice(vecslice(A, y1, y2), x1, x2);
     868             : }
     869             : 
     870             : /* shallow, remove coeff of index j */
     871             : INLINE GEN
     872         126 : rowsplice(GEN a, long j)
     873             : {
     874             :   long i, k, l;
     875         126 :   GEN b = cgetg_copy(a,&l);
     876         126 :   for (i = k = 1; i < l; i++) gel(b,i) = vecsplice(gel(a,i), j);
     877         126 :   return b;
     878             : }
     879             : /* shallow, remove coeff of index j */
     880             : INLINE GEN
     881        8253 : vecsplice(GEN a, long j)
     882             : {
     883        8253 :   long i, k, l = lg(a);
     884             :   GEN b;
     885        8253 :   if (l == 1) pari_err(e_MISC, "incorrect component in vecsplice");
     886        8253 :   b = cgetg(l-1, typ(a));
     887       45857 :   for (i = k = 1; i < l; i++)
     888       37604 :     if (i != j) gel(b, k++) = gel(a,i);
     889        8253 :   return b;
     890             : }
     891             : /* shallow */
     892             : INLINE GEN
     893         756 : RgM_minor(GEN a, long i, long j)
     894             : {
     895         756 :   GEN b = vecsplice(a, j);
     896         756 :   long k, l = lg(b);
     897         756 :   for (k = 1; k < l; k++) gel(b,k) = vecsplice(gel(b,k), i);
     898         756 :   return b;
     899             : }
     900             : 
     901             : /* A[x0,] */
     902             : INLINE GEN
     903      115695 : row(GEN A, long x0)
     904             : {
     905      115695 :   long i, lB = lg(A);
     906      115695 :   GEN B  = cgetg(lB, t_VEC);
     907      115695 :   for (i=1; i<lB; i++) gel(B, i) = gcoeff(A, x0, i);
     908      115695 :   return B;
     909             : }
     910             : INLINE GEN
     911       24544 : Flm_row(GEN A, long x0)
     912             : {
     913       24544 :   long i, lB = lg(A);
     914       24544 :   GEN B  = cgetg(lB, t_VECSMALL);
     915       24548 :   for (i=1; i<lB; i++) B[i] = coeff(A, x0, i);
     916       24548 :   return B;
     917             : }
     918             : /* A[x0,] */
     919             : INLINE GEN
     920          56 : rowcopy(GEN A, long x0)
     921             : {
     922          56 :   long i, lB = lg(A);
     923          56 :   GEN B  = cgetg(lB, t_VEC);
     924          56 :   for (i=1; i<lB; i++) gel(B, i) = gcopy(gcoeff(A, x0, i));
     925          56 :   return B;
     926             : }
     927             : /* A[x0, x1..x2] */
     928             : INLINE GEN
     929        2177 : row_i(GEN A, long x0, long x1, long x2)
     930             : {
     931        2177 :   long i, lB = x2 - x1 + 2;
     932        2177 :   GEN B  = cgetg(lB, t_VEC);
     933        2177 :   for (i=x1; i<=x2; i++) gel(B, i) = gcoeff(A, x0, i);
     934        2177 :   return B;
     935             : }
     936             : 
     937             : INLINE GEN
     938     4759623 : vecreverse(GEN A)
     939             : {
     940             :   long i, l;
     941     4759623 :   GEN B = cgetg_copy(A, &l);
     942     4759623 :   for (i=1; i<l; i++) gel(B, i) = gel(A, l-i);
     943     4759623 :   return B;
     944             : }
     945             : 
     946             : INLINE GEN
     947         252 : vecsmall_reverse(GEN A)
     948             : {
     949             :   long i, l;
     950         252 :   GEN B = cgetg_copy(A, &l);
     951         252 :   for (i=1; i<l; i++) B[i] = A[l-i];
     952         252 :   return B;
     953             : }
     954             : 
     955             : INLINE void
     956         232 : vecreverse_inplace(GEN y)
     957             : {
     958         232 :   long ly = lg(y), lim = ly>>1, i;
     959         640 :   for (i = 1; i <= lim; i++)
     960             :   {
     961         408 :     GEN z = gel(y,i);
     962         408 :     gel(y,i)    = gel(y,ly-i);
     963         408 :     gel(y,ly-i) = z;
     964             :   }
     965         232 : }
     966             : 
     967             : INLINE GEN
     968    20081739 : vecsmallpermute(GEN A, GEN p) { return perm_mul(A, p); }
     969             : 
     970             : INLINE GEN
     971     4995972 : vecpermute(GEN A, GEN p)
     972             : {
     973     4995972 :   long i,lB = lg(p);
     974     4995972 :   GEN B = cgetg(lB, typ(A));
     975     4995972 :   for (i=1; i<lB; i++) gel(B, i) = gel(A, p[i]);
     976     4995972 :   return B;
     977             : }
     978             : INLINE GEN
     979      203450 : rowpermute(GEN A, GEN p)
     980             : {
     981      203450 :   long i, lB = lg(A);
     982      203450 :   GEN B = cgetg(lB, typ(A));
     983     2169189 :   for (i=1; i<lB; i++)
     984     3886755 :     gel(B, i) = typ(gel(A,i)) == t_VECSMALL ? vecsmallpermute(gel(A, i), p):
     985     1921016 :                                                     vecpermute(gel(A, i), p);
     986      203450 :   return B;
     987             : }
     988             : /*******************************************************************/
     989             : /*                                                                 */
     990             : /*                          PERMUTATIONS                           */
     991             : /*                                                                 */
     992             : /*******************************************************************/
     993             : /* identity permutation */
     994             : INLINE GEN
     995       67009 : identity_perm(long n)
     996             : {
     997       67009 :   GEN perm = cgetg(n+1, t_VECSMALL);
     998             :   long i;
     999       67009 :   for (i = 1; i <= n; i++) perm[i] = i;
    1000       67009 :   return perm;
    1001             : }
    1002             : 
    1003             : /* assume d <= n */
    1004             : INLINE GEN
    1005           0 : cyclic_perm(long n, long d)
    1006             : {
    1007           0 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1008             :   long i;
    1009           0 :   for (i = 1; i <= n-d; i++) perm[i] = i+d;
    1010           0 :   for (     ; i <= n;   i++) perm[i] = i-n+d;
    1011           0 :   return perm;
    1012             : }
    1013             : 
    1014             : /* Multiply (compose) two permutations */
    1015             : INLINE GEN
    1016    20498946 : perm_mul(GEN s, GEN t)
    1017             : {
    1018             :   GEN u;
    1019    20498946 :   long i, l = lg(t);
    1020    20498946 :   u = cgetg(l, t_VECSMALL);
    1021    20498946 :   for (i = 1; i < l; i++) u[i] = s[ t[i] ];
    1022    20498946 :   return u;
    1023             : }
    1024             : /* Compute the inverse (reciprocal) of a permutation. */
    1025             : INLINE GEN
    1026        3815 : perm_inv(GEN x)
    1027             : {
    1028             :   long i, lx;
    1029        3815 :   GEN y = cgetg_copy(x, &lx);
    1030        3815 :   for (i=1; i<lx; i++) y[ x[i] ] = i;
    1031        3815 :   return y;
    1032             : }
    1033             : /* Return s*t*s^-1 */
    1034             : INLINE GEN
    1035          35 : perm_conj(GEN s, GEN t)
    1036             : {
    1037             :   long i, l;
    1038          35 :   GEN v = cgetg_copy(s, &l);
    1039          35 :   for (i = 1; i < l; i++) v[ s[i] ] = s[ t[i] ];
    1040          35 :   return v;
    1041             : }
    1042             : 
    1043             : /*********************************************************************/
    1044             : /*                       MALLOC/FREE WRAPPERS                        */
    1045             : /*********************************************************************/
    1046             : #define BLOCK_SIGALRM_START          \
    1047             : {                                    \
    1048             :   int block=PARI_SIGINT_block;       \
    1049             :   PARI_SIGINT_block = 2;             \
    1050             :   MT_SIGINT_BLOCK(block);
    1051             : 
    1052             : #define BLOCK_SIGINT_START           \
    1053             : {                                    \
    1054             :   int block=PARI_SIGINT_block;       \
    1055             :   PARI_SIGINT_block = 1;             \
    1056             :   MT_SIGINT_BLOCK(block);
    1057             : 
    1058             : #define BLOCK_SIGINT_END             \
    1059             :   PARI_SIGINT_block = block;         \
    1060             :   MT_SIGINT_UNBLOCK(block);          \
    1061             :   if (!block && PARI_SIGINT_pending) \
    1062             :   {                                  \
    1063             :     int sig = PARI_SIGINT_pending;   \
    1064             :     PARI_SIGINT_pending = 0;         \
    1065             :     raise(sig);                      \
    1066             :   }                                  \
    1067             : }
    1068             : 
    1069             : INLINE void
    1070    48455347 : pari_free(void *pointer)
    1071             : {
    1072    48455347 :   BLOCK_SIGINT_START;
    1073    48457636 :   free(pointer);
    1074    48457636 :   BLOCK_SIGINT_END;
    1075    48456970 : }
    1076             : INLINE void*
    1077   186165897 : pari_malloc(size_t size)
    1078             : {
    1079   186165897 :   if (size)
    1080             :   {
    1081             :     char *tmp;
    1082   186165897 :     BLOCK_SIGINT_START;
    1083   186168002 :     tmp = (char*)malloc(size);
    1084   186168002 :     BLOCK_SIGINT_END;
    1085   186168032 :     if (!tmp) pari_err(e_MEM);
    1086   186168032 :     return tmp;
    1087             :   }
    1088           0 :   if (DEBUGMEM) pari_warn(warner,"mallocing NULL object");
    1089           0 :   return NULL;
    1090             : }
    1091             : INLINE void*
    1092      773919 : pari_realloc(void *pointer, size_t size)
    1093             : {
    1094             :   char *tmp;
    1095             : 
    1096      773919 :   BLOCK_SIGINT_START;
    1097      776162 :   if (!pointer) tmp = (char *) malloc(size);
    1098       48266 :   else tmp = (char *) realloc(pointer,size);
    1099      776162 :   BLOCK_SIGINT_END;
    1100      774989 :   if (!tmp) pari_err(e_MEM);
    1101      774989 :   return tmp;
    1102             : }
    1103             : INLINE void*
    1104       29111 : pari_calloc(size_t size)
    1105             : {
    1106       29111 :   void *t = pari_malloc(size);
    1107       29111 :   memset(t, 0, size); return t;
    1108             : }
    1109             : INLINE GEN
    1110        4891 : cgetalloc(long t, size_t l)
    1111             : {
    1112        4891 :   GEN x = (GEN)pari_malloc(l * sizeof(long));
    1113        4891 :   x[0] = evaltyp(t) | evallg(l); return x;
    1114             : }
    1115             : 
    1116             : /*******************************************************************/
    1117             : /*                                                                 */
    1118             : /*                       GARBAGE COLLECTION                        */
    1119             : /*                                                                 */
    1120             : /*******************************************************************/
    1121             : /* copy integer x as if we had avma = av */
    1122             : INLINE GEN
    1123  3641502956 : icopy_avma(GEN x, pari_sp av)
    1124             : {
    1125  3641502956 :   long i = lgefint(x), lx = i;
    1126  3641502956 :   GEN y = ((GEN)av) - i;
    1127  3641502956 :   while (--i > 0) y[i] = x[i];
    1128  3641502956 :   y[0] = evaltyp(t_INT)|evallg(lx);
    1129  3641397118 :   return y;
    1130             : }
    1131             : /* copy leaf x as if we had avma = av */
    1132             : INLINE GEN
    1133    97558297 : leafcopy_avma(GEN x, pari_sp av)
    1134             : {
    1135    97558297 :   long i = lg(x);
    1136    97558297 :   GEN y = ((GEN)av) - i;
    1137    97558297 :   while (--i > 0) y[i] = x[i];
    1138    97558297 :   y[0] = x[0] & (~CLONEBIT);
    1139    97558297 :   return y;
    1140             : }
    1141             : INLINE GEN
    1142   524977056 : gerepileuptoleaf(pari_sp av, GEN x)
    1143             : {
    1144             :   long lx;
    1145             :   GEN q;
    1146             : 
    1147   524977056 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1148   525766624 :   lx = lg(x);
    1149   525766624 :   q = ((GEN)av) - lx;
    1150   525766624 :   avma = (pari_sp)q;
    1151   525766624 :   while (--lx >= 0) q[lx] = x[lx];
    1152   525766624 :   return q;
    1153             : }
    1154             : INLINE GEN
    1155  1080050453 : gerepileuptoint(pari_sp av, GEN x)
    1156             : {
    1157  1080050453 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1158   817792373 :   avma = (pari_sp)icopy_avma(x, av);
    1159   818070585 :   return (GEN)avma;
    1160             : }
    1161             : INLINE GEN
    1162   631509889 : gerepileupto(pari_sp av, GEN x)
    1163             : {
    1164   631509889 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1165   566519070 :   switch(typ(x))
    1166             :   { /* non-default = !is_recursive_t(tq) */
    1167   173550847 :     case t_INT: return gerepileuptoint(av, x);
    1168             :     case t_REAL:
    1169             :     case t_STR:
    1170   110140980 :     case t_VECSMALL: return gerepileuptoleaf(av,x);
    1171             :     default:
    1172             :       /* NB: x+i --> ((long)x) + i*sizeof(long) */
    1173   282827243 :       return gerepile(av, (pari_sp) (x+lg(x)), x);
    1174             :   }
    1175             : }
    1176             : 
    1177             : /* gerepileupto(av, gcopy(x)) */
    1178             : INLINE GEN
    1179    35678913 : gerepilecopy(pari_sp av, GEN x)
    1180             : {
    1181    35678913 :   if (is_recursive_t(typ(x)))
    1182             :   {
    1183    29440547 :     GENbin *p = copy_bin(x);
    1184    29440554 :     avma = av; return bin_copy(p);
    1185             :   }
    1186             :   else
    1187             :   {
    1188     6238517 :     avma = av;
    1189     6238517 :     if (x < (GEN)av) {
    1190     4909807 :       if (x < (GEN)pari_mainstack->bot) new_chunk(lg(x));
    1191     4909807 :       x = leafcopy_avma(x, av);
    1192     4920070 :       avma = (pari_sp)x;
    1193             :     } else
    1194     1328710 :       x = leafcopy(x);
    1195     6251690 :     return x;
    1196             :   }
    1197             : }
    1198             : 
    1199             : /* Takes an array of pointers to GENs, of length n. Copies all
    1200             :  * objects to contiguous locations and cleans up the stack between
    1201             :  * av and avma. */
    1202             : INLINE void
    1203       70756 : gerepilemany(pari_sp av, GEN* gptr[], int n)
    1204             : {
    1205             :   int i;
    1206       70756 :   for (i=0; i<n; i++) *gptr[i] = (GEN)copy_bin(*gptr[i]);
    1207       70756 :   avma = av;
    1208       70756 :   for (i=0; i<n; i++) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1209       70756 : }
    1210             : 
    1211             : INLINE void
    1212     4790264 : gerepileall(pari_sp av, int n, ...)
    1213             : {
    1214             :   int i;
    1215     4790264 :   va_list a; va_start(a, n);
    1216     4790264 :   if (n < 10)
    1217             :   {
    1218             :     GEN *gptr[10];
    1219    14698481 :     for (i=0; i<n; i++)
    1220     9908211 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1221     4790270 :     avma = av;
    1222     4790270 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1223             : 
    1224             :   }
    1225             :   else
    1226             :   {
    1227           0 :     GEN **gptr = (GEN**)  pari_malloc(n*sizeof(GEN*));
    1228           0 :     for (i=0; i<n; i++)
    1229           0 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1230           0 :     avma = av;
    1231           0 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1232           0 :     pari_free(gptr);
    1233             :   }
    1234     4790268 : }
    1235             : 
    1236             : INLINE void
    1237           8 : gerepilecoeffs(pari_sp av, GEN x, int n)
    1238             : {
    1239             :   int i;
    1240           8 :   for (i=0; i<n; i++) gel(x,i) = (GEN)copy_bin(gel(x,i));
    1241           8 :   avma = av;
    1242           8 :   for (i=0; i<n; i++) gel(x,i) = bin_copy((GENbin*)x[i]);
    1243           8 : }
    1244             : 
    1245             : /* p from copy_bin. Copy p->x back to stack, then destroy p */
    1246             : INLINE GEN
    1247    39530395 : bin_copy(GENbin *p)
    1248             : {
    1249             :   GEN x, y, base;
    1250             :   long dx, len;
    1251             : 
    1252    39530395 :   x   = p->x; if (!x) { pari_free(p); return gen_0; }
    1253    39528407 :   len = p->len;
    1254    39528407 :   base= p->base; dx = x - base;
    1255    39528407 :   y = (GEN)memcpy((void*)new_chunk(len), (void*)GENbinbase(p), len*sizeof(long));
    1256    39528415 :   y += dx;
    1257    39528415 :   p->rebase(y, ((ulong)y-(ulong)x));
    1258    39528411 :   pari_free(p); return y;
    1259             : }
    1260             : 
    1261             : INLINE GEN
    1262    79058809 : GENbinbase(GENbin *p) { return (GEN)(p + 1); }
    1263             : 
    1264             : INLINE void
    1265    26361476 : cgiv(GEN x)
    1266             : {
    1267    26361476 :   pari_sp av = (pari_sp)(x+lg(x));
    1268    26361476 :   if (isonstack((GEN)av)) avma = av;
    1269    26361476 : }
    1270             : 
    1271             : INLINE void
    1272     1369632 : killblock(GEN x) { gunclone(x); }
    1273             : 
    1274             : INLINE int
    1275    17930192 : is_universal_constant(GEN x) { return (x >= gen_0 && x <= ghalf); }
    1276             : 
    1277             : /*******************************************************************/
    1278             : /*                                                                 */
    1279             : /*                    CONVERSION / ASSIGNMENT                      */
    1280             : /*                                                                 */
    1281             : /*******************************************************************/
    1282             : /* z is a type which may be a t_COMPLEX component (not a t_QUAD) */
    1283             : INLINE GEN
    1284     2119454 : cxcompotor(GEN z, long prec)
    1285             : {
    1286     2119454 :   switch(typ(z))
    1287             :   {
    1288     1039602 :     case t_INT:  return itor(z, prec);
    1289      134120 :     case t_FRAC: return fractor(z, prec);
    1290      945732 :     case t_REAL: return rtor(z, prec);
    1291           0 :     default: pari_err_TYPE("cxcompotor",z); return NULL; /* not reached */
    1292             :   }
    1293             : }
    1294             : INLINE GEN
    1295     1058018 : cxtofp(GEN x, long prec)
    1296     1058018 : { retmkcomplex(cxcompotor(gel(x,1),prec), cxcompotor(gel(x,2),prec)); }
    1297             : 
    1298             : INLINE double
    1299    25821935 : gtodouble(GEN x)
    1300             : {
    1301    25821935 :   if (typ(x)!=t_REAL) {
    1302     4793888 :     pari_sp av = avma;
    1303     4793888 :     x = gtofp(x, DEFAULTPREC);
    1304     4793888 :     if (typ(x)!=t_REAL) pari_err_TYPE("gtodouble [t_REAL expected]", x);
    1305     4793888 :     avma = av;
    1306             :   }
    1307    25821935 :   return rtodbl(x);
    1308             : }
    1309             : INLINE long
    1310    64431448 : gtos(GEN x) {
    1311    64431448 :   if (typ(x) != t_INT) pari_err_TYPE("gtos [integer expected]",x);
    1312    64431441 :   return itos(x);
    1313             : }
    1314             : 
    1315             : INLINE ulong
    1316       83183 : gtou(GEN x) {
    1317       83183 :   if (typ(x) != t_INT || signe(x)<0)
    1318           0 :     pari_err_TYPE("gtou [integer >=0 expected]",x);
    1319       83396 :   return itou(x);
    1320             : }
    1321             : 
    1322             : INLINE GEN
    1323     1909706 : absfrac(GEN x)
    1324             : {
    1325     1909706 :   GEN y = cgetg(3, t_FRAC);
    1326     1909706 :   gel(y,1) = absi(gel(x,1));
    1327     1909706 :   gel(y,2) = icopy(gel(x,2)); return y;
    1328             : }
    1329             : INLINE GEN
    1330       11421 : absfrac_shallow(GEN x)
    1331       11421 : { return signe(gel(x,1))>0? x: mkfrac(negi(gel(x,1)), gel(x,2)); }
    1332             : INLINE GEN
    1333      608581 : Q_abs(GEN x) { return (typ(x) == t_INT)? absi(x): absfrac(x); }
    1334             : INLINE GEN
    1335       38303 : Q_abs_shallow(GEN x)
    1336       38303 : { return (typ(x) == t_INT)? absi_shallow(x): absfrac_shallow(x); }
    1337             : INLINE GEN
    1338         322 : R_abs_shallow(GEN x)
    1339         322 : { return (typ(x) == t_FRAC)? absfrac_shallow(x): mpabs_shallow(x); }
    1340             : INLINE GEN
    1341           0 : R_abs(GEN x)
    1342           0 : { return (typ(x) == t_FRAC)? absfrac(x): mpabs(x); }
    1343             : 
    1344             : /* Force z to be of type real/complex with floating point components */
    1345             : INLINE GEN
    1346    20089338 : gtofp(GEN z, long prec)
    1347             : {
    1348    20089338 :   switch(typ(z))
    1349             :   {
    1350     9969700 :     case t_INT:  return itor(z, prec);
    1351     4952773 :     case t_FRAC: return fractor(z, prec);
    1352     4280702 :     case t_REAL: return rtor(z, prec);
    1353             :     case t_COMPLEX: {
    1354      886163 :       GEN a = gel(z,1), b = gel(z,2);
    1355      886163 :       if (isintzero(b)) return cxcompotor(a, prec);
    1356      884441 :       if (isintzero(a)) {
    1357        1654 :         GEN y = cgetg(3, t_COMPLEX);
    1358        1654 :         b = cxcompotor(b, prec);
    1359        1654 :         gel(y,1) = real_0_bit(expo(b) - prec2nbits(prec));
    1360        1654 :         gel(y,2) = b; return y;
    1361             :       }
    1362      882787 :       return cxtofp(z, prec);
    1363             :     }
    1364           0 :     case t_QUAD: return quadtofp(z, prec);
    1365           0 :     default: pari_err_TYPE("gtofp",z); return NULL; /* not reached */
    1366             :   }
    1367             : }
    1368             : /* Force z to be of type real / int */
    1369             : INLINE GEN
    1370       22400 : gtomp(GEN z, long prec)
    1371             : {
    1372       22400 :   switch(typ(z))
    1373             :   {
    1374          14 :     case t_INT:  return z;
    1375       22386 :     case t_FRAC: return fractor(z, prec);
    1376           0 :     case t_REAL: return rtor(z, prec);
    1377           0 :     case t_QUAD: z = quadtofp(z, prec);
    1378           0 :                  if (typ(z) == t_REAL) return z;
    1379           0 :     default: pari_err_TYPE("gtomp",z); return NULL; /* not reached */
    1380             :   }
    1381             : }
    1382             : 
    1383             : INLINE GEN
    1384      485814 : RgX_gtofp(GEN x, long prec)
    1385             : {
    1386             :   long l;
    1387      485814 :   GEN y = cgetg_copy(x, &l);
    1388      485814 :   while (--l > 1) gel(y,l) = gtofp(gel(x,l), prec);
    1389      485814 :   y[1] = x[1]; return y;
    1390             : }
    1391             : INLINE GEN
    1392      393957 : RgC_gtofp(GEN x, long prec)
    1393             : {
    1394      393957 :   long l = lg(x);
    1395      393957 :   GEN y = cgetg(l, t_COL);
    1396      393957 :   while (--l > 0) gel(y,l) = gtofp(gel(x,l), prec);
    1397      393957 :   return y;
    1398             : }
    1399             : INLINE GEN
    1400       18943 : RgM_gtofp(GEN x, long prec)
    1401             : {
    1402             :   long l;
    1403       18943 :   GEN y = cgetg_copy(x, &l);
    1404       18943 :   while (--l > 0) gel(y,l) = RgC_gtofp(gel(x,l), prec);
    1405       18943 :   return y;
    1406             : }
    1407             : INLINE GEN
    1408         560 : RgC_gtomp(GEN x, long prec)
    1409             : {
    1410         560 :   long l = lg(x);
    1411         560 :   GEN y = cgetg(l, t_COL);
    1412         560 :   while (--l > 0) gel(y,l) = gtomp(gel(x,l), prec);
    1413         560 :   return y;
    1414             : }
    1415             : INLINE GEN
    1416          14 : RgM_gtomp(GEN x, long prec)
    1417             : {
    1418             :   long l;
    1419          14 :   GEN y = cgetg_copy(x, &l);
    1420          14 :   while (--l > 0) gel(y,l) = RgC_gtomp(gel(x,l), prec);
    1421          14 :   return y;
    1422             : }
    1423             : 
    1424             : INLINE GEN
    1425        6385 : RgX_fpnorml2(GEN x, long prec)
    1426             : {
    1427        6385 :   pari_sp av = avma;
    1428        6385 :   return gerepileupto(av, gnorml2(RgX_gtofp(x, prec)));
    1429             : }
    1430             : INLINE GEN
    1431      259953 : RgC_fpnorml2(GEN x, long prec)
    1432             : {
    1433      259953 :   pari_sp av = avma;
    1434      259953 :   return gerepileupto(av, gnorml2(RgC_gtofp(x, prec)));
    1435             : }
    1436             : INLINE GEN
    1437        1738 : RgM_fpnorml2(GEN x, long prec)
    1438             : {
    1439        1738 :   pari_sp av = avma;
    1440        1738 :   return gerepileupto(av, gnorml2(RgM_gtofp(x, prec)));
    1441             : }
    1442             : 
    1443             : /* y a t_REAL */
    1444             : INLINE void
    1445      180734 : affgr(GEN x, GEN y)
    1446             : {
    1447             :   pari_sp av;
    1448      180734 :   switch(typ(x)) {
    1449         512 :     case t_INT:  affir(x,y); break;
    1450      180222 :     case t_REAL: affrr(x,y); break;
    1451           0 :     case t_FRAC: rdiviiz(gel(x,1),gel(x,2), y); break;
    1452           0 :     case t_QUAD: av = avma; affgr(quadtofp(x,realprec(y)), y); avma = av; break;
    1453           0 :     default: pari_err_TYPE2("=",x,y);
    1454             :   }
    1455      180734 : }
    1456             : 
    1457             : INLINE GEN
    1458      183809 : affc_fixlg(GEN x, GEN res)
    1459             : {
    1460      183809 :   if (typ(x) == t_COMPLEX)
    1461             :   {
    1462      175308 :     affrr_fixlg(gel(x,1), gel(res,1));
    1463      175308 :     affrr_fixlg(gel(x,2), gel(res,2));
    1464             :   }
    1465             :   else
    1466             :   {
    1467        8501 :     avma = (pari_sp)(res+3);
    1468        8501 :     res = cgetr(realprec(gel(res,1)));
    1469        8501 :     affrr_fixlg(x, res);
    1470             :   }
    1471      183809 :   return res;
    1472             : }
    1473             : 
    1474             : INLINE GEN
    1475           0 : trunc_safe(GEN x) { long e; return gcvtoi(x,&e); }
    1476             : 
    1477             : /*******************************************************************/
    1478             : /*                                                                 */
    1479             : /*                          LENGTH CONVERSIONS                     */
    1480             : /*                                                                 */
    1481             : /*******************************************************************/
    1482             : INLINE long
    1483       22414 : ndec2nlong(long x) { return 1 + (long)((x)*(LOG2_10/BITS_IN_LONG)); }
    1484             : INLINE long
    1485       21971 : ndec2prec(long x) { return 2 + ndec2nlong(x); }
    1486             : INLINE long
    1487         443 : ndec2nbits(long x) { return ndec2nlong(x) << TWOPOTBITS_IN_LONG; }
    1488             : /* Fast implementation of ceil(x / (8*sizeof(long))); typecast to (ulong)
    1489             :  * to avoid overflow. Faster than 1 + ((x-1)>>TWOPOTBITS_IN_LONG)) :
    1490             :  *   addl, shrl instead of subl, sarl, addl */
    1491             : INLINE long
    1492     1022441 : nbits2nlong(long x) {
    1493     1022441 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1494             : }
    1495             : 
    1496             : INLINE long
    1497   249884069 : nbits2extraprec(long x) {
    1498   249884069 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1499             : }
    1500             : 
    1501             : /* Fast implementation of 2 + nbits2nlong(x) */
    1502             : INLINE long
    1503    79323879 : nbits2prec(long x) {
    1504    79323879 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1505             : }
    1506             : INLINE long
    1507     4537216 : nbits2lg(long x) {
    1508     4537216 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1509             : }
    1510             : /* ceil(x / sizeof(long)) */
    1511             : INLINE long
    1512     7042247 : nchar2nlong(long x) {
    1513     7042247 :   return (long)(((ulong)x+sizeof(long)-1) >> (TWOPOTBITS_IN_LONG-3L));
    1514             : }
    1515             : INLINE long
    1516  1141747783 : prec2nbits(long x) { return (x-2) * BITS_IN_LONG; }
    1517             : INLINE double
    1518      451310 : bit_accuracy_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1519             : INLINE double
    1520      224402 : prec2nbits_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1521             : INLINE long
    1522    24089712 : bit_prec(GEN x) { return prec2nbits(realprec(x)); }
    1523             : INLINE long
    1524  1059789770 : bit_accuracy(long x) { return prec2nbits(x); }
    1525             : INLINE long
    1526       12001 : prec2ndec(long x) { return (long)prec2nbits_mul(x, LOG10_2); }
    1527             : INLINE long
    1528         165 : nbits2ndec(long x) { return (long)(x * LOG10_2); }
    1529             : INLINE long
    1530        1707 : precdbl(long x) {return (x - 1) << 1;}
    1531             : INLINE long
    1532  2966968769 : divsBIL(long n) { return n >> TWOPOTBITS_IN_LONG; }
    1533             : INLINE long
    1534  2900142321 : remsBIL(long n) { return n & (BITS_IN_LONG-1); }
    1535             : 
    1536             : /*********************************************************************/
    1537             : /**                                                                 **/
    1538             : /**                      OPERATIONS MODULO m                        **/
    1539             : /**                                                                 **/
    1540             : /*********************************************************************/
    1541             : /* Assume m > 0, more efficient if 0 <= a, b < m */
    1542             : 
    1543             : INLINE GEN
    1544     1152360 : Fp_red(GEN a, GEN m) { return modii(a, m); }
    1545             : INLINE GEN
    1546   359511730 : Fp_add(GEN a, GEN b, GEN m)
    1547             : {
    1548   359511730 :   pari_sp av=avma;
    1549   359511730 :   GEN p = addii(a,b);
    1550   359491243 :   long s = signe(p);
    1551   359491243 :   if (!s) return p; /* = gen_0 */
    1552   172312546 :   if (s > 0) /* general case */
    1553             :   {
    1554   172094601 :     GEN t = subii(p, m);
    1555   172107904 :     s = signe(t);
    1556   172107904 :     if (!s) { avma = av; return gen_0; }
    1557   159398785 :     if (s < 0) { avma = (pari_sp)p; return p; }
    1558    27155314 :     if (cmpii(t, m) < 0) return gerepileuptoint(av, t); /* general case ! */
    1559     1081102 :     p = remii(t, m);
    1560             :   }
    1561             :   else
    1562      217945 :     p = modii(p, m);
    1563     1299047 :   return gerepileuptoint(av, p);
    1564             : }
    1565             : INLINE GEN
    1566    45399481 : Fp_sub(GEN a, GEN b, GEN m)
    1567             : {
    1568    45399481 :   pari_sp av=avma;
    1569    45399481 :   GEN p = subii(a,b);
    1570    45488607 :   long s = signe(p);
    1571    45488607 :   if (!s) return p; /* = gen_0 */
    1572    38517890 :   if (s > 0)
    1573             :   {
    1574    18786906 :     if (cmpii(p, m) < 0) return p; /* general case ! */
    1575      742259 :     p = remii(p, m);
    1576             :   }
    1577             :   else
    1578             :   {
    1579    19730984 :     GEN t = addii(p, m);
    1580    19718503 :     if (!s) { avma = av; return gen_0; }
    1581    19718503 :     if (s > 0) return gerepileuptoint(av, t); /* general case ! */
    1582    19718503 :     p = modii(t, m);
    1583             :   }
    1584    20456735 :   return gerepileuptoint(av, p);
    1585             : }
    1586             : INLINE GEN
    1587     9921281 : Fp_neg(GEN b, GEN m)
    1588             : {
    1589     9921281 :   pari_sp av = avma;
    1590     9921281 :   long s = signe(b);
    1591             :   GEN p;
    1592     9921281 :   if (!s) return gen_0;
    1593     7105920 :   if (s > 0)
    1594             :   {
    1595     7104961 :     p = subii(m, b);
    1596     7104789 :     if (signe(p) >= 0) return p; /* general case ! */
    1597       36753 :     p = modii(p, m);
    1598             :   } else
    1599         959 :     p = remii(negi(b), m);
    1600       37712 :   return gerepileuptoint(av, p);
    1601             : }
    1602             : 
    1603             : INLINE GEN
    1604       19788 : Fp_halve(GEN a, GEN p)
    1605             : {
    1606       19788 :   if (mpodd(a)) a = addii(a,p);
    1607       19788 :   return shifti(a,-1);
    1608             : }
    1609             : 
    1610             : /* assume 0 <= u < p and ps2 = p>>1 */
    1611             : INLINE GEN
    1612     5700379 : Fp_center(GEN u, GEN p, GEN ps2)
    1613     5700379 : { return abscmpii(u,ps2)<=0? icopy(u): subii(u,p); }
    1614             : 
    1615             : /* x + y*z mod p */
    1616             : INLINE GEN
    1617     1425935 : Fp_addmul(GEN x, GEN y, GEN z, GEN p)
    1618             : {
    1619             :   pari_sp av;
    1620     1425935 :   if (!signe(y) || !signe(z)) return Fp_red(x, p);
    1621     1425662 :   if (!signe(x)) return Fp_mul(z,y, p);
    1622     1138494 :   av = avma;
    1623     1138494 :   return gerepileuptoint(av, modii(addii(x, mulii(y,z)), p));
    1624             : }
    1625             : 
    1626             : INLINE GEN
    1627   342568848 : Fp_mul(GEN a, GEN b, GEN m)
    1628             : {
    1629   342568848 :   pari_sp av=avma;
    1630             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1631   342568848 :   (void)new_chunk(lg(a)+lg(b)+(lg(m)<<1));
    1632   342572431 :   p = mulii(a,b);
    1633   342574508 :   avma = av; return modii(p,m);
    1634             : }
    1635             : INLINE GEN
    1636     6933861 : Fp_sqr(GEN a, GEN m)
    1637             : {
    1638     6933861 :   pari_sp av=avma;
    1639             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1640     6933861 :   (void)new_chunk((lg(a)+lg(m))<<1);
    1641     6964910 :   p = sqri(a);
    1642     7004964 :   avma = av; return modii(p,m);
    1643             : }
    1644             : INLINE GEN
    1645    52830681 : Fp_mulu(GEN a, ulong b, GEN m)
    1646             : {
    1647    52830681 :   long l = lgefint(m);
    1648    52830681 :   if (l == 3)
    1649             :   {
    1650    35708636 :     ulong mm = m[2];
    1651    35708636 :     return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1652             :   } else {
    1653    17122045 :     pari_sp av = avma;
    1654             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1655    17122045 :     (void)new_chunk(lg(a)+1+(l<<1));
    1656    17143667 :     p = muliu(a,b);
    1657    16892564 :     avma = av; return modii(p,m);
    1658             :   }
    1659             : }
    1660             : INLINE GEN
    1661           0 : Fp_muls(GEN a, long b, GEN m)
    1662             : {
    1663           0 :   long l = lgefint(m);
    1664           0 :   if (l == 3)
    1665             :   {
    1666           0 :     ulong mm = m[2];
    1667           0 :     if (b < 0)
    1668             :     {
    1669           0 :       ulong t = Fl_mul(umodiu(a, mm), -b, mm);
    1670           0 :       return t? utoipos(mm - t): gen_0;
    1671             :     }
    1672             :     else
    1673           0 :       return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1674             :   } else {
    1675           0 :     pari_sp av = avma;
    1676             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1677           0 :     (void)new_chunk(lg(a)+1+(l<<1));
    1678           0 :     p = mulis(a,b);
    1679           0 :     avma = av; return modii(p,m);
    1680             :   }
    1681             : }
    1682             : 
    1683             : INLINE GEN
    1684     7962057 : Fp_inv(GEN a, GEN m)
    1685             : {
    1686             :   GEN res;
    1687     7962057 :   if (! invmod(a,m,&res)) pari_err_INV("Fp_inv", mkintmod(res,m));
    1688     7949951 :   return res;
    1689             : }
    1690             : INLINE GEN
    1691      286518 : Fp_invsafe(GEN a, GEN m)
    1692             : {
    1693             :   GEN res;
    1694      286518 :   if (! invmod(a,m,&res)) return NULL;
    1695      286518 :   return res;
    1696             : }
    1697             : INLINE GEN
    1698     4585831 : Fp_div(GEN a, GEN b, GEN m)
    1699             : {
    1700     4585831 :   pari_sp av=avma;
    1701             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1702     4585831 :   (void)new_chunk(lg(a)+(lg(m)<<1));
    1703     4595263 :   p = mulii(a, Fp_inv(b,m));
    1704     4603465 :   avma = av; return modii(p,m);
    1705             : }
    1706             : 
    1707             : INLINE GEN
    1708      665843 : Flx_mulu(GEN x, ulong a, ulong p) { return Flx_Fl_mul(x,a%p,p); }
    1709             : 
    1710             : /*******************************************************************/
    1711             : /*                                                                 */
    1712             : /*                        ADDMULII / SUBMULII                      */
    1713             : /*                                                                 */
    1714             : /*******************************************************************/
    1715             : /* x - y*z */
    1716             : INLINE GEN
    1717    19037056 : submulii(GEN x, GEN y, GEN z)
    1718             : {
    1719    19037056 :   long lx = lgefint(x), ly, lz;
    1720             :   pari_sp av;
    1721             :   GEN t;
    1722    19037056 :   if (lx == 2) { t = mulii(z,y); togglesign(t); return t; }
    1723    16405910 :   ly = lgefint(y);
    1724    16405910 :   if (ly == 2) return icopy(x);
    1725    15149421 :   lz = lgefint(z);
    1726    15149421 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1727    15149421 :   t = mulii(z, y);
    1728    15149421 :   avma = av; return subii(x,t);
    1729             : }
    1730             : /* y*z - x */
    1731             : INLINE GEN
    1732     2288556 : mulsubii(GEN y, GEN z, GEN x)
    1733             : {
    1734     2288556 :   long lx = lgefint(x), ly, lz;
    1735             :   pari_sp av;
    1736             :   GEN t;
    1737     2288556 :   if (lx == 2) return mulii(z,y);
    1738     1412044 :   ly = lgefint(y);
    1739     1412044 :   if (ly == 2) return negi(x);
    1740     1354547 :   lz = lgefint(z);
    1741     1354547 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1742     1354547 :   t = mulii(z, y);
    1743     1354547 :   avma = av; return subii(t,x);
    1744             : }
    1745             : 
    1746             : /* x - u*y */
    1747             : INLINE GEN
    1748        7000 : submuliu(GEN x, GEN y, ulong u)
    1749             : {
    1750             :   pari_sp av;
    1751        7000 :   long ly = lgefint(y);
    1752        7000 :   if (ly == 2) return icopy(x);
    1753        7000 :   av = avma;
    1754        7000 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1755        7000 :   y = mului(u,y);
    1756        7000 :   avma = av; return subii(x, y);
    1757             : }
    1758             : /* x + u*y */
    1759             : INLINE GEN
    1760        7000 : addmuliu(GEN x, GEN y, ulong u)
    1761             : {
    1762             :   pari_sp av;
    1763        7000 :   long ly = lgefint(y);
    1764        7000 :   if (ly == 2) return icopy(x);
    1765        7000 :   av = avma;
    1766        7000 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1767        7000 :   y = mului(u,y);
    1768        7000 :   avma = av; return addii(x, y);
    1769             : }
    1770             : /* x - u*y */
    1771             : INLINE GEN
    1772   116507589 : submuliu_inplace(GEN x, GEN y, ulong u)
    1773             : {
    1774             :   pari_sp av;
    1775   116507589 :   long ly = lgefint(y);
    1776   116507589 :   if (ly == 2) return x;
    1777    93071578 :   av = avma;
    1778    93071578 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1779    93071578 :   y = mului(u,y);
    1780    93071578 :   avma = av; return subii(x, y);
    1781             : }
    1782             : /* x + u*y */
    1783             : INLINE GEN
    1784   115202542 : addmuliu_inplace(GEN x, GEN y, ulong u)
    1785             : {
    1786             :   pari_sp av;
    1787   115202542 :   long ly = lgefint(y);
    1788   115202542 :   if (ly == 2) return x;
    1789    92728056 :   av = avma;
    1790    92728056 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1791    92728056 :   y = mului(u,y);
    1792    92728056 :   avma = av; return addii(x, y);
    1793             : }
    1794             : /* ux + vy */
    1795             : INLINE GEN
    1796    27027968 : lincombii(GEN u, GEN v, GEN x, GEN y)
    1797             : {
    1798    27027968 :   long lx = lgefint(x), ly;
    1799             :   GEN p1, p2;
    1800             :   pari_sp av;
    1801    27027968 :   if (lx == 2) return mulii(v,y);
    1802    16487175 :   ly = lgefint(y);
    1803    16487175 :   if (ly == 2) return mulii(u,x);
    1804    15048250 :   av = avma; (void)new_chunk(lx+ly+lgefint(u)+lgefint(v)); /* HACK */
    1805    15048250 :   p1 = mulii(u,x);
    1806    15048250 :   p2 = mulii(v,y);
    1807    15048250 :   avma = av; return addii(p1,p2);
    1808             : }
    1809             : 
    1810             : /*******************************************************************/
    1811             : /*                                                                 */
    1812             : /*                          GEN SUBTYPES                           */
    1813             : /*                                                                 */
    1814             : /*******************************************************************/
    1815             : 
    1816             : INLINE int
    1817   989086786 : is_const_t(long t) { return (t < t_POLMOD); }
    1818             : INLINE int
    1819      371961 : is_extscalar_t(long t) { return (t <= t_POL); }
    1820             : INLINE int
    1821      860526 : is_intreal_t(long t) { return (t <= t_REAL); }
    1822             : INLINE int
    1823   349029685 : is_matvec_t(long t) { return (t >= t_VEC && t <= t_MAT); }
    1824             : INLINE int
    1825    50912094 : is_noncalc_t(long tx) { return (tx) >= t_LIST; }
    1826             : INLINE int
    1827      582205 : is_rational_t(long t) { return (t == t_INT || t == t_FRAC); }
    1828             : INLINE int
    1829       53487 : is_real_t(long t) { return (t == t_INT || t == t_REAL || t == t_FRAC); }
    1830             : INLINE int
    1831  2524743311 : is_recursive_t(long t) { return lontyp[t]; }
    1832             : INLINE int
    1833   152428003 : is_scalar_t(long t) { return (t < t_POL); }
    1834             : INLINE int
    1835      403013 : is_vec_t(long t) { return (t == t_VEC || t == t_COL); }
    1836             : 
    1837             : /*******************************************************************/
    1838             : /*                                                                 */
    1839             : /*                         TRANSCENDENTAL                          */
    1840             : /*                                                                 */
    1841             : /*******************************************************************/
    1842             : INLINE GEN
    1843    15155772 : sqrtr(GEN x) {
    1844    15155772 :   long s = signe(x);
    1845    15155772 :   if (s == 0) return real_0_bit(expo(x) >> 1);
    1846    15122283 :   if (s >= 0) return sqrtr_abs(x);
    1847       13485 :   retmkcomplex(gen_0, sqrtr_abs(x));
    1848             : }
    1849             : INLINE GEN
    1850       12038 : cbrtr(GEN x) {
    1851       12038 :   long s = signe(x);
    1852             :   GEN r;
    1853       12038 :   if (s == 0) return real_0_bit(expo(x) / 3);
    1854       12038 :   r = cbrtr_abs(x);
    1855       12038 :   if (s < 0) togglesign(r);
    1856       12038 :   return r;
    1857             : }
    1858             : /* x^(1/n) */
    1859             : INLINE GEN
    1860       34855 : sqrtnr(GEN x, long n) {
    1861       34855 :   switch(n)
    1862             :   {
    1863         595 :     case 1: return rcopy(x);
    1864        5359 :     case 2: return sqrtr(x);
    1865       12038 :     case 3: return cbrtr(x);
    1866             :   }
    1867       16863 :   return mpexp(divrs(mplog(x), n));
    1868             : }
    1869             : INLINE long
    1870      397495 : logint(GEN B, GEN y) { return logintall(B,y,NULL); }
    1871             : 
    1872             : /*******************************************************************/
    1873             : /*                                                                 */
    1874             : /*                         MISCELLANEOUS                           */
    1875             : /*                                                                 */
    1876             : /*******************************************************************/
    1877      860449 : INLINE int ismpzero(GEN x) { return is_intreal_t(typ(x)) && !signe(x); }
    1878   363024432 : INLINE int isintzero(GEN x) { return typ(x) == t_INT && !signe(x); }
    1879     6295686 : INLINE int isint1(GEN x) { return typ(x)==t_INT && equali1(x); }
    1880         301 : INLINE int isintm1(GEN x){ return typ(x)==t_INT && equalim1(x);}
    1881   214615400 : INLINE int equali1(GEN n)
    1882   214615400 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(1)) && n[2] == 1; }
    1883    23575360 : INLINE int equalim1(GEN n)
    1884    23575360 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(-1)) && n[2] == 1; }
    1885             : /* works only for POSITIVE integers */
    1886  1527803975 : INLINE int is_pm1(GEN n)
    1887  1527803975 : { return lgefint(n) == 3 && n[2] == 1; }
    1888   132729385 : INLINE int is_bigint(GEN n)
    1889   132729385 : { long l = lgefint(n); return l > 3 || (l == 3 && (n[2] & HIGHBIT)); }
    1890             : 
    1891  1299864443 : INLINE int odd(long x) { return x & 1; }
    1892     8124981 : INLINE int both_odd(long x, long y) { return x & y & 1; }
    1893             : 
    1894             : INLINE int
    1895  2262956298 : isonstack(GEN x)
    1896  4525912596 : { return ((pari_sp)x >= pari_mainstack->bot
    1897  2262956298 :        && (pari_sp)x <  pari_mainstack->top); }
    1898             : 
    1899             : /* assume x != 0 and x t_REAL, return an approximation to log2(|x|) */
    1900             : INLINE double
    1901    16986355 : dbllog2r(GEN x)
    1902    16986355 : { return log2((double)(ulong)x[2]) + (double)(expo(x) - (BITS_IN_LONG-1)); }
    1903             : 
    1904             : INLINE GEN
    1905      234380 : mul_content(GEN cx, GEN cy)
    1906             : {
    1907      234380 :   if (!cx) return cy;
    1908       59342 :   if (!cy) return cx;
    1909       37416 :   return gmul(cx,cy);
    1910             : }
    1911             : INLINE GEN
    1912      438140 : mul_denom(GEN dx, GEN dy)
    1913             : {
    1914      438140 :   if (!dx) return dy;
    1915      311614 :   if (!dy) return dx;
    1916      122641 :   return mulii(dx,dy);
    1917             : }
    1918             : 
    1919             : /* POLYNOMIALS */
    1920             : INLINE GEN
    1921    17559234 : constant_coeff(GEN x) { return signe(x)? gel(x,2): gen_0; }
    1922             : INLINE GEN
    1923    76039343 : leading_coeff(GEN x) { return lg(x) == 2? gen_0: gel(x,lg(x)-1); }
    1924             : INLINE ulong
    1925      415556 : Flx_lead(GEN x) { return lg(x) == 2? 0: x[lg(x)-1]; }
    1926             : INLINE long
    1927  2534950421 : degpol(GEN x) { return lg(x)-3; }
    1928             : INLINE long
    1929  1256810473 : lgpol(GEN x) { return lg(x)-2; }
    1930             : INLINE long
    1931    61347018 : lgcols(GEN x) { return lg(gel(x,1)); }
    1932             : INLINE long
    1933    16534796 : nbrows(GEN x) { return lg(gel(x,1))-1; }
    1934             : INLINE GEN
    1935           0 : truecoeff(GEN x, long n) { return polcoeff0(x,n,-1); }
    1936             : 
    1937             : INLINE GEN
    1938      431370 : RgXQ_mul(GEN y, GEN x, GEN T) { return RgX_rem(RgX_mul(y, x), T); }
    1939             : INLINE GEN
    1940      211230 : RgXQ_sqr(GEN x, GEN T) { return RgX_rem(RgX_sqr(x), T); }
    1941             : 
    1942             : INLINE GEN
    1943      116585 : ZXQ_mul(GEN y, GEN x, GEN T) { return ZX_rem(ZX_mul(y, x), T); }
    1944             : INLINE GEN
    1945       20517 : ZXQ_sqr(GEN x, GEN T) { return ZX_rem(ZX_sqr(x), T); }
    1946             : 
    1947             : INLINE GEN
    1948    61902666 : RgX_copy(GEN x)
    1949             : {
    1950             :   long lx, i;
    1951    61902666 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
    1952    61902666 :   for (i = 2; i<lx; i++) gel(y,i) = gcopy(gel(x,i));
    1953    61902666 :   return y;
    1954             : }
    1955             : /* have to use ulong to avoid silly warnings from gcc "assuming signed
    1956             :  * overflow does not occur" */
    1957             : INLINE GEN
    1958     2219869 : RgX_coeff(GEN x, long n)
    1959             : {
    1960     2219869 :   ulong l = lg(x);
    1961     2219869 :   return (n < 0 || ((ulong)n+3) > l)? gen_0: gel(x,n+2);
    1962             : }
    1963             : INLINE GEN
    1964      310625 : RgX_renormalize(GEN x) { return RgX_renormalize_lg(x, lg(x)); }
    1965             : INLINE GEN
    1966     6097976 : RgX_div(GEN x, GEN y) { return RgX_divrem(x,y,NULL); }
    1967             : INLINE GEN
    1968     2464449 : RgX_rem(GEN x, GEN y) { return RgX_divrem(x,y,ONLY_REM); }
    1969             : INLINE GEN
    1970           7 : RgXQX_div(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,NULL); }
    1971             : INLINE GEN
    1972       17248 : RgXQX_rem(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,ONLY_REM); }
    1973             : INLINE GEN
    1974      753568 : FpX_div(GEN x, GEN y, GEN p) { return FpX_divrem(x,y,p, NULL); }
    1975             : INLINE GEN
    1976     3094066 : Flx_div(GEN x, GEN y, ulong p) { return Flx_divrem(x,y,p, NULL); }
    1977             : INLINE GEN
    1978     1193637 : F2x_div(GEN x, GEN y) { return F2x_divrem(x,y, NULL); }
    1979             : INLINE GEN
    1980           0 : FpV_FpC_mul(GEN x, GEN y, GEN p) { return FpV_dotproduct(x,y,p); }
    1981             : INLINE GEN
    1982    44018991 : pol0_Flx(long sv) { return mkvecsmall(sv); }
    1983             : INLINE GEN
    1984    17599748 : pol1_Flx(long sv) { return mkvecsmall2(sv, 1); }
    1985             : INLINE GEN
    1986    17148592 : polx_Flx(long sv) { return mkvecsmall3(sv, 0, 1); }
    1987             : INLINE GEN
    1988           0 : zero_zx(long sv) { return zero_Flx(sv); }
    1989             : INLINE GEN
    1990           0 : polx_zx(long sv) { return polx_Flx(sv); }
    1991             : INLINE GEN
    1992           0 : zx_shift(GEN x, long n) { return Flx_shift(x,n); }
    1993             : INLINE GEN
    1994           0 : zx_renormalize(GEN x, long l) { return Flx_renormalize(x,l); }
    1995             : INLINE GEN
    1996          56 : zero_F2x(long sv) { return zero_Flx(sv); }
    1997             : INLINE GEN
    1998     9377882 : pol0_F2x(long sv) { return pol0_Flx(sv); }
    1999             : INLINE GEN
    2000     2628120 : pol1_F2x(long sv) { return pol1_Flx(sv); }
    2001             : INLINE GEN
    2002      464535 : polx_F2x(long sv) { return mkvecsmall2(sv, 2); }
    2003             : INLINE int
    2004      782481 : F2x_equal1(GEN x) { return Flx_equal1(x); }
    2005             : INLINE int
    2006     1703198 : F2x_equal(GEN V, GEN W) { return Flx_equal(V,W); }
    2007             : INLINE GEN
    2008    46615376 : F2x_copy(GEN x) { return leafcopy(x); }
    2009             : INLINE GEN
    2010           0 : F2v_copy(GEN x) { return leafcopy(x); }
    2011             : INLINE GEN
    2012     2609922 : Flv_copy(GEN x) { return leafcopy(x); }
    2013             : INLINE GEN
    2014    77296405 : Flx_copy(GEN x) { return leafcopy(x); }
    2015             : INLINE GEN
    2016     2230468 : vecsmall_copy(GEN x) { return leafcopy(x); }
    2017             : INLINE int
    2018     4669466 : Flx_equal1(GEN x) { return degpol(x)==0 && x[2] == 1; }
    2019             : INLINE int
    2020       17992 : ZX_equal1(GEN x) { return degpol(x)==0 && equali1(gel(x,2)); }
    2021             : 
    2022             : INLINE GEN
    2023    76157936 : ZX_renormalize(GEN x, long lx)    { return ZXX_renormalize(x,lx); }
    2024             : INLINE GEN
    2025    91270966 : FpX_renormalize(GEN x, long lx)   { return ZXX_renormalize(x,lx); }
    2026             : INLINE GEN
    2027      948782 : FpXX_renormalize(GEN x, long lx)  { return ZXX_renormalize(x,lx); }
    2028             : INLINE GEN
    2029     1058308 : FpXQX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
    2030             : INLINE GEN
    2031   103722334 : F2x_renormalize(GEN x, long lx)   { return Flx_renormalize(x,lx); }
    2032             : INLINE GEN
    2033        6762 : F2v_to_F2x(GEN x, long sv) {
    2034        6762 :   GEN y = leafcopy(x);
    2035        6762 :   y[1] = sv; F2x_renormalize(y, lg(y)); return y;
    2036             : }
    2037             : 
    2038             : INLINE GEN
    2039           0 : ZX_ZXY_resultant(GEN a, GEN b) { return ZX_ZXY_rnfequation(a,b,NULL); }
    2040             : INLINE long
    2041         441 : sturm(GEN x) { return sturmpart(x, NULL, NULL); }
    2042             : INLINE GEN
    2043       36041 : resultant(GEN x, GEN y) { return resultant_all(x,y,NULL); }
    2044             : 
    2045             : INLINE long
    2046        2037 : gval(GEN x, long v) {
    2047        2037 :   pari_sp av = avma;
    2048        2037 :   long n = gvaluation(x, pol_x(v));
    2049        2037 :   avma = av; return n;
    2050             : }
    2051             : 
    2052             : INLINE void
    2053      582960 : RgX_shift_inplace_init(long v)
    2054      582960 : { if (v) (void)cgetg(v, t_VECSMALL); }
    2055             : /* shift polynomial in place. assume v free cells have been left before x */
    2056             : INLINE GEN
    2057      582959 : RgX_shift_inplace(GEN x, long v)
    2058             : {
    2059             :   long i, lx;
    2060             :   GEN y, z;
    2061      582959 :   if (!v) return x;
    2062      257815 :   lx = lg(x);
    2063      257815 :   if (lx == 2) return x;
    2064      257815 :   y = x + v;
    2065      257815 :   z = x + lx;
    2066             :   /* stackdummy from normalizepol: move it up */
    2067      257815 :   if (lg(z) != v) x[lx + v] = z[0];
    2068      257815 :   for (i = lx-1; i >= 2; i--) gel(y,i) = gel(x,i);
    2069      257815 :   for (i = v+1;  i >= 2; i--) gel(x,i) = gen_0;
    2070             :   /* leave x[1] alone: it is correct */
    2071      257815 :   x[0] = evaltyp(t_POL) | evallg(lx+v); return x;
    2072             : }
    2073             : 
    2074             : 
    2075             : /* LINEAR ALGEBRA */
    2076             : INLINE GEN
    2077        8666 : zv_to_ZV(GEN x) { return vecsmall_to_vec(x); }
    2078             : INLINE GEN
    2079     1095845 : zc_to_ZC(GEN x) { return vecsmall_to_col(x); }
    2080             : INLINE GEN
    2081      224789 : ZV_to_zv(GEN x) { return vec_to_vecsmall(x); }
    2082             : INLINE GEN
    2083           0 : zx_to_zv(GEN x, long N) { return Flx_to_Flv(x,N); }
    2084             : INLINE GEN
    2085           0 : zv_to_zx(GEN x, long sv) { return Flv_to_Flx(x,sv); }
    2086             : INLINE GEN
    2087           0 : zm_to_zxV(GEN x, long sv) { return Flm_to_FlxV(x,sv); }
    2088             : INLINE GEN
    2089           0 : zero_zm(long x, long y) { return zero_Flm(x,y); }
    2090             : INLINE GEN
    2091    15895731 : zero_zv(long x) { return zero_Flv(x); }
    2092             : INLINE GEN
    2093         168 : zm_transpose(GEN x) { return Flm_transpose(x); }
    2094             : INLINE GEN
    2095           0 : zm_copy(GEN x) { return Flm_copy(x); }
    2096             : INLINE GEN
    2097     2147257 : zv_copy(GEN x) { return Flv_copy(x); }
    2098             : INLINE GEN
    2099           0 : zm_row(GEN x, long i) { return Flm_row(x,i); }
    2100             : 
    2101             : INLINE GEN
    2102      828638 : ZC_hnfrem(GEN x, GEN y) { return ZC_hnfremdiv(x,y,NULL); }
    2103             : INLINE GEN
    2104       58630 : ZM_hnfrem(GEN x, GEN y) { return ZM_hnfdivrem(x,y,NULL); }
    2105             : INLINE GEN
    2106     1374437 : ZM_lll(GEN x, double D, long f) { return ZM_lll_norms(x,D,f,NULL); }
    2107             : INLINE void
    2108      119214 : RgM_dimensions(GEN x, long *m, long *n) { *n = lg(x)-1; *m = *n? nbrows(x): 0; }
    2109             : INLINE GEN
    2110       31982 : RgM_inv(GEN a) { return RgM_solve(a, NULL); }
    2111             : INLINE GEN
    2112     6535456 : RgM_shallowcopy(GEN x)
    2113             : {
    2114             :   long l;
    2115     6535456 :   GEN y = cgetg_copy(x, &l);
    2116     6535456 :   while (--l > 0) gel(y,l) = leafcopy(gel(x,l));
    2117     6535456 :   return y;
    2118             : }
    2119             : INLINE GEN
    2120        1631 : F2m_copy(GEN x) { return RgM_shallowcopy(x); }
    2121             : 
    2122             : INLINE GEN
    2123      339261 : Flm_copy(GEN x) { return RgM_shallowcopy(x); }
    2124             : 
    2125             : /* divisibility: return 1 if y[i] | x[i] for all i, 0 otherwise. Assume
    2126             :  * x,y are ZV of the same length */
    2127             : INLINE int
    2128       23198 : ZV_dvd(GEN x, GEN y)
    2129             : {
    2130       23198 :   long i, l = lg(x);
    2131       36652 :   for (i=1; i < l; i++)
    2132       29519 :     if ( ! dvdii( gel(x,i), gel(y,i) ) ) return 0;
    2133        7133 :   return 1;
    2134             : }
    2135             : 
    2136             : /* Fq */
    2137             : INLINE GEN
    2138     1349075 : Fq_red(GEN x, GEN T, GEN p)
    2139     1349075 : { return typ(x)==t_INT? Fp_red(x,p): FpXQ_red(x,T,p); }
    2140             : INLINE GEN
    2141       10887 : Fq_to_FpXQ(GEN x, GEN T, GEN p /*unused*/)
    2142             : {
    2143             :   (void) p;
    2144       10887 :   return typ(x)==t_INT ? scalarpol(x, get_FpX_var(T)): x;
    2145             : }
    2146             : 
    2147             : INLINE GEN
    2148         511 : gener_Fq_local(GEN T, GEN p, GEN L)
    2149         511 : { return T? gener_FpXQ_local(T,p, L)
    2150         511 :           : pgener_Fp_local(p, L); }
    2151             : 
    2152             : /* FpXQX */
    2153             : INLINE GEN
    2154         940 : FpXQX_div(GEN x, GEN y, GEN T, GEN p) { return FpXQX_divrem(x, y, T, p, NULL); }
    2155             : INLINE GEN
    2156       32535 : FlxqX_div(GEN x, GEN y, GEN T, ulong p) { return FlxqX_divrem(x, y, T, p, NULL); }
    2157             : INLINE GEN
    2158       29785 : F2xqX_div(GEN x, GEN y, GEN T) { return F2xqX_divrem(x, y, T, NULL); }
    2159             : 
    2160             : /* FqX */
    2161             : INLINE GEN
    2162       27419 : FqX_red(GEN z, GEN T, GEN p) { return T? FpXQX_red(z, T, p): FpX_red(z, p); }
    2163             : INLINE GEN
    2164      903963 : FqX_add(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2165             : INLINE GEN
    2166       16438 : FqX_neg(GEN x,GEN T,GEN p) { return T? FpXX_neg(x,p): FpX_neg(x,p); }
    2167             : INLINE GEN
    2168        2380 : FqX_sub(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2169             : INLINE GEN
    2170      604488 : FqX_Fp_mul(GEN P, GEN u, GEN T, GEN p)
    2171      604488 : { return T? FpXX_Fp_mul(P, u, p): FpX_Fp_mul(P, u, p); }
    2172             : INLINE GEN
    2173      553995 : FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p)
    2174      553995 : { return typ(U)==t_INT ? FqX_Fp_mul(P, U, T, p): FpXQX_FpXQ_mul(P, U, T, p); }
    2175             : INLINE GEN
    2176       83532 : FqX_mul(GEN x, GEN y, GEN T, GEN p)
    2177       83532 : { return T? FpXQX_mul(x, y, T, p): FpX_mul(x, y, p); }
    2178             : INLINE GEN
    2179      459861 : FqX_mulu(GEN x, ulong y, GEN T, GEN p)
    2180      459861 : { return T? FpXX_mulu(x, y, p): FpX_mulu(x, y, p); }
    2181             : INLINE GEN
    2182        4760 : FqX_sqr(GEN x, GEN T, GEN p)
    2183        4760 : { return T? FpXQX_sqr(x, T, p): FpX_sqr(x, p); }
    2184             : INLINE GEN
    2185        1428 : FqX_powu(GEN x, ulong n, GEN T, GEN p)
    2186        1428 : { return T? FpXQX_powu(x, n, T, p): FpX_powu(x, n, p); }
    2187             : INLINE GEN
    2188        2970 : FqX_div(GEN x, GEN y, GEN T, GEN p)
    2189        2970 : { return T? FpXQX_divrem(x,y,T,p,NULL): FpX_divrem(x,y,p,NULL); }
    2190             : INLINE GEN
    2191        5605 : FqX_get_red(GEN S, GEN T, GEN p)
    2192        5605 : { return T? FpXQX_get_red(S,T,p): FpX_get_red(S,p); }
    2193             : INLINE GEN
    2194       47875 : FqX_rem(GEN x, GEN y, GEN T, GEN p)
    2195       47875 : { return T? FpXQX_rem(x,y,T,p): FpX_rem(x,y,p); }
    2196             : INLINE GEN
    2197         329 : FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2198         329 : { return T? FpXQX_divrem(x,y,T,p,z): FpX_divrem(x,y,p,z); }
    2199             : INLINE GEN
    2200        5957 : FqX_div_by_X_x(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2201        5957 : { return T? FpXQX_div_by_X_x(x,y,T,p,z): FpX_div_by_X_x(x,y,p,z); }
    2202             : INLINE GEN
    2203           0 : FqX_halfgcd(GEN P,GEN Q,GEN T,GEN p)
    2204           0 : {return T? FpXQX_halfgcd(P,Q,T,p): FpX_halfgcd(P,Q,p);}
    2205             : INLINE GEN
    2206      254452 : FqX_gcd(GEN P,GEN Q,GEN T,GEN p)
    2207      254452 : {return T? FpXQX_gcd(P,Q,T,p): FpX_gcd(P,Q,p);}
    2208             : INLINE GEN
    2209       78379 : FqX_extgcd(GEN P,GEN Q,GEN T,GEN p, GEN *U, GEN *V)
    2210       78379 : { return T? FpXQX_extgcd(P,Q,T,p,U,V): FpX_extgcd(P,Q,p,U,V); }
    2211             : INLINE GEN
    2212        2016 : FqX_normalize(GEN z, GEN T, GEN p) { return T? FpXQX_normalize(z, T, p): FpX_normalize(z, p); }
    2213             : INLINE GEN
    2214      268982 : FqX_deriv(GEN f, /*unused*/GEN T, GEN p) { (void)T; return FpXX_deriv(f, p); }
    2215             : INLINE GEN
    2216       71498 : FqX_factor(GEN f, GEN T, GEN p) { return T?FpXQX_factor(f, T, p): FpX_factor(f, p); }
    2217             : INLINE GEN
    2218        5810 : FqX_roots(GEN f, GEN T, GEN p) { return T?FpXQX_roots(f, T, p): FpX_roots(f, p); }
    2219             : 
    2220             : /*FqXQ*/
    2221             : INLINE GEN
    2222           0 : FqXQ_add(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2223           0 : { (void)S; return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2224             : INLINE GEN
    2225           0 : FqXQ_sub(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2226           0 : { (void)S; return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2227             : INLINE GEN
    2228           0 : FqXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p)
    2229           0 : { return T? FpXQXQ_div(x,y,S,T,p): FpXQ_div(x,y,S,p); }
    2230             : INLINE GEN
    2231           0 : FqXQ_inv(GEN x, GEN S, GEN T, GEN p)
    2232           0 : { return T? FpXQXQ_inv(x,S,T,p): FpXQ_inv(x,S,p); }
    2233             : INLINE GEN
    2234           0 : FqXQ_invsafe(GEN x, GEN S, GEN T, GEN p)
    2235           0 : { return T? FpXQXQ_invsafe(x,S,T,p): FpXQ_inv(x,S,p); }
    2236             : INLINE GEN
    2237       21018 : FqXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p)
    2238       21018 : { return T? FpXQXQ_mul(x,y,S,T,p): FpXQ_mul(x,y,S,p); }
    2239             : INLINE GEN
    2240           0 : FqXQ_sqr(GEN x, GEN S, GEN T, GEN p)
    2241           0 : { return T? FpXQXQ_sqr(x,S,T,p): FpXQ_sqr(x,S,p); }
    2242             : INLINE GEN
    2243           0 : FqXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p)
    2244           0 : { return T? FpXQXQ_pow(x,n,S,T,p): FpXQ_pow(x,n,S,p); }
    2245             : 
    2246             : /*FpXQ*/
    2247             : INLINE GEN
    2248           0 : FpXQ_add(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2249           0 : { (void)T; return FpX_add(x,y,p); }
    2250             : INLINE GEN
    2251           0 : FpXQ_sub(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2252           0 : { (void)T; return FpX_sub(x,y,p); }
    2253             : 
    2254             : /*Flxq*/
    2255             : INLINE GEN
    2256           0 : Flxq_add(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2257           0 : { (void)T; return Flx_add(x,y,p); }
    2258             : INLINE GEN
    2259          96 : Flxq_sub(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2260          96 : { (void)T; return Flx_sub(x,y,p); }
    2261             : 
    2262             : /* F2x */
    2263             : 
    2264             : INLINE ulong
    2265   108206527 : F2x_coeff(GEN x,long v)
    2266             : {
    2267   108206527 :    ulong u=(ulong)x[2+divsBIL(v)];
    2268   108206709 :    return (u>>remsBIL(v))&1UL;
    2269             : }
    2270             : 
    2271             : INLINE void
    2272     3847066 : F2x_clear(GEN x,long v)
    2273             : {
    2274     3847066 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2275     3847066 :    *u&=~(1UL<<remsBIL(v));
    2276     3847066 : }
    2277             : 
    2278             : INLINE void
    2279    36149015 : F2x_set(GEN x,long v)
    2280             : {
    2281    36149015 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2282    36148990 :    *u|=1UL<<remsBIL(v);
    2283    36148810 : }
    2284             : 
    2285             : INLINE void
    2286     1341451 : F2x_flip(GEN x,long v)
    2287             : {
    2288     1341451 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2289     1341451 :    *u^=1UL<<remsBIL(v);
    2290     1341451 : }
    2291             : 
    2292             : /* F2v */
    2293             : 
    2294             : INLINE ulong
    2295   104440215 : F2v_coeff(GEN x,long v) { return F2x_coeff(x,v-1); }
    2296             : 
    2297             : INLINE void
    2298     3847066 : F2v_clear(GEN x,long v) { F2x_clear(x,v-1); }
    2299             : 
    2300             : INLINE void
    2301    15219758 : F2v_set(GEN x,long v)   { F2x_set(x,v-1); }
    2302             : 
    2303             : INLINE void
    2304     1341451 : F2v_flip(GEN x,long v) { F2x_flip(x,v-1); }
    2305             : 
    2306             : /* F2m */
    2307             : 
    2308             : INLINE ulong
    2309    12766088 : F2m_coeff(GEN x, long a, long b) { return F2v_coeff(gel(x,b), a); }
    2310             : 
    2311             : INLINE void
    2312           0 : F2m_clear(GEN x, long a, long b) { F2v_clear(gel(x,b), a); }
    2313             : 
    2314             : INLINE void
    2315     1613024 : F2m_set(GEN x, long a, long b) { F2v_set(gel(x,b), a); }
    2316             : 
    2317             : INLINE void
    2318     1341451 : F2m_flip(GEN x, long a, long b) { F2v_flip(gel(x,b), a); }
    2319             : 
    2320             : /* ARITHMETIC */
    2321             : INLINE GEN
    2322         938 : matpascal(long n) { return matqpascal(n, NULL); }
    2323             : INLINE long
    2324     1975475 : Z_issquare(GEN x) { return Z_issquareall(x, NULL); }
    2325             : INLINE long
    2326          14 : Z_ispower(GEN x, ulong k) { return Z_ispowerall(x, k, NULL); }
    2327             : INLINE GEN
    2328     4643889 : sqrti(GEN x) { return sqrtremi(x,NULL); }
    2329             : INLINE GEN
    2330     7338064 : gaddgs(GEN y, long s) { return gaddsg(s,y); }
    2331             : INLINE int
    2332       24114 : gcmpgs(GEN y, long s) { return -gcmpsg(s,y); }
    2333             : INLINE int
    2334       22953 : gequalgs(GEN y, long s) { return gequalsg(s,y); }
    2335             : INLINE GEN
    2336           0 : gmaxsg(long s, GEN y) { return gmaxgs(y,s); }
    2337             : INLINE GEN
    2338           0 : gminsg(long s, GEN y) { return gmings(y,s); }
    2339             : INLINE GEN
    2340     5784812 : gmulgs(GEN y, long s) { return gmulsg(s,y); }
    2341             : INLINE GEN
    2342      614087 : gsubgs(GEN y, long s) { return gaddgs(y, -s); }
    2343             : INLINE GEN
    2344      442861 : gdivsg(long s, GEN y) { return gdiv(stoi(s), y); }
    2345             : 
    2346             : /* x t_COMPLEX */
    2347             : INLINE GEN
    2348     8793642 : cxnorm(GEN x) { return gadd(gsqr(gel(x,1)), gsqr(gel(x,2))); }
    2349             : /* q t_QUAD */
    2350             : INLINE GEN
    2351         623 : quadnorm(GEN q)
    2352             : {
    2353         623 :   GEN X = gel(q,1), b = gel(X,3), c = gel(X,2);
    2354         623 :   GEN z, u = gel(q,3), v = gel(q,2);
    2355         623 :   if (typ(u) == t_INT && typ(v) == t_INT) /* generic case */
    2356             :   {
    2357         308 :     z = signe(b)? mulii(v, addii(u,v)): sqri(v);
    2358         308 :     return addii(z, mulii(c, sqri(u)));
    2359             :   }
    2360             :   else
    2361             :   {
    2362         315 :     z = signe(b)? gmul(v, gadd(u,v)): gsqr(v);
    2363         315 :     return gadd(z, gmul(c, gsqr(u)));
    2364             :   }
    2365             : }
    2366             : /* x a t_QUAD, return the attached discriminant */
    2367             : INLINE GEN
    2368         252 : quad_disc(GEN x)
    2369             : {
    2370         252 :   GEN Q = gel(x,1), b = gel(Q,3), c = gel(Q,2), c4;
    2371         252 :   if (is_pm1(b))
    2372             :   {
    2373         196 :     pari_sp av = avma; (void)new_chunk(lgefint(c) + 1);
    2374         196 :     c4 = shifti(c,2); avma = av; return subsi(1, c4);
    2375             :   }
    2376          56 :   c4 = shifti(c,2); togglesign_safe(&c4); return c4;
    2377             : }
    2378             : INLINE GEN
    2379     6011782 : qfb_disc3(GEN x, GEN y, GEN z) { return subii(sqri(y), shifti(mulii(x,z),2)); }
    2380             : INLINE GEN
    2381     5919942 : qfb_disc(GEN x) { return qfb_disc3(gel(x,1), gel(x,2), gel(x,3)); }
    2382             : 
    2383             : INLINE GEN
    2384     1418427 : sqrfrac(GEN x)
    2385             : {
    2386     1418427 :   GEN z = cgetg(3,t_FRAC);
    2387     1418427 :   gel(z,1) = sqri(gel(x,1));
    2388     1418427 :   gel(z,2) = sqri(gel(x,2)); return z;
    2389             : }
    2390             : 
    2391             : INLINE void
    2392     7447595 : normalize_frac(GEN z) {
    2393     7447595 :   if (signe(gel(z,2)) < 0) { togglesign(gel(z,1)); setabssign(gel(z,2)); }
    2394     7447595 : }
    2395             : 
    2396             : INLINE GEN
    2397      325024 : powii(GEN x, GEN n)
    2398             : {
    2399      325024 :   long ln = lgefint(n);
    2400      325024 :   if (ln == 3) {
    2401             :     GEN z;
    2402      323638 :     if (signe(n) > 0) return powiu(x, n[2]);
    2403        2359 :     z = cgetg(3, t_FRAC);
    2404        2359 :     gel(z,1) = gen_1;
    2405        2359 :     gel(z,2) = powiu(x, n[2]);
    2406        2359 :     return z;
    2407             :   }
    2408        1386 :   if (ln == 2) return gen_1; /* rare */
    2409             :   /* should never happen */
    2410           0 :   return powgi(x, n); /* overflow unless x = 0, 1, -1 */
    2411             : }
    2412             : INLINE GEN
    2413         847 : powIs(long n) {
    2414         847 :   switch(n & 3)
    2415             :   {
    2416           7 :     case 1: return mkcomplex(gen_0,gen_1);
    2417         315 :     case 2: return gen_m1;
    2418         462 :     case 3: return mkcomplex(gen_0,gen_m1);
    2419             :   }
    2420          63 :   return gen_1;
    2421             : }
    2422             : 
    2423             : /*******************************************************************/
    2424             : /*                                                                 */
    2425             : /*                             ASSIGNMENTS                         */
    2426             : /*                                                                 */
    2427             : /*******************************************************************/
    2428           0 : INLINE void mpexpz(GEN x, GEN z)
    2429           0 : { pari_sp av = avma; gaffect(mpexp(x), z); avma = av; }
    2430           0 : INLINE void mplogz(GEN x, GEN z)
    2431           0 : { pari_sp av = avma; gaffect(mplog(x), z); avma = av; }
    2432           0 : INLINE void mpcosz(GEN x, GEN z)
    2433           0 : { pari_sp av = avma; gaffect(mpcos(x), z); avma = av; }
    2434           0 : INLINE void mpsinz(GEN x, GEN z)
    2435           0 : { pari_sp av = avma; gaffect(mpsin(x), z); avma = av; }
    2436           0 : INLINE void gnegz(GEN x, GEN z)
    2437           0 : { pari_sp av = avma; gaffect(gneg(x), z); avma = av; }
    2438           0 : INLINE void gabsz(GEN x, long prec, GEN z)
    2439           0 : { pari_sp av = avma; gaffect(gabs(x,prec), z); avma = av; }
    2440       23318 : INLINE void gaddz(GEN x, GEN y, GEN z)
    2441       23318 : { pari_sp av = avma; gaffect(gadd(x,y), z); avma = av; }
    2442           0 : INLINE void gsubz(GEN x, GEN y, GEN z)
    2443           0 : { pari_sp av = avma; gaffect(gsub(x,y), z); avma = av; }
    2444       11673 : INLINE void gmulz(GEN x, GEN y, GEN z)
    2445       11673 : { pari_sp av = avma; gaffect(gmul(x,y), z); avma = av; }
    2446           0 : INLINE void gdivz(GEN x, GEN y, GEN z)
    2447           0 : { pari_sp av = avma; gaffect(gdiv(x,y), z); avma = av; }
    2448           0 : INLINE void gdiventz(GEN x, GEN y, GEN z)
    2449           0 : { pari_sp av = avma; gaffect(gdivent(x,y), z); avma = av; }
    2450           0 : INLINE void gmodz(GEN x, GEN y, GEN z)
    2451           0 : { pari_sp av = avma; gaffect(gmod(x,y), z); avma = av; }
    2452           0 : INLINE void gmul2nz(GEN x, long s, GEN z)
    2453           0 : { pari_sp av = avma; gaffect(gmul2n(x,s), z); avma = av; }
    2454           0 : INLINE void gshiftz(GEN x, long s, GEN z)
    2455           0 : { pari_sp av = avma; gaffect(gshift(x,s), z); avma = av; }
    2456             : 
    2457             : /*******************************************************************/
    2458             : /*                                                                 */
    2459             : /*                       ELLIPTIC CURVES                           */
    2460             : /*                                                                 */
    2461             : /*******************************************************************/
    2462     5003816 : INLINE GEN ell_get_a1(GEN e) { return gel(e,1); }
    2463     3296438 : INLINE GEN ell_get_a2(GEN e) { return gel(e,2); }
    2464     4476617 : INLINE GEN ell_get_a3(GEN e) { return gel(e,3); }
    2465     4094193 : INLINE GEN ell_get_a4(GEN e) { return gel(e,4); }
    2466     4668025 : INLINE GEN ell_get_a6(GEN e) { return gel(e,5); }
    2467     3948625 : INLINE GEN ell_get_b2(GEN e) { return gel(e,6); }
    2468     1008988 : INLINE GEN ell_get_b4(GEN e) { return gel(e,7); }
    2469     1612780 : INLINE GEN ell_get_b6(GEN e) { return gel(e,8); }
    2470     1456980 : INLINE GEN ell_get_b8(GEN e) { return gel(e,9); }
    2471     6273916 : INLINE GEN ell_get_c4(GEN e) { return gel(e,10); }
    2472     8305232 : INLINE GEN ell_get_c6(GEN e) { return gel(e,11); }
    2473     9736892 : INLINE GEN ell_get_disc(GEN e) { return gel(e,12); }
    2474     1174362 : INLINE GEN ell_get_j(GEN e) { return gel(e,13); }
    2475     8080623 : INLINE long ell_get_type(GEN e) { return mael(e,14,1); }
    2476     1510106 : INLINE GEN ellff_get_field(GEN x) { return gmael(x, 15, 1); }
    2477      652420 : INLINE GEN ellff_get_a4a6(GEN x)  { return gmael(x, 15, 2); }
    2478         917 : INLINE GEN ellQp_get_zero(GEN x) { return gmael(x, 15, 1); }
    2479         287 : INLINE long ellQp_get_prec(GEN E) { GEN z = ellQp_get_zero(E); return valp(z); }
    2480         623 : INLINE GEN ellQp_get_p(GEN E) { GEN z = ellQp_get_zero(E); return gel(z,2); }
    2481       36946 : INLINE long ellR_get_prec(GEN x) { return nbits2prec(mael3(x, 15, 1, 1)); }
    2482        1325 : INLINE long ellR_get_sign(GEN x) { return mael3(x, 15, 1, 2); }
    2483      708337 : INLINE GEN ellnf_get_nf(GEN x) { return checknf_i(gmael(x,15,1)); }
    2484          42 : INLINE GEN ellnf_get_bnf(GEN x) { return checkbnf_i(gmael(x,15,1)); }
    2485             : 
    2486    34076581 : INLINE int ell_is_inf(GEN z) { return lg(z) == 2; }
    2487      927157 : INLINE GEN ellinf(void) { return mkvec(gen_0); }
    2488             : 
    2489             : /*******************************************************************/
    2490             : /*                                                                 */
    2491             : /*                    ALGEBRAIC NUMBER THEORY                      */
    2492             : /*                                                                 */
    2493             : /*******************************************************************/
    2494     6690734 : INLINE GEN modpr_get_pr(GEN x)  { return gel(x,3); }
    2495      602366 : INLINE GEN modpr_get_p(GEN x)  { return pr_get_p(modpr_get_pr(x)); }
    2496     1950034 : INLINE GEN modpr_get_T(GEN x)  { return lg(x) == 4? NULL: gel(x,4); }
    2497             : 
    2498    16058973 : INLINE GEN pr_get_p(GEN pr)  { return gel(pr,1); }
    2499     2285229 : INLINE GEN pr_get_gen(GEN pr){ return gel(pr,2); }
    2500             : /* .[2] instead of itos works: e and f are small positive integers */
    2501     2473791 : INLINE long pr_get_e(GEN pr) { return gel(pr,3)[2]; }
    2502     6924869 : INLINE long pr_get_f(GEN pr) { return gel(pr,4)[2]; }
    2503     6034968 : INLINE GEN pr_get_tau(GEN pr){ return gel(pr,5); }
    2504             : INLINE int
    2505      677735 : pr_is_inert(GEN P) { return pr_get_f(P) == lg(pr_get_gen(P))-1; }
    2506             : INLINE GEN
    2507      336960 : pr_norm(GEN pr) { return powiu(pr_get_p(pr), pr_get_f(pr)); }
    2508             : INLINE ulong
    2509       29358 : upr_norm(GEN pr) { return upowuu(pr_get_p(pr)[2], pr_get_f(pr)); }
    2510             : 
    2511             : /* assume nf a genuine nf */
    2512             : INLINE long
    2513        7363 : nf_get_varn(GEN nf) { return varn(gel(nf,1)); }
    2514             : INLINE GEN
    2515     7976978 : nf_get_pol(GEN nf) { return gel(nf,1); }
    2516             : INLINE long
    2517     4329120 : nf_get_degree(GEN nf) { return degpol( nf_get_pol(nf) ); }
    2518             : INLINE long
    2519     1101979 : nf_get_r1(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,1)); }
    2520             : INLINE long
    2521        1057 : nf_get_r2(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,2)); }
    2522             : INLINE GEN
    2523       25984 : nf_get_disc(GEN nf) { return gel(nf,3); }
    2524             : INLINE GEN
    2525      744943 : nf_get_index(GEN nf) { return gel(nf,4); }
    2526             : INLINE GEN
    2527      985399 : nf_get_M(GEN nf) { return gmael(nf,5,1); }
    2528             : INLINE GEN
    2529       45897 : nf_get_G(GEN nf) { return gmael(nf,5,2); }
    2530             : INLINE GEN
    2531      380599 : nf_get_roundG(GEN nf) { return gmael(nf,5,3); }
    2532             : INLINE GEN
    2533         826 : nf_get_Tr(GEN nf) { return gmael(nf,5,4); }
    2534             : INLINE GEN
    2535         840 : nf_get_diff(GEN nf) { return gmael(nf,5,5); }
    2536             : INLINE GEN
    2537          35 : nf_get_ramified_primes(GEN nf) { return gmael(nf,5,8); }
    2538             : INLINE GEN
    2539      101704 : nf_get_roots(GEN nf) { return gel(nf,6); }
    2540             : INLINE GEN
    2541     7827762 : nf_get_zk(GEN nf) { return gel(nf,7); }
    2542             : INLINE GEN
    2543     1306850 : nf_get_invzk(GEN nf) { return gel(nf,8); }
    2544             : INLINE void
    2545        6104 : nf_get_sign(GEN nf, long *r1, long *r2)
    2546             : {
    2547        6104 :   GEN x = gel(nf,2);
    2548        6104 :   *r1 = itou(gel(x,1));
    2549        6104 :   *r2 = itou(gel(x,2));
    2550        6104 : }
    2551             : 
    2552             : INLINE GEN
    2553       10150 : abgrp_get_no(GEN x) { return gel(x,1); }
    2554             : INLINE GEN
    2555     1032715 : abgrp_get_cyc(GEN x) { return gel(x,2); }
    2556             : INLINE GEN
    2557      276177 : abgrp_get_gen(GEN x) { return gel(x,3); }
    2558             : INLINE GEN
    2559     1185115 : bnf_get_nf(GEN bnf) { return gel(bnf,7); }
    2560             : INLINE GEN
    2561      565423 : bnf_get_clgp(GEN bnf) { return gmael(bnf,8,1); }
    2562             : INLINE GEN
    2563        1029 : bnf_get_no(GEN bnf) { return abgrp_get_no(bnf_get_clgp(bnf)); }
    2564             : INLINE GEN
    2565      296029 : bnf_get_cyc(GEN bnf) { return abgrp_get_cyc(bnf_get_clgp(bnf)); }
    2566             : INLINE GEN
    2567      268043 : bnf_get_gen(GEN bnf)  { return abgrp_get_gen(bnf_get_clgp(bnf)); }
    2568             : INLINE GEN
    2569         839 : bnf_get_reg(GEN bnf) { return gmael(bnf,8,2); }
    2570             : INLINE GEN
    2571      429509 : bnf_get_logfu(GEN bnf) { return gel(bnf,3); }
    2572             : INLINE GEN
    2573        2465 : bnf_get_tuU(GEN bnf) { return gmael3(bnf,8,4,2); }
    2574             : INLINE long
    2575        8603 : bnf_get_tuN(GEN bnf) { return gmael3(bnf,8,4,1)[2]; }
    2576             : INLINE GEN
    2577        1799 : bnf_get_fu(GEN bnf) {
    2578        1799 :   GEN fu = bnf_get_fu_nocheck(bnf);
    2579        1799 :   if (typ(fu) == t_MAT) pari_err(e_MISC,"missing units in bnf");
    2580        1799 :   return fu;
    2581             : }
    2582             : INLINE GEN
    2583        3620 : bnf_get_fu_nocheck(GEN bnf) { return gmael(bnf,8,5); }
    2584             : 
    2585             : INLINE GEN
    2586      397254 : bnr_get_bnf(GEN bnr) { return gel(bnr,1); }
    2587             : INLINE GEN
    2588      198697 : bnr_get_bid(GEN bnr) { return gel(bnr,2); }
    2589             : INLINE GEN
    2590       11018 : bnr_get_mod(GEN bnr) { return gmael(bnr,2,1); }
    2591             : INLINE GEN
    2592        8197 : bnr_get_nf(GEN bnr) { return gmael(bnr,1,7); }
    2593             : INLINE GEN
    2594      231877 : bnr_get_clgp(GEN bnr) { return gel(bnr,5); }
    2595             : INLINE GEN
    2596        9121 : bnr_get_no(GEN bnr) { return abgrp_get_no(bnr_get_clgp(bnr)); }
    2597             : INLINE GEN
    2598      220075 : bnr_get_cyc(GEN bnr) { return abgrp_get_cyc(bnr_get_clgp(bnr)); }
    2599             : INLINE GEN
    2600          70 : bnr_get_gen_nocheck(GEN bnr) { return abgrp_get_gen(bnr_get_clgp(bnr)); }
    2601             : INLINE GEN
    2602        2611 : bnr_get_gen(GEN bnr) {
    2603        2611 :   GEN G = bnr_get_clgp(bnr);
    2604        2611 :   if (lg(G) !=  4)
    2605           0 :     pari_err(e_MISC,"missing bnr generators: please use bnrinit(,,1)");
    2606        2611 :   return gel(G,3);
    2607             : }
    2608             : 
    2609             : INLINE GEN
    2610      236504 : bid_get_mod(GEN bid) { return gel(bid,1); }
    2611             : INLINE GEN
    2612      114412 : bid_get_ideal(GEN bid) { return gmael(bid,1,1); }
    2613             : INLINE GEN
    2614       96033 : bid_get_arch(GEN bid) { return gmael(bid,1,2); }
    2615             : INLINE GEN
    2616      522071 : bid_get_grp(GEN bid) { return gel(bid,2); }
    2617             : INLINE GEN
    2618      362464 : bid_get_fact(GEN bid) { return gel(bid,3); }
    2619             : INLINE GEN
    2620      215252 : bid_get_sprk(GEN bid) { return gmael(bid,4,1); }
    2621             : INLINE GEN
    2622      239703 : bid_get_sarch(GEN bid) { return gmael(bid,4,2); }
    2623             : INLINE GEN
    2624      118981 : bid_get_ind(GEN bid) { return gmael(bid,4,3); }
    2625             : INLINE GEN
    2626      423175 : bid_get_U(GEN bid) { return gel(bid,5); }
    2627             : INLINE GEN
    2628           0 : bid_get_no(GEN bid) { return abgrp_get_no(bid_get_grp(bid)); }
    2629             : INLINE GEN
    2630      515288 : bid_get_cyc(GEN bid) { return abgrp_get_cyc(bid_get_grp(bid)); }
    2631             : INLINE GEN
    2632           0 : bid_get_gen_nocheck(GEN bid)  { return abgrp_get_gen(bid_get_grp(bid)); }
    2633             : INLINE GEN
    2634        6188 : bid_get_gen(GEN bid) {
    2635        6188 :   GEN G = bid_get_grp(bid);
    2636        6188 :   if (lg(G) != 4) pari_err(e_MISC,"missing bid generators. Use idealstar(,,2)");
    2637        6188 :   return abgrp_get_gen(G);
    2638             : }
    2639             : INLINE GEN
    2640        2240 : gal_get_pol(GEN gal) { return gel(gal,1); }
    2641             : INLINE GEN
    2642         980 : gal_get_p(GEN gal) { return gmael(gal,2,1); }
    2643             : INLINE GEN
    2644          56 : gal_get_e(GEN gal) { return gmael(gal,2,2); }
    2645             : INLINE GEN
    2646        1813 : gal_get_mod(GEN gal) { return gmael(gal,2,3); }
    2647             : INLINE GEN
    2648        2191 : gal_get_roots(GEN gal) { return gel(gal,3); }
    2649             : INLINE GEN
    2650        1820 : gal_get_invvdm(GEN gal) { return gel(gal,4); }
    2651             : INLINE GEN
    2652        1820 : gal_get_den(GEN gal) { return gel(gal,5); }
    2653             : INLINE GEN
    2654        3829 : gal_get_group(GEN gal) { return gel(gal,6); }
    2655             : INLINE GEN
    2656        1218 : gal_get_gen(GEN gal) { return gel(gal,7); }
    2657             : INLINE GEN
    2658         763 : gal_get_orders(GEN gal) { return gel(gal,8); }
    2659             : 
    2660             : /* assume rnf a genuine rnf */
    2661             : INLINE long
    2662      310786 : rnf_get_degree(GEN rnf) { return degpol(rnf_get_pol(rnf)); }
    2663             : INLINE long
    2664       14742 : rnf_get_nfdegree(GEN rnf) { return degpol(nf_get_pol(rnf_get_nf(rnf))); }
    2665             : INLINE long
    2666      156254 : rnf_get_absdegree(GEN rnf) { return degpol(gmael(rnf,11,1)); }
    2667             : INLINE GEN
    2668         427 : rnf_get_idealdisc(GEN rnf) { return gmael(rnf,3,1); }
    2669             : INLINE GEN
    2670         455 : rnf_get_k(GEN rnf) { return gmael(rnf,11,3); }
    2671             : INLINE GEN
    2672         455 : rnf_get_alpha(GEN rnf) { return gmael(rnf, 11, 2); }
    2673             : INLINE GEN
    2674      123438 : rnf_get_nf(GEN rnf) { return gel(rnf,10); }
    2675             : INLINE void
    2676        1687 : rnf_get_nfzk(GEN rnf, GEN *b, GEN *cb) {*b=gmael(rnf,2,1); *cb=gmael(rnf,2,2);}
    2677             : INLINE GEN
    2678       93450 : rnf_get_polabs(GEN rnf) { return gmael(rnf,11,1); }
    2679             : INLINE GEN
    2680      462154 : rnf_get_pol(GEN rnf) { return gel(rnf,1); }
    2681             : INLINE GEN
    2682          63 : rnf_get_disc(GEN rnf) { return gel(rnf,3); }
    2683             : INLINE GEN
    2684         105 : rnf_get_index(GEN rnf) { return gel(rnf,4); }
    2685             : INLINE long
    2686           0 : rnf_get_varn(GEN rnf) { return varn(gel(rnf,1)); }
    2687             : INLINE GEN
    2688      106295 : rnf_get_nfpol(GEN rnf) { return gmael(rnf,10,1); }
    2689             : INLINE long
    2690         490 : rnf_get_nfvarn(GEN rnf) { return varn(gmael(rnf,10,1)); }
    2691             : INLINE GEN
    2692        2436 : rnf_get_zk(GEN rnf) { return gel(rnf,7); }
    2693             : INLINE GEN
    2694       33950 : rnf_get_map(GEN rnf) { return gel(rnf,11); }
    2695             : INLINE GEN
    2696        1190 : rnf_get_invzk(GEN rnf) { return gel(rnf,8); }
    2697             : 
    2698             : /* I integral ZM (not HNF), G ZM, rounded Cholesky form of a weighted
    2699             :  * T2 matrix. Reduce I wrt G */
    2700             : INLINE GEN
    2701        1323 : idealpseudored(GEN I, GEN G)
    2702        1323 : { return ZM_mul(I, ZM_lll(ZM_mul(G, I), 0.99, LLL_IM)); }
    2703             : 
    2704             : /* I integral (not necessarily HNF), G ZM, rounded Cholesky form of a weighted
    2705             :  * T2 matrix. Return m in I with T2(m) small */
    2706             : INLINE GEN
    2707      164709 : idealpseudomin(GEN I, GEN G)
    2708             : {
    2709      164709 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2710      164709 :   return ZM_ZC_mul(I, gel(u,1));
    2711             : }
    2712             : /* I, G as in idealpseudomin. Return an irrational m in I with T2(m) small */
    2713             : INLINE GEN
    2714      252070 : idealpseudomin_nonscalar(GEN I, GEN G)
    2715             : {
    2716      252070 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2717      252070 :   GEN m = ZM_ZC_mul(I, gel(u,1));
    2718      252070 :   if (ZV_isscalar(m) && lg(u) > 2) m = ZM_ZC_mul(I, gel(u,2));
    2719      252070 :   return m;
    2720             : }
    2721             : 
    2722             : INLINE GEN
    2723           0 : idealred_elt(GEN nf, GEN I) {
    2724           0 :   pari_sp av = avma;
    2725           0 :   GEN u = idealpseudomin(I, nf_get_roundG(nf));
    2726           0 :   return gerepileupto(av, u);
    2727             : }
    2728             : INLINE GEN
    2729      169779 : idealred(GEN nf, GEN I) { return idealred0(nf, I, NULL); }
    2730             : 
    2731             : INLINE GEN
    2732        1197 : idealchineseinit(GEN nf, GEN x)
    2733        1197 : { return idealchinese(nf,x,NULL); }
    2734             : 
    2735             : /*******************************************************************/
    2736             : /*                                                                 */
    2737             : /*                              CLOSURES                           */
    2738             : /*                                                                 */
    2739             : /*******************************************************************/
    2740   186488267 : INLINE long closure_arity(GEN C)          { return ((ulong)C[1])&ARITYBITS; }
    2741    34462035 : INLINE long closure_is_variadic(GEN C) { return !!(((ulong)C[1])&VARARGBITS); }
    2742   151848394 : INLINE const char *closure_codestr(GEN C)  { return GSTR(gel(C,2))-1; }
    2743           0 : INLINE GEN closure_get_code(GEN C)  { return gel(C,2); }
    2744   151823951 : INLINE GEN closure_get_oper(GEN C)  { return gel(C,3); }
    2745   151801405 : INLINE GEN closure_get_data(GEN C)  { return gel(C,4); }
    2746       16372 : INLINE GEN closure_get_dbg(GEN C)   { return gel(C,5); }
    2747       34620 : INLINE GEN closure_get_text(GEN C)  { return gel(C,6); }
    2748      603494 : INLINE GEN closure_get_frame(GEN C) { return gel(C,7); }
    2749             : 
    2750             : /*******************************************************************/
    2751             : /*                                                                 */
    2752             : /*                               ERRORS                            */
    2753             : /*                                                                 */
    2754             : /*******************************************************************/
    2755             : INLINE long
    2756       46116 : err_get_num(GEN e) { return e[1]; }
    2757             : INLINE GEN
    2758          70 : err_get_compo(GEN e, long i) { return gel(e, i+1); }
    2759             : 
    2760             : INLINE void
    2761          14 : pari_err_BUG(const char *f) { pari_err(e_BUG,f); }
    2762             : INLINE void
    2763           7 : pari_err_CONSTPOL(const char *f) { pari_err(e_CONSTPOL, f); }
    2764             : INLINE void
    2765          63 : pari_err_COPRIME(const char *f, GEN x, GEN y) { pari_err(e_COPRIME, f,x,y); }
    2766             : INLINE void
    2767         918 : pari_err_DIM(const char *f) { pari_err(e_DIM, f); }
    2768             : INLINE void
    2769           0 : pari_err_FILE(const char *f, const char *g) { pari_err(e_FILE, f,g); }
    2770             : INLINE void
    2771          21 : pari_err_FLAG(const char *f) { pari_err(e_FLAG,f); }
    2772             : INLINE void
    2773         252 : pari_err_IMPL(const char *f) { pari_err(e_IMPL,f); }
    2774             : INLINE void
    2775         578 : pari_err_INV(const char *f, GEN x) { pari_err(e_INV,f,x); }
    2776             : INLINE void
    2777          14 : pari_err_IRREDPOL(const char *f, GEN x) { pari_err(e_IRREDPOL, f,x); }
    2778             : INLINE void
    2779        5089 : 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); }
    2780             : INLINE void
    2781         224 : pari_err_COMPONENT(const char *f, const char *op, GEN l, GEN x) { pari_err(e_COMPONENT, f,op,l,x); }
    2782             : INLINE void
    2783           0 : pari_err_MAXPRIME(ulong c) { pari_err(e_MAXPRIME, c); }
    2784             : INLINE void
    2785         287 : pari_err_OP(const char *f, GEN x, GEN y) { pari_err(e_OP, f,x,y); }
    2786             : INLINE void
    2787          63 : pari_err_OVERFLOW(const char *f) { pari_err(e_OVERFLOW, f); }
    2788             : INLINE void
    2789         225 : pari_err_PREC(const char *f) { pari_err(e_PREC,f); }
    2790             : INLINE void
    2791           0 : pari_err_PACKAGE(const char *f) { pari_err(e_PACKAGE,f); }
    2792             : INLINE void
    2793          56 : pari_err_PRIME(const char *f, GEN x) { pari_err(e_PRIME, f,x); }
    2794             : INLINE void
    2795         728 : pari_err_MODULUS(const char *f, GEN x, GEN y) { pari_err(e_MODULUS, f,x,y); }
    2796             : INLINE void
    2797          35 : pari_err_ROOTS0(const char *f) { pari_err(e_ROOTS0, f); }
    2798             : INLINE void
    2799          77 : pari_err_SQRTN(const char *f, GEN x) { pari_err(e_SQRTN, f,x); }
    2800             : INLINE void
    2801       24173 : pari_err_TYPE(const char *f, GEN x) { pari_err(e_TYPE, f,x); }
    2802             : INLINE void
    2803        3010 : pari_err_TYPE2(const char *f, GEN x, GEN y) { pari_err(e_TYPE2, f,x,y); }
    2804             : INLINE void
    2805         196 : pari_err_VAR(const char *f, GEN x, GEN y) { pari_err(e_VAR, f,x,y); }
    2806             : INLINE void
    2807         119 : pari_err_PRIORITY(const char *f, GEN x, const char *op, long v)
    2808         119 : { pari_err(e_PRIORITY, f,x,op,v); }

Generated by: LCOV version 1.11