source: git/Singular/LIB/primitiv.lib @ cb8103a

spielwiese
Last change on this file since cb8103a was 66d68c, checked in by Hans Schoenemann <hannes@…>, 14 years ago
format git-svn-id: file:///usr/local/Singular/svn/trunk@13499 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 13.9 KB
Line 
1///////////////////////////////////////////////////////////////////////////////
2
3version="$Id$";
4category="Commutative Algebra";
5info="
6LIBRARY:    primitiv.lib    Computing a Primitive Element
7AUTHOR:     Martin Lamm,    email: lamm@mathematik.uni-kl.de
8
9PROCEDURES:
10 primitive(ideal i);   find minimal polynomial for a primitive element
11 primitive_extra(i);   find primitive element for two generators
12 splitring(f,R[,L]);   define ring extension with name R and switch to it
13";
14
15LIB "random.lib";
16///////////////////////////////////////////////////////////////////////////////
17
18proc primitive(ideal i)
19"USAGE:   primitive(i); i ideal
20ASSUME:   i is given by generators m[1],...,m[n] such that for j=1,...,n @*
21          -  m[j] is a polynomial in k[x(1),...,x(j)] @*
22          -  m[j](a[1],...,a[j-1],x(j)) is the minimal polynomial for a[j] over
23             k(a[1],...,a[j-1]) @*
24          (k the ground field of the current basering and x(1),...,x(n)
25          the ring variables).
26RETURN:   ideal j in k[x(n)] with
27          - j[1] a minimal polynomial for a primitive element b of
28                 k(a[1],...,a[n]) over k,
29          - j[2],...,j[n+1] polynomials in k[x(n)] such that j[i+1](b)=a[i]
30                 for i=1,...,n.
31NOTE:     the number of variables in the basering has to be exactly n,
32          the number of given generators (i.e., minimal polynomials).@*
33          If the ground field k has only a few elements it may happen that no
34          linear combination of a[1],...,a[n] is a primitive element. In this
35          case @code{primitive(i)} returns the zero ideal, and one should use
36          @code{primitive_extra(i)} instead.
37SEE ALSO: primitive_extra
38KEYWORDS: primitive element
39EXAMPLE:  example primitive;  shows an example
40"
41{
42 def altring=basering;
43 execute("ring deglexring=("+charstr(altring)+"),("+varstr(altring)+"),dp;");
44 ideal j;
45 execute("ring lexring=("+charstr(altring)+"),("+varstr(altring)+"),lp;");
46 ideal i=fetch(altring,i);
47
48 int k,schlecht,Fehlversuche,maxtry;
49 int nva = nvars(basering);
50 int p=char(basering);
51 if (p==0) {
52   p=100000;
53   if (nva<3) { maxtry= 100000000; }
54   else       { maxtry=2147483647; }
55 }
56 else {
57   if ((nva<4) || (p<60)) {
58     maxtry=p^(nva-1); }
59   else {
60     maxtry=2147483647;          // int overflow(^)  vermeiden
61   }
62 }
63 ideal jmap,j;
64 map phi;
65 option(redSB);
66
67 //-------- Mache so lange Random-Koord.wechsel, bis letztes Polynom -------------
68 //--------------- das Minpoly eines primitiven Elements ist : ----------------
69 for (Fehlversuche=0; Fehlversuche<maxtry; Fehlversuche++) {
70   schlecht=0;
71   if ((p<60) && (nva==2)) {  // systematische Suche statt random
72      jmap=ideal(var(1),var(2)+Fehlversuche*var(1));
73   }
74   else {
75    if (Fehlversuche==0) { jmap=maxideal(1);}
76    else {
77      if (Fehlversuche<5) { jmap=randomLast(10);}
78      else {
79       if (Fehlversuche<20) { jmap=randomLast(100);}
80       else                 { jmap=randomLast(100000000);}
81    }}                        // groessere Werte machen keinen Sinn
82   }
83   phi=lexring,jmap;
84   j=phi(i);
85   setring deglexring;
86 //--------------- Berechne reduzierte Standardbasis mit fglm: ----------------
87   j=std(fetch(lexring,j));
88   setring lexring;
89   j=fglm(deglexring,j);
90 //-- teste, ob SB n Elemente enthaelt (falls ja, ob lead(Fi)=xi i=1... n-1): -
91   if (size(j)==nva) {
92     for (k=1; k<nva; k++) {
93       j[k+1]=j[k+1]/leadcoef(j[k+1]);        // normiere die Erzeuger
94       if (lead(j[k+1]) != var(nva-k)) { schlecht=1;}
95     }
96     if (schlecht==0) {
97 //--- Random-Koord.wechsel war gut: Berechne das zurueckzugebende Ideal: -----
98       ideal erg;
99       for (k=1; k<nva; k++) { erg[k]=var(k)-j[nva-k+1]; }
100                               // =g_k(x_n) mit a_k=g_k(a_n)
101       erg[nva]=var(nva);
102       map chi=lexring,erg;
103       ideal extra=maxideal(1);extra=phi(extra);
104                               // sonst: "argument of a map must have a name"
105       erg=j[1],chi(extra);    // j[1] = Minimalpolynom
106       setring altring;
107       return(fetch(lexring,erg));
108     }
109   }
110   dbprint("The random coordinate change was bad!");
111 }
112 if (voice==2) {
113   "// ** Warning: No primitive element could be found.";
114   "//    If the given ideal really describes the minimal polynomials of";
115   "//    a series of algebraic elements (cf. `help primitive;') then";
116   "//    try `primitive_extra'.";
117 }
118 setring altring;
119 return(ideal(0));
120}
121example
122{ "EXAMPLE:"; echo = 2;
123 ring exring=0,(x,y),dp;
124 ideal i=x2+1,y2-x;                  // compute Q(i,i^(1/2))=:L
125 ideal j=primitive(i);
126 j[1];                               // L=Q(a) with a=(-1)^(1/4)
127 j[2];                               // i=a^2
128 j[3];                               // i^(1/2)=a
129 // the 2nd element was already primitive!
130 j=primitive(ideal(x2-2,y2-3));      // compute Q(sqrt(2),sqrt(3))
131 j[1];
132 j[2];
133 j[3];
134 // no element was primitive -- the calculation of primitive elements
135 // is based on a random choice.
136}
137///////////////////////////////////////////////////////////////////////////////
138
139proc primitive_extra(ideal i)
140"USAGE:   primitive_extra(i); i ideal
141ASSUME:  The ground field of the basering is k=Q or k=Z/pZ and the ideal
142         i is given by 2 generators f,g with the following properties:
143@format
144   f is the minimal polynomial of a in k[x],
145   g is a polynomial in k[x,y] s.th. g(a,y) is the minpoly of b in k(a)[y].
146@end format
147          Here, x is the name of the first ring variable, y the name of the
148          second.
149RETURN:  ideal j in k[y] such that
150@format
151   j[1] is the minimal polynomial for a primitive element c of k(a,b) over k,
152   j[2] is a polynomial s.th. j[2](c)=a.
153@end format
154NOTE:    While @code{primitive(i)} may fail for finite fields,
155         @code{primitive_extra(i)} tries all elements of k(a,b) and, hence,
156         always finds a primitive element. @*
157         In order to do this (try all elements), field extensions like Z/pZ(a)
158         are not allowed for the ground field k. @*
159         @code{primitive_extra(i)} assumes that the second generator, g, is
160         monic as polynomial in (k[x])[y].
161EXAMPLE: example primitive_extra;  shows an example
162"
163{
164 def altring=basering;
165 int grad1=deg(i[1]);
166 int grad2=deg(jet(i[2],0,intvec(1,0)));
167 if (grad2==0) { ERROR("i[2] is not monic"); }
168 int countx,countz;
169  if (size(variables(i[1]))!=1) { ERROR("i[1] must be poly in x"); }
170  if (size(variables(i[2]))>2) { ERROR("i[2] must be poly in x,a"); }
171  //if (variables(i[2])[2]!=a) { ERROR("i[2] must be poly in x,a"); }
172 ring deglexring=char(altring),(x,y,z),dp;
173 map transfer=altring,x,z;
174 ideal i=transfer(i);
175 if (size(i)!=2)
176 {
177   ERROR("either wrong number of given minimal polynomials"+newline+
178   "or wrong choice of ring variables (must use the first two)");
179 }
180 matrix mat;
181 ring lexring=char(altring),(x,y),lp;
182 ideal j;
183 ring deglex2ring=char(altring),(x,y),dp;
184 ideal j;
185 setring deglexring;
186 ideal j;
187 option(redSB);
188 poly g=z;
189 int found=0;
190
191 //---------------- Schleife zum Finden des primitiven Elements ---------------
192 //--- Schleife ist so angordnet, dass g in Charakteristik 0 linear bleibt ----
193 while (found==0)
194 {
195   j=eliminate(i+ideal(g-y),z);
196   setring deglex2ring;
197   j=std(imap(deglexring,j));
198   setring lexring;
199   j=fglm(deglex2ring,j);
200   if (size(j)==2)
201   {
202     if (deg(j[1])==grad1*grad2)
203     {
204       j[2]=j[2]/leadcoef(j[2]);    // Normierung
205       if (lead(j[2])==x)
206       {         // Alles ok
207          found=1;
208       }
209     }
210   }
211   setring deglexring;
212   if (found==0)
213   {
214 //------------------ waehle ein neues Polynom g ------------------------------
215     dbprint("Still searching for primitive element...");
216     countx=0;
217     countz=0;
218     while (found==0)
219     {
220      countx++;
221      if (countx>=grad1)
222      {
223        countx=0;
224        countz++;
225        if (countz>=grad2)
226        { ERROR("No primitive element found!! This should NEVER happen!"); }
227      }
228      g = g +x^countx *z^countz;
229      mat=coeffs(g,z);
230      if (size(mat)>countz)
231      {
232        mat=coeffs(mat[countz+1,1],x);
233        if (size(mat)>countx)
234        {
235          if (mat[countx+1,1] != 0)
236          {
237            found=1;         // d.h. hier: neues g gefunden
238      }}}
239     }
240     found=0;
241   }
242 }
243 //------------------- primitives Element gefunden; Rueckgabe -----------------
244 setring lexring;
245 j[2]=x-j[2];
246 setring altring;
247 map transfer=lexring,var(1),var(2);
248 return(transfer(j));
249}
250example
251{ "EXAMPLE:"; echo = 2;
252 ring exring=3,(x,y),dp;
253 ideal i=x2+1,y3+y2-1;
254 primitive_extra(i);
255 ring extension=(3,y),x,dp;
256 minpoly=y6-y5+y4-y3-y-1;
257 number a=y5+y4+y2+y+1;
258 a^2;
259 factorize(x2+1);
260 factorize(x3+x2-1);
261}
262///////////////////////////////////////////////////////////////////////////////
263
264proc splitring(poly f,list #)
265"USAGE:   splitring(f[,L]); f poly, L list of polys and/or ideals
266         (optional)
267ASSUME:  f is univariate and irreducible over the active ring. @*
268         The active ring must allow an algebraic extension (e.g., it cannot
269         be a transcendent ring extension of Q or Z/p).
270RETURN:  ring; @*
271           if called with a nonempty second parameter L, then in the output
272           ring there is defined a list erg ( =L mapped to the new ring);
273           if the minpoly of the active ring is non-zero, then the image of
274           the primitive root of f in the output ring is appended as last
275           entry of the list erg.
276NOTE:    If the old ring has no parameter, the name @code{a} is chosen for the
277         parameter of R (if @code{a} is no ring variable; if it is, @code{b} is
278         chosen, etc.; if @code{a,b,c,o} are ring variables,
279         @code{splitring(f[,L])} produces an error message), otherwise the
280         name of the parameter is kept and only the minimal polynomial is
281         changed. @*
282         The names of the ring variables and the orderings are not affected. @*
283KEYWORDS: algebraic field extension; extension of rings
284EXAMPLE: example splitring;  shows an example
285"
286{
287 //----------------- split ist bereits eine proc in 'inout.lib' ! -------------
288 if (size(#)>=1) {
289    list L=#;
290    int L_groesse=size(L);
291 }
292 else { int L_groesse=-1; }
293 //-------------- ermittle das Minimalpolynom des aktuellen Rings: ------------
294 string minp=string(minpoly);
295
296 def altring=basering;
297 string charakt=string(char(altring));
298 string varnames=varstr(altring);
299 string algname;
300 int i;
301 int anzvar=size(maxideal(1));
302 //--------------- Fall 1: Bisheriger Ring hatte kein Minimalpolynom ----------
303 if (minp=="0") { // only possible without parameters (by assumption)
304  if (find(varnames,"a")==0)        { algname="a";}
305  else { if (find(varnames,"b")==0) { algname="b";}
306         else { if (find(varnames,"c")==0)
307                                    { algname="c";}
308         else { if (find(varnames,"o")==0)
309                                    { algname="o";}
310         else {
311           "** Sorry -- could not find a free name for the primitive element.";
312           "** Try e.g. a ring without 'a' or 'b' as variable.";
313           return();
314         }}
315       }
316  }
317  //-- erzeuge einen String, der das Minimalpolynom des neuen Rings enthaelt: -
318  execute("ring splt1="+charakt+","+algname+",dp;");
319  ideal abbnach=var(1);
320  for (i=1; i<anzvar; i++) { abbnach=abbnach,var(1); }
321  map nach_splt1=altring,abbnach;
322  execute("poly mipol="+string(nach_splt1(f))+";");
323  string Rminp=string(mipol);
324
325  //--------------------- definiere den neuen Ring: ---------------------------
326  execute("ring neuring = ("+charakt+","+algname+"),("+varnames+"),("
327           +ordstr(altring)+");");
328  execute("minpoly="+Rminp+";");
329
330  //---------------------- Berechne die zurueckzugebende Liste: ---------------
331  if (L_groesse>0) {
332   list erg;
333   map take=altring,maxideal(1);
334   erg=take(L);
335  }
336 }
337 else {
338
339  //------------- Fall 2: Bisheriger Ring hatte ein Minimalpolynom: -----------
340  algname=parstr(altring);           // Name des algebraischen Elements
341  if (npars(altring)>1) {"only one Parameter is allowed!!"; return(altring);}
342
343  //---------------- Minimalpolynom in ein Polynom umwandeln: -----------------
344  execute("ring splt2="+charakt+","+algname+",dp;");
345  execute("poly mipol="+minp+";");
346  // f ist Polynom in algname und einer weiteren Variablen -> mache f bivariat:
347  execute("ring splt3="+charakt+",("+algname+","+varnames+"),dp;");
348  poly f=imap(altring,f);
349
350  //-------------- Vorbereitung des Aufrufes von primitive: -------------------
351  execute("ring splt1="+charakt+",(x,y),dp;");
352  ideal abbnach=x;
353  for (i=1; i<=anzvar; i++) { abbnach=abbnach,y; }
354  map nach_splt1_3=splt3,abbnach;
355  map nach_splt1_2=splt2,x;
356  ideal maxid=nach_splt1_2(mipol),nach_splt1_3(f);
357  ideal primit=primitive(maxid);
358  if (size(primit)==0) {             // Suche mit 1. Proc erfolglos
359    primit=primitive_extra(maxid);
360  }
361  //-- erzeuge einen String, der das Minimalpolynom des neuen Rings enthaelt: -
362  setring splt2;
363  map nach_splt2=splt1,0,var(1);     // x->0, y->a
364  minp=string(nach_splt2(primit)[1]);
365  if (printlevel > -1) { "// new minimal polynomial:",minp; }
366  //--------------------- definiere den neuen Ring: ---------------------------
367  execute("ring neuring = ("+charakt+","+algname+"),("+varnames+"),("
368          +ordstr(altring)+");");
369  execute("minpoly="+minp+";");
370
371  if (L_groesse>0) {
372    //---------------------- Berechne die zurueckzugebende Liste: -------------
373    list erg;
374    setring splt3;
375    list zwi=imap(altring,L);
376    map nach_splt3_1=splt1,0,var(1);  // x->0, y->a
377    //----- rechne das primitive Element von altring in das von neuring um: ---
378    ideal convid=maxideal(1);
379    convid[1]=nach_splt3_1(primit)[2];
380    poly new_b=nach_splt3_1(primit)[3];
381    map convert=splt3,convid;
382    zwi=convert(zwi);
383    setring neuring;
384    erg=imap(splt3,zwi);
385    erg[size(erg)+1]=imap(splt3,new_b);
386  }
387 }
388 if (defined(erg)){export erg;}
389 return(neuring);
390}
391example
392{ "EXAMPLE:"; echo = 2;
393 ring r=0,(x,y),dp;
394 def r1=splitring(x2-2);
395 setring r1; basering;    // change to Q(sqrt(2))
396 // change to Q(sqrt(2),sqrt(sqrt(2)))=Q(a) and return the transformed
397 // old parameter:
398 def r2=splitring(x2-a,a);
399 setring r2; basering; erg;
400 // the result is (a)^2 = (sqrt(sqrt(2)))^2
401 kill r1; kill r2;
402}
403///////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.