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.12.0 lcov report (development 22875-74571cde7) Lines: 1263 1427 88.5 %
Date: 2018-07-21 05:35:54 Functions: 558 633 88.2 %
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     2740756 : mkintmod(GEN x, GEN y) { retmkintmod(x,y); }
     141             : INLINE GEN
     142        3948 : mkintmodu(ulong x, ulong y) {
     143        3948 :   GEN v = cgetg(3,t_INTMOD);
     144        3948 :   gel(v,1) = utoipos(y);
     145        3948 :   gel(v,2) = utoi(x); return v;
     146             : }
     147             : INLINE GEN
     148     2541336 : mkpolmod(GEN x, GEN y) { retmkpolmod(x,y); }
     149             : INLINE GEN
     150    13245547 : mkfrac(GEN x, GEN y) { retmkfrac(x,y); }
     151             : INLINE GEN
     152         511 : 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       12173 : Qtoss(GEN q, long *n, long *d)
     156             : {
     157       12173 :   if (typ(q) == t_INT) { *n = itos(q); *d = 1; }
     158        2443 :   else { *n = itos(gel(q,1)); *d = itou(gel(q,2)); }
     159       12173 : }
     160             : INLINE GEN
     161    36039374 : sstoQ(long n, long d)
     162             : {
     163             :   ulong r;
     164             :   long g, q;
     165    36039374 :   if (!n)
     166             :   {
     167       59185 :     if (!d) pari_err_INV("sstoQ",gen_0);
     168       59185 :     return gen_0;
     169             :   }
     170    35980189 :   if (d < 0) { d = -d; n = -n; }
     171    35980189 :   if (d == 1) return stoi(n);
     172    35977004 :   q = udivuu_rem(labs(n),d,&r);
     173    35977004 :   if (!r) return n > 0? utoipos(q): utoineg(q);
     174     1475733 :   g = ugcd(d,r); /* gcd(n,d) */
     175     1475733 :   if (g != 1) { n /= g; d /= g; }
     176     1475733 :   retmkfrac(stoi(n), utoi(d));
     177             : }
     178             : 
     179             : INLINE GEN
     180     4627816 : mkfraccopy(GEN x, GEN y) { retmkfrac(icopy(x), icopy(y)); }
     181             : INLINE GEN
     182           7 : mkrfrac(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     183           7 :   gel(v,1) = x; gel(v,2) = y; return v; }
     184             : INLINE GEN
     185           7 : mkrfraccopy(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     186           7 :   gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     187             : INLINE GEN
     188     7669453 : mkcomplex(GEN x, GEN y) { retmkcomplex(x,y); }
     189             : INLINE GEN
     190      448448 : gen_I(void) { return mkcomplex(gen_0, gen_1); }
     191             : INLINE GEN
     192      204391 : cgetc(long l) { retmkcomplex(cgetr(l), cgetr(l)); }
     193             : INLINE GEN
     194         105 : mkquad(GEN n, GEN x, GEN y) { GEN v = cgetg(4, t_QUAD);
     195         105 :   gel(v,1) = n; gel(v,2) = x; gel(v,3) = y; return v; }
     196             : /* vecsmall */
     197             : INLINE GEN
     198    70991970 : mkvecsmall(long x) { GEN v = cgetg(2, t_VECSMALL); v[1] = x; return v; }
     199             : INLINE GEN
     200   121025187 : mkvecsmall2(long x,long y) { GEN v = cgetg(3, t_VECSMALL);
     201   121026983 :   v[1]=x; v[2]=y; return v; }
     202             : INLINE GEN
     203    58201737 : mkvecsmall3(long x,long y,long z) { GEN v = cgetg(4, t_VECSMALL);
     204    58199524 :   v[1]=x; v[2]=y; v[3]=z; return v; }
     205             : INLINE GEN
     206    11939228 : mkvecsmall4(long x,long y,long z,long t) { GEN v = cgetg(5, t_VECSMALL);
     207    11927838 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; return v; }
     208             : INLINE GEN
     209      466224 : mkvecsmall5(long x,long y,long z,long t,long u) { GEN v = cgetg(6, t_VECSMALL);
     210      466224 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; v[5]=u; return v; }
     211             : 
     212             : INLINE GEN
     213      158123 : mkqfi(GEN x, GEN y, GEN z) { retmkqfi(x,y,z); }
     214             : /* vec */
     215             : INLINE GEN
     216    14007012 : mkvec(GEN x) { retmkvec(x); }
     217             : INLINE GEN
     218    95606369 : mkvec2(GEN x, GEN y) { retmkvec2(x,y); }
     219             : INLINE GEN
     220    71845612 : mkvec3(GEN x, GEN y, GEN z) { retmkvec3(x,y,z); }
     221             : INLINE GEN
     222     7254193 : mkvec4(GEN x, GEN y, GEN z, GEN t) { retmkvec4(x,y,z,t); }
     223             : INLINE GEN
     224    11967997 : mkvec5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkvec5(x,y,z,t,u); }
     225             : INLINE GEN
     226           7 : mkvecs(long x) { retmkvec(stoi(x)); }
     227             : INLINE GEN
     228       19780 : mkvec2s(long x, long y) { retmkvec2(stoi(x),stoi(y)); }
     229             : INLINE GEN
     230      492724 : mkvec3s(long x, long y, long z) { retmkvec3(stoi(x),stoi(y),stoi(z)); }
     231             : INLINE GEN
     232          21 : mkvec4s(long x, long y, long z, long t) { retmkvec4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     233             : INLINE GEN
     234       35084 : mkveccopy(GEN x) { GEN v = cgetg(2, t_VEC); gel(v,1) = gcopy(x); return v; }
     235             : INLINE GEN
     236       91317 : mkvec2copy(GEN x, GEN y) {
     237       91317 :   GEN v = cgetg(3,t_VEC); gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     238             : /* col */
     239             : INLINE GEN
     240     2417806 : mkcol(GEN x) { retmkcol(x); }
     241             : INLINE GEN
     242    23605072 : mkcol2(GEN x, GEN y) { retmkcol2(x,y); }
     243             : INLINE GEN
     244       42385 : mkcol3(GEN x, GEN y, GEN z) { retmkcol3(x,y,z); }
     245             : INLINE GEN
     246           0 : mkcol4(GEN x, GEN y, GEN z, GEN t) { retmkcol4(x,y,z,t); }
     247             : INLINE GEN
     248           0 : mkcol5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkcol5(x,y,z,t,u); }
     249             : INLINE GEN
     250        8716 : mkcol6(GEN x, GEN y, GEN z, GEN t, GEN u, GEN v) { retmkcol6(x,y,z,t,u,v); }
     251             : INLINE GEN
     252         273 : mkcols(long x) { retmkcol(stoi(x)); }
     253             : INLINE GEN
     254     2176146 : mkcol2s(long x, long y) { retmkcol2(stoi(x),stoi(y)); }
     255             : INLINE GEN
     256           0 : mkcol3s(long x, long y, long z) { retmkcol3(stoi(x),stoi(y),stoi(z)); }
     257             : INLINE GEN
     258           0 : mkcol4s(long x, long y, long z, long t) { retmkcol4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     259             : INLINE GEN
     260       46031 : mkcolcopy(GEN x) { GEN v = cgetg(2, t_COL); gel(v,1) = gcopy(x); return v; }
     261             : /* mat */
     262             : INLINE GEN
     263     2513272 : mkmat(GEN x) { retmkmat(x); }
     264             : INLINE GEN
     265    28845410 : mkmat2(GEN x, GEN y) { retmkmat2(x,y); }
     266             : INLINE GEN
     267        2331 : mkmat3(GEN x, GEN y, GEN z) { retmkmat3(x,y,z); }
     268             : INLINE GEN
     269           0 : mkmat4(GEN x, GEN y, GEN z, GEN t) { retmkmat4(x,y,z,t); }
     270             : INLINE GEN
     271           0 : mkmat5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkmat5(x,y,z,t,u); }
     272             : INLINE GEN
     273       21998 : mkmatcopy(GEN x) { GEN v = cgetg(2, t_MAT); gel(v,1) = gcopy(x); return v; }
     274             : INLINE GEN
     275           0 : mkerr(long x) { GEN v = cgetg(2, t_ERROR); v[1] = x; return v; }
     276             : INLINE GEN
     277       25236 : mkoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_1; return v; }
     278             : INLINE GEN
     279       13979 : mkmoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_m1; return v; }
     280             : INLINE long
     281       50223 : inf_get_sign(GEN x) { return signe(gel(x,1)); }
     282             : INLINE GEN
     283       10661 : mkmat22s(long a, long b, long c, long d) {retmkmat2(mkcol2s(a,c),mkcol2s(b,d));}
     284             : INLINE GEN
     285     1533049 : mkmat22(GEN a, GEN b, GEN c, GEN d) { retmkmat2(mkcol2(a,c),mkcol2(b,d)); }
     286             : 
     287             : /* pol */
     288             : INLINE GEN
     289      972019 : pol_x(long v) {
     290      972019 :   GEN p = cgetg(4, t_POL);
     291      972019 :   p[1] = evalsigne(1)|evalvarn(v);
     292      972019 :   gel(p,2) = gen_0;
     293      972019 :   gel(p,3) = gen_1; return p;
     294             : }
     295             : /* x^n, assume n >= 0 */
     296             : INLINE GEN
     297     2626765 : pol_xn(long n, long v) {
     298     2626765 :   long i, a = n+2;
     299     2626765 :   GEN p = cgetg(a+1, t_POL);
     300     2626765 :   p[1] = evalsigne(1)|evalvarn(v);
     301     2626765 :   for (i = 2; i < a; i++) gel(p,i) = gen_0;
     302     2626765 :   gel(p,a) = gen_1; return p;
     303             : }
     304             : /* x^n, no assumption on n */
     305             : INLINE GEN
     306         287 : pol_xnall(long n, long v)
     307             : {
     308         287 :   if (n < 0) retmkrfrac(gen_1, pol_xn(-n,v));
     309         280 :   return pol_xn(n, v);
     310             : }
     311             : INLINE GEN
     312     1501932 : pol_1(long v) {
     313     1501932 :   GEN p = cgetg(3, t_POL);
     314     1501935 :   p[1] = evalsigne(1)|evalvarn(v);
     315     1501935 :   gel(p,2) = gen_1; return p;
     316             : }
     317             : INLINE GEN
     318    15290560 : pol_0(long v)
     319             : {
     320    15290560 :   GEN x = cgetg(2,t_POL);
     321    15290560 :   x[1] = evalvarn(v); return x;
     322             : }
     323             : #define retconst_vec(n,x)\
     324             :   do { long _i, _n = (n);\
     325             :        GEN _v = cgetg(_n+1, t_VEC), _x = (x);\
     326             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     327             :        return _v; } while(0)
     328             : INLINE GEN
     329     8318346 : const_vec(long n, GEN x) { retconst_vec(n, x); }
     330             : #define retconst_col(n,x)\
     331             :   do { long _i, _n = (n);\
     332             :        GEN _v = cgetg(_n+1, t_COL), _x = (x);\
     333             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     334             :        return _v; } while(0)
     335             : INLINE GEN
     336     8626042 : const_col(long n, GEN x) { retconst_col(n, x); }
     337             : INLINE GEN
     338     8234834 : const_vecsmall(long n, long c)
     339             : {
     340             :   long i;
     341     8234834 :   GEN V = cgetg(n+1,t_VECSMALL);
     342     8234838 :   for(i=1;i<=n;i++) V[i] = c;
     343     8234838 :   return V;
     344             : }
     345             : 
     346             : /***   ZERO   ***/
     347             : /* O(p^e) */
     348             : INLINE GEN
     349      302747 : zeropadic(GEN p, long e)
     350             : {
     351      302747 :   GEN y = cgetg(5,t_PADIC);
     352      302747 :   gel(y,4) = gen_0;
     353      302747 :   gel(y,3) = gen_1;
     354      302747 :   gel(y,2) = icopy(p);
     355      302747 :   y[1] = evalvalp(e) | _evalprecp(0);
     356      302747 :   return y;
     357             : }
     358             : INLINE GEN
     359         966 : zeropadic_shallow(GEN p, long e)
     360             : {
     361         966 :   GEN y = cgetg(5,t_PADIC);
     362         966 :   gel(y,4) = gen_0;
     363         966 :   gel(y,3) = gen_1;
     364         966 :   gel(y,2) = p;
     365         966 :   y[1] = evalvalp(e) | _evalprecp(0);
     366         966 :   return y;
     367             : }
     368             : /* O(pol_x(v)^e) */
     369             : INLINE GEN
     370      143479 : zeroser(long v, long e)
     371             : {
     372      143479 :   GEN x = cgetg(2, t_SER);
     373      143479 :   x[1] = evalvalp(e) | evalvarn(v); return x;
     374             : }
     375             : INLINE int
     376     5743459 : ser_isexactzero(GEN x)
     377             : {
     378     5743459 :   if (!signe(x)) switch(lg(x))
     379             :   {
     380      136136 :     case 2: return 1;
     381         854 :     case 3: return isexactzero(gel(x,2));
     382             :   }
     383     5606469 :   return 0;
     384             : }
     385             : /* 0 * pol_x(v) */
     386             : INLINE GEN
     387     5490630 : zeropol(long v) { return pol_0(v); }
     388             : /* vector(n) */
     389             : INLINE GEN
     390    35947638 : zerocol(long n)
     391             : {
     392    35947638 :   GEN y = cgetg(n+1,t_COL);
     393    35947638 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     394    35947638 :   return y;
     395             : }
     396             : /* vectorv(n) */
     397             : INLINE GEN
     398    18750327 : zerovec(long n)
     399             : {
     400    18750327 :   GEN y = cgetg(n+1,t_VEC);
     401    18750329 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     402    18750329 :   return y;
     403             : }
     404             : /* matrix(m, n) */
     405             : INLINE GEN
     406       16100 : zeromat(long m, long n)
     407             : {
     408       16100 :   GEN y = cgetg(n+1,t_MAT);
     409       16100 :   GEN v = zerocol(m);
     410       16100 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     411       16100 :   return y;
     412             : }
     413             : /* = zero_zx, sv is a evalvarn()*/
     414             : INLINE GEN
     415      923829 : zero_Flx(long sv) { return pol0_Flx(sv); }
     416             : INLINE GEN
     417    33278732 : zero_Flv(long n)
     418             : {
     419    33278732 :   GEN y = cgetg(n+1,t_VECSMALL);
     420    33279935 :   long i; for (i=1; i<=n; i++) y[i] = 0;
     421    33279935 :   return y;
     422             : }
     423             : /* matrix(m, n) */
     424             : INLINE GEN
     425      907344 : zero_Flm(long m, long n)
     426             : {
     427      907344 :   GEN y = cgetg(n+1,t_MAT);
     428      907333 :   GEN v = zero_Flv(m);
     429      907337 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     430      907337 :   return y;
     431             : }
     432             : /* matrix(m, n) */
     433             : INLINE GEN
     434      104212 : zero_Flm_copy(long m, long n)
     435             : {
     436      104212 :   GEN y = cgetg(n+1,t_MAT);
     437      104207 :   long i; for (i=1; i<=n; i++) gel(y,i) = zero_Flv(m);
     438      104219 :   return y;
     439             : }
     440             : 
     441             : INLINE GEN
     442      793217 : zero_F2v(long m)
     443             : {
     444      793217 :   long l = nbits2nlong(m);
     445      793217 :   GEN v  = zero_Flv(l+1);
     446      793217 :   v[1] = m;
     447      793217 :   return v;
     448             : }
     449             : 
     450             : INLINE GEN
     451           0 : zero_F2m(long m, long n)
     452             : {
     453             :   long i;
     454           0 :   GEN M = cgetg(n+1, t_MAT);
     455           0 :   GEN v = zero_F2v(m);
     456           0 :   for (i = 1; i <= n; i++)
     457           0 :     gel(M,i) = v;
     458           0 :   return M;
     459             : }
     460             : 
     461             : 
     462             : INLINE GEN
     463      276568 : zero_F2m_copy(long m, long n)
     464             : {
     465             :   long i;
     466      276568 :   GEN M = cgetg(n+1, t_MAT);
     467      806171 :   for (i = 1; i <= n; i++)
     468      529603 :     gel(M,i)= zero_F2v(m);
     469      276568 :   return M;
     470             : }
     471             : 
     472             : /* matrix(m, n) */
     473             : INLINE GEN
     474     4751431 : zeromatcopy(long m, long n)
     475             : {
     476     4751431 :   GEN y = cgetg(n+1,t_MAT);
     477     4751431 :   long i; for (i=1; i<=n; i++) gel(y,i) = zerocol(m);
     478     4751431 :   return y;
     479             : }
     480             : 
     481             : INLINE GEN
     482       17605 : zerovec_block(long len)
     483             : {
     484             :   long i;
     485       17605 :   GEN blk = cgetg_block(len + 1, t_VEC);
     486      580965 :   for (i = 1; i <= len; ++i)
     487      563360 :     gel(blk, i) = gen_0;
     488       17605 :   return blk;
     489             : }
     490             : 
     491             : /* i-th vector in the standard basis */
     492             : INLINE GEN
     493     1311271 : col_ei(long n, long i) { GEN e = zerocol(n); gel(e,i) = gen_1; return e; }
     494             : INLINE GEN
     495      326495 : vec_ei(long n, long i) { GEN e = zerovec(n); gel(e,i) = gen_1; return e; }
     496             : INLINE GEN
     497          42 : F2v_ei(long n, long i) { GEN e = zero_F2v(n); F2v_set(e,i); return e; }
     498             : INLINE GEN
     499       71379 : vecsmall_ei(long n, long i) { GEN e = zero_zv(n); e[i] = 1; return e; }
     500             : INLINE GEN
     501      657808 : Rg_col_ei(GEN x, long n, long i) { GEN e = zerocol(n); gel(e,i) = x; return e; }
     502             : 
     503             : INLINE GEN
     504    12406236 : shallowcopy(GEN x)
     505    12406236 : { return typ(x) == t_MAT ? RgM_shallowcopy(x): leafcopy(x); }
     506             : 
     507             : /* routines for naive growarrays */
     508             : INLINE GEN
     509    12697810 : vectrunc_init(long l)
     510             : {
     511    12697810 :   GEN z = new_chunk(l);
     512    12697865 :   z[0] = evaltyp(t_VEC) | _evallg(1); return z;
     513             : }
     514             : INLINE GEN
     515          28 : coltrunc_init(long l)
     516             : {
     517          28 :   GEN z = new_chunk(l);
     518          28 :   z[0] = evaltyp(t_COL) | _evallg(1); return z;
     519             : }
     520             : INLINE void
     521   253327909 : lg_increase(GEN x) { x[0]++; }
     522             : INLINE void
     523    51299898 : vectrunc_append(GEN x, GEN t) { gel(x, lg(x)) = t; lg_increase(x); }
     524             : INLINE void
     525       10416 : vectrunc_append_batch(GEN x, GEN y)
     526             : {
     527       10416 :   long i, l = lg(x), ly = lg(y);
     528       10416 :   GEN z = x + l-1;
     529       10416 :   for (i = 1; i < ly; i++) gel(z,i) = gel(y,i);
     530       10416 :   setlg(x, l+ly-1);
     531       10416 : }
     532             : INLINE GEN
     533    82737087 : vecsmalltrunc_init(long l)
     534             : {
     535    82737087 :   GEN z = new_chunk(l);
     536    82737087 :   z[0] = evaltyp(t_VECSMALL) | _evallg(1); return z;
     537             : }
     538             : INLINE void
     539    33040633 : vecsmalltrunc_append(GEN x, long t) { x[ lg(x) ] = t; lg_increase(x); }
     540             : 
     541             : /*******************************************************************/
     542             : /*                                                                 */
     543             : /*                        VEC / COL / VECSMALL                     */
     544             : /*                                                                 */
     545             : /*******************************************************************/
     546             : /* shallow*/
     547             : INLINE GEN
     548           0 : vec_shorten(GEN v, long n)
     549             : {
     550             :   long i;
     551           0 :   GEN V = cgetg(n+1,t_VEC);
     552           0 :   for(i=1;i<=n;i++) gel(V,i) = gel(v,i);
     553           0 :   return V;
     554             : }
     555             : /* shallow*/
     556             : INLINE GEN
     557       13328 : vec_lengthen(GEN v, long n)
     558             : {
     559             :   long i;
     560       13328 :   long l=lg(v);
     561       13328 :   GEN V = cgetg(n+1,t_VEC);
     562       13328 :   for(i=1;i<l;i++) gel(V,i) = gel(v,i);
     563       13328 :   return V;
     564             : }
     565             : /* shallow*/
     566             : INLINE GEN
     567       61124 : vec_append(GEN V, GEN s)
     568             : {
     569       61124 :   long i, l2 = lg(V);
     570       61124 :   GEN res = cgetg(l2+1, typ(V));
     571       61124 :   for (i = 1; i < l2; ++i) gel(res, i) = gel(V,i);
     572       61124 :   gel(res,l2) = s; return res;
     573             : }
     574             : /* shallow*/
     575             : INLINE GEN
     576        1785 : vec_prepend(GEN v, GEN s)
     577             : {
     578        1785 :   long i, l = lg(v);
     579        1785 :   GEN w = cgetg(l+1, typ(v));
     580        1785 :   gel(w,1) = s;
     581        1785 :   for (i = 2; i <= l; ++i) gel(w,i) = gel(v,i-1);
     582        1785 :   return w;
     583             : }
     584             : /* shallow*/
     585             : INLINE GEN
     586           0 : vec_setconst(GEN v, GEN x)
     587             : {
     588           0 :   long i, l = lg(v);
     589           0 :   for (i = 1; i < l; i++) gel(v,i) = x;
     590           0 :   return v;
     591             : }
     592             : INLINE GEN
     593      732251 : vecsmall_shorten(GEN v, long n)
     594             : {
     595             :   long i;
     596      732251 :   GEN V = cgetg(n+1,t_VECSMALL);
     597      732252 :   for(i=1;i<=n;i++) V[i] = v[i];
     598      732252 :   return V;
     599             : }
     600             : INLINE GEN
     601          21 : vecsmall_lengthen(GEN v, long n)
     602             : {
     603          21 :   long i, l = lg(v);
     604          21 :   GEN V = cgetg(n+1,t_VECSMALL);
     605          21 :   for(i=1;i<l;i++) V[i] = v[i];
     606          21 :   return V;
     607             : }
     608             : 
     609             : INLINE GEN
     610      457679 : vec_to_vecsmall(GEN x)
     611      457679 : { pari_APPLY_long(itos(gel(x,i))) }
     612             : INLINE GEN
     613      135396 : vecsmall_to_vec(GEN x)
     614      135396 : { pari_APPLY_type(t_VEC, stoi(x[i])) }
     615             : INLINE GEN
     616        1617 : vecsmall_to_vec_inplace(GEN z)
     617             : {
     618        1617 :   long i, l = lg(z);
     619        1617 :   for (i=1; i<l; i++) gel(z,i) = stoi(z[i]);
     620        1617 :   settyp(z, t_VEC); return z;
     621             : }
     622             : INLINE GEN
     623     5210063 : vecsmall_to_col(GEN x)
     624     5210063 : { pari_APPLY_type(t_COL, stoi(x[i])) }
     625             : 
     626             : INLINE int
     627     8065634 : vecsmall_lexcmp(GEN x, GEN y)
     628             : {
     629             :   long lx,ly,l,i;
     630     8065634 :   lx = lg(x);
     631     8065634 :   ly = lg(y); l = minss(lx,ly);
     632    39683347 :   for (i=1; i<l; i++)
     633    37751063 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     634     1932284 :   if (lx == ly) return 0;
     635          14 :   return (lx < ly)? -1 : 1;
     636             : }
     637             : 
     638             : INLINE int
     639    85155511 : vecsmall_prefixcmp(GEN x, GEN y)
     640             : {
     641    85155511 :   long i, lx = lg(x), ly = lg(y), l = minss(lx,ly);
     642   394027655 :   for (i=1; i<l; i++)
     643   374395014 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     644    19632641 :   return 0;
     645             : }
     646             : 
     647             : /*Can be used on t_VEC, but coeffs not gcopy-ed*/
     648             : INLINE GEN
     649       14155 : vecsmall_prepend(GEN V, long s)
     650             : {
     651       14155 :   long i, l2 = lg(V);
     652       14155 :   GEN res = cgetg(l2+1, typ(V));
     653       14155 :   res[1] = s;
     654       14155 :   for (i = 2; i <= l2; ++i) res[i] = V[i - 1];
     655       14155 :   return res;
     656             : }
     657             : 
     658             : INLINE GEN
     659     2551491 : vecsmall_append(GEN V, long s)
     660             : {
     661     2551491 :   long i, l2 = lg(V);
     662     2551491 :   GEN res = cgetg(l2+1, t_VECSMALL);
     663     2551490 :   for (i = 1; i < l2; ++i) res[i] = V[i];
     664     2551490 :   res[l2] = s; return res;
     665             : }
     666             : 
     667             : INLINE GEN
     668      781885 : vecsmall_concat(GEN u, GEN v)
     669             : {
     670      781885 :   long i, l1 = lg(u)-1, l2 = lg(v)-1;
     671      781885 :   GEN res = cgetg(l1+l2+1, t_VECSMALL);
     672      781885 :   for (i = 1; i <= l1; ++i) res[i]    = u[i];
     673      781885 :   for (i = 1; i <= l2; ++i) res[i+l1] = v[i];
     674      781885 :   return res;
     675             : }
     676             : 
     677             : /* return the number of indices where u and v are equal */
     678             : INLINE long
     679           0 : vecsmall_coincidence(GEN u, GEN v)
     680             : {
     681           0 :   long i, s = 0, l = minss(lg(u),lg(v));
     682           0 :   for(i=1; i<l; i++)
     683           0 :     if(u[i] == v[i]) s++;
     684           0 :   return s;
     685             : }
     686             : 
     687             : /* returns the first index i<=n such that x=v[i] if it exists, 0 otherwise */
     688             : INLINE long
     689           0 : vecsmall_isin(GEN v, long x)
     690             : {
     691           0 :   long i, l = lg(v);
     692           0 :   for (i = 1; i < l; i++)
     693           0 :     if (v[i] == x) return i;
     694           0 :   return 0;
     695             : }
     696             : 
     697             : INLINE long
     698          84 : vecsmall_pack(GEN V, long base, long mod)
     699             : {
     700          84 :   long i, s = 0;
     701          84 :   for(i=1; i<lg(V); i++) s = (base*s + V[i]) % mod;
     702          84 :   return s;
     703             : }
     704             : 
     705             : INLINE long
     706          14 : vecsmall_indexmax(GEN x)
     707             : {
     708          14 :   long i, i0 = 1, t = x[1], lx = lg(x);
     709          56 :   for (i=2; i<lx; i++)
     710          42 :     if (x[i] > t) t = x[i0=i];
     711          14 :   return i0;
     712             : }
     713             : 
     714             : INLINE long
     715      154105 : vecsmall_max(GEN x)
     716             : {
     717      154105 :   long i, t = x[1], lx = lg(x);
     718      558808 :   for (i=2; i<lx; i++)
     719      404703 :     if (x[i] > t) t = x[i];
     720      154105 :   return t;
     721             : }
     722             : 
     723             : INLINE long
     724          14 : vecsmall_indexmin(GEN x)
     725             : {
     726          14 :   long i, i0 = 1, t = x[1], lx =lg(x);
     727          56 :   for (i=2; i<lx; i++)
     728          42 :     if (x[i] < t) t = x[i0=i];
     729          14 :   return i0;
     730             : }
     731             : 
     732             : INLINE long
     733        1421 : vecsmall_min(GEN x)
     734             : {
     735        1421 :   long i, t = x[1], lx =lg(x);
     736        9947 :   for (i=2; i<lx; i++)
     737        8526 :     if (x[i] < t) t = x[i];
     738        1421 :   return t;
     739             : }
     740             : 
     741             : INLINE int
     742     4976051 : ZV_isscalar(GEN x)
     743             : {
     744     4976051 :   long l = lg(x);
     745    14205343 :   while (--l > 1)
     746     8140566 :     if (signe(gel(x, l))) return 0;
     747     1088726 :   return 1;
     748             : }
     749             : INLINE int
     750    19351517 : QV_isscalar(GEN x)
     751             : {
     752    19351517 :   long lx = lg(x),i;
     753    20867158 :   for (i=2; i<lx; i++)
     754    20320449 :     if (!isintzero(gel(x, i))) return 0;
     755      546709 :   return 1;
     756             : }
     757             : INLINE int
     758        7501 : RgV_isscalar(GEN x)
     759             : {
     760        7501 :   long lx = lg(x),i;
     761       10891 :   for (i=2; i<lx; i++)
     762        9809 :     if (!gequal0(gel(x, i))) return 0;
     763        1082 :   return 1;
     764             : }
     765             : INLINE int
     766           0 : RgX_isscalar(GEN x)
     767             : {
     768             :   long i;
     769           0 :   for (i=lg(x)-1; i>2; i--)
     770           0 :     if (!gequal0(gel(x, i))) return 0;
     771           0 :   return 1;
     772             : }
     773             : INLINE long
     774     4479158 : RgX_equal_var(GEN x, GEN y) { return varn(x) == varn(y) && RgX_equal(x,y); }
     775             : 
     776             : INLINE int
     777        5902 : RgX_is_rational(GEN x)
     778             : {
     779             :   long i;
     780       28861 :   for (i = lg(x)-1; i > 1; i--)
     781       26865 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     782        1996 :   return 1;
     783             : }
     784             : INLINE int
     785     4272055 : RgX_is_ZX(GEN x)
     786             : {
     787             :   long i;
     788    18613476 :   for (i = lg(x)-1; i > 1; i--)
     789    14357185 :     if (typ(gel(x,i)) != t_INT) return 0;
     790     4256291 :   return 1;
     791             : }
     792             : INLINE int
     793      262213 : RgX_is_QX(GEN x)
     794             : {
     795      262213 :   long k = lg(x)-1;
     796      926114 :   for ( ; k>1; k--)
     797      664146 :     if (!is_rational_t(typ(gel(x,k)))) return 0;
     798      261968 :   return 1;
     799             : }
     800             : INLINE int
     801    15894291 : RgX_is_monomial(GEN x)
     802             : {
     803             :   long i;
     804    15894291 :   if (!signe(x)) return 0;
     805    26439355 :   for (i=lg(x)-2; i>1; i--)
     806    18325760 :     if (!isexactzero(gel(x,i))) return 0;
     807     8113595 :   return 1;
     808             : }
     809             : INLINE int
     810    27032277 : RgV_is_ZV(GEN x)
     811             : {
     812             :   long i;
     813   111359900 :   for (i = lg(x)-1; i > 0; i--)
     814    84329828 :     if (typ(gel(x,i)) != t_INT) return 0;
     815    27030072 :   return 1;
     816             : }
     817             : INLINE int
     818         798 : RgV_is_QV(GEN x)
     819             : {
     820             :   long i;
     821        1211 :   for (i = lg(x)-1; i > 0; i--)
     822        1078 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     823         133 :   return 1;
     824             : }
     825             : 
     826             : /********************************************************************/
     827             : /**                                                                **/
     828             : /**            Dynamic arrays implementation                       **/
     829             : /**                                                                **/
     830             : /********************************************************************/
     831             : INLINE void **
     832   405862531 : pari_stack_base(pari_stack *s) { return s->data; }
     833             : 
     834             : INLINE void
     835     1700712 : pari_stack_init(pari_stack *s, size_t size, void **data)
     836             : {
     837     1700712 :   s->data = data;
     838     1700712 :   *data = NULL;
     839     1700712 :   s->n = 0;
     840     1700712 :   s->alloc = 0;
     841     1700712 :   s->size = size;
     842     1700712 : }
     843             : 
     844             : INLINE void
     845   404209643 : pari_stack_alloc(pari_stack *s, long nb)
     846             : {
     847   404209643 :   void **sdat = pari_stack_base(s);
     848   404214039 :   long alloc = s->alloc;
     849   404214039 :   if (s->n+nb <= alloc) return;
     850      628479 :   if (!alloc)
     851      576841 :     alloc = nb;
     852             :   else
     853             :   {
     854       51638 :     while (s->n+nb > alloc) alloc <<= 1;
     855             :   }
     856      628479 :   *sdat = pari_realloc(*sdat,alloc*s->size);
     857      629081 :   s->alloc = alloc;
     858             : }
     859             : 
     860             : INLINE long
     861   326440150 : pari_stack_new(pari_stack *s) { pari_stack_alloc(s, 1); return s->n++; }
     862             : 
     863             : INLINE void
     864     1652291 : pari_stack_delete(pari_stack *s)
     865             : {
     866     1652291 :   void **sdat = pari_stack_base(s);
     867     1649825 :   if (*sdat) pari_free(*sdat);
     868     1659259 : }
     869             : 
     870             : INLINE void
     871        4773 : pari_stack_pushp(pari_stack *s, void *u)
     872             : {
     873        4773 :   long n = pari_stack_new(s);
     874        4773 :   void **sdat =(void**) *pari_stack_base(s);
     875        4773 :   sdat[n] = u;
     876        4773 : }
     877             : 
     878             : /*******************************************************************/
     879             : /*                                                                 */
     880             : /*                            EXTRACT                              */
     881             : /*                                                                 */
     882             : /*******************************************************************/
     883             : INLINE GEN
     884   197224648 : vecslice(GEN A, long y1, long y2)
     885             : {
     886   197224648 :   long i,lB = y2 - y1 + 2;
     887   197224648 :   GEN B = cgetg(lB, typ(A));
     888   197226362 :   for (i=1; i<lB; i++) B[i] = A[y1-1+i];
     889   197226362 :   return B;
     890             : }
     891             : INLINE GEN
     892      799585 : vecslicepermute(GEN A, GEN p, long y1, long y2)
     893             : {
     894      799585 :   long i,lB = y2 - y1 + 2;
     895      799585 :   GEN B = cgetg(lB, typ(A));
     896      799587 :   for (i=1; i<lB; i++) B[i] = A[p[y1-1+i]];
     897      799587 :   return B;
     898             : }
     899             : /* rowslice(rowpermute(A,p), x1, x2) */
     900             : INLINE GEN
     901       38458 : rowslicepermute(GEN x, GEN p, long j1, long j2)
     902       38458 : { pari_APPLY_same(vecslicepermute(gel(x,i),p,j1,j2)) }
     903             : 
     904             : INLINE GEN
     905    21830454 : rowslice(GEN x, long j1, long j2)
     906    21830454 : { pari_APPLY_same(vecslice(gel(x,i), j1, j2)) }
     907             : 
     908             : INLINE GEN
     909     3596625 : matslice(GEN A, long x1, long x2, long y1, long y2)
     910     3596625 : { return rowslice(vecslice(A, y1, y2), x1, x2); }
     911             : 
     912             : /* shallow, remove coeff of index j */
     913             : INLINE GEN
     914         133 : rowsplice(GEN x, long j)
     915         133 : { pari_APPLY_same(vecsplice(gel(x,i), j)) }
     916             : 
     917             : /* shallow, remove coeff of index j */
     918             : INLINE GEN
     919      252462 : vecsplice(GEN a, long j)
     920             : {
     921      252462 :   long i, k, l = lg(a);
     922             :   GEN b;
     923      252462 :   if (l == 1) pari_err(e_MISC, "incorrect component in vecsplice");
     924      252462 :   b = cgetg(l-1, typ(a));
     925     1006285 :   for (i = k = 1; i < l; i++)
     926      753823 :     if (i != j) gel(b, k++) = gel(a,i);
     927      252462 :   return b;
     928             : }
     929             : /* shallow */
     930             : INLINE GEN
     931         833 : RgM_minor(GEN a, long i, long j)
     932             : {
     933         833 :   GEN b = vecsplice(a, j);
     934         833 :   long k, l = lg(b);
     935         833 :   for (k = 1; k < l; k++) gel(b,k) = vecsplice(gel(b,k), i);
     936         833 :   return b;
     937             : }
     938             : 
     939             : /* A[x0,] */
     940             : INLINE GEN
     941      390121 : row(GEN x, long j)
     942      390121 : { pari_APPLY_type(t_VEC, gcoeff(x, j, i)) }
     943             : INLINE GEN
     944     3710395 : Flm_row(GEN x, long j)
     945     3710395 : { pari_APPLY_ulong((ulong)coeff(x, j, i)) }
     946             : /* A[x0,] */
     947             : INLINE GEN
     948      204820 : rowcopy(GEN x, long j)
     949      204820 : { pari_APPLY_type(t_VEC, gcopy(gcoeff(x, j, i))) }
     950             : /* A[x0, x1..x2] */
     951             : INLINE GEN
     952        2177 : row_i(GEN A, long x0, long x1, long x2)
     953             : {
     954        2177 :   long i, lB = x2 - x1 + 2;
     955        2177 :   GEN B  = cgetg(lB, t_VEC);
     956        2177 :   for (i=x1; i<=x2; i++) gel(B, i) = gcoeff(A, x0, i);
     957        2177 :   return B;
     958             : }
     959             : 
     960             : INLINE GEN
     961     5830336 : vecreverse(GEN A)
     962             : {
     963             :   long i, l;
     964     5830336 :   GEN B = cgetg_copy(A, &l);
     965     5830336 :   for (i=1; i<l; i++) gel(B, i) = gel(A, l-i);
     966     5830336 :   return B;
     967             : }
     968             : 
     969             : INLINE GEN
     970         252 : vecsmall_reverse(GEN A)
     971             : {
     972             :   long i, l;
     973         252 :   GEN B = cgetg_copy(A, &l);
     974         252 :   for (i=1; i<l; i++) B[i] = A[l-i];
     975         252 :   return B;
     976             : }
     977             : 
     978             : INLINE void
     979         260 : vecreverse_inplace(GEN y)
     980             : {
     981         260 :   long l = lg(y), lim = l>>1, i;
     982         724 :   for (i = 1; i <= lim; i++)
     983             :   {
     984         464 :     GEN z = gel(y,i);
     985         464 :     gel(y,i)    = gel(y,l-i);
     986         464 :     gel(y,l-i) = z;
     987             :   }
     988         260 : }
     989             : 
     990             : INLINE GEN
     991    44848418 : vecsmallpermute(GEN A, GEN p) { return perm_mul(A, p); }
     992             : 
     993             : INLINE GEN
     994     6211221 : vecpermute(GEN A, GEN x)
     995     6211221 : { pari_APPLY_type(typ(A), gel(A, x[i])) }
     996             : 
     997             : INLINE GEN
     998     2954525 : rowpermute(GEN x, GEN p)
     999     2954525 : { pari_APPLY_same(typ(gel(x,i)) == t_VECSMALL ? vecsmallpermute(gel(x, i), p)
    1000             :                                               : vecpermute(gel(x, i), p))
    1001             : }
    1002             : /*******************************************************************/
    1003             : /*                                                                 */
    1004             : /*                          PERMUTATIONS                           */
    1005             : /*                                                                 */
    1006             : /*******************************************************************/
    1007             : /* identity permutation */
    1008             : INLINE GEN
    1009      716750 : identity_perm(long n)
    1010             : {
    1011      716750 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1012             :   long i;
    1013      716746 :   for (i = 1; i <= n; i++) perm[i] = i;
    1014      716746 :   return perm;
    1015             : }
    1016             : 
    1017             : /* assume d <= n */
    1018             : INLINE GEN
    1019       98434 : cyclic_perm(long n, long d)
    1020             : {
    1021       98434 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1022             :   long i;
    1023       98434 :   for (i = 1; i <= n-d; i++) perm[i] = i+d;
    1024       98434 :   for (     ; i <= n;   i++) perm[i] = i-n+d;
    1025       98434 :   return perm;
    1026             : }
    1027             : 
    1028             : /* Multiply (compose) two permutations */
    1029             : INLINE GEN
    1030    46088599 : perm_mul(GEN s, GEN x)
    1031    46088599 : { pari_APPLY_long(s[x[i]]) }
    1032             : 
    1033             : /* Compute the inverse (reciprocal) of a permutation. */
    1034             : INLINE GEN
    1035     1153297 : perm_inv(GEN x)
    1036             : {
    1037             :   long i, lx;
    1038     1153297 :   GEN y = cgetg_copy(x, &lx);
    1039     1153297 :   for (i=1; i<lx; i++) y[ x[i] ] = i;
    1040     1153297 :   return y;
    1041             : }
    1042             : /* Return s*t*s^-1 */
    1043             : INLINE GEN
    1044      416934 : perm_conj(GEN s, GEN t)
    1045             : {
    1046             :   long i, l;
    1047      416934 :   GEN v = cgetg_copy(s, &l);
    1048      416934 :   for (i = 1; i < l; i++) v[ s[i] ] = s[ t[i] ];
    1049      416934 :   return v;
    1050             : }
    1051             : 
    1052             : /*********************************************************************/
    1053             : /*                       MALLOC/FREE WRAPPERS                        */
    1054             : /*********************************************************************/
    1055             : #define BLOCK_SIGALRM_START          \
    1056             : {                                    \
    1057             :   int block=PARI_SIGINT_block;       \
    1058             :   PARI_SIGINT_block = 2;             \
    1059             :   MT_SIGINT_BLOCK(block);
    1060             : 
    1061             : #define BLOCK_SIGINT_START           \
    1062             : {                                    \
    1063             :   int block=PARI_SIGINT_block;       \
    1064             :   PARI_SIGINT_block = 1;             \
    1065             :   MT_SIGINT_BLOCK(block);
    1066             : 
    1067             : #define BLOCK_SIGINT_END             \
    1068             :   PARI_SIGINT_block = block;         \
    1069             :   MT_SIGINT_UNBLOCK(block);          \
    1070             :   if (!block && PARI_SIGINT_pending) \
    1071             :   {                                  \
    1072             :     int sig = PARI_SIGINT_pending;   \
    1073             :     PARI_SIGINT_pending = 0;         \
    1074             :     raise(sig);                      \
    1075             :   }                                  \
    1076             : }
    1077             : 
    1078             : INLINE void
    1079    65568482 : pari_free(void *pointer)
    1080             : {
    1081    65568482 :   BLOCK_SIGINT_START;
    1082    65584616 :   free(pointer);
    1083    65584616 :   BLOCK_SIGINT_END;
    1084    65581620 : }
    1085             : INLINE void*
    1086   277403696 : pari_malloc(size_t size)
    1087             : {
    1088   277403696 :   if (size)
    1089             :   {
    1090             :     char *tmp;
    1091   277403696 :     BLOCK_SIGINT_START;
    1092   277406168 :     tmp = (char*)malloc(size);
    1093   277406168 :     BLOCK_SIGINT_END;
    1094   277405966 :     if (!tmp) pari_err(e_MEM);
    1095   277405966 :     return tmp;
    1096             :   }
    1097           0 :   return NULL;
    1098             : }
    1099             : INLINE void*
    1100      640165 : pari_realloc(void *pointer, size_t size)
    1101             : {
    1102             :   char *tmp;
    1103             : 
    1104      640165 :   BLOCK_SIGINT_START;
    1105      641516 :   if (!pointer) tmp = (char *) malloc(size);
    1106       55414 :   else tmp = (char *) realloc(pointer,size);
    1107      641516 :   BLOCK_SIGINT_END;
    1108      641116 :   if (!tmp) pari_err(e_MEM);
    1109      641116 :   return tmp;
    1110             : }
    1111             : INLINE void*
    1112       35158 : pari_calloc(size_t size)
    1113             : {
    1114       35158 :   void *t = pari_malloc(size);
    1115       35158 :   memset(t, 0, size); return t;
    1116             : }
    1117             : INLINE GEN
    1118        5771 : cgetalloc(long t, size_t l)
    1119             : {
    1120        5771 :   GEN x = (GEN)pari_malloc(l * sizeof(long));
    1121        5771 :   x[0] = evaltyp(t) | evallg(l); return x;
    1122             : }
    1123             : 
    1124             : /*******************************************************************/
    1125             : /*                                                                 */
    1126             : /*                       GARBAGE COLLECTION                        */
    1127             : /*                                                                 */
    1128             : /*******************************************************************/
    1129             : /* copy integer x as if we had set_avma(av) */
    1130             : INLINE GEN
    1131  3717969350 : icopy_avma(GEN x, pari_sp av)
    1132             : {
    1133  3717969350 :   long i = lgefint(x), lx = i;
    1134  3717969350 :   GEN y = ((GEN)av) - i;
    1135  3717969350 :   while (--i > 0) y[i] = x[i];
    1136  3717969350 :   y[0] = evaltyp(t_INT)|evallg(lx);
    1137  3717747073 :   return y;
    1138             : }
    1139             : /* copy leaf x as if we had set_avma(av) */
    1140             : INLINE GEN
    1141   172633262 : leafcopy_avma(GEN x, pari_sp av)
    1142             : {
    1143   172633262 :   long i = lg(x);
    1144   172633262 :   GEN y = ((GEN)av) - i;
    1145   172633262 :   while (--i > 0) y[i] = x[i];
    1146   172633262 :   y[0] = x[0] & (~CLONEBIT);
    1147   172633262 :   return y;
    1148             : }
    1149             : INLINE GEN
    1150   628916885 : gerepileuptoleaf(pari_sp av, GEN x)
    1151             : {
    1152             :   long lx;
    1153             :   GEN q;
    1154             : 
    1155   628916885 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1156   631039155 :   lx = lg(x);
    1157   631039155 :   q = ((GEN)av) - lx;
    1158   631039155 :   avma = (pari_sp)q;
    1159   631039155 :   while (--lx >= 0) q[lx] = x[lx];
    1160   631039155 :   return q;
    1161             : }
    1162             : INLINE GEN
    1163  1214487459 : gerepileuptoint(pari_sp av, GEN x)
    1164             : {
    1165  1214487459 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1166  1068490856 :   avma = (pari_sp)icopy_avma(x, av);
    1167  1070445868 :   return (GEN)avma;
    1168             : }
    1169             : INLINE GEN
    1170   759722934 : gerepileupto(pari_sp av, GEN x)
    1171             : {
    1172   759722934 :   if (!isonstack(x) || (GEN)av<=x) { set_avma(av); return x; }
    1173   663349390 :   switch(typ(x))
    1174             :   { /* non-default = !is_recursive_t(tq) */
    1175   220649592 :     case t_INT: return gerepileuptoint(av, x);
    1176             :     case t_REAL:
    1177             :     case t_STR:
    1178   148049107 :     case t_VECSMALL: return gerepileuptoleaf(av,x);
    1179             :     default:
    1180             :       /* NB: x+i --> ((long)x) + i*sizeof(long) */
    1181   294650691 :       return gerepile(av, (pari_sp) (x+lg(x)), x);
    1182             :   }
    1183             : }
    1184             : 
    1185             : /* gerepileupto(av, gcopy(x)) */
    1186             : INLINE GEN
    1187    46968145 : gerepilecopy(pari_sp av, GEN x)
    1188             : {
    1189    46968145 :   if (is_recursive_t(typ(x)))
    1190             :   {
    1191    42384814 :     GENbin *p = copy_bin(x);
    1192    42384851 :     set_avma(av); return bin_copy(p);
    1193             :   }
    1194             :   else
    1195             :   {
    1196     4583333 :     set_avma(av);
    1197     4583333 :     if (x < (GEN)av) {
    1198     3095910 :       if (x < (GEN)pari_mainstack->bot) new_chunk(lg(x));
    1199     3095910 :       x = leafcopy_avma(x, av);
    1200     3095915 :       avma = (pari_sp)x;
    1201             :     } else
    1202     1487423 :       x = leafcopy(x);
    1203     4583338 :     return x;
    1204             :   }
    1205             : }
    1206             : 
    1207             : /* Takes an array of pointers to GENs, of length n. Copies all
    1208             :  * objects to contiguous locations and cleans up the stack between
    1209             :  * av and avma. */
    1210             : INLINE void
    1211      136131 : gerepilemany(pari_sp av, GEN* gptr[], int n)
    1212             : {
    1213             :   int i;
    1214      136131 :   for (i=0; i<n; i++) *gptr[i] = (GEN)copy_bin(*gptr[i]);
    1215      136131 :   set_avma(av);
    1216      136131 :   for (i=0; i<n; i++) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1217      136131 : }
    1218             : 
    1219             : INLINE void
    1220     7478712 : gerepileall(pari_sp av, int n, ...)
    1221             : {
    1222             :   int i;
    1223     7478712 :   va_list a; va_start(a, n);
    1224     7478712 :   if (n < 10)
    1225             :   {
    1226             :     GEN *gptr[10];
    1227    21621605 :     for (i=0; i<n; i++)
    1228    14142878 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1229     7478727 :     set_avma(av);
    1230     7478623 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1231             : 
    1232             :   }
    1233             :   else
    1234             :   {
    1235           0 :     GEN **gptr = (GEN**)  pari_malloc(n*sizeof(GEN*));
    1236           0 :     for (i=0; i<n; i++)
    1237           0 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1238           0 :     set_avma(av);
    1239           0 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1240           0 :     pari_free(gptr);
    1241             :   }
    1242     7478819 :   va_end(a);
    1243     7478819 : }
    1244             : 
    1245             : INLINE void
    1246          14 : gerepilecoeffs(pari_sp av, GEN x, int n)
    1247             : {
    1248             :   int i;
    1249          14 :   for (i=0; i<n; i++) gel(x,i) = (GEN)copy_bin(gel(x,i));
    1250          14 :   set_avma(av);
    1251          14 :   for (i=0; i<n; i++) gel(x,i) = bin_copy((GENbin*)x[i]);
    1252          14 : }
    1253             : 
    1254             : /* p from copy_bin. Copy p->x back to stack, then destroy p */
    1255             : INLINE GEN
    1256    56953887 : bin_copy(GENbin *p)
    1257             : {
    1258             :   GEN x, y, base;
    1259             :   long dx, len;
    1260             : 
    1261    56953887 :   x   = p->x; if (!x) { pari_free(p); return gen_0; }
    1262    56946765 :   len = p->len;
    1263    56946765 :   base= p->base; dx = x - base;
    1264    56946765 :   y = (GEN)memcpy((void*)new_chunk(len), (void*)GENbinbase(p), len*sizeof(long));
    1265    56946668 :   y += dx;
    1266    56946668 :   p->rebase(y, ((ulong)y-(ulong)x));
    1267    56946603 :   pari_free(p); return y;
    1268             : }
    1269             : 
    1270             : INLINE GEN
    1271   113900860 : GENbinbase(GENbin *p) { return (GEN)(p + 1); }
    1272             : 
    1273             : INLINE void
    1274    31466317 : cgiv(GEN x)
    1275             : {
    1276    31466317 :   pari_sp av = (pari_sp)(x+lg(x));
    1277    31466317 :   if (isonstack((GEN)av)) set_avma(av);
    1278    31466042 : }
    1279             : 
    1280             : INLINE void
    1281     1256604 : killblock(GEN x) { gunclone(x); }
    1282             : 
    1283             : INLINE int
    1284    24156193 : is_universal_constant(GEN x) { return (x >= gen_0 && x <= ghalf); }
    1285             : 
    1286             : /*******************************************************************/
    1287             : /*                                                                 */
    1288             : /*                    CONVERSION / ASSIGNMENT                      */
    1289             : /*                                                                 */
    1290             : /*******************************************************************/
    1291             : /* z is a type which may be a t_COMPLEX component (not a t_QUAD) */
    1292             : INLINE GEN
    1293     3288034 : cxcompotor(GEN z, long prec)
    1294             : {
    1295     3288034 :   switch(typ(z))
    1296             :   {
    1297     1752228 :     case t_INT:  return itor(z, prec);
    1298      134155 :     case t_FRAC: return fractor(z, prec);
    1299     1401651 :     case t_REAL: return rtor(z, prec);
    1300           0 :     default: pari_err_TYPE("cxcompotor",z);
    1301             :              return NULL; /* LCOV_EXCL_LINE */
    1302             :   }
    1303             : }
    1304             : INLINE GEN
    1305     1630694 : cxtofp(GEN x, long prec)
    1306     1630694 : { retmkcomplex(cxcompotor(gel(x,1),prec), cxcompotor(gel(x,2),prec)); }
    1307             : 
    1308             : INLINE GEN
    1309      217474 : cxtoreal(GEN q)
    1310      217474 : { return (typ(q) == t_COMPLEX && gequal0(gel(q,2)))? gel(q,1): q; }
    1311             : 
    1312             : INLINE double
    1313    33565511 : gtodouble(GEN x)
    1314             : {
    1315    33565511 :   if (typ(x)!=t_REAL) {
    1316     7429543 :     pari_sp av = avma;
    1317     7429543 :     x = gtofp(x, DEFAULTPREC);
    1318     7429543 :     if (typ(x)!=t_REAL) pari_err_TYPE("gtodouble [t_REAL expected]", x);
    1319     7429543 :     set_avma(av);
    1320             :   }
    1321    33565511 :   return rtodbl(x);
    1322             : }
    1323             : INLINE long
    1324    73013229 : gtos(GEN x) {
    1325    73013229 :   if (typ(x) != t_INT) pari_err_TYPE("gtos [integer expected]",x);
    1326    73013222 :   return itos(x);
    1327             : }
    1328             : 
    1329             : INLINE ulong
    1330      122944 : gtou(GEN x) {
    1331      122944 :   if (typ(x) != t_INT || signe(x)<0)
    1332           0 :     pari_err_TYPE("gtou [integer >=0 expected]",x);
    1333      122962 :   return itou(x);
    1334             : }
    1335             : 
    1336             : INLINE GEN
    1337    21933443 : absfrac(GEN x)
    1338             : {
    1339    21933443 :   GEN y = cgetg(3, t_FRAC);
    1340    21933443 :   gel(y,1) = absi(gel(x,1));
    1341    21933443 :   gel(y,2) = icopy(gel(x,2)); return y;
    1342             : }
    1343             : INLINE GEN
    1344       32434 : absfrac_shallow(GEN x)
    1345       32434 : { return signe(gel(x,1))>0? x: mkfrac(negi(gel(x,1)), gel(x,2)); }
    1346             : INLINE GEN
    1347     7545307 : Q_abs(GEN x) { return (typ(x) == t_INT)? absi(x): absfrac(x); }
    1348             : INLINE GEN
    1349      113706 : Q_abs_shallow(GEN x)
    1350      113706 : { return (typ(x) == t_INT)? absi_shallow(x): absfrac_shallow(x); }
    1351             : INLINE GEN
    1352         322 : R_abs_shallow(GEN x)
    1353         322 : { return (typ(x) == t_FRAC)? absfrac_shallow(x): mpabs_shallow(x); }
    1354             : INLINE GEN
    1355           0 : R_abs(GEN x)
    1356           0 : { return (typ(x) == t_FRAC)? absfrac(x): mpabs(x); }
    1357             : 
    1358             : /* Force z to be of type real/complex with floating point components */
    1359             : INLINE GEN
    1360    35271508 : gtofp(GEN z, long prec)
    1361             : {
    1362    35271508 :   switch(typ(z))
    1363             :   {
    1364    22132475 :     case t_INT:  return itor(z, prec);
    1365     4309030 :     case t_FRAC: return fractor(z, prec);
    1366     7399318 :     case t_REAL: return rtor(z, prec);
    1367             :     case t_COMPLEX: {
    1368     1430685 :       GEN a = gel(z,1), b = gel(z,2);
    1369     1430685 :       if (isintzero(b)) return cxcompotor(a, prec);
    1370     1428274 :       if (isintzero(a)) {
    1371        2041 :         GEN y = cgetg(3, t_COMPLEX);
    1372        2041 :         b = cxcompotor(b, prec);
    1373        2041 :         gel(y,1) = real_0_bit(expo(b) - prec2nbits(prec));
    1374        2041 :         gel(y,2) = b; return y;
    1375             :       }
    1376     1426233 :       return cxtofp(z, prec);
    1377             :     }
    1378           0 :     case t_QUAD: return quadtofp(z, prec);
    1379           0 :     default: pari_err_TYPE("gtofp",z);
    1380             :              return NULL; /* LCOV_EXCL_LINE */
    1381             :   }
    1382             : }
    1383             : /* Force z to be of type real / int */
    1384             : INLINE GEN
    1385       22400 : gtomp(GEN z, long prec)
    1386             : {
    1387       22400 :   switch(typ(z))
    1388             :   {
    1389          14 :     case t_INT:  return z;
    1390       22386 :     case t_FRAC: return fractor(z, prec);
    1391           0 :     case t_REAL: return rtor(z, prec);
    1392           0 :     case t_QUAD: z = quadtofp(z, prec);
    1393           0 :                  if (typ(z) == t_REAL) return z;
    1394           0 :     default: pari_err_TYPE("gtomp",z);
    1395             :              return NULL; /* LCOV_EXCL_LINE */
    1396             :   }
    1397             : }
    1398             : 
    1399             : INLINE GEN
    1400      732423 : RgX_gtofp(GEN x, long prec)
    1401             : {
    1402             :   long l;
    1403      732423 :   GEN y = cgetg_copy(x, &l);
    1404      732423 :   while (--l > 1) gel(y,l) = gtofp(gel(x,l), prec);
    1405      732423 :   y[1] = x[1]; return y;
    1406             : }
    1407             : INLINE GEN
    1408     1176608 : RgC_gtofp(GEN x, long prec)
    1409     1176608 : { pari_APPLY_type(t_COL, gtofp(gel(x,i), prec)) }
    1410             : 
    1411             : INLINE GEN
    1412          42 : RgV_gtofp(GEN x, long prec)
    1413          42 : { pari_APPLY_type(t_VEC, gtofp(gel(x,i), prec)) }
    1414             : 
    1415             : INLINE GEN
    1416      133885 : RgM_gtofp(GEN x, long prec)
    1417      133885 : { pari_APPLY_same(RgC_gtofp(gel(x,i), prec)) }
    1418             : 
    1419             : INLINE GEN
    1420         560 : RgC_gtomp(GEN x, long prec)
    1421         560 : { pari_APPLY_type(t_COL, gtomp(gel(x,i), prec)) }
    1422             : 
    1423             : INLINE GEN
    1424          14 : RgM_gtomp(GEN x, long prec)
    1425          14 : { pari_APPLY_same(RgC_gtomp(gel(x,i), prec)) }
    1426             : 
    1427             : INLINE GEN
    1428        9122 : RgX_fpnorml2(GEN x, long prec)
    1429             : {
    1430        9122 :   pari_sp av = avma;
    1431        9122 :   return gerepileupto(av, gnorml2(RgX_gtofp(x, prec)));
    1432             : }
    1433             : INLINE GEN
    1434      177877 : RgC_fpnorml2(GEN x, long prec)
    1435             : {
    1436      177877 :   pari_sp av = avma;
    1437      177877 :   return gerepileupto(av, gnorml2(RgC_gtofp(x, prec)));
    1438             : }
    1439             : INLINE GEN
    1440        3804 : RgM_fpnorml2(GEN x, long prec)
    1441             : {
    1442        3804 :   pari_sp av = avma;
    1443        3804 :   return gerepileupto(av, gnorml2(RgM_gtofp(x, prec)));
    1444             : }
    1445             : 
    1446             : /* y a t_REAL */
    1447             : INLINE void
    1448      216244 : affgr(GEN x, GEN y)
    1449             : {
    1450             :   pari_sp av;
    1451      216244 :   switch(typ(x)) {
    1452        5992 :     case t_INT:  affir(x,y); break;
    1453      210252 :     case t_REAL: affrr(x,y); break;
    1454           0 :     case t_FRAC: rdiviiz(gel(x,1),gel(x,2), y); break;
    1455           0 :     case t_QUAD: av = avma; affgr(quadtofp(x,realprec(y)), y); set_avma(av); break;
    1456           0 :     default: pari_err_TYPE2("=",x,y);
    1457             :   }
    1458      216244 : }
    1459             : 
    1460             : INLINE GEN
    1461      187262 : affc_fixlg(GEN x, GEN res)
    1462             : {
    1463      187262 :   if (typ(x) == t_COMPLEX)
    1464             :   {
    1465      175700 :     affrr_fixlg(gel(x,1), gel(res,1));
    1466      175700 :     affrr_fixlg(gel(x,2), gel(res,2));
    1467             :   }
    1468             :   else
    1469             :   {
    1470       11562 :     avma = (pari_sp)(res+3);
    1471       11562 :     res = cgetr(realprec(gel(res,1)));
    1472       11562 :     affrr_fixlg(x, res);
    1473             :   }
    1474      187262 :   return res;
    1475             : }
    1476             : 
    1477             : INLINE GEN
    1478           0 : trunc_safe(GEN x) { long e; return gcvtoi(x,&e); }
    1479             : 
    1480             : /*******************************************************************/
    1481             : /*                                                                 */
    1482             : /*                          LENGTH CONVERSIONS                     */
    1483             : /*                                                                 */
    1484             : /*******************************************************************/
    1485             : INLINE long
    1486       28204 : ndec2nlong(long x) { return 1 + (long)((x)*(LOG2_10/BITS_IN_LONG)); }
    1487             : INLINE long
    1488       27721 : ndec2prec(long x) { return 2 + ndec2nlong(x); }
    1489             : INLINE long
    1490         483 : ndec2nbits(long x) { return ndec2nlong(x) << TWOPOTBITS_IN_LONG; }
    1491             : /* Fast implementation of ceil(x / (8*sizeof(long))); typecast to (ulong)
    1492             :  * to avoid overflow. Faster than 1 + ((x-1)>>TWOPOTBITS_IN_LONG)) :
    1493             :  *   addl, shrl instead of subl, sarl, addl */
    1494             : INLINE long
    1495     1186396 : nbits2nlong(long x) {
    1496     1186396 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1497             : }
    1498             : 
    1499             : INLINE long
    1500   288561867 : nbits2extraprec(long x) {
    1501   288561867 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1502             : }
    1503             : 
    1504             : /* Fast implementation of 2 + nbits2nlong(x) */
    1505             : INLINE long
    1506   106931026 : nbits2prec(long x) {
    1507   106931026 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1508             : }
    1509             : INLINE long
    1510     7636512 : nbits2lg(long x) {
    1511     7636512 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1512             : }
    1513             : /* ceil(x / sizeof(long)) */
    1514             : INLINE long
    1515     8603545 : nchar2nlong(long x) {
    1516     8603545 :   return (long)(((ulong)x+sizeof(long)-1) >> (TWOPOTBITS_IN_LONG-3L));
    1517             : }
    1518             : INLINE long
    1519  1112035218 : prec2nbits(long x) { return (x-2) * BITS_IN_LONG; }
    1520             : INLINE double
    1521      563778 : bit_accuracy_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1522             : INLINE double
    1523      235157 : prec2nbits_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1524             : INLINE long
    1525    31700863 : bit_prec(GEN x) { return prec2nbits(realprec(x)); }
    1526             : INLINE long
    1527  1004156006 : bit_accuracy(long x) { return prec2nbits(x); }
    1528             : INLINE long
    1529       12365 : prec2ndec(long x) { return (long)prec2nbits_mul(x, LOG10_2); }
    1530             : INLINE long
    1531         186 : nbits2ndec(long x) { return (long)(x * LOG10_2); }
    1532             : INLINE long
    1533        1743 : precdbl(long x) {return (x - 1) << 1;}
    1534             : INLINE long
    1535  3315246815 : divsBIL(long n) { return n >> TWOPOTBITS_IN_LONG; }
    1536             : INLINE long
    1537  3274505424 : remsBIL(long n) { return n & (BITS_IN_LONG-1); }
    1538             : 
    1539             : /*********************************************************************/
    1540             : /**                                                                 **/
    1541             : /**                      OPERATIONS MODULO m                        **/
    1542             : /**                                                                 **/
    1543             : /*********************************************************************/
    1544             : /* Assume m > 0, more efficient if 0 <= a, b < m */
    1545             : 
    1546             : INLINE GEN
    1547    33685214 : Fp_red(GEN a, GEN m) { return modii(a, m); }
    1548             : INLINE GEN
    1549    71984215 : Fp_add(GEN a, GEN b, GEN m)
    1550             : {
    1551    71984215 :   pari_sp av=avma;
    1552    71984215 :   GEN p = addii(a,b);
    1553    70273060 :   long s = signe(p);
    1554    70273060 :   if (!s) return p; /* = gen_0 */
    1555    62665460 :   if (s > 0) /* general case */
    1556             :   {
    1557    62439036 :     GEN t = subii(p, m);
    1558    63465173 :     s = signe(t);
    1559    63465173 :     if (!s) { set_avma(av); return gen_0; }
    1560    57681617 :     if (s < 0) { avma = (pari_sp)p; return p; }
    1561    24312257 :     if (cmpii(t, m) < 0) return gerepileuptoint(av, t); /* general case ! */
    1562     1105970 :     p = remii(t, m);
    1563             :   }
    1564             :   else
    1565      226424 :     p = modii(p, m);
    1566     1332394 :   return gerepileuptoint(av, p);
    1567             : }
    1568             : INLINE GEN
    1569    56955467 : Fp_sub(GEN a, GEN b, GEN m)
    1570             : {
    1571    56955467 :   pari_sp av=avma;
    1572    56955467 :   GEN p = subii(a,b);
    1573    55546021 :   long s = signe(p);
    1574    55546021 :   if (!s) return p; /* = gen_0 */
    1575    49283914 :   if (s > 0)
    1576             :   {
    1577    23825842 :     if (cmpii(p, m) < 0) return p; /* general case ! */
    1578     1120593 :     p = remii(p, m);
    1579             :   }
    1580             :   else
    1581             :   {
    1582    25458072 :     GEN t = addii(p, m);
    1583    25381557 :     if (!s) { set_avma(av); return gen_0; }
    1584    25381557 :     if (s > 0) return gerepileuptoint(av, t); /* general case ! */
    1585    25381557 :     p = modii(t, m);
    1586             :   }
    1587    27218492 :   return gerepileuptoint(av, p);
    1588             : }
    1589             : INLINE GEN
    1590    11622292 : Fp_neg(GEN b, GEN m)
    1591             : {
    1592    11622292 :   pari_sp av = avma;
    1593    11622292 :   long s = signe(b);
    1594             :   GEN p;
    1595    11622292 :   if (!s) return gen_0;
    1596     8190169 :   if (s > 0)
    1597             :   {
    1598     7990044 :     p = subii(m, b);
    1599     7988218 :     if (signe(p) >= 0) return p; /* general case ! */
    1600       92070 :     p = modii(p, m);
    1601             :   } else
    1602      200125 :     p = remii(negi(b), m);
    1603      292195 :   return gerepileuptoint(av, p);
    1604             : }
    1605             : 
    1606             : INLINE GEN
    1607       23592 : Fp_halve(GEN a, GEN p)
    1608             : {
    1609       23592 :   if (mpodd(a)) a = addii(a,p);
    1610       23592 :   return shifti(a,-1);
    1611             : }
    1612             : 
    1613             : /* assume 0 <= u < p and ps2 = p>>1 */
    1614             : INLINE GEN
    1615    16315021 : Fp_center(GEN u, GEN p, GEN ps2)
    1616    16315021 : { return abscmpii(u,ps2)<=0? icopy(u): subii(u,p); }
    1617             : /* same without copy */
    1618             : INLINE GEN
    1619    14912303 : Fp_center_i(GEN u, GEN p, GEN ps2)
    1620    14912303 : { return abscmpii(u,ps2)<=0? u: subii(u,p); }
    1621             : 
    1622             : /* x + y*z mod p */
    1623             : INLINE GEN
    1624     5034022 : Fp_addmul(GEN x, GEN y, GEN z, GEN p)
    1625             : {
    1626             :   pari_sp av;
    1627     5034022 :   if (!signe(y) || !signe(z)) return Fp_red(x, p);
    1628     4742281 :   if (!signe(x)) return Fp_mul(z,y, p);
    1629     4441471 :   av = avma;
    1630     4441471 :   return gerepileuptoint(av, modii(addii(x, mulii(y,z)), p));
    1631             : }
    1632             : 
    1633             : INLINE GEN
    1634    90724292 : Fp_mul(GEN a, GEN b, GEN m)
    1635             : {
    1636    90724292 :   pari_sp av=avma;
    1637             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1638    90724292 :   (void)new_chunk(lg(a)+lg(b)+(lg(m)<<1));
    1639    90720943 :   p = mulii(a,b);
    1640    90812760 :   set_avma(av); return modii(p,m);
    1641             : }
    1642             : INLINE GEN
    1643    34089955 : Fp_sqr(GEN a, GEN m)
    1644             : {
    1645    34089955 :   pari_sp av=avma;
    1646             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1647    34089955 :   (void)new_chunk((lg(a)+lg(m))<<1);
    1648    33980720 :   p = sqri(a);
    1649    30341985 :   set_avma(av); return remii(p,m); /*Use remii: p >= 0 */
    1650             : }
    1651             : INLINE GEN
    1652    65255812 : Fp_mulu(GEN a, ulong b, GEN m)
    1653             : {
    1654    65255812 :   long l = lgefint(m);
    1655    65255812 :   if (l == 3)
    1656             :   {
    1657    39146290 :     ulong mm = m[2];
    1658    39146290 :     return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1659             :   } else {
    1660    26109522 :     pari_sp av = avma;
    1661             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1662    26109522 :     (void)new_chunk(lg(a)+1+(l<<1));
    1663    26025201 :     p = muliu(a,b);
    1664    24226120 :     set_avma(av); return modii(p,m);
    1665             :   }
    1666             : }
    1667             : INLINE GEN
    1668           0 : Fp_muls(GEN a, long b, GEN m)
    1669             : {
    1670           0 :   long l = lgefint(m);
    1671           0 :   if (l == 3)
    1672             :   {
    1673           0 :     ulong mm = m[2];
    1674           0 :     if (b < 0)
    1675             :     {
    1676           0 :       ulong t = Fl_mul(umodiu(a, mm), -b, mm);
    1677           0 :       return t? utoipos(mm - t): gen_0;
    1678             :     }
    1679             :     else
    1680           0 :       return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1681             :   } else {
    1682           0 :     pari_sp av = avma;
    1683             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1684           0 :     (void)new_chunk(lg(a)+1+(l<<1));
    1685           0 :     p = mulis(a,b);
    1686           0 :     set_avma(av); return modii(p,m);
    1687             :   }
    1688             : }
    1689             : 
    1690             : INLINE GEN
    1691     8714295 : Fp_inv(GEN a, GEN m)
    1692             : {
    1693             :   GEN res;
    1694     8714295 :   if (! invmod(a,m,&res)) pari_err_INV("Fp_inv", mkintmod(res,m));
    1695     8714125 :   return res;
    1696             : }
    1697             : INLINE GEN
    1698      313875 : Fp_invsafe(GEN a, GEN m)
    1699             : {
    1700             :   GEN res;
    1701      313875 :   if (! invmod(a,m,&res)) return NULL;
    1702      313875 :   return res;
    1703             : }
    1704             : INLINE GEN
    1705     2366864 : Fp_div(GEN a, GEN b, GEN m)
    1706             : {
    1707     2366864 :   pari_sp av=avma;
    1708             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1709     2366864 :   (void)new_chunk(lg(a)+(lg(m)<<1));
    1710     2366864 :   p = mulii(a, Fp_inv(b,m));
    1711     2366862 :   set_avma(av); return modii(p,m);
    1712             : }
    1713             : 
    1714             : INLINE GEN
    1715      842951 : Flx_mulu(GEN x, ulong a, ulong p) { return Flx_Fl_mul(x,a%p,p); }
    1716             : 
    1717             : INLINE GEN
    1718           0 : get_F2x_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1719             : 
    1720             : INLINE long
    1721      448468 : get_F2x_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1722             : 
    1723             : INLINE long
    1724      121548 : get_F2x_degree(GEN T) { return typ(T)==t_VEC? F2x_degree(gel(T,2)): F2x_degree(T); }
    1725             : 
    1726             : INLINE GEN
    1727         378 : get_F2xqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1728             : 
    1729             : INLINE long
    1730      376495 : get_F2xqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1731             : 
    1732             : INLINE long
    1733      201684 : get_F2xqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1734             : 
    1735             : INLINE GEN
    1736     7447300 : get_Flx_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1737             : 
    1738             : INLINE long
    1739    20031015 : get_Flx_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1740             : 
    1741             : INLINE long
    1742    31097427 : get_Flx_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1743             : 
    1744             : INLINE GEN
    1745        2258 : get_FlxqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1746             : 
    1747             : INLINE long
    1748      368931 : get_FlxqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1749             : 
    1750             : INLINE long
    1751      155787 : get_FlxqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1752             : 
    1753             : INLINE GEN
    1754     1608383 : get_FpX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1755             : 
    1756             : INLINE long
    1757     2891020 : get_FpX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1758             : 
    1759             : INLINE long
    1760     1881843 : get_FpX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1761             : 
    1762             : INLINE GEN
    1763      142586 : get_FpXQX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1764             : 
    1765             : INLINE long
    1766       57357 : get_FpXQX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1767             : 
    1768             : INLINE long
    1769        2187 : get_FpXQX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1770             : 
    1771             : /*******************************************************************/
    1772             : /*                                                                 */
    1773             : /*                        ADDMULII / SUBMULII                      */
    1774             : /*                                                                 */
    1775             : /*******************************************************************/
    1776             : /* x - y*z */
    1777             : INLINE GEN
    1778    13409827 : submulii(GEN x, GEN y, GEN z)
    1779             : {
    1780    13409827 :   long lx = lgefint(x), ly, lz;
    1781             :   pari_sp av;
    1782             :   GEN t;
    1783    13409827 :   if (lx == 2) { t = mulii(z,y); togglesign(t); return t; }
    1784    11599698 :   ly = lgefint(y);
    1785    11599698 :   if (ly == 2) return icopy(x);
    1786    10471470 :   lz = lgefint(z);
    1787    10471470 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1788    10471470 :   t = mulii(z, y);
    1789    10471470 :   set_avma(av); return subii(x,t);
    1790             : }
    1791             : /* y*z - x */
    1792             : INLINE GEN
    1793     1188646 : mulsubii(GEN y, GEN z, GEN x)
    1794             : {
    1795     1188646 :   long lx = lgefint(x), ly, lz;
    1796             :   pari_sp av;
    1797             :   GEN t;
    1798     1188646 :   if (lx == 2) return mulii(z,y);
    1799      759394 :   ly = lgefint(y);
    1800      759394 :   if (ly == 2) return negi(x);
    1801      703302 :   lz = lgefint(z);
    1802      703302 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1803      703302 :   t = mulii(z, y);
    1804      703302 :   set_avma(av); return subii(t,x);
    1805             : }
    1806             : 
    1807             : /* x - u*y */
    1808             : INLINE GEN
    1809        7595 : submuliu(GEN x, GEN y, ulong u)
    1810             : {
    1811             :   pari_sp av;
    1812        7595 :   long ly = lgefint(y);
    1813        7595 :   if (ly == 2) return icopy(x);
    1814        7595 :   av = avma;
    1815        7595 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1816        7595 :   y = mului(u,y);
    1817        7595 :   set_avma(av); return subii(x, y);
    1818             : }
    1819             : /* x + u*y */
    1820             : INLINE GEN
    1821        7595 : addmuliu(GEN x, GEN y, ulong u)
    1822             : {
    1823             :   pari_sp av;
    1824        7595 :   long ly = lgefint(y);
    1825        7595 :   if (ly == 2) return icopy(x);
    1826        7595 :   av = avma;
    1827        7595 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1828        7595 :   y = mului(u,y);
    1829        7595 :   set_avma(av); return addii(x, y);
    1830             : }
    1831             : /* x - u*y */
    1832             : INLINE GEN
    1833   120899870 : submuliu_inplace(GEN x, GEN y, ulong u)
    1834             : {
    1835             :   pari_sp av;
    1836   120899870 :   long ly = lgefint(y);
    1837   120899870 :   if (ly == 2) return x;
    1838    96726044 :   av = avma;
    1839    96726044 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1840    96726044 :   y = mului(u,y);
    1841    96726044 :   set_avma(av); return subii(x, y);
    1842             : }
    1843             : /* x + u*y */
    1844             : INLINE GEN
    1845   119297417 : addmuliu_inplace(GEN x, GEN y, ulong u)
    1846             : {
    1847             :   pari_sp av;
    1848   119297417 :   long ly = lgefint(y);
    1849   119297417 :   if (ly == 2) return x;
    1850    96550364 :   av = avma;
    1851    96550364 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1852    96550364 :   y = mului(u,y);
    1853    96550364 :   set_avma(av); return addii(x, y);
    1854             : }
    1855             : /* ux + vy */
    1856             : INLINE GEN
    1857    20302902 : lincombii(GEN u, GEN v, GEN x, GEN y)
    1858             : {
    1859    20302902 :   long lx = lgefint(x), ly;
    1860             :   GEN p1, p2;
    1861             :   pari_sp av;
    1862    20302902 :   if (lx == 2) return mulii(v,y);
    1863    14352648 :   ly = lgefint(y);
    1864    14352648 :   if (ly == 2) return mulii(u,x);
    1865    13211507 :   av = avma; (void)new_chunk(lx+ly+lgefint(u)+lgefint(v)); /* HACK */
    1866    13211507 :   p1 = mulii(u,x);
    1867    13211507 :   p2 = mulii(v,y);
    1868    13211507 :   set_avma(av); return addii(p1,p2);
    1869             : }
    1870             : 
    1871             : /*******************************************************************/
    1872             : /*                                                                 */
    1873             : /*                          GEN SUBTYPES                           */
    1874             : /*                                                                 */
    1875             : /*******************************************************************/
    1876             : 
    1877             : INLINE int
    1878  1167300344 : is_const_t(long t) { return (t < t_POLMOD); }
    1879             : INLINE int
    1880        5325 : is_extscalar_t(long t) { return (t <= t_POL); }
    1881             : INLINE int
    1882     1024885 : is_intreal_t(long t) { return (t <= t_REAL); }
    1883             : INLINE int
    1884   401039928 : is_matvec_t(long t) { return (t >= t_VEC && t <= t_MAT); }
    1885             : INLINE int
    1886    59172939 : is_noncalc_t(long tx) { return (tx) >= t_LIST; }
    1887             : INLINE int
    1888     1130946 : is_rational_t(long t) { return (t == t_INT || t == t_FRAC); }
    1889             : INLINE int
    1890      375953 : is_real_t(long t) { return (t == t_INT || t == t_REAL || t == t_FRAC); }
    1891             : INLINE int
    1892  2866243601 : is_recursive_t(long t) { return lontyp[t]; }
    1893             : INLINE int
    1894   179257371 : is_scalar_t(long t) { return (t < t_POL); }
    1895             : INLINE int
    1896     1190883 : is_vec_t(long t) { return (t == t_VEC || t == t_COL); }
    1897             : 
    1898             : /*******************************************************************/
    1899             : /*                                                                 */
    1900             : /*                         TRANSCENDENTAL                          */
    1901             : /*                                                                 */
    1902             : /*******************************************************************/
    1903             : INLINE GEN
    1904    21757341 : sqrtr(GEN x) {
    1905    21757341 :   long s = signe(x);
    1906    21757341 :   if (s == 0) return real_0_bit(expo(x) >> 1);
    1907    21723640 :   if (s >= 0) return sqrtr_abs(x);
    1908       29315 :   retmkcomplex(gen_0, sqrtr_abs(x));
    1909             : }
    1910             : INLINE GEN
    1911           0 : cbrtr_abs(GEN x) { return sqrtnr_abs(x, 3); }
    1912             : INLINE GEN
    1913           0 : cbrtr(GEN x) {
    1914           0 :   long s = signe(x);
    1915             :   GEN r;
    1916           0 :   if (s == 0) return real_0_bit(expo(x) / 3);
    1917           0 :   r = cbrtr_abs(x);
    1918           0 :   if (s < 0) togglesign(r);
    1919           0 :   return r;
    1920             : }
    1921             : INLINE GEN
    1922      373769 : sqrtnr(GEN x, long n) {
    1923      373769 :   long s = signe(x);
    1924             :   GEN r;
    1925      373769 :   if (s == 0) return real_0_bit(expo(x) / n);
    1926      373769 :   r = sqrtnr_abs(x, n);
    1927      373769 :   if (s < 0) pari_err_IMPL("sqrtnr for x < 0");
    1928      373769 :   return r;
    1929             : }
    1930             : INLINE long
    1931      212480 : logint(GEN B, GEN y) { return logintall(B,y,NULL); }
    1932             : INLINE ulong
    1933     1810842 : ulogint(ulong B, ulong y)
    1934             : {
    1935             :   ulong r;
    1936             :   long e;
    1937     1810842 :   if (y == 2) return expu(B);
    1938     1792999 :   r = y;
    1939     6011909 :   for (e=1;; e++)
    1940             :   { /* here, r = y^e, r2 = y^(e-1) */
    1941    10230819 :     if (r >= B) return r == B? e: e-1;
    1942     4218910 :     r = umuluu_or_0(y, r);
    1943     4218910 :     if (!r) return e;
    1944             :   }
    1945             : }
    1946             : 
    1947             : /*******************************************************************/
    1948             : /*                                                                 */
    1949             : /*                         MISCELLANEOUS                           */
    1950             : /*                                                                 */
    1951             : /*******************************************************************/
    1952     1024808 : INLINE int ismpzero(GEN x) { return is_intreal_t(typ(x)) && !signe(x); }
    1953   556597466 : INLINE int isintzero(GEN x) { return typ(x) == t_INT && !signe(x); }
    1954     7012260 : INLINE int isint1(GEN x) { return typ(x)==t_INT && equali1(x); }
    1955        4613 : INLINE int isintm1(GEN x){ return typ(x)==t_INT && equalim1(x);}
    1956   674538803 : INLINE int equali1(GEN n)
    1957   674538803 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(1)) && n[2] == 1; }
    1958    62132248 : INLINE int equalim1(GEN n)
    1959    62132248 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(-1)) && n[2] == 1; }
    1960             : /* works only for POSITIVE integers */
    1961   934639349 : INLINE int is_pm1(GEN n)
    1962   934639349 : { return lgefint(n) == 3 && n[2] == 1; }
    1963   220326702 : INLINE int is_bigint(GEN n)
    1964   220326702 : { long l = lgefint(n); return l > 3 || (l == 3 && (n[2] & HIGHBIT)); }
    1965             : 
    1966  2053731296 : INLINE int odd(long x) { return x & 1; }
    1967    28644333 : INLINE int both_odd(long x, long y) { return x & y & 1; }
    1968             : 
    1969             : INLINE int
    1970  2634271362 : isonstack(GEN x)
    1971  2634271362 : { return ((pari_sp)x >= pari_mainstack->bot
    1972  2634271362 :        && (pari_sp)x <  pari_mainstack->top); }
    1973             : 
    1974             : /* assume x != 0 and x t_REAL, return an approximation to log2(|x|) */
    1975             : INLINE double
    1976    21999132 : dbllog2r(GEN x)
    1977    21999132 : { return log2((double)(ulong)x[2]) + (double)(expo(x) - (BITS_IN_LONG-1)); }
    1978             : 
    1979             : INLINE GEN
    1980      308639 : mul_content(GEN cx, GEN cy)
    1981             : {
    1982      308639 :   if (!cx) return cy;
    1983      108065 :   if (!cy) return cx;
    1984       79214 :   return gmul(cx,cy);
    1985             : }
    1986             : INLINE GEN
    1987        5901 : inv_content(GEN c) { return c? ginv(c): NULL; }
    1988             : INLINE GEN
    1989     1603238 : mul_denom(GEN dx, GEN dy)
    1990             : {
    1991     1603238 :   if (!dx) return dy;
    1992     1060336 :   if (!dy) return dx;
    1993      334376 :   return mulii(dx,dy);
    1994             : }
    1995             : 
    1996             : /* POLYNOMIALS */
    1997             : INLINE GEN
    1998    17566814 : constant_coeff(GEN x) { return signe(x)? gel(x,2): gen_0; }
    1999             : INLINE GEN
    2000    81477033 : leading_coeff(GEN x) { return lg(x) == 2? gen_0: gel(x,lg(x)-1); }
    2001             : INLINE ulong
    2002      477141 : Flx_lead(GEN x) { return lg(x) == 2? 0: x[lg(x)-1]; }
    2003             : INLINE ulong
    2004       12348 : Flx_constant(GEN x) { return lg(x) == 2? 0: x[2]; }
    2005             : INLINE long
    2006  2795499692 : degpol(GEN x) { return lg(x)-3; }
    2007             : INLINE long
    2008  1361993764 : lgpol(GEN x) { return lg(x)-2; }
    2009             : INLINE long
    2010   115477938 : lgcols(GEN x) { return lg(gel(x,1)); }
    2011             : INLINE long
    2012    33454403 : nbrows(GEN x) { return lg(gel(x,1))-1; }
    2013             : INLINE GEN
    2014           0 : truecoef(GEN x, long n) { return polcoef(x,n,-1); }
    2015             : 
    2016             : INLINE GEN
    2017      555798 : ZXQ_mul(GEN y, GEN x, GEN T) { return ZX_rem(ZX_mul(y, x), T); }
    2018             : INLINE GEN
    2019      277910 : ZXQ_sqr(GEN x, GEN T) { return ZX_rem(ZX_sqr(x), T); }
    2020             : 
    2021             : INLINE GEN
    2022    57843054 : RgX_copy(GEN x)
    2023             : {
    2024             :   long lx, i;
    2025    57843054 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
    2026    57843060 :   for (i = 2; i<lx; i++) gel(y,i) = gcopy(gel(x,i));
    2027    57843062 :   return y;
    2028             : }
    2029             : /* have to use ulong to avoid silly warnings from gcc "assuming signed
    2030             :  * overflow does not occur" */
    2031             : INLINE GEN
    2032     2956710 : RgX_coeff(GEN x, long n)
    2033             : {
    2034     2956710 :   ulong l = lg(x);
    2035     2956710 :   return (n < 0 || ((ulong)n+3) > l)? gen_0: gel(x,n+2);
    2036             : }
    2037             : INLINE GEN
    2038      353293 : RgX_renormalize(GEN x) { return RgX_renormalize_lg(x, lg(x)); }
    2039             : INLINE GEN
    2040     6702010 : RgX_div(GEN x, GEN y) { return RgX_divrem(x,y,NULL); }
    2041             : INLINE GEN
    2042        1792 : RgXQX_div(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,NULL); }
    2043             : INLINE GEN
    2044       65155 : RgXQX_rem(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,ONLY_REM); }
    2045             : INLINE GEN
    2046      884862 : FpX_div(GEN x, GEN y, GEN p) { return FpX_divrem(x,y,p, NULL); }
    2047             : INLINE GEN
    2048     4337455 : Flx_div(GEN x, GEN y, ulong p) { return Flx_divrem(x,y,p, NULL); }
    2049             : INLINE GEN
    2050     2598735 : F2x_div(GEN x, GEN y) { return F2x_divrem(x,y, NULL); }
    2051             : INLINE GEN
    2052           0 : FpV_FpC_mul(GEN x, GEN y, GEN p) { return FpV_dotproduct(x,y,p); }
    2053             : INLINE GEN
    2054    56933067 : pol0_Flx(long sv) { return mkvecsmall(sv); }
    2055             : INLINE GEN
    2056    22786351 : pol1_Flx(long sv) { return mkvecsmall2(sv, 1); }
    2057             : INLINE GEN
    2058    17647694 : polx_Flx(long sv) { return mkvecsmall3(sv, 0, 1); }
    2059             : INLINE GEN
    2060           0 : zero_zx(long sv) { return zero_Flx(sv); }
    2061             : INLINE GEN
    2062           0 : polx_zx(long sv) { return polx_Flx(sv); }
    2063             : INLINE GEN
    2064           0 : zx_shift(GEN x, long n) { return Flx_shift(x,n); }
    2065             : INLINE GEN
    2066           0 : zx_renormalize(GEN x, long l) { return Flx_renormalize(x,l); }
    2067             : INLINE GEN
    2068        1474 : zero_F2x(long sv) { return zero_Flx(sv); }
    2069             : INLINE GEN
    2070    11162576 : pol0_F2x(long sv) { return pol0_Flx(sv); }
    2071             : INLINE GEN
    2072     2869383 : pol1_F2x(long sv) { return pol1_Flx(sv); }
    2073             : INLINE GEN
    2074      684658 : polx_F2x(long sv) { return mkvecsmall2(sv, 2); }
    2075             : INLINE int
    2076      812381 : F2x_equal1(GEN x) { return Flx_equal1(x); }
    2077             : INLINE int
    2078     3111461 : F2x_equal(GEN V, GEN W) { return Flx_equal(V,W); }
    2079             : INLINE GEN
    2080    59334542 : F2x_copy(GEN x) { return leafcopy(x); }
    2081             : INLINE GEN
    2082           0 : F2v_copy(GEN x) { return leafcopy(x); }
    2083             : INLINE GEN
    2084     2273212 : Flv_copy(GEN x) { return leafcopy(x); }
    2085             : INLINE GEN
    2086    83222967 : Flx_copy(GEN x) { return leafcopy(x); }
    2087             : INLINE GEN
    2088     1863892 : vecsmall_copy(GEN x) { return leafcopy(x); }
    2089             : INLINE int
    2090     4854477 : Flx_equal1(GEN x) { return degpol(x)==0 && x[2] == 1; }
    2091             : INLINE int
    2092       18205 : ZX_equal1(GEN x) { return degpol(x)==0 && equali1(gel(x,2)); }
    2093             : INLINE int
    2094     5559467 : ZX_is_monic(GEN x) { return equali1(leading_coeff(x)); }
    2095             : 
    2096             : INLINE GEN
    2097    50525675 : ZX_renormalize(GEN x, long lx)    { return ZXX_renormalize(x,lx); }
    2098             : INLINE GEN
    2099    67210609 : FpX_renormalize(GEN x, long lx)   { return ZXX_renormalize(x,lx); }
    2100             : INLINE GEN
    2101      771228 : FpXX_renormalize(GEN x, long lx)  { return ZXX_renormalize(x,lx); }
    2102             : INLINE GEN
    2103     1237233 : FpXQX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
    2104             : INLINE GEN
    2105   111339587 : F2x_renormalize(GEN x, long lx)   { return Flx_renormalize(x,lx); }
    2106             : INLINE GEN
    2107       32387 : F2v_to_F2x(GEN x, long sv) {
    2108       32387 :   GEN y = leafcopy(x);
    2109       32387 :   y[1] = sv; F2x_renormalize(y, lg(y)); return y;
    2110             : }
    2111             : 
    2112             : INLINE long
    2113           0 : sturm(GEN x) { return sturmpart(x, NULL, NULL); }
    2114             : 
    2115             : INLINE long
    2116        7042 : gval(GEN x, long v) {
    2117        7042 :   pari_sp av = avma;
    2118        7042 :   long n = gvaluation(x, pol_x(v));
    2119        7042 :   set_avma(av); return n;
    2120             : }
    2121             : 
    2122             : INLINE void
    2123      469118 : RgX_shift_inplace_init(long v)
    2124      469118 : { if (v) (void)cgetg(v, t_VECSMALL); }
    2125             : /* shift polynomial in place. assume v free cells have been left before x */
    2126             : INLINE GEN
    2127      469118 : RgX_shift_inplace(GEN x, long v)
    2128             : {
    2129             :   long i, lx;
    2130             :   GEN y, z;
    2131      469118 :   if (!v) return x;
    2132      253227 :   lx = lg(x);
    2133      253227 :   if (lx == 2) return x;
    2134      253227 :   y = x + v;
    2135      253227 :   z = x + lx;
    2136             :   /* stackdummy from normalizepol: move it up */
    2137      253227 :   if (lg(z) != v) x[lx + v] = z[0];
    2138      253227 :   for (i = lx-1; i >= 2; i--) gel(y,i) = gel(x,i);
    2139      253227 :   for (i = v+1;  i >= 2; i--) gel(x,i) = gen_0;
    2140             :   /* leave x[1] alone: it is correct */
    2141      253227 :   x[0] = evaltyp(t_POL) | evallg(lx+v); return x;
    2142             : }
    2143             : 
    2144             : 
    2145             : /* LINEAR ALGEBRA */
    2146             : INLINE GEN
    2147      131784 : zv_to_ZV(GEN x) { return vecsmall_to_vec(x); }
    2148             : INLINE GEN
    2149     5191030 : zc_to_ZC(GEN x) { return vecsmall_to_col(x); }
    2150             : INLINE GEN
    2151      438793 : ZV_to_zv(GEN x) { return vec_to_vecsmall(x); }
    2152             : INLINE GEN
    2153           0 : zx_to_zv(GEN x, long N) { return Flx_to_Flv(x,N); }
    2154             : INLINE GEN
    2155           0 : zv_to_zx(GEN x, long sv) { return Flv_to_Flx(x,sv); }
    2156             : INLINE GEN
    2157           0 : zm_to_zxV(GEN x, long sv) { return Flm_to_FlxV(x,sv); }
    2158             : INLINE GEN
    2159           0 : zero_zm(long x, long y) { return zero_Flm(x,y); }
    2160             : INLINE GEN
    2161    17128556 : zero_zv(long x) { return zero_Flv(x); }
    2162             : INLINE GEN
    2163         210 : zm_transpose(GEN x) { return Flm_transpose(x); }
    2164             : INLINE GEN
    2165           0 : zm_copy(GEN x) { return Flm_copy(x); }
    2166             : INLINE GEN
    2167     1903287 : zv_copy(GEN x) { return Flv_copy(x); }
    2168             : INLINE GEN
    2169           0 : zm_row(GEN x, long i) { return Flm_row(x,i); }
    2170             : 
    2171             : INLINE GEN
    2172      843568 : ZC_hnfrem(GEN x, GEN y) { return ZC_hnfremdiv(x,y,NULL); }
    2173             : INLINE GEN
    2174       35594 : ZM_hnfrem(GEN x, GEN y) { return ZM_hnfdivrem(x,y,NULL); }
    2175             : INLINE GEN
    2176     2380839 : ZM_lll(GEN x, double D, long f) { return ZM_lll_norms(x,D,f,NULL); }
    2177             : INLINE void
    2178     5649816 : RgM_dimensions(GEN x, long *m, long *n) { *n = lg(x)-1; *m = *n? nbrows(x): 0; }
    2179             : INLINE GEN
    2180     9920922 : RgM_shallowcopy(GEN x)
    2181             : {
    2182             :   long l;
    2183     9920922 :   GEN y = cgetg_copy(x, &l);
    2184     9920922 :   while (--l > 0) gel(y,l) = leafcopy(gel(x,l));
    2185     9920922 :   return y;
    2186             : }
    2187             : INLINE GEN
    2188         302 : F2m_copy(GEN x) { return RgM_shallowcopy(x); }
    2189             : 
    2190             : INLINE GEN
    2191     1312887 : Flm_copy(GEN x) { return RgM_shallowcopy(x); }
    2192             : 
    2193             : /* divisibility: return 1 if y[i] | x[i] for all i, 0 otherwise. Assume
    2194             :  * x,y are ZV of the same length */
    2195             : INLINE int
    2196       23198 : ZV_dvd(GEN x, GEN y)
    2197             : {
    2198       23198 :   long i, l = lg(x);
    2199       36652 :   for (i=1; i < l; i++)
    2200       29519 :     if ( ! dvdii( gel(x,i), gel(y,i) ) ) return 0;
    2201        7133 :   return 1;
    2202             : }
    2203             : 
    2204             : /* Fq */
    2205             : INLINE GEN
    2206     2798419 : Fq_red(GEN x, GEN T, GEN p)
    2207     2798419 : { return typ(x)==t_INT? Fp_red(x,p): FpXQ_red(x,T,p); }
    2208             : INLINE GEN
    2209       43439 : Fq_to_FpXQ(GEN x, GEN T, GEN p /*unused*/)
    2210             : {
    2211             :   (void) p;
    2212       43439 :   return typ(x)==t_INT ? scalarpol(x, get_FpX_var(T)): x;
    2213             : }
    2214             : INLINE GEN
    2215         756 : Rg_to_Fq(GEN x, GEN T, GEN p) { return T? Rg_to_FpXQ(x,T,p): Rg_to_Fp(x,p); }
    2216             : 
    2217             : INLINE GEN
    2218         903 : gener_Fq_local(GEN T, GEN p, GEN L)
    2219             : { return T? gener_FpXQ_local(T,p, L)
    2220         903 :           : pgener_Fp_local(p, L); }
    2221             : 
    2222             : /* FpXQX */
    2223             : INLINE GEN
    2224        4347 : FpXQX_div(GEN x, GEN y, GEN T, GEN p) { return FpXQX_divrem(x, y, T, p, NULL); }
    2225             : INLINE GEN
    2226       34803 : FlxqX_div(GEN x, GEN y, GEN T, ulong p) { return FlxqX_divrem(x, y, T, p, NULL); }
    2227             : INLINE GEN
    2228       33278 : F2xqX_div(GEN x, GEN y, GEN T) { return F2xqX_divrem(x, y, T, NULL); }
    2229             : 
    2230             : /* FqX */
    2231             : INLINE GEN
    2232       25431 : FqX_red(GEN z, GEN T, GEN p) { return T? FpXQX_red(z, T, p): FpX_red(z, p); }
    2233             : INLINE GEN
    2234      957187 : FqX_add(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2235             : INLINE GEN
    2236       17404 : FqX_neg(GEN x,GEN T,GEN p) { return T? FpXX_neg(x,p): FpX_neg(x,p); }
    2237             : INLINE GEN
    2238        3234 : FqX_sub(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2239             : INLINE GEN
    2240      655996 : FqX_Fp_mul(GEN P, GEN u, GEN T, GEN p)
    2241      655996 : { return T? FpXX_Fp_mul(P, u, p): FpX_Fp_mul(P, u, p); }
    2242             : INLINE GEN
    2243      587707 : FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p)
    2244      587707 : { return typ(U)==t_INT ? FqX_Fp_mul(P, U, T, p): FpXQX_FpXQ_mul(P, U, T, p); }
    2245             : INLINE GEN
    2246       95992 : FqX_mul(GEN x, GEN y, GEN T, GEN p)
    2247       95992 : { return T? FpXQX_mul(x, y, T, p): FpX_mul(x, y, p); }
    2248             : INLINE GEN
    2249      489744 : FqX_mulu(GEN x, ulong y, GEN T, GEN p)
    2250      489744 : { return T? FpXX_mulu(x, y, p): FpX_mulu(x, y, p); }
    2251             : INLINE GEN
    2252        6468 : FqX_sqr(GEN x, GEN T, GEN p)
    2253        6468 : { return T? FpXQX_sqr(x, T, p): FpX_sqr(x, p); }
    2254             : INLINE GEN
    2255        1288 : FqX_powu(GEN x, ulong n, GEN T, GEN p)
    2256        1288 : { return T? FpXQX_powu(x, n, T, p): FpX_powu(x, n, p); }
    2257             : INLINE GEN
    2258           0 : FqX_halve(GEN x, GEN T, GEN p)
    2259           0 : { return T? FpXX_halve(x, p): FpX_halve(x, p); }
    2260             : INLINE GEN
    2261        5523 : FqX_div(GEN x, GEN y, GEN T, GEN p)
    2262        5523 : { return T? FpXQX_divrem(x,y,T,p,NULL): FpX_divrem(x,y,p,NULL); }
    2263             : INLINE GEN
    2264        6095 : FqX_get_red(GEN S, GEN T, GEN p)
    2265        6095 : { return T? FpXQX_get_red(S,T,p): FpX_get_red(S,p); }
    2266             : INLINE GEN
    2267       53108 : FqX_rem(GEN x, GEN y, GEN T, GEN p)
    2268       53108 : { return T? FpXQX_rem(x,y,T,p): FpX_rem(x,y,p); }
    2269             : INLINE GEN
    2270           0 : FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2271           0 : { return T? FpXQX_divrem(x,y,T,p,z): FpX_divrem(x,y,p,z); }
    2272             : INLINE GEN
    2273        5936 : FqX_div_by_X_x(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2274        5936 : { return T? FpXQX_div_by_X_x(x,y,T,p,z): FpX_div_by_X_x(x,y,p,z); }
    2275             : INLINE GEN
    2276           0 : FqX_halfgcd(GEN P,GEN Q,GEN T,GEN p)
    2277           0 : {return T? FpXQX_halfgcd(P,Q,T,p): FpX_halfgcd(P,Q,p);}
    2278             : INLINE GEN
    2279      259098 : FqX_gcd(GEN P,GEN Q,GEN T,GEN p)
    2280      259098 : {return T? FpXQX_gcd(P,Q,T,p): FpX_gcd(P,Q,p);}
    2281             : INLINE GEN
    2282       86994 : FqX_extgcd(GEN P,GEN Q,GEN T,GEN p, GEN *U, GEN *V)
    2283       86994 : { return T? FpXQX_extgcd(P,Q,T,p,U,V): FpX_extgcd(P,Q,p,U,V); }
    2284             : INLINE GEN
    2285        3178 : FqX_normalize(GEN z, GEN T, GEN p)
    2286        3178 : { return T? FpXQX_normalize(z, T, p): FpX_normalize(z, p); }
    2287             : INLINE GEN
    2288      272895 : FqX_deriv(GEN f, GEN T, GEN p) { return T? FpXX_deriv(f, p): FpX_deriv(f, p); }
    2289             : INLINE GEN
    2290           0 : FqX_integ(GEN f, GEN T, GEN p) { return T? FpXX_integ(f, p): FpX_integ(f, p); }
    2291             : INLINE GEN
    2292       74459 : FqX_factor(GEN f, GEN T, GEN p)
    2293       74459 : { return T?FpXQX_factor(f, T, p): FpX_factor(f, p); }
    2294             : INLINE GEN
    2295           7 : FqX_factor_squarefree(GEN f, GEN T, GEN p)
    2296           7 : { return T ? FpXQX_factor_squarefree(f, T, p): FpX_factor_squarefree(f, p); }
    2297             : INLINE GEN
    2298           7 : FqX_ddf(GEN f, GEN T, GEN p)
    2299           7 : { return T ? FpXQX_ddf(f, T, p): FpX_ddf(f, p); }
    2300             : INLINE GEN
    2301          42 : FqX_degfact(GEN f, GEN T, GEN p)
    2302          42 : { return T?FpXQX_degfact(f, T, p): FpX_degfact(f, p); }
    2303             : INLINE GEN
    2304        7126 : FqX_roots(GEN f, GEN T, GEN p)
    2305        7126 : { return T?FpXQX_roots(f, T, p): FpX_roots(f, p); }
    2306             : INLINE GEN
    2307         203 : FqX_to_mod(GEN f, GEN T, GEN p)
    2308         203 : { return T?FpXQX_to_mod(f, T, p): FpX_to_mod(f, p); }
    2309             : 
    2310             : /*FqXQ*/
    2311             : INLINE GEN
    2312           0 : FqXQ_add(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2313           0 : { (void)S; return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2314             : INLINE GEN
    2315           0 : FqXQ_sub(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2316           0 : { (void)S; return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2317             : INLINE GEN
    2318           0 : FqXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p)
    2319           0 : { return T? FpXQXQ_div(x,y,S,T,p): FpXQ_div(x,y,S,p); }
    2320             : INLINE GEN
    2321           0 : FqXQ_inv(GEN x, GEN S, GEN T, GEN p)
    2322           0 : { return T? FpXQXQ_inv(x,S,T,p): FpXQ_inv(x,S,p); }
    2323             : INLINE GEN
    2324           0 : FqXQ_invsafe(GEN x, GEN S, GEN T, GEN p)
    2325           0 : { return T? FpXQXQ_invsafe(x,S,T,p): FpXQ_inv(x,S,p); }
    2326             : INLINE GEN
    2327       22348 : FqXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p)
    2328       22348 : { return T? FpXQXQ_mul(x,y,S,T,p): FpXQ_mul(x,y,S,p); }
    2329             : INLINE GEN
    2330           0 : FqXQ_sqr(GEN x, GEN S, GEN T, GEN p)
    2331           0 : { return T? FpXQXQ_sqr(x,S,T,p): FpXQ_sqr(x,S,p); }
    2332             : INLINE GEN
    2333           0 : FqXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p)
    2334           0 : { return T? FpXQXQ_pow(x,n,S,T,p): FpXQ_pow(x,n,S,p); }
    2335             : 
    2336             : /*FqXn*/
    2337             : INLINE GEN
    2338           0 : FqXn_exp(GEN x, long n, GEN T, GEN p)
    2339           0 : { return T? FpXQXn_exp(x,n,T,p): FpXn_exp(x,n,p); }
    2340             : INLINE GEN
    2341           0 : FqXn_inv(GEN x, long n, GEN T, GEN p)
    2342           0 : { return T? FpXQXn_inv(x,n,T,p): FpXn_inv(x,n,p); }
    2343             : INLINE GEN
    2344           0 : FqXn_mul(GEN x, GEN y, long n, GEN T, GEN p)
    2345           0 : { return T? FpXQXn_mul(x, y, n, T, p): FpXn_mul(x, y, n, p); }
    2346             : INLINE GEN
    2347           0 : FqXn_sqr(GEN x, long n, GEN T, GEN p)
    2348           0 : { return T? FpXQXn_sqr(x,n,T,p): FpXn_sqr(x,n,p); }
    2349             : 
    2350             : /*FpXQ*/
    2351             : INLINE GEN
    2352           0 : FpXQ_add(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2353           0 : { (void)T; return FpX_add(x,y,p); }
    2354             : INLINE GEN
    2355           0 : FpXQ_sub(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2356           0 : { (void)T; return FpX_sub(x,y,p); }
    2357             : 
    2358             : /*Flxq*/
    2359             : INLINE GEN
    2360           0 : Flxq_add(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2361           0 : { (void)T; return Flx_add(x,y,p); }
    2362             : INLINE GEN
    2363           0 : Flxq_sub(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2364           0 : { (void)T; return Flx_sub(x,y,p); }
    2365             : 
    2366             : /* F2x */
    2367             : 
    2368             : INLINE ulong
    2369   100496582 : F2x_coeff(GEN x,long v)
    2370             : {
    2371   100496582 :    ulong u=(ulong)x[2+divsBIL(v)];
    2372   100495237 :    return (u>>remsBIL(v))&1UL;
    2373             : }
    2374             : 
    2375             : INLINE void
    2376     4711156 : F2x_clear(GEN x,long v)
    2377             : {
    2378     4711156 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2379     4711157 :    *u&=~(1UL<<remsBIL(v));
    2380     4711157 : }
    2381             : 
    2382             : INLINE void
    2383    32738625 : F2x_set(GEN x,long v)
    2384             : {
    2385    32738625 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2386    32726459 :    *u|=1UL<<remsBIL(v);
    2387    32725605 : }
    2388             : 
    2389             : INLINE void
    2390     1501806 : F2x_flip(GEN x,long v)
    2391             : {
    2392     1501806 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2393     1501806 :    *u^=1UL<<remsBIL(v);
    2394     1501806 : }
    2395             : 
    2396             : /* F2v */
    2397             : 
    2398             : INLINE ulong
    2399    95885541 : F2v_coeff(GEN x,long v) { return F2x_coeff(x,v-1); }
    2400             : 
    2401             : INLINE void
    2402     4711156 : F2v_clear(GEN x,long v) { F2x_clear(x,v-1); }
    2403             : 
    2404             : INLINE void
    2405     8951558 : F2v_set(GEN x,long v)   { F2x_set(x,v-1); }
    2406             : 
    2407             : INLINE void
    2408     1501806 : F2v_flip(GEN x,long v) { F2x_flip(x,v-1); }
    2409             : 
    2410             : /* F2m */
    2411             : 
    2412             : INLINE ulong
    2413    11669876 : F2m_coeff(GEN x, long a, long b) { return F2v_coeff(gel(x,b), a); }
    2414             : 
    2415             : INLINE void
    2416           0 : F2m_clear(GEN x, long a, long b) { F2v_clear(gel(x,b), a); }
    2417             : 
    2418             : INLINE void
    2419     1362615 : F2m_set(GEN x, long a, long b) { F2v_set(gel(x,b), a); }
    2420             : 
    2421             : INLINE void
    2422     1501806 : F2m_flip(GEN x, long a, long b) { F2v_flip(gel(x,b), a); }
    2423             : 
    2424             : /* ARITHMETIC */
    2425             : INLINE GEN
    2426        1071 : matpascal(long n) { return matqpascal(n, NULL); }
    2427             : INLINE long
    2428     2330804 : Z_issquare(GEN x) { return Z_issquareall(x, NULL); }
    2429             : INLINE long
    2430          14 : Z_ispower(GEN x, ulong k) { return Z_ispowerall(x, k, NULL); }
    2431             : INLINE GEN
    2432     5677220 : sqrti(GEN x) { return sqrtremi(x,NULL); }
    2433             : INLINE GEN
    2434     4217746 : gaddgs(GEN y, long s) { return gaddsg(s,y); }
    2435             : INLINE int
    2436       39724 : gcmpgs(GEN y, long s) { return -gcmpsg(s,y); }
    2437             : INLINE int
    2438       24570 : gequalgs(GEN y, long s) { return gequalsg(s,y); }
    2439             : INLINE GEN
    2440           0 : gmaxsg(long s, GEN y) { return gmaxgs(y,s); }
    2441             : INLINE GEN
    2442           0 : gminsg(long s, GEN y) { return gmings(y,s); }
    2443             : INLINE GEN
    2444    13210239 : gmulgs(GEN y, long s) { return gmulsg(s,y); }
    2445             : INLINE GEN
    2446     1245971 : gsubgs(GEN y, long s) { return gaddgs(y, -s); }
    2447             : INLINE GEN
    2448      678127 : gdivsg(long s, GEN y) { return gdiv(stoi(s), y); }
    2449             : 
    2450             : /* x t_COMPLEX */
    2451             : INLINE GEN
    2452    11103624 : cxnorm(GEN x) { return gadd(gsqr(gel(x,1)), gsqr(gel(x,2))); }
    2453             : /* q t_QUAD */
    2454             : INLINE GEN
    2455         623 : quadnorm(GEN q)
    2456             : {
    2457         623 :   GEN X = gel(q,1), b = gel(X,3), c = gel(X,2);
    2458         623 :   GEN z, u = gel(q,3), v = gel(q,2);
    2459         623 :   if (typ(u) == t_INT && typ(v) == t_INT) /* generic case */
    2460             :   {
    2461         308 :     z = signe(b)? mulii(v, addii(u,v)): sqri(v);
    2462         308 :     return addii(z, mulii(c, sqri(u)));
    2463             :   }
    2464             :   else
    2465             :   {
    2466         315 :     z = signe(b)? gmul(v, gadd(u,v)): gsqr(v);
    2467         315 :     return gadd(z, gmul(c, gsqr(u)));
    2468             :   }
    2469             : }
    2470             : /* x a t_QUAD, return the attached discriminant */
    2471             : INLINE GEN
    2472         273 : quad_disc(GEN x)
    2473             : {
    2474         273 :   GEN Q = gel(x,1), b = gel(Q,3), c = gel(Q,2), c4;
    2475         273 :   if (is_pm1(b))
    2476             :   {
    2477         217 :     pari_sp av = avma; (void)new_chunk(lgefint(c) + 1);
    2478         217 :     c4 = shifti(c,2); set_avma(av); return subsi(1, c4);
    2479             :   }
    2480          56 :   c4 = shifti(c,2); togglesign_safe(&c4); return c4;
    2481             : }
    2482             : INLINE GEN
    2483     6480663 : qfb_disc3(GEN x, GEN y, GEN z) { return subii(sqri(y), shifti(mulii(x,z),2)); }
    2484             : INLINE GEN
    2485     6399785 : qfb_disc(GEN x) { return qfb_disc3(gel(x,1), gel(x,2), gel(x,3)); }
    2486             : 
    2487             : INLINE GEN
    2488     1251401 : sqrfrac(GEN x)
    2489             : {
    2490     1251401 :   GEN z = cgetg(3,t_FRAC);
    2491     1251401 :   gel(z,1) = sqri(gel(x,1));
    2492     1251401 :   gel(z,2) = sqri(gel(x,2)); return z;
    2493             : }
    2494             : 
    2495             : INLINE void
    2496    14712759 : normalize_frac(GEN z) {
    2497    14712759 :   if (signe(gel(z,2)) < 0) { togglesign(gel(z,1)); setabssign(gel(z,2)); }
    2498    14712759 : }
    2499             : 
    2500             : INLINE GEN
    2501      251224 : powii(GEN x, GEN n)
    2502             : {
    2503      251224 :   long ln = lgefint(n);
    2504      251224 :   if (ln == 3) {
    2505             :     GEN z;
    2506      248606 :     if (signe(n) > 0) return powiu(x, n[2]);
    2507        5852 :     z = cgetg(3, t_FRAC);
    2508        5852 :     gel(z,1) = gen_1;
    2509        5852 :     gel(z,2) = powiu(x, n[2]);
    2510        5852 :     return z;
    2511             :   }
    2512        2618 :   if (ln == 2) return gen_1; /* rare */
    2513             :   /* should never happen */
    2514           0 :   return powgi(x, n); /* overflow unless x = 0, 1, -1 */
    2515             : }
    2516             : INLINE GEN
    2517        1246 : powIs(long n) {
    2518        1246 :   switch(n & 3)
    2519             :   {
    2520          28 :     case 1: return mkcomplex(gen_0,gen_1);
    2521         378 :     case 2: return gen_m1;
    2522         518 :     case 3: return mkcomplex(gen_0,gen_m1);
    2523             :   }
    2524         322 :   return gen_1;
    2525             : }
    2526             : 
    2527             : /*******************************************************************/
    2528             : /*                                                                 */
    2529             : /*                             ASSIGNMENTS                         */
    2530             : /*                                                                 */
    2531             : /*******************************************************************/
    2532           0 : INLINE void mpexpz(GEN x, GEN z)
    2533           0 : { pari_sp av = avma; gaffect(mpexp(x), z); set_avma(av); }
    2534           0 : INLINE void mplogz(GEN x, GEN z)
    2535           0 : { pari_sp av = avma; gaffect(mplog(x), z); set_avma(av); }
    2536           0 : INLINE void mpcosz(GEN x, GEN z)
    2537           0 : { pari_sp av = avma; gaffect(mpcos(x), z); set_avma(av); }
    2538           0 : INLINE void mpsinz(GEN x, GEN z)
    2539           0 : { pari_sp av = avma; gaffect(mpsin(x), z); set_avma(av); }
    2540           0 : INLINE void gnegz(GEN x, GEN z)
    2541           0 : { pari_sp av = avma; gaffect(gneg(x), z); set_avma(av); }
    2542           0 : INLINE void gabsz(GEN x, long prec, GEN z)
    2543           0 : { pari_sp av = avma; gaffect(gabs(x,prec), z); set_avma(av); }
    2544       23318 : INLINE void gaddz(GEN x, GEN y, GEN z)
    2545       23318 : { pari_sp av = avma; gaffect(gadd(x,y), z); set_avma(av); }
    2546           0 : INLINE void gsubz(GEN x, GEN y, GEN z)
    2547           0 : { pari_sp av = avma; gaffect(gsub(x,y), z); set_avma(av); }
    2548       11673 : INLINE void gmulz(GEN x, GEN y, GEN z)
    2549       11673 : { pari_sp av = avma; gaffect(gmul(x,y), z); set_avma(av); }
    2550           0 : INLINE void gdivz(GEN x, GEN y, GEN z)
    2551           0 : { pari_sp av = avma; gaffect(gdiv(x,y), z); set_avma(av); }
    2552           0 : INLINE void gdiventz(GEN x, GEN y, GEN z)
    2553           0 : { pari_sp av = avma; gaffect(gdivent(x,y), z); set_avma(av); }
    2554           0 : INLINE void gmodz(GEN x, GEN y, GEN z)
    2555           0 : { pari_sp av = avma; gaffect(gmod(x,y), z); set_avma(av); }
    2556           0 : INLINE void gmul2nz(GEN x, long s, GEN z)
    2557           0 : { pari_sp av = avma; gaffect(gmul2n(x,s), z); set_avma(av); }
    2558           0 : INLINE void gshiftz(GEN x, long s, GEN z)
    2559           0 : { pari_sp av = avma; gaffect(gshift(x,s), z); set_avma(av); }
    2560             : 
    2561             : /*******************************************************************/
    2562             : /*                                                                 */
    2563             : /*                       ELLIPTIC CURVES                           */
    2564             : /*                                                                 */
    2565             : /*******************************************************************/
    2566     3979738 : INLINE GEN ell_get_a1(GEN e) { return gel(e,1); }
    2567     3095797 : INLINE GEN ell_get_a2(GEN e) { return gel(e,2); }
    2568     3861691 : INLINE GEN ell_get_a3(GEN e) { return gel(e,3); }
    2569     3888743 : INLINE GEN ell_get_a4(GEN e) { return gel(e,4); }
    2570     4704922 : INLINE GEN ell_get_a6(GEN e) { return gel(e,5); }
    2571     3318516 : INLINE GEN ell_get_b2(GEN e) { return gel(e,6); }
    2572     1024949 : INLINE GEN ell_get_b4(GEN e) { return gel(e,7); }
    2573     1630617 : INLINE GEN ell_get_b6(GEN e) { return gel(e,8); }
    2574     1464001 : INLINE GEN ell_get_b8(GEN e) { return gel(e,9); }
    2575     6167358 : INLINE GEN ell_get_c4(GEN e) { return gel(e,10); }
    2576     7403845 : INLINE GEN ell_get_c6(GEN e) { return gel(e,11); }
    2577     9654077 : INLINE GEN ell_get_disc(GEN e) { return gel(e,12); }
    2578     1028916 : INLINE GEN ell_get_j(GEN e) { return gel(e,13); }
    2579    11456565 : INLINE long ell_get_type(GEN e) { return mael(e,14,1); }
    2580     1570422 : INLINE GEN ellff_get_field(GEN x) { return gmael(x, 15, 1); }
    2581      683105 : INLINE GEN ellff_get_a4a6(GEN x)  { return gmael(x, 15, 2); }
    2582        1407 : INLINE GEN ellQp_get_zero(GEN x) { return gmael(x, 15, 1); }
    2583         287 : INLINE long ellQp_get_prec(GEN E) { GEN z = ellQp_get_zero(E); return valp(z); }
    2584        1085 : INLINE GEN ellQp_get_p(GEN E) { GEN z = ellQp_get_zero(E); return gel(z,2); }
    2585       37156 : INLINE long ellR_get_prec(GEN x) { return nbits2prec(mael3(x, 15, 1, 1)); }
    2586       12106 : INLINE long ellR_get_sign(GEN x) { return mael3(x, 15, 1, 2); }
    2587      699475 : INLINE GEN ellnf_get_nf(GEN x) { return checknf_i(gmael(x,15,1)); }
    2588          56 : INLINE GEN ellnf_get_bnf(GEN x) { return checkbnf_i(gmael(x,15,1)); }
    2589             : 
    2590     4625050 : INLINE int checkell_i(GEN e) { return typ(e) == t_VEC && lg(e) == 17; }
    2591    33935053 : INLINE int ell_is_inf(GEN z) { return lg(z) == 2; }
    2592      809800 : INLINE GEN ellinf(void) { return mkvec(gen_0); }
    2593             : 
    2594             : /*******************************************************************/
    2595             : /*                                                                 */
    2596             : /*                    ALGEBRAIC NUMBER THEORY                      */
    2597             : /*                                                                 */
    2598             : /*******************************************************************/
    2599     8126840 : INLINE GEN modpr_get_pr(GEN x)  { return gel(x,3); }
    2600      609512 : INLINE GEN modpr_get_p(GEN x)  { return pr_get_p(modpr_get_pr(x)); }
    2601     2520370 : INLINE GEN modpr_get_T(GEN x)  { return lg(x) == 4? NULL: gel(x,4); }
    2602             : 
    2603    19370926 : INLINE GEN pr_get_p(GEN pr)  { return gel(pr,1); }
    2604     6273165 : INLINE GEN pr_get_gen(GEN pr){ return gel(pr,2); }
    2605             : /* .[2] instead of itos works: e and f are small positive integers */
    2606     2266326 : INLINE long pr_get_e(GEN pr) { return gel(pr,3)[2]; }
    2607     8716111 : INLINE long pr_get_f(GEN pr) { return gel(pr,4)[2]; }
    2608     6141792 : INLINE GEN pr_get_tau(GEN pr){ return gel(pr,5); }
    2609             : INLINE int
    2610     3051845 : pr_is_inert(GEN P) { return pr_get_f(P) == lg(pr_get_gen(P))-1; }
    2611             : INLINE GEN
    2612      217505 : pr_norm(GEN pr) { return powiu(pr_get_p(pr), pr_get_f(pr)); }
    2613             : INLINE ulong
    2614       39487 : upr_norm(GEN pr) { return upowuu(pr_get_p(pr)[2], pr_get_f(pr)); }
    2615             : 
    2616             : /* assume nf a genuine nf */
    2617             : INLINE long
    2618        4528 : nf_get_varn(GEN nf) { return varn(gel(nf,1)); }
    2619             : INLINE GEN
    2620    30918607 : nf_get_pol(GEN nf) { return gel(nf,1); }
    2621             : INLINE long
    2622    24710894 : nf_get_degree(GEN nf) { return degpol( nf_get_pol(nf) ); }
    2623             : INLINE long
    2624     4092354 : nf_get_r1(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,1)); }
    2625             : INLINE long
    2626        1673 : nf_get_r2(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,2)); }
    2627             : INLINE GEN
    2628       49826 : nf_get_disc(GEN nf) { return gel(nf,3); }
    2629             : INLINE GEN
    2630      765942 : nf_get_index(GEN nf) { return gel(nf,4); }
    2631             : INLINE GEN
    2632     2821420 : nf_get_M(GEN nf) { return gmael(nf,5,1); }
    2633             : INLINE GEN
    2634       73824 : nf_get_G(GEN nf) { return gmael(nf,5,2); }
    2635             : INLINE GEN
    2636      385499 : nf_get_roundG(GEN nf) { return gmael(nf,5,3); }
    2637             : INLINE GEN
    2638       24367 : nf_get_Tr(GEN nf) { return gmael(nf,5,4); }
    2639             : INLINE GEN
    2640        2324 : nf_get_diff(GEN nf) { return gmael(nf,5,5); }
    2641             : INLINE GEN
    2642          77 : nf_get_ramified_primes(GEN nf) { return gmael(nf,5,8); }
    2643             : INLINE GEN
    2644      291043 : nf_get_roots(GEN nf) { return gel(nf,6); }
    2645             : INLINE GEN
    2646          91 : nf_get_zk(GEN nf)
    2647             : {
    2648          91 :   GEN y = gel(nf,7), D = gel(y, 1);
    2649          91 :   if (typ(D) == t_POL) D = gel(D, 2);
    2650          91 :   if (!equali1(D)) y = gdiv(y, D);
    2651          91 :   return y;
    2652             : }
    2653             : INLINE GEN
    2654      247678 : nf_get_zkprimpart(GEN nf)
    2655             : {
    2656      247678 :   GEN y = gel(nf,7);
    2657             :   /* test for old format of nf.zk: non normalized */
    2658      247678 :   if (!equali1(gel(nf,4)) && gequal1(gel(y,1))) y = Q_remove_denom(y,NULL);
    2659      247678 :   return y;
    2660             : }
    2661             : INLINE GEN
    2662      248813 : nf_get_zkden(GEN nf)
    2663             : {
    2664      248813 :   GEN y = gel(nf,7), D = gel(y,1);
    2665      248813 :   if (typ(D) == t_POL) D = gel(D,2);
    2666             :   /* test for old format of nf.zk: non normalized */
    2667      248813 :   if (!equali1(gel(nf,4)) && equali1(D)) D = Q_denom(y);
    2668      248813 :   return D;
    2669             : }
    2670             : INLINE GEN
    2671     2336951 : nf_get_invzk(GEN nf) { return gel(nf,8); }
    2672             : INLINE void
    2673       19819 : nf_get_sign(GEN nf, long *r1, long *r2)
    2674             : {
    2675       19819 :   GEN x = gel(nf,2);
    2676       19819 :   *r1 = itou(gel(x,1));
    2677       19819 :   *r2 = itou(gel(x,2));
    2678       19819 : }
    2679             : 
    2680             : INLINE GEN
    2681       49651 : abgrp_get_no(GEN x) { return gel(x,1); }
    2682             : INLINE GEN
    2683     2094351 : abgrp_get_cyc(GEN x) { return gel(x,2); }
    2684             : INLINE GEN
    2685      396512 : abgrp_get_gen(GEN x) { return gel(x,3); }
    2686             : INLINE GEN
    2687     2062709 : bnf_get_nf(GEN bnf) { return gel(bnf,7); }
    2688             : INLINE GEN
    2689      806275 : bnf_get_clgp(GEN bnf) { return gmael(bnf,8,1); }
    2690             : INLINE GEN
    2691        4564 : bnf_get_no(GEN bnf) { return abgrp_get_no(bnf_get_clgp(bnf)); }
    2692             : INLINE GEN
    2693      434249 : bnf_get_cyc(GEN bnf) { return abgrp_get_cyc(bnf_get_clgp(bnf)); }
    2694             : INLINE GEN
    2695      367133 : bnf_get_gen(GEN bnf)  { return abgrp_get_gen(bnf_get_clgp(bnf)); }
    2696             : INLINE GEN
    2697         846 : bnf_get_reg(GEN bnf) { return gmael(bnf,8,2); }
    2698             : INLINE GEN
    2699      481743 : bnf_get_logfu(GEN bnf) { return gel(bnf,3); }
    2700             : INLINE GEN
    2701        5868 : bnf_get_tuU(GEN bnf) { return gmael3(bnf,8,4,2); }
    2702             : INLINE long
    2703       24682 : bnf_get_tuN(GEN bnf) { return gmael3(bnf,8,4,1)[2]; }
    2704             : INLINE GEN
    2705        1806 : bnf_get_fu(GEN bnf) {
    2706        1806 :   GEN fu = bnf_get_fu_nocheck(bnf);
    2707        1806 :   if (typ(fu) == t_MAT) pari_err(e_MISC,"missing units in bnf");
    2708        1806 :   return fu;
    2709             : }
    2710             : INLINE GEN
    2711        7170 : bnf_get_fu_nocheck(GEN bnf) { return gmael(bnf,8,5); }
    2712             : 
    2713             : INLINE GEN
    2714      746961 : bnr_get_bnf(GEN bnr) { return gel(bnr,1); }
    2715             : INLINE GEN
    2716      384712 : bnr_get_bid(GEN bnr) { return gel(bnr,2); }
    2717             : INLINE GEN
    2718       18130 : bnr_get_mod(GEN bnr) { return gmael(bnr,2,1); }
    2719             : INLINE GEN
    2720       27811 : bnr_get_nf(GEN bnr) { return gmael(bnr,1,7); }
    2721             : INLINE GEN
    2722      516571 : bnr_get_clgp(GEN bnr) { return gel(bnr,5); }
    2723             : INLINE GEN
    2724       45080 : bnr_get_no(GEN bnr) { return abgrp_get_no(bnr_get_clgp(bnr)); }
    2725             : INLINE GEN
    2726      459598 : bnr_get_cyc(GEN bnr) { return abgrp_get_cyc(bnr_get_clgp(bnr)); }
    2727             : INLINE GEN
    2728          70 : bnr_get_gen_nocheck(GEN bnr) { return abgrp_get_gen(bnr_get_clgp(bnr)); }
    2729             : INLINE GEN
    2730       11032 : bnr_get_gen(GEN bnr) {
    2731       11032 :   GEN G = bnr_get_clgp(bnr);
    2732       11032 :   if (lg(G) !=  4)
    2733           0 :     pari_err(e_MISC,"missing bnr generators: please use bnrinit(,,1)");
    2734       11032 :   return gel(G,3);
    2735             : }
    2736             : 
    2737             : INLINE GEN
    2738      301888 : bid_get_mod(GEN bid) { return gel(bid,1); }
    2739             : INLINE GEN
    2740       46361 : bid_get_ideal(GEN bid) { return gmael(bid,1,1); }
    2741             : INLINE GEN
    2742         518 : bid_get_arch(GEN bid) { return gmael(bid,1,2); }
    2743             : INLINE GEN
    2744     1059923 : bid_get_grp(GEN bid) { return gel(bid,2); }
    2745             : INLINE GEN
    2746      395527 : bid_get_fact(GEN bid) { return gmael(bid,3,1); }
    2747             : INLINE GEN
    2748      354031 : bid_get_fact2(GEN bid) { return gmael(bid,3,2); }
    2749             : INLINE GEN
    2750      354031 : bid_get_sprk(GEN bid) { return gmael(bid,4,1); }
    2751             : INLINE GEN
    2752       29939 : bid_get_sarch(GEN bid) { return gmael(bid,4,2); }
    2753             : INLINE GEN
    2754      374695 : bid_get_archp(GEN bid) { return gmael3(bid,4,2,2); }
    2755             : INLINE GEN
    2756      656129 : bid_get_U(GEN bid) { return gel(bid,5); }
    2757             : INLINE GEN
    2758           0 : bid_get_no(GEN bid) { return abgrp_get_no(bid_get_grp(bid)); }
    2759             : INLINE GEN
    2760     1031538 : bid_get_cyc(GEN bid) { return abgrp_get_cyc(bid_get_grp(bid)); }
    2761             : INLINE GEN
    2762           0 : bid_get_gen_nocheck(GEN bid)  { return abgrp_get_gen(bid_get_grp(bid)); }
    2763             : INLINE GEN
    2764       27790 : bid_get_gen(GEN bid) {
    2765       27790 :   GEN G = bid_get_grp(bid);
    2766       27790 :   if (lg(G) != 4) pari_err(e_MISC,"missing bid generators. Use idealstar(,,2)");
    2767       27790 :   return abgrp_get_gen(G);
    2768             : }
    2769             : 
    2770             : INLINE GEN
    2771    21293125 : znstar_get_N(GEN G) { return gmael(G,1,1); }
    2772             : INLINE GEN
    2773     2210873 : znstar_get_faN(GEN G) { return gel(G,3); }
    2774             : INLINE GEN
    2775           7 : znstar_get_no(GEN G) { return abgrp_get_no(gel(G,2)); }
    2776             : INLINE GEN
    2777      167545 : znstar_get_cyc(GEN G) { return abgrp_get_cyc(gel(G,2)); }
    2778             : INLINE GEN
    2779           7 : znstar_get_gen(GEN G) { return abgrp_get_gen(gel(G,2)); }
    2780             : INLINE GEN
    2781     2888417 : znstar_get_conreycyc(GEN G) { return gmael(G,4,5); }
    2782             : INLINE GEN
    2783      887572 : znstar_get_conreygen(GEN G) { return gmael(G,4,4); }
    2784             : INLINE GEN
    2785       28518 : znstar_get_Ui(GEN G) { return gmael(G,4,3); }
    2786             : INLINE GEN
    2787      118160 : znstar_get_U(GEN G) { return gel(G,5); }
    2788             : INLINE GEN
    2789      521549 : znstar_get_pe(GEN G) { return gmael(G,4,1); }
    2790             : INLINE GEN
    2791       19880 : gal_get_pol(GEN gal) { return gel(gal,1); }
    2792             : INLINE GEN
    2793        1309 : gal_get_p(GEN gal) { return gmael(gal,2,1); }
    2794             : INLINE GEN
    2795          84 : gal_get_e(GEN gal) { return gmael(gal,2,2); }
    2796             : INLINE GEN
    2797       15946 : gal_get_mod(GEN gal) { return gmael(gal,2,3); }
    2798             : INLINE GEN
    2799       16324 : gal_get_roots(GEN gal) { return gel(gal,3); }
    2800             : INLINE GEN
    2801       15904 : gal_get_invvdm(GEN gal) { return gel(gal,4); }
    2802             : INLINE GEN
    2803       15904 : gal_get_den(GEN gal) { return gel(gal,5); }
    2804             : INLINE GEN
    2805       66983 : gal_get_group(GEN gal) { return gel(gal,6); }
    2806             : INLINE GEN
    2807        1715 : gal_get_gen(GEN gal) { return gel(gal,7); }
    2808             : INLINE GEN
    2809        1365 : gal_get_orders(GEN gal) { return gel(gal,8); }
    2810             : 
    2811             : /* assume rnf a genuine rnf */
    2812             : INLINE long
    2813     1233638 : rnf_get_degree(GEN rnf) { return degpol(rnf_get_pol(rnf)); }
    2814             : INLINE long
    2815       16394 : rnf_get_nfdegree(GEN rnf) { return degpol(nf_get_pol(rnf_get_nf(rnf))); }
    2816             : INLINE long
    2817      775698 : rnf_get_absdegree(GEN rnf) { return degpol(gmael(rnf,11,1)); }
    2818             : INLINE GEN
    2819         700 : rnf_get_idealdisc(GEN rnf) { return gmael(rnf,3,1); }
    2820             : INLINE GEN
    2821         742 : rnf_get_k(GEN rnf) { return gmael(rnf,11,3); }
    2822             : INLINE GEN
    2823         609 : rnf_get_alpha(GEN rnf) { return gmael(rnf, 11, 2); }
    2824             : INLINE GEN
    2825      384706 : rnf_get_nf(GEN rnf) { return gel(rnf,10); }
    2826             : INLINE GEN
    2827        3080 : rnf_get_nfzk(GEN rnf) { return gel(rnf,2); }
    2828             : INLINE GEN
    2829      205170 : rnf_get_polabs(GEN rnf) { return gmael(rnf,11,1); }
    2830             : INLINE GEN
    2831     1479849 : rnf_get_pol(GEN rnf) { return gel(rnf,1); }
    2832             : INLINE GEN
    2833          63 : rnf_get_disc(GEN rnf) { return gel(rnf,3); }
    2834             : INLINE GEN
    2835         105 : rnf_get_index(GEN rnf) { return gel(rnf,4); }
    2836             : INLINE long
    2837           0 : rnf_get_varn(GEN rnf) { return varn(gel(rnf,1)); }
    2838             : INLINE GEN
    2839      188580 : rnf_get_nfpol(GEN rnf) { return gmael(rnf,10,1); }
    2840             : INLINE long
    2841        3325 : rnf_get_nfvarn(GEN rnf) { return varn(gmael(rnf,10,1)); }
    2842             : INLINE GEN
    2843        3213 : rnf_get_zk(GEN rnf) { return gel(rnf,7); }
    2844             : INLINE GEN
    2845       96768 : rnf_get_map(GEN rnf) { return gel(rnf,11); }
    2846             : INLINE GEN
    2847        1197 : rnf_get_invzk(GEN rnf) { return gel(rnf,8); }
    2848             : 
    2849             : /* I integral ZM (not HNF), G ZM, rounded Cholesky form of a weighted
    2850             :  * T2 matrix. Reduce I wrt G */
    2851             : INLINE GEN
    2852       14077 : idealpseudored(GEN I, GEN G)
    2853       14077 : { return ZM_mul(I, ZM_lll(ZM_mul(G, I), 0.99, LLL_IM)); }
    2854             : 
    2855             : /* I integral (not necessarily HNF), G ZM, rounded Cholesky form of a weighted
    2856             :  * T2 matrix. Return m in I with T2(m) small */
    2857             : INLINE GEN
    2858      127731 : idealpseudomin(GEN I, GEN G)
    2859             : {
    2860      127731 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2861      127731 :   return ZM_ZC_mul(I, gel(u,1));
    2862             : }
    2863             : /* I, G as in idealpseudomin. Return an irrational m in I with T2(m) small */
    2864             : INLINE GEN
    2865      297163 : idealpseudomin_nonscalar(GEN I, GEN G)
    2866             : {
    2867      297163 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2868      297163 :   GEN m = ZM_ZC_mul(I, gel(u,1));
    2869      297163 :   if (ZV_isscalar(m) && lg(u) > 2) m = ZM_ZC_mul(I, gel(u,2));
    2870      297163 :   return m;
    2871             : }
    2872             : 
    2873             : INLINE GEN
    2874         770 : idealred_elt(GEN nf, GEN I) {
    2875         770 :   pari_sp av = avma;
    2876         770 :   GEN u = idealpseudomin(I, nf_get_roundG(nf));
    2877         770 :   return gerepileupto(av, u);
    2878             : }
    2879             : INLINE GEN
    2880      109444 : idealred(GEN nf, GEN I) { return idealred0(nf, I, NULL); }
    2881             : 
    2882             : INLINE GEN
    2883        2058 : idealchineseinit(GEN nf, GEN x)
    2884        2058 : { return idealchinese(nf,x,NULL); }
    2885             : 
    2886             : /*******************************************************************/
    2887             : /*                                                                 */
    2888             : /*                              CLOSURES                           */
    2889             : /*                                                                 */
    2890             : /*******************************************************************/
    2891   228737722 : INLINE long closure_arity(GEN C)          { return ((ulong)C[1])&ARITYBITS; }
    2892    35442302 : INLINE long closure_is_variadic(GEN C) { return !!(((ulong)C[1])&VARARGBITS); }
    2893   193051333 : INLINE const char *closure_codestr(GEN C)  { return GSTR(gel(C,2))-1; }
    2894           0 : INLINE GEN closure_get_code(GEN C)  { return gel(C,2); }
    2895   192994254 : INLINE GEN closure_get_oper(GEN C)  { return gel(C,3); }
    2896   192967079 : INLINE GEN closure_get_data(GEN C)  { return gel(C,4); }
    2897        9330 : INLINE GEN closure_get_dbg(GEN C)   { return gel(C,5); }
    2898       22398 : INLINE GEN closure_get_text(GEN C)  { return gel(C,6); }
    2899     1166093 : INLINE GEN closure_get_frame(GEN C) { return gel(C,7); }
    2900             : 
    2901             : /*******************************************************************/
    2902             : /*                                                                 */
    2903             : /*                               ERRORS                            */
    2904             : /*                                                                 */
    2905             : /*******************************************************************/
    2906             : INLINE long
    2907       52051 : err_get_num(GEN e) { return e[1]; }
    2908             : INLINE GEN
    2909          77 : err_get_compo(GEN e, long i) { return gel(e, i+1); }
    2910             : 
    2911             : INLINE void
    2912          14 : pari_err_BUG(const char *f) { pari_err(e_BUG,f); }
    2913             : INLINE void
    2914           7 : pari_err_CONSTPOL(const char *f) { pari_err(e_CONSTPOL, f); }
    2915             : INLINE void
    2916          63 : pari_err_COPRIME(const char *f, GEN x, GEN y) { pari_err(e_COPRIME, f,x,y); }
    2917             : INLINE void
    2918         487 : pari_err_DIM(const char *f) { pari_err(e_DIM, f); }
    2919             : INLINE void
    2920           0 : pari_err_FILE(const char *f, const char *g) { pari_err(e_FILE, f,g); }
    2921             : INLINE void
    2922           0 : pari_err_FILEDESC(const char *f, long n) { pari_err(e_FILEDESC, f,n); }
    2923             : INLINE void
    2924          42 : pari_err_FLAG(const char *f) { pari_err(e_FLAG,f); }
    2925             : INLINE void
    2926         420 : pari_err_IMPL(const char *f) { pari_err(e_IMPL,f); }
    2927             : INLINE void
    2928       19716 : pari_err_INV(const char *f, GEN x) { pari_err(e_INV,f,x); }
    2929             : INLINE void
    2930          28 : pari_err_IRREDPOL(const char *f, GEN x) { pari_err(e_IRREDPOL, f,x); }
    2931             : INLINE void
    2932        1996 : 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); }
    2933             : INLINE void
    2934         203 : pari_err_COMPONENT(const char *f, const char *op, GEN l, GEN x) { pari_err(e_COMPONENT, f,op,l,x); }
    2935             : INLINE void
    2936           0 : pari_err_MAXPRIME(ulong c) { pari_err(e_MAXPRIME, c); }
    2937             : INLINE void
    2938         350 : pari_err_OP(const char *f, GEN x, GEN y) { pari_err(e_OP, f,x,y); }
    2939             : INLINE void
    2940          84 : pari_err_OVERFLOW(const char *f) { pari_err(e_OVERFLOW, f); }
    2941             : INLINE void
    2942         218 : pari_err_PREC(const char *f) { pari_err(e_PREC,f); }
    2943             : INLINE void
    2944           0 : pari_err_PACKAGE(const char *f) { pari_err(e_PACKAGE,f); }
    2945             : INLINE void
    2946          70 : pari_err_PRIME(const char *f, GEN x) { pari_err(e_PRIME, f,x); }
    2947             : INLINE void
    2948         749 : pari_err_MODULUS(const char *f, GEN x, GEN y) { pari_err(e_MODULUS, f,x,y); }
    2949             : INLINE void
    2950          49 : pari_err_ROOTS0(const char *f) { pari_err(e_ROOTS0, f); }
    2951             : INLINE void
    2952          77 : pari_err_SQRTN(const char *f, GEN x) { pari_err(e_SQRTN, f,x); }
    2953             : INLINE void
    2954       12461 : pari_err_TYPE(const char *f, GEN x) { pari_err(e_TYPE, f,x); }
    2955             : INLINE void
    2956        3073 : pari_err_TYPE2(const char *f, GEN x, GEN y) { pari_err(e_TYPE2, f,x,y); }
    2957             : INLINE void
    2958         203 : pari_err_VAR(const char *f, GEN x, GEN y) { pari_err(e_VAR, f,x,y); }
    2959             : INLINE void
    2960         175 : pari_err_PRIORITY(const char *f, GEN x, const char *op, long v)
    2961         175 : { pari_err(e_PRIORITY, f,x,op,v); }

Generated by: LCOV version 1.13