Line data Source code
1 : /* Copyright (C) 2000-2018 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 : GEN
19 198 : galoisnbpol(long a)
20 : {
21 : GEN n;
22 : pariFILE *F;
23 198 : char *s = stack_sprintf("%s/galpol/%ld/nb", pari_datadir, a);
24 198 : F = pari_fopengz(s);
25 198 : if (!F) pari_err_FILE("galpol file",s);
26 198 : n = gp_read_stream(F->file);
27 198 : if (!n || typ(n)!=t_INT) pari_err_FILE("galpol file [incompatible]",s);
28 198 : pari_fclose(F); return n;
29 : }
30 :
31 : GEN
32 816 : galoisgetpol(long a, long b, long sig)
33 : {
34 : pariFILE *F;
35 : GEN V;
36 : const char *si;
37 : char *s;
38 816 : if (a<=0) pari_err_DOMAIN("galoisgetpol", "degree", "<=", gen_0, stoi(a));
39 816 : if (b<0) pari_err_DOMAIN("galoisgetpol", "index", "<", gen_0, stoi(b));
40 816 : if (!b) return galoisnbpol(a);
41 624 : switch(sig)
42 : {
43 582 : case 1: si="real"; break;
44 36 : case 2: if (a%2==0) { si="complex"; break; }
45 6 : pari_err_DOMAIN("galoisgetpol", "s", ">", gen_1, stoi(sig));
46 6 : default:
47 6 : pari_err_FLAG("galoisgetpol");
48 : return NULL;/*LCOV_EXCL_LINE*/
49 : }
50 : /* left on stack */
51 612 : s = stack_sprintf("%s/galpol/%ld/%ld/%s", pari_datadir, a,b,si);
52 612 : F = pari_fopengz(s);
53 612 : if (!F)
54 : {
55 6 : long n = itos(galoisnbpol(a));
56 6 : if (b > n)
57 6 : pari_err_DOMAIN("galoisgetpol", "group index", ">", stoi(n), stoi(b));
58 0 : else pari_err_FILE("galpol file", s);
59 : }
60 606 : V = gp_read_stream(F->file);
61 606 : if (!V || typ(V)!=t_VEC) pari_err_FILE("galpol file", F->name);
62 606 : pari_fclose(F); return V;
63 : }
64 :
65 : GEN
66 30 : galoisgetgroup(long a, long b)
67 : {
68 : pariFILE *F;
69 : GEN V;
70 : char *s;
71 30 : if (a<=0) pari_err_DOMAIN("galoisgetgroup", "degree", "<=", gen_0, stoi(a));
72 30 : if (b<0) pari_err_DOMAIN("galoisgetgroup", "index", "<", gen_0, stoi(b));
73 30 : if (!b) return galoisnbpol(a);
74 : /* left on stack */
75 30 : s = stack_sprintf("%s/galpol/%ld/%ld/group", pari_datadir, a,b);
76 30 : F = pari_fopengz(s);
77 30 : if (!F)
78 : {
79 0 : long n = itos(galoisnbpol(a));
80 0 : if (b > n)
81 0 : pari_err_DOMAIN("galoisgetgroup", "group index", ">", stoi(n), stoi(b));
82 0 : else pari_err_FILE("galpol file", s);
83 : }
84 30 : V = gp_read_stream(F->file);
85 30 : if (!V || typ(V)!=t_VEC) pari_err_FILE("galpol file", F->name);
86 30 : pari_fclose(F); return V;
87 : }
88 :
89 : GEN
90 30 : galoisgetname(long a, long b)
91 : {
92 : pariFILE *F;
93 : GEN V;
94 : char *s;
95 30 : if (a<=0) pari_err_DOMAIN("galoisgetname", "degree", "<=", gen_0, stoi(a));
96 30 : if (b<0) pari_err_DOMAIN("galoisgetname", "index", "<", gen_0, stoi(b));
97 : /* left on stack */
98 30 : s = stack_sprintf("%s/galpol/%ld/%ld/name", pari_datadir, a,b);
99 30 : F = pari_fopengz(s);
100 30 : if (!F)
101 : {
102 0 : long n = itos(galoisnbpol(a));
103 0 : if (b > n)
104 0 : pari_err_DOMAIN("galoisgetname", "group index", ">", stoi(n), stoi(b));
105 0 : else pari_err_FILE("galpol file", s);
106 : }
107 30 : V = gp_read_stream(F->file);
108 30 : if (!V || typ(V)!=t_STR) pari_err_FILE("galpol file", F->name);
109 30 : pari_fclose(F); return V;
110 : }
|