Code coverage tests

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

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

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

LCOV - code coverage report
Current view: top level - headers - pariinl.h (source / functions) Hit Total Coverage
Test: PARI/GP v2.10.0 lcov report (development 22296-eb24562) Lines: 1253 1420 88.2 %
Date: 2018-04-19 06:16:12 Functions: 555 629 88.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (C) 2000-2010  The PARI group.
       2             : 
       3             : This file is part of the PARI/GP package.
       4             : 
       5             : PARI/GP is free software; you can redistribute it and/or modify it under the
       6             : terms of the GNU General Public License as published by the Free Software
       7             : Foundation. It is distributed in the hope that it will be useful, but WITHOUT
       8             : ANY WARRANTY WHATSOEVER.
       9             : 
      10             : Check the License for details. You should have received a copy of it, along
      11             : with the package; see the file 'COPYING'. If not, write to the Free Software
      12             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
      13             : 
      14             : /*******************************************************************/
      15             : /*                                                                 */
      16             : /*                          CONSTRUCTORS                           */
      17             : /*                                                                 */
      18             : /*******************************************************************/
      19             : #define retmkfrac(x,y)\
      20             :   do { GEN _v = cgetg(3, t_FRAC);\
      21             :        gel(_v,1) = (x);\
      22             :        gel(_v,2) = (y); return _v; } while(0)
      23             : #define retmkrfrac(x,y)\
      24             :   do { GEN _v = cgetg(3, t_RFRAC);\
      25             :        gel(_v,1) = (x);\
      26             :        gel(_v,2) = (y); return _v; } while(0)
      27             : #define retmkintmod(x,y)\
      28             :   do { GEN _v = cgetg(3, t_INTMOD);\
      29             :        gel(_v,1) = (y);\
      30             :        gel(_v,2) = (x); return _v; } while(0)
      31             : #define retmkcomplex(x,y)\
      32             :   do { GEN _v = cgetg(3, t_COMPLEX);\
      33             :        gel(_v,1) = (x);\
      34             :        gel(_v,2) = (y); return _v; } while(0)
      35             : #define retmkpolmod(x,y)\
      36             :   do { GEN _v = cgetg(3, t_POLMOD);\
      37             :        gel(_v,1) = (y);\
      38             :        gel(_v,2) = (x); return _v; } while(0)
      39             : #define retmkvec(x)\
      40             :   do { GEN _v = cgetg(2, t_VEC);\
      41             :        gel(_v,1) = (x); return _v; } while(0)
      42             : #define retmkvec2(x,y)\
      43             :   do { GEN _v = cgetg(3, t_VEC);\
      44             :        gel(_v,1) = (x);\
      45             :        gel(_v,2) = (y); return _v; } while(0)
      46             : #define retmkvec3(x,y,z)\
      47             :   do { GEN _v = cgetg(4, t_VEC);\
      48             :        gel(_v,1) = (x);\
      49             :        gel(_v,2) = (y);\
      50             :        gel(_v,3) = (z); return _v; } while(0)
      51             : #define retmkqfi(x,y,z)\
      52             :   do { GEN _v = cgetg(4, t_QFI);\
      53             :        gel(_v,1) = (x);\
      54             :        gel(_v,2) = (y);\
      55             :        gel(_v,3) = (z); return _v; } while(0)
      56             : #define retmkqfr(x,y,z,d)\
      57             :   do { GEN _v = cgetg(5, t_QFR);\
      58             :        gel(_v,1) = (x);\
      59             :        gel(_v,2) = (y);\
      60             :        gel(_v,3) = (z);\
      61             :        gel(_v,4) = (d); return _v; } while(0)
      62             : #define retmkquad(x,y,z)\
      63             :   do { GEN _v = cgetg(4, t_QUAD);\
      64             :        gel(_v,1) = (x);\
      65             :        gel(_v,2) = (y);\
      66             :        gel(_v,3) = (z); return _v; } while(0)
      67             : #define retmkvec4(x,y,z,t)\
      68             :   do { GEN _v = cgetg(5, t_VEC);\
      69             :        gel(_v,1) = (x);\
      70             :        gel(_v,2) = (y);\
      71             :        gel(_v,3) = (z);\
      72             :        gel(_v,4) = (t); return _v; } while(0)
      73             : #define retmkvec5(x,y,z,t,u)\
      74             :   do { GEN _v = cgetg(6, t_VEC);\
      75             :        gel(_v,1) = (x);\
      76             :        gel(_v,2) = (y);\
      77             :        gel(_v,3) = (z);\
      78             :        gel(_v,4) = (t);\
      79             :        gel(_v,5) = (u); return _v; } while(0)
      80             : #define retmkcol(x)\
      81             :   do { GEN _v = cgetg(2, t_COL);\
      82             :        gel(_v,1) = (x); return _v; } while(0)
      83             : #define retmkcol2(x,y)\
      84             :   do { GEN _v = cgetg(3, t_COL);\
      85             :        gel(_v,1) = (x);\
      86             :        gel(_v,2) = (y); return _v; } while(0)
      87             : #define retmkcol3(x,y,z)\
      88             :   do { GEN _v = cgetg(4, t_COL);\
      89             :        gel(_v,1) = (x);\
      90             :        gel(_v,2) = (y);\
      91             :        gel(_v,3) = (z); return _v; } while(0)
      92             : #define retmkcol4(x,y,z,t)\
      93             :   do { GEN _v = cgetg(5, t_COL);\
      94             :        gel(_v,1) = (x);\
      95             :        gel(_v,2) = (y);\
      96             :        gel(_v,3) = (z);\
      97             :        gel(_v,4) = (t); return _v; } while(0)
      98             : #define retmkcol5(x,y,z,t,u)\
      99             :   do { GEN _v = cgetg(6, t_COL);\
     100             :        gel(_v,1) = (x);\
     101             :        gel(_v,2) = (y);\
     102             :        gel(_v,3) = (z);\
     103             :        gel(_v,4) = (t);\
     104             :        gel(_v,5) = (u); return _v; } while(0)
     105             : #define retmkcol6(x,y,z,t,u,v)\
     106             :   do { GEN _v = cgetg(7, t_COL);\
     107             :        gel(_v,1) = (x);\
     108             :        gel(_v,2) = (y);\
     109             :        gel(_v,3) = (z);\
     110             :        gel(_v,4) = (t);\
     111             :        gel(_v,5) = (u);\
     112             :        gel(_v,6) = (v); return _v; } while(0)
     113             : #define retmkmat(x)\
     114             :   do { GEN _v = cgetg(2, t_MAT);\
     115             :        gel(_v,1) = (x); return _v; } while(0)
     116             : #define retmkmat2(x,y)\
     117             :   do { GEN _v = cgetg(3, t_MAT);\
     118             :        gel(_v,1) = (x);\
     119             :        gel(_v,2) = (y); return _v; } while(0)
     120             : #define retmkmat3(x,y,z)\
     121             :   do { GEN _v = cgetg(4, t_MAT);\
     122             :        gel(_v,1) = (x);\
     123             :        gel(_v,2) = (y);\
     124             :        gel(_v,3) = (z); return _v; } while(0)
     125             : #define retmkmat4(x,y,z,t)\
     126             :   do { GEN _v = cgetg(5, t_MAT);\
     127             :        gel(_v,1) = (x);\
     128             :        gel(_v,2) = (y);\
     129             :        gel(_v,3) = (z);\
     130             :        gel(_v,4) = (t); return _v; } while(0)
     131             : #define retmkmat5(x,y,z,t,u)\
     132             :   do { GEN _v = cgetg(6, t_MAT);\
     133             :        gel(_v,1) = (x);\
     134             :        gel(_v,2) = (y);\
     135             :        gel(_v,3) = (z);\
     136             :        gel(_v,4) = (t);\
     137             :        gel(_v,5) = (u); return _v; } while(0)
     138             : 
     139             : INLINE GEN
     140     2054625 : mkintmod(GEN x, GEN y) { retmkintmod(x,y); }
     141             : INLINE GEN
     142        3801 : mkintmodu(ulong x, ulong y) {
     143        3801 :   GEN v = cgetg(3,t_INTMOD);
     144        3801 :   gel(v,1) = utoipos(y);
     145        3801 :   gel(v,2) = utoi(x); return v;
     146             : }
     147             : INLINE GEN
     148     2367144 : mkpolmod(GEN x, GEN y) { retmkpolmod(x,y); }
     149             : INLINE GEN
     150    12586324 : mkfrac(GEN x, GEN y) { retmkfrac(x,y); }
     151             : INLINE GEN
     152         385 : mkfracss(long x, long y) { retmkfrac(stoi(x),stoi(y)); }
     153             : /* q = n/d a t_FRAC or t_INT; recover (n,d) */
     154             : INLINE void
     155       10773 : Qtoss(GEN q, long *n, long *d)
     156             : {
     157       10773 :   if (typ(q) == t_INT) { *n = itos(q); *d = 1; }
     158        2275 :   else { *n = itos(gel(q,1)); *d = itou(gel(q,2)); }
     159       10773 : }
     160             : INLINE GEN
     161    35828506 : sstoQ(long n, long d)
     162             : {
     163             :   long g, r, q;
     164    35828506 :   if (d == 1) return stoi(n);
     165    35824999 :   q = sdivss_rem(n,d,&r);
     166    35824999 :   if (!r) return stoi(q);
     167     1417906 :   g = cgcd(d,r); /* gcd(n,d) */
     168     1417906 :   if (g != 1) { n /= g; d /= g; }
     169     1417906 :   if (d < 0) { d = -d; n = -n; }
     170     1417906 :   retmkfrac(stoi(n), utoi(d));
     171             : }
     172             : 
     173             : INLINE GEN
     174     3986303 : mkfraccopy(GEN x, GEN y) { retmkfrac(icopy(x), icopy(y)); }
     175             : INLINE GEN
     176           7 : mkrfrac(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     177           7 :   gel(v,1) = x; gel(v,2) = y; return v; }
     178             : INLINE GEN
     179           7 : mkrfraccopy(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
     180           7 :   gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     181             : INLINE GEN
     182     3381992 : mkcomplex(GEN x, GEN y) { retmkcomplex(x,y); }
     183             : INLINE GEN
     184      449485 : gen_I(void) { return mkcomplex(gen_0, gen_1); }
     185             : INLINE GEN
     186      203899 : cgetc(long l) { retmkcomplex(cgetr(l), cgetr(l)); }
     187             : INLINE GEN
     188          56 : mkquad(GEN n, GEN x, GEN y) { GEN v = cgetg(4, t_QUAD);
     189          56 :   gel(v,1) = n; gel(v,2) = x; gel(v,3) = y; return v; }
     190             : /* vecsmall */
     191             : INLINE GEN
     192    70416567 : mkvecsmall(long x) { GEN v = cgetg(2, t_VECSMALL); v[1] = x; return v; }
     193             : INLINE GEN
     194   120682725 : mkvecsmall2(long x,long y) { GEN v = cgetg(3, t_VECSMALL);
     195   120663588 :   v[1]=x; v[2]=y; return v; }
     196             : INLINE GEN
     197    58030047 : mkvecsmall3(long x,long y,long z) { GEN v = cgetg(4, t_VECSMALL);
     198    58025187 :   v[1]=x; v[2]=y; v[3]=z; return v; }
     199             : INLINE GEN
     200    11945263 : mkvecsmall4(long x,long y,long z,long t) { GEN v = cgetg(5, t_VECSMALL);
     201    11925985 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; return v; }
     202             : INLINE GEN
     203      462026 : mkvecsmall5(long x,long y,long z,long t,long u) { GEN v = cgetg(6, t_VECSMALL);
     204      462026 :   v[1]=x; v[2]=y; v[3]=z; v[4]=t; v[5]=u; return v; }
     205             : 
     206             : INLINE GEN
     207      158123 : mkqfi(GEN x, GEN y, GEN z) { retmkqfi(x,y,z); }
     208             : /* vec */
     209             : INLINE GEN
     210    13915591 : mkvec(GEN x) { retmkvec(x); }
     211             : INLINE GEN
     212    93924272 : mkvec2(GEN x, GEN y) { retmkvec2(x,y); }
     213             : INLINE GEN
     214    59368779 : mkvec3(GEN x, GEN y, GEN z) { retmkvec3(x,y,z); }
     215             : INLINE GEN
     216     7230368 : mkvec4(GEN x, GEN y, GEN z, GEN t) { retmkvec4(x,y,z,t); }
     217             : INLINE GEN
     218    11939799 : mkvec5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkvec5(x,y,z,t,u); }
     219             : INLINE GEN
     220           7 : mkvecs(long x) { retmkvec(stoi(x)); }
     221             : INLINE GEN
     222       19227 : mkvec2s(long x, long y) { retmkvec2(stoi(x),stoi(y)); }
     223             : INLINE GEN
     224      492724 : mkvec3s(long x, long y, long z) { retmkvec3(stoi(x),stoi(y),stoi(z)); }
     225             : INLINE GEN
     226          21 : mkvec4s(long x, long y, long z, long t) { retmkvec4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     227             : INLINE GEN
     228       35042 : mkveccopy(GEN x) { GEN v = cgetg(2, t_VEC); gel(v,1) = gcopy(x); return v; }
     229             : INLINE GEN
     230      107912 : mkvec2copy(GEN x, GEN y) {
     231      107912 :   GEN v = cgetg(3,t_VEC); gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
     232             : /* col */
     233             : INLINE GEN
     234     2398867 : mkcol(GEN x) { retmkcol(x); }
     235             : INLINE GEN
     236    23550602 : mkcol2(GEN x, GEN y) { retmkcol2(x,y); }
     237             : INLINE GEN
     238       42385 : mkcol3(GEN x, GEN y, GEN z) { retmkcol3(x,y,z); }
     239             : INLINE GEN
     240           0 : mkcol4(GEN x, GEN y, GEN z, GEN t) { retmkcol4(x,y,z,t); }
     241             : INLINE GEN
     242           0 : mkcol5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkcol5(x,y,z,t,u); }
     243             : INLINE GEN
     244        8548 : mkcol6(GEN x, GEN y, GEN z, GEN t, GEN u, GEN v) { retmkcol6(x,y,z,t,u,v); }
     245             : INLINE GEN
     246         735 : mkcols(long x) { retmkcol(stoi(x)); }
     247             : INLINE GEN
     248     2147684 : mkcol2s(long x, long y) { retmkcol2(stoi(x),stoi(y)); }
     249             : INLINE GEN
     250           0 : mkcol3s(long x, long y, long z) { retmkcol3(stoi(x),stoi(y),stoi(z)); }
     251             : INLINE GEN
     252           0 : mkcol4s(long x, long y, long z, long t) { retmkcol4(stoi(x),stoi(y),stoi(z),stoi(t)); }
     253             : INLINE GEN
     254       28751 : mkcolcopy(GEN x) { GEN v = cgetg(2, t_COL); gel(v,1) = gcopy(x); return v; }
     255             : /* mat */
     256             : INLINE GEN
     257     2533030 : mkmat(GEN x) { retmkmat(x); }
     258             : INLINE GEN
     259    28793586 : mkmat2(GEN x, GEN y) { retmkmat2(x,y); }
     260             : INLINE GEN
     261        2331 : mkmat3(GEN x, GEN y, GEN z) { retmkmat3(x,y,z); }
     262             : INLINE GEN
     263           0 : mkmat4(GEN x, GEN y, GEN z, GEN t) { retmkmat4(x,y,z,t); }
     264             : INLINE GEN
     265           0 : mkmat5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkmat5(x,y,z,t,u); }
     266             : INLINE GEN
     267       21697 : mkmatcopy(GEN x) { GEN v = cgetg(2, t_MAT); gel(v,1) = gcopy(x); return v; }
     268             : INLINE GEN
     269           0 : mkerr(long x) { GEN v = cgetg(2, t_ERROR); v[1] = x; return v; }
     270             : INLINE GEN
     271       24794 : mkoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_1; return v; }
     272             : INLINE GEN
     273       14469 : mkmoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_m1; return v; }
     274             : INLINE long
     275       49932 : inf_get_sign(GEN x) { return signe(gel(x,1)); }
     276             : INLINE GEN
     277        9317 : mkmat22s(long a, long b, long c, long d) {retmkmat2(mkcol2s(a,c),mkcol2s(b,d));}
     278             : INLINE GEN
     279     1532111 : mkmat22(GEN a, GEN b, GEN c, GEN d) { retmkmat2(mkcol2(a,c),mkcol2(b,d)); }
     280             : 
     281             : /* pol */
     282             : INLINE GEN
     283      918475 : pol_x(long v) {
     284      918475 :   GEN p = cgetg(4, t_POL);
     285      918475 :   p[1] = evalsigne(1)|evalvarn(v);
     286      918475 :   gel(p,2) = gen_0;
     287      918475 :   gel(p,3) = gen_1; return p;
     288             : }
     289             : /* x^n, assume n >= 0 */
     290             : INLINE GEN
     291     2527084 : pol_xn(long n, long v) {
     292     2527084 :   long i, a = n+2;
     293     2527084 :   GEN p = cgetg(a+1, t_POL);
     294     2527084 :   p[1] = evalsigne(1)|evalvarn(v);
     295     2527084 :   for (i = 2; i < a; i++) gel(p,i) = gen_0;
     296     2527084 :   gel(p,a) = gen_1; return p;
     297             : }
     298             : /* x^n, no assumption on n */
     299             : INLINE GEN
     300          42 : pol_xnall(long n, long v)
     301             : {
     302          42 :   if (n < 0) retmkrfrac(gen_1, pol_xn(-n,v));
     303          42 :   return pol_xn(n, v);
     304             : }
     305             : INLINE GEN
     306     1345107 : pol_1(long v) {
     307     1345107 :   GEN p = cgetg(3, t_POL);
     308     1345109 :   p[1] = evalsigne(1)|evalvarn(v);
     309     1345109 :   gel(p,2) = gen_1; return p;
     310             : }
     311             : INLINE GEN
     312    15174138 : pol_0(long v)
     313             : {
     314    15174138 :   GEN x = cgetg(2,t_POL);
     315    15174138 :   x[1] = evalvarn(v); return x;
     316             : }
     317             : #define retconst_vec(n,x)\
     318             :   do { long _i, _n = (n);\
     319             :        GEN _v = cgetg(_n+1, t_VEC), _x = (x);\
     320             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     321             :        return _v; } while(0)
     322             : INLINE GEN
     323     7025719 : const_vec(long n, GEN x) { retconst_vec(n, x); }
     324             : #define retconst_col(n,x)\
     325             :   do { long _i, _n = (n);\
     326             :        GEN _v = cgetg(_n+1, t_COL), _x = (x);\
     327             :        for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
     328             :        return _v; } while(0)
     329             : INLINE GEN
     330     8619813 : const_col(long n, GEN x) { retconst_col(n, x); }
     331             : INLINE GEN
     332     5748081 : const_vecsmall(long n, long c)
     333             : {
     334             :   long i;
     335     5748081 :   GEN V = cgetg(n+1,t_VECSMALL);
     336     5748085 :   for(i=1;i<=n;i++) V[i] = c;
     337     5748085 :   return V;
     338             : }
     339             : 
     340             : /***   ZERO   ***/
     341             : /* O(p^e) */
     342             : INLINE GEN
     343      303713 : zeropadic(GEN p, long e)
     344             : {
     345      303713 :   GEN y = cgetg(5,t_PADIC);
     346      303713 :   gel(y,4) = gen_0;
     347      303713 :   gel(y,3) = gen_1;
     348      303713 :   gel(y,2) = icopy(p);
     349      303713 :   y[1] = evalvalp(e) | _evalprecp(0);
     350      303713 :   return y;
     351             : }
     352             : INLINE GEN
     353         882 : zeropadic_shallow(GEN p, long e)
     354             : {
     355         882 :   GEN y = cgetg(5,t_PADIC);
     356         882 :   gel(y,4) = gen_0;
     357         882 :   gel(y,3) = gen_1;
     358         882 :   gel(y,2) = p;
     359         882 :   y[1] = evalvalp(e) | _evalprecp(0);
     360         882 :   return y;
     361             : }
     362             : /* O(pol_x(v)^e) */
     363             : INLINE GEN
     364      143983 : zeroser(long v, long e)
     365             : {
     366      143983 :   GEN x = cgetg(2, t_SER);
     367      143983 :   x[1] = evalvalp(e) | evalvarn(v); return x;
     368             : }
     369             : INLINE int
     370     4862059 : ser_isexactzero(GEN x)
     371             : {
     372     4862059 :   if (!signe(x)) switch(lg(x))
     373             :   {
     374      136388 :     case 2: return 1;
     375         847 :     case 3: return isexactzero(gel(x,2));
     376             :   }
     377     4724824 :   return 0;
     378             : }
     379             : /* 0 * pol_x(v) */
     380             : INLINE GEN
     381     5385517 : zeropol(long v) { return pol_0(v); }
     382             : /* vector(n) */
     383             : INLINE GEN
     384    24993999 : zerocol(long n)
     385             : {
     386    24993999 :   GEN y = cgetg(n+1,t_COL);
     387    24993999 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     388    24993999 :   return y;
     389             : }
     390             : /* vectorv(n) */
     391             : INLINE GEN
     392    17591611 : zerovec(long n)
     393             : {
     394    17591611 :   GEN y = cgetg(n+1,t_VEC);
     395    17591609 :   long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
     396    17591609 :   return y;
     397             : }
     398             : /* matrix(m, n) */
     399             : INLINE GEN
     400       16562 : zeromat(long m, long n)
     401             : {
     402       16562 :   GEN y = cgetg(n+1,t_MAT);
     403       16562 :   GEN v = zerocol(m);
     404       16562 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     405       16562 :   return y;
     406             : }
     407             : /* = zero_zx, sv is a evalvarn()*/
     408             : INLINE GEN
     409      921768 : zero_Flx(long sv) { return pol0_Flx(sv); }
     410             : INLINE GEN
     411    33173469 : zero_Flv(long n)
     412             : {
     413    33173469 :   GEN y = cgetg(n+1,t_VECSMALL);
     414    33173636 :   long i; for (i=1; i<=n; i++) y[i] = 0;
     415    33173636 :   return y;
     416             : }
     417             : /* matrix(m, n) */
     418             : INLINE GEN
     419      854975 : zero_Flm(long m, long n)
     420             : {
     421      854975 :   GEN y = cgetg(n+1,t_MAT);
     422      854967 :   GEN v = zero_Flv(m);
     423      854979 :   long i; for (i=1; i<=n; i++) gel(y,i) = v;
     424      854979 :   return y;
     425             : }
     426             : /* matrix(m, n) */
     427             : INLINE GEN
     428      103665 : zero_Flm_copy(long m, long n)
     429             : {
     430      103665 :   GEN y = cgetg(n+1,t_MAT);
     431      103672 :   long i; for (i=1; i<=n; i++) gel(y,i) = zero_Flv(m);
     432      103673 :   return y;
     433             : }
     434             : 
     435             : INLINE GEN
     436      808964 : zero_F2v(long m)
     437             : {
     438      808964 :   long l = nbits2nlong(m);
     439      808964 :   GEN v  = zero_Flv(l+1);
     440      808963 :   v[1] = m;
     441      808963 :   return v;
     442             : }
     443             : 
     444             : INLINE GEN
     445           0 : zero_F2m(long m, long n)
     446             : {
     447             :   long i;
     448           0 :   GEN M = cgetg(n+1, t_MAT);
     449           0 :   GEN v = zero_F2v(m);
     450           0 :   for (i = 1; i <= n; i++)
     451           0 :     gel(M,i) = v;
     452           0 :   return M;
     453             : }
     454             : 
     455             : 
     456             : INLINE GEN
     457      273153 : zero_F2m_copy(long m, long n)
     458             : {
     459             :   long i;
     460      273153 :   GEN M = cgetg(n+1, t_MAT);
     461      833195 :   for (i = 1; i <= n; i++)
     462      560043 :     gel(M,i)= zero_F2v(m);
     463      273152 :   return M;
     464             : }
     465             : 
     466             : /* matrix(m, n) */
     467             : INLINE GEN
     468     2268011 : zeromatcopy(long m, long n)
     469             : {
     470     2268011 :   GEN y = cgetg(n+1,t_MAT);
     471     2268011 :   long i; for (i=1; i<=n; i++) gel(y,i) = zerocol(m);
     472     2268011 :   return y;
     473             : }
     474             : 
     475             : INLINE GEN
     476       17584 : zerovec_block(long len)
     477             : {
     478             :   long i;
     479       17584 :   GEN blk = cgetg_block(len + 1, t_VEC);
     480      580272 :   for (i = 1; i <= len; ++i)
     481      562688 :     gel(blk, i) = gen_0;
     482       17584 :   return blk;
     483             : }
     484             : 
     485             : /* i-th vector in the standard basis */
     486             : INLINE GEN
     487     1317141 : col_ei(long n, long i) { GEN e = zerocol(n); gel(e,i) = gen_1; return e; }
     488             : INLINE GEN
     489      324745 : vec_ei(long n, long i) { GEN e = zerovec(n); gel(e,i) = gen_1; return e; }
     490             : INLINE GEN
     491          42 : F2v_ei(long n, long i) { GEN e = zero_F2v(n); F2v_set(e,i); return e; }
     492             : INLINE GEN
     493       70925 : vecsmall_ei(long n, long i) { GEN e = zero_zv(n); e[i] = 1; return e; }
     494             : INLINE GEN
     495      396620 : Rg_col_ei(GEN x, long n, long i) { GEN e = zerocol(n); gel(e,i) = x; return e; }
     496             : 
     497             : INLINE GEN
     498    11139623 : shallowcopy(GEN x)
     499    11139623 : { return typ(x) == t_MAT ? RgM_shallowcopy(x): leafcopy(x); }
     500             : 
     501             : /* routines for naive growarrays */
     502             : INLINE GEN
     503    12655882 : vectrunc_init(long l)
     504             : {
     505    12655882 :   GEN z = new_chunk(l);
     506    12656300 :   z[0] = evaltyp(t_VEC) | _evallg(1); return z;
     507             : }
     508             : INLINE void
     509   252960149 : lg_increase(GEN x) { x[0]++; }
     510             : INLINE void
     511    50947625 : vectrunc_append(GEN x, GEN t) { gel(x, lg(x)) = t; lg_increase(x); }
     512             : INLINE void
     513       10416 : vectrunc_append_batch(GEN x, GEN y)
     514             : {
     515       10416 :   long i, l = lg(x), ly = lg(y);
     516       10416 :   GEN z = x + l-1;
     517       10416 :   for (i = 1; i < ly; i++) gel(z,i) = gel(y,i);
     518       10416 :   setlg(x, l+ly-1);
     519       10416 : }
     520             : INLINE GEN
     521    82733458 : vecsmalltrunc_init(long l)
     522             : {
     523    82733458 :   GEN z = new_chunk(l);
     524    82733458 :   z[0] = evaltyp(t_VECSMALL) | _evallg(1); return z;
     525             : }
     526             : INLINE void
     527    33024695 : vecsmalltrunc_append(GEN x, long t) { x[ lg(x) ] = t; lg_increase(x); }
     528             : 
     529             : /*******************************************************************/
     530             : /*                                                                 */
     531             : /*                        VEC / COL / VECSMALL                     */
     532             : /*                                                                 */
     533             : /*******************************************************************/
     534             : /* shallow*/
     535             : INLINE GEN
     536           0 : vec_shorten(GEN v, long n)
     537             : {
     538             :   long i;
     539           0 :   GEN V = cgetg(n+1,t_VEC);
     540           0 :   for(i=1;i<=n;i++) gel(V,i) = gel(v,i);
     541           0 :   return V;
     542             : }
     543             : /* shallow*/
     544             : INLINE GEN
     545       13328 : vec_lengthen(GEN v, long n)
     546             : {
     547             :   long i;
     548       13328 :   long l=lg(v);
     549       13328 :   GEN V = cgetg(n+1,t_VEC);
     550       13328 :   for(i=1;i<l;i++) gel(V,i) = gel(v,i);
     551       13328 :   return V;
     552             : }
     553             : /* shallow*/
     554             : INLINE GEN
     555       61089 : vec_append(GEN V, GEN s)
     556             : {
     557       61089 :   long i, l2 = lg(V);
     558       61089 :   GEN res = cgetg(l2+1, typ(V));
     559       61089 :   for (i = 1; i < l2; ++i) gel(res, i) = gel(V,i);
     560       61089 :   gel(res,l2) = s; return res;
     561             : }
     562             : /* shallow*/
     563             : INLINE GEN
     564        1785 : vec_prepend(GEN v, GEN s)
     565             : {
     566        1785 :   long i, l = lg(v);
     567        1785 :   GEN w = cgetg(l+1, typ(v));
     568        1785 :   gel(w,1) = s;
     569        1785 :   for (i = 2; i <= l; ++i) gel(w,i) = gel(v,i-1);
     570        1785 :   return w;
     571             : }
     572             : /* shallow*/
     573             : INLINE GEN
     574           0 : vec_setconst(GEN v, GEN x)
     575             : {
     576           0 :   long i, l = lg(v);
     577           0 :   for (i = 1; i < l; i++) gel(v,i) = x;
     578           0 :   return v;
     579             : }
     580             : INLINE GEN
     581      718634 : vecsmall_shorten(GEN v, long n)
     582             : {
     583             :   long i;
     584      718634 :   GEN V = cgetg(n+1,t_VECSMALL);
     585      718636 :   for(i=1;i<=n;i++) V[i] = v[i];
     586      718636 :   return V;
     587             : }
     588             : INLINE GEN
     589          21 : vecsmall_lengthen(GEN v, long n)
     590             : {
     591          21 :   long i, l = lg(v);
     592          21 :   GEN V = cgetg(n+1,t_VECSMALL);
     593          21 :   for(i=1;i<l;i++) V[i] = v[i];
     594          21 :   return V;
     595             : }
     596             : 
     597             : INLINE GEN
     598      453591 : vec_to_vecsmall(GEN x)
     599      453591 : { pari_APPLY_long(itos(gel(x,i))) }
     600             : INLINE GEN
     601      412302 : vecsmall_to_vec(GEN x)
     602      412302 : { pari_APPLY_type(t_VEC, stoi(x[i])) }
     603             : INLINE GEN
     604        1561 : vecsmall_to_vec_inplace(GEN z)
     605             : {
     606        1561 :   long i, l = lg(z);
     607        1561 :   for (i=1; i<l; i++) gel(z,i) = stoi(z[i]);
     608        1561 :   settyp(z, t_VEC); return z;
     609             : }
     610             : INLINE GEN
     611     4947138 : vecsmall_to_col(GEN x)
     612     4947138 : { pari_APPLY_type(t_COL, stoi(x[i])) }
     613             : 
     614             : INLINE int
     615     7943272 : vecsmall_lexcmp(GEN x, GEN y)
     616             : {
     617             :   long lx,ly,l,i;
     618     7943272 :   lx = lg(x);
     619     7943272 :   ly = lg(y); l = minss(lx,ly);
     620    38512497 :   for (i=1; i<l; i++)
     621    36607641 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     622     1904856 :   if (lx == ly) return 0;
     623          14 :   return (lx < ly)? -1 : 1;
     624             : }
     625             : 
     626             : INLINE int
     627    85155511 : vecsmall_prefixcmp(GEN x, GEN y)
     628             : {
     629    85155511 :   long i, lx = lg(x), ly = lg(y), l = minss(lx,ly);
     630   394027655 :   for (i=1; i<l; i++)
     631   374395014 :     if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
     632    19632641 :   return 0;
     633             : }
     634             : 
     635             : /*Can be used on t_VEC, but coeffs not gcopy-ed*/
     636             : INLINE GEN
     637       14113 : vecsmall_prepend(GEN V, long s)
     638             : {
     639       14113 :   long i, l2 = lg(V);
     640       14113 :   GEN res = cgetg(l2+1, typ(V));
     641       14113 :   res[1] = s;
     642       14113 :   for (i = 2; i <= l2; ++i) res[i] = V[i - 1];
     643       14113 :   return res;
     644             : }
     645             : 
     646             : INLINE GEN
     647     2541329 : vecsmall_append(GEN V, long s)
     648             : {
     649     2541329 :   long i, l2 = lg(V);
     650     2541329 :   GEN res = cgetg(l2+1, t_VECSMALL);
     651     2541329 :   for (i = 1; i < l2; ++i) res[i] = V[i];
     652     2541329 :   res[l2] = s; return res;
     653             : }
     654             : 
     655             : INLINE GEN
     656      765775 : vecsmall_concat(GEN u, GEN v)
     657             : {
     658      765775 :   long i, l1 = lg(u)-1, l2 = lg(v)-1;
     659      765775 :   GEN res = cgetg(l1+l2+1, t_VECSMALL);
     660      765776 :   for (i = 1; i <= l1; ++i) res[i]    = u[i];
     661      765776 :   for (i = 1; i <= l2; ++i) res[i+l1] = v[i];
     662      765776 :   return res;
     663             : }
     664             : 
     665             : /* return the number of indices where u and v are equal */
     666             : INLINE long
     667           0 : vecsmall_coincidence(GEN u, GEN v)
     668             : {
     669           0 :   long i, s = 0, l = minss(lg(u),lg(v));
     670           0 :   for(i=1; i<l; i++)
     671           0 :     if(u[i] == v[i]) s++;
     672           0 :   return s;
     673             : }
     674             : 
     675             : /* returns the first index i<=n such that x=v[i] if it exists, 0 otherwise */
     676             : INLINE long
     677           0 : vecsmall_isin(GEN v, long x)
     678             : {
     679           0 :   long i, l = lg(v);
     680           0 :   for (i = 1; i < l; i++)
     681           0 :     if (v[i] == x) return i;
     682           0 :   return 0;
     683             : }
     684             : 
     685             : INLINE long
     686          84 : vecsmall_pack(GEN V, long base, long mod)
     687             : {
     688          84 :   long i, s = 0;
     689          84 :   for(i=1; i<lg(V); i++) s = (base*s + V[i]) % mod;
     690          84 :   return s;
     691             : }
     692             : 
     693             : INLINE long
     694          14 : vecsmall_indexmax(GEN x)
     695             : {
     696          14 :   long i, i0 = 1, t = x[1], lx = lg(x);
     697          56 :   for (i=2; i<lx; i++)
     698          42 :     if (x[i] > t) t = x[i0=i];
     699          14 :   return i0;
     700             : }
     701             : 
     702             : INLINE long
     703      135213 : vecsmall_max(GEN x)
     704             : {
     705      135213 :   long i, t = x[1], lx = lg(x);
     706      523696 :   for (i=2; i<lx; i++)
     707      388483 :     if (x[i] > t) t = x[i];
     708      135213 :   return t;
     709             : }
     710             : 
     711             : INLINE long
     712          14 : vecsmall_indexmin(GEN x)
     713             : {
     714          14 :   long i, i0 = 1, t = x[1], lx =lg(x);
     715          56 :   for (i=2; i<lx; i++)
     716          42 :     if (x[i] < t) t = x[i0=i];
     717          14 :   return i0;
     718             : }
     719             : 
     720             : INLINE long
     721           0 : vecsmall_min(GEN x)
     722             : {
     723           0 :   long i, t = x[1], lx =lg(x);
     724           0 :   for (i=2; i<lx; i++)
     725           0 :     if (x[i] < t) t = x[i];
     726           0 :   return t;
     727             : }
     728             : 
     729             : INLINE int
     730     2163762 : ZV_isscalar(GEN x)
     731             : {
     732     2163762 :   long l = lg(x);
     733     7890486 :   while (--l > 1)
     734     5331770 :     if (signe(gel(x, l))) return 0;
     735      394954 :   return 1;
     736             : }
     737             : INLINE int
     738    17441352 : QV_isscalar(GEN x)
     739             : {
     740    17441352 :   long lx = lg(x),i;
     741    18920046 :   for (i=2; i<lx; i++)
     742    18391537 :     if (!isintzero(gel(x, i))) return 0;
     743      528509 :   return 1;
     744             : }
     745             : INLINE int
     746        3840 : RgV_isscalar(GEN x)
     747             : {
     748        3840 :   long lx = lg(x),i;
     749        7235 :   for (i=2; i<lx; i++)
     750        6153 :     if (!gequal0(gel(x, i))) return 0;
     751        1082 :   return 1;
     752             : }
     753             : INLINE int
     754           0 : RgX_isscalar(GEN x)
     755             : {
     756             :   long i;
     757           0 :   for (i=lg(x)-1; i>2; i--)
     758           0 :     if (!gequal0(gel(x, i))) return 0;
     759           0 :   return 1;
     760             : }
     761             : INLINE long
     762     3845082 : RgX_equal_var(GEN x, GEN y) { return varn(x) == varn(y) && RgX_equal(x,y); }
     763             : 
     764             : INLINE int
     765        5538 : RgX_is_rational(GEN x)
     766             : {
     767             :   long i;
     768       27699 :   for (i = lg(x)-1; i > 1; i--)
     769       25843 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     770        1856 :   return 1;
     771             : }
     772             : INLINE int
     773     3984433 : RgX_is_ZX(GEN x)
     774             : {
     775             :   long i;
     776    17239968 :   for (i = lg(x)-1; i > 1; i--)
     777    13271257 :     if (typ(gel(x,i)) != t_INT) return 0;
     778     3968711 :   return 1;
     779             : }
     780             : INLINE int
     781      116641 : RgX_is_QX(GEN x)
     782             : {
     783      116641 :   long k = lg(x)-1;
     784      443205 :   for ( ; k>1; k--)
     785      327516 :     if (!is_rational_t(typ(gel(x,k)))) return 0;
     786      115689 :   return 1;
     787             : }
     788             : INLINE int
     789    15568647 : RgX_is_monomial(GEN x)
     790             : {
     791             :   long i;
     792    15568647 :   if (!signe(x)) return 0;
     793    25756463 :   for (i=lg(x)-2; i>1; i--)
     794    17783411 :     if (!isexactzero(gel(x,i))) return 0;
     795     7973052 :   return 1;
     796             : }
     797             : INLINE int
     798    26934631 : RgV_is_ZV(GEN x)
     799             : {
     800             :   long i;
     801   111000717 :   for (i = lg(x)-1; i > 0; i--)
     802    84067255 :     if (typ(gel(x,i)) != t_INT) return 0;
     803    26933462 :   return 1;
     804             : }
     805             : INLINE int
     806         791 : RgV_is_QV(GEN x)
     807             : {
     808             :   long i;
     809        1197 :   for (i = lg(x)-1; i > 0; i--)
     810        1064 :     if (!is_rational_t(typ(gel(x,i)))) return 0;
     811         133 :   return 1;
     812             : }
     813             : 
     814             : /********************************************************************/
     815             : /**                                                                **/
     816             : /**            Dynamic arrays implementation                       **/
     817             : /**                                                                **/
     818             : /********************************************************************/
     819             : INLINE void **
     820   441141235 : pari_stack_base(pari_stack *s) { return s->data; }
     821             : 
     822             : INLINE void
     823     1348551 : pari_stack_init(pari_stack *s, size_t size, void **data)
     824             : {
     825     1348551 :   s->data = data;
     826     1348551 :   *data = NULL;
     827     1348551 :   s->n = 0;
     828     1348551 :   s->alloc = 0;
     829     1348551 :   s->size = size;
     830     1348551 : }
     831             : 
     832             : INLINE void
     833   439866584 : pari_stack_alloc(pari_stack *s, long nb)
     834             : {
     835   439866584 :   void **sdat = pari_stack_base(s);
     836   440022026 :   long alloc = s->alloc;
     837   880046137 :   if (s->n+nb <= alloc) return;
     838      515922 :   if (!alloc)
     839      464656 :     alloc = nb;
     840             :   else
     841             :   {
     842       51266 :     while (s->n+nb > alloc) alloc <<= 1;
     843             :   }
     844      515922 :   *sdat = pari_realloc(*sdat,alloc*s->size);
     845      518007 :   s->alloc = alloc;
     846             : }
     847             : 
     848             : INLINE long
     849   362078282 : pari_stack_new(pari_stack *s) { pari_stack_alloc(s, 1); return s->n++; }
     850             : 
     851             : INLINE void
     852     1179852 : pari_stack_delete(pari_stack *s)
     853             : {
     854     1179852 :   void **sdat = pari_stack_base(s);
     855     1179753 :   if (*sdat) pari_free(*sdat);
     856     1179865 : }
     857             : 
     858             : INLINE void
     859        4860 : pari_stack_pushp(pari_stack *s, void *u)
     860             : {
     861        4860 :   long n = pari_stack_new(s);
     862        4860 :   void **sdat =(void**) *pari_stack_base(s);
     863        4860 :   sdat[n] = u;
     864        4860 : }
     865             : 
     866             : /*******************************************************************/
     867             : /*                                                                 */
     868             : /*                            EXTRACT                              */
     869             : /*                                                                 */
     870             : /*******************************************************************/
     871             : INLINE GEN
     872   182549900 : vecslice(GEN A, long y1, long y2)
     873             : {
     874   182549900 :   long i,lB = y2 - y1 + 2;
     875   182549900 :   GEN B = cgetg(lB, typ(A));
     876   182556484 :   for (i=1; i<lB; i++) B[i] = A[y1-1+i];
     877   182556484 :   return B;
     878             : }
     879             : INLINE GEN
     880      755503 : vecslicepermute(GEN A, GEN p, long y1, long y2)
     881             : {
     882      755503 :   long i,lB = y2 - y1 + 2;
     883      755503 :   GEN B = cgetg(lB, typ(A));
     884      755502 :   for (i=1; i<lB; i++) B[i] = A[p[y1-1+i]];
     885      755502 :   return B;
     886             : }
     887             : /* rowslice(rowpermute(A,p), x1, x2) */
     888             : INLINE GEN
     889       35166 : rowslicepermute(GEN x, GEN p, long j1, long j2)
     890       35166 : { pari_APPLY_same(vecslicepermute(gel(x,i),p,j1,j2)) }
     891             : 
     892             : INLINE GEN
     893    20967759 : rowslice(GEN x, long j1, long j2)
     894    20967759 : { pari_APPLY_same(vecslice(gel(x,i), j1, j2)) }
     895             : 
     896             : INLINE GEN
     897     3427663 : matslice(GEN A, long x1, long x2, long y1, long y2)
     898     3427663 : { return rowslice(vecslice(A, y1, y2), x1, x2); }
     899             : 
     900             : /* shallow, remove coeff of index j */
     901             : INLINE GEN
     902         133 : rowsplice(GEN x, long j)
     903         133 : { pari_APPLY_same(vecsplice(gel(x,i), j)) }
     904             : 
     905             : /* shallow, remove coeff of index j */
     906             : INLINE GEN
     907      251566 : vecsplice(GEN a, long j)
     908             : {
     909      251566 :   long i, k, l = lg(a);
     910             :   GEN b;
     911      251566 :   if (l == 1) pari_err(e_MISC, "incorrect component in vecsplice");
     912      251566 :   b = cgetg(l-1, typ(a));
     913     1002407 :   for (i = k = 1; i < l; i++)
     914      750841 :     if (i != j) gel(b, k++) = gel(a,i);
     915      251566 :   return b;
     916             : }
     917             : /* shallow */
     918             : INLINE GEN
     919         637 : RgM_minor(GEN a, long i, long j)
     920             : {
     921         637 :   GEN b = vecsplice(a, j);
     922         637 :   long k, l = lg(b);
     923         637 :   for (k = 1; k < l; k++) gel(b,k) = vecsplice(gel(b,k), i);
     924         637 :   return b;
     925             : }
     926             : 
     927             : /* A[x0,] */
     928             : INLINE GEN
     929      383940 : row(GEN x, long j)
     930      383940 : { pari_APPLY_type(t_VEC, gcoeff(x, j, i)) }
     931             : INLINE GEN
     932     3106154 : Flm_row(GEN x, long j)
     933     3106154 : { pari_APPLY_ulong((ulong)coeff(x, j, i)) }
     934             : /* A[x0,] */
     935             : INLINE GEN
     936      204820 : rowcopy(GEN x, long j)
     937      204820 : { pari_APPLY_type(t_VEC, gcopy(gcoeff(x, j, i))) }
     938             : /* A[x0, x1..x2] */
     939             : INLINE GEN
     940        2177 : row_i(GEN A, long x0, long x1, long x2)
     941             : {
     942        2177 :   long i, lB = x2 - x1 + 2;
     943        2177 :   GEN B  = cgetg(lB, t_VEC);
     944        2177 :   for (i=x1; i<=x2; i++) gel(B, i) = gcoeff(A, x0, i);
     945        2177 :   return B;
     946             : }
     947             : 
     948             : INLINE GEN
     949     5787860 : vecreverse(GEN A)
     950             : {
     951             :   long i, l;
     952     5787860 :   GEN B = cgetg_copy(A, &l);
     953     5787860 :   for (i=1; i<l; i++) gel(B, i) = gel(A, l-i);
     954     5787860 :   return B;
     955             : }
     956             : 
     957             : INLINE GEN
     958         252 : vecsmall_reverse(GEN A)
     959             : {
     960             :   long i, l;
     961         252 :   GEN B = cgetg_copy(A, &l);
     962         252 :   for (i=1; i<l; i++) B[i] = A[l-i];
     963         252 :   return B;
     964             : }
     965             : 
     966             : INLINE void
     967         260 : vecreverse_inplace(GEN y)
     968             : {
     969         260 :   long l = lg(y), lim = l>>1, i;
     970         724 :   for (i = 1; i <= lim; i++)
     971             :   {
     972         464 :     GEN z = gel(y,i);
     973         464 :     gel(y,i)    = gel(y,l-i);
     974         464 :     gel(y,l-i) = z;
     975             :   }
     976         260 : }
     977             : 
     978             : INLINE GEN
     979    43344625 : vecsmallpermute(GEN A, GEN p) { return perm_mul(A, p); }
     980             : 
     981             : INLINE GEN
     982     5698255 : vecpermute(GEN A, GEN x)
     983     5698255 : { pari_APPLY_type(typ(A), gel(A, x[i])) }
     984             : 
     985             : INLINE GEN
     986     2843762 : rowpermute(GEN x, GEN p)
     987     2843762 : { pari_APPLY_same(typ(gel(x,i)) == t_VECSMALL ? vecsmallpermute(gel(x, i), p)
     988             :                                               : vecpermute(gel(x, i), p))
     989             : }
     990             : /*******************************************************************/
     991             : /*                                                                 */
     992             : /*                          PERMUTATIONS                           */
     993             : /*                                                                 */
     994             : /*******************************************************************/
     995             : /* identity permutation */
     996             : INLINE GEN
     997      684962 : identity_perm(long n)
     998             : {
     999      684962 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1000             :   long i;
    1001      684960 :   for (i = 1; i <= n; i++) perm[i] = i;
    1002      684960 :   return perm;
    1003             : }
    1004             : 
    1005             : /* assume d <= n */
    1006             : INLINE GEN
    1007       98399 : cyclic_perm(long n, long d)
    1008             : {
    1009       98399 :   GEN perm = cgetg(n+1, t_VECSMALL);
    1010             :   long i;
    1011       98399 :   for (i = 1; i <= n-d; i++) perm[i] = i+d;
    1012       98399 :   for (     ; i <= n;   i++) perm[i] = i-n+d;
    1013       98399 :   return perm;
    1014             : }
    1015             : 
    1016             : /* Multiply (compose) two permutations */
    1017             : INLINE GEN
    1018    44559217 : perm_mul(GEN s, GEN x)
    1019    44559217 : { pari_APPLY_long(s[x[i]]) }
    1020             : 
    1021             : /* Compute the inverse (reciprocal) of a permutation. */
    1022             : INLINE GEN
    1023     1135577 : perm_inv(GEN x)
    1024             : {
    1025             :   long i, lx;
    1026     1135577 :   GEN y = cgetg_copy(x, &lx);
    1027     1135577 :   for (i=1; i<lx; i++) y[ x[i] ] = i;
    1028     1135577 :   return y;
    1029             : }
    1030             : /* Return s*t*s^-1 */
    1031             : INLINE GEN
    1032      402990 : perm_conj(GEN s, GEN t)
    1033             : {
    1034             :   long i, l;
    1035      402990 :   GEN v = cgetg_copy(s, &l);
    1036      402990 :   for (i = 1; i < l; i++) v[ s[i] ] = s[ t[i] ];
    1037      402990 :   return v;
    1038             : }
    1039             : 
    1040             : /*********************************************************************/
    1041             : /*                       MALLOC/FREE WRAPPERS                        */
    1042             : /*********************************************************************/
    1043             : #define BLOCK_SIGALRM_START          \
    1044             : {                                    \
    1045             :   int block=PARI_SIGINT_block;       \
    1046             :   PARI_SIGINT_block = 2;             \
    1047             :   MT_SIGINT_BLOCK(block);
    1048             : 
    1049             : #define BLOCK_SIGINT_START           \
    1050             : {                                    \
    1051             :   int block=PARI_SIGINT_block;       \
    1052             :   PARI_SIGINT_block = 1;             \
    1053             :   MT_SIGINT_BLOCK(block);
    1054             : 
    1055             : #define BLOCK_SIGINT_END             \
    1056             :   PARI_SIGINT_block = block;         \
    1057             :   MT_SIGINT_UNBLOCK(block);          \
    1058             :   if (!block && PARI_SIGINT_pending) \
    1059             :   {                                  \
    1060             :     int sig = PARI_SIGINT_pending;   \
    1061             :     PARI_SIGINT_pending = 0;         \
    1062             :     raise(sig);                      \
    1063             :   }                                  \
    1064             : }
    1065             : 
    1066             : INLINE void
    1067    63080959 : pari_free(void *pointer)
    1068             : {
    1069    63080959 :   BLOCK_SIGINT_START;
    1070    63082045 :   free(pointer);
    1071    63082045 :   BLOCK_SIGINT_END;
    1072    63081598 : }
    1073             : INLINE void*
    1074   275173281 : pari_malloc(size_t size)
    1075             : {
    1076   275173281 :   if (size)
    1077             :   {
    1078             :     char *tmp;
    1079   275173281 :     BLOCK_SIGINT_START;
    1080   275177872 :     tmp = (char*)malloc(size);
    1081   275177872 :     BLOCK_SIGINT_END;
    1082   275177536 :     if (!tmp) pari_err(e_MEM);
    1083   275177536 :     return tmp;
    1084             :   }
    1085           0 :   return NULL;
    1086             : }
    1087             : INLINE void*
    1088      528571 : pari_realloc(void *pointer, size_t size)
    1089             : {
    1090             :   char *tmp;
    1091             : 
    1092      528571 :   BLOCK_SIGINT_START;
    1093      530731 :   if (!pointer) tmp = (char *) malloc(size);
    1094       55019 :   else tmp = (char *) realloc(pointer,size);
    1095      530731 :   BLOCK_SIGINT_END;
    1096      529952 :   if (!tmp) pari_err(e_MEM);
    1097      529952 :   return tmp;
    1098             : }
    1099             : INLINE void*
    1100       35058 : pari_calloc(size_t size)
    1101             : {
    1102       35058 :   void *t = pari_malloc(size);
    1103       35058 :   memset(t, 0, size); return t;
    1104             : }
    1105             : INLINE GEN
    1106        5813 : cgetalloc(long t, size_t l)
    1107             : {
    1108        5813 :   GEN x = (GEN)pari_malloc(l * sizeof(long));
    1109        5813 :   x[0] = evaltyp(t) | evallg(l); return x;
    1110             : }
    1111             : 
    1112             : /*******************************************************************/
    1113             : /*                                                                 */
    1114             : /*                       GARBAGE COLLECTION                        */
    1115             : /*                                                                 */
    1116             : /*******************************************************************/
    1117             : /* copy integer x as if we had avma = av */
    1118             : INLINE GEN
    1119  3663777354 : icopy_avma(GEN x, pari_sp av)
    1120             : {
    1121  3663777354 :   long i = lgefint(x), lx = i;
    1122  3663777354 :   GEN y = ((GEN)av) - i;
    1123  3663777354 :   while (--i > 0) y[i] = x[i];
    1124  3663777354 :   y[0] = evaltyp(t_INT)|evallg(lx);
    1125  3663500541 :   return y;
    1126             : }
    1127             : /* copy leaf x as if we had avma = av */
    1128             : INLINE GEN
    1129   164103602 : leafcopy_avma(GEN x, pari_sp av)
    1130             : {
    1131   164103602 :   long i = lg(x);
    1132   164103602 :   GEN y = ((GEN)av) - i;
    1133   164103602 :   while (--i > 0) y[i] = x[i];
    1134   164103602 :   y[0] = x[0] & (~CLONEBIT);
    1135   164103602 :   return y;
    1136             : }
    1137             : INLINE GEN
    1138   596164708 : gerepileuptoleaf(pari_sp av, GEN x)
    1139             : {
    1140             :   long lx;
    1141             :   GEN q;
    1142             : 
    1143   596164708 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1144   596987596 :   lx = lg(x);
    1145   596987596 :   q = ((GEN)av) - lx;
    1146   596987596 :   avma = (pari_sp)q;
    1147   596987596 :   while (--lx >= 0) q[lx] = x[lx];
    1148   596987596 :   return q;
    1149             : }
    1150             : INLINE GEN
    1151  1161597088 : gerepileuptoint(pari_sp av, GEN x)
    1152             : {
    1153  1161597088 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1154  1030542263 :   avma = (pari_sp)icopy_avma(x, av);
    1155  1031281730 :   return (GEN)avma;
    1156             : }
    1157             : INLINE GEN
    1158   735349673 : gerepileupto(pari_sp av, GEN x)
    1159             : {
    1160   735349673 :   if (!isonstack(x) || (GEN)av<=x) { avma = av; return x; }
    1161   643306062 :   switch(typ(x))
    1162             :   { /* non-default = !is_recursive_t(tq) */
    1163   217835985 :     case t_INT: return gerepileuptoint(av, x);
    1164             :     case t_REAL:
    1165             :     case t_STR:
    1166   133840594 :     case t_VECSMALL: return gerepileuptoleaf(av,x);
    1167             :     default:
    1168             :       /* NB: x+i --> ((long)x) + i*sizeof(long) */
    1169   291629483 :       return gerepile(av, (pari_sp) (x+lg(x)), x);
    1170             :   }
    1171             : }
    1172             : 
    1173             : /* gerepileupto(av, gcopy(x)) */
    1174             : INLINE GEN
    1175    44063224 : gerepilecopy(pari_sp av, GEN x)
    1176             : {
    1177    44063224 :   if (is_recursive_t(typ(x)))
    1178             :   {
    1179    39686809 :     GENbin *p = copy_bin(x);
    1180    39686827 :     avma = av; return bin_copy(p);
    1181             :   }
    1182             :   else
    1183             :   {
    1184     4376416 :     avma = av;
    1185     4376416 :     if (x < (GEN)av) {
    1186     2897113 :       if (x < (GEN)pari_mainstack->bot) new_chunk(lg(x));
    1187     2897113 :       x = leafcopy_avma(x, av);
    1188     2897125 :       avma = (pari_sp)x;
    1189             :     } else
    1190     1479303 :       x = leafcopy(x);
    1191     4376430 :     return x;
    1192             :   }
    1193             : }
    1194             : 
    1195             : /* Takes an array of pointers to GENs, of length n. Copies all
    1196             :  * objects to contiguous locations and cleans up the stack between
    1197             :  * av and avma. */
    1198             : INLINE void
    1199      134465 : gerepilemany(pari_sp av, GEN* gptr[], int n)
    1200             : {
    1201             :   int i;
    1202      134465 :   for (i=0; i<n; i++) *gptr[i] = (GEN)copy_bin(*gptr[i]);
    1203      134465 :   avma = av;
    1204      134465 :   for (i=0; i<n; i++) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1205      134465 : }
    1206             : 
    1207             : INLINE void
    1208     7634057 : gerepileall(pari_sp av, int n, ...)
    1209             : {
    1210             :   int i;
    1211     7634057 :   va_list a; va_start(a, n);
    1212     7634057 :   if (n < 10)
    1213             :   {
    1214             :     GEN *gptr[10];
    1215    22085835 :     for (i=0; i<n; i++)
    1216    14451787 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1217     7634048 :     avma = av;
    1218     7634048 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1219             : 
    1220             :   }
    1221             :   else
    1222             :   {
    1223           0 :     GEN **gptr = (GEN**)  pari_malloc(n*sizeof(GEN*));
    1224           0 :     for (i=0; i<n; i++)
    1225           0 :     { gptr[i] = va_arg(a,GEN*); *gptr[i] = (GEN)copy_bin(*gptr[i]); }
    1226           0 :     avma = av;
    1227           0 :     for (--i; i>=0; i--) *gptr[i] = bin_copy((GENbin*)*gptr[i]);
    1228           0 :     pari_free(gptr);
    1229             :   }
    1230     7634007 :   va_end(a);
    1231     7634007 : }
    1232             : 
    1233             : INLINE void
    1234          14 : gerepilecoeffs(pari_sp av, GEN x, int n)
    1235             : {
    1236             :   int i;
    1237          14 :   for (i=0; i<n; i++) gel(x,i) = (GEN)copy_bin(gel(x,i));
    1238          14 :   avma = av;
    1239          14 :   for (i=0; i<n; i++) gel(x,i) = bin_copy((GENbin*)x[i]);
    1240          14 : }
    1241             : 
    1242             : /* p from copy_bin. Copy p->x back to stack, then destroy p */
    1243             : INLINE GEN
    1244    54559999 : bin_copy(GENbin *p)
    1245             : {
    1246             :   GEN x, y, base;
    1247             :   long dx, len;
    1248             : 
    1249    54559999 :   x   = p->x; if (!x) { pari_free(p); return gen_0; }
    1250    54552913 :   len = p->len;
    1251    54552913 :   base= p->base; dx = x - base;
    1252    54552913 :   y = (GEN)memcpy((void*)new_chunk(len), (void*)GENbinbase(p), len*sizeof(long));
    1253    54552857 :   y += dx;
    1254    54552857 :   p->rebase(y, ((ulong)y-(ulong)x));
    1255    54552852 :   pari_free(p); return y;
    1256             : }
    1257             : 
    1258             : INLINE GEN
    1259   109112979 : GENbinbase(GENbin *p) { return (GEN)(p + 1); }
    1260             : 
    1261             : INLINE void
    1262    27089294 : cgiv(GEN x)
    1263             : {
    1264    27089294 :   pari_sp av = (pari_sp)(x+lg(x));
    1265    27089294 :   if (isonstack((GEN)av)) avma = av;
    1266    27089252 : }
    1267             : 
    1268             : INLINE void
    1269     1208341 : killblock(GEN x) { gunclone(x); }
    1270             : 
    1271             : INLINE int
    1272    24215578 : is_universal_constant(GEN x) { return (x >= gen_0 && x <= ghalf); }
    1273             : 
    1274             : /*******************************************************************/
    1275             : /*                                                                 */
    1276             : /*                    CONVERSION / ASSIGNMENT                      */
    1277             : /*                                                                 */
    1278             : /*******************************************************************/
    1279             : /* z is a type which may be a t_COMPLEX component (not a t_QUAD) */
    1280             : INLINE GEN
    1281     3130326 : cxcompotor(GEN z, long prec)
    1282             : {
    1283     3130326 :   switch(typ(z))
    1284             :   {
    1285     1771422 :     case t_INT:  return itor(z, prec);
    1286      134134 :     case t_FRAC: return fractor(z, prec);
    1287     1224770 :     case t_REAL: return rtor(z, prec);
    1288           0 :     default: pari_err_TYPE("cxcompotor",z);
    1289             :              return NULL; /* LCOV_EXCL_LINE */
    1290             :   }
    1291             : }
    1292             : INLINE GEN
    1293     1551861 : cxtofp(GEN x, long prec)
    1294     1551861 : { retmkcomplex(cxcompotor(gel(x,1),prec), cxcompotor(gel(x,2),prec)); }
    1295             : 
    1296             : INLINE double
    1297    19026990 : gtodouble(GEN x)
    1298             : {
    1299    19026990 :   if (typ(x)!=t_REAL) {
    1300     3538364 :     pari_sp av = avma;
    1301     3538364 :     x = gtofp(x, DEFAULTPREC);
    1302     3538364 :     if (typ(x)!=t_REAL) pari_err_TYPE("gtodouble [t_REAL expected]", x);
    1303     3538364 :     avma = av;
    1304             :   }
    1305    19026990 :   return rtodbl(x);
    1306             : }
    1307             : INLINE long
    1308    72590532 : gtos(GEN x) {
    1309    72590532 :   if (typ(x) != t_INT) pari_err_TYPE("gtos [integer expected]",x);
    1310    72590525 :   return itos(x);
    1311             : }
    1312             : 
    1313             : INLINE ulong
    1314      123015 : gtou(GEN x) {
    1315      123015 :   if (typ(x) != t_INT || signe(x)<0)
    1316           0 :     pari_err_TYPE("gtou [integer >=0 expected]",x);
    1317      123202 :   return itou(x);
    1318             : }
    1319             : 
    1320             : INLINE GEN
    1321    21267003 : absfrac(GEN x)
    1322             : {
    1323    21267003 :   GEN y = cgetg(3, t_FRAC);
    1324    21267003 :   gel(y,1) = absi(gel(x,1));
    1325    21267003 :   gel(y,2) = icopy(gel(x,2)); return y;
    1326             : }
    1327             : INLINE GEN
    1328       32686 : absfrac_shallow(GEN x)
    1329       32686 : { return signe(gel(x,1))>0? x: mkfrac(negi(gel(x,1)), gel(x,2)); }
    1330             : INLINE GEN
    1331     7322315 : Q_abs(GEN x) { return (typ(x) == t_INT)? absi(x): absfrac(x); }
    1332             : INLINE GEN
    1333      107126 : Q_abs_shallow(GEN x)
    1334      107126 : { return (typ(x) == t_INT)? absi_shallow(x): absfrac_shallow(x); }
    1335             : INLINE GEN
    1336         322 : R_abs_shallow(GEN x)
    1337         322 : { return (typ(x) == t_FRAC)? absfrac_shallow(x): mpabs_shallow(x); }
    1338             : INLINE GEN
    1339           0 : R_abs(GEN x)
    1340           0 : { return (typ(x) == t_FRAC)? absfrac(x): mpabs(x); }
    1341             : 
    1342             : /* Force z to be of type real/complex with floating point components */
    1343             : INLINE GEN
    1344    27755244 : gtofp(GEN z, long prec)
    1345             : {
    1346    27755244 :   switch(typ(z))
    1347             :   {
    1348    17214821 :     case t_INT:  return itor(z, prec);
    1349     4283781 :     case t_FRAC: return fractor(z, prec);
    1350     4901883 :     case t_REAL: return rtor(z, prec);
    1351             :     case t_COMPLEX: {
    1352     1354759 :       GEN a = gel(z,1), b = gel(z,2);
    1353     1354759 :       if (isintzero(b)) return cxcompotor(a, prec);
    1354     1352376 :       if (isintzero(a)) {
    1355        2041 :         GEN y = cgetg(3, t_COMPLEX);
    1356        2041 :         b = cxcompotor(b, prec);
    1357        2041 :         gel(y,1) = real_0_bit(expo(b) - prec2nbits(prec));
    1358        2041 :         gel(y,2) = b; return y;
    1359             :       }
    1360     1350335 :       return cxtofp(z, prec);
    1361             :     }
    1362           0 :     case t_QUAD: return quadtofp(z, prec);
    1363           0 :     default: pari_err_TYPE("gtofp",z);
    1364             :              return NULL; /* LCOV_EXCL_LINE */
    1365             :   }
    1366             : }
    1367             : /* Force z to be of type real / int */
    1368             : INLINE GEN
    1369       22400 : gtomp(GEN z, long prec)
    1370             : {
    1371       22400 :   switch(typ(z))
    1372             :   {
    1373          14 :     case t_INT:  return z;
    1374       22386 :     case t_FRAC: return fractor(z, prec);
    1375           0 :     case t_REAL: return rtor(z, prec);
    1376           0 :     case t_QUAD: z = quadtofp(z, prec);
    1377           0 :                  if (typ(z) == t_REAL) return z;
    1378           0 :     default: pari_err_TYPE("gtomp",z);
    1379             :              return NULL; /* LCOV_EXCL_LINE */
    1380             :   }
    1381             : }
    1382             : 
    1383             : INLINE GEN
    1384      725760 : RgX_gtofp(GEN x, long prec)
    1385             : {
    1386             :   long l;
    1387      725760 :   GEN y = cgetg_copy(x, &l);
    1388      725760 :   while (--l > 1) gel(y,l) = gtofp(gel(x,l), prec);
    1389      725760 :   y[1] = x[1]; return y;
    1390             : }
    1391             : INLINE GEN
    1392     1128924 : RgC_gtofp(GEN x, long prec)
    1393     1128924 : { pari_APPLY_type(t_COL, gtofp(gel(x,i), prec)) }
    1394             : 
    1395             : INLINE GEN
    1396          42 : RgV_gtofp(GEN x, long prec)
    1397          42 : { pari_APPLY_type(t_VEC, gtofp(gel(x,i), prec)) }
    1398             : 
    1399             : INLINE GEN
    1400      130287 : RgM_gtofp(GEN x, long prec)
    1401      130287 : { pari_APPLY_same(RgC_gtofp(gel(x,i), prec)) }
    1402             : 
    1403             : INLINE GEN
    1404         560 : RgC_gtomp(GEN x, long prec)
    1405         560 : { pari_APPLY_type(t_COL, gtomp(gel(x,i), prec)) }
    1406             : 
    1407             : INLINE GEN
    1408          14 : RgM_gtomp(GEN x, long prec)
    1409          14 : { pari_APPLY_same(RgC_gtomp(gel(x,i), prec)) }
    1410             : 
    1411             : INLINE GEN
    1412        8835 : RgX_fpnorml2(GEN x, long prec)
    1413             : {
    1414        8835 :   pari_sp av = avma;
    1415        8835 :   return gerepileupto(av, gnorml2(RgX_gtofp(x, prec)));
    1416             : }
    1417             : INLINE GEN
    1418      178080 : RgC_fpnorml2(GEN x, long prec)
    1419             : {
    1420      178080 :   pari_sp av = avma;
    1421      178080 :   return gerepileupto(av, gnorml2(RgC_gtofp(x, prec)));
    1422             : }
    1423             : INLINE GEN
    1424        3755 : RgM_fpnorml2(GEN x, long prec)
    1425             : {
    1426        3755 :   pari_sp av = avma;
    1427        3755 :   return gerepileupto(av, gnorml2(RgM_gtofp(x, prec)));
    1428             : }
    1429             : 
    1430             : /* y a t_REAL */
    1431             : INLINE void
    1432      190202 : affgr(GEN x, GEN y)
    1433             : {
    1434             :   pari_sp av;
    1435      190202 :   switch(typ(x)) {
    1436        5992 :     case t_INT:  affir(x,y); break;
    1437      184210 :     case t_REAL: affrr(x,y); break;
    1438           0 :     case t_FRAC: rdiviiz(gel(x,1),gel(x,2), y); break;
    1439           0 :     case t_QUAD: av = avma; affgr(quadtofp(x,realprec(y)), y); avma = av; break;
    1440           0 :     default: pari_err_TYPE2("=",x,y);
    1441             :   }
    1442      190202 : }
    1443             : 
    1444             : INLINE GEN
    1445      186765 : affc_fixlg(GEN x, GEN res)
    1446             : {
    1447      186765 :   if (typ(x) == t_COMPLEX)
    1448             :   {
    1449      175658 :     affrr_fixlg(gel(x,1), gel(res,1));
    1450      175658 :     affrr_fixlg(gel(x,2), gel(res,2));
    1451             :   }
    1452             :   else
    1453             :   {
    1454       11107 :     avma = (pari_sp)(res+3);
    1455       11107 :     res = cgetr(realprec(gel(res,1)));
    1456       11107 :     affrr_fixlg(x, res);
    1457             :   }
    1458      186765 :   return res;
    1459             : }
    1460             : 
    1461             : INLINE GEN
    1462           0 : trunc_safe(GEN x) { long e; return gcvtoi(x,&e); }
    1463             : 
    1464             : /*******************************************************************/
    1465             : /*                                                                 */
    1466             : /*                          LENGTH CONVERSIONS                     */
    1467             : /*                                                                 */
    1468             : /*******************************************************************/
    1469             : INLINE long
    1470       27420 : ndec2nlong(long x) { return 1 + (long)((x)*(LOG2_10/BITS_IN_LONG)); }
    1471             : INLINE long
    1472       26937 : ndec2prec(long x) { return 2 + ndec2nlong(x); }
    1473             : INLINE long
    1474         483 : ndec2nbits(long x) { return ndec2nlong(x) << TWOPOTBITS_IN_LONG; }
    1475             : /* Fast implementation of ceil(x / (8*sizeof(long))); typecast to (ulong)
    1476             :  * to avoid overflow. Faster than 1 + ((x-1)>>TWOPOTBITS_IN_LONG)) :
    1477             :  *   addl, shrl instead of subl, sarl, addl */
    1478             : INLINE long
    1479     1202057 : nbits2nlong(long x) {
    1480     1202057 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1481             : }
    1482             : 
    1483             : INLINE long
    1484   250088549 : nbits2extraprec(long x) {
    1485   250088549 :   return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1486             : }
    1487             : 
    1488             : /* Fast implementation of 2 + nbits2nlong(x) */
    1489             : INLINE long
    1490    99610311 : nbits2prec(long x) {
    1491    99610311 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1492             : }
    1493             : INLINE long
    1494     7340334 : nbits2lg(long x) {
    1495     7340334 :   return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
    1496             : }
    1497             : /* ceil(x / sizeof(long)) */
    1498             : INLINE long
    1499     8996444 : nchar2nlong(long x) {
    1500     8996444 :   return (long)(((ulong)x+sizeof(long)-1) >> (TWOPOTBITS_IN_LONG-3L));
    1501             : }
    1502             : INLINE long
    1503  1070500266 : prec2nbits(long x) { return (x-2) * BITS_IN_LONG; }
    1504             : INLINE double
    1505      563003 : bit_accuracy_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1506             : INLINE double
    1507      233561 : prec2nbits_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
    1508             : INLINE long
    1509    28138540 : bit_prec(GEN x) { return prec2nbits(realprec(x)); }
    1510             : INLINE long
    1511   975843245 : bit_accuracy(long x) { return prec2nbits(x); }
    1512             : INLINE long
    1513       12239 : prec2ndec(long x) { return (long)prec2nbits_mul(x, LOG10_2); }
    1514             : INLINE long
    1515         186 : nbits2ndec(long x) { return (long)(x * LOG10_2); }
    1516             : INLINE long
    1517        1897 : precdbl(long x) {return (x - 1) << 1;}
    1518             : INLINE long
    1519  3162019129 : divsBIL(long n) { return n >> TWOPOTBITS_IN_LONG; }
    1520             : INLINE long
    1521  3124524406 : remsBIL(long n) { return n & (BITS_IN_LONG-1); }
    1522             : 
    1523             : /*********************************************************************/
    1524             : /**                                                                 **/
    1525             : /**                      OPERATIONS MODULO m                        **/
    1526             : /**                                                                 **/
    1527             : /*********************************************************************/
    1528             : /* Assume m > 0, more efficient if 0 <= a, b < m */
    1529             : 
    1530             : INLINE GEN
    1531    33676979 : Fp_red(GEN a, GEN m) { return modii(a, m); }
    1532             : INLINE GEN
    1533    83756392 : Fp_add(GEN a, GEN b, GEN m)
    1534             : {
    1535    83756392 :   pari_sp av=avma;
    1536    83756392 :   GEN p = addii(a,b);
    1537    83779799 :   long s = signe(p);
    1538    83779799 :   if (!s) return p; /* = gen_0 */
    1539    76221089 :   if (s > 0) /* general case */
    1540             :   {
    1541    75994620 :     GEN t = subii(p, m);
    1542    76058556 :     s = signe(t);
    1543    76058556 :     if (!s) { avma = av; return gen_0; }
    1544    70283890 :     if (s < 0) { avma = (pari_sp)p; return p; }
    1545    30596067 :     if (cmpii(t, m) < 0) return gerepileuptoint(av, t); /* general case ! */
    1546     1106140 :     p = remii(t, m);
    1547             :   }
    1548             :   else
    1549      226469 :     p = modii(p, m);
    1550     1332609 :   return gerepileuptoint(av, p);
    1551             : }
    1552             : INLINE GEN
    1553    74254148 : Fp_sub(GEN a, GEN b, GEN m)
    1554             : {
    1555    74254148 :   pari_sp av=avma;
    1556    74254148 :   GEN p = subii(a,b);
    1557    74514416 :   long s = signe(p);
    1558    74514416 :   if (!s) return p; /* = gen_0 */
    1559    68484583 :   if (s > 0)
    1560             :   {
    1561    33053306 :     if (cmpii(p, m) < 0) return p; /* general case ! */
    1562     1296979 :     p = remii(p, m);
    1563             :   }
    1564             :   else
    1565             :   {
    1566    35431277 :     GEN t = addii(p, m);
    1567    35414167 :     if (!s) { avma = av; return gen_0; }
    1568    35414167 :     if (s > 0) return gerepileuptoint(av, t); /* general case ! */
    1569    35414167 :     p = modii(t, m);
    1570             :   }
    1571    36715064 :   return gerepileuptoint(av, p);
    1572             : }
    1573             : INLINE GEN
    1574    11883029 : Fp_neg(GEN b, GEN m)
    1575             : {
    1576    11883029 :   pari_sp av = avma;
    1577    11883029 :   long s = signe(b);
    1578             :   GEN p;
    1579    11883029 :   if (!s) return gen_0;
    1580     8459113 :   if (s > 0)
    1581             :   {
    1582     8257574 :     p = subii(m, b);
    1583     8257274 :     if (signe(p) >= 0) return p; /* general case ! */
    1584       92350 :     p = modii(p, m);
    1585             :   } else
    1586      201539 :     p = remii(negi(b), m);
    1587      293889 :   return gerepileuptoint(av, p);
    1588             : }
    1589             : 
    1590             : INLINE GEN
    1591       22249 : Fp_halve(GEN a, GEN p)
    1592             : {
    1593       22249 :   if (mpodd(a)) a = addii(a,p);
    1594       22249 :   return shifti(a,-1);
    1595             : }
    1596             : 
    1597             : /* assume 0 <= u < p and ps2 = p>>1 */
    1598             : INLINE GEN
    1599    15425654 : Fp_center(GEN u, GEN p, GEN ps2)
    1600    15425654 : { return abscmpii(u,ps2)<=0? icopy(u): subii(u,p); }
    1601             : /* same without copy */
    1602             : INLINE GEN
    1603    12852318 : Fp_center_i(GEN u, GEN p, GEN ps2)
    1604    12852318 : { return abscmpii(u,ps2)<=0? u: subii(u,p); }
    1605             : 
    1606             : /* x + y*z mod p */
    1607             : INLINE GEN
    1608     7593540 : Fp_addmul(GEN x, GEN y, GEN z, GEN p)
    1609             : {
    1610             :   pari_sp av;
    1611     7593540 :   if (!signe(y) || !signe(z)) return Fp_red(x, p);
    1612     7296500 :   if (!signe(x)) return Fp_mul(z,y, p);
    1613     6995057 :   av = avma;
    1614     6995057 :   return gerepileuptoint(av, modii(addii(x, mulii(y,z)), p));
    1615             : }
    1616             : 
    1617             : INLINE GEN
    1618    92492364 : Fp_mul(GEN a, GEN b, GEN m)
    1619             : {
    1620    92492364 :   pari_sp av=avma;
    1621             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1622    92492364 :   (void)new_chunk(lg(a)+lg(b)+(lg(m)<<1));
    1623    92502230 :   p = mulii(a,b);
    1624    92502356 :   avma = av; return modii(p,m);
    1625             : }
    1626             : INLINE GEN
    1627    59050031 : Fp_sqr(GEN a, GEN m)
    1628             : {
    1629    59050031 :   pari_sp av=avma;
    1630             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1631    59050031 :   (void)new_chunk((lg(a)+lg(m))<<1);
    1632    59311559 :   p = sqri(a);
    1633    59545667 :   avma = av; return remii(p,m); /*Use remii: p >= 0 */
    1634             : }
    1635             : INLINE GEN
    1636    69147892 : Fp_mulu(GEN a, ulong b, GEN m)
    1637             : {
    1638    69147892 :   long l = lgefint(m);
    1639    69147892 :   if (l == 3)
    1640             :   {
    1641    35080486 :     ulong mm = m[2];
    1642    35080486 :     return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1643             :   } else {
    1644    34067406 :     pari_sp av = avma;
    1645             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1646    34067406 :     (void)new_chunk(lg(a)+1+(l<<1));
    1647    34118031 :     p = muliu(a,b);
    1648    33821116 :     avma = av; return modii(p,m);
    1649             :   }
    1650             : }
    1651             : INLINE GEN
    1652           0 : Fp_muls(GEN a, long b, GEN m)
    1653             : {
    1654           0 :   long l = lgefint(m);
    1655           0 :   if (l == 3)
    1656             :   {
    1657           0 :     ulong mm = m[2];
    1658           0 :     if (b < 0)
    1659             :     {
    1660           0 :       ulong t = Fl_mul(umodiu(a, mm), -b, mm);
    1661           0 :       return t? utoipos(mm - t): gen_0;
    1662             :     }
    1663             :     else
    1664           0 :       return utoi( Fl_mul(umodiu(a, mm), b, mm) );
    1665             :   } else {
    1666           0 :     pari_sp av = avma;
    1667             :     GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1668           0 :     (void)new_chunk(lg(a)+1+(l<<1));
    1669           0 :     p = mulis(a,b);
    1670           0 :     avma = av; return modii(p,m);
    1671             :   }
    1672             : }
    1673             : 
    1674             : INLINE GEN
    1675     8099518 : Fp_inv(GEN a, GEN m)
    1676             : {
    1677             :   GEN res;
    1678     8099518 :   if (! invmod(a,m,&res)) pari_err_INV("Fp_inv", mkintmod(res,m));
    1679     8099382 :   return res;
    1680             : }
    1681             : INLINE GEN
    1682      317478 : Fp_invsafe(GEN a, GEN m)
    1683             : {
    1684             :   GEN res;
    1685      317478 :   if (! invmod(a,m,&res)) return NULL;
    1686      317478 :   return res;
    1687             : }
    1688             : INLINE GEN
    1689     2359794 : Fp_div(GEN a, GEN b, GEN m)
    1690             : {
    1691     2359794 :   pari_sp av=avma;
    1692             :   GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
    1693     2359794 :   (void)new_chunk(lg(a)+(lg(m)<<1));
    1694     2359794 :   p = mulii(a, Fp_inv(b,m));
    1695     2359790 :   avma = av; return modii(p,m);
    1696             : }
    1697             : 
    1698             : INLINE GEN
    1699      837959 : Flx_mulu(GEN x, ulong a, ulong p) { return Flx_Fl_mul(x,a%p,p); }
    1700             : 
    1701             : INLINE GEN
    1702           0 : get_F2x_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1703             : 
    1704             : INLINE long
    1705      447845 : get_F2x_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1706             : 
    1707             : INLINE long
    1708      121352 : get_F2x_degree(GEN T) { return typ(T)==t_VEC? F2x_degree(gel(T,2)): F2x_degree(T); }
    1709             : 
    1710             : INLINE GEN
    1711         378 : get_F2xqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1712             : 
    1713             : INLINE long
    1714      376068 : get_F2xqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1715             : 
    1716             : INLINE long
    1717      201397 : get_F2xqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1718             : 
    1719             : INLINE GEN
    1720     7414669 : get_Flx_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1721             : 
    1722             : INLINE long
    1723    19850471 : get_Flx_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
    1724             : 
    1725             : INLINE long
    1726    26724996 : get_Flx_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1727             : 
    1728             : INLINE GEN
    1729        2522 : get_FlxqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1730             : 
    1731             : INLINE long
    1732      365836 : get_FlxqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1733             : 
    1734             : INLINE long
    1735       91044 : get_FlxqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1736             : 
    1737             : INLINE GEN
    1738     1618063 : get_FpX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1739             : 
    1740             : INLINE long
    1741     2889794 : get_FpX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1742             : 
    1743             : INLINE long
    1744     2018267 : get_FpX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1745             : 
    1746             : INLINE GEN
    1747      142686 : get_FpXQX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
    1748             : 
    1749             : INLINE long
    1750       55743 : get_FpXQX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
    1751             : 
    1752             : INLINE long
    1753        2177 : get_FpXQX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
    1754             : 
    1755             : /*******************************************************************/
    1756             : /*                                                                 */
    1757             : /*                        ADDMULII / SUBMULII                      */
    1758             : /*                                                                 */
    1759             : /*******************************************************************/
    1760             : /* x - y*z */
    1761             : INLINE GEN
    1762    13409380 : submulii(GEN x, GEN y, GEN z)
    1763             : {
    1764    13409380 :   long lx = lgefint(x), ly, lz;
    1765             :   pari_sp av;
    1766             :   GEN t;
    1767    13409380 :   if (lx == 2) { t = mulii(z,y); togglesign(t); return t; }
    1768    11599875 :   ly = lgefint(y);
    1769    11599875 :   if (ly == 2) return icopy(x);
    1770    10471999 :   lz = lgefint(z);
    1771    10471999 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1772    10471999 :   t = mulii(z, y);
    1773    10471999 :   avma = av; return subii(x,t);
    1774             : }
    1775             : /* y*z - x */
    1776             : INLINE GEN
    1777     1132206 : mulsubii(GEN y, GEN z, GEN x)
    1778             : {
    1779     1132206 :   long lx = lgefint(x), ly, lz;
    1780             :   pari_sp av;
    1781             :   GEN t;
    1782     1132206 :   if (lx == 2) return mulii(z,y);
    1783      705200 :   ly = lgefint(y);
    1784      705200 :   if (ly == 2) return negi(x);
    1785      648953 :   lz = lgefint(z);
    1786      648953 :   av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
    1787      648953 :   t = mulii(z, y);
    1788      648953 :   avma = av; return subii(t,x);
    1789             : }
    1790             : 
    1791             : /* x - u*y */
    1792             : INLINE GEN
    1793        7595 : submuliu(GEN x, GEN y, ulong u)
    1794             : {
    1795             :   pari_sp av;
    1796        7595 :   long ly = lgefint(y);
    1797        7595 :   if (ly == 2) return icopy(x);
    1798        7595 :   av = avma;
    1799        7595 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1800        7595 :   y = mului(u,y);
    1801        7595 :   avma = av; return subii(x, y);
    1802             : }
    1803             : /* x + u*y */
    1804             : INLINE GEN
    1805        7595 : addmuliu(GEN x, GEN y, ulong u)
    1806             : {
    1807             :   pari_sp av;
    1808        7595 :   long ly = lgefint(y);
    1809        7595 :   if (ly == 2) return icopy(x);
    1810        7595 :   av = avma;
    1811        7595 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1812        7595 :   y = mului(u,y);
    1813        7595 :   avma = av; return addii(x, y);
    1814             : }
    1815             : /* x - u*y */
    1816             : INLINE GEN
    1817   115978485 : submuliu_inplace(GEN x, GEN y, ulong u)
    1818             : {
    1819             :   pari_sp av;
    1820   115978485 :   long ly = lgefint(y);
    1821   115978485 :   if (ly == 2) return x;
    1822    92063374 :   av = avma;
    1823    92063374 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1824    92063374 :   y = mului(u,y);
    1825    92063374 :   avma = av; return subii(x, y);
    1826             : }
    1827             : /* x + u*y */
    1828             : INLINE GEN
    1829   114413881 : addmuliu_inplace(GEN x, GEN y, ulong u)
    1830             : {
    1831             :   pari_sp av;
    1832   114413881 :   long ly = lgefint(y);
    1833   114413881 :   if (ly == 2) return x;
    1834    91668456 :   av = avma;
    1835    91668456 :   (void)new_chunk(3+ly+lgefint(x)); /* HACK */
    1836    91668456 :   y = mului(u,y);
    1837    91668456 :   avma = av; return addii(x, y);
    1838             : }
    1839             : /* ux + vy */
    1840             : INLINE GEN
    1841    14994536 : lincombii(GEN u, GEN v, GEN x, GEN y)
    1842             : {
    1843    14994536 :   long lx = lgefint(x), ly;
    1844             :   GEN p1, p2;
    1845             :   pari_sp av;
    1846    14994536 :   if (lx == 2) return mulii(v,y);
    1847     9065010 :   ly = lgefint(y);
    1848     9065010 :   if (ly == 2) return mulii(u,x);
    1849     7927147 :   av = avma; (void)new_chunk(lx+ly+lgefint(u)+lgefint(v)); /* HACK */
    1850     7927147 :   p1 = mulii(u,x);
    1851     7927147 :   p2 = mulii(v,y);
    1852     7927147 :   avma = av; return addii(p1,p2);
    1853             : }
    1854             : 
    1855             : /*******************************************************************/
    1856             : /*                                                                 */
    1857             : /*                          GEN SUBTYPES                           */
    1858             : /*                                                                 */
    1859             : /*******************************************************************/
    1860             : 
    1861             : INLINE int
    1862   989939601 : is_const_t(long t) { return (t < t_POLMOD); }
    1863             : INLINE int
    1864        5353 : is_extscalar_t(long t) { return (t <= t_POL); }
    1865             : INLINE int
    1866     1036428 : is_intreal_t(long t) { return (t <= t_REAL); }
    1867             : INLINE int
    1868   401706182 : is_matvec_t(long t) { return (t >= t_VEC && t <= t_MAT); }
    1869             : INLINE int
    1870    51837156 : is_noncalc_t(long tx) { return (tx) >= t_LIST; }
    1871             : INLINE int
    1872      779880 : is_rational_t(long t) { return (t == t_INT || t == t_FRAC); }
    1873             : INLINE int
    1874      309257 : is_real_t(long t) { return (t == t_INT || t == t_REAL || t == t_FRAC); }
    1875             : INLINE int
    1876  2771655433 : is_recursive_t(long t) { return lontyp[t]; }
    1877             : INLINE int
    1878   176518266 : is_scalar_t(long t) { return (t < t_POL); }
    1879             : INLINE int
    1880      944437 : is_vec_t(long t) { return (t == t_VEC || t == t_COL); }
    1881             : 
    1882             : /*******************************************************************/
    1883             : /*                                                                 */
    1884             : /*                         TRANSCENDENTAL                          */
    1885             : /*                                                                 */
    1886             : /*******************************************************************/
    1887             : INLINE GEN
    1888    17976156 : sqrtr(GEN x) {
    1889    17976156 :   long s = signe(x);
    1890    17976156 :   if (s == 0) return real_0_bit(expo(x) >> 1);
    1891    17942435 :   if (s >= 0) return sqrtr_abs(x);
    1892       28466 :   retmkcomplex(gen_0, sqrtr_abs(x));
    1893             : }
    1894             : INLINE GEN
    1895           0 : cbrtr_abs(GEN x) { return sqrtnr_abs(x, 3); }
    1896             : INLINE GEN
    1897           0 : cbrtr(GEN x) {
    1898           0 :   long s = signe(x);
    1899             :   GEN r;
    1900           0 :   if (s == 0) return real_0_bit(expo(x) / 3);
    1901           0 :   r = cbrtr_abs(x);
    1902           0 :   if (s < 0) togglesign(r);
    1903           0 :   return r;
    1904             : }
    1905             : INLINE GEN
    1906      306568 : sqrtnr(GEN x, long n) {
    1907      306568 :   long s = signe(x);
    1908             :   GEN r;
    1909      306568 :   if (s == 0) return real_0_bit(expo(x) / n);
    1910      306568 :   r = sqrtnr_abs(x, n);
    1911      306568 :   if (s < 0) pari_err_IMPL("sqrtnr for x < 0");
    1912      306568 :   return r;
    1913             : }
    1914             : INLINE long
    1915      213860 : logint(GEN B, GEN y) { return logintall(B,y,NULL); }
    1916             : INLINE ulong
    1917     1807573 : ulogint(ulong B, ulong y)
    1918             : {
    1919             :   ulong r;
    1920             :   long e;
    1921     1807573 :   if (y == 2) return expu(B);
    1922     1790045 :   r = y;
    1923     6001647 :   for (e=1;; e++)
    1924             :   { /* here, r = y^e, r2 = y^(e-1) */
    1925     6001647 :     if (r >= B) return r == B? e: e-1;
    1926     4211602 :     r = umuluu_or_0(y, r);
    1927     4211602 :     if (!r) return e;
    1928     4211602 :   }
    1929             : }
    1930             : 
    1931             : /*******************************************************************/
    1932             : /*                                                                 */
    1933             : /*                         MISCELLANEOUS                           */
    1934             : /*                                                                 */
    1935             : /*******************************************************************/
    1936     1036351 : INLINE int ismpzero(GEN x) { return is_intreal_t(typ(x)) && !signe(x); }
    1937   486751544 : INLINE int isintzero(GEN x) { return typ(x) == t_INT && !signe(x); }
    1938     6822968 : INLINE int isint1(GEN x) { return typ(x)==t_INT && equali1(x); }
    1939        4536 : INLINE int isintm1(GEN x){ return typ(x)==t_INT && equalim1(x);}
    1940   327378650 : INLINE int equali1(GEN n)
    1941   327378650 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(1)) && n[2] == 1; }
    1942    61929268 : INLINE int equalim1(GEN n)
    1943    61929268 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(-1)) && n[2] == 1; }
    1944             : /* works only for POSITIVE integers */
    1945  1190861208 : INLINE int is_pm1(GEN n)
    1946  1190861208 : { return lgefint(n) == 3 && n[2] == 1; }
    1947   209594604 : INLINE int is_bigint(GEN n)
    1948   209594604 : { long l = lgefint(n); return l > 3 || (l == 3 && (n[2] & HIGHBIT)); }
    1949             : 
    1950  2154588823 : INLINE int odd(long x) { return x & 1; }
    1951    28942807 : INLINE int both_odd(long x, long y) { return x & y & 1; }
    1952             : 
    1953             : INLINE int
    1954  2520570434 : isonstack(GEN x)
    1955  5041140868 : { return ((pari_sp)x >= pari_mainstack->bot
    1956  2520570434 :        && (pari_sp)x <  pari_mainstack->top); }
    1957             : 
    1958             : /* assume x != 0 and x t_REAL, return an approximation to log2(|x|) */
    1959             : INLINE double
    1960    19191282 : dbllog2r(GEN x)
    1961    19191282 : { return log2((double)(ulong)x[2]) + (double)(expo(x) - (BITS_IN_LONG-1)); }
    1962             : 
    1963             : INLINE GEN
    1964      288837 : mul_content(GEN cx, GEN cy)
    1965             : {
    1966      288837 :   if (!cx) return cy;
    1967      103880 :   if (!cy) return cx;
    1968       77864 :   return gmul(cx,cy);
    1969             : }
    1970             : INLINE GEN
    1971         847 : inv_content(GEN c) { return c? ginv(c): NULL; }
    1972             : INLINE GEN
    1973     1570192 : mul_denom(GEN dx, GEN dy)
    1974             : {
    1975     1570192 :   if (!dx) return dy;
    1976     1049752 :   if (!dy) return dx;
    1977      324093 :   return mulii(dx,dy);
    1978             : }
    1979             : 
    1980             : /* POLYNOMIALS */
    1981             : INLINE GEN
    1982    17565752 : constant_coeff(GEN x) { return signe(x)? gel(x,2): gen_0; }
    1983             : INLINE GEN
    1984    82348180 : leading_coeff(GEN x) { return lg(x) == 2? gen_0: gel(x,lg(x)-1); }
    1985             : INLINE ulong
    1986      418541 : Flx_lead(GEN x) { return lg(x) == 2? 0: x[lg(x)-1]; }
    1987             : INLINE ulong
    1988       12348 : Flx_constant(GEN x) { return lg(x) == 2? 0: x[2]; }
    1989             : INLINE long
    1990  2734448949 : degpol(GEN x) { return lg(x)-3; }
    1991             : INLINE long
    1992  1350740942 : lgpol(GEN x) { return lg(x)-2; }
    1993             : INLINE long
    1994    94631129 : lgcols(GEN x) { return lg(gel(x,1)); }
    1995             : INLINE long
    1996    28910428 : nbrows(GEN x) { return lg(gel(x,1))-1; }
    1997             : INLINE GEN
    1998      269115 : truecoeff(GEN x, long n) { return polcoeff0(x,n,-1); }
    1999             : 
    2000             : INLINE GEN
    2001      582607 : ZXQ_mul(GEN y, GEN x, GEN T) { return ZX_rem(ZX_mul(y, x), T); }
    2002             : INLINE GEN
    2003      312643 : ZXQ_sqr(GEN x, GEN T) { return ZX_rem(ZX_sqr(x), T); }
    2004             : 
    2005             : INLINE GEN
    2006    64016793 : RgX_copy(GEN x)
    2007             : {
    2008             :   long lx, i;
    2009    64016793 :   GEN y = cgetg_copy(x, &lx); y[1] = x[1];
    2010    64016798 :   for (i = 2; i<lx; i++) gel(y,i) = gcopy(gel(x,i));
    2011    64016792 :   return y;
    2012             : }
    2013             : /* have to use ulong to avoid silly warnings from gcc "assuming signed
    2014             :  * overflow does not occur" */
    2015             : INLINE GEN
    2016     2474207 : RgX_coeff(GEN x, long n)
    2017             : {
    2018     2474207 :   ulong l = lg(x);
    2019     2474207 :   return (n < 0 || ((ulong)n+3) > l)? gen_0: gel(x,n+2);
    2020             : }
    2021             : INLINE GEN
    2022      353293 : RgX_renormalize(GEN x) { return RgX_renormalize_lg(x, lg(x)); }
    2023             : INLINE GEN
    2024     6554338 : RgX_div(GEN x, GEN y) { return RgX_divrem(x,y,NULL); }
    2025             : INLINE GEN
    2026        1792 : RgXQX_div(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,NULL); }
    2027             : INLINE GEN
    2028       53826 : RgXQX_rem(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,ONLY_REM); }
    2029             : INLINE GEN
    2030      866979 : FpX_div(GEN x, GEN y, GEN p) { return FpX_divrem(x,y,p, NULL); }
    2031             : INLINE GEN
    2032     4039122 : Flx_div(GEN x, GEN y, ulong p) { return Flx_divrem(x,y,p, NULL); }
    2033             : INLINE GEN
    2034     2520305 : F2x_div(GEN x, GEN y) { return F2x_divrem(x,y, NULL); }
    2035             : INLINE GEN
    2036           0 : FpV_FpC_mul(GEN x, GEN y, GEN p) { return FpV_dotproduct(x,y,p); }
    2037             : INLINE GEN
    2038    56617227 : pol0_Flx(long sv) { return mkvecsmall(sv); }
    2039             : INLINE GEN
    2040    22632828 : pol1_Flx(long sv) { return mkvecsmall2(sv, 1); }
    2041             : INLINE GEN
    2042    17546891 : polx_Flx(long sv) { return mkvecsmall3(sv, 0, 1); }
    2043             : INLINE GEN
    2044           0 : zero_zx(long sv) { return zero_Flx(sv); }
    2045             : INLINE GEN
    2046           0 : polx_zx(long sv) { return polx_Flx(sv); }
    2047             : INLINE GEN
    2048           0 : zx_shift(GEN x, long n) { return Flx_shift(x,n); }
    2049             : INLINE GEN
    2050           0 : zx_renormalize(GEN x, long l) { return Flx_renormalize(x,l); }
    2051             : INLINE GEN
    2052        1474 : zero_F2x(long sv) { return zero_Flx(sv); }
    2053             : INLINE GEN
    2054    11240707 : pol0_F2x(long sv) { return pol0_Flx(sv); }
    2055             : INLINE GEN
    2056     2892155 : pol1_F2x(long sv) { return pol1_Flx(sv); }
    2057             : INLINE GEN
    2058      674612 : polx_F2x(long sv) { return mkvecsmall2(sv, 2); }
    2059             : INLINE int
    2060      815916 : F2x_equal1(GEN x) { return Flx_equal1(x); }
    2061             : INLINE int
    2062     3052866 : F2x_equal(GEN V, GEN W) { return Flx_equal(V,W); }
    2063             : INLINE GEN
    2064    60742388 : F2x_copy(GEN x) { return leafcopy(x); }
    2065             : INLINE GEN
    2066           0 : F2v_copy(GEN x) { return leafcopy(x); }
    2067             : INLINE GEN
    2068     2223611 : Flv_copy(GEN x) { return leafcopy(x); }
    2069             : INLINE GEN
    2070    82102425 : Flx_copy(GEN x) { return leafcopy(x); }
    2071             : INLINE GEN
    2072     1819803 : vecsmall_copy(GEN x) { return leafcopy(x); }
    2073             : INLINE int
    2074     4831083 : Flx_equal1(GEN x) { return degpol(x)==0 && x[2] == 1; }
    2075             : INLINE int
    2076       18170 : ZX_equal1(GEN x) { return degpol(x)==0 && equali1(gel(x,2)); }
    2077             : INLINE int
    2078     5741034 : ZX_is_monic(GEN x) { return equali1(leading_coeff(x)); }
    2079             : 
    2080             : INLINE GEN
    2081    47950426 : ZX_renormalize(GEN x, long lx)    { return ZXX_renormalize(x,lx); }
    2082             : INLINE GEN
    2083    66611409 : FpX_renormalize(GEN x, long lx)   { return ZXX_renormalize(x,lx); }
    2084             : INLINE GEN
    2085     1037093 : FpXX_renormalize(GEN x, long lx)  { return ZXX_renormalize(x,lx); }
    2086             : INLINE GEN
    2087     1239544 : FpXQX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
    2088             : INLINE GEN
    2089   113462285 : F2x_renormalize(GEN x, long lx)   { return Flx_renormalize(x,lx); }
    2090             : INLINE GEN
    2091       31485 : F2v_to_F2x(GEN x, long sv) {
    2092       31485 :   GEN y = leafcopy(x);
    2093       31485 :   y[1] = sv; F2x_renormalize(y, lg(y)); return y;
    2094             : }
    2095             : 
    2096             : INLINE long
    2097         462 : sturm(GEN x) { return sturmpart(x, NULL, NULL); }
    2098             : 
    2099             : INLINE long
    2100        7224 : gval(GEN x, long v) {
    2101        7224 :   pari_sp av = avma;
    2102        7224 :   long n = gvaluation(x, pol_x(v));
    2103        7224 :   avma = av; return n;
    2104             : }
    2105             : 
    2106             : INLINE void
    2107      469016 : RgX_shift_inplace_init(long v)
    2108      469016 : { if (v) (void)cgetg(v, t_VECSMALL); }
    2109             : /* shift polynomial in place. assume v free cells have been left before x */
    2110             : INLINE GEN
    2111      469016 : RgX_shift_inplace(GEN x, long v)
    2112             : {
    2113             :   long i, lx;
    2114             :   GEN y, z;
    2115      469016 :   if (!v) return x;
    2116      253227 :   lx = lg(x);
    2117      253227 :   if (lx == 2) return x;
    2118      253227 :   y = x + v;
    2119      253227 :   z = x + lx;
    2120             :   /* stackdummy from normalizepol: move it up */
    2121      253227 :   if (lg(z) != v) x[lx + v] = z[0];
    2122      253227 :   for (i = lx-1; i >= 2; i--) gel(y,i) = gel(x,i);
    2123      253227 :   for (i = v+1;  i >= 2; i--) gel(x,i) = gen_0;
    2124             :   /* leave x[1] alone: it is correct */
    2125      253227 :   x[0] = evaltyp(t_POL) | evallg(lx+v); return x;
    2126             : }
    2127             : 
    2128             : 
    2129             : /* LINEAR ALGEBRA */
    2130             : INLINE GEN
    2131      408711 : zv_to_ZV(GEN x) { return vecsmall_to_vec(x); }
    2132             : INLINE GEN
    2133     4928133 : zc_to_ZC(GEN x) { return vecsmall_to_col(x); }
    2134             : INLINE GEN
    2135      435041 : ZV_to_zv(GEN x) { return vec_to_vecsmall(x); }
    2136             : INLINE GEN
    2137           0 : zx_to_zv(GEN x, long N) { return Flx_to_Flv(x,N); }
    2138             : INLINE GEN
    2139           0 : zv_to_zx(GEN x, long sv) { return Flv_to_Flx(x,sv); }
    2140             : INLINE GEN
    2141           0 : zm_to_zxV(GEN x, long sv) { return Flm_to_FlxV(x,sv); }
    2142             : INLINE GEN
    2143           0 : zero_zm(long x, long y) { return zero_Flm(x,y); }
    2144             : INLINE GEN
    2145    17092014 : zero_zv(long x) { return zero_Flv(x); }
    2146             : INLINE GEN
    2147         210 : zm_transpose(GEN x) { return Flm_transpose(x); }
    2148             : INLINE GEN
    2149           0 : zm_copy(GEN x) { return Flm_copy(x); }
    2150             : INLINE GEN
    2151     1902457 : zv_copy(GEN x) { return Flv_copy(x); }
    2152             : INLINE GEN
    2153           0 : zm_row(GEN x, long i) { return Flm_row(x,i); }
    2154             : 
    2155             : INLINE GEN
    2156      841203 : ZC_hnfrem(GEN x, GEN y) { return ZC_hnfremdiv(x,y,NULL); }
    2157             : INLINE GEN
    2158       35588 : ZM_hnfrem(GEN x, GEN y) { return ZM_hnfdivrem(x,y,NULL); }
    2159             : INLINE GEN
    2160     1165568 : ZM_lll(GEN x, double D, long f) { return ZM_lll_norms(x,D,f,NULL); }
    2161             : INLINE void
    2162     5647371 : RgM_dimensions(GEN x, long *m, long *n) { *n = lg(x)-1; *m = *n? nbrows(x): 0; }
    2163             : INLINE GEN
    2164     7411603 : RgM_shallowcopy(GEN x)
    2165             : {
    2166             :   long l;
    2167     7411603 :   GEN y = cgetg_copy(x, &l);
    2168     7411603 :   while (--l > 0) gel(y,l) = leafcopy(gel(x,l));
    2169     7411603 :   return y;
    2170             : }
    2171             : INLINE GEN
    2172         288 : F2m_copy(GEN x) { return RgM_shallowcopy(x); }
    2173             : 
    2174             : INLINE GEN
    2175     1270100 : Flm_copy(GEN x) { return RgM_shallowcopy(x); }
    2176             : 
    2177             : /* divisibility: return 1 if y[i] | x[i] for all i, 0 otherwise. Assume
    2178             :  * x,y are ZV of the same length */
    2179             : INLINE int
    2180       23198 : ZV_dvd(GEN x, GEN y)
    2181             : {
    2182       23198 :   long i, l = lg(x);
    2183       36666 :   for (i=1; i < l; i++)
    2184       29533 :     if ( ! dvdii( gel(x,i), gel(y,i) ) ) return 0;
    2185        7133 :   return 1;
    2186             : }
    2187             : 
    2188             : /* Fq */
    2189             : INLINE GEN
    2190     2890616 : Fq_red(GEN x, GEN T, GEN p)
    2191     2890616 : { return typ(x)==t_INT? Fp_red(x,p): FpXQ_red(x,T,p); }
    2192             : INLINE GEN
    2193       43430 : Fq_to_FpXQ(GEN x, GEN T, GEN p /*unused*/)
    2194             : {
    2195             :   (void) p;
    2196       43430 :   return typ(x)==t_INT ? scalarpol(x, get_FpX_var(T)): x;
    2197             : }
    2198             : INLINE GEN
    2199         756 : Rg_to_Fq(GEN x, GEN T, GEN p) { return T? Rg_to_FpXQ(x,T,p): Rg_to_Fp(x,p); }
    2200             : 
    2201             : INLINE GEN
    2202         833 : gener_Fq_local(GEN T, GEN p, GEN L)
    2203         833 : { return T? gener_FpXQ_local(T,p, L)
    2204         833 :           : pgener_Fp_local(p, L); }
    2205             : 
    2206             : /* FpXQX */
    2207             : INLINE GEN
    2208        4429 : FpXQX_div(GEN x, GEN y, GEN T, GEN p) { return FpXQX_divrem(x, y, T, p, NULL); }
    2209             : INLINE GEN
    2210       34886 : FlxqX_div(GEN x, GEN y, GEN T, ulong p) { return FlxqX_divrem(x, y, T, p, NULL); }
    2211             : INLINE GEN
    2212       33278 : F2xqX_div(GEN x, GEN y, GEN T) { return F2xqX_divrem(x, y, T, NULL); }
    2213             : 
    2214             : /* FqX */
    2215             : INLINE GEN
    2216       25158 : FqX_red(GEN z, GEN T, GEN p) { return T? FpXQX_red(z, T, p): FpX_red(z, p); }
    2217             : INLINE GEN
    2218      959140 : FqX_add(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2219             : INLINE GEN
    2220       17404 : FqX_neg(GEN x,GEN T,GEN p) { return T? FpXX_neg(x,p): FpX_neg(x,p); }
    2221             : INLINE GEN
    2222        2688 : FqX_sub(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2223             : INLINE GEN
    2224      652637 : FqX_Fp_mul(GEN P, GEN u, GEN T, GEN p)
    2225      652637 : { return T? FpXX_Fp_mul(P, u, p): FpX_Fp_mul(P, u, p); }
    2226             : INLINE GEN
    2227      588081 : FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p)
    2228      588081 : { return typ(U)==t_INT ? FqX_Fp_mul(P, U, T, p): FpXQX_FpXQ_mul(P, U, T, p); }
    2229             : INLINE GEN
    2230       92771 : FqX_mul(GEN x, GEN y, GEN T, GEN p)
    2231       92771 : { return T? FpXQX_mul(x, y, T, p): FpX_mul(x, y, p); }
    2232             : INLINE GEN
    2233      489590 : FqX_mulu(GEN x, ulong y, GEN T, GEN p)
    2234      489590 : { return T? FpXX_mulu(x, y, p): FpX_mulu(x, y, p); }
    2235             : INLINE GEN
    2236        5376 : FqX_sqr(GEN x, GEN T, GEN p)
    2237        5376 : { return T? FpXQX_sqr(x, T, p): FpX_sqr(x, p); }
    2238             : INLINE GEN
    2239        1253 : FqX_powu(GEN x, ulong n, GEN T, GEN p)
    2240        1253 : { return T? FpXQX_powu(x, n, T, p): FpX_powu(x, n, p); }
    2241             : INLINE GEN
    2242           0 : FqX_halve(GEN x, GEN T, GEN p)
    2243           0 : { return T? FpXX_halve(x, p): FpX_halve(x, p); }
    2244             : INLINE GEN
    2245        5131 : FqX_div(GEN x, GEN y, GEN T, GEN p)
    2246        5131 : { return T? FpXQX_divrem(x,y,T,p,NULL): FpX_divrem(x,y,p,NULL); }
    2247             : INLINE GEN
    2248        6074 : FqX_get_red(GEN S, GEN T, GEN p)
    2249        6074 : { return T? FpXQX_get_red(S,T,p): FpX_get_red(S,p); }
    2250             : INLINE GEN
    2251       51407 : FqX_rem(GEN x, GEN y, GEN T, GEN p)
    2252       51407 : { return T? FpXQX_rem(x,y,T,p): FpX_rem(x,y,p); }
    2253             : INLINE GEN
    2254           0 : FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2255           0 : { return T? FpXQX_divrem(x,y,T,p,z): FpX_divrem(x,y,p,z); }
    2256             : INLINE GEN
    2257        5936 : FqX_div_by_X_x(GEN x, GEN y, GEN T, GEN p, GEN *z)
    2258        5936 : { return T? FpXQX_div_by_X_x(x,y,T,p,z): FpX_div_by_X_x(x,y,p,z); }
    2259             : INLINE GEN
    2260           0 : FqX_halfgcd(GEN P,GEN Q,GEN T,GEN p)
    2261           0 : {return T? FpXQX_halfgcd(P,Q,T,p): FpX_halfgcd(P,Q,p);}
    2262             : INLINE GEN
    2263      258538 : FqX_gcd(GEN P,GEN Q,GEN T,GEN p)
    2264      258538 : {return T? FpXQX_gcd(P,Q,T,p): FpX_gcd(P,Q,p);}
    2265             : INLINE GEN
    2266       86086 : FqX_extgcd(GEN P,GEN Q,GEN T,GEN p, GEN *U, GEN *V)
    2267       86086 : { return T? FpXQX_extgcd(P,Q,T,p,U,V): FpX_extgcd(P,Q,p,U,V); }
    2268             : INLINE GEN
    2269        2884 : FqX_normalize(GEN z, GEN T, GEN p)
    2270        2884 : { return T? FpXQX_normalize(z, T, p): FpX_normalize(z, p); }
    2271             : INLINE GEN
    2272      271859 : FqX_deriv(GEN f, /*unused*/GEN T, GEN p)
    2273      271859 : { (void)T; return FpXX_deriv(f, p); }
    2274             : INLINE GEN
    2275       74011 : FqX_factor(GEN f, GEN T, GEN p)
    2276       74011 : { return T?FpXQX_factor(f, T, p): FpX_factor(f, p); }
    2277             : INLINE GEN
    2278           7 : FqX_factor_squarefree(GEN f, GEN T, GEN p)
    2279           7 : { return T ? FpXQX_factor_squarefree(f, T, p): FpX_factor_squarefree(f, p); }
    2280             : INLINE GEN
    2281           7 : FqX_ddf(GEN f, GEN T, GEN p)
    2282           7 : { return T ? FpXQX_ddf(f, T, p): FpX_ddf(f, p); }
    2283             : INLINE GEN
    2284          42 : FqX_degfact(GEN f, GEN T, GEN p)
    2285          42 : { return T?FpXQX_degfact(f, T, p): FpX_degfact(f, p); }
    2286             : INLINE GEN
    2287        6860 : FqX_roots(GEN f, GEN T, GEN p)
    2288        6860 : { return T?FpXQX_roots(f, T, p): FpX_roots(f, p); }
    2289             : INLINE GEN
    2290         203 : FqX_to_mod(GEN f, GEN T, GEN p)
    2291         203 : { return T?FpXQX_to_mod(f, T, p): FpX_to_mod(f, p); }
    2292             : 
    2293             : /*FqXQ*/
    2294             : INLINE GEN
    2295           0 : FqXQ_add(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2296           0 : { (void)S; return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
    2297             : INLINE GEN
    2298           0 : FqXQ_sub(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
    2299           0 : { (void)S; return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
    2300             : INLINE GEN
    2301           0 : FqXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p)
    2302           0 : { return T? FpXQXQ_div(x,y,S,T,p): FpXQ_div(x,y,S,p); }
    2303             : INLINE GEN
    2304           0 : FqXQ_inv(GEN x, GEN S, GEN T, GEN p)
    2305           0 : { return T? FpXQXQ_inv(x,S,T,p): FpXQ_inv(x,S,p); }
    2306             : INLINE GEN
    2307           0 : FqXQ_invsafe(GEN x, GEN S, GEN T, GEN p)
    2308           0 : { return T? FpXQXQ_invsafe(x,S,T,p): FpXQ_inv(x,S,p); }
    2309             : INLINE GEN
    2310       22327 : FqXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p)
    2311       22327 : { return T? FpXQXQ_mul(x,y,S,T,p): FpXQ_mul(x,y,S,p); }
    2312             : INLINE GEN
    2313           0 : FqXQ_sqr(GEN x, GEN S, GEN T, GEN p)
    2314           0 : { return T? FpXQXQ_sqr(x,S,T,p): FpXQ_sqr(x,S,p); }
    2315             : INLINE GEN
    2316           0 : FqXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p)
    2317           0 : { return T? FpXQXQ_pow(x,n,S,T,p): FpXQ_pow(x,n,S,p); }
    2318             : 
    2319             : /*FqXn*/
    2320             : INLINE GEN
    2321           0 : FqXn_exp(GEN x, long n, GEN T, GEN p)
    2322           0 : { return T? FpXQXn_exp(x,n,T,p): FpXn_exp(x,n,p); }
    2323             : INLINE GEN
    2324           0 : FqXn_inv(GEN x, long n, GEN T, GEN p)
    2325           0 : { return T? FpXQXn_inv(x,n,T,p): FpXn_inv(x,n,p); }
    2326             : INLINE GEN
    2327           0 : FqXn_mul(GEN x, GEN y, long n, GEN T, GEN p)
    2328           0 : { return T? FpXQXn_mul(x, y, n, T, p): FpXn_mul(x, y, n, p); }
    2329             : INLINE GEN
    2330           0 : FqXn_sqr(GEN x, long n, GEN T, GEN p)
    2331           0 : { return T? FpXQXn_sqr(x,n,T,p): FpXn_sqr(x,n,p); }
    2332             : 
    2333             : /*FpXQ*/
    2334             : INLINE GEN
    2335           0 : FpXQ_add(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2336           0 : { (void)T; return FpX_add(x,y,p); }
    2337             : INLINE GEN
    2338           0 : FpXQ_sub(GEN x,GEN y,GEN T/*unused*/,GEN p)
    2339           0 : { (void)T; return FpX_sub(x,y,p); }
    2340             : 
    2341             : /*Flxq*/
    2342             : INLINE GEN
    2343           0 : Flxq_add(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2344           0 : { (void)T; return Flx_add(x,y,p); }
    2345             : INLINE GEN
    2346           0 : Flxq_sub(GEN x,GEN y,GEN T/*unused*/,ulong p)
    2347           0 : { (void)T; return Flx_sub(x,y,p); }
    2348             : 
    2349             : /* F2x */
    2350             : 
    2351             : INLINE ulong
    2352   163961724 : F2x_coeff(GEN x,long v)
    2353             : {
    2354   163961724 :    ulong u=(ulong)x[2+divsBIL(v)];
    2355   163961088 :    return (u>>remsBIL(v))&1UL;
    2356             : }
    2357             : 
    2358             : INLINE void
    2359     4637846 : F2x_clear(GEN x,long v)
    2360             : {
    2361     4637846 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2362     4637845 :    *u&=~(1UL<<remsBIL(v));
    2363     4637845 : }
    2364             : 
    2365             : INLINE void
    2366    36511010 : F2x_set(GEN x,long v)
    2367             : {
    2368    36511010 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2369    36509517 :    *u|=1UL<<remsBIL(v);
    2370    36508579 : }
    2371             : 
    2372             : INLINE void
    2373     1496909 : F2x_flip(GEN x,long v)
    2374             : {
    2375     1496909 :    ulong* u=(ulong*)&x[2+divsBIL(v)];
    2376     1496909 :    *u^=1UL<<remsBIL(v);
    2377     1496909 : }
    2378             : 
    2379             : /* F2v */
    2380             : 
    2381             : INLINE ulong
    2382   157397665 : F2v_coeff(GEN x,long v) { return F2x_coeff(x,v-1); }
    2383             : 
    2384             : INLINE void
    2385     4637846 : F2v_clear(GEN x,long v) { F2x_clear(x,v-1); }
    2386             : 
    2387             : INLINE void
    2388    11915376 : F2v_set(GEN x,long v)   { F2x_set(x,v-1); }
    2389             : 
    2390             : INLINE void
    2391     1496909 : F2v_flip(GEN x,long v) { F2x_flip(x,v-1); }
    2392             : 
    2393             : /* F2m */
    2394             : 
    2395             : INLINE ulong
    2396    17632443 : F2m_coeff(GEN x, long a, long b) { return F2v_coeff(gel(x,b), a); }
    2397             : 
    2398             : INLINE void
    2399           0 : F2m_clear(GEN x, long a, long b) { F2v_clear(gel(x,b), a); }
    2400             : 
    2401             : INLINE void
    2402     2032155 : F2m_set(GEN x, long a, long b) { F2v_set(gel(x,b), a); }
    2403             : 
    2404             : INLINE void
    2405     1496909 : F2m_flip(GEN x, long a, long b) { F2v_flip(gel(x,b), a); }
    2406             : 
    2407             : /* ARITHMETIC */
    2408             : INLINE GEN
    2409        1071 : matpascal(long n) { return matqpascal(n, NULL); }
    2410             : INLINE long
    2411     2315175 : Z_issquare(GEN x) { return Z_issquareall(x, NULL); }
    2412             : INLINE long
    2413          14 : Z_ispower(GEN x, ulong k) { return Z_ispowerall(x, k, NULL); }
    2414             : INLINE GEN
    2415     5592082 : sqrti(GEN x) { return sqrtremi(x,NULL); }
    2416             : INLINE GEN
    2417     4056082 : gaddgs(GEN y, long s) { return gaddsg(s,y); }
    2418             : INLINE int
    2419       25983 : gcmpgs(GEN y, long s) { return -gcmpsg(s,y); }
    2420             : INLINE int
    2421       24479 : gequalgs(GEN y, long s) { return gequalsg(s,y); }
    2422             : INLINE GEN
    2423           0 : gmaxsg(long s, GEN y) { return gmaxgs(y,s); }
    2424             : INLINE GEN
    2425           0 : gminsg(long s, GEN y) { return gmings(y,s); }
    2426             : INLINE GEN
    2427    13930594 : gmulgs(GEN y, long s) { return gmulsg(s,y); }
    2428             : INLINE GEN
    2429     1102645 : gsubgs(GEN y, long s) { return gaddgs(y, -s); }
    2430             : INLINE GEN
    2431      583877 : gdivsg(long s, GEN y) { return gdiv(stoi(s), y); }
    2432             : 
    2433             : /* x t_COMPLEX */
    2434             : INLINE GEN
    2435    10603075 : cxnorm(GEN x) { return gadd(gsqr(gel(x,1)), gsqr(gel(x,2))); }
    2436             : /* q t_QUAD */
    2437             : INLINE GEN
    2438         623 : quadnorm(GEN q)
    2439             : {
    2440         623 :   GEN X = gel(q,1), b = gel(X,3), c = gel(X,2);
    2441         623 :   GEN z, u = gel(q,3), v = gel(q,2);
    2442         623 :   if (typ(u) == t_INT && typ(v) == t_INT) /* generic case */
    2443             :   {
    2444         308 :     z = signe(b)? mulii(v, addii(u,v)): sqri(v);
    2445         308 :     return addii(z, mulii(c, sqri(u)));
    2446             :   }
    2447             :   else
    2448             :   {
    2449         315 :     z = signe(b)? gmul(v, gadd(u,v)): gsqr(v);
    2450         315 :     return gadd(z, gmul(c, gsqr(u)));
    2451             :   }
    2452             : }
    2453             : /* x a t_QUAD, return the attached discriminant */
    2454             : INLINE GEN
    2455         273 : quad_disc(GEN x)
    2456             : {
    2457         273 :   GEN Q = gel(x,1), b = gel(Q,3), c = gel(Q,2), c4;
    2458         273 :   if (is_pm1(b))
    2459             :   {
    2460         217 :     pari_sp av = avma; (void)new_chunk(lgefint(c) + 1);
    2461         217 :     c4 = shifti(c,2); avma = av; return subsi(1, c4);
    2462             :   }
    2463          56 :   c4 = shifti(c,2); togglesign_safe(&c4); return c4;
    2464             : }
    2465             : INLINE GEN
    2466     6462113 : qfb_disc3(GEN x, GEN y, GEN z) { return subii(sqri(y), shifti(mulii(x,z),2)); }
    2467             : INLINE GEN
    2468     6381263 : qfb_disc(GEN x) { return qfb_disc3(gel(x,1), gel(x,2), gel(x,3)); }
    2469             : 
    2470             : INLINE GEN
    2471     1244597 : sqrfrac(GEN x)
    2472             : {
    2473     1244597 :   GEN z = cgetg(3,t_FRAC);
    2474     1244597 :   gel(z,1) = sqri(gel(x,1));
    2475     1244597 :   gel(z,2) = sqri(gel(x,2)); return z;
    2476             : }
    2477             : 
    2478             : INLINE void
    2479    11700161 : normalize_frac(GEN z) {
    2480    11700161 :   if (signe(gel(z,2)) < 0) { togglesign(gel(z,1)); setabssign(gel(z,2)); }
    2481    11700161 : }
    2482             : 
    2483             : INLINE GEN
    2484      231888 : powii(GEN x, GEN n)
    2485             : {
    2486      231888 :   long ln = lgefint(n);
    2487      231888 :   if (ln == 3) {
    2488             :     GEN z;
    2489      228626 :     if (signe(n) > 0) return powiu(x, n[2]);
    2490        4984 :     z = cgetg(3, t_FRAC);
    2491        4984 :     gel(z,1) = gen_1;
    2492        4984 :     gel(z,2) = powiu(x, n[2]);
    2493        4984 :     return z;
    2494             :   }
    2495        3262 :   if (ln == 2) return gen_1; /* rare */
    2496             :   /* should never happen */
    2497           0 :   return powgi(x, n); /* overflow unless x = 0, 1, -1 */
    2498             : }
    2499             : INLINE GEN
    2500        1176 : powIs(long n) {
    2501        1176 :   switch(n & 3)
    2502             :   {
    2503          14 :     case 1: return mkcomplex(gen_0,gen_1);
    2504         364 :     case 2: return gen_m1;
    2505         490 :     case 3: return mkcomplex(gen_0,gen_m1);
    2506             :   }
    2507         308 :   return gen_1;
    2508             : }
    2509             : 
    2510             : /*******************************************************************/
    2511             : /*                                                                 */
    2512             : /*                             ASSIGNMENTS                         */
    2513             : /*                                                                 */
    2514             : /*******************************************************************/
    2515           0 : INLINE void mpexpz(GEN x, GEN z)
    2516           0 : { pari_sp av = avma; gaffect(mpexp(x), z); avma = av; }
    2517           0 : INLINE void mplogz(GEN x, GEN z)
    2518           0 : { pari_sp av = avma; gaffect(mplog(x), z); avma = av; }
    2519           0 : INLINE void mpcosz(GEN x, GEN z)
    2520           0 : { pari_sp av = avma; gaffect(mpcos(x), z); avma = av; }
    2521           0 : INLINE void mpsinz(GEN x, GEN z)
    2522           0 : { pari_sp av = avma; gaffect(mpsin(x), z); avma = av; }
    2523           0 : INLINE void gnegz(GEN x, GEN z)
    2524           0 : { pari_sp av = avma; gaffect(gneg(x), z); avma = av; }
    2525           0 : INLINE void gabsz(GEN x, long prec, GEN z)
    2526           0 : { pari_sp av = avma; gaffect(gabs(x,prec), z); avma = av; }
    2527       23318 : INLINE void gaddz(GEN x, GEN y, GEN z)
    2528       23318 : { pari_sp av = avma; gaffect(gadd(x,y), z); avma = av; }
    2529           0 : INLINE void gsubz(GEN x, GEN y, GEN z)
    2530           0 : { pari_sp av = avma; gaffect(gsub(x,y), z); avma = av; }
    2531       11673 : INLINE void gmulz(GEN x, GEN y, GEN z)
    2532       11673 : { pari_sp av = avma; gaffect(gmul(x,y), z); avma = av; }
    2533           0 : INLINE void gdivz(GEN x, GEN y, GEN z)
    2534           0 : { pari_sp av = avma; gaffect(gdiv(x,y), z); avma = av; }
    2535           0 : INLINE void gdiventz(GEN x, GEN y, GEN z)
    2536           0 : { pari_sp av = avma; gaffect(gdivent(x,y), z); avma = av; }
    2537           0 : INLINE void gmodz(GEN x, GEN y, GEN z)
    2538           0 : { pari_sp av = avma; gaffect(gmod(x,y), z); avma = av; }
    2539           0 : INLINE void gmul2nz(GEN x, long s, GEN z)
    2540           0 : { pari_sp av = avma; gaffect(gmul2n(x,s), z); avma = av; }
    2541           0 : INLINE void gshiftz(GEN x, long s, GEN z)
    2542           0 : { pari_sp av = avma; gaffect(gshift(x,s), z); avma = av; }
    2543             : 
    2544             : /*******************************************************************/
    2545             : /*                                                                 */
    2546             : /*                       ELLIPTIC CURVES                           */
    2547             : /*                                                                 */
    2548             : /*******************************************************************/
    2549     3978331 : INLINE GEN ell_get_a1(GEN e) { return gel(e,1); }
    2550     3094727 : INLINE GEN ell_get_a2(GEN e) { return gel(e,2); }
    2551     3860746 : INLINE GEN ell_get_a3(GEN e) { return gel(e,3); }
    2552     3887702 : INLINE GEN ell_get_a4(GEN e) { return gel(e,4); }
    2553     4704105 : INLINE GEN ell_get_a6(GEN e) { return gel(e,5); }
    2554     3317184 : INLINE GEN ell_get_b2(GEN e) { return gel(e,6); }
    2555     1023710 : INLINE GEN ell_get_b4(GEN e) { return gel(e,7); }
    2556     1629413 : INLINE GEN ell_get_b6(GEN e) { return gel(e,8); }
    2557     1463875 : INLINE GEN ell_get_b8(GEN e) { return gel(e,9); }
    2558     6095274 : INLINE GEN ell_get_c4(GEN e) { return gel(e,10); }
    2559     7331454 : INLINE GEN ell_get_c6(GEN e) { return gel(e,11); }
    2560     9580666 : INLINE GEN ell_get_disc(GEN e) { return gel(e,12); }
    2561     1028006 : INLINE GEN ell_get_j(GEN e) { return gel(e,13); }
    2562    11245647 : INLINE long ell_get_type(GEN e) { return mael(e,14,1); }
    2563     1570338 : INLINE GEN ellff_get_field(GEN x) { return gmael(x, 15, 1); }
    2564      683257 : INLINE GEN ellff_get_a4a6(GEN x)  { return gmael(x, 15, 2); }
    2565        1407 : INLINE GEN ellQp_get_zero(GEN x) { return gmael(x, 15, 1); }
    2566         287 : INLINE long ellQp_get_prec(GEN E) { GEN z = ellQp_get_zero(E); return valp(z); }
    2567        1085 : INLINE GEN ellQp_get_p(GEN E) { GEN z = ellQp_get_zero(E); return gel(z,2); }
    2568       37030 : INLINE long ellR_get_prec(GEN x) { return nbits2prec(mael3(x, 15, 1, 1)); }
    2569       11784 : INLINE long ellR_get_sign(GEN x) { return mael3(x, 15, 1, 2); }
    2570      699426 : INLINE GEN ellnf_get_nf(GEN x) { return checknf_i(gmael(x,15,1)); }
    2571          56 : INLINE GEN ellnf_get_bnf(GEN x) { return checkbnf_i(gmael(x,15,1)); }
    2572             : 
    2573    33820774 : INLINE int ell_is_inf(GEN z) { return lg(z) == 2; }
    2574      808351 : INLINE GEN ellinf(void) { return mkvec(gen_0); }
    2575             : 
    2576             : /*******************************************************************/
    2577             : /*                                                                 */
    2578             : /*                    ALGEBRAIC NUMBER THEORY                      */
    2579             : /*                                                                 */
    2580             : /*******************************************************************/
    2581     8129700 : INLINE GEN modpr_get_pr(GEN x)  { return gel(x,3); }
    2582      609532 : INLINE GEN modpr_get_p(GEN x)  { return pr_get_p(modpr_get_pr(x)); }
    2583     2521859 : INLINE GEN modpr_get_T(GEN x)  { return lg(x) == 4? NULL: gel(x,4); }
    2584             : 
    2585    18533404 : INLINE GEN pr_get_p(GEN pr)  { return gel(pr,1); }
    2586     4841832 : INLINE GEN pr_get_gen(GEN pr){ return gel(pr,2); }
    2587             : /* .[2] instead of itos works: e and f are small positive integers */
    2588     2233866 : INLINE long pr_get_e(GEN pr) { return gel(pr,3)[2]; }
    2589     7881687 : INLINE long pr_get_f(GEN pr) { return gel(pr,4)[2]; }
    2590     6033559 : INLINE GEN pr_get_tau(GEN pr){ return gel(pr,5); }
    2591             : INLINE int
    2592     2342455 : pr_is_inert(GEN P) { return pr_get_f(P) == lg(pr_get_gen(P))-1; }
    2593             : INLINE GEN
    2594      206144 : pr_norm(GEN pr) { return powiu(pr_get_p(pr), pr_get_f(pr)); }
    2595             : INLINE ulong
    2596       40852 : upr_norm(GEN pr) { return upowuu(pr_get_p(pr)[2], pr_get_f(pr)); }
    2597             : 
    2598             : /* assume nf a genuine nf */
    2599             : INLINE long
    2600        4255 : nf_get_varn(GEN nf) { return varn(gel(nf,1)); }
    2601             : INLINE GEN
    2602    27176837 : nf_get_pol(GEN nf) { return gel(nf,1); }
    2603             : INLINE long
    2604    21304510 : nf_get_degree(GEN nf) { return degpol( nf_get_pol(nf) ); }
    2605             : INLINE long
    2606     1273596 : nf_get_r1(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,1)); }
    2607             : INLINE long
    2608        2373 : nf_get_r2(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,2)); }
    2609             : INLINE GEN
    2610       48545 : nf_get_disc(GEN nf) { return gel(nf,3); }
    2611             : INLINE GEN
    2612      752009 : nf_get_index(GEN nf) { return gel(nf,4); }
    2613             : INLINE GEN
    2614     1217179 : nf_get_M(GEN nf) { return gmael(nf,5,1); }
    2615             : INLINE GEN
    2616       61728 : nf_get_G(GEN nf) { return gmael(nf,5,2); }
    2617             : INLINE GEN
    2618      434973 : nf_get_roundG(GEN nf) { return gmael(nf,5,3); }
    2619             : INLINE GEN
    2620       24332 : nf_get_Tr(GEN nf) { return gmael(nf,5,4); }
    2621             : INLINE GEN
    2622        2233 : nf_get_diff(GEN nf) { return gmael(nf,5,5); }
    2623             : INLINE GEN
    2624          49 : nf_get_ramified_primes(GEN nf) { return gmael(nf,5,8); }
    2625             : INLINE GEN
    2626      160806 : nf_get_roots(GEN nf) { return gel(nf,6); }
    2627             : INLINE GEN
    2628          84 : nf_get_zk(GEN nf)
    2629             : {
    2630          84 :   GEN y = gel(nf,7), D = gel(y, 1);
    2631          84 :   if (typ(D) == t_POL) D = gel(D, 2);
    2632          84 :   if (!equali1(D)) y = gdiv(y, D);
    2633          84 :   return y;
    2634             : }
    2635             : INLINE GEN
    2636      221801 : nf_get_zkprimpart(GEN nf)
    2637             : {
    2638      221801 :   GEN y = gel(nf,7);
    2639             :   /* test for old format of nf.zk: non normalized */
    2640      221801 :   if (!equali1(gel(nf,4)) && gequal1(gel(y,1))) y = Q_remove_denom(y,NULL);
    2641      221801 :   return y;
    2642             : }
    2643             : INLINE GEN
    2644      224329 : nf_get_zkden(GEN nf)
    2645             : {
    2646      224329 :   GEN y = gel(nf,7), D = gel(y,1);
    2647      224329 :   if (typ(D) == t_POL) D = gel(D,2);
    2648             :   /* test for old format of nf.zk: non normalized */
    2649      224329 :   if (!equali1(gel(nf,4)) && equali1(D)) D = Q_denom(y);
    2650      224329 :   return D;
    2651             : }
    2652             : INLINE GEN
    2653     2187404 : nf_get_invzk(GEN nf) { return gel(nf,8); }
    2654             : INLINE void
    2655       19490 : nf_get_sign(GEN nf, long *r1, long *r2)
    2656             : {
    2657       19490 :   GEN x = gel(nf,2);
    2658       19490 :   *r1 = itou(gel(x,1));
    2659       19490 :   *r2 = itou(gel(x,2));
    2660       19490 : }
    2661             : 
    2662             : INLINE GEN
    2663       49693 : abgrp_get_no(GEN x) { return gel(x,1); }
    2664             : INLINE GEN
    2665     2090291 : abgrp_get_cyc(GEN x) { return gel(x,2); }
    2666             : INLINE GEN
    2667      395644 : abgrp_get_gen(GEN x) { return gel(x,3); }
    2668             : INLINE GEN
    2669     2058544 : bnf_get_nf(GEN bnf) { return gel(bnf,7); }
    2670             : INLINE GEN
    2671      804315 : bnf_get_clgp(GEN bnf) { return gmael(bnf,8,1); }
    2672             : INLINE GEN
    2673        4613 : bnf_get_no(GEN bnf) { return abgrp_get_no(bnf_get_clgp(bnf)); }
    2674             : INLINE GEN
    2675      433108 : bnf_get_cyc(GEN bnf) { return abgrp_get_cyc(bnf_get_clgp(bnf)); }
    2676             : INLINE GEN
    2677      366265 : bnf_get_gen(GEN bnf)  { return abgrp_get_gen(bnf_get_clgp(bnf)); }
    2678             : INLINE GEN
    2679         860 : bnf_get_reg(GEN bnf) { return gmael(bnf,8,2); }
    2680             : INLINE GEN
    2681      481883 : bnf_get_logfu(GEN bnf) { return gel(bnf,3); }
    2682             : INLINE GEN
    2683        5798 : bnf_get_tuU(GEN bnf) { return gmael3(bnf,8,4,2); }
    2684             : INLINE long
    2685       24584 : bnf_get_tuN(GEN bnf) { return gmael3(bnf,8,4,1)[2]; }
    2686             : INLINE GEN
    2687        1806 : bnf_get_fu(GEN bnf) {
    2688        1806 :   GEN fu = bnf_get_fu_nocheck(bnf);
    2689        1806 :   if (typ(fu) == t_MAT) pari_err(e_MISC,"missing units in bnf");
    2690        1806 :   return fu;
    2691             : }
    2692             : INLINE GEN
    2693        7030 : bnf_get_fu_nocheck(GEN bnf) { return gmael(bnf,8,5); }
    2694             : 
    2695             : INLINE GEN
    2696      744847 : bnr_get_bnf(GEN bnr) { return gel(bnr,1); }
    2697             : INLINE GEN
    2698      383424 : bnr_get_bid(GEN bnr) { return gel(bnr,2); }
    2699             : INLINE GEN
    2700       18123 : bnr_get_mod(GEN bnr) { return gmael(bnr,2,1); }
    2701             : INLINE GEN
    2702       27559 : bnr_get_nf(GEN bnr) { return gmael(bnr,1,7); }
    2703             : INLINE GEN
    2704      515675 : bnr_get_clgp(GEN bnr) { return gel(bnr,5); }
    2705             : INLINE GEN
    2706       45080 : bnr_get_no(GEN bnr) { return abgrp_get_no(bnr_get_clgp(bnr)); }
    2707             : INLINE GEN
    2708      458667 : bnr_get_cyc(GEN bnr) { return abgrp_get_cyc(bnr_get_clgp(bnr)); }
    2709             : INLINE GEN
    2710          70 : bnr_get_gen_nocheck(GEN bnr) { return abgrp_get_gen(bnr_get_clgp(bnr)); }
    2711             : INLINE GEN
    2712       11025 : bnr_get_gen(GEN bnr) {
    2713       11025 :   GEN G = bnr_get_clgp(bnr);
    2714       11025 :   if (lg(G) !=  4)
    2715           0 :     pari_err(e_MISC,"missing bnr generators: please use bnrinit(,,1)");
    2716       11025 :   return gel(G,3);
    2717             : }
    2718             : 
    2719             : INLINE GEN
    2720      301916 : bid_get_mod(GEN bid) { return gel(bid,1); }
    2721             : INLINE GEN
    2722       46144 : bid_get_ideal(GEN bid) { return gmael(bid,1,1); }
    2723             : INLINE GEN
    2724         448 : bid_get_arch(GEN bid) { return gmael(bid,1,2); }
    2725             : INLINE GEN
    2726     1058971 : bid_get_grp(GEN bid) { return gel(bid,2); }
    2727             : INLINE GEN
    2728      395499 : bid_get_fact(GEN bid) { return gmael(bid,3,1); }
    2729             : INLINE GEN
    2730      354024 : bid_get_fact2(GEN bid) { return gmael(bid,3,2); }
    2731             : INLINE GEN
    2732      354094 : bid_get_sprk(GEN bid) { return gmael(bid,4,1); }
    2733             : INLINE GEN
    2734       29911 : bid_get_sarch(GEN bid) { return gmael(bid,4,2); }
    2735             : INLINE GEN
    2736      374716 : bid_get_archp(GEN bid) { return gmael3(bid,4,2,2); }
    2737             : INLINE GEN
    2738      656220 : bid_get_U(GEN bid) { return gel(bid,5); }
    2739             : INLINE GEN
    2740           0 : bid_get_no(GEN bid) { return abgrp_get_no(bid_get_grp(bid)); }
    2741             : INLINE GEN
    2742     1030558 : bid_get_cyc(GEN bid) { return abgrp_get_cyc(bid_get_grp(bid)); }
    2743             : INLINE GEN
    2744           0 : bid_get_gen_nocheck(GEN bid)  { return abgrp_get_gen(bid_get_grp(bid)); }
    2745             : INLINE GEN
    2746       27818 : bid_get_gen(GEN bid) {
    2747       27818 :   GEN G = bid_get_grp(bid);
    2748       27818 :   if (lg(G) != 4) pari_err(e_MISC,"missing bid generators. Use idealstar(,,2)");
    2749       27818 :   return abgrp_get_gen(G);
    2750             : }
    2751             : 
    2752             : INLINE GEN
    2753     8685201 : znstar_get_N(GEN G) { return gmael(G,1,1); }
    2754             : INLINE GEN
    2755     2079385 : znstar_get_faN(GEN G) { return gel(G,3); }
    2756             : INLINE GEN
    2757           0 : znstar_get_no(GEN G) { return abgrp_get_no(gel(G,2)); }
    2758             : INLINE GEN
    2759      166544 : znstar_get_cyc(GEN G) { return abgrp_get_cyc(gel(G,2)); }
    2760             : INLINE GEN
    2761           0 : znstar_get_gen(GEN G) { return abgrp_get_gen(gel(G,2)); }
    2762             : INLINE GEN
    2763     2753401 : znstar_get_conreycyc(GEN G) { return gmael(G,4,5); }
    2764             : INLINE GEN
    2765      823186 : znstar_get_conreygen(GEN G) { return gmael(G,4,4); }
    2766             : INLINE GEN
    2767       28357 : znstar_get_Ui(GEN G) { return gmael(G,4,3); }
    2768             : INLINE GEN
    2769      117943 : znstar_get_U(GEN G) { return gel(G,5); }
    2770             : INLINE GEN
    2771      463463 : znstar_get_pe(GEN G) { return gmael(G,4,1); }
    2772             : INLINE GEN
    2773       19194 : gal_get_pol(GEN gal) { return gel(gal,1); }
    2774             : INLINE GEN
    2775        1309 : gal_get_p(GEN gal) { return gmael(gal,2,1); }
    2776             : INLINE GEN
    2777         105 : gal_get_e(GEN gal) { return gmael(gal,2,2); }
    2778             : INLINE GEN
    2779       15673 : gal_get_mod(GEN gal) { return gmael(gal,2,3); }
    2780             : INLINE GEN
    2781       16051 : gal_get_roots(GEN gal) { return gel(gal,3); }
    2782             : INLINE GEN
    2783       15673 : gal_get_invvdm(GEN gal) { return gel(gal,4); }
    2784             : INLINE GEN
    2785       15673 : gal_get_den(GEN gal) { return gel(gal,5); }
    2786             : INLINE GEN
    2787       65072 : gal_get_group(GEN gal) { return gel(gal,6); }
    2788             : INLINE GEN
    2789        1708 : gal_get_gen(GEN gal) { return gel(gal,7); }
    2790             : INLINE GEN
    2791        1358 : gal_get_orders(GEN gal) { return gel(gal,8); }
    2792             : 
    2793             : /* assume rnf a genuine rnf */
    2794             : INLINE long
    2795      628453 : rnf_get_degree(GEN rnf) { return degpol(rnf_get_pol(rnf)); }
    2796             : INLINE long
    2797       15386 : rnf_get_nfdegree(GEN rnf) { return degpol(nf_get_pol(rnf_get_nf(rnf))); }
    2798             : INLINE long
    2799      460194 : rnf_get_absdegree(GEN rnf) { return degpol(gmael(rnf,11,1)); }
    2800             : INLINE GEN
    2801         476 : rnf_get_idealdisc(GEN rnf) { return gmael(rnf,3,1); }
    2802             : INLINE GEN
    2803         448 : rnf_get_k(GEN rnf) { return gmael(rnf,11,3); }
    2804             : INLINE GEN
    2805         448 : rnf_get_alpha(GEN rnf) { return gmael(rnf, 11, 2); }
    2806             : INLINE GEN
    2807      128891 : rnf_get_nf(GEN rnf) { return gel(rnf,10); }
    2808             : INLINE void
    2809        2541 : rnf_get_nfzk(GEN rnf, GEN *b, GEN *cb) {*b=gmael(rnf,2,1); *cb=gmael(rnf,2,2);}
    2810             : INLINE GEN
    2811       95543 : rnf_get_polabs(GEN rnf) { return gmael(rnf,11,1); }
    2812             : INLINE GEN
    2813      783860 : rnf_get_pol(GEN rnf) { return gel(rnf,1); }
    2814             : INLINE GEN
    2815          63 : rnf_get_disc(GEN rnf) { return gel(rnf,3); }
    2816             : INLINE GEN
    2817         105 : rnf_get_index(GEN rnf) { return gel(rnf,4); }
    2818             : INLINE long
    2819           0 : rnf_get_varn(GEN rnf) { return varn(gel(rnf,1)); }
    2820             : INLINE GEN
    2821      108500 : rnf_get_nfpol(GEN rnf) { return gmael(rnf,10,1); }
    2822             : INLINE long
    2823         595 : rnf_get_nfvarn(GEN rnf) { return varn(gmael(rnf,10,1)); }
    2824             : INLINE GEN
    2825        2891 : rnf_get_zk(GEN rnf) { return gel(rnf,7); }
    2826             : INLINE GEN
    2827       35364 : rnf_get_map(GEN rnf) { return gel(rnf,11); }
    2828             : INLINE GEN
    2829        1190 : rnf_get_invzk(GEN rnf) { return gel(rnf,8); }
    2830             : 
    2831             : /* I integral ZM (not HNF), G ZM, rounded Cholesky form of a weighted
    2832             :  * T2 matrix. Reduce I wrt G */
    2833             : INLINE GEN
    2834       13146 : idealpseudored(GEN I, GEN G)
    2835       13146 : { return ZM_mul(I, ZM_lll(ZM_mul(G, I), 0.99, LLL_IM)); }
    2836             : 
    2837             : /* I integral (not necessarily HNF), G ZM, rounded Cholesky form of a weighted
    2838             :  * T2 matrix. Return m in I with T2(m) small */
    2839             : INLINE GEN
    2840      154453 : idealpseudomin(GEN I, GEN G)
    2841             : {
    2842      154453 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2843      154453 :   return ZM_ZC_mul(I, gel(u,1));
    2844             : }
    2845             : /* I, G as in idealpseudomin. Return an irrational m in I with T2(m) small */
    2846             : INLINE GEN
    2847      297226 : idealpseudomin_nonscalar(GEN I, GEN G)
    2848             : {
    2849      297226 :   GEN u = ZM_lll(ZM_mul(G, I), 0.99, LLL_IM);
    2850      297226 :   GEN m = ZM_ZC_mul(I, gel(u,1));
    2851      297226 :   if (ZV_isscalar(m) && lg(u) > 2) m = ZM_ZC_mul(I, gel(u,2));
    2852      297226 :   return m;
    2853             : }
    2854             : 
    2855             : INLINE GEN
    2856          70 : idealred_elt(GEN nf, GEN I) {
    2857          70 :   pari_sp av = avma;
    2858          70 :   GEN u = idealpseudomin(I, nf_get_roundG(nf));
    2859          70 :   return gerepileupto(av, u);
    2860             : }
    2861             : INLINE GEN
    2862      159968 : idealred(GEN nf, GEN I) { return idealred0(nf, I, NULL); }
    2863             : 
    2864             : INLINE GEN
    2865        1309 : idealchineseinit(GEN nf, GEN x)
    2866        1309 : { return idealchinese(nf,x,NULL); }
    2867             : 
    2868             : /*******************************************************************/
    2869             : /*                                                                 */
    2870             : /*                              CLOSURES                           */
    2871             : /*                                                                 */
    2872             : /*******************************************************************/
    2873   265610261 : INLINE long closure_arity(GEN C)          { return ((ulong)C[1])&ARITYBITS; }
    2874    35461127 : INLINE long closure_is_variadic(GEN C) { return !!(((ulong)C[1])&VARARGBITS); }
    2875   229745680 : INLINE const char *closure_codestr(GEN C)  { return GSTR(gel(C,2))-1; }
    2876           0 : INLINE GEN closure_get_code(GEN C)  { return gel(C,2); }
    2877   229698471 : INLINE GEN closure_get_oper(GEN C)  { return gel(C,3); }
    2878   229682476 : INLINE GEN closure_get_data(GEN C)  { return gel(C,4); }
    2879        9132 : INLINE GEN closure_get_dbg(GEN C)   { return gel(C,5); }
    2880       21876 : INLINE GEN closure_get_text(GEN C)  { return gel(C,6); }
    2881     1201319 : INLINE GEN closure_get_frame(GEN C) { return gel(C,7); }
    2882             : 
    2883             : /*******************************************************************/
    2884             : /*                                                                 */
    2885             : /*                               ERRORS                            */
    2886             : /*                                                                 */
    2887             : /*******************************************************************/
    2888             : INLINE long
    2889       51679 : err_get_num(GEN e) { return e[1]; }
    2890             : INLINE GEN
    2891          77 : err_get_compo(GEN e, long i) { return gel(e, i+1); }
    2892             : 
    2893             : INLINE void
    2894          14 : pari_err_BUG(const char *f) { pari_err(e_BUG,f); }
    2895             : INLINE void
    2896           7 : pari_err_CONSTPOL(const char *f) { pari_err(e_CONSTPOL, f); }
    2897             : INLINE void
    2898          63 : pari_err_COPRIME(const char *f, GEN x, GEN y) { pari_err(e_COPRIME, f,x,y); }
    2899             : INLINE void
    2900         487 : pari_err_DIM(const char *f) { pari_err(e_DIM, f); }
    2901             : INLINE void
    2902           0 : pari_err_FILE(const char *f, const char *g) { pari_err(e_FILE, f,g); }
    2903             : INLINE void
    2904          36 : pari_err_FILEDESC(const char *f, long n) { pari_err(e_FILEDESC, f,n); }
    2905             : INLINE void
    2906          42 : pari_err_FLAG(const char *f) { pari_err(e_FLAG,f); }
    2907             : INLINE void
    2908         364 : pari_err_IMPL(const char *f) { pari_err(e_IMPL,f); }
    2909             : INLINE void
    2910       19710 : pari_err_INV(const char *f, GEN x) { pari_err(e_INV,f,x); }
    2911             : INLINE void
    2912          28 : pari_err_IRREDPOL(const char *f, GEN x) { pari_err(e_IRREDPOL, f,x); }
    2913             : INLINE void
    2914        1968 : pari_err_DOMAIN(const char *f, const char *v, const char *op, GEN l, GEN x) { pari_err(e_DOMAIN, f,v,op,l,x); }
    2915             : INLINE void
    2916         245 : pari_err_COMPONENT(const char *f, const char *op, GEN l, GEN x) { pari_err(e_COMPONENT, f,op,l,x); }
    2917             : INLINE void
    2918           0 : pari_err_MAXPRIME(ulong c) { pari_err(e_MAXPRIME, c); }
    2919             : INLINE void
    2920         287 : pari_err_OP(const char *f, GEN x, GEN y) { pari_err(e_OP, f,x,y); }
    2921             : INLINE void
    2922          84 : pari_err_OVERFLOW(const char *f) { pari_err(e_OVERFLOW, f); }
    2923             : INLINE void
    2924         218 : pari_err_PREC(const char *f) { pari_err(e_PREC,f); }
    2925             : INLINE void
    2926           0 : pari_err_PACKAGE(const char *f) { pari_err(e_PACKAGE,f); }
    2927             : INLINE void
    2928          70 : pari_err_PRIME(const char *f, GEN x) { pari_err(e_PRIME, f,x); }
    2929             : INLINE void
    2930         784 : pari_err_MODULUS(const char *f, GEN x, GEN y) { pari_err(e_MODULUS, f,x,y); }
    2931             : INLINE void
    2932          42 : pari_err_ROOTS0(const char *f) { pari_err(e_ROOTS0, f); }
    2933             : INLINE void
    2934          77 : pari_err_SQRTN(const char *f, GEN x) { pari_err(e_SQRTN, f,x); }
    2935             : INLINE void
    2936       12332 : pari_err_TYPE(const char *f, GEN x) { pari_err(e_TYPE, f,x); }
    2937             : INLINE void
    2938        3073 : pari_err_TYPE2(const char *f, GEN x, GEN y) { pari_err(e_TYPE2, f,x,y); }
    2939             : INLINE void
    2940         203 : pari_err_VAR(const char *f, GEN x, GEN y) { pari_err(e_VAR, f,x,y); }
    2941             : INLINE void
    2942         175 : pari_err_PRIORITY(const char *f, GEN x, const char *op, long v)
    2943         175 : { pari_err(e_PRIORITY, f,x,op,v); }

Generated by: LCOV version 1.11