1#############################################################################
2##
3#W kantin.gi        Alnuth - ALgebraic NUmber THeory           Bettina Eick
4#W                                                           Bjoern Assmann
5#W                                                          Andreas Distler
6##
7
8#############################################################################
9##
10#F PolynomialWithNameToStringList( f[, name] )
11##
12InstallGlobalFunction(PolynomialWithNameToStringList, function( arg )
13    local c, f, stringlist, i;
14
15    # get input
16    f := arg[1];
17
18    # print identifier of polynomial, default 'f', or given as second argument
19    if Length( arg ) = 1 then
20        stringlist := ["f = "];
21    else
22        stringlist := Concatenation(arg[2], " = ");
23    fi;
24
25    # print polynomial using 'x' as variable
26    c := CoefficientsOfUnivariatePolynomial( f );
27    for i in [1..Length(c)] do
28        if c[i] >= 0 and i > 1 then
29            Add(stringlist, "+");
30        fi;
31        Add(stringlist, Concatenation(String(c[i]), "*x^", String(i-1)));
32    od;
33    Add(stringlist,";\n");
34
35    return stringlist;
36end);
37
38#############################################################################
39##
40#F CoefficientsToStringList(name, coeffs)
41##
42InstallGlobalFunction(CoefficientsToStringList, function(name, coeffs)
43    local stringlist, c;
44
45    stringlist := ["{"];
46    Add(stringlist, name);
47    Add(stringlist, "= [ \n");
48    for c in coeffs do
49        Add(stringlist, String(c));
50        Add(stringlist, ", \n");
51    od;
52    Add(stringlist, "0]; }\n");
53
54    return stringlist;
55end);
56
57#############################################################################
58##
59#F MaximalOrderDescriptionPari( F )
60##
61InstallGlobalFunction(MaximalOrderDescriptionPari, function( F )
62    local input, result;
63
64    if IsPrimeField(F) then return [1]; fi;
65
66    # initialize list of input strings with the defining polynomial
67    input := PolynomialWithNameToStringList(IntegerDefiningPolynomial(F));
68
69    # execute PARI/GP
70    result := ProcessPariGP(Concatenation(input), "maxord.gp");
71
72    # return result
73    return result;
74end);
75
76#############################################################################
77##
78#F UnitGroupDescriptionPari( F )
79##
80InstallGlobalFunction(UnitGroupDescriptionPari, function( F )
81    local input, result;
82
83    if IsPrimeField( F ) then return [-1]; fi;
84
85    # initialize list of input strings with the defining polynomial
86    input := PolynomialWithNameToStringList(IntegerDefiningPolynomial(F));
87
88    # execute PARI/GP
89    result := ProcessPariGP(Concatenation(input), "units.gp");
90
91    # return result
92    return result;
93end);
94
95#############################################################################
96##
97#F ExponentsOfUnitsDescriptionWithRankPari( F, elms )
98##
99InstallGlobalFunction(ExponentsOfUnitsDescriptionWithRankPari,
100function( F, elms )
101    local input, e, result;
102
103    if IsPrimeField( F ) then return fail; fi;
104
105    # initialize list of input strings with the defining polynomial
106    input := PolynomialWithNameToStringList(IntegerDefiningPolynomial(F));
107
108    # add coefficients of <elms>
109    input := Concatenation(input, CoefficientsToStringList("elms", elms));
110
111    # execute PARI/GP
112    result := ProcessPariGP(Concatenation(input), "decompra.gp");
113
114    # return result
115    return rec(units := result[1], expns := result[2], rank := result[3]);
116end);
117
118#############################################################################
119##
120#F ExponentsOfFractionalIdealDescriptionPari( F, elms )
121##
122## <elms> are arbitrary elements of F (or rather their coefficients).
123## Returns the exponents vectors of the fractional ideals
124## generated by elms corresponding to the underlying prime ideals.
125##
126InstallGlobalFunction( ExponentsOfFractionalIdealDescriptionPari,
127function( F, elms )
128    local input, e, result;
129
130    if IsPrimeField( F ) then return fail; fi;
131
132    # initialize list of input strings with the defining polynomial
133    input := PolynomialWithNameToStringList(IntegerDefiningPolynomial(F));
134
135    # add coefficients of <elms>
136    input := Concatenation(input, CoefficientsToStringList("elms", elms));
137
138    # execute PARI/GP
139    result := ProcessPariGP(Concatenation(input), "fracidea.gp");
140
141    # return result
142    return result;
143end);
144
145#############################################################################
146##
147#F NormCosetsDescriptionPari( F, norm )
148##
149InstallGlobalFunction( NormCosetsDescriptionPari, function( F, norm )
150    local input, result;
151
152    if IsPrimeField(F) then return fail; fi;
153
154    # initialize list of input strings with the defining polynomial
155    input := PolynomialWithNameToStringList(IntegerDefiningPolynomial(F));
156
157    # add norm information
158    Add(input, "nrm = ");
159    Add(input, String(norm));
160    Add(input, "; \n");
161
162    # execute PARI/GP
163    result := ProcessPariGP(Concatenation(input), "norm.gp");
164
165    # return result
166    return rec(units := result[1], creps := result[2]);
167end);
168
169#############################################################################
170##
171#F  PolynomialFactorsDescriptionPari, function( <F>, <coeffs> )
172##
173##  Factorizes the polynomial defined by <coeffs> over the field <F>
174##  using PARI/GP
175##
176InstallGlobalFunction( PolynomialFactorsDescriptionPari, function( F, coeffs )
177    local input, c, result, runtime;
178
179    # initialize list of input strings with the defining polynomial
180    input := PolynomialWithNameToStringList(IntegerDefiningPolynomial(F));
181
182    # add the coefficients of the polynomial to be factorised
183    input := Concatenation(input, CoefficientsToStringList("coeffs", coeffs));
184
185    # execute PARI/GP
186    result := ProcessPariGP(Concatenation(input), "polyfactors.gp");
187
188    # print runtime
189    runtime := Remove(result);
190    Info(InfoAlnuth, 1, "Runtime: ", runtime);
191
192    # return result
193    return result;
194end );
195
196#############################################################################
197##
198#F ProcessPariGP(input, codefile)
199##
200InstallGlobalFunction(ProcessPariGP, function(input, codefile)
201    local output, paricode;
202
203    # test, wether AL_EXECUTABLE is set
204    if AL_EXECUTABLE = fail then
205        Error( "AL_EXECUTABLE, the executable for PARI/GP, has to be set" );
206    fi;
207
208    # add the prepared code fragments for the calculations in PARI/GP
209    paricode := InputTextFile(Filename(AL_PATH, codefile));
210
211    # execute PARI/GP
212    Info(InfoAlnuth, 1, "executing PARI/GP with ", codefile);
213    output := "";
214    Process(DirectoryCurrent(), AL_EXECUTABLE,
215            InputTextString(Concatenation(input, ReadAll(paricode))),
216            OutputTextString(output,false),
217            Concatenation(AL_OPTIONS, [AL_STACKSIZE])
218           );
219
220    # close open input stream from file with GP code
221    CloseStream(paricode);
222
223    return EvalString(output);
224end);
225
226#############################################################################
227##
228#E