Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

Testing latest pari + WASM + node.js... and it works?! Wow.

28485 views
License: GPL3
ubuntu2004
1
/* Copyright (C) 2000-2003 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
#include "pari.h"
16
#include "paripriv.h"
17
18
/********************************************************************/
19
/** **/
20
/** MEMBER FUNCTIONS **/
21
/** **/
22
/********************************************************************/
23
INLINE int
24
is_ell5(GEN x) {
25
long lx;
26
if (typ(x) != t_VEC) return 0;
27
lx = lg(x);
28
return lx == 17 || (lx == 6 && !is_vec_t(typ(gel(x,2))));
29
}
30
INLINE int is_ell(GEN x) {
31
long lx = lg(x);
32
return (typ(x) == t_VEC && lx == 17);
33
}
34
35
static void
36
member_err(const char *s, GEN y) { pari_err_TYPE(s,y); }
37
38
GEN
39
member_e(GEN x)
40
{
41
GEN y = get_prid(x);
42
if (!y) member_err("e",x);
43
return gel(y,3);
44
}
45
46
GEN
47
member_f(GEN x)
48
{
49
GEN y = get_prid(x);
50
if (!y)
51
{
52
if (typ(x) == t_FFELT) return utoipos(FF_f(x));
53
member_err("f",x);
54
}
55
return gel(y,4);
56
}
57
58
GEN
59
member_p(GEN x)
60
{
61
long t; GEN y = get_nf(x,&t);
62
if (y)
63
{
64
if (t == typ_RNF) return rnf_get_ramified_primes(x);
65
return nf_get_ramified_primes(y);
66
}
67
switch(t)
68
{
69
case typ_GAL: return gal_get_p(x);
70
case typ_ELL: switch(ell_get_type(x))
71
{
72
case t_ELL_Fp:
73
case t_ELL_Fq: return ellff_get_p(x);
74
case t_ELL_Qp: return ellQp_get_p(x);
75
default: member_err("p",x);
76
}
77
case typ_MODPR: x = get_prid(x);
78
case typ_PRID: return pr_get_p(x);
79
}
80
switch(typ(x)) {
81
case t_PADIC: return gel(x,2);
82
case t_FFELT: return FF_p_i(x);
83
}
84
member_err("p",x);
85
return NULL;
86
}
87
88
GEN
89
member_bid(GEN x)
90
{
91
long t; (void)get_nf(x,&t);
92
switch(t) {
93
case typ_BNR: return bnr_get_bid(x);
94
case typ_BIDZ:
95
case typ_BID: return x;
96
}
97
member_err("bid",x);
98
return NULL;
99
}
100
101
GEN
102
member_bnf(GEN x)
103
{
104
long t; GEN y = get_bnf(x,&t);
105
if (!y) {
106
if (t == typ_ELL && ell_get_type(x) == t_ELL_NF)
107
{
108
y = ellnf_get_bnf(x);
109
if (y) return y;
110
}
111
member_err("bnf",x);
112
}
113
return y;
114
}
115
116
GEN
117
member_nf(GEN x)
118
{
119
long t; GEN y = get_nf(x,&t);
120
if (!y) {
121
if (t == typ_RNF) return gel(x,10);
122
if (t == typ_ELL && ell_get_type(x) == t_ELL_NF) return ellnf_get_nf(x);
123
member_err("nf",x);
124
}
125
return y;
126
}
127
128
/* integral basis */
129
GEN
130
member_zk(GEN x)
131
{
132
long t; GEN y = get_nf(x,&t);
133
if (!y)
134
{
135
switch(t)
136
{
137
case typ_Q:
138
y = cgetg(3,t_VEC);
139
gel(y,1) = gen_1;
140
gel(y,2) = pol_x(varn(gel(x,1))); return y;
141
case typ_RNF:
142
return gel(x,7);
143
}
144
member_err("zk",x);
145
}
146
return nf_get_zk(y);
147
}
148
149
GEN
150
member_disc(GEN x) /* discriminant */
151
{
152
long t; GEN y = get_nf(x,&t);
153
if (!y)
154
{
155
switch(t)
156
{
157
case typ_Q : return quad_disc(x);
158
case typ_QFB: return qfb_disc(x);
159
case typ_ELL: return ell_get_disc(x);
160
case typ_RNF: return rnf_get_disc(x);
161
}
162
member_err("disc",x);
163
}
164
return nf_get_disc(y);
165
}
166
167
GEN
168
member_pol(GEN x) /* polynomial */
169
{
170
long t; GEN y = get_nf(x,&t);
171
if (!y)
172
{
173
switch(t)
174
{
175
case typ_POL: return x;
176
case typ_Q : return gel(x,1);
177
case typ_GAL: return gal_get_pol(x);
178
case typ_RNF: return rnf_get_pol(x);
179
}
180
if (typ(x)==t_POLMOD) return gel(x,2);
181
if (typ(x)==t_FFELT) return FF_to_FpXQ(x);
182
member_err("pol",x);
183
}
184
return nf_get_pol(y);
185
}
186
187
GEN
188
member_polabs(GEN x)
189
{
190
long t; (void)get_nf(x,&t);
191
if (t != typ_RNF) member_err("pol",x);
192
return rnf_get_polabs(x);
193
}
194
195
GEN
196
member_mod(GEN x) /* modulus */
197
{
198
long t; (void)get_nf(x,&t);
199
switch(t) {
200
case typ_GAL: return gal_get_mod(x);
201
case typ_BNR: return bnr_get_mod(x);
202
case typ_BIDZ: return bid_get_ideal(x);
203
case typ_BID: return bid_get_mod(x);
204
}
205
switch(typ(x))
206
{
207
case t_INTMOD: case t_POLMOD: case t_QUAD: break;
208
case t_PADIC: return gel(x,3);
209
case t_FFELT: return FF_mod(x);
210
case t_VEC:
211
if (checkmf_i(x))
212
{
213
GEN T = mf_get_field(x), CHI = mf_get_CHI(x), P = mfcharpol(CHI);
214
return (degpol(T) == 1)? P: (degpol(P) > 1? gmodulo(T, P): T);
215
}
216
else if (checkMF_i(x))
217
return mfcharpol(MF_get_CHI(x));
218
default: member_err("mod",x);
219
}
220
return gel(x,1);
221
}
222
223
GEN
224
member_sign(GEN x) /* signature */
225
{
226
long t; GEN y = get_nf(x,&t);
227
if (!y) member_err("sign",x);
228
return gel(y,2);
229
}
230
GEN
231
member_r1(GEN x) { return gel(member_sign(x), 1); }
232
GEN
233
member_r2(GEN x) { return gel(member_sign(x), 2); }
234
235
GEN
236
member_index(GEN x)
237
{
238
long t; GEN y = get_nf(x,&t);
239
if (!y)
240
{
241
if (t == typ_RNF) return rnf_get_index(x);
242
member_err("index",x);
243
}
244
return nf_get_index(y);
245
}
246
247
/* x assumed to be output by get_nf: ie a t_VEC with length 11 */
248
static GEN
249
nfmats(GEN x)
250
{
251
GEN y;
252
if (!x) return NULL;
253
y = gel(x,5);
254
if (typ(y) == t_VEC && lg(y) < 8) return NULL;
255
return y;
256
}
257
258
GEN
259
member_t2(GEN x) /* T2 matrix */
260
{
261
long t; GEN y = nfmats(get_nf(x,&t));
262
if (!y) member_err("t2",x);
263
return gram_matrix(gel(y,2));
264
}
265
266
GEN
267
member_diff(GEN x) /* different */
268
{
269
long t; GEN y = nfmats(get_nf(x,&t));
270
if (!y) member_err("diff",x);
271
return gel(y,5);
272
}
273
274
GEN
275
member_codiff(GEN x) /* codifferent */
276
{
277
long t;
278
GEN T, d, Di, nf = get_nf(x,&t), y = nfmats(nf);
279
if (!y) member_err("codiff",x);
280
T = gel(y,4);
281
Di = ZM_inv(T, &d); if (!d) return matid(lg(Di)-1);
282
return RgM_Rg_div(ZM_hnfmodid(Di, d), d);
283
}
284
285
GEN
286
member_roots(GEN x) /* roots */
287
{
288
long t; GEN y = get_nf(x,&t);
289
if (!y)
290
{
291
if (t == typ_GAL) return gal_get_roots(x);
292
if (t == typ_ELL)
293
switch(ell_get_type(x))
294
{
295
case t_ELL_Qp: return mkcol( ellQp_root(x, ellQp_get_prec(x)) );
296
case t_ELL_Q:
297
case t_ELL_Rg: return ellR_roots(x, ellR_get_prec(x));
298
}
299
member_err("roots",x);
300
}
301
return nf_get_roots(y);
302
}
303
304
/* assume x output by get_bnf: ie a t_VEC with length 10 */
305
static GEN
306
check_RES(GEN x, const char *s)
307
{
308
GEN y = gel(x,8);
309
if (typ(y) != t_VEC || lg(y) < 4) member_err(s,x);
310
return y;
311
}
312
313
/* y = get_bnf(x, &t) */
314
static GEN
315
_member_clgp(GEN x, GEN y, long t) /* class group (3-component row vector) */
316
{
317
if (!y)
318
{
319
switch(t)
320
{
321
case typ_QUA: return mkvec3(gel(x,1), gel(x,2), gel(x,3));
322
case typ_BIDZ:
323
case typ_BID: return gel(x,2);
324
}
325
if (typ(x)==t_VEC)
326
switch(lg(x))
327
{
328
case 3: /* no gen */
329
case 4: return x;
330
}
331
member_err("clgp",x);
332
}
333
if (t==typ_BNR) return gel(x,5);
334
y = check_RES(y, "clgp"); return gel(y,1);
335
}
336
static GEN
337
_check_clgp(GEN x, GEN y, long t)
338
{ GEN c = _member_clgp(x,y,t); checkabgrp(c); return c; }
339
GEN
340
member_clgp(GEN x)
341
{ long t; GEN y = get_bnf(x,&t); return _check_clgp(x,y,t); }
342
343
GEN
344
member_reg(GEN x) /* regulator */
345
{
346
long t; GEN y = get_bnf(x,&t);
347
if (!y)
348
{
349
if (t == typ_QUA) return gel(x,4);
350
member_err("reg",x);
351
}
352
if (t == typ_BNR) pari_err_IMPL("ray regulator");
353
y = check_RES(y, "reg");
354
return gel(y,2);
355
}
356
357
GEN
358
member_fu(GEN x) /* fundamental units */
359
{
360
long t; GEN fu, y = get_bnf(x,&t);
361
if (!y)
362
{
363
switch(t)
364
{
365
case typ_Q:
366
x = quad_disc(x);
367
return (signe(x)<0)? cgetg(1,t_VEC): quadunit(x);
368
}
369
member_err("fu",x);
370
}
371
if (t == typ_BNR) pari_err_IMPL("ray units");
372
fu = bnf_get_fu_nocheck(y);
373
if (typ(fu) == t_MAT)
374
{ /*missing units*/
375
GEN SUnits = bnf_get_sunits(y);
376
if (!SUnits) return gen_0;
377
fu = bnf_build_units(y);
378
fu = vecslice(fu, 2, lg(fu)-1); /* remove torsion unit */
379
}
380
return matbasistoalg(y, fu);
381
}
382
383
/* torsion units. return [w,e] where w is the number of roots of 1, and e a
384
* polmod (or integer) generator */
385
GEN
386
member_tu(GEN x)
387
{
388
long t; GEN bnf = get_bnf(x,&t), res = cgetg(3,t_VEC);
389
if (!bnf)
390
{
391
GEN y;
392
if (t != typ_Q) member_err("tu",x);
393
y = quad_disc(x);
394
if (signe(y) > 0 || abscmpiu(y,4) > 0) return mkvec2(gen_m1, gen_2);
395
396
gel(res,1) = utoipos((itos(y) == -4)? 4: 6);
397
gel(res,2) = gcopy(x);
398
}
399
else
400
{
401
GEN z = bnf_get_tuU(bnf);
402
if (t == typ_BNR) pari_err_IMPL("ray torsion units");
403
gel(res,1) = utoipos( bnf_get_tuN(bnf) );
404
gel(res,2) = typ(z)==t_INT? gen_m1: basistoalg(bnf,z);
405
}
406
return res;
407
}
408
409
/* structure of (Z_K/m)^*, where x is an idealstarinit (with or without gen)
410
* or a bnrinit (with or without gen) */
411
GEN
412
member_zkst(GEN x)
413
{
414
long t; (void)get_nf(x,&t);
415
switch(t)
416
{
417
case typ_BIDZ:
418
case typ_BID: return bid_get_grp(x);
419
case typ_BNR: {
420
GEN bid = bnr_get_bid(x);
421
if (typ(bid) == t_VEC && lg(bid) > 2) return bid_get_grp(bid);
422
}
423
}
424
member_err("zkst",x);
425
return NULL; /* LCOV_EXCL_LINE */
426
}
427
428
GEN
429
member_no(GEN x) /* number of elements of a group (of type clgp) */
430
{
431
pari_sp av = avma;
432
long t; GEN y = get_bnf(x,&t);
433
if (t == typ_ELL) switch(ell_get_type(x))
434
{
435
case t_ELL_Fp:
436
case t_ELL_Fq: return ellcard(x, NULL);
437
}
438
x = _check_clgp(x,y,t);
439
return gc_const(av, abgrp_get_no(x));
440
}
441
442
GEN
443
member_cyc(GEN x) /* cyclic decomposition (SNF) of a group (of type clgp) */
444
{
445
pari_sp av = avma;
446
long t; GEN y = get_bnf(x,&t);
447
if (t == typ_ELL) switch(ell_get_type(x))
448
{
449
case t_ELL_Fp:
450
case t_ELL_Fq: return ellgroup(x, NULL);
451
}
452
x = _check_clgp(x,y,t);
453
return gc_const(av, abgrp_get_cyc(x));
454
}
455
456
/* SNF generators of a group (of type clgp), or generators of a prime
457
* ideal */
458
GEN
459
member_gen(GEN x)
460
{
461
pari_sp av;
462
long t; GEN y = get_bnf(x,&t);
463
switch(t)
464
{
465
case typ_MODPR: x = get_prid(x);
466
case typ_PRID: return mkvec2(gel(x,1), gel(x,2));
467
case typ_GAL: return gal_get_gen(x);
468
case typ_ELL: return ellgenerators(x);
469
}
470
av = avma;
471
x = _check_clgp(x,y,t);
472
if (lg(x)!=4) member_err("gen",x);
473
return gc_const(av, abgrp_get_gen(x));
474
}
475
GEN
476
member_group(GEN x)
477
{
478
long t; (void)get_nf(x,&t);
479
if (t == typ_GAL) return gal_get_group(x);
480
if (t == typ_ELL) return ellgroup0(x, NULL, 1);
481
member_err("group",x);
482
return NULL; /* LCOV_EXCL_LINE */
483
}
484
GEN
485
member_orders(GEN x)
486
{
487
long t; (void)get_nf(x,&t);
488
if (t == typ_GAL) return gal_get_orders(x);
489
member_err("orders",x);
490
return NULL; /* LCOV_EXCL_LINE */
491
}
492
493
GEN
494
member_a1(GEN x)
495
{
496
if (!is_ell5(x)) member_err("a1",x);
497
return ell_get_a1(x);
498
}
499
500
GEN
501
member_a2(GEN x)
502
{
503
if (!is_ell5(x)) member_err("a2",x);
504
return ell_get_a2(x);
505
}
506
507
GEN
508
member_a3(GEN x)
509
{
510
if (!is_ell5(x)) member_err("a3",x);
511
return ell_get_a3(x);
512
}
513
514
GEN
515
member_a4(GEN x)
516
{
517
if (!is_ell5(x)) member_err("a4",x);
518
return ell_get_a4(x);
519
}
520
521
GEN
522
member_a6(GEN x)
523
{
524
if (!is_ell5(x)) member_err("a6",x);
525
return ell_get_a6(x);
526
}
527
528
GEN
529
member_b2(GEN x)
530
{
531
if (!is_ell(x)) member_err("b2",x);
532
return ell_get_b2(x);
533
}
534
535
GEN
536
member_b4(GEN x)
537
{
538
if (!is_ell(x)) member_err("b4",x);
539
return ell_get_b4(x);
540
}
541
542
GEN
543
member_b6(GEN x)
544
{
545
if (!is_ell(x)) member_err("b6",x);
546
return ell_get_b6(x);
547
}
548
549
GEN
550
member_b8(GEN x)
551
{
552
if (!is_ell(x)) member_err("b8",x);
553
return ell_get_b8(x);
554
}
555
556
GEN
557
member_c4(GEN x)
558
{
559
if (!is_ell(x)) member_err("c4",x);
560
return ell_get_c4(x);
561
}
562
563
GEN
564
member_c6(GEN x)
565
{
566
if (!is_ell(x)) member_err("c6",x);
567
return ell_get_c6(x);
568
}
569
570
GEN
571
member_j(GEN x)
572
{
573
if (!is_ell(x)) member_err("j",x);
574
return ell_get_j(x);
575
}
576
577
static int
578
ell_is_complex(GEN x)
579
{ long t = ell_get_type(x); return t == t_ELL_Q || t == t_ELL_Rg; }
580
581
static long
582
ellnf_get_prec(GEN x) { return nf_get_prec(ellnf_get_nf(x)); }
583
584
GEN
585
member_omega(GEN x)
586
{
587
if (!is_ell(x)) member_err("omega",x);
588
if (ell_get_type(x)==t_ELL_NF)
589
return ellnf_vecomega(x, ellnf_get_prec(x));
590
if (!ell_is_complex(x)) pari_err_TYPE("omega [not defined over C]",x);
591
return ellR_omega(x, ellR_get_prec(x));
592
}
593
594
GEN
595
member_eta(GEN x)
596
{
597
if (!is_ell(x)) member_err("eta",x);
598
if (ell_get_type(x)==t_ELL_NF)
599
return ellnf_veceta(x, ellnf_get_prec(x));
600
if (!ell_is_complex(x)) pari_err_TYPE("eta [not defined over C]",x);
601
return ellR_eta(x, ellR_get_prec(x));
602
}
603
604
GEN
605
member_area(GEN x)
606
{
607
if (!is_ell(x)) member_err("area",x);
608
if (ell_get_type(x)==t_ELL_NF)
609
return ellnf_vecarea(x, ellnf_get_prec(x));
610
if (!ell_is_complex(x)) pari_err_TYPE("area [not defined over C]",x);
611
return ellR_area(x, ellR_get_prec(x));
612
}
613
614
GEN
615
member_tate(GEN x)
616
{
617
long prec;
618
if (!is_ell(x)) member_err("tate",x);
619
if (ell_get_type(x) != t_ELL_Qp)
620
pari_err_TYPE("tate [not defined over Qp]",x);
621
prec = ellQp_get_prec(x);
622
return ellQp_Tate_uniformization(x, prec);
623
}
624
625