source: git/Singular/LIB/primitiv.lib @ 0dd77c2

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