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.12.1 lcov report (development 24782-f7724578b4) Lines: 1310 1480 88.5 %
Date: 2019-12-06 05:56:26 Functions: 577 652 88.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (C) 2000-2010  The PARI group.
       2             : 
       3             : This file is part of the PARI/GP package.
       4             : 
       5             : PARI/GP is free software; you can redistribute it and/or modify it under the
       6             : terms of the GNU General Public License as published by the Free Software
       7             : Foundation. It is distributed in the hope that it will be useful, but WITHOUT
       8             : ANY WARRANTY WHATSOEVER.
       9             : 
      10             : Check the License for details. You should have received a copy of it, along
      11             : with the package; see the file 'COPYING'. If not, write to the Free Software
      12             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
      13             : 
      14             : /*******************************************************************/
      15             : /*                                                                 */
      16             : /*                          CONSTRUCTORS                           */
      17             : /*                                                                 */
      18             : /*******************************************************************/
      19             : #define retmkfrac(x,y)\
      20             :   do { GEN _v = cgetg(3, t_FRAC);\
      21             :        gel(_v,1) = (x);\
      22             :        gel(_v,2) = (y); return _v; } while(0)
      23             : #define retmkrfrac(x,y)\
      24             :   do { GEN _v = cgetg(3, t_RFRAC);\
      25             :        gel(_v,1) = (x);\
      26             :        gel(_v,2) = (y); return _v; } while(0)
      27             : #define retmkintmod(x,y)\
      28             :   do { GEN _v = cgetg(3, t_INTMOD);\
      29             :        gel(_v,1) = (y);\
      30             :        gel(_v,2) = (x); return _v; } while(0)
      31             : #define retmkcomplex(x,y)\
      32             :   do { GEN _v = cgetg(3, t_COMPLEX);\
      33             :        gel(_v,1) = (x);\
      34             :        gel(_v,2) = (y); return _v; } while(0)
      35             : #define retmkpolmod(x,y)\
      36             :   do { GEN _v = cgetg(3, t_POLMOD);\
      37             :        gel(_v,1) = (y);\
      38             :        gel(_v,2) = (x); return _v; } while(0)
      39             : #define retmkvec(x)\
      40             :   do { GEN _v = cgetg(2, t_VEC);\
      41             :        gel(_v,1) = (x); return _v; } while(0)
      42             : #define retmkvec2(x,y)\
      43             :   do { GEN _v = cgetg(3, t_VEC);\
      44             :        gel(_v,1) = (x);\
      45             :        gel(_v,2) = (y); return _v; } while(0)
      46             : #define retmkvec3(x,y,z)\
      47             :   do { GEN _v = cgetg(4, t_VEC);\
      48             :        gel(_v,1) = (x);\
      49             :        gel(_v,2) = (y);\
      50             :        gel(_v,3) = (z); return _v; } while(0)
      51             : #define retmkqfi(x,y,z)\
      52             :   do { GEN _v = cgetg(4, t_QFI);\
      53             :        gel(_v,1) = (x);\
      54             :        gel(_v,2) = (y);\
      55             :        gel(_v,3) = (z); return _v; } while(0)
      56             : #define retmkqfr(x,y,z,d)\
      57             :   do { GEN _v = cgetg(5, t_QFR);\
      58             :        gel(_v,1) = (x);\
      59             :        gel(_v,2) = (y);\
      60             :        gel(_v,3) = (z);\
      61             :        gel(_v,4) = (d); return _v; } while(0)
      62             : #define retmkquad(x,y,z)\
      63             :   do { GEN _v = cgetg(4, t_QUAD);\
      64             :        gel(_v,1) = (x);\
      65             :        gel(_v,2) = (y);\
      66             :        gel(_v,3) = (z); return _v; } while(0)
      67             : #define retmkvec4(x,y,z,t)\
      68             :   do { GEN _v = cgetg(5, t_VEC);\
      69             :        gel(_v,1) = (x);\
      70             :        gel(_v,2) = (y);\
      71             :        gel(_v,3) = (z);\
      72             :        gel(_v,4) = (t); return _v; } while(0)
      73             : #define retmkvec5(x,y,z,t,u)\
      74             :   do { GEN _v = cgetg(6, t_VEC);\
      75             :        gel(_v,1) = (x);\
      76             :        gel(_v,2) = (y);\
      77             :        gel(_v,3) = (z);\
      78             :        gel(_v,4) = (t);\
      79             :        gel(_v,5) = (u); return _v; } while(0)
      80             : #define retmkcol(x)\
      81             :   do { GEN _v = cgetg(2, t_COL);\
      82             :        gel(_v,1) = (x); return _v; } while(0)
      83             : #define retmkcol2(x,y)\
      84             :   do { GEN _v = cgetg(3, t_COL);\
      85             :        gel(_v,1) = (x);\
      86             :        gel(_v,2) = (y); return _v; } while(0)
      87             : #define retmkcol3(x,y,z)\
      88             :   do { GEN _v = cgetg(4, t_COL);\
      89             :        gel(_v,1) = (x);\
      90             :        gel(_v,2) = (y);\
      91             :        gel(_v,3) = (z); return _v; } while(0)
      92             : #define retmkcol4(x,y,z,t)\
      93             :   do { GEN _v = cgetg(5, t_COL);\
      94             :        gel(_v,1) = (x);\
      95             :        gel(_v,2) = (y);\
      96             :        gel(_v,3) = (z);\
      97             :        gel(_v,4) = (t); return _v; } while(0)
      98             : #define retmkcol5(x,y,z,t,u)\
      99             :   do { GEN _v = cgetg(6, t_COL);\
     100             :        gel(_v,1) = (x);\
     101             :        gel(_v,2) = (y);\
     102             :        gel(_v,3) = (z);\
     103             :        gel(_v,4) = (t);\
     104             :        gel(_v,5) = (u); return _v; } while(0)
     105             : #define retmkcol6(x,y,z,t,u,v)\
     106             :   do { GEN _v = cgetg(7, t_COL);\
     107             :        gel(_v,1) = (x);\
     108             :        gel(_v,2) = (y);\
     109             :        gel(_v,3) = (z);\
     110             :        gel(_v,4) = (t);\
     111             :        gel(_v,5) = (u);\
     112             :        gel(_v,6) = (v); return _v; } while(0)
     113             : #define retmkmat(x)\
     114             :   do { GEN _v = cgetg(2, t_MAT);\
     115             :        gel(_v,1) = (x); return _v; } while(0)
     116             : #define retmkmat2(x,y)\
     117             :   do { GEN _v = cgetg(3, t_MAT);\
     118             :        gel(_v,1) = (x);\
     119             :        gel(_v,2) = (y); return _v; } while(0)
     120             : #define retmkmat3(x,y,z)\
     121             :   do { GEN _v = cgetg(4, t_MAT);\
     122             :        gel(_v,1) = (x);\
     123             :        gel(_v,2) = (y);\
     124             :        gel(_v,3) = (z); return _v; } while(0)
     125             : #define retmkmat4(x,y,z,t)\
     126             :   do { GEN _v = cgetg(5, t_MAT);\
     127             :        gel(_v,1) = (x);\
     128             :        gel(_v,2) = (y);\
     129             :        gel(_v,3) = (z);\
     130             :        gel(_v,4) = (t); return _v; } while(0)
     131             : #define retmkmat5(x,y,z,t,u)\
     132             :   do { GEN _v = cgetg(6, t_MAT);\
     133             :        gel(_v,1) = (x);\
     134             :        gel(_v,2) = (y);\
     135             :        gel(_v,3) = (z);\
     136             :        gel(_v,4) = (t);\
     137             :        gel(_v,5) = (u); return _v; } while(0)
     138             : 
     139             : INLINE GEN
     140     3206477 : mkintmod(GEN x, GEN y) { retmkintmod(x,y); }
     141             : INLINE GEN
     142        3164 : mkintmodu(ulong x, ulong y) {
     143        3164 :   GEN v = cgetg(3,t_INTMOD);
     144        3164 :   gel(v,1) = utoipos(y);
     145        3164 :   gel(v,2) = utoi(x); return v;
     146             : }
     147             : INLINE GEN
     148     3035667 : mkpolmod(GEN x, GEN y) { retmkpolmod(x,y); }
     149             : INLINE GEN
     150    25672045 : mkfrac(GEN x, GEN y) { retmkfrac(x,y); }
     151             : INLINE GEN
     152       32172 : mkfracss(long x, long y) { retmkfrac(stoi(x),utoipos(y)); }
     153             : /* q = n/d a t_FRAC or t_INT; recover (n,d) */
     154             : INLINE void
     155       13916 : Qtoss(GEN q, long *n, long *d)
     156             : {
     157       13916 :   if (typ(q) == t_INT) { *n = itos(q); *d = 1; }
     158        2828 :   else { *n = itos(gel(q,1)); *d = itou(gel(q,2)); }
     159       13916 : }
     160             : INLINE GEN
     161    71394509 : sstoQ(long n, long d)
     162             : {
     163             :   ulong r;
     164             :   long g, q;
     165    71394509 :   if (!n)
     166             :   {
     167      100205 :     if (!d) pari_err_INV("sstoQ",gen_0);
     168      100205 :     return gen_0;
     169             :   }
     170    71294304 :   if (d < 0) { d = -d; n = -n; }
     171    71294304 :   if (d == 1) return stoi(n);
     172    71281949 :   q = udivuu_rem(labs(n),d,&r);
     173    71281949 :   if (!r) return n > 0? utoipos(q): utoineg(q);
     174     3642034 :   g = ugcd(d,r); /* gcd(n,d) */
     175     3642034 :   if (g != 1) { n /= g; d /= g; }
     176     3642034 :   retmkfrac(stoi(n), utoi(d));
     177             : }
     178             : 
     179             : INLINE GEN
     180    16802093 : mkfraccopy(GEN x, GEN y) { retmkfrac(icopy(x), icopy(y)); }
     181             : INLINE GEN
     182          35 : mkrfrac(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     183          35 :   gel(v,1) = x; gel(v,2) = y; return v; }
     184             : INLINE GEN
     185           7 : mkrfraccopy(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     186           7 :   gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     187             : INLINE GEN
     188    20819298 : mkcomplex(GEN x, GEN y) { retmkcomplex(x,y); }
     189             : INLINE GEN
     190      455966 : gen_I(void) { return mkcomplex(gen_0, gen_1); }
     191             : INLINE GEN
     192      268580 : cgetc(long l) { retmkcomplex(cgetr(l), cgetr(l)); }
     193             : INLINE GEN
     194         105 : mkquad(GEN n, GEN x, GEN y) { GEN v = cgetg(4, t_QUAD);
     195         105 :   gel(v,1) = n; gel(v,2) = x; gel(v,3) = y; return v; }
     196             : /* vecsmall */
     197             : INLINE GEN
     198    67104425 : mkvecsmall(long x) { GEN v = cgetg(2, t_VECSMALL); v[1] = x; return v; }
     199             : INLINE GEN
     200   115722736 : mkvecsmall2(long x,long y) { GEN v = cgetg(3, t_VECSMALL);
     201   115737920 :   v[1]=x; v[2]=y; return v; }
     202             : INLINE GEN
     203    57831690 : mkvecsmall3(long x,long y,long z) { GEN v = cgetg(4, t_VECSMALL);
     204    57826812 :   v[1]=x; v[2]=y; v[3]=z; return v; }
     205             : INLINE GEN
     206    11939451 : mkvecsmall4(long x,long y,long z,long t) { GEN v = cgetg(5, t_VECSMALL);
     207    11932845 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; return v; }
     208             : INLINE GEN
     209      468087 : mkvecsmall5(long x,long y,long z,long t,long u) { GEN v = cgetg(6, t_VECSMALL);
     210      468087 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; v[5]=u; return v; }
     211             : 
     212             : INLINE GEN
     213      158116 : mkqfi(GEN x, GEN y, GEN z) { retmkqfi(x,y,z); }
     214             : /* vec */
     215             : INLINE GEN
     216    45904120 : mkvec(GEN x) { retmkvec(x); }
     217             : INLINE GEN
     218   107808368 : mkvec2(GEN x, GEN y) { retmkvec2(x,y); }
     219             : INLINE GEN
     220    64296981 : mkvec3(GEN x, GEN y, GEN z) { retmkvec3(x,y,z); }
     221             : INLINE GEN
     222     7391739 : mkvec4(GEN x, GEN y, GEN z, GEN t) { retmkvec4(x,y,z,t); }
     223             : INLINE GEN
     224    12238172 : mkvec5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkvec5(x,y,z,t,u); }
     225             : INLINE GEN
     226         105 : mkvecs(long x) { retmkvec(stoi(x)); }
     227             : INLINE GEN
     228       25002 : mkvec2s(long x, long y) { retmkvec2(stoi(x),stoi(y)); }
     229             : INLINE GEN
     230      492752 : mkvec3s(long x, long y, long z) { retmkvec3(stoi(x),stoi(y),stoi(z)); }
     231             : INLINE GEN
     232          21 : mkvec4s(long x, long y, long z, long t) { retmkvec4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     233             : INLINE GEN
     234       35756 : mkveccopy(GEN x) { GEN v = cgetg(2, t_VEC); gel(v,1) = gcopy(x); return v; }
     235             : INLINE GEN
     236      100906 : mkvec2copy(GEN x, GEN y) {
     237      100906 :   GEN v = cgetg(3,t_VEC); gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     238             : /* col */
     239             : INLINE GEN
     240     2618421 : mkcol(GEN x) { retmkcol(x); }
     241             : INLINE GEN
     242    26429170 : mkcol2(GEN x, GEN y) { retmkcol2(x,y); }
     243             : INLINE GEN
     244       42707 : mkcol3(GEN x, GEN y, GEN z) { retmkcol3(x,y,z); }
     245             : INLINE GEN
     246           0 : mkcol4(GEN x, GEN y, GEN z, GEN t) { retmkcol4(x,y,z,t); }
     247             : INLINE GEN
     248           0 : mkcol5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkcol5(x,y,z,t,u); }
     249             : INLINE GEN
     250        9579 : mkcol6(GEN x, GEN y, GEN z, GEN t, GEN u, GEN v) { retmkcol6(x,y,z,t,u,v); }
     251             : INLINE GEN
     252         259 : mkcols(long x) { retmkcol(stoi(x)); }
     253             : INLINE GEN
     254     2760786 : mkcol2s(long x, long y) { retmkcol2(stoi(x),stoi(y)); }
     255             : INLINE GEN
     256           0 : mkcol3s(long x, long y, long z) { retmkcol3(stoi(x),stoi(y),stoi(z)); }
     257             : INLINE GEN
     258           0 : mkcol4s(long x, long y, long z, long t) { retmkcol4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     259             : INLINE GEN
     260       49145 : mkcolcopy(GEN x) { GEN v = cgetg(2, t_COL); gel(v,1) = gcopy(x); return v; }
     261             : /* mat */
     262             : INLINE GEN
     263     2815818 : mkmat(GEN x) { retmkmat(x); }
     264             : INLINE GEN
     265    32587079 : mkmat2(GEN x, GEN y) { retmkmat2(x,y); }
     266             : INLINE GEN
     267        2329 : mkmat3(GEN x, GEN y, GEN z) { retmkmat3(x,y,z); }
     268             : INLINE GEN
     269           0 : mkmat4(GEN x, GEN y, GEN z, GEN t) { retmkmat4(x,y,z,t); }
     270             : INLINE GEN
     271           0 : mkmat5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkmat5(x,y,z,t,u); }
     272             : INLINE GEN
     273       27449 : mkmatcopy(GEN x) { GEN v = cgetg(2, t_MAT); gel(v,1) = gcopy(x); return v; }
     274             : INLINE GEN
     275           0 : mkerr(long x) { GEN v = cgetg(2, t_ERROR); v[1] = x; return v; }
     276             : INLINE GEN
     277       88724 : mkoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_1; return v; }
     278             : INLINE GEN
     279       17045 : mkmoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_m1; return v; }
     280             : INLINE long
     281      117894 : inf_get_sign(GEN x) { return signe(gel(x,1)); }
     282             : INLINE GEN
     283       12425 : mkmat22s(long a, long b, long c, long d) {retmkmat2(mkcol2s(a,c),mkcol2s(b,d));}
     284             : INLINE GEN
     285     1620185 : mkmat22(GEN a, GEN b, GEN c, GEN d) { retmkmat2(mkcol2(a,c),mkcol2(b,d)); }
     286             : 
     287             : /* pol */
     288             : INLINE GEN
     289     1037429 : pol_x(long v) {
     290     1037429 :   GEN p = cgetg(4, t_POL);
     291     1037429 :   p[1] = evalsigne(1)|evalvarn(v);
     292     1037429 :   gel(p,2) = gen_0;
     293     1037429 :   gel(p,3) = gen_1; return p;
     294             : }
     295             : /* x^n, assume n >= 0 */
     296             : INLINE GEN
     297     1699668 : pol_xn(long n, long v) {
     298     1699668 :   long i, a = n+2;
     299     1699668 :   GEN p = cgetg(a+1, t_POL);
     300     1699668 :   p[1] = evalsigne(1)|evalvarn(v);
     301     1699668 :   for (i = 2; i < a; i++) gel(p,i) = gen_0;
     302     1699668 :   gel(p,a) = gen_1; return p;
     303             : }
     304             : /* x^n, no assumption on n */
     305             : INLINE GEN
     306         287 : pol_xnall(long n, long v)
     307             : {
     308         287 :   if (n < 0) retmkrfrac(gen_1, pol_xn(-n,v));
     309         280 :   return pol_xn(n, v);
     310             : }
     311             : /* x^n, assume n >= 0 */
     312             : INLINE GEN
     313         203 : polxn_Flx(long n, long sv) {
     314         203 :   long i, a = n+2;
     315         203 :   GEN p = cgetg(a+1, t_VECSMALL);
     316         203 :   p[1] = sv;
     317         203 :   for (i = 2; i < a; i++) p[i] = 0;
     318         203 :   p[a] = 1; return p;
     319             : }
     320             : INLINE GEN
     321     1805073 : pol_1(long v) {
     322     1805073 :   GEN p = cgetg(3, t_POL);
     323     1805073 :   p[1] = evalsigne(1)|evalvarn(v);
     324     1805073 :   gel(p,2) = gen_1; return p;
     325             : }
     326             : INLINE GEN
     327    32793298 : pol_0(long v)
     328             : {
     329    32793298 :   GEN x = cgetg(2,t_POL);
     330    32793298 :   x[1] = evalvarn(v); return x;
     331             : }
     332             : #define retconst_vec(n,x)\
     333             :   do { long _i, _n = (n);\
     334             :        GEN _v = cgetg(_n+1, t_VEC), _x = (x);\
     335             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     336             :        return _v; } while(0)
     337             : INLINE GEN
     338     9264795 : const_vec(long n, GEN x) { retconst_vec(n, x); }
     339             : #define retconst_col(n,x)\
     340             :   do { long _i, _n = (n);\
     341             :        GEN _v = cgetg(_n+1, t_COL), _x = (x);\
     342             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     343             :        return _v; } while(0)
     344             : INLINE GEN
     345     8690693 : const_col(long n, GEN x) { retconst_col(n, x); }
     346             : INLINE GEN
     347    10951873 : const_vecsmall(long n, long c)
     348             : {
     349             :   long i;
     350    10951873 :   GEN V = cgetg(n+1,t_VECSMALL);
     351    10951994 :   for(i=1;i<=n;i++) V[i] = c;
     352    10951994 :   return V;
     353             : }
     354             : 
     355             : /***   ZERO   ***/
     356             : /* O(p^e) */
     357             : INLINE GEN
     358      362036 : zeropadic(GEN p, long e)
     359             : {
     360      362036 :   GEN y = cgetg(5,t_PADIC);
     361      362036 :   gel(y,4) = gen_0;
     362      362036 :   gel(y,3) = gen_1;
     363      362036 :   gel(y,2) = icopy(p);
     364      362036 :   y[1] = evalvalp(e) | _evalprecp(0);
     365      362036 :   return y;
     366             : }
     367             : INLINE GEN
     368         966 : zeropadic_shallow(GEN p, long e)
     369             : {
     370         966 :   GEN y = cgetg(5,t_PADIC);
     371         966 :   gel(y,4) = gen_0;
     372         966 :   gel(y,3) = gen_1;
     373         966 :   gel(y,2) = p;
     374         966 :   y[1] = evalvalp(e) | _evalprecp(0);
     375         966 :   return y;
     376             : }
     377             : /* O(pol_x(v)^e) */
     378             : INLINE GEN
     379      145250 : zeroser(long v, long e)
     380             : {
     381      145250 :   GEN x = cgetg(2, t_SER);
     382      145250 :   x[1] = evalvalp(e) | evalvarn(v); return x;
     383             : }
     384             : INLINE int
     385     5492983 : ser_isexactzero(GEN x)
     386             : {
     387     5492983 :   if (!signe(x)) switch(lg(x))
     388             :   {
     389      137620 :     case 2: return 1;
     390         896 :     case 3: return isexactzero(gel(x,2));
     391             :   }
     392     5354467 :   return 0;
     393             : }
     394             : /* 0 * pol_x(v) */
     395             : INLINE GEN
     396    15564457 : zeropol(long v) { return pol_0(v); }
     397             : /* vector(n) */
     398             : INLINE GEN
     399    39676432 : zerocol(long n)
     400             : {
     401    39676432 :   GEN y = cgetg(n+1,t_COL);
     402    39676561 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     403    39676561 :   return y;
     404             : }
     405             : /* vectorv(n) */
     406             : INLINE GEN
     407    25005793 : zerovec(long n)
     408             : {
     409    25005793 :   GEN y = cgetg(n+1,t_VEC);
     410    25005792 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     411    25005792 :   return y;
     412             : }
     413             : /* matrix(m, n) */
     414             : INLINE GEN
     415       24854 : zeromat(long m, long n)
     416             : {
     417       24854 :   GEN y = cgetg(n+1,t_MAT);
     418       24854 :   GEN v = zerocol(m);
     419       24854 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     420       24854 :   return y;
     421             : }
     422             : /* = zero_zx, sv is a evalvarn()*/
     423             : INLINE GEN
     424      947767 : zero_Flx(long sv) { return pol0_Flx(sv); }
     425             : INLINE GEN
     426    35017312 : zero_Flv(long n)
     427             : {
     428    35017312 :   GEN y = cgetg(n+1,t_VECSMALL);
     429    35019103 :   long i; for (i=1; i<=n; i++) y[i] = 0;
     430    35019103 :   return y;
     431             : }
     432             : /* matrix(m, n) */
     433             : INLINE GEN
     434     1227219 : zero_Flm(long m, long n)
     435             : {
     436     1227219 :   GEN y = cgetg(n+1,t_MAT);
     437     1227211 :   GEN v = zero_Flv(m);
     438     1227220 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     439     1227220 :   return y;
     440             : }
     441             : /* matrix(m, n) */
     442             : INLINE GEN
     443      111812 : zero_Flm_copy(long m, long n)
     444             : {
     445      111812 :   GEN y = cgetg(n+1,t_MAT);
     446      111813 :   long i; for (i=1; i<=n; i++) gel(y,i) = zero_Flv(m);
     447      111814 :   return y;
     448             : }
     449             : 
     450             : INLINE GEN
     451      960759 : zero_F2v(long m)
     452             : {
     453      960759 :   long l = nbits2nlong(m);
     454      960759 :   GEN v  = zero_Flv(l+1);
     455      960759 :   v[1] = m;
     456      960759 :   return v;
     457             : }
     458             : 
     459             : INLINE GEN
     460           0 : zero_F2m(long m, long n)
     461             : {
     462             :   long i;
     463           0 :   GEN M = cgetg(n+1, t_MAT);
     464           0 :   GEN v = zero_F2v(m);
     465           0 :   for (i = 1; i <= n; i++)
     466           0 :     gel(M,i) = v;
     467           0 :   return M;
     468             : }
     469             : 
     470             : 
     471             : INLINE GEN
     472      309326 : zero_F2m_copy(long m, long n)
     473             : {
     474             :   long i;
     475      309326 :   GEN M = cgetg(n+1, t_MAT);
     476      960481 :   for (i = 1; i <= n; i++)
     477      651155 :     gel(M,i)= zero_F2v(m);
     478      309326 :   return M;
     479             : }
     480             : 
     481             : /* matrix(m, n) */
     482             : INLINE GEN
     483     5107467 : zeromatcopy(long m, long n)
     484             : {
     485     5107467 :   GEN y = cgetg(n+1,t_MAT);
     486     5107467 :   long i; for (i=1; i<=n; i++) gel(y,i) = zerocol(m);
     487     5107467 :   return y;
     488             : }
     489             : 
     490             : INLINE GEN
     491       17626 : zerovec_block(long len)
     492             : {
     493             :   long i;
     494       17626 :   GEN blk = cgetg_block(len + 1, t_VEC);
     495      581658 :   for (i = 1; i <= len; ++i)
     496      564032 :     gel(blk, i) = gen_0;
     497       17626 :   return blk;
     498             : }
     499             : 
     500             : /* i-th vector in the standard basis */
     501             : INLINE GEN
     502     1528892 : col_ei(long n, long i) { GEN e = zerocol(n); gel(e,i) = gen_1; return e; }
     503             : INLINE GEN
     504      360721 : vec_ei(long n, long i) { GEN e = zerovec(n); gel(e,i) = gen_1; return e; }
     505             : INLINE GEN
     506          42 : F2v_ei(long n, long i) { GEN e = zero_F2v(n); F2v_set(e,i); return e; }
     507             : INLINE GEN
     508       72688 : vecsmall_ei(long n, long i) { GEN e = zero_zv(n); e[i] = 1; return e; }
     509             : INLINE GEN
     510      682615 : Rg_col_ei(GEN x, long n, long i) { GEN e = zerocol(n); gel(e,i) = x; return e; }
     511             : 
     512             : INLINE GEN
     513    12893434 : shallowcopy(GEN x)
     514    12893434 : { return typ(x) == t_MAT ? RgM_shallowcopy(x): leafcopy(x); }
     515             : 
     516             : /* routines for naive growarrays */
     517             : INLINE GEN
     518    12373180 : vectrunc_init(long l)
     519             : {
     520    12373180 :   GEN z = new_chunk(l);
     521    12373276 :   z[0] = evaltyp(t_VEC) | _evallg(1); return z;
     522             : }
     523             : INLINE GEN
     524      347543 : coltrunc_init(long l)
     525             : {
     526      347543 :   GEN z = new_chunk(l);
     527      347543 :   z[0] = evaltyp(t_COL) | _evallg(1); return z;
     528             : }
     529             : INLINE void
     530   266531018 : lg_increase(GEN x) { x[0]++; }
     531             : INLINE void
     532    51107419 : vectrunc_append(GEN x, GEN t) { gel(x, lg(x)) = t; lg_increase(x); }
     533             : INLINE void
     534       10416 : vectrunc_append_batch(GEN x, GEN y)
     535             : {
     536       10416 :   long i, l = lg(x), ly = lg(y);
     537       10416 :   GEN z = x + l-1;
     538       10416 :   for (i = 1; i < ly; i++) gel(z,i) = gel(y,i);
     539       10416 :   setlg(x, l+ly-1);
     540       10416 : }
     541             : INLINE GEN
     542    88192910 : vecsmalltrunc_init(long l)
     543             : {
     544    88192910 :   GEN z = new_chunk(l);
     545    88192910 :   z[0] = evaltyp(t_VECSMALL) | _evallg(1); return z;
     546             : }
     547             : INLINE void
     548    33619862 : vecsmalltrunc_append(GEN x, long t) { x[ lg(x) ] = t; lg_increase(x); }
     549             : 
     550             : /*******************************************************************/
     551             : /*                                                                 */
     552             : /*                    STRING HASH FUNCTIONS                        */
     553             : /*                                                                 */
     554             : /*******************************************************************/
     555             : INLINE ulong
     556     2098347 : hash_str(const char *str)
     557             : {
     558     2098347 :   ulong hash = 5381UL, c;
     559    23023945 :   while ( (c = (ulong)*str++) )
     560    18827251 :     hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
     561     2098347 :   return hash;
     562             : }
     563             : INLINE ulong
     564     9980621 : hash_str_len(const char *str, long len)
     565             : {
     566     9980621 :   ulong hash = 5381UL;
     567             :   long i;
     568    75479968 :   for (i = 0; i < len; i++)
     569             :   {
     570    65499347 :     ulong c = (ulong)*str++;
     571    65499347 :     hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
     572             :   }
     573     9980621 :   return hash;
     574             : }
     575             : 
     576             : /*******************************************************************/
     577             : /*                                                                 */
     578             : /*                        VEC / COL / VECSMALL                     */
     579             : /*                                                                 */
     580             : /*******************************************************************/
     581             : /* shallow*/
     582             : INLINE GEN
     583           0 : vec_shorten(GEN v, long n)
     584             : {
     585             :   long i;
     586           0 :   GEN V = cgetg(n+1,t_VEC);
     587           0 :   for(i=1;i<=n;i++) gel(V,i) = gel(v,i);
     588           0 :   return V;
     589             : }
     590             : /* shallow*/
     591             : INLINE GEN
     592       13738 : vec_lengthen(GEN v, long n)
     593             : {
     594             :   long i;
     595       13738 :   long l=lg(v);
     596       13738 :   GEN V = cgetg(n+1,t_VEC);
     597       13738 :   for(i=1;i<l;i++) gel(V,i) = gel(v,i);
     598       13738 :   return V;
     599             : }
     600             : /* shallow*/
     601             : INLINE GEN
     602       97600 : vec_append(GEN V, GEN s)
     603             : {
     604       97600 :   long i, l2 = lg(V);
     605       97600 :   GEN res = cgetg(l2+1, typ(V));
     606       97600 :   for (i = 1; i < l2; ++i) gel(res, i) = gel(V,i);
     607       97600 :   gel(res,l2) = s; return res;
     608             : }
     609             : /* shallow*/
     610             : INLINE GEN
     611       40838 : vec_prepend(GEN v, GEN s)
     612             : {
     613       40838 :   long i, l = lg(v);
     614       40838 :   GEN w = cgetg(l+1, typ(v));
     615       40838 :   gel(w,1) = s;
     616       40838 :   for (i = 2; i <= l; ++i) gel(w,i) = gel(v,i-1);
     617       40838 :   return w;
     618             : }
     619             : /* shallow*/
     620             : INLINE GEN
     621           0 : vec_setconst(GEN v, GEN x)
     622             : {
     623           0 :   long i, l = lg(v);
     624           0 :   for (i = 1; i < l; i++) gel(v,i) = x;
     625           0 :   return v;
     626             : }
     627             : INLINE GEN
     628       42282 : vecsmall_shorten(GEN v, long n)
     629             : {
     630             :   long i;
     631       42282 :   GEN V = cgetg(n+1,t_VECSMALL);
     632       42284 :   for(i=1;i<=n;i++) V[i] = v[i];
     633       42284 :   return V;
     634             : }
     635             : INLINE GEN
     636           0 : vecsmall_lengthen(GEN v, long n)
     637             : {
     638           0 :   long i, l = lg(v);
     639           0 :   GEN V = cgetg(n+1,t_VECSMALL);
     640           0 :   for(i=1;i<l;i++) V[i] = v[i];
     641           0 :   return V;
     642             : }
     643             : 
     644             : INLINE GEN
     645     3324536 : vec_to_vecsmall(GEN x)
     646     3324536 : { pari_APPLY_long(itos(gel(x,i))) }
     647             : INLINE GEN
     648      138313 : vecsmall_to_vec(GEN x)
     649      138313 : { pari_APPLY_type(t_VEC, stoi(x[i])) }
     650             : INLINE GEN
     651         742 : vecsmall_to_vec_inplace(GEN z)
     652             : {
     653         742 :   long i, l = lg(z);
     654         742 :   for (i=1; i<l; i++) gel(z,i) = stoi(z[i]);
     655         742 :   settyp(z, t_VEC); return z;
     656             : }
     657             : INLINE GEN
     658     5347745 : vecsmall_to_col(GEN x)
     659     5347745 : { pari_APPLY_type(t_COL, stoi(x[i])) }
     660             : 
     661             : INLINE int
     662     8430513 : vecsmall_lexcmp(GEN x, GEN y)
     663             : {
     664             :   long lx,ly,l,i;
     665     8430513 :   lx = lg(x);
     666     8430513 :   ly = lg(y); l = minss(lx,ly);
     667    41367315 :   for (i=1; i<l; i++)
     668    39277645 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     669     2089670 :   if (lx == ly) return 0;
     670       30578 :   return (lx < ly)? -1 : 1;
     671             : }
     672             : 
     673             : INLINE int
     674    85249612 : vecsmall_prefixcmp(GEN x, GEN y)
     675             : {
     676    85249612 :   long i, lx = lg(x), ly = lg(y), l = minss(lx,ly);
     677   394179177 :   for (i=1; i<l; i++)
     678   374535735 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     679    19643442 :   return 0;
     680             : }
     681             : 
     682             : /*Can be used on t_VEC, but coeffs not gcopy-ed*/
     683             : INLINE GEN
     684       21847 : vecsmall_prepend(GEN V, long s)
     685             : {
     686       21847 :   long i, l2 = lg(V);
     687       21847 :   GEN res = cgetg(l2+1, typ(V));
     688       21847 :   res[1] = s;
     689       21847 :   for (i = 2; i <= l2; ++i) res[i] = V[i - 1];
     690       21847 :   return res;
     691             : }
     692             : 
     693             : INLINE GEN
     694     3137852 : vecsmall_append(GEN V, long s)
     695             : {
     696     3137852 :   long i, l2 = lg(V);
     697     3137852 :   GEN res = cgetg(l2+1, t_VECSMALL);
     698     3137852 :   for (i = 1; i < l2; ++i) res[i] = V[i];
     699     3137852 :   res[l2] = s; return res;
     700             : }
     701             : 
     702             : INLINE GEN
     703      921184 : vecsmall_concat(GEN u, GEN v)
     704             : {
     705      921184 :   long i, l1 = lg(u)-1, l2 = lg(v)-1;
     706      921184 :   GEN res = cgetg(l1+l2+1, t_VECSMALL);
     707      921184 :   for (i = 1; i <= l1; ++i) res[i]    = u[i];
     708      921184 :   for (i = 1; i <= l2; ++i) res[i+l1] = v[i];
     709      921184 :   return res;
     710             : }
     711             : 
     712             : /* return the number of indices where u and v are equal */
     713             : INLINE long
     714           0 : vecsmall_coincidence(GEN u, GEN v)
     715             : {
     716           0 :   long i, s = 0, l = minss(lg(u),lg(v));
     717           0 :   for(i=1; i<l; i++)
     718           0 :     if(u[i] == v[i]) s++;
     719           0 :   return s;
     720             : }
     721             : 
     722             : /* returns the first index i<=n such that x=v[i] if it exists, 0 otherwise */
     723             : INLINE long
     724           0 : vecsmall_isin(GEN v, long x)
     725             : {
     726           0 :   long i, l = lg(v);
     727           0 :   for (i = 1; i < l; i++)
     728           0 :     if (v[i] == x) return i;
     729           0 :   return 0;
     730             : }
     731             : 
     732             : INLINE long
     733          84 : vecsmall_pack(GEN V, long base, long mod)
     734             : {
     735          84 :   long i, s = 0;
     736          84 :   for(i=1; i<lg(V); i++) s = (base*s + V[i]) % mod;
     737          84 :   return s;
     738             : }
     739             : 
     740             : INLINE long
     741          14 : vecsmall_indexmax(GEN x)
     742             : {
     743          14 :   long i, i0 = 1, t = x[1], lx = lg(x);
     744          56 :   for (i=2; i<lx; i++)
     745          42 :     if (x[i] > t) t = x[i0=i];
     746          14 :   return i0;
     747             : }
     748             : 
     749             : INLINE long
     750      242943 : vecsmall_max(GEN x)
     751             : {
     752      242943 :   long i, t = x[1], lx = lg(x);
     753      821724 :   for (i=2; i<lx; i++)
     754      578781 :     if (x[i] > t) t = x[i];
     755      242943 :   return t;
     756             : }
     757             : 
     758             : INLINE long
     759          14 : vecsmall_indexmin(GEN x)
     760             : {
     761          14 :   long i, i0 = 1, t = x[1], lx =lg(x);
     762          56 :   for (i=2; i<lx; i++)
     763          42 :     if (x[i] < t) t = x[i0=i];
     764          14 :   return i0;
     765             : }
     766             : 
     767             : INLINE long
     768        1421 : vecsmall_min(GEN x)
     769             : {
     770        1421 :   long i, t = x[1], lx =lg(x);
     771        9947 :   for (i=2; i<lx; i++)
     772        8526 :     if (x[i] < t) t = x[i];
     773        1421 :   return t;
     774             : }
     775             : 
     776             : INLINE int
     777     5322133 : ZV_isscalar(GEN x)
     778             : {
     779     5322133 :   long l = lg(x);
     780    16338369 :   while (--l > 1)
     781     9927104 :     if (signe(gel(x, l))) return 0;
     782     1089132 :   return 1;
     783             : }
     784             : INLINE int
     785    22431723 : QV_isscalar(GEN x)
     786             : {
     787    22431723 :   long lx = lg(x),i;
     788    24743158 :   for (i=2; i<lx; i++)
     789    24071127 :     if (!isintzero(gel(x, i))) return 0;
     790      672031 :   return 1;
     791             : }
     792             : INLINE int
     793        7296 : RgV_isscalar(GEN x)
     794             : {
     795        7296 :   long lx = lg(x),i;
     796       12168 :   for (i=2; i<lx; i++)
     797       10339 :     if (!gequal0(gel(x, i))) return 0;
     798        1829 :   return 1;
     799             : }
     800             : INLINE int
     801           0 : RgX_isscalar(GEN x)
     802             : {
     803             :   long i;
     804           0 :   for (i=lg(x)-1; i>2; i--)
     805           0 :     if (!gequal0(gel(x, i))) return 0;
     806           0 :   return 1;
     807             : }
     808             : INLINE long
     809    28953609 : RgX_equal_var(GEN x, GEN y) { return varn(x) == varn(y) && RgX_equal(x,y); }
     810             : 
     811             : INLINE int
     812        7805 : RgX_is_rational(GEN x)
     813             : {
     814             :   long i;
     815       42166 :   for (i = lg(x)-1; i > 1; i--)
     816       39051 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     817        3115 :   return 1;
     818             : }
     819             : INLINE int
     820     5043174 : RgX_is_ZX(GEN x)
     821             : {
     822             :   long i;
     823    24931171 :   for (i = lg(x)-1; i > 1; i--)
     824    19940543 :     if (typ(gel(x,i)) != t_INT) return 0;
     825     4990628 :   return 1;
     826             : }
     827             : INLINE int
     828      256032 : RgX_is_QX(GEN x)
     829             : {
     830      256032 :   long k = lg(x)-1;
     831      946060 :   for ( ; k>1; k--)
     832      690301 :     if (!is_rational_t(typ(gel(x,k)))) return 0;
     833      255759 :   return 1;
     834             : }
     835             : INLINE int
     836     2353114 : RgX_is_monomial(GEN x)
     837             : {
     838             :   long i;
     839     2353114 :   if (!signe(x)) return 0;
     840     5868946 :   for (i=lg(x)-2; i>1; i--)
     841     3569518 :     if (!isexactzero(gel(x,i))) return 0;
     842     2299428 :   return 1;
     843             : }
     844             : INLINE int
     845    27504315 : RgV_is_ZV(GEN x)
     846             : {
     847             :   long i;
     848   112676636 :   for (i = lg(x)-1; i > 0; i--)
     849    85175583 :     if (typ(gel(x,i)) != t_INT) return 0;
     850    27501053 :   return 1;
     851             : }
     852             : INLINE int
     853       23653 : RgV_is_QV(GEN x)
     854             : {
     855             :   long i;
     856      106596 :   for (i = lg(x)-1; i > 0; i--)
     857       84651 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     858       21945 :   return 1;
     859             : }
     860             : INLINE long
     861       24241 : RgV_isin_i(GEN v, GEN x, long n)
     862             : {
     863             :   long i;
     864      513345 :   for (i = 1; i <= n; i++)
     865      513086 :     if (gequal(gel(v,i), x)) return i;
     866         259 :   return 0;
     867             : }
     868             : INLINE long
     869       24241 : RgV_isin(GEN v, GEN x) { return RgV_isin_i(v, x, lg(v)-1); }
     870             : 
     871             : /********************************************************************/
     872             : /**                                                                **/
     873             : /**            Dynamic arrays implementation                       **/
     874             : /**                                                                **/
     875             : /********************************************************************/
     876             : INLINE void **
     877   470271181 : pari_stack_base(pari_stack *s) { return s->data; }
     878             : 
     879             : INLINE void
     880     3896271 : pari_stack_init(pari_stack *s, size_t size, void **data)
     881             : {
     882     3896271 :   s->data = data;
     883     3896271 :   *data = NULL;
     884     3896271 :   s->n = 0;
     885     3896271 :   s->alloc = 0;
     886     3896271 :   s->size = size;
     887     3896271 : }
     888             : 
     889             : INLINE void
     890   466694441 : pari_stack_alloc(pari_stack *s, long nb)
     891             : {
     892   466694441 :   void **sdat = pari_stack_base(s);
     893   466694608 :   long alloc = s->alloc;
     894   466694608 :   if (s->n+nb <= alloc) return;
     895     1534039 :   if (!alloc)
     896     1472343 :     alloc = nb;
     897             :   else
     898             :   {
     899       61696 :     while (s->n+nb > alloc) alloc <<= 1;
     900             :   }
     901     1534039 :   *sdat = pari_realloc(*sdat,alloc*s->size);
     902     1535218 :   s->alloc = alloc;
     903             : }
     904             : 
     905             : INLINE long
     906   382785736 : pari_stack_new(pari_stack *s) { pari_stack_alloc(s, 1); return s->n++; }
     907             : 
     908             : INLINE void
     909     3575928 : pari_stack_delete(pari_stack *s)
     910             : {
     911     3575928 :   void **sdat = pari_stack_base(s);
     912     3568349 :   if (*sdat) pari_free(*sdat);
     913     3591003 : }
     914             : 
     915             : INLINE void
     916        5018 : pari_stack_pushp(pari_stack *s, void *u)
     917             : {
     918        5018 :   long n = pari_stack_new(s);
     919        5018 :   void **sdat =(void**) *pari_stack_base(s);
     920        5018 :   sdat[n] = u;
     921        5018 : }
     922             : 
     923             : /*******************************************************************/
     924             : /*                                                                 */
     925             : /*                            EXTRACT                              */
     926             : /*                                                                 */
     927             : /*******************************************************************/
     928             : INLINE GEN
     929   364857012 : vecslice(GEN A, long y1, long y2)
     930             : {
     931   364857012 :   long i,lB = y2 - y1 + 2;
     932   364857012 :   GEN B = cgetg(lB, typ(A));
     933   364886826 :   for (i=1; i<lB; i++) B[i] = A[y1-1+i];
     934   364886826 :   return B;
     935             : }
     936             : INLINE GEN
     937     1044696 : vecslicepermute(GEN A, GEN p, long y1, long y2)
     938             : {
     939     1044696 :   long i,lB = y2 - y1 + 2;
     940     1044696 :   GEN B = cgetg(lB, typ(A));
     941     1044694 :   for (i=1; i<lB; i++) B[i] = A[p[y1-1+i]];
     942     1044694 :   return B;
     943             : }
     944             : /* rowslice(rowpermute(A,p), x1, x2) */
     945             : INLINE GEN
     946       42852 : rowslicepermute(GEN x, GEN p, long j1, long j2)
     947       42852 : { pari_APPLY_same(vecslicepermute(gel(x,i),p,j1,j2)) }
     948             : 
     949             : INLINE GEN
     950    32157383 : rowslice(GEN x, long j1, long j2)
     951    32157383 : { pari_APPLY_same(vecslice(gel(x,i), j1, j2)) }
     952             : 
     953             : INLINE GEN
     954     5326858 : matslice(GEN A, long x1, long x2, long y1, long y2)
     955     5326858 : { return rowslice(vecslice(A, y1, y2), x1, x2); }
     956             : 
     957             : /* shallow, remove coeff of index j */
     958             : INLINE GEN
     959         133 : rowsplice(GEN x, long j)
     960         133 : { pari_APPLY_same(vecsplice(gel(x,i), j)) }
     961             : 
     962             : /* shallow, remove coeff of index j */
     963             : INLINE GEN
     964      268719 : vecsplice(GEN a, long j)
     965             : {
     966      268719 :   long i, k, l = lg(a);
     967             :   GEN b;
     968      268719 :   if (l == 1) pari_err(e_MISC, "incorrect component in vecsplice");
     969      268719 :   b = cgetg(l-1, typ(a));
     970     1242105 :   for (i = k = 1; i < l; i++)
     971      973386 :     if (i != j) gel(b, k++) = gel(a,i);
     972      268719 :   return b;
     973             : }
     974             : /* shallow */
     975             : INLINE GEN
     976        1036 : RgM_minor(GEN a, long i, long j)
     977             : {
     978        1036 :   GEN b = vecsplice(a, j);
     979        1036 :   long k, l = lg(b);
     980        1036 :   for (k = 1; k < l; k++) gel(b,k) = vecsplice(gel(b,k), i);
     981        1036 :   return b;
     982             : }
     983             : 
     984             : /* A[x0,] */
     985             : INLINE GEN
     986      390581 : row(GEN x, long j)
     987      390581 : { pari_APPLY_type(t_VEC, gcoeff(x, j, i)) }
     988             : INLINE GEN
     989     4486661 : Flm_row(GEN x, long j)
     990     4486661 : { pari_APPLY_ulong((ulong)coeff(x, j, i)) }
     991             : /* A[x0,] */
     992             : INLINE GEN
     993      204834 : rowcopy(GEN x, long j)
     994      204834 : { pari_APPLY_type(t_VEC, gcopy(gcoeff(x, j, i))) }
     995             : /* A[x0, x1..x2] */
     996             : INLINE GEN
     997         861 : row_i(GEN A, long x0, long x1, long x2)
     998             : {
     999         861 :   long i, lB = x2 - x1 + 2;
    1000         861 :   GEN B  = cgetg(lB, t_VEC);
    1001         861 :   for (i=x1; i<=x2; i++) gel(B, i) = gcoeff(A, x0, i);
    1002         861 :   return B;
    1003             : }
    1004             : 
    1005             : INLINE GEN
    1006     5941622 : vecreverse(GEN A)
    1007             : {
    1008             :   long i, l;
    1009     5941622 :   GEN B = cgetg_copy(A, &l);
    1010     5941622 :   for (i=1; i<l; i++) gel(B, i) = gel(A, l-i);
    1011     5941622 :   return B;
    1012             : }
    1013             : 
    1014             : INLINE GEN
    1015         546 : vecsmall_reverse(GEN A)
    1016             : {
    1017             :   long i, l;
    1018         546 :   GEN B = cgetg_copy(A, &l);
    1019         546 :   for (i=1; i<l; i++) B[i] = A[l-i];
    1020         546 :   return B;
    1021             : }
    1022             : 
    1023             : INLINE void
    1024         414 : vecreverse_inplace(GEN y)
    1025             : {
    1026         414 :   long l = lg(y), lim = l>>1, i;
    1027        1501 :   for (i = 1; i <= lim; i++)
    1028             :   {
    1029        1087 :     GEN z = gel(y,i);
    1030        1087 :     gel(y,i)    = gel(y,l-i);
    1031        1087 :     gel(y,l-i) = z;
    1032             :   }
    1033         414 : }
    1034             : 
    1035             : INLINE GEN
    1036    55166278 : vecsmallpermute(GEN A, GEN p) { return perm_mul(A, p); }
    1037             : 
    1038             : INLINE GEN
    1039     6785892 : vecpermute(GEN A, GEN x)
    1040     6785892 : { pari_APPLY_type(typ(A), gel(A, x[i])) }
    1041             : 
    1042             : INLINE GEN
    1043     3897695 : rowpermute(GEN x, GEN p)
    1044     3897695 : { pari_APPLY_same(typ(gel(x,i)) == t_VECSMALL ? vecsmallpermute(gel(x, i), p)
    1045             :                                               : vecpermute(gel(x, i), p))
    1046             : }
    1047             : /*******************************************************************/
    1048             : /*                                                                 */
    1049             : /*                          PERMUTATIONS                           */
    1050             : /*                                                                 */
    1051             : /*******************************************************************/
    1052             : INLINE GEN
    1053      878906 : identity_zv(long n)
    1054             : {
    1055      878906 :   GEN v = cgetg(n+1, t_VECSMALL);
    1056             :   long i;
    1057      878905 :   for (i = 1; i <= n; i++) v[i] = i;
    1058      878905 :   return v;
    1059             : }
    1060             : INLINE GEN
    1061        3563 : identity_ZV(long n)
    1062             : {
    1063        3563 :   GEN v = cgetg(n+1, t_VEC);
    1064             :   long i;
    1065        3563 :   for (i = 1; i <= n; i++) gel(v,i) = utoipos(i);
    1066        3563 :   return v;
    1067             : }
    1068             : /* identity permutation */
    1069             : INLINE GEN
    1070      878409 : identity_perm(long n) { return identity_zv(n); }
    1071             : 
    1072             : /* assume d <= n */
    1073             : INLINE GEN
    1074       98483 : cyclic_perm(long n, long d)
    1075             : {
    1076       98483 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1077             :   long i;
    1078       98483 :   for (i = 1; i <= n-d; i++) perm[i] = i+d;
    1079       98483 :   for (     ; i <= n;   i++) perm[i] = i-n+d;
    1080       98483 :   return perm;
    1081             : }
    1082             : 
    1083             : /* Multiply (compose) two permutations */
    1084             : INLINE GEN
    1085    56513679 : perm_mul(GEN s, GEN x)
    1086    56513679 : { pari_APPLY_long(s[x[i]]) }
    1087             : 
    1088             : /* Compute the inverse (reciprocal) of a permutation. */
    1089             : INLINE GEN
    1090     1325071 : perm_inv(GEN x)
    1091             : {
    1092             :   long i, lx;
    1093     1325071 :   GEN y = cgetg_copy(x, &lx);
    1094     1325071 :   for (i=1; i<lx; i++) y[ x[i] ] = i;
    1095     1325071 :   return y;
    1096             : }
    1097             : /* Return s*t*s^-1 */
    1098             : INLINE GEN
    1099      417109 : perm_conj(GEN s, GEN t)
    1100             : {
    1101             :   long i, l;
    1102      417109 :   GEN v = cgetg_copy(s, &l);
    1103      417109 :   for (i = 1; i < l; i++) v[ s[i] ] = s[ t[i] ];
    1104      417109 :   return v;
    1105             : }
    1106             : 
    1107             : /*********************************************************************/
    1108             : /*                       MALLOC/FREE WRAPPERS                        */
    1109             : /*********************************************************************/
    1110             : #define BLOCK_SIGALRM_START          \
    1111             : {                                    \
    1112             :   int block=PARI_SIGINT_block;       \
    1113             :   PARI_SIGINT_block = 2;             \
    1114             :   MT_SIGINT_BLOCK(block);
    1115             : 
    1116             : #define BLOCK_SIGINT_START           \
    1117             : {                                    \
    1118             :   int block=PARI_SIGINT_block;       \
    1119             :   PARI_SIGINT_block = 1;             \
    1120             :   MT_SIGINT_BLOCK(block);
    1121             : 
    1122             : #define BLOCK_SIGINT_END             \
    1123             :   PARI_SIGINT_block = block;         \
    1124             :   MT_SIGINT_UNBLOCK(block);          \
    1125             :   if (!block && PARI_SIGINT_pending) \
    1126             :   {                                  \
    1127             :     int sig = PARI_SIGINT_pending;   \
    1128             :     PARI_SIGINT_pending = 0;         \
    1129             :     raise(sig);                      \
    1130             :   }                                  \
    1131             : }
    1132             : 
    1133             : INLINE void
    1134   101668779 : pari_free(void *pointer)
    1135             : {
    1136   101668779 :   BLOCK_SIGINT_START;
    1137   101709688 :   free(pointer);
    1138   101709688 :   BLOCK_SIGINT_END;
    1139   101702051 : }
    1140             : INLINE void*
    1141   311965947 : pari_malloc(size_t size)
    1142             : {
    1143   311965947 :   if (size)
    1144             :   {
    1145             :     char *tmp;
    1146   311965947 :     BLOCK_SIGINT_START;
    1147   311969270 :     tmp = (char*)malloc(size);
    1148   311969270 :     BLOCK_SIGINT_END;
    1149   311968612 :     if (!tmp) pari_err(e_MEM);
    1150   311968612 :     return tmp;
    1151             :   }
    1152           0 :   return NULL;
    1153             : }
    1154             : INLINE void*
    1155     1549657 : pari_realloc(void *pointer, size_t size)
    1156             : {
    1157             :   char *tmp;
    1158             : 
    1159     1549657 :   BLOCK_SIGINT_START;
    1160     1552783 :   if (!pointer) tmp = (char *) malloc(size);
    1161       65541 :   else tmp = (char *) realloc(pointer,size);
    1162     1552783 :   BLOCK_SIGINT_END;
    1163     1551483 :   if (!tmp) pari_err(e_MEM);
    1164     1551483 :   return tmp;
    1165             : }
    1166             : INLINE void*
    1167       38674 : pari_calloc(size_t size)
    1168             : {
    1169       38674 :   void *t = pari_malloc(size);
    1170       38674 :   memset(t, 0, size); return t;
    1171             : }
    1172             : INLINE GEN
    1173        6601 : cgetalloc(long t, size_t l)
    1174             : { /* evallg may raise e_OVERFLOW, which would leak x */
    1175        6601 :   ulong x0 = evaltyp(t) | evallg(l);
    1176        6601 :   GEN x = (GEN)pari_malloc(l * sizeof(long));
    1177        6601 :   x[0] = x0; return x;
    1178             : }
    1179             : 
    1180             : /*******************************************************************/
    1181             : /*                                                                 */
    1182             : /*                       GARBAGE COLLECTION                        */
    1183             : /*                                                                 */
    1184             : /*******************************************************************/
    1185             : /* copy integer x as if we had set_avma(av) */
    1186             : INLINE GEN
    1187  4217632619 : icopy_avma(GEN x, pari_sp av)
    1188             : {
    1189  4217632619 :   long i = lgefint(x), lx = i;
    1190  4217632619 :   GEN y = ((GEN)av) - i;
    1191  4217632619 :   while (--i > 0) y[i] = x[i];
    1192  4217632619 :   y[0] = evaltyp(t_INT)|evallg(lx);
    1193  4217156449 :   return y;
    1194             : }
    1195             : /* copy leaf x as if we had set_avma(av) */
    1196             : INLINE GEN
    1197   202586796 : leafcopy_avma(GEN x, pari_sp av)
    1198             : {
    1199   202586796 :   long i = lg(x);
    1200   202586796 :   GEN y = ((GEN)av) - i;
    1201   202586796 :   while (--i > 0) y[i] = x[i];
    1202   202586796 :   y[0] = x[0] & (~CLONEBIT);
    1203   202586796 :   return y;
    1204             : }
    1205             : INLINE GEN
    1206   620355763 : gerepileuptoleaf(pari_sp av, GEN x)
    1207             : {
    1208             :   long lx;
    1209             :   GEN q;
    1210             : 
    1211   620355763 :   if (!isonstack(x) || (GEN)av<=x) return gc_const(av,x);
    1212   620141720 :   lx = lg(x);
    1213   620141720 :   q = ((GEN)av) - lx;
    1214   620141720 :   set_avma((pari_sp)q);
    1215   621217526 :   while (--lx >= 0) q[lx] = x[lx];
    1216   621217526 :   return q;
    1217             : }
    1218             : INLINE GEN
    1219  1588861254 : gerepileuptoint(pari_sp av, GEN x)
    1220             : {
    1221  1588861254 :   if (!isonstack(x) || (GEN)av<=x) return gc_const(av,x);
    1222  1365074052 :   set_avma((pari_sp)icopy_avma(x, av));
    1223  1366783470 :   return (GEN)avma;
    1224             : }
    1225             : INLINE GEN
    1226   792634664 : gerepileupto(pari_sp av, GEN x)
    1227             : {
    1228   792634664 :   if (!isonstack(x) || (GEN)av<=x) return gc_const(av,x);
    1229   708600622 :   switch(typ(x))
    1230             :   { /* non-default = !is_recursive_t(tq) */
    1231   216804528 :     case t_INT: return gerepileuptoint(av, x);
    1232             :     case t_REAL:
    1233             :     case t_STR:
    1234   127333034 :     case t_VECSMALL: return gerepileuptoleaf(av,x);
    1235             :     default:
    1236             :       /* NB: x+i --> ((long)x) + i*sizeof(long) */
    1237   364463060 :       return gerepile(av, (pari_sp) (x+lg(x)), x);
    1238             :   }
    1239             : }
    1240             : INLINE double
    1241     2891654 : gc_double(pari_sp av, double d) { set_avma(av); return d; }
    1242             : INLINE long
    1243   115943159 : gc_long(pari_sp av, long s) { set_avma(av); return s; }
    1244             : INLINE ulong
    1245    14067740 : gc_ulong(pari_sp av, ulong s) { set_avma(av); return s; }
    1246             : INLINE int
    1247    20432806 : gc_bool(pari_sp av, int s) { set_avma(av); return s; }
    1248             : INLINE int
    1249     3383411 : gc_int(pari_sp av, int s) { set_avma(av); return s; }
    1250             : INLINE GEN
    1251     1744892 : gc_NULL(pari_sp av) { set_avma(av); return NULL; }
    1252             : INLINE GEN
    1253   374067925 : gc_const(pari_sp av, GEN x) { set_avma(av); return x; }
    1254             : 
    1255             : /* gerepileupto(av, gcopy(x)) */
    1256             : INLINE GEN
    1257    66453263 : gerepilecopy(pari_sp av, GEN x)
    1258             : {
    1259    66453263 :   if (is_recursive_t(typ(x)))
    1260             :   {
    1261    61695591 :     GENbin *p = copy_bin(x);
    1262    61696033 :     set_avma(av); return bin_copy(p);
    1263             :   }
    1264             :   else
    1265             :   {
    1266     4757660 :     set_avma(av);
    1267     4757661 :     if (x < (GEN)av) {
    1268     3269449 :       if (x < (GEN)pari_mainstack->bot) new_chunk(lg(x));
    1269     3269449 :       x = leafcopy_avma(x, av);
    1270     3269448 :       set_avma((pari_sp)x);
    1271             :     } else
    1272     1488212 :       x = leafcopy(x);
    1273     4757657 :     return x;
    1274             :   }
    1275             : }
    1276             : 
    1277             : INLINE void
    1278    29630818 : guncloneNULL(GEN x) { if (x) gunclone(x); }
    1279             : INLINE void
    1280      292936 : 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      203785 : gerepilemany(pari_sp av, GEN* gptr[], int n)
    1287             : {
    1288             :   int i;
    1289      203785 :   for (i=0; i<n; i++) *gptr[i] = (GEN)copy_bin(*gptr[i]);
    1290      203785 :   set_avma(av);
    1291      203785 :   for (i=0; i<n; i++) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1292      203785 : }
    1293             : 
    1294             : INLINE void
    1295    11781680 : gerepileall(pari_sp av, int n, ...)
    1296             : {
    1297             :   int i;
    1298    11781680 :   va_list a; va_start(a, n);
    1299    11781680 :   if (n < 10)
    1300             :   {
    1301             :     GEN *gptr[10];
    1302    34363598 :     for (i=0; i<n; i++)
    1303    22581851 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1304    11781747 :     set_avma(av);
    1305    11781718 :     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    11781792 :   va_end(a);
    1318    11781792 : }
    1319             : 
    1320             : INLINE void
    1321      605310 : gerepilecoeffs(pari_sp av, GEN x, int n)
    1322             : {
    1323             :   int i;
    1324      605310 :   for (i=0; i<n; i++) gel(x,i) = (GEN)copy_bin(gel(x,i));
    1325      605310 :   set_avma(av);
    1326      605310 :   for (i=0; i<n; i++) gel(x,i) = bin_copy((GENbin*)x[i]);
    1327      605310 : }
    1328             : 
    1329             : /* p from copy_bin. Copy p->x back to stack, then destroy p */
    1330             : INLINE GEN
    1331    92152715 : bin_copy(GENbin *p)
    1332             : {
    1333             :   GEN x, y, base;
    1334             :   long dx, len;
    1335             : 
    1336    92152715 :   x   = p->x; if (!x) { pari_free(p); return gen_0; }
    1337    92145420 :   len = p->len;
    1338    92145420 :   base= p->base; dx = x - base;
    1339    92145420 :   y = (GEN)memcpy((void*)new_chunk(len), (void*)GENbinbase(p), len*sizeof(long));
    1340    92145337 :   y += dx;
    1341    92145337 :   p->rebase(y, ((ulong)y-(ulong)x));
    1342    92145345 :   pari_free(p); return y;
    1343             : }
    1344             : 
    1345             : INLINE GEN
    1346   184298112 : GENbinbase(GENbin *p) { return (GEN)(p + 1); }
    1347             : 
    1348             : INLINE void
    1349    68642358 : cgiv(GEN x)
    1350             : {
    1351    68642358 :   pari_sp av = (pari_sp)(x+lg(x));
    1352    68642358 :   if (isonstack((GEN)av)) set_avma(av);
    1353    68641976 : }
    1354             : 
    1355             : INLINE void
    1356     1505136 : killblock(GEN x) { gunclone(x); }
    1357             : 
    1358             : INLINE int
    1359    30747636 : 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     4214347 : cxcompotor(GEN z, long prec)
    1369             : {
    1370     4214347 :   switch(typ(z))
    1371             :   {
    1372     2423205 :     case t_INT:  return itor(z, prec);
    1373      136689 :     case t_FRAC: return fractor(z, prec);
    1374     1654453 :     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     2094293 : cxtofp(GEN x, long prec)
    1381     2094293 : { retmkcomplex(cxcompotor(gel(x,1),prec), cxcompotor(gel(x,2),prec)); }
    1382             : 
    1383             : INLINE GEN
    1384      263018 : cxtoreal(GEN q)
    1385      263018 : { return (typ(q) == t_COMPLEX && gequal0(gel(q,2)))? gel(q,1): q; }
    1386             : 
    1387             : INLINE double
    1388    31125789 : gtodouble(GEN x)
    1389             : {
    1390    31125789 :   if (typ(x)!=t_REAL) {
    1391     5633926 :     pari_sp av = avma;
    1392     5633926 :     x = gtofp(x, DEFAULTPREC);
    1393     5632974 :     if (typ(x)!=t_REAL) pari_err_TYPE("gtodouble [t_REAL expected]", x);
    1394     5632974 :     set_avma(av);
    1395             :   }
    1396    31124668 :   return rtodbl(x);
    1397             : }
    1398             : INLINE long
    1399    73456724 : gtos(GEN x) {
    1400    73456724 :   if (typ(x) != t_INT) pari_err_TYPE("gtos [integer expected]",x);
    1401    73456717 :   return itos(x);
    1402             : }
    1403             : 
    1404             : INLINE ulong
    1405       88197 : gtou(GEN x) {
    1406       88197 :   if (typ(x) != t_INT || signe(x)<0)
    1407           0 :     pari_err_TYPE("gtou [integer >=0 expected]",x);
    1408       88197 :   return itou(x);
    1409             : }
    1410             : 
    1411             : INLINE GEN
    1412    33358288 : absfrac(GEN x)
    1413             : {
    1414    33358288 :   GEN y = cgetg(3, t_FRAC);
    1415    33358288 :   gel(y,1) = absi(gel(x,1));
    1416    33358288 :   gel(y,2) = icopy(gel(x,2)); return y;
    1417             : }
    1418             : INLINE GEN
    1419       38314 : absfrac_shallow(GEN x)
    1420       38314 : { return signe(gel(x,1))>0? x: mkfrac(negi(gel(x,1)), gel(x,2)); }
    1421             : INLINE GEN
    1422    10134690 : Q_abs(GEN x) { return (typ(x) == t_INT)? absi(x): absfrac(x); }
    1423             : INLINE GEN
    1424      142131 : Q_abs_shallow(GEN x)
    1425      142131 : { return (typ(x) == t_INT)? absi_shallow(x): absfrac_shallow(x); }
    1426             : INLINE GEN
    1427       12712 : R_abs_shallow(GEN x)
    1428       12712 : { return (typ(x) == t_FRAC)? absfrac_shallow(x): mpabs_shallow(x); }
    1429             : INLINE GEN
    1430           0 : R_abs(GEN x)
    1431           0 : { return (typ(x) == t_FRAC)? absfrac(x): mpabs(x); }
    1432             : 
    1433             : /* Force z to be of type real/complex with floating point components */
    1434             : INLINE GEN
    1435    35174625 : gtofp(GEN z, long prec)
    1436             : {
    1437    35174625 :   switch(typ(z))
    1438             :   {
    1439    22295098 :     case t_INT:  return itor(z, prec);
    1440     4313266 :     case t_FRAC: return fractor(z, prec);
    1441     6712708 :     case t_REAL: return rtor(z, prec);
    1442             :     case t_COMPLEX: {
    1443     1853553 :       GEN a = gel(z,1), b = gel(z,2);
    1444     1853553 :       if (isintzero(b)) return cxcompotor(a, prec);
    1445     1853553 :       if (isintzero(a)) {
    1446        3511 :         GEN y = cgetg(3, t_COMPLEX);
    1447        3511 :         b = cxcompotor(b, prec);
    1448        3511 :         gel(y,1) = real_0_bit(expo(b) - prec2nbits(prec));
    1449        3511 :         gel(y,2) = b; return y;
    1450             :       }
    1451     1850042 :       return cxtofp(z, prec);
    1452             :     }
    1453           0 :     case t_QUAD: return quadtofp(z, prec);
    1454           0 :     default: pari_err_TYPE("gtofp",z);
    1455             :              return NULL; /* LCOV_EXCL_LINE */
    1456             :   }
    1457             : }
    1458             : /* Force z to be of type real / int */
    1459             : INLINE GEN
    1460       22428 : gtomp(GEN z, long prec)
    1461             : {
    1462       22428 :   switch(typ(z))
    1463             :   {
    1464          42 :     case t_INT:  return z;
    1465       22386 :     case t_FRAC: return fractor(z, prec);
    1466           0 :     case t_REAL: return rtor(z, prec);
    1467           0 :     case t_QUAD: z = quadtofp(z, prec);
    1468           0 :                  if (typ(z) == t_REAL) return z;
    1469           0 :     default: pari_err_TYPE("gtomp",z);
    1470             :              return NULL; /* LCOV_EXCL_LINE */
    1471             :   }
    1472             : }
    1473             : 
    1474             : INLINE GEN
    1475      963222 : RgX_gtofp(GEN x, long prec)
    1476             : {
    1477             :   long l;
    1478      963222 :   GEN y = cgetg_copy(x, &l);
    1479      963222 :   while (--l > 1) gel(y,l) = gtofp(gel(x,l), prec);
    1480      963222 :   y[1] = x[1]; return y;
    1481             : }
    1482             : INLINE GEN
    1483     1261667 : RgC_gtofp(GEN x, long prec)
    1484     1261667 : { pari_APPLY_type(t_COL, gtofp(gel(x,i), prec)) }
    1485             : 
    1486             : INLINE GEN
    1487          42 : RgV_gtofp(GEN x, long prec)
    1488          42 : { pari_APPLY_type(t_VEC, gtofp(gel(x,i), prec)) }
    1489             : 
    1490             : INLINE GEN
    1491      139710 : RgM_gtofp(GEN x, long prec)
    1492      139710 : { pari_APPLY_same(RgC_gtofp(gel(x,i), prec)) }
    1493             : 
    1494             : INLINE GEN
    1495         574 : RgC_gtomp(GEN x, long prec)
    1496         574 : { pari_APPLY_type(t_COL, gtomp(gel(x,i), prec)) }
    1497             : 
    1498             : INLINE GEN
    1499          21 : RgM_gtomp(GEN x, long prec)
    1500          21 : { pari_APPLY_same(RgC_gtomp(gel(x,i), prec)) }
    1501             : 
    1502             : INLINE GEN
    1503       10528 : RgX_fpnorml2(GEN x, long prec)
    1504             : {
    1505       10528 :   pari_sp av = avma;
    1506       10528 :   return gerepileupto(av, gnorml2(RgX_gtofp(x, prec)));
    1507             : }
    1508             : INLINE GEN
    1509      227048 : RgC_fpnorml2(GEN x, long prec)
    1510             : {
    1511      227048 :   pari_sp av = avma;
    1512      227048 :   return gerepileupto(av, gnorml2(RgC_gtofp(x, prec)));
    1513             : }
    1514             : INLINE GEN
    1515        4802 : RgM_fpnorml2(GEN x, long prec)
    1516             : {
    1517        4802 :   pari_sp av = avma;
    1518        4802 :   return gerepileupto(av, gnorml2(RgM_gtofp(x, prec)));
    1519             : }
    1520             : 
    1521             : /* y a t_REAL */
    1522             : INLINE void
    1523      216244 : affgr(GEN x, GEN y)
    1524             : {
    1525             :   pari_sp av;
    1526      216244 :   switch(typ(x)) {
    1527        5992 :     case t_INT:  affir(x,y); break;
    1528      210252 :     case t_REAL: affrr(x,y); break;
    1529           0 :     case t_FRAC: rdiviiz(gel(x,1),gel(x,2), y); break;
    1530           0 :     case t_QUAD: av = avma; affgr(quadtofp(x,realprec(y)), y); set_avma(av); break;
    1531           0 :     default: pari_err_TYPE2("=",x,y);
    1532             :   }
    1533      216244 : }
    1534             : 
    1535             : INLINE GEN
    1536      232817 : affc_fixlg(GEN x, GEN res)
    1537             : {
    1538      232817 :   if (typ(x) == t_COMPLEX)
    1539             :   {
    1540      207522 :     affrr_fixlg(gel(x,1), gel(res,1));
    1541      207522 :     affrr_fixlg(gel(x,2), gel(res,2));
    1542             :   }
    1543             :   else
    1544             :   {
    1545       25295 :     set_avma((pari_sp)(res+3));
    1546       25295 :     res = cgetr(realprec(gel(res,1)));
    1547       25295 :     affrr_fixlg(x, res);
    1548             :   }
    1549      232817 :   return res;
    1550             : }
    1551             : 
    1552             : INLINE GEN
    1553           0 : trunc_safe(GEN x) { long e; return gcvtoi(x,&e); }
    1554             : 
    1555             : /*******************************************************************/
    1556             : /*                                                                 */
    1557             : /*                          LENGTH CONVERSIONS                     */
    1558             : /*                                                                 */
    1559             : /*******************************************************************/
    1560             : INLINE long
    1561       34015 : ndec2nlong(long x) { return 1 + (long)((x)*(LOG2_10/BITS_IN_LONG)); }
    1562             : INLINE long
    1563       25530 : ndec2prec(long x) { return 2 + ndec2nlong(x); }
    1564             : INLINE long
    1565        8485 : ndec2nbits(long x) { return ndec2nlong(x) << TWOPOTBITS_IN_LONG; }
    1566             : /* Fast implementation of ceil(x / (8*sizeof(long))); typecast to (ulong)
    1567             :  * to avoid overflow. Faster than 1 + ((x-1)>>TWOPOTBITS_IN_LONG)) :
    1568             :  *   addl, shrl instead of subl, sarl, addl */
    1569             : INLINE long
    1570     6375756 : nbits2nlong(long x) {
    1571     6375756 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1572             : }
    1573             : 
    1574             : INLINE long
    1575   331432328 : nbits2extraprec(long x) {
    1576   331432328 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1577             : }
    1578             : 
    1579             : /* Fast implementation of 2 + nbits2nlong(x) */
    1580             : INLINE long
    1581   126621749 : nbits2prec(long x) {
    1582   126621749 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1583             : }
    1584             : INLINE long
    1585   171474659 : nbits2lg(long x) {
    1586   171474659 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1587             : }
    1588             : /* ceil(x / sizeof(long)) */
    1589             : INLINE long
    1590    16328459 : nchar2nlong(long x) {
    1591    16328459 :   return (long)(((ulong)x+sizeof(long)-1) >> (TWOPOTBITS_IN_LONG-3L));
    1592             : }
    1593             : INLINE long
    1594  1319608707 : prec2nbits(long x) { return (x-2) * BITS_IN_LONG; }
    1595             : INLINE double
    1596     2864252 : bit_accuracy_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1597             : INLINE double
    1598      259442 : prec2nbits_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1599             : INLINE long
    1600    38636281 : bit_prec(GEN x) { return prec2nbits(realprec(x)); }
    1601             : INLINE long
    1602  1193534146 : bit_accuracy(long x) { return prec2nbits(x); }
    1603             : INLINE long
    1604       12812 : prec2ndec(long x) { return (long)prec2nbits_mul(x, LOG10_2); }
    1605             : INLINE long
    1606         186 : nbits2ndec(long x) { return (long)(x * LOG10_2); }
    1607             : INLINE long
    1608        3136 : precdbl(long x) {return (x - 1) << 1;}
    1609             : INLINE long
    1610  3978528755 : divsBIL(long n) { return n >> TWOPOTBITS_IN_LONG; }
    1611             : INLINE long
    1612  3925638471 : remsBIL(long n) { return n & (BITS_IN_LONG-1); }
    1613             : 
    1614             : /*********************************************************************/
    1615             : /**                                                                 **/
    1616             : /**                      OPERATIONS MODULO m                        **/
    1617             : /**                                                                 **/
    1618             : /*********************************************************************/
    1619             : /* Assume m > 0, more efficient if 0 <= a, b < m */
    1620             : 
    1621             : INLINE GEN
    1622    38441237 : Fp_red(GEN a, GEN m) { return modii(a, m); }
    1623             : INLINE GEN
    1624    92872693 : Fp_add(GEN a, GEN b, GEN m)
    1625             : {
    1626    92872693 :   pari_sp av=avma;
    1627    92872693 :   GEN p = addii(a,b);
    1628    91582835 :   long s = signe(p);
    1629    91582835 :   if (!s) return p; /* = gen_0 */
    1630    80368418 :   if (s > 0) /* general case */
    1631             :   {
    1632    80141990 :     GEN t = subii(p, m);
    1633    81125993 :     s = signe(t);
    1634    81125993 :     if (!s) return gc_const(av, gen_0);
    1635    72437855 :     if (s < 0) return gc_const((pari_sp)p, p);
    1636    30871362 :     if (cmpii(t, m) < 0) return gerepileuptoint(av, t); /* general case ! */
    1637     1109080 :     p = remii(t, m);
    1638             :   }
    1639             :   else
    1640      226428 :     p = modii(p, m);
    1641     1335508 :   return gerepileuptoint(av, p);
    1642             : }
    1643             : INLINE GEN
    1644    67116780 : Fp_sub(GEN a, GEN b, GEN m)
    1645             : {
    1646    67116780 :   pari_sp av=avma;
    1647    67116780 :   GEN p = subii(a,b);
    1648    66650375 :   long s = signe(p);
    1649    66650375 :   if (!s) return p; /* = gen_0 */
    1650    58859705 :   if (s > 0)
    1651             :   {
    1652    25304133 :     if (cmpii(p, m) < 0) return p; /* general case ! */
    1653     1124465 :     p = remii(p, m);
    1654             :   }
    1655             :   else
    1656             :   {
    1657    33555572 :     GEN t = addii(p, m);
    1658    33501495 :     if (!s) return gc_const(av, gen_0);
    1659    33501495 :     if (s > 0) return gerepileuptoint(av, t); /* general case ! */
    1660    33501495 :     p = modii(t, m);
    1661             :   }
    1662    35378900 :   return gerepileuptoint(av, p);
    1663             : }
    1664             : INLINE GEN
    1665    13633461 : Fp_neg(GEN b, GEN m)
    1666             : {
    1667    13633461 :   pari_sp av = avma;
    1668    13633461 :   long s = signe(b);
    1669             :   GEN p;
    1670    13633461 :   if (!s) return gen_0;
    1671    10169011 :   if (s > 0)
    1672             :   {
    1673     9984057 :     p = subii(m, b);
    1674     9981508 :     if (signe(p) >= 0) return p; /* general case ! */
    1675       94638 :     p = modii(p, m);
    1676             :   } else
    1677      184954 :     p = remii(negi(b), m);
    1678      279592 :   return gerepileuptoint(av, p);
    1679             : }
    1680             : 
    1681             : INLINE GEN
    1682       23594 : Fp_halve(GEN a, GEN p)
    1683             : {
    1684       23594 :   if (mpodd(a)) a = addii(a,p);
    1685       23594 :   return shifti(a,-1);
    1686             : }
    1687             : 
    1688             : /* assume 0 <= u < p and ps2 = p>>1 */
    1689             : INLINE GEN
    1690    46904342 : Fp_center(GEN u, GEN p, GEN ps2)
    1691    46904342 : { return abscmpii(u,ps2)<=0? icopy(u): subii(u,p); }
    1692             : /* same without copy */
    1693             : INLINE GEN
    1694     6850831 : Fp_center_i(GEN u, GEN p, GEN ps2)
    1695     6850831 : { return abscmpii(u,ps2)<=0? u: subii(u,p); }
    1696             : 
    1697             : /* x + y*z mod p */
    1698             : INLINE GEN
    1699     5135253 : Fp_addmul(GEN x, GEN y, GEN z, GEN p)
    1700             : {
    1701             :   pari_sp av;
    1702     5135253 :   if (!signe(y) || !signe(z)) return Fp_red(x, p);
    1703     4838130 :   if (!signe(x)) return Fp_mul(z,y, p);
    1704     4528353 :   av = avma;
    1705     4528353 :   return gerepileuptoint(av, modii(addii(x, mulii(y,z)), p));
    1706             : }
    1707             : 
    1708             : INLINE GEN
    1709    95297184 : Fp_mul(GEN a, GEN b, GEN m)
    1710             : {
    1711    95297184 :   pari_sp av=avma;
    1712             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1713    95297184 :   (void)new_chunk(lg(a)+lg(b)+(lg(m)<<1));
    1714    95268385 :   p = mulii(a,b);
    1715    95463162 :   set_avma(av); return modii(p,m);
    1716             : }
    1717             : INLINE GEN
    1718    33681711 : Fp_sqr(GEN a, GEN m)
    1719             : {
    1720    33681711 :   pari_sp av=avma;
    1721             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1722    33681711 :   (void)new_chunk((lg(a)+lg(m))<<1);
    1723    33207179 :   p = sqri(a);
    1724    30771517 :   set_avma(av); return remii(p,m); /*Use remii: p >= 0 */
    1725             : }
    1726             : INLINE GEN
    1727    53945461 : Fp_mulu(GEN a, ulong b, GEN m)
    1728             : {
    1729    53945461 :   long l = lgefint(m);
    1730    53945461 :   if (l == 3)
    1731             :   {
    1732    30615981 :     ulong mm = m[2];
    1733    30615981 :     return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1734             :   } else {
    1735    23329480 :     pari_sp av = avma;
    1736             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1737    23329480 :     (void)new_chunk(lg(a)+1+(l<<1));
    1738    23204897 :     p = muliu(a,b);
    1739    21840200 :     set_avma(av); return modii(p,m);
    1740             :   }
    1741             : }
    1742             : INLINE GEN
    1743           0 : Fp_muls(GEN a, long b, GEN m)
    1744             : {
    1745           0 :   long l = lgefint(m);
    1746           0 :   if (l == 3)
    1747             :   {
    1748           0 :     ulong mm = m[2];
    1749           0 :     if (b < 0)
    1750             :     {
    1751           0 :       ulong t = Fl_mul(umodiu(a, mm), -b, mm);
    1752           0 :       return t? utoipos(mm - t): gen_0;
    1753             :     }
    1754             :     else
    1755           0 :       return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1756             :   } else {
    1757           0 :     pari_sp av = avma;
    1758             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1759           0 :     (void)new_chunk(lg(a)+1+(l<<1));
    1760           0 :     p = mulis(a,b);
    1761           0 :     set_avma(av); return modii(p,m);
    1762             :   }
    1763             : }
    1764             : 
    1765             : INLINE GEN
    1766    12485705 : Fp_inv(GEN a, GEN m)
    1767             : {
    1768             :   GEN res;
    1769    12485705 :   if (! invmod(a,m,&res)) pari_err_INV("Fp_inv", mkintmod(res,m));
    1770    12485392 :   return res;
    1771             : }
    1772             : INLINE GEN
    1773      329441 : Fp_invsafe(GEN a, GEN m)
    1774             : {
    1775             :   GEN res;
    1776      329441 :   if (! invmod(a,m,&res)) return NULL;
    1777      329441 :   return res;
    1778             : }
    1779             : INLINE GEN
    1780     1700532 : Fp_div(GEN a, GEN b, GEN m)
    1781             : {
    1782     1700532 :   pari_sp av = avma;
    1783             :   GEN p;
    1784     1700532 :   if (lgefint(b) == 3)
    1785             :   {
    1786      713028 :     a = Fp_divu(a, b[2], m);
    1787      713028 :     if (signe(b) < 0) a = Fp_neg(a, m);
    1788      713028 :     return a;
    1789             :   }
    1790             :   /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1791      987504 :   (void)new_chunk(lg(a)+(lg(m)<<1));
    1792      987504 :   p = mulii(a, Fp_inv(b,m));
    1793      987504 :   set_avma(av); return modii(p,m);
    1794             : }
    1795             : INLINE GEN
    1796     1820563 : Fp_divu(GEN x, ulong a, GEN p)
    1797             : {
    1798     1820563 :   pari_sp av = avma;
    1799             :   ulong b;
    1800     1820563 :   if (lgefint(p) == 3)
    1801             :   {
    1802     1415021 :     ulong pp = p[2], xp = umodiu(x, pp);
    1803     1415021 :     return xp? utoipos(Fl_div(xp, a % pp, pp)): gen_0;
    1804             :   }
    1805      405542 :   x = Fp_red(x, p);
    1806      405543 :   b = Fl_neg(Fl_div(umodiu(x,a), umodiu(p,a), a), a); /* x + pb = 0 (mod a) */
    1807      405544 :   return gerepileuptoint(av, diviuexact(addmuliu(x, p, b), a));
    1808             : }
    1809             : 
    1810             : INLINE GEN
    1811      889721 : Flx_mulu(GEN x, ulong a, ulong p) { return Flx_Fl_mul(x,a%p,p); }
    1812             : 
    1813             : INLINE GEN
    1814     1830246 : get_F2x_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1815             : 
    1816             : INLINE long
    1817     2252395 : get_F2x_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1818             : 
    1819             : INLINE long
    1820     1899687 : get_F2x_degree(GEN T) { return typ(T)==t_VEC? F2x_degree(gel(T,2)): F2x_degree(T); }
    1821             : 
    1822             : INLINE GEN
    1823         399 : get_F2xqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1824             : 
    1825             : INLINE long
    1826      376159 : get_F2xqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1827             : 
    1828             : INLINE long
    1829      201446 : get_F2xqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1830             : 
    1831             : INLINE GEN
    1832     8052244 : get_Flx_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1833             : 
    1834             : INLINE long
    1835    21651070 : get_Flx_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1836             : 
    1837             : INLINE long
    1838    33475081 : get_Flx_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1839             : 
    1840             : INLINE GEN
    1841        3980 : get_FlxqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1842             : 
    1843             : INLINE long
    1844      222674 : get_FlxqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1845             : 
    1846             : INLINE long
    1847      278459 : get_FlxqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1848             : 
    1849             : INLINE GEN
    1850     1661852 : get_FpX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1851             : 
    1852             : INLINE long
    1853     4023449 : get_FpX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1854             : 
    1855             : INLINE long
    1856     2886855 : get_FpX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1857             : 
    1858             : INLINE GEN
    1859      142586 : get_FpXQX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1860             : 
    1861             : INLINE long
    1862       57495 : get_FpXQX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1863             : 
    1864             : INLINE long
    1865        2259 : get_FpXQX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1866             : 
    1867             : /*******************************************************************/
    1868             : /*                                                                 */
    1869             : /*                        ADDMULII / SUBMULII                      */
    1870             : /*                                                                 */
    1871             : /*******************************************************************/
    1872             : /* x - y*z */
    1873             : INLINE GEN
    1874      391814 : submulii(GEN x, GEN y, GEN z)
    1875             : {
    1876      391814 :   long lx = lgefint(x), ly, lz;
    1877             :   pari_sp av;
    1878             :   GEN t;
    1879      391814 :   if (lx == 2) { t = mulii(z,y); togglesign(t); return t; }
    1880      341730 :   ly = lgefint(y);
    1881      341730 :   if (ly == 2) return icopy(x);
    1882      287151 :   lz = lgefint(z);
    1883      287151 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1884      287151 :   t = mulii(z, y);
    1885      287151 :   set_avma(av); return subii(x,t);
    1886             : }
    1887             : /* y*z - x */
    1888             : INLINE GEN
    1889     1540127 : mulsubii(GEN y, GEN z, GEN x)
    1890             : {
    1891     1540127 :   long lx = lgefint(x), ly, lz;
    1892             :   pari_sp av;
    1893             :   GEN t;
    1894     1540127 :   if (lx == 2) return mulii(z,y);
    1895      986487 :   ly = lgefint(y);
    1896      986487 :   if (ly == 2) return negi(x);
    1897      913991 :   lz = lgefint(z);
    1898      913991 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1899      913991 :   t = mulii(z, y);
    1900      913991 :   set_avma(av); return subii(t,x);
    1901             : }
    1902             : 
    1903             : /* x - u*y */
    1904             : INLINE GEN
    1905        7595 : submuliu(GEN x, GEN y, ulong u)
    1906             : {
    1907             :   pari_sp av;
    1908        7595 :   long ly = lgefint(y);
    1909        7595 :   if (ly == 2) return icopy(x);
    1910        7595 :   av = avma;
    1911        7595 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1912        7595 :   y = mului(u,y);
    1913        7595 :   set_avma(av); return subii(x, y);
    1914             : }
    1915             : /* x + u*y */
    1916             : INLINE GEN
    1917      413500 : addmuliu(GEN x, GEN y, ulong u)
    1918             : {
    1919             :   pari_sp av;
    1920      413500 :   long ly = lgefint(y);
    1921      413500 :   if (ly == 2) return icopy(x);
    1922      413500 :   av = avma;
    1923      413500 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1924      413500 :   y = mului(u,y);
    1925      413501 :   set_avma(av); return addii(x, y);
    1926             : }
    1927             : /* x - u*y */
    1928             : INLINE GEN
    1929   156934118 : submuliu_inplace(GEN x, GEN y, ulong u)
    1930             : {
    1931             :   pari_sp av;
    1932   156934118 :   long ly = lgefint(y);
    1933   156934118 :   if (ly == 2) return x;
    1934   125305213 :   av = avma;
    1935   125305213 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1936   125305213 :   y = mului(u,y);
    1937   125305213 :   set_avma(av); return subii(x, y);
    1938             : }
    1939             : /* x + u*y */
    1940             : INLINE GEN
    1941   154899294 : addmuliu_inplace(GEN x, GEN y, ulong u)
    1942             : {
    1943             :   pari_sp av;
    1944   154899294 :   long ly = lgefint(y);
    1945   154899294 :   if (ly == 2) return x;
    1946   124744203 :   av = avma;
    1947   124744203 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1948   124744203 :   y = mului(u,y);
    1949   124744203 :   set_avma(av); return addii(x, y);
    1950             : }
    1951             : /* ux + vy */
    1952             : INLINE GEN
    1953    25188142 : lincombii(GEN u, GEN v, GEN x, GEN y)
    1954             : {
    1955    25188142 :   long lx = lgefint(x), ly;
    1956             :   GEN p1, p2;
    1957             :   pari_sp av;
    1958    25188142 :   if (lx == 2) return mulii(v,y);
    1959    17346561 :   ly = lgefint(y);
    1960    17346561 :   if (ly == 2) return mulii(u,x);
    1961    16067999 :   av = avma; (void)new_chunk(lx+ly+lgefint(u)+lgefint(v)); /* HACK */
    1962    16068001 :   p1 = mulii(u,x);
    1963    16067921 :   p2 = mulii(v,y);
    1964    16067944 :   set_avma(av); return addii(p1,p2);
    1965             : }
    1966             : 
    1967             : /*******************************************************************/
    1968             : /*                                                                 */
    1969             : /*                          GEN SUBTYPES                           */
    1970             : /*                                                                 */
    1971             : /*******************************************************************/
    1972             : 
    1973             : INLINE int
    1974  1411991923 : is_const_t(long t) { return (t < t_POLMOD); }
    1975             : INLINE int
    1976        6753 : is_extscalar_t(long t) { return (t <= t_POL); }
    1977             : INLINE int
    1978     1227720 : is_intreal_t(long t) { return (t <= t_REAL); }
    1979             : INLINE int
    1980   420218618 : is_matvec_t(long t) { return (t >= t_VEC && t <= t_MAT); }
    1981             : INLINE int
    1982    70380027 : is_noncalc_t(long tx) { return (tx) >= t_LIST; }
    1983             : INLINE int
    1984     1301396 : is_rational_t(long t) { return (t == t_INT || t == t_FRAC); }
    1985             : INLINE int
    1986      538638 : is_real_t(long t) { return (t == t_INT || t == t_REAL || t == t_FRAC); }
    1987             : INLINE int
    1988  3610327184 : is_recursive_t(long t) { return lontyp[t]; }
    1989             : INLINE int
    1990   176095394 : is_scalar_t(long t) { return (t < t_POL); }
    1991             : INLINE int
    1992     1097926 : is_vec_t(long t) { return (t == t_VEC || t == t_COL); }
    1993             : 
    1994             : /*******************************************************************/
    1995             : /*                                                                 */
    1996             : /*                         TRANSCENDENTAL                          */
    1997             : /*                                                                 */
    1998             : /*******************************************************************/
    1999             : INLINE GEN
    2000    22861090 : sqrtr(GEN x) {
    2001    22861090 :   long s = signe(x);
    2002    22861090 :   if (s == 0) return real_0_bit(expo(x) >> 1);
    2003    22827623 :   if (s >= 0) return sqrtr_abs(x);
    2004       39836 :   retmkcomplex(gen_0, sqrtr_abs(x));
    2005             : }
    2006             : INLINE GEN
    2007           0 : cbrtr_abs(GEN x) { return sqrtnr_abs(x, 3); }
    2008             : INLINE GEN
    2009           0 : cbrtr(GEN x) {
    2010           0 :   long s = signe(x);
    2011             :   GEN r;
    2012           0 :   if (s == 0) return real_0_bit(expo(x) / 3);
    2013           0 :   r = cbrtr_abs(x);
    2014           0 :   if (s < 0) togglesign(r);
    2015           0 :   return r;
    2016             : }
    2017             : INLINE GEN
    2018      471224 : sqrtnr(GEN x, long n) {
    2019      471224 :   long s = signe(x);
    2020             :   GEN r;
    2021      471224 :   if (s == 0) return real_0_bit(expo(x) / n);
    2022      471224 :   r = sqrtnr_abs(x, n);
    2023      471224 :   if (s < 0) pari_err_IMPL("sqrtnr for x < 0");
    2024      471224 :   return r;
    2025             : }
    2026             : INLINE long
    2027      265072 : logint(GEN B, GEN y) { return logintall(B,y,NULL); }
    2028             : INLINE ulong
    2029     2006308 : ulogint(ulong B, ulong y)
    2030             : {
    2031             :   ulong r;
    2032             :   long e;
    2033     2006308 :   if (y == 2) return expu(B);
    2034     1987296 :   r = y;
    2035     6413517 :   for (e=1;; e++)
    2036             :   { /* here, r = y^e, r2 = y^(e-1) */
    2037    10839738 :     if (r >= B) return r == B? e: e-1;
    2038     4426216 :     r = umuluu_or_0(y, r);
    2039     4426221 :     if (!r) return e;
    2040             :   }
    2041             : }
    2042             : 
    2043             : /*******************************************************************/
    2044             : /*                                                                 */
    2045             : /*                         MISCELLANEOUS                           */
    2046             : /*                                                                 */
    2047             : /*******************************************************************/
    2048     1227643 : INLINE int ismpzero(GEN x) { return is_intreal_t(typ(x)) && !signe(x); }
    2049   758553265 : INLINE int isintzero(GEN x) { return typ(x) == t_INT && !signe(x); }
    2050     7704979 : INLINE int isint1(GEN x) { return typ(x)==t_INT && equali1(x); }
    2051     1454359 : INLINE int isintm1(GEN x){ return typ(x)==t_INT && equalim1(x);}
    2052   745679292 : INLINE int equali1(GEN n)
    2053   745679292 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(1)) && n[2] == 1; }
    2054    61389230 : INLINE int equalim1(GEN n)
    2055    61389230 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(-1)) && n[2] == 1; }
    2056             : /* works only for POSITIVE integers */
    2057  1364979300 : INLINE int is_pm1(GEN n)
    2058  1364979300 : { return lgefint(n) == 3 && n[2] == 1; }
    2059   266441224 : INLINE int is_bigint(GEN n)
    2060   266441224 : { long l = lgefint(n); return l > 3 || (l == 3 && (n[2] & HIGHBIT)); }
    2061             : 
    2062  2092570087 : INLINE int odd(long x) { return x & 1; }
    2063    30231544 : INLINE int both_odd(long x, long y) { return x & y & 1; }
    2064             : 
    2065             : INLINE int
    2066  3070441972 : isonstack(GEN x)
    2067  3070441972 : { return ((pari_sp)x >= pari_mainstack->bot
    2068  3070441972 :        && (pari_sp)x <  pari_mainstack->top); }
    2069             : 
    2070             : /* assume x != 0 and x t_REAL, return an approximation to log2(|x|) */
    2071             : INLINE double
    2072    22896675 : dbllog2r(GEN x)
    2073    22896675 : { return log2((double)(ulong)x[2]) + (double)(expo(x) - (BITS_IN_LONG-1)); }
    2074             : 
    2075             : INLINE GEN
    2076      400883 : mul_content(GEN cx, GEN cy)
    2077             : {
    2078      400883 :   if (!cx) return cy;
    2079      155252 :   if (!cy) return cx;
    2080      105196 :   return gmul(cx,cy);
    2081             : }
    2082             : INLINE GEN
    2083       10712 : inv_content(GEN c) { return c? ginv(c): NULL; }
    2084             : INLINE GEN
    2085     2047575 : mul_denom(GEN dx, GEN dy)
    2086             : {
    2087     2047575 :   if (!dx) return dy;
    2088     1267946 :   if (!dy) return dx;
    2089      407314 :   return mulii(dx,dy);
    2090             : }
    2091             : 
    2092             : /* POLYNOMIALS */
    2093             : INLINE GEN
    2094    17954319 : constant_coeff(GEN x) { return signe(x)? gel(x,2): gen_0; }
    2095             : INLINE GEN
    2096    85112383 : leading_coeff(GEN x) { return lg(x) == 2? gen_0: gel(x,lg(x)-1); }
    2097             : INLINE ulong
    2098      502738 : Flx_lead(GEN x) { return lg(x) == 2? 0: x[lg(x)-1]; }
    2099             : INLINE ulong
    2100       15153 : Flx_constant(GEN x) { return lg(x) == 2? 0: x[2]; }
    2101             : INLINE long
    2102  2887575006 : degpol(GEN x) { return lg(x)-3; }
    2103             : INLINE long
    2104  1498746171 : lgpol(GEN x) { return lg(x)-2; }
    2105             : INLINE long
    2106   142398575 : lgcols(GEN x) { return lg(gel(x,1)); }
    2107             : INLINE long
    2108    41037281 : nbrows(GEN x) { return lg(gel(x,1))-1; }
    2109             : INLINE GEN
    2110           0 : truecoef(GEN x, long n) { return polcoef(x,n,-1); }
    2111             : 
    2112             : INLINE GEN
    2113      641887 : ZXQ_mul(GEN y, GEN x, GEN T) { return ZX_rem(ZX_mul(y, x), T); }
    2114             : INLINE GEN
    2115      292951 : ZXQ_sqr(GEN x, GEN T) { return ZX_rem(ZX_sqr(x), T); }
    2116             : 
    2117             : INLINE GEN
    2118    95239619 : RgX_copy(GEN x)
    2119             : {
    2120             :   long lx, i;
    2121    95239619 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
    2122    95239616 :   for (i = 2; i<lx; i++) gel(y,i) = gcopy(gel(x,i));
    2123    95239614 :   return y;
    2124             : }
    2125             : /* have to use ulong to avoid silly warnings from gcc "assuming signed
    2126             :  * overflow does not occur" */
    2127             : INLINE GEN
    2128      801287 : RgX_coeff(GEN x, long n)
    2129             : {
    2130      801287 :   ulong l = lg(x);
    2131      801287 :   return (n < 0 || ((ulong)n+3) > l)? gen_0: gel(x,n+2);
    2132             : }
    2133             : INLINE GEN
    2134      367881 : RgX_renormalize(GEN x) { return RgX_renormalize_lg(x, lg(x)); }
    2135             : INLINE GEN
    2136     6812315 : RgX_div(GEN x, GEN y) { return RgX_divrem(x,y,NULL); }
    2137             : INLINE GEN
    2138        1792 : RgXQX_div(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,NULL); }
    2139             : INLINE GEN
    2140      104345 : RgXQX_rem(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,ONLY_REM); }
    2141             : INLINE GEN
    2142     1106212 : FpX_div(GEN x, GEN y, GEN p) { return FpX_divrem(x,y,p, NULL); }
    2143             : INLINE GEN
    2144     5506698 : Flx_div(GEN x, GEN y, ulong p) { return Flx_divrem(x,y,p, NULL); }
    2145             : INLINE GEN
    2146      828754 : F2x_div(GEN x, GEN y) { return F2x_divrem(x,y, NULL); }
    2147             : INLINE GEN
    2148           0 : FpV_FpC_mul(GEN x, GEN y, GEN p) { return FpV_dotproduct(x,y,p); }
    2149             : INLINE GEN
    2150    51895336 : pol0_Flx(long sv) { return mkvecsmall(sv); }
    2151             : INLINE GEN
    2152    16814739 : pol1_Flx(long sv) { return mkvecsmall2(sv, 1); }
    2153             : INLINE GEN
    2154    18554653 : polx_Flx(long sv) { return mkvecsmall3(sv, 0, 1); }
    2155             : INLINE GEN
    2156           0 : zero_zx(long sv) { return zero_Flx(sv); }
    2157             : INLINE GEN
    2158           0 : polx_zx(long sv) { return polx_Flx(sv); }
    2159             : INLINE GEN
    2160           0 : zx_shift(GEN x, long n) { return Flx_shift(x,n); }
    2161             : INLINE GEN
    2162           0 : zx_renormalize(GEN x, long l) { return Flx_renormalize(x,l); }
    2163             : INLINE GEN
    2164        1341 : zero_F2x(long sv) { return zero_Flx(sv); }
    2165             : INLINE GEN
    2166    11187073 : pol0_F2x(long sv) { return pol0_Flx(sv); }
    2167             : INLINE GEN
    2168     2889100 : pol1_F2x(long sv) { return pol1_Flx(sv); }
    2169             : INLINE GEN
    2170      693364 : polx_F2x(long sv) { return mkvecsmall2(sv, 2); }
    2171             : INLINE int
    2172      845897 : F2x_equal1(GEN x) { return Flx_equal1(x); }
    2173             : INLINE int
    2174     3125182 : F2x_equal(GEN V, GEN W) { return Flx_equal(V,W); }
    2175             : INLINE GEN
    2176    54207149 : F2x_copy(GEN x) { return leafcopy(x); }
    2177             : INLINE GEN
    2178        3185 : F2v_copy(GEN x) { return leafcopy(x); }
    2179             : INLINE GEN
    2180     2274671 : Flv_copy(GEN x) { return leafcopy(x); }
    2181             : INLINE GEN
    2182    87761179 : Flx_copy(GEN x) { return leafcopy(x); }
    2183             : INLINE GEN
    2184     1955863 : vecsmall_copy(GEN x) { return leafcopy(x); }
    2185             : INLINE int
    2186     5053285 : Flx_equal1(GEN x) { return degpol(x)==0 && x[2] == 1; }
    2187             : INLINE int
    2188       18131 : ZX_equal1(GEN x) { return degpol(x)==0 && equali1(gel(x,2)); }
    2189             : INLINE int
    2190     5838924 : ZX_is_monic(GEN x) { return equali1(leading_coeff(x)); }
    2191             : 
    2192             : INLINE GEN
    2193    65093936 : ZX_renormalize(GEN x, long lx)    { return ZXX_renormalize(x,lx); }
    2194             : INLINE GEN
    2195    74984186 : FpX_renormalize(GEN x, long lx)   { return ZXX_renormalize(x,lx); }
    2196             : INLINE GEN
    2197      790107 : FpXX_renormalize(GEN x, long lx)  { return ZXX_renormalize(x,lx); }
    2198             : INLINE GEN
    2199     1301114 : FpXQX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
    2200             : INLINE GEN
    2201   108471678 : F2x_renormalize(GEN x, long lx)   { return Flx_renormalize(x,lx); }
    2202             : INLINE GEN
    2203       32603 : F2v_to_F2x(GEN x, long sv) {
    2204       32603 :   GEN y = leafcopy(x);
    2205       32603 :   y[1] = sv; F2x_renormalize(y, lg(y)); return y;
    2206             : }
    2207             : 
    2208             : INLINE long
    2209         126 : sturm(GEN x) { return sturmpart(x, NULL, NULL); }
    2210             : 
    2211             : INLINE long
    2212        7273 : gval(GEN x, long v)
    2213        7273 : { pari_sp av = avma; return gc_long(av, gvaluation(x, pol_x(v))); }
    2214             : 
    2215             : INLINE void
    2216      472832 : RgX_shift_inplace_init(long v)
    2217      472832 : { if (v) (void)cgetg(v, t_VECSMALL); }
    2218             : /* shift polynomial in place. assume v free cells have been left before x */
    2219             : INLINE GEN
    2220      472832 : RgX_shift_inplace(GEN x, long v)
    2221             : {
    2222             :   long i, lx;
    2223             :   GEN z;
    2224      472832 :   if (!v) return x;
    2225      253227 :   lx = lg(x);
    2226      253227 :   if (lx == 2) return x;
    2227      253227 :   z = x + lx;
    2228             :   /* stackdummy's from normalizepol */
    2229      253227 :   while (lg(z) != v) z += lg(z);
    2230      253227 :   z += v;
    2231      253227 :   for (i = lx-1; i >= 2; i--) gel(--z,0) = gel(x,i);
    2232      253227 :   for (i = 0;  i < v; i++) gel(--z,0) = gen_0;
    2233      253227 :   z -= 2;
    2234      253227 :   z[1] = x[1];
    2235      253227 :   z[0] = evaltyp(t_POL) | evallg(lx+v);
    2236      253227 :   stackdummy((pari_sp)z, (pari_sp)x); return z;
    2237             : }
    2238             : 
    2239             : 
    2240             : /* LINEAR ALGEBRA */
    2241             : INLINE GEN
    2242      134113 : zv_to_ZV(GEN x) { return vecsmall_to_vec(x); }
    2243             : INLINE GEN
    2244     5328600 : zc_to_ZC(GEN x) { return vecsmall_to_col(x); }
    2245             : INLINE GEN
    2246     3300764 : ZV_to_zv(GEN x) { return vec_to_vecsmall(x); }
    2247             : INLINE GEN
    2248           0 : zx_to_zv(GEN x, long N) { return Flx_to_Flv(x,N); }
    2249             : INLINE GEN
    2250           0 : zv_to_zx(GEN x, long sv) { return Flv_to_Flx(x,sv); }
    2251             : INLINE GEN
    2252           0 : zm_to_zxV(GEN x, long sv) { return Flm_to_FlxV(x,sv); }
    2253             : INLINE GEN
    2254           0 : zero_zm(long x, long y) { return zero_Flm(x,y); }
    2255             : INLINE GEN
    2256    18037603 : zero_zv(long x) { return zero_Flv(x); }
    2257             : INLINE GEN
    2258         238 : zm_transpose(GEN x) { return Flm_transpose(x); }
    2259             : INLINE GEN
    2260           0 : zm_copy(GEN x) { return Flm_copy(x); }
    2261             : INLINE GEN
    2262     1901403 : zv_copy(GEN x) { return Flv_copy(x); }
    2263             : INLINE GEN
    2264           0 : zm_row(GEN x, long i) { return Flm_row(x,i); }
    2265             : 
    2266             : INLINE GEN
    2267     2547876 : ZC_hnfrem(GEN x, GEN y) { return ZC_hnfremdiv(x,y,NULL); }
    2268             : INLINE GEN
    2269       50279 : ZM_hnfrem(GEN x, GEN y) { return ZM_hnfdivrem(x,y,NULL); }
    2270             : INLINE GEN
    2271     2536790 : ZM_lll(GEN x, double D, long f) { return ZM_lll_norms(x,D,f,NULL); }
    2272             : INLINE void
    2273     6472424 : RgM_dimensions(GEN x, long *m, long *n) { *n = lg(x)-1; *m = *n? nbrows(x): 0; }
    2274             : INLINE GEN
    2275    10637705 : RgM_shallowcopy(GEN x)
    2276             : {
    2277             :   long l;
    2278    10637705 :   GEN y = cgetg_copy(x, &l);
    2279    10637703 :   while (--l > 0) gel(y,l) = leafcopy(gel(x,l));
    2280    10637707 :   return y;
    2281             : }
    2282             : INLINE GEN
    2283       21722 : F2m_copy(GEN x) { return RgM_shallowcopy(x); }
    2284             : 
    2285             : INLINE GEN
    2286     1686311 : Flm_copy(GEN x) { return RgM_shallowcopy(x); }
    2287             : 
    2288             : /* divisibility: return 1 if y[i] | x[i] for all i, 0 otherwise. Assume
    2289             :  * x,y are ZV of the same length */
    2290             : INLINE int
    2291       23198 : ZV_dvd(GEN x, GEN y)
    2292             : {
    2293       23198 :   long i, l = lg(x);
    2294       36652 :   for (i=1; i < l; i++)
    2295       29519 :     if ( ! dvdii( gel(x,i), gel(y,i) ) ) return 0;
    2296        7133 :   return 1;
    2297             : }
    2298             : 
    2299             : /* Fq */
    2300             : INLINE GEN
    2301     2520698 : Fq_red(GEN x, GEN T, GEN p)
    2302     2520698 : { return typ(x)==t_INT? Fp_red(x,p): FpXQ_red(x,T,p); }
    2303             : INLINE GEN
    2304       99511 : Fq_to_FpXQ(GEN x, GEN T, GEN p /*unused*/)
    2305             : {
    2306             :   (void) p;
    2307       99511 :   return typ(x)==t_INT ? scalarpol(x, get_FpX_var(T)): x;
    2308             : }
    2309             : INLINE GEN
    2310         756 : Rg_to_Fq(GEN x, GEN T, GEN p) { return T? Rg_to_FpXQ(x,T,p): Rg_to_Fp(x,p); }
    2311             : 
    2312             : INLINE GEN
    2313        2345 : gener_Fq_local(GEN T, GEN p, GEN L)
    2314             : { return T? gener_FpXQ_local(T,p, L)
    2315        2345 :           : pgener_Fp_local(p, L); }
    2316             : 
    2317             : /* FpXQX */
    2318             : INLINE GEN
    2319        4410 : FpXQX_div(GEN x, GEN y, GEN T, GEN p) { return FpXQX_divrem(x, y, T, p, NULL); }
    2320             : INLINE GEN
    2321       36763 : FlxqX_div(GEN x, GEN y, GEN T, ulong p) { return FlxqX_divrem(x, y, T, p, NULL); }
    2322             : INLINE GEN
    2323       33334 : F2xqX_div(GEN x, GEN y, GEN T) { return F2xqX_divrem(x, y, T, NULL); }
    2324             : 
    2325             : /* FqX */
    2326             : INLINE GEN
    2327       25452 : FqX_red(GEN z, GEN T, GEN p) { return T? FpXQX_red(z, T, p): FpX_red(z, p); }
    2328             : INLINE GEN
    2329      957187 : FqX_add(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2330             : INLINE GEN
    2331       17404 : FqX_neg(GEN x,GEN T,GEN p) { return T? FpXX_neg(x,p): FpX_neg(x,p); }
    2332             : INLINE GEN
    2333        3234 : FqX_sub(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2334             : INLINE GEN
    2335      668506 : FqX_Fp_mul(GEN P, GEN u, GEN T, GEN p)
    2336      668506 : { return T? FpXX_Fp_mul(P, u, p): FpX_Fp_mul(P, u, p); }
    2337             : INLINE GEN
    2338      590243 : FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p)
    2339      590243 : { return typ(U)==t_INT ? FqX_Fp_mul(P, U, T, p): FpXQX_FpXQ_mul(P, U, T, p); }
    2340             : INLINE GEN
    2341      101028 : FqX_mul(GEN x, GEN y, GEN T, GEN p)
    2342      101028 : { return T? FpXQX_mul(x, y, T, p): FpX_mul(x, y, p); }
    2343             : INLINE GEN
    2344      489744 : FqX_mulu(GEN x, ulong y, GEN T, GEN p)
    2345      489744 : { return T? FpXX_mulu(x, y, p): FpX_mulu(x, y, p); }
    2346             : INLINE GEN
    2347        6468 : FqX_sqr(GEN x, GEN T, GEN p)
    2348        6468 : { return T? FpXQX_sqr(x, T, p): FpX_sqr(x, p); }
    2349             : INLINE GEN
    2350        1288 : FqX_powu(GEN x, ulong n, GEN T, GEN p)
    2351        1288 : { return T? FpXQX_powu(x, n, T, p): FpX_powu(x, n, p); }
    2352             : INLINE GEN
    2353           0 : FqX_halve(GEN x, GEN T, GEN p)
    2354           0 : { return T? FpXX_halve(x, p): FpX_halve(x, p); }
    2355             : INLINE GEN
    2356        5964 : FqX_div(GEN x, GEN y, GEN T, GEN p)
    2357        5964 : { return T? FpXQX_divrem(x,y,T,p,NULL): FpX_divrem(x,y,p,NULL); }
    2358             : INLINE GEN
    2359        6095 : FqX_get_red(GEN S, GEN T, GEN p)
    2360        6095 : { return T? FpXQX_get_red(S,T,p): FpX_get_red(S,p); }
    2361             : INLINE GEN
    2362       53108 : FqX_rem(GEN x, GEN y, GEN T, GEN p)
    2363       53108 : { return T? FpXQX_rem(x,y,T,p): FpX_rem(x,y,p); }
    2364             : INLINE GEN
    2365           0 : FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2366           0 : { return T? FpXQX_divrem(x,y,T,p,z): FpX_divrem(x,y,p,z); }
    2367             : INLINE GEN
    2368        5936 : FqX_div_by_X_x(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2369        5936 : { return T? FpXQX_div_by_X_x(x,y,T,p,z): FpX_div_by_X_x(x,y,p,z); }
    2370             : INLINE GEN
    2371           0 : FqX_halfgcd(GEN P,GEN Q,GEN T,GEN p)
    2372           0 : {return T? FpXQX_halfgcd(P,Q,T,p): FpX_halfgcd(P,Q,p);}
    2373             : INLINE GEN
    2374      259833 : FqX_gcd(GEN P,GEN Q,GEN T,GEN p)
    2375      259833 : {return T? FpXQX_gcd(P,Q,T,p): FpX_gcd(P,Q,p);}
    2376             : INLINE GEN
    2377       96340 : FqX_extgcd(GEN P,GEN Q,GEN T,GEN p, GEN *U, GEN *V)
    2378       96340 : { return T? FpXQX_extgcd(P,Q,T,p,U,V): FpX_extgcd(P,Q,p,U,V); }
    2379             : INLINE GEN
    2380        3437 : FqX_normalize(GEN z, GEN T, GEN p)
    2381        3437 : { return T? FpXQX_normalize(z, T, p): FpX_normalize(z, p); }
    2382             : INLINE GEN
    2383      273175 : FqX_deriv(GEN f, GEN T, GEN p) { return T? FpXX_deriv(f, p): FpX_deriv(f, p); }
    2384             : INLINE GEN
    2385           0 : FqX_integ(GEN f, GEN T, GEN p) { return T? FpXX_integ(f, p): FpX_integ(f, p); }
    2386             : INLINE GEN
    2387       75229 : FqX_factor(GEN f, GEN T, GEN p)
    2388       75229 : { return T?FpXQX_factor(f, T, p): FpX_factor(f, p); }
    2389             : INLINE GEN
    2390           7 : FqX_factor_squarefree(GEN f, GEN T, GEN p)
    2391           7 : { return T ? FpXQX_factor_squarefree(f, T, p): FpX_factor_squarefree(f, p); }
    2392             : INLINE GEN
    2393           7 : FqX_ddf(GEN f, GEN T, GEN p)
    2394           7 : { return T ? FpXQX_ddf(f, T, p): FpX_ddf(f, p); }
    2395             : INLINE GEN
    2396        1862 : FqX_degfact(GEN f, GEN T, GEN p)
    2397        1862 : { return T?FpXQX_degfact(f, T, p): FpX_degfact(f, p); }
    2398             : INLINE GEN
    2399        7147 : FqX_roots(GEN f, GEN T, GEN p)
    2400        7147 : { return T?FpXQX_roots(f, T, p): FpX_roots(f, p); }
    2401             : INLINE GEN
    2402         203 : FqX_to_mod(GEN f, GEN T, GEN p)
    2403         203 : { return T?FpXQX_to_mod(f, T, p): FpX_to_mod(f, p); }
    2404             : 
    2405             : /*FqXQ*/
    2406             : INLINE GEN
    2407           0 : FqXQ_add(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2408           0 : { (void)S; return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2409             : INLINE GEN
    2410           0 : FqXQ_sub(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2411           0 : { (void)S; return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2412             : INLINE GEN
    2413           0 : FqXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p)
    2414           0 : { return T? FpXQXQ_div(x,y,S,T,p): FpXQ_div(x,y,S,p); }
    2415             : INLINE GEN
    2416           0 : FqXQ_inv(GEN x, GEN S, GEN T, GEN p)
    2417           0 : { return T? FpXQXQ_inv(x,S,T,p): FpXQ_inv(x,S,p); }
    2418             : INLINE GEN
    2419           0 : FqXQ_invsafe(GEN x, GEN S, GEN T, GEN p)
    2420           0 : { return T? FpXQXQ_invsafe(x,S,T,p): FpXQ_inv(x,S,p); }
    2421             : INLINE GEN
    2422       22348 : FqXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p)
    2423       22348 : { return T? FpXQXQ_mul(x,y,S,T,p): FpXQ_mul(x,y,S,p); }
    2424             : INLINE GEN
    2425           0 : FqXQ_sqr(GEN x, GEN S, GEN T, GEN p)
    2426           0 : { return T? FpXQXQ_sqr(x,S,T,p): FpXQ_sqr(x,S,p); }
    2427             : INLINE GEN
    2428           0 : FqXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p)
    2429           0 : { return T? FpXQXQ_pow(x,n,S,T,p): FpXQ_pow(x,n,S,p); }
    2430             : 
    2431             : /*FqXn*/
    2432             : INLINE GEN
    2433           0 : FqXn_exp(GEN x, long n, GEN T, GEN p)
    2434           0 : { return T? FpXQXn_exp(x,n,T,p): FpXn_exp(x,n,p); }
    2435             : INLINE GEN
    2436           0 : FqXn_inv(GEN x, long n, GEN T, GEN p)
    2437           0 : { return T? FpXQXn_inv(x,n,T,p): FpXn_inv(x,n,p); }
    2438             : INLINE GEN
    2439           0 : FqXn_mul(GEN x, GEN y, long n, GEN T, GEN p)
    2440           0 : { return T? FpXQXn_mul(x, y, n, T, p): FpXn_mul(x, y, n, p); }
    2441             : INLINE GEN
    2442           0 : FqXn_sqr(GEN x, long n, GEN T, GEN p)
    2443           0 : { return T? FpXQXn_sqr(x,n,T,p): FpXn_sqr(x,n,p); }
    2444             : 
    2445             : /*FpXQ*/
    2446             : INLINE GEN
    2447           0 : FpXQ_add(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2448           0 : { (void)T; return FpX_add(x,y,p); }
    2449             : INLINE GEN
    2450           0 : FpXQ_sub(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2451           0 : { (void)T; return FpX_sub(x,y,p); }
    2452             : 
    2453             : /*Flxq*/
    2454             : INLINE GEN
    2455           0 : Flxq_add(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2456           0 : { (void)T; return Flx_add(x,y,p); }
    2457             : INLINE GEN
    2458           0 : Flxq_sub(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2459           0 : { (void)T; return Flx_sub(x,y,p); }
    2460             : 
    2461             : /* F2x */
    2462             : 
    2463             : INLINE ulong
    2464   134966245 : F2x_coeff(GEN x,long v)
    2465             : {
    2466   134966245 :    ulong u=(ulong)x[2+divsBIL(v)];
    2467   134964830 :    return (u>>remsBIL(v))&1UL;
    2468             : }
    2469             : 
    2470             : INLINE void
    2471     5534401 : F2x_clear(GEN x,long v)
    2472             : {
    2473     5534401 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2474     5534400 :    *u&=~(1UL<<remsBIL(v));
    2475     5534399 : }
    2476             : 
    2477             : INLINE void
    2478    33467264 : F2x_set(GEN x,long v)
    2479             : {
    2480    33467264 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2481    33442393 :    *u|=1UL<<remsBIL(v);
    2482    33433542 : }
    2483             : 
    2484             : INLINE void
    2485     1505895 : F2x_flip(GEN x,long v)
    2486             : {
    2487     1505895 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2488     1505895 :    *u^=1UL<<remsBIL(v);
    2489     1505894 : }
    2490             : 
    2491             : /* F2v */
    2492             : 
    2493             : INLINE ulong
    2494   130288189 : F2v_coeff(GEN x,long v) { return F2x_coeff(x,v-1); }
    2495             : 
    2496             : INLINE void
    2497     5534401 : F2v_clear(GEN x,long v) { F2x_clear(x,v-1); }
    2498             : 
    2499             : INLINE void
    2500     9534069 : F2v_set(GEN x,long v)   { F2x_set(x,v-1); }
    2501             : 
    2502             : INLINE void
    2503     1505895 : F2v_flip(GEN x,long v) { F2x_flip(x,v-1); }
    2504             : 
    2505             : /* F2m */
    2506             : 
    2507             : INLINE ulong
    2508    11762927 : F2m_coeff(GEN x, long a, long b) { return F2v_coeff(gel(x,b), a); }
    2509             : 
    2510             : INLINE void
    2511           0 : F2m_clear(GEN x, long a, long b) { F2v_clear(gel(x,b), a); }
    2512             : 
    2513             : INLINE void
    2514     2060485 : F2m_set(GEN x, long a, long b) { F2v_set(gel(x,b), a); }
    2515             : 
    2516             : INLINE void
    2517     1505895 : F2m_flip(GEN x, long a, long b) { F2v_flip(gel(x,b), a); }
    2518             : 
    2519             : /* ARITHMETIC */
    2520             : INLINE GEN
    2521        2114 : matpascal(long n) { return matqpascal(n, NULL); }
    2522             : INLINE long
    2523     2334942 : Z_issquare(GEN x) { return Z_issquareall(x, NULL); }
    2524             : INLINE long
    2525          14 : Z_ispower(GEN x, ulong k) { return Z_ispowerall(x, k, NULL); }
    2526             : INLINE GEN
    2527     5809961 : sqrti(GEN x) { return sqrtremi(x,NULL); }
    2528             : INLINE GEN
    2529     5957129 : gaddgs(GEN y, long s) { return gaddsg(s,y); }
    2530             : INLINE int
    2531       72372 : gcmpgs(GEN y, long s) { return -gcmpsg(s,y); }
    2532             : INLINE int
    2533       24542 : gequalgs(GEN y, long s) { return gequalsg(s,y); }
    2534             : INLINE GEN
    2535           0 : gmaxsg(long s, GEN y) { return gmaxgs(y,s); }
    2536             : INLINE GEN
    2537           0 : gminsg(long s, GEN y) { return gmings(y,s); }
    2538             : INLINE GEN
    2539    20891907 : gmulgs(GEN y, long s) { return gmulsg(s,y); }
    2540             : INLINE GEN
    2541      986015 : gsubgs(GEN y, long s) { return gaddgs(y, -s); }
    2542             : INLINE GEN
    2543      196977 : gdivsg(long s, GEN y) { return gdiv(stoi(s), y); }
    2544             : 
    2545             : /* x t_COMPLEX */
    2546             : INLINE GEN
    2547    16014553 : cxnorm(GEN x) { return gadd(gsqr(gel(x,1)), gsqr(gel(x,2))); }
    2548             : /* q t_QUAD */
    2549             : INLINE GEN
    2550         966 : quadnorm(GEN q)
    2551             : {
    2552         966 :   GEN X = gel(q,1), b = gel(X,3), c = gel(X,2);
    2553         966 :   GEN z, u = gel(q,3), v = gel(q,2);
    2554         966 :   if (typ(u) == t_INT && typ(v) == t_INT) /* generic case */
    2555             :   {
    2556         651 :     z = signe(b)? mulii(v, addii(u,v)): sqri(v);
    2557         651 :     return addii(z, mulii(c, sqri(u)));
    2558             :   }
    2559             :   else
    2560             :   {
    2561         315 :     z = signe(b)? gmul(v, gadd(u,v)): gsqr(v);
    2562         315 :     return gadd(z, gmul(c, gsqr(u)));
    2563             :   }
    2564             : }
    2565             : /* x a t_QUAD, return the attached discriminant */
    2566             : INLINE GEN
    2567        1001 : quad_disc(GEN x)
    2568             : {
    2569        1001 :   GEN Q = gel(x,1), b = gel(Q,3), c = gel(Q,2), c4 = shifti(c,2);
    2570        1001 :   if (is_pm1(b)) return subsi(1, c4);
    2571         147 :   togglesign_safe(&c4); return c4;
    2572             : }
    2573             : INLINE GEN
    2574     6386723 : qfb_disc3(GEN x, GEN y, GEN z) { return subii(sqri(y), shifti(mulii(x,z),2)); }
    2575             : INLINE GEN
    2576     6305782 : qfb_disc(GEN x) { return qfb_disc3(gel(x,1), gel(x,2), gel(x,3)); }
    2577             : 
    2578             : INLINE GEN
    2579     1384113 : sqrfrac(GEN x)
    2580             : {
    2581     1384113 :   GEN z = cgetg(3,t_FRAC);
    2582     1384113 :   gel(z,1) = sqri(gel(x,1));
    2583     1384113 :   gel(z,2) = sqri(gel(x,2)); return z;
    2584             : }
    2585             : 
    2586             : INLINE void
    2587    37837797 : normalize_frac(GEN z) {
    2588    37837797 :   if (signe(gel(z,2)) < 0) { togglesign(gel(z,1)); setabssign(gel(z,2)); }
    2589    37837797 : }
    2590             : 
    2591             : INLINE GEN
    2592      265658 : powii(GEN x, GEN n)
    2593             : {
    2594      265658 :   long ln = lgefint(n);
    2595      265658 :   if (ln == 3) {
    2596             :     GEN z;
    2597      261178 :     if (signe(n) > 0) return powiu(x, n[2]);
    2598        8239 :     z = cgetg(3, t_FRAC);
    2599        8239 :     gel(z,1) = gen_1;
    2600        8239 :     gel(z,2) = powiu(x, n[2]);
    2601        8239 :     return z;
    2602             :   }
    2603        4480 :   if (ln == 2) return gen_1; /* rare */
    2604             :   /* should never happen */
    2605           0 :   return powgi(x, n); /* overflow unless x = 0, 1, -1 */
    2606             : }
    2607             : INLINE GEN
    2608        1351 : powIs(long n) {
    2609        1351 :   switch(n & 3)
    2610             :   {
    2611          63 :     case 1: return mkcomplex(gen_0,gen_1);
    2612         385 :     case 2: return gen_m1;
    2613         560 :     case 3: return mkcomplex(gen_0,gen_m1);
    2614             :   }
    2615         343 :   return gen_1;
    2616             : }
    2617             : 
    2618             : /*******************************************************************/
    2619             : /*                                                                 */
    2620             : /*                             ASSIGNMENTS                         */
    2621             : /*                                                                 */
    2622             : /*******************************************************************/
    2623           0 : INLINE void mpexpz(GEN x, GEN z)
    2624           0 : { pari_sp av = avma; gaffect(mpexp(x), z); set_avma(av); }
    2625           0 : INLINE void mplogz(GEN x, GEN z)
    2626           0 : { pari_sp av = avma; gaffect(mplog(x), z); set_avma(av); }
    2627           0 : INLINE void mpcosz(GEN x, GEN z)
    2628           0 : { pari_sp av = avma; gaffect(mpcos(x), z); set_avma(av); }
    2629           0 : INLINE void mpsinz(GEN x, GEN z)
    2630           0 : { pari_sp av = avma; gaffect(mpsin(x), z); set_avma(av); }
    2631           0 : INLINE void gnegz(GEN x, GEN z)
    2632           0 : { pari_sp av = avma; gaffect(gneg(x), z); set_avma(av); }
    2633           0 : INLINE void gabsz(GEN x, long prec, GEN z)
    2634           0 : { pari_sp av = avma; gaffect(gabs(x,prec), z); set_avma(av); }
    2635           0 : INLINE void gaddz(GEN x, GEN y, GEN z)
    2636           0 : { pari_sp av = avma; gaffect(gadd(x,y), z); set_avma(av); }
    2637           0 : INLINE void gsubz(GEN x, GEN y, GEN z)
    2638           0 : { pari_sp av = avma; gaffect(gsub(x,y), z); set_avma(av); }
    2639           0 : INLINE void gmulz(GEN x, GEN y, GEN z)
    2640           0 : { pari_sp av = avma; gaffect(gmul(x,y), z); set_avma(av); }
    2641           0 : INLINE void gdivz(GEN x, GEN y, GEN z)
    2642           0 : { pari_sp av = avma; gaffect(gdiv(x,y), z); set_avma(av); }
    2643           0 : INLINE void gdiventz(GEN x, GEN y, GEN z)
    2644           0 : { pari_sp av = avma; gaffect(gdivent(x,y), z); set_avma(av); }
    2645           0 : INLINE void gmodz(GEN x, GEN y, GEN z)
    2646           0 : { pari_sp av = avma; gaffect(gmod(x,y), z); set_avma(av); }
    2647           0 : INLINE void gmul2nz(GEN x, long s, GEN z)
    2648           0 : { pari_sp av = avma; gaffect(gmul2n(x,s), z); set_avma(av); }
    2649           0 : INLINE void gshiftz(GEN x, long s, GEN z)
    2650           0 : { pari_sp av = avma; gaffect(gshift(x,s), z); set_avma(av); }
    2651             : 
    2652             : /*******************************************************************/
    2653             : /*                                                                 */
    2654             : /*                       ELLIPTIC CURVES                           */
    2655             : /*                                                                 */
    2656             : /*******************************************************************/
    2657     3985043 : INLINE GEN ell_get_a1(GEN e) { return gel(e,1); }
    2658     3098802 : INLINE GEN ell_get_a2(GEN e) { return gel(e,2); }
    2659     3866365 : INLINE GEN ell_get_a3(GEN e) { return gel(e,3); }
    2660     3891713 : INLINE GEN ell_get_a4(GEN e) { return gel(e,4); }
    2661     4708494 : INLINE GEN ell_get_a6(GEN e) { return gel(e,5); }
    2662     3323386 : INLINE GEN ell_get_b2(GEN e) { return gel(e,6); }
    2663     1027590 : INLINE GEN ell_get_b4(GEN e) { return gel(e,7); }
    2664     1633608 : INLINE GEN ell_get_b6(GEN e) { return gel(e,8); }
    2665     1464911 : INLINE GEN ell_get_b8(GEN e) { return gel(e,9); }
    2666     6213134 : INLINE GEN ell_get_c4(GEN e) { return gel(e,10); }
    2667     7451236 : INLINE GEN ell_get_c6(GEN e) { return gel(e,11); }
    2668     9705417 : INLINE GEN ell_get_disc(GEN e) { return gel(e,12); }
    2669     1031359 : INLINE GEN ell_get_j(GEN e) { return gel(e,13); }
    2670    11473102 : INLINE long ell_get_type(GEN e) { return mael(e,14,1); }
    2671     1570141 : INLINE GEN ellff_get_field(GEN x) { return gmael(x, 15, 1); }
    2672      682702 : INLINE GEN ellff_get_a4a6(GEN x)  { return gmael(x, 15, 2); }
    2673        1407 : INLINE GEN ellQp_get_zero(GEN x) { return gmael(x, 15, 1); }
    2674         287 : INLINE long ellQp_get_prec(GEN E) { GEN z = ellQp_get_zero(E); return valp(z); }
    2675        1085 : INLINE GEN ellQp_get_p(GEN E) { GEN z = ellQp_get_zero(E); return gel(z,2); }
    2676       37471 : INLINE long ellR_get_prec(GEN x) { return nbits2prec(mael3(x, 15, 1, 1)); }
    2677       13748 : INLINE long ellR_get_sign(GEN x) { return mael3(x, 15, 1, 2); }
    2678      701074 : INLINE GEN ellnf_get_nf(GEN x) { return checknf_i(gmael(x,15,1)); }
    2679          56 : INLINE GEN ellnf_get_bnf(GEN x) { return checkbnf_i(gmael(x,15,1)); }
    2680             : 
    2681     4630152 : INLINE int checkell_i(GEN e) { return typ(e) == t_VEC && lg(e) == 17; }
    2682    33994878 : INLINE int ell_is_inf(GEN z) { return lg(z) == 2; }
    2683      808419 : INLINE GEN ellinf(void) { return mkvec(gen_0); }
    2684             : 
    2685             : /*******************************************************************/
    2686             : /*                                                                 */
    2687             : /*                    ALGEBRAIC NUMBER THEORY                      */
    2688             : /*                                                                 */
    2689             : /*******************************************************************/
    2690     8654953 : INLINE GEN modpr_get_pr(GEN x)  { return gel(x,3); }
    2691      627893 : INLINE GEN modpr_get_p(GEN x)  { return pr_get_p(modpr_get_pr(x)); }
    2692     2771928 : INLINE GEN modpr_get_T(GEN x)  { return lg(x) == 4? NULL: gel(x,4); }
    2693             : 
    2694    26443628 : INLINE GEN pr_get_p(GEN pr)  { return gel(pr,1); }
    2695     7396543 : INLINE GEN pr_get_gen(GEN pr){ return gel(pr,2); }
    2696             : /* .[2] instead of itos works: e and f are small positive integers */
    2697     2442308 : INLINE long pr_get_e(GEN pr) { return gel(pr,3)[2]; }
    2698    12671617 : INLINE long pr_get_f(GEN pr) { return gel(pr,4)[2]; }
    2699    10293775 : INLINE GEN pr_get_tau(GEN pr){ return gel(pr,5); }
    2700             : INLINE int
    2701     3504552 : pr_is_inert(GEN P) { return pr_get_f(P) == lg(pr_get_gen(P))-1; }
    2702             : INLINE GEN
    2703     1912803 : pr_norm(GEN pr) { return powiu(pr_get_p(pr), pr_get_f(pr)); }
    2704             : INLINE ulong
    2705       91532 : upr_norm(GEN pr) { return upowuu(pr_get_p(pr)[2], pr_get_f(pr)); }
    2706             : 
    2707             : /* assume nf a genuine nf */
    2708             : INLINE long
    2709      398825 : nf_get_varn(GEN nf) { return varn(gel(nf,1)); }
    2710             : INLINE GEN
    2711    35530170 : nf_get_pol(GEN nf) { return gel(nf,1); }
    2712             : INLINE long
    2713    28266893 : nf_get_degree(GEN nf) { return degpol( nf_get_pol(nf) ); }
    2714             : INLINE long
    2715     4248382 : nf_get_r1(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,1)); }
    2716             : INLINE long
    2717        1806 : nf_get_r2(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,2)); }
    2718             : INLINE GEN
    2719       62374 : nf_get_disc(GEN nf) { return gel(nf,3); }
    2720             : INLINE GEN
    2721      931683 : nf_get_index(GEN nf) { return gel(nf,4); }
    2722             : INLINE GEN
    2723     2938747 : nf_get_M(GEN nf) { return gmael(nf,5,1); }
    2724             : INLINE GEN
    2725     1669989 : nf_get_G(GEN nf) { return gmael(nf,5,2); }
    2726             : INLINE GEN
    2727     2115449 : nf_get_roundG(GEN nf) { return gmael(nf,5,3); }
    2728             : INLINE GEN
    2729       26103 : nf_get_Tr(GEN nf) { return gmael(nf,5,4); }
    2730             : INLINE GEN
    2731        2709 : nf_get_diff(GEN nf) { return gmael(nf,5,5); }
    2732             : INLINE GEN
    2733        2660 : nf_get_ramified_primes(GEN nf) { return gmael(nf,5,8); }
    2734             : INLINE GEN
    2735      388372 : nf_get_roots(GEN nf) { return gel(nf,6); }
    2736             : INLINE GEN
    2737          98 : nf_get_zk(GEN nf)
    2738             : {
    2739          98 :   GEN y = gel(nf,7), D = gel(y, 1);
    2740          98 :   if (typ(D) == t_POL) D = gel(D, 2);
    2741          98 :   if (!equali1(D)) y = gdiv(y, D);
    2742          98 :   return y;
    2743             : }
    2744             : INLINE GEN
    2745      431340 : nf_get_zkprimpart(GEN nf)
    2746             : {
    2747      431340 :   GEN y = gel(nf,7);
    2748             :   /* test for old format of nf.zk: non normalized */
    2749      431340 :   if (!equali1(gel(nf,4)) && gequal1(gel(y,1))) y = Q_remove_denom(y,NULL);
    2750      431339 :   return y;
    2751             : }
    2752             : INLINE GEN
    2753      432872 : nf_get_zkden(GEN nf)
    2754             : {
    2755      432872 :   GEN y = gel(nf,7), D = gel(y,1);
    2756      432872 :   if (typ(D) == t_POL) D = gel(D,2);
    2757             :   /* test for old format of nf.zk: non normalized */
    2758      432872 :   if (!equali1(gel(nf,4)) && equali1(D)) D = Q_denom(y);
    2759      432870 :   return D;
    2760             : }
    2761             : INLINE GEN
    2762     2842352 : nf_get_invzk(GEN nf) { return gel(nf,8); }
    2763             : INLINE void
    2764       24036 : nf_get_sign(GEN nf, long *r1, long *r2)
    2765             : {
    2766       24036 :   GEN x = gel(nf,2);
    2767       24036 :   *r1 = itou(gel(x,1));
    2768       24036 :   *r2 = itou(gel(x,2));
    2769       24036 : }
    2770             : 
    2771             : INLINE GEN
    2772       95292 : abgrp_get_no(GEN x) { return gel(x,1); }
    2773             : INLINE GEN
    2774     3020908 : abgrp_get_cyc(GEN x) { return gel(x,2); }
    2775             : INLINE GEN
    2776      345700 : abgrp_get_gen(GEN x) { return gel(x,3); }
    2777             : INLINE GEN
    2778     2468492 : bnf_get_nf(GEN bnf) { return gel(bnf,7); }
    2779             : INLINE GEN
    2780     1235844 : bnf_get_clgp(GEN bnf) { return gmael(bnf,8,1); }
    2781             : INLINE GEN
    2782        7140 : bnf_get_no(GEN bnf) { return abgrp_get_no(bnf_get_clgp(bnf)); }
    2783             : INLINE GEN
    2784      931115 : bnf_get_cyc(GEN bnf) { return abgrp_get_cyc(bnf_get_clgp(bnf)); }
    2785             : INLINE GEN
    2786      297239 : bnf_get_gen(GEN bnf)  { return abgrp_get_gen(bnf_get_clgp(bnf)); }
    2787             : INLINE GEN
    2788        1210 : bnf_get_reg(GEN bnf) { return gmael(bnf,8,2); }
    2789             : INLINE GEN
    2790      540649 : bnf_get_logfu(GEN bnf) { return gel(bnf,3); }
    2791             : INLINE GEN
    2792        5259 : bnf_get_sunits(GEN bnf)
    2793        5259 : { GEN s = gmael(bnf,8,3); return typ(s) == t_INT? NULL: s; }
    2794             : INLINE GEN
    2795       39180 : bnf_get_tuU(GEN bnf) { return gmael3(bnf,8,4,2); }
    2796             : INLINE long
    2797       40656 : bnf_get_tuN(GEN bnf) { return gmael3(bnf,8,4,1)[2]; }
    2798             : INLINE GEN
    2799       38969 : bnf_get_fu_nocheck(GEN bnf) { return gmael(bnf,8,5); }
    2800             : INLINE GEN
    2801        1687 : bnf_get_fu(GEN bnf) {
    2802        1687 :   GEN fu = bnf_build_units(bnf), nf = bnf_get_nf(bnf);
    2803             :   long i, l;
    2804        1687 :   if (typ(fu) == t_MAT) pari_err(e_MISC,"missing units in bnf");
    2805        1687 :   l = lg(fu)-1; fu = vecslice(fu, 2, l);
    2806        1687 :   for (i = 1; i < l; i++) gel(fu,i) = nf_to_scalar_or_alg(nf, gel(fu,i));
    2807        1687 :   return fu;
    2808             : }
    2809             : 
    2810             : INLINE GEN
    2811      991798 : bnr_get_bnf(GEN bnr) { return gel(bnr,1); }
    2812             : INLINE GEN
    2813      506791 : bnr_get_bid(GEN bnr) { return gel(bnr,2); }
    2814             : INLINE GEN
    2815       20237 : bnr_get_mod(GEN bnr) { return gmael(bnr,2,1); }
    2816             : INLINE GEN
    2817       36946 : bnr_get_nf(GEN bnr) { return gmael(bnr,1,7); }
    2818             : INLINE GEN
    2819      753758 : bnr_get_clgp(GEN bnr) { return gel(bnr,5); }
    2820             : INLINE GEN
    2821       84385 : bnr_get_no(GEN bnr) { return abgrp_get_no(bnr_get_clgp(bnr)); }
    2822             : INLINE GEN
    2823      653077 : bnr_get_cyc(GEN bnr) { return abgrp_get_cyc(bnr_get_clgp(bnr)); }
    2824             : INLINE GEN
    2825          70 : bnr_get_gen_nocheck(GEN bnr) { return abgrp_get_gen(bnr_get_clgp(bnr)); }
    2826             : INLINE GEN
    2827       14931 : bnr_get_gen(GEN bnr) {
    2828       14931 :   GEN G = bnr_get_clgp(bnr);
    2829       14931 :   if (lg(G) !=  4)
    2830           0 :     pari_err(e_MISC,"missing bnr generators: please use bnrinit(,,1)");
    2831       14931 :   return gel(G,3);
    2832             : }
    2833             : 
    2834             : INLINE GEN
    2835      299143 : bid_get_mod(GEN bid) { return gel(bid,1); }
    2836             : INLINE GEN
    2837       68684 : bid_get_ideal(GEN bid) { return gmael(bid,1,1); }
    2838             : INLINE GEN
    2839        1260 : bid_get_arch(GEN bid) { return gmael(bid,1,2); }
    2840             : INLINE GEN
    2841     1291641 : bid_get_grp(GEN bid) { return gel(bid,2); }
    2842             : INLINE GEN
    2843      506406 : bid_get_fact(GEN bid) { return gmael(bid,3,1); }
    2844             : INLINE GEN
    2845      435776 : bid_get_fact2(GEN bid) { return gmael(bid,3,2); }
    2846             : INLINE GEN
    2847      434789 : bid_get_sprk(GEN bid) { return gmael(bid,4,1); }
    2848             : INLINE GEN
    2849       49182 : bid_get_sarch(GEN bid) { return gmael(bid,4,2); }
    2850             : INLINE GEN
    2851      471385 : bid_get_archp(GEN bid) { return gmael3(bid,4,2,2); }
    2852             : INLINE GEN
    2853      734198 : bid_get_U(GEN bid) { return gel(bid,5); }
    2854             : INLINE GEN
    2855           0 : bid_get_no(GEN bid) { return abgrp_get_no(bid_get_grp(bid)); }
    2856             : INLINE GEN
    2857     1244195 : bid_get_cyc(GEN bid) { return abgrp_get_cyc(bid_get_grp(bid)); }
    2858             : INLINE GEN
    2859           0 : bid_get_gen_nocheck(GEN bid)  { return abgrp_get_gen(bid_get_grp(bid)); }
    2860             : INLINE GEN
    2861       46865 : bid_get_gen(GEN bid) {
    2862       46865 :   GEN G = bid_get_grp(bid);
    2863       46865 :   if (lg(G) != 4) pari_err(e_MISC,"missing bid generators. Use idealstar(,,2)");
    2864       46865 :   return abgrp_get_gen(G);
    2865             : }
    2866             : 
    2867             : INLINE GEN
    2868    25992085 : znstar_get_N(GEN G) { return gmael(G,1,1); }
    2869             : INLINE GEN
    2870     2917110 : znstar_get_faN(GEN G) { return gel(G,3); }
    2871             : INLINE GEN
    2872           7 : znstar_get_no(GEN G) { return abgrp_get_no(gel(G,2)); }
    2873             : INLINE GEN
    2874      191093 : znstar_get_cyc(GEN G) { return abgrp_get_cyc(gel(G,2)); }
    2875             : INLINE GEN
    2876           7 : znstar_get_gen(GEN G) { return abgrp_get_gen(gel(G,2)); }
    2877             : INLINE GEN
    2878     3590937 : znstar_get_conreycyc(GEN G) { return gmael(G,4,5); }
    2879             : INLINE GEN
    2880     1237467 : znstar_get_conreygen(GEN G) { return gmael(G,4,4); }
    2881             : INLINE GEN
    2882       45927 : znstar_get_Ui(GEN G) { return gmael(G,4,3); }
    2883             : INLINE GEN
    2884      120162 : znstar_get_U(GEN G) { return gel(G,5); }
    2885             : INLINE GEN
    2886      842464 : znstar_get_pe(GEN G) { return gmael(G,4,1); }
    2887             : INLINE GEN
    2888       20755 : gal_get_pol(GEN gal) { return gel(gal,1); }
    2889             : INLINE GEN
    2890        1470 : gal_get_p(GEN gal) { return gmael(gal,2,1); }
    2891             : INLINE GEN
    2892         119 : gal_get_e(GEN gal) { return gmael(gal,2,2); }
    2893             : INLINE GEN
    2894       16135 : gal_get_mod(GEN gal) { return gmael(gal,2,3); }
    2895             : INLINE GEN
    2896       17157 : gal_get_roots(GEN gal) { return gel(gal,3); }
    2897             : INLINE GEN
    2898       16681 : gal_get_invvdm(GEN gal) { return gel(gal,4); }
    2899             : INLINE GEN
    2900       16681 : gal_get_den(GEN gal) { return gel(gal,5); }
    2901             : INLINE GEN
    2902       68162 : gal_get_group(GEN gal) { return gel(gal,6); }
    2903             : INLINE GEN
    2904        1785 : gal_get_gen(GEN gal) { return gel(gal,7); }
    2905             : INLINE GEN
    2906        1428 : gal_get_orders(GEN gal) { return gel(gal,8); }
    2907             : 
    2908             : /* assume rnf a genuine rnf */
    2909             : INLINE long
    2910     1230831 : rnf_get_degree(GEN rnf) { return degpol(rnf_get_pol(rnf)); }
    2911             : INLINE long
    2912       16681 : rnf_get_nfdegree(GEN rnf) { return degpol(nf_get_pol(rnf_get_nf(rnf))); }
    2913             : INLINE long
    2914      774613 : rnf_get_absdegree(GEN rnf) { return degpol(gmael(rnf,11,1)); }
    2915             : INLINE GEN
    2916         700 : rnf_get_idealdisc(GEN rnf) { return gmael(rnf,3,1); }
    2917             : INLINE GEN
    2918         749 : rnf_get_k(GEN rnf) { return gmael(rnf,11,3); }
    2919             : INLINE GEN
    2920         805 : rnf_get_alpha(GEN rnf) { return gmael(rnf, 11, 2); }
    2921             : INLINE GEN
    2922      423010 : rnf_get_nf(GEN rnf) { return gel(rnf,10); }
    2923             : INLINE GEN
    2924        3808 : rnf_get_nfzk(GEN rnf) { return gel(rnf,2); }
    2925             : INLINE GEN
    2926      207984 : rnf_get_polabs(GEN rnf) { return gmael(rnf,11,1); }
    2927             : INLINE GEN
    2928     1476461 : rnf_get_pol(GEN rnf) { return gel(rnf,1); }
    2929             : INLINE GEN
    2930         175 : rnf_get_disc(GEN rnf) { return gel(rnf,3); }
    2931             : INLINE GEN
    2932         105 : rnf_get_index(GEN rnf) { return gel(rnf,4); }
    2933             : INLINE GEN
    2934        1561 : rnf_get_ramified_primes(GEN rnf) { return gel(rnf,5); }
    2935             : INLINE long
    2936           0 : rnf_get_varn(GEN rnf) { return varn(gel(rnf,1)); }
    2937             : INLINE GEN
    2938      187999 : rnf_get_nfpol(GEN rnf) { return gmael(rnf,10,1); }
    2939             : INLINE long
    2940        3332 : rnf_get_nfvarn(GEN rnf) { return varn(gmael(rnf,10,1)); }
    2941             : INLINE GEN
    2942        3500 : rnf_get_zk(GEN rnf) { return gel(rnf,7); }
    2943             : INLINE GEN
    2944      102746 : rnf_get_map(GEN rnf) { return gel(rnf,11); }
    2945             : INLINE GEN
    2946        1197 : rnf_get_invzk(GEN rnf) { return gel(rnf,8); }
    2947             : 
    2948             : /* I integral ZM (not HNF), G ZM, rounded Cholesky form of a weighted
    2949             :  * T2 matrix. Reduce I wrt G */
    2950             : INLINE GEN
    2951       22267 : idealpseudored(GEN I, GEN G)
    2952       22267 : { return ZM_mul(I, ZM_lll(ZM_mul(G, I), 0.99, LLL_IM)); }
    2953             : 
    2954             : /* I integral (not necessarily HNF), G ZM, rounded Cholesky form of a weighted
    2955             :  * T2 matrix. Return m in I with T2(m) small */
    2956             : INLINE GEN
    2957      131769 : idealpseudomin(GEN I, GEN G)
    2958             : {
    2959      131769 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2960      131769 :   return ZM_ZC_mul(I, gel(u,1));
    2961             : }
    2962             : /* I, G as in idealpseudomin. Return an irrational m in I with T2(m) small */
    2963             : INLINE GEN
    2964      355216 : idealpseudomin_nonscalar(GEN I, GEN G)
    2965             : {
    2966      355216 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2967      355216 :   GEN m = ZM_ZC_mul(I, gel(u,1));
    2968      355216 :   if (ZV_isscalar(m) && lg(u) > 2) m = ZM_ZC_mul(I, gel(u,2));
    2969      355216 :   return m;
    2970             : }
    2971             : 
    2972             : INLINE GEN
    2973         945 : idealred_elt(GEN nf, GEN I) {
    2974         945 :   pari_sp av = avma;
    2975         945 :   GEN u = idealpseudomin(I, nf_get_roundG(nf));
    2976         945 :   return gerepileupto(av, u);
    2977             : }
    2978             : INLINE GEN
    2979      139330 : idealred(GEN nf, GEN I) { return idealred0(nf, I, NULL); }
    2980             : 
    2981             : INLINE GEN
    2982        2023 : idealchineseinit(GEN nf, GEN x)
    2983        2023 : { return idealchinese(nf,x,NULL); }
    2984             : 
    2985             : /*******************************************************************/
    2986             : /*                                                                 */
    2987             : /*                              CLOSURES                           */
    2988             : /*                                                                 */
    2989             : /*******************************************************************/
    2990   235536065 : INLINE long closure_arity(GEN C)          { return ((ulong)C[1])&ARITYBITS; }
    2991    36094351 : INLINE long closure_is_variadic(GEN C) { return !!(((ulong)C[1])&VARARGBITS); }
    2992   194966400 : INLINE const char *closure_codestr(GEN C)  { return GSTR(gel(C,2))-1; }
    2993           0 : INLINE GEN closure_get_code(GEN C)  { return gel(C,2); }
    2994   194949327 : INLINE GEN closure_get_oper(GEN C)  { return gel(C,3); }
    2995   194935808 : INLINE GEN closure_get_data(GEN C)  { return gel(C,4); }
    2996       10160 : INLINE GEN closure_get_dbg(GEN C)   { return gel(C,5); }
    2997       24261 : INLINE GEN closure_get_text(GEN C)  { return gel(C,6); }
    2998     5981809 : INLINE GEN closure_get_frame(GEN C) { return gel(C,7); }
    2999             : 
    3000             : /*******************************************************************/
    3001             : /*                                                                 */
    3002             : /*                               ERRORS                            */
    3003             : /*                                                                 */
    3004             : /*******************************************************************/
    3005             : INLINE long
    3006       54041 : err_get_num(GEN e) { return e[1]; }
    3007             : INLINE GEN
    3008          84 : err_get_compo(GEN e, long i) { return gel(e, i+1); }
    3009             : 
    3010             : INLINE void
    3011          14 : pari_err_BUG(const char *f) { pari_err(e_BUG,f); }
    3012             : INLINE void
    3013           7 : pari_err_CONSTPOL(const char *f) { pari_err(e_CONSTPOL, f); }
    3014             : INLINE void
    3015          63 : pari_err_COPRIME(const char *f, GEN x, GEN y) { pari_err(e_COPRIME, f,x,y); }
    3016             : INLINE void
    3017         494 : pari_err_DIM(const char *f) { pari_err(e_DIM, f); }
    3018             : INLINE void
    3019           0 : pari_err_FILE(const char *f, const char *g) { pari_err(e_FILE, f,g); }
    3020             : INLINE void
    3021           0 : pari_err_FILEDESC(const char *f, long n) { pari_err(e_FILEDESC, f,n); }
    3022             : INLINE void
    3023          84 : pari_err_FLAG(const char *f) { pari_err(e_FLAG,f); }
    3024             : INLINE void
    3025         448 : pari_err_IMPL(const char *f) { pari_err(e_IMPL,f); }
    3026             : INLINE void
    3027       19730 : pari_err_INV(const char *f, GEN x) { pari_err(e_INV,f,x); }
    3028             : INLINE void
    3029          42 : pari_err_IRREDPOL(const char *f, GEN x) { pari_err(e_IRREDPOL, f,x); }
    3030             : INLINE void
    3031        2141 : 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); }
    3032             : INLINE void
    3033         200 : pari_err_COMPONENT(const char *f, const char *op, GEN l, GEN x) { pari_err(e_COMPONENT, f,op,l,x); }
    3034             : INLINE void
    3035           0 : pari_err_MAXPRIME(ulong c) { pari_err(e_MAXPRIME, c); }
    3036             : INLINE void
    3037         364 : pari_err_OP(const char *f, GEN x, GEN y) { pari_err(e_OP, f,x,y); }
    3038             : INLINE void
    3039         100 : pari_err_OVERFLOW(const char *f) { pari_err(e_OVERFLOW, f); }
    3040             : INLINE void
    3041         225 : pari_err_PREC(const char *f) { pari_err(e_PREC,f); }
    3042             : INLINE void
    3043           0 : pari_err_PACKAGE(const char *f) { pari_err(e_PACKAGE,f); }
    3044             : INLINE void
    3045          70 : pari_err_PRIME(const char *f, GEN x) { pari_err(e_PRIME, f,x); }
    3046             : INLINE void
    3047         749 : pari_err_MODULUS(const char *f, GEN x, GEN y) { pari_err(e_MODULUS, f,x,y); }
    3048             : INLINE void
    3049          49 : pari_err_ROOTS0(const char *f) { pari_err(e_ROOTS0, f); }
    3050             : INLINE void
    3051          84 : pari_err_SQRTN(const char *f, GEN x) { pari_err(e_SQRTN, f,x); }
    3052             : INLINE void
    3053       12895 : pari_err_TYPE(const char *f, GEN x) { pari_err(e_TYPE, f,x); }
    3054             : INLINE void
    3055        3388 : pari_err_TYPE2(const char *f, GEN x, GEN y) { pari_err(e_TYPE2, f,x,y); }
    3056             : INLINE void
    3057         280 : pari_err_VAR(const char *f, GEN x, GEN y) { pari_err(e_VAR, f,x,y); }
    3058             : INLINE void
    3059         196 : pari_err_PRIORITY(const char *f, GEN x, const char *op, long v)
    3060         196 : { pari_err(e_PRIORITY, f,x,op,v); }

Generated by: LCOV version 1.13