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 to exceed 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.14.0 lcov report (development 25889-d46d65e6dd) Lines: 1364 1519 89.8 %
Date: 2020-10-25 06:08:49 Functions: 585 656 89.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; either version 2 of the License, or (at your option) any later
       8             : version. It is distributed in the hope that it will be useful, but WITHOUT
       9             : ANY WARRANTY WHATSOEVER.
      10             : 
      11             : Check the License for details. You should have received a copy of it, along
      12             : with the package; see the file 'COPYING'. If not, write to the Free Software
      13             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
      14             : 
      15             : /*********************************************************************/
      16             : /*                       MALLOC/FREE WRAPPERS                        */
      17             : /*********************************************************************/
      18             : #define BLOCK_SIGALRM_START          \
      19             : {                                    \
      20             :   int block=PARI_SIGINT_block;       \
      21             :   PARI_SIGINT_block = 2;             \
      22             :   MT_SIGINT_BLOCK(block);
      23             : 
      24             : #define BLOCK_SIGINT_START           \
      25             : {                                    \
      26             :   int block=PARI_SIGINT_block;       \
      27             :   PARI_SIGINT_block = 1;             \
      28             :   MT_SIGINT_BLOCK(block);
      29             : 
      30             : #define BLOCK_SIGINT_END             \
      31             :   PARI_SIGINT_block = block;         \
      32             :   MT_SIGINT_UNBLOCK(block);          \
      33             :   if (!block && PARI_SIGINT_pending) \
      34             :   {                                  \
      35             :     int sig = PARI_SIGINT_pending;   \
      36             :     PARI_SIGINT_pending = 0;         \
      37             :     raise(sig);                      \
      38             :   }                                  \
      39             : }
      40             : 
      41             : /*******************************************************************/
      42             : /*                                                                 */
      43             : /*                          CONSTRUCTORS                           */
      44             : /*                                                                 */
      45             : /*******************************************************************/
      46             : #define retmkfrac(x,y)\
      47             :   do { GEN _v = cgetg(3, t_FRAC);\
      48             :        gel(_v,1) = (x);\
      49             :        gel(_v,2) = (y); return _v; } while(0)
      50             : #define retmkrfrac(x,y)\
      51             :   do { GEN _v = cgetg(3, t_RFRAC);\
      52             :        gel(_v,1) = (x);\
      53             :        gel(_v,2) = (y); return _v; } while(0)
      54             : #define retmkintmod(x,y)\
      55             :   do { GEN _v = cgetg(3, t_INTMOD);\
      56             :        gel(_v,1) = (y);\
      57             :        gel(_v,2) = (x); return _v; } while(0)
      58             : #define retmkcomplex(x,y)\
      59             :   do { GEN _v = cgetg(3, t_COMPLEX);\
      60             :        gel(_v,1) = (x);\
      61             :        gel(_v,2) = (y); return _v; } while(0)
      62             : #define retmkpolmod(x,y)\
      63             :   do { GEN _v = cgetg(3, t_POLMOD);\
      64             :        gel(_v,1) = (y);\
      65             :        gel(_v,2) = (x); return _v; } while(0)
      66             : #define retmkvec(x)\
      67             :   do { GEN _v = cgetg(2, t_VEC);\
      68             :        gel(_v,1) = (x); return _v; } while(0)
      69             : #define retmkvec2(x,y)\
      70             :   do { GEN _v = cgetg(3, t_VEC);\
      71             :        gel(_v,1) = (x);\
      72             :        gel(_v,2) = (y); return _v; } while(0)
      73             : #define retmkvec3(x,y,z)\
      74             :   do { GEN _v = cgetg(4, t_VEC);\
      75             :        gel(_v,1) = (x);\
      76             :        gel(_v,2) = (y);\
      77             :        gel(_v,3) = (z); return _v; } while(0)
      78             : #define retmkqfi(x,y,z)\
      79             :   do { GEN _v = cgetg(4, t_QFI);\
      80             :        gel(_v,1) = (x);\
      81             :        gel(_v,2) = (y);\
      82             :        gel(_v,3) = (z); return _v; } while(0)
      83             : #define retmkqfr(x,y,z,d)\
      84             :   do { GEN _v = cgetg(5, t_QFR);\
      85             :        gel(_v,1) = (x);\
      86             :        gel(_v,2) = (y);\
      87             :        gel(_v,3) = (z);\
      88             :        gel(_v,4) = (d); return _v; } while(0)
      89             : #define retmkquad(x,y,z)\
      90             :   do { GEN _v = cgetg(4, t_QUAD);\
      91             :        gel(_v,1) = (x);\
      92             :        gel(_v,2) = (y);\
      93             :        gel(_v,3) = (z); return _v; } while(0)
      94             : #define retmkvec4(x,y,z,t)\
      95             :   do { GEN _v = cgetg(5, t_VEC);\
      96             :        gel(_v,1) = (x);\
      97             :        gel(_v,2) = (y);\
      98             :        gel(_v,3) = (z);\
      99             :        gel(_v,4) = (t); return _v; } while(0)
     100             : #define retmkvec5(x,y,z,t,u)\
     101             :   do { GEN _v = cgetg(6, t_VEC);\
     102             :        gel(_v,1) = (x);\
     103             :        gel(_v,2) = (y);\
     104             :        gel(_v,3) = (z);\
     105             :        gel(_v,4) = (t);\
     106             :        gel(_v,5) = (u); return _v; } while(0)
     107             : #define retmkcol(x)\
     108             :   do { GEN _v = cgetg(2, t_COL);\
     109             :        gel(_v,1) = (x); return _v; } while(0)
     110             : #define retmkcol2(x,y)\
     111             :   do { GEN _v = cgetg(3, t_COL);\
     112             :        gel(_v,1) = (x);\
     113             :        gel(_v,2) = (y); return _v; } while(0)
     114             : #define retmkcol3(x,y,z)\
     115             :   do { GEN _v = cgetg(4, t_COL);\
     116             :        gel(_v,1) = (x);\
     117             :        gel(_v,2) = (y);\
     118             :        gel(_v,3) = (z); return _v; } while(0)
     119             : #define retmkcol4(x,y,z,t)\
     120             :   do { GEN _v = cgetg(5, t_COL);\
     121             :        gel(_v,1) = (x);\
     122             :        gel(_v,2) = (y);\
     123             :        gel(_v,3) = (z);\
     124             :        gel(_v,4) = (t); return _v; } while(0)
     125             : #define retmkcol5(x,y,z,t,u)\
     126             :   do { GEN _v = cgetg(6, t_COL);\
     127             :        gel(_v,1) = (x);\
     128             :        gel(_v,2) = (y);\
     129             :        gel(_v,3) = (z);\
     130             :        gel(_v,4) = (t);\
     131             :        gel(_v,5) = (u); return _v; } while(0)
     132             : #define retmkcol6(x,y,z,t,u,v)\
     133             :   do { GEN _v = cgetg(7, t_COL);\
     134             :        gel(_v,1) = (x);\
     135             :        gel(_v,2) = (y);\
     136             :        gel(_v,3) = (z);\
     137             :        gel(_v,4) = (t);\
     138             :        gel(_v,5) = (u);\
     139             :        gel(_v,6) = (v); return _v; } while(0)
     140             : #define retmkmat(x)\
     141             :   do { GEN _v = cgetg(2, t_MAT);\
     142             :        gel(_v,1) = (x); return _v; } while(0)
     143             : #define retmkmat2(x,y)\
     144             :   do { GEN _v = cgetg(3, t_MAT);\
     145             :        gel(_v,1) = (x);\
     146             :        gel(_v,2) = (y); return _v; } while(0)
     147             : #define retmkmat3(x,y,z)\
     148             :   do { GEN _v = cgetg(4, t_MAT);\
     149             :        gel(_v,1) = (x);\
     150             :        gel(_v,2) = (y);\
     151             :        gel(_v,3) = (z); return _v; } while(0)
     152             : #define retmkmat4(x,y,z,t)\
     153             :   do { GEN _v = cgetg(5, t_MAT);\
     154             :        gel(_v,1) = (x);\
     155             :        gel(_v,2) = (y);\
     156             :        gel(_v,3) = (z);\
     157             :        gel(_v,4) = (t); return _v; } while(0)
     158             : #define retmkmat5(x,y,z,t,u)\
     159             :   do { GEN _v = cgetg(6, t_MAT);\
     160             :        gel(_v,1) = (x);\
     161             :        gel(_v,2) = (y);\
     162             :        gel(_v,3) = (z);\
     163             :        gel(_v,4) = (t);\
     164             :        gel(_v,5) = (u); return _v; } while(0)
     165             : 
     166             : INLINE GEN
     167     3086965 : mkintmod(GEN x, GEN y) { retmkintmod(x,y); }
     168             : INLINE GEN
     169        1666 : mkintmodu(ulong x, ulong y) {
     170        1666 :   GEN v = cgetg(3,t_INTMOD);
     171        1666 :   gel(v,1) = utoipos(y);
     172        1666 :   gel(v,2) = utoi(x); return v;
     173             : }
     174             : INLINE GEN
     175     3412463 : mkpolmod(GEN x, GEN y) { retmkpolmod(x,y); }
     176             : INLINE GEN
     177    26313905 : mkfrac(GEN x, GEN y) { retmkfrac(x,y); }
     178             : INLINE GEN
     179       32678 : mkfracss(long x, long y) { retmkfrac(stoi(x),utoipos(y)); }
     180             : /* q = n/d a t_FRAC or t_INT; recover (n,d) */
     181             : INLINE void
     182       14126 : Qtoss(GEN q, long *n, long *d)
     183             : {
     184       14126 :   if (typ(q) == t_INT) { *n = itos(q); *d = 1; }
     185        2891 :   else { *n = itos(gel(q,1)); *d = itou(gel(q,2)); }
     186       14126 : }
     187             : INLINE GEN
     188    68500204 : sstoQ(long n, long d)
     189             : {
     190             :   ulong r;
     191             :   long g, q;
     192    68500204 :   if (!n)
     193             :   {
     194      100452 :     if (!d) pari_err_INV("sstoQ",gen_0);
     195      100452 :     return gen_0;
     196             :   }
     197    68399752 :   if (d < 0) { d = -d; n = -n; }
     198    68399752 :   if (d == 1) return stoi(n);
     199    68387397 :   q = udivuu_rem(labs(n),d,&r);
     200    68387397 :   if (!r) return n > 0? utoipos(q): utoineg(q);
     201     3598099 :   g = ugcd(d,r); /* gcd(n,d) */
     202     3598099 :   if (g != 1) { n /= g; d /= g; }
     203     3598099 :   retmkfrac(stoi(n), utoi(d));
     204             : }
     205             : 
     206             : INLINE GEN
     207     2491502 : mkfraccopy(GEN x, GEN y) { retmkfrac(icopy(x), icopy(y)); }
     208             : INLINE GEN
     209        1645 : mkrfrac(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     210        1645 :   gel(v,1) = x; gel(v,2) = y; return v; }
     211             : INLINE GEN
     212           7 : mkrfraccopy(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     213           7 :   gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     214             : INLINE GEN
     215    25418542 : mkcomplex(GEN x, GEN y) { retmkcomplex(x,y); }
     216             : INLINE GEN
     217      460842 : gen_I(void) { return mkcomplex(gen_0, gen_1); }
     218             : INLINE GEN
     219      285843 : cgetc(long l) { retmkcomplex(cgetr(l), cgetr(l)); }
     220             : INLINE GEN
     221       86331 : mkquad(GEN n, GEN x, GEN y) { GEN v = cgetg(4, t_QUAD);
     222       86331 :   gel(v,1) = n; gel(v,2) = x; gel(v,3) = y; return v; }
     223             : /* vecsmall */
     224             : INLINE GEN
     225    72917813 : mkvecsmall(long x) { GEN v = cgetg(2, t_VECSMALL); v[1] = x; return v; }
     226             : INLINE GEN
     227   118060346 : mkvecsmall2(long x,long y) { GEN v = cgetg(3, t_VECSMALL);
     228   118063451 :   v[1]=x; v[2]=y; return v; }
     229             : INLINE GEN
     230    59054462 : mkvecsmall3(long x,long y,long z) { GEN v = cgetg(4, t_VECSMALL);
     231    59049274 :   v[1]=x; v[2]=y; v[3]=z; return v; }
     232             : INLINE GEN
     233    11998604 : mkvecsmall4(long x,long y,long z,long t) { GEN v = cgetg(5, t_VECSMALL);
     234    11986375 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; return v; }
     235             : INLINE GEN
     236      471351 : mkvecsmall5(long x,long y,long z,long t,long u) { GEN v = cgetg(6, t_VECSMALL);
     237      471353 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; v[5]=u; return v; }
     238             : 
     239             : INLINE GEN
     240      158116 : mkqfi(GEN x, GEN y, GEN z) { retmkqfi(x,y,z); }
     241             : /* vec */
     242             : INLINE GEN
     243    35034353 : mkvec(GEN x) { retmkvec(x); }
     244             : INLINE GEN
     245   110801216 : mkvec2(GEN x, GEN y) { retmkvec2(x,y); }
     246             : INLINE GEN
     247    91790590 : mkvec3(GEN x, GEN y, GEN z) { retmkvec3(x,y,z); }
     248             : INLINE GEN
     249     7362945 : mkvec4(GEN x, GEN y, GEN z, GEN t) { retmkvec4(x,y,z,t); }
     250             : INLINE GEN
     251    12263316 : mkvec5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkvec5(x,y,z,t,u); }
     252             : INLINE GEN
     253         105 : mkvecs(long x) { retmkvec(stoi(x)); }
     254             : INLINE GEN
     255       26664 : mkvec2s(long x, long y) { retmkvec2(stoi(x),stoi(y)); }
     256             : INLINE GEN
     257      492752 : mkvec3s(long x, long y, long z) { retmkvec3(stoi(x),stoi(y),stoi(z)); }
     258             : INLINE GEN
     259          21 : mkvec4s(long x, long y, long z, long t) { retmkvec4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     260             : INLINE GEN
     261       35763 : mkveccopy(GEN x) { GEN v = cgetg(2, t_VEC); gel(v,1) = gcopy(x); return v; }
     262             : INLINE GEN
     263       85350 : mkvec2copy(GEN x, GEN y) {
     264       85350 :   GEN v = cgetg(3,t_VEC); gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     265             : /* col */
     266             : INLINE GEN
     267     3015381 : mkcol(GEN x) { retmkcol(x); }
     268             : INLINE GEN
     269    54244629 : mkcol2(GEN x, GEN y) { retmkcol2(x,y); }
     270             : INLINE GEN
     271       42707 : mkcol3(GEN x, GEN y, GEN z) { retmkcol3(x,y,z); }
     272             : INLINE GEN
     273           0 : mkcol4(GEN x, GEN y, GEN z, GEN t) { retmkcol4(x,y,z,t); }
     274             : INLINE GEN
     275         106 : mkcol5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkcol5(x,y,z,t,u); }
     276             : INLINE GEN
     277        9509 : mkcol6(GEN x, GEN y, GEN z, GEN t, GEN u, GEN v) { retmkcol6(x,y,z,t,u,v); }
     278             : INLINE GEN
     279         273 : mkcols(long x) { retmkcol(stoi(x)); }
     280             : INLINE GEN
     281     2760800 : mkcol2s(long x, long y) { retmkcol2(stoi(x),stoi(y)); }
     282             : INLINE GEN
     283           0 : mkcol3s(long x, long y, long z) { retmkcol3(stoi(x),stoi(y),stoi(z)); }
     284             : INLINE GEN
     285           0 : mkcol4s(long x, long y, long z, long t) { retmkcol4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     286             : INLINE GEN
     287       14670 : mkcolcopy(GEN x) { GEN v = cgetg(2, t_COL); gel(v,1) = gcopy(x); return v; }
     288             : /* mat */
     289             : INLINE GEN
     290     2491691 : mkmat(GEN x) { retmkmat(x); }
     291             : INLINE GEN
     292    32908067 : mkmat2(GEN x, GEN y) { retmkmat2(x,y); }
     293             : INLINE GEN
     294        2329 : mkmat3(GEN x, GEN y, GEN z) { retmkmat3(x,y,z); }
     295             : INLINE GEN
     296           0 : mkmat4(GEN x, GEN y, GEN z, GEN t) { retmkmat4(x,y,z,t); }
     297             : INLINE GEN
     298           0 : mkmat5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkmat5(x,y,z,t,u); }
     299             : INLINE GEN
     300       26400 : mkmatcopy(GEN x) { GEN v = cgetg(2, t_MAT); gel(v,1) = gcopy(x); return v; }
     301             : INLINE GEN
     302           0 : mkerr(long x) { GEN v = cgetg(2, t_ERROR); v[1] = x; return v; }
     303             : INLINE GEN
     304       91143 : mkoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_1; return v; }
     305             : INLINE GEN
     306       18904 : mkmoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_m1; return v; }
     307             : INLINE long
     308      122228 : inf_get_sign(GEN x) { return signe(gel(x,1)); }
     309             : INLINE GEN
     310       12432 : mkmat22s(long a, long b, long c, long d) {retmkmat2(mkcol2s(a,c),mkcol2s(b,d));}
     311             : INLINE GEN
     312     5286134 : mkmat22(GEN a, GEN b, GEN c, GEN d) { retmkmat2(mkcol2(a,c),mkcol2(b,d)); }
     313             : 
     314             : /* pol */
     315             : INLINE GEN
     316     1035277 : pol_x(long v) {
     317     1035277 :   GEN p = cgetg(4, t_POL);
     318     1035279 :   p[1] = evalsigne(1)|evalvarn(v);
     319     1035279 :   gel(p,2) = gen_0;
     320     1035279 :   gel(p,3) = gen_1; return p;
     321             : }
     322             : /* x^n, assume n >= 0 */
     323             : INLINE GEN
     324     1700678 : pol_xn(long n, long v) {
     325     1700678 :   long i, a = n+2;
     326     1700678 :   GEN p = cgetg(a+1, t_POL);
     327     1700678 :   p[1] = evalsigne(1)|evalvarn(v);
     328     4325869 :   for (i = 2; i < a; i++) gel(p,i) = gen_0;
     329     1700678 :   gel(p,a) = gen_1; return p;
     330             : }
     331             : /* x^n, no assumption on n */
     332             : INLINE GEN
     333         287 : pol_xnall(long n, long v)
     334             : {
     335         287 :   if (n < 0) retmkrfrac(gen_1, pol_xn(-n,v));
     336         280 :   return pol_xn(n, v);
     337             : }
     338             : /* x^n, assume n >= 0 */
     339             : INLINE GEN
     340         210 : polxn_Flx(long n, long sv) {
     341         210 :   long i, a = n+2;
     342         210 :   GEN p = cgetg(a+1, t_VECSMALL);
     343         210 :   p[1] = sv;
     344        1022 :   for (i = 2; i < a; i++) p[i] = 0;
     345         210 :   p[a] = 1; return p;
     346             : }
     347             : INLINE GEN
     348     1864558 : pol_1(long v) {
     349     1864558 :   GEN p = cgetg(3, t_POL);
     350     1864557 :   p[1] = evalsigne(1)|evalvarn(v);
     351     1864557 :   gel(p,2) = gen_1; return p;
     352             : }
     353             : INLINE GEN
     354    30513165 : pol_0(long v)
     355             : {
     356    30513165 :   GEN x = cgetg(2,t_POL);
     357    30513157 :   x[1] = evalvarn(v); return x;
     358             : }
     359             : #define retconst_vec(n,x)\
     360             :   do { long _i, _n = (n);\
     361             :        GEN _v = cgetg(_n+1, t_VEC), _x = (x);\
     362             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     363             :        return _v; } while(0)
     364             : INLINE GEN
     365   139238314 : const_vec(long n, GEN x) { retconst_vec(n, x); }
     366             : #define retconst_col(n,x)\
     367             :   do { long _i, _n = (n);\
     368             :        GEN _v = cgetg(_n+1, t_COL), _x = (x);\
     369             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     370             :        return _v; } while(0)
     371             : INLINE GEN
     372    35794131 : const_col(long n, GEN x) { retconst_col(n, x); }
     373             : INLINE GEN
     374    11273312 : const_vecsmall(long n, long c)
     375             : {
     376             :   long i;
     377    11273312 :   GEN V = cgetg(n+1,t_VECSMALL);
     378   382617703 :   for(i=1;i<=n;i++) V[i] = c;
     379    11273308 :   return V;
     380             : }
     381             : 
     382             : /***   ZERO   ***/
     383             : /* O(p^e) */
     384             : INLINE GEN
     385      361939 : zeropadic(GEN p, long e)
     386             : {
     387      361939 :   GEN y = cgetg(5,t_PADIC);
     388      361939 :   gel(y,4) = gen_0;
     389      361939 :   gel(y,3) = gen_1;
     390      361939 :   gel(y,2) = icopy(p);
     391      361939 :   y[1] = evalvalp(e) | _evalprecp(0);
     392      361939 :   return y;
     393             : }
     394             : INLINE GEN
     395         966 : zeropadic_shallow(GEN p, long e)
     396             : {
     397         966 :   GEN y = cgetg(5,t_PADIC);
     398         966 :   gel(y,4) = gen_0;
     399         966 :   gel(y,3) = gen_1;
     400         966 :   gel(y,2) = p;
     401         966 :   y[1] = evalvalp(e) | _evalprecp(0);
     402         966 :   return y;
     403             : }
     404             : /* O(pol_x(v)^e) */
     405             : INLINE GEN
     406      138054 : zeroser(long v, long e)
     407             : {
     408      138054 :   GEN x = cgetg(2, t_SER);
     409      138054 :   x[1] = evalvalp(e) | evalvarn(v); return x;
     410             : }
     411             : INLINE int
     412     7080663 : ser_isexactzero(GEN x)
     413             : {
     414     7080663 :   if (!signe(x)) switch(lg(x))
     415             :   {
     416      132265 :     case 2: return 1;
     417        1267 :     case 3: return isexactzero(gel(x,2));
     418             :   }
     419     6947131 :   return 0;
     420             : }
     421             : /* 0 * pol_x(v) */
     422             : INLINE GEN
     423    14230432 : zeropol(long v) { return pol_0(v); }
     424             : /* vector(n) */
     425             : INLINE GEN
     426    43951213 : zerocol(long n)
     427             : {
     428    43951213 :   GEN y = cgetg(n+1,t_COL);
     429   316449746 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     430    43951369 :   return y;
     431             : }
     432             : /* vectorv(n) */
     433             : INLINE GEN
     434    17105652 : zerovec(long n)
     435             : {
     436    17105652 :   GEN y = cgetg(n+1,t_VEC);
     437   135869542 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     438    17105652 :   return y;
     439             : }
     440             : /* matrix(m, n) */
     441             : INLINE GEN
     442       25738 : zeromat(long m, long n)
     443             : {
     444       25738 :   GEN y = cgetg(n+1,t_MAT);
     445       25738 :   GEN v = zerocol(m);
     446       95439 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     447       25738 :   return y;
     448             : }
     449             : /* = zero_zx, sv is a evalvarn()*/
     450             : INLINE GEN
     451      948571 : zero_Flx(long sv) { return pol0_Flx(sv); }
     452             : INLINE GEN
     453    35692446 : zero_Flv(long n)
     454             : {
     455    35692446 :   GEN y = cgetg(n+1,t_VECSMALL);
     456   762161697 :   long i; for (i=1; i<=n; i++) y[i] = 0;
     457    35692930 :   return y;
     458             : }
     459             : /* matrix(m, n) */
     460             : INLINE GEN
     461     1330409 : zero_Flm(long m, long n)
     462             : {
     463     1330409 :   GEN y = cgetg(n+1,t_MAT);
     464     1330393 :   GEN v = zero_Flv(m);
     465     9128875 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     466     1330380 :   return y;
     467             : }
     468             : /* matrix(m, n) */
     469             : INLINE GEN
     470      113384 : zero_Flm_copy(long m, long n)
     471             : {
     472      113384 :   GEN y = cgetg(n+1,t_MAT);
     473     1672056 :   long i; for (i=1; i<=n; i++) gel(y,i) = zero_Flv(m);
     474      113380 :   return y;
     475             : }
     476             : 
     477             : INLINE GEN
     478      935482 : zero_F2v(long m)
     479             : {
     480      935482 :   long l = nbits2nlong(m);
     481      935482 :   GEN v  = zero_Flv(l+1);
     482      935482 :   v[1] = m;
     483      935482 :   return v;
     484             : }
     485             : 
     486             : INLINE GEN
     487           0 : zero_F2m(long m, long n)
     488             : {
     489             :   long i;
     490           0 :   GEN M = cgetg(n+1, t_MAT);
     491           0 :   GEN v = zero_F2v(m);
     492           0 :   for (i = 1; i <= n; i++)
     493           0 :     gel(M,i) = v;
     494           0 :   return M;
     495             : }
     496             : 
     497             : 
     498             : INLINE GEN
     499      311422 : zero_F2m_copy(long m, long n)
     500             : {
     501             :   long i;
     502      311422 :   GEN M = cgetg(n+1, t_MAT);
     503      830280 :   for (i = 1; i <= n; i++)
     504      518858 :     gel(M,i)= zero_F2v(m);
     505      311422 :   return M;
     506             : }
     507             : 
     508             : /* matrix(m, n) */
     509             : INLINE GEN
     510     5652285 : zeromatcopy(long m, long n)
     511             : {
     512     5652285 :   GEN y = cgetg(n+1,t_MAT);
     513    23428190 :   long i; for (i=1; i<=n; i++) gel(y,i) = zerocol(m);
     514     5652285 :   return y;
     515             : }
     516             : 
     517             : INLINE GEN
     518       17640 : zerovec_block(long len)
     519             : {
     520             :   long i;
     521       17640 :   GEN blk = cgetg_block(len + 1, t_VEC);
     522      582120 :   for (i = 1; i <= len; ++i)
     523      564480 :     gel(blk, i) = gen_0;
     524       17640 :   return blk;
     525             : }
     526             : 
     527             : /* i-th vector in the standard basis */
     528             : INLINE GEN
     529     1392053 : col_ei(long n, long i) { GEN e = zerocol(n); gel(e,i) = gen_1; return e; }
     530             : INLINE GEN
     531      395902 : vec_ei(long n, long i) { GEN e = zerovec(n); gel(e,i) = gen_1; return e; }
     532             : INLINE GEN
     533          42 : F2v_ei(long n, long i) { GEN e = zero_F2v(n); F2v_set(e,i); return e; }
     534             : INLINE GEN
     535       35001 : vecsmall_ei(long n, long i) { GEN e = zero_zv(n); e[i] = 1; return e; }
     536             : INLINE GEN
     537      506985 : Rg_col_ei(GEN x, long n, long i) { GEN e = zerocol(n); gel(e,i) = x; return e; }
     538             : 
     539             : INLINE GEN
     540    13141487 : shallowcopy(GEN x)
     541    13141487 : { return typ(x) == t_MAT ? RgM_shallowcopy(x): leafcopy(x); }
     542             : 
     543             : /* routines for naive growarrays */
     544             : INLINE GEN
     545    12383687 : vectrunc_init(long l)
     546             : {
     547    12383687 :   GEN z = new_chunk(l);
     548    12383599 :   z[0] = evaltyp(t_VEC) | _evallg(1); return z;
     549             : }
     550             : INLINE GEN
     551      347564 : coltrunc_init(long l)
     552             : {
     553      347564 :   GEN z = new_chunk(l);
     554      347564 :   z[0] = evaltyp(t_COL) | _evallg(1); return z;
     555             : }
     556             : INLINE void
     557   267252558 : lg_increase(GEN x) { x[0]++; }
     558             : INLINE void
     559    51351229 : vectrunc_append(GEN x, GEN t) { gel(x, lg(x)) = t; lg_increase(x); }
     560             : INLINE void
     561       10416 : vectrunc_append_batch(GEN x, GEN y)
     562             : {
     563       10416 :   long i, l = lg(x), ly = lg(y);
     564       10416 :   GEN z = x + l-1;
     565       34482 :   for (i = 1; i < ly; i++) gel(z,i) = gel(y,i);
     566       10416 :   setlg(x, l+ly-1);
     567       10416 : }
     568             : INLINE GEN
     569    89135827 : vecsmalltrunc_init(long l)
     570             : {
     571    89135827 :   GEN z = new_chunk(l);
     572    89135827 :   z[0] = evaltyp(t_VECSMALL) | _evallg(1); return z;
     573             : }
     574             : INLINE void
     575    34087418 : vecsmalltrunc_append(GEN x, long t) { x[ lg(x) ] = t; lg_increase(x); }
     576             : 
     577             : /*******************************************************************/
     578             : /*                                                                 */
     579             : /*                    STRING HASH FUNCTIONS                        */
     580             : /*                                                                 */
     581             : /*******************************************************************/
     582             : INLINE ulong
     583     2168453 : hash_str(const char *str)
     584             : {
     585     2168453 :   ulong hash = 5381UL, c;
     586    21752675 :   while ( (c = (ulong)*str++) )
     587    19584222 :     hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
     588     2168453 :   return hash;
     589             : }
     590             : INLINE ulong
     591    10096357 : hash_str_len(const char *str, long len)
     592             : {
     593    10096357 :   ulong hash = 5381UL;
     594             :   long i;
     595    76120371 :   for (i = 0; i < len; i++)
     596             :   {
     597    66024014 :     ulong c = (ulong)*str++;
     598    66024014 :     hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
     599             :   }
     600    10096357 :   return hash;
     601             : }
     602             : 
     603             : /*******************************************************************/
     604             : /*                                                                 */
     605             : /*                        VEC / COL / VECSMALL                     */
     606             : /*                                                                 */
     607             : /*******************************************************************/
     608             : /* shallow*/
     609             : INLINE GEN
     610           0 : vec_shorten(GEN v, long n)
     611             : {
     612             :   long i;
     613           0 :   GEN V = cgetg(n+1,t_VEC);
     614           0 :   for(i=1;i<=n;i++) gel(V,i) = gel(v,i);
     615           0 :   return V;
     616             : }
     617             : /* shallow*/
     618             : INLINE GEN
     619       13731 : vec_lengthen(GEN v, long n)
     620             : {
     621             :   long i;
     622       13731 :   long l=lg(v);
     623       13731 :   GEN V = cgetg(n+1,t_VEC);
     624      455493 :   for(i=1;i<l;i++) gel(V,i) = gel(v,i);
     625       13731 :   return V;
     626             : }
     627             : /* shallow*/
     628             : INLINE GEN
     629       80402 : vec_append(GEN V, GEN s)
     630             : {
     631       80402 :   long i, l2 = lg(V);
     632       80402 :   GEN res = cgetg(l2+1, typ(V));
     633      832145 :   for (i = 1; i < l2; ++i) gel(res, i) = gel(V,i);
     634       80402 :   gel(res,l2) = s; return res;
     635             : }
     636             : /* shallow*/
     637             : INLINE GEN
     638       40827 : vec_prepend(GEN v, GEN s)
     639             : {
     640       40827 :   long i, l = lg(v);
     641       40827 :   GEN w = cgetg(l+1, typ(v));
     642       40827 :   gel(w,1) = s;
     643       77439 :   for (i = 2; i <= l; ++i) gel(w,i) = gel(v,i-1);
     644       40827 :   return w;
     645             : }
     646             : /* shallow*/
     647             : INLINE GEN
     648           0 : vec_setconst(GEN v, GEN x)
     649             : {
     650           0 :   long i, l = lg(v);
     651           0 :   for (i = 1; i < l; i++) gel(v,i) = x;
     652           0 :   return v;
     653             : }
     654             : INLINE GEN
     655       43435 : vecsmall_shorten(GEN v, long n)
     656             : {
     657             :   long i;
     658       43435 :   GEN V = cgetg(n+1,t_VECSMALL);
     659      569632 :   for(i=1;i<=n;i++) V[i] = v[i];
     660       43434 :   return V;
     661             : }
     662             : INLINE GEN
     663           0 : vecsmall_lengthen(GEN v, long n)
     664             : {
     665           0 :   long i, l = lg(v);
     666           0 :   GEN V = cgetg(n+1,t_VECSMALL);
     667           0 :   for(i=1;i<l;i++) V[i] = v[i];
     668           0 :   return V;
     669             : }
     670             : 
     671             : INLINE GEN
     672     3331056 : vec_to_vecsmall(GEN x)
     673    16221258 : { pari_APPLY_long(itos(gel(x,i))) }
     674             : INLINE GEN
     675      143528 : vecsmall_to_vec(GEN x)
     676     4465491 : { pari_APPLY_type(t_VEC, stoi(x[i])) }
     677             : INLINE GEN
     678        2457 : vecsmall_to_vec_inplace(GEN z)
     679             : {
     680        2457 :   long i, l = lg(z);
     681       76587 :   for (i=1; i<l; i++) gel(z,i) = stoi(z[i]);
     682        2457 :   settyp(z, t_VEC); return z;
     683             : }
     684             : INLINE GEN
     685     5362676 : vecsmall_to_col(GEN x)
     686    53621587 : { pari_APPLY_type(t_COL, stoi(x[i])) }
     687             : 
     688             : INLINE int
     689     6088710 : vecsmall_lexcmp(GEN x, GEN y)
     690             : {
     691             :   long lx,ly,l,i;
     692     6088710 :   lx = lg(x);
     693     6088710 :   ly = lg(y); l = minss(lx,ly);
     694    29479854 :   for (i=1; i<l; i++)
     695    27864417 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     696     1615437 :   if (lx == ly) return 0;
     697       30578 :   return (lx < ly)? -1 : 1;
     698             : }
     699             : 
     700             : INLINE int
     701    85249612 : vecsmall_prefixcmp(GEN x, GEN y)
     702             : {
     703    85249612 :   long i, lx = lg(x), ly = lg(y), l = minss(lx,ly);
     704   394179177 :   for (i=1; i<l; i++)
     705   374535735 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     706    19643442 :   return 0;
     707             : }
     708             : 
     709             : /*Can be used on t_VEC, but coeffs not gcopy-ed*/
     710             : INLINE GEN
     711       22421 : vecsmall_prepend(GEN V, long s)
     712             : {
     713       22421 :   long i, l2 = lg(V);
     714       22421 :   GEN res = cgetg(l2+1, typ(V));
     715       22421 :   res[1] = s;
     716       71085 :   for (i = 2; i <= l2; ++i) res[i] = V[i - 1];
     717       22421 :   return res;
     718             : }
     719             : 
     720             : INLINE GEN
     721     2963571 : vecsmall_append(GEN V, long s)
     722             : {
     723     2963571 :   long i, l2 = lg(V);
     724     2963571 :   GEN res = cgetg(l2+1, t_VECSMALL);
     725     4438683 :   for (i = 1; i < l2; ++i) res[i] = V[i];
     726     2963571 :   res[l2] = s; return res;
     727             : }
     728             : 
     729             : INLINE GEN
     730      945921 : vecsmall_concat(GEN u, GEN v)
     731             : {
     732      945921 :   long i, l1 = lg(u)-1, l2 = lg(v)-1;
     733      945921 :   GEN res = cgetg(l1+l2+1, t_VECSMALL);
     734     7320153 :   for (i = 1; i <= l1; ++i) res[i]    = u[i];
     735     8207843 :   for (i = 1; i <= l2; ++i) res[i+l1] = v[i];
     736      945921 :   return res;
     737             : }
     738             : 
     739             : /* return the number of indices where u and v are equal */
     740             : INLINE long
     741           0 : vecsmall_coincidence(GEN u, GEN v)
     742             : {
     743           0 :   long i, s = 0, l = minss(lg(u),lg(v));
     744           0 :   for(i=1; i<l; i++)
     745           0 :     if(u[i] == v[i]) s++;
     746           0 :   return s;
     747             : }
     748             : 
     749             : /* returns the first index i<=n such that x=v[i] if it exists, 0 otherwise */
     750             : INLINE long
     751           0 : vecsmall_isin(GEN v, long x)
     752             : {
     753           0 :   long i, l = lg(v);
     754           0 :   for (i = 1; i < l; i++)
     755           0 :     if (v[i] == x) return i;
     756           0 :   return 0;
     757             : }
     758             : 
     759             : INLINE long
     760          84 : vecsmall_pack(GEN V, long base, long mod)
     761             : {
     762          84 :   long i, s = 0;
     763         273 :   for(i=1; i<lg(V); i++) s = (base*s + V[i]) % mod;
     764          84 :   return s;
     765             : }
     766             : 
     767             : INLINE long
     768          14 : vecsmall_indexmax(GEN x)
     769             : {
     770          14 :   long i, i0 = 1, t = x[1], lx = lg(x);
     771          56 :   for (i=2; i<lx; i++)
     772          42 :     if (x[i] > t) t = x[i0=i];
     773          14 :   return i0;
     774             : }
     775             : 
     776             : INLINE long
     777      381587 : vecsmall_max(GEN x)
     778             : {
     779      381587 :   long i, t = x[1], lx = lg(x);
     780      978211 :   for (i=2; i<lx; i++)
     781      596624 :     if (x[i] > t) t = x[i];
     782      381587 :   return t;
     783             : }
     784             : 
     785             : INLINE long
     786          14 : vecsmall_indexmin(GEN x)
     787             : {
     788          14 :   long i, i0 = 1, t = x[1], lx =lg(x);
     789          56 :   for (i=2; i<lx; i++)
     790          42 :     if (x[i] < t) t = x[i0=i];
     791          14 :   return i0;
     792             : }
     793             : 
     794             : INLINE long
     795        1421 : vecsmall_min(GEN x)
     796             : {
     797        1421 :   long i, t = x[1], lx =lg(x);
     798        9947 :   for (i=2; i<lx; i++)
     799        8526 :     if (x[i] < t) t = x[i];
     800        1421 :   return t;
     801             : }
     802             : 
     803             : INLINE int
     804     8316967 : ZV_isscalar(GEN x)
     805             : {
     806     8316967 :   long l = lg(x);
     807    19479982 :   while (--l > 1)
     808    18132170 :     if (signe(gel(x, l))) return 0;
     809     1347812 :   return 1;
     810             : }
     811             : INLINE int
     812    24565111 : QV_isscalar(GEN x)
     813             : {
     814    24565111 :   long lx = lg(x),i;
     815    27339174 :   for (i=2; i<lx; i++)
     816    26579059 :     if (!isintzero(gel(x, i))) return 0;
     817      760115 :   return 1;
     818             : }
     819             : INLINE int
     820        7184 : RgV_isscalar(GEN x)
     821             : {
     822        7184 :   long lx = lg(x),i;
     823        7340 :   for (i=2; i<lx; i++)
     824        7298 :     if (!gequal0(gel(x, i))) return 0;
     825          42 :   return 1;
     826             : }
     827             : INLINE int
     828           0 : RgX_isscalar(GEN x)
     829             : {
     830             :   long i;
     831           0 :   for (i=lg(x)-1; i>2; i--)
     832           0 :     if (!gequal0(gel(x, i))) return 0;
     833           0 :   return 1;
     834             : }
     835             : INLINE long
     836    24846871 : RgX_equal_var(GEN x, GEN y) { return varn(x) == varn(y) && RgX_equal(x,y); }
     837             : 
     838             : INLINE int
     839       10213 : RgX_is_rational(GEN x)
     840             : {
     841             :   long i;
     842       57697 :   for (i = lg(x)-1; i > 1; i--)
     843       53385 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     844        4312 :   return 1;
     845             : }
     846             : INLINE int
     847     5268901 : RgX_is_ZX(GEN x)
     848             : {
     849             :   long i;
     850    23778900 :   for (i = lg(x)-1; i > 1; i--)
     851    18562546 :     if (typ(gel(x,i)) != t_INT) return 0;
     852     5216354 :   return 1;
     853             : }
     854             : INLINE int
     855      258247 : RgX_is_QX(GEN x)
     856             : {
     857      258247 :   long k = lg(x)-1;
     858      955644 :   for ( ; k>1; k--)
     859      697677 :     if (!is_rational_t(typ(gel(x,k)))) return 0;
     860      257967 :   return 1;
     861             : }
     862             : INLINE int
     863     2341872 : RgX_is_monomial(GEN x)
     864             : {
     865             :   long i;
     866     2341872 :   if (!signe(x)) return 0;
     867     5854282 :   for (i=lg(x)-2; i>1; i--)
     868     3560425 :     if (!isexactzero(gel(x,i))) return 0;
     869     2293857 :   return 1;
     870             : }
     871             : INLINE int
     872    27696538 : RgV_is_ZV(GEN x)
     873             : {
     874             :   long i;
     875   113265874 :   for (i = lg(x)-1; i > 0; i--)
     876    85572640 :     if (typ(gel(x,i)) != t_INT) return 0;
     877    27693234 :   return 1;
     878             : }
     879             : INLINE int
     880       24283 : RgV_is_QV(GEN x)
     881             : {
     882             :   long i;
     883      111930 :   for (i = lg(x)-1; i > 0; i--)
     884       89341 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     885       22589 :   return 1;
     886             : }
     887             : INLINE long
     888       24241 : RgV_isin_i(GEN v, GEN x, long n)
     889             : {
     890             :   long i;
     891      513345 :   for (i = 1; i <= n; i++)
     892      513086 :     if (gequal(gel(v,i), x)) return i;
     893         259 :   return 0;
     894             : }
     895             : INLINE long
     896       24241 : RgV_isin(GEN v, GEN x) { return RgV_isin_i(v, x, lg(v)-1); }
     897             : 
     898             : /********************************************************************/
     899             : /**                                                                **/
     900             : /**            Dynamic arrays implementation                       **/
     901             : /**                                                                **/
     902             : /********************************************************************/
     903             : INLINE void **
     904   471634991 : pari_stack_base(pari_stack *s) { return s->data; }
     905             : 
     906             : INLINE void
     907     2984593 : pari_stack_init(pari_stack *s, size_t size, void **data)
     908             : {
     909     2984593 :   s->data = data;
     910     2984593 :   *data = NULL;
     911     2984593 :   s->n = 0;
     912     2984593 :   s->alloc = 0;
     913     2984593 :   s->size = size;
     914     2984593 : }
     915             : 
     916             : INLINE void
     917   468866716 : pari_stack_alloc(pari_stack *s, long nb)
     918             : {
     919   468866716 :   void **sdat = pari_stack_base(s);
     920   468812611 :   long alloc = s->alloc;
     921   468812611 :   if (s->n+nb <= alloc) return;
     922     1133916 :   if (!alloc)
     923     1065021 :     alloc = nb;
     924             :   else
     925             :   {
     926      137922 :     while (s->n+nb > alloc) alloc <<= 1;
     927             :   }
     928     1133916 :   pari_realloc_ip(sdat,alloc*s->size);
     929     1138707 :   s->alloc = alloc;
     930             : }
     931             : 
     932             : INLINE long
     933   385595526 : pari_stack_new(pari_stack *s) { pari_stack_alloc(s, 1); return s->n++; }
     934             : 
     935             : INLINE void
     936     2785438 : pari_stack_delete(pari_stack *s)
     937             : {
     938     2785438 :   void **sdat = pari_stack_base(s);
     939     2780245 :   if (*sdat) pari_free(*sdat);
     940     2797452 : }
     941             : 
     942             : INLINE void
     943        5102 : pari_stack_pushp(pari_stack *s, void *u)
     944             : {
     945        5102 :   long n = pari_stack_new(s);
     946        5102 :   void **sdat =(void**) *pari_stack_base(s);
     947        5102 :   sdat[n] = u;
     948        5102 : }
     949             : 
     950             : /*******************************************************************/
     951             : /*                                                                 */
     952             : /*                            EXTRACT                              */
     953             : /*                                                                 */
     954             : /*******************************************************************/
     955             : INLINE GEN
     956   397787139 : vecslice(GEN A, long y1, long y2)
     957             : {
     958   397787139 :   long i,lB = y2 - y1 + 2;
     959   397787139 :   GEN B = cgetg(lB, typ(A));
     960  1821806994 :   for (i=1; i<lB; i++) B[i] = A[y1-1+i];
     961   397779938 :   return B;
     962             : }
     963             : INLINE GEN
     964     1184893 : vecslicepermute(GEN A, GEN p, long y1, long y2)
     965             : {
     966     1184893 :   long i,lB = y2 - y1 + 2;
     967     1184893 :   GEN B = cgetg(lB, typ(A));
     968    22787270 :   for (i=1; i<lB; i++) B[i] = A[p[y1-1+i]];
     969     1184886 :   return B;
     970             : }
     971             : /* rowslice(rowpermute(A,p), x1, x2) */
     972             : INLINE GEN
     973       54736 : rowslicepermute(GEN x, GEN p, long j1, long j2)
     974      273048 : { pari_APPLY_same(vecslicepermute(gel(x,i),p,j1,j2)) }
     975             : 
     976             : INLINE GEN
     977    34745620 : rowslice(GEN x, long j1, long j2)
     978   404998333 : { pari_APPLY_same(vecslice(gel(x,i), j1, j2)) }
     979             : 
     980             : INLINE GEN
     981     5739907 : matslice(GEN A, long x1, long x2, long y1, long y2)
     982     5739907 : { return rowslice(vecslice(A, y1, y2), x1, x2); }
     983             : 
     984             : /* shallow, remove coeff of index j */
     985             : INLINE GEN
     986         133 : rowsplice(GEN x, long j)
     987         805 : { pari_APPLY_same(vecsplice(gel(x,i), j)) }
     988             : 
     989             : /* shallow, remove coeff of index j */
     990             : INLINE GEN
     991      268453 : vecsplice(GEN a, long j)
     992             : {
     993      268453 :   long i, k, l = lg(a);
     994             :   GEN b;
     995      268453 :   if (l == 1) pari_err(e_MISC, "incorrect component in vecsplice");
     996      268453 :   b = cgetg(l-1, typ(a));
     997     1242175 :   for (i = k = 1; i < l; i++)
     998      973722 :     if (i != j) gel(b, k++) = gel(a,i);
     999      268453 :   return b;
    1000             : }
    1001             : /* shallow */
    1002             : INLINE GEN
    1003        1036 : RgM_minor(GEN a, long i, long j)
    1004             : {
    1005        1036 :   GEN b = vecsplice(a, j);
    1006        1036 :   long k, l = lg(b);
    1007        4242 :   for (k = 1; k < l; k++) gel(b,k) = vecsplice(gel(b,k), i);
    1008        1036 :   return b;
    1009             : }
    1010             : 
    1011             : /* A[x0,] */
    1012             : INLINE GEN
    1013      390393 : row(GEN x, long j)
    1014     4020368 : { pari_APPLY_type(t_VEC, gcoeff(x, j, i)) }
    1015             : INLINE GEN
    1016     5032393 : Flm_row(GEN x, long j)
    1017   125209673 : { pari_APPLY_ulong((ulong)coeff(x, j, i)) }
    1018             : /* A[x0,] */
    1019             : INLINE GEN
    1020      204834 : rowcopy(GEN x, long j)
    1021     2097809 : { pari_APPLY_type(t_VEC, gcopy(gcoeff(x, j, i))) }
    1022             : /* A[x0, x1..x2] */
    1023             : INLINE GEN
    1024         980 : row_i(GEN A, long x0, long x1, long x2)
    1025             : {
    1026         980 :   long i, lB = x2 - x1 + 2;
    1027         980 :   GEN B  = cgetg(lB, t_VEC);
    1028        2975 :   for (i=x1; i<=x2; i++) gel(B, i) = gcoeff(A, x0, i);
    1029         980 :   return B;
    1030             : }
    1031             : 
    1032             : INLINE GEN
    1033     5971771 : vecreverse(GEN A)
    1034             : {
    1035             :   long i, l;
    1036     5971771 :   GEN B = cgetg_copy(A, &l);
    1037    14497704 :   for (i=1; i<l; i++) gel(B, i) = gel(A, l-i);
    1038     5971771 :   return B;
    1039             : }
    1040             : 
    1041             : INLINE GEN
    1042         686 : vecsmall_reverse(GEN A)
    1043             : {
    1044             :   long i, l;
    1045         686 :   GEN B = cgetg_copy(A, &l);
    1046        2268 :   for (i=1; i<l; i++) B[i] = A[l-i];
    1047         686 :   return B;
    1048             : }
    1049             : 
    1050             : INLINE void
    1051         435 : vecreverse_inplace(GEN y)
    1052             : {
    1053         435 :   long l = lg(y), lim = l>>1, i;
    1054        1648 :   for (i = 1; i <= lim; i++)
    1055             :   {
    1056        1213 :     GEN z = gel(y,i);
    1057        1213 :     gel(y,i)    = gel(y,l-i);
    1058        1213 :     gel(y,l-i) = z;
    1059             :   }
    1060         435 : }
    1061             : 
    1062             : INLINE GEN
    1063    40867636 : vecsmallpermute(GEN A, GEN p) { return perm_mul(A, p); }
    1064             : 
    1065             : INLINE GEN
    1066     7349935 : vecpermute(GEN A, GEN x)
    1067    91143973 : { pari_APPLY_type(typ(A), gel(A, x[i])) }
    1068             : 
    1069             : INLINE GEN
    1070     4089737 : rowpermute(GEN x, GEN p)
    1071    44983303 : { pari_APPLY_same(typ(gel(x,i)) == t_VECSMALL ? vecsmallpermute(gel(x, i), p)
    1072             :                                               : vecpermute(gel(x, i), p))
    1073             : }
    1074             : /*******************************************************************/
    1075             : /*                                                                 */
    1076             : /*                          PERMUTATIONS                           */
    1077             : /*                                                                 */
    1078             : /*******************************************************************/
    1079             : INLINE GEN
    1080      933749 : identity_zv(long n)
    1081             : {
    1082      933749 :   GEN v = cgetg(n+1, t_VECSMALL);
    1083             :   long i;
    1084    15516935 :   for (i = 1; i <= n; i++) v[i] = i;
    1085      933743 :   return v;
    1086             : }
    1087             : INLINE GEN
    1088        3591 : identity_ZV(long n)
    1089             : {
    1090        3591 :   GEN v = cgetg(n+1, t_VEC);
    1091             :   long i;
    1092       44688 :   for (i = 1; i <= n; i++) gel(v,i) = utoipos(i);
    1093        3591 :   return v;
    1094             : }
    1095             : /* identity permutation */
    1096             : INLINE GEN
    1097      933152 : identity_perm(long n) { return identity_zv(n); }
    1098             : 
    1099             : /* assume d <= n */
    1100             : INLINE GEN
    1101       98483 : cyclic_perm(long n, long d)
    1102             : {
    1103       98483 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1104             :   long i;
    1105      504098 :   for (i = 1; i <= n-d; i++) perm[i] = i+d;
    1106      225029 :   for (     ; i <= n;   i++) perm[i] = i-n+d;
    1107       98483 :   return perm;
    1108             : }
    1109             : 
    1110             : /* Multiply (compose) two permutations */
    1111             : INLINE GEN
    1112    41813949 : perm_mul(GEN s, GEN x)
    1113   559456917 : { pari_APPLY_long(s[x[i]]) }
    1114             : 
    1115             : INLINE GEN
    1116          21 : perm_sqr(GEN x)
    1117         525 : { pari_APPLY_long(x[x[i]]) }
    1118             : 
    1119             : /* Compute the inverse (reciprocal) of a permutation. */
    1120             : INLINE GEN
    1121     1349684 : perm_inv(GEN x)
    1122             : {
    1123             :   long i, lx;
    1124     1349684 :   GEN y = cgetg_copy(x, &lx);
    1125    19148475 :   for (i=1; i<lx; i++) y[ x[i] ] = i;
    1126     1349684 :   return y;
    1127             : }
    1128             : /* Return s*t*s^-1 */
    1129             : INLINE GEN
    1130      417312 : perm_conj(GEN s, GEN t)
    1131             : {
    1132             :   long i, l;
    1133      417312 :   GEN v = cgetg_copy(s, &l);
    1134     6838846 :   for (i = 1; i < l; i++) v[ s[i] ] = s[ t[i] ];
    1135      417312 :   return v;
    1136             : }
    1137             : 
    1138             : INLINE void
    1139   306692590 : pari_free(void *pointer)
    1140             : {
    1141   306692590 :   BLOCK_SIGINT_START;
    1142   306712507 :   free(pointer);
    1143   306712507 :   BLOCK_SIGINT_END;
    1144   306715700 : }
    1145             : INLINE void*
    1146   517605881 : pari_malloc(size_t size)
    1147             : {
    1148   517605881 :   if (size)
    1149             :   {
    1150             :     char *tmp;
    1151   517605876 :     BLOCK_SIGINT_START;
    1152   517606298 :     tmp = (char*)malloc(size);
    1153   517606298 :     BLOCK_SIGINT_END;
    1154   517604784 :     if (!tmp) pari_err(e_MEM);
    1155   517609324 :     return tmp;
    1156             :   }
    1157           5 :   return NULL;
    1158             : }
    1159             : INLINE void*
    1160        1647 : pari_realloc(void *pointer, size_t size)
    1161             : {
    1162             :   char *tmp;
    1163             : 
    1164        1647 :   BLOCK_SIGINT_START;
    1165        1647 :   if (!pointer) tmp = (char *) malloc(size);
    1166        1647 :   else tmp = (char *) realloc(pointer,size);
    1167        1647 :   BLOCK_SIGINT_END;
    1168        1647 :   if (!tmp) pari_err(e_MEM);
    1169        1647 :   return tmp;
    1170             : }
    1171             : INLINE void
    1172     1147168 : pari_realloc_ip(void **pointer, size_t size)
    1173             : {
    1174             :   char *tmp;
    1175     1147168 :   BLOCK_SIGINT_START;
    1176     1145964 :   if (!*pointer) tmp = (char *) malloc(size);
    1177       70332 :   else tmp = (char *) realloc(*pointer,size);
    1178     1145964 :   if (!tmp) pari_err(e_MEM);
    1179     1145964 :   *pointer = tmp;
    1180     1145964 :   BLOCK_SIGINT_END;
    1181     1143470 : }
    1182             : 
    1183             : INLINE void*
    1184       39587 : pari_calloc(size_t size)
    1185             : {
    1186       39587 :   void *t = pari_malloc(size);
    1187       39587 :   memset(t, 0, size); return t;
    1188             : }
    1189             : INLINE GEN
    1190        7826 : cgetalloc(long t, size_t l)
    1191             : { /* evallg may raise e_OVERFLOW, which would leak x */
    1192        7826 :   ulong x0 = evaltyp(t) | evallg(l);
    1193        7826 :   GEN x = (GEN)pari_malloc(l * sizeof(long));
    1194        7826 :   x[0] = x0; return x;
    1195             : }
    1196             : 
    1197             : /*******************************************************************/
    1198             : /*                                                                 */
    1199             : /*                       GARBAGE COLLECTION                        */
    1200             : /*                                                                 */
    1201             : /*******************************************************************/
    1202             : /* copy integer x as if we had set_avma(av) */
    1203             : INLINE GEN
    1204  4785440165 : icopy_avma(GEN x, pari_sp av)
    1205             : {
    1206  4785440165 :   long i = lgefint(x), lx = i;
    1207  4785440165 :   GEN y = ((GEN)av) - i;
    1208 26183048967 :   while (--i > 0) y[i] = x[i];
    1209  4785440165 :   y[0] = evaltyp(t_INT)|evallg(lx);
    1210  4788147535 :   return y;
    1211             : }
    1212             : /* copy leaf x as if we had set_avma(av) */
    1213             : INLINE GEN
    1214   257972590 : leafcopy_avma(GEN x, pari_sp av)
    1215             : {
    1216   257972590 :   long i = lg(x);
    1217   257972590 :   GEN y = ((GEN)av) - i;
    1218  1872071576 :   while (--i > 0) y[i] = x[i];
    1219   257972590 :   y[0] = x[0] & (~CLONEBIT);
    1220   257972590 :   return y;
    1221             : }
    1222             : INLINE GEN
    1223   665654095 : gerepileuptoleaf(pari_sp av, GEN x)
    1224             : {
    1225             :   long lx;
    1226             :   GEN q;
    1227             : 
    1228   665654095 :   if (!isonstack(x) || (GEN)av<=x) return gc_const(av,x);
    1229   665369058 :   lx = lg(x);
    1230   665369058 :   q = ((GEN)av) - lx;
    1231   665369058 :   set_avma((pari_sp)q);
    1232  7281517794 :   while (--lx >= 0) q[lx] = x[lx];
    1233   665320789 :   return q;
    1234             : }
    1235             : INLINE GEN
    1236  1862662378 : gerepileuptoint(pari_sp av, GEN x)
    1237             : {
    1238  1862662378 :   if (!isonstack(x) || (GEN)av<=x) return gc_const(av,x);
    1239  1629690017 :   set_avma((pari_sp)icopy_avma(x, av));
    1240  1631708589 :   return (GEN)avma;
    1241             : }
    1242             : INLINE GEN
    1243   849343782 : gerepileupto(pari_sp av, GEN x)
    1244             : {
    1245   849343782 :   if (!isonstack(x) || (GEN)av<=x) return gc_const(av,x);
    1246   751539815 :   switch(typ(x))
    1247             :   { /* non-default = !is_recursive_t(tq) */
    1248   222185983 :     case t_INT: return gerepileuptoint(av, x);
    1249   153652382 :     case t_REAL:
    1250             :     case t_STR:
    1251   153652382 :     case t_VECSMALL: return gerepileuptoleaf(av,x);
    1252   375702265 :     default:
    1253             :       /* NB: x+i --> ((long)x) + i*sizeof(long) */
    1254   375702265 :       return gerepile(av, (pari_sp) (x+lg(x)), x);
    1255             :   }
    1256             : }
    1257             : 
    1258             : /* gerepileupto(av, gcopy(x)) */
    1259             : INLINE GEN
    1260    75805739 : gerepilecopy(pari_sp av, GEN x)
    1261             : {
    1262    75805739 :   if (is_recursive_t(typ(x)))
    1263             :   {
    1264    71119002 :     GENbin *p = copy_bin(x);
    1265    71119868 :     set_avma(av); return bin_copy(p);
    1266             :   }
    1267             :   else
    1268             :   {
    1269     4686804 :     set_avma(av);
    1270     4686807 :     if (x < (GEN)av) {
    1271     3190904 :       if (x < (GEN)pari_mainstack->bot) new_chunk(lg(x));
    1272     3190904 :       x = leafcopy_avma(x, av);
    1273     3190904 :       set_avma((pari_sp)x);
    1274             :     } else
    1275     1495903 :       x = leafcopy(x);
    1276     4686810 :     return x;
    1277             :   }
    1278             : }
    1279             : 
    1280             : INLINE void
    1281    25251107 : guncloneNULL(GEN x) { if (x) gunclone(x); }
    1282             : INLINE void
    1283      382772 : guncloneNULL_deep(GEN x) { if (x) gunclone_deep(x); }
    1284             : 
    1285             : /* Takes an array of pointers to GENs, of length n. Copies all
    1286             :  * objects to contiguous locations and cleans up the stack between
    1287             :  * av and avma. */
    1288             : INLINE void
    1289      194195 : gerepilemany(pari_sp av, GEN* gptr[], int n)
    1290             : {
    1291             :   int i;
    1292      770285 :   for (i=0; i<n; i++) *gptr[i] = (GEN)copy_bin(*gptr[i]);
    1293      194195 :   set_avma(av);
    1294      770285 :   for (i=0; i<n; i++) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1295      194195 : }
    1296             : 
    1297             : INLINE void
    1298    94993064 : gerepileall(pari_sp av, int n, ...)
    1299             : {
    1300             :   int i;
    1301    94993064 :   va_list a; va_start(a, n);
    1302    94993064 :   if (n < 10)
    1303             :   {
    1304             :     GEN *gptr[10];
    1305   311614525 :     for (i=0; i<n; i++)
    1306   216621345 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1307    94993180 :     set_avma(av);
    1308   311614795 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1309             : 
    1310             :   }
    1311             :   else
    1312             :   {
    1313           1 :     GEN **gptr = (GEN**)  pari_malloc(n*sizeof(GEN*));
    1314           0 :     for (i=0; i<n; i++)
    1315           0 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1316           0 :     set_avma(av);
    1317           0 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1318           0 :     pari_free(gptr);
    1319             :   }
    1320    94993373 :   va_end(a);
    1321    94993373 : }
    1322             : 
    1323             : INLINE void
    1324      754560 : gerepilecoeffs(pari_sp av, GEN x, int n)
    1325             : {
    1326             :   int i;
    1327     9880388 :   for (i=0; i<n; i++) gel(x,i) = (GEN)copy_bin(gel(x,i));
    1328      754560 :   set_avma(av);
    1329     9880388 :   for (i=0; i<n; i++) gel(x,i) = bin_copy((GENbin*)x[i]);
    1330      754560 : }
    1331             : 
    1332             : /* p from copy_bin. Copy p->x back to stack, then destroy p */
    1333             : INLINE GEN
    1334   297493524 : bin_copy(GENbin *p)
    1335             : {
    1336             :   GEN x, y, base;
    1337             :   long dx, len;
    1338             : 
    1339   297493524 :   x   = p->x; if (!x) { pari_free(p); return gen_0; }
    1340   273195909 :   len = p->len;
    1341   273195909 :   base= p->base; dx = x - base;
    1342   273195909 :   y = (GEN)memcpy((void*)new_chunk(len), (void*)GENbinbase(p), len*sizeof(long));
    1343   273195592 :   y += dx;
    1344   273195592 :   p->rebase(y, ((ulong)y-(ulong)x));
    1345   273195771 :   pari_free(p); return y;
    1346             : }
    1347             : 
    1348             : INLINE GEN
    1349   570689789 : GENbinbase(GENbin *p) { return (GEN)(p + 1); }
    1350             : 
    1351             : INLINE void
    1352    81847284 : cgiv(GEN x)
    1353             : {
    1354    81847284 :   pari_sp av = (pari_sp)(x+lg(x));
    1355    81847284 :   if (isonstack((GEN)av)) set_avma(av);
    1356    81846430 : }
    1357             : 
    1358             : INLINE void
    1359     6597422 : killblock(GEN x) { gunclone(x); }
    1360             : 
    1361             : INLINE int
    1362   240266967 : is_universal_constant(GEN x) { return (x >= gen_0 && x <= ghalf); }
    1363             : 
    1364             : /*******************************************************************/
    1365             : /*                                                                 */
    1366             : /*                    CONVERSION / ASSIGNMENT                      */
    1367             : /*                                                                 */
    1368             : /*******************************************************************/
    1369             : /* z is a type which may be a t_COMPLEX component (not a t_QUAD) */
    1370             : INLINE GEN
    1371     5350645 : cxcompotor(GEN z, long prec)
    1372             : {
    1373     5350645 :   switch(typ(z))
    1374             :   {
    1375     3101848 :     case t_INT:  return itor(z, prec);
    1376      136696 :     case t_FRAC: return fractor(z, prec);
    1377     2112101 :     case t_REAL: return rtor(z, prec);
    1378           0 :     default: pari_err_TYPE("cxcompotor",z);
    1379             :              return NULL; /* LCOV_EXCL_LINE */
    1380             :   }
    1381             : }
    1382             : INLINE GEN
    1383     2662280 : cxtofp(GEN x, long prec)
    1384     2662280 : { retmkcomplex(cxcompotor(gel(x,1),prec), cxcompotor(gel(x,2),prec)); }
    1385             : 
    1386             : INLINE GEN
    1387      273430 : cxtoreal(GEN q)
    1388      273430 : { return (typ(q) == t_COMPLEX && gequal0(gel(q,2)))? gel(q,1): q; }
    1389             : 
    1390             : INLINE double
    1391    26263810 : gtodouble(GEN x)
    1392             : {
    1393    26263810 :   if (typ(x)!=t_REAL) {
    1394     4797350 :     pari_sp av = avma;
    1395     4797350 :     x = gtofp(x, DEFAULTPREC);
    1396     4796668 :     if (typ(x)!=t_REAL) pari_err_TYPE("gtodouble [t_REAL expected]", x);
    1397     4796668 :     set_avma(av);
    1398             :   }
    1399    26263013 :   return rtodbl(x);
    1400             : }
    1401             : 
    1402             : INLINE int
    1403    11643479 : gisdouble(GEN x, double *g)
    1404             : {
    1405    11643479 :   if (typ(x)!=t_REAL) {
    1406     1250744 :     pari_sp av = avma;
    1407     1250744 :     x = gtofp(x, DEFAULTPREC);
    1408     1250744 :     if (typ(x)!=t_REAL) pari_err_TYPE("gisdouble [t_REAL expected]", x);
    1409     1250744 :     set_avma(av);
    1410             :   }
    1411    11643479 :   if (expo(x) >= 0x3ff) return 0;
    1412    11643479 :   *g = rtodbl(x); return 1;
    1413             : }
    1414             : 
    1415             : INLINE long
    1416    73478426 : gtos(GEN x) {
    1417    73478426 :   if (typ(x) != t_INT) pari_err_TYPE("gtos [integer expected]",x);
    1418    73478419 :   return itos(x);
    1419             : }
    1420             : 
    1421             : INLINE ulong
    1422       86827 : gtou(GEN x) {
    1423       86827 :   if (typ(x) != t_INT || signe(x)<0)
    1424           7 :     pari_err_TYPE("gtou [integer >=0 expected]",x);
    1425       86820 :   return itou(x);
    1426             : }
    1427             : 
    1428             : INLINE GEN
    1429    35834185 : absfrac(GEN x)
    1430             : {
    1431    35834185 :   GEN y = cgetg(3, t_FRAC);
    1432    35834185 :   gel(y,1) = absi(gel(x,1));
    1433    35834185 :   gel(y,2) = icopy(gel(x,2)); return y;
    1434             : }
    1435             : INLINE GEN
    1436       38059 : absfrac_shallow(GEN x)
    1437       38059 : { return signe(gel(x,1))>0? x: mkfrac(negi(gel(x,1)), gel(x,2)); }
    1438             : INLINE GEN
    1439    10024302 : Q_abs(GEN x) { return (typ(x) == t_INT)? absi(x): absfrac(x); }
    1440             : INLINE GEN
    1441      125734 : Q_abs_shallow(GEN x)
    1442      125734 : { return (typ(x) == t_INT)? absi_shallow(x): absfrac_shallow(x); }
    1443             : INLINE GEN
    1444       12712 : R_abs_shallow(GEN x)
    1445       12712 : { return (typ(x) == t_FRAC)? absfrac_shallow(x): mpabs_shallow(x); }
    1446             : INLINE GEN
    1447           0 : R_abs(GEN x)
    1448           0 : { return (typ(x) == t_FRAC)? absfrac(x): mpabs(x); }
    1449             : 
    1450             : /* Force z to be of type real/complex with floating point components */
    1451             : INLINE GEN
    1452    39334750 : gtofp(GEN z, long prec)
    1453             : {
    1454    39334750 :   switch(typ(z))
    1455             :   {
    1456    23884860 :     case t_INT:  return itor(z, prec);
    1457     4068126 :     case t_FRAC: return fractor(z, prec);
    1458     8968787 :     case t_REAL: return rtor(z, prec);
    1459     2414738 :     case t_COMPLEX: {
    1460     2414738 :       GEN a = gel(z,1), b = gel(z,2);
    1461     2414738 :       if (isintzero(b)) return cxcompotor(a, prec);
    1462     2414738 :       if (isintzero(a)) {
    1463        3947 :         GEN y = cgetg(3, t_COMPLEX);
    1464        3947 :         b = cxcompotor(b, prec);
    1465        3947 :         gel(y,1) = real_0_bit(expo(b) - prec2nbits(prec));
    1466        3947 :         gel(y,2) = b; return y;
    1467             :       }
    1468     2410791 :       return cxtofp(z, prec);
    1469             :     }
    1470           0 :     case t_QUAD: return quadtofp(z, prec);
    1471           0 :     default: pari_err_TYPE("gtofp",z);
    1472             :              return NULL; /* LCOV_EXCL_LINE */
    1473             :   }
    1474             : }
    1475             : /* Force z to be of type real / int */
    1476             : INLINE GEN
    1477       22428 : gtomp(GEN z, long prec)
    1478             : {
    1479       22428 :   switch(typ(z))
    1480             :   {
    1481          42 :     case t_INT:  return z;
    1482       22386 :     case t_FRAC: return fractor(z, prec);
    1483           0 :     case t_REAL: return rtor(z, prec);
    1484           0 :     case t_QUAD: z = quadtofp(z, prec);
    1485           0 :                  if (typ(z) == t_REAL) return z;
    1486           0 :     default: pari_err_TYPE("gtomp",z);
    1487             :              return NULL; /* LCOV_EXCL_LINE */
    1488             :   }
    1489             : }
    1490             : 
    1491             : INLINE GEN
    1492     1140181 : RgX_gtofp(GEN x, long prec)
    1493             : {
    1494             :   long l;
    1495     1140181 :   GEN y = cgetg_copy(x, &l);
    1496     7040457 :   while (--l > 1) gel(y,l) = gtofp(gel(x,l), prec);
    1497     1140181 :   y[1] = x[1]; return y;
    1498             : }
    1499             : INLINE GEN
    1500     1314361 : RgC_gtofp(GEN x, long prec)
    1501    15998892 : { pari_APPLY_type(t_COL, gtofp(gel(x,i), prec)) }
    1502             : 
    1503             : INLINE GEN
    1504       13209 : RgV_gtofp(GEN x, long prec)
    1505       40817 : { pari_APPLY_type(t_VEC, gtofp(gel(x,i), prec)) }
    1506             : 
    1507             : INLINE GEN
    1508      144603 : RgM_gtofp(GEN x, long prec)
    1509     1199911 : { pari_APPLY_same(RgC_gtofp(gel(x,i), prec)) }
    1510             : 
    1511             : INLINE GEN
    1512         574 : RgC_gtomp(GEN x, long prec)
    1513       23002 : { pari_APPLY_type(t_COL, gtomp(gel(x,i), prec)) }
    1514             : 
    1515             : INLINE GEN
    1516          21 : RgM_gtomp(GEN x, long prec)
    1517         595 : { pari_APPLY_same(RgC_gtomp(gel(x,i), prec)) }
    1518             : 
    1519             : INLINE GEN
    1520       11739 : RgX_fpnorml2(GEN x, long prec)
    1521             : {
    1522       11739 :   pari_sp av = avma;
    1523       11739 :   return gerepileupto(av, gnorml2(RgX_gtofp(x, prec)));
    1524             : }
    1525             : INLINE GEN
    1526      246470 : RgC_fpnorml2(GEN x, long prec)
    1527             : {
    1528      246470 :   pari_sp av = avma;
    1529      246470 :   return gerepileupto(av, gnorml2(RgC_gtofp(x, prec)));
    1530             : }
    1531             : INLINE GEN
    1532        7681 : RgM_fpnorml2(GEN x, long prec)
    1533             : {
    1534        7681 :   pari_sp av = avma;
    1535        7681 :   return gerepileupto(av, gnorml2(RgM_gtofp(x, prec)));
    1536             : }
    1537             : 
    1538             : /* y a t_REAL */
    1539             : INLINE void
    1540      216244 : affgr(GEN x, GEN y)
    1541             : {
    1542             :   pari_sp av;
    1543      216244 :   switch(typ(x)) {
    1544        5992 :     case t_INT:  affir(x,y); break;
    1545      210252 :     case t_REAL: affrr(x,y); break;
    1546           0 :     case t_FRAC: rdiviiz(gel(x,1),gel(x,2), y); break;
    1547           0 :     case t_QUAD: av = avma; affgr(quadtofp(x,realprec(y)), y); set_avma(av); break;
    1548           0 :     default: pari_err_TYPE2("=",x,y);
    1549             :   }
    1550      216244 : }
    1551             : 
    1552             : INLINE GEN
    1553      243077 : affc_fixlg(GEN x, GEN res)
    1554             : {
    1555      243077 :   if (typ(x) == t_COMPLEX)
    1556             :   {
    1557      210672 :     affrr_fixlg(gel(x,1), gel(res,1));
    1558      210672 :     affrr_fixlg(gel(x,2), gel(res,2));
    1559             :   }
    1560             :   else
    1561             :   {
    1562       32405 :     set_avma((pari_sp)(res+3));
    1563       32404 :     res = cgetr(realprec(gel(res,1)));
    1564       32411 :     affrr_fixlg(x, res);
    1565             :   }
    1566      243083 :   return res;
    1567             : }
    1568             : 
    1569             : INLINE GEN
    1570           0 : trunc_safe(GEN x) { long e; return gcvtoi(x,&e); }
    1571             : 
    1572             : /*******************************************************************/
    1573             : /*                                                                 */
    1574             : /*                          LENGTH CONVERSIONS                     */
    1575             : /*                                                                 */
    1576             : /*******************************************************************/
    1577             : INLINE long
    1578       36074 : ndec2nlong(long x) { return 1 + (long)((x)*(LOG2_10/BITS_IN_LONG)); }
    1579             : INLINE long
    1580       27791 : ndec2prec(long x) { return 2 + ndec2nlong(x); }
    1581             : INLINE long
    1582        8283 : ndec2nbits(long x) { return ndec2nlong(x) << TWOPOTBITS_IN_LONG; }
    1583             : /* Fast implementation of ceil(x / (8*sizeof(long))); typecast to (ulong)
    1584             :  * to avoid overflow. Faster than 1 + ((x-1)>>TWOPOTBITS_IN_LONG)) :
    1585             :  *   addl, shrl instead of subl, sarl, addl */
    1586             : INLINE long
    1587     6876322 : nbits2nlong(long x) {
    1588     6876322 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1589             : }
    1590             : 
    1591             : INLINE long
    1592   401878694 : nbits2extraprec(long x) {
    1593   401878694 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1594             : }
    1595             : 
    1596             : /* Fast implementation of 2 + nbits2nlong(x) */
    1597             : INLINE long
    1598   139182115 : nbits2prec(long x) {
    1599   139182115 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1600             : }
    1601             : INLINE long
    1602   196820520 : nbits2lg(long x) {
    1603   196820520 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1604             : }
    1605             : /* ceil(x / sizeof(long)) */
    1606             : INLINE long
    1607    16817391 : nchar2nlong(long x) {
    1608    16817391 :   return (long)(((ulong)x+sizeof(long)-1) >> (TWOPOTBITS_IN_LONG-3L));
    1609             : }
    1610             : INLINE long
    1611  1686548638 : prec2nbits(long x) { return (x-2) * BITS_IN_LONG; }
    1612             : INLINE double
    1613     2865320 : bit_accuracy_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1614             : INLINE double
    1615      272379 : prec2nbits_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1616             : INLINE long
    1617    57685841 : bit_prec(GEN x) { return prec2nbits(realprec(x)); }
    1618             : INLINE long
    1619  1495586777 : bit_accuracy(long x) { return prec2nbits(x); }
    1620             : INLINE long
    1621       12847 : prec2ndec(long x) { return (long)prec2nbits_mul(x, LOG10_2); }
    1622             : INLINE long
    1623         186 : nbits2ndec(long x) { return (long)(x * LOG10_2); }
    1624             : INLINE long
    1625        3193 : precdbl(long x) {return (x - 1) << 1;}
    1626             : INLINE long
    1627  4640123282 : divsBIL(long n) { return n >> TWOPOTBITS_IN_LONG; }
    1628             : INLINE long
    1629  4583210217 : remsBIL(long n) { return n & (BITS_IN_LONG-1); }
    1630             : 
    1631             : /*********************************************************************/
    1632             : /**                                                                 **/
    1633             : /**                      OPERATIONS MODULO m                        **/
    1634             : /**                                                                 **/
    1635             : /*********************************************************************/
    1636             : /* Assume m > 0, more efficient if 0 <= a, b < m */
    1637             : 
    1638             : INLINE GEN
    1639    36828683 : Fp_red(GEN a, GEN m) { return modii(a, m); }
    1640             : INLINE GEN
    1641    96254706 : Fp_add(GEN a, GEN b, GEN m)
    1642             : {
    1643    96254706 :   pari_sp av=avma;
    1644    96254706 :   GEN p = addii(a,b);
    1645    94693759 :   long s = signe(p);
    1646    94693759 :   if (!s) return p; /* = gen_0 */
    1647    83980191 :   if (s > 0) /* general case */
    1648             :   {
    1649    84003451 :     GEN t = subii(p, m);
    1650    83691236 :     s = signe(t);
    1651    83691236 :     if (!s) return gc_const(av, gen_0);
    1652    76253805 :     if (s < 0) return gc_const((pari_sp)p, p);
    1653    38522933 :     if (cmpii(t, m) < 0) return gerepileuptoint(av, t); /* general case ! */
    1654     2990732 :     p = remii(t, m);
    1655             :   }
    1656             :   else
    1657      226443 :     p = modii(p, m);
    1658     3217175 :   return gerepileuptoint(av, p);
    1659             : }
    1660             : INLINE GEN
    1661    65931201 : Fp_sub(GEN a, GEN b, GEN m)
    1662             : {
    1663    65931201 :   pari_sp av=avma;
    1664    65931201 :   GEN p = subii(a,b);
    1665    63968045 :   long s = signe(p);
    1666    63968045 :   if (!s) return p; /* = gen_0 */
    1667    56236217 :   if (s > 0)
    1668             :   {
    1669    25843725 :     if (cmpii(p, m) < 0) return p; /* general case ! */
    1670     1049288 :     p = remii(p, m);
    1671             :   }
    1672             :   else
    1673             :   {
    1674    30392492 :     GEN t = addii(p, m);
    1675    32196381 :     if (!s) return gc_const(av, gen_0);
    1676    32264580 :     if (s > 0) return gerepileuptoint(av, t); /* general case ! */
    1677    32264580 :     p = modii(t, m);
    1678             :   }
    1679    33598546 :   return gerepileuptoint(av, p);
    1680             : }
    1681             : INLINE GEN
    1682    14303745 : Fp_neg(GEN b, GEN m)
    1683             : {
    1684    14303745 :   pari_sp av = avma;
    1685    14303745 :   long s = signe(b);
    1686             :   GEN p;
    1687    14303745 :   if (!s) return gen_0;
    1688    11107497 :   if (s > 0)
    1689             :   {
    1690    10908865 :     p = subii(m, b);
    1691    10906086 :     if (signe(p) >= 0) return p; /* general case ! */
    1692      131659 :     p = modii(p, m);
    1693             :   } else
    1694      199883 :     p = remii(negi(b), m);
    1695      331599 :   return gerepileuptoint(av, p);
    1696             : }
    1697             : 
    1698             : INLINE GEN
    1699       63497 : Fp_halve(GEN a, GEN p)
    1700             : {
    1701       63497 :   if (mpodd(a)) a = addii(a,p);
    1702       63497 :   return shifti(a,-1);
    1703             : }
    1704             : 
    1705             : /* assume 0 <= u < p and ps2 = p>>1 */
    1706             : INLINE GEN
    1707    40092003 : Fp_center(GEN u, GEN p, GEN ps2)
    1708    40092003 : { return abscmpii(u,ps2)<=0? icopy(u): subii(u,p); }
    1709             : /* same without copy */
    1710             : INLINE GEN
    1711     5400749 : Fp_center_i(GEN u, GEN p, GEN ps2)
    1712     5400749 : { return abscmpii(u,ps2)<=0? u: subii(u,p); }
    1713             : 
    1714             : /* x + y*z mod p */
    1715             : INLINE GEN
    1716     5195179 : Fp_addmul(GEN x, GEN y, GEN z, GEN p)
    1717             : {
    1718             :   pari_sp av;
    1719     5195179 :   if (!signe(y) || !signe(z)) return Fp_red(x, p);
    1720     4917306 :   if (!signe(x)) return Fp_mul(z,y, p);
    1721     4601335 :   av = avma;
    1722     4601335 :   return gerepileuptoint(av, modii(addii(x, mulii(y,z)), p));
    1723             : }
    1724             : 
    1725             : INLINE GEN
    1726    94613689 : Fp_mul(GEN a, GEN b, GEN m)
    1727             : {
    1728    94613689 :   pari_sp av=avma;
    1729             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1730    94613689 :   (void)new_chunk(lg(a)+lg(b)+(lg(m)<<1));
    1731    94599676 :   p = mulii(a,b);
    1732    94754868 :   set_avma(av); return modii(p,m);
    1733             : }
    1734             : INLINE GEN
    1735    33502415 : Fp_sqr(GEN a, GEN m)
    1736             : {
    1737    33502415 :   pari_sp av=avma;
    1738             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1739    33502415 :   (void)new_chunk((lg(a)+lg(m))<<1);
    1740    33275128 :   p = sqri(a);
    1741    31171889 :   set_avma(av); return remii(p,m); /*Use remii: p >= 0 */
    1742             : }
    1743             : INLINE GEN
    1744    66834664 : Fp_mulu(GEN a, ulong b, GEN m)
    1745             : {
    1746    66834664 :   long l = lgefint(m);
    1747    66834664 :   if (l == 3)
    1748             :   {
    1749    45125102 :     ulong mm = m[2];
    1750    45125102 :     return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1751             :   } else {
    1752    21709562 :     pari_sp av = avma;
    1753             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1754    21709562 :     (void)new_chunk(lg(a)+1+(l<<1));
    1755    21621778 :     p = muliu(a,b);
    1756    19880868 :     set_avma(av); return modii(p,m);
    1757             :   }
    1758             : }
    1759             : INLINE GEN
    1760       17290 : Fp_muls(GEN a, long b, GEN m)
    1761             : {
    1762       17290 :   long l = lgefint(m);
    1763       17290 :   if (l == 3)
    1764             :   {
    1765        3058 :     ulong mm = m[2];
    1766        3058 :     if (b < 0)
    1767             :     {
    1768        3058 :       ulong t = Fl_mul(umodiu(a, mm), -b, mm);
    1769        3058 :       return t? utoipos(mm - t): gen_0;
    1770             :     }
    1771             :     else
    1772           0 :       return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1773             :   } else {
    1774       14232 :     pari_sp av = avma;
    1775             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1776       14232 :     (void)new_chunk(lg(a)+1+(l<<1));
    1777       14232 :     p = mulis(a,b);
    1778       14232 :     set_avma(av); return modii(p,m);
    1779             :   }
    1780             : }
    1781             : 
    1782             : INLINE GEN
    1783    12936210 : Fp_inv(GEN a, GEN m)
    1784             : {
    1785             :   GEN res;
    1786    12936210 :   if (! invmod(a,m,&res)) pari_err_INV("Fp_inv", mkintmod(res,m));
    1787    12935788 :   return res;
    1788             : }
    1789             : INLINE GEN
    1790      344864 : Fp_invsafe(GEN a, GEN m)
    1791             : {
    1792             :   GEN res;
    1793      344864 :   if (! invmod(a,m,&res)) return NULL;
    1794      344864 :   return res;
    1795             : }
    1796             : INLINE GEN
    1797     1499087 : Fp_div(GEN a, GEN b, GEN m)
    1798             : {
    1799     1499087 :   pari_sp av = avma;
    1800             :   GEN p;
    1801     1499087 :   if (lgefint(b) == 3)
    1802             :   {
    1803      526100 :     a = Fp_divu(a, b[2], m);
    1804      526100 :     if (signe(b) < 0) a = Fp_neg(a, m);
    1805      526100 :     return a;
    1806             :   }
    1807             :   /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1808      972987 :   (void)new_chunk(lg(a)+(lg(m)<<1));
    1809      972987 :   p = mulii(a, Fp_inv(b,m));
    1810      972987 :   set_avma(av); return modii(p,m);
    1811             : }
    1812             : INLINE GEN
    1813     1689101 : Fp_divu(GEN x, ulong a, GEN p)
    1814             : {
    1815     1689101 :   pari_sp av = avma;
    1816             :   ulong b;
    1817     1689101 :   if (lgefint(p) == 3)
    1818             :   {
    1819     1393297 :     ulong pp = p[2], xp = umodiu(x, pp);
    1820     1393297 :     return xp? utoipos(Fl_div(xp, a % pp, pp)): gen_0;
    1821             :   }
    1822      295804 :   x = Fp_red(x, p);
    1823      295803 :   b = Fl_neg(Fl_div(umodiu(x,a), umodiu(p,a), a), a); /* x + pb = 0 (mod a) */
    1824      295808 :   return gerepileuptoint(av, diviuexact(addmuliu(x, p, b), a));
    1825             : }
    1826             : 
    1827             : INLINE GEN
    1828     1103846 : Flx_mulu(GEN x, ulong a, ulong p) { return Flx_Fl_mul(x,a%p,p); }
    1829             : 
    1830             : INLINE GEN
    1831     1748063 : get_F2x_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1832             : 
    1833             : INLINE long
    1834     2254782 : get_F2x_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1835             : 
    1836             : INLINE long
    1837     1899491 : get_F2x_degree(GEN T) { return typ(T)==t_VEC? F2x_degree(gel(T,2)): F2x_degree(T); }
    1838             : 
    1839             : INLINE GEN
    1840         399 : get_F2xqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1841             : 
    1842             : INLINE long
    1843      376152 : get_F2xqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1844             : 
    1845             : INLINE long
    1846      201446 : get_F2xqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1847             : 
    1848             : INLINE GEN
    1849     9160337 : get_Flx_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1850             : 
    1851             : INLINE long
    1852    24551464 : get_Flx_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1853             : 
    1854             : INLINE long
    1855    43160242 : get_Flx_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1856             : 
    1857             : INLINE GEN
    1858        6850 : get_FlxqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1859             : 
    1860             : INLINE long
    1861      240670 : get_FlxqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1862             : 
    1863             : INLINE long
    1864      296462 : get_FlxqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1865             : 
    1866             : INLINE GEN
    1867     1634544 : get_FpX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1868             : 
    1869             : INLINE long
    1870     4189309 : get_FpX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1871             : 
    1872             : INLINE long
    1873     3255627 : get_FpX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1874             : 
    1875             : INLINE GEN
    1876      146604 : get_FpXQX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1877             : 
    1878             : INLINE long
    1879       34892 : get_FpXQX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1880             : 
    1881             : INLINE long
    1882        2259 : get_FpXQX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1883             : 
    1884             : /*******************************************************************/
    1885             : /*                                                                 */
    1886             : /*                        ADDMULII / SUBMULII                      */
    1887             : /*                                                                 */
    1888             : /*******************************************************************/
    1889             : /* x - y*z */
    1890             : INLINE GEN
    1891     1019379 : submulii(GEN x, GEN y, GEN z)
    1892             : {
    1893     1019379 :   long lx = lgefint(x), ly, lz;
    1894             :   pari_sp av;
    1895             :   GEN t;
    1896     1019379 :   if (lx == 2) { t = mulii(z,y); togglesign(t); return t; }
    1897      862797 :   ly = lgefint(y);
    1898      862797 :   if (ly == 2) return icopy(x);
    1899      706264 :   lz = lgefint(z);
    1900      706264 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1901      706264 :   t = mulii(z, y);
    1902      706264 :   set_avma(av); return subii(x,t);
    1903             : }
    1904             : /* y*z - x */
    1905             : INLINE GEN
    1906     1334761 : mulsubii(GEN y, GEN z, GEN x)
    1907             : {
    1908     1334761 :   long lx = lgefint(x), ly, lz;
    1909             :   pari_sp av;
    1910             :   GEN t;
    1911     1334761 :   if (lx == 2) return mulii(z,y);
    1912      805409 :   ly = lgefint(y);
    1913      805409 :   if (ly == 2) return negi(x);
    1914      736814 :   lz = lgefint(z);
    1915      736814 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1916      736814 :   t = mulii(z, y);
    1917      736814 :   set_avma(av); return subii(t,x);
    1918             : }
    1919             : 
    1920             : /* x - u*y */
    1921             : INLINE GEN
    1922        7595 : submuliu(GEN x, GEN y, ulong u)
    1923             : {
    1924             :   pari_sp av;
    1925        7595 :   long ly = lgefint(y);
    1926        7595 :   if (ly == 2) return icopy(x);
    1927        7595 :   av = avma;
    1928        7595 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1929        7595 :   y = mului(u,y);
    1930        7595 :   set_avma(av); return subii(x, y);
    1931             : }
    1932             : /* x + u*y */
    1933             : INLINE GEN
    1934      303764 : addmuliu(GEN x, GEN y, ulong u)
    1935             : {
    1936             :   pari_sp av;
    1937      303764 :   long ly = lgefint(y);
    1938      303764 :   if (ly == 2) return icopy(x);
    1939      303764 :   av = avma;
    1940      303764 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1941      303764 :   y = mului(u,y);
    1942      303760 :   set_avma(av); return addii(x, y);
    1943             : }
    1944             : /* x - u*y */
    1945             : INLINE GEN
    1946   204307570 : submuliu_inplace(GEN x, GEN y, ulong u)
    1947             : {
    1948             :   pari_sp av;
    1949   204307570 :   long ly = lgefint(y);
    1950   204307570 :   if (ly == 2) return x;
    1951   166322613 :   av = avma;
    1952   166322613 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1953   166322623 :   y = mului(u,y);
    1954   166322577 :   set_avma(av); return subii(x, y);
    1955             : }
    1956             : /* x + u*y */
    1957             : INLINE GEN
    1958   201298073 : addmuliu_inplace(GEN x, GEN y, ulong u)
    1959             : {
    1960             :   pari_sp av;
    1961   201298073 :   long ly = lgefint(y);
    1962   201298073 :   if (ly == 2) return x;
    1963   165088681 :   av = avma;
    1964   165088681 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1965   165088687 :   y = mului(u,y);
    1966   165088625 :   set_avma(av); return addii(x, y);
    1967             : }
    1968             : /* ux + vy */
    1969             : INLINE GEN
    1970    24940041 : lincombii(GEN u, GEN v, GEN x, GEN y)
    1971             : {
    1972    24940041 :   long lx = lgefint(x), ly;
    1973             :   GEN p1, p2;
    1974             :   pari_sp av;
    1975    24940041 :   if (lx == 2) return mulii(v,y);
    1976    16623038 :   ly = lgefint(y);
    1977    16623038 :   if (ly == 2) return mulii(u,x);
    1978    15305358 :   av = avma; (void)new_chunk(lx+ly+lgefint(u)+lgefint(v)); /* HACK */
    1979    15306063 :   p1 = mulii(u,x);
    1980    15305948 :   p2 = mulii(v,y);
    1981    15305954 :   set_avma(av); return addii(p1,p2);
    1982             : }
    1983             : 
    1984             : /*******************************************************************/
    1985             : /*                                                                 */
    1986             : /*                          GEN SUBTYPES                           */
    1987             : /*                                                                 */
    1988             : /*******************************************************************/
    1989             : 
    1990             : INLINE int
    1991  1844002152 : is_const_t(long t) { return (t < t_POLMOD); }
    1992             : INLINE int
    1993        6811 : is_extscalar_t(long t) { return (t <= t_POL); }
    1994             : INLINE int
    1995     1506795 : is_intreal_t(long t) { return (t <= t_REAL); }
    1996             : INLINE int
    1997   431599484 : is_matvec_t(long t) { return (t >= t_VEC && t <= t_MAT); }
    1998             : INLINE int
    1999    73040773 : is_noncalc_t(long tx) { return (tx) >= t_LIST; }
    2000             : INLINE int
    2001     1606480 : is_rational_t(long t) { return (t == t_INT || t == t_FRAC); }
    2002             : INLINE int
    2003     2817880 : is_qfb_t(long t) { return (t == t_QFI || t == t_QFR); }
    2004             : INLINE int
    2005     1105949 : is_real_t(long t) { return (t == t_INT || t == t_REAL || t == t_FRAC); }
    2006             : INLINE int
    2007  4191359436 : is_recursive_t(long t) { return lontyp[t]; }
    2008             : INLINE int
    2009   179590824 : is_scalar_t(long t) { return (t < t_POL); }
    2010             : INLINE int
    2011     1054332 : is_vec_t(long t) { return (t == t_VEC || t == t_COL); }
    2012             : 
    2013             : /*******************************************************************/
    2014             : /*                                                                 */
    2015             : /*                         TRANSCENDENTAL                          */
    2016             : /*                                                                 */
    2017             : /*******************************************************************/
    2018             : INLINE GEN
    2019    24988138 : sqrtr(GEN x) {
    2020    24988138 :   long s = signe(x);
    2021    24988138 :   if (s == 0) return real_0_bit(expo(x) >> 1);
    2022    24954902 :   if (s >= 0) return sqrtr_abs(x);
    2023       43790 :   retmkcomplex(gen_0, sqrtr_abs(x));
    2024             : }
    2025             : INLINE GEN
    2026           0 : cbrtr_abs(GEN x) { return sqrtnr_abs(x, 3); }
    2027             : INLINE GEN
    2028           0 : cbrtr(GEN x) {
    2029           0 :   long s = signe(x);
    2030             :   GEN r;
    2031           0 :   if (s == 0) return real_0_bit(expo(x) / 3);
    2032           0 :   r = cbrtr_abs(x);
    2033           0 :   if (s < 0) togglesign(r);
    2034           0 :   return r;
    2035             : }
    2036             : INLINE GEN
    2037      767904 : sqrtnr(GEN x, long n) {
    2038      767904 :   long s = signe(x);
    2039             :   GEN r;
    2040      767904 :   if (s == 0) return real_0_bit(expo(x) / n);
    2041      767904 :   r = sqrtnr_abs(x, n);
    2042      767905 :   if (s < 0) pari_err_IMPL("sqrtnr for x < 0");
    2043      767905 :   return r;
    2044             : }
    2045             : INLINE long
    2046      266340 : logint(GEN B, GEN y) { return logintall(B,y,NULL); }
    2047             : INLINE ulong
    2048     2019378 : ulogint(ulong B, ulong y)
    2049             : {
    2050             :   ulong r;
    2051             :   long e;
    2052     2019378 :   if (y == 2) return expu(B);
    2053     2000352 :   r = y;
    2054     2000352 :   for (e=1;; e++)
    2055             :   { /* here, r = y^e, r2 = y^(e-1) */
    2056     6438708 :     if (r >= B) return r == B? e: e-1;
    2057     4438346 :     r = umuluu_or_0(y, r);
    2058     4438349 :     if (!r) return e;
    2059             :   }
    2060             : }
    2061             : 
    2062             : /*******************************************************************/
    2063             : /*                                                                 */
    2064             : /*                         MISCELLANEOUS                           */
    2065             : /*                                                                 */
    2066             : /*******************************************************************/
    2067     1506718 : INLINE int ismpzero(GEN x) { return is_intreal_t(typ(x)) && !signe(x); }
    2068   877255911 : INLINE int isintzero(GEN x) { return typ(x) == t_INT && !signe(x); }
    2069    11182582 : INLINE int isint1(GEN x) { return typ(x)==t_INT && equali1(x); }
    2070     2004421 : INLINE int isintm1(GEN x){ return typ(x)==t_INT && equalim1(x);}
    2071   751158271 : INLINE int equali1(GEN n)
    2072   751158271 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(1)) && n[2] == 1; }
    2073    61493475 : INLINE int equalim1(GEN n)
    2074    61493475 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(-1)) && n[2] == 1; }
    2075             : /* works only for POSITIVE integers */
    2076  1381571463 : INLINE int is_pm1(GEN n)
    2077  1381571463 : { return lgefint(n) == 3 && n[2] == 1; }
    2078   284913533 : INLINE int is_bigint(GEN n)
    2079   284913533 : { long l = lgefint(n); return l > 3 || (l == 3 && (n[2] & HIGHBIT)); }
    2080             : 
    2081  2120964797 : INLINE int odd(long x) { return x & 1; }
    2082    30194194 : INLINE int both_odd(long x, long y) { return x & y & 1; }
    2083             : 
    2084             : INLINE int
    2085  3802738454 : isonstack(GEN x)
    2086  3802738454 : { return ((pari_sp)x >= pari_mainstack->bot
    2087  3802738454 :        && (pari_sp)x <  pari_mainstack->top); }
    2088             : 
    2089             : /* assume x != 0 and x t_REAL, return an approximation to log2(|x|) */
    2090             : INLINE double
    2091    27301954 : dbllog2r(GEN x)
    2092    27301954 : { return log2((double)(ulong)x[2]) + (double)(expo(x) - (BITS_IN_LONG-1)); }
    2093             : 
    2094             : INLINE GEN
    2095      433441 : mul_content(GEN cx, GEN cy)
    2096             : {
    2097      433441 :   if (!cx) return cy;
    2098      158582 :   if (!cy) return cx;
    2099      104346 :   return gmul(cx,cy);
    2100             : }
    2101             : INLINE GEN
    2102        6139 : inv_content(GEN c) { return c? ginv(c): NULL; }
    2103             : INLINE GEN
    2104        7777 : div_content(GEN cx, GEN cy)
    2105             : {
    2106        7777 :   if (!cy) return cx;
    2107        7574 :   if (!cx) return ginv(cy);
    2108        3772 :   return gdiv(cx,cy);
    2109             : }
    2110             : INLINE GEN
    2111     2942620 : mul_denom(GEN dx, GEN dy)
    2112             : {
    2113     2942620 :   if (!dx) return dy;
    2114     1311520 :   if (!dy) return dx;
    2115      458377 :   return mulii(dx,dy);
    2116             : }
    2117             : 
    2118             : /* POLYNOMIALS */
    2119             : INLINE GEN
    2120      839021 : constant_coeff(GEN x) { return signe(x)? gel(x,2): gen_0; }
    2121             : INLINE GEN
    2122    52149392 : leading_coeff(GEN x) { return lg(x) == 2? gen_0: gel(x,lg(x)-1); }
    2123             : INLINE ulong
    2124      505537 : Flx_lead(GEN x) { return lg(x) == 2? 0: x[lg(x)-1]; }
    2125             : INLINE ulong
    2126       15166 : Flx_constant(GEN x) { return lg(x) == 2? 0: x[2]; }
    2127             : INLINE long
    2128  2881756098 : degpol(GEN x) { return lg(x)-3; }
    2129             : INLINE long
    2130  1551010326 : lgpol(GEN x) { return lg(x)-2; }
    2131             : INLINE long
    2132   150706671 : lgcols(GEN x) { return lg(gel(x,1)); }
    2133             : INLINE long
    2134    80969879 : nbrows(GEN x) { return lg(gel(x,1))-1; }
    2135             : INLINE GEN
    2136           0 : truecoef(GEN x, long n) { return polcoef(x,n,-1); }
    2137             : 
    2138             : INLINE GEN
    2139      672459 : ZXQ_mul(GEN y, GEN x, GEN T) { return ZX_rem(ZX_mul(y, x), T); }
    2140             : INLINE GEN
    2141      277557 : ZXQ_sqr(GEN x, GEN T) { return ZX_rem(ZX_sqr(x), T); }
    2142             : 
    2143             : INLINE GEN
    2144    92383395 : RgX_copy(GEN x)
    2145             : {
    2146             :   long lx, i;
    2147    92383395 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
    2148   334885685 :   for (i = 2; i<lx; i++) gel(y,i) = gcopy(gel(x,i));
    2149    92383402 :   return y;
    2150             : }
    2151             : /* have to use ulong to avoid silly warnings from gcc "assuming signed
    2152             :  * overflow does not occur" */
    2153             : INLINE GEN
    2154     1083635 : RgX_coeff(GEN x, long n)
    2155             : {
    2156     1083635 :   ulong l = lg(x);
    2157     1083635 :   return (n < 0 || ((ulong)n+3) > l)? gen_0: gel(x,n+2);
    2158             : }
    2159             : INLINE GEN
    2160      369316 : RgX_renormalize(GEN x) { return RgX_renormalize_lg(x, lg(x)); }
    2161             : INLINE GEN
    2162     6813000 : RgX_div(GEN x, GEN y) { return RgX_divrem(x,y,NULL); }
    2163             : INLINE GEN
    2164        1792 : RgXQX_div(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,NULL); }
    2165             : INLINE GEN
    2166      102927 : RgXQX_rem(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,ONLY_REM); }
    2167             : INLINE GEN
    2168     1150520 : FpX_div(GEN x, GEN y, GEN p) { return FpX_divrem(x,y,p, NULL); }
    2169             : INLINE GEN
    2170     6438177 : Flx_div(GEN x, GEN y, ulong p) { return Flx_divrem(x,y,p, NULL); }
    2171             : INLINE GEN
    2172      862784 : F2x_div(GEN x, GEN y) { return F2x_divrem(x,y, NULL); }
    2173             : INLINE GEN
    2174           0 : FpV_FpC_mul(GEN x, GEN y, GEN p) { return FpV_dotproduct(x,y,p); }
    2175             : INLINE GEN
    2176    56421103 : pol0_Flx(long sv) { return mkvecsmall(sv); }
    2177             : INLINE GEN
    2178    18557486 : pol1_Flx(long sv) { return mkvecsmall2(sv, 1); }
    2179             : INLINE GEN
    2180    19317635 : polx_Flx(long sv) { return mkvecsmall3(sv, 0, 1); }
    2181             : INLINE GEN
    2182           0 : zero_zx(long sv) { return zero_Flx(sv); }
    2183             : INLINE GEN
    2184           0 : polx_zx(long sv) { return polx_Flx(sv); }
    2185             : INLINE GEN
    2186           0 : zx_shift(GEN x, long n) { return Flx_shift(x,n); }
    2187             : INLINE GEN
    2188           0 : zx_renormalize(GEN x, long l) { return Flx_renormalize(x,l); }
    2189             : INLINE GEN
    2190        1341 : zero_F2x(long sv) { return zero_Flx(sv); }
    2191             : INLINE GEN
    2192    11076941 : pol0_F2x(long sv) { return pol0_Flx(sv); }
    2193             : INLINE GEN
    2194     2801821 : pol1_F2x(long sv) { return pol1_Flx(sv); }
    2195             : INLINE GEN
    2196      705540 : polx_F2x(long sv) { return mkvecsmall2(sv, 2); }
    2197             : INLINE int
    2198      518228 : F2x_equal1(GEN x) { return Flx_equal1(x); }
    2199             : INLINE int
    2200     3053901 : F2x_equal(GEN V, GEN W) { return Flx_equal(V,W); }
    2201             : INLINE GEN
    2202    54786040 : F2x_copy(GEN x) { return leafcopy(x); }
    2203             : INLINE GEN
    2204        3535 : F2v_copy(GEN x) { return leafcopy(x); }
    2205             : INLINE GEN
    2206     2276981 : Flv_copy(GEN x) { return leafcopy(x); }
    2207             : INLINE GEN
    2208   108267758 : Flx_copy(GEN x) { return leafcopy(x); }
    2209             : INLINE GEN
    2210     1982332 : vecsmall_copy(GEN x) { return leafcopy(x); }
    2211             : INLINE int
    2212     4647563 : Flx_equal1(GEN x) { return degpol(x)==0 && x[2] == 1; }
    2213             : INLINE int
    2214       18632 : ZX_equal1(GEN x) { return degpol(x)==0 && equali1(gel(x,2)); }
    2215             : INLINE int
    2216     6380454 : ZX_is_monic(GEN x) { return equali1(leading_coeff(x)); }
    2217             : 
    2218             : INLINE GEN
    2219    65165692 : ZX_renormalize(GEN x, long lx)    { return ZXX_renormalize(x,lx); }
    2220             : INLINE GEN
    2221    74075754 : FpX_renormalize(GEN x, long lx)   { return ZXX_renormalize(x,lx); }
    2222             : INLINE GEN
    2223      675481 : FpXX_renormalize(GEN x, long lx)  { return ZXX_renormalize(x,lx); }
    2224             : INLINE GEN
    2225     1478580 : FpXQX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
    2226             : INLINE GEN
    2227   108539160 : F2x_renormalize(GEN x, long lx)   { return Flx_renormalize(x,lx); }
    2228             : INLINE GEN
    2229       32924 : F2v_to_F2x(GEN x, long sv) {
    2230       32924 :   GEN y = leafcopy(x);
    2231       32923 :   y[1] = sv; F2x_renormalize(y, lg(y)); return y;
    2232             : }
    2233             : 
    2234             : INLINE long
    2235         322 : sturm(GEN x) { return sturmpart(x, NULL, NULL); }
    2236             : 
    2237             : INLINE long
    2238        4844 : gval(GEN x, long v)
    2239        4844 : { pari_sp av = avma; return gc_long(av, gvaluation(x, pol_x(v))); }
    2240             : 
    2241             : INLINE void
    2242      472989 : RgX_shift_inplace_init(long v)
    2243      472989 : { if (v) (void)cgetg(v, t_VECSMALL); }
    2244             : /* shift polynomial in place. assume v free cells have been left before x */
    2245             : INLINE GEN
    2246      472989 : RgX_shift_inplace(GEN x, long v)
    2247             : {
    2248             :   long i, lx;
    2249             :   GEN z;
    2250      472989 :   if (!v) return x;
    2251      253165 :   lx = lg(x);
    2252      253165 :   if (lx == 2) return x;
    2253      253165 :   z = x + lx;
    2254             :   /* stackdummy's from normalizepol */
    2255      253165 :   while (lg(z) != v) z += lg(z);
    2256      253165 :   z += v;
    2257     4654452 :   for (i = lx-1; i >= 2; i--) gel(--z,0) = gel(x,i);
    2258      675883 :   for (i = 0;  i < v; i++) gel(--z,0) = gen_0;
    2259      253165 :   z -= 2;
    2260      253165 :   z[1] = x[1];
    2261      253165 :   z[0] = evaltyp(t_POL) | evallg(lx+v);
    2262      253165 :   stackdummy((pari_sp)z, (pari_sp)x); return z;
    2263             : }
    2264             : 
    2265             : 
    2266             : /* LINEAR ALGEBRA */
    2267             : INLINE GEN
    2268      138579 : zv_to_ZV(GEN x) { return vecsmall_to_vec(x); }
    2269             : INLINE GEN
    2270     5350986 : zc_to_ZC(GEN x) { return vecsmall_to_col(x); }
    2271             : INLINE GEN
    2272     3305405 : ZV_to_zv(GEN x) { return vec_to_vecsmall(x); }
    2273             : INLINE GEN
    2274           0 : zx_to_zv(GEN x, long N) { return Flx_to_Flv(x,N); }
    2275             : INLINE GEN
    2276           0 : zv_to_zx(GEN x, long sv) { return Flv_to_Flx(x,sv); }
    2277             : INLINE GEN
    2278           0 : zm_to_zxV(GEN x, long sv) { return Flm_to_FlxV(x,sv); }
    2279             : INLINE GEN
    2280           0 : zero_zm(long x, long y) { return zero_Flm(x,y); }
    2281             : INLINE GEN
    2282    17806124 : zero_zv(long x) { return zero_Flv(x); }
    2283             : INLINE GEN
    2284         238 : zm_transpose(GEN x) { return Flm_transpose(x); }
    2285             : INLINE GEN
    2286           0 : zm_copy(GEN x) { return Flm_copy(x); }
    2287             : INLINE GEN
    2288     1902765 : zv_copy(GEN x) { return Flv_copy(x); }
    2289             : INLINE GEN
    2290           0 : zm_row(GEN x, long i) { return Flm_row(x,i); }
    2291             : 
    2292             : INLINE GEN
    2293     1735459 : ZC_hnfrem(GEN x, GEN y) { return ZC_hnfremdiv(x,y,NULL); }
    2294             : INLINE GEN
    2295       42166 : ZM_hnfrem(GEN x, GEN y) { return ZM_hnfdivrem(x,y,NULL); }
    2296             : INLINE GEN
    2297     2775365 : ZM_lll(GEN x, double D, long f) { return ZM_lll_norms(x,D,f,NULL); }
    2298             : INLINE void
    2299     6081796 : RgM_dimensions(GEN x, long *m, long *n) { *n = lg(x)-1; *m = *n? nbrows(x): 0; }
    2300             : INLINE GEN
    2301    11015473 : RgM_shallowcopy(GEN x)
    2302             : {
    2303             :   long l;
    2304    11015473 :   GEN y = cgetg_copy(x, &l);
    2305    55616071 :   while (--l > 0) gel(y,l) = leafcopy(gel(x,l));
    2306    11015469 :   return y;
    2307             : }
    2308             : INLINE GEN
    2309       22493 : F2m_copy(GEN x) { return RgM_shallowcopy(x); }
    2310             : 
    2311             : INLINE GEN
    2312     1761872 : Flm_copy(GEN x) { return RgM_shallowcopy(x); }
    2313             : 
    2314             : /* divisibility: return 1 if y[i] | x[i] for all i, 0 otherwise. Assume
    2315             :  * x,y are ZV of the same length */
    2316             : INLINE int
    2317       23198 : ZV_dvd(GEN x, GEN y)
    2318             : {
    2319       23198 :   long i, l = lg(x);
    2320       36666 :   for (i=1; i < l; i++)
    2321       29533 :     if ( ! dvdii( gel(x,i), gel(y,i) ) ) return 0;
    2322        7133 :   return 1;
    2323             : }
    2324             : 
    2325             : /* Fq */
    2326             : INLINE GEN
    2327     2501671 : Fq_red(GEN x, GEN T, GEN p)
    2328     2501671 : { return typ(x)==t_INT? Fp_red(x,p): FpXQ_red(x,T,p); }
    2329             : INLINE GEN
    2330       99889 : Fq_to_FpXQ(GEN x, GEN T, GEN p /*unused*/)
    2331             : {
    2332             :   (void) p;
    2333       99889 :   return typ(x)==t_INT ? scalarpol(x, get_FpX_var(T)): x;
    2334             : }
    2335             : INLINE GEN
    2336         756 : Rg_to_Fq(GEN x, GEN T, GEN p) { return T? Rg_to_FpXQ(x,T,p): Rg_to_Fp(x,p); }
    2337             : 
    2338             : INLINE GEN
    2339         805 : gener_Fq_local(GEN T, GEN p, GEN L)
    2340           0 : { return T? gener_FpXQ_local(T,p, L)
    2341         805 :           : pgener_Fp_local(p, L); }
    2342             : 
    2343             : /* FpXQX */
    2344             : INLINE GEN
    2345        4424 : FpXQX_div(GEN x, GEN y, GEN T, GEN p) { return FpXQX_divrem(x, y, T, p, NULL); }
    2346             : INLINE GEN
    2347       44582 : FlxqX_div(GEN x, GEN y, GEN T, ulong p) { return FlxqX_divrem(x, y, T, p, NULL); }
    2348             : INLINE GEN
    2349       33334 : F2xqX_div(GEN x, GEN y, GEN T) { return F2xqX_divrem(x, y, T, NULL); }
    2350             : 
    2351             : INLINE GEN
    2352       20006 : FpXY_Fq_evaly(GEN Q, GEN y, GEN T, GEN p, long vx)
    2353       20006 : { return T ? FpXY_FpXQ_evaly(Q, y, T, p, vx): FpXY_evaly(Q, y, p, vx); }
    2354             : 
    2355             : /* FqX */
    2356             : INLINE GEN
    2357       25067 : FqX_red(GEN z, GEN T, GEN p) { return T? FpXQX_red(z, T, p): FpX_red(z, p); }
    2358             : INLINE GEN
    2359      105343 : FqX_add(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2360             : INLINE GEN
    2361       24313 : FqX_neg(GEN x,GEN T,GEN p) { return T? FpXX_neg(x,p): FpX_neg(x,p); }
    2362             : INLINE GEN
    2363       66458 : FqX_sub(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2364             : INLINE GEN
    2365      212098 : FqX_Fp_mul(GEN P, GEN u, GEN T, GEN p)
    2366      212098 : { return T? FpXX_Fp_mul(P, u, p): FpX_Fp_mul(P, u, p); }
    2367             : INLINE GEN
    2368      100019 : FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p)
    2369      100019 : { return typ(U)==t_INT ? FqX_Fp_mul(P, U, T, p): FpXQX_FpXQ_mul(P, U, T, p); }
    2370             : INLINE GEN
    2371      168421 : FqX_mul(GEN x, GEN y, GEN T, GEN p)
    2372      168421 : { return T? FpXQX_mul(x, y, T, p): FpX_mul(x, y, p); }
    2373             : INLINE GEN
    2374       17594 : FqX_mulu(GEN x, ulong y, GEN T, GEN p)
    2375       17594 : { return T? FpXX_mulu(x, y, p): FpX_mulu(x, y, p); }
    2376             : INLINE GEN
    2377       69678 : FqX_sqr(GEN x, GEN T, GEN p)
    2378       69678 : { return T? FpXQX_sqr(x, T, p): FpX_sqr(x, p); }
    2379             : INLINE GEN
    2380        1281 : FqX_powu(GEN x, ulong n, GEN T, GEN p)
    2381        1281 : { return T? FpXQX_powu(x, n, T, p): FpX_powu(x, n, p); }
    2382             : INLINE GEN
    2383       18774 : FqX_halve(GEN x, GEN T, GEN p)
    2384       18774 : { return T? FpXX_halve(x, p): FpX_halve(x, p); }
    2385             : INLINE GEN
    2386        6328 : FqX_div(GEN x, GEN y, GEN T, GEN p)
    2387        6328 : { return T? FpXQX_divrem(x,y,T,p,NULL): FpX_divrem(x,y,p,NULL); }
    2388             : INLINE GEN
    2389        6081 : FqX_get_red(GEN S, GEN T, GEN p)
    2390        6081 : { return T? FpXQX_get_red(S,T,p): FpX_get_red(S,p); }
    2391             : INLINE GEN
    2392       31086 : FqX_rem(GEN x, GEN y, GEN T, GEN p)
    2393       31086 : { return T? FpXQX_rem(x,y,T,p): FpX_rem(x,y,p); }
    2394             : INLINE GEN
    2395           0 : FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2396           0 : { return T? FpXQX_divrem(x,y,T,p,z): FpX_divrem(x,y,p,z); }
    2397             : INLINE GEN
    2398        5936 : FqX_div_by_X_x(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2399        5936 : { return T? FpXQX_div_by_X_x(x,y,T,p,z): FpX_div_by_X_x(x,y,p,z); }
    2400             : INLINE GEN
    2401           0 : FqX_halfgcd(GEN P,GEN Q,GEN T,GEN p)
    2402           0 : {return T? FpXQX_halfgcd(P,Q,T,p): FpX_halfgcd(P,Q,p);}
    2403             : INLINE GEN
    2404      260113 : FqX_gcd(GEN P,GEN Q,GEN T,GEN p)
    2405      260113 : {return T? FpXQX_gcd(P,Q,T,p): FpX_gcd(P,Q,p);}
    2406             : INLINE GEN
    2407      111276 : FqX_extgcd(GEN P,GEN Q,GEN T,GEN p, GEN *U, GEN *V)
    2408      111276 : { return T? FpXQX_extgcd(P,Q,T,p,U,V): FpX_extgcd(P,Q,p,U,V); }
    2409             : INLINE GEN
    2410        3570 : FqX_normalize(GEN z, GEN T, GEN p)
    2411        3570 : { return T? FpXQX_normalize(z, T, p): FpX_normalize(z, p); }
    2412             : INLINE GEN
    2413      291893 : FqX_deriv(GEN f, GEN T, GEN p) { return T? FpXX_deriv(f, p): FpX_deriv(f, p); }
    2414             : INLINE GEN
    2415           0 : FqX_integ(GEN f, GEN T, GEN p) { return T? FpXX_integ(f, p): FpX_integ(f, p); }
    2416             : INLINE GEN
    2417       76279 : FqX_factor(GEN f, GEN T, GEN p)
    2418       76279 : { return T?FpXQX_factor(f, T, p): FpX_factor(f, p); }
    2419             : INLINE GEN
    2420           7 : FqX_factor_squarefree(GEN f, GEN T, GEN p)
    2421           7 : { return T ? FpXQX_factor_squarefree(f, T, p): FpX_factor_squarefree(f, p); }
    2422             : INLINE GEN
    2423           7 : FqX_ddf(GEN f, GEN T, GEN p)
    2424           7 : { return T ? FpXQX_ddf(f, T, p): FpX_ddf(f, p); }
    2425             : INLINE GEN
    2426        1862 : FqX_degfact(GEN f, GEN T, GEN p)
    2427        1862 : { return T?FpXQX_degfact(f, T, p): FpX_degfact(f, p); }
    2428             : INLINE GEN
    2429        7147 : FqX_roots(GEN f, GEN T, GEN p)
    2430        7147 : { return T?FpXQX_roots(f, T, p): FpX_roots(f, p); }
    2431             : INLINE GEN
    2432         175 : FqX_to_mod(GEN f, GEN T, GEN p)
    2433         175 : { return T?FpXQX_to_mod(f, T, p): FpX_to_mod(f, p); }
    2434             : 
    2435             : /*FqXQ*/
    2436             : INLINE GEN
    2437           0 : FqXQ_add(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2438           0 : { (void)S; return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2439             : INLINE GEN
    2440           0 : FqXQ_sub(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2441           0 : { (void)S; return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2442             : INLINE GEN
    2443           0 : FqXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p)
    2444           0 : { return T? FpXQXQ_div(x,y,S,T,p): FpXQ_div(x,y,S,p); }
    2445             : INLINE GEN
    2446           0 : FqXQ_inv(GEN x, GEN S, GEN T, GEN p)
    2447           0 : { return T? FpXQXQ_inv(x,S,T,p): FpXQ_inv(x,S,p); }
    2448             : INLINE GEN
    2449           0 : FqXQ_invsafe(GEN x, GEN S, GEN T, GEN p)
    2450           0 : { return T? FpXQXQ_invsafe(x,S,T,p): FpXQ_inv(x,S,p); }
    2451             : INLINE GEN
    2452       22320 : FqXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p)
    2453       22320 : { return T? FpXQXQ_mul(x,y,S,T,p): FpXQ_mul(x,y,S,p); }
    2454             : INLINE GEN
    2455           0 : FqXQ_sqr(GEN x, GEN S, GEN T, GEN p)
    2456           0 : { return T? FpXQXQ_sqr(x,S,T,p): FpXQ_sqr(x,S,p); }
    2457             : INLINE GEN
    2458           0 : FqXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p)
    2459           0 : { return T? FpXQXQ_pow(x,n,S,T,p): FpXQ_pow(x,n,S,p); }
    2460             : 
    2461             : /*FqXn*/
    2462             : INLINE GEN
    2463        6610 : FqXn_expint(GEN x, long n, GEN T, GEN p)
    2464        6610 : { return T? FpXQXn_expint(x,n,T,p): FpXn_expint(x,n,p); }
    2465             : INLINE GEN
    2466           0 : FqXn_exp(GEN x, long n, GEN T, GEN p)
    2467           0 : { return T? FpXQXn_exp(x,n,T,p): FpXn_exp(x,n,p); }
    2468             : INLINE GEN
    2469        6916 : FqXn_inv(GEN x, long n, GEN T, GEN p)
    2470        6916 : { return T? FpXQXn_inv(x,n,T,p): FpXn_inv(x,n,p); }
    2471             : INLINE GEN
    2472      254926 : FqXn_mul(GEN x, GEN y, long n, GEN T, GEN p)
    2473      254926 : { return T? FpXQXn_mul(x, y, n, T, p): FpXn_mul(x, y, n, p); }
    2474             : INLINE GEN
    2475           0 : FqXn_sqr(GEN x, long n, GEN T, GEN p)
    2476           0 : { return T? FpXQXn_sqr(x,n,T,p): FpXn_sqr(x,n,p); }
    2477             : 
    2478             : /*FpXQ*/
    2479             : INLINE GEN
    2480           0 : FpXQ_add(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2481           0 : { (void)T; return FpX_add(x,y,p); }
    2482             : INLINE GEN
    2483           0 : FpXQ_sub(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2484           0 : { (void)T; return FpX_sub(x,y,p); }
    2485             : 
    2486             : /*Flxq*/
    2487             : INLINE GEN
    2488           0 : Flxq_add(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2489           0 : { (void)T; return Flx_add(x,y,p); }
    2490             : INLINE GEN
    2491           0 : Flxq_sub(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2492           0 : { (void)T; return Flx_sub(x,y,p); }
    2493             : 
    2494             : /* F2x */
    2495             : 
    2496             : INLINE ulong
    2497    60874470 : F2x_coeff(GEN x,long v)
    2498             : {
    2499    60874470 :    ulong u=(ulong)x[2+divsBIL(v)];
    2500    60873025 :    return (u>>remsBIL(v))&1UL;
    2501             : }
    2502             : 
    2503             : INLINE void
    2504     5520571 : F2x_clear(GEN x,long v)
    2505             : {
    2506     5520571 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2507     5520566 :    *u&=~(1UL<<remsBIL(v));
    2508     5520561 : }
    2509             : 
    2510             : INLINE void
    2511    33988904 : F2x_set(GEN x,long v)
    2512             : {
    2513    33988904 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2514    33977806 :    *u|=1UL<<remsBIL(v);
    2515    33969768 : }
    2516             : 
    2517             : INLINE void
    2518     1509187 : F2x_flip(GEN x,long v)
    2519             : {
    2520     1509187 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2521     1509187 :    *u^=1UL<<remsBIL(v);
    2522     1509187 : }
    2523             : 
    2524             : /* F2v */
    2525             : 
    2526             : INLINE ulong
    2527    56756313 : F2v_coeff(GEN x,long v) { return F2x_coeff(x,v-1); }
    2528             : 
    2529             : INLINE void
    2530     5520570 : F2v_clear(GEN x,long v) { F2x_clear(x,v-1); }
    2531             : 
    2532             : INLINE void
    2533    10120682 : F2v_set(GEN x,long v)   { F2x_set(x,v-1); }
    2534             : 
    2535             : INLINE void
    2536     1509187 : F2v_flip(GEN x,long v) { F2x_flip(x,v-1); }
    2537             : 
    2538             : /* F2m */
    2539             : 
    2540             : INLINE ulong
    2541     4796558 : F2m_coeff(GEN x, long a, long b) { return F2v_coeff(gel(x,b), a); }
    2542             : 
    2543             : INLINE void
    2544           0 : F2m_clear(GEN x, long a, long b) { F2v_clear(gel(x,b), a); }
    2545             : 
    2546             : INLINE void
    2547           0 : F2m_set(GEN x, long a, long b) { F2v_set(gel(x,b), a); }
    2548             : 
    2549             : INLINE void
    2550     1509186 : F2m_flip(GEN x, long a, long b) { F2v_flip(gel(x,b), a); }
    2551             : 
    2552             : /* ARITHMETIC */
    2553             : INLINE GEN
    2554        2849 : matpascal(long n) { return matqpascal(n, NULL); }
    2555             : INLINE long
    2556     2549971 : Z_issquare(GEN x) { return Z_issquareall(x, NULL); }
    2557             : INLINE long
    2558          14 : Z_ispower(GEN x, ulong k) { return Z_ispowerall(x, k, NULL); }
    2559             : INLINE GEN
    2560     4457579 : sqrti(GEN x) { return sqrtremi(x,NULL); }
    2561             : INLINE GEN
    2562     6004405 : gaddgs(GEN y, long s) { return gaddsg(s,y); }
    2563             : INLINE int
    2564       74199 : gcmpgs(GEN y, long s) { return -gcmpsg(s,y); }
    2565             : INLINE int
    2566       24549 : gequalgs(GEN y, long s) { return gequalsg(s,y); }
    2567             : INLINE GEN
    2568           0 : gmaxsg(long s, GEN y) { return gmaxgs(y,s); }
    2569             : INLINE GEN
    2570           0 : gminsg(long s, GEN y) { return gmings(y,s); }
    2571             : INLINE GEN
    2572    36519842 : gmulgs(GEN y, long s) { return gmulsg(s,y); }
    2573             : INLINE GEN
    2574     1083575 : gsubgs(GEN y, long s) { return gaddgs(y, -s); }
    2575             : INLINE GEN
    2576      204234 : gdivsg(long s, GEN y) { return gdiv(stoi(s), y); }
    2577             : 
    2578             : INLINE GEN
    2579     9672146 : gmax_shallow(GEN x, GEN y) { return gcmp(x,y)<0? y: x; }
    2580             : INLINE GEN
    2581      264180 : gmin_shallow(GEN x, GEN y) { return gcmp(x,y)<0? x: y; }
    2582             : 
    2583             : /* x t_COMPLEX */
    2584             : INLINE GEN
    2585    23612865 : cxnorm(GEN x) { return gadd(gsqr(gel(x,1)), gsqr(gel(x,2))); }
    2586             : /* q t_QUAD */
    2587             : INLINE GEN
    2588      138866 : quadnorm(GEN q)
    2589             : {
    2590      138866 :   GEN X = gel(q,1), b = gel(X,3), c = gel(X,2);
    2591      138866 :   GEN z, u = gel(q,3), v = gel(q,2);
    2592      138866 :   if (typ(u) == t_INT && typ(v) == t_INT) /* generic case */
    2593             :   {
    2594      138677 :     z = signe(b)? mulii(v, addii(u,v)): sqri(v);
    2595      138677 :     return addii(z, mulii(c, sqri(u)));
    2596             :   }
    2597             :   else
    2598             :   {
    2599         189 :     z = signe(b)? gmul(v, gadd(u,v)): gsqr(v);
    2600         189 :     return gadd(z, gmul(c, gsqr(u)));
    2601             :   }
    2602             : }
    2603             : /* x a t_QUAD, return the attached discriminant */
    2604             : INLINE GEN
    2605        1001 : quad_disc(GEN x)
    2606             : {
    2607        1001 :   GEN Q = gel(x,1), b = gel(Q,3), c = gel(Q,2), c4 = shifti(c,2);
    2608        1001 :   if (is_pm1(b)) return subsi(1, c4);
    2609         147 :   togglesign_safe(&c4); return c4;
    2610             : }
    2611             : INLINE GEN
    2612     5633278 : qfb_disc3(GEN x, GEN y, GEN z) { return subii(sqri(y), shifti(mulii(x,z),2)); }
    2613             : INLINE GEN
    2614     5556558 : qfb_disc(GEN x) { return qfb_disc3(gel(x,1), gel(x,2), gel(x,3)); }
    2615             : 
    2616             : INLINE GEN
    2617     1655086 : sqrfrac(GEN x)
    2618             : {
    2619     1655086 :   GEN z = cgetg(3,t_FRAC);
    2620     1655086 :   gel(z,1) = sqri(gel(x,1));
    2621     1655086 :   gel(z,2) = sqri(gel(x,2)); return z;
    2622             : }
    2623             : 
    2624             : INLINE void
    2625     9252344 : normalize_frac(GEN z) {
    2626     9252344 :   if (signe(gel(z,2)) < 0) { togglesign(gel(z,1)); setabssign(gel(z,2)); }
    2627     9252344 : }
    2628             : 
    2629             : INLINE GEN
    2630      356667 : powii(GEN x, GEN n)
    2631             : {
    2632      356667 :   long ln = lgefint(n);
    2633      356667 :   if (ln == 3) {
    2634             :     GEN z;
    2635      352166 :     if (signe(n) > 0) return powiu(x, n[2]);
    2636        8484 :     z = cgetg(3, t_FRAC);
    2637        8484 :     gel(z,1) = gen_1;
    2638        8484 :     gel(z,2) = powiu(x, n[2]);
    2639        8484 :     return z;
    2640             :   }
    2641        4501 :   if (ln == 2) return gen_1; /* rare */
    2642             :   /* should never happen */
    2643           0 :   return powgi(x, n); /* overflow unless x = 0, 1, -1 */
    2644             : }
    2645             : INLINE GEN
    2646        1498 : powIs(long n) {
    2647        1498 :   switch(n & 3)
    2648             :   {
    2649          63 :     case 1: return mkcomplex(gen_0,gen_1);
    2650         385 :     case 2: return gen_m1;
    2651         707 :     case 3: return mkcomplex(gen_0,gen_m1);
    2652             :   }
    2653         343 :   return gen_1;
    2654             : }
    2655             : 
    2656             : /*******************************************************************/
    2657             : /*                                                                 */
    2658             : /*                             ASSIGNMENTS                         */
    2659             : /*                                                                 */
    2660             : /*******************************************************************/
    2661           0 : INLINE void mpexpz(GEN x, GEN z)
    2662           0 : { pari_sp av = avma; gaffect(mpexp(x), z); set_avma(av); }
    2663           0 : INLINE void mplogz(GEN x, GEN z)
    2664           0 : { pari_sp av = avma; gaffect(mplog(x), z); set_avma(av); }
    2665           0 : INLINE void mpcosz(GEN x, GEN z)
    2666           0 : { pari_sp av = avma; gaffect(mpcos(x), z); set_avma(av); }
    2667           0 : INLINE void mpsinz(GEN x, GEN z)
    2668           0 : { pari_sp av = avma; gaffect(mpsin(x), z); set_avma(av); }
    2669           0 : INLINE void gnegz(GEN x, GEN z)
    2670           0 : { pari_sp av = avma; gaffect(gneg(x), z); set_avma(av); }
    2671           0 : INLINE void gabsz(GEN x, long prec, GEN z)
    2672           0 : { pari_sp av = avma; gaffect(gabs(x,prec), z); set_avma(av); }
    2673           0 : INLINE void gaddz(GEN x, GEN y, GEN z)
    2674           0 : { pari_sp av = avma; gaffect(gadd(x,y), z); set_avma(av); }
    2675           0 : INLINE void gsubz(GEN x, GEN y, GEN z)
    2676           0 : { pari_sp av = avma; gaffect(gsub(x,y), z); set_avma(av); }
    2677           0 : INLINE void gmulz(GEN x, GEN y, GEN z)
    2678           0 : { pari_sp av = avma; gaffect(gmul(x,y), z); set_avma(av); }
    2679           0 : INLINE void gdivz(GEN x, GEN y, GEN z)
    2680           0 : { pari_sp av = avma; gaffect(gdiv(x,y), z); set_avma(av); }
    2681           0 : INLINE void gdiventz(GEN x, GEN y, GEN z)
    2682           0 : { pari_sp av = avma; gaffect(gdivent(x,y), z); set_avma(av); }
    2683           0 : INLINE void gmodz(GEN x, GEN y, GEN z)
    2684           0 : { pari_sp av = avma; gaffect(gmod(x,y), z); set_avma(av); }
    2685           0 : INLINE void gmul2nz(GEN x, long s, GEN z)
    2686           0 : { pari_sp av = avma; gaffect(gmul2n(x,s), z); set_avma(av); }
    2687           0 : INLINE void gshiftz(GEN x, long s, GEN z)
    2688           0 : { pari_sp av = avma; gaffect(gshift(x,s), z); set_avma(av); }
    2689             : 
    2690             : /*******************************************************************/
    2691             : /*                                                                 */
    2692             : /*                       ELLIPTIC CURVES                           */
    2693             : /*                                                                 */
    2694             : /*******************************************************************/
    2695     3985178 : INLINE GEN ell_get_a1(GEN e) { return gel(e,1); }
    2696     3098891 : INLINE GEN ell_get_a2(GEN e) { return gel(e,2); }
    2697     3866492 : INLINE GEN ell_get_a3(GEN e) { return gel(e,3); }
    2698     3891801 : INLINE GEN ell_get_a4(GEN e) { return gel(e,4); }
    2699     4708582 : INLINE GEN ell_get_a6(GEN e) { return gel(e,5); }
    2700     3323529 : INLINE GEN ell_get_b2(GEN e) { return gel(e,6); }
    2701     1027722 : INLINE GEN ell_get_b4(GEN e) { return gel(e,7); }
    2702     1633740 : INLINE GEN ell_get_b6(GEN e) { return gel(e,8); }
    2703     1464918 : INLINE GEN ell_get_b8(GEN e) { return gel(e,9); }
    2704     6231200 : INLINE GEN ell_get_c4(GEN e) { return gel(e,10); }
    2705     7469658 : INLINE GEN ell_get_c6(GEN e) { return gel(e,11); }
    2706     9724239 : INLINE GEN ell_get_disc(GEN e) { return gel(e,12); }
    2707     1031513 : INLINE GEN ell_get_j(GEN e) { return gel(e,13); }
    2708    11492848 : INLINE long ell_get_type(GEN e) { return mael(e,14,1); }
    2709     1569999 : INLINE GEN ellff_get_field(GEN x) { return gmael(x, 15, 1); }
    2710      682683 : INLINE GEN ellff_get_a4a6(GEN x)  { return gmael(x, 15, 2); }
    2711        1407 : INLINE GEN ellQp_get_zero(GEN x) { return gmael(x, 15, 1); }
    2712         287 : INLINE long ellQp_get_prec(GEN E) { GEN z = ellQp_get_zero(E); return valp(z); }
    2713        1085 : INLINE GEN ellQp_get_p(GEN E) { GEN z = ellQp_get_zero(E); return gel(z,2); }
    2714       37471 : INLINE long ellR_get_prec(GEN x) { return nbits2prec(mael3(x, 15, 1, 1)); }
    2715       13684 : INLINE long ellR_get_sign(GEN x) { return mael3(x, 15, 1, 2); }
    2716      711094 : INLINE GEN ellnf_get_nf(GEN x) { return checknf_i(gmael(x,15,1)); }
    2717          56 : INLINE GEN ellnf_get_bnf(GEN x) { return checkbnf_i(gmael(x,15,1)); }
    2718             : 
    2719     4636663 : INLINE int checkell_i(GEN e) { return typ(e) == t_VEC && lg(e) == 17; }
    2720    34039510 : INLINE int ell_is_inf(GEN z) { return lg(z) == 2; }
    2721      808850 : INLINE GEN ellinf(void) { return mkvec(gen_0); }
    2722             : 
    2723             : /*******************************************************************/
    2724             : /*                                                                 */
    2725             : /*                    ALGEBRAIC NUMBER THEORY                      */
    2726             : /*                                                                 */
    2727             : /*******************************************************************/
    2728     8477934 : INLINE GEN modpr_get_pr(GEN x)  { return gel(x,3); }
    2729      631281 : INLINE GEN modpr_get_p(GEN x)  { return pr_get_p(modpr_get_pr(x)); }
    2730     2543306 : INLINE GEN modpr_get_T(GEN x)  { return lg(x) == 4? NULL: gel(x,4); }
    2731             : 
    2732    37692920 : INLINE GEN pr_get_p(GEN pr)  { return gel(pr,1); }
    2733     4414658 : INLINE GEN pr_get_gen(GEN pr){ return gel(pr,2); }
    2734             : /* .[2] instead of itos works: e and f are small positive integers */
    2735     2859688 : INLINE long pr_get_e(GEN pr) { return gel(pr,3)[2]; }
    2736    12991255 : INLINE long pr_get_f(GEN pr) { return gel(pr,4)[2]; }
    2737    24780952 : INLINE GEN pr_get_tau(GEN pr){ return gel(pr,5); }
    2738             : INLINE int
    2739     4011058 : pr_is_inert(GEN P) { return typ(pr_get_tau(P)) == t_INT; }
    2740             : INLINE GEN
    2741     2276023 : pr_norm(GEN pr) { return powiu(pr_get_p(pr), pr_get_f(pr)); }
    2742             : INLINE ulong
    2743       97006 : upr_norm(GEN pr) { return upowuu(pr_get_p(pr)[2], pr_get_f(pr)); }
    2744             : 
    2745             : /* assume nf a genuine nf */
    2746             : INLINE long
    2747      395300 : nf_get_varn(GEN nf) { return varn(gel(nf,1)); }
    2748             : INLINE GEN
    2749    38021784 : nf_get_pol(GEN nf) { return gel(nf,1); }
    2750             : INLINE long
    2751    30625604 : nf_get_degree(GEN nf) { return degpol( nf_get_pol(nf) ); }
    2752             : INLINE long
    2753     4495790 : nf_get_r1(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,1)); }
    2754             : INLINE long
    2755        3032 : nf_get_r2(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,2)); }
    2756             : INLINE GEN
    2757       62402 : nf_get_disc(GEN nf) { return gel(nf,3); }
    2758             : INLINE GEN
    2759      941842 : nf_get_index(GEN nf) { return gel(nf,4); }
    2760             : INLINE GEN
    2761     2851076 : nf_get_M(GEN nf) { return gmael(nf,5,1); }
    2762             : INLINE GEN
    2763     1967699 : nf_get_G(GEN nf) { return gmael(nf,5,2); }
    2764             : INLINE GEN
    2765     2383085 : nf_get_roundG(GEN nf) { return gmael(nf,5,3); }
    2766             : INLINE GEN
    2767       16121 : nf_get_Tr(GEN nf) { return gmael(nf,5,4); }
    2768             : INLINE GEN
    2769        2814 : nf_get_diff(GEN nf) { return gmael(nf,5,5); }
    2770             : INLINE GEN
    2771        2898 : nf_get_ramified_primes(GEN nf) { return gmael(nf,5,8); }
    2772             : INLINE GEN
    2773      398281 : nf_get_roots(GEN nf) { return gel(nf,6); }
    2774             : INLINE GEN
    2775          98 : nf_get_zk(GEN nf)
    2776             : {
    2777          98 :   GEN y = gel(nf,7), D = gel(y, 1);
    2778          98 :   if (typ(D) == t_POL) D = gel(D, 2);
    2779          98 :   if (!equali1(D)) y = gdiv(y, D);
    2780          98 :   return y;
    2781             : }
    2782             : INLINE GEN
    2783     1276610 : nf_get_zkprimpart(GEN nf)
    2784             : {
    2785     1276610 :   GEN y = gel(nf,7);
    2786             :   /* test for old format of nf.zk: non normalized */
    2787     1276610 :   if (!equali1(gel(nf,4)) && gequal1(gel(y,1))) y = Q_remove_denom(y,NULL);
    2788     1276605 :   return y;
    2789             : }
    2790             : INLINE GEN
    2791     1277468 : nf_get_zkden(GEN nf)
    2792             : {
    2793     1277468 :   GEN y = gel(nf,7), D = gel(y,1);
    2794     1277468 :   if (typ(D) == t_POL) D = gel(D,2);
    2795             :   /* test for old format of nf.zk: non normalized */
    2796     1277468 :   if (!equali1(gel(nf,4)) && equali1(D)) D = Q_denom(y);
    2797     1277463 :   return D;
    2798             : }
    2799             : INLINE GEN
    2800     2914511 : nf_get_invzk(GEN nf) { return gel(nf,8); }
    2801             : INLINE void
    2802       23833 : nf_get_sign(GEN nf, long *r1, long *r2)
    2803             : {
    2804       23833 :   GEN x = gel(nf,2);
    2805       23833 :   *r1 = itou(gel(x,1));
    2806       23833 :   *r2 = itou(gel(x,2));
    2807       23833 : }
    2808             : 
    2809             : INLINE GEN
    2810      438716 : cyc_get_expo(GEN c) { return lg(c) == 1? gen_1: gel(c,1); }
    2811             : INLINE GEN
    2812       98785 : abgrp_get_no(GEN x) { return gel(x,1); }
    2813             : INLINE GEN
    2814     3027366 : abgrp_get_cyc(GEN x) { return gel(x,2); }
    2815             : INLINE GEN
    2816      390122 : abgrp_get_gen(GEN x) { return gel(x,3); }
    2817             : INLINE GEN
    2818     2408198 : bnf_get_nf(GEN bnf) { return gel(bnf,7); }
    2819             : INLINE GEN
    2820     1265540 : bnf_get_clgp(GEN bnf) { return gmael(bnf,8,1); }
    2821             : INLINE GEN
    2822        7364 : bnf_get_no(GEN bnf) { return abgrp_get_no(bnf_get_clgp(bnf)); }
    2823             : INLINE GEN
    2824      920512 : bnf_get_cyc(GEN bnf) { return abgrp_get_cyc(bnf_get_clgp(bnf)); }
    2825             : INLINE GEN
    2826      337650 : bnf_get_gen(GEN bnf)  { return abgrp_get_gen(bnf_get_clgp(bnf)); }
    2827             : INLINE GEN
    2828         713 : bnf_get_reg(GEN bnf) { return gmael(bnf,8,2); }
    2829             : INLINE GEN
    2830      531517 : bnf_get_logfu(GEN bnf) { return gel(bnf,3); }
    2831             : INLINE GEN
    2832        5456 : bnf_get_sunits(GEN bnf)
    2833        5456 : { GEN s = gmael(bnf,8,3); return typ(s) == t_INT? NULL: s; }
    2834             : INLINE GEN
    2835       39173 : bnf_get_tuU(GEN bnf) { return gmael3(bnf,8,4,2); }
    2836             : INLINE long
    2837       40656 : bnf_get_tuN(GEN bnf) { return gmael3(bnf,8,4,1)[2]; }
    2838             : INLINE GEN
    2839       39004 : bnf_get_fu_nocheck(GEN bnf) { return gmael(bnf,8,5); }
    2840             : INLINE GEN
    2841        1687 : bnf_get_fu(GEN bnf) {
    2842        1687 :   GEN fu = bnf_build_units(bnf), nf = bnf_get_nf(bnf);
    2843             :   long i, l;
    2844        1687 :   if (typ(fu) == t_MAT) pari_err(e_MISC,"missing units in bnf");
    2845        1687 :   l = lg(fu)-1; fu = vecslice(fu, 2, l);
    2846        3822 :   for (i = 1; i < l; i++) gel(fu,i) = nf_to_scalar_or_alg(nf, gel(fu,i));
    2847        1687 :   return fu;
    2848             : }
    2849             : 
    2850             : INLINE GEN
    2851      897167 : bnr_get_bnf(GEN bnr) { return gel(bnr,1); }
    2852             : INLINE GEN
    2853      508689 : bnr_get_bid(GEN bnr) { return gel(bnr,2); }
    2854             : INLINE GEN
    2855       24402 : bnr_get_mod(GEN bnr) { return gmael(bnr,2,1); }
    2856             : INLINE GEN
    2857      134855 : bnr_get_nf(GEN bnr) { return gmael(bnr,1,7); }
    2858             : INLINE GEN
    2859      754732 : bnr_get_clgp(GEN bnr) { return gel(bnr,5); }
    2860             : INLINE GEN
    2861       84665 : bnr_get_no(GEN bnr) { return abgrp_get_no(bnr_get_clgp(bnr)); }
    2862             : INLINE GEN
    2863      654065 : bnr_get_cyc(GEN bnr) { return abgrp_get_cyc(bnr_get_clgp(bnr)); }
    2864             : INLINE GEN
    2865          70 : bnr_get_gen_nocheck(GEN bnr) { return abgrp_get_gen(bnr_get_clgp(bnr)); }
    2866             : INLINE GEN
    2867        7812 : bnr_get_gen(GEN bnr) {
    2868        7812 :   GEN G = bnr_get_clgp(bnr);
    2869        7812 :   if (lg(G) !=  4)
    2870           0 :     pari_err(e_MISC,"missing bnr generators: please use bnrinit(,,1)");
    2871        7812 :   return gel(G,3);
    2872             : }
    2873             : 
    2874             : INLINE GEN
    2875      302188 : bid_get_mod(GEN bid) { return gel(bid,1); }
    2876             : INLINE GEN
    2877       65030 : bid_get_ideal(GEN bid) { return gmael(bid,1,1); }
    2878             : INLINE GEN
    2879        2695 : bid_get_arch(GEN bid) { return gmael(bid,1,2); }
    2880             : INLINE GEN
    2881     1297207 : bid_get_grp(GEN bid) { return gel(bid,2); }
    2882             : INLINE GEN
    2883      510557 : bid_get_fact(GEN bid) { return gmael(bid,3,1); }
    2884             : INLINE GEN
    2885      438744 : bid_get_fact2(GEN bid) { return gmael(bid,3,2); }
    2886             : INLINE GEN
    2887      437813 : bid_get_sprk(GEN bid) { return gmael(bid,4,1); }
    2888             : INLINE GEN
    2889       49322 : bid_get_sarch(GEN bid) { return gmael(bid,4,2); }
    2890             : INLINE GEN
    2891      474360 : bid_get_archp(GEN bid) { return gmael3(bid,4,2,2); }
    2892             : INLINE GEN
    2893      740267 : bid_get_U(GEN bid) { return gel(bid,5); }
    2894             : INLINE GEN
    2895           0 : bid_get_no(GEN bid) { return abgrp_get_no(bid_get_grp(bid)); }
    2896             : INLINE GEN
    2897     1248053 : bid_get_cyc(GEN bid) { return abgrp_get_cyc(bid_get_grp(bid)); }
    2898             : INLINE GEN
    2899           0 : bid_get_gen_nocheck(GEN bid)  { return abgrp_get_gen(bid_get_grp(bid)); }
    2900             : INLINE GEN
    2901       48573 : bid_get_gen(GEN bid) {
    2902       48573 :   GEN G = bid_get_grp(bid);
    2903       48573 :   if (lg(G) != 4) pari_err(e_MISC,"missing bid generators. Use idealstar(,,2)");
    2904       48573 :   return abgrp_get_gen(G);
    2905             : }
    2906             : 
    2907             : INLINE GEN
    2908    26241327 : znstar_get_N(GEN G) { return gmael(G,1,1); }
    2909             : INLINE GEN
    2910     3216444 : znstar_get_faN(GEN G) { return gel(G,3); }
    2911             : INLINE GEN
    2912           7 : znstar_get_no(GEN G) { return abgrp_get_no(gel(G,2)); }
    2913             : INLINE GEN
    2914      191107 : znstar_get_cyc(GEN G) { return abgrp_get_cyc(gel(G,2)); }
    2915             : INLINE GEN
    2916           7 : znstar_get_gen(GEN G) { return abgrp_get_gen(gel(G,2)); }
    2917             : INLINE GEN
    2918     3893393 : znstar_get_conreycyc(GEN G) { return gmael(G,4,5); }
    2919             : INLINE GEN
    2920     1386476 : znstar_get_conreygen(GEN G) { return gmael(G,4,4); }
    2921             : INLINE GEN
    2922       45927 : znstar_get_Ui(GEN G) { return gmael(G,4,3); }
    2923             : INLINE GEN
    2924      120162 : znstar_get_U(GEN G) { return gel(G,5); }
    2925             : INLINE GEN
    2926      989856 : znstar_get_pe(GEN G) { return gmael(G,4,1); }
    2927             : INLINE GEN
    2928       21630 : gal_get_pol(GEN gal) { return gel(gal,1); }
    2929             : INLINE GEN
    2930        2051 : gal_get_p(GEN gal) { return gmael(gal,2,1); }
    2931             : INLINE GEN
    2932          91 : gal_get_e(GEN gal) { return gmael(gal,2,2); }
    2933             : INLINE GEN
    2934       16800 : gal_get_mod(GEN gal) { return gmael(gal,2,3); }
    2935             : INLINE GEN
    2936       17913 : gal_get_roots(GEN gal) { return gel(gal,3); }
    2937             : INLINE GEN
    2938       16870 : gal_get_invvdm(GEN gal) { return gel(gal,4); }
    2939             : INLINE GEN
    2940       16870 : gal_get_den(GEN gal) { return gel(gal,5); }
    2941             : INLINE GEN
    2942       69626 : gal_get_group(GEN gal) { return gel(gal,6); }
    2943             : INLINE GEN
    2944        1988 : gal_get_gen(GEN gal) { return gel(gal,7); }
    2945             : INLINE GEN
    2946        1624 : gal_get_orders(GEN gal) { return gel(gal,8); }
    2947             : 
    2948             : /* assume rnf a genuine rnf */
    2949             : INLINE long
    2950     1233932 : rnf_get_degree(GEN rnf) { return degpol(rnf_get_pol(rnf)); }
    2951             : INLINE long
    2952       16688 : rnf_get_nfdegree(GEN rnf) { return degpol(nf_get_pol(rnf_get_nf(rnf))); }
    2953             : INLINE long
    2954      775705 : rnf_get_absdegree(GEN rnf) { return degpol(gmael(rnf,11,1)); }
    2955             : INLINE GEN
    2956         700 : rnf_get_idealdisc(GEN rnf) { return gmael(rnf,3,1); }
    2957             : INLINE GEN
    2958         749 : rnf_get_k(GEN rnf) { return gmael(rnf,11,3); }
    2959             : INLINE GEN
    2960         812 : rnf_get_alpha(GEN rnf) { return gmael(rnf, 11, 2); }
    2961             : INLINE GEN
    2962      425789 : rnf_get_nf(GEN rnf) { return gel(rnf,10); }
    2963             : INLINE GEN
    2964        3829 : rnf_get_nfzk(GEN rnf) { return gel(rnf,2); }
    2965             : INLINE GEN
    2966      210301 : rnf_get_polabs(GEN rnf) { return gmael(rnf,11,1); }
    2967             : INLINE GEN
    2968     1480220 : rnf_get_pol(GEN rnf) { return gel(rnf,1); }
    2969             : INLINE GEN
    2970         175 : rnf_get_disc(GEN rnf) { return gel(rnf,3); }
    2971             : INLINE GEN
    2972         105 : rnf_get_index(GEN rnf) { return gel(rnf,4); }
    2973             : INLINE GEN
    2974        1568 : rnf_get_ramified_primes(GEN rnf) { return gel(rnf,5); }
    2975             : INLINE long
    2976         231 : rnf_get_varn(GEN rnf) { return varn(gel(rnf,1)); }
    2977             : INLINE GEN
    2978      188538 : rnf_get_nfpol(GEN rnf) { return gmael(rnf,10,1); }
    2979             : INLINE long
    2980        3332 : rnf_get_nfvarn(GEN rnf) { return varn(gmael(rnf,10,1)); }
    2981             : INLINE GEN
    2982        3507 : rnf_get_zk(GEN rnf) { return gel(rnf,7); }
    2983             : INLINE GEN
    2984      102711 : rnf_get_map(GEN rnf) { return gel(rnf,11); }
    2985             : INLINE GEN
    2986        1197 : rnf_get_invzk(GEN rnf) { return gel(rnf,8); }
    2987             : 
    2988             : /* I integral ZM (not HNF), G ZM, rounded Cholesky form of a weighted
    2989             :  * T2 matrix. Reduce I wrt G */
    2990             : INLINE GEN
    2991      352627 : idealpseudored(GEN I, GEN G)
    2992      352627 : { return ZM_mul(I, ZM_lll(ZM_mul(G, I), 0.99, LLL_IM)); }
    2993             : 
    2994             : /* Same I, G; m in I with T2(m) small */
    2995             : INLINE GEN
    2996       86109 : idealpseudomin(GEN I, GEN G)
    2997             : {
    2998       86109 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2999       86109 :   return ZM_ZC_mul(I, gel(u,1));
    3000             : }
    3001             : /* Same I,G; irrational m in I with T2(m) small */
    3002             : INLINE GEN
    3003           0 : idealpseudomin_nonscalar(GEN I, GEN G)
    3004             : {
    3005           0 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    3006           0 :   GEN m = ZM_ZC_mul(I, gel(u,1));
    3007           0 :   if (ZV_isscalar(m) && lg(u) > 2) m = ZM_ZC_mul(I, gel(u,2));
    3008           0 :   return m;
    3009             : }
    3010             : /* Same I,G; t_VEC of irrational m in I with T2(m) small */
    3011             : INLINE GEN
    3012      330332 : idealpseudominvec(GEN I, GEN G)
    3013             : {
    3014      330332 :   long i, j, k, n = lg(I)-1;
    3015      330332 :   GEN x, L, b = idealpseudored(I, G);
    3016      330332 :   L = cgetg(1 + (n*(n+1))/2, t_VEC);
    3017     1289299 :   for (i = k = 1; i <= n; i++)
    3018             :   {
    3019      958967 :     x = gel(b,i);
    3020      958967 :     if (!ZV_isscalar(x)) gel(L,k++) = x;
    3021             :   }
    3022      958967 :   for (i = 2; i <= n; i++)
    3023     1692694 :     for (j = 1; j < i; j++)
    3024             :     {
    3025     1064059 :       x = ZC_add(gel(b,i),gel(b,j));
    3026     1064059 :       if (!ZV_isscalar(x)) gel(L,k++) = x;
    3027             :     }
    3028      330332 :   setlg(L,k); return L;
    3029             : }
    3030             : 
    3031             : INLINE GEN
    3032        1694 : idealred_elt(GEN nf, GEN I) {
    3033        1694 :   pari_sp av = avma;
    3034        1694 :   GEN u = idealpseudomin(I, nf_get_roundG(nf));
    3035        1694 :   return gerepileupto(av, u);
    3036             : }
    3037             : INLINE GEN
    3038       93386 : idealred(GEN nf, GEN I) { return idealred0(nf, I, NULL); }
    3039             : 
    3040             : INLINE GEN
    3041        2051 : idealchineseinit(GEN nf, GEN x)
    3042        2051 : { return idealchinese(nf,x,NULL); }
    3043             : 
    3044             : /*******************************************************************/
    3045             : /*                                                                 */
    3046             : /*                              CLOSURES                           */
    3047             : /*                                                                 */
    3048             : /*******************************************************************/
    3049   236195615 : INLINE long closure_arity(GEN C)          { return ((ulong)C[1])&ARITYBITS; }
    3050    35494780 : INLINE long closure_is_variadic(GEN C) { return !!(((ulong)C[1])&VARARGBITS); }
    3051   196168741 : INLINE const char *closure_codestr(GEN C)  { return GSTR(gel(C,2))-1; }
    3052           0 : INLINE GEN closure_get_code(GEN C)  { return gel(C,2); }
    3053   196147950 : INLINE GEN closure_get_oper(GEN C)  { return gel(C,3); }
    3054   196127775 : INLINE GEN closure_get_data(GEN C)  { return gel(C,4); }
    3055       10493 : INLINE GEN closure_get_dbg(GEN C)   { return gel(C,5); }
    3056       24909 : INLINE GEN closure_get_text(GEN C)  { return gel(C,6); }
    3057     5447778 : INLINE GEN closure_get_frame(GEN C) { return gel(C,7); }
    3058             : 
    3059             : /*******************************************************************/
    3060             : /*                                                                 */
    3061             : /*                               ERRORS                            */
    3062             : /*                                                                 */
    3063             : /*******************************************************************/
    3064             : INLINE long
    3065       54618 : err_get_num(GEN e) { return e[1]; }
    3066             : INLINE GEN
    3067         105 : err_get_compo(GEN e, long i) { return gel(e, i+1); }
    3068             : 
    3069             : INLINE void
    3070          14 : pari_err_BUG(const char *f) { pari_err(e_BUG,f); }
    3071             : INLINE void
    3072           7 : pari_err_CONSTPOL(const char *f) { pari_err(e_CONSTPOL, f); }
    3073             : INLINE void
    3074          70 : pari_err_COPRIME(const char *f, GEN x, GEN y) { pari_err(e_COPRIME, f,x,y); }
    3075             : INLINE void
    3076         529 : pari_err_DIM(const char *f) { pari_err(e_DIM, f); }
    3077             : INLINE void
    3078           0 : pari_err_FILE(const char *f, const char *g) { pari_err(e_FILE, f,g); }
    3079             : INLINE void
    3080           0 : pari_err_FILEDESC(const char *f, long n) { pari_err(e_FILEDESC, f,n); }
    3081             : INLINE void
    3082          91 : pari_err_FLAG(const char *f) { pari_err(e_FLAG,f); }
    3083             : INLINE void
    3084         448 : pari_err_IMPL(const char *f) { pari_err(e_IMPL,f); }
    3085             : INLINE void
    3086       19779 : pari_err_INV(const char *f, GEN x) { pari_err(e_INV,f,x); }
    3087             : INLINE void
    3088          49 : pari_err_IRREDPOL(const char *f, GEN x) { pari_err(e_IRREDPOL, f,x); }
    3089             : INLINE void
    3090        2169 : 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); }
    3091             : INLINE void
    3092         200 : pari_err_COMPONENT(const char *f, const char *op, GEN l, GEN x) { pari_err(e_COMPONENT, f,op,l,x); }
    3093             : INLINE void
    3094           0 : pari_err_MAXPRIME(ulong c) { pari_err(e_MAXPRIME, c); }
    3095             : INLINE void
    3096         364 : pari_err_OP(const char *f, GEN x, GEN y) { pari_err(e_OP, f,x,y); }
    3097             : INLINE void
    3098         114 : pari_err_OVERFLOW(const char *f) { pari_err(e_OVERFLOW, f); }
    3099             : INLINE void
    3100         225 : pari_err_PREC(const char *f) { pari_err(e_PREC,f); }
    3101             : INLINE void
    3102           0 : pari_err_PACKAGE(const char *f) { pari_err(e_PACKAGE,f); }
    3103             : INLINE void
    3104          77 : pari_err_PRIME(const char *f, GEN x) { pari_err(e_PRIME, f,x); }
    3105             : INLINE void
    3106         749 : pari_err_MODULUS(const char *f, GEN x, GEN y) { pari_err(e_MODULUS, f,x,y); }
    3107             : INLINE void
    3108          49 : pari_err_ROOTS0(const char *f) { pari_err(e_ROOTS0, f); }
    3109             : INLINE void
    3110          84 : pari_err_SQRTN(const char *f, GEN x) { pari_err(e_SQRTN, f,x); }
    3111             : INLINE void
    3112       13049 : pari_err_TYPE(const char *f, GEN x) { pari_err(e_TYPE, f,x); }
    3113             : INLINE void
    3114        3388 : pari_err_TYPE2(const char *f, GEN x, GEN y) { pari_err(e_TYPE2, f,x,y); }
    3115             : INLINE void
    3116         280 : pari_err_VAR(const char *f, GEN x, GEN y) { pari_err(e_VAR, f,x,y); }
    3117             : INLINE void
    3118         196 : pari_err_PRIORITY(const char *f, GEN x, const char *op, long v)
    3119         196 : { pari_err(e_PRIORITY, f,x,op,v); }

Generated by: LCOV version 1.13