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 26712-590d837a1c) Lines: 1367 1524 89.7 %
Date: 2021-06-22 07:13:04 Functions: 587 662 88.7 %
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 retmkqfb(x,y,z,d)\
      79             :   do { GEN _v = cgetg(5, t_QFB);\
      80             :        gel(_v,1) = (x);\
      81             :        gel(_v,2) = (y);\
      82             :        gel(_v,3) = (z);\
      83             :        gel(_v,4) = (d); return _v; } while(0)
      84             : #define retmkquad(x,y,z)\
      85             :   do { GEN _v = cgetg(4, t_QUAD);\
      86             :        gel(_v,1) = (x);\
      87             :        gel(_v,2) = (y);\
      88             :        gel(_v,3) = (z); return _v; } while(0)
      89             : #define retmkvec4(x,y,z,t)\
      90             :   do { GEN _v = cgetg(5, t_VEC);\
      91             :        gel(_v,1) = (x);\
      92             :        gel(_v,2) = (y);\
      93             :        gel(_v,3) = (z);\
      94             :        gel(_v,4) = (t); return _v; } while(0)
      95             : #define retmkvec5(x,y,z,t,u)\
      96             :   do { GEN _v = cgetg(6, t_VEC);\
      97             :        gel(_v,1) = (x);\
      98             :        gel(_v,2) = (y);\
      99             :        gel(_v,3) = (z);\
     100             :        gel(_v,4) = (t);\
     101             :        gel(_v,5) = (u); return _v; } while(0)
     102             : #define retmkcol(x)\
     103             :   do { GEN _v = cgetg(2, t_COL);\
     104             :        gel(_v,1) = (x); return _v; } while(0)
     105             : #define retmkcol2(x,y)\
     106             :   do { GEN _v = cgetg(3, t_COL);\
     107             :        gel(_v,1) = (x);\
     108             :        gel(_v,2) = (y); return _v; } while(0)
     109             : #define retmkcol3(x,y,z)\
     110             :   do { GEN _v = cgetg(4, t_COL);\
     111             :        gel(_v,1) = (x);\
     112             :        gel(_v,2) = (y);\
     113             :        gel(_v,3) = (z); return _v; } while(0)
     114             : #define retmkcol4(x,y,z,t)\
     115             :   do { GEN _v = cgetg(5, t_COL);\
     116             :        gel(_v,1) = (x);\
     117             :        gel(_v,2) = (y);\
     118             :        gel(_v,3) = (z);\
     119             :        gel(_v,4) = (t); return _v; } while(0)
     120             : #define retmkcol5(x,y,z,t,u)\
     121             :   do { GEN _v = cgetg(6, t_COL);\
     122             :        gel(_v,1) = (x);\
     123             :        gel(_v,2) = (y);\
     124             :        gel(_v,3) = (z);\
     125             :        gel(_v,4) = (t);\
     126             :        gel(_v,5) = (u); return _v; } while(0)
     127             : #define retmkcol6(x,y,z,t,u,v)\
     128             :   do { GEN _v = cgetg(7, t_COL);\
     129             :        gel(_v,1) = (x);\
     130             :        gel(_v,2) = (y);\
     131             :        gel(_v,3) = (z);\
     132             :        gel(_v,4) = (t);\
     133             :        gel(_v,5) = (u);\
     134             :        gel(_v,6) = (v); return _v; } while(0)
     135             : #define retmkmat(x)\
     136             :   do { GEN _v = cgetg(2, t_MAT);\
     137             :        gel(_v,1) = (x); return _v; } while(0)
     138             : #define retmkmat2(x,y)\
     139             :   do { GEN _v = cgetg(3, t_MAT);\
     140             :        gel(_v,1) = (x);\
     141             :        gel(_v,2) = (y); return _v; } while(0)
     142             : #define retmkmat3(x,y,z)\
     143             :   do { GEN _v = cgetg(4, t_MAT);\
     144             :        gel(_v,1) = (x);\
     145             :        gel(_v,2) = (y);\
     146             :        gel(_v,3) = (z); return _v; } while(0)
     147             : #define retmkmat4(x,y,z,t)\
     148             :   do { GEN _v = cgetg(5, t_MAT);\
     149             :        gel(_v,1) = (x);\
     150             :        gel(_v,2) = (y);\
     151             :        gel(_v,3) = (z);\
     152             :        gel(_v,4) = (t); return _v; } while(0)
     153             : #define retmkmat5(x,y,z,t,u)\
     154             :   do { GEN _v = cgetg(6, t_MAT);\
     155             :        gel(_v,1) = (x);\
     156             :        gel(_v,2) = (y);\
     157             :        gel(_v,3) = (z);\
     158             :        gel(_v,4) = (t);\
     159             :        gel(_v,5) = (u); return _v; } while(0)
     160             : 
     161             : INLINE GEN
     162     6197080 : mkintmod(GEN x, GEN y) { retmkintmod(x,y); }
     163             : INLINE GEN
     164        1666 : mkintmodu(ulong x, ulong y) {
     165        1666 :   GEN v = cgetg(3,t_INTMOD);
     166        1666 :   gel(v,1) = utoipos(y);
     167        1666 :   gel(v,2) = utoi(x); return v;
     168             : }
     169             : INLINE GEN
     170     2626614 : mkpolmod(GEN x, GEN y) { retmkpolmod(x,y); }
     171             : INLINE GEN
     172    29165944 : mkfrac(GEN x, GEN y) { retmkfrac(x,y); }
     173             : INLINE GEN
     174       32881 : mkfracss(long x, long y) { retmkfrac(stoi(x),utoipos(y)); }
     175             : /* q = n/d a t_FRAC or t_INT; recover (n,d) */
     176             : INLINE void
     177       14161 : Qtoss(GEN q, long *n, long *d)
     178             : {
     179       14161 :   if (typ(q) == t_INT) { *n = itos(q); *d = 1; }
     180        2912 :   else { *n = itos(gel(q,1)); *d = itou(gel(q,2)); }
     181       14161 : }
     182             : INLINE GEN
     183   137650754 : sstoQ(long n, long d)
     184             : {
     185             :   ulong r;
     186             :   long g, q;
     187   137650754 :   if (!n)
     188             :   {
     189      100613 :     if (!d) pari_err_INV("sstoQ",gen_0);
     190      100613 :     return gen_0;
     191             :   }
     192   137550141 :   if (d < 0) { d = -d; n = -n; }
     193   137550141 :   if (d == 1) return stoi(n);
     194   137537786 :   q = udivuu_rem(labs(n),d,&r);
     195   137537786 :   if (!r) return n > 0? utoipos(q): utoineg(q);
     196     4932558 :   g = ugcd(d,r); /* gcd(n,d) */
     197     4932558 :   if (g != 1) { n /= g; d /= g; }
     198     4932558 :   retmkfrac(stoi(n), utoi(d));
     199             : }
     200             : 
     201             : INLINE GEN
     202     3695584 : mkfraccopy(GEN x, GEN y) { retmkfrac(icopy(x), icopy(y)); }
     203             : INLINE GEN
     204        9345 : mkrfrac(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     205        9345 :   gel(v,1) = x; gel(v,2) = y; return v; }
     206             : INLINE GEN
     207           7 : mkrfraccopy(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     208           7 :   gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     209             : INLINE GEN
     210    84905300 : mkcomplex(GEN x, GEN y) { retmkcomplex(x,y); }
     211             : INLINE GEN
     212      854446 : gen_I(void) { return mkcomplex(gen_0, gen_1); }
     213             : INLINE GEN
     214      293378 : cgetc(long l) { retmkcomplex(cgetr(l), cgetr(l)); }
     215             : INLINE GEN
     216       86331 : mkquad(GEN n, GEN x, GEN y) { GEN v = cgetg(4, t_QUAD);
     217       86331 :   gel(v,1) = n; gel(v,2) = x; gel(v,3) = y; return v; }
     218             : /* vecsmall */
     219             : INLINE GEN
     220   111015976 : mkvecsmall(long x) { GEN v = cgetg(2, t_VECSMALL); v[1] = x; return v; }
     221             : INLINE GEN
     222   515867513 : mkvecsmall2(long x,long y) { GEN v = cgetg(3, t_VECSMALL);
     223   515845896 :   v[1]=x; v[2]=y; return v; }
     224             : INLINE GEN
     225   229766348 : mkvecsmall3(long x,long y,long z) { GEN v = cgetg(4, t_VECSMALL);
     226   229753063 :   v[1]=x; v[2]=y; v[3]=z; return v; }
     227             : INLINE GEN
     228    13902141 : mkvecsmall4(long x,long y,long z,long t) { GEN v = cgetg(5, t_VECSMALL);
     229    13888075 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; return v; }
     230             : INLINE GEN
     231      556102 : mkvecsmall5(long x,long y,long z,long t,long u) { GEN v = cgetg(6, t_VECSMALL);
     232      556101 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; v[5]=u; return v; }
     233             : 
     234             : INLINE GEN
     235    16845548 : mkqfb(GEN x, GEN y, GEN z, GEN d) { retmkqfb(x,y,z,d); }
     236             : /* vec */
     237             : INLINE GEN
     238    56457602 : mkvec(GEN x) { retmkvec(x); }
     239             : INLINE GEN
     240   162180134 : mkvec2(GEN x, GEN y) { retmkvec2(x,y); }
     241             : INLINE GEN
     242    92115251 : mkvec3(GEN x, GEN y, GEN z) { retmkvec3(x,y,z); }
     243             : INLINE GEN
     244     7947856 : mkvec4(GEN x, GEN y, GEN z, GEN t) { retmkvec4(x,y,z,t); }
     245             : INLINE GEN
     246    14306754 : mkvec5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkvec5(x,y,z,t,u); }
     247             : INLINE GEN
     248         105 : mkvecs(long x) { retmkvec(stoi(x)); }
     249             : INLINE GEN
     250       91900 : mkvec2s(long x, long y) { retmkvec2(stoi(x),stoi(y)); }
     251             : INLINE GEN
     252      488650 : mkvec3s(long x, long y, long z) { retmkvec3(stoi(x),stoi(y),stoi(z)); }
     253             : INLINE GEN
     254          21 : mkvec4s(long x, long y, long z, long t) { retmkvec4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     255             : INLINE GEN
     256       35763 : mkveccopy(GEN x) { GEN v = cgetg(2, t_VEC); gel(v,1) = gcopy(x); return v; }
     257             : INLINE GEN
     258      114235 : mkvec2copy(GEN x, GEN y) {
     259      114235 :   GEN v = cgetg(3,t_VEC); gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     260             : /* col */
     261             : INLINE GEN
     262     4938207 : mkcol(GEN x) { retmkcol(x); }
     263             : INLINE GEN
     264    63681082 : mkcol2(GEN x, GEN y) { retmkcol2(x,y); }
     265             : INLINE GEN
     266       51943 : mkcol3(GEN x, GEN y, GEN z) { retmkcol3(x,y,z); }
     267             : INLINE GEN
     268           0 : mkcol4(GEN x, GEN y, GEN z, GEN t) { retmkcol4(x,y,z,t); }
     269             : INLINE GEN
     270         106 : mkcol5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkcol5(x,y,z,t,u); }
     271             : INLINE GEN
     272       11902 : mkcol6(GEN x, GEN y, GEN z, GEN t, GEN u, GEN v) { retmkcol6(x,y,z,t,u,v); }
     273             : INLINE GEN
     274       36589 : mkcols(long x) { retmkcol(stoi(x)); }
     275             : INLINE GEN
     276     2760800 : mkcol2s(long x, long y) { retmkcol2(stoi(x),stoi(y)); }
     277             : INLINE GEN
     278           0 : mkcol3s(long x, long y, long z) { retmkcol3(stoi(x),stoi(y),stoi(z)); }
     279             : INLINE GEN
     280           0 : mkcol4s(long x, long y, long z, long t) { retmkcol4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     281             : INLINE GEN
     282       27627 : mkcolcopy(GEN x) { GEN v = cgetg(2, t_COL); gel(v,1) = gcopy(x); return v; }
     283             : /* mat */
     284             : INLINE GEN
     285     3305011 : mkmat(GEN x) { retmkmat(x); }
     286             : INLINE GEN
     287    39527015 : mkmat2(GEN x, GEN y) { retmkmat2(x,y); }
     288             : INLINE GEN
     289        5341 : mkmat3(GEN x, GEN y, GEN z) { retmkmat3(x,y,z); }
     290             : INLINE GEN
     291           0 : mkmat4(GEN x, GEN y, GEN z, GEN t) { retmkmat4(x,y,z,t); }
     292             : INLINE GEN
     293           0 : mkmat5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkmat5(x,y,z,t,u); }
     294             : INLINE GEN
     295      118953 : mkmatcopy(GEN x) { GEN v = cgetg(2, t_MAT); gel(v,1) = gcopy(x); return v; }
     296             : INLINE GEN
     297           0 : mkerr(long x) { GEN v = cgetg(2, t_ERROR); v[1] = x; return v; }
     298             : INLINE GEN
     299      197270 : mkoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_1; return v; }
     300             : INLINE GEN
     301      100905 : mkmoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_m1; return v; }
     302             : INLINE long
     303      310154 : inf_get_sign(GEN x) { return signe(gel(x,1)); }
     304             : INLINE GEN
     305       12432 : mkmat22s(long a, long b, long c, long d) {retmkmat2(mkcol2s(a,c),mkcol2s(b,d));}
     306             : INLINE GEN
     307     5355456 : mkmat22(GEN a, GEN b, GEN c, GEN d) { retmkmat2(mkcol2(a,c),mkcol2(b,d)); }
     308             : 
     309             : /* pol */
     310             : INLINE GEN
     311     2458147 : pol_x(long v) {
     312     2458147 :   GEN p = cgetg(4, t_POL);
     313     2458183 :   p[1] = evalsigne(1)|evalvarn(v);
     314     2458183 :   gel(p,2) = gen_0;
     315     2458183 :   gel(p,3) = gen_1; return p;
     316             : }
     317             : /* x^n, assume n >= 0 */
     318             : INLINE GEN
     319     2140031 : pol_xn(long n, long v) {
     320     2140031 :   long i, a = n+2;
     321     2140031 :   GEN p = cgetg(a+1, t_POL);
     322     2140035 :   p[1] = evalsigne(1)|evalvarn(v);
     323     5012733 :   for (i = 2; i < a; i++) gel(p,i) = gen_0;
     324     2140035 :   gel(p,a) = gen_1; return p;
     325             : }
     326             : /* x^n, no assumption on n */
     327             : INLINE GEN
     328         287 : pol_xnall(long n, long v)
     329             : {
     330         287 :   if (n < 0) retmkrfrac(gen_1, pol_xn(-n,v));
     331         280 :   return pol_xn(n, v);
     332             : }
     333             : /* x^n, assume n >= 0 */
     334             : INLINE GEN
     335         210 : polxn_Flx(long n, long sv) {
     336         210 :   long i, a = n+2;
     337         210 :   GEN p = cgetg(a+1, t_VECSMALL);
     338         210 :   p[1] = sv;
     339        1022 :   for (i = 2; i < a; i++) p[i] = 0;
     340         210 :   p[a] = 1; return p;
     341             : }
     342             : INLINE GEN
     343     3108565 : pol_1(long v) {
     344     3108565 :   GEN p = cgetg(3, t_POL);
     345     3108550 :   p[1] = evalsigne(1)|evalvarn(v);
     346     3108550 :   gel(p,2) = gen_1; return p;
     347             : }
     348             : INLINE GEN
     349    31942548 : pol_0(long v)
     350             : {
     351    31942548 :   GEN x = cgetg(2,t_POL);
     352    31942543 :   x[1] = evalvarn(v); return x;
     353             : }
     354             : #define retconst_vec(n,x)\
     355             :   do { long _i, _n = (n);\
     356             :        GEN _v = cgetg(_n+1, t_VEC), _x = (x);\
     357             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     358             :        return _v; } while(0)
     359             : INLINE GEN
     360   238378363 : const_vec(long n, GEN x) { retconst_vec(n, x); }
     361             : #define retconst_col(n,x)\
     362             :   do { long _i, _n = (n);\
     363             :        GEN _v = cgetg(_n+1, t_COL), _x = (x);\
     364             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     365             :        return _v; } while(0)
     366             : INLINE GEN
     367    37090604 : const_col(long n, GEN x) { retconst_col(n, x); }
     368             : INLINE GEN
     369    18236970 : const_vecsmall(long n, long c)
     370             : {
     371             :   long i;
     372    18236970 :   GEN V = cgetg(n+1,t_VECSMALL);
     373   453748828 :   for(i=1;i<=n;i++) V[i] = c;
     374    18237339 :   return V;
     375             : }
     376             : 
     377             : /***   ZERO   ***/
     378             : /* O(p^e) */
     379             : INLINE GEN
     380      366877 : zeropadic(GEN p, long e)
     381             : {
     382      366877 :   GEN y = cgetg(5,t_PADIC);
     383      366877 :   gel(y,4) = gen_0;
     384      366877 :   gel(y,3) = gen_1;
     385      366877 :   gel(y,2) = icopy(p);
     386      366877 :   y[1] = evalvalp(e) | _evalprecp(0);
     387      366877 :   return y;
     388             : }
     389             : INLINE GEN
     390         973 : zeropadic_shallow(GEN p, long e)
     391             : {
     392         973 :   GEN y = cgetg(5,t_PADIC);
     393         973 :   gel(y,4) = gen_0;
     394         973 :   gel(y,3) = gen_1;
     395         973 :   gel(y,2) = p;
     396         973 :   y[1] = evalvalp(e) | _evalprecp(0);
     397         973 :   return y;
     398             : }
     399             : /* O(pol_x(v)^e) */
     400             : INLINE GEN
     401      138446 : zeroser(long v, long e)
     402             : {
     403      138446 :   GEN x = cgetg(2, t_SER);
     404      138446 :   x[1] = evalvalp(e) | evalvarn(v); return x;
     405             : }
     406             : INLINE int
     407     7119170 : ser_isexactzero(GEN x)
     408             : {
     409     7119170 :   if (!signe(x)) switch(lg(x))
     410             :   {
     411      132566 :     case 2: return 1;
     412        1267 :     case 3: return isexactzero(gel(x,2));
     413             :   }
     414     6985337 :   return 0;
     415             : }
     416             : /* 0 * pol_x(v) */
     417             : INLINE GEN
     418    14542355 : zeropol(long v) { return pol_0(v); }
     419             : /* vector(n) */
     420             : INLINE GEN
     421    78089470 : zerocol(long n)
     422             : {
     423    78089470 :   GEN y = cgetg(n+1,t_COL);
     424   543680726 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     425    78089866 :   return y;
     426             : }
     427             : /* vectorv(n) */
     428             : INLINE GEN
     429    19684367 : zerovec(long n)
     430             : {
     431    19684367 :   GEN y = cgetg(n+1,t_VEC);
     432   183232494 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     433    19684356 :   return y;
     434             : }
     435             : /* matrix(m, n) */
     436             : INLINE GEN
     437       91171 : zeromat(long m, long n)
     438             : {
     439       91171 :   GEN y = cgetg(n+1,t_MAT);
     440       91170 :   GEN v = zerocol(m);
     441      291379 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     442       91170 :   return y;
     443             : }
     444             : /* = zero_zx, sv is a evalvarn()*/
     445             : INLINE GEN
     446     1095273 : zero_Flx(long sv) { return pol0_Flx(sv); }
     447             : INLINE GEN
     448    47831370 : zero_Flv(long n)
     449             : {
     450    47831370 :   GEN y = cgetg(n+1,t_VECSMALL);
     451   962553391 :   long i; for (i=1; i<=n; i++) y[i] = 0;
     452    47831661 :   return y;
     453             : }
     454             : /* matrix(m, n) */
     455             : INLINE GEN
     456     2188570 : zero_Flm(long m, long n)
     457             : {
     458     2188570 :   GEN y = cgetg(n+1,t_MAT);
     459     2188569 :   GEN v = zero_Flv(m);
     460    14278649 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     461     2188561 :   return y;
     462             : }
     463             : /* matrix(m, n) */
     464             : INLINE GEN
     465      219270 : zero_Flm_copy(long m, long n)
     466             : {
     467      219270 :   GEN y = cgetg(n+1,t_MAT);
     468     2234028 :   long i; for (i=1; i<=n; i++) gel(y,i) = zero_Flv(m);
     469      219270 :   return y;
     470             : }
     471             : 
     472             : INLINE GEN
     473     2602965 : zero_F2v(long m)
     474             : {
     475     2602965 :   long l = nbits2nlong(m);
     476     2602942 :   GEN v  = zero_Flv(l+1);
     477     2602944 :   v[1] = m;
     478     2602944 :   return v;
     479             : }
     480             : 
     481             : INLINE GEN
     482           0 : zero_F2m(long m, long n)
     483             : {
     484             :   long i;
     485           0 :   GEN M = cgetg(n+1, t_MAT);
     486           0 :   GEN v = zero_F2v(m);
     487           0 :   for (i = 1; i <= n; i++)
     488           0 :     gel(M,i) = v;
     489           0 :   return M;
     490             : }
     491             : 
     492             : 
     493             : INLINE GEN
     494      804494 : zero_F2m_copy(long m, long n)
     495             : {
     496             :   long i;
     497      804494 :   GEN M = cgetg(n+1, t_MAT);
     498     1881467 :   for (i = 1; i <= n; i++)
     499     1076976 :     gel(M,i)= zero_F2v(m);
     500      804491 :   return M;
     501             : }
     502             : 
     503             : /* matrix(m, n) */
     504             : INLINE GEN
     505     8105053 : zeromatcopy(long m, long n)
     506             : {
     507     8105053 :   GEN y = cgetg(n+1,t_MAT);
     508    34624086 :   long i; for (i=1; i<=n; i++) gel(y,i) = zerocol(m);
     509     8105082 :   return y;
     510             : }
     511             : 
     512             : INLINE GEN
     513       18235 : zerovec_block(long len)
     514             : {
     515             :   long i;
     516       18235 :   GEN blk = cgetg_block(len + 1, t_VEC);
     517      601755 :   for (i = 1; i <= len; ++i)
     518      583520 :     gel(blk, i) = gen_0;
     519       18235 :   return blk;
     520             : }
     521             : 
     522             : /* i-th vector in the standard basis */
     523             : INLINE GEN
     524     4060756 : col_ei(long n, long i) { GEN e = zerocol(n); gel(e,i) = gen_1; return e; }
     525             : INLINE GEN
     526     1250218 : vec_ei(long n, long i) { GEN e = zerovec(n); gel(e,i) = gen_1; return e; }
     527             : INLINE GEN
     528          42 : F2v_ei(long n, long i) { GEN e = zero_F2v(n); F2v_set(e,i); return e; }
     529             : INLINE GEN
     530       66220 : vecsmall_ei(long n, long i) { GEN e = zero_zv(n); e[i] = 1; return e; }
     531             : INLINE GEN
     532     1190664 : Rg_col_ei(GEN x, long n, long i) { GEN e = zerocol(n); gel(e,i) = x; return e; }
     533             : 
     534             : INLINE GEN
     535    23569370 : shallowcopy(GEN x)
     536    23569370 : { return typ(x) == t_MAT ? RgM_shallowcopy(x): leafcopy(x); }
     537             : 
     538             : /* routines for naive growarrays */
     539             : INLINE GEN
     540    13283595 : vectrunc_init(long l)
     541             : {
     542    13283595 :   GEN z = new_chunk(l);
     543    13283609 :   z[0] = evaltyp(t_VEC) | _evallg(1); return z;
     544             : }
     545             : INLINE GEN
     546      348180 : coltrunc_init(long l)
     547             : {
     548      348180 :   GEN z = new_chunk(l);
     549      348180 :   z[0] = evaltyp(t_COL) | _evallg(1); return z;
     550             : }
     551             : INLINE void
     552   355439634 : lg_increase(GEN x) { x[0]++; }
     553             : INLINE void
     554    54127611 : vectrunc_append(GEN x, GEN t) { gel(x, lg(x)) = t; lg_increase(x); }
     555             : INLINE void
     556       10864 : vectrunc_append_batch(GEN x, GEN y)
     557             : {
     558       10864 :   long i, l = lg(x), ly = lg(y);
     559       10864 :   GEN z = x + l-1;
     560       36358 :   for (i = 1; i < ly; i++) gel(z,i) = gel(y,i);
     561       10864 :   setlg(x, l+ly-1);
     562       10864 : }
     563             : INLINE GEN
     564   126195602 : vecsmalltrunc_init(long l)
     565             : {
     566   126195602 :   GEN z = new_chunk(l);
     567   126123460 :   z[0] = evaltyp(t_VECSMALL) | _evallg(1); return z;
     568             : }
     569             : INLINE void
     570    35183330 : vecsmalltrunc_append(GEN x, long t) { x[ lg(x) ] = t; lg_increase(x); }
     571             : 
     572             : /*******************************************************************/
     573             : /*                                                                 */
     574             : /*                    STRING HASH FUNCTIONS                        */
     575             : /*                                                                 */
     576             : /*******************************************************************/
     577             : INLINE ulong
     578     2295680 : hash_str(const char *str)
     579             : {
     580     2295680 :   ulong hash = 5381UL, c;
     581    23521058 :   while ( (c = (ulong)*str++) )
     582    21225378 :     hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
     583     2295680 :   return hash;
     584             : }
     585             : INLINE ulong
     586   136452912 : hash_str_len(const char *str, long len)
     587             : {
     588   136452912 :   ulong hash = 5381UL;
     589             :   long i;
     590   568075687 :   for (i = 0; i < len; i++)
     591             :   {
     592   431622775 :     ulong c = (ulong)*str++;
     593   431622775 :     hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
     594             :   }
     595   136452912 :   return hash;
     596             : }
     597             : 
     598             : /*******************************************************************/
     599             : /*                                                                 */
     600             : /*                        VEC / COL / VECSMALL                     */
     601             : /*                                                                 */
     602             : /*******************************************************************/
     603             : /* shallow*/
     604             : INLINE GEN
     605           0 : vec_shorten(GEN v, long n)
     606             : {
     607             :   long i;
     608           0 :   GEN V = cgetg(n+1,t_VEC);
     609           0 :   for(i=1;i<=n;i++) gel(V,i) = gel(v,i);
     610           0 :   return V;
     611             : }
     612             : /* shallow*/
     613             : INLINE GEN
     614       17674 : vec_lengthen(GEN v, long n)
     615             : {
     616             :   long i;
     617       17674 :   long l=lg(v);
     618       17674 :   GEN V = cgetg(n+1,t_VEC);
     619     7008650 :   for(i=1;i<l;i++) gel(V,i) = gel(v,i);
     620       17674 :   return V;
     621             : }
     622             : /* shallow*/
     623             : INLINE GEN
     624     2538224 : vec_append(GEN V, GEN s)
     625             : {
     626     2538224 :   long i, l2 = lg(V);
     627     2538224 :   GEN res = cgetg(l2+1, typ(V));
     628     6160170 :   for (i = 1; i < l2; ++i) gel(res, i) = gel(V,i);
     629     2538227 :   gel(res,l2) = s; return res;
     630             : }
     631             : /* shallow*/
     632             : INLINE GEN
     633      270076 : vec_prepend(GEN v, GEN s)
     634             : {
     635      270076 :   long i, l = lg(v);
     636      270076 :   GEN w = cgetg(l+1, typ(v));
     637      270082 :   gel(w,1) = s;
     638      529856 :   for (i = 2; i <= l; ++i) gel(w,i) = gel(v,i-1);
     639      270082 :   return w;
     640             : }
     641             : /* shallow*/
     642             : INLINE GEN
     643           0 : vec_setconst(GEN v, GEN x)
     644             : {
     645           0 :   long i, l = lg(v);
     646           0 :   for (i = 1; i < l; i++) gel(v,i) = x;
     647           0 :   return v;
     648             : }
     649             : INLINE GEN
     650       51650 : vecsmall_shorten(GEN v, long n)
     651             : {
     652             :   long i;
     653       51650 :   GEN V = cgetg(n+1,t_VECSMALL);
     654      628295 :   for(i=1;i<=n;i++) V[i] = v[i];
     655       51650 :   return V;
     656             : }
     657             : INLINE GEN
     658           0 : vecsmall_lengthen(GEN v, long n)
     659             : {
     660           0 :   long i, l = lg(v);
     661           0 :   GEN V = cgetg(n+1,t_VECSMALL);
     662           0 :   for(i=1;i<l;i++) V[i] = v[i];
     663           0 :   return V;
     664             : }
     665             : 
     666             : INLINE GEN
     667     4220737 : vec_to_vecsmall(GEN x)
     668    19510768 : { pari_APPLY_long(itos(gel(x,i))) }
     669             : INLINE GEN
     670      471310 : vecsmall_to_vec(GEN x)
     671     6138923 : { pari_APPLY_type(t_VEC, stoi(x[i])) }
     672             : INLINE GEN
     673        2457 : vecsmall_to_vec_inplace(GEN z)
     674             : {
     675        2457 :   long i, l = lg(z);
     676       76587 :   for (i=1; i<l; i++) gel(z,i) = stoi(z[i]);
     677        2457 :   settyp(z, t_VEC); return z;
     678             : }
     679             : INLINE GEN
     680     6578206 : vecsmall_to_col(GEN x)
     681    59184790 : { pari_APPLY_type(t_COL, stoi(x[i])) }
     682             : 
     683             : INLINE int
     684     6973952 : vecsmall_lexcmp(GEN x, GEN y)
     685             : {
     686             :   long lx,ly,l,i;
     687     6973952 :   lx = lg(x);
     688     6973952 :   ly = lg(y); l = minss(lx,ly);
     689    30387665 :   for (i=1; i<l; i++)
     690    28769406 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     691     1618259 :   if (lx == ly) return 0;
     692       30578 :   return (lx < ly)? -1 : 1;
     693             : }
     694             : 
     695             : INLINE int
     696   109454527 : vecsmall_prefixcmp(GEN x, GEN y)
     697             : {
     698   109454527 :   long i, lx = lg(x), ly = lg(y), l = minss(lx,ly);
     699   578736592 :   for (i=1; i<l; i++)
     700   556596383 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     701    22140209 :   return 0;
     702             : }
     703             : 
     704             : /*Can be used on t_VEC, but coeffs not gcopy-ed*/
     705             : INLINE GEN
     706      179711 : vecsmall_prepend(GEN V, long s)
     707             : {
     708      179711 :   long i, l2 = lg(V);
     709      179711 :   GEN res = cgetg(l2+1, typ(V));
     710      179711 :   res[1] = s;
     711      602385 :   for (i = 2; i <= l2; ++i) res[i] = V[i - 1];
     712      179711 :   return res;
     713             : }
     714             : 
     715             : INLINE GEN
     716     3508773 : vecsmall_append(GEN V, long s)
     717             : {
     718     3508773 :   long i, l2 = lg(V);
     719     3508773 :   GEN res = cgetg(l2+1, t_VECSMALL);
     720     5256719 :   for (i = 1; i < l2; ++i) res[i] = V[i];
     721     3508773 :   res[l2] = s; return res;
     722             : }
     723             : 
     724             : INLINE GEN
     725     1605809 : vecsmall_concat(GEN u, GEN v)
     726             : {
     727     1605809 :   long i, l1 = lg(u)-1, l2 = lg(v)-1;
     728     1605809 :   GEN res = cgetg(l1+l2+1, t_VECSMALL);
     729    13287100 :   for (i = 1; i <= l1; ++i) res[i]    = u[i];
     730    16563764 :   for (i = 1; i <= l2; ++i) res[i+l1] = v[i];
     731     1605809 :   return res;
     732             : }
     733             : 
     734             : /* return the number of indices where u and v are equal */
     735             : INLINE long
     736           0 : vecsmall_coincidence(GEN u, GEN v)
     737             : {
     738           0 :   long i, s = 0, l = minss(lg(u),lg(v));
     739           0 :   for(i=1; i<l; i++)
     740           0 :     if(u[i] == v[i]) s++;
     741           0 :   return s;
     742             : }
     743             : 
     744             : /* returns the first index i<=n such that x=v[i] if it exists, 0 otherwise */
     745             : INLINE long
     746          42 : vecsmall_isin(GEN v, long x)
     747             : {
     748          42 :   long i, l = lg(v);
     749          63 :   for (i = 1; i < l; i++)
     750          42 :     if (v[i] == x) return i;
     751          21 :   return 0;
     752             : }
     753             : 
     754             : INLINE long
     755          84 : vecsmall_pack(GEN V, long base, long mod)
     756             : {
     757          84 :   long i, s = 0;
     758         273 :   for(i=1; i<lg(V); i++) s = (base*s + V[i]) % mod;
     759          84 :   return s;
     760             : }
     761             : 
     762             : INLINE long
     763          14 : vecsmall_indexmax(GEN x)
     764             : {
     765          14 :   long i, i0 = 1, t = x[1], lx = lg(x);
     766          56 :   for (i=2; i<lx; i++)
     767          42 :     if (x[i] > t) t = x[i0=i];
     768          14 :   return i0;
     769             : }
     770             : 
     771             : INLINE long
     772      364152 : vecsmall_max(GEN x)
     773             : {
     774      364152 :   long i, t = x[1], lx = lg(x);
     775      889587 :   for (i=2; i<lx; i++)
     776      525435 :     if (x[i] > t) t = x[i];
     777      364152 :   return t;
     778             : }
     779             : 
     780             : INLINE long
     781          14 : vecsmall_indexmin(GEN x)
     782             : {
     783          14 :   long i, i0 = 1, t = x[1], lx =lg(x);
     784          56 :   for (i=2; i<lx; i++)
     785          42 :     if (x[i] < t) t = x[i0=i];
     786          14 :   return i0;
     787             : }
     788             : 
     789             : INLINE long
     790        1421 : vecsmall_min(GEN x)
     791             : {
     792        1421 :   long i, t = x[1], lx =lg(x);
     793        9947 :   for (i=2; i<lx; i++)
     794        8526 :     if (x[i] < t) t = x[i];
     795        1421 :   return t;
     796             : }
     797             : 
     798             : INLINE int
     799    10880785 : ZV_isscalar(GEN x)
     800             : {
     801    10880785 :   long l = lg(x);
     802    26512442 :   while (--l > 1)
     803    24785816 :     if (signe(gel(x, l))) return 0;
     804     1726626 :   return 1;
     805             : }
     806             : INLINE int
     807    34527145 : QV_isscalar(GEN x)
     808             : {
     809    34527145 :   long lx = lg(x),i;
     810    39450699 :   for (i=2; i<lx; i++)
     811    38249366 :     if (!isintzero(gel(x, i))) return 0;
     812     1201333 :   return 1;
     813             : }
     814             : INLINE int
     815        9578 : RgV_isscalar(GEN x)
     816             : {
     817        9578 :   long lx = lg(x),i;
     818       10306 :   for (i=2; i<lx; i++)
     819       10264 :     if (!gequal0(gel(x, i))) return 0;
     820          42 :   return 1;
     821             : }
     822             : INLINE int
     823           0 : RgX_isscalar(GEN x)
     824             : {
     825             :   long i;
     826           0 :   for (i=lg(x)-1; i>2; i--)
     827           0 :     if (!gequal0(gel(x, i))) return 0;
     828           0 :   return 1;
     829             : }
     830             : INLINE long
     831    25357229 : RgX_equal_var(GEN x, GEN y) { return varn(x) == varn(y) && RgX_equal(x,y); }
     832             : INLINE GEN
     833         140 : RgX_to_RgV(GEN x, long N) { x = RgX_to_RgC(x, N); settyp(x, t_VEC); return x; }
     834             : 
     835             : INLINE int
     836       63651 : RgX_is_rational(GEN x)
     837             : {
     838             :   long i;
     839      296284 :   for (i = lg(x)-1; i > 1; i--)
     840      281048 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     841       15236 :   return 1;
     842             : }
     843             : INLINE int
     844    10984813 : RgX_is_ZX(GEN x)
     845             : {
     846             :   long i;
     847    46881314 :   for (i = lg(x)-1; i > 1; i--)
     848    35953969 :     if (typ(gel(x,i)) != t_INT) return 0;
     849    10927345 :   return 1;
     850             : }
     851             : INLINE int
     852      333031 : RgX_is_QX(GEN x)
     853             : {
     854      333031 :   long k = lg(x)-1;
     855     1230523 :   for ( ; k>1; k--)
     856      897772 :     if (!is_rational_t(typ(gel(x,k)))) return 0;
     857      332751 :   return 1;
     858             : }
     859             : INLINE int
     860    17172521 : RgX_is_monomial(GEN x)
     861             : {
     862             :   long i;
     863    17172521 :   if (!signe(x)) return 0;
     864    35512387 :   for (i=lg(x)-2; i>1; i--)
     865    18397179 :     if (!isexactzero(gel(x,i))) return 0;
     866    17115208 :   return 1;
     867             : }
     868             : INLINE int
     869    30040345 : RgV_is_ZV(GEN x)
     870             : {
     871             :   long i;
     872   120096148 :   for (i = lg(x)-1; i > 0; i--)
     873    90084629 :     if (typ(gel(x,i)) != t_INT) return 0;
     874    30011519 :   return 1;
     875             : }
     876             : INLINE int
     877      107856 : RgV_is_QV(GEN x)
     878             : {
     879             :   long i;
     880      515960 :   for (i = lg(x)-1; i > 0; i--)
     881      411026 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     882      104934 :   return 1;
     883             : }
     884             : INLINE long
     885      194208 : RgV_isin_i(GEN v, GEN x, long n)
     886             : {
     887             :   long i;
     888     3765090 :   for (i = 1; i <= n; i++)
     889     3764558 :     if (gequal(gel(v,i), x)) return i;
     890         532 :   return 0;
     891             : }
     892             : INLINE long
     893      194208 : RgV_isin(GEN v, GEN x) { return RgV_isin_i(v, x, lg(v)-1); }
     894             : 
     895             : /********************************************************************/
     896             : /**                                                                **/
     897             : /**            Dynamic arrays implementation                       **/
     898             : /**                                                                **/
     899             : /********************************************************************/
     900             : INLINE void **
     901   994248097 : pari_stack_base(pari_stack *s) { return s->data; }
     902             : 
     903             : INLINE void
     904     3526149 : pari_stack_init(pari_stack *s, size_t size, void **data)
     905             : {
     906     3526149 :   s->data = data;
     907     3526149 :   *data = NULL;
     908     3526149 :   s->n = 0;
     909     3526149 :   s->alloc = 0;
     910     3526149 :   s->size = size;
     911     3526149 : }
     912             : 
     913             : INLINE void
     914   990958009 : pari_stack_alloc(pari_stack *s, long nb)
     915             : {
     916   990958009 :   void **sdat = pari_stack_base(s);
     917   990952070 :   long alloc = s->alloc;
     918   990952070 :   if (s->n+nb <= alloc) return;
     919     1363016 :   if (!alloc)
     920     1266661 :     alloc = nb;
     921             :   else
     922             :   {
     923      193304 :     while (s->n+nb > alloc) alloc <<= 1;
     924             :   }
     925     1363016 :   pari_realloc_ip(sdat,alloc*s->size);
     926     1365686 :   s->alloc = alloc;
     927             : }
     928             : 
     929             : INLINE long
     930   905476296 : pari_stack_new(pari_stack *s) { pari_stack_alloc(s, 1); return s->n++; }
     931             : 
     932             : INLINE void
     933     3291991 : pari_stack_delete(pari_stack *s)
     934             : {
     935     3291991 :   void **sdat = pari_stack_base(s);
     936     3287557 :   if (*sdat) pari_free(*sdat);
     937     3303289 : }
     938             : 
     939             : INLINE void
     940        5228 : pari_stack_pushp(pari_stack *s, void *u)
     941             : {
     942        5228 :   long n = pari_stack_new(s);
     943        5228 :   void **sdat =(void**) *pari_stack_base(s);
     944        5228 :   sdat[n] = u;
     945        5228 : }
     946             : 
     947             : /*******************************************************************/
     948             : /*                                                                 */
     949             : /*                            EXTRACT                              */
     950             : /*                                                                 */
     951             : /*******************************************************************/
     952             : INLINE GEN
     953   559727947 : vecslice(GEN A, long y1, long y2)
     954             : {
     955   559727947 :   long i,lB = y2 - y1 + 2;
     956   559727947 :   GEN B = cgetg(lB, typ(A));
     957  2511520120 :   for (i=1; i<lB; i++) B[i] = A[y1-1+i];
     958   559721827 :   return B;
     959             : }
     960             : INLINE GEN
     961     2027271 : vecslicepermute(GEN A, GEN p, long y1, long y2)
     962             : {
     963     2027271 :   long i,lB = y2 - y1 + 2;
     964     2027271 :   GEN B = cgetg(lB, typ(A));
     965    35416107 :   for (i=1; i<lB; i++) B[i] = A[p[y1-1+i]];
     966     2027260 :   return B;
     967             : }
     968             : /* rowslice(rowpermute(A,p), x1, x2) */
     969             : INLINE GEN
     970      193312 : rowslicepermute(GEN x, GEN p, long j1, long j2)
     971      837708 : { pari_APPLY_same(vecslicepermute(gel(x,i),p,j1,j2)) }
     972             : 
     973             : INLINE GEN
     974    57861724 : rowslice(GEN x, long j1, long j2)
     975   569314923 : { pari_APPLY_same(vecslice(gel(x,i), j1, j2)) }
     976             : 
     977             : INLINE GEN
     978     8589505 : matslice(GEN A, long x1, long x2, long y1, long y2)
     979     8589505 : { return rowslice(vecslice(A, y1, y2), x1, x2); }
     980             : 
     981             : /* shallow, remove coeff of index j */
     982             : INLINE GEN
     983         210 : rowsplice(GEN x, long j)
     984        1036 : { pari_APPLY_same(vecsplice(gel(x,i), j)) }
     985             : 
     986             : /* shallow, remove coeff of index j */
     987             : INLINE GEN
     988      349945 : vecsplice(GEN a, long j)
     989             : {
     990      349945 :   long i, k, l = lg(a);
     991             :   GEN b;
     992      349945 :   if (l == 1) pari_err(e_MISC, "incorrect component in vecsplice");
     993      349945 :   b = cgetg(l-1, typ(a));
     994     1471460 :   for (i = k = 1; i < l; i++)
     995     1121514 :     if (i != j) gel(b, k++) = gel(a,i);
     996      349946 :   return b;
     997             : }
     998             : /* shallow */
     999             : INLINE GEN
    1000        1036 : RgM_minor(GEN a, long i, long j)
    1001             : {
    1002        1036 :   GEN b = vecsplice(a, j);
    1003        1036 :   long k, l = lg(b);
    1004        4242 :   for (k = 1; k < l; k++) gel(b,k) = vecsplice(gel(b,k), i);
    1005        1036 :   return b;
    1006             : }
    1007             : 
    1008             : /* A[x0,] */
    1009             : INLINE GEN
    1010      418995 : row(GEN x, long j)
    1011     4154441 : { pari_APPLY_type(t_VEC, gcoeff(x, j, i)) }
    1012             : INLINE GEN
    1013     9202760 : Flm_row(GEN x, long j)
    1014   235616228 : { pari_APPLY_ulong((ulong)coeff(x, j, i)) }
    1015             : /* A[x0,] */
    1016             : INLINE GEN
    1017      204834 : rowcopy(GEN x, long j)
    1018     2097809 : { pari_APPLY_type(t_VEC, gcopy(gcoeff(x, j, i))) }
    1019             : /* A[x0, x1..x2] */
    1020             : INLINE GEN
    1021         987 : row_i(GEN A, long x0, long x1, long x2)
    1022             : {
    1023         987 :   long i, lB = x2 - x1 + 2;
    1024         987 :   GEN B  = cgetg(lB, t_VEC);
    1025        2989 :   for (i=x1; i<=x2; i++) gel(B, i) = gcoeff(A, x0, i);
    1026         987 :   return B;
    1027             : }
    1028             : 
    1029             : INLINE GEN
    1030     6101792 : vecreverse(GEN A)
    1031             : {
    1032             :   long i, l;
    1033     6101792 :   GEN B = cgetg_copy(A, &l);
    1034    14807657 :   for (i=1; i<l; i++) gel(B, i) = gel(A, l-i);
    1035     6101792 :   return B;
    1036             : }
    1037             : 
    1038             : INLINE GEN
    1039        2954 : vecsmall_reverse(GEN A)
    1040             : {
    1041             :   long i, l;
    1042        2954 :   GEN B = cgetg_copy(A, &l);
    1043       11648 :   for (i=1; i<l; i++) B[i] = A[l-i];
    1044        2954 :   return B;
    1045             : }
    1046             : 
    1047             : INLINE void
    1048         449 : vecreverse_inplace(GEN y)
    1049             : {
    1050         449 :   long l = lg(y), lim = l>>1, i;
    1051        1704 :   for (i = 1; i <= lim; i++)
    1052             :   {
    1053        1255 :     GEN z = gel(y,i);
    1054        1255 :     gel(y,i)    = gel(y,l-i);
    1055        1255 :     gel(y,l-i) = z;
    1056             :   }
    1057         449 : }
    1058             : 
    1059             : INLINE GEN
    1060    70164952 : vecsmallpermute(GEN A, GEN p) { return perm_mul(A, p); }
    1061             : 
    1062             : INLINE GEN
    1063    11262279 : vecpermute(GEN A, GEN x)
    1064   123927873 : { pari_APPLY_type(typ(A), gel(A, x[i])) }
    1065             : 
    1066             : INLINE GEN
    1067     8420734 : rowpermute(GEN x, GEN p)
    1068    79619196 : { pari_APPLY_same(typ(gel(x,i)) == t_VECSMALL ? vecsmallpermute(gel(x, i), p)
    1069             :                                               : vecpermute(gel(x, i), p))
    1070             : }
    1071             : /*******************************************************************/
    1072             : /*                                                                 */
    1073             : /*                          PERMUTATIONS                           */
    1074             : /*                                                                 */
    1075             : /*******************************************************************/
    1076             : INLINE GEN
    1077     1773617 : identity_zv(long n)
    1078             : {
    1079     1773617 :   GEN v = cgetg(n+1, t_VECSMALL);
    1080             :   long i;
    1081    24258744 :   for (i = 1; i <= n; i++) v[i] = i;
    1082     1773605 :   return v;
    1083             : }
    1084             : INLINE GEN
    1085        4179 : identity_ZV(long n)
    1086             : {
    1087        4179 :   GEN v = cgetg(n+1, t_VEC);
    1088             :   long i;
    1089       51121 :   for (i = 1; i <= n; i++) gel(v,i) = utoipos(i);
    1090        4179 :   return v;
    1091             : }
    1092             : /* identity permutation */
    1093             : INLINE GEN
    1094     1749522 : identity_perm(long n) { return identity_zv(n); }
    1095             : 
    1096             : /* assume d <= n */
    1097             : INLINE GEN
    1098       98483 : cyclic_perm(long n, long d)
    1099             : {
    1100       98483 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1101             :   long i;
    1102      504098 :   for (i = 1; i <= n-d; i++) perm[i] = i+d;
    1103      225029 :   for (     ; i <= n;   i++) perm[i] = i-n+d;
    1104       98483 :   return perm;
    1105             : }
    1106             : 
    1107             : /* Multiply (compose) two permutations */
    1108             : INLINE GEN
    1109    72213466 : perm_mul(GEN s, GEN x)
    1110   959393538 : { pari_APPLY_long(s[x[i]]) }
    1111             : 
    1112             : INLINE GEN
    1113         749 : perm_sqr(GEN x)
    1114       18725 : { pari_APPLY_long(x[x[i]]) }
    1115             : 
    1116             : /* Compute the inverse (reciprocal) of a permutation. */
    1117             : INLINE GEN
    1118     2282545 : perm_inv(GEN x)
    1119             : {
    1120             :   long i, lx;
    1121     2282545 :   GEN y = cgetg_copy(x, &lx);
    1122    34382532 :   for (i=1; i<lx; i++) y[ x[i] ] = i;
    1123     2282541 :   return y;
    1124             : }
    1125             : /* Return s*t*s^-1 */
    1126             : INLINE GEN
    1127      417816 : perm_conj(GEN s, GEN t)
    1128             : {
    1129             :   long i, l;
    1130      417816 :   GEN v = cgetg_copy(s, &l);
    1131     6853658 :   for (i = 1; i < l; i++) v[ s[i] ] = s[ t[i] ];
    1132      417816 :   return v;
    1133             : }
    1134             : 
    1135             : INLINE void
    1136   496105015 : pari_free(void *pointer)
    1137             : {
    1138   496105015 :   BLOCK_SIGINT_START;
    1139   496164906 :   free(pointer);
    1140   496164906 :   BLOCK_SIGINT_END;
    1141   496166588 : }
    1142             : INLINE void*
    1143   717884694 : pari_malloc(size_t size)
    1144             : {
    1145   717884694 :   if (size)
    1146             :   {
    1147             :     char *tmp;
    1148   717886865 :     BLOCK_SIGINT_START;
    1149   717962998 :     tmp = (char*)malloc(size);
    1150   717962998 :     BLOCK_SIGINT_END;
    1151   717967151 :     if (!tmp) pari_err(e_MEM);
    1152   717976446 :     return tmp;
    1153             :   }
    1154           0 :   return NULL;
    1155             : }
    1156             : INLINE void*
    1157        1689 : pari_realloc(void *pointer, size_t size)
    1158             : {
    1159             :   char *tmp;
    1160             : 
    1161        1689 :   BLOCK_SIGINT_START;
    1162        1689 :   if (!pointer) tmp = (char *) malloc(size);
    1163        1689 :   else tmp = (char *) realloc(pointer,size);
    1164        1689 :   BLOCK_SIGINT_END;
    1165        1689 :   if (!tmp) pari_err(e_MEM);
    1166        1689 :   return tmp;
    1167             : }
    1168             : INLINE void
    1169     1425994 : pari_realloc_ip(void **pointer, size_t size)
    1170             : {
    1171             :   char *tmp;
    1172     1425994 :   BLOCK_SIGINT_START;
    1173     1424521 :   if (!*pointer) tmp = (char *) malloc(size);
    1174       97558 :   else tmp = (char *) realloc(*pointer,size);
    1175     1424521 :   if (!tmp) pari_err(e_MEM);
    1176     1424521 :   *pointer = tmp;
    1177     1424521 :   BLOCK_SIGINT_END;
    1178     1420132 : }
    1179             : 
    1180             : INLINE void*
    1181       40602 : pari_calloc(size_t size)
    1182             : {
    1183       40602 :   void *t = pari_malloc(size);
    1184       40602 :   memset(t, 0, size); return t;
    1185             : }
    1186             : INLINE GEN
    1187        8001 : cgetalloc(long t, size_t l)
    1188             : { /* evallg may raise e_OVERFLOW, which would leak x */
    1189        8001 :   ulong x0 = evaltyp(t) | evallg(l);
    1190        8001 :   GEN x = (GEN)pari_malloc(l * sizeof(long));
    1191        8001 :   x[0] = x0; return x;
    1192             : }
    1193             : 
    1194             : /*******************************************************************/
    1195             : /*                                                                 */
    1196             : /*                       GARBAGE COLLECTION                        */
    1197             : /*                                                                 */
    1198             : /*******************************************************************/
    1199             : /* copy integer x as if we had set_avma(av) */
    1200             : INLINE GEN
    1201  6072431926 : icopy_avma(GEN x, pari_sp av)
    1202             : {
    1203  6072431926 :   long i = lgefint(x), lx = i;
    1204  6072431926 :   GEN y = ((GEN)av) - i;
    1205 33024117896 :   while (--i > 0) y[i] = x[i];
    1206  6072431926 :   y[0] = evaltyp(t_INT)|evallg(lx);
    1207  6075718729 :   return y;
    1208             : }
    1209             : /* copy leaf x as if we had set_avma(av) */
    1210             : INLINE GEN
    1211   445890051 : leafcopy_avma(GEN x, pari_sp av)
    1212             : {
    1213   445890051 :   long i = lg(x);
    1214   445890051 :   GEN y = ((GEN)av) - i;
    1215  2912762216 :   while (--i > 0) y[i] = x[i];
    1216   445890051 :   y[0] = x[0] & (~CLONEBIT);
    1217   445890051 :   return y;
    1218             : }
    1219             : INLINE GEN
    1220   891215817 : gerepileuptoleaf(pari_sp av, GEN x)
    1221             : {
    1222             :   long lx;
    1223             :   GEN q;
    1224             : 
    1225   891215817 :   if (!isonstack(x) || (GEN)av<=x) return gc_const(av,x);
    1226   890643679 :   lx = lg(x);
    1227   890643679 :   q = ((GEN)av) - lx;
    1228   890643679 :   set_avma((pari_sp)q);
    1229  9078526801 :   while (--lx >= 0) q[lx] = x[lx];
    1230   890651244 :   return q;
    1231             : }
    1232             : INLINE GEN
    1233  2594106605 : gerepileuptoint(pari_sp av, GEN x)
    1234             : {
    1235  2594106605 :   if (!isonstack(x) || (GEN)av<=x) return gc_const(av,x);
    1236  2254926884 :   set_avma((pari_sp)icopy_avma(x, av));
    1237  2257491856 :   return (GEN)avma;
    1238             : }
    1239             : INLINE GEN
    1240  1327758846 : gerepileupto(pari_sp av, GEN x)
    1241             : {
    1242  1327758846 :   if (!isonstack(x) || (GEN)av<=x) return gc_const(av,x);
    1243  1198754919 :   switch(typ(x))
    1244             :   { /* non-default = !is_recursive_t(tq) */
    1245   318401008 :     case t_INT: return gerepileuptoint(av, x);
    1246   236551833 :     case t_REAL:
    1247             :     case t_STR:
    1248   236551833 :     case t_VECSMALL: return gerepileuptoleaf(av,x);
    1249   643803416 :     default:
    1250             :       /* NB: x+i --> ((long)x) + i*sizeof(long) */
    1251   643803416 :       return gerepile(av, (pari_sp) (x+lg(x)), x);
    1252             :   }
    1253             : }
    1254             : 
    1255             : /* gerepileupto(av, gcopy(x)) */
    1256             : INLINE GEN
    1257   167861249 : gerepilecopy(pari_sp av, GEN x)
    1258             : {
    1259   167861249 :   if (is_recursive_t(typ(x)))
    1260             :   {
    1261   161704033 :     GENbin *p = copy_bin(x);
    1262   161717045 :     set_avma(av); return bin_copy(p);
    1263             :   }
    1264             :   else
    1265             :   {
    1266     6158007 :     set_avma(av);
    1267     6158029 :     if (x < (GEN)av) {
    1268     4427854 :       if (x < (GEN)pari_mainstack->bot) new_chunk(lg(x));
    1269     4427861 :       x = leafcopy_avma(x, av);
    1270     4427889 :       set_avma((pari_sp)x);
    1271             :     } else
    1272     1730175 :       x = leafcopy(x);
    1273     6158062 :     return x;
    1274             :   }
    1275             : }
    1276             : 
    1277             : INLINE void
    1278    27886197 : guncloneNULL(GEN x) { if (x) gunclone(x); }
    1279             : INLINE void
    1280      446734 : guncloneNULL_deep(GEN x) { if (x) gunclone_deep(x); }
    1281             : 
    1282             : /* Takes an array of pointers to GENs, of length n. Copies all
    1283             :  * objects to contiguous locations and cleans up the stack between
    1284             :  * av and avma. */
    1285             : INLINE void
    1286      936464 : gerepilemany(pari_sp av, GEN* gptr[], int n)
    1287             : {
    1288             :   int i;
    1289     3737656 :   for (i=0; i<n; i++) *gptr[i] = (GEN)copy_bin(*gptr[i]);
    1290      935995 :   set_avma(av);
    1291     3738377 :   for (i=0; i<n; i++) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1292      936754 : }
    1293             : 
    1294             : INLINE void
    1295   125411856 : gerepileall(pari_sp av, int n, ...)
    1296             : {
    1297             :   int i;
    1298   125411856 :   va_list a; va_start(a, n);
    1299   125411856 :   if (n < 10)
    1300             :   {
    1301             :     GEN *gptr[10];
    1302   416222507 :     for (i=0; i<n; i++)
    1303   290809998 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1304   125412509 :     set_avma(av);
    1305   416223422 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1306             : 
    1307             :   }
    1308             :   else
    1309             :   {
    1310           0 :     GEN **gptr = (GEN**)  pari_malloc(n*sizeof(GEN*));
    1311           0 :     for (i=0; i<n; i++)
    1312           0 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1313           0 :     set_avma(av);
    1314           0 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1315           0 :     pari_free(gptr);
    1316             :   }
    1317   125413378 :   va_end(a);
    1318   125413378 : }
    1319             : 
    1320             : INLINE void
    1321     2745562 : gerepilecoeffs(pari_sp av, GEN x, int n)
    1322             : {
    1323             :   int i;
    1324    32466923 :   for (i=0; i<n; i++) gel(x,i) = (GEN)copy_bin(gel(x,i));
    1325     2746032 :   set_avma(av);
    1326    32468317 :   for (i=0; i<n; i++) gel(x,i) = bin_copy((GENbin*)x[i]);
    1327     2745729 : }
    1328             : 
    1329             : /* p from copy_bin. Copy p->x back to stack, then destroy p */
    1330             : INLINE GEN
    1331   485105576 : bin_copy(GENbin *p)
    1332             : {
    1333             :   GEN x, y, base;
    1334             :   long dx, len;
    1335             : 
    1336   485105576 :   x   = p->x; if (!x) { pari_free(p); return gen_0; }
    1337   449848568 :   len = p->len;
    1338   449848568 :   base= p->base; dx = x - base;
    1339   449848568 :   y = (GEN)memcpy((void*)new_chunk(len), (void*)GENbinbase(p), len*sizeof(long));
    1340   449845927 :   y += dx;
    1341   449845927 :   p->rebase(y, ((ulong)y-(ulong)x));
    1342   449843249 :   pari_free(p); return y;
    1343             : }
    1344             : 
    1345             : INLINE GEN
    1346   934951884 : GENbinbase(GENbin *p) { return (GEN)(p + 1); }
    1347             : 
    1348             : INLINE void
    1349    93266342 : cgiv(GEN x)
    1350             : {
    1351    93266342 :   pari_sp av = (pari_sp)(x+lg(x));
    1352    93266342 :   if (isonstack((GEN)av)) set_avma(av);
    1353    93267321 : }
    1354             : 
    1355             : INLINE void
    1356     6696465 : killblock(GEN x) { gunclone(x); }
    1357             : 
    1358             : INLINE int
    1359   247468042 : is_universal_constant(GEN x) { return (x >= gen_0 && x <= ghalf); }
    1360             : 
    1361             : /*******************************************************************/
    1362             : /*                                                                 */
    1363             : /*                    CONVERSION / ASSIGNMENT                      */
    1364             : /*                                                                 */
    1365             : /*******************************************************************/
    1366             : /* z is a type which may be a t_COMPLEX component (not a t_QUAD) */
    1367             : INLINE GEN
    1368    18133843 : cxcompotor(GEN z, long prec)
    1369             : {
    1370    18133843 :   switch(typ(z))
    1371             :   {
    1372    13670451 :     case t_INT:  return itor(z, prec);
    1373      284074 :     case t_FRAC: return fractor(z, prec);
    1374     4179696 :     case t_REAL: return rtor(z, prec);
    1375           0 :     default: pari_err_TYPE("cxcompotor",z);
    1376             :              return NULL; /* LCOV_EXCL_LINE */
    1377             :   }
    1378             : }
    1379             : INLINE GEN
    1380     9051816 : cxtofp(GEN x, long prec)
    1381     9051816 : { retmkcomplex(cxcompotor(gel(x,1),prec), cxcompotor(gel(x,2),prec)); }
    1382             : 
    1383             : INLINE GEN
    1384      273443 : cxtoreal(GEN q)
    1385      273443 : { return (typ(q) == t_COMPLEX && gequal0(gel(q,2)))? gel(q,1): q; }
    1386             : 
    1387             : INLINE double
    1388    60819732 : gtodouble(GEN x)
    1389             : {
    1390    60819732 :   if (typ(x)!=t_REAL) {
    1391     5127255 :     pari_sp av = avma;
    1392     5127255 :     x = gtofp(x, DEFAULTPREC);
    1393     5126650 :     if (typ(x)!=t_REAL) pari_err_TYPE("gtodouble [t_REAL expected]", x);
    1394     5126650 :     set_avma(av);
    1395             :   }
    1396    60818988 :   return rtodbl(x);
    1397             : }
    1398             : 
    1399             : INLINE int
    1400    16046693 : gisdouble(GEN x, double *g)
    1401             : {
    1402    16046693 :   if (typ(x)!=t_REAL) {
    1403     1432105 :     pari_sp av = avma;
    1404     1432105 :     x = gtofp(x, DEFAULTPREC);
    1405     1432103 :     if (typ(x)!=t_REAL) pari_err_TYPE("gisdouble [t_REAL expected]", x);
    1406     1432103 :     set_avma(av);
    1407             :   }
    1408    16046675 :   if (expo(x) >= 0x3ff) return 0;
    1409    16046675 :   *g = rtodbl(x); return 1;
    1410             : }
    1411             : 
    1412             : INLINE long
    1413    73572053 : gtos(GEN x) {
    1414    73572053 :   if (typ(x) != t_INT) pari_err_TYPE("gtos [integer expected]",x);
    1415    73572046 :   return itos(x);
    1416             : }
    1417             : 
    1418             : INLINE ulong
    1419       95950 : gtou(GEN x) {
    1420       95950 :   if (typ(x) != t_INT || signe(x)<0)
    1421           7 :     pari_err_TYPE("gtou [integer >=0 expected]",x);
    1422       95943 :   return itou(x);
    1423             : }
    1424             : 
    1425             : INLINE GEN
    1426    37996030 : absfrac(GEN x)
    1427             : {
    1428    37996030 :   GEN y = cgetg(3, t_FRAC);
    1429    37996065 :   gel(y,1) = absi(gel(x,1));
    1430    37996059 :   gel(y,2) = icopy(gel(x,2)); return y;
    1431             : }
    1432             : INLINE GEN
    1433       41545 : absfrac_shallow(GEN x)
    1434       41545 : { return signe(gel(x,1))>0? x: mkfrac(negi(gel(x,1)), gel(x,2)); }
    1435             : INLINE GEN
    1436     6768358 : Q_abs(GEN x) { return (typ(x) == t_INT)? absi(x): absfrac(x); }
    1437             : INLINE GEN
    1438      153601 : Q_abs_shallow(GEN x)
    1439      153601 : { return (typ(x) == t_INT)? absi_shallow(x): absfrac_shallow(x); }
    1440             : INLINE GEN
    1441       12712 : R_abs_shallow(GEN x)
    1442       12712 : { return (typ(x) == t_FRAC)? absfrac_shallow(x): mpabs_shallow(x); }
    1443             : INLINE GEN
    1444           0 : R_abs(GEN x)
    1445           0 : { return (typ(x) == t_FRAC)? absfrac(x): mpabs(x); }
    1446             : 
    1447             : /* Force z to be of type real/complex with floating point components */
    1448             : INLINE GEN
    1449    79084728 : gtofp(GEN z, long prec)
    1450             : {
    1451    79084728 :   switch(typ(z))
    1452             :   {
    1453    44375971 :     case t_INT:  return itor(z, prec);
    1454     4355153 :     case t_FRAC: return fractor(z, prec);
    1455    21572699 :     case t_REAL: return rtor(z, prec);
    1456     8789270 :     case t_COMPLEX: {
    1457     8789270 :       GEN a = gel(z,1), b = gel(z,2);
    1458     8789270 :       if (isintzero(b)) return cxcompotor(a, prec);
    1459     8789318 :       if (isintzero(a)) {
    1460        9484 :         GEN y = cgetg(3, t_COMPLEX);
    1461        9484 :         b = cxcompotor(b, prec);
    1462        9484 :         gel(y,1) = real_0_bit(expo(b) - prec2nbits(prec));
    1463        9484 :         gel(y,2) = b; return y;
    1464             :       }
    1465     8779841 :       return cxtofp(z, prec);
    1466             :     }
    1467           0 :     case t_QUAD: return quadtofp(z, prec);
    1468           0 :     default: pari_err_TYPE("gtofp",z);
    1469             :              return NULL; /* LCOV_EXCL_LINE */
    1470             :   }
    1471             : }
    1472             : /* Force z to be of type real / int */
    1473             : INLINE GEN
    1474       22428 : gtomp(GEN z, long prec)
    1475             : {
    1476       22428 :   switch(typ(z))
    1477             :   {
    1478          42 :     case t_INT:  return z;
    1479       22386 :     case t_FRAC: return fractor(z, prec);
    1480           0 :     case t_REAL: return rtor(z, prec);
    1481           0 :     case t_QUAD: z = quadtofp(z, prec);
    1482           0 :                  if (typ(z) == t_REAL) return z;
    1483           0 :     default: pari_err_TYPE("gtomp",z);
    1484             :              return NULL; /* LCOV_EXCL_LINE */
    1485             :   }
    1486             : }
    1487             : 
    1488             : INLINE GEN
    1489     5800537 : RgX_gtofp(GEN x, long prec)
    1490             : {
    1491             :   long l;
    1492     5800537 :   GEN y = cgetg_copy(x, &l);
    1493    33440775 :   while (--l > 1) gel(y,l) = gtofp(gel(x,l), prec);
    1494     5798527 :   y[1] = x[1]; return y;
    1495             : }
    1496             : INLINE GEN
    1497     2521138 : RgC_gtofp(GEN x, long prec)
    1498    22862804 : { pari_APPLY_type(t_COL, gtofp(gel(x,i), prec)) }
    1499             : 
    1500             : INLINE GEN
    1501          49 : RgV_gtofp(GEN x, long prec)
    1502        4746 : { pari_APPLY_type(t_VEC, gtofp(gel(x,i), prec)) }
    1503             : 
    1504             : INLINE GEN
    1505      396728 : RgM_gtofp(GEN x, long prec)
    1506     2340247 : { pari_APPLY_same(RgC_gtofp(gel(x,i), prec)) }
    1507             : 
    1508             : INLINE GEN
    1509         574 : RgC_gtomp(GEN x, long prec)
    1510       23002 : { pari_APPLY_type(t_COL, gtomp(gel(x,i), prec)) }
    1511             : 
    1512             : INLINE GEN
    1513          21 : RgM_gtomp(GEN x, long prec)
    1514         595 : { pari_APPLY_same(RgC_gtomp(gel(x,i), prec)) }
    1515             : 
    1516             : INLINE GEN
    1517       96719 : RgX_fpnorml2(GEN x, long prec)
    1518             : {
    1519       96719 :   pari_sp av = avma;
    1520       96719 :   return gerepileupto(av, gnorml2(RgX_gtofp(x, prec)));
    1521             : }
    1522             : INLINE GEN
    1523      567732 : RgC_fpnorml2(GEN x, long prec)
    1524             : {
    1525      567732 :   pari_sp av = avma;
    1526      567732 :   return gerepileupto(av, gnorml2(RgC_gtofp(x, prec)));
    1527             : }
    1528             : INLINE GEN
    1529       18651 : RgM_fpnorml2(GEN x, long prec)
    1530             : {
    1531       18651 :   pari_sp av = avma;
    1532       18651 :   return gerepileupto(av, gnorml2(RgM_gtofp(x, prec)));
    1533             : }
    1534             : 
    1535             : /* y a t_REAL */
    1536             : INLINE void
    1537      216244 : affgr(GEN x, GEN y)
    1538             : {
    1539             :   pari_sp av;
    1540      216244 :   switch(typ(x)) {
    1541        5992 :     case t_INT:  affir(x,y); break;
    1542      210252 :     case t_REAL: affrr(x,y); break;
    1543           0 :     case t_FRAC: rdiviiz(gel(x,1),gel(x,2), y); break;
    1544           0 :     case t_QUAD: av = avma; affgr(quadtofp(x,realprec(y)), y); set_avma(av); break;
    1545           0 :     default: pari_err_TYPE2("=",x,y);
    1546             :   }
    1547      216244 : }
    1548             : 
    1549             : INLINE GEN
    1550      243089 : affc_fixlg(GEN x, GEN res)
    1551             : {
    1552      243089 :   if (typ(x) == t_COMPLEX)
    1553             :   {
    1554      210679 :     affrr_fixlg(gel(x,1), gel(res,1));
    1555      210679 :     affrr_fixlg(gel(x,2), gel(res,2));
    1556             :   }
    1557             :   else
    1558             :   {
    1559       32410 :     set_avma((pari_sp)(res+3));
    1560       32408 :     res = cgetr(realprec(gel(res,1)));
    1561       32412 :     affrr_fixlg(x, res);
    1562             :   }
    1563      243091 :   return res;
    1564             : }
    1565             : 
    1566             : INLINE GEN
    1567           0 : trunc_safe(GEN x) { long e; return gcvtoi(x,&e); }
    1568             : 
    1569             : /*******************************************************************/
    1570             : /*                                                                 */
    1571             : /*                          LENGTH CONVERSIONS                     */
    1572             : /*                                                                 */
    1573             : /*******************************************************************/
    1574             : INLINE long
    1575       37286 : ndec2nlong(long x) { return 1 + (long)((x)*(LOG2_10/BITS_IN_LONG)); }
    1576             : INLINE long
    1577       28988 : ndec2prec(long x) { return 2 + ndec2nlong(x); }
    1578             : INLINE long
    1579        8298 : ndec2nbits(long x) { return ndec2nlong(x) << TWOPOTBITS_IN_LONG; }
    1580             : /* Fast implementation of ceil(x / (8*sizeof(long))); typecast to (ulong)
    1581             :  * to avoid overflow. Faster than 1 + ((x-1)>>TWOPOTBITS_IN_LONG)) :
    1582             :  *   addl, shrl instead of subl, sarl, addl */
    1583             : INLINE long
    1584     9990775 : nbits2nlong(long x) {
    1585     9990775 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1586             : }
    1587             : 
    1588             : INLINE long
    1589   307360458 : nbits2extraprec(long x) {
    1590   307360458 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1591             : }
    1592             : 
    1593             : /* Fast implementation of 2 + nbits2nlong(x) */
    1594             : INLINE long
    1595   192342030 : nbits2prec(long x) {
    1596   192342030 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1597             : }
    1598             : INLINE long
    1599   243419247 : nbits2lg(long x) {
    1600   243419247 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1601             : }
    1602             : /* ceil(x / sizeof(long)) */
    1603             : INLINE long
    1604   110684421 : nchar2nlong(long x) {
    1605   110684421 :   return (long)(((ulong)x+sizeof(long)-1) >> (TWOPOTBITS_IN_LONG-3L));
    1606             : }
    1607             : INLINE long
    1608  2152201775 : prec2nbits(long x) { return (x-2) * BITS_IN_LONG; }
    1609             : INLINE double
    1610     2866304 : bit_accuracy_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1611             : INLINE double
    1612      273060 : prec2nbits_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1613             : INLINE long
    1614   118040230 : bit_prec(GEN x) { return prec2nbits(realprec(x)); }
    1615             : INLINE long
    1616  1916921354 : bit_accuracy(long x) { return prec2nbits(x); }
    1617             : INLINE long
    1618       12861 : prec2ndec(long x) { return (long)prec2nbits_mul(x, LOG10_2); }
    1619             : INLINE long
    1620         200 : nbits2ndec(long x) { return (long)(x * LOG10_2); }
    1621             : INLINE long
    1622        4461 : precdbl(long x) {return (x - 1) << 1;}
    1623             : INLINE long
    1624  5329915491 : divsBIL(long n) { return n >> TWOPOTBITS_IN_LONG; }
    1625             : INLINE long
    1626  5262160369 : remsBIL(long n) { return n & (BITS_IN_LONG-1); }
    1627             : 
    1628             : /*********************************************************************/
    1629             : /**                                                                 **/
    1630             : /**                      OPERATIONS MODULO m                        **/
    1631             : /**                                                                 **/
    1632             : /*********************************************************************/
    1633             : /* Assume m > 0, more efficient if 0 <= a, b < m */
    1634             : 
    1635             : INLINE GEN
    1636    45370681 : Fp_red(GEN a, GEN m) { return modii(a, m); }
    1637             : INLINE GEN
    1638    97336065 : Fp_add(GEN a, GEN b, GEN m)
    1639             : {
    1640    97336065 :   pari_sp av=avma;
    1641    97336065 :   GEN p = addii(a,b);
    1642    95696327 :   long s = signe(p);
    1643    95696327 :   if (!s) return p; /* = gen_0 */
    1644    84787934 :   if (s > 0) /* general case */
    1645             :   {
    1646    84838886 :     GEN t = subii(p, m);
    1647    84487151 :     s = signe(t);
    1648    84487151 :     if (!s) return gc_const(av, gen_0);
    1649    77043572 :     if (s < 0) return gc_const((pari_sp)p, p);
    1650    38869938 :     if (cmpii(t, m) < 0) return gerepileuptoint(av, t); /* general case ! */
    1651     3001534 :     p = remii(t, m);
    1652             :   }
    1653             :   else
    1654      226428 :     p = modii(p, m);
    1655     3228074 :   return gerepileuptoint(av, p);
    1656             : }
    1657             : INLINE GEN
    1658    73775689 : Fp_sub(GEN a, GEN b, GEN m)
    1659             : {
    1660    73775689 :   pari_sp av=avma;
    1661    73775689 :   GEN p = subii(a,b);
    1662    71325898 :   long s = signe(p);
    1663    71325898 :   if (!s) return p; /* = gen_0 */
    1664    61876204 :   if (s > 0)
    1665             :   {
    1666    26717557 :     if (cmpii(p, m) < 0) return p; /* general case ! */
    1667     1058980 :     p = remii(p, m);
    1668             :   }
    1669             :   else
    1670             :   {
    1671    35158647 :     GEN t = addii(p, m);
    1672    36911094 :     if (!s) return gc_const(av, gen_0);
    1673    36985709 :     if (s > 0) return gerepileuptoint(av, t); /* general case ! */
    1674    36985709 :     p = modii(t, m);
    1675             :   }
    1676    38401150 :   return gerepileuptoint(av, p);
    1677             : }
    1678             : INLINE GEN
    1679    15462550 : Fp_neg(GEN b, GEN m)
    1680             : {
    1681    15462550 :   pari_sp av = avma;
    1682    15462550 :   long s = signe(b);
    1683             :   GEN p;
    1684    15462550 :   if (!s) return gen_0;
    1685    11863278 :   if (s > 0)
    1686             :   {
    1687    11080103 :     p = subii(m, b);
    1688    11077843 :     if (signe(p) >= 0) return p; /* general case ! */
    1689      378955 :     p = modii(p, m);
    1690             :   } else
    1691      783999 :     p = remii(negi(b), m);
    1692     1163187 :   return gerepileuptoint(av, p);
    1693             : }
    1694             : 
    1695             : INLINE GEN
    1696       63819 : Fp_halve(GEN a, GEN p)
    1697             : {
    1698       63819 :   if (mpodd(a)) a = addii(a,p);
    1699       63819 :   return shifti(a,-1);
    1700             : }
    1701             : 
    1702             : /* assume 0 <= u < p and ps2 = p>>1 */
    1703             : INLINE GEN
    1704    55133346 : Fp_center(GEN u, GEN p, GEN ps2)
    1705    55133346 : { return abscmpii(u,ps2)<=0? icopy(u): subii(u,p); }
    1706             : /* same without copy */
    1707             : INLINE GEN
    1708    11607235 : Fp_center_i(GEN u, GEN p, GEN ps2)
    1709    11607235 : { return abscmpii(u,ps2)<=0? u: subii(u,p); }
    1710             : 
    1711             : /* x + y*z mod p */
    1712             : INLINE GEN
    1713     7270523 : Fp_addmul(GEN x, GEN y, GEN z, GEN p)
    1714             : {
    1715             :   pari_sp av;
    1716     7270523 :   if (!signe(y) || !signe(z)) return Fp_red(x, p);
    1717     6956661 :   if (!signe(x)) return Fp_mul(z,y, p);
    1718     5997085 :   av = avma;
    1719     5997085 :   return gerepileuptoint(av, modii(addii(x, mulii(y,z)), p));
    1720             : }
    1721             : 
    1722             : INLINE GEN
    1723   121165484 : Fp_mul(GEN a, GEN b, GEN m)
    1724             : {
    1725   121165484 :   pari_sp av=avma;
    1726             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1727   121165484 :   (void)new_chunk(lg(a)+lg(b)+(lg(m)<<1));
    1728   121154079 :   p = mulii(a,b);
    1729   121279781 :   set_avma(av); return modii(p,m);
    1730             : }
    1731             : INLINE GEN
    1732    34872368 : Fp_sqr(GEN a, GEN m)
    1733             : {
    1734    34872368 :   pari_sp av=avma;
    1735             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1736    34872368 :   (void)new_chunk((lg(a)+lg(m))<<1);
    1737    34639728 :   p = sqri(a);
    1738    32070767 :   set_avma(av); return remii(p,m); /*Use remii: p >= 0 */
    1739             : }
    1740             : INLINE GEN
    1741    66837527 : Fp_mulu(GEN a, ulong b, GEN m)
    1742             : {
    1743    66837527 :   long l = lgefint(m);
    1744    66837527 :   if (l == 3)
    1745             :   {
    1746    44768308 :     ulong mm = m[2];
    1747    44768308 :     return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1748             :   } else {
    1749    22069219 :     pari_sp av = avma;
    1750             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1751    22069219 :     (void)new_chunk(lg(a)+1+(l<<1));
    1752    21981205 :     p = muliu(a,b);
    1753    20173460 :     set_avma(av); return modii(p,m);
    1754             :   }
    1755             : }
    1756             : INLINE GEN
    1757       17290 : Fp_muls(GEN a, long b, GEN m)
    1758             : {
    1759       17290 :   long l = lgefint(m);
    1760       17290 :   if (l == 3)
    1761             :   {
    1762        3058 :     ulong mm = m[2];
    1763        3058 :     if (b < 0)
    1764             :     {
    1765        3058 :       ulong t = Fl_mul(umodiu(a, mm), -b, mm);
    1766        3058 :       return t? utoipos(mm - t): gen_0;
    1767             :     }
    1768             :     else
    1769           0 :       return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1770             :   } else {
    1771       14232 :     pari_sp av = avma;
    1772             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1773       14232 :     (void)new_chunk(lg(a)+1+(l<<1));
    1774       14232 :     p = mulis(a,b);
    1775       14232 :     set_avma(av); return modii(p,m);
    1776             :   }
    1777             : }
    1778             : 
    1779             : INLINE GEN
    1780    24407878 : Fp_inv(GEN a, GEN m)
    1781             : {
    1782             :   GEN res;
    1783    24407878 :   if (! invmod(a,m,&res)) pari_err_INV("Fp_inv", mkintmod(res,m));
    1784    24406536 :   return res;
    1785             : }
    1786             : INLINE GEN
    1787      779965 : Fp_invsafe(GEN a, GEN m)
    1788             : {
    1789             :   GEN res;
    1790      779965 :   if (! invmod(a,m,&res)) return NULL;
    1791      779861 :   return res;
    1792             : }
    1793             : INLINE GEN
    1794     1458491 : Fp_div(GEN a, GEN b, GEN m)
    1795             : {
    1796     1458491 :   pari_sp av = avma;
    1797             :   GEN p;
    1798     1458491 :   if (lgefint(b) == 3)
    1799             :   {
    1800      485936 :     a = Fp_divu(a, b[2], m);
    1801      485936 :     if (signe(b) < 0) a = Fp_neg(a, m);
    1802      485936 :     return a;
    1803             :   }
    1804             :   /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1805      972555 :   (void)new_chunk(lg(a)+(lg(m)<<1));
    1806      972555 :   p = mulii(a, Fp_inv(b,m));
    1807      972555 :   set_avma(av); return modii(p,m);
    1808             : }
    1809             : INLINE GEN
    1810     1648664 : Fp_divu(GEN x, ulong a, GEN p)
    1811             : {
    1812     1648664 :   pari_sp av = avma;
    1813             :   ulong b;
    1814     1648664 :   if (lgefint(p) == 3)
    1815             :   {
    1816     1353140 :     ulong pp = p[2], xp = umodiu(x, pp);
    1817     1353140 :     return xp? utoipos(Fl_div(xp, a % pp, pp)): gen_0;
    1818             :   }
    1819      295524 :   x = Fp_red(x, p);
    1820      295524 :   b = Fl_neg(Fl_div(umodiu(x,a), umodiu(p,a), a), a); /* x + pb = 0 (mod a) */
    1821      295524 :   return gerepileuptoint(av, diviuexact(addmuliu(x, p, b), a));
    1822             : }
    1823             : 
    1824             : INLINE GEN
    1825     1113326 : Flx_mulu(GEN x, ulong a, ulong p) { return Flx_Fl_mul(x,a%p,p); }
    1826             : 
    1827             : INLINE GEN
    1828     1774860 : get_F2x_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1829             : 
    1830             : INLINE long
    1831     2462580 : get_F2x_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1832             : 
    1833             : INLINE long
    1834     1924978 : get_F2x_degree(GEN T) { return typ(T)==t_VEC? F2x_degree(gel(T,2)): F2x_degree(T); }
    1835             : 
    1836             : INLINE GEN
    1837         406 : get_F2xqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1838             : 
    1839             : INLINE long
    1840      376187 : get_F2xqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1841             : 
    1842             : INLINE long
    1843      201481 : get_F2xqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1844             : 
    1845             : INLINE GEN
    1846    23560253 : get_Flx_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1847             : 
    1848             : INLINE long
    1849    64693127 : get_Flx_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1850             : 
    1851             : INLINE long
    1852    81648718 : get_Flx_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1853             : 
    1854             : INLINE GEN
    1855        6997 : get_FlxqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1856             : 
    1857             : INLINE long
    1858      245078 : get_FlxqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1859             : 
    1860             : INLINE long
    1861      300898 : get_FlxqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1862             : 
    1863             : INLINE GEN
    1864     2528646 : get_FpX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1865             : 
    1866             : INLINE long
    1867     6556226 : get_FpX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1868             : 
    1869             : INLINE long
    1870     5258249 : get_FpX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1871             : 
    1872             : INLINE GEN
    1873      146583 : get_FpXQX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1874             : 
    1875             : INLINE long
    1876       34808 : get_FpXQX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1877             : 
    1878             : INLINE long
    1879        2259 : get_FpXQX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1880             : 
    1881             : /*******************************************************************/
    1882             : /*                                                                 */
    1883             : /*                        ADDMULII / SUBMULII                      */
    1884             : /*                                                                 */
    1885             : /*******************************************************************/
    1886             : /* x - y*z */
    1887             : INLINE GEN
    1888    24638458 : submulii(GEN x, GEN y, GEN z)
    1889             : {
    1890    24638458 :   long lx = lgefint(x), ly, lz;
    1891             :   pari_sp av;
    1892             :   GEN t;
    1893    24638458 :   if (lx == 2) { t = mulii(z,y); togglesign(t); return t; }
    1894    19926421 :   ly = lgefint(y);
    1895    19926421 :   if (ly == 2) return icopy(x);
    1896    17630014 :   lz = lgefint(z);
    1897    17630014 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1898    17630014 :   t = mulii(z, y);
    1899    17630014 :   set_avma(av); return subii(x,t);
    1900             : }
    1901             : /* y*z - x */
    1902             : INLINE GEN
    1903     2381438 : mulsubii(GEN y, GEN z, GEN x)
    1904             : {
    1905     2381438 :   long lx = lgefint(x), ly, lz;
    1906             :   pari_sp av;
    1907             :   GEN t;
    1908     2381438 :   if (lx == 2) return mulii(z,y);
    1909     1466316 :   ly = lgefint(y);
    1910     1466316 :   if (ly == 2) return negi(x);
    1911     1295796 :   lz = lgefint(z);
    1912     1295796 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1913     1295836 :   t = mulii(z, y);
    1914     1295775 :   set_avma(av); return subii(t,x);
    1915             : }
    1916             : 
    1917             : /* x - u*y */
    1918             : INLINE GEN
    1919        7693 : submuliu(GEN x, GEN y, ulong u)
    1920             : {
    1921             :   pari_sp av;
    1922        7693 :   long ly = lgefint(y);
    1923        7693 :   if (ly == 2) return icopy(x);
    1924        7693 :   av = avma;
    1925        7693 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1926        7693 :   y = mului(u,y);
    1927        7693 :   set_avma(av); return subii(x, y);
    1928             : }
    1929             : /* x + u*y */
    1930             : INLINE GEN
    1931      303592 : addmuliu(GEN x, GEN y, ulong u)
    1932             : {
    1933             :   pari_sp av;
    1934      303592 :   long ly = lgefint(y);
    1935      303592 :   if (ly == 2) return icopy(x);
    1936      303592 :   av = avma;
    1937      303592 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1938      303592 :   y = mului(u,y);
    1939      303591 :   set_avma(av); return addii(x, y);
    1940             : }
    1941             : /* x - u*y */
    1942             : INLINE GEN
    1943   180099567 : submuliu_inplace(GEN x, GEN y, ulong u)
    1944             : {
    1945             :   pari_sp av;
    1946   180099567 :   long ly = lgefint(y);
    1947   180099567 :   if (ly == 2) return x;
    1948   132972806 :   av = avma;
    1949   132972806 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1950   132979595 :   y = mului(u,y);
    1951   132976967 :   set_avma(av); return subii(x, y);
    1952             : }
    1953             : /* x + u*y */
    1954             : INLINE GEN
    1955   178029024 : addmuliu_inplace(GEN x, GEN y, ulong u)
    1956             : {
    1957             :   pari_sp av;
    1958   178029024 :   long ly = lgefint(y);
    1959   178029024 :   if (ly == 2) return x;
    1960   132862666 :   av = avma;
    1961   132862666 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1962   132870000 :   y = mului(u,y);
    1963   132867652 :   set_avma(av); return addii(x, y);
    1964             : }
    1965             : /* ux + vy */
    1966             : INLINE GEN
    1967    38784743 : lincombii(GEN u, GEN v, GEN x, GEN y)
    1968             : {
    1969    38784743 :   long lx = lgefint(x), ly;
    1970             :   GEN p1, p2;
    1971             :   pari_sp av;
    1972    38784743 :   if (lx == 2) return mulii(v,y);
    1973    25260952 :   ly = lgefint(y);
    1974    25260952 :   if (ly == 2) return mulii(u,x);
    1975    22832023 :   av = avma; (void)new_chunk(lx+ly+lgefint(u)+lgefint(v)); /* HACK */
    1976    22835667 :   p1 = mulii(u,x);
    1977    22833666 :   p2 = mulii(v,y);
    1978    22833564 :   set_avma(av); return addii(p1,p2);
    1979             : }
    1980             : 
    1981             : /*******************************************************************/
    1982             : /*                                                                 */
    1983             : /*                          GEN SUBTYPES                           */
    1984             : /*                                                                 */
    1985             : /*******************************************************************/
    1986             : 
    1987             : INLINE int
    1988  3201279305 : is_const_t(long t) { return (t < t_POLMOD); }
    1989             : INLINE int
    1990        6841 : is_extscalar_t(long t) { return (t <= t_POL); }
    1991             : INLINE int
    1992     4889537 : is_intreal_t(long t) { return (t <= t_REAL); }
    1993             : INLINE int
    1994   737105628 : is_matvec_t(long t) { return (t >= t_VEC && t <= t_MAT); }
    1995             : INLINE int
    1996    76220353 : is_noncalc_t(long tx) { return (tx) >= t_LIST; }
    1997             : INLINE int
    1998           0 : is_qfb_t(long t) { return (t == t_QFB); }
    1999             : INLINE int
    2000     3442422 : is_rational_t(long t) { return (t == t_INT || t == t_FRAC); }
    2001             : INLINE int
    2002     1106404 : is_real_t(long t) { return (t == t_INT || t == t_REAL || t == t_FRAC); }
    2003             : INLINE int
    2004  7501149686 : is_recursive_t(long t) { return lontyp[t]; }
    2005             : INLINE int
    2006   242038416 : is_scalar_t(long t) { return (t < t_POL); }
    2007             : INLINE int
    2008     1123036 : is_vec_t(long t) { return (t == t_VEC || t == t_COL); }
    2009             : 
    2010             : INLINE int
    2011   144389554 : qfb_is_qfi(GEN q) { return signe(gel(q,4)) < 0; }
    2012             : 
    2013             : /*******************************************************************/
    2014             : /*                                                                 */
    2015             : /*                         TRANSCENDENTAL                          */
    2016             : /*                                                                 */
    2017             : /*******************************************************************/
    2018             : INLINE GEN
    2019    49349618 : sqrtr(GEN x) {
    2020    49349618 :   long s = signe(x);
    2021    49349618 :   if (s == 0) return real_0_bit(expo(x) >> 1);
    2022    49316528 :   if (s >= 0) return sqrtr_abs(x);
    2023      279841 :   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     1014162 : sqrtnr(GEN x, long n) {
    2038     1014162 :   long s = signe(x);
    2039             :   GEN r;
    2040     1014162 :   if (s == 0) return real_0_bit(expo(x) / n);
    2041     1014162 :   r = sqrtnr_abs(x, n);
    2042     1014190 :   if (s < 0) pari_err_IMPL("sqrtnr for x < 0");
    2043     1014192 :   return r;
    2044             : }
    2045             : INLINE long
    2046      411535 : logint(GEN B, GEN y) { return logintall(B,y,NULL); }
    2047             : INLINE ulong
    2048     2222048 : ulogint(ulong B, ulong y)
    2049             : {
    2050             :   ulong r;
    2051             :   long e;
    2052     2222048 :   if (y == 2) return expu(B);
    2053     2198580 :   r = y;
    2054     2198580 :   for (e=1;; e++)
    2055             :   { /* here, r = y^e, r2 = y^(e-1) */
    2056     7112921 :     if (r >= B) return r == B? e: e-1;
    2057     4914259 :     r = umuluu_or_0(y, r);
    2058     4914346 :     if (!r) return e;
    2059             :   }
    2060             : }
    2061             : 
    2062             : /*******************************************************************/
    2063             : /*                                                                 */
    2064             : /*                         MISCELLANEOUS                           */
    2065             : /*                                                                 */
    2066             : /*******************************************************************/
    2067     4889461 : INLINE int ismpzero(GEN x) { return is_intreal_t(typ(x)) && !signe(x); }
    2068  3167192078 : INLINE int isintzero(GEN x) { return typ(x) == t_INT && !signe(x); }
    2069    15107321 : INLINE int isint1(GEN x) { return typ(x)==t_INT && equali1(x); }
    2070     4028436 : INLINE int isintm1(GEN x){ return typ(x)==t_INT && equalim1(x);}
    2071   903756157 : INLINE int equali1(GEN n)
    2072   903756157 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(1)) && n[2] == 1; }
    2073    62817317 : INLINE int equalim1(GEN n)
    2074    62817317 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(-1)) && n[2] == 1; }
    2075             : /* works only for POSITIVE integers */
    2076  2201511418 : INLINE int is_pm1(GEN n)
    2077  2201511418 : { return lgefint(n) == 3 && n[2] == 1; }
    2078   321123724 : INLINE int is_bigint(GEN n)
    2079   321123724 : { long l = lgefint(n); return l > 3 || (l == 3 && (n[2] & HIGHBIT)); }
    2080             : 
    2081  2632529407 : INLINE int odd(long x) { return x & 1; }
    2082    55118302 : INLINE int both_odd(long x, long y) { return x & y & 1; }
    2083             : 
    2084             : INLINE int
    2085  5263334462 : isonstack(GEN x)
    2086  5263334462 : { return ((pari_sp)x >= pari_mainstack->bot
    2087  5263334462 :        && (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    60870836 : dbllog2r(GEN x)
    2092    60870836 : { return log2((double)(ulong)x[2]) + (double)(expo(x) - (BITS_IN_LONG-1)); }
    2093             : 
    2094             : INLINE GEN
    2095     1373404 : mul_content(GEN cx, GEN cy)
    2096             : {
    2097     1373404 :   if (!cx) return cy;
    2098      567017 :   if (!cy) return cx;
    2099      372902 :   return gmul(cx,cy);
    2100             : }
    2101             : INLINE GEN
    2102           0 : inv_content(GEN c) { return c? ginv(c): NULL; }
    2103             : INLINE GEN
    2104       36274 : div_content(GEN cx, GEN cy)
    2105             : {
    2106       36274 :   if (!cy) return cx;
    2107       35224 :   if (!cx) return ginv(cy);
    2108        7223 :   return gdiv(cx,cy);
    2109             : }
    2110             : INLINE GEN
    2111     5061480 : mul_denom(GEN dx, GEN dy)
    2112             : {
    2113     5061480 :   if (!dx) return dy;
    2114     1566111 :   if (!dy) return dx;
    2115      686553 :   return mulii(dx,dy);
    2116             : }
    2117             : 
    2118             : /* POLYNOMIALS */
    2119             : INLINE GEN
    2120     1284432 : constant_coeff(GEN x) { return signe(x)? gel(x,2): gen_0; }
    2121             : INLINE GEN
    2122    77137900 : leading_coeff(GEN x) { return lg(x) == 2? gen_0: gel(x,lg(x)-1); }
    2123             : INLINE ulong
    2124      681944 : Flx_lead(GEN x) { return lg(x) == 2? 0: x[lg(x)-1]; }
    2125             : INLINE ulong
    2126       34313 : Flx_constant(GEN x) { return lg(x) == 2? 0: x[2]; }
    2127             : INLINE long
    2128  4483261825 : degpol(GEN x) { return lg(x)-3; }
    2129             : INLINE long
    2130  2285119788 : lgpol(GEN x) { return lg(x)-2; }
    2131             : INLINE long
    2132   237621740 : lgcols(GEN x) { return lg(gel(x,1)); }
    2133             : INLINE long
    2134   142220678 : 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     1240048 : ZXQ_mul(GEN y, GEN x, GEN T) { return ZX_rem(ZX_mul(y, x), T); }
    2140             : INLINE GEN
    2141      499217 : ZXQ_sqr(GEN x, GEN T) { return ZX_rem(ZX_sqr(x), T); }
    2142             : 
    2143             : INLINE GEN
    2144    96667030 : RgX_copy(GEN x)
    2145             : {
    2146             :   long lx, i;
    2147    96667030 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
    2148   351712942 :   for (i = 2; i<lx; i++) gel(y,i) = gcopy(gel(x,i));
    2149    96667051 :   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     1087093 : RgX_coeff(GEN x, long n)
    2155             : {
    2156     1087093 :   ulong l = lg(x);
    2157     1087093 :   return (n < 0 || ((ulong)n+3) > l)? gen_0: gel(x,n+2);
    2158             : }
    2159             : INLINE GEN
    2160      345299 : RgX_renormalize(GEN x) { return RgX_renormalize_lg(x, lg(x)); }
    2161             : INLINE GEN
    2162     6835527 : 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      104526 : RgXQX_rem(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,ONLY_REM); }
    2167             : INLINE GEN
    2168     4299218 : FpX_div(GEN x, GEN y, GEN p) { return FpX_divrem(x,y,p, NULL); }
    2169             : INLINE GEN
    2170    22002411 : Flx_div(GEN x, GEN y, ulong p) { return Flx_divrem(x,y,p, NULL); }
    2171             : INLINE GEN
    2172     1248603 : 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    87092706 : pol0_Flx(long sv) { return mkvecsmall(sv); }
    2177             : INLINE GEN
    2178    49870360 : pol1_Flx(long sv) { return mkvecsmall2(sv, 1); }
    2179             : INLINE GEN
    2180    34866196 : 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    11428112 : pol0_F2x(long sv) { return pol0_Flx(sv); }
    2193             : INLINE GEN
    2194     3118449 : pol1_F2x(long sv) { return pol1_Flx(sv); }
    2195             : INLINE GEN
    2196     1001742 : polx_F2x(long sv) { return mkvecsmall2(sv, 2); }
    2197             : INLINE int
    2198      604532 : F2x_equal1(GEN x) { return Flx_equal1(x); }
    2199             : INLINE int
    2200     3110009 : F2x_equal(GEN V, GEN W) { return Flx_equal(V,W); }
    2201             : INLINE GEN
    2202    56103773 : F2x_copy(GEN x) { return leafcopy(x); }
    2203             : INLINE GEN
    2204        4074 : F2v_copy(GEN x) { return leafcopy(x); }
    2205             : INLINE GEN
    2206     2584436 : Flv_copy(GEN x) { return leafcopy(x); }
    2207             : INLINE GEN
    2208   168072583 : Flx_copy(GEN x) { return leafcopy(x); }
    2209             : INLINE GEN
    2210     3917134 : vecsmall_copy(GEN x) { return leafcopy(x); }
    2211             : INLINE int
    2212     6423934 : Flx_equal1(GEN x) { return degpol(x)==0 && x[2] == 1; }
    2213             : INLINE int
    2214       19303 : ZX_equal1(GEN x) { return degpol(x)==0 && equali1(gel(x,2)); }
    2215             : INLINE int
    2216     5646328 : ZX_is_monic(GEN x) { return equali1(leading_coeff(x)); }
    2217             : 
    2218             : INLINE GEN
    2219   137216585 : ZX_renormalize(GEN x, long lx)    { return ZXX_renormalize(x,lx); }
    2220             : INLINE GEN
    2221    97919088 : FpX_renormalize(GEN x, long lx)   { return ZXX_renormalize(x,lx); }
    2222             : INLINE GEN
    2223      677721 : FpXX_renormalize(GEN x, long lx)  { return ZXX_renormalize(x,lx); }
    2224             : INLINE GEN
    2225     4246201 : FpXQX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
    2226             : INLINE GEN
    2227   111946679 : F2x_renormalize(GEN x, long lx)   { return Flx_renormalize(x,lx); }
    2228             : INLINE GEN
    2229       39795 : F2v_to_F2x(GEN x, long sv) {
    2230       39795 :   GEN y = leafcopy(x);
    2231       39795 :   y[1] = sv; F2x_renormalize(y, lg(y)); return y;
    2232             : }
    2233             : 
    2234             : INLINE long
    2235         350 : sturm(GEN x) { return sturmpart(x, NULL, NULL); }
    2236             : 
    2237             : INLINE long
    2238        4893 : gval(GEN x, long v)
    2239        4893 : { pari_sp av = avma; return gc_long(av, gvaluation(x, pol_x(v))); }
    2240             : 
    2241             : INLINE void
    2242      494596 : RgX_shift_inplace_init(long v)
    2243      494596 : { 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      494596 : RgX_shift_inplace(GEN x, long v)
    2247             : {
    2248             :   long i, lx;
    2249             :   GEN z;
    2250      494596 :   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      466326 : zv_to_ZV(GEN x) { return vecsmall_to_vec(x); }
    2269             : INLINE GEN
    2270     6564400 : zc_to_ZC(GEN x) { return vecsmall_to_col(x); }
    2271             : INLINE GEN
    2272     3408128 : 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    25250869 : zero_zv(long x) { return zero_Flv(x); }
    2283             : INLINE GEN
    2284         266 : 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     2112809 : 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     5269198 : ZC_hnfrem(GEN x, GEN y) { return ZC_hnfremdiv(x,y,NULL); }
    2294             : INLINE GEN
    2295      312674 : ZM_hnfrem(GEN x, GEN y) { return ZM_hnfdivrem(x,y,NULL); }
    2296             : INLINE GEN
    2297     3858534 : ZM_lll(GEN x, double D, long f) { return ZM_lll_norms(x,D,f,NULL); }
    2298             : INLINE void
    2299     8947979 : RgM_dimensions(GEN x, long *m, long *n) { *n = lg(x)-1; *m = *n? nbrows(x): 0; }
    2300             : INLINE GEN
    2301    20061867 : RgM_shallowcopy(GEN x)
    2302             : {
    2303             :   long l;
    2304    20061867 :   GEN y = cgetg_copy(x, &l);
    2305   101930476 :   while (--l > 0) gel(y,l) = leafcopy(gel(x,l));
    2306    20061430 :   return y;
    2307             : }
    2308             : INLINE GEN
    2309      188913 : F2m_copy(GEN x) { return RgM_shallowcopy(x); }
    2310             : 
    2311             : INLINE GEN
    2312           0 : F3m_copy(GEN x) { return RgM_shallowcopy(x); }
    2313             : 
    2314             : INLINE GEN
    2315     5241264 : Flm_copy(GEN x) { return RgM_shallowcopy(x); }
    2316             : 
    2317             : /* divisibility: return 1 if y[i] | x[i] for all i, 0 otherwise. Assume
    2318             :  * x,y are ZV of the same length */
    2319             : INLINE int
    2320       23198 : ZV_dvd(GEN x, GEN y)
    2321             : {
    2322       23198 :   long i, l = lg(x);
    2323       36666 :   for (i=1; i < l; i++)
    2324       29533 :     if ( ! dvdii( gel(x,i), gel(y,i) ) ) return 0;
    2325        7133 :   return 1;
    2326             : }
    2327             : 
    2328             : /* Fq */
    2329             : INLINE GEN
    2330     2562860 : Fq_red(GEN x, GEN T, GEN p)
    2331     2562860 : { return typ(x)==t_INT? Fp_red(x,p): FpXQ_red(x,T,p); }
    2332             : INLINE GEN
    2333      100519 : Fq_to_FpXQ(GEN x, GEN T, GEN p /*unused*/)
    2334             : {
    2335             :   (void) p;
    2336      100519 :   return typ(x)==t_INT ? scalarpol(x, get_FpX_var(T)): x;
    2337             : }
    2338             : INLINE GEN
    2339         756 : Rg_to_Fq(GEN x, GEN T, GEN p) { return T? Rg_to_FpXQ(x,T,p): Rg_to_Fp(x,p); }
    2340             : 
    2341             : INLINE GEN
    2342       14538 : gener_Fq_local(GEN T, GEN p, GEN L)
    2343           0 : { return T? gener_FpXQ_local(T,p, L)
    2344       14538 :           : pgener_Fp_local(p, L); }
    2345             : 
    2346             : /* FpXQX */
    2347             : INLINE GEN
    2348        4431 : FpXQX_div(GEN x, GEN y, GEN T, GEN p) { return FpXQX_divrem(x, y, T, p, NULL); }
    2349             : INLINE GEN
    2350      165966 : FlxqX_div(GEN x, GEN y, GEN T, ulong p) { return FlxqX_divrem(x, y, T, p, NULL); }
    2351             : INLINE GEN
    2352       33376 : F2xqX_div(GEN x, GEN y, GEN T) { return F2xqX_divrem(x, y, T, NULL); }
    2353             : 
    2354             : INLINE GEN
    2355       20006 : FpXY_Fq_evaly(GEN Q, GEN y, GEN T, GEN p, long vx)
    2356       20006 : { return T ? FpXY_FpXQ_evaly(Q, y, T, p, vx): FpXY_evaly(Q, y, p, vx); }
    2357             : 
    2358             : /* FqX */
    2359             : INLINE GEN
    2360       25109 : FqX_red(GEN z, GEN T, GEN p) { return T? FpXQX_red(z, T, p): FpX_red(z, p); }
    2361             : INLINE GEN
    2362      105343 : FqX_add(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2363             : INLINE GEN
    2364       24313 : FqX_neg(GEN x,GEN T,GEN p) { return T? FpXX_neg(x,p): FpX_neg(x,p); }
    2365             : INLINE GEN
    2366       66458 : FqX_sub(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2367             : INLINE GEN
    2368      613521 : FqX_Fp_mul(GEN P, GEN u, GEN T, GEN p)
    2369      613521 : { return T? FpXX_Fp_mul(P, u, p): FpX_Fp_mul(P, u, p); }
    2370             : INLINE GEN
    2371      408572 : FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p)
    2372      408572 : { return typ(U)==t_INT ? FqX_Fp_mul(P, U, T, p): FpXQX_FpXQ_mul(P, U, T, p); }
    2373             : INLINE GEN
    2374      377243 : FqX_mul(GEN x, GEN y, GEN T, GEN p)
    2375      377243 : { return T? FpXQX_mul(x, y, T, p): FpX_mul(x, y, p); }
    2376             : INLINE GEN
    2377       17510 : FqX_mulu(GEN x, ulong y, GEN T, GEN p)
    2378       17510 : { return T? FpXX_mulu(x, y, p): FpX_mulu(x, y, p); }
    2379             : INLINE GEN
    2380       69678 : FqX_sqr(GEN x, GEN T, GEN p)
    2381       69678 : { return T? FpXQX_sqr(x, T, p): FpX_sqr(x, p); }
    2382             : INLINE GEN
    2383        1281 : FqX_powu(GEN x, ulong n, GEN T, GEN p)
    2384        1281 : { return T? FpXQX_powu(x, n, T, p): FpX_powu(x, n, p); }
    2385             : INLINE GEN
    2386       18774 : FqX_halve(GEN x, GEN T, GEN p)
    2387       18774 : { return T? FpXX_halve(x, p): FpX_halve(x, p); }
    2388             : INLINE GEN
    2389       38659 : FqX_div(GEN x, GEN y, GEN T, GEN p)
    2390       38659 : { return T? FpXQX_divrem(x,y,T,p,NULL): FpX_divrem(x,y,p,NULL); }
    2391             : INLINE GEN
    2392        6081 : FqX_get_red(GEN S, GEN T, GEN p)
    2393        6081 : { return T? FpXQX_get_red(S,T,p): FpX_get_red(S,p); }
    2394             : INLINE GEN
    2395       31086 : FqX_rem(GEN x, GEN y, GEN T, GEN p)
    2396       31086 : { return T? FpXQX_rem(x,y,T,p): FpX_rem(x,y,p); }
    2397             : INLINE GEN
    2398           0 : FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2399           0 : { return T? FpXQX_divrem(x,y,T,p,z): FpX_divrem(x,y,p,z); }
    2400             : INLINE GEN
    2401        5936 : FqX_div_by_X_x(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2402        5936 : { return T? FpXQX_div_by_X_x(x,y,T,p,z): FpX_div_by_X_x(x,y,p,z); }
    2403             : INLINE GEN
    2404           0 : FqX_halfgcd(GEN P,GEN Q,GEN T,GEN p)
    2405           0 : {return T? FpXQX_halfgcd(P,Q,T,p): FpX_halfgcd(P,Q,p);}
    2406             : INLINE GEN
    2407      260645 : FqX_gcd(GEN P,GEN Q,GEN T,GEN p)
    2408      260645 : {return T? FpXQX_gcd(P,Q,T,p): FpX_gcd(P,Q,p);}
    2409             : INLINE GEN
    2410      470900 : FqX_extgcd(GEN P,GEN Q,GEN T,GEN p, GEN *U, GEN *V)
    2411      470900 : { return T? FpXQX_extgcd(P,Q,T,p,U,V): FpX_extgcd(P,Q,p,U,V); }
    2412             : INLINE GEN
    2413        3836 : FqX_normalize(GEN z, GEN T, GEN p)
    2414        3836 : { return T? FpXQX_normalize(z, T, p): FpX_normalize(z, p); }
    2415             : INLINE GEN
    2416      291893 : FqX_deriv(GEN f, GEN T, GEN p) { return T? FpXX_deriv(f, p): FpX_deriv(f, p); }
    2417             : INLINE GEN
    2418           0 : FqX_integ(GEN f, GEN T, GEN p) { return T? FpXX_integ(f, p): FpX_integ(f, p); }
    2419             : INLINE GEN
    2420       86058 : FqX_factor(GEN f, GEN T, GEN p)
    2421       86058 : { return T?FpXQX_factor(f, T, p): FpX_factor(f, p); }
    2422             : INLINE GEN
    2423           7 : FqX_factor_squarefree(GEN f, GEN T, GEN p)
    2424           7 : { return T ? FpXQX_factor_squarefree(f, T, p): FpX_factor_squarefree(f, p); }
    2425             : INLINE GEN
    2426           7 : FqX_ddf(GEN f, GEN T, GEN p)
    2427           7 : { return T ? FpXQX_ddf(f, T, p): FpX_ddf(f, p); }
    2428             : INLINE GEN
    2429        2002 : FqX_degfact(GEN f, GEN T, GEN p)
    2430        2002 : { return T?FpXQX_degfact(f, T, p): FpX_degfact(f, p); }
    2431             : INLINE GEN
    2432        7147 : FqX_roots(GEN f, GEN T, GEN p)
    2433        7147 : { return T?FpXQX_roots(f, T, p): FpX_roots(f, p); }
    2434             : INLINE GEN
    2435         175 : FqX_to_mod(GEN f, GEN T, GEN p)
    2436         175 : { return T?FpXQX_to_mod(f, T, p): FpX_to_mod(f, p); }
    2437             : 
    2438             : /*FqXQ*/
    2439             : INLINE GEN
    2440           0 : FqXQ_add(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2441           0 : { (void)S; return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2442             : INLINE GEN
    2443           0 : FqXQ_sub(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2444           0 : { (void)S; return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2445             : INLINE GEN
    2446           0 : FqXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p)
    2447           0 : { return T? FpXQXQ_div(x,y,S,T,p): FpXQ_div(x,y,S,p); }
    2448             : INLINE GEN
    2449           0 : FqXQ_inv(GEN x, GEN S, GEN T, GEN p)
    2450           0 : { return T? FpXQXQ_inv(x,S,T,p): FpXQ_inv(x,S,p); }
    2451             : INLINE GEN
    2452           0 : FqXQ_invsafe(GEN x, GEN S, GEN T, GEN p)
    2453           0 : { return T? FpXQXQ_invsafe(x,S,T,p): FpXQ_inv(x,S,p); }
    2454             : INLINE GEN
    2455       22320 : FqXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p)
    2456       22320 : { return T? FpXQXQ_mul(x,y,S,T,p): FpXQ_mul(x,y,S,p); }
    2457             : INLINE GEN
    2458           0 : FqXQ_sqr(GEN x, GEN S, GEN T, GEN p)
    2459           0 : { return T? FpXQXQ_sqr(x,S,T,p): FpXQ_sqr(x,S,p); }
    2460             : INLINE GEN
    2461           0 : FqXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p)
    2462           0 : { return T? FpXQXQ_pow(x,n,S,T,p): FpXQ_pow(x,n,S,p); }
    2463             : 
    2464             : /*FqXn*/
    2465             : INLINE GEN
    2466        6610 : FqXn_expint(GEN x, long n, GEN T, GEN p)
    2467        6610 : { return T? FpXQXn_expint(x,n,T,p): FpXn_expint(x,n,p); }
    2468             : INLINE GEN
    2469           0 : FqXn_exp(GEN x, long n, GEN T, GEN p)
    2470           0 : { return T? FpXQXn_exp(x,n,T,p): FpXn_exp(x,n,p); }
    2471             : INLINE GEN
    2472        6916 : FqXn_inv(GEN x, long n, GEN T, GEN p)
    2473        6916 : { return T? FpXQXn_inv(x,n,T,p): FpXn_inv(x,n,p); }
    2474             : INLINE GEN
    2475      254926 : FqXn_mul(GEN x, GEN y, long n, GEN T, GEN p)
    2476      254926 : { return T? FpXQXn_mul(x, y, n, T, p): FpXn_mul(x, y, n, p); }
    2477             : INLINE GEN
    2478           0 : FqXn_sqr(GEN x, long n, GEN T, GEN p)
    2479           0 : { return T? FpXQXn_sqr(x,n,T,p): FpXn_sqr(x,n,p); }
    2480             : 
    2481             : /*FpXQ*/
    2482             : INLINE GEN
    2483           0 : FpXQ_add(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2484           0 : { (void)T; return FpX_add(x,y,p); }
    2485             : INLINE GEN
    2486           0 : FpXQ_sub(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2487           0 : { (void)T; return FpX_sub(x,y,p); }
    2488             : 
    2489             : /*Flxq*/
    2490             : INLINE GEN
    2491           0 : Flxq_add(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2492           0 : { (void)T; return Flx_add(x,y,p); }
    2493             : INLINE GEN
    2494           0 : Flxq_sub(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2495           0 : { (void)T; return Flx_sub(x,y,p); }
    2496             : 
    2497             : /* F2x */
    2498             : 
    2499             : INLINE ulong
    2500    84570871 : F2x_coeff(GEN x,long v)
    2501             : {
    2502    84570871 :    ulong u=(ulong)x[2+divsBIL(v)];
    2503    84569453 :    return (u>>remsBIL(v))&1UL;
    2504             : }
    2505             : 
    2506             : INLINE void
    2507    10931599 : F2x_clear(GEN x,long v)
    2508             : {
    2509    10931599 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2510    10931521 :    *u&=~(1UL<<remsBIL(v));
    2511    10931506 : }
    2512             : 
    2513             : INLINE void
    2514    42162704 : F2x_set(GEN x,long v)
    2515             : {
    2516    42162704 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2517    42162108 :    *u|=1UL<<remsBIL(v);
    2518    42159554 : }
    2519             : 
    2520             : INLINE void
    2521     1577797 : F2x_flip(GEN x,long v)
    2522             : {
    2523     1577797 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2524     1577797 :    *u^=1UL<<remsBIL(v);
    2525     1577797 : }
    2526             : 
    2527             : /* F2v */
    2528             : 
    2529             : INLINE ulong
    2530    80473496 : F2v_coeff(GEN x,long v) { return F2x_coeff(x,v-1); }
    2531             : 
    2532             : INLINE void
    2533    10931610 : F2v_clear(GEN x,long v) { F2x_clear(x,v-1); }
    2534             : 
    2535             : INLINE void
    2536    17998481 : F2v_set(GEN x,long v)   { F2x_set(x,v-1); }
    2537             : 
    2538             : INLINE void
    2539     1577797 : F2v_flip(GEN x,long v) { F2x_flip(x,v-1); }
    2540             : 
    2541             : /* F2m */
    2542             : 
    2543             : INLINE ulong
    2544     5361197 : F2m_coeff(GEN x, long a, long b) { return F2v_coeff(gel(x,b), a); }
    2545             : 
    2546             : INLINE void
    2547           0 : F2m_clear(GEN x, long a, long b) { F2v_clear(gel(x,b), a); }
    2548             : 
    2549             : INLINE void
    2550           0 : F2m_set(GEN x, long a, long b) { F2v_set(gel(x,b), a); }
    2551             : 
    2552             : INLINE void
    2553     1577797 : F2m_flip(GEN x, long a, long b) { F2v_flip(gel(x,b), a); }
    2554             : 
    2555             : /* F3m */
    2556             : 
    2557             : INLINE ulong
    2558           0 : F3m_coeff(GEN x, long a, long b) { return F3v_coeff(gel(x,b), a); }
    2559             : 
    2560             : INLINE void
    2561           0 : F3m_set(GEN x, long a, long b, ulong c) { F3v_set(gel(x,b), a, c); }
    2562             : 
    2563             : /* ARITHMETIC */
    2564             : INLINE GEN
    2565       33935 : matpascal(long n) { return matqpascal(n, NULL); }
    2566             : INLINE long
    2567     2729825 : Z_issquare(GEN x) { return Z_issquareall(x, NULL); }
    2568             : INLINE long
    2569          14 : Z_ispower(GEN x, ulong k) { return Z_ispowerall(x, k, NULL); }
    2570             : INLINE GEN
    2571     6456923 : sqrti(GEN x) { return sqrtremi(x,NULL); }
    2572             : INLINE GEN
    2573     7347166 : gaddgs(GEN y, long s) { return gaddsg(s,y); }
    2574             : INLINE int
    2575       74900 : gcmpgs(GEN y, long s) { return -gcmpsg(s,y); }
    2576             : INLINE int
    2577       24843 : gequalgs(GEN y, long s) { return gequalsg(s,y); }
    2578             : INLINE GEN
    2579           0 : gmaxsg(long s, GEN y) { return gmaxgs(y,s); }
    2580             : INLINE GEN
    2581           0 : gminsg(long s, GEN y) { return gmings(y,s); }
    2582             : INLINE GEN
    2583    59552192 : gmulgs(GEN y, long s) { return gmulsg(s,y); }
    2584             : INLINE GEN
    2585     1112326 : gsubgs(GEN y, long s) { return gaddgs(y, -s); }
    2586             : INLINE GEN
    2587      211950 : gdivsg(long s, GEN y) { return gdiv(stoi(s), y); }
    2588             : 
    2589             : INLINE GEN
    2590    13510226 : gmax_shallow(GEN x, GEN y) { return gcmp(x,y)<0? y: x; }
    2591             : INLINE GEN
    2592      910800 : gmin_shallow(GEN x, GEN y) { return gcmp(x,y)<0? x: y; }
    2593             : 
    2594             : /* x t_COMPLEX */
    2595             : INLINE GEN
    2596    55478895 : cxnorm(GEN x) { return gadd(gsqr(gel(x,1)), gsqr(gel(x,2))); }
    2597             : /* q t_QUAD */
    2598             : INLINE GEN
    2599      138873 : quadnorm(GEN q)
    2600             : {
    2601      138873 :   GEN X = gel(q,1), b = gel(X,3), c = gel(X,2);
    2602      138873 :   GEN z, u = gel(q,3), v = gel(q,2);
    2603      138873 :   if (typ(u) == t_INT && typ(v) == t_INT) /* generic case */
    2604             :   {
    2605      138684 :     z = signe(b)? mulii(v, addii(u,v)): sqri(v);
    2606      138684 :     return addii(z, mulii(c, sqri(u)));
    2607             :   }
    2608             :   else
    2609             :   {
    2610         189 :     z = signe(b)? gmul(v, gadd(u,v)): gsqr(v);
    2611         189 :     return gadd(z, gmul(c, gsqr(u)));
    2612             :   }
    2613             : }
    2614             : /* x a t_QUAD, return the attached discriminant */
    2615             : INLINE GEN
    2616        1015 : quad_disc(GEN x)
    2617             : {
    2618        1015 :   GEN Q = gel(x,1), b = gel(Q,3), c = gel(Q,2), c4 = shifti(c,2);
    2619        1015 :   if (is_pm1(b)) return subsi(1, c4);
    2620         154 :   togglesign_safe(&c4); return c4;
    2621             : }
    2622             : INLINE GEN
    2623       80514 : qfb_disc3(GEN x, GEN y, GEN z) { return subii(sqri(y), shifti(mulii(x,z),2)); }
    2624             : INLINE GEN
    2625    20386339 : qfb_disc(GEN x) { return gel(x,4); }
    2626             : 
    2627             : INLINE GEN
    2628     2775717 : sqrfrac(GEN x)
    2629             : {
    2630     2775717 :   GEN z = cgetg(3,t_FRAC);
    2631     2775717 :   gel(z,1) = sqri(gel(x,1));
    2632     2775717 :   gel(z,2) = sqri(gel(x,2)); return z;
    2633             : }
    2634             : 
    2635             : INLINE void
    2636    12054978 : normalize_frac(GEN z) {
    2637    12054978 :   if (signe(gel(z,2)) < 0) { togglesign(gel(z,1)); setabssign(gel(z,2)); }
    2638    12054978 : }
    2639             : 
    2640             : INLINE GEN
    2641      673734 : powii(GEN x, GEN n)
    2642             : {
    2643      673734 :   long ln = lgefint(n);
    2644      673734 :   if (ln == 3) {
    2645             :     GEN z;
    2646      651471 :     if (signe(n) > 0) return powiu(x, n[2]);
    2647       69106 :     z = cgetg(3, t_FRAC);
    2648       69112 :     gel(z,1) = gen_1;
    2649       69112 :     gel(z,2) = powiu(x, n[2]);
    2650       69115 :     return z;
    2651             :   }
    2652       22263 :   if (ln == 2) return gen_1; /* rare */
    2653             :   /* should never happen */
    2654           0 :   return powgi(x, n); /* overflow unless x = 0, 1, -1 */
    2655             : }
    2656             : INLINE GEN
    2657        1533 : powIs(long n) {
    2658        1533 :   switch(n & 3)
    2659             :   {
    2660          63 :     case 1: return mkcomplex(gen_0,gen_1);
    2661         385 :     case 2: return gen_m1;
    2662         721 :     case 3: return mkcomplex(gen_0,gen_m1);
    2663             :   }
    2664         364 :   return gen_1;
    2665             : }
    2666             : 
    2667             : /*******************************************************************/
    2668             : /*                                                                 */
    2669             : /*                             ASSIGNMENTS                         */
    2670             : /*                                                                 */
    2671             : /*******************************************************************/
    2672           0 : INLINE void mpexpz(GEN x, GEN z)
    2673           0 : { pari_sp av = avma; gaffect(mpexp(x), z); set_avma(av); }
    2674           0 : INLINE void mplogz(GEN x, GEN z)
    2675           0 : { pari_sp av = avma; gaffect(mplog(x), z); set_avma(av); }
    2676           0 : INLINE void mpcosz(GEN x, GEN z)
    2677           0 : { pari_sp av = avma; gaffect(mpcos(x), z); set_avma(av); }
    2678           0 : INLINE void mpsinz(GEN x, GEN z)
    2679           0 : { pari_sp av = avma; gaffect(mpsin(x), z); set_avma(av); }
    2680           0 : INLINE void gnegz(GEN x, GEN z)
    2681           0 : { pari_sp av = avma; gaffect(gneg(x), z); set_avma(av); }
    2682           0 : INLINE void gabsz(GEN x, long prec, GEN z)
    2683           0 : { pari_sp av = avma; gaffect(gabs(x,prec), z); set_avma(av); }
    2684           0 : INLINE void gaddz(GEN x, GEN y, GEN z)
    2685           0 : { pari_sp av = avma; gaffect(gadd(x,y), z); set_avma(av); }
    2686           0 : INLINE void gsubz(GEN x, GEN y, GEN z)
    2687           0 : { pari_sp av = avma; gaffect(gsub(x,y), z); set_avma(av); }
    2688           0 : INLINE void gmulz(GEN x, GEN y, GEN z)
    2689           0 : { pari_sp av = avma; gaffect(gmul(x,y), z); set_avma(av); }
    2690           0 : INLINE void gdivz(GEN x, GEN y, GEN z)
    2691           0 : { pari_sp av = avma; gaffect(gdiv(x,y), z); set_avma(av); }
    2692           0 : INLINE void gdiventz(GEN x, GEN y, GEN z)
    2693           0 : { pari_sp av = avma; gaffect(gdivent(x,y), z); set_avma(av); }
    2694           0 : INLINE void gmodz(GEN x, GEN y, GEN z)
    2695           0 : { pari_sp av = avma; gaffect(gmod(x,y), z); set_avma(av); }
    2696           0 : INLINE void gmul2nz(GEN x, long s, GEN z)
    2697           0 : { pari_sp av = avma; gaffect(gmul2n(x,s), z); set_avma(av); }
    2698           0 : INLINE void gshiftz(GEN x, long s, GEN z)
    2699           0 : { pari_sp av = avma; gaffect(gshift(x,s), z); set_avma(av); }
    2700             : 
    2701             : /*******************************************************************/
    2702             : /*                                                                 */
    2703             : /*                       ELLIPTIC CURVES                           */
    2704             : /*                                                                 */
    2705             : /*******************************************************************/
    2706     4200133 : INLINE GEN ell_get_a1(GEN e) { return gel(e,1); }
    2707     3201886 : INLINE GEN ell_get_a2(GEN e) { return gel(e,2); }
    2708     4030033 : INLINE GEN ell_get_a3(GEN e) { return gel(e,3); }
    2709     3972614 : INLINE GEN ell_get_a4(GEN e) { return gel(e,4); }
    2710     4760436 : INLINE GEN ell_get_a6(GEN e) { return gel(e,5); }
    2711     3384501 : INLINE GEN ell_get_b2(GEN e) { return gel(e,6); }
    2712     1055162 : INLINE GEN ell_get_b4(GEN e) { return gel(e,7); }
    2713     1661229 : INLINE GEN ell_get_b6(GEN e) { return gel(e,8); }
    2714     1488466 : INLINE GEN ell_get_b8(GEN e) { return gel(e,9); }
    2715     6056554 : INLINE GEN ell_get_c4(GEN e) { return gel(e,10); }
    2716     7258989 : INLINE GEN ell_get_c6(GEN e) { return gel(e,11); }
    2717     9214521 : INLINE GEN ell_get_disc(GEN e) { return gel(e,12); }
    2718     1042106 : INLINE GEN ell_get_j(GEN e) { return gel(e,13); }
    2719     9890733 : INLINE long ell_get_type(GEN e) { return mael(e,14,1); }
    2720     1569888 : INLINE GEN ellff_get_field(GEN x) { return gmael(x, 15, 1); }
    2721      682639 : INLINE GEN ellff_get_a4a6(GEN x)  { return gmael(x, 15, 2); }
    2722        1407 : INLINE GEN ellQp_get_zero(GEN x) { return gmael(x, 15, 1); }
    2723         287 : INLINE long ellQp_get_prec(GEN E) { GEN z = ellQp_get_zero(E); return valp(z); }
    2724        1085 : INLINE GEN ellQp_get_p(GEN E) { GEN z = ellQp_get_zero(E); return gel(z,2); }
    2725       37478 : INLINE long ellR_get_prec(GEN x) { return nbits2prec(mael3(x, 15, 1, 1)); }
    2726       17099 : INLINE long ellR_get_sign(GEN x) { return mael3(x, 15, 1, 2); }
    2727      713840 : INLINE GEN ellnf_get_nf(GEN x) { return checknf_i(gmael(x,15,1)); }
    2728          56 : INLINE GEN ellnf_get_bnf(GEN x) { return checkbnf_i(gmael(x,15,1)); }
    2729             : 
    2730     4124622 : INLINE int checkell_i(GEN e) { return typ(e) == t_VEC && lg(e) == 17; }
    2731    38033339 : INLINE int ell_is_inf(GEN z) { return lg(z) == 2; }
    2732      918819 : INLINE GEN ellinf(void) { return mkvec(gen_0); }
    2733             : 
    2734             : /*******************************************************************/
    2735             : /*                                                                 */
    2736             : /*                    ALGEBRAIC NUMBER THEORY                      */
    2737             : /*                                                                 */
    2738             : /*******************************************************************/
    2739    14870773 : INLINE GEN modpr_get_pr(GEN x)  { return gel(x,3); }
    2740      725457 : INLINE GEN modpr_get_p(GEN x)  { return pr_get_p(modpr_get_pr(x)); }
    2741     6361791 : INLINE GEN modpr_get_T(GEN x)  { return lg(x) == 4? NULL: gel(x,4); }
    2742             : 
    2743    60893140 : INLINE GEN pr_get_p(GEN pr)  { return gel(pr,1); }
    2744     9264996 : INLINE GEN pr_get_gen(GEN pr){ return gel(pr,2); }
    2745             : /* .[2] instead of itos works: e and f are small positive integers */
    2746     7020634 : INLINE long pr_get_e(GEN pr) { return gel(pr,3)[2]; }
    2747    22677245 : INLINE long pr_get_f(GEN pr) { return gel(pr,4)[2]; }
    2748    38498932 : INLINE GEN pr_get_tau(GEN pr){ return gel(pr,5); }
    2749             : INLINE int
    2750     6756033 : pr_is_inert(GEN P) { return typ(pr_get_tau(P)) == t_INT; }
    2751             : INLINE GEN
    2752     3040074 : pr_norm(GEN pr) { return powiu(pr_get_p(pr), pr_get_f(pr)); }
    2753             : INLINE ulong
    2754      156280 : upr_norm(GEN pr) { return upowuu(pr_get_p(pr)[2], pr_get_f(pr)); }
    2755             : 
    2756             : /* assume nf a genuine nf */
    2757             : INLINE long
    2758      814904 : nf_get_varn(GEN nf) { return varn(gel(nf,1)); }
    2759             : INLINE GEN
    2760    65308929 : nf_get_pol(GEN nf) { return gel(nf,1); }
    2761             : INLINE long
    2762    46295549 : nf_get_degree(GEN nf) { return degpol( nf_get_pol(nf) ); }
    2763             : INLINE long
    2764     6031595 : nf_get_r1(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,1)); }
    2765             : INLINE long
    2766        3032 : nf_get_r2(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,2)); }
    2767             : INLINE GEN
    2768      431532 : nf_get_disc(GEN nf) { return gel(nf,3); }
    2769             : INLINE GEN
    2770     2242421 : nf_get_index(GEN nf) { return gel(nf,4); }
    2771             : INLINE GEN
    2772     3869164 : nf_get_M(GEN nf) { return gmael(nf,5,1); }
    2773             : INLINE GEN
    2774     2374691 : nf_get_G(GEN nf) { return gmael(nf,5,2); }
    2775             : INLINE GEN
    2776     2929997 : nf_get_roundG(GEN nf) { return gmael(nf,5,3); }
    2777             : INLINE GEN
    2778       21535 : nf_get_Tr(GEN nf) { return gmael(nf,5,4); }
    2779             : INLINE GEN
    2780        5593 : nf_get_diff(GEN nf) { return gmael(nf,5,5); }
    2781             : INLINE GEN
    2782       39270 : nf_get_ramified_primes(GEN nf) { return gmael(nf,5,8); }
    2783             : INLINE GEN
    2784     1061111 : nf_get_roots(GEN nf) { return gel(nf,6); }
    2785             : INLINE GEN
    2786        1456 : nf_get_zk(GEN nf)
    2787             : {
    2788        1456 :   GEN y = gel(nf,7), D = gel(y, 1);
    2789        1456 :   if (typ(D) == t_POL) D = gel(D, 2);
    2790        1456 :   if (!equali1(D)) y = gdiv(y, D);
    2791        1456 :   return y;
    2792             : }
    2793             : INLINE GEN
    2794     2916423 : nf_get_zkprimpart(GEN nf)
    2795             : {
    2796     2916423 :   GEN y = gel(nf,7);
    2797             :   /* test for old format of nf.zk: non normalized */
    2798     2916423 :   if (!equali1(gel(nf,4)) && gequal1(gel(y,1))) y = Q_remove_denom(y,NULL);
    2799     2916440 :   return y;
    2800             : }
    2801             : INLINE GEN
    2802     2962722 : nf_get_zkden(GEN nf)
    2803             : {
    2804     2962722 :   GEN y = gel(nf,7), D = gel(y,1);
    2805     2962722 :   if (typ(D) == t_POL) D = gel(D,2);
    2806             :   /* test for old format of nf.zk: non normalized */
    2807     2962722 :   if (!equali1(gel(nf,4)) && equali1(D)) D = Q_denom(y);
    2808     2962715 :   return D;
    2809             : }
    2810             : INLINE GEN
    2811     7251742 : nf_get_invzk(GEN nf) { return gel(nf,8); }
    2812             : INLINE void
    2813       74595 : nf_get_sign(GEN nf, long *r1, long *r2)
    2814             : {
    2815       74595 :   GEN x = gel(nf,2);
    2816       74595 :   *r1 = itou(gel(x,1));
    2817       74595 :   *r2 = itou(gel(x,2));
    2818       74595 : }
    2819             : 
    2820             : INLINE GEN
    2821     1055620 : cyc_get_expo(GEN c) { return lg(c) == 1? gen_1: gel(c,1); }
    2822             : INLINE GEN
    2823      348343 : abgrp_get_no(GEN x) { return gel(x,1); }
    2824             : INLINE GEN
    2825     5355825 : abgrp_get_cyc(GEN x) { return gel(x,2); }
    2826             : INLINE GEN
    2827      818265 : abgrp_get_gen(GEN x) { return gel(x,3); }
    2828             : INLINE GEN
    2829     4110284 : bnf_get_nf(GEN bnf) { return gel(bnf,7); }
    2830             : INLINE GEN
    2831     2266846 : bnf_get_clgp(GEN bnf) { return gmael(bnf,8,1); }
    2832             : INLINE GEN
    2833       30246 : bnf_get_no(GEN bnf) { return abgrp_get_no(bnf_get_clgp(bnf)); }
    2834             : INLINE GEN
    2835     1474412 : bnf_get_cyc(GEN bnf) { return abgrp_get_cyc(bnf_get_clgp(bnf)); }
    2836             : INLINE GEN
    2837      762030 : bnf_get_gen(GEN bnf)  { return abgrp_get_gen(bnf_get_clgp(bnf)); }
    2838             : INLINE GEN
    2839         608 : bnf_get_reg(GEN bnf) { return gmael(bnf,8,2); }
    2840             : INLINE GEN
    2841     1093598 : bnf_get_logfu(GEN bnf) { return gel(bnf,3); }
    2842             : INLINE GEN
    2843      457147 : bnf_get_sunits(GEN bnf)
    2844      457147 : { GEN s = gmael(bnf,8,3); return typ(s) == t_INT? NULL: s; }
    2845             : INLINE GEN
    2846      287894 : bnf_get_tuU(GEN bnf) { return gmael3(bnf,8,4,2); }
    2847             : INLINE long
    2848      262891 : bnf_get_tuN(GEN bnf) { return gmael3(bnf,8,4,1)[2]; }
    2849             : INLINE GEN
    2850      286871 : bnf_get_fu_nocheck(GEN bnf) { return gmael(bnf,8,5); }
    2851             : INLINE GEN
    2852       25998 : nfV_to_scalar_or_alg(GEN nf, GEN x)
    2853       62404 : { pari_APPLY_same(nf_to_scalar_or_alg(nf, gel(x,i))) }
    2854             : INLINE GEN
    2855       25626 : bnf_get_fu(GEN bnf) {
    2856       25626 :   GEN fu = bnf_build_units(bnf), nf = bnf_get_nf(bnf);
    2857       25627 :   if (typ(fu) == t_MAT) pari_err(e_MISC,"missing units in bnf");
    2858       25627 :   return nfV_to_scalar_or_alg(nf, vecslice(fu, 2, lg(fu)-1));
    2859             : }
    2860             : 
    2861             : INLINE GEN
    2862     1589780 : bnr_get_bnf(GEN bnr) { return gel(bnr,1); }
    2863             : INLINE GEN
    2864      913780 : bnr_get_bid(GEN bnr) { return gel(bnr,2); }
    2865             : INLINE GEN
    2866      137231 : bnr_get_mod(GEN bnr) { return gmael(bnr,2,1); }
    2867             : INLINE GEN
    2868      564231 : bnr_get_nf(GEN bnr) { return gmael(bnr,1,7); }
    2869             : INLINE GEN
    2870     1696730 : bnr_get_clgp(GEN bnr) { return gel(bnr,5); }
    2871             : INLINE GEN
    2872      311248 : bnr_get_no(GEN bnr) { return abgrp_get_no(bnr_get_clgp(bnr)); }
    2873             : INLINE GEN
    2874     1368645 : bnr_get_cyc(GEN bnr) { return abgrp_get_cyc(bnr_get_clgp(bnr)); }
    2875             : INLINE GEN
    2876          70 : bnr_get_gen_nocheck(GEN bnr) { return abgrp_get_gen(bnr_get_clgp(bnr)); }
    2877             : INLINE GEN
    2878        7833 : bnr_get_gen(GEN bnr) {
    2879        7833 :   GEN G = bnr_get_clgp(bnr);
    2880        7833 :   if (lg(G) !=  4)
    2881           0 :     pari_err(e_MISC,"missing bnr generators: please use bnrinit(,,1)");
    2882        7833 :   return gel(G,3);
    2883             : }
    2884             : 
    2885             : INLINE GEN
    2886      369400 : bid_get_mod(GEN bid) { return gel(bid,1); }
    2887             : INLINE GEN
    2888       68418 : bid_get_ideal(GEN bid) { return gmael(bid,1,1); }
    2889             : INLINE GEN
    2890       33460 : bid_get_arch(GEN bid) { return gmael(bid,1,2); }
    2891             : INLINE GEN
    2892     2356334 : bid_get_grp(GEN bid) { return gel(bid,2); }
    2893             : INLINE GEN
    2894     1291090 : bid_get_fact(GEN bid) { return gmael(bid,3,1); }
    2895             : INLINE GEN
    2896     1004195 : bid_get_fact2(GEN bid) { return gmael(bid,3,2); }
    2897             : INLINE GEN
    2898      970459 : bid_get_sprk(GEN bid) { return gmael(bid,4,1); }
    2899             : INLINE GEN
    2900       50750 : bid_get_sarch(GEN bid) { return gmael(bid,4,2); }
    2901             : INLINE GEN
    2902     1195752 : bid_get_archp(GEN bid) { return gmael3(bid,4,2,2); }
    2903             : INLINE GEN
    2904     1340130 : bid_get_U(GEN bid) { return gel(bid,5); }
    2905             : INLINE GEN
    2906           0 : bid_get_no(GEN bid) { return abgrp_get_no(bid_get_grp(bid)); }
    2907             : INLINE GEN
    2908     2303704 : bid_get_cyc(GEN bid) { return abgrp_get_cyc(bid_get_grp(bid)); }
    2909             : INLINE GEN
    2910           0 : bid_get_gen_nocheck(GEN bid)  { return abgrp_get_gen(bid_get_grp(bid)); }
    2911             : INLINE GEN
    2912       52038 : bid_get_gen(GEN bid) {
    2913       52038 :   GEN G = bid_get_grp(bid);
    2914       52038 :   if (lg(G) != 4) pari_err(e_MISC,"missing bid generators. Use idealstar(,,2)");
    2915       52038 :   return abgrp_get_gen(G);
    2916             : }
    2917             : 
    2918             : INLINE GEN
    2919    29703604 : znstar_get_N(GEN G) { return gmael(G,1,1); }
    2920             : INLINE GEN
    2921     6897527 : znstar_get_faN(GEN G) { return gel(G,3); }
    2922             : INLINE GEN
    2923           7 : znstar_get_no(GEN G) { return abgrp_get_no(gel(G,2)); }
    2924             : INLINE GEN
    2925      193382 : znstar_get_cyc(GEN G) { return abgrp_get_cyc(gel(G,2)); }
    2926             : INLINE GEN
    2927           7 : znstar_get_gen(GEN G) { return abgrp_get_gen(gel(G,2)); }
    2928             : INLINE GEN
    2929     7574231 : znstar_get_conreycyc(GEN G) { return gmael(G,4,5); }
    2930             : INLINE GEN
    2931     3131926 : znstar_get_conreygen(GEN G) { return gmael(G,4,4); }
    2932             : INLINE GEN
    2933       46704 : znstar_get_Ui(GEN G) { return gmael(G,4,3); }
    2934             : INLINE GEN
    2935      120932 : znstar_get_U(GEN G) { return gel(G,5); }
    2936             : INLINE GEN
    2937     2735215 : znstar_get_pe(GEN G) { return gmael(G,4,1); }
    2938             : INLINE GEN
    2939       35542 : gal_get_pol(GEN gal) { return gel(gal,1); }
    2940             : INLINE GEN
    2941        5838 : gal_get_p(GEN gal) { return gmael(gal,2,1); }
    2942             : INLINE GEN
    2943          91 : gal_get_e(GEN gal) { return gmael(gal,2,2); }
    2944             : INLINE GEN
    2945       23271 : gal_get_mod(GEN gal) { return gmael(gal,2,3); }
    2946             : INLINE GEN
    2947       31769 : gal_get_roots(GEN gal) { return gel(gal,3); }
    2948             : INLINE GEN
    2949       26967 : gal_get_invvdm(GEN gal) { return gel(gal,4); }
    2950             : INLINE GEN
    2951       26967 : gal_get_den(GEN gal) { return gel(gal,5); }
    2952             : INLINE GEN
    2953       79078 : gal_get_group(GEN gal) { return gel(gal,6); }
    2954             : INLINE GEN
    2955        8841 : gal_get_gen(GEN gal) { return gel(gal,7); }
    2956             : INLINE GEN
    2957        6832 : gal_get_orders(GEN gal) { return gel(gal,8); }
    2958             : 
    2959             : /* assume rnf a genuine rnf */
    2960             : INLINE long
    2961     1237180 : rnf_get_degree(GEN rnf) { return degpol(rnf_get_pol(rnf)); }
    2962             : INLINE long
    2963       16758 : rnf_get_nfdegree(GEN rnf) { return degpol(nf_get_pol(rnf_get_nf(rnf))); }
    2964             : INLINE long
    2965      777028 : rnf_get_absdegree(GEN rnf) { return degpol(gmael(rnf,11,1)); }
    2966             : INLINE GEN
    2967         700 : rnf_get_idealdisc(GEN rnf) { return gmael(rnf,3,1); }
    2968             : INLINE GEN
    2969         749 : rnf_get_k(GEN rnf) { return gmael(rnf,11,3); }
    2970             : INLINE GEN
    2971         861 : rnf_get_alpha(GEN rnf) { return gmael(rnf, 11, 2); }
    2972             : INLINE GEN
    2973      442330 : rnf_get_nf(GEN rnf) { return gel(rnf,10); }
    2974             : INLINE GEN
    2975        3997 : rnf_get_nfzk(GEN rnf) { return gel(rnf,2); }
    2976             : INLINE GEN
    2977      215460 : rnf_get_polabs(GEN rnf) { return gmael(rnf,11,1); }
    2978             : INLINE GEN
    2979     1484063 : rnf_get_pol(GEN rnf) { return gel(rnf,1); }
    2980             : INLINE GEN
    2981         175 : rnf_get_disc(GEN rnf) { return gel(rnf,3); }
    2982             : INLINE GEN
    2983         105 : rnf_get_index(GEN rnf) { return gel(rnf,4); }
    2984             : INLINE GEN
    2985        1631 : rnf_get_ramified_primes(GEN rnf) { return gel(rnf,5); }
    2986             : INLINE long
    2987         231 : rnf_get_varn(GEN rnf) { return varn(gel(rnf,1)); }
    2988             : INLINE GEN
    2989      189133 : rnf_get_nfpol(GEN rnf) { return gmael(rnf,10,1); }
    2990             : INLINE long
    2991        3332 : rnf_get_nfvarn(GEN rnf) { return varn(gmael(rnf,10,1)); }
    2992             : INLINE GEN
    2993        3577 : rnf_get_zk(GEN rnf) { return gel(rnf,7); }
    2994             : INLINE GEN
    2995      103257 : rnf_get_map(GEN rnf) { return gel(rnf,11); }
    2996             : INLINE GEN
    2997        1197 : rnf_get_invzk(GEN rnf) { return gel(rnf,8); }
    2998             : 
    2999             : /* I integral ZM (not HNF), G ZM, rounded Cholesky form of a weighted
    3000             :  * T2 matrix. Reduce I wrt G */
    3001             : INLINE GEN
    3002      472074 : idealpseudored(GEN I, GEN G)
    3003      472074 : { return ZM_mul(I, ZM_lll(ZM_mul(G, I), 0.99, LLL_IM)); }
    3004             : 
    3005             : /* Same I, G; m in I with T2(m) small */
    3006             : INLINE GEN
    3007      126536 : idealpseudomin(GEN I, GEN G)
    3008             : {
    3009      126536 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    3010      126536 :   return ZM_ZC_mul(I, gel(u,1));
    3011             : }
    3012             : /* Same I,G; irrational m in I with T2(m) small */
    3013             : INLINE GEN
    3014           0 : idealpseudomin_nonscalar(GEN I, GEN G)
    3015             : {
    3016           0 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    3017           0 :   GEN m = ZM_ZC_mul(I, gel(u,1));
    3018           0 :   if (ZV_isscalar(m) && lg(u) > 2) m = ZM_ZC_mul(I, gel(u,2));
    3019           0 :   return m;
    3020             : }
    3021             : /* Same I,G; t_VEC of irrational m in I with T2(m) small */
    3022             : INLINE GEN
    3023      393879 : idealpseudominvec(GEN I, GEN G)
    3024             : {
    3025      393879 :   long i, j, k, n = lg(I)-1;
    3026      393879 :   GEN x, L, b = idealpseudored(I, G);
    3027      393878 :   L = cgetg(1 + (n*(n+1))/2, t_VEC);
    3028     1495620 :   for (i = k = 1; i <= n; i++)
    3029             :   {
    3030     1101742 :     x = gel(b,i);
    3031     1101742 :     if (!ZV_isscalar(x)) gel(L,k++) = x;
    3032             :   }
    3033     1101740 :   for (i = 2; i <= n; i++)
    3034     1894178 :     for (j = 1; j < i; j++)
    3035             :     {
    3036     1186316 :       x = ZC_add(gel(b,i),gel(b,j));
    3037     1186315 :       if (!ZV_isscalar(x)) gel(L,k++) = x;
    3038             :     }
    3039      393877 :   setlg(L,k); return L;
    3040             : }
    3041             : 
    3042             : INLINE GEN
    3043       13865 : idealred_elt(GEN nf, GEN I) {
    3044       13865 :   pari_sp av = avma;
    3045       13865 :   GEN u = idealpseudomin(I, nf_get_roundG(nf));
    3046       13865 :   return gerepileupto(av, u);
    3047             : }
    3048             : INLINE GEN
    3049      121801 : idealred(GEN nf, GEN I) { return idealred0(nf, I, NULL); }
    3050             : 
    3051             : INLINE GEN
    3052        2142 : idealchineseinit(GEN nf, GEN x)
    3053        2142 : { return idealchinese(nf,x,NULL); }
    3054             : 
    3055             : /*******************************************************************/
    3056             : /*                                                                 */
    3057             : /*                              CLOSURES                           */
    3058             : /*                                                                 */
    3059             : /*******************************************************************/
    3060   244963565 : INLINE long closure_arity(GEN C)          { return ((ulong)C[1])&ARITYBITS; }
    3061    36118675 : INLINE long closure_is_variadic(GEN C) { return !!(((ulong)C[1])&VARARGBITS); }
    3062   202862717 : INLINE const char *closure_codestr(GEN C)  { return GSTR(gel(C,2))-1; }
    3063           0 : INLINE GEN closure_get_code(GEN C)  { return gel(C,2); }
    3064   202846565 : INLINE GEN closure_get_oper(GEN C)  { return gel(C,3); }
    3065   202830030 : INLINE GEN closure_get_data(GEN C)  { return gel(C,4); }
    3066       10780 : INLINE GEN closure_get_dbg(GEN C)   { return gel(C,5); }
    3067       25483 : INLINE GEN closure_get_text(GEN C)  { return gel(C,6); }
    3068     7343563 : INLINE GEN closure_get_frame(GEN C) { return gel(C,7); }
    3069             : 
    3070             : /*******************************************************************/
    3071             : /*                                                                 */
    3072             : /*                               ERRORS                            */
    3073             : /*                                                                 */
    3074             : /*******************************************************************/
    3075             : INLINE long
    3076       55346 : err_get_num(GEN e) { return e[1]; }
    3077             : INLINE GEN
    3078         189 : err_get_compo(GEN e, long i) { return gel(e, i+1); }
    3079             : 
    3080             : INLINE void
    3081          14 : pari_err_BUG(const char *f) { pari_err(e_BUG,f); }
    3082             : INLINE void
    3083           7 : pari_err_CONSTPOL(const char *f) { pari_err(e_CONSTPOL, f); }
    3084             : INLINE void
    3085          70 : pari_err_COPRIME(const char *f, GEN x, GEN y) { pari_err(e_COPRIME, f,x,y); }
    3086             : INLINE void
    3087         529 : pari_err_DIM(const char *f) { pari_err(e_DIM, f); }
    3088             : INLINE void
    3089           0 : pari_err_FILE(const char *f, const char *g) { pari_err(e_FILE, f,g); }
    3090             : INLINE void
    3091           0 : pari_err_FILEDESC(const char *f, long n) { pari_err(e_FILEDESC, f,n); }
    3092             : INLINE void
    3093          91 : pari_err_FLAG(const char *f) { pari_err(e_FLAG,f); }
    3094             : INLINE void
    3095         441 : pari_err_IMPL(const char *f) { pari_err(e_IMPL,f); }
    3096             : INLINE void
    3097       19870 : pari_err_INV(const char *f, GEN x) { pari_err(e_INV,f,x); }
    3098             : INLINE void
    3099          63 : pari_err_IRREDPOL(const char *f, GEN x) { pari_err(e_IRREDPOL, f,x); }
    3100             : INLINE void
    3101        2260 : 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); }
    3102             : INLINE void
    3103         200 : pari_err_COMPONENT(const char *f, const char *op, GEN l, GEN x) { pari_err(e_COMPONENT, f,op,l,x); }
    3104             : INLINE void
    3105           0 : pari_err_MAXPRIME(ulong c) { pari_err(e_MAXPRIME, c); }
    3106             : INLINE void
    3107         378 : pari_err_OP(const char *f, GEN x, GEN y) { pari_err(e_OP, f,x,y); }
    3108             : INLINE void
    3109         114 : pari_err_OVERFLOW(const char *f) { pari_err(e_OVERFLOW, f); }
    3110             : INLINE void
    3111         225 : pari_err_PREC(const char *f) { pari_err(e_PREC,f); }
    3112             : INLINE void
    3113           0 : pari_err_PACKAGE(const char *f) { pari_err(e_PACKAGE,f); }
    3114             : INLINE void
    3115          77 : pari_err_PRIME(const char *f, GEN x) { pari_err(e_PRIME, f,x); }
    3116             : INLINE void
    3117         749 : pari_err_MODULUS(const char *f, GEN x, GEN y) { pari_err(e_MODULUS, f,x,y); }
    3118             : INLINE void
    3119          49 : pari_err_ROOTS0(const char *f) { pari_err(e_ROOTS0, f); }
    3120             : INLINE void
    3121          84 : pari_err_SQRTN(const char *f, GEN x) { pari_err(e_SQRTN, f,x); }
    3122             : INLINE void
    3123       13182 : pari_err_TYPE(const char *f, GEN x) { pari_err(e_TYPE, f,x); }
    3124             : INLINE void
    3125        3388 : pari_err_TYPE2(const char *f, GEN x, GEN y) { pari_err(e_TYPE2, f,x,y); }
    3126             : INLINE void
    3127         280 : pari_err_VAR(const char *f, GEN x, GEN y) { pari_err(e_VAR, f,x,y); }
    3128             : INLINE void
    3129         231 : pari_err_PRIORITY(const char *f, GEN x, const char *op, long v)
    3130         231 : { pari_err(e_PRIORITY, f,x,op,v); }

Generated by: LCOV version 1.13