Line data Source code
1 : /* Copyright (C) 2000-2010 The PARI group.
2 :
3 : This file is part of the PARI/GP package.
4 :
5 : PARI/GP is free software; you can redistribute it and/or modify it under the
6 : terms of the GNU General Public License as published by the Free Software
7 : Foundation; either version 2 of the License, or (at your option) any later
8 : version. It is distributed in the hope that it will be useful, but WITHOUT
9 : ANY WARRANTY WHATSOEVER.
10 :
11 : Check the License for details. You should have received a copy of it, along
12 : with the package; see the file 'COPYING'. If not, write to the Free Software
13 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
14 :
15 :
16 : /*********************************************************************/
17 : /* MALLOC/FREE WRAPPERS */
18 : /*********************************************************************/
19 : #define BLOCK_SIGALRM_START \
20 : { \
21 : int block=PARI_SIGINT_block; \
22 : PARI_SIGINT_block = 2; \
23 : MT_SIGINT_BLOCK(block);
24 :
25 : #define BLOCK_SIGINT_START \
26 : { \
27 : int block=PARI_SIGINT_block; \
28 : PARI_SIGINT_block = 1; \
29 : MT_SIGINT_BLOCK(block);
30 :
31 : #define BLOCK_SIGINT_END \
32 : PARI_SIGINT_block = block; \
33 : MT_SIGINT_UNBLOCK(block); \
34 : if (!block && PARI_SIGINT_pending) \
35 : { \
36 : int sig = PARI_SIGINT_pending; \
37 : PARI_SIGINT_pending = 0; \
38 : raise(sig); \
39 : } \
40 : }
41 :
42 : /*******************************************************************/
43 : /* */
44 : /* CONSTRUCTORS */
45 : /* */
46 : /*******************************************************************/
47 : #define retmkfrac(x,y)\
48 : do { GEN _v = cgetg(3, t_FRAC);\
49 : gel(_v,1) = (x);\
50 : gel(_v,2) = (y); return _v; } while(0)
51 : #define retmkrfrac(x,y)\
52 : do { GEN _v = cgetg(3, t_RFRAC);\
53 : gel(_v,1) = (x);\
54 : gel(_v,2) = (y); return _v; } while(0)
55 : #define retmkintmod(x,y)\
56 : do { GEN _v = cgetg(3, t_INTMOD);\
57 : gel(_v,1) = (y);\
58 : gel(_v,2) = (x); return _v; } while(0)
59 : #define retmkcomplex(x,y)\
60 : do { GEN _v = cgetg(3, t_COMPLEX);\
61 : gel(_v,1) = (x);\
62 : gel(_v,2) = (y); return _v; } while(0)
63 : #define retmkpolmod(x,y)\
64 : do { GEN _v = cgetg(3, t_POLMOD);\
65 : gel(_v,1) = (y);\
66 : gel(_v,2) = (x); return _v; } while(0)
67 : #define retmkvec(x)\
68 : do { GEN _v = cgetg(2, t_VEC);\
69 : gel(_v,1) = (x); return _v; } while(0)
70 : #define retmkvec2(x,y)\
71 : do { GEN _v = cgetg(3, t_VEC);\
72 : gel(_v,1) = (x);\
73 : gel(_v,2) = (y); return _v; } while(0)
74 : #define retmkvec3(x,y,z)\
75 : do { GEN _v = cgetg(4, t_VEC);\
76 : gel(_v,1) = (x);\
77 : gel(_v,2) = (y);\
78 : gel(_v,3) = (z); return _v; } while(0)
79 : #define retmkpadic(x,p,pd,e,d)\
80 : do { GEN _v = cgetg(5, t_PADIC);\
81 : _v[1] = evalvalp(e) | evalprecp(d);\
82 : gel(_v,2) = (p);\
83 : gel(_v,3) = (pd);\
84 : gel(_v,4) = (x); return _v; } while(0)
85 : /* x allowed to contain _pd */
86 : #define retmkpadic_i(x,p,pd,e,d)\
87 : do { GEN _v = cgetg(5, t_PADIC), _pd = (pd);\
88 : _v[1] = evalvalp(e) | evalprecp(d);\
89 : gel(_v,2) = (p);\
90 : gel(_v,3) = (_pd);\
91 : gel(_v,4) = (x); return _v; } while(0)
92 : #define retmkqfb(x,y,z,d)\
93 : do { GEN _v = cgetg(5, t_QFB);\
94 : gel(_v,1) = (x);\
95 : gel(_v,2) = (y);\
96 : gel(_v,3) = (z);\
97 : gel(_v,4) = (d); return _v; } while(0)
98 : #define retmkquad(x,y,z)\
99 : do { GEN _v = cgetg(4, t_QUAD);\
100 : gel(_v,1) = (x);\
101 : gel(_v,2) = (y);\
102 : gel(_v,3) = (z); return _v; } while(0)
103 : #define retmkvec4(x,y,z,t)\
104 : do { GEN _v = cgetg(5, t_VEC);\
105 : gel(_v,1) = (x);\
106 : gel(_v,2) = (y);\
107 : gel(_v,3) = (z);\
108 : gel(_v,4) = (t); return _v; } while(0)
109 : #define retmkvec5(x,y,z,t,u)\
110 : do { GEN _v = cgetg(6, t_VEC);\
111 : gel(_v,1) = (x);\
112 : gel(_v,2) = (y);\
113 : gel(_v,3) = (z);\
114 : gel(_v,4) = (t);\
115 : gel(_v,5) = (u); return _v; } while(0)
116 : #define retmkcol(x)\
117 : do { GEN _v = cgetg(2, t_COL);\
118 : gel(_v,1) = (x); return _v; } while(0)
119 : #define retmkcol2(x,y)\
120 : do { GEN _v = cgetg(3, t_COL);\
121 : gel(_v,1) = (x);\
122 : gel(_v,2) = (y); return _v; } while(0)
123 : #define retmkcol3(x,y,z)\
124 : do { GEN _v = cgetg(4, t_COL);\
125 : gel(_v,1) = (x);\
126 : gel(_v,2) = (y);\
127 : gel(_v,3) = (z); return _v; } while(0)
128 : #define retmkcol4(x,y,z,t)\
129 : do { GEN _v = cgetg(5, t_COL);\
130 : gel(_v,1) = (x);\
131 : gel(_v,2) = (y);\
132 : gel(_v,3) = (z);\
133 : gel(_v,4) = (t); return _v; } while(0)
134 : #define retmkcol5(x,y,z,t,u)\
135 : do { GEN _v = cgetg(6, t_COL);\
136 : gel(_v,1) = (x);\
137 : gel(_v,2) = (y);\
138 : gel(_v,3) = (z);\
139 : gel(_v,4) = (t);\
140 : gel(_v,5) = (u); return _v; } while(0)
141 : #define retmkcol6(x,y,z,t,u,v)\
142 : do { GEN _v = cgetg(7, t_COL);\
143 : gel(_v,1) = (x);\
144 : gel(_v,2) = (y);\
145 : gel(_v,3) = (z);\
146 : gel(_v,4) = (t);\
147 : gel(_v,5) = (u);\
148 : gel(_v,6) = (v); return _v; } while(0)
149 : #define retmkmat(x)\
150 : do { GEN _v = cgetg(2, t_MAT);\
151 : gel(_v,1) = (x); return _v; } while(0)
152 : #define retmkmat2(x,y)\
153 : do { GEN _v = cgetg(3, t_MAT);\
154 : gel(_v,1) = (x);\
155 : gel(_v,2) = (y); return _v; } while(0)
156 : #define retmkmat3(x,y,z)\
157 : do { GEN _v = cgetg(4, t_MAT);\
158 : gel(_v,1) = (x);\
159 : gel(_v,2) = (y);\
160 : gel(_v,3) = (z); return _v; } while(0)
161 : #define retmkmat4(x,y,z,t)\
162 : do { GEN _v = cgetg(5, t_MAT);\
163 : gel(_v,1) = (x);\
164 : gel(_v,2) = (y);\
165 : gel(_v,3) = (z);\
166 : gel(_v,4) = (t); return _v; } while(0)
167 : #define retmkmat5(x,y,z,t,u)\
168 : do { GEN _v = cgetg(6, t_MAT);\
169 : gel(_v,1) = (x);\
170 : gel(_v,2) = (y);\
171 : gel(_v,3) = (z);\
172 : gel(_v,4) = (t);\
173 : gel(_v,5) = (u); return _v; } while(0)
174 : #define retmkmat22(a,b,c,d)\
175 : do { GEN _v = cgetg(3, t_MAT);\
176 : gel(_v,1) = mkcol2(a,c);\
177 : gel(_v,2) = mkcol2(b,d); return _v; } while(0)
178 : INLINE GEN
179 8092607 : mkintmod(GEN x, GEN y) { retmkintmod(x,y); }
180 : INLINE GEN
181 1813 : mkintmodu(ulong x, ulong y) {
182 1813 : GEN v = cgetg(3,t_INTMOD);
183 1813 : gel(v,1) = utoipos(y);
184 1813 : gel(v,2) = utoi(x); return v;
185 : }
186 : INLINE GEN
187 2009 : mkpadic(GEN x, GEN p, GEN pd, long e, long d) { retmkpadic(x,p,pd,e,d); }
188 : INLINE GEN
189 3105019 : mkpolmod(GEN x, GEN y) { retmkpolmod(x,y); }
190 : INLINE GEN
191 41639611 : mkfrac(GEN x, GEN y) { retmkfrac(x,y); }
192 : INLINE GEN
193 1209563 : mkfracss(long x, long y) { retmkfrac(stoi(x),utoipos(y)); }
194 : /* q = n/d a t_FRAC or t_INT; recover (n,d) */
195 : INLINE void
196 35322 : Qtoss(GEN q, long *n, long *d)
197 : {
198 35322 : if (typ(q) == t_INT) { *n = itos(q); *d = 1; }
199 5796 : else { *n = itos(gel(q,1)); *d = itou(gel(q,2)); }
200 35322 : }
201 : INLINE GEN
202 1097215 : sstoQ(long n, long d)
203 : {
204 : ulong r;
205 : long g, q;
206 1097215 : if (!n)
207 : {
208 117936 : if (!d) pari_err_INV("sstoQ",gen_0);
209 117936 : return gen_0;
210 : }
211 979279 : if (d < 0) { d = -d; n = -n; }
212 979279 : if (d == 1) return stoi(n);
213 959945 : r = labs(n);
214 959945 : if (r == 1) retmkfrac(n > 0? gen_1: gen_m1, utoipos(d));
215 909825 : q = udivuu_rem(r, d, &r);
216 909825 : if (!r) return n > 0? utoipos(q): utoineg(q);
217 854952 : g = ugcd(d,r); /* gcd(n,d) */
218 854952 : if (g != 1) { n /= g; d /= g; }
219 854952 : retmkfrac(stoi(n), utoipos(d));
220 : }
221 :
222 : INLINE GEN
223 1600142 : uutoQ(ulong n, ulong d)
224 : {
225 : ulong r;
226 : long g, q;
227 1600142 : if (!n)
228 : {
229 595 : if (!d) pari_err_INV("uutoQ",gen_0);
230 595 : return gen_0;
231 : }
232 1599547 : if (d == 1) return utoipos(n);
233 1588445 : if (n == 1) retmkfrac(gen_1, utoipos(d));
234 1499433 : q = udivuu_rem(n,d,&r);
235 1499433 : if (!r) return utoipos(q);
236 1259347 : g = ugcd(d,r); /* gcd(n,d) */
237 1259347 : if (g != 1) { n /= g; d /= g; }
238 1259347 : retmkfrac(utoipos(n), utoipos(d));
239 : }
240 :
241 : INLINE GEN
242 4999065 : mkfraccopy(GEN x, GEN y) { retmkfrac(icopy(x), icopy(y)); }
243 : INLINE GEN
244 698152 : mkrfrac(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
245 698152 : gel(v,1) = x; gel(v,2) = y; return v; }
246 : INLINE GEN
247 14 : mkrfraccopy(GEN x, GEN y) { GEN v = cgetg(3, t_RFRAC);
248 14 : gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
249 : INLINE GEN
250 91629046 : mkcomplex(GEN x, GEN y) { retmkcomplex(x,y); }
251 : INLINE GEN
252 1269787 : gen_I(void) { return mkcomplex(gen_0, gen_1); }
253 : INLINE GEN
254 975621 : cgetc(long l) { retmkcomplex(cgetr(l), cgetr(l)); }
255 : INLINE GEN
256 69118 : mkquad(GEN n, GEN x, GEN y) { GEN v = cgetg(4, t_QUAD);
257 69118 : gel(v,1) = n; gel(v,2) = x; gel(v,3) = y; return v; }
258 : /* vecsmall */
259 : INLINE GEN
260 131674139 : mkvecsmall(long x) { GEN v = cgetg(2, t_VECSMALL); v[1] = x; return v; }
261 : INLINE GEN
262 233617551 : mkvecsmall2(long x,long y) { GEN v = cgetg(3, t_VECSMALL);
263 233630189 : v[1]=x; v[2]=y; return v; }
264 : INLINE GEN
265 104053359 : mkvecsmall3(long x,long y,long z) { GEN v = cgetg(4, t_VECSMALL);
266 104049752 : v[1]=x; v[2]=y; v[3]=z; return v; }
267 : INLINE GEN
268 17839005 : mkvecsmall4(long x,long y,long z,long t) { GEN v = cgetg(5, t_VECSMALL);
269 17840776 : v[1]=x; v[2]=y; v[3]=z; v[4]=t; return v; }
270 : INLINE GEN
271 1730599 : mkvecsmall5(long x,long y,long z,long t,long u) { GEN v = cgetg(6, t_VECSMALL);
272 1730598 : v[1]=x; v[2]=y; v[3]=z; v[4]=t; v[5]=u; return v; }
273 :
274 : INLINE GEN
275 27919516 : mkqfb(GEN x, GEN y, GEN z, GEN d) { retmkqfb(x,y,z,d); }
276 : /* vec */
277 : INLINE GEN
278 71146285 : mkvec(GEN x) { retmkvec(x); }
279 : INLINE GEN
280 186421181 : mkvec2(GEN x, GEN y) { retmkvec2(x,y); }
281 : INLINE GEN
282 117685208 : mkvec3(GEN x, GEN y, GEN z) { retmkvec3(x,y,z); }
283 : INLINE GEN
284 10105909 : mkvec4(GEN x, GEN y, GEN z, GEN t) { retmkvec4(x,y,z,t); }
285 : INLINE GEN
286 15184920 : mkvec5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkvec5(x,y,z,t,u); }
287 : INLINE GEN
288 168 : mkvecs(long x) { retmkvec(stoi(x)); }
289 : INLINE GEN
290 220418 : mkvec2s(long x, long y) { retmkvec2(stoi(x),stoi(y)); }
291 : INLINE GEN
292 524441 : mkvec3s(long x, long y, long z) { retmkvec3(stoi(x),stoi(y),stoi(z)); }
293 : INLINE GEN
294 21 : mkvec4s(long x, long y, long z, long t) { retmkvec4(stoi(x),stoi(y),stoi(z),stoi(t)); }
295 : INLINE GEN
296 122521 : mkveccopy(GEN x) { GEN v = cgetg(2, t_VEC); gel(v,1) = gcopy(x); return v; }
297 : INLINE GEN
298 114569 : mkvec2copy(GEN x, GEN y) {
299 114569 : GEN v = cgetg(3,t_VEC); gel(v,1) = gcopy(x); gel(v,2) = gcopy(y); return v; }
300 : /* col */
301 : INLINE GEN
302 10640992 : mkcol(GEN x) { retmkcol(x); }
303 : INLINE GEN
304 156920423 : mkcol2(GEN x, GEN y) { retmkcol2(x,y); }
305 : INLINE GEN
306 88314 : mkcol3(GEN x, GEN y, GEN z) { retmkcol3(x,y,z); }
307 : INLINE GEN
308 103467 : mkcol4(GEN x, GEN y, GEN z, GEN t) { retmkcol4(x,y,z,t); }
309 : INLINE GEN
310 94 : mkcol5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkcol5(x,y,z,t,u); }
311 : INLINE GEN
312 232589 : mkcol6(GEN x, GEN y, GEN z, GEN t, GEN u, GEN v) { retmkcol6(x,y,z,t,u,v); }
313 : INLINE GEN
314 40411 : mkcols(long x) { retmkcol(stoi(x)); }
315 : INLINE GEN
316 4416244 : mkcol2s(long x, long y) { retmkcol2(stoi(x),stoi(y)); }
317 : INLINE GEN
318 315 : mkcol3s(long x, long y, long z) { retmkcol3(stoi(x),stoi(y),stoi(z)); }
319 : INLINE GEN
320 0 : mkcol4s(long x, long y, long z, long t) { retmkcol4(stoi(x),stoi(y),stoi(z),stoi(t)); }
321 : INLINE GEN
322 33499 : mkcolcopy(GEN x) { GEN v = cgetg(2, t_COL); gel(v,1) = gcopy(x); return v; }
323 : /* mat */
324 : INLINE GEN
325 4750781 : mkmat(GEN x) { retmkmat(x); }
326 : INLINE GEN
327 33658360 : mkmat2(GEN x, GEN y) { retmkmat2(x,y); }
328 : INLINE GEN
329 17001 : mkmat3(GEN x, GEN y, GEN z) { retmkmat3(x,y,z); }
330 : INLINE GEN
331 84 : mkmat4(GEN x, GEN y, GEN z, GEN t) { retmkmat4(x,y,z,t); }
332 : INLINE GEN
333 0 : mkmat5(GEN x, GEN y, GEN z, GEN t, GEN u) { retmkmat5(x,y,z,t,u); }
334 : INLINE GEN
335 122230 : mkmatcopy(GEN x) { GEN v = cgetg(2, t_MAT); gel(v,1) = gcopy(x); return v; }
336 : INLINE GEN
337 0 : mkerr(long x) { GEN v = cgetg(2, t_ERROR); v[1] = x; return v; }
338 : INLINE GEN
339 1332012 : mkoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_1; return v; }
340 : INLINE GEN
341 108848 : mkmoo(void) { GEN v = cgetg(2, t_INFINITY); gel(v,1) = gen_m1; return v; }
342 : INLINE long
343 1453119 : inf_get_sign(GEN x) { return signe(gel(x,1)); }
344 : INLINE GEN
345 207578 : mkmat22s(long a, long b, long c, long d) {retmkmat2(mkcol2s(a,c),mkcol2s(b,d));}
346 : INLINE GEN
347 50284848 : mkmat22(GEN a, GEN b, GEN c, GEN d) { retmkmat2(mkcol2(a,c),mkcol2(b,d)); }
348 :
349 : /* pol */
350 : INLINE GEN
351 3856879 : pol_x(long v) {
352 3856879 : GEN p = cgetg(4, t_POL);
353 3856874 : p[1] = evalsigne(1)|evalvarn(v);
354 3856874 : gel(p,2) = gen_0;
355 3856874 : gel(p,3) = gen_1; return p;
356 : }
357 : /* x^n, assume n >= 0 */
358 : INLINE GEN
359 2249935 : pol_xn(long n, long v) {
360 2249935 : long i, a = n+2;
361 2249935 : GEN p = cgetg(a+1, t_POL);
362 2249939 : p[1] = evalsigne(1)|evalvarn(v);
363 5545758 : for (i = 2; i < a; i++) gel(p,i) = gen_0;
364 2249939 : gel(p,a) = gen_1; return p;
365 : }
366 : /* x^n, no assumption on n */
367 : INLINE GEN
368 294 : pol_xnall(long n, long v)
369 : {
370 294 : if (n < 0) retmkrfrac(gen_1, pol_xn(-n,v));
371 287 : return pol_xn(n, v);
372 : }
373 : /* x^n, assume n >= 0 */
374 : INLINE GEN
375 371 : polxn_Flx(long n, long sv) {
376 371 : long i, a = n+2;
377 371 : GEN p = cgetg(a+1, t_VECSMALL);
378 371 : p[1] = sv;
379 1806 : for (i = 2; i < a; i++) p[i] = 0;
380 371 : p[a] = 1; return p;
381 : }
382 : INLINE GEN
383 3756386 : pol_1(long v) {
384 3756386 : GEN p = cgetg(3, t_POL);
385 3756387 : p[1] = evalsigne(1)|evalvarn(v);
386 3756387 : gel(p,2) = gen_1; return p;
387 : }
388 : INLINE GEN
389 82998096 : pol_0(long v)
390 : {
391 82998096 : GEN x = cgetg(2,t_POL);
392 82998096 : x[1] = evalvarn(v); return x;
393 : }
394 : #define retconst_vec(n,x)\
395 : do { long _i, _n = (n);\
396 : GEN _v = cgetg(_n+1, t_VEC), _x = (x);\
397 : for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
398 : return _v; } while(0)
399 : INLINE GEN
400 241183057 : const_vec(long n, GEN x) { retconst_vec(n, x); }
401 : #define retconst_col(n,x)\
402 : do { long _i, _n = (n);\
403 : GEN _v = cgetg(_n+1, t_COL), _x = (x);\
404 : for (_i = 1; _i <= _n; _i++) gel(_v,_i) = _x;\
405 : return _v; } while(0)
406 : INLINE GEN
407 39631408 : const_col(long n, GEN x) { retconst_col(n, x); }
408 : INLINE GEN
409 19663366 : const_vecsmall(long n, long c)
410 : {
411 : long i;
412 19663366 : GEN V = cgetg(n+1,t_VECSMALL);
413 759373072 : for(i=1;i<=n;i++) V[i] = c;
414 19663963 : return V;
415 : }
416 :
417 : /*** ZERO ***/
418 : /* O(p^e) */
419 : INLINE GEN
420 855782 : zeropadic(GEN p, long e) { retmkpadic(gen_0, icopy(p), gen_1, e, 0); }
421 : INLINE GEN
422 17024 : zeropadic_shallow(GEN p, long e) { retmkpadic(gen_0, icopy(p), gen_1, e, 0); }
423 : /* O(pol_x(v)^e) */
424 : INLINE GEN
425 138824 : zeroser(long v, long e)
426 : {
427 138824 : GEN x = cgetg(2, t_SER);
428 138824 : x[1] = evalvalser(e) | evalvarn(v); return x;
429 : }
430 : INLINE int
431 10079479 : ser_isexactzero(GEN x)
432 : {
433 10079479 : if (!signe(x)) switch(lg(x))
434 : {
435 132804 : case 2: return 1;
436 4676 : case 3: return isexactzero(gel(x,2));
437 : }
438 9941999 : return 0;
439 : }
440 : /* 0 * pol_x(v) */
441 : INLINE GEN
442 42358612 : zeropol(long v) { return pol_0(v); }
443 : /* vector(n) */
444 : INLINE GEN
445 122289956 : zerocol(long n)
446 : {
447 122289956 : GEN y = cgetg(n+1,t_COL);
448 820845233 : long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
449 122290863 : return y;
450 : }
451 : /* vectorv(n) */
452 : INLINE GEN
453 28455466 : zerovec(long n)
454 : {
455 28455466 : GEN y = cgetg(n+1,t_VEC);
456 418537735 : long i; for (i=1; i<=n; i++) gel(y,i) = gen_0;
457 28455468 : return y;
458 : }
459 : /* matrix(m, n) */
460 : INLINE GEN
461 109132 : zeromat(long m, long n)
462 : {
463 109132 : GEN y = cgetg(n+1,t_MAT);
464 109131 : GEN v = zerocol(m);
465 403628 : long i; for (i=1; i<=n; i++) gel(y,i) = v;
466 109131 : return y;
467 : }
468 : /* = zero_zx, sv is a evalvarn()*/
469 : INLINE GEN
470 1426983 : zero_Flx(long sv) { return pol0_Flx(sv); }
471 : INLINE GEN
472 59497400 : zero_Flv(long n)
473 : {
474 59497400 : GEN y = cgetg(n+1,t_VECSMALL);
475 956640861 : long i; for (i=1; i<=n; i++) y[i] = 0;
476 59497636 : return y;
477 : }
478 : /* matrix(m, n) */
479 : INLINE GEN
480 2830558 : zero_Flm(long m, long n)
481 : {
482 2830558 : GEN y = cgetg(n+1,t_MAT);
483 2830546 : GEN v = zero_Flv(m);
484 18033271 : long i; for (i=1; i<=n; i++) gel(y,i) = v;
485 2830549 : return y;
486 : }
487 : /* matrix(m, n) */
488 : INLINE GEN
489 235917 : zero_Flm_copy(long m, long n)
490 : {
491 235917 : GEN y = cgetg(n+1,t_MAT);
492 2480416 : long i; for (i=1; i<=n; i++) gel(y,i) = zero_Flv(m);
493 235920 : return y;
494 : }
495 :
496 : INLINE GEN
497 3648086 : zero_F2v(long m)
498 : {
499 3648086 : long l = nbits2nlong(m);
500 3648067 : GEN v = zero_Flv(l+1);
501 3648050 : v[1] = m;
502 3648050 : return v;
503 : }
504 :
505 : INLINE GEN
506 0 : zero_F2m(long m, long n)
507 : {
508 : long i;
509 0 : GEN M = cgetg(n+1, t_MAT);
510 0 : GEN v = zero_F2v(m);
511 0 : for (i = 1; i <= n; i++)
512 0 : gel(M,i) = v;
513 0 : return M;
514 : }
515 :
516 :
517 : INLINE GEN
518 845108 : zero_F2m_copy(long m, long n)
519 : {
520 : long i;
521 845108 : GEN M = cgetg(n+1, t_MAT);
522 2017156 : for (i = 1; i <= n; i++)
523 1172051 : gel(M,i)= zero_F2v(m);
524 845105 : return M;
525 : }
526 :
527 : /* matrix(m, n) */
528 : INLINE GEN
529 14240242 : zeromatcopy(long m, long n)
530 : {
531 14240242 : GEN y = cgetg(n+1,t_MAT);
532 72011268 : long i; for (i=1; i<=n; i++) gel(y,i) = zerocol(m);
533 14240244 : return y;
534 : }
535 :
536 : INLINE GEN
537 28947 : zerovec_block(long len)
538 : {
539 : long i;
540 28947 : GEN blk = cgetg_block(len + 1, t_VEC);
541 955251 : for (i = 1; i <= len; ++i)
542 926304 : gel(blk, i) = gen_0;
543 28947 : return blk;
544 : }
545 :
546 : /* i-th vector in the standard basis */
547 : INLINE GEN
548 5925929 : col_ei(long n, long i) { GEN e = zerocol(n); gel(e,i) = gen_1; return e; }
549 : INLINE GEN
550 1714599 : vec_ei(long n, long i) { GEN e = zerovec(n); gel(e,i) = gen_1; return e; }
551 : INLINE GEN
552 42 : F2v_ei(long n, long i) { GEN e = zero_F2v(n); F2v_set(e,i); return e; }
553 : INLINE GEN
554 584726 : vecsmall_ei(long n, long i) { GEN e = zero_zv(n); e[i] = 1; return e; }
555 : INLINE GEN
556 1451313 : Rg_col_ei(GEN x, long n, long i) { GEN e = zerocol(n); gel(e,i) = x; return e; }
557 :
558 : INLINE GEN
559 27639918 : shallowcopy(GEN x)
560 27639918 : { return typ(x) == t_MAT ? RgM_shallowcopy(x): leafcopy(x); }
561 :
562 : /* routines for naive growarrays */
563 : INLINE GEN
564 12067081 : vectrunc_init(long l)
565 : {
566 12067081 : GEN z = new_chunk(l);
567 12066839 : z[0] = evaltyp(t_VEC) | _evallg(1); return z;
568 : }
569 : INLINE GEN
570 740250 : coltrunc_init(long l)
571 : {
572 740250 : GEN z = new_chunk(l);
573 740250 : z[0] = evaltyp(t_COL) | _evallg(1); return z;
574 : }
575 : INLINE void
576 324081437 : lg_increase(GEN x) { x[0]++; }
577 : INLINE void
578 16162636 : vectrunc_append(GEN x, GEN t) { gel(x, lg(x)) = t; lg_increase(x); }
579 : INLINE void
580 12306 : vectrunc_append_batch(GEN x, GEN y)
581 : {
582 12306 : long i, l = lg(x), ly = lg(y);
583 12306 : GEN z = x + l-1;
584 40880 : for (i = 1; i < ly; i++) gel(z,i) = gel(y,i);
585 12306 : setlg(x, l+ly-1);
586 12306 : }
587 : INLINE GEN
588 192971097 : vecsmalltrunc_init(long l)
589 : {
590 192971097 : GEN z = new_chunk(l);
591 192996540 : z[0] = evaltyp(t_VECSMALL) | _evallg(1); return z;
592 : }
593 : INLINE void
594 101581440 : vecsmalltrunc_append(GEN x, long t) { x[ lg(x) ] = t; lg_increase(x); }
595 :
596 : /*******************************************************************/
597 : /* */
598 : /* STRING HASH FUNCTIONS */
599 : /* */
600 : /*******************************************************************/
601 : INLINE ulong
602 2753014 : hash_str(const char *str)
603 : {
604 2753014 : ulong hash = 5381UL, c;
605 28612553 : while ( (c = (ulong)*str++) )
606 25859539 : hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
607 2753014 : return hash;
608 : }
609 : INLINE ulong
610 31542657 : hash_str_len(const char *str, long len)
611 : {
612 31542657 : ulong hash = 5381UL;
613 : long i;
614 228006420 : for (i = 0; i < len; i++)
615 : {
616 196463763 : ulong c = (ulong)*str++;
617 196463763 : hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
618 : }
619 31542657 : return hash;
620 : }
621 :
622 : /*******************************************************************/
623 : /* */
624 : /* VEC / COL / VECSMALL */
625 : /* */
626 : /*******************************************************************/
627 : /* shallow*/
628 : INLINE GEN
629 11557 : vec_shorten(GEN v, long n)
630 : {
631 11557 : GEN V = cgetg(n+1, t_VEC);
632 : long i;
633 13013 : for(i = 1; i <= n; i++) gel(V,i) = gel(v,i);
634 11557 : return V;
635 : }
636 : /* shallow*/
637 : INLINE GEN
638 18946 : vec_lengthen(GEN v, long n)
639 : {
640 18946 : GEN V = cgetg(n+1, t_VEC);
641 18946 : long i, l = lg(v);
642 1937064 : for(i = 1; i < l; i++) gel(V,i) = gel(v,i);
643 18946 : return V;
644 : }
645 : /* shallow*/
646 : INLINE GEN
647 3465623 : vec_append(GEN V, GEN s)
648 : {
649 3465623 : long i, l2 = lg(V);
650 3465623 : GEN res = cgetg(l2+1, typ(V));
651 10818615 : for (i = 1; i < l2; i++) gel(res, i) = gel(V,i);
652 3465618 : gel(res,l2) = s; return res;
653 : }
654 : /* shallow*/
655 : INLINE GEN
656 314005 : vec_prepend(GEN v, GEN s)
657 : {
658 314005 : long i, l = lg(v);
659 314005 : GEN w = cgetg(l+1, typ(v));
660 314004 : gel(w,1) = s;
661 796231 : for (i = 2; i <= l; i++) gel(w,i) = gel(v,i-1);
662 314004 : return w;
663 : }
664 : /* shallow*/
665 : INLINE GEN
666 0 : vec_setconst(GEN v, GEN x)
667 : {
668 0 : long i, l = lg(v);
669 0 : for (i = 1; i < l; i++) gel(v,i) = x;
670 0 : return v;
671 : }
672 : INLINE GEN
673 74578 : vecsmall_shorten(GEN v, long n)
674 : {
675 74578 : GEN V = cgetg(n+1,t_VECSMALL);
676 : long i;
677 935608 : for(i = 1; i <= n; i++) V[i] = v[i];
678 74578 : return V;
679 : }
680 : INLINE GEN
681 547 : vecsmall_lengthen(GEN v, long n)
682 : {
683 547 : long i, l = lg(v);
684 547 : GEN V = cgetg(n+1,t_VECSMALL);
685 53385 : for(i = 1; i < l; i++) V[i] = v[i];
686 547 : return V;
687 : }
688 :
689 : INLINE GEN
690 4036825 : vec_to_vecsmall(GEN x)
691 18929556 : { pari_APPLY_long(itos(gel(x,i))) }
692 : INLINE GEN
693 511571 : vecsmall_to_vec(GEN x)
694 7072675 : { pari_APPLY_type(t_VEC, stoi(x[i])) }
695 : INLINE GEN
696 3304 : vecsmall_to_vec_inplace(GEN z)
697 : {
698 3304 : long i, l = lg(z);
699 79604 : for (i=1; i<l; i++) gel(z,i) = stoi(z[i]);
700 3304 : settyp(z, t_VEC); return z;
701 : }
702 : INLINE GEN
703 7837743 : vecsmall_to_col(GEN x)
704 59617794 : { pari_APPLY_type(t_COL, stoi(x[i])) }
705 :
706 : INLINE int
707 7043259 : vecsmall_lexcmp(GEN x, GEN y)
708 : {
709 : long lx,ly,l,i;
710 7043259 : lx = lg(x);
711 7043259 : ly = lg(y); l = minss(lx,ly);
712 30264526 : for (i=1; i<l; i++)
713 28787584 : if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
714 1476942 : if (lx == ly) return 0;
715 4154 : return (lx < ly)? -1 : 1;
716 : }
717 :
718 : INLINE int
719 108088071 : vecsmall_prefixcmp(GEN x, GEN y)
720 : {
721 108088071 : long i, lx = lg(x), ly = lg(y), l = minss(lx,ly);
722 542691324 : for (i=1; i<l; i++)
723 519806035 : if (x[i] != y[i]) return x[i]<y[i]? -1: 1;
724 22885289 : return 0;
725 : }
726 :
727 : /*Can be used on t_VEC, but coeffs not gcopy-ed*/
728 : INLINE GEN
729 186991 : vecsmall_prepend(GEN V, long s)
730 : {
731 186991 : long i, l2 = lg(V);
732 186991 : GEN res = cgetg(l2+1, typ(V));
733 186991 : res[1] = s;
734 625343 : for (i = 2; i <= l2; ++i) res[i] = V[i - 1];
735 186991 : return res;
736 : }
737 :
738 : INLINE GEN
739 4111393 : vecsmall_append(GEN V, long s)
740 : {
741 4111393 : long i, l2 = lg(V);
742 4111393 : GEN res = cgetg(l2+1, t_VECSMALL);
743 6028468 : for (i = 1; i < l2; ++i) res[i] = V[i];
744 4111393 : res[l2] = s; return res;
745 : }
746 :
747 : INLINE GEN
748 1464438 : vecsmall_concat(GEN u, GEN v)
749 : {
750 1464438 : long i, l1 = lg(u)-1, l2 = lg(v)-1;
751 1464438 : GEN res = cgetg(l1+l2+1, t_VECSMALL);
752 11618713 : for (i = 1; i <= l1; ++i) res[i] = u[i];
753 15219987 : for (i = 1; i <= l2; ++i) res[i+l1] = v[i];
754 1464438 : return res;
755 : }
756 :
757 : /* return the number of indices where u and v are equal */
758 : INLINE long
759 0 : vecsmall_coincidence(GEN u, GEN v)
760 : {
761 0 : long i, s = 0, l = minss(lg(u),lg(v));
762 0 : for(i=1; i<l; i++)
763 0 : if(u[i] == v[i]) s++;
764 0 : return s;
765 : }
766 :
767 : /* returns the first index i<=n such that x=v[i] if it exists, 0 otherwise */
768 : INLINE long
769 84 : vecsmall_isin(GEN v, long x)
770 : {
771 84 : long i, l = lg(v);
772 124 : for (i = 1; i < l; i++)
773 80 : if (v[i] == x) return i;
774 44 : return 0;
775 : }
776 :
777 : INLINE long
778 84 : vecsmall_pack(GEN V, long base, long mod)
779 : {
780 84 : long i, s = 0;
781 273 : for(i=1; i<lg(V); i++) s = (base*s + V[i]) % mod;
782 84 : return s;
783 : }
784 :
785 : INLINE long
786 21 : vecsmall_indexmax(GEN x)
787 : {
788 21 : long i, i0 = 1, t = x[1], lx = lg(x);
789 84 : for (i=2; i<lx; i++)
790 63 : if (x[i] > t) t = x[i0=i];
791 21 : return i0;
792 : }
793 :
794 : INLINE long
795 1164619 : vecsmall_max(GEN x)
796 : {
797 1164619 : long i, t = x[1], lx = lg(x);
798 3384339 : for (i=2; i<lx; i++)
799 2219720 : if (x[i] > t) t = x[i];
800 1164619 : return t;
801 : }
802 :
803 : INLINE long
804 21 : vecsmall_indexmin(GEN x)
805 : {
806 21 : long i, i0 = 1, t = x[1], lx =lg(x);
807 84 : for (i=2; i<lx; i++)
808 63 : if (x[i] < t) t = x[i0=i];
809 21 : return i0;
810 : }
811 :
812 : INLINE long
813 2324 : vecsmall_min(GEN x)
814 : {
815 2324 : long i, t = x[1], lx =lg(x);
816 16268 : for (i=2; i<lx; i++)
817 13944 : if (x[i] < t) t = x[i];
818 2324 : return t;
819 : }
820 :
821 : INLINE int
822 23098227 : ZV_isscalar(GEN x)
823 : {
824 23098227 : long l = lg(x);
825 54778014 : while (--l > 1)
826 54344353 : if (signe(gel(x, l))) return 0;
827 433661 : return 1;
828 : }
829 : INLINE int
830 54402255 : QV_isscalar(GEN x)
831 : {
832 54402255 : long lx = lg(x),i;
833 70399907 : for (i=2; i<lx; i++)
834 66442327 : if (!isintzero(gel(x, i))) return 0;
835 3957580 : return 1;
836 : }
837 : INLINE int
838 1210302 : RgV_isscalar(GEN x)
839 : {
840 1210302 : long lx = lg(x),i;
841 1236616 : for (i=2; i<lx; i++)
842 1232898 : if (!gequal0(gel(x, i))) return 0;
843 3718 : return 1;
844 : }
845 : INLINE int
846 0 : RgX_isscalar(GEN x)
847 : {
848 : long i;
849 0 : for (i=lg(x)-1; i>2; i--)
850 0 : if (!gequal0(gel(x, i))) return 0;
851 0 : return 1;
852 : }
853 : INLINE long
854 26880644 : RgX_equal_var(GEN x, GEN y) { return varn(x) == varn(y) && RgX_equal(x,y); }
855 : INLINE GEN
856 140 : RgX_to_RgV(GEN x, long N) { x = RgX_to_RgC(x, N); settyp(x, t_VEC); return x; }
857 :
858 : #define RgX_type_code(t1,t2) ((t1 << 6) | t2)
859 :
860 : INLINE int
861 68302 : RgX_is_rational(GEN x)
862 : {
863 : long i;
864 311362 : for (i = lg(x)-1; i > 1; i--)
865 295246 : if (!is_rational_t(typ(gel(x,i)))) return 0;
866 16116 : return 1;
867 : }
868 : INLINE int
869 22421931 : RgX_is_ZX(GEN x)
870 : {
871 : long i;
872 82872698 : for (i = lg(x)-1; i > 1; i--)
873 62232755 : if (typ(gel(x,i)) != t_INT) return 0;
874 20639943 : return 1;
875 : }
876 : INLINE int
877 400119 : RgX_is_QX(GEN x)
878 : {
879 400119 : long k = lg(x)-1;
880 1497800 : for ( ; k>1; k--)
881 1097962 : if (!is_rational_t(typ(gel(x,k)))) return 0;
882 399838 : return 1;
883 : }
884 : INLINE int
885 1331271 : RgX_is_monomial(GEN x)
886 : {
887 : long i;
888 1331271 : if (!signe(x)) return 0;
889 3340129 : for (i=lg(x)-2; i>1; i--)
890 2653113 : if (!isexactzero(gel(x,i))) return 0;
891 687016 : return 1;
892 : }
893 : INLINE int
894 32164052 : RgV_is_ZV(GEN x)
895 : {
896 : long i;
897 127605281 : for (i = lg(x)-1; i > 0; i--)
898 95474052 : if (typ(gel(x,i)) != t_INT) return 0;
899 32131229 : return 1;
900 : }
901 : INLINE int
902 140759 : RgV_is_QV(GEN x)
903 : {
904 : long i;
905 623053 : for (i = lg(x)-1; i > 0; i--)
906 485244 : if (!is_rational_t(typ(gel(x,i)))) return 0;
907 137809 : return 1;
908 : }
909 : INLINE long
910 110130 : RgV_isin_i(GEN v, GEN x, long n)
911 : {
912 : long i;
913 1033437 : for (i = 1; i <= n; i++)
914 1026703 : if (gequal(gel(v,i), x)) return i;
915 6734 : return 0;
916 : }
917 : INLINE long
918 110130 : RgV_isin(GEN v, GEN x) { return RgV_isin_i(v, x, lg(v)-1); }
919 :
920 : /********************************************************************/
921 : /** **/
922 : /** Dynamic arrays implementation **/
923 : /** **/
924 : /********************************************************************/
925 : INLINE void **
926 1024056441 : pari_stack_base(pari_stack *s) { return s->data; }
927 :
928 : INLINE void
929 5834805 : pari_stack_init(pari_stack *s, size_t size, void **data)
930 : {
931 5834805 : s->data = data;
932 5834805 : *data = NULL;
933 5834805 : s->n = 0;
934 5834805 : s->alloc = 0;
935 5834805 : s->size = size;
936 5834805 : }
937 :
938 : INLINE void
939 1018667332 : pari_stack_alloc(pari_stack *s, long nb)
940 : {
941 1018667332 : void **sdat = pari_stack_base(s);
942 1018617383 : long alloc = s->alloc;
943 1018617383 : if (s->n+nb <= alloc) return;
944 2173616 : if (!alloc)
945 2074899 : alloc = nb;
946 : else
947 : {
948 199882 : while (s->n+nb > alloc) alloc <<= 1;
949 : }
950 2173616 : pari_realloc_ip(sdat,alloc*s->size);
951 2173059 : s->alloc = alloc;
952 : }
953 :
954 : INLINE long
955 924049216 : pari_stack_new(pari_stack *s) { pari_stack_alloc(s, 1); return s->n++; }
956 :
957 : INLINE void
958 5403893 : pari_stack_delete(pari_stack *s)
959 : {
960 5403893 : void **sdat = pari_stack_base(s);
961 5396993 : if (*sdat) pari_free(*sdat);
962 5417696 : }
963 :
964 : INLINE void
965 5851 : pari_stack_pushp(pari_stack *s, void *u)
966 : {
967 5851 : long n = pari_stack_new(s);
968 5851 : void **sdat =(void**) *pari_stack_base(s);
969 5851 : sdat[n] = u;
970 5851 : }
971 :
972 : /*******************************************************************/
973 : /* */
974 : /* EXTRACT */
975 : /* */
976 : /*******************************************************************/
977 : INLINE GEN
978 656426040 : vecslice(GEN A, long y1, long y2)
979 : {
980 656426040 : long i,lB = y2 - y1 + 2;
981 656426040 : GEN B = cgetg(lB, typ(A));
982 2920106654 : for (i=1; i<lB; i++) B[i] = A[y1-1+i];
983 656418111 : return B;
984 : }
985 : INLINE GEN
986 2690098 : vecslicepermute(GEN A, GEN p, long y1, long y2)
987 : {
988 2690098 : long i,lB = y2 - y1 + 2;
989 2690098 : GEN B = cgetg(lB, typ(A));
990 30455383 : for (i=1; i<lB; i++) B[i] = A[p[y1-1+i]];
991 2690092 : return B;
992 : }
993 : /* rowslice(rowpermute(A,p), x1, x2) */
994 : INLINE GEN
995 184740 : rowslicepermute(GEN x, GEN p, long j1, long j2)
996 780776 : { pari_APPLY_same(vecslicepermute(gel(x,i),p,j1,j2)) }
997 :
998 : INLINE GEN
999 79358326 : rowslice(GEN x, long j1, long j2)
1000 672301312 : { pari_APPLY_same(vecslice(gel(x,i), j1, j2)) }
1001 :
1002 : INLINE GEN
1003 16818859 : matslice(GEN A, long x1, long x2, long y1, long y2)
1004 16818859 : { return rowslice(vecslice(A, y1, y2), x1, x2); }
1005 :
1006 : /* shallow, remove coeff of index j */
1007 : INLINE GEN
1008 273 : rowsplice(GEN x, long j)
1009 1225 : { pari_APPLY_same(vecsplice(gel(x,i), j)) }
1010 :
1011 : /* shallow, remove coeff of index j */
1012 : INLINE GEN
1013 384908 : vecsplice(GEN a, long j)
1014 : {
1015 384908 : long i, k, l = lg(a);
1016 : GEN b;
1017 384908 : if (l == 1) pari_err(e_MISC, "incorrect component in vecsplice");
1018 384908 : b = cgetg(l-1, typ(a));
1019 1593581 : for (i = k = 1; i < l; i++)
1020 1208670 : if (i != j) gel(b, k++) = gel(a,i);
1021 384911 : return b;
1022 : }
1023 : /* shallow */
1024 : INLINE GEN
1025 1036 : RgM_minor(GEN a, long i, long j)
1026 : {
1027 1036 : GEN b = vecsplice(a, j);
1028 1036 : long k, l = lg(b);
1029 4242 : for (k = 1; k < l; k++) gel(b,k) = vecsplice(gel(b,k), i);
1030 1036 : return b;
1031 : }
1032 :
1033 : /* A[x0,] */
1034 : INLINE GEN
1035 764004 : row(GEN x, long j)
1036 6693243 : { pari_APPLY_type(t_VEC, gcoeff(x, j, i)) }
1037 : INLINE GEN
1038 8742529 : Flm_row(GEN x, long j)
1039 231901388 : { pari_APPLY_ulong((ulong)coeff(x, j, i)) }
1040 : /* A[x0,] */
1041 : INLINE GEN
1042 204988 : rowcopy(GEN x, long j)
1043 2105509 : { pari_APPLY_type(t_VEC, gcopy(gcoeff(x, j, i))) }
1044 : /* A[x0, x1..x2] */
1045 : INLINE GEN
1046 987 : row_i(GEN A, long x0, long x1, long x2)
1047 : {
1048 987 : long i, lB = x2 - x1 + 2;
1049 987 : GEN B = cgetg(lB, t_VEC);
1050 2989 : for (i=x1; i<=x2; i++) gel(B, i) = gcoeff(A, x0, i);
1051 987 : return B;
1052 : }
1053 :
1054 : INLINE GEN
1055 697235 : vecreverse(GEN A)
1056 : {
1057 : long i, l;
1058 697235 : GEN B = cgetg_copy(A, &l);
1059 2408385 : for (i=1; i<l; i++) gel(B, i) = gel(A, l-i);
1060 697235 : return B;
1061 : }
1062 :
1063 : INLINE GEN
1064 3052 : vecsmall_reverse(GEN A)
1065 : {
1066 : long i, l;
1067 3052 : GEN B = cgetg_copy(A, &l);
1068 12698 : for (i=1; i<l; i++) B[i] = A[l-i];
1069 3052 : return B;
1070 : }
1071 :
1072 : INLINE void
1073 2605 : vecreverse_inplace(GEN y)
1074 : {
1075 2605 : long l = lg(y), lim = l>>1, i;
1076 8312 : for (i = 1; i <= lim; i++)
1077 : {
1078 5707 : GEN z = gel(y,i);
1079 5707 : gel(y,i) = gel(y,l-i);
1080 5707 : gel(y,l-i) = z;
1081 : }
1082 2605 : }
1083 :
1084 : INLINE GEN
1085 78740059 : vecsmallpermute(GEN A, GEN p) { return perm_mul(A, p); }
1086 :
1087 : INLINE GEN
1088 20531298 : vecpermute(GEN A, GEN x)
1089 115097486 : { pari_APPLY_type(typ(A), gel(A, x[i])) }
1090 :
1091 : INLINE GEN
1092 9372668 : veclast(GEN A) { return gel(A, lg(A)-1); }
1093 :
1094 : INLINE GEN
1095 14710277 : rowpermute(GEN x, GEN p)
1096 102254007 : { pari_APPLY_same(typ(gel(x,i)) == t_VECSMALL ? vecsmallpermute(gel(x, i), p)
1097 : : vecpermute(gel(x, i), p))
1098 : }
1099 : /*******************************************************************/
1100 : /* */
1101 : /* PERMUTATIONS */
1102 : /* */
1103 : /*******************************************************************/
1104 : INLINE GEN
1105 3267351 : identity_zv(long n)
1106 : {
1107 3267351 : GEN v = cgetg(n+1, t_VECSMALL);
1108 : long i;
1109 32956650 : for (i = 1; i <= n; i++) v[i] = i;
1110 3267342 : return v;
1111 : }
1112 : INLINE GEN
1113 8113 : identity_ZV(long n)
1114 : {
1115 8113 : GEN v = cgetg(n+1, t_VEC);
1116 : long i;
1117 169078 : for (i = 1; i <= n; i++) gel(v,i) = utoipos(i);
1118 8113 : return v;
1119 : }
1120 : /* identity permutation */
1121 : INLINE GEN
1122 3243001 : identity_perm(long n) { return identity_zv(n); }
1123 :
1124 : /* assume d <= n */
1125 : INLINE GEN
1126 99911 : cyclic_perm(long n, long d)
1127 : {
1128 99911 : GEN perm = cgetg(n+1, t_VECSMALL);
1129 : long i;
1130 520240 : for (i = 1; i <= n-d; i++) perm[i] = i+d;
1131 226702 : for ( ; i <= n; i++) perm[i] = i-n+d;
1132 99911 : return perm;
1133 : }
1134 :
1135 : /* Multiply (compose) two permutations */
1136 : INLINE GEN
1137 80935555 : perm_mul(GEN s, GEN x)
1138 1025538194 : { pari_APPLY_long(s[x[i]]) }
1139 :
1140 : INLINE GEN
1141 728 : perm_sqr(GEN x)
1142 18284 : { pari_APPLY_long(x[x[i]]) }
1143 :
1144 : /* Compute the inverse (reciprocal) of a permutation. */
1145 : INLINE GEN
1146 2782993 : perm_inv(GEN x)
1147 : {
1148 : long i, lx;
1149 2782993 : GEN y = cgetg_copy(x, &lx);
1150 39160569 : for (i=1; i<lx; i++) y[ x[i] ] = i;
1151 2782989 : return y;
1152 : }
1153 : /* Return s*t*s^-1 */
1154 : INLINE GEN
1155 418299 : perm_conj(GEN s, GEN t)
1156 : {
1157 : long i, l;
1158 418299 : GEN v = cgetg_copy(s, &l);
1159 6857893 : for (i = 1; i < l; i++) v[ s[i] ] = s[ t[i] ];
1160 418299 : return v;
1161 : }
1162 :
1163 : INLINE void
1164 510596950 : pari_free(void *pointer)
1165 : {
1166 510596950 : BLOCK_SIGINT_START;
1167 510651988 : free(pointer);
1168 510651988 : BLOCK_SIGINT_END;
1169 510647556 : }
1170 : INLINE void*
1171 746529863 : pari_malloc(size_t size)
1172 : {
1173 746529863 : if (size)
1174 : {
1175 : char *tmp;
1176 746530011 : BLOCK_SIGINT_START;
1177 746598117 : tmp = (char*)malloc(size);
1178 746598117 : BLOCK_SIGINT_END;
1179 746591646 : if (!tmp) pari_err(e_MEM);
1180 746599704 : return tmp;
1181 : }
1182 0 : return NULL;
1183 : }
1184 : INLINE void*
1185 1890 : pari_realloc(void *pointer, size_t size)
1186 : {
1187 : char *tmp;
1188 :
1189 1890 : BLOCK_SIGINT_START;
1190 1890 : if (!pointer) tmp = (char *) malloc(size);
1191 1890 : else tmp = (char *) realloc(pointer,size);
1192 1890 : BLOCK_SIGINT_END;
1193 1890 : if (!tmp) pari_err(e_MEM);
1194 1890 : return tmp;
1195 : }
1196 : INLINE void
1197 2180053 : pari_realloc_ip(void **pointer, size_t size)
1198 : {
1199 : char *tmp;
1200 2180053 : BLOCK_SIGINT_START;
1201 2180071 : if (!*pointer) tmp = (char *) malloc(size);
1202 105459 : else tmp = (char *) realloc(*pointer,size);
1203 2180071 : if (!tmp) pari_err(e_MEM);
1204 2180071 : *pointer = tmp;
1205 2180071 : BLOCK_SIGINT_END;
1206 2179915 : }
1207 :
1208 : INLINE void*
1209 47671 : pari_calloc(size_t size)
1210 : {
1211 47671 : void *t = pari_malloc(size);
1212 47671 : memset(t, 0, size); return t;
1213 : }
1214 : INLINE GEN
1215 10166 : cgetalloc(size_t l, long t)
1216 : { /* evallg may raise e_OVERFLOW, which would leak x */
1217 10166 : ulong x0 = evaltyp(t) | evallg(l);
1218 10166 : GEN x = (GEN)pari_malloc(l * sizeof(long));
1219 10166 : x[0] = x0; return x;
1220 : }
1221 :
1222 : /*******************************************************************/
1223 : /* */
1224 : /* GARBAGE COLLECTION */
1225 : /* */
1226 : /*******************************************************************/
1227 : /* copy integer x as if we had set_avma(av) */
1228 : INLINE GEN
1229 8036000576 : icopy_avma(GEN x, pari_sp av)
1230 : {
1231 8036000576 : long i = lgefint(x), lx = i;
1232 8036000576 : GEN y = ((GEN)av) - i;
1233 58494023144 : while (--i > 0) y[i] = x[i];
1234 8036000576 : y[0] = evaltyp(t_INT)|evallg(lx);
1235 8039063838 : return y;
1236 : }
1237 : /* copy leaf x as if we had set_avma(av) */
1238 : INLINE GEN
1239 577441237 : leafcopy_avma(GEN x, pari_sp av)
1240 : {
1241 577441237 : long i = lg(x);
1242 577441237 : GEN y = ((GEN)av) - i;
1243 3072914884 : while (--i > 0) y[i] = x[i];
1244 577441237 : y[0] = x[0] & (~CLONEBIT);
1245 577441237 : return y;
1246 : }
1247 : INLINE GEN
1248 1132624585 : gc_leaf(pari_sp av, GEN x)
1249 : {
1250 : long lx;
1251 : GEN q;
1252 :
1253 1132624585 : if (!isonstack(x) || (GEN)av<=x) return gc_const(av,x);
1254 1131387436 : lx = lg(x);
1255 1131387436 : q = ((GEN)av) - lx;
1256 1131387436 : set_avma((pari_sp)q);
1257 11281174804 : while (--lx >= 0) q[lx] = x[lx];
1258 1130996226 : return q;
1259 : }
1260 : INLINE GEN
1261 4105157224 : gc_INT(pari_sp av, GEN x)
1262 : {
1263 4105157224 : if (!isonstack(x) || (GEN)av<=x) return gc_const(av,x);
1264 3657299481 : set_avma((pari_sp)icopy_avma(x, av));
1265 3660697248 : return (GEN)avma;
1266 : }
1267 : INLINE void
1268 8490187 : gc_INT_affii(pari_sp av, GEN x, GEN *y)
1269 : {
1270 8490187 : long l = lg(*y);
1271 8490187 : if (lgefint(x) <= l && isonstack(*y))
1272 : {
1273 6834959 : affii(x,*y);
1274 6837381 : set_avma(av);
1275 : }
1276 : else
1277 1655079 : *y = gc_INT(av, x);
1278 8501365 : }
1279 : INLINE GEN
1280 1949593477 : gc_upto(pari_sp av, GEN q)
1281 : {
1282 1949593477 : if (!isonstack(q) || (GEN)av<=q) return gc_const(av,q);
1283 1757734533 : switch(typ(q))
1284 : { /* first all non recursive types */
1285 527456867 : case t_INT: return gc_INT(av, q);
1286 347035770 : case t_REAL:
1287 : case t_STR:
1288 347035770 : case t_VECSMALL: return gc_leaf(av,q);
1289 883241896 : default: return (GEN)((pari_sp)q + gc_stack_update(av, (pari_sp)(q+lg(q))));
1290 : }
1291 : }
1292 :
1293 : /* gc_upto(av, gcopy(x)) */
1294 : INLINE GEN
1295 256168707 : gc_GEN(pari_sp av, GEN x)
1296 : {
1297 256168707 : if (is_recursive_t(typ(x)))
1298 : {
1299 219184803 : GENbin *p = copy_bin(x);
1300 219204313 : set_avma(av); return bin_copy(p);
1301 : }
1302 : else
1303 : {
1304 36983153 : set_avma(av);
1305 36984271 : if (x < (GEN)av) {
1306 36766753 : if (x < (GEN)pari_mainstack->bot) new_chunk(lg(x));
1307 36765003 : x = leafcopy_avma(x, av);
1308 36764379 : set_avma((pari_sp)x);
1309 : } else
1310 217846 : x = leafcopy(x);
1311 36981181 : return x;
1312 : }
1313 : }
1314 :
1315 : INLINE void
1316 48157473 : guncloneNULL(GEN x) { if (x) gunclone(x); }
1317 : INLINE void
1318 1388013 : guncloneNULL_deep(GEN x) { if (x) gunclone_deep(x); }
1319 :
1320 : /* assume 1 <= n < 10 */
1321 : INLINE GEN
1322 109992264 : gc_all(pari_sp av, int n, ...)
1323 : {
1324 : int i;
1325 109992264 : va_list a; va_start(a, n);
1326 109992264 : if (n < 10)
1327 : {
1328 : GEN *v[10];
1329 363972153 : for (i=0; i<n; i++) { v[i] = va_arg(a,GEN*); *v[i] = (GEN)copy_bin(*v[i]); }
1330 109993241 : set_avma(av);
1331 363975178 : for (i=0; i<n; i++) *v[i] = bin_copy((GENbin*)*v[i]);
1332 109994072 : va_end(a); return *v[0];
1333 : }
1334 : else
1335 : {
1336 0 : GEN z, **v = (GEN**)pari_malloc(n*sizeof(GEN*));
1337 0 : for (i=0; i<n; i++) { v[i] = va_arg(a,GEN*); *v[i] = (GEN)copy_bin(*v[i]); }
1338 0 : set_avma(av);
1339 0 : for (i=0; i<n; i++) *v[i] = bin_copy((GENbin*)*v[i]);
1340 0 : z = *v[0]; pari_free(v); va_end(a); return z;
1341 : }
1342 : }
1343 :
1344 : INLINE void
1345 2204773 : gc_slice(pari_sp av, GEN x, int n)
1346 : {
1347 : int i;
1348 26247788 : for (i=0; i<n; i++) gel(x,i) = (GEN)copy_bin(gel(x,i));
1349 2205196 : set_avma(av);
1350 26249000 : for (i=0; i<n; i++) gel(x,i) = bin_copy((GENbin*)x[i]);
1351 2204913 : }
1352 :
1353 : /* p from copy_bin. Copy p->x back to stack, then destroy p */
1354 : INLINE GEN
1355 497276042 : bin_copy(GENbin *p)
1356 : {
1357 : GEN x, y, base;
1358 : long dx, len;
1359 :
1360 497276042 : x = p->x; if (!x) { pari_free(p); return gen_0; }
1361 466976676 : len = p->len;
1362 466976676 : base= p->base; dx = x - base;
1363 466976676 : y = (GEN)memcpy((void*)new_chunk(len), (void*)GENbinbase(p), len*sizeof(long));
1364 466969848 : y += dx;
1365 466969848 : p->rebase(y, ((ulong)y-(ulong)x));
1366 466967686 : pari_free(p); return y;
1367 : }
1368 :
1369 : INLINE GEN
1370 964241994 : GENbinbase(GENbin *p) { return (GEN)(p + 1); }
1371 :
1372 : INLINE void
1373 102125063 : cgiv(GEN x)
1374 : {
1375 102125063 : pari_sp av = (pari_sp)(x+lg(x));
1376 102125063 : if (isonstack((GEN)av)) set_avma(av);
1377 102138217 : }
1378 :
1379 : INLINE void
1380 1902701 : killblock(GEN x) { gunclone(x); }
1381 :
1382 : INLINE int
1383 325738581 : is_universal_constant(GEN x) { return (x >= gen_0 && x <= ghalf); }
1384 :
1385 : /*******************************************************************/
1386 : /* */
1387 : /* CONVERSION / ASSIGNMENT */
1388 : /* */
1389 : /*******************************************************************/
1390 : /* z is a type which may be a t_COMPLEX component (not a t_QUAD) */
1391 : INLINE GEN
1392 18216748 : cxcompotor(GEN z, long prec)
1393 : {
1394 18216748 : switch(typ(z))
1395 : {
1396 11786927 : case t_INT: return itor(z, prec);
1397 293342 : case t_FRAC: return fractor(z, prec);
1398 6136745 : case t_REAL: return rtor(z, prec);
1399 0 : default: pari_err_TYPE("cxcompotor",z);
1400 : return NULL; /* LCOV_EXCL_LINE */
1401 : }
1402 : }
1403 : INLINE GEN
1404 9082539 : cxtofp(GEN x, long prec)
1405 9082539 : { retmkcomplex(cxcompotor(gel(x,1),prec), cxcompotor(gel(x,2),prec)); }
1406 :
1407 : INLINE GEN
1408 337177 : cxtoreal(GEN q)
1409 337177 : { return (typ(q) == t_COMPLEX && gequal0(gel(q,2)))? gel(q,1): q; }
1410 :
1411 : INLINE double
1412 60763884 : gtodouble(GEN x)
1413 : {
1414 60763884 : if (typ(x)!=t_REAL) {
1415 8265721 : pari_sp av = avma;
1416 8265721 : x = gtofp(x, DEFAULTPREC);
1417 8265198 : if (typ(x)!=t_REAL) pari_err_TYPE("gtodouble [t_REAL expected]", x);
1418 8265198 : set_avma(av);
1419 : }
1420 60763247 : return rtodbl(x);
1421 : }
1422 :
1423 : INLINE int
1424 2988058 : gisdouble(GEN x, double *g)
1425 : {
1426 2988058 : if (typ(x)!=t_REAL) {
1427 42341 : pari_sp av = avma;
1428 42341 : x = gtofp(x, DEFAULTPREC);
1429 42341 : if (typ(x)!=t_REAL) return gc_double(av, 0);
1430 42341 : set_avma(av);
1431 : }
1432 2988059 : if (expo(x) >= 0x3ff) return 0;
1433 2988059 : *g = rtodbl(x); return 1;
1434 : }
1435 :
1436 : INLINE long
1437 85833191 : gtos(GEN x) {
1438 85833191 : if (typ(x) != t_INT) pari_err_TYPE("gtos [integer expected]",x);
1439 85833177 : return itos(x);
1440 : }
1441 :
1442 : INLINE ulong
1443 104263 : gtou(GEN x) {
1444 104263 : if (typ(x) != t_INT || signe(x)<0)
1445 7 : pari_err_TYPE("gtou [integer >=0 expected]",x);
1446 104256 : return itou(x);
1447 : }
1448 :
1449 : INLINE GEN
1450 46637926 : absfrac(GEN x)
1451 : {
1452 46637926 : GEN y = cgetg(3, t_FRAC);
1453 46637948 : gel(y,1) = absi(gel(x,1));
1454 46638008 : gel(y,2) = icopy(gel(x,2)); return y;
1455 : }
1456 : INLINE GEN
1457 28237 : absfrac_shallow(GEN x)
1458 28237 : { return signe(gel(x,1))>0? x: mkfrac(negi(gel(x,1)), gel(x,2)); }
1459 : INLINE GEN
1460 8062660 : Q_abs(GEN x) { return (typ(x) == t_INT)? absi(x): absfrac(x); }
1461 : INLINE GEN
1462 120254 : Q_abs_shallow(GEN x)
1463 120254 : { return (typ(x) == t_INT)? absi_shallow(x): absfrac_shallow(x); }
1464 : INLINE GEN
1465 13097 : R_abs_shallow(GEN x)
1466 13097 : { return (typ(x) == t_FRAC)? absfrac_shallow(x): mpabs_shallow(x); }
1467 : INLINE GEN
1468 0 : R_abs(GEN x)
1469 0 : { return (typ(x) == t_FRAC)? absfrac(x): mpabs(x); }
1470 :
1471 : /* Force z to be of type real/complex with floating point components */
1472 : INLINE GEN
1473 254251628 : gtofp(GEN z, long prec)
1474 : {
1475 254251628 : switch(typ(z))
1476 : {
1477 215349056 : case t_INT: return itor(z, prec);
1478 4097761 : case t_FRAC: return fractor(z, prec);
1479 26028535 : case t_REAL: return rtor(z, prec);
1480 8783598 : case t_COMPLEX: {
1481 8783598 : GEN a = gel(z,1), b = gel(z,2);
1482 8783598 : if (isintzero(b)) return cxcompotor(a, prec);
1483 8783602 : if (isintzero(a)) {
1484 27482 : GEN y = cgetg(3, t_COMPLEX);
1485 27482 : b = cxcompotor(b, prec);
1486 27482 : gel(y,1) = real_0_bit(expo(b) - prec);
1487 27482 : gel(y,2) = b; return y;
1488 : }
1489 8756085 : return cxtofp(z, prec);
1490 : }
1491 0 : case t_QUAD: return quadtofp(z, prec);
1492 0 : default: pari_err_TYPE("gtofp",z);
1493 : return NULL; /* LCOV_EXCL_LINE */
1494 : }
1495 : }
1496 : /* Force z to be of type real / int */
1497 : INLINE GEN
1498 22428 : gtomp(GEN z, long prec)
1499 : {
1500 22428 : switch(typ(z))
1501 : {
1502 42 : case t_INT: return z;
1503 22386 : case t_FRAC: return fractor(z, prec);
1504 0 : case t_REAL: return rtor(z, prec);
1505 0 : case t_QUAD: z = quadtofp(z, prec);
1506 0 : if (typ(z) == t_REAL) return z;
1507 0 : default: pari_err_TYPE("gtomp",z);
1508 : return NULL; /* LCOV_EXCL_LINE */
1509 : }
1510 : }
1511 :
1512 : INLINE GEN
1513 7147143 : RgX_gtofp(GEN x, long prec)
1514 37274296 : { pari_APPLY_pol_normalized(gtofp(gel(x,i), prec)); }
1515 :
1516 : INLINE GEN
1517 34013738 : RgC_gtofp(GEN x, long prec)
1518 219164170 : { pari_APPLY_type(t_COL, gtofp(gel(x,i), prec)) }
1519 :
1520 : INLINE GEN
1521 56 : RgV_gtofp(GEN x, long prec)
1522 4781 : { pari_APPLY_type(t_VEC, gtofp(gel(x,i), prec)) }
1523 :
1524 : INLINE GEN
1525 8252419 : RgM_gtofp(GEN x, long prec)
1526 41632474 : { pari_APPLY_same(RgC_gtofp(gel(x,i), prec)) }
1527 :
1528 : INLINE GEN
1529 574 : RgC_gtomp(GEN x, long prec)
1530 23002 : { pari_APPLY_type(t_COL, gtomp(gel(x,i), prec)) }
1531 :
1532 : INLINE GEN
1533 21 : RgM_gtomp(GEN x, long prec)
1534 595 : { pari_APPLY_same(RgC_gtomp(gel(x,i), prec)) }
1535 :
1536 : INLINE GEN
1537 61608 : RgX_fpnorml2(GEN x, long prec)
1538 : {
1539 61608 : pari_sp av = avma;
1540 61608 : return gc_upto(av, gnorml2(RgX_gtofp(x, prec)));
1541 : }
1542 : INLINE GEN
1543 622072 : RgC_fpnorml2(GEN x, long prec)
1544 : {
1545 622072 : pari_sp av = avma;
1546 622072 : return gc_upto(av, gnorml2(RgC_gtofp(x, prec)));
1547 : }
1548 : INLINE GEN
1549 22780 : RgM_fpnorml2(GEN x, long prec)
1550 : {
1551 22780 : pari_sp av = avma;
1552 22780 : return gc_upto(av, gnorml2(RgM_gtofp(x, prec)));
1553 : }
1554 :
1555 : /* y a t_REAL */
1556 : INLINE void
1557 898768 : affgr(GEN x, GEN y)
1558 : {
1559 898768 : switch(typ(x)) {
1560 288974 : case t_INT: affir(x,y); break;
1561 609794 : case t_REAL: affrr(x,y); break;
1562 0 : case t_FRAC: rdiviiz(gel(x,1),gel(x,2), y); break;
1563 0 : default: pari_err_TYPE2("=",x,y);
1564 : }
1565 898768 : }
1566 :
1567 : INLINE GEN
1568 249594 : affc_fixlg(GEN x, GEN res)
1569 : {
1570 249594 : if (typ(x) == t_COMPLEX)
1571 : {
1572 206878 : affrr_fixlg(gel(x,1), gel(res,1));
1573 206878 : affrr_fixlg(gel(x,2), gel(res,2));
1574 : }
1575 : else
1576 : {
1577 42716 : set_avma((pari_sp)(res+3));
1578 42716 : res = cgetr(realprec(gel(res,1)));
1579 42717 : affrr_fixlg(x, res);
1580 : }
1581 249595 : return res;
1582 : }
1583 :
1584 : INLINE GEN
1585 0 : trunc_safe(GEN x) { long e; return gcvtoi(x,&e); }
1586 :
1587 : /*******************************************************************/
1588 : /* */
1589 : /* LENGTH CONVERSIONS */
1590 : /* */
1591 : /*******************************************************************/
1592 : INLINE long
1593 41465 : ndec2nlong(long x) { return 1 + (long)((x)*(LOG2_10/BITS_IN_LONG)); }
1594 : INLINE long
1595 33195 : ndec2prec(long x) { return ndec2nlong(x) << TWOPOTBITS_IN_LONG; }
1596 : INLINE long
1597 8270 : ndec2nbits(long x) { return ndec2nlong(x) << TWOPOTBITS_IN_LONG; }
1598 : /* Fast implementation of ceil(x / (8*sizeof(long))); typecast to (ulong)
1599 : * to avoid overflow. Faster than 1 + ((x-1)>>TWOPOTBITS_IN_LONG)) :
1600 : * addl, shrl instead of subl, sarl, addl */
1601 : INLINE long
1602 12648021 : nbits2nlong(long x) {
1603 12648021 : return (long)(((ulong)x+BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
1604 : }
1605 :
1606 : INLINE long
1607 1499177898 : nbits2extraprec(long x) {
1608 1499177898 : return (((ulong)x+BITS_IN_LONG-1)>>TWOPOTBITS_IN_LONG) << TWOPOTBITS_IN_LONG;
1609 : }
1610 :
1611 : INLINE long
1612 187641216 : nbits2prec(long x) {
1613 187641216 : return (((ulong)x+BITS_IN_LONG-1)>>TWOPOTBITS_IN_LONG) << TWOPOTBITS_IN_LONG;
1614 : }
1615 :
1616 : INLINE long
1617 4513666770 : prec2lg(long x) {
1618 4513666770 : return (long)(((ulong)x+3*BITS_IN_LONG-1) >> TWOPOTBITS_IN_LONG);
1619 : }
1620 : /* ceil(x / sizeof(long)) */
1621 : INLINE long
1622 127394315 : nchar2nlong(long x) {
1623 127394315 : return (long)(((ulong)x+sizeof(long)-1) >> (TWOPOTBITS_IN_LONG-3L));
1624 : }
1625 : INLINE long
1626 105719108 : prec2nbits(long x) { return x; }
1627 : INLINE double
1628 3175436 : bit_accuracy_mul(long x, double y) { return (x-2) * (BITS_IN_LONG*y); }
1629 : INLINE double
1630 581138 : prec2nbits_mul(long x, double y) { return x * y; }
1631 : INLINE long
1632 143022811 : bit_prec(GEN x) { return realprec(x); }
1633 : INLINE long
1634 3163389960 : bit_accuracy(long x) { return (x-2) * BITS_IN_LONG; }
1635 : INLINE long
1636 9778 : prec2ndec(long x) { return (long)(x * LOG10_2); }
1637 : INLINE long
1638 228 : nbits2ndec(long x) { return prec2ndec(x); }
1639 : INLINE long
1640 475475 : precdbl(long x) {return x << 1;}
1641 : INLINE long
1642 8173857660 : divsBIL(long n) { return n >> TWOPOTBITS_IN_LONG; }
1643 : INLINE long
1644 8083951222 : remsBIL(long n) { return n & (BITS_IN_LONG-1); }
1645 :
1646 : /*********************************************************************/
1647 : /** **/
1648 : /** OPERATIONS MODULO m **/
1649 : /** **/
1650 : /*********************************************************************/
1651 : /* Assume m > 0, more efficient if 0 <= a, b < m */
1652 :
1653 : INLINE GEN
1654 82092824 : Fp_red(GEN a, GEN m) { return modii(a, m); }
1655 : INLINE GEN
1656 181600066 : Fp_add(GEN a, GEN b, GEN m)
1657 : {
1658 181600066 : pari_sp av=avma;
1659 181600066 : GEN p = addii(a,b);
1660 181059593 : long s = signe(p);
1661 181059593 : if (!s) return p; /* = gen_0 */
1662 167882217 : if (s > 0) /* general case */
1663 : {
1664 167628319 : GEN t = subii(p, m);
1665 167572014 : s = signe(t);
1666 167572014 : if (!s) return gc_const(av, gen_0);
1667 159344029 : if (s < 0) return gc_const((pari_sp)p, p);
1668 76493282 : if (cmpii(t, m) < 0) return gc_INT(av, t); /* general case ! */
1669 3289369 : p = remii(t, m);
1670 : }
1671 : else
1672 260402 : p = modii(p, m);
1673 3549880 : return gc_INT(av, p);
1674 : }
1675 : INLINE GEN
1676 22251231 : Fp_double(GEN x, GEN N)
1677 : {
1678 22251231 : GEN z = shifti(x, 1);
1679 21882929 : return cmpii(z, N) >= 0? subii(z, N): z;
1680 : }
1681 : INLINE GEN
1682 203527231 : Fp_sub(GEN a, GEN b, GEN m)
1683 : {
1684 203527231 : pari_sp av=avma;
1685 203527231 : GEN p = subii(a,b);
1686 202045122 : long s = signe(p);
1687 202045122 : if (!s) return p; /* = gen_0 */
1688 186356290 : if (s > 0)
1689 : {
1690 93407894 : if (cmpii(p, m) < 0) return p; /* general case ! */
1691 1457681 : p = remii(p, m);
1692 : }
1693 : else
1694 : {
1695 92948396 : GEN t = addii(p, m);
1696 94433409 : if (!s) return gc_const(av, gen_0);
1697 94430865 : if (s > 0) return gc_INT(av, t); /* general case ! */
1698 94430865 : p = modii(t, m);
1699 : }
1700 96184230 : return gc_INT(av, p);
1701 : }
1702 : INLINE GEN
1703 30904832 : Fp_neg(GEN b, GEN m)
1704 : {
1705 30904832 : pari_sp av = avma;
1706 30904832 : long s = signe(b);
1707 : GEN p;
1708 30904832 : if (!s) return gen_0;
1709 26100104 : if (s > 0)
1710 : {
1711 24839106 : p = subii(m, b);
1712 24838768 : if (signe(p) >= 0) return p; /* general case ! */
1713 611065 : p = modii(p, m);
1714 : } else
1715 1261566 : p = remii(negi(b), m);
1716 1872713 : return gc_INT(av, p);
1717 : }
1718 :
1719 : INLINE GEN
1720 247348 : Fp_halve(GEN a, GEN p)
1721 : {
1722 247348 : if (mpodd(a)) a = addii(a,p);
1723 247348 : return shifti(a,-1);
1724 : }
1725 :
1726 : /* assume 0 <= u < p and ps2 = p>>1 */
1727 : INLINE GEN
1728 77238082 : Fp_center(GEN u, GEN p, GEN ps2)
1729 77238082 : { return abscmpii(u,ps2)<=0? icopy(u): subii(u,p); }
1730 : /* same without copy */
1731 : INLINE GEN
1732 18059032 : Fp_center_i(GEN u, GEN p, GEN ps2)
1733 18059032 : { return abscmpii(u,ps2)<=0? u: subii(u,p); }
1734 :
1735 : /* x + y*z mod p */
1736 : INLINE GEN
1737 11384540 : Fp_addmul(GEN x, GEN y, GEN z, GEN p)
1738 : {
1739 : pari_sp av;
1740 11384540 : if (!signe(y) || !signe(z)) return Fp_red(x, p);
1741 11025579 : if (!signe(x)) return Fp_mul(z,y, p);
1742 9994164 : av = avma;
1743 9994164 : return gc_INT(av, modii(addii(x, mulii(y,z)), p));
1744 : }
1745 :
1746 : INLINE GEN
1747 201113517 : Fp_mul(GEN a, GEN b, GEN m)
1748 : {
1749 201113517 : pari_sp av=avma;
1750 : GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
1751 201113517 : (void)new_chunk(lg(a)+lg(b)+(lg(m)<<1));
1752 201178733 : p = mulii(a,b);
1753 201017109 : set_avma(av); return modii(p,m);
1754 : }
1755 : INLINE GEN
1756 64624046 : Fp_sqr(GEN a, GEN m)
1757 : {
1758 64624046 : pari_sp av=avma;
1759 : GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
1760 64624046 : (void)new_chunk((lg(a)+lg(m))<<1);
1761 64983604 : p = sqri(a);
1762 63311328 : set_avma(av); return remii(p,m); /*Use remii: p >= 0 */
1763 : }
1764 : INLINE GEN
1765 67151386 : Fp_mulu(GEN a, ulong b, GEN m)
1766 : {
1767 67151386 : long l = lgefint(m);
1768 67151386 : if (l == 3)
1769 : {
1770 45402450 : ulong mm = m[2];
1771 45402450 : return utoi( Fl_mul(umodiu(a, mm), b, mm) );
1772 : } else {
1773 21748936 : pari_sp av = avma;
1774 : GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
1775 21748936 : (void)new_chunk(lg(a)+1+(l<<1));
1776 21718452 : p = muliu(a,b);
1777 21521015 : set_avma(av); return modii(p,m);
1778 : }
1779 : }
1780 : INLINE GEN
1781 17780 : Fp_muls(GEN a, long b, GEN m)
1782 : {
1783 17780 : long l = lgefint(m);
1784 17780 : if (l == 3)
1785 : {
1786 3578 : ulong mm = m[2];
1787 3578 : if (b < 0)
1788 : {
1789 3578 : ulong t = Fl_mul(umodiu(a, mm), -b, mm);
1790 3578 : return t? utoipos(mm - t): gen_0;
1791 : }
1792 : else
1793 0 : return utoi( Fl_mul(umodiu(a, mm), b, mm) );
1794 : } else {
1795 14202 : pari_sp av = avma;
1796 : GEN p; /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
1797 14202 : (void)new_chunk(lg(a)+1+(l<<1));
1798 14202 : p = mulis(a,b);
1799 14202 : set_avma(av); return modii(p,m);
1800 : }
1801 : }
1802 :
1803 : INLINE GEN
1804 23438174 : Fp_inv(GEN a, GEN m)
1805 : {
1806 : GEN res;
1807 23438174 : if (! invmod(a,m,&res)) pari_err_INV("Fp_inv", mkintmod(res,m));
1808 23437850 : return res;
1809 : }
1810 : INLINE GEN
1811 1100364 : Fp_invsafe(GEN a, GEN m)
1812 : {
1813 : GEN res;
1814 1100364 : if (! invmod(a,m,&res)) return NULL;
1815 1100319 : return res;
1816 : }
1817 : INLINE GEN
1818 15034866 : Fp_div(GEN a, GEN b, GEN m)
1819 : {
1820 15034866 : pari_sp av = avma;
1821 : GEN p;
1822 15034866 : if (lgefint(b) == 3)
1823 : {
1824 13890252 : a = Fp_divu(a, b[2], m);
1825 13891518 : if (signe(b) < 0) a = Fp_neg(a, m);
1826 13891522 : return a;
1827 : }
1828 : /*HACK: assume modii use <=lg(p)+(lg(m)<<1) space*/
1829 1144614 : (void)new_chunk(lg(a)+(lg(m)<<1));
1830 1144615 : p = mulii(a, Fp_inv(b,m));
1831 1144615 : set_avma(av); return modii(p,m);
1832 : }
1833 : INLINE GEN
1834 15134604 : Fp_divu(GEN x, ulong a, GEN p)
1835 : {
1836 15134604 : pari_sp av = avma;
1837 : ulong b;
1838 15134604 : if (lgefint(p) == 3)
1839 : {
1840 14601642 : ulong pp = p[2], xp = umodiu(x, pp);
1841 14602433 : return xp? utoipos(Fl_div(xp, a % pp, pp)): gen_0;
1842 : }
1843 532962 : x = Fp_red(x, p);
1844 532964 : b = Fl_neg(Fl_div(umodiu(x,a), umodiu(p,a), a), a); /* x + pb = 0 (mod a) */
1845 532966 : return gc_INT(av, diviuexact(addmuliu(x, p, b), a));
1846 : }
1847 :
1848 : INLINE GEN
1849 1105157 : Flx_mulu(GEN x, ulong a, ulong p) { return Flx_Fl_mul(x,a%p,p); }
1850 :
1851 : INLINE GEN
1852 2499202 : get_F2x_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
1853 :
1854 : INLINE long
1855 2534154 : get_F2x_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
1856 :
1857 : INLINE long
1858 1929021 : get_F2x_degree(GEN T) { return typ(T)==t_VEC? F2x_degree(gel(T,2)): F2x_degree(T); }
1859 :
1860 : INLINE GEN
1861 343 : get_F2xqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
1862 :
1863 : INLINE long
1864 375375 : get_F2xqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
1865 :
1866 : INLINE long
1867 200851 : get_F2xqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
1868 :
1869 : INLINE GEN
1870 25600253 : get_Flx_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
1871 :
1872 : INLINE long
1873 68358639 : get_Flx_var(GEN T) { return typ(T)==t_VEC? mael(T,2,1): T[1]; }
1874 :
1875 : INLINE long
1876 82210425 : get_Flx_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
1877 :
1878 : INLINE GEN
1879 8033 : get_FlxqX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
1880 :
1881 : INLINE long
1882 264420 : get_FlxqX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
1883 :
1884 : INLINE long
1885 317565 : get_FlxqX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
1886 :
1887 : INLINE GEN
1888 3394346 : get_FpX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
1889 :
1890 : INLINE long
1891 6958054 : get_FpX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
1892 :
1893 : INLINE long
1894 6424546 : get_FpX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
1895 :
1896 : INLINE GEN
1897 146583 : get_FpXQX_mod(GEN T) { return typ(T)==t_VEC? gel(T,2): T; }
1898 :
1899 : INLINE long
1900 51630 : get_FpXQX_var(GEN T) { return typ(T)==t_VEC? varn(gel(T,2)): varn(T); }
1901 :
1902 : INLINE long
1903 3589 : get_FpXQX_degree(GEN T) { return typ(T)==t_VEC? degpol(gel(T,2)): degpol(T); }
1904 :
1905 : /*******************************************************************/
1906 : /* */
1907 : /* ADDMULII / SUBMULII */
1908 : /* */
1909 : /*******************************************************************/
1910 : /* x - y*z */
1911 : INLINE GEN
1912 32847018 : submulii(GEN x, GEN y, GEN z)
1913 : {
1914 32847018 : long lx = lgefint(x), ly, lz;
1915 : pari_sp av;
1916 : GEN t;
1917 32847018 : if (lx == 2) { t = mulii(z,y); togglesign(t); return t; }
1918 30297063 : ly = lgefint(y);
1919 30297063 : if (ly == 2) return icopy(x);
1920 29023951 : lz = lgefint(z);
1921 29023951 : av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
1922 29023951 : t = mulii(z, y);
1923 29023951 : set_avma(av); return subii(x,t);
1924 : }
1925 : /* y*z - x */
1926 : INLINE GEN
1927 3881990 : mulsubii(GEN y, GEN z, GEN x)
1928 : {
1929 3881990 : long lx = lgefint(x), ly, lz;
1930 : pari_sp av;
1931 : GEN t;
1932 3881990 : if (lx == 2) return mulii(z,y);
1933 2451460 : ly = lgefint(y);
1934 2451460 : if (ly == 2) return negi(x);
1935 2166782 : lz = lgefint(z);
1936 2166782 : av = avma; (void)new_chunk(lx+ly+lz); /* HACK */
1937 2166831 : t = mulii(z, y);
1938 2166804 : set_avma(av); return subii(t,x);
1939 : }
1940 :
1941 : /* x - u*y */
1942 : INLINE GEN
1943 7742 : submuliu(GEN x, GEN y, ulong u)
1944 : {
1945 : pari_sp av;
1946 7742 : long ly = lgefint(y);
1947 7742 : if (ly == 2) return icopy(x);
1948 7742 : av = avma;
1949 7742 : (void)new_chunk(3+ly+lgefint(x)); /* HACK */
1950 7742 : y = mului(u,y);
1951 7742 : set_avma(av); return subii(x, y);
1952 : }
1953 : /* x + u*y */
1954 : INLINE GEN
1955 541083 : addmuliu(GEN x, GEN y, ulong u)
1956 : {
1957 : pari_sp av;
1958 541083 : long ly = lgefint(y);
1959 541083 : if (ly == 2) return icopy(x);
1960 541083 : av = avma;
1961 541083 : (void)new_chunk(3+ly+lgefint(x)); /* HACK */
1962 541083 : y = mului(u,y);
1963 541082 : set_avma(av); return addii(x, y);
1964 : }
1965 : /* x - u*y */
1966 : INLINE GEN
1967 60191698 : submuliu_inplace(GEN x, GEN y, ulong u)
1968 : {
1969 : pari_sp av;
1970 60191698 : long ly = lgefint(y);
1971 60191698 : if (ly == 2) return x;
1972 38184686 : av = avma;
1973 38184686 : (void)new_chunk(3+ly+lgefint(x)); /* HACK */
1974 38189782 : y = mului(u,y);
1975 38189686 : set_avma(av); return subii(x, y);
1976 : }
1977 : /* x + u*y */
1978 : INLINE GEN
1979 59704112 : addmuliu_inplace(GEN x, GEN y, ulong u)
1980 : {
1981 : pari_sp av;
1982 59704112 : long ly = lgefint(y);
1983 59704112 : if (ly == 2) return x;
1984 38089871 : av = avma;
1985 38089871 : (void)new_chunk(3+ly+lgefint(x)); /* HACK */
1986 38094834 : y = mului(u,y);
1987 38094597 : set_avma(av); return addii(x, y);
1988 : }
1989 : /* ux + vy */
1990 : INLINE GEN
1991 38209651 : lincombii(GEN u, GEN v, GEN x, GEN y)
1992 : {
1993 38209651 : long lx = lgefint(x), ly;
1994 : GEN p1, p2;
1995 : pari_sp av;
1996 38209651 : if (lx == 2) return mulii(v,y);
1997 24015727 : ly = lgefint(y);
1998 24015727 : if (ly == 2) return mulii(u,x);
1999 21279469 : av = avma; (void)new_chunk(lx+ly+lgefint(u)+lgefint(v)); /* HACK */
2000 21282671 : p1 = mulii(u,x);
2001 21281544 : p2 = mulii(v,y);
2002 21281395 : set_avma(av); return addii(p1,p2);
2003 : }
2004 :
2005 : /*******************************************************************/
2006 : /* */
2007 : /* GEN SUBTYPES */
2008 : /* */
2009 : /*******************************************************************/
2010 :
2011 : INLINE int
2012 4890801953 : is_const_t(long t) { return (t < t_POLMOD); }
2013 : INLINE int
2014 6876 : is_extscalar_t(long t) { return (t <= t_POL); }
2015 : INLINE int
2016 9583840 : is_intreal_t(long t) { return (t <= t_REAL); }
2017 : INLINE int
2018 659223779 : is_matvec_t(long t) { return (t >= t_VEC && t <= t_MAT); }
2019 : INLINE int
2020 85862163 : is_noncalc_t(long tx) { return (tx) >= t_LIST; }
2021 : INLINE int
2022 0 : is_qfb_t(long t) { return (t == t_QFB); }
2023 : INLINE int
2024 5035176 : is_rational_t(long t) { return (t == t_INT || t == t_FRAC); }
2025 : INLINE int
2026 62657945 : is_real_t(long t) { return (t == t_INT || t == t_REAL || t == t_FRAC); }
2027 : INLINE int
2028 9245165443 : is_recursive_t(long t) { return lontyp[t]; }
2029 : INLINE int
2030 375643929 : is_scalar_t(long t) { return (t < t_POL); }
2031 : INLINE int
2032 43954288 : is_vec_t(long t) { return (t == t_VEC || t == t_COL); }
2033 :
2034 : INLINE int
2035 62949606 : qfb_is_qfi(GEN q) { return signe(gel(q,4)) < 0; }
2036 :
2037 : /*******************************************************************/
2038 : /* */
2039 : /* TRANSCENDENTAL */
2040 : /* */
2041 : /*******************************************************************/
2042 : INLINE GEN
2043 80370183 : sqrtr(GEN x) {
2044 80370183 : long s = signe(x);
2045 80370183 : if (s == 0) return real_0_bit(expo(x) >> 1);
2046 80337068 : if (s >= 0) return sqrtr_abs(x);
2047 439937 : retmkcomplex(gen_0, sqrtr_abs(x));
2048 : }
2049 : INLINE GEN
2050 0 : cbrtr_abs(GEN x) { return sqrtnr_abs(x, 3); }
2051 : INLINE GEN
2052 0 : cbrtr(GEN x) {
2053 0 : long s = signe(x);
2054 : GEN r;
2055 0 : if (s == 0) return real_0_bit(expo(x) / 3);
2056 0 : r = cbrtr_abs(x);
2057 0 : if (s < 0) togglesign(r);
2058 0 : return r;
2059 : }
2060 : INLINE GEN
2061 2807255 : sqrtnr(GEN x, long n) {
2062 2807255 : long s = signe(x);
2063 : GEN r;
2064 2807255 : if (s == 0) return real_0_bit(expo(x) / n);
2065 2807255 : r = sqrtnr_abs(x, n);
2066 2807232 : if (s < 0) pari_err_IMPL("sqrtnr for x < 0");
2067 2807231 : return r;
2068 : }
2069 : INLINE long
2070 755027 : logint(GEN B, GEN y) { return logintall(B,y,NULL); }
2071 : INLINE ulong
2072 1736078 : ulogint(ulong B, ulong y)
2073 : {
2074 : ulong r;
2075 : long e;
2076 1736078 : if (y == 2) return expu(B);
2077 1688050 : r = y;
2078 5106954 : for (e=1;; e++)
2079 : { /* here, r = y^e, r2 = y^(e-1) */
2080 5106954 : if (r >= B) return r == B? e: e-1;
2081 3420385 : r = umuluu_or_0(y, r);
2082 3420403 : if (!r) return e;
2083 : }
2084 : }
2085 :
2086 : /*******************************************************************/
2087 : /* */
2088 : /* MISCELLANEOUS */
2089 : /* */
2090 : /*******************************************************************/
2091 9583724 : INLINE int ismpzero(GEN x) { return is_intreal_t(typ(x)) && !signe(x); }
2092 2839028391 : INLINE int isintzero(GEN x) { return typ(x) == t_INT && !signe(x); }
2093 17571631 : INLINE int isint1(GEN x) { return typ(x)==t_INT && equali1(x); }
2094 5703978 : INLINE int isintm1(GEN x){ return typ(x)==t_INT && equalim1(x);}
2095 1175153274 : INLINE int equali1(GEN n)
2096 1175153274 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(1)) && n[2] == 1; }
2097 139504281 : INLINE int equalim1(GEN n)
2098 139504281 : { return (ulong) n[1] == (evallgefint(3UL) | evalsigne(-1)) && n[2] == 1; }
2099 : /* works only for POSITIVE integers */
2100 2202109300 : INLINE int is_pm1(GEN n)
2101 2202109300 : { return lgefint(n) == 3 && n[2] == 1; }
2102 562589668 : INLINE int is_bigint(GEN n)
2103 562589668 : { long l = lgefint(n); return l > 3 || (l == 3 && (n[2] & HIGHBIT)); }
2104 :
2105 2085100914 : INLINE int odd(long x) { return x & 1; }
2106 124004630 : INLINE int both_odd(long x, long y) { return x & y & 1; }
2107 :
2108 : INLINE int
2109 8255529339 : isonstack(GEN x)
2110 8255529339 : { return ((pari_sp)x >= pari_mainstack->bot
2111 8255529339 : && (pari_sp)x < pari_mainstack->top); }
2112 :
2113 : /* assume x != 0 and x t_REAL, return an approximation to log2(|x|) */
2114 : INLINE double
2115 94007189 : dbllog2r(GEN x)
2116 94007189 : { return log2((double)(ulong)x[2]) + (double)(expo(x) - (BITS_IN_LONG-1)); }
2117 :
2118 : INLINE GEN
2119 2654167 : mul_content(GEN cx, GEN cy)
2120 : {
2121 2654167 : if (!cx) return cy;
2122 568141 : if (!cy) return cx;
2123 374428 : return gmul(cx,cy);
2124 : }
2125 : INLINE GEN
2126 0 : inv_content(GEN c) { return c? ginv(c): NULL; }
2127 : INLINE GEN
2128 58476 : div_content(GEN cx, GEN cy)
2129 : {
2130 58476 : if (!cy) return cx;
2131 57342 : if (!cx) return ginv(cy);
2132 25990 : return gdiv(cx,cy);
2133 : }
2134 : INLINE GEN
2135 10710165 : mul_denom(GEN dx, GEN dy)
2136 : {
2137 10710165 : if (!dx) return dy;
2138 1840412 : if (!dy) return dx;
2139 1371922 : return mulii(dx,dy);
2140 : }
2141 :
2142 : /* POLYNOMIALS */
2143 : INLINE GEN
2144 1441512 : constant_coeff(GEN x) { return signe(x)? gel(x,2): gen_0; }
2145 : INLINE GEN
2146 170554747 : leading_coeff(GEN x) { return lg(x) == 2? gen_0: gel(x,lg(x)-1); }
2147 : INLINE ulong
2148 980500 : Flx_lead(GEN x) { return lg(x) == 2? 0: x[lg(x)-1]; }
2149 : INLINE ulong
2150 332028 : Flx_constant(GEN x) { return lg(x) == 2? 0: x[2]; }
2151 : INLINE long
2152 5500601377 : degpol(GEN x) { return lg(x)-3; }
2153 : INLINE long
2154 2681143575 : lgpol(GEN x) { return lg(x)-2; }
2155 : INLINE long
2156 350252855 : lgcols(GEN x) { return lg(gel(x,1)); }
2157 : INLINE long
2158 157477630 : nbrows(GEN x) { return lg(gel(x,1))-1; }
2159 : INLINE GEN
2160 0 : truecoef(GEN x, long n) { return polcoef(x,n,-1); }
2161 :
2162 : INLINE GEN
2163 2162084 : ZXQ_mul(GEN y, GEN x, GEN T) { return ZX_rem(ZX_mul(y, x), T); }
2164 : INLINE GEN
2165 961075 : ZXQ_sqr(GEN x, GEN T) { return ZX_rem(ZX_sqr(x), T); }
2166 :
2167 : INLINE GEN
2168 103404617 : RgX_copy(GEN x)
2169 376322800 : { pari_APPLY_pol_normalized(gcopy(gel(x,i))); }
2170 : /* have to use ulong to avoid silly warnings from gcc "assuming signed
2171 : * overflow does not occur" */
2172 : INLINE GEN
2173 2669140 : RgX_coeff(GEN x, long n)
2174 : {
2175 2669140 : ulong l = lg(x);
2176 2669140 : return (n < 0 || ((ulong)n+3) > l)? gen_0: gel(x,n+2);
2177 : }
2178 : INLINE GEN
2179 349807 : RgX_renormalize(GEN x) { return RgX_renormalize_lg(x, lg(x)); }
2180 : INLINE GEN
2181 7000740 : RgX_div(GEN x, GEN y) { return RgX_divrem(x,y,NULL); }
2182 : INLINE GEN
2183 1904 : RgXQX_div(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,NULL); }
2184 : INLINE GEN
2185 127635 : RgXQX_rem(GEN x, GEN y, GEN T) { return RgXQX_divrem(x,y,T,ONLY_REM); }
2186 : INLINE GEN
2187 5580979 : FpX_div(GEN x, GEN y, GEN p) { return FpX_divrem(x,y,p, NULL); }
2188 : INLINE GEN
2189 1999030 : Flx_div(GEN x, GEN y, ulong p) { return Flx_divrem(x,y,p, NULL); }
2190 : INLINE GEN
2191 21703850 : Flx_div_pre(GEN x, GEN y, ulong p, ulong pi)
2192 21703850 : { return Flx_divrem_pre(x,y,p,pi, NULL); }
2193 : INLINE GEN
2194 1571194 : F2x_div(GEN x, GEN y) { return F2x_divrem(x,y, NULL); }
2195 : INLINE GEN
2196 0 : FpV_FpC_mul(GEN x, GEN y, GEN p) { return FpV_dotproduct(x,y,p); }
2197 : INLINE GEN
2198 103507297 : pol0_Flx(long sv) { return mkvecsmall(sv); }
2199 : INLINE GEN
2200 55056231 : pol1_Flx(long sv) { return mkvecsmall2(sv, 1); }
2201 : INLINE GEN
2202 37825260 : polx_Flx(long sv) { return mkvecsmall3(sv, 0, 1); }
2203 : INLINE GEN
2204 0 : zero_zx(long sv) { return zero_Flx(sv); }
2205 : INLINE GEN
2206 0 : polx_zx(long sv) { return polx_Flx(sv); }
2207 : INLINE GEN
2208 0 : zx_shift(GEN x, long n) { return Flx_shift(x,n); }
2209 : INLINE GEN
2210 14049 : zx_renormalize(GEN x, long l) { return Flx_renormalize(x,l); }
2211 : INLINE GEN
2212 1350 : zero_F2x(long sv) { return zero_Flx(sv); }
2213 : INLINE GEN
2214 13246598 : pol0_F2x(long sv) { return pol0_Flx(sv); }
2215 : INLINE GEN
2216 3957634 : pol1_F2x(long sv) { return pol1_Flx(sv); }
2217 : INLINE GEN
2218 1078870 : polx_F2x(long sv) { return mkvecsmall2(sv, 2); }
2219 : INLINE int
2220 2874063 : F2x_equal1(GEN x) { return Flx_equal1(x); }
2221 : INLINE int
2222 4662069 : F2x_equal(GEN V, GEN W) { return Flx_equal(V,W); }
2223 : INLINE GEN
2224 60441252 : F2x_copy(GEN x) { return leafcopy(x); }
2225 : INLINE GEN
2226 4487 : F2v_copy(GEN x) { return leafcopy(x); }
2227 : INLINE GEN
2228 2555341 : Flv_copy(GEN x) { return leafcopy(x); }
2229 : INLINE GEN
2230 173781139 : Flx_copy(GEN x) { return leafcopy(x); }
2231 : INLINE GEN
2232 4404233 : vecsmall_copy(GEN x) { return leafcopy(x); }
2233 : INLINE int
2234 8327223 : Flx_equal1(GEN x) { return degpol(x)==0 && x[2] == 1; }
2235 : INLINE int
2236 12711 : ZX_equal1(GEN x) { return degpol(x)==0 && equali1(gel(x,2)); }
2237 : INLINE int
2238 7376013 : ZX_is_monic(GEN x) { return equali1(leading_coeff(x)); }
2239 :
2240 : INLINE GEN
2241 155010738 : ZX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
2242 : INLINE GEN
2243 144588286 : FpX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
2244 : INLINE GEN
2245 849896 : FpXX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
2246 : INLINE GEN
2247 4693673 : FpXQX_renormalize(GEN x, long lx) { return ZXX_renormalize(x,lx); }
2248 : INLINE GEN
2249 115190573 : F2x_renormalize(GEN x, long lx) { return Flx_renormalize(x,lx); }
2250 :
2251 : INLINE GEN
2252 0 : F2xX_shift(GEN a, long n, long vs) { return FlxX_shift(a, n, vs); }
2253 :
2254 : INLINE GEN
2255 37827 : F2v_to_F2x(GEN x, long sv) {
2256 37827 : GEN y = leafcopy(x);
2257 37827 : y[1] = sv; F2x_renormalize(y, lg(y)); return y;
2258 : }
2259 :
2260 : INLINE long
2261 385 : sturm(GEN x) { return sturmpart(x, NULL, NULL); }
2262 :
2263 : INLINE long
2264 5824 : gval(GEN x, long v)
2265 5824 : { pari_sp av = avma; return gc_long(av, gvaluation(x, pol_x(v))); }
2266 :
2267 : INLINE void
2268 479366 : RgX_shift_inplace_init(long v)
2269 479366 : { if (v) (void)cgetg(v, t_VECSMALL); }
2270 : /* shift polynomial in place. assume v free cells have been left before x */
2271 : INLINE GEN
2272 479366 : RgX_shift_inplace(GEN x, long v)
2273 : {
2274 : long i, lx;
2275 : GEN z;
2276 479366 : if (!v) return x;
2277 252260 : lx = lg(x);
2278 252260 : if (lx == 2) return x;
2279 252260 : z = x + lx;
2280 : /* stackdummy's from normalizepol */
2281 252260 : while (lg(z) != v) z += lg(z);
2282 252260 : z += v;
2283 4637681 : for (i = lx-1; i >= 2; i--) gel(--z,0) = gel(x,i);
2284 672402 : for (i = 0; i < v; i++) gel(--z,0) = gen_0;
2285 252260 : z -= 2;
2286 252260 : z[1] = x[1];
2287 252260 : z[0] = evaltyp(t_POL) | evallg(lx+v);
2288 252260 : stackdummy((pari_sp)z, (pari_sp)x); return z;
2289 : }
2290 :
2291 :
2292 : /* LINEAR ALGEBRA */
2293 : INLINE GEN
2294 502996 : zv_to_ZV(GEN x) { return vecsmall_to_vec(x); }
2295 : INLINE GEN
2296 7823563 : zc_to_ZC(GEN x) { return vecsmall_to_col(x); }
2297 : INLINE GEN
2298 3211415 : ZV_to_zv(GEN x) { return vec_to_vecsmall(x); }
2299 : INLINE GEN
2300 0 : zx_to_zv(GEN x, long N) { return Flx_to_Flv(x,N); }
2301 : INLINE GEN
2302 104146 : zv_to_zx(GEN x, long sv) { return Flv_to_Flx(x,sv); }
2303 : INLINE GEN
2304 0 : zm_to_zxV(GEN x, long sv) { return Flm_to_FlxV(x,sv); }
2305 : INLINE GEN
2306 0 : zero_zm(long x, long y) { return zero_Flm(x,y); }
2307 : INLINE GEN
2308 36737831 : zero_zv(long x) { return zero_Flv(x); }
2309 : INLINE GEN
2310 266 : zm_transpose(GEN x) { return Flm_transpose(x); }
2311 : INLINE GEN
2312 0 : zm_copy(GEN x) { return Flm_copy(x); }
2313 : INLINE GEN
2314 2184085 : zv_copy(GEN x) { return Flv_copy(x); }
2315 : INLINE GEN
2316 0 : zm_row(GEN x, long i) { return Flm_row(x,i); }
2317 :
2318 : INLINE GEN
2319 10690847 : ZC_hnfrem(GEN x, GEN y) { return ZC_hnfdivrem(x,y,NULL); }
2320 : INLINE GEN
2321 363868 : ZM_hnfrem(GEN x, GEN y) { return ZM_hnfdivrem(x,y,NULL); }
2322 : INLINE GEN
2323 7112436 : ZM_lll(GEN x, double D, long f) { return ZM_lll_norms(x,D,f,NULL); }
2324 : INLINE void
2325 9741991 : RgM_dimensions(GEN x, long *m, long *n) { *n = lg(x)-1; *m = *n? nbrows(x): 0; }
2326 : INLINE GEN
2327 22169825 : RgM_shallowcopy(GEN x)
2328 96121414 : { pari_APPLY_same(leafcopy(gel(x,i))); }
2329 : INLINE GEN
2330 200499 : F2m_copy(GEN x) { return RgM_shallowcopy(x); }
2331 :
2332 : INLINE GEN
2333 0 : F3m_copy(GEN x) { return RgM_shallowcopy(x); }
2334 :
2335 : INLINE GEN
2336 6433591 : Flm_copy(GEN x) { return RgM_shallowcopy(x); }
2337 :
2338 : /* divisibility: return 1 if y[i] | x[i] for all i, 0 otherwise. Assume
2339 : * x,y are ZV of the same length */
2340 : INLINE int
2341 23485 : ZV_dvd(GEN x, GEN y)
2342 : {
2343 23485 : long i, l = lg(x);
2344 37856 : for (i=1; i < l; i++)
2345 30464 : if ( ! dvdii( gel(x,i), gel(y,i) ) ) return 0;
2346 7392 : return 1;
2347 : }
2348 : INLINE GEN
2349 596596 : ZM_ZV_mod(GEN x, GEN y)
2350 1765648 : { pari_APPLY_same(ZV_ZV_mod(gel(x,i), y)) }
2351 : INLINE GEN
2352 8131299 : ZV_ZV_mod(GEN x, GEN y)
2353 22497416 : { pari_APPLY_same(modii(gel(x,i), gel(y,i))) }
2354 : INLINE GEN
2355 0 : vecmodii(GEN x, GEN y) { return ZV_ZV_mod(x,y); }
2356 : INLINE GEN
2357 174881 : vecmoduu(GEN x, GEN y) { pari_APPLY_ulong(((ulong*)x)[i] % ((ulong*)y)[i]) }
2358 :
2359 : /* Fq */
2360 : INLINE GEN
2361 3106350 : Fq_red(GEN x, GEN T, GEN p)
2362 3106350 : { return typ(x)==t_INT? Fp_red(x,p): FpXQ_red(x,T,p); }
2363 : INLINE GEN
2364 73792 : Fq_to_FpXQ(GEN x, GEN T, GEN p /*unused*/)
2365 : {
2366 : (void) p;
2367 73792 : return typ(x)==t_INT ? scalarpol(x, get_FpX_var(T)): x;
2368 : }
2369 : INLINE GEN
2370 756 : Rg_to_Fq(GEN x, GEN T, GEN p) { return T? Rg_to_FpXQ(x,T,p): Rg_to_Fp(x,p); }
2371 :
2372 : INLINE GEN
2373 29932 : gener_Fq_local(GEN T, GEN p, GEN L)
2374 0 : { return T? gener_FpXQ_local(T,p, L)
2375 29932 : : pgener_Fp_local(p, L); }
2376 :
2377 : INLINE GEN
2378 0 : random_Fq(GEN T, GEN p)
2379 0 : { return T ? random_FpX(get_FpX_degree(T), get_FpX_var(T), p): randomi(p); }
2380 :
2381 : /* FpXQX */
2382 : INLINE GEN
2383 4526 : FpXQX_div(GEN x, GEN y, GEN T, GEN p) { return FpXQX_divrem(x, y, T, p, NULL); }
2384 : INLINE GEN
2385 0 : FlxqX_div(GEN x, GEN y, GEN T, ulong p) { return FlxqX_divrem(x, y, T, p, NULL); }
2386 : INLINE GEN
2387 165416 : FlxqX_div_pre(GEN x, GEN y, GEN T, ulong p, ulong pi) { return FlxqX_divrem_pre(x, y, T, p, pi, NULL); }
2388 : INLINE GEN
2389 33173 : F2xqX_div(GEN x, GEN y, GEN T) { return F2xqX_divrem(x, y, T, NULL); }
2390 :
2391 : INLINE GEN
2392 20587 : FpXY_Fq_evaly(GEN Q, GEN y, GEN T, GEN p, long vx)
2393 20587 : { return T ? FpXY_FpXQ_evaly(Q, y, T, p, vx): FpXY_evaly(Q, y, p, vx); }
2394 :
2395 : /* FqX */
2396 : INLINE GEN
2397 25354 : FqX_red(GEN z, GEN T, GEN p) { return T? FpXQX_red(z, T, p): FpX_red(z, p); }
2398 : INLINE GEN
2399 127694 : FqX_add(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
2400 : INLINE GEN
2401 24956 : FqX_neg(GEN x,GEN T,GEN p) { return T? FpXX_neg(x,p): FpX_neg(x,p); }
2402 : INLINE GEN
2403 68607 : FqX_sub(GEN x,GEN y,GEN T,GEN p) { return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
2404 : INLINE GEN
2405 572123 : FqX_Fp_mul(GEN P, GEN u, GEN T, GEN p)
2406 572123 : { return T? FpXX_Fp_mul(P, u, p): FpX_Fp_mul(P, u, p); }
2407 : INLINE GEN
2408 427290 : FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p)
2409 427290 : { return typ(U)==t_INT ? FqX_Fp_mul(P, U, T, p): FpXQX_FpXQ_mul(P, U, T, p); }
2410 : INLINE GEN
2411 367817 : FqX_mul(GEN x, GEN y, GEN T, GEN p)
2412 367817 : { return T? FpXQX_mul(x, y, T, p): FpX_mul(x, y, p); }
2413 : INLINE GEN
2414 21942 : FqX_mulu(GEN x, ulong y, GEN T, GEN p)
2415 21942 : { return T? FpXX_mulu(x, y, p): FpX_mulu(x, y, p); }
2416 : INLINE GEN
2417 71855 : FqX_sqr(GEN x, GEN T, GEN p)
2418 71855 : { return T? FpXQX_sqr(x, T, p): FpX_sqr(x, p); }
2419 : INLINE GEN
2420 1295 : FqX_powu(GEN x, ulong n, GEN T, GEN p)
2421 1295 : { return T? FpXQX_powu(x, n, T, p): FpX_powu(x, n, p); }
2422 : INLINE GEN
2423 19411 : FqX_halve(GEN x, GEN T, GEN p)
2424 19411 : { return T? FpXX_halve(x, p): FpX_halve(x, p); }
2425 : INLINE GEN
2426 38546 : FqX_div(GEN x, GEN y, GEN T, GEN p)
2427 38546 : { return T? FpXQX_divrem(x,y,T,p,NULL): FpX_divrem(x,y,p,NULL); }
2428 : INLINE GEN
2429 6090 : FqX_get_red(GEN S, GEN T, GEN p)
2430 6090 : { return T? FpXQX_get_red(S,T,p): FpX_get_red(S,p); }
2431 : INLINE GEN
2432 37743 : FqX_rem(GEN x, GEN y, GEN T, GEN p)
2433 37743 : { return T? FpXQX_rem(x,y,T,p): FpX_rem(x,y,p); }
2434 : INLINE GEN
2435 0 : FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z)
2436 0 : { return T? FpXQX_divrem(x,y,T,p,z): FpX_divrem(x,y,p,z); }
2437 : INLINE GEN
2438 69629 : FqX_div_by_X_x(GEN x, GEN y, GEN T, GEN p, GEN *z)
2439 69629 : { return T? FpXQX_div_by_X_x(x,y,T,p,z): FpX_div_by_X_x(x,y,p,z); }
2440 : INLINE GEN
2441 0 : FqX_halfgcd(GEN P,GEN Q,GEN T,GEN p)
2442 0 : {return T? FpXQX_halfgcd(P,Q,T,p): FpX_halfgcd(P,Q,p);}
2443 : INLINE GEN
2444 8246 : FqX_gcd(GEN P,GEN Q,GEN T,GEN p)
2445 8246 : {return T? FpXQX_gcd(P,Q,T,p): FpX_gcd(P,Q,p);}
2446 : INLINE GEN
2447 445049 : FqX_extgcd(GEN P,GEN Q,GEN T,GEN p, GEN *U, GEN *V)
2448 445049 : { return T? FpXQX_extgcd(P,Q,T,p,U,V): FpX_extgcd(P,Q,p,U,V); }
2449 : INLINE GEN
2450 4123 : FqX_normalize(GEN z, GEN T, GEN p)
2451 4123 : { return T? FpXQX_normalize(z, T, p): FpX_normalize(z, p); }
2452 : INLINE GEN
2453 40061 : FqX_deriv(GEN f, GEN T, GEN p) { return T? FpXX_deriv(f, p): FpX_deriv(f, p); }
2454 : INLINE long
2455 683802 : FqX_is_squarefree(GEN P, GEN T, GEN p)
2456 683802 : { return T ? FpXQX_is_squarefree(P, T, p): FpX_is_squarefree(P, p); }
2457 : INLINE GEN
2458 0 : FqX_integ(GEN f, GEN T, GEN p) { return T? FpXX_integ(f, p): FpX_integ(f, p); }
2459 : INLINE GEN
2460 141051 : FqX_factor(GEN f, GEN T, GEN p)
2461 141051 : { return T?FpXQX_factor(f, T, p): FpX_factor(f, p); }
2462 : INLINE GEN
2463 7 : FqX_factor_squarefree(GEN f, GEN T, GEN p)
2464 7 : { return T ? FpXQX_factor_squarefree(f, T, p): FpX_factor_squarefree(f, p); }
2465 : INLINE GEN
2466 7 : FqX_ddf(GEN f, GEN T, GEN p)
2467 7 : { return T ? FpXQX_ddf(f, T, p): FpX_ddf(f, p); }
2468 : INLINE GEN
2469 47786 : FqX_degfact(GEN f, GEN T, GEN p)
2470 47786 : { return T?FpXQX_degfact(f, T, p): FpX_degfact(f, p); }
2471 : INLINE GEN
2472 7273 : FqX_roots(GEN f, GEN T, GEN p)
2473 7273 : { return T?FpXQX_roots(f, T, p): FpX_roots(f, p); }
2474 : INLINE GEN
2475 175 : FqX_to_mod(GEN f, GEN T, GEN p)
2476 175 : { return T?FpXQX_to_mod(f, T, p): FpX_to_mod(f, p); }
2477 :
2478 : /*FqXQ*/
2479 : INLINE GEN
2480 0 : FqXQ_add(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
2481 0 : { (void)S; return T? FpXX_add(x,y,p): FpX_add(x,y,p); }
2482 : INLINE GEN
2483 0 : FqXQ_sub(GEN x, GEN y, GEN S/*unused*/, GEN T, GEN p)
2484 0 : { (void)S; return T? FpXX_sub(x,y,p): FpX_sub(x,y,p); }
2485 : INLINE GEN
2486 0 : FqXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p)
2487 0 : { return T? FpXQXQ_div(x,y,S,T,p): FpXQ_div(x,y,S,p); }
2488 : INLINE GEN
2489 0 : FqXQ_inv(GEN x, GEN S, GEN T, GEN p)
2490 0 : { return T? FpXQXQ_inv(x,S,T,p): FpXQ_inv(x,S,p); }
2491 : INLINE GEN
2492 0 : FqXQ_invsafe(GEN x, GEN S, GEN T, GEN p)
2493 0 : { return T? FpXQXQ_invsafe(x,S,T,p): FpXQ_inv(x,S,p); }
2494 : INLINE GEN
2495 22766 : FqXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p)
2496 22766 : { return T? FpXQXQ_mul(x,y,S,T,p): FpXQ_mul(x,y,S,p); }
2497 : INLINE GEN
2498 0 : FqXQ_sqr(GEN x, GEN S, GEN T, GEN p)
2499 0 : { return T? FpXQXQ_sqr(x,S,T,p): FpXQ_sqr(x,S,p); }
2500 : INLINE GEN
2501 0 : FqXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p)
2502 0 : { return T? FpXQXQ_pow(x,n,S,T,p): FpXQ_pow(x,n,S,p); }
2503 :
2504 : /*FqXn*/
2505 : INLINE GEN
2506 6590 : FqXn_expint(GEN x, long n, GEN T, GEN p)
2507 6590 : { return T? FpXQXn_expint(x,n,T,p): FpXn_expint(x,n,p); }
2508 : INLINE GEN
2509 0 : FqXn_exp(GEN x, long n, GEN T, GEN p)
2510 0 : { return T? FpXQXn_exp(x,n,T,p): FpXn_exp(x,n,p); }
2511 : INLINE GEN
2512 7126 : FqXn_inv(GEN x, long n, GEN T, GEN p)
2513 7126 : { return T? FpXQXn_inv(x,n,T,p): FpXn_inv(x,n,p); }
2514 : INLINE GEN
2515 263403 : FqXn_mul(GEN x, GEN y, long n, GEN T, GEN p)
2516 263403 : { return T? FpXQXn_mul(x, y, n, T, p): FpXn_mul(x, y, n, p); }
2517 : INLINE GEN
2518 0 : FqXn_sqr(GEN x, long n, GEN T, GEN p)
2519 0 : { return T? FpXQXn_sqr(x,n,T,p): FpXn_sqr(x,n,p); }
2520 :
2521 : /*FpXQ*/
2522 : INLINE GEN
2523 0 : FpXQ_add(GEN x,GEN y,GEN T/*unused*/,GEN p)
2524 0 : { (void)T; return FpX_add(x,y,p); }
2525 : INLINE GEN
2526 0 : FpXQ_sub(GEN x,GEN y,GEN T/*unused*/,GEN p)
2527 0 : { (void)T; return FpX_sub(x,y,p); }
2528 :
2529 : /*Flxq*/
2530 : INLINE GEN
2531 0 : Flxq_add(GEN x,GEN y,GEN T/*unused*/,ulong p)
2532 0 : { (void)T; return Flx_add(x,y,p); }
2533 : INLINE GEN
2534 0 : Flxq_sub(GEN x,GEN y,GEN T/*unused*/,ulong p)
2535 0 : { (void)T; return Flx_sub(x,y,p); }
2536 :
2537 : /* F2x */
2538 :
2539 : INLINE ulong
2540 667904652 : F2x_coeff(GEN x,long v)
2541 : {
2542 667904652 : ulong u=(ulong)x[2+divsBIL(v)];
2543 667898676 : return (u>>remsBIL(v))&1UL;
2544 : }
2545 :
2546 : INLINE void
2547 12355753 : F2x_clear(GEN x,long v)
2548 : {
2549 12355753 : ulong* u=(ulong*)&x[2+divsBIL(v)];
2550 12355724 : *u&=~(1UL<<remsBIL(v));
2551 12355695 : }
2552 :
2553 : INLINE void
2554 124731961 : F2x_set(GEN x,long v)
2555 : {
2556 124731961 : ulong* u=(ulong*)&x[2+divsBIL(v)];
2557 124728079 : *u|=1UL<<remsBIL(v);
2558 124728845 : }
2559 :
2560 : INLINE void
2561 1554251 : F2x_flip(GEN x,long v)
2562 : {
2563 1554251 : ulong* u=(ulong*)&x[2+divsBIL(v)];
2564 1554251 : *u^=1UL<<remsBIL(v);
2565 1554251 : }
2566 :
2567 : /* F2v */
2568 :
2569 : INLINE ulong
2570 661330708 : F2v_coeff(GEN x,long v) { return F2x_coeff(x,v-1); }
2571 :
2572 : INLINE void
2573 12355765 : F2v_clear(GEN x,long v) { F2x_clear(x,v-1); }
2574 :
2575 : INLINE void
2576 101404465 : F2v_set(GEN x,long v) { F2x_set(x,v-1); }
2577 :
2578 : INLINE void
2579 1554251 : F2v_flip(GEN x,long v) { F2x_flip(x,v-1); }
2580 :
2581 : /* F2m */
2582 :
2583 : INLINE ulong
2584 8039263 : F2m_coeff(GEN x, long a, long b) { return F2v_coeff(gel(x,b), a); }
2585 :
2586 : INLINE void
2587 0 : F2m_clear(GEN x, long a, long b) { F2v_clear(gel(x,b), a); }
2588 :
2589 : INLINE void
2590 798 : F2m_set(GEN x, long a, long b) { F2v_set(gel(x,b), a); }
2591 :
2592 : INLINE void
2593 1554251 : F2m_flip(GEN x, long a, long b) { F2v_flip(gel(x,b), a); }
2594 :
2595 : /* F3m */
2596 :
2597 : INLINE ulong
2598 3256766 : F3m_coeff(GEN x, long a, long b) { return F3v_coeff(gel(x,b), a); }
2599 :
2600 : INLINE void
2601 0 : F3m_set(GEN x, long a, long b, ulong c) { F3v_set(gel(x,b), a, c); }
2602 :
2603 : /* ARITHMETIC */
2604 : INLINE GEN
2605 3885 : matpascal(long n) { return matqpascal(n, NULL); }
2606 : INLINE long
2607 458920 : Z_issquare(GEN x) { return Z_issquareall(x, NULL); }
2608 : INLINE long
2609 98 : Z_ispower(GEN x, ulong k) { return Z_ispowerall(x, k, NULL); }
2610 : INLINE GEN
2611 6665702 : sqrti(GEN x) { return sqrtremi(x,NULL); }
2612 : INLINE GEN
2613 123249097 : gaddgs(GEN y, long s) { return gaddsg(s,y); }
2614 : INLINE int
2615 761923 : gcmpgs(GEN y, long s) { return -gcmpsg(s,y); }
2616 : INLINE int
2617 29176 : gequalgs(GEN y, long s) { return gequalsg(s,y); }
2618 : INLINE GEN
2619 0 : gmaxsg(long s, GEN y) { return gmaxgs(y,s); }
2620 : INLINE GEN
2621 0 : gminsg(long s, GEN y) { return gmings(y,s); }
2622 : INLINE GEN
2623 22526604 : gmulgs(GEN y, long s) { return gmulsg(s,y); }
2624 : INLINE GEN
2625 282058132 : gmulgu(GEN y, ulong s) { return gmulug(s,y); }
2626 : INLINE GEN
2627 1727503 : gsubgs(GEN y, long s) { return gaddgs(y, -s); }
2628 : INLINE GEN
2629 531333 : gdivsg(long s, GEN y) { return gdiv(stoi(s), y); }
2630 :
2631 : INLINE GEN
2632 13510221 : gmax_shallow(GEN x, GEN y) { return gcmp(x,y)<0? y: x; }
2633 : INLINE GEN
2634 876379 : gmin_shallow(GEN x, GEN y) { return gcmp(x,y)<0? x: y; }
2635 :
2636 : /* x t_COMPLEX */
2637 : INLINE GEN
2638 90941605 : cxnorm(GEN x) { return gadd(gsqr(gel(x,1)), gsqr(gel(x,2))); }
2639 : /* q t_QUAD */
2640 : INLINE GEN
2641 69881 : quadnorm(GEN q)
2642 : {
2643 69881 : GEN X = gel(q,1), b = gel(X,3), c = gel(X,2);
2644 69881 : GEN z, u = gel(q,3), v = gel(q,2);
2645 69881 : if (typ(u) == t_INT && typ(v) == t_INT) /* generic case */
2646 : {
2647 69671 : z = signe(b)? mulii(v, addii(u,v)): sqri(v);
2648 69671 : return addii(z, mulii(c, sqri(u)));
2649 : }
2650 : else
2651 : {
2652 210 : z = signe(b)? gmul(v, gadd(u,v)): gsqr(v);
2653 210 : return gadd(z, gmul(c, gsqr(u)));
2654 : }
2655 : }
2656 : /* x a t_QUAD, return the attached discriminant */
2657 : INLINE GEN
2658 1085 : quad_disc(GEN x)
2659 : {
2660 1085 : GEN Q = gel(x,1), b = gel(Q,3), c = gel(Q,2), c4 = shifti(c,2);
2661 1085 : if (is_pm1(b)) return subsi(1, c4);
2662 154 : togglesign_safe(&c4); return c4;
2663 : }
2664 : INLINE GEN
2665 4990691 : qfb_disc3(GEN x, GEN y, GEN z) { return subii(sqri(y), shifti(mulii(x,z),2)); }
2666 : INLINE GEN
2667 18514509 : qfb_disc(GEN x) { return gel(x,4); }
2668 :
2669 : INLINE GEN
2670 4148145 : sqrfrac(GEN x)
2671 : {
2672 4148145 : GEN z = cgetg(3,t_FRAC);
2673 4148143 : gel(z,1) = sqri(gel(x,1));
2674 4148127 : gel(z,2) = sqri(gel(x,2)); return z;
2675 : }
2676 :
2677 : INLINE void
2678 17204939 : normalize_frac(GEN z) {
2679 17204939 : if (signe(gel(z,2)) < 0) { togglesign(gel(z,1)); setabssign(gel(z,2)); }
2680 17204939 : }
2681 :
2682 : INLINE GEN
2683 43176747 : powii(GEN x, GEN n)
2684 : {
2685 43176747 : long ln = lgefint(n);
2686 43176747 : if (ln == 3) {
2687 : GEN z;
2688 43135125 : if (signe(n) > 0) return powiu(x, n[2]);
2689 75038 : z = cgetg(3, t_FRAC);
2690 75056 : gel(z,1) = gen_1;
2691 75056 : gel(z,2) = powiu(x, n[2]);
2692 75053 : return z;
2693 : }
2694 41622 : if (ln == 2) return gen_1; /* rare */
2695 : /* should never happen */
2696 0 : return powgi(x, n); /* overflow unless x = 0, 1, -1 */
2697 : }
2698 : INLINE GEN
2699 1561 : powIs(long n) {
2700 1561 : switch(n & 3)
2701 : {
2702 63 : case 1: return mkcomplex(gen_0,gen_1);
2703 385 : case 2: return gen_m1;
2704 707 : case 3: return mkcomplex(gen_0,gen_m1);
2705 : }
2706 406 : return gen_1;
2707 : }
2708 :
2709 : /*******************************************************************/
2710 : /* */
2711 : /* ELLIPTIC CURVES */
2712 : /* */
2713 : /*******************************************************************/
2714 8996370 : INLINE GEN ell_get_a1(GEN e) { return gel(e,1); }
2715 7105469 : INLINE GEN ell_get_a2(GEN e) { return gel(e,2); }
2716 8813338 : INLINE GEN ell_get_a3(GEN e) { return gel(e,3); }
2717 8536010 : INLINE GEN ell_get_a4(GEN e) { return gel(e,4); }
2718 10370248 : INLINE GEN ell_get_a6(GEN e) { return gel(e,5); }
2719 7369848 : INLINE GEN ell_get_b2(GEN e) { return gel(e,6); }
2720 2549033 : INLINE GEN ell_get_b4(GEN e) { return gel(e,7); }
2721 3861932 : INLINE GEN ell_get_b6(GEN e) { return gel(e,8); }
2722 3297414 : INLINE GEN ell_get_b8(GEN e) { return gel(e,9); }
2723 10728685 : INLINE GEN ell_get_c4(GEN e) { return gel(e,10); }
2724 12892042 : INLINE GEN ell_get_c6(GEN e) { return gel(e,11); }
2725 16525561 : INLINE GEN ell_get_disc(GEN e) { return gel(e,12); }
2726 2126227 : INLINE GEN ell_get_j(GEN e) { return gel(e,13); }
2727 12499487 : INLINE long ell_get_type(GEN e) { return mael(e,14,1); }
2728 2036861 : INLINE GEN ellff_get_field(GEN x) { return gmael(x, 15, 1); }
2729 800030 : INLINE GEN ellff_get_a4a6(GEN x) { return gmael(x, 15, 2); }
2730 1463 : INLINE GEN ellQp_get_zero(GEN x) { return gmael(x, 15, 1); }
2731 308 : INLINE long ellQp_get_prec(GEN E) { return valp(ellQp_get_zero(E)); }
2732 1134 : INLINE GEN ellQp_get_p(GEN E) { return padic_p(ellQp_get_zero(E)); }
2733 232750 : INLINE long ellR_get_prec(GEN x) { return nbits2prec(mael3(x, 15, 1, 1)); }
2734 371535 : INLINE long ellR_get_sign(GEN x) { return mael3(x, 15, 1, 2); }
2735 2027599 : INLINE GEN ellnf_get_nf(GEN x) { return checknf_i(gmael(x,15,1)); }
2736 126 : INLINE GEN ellnf_get_bnf(GEN x) { return checkbnf_i(gmael(x,15,1)); }
2737 :
2738 5593352 : INLINE int checkell_i(GEN e) { return typ(e) == t_VEC && lg(e) == 17; }
2739 52495991 : INLINE int ell_is_inf(GEN z) { return lg(z) == 2; }
2740 1868458 : INLINE GEN ellinf(void) { return mkvec(gen_0); }
2741 :
2742 : /*******************************************************************/
2743 : /* */
2744 : /* ALGEBRAIC NUMBER THEORY */
2745 : /* */
2746 : /*******************************************************************/
2747 31237999 : INLINE GEN modpr_get_pr(GEN x) { return gel(x,3); }
2748 1888432 : INLINE GEN modpr_get_p(GEN x) { return pr_get_p(modpr_get_pr(x)); }
2749 13867586 : INLINE GEN modpr_get_T(GEN x) { return lg(x) == 4? NULL: gel(x,4); }
2750 :
2751 91709034 : INLINE GEN pr_get_p(GEN pr) { return gel(pr,1); }
2752 12062185 : INLINE GEN pr_get_gen(GEN pr){ return gel(pr,2); }
2753 : /* .[2] instead of itos works: e and f are small positive integers */
2754 15952826 : INLINE long pr_get_e(GEN pr) { return gel(pr,3)[2]; }
2755 26041037 : INLINE long pr_get_f(GEN pr) { return gel(pr,4)[2]; }
2756 48872022 : INLINE GEN pr_get_tau(GEN pr){ return gel(pr,5); }
2757 : INLINE int
2758 16910178 : pr_is_inert(GEN P) { return typ(pr_get_tau(P)) == t_INT; }
2759 : INLINE GEN
2760 1088534 : pr_norm(GEN pr) { return powiu(pr_get_p(pr), pr_get_f(pr)); }
2761 : INLINE ulong
2762 346136 : upr_norm(GEN pr) { return upowuu(pr_get_p(pr)[2], pr_get_f(pr)); }
2763 :
2764 : /* assume nf a genuine nf */
2765 : INLINE long
2766 1503581 : nf_get_varn(GEN nf) { return varn(gel(nf,1)); }
2767 : INLINE GEN
2768 98057792 : nf_get_pol(GEN nf) { return gel(nf,1); }
2769 : INLINE long
2770 71351623 : nf_get_degree(GEN nf) { return degpol( nf_get_pol(nf) ); }
2771 : INLINE long
2772 22892567 : nf_get_r1(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,1)); }
2773 : INLINE long
2774 4154 : nf_get_r2(GEN nf) { GEN x = gel(nf,2); return itou(gel(x,2)); }
2775 : INLINE GEN
2776 463862 : nf_get_disc(GEN nf) { return gel(nf,3); }
2777 : INLINE GEN
2778 3711328 : nf_get_index(GEN nf) { return gel(nf,4); }
2779 : INLINE GEN
2780 21172058 : nf_get_M(GEN nf) { return gmael(nf,5,1); }
2781 : INLINE GEN
2782 303561 : nf_get_G(GEN nf) { return gmael(nf,5,2); }
2783 : INLINE GEN
2784 1746581 : nf_get_roundG(GEN nf) { return gmael(nf,5,3); }
2785 : INLINE GEN
2786 22080 : nf_get_Tr(GEN nf) { return gmael(nf,5,4); }
2787 : INLINE GEN
2788 4438 : nf_get_diff(GEN nf) { return gmael(nf,5,5); }
2789 : INLINE GEN
2790 64813 : nf_get_ramified_primes(GEN nf) { return gmael(nf,5,8); }
2791 : INLINE GEN
2792 1627817 : nf_get_roots(GEN nf) { return gel(nf,6); }
2793 : INLINE GEN
2794 4382 : nf_get_zk(GEN nf)
2795 : {
2796 4382 : GEN y = gel(nf,7), D = gel(y, 1);
2797 4382 : if (typ(D) == t_POL) D = gel(D, 2);
2798 4382 : if (!equali1(D)) y = gdiv(y, D);
2799 4382 : return y;
2800 : }
2801 : INLINE GEN
2802 5416321 : nf_get_zkprimpart(GEN nf)
2803 : {
2804 5416321 : GEN y = gel(nf,7);
2805 : /* test for old format of nf.zk: non normalized */
2806 5416321 : if (!equali1(gel(nf,4)) && gequal1(gel(y,1))) y = Q_remove_denom(y,NULL);
2807 5416326 : return y;
2808 : }
2809 : INLINE GEN
2810 5462158 : nf_get_zkden(GEN nf)
2811 : {
2812 5462158 : GEN y = gel(nf,7), D = gel(y,1);
2813 5462158 : if (typ(D) == t_POL) D = gel(D,2);
2814 : /* test for old format of nf.zk: non normalized */
2815 5462158 : if (!equali1(gel(nf,4)) && equali1(D)) D = Q_denom(y);
2816 5462152 : return D;
2817 : }
2818 : INLINE GEN
2819 9765429 : nf_get_invzk(GEN nf) { return gel(nf,8); }
2820 : INLINE void
2821 519552 : nf_get_sign(GEN nf, long *r1, long *r2)
2822 : {
2823 519552 : GEN x = gel(nf,2);
2824 519552 : *r1 = itou(gel(x,1));
2825 519552 : *r2 = itou(gel(x,2));
2826 519552 : }
2827 :
2828 : INLINE GEN
2829 2757773 : cyc_get_expo(GEN c) { return lg(c) == 1? gen_1: gel(c,1); }
2830 : INLINE GEN
2831 355190 : abgrp_get_no(GEN x) { return gel(x,1); }
2832 : INLINE GEN
2833 12230211 : abgrp_get_cyc(GEN x) { return gel(x,2); }
2834 : INLINE GEN
2835 1765031 : abgrp_get_gen(GEN x) { return gel(x,3); }
2836 : INLINE GEN
2837 9863704 : bnf_get_nf(GEN bnf) { return gel(bnf,7); }
2838 : INLINE GEN
2839 5374933 : bnf_get_clgp(GEN bnf) { return gmael(bnf,8,1); }
2840 : INLINE GEN
2841 8372 : bnf_get_no(GEN bnf) { return abgrp_get_no(bnf_get_clgp(bnf)); }
2842 : INLINE GEN
2843 3686070 : bnf_get_cyc(GEN bnf) { return abgrp_get_cyc(bnf_get_clgp(bnf)); }
2844 : INLINE GEN
2845 1680317 : bnf_get_gen(GEN bnf) { return abgrp_get_gen(bnf_get_clgp(bnf)); }
2846 : INLINE GEN
2847 648 : bnf_get_reg(GEN bnf) { return gmael(bnf,8,2); }
2848 : INLINE GEN
2849 2874717 : bnf_get_logfu(GEN bnf) { return gel(bnf,3); }
2850 : INLINE GEN
2851 1367780 : bnf_get_sunits(GEN bnf)
2852 1367780 : { GEN s = gmael(bnf,8,3); return typ(s) == t_INT? NULL: s; }
2853 : INLINE GEN
2854 303581 : bnf_get_tuU(GEN bnf) { return gmael3(bnf,8,4,2); }
2855 : INLINE long
2856 283005 : bnf_get_tuN(GEN bnf) { return gmael3(bnf,8,4,1)[2]; }
2857 : INLINE GEN
2858 289081 : bnf_get_fu_nocheck(GEN bnf) { return gmael(bnf,8,5); }
2859 : INLINE GEN
2860 26300 : nfV_to_scalar_or_alg(GEN nf, GEN x)
2861 63441 : { pari_APPLY_same(nf_to_scalar_or_alg(nf, gel(x,i))) }
2862 : INLINE GEN
2863 25859 : bnf_get_fu(GEN bnf) {
2864 25859 : GEN fu = bnf_build_units(bnf), nf = bnf_get_nf(bnf);
2865 25859 : if (typ(fu) == t_MAT) pari_err(e_MISC,"missing units in bnf");
2866 25859 : return nfV_to_scalar_or_alg(nf, vecslice(fu, 2, lg(fu)-1));
2867 : }
2868 :
2869 : INLINE GEN
2870 3750899 : bnr_get_bnf(GEN bnr) { return gel(bnr,1); }
2871 : INLINE GEN
2872 2045870 : bnr_get_bid(GEN bnr) { return gel(bnr,2); }
2873 : INLINE GEN
2874 77117 : bnr_get_mod(GEN bnr) { return gmael(bnr,2,1); }
2875 : INLINE GEN
2876 1368099 : bnr_get_nf(GEN bnr) { return gmael(bnr,1,7); }
2877 : INLINE GEN
2878 2830007 : bnr_get_clgp(GEN bnr) { return gel(bnr,5); }
2879 : INLINE GEN
2880 277497 : bnr_get_no(GEN bnr) { return abgrp_get_no(bnr_get_clgp(bnr)); }
2881 : INLINE GEN
2882 2522328 : bnr_get_cyc(GEN bnr) { return abgrp_get_cyc(bnr_get_clgp(bnr)); }
2883 : INLINE GEN
2884 70 : bnr_get_gen_nocheck(GEN bnr) { return abgrp_get_gen(bnr_get_clgp(bnr)); }
2885 : INLINE GEN
2886 7847 : bnr_get_gen(GEN bnr) {
2887 7847 : GEN G = bnr_get_clgp(bnr);
2888 7847 : if (lg(G) != 4)
2889 0 : pari_err(e_MISC,"missing bnr generators: please use bnrinit(,,1)");
2890 7847 : return gel(G,3);
2891 : }
2892 :
2893 : /* localstar, used in gchar */
2894 : INLINE GEN
2895 52136 : locs_get_cyc(GEN locs) { return gel(locs,1); }
2896 : INLINE GEN
2897 193935 : locs_get_Lsprk(GEN locs) { return gel(locs,2); }
2898 : INLINE GEN
2899 1288 : locs_get_Lgenfil(GEN locs) { return gel(locs,3); }
2900 : INLINE GEN
2901 8225 : locs_get_mod(GEN locs) { return gel(locs,4); }
2902 : /* pr dividing the modulus N of locs, 0 <= i < v_pr(N)
2903 : * return a t_MAT whose columns are the logs
2904 : * of generators of U_i(pr)/U_{i+1}(pr). */
2905 : INLINE GEN
2906 1288 : locs_get_famod(GEN locs) { return gmael(locs,4,1); }
2907 : INLINE GEN
2908 209475 : locs_get_m_infty(GEN locs) { return gmael(locs,4,2); }
2909 :
2910 : /* G a grossenchar group */
2911 : INLINE GEN
2912 32816 : gchar_get_basis(GEN gc) { return gel(gc, 1); }
2913 : INLINE GEN
2914 205373 : gchar_get_bnf(GEN gc) { return gel(gc, 2); }
2915 : INLINE GEN
2916 243932 : gchar_get_nf(GEN gc) { return gel(gc, 3); }
2917 : INLINE GEN
2918 281911 : gchar_get_zm(GEN gc) { return gel(gc, 4); }
2919 : INLINE GEN
2920 8225 : gchar_get_mod(GEN gc) { return locs_get_mod(gchar_get_zm(gc)); }
2921 : INLINE GEN
2922 4095 : gchar_get_modP(GEN gc) { return gmael(gchar_get_mod(gc),1,1); }
2923 : INLINE GEN
2924 36995 : gchar_get_S(GEN gc) { return gel(gc, 5); }
2925 : INLINE GEN
2926 190673 : gchar_get_DLdata(GEN gc) { return gel(gc, 6); }
2927 : INLINE GEN
2928 1743 : gchar_get_sfu(GEN gc) { return gel(gc, 7); }
2929 : INLINE GEN
2930 16177 : gchar_get_cyc(GEN gc) { return gel(gc, 9); }
2931 : INLINE GEN
2932 0 : gchar_get_hnf(GEN gc) { return gmael(gc, 10, 1); }
2933 : INLINE GEN
2934 0 : gchar_get_U(GEN gc) { return gmael(gc, 10, 2); }
2935 : INLINE GEN
2936 10983 : gchar_get_Ui(GEN gc) { return gmael(gc, 10, 3); }
2937 : INLINE GEN
2938 3318 : gchar_get_m0(GEN gc) { return gel(gc, 11); }
2939 : INLINE GEN
2940 4252 : gchar_get_u0(GEN gc) { return gel(gc, 12); }
2941 : INLINE long
2942 17444 : gchar_get_r1(GEN gc) { return nf_get_r1(gchar_get_nf(gc)); }
2943 : INLINE long
2944 623 : gchar_get_r2(GEN gc) { return nf_get_r2(gchar_get_nf(gc)); }
2945 : INLINE GEN
2946 50519 : gchar_get_loccyc(GEN gc) { return locs_get_cyc(gchar_get_zm(gc)); }
2947 : INLINE long
2948 37261 : gchar_get_nc(GEN gc) { return lg(gchar_get_loccyc(gc))-1; }
2949 : INLINE long
2950 36995 : gchar_get_ns(GEN gc) { return lg(gchar_get_S(gc))-1; }
2951 : INLINE long
2952 1869 : gchar_get_nm(GEN gc) { return lg(gchar_get_basis(gc))-1; }
2953 : INLINE long
2954 4011 : gchar_get_evalprec(GEN gc) { return gmael(gc, 8, 1)[1]; }
2955 : INLINE long
2956 18795 : gchar_get_prec(GEN gc) { return gmael(gc, 8, 1)[2]; }
2957 : INLINE long
2958 13468 : gchar_get_nfprec(GEN gc) { return gmael(gc, 8, 1)[3]; }
2959 : INLINE void
2960 1813 : gchar_set_evalprec(GEN gc, long prec) { gmael(gc, 8, 1)[1] = prec; }
2961 : INLINE void
2962 1225 : gchar_set_prec(GEN gc, long prec) { gmael(gc, 8, 1)[2] = prec; }
2963 : INLINE void
2964 1225 : gchar_copy_precs(GEN gc, GEN gc2)
2965 : {
2966 1225 : gel(gc2, 8) = shallowcopy(gel(gc,8));
2967 1225 : gmael(gc2, 8, 1) = shallowcopy(gmael(gc, 8, 1));
2968 1225 : }
2969 : INLINE void
2970 2968 : gchar_set_nfprec(GEN gc, long prec) { gmael(gc, 8, 1)[3] = prec; }
2971 : INLINE long
2972 322 : gchar_get_ntors(GEN gc) { return gmael(gc, 8, 2)[1]; }
2973 : INLINE long
2974 322 : gchar_get_nfree(GEN gc) { return gmael(gc, 8, 2)[2]; }
2975 : INLINE long
2976 2044 : gchar_get_nalg(GEN gc) { return gmael(gc, 8, 2)[3]; }
2977 : INLINE void
2978 1575 : gchar_set_basis(GEN gc, GEN m_inv) { gel(gc, 1) = m_inv; }
2979 : INLINE void
2980 2110 : gchar_set_nf(GEN gc, GEN nf) { gel(gc, 3) = nf; }
2981 : INLINE void
2982 630 : gchar_set_ntors(GEN gc, long n) { gmael(gc, 8, 2)[1] = n; }
2983 : INLINE void
2984 630 : gchar_set_nfree(GEN gc, long n) { gmael(gc, 8, 2)[2] = n; }
2985 : INLINE void
2986 630 : gchar_set_nalg(GEN gc, long n) { gmael(gc, 8, 2)[3] = n; }
2987 : INLINE void
2988 1575 : gchar_set_cyc(GEN gc, GEN cyc) { gel(gc, 9) = cyc; }
2989 : INLINE void
2990 630 : gchar_set_HUUi(GEN gc, GEN hnf, GEN U, GEN Ui) { gel(gc, 10) = mkvec3(hnf, U, Ui); }
2991 : INLINE void
2992 945 : gchar_set_m0(GEN gc, GEN m0) { gel(gc, 11) = m0; }
2993 : INLINE void
2994 2121 : gchar_set_u0(GEN gc, GEN u0) { gel(gc, 12) = u0; }
2995 :
2996 : INLINE GEN
2997 1521922 : bid_get_mod(GEN bid) { return gel(bid,1); }
2998 : INLINE GEN
2999 72842 : bid_get_ideal(GEN bid) { return gmael(bid,1,1); }
3000 : INLINE GEN
3001 41188 : bid_get_arch(GEN bid) { return gmael(bid,1,2); }
3002 : INLINE GEN
3003 5804425 : bid_get_grp(GEN bid) { return gel(bid,2); }
3004 : INLINE GEN
3005 2498939 : bid_get_fact(GEN bid) { return gmael(bid,3,1); }
3006 : INLINE GEN
3007 2201577 : bid_get_fact2(GEN bid) { return gmael(bid,3,2); }
3008 : INLINE GEN
3009 2157255 : bid_get_MOD(GEN bid) { GEN y = gel(bid,4); return lg(y) == 4? gel(y,3): NULL; }
3010 : INLINE GEN
3011 2157986 : bid_get_sprk(GEN bid) { return gmael(bid,4,1); }
3012 : INLINE GEN
3013 48594 : bid_get_sarch(GEN bid) { return gmael(bid,4,2); }
3014 : INLINE GEN
3015 2397108 : bid_get_archp(GEN bid) { return gmael3(bid,4,2,2); }
3016 : INLINE GEN
3017 3680237 : bid_get_U(GEN bid) { return gel(bid,5); }
3018 : INLINE GEN
3019 0 : bid_get_no(GEN bid) { return abgrp_get_no(bid_get_grp(bid)); }
3020 : INLINE GEN
3021 5739572 : bid_get_cyc(GEN bid) { return abgrp_get_cyc(bid_get_grp(bid)); }
3022 : INLINE GEN
3023 0 : bid_get_gen_nocheck(GEN bid) { return abgrp_get_gen(bid_get_grp(bid)); }
3024 : INLINE GEN
3025 64274 : bid_get_gen(GEN bid) {
3026 64274 : GEN G = bid_get_grp(bid);
3027 64274 : if (lg(G) != 4) pari_err(e_MISC,"missing bid generators. Use idealstar(,,2)");
3028 64274 : return abgrp_get_gen(G);
3029 : }
3030 :
3031 : INLINE GEN
3032 38653757 : znstar_get_N(GEN G) { return gmael(G,1,1); }
3033 : INLINE GEN
3034 7330731 : znstar_get_faN(GEN G) { return gel(G,3); }
3035 : INLINE GEN
3036 14 : znstar_get_no(GEN G) { return abgrp_get_no(gel(G,2)); }
3037 : INLINE GEN
3038 262088 : znstar_get_cyc(GEN G) { return abgrp_get_cyc(gel(G,2)); }
3039 : INLINE GEN
3040 16150 : znstar_get_gen(GEN G) { return abgrp_get_gen(gel(G,2)); }
3041 : INLINE GEN
3042 7978902 : znstar_get_conreycyc(GEN G) { return gmael(G,4,5); }
3043 : INLINE GEN
3044 3289889 : znstar_get_conreygen(GEN G) { return gmael(G,4,4); }
3045 : INLINE GEN
3046 46788 : znstar_get_Ui(GEN G) { return gmael(G,4,3); }
3047 : INLINE GEN
3048 176107 : znstar_get_U(GEN G) { return gel(G,5); }
3049 : INLINE GEN
3050 2868790 : znstar_get_pe(GEN G) { return gmael(G,4,1); }
3051 : INLINE GEN
3052 36337 : gal_get_pol(GEN gal) { return gel(gal,1); }
3053 : INLINE GEN
3054 6020 : gal_get_p(GEN gal) { return gmael(gal,2,1); }
3055 : INLINE GEN
3056 91 : gal_get_e(GEN gal) { return gmael(gal,2,2); }
3057 : INLINE GEN
3058 23772 : gal_get_mod(GEN gal) { return gmael(gal,2,3); }
3059 : INLINE GEN
3060 32753 : gal_get_roots(GEN gal) { return gel(gal,3); }
3061 : INLINE GEN
3062 27881 : gal_get_invvdm(GEN gal) { return gel(gal,4); }
3063 : INLINE GEN
3064 27874 : gal_get_den(GEN gal) { return gel(gal,5); }
3065 : INLINE GEN
3066 80394 : gal_get_group(GEN gal) { return gel(gal,6); }
3067 : INLINE GEN
3068 15449 : gal_get_gen(GEN gal) { return gel(gal,7); }
3069 : INLINE GEN
3070 6678 : gal_get_orders(GEN gal) { return gel(gal,8); }
3071 :
3072 : /* assume rnf a genuine rnf */
3073 : INLINE long
3074 2506307 : rnf_get_degree(GEN rnf) { return degpol(rnf_get_pol(rnf)); }
3075 : INLINE long
3076 21455 : rnf_get_nfdegree(GEN rnf) { return degpol(nf_get_pol(rnf_get_nf(rnf))); }
3077 : INLINE long
3078 1392746 : rnf_get_absdegree(GEN rnf) { return degpol(gmael(rnf,11,1)); }
3079 : INLINE GEN
3080 1386 : rnf_get_idealdisc(GEN rnf) { return gmael(rnf,3,1); }
3081 : INLINE GEN
3082 1225 : rnf_get_k(GEN rnf) { return gmael(rnf,11,3); }
3083 : INLINE GEN
3084 1428 : rnf_get_alpha(GEN rnf) { return gmael(rnf, 11, 2); }
3085 : INLINE GEN
3086 786030 : rnf_get_nf(GEN rnf) { return gel(rnf,10); }
3087 : INLINE GEN
3088 7245 : rnf_get_nfzk(GEN rnf) { return gel(rnf,2); }
3089 : INLINE GEN
3090 327628 : rnf_get_polabs(GEN rnf) { return gmael(rnf,11,1); }
3091 : INLINE GEN
3092 2845157 : rnf_get_pol(GEN rnf) { return gel(rnf,1); }
3093 : INLINE GEN
3094 350 : rnf_get_disc(GEN rnf) { return gel(rnf,3); }
3095 : INLINE GEN
3096 105 : rnf_get_index(GEN rnf) { return gel(rnf,4); }
3097 : INLINE GEN
3098 2849 : rnf_get_ramified_primes(GEN rnf) { return gel(rnf,5); }
3099 : INLINE long
3100 574 : rnf_get_varn(GEN rnf) { return varn(gel(rnf,1)); }
3101 : INLINE GEN
3102 255354 : rnf_get_nfpol(GEN rnf) { return gmael(rnf,10,1); }
3103 : INLINE long
3104 4886 : rnf_get_nfvarn(GEN rnf) { return varn(gmael(rnf,10,1)); }
3105 : INLINE GEN
3106 4830 : rnf_get_zk(GEN rnf) { return gel(rnf,7); }
3107 : INLINE GEN
3108 135659 : rnf_get_map(GEN rnf) { return gel(rnf,11); }
3109 : INLINE GEN
3110 1225 : rnf_get_invzk(GEN rnf) { return gel(rnf,8); }
3111 :
3112 : INLINE GEN
3113 138519 : idealred(GEN nf, GEN id) { return idealred0(nf, id, NULL); }
3114 :
3115 : INLINE GEN
3116 5427 : idealchineseinit(GEN nf, GEN x)
3117 5427 : { return idealchinese(nf,x,NULL); }
3118 :
3119 : /*******************************************************************/
3120 : /* */
3121 : /* CLOSURES */
3122 : /* */
3123 : /*******************************************************************/
3124 370520091 : INLINE long closure_arity(GEN C) { return ((ulong)C[1])&ARITYBITS; }
3125 40152946 : INLINE long closure_is_variadic(GEN C) { return !!(((ulong)C[1])&VARARGBITS); }
3126 320684157 : INLINE const char *closure_codestr(GEN C) { return GSTR(gel(C,2))-1; }
3127 0 : INLINE GEN closure_get_code(GEN C) { return gel(C,2); }
3128 320658550 : INLINE GEN closure_get_oper(GEN C) { return gel(C,3); }
3129 320630922 : INLINE GEN closure_get_data(GEN C) { return gel(C,4); }
3130 13621 : INLINE GEN closure_get_dbg(GEN C) { return gel(C,5); }
3131 37051 : INLINE GEN closure_get_text(GEN C) { return gel(C,6); }
3132 14147581 : INLINE GEN closure_get_frame(GEN C) { return gel(C,7); }
3133 :
3134 : /*******************************************************************/
3135 : /* */
3136 : /* ERRORS */
3137 : /* */
3138 : /*******************************************************************/
3139 : INLINE long
3140 62529 : err_get_num(GEN e) { return e[1]; }
3141 : INLINE GEN
3142 294 : err_get_compo(GEN e, long i) { return gel(e, i+1); }
3143 :
3144 : INLINE void
3145 14 : pari_err_BUG(const char *f) { pari_err(e_BUG,f); }
3146 : INLINE void
3147 21 : pari_err_CONSTPOL(const char *f) { pari_err(e_CONSTPOL, f); }
3148 : INLINE void
3149 84 : pari_err_COPRIME(const char *f, GEN x, GEN y) { pari_err(e_COPRIME, f,x,y); }
3150 : INLINE void
3151 718 : pari_err_DIM(const char *f) { pari_err(e_DIM, f); }
3152 : INLINE void
3153 0 : pari_err_FILE(const char *f, const char *g) { pari_err(e_FILE, f,g); }
3154 : INLINE void
3155 36 : pari_err_FILEDESC(const char *f, long n) { pari_err(e_FILEDESC, f,n); }
3156 : INLINE void
3157 98 : pari_err_FLAG(const char *f) { pari_err(e_FLAG,f); }
3158 : INLINE void
3159 539 : pari_err_IMPL(const char *f) { pari_err(e_IMPL,f); }
3160 : INLINE void
3161 20018 : pari_err_INV(const char *f, GEN x) { pari_err(e_INV,f,x); }
3162 : INLINE void
3163 63 : pari_err_IRREDPOL(const char *f, GEN x) { pari_err(e_IRREDPOL, f,x); }
3164 : INLINE void
3165 2841 : 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); }
3166 : INLINE void
3167 214 : pari_err_COMPONENT(const char *f, const char *op, GEN l, GEN x) { pari_err(e_COMPONENT, f,op,l,x); }
3168 : INLINE void
3169 0 : pari_err_MAXPRIME(ulong c) { pari_err(e_MAXPRIME, c); }
3170 : INLINE void
3171 406 : pari_err_OP(const char *f, GEN x, GEN y) { pari_err(e_OP, f,x,y); }
3172 : INLINE void
3173 156 : pari_err_OVERFLOW(const char *f) { pari_err(e_OVERFLOW, f); }
3174 : INLINE void
3175 238 : pari_err_PREC(const char *f) { pari_err(e_PREC,f); }
3176 : INLINE void
3177 0 : pari_err_PACKAGE(const char *f) { pari_err(e_PACKAGE,f); }
3178 : INLINE void
3179 98 : pari_err_PRIME(const char *f, GEN x) { pari_err(e_PRIME, f,x); }
3180 : INLINE void
3181 1316 : pari_err_MODULUS(const char *f, GEN x, GEN y) { pari_err(e_MODULUS, f,x,y); }
3182 : INLINE void
3183 63 : pari_err_ROOTS0(const char *f) { pari_err(e_ROOTS0, f); }
3184 : INLINE void
3185 7084 : pari_err_SQRTN(const char *f, GEN x) { pari_err(e_SQRTN, f,x); }
3186 : INLINE void
3187 15398 : pari_err_TYPE(const char *f, GEN x) { pari_err(e_TYPE, f,x); }
3188 : INLINE void
3189 3493 : pari_err_TYPE2(const char *f, GEN x, GEN y) { pari_err(e_TYPE2, f,x,y); }
3190 : INLINE void
3191 371 : pari_err_VAR(const char *f, GEN x, GEN y) { pari_err(e_VAR, f,x,y); }
3192 : INLINE void
3193 238 : pari_err_PRIORITY(const char *f, GEN x, const char *op, long v)
3194 238 : { pari_err(e_PRIORITY, f,x,op,v); }
3195 :
|