source: git/Singular/LIB/elim.lib @ 334c21f

spielwiese
Last change on this file since 334c21f was 3360fb, checked in by Hans Schönemann <hannes@…>, 15 years ago
*hannes: format git-svn-id: file:///usr/local/Singular/svn/trunk@11695 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 30.9 KB
Line 
1// $Id: elim.lib,v 1.30 2009-04-14 12:00:14 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.30 2009-04-14 12:00:14 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 minus the 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, blowUp2
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=1:nvarBR;     //to store weights of all variables
226  string str = "a";       //default for specifying elimination ordering
227  if (size(#) == 0)       //default values
228  {
229     @w = ringweights(BR);     //compute the ring weights (proc from ring.lib)
230  }
231
232  if (size(#) == 1)
233  {
234    if ( typeof(#[1]) == "intvec" )
235    {
236       @w = #[1];              //take the given weights
237    }
238    if ( typeof(#[1]) == "string" )
239    {
240       str = #[1];             //string for specifying elimination ordering
241    }
242  }
243
244  if (size(#) >= 2)
245  {
246    if ( typeof(#[1]) == "intvec" and typeof(#[2]) == "string" )
247    {
248       @w = #[1];              //take the given weights
249       str = #[2];             //string for specifying elimination ordering
250    }
251    if ( typeof(#[1]) == "string" and typeof(#[2]) == "intvec" )
252    {
253       str = #[1];             //string for specifying elimination ordering
254       @w = #[2];              //take the given weights
255    }
256  }
257
258  for ( ii=1; ii<=size(@w); ii++ )
259  {
260    if ( @w[ii] <= 0 )
261    {
262       @w[ii] = 1;             //replace non-positive weights by 1
263    }
264  }
265
266  //------ get variables to be eliminated together with their weights -------
267  intvec w1,w2;  //for ringweights of first (w1) and second (w2) block
268  list v1,v2;    //for variables of first (to be liminated) and second block
269
270  for( ii=1; ii<=nvarBR; ii++ )
271  {
272     if( vars/var(ii)==0 )    //treat variables not to be eliminated
273     {
274        w2 = w2,@w[ii];
275        v2 = v2+list(string(var(ii)));
276        if ( ! defined(local) )
277        {
278           int local = (var(ii) < 1);
279        }
280     }
281     else
282     {
283        w1 = w1,@w[ii];
284        v1 = v1+list(string(var(ii)));
285     }
286  }
287
288  if ( size(w1) <= 1 )
289  {
290    return(BR);
291  }
292  if ( size(w2) <= 1 )
293  {
294    ERROR("## elimination of all variables is not possible");
295  }
296
297  w1 = w1[2..size(w1)];
298  w2 = w2[2..size(w2)];
299  BRlist[2] = v1 + v2;         //put variables to be eliminated in front
300
301  //-------- create elimination ordering with two blocks and weights ---------
302  //Assume that the first r of the n variables are to be eliminated.
303  //Then, in case of an a-ordering (default), the new ring ordering will be
304  //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))
305  //if there are varaible weights which are not 1.
306  //In the case of a b-ordering the ordering will be a block ordering with two
307  //blocks of the form (dp(r),dp(n-r))  resp. (wp(w1),dp(w2))
308
309  list B3;                     //this will become the list for new ordering
310
311  //----- b-ordering case:
312  if ( str == "b" )
313  {
314    if( w1==1 )              //weights for vars to be eliminated are all 1
315    {
316       B3[1] = list("dp", w1);
317    }
318    else
319    {
320       B3[1] = list("wp", w1);
321    }
322
323    if( w2==1 )              //weights for vars not to be eliminated are all 1
324    {
325       if ( local )
326       {
327          B3[2] = list("ds", w2);
328       }
329       else
330       {
331          B3[2] = list("dp", w2);
332       }
333    }
334    else
335    {
336       if ( local )
337       {
338          B3[2] = list("ws", w2);
339       }
340       else
341       {
342          B3[2] = list("wp", w2);
343       }
344    }
345  }
346
347  //----- a-ordering case:
348  else
349  {
350    //define first the second block
351    if( @w==1 )              //weights for all vars are 1
352    {
353       if ( local )
354       {
355          B3[2] = list("ls", @w);
356       }
357       else
358       {
359          B3[2] = list("dp", @w);
360       }
361    }
362    else
363    {
364       if ( local )
365       {
366          B3[2] = list("ws", @w);
367       }
368       else
369       {
370          B3[2] = list("wp", @w);
371       }
372    }
373
374    //define now the first a-block of the form a(w1,0..0)
375    intvec @v=0:nvarBR;
376    @v = @v+w1;
377    B3[1] = list("a", @v);
378  }
379  BRlist[3] = B3;
380
381  //----------- put module ordering always at the end and return -------------
382
383  BRlist[3] = insert(BRlist[3],list("C",intvec(0)),size(B3));
384
385  def eRing = ring(quotientList(BRlist));
386  list result = eRing, @w;
387  return (result);
388}
389example
390{ "EXAMPLE:"; echo = 2;
391   ring R = 0,(x,y,z,u,v),(c,lp);
392   def P = elimRing(yu);  P;
393   intvec w = 1,1,3,4,5;
394   elimRing(yu,w);
395
396   ring S =  (0,a),(x,y,z,u,v),ws(1,2,3,4,5);
397   minpoly = a2+1;
398   qring T = std(ideal(x+y2+v3,(x+v)^2));
399   def Q = elimRing(yv)[1];
400   setring Q; Q;
401}
402///////////////////////////////////////////////////////////////////////////////
403
404proc elim (id, list #)
405"USAGE:   elim(id,arg[,s]);  id ideal/module, arg can be either an intvec v or
406         a product p of variables (type poly), s a string determining the
407         method which can be \"slimgb\" or \"std\" or, additionally,
408         \"withWeigts\".
409RETURN: ideal/module obtained from id by eliminating either the variables
410        with indices appearing in v or the variables appearing in p.
411        Works also in a qring.
412METHOD: elim uses elimRing to create a ring with an elimination ordering for
413        the variables to be eliminated and then applies std if \"std\"
414        is given, or slimgb if \"slimgb\" is given, or a heuristically choosen
415        method.
416@*      If the variables in the basering have weights these weights are used
417        in elimRing. If a string \"withWeigts\" as (optional) argument is given
418        Singular computes weights for the variables to make the input as
419        homogeneous as possible.
420@*      The method is different from that used by eliminate and elim1;
421        depending on the example, any of these commands can be faster.
422NOTE:   No special monomial ordering is required, i.e. the ordering can be
423        local or mixed. The result is a SB with respect to the ordering of
424        the second block used by elimRing. E.g. if the first var not to be
425        eliminated is global, resp. local, this ordering is dp, resp. ds
426        (or wp, resp. ws, with the given weights for these variables).
427        If printlevel > 0 the ring for which the output is a SB is shown.
428SEE ALSO: eliminate, elim1
429EXAMPLE: example elim; shows an example
430"
431{
432  if (size(#) == 0)
433  {
434    ERROR("## specify variables to be eliminated");
435  }
436  int pr = printlevel - voice + 2;   //for ring display if printlevel > 0
437  def BR = basering;
438  list lER;                          //for list returned by elimRing
439//-------------------------------- check input -------------------------------
440  poly vars;
441  int ne;                           //for number of vars to be eliminated
442  int ii;
443  if (size(#) > 0)
444  {
445    if ( typeof(#[1]) == "poly" )
446    {
447      vars = #[1];
448      for( ii=1; ii<=nvars(BR); ii++ )
449      {
450        if ( vars/var(ii) != 0)
451        { ne++; }
452      }
453    }
454    if ( typeof(#[1]) == "intvec" or typeof(#[1]) == "int")
455    {
456      ne = size(#[1]);
457      vars=1;
458      for( ii=1; ii<=ne; ii++ )
459      {
460        vars=vars*var(#[1][ii]);
461      }
462    }
463  }
464
465  string method;                    //for "std" or "slimgb" or "withWeights"
466  if (size(#) >= 2)
467  {
468    if ( typeof(#[2]) == "string" )
469    {
470       if ( #[2] == "withWeights" )
471       {
472         intvec @w = weight(id);        //computation of weights
473       }
474       if ( #[2] == "std" ) { method = "std"; }
475       if ( #[2] == "slimgb" ) { method = "slimgb"; }
476    }
477    if (size(#) == 3)
478    {
479       if ( typeof(#[3]) == "string" )
480       {
481          if ( #[3] == "withWeights" )
482          {
483            intvec @w = weight(id);        //computation of weights
484          }
485          if ( #[3] == "std" ) { method = "std"; }
486          if ( #[3] == "slimgb" ) { method = "slimgb"; }
487       }
488    }
489  }
490
491//-------------- create new ring and map objects to new ring ------------------
492   if ( defined(@w) )
493   {
494      lER = elimRing(vars,@w);  //in this case lER[2] = @w
495   }
496   else
497   {
498      lER = elimRing(vars);
499      intvec @w = lER[2];      //in this case w is the intvec of
500                               //variable weights as computed in elimRing
501   }
502   def ER = lER[1];
503   setring ER;
504   def id = imap(BR,id);
505   poly vars = imap(BR,vars);
506
507//---------- now eliminate in new ring and map back to old ring ---------------
508  //if possible apply std(id,hi,w) where hi is the first hilbert function
509  //of id with respect to the weights w. If w is not defined (i.e. good weights
510  //@w are computed then id is only approximately @w-homogeneous and
511  //the hilbert driven std cannot be used directly; however, stdhilb
512  //homogenizes first and applies the hilbert driven std to the homogenization
513
514   option(redThrough);
515   if (typeof(id)=="matrix")
516   {
517     id = matrix(stdhilb(module(id),method,@w));
518   }
519   else
520   {
521     id = stdhilb(id,method,@w);
522   }
523
524   //### Todo: hier sollte id = groebner(id, "hilb"); verwendet werden.
525   //da z.Zt. (Jan 09) groebener bei extra Gewichtsvektor a(...) aber stets std
526   //aufruft und ausserdem "withWeigts" nicht kennt, ist groebner(id, "hilb")
527   //zunaechst nicht aktiviert. Ev. nach Ueberarbeitung von groebner aktivieren
528
529   id = nselect(id,1..ne);
530   if ( pr > 0 )
531   {
532     "// result is a SB in the following ring:";
533      ER;
534   }
535   setring BR;
536   return(imap(ER,id));
537}
538example
539{ "EXAMPLE:"; echo = 2;
540   ring r=0,(x,y,u,v,w),dp;
541   ideal i=x-u,y-u2,w-u3,v-x+y3;
542   elim(i,3..4);
543   elim(i,uv);
544   int p = printlevel;
545   printlevel = 2;
546   elim(i,uv,"withWeights","slimgb");
547   printlevel = p;
548
549   ring S =  (0,a),(x,y,z,u,v),ws(1,2,3,4,5);
550   minpoly = a2+1;
551   qring T = std(ideal(ax+y2+v3,(x+v)^2));
552   ideal i=x-u,y-u2,az-u3,v-x+ay3;
553   module m=i*gen(1)+i*gen(2);
554   m=elim(m,xy);
555   show(m);
556}
557///////////////////////////////////////////////////////////////////////////////
558
559proc elim2 (id, intvec va)
560"USAGE:   elim2(id,v);  id ideal/module, v intvec
561RETURNS: ideal/module obtained from id by eliminating variables in v
562NOTE:    no special monomial ordering is required, result is a SB with
563         respect to ordering dp (resp. ls) if the first var not to be
564         eliminated belongs to a -p (resp. -s) blockordering
565         This proc uses 'execute' or calls a procedure using 'execute'.
566SEE ALSO: elim1, eliminate, elim
567EXAMPLE: example elim2; shows examples
568"
569{
570//---- get variables to be eliminated and create string for new ordering ------
571   int ii; poly vars=1;
572   for( ii=1; ii<=size(va); ii++ ) { vars=vars*var(va[ii]); }
573   if(  attrib(basering,"global")) { string ordering = "),dp;"; }
574   else { string ordering = "),ls;"; }
575   string mpoly=string(minpoly);
576//-------------- create new ring and map objects to new ring ------------------
577   def br = basering;
578   string str = "ring @newr = ("+charstr(br)+"),("+varstr(br)+ordering;
579   execute(str);
580   if (mpoly!="0") { execute("minpoly="+mpoly+";"); }
581   def i = imap(br,id);
582   poly vars = imap(br,vars);
583//---------- now eliminate in new ring and map back to old ring ---------------
584   i = eliminate(i,vars);
585   setring br;
586   return(imap(@newr,i));
587}
588example
589{ "EXAMPLE:"; echo = 2;
590   ring r=0,(x,y,u,v,w),dp;
591   ideal i=x-u,y-u2,w-u3,v-x+y3;
592   elim2(i,3..4);
593   module m=i*gen(1)+i*gen(2);
594   m=elim2(m,3..4);show(m);
595}
596
597///////////////////////////////////////////////////////////////////////////////
598proc elim1 (id, list #)
599"USAGE:   elim1(id,arg); id ideal/module, arg can be either an intvec v or a
600         product p of variables (type poly)
601RETURN: ideal/module obtained from id by eliminating either the variables
602        with indices appearing in v or the variables appearing in p
603METHOD:  elim1 calls eliminate but in a ring with ordering dp (resp. ls)
604         if the first var not to be eliminated belongs to a -p (resp. -s)
605         ordering.
606NOTE:    no special monomial ordering is required.
607         This proc uses 'execute' or calls a procedure using 'execute'.
608SEE ALSO: elim, eliminate
609EXAMPLE: example elim1; shows examples
610"
611{
612   def br = basering;
613   if ( size(ideal(br)) != 0 )
614   {
615      ERROR ("elim1 cannot eliminate in a qring");
616   }
617//------------- create product vars of variables to be eliminated -------------
618  poly vars;
619  int ii;
620  if (size(#) > 0)
621  {
622    if ( typeof(#[1]) == "poly" ) {  vars = #[1]; }
623    if ( typeof(#[1]) == "intvec" or typeof(#[1]) == "int")
624    {
625      vars=1;
626      for( ii=1; ii<=size(#[1]); ii++ )
627      {
628        vars=vars*var(#[1][ii]);
629      }
630    }
631  }
632//---- get variables to be eliminated and create string for new ordering ------
633   for( ii=1; ii<=nvars(basering); ii++ )
634   {
635      if( vars/var(ii)==0 ) { poly p = 1+var(ii); break;}
636   }
637   if( ord(p)==0 ) { string ordering = "),ls;"; }
638   if( ord(p)>0 ) { string ordering = "),dp;"; }
639//-------------- create new ring and map objects to new ring ------------------
640   string str = "ring @newr = ("+charstr(br)+"),("+varstr(br)+ordering;
641   execute(str);
642   def id = fetch(br,id);
643   poly vars = fetch(br,vars);
644//---------- now eliminate in new ring and map back to old ring ---------------
645   id = eliminate(id,vars);
646   setring br;
647   return(imap(@newr,id));
648}
649example
650{ "EXAMPLE:"; echo = 2;
651   ring r=0,(x,y,t,s,z),dp;
652   ideal i=x-t,y-t2,z-t3,s-x+y3;
653   elim1(i,ts);
654   module m=i*gen(1)+i*gen(2);
655   m=elim1(m,3..4); show(m);
656}
657///////////////////////////////////////////////////////////////////////////////
658
659proc nselect (id, intvec v)
660"USAGE:   nselect(id,v); id = ideal, module or matrix, v = intvec
661RETURN:  generators (or columns) of id not containing the variables with index
662         an entry of v
663SEE ALSO: select, select1
664EXAMPLE: example nselect; shows examples
665"
666{
667   if (typeof(id) != "ideal")
668   {
669      if (typeof(id)=="module" || typeof(id)=="matrix")
670      {
671        module id1 = module(id);
672      }
673      else
674      {
675        ERROR("// *** input must be of type ideal or module or matrix");
676      }
677   }
678   else
679   {
680      ideal id1 = id;
681   }
682   int j,k;
683   int n,m = size(v), ncols(id1);
684   for( k=1; k<=m; k++ )
685   {
686      for( j=1; j<=n; j++ )
687      {
688        if( size(id1[k]/var(v[j]))!=0 )
689        {
690           id1[k]=0; break;
691        }
692      }
693   }
694   if(typeof(id)=="matrix")
695   {
696      return(matrix(simplify(id1,2)));
697   }
698   return(simplify(id1,2));
699}
700example
701{ "EXAMPLE:"; echo = 2;
702   ring r=0,(x,y,t,s,z),(c,dp);
703   ideal i=x-y,y-z2,z-t3,s-x+y3;
704   nselect(i,3);
705   module m=i*(gen(1)+gen(2));
706   m;
707   nselect(m,3..4);
708   nselect(matrix(m),3..4);
709}
710///////////////////////////////////////////////////////////////////////////////
711
712proc sat (id, ideal j)
713"USAGE:   sat(id,j);  id=ideal/module, j=ideal
714RETURN:  list of an ideal/module [1] and an integer [2]:
715         [1] = saturation of id with respect to j (= union_(k=1...) of id:j^k)
716         [2] = saturation exponent (= min( k | id:j^k = id:j^(k+1) ))
717NOTE:    [1] is a standard basis in the basering
718DISPLAY: saturation exponent during computation if printlevel >=1
719EXAMPLE: example sat; shows an example
720"{
721   int ii,kk;
722   def i=id;
723   id=std(id);
724   int p = printlevel-voice+3;  // p=printlevel+1 (default: p=1)
725   while( ii<=size(i) )
726   {
727      dbprint(p-1,"// compute quotient "+string(kk+1));
728      i=quotient(id,j);
729      for( ii=1; ii<=size(i); ii++ )
730      {
731         if( reduce(i[ii],id,1)!=0 ) break;
732      }
733      id=std(i); kk++;
734   }
735   dbprint(p-1,"// saturation becomes stable after "+string(kk-1)+" iteration(s)","");
736   list L = id,kk-1;
737   return (L);
738}
739example
740{ "EXAMPLE:"; echo = 2;
741   int p      = printlevel;
742   ring r     = 2,(x,y,z),dp;
743   poly F     = x5+y5+(x-y)^2*xyz;
744   ideal j    = jacob(F);
745   sat(j,maxideal(1));
746   printlevel = 2;
747   sat(j,maxideal(2));
748   printlevel = p;
749}
750///////////////////////////////////////////////////////////////////////////////
751
752proc select (id, intvec v)
753"USAGE:   select(id,n[,m]); id = ideal/module/matrix, v = intvec
754RETURN:  generators/columns of id containing all variables with index
755         an entry of v
756NOTE:    use 'select1' for selecting generators/columns containing at least
757         one of the variables with index an entry of v
758SEE ALSO: select1, nselect
759EXAMPLE: example select; shows examples
760"
761{
762   if (typeof(id) != "ideal")
763   {
764      if (typeof(id)=="module" || typeof(id)=="matrix")
765      {
766        module id1 = module(id);
767      }
768      else
769      {
770        ERROR("// *** input must be of type ideal or module or matrix");
771      }
772   }
773   else
774   {
775      ideal id1 = id;
776   }
777   int j,k;
778   int n,m = size(v), ncols(id1);
779   for( k=1; k<=m; k++ )
780   {
781      for( j=1; j<=n; j++ )
782      {
783         if( size(id1[k]/var(v[j]))==0)
784         {
785            id1[k]=0; break;
786         }
787      }
788   }
789   if(typeof(id)=="matrix")
790   {
791      return(matrix(simplify(id1,2)));
792   }
793   return(simplify(id1,2));
794}
795example
796{ "EXAMPLE:"; echo = 2;
797   ring r=0,(x,y,t,s,z),(c,dp);
798   ideal i=x-y,y-z2,z-t3,s-x+y3;
799   ideal j=select(i,1);
800   j;
801   module m=i*(gen(1)+gen(2));
802   m;
803   select(m,1..2);
804   select(matrix(m),1..2);
805}
806///////////////////////////////////////////////////////////////////////////////
807
808proc select1 (id, intvec v)
809"USAGE:   select1(id,v); id = ideal/module/matrix, v = intvec
810RETURN:  generators/columns of id containing at least one of the variables
811         with index an entry of v
812NOTE:    use 'select' for selecting generators/columns containing all variables
813         with index an entry of v
814SEE ALSO: select, nselect
815EXAMPLE: example select1; shows examples
816"
817{
818   if (typeof(id) != "ideal")
819   {
820      if (typeof(id)=="module" || typeof(id)=="matrix")
821      {
822        module id1 = module(id);
823        module I;
824      }
825      else
826      {
827        ERROR("// *** input must be of type ideal or module or matrix");
828      }
829   }
830   else
831   {
832      ideal id1 = id;
833      ideal I;
834   }
835   int j,k;
836   int n,m = size(v), ncols(id1);
837   for( k=1; k<=m; k++ )
838   {  for( j=1; j<=n; j++ )
839      {
840         if( size(subst(id1[k],var(v[j]),0)) != size(id1[k]) )
841         {
842            I = I,id1[k]; break;
843         }
844      }
845   }
846   if(typeof(id)=="matrix")
847   {
848      return(matrix(simplify(I,2)));
849   }
850   return(simplify(I,2));
851}
852example
853{ "EXAMPLE:"; echo = 2;
854   ring r=0,(x,y,t,s,z),(c,dp);
855   ideal i=x-y,y-z2,z-t3,s-x+y3;
856   ideal j=select1(i,1);j;
857   module m=i*(gen(1)+gen(2)); m;
858   select1(m,1..2);
859   select1(matrix(m),1..2);
860}
861/*
862///////////////////////////////////////////////////////////////////////////////
863//                      EXAMPLEs
864///////////////////////////////////////////////////////////////////////////////
865// Siehe auch file 'tst-elim' mit grossem Beispiel;
866example blowup0;
867example elimRing;
868example elim;
869example elim1;
870example nselect;
871example sat;
872example select;
873example select1;
874//===========================================================================
875//         Rationale Normalkurve vom Grad d im P^d bzw. im A^d:
876//homogen s:t -> (t^d:t^(d-1)s: ...: s^d), inhomogen t ->(t^d:t^(d-1): ...:t)
877
878//------------------- 1. Homogen:
879//Varianten der Methode
880int d = 5;
881ring R = 0,(s,t,x(0..d)),dp;
882ideal I;
883for( int ii=0; ii<=d; ii++) {I = I,ideal(x(ii)-t^(d-ii)*s^ii); }
884
885int tt = timer;
886ideal eI = elim(I,1..2,"std");
887ideal eI = elim(I,1..2,"slimgb");
888ideal eI = elim(I,st,"withWeights");
889ideal eI = elim(I,st,"std","withWeights");
890//komplizierter
891int d = 50;
892ring R = 0,(s,t,x(0..d)),dp;
893ideal I;
894for( int ii=0; ii<=d; ii++) {I = I,ideal(x(ii)-t^(d-ii)*s^ii); }
895int tt = timer;
896ideal eI = elim(I,1..2);               //56(44)sec (slimgb 22(17),hilb 33(26))
897timer-tt; tt = timer;
898ideal eI = elim1(I,1..2);              //71(53)sec
899timer-tt; tt = timer;
900ideal eI = eliminate(I,st);            //70(51)sec (wie elim1)
901timer-tt;
902timer-tt; tt = timer;
903ideal eI = elim(I,1..2,"withWeights"); //190(138)sec
904                                //(weights73(49), slimgb43(33), hilb71(53)
905timer-tt;
906//------------------- 2. Inhomogen
907int d = 50;
908ring r = 0,(t,x(0..d)),dp;
909ideal I;
910for( int ii=0; ii<=d; ii++) {I = I+ideal(x(ii)-t^(d-ii)); }
911int tt = timer;
912ideal eI = elim(I,1,);                //20(15)sec (slimgb13(10), hilb6(5))
913ideal eI = elim(I,1,"std");           //17sec (std 11, hilb 6)
914timer-tt; tt = timer;
915ideal eI = elim1(I,t);               //8(6)sec
916timer-tt; tt = timer;
917ideal eI = eliminate(I,t);           //7(6)sec
918timer-tt;
919timer-tt; tt = timer;
920ideal eI = elim(I,1..1,"withWeights"); //189(47)sec
921//(weights73(42), slimgb43(1), hilb70(2)
922timer-tt;
923
924//===========================================================================
925//        Zufaellige Beispiele, homogen
926system("random",37);
927ring R = 0,x(1..6),lp;
928ideal I = sparseid(4,3);
929
930int tt = timer;
931ideal eI = elim(I,1);                //108(85)sec (slimgb 29(23), hilb79(61)
932timer-tt; tt = timer;
933ideal eI = elim(I,1,"std");          //(139)sec (std 77, hilb 61)
934timer-tt; tt = timer;
935ideal eI = elim1(I,1);               //(nach 45 min abgebrochen)
936timer-tt; tt = timer;
937ideal eI = eliminate(I,x(1));        //(nach 45 min abgebrochen)
938timer-tt; tt = timer;
939
940//        Zufaellige Beispiele, inhomogen
941system("random",37);
942ring R = 32003,x(1..5),dp;
943ideal I = sparseid(4,2,3);
944option(prot,redThrough);
945
946intvec w = 1,1,1,1,1,1;
947int tt = timer;
948ideal eI = elim(I,1,w);            //(nach 5min abgebr.) hilb schlaegt nicht zu
949timer-tt; tt = timer;              //BUG!!!!!!
950
951int tt = timer;
952ideal eI = elim(I,1);              //(nach 5min abgebr.) hilb schlaegt nicht zu
953timer-tt; tt = timer;              //BUG!!!!!!
954ideal eI = elim1(I,1);             //8(7.8)sec
955timer-tt; tt = timer;
956ideal eI = eliminate(I,x(1));      //8(7.8)sec
957timer-tt; tt = timer;
958
959                              BUG!!!!
960//        Zufaellige Beispiele, inhomogen, lokal
961system("random",37);
962ring R = 32003,x(1..6),ds;
963ideal I = sparseid(4,1,2);
964option(prot,redThrough);
965int tt = timer;
966ideal eI = elim(I,1);                //(haengt sich auf)
967timer-tt; tt = timer;
968ideal eI = elim1(I,1);               //(0)sec !!!!!!
969timer-tt; tt = timer;
970ideal eI = eliminate(I,x(1));        //(ewig mit ...., abgebrochen)
971timer-tt; tt = timer;
972
973ring R1 =(32003),(x(1),x(2),x(3),x(4),x(5),x(6)),(a(1,0,0,0,0,0),ds,C);
974ideal I = imap(R,I);
975I = std(I);                           //(haengt sich auf) !!!!!!!
976
977ideal eI = elim(I,1..1,"withWeights"); //(47)sec (weights42, slimgb1, hilb2)
978timer-tt;
979
980ring R1 =(32003),(x(1),x(2),x(3),x(4),x(5),x(6)),(a(1,0,0,0,0,0),ds,C);
981ideal I = imap(R,I);
982I = std(I);                           //(haengt sich auf) !!!!!!!
983
984ideal eI = elim(I,1..1,"withWeights"); //(47)sec (weights42, slimgb1, hilb2)
985timer-tt;
986*/
Note: See TracBrowser for help on using the repository browser.