source: git/Singular/LIB/elim.lib @ faed79

fieker-DuValspielwiese
Last change on this file since faed79 was 4820e6, checked in by Hans Schönemann <hannes@…>, 15 years ago
*hannes: optim git-svn-id: file:///usr/local/Singular/svn/trunk@11316 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 31.0 KB
Line 
1// $Id: elim.lib,v 1.28 2009-01-15 13:51:18 Singular Exp $
2// (GMG, modified 22.06.96)
3// GMG, last modified 30.10.08: new procedure elimRing;
4// elim changes now to ring with elimination ordering (extra weight vector
5// a(...)), works now in qring, new examples have been added;
6// syntax of elim, nselect, select and select1 changed: instead of two
7// integers an intvec can be given. Bug in nselect fixed which occured
8// in connectin with type conversion from matrix to module.
9// GMG, last modified 5.01.09: elim uses now stdhilb(id,@w) instead of std(id)
10// and can now choose as method slimgb or std.
11///////////////////////////////////////////////////////////////////////////////
12version="$Id: elim.lib,v 1.28 2009-01-15 13:51:18 Singular Exp $";
13category="Commutative Algebra";
14info="
15LIBRARY:  elim.lib      Elimination, Saturation and Blowing up
16
17PROCEDURES:
18 blowup0(j[,s1,s2]);   create presentation of blownup ring of ideal j
19 elimRing(p);          create ring with block ordering for elimating vars in p
20 elim(id,..);          variables .. eliminated from id (ideal/module)
21 elim1(id,p);          variables .. eliminated from id (different algorithm)
22 elim2(id,..);         variables .. eliminated from id (different algorithm)
23 nselect(id,v);        select generators not containing variables given by v
24 sat(id,j);            saturated quotient of ideal/module id by ideal j
25 select(id,v]);        select generators containing all variables given by v
26 select1(id,v);        select generators containing one variable given by v
27           (parameters in square brackets [] are optional)
28";
29
30LIB "inout.lib";
31LIB "general.lib";
32LIB "poly.lib";
33LIB "ring.lib";
34///////////////////////////////////////////////////////////////////////////////
35
36proc blowup0 (ideal J,ideal C, list #)
37"USAGE:   blowup0(J,C [,W]); J,C,W ideals
38@*       C = ideal of center of blowup, J = ideal to be blown up,
39         W = ideal of ambient space
40ASSUME:  inclusion of ideals : W in J, J in C.
41         If not, the procedure replaces J by J+W and C by C+J+W
42RETURN:  a ring, say B, containing the ideals C,J,W and the ideals
43@*         - bR (ideal defining the blown up basering)
44@*         - aS (ideal of blown up ambient space)
45@*         - eD (ideal of exceptional divisor)
46@*         - tT (ideal of total transform)
47@*         - sT (ideal of strict transform)
48@*         - bM (ideal of the blowup map from basering to B)
49@*       such that B/bR is isomorphic to the blowup ring BC.
50PURPOSE: compute the projective blowup of the basering in the center C, the
51         exceptional locus, the total and strict tranform of J,
52         and the blowup map.
53         The projective blowup is a presentation of the blowup ring
54         BC = R[C] = R + t*C + t^2*C^2 + ... (also called Rees ring) of the
55         ideal C in the ring basering R.
56THEORY:  If basering = K[x1,...,xn] and C = <f1,...,fk> then let
57         B = K[x1,...,xn,y1,...,yk] and aS the preimage in B of W
58         under the map B -> K[x1,...,xn,t], xi -> xi, yi -> t*fi.
59         aS is homogeneous in the variables yi and defines a variety
60         Z=V(aS) in  A^n x P^(k-1), the ambient space of the blowup of V(W).
61         The projection Z -> A^n is an isomorphism outside the preimage
62         of the center V(C) in A^n and is called the blowup of the center.
63         The preimage of V(C) is called the exceptional set, the preimage of
64         V(J) is called the total transform of V(J). The strict transform
65         is the closure of (total transform - exceptional set).
66@*       If C = <x1,...,xn> then aS = <yi*xj - yj*xi | i,j=1,...,n>
67         and Z is the blowup of A^n in 0, the exceptional set is P^(k-1).
68NOTE:    The procedure creates a new ring with variables y(1..k) and x(1..n)
69         where n=nvars(basering) and k=ncols(C). The ordering is a block
70         ordering where the x-block has the ordering of the basering and
71         the y-block has ordering dp if C is not homogeneous
72         resp. the weighted ordering wp(b1,...bk) if C is homogeneous
73         with deg(C[i])=bi.
74SEE ALSO:blowUp
75EXAMPLE: example blowup0; shows examples
76"{
77   def br = basering;
78   list l = ringlist(br);
79   int n,k,i = nvars(br),ncols(C),0;
80   ideal W;
81   if (size(#) !=0)
82   { W = #[1];}
83   J = J,W;
84   //J = interred(J+W);
85//------------------------- create rings for blowup ------------------------
86//Create rings tr = K[x(1),...,x(n),t] and nr = K[x(1),...,x(n),y(1),...,y(k)]
87//and map Bl: nr --> tr, x(i)->x(i), y(i)->t*fi.
88//Let ord be the ordering of the basering.
89//We change the ringlist l by changing l[2] and l[3]
90//For K[t,x(1),...,x(n),t]
91// - l[2]: the variables to x(1),...,x(n),t
92// - l[3]: the ordering to a block ordering (ord,dp(1))
93//For K[x(1),...,x(n),y(1),...,y(k)]
94// - l[2]: the variables to x(1),...,x(n),y(1),...,y(k),
95// - l[3]: the ordering to a block ordering (ord,dp) if C is
96//         not homogeneous or to (ord,wp(b1,...bk),ord) if C is
97//         homogeneous with deg(C[i])=bi;
98
99//--------------- create tr = K[x(1),...,x(n),t] ---------------------------
100   int s = size(l[3]);
101   for ( i=n; i>=1; i--)
102   {
103      l[2][i]="x("+string(i)+")";
104   }
105   l[2]=insert(l[2],"t",n);
106   l[3]=insert(l[3],list("dp",1),s-1);
107   def tr = ring(l);
108
109//--------------- create nr = K[x(1),...,x(n),y(1),...,y(k)] ---------------
110   l[2]=delete(l[2],n+1);
111   l[3]=delete(l[3],s);
112   for ( i=k; i>=1; i--)
113   {
114      l[2][n+i]="y("+string(i)+")";
115   }
116
117   //---- change l[3]:
118   l[3][s+1] = l[3][s];         // save the module ordering of the basering
119   intvec w=1:k;
120   intvec v;                    // containing the weights for the varibale
121   if( homog(C) )
122   {
123      for( i=k; i>=1; i--)
124      {
125         v[i]=deg(C[i]);
126      }
127      if (v != w)
128      {
129         l[3][s]=list("wp",v);
130      }
131      else
132      {
133         l[3][s]=list("dp",v);
134      }
135   }
136   else
137   {
138      v=1:k;
139      l[3][s]=list("dp",v);
140   }
141   def nr = ring(l);
142
143//-------- create blowup map Bl: nr --> tr, x(i)->x(i), y(i)->t*fi ---------
144   setring tr;
145   ideal C = fetch(br,C);
146   ideal bl = x(1..n);
147   for( i=1; i<=k; i++) { bl = bl,t*C[i]; }
148   map Bl = nr,bl;
149   ideal Z;
150//------------------ compute blown up objects and return  -------------------
151   setring nr;
152   ideal bR = preimage(tr,Bl,Z);   //ideal of blown up affine space A^n
153   ideal C = fetch(br,C);
154   ideal J = fetch(br,J);
155   ideal W = fetch(br,W);
156   ideal aS = interred(bR+W);                //ideal of ambient space
157   ideal tT = interred(J+bR+W);              //ideal of total transform
158   ideal eD = interred(C+J+bR+W);            //ideal of exceptional divisor
159   ideal sT = sat(tT,C)[1];       //ideal of strict transform
160   ideal bM = x(1..n);            //ideal of blowup map br --> nr
161
162   export(bR,C,J,W,aS,tT,eD,sT,bM);
163   return(nr);
164}
165example
166{ "EXAMPLE:"; echo = 2;
167   ring r  = 0,(x,y),dp;
168   poly f  = x2+y3;
169   ideal C = x,y;           //center of blowup
170   def B1 = blowup0(f,C);
171   setring B1;
172   aS;                      //ideal of blown up ambient space
173   tT;                      //ideal of total transform of f
174   sT;                      //ideal of strict transform of f
175   eD;                      //ideal of exceptional divisor
176   bM;                      //ideal of blowup map r --> B1
177
178   ring R  = 0,(x,y,z),ds;
179   poly f  = y2+x3+z5;
180   ideal C = y2,x,z;
181   ideal W = z-x;
182   def B2 = blowup0(f,C,W);
183   setring B2;
184   B2;                       //weighted ordering
185   bR;                       //ideal of blown up R
186   aS;                       //ideal of blown up R/W
187   sT;                       //strict transform of f
188   eD;                       //ideal of exceptional divisor
189   //Note that the different affine charts are {y(i)=1}
190 }
191
192//////////////////////////////////////////////////////////////////////////////
193proc elimRing ( poly vars, list #)
194"USAGE:   elimRing(vars [,w,str]); vars = product of variables to be eliminated
195         (type poly), w = intvec (specifying weights for all variables),
196         str = string either \"a\" or \"b\" (default: w=ringweights, str=\"a\")
197RETURN:  a list, say L, with R:=L[1] a ring and L[2] an intvec.
198         The ordering in R is an elimination ordering for the variables
199         appearing in vars depending on \"a\" resp. \"b\". Let w1 (resp. w2)
200         be the intvec of weights of the variables to be eliminated (resp. not
201         to be eliminated).
202         The monomial ordering of R has always 2 blocks, the first
203         block corresponds to the (given) variables to be eliminated.
204@*       If str = \"a\" the first block is a(w1,0..0) and the second block is
205         wp(w) resp. ws(w) if the first variable not to be eliminated is local.
206@*       If str = \"b\" the 1st block has ordering wp(w1) and the 2nd block
207         is wp(w2) resp. ws(w2) if the first variable not to be eliminated is
208         local.
209@*       If the basering is a quotient ring P/Q, then R is also a quotient ring
210         with Q replaced by a standard basis of Q w.r.t. the new ordering
211         (parameters are not touched).
212@*       The intvec L[2] is the intvec of variable weights (or the given w)
213         with weights <= 0 replaced by 1.
214PURPOSE: Prepare a ring for eliminating vars from an ideal/moduel by
215         computing a standard basis in R with a fast monomial ordering.
216         This procedure is used by the procedure elim.
217EXAMPLE: example elimRing; shows an example
218"
219{
220  def BR = basering;
221  int nvarBR = nvars(BR);
222  list BRlist = ringlist(BR);
223  //------------------ set resp. compute ring weights ----------------------
224  int ii;
225  intvec @w;              //to store weights of all variables
226  @w[nvarBR] = 0;
227  @w = @w + 1;            //initialize @w as 1..1
228  string str = "a";       //default for specifying elimination ordering
229  if (size(#) == 0)       //default values
230  {
231     @w = ringweights(BR);     //compute the ring weights (proc from ring.lib)
232  }
233
234  if (size(#) == 1)
235  {
236    if ( typeof(#[1]) == "intvec" )
237    {
238       @w = #[1];              //take the given weights
239    }
240    if ( typeof(#[1]) == "string" )
241    {
242       str = #[1];             //string for specifying elimination ordering
243    }
244  }
245
246  if (size(#) >= 2)
247  {
248    if ( typeof(#[1]) == "intvec" and typeof(#[2]) == "string" )
249    {
250       @w = #[1];              //take the given weights
251       str = #[2];             //string for specifying elimination ordering
252
253    }
254    if ( typeof(#[1]) == "string" and typeof(#[2]) == "intvec" )
255    {
256       str = #[1];             //string for specifying elimination ordering
257       @w = #[2];              //take the given weights
258    }
259  }
260
261  for ( ii=1; ii<=size(@w); ii++ )
262  {
263    if ( @w[ii] <= 0 )
264    {
265       @w[ii] = 1;             //replace non-positive weights by 1
266    }
267  }
268
269  //------ get variables to be eliminated together with their weights -------
270  intvec w1,w2;  //for ringweights of first (w1) and second (w2) block
271  list v1,v2;    //for variables of first (to be liminated) and second block
272
273  for( ii=1; ii<=nvarBR; ii++ )
274  {
275     if( vars/var(ii)==0 )    //treat variables not to be eliminated
276     {
277        w2 = w2,@w[ii];
278        v2 = v2+list(string(var(ii)));
279        if ( ! defined(local) )
280        {
281           int local = (var(ii) < 1);
282         }
283     }
284     else
285     {
286        w1 = w1,@w[ii];
287        v1 = v1+list(string(var(ii)));
288     }
289  }
290
291  if ( size(w1) <= 1 )
292  {
293    return(BR);
294  }
295  if ( size(w2) <= 1 )
296  {
297    ERROR("## elimination of all variables is not possible");
298  }
299
300  w1 = w1[2..size(w1)];
301  w2 = w2[2..size(w2)];
302  BRlist[2] = v1 + v2;         //put variables to be eliminated in front
303
304  //-------- create elimination ordering with two blocks and weights ---------
305  //Assume that the first r of the n variables are to be eliminated.
306  //Then, in case of an a-ordering (default), the new ring ordering will be
307  //of the form (a(1..1,0..0),dp) with r 1's and n-r 0's or (a(w1,0..0),wp(@w))
308  //if there are varaible weights which are not 1.
309  //In the case of a b-ordering the ordering will be a block ordering with two
310  //blocks of the form (dp(r),dp(n-r))  resp. (wp(w1),dp(w2))
311
312  list B3;                     //this will become the list for new ordering
313
314  //----- b-ordering case:
315  if ( str == "b" )
316  {
317    if( w1==1 )              //weights for vars to be eliminated are all 1
318    {
319       B3[1] = list("dp", w1);
320    }
321    else
322    {
323       B3[1] = list("wp", w1);
324    }
325
326    if( w2==1 )              //weights for vars not to be eliminated are all 1
327    {
328       if ( local )
329       {
330          B3[2] = list("ds", w2);
331       }
332       else
333       {
334          B3[2] = list("dp", w2);
335       }
336    }
337    else
338    {
339       if ( local )
340       {
341          B3[2] = list("ws", w2);
342       }
343       else
344       {
345          B3[2] = list("wp", w2);
346       }
347    }
348  }
349
350  //----- a-ordering case:
351  else
352  {
353    //define first the second block
354    if( @w==1 )              //weights for all vars are 1
355    {
356       if ( local )
357       {
358          B3[2] = list("ls", @w);
359       }
360       else
361       {
362          B3[2] = list("dp", @w);
363       }
364    }
365    else
366    {
367       if ( local )
368       {
369          B3[2] = list("ws", @w);
370       }
371       else
372       {
373          B3[2] = list("wp", @w);
374       }
375    }
376
377    //define now the first a-block of the form a(w1,0..0)
378    intvec @v;
379    @v[nvarBR] = 0;
380    @v = @v+w1;
381    B3[1] = list("a", @v);
382  }
383  BRlist[3] = B3;
384
385  //----------- put module ordering always at the end and return -------------
386
387  BRlist[3] = insert(BRlist[3],list("C",intvec(0)),size(B3));
388
389  def eRing = ring(quotientList(BRlist));
390  list result = eRing, @w;
391  return (result);
392}
393example
394{ "EXAMPLE:"; echo = 2;
395   ring R = 0,(x,y,z,u,v),(c,lp);
396   def P = elimRing(yu);  P;
397   intvec w = 1,1,3,4,5;
398   elimRing(yu,w);
399
400   ring S =  (0,a),(x,y,z,u,v),ws(1,2,3,4,5);
401   minpoly = a2+1;
402   qring T = std(ideal(x+y2+v3,(x+v)^2));
403   def Q = elimRing(yv)[1];
404   setring Q; Q;
405}
406///////////////////////////////////////////////////////////////////////////////
407
408proc elim (id, list #)
409"USAGE:   elim(id,arg[,s]);  id ideal/module, arg can be either an intvec v or
410         a product p of variables (type poly), s a string determining the
411         method which can be \"slimgb\" or \"std\" or, additionally,
412         \"withWeigts\".
413RETURN: ideal/module obtained from id by eliminating either the variables
414        with indices appearing in v or the variables appearing in p.
415        Works also in a qring.
416METHOD: elim uses elimRing to create a ring with an elimination ordering for
417        the variables to be eliminated and then applies std if \"std\"
418        is given, or slimgb if \"slimgb\" is given, or a heuristically choosen
419        method.
420@*      If the variables in the basering have weights these weights are used
421        in elimRing. If a string \"withWeigts\" as (optional) argument is given
422        Singular computes weights for the variables to make the input as
423        homogeneous as possible.
424@*      The method is different from that used by eliminate and elim1;
425        depending on the example, any of these commands can be faster.
426NOTE:   No special monomial ordering is required, i.e. the ordering can be
427        local or mixed. The result is a SB with respect to the ordering of
428        the second block used by elimRing. E.g. if the first var not to be
429        eliminated is global, resp. local, this ordering is dp, resp. ds
430        (or wp, resp. ws, with the given weights for these variables).
431        If printlevel > 0 the ring for which the output is a SB is shown.
432SEE ALSO: eliminate, elim1
433EXAMPLE: example elim; shows an example
434"
435{
436  if (size(#) == 0)
437  {
438    ERROR("## specify variables to be eliminated");
439  }
440  int pr = printlevel - voice + 2;   //for ring display if printlevel > 0
441  def BR = basering;
442  list lER;                          //for list returned by elimRing
443//-------------------------------- check input -------------------------------
444  poly vars;
445  int ne;                           //for number of vars to be eliminated
446  int ii;
447  if (size(#) > 0)
448  {
449    if ( typeof(#[1]) == "poly" )
450    {
451      vars = #[1];
452      for( ii=1; ii<=nvars(BR); ii++ )
453      {
454        if ( vars/var(ii) != 0)
455        { ne++; }
456      }
457    }
458    if ( typeof(#[1]) == "intvec" or typeof(#[1]) == "int")
459    {
460      ne = size(#[1]);
461      vars=1;
462      for( ii=1; ii<=ne; ii++ )
463      {
464        vars=vars*var(#[1][ii]);
465      }
466    }
467  }
468
469  string method;                    //for "std" or "slimgb" or "withWeights"
470  if (size(#) >= 2)
471  {
472    if ( typeof(#[2]) == "string" )
473    {
474       if ( #[2] == "withWeights" )
475       {
476         intvec @w = weight(id);        //computation of weights
477       }
478       if ( #[2] == "std" ) { method = "std"; }
479       if ( #[2] == "slimgb" ) { method = "slimgb"; }
480    }
481    if (size(#) == 3)
482    {
483       if ( typeof(#[3]) == "string" )
484       {
485          if ( #[3] == "withWeights" )
486          {
487            intvec @w = weight(id);        //computation of weights
488          }
489          if ( #[3] == "std" ) { method = "std"; }
490          if ( #[3] == "slimgb" ) { method = "slimgb"; }
491       }
492    }
493  }
494
495//-------------- create new ring and map objects to new ring ------------------
496   if ( defined(@w) )
497   {
498      lER = elimRing(vars,@w);  //in this case lER[2] = @w
499   }
500   else
501   {
502      lER = elimRing(vars);
503      intvec @w = lER[2];      //in this case w is the intvec of
504                               //variable weights as computed in elimRing
505   }
506   def ER = lER[1];
507   setring ER;
508   def id = imap(BR,id);
509   poly vars = imap(BR,vars);
510
511//---------- now eliminate in new ring and map back to old ring ---------------
512  //if possible apply std(id,hi,w) where hi is the first hilbert function
513  //of id with respect to the weights w. If w is not defined (i.e. good weights
514  //@w are computed then id is only approximately @w-homogeneous and
515  //the hilbert driven std cannot be used directly; however, stdhilb
516  //homogenizes first and applies the hilbert driven std to the homogenization
517
518   option(redThrough);
519   if (typeof(id)=="matrix")
520   {
521     id = matrix(stdhilb(module(id),method,@w));
522   }
523   else
524   {
525     id = stdhilb(id,method,@w);
526   }
527
528   //### Todo: hier sollte id = groebner(id, "hilb"); verwendet werden.
529   //da z.Zt. (Jan 09) groebener bei extra Gewichtsvektor a(...) aber stets std
530   //aufruft und ausserdem "withWeigts" nicht kennt, ist groebner(id, "hilb")
531   //zunaechst nicht aktiviert. Ev. nach Ueberarbeitung von groebner aktivieren
532
533   id = nselect(id,1..ne);
534   if ( pr > 0 )
535   {
536     "// result is a SB in the following ring:";
537      ER;
538   }
539   setring BR;
540   return(imap(ER,id));
541}
542example
543{ "EXAMPLE:"; echo = 2;
544   ring r=0,(x,y,u,v,w),dp;
545   ideal i=x-u,y-u2,w-u3,v-x+y3;
546   elim(i,3..4);
547   elim(i,uv);
548   int p = printlevel;
549   printlevel = 2;
550   elim(i,uv,"withWeights","slimgb");
551   printlevel = p;
552
553   ring S =  (0,a),(x,y,z,u,v),ws(1,2,3,4,5);
554   minpoly = a2+1;
555   qring T = std(ideal(ax+y2+v3,(x+v)^2));
556   ideal i=x-u,y-u2,az-u3,v-x+ay3;
557   module m=i*gen(1)+i*gen(2);
558   m=elim(m,xy);
559   show(m);
560}
561///////////////////////////////////////////////////////////////////////////////
562
563proc elim2 (id, intvec va)
564"USAGE:   elim2(id,v);  id ideal/module, v intvec
565RETURNS: ideal/module obtained from id by eliminating variables in v
566NOTE:    no special monomial ordering is required, result is a SB with
567         respect to ordering dp (resp. ls) if the first var not to be
568         eliminated belongs to a -p (resp. -s) blockordering
569         This proc uses 'execute' or calls a procedure using 'execute'.
570SEE ALSO: elim1, eliminate, elim
571EXAMPLE: example elim2; shows examples
572"
573{
574//---- get variables to be eliminated and create string for new ordering ------
575   int ii; poly vars=1;
576   for( ii=1; ii<=size(va); ii++ ) { vars=vars*var(va[ii]); }
577   if(  attrib(basering,"global")) { string ordering = "),dp;"; }
578   else { string ordering = "),ls;"; }
579   string mpoly=string(minpoly);
580//-------------- create new ring and map objects to new ring ------------------
581   def br = basering;
582   string str = "ring @newr = ("+charstr(br)+"),("+varstr(br)+ordering;
583   execute(str);
584   if (mpoly!="0") { execute("minpoly="+mpoly+";"); }
585   def i = imap(br,id);
586   poly vars = imap(br,vars);
587//---------- now eliminate in new ring and map back to old ring ---------------
588   i = eliminate(i,vars);
589   setring br;
590   return(imap(@newr,i));
591}
592example
593{ "EXAMPLE:"; echo = 2;
594   ring r=0,(x,y,u,v,w),dp;
595   ideal i=x-u,y-u2,w-u3,v-x+y3;
596   elim2(i,3..4);
597   module m=i*gen(1)+i*gen(2);
598   m=elim2(m,3..4);show(m);
599}
600
601///////////////////////////////////////////////////////////////////////////////
602proc elim1 (id, list #)
603"USAGE:   elim1(id,arg); id ideal/module, arg can be either an intvec v or a
604         product p of variables (type poly)
605RETURN: ideal/module obtained from id by eliminating either the variables
606        with indices appearing in v or the variables appearing in p
607METHOD:  elim1 calls eliminate but in a ring with ordering dp (resp. ls)
608         if the first var not to be eliminated belongs to a -p (resp. -s)
609         ordering.
610NOTE:    no special monomial ordering is required.
611         This proc uses 'execute' or calls a procedure using 'execute'.
612SEE ALSO: elim, eliminate
613EXAMPLE: example elim1; shows examples
614"
615{
616   def br = basering;
617   if ( size(ideal(br)) != 0 )
618   {
619      ERROR ("elim1 cannot eliminate in a qring");
620   }
621//------------- create product vars of variables to be eliminated -------------
622  poly vars;
623  int ii;
624  if (size(#) > 0)
625  {
626    if ( typeof(#[1]) == "poly" ) {  vars = #[1]; }
627    if ( typeof(#[1]) == "intvec" or typeof(#[1]) == "int")
628    {
629      vars=1;
630      for( ii=1; ii<=size(#[1]); ii++ )
631      {
632        vars=vars*var(#[1][ii]);
633      }
634    }
635  }
636//---- get variables to be eliminated and create string for new ordering ------
637   for( ii=1; ii<=nvars(basering); ii++ )
638   {
639      if( vars/var(ii)==0 ) { poly p = 1+var(ii); break;}
640   }
641   if( ord(p)==0 ) { string ordering = "),ls;"; }
642   if( ord(p)>0 ) { string ordering = "),dp;"; }
643//-------------- create new ring and map objects to new ring ------------------
644   string str = "ring @newr = ("+charstr(br)+"),("+varstr(br)+ordering;
645   execute(str);
646   def id = fetch(br,id);
647   poly vars = fetch(br,vars);
648//---------- now eliminate in new ring and map back to old ring ---------------
649   id = eliminate(id,vars);
650   setring br;
651   return(imap(@newr,id));
652}
653example
654{ "EXAMPLE:"; echo = 2;
655   ring r=0,(x,y,t,s,z),dp;
656   ideal i=x-t,y-t2,z-t3,s-x+y3;
657   elim1(i,ts);
658   module m=i*gen(1)+i*gen(2);
659   m=elim1(m,3..4); show(m);
660}
661///////////////////////////////////////////////////////////////////////////////
662
663proc nselect (id, intvec v)
664"USAGE:   nselect(id,v); id = ideal, module or matrix, v = intvec
665RETURN:  generators (or columns) of id not containing the variables with index
666         an entry of v
667SEE ALSO: select, select1
668EXAMPLE: example nselect; shows examples
669"
670{
671   if (typeof(id) != "ideal")
672   {
673      if (typeof(id)=="module" || typeof(id)=="matrix")
674      {
675        module id1 = module(id);
676      }
677      else
678      {
679        ERROR("// *** input must be of type ideal or module or matrix");
680      }
681   }
682   else
683   {
684      ideal id1 = id;
685   }
686   int j,k;
687   int n,m = size(v), ncols(id1);
688   for( k=1; k<=m; k++ )
689   {
690      for( j=1; j<=n; j++ )
691      {
692        if( size(id1[k]/var(v[j]))!=0 )
693        {
694           id1[k]=0; break;
695        }
696      }
697   }
698   if(typeof(id)=="matrix")
699   {
700      return(matrix(simplify(id1,2)));
701   }
702   return(simplify(id1,2));
703}
704example
705{ "EXAMPLE:"; echo = 2;
706   ring r=0,(x,y,t,s,z),(c,dp);
707   ideal i=x-y,y-z2,z-t3,s-x+y3;
708   nselect(i,3);
709   module m=i*(gen(1)+gen(2));
710   m;
711   nselect(m,3..4);
712   nselect(matrix(m),3..4);
713}
714///////////////////////////////////////////////////////////////////////////////
715
716proc sat (id, ideal j)
717"USAGE:   sat(id,j);  id=ideal/module, j=ideal
718RETURN:  list of an ideal/module [1] and an integer [2]:
719         [1] = saturation of id with respect to j (= union_(k=1...) of id:j^k)
720         [2] = saturation exponent (= min( k | id:j^k = id:j^(k+1) ))
721NOTE:    [1] is a standard basis in the basering
722DISPLAY: saturation exponent during computation if printlevel >=1
723EXAMPLE: example sat; shows an example
724"{
725   int ii,kk;
726   def i=id;
727   id=std(id);
728   int p = printlevel-voice+3;  // p=printlevel+1 (default: p=1)
729   while( ii<=size(i) )
730   {
731      dbprint(p-1,"// compute quotient "+string(kk+1));
732      i=quotient(id,j);
733      for( ii=1; ii<=size(i); ii++ )
734      {
735         if( reduce(i[ii],id,1)!=0 ) break;
736      }
737      id=std(i); kk++;
738   }
739   dbprint(p-1,"// saturation becomes stable after "+string(kk-1)+" iteration(s)","");
740   list L = id,kk-1;
741   return (L);
742}
743example
744{ "EXAMPLE:"; echo = 2;
745   int p      = printlevel;
746   ring r     = 2,(x,y,z),dp;
747   poly F     = x5+y5+(x-y)^2*xyz;
748   ideal j    = jacob(F);
749   sat(j,maxideal(1));
750   printlevel = 2;
751   sat(j,maxideal(2));
752   printlevel = p;
753}
754///////////////////////////////////////////////////////////////////////////////
755
756proc select (id, intvec v)
757"USAGE:   select(id,n[,m]); id = ideal/module/matrix, v = intvec
758RETURN:  generators/columns of id containing all variables with index
759         an entry of v
760NOTE:    use 'select1' for selecting generators/columns containing at least
761         one of the variables with index an entry of v
762SEE ALSO: select1, nselect
763EXAMPLE: example select; shows examples
764"
765{
766   if (typeof(id) != "ideal")
767   {
768      if (typeof(id)=="module" || typeof(id)=="matrix")
769      {
770        module id1 = module(id);
771      }
772      else
773      {
774        ERROR("// *** input must be of type ideal or module or matrix");
775      }
776   }
777   else
778   {
779      ideal id1 = id;
780   }
781   int j,k;
782   int n,m = size(v), ncols(id1);
783   for( k=1; k<=m; k++ )
784   {
785      for( j=1; j<=n; j++ )
786      {
787         if( size(id1[k]/var(v[j]))==0)
788         {
789            id1[k]=0; break;
790         }
791      }
792   }
793   if(typeof(id)=="matrix")
794   {
795      return(matrix(simplify(id1,2)));
796   }
797   return(simplify(id1,2));
798}
799example
800{ "EXAMPLE:"; echo = 2;
801   ring r=0,(x,y,t,s,z),(c,dp);
802   ideal i=x-y,y-z2,z-t3,s-x+y3;
803   ideal j=select(i,1);
804   j;
805   module m=i*(gen(1)+gen(2));
806   m;
807   select(m,1..2);
808   select(matrix(m),1..2);
809}
810///////////////////////////////////////////////////////////////////////////////
811
812proc select1 (id, intvec v)
813"USAGE:   select1(id,v); id = ideal/module/matrix, v = intvec
814RETURN:  generators/columns of id containing at least one of the variables
815         with index an entry of v
816NOTE:    use 'select' for selecting generators/columns containing all variables
817         with index an entry of v
818SEE ALSO: select, nselect
819EXAMPLE: example select1; shows examples
820"
821{
822   if (typeof(id) != "ideal")
823   {
824      if (typeof(id)=="module" || typeof(id)=="matrix")
825      {
826        module id1 = module(id);
827        module I;
828      }
829      else
830      {
831        ERROR("// *** input must be of type ideal or module or matrix");
832      }
833   }
834   else
835   {
836      ideal id1 = id;
837      ideal I;
838   }
839   int j,k;
840   int n,m = size(v), ncols(id1);
841   for( k=1; k<=m; k++ )
842   {  for( j=1; j<=n; j++ )
843      {
844         if( size(subst(id1[k],var(v[j]),0)) != size(id1[k]) )
845         {
846            I = I,id1[k]; break;
847         }
848      }
849   }
850   if(typeof(id)=="matrix")
851   {
852      return(matrix(simplify(I,2)));
853   }
854   return(simplify(I,2));
855}
856example
857{ "EXAMPLE:"; echo = 2;
858   ring r=0,(x,y,t,s,z),(c,dp);
859   ideal i=x-y,y-z2,z-t3,s-x+y3;
860   ideal j=select1(i,1);j;
861   module m=i*(gen(1)+gen(2)); m;
862   select1(m,1..2);
863   select1(matrix(m),1..2);
864}
865/*
866///////////////////////////////////////////////////////////////////////////////
867//                      EXAMPLEs
868///////////////////////////////////////////////////////////////////////////////
869// Siehe auch file 'tst-elim' mit grossem Beispiel;
870example blowup0;
871example elimRing;
872example elim;
873example elim1;
874example nselect;
875example sat;
876example select;
877example select1;
878//===========================================================================
879//         Rationale Normalkurve vom Grad d im P^d bzw. im A^d:
880//homogen s:t -> (t^d:t^(d-1)s: ...: s^d), inhomogen t ->(t^d:t^(d-1): ...:t)
881
882//------------------- 1. Homogen:
883//Varianten der Methode
884int d = 5;
885ring R = 0,(s,t,x(0..d)),dp;
886ideal I;
887for( int ii=0; ii<=d; ii++) {I = I,ideal(x(ii)-t^(d-ii)*s^ii); }
888
889int tt = timer;
890ideal eI = elim(I,1..2,"std");
891ideal eI = elim(I,1..2,"slimgb");
892ideal eI = elim(I,st,"withWeights");
893ideal eI = elim(I,st,"std","withWeights");
894//komplizierter
895int d = 50;
896ring R = 0,(s,t,x(0..d)),dp;
897ideal I;
898for( int ii=0; ii<=d; ii++) {I = I,ideal(x(ii)-t^(d-ii)*s^ii); }
899int tt = timer;
900ideal eI = elim(I,1..2);               //56(44)sec (slimgb 22(17),hilb 33(26))
901timer-tt; tt = timer;
902ideal eI = elim1(I,1..2);              //71(53)sec
903timer-tt; tt = timer;
904ideal eI = eliminate(I,st);            //70(51)sec (wie elim1)
905timer-tt;
906timer-tt; tt = timer;
907ideal eI = elim(I,1..2,"withWeights"); //190(138)sec
908                                //(weights73(49), slimgb43(33), hilb71(53)
909timer-tt;
910//------------------- 2. Inhomogen
911int d = 50;
912ring r = 0,(t,x(0..d)),dp;
913ideal I;
914for( int ii=0; ii<=d; ii++) {I = I+ideal(x(ii)-t^(d-ii)); }
915int tt = timer;
916ideal eI = elim(I,1,);                //20(15)sec (slimgb13(10), hilb6(5))
917ideal eI = elim(I,1,"std");           //17sec (std 11, hilb 6)
918timer-tt; tt = timer;
919ideal eI = elim1(I,t);               //8(6)sec
920timer-tt; tt = timer;
921ideal eI = eliminate(I,t);           //7(6)sec
922timer-tt;
923timer-tt; tt = timer;
924ideal eI = elim(I,1..1,"withWeights"); //189(47)sec
925//(weights73(42), slimgb43(1), hilb70(2)
926timer-tt;
927
928//===========================================================================
929//        Zufaellige Beispiele, homogen
930system("random",37);
931ring R = 0,x(1..6),lp;
932ideal I = sparseid(4,3);
933
934int tt = timer;
935ideal eI = elim(I,1);                //108(85)sec (slimgb 29(23), hilb79(61)
936timer-tt; tt = timer;
937ideal eI = elim(I,1,"std");          //(139)sec (std 77, hilb 61)
938timer-tt; tt = timer;
939ideal eI = elim1(I,1);               //(nach 45 min abgebrochen)
940timer-tt; tt = timer;
941ideal eI = eliminate(I,x(1));        //(nach 45 min abgebrochen)
942timer-tt; tt = timer;
943
944//        Zufaellige Beispiele, inhomogen
945system("random",37);
946ring R = 32003,x(1..5),dp;
947ideal I = sparseid(4,2,3);
948option(prot,redThrough);
949
950intvec w = 1,1,1,1,1,1;
951int tt = timer;
952ideal eI = elim(I,1,w);            //(nach 5min abgebr.) hilb schlaegt nicht zu
953timer-tt; tt = timer;              //BUG!!!!!!
954
955int tt = timer;
956ideal eI = elim(I,1);              //(nach 5min abgebr.) hilb schlaegt nicht zu
957timer-tt; tt = timer;              //BUG!!!!!!
958ideal eI = elim1(I,1);             //8(7.8)sec
959timer-tt; tt = timer;
960ideal eI = eliminate(I,x(1));      //8(7.8)sec
961timer-tt; tt = timer;
962
963                              BUG!!!!
964//        Zufaellige Beispiele, inhomogen, lokal
965system("random",37);
966ring R = 32003,x(1..6),ds;
967ideal I = sparseid(4,1,2);
968option(prot,redThrough);
969int tt = timer;
970ideal eI = elim(I,1);                //(haengt sich auf)
971timer-tt; tt = timer;
972ideal eI = elim1(I,1);               //(0)sec !!!!!!
973timer-tt; tt = timer;
974ideal eI = eliminate(I,x(1));        //(ewig mit ...., abgebrochen)
975timer-tt; tt = timer;
976
977ring R1 =(32003),(x(1),x(2),x(3),x(4),x(5),x(6)),(a(1,0,0,0,0,0),ds,C);
978ideal I = imap(R,I);
979I = std(I);                           //(haengt sich auf) !!!!!!!
980
981ideal eI = elim(I,1..1,"withWeights"); //(47)sec (weights42, slimgb1, hilb2)
982timer-tt;
983
984ring R1 =(32003),(x(1),x(2),x(3),x(4),x(5),x(6)),(a(1,0,0,0,0,0),ds,C);
985ideal I = imap(R,I);
986I = std(I);                           //(haengt sich auf) !!!!!!!
987
988ideal eI = elim(I,1..1,"withWeights"); //(47)sec (weights42, slimgb1, hilb2)
989timer-tt;
990*/
Note: See TracBrowser for help on using the repository browser.