Code coverage tests

This page documents the degree to which the PARI/GP source code is tested by our public test suite, distributed with the source distribution in directory src/test/. This is measured by the gcov utility; we then process gcov output using the lcov frond-end.

We test a few variants depending on Configure flags on the pari.math.u-bordeaux.fr machine (x86_64 architecture), and agregate them in the final report:

The target is 90% coverage for all mathematical modules (given that branches depending on DEBUGLEVEL or DEBUGMEM are not covered). This script is run to produce the results below.

LCOV - code coverage report
Current view: top level - headers - pariinl.h (source / functions) Hit Total Coverage
Test: PARI/GP v2.10.0 lcov report (development 21947-4fc3047) Lines: 1230 1394 88.2 %
Date: 2018-02-24 06:16:21 Functions: 547 618 88.5 %
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     1538472 : mkintmod(GEN x, GEN y) { retmkintmod(x,y); }
     141             : INLINE GEN
     142        3801 : mkintmodu(ulong x, ulong y) {
     143        3801 :   GEN v = cgetg(3,t_INTMOD);
     144        3801 :   gel(v,1) = utoipos(y);
     145        3801 :   gel(v,2) = utoi(x); return v;
     146             : }
     147             : INLINE GEN
     148     1688137 : mkpolmod(GEN x, GEN y) { retmkpolmod(x,y); }
     149             : INLINE GEN
     150    12292634 : mkfrac(GEN x, GEN y) { retmkfrac(x,y); }
     151             : INLINE GEN
     152         385 : mkfracss(long x, long y) { retmkfrac(stoi(x),stoi(y)); }
     153             : /* q = n/d a t_FRAC or t_INT; recover (n,d) */
     154             : INLINE void
     155       10381 : Qtoss(GEN q, long *n, long *d)
     156             : {
     157       10381 :   if (typ(q) == t_INT) { *n = itos(q); *d = 1; }
     158        2198 :   else { *n = itos(gel(q,1)); *d = itou(gel(q,2)); }
     159       10381 : }
     160             : INLINE GEN
     161    35066017 : sstoQ(long n, long d)
     162             : {
     163             :   long g, r, q;
     164    35066017 :   if (d == 1) return stoi(n);
     165    35062391 :   q = sdivss_rem(n,d,&r);
     166    35062391 :   if (!r) return stoi(q);
     167     1349285 :   g = cgcd(d,r); /* gcd(n,d) */
     168     1349285 :   if (g != 1) { n /= g; d /= g; }
     169     1349285 :   if (d < 0) { d = -d; n = -n; }
     170     1349285 :   retmkfrac(stoi(n), utoi(d));
     171             : }
     172             : 
     173             : INLINE GEN
     174     3953883 : mkfraccopy(GEN x, GEN y) { retmkfrac(icopy(x), icopy(y)); }
     175             : INLINE GEN
     176           7 : mkrfrac(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     177           7 :   gel(v,1) = x; gel(v,2) = y; return v; }
     178             : INLINE GEN
     179           7 : mkrfraccopy(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     180           7 :   gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     181             : INLINE GEN
     182     3337851 : mkcomplex(GEN x, GEN y) { retmkcomplex(x,y); }
     183             : INLINE GEN
     184      449523 : gen_I(void) { return mkcomplex(gen_0, gen_1); }
     185             : INLINE GEN
     186      203642 : cgetc(long l) { retmkcomplex(cgetr(l), cgetr(l)); }
     187             : INLINE GEN
     188          42 : mkquad(GEN n, GEN x, GEN y) { GEN v = cgetg(4, t_QUAD);
     189          42 :   gel(v,1) = n; gel(v,2) = x; gel(v,3) = y; return v; }
     190             : /* vecsmall */
     191             : INLINE GEN
     192    60384222 : mkvecsmall(long x) { GEN v = cgetg(2, t_VECSMALL); v[1] = x; return v; }
     193             : INLINE GEN
     194   116696984 : mkvecsmall2(long x,long y) { GEN v = cgetg(3, t_VECSMALL);
     195   116681307 :   v[1]=x; v[2]=y; return v; }
     196             : INLINE GEN
     197    57259803 : mkvecsmall3(long x,long y,long z) { GEN v = cgetg(4, t_VECSMALL);
     198    57254927 :   v[1]=x; v[2]=y; v[3]=z; return v; }
     199             : INLINE GEN
     200    25379994 : mkvecsmall4(long x,long y,long z,long t) { GEN v = cgetg(5, t_VECSMALL);
     201    25359557 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; return v; }
     202             : INLINE GEN
     203      467857 : mkvecsmall5(long x,long y,long z,long t,long u) { GEN v = cgetg(6, t_VECSMALL);
     204      467857 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; v[5]=u; return v; }
     205             : 
     206             : INLINE GEN
     207      158123 : mkqfi(GEN x, GEN y, GEN z) { retmkqfi(x,y,z); }
     208             : /* vec */
     209             : INLINE GEN
     210    13847465 : mkvec(GEN x) { retmkvec(x); }
     211             : INLINE GEN
     212   106821249 : mkvec2(GEN x, GEN y) { retmkvec2(x,y); }
     213             : INLINE GEN
     214    74901531 : mkvec3(GEN x, GEN y, GEN z) { retmkvec3(x,y,z); }
     215             : INLINE GEN
     216     8570295 : mkvec4(GEN x, GEN y, GEN z, GEN t) { retmkvec4(x,y,z,t); }
     217             : INLINE GEN
     218    11931714 : mkvec5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkvec5(x,y,z,t,u); }
     219             : INLINE GEN
     220           7 : mkvecs(long x) { retmkvec(stoi(x)); }
     221             : INLINE GEN
     222       20319 : mkvec2s(long x, long y) { retmkvec2(stoi(x),stoi(y)); }
     223             : INLINE GEN
     224      492724 : mkvec3s(long x, long y, long z) { retmkvec3(stoi(x),stoi(y),stoi(z)); }
     225             : INLINE GEN
     226          21 : mkvec4s(long x, long y, long z, long t) { retmkvec4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     227             : INLINE GEN
     228       33852 : mkveccopy(GEN x) { GEN v = cgetg(2, t_VEC); gel(v,1) = gcopy(x); return v; }
     229             : INLINE GEN
     230      107660 : mkvec2copy(GEN x, GEN y) {
     231      107660 :   GEN v = cgetg(3,t_VEC); gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     232             : /* col */
     233             : INLINE GEN
     234     2387992 : mkcol(GEN x) { retmkcol(x); }
     235             : INLINE GEN
     236    26142905 : mkcol2(GEN x, GEN y) { retmkcol2(x,y); }
     237             : INLINE GEN
     238       42385 : mkcol3(GEN x, GEN y, GEN z) { retmkcol3(x,y,z); }
     239             : INLINE GEN
     240           0 : mkcol4(GEN x, GEN y, GEN z, GEN t) { retmkcol4(x,y,z,t); }
     241             : INLINE GEN
     242           0 : mkcol5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkcol5(x,y,z,t,u); }
     243             : INLINE GEN
     244        8338 : mkcol6(GEN x, GEN y, GEN z, GEN t, GEN u, GEN v) { retmkcol6(x,y,z,t,u,v); }
     245             : INLINE GEN
     246         735 : mkcols(long x) { retmkcol(stoi(x)); }
     247             : INLINE GEN
     248     2149938 : mkcol2s(long x, long y) { retmkcol2(stoi(x),stoi(y)); }
     249             : INLINE GEN
     250           0 : mkcol3s(long x, long y, long z) { retmkcol3(stoi(x),stoi(y),stoi(z)); }
     251             : INLINE GEN
     252           0 : mkcol4s(long x, long y, long z, long t) { retmkcol4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     253             : INLINE GEN
     254       28498 : mkcolcopy(GEN x) { GEN v = cgetg(2, t_COL); gel(v,1) = gcopy(x); return v; }
     255             : /* mat */
     256             : INLINE GEN
     257     5522299 : mkmat(GEN x) { retmkmat(x); }
     258             : INLINE GEN
     259    28602405 : mkmat2(GEN x, GEN y) { retmkmat2(x,y); }
     260             : INLINE GEN
     261        2331 : mkmat3(GEN x, GEN y, GEN z) { retmkmat3(x,y,z); }
     262             : INLINE GEN
     263           0 : mkmat4(GEN x, GEN y, GEN z, GEN t) { retmkmat4(x,y,z,t); }
     264             : INLINE GEN
     265           0 : mkmat5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkmat5(x,y,z,t,u); }
     266             : INLINE GEN
     267       21549 : mkmatcopy(GEN x) { GEN v = cgetg(2, t_MAT); gel(v,1) = gcopy(x); return v; }
     268             : INLINE GEN
     269           0 : mkerr(long x) { GEN v = cgetg(2, t_ERROR); v[1] = x; return v; }
     270             : INLINE GEN
     271       24255 : mkoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_1; return v; }
     272             : INLINE GEN
     273       14287 : mkmoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_m1; return v; }
     274             : INLINE long
     275       48833 : inf_get_sign(GEN x) { return signe(gel(x,1)); }
     276             : INLINE GEN
     277       10444 : mkmat22s(long a, long b, long c, long d) {retmkmat2(mkcol2s(a,c),mkcol2s(b,d));}
     278             : INLINE GEN
     279     1530753 : mkmat22(GEN a, GEN b, GEN c, GEN d) { retmkmat2(mkcol2(a,c),mkcol2(b,d)); }
     280             : 
     281             : /* pol */
     282             : INLINE GEN
     283      879157 : pol_x(long v) {
     284      879157 :   GEN p = cgetg(4, t_POL);
     285      879157 :   p[1] = evalsigne(1)|evalvarn(v);
     286      879157 :   gel(p,2) = gen_0;
     287      879157 :   gel(p,3) = gen_1; return p;
     288             : }
     289             : /* x^n, assume n >= 0 */
     290             : INLINE GEN
     291     2498019 : pol_xn(long n, long v) {
     292     2498019 :   long i, a = n+2;
     293     2498019 :   GEN p = cgetg(a+1, t_POL);
     294     2498018 :   p[1] = evalsigne(1)|evalvarn(v);
     295     2498018 :   for (i = 2; i < a; i++) gel(p,i) = gen_0;
     296     2498018 :   gel(p,a) = gen_1; return p;
     297             : }
     298             : /* x^n, no assumption on n */
     299             : INLINE GEN
     300          42 : pol_xnall(long n, long v)
     301             : {
     302          42 :   if (n < 0) retmkrfrac(gen_1, pol_xn(-n,v));
     303          42 :   return pol_xn(n, v);
     304             : }
     305             : INLINE GEN
     306     1325319 : pol_1(long v) {
     307     1325319 :   GEN p = cgetg(3, t_POL);
     308     1325315 :   p[1] = evalsigne(1)|evalvarn(v);
     309     1325315 :   gel(p,2) = gen_1; return p;
     310             : }
     311             : INLINE GEN
     312    15081493 : pol_0(long v)
     313             : {
     314    15081493 :   GEN x = cgetg(2,t_POL);
     315    15081493 :   x[1] = evalvarn(v); return x;
     316             : }
     317             : #define retconst_vec(n,x)\
     318             :   do { long _i, _n = (n);\
     319             :        GEN _v = cgetg(_n+1, t_VEC), _x = (x);\
     320             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     321             :        return _v; } while(0)
     322             : INLINE GEN
     323     7967415 : const_vec(long n, GEN x) { retconst_vec(n, x); }
     324             : #define retconst_col(n,x)\
     325             :   do { long _i, _n = (n);\
     326             :        GEN _v = cgetg(_n+1, t_COL), _x = (x);\
     327             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     328             :        return _v; } while(0)
     329             : INLINE GEN
     330     8619285 : const_col(long n, GEN x) { retconst_col(n, x); }
     331             : INLINE GEN
     332     5369144 : const_vecsmall(long n, long c)
     333             : {
     334             :   long i;
     335     5369144 :   GEN V = cgetg(n+1,t_VECSMALL);
     336     5369151 :   for(i=1;i<=n;i++) V[i] = c;
     337     5369151 :   return V;
     338             : }
     339             : 
     340             : /***   ZERO   ***/
     341             : /* O(p^e) */
     342             : INLINE GEN
     343      303524 : zeropadic(GEN p, long e)
     344             : {
     345      303524 :   GEN y = cgetg(5,t_PADIC);
     346      303524 :   gel(y,4) = gen_0;
     347      303524 :   gel(y,3) = gen_1;
     348      303524 :   gel(y,2) = icopy(p);
     349      303524 :   y[1] = evalvalp(e) | _evalprecp(0);
     350      303524 :   return y;
     351             : }
     352             : INLINE GEN
     353         819 : zeropadic_shallow(GEN p, long e)
     354             : {
     355         819 :   GEN y = cgetg(5,t_PADIC);
     356         819 :   gel(y,4) = gen_0;
     357         819 :   gel(y,3) = gen_1;
     358         819 :   gel(y,2) = p;
     359         819 :   y[1] = evalvalp(e) | _evalprecp(0);
     360         819 :   return y;
     361             : }
     362             : /* O(pol_x(v)^e) */
     363             : INLINE GEN
     364      130879 : zeroser(long v, long e)
     365             : {
     366      130879 :   GEN x = cgetg(2, t_SER);
     367      130879 :   x[1] = evalvalp(e) | evalvarn(v); return x;
     368             : }
     369             : INLINE int
     370     4443515 : ser_isexactzero(GEN x)
     371             : {
     372     4443515 :   if (!signe(x)) switch(lg(x))
     373             :   {
     374      127666 :     case 2: return 1;
     375         847 :     case 3: return isexactzero(gel(x,2));
     376             :   }
     377     4315002 :   return 0;
     378             : }
     379             : /* 0 * pol_x(v) */
     380             : INLINE GEN
     381     5238202 : zeropol(long v) { return pol_0(v); }
     382             : /* vector(n) */
     383             : INLINE GEN
     384    26931141 : zerocol(long n)
     385             : {
     386    26931141 :   GEN y = cgetg(n+1,t_COL);
     387    26931141 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     388    26931141 :   return y;
     389             : }
     390             : /* vectorv(n) */
     391             : INLINE GEN
     392    17736750 : zerovec(long n)
     393             : {
     394    17736750 :   GEN y = cgetg(n+1,t_VEC);
     395    17736750 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     396    17736750 :   return y;
     397             : }
     398             : /* matrix(m, n) */
     399             : INLINE GEN
     400       16289 : zeromat(long m, long n)
     401             : {
     402       16289 :   GEN y = cgetg(n+1,t_MAT);
     403       16289 :   GEN v = zerocol(m);
     404       16289 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     405       16289 :   return y;
     406             : }
     407             : /* = zero_zx, sv is a evalvarn()*/
     408             : INLINE GEN
     409      787723 : zero_Flx(long sv) { return pol0_Flx(sv); }
     410             : INLINE GEN
     411    32803664 : zero_Flv(long n)
     412             : {
     413    32803664 :   GEN y = cgetg(n+1,t_VECSMALL);
     414    32803838 :   long i; for (i=1; i<=n; i++) y[i] = 0;
     415    32803838 :   return y;
     416             : }
     417             : /* matrix(m, n) */
     418             : INLINE GEN
     419      802410 : zero_Flm(long m, long n)
     420             : {
     421      802410 :   GEN y = cgetg(n+1,t_MAT);
     422      802402 :   GEN v = zero_Flv(m);
     423      802409 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     424      802409 :   return y;
     425             : }
     426             : /* matrix(m, n) */
     427             : INLINE GEN
     428      103085 : zero_Flm_copy(long m, long n)
     429             : {
     430      103085 :   GEN y = cgetg(n+1,t_MAT);
     431      103093 :   long i; for (i=1; i<=n; i++) gel(y,i) = zero_Flv(m);
     432      103090 :   return y;
     433             : }
     434             : 
     435             : INLINE GEN
     436      796329 : zero_F2v(long m)
     437             : {
     438      796329 :   long l = nbits2nlong(m);
     439      796329 :   GEN v  = zero_Flv(l+1);
     440      796329 :   v[1] = m;
     441      796329 :   return v;
     442             : }
     443             : 
     444             : INLINE GEN
     445           0 : zero_F2m(long m, long n)
     446             : {
     447             :   long i;
     448           0 :   GEN M = cgetg(n+1, t_MAT);
     449           0 :   GEN v = zero_F2v(m);
     450           0 :   for (i = 1; i <= n; i++)
     451           0 :     gel(M,i) = v;
     452           0 :   return M;
     453             : }
     454             : 
     455             : 
     456             : INLINE GEN
     457      280526 : zero_F2m_copy(long m, long n)
     458             : {
     459             :   long i;
     460      280526 :   GEN M = cgetg(n+1, t_MAT);
     461      865024 :   for (i = 1; i <= n; i++)
     462      584498 :     gel(M,i)= zero_F2v(m);
     463      280526 :   return M;
     464             : }
     465             : 
     466             : /* matrix(m, n) */
     467             : INLINE GEN
     468     2248404 : zeromatcopy(long m, long n)
     469             : {
     470     2248404 :   GEN y = cgetg(n+1,t_MAT);
     471     2248404 :   long i; for (i=1; i<=n; i++) gel(y,i) = zerocol(m);
     472     2248404 :   return y;
     473             : }
     474             : 
     475             : INLINE GEN
     476       17304 : zerovec_block(long len)
     477             : {
     478             :   long i;
     479       17304 :   GEN blk = cgetg_block(len + 1, t_VEC);
     480      571032 :   for (i = 1; i <= len; ++i)
     481      553728 :     gel(blk, i) = gen_0;
     482       17304 :   return blk;
     483             : }
     484             : 
     485             : /* i-th vector in the standard basis */
     486             : INLINE GEN
     487     1265165 : col_ei(long n, long i) { GEN e = zerocol(n); gel(e,i) = gen_1; return e; }
     488             : INLINE GEN
     489      325179 : vec_ei(long n, long i) { GEN e = zerovec(n); gel(e,i) = gen_1; return e; }
     490             : INLINE GEN
     491          42 : F2v_ei(long n, long i) { GEN e = zero_F2v(n); F2v_set(e,i); return e; }
     492             : INLINE GEN
     493       68856 : vecsmall_ei(long n, long i) { GEN e = zero_zv(n); e[i] = 1; return e; }
     494             : INLINE GEN
     495     1284044 : Rg_col_ei(GEN x, long n, long i) { GEN e = zerocol(n); gel(e,i) = x; return e; }
     496             : 
     497             : INLINE GEN
     498     8902540 : shallowcopy(GEN x)
     499     8902540 : { return typ(x) == t_MAT ? RgM_shallowcopy(x): leafcopy(x); }
     500             : 
     501             : /* routines for naive growarrays */
     502             : INLINE GEN
     503    13878901 : vectrunc_init(long l)
     504             : {
     505    13878901 :   GEN z = new_chunk(l);
     506    13879294 :   z[0] = evaltyp(t_VEC) | _evallg(1); return z;
     507             : }
     508             : INLINE void
     509   272380481 : lg_increase(GEN x) { x[0]++; }
     510             : INLINE void
     511    52157034 : vectrunc_append(GEN x, GEN t) { gel(x, lg(x)) = t; lg_increase(x); }
     512             : INLINE void
     513           0 : vectrunc_append_batch(GEN x, GEN y)
     514             : {
     515           0 :   long i, l = lg(x), ly = lg(y);
     516           0 :   GEN z = x + l-1;
     517           0 :   for (i = 1; i < ly; i++) gel(z,i) = gel(y,i);
     518           0 :   setlg(x, l+ly-1);
     519           0 : }
     520             : INLINE GEN
     521    95992742 : vecsmalltrunc_init(long l)
     522             : {
     523    95992742 :   GEN z = new_chunk(l);
     524    95992742 :   z[0] = evaltyp(t_VECSMALL) | _evallg(1); return z;
     525             : }
     526             : INLINE void
     527    50538293 : vecsmalltrunc_append(GEN x, long t) { x[ lg(x) ] = t; lg_increase(x); }
     528             : 
     529             : /*******************************************************************/
     530             : /*                                                                 */
     531             : /*                        VEC / COL / VECSMALL                     */
     532             : /*                                                                 */
     533             : /*******************************************************************/
     534             : /* shallow*/
     535             : INLINE GEN
     536           0 : vec_shorten(GEN v, long n)
     537             : {
     538             :   long i;
     539           0 :   GEN V = cgetg(n+1,t_VEC);
     540           0 :   for(i=1;i<=n;i++) gel(V,i) = gel(v,i);
     541           0 :   return V;
     542             : }
     543             : /* shallow*/
     544             : INLINE GEN
     545       13314 : vec_lengthen(GEN v, long n)
     546             : {
     547             :   long i;
     548       13314 :   long l=lg(v);
     549       13314 :   GEN V = cgetg(n+1,t_VEC);
     550       13314 :   for(i=1;i<l;i++) gel(V,i) = gel(v,i);
     551       13314 :   return V;
     552             : }
     553             : /* shallow*/
     554             : INLINE GEN
     555       60956 : vec_append(GEN V, GEN s)
     556             : {
     557       60956 :   long i, l2 = lg(V);
     558       60956 :   GEN res = cgetg(l2+1, typ(V));
     559       60956 :   for (i = 1; i < l2; ++i) gel(res, i) = gel(V,i);
     560       60956 :   gel(res,l2) = s; return res;
     561             : }
     562             : /* shallow*/
     563             : INLINE GEN
     564        1764 : vec_prepend(GEN v, GEN s)
     565             : {
     566        1764 :   long i, l = lg(v);
     567        1764 :   GEN w = cgetg(l+1, typ(v));
     568        1764 :   gel(w,1) = s;
     569        1764 :   for (i = 2; i <= l; ++i) gel(w,i) = gel(v,i-1);
     570        1764 :   return w;
     571             : }
     572             : /* shallow*/
     573             : INLINE GEN
     574           0 : vec_setconst(GEN v, GEN x)
     575             : {
     576           0 :   long i, l = lg(v);
     577           0 :   for (i = 1; i < l; i++) gel(v,i) = x;
     578           0 :   return v;
     579             : }
     580             : INLINE GEN
     581      668731 : vecsmall_shorten(GEN v, long n)
     582             : {
     583             :   long i;
     584      668731 :   GEN V = cgetg(n+1,t_VECSMALL);
     585      668731 :   for(i=1;i<=n;i++) V[i] = v[i];
     586      668731 :   return V;
     587             : }
     588             : INLINE GEN
     589          21 : vecsmall_lengthen(GEN v, long n)
     590             : {
     591          21 :   long i, l = lg(v);
     592          21 :   GEN V = cgetg(n+1,t_VECSMALL);
     593          21 :   for(i=1;i<l;i++) V[i] = v[i];
     594          21 :   return V;
     595             : }
     596             : 
     597             : INLINE GEN
     598      451869 : vec_to_vecsmall(GEN x)
     599      451869 : { pari_APPLY_long(itos(gel(x,i))) }
     600             : INLINE GEN
     601      407757 : vecsmall_to_vec(GEN x)
     602      407757 : { pari_APPLY_type(t_VEC, stoi(x[i])) }
     603             : INLINE GEN
     604        1561 : vecsmall_to_vec_inplace(GEN z)
     605             : {
     606        1561 :   long i, l = lg(z);
     607        1561 :   for (i=1; i<l; i++) gel(z,i) = stoi(z[i]);
     608        1561 :   settyp(z, t_VEC); return z;
     609             : }
     610             : INLINE GEN
     611     4938322 : vecsmall_to_col(GEN x)
     612     4938322 : { pari_APPLY_type(t_COL, stoi(x[i])) }
     613             : 
     614             : INLINE int
     615     7943031 : vecsmall_lexcmp(GEN x, GEN y)
     616             : {
     617             :   long lx,ly,l,i;
     618     7943031 :   lx = lg(x);
     619     7943031 :   ly = lg(y); l = minss(lx,ly);
     620    38510497 :   for (i=1; i<l; i++)
     621    36605882 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     622     1904615 :   if (lx == ly) return 0;
     623          14 :   return (lx < ly)? -1 : 1;
     624             : }
     625             : 
     626             : INLINE int
     627    85155511 : vecsmall_prefixcmp(GEN x, GEN y)
     628             : {
     629    85155511 :   long i, lx = lg(x), ly = lg(y), l = minss(lx,ly);
     630   394027655 :   for (i=1; i<l; i++)
     631   374395014 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     632    19632641 :   return 0;
     633             : }
     634             : 
     635             : /*Can be used on t_VEC, but coeffs not gcopy-ed*/
     636             : INLINE GEN
     637       13930 : vecsmall_prepend(GEN V, long s)
     638             : {
     639       13930 :   long i, l2 = lg(V);
     640       13930 :   GEN res = cgetg(l2+1, typ(V));
     641       13930 :   res[1] = s;
     642       13930 :   for (i = 2; i <= l2; ++i) res[i] = V[i - 1];
     643       13930 :   return res;
     644             : }
     645             : 
     646             : INLINE GEN
     647     2442911 : vecsmall_append(GEN V, long s)
     648             : {
     649     2442911 :   long i, l2 = lg(V);
     650     2442911 :   GEN res = cgetg(l2+1, t_VECSMALL);
     651     2442911 :   for (i = 1; i < l2; ++i) res[i] = V[i];
     652     2442911 :   res[l2] = s; return res;
     653             : }
     654             : 
     655             : INLINE GEN
     656      749459 : vecsmall_concat(GEN u, GEN v)
     657             : {
     658      749459 :   long i, l1 = lg(u)-1, l2 = lg(v)-1;
     659      749459 :   GEN res = cgetg(l1+l2+1, t_VECSMALL);
     660      749459 :   for (i = 1; i <= l1; ++i) res[i]    = u[i];
     661      749459 :   for (i = 1; i <= l2; ++i) res[i+l1] = v[i];
     662      749459 :   return res;
     663             : }
     664             : 
     665             : /* return the number of indices where u and v are equal */
     666             : INLINE long
     667           0 : vecsmall_coincidence(GEN u, GEN v)
     668             : {
     669           0 :   long i, s = 0, l = minss(lg(u),lg(v));
     670           0 :   for(i=1; i<l; i++)
     671           0 :     if(u[i] == v[i]) s++;
     672           0 :   return s;
     673             : }
     674             : 
     675             : /* returns the first index i<=n such that x=v[i] if it exists, 0 otherwise */
     676             : INLINE long
     677           0 : vecsmall_isin(GEN v, long x)
     678             : {
     679           0 :   long i, l = lg(v);
     680           0 :   for (i = 1; i < l; i++)
     681           0 :     if (v[i] == x) return i;
     682           0 :   return 0;
     683             : }
     684             : 
     685             : INLINE long
     686          84 : vecsmall_pack(GEN V, long base, long mod)
     687             : {
     688          84 :   long i, s = 0;
     689          84 :   for(i=1; i<lg(V); i++) s = (base*s + V[i]) % mod;
     690          84 :   return s;
     691             : }
     692             : 
     693             : INLINE long
     694          14 : vecsmall_indexmax(GEN x)
     695             : {
     696          14 :   long i, i0 = 1, t = x[1], lx = lg(x);
     697          56 :   for (i=2; i<lx; i++)
     698          42 :     if (x[i] > t) t = x[i0=i];
     699          14 :   return i0;
     700             : }
     701             : 
     702             : INLINE long
     703      109793 : vecsmall_max(GEN x)
     704             : {
     705      109793 :   long i, t = x[1], lx = lg(x);
     706      355667 :   for (i=2; i<lx; i++)
     707      245874 :     if (x[i] > t) t = x[i];
     708      109793 :   return t;
     709             : }
     710             : 
     711             : INLINE long
     712          14 : vecsmall_indexmin(GEN x)
     713             : {
     714          14 :   long i, i0 = 1, t = x[1], lx =lg(x);
     715          56 :   for (i=2; i<lx; i++)
     716          42 :     if (x[i] < t) t = x[i0=i];
     717          14 :   return i0;
     718             : }
     719             : 
     720             : INLINE long
     721           0 : vecsmall_min(GEN x)
     722             : {
     723           0 :   long i, t = x[1], lx =lg(x);
     724           0 :   for (i=2; i<lx; i++)
     725           0 :     if (x[i] < t) t = x[i];
     726           0 :   return t;
     727             : }
     728             : 
     729             : INLINE int
     730     2121704 : ZV_isscalar(GEN x)
     731             : {
     732     2121704 :   long l = lg(x);
     733     7477951 :   while (--l > 1)
     734     4976670 :     if (signe(gel(x, l))) return 0;
     735      379577 :   return 1;
     736             : }
     737             : INLINE int
     738    17418009 : QV_isscalar(GEN x)
     739             : {
     740    17418009 :   long lx = lg(x),i;
     741    18888514 :   for (i=2; i<lx; i++)
     742    18360268 :     if (!isintzero(gel(x, i))) return 0;
     743      528246 :   return 1;
     744             : }
     745             : INLINE int
     746        3857 : RgV_isscalar(GEN x)
     747             : {
     748        3857 :   long lx = lg(x),i;
     749        7300 :   for (i=2; i<lx; i++)
     750        6201 :     if (!gequal0(gel(x, i))) return 0;
     751        1099 :   return 1;
     752             : }
     753             : INLINE int
     754           0 : RgX_isscalar(GEN x)
     755             : {
     756             :   long i;
     757           0 :   for (i=lg(x)-1; i>2; i--)
     758           0 :     if (!gequal0(gel(x, i))) return 0;
     759           0 :   return 1;
     760             : }
     761             : INLINE long
     762     3943971 : RgX_equal_var(GEN x, GEN y) { return varn(x) == varn(y) && RgX_equal(x,y); }
     763             : 
     764             : INLINE int
     765        5405 : RgX_is_rational(GEN x)
     766             : {
     767             :   long i;
     768       26264 :   for (i = lg(x)-1; i > 1; i--)
     769       24485 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     770        1779 :   return 1;
     771             : }
     772             : INLINE int
     773     3928305 : RgX_is_ZX(GEN x)
     774             : {
     775             :   long i;
     776    17027683 :   for (i = lg(x)-1; i > 1; i--)
     777    13114911 :     if (typ(gel(x,i)) != t_INT) return 0;
     778     3912772 :   return 1;
     779             : }
     780             : INLINE int
     781      115997 : RgX_is_QX(GEN x)
     782             : {
     783      115997 :   long k = lg(x)-1;
     784      440440 :   for ( ; k>1; k--)
     785      325381 :     if (!is_rational_t(typ(gel(x,k)))) return 0;
     786      115059 :   return 1;
     787             : }
     788             : INLINE int
     789    15557357 : RgX_is_monomial(GEN x)
     790             : {
     791             :   long i;
     792    15557357 :   if (!signe(x)) return 0;
     793    25736319 :   for (i=lg(x)-2; i>1; i--)
     794    17773332 :     if (!isexactzero(gel(x,i))) return 0;
     795     7962987 :   return 1;
     796             : }
     797             : INLINE int
     798    26780686 : RgV_is_ZV(GEN x)
     799             : {
     800             :   long i;
     801   110568832 :   for (i = lg(x)-1; i > 0; i--)
     802    83789301 :     if (typ(gel(x,i)) != t_INT) return 0;
     803    26779531 :   return 1;
     804             : }
     805             : INLINE int
     806         728 : RgV_is_QV(GEN x)
     807             : {
     808             :   long i;
     809        1127 :   for (i = lg(x)-1; i > 0; i--)
     810         994 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     811         133 :   return 1;
     812             : }
     813             : 
     814             : /********************************************************************/
     815             : /**                                                                **/
     816             : /**            Dynamic arrays implementation                       **/
     817             : /**                                                                **/
     818             : /********************************************************************/
     819             : INLINE void **
     820   433032980 : pari_stack_base(pari_stack *s) { return s->data; }
     821             : 
     822             : INLINE void
     823     1257394 : pari_stack_init(pari_stack *s, size_t size, void **data)
     824             : {
     825     1257394 :   s->data = data;
     826     1257394 :   *data = NULL;
     827     1257394 :   s->n = 0;
     828     1257394 :   s->alloc = 0;
     829     1257394 :   s->size = size;
     830     1257394 : }
     831             : 
     832             : INLINE void
     833   431866473 : pari_stack_alloc(pari_stack *s, long nb)
     834             : {
     835   431866473 :   void **sdat = pari_stack_base(s);
     836   432007970 :   long alloc = s->alloc;
     837   864017988 :   if (s->n+nb <= alloc) return;
     838      515070 :   if (!alloc)
     839      464406 :     alloc = nb;
     840             :   else
     841             :   {
     842       50664 :     while (s->n+nb > alloc) alloc <<= 1;
     843             :   }
     844      515070 :   *sdat = pari_realloc(*sdat,alloc*s->size);
     845      517118 :   s->alloc = alloc;
     846             : }
     847             : 
     848             : INLINE long
     849   354211433 : pari_stack_new(pari_stack *s) { pari_stack_alloc(s, 1); return s->n++; }
     850             : 
     851             : INLINE void
     852     1087470 : pari_stack_delete(pari_stack *s)
     853             : {
     854     1087470 :   void **sdat = pari_stack_base(s);
     855     1086931 :   if (*sdat) pari_free(*sdat);
     856     1087378 : }
     857             : 
     858             : INLINE void
     859        4839 : pari_stack_pushp(pari_stack *s, void *u)
     860             : {
     861        4839 :   long n = pari_stack_new(s);
     862        4839 :   void **sdat =(void**) *pari_stack_base(s);
     863        4839 :   sdat[n] = u;
     864        4839 : }
     865             : 
     866             : /*******************************************************************/
     867             : /*                                                                 */
     868             : /*                            EXTRACT                              */
     869             : /*                                                                 */
     870             : /*******************************************************************/
     871             : INLINE GEN
     872   159783998 : vecslice(GEN A, long y1, long y2)
     873             : {
     874   159783998 :   long i,lB = y2 - y1 + 2;
     875   159783998 :   GEN B = cgetg(lB, typ(A));
     876   159787107 :   for (i=1; i<lB; i++) B[i] = A[y1-1+i];
     877   159787107 :   return B;
     878             : }
     879             : INLINE GEN
     880      711141 : vecslicepermute(GEN A, GEN p, long y1, long y2)
     881             : {
     882      711141 :   long i,lB = y2 - y1 + 2;
     883      711141 :   GEN B = cgetg(lB, typ(A));
     884      711146 :   for (i=1; i<lB; i++) B[i] = A[p[y1-1+i]];
     885      711146 :   return B;
     886             : }
     887             : /* rowslice(rowpermute(A,p), x1, x2) */
     888             : INLINE GEN
     889       35078 : rowslicepermute(GEN x, GEN p, long j1, long j2)
     890       35078 : { pari_APPLY_same(vecslicepermute(gel(x,i),p,j1,j2)) }
     891             : 
     892             : INLINE GEN
     893    19591026 : rowslice(GEN x, long j1, long j2)
     894    19591026 : { pari_APPLY_same(vecslice(gel(x,i), j1, j2)) }
     895             : 
     896             : INLINE GEN
     897     3250126 : matslice(GEN A, long x1, long x2, long y1, long y2)
     898     3250126 : { return rowslice(vecslice(A, y1, y2), x1, x2); }
     899             : 
     900             : /* shallow, remove coeff of index j */
     901             : INLINE GEN
     902         133 : rowsplice(GEN x, long j)
     903         133 : { pari_APPLY_same(vecsplice(gel(x,i), j)) }
     904             : 
     905             : /* shallow, remove coeff of index j */
     906             : INLINE GEN
     907      249732 : vecsplice(GEN a, long j)
     908             : {
     909      249732 :   long i, k, l = lg(a);
     910             :   GEN b;
     911      249732 :   if (l == 1) pari_err(e_MISC, "incorrect component in vecsplice");
     912      249732 :   b = cgetg(l-1, typ(a));
     913      996653 :   for (i = k = 1; i < l; i++)
     914      746921 :     if (i != j) gel(b, k++) = gel(a,i);
     915      249732 :   return b;
     916             : }
     917             : /* shallow */
     918             : INLINE GEN
     919         637 : RgM_minor(GEN a, long i, long j)
     920             : {
     921         637 :   GEN b = vecsplice(a, j);
     922         637 :   long k, l = lg(b);
     923         637 :   for (k = 1; k < l; k++) gel(b,k) = vecsplice(gel(b,k), i);
     924         637 :   return b;
     925             : }
     926             : 
     927             : /* A[x0,] */
     928             : INLINE GEN
     929      178468 : row(GEN x, long j)
     930      178468 : { pari_APPLY_type(t_VEC, gcoeff(x, j, i)) }
     931             : INLINE GEN
     932     2856238 : Flm_row(GEN x, long j)
     933     2856238 : { pari_APPLY_ulong((ulong)coeff(x, j, i)) }
     934             : /* A[x0,] */
     935             : INLINE GEN
     936          63 : rowcopy(GEN x, long j)
     937          63 : { pari_APPLY_type(t_VEC, gcopy(gcoeff(x, j, i))) }
     938             : /* A[x0, x1..x2] */
     939             : INLINE GEN
     940        2177 : row_i(GEN A, long x0, long x1, long x2)
     941             : {
     942        2177 :   long i, lB = x2 - x1 + 2;
     943        2177 :   GEN B  = cgetg(lB, t_VEC);
     944        2177 :   for (i=x1; i<=x2; i++) gel(B, i) = gcoeff(A, x0, i);
     945        2177 :   return B;
     946             : }
     947             : 
     948             : INLINE GEN
     949     5786495 : vecreverse(GEN A)
     950             : {
     951             :   long i, l;
     952     5786495 :   GEN B = cgetg_copy(A, &l);
     953     5786495 :   for (i=1; i<l; i++) gel(B, i) = gel(A, l-i);
     954     5786495 :   return B;
     955             : }
     956             : 
     957             : INLINE GEN
     958         252 : vecsmall_reverse(GEN A)
     959             : {
     960             :   long i, l;
     961         252 :   GEN B = cgetg_copy(A, &l);
     962         252 :   for (i=1; i<l; i++) B[i] = A[l-i];
     963         252 :   return B;
     964             : }
     965             : 
     966             : INLINE void
     967         260 : vecreverse_inplace(GEN y)
     968             : {
     969         260 :   long l = lg(y), lim = l>>1, i;
     970         724 :   for (i = 1; i <= lim; i++)
     971             :   {
     972         464 :     GEN z = gel(y,i);
     973         464 :     gel(y,i)    = gel(y,l-i);
     974         464 :     gel(y,l-i) = z;
     975             :   }
     976         260 : }
     977             : 
     978             : INLINE GEN
     979    41811751 : vecsmallpermute(GEN A, GEN p) { return perm_mul(A, p); }
     980             : 
     981             : INLINE GEN
     982     6000726 : vecpermute(GEN A, GEN x)
     983     6000726 : { pari_APPLY_type(typ(A), gel(A, x[i])) }
     984             : 
     985             : INLINE GEN
     986     2719588 : rowpermute(GEN x, GEN p)
     987     2719588 : { pari_APPLY_same(typ(gel(x,i)) == t_VECSMALL ? vecsmallpermute(gel(x, i), p)
     988             :                                               : vecpermute(gel(x, i), p))
     989             : }
     990             : /*******************************************************************/
     991             : /*                                                                 */
     992             : /*                          PERMUTATIONS                           */
     993             : /*                                                                 */
     994             : /*******************************************************************/
     995             : /* identity permutation */
     996             : INLINE GEN
     997      652435 : identity_perm(long n)
     998             : {
     999      652435 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1000             :   long i;
    1001      652434 :   for (i = 1; i <= n; i++) perm[i] = i;
    1002      652434 :   return perm;
    1003             : }
    1004             : 
    1005             : /* assume d <= n */
    1006             : INLINE GEN
    1007       98399 : cyclic_perm(long n, long d)
    1008             : {
    1009       98399 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1010             :   long i;
    1011       98399 :   for (i = 1; i <= n-d; i++) perm[i] = i+d;
    1012       98399 :   for (     ; i <= n;   i++) perm[i] = i-n+d;
    1013       98399 :   return perm;
    1014             : }
    1015             : 
    1016             : /* Multiply (compose) two permutations */
    1017             : INLINE GEN
    1018    43018025 : perm_mul(GEN s, GEN x)
    1019    43018025 : { pari_APPLY_long(s[x[i]]) }
    1020             : 
    1021             : /* Compute the inverse (reciprocal) of a permutation. */
    1022             : INLINE GEN
    1023     1317146 : perm_inv(GEN x)
    1024             : {
    1025             :   long i, lx;
    1026     1317146 :   GEN y = cgetg_copy(x, &lx);
    1027     1317145 :   for (i=1; i<lx; i++) y[ x[i] ] = i;
    1028     1317145 :   return y;
    1029             : }
    1030             : /* Return s*t*s^-1 */
    1031             : INLINE GEN
    1032      402990 : perm_conj(GEN s, GEN t)
    1033             : {
    1034             :   long i, l;
    1035      402990 :   GEN v = cgetg_copy(s, &l);
    1036      402990 :   for (i = 1; i < l; i++) v[ s[i] ] = s[ t[i] ];
    1037      402990 :   return v;
    1038             : }
    1039             : 
    1040             : /*********************************************************************/
    1041             : /*                       MALLOC/FREE WRAPPERS                        */
    1042             : /*********************************************************************/
    1043             : #define BLOCK_SIGALRM_START          \
    1044             : {                                    \
    1045             :   int block=PARI_SIGINT_block;       \
    1046             :   PARI_SIGINT_block = 2;             \
    1047             :   MT_SIGINT_BLOCK(block);
    1048             : 
    1049             : #define BLOCK_SIGINT_START           \
    1050             : {                                    \
    1051             :   int block=PARI_SIGINT_block;       \
    1052             :   PARI_SIGINT_block = 1;             \
    1053             :   MT_SIGINT_BLOCK(block);
    1054             : 
    1055             : #define BLOCK_SIGINT_END             \
    1056             :   PARI_SIGINT_block = block;         \
    1057             :   MT_SIGINT_UNBLOCK(block);          \
    1058             :   if (!block && PARI_SIGINT_pending) \
    1059             :   {                                  \
    1060             :     int sig = PARI_SIGINT_pending;   \
    1061             :     PARI_SIGINT_pending = 0;         \
    1062             :     raise(sig);                      \
    1063             :   }                                  \
    1064             : }
    1065             : 
    1066             : INLINE void
    1067    62432392 : pari_free(void *pointer)
    1068             : {
    1069    62432392 :   BLOCK_SIGINT_START;
    1070    62434233 :   free(pointer);
    1071    62434233 :   BLOCK_SIGINT_END;
    1072    62433667 : }
    1073             : INLINE void*
    1074   271054912 : pari_malloc(size_t size)
    1075             : {
    1076   271054912 :   if (size)
    1077             :   {
    1078             :     char *tmp;
    1079   271054912 :     BLOCK_SIGINT_START;
    1080   271059682 :     tmp = (char*)malloc(size);
    1081   271059682 :     BLOCK_SIGINT_END;
    1082   271059188 :     if (!tmp) pari_err(e_MEM);
    1083   271059188 :     return tmp;
    1084             :   }
    1085           0 :   return NULL;
    1086             : }
    1087             : INLINE void*
    1088      526874 : pari_realloc(void *pointer, size_t size)
    1089             : {
    1090             :   char *tmp;
    1091             : 
    1092      526874 :   BLOCK_SIGINT_START;
    1093      529991 :   if (!pointer) tmp = (char *) malloc(size);
    1094       54374 :   else tmp = (char *) realloc(pointer,size);
    1095      529991 :   BLOCK_SIGINT_END;
    1096      528866 :   if (!tmp) pari_err(e_MEM);
    1097      528866 :   return tmp;
    1098             : }
    1099             : INLINE void*
    1100       34738 : pari_calloc(size_t size)
    1101             : {
    1102       34738 :   void *t = pari_malloc(size);
    1103       34738 :   memset(t, 0, size); return t;
    1104             : }
    1105             : INLINE GEN
    1106        5750 : cgetalloc(long t, size_t l)
    1107             : {
    1108        5750 :   GEN x = (GEN)pari_malloc(l * sizeof(long));
    1109        5750 :   x[0] = evaltyp(t) | evallg(l); return x;
    1110             : }
    1111             : 
    1112             : /*******************************************************************/
    1113             : /*                                                                 */
    1114             : /*                       GARBAGE COLLECTION                        */
    1115             : /*                                                                 */
    1116             : /*******************************************************************/
    1117             : /* copy integer x as if we had avma = av */
    1118             : INLINE GEN
    1119  3619303026 : icopy_avma(GEN x, pari_sp av)
    1120             : {
    1121  3619303026 :   long i = lgefint(x), lx = i;
    1122  3619303026 :   GEN y = ((GEN)av) - i;
    1123  3619303026 :   while (--i > 0) y[i] = x[i];
    1124  3619303026 :   y[0] = evaltyp(t_INT)|evallg(lx);
    1125  3618992204 :   return y;
    1126             : }
    1127             : /* copy leaf x as if we had avma = av */
    1128             : INLINE GEN
    1129   161645608 : leafcopy_avma(GEN x, pari_sp av)
    1130             : {
    1131   161645608 :   long i = lg(x);
    1132   161645608 :   GEN y = ((GEN)av) - i;
    1133   161645608 :   while (--i > 0) y[i] = x[i];
    1134   161645608 :   y[0] = x[0] & (~CLONEBIT);
    1135   161645608 :   return y;
    1136             : }
    1137             : INLINE GEN
    1138   629911318 : gerepileuptoleaf(pari_sp av, GEN x)
    1139             : {
    1140             :   long lx;
    1141             :   GEN q;
    1142             : 
    1143   629911318 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1144   631402442 :   lx = lg(x);
    1145   631402442 :   q = ((GEN)av) - lx;
    1146   631402442 :   avma = (pari_sp)q;
    1147   631402442 :   while (--lx >= 0) q[lx] = x[lx];
    1148   631402442 :   return q;
    1149             : }
    1150             : INLINE GEN
    1151  1143144402 : gerepileuptoint(pari_sp av, GEN x)
    1152             : {
    1153  1143144402 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1154  1014043664 :   avma = (pari_sp)icopy_avma(x, av);
    1155  1014829519 :   return (GEN)avma;
    1156             : }
    1157             : INLINE GEN
    1158   727405916 : gerepileupto(pari_sp av, GEN x)
    1159             : {
    1160   727405916 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1161   635716723 :   switch(typ(x))
    1162             :   { /* non-default = !is_recursive_t(tq) */
    1163   215606570 :     case t_INT: return gerepileuptoint(av, x);
    1164             :     case t_REAL:
    1165             :     case t_STR:
    1166   133146922 :     case t_VECSMALL: return gerepileuptoleaf(av,x);
    1167             :     default:
    1168             :       /* NB: x+i --> ((long)x) + i*sizeof(long) */
    1169   286963231 :       return gerepile(av, (pari_sp) (x+lg(x)), x);
    1170             :   }
    1171             : }
    1172             : 
    1173             : /* gerepileupto(av, gcopy(x)) */
    1174             : INLINE GEN
    1175    43690095 : gerepilecopy(pari_sp av, GEN x)
    1176             : {
    1177    43690095 :   if (is_recursive_t(typ(x)))
    1178             :   {
    1179    39343210 :     GENbin *p = copy_bin(x);
    1180    39343232 :     avma = av; return bin_copy(p);
    1181             :   }
    1182             :   else
    1183             :   {
    1184     4346891 :     avma = av;
    1185     4346891 :     if (x < (GEN)av) {
    1186     2870318 :       if (x < (GEN)pari_mainstack->bot) new_chunk(lg(x));
    1187     2870318 :       x = leafcopy_avma(x, av);
    1188     2870328 :       avma = (pari_sp)x;
    1189             :     } else
    1190     1476573 :       x = leafcopy(x);
    1191     4346903 :     return x;
    1192             :   }
    1193             : }
    1194             : 
    1195             : /* Takes an array of pointers to GENs, of length n. Copies all
    1196             :  * objects to contiguous locations and cleans up the stack between
    1197             :  * av and avma. */
    1198             : INLINE void
    1199      134000 : gerepilemany(pari_sp av, GEN* gptr[], int n)
    1200             : {
    1201             :   int i;
    1202      134000 :   for (i=0; i<n; i++) *gptr[i] = (GEN)copy_bin(*gptr[i]);
    1203      134000 :   avma = av;
    1204      134000 :   for (i=0; i<n; i++) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1205      134000 : }
    1206             : 
    1207             : INLINE void
    1208     7562360 : gerepileall(pari_sp av, int n, ...)
    1209             : {
    1210             :   int i;
    1211     7562360 :   va_list a; va_start(a, n);
    1212     7562360 :   if (n < 10)
    1213             :   {
    1214             :     GEN *gptr[10];
    1215    21671719 :     for (i=0; i<n; i++)
    1216    14109403 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1217     7562316 :     avma = av;
    1218     7562316 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1219             : 
    1220             :   }
    1221             :   else
    1222             :   {
    1223           0 :     GEN **gptr = (GEN**)  pari_malloc(n*sizeof(GEN*));
    1224           0 :     for (i=0; i<n; i++)
    1225           0 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1226           0 :     avma = av;
    1227           0 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1228           0 :     pari_free(gptr);
    1229             :   }
    1230     7562283 :   va_end(a);
    1231     7562283 : }
    1232             : 
    1233             : INLINE void
    1234           8 : gerepilecoeffs(pari_sp av, GEN x, int n)
    1235             : {
    1236             :   int i;
    1237           8 :   for (i=0; i<n; i++) gel(x,i) = (GEN)copy_bin(gel(x,i));
    1238           8 :   avma = av;
    1239           8 :   for (i=0; i<n; i++) gel(x,i) = bin_copy((GENbin*)x[i]);
    1240           8 : }
    1241             : 
    1242             : /* p from copy_bin. Copy p->x back to stack, then destroy p */
    1243             : INLINE GEN
    1244    53870842 : bin_copy(GENbin *p)
    1245             : {
    1246             :   GEN x, y, base;
    1247             :   long dx, len;
    1248             : 
    1249    53870842 :   x   = p->x; if (!x) { pari_free(p); return gen_0; }
    1250    53864659 :   len = p->len;
    1251    53864659 :   base= p->base; dx = x - base;
    1252    53864659 :   y = (GEN)memcpy((void*)new_chunk(len), (void*)GENbinbase(p), len*sizeof(long));
    1253    53864627 :   y += dx;
    1254    53864627 :   p->rebase(y, ((ulong)y-(ulong)x));
    1255    53864596 :   pari_free(p); return y;
    1256             : }
    1257             : 
    1258             : INLINE GEN
    1259   107735573 : GENbinbase(GENbin *p) { return (GEN)(p + 1); }
    1260             : 
    1261             : INLINE void
    1262    27248440 : cgiv(GEN x)
    1263             : {
    1264    27248440 :   pari_sp av = (pari_sp)(x+lg(x));
    1265    27248440 :   if (isonstack((GEN)av)) avma = av;
    1266    27248323 : }
    1267             : 
    1268             : INLINE void
    1269     1212388 : killblock(GEN x) { gunclone(x); }
    1270             : 
    1271             : INLINE int
    1272    23794025 : is_universal_constant(GEN x) { return (x >= gen_0 && x <= ghalf); }
    1273             : 
    1274             : /*******************************************************************/
    1275             : /*                                                                 */
    1276             : /*                    CONVERSION / ASSIGNMENT                      */
    1277             : /*                                                                 */
    1278             : /*******************************************************************/
    1279             : /* z is a type which may be a t_COMPLEX component (not a t_QUAD) */
    1280             : INLINE GEN
    1281     3074809 : cxcompotor(GEN z, long prec)
    1282             : {
    1283     3074809 :   switch(typ(z))
    1284             :   {
    1285     1727437 :     case t_INT:  return itor(z, prec);
    1286      134134 :     case t_FRAC: return fractor(z, prec);
    1287     1213238 :     case t_REAL: return rtor(z, prec);
    1288           0 :     default: pari_err_TYPE("cxcompotor",z);
    1289             :              return NULL; /* LCOV_EXCL_LINE */
    1290             :   }
    1291             : }
    1292             : INLINE GEN
    1293     1524117 : cxtofp(GEN x, long prec)
    1294     1524117 : { retmkcomplex(cxcompotor(gel(x,1),prec), cxcompotor(gel(x,2),prec)); }
    1295             : 
    1296             : INLINE double
    1297    18828313 : gtodouble(GEN x)
    1298             : {
    1299    18828313 :   if (typ(x)!=t_REAL) {
    1300     3515323 :     pari_sp av = avma;
    1301     3515323 :     x = gtofp(x, DEFAULTPREC);
    1302     3515323 :     if (typ(x)!=t_REAL) pari_err_TYPE("gtodouble [t_REAL expected]", x);
    1303     3515323 :     avma = av;
    1304             :   }
    1305    18828313 :   return rtodbl(x);
    1306             : }
    1307             : INLINE long
    1308    68180195 : gtos(GEN x) {
    1309    68180195 :   if (typ(x) != t_INT) pari_err_TYPE("gtos [integer expected]",x);
    1310    68180188 :   return itos(x);
    1311             : }
    1312             : 
    1313             : INLINE ulong
    1314      121563 : gtou(GEN x) {
    1315      121563 :   if (typ(x) != t_INT || signe(x)<0)
    1316           0 :     pari_err_TYPE("gtou [integer >=0 expected]",x);
    1317      121998 :   return itou(x);
    1318             : }
    1319             : 
    1320             : INLINE GEN
    1321    20498527 : absfrac(GEN x)
    1322             : {
    1323    20498527 :   GEN y = cgetg(3, t_FRAC);
    1324    20498527 :   gel(y,1) = absi(gel(x,1));
    1325    20498527 :   gel(y,2) = icopy(gel(x,2)); return y;
    1326             : }
    1327             : INLINE GEN
    1328       32686 : absfrac_shallow(GEN x)
    1329       32686 : { return signe(gel(x,1))>0? x: mkfrac(negi(gel(x,1)), gel(x,2)); }
    1330             : INLINE GEN
    1331     7111008 : Q_abs(GEN x) { return (typ(x) == t_INT)? absi(x): absfrac(x); }
    1332             : INLINE GEN
    1333      107112 : Q_abs_shallow(GEN x)
    1334      107112 : { return (typ(x) == t_INT)? absi_shallow(x): absfrac_shallow(x); }
    1335             : INLINE GEN
    1336         322 : R_abs_shallow(GEN x)
    1337         322 : { return (typ(x) == t_FRAC)? absfrac_shallow(x): mpabs_shallow(x); }
    1338             : INLINE GEN
    1339           0 : R_abs(GEN x)
    1340           0 : { return (typ(x) == t_FRAC)? absfrac(x): mpabs(x); }
    1341             : 
    1342             : /* Force z to be of type real/complex with floating point components */
    1343             : INLINE GEN
    1344    27672451 : gtofp(GEN z, long prec)
    1345             : {
    1346    27672451 :   switch(typ(z))
    1347             :   {
    1348    17190700 :     case t_INT:  return itor(z, prec);
    1349     4262718 :     case t_FRAC: return fractor(z, prec);
    1350     4891526 :     case t_REAL: return rtor(z, prec);
    1351             :     case t_COMPLEX: {
    1352     1327507 :       GEN a = gel(z,1), b = gel(z,2);
    1353     1327507 :       if (isintzero(b)) return cxcompotor(a, prec);
    1354     1325167 :       if (isintzero(a)) {
    1355        2055 :         GEN y = cgetg(3, t_COMPLEX);
    1356        2055 :         b = cxcompotor(b, prec);
    1357        2055 :         gel(y,1) = real_0_bit(expo(b) - prec2nbits(prec));
    1358        2055 :         gel(y,2) = b; return y;
    1359             :       }
    1360     1323112 :       return cxtofp(z, prec);
    1361             :     }
    1362           0 :     case t_QUAD: return quadtofp(z, prec);
    1363           0 :     default: pari_err_TYPE("gtofp",z);
    1364             :              return NULL; /* LCOV_EXCL_LINE */
    1365             :   }
    1366             : }
    1367             : /* Force z to be of type real / int */
    1368             : INLINE GEN
    1369       22400 : gtomp(GEN z, long prec)
    1370             : {
    1371       22400 :   switch(typ(z))
    1372             :   {
    1373          14 :     case t_INT:  return z;
    1374       22386 :     case t_FRAC: return fractor(z, prec);
    1375           0 :     case t_REAL: return rtor(z, prec);
    1376           0 :     case t_QUAD: z = quadtofp(z, prec);
    1377           0 :                  if (typ(z) == t_REAL) return z;
    1378           0 :     default: pari_err_TYPE("gtomp",z);
    1379             :              return NULL; /* LCOV_EXCL_LINE */
    1380             :   }
    1381             : }
    1382             : 
    1383             : INLINE GEN
    1384      724244 : RgX_gtofp(GEN x, long prec)
    1385             : {
    1386             :   long l;
    1387      724244 :   GEN y = cgetg_copy(x, &l);
    1388      724244 :   while (--l > 1) gel(y,l) = gtofp(gel(x,l), prec);
    1389      724244 :   y[1] = x[1]; return y;
    1390             : }
    1391             : INLINE GEN
    1392     1149251 : RgC_gtofp(GEN x, long prec)
    1393     1149251 : { pari_APPLY_type(t_COL, gtofp(gel(x,i), prec)) }
    1394             : 
    1395             : INLINE GEN
    1396          42 : RgV_gtofp(GEN x, long prec)
    1397          42 : { pari_APPLY_type(t_VEC, gtofp(gel(x,i), prec)) }
    1398             : 
    1399             : INLINE GEN
    1400      129970 : RgM_gtofp(GEN x, long prec)
    1401      129970 : { pari_APPLY_same(RgC_gtofp(gel(x,i), prec)) }
    1402             : 
    1403             : INLINE GEN
    1404         560 : RgC_gtomp(GEN x, long prec)
    1405         560 : { pari_APPLY_type(t_COL, gtomp(gel(x,i), prec)) }
    1406             : 
    1407             : INLINE GEN
    1408          14 : RgM_gtomp(GEN x, long prec)
    1409          14 : { pari_APPLY_same(RgC_gtomp(gel(x,i), prec)) }
    1410             : 
    1411             : INLINE GEN
    1412        8772 : RgX_fpnorml2(GEN x, long prec)
    1413             : {
    1414        8772 :   pari_sp av = avma;
    1415        8772 :   return gerepileupto(av, gnorml2(RgX_gtofp(x, prec)));
    1416             : }
    1417             : INLINE GEN
    1418      200698 : RgC_fpnorml2(GEN x, long prec)
    1419             : {
    1420      200698 :   pari_sp av = avma;
    1421      200698 :   return gerepileupto(av, gnorml2(RgC_gtofp(x, prec)));
    1422             : }
    1423             : INLINE GEN
    1424        3635 : RgM_fpnorml2(GEN x, long prec)
    1425             : {
    1426        3635 :   pari_sp av = avma;
    1427        3635 :   return gerepileupto(av, gnorml2(RgM_gtofp(x, prec)));
    1428             : }
    1429             : 
    1430             : /* y a t_REAL */
    1431             : INLINE void
    1432      190202 : affgr(GEN x, GEN y)
    1433             : {
    1434             :   pari_sp av;
    1435      190202 :   switch(typ(x)) {
    1436        5992 :     case t_INT:  affir(x,y); break;
    1437      184210 :     case t_REAL: affrr(x,y); break;
    1438           0 :     case t_FRAC: rdiviiz(gel(x,1),gel(x,2), y); break;
    1439           0 :     case t_QUAD: av = avma; affgr(quadtofp(x,realprec(y)), y); avma = av; break;
    1440           0 :     default: pari_err_TYPE2("=",x,y);
    1441             :   }
    1442      190202 : }
    1443             : 
    1444             : INLINE GEN
    1445      186751 : affc_fixlg(GEN x, GEN res)
    1446             : {
    1447      186751 :   if (typ(x) == t_COMPLEX)
    1448             :   {
    1449      175658 :     affrr_fixlg(gel(x,1), gel(res,1));
    1450      175658 :     affrr_fixlg(gel(x,2), gel(res,2));
    1451             :   }
    1452             :   else
    1453             :   {
    1454       11093 :     avma = (pari_sp)(res+3);
    1455       11093 :     res = cgetr(realprec(gel(res,1)));
    1456       11093 :     affrr_fixlg(x, res);
    1457             :   }
    1458      186751 :   return res;
    1459             : }
    1460             : 
    1461             : INLINE GEN
    1462           0 : trunc_safe(GEN x) { long e; return gcvtoi(x,&e); }
    1463             : 
    1464             : /*******************************************************************/
    1465             : /*                                                                 */
    1466             : /*                          LENGTH CONVERSIONS                     */
    1467             : /*                                                                 */
    1468             : /*******************************************************************/
    1469             : INLINE long
    1470       27287 : ndec2nlong(long x) { return 1 + (long)((x)*(LOG2_10/BITS_IN_LONG)); }
    1471             : INLINE long
    1472       26804 : ndec2prec(long x) { return 2 + ndec2nlong(x); }
    1473             : INLINE long
    1474         483 : ndec2nbits(long x) { return ndec2nlong(x) << TWOPOTBITS_IN_LONG; }
    1475             : /* Fast implementation of ceil(x / (8*sizeof(long))); typecast to (ulong)
    1476             :  * to avoid overflow. Faster than 1 + ((x-1)>>TWOPOTBITS_IN_LONG)) :
    1477             :  *   addl, shrl instead of subl, sarl, addl */
    1478             : INLINE long
    1479     1191718 : nbits2nlong(long x) {
    1480     1191718 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1481             : }
    1482             : 
    1483             : INLINE long
    1484   248456008 : nbits2extraprec(long x) {
    1485   248456008 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1486             : }
    1487             : 
    1488             : /* Fast implementation of 2 + nbits2nlong(x) */
    1489             : INLINE long
    1490    87911392 : nbits2prec(long x) {
    1491    87911392 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1492             : }
    1493             : INLINE long
    1494     6811059 : nbits2lg(long x) {
    1495     6811059 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1496             : }
    1497             : /* ceil(x / sizeof(long)) */
    1498             : INLINE long
    1499     9072169 : nchar2nlong(long x) {
    1500     9072169 :   return (long)(((ulong)x+sizeof(long)-1) >> (TWOPOTBITS_IN_LONG-3L));
    1501             : }
    1502             : INLINE long
    1503  1105122324 : prec2nbits(long x) { return (x-2) * BITS_IN_LONG; }
    1504             : INLINE double
    1505      582362 : bit_accuracy_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1506             : INLINE double
    1507      233231 : prec2nbits_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1508             : INLINE long
    1509    27815582 : bit_prec(GEN x) { return prec2nbits(realprec(x)); }
    1510             : INLINE long
    1511  1011545754 : bit_accuracy(long x) { return prec2nbits(x); }
    1512             : INLINE long
    1513       12239 : prec2ndec(long x) { return (long)prec2nbits_mul(x, LOG10_2); }
    1514             : INLINE long
    1515         186 : nbits2ndec(long x) { return (long)(x * LOG10_2); }
    1516             : INLINE long
    1517        1875 : precdbl(long x) {return (x - 1) << 1;}
    1518             : INLINE long
    1519  3153811616 : divsBIL(long n) { return n >> TWOPOTBITS_IN_LONG; }
    1520             : INLINE long
    1521  3116996147 : remsBIL(long n) { return n & (BITS_IN_LONG-1); }
    1522             : 
    1523             : /*********************************************************************/
    1524             : /**                                                                 **/
    1525             : /**                      OPERATIONS MODULO m                        **/
    1526             : /**                                                                 **/
    1527             : /*********************************************************************/
    1528             : /* Assume m > 0, more efficient if 0 <= a, b < m */
    1529             : 
    1530             : INLINE GEN
    1531    85835289 : Fp_red(GEN a, GEN m) { return modii(a, m); }
    1532             : INLINE GEN
    1533    80271860 : Fp_add(GEN a, GEN b, GEN m)
    1534             : {
    1535    80271860 :   pari_sp av=avma;
    1536    80271860 :   GEN p = addii(a,b);
    1537    80263043 :   long s = signe(p);
    1538    80263043 :   if (!s) return p; /* = gen_0 */
    1539    73247434 :   if (s > 0) /* general case */
    1540             :   {
    1541    73022701 :     GEN t = subii(p, m);
    1542    73099952 :     s = signe(t);
    1543    73099952 :     if (!s) { avma = av; return gen_0; }
    1544    67511811 :     if (s < 0) { avma = (pari_sp)p; return p; }
    1545    29613242 :     if (cmpii(t, m) < 0) return gerepileuptoint(av, t); /* general case ! */
    1546     1106324 :     p = remii(t, m);
    1547             :   }
    1548             :   else
    1549      224733 :     p = modii(p, m);
    1550     1331057 :   return gerepileuptoint(av, p);
    1551             : }
    1552             : INLINE GEN
    1553    70193959 : Fp_sub(GEN a, GEN b, GEN m)
    1554             : {
    1555    70193959 :   pari_sp av=avma;
    1556    70193959 :   GEN p = subii(a,b);
    1557    70428793 :   long s = signe(p);
    1558    70428793 :   if (!s) return p; /* = gen_0 */
    1559    66026360 :   if (s > 0)
    1560             :   {
    1561    31848050 :     if (cmpii(p, m) < 0) return p; /* general case ! */
    1562     1273484 :     p = remii(p, m);
    1563             :   }
    1564             :   else
    1565             :   {
    1566    34178310 :     GEN t = addii(p, m);
    1567    34153968 :     if (!s) { avma = av; return gen_0; }
    1568    34153968 :     if (s > 0) return gerepileuptoint(av, t); /* general case ! */
    1569    34153968 :     p = modii(t, m);
    1570             :   }
    1571    35452460 :   return gerepileuptoint(av, p);
    1572             : }
    1573             : INLINE GEN
    1574    12576572 : Fp_neg(GEN b, GEN m)
    1575             : {
    1576    12576572 :   pari_sp av = avma;
    1577    12576572 :   long s = signe(b);
    1578             :   GEN p;
    1579    12576572 :   if (!s) return gen_0;
    1580     9155795 :   if (s > 0)
    1581             :   {
    1582     8954256 :     p = subii(m, b);
    1583     8953964 :     if (signe(p) >= 0) return p; /* general case ! */
    1584       92603 :     p = modii(p, m);
    1585             :   } else
    1586      201539 :     p = remii(negi(b), m);
    1587      294142 :   return gerepileuptoint(av, p);
    1588             : }
    1589             : 
    1590             : INLINE GEN
    1591       21329 : Fp_halve(GEN a, GEN p)
    1592             : {
    1593       21329 :   if (mpodd(a)) a = addii(a,p);
    1594       21329 :   return shifti(a,-1);
    1595             : }
    1596             : 
    1597             : /* assume 0 <= u < p and ps2 = p>>1 */
    1598             : INLINE GEN
    1599    27958291 : Fp_center(GEN u, GEN p, GEN ps2)
    1600    27958291 : { return abscmpii(u,ps2)<=0? icopy(u): subii(u,p); }
    1601             : 
    1602             : /* x + y*z mod p */
    1603             : INLINE GEN
    1604     7422287 : Fp_addmul(GEN x, GEN y, GEN z, GEN p)
    1605             : {
    1606             :   pari_sp av;
    1607     7422287 :   if (!signe(y) || !signe(z)) return Fp_red(x, p);
    1608     7062895 :   if (!signe(x)) return Fp_mul(z,y, p);
    1609     6761456 :   av = avma;
    1610     6761456 :   return gerepileuptoint(av, modii(addii(x, mulii(y,z)), p));
    1611             : }
    1612             : 
    1613             : INLINE GEN
    1614    89719787 : Fp_mul(GEN a, GEN b, GEN m)
    1615             : {
    1616    89719787 :   pari_sp av=avma;
    1617             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1618    89719787 :   (void)new_chunk(lg(a)+lg(b)+(lg(m)<<1));
    1619    89731736 :   p = mulii(a,b);
    1620    89733404 :   avma = av; return modii(p,m);
    1621             : }
    1622             : INLINE GEN
    1623    56704930 : Fp_sqr(GEN a, GEN m)
    1624             : {
    1625    56704930 :   pari_sp av=avma;
    1626             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1627    56704930 :   (void)new_chunk((lg(a)+lg(m))<<1);
    1628    56930181 :   p = sqri(a);
    1629    57071651 :   avma = av; return remii(p,m); /*Use remii: p >= 0 */
    1630             : }
    1631             : INLINE GEN
    1632    78655584 : Fp_mulu(GEN a, ulong b, GEN m)
    1633             : {
    1634    78655584 :   long l = lgefint(m);
    1635    78655584 :   if (l == 3)
    1636             :   {
    1637    43527639 :     ulong mm = m[2];
    1638    43527639 :     return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1639             :   } else {
    1640    35127945 :     pari_sp av = avma;
    1641             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1642    35127945 :     (void)new_chunk(lg(a)+1+(l<<1));
    1643    35204632 :     p = muliu(a,b);
    1644    34848002 :     avma = av; return modii(p,m);
    1645             :   }
    1646             : }
    1647             : INLINE GEN
    1648           0 : Fp_muls(GEN a, long b, GEN m)
    1649             : {
    1650           0 :   long l = lgefint(m);
    1651           0 :   if (l == 3)
    1652             :   {
    1653           0 :     ulong mm = m[2];
    1654           0 :     if (b < 0)
    1655             :     {
    1656           0 :       ulong t = Fl_mul(umodiu(a, mm), -b, mm);
    1657           0 :       return t? utoipos(mm - t): gen_0;
    1658             :     }
    1659             :     else
    1660           0 :       return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1661             :   } else {
    1662           0 :     pari_sp av = avma;
    1663             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1664           0 :     (void)new_chunk(lg(a)+1+(l<<1));
    1665           0 :     p = mulis(a,b);
    1666           0 :     avma = av; return modii(p,m);
    1667             :   }
    1668             : }
    1669             : 
    1670             : INLINE GEN
    1671     8488668 : Fp_inv(GEN a, GEN m)
    1672             : {
    1673             :   GEN res;
    1674     8488668 :   if (! invmod(a,m,&res)) pari_err_INV("Fp_inv", mkintmod(res,m));
    1675     8488543 :   return res;
    1676             : }
    1677             : INLINE GEN
    1678      312545 : Fp_invsafe(GEN a, GEN m)
    1679             : {
    1680             :   GEN res;
    1681      312545 :   if (! invmod(a,m,&res)) return NULL;
    1682      312545 :   return res;
    1683             : }
    1684             : INLINE GEN
    1685     2333798 : Fp_div(GEN a, GEN b, GEN m)
    1686             : {
    1687     2333798 :   pari_sp av=avma;
    1688             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1689     2333798 :   (void)new_chunk(lg(a)+(lg(m)<<1));
    1690     2333798 :   p = mulii(a, Fp_inv(b,m));
    1691     2333798 :   avma = av; return modii(p,m);
    1692             : }
    1693             : 
    1694             : INLINE GEN
    1695      695962 : Flx_mulu(GEN x, ulong a, ulong p) { return Flx_Fl_mul(x,a%p,p); }
    1696             : 
    1697             : INLINE GEN
    1698           0 : get_F2x_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1699             : 
    1700             : INLINE long
    1701      447467 : get_F2x_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1702             : 
    1703             : INLINE long
    1704      121254 : get_F2x_degree(GEN T) { return typ(T)==t_VEC? F2x_degree(gel(T,2)): F2x_degree(T); }
    1705             : 
    1706             : INLINE GEN
    1707         287 : get_F2xqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1708             : 
    1709             : INLINE long
    1710      375739 : get_F2xqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1711             : 
    1712             : INLINE long
    1713      201068 : get_F2xqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1714             : 
    1715             : INLINE GEN
    1716     7095272 : get_Flx_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1717             : 
    1718             : INLINE long
    1719    19263135 : get_Flx_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1720             : 
    1721             : INLINE long
    1722    31786798 : get_Flx_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1723             : 
    1724             : INLINE GEN
    1725        1017 : get_FlxqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1726             : 
    1727             : INLINE long
    1728      356694 : get_FlxqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1729             : 
    1730             : INLINE long
    1731       90260 : get_FlxqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1732             : 
    1733             : INLINE GEN
    1734      560598 : get_FpX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1735             : 
    1736             : INLINE long
    1737     1810643 : get_FpX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1738             : 
    1739             : INLINE long
    1740     1832607 : get_FpX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1741             : 
    1742             : INLINE GEN
    1743      142588 : get_FpXQX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1744             : 
    1745             : INLINE long
    1746       53083 : get_FpXQX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1747             : 
    1748             : INLINE long
    1749        1848 : get_FpXQX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1750             : 
    1751             : /*******************************************************************/
    1752             : /*                                                                 */
    1753             : /*                        ADDMULII / SUBMULII                      */
    1754             : /*                                                                 */
    1755             : /*******************************************************************/
    1756             : /* x - y*z */
    1757             : INLINE GEN
    1758    13412503 : submulii(GEN x, GEN y, GEN z)
    1759             : {
    1760    13412503 :   long lx = lgefint(x), ly, lz;
    1761             :   pari_sp av;
    1762             :   GEN t;
    1763    13412503 :   if (lx == 2) { t = mulii(z,y); togglesign(t); return t; }
    1764    11598973 :   ly = lgefint(y);
    1765    11598973 :   if (ly == 2) return icopy(x);
    1766    10584175 :   lz = lgefint(z);
    1767    10584175 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1768    10584175 :   t = mulii(z, y);
    1769    10584175 :   avma = av; return subii(x,t);
    1770             : }
    1771             : /* y*z - x */
    1772             : INLINE GEN
    1773     1822769 : mulsubii(GEN y, GEN z, GEN x)
    1774             : {
    1775     1822769 :   long lx = lgefint(x), ly, lz;
    1776             :   pari_sp av;
    1777             :   GEN t;
    1778     1822769 :   if (lx == 2) return mulii(z,y);
    1779     1132192 :   ly = lgefint(y);
    1780     1132192 :   if (ly == 2) return negi(x);
    1781     1091051 :   lz = lgefint(z);
    1782     1091051 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1783     1091051 :   t = mulii(z, y);
    1784     1091051 :   avma = av; return subii(t,x);
    1785             : }
    1786             : 
    1787             : /* x - u*y */
    1788             : INLINE GEN
    1789        7483 : submuliu(GEN x, GEN y, ulong u)
    1790             : {
    1791             :   pari_sp av;
    1792        7483 :   long ly = lgefint(y);
    1793        7483 :   if (ly == 2) return icopy(x);
    1794        7483 :   av = avma;
    1795        7483 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1796        7483 :   y = mului(u,y);
    1797        7483 :   avma = av; return subii(x, y);
    1798             : }
    1799             : /* x + u*y */
    1800             : INLINE GEN
    1801        7483 : addmuliu(GEN x, GEN y, ulong u)
    1802             : {
    1803             :   pari_sp av;
    1804        7483 :   long ly = lgefint(y);
    1805        7483 :   if (ly == 2) return icopy(x);
    1806        7483 :   av = avma;
    1807        7483 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1808        7483 :   y = mului(u,y);
    1809        7483 :   avma = av; return addii(x, y);
    1810             : }
    1811             : /* x - u*y */
    1812             : INLINE GEN
    1813   115709519 : submuliu_inplace(GEN x, GEN y, ulong u)
    1814             : {
    1815             :   pari_sp av;
    1816   115709519 :   long ly = lgefint(y);
    1817   115709519 :   if (ly == 2) return x;
    1818    91752403 :   av = avma;
    1819    91752403 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1820    91752403 :   y = mului(u,y);
    1821    91752403 :   avma = av; return subii(x, y);
    1822             : }
    1823             : /* x + u*y */
    1824             : INLINE GEN
    1825   114222713 : addmuliu_inplace(GEN x, GEN y, ulong u)
    1826             : {
    1827             :   pari_sp av;
    1828   114222713 :   long ly = lgefint(y);
    1829   114222713 :   if (ly == 2) return x;
    1830    91348328 :   av = avma;
    1831    91348328 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1832    91348328 :   y = mului(u,y);
    1833    91348328 :   avma = av; return addii(x, y);
    1834             : }
    1835             : /* ux + vy */
    1836             : INLINE GEN
    1837    24894247 : lincombii(GEN u, GEN v, GEN x, GEN y)
    1838             : {
    1839    24894247 :   long lx = lgefint(x), ly;
    1840             :   GEN p1, p2;
    1841             :   pari_sp av;
    1842    24894247 :   if (lx == 2) return mulii(v,y);
    1843    15333830 :   ly = lgefint(y);
    1844    15333830 :   if (ly == 2) return mulii(u,x);
    1845    14501689 :   av = avma; (void)new_chunk(lx+ly+lgefint(u)+lgefint(v)); /* HACK */
    1846    14501689 :   p1 = mulii(u,x);
    1847    14501689 :   p2 = mulii(v,y);
    1848    14501689 :   avma = av; return addii(p1,p2);
    1849             : }
    1850             : 
    1851             : /*******************************************************************/
    1852             : /*                                                                 */
    1853             : /*                          GEN SUBTYPES                           */
    1854             : /*                                                                 */
    1855             : /*******************************************************************/
    1856             : 
    1857             : INLINE int
    1858   950394050 : is_const_t(long t) { return (t < t_POLMOD); }
    1859             : INLINE int
    1860        5353 : is_extscalar_t(long t) { return (t <= t_POL); }
    1861             : INLINE int
    1862     1015872 : is_intreal_t(long t) { return (t <= t_REAL); }
    1863             : INLINE int
    1864   371901711 : is_matvec_t(long t) { return (t >= t_VEC && t <= t_MAT); }
    1865             : INLINE int
    1866    50902727 : is_noncalc_t(long tx) { return (tx) >= t_LIST; }
    1867             : INLINE int
    1868      774230 : is_rational_t(long t) { return (t == t_INT || t == t_FRAC); }
    1869             : INLINE int
    1870      309019 : is_real_t(long t) { return (t == t_INT || t == t_REAL || t == t_FRAC); }
    1871             : INLINE int
    1872  2706155537 : is_recursive_t(long t) { return lontyp[t]; }
    1873             : INLINE int
    1874   170946133 : is_scalar_t(long t) { return (t < t_POL); }
    1875             : INLINE int
    1876      910083 : is_vec_t(long t) { return (t == t_VEC || t == t_COL); }
    1877             : 
    1878             : /*******************************************************************/
    1879             : /*                                                                 */
    1880             : /*                         TRANSCENDENTAL                          */
    1881             : /*                                                                 */
    1882             : /*******************************************************************/
    1883             : INLINE GEN
    1884    17825866 : sqrtr(GEN x) {
    1885    17825866 :   long s = signe(x);
    1886    17825866 :   if (s == 0) return real_0_bit(expo(x) >> 1);
    1887    17792166 :   if (s >= 0) return sqrtr_abs(x);
    1888       28317 :   retmkcomplex(gen_0, sqrtr_abs(x));
    1889             : }
    1890             : INLINE GEN
    1891           0 : cbrtr_abs(GEN x) { return sqrtnr_abs(x, 3); }
    1892             : INLINE GEN
    1893           0 : cbrtr(GEN x) {
    1894           0 :   long s = signe(x);
    1895             :   GEN r;
    1896           0 :   if (s == 0) return real_0_bit(expo(x) / 3);
    1897           0 :   r = cbrtr_abs(x);
    1898           0 :   if (s < 0) togglesign(r);
    1899           0 :   return r;
    1900             : }
    1901             : INLINE GEN
    1902      306051 : sqrtnr(GEN x, long n) {
    1903      306051 :   long s = signe(x);
    1904             :   GEN r;
    1905      306051 :   if (s == 0) return real_0_bit(expo(x) / n);
    1906      306051 :   r = sqrtnr_abs(x, n);
    1907      306051 :   if (s < 0) pari_err_IMPL("sqrtnr for x < 0");
    1908      306051 :   return r;
    1909             : }
    1910             : INLINE long
    1911      211708 : logint(GEN B, GEN y) { return logintall(B,y,NULL); }
    1912             : INLINE ulong
    1913     1808567 : ulogint(ulong B, ulong y)
    1914             : {
    1915             :   ulong r;
    1916             :   long e;
    1917     1808567 :   if (y == 2) return expu(B);
    1918     1791179 :   r = y;
    1919     6005700 :   for (e=1;; e++)
    1920             :   { /* here, r = y^e, r2 = y^(e-1) */
    1921     6005700 :     if (r >= B) return r == B? e: e-1;
    1922     4214521 :     r = umuluu_or_0(y, r);
    1923     4214521 :     if (!r) return e;
    1924     4214521 :   }
    1925             : }
    1926             : 
    1927             : /*******************************************************************/
    1928             : /*                                                                 */
    1929             : /*                         MISCELLANEOUS                           */
    1930             : /*                                                                 */
    1931             : /*******************************************************************/
    1932     1015795 : INLINE int ismpzero(GEN x) { return is_intreal_t(typ(x)) && !signe(x); }
    1933   430950320 : INLINE int isintzero(GEN x) { return typ(x) == t_INT && !signe(x); }
    1934     6817829 : INLINE int isint1(GEN x) { return typ(x)==t_INT && equali1(x); }
    1935        4522 : INLINE int isintm1(GEN x){ return typ(x)==t_INT && equalim1(x);}
    1936   330640714 : INLINE int equali1(GEN n)
    1937   330640714 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(1)) && n[2] == 1; }
    1938    61762187 : INLINE int equalim1(GEN n)
    1939    61762187 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(-1)) && n[2] == 1; }
    1940             : /* works only for POSITIVE integers */
    1941  1194172893 : INLINE int is_pm1(GEN n)
    1942  1194172893 : { return lgefint(n) == 3 && n[2] == 1; }
    1943   205685427 : INLINE int is_bigint(GEN n)
    1944   205685427 : { long l = lgefint(n); return l > 3 || (l == 3 && (n[2] & HIGHBIT)); }
    1945             : 
    1946  2164646211 : INLINE int odd(long x) { return x & 1; }
    1947    28973976 : INLINE int both_odd(long x, long y) { return x & y & 1; }
    1948             : 
    1949             : INLINE int
    1950  2528089353 : isonstack(GEN x)
    1951  5056178706 : { return ((pari_sp)x >= pari_mainstack->bot
    1952  2528089353 :        && (pari_sp)x <  pari_mainstack->top); }
    1953             : 
    1954             : /* assume x != 0 and x t_REAL, return an approximation to log2(|x|) */
    1955             : INLINE double
    1956    18908074 : dbllog2r(GEN x)
    1957    18908074 : { return log2((double)(ulong)x[2]) + (double)(expo(x) - (BITS_IN_LONG-1)); }
    1958             : 
    1959             : INLINE GEN
    1960      282168 : mul_content(GEN cx, GEN cy)
    1961             : {
    1962      282168 :   if (!cx) return cy;
    1963       98695 :   if (!cy) return cx;
    1964       72925 :   return gmul(cx,cy);
    1965             : }
    1966             : INLINE GEN
    1967         833 : inv_content(GEN c) { return c? ginv(c): NULL; }
    1968             : INLINE GEN
    1969     1570357 : mul_denom(GEN dx, GEN dy)
    1970             : {
    1971     1570357 :   if (!dx) return dy;
    1972     1050774 :   if (!dy) return dx;
    1973      325507 :   return mulii(dx,dy);
    1974             : }
    1975             : 
    1976             : /* POLYNOMIALS */
    1977             : INLINE GEN
    1978    17565703 : constant_coeff(GEN x) { return signe(x)? gel(x,2): gen_0; }
    1979             : INLINE GEN
    1980    80732173 : leading_coeff(GEN x) { return lg(x) == 2? gen_0: gel(x,lg(x)-1); }
    1981             : INLINE ulong
    1982      413086 : Flx_lead(GEN x) { return lg(x) == 2? 0: x[lg(x)-1]; }
    1983             : INLINE ulong
    1984       12348 : Flx_constant(GEN x) { return lg(x) == 2? 0: x[2]; }
    1985             : INLINE long
    1986  2865202616 : degpol(GEN x) { return lg(x)-3; }
    1987             : INLINE long
    1988  1414157010 : lgpol(GEN x) { return lg(x)-2; }
    1989             : INLINE long
    1990    93485075 : lgcols(GEN x) { return lg(gel(x,1)); }
    1991             : INLINE long
    1992    32382613 : nbrows(GEN x) { return lg(gel(x,1))-1; }
    1993             : INLINE GEN
    1994           0 : truecoeff(GEN x, long n) { return polcoeff0(x,n,-1); }
    1995             : 
    1996             : INLINE GEN
    1997      582367 : ZXQ_mul(GEN y, GEN x, GEN T) { return ZX_rem(ZX_mul(y, x), T); }
    1998             : INLINE GEN
    1999      311735 : ZXQ_sqr(GEN x, GEN T) { return ZX_rem(ZX_sqr(x), T); }
    2000             : 
    2001             : INLINE GEN
    2002    63994149 : RgX_copy(GEN x)
    2003             : {
    2004             :   long lx, i;
    2005    63994149 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
    2006    63994154 :   for (i = 2; i<lx; i++) gel(y,i) = gcopy(gel(x,i));
    2007    63994151 :   return y;
    2008             : }
    2009             : /* have to use ulong to avoid silly warnings from gcc "assuming signed
    2010             :  * overflow does not occur" */
    2011             : INLINE GEN
    2012     2380386 : RgX_coeff(GEN x, long n)
    2013             : {
    2014     2380386 :   ulong l = lg(x);
    2015     2380386 :   return (n < 0 || ((ulong)n+3) > l)? gen_0: gel(x,n+2);
    2016             : }
    2017             : INLINE GEN
    2018      344827 : RgX_renormalize(GEN x) { return RgX_renormalize_lg(x, lg(x)); }
    2019             : INLINE GEN
    2020     6554009 : RgX_div(GEN x, GEN y) { return RgX_divrem(x,y,NULL); }
    2021             : INLINE GEN
    2022        1792 : RgXQX_div(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,NULL); }
    2023             : INLINE GEN
    2024       53735 : RgXQX_rem(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,ONLY_REM); }
    2025             : INLINE GEN
    2026      816616 : FpX_div(GEN x, GEN y, GEN p) { return FpX_divrem(x,y,p, NULL); }
    2027             : INLINE GEN
    2028     4948238 : Flx_div(GEN x, GEN y, ulong p) { return Flx_divrem(x,y,p, NULL); }
    2029             : INLINE GEN
    2030     2995737 : F2x_div(GEN x, GEN y) { return F2x_divrem(x,y, NULL); }
    2031             : INLINE GEN
    2032           0 : FpV_FpC_mul(GEN x, GEN y, GEN p) { return FpV_dotproduct(x,y,p); }
    2033             : INLINE GEN
    2034    46846042 : pol0_Flx(long sv) { return mkvecsmall(sv); }
    2035             : INLINE GEN
    2036    21801902 : pol1_Flx(long sv) { return mkvecsmall2(sv, 1); }
    2037             : INLINE GEN
    2038    18740423 : polx_Flx(long sv) { return mkvecsmall3(sv, 0, 1); }
    2039             : INLINE GEN
    2040           0 : zero_zx(long sv) { return zero_Flx(sv); }
    2041             : INLINE GEN
    2042           0 : polx_zx(long sv) { return polx_Flx(sv); }
    2043             : INLINE GEN
    2044           0 : zx_shift(GEN x, long n) { return Flx_shift(x,n); }
    2045             : INLINE GEN
    2046           0 : zx_renormalize(GEN x, long l) { return Flx_renormalize(x,l); }
    2047             : INLINE GEN
    2048        1495 : zero_F2x(long sv) { return zero_Flx(sv); }
    2049             : INLINE GEN
    2050    11518164 : pol0_F2x(long sv) { return pol0_Flx(sv); }
    2051             : INLINE GEN
    2052     2823938 : pol1_F2x(long sv) { return pol1_Flx(sv); }
    2053             : INLINE GEN
    2054      667783 : polx_F2x(long sv) { return mkvecsmall2(sv, 2); }
    2055             : INLINE int
    2056      818806 : F2x_equal1(GEN x) { return Flx_equal1(x); }
    2057             : INLINE int
    2058     3552178 : F2x_equal(GEN V, GEN W) { return Flx_equal(V,W); }
    2059             : INLINE GEN
    2060    70051165 : F2x_copy(GEN x) { return leafcopy(x); }
    2061             : INLINE GEN
    2062           0 : F2v_copy(GEN x) { return leafcopy(x); }
    2063             : INLINE GEN
    2064     2331321 : Flv_copy(GEN x) { return leafcopy(x); }
    2065             : INLINE GEN
    2066    76513841 : Flx_copy(GEN x) { return leafcopy(x); }
    2067             : INLINE GEN
    2068     1664315 : vecsmall_copy(GEN x) { return leafcopy(x); }
    2069             : INLINE int
    2070     4757114 : Flx_equal1(GEN x) { return degpol(x)==0 && x[2] == 1; }
    2071             : INLINE int
    2072       18149 : ZX_equal1(GEN x) { return degpol(x)==0 && equali1(gel(x,2)); }
    2073             : INLINE int
    2074     5460327 : ZX_is_monic(GEN x) { return equali1(leading_coeff(x)); }
    2075             : 
    2076             : INLINE GEN
    2077    46455695 : ZX_renormalize(GEN x, long lx)    { return ZXX_renormalize(x,lx); }
    2078             : INLINE GEN
    2079    60020065 : FpX_renormalize(GEN x, long lx)   { return ZXX_renormalize(x,lx); }
    2080             : INLINE GEN
    2081     1033335 : FpXX_renormalize(GEN x, long lx)  { return ZXX_renormalize(x,lx); }
    2082             : INLINE GEN
    2083     1135200 : FpXQX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
    2084             : INLINE GEN
    2085   123377370 : F2x_renormalize(GEN x, long lx)   { return Flx_renormalize(x,lx); }
    2086             : INLINE GEN
    2087        8702 : F2v_to_F2x(GEN x, long sv) {
    2088        8702 :   GEN y = leafcopy(x);
    2089        8702 :   y[1] = sv; F2x_renormalize(y, lg(y)); return y;
    2090             : }
    2091             : 
    2092             : INLINE long
    2093         455 : sturm(GEN x) { return sturmpart(x, NULL, NULL); }
    2094             : 
    2095             : INLINE long
    2096        2569 : gval(GEN x, long v) {
    2097        2569 :   pari_sp av = avma;
    2098        2569 :   long n = gvaluation(x, pol_x(v));
    2099        2569 :   avma = av; return n;
    2100             : }
    2101             : 
    2102             : INLINE void
    2103      468936 : RgX_shift_inplace_init(long v)
    2104      468936 : { if (v) (void)cgetg(v, t_VECSMALL); }
    2105             : /* shift polynomial in place. assume v free cells have been left before x */
    2106             : INLINE GEN
    2107      468936 : RgX_shift_inplace(GEN x, long v)
    2108             : {
    2109             :   long i, lx;
    2110             :   GEN y, z;
    2111      468936 :   if (!v) return x;
    2112      253227 :   lx = lg(x);
    2113      253227 :   if (lx == 2) return x;
    2114      253227 :   y = x + v;
    2115      253227 :   z = x + lx;
    2116             :   /* stackdummy from normalizepol: move it up */
    2117      253227 :   if (lg(z) != v) x[lx + v] = z[0];
    2118      253227 :   for (i = lx-1; i >= 2; i--) gel(y,i) = gel(x,i);
    2119      253227 :   for (i = v+1;  i >= 2; i--) gel(x,i) = gen_0;
    2120             :   /* leave x[1] alone: it is correct */
    2121      253227 :   x[0] = evaltyp(t_POL) | evallg(lx+v); return x;
    2122             : }
    2123             : 
    2124             : 
    2125             : /* LINEAR ALGEBRA */
    2126             : INLINE GEN
    2127      404446 : zv_to_ZV(GEN x) { return vecsmall_to_vec(x); }
    2128             : INLINE GEN
    2129     4919317 : zc_to_ZC(GEN x) { return vecsmall_to_col(x); }
    2130             : INLINE GEN
    2131      433578 : ZV_to_zv(GEN x) { return vec_to_vecsmall(x); }
    2132             : INLINE GEN
    2133           0 : zx_to_zv(GEN x, long N) { return Flx_to_Flv(x,N); }
    2134             : INLINE GEN
    2135           0 : zv_to_zx(GEN x, long sv) { return Flv_to_Flx(x,sv); }
    2136             : INLINE GEN
    2137           0 : zm_to_zxV(GEN x, long sv) { return Flm_to_FlxV(x,sv); }
    2138             : INLINE GEN
    2139           0 : zero_zm(long x, long y) { return zero_Flm(x,y); }
    2140             : INLINE GEN
    2141    16809137 : zero_zv(long x) { return zero_Flv(x); }
    2142             : INLINE GEN
    2143         210 : zm_transpose(GEN x) { return Flm_transpose(x); }
    2144             : INLINE GEN
    2145           0 : zm_copy(GEN x) { return Flm_copy(x); }
    2146             : INLINE GEN
    2147     2008887 : zv_copy(GEN x) { return Flv_copy(x); }
    2148             : INLINE GEN
    2149           0 : zm_row(GEN x, long i) { return Flm_row(x,i); }
    2150             : 
    2151             : INLINE GEN
    2152      841495 : ZC_hnfrem(GEN x, GEN y) { return ZC_hnfremdiv(x,y,NULL); }
    2153             : INLINE GEN
    2154       35625 : ZM_hnfrem(GEN x, GEN y) { return ZM_hnfdivrem(x,y,NULL); }
    2155             : INLINE GEN
    2156     1158771 : ZM_lll(GEN x, double D, long f) { return ZM_lll_norms(x,D,f,NULL); }
    2157             : INLINE void
    2158    11623860 : RgM_dimensions(GEN x, long *m, long *n) { *n = lg(x)-1; *m = *n? nbrows(x): 0; }
    2159             : INLINE GEN
    2160     6852044 : RgM_shallowcopy(GEN x)
    2161             : {
    2162             :   long l;
    2163     6852044 :   GEN y = cgetg_copy(x, &l);
    2164     6852044 :   while (--l > 0) gel(y,l) = leafcopy(gel(x,l));
    2165     6852044 :   return y;
    2166             : }
    2167             : INLINE GEN
    2168         383 : F2m_copy(GEN x) { return RgM_shallowcopy(x); }
    2169             : 
    2170             : INLINE GEN
    2171     1225793 : Flm_copy(GEN x) { return RgM_shallowcopy(x); }
    2172             : 
    2173             : /* divisibility: return 1 if y[i] | x[i] for all i, 0 otherwise. Assume
    2174             :  * x,y are ZV of the same length */
    2175             : INLINE int
    2176       23198 : ZV_dvd(GEN x, GEN y)
    2177             : {
    2178       23198 :   long i, l = lg(x);
    2179       36666 :   for (i=1; i < l; i++)
    2180       29533 :     if ( ! dvdii( gel(x,i), gel(y,i) ) ) return 0;
    2181        7133 :   return 1;
    2182             : }
    2183             : 
    2184             : /* Fq */
    2185             : INLINE GEN
    2186     2858223 : Fq_red(GEN x, GEN T, GEN p)
    2187     2858223 : { return typ(x)==t_INT? Fp_red(x,p): FpXQ_red(x,T,p); }
    2188             : INLINE GEN
    2189       38491 : Fq_to_FpXQ(GEN x, GEN T, GEN p /*unused*/)
    2190             : {
    2191             :   (void) p;
    2192       38491 :   return typ(x)==t_INT ? scalarpol(x, get_FpX_var(T)): x;
    2193             : }
    2194             : 
    2195             : INLINE GEN
    2196         833 : gener_Fq_local(GEN T, GEN p, GEN L)
    2197         833 : { return T? gener_FpXQ_local(T,p, L)
    2198         833 :           : pgener_Fp_local(p, L); }
    2199             : 
    2200             : /* FpXQX */
    2201             : INLINE GEN
    2202        4378 : FpXQX_div(GEN x, GEN y, GEN T, GEN p) { return FpXQX_divrem(x, y, T, p, NULL); }
    2203             : INLINE GEN
    2204       35483 : FlxqX_div(GEN x, GEN y, GEN T, ulong p) { return FlxqX_divrem(x, y, T, p, NULL); }
    2205             : INLINE GEN
    2206       33180 : F2xqX_div(GEN x, GEN y, GEN T) { return F2xqX_divrem(x, y, T, NULL); }
    2207             : 
    2208             : /* FqX */
    2209             : INLINE GEN
    2210       24829 : FqX_red(GEN z, GEN T, GEN p) { return T? FpXQX_red(z, T, p): FpX_red(z, p); }
    2211             : INLINE GEN
    2212      928648 : FqX_add(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2213             : INLINE GEN
    2214       16837 : FqX_neg(GEN x,GEN T,GEN p) { return T? FpXX_neg(x,p): FpX_neg(x,p); }
    2215             : INLINE GEN
    2216        2604 : FqX_sub(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2217             : INLINE GEN
    2218      633902 : FqX_Fp_mul(GEN P, GEN u, GEN T, GEN p)
    2219      633902 : { return T? FpXX_Fp_mul(P, u, p): FpX_Fp_mul(P, u, p); }
    2220             : INLINE GEN
    2221      570203 : FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p)
    2222      570203 : { return typ(U)==t_INT ? FqX_Fp_mul(P, U, T, p): FpXQX_FpXQ_mul(P, U, T, p); }
    2223             : INLINE GEN
    2224       91071 : FqX_mul(GEN x, GEN y, GEN T, GEN p)
    2225       91071 : { return T? FpXQX_mul(x, y, T, p): FpX_mul(x, y, p); }
    2226             : INLINE GEN
    2227      473371 : FqX_mulu(GEN x, ulong y, GEN T, GEN p)
    2228      473371 : { return T? FpXX_mulu(x, y, p): FpX_mulu(x, y, p); }
    2229             : INLINE GEN
    2230        5208 : FqX_sqr(GEN x, GEN T, GEN p)
    2231        5208 : { return T? FpXQX_sqr(x, T, p): FpX_sqr(x, p); }
    2232             : INLINE GEN
    2233        1211 : FqX_powu(GEN x, ulong n, GEN T, GEN p)
    2234        1211 : { return T? FpXQX_powu(x, n, T, p): FpX_powu(x, n, p); }
    2235             : INLINE GEN
    2236        5110 : FqX_div(GEN x, GEN y, GEN T, GEN p)
    2237        5110 : { return T? FpXQX_divrem(x,y,T,p,NULL): FpX_divrem(x,y,p,NULL); }
    2238             : INLINE GEN
    2239        5752 : FqX_get_red(GEN S, GEN T, GEN p)
    2240        5752 : { return T? FpXQX_get_red(S,T,p): FpX_get_red(S,p); }
    2241             : INLINE GEN
    2242       48985 : FqX_rem(GEN x, GEN y, GEN T, GEN p)
    2243       48985 : { return T? FpXQX_rem(x,y,T,p): FpX_rem(x,y,p); }
    2244             : INLINE GEN
    2245           0 : FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2246           0 : { return T? FpXQX_divrem(x,y,T,p,z): FpX_divrem(x,y,p,z); }
    2247             : INLINE GEN
    2248        5936 : FqX_div_by_X_x(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2249        5936 : { return T? FpXQX_div_by_X_x(x,y,T,p,z): FpX_div_by_X_x(x,y,p,z); }
    2250             : INLINE GEN
    2251           0 : FqX_halfgcd(GEN P,GEN Q,GEN T,GEN p)
    2252           0 : {return T? FpXQX_halfgcd(P,Q,T,p): FpX_halfgcd(P,Q,p);}
    2253             : INLINE GEN
    2254      257971 : FqX_gcd(GEN P,GEN Q,GEN T,GEN p)
    2255      257971 : {return T? FpXQX_gcd(P,Q,T,p): FpX_gcd(P,Q,p);}
    2256             : INLINE GEN
    2257       86065 : FqX_extgcd(GEN P,GEN Q,GEN T,GEN p, GEN *U, GEN *V)
    2258       86065 : { return T? FpXQX_extgcd(P,Q,T,p,U,V): FpX_extgcd(P,Q,p,U,V); }
    2259             : INLINE GEN
    2260        2863 : FqX_normalize(GEN z, GEN T, GEN p) { return T? FpXQX_normalize(z, T, p): FpX_normalize(z, p); }
    2261             : INLINE GEN
    2262      270487 : FqX_deriv(GEN f, /*unused*/GEN T, GEN p) { (void)T; return FpXX_deriv(f, p); }
    2263             : INLINE GEN
    2264       73451 : FqX_factor(GEN f, GEN T, GEN p) { return T?FpXQX_factor(f, T, p): FpX_factor(f, p); }
    2265             : INLINE GEN
    2266        6405 : FqX_roots(GEN f, GEN T, GEN p) { return T?FpXQX_roots(f, T, p): FpX_roots(f, p); }
    2267             : INLINE GEN
    2268         175 : FqX_to_mod(GEN f, GEN T, GEN p) { return T?FpXQX_to_mod(f, T, p): FpX_to_mod(f, p); }
    2269             : 
    2270             : /*FqXQ*/
    2271             : INLINE GEN
    2272           0 : FqXQ_add(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2273           0 : { (void)S; return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2274             : INLINE GEN
    2275           0 : FqXQ_sub(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2276           0 : { (void)S; return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2277             : INLINE GEN
    2278           0 : FqXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p)
    2279           0 : { return T? FpXQXQ_div(x,y,S,T,p): FpXQ_div(x,y,S,p); }
    2280             : INLINE GEN
    2281           0 : FqXQ_inv(GEN x, GEN S, GEN T, GEN p)
    2282           0 : { return T? FpXQXQ_inv(x,S,T,p): FpXQ_inv(x,S,p); }
    2283             : INLINE GEN
    2284           0 : FqXQ_invsafe(GEN x, GEN S, GEN T, GEN p)
    2285           0 : { return T? FpXQXQ_invsafe(x,S,T,p): FpXQ_inv(x,S,p); }
    2286             : INLINE GEN
    2287       21522 : FqXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p)
    2288       21522 : { return T? FpXQXQ_mul(x,y,S,T,p): FpXQ_mul(x,y,S,p); }
    2289             : INLINE GEN
    2290           0 : FqXQ_sqr(GEN x, GEN S, GEN T, GEN p)
    2291           0 : { return T? FpXQXQ_sqr(x,S,T,p): FpXQ_sqr(x,S,p); }
    2292             : INLINE GEN
    2293           0 : FqXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p)
    2294           0 : { return T? FpXQXQ_pow(x,n,S,T,p): FpXQ_pow(x,n,S,p); }
    2295             : 
    2296             : /*FpXQ*/
    2297             : INLINE GEN
    2298           0 : FpXQ_add(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2299           0 : { (void)T; return FpX_add(x,y,p); }
    2300             : INLINE GEN
    2301           0 : FpXQ_sub(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2302           0 : { (void)T; return FpX_sub(x,y,p); }
    2303             : 
    2304             : /*Flxq*/
    2305             : INLINE GEN
    2306           0 : Flxq_add(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2307           0 : { (void)T; return Flx_add(x,y,p); }
    2308             : INLINE GEN
    2309           0 : Flxq_sub(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2310           0 : { (void)T; return Flx_sub(x,y,p); }
    2311             : 
    2312             : /* F2x */
    2313             : 
    2314             : INLINE ulong
    2315   173126889 : F2x_coeff(GEN x,long v)
    2316             : {
    2317   173126889 :    ulong u=(ulong)x[2+divsBIL(v)];
    2318   173126694 :    return (u>>remsBIL(v))&1UL;
    2319             : }
    2320             : 
    2321             : INLINE void
    2322     4181752 : F2x_clear(GEN x,long v)
    2323             : {
    2324     4181752 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2325     4181752 :    *u&=~(1UL<<remsBIL(v));
    2326     4181752 : }
    2327             : 
    2328             : INLINE void
    2329    39196158 : F2x_set(GEN x,long v)
    2330             : {
    2331    39196158 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2332    39192975 :    *u|=1UL<<remsBIL(v);
    2333    39198017 : }
    2334             : 
    2335             : INLINE void
    2336     1360806 : F2x_flip(GEN x,long v)
    2337             : {
    2338     1360806 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2339     1360806 :    *u^=1UL<<remsBIL(v);
    2340     1360806 : }
    2341             : 
    2342             : /* F2v */
    2343             : 
    2344             : INLINE ulong
    2345   166598760 : F2v_coeff(GEN x,long v) { return F2x_coeff(x,v-1); }
    2346             : 
    2347             : INLINE void
    2348     4181752 : F2v_clear(GEN x,long v) { F2x_clear(x,v-1); }
    2349             : 
    2350             : INLINE void
    2351    12906381 : F2v_set(GEN x,long v)   { F2x_set(x,v-1); }
    2352             : 
    2353             : INLINE void
    2354     1360806 : F2v_flip(GEN x,long v) { F2x_flip(x,v-1); }
    2355             : 
    2356             : /* F2m */
    2357             : 
    2358             : INLINE ulong
    2359    20107365 : F2m_coeff(GEN x, long a, long b) { return F2v_coeff(gel(x,b), a); }
    2360             : 
    2361             : INLINE void
    2362           0 : F2m_clear(GEN x, long a, long b) { F2v_clear(gel(x,b), a); }
    2363             : 
    2364             : INLINE void
    2365     2434021 : F2m_set(GEN x, long a, long b) { F2v_set(gel(x,b), a); }
    2366             : 
    2367             : INLINE void
    2368     1360806 : F2m_flip(GEN x, long a, long b) { F2v_flip(gel(x,b), a); }
    2369             : 
    2370             : /* ARITHMETIC */
    2371             : INLINE GEN
    2372        1071 : matpascal(long n) { return matqpascal(n, NULL); }
    2373             : INLINE long
    2374     2314132 : Z_issquare(GEN x) { return Z_issquareall(x, NULL); }
    2375             : INLINE long
    2376          14 : Z_ispower(GEN x, ulong k) { return Z_ispowerall(x, k, NULL); }
    2377             : INLINE GEN
    2378     5491114 : sqrti(GEN x) { return sqrtremi(x,NULL); }
    2379             : INLINE GEN
    2380     3801039 : gaddgs(GEN y, long s) { return gaddsg(s,y); }
    2381             : INLINE int
    2382       25983 : gcmpgs(GEN y, long s) { return -gcmpsg(s,y); }
    2383             : INLINE int
    2384       24395 : gequalgs(GEN y, long s) { return gequalsg(s,y); }
    2385             : INLINE GEN
    2386           0 : gmaxsg(long s, GEN y) { return gmaxgs(y,s); }
    2387             : INLINE GEN
    2388           0 : gminsg(long s, GEN y) { return gmings(y,s); }
    2389             : INLINE GEN
    2390    13655845 : gmulgs(GEN y, long s) { return gmulsg(s,y); }
    2391             : INLINE GEN
    2392      929134 : gsubgs(GEN y, long s) { return gaddgs(y, -s); }
    2393             : INLINE GEN
    2394      563033 : gdivsg(long s, GEN y) { return gdiv(stoi(s), y); }
    2395             : 
    2396             : /* x t_COMPLEX */
    2397             : INLINE GEN
    2398    10344513 : cxnorm(GEN x) { return gadd(gsqr(gel(x,1)), gsqr(gel(x,2))); }
    2399             : /* q t_QUAD */
    2400             : INLINE GEN
    2401         623 : quadnorm(GEN q)
    2402             : {
    2403         623 :   GEN X = gel(q,1), b = gel(X,3), c = gel(X,2);
    2404         623 :   GEN z, u = gel(q,3), v = gel(q,2);
    2405         623 :   if (typ(u) == t_INT && typ(v) == t_INT) /* generic case */
    2406             :   {
    2407         308 :     z = signe(b)? mulii(v, addii(u,v)): sqri(v);
    2408         308 :     return addii(z, mulii(c, sqri(u)));
    2409             :   }
    2410             :   else
    2411             :   {
    2412         315 :     z = signe(b)? gmul(v, gadd(u,v)): gsqr(v);
    2413         315 :     return gadd(z, gmul(c, gsqr(u)));
    2414             :   }
    2415             : }
    2416             : /* x a t_QUAD, return the attached discriminant */
    2417             : INLINE GEN
    2418         252 : quad_disc(GEN x)
    2419             : {
    2420         252 :   GEN Q = gel(x,1), b = gel(Q,3), c = gel(Q,2), c4;
    2421         252 :   if (is_pm1(b))
    2422             :   {
    2423         196 :     pari_sp av = avma; (void)new_chunk(lgefint(c) + 1);
    2424         196 :     c4 = shifti(c,2); avma = av; return subsi(1, c4);
    2425             :   }
    2426          56 :   c4 = shifti(c,2); togglesign_safe(&c4); return c4;
    2427             : }
    2428             : INLINE GEN
    2429     6458500 : qfb_disc3(GEN x, GEN y, GEN z) { return subii(sqri(y), shifti(mulii(x,z),2)); }
    2430             : INLINE GEN
    2431     6377678 : qfb_disc(GEN x) { return qfb_disc3(gel(x,1), gel(x,2), gel(x,3)); }
    2432             : 
    2433             : INLINE GEN
    2434     1242658 : sqrfrac(GEN x)
    2435             : {
    2436     1242658 :   GEN z = cgetg(3,t_FRAC);
    2437     1242658 :   gel(z,1) = sqri(gel(x,1));
    2438     1242658 :   gel(z,2) = sqri(gel(x,2)); return z;
    2439             : }
    2440             : 
    2441             : INLINE void
    2442    11591476 : normalize_frac(GEN z) {
    2443    11591476 :   if (signe(gel(z,2)) < 0) { togglesign(gel(z,1)); setabssign(gel(z,2)); }
    2444    11591476 : }
    2445             : 
    2446             : INLINE GEN
    2447      231553 : powii(GEN x, GEN n)
    2448             : {
    2449      231553 :   long ln = lgefint(n);
    2450      231553 :   if (ln == 3) {
    2451             :     GEN z;
    2452      228319 :     if (signe(n) > 0) return powiu(x, n[2]);
    2453        4970 :     z = cgetg(3, t_FRAC);
    2454        4970 :     gel(z,1) = gen_1;
    2455        4970 :     gel(z,2) = powiu(x, n[2]);
    2456        4970 :     return z;
    2457             :   }
    2458        3234 :   if (ln == 2) return gen_1; /* rare */
    2459             :   /* should never happen */
    2460           0 :   return powgi(x, n); /* overflow unless x = 0, 1, -1 */
    2461             : }
    2462             : INLINE GEN
    2463        1148 : powIs(long n) {
    2464        1148 :   switch(n & 3)
    2465             :   {
    2466           7 :     case 1: return mkcomplex(gen_0,gen_1);
    2467         364 :     case 2: return gen_m1;
    2468         476 :     case 3: return mkcomplex(gen_0,gen_m1);
    2469             :   }
    2470         301 :   return gen_1;
    2471             : }
    2472             : 
    2473             : /*******************************************************************/
    2474             : /*                                                                 */
    2475             : /*                             ASSIGNMENTS                         */
    2476             : /*                                                                 */
    2477             : /*******************************************************************/
    2478           0 : INLINE void mpexpz(GEN x, GEN z)
    2479           0 : { pari_sp av = avma; gaffect(mpexp(x), z); avma = av; }
    2480           0 : INLINE void mplogz(GEN x, GEN z)
    2481           0 : { pari_sp av = avma; gaffect(mplog(x), z); avma = av; }
    2482           0 : INLINE void mpcosz(GEN x, GEN z)
    2483           0 : { pari_sp av = avma; gaffect(mpcos(x), z); avma = av; }
    2484           0 : INLINE void mpsinz(GEN x, GEN z)
    2485           0 : { pari_sp av = avma; gaffect(mpsin(x), z); avma = av; }
    2486           0 : INLINE void gnegz(GEN x, GEN z)
    2487           0 : { pari_sp av = avma; gaffect(gneg(x), z); avma = av; }
    2488           0 : INLINE void gabsz(GEN x, long prec, GEN z)
    2489           0 : { pari_sp av = avma; gaffect(gabs(x,prec), z); avma = av; }
    2490       23318 : INLINE void gaddz(GEN x, GEN y, GEN z)
    2491       23318 : { pari_sp av = avma; gaffect(gadd(x,y), z); avma = av; }
    2492           0 : INLINE void gsubz(GEN x, GEN y, GEN z)
    2493           0 : { pari_sp av = avma; gaffect(gsub(x,y), z); avma = av; }
    2494       11673 : INLINE void gmulz(GEN x, GEN y, GEN z)
    2495       11673 : { pari_sp av = avma; gaffect(gmul(x,y), z); avma = av; }
    2496           0 : INLINE void gdivz(GEN x, GEN y, GEN z)
    2497           0 : { pari_sp av = avma; gaffect(gdiv(x,y), z); avma = av; }
    2498           0 : INLINE void gdiventz(GEN x, GEN y, GEN z)
    2499           0 : { pari_sp av = avma; gaffect(gdivent(x,y), z); avma = av; }
    2500           0 : INLINE void gmodz(GEN x, GEN y, GEN z)
    2501           0 : { pari_sp av = avma; gaffect(gmod(x,y), z); avma = av; }
    2502           0 : INLINE void gmul2nz(GEN x, long s, GEN z)
    2503           0 : { pari_sp av = avma; gaffect(gmul2n(x,s), z); avma = av; }
    2504           0 : INLINE void gshiftz(GEN x, long s, GEN z)
    2505           0 : { pari_sp av = avma; gaffect(gshift(x,s), z); avma = av; }
    2506             : 
    2507             : /*******************************************************************/
    2508             : /*                                                                 */
    2509             : /*                       ELLIPTIC CURVES                           */
    2510             : /*                                                                 */
    2511             : /*******************************************************************/
    2512     5285582 : INLINE GEN ell_get_a1(GEN e) { return gel(e,1); }
    2513     3094402 : INLINE GEN ell_get_a2(GEN e) { return gel(e,2); }
    2514     4514210 : INLINE GEN ell_get_a3(GEN e) { return gel(e,3); }
    2515     3887390 : INLINE GEN ell_get_a4(GEN e) { return gel(e,4); }
    2516     4703737 : INLINE GEN ell_get_a6(GEN e) { return gel(e,5); }
    2517     3971772 : INLINE GEN ell_get_b2(GEN e) { return gel(e,6); }
    2518     1024676 : INLINE GEN ell_get_b4(GEN e) { return gel(e,7); }
    2519     1630477 : INLINE GEN ell_get_b6(GEN e) { return gel(e,8); }
    2520     1463840 : INLINE GEN ell_get_b8(GEN e) { return gel(e,9); }
    2521     5951085 : INLINE GEN ell_get_c4(GEN e) { return gel(e,10); }
    2522     7983017 : INLINE GEN ell_get_c6(GEN e) { return gel(e,11); }
    2523     9416898 : INLINE GEN ell_get_disc(GEN e) { return gel(e,12); }
    2524     1027292 : INLINE GEN ell_get_j(GEN e) { return gel(e,13); }
    2525     7958150 : INLINE long ell_get_type(GEN e) { return mael(e,14,1); }
    2526     1561174 : INLINE GEN ellff_get_field(GEN x) { return gmael(x, 15, 1); }
    2527      678203 : INLINE GEN ellff_get_a4a6(GEN x)  { return gmael(x, 15, 2); }
    2528        1141 : INLINE GEN ellQp_get_zero(GEN x) { return gmael(x, 15, 1); }
    2529         287 : INLINE long ellQp_get_prec(GEN E) { GEN z = ellQp_get_zero(E); return valp(z); }
    2530         847 : INLINE GEN ellQp_get_p(GEN E) { GEN z = ellQp_get_zero(E); return gel(z,2); }
    2531       37058 : INLINE long ellR_get_prec(GEN x) { return nbits2prec(mael3(x, 15, 1, 1)); }
    2532       11784 : INLINE long ellR_get_sign(GEN x) { return mael3(x, 15, 1, 2); }
    2533      502502 : INLINE GEN ellnf_get_nf(GEN x) { return checknf_i(gmael(x,15,1)); }
    2534          56 : INLINE GEN ellnf_get_bnf(GEN x) { return checkbnf_i(gmael(x,15,1)); }
    2535             : 
    2536    34186175 : INLINE int ell_is_inf(GEN z) { return lg(z) == 2; }
    2537      806783 : INLINE GEN ellinf(void) { return mkvec(gen_0); }
    2538             : 
    2539             : /*******************************************************************/
    2540             : /*                                                                 */
    2541             : /*                    ALGEBRAIC NUMBER THEORY                      */
    2542             : /*                                                                 */
    2543             : /*******************************************************************/
    2544     8123832 : INLINE GEN modpr_get_pr(GEN x)  { return gel(x,3); }
    2545      609465 : INLINE GEN modpr_get_p(GEN x)  { return pr_get_p(modpr_get_pr(x)); }
    2546     2518312 : INLINE GEN modpr_get_T(GEN x)  { return lg(x) == 4? NULL: gel(x,4); }
    2547             : 
    2548    18278623 : INLINE GEN pr_get_p(GEN pr)  { return gel(pr,1); }
    2549     4803432 : INLINE GEN pr_get_gen(GEN pr){ return gel(pr,2); }
    2550             : /* .[2] instead of itos works: e and f are small positive integers */
    2551     2230209 : INLINE long pr_get_e(GEN pr) { return gel(pr,3)[2]; }
    2552     7745842 : INLINE long pr_get_f(GEN pr) { return gel(pr,4)[2]; }
    2553     5801795 : INLINE GEN pr_get_tau(GEN pr){ return gel(pr,5); }
    2554             : INLINE int
    2555     2323009 : pr_is_inert(GEN P) { return pr_get_f(P) == lg(pr_get_gen(P))-1; }
    2556             : INLINE GEN
    2557      205716 : pr_norm(GEN pr) { return powiu(pr_get_p(pr), pr_get_f(pr)); }
    2558             : INLINE ulong
    2559       40852 : upr_norm(GEN pr) { return upowuu(pr_get_p(pr)[2], pr_get_f(pr)); }
    2560             : 
    2561             : /* assume nf a genuine nf */
    2562             : INLINE long
    2563        4206 : nf_get_varn(GEN nf) { return varn(gel(nf,1)); }
    2564             : INLINE GEN
    2565    27103896 : nf_get_pol(GEN nf) { return gel(nf,1); }
    2566             : INLINE long
    2567    21267976 : nf_get_degree(GEN nf) { return degpol( nf_get_pol(nf) ); }
    2568             : INLINE long
    2569     1266947 : nf_get_r1(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,1)); }
    2570             : INLINE long
    2571        2373 : nf_get_r2(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,2)); }
    2572             : INLINE GEN
    2573       47553 : nf_get_disc(GEN nf) { return gel(nf,3); }
    2574             : INLINE GEN
    2575      748553 : nf_get_index(GEN nf) { return gel(nf,4); }
    2576             : INLINE GEN
    2577     1212604 : nf_get_M(GEN nf) { return gmael(nf,5,1); }
    2578             : INLINE GEN
    2579       61044 : nf_get_G(GEN nf) { return gmael(nf,5,2); }
    2580             : INLINE GEN
    2581      431190 : nf_get_roundG(GEN nf) { return gmael(nf,5,3); }
    2582             : INLINE GEN
    2583       24332 : nf_get_Tr(GEN nf) { return gmael(nf,5,4); }
    2584             : INLINE GEN
    2585        2268 : nf_get_diff(GEN nf) { return gmael(nf,5,5); }
    2586             : INLINE GEN
    2587          28 : nf_get_ramified_primes(GEN nf) { return gmael(nf,5,8); }
    2588             : INLINE GEN
    2589      159317 : nf_get_roots(GEN nf) { return gel(nf,6); }
    2590             : INLINE GEN
    2591          77 : nf_get_zk(GEN nf)
    2592             : {
    2593          77 :   GEN y = gel(nf,7), D = nf_get_zkden(nf);
    2594          77 :   if (!equali1(D)) y = gdiv(y, D);
    2595          77 :   return y;
    2596             : }
    2597             : INLINE GEN
    2598      221078 : nf_get_zkprimpart(GEN nf)
    2599             : {
    2600      221078 :   GEN y = gel(nf,7);
    2601             :   /* test for old format of nf.zk: non normalized */
    2602      221078 :   if (!equali1(gel(nf,4)) && gequal1(gel(y,1))) y = Q_remove_denom(y,NULL);
    2603      221078 :   return y;
    2604             : }
    2605             : INLINE GEN
    2606      223682 : nf_get_zkden(GEN nf)
    2607             : {
    2608      223682 :   GEN y = gel(nf,7), D = gel(y,1);
    2609      223682 :   if (typ(D) == t_POL) D = gel(D,2);
    2610             :   /* test for old format of nf.zk: non normalized */
    2611      223682 :   if (!equali1(gel(nf,4)) && equali1(D)) D = Q_denom(y);
    2612      223682 :   return D;
    2613             : }
    2614             : INLINE GEN
    2615     2171798 : nf_get_invzk(GEN nf) { return gel(nf,8); }
    2616             : INLINE void
    2617       19438 : nf_get_sign(GEN nf, long *r1, long *r2)
    2618             : {
    2619       19438 :   GEN x = gel(nf,2);
    2620       19438 :   *r1 = itou(gel(x,1));
    2621       19438 :   *r2 = itou(gel(x,2));
    2622       19438 : }
    2623             : 
    2624             : INLINE GEN
    2625       49672 : abgrp_get_no(GEN x) { return gel(x,1); }
    2626             : INLINE GEN
    2627     2074790 : abgrp_get_cyc(GEN x) { return gel(x,2); }
    2628             : INLINE GEN
    2629      391714 : abgrp_get_gen(GEN x) { return gel(x,3); }
    2630             : INLINE GEN
    2631     2041634 : bnf_get_nf(GEN bnf) { return gel(bnf,7); }
    2632             : INLINE GEN
    2633      796378 : bnf_get_clgp(GEN bnf) { return gmael(bnf,8,1); }
    2634             : INLINE GEN
    2635        4592 : bnf_get_no(GEN bnf) { return abgrp_get_no(bnf_get_clgp(bnf)); }
    2636             : INLINE GEN
    2637      429073 : bnf_get_cyc(GEN bnf) { return abgrp_get_cyc(bnf_get_clgp(bnf)); }
    2638             : INLINE GEN
    2639      362384 : bnf_get_gen(GEN bnf)  { return abgrp_get_gen(bnf_get_clgp(bnf)); }
    2640             : INLINE GEN
    2641         860 : bnf_get_reg(GEN bnf) { return gmael(bnf,8,2); }
    2642             : INLINE GEN
    2643      480297 : bnf_get_logfu(GEN bnf) { return gel(bnf,3); }
    2644             : INLINE GEN
    2645        5762 : bnf_get_tuU(GEN bnf) { return gmael3(bnf,8,4,2); }
    2646             : INLINE long
    2647       24549 : bnf_get_tuN(GEN bnf) { return gmael3(bnf,8,4,1)[2]; }
    2648             : INLINE GEN
    2649        1806 : bnf_get_fu(GEN bnf) {
    2650        1806 :   GEN fu = bnf_get_fu_nocheck(bnf);
    2651        1806 :   if (typ(fu) == t_MAT) pari_err(e_MISC,"missing units in bnf");
    2652        1806 :   return fu;
    2653             : }
    2654             : INLINE GEN
    2655        7022 : bnf_get_fu_nocheck(GEN bnf) { return gmael(bnf,8,5); }
    2656             : 
    2657             : INLINE GEN
    2658      737035 : bnr_get_bnf(GEN bnr) { return gel(bnr,1); }
    2659             : INLINE GEN
    2660      379266 : bnr_get_bid(GEN bnr) { return gel(bnr,2); }
    2661             : INLINE GEN
    2662       18123 : bnr_get_mod(GEN bnr) { return gmael(bnr,2,1); }
    2663             : INLINE GEN
    2664       27307 : bnr_get_nf(GEN bnr) { return gmael(bnr,1,7); }
    2665             : INLINE GEN
    2666      511769 : bnr_get_clgp(GEN bnr) { return gel(bnr,5); }
    2667             : INLINE GEN
    2668       45080 : bnr_get_no(GEN bnr) { return abgrp_get_no(bnr_get_clgp(bnr)); }
    2669             : INLINE GEN
    2670      454761 : bnr_get_cyc(GEN bnr) { return abgrp_get_cyc(bnr_get_clgp(bnr)); }
    2671             : INLINE GEN
    2672          70 : bnr_get_gen_nocheck(GEN bnr) { return abgrp_get_gen(bnr_get_clgp(bnr)); }
    2673             : INLINE GEN
    2674       11025 : bnr_get_gen(GEN bnr) {
    2675       11025 :   GEN G = bnr_get_clgp(bnr);
    2676       11025 :   if (lg(G) !=  4)
    2677           0 :     pari_err(e_MISC,"missing bnr generators: please use bnrinit(,,1)");
    2678       11025 :   return gel(G,3);
    2679             : }
    2680             : 
    2681             : INLINE GEN
    2682      300579 : bid_get_mod(GEN bid) { return gel(bid,1); }
    2683             : INLINE GEN
    2684       45836 : bid_get_ideal(GEN bid) { return gmael(bid,1,1); }
    2685             : INLINE GEN
    2686         448 : bid_get_arch(GEN bid) { return gmael(bid,1,2); }
    2687             : INLINE GEN
    2688     1052237 : bid_get_grp(GEN bid) { return gel(bid,2); }
    2689             : INLINE GEN
    2690      394085 : bid_get_fact(GEN bid) { return gmael(bid,3,1); }
    2691             : INLINE GEN
    2692      352687 : bid_get_fact2(GEN bid) { return gmael(bid,3,2); }
    2693             : INLINE GEN
    2694      352757 : bid_get_sprk(GEN bid) { return gmael(bid,4,1); }
    2695             : INLINE GEN
    2696       29855 : bid_get_sarch(GEN bid) { return gmael(bid,4,2); }
    2697             : INLINE GEN
    2698      373351 : bid_get_archp(GEN bid) { return gmael3(bid,4,2,2); }
    2699             : INLINE GEN
    2700      653546 : bid_get_U(GEN bid) { return gel(bid,5); }
    2701             : INLINE GEN
    2702           0 : bid_get_no(GEN bid) { return abgrp_get_no(bid_get_grp(bid)); }
    2703             : INLINE GEN
    2704     1023873 : bid_get_cyc(GEN bid) { return abgrp_get_cyc(bid_get_grp(bid)); }
    2705             : INLINE GEN
    2706           0 : bid_get_gen_nocheck(GEN bid)  { return abgrp_get_gen(bid_get_grp(bid)); }
    2707             : INLINE GEN
    2708       27769 : bid_get_gen(GEN bid) {
    2709       27769 :   GEN G = bid_get_grp(bid);
    2710       27769 :   if (lg(G) != 4) pari_err(e_MISC,"missing bid generators. Use idealstar(,,2)");
    2711       27769 :   return abgrp_get_gen(G);
    2712             : }
    2713             : 
    2714             : INLINE GEN
    2715     5861212 : znstar_get_N(GEN G) { return gmael(G,1,1); }
    2716             : INLINE GEN
    2717     1838760 : znstar_get_faN(GEN G) { return gel(G,3); }
    2718             : INLINE GEN
    2719           0 : znstar_get_no(GEN G) { return abgrp_get_no(gel(G,2)); }
    2720             : INLINE GEN
    2721      165669 : znstar_get_cyc(GEN G) { return abgrp_get_cyc(gel(G,2)); }
    2722             : INLINE GEN
    2723           0 : znstar_get_gen(GEN G) { return abgrp_get_gen(gel(G,2)); }
    2724             : INLINE GEN
    2725     2514771 : znstar_get_conreycyc(GEN G) { return gmael(G,4,5); }
    2726             : INLINE GEN
    2727      707336 : znstar_get_conreygen(GEN G) { return gmael(G,4,4); }
    2728             : INLINE GEN
    2729       28140 : znstar_get_Ui(GEN G) { return gmael(G,4,3); }
    2730             : INLINE GEN
    2731      117670 : znstar_get_U(GEN G) { return gel(G,5); }
    2732             : INLINE GEN
    2733      350119 : znstar_get_pe(GEN G) { return gmael(G,4,1); }
    2734             : INLINE GEN
    2735       19194 : gal_get_pol(GEN gal) { return gel(gal,1); }
    2736             : INLINE GEN
    2737        1309 : gal_get_p(GEN gal) { return gmael(gal,2,1); }
    2738             : INLINE GEN
    2739         105 : gal_get_e(GEN gal) { return gmael(gal,2,2); }
    2740             : INLINE GEN
    2741       15673 : gal_get_mod(GEN gal) { return gmael(gal,2,3); }
    2742             : INLINE GEN
    2743       16051 : gal_get_roots(GEN gal) { return gel(gal,3); }
    2744             : INLINE GEN
    2745       15673 : gal_get_invvdm(GEN gal) { return gel(gal,4); }
    2746             : INLINE GEN
    2747       15673 : gal_get_den(GEN gal) { return gel(gal,5); }
    2748             : INLINE GEN
    2749       65072 : gal_get_group(GEN gal) { return gel(gal,6); }
    2750             : INLINE GEN
    2751        1708 : gal_get_gen(GEN gal) { return gel(gal,7); }
    2752             : INLINE GEN
    2753        1358 : gal_get_orders(GEN gal) { return gel(gal,8); }
    2754             : 
    2755             : /* assume rnf a genuine rnf */
    2756             : INLINE long
    2757      627501 : rnf_get_degree(GEN rnf) { return degpol(rnf_get_pol(rnf)); }
    2758             : INLINE long
    2759       15316 : rnf_get_nfdegree(GEN rnf) { return degpol(nf_get_pol(rnf_get_nf(rnf))); }
    2760             : INLINE long
    2761      459914 : rnf_get_absdegree(GEN rnf) { return degpol(gmael(rnf,11,1)); }
    2762             : INLINE GEN
    2763         462 : rnf_get_idealdisc(GEN rnf) { return gmael(rnf,3,1); }
    2764             : INLINE GEN
    2765         448 : rnf_get_k(GEN rnf) { return gmael(rnf,11,3); }
    2766             : INLINE GEN
    2767         448 : rnf_get_alpha(GEN rnf) { return gmael(rnf, 11, 2); }
    2768             : INLINE GEN
    2769      128107 : rnf_get_nf(GEN rnf) { return gel(rnf,10); }
    2770             : INLINE void
    2771        2513 : rnf_get_nfzk(GEN rnf, GEN *b, GEN *cb) {*b=gmael(rnf,2,1); *cb=gmael(rnf,2,2);}
    2772             : INLINE GEN
    2773       94955 : rnf_get_polabs(GEN rnf) { return gmael(rnf,11,1); }
    2774             : INLINE GEN
    2775      782103 : rnf_get_pol(GEN rnf) { return gel(rnf,1); }
    2776             : INLINE GEN
    2777          63 : rnf_get_disc(GEN rnf) { return gel(rnf,3); }
    2778             : INLINE GEN
    2779         105 : rnf_get_index(GEN rnf) { return gel(rnf,4); }
    2780             : INLINE long
    2781           0 : rnf_get_varn(GEN rnf) { return varn(gel(rnf,1)); }
    2782             : INLINE GEN
    2783      107982 : rnf_get_nfpol(GEN rnf) { return gmael(rnf,10,1); }
    2784             : INLINE long
    2785         595 : rnf_get_nfvarn(GEN rnf) { return varn(gmael(rnf,10,1)); }
    2786             : INLINE GEN
    2787        2877 : rnf_get_zk(GEN rnf) { return gel(rnf,7); }
    2788             : INLINE GEN
    2789       35182 : rnf_get_map(GEN rnf) { return gel(rnf,11); }
    2790             : INLINE GEN
    2791        1190 : rnf_get_invzk(GEN rnf) { return gel(rnf,8); }
    2792             : 
    2793             : /* I integral ZM (not HNF), G ZM, rounded Cholesky form of a weighted
    2794             :  * T2 matrix. Reduce I wrt G */
    2795             : INLINE GEN
    2796       13111 : idealpseudored(GEN I, GEN G)
    2797       13111 : { return ZM_mul(I, ZM_lll(ZM_mul(G, I), 0.99, LLL_IM)); }
    2798             : 
    2799             : /* I integral (not necessarily HNF), G ZM, rounded Cholesky form of a weighted
    2800             :  * T2 matrix. Return m in I with T2(m) small */
    2801             : INLINE GEN
    2802      153315 : idealpseudomin(GEN I, GEN G)
    2803             : {
    2804      153315 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2805      153315 :   return ZM_ZC_mul(I, gel(u,1));
    2806             : }
    2807             : /* I, G as in idealpseudomin. Return an irrational m in I with T2(m) small */
    2808             : INLINE GEN
    2809      294411 : idealpseudomin_nonscalar(GEN I, GEN G)
    2810             : {
    2811      294411 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2812      294411 :   GEN m = ZM_ZC_mul(I, gel(u,1));
    2813      294411 :   if (ZV_isscalar(m) && lg(u) > 2) m = ZM_ZC_mul(I, gel(u,2));
    2814      294411 :   return m;
    2815             : }
    2816             : 
    2817             : INLINE GEN
    2818          70 : idealred_elt(GEN nf, GEN I) {
    2819          70 :   pari_sp av = avma;
    2820          70 :   GEN u = idealpseudomin(I, nf_get_roundG(nf));
    2821          70 :   return gerepileupto(av, u);
    2822             : }
    2823             : INLINE GEN
    2824      158933 : idealred(GEN nf, GEN I) { return idealred0(nf, I, NULL); }
    2825             : 
    2826             : INLINE GEN
    2827        1274 : idealchineseinit(GEN nf, GEN x)
    2828        1274 : { return idealchinese(nf,x,NULL); }
    2829             : 
    2830             : /*******************************************************************/
    2831             : /*                                                                 */
    2832             : /*                              CLOSURES                           */
    2833             : /*                                                                 */
    2834             : /*******************************************************************/
    2835   261607408 : INLINE long closure_arity(GEN C)          { return ((ulong)C[1])&ARITYBITS; }
    2836    35404637 : INLINE long closure_is_variadic(GEN C) { return !!(((ulong)C[1])&VARARGBITS); }
    2837   225780778 : INLINE const char *closure_codestr(GEN C)  { return GSTR(gel(C,2))-1; }
    2838           0 : INLINE GEN closure_get_code(GEN C)  { return gel(C,2); }
    2839   225755941 : INLINE GEN closure_get_oper(GEN C)  { return gel(C,3); }
    2840   225756344 : INLINE GEN closure_get_data(GEN C)  { return gel(C,4); }
    2841        8952 : INLINE GEN closure_get_dbg(GEN C)   { return gel(C,5); }
    2842       21516 : INLINE GEN closure_get_text(GEN C)  { return gel(C,6); }
    2843     1201973 : INLINE GEN closure_get_frame(GEN C) { return gel(C,7); }
    2844             : 
    2845             : /*******************************************************************/
    2846             : /*                                                                 */
    2847             : /*                               ERRORS                            */
    2848             : /*                                                                 */
    2849             : /*******************************************************************/
    2850             : INLINE long
    2851       51296 : err_get_num(GEN e) { return e[1]; }
    2852             : INLINE GEN
    2853          77 : err_get_compo(GEN e, long i) { return gel(e, i+1); }
    2854             : 
    2855             : INLINE void
    2856          14 : pari_err_BUG(const char *f) { pari_err(e_BUG,f); }
    2857             : INLINE void
    2858           7 : pari_err_CONSTPOL(const char *f) { pari_err(e_CONSTPOL, f); }
    2859             : INLINE void
    2860          63 : pari_err_COPRIME(const char *f, GEN x, GEN y) { pari_err(e_COPRIME, f,x,y); }
    2861             : INLINE void
    2862         487 : pari_err_DIM(const char *f) { pari_err(e_DIM, f); }
    2863             : INLINE void
    2864           0 : pari_err_FILE(const char *f, const char *g) { pari_err(e_FILE, f,g); }
    2865             : INLINE void
    2866          42 : pari_err_FLAG(const char *f) { pari_err(e_FLAG,f); }
    2867             : INLINE void
    2868         364 : pari_err_IMPL(const char *f) { pari_err(e_IMPL,f); }
    2869             : INLINE void
    2870       19710 : pari_err_INV(const char *f, GEN x) { pari_err(e_INV,f,x); }
    2871             : INLINE void
    2872          28 : pari_err_IRREDPOL(const char *f, GEN x) { pari_err(e_IRREDPOL, f,x); }
    2873             : INLINE void
    2874        1968 : 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); }
    2875             : INLINE void
    2876         245 : pari_err_COMPONENT(const char *f, const char *op, GEN l, GEN x) { pari_err(e_COMPONENT, f,op,l,x); }
    2877             : INLINE void
    2878           0 : pari_err_MAXPRIME(ulong c) { pari_err(e_MAXPRIME, c); }
    2879             : INLINE void
    2880         287 : pari_err_OP(const char *f, GEN x, GEN y) { pari_err(e_OP, f,x,y); }
    2881             : INLINE void
    2882          84 : pari_err_OVERFLOW(const char *f) { pari_err(e_OVERFLOW, f); }
    2883             : INLINE void
    2884         218 : pari_err_PREC(const char *f) { pari_err(e_PREC,f); }
    2885             : INLINE void
    2886           0 : pari_err_PACKAGE(const char *f) { pari_err(e_PACKAGE,f); }
    2887             : INLINE void
    2888          49 : pari_err_PRIME(const char *f, GEN x) { pari_err(e_PRIME, f,x); }
    2889             : INLINE void
    2890         735 : pari_err_MODULUS(const char *f, GEN x, GEN y) { pari_err(e_MODULUS, f,x,y); }
    2891             : INLINE void
    2892          42 : pari_err_ROOTS0(const char *f) { pari_err(e_ROOTS0, f); }
    2893             : INLINE void
    2894          77 : pari_err_SQRTN(const char *f, GEN x) { pari_err(e_SQRTN, f,x); }
    2895             : INLINE void
    2896       12293 : pari_err_TYPE(const char *f, GEN x) { pari_err(e_TYPE, f,x); }
    2897             : INLINE void
    2898        3073 : pari_err_TYPE2(const char *f, GEN x, GEN y) { pari_err(e_TYPE2, f,x,y); }
    2899             : INLINE void
    2900         203 : pari_err_VAR(const char *f, GEN x, GEN y) { pari_err(e_VAR, f,x,y); }
    2901             : INLINE void
    2902         154 : pari_err_PRIORITY(const char *f, GEN x, const char *op, long v)
    2903         154 : { pari_err(e_PRIORITY, f,x,op,v); }

Generated by: LCOV version 1.11