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

spielwiese
Last change on this file since f1c6ce0 was f1c6ce0, checked in by Hans Schönemann <hannes@…>, 14 years ago
*hannes: better arg. check for elim git-svn-id: file:///usr/local/Singular/svn/trunk@11725 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 31.1 KB
Line 
1// $Id: elim.lib,v 1.32 2009-04-16 12:45:12 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.32 2009-04-16 12:45:12 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;              //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        @sc{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    else
482    {
483      if (typeof(#[2]) != "poly")
484      { ERROR("expected `elim(ideal,intvec[,string])`"); }
485    }
486    if (size(#) == 3)
487    {
488       if ( typeof(#[3]) == "string" )
489       {
490          if ( #[3] == "withWeights" )
491          {
492            intvec @w = weight(id);        //computation of weights
493          }
494          if ( #[3] == "std" ) { method = "std"; }
495          if ( #[3] == "slimgb" ) { method = "slimgb"; }
496       }
497    }
498  }
499
500//-------------- create new ring and map objects to new ring ------------------
501   if ( defined(@w) )
502   {
503      lER = elimRing(vars,@w);  //in this case lER[2] = @w
504   }
505   else
506   {
507      lER = elimRing(vars);
508      intvec @w = lER[2];      //in this case w is the intvec of
509                               //variable weights as computed in elimRing
510   }
511   def ER = lER[1];
512   setring ER;
513   def id = imap(BR,id);
514   poly vars = imap(BR,vars);
515
516//---------- now eliminate in new ring and map back to old ring ---------------
517  //if possible apply std(id,hi,w) where hi is the first hilbert function
518  //of id with respect to the weights w. If w is not defined (i.e. good weights
519  //@w are computed then id is only approximately @w-homogeneous and
520  //the hilbert driven std cannot be used directly; however, stdhilb
521  //homogenizes first and applies the hilbert driven std to the homogenization
522
523   option(redThrough);
524   if (typeof(id)=="matrix")
525   {
526     id = matrix(stdhilb(module(id),method,@w));
527   }
528   else
529   {
530     id = stdhilb(id,method,@w);
531   }
532
533   //### Todo: hier sollte id = groebner(id, "hilb"); verwendet werden.
534   //da z.Zt. (Jan 09) groebener bei extra Gewichtsvektor a(...) aber stets std
535   //aufruft und ausserdem "withWeigts" nicht kennt, ist groebner(id, "hilb")
536   //zunaechst nicht aktiviert. Ev. nach Ueberarbeitung von groebner aktivieren
537
538   id = nselect(id,1..ne);
539   if ( pr > 0 )
540   {
541     "// result is a SB in the following ring:";
542      ER;
543   }
544   setring BR;
545   return(imap(ER,id));
546}
547example
548{ "EXAMPLE:"; echo = 2;
549   ring r=0,(x,y,u,v,w),dp;
550   ideal i=x-u,y-u2,w-u3,v-x+y3;
551   elim(i,3..4);
552   elim(i,uv);
553   int p = printlevel;
554   printlevel = 2;
555   elim(i,uv,"withWeights","slimgb");
556   printlevel = p;
557
558   ring S =  (0,a),(x,y,z,u,v),ws(1,2,3,4,5);
559   minpoly = a2+1;
560   qring T = std(ideal(ax+y2+v3,(x+v)^2));
561   ideal i=x-u,y-u2,az-u3,v-x+ay3;
562   module m=i*gen(1)+i*gen(2);
563   m=elim(m,xy);
564   show(m);
565}
566///////////////////////////////////////////////////////////////////////////////
567
568proc elim2 (id, intvec va)
569"USAGE:   elim2(id,v);  id ideal/module, v intvec
570RETURNS: ideal/module obtained from id by eliminating variables in v
571NOTE:    no special monomial ordering is required, result is a SB with
572         respect to ordering dp (resp. ls) if the first var not to be
573         eliminated belongs to a -p (resp. -s) blockordering
574         This proc uses 'execute' or calls a procedure using 'execute'.
575SEE ALSO: elim1, eliminate, elim
576EXAMPLE: example elim2; shows examples
577"
578{
579//---- get variables to be eliminated and create string for new ordering ------
580   int ii; poly vars=1;
581   for( ii=1; ii<=size(va); ii++ ) { vars=vars*var(va[ii]); }
582   if(  attrib(basering,"global")) { string ordering = "),dp;"; }
583   else { string ordering = "),ls;"; }
584   string mpoly=string(minpoly);
585//-------------- create new ring and map objects to new ring ------------------
586   def br = basering;
587   string str = "ring @newr = ("+charstr(br)+"),("+varstr(br)+ordering;
588   execute(str);
589   if (mpoly!="0") { execute("minpoly="+mpoly+";"); }
590   def i = imap(br,id);
591   poly vars = imap(br,vars);
592//---------- now eliminate in new ring and map back to old ring ---------------
593   i = eliminate(i,vars);
594   setring br;
595   return(imap(@newr,i));
596}
597example
598{ "EXAMPLE:"; echo = 2;
599   ring r=0,(x,y,u,v,w),dp;
600   ideal i=x-u,y-u2,w-u3,v-x+y3;
601   elim2(i,3..4);
602   module m=i*gen(1)+i*gen(2);
603   m=elim2(m,3..4);show(m);
604}
605
606///////////////////////////////////////////////////////////////////////////////
607proc elim1 (id, list #)
608"USAGE:   elim1(id,arg); id ideal/module, arg can be either an intvec v or a
609         product p of variables (type poly)
610RETURN: ideal/module obtained from id by eliminating either the variables
611        with indices appearing in v or the variables appearing in p
612METHOD:  elim1 calls eliminate but in a ring with ordering dp (resp. ls)
613         if the first var not to be eliminated belongs to a -p (resp. -s)
614         ordering.
615NOTE:    no special monomial ordering is required.
616         This proc uses 'execute' or calls a procedure using 'execute'.
617SEE ALSO: elim, eliminate
618EXAMPLE: example elim1; shows examples
619"
620{
621   def br = basering;
622   if ( size(ideal(br)) != 0 )
623   {
624      ERROR ("elim1 cannot eliminate in a qring");
625   }
626//------------- create product vars of variables to be eliminated -------------
627  poly vars;
628  int ii;
629  if (size(#) > 0)
630  {
631    if ( typeof(#[1]) == "poly" ) {  vars = #[1]; }
632    if ( typeof(#[1]) == "intvec" or typeof(#[1]) == "int")
633    {
634      vars=1;
635      for( ii=1; ii<=size(#[1]); ii++ )
636      {
637        vars=vars*var(#[1][ii]);
638      }
639    }
640  }
641//---- get variables to be eliminated and create string for new ordering ------
642   for( ii=1; ii<=nvars(basering); ii++ )
643   {
644      if( vars/var(ii)==0 ) { poly p = 1+var(ii); break;}
645   }
646   if( ord(p)==0 ) { string ordering = "),ls;"; }
647   if( ord(p)>0 ) { string ordering = "),dp;"; }
648//-------------- create new ring and map objects to new ring ------------------
649   string str = "ring @newr = ("+charstr(br)+"),("+varstr(br)+ordering;
650   execute(str);
651   def id = fetch(br,id);
652   poly vars = fetch(br,vars);
653//---------- now eliminate in new ring and map back to old ring ---------------
654   id = eliminate(id,vars);
655   setring br;
656   return(imap(@newr,id));
657}
658example
659{ "EXAMPLE:"; echo = 2;
660   ring r=0,(x,y,t,s,z),dp;
661   ideal i=x-t,y-t2,z-t3,s-x+y3;
662   elim1(i,ts);
663   module m=i*gen(1)+i*gen(2);
664   m=elim1(m,3..4); show(m);
665}
666///////////////////////////////////////////////////////////////////////////////
667
668proc nselect (id, intvec v)
669"USAGE:   nselect(id,v); id = ideal, module or matrix, v = intvec
670RETURN:  generators (or columns) of id not containing the variables with index
671         an entry of v
672SEE ALSO: select, select1
673EXAMPLE: example nselect; shows examples
674"
675{
676   if (typeof(id) != "ideal")
677   {
678      if (typeof(id)=="module" || typeof(id)=="matrix")
679      {
680        module id1 = module(id);
681      }
682      else
683      {
684        ERROR("// *** input must be of type ideal or module or matrix");
685      }
686   }
687   else
688   {
689      ideal id1 = id;
690   }
691   int j,k;
692   int n,m = size(v), ncols(id1);
693   for( k=1; k<=m; k++ )
694   {
695      for( j=1; j<=n; j++ )
696      {
697        if( size(id1[k]/var(v[j]))!=0 )
698        {
699           id1[k]=0; break;
700        }
701      }
702   }
703   if(typeof(id)=="matrix")
704   {
705      return(matrix(simplify(id1,2)));
706   }
707   return(simplify(id1,2));
708}
709example
710{ "EXAMPLE:"; echo = 2;
711   ring r=0,(x,y,t,s,z),(c,dp);
712   ideal i=x-y,y-z2,z-t3,s-x+y3;
713   nselect(i,3);
714   module m=i*(gen(1)+gen(2));
715   m;
716   nselect(m,3..4);
717   nselect(matrix(m),3..4);
718}
719///////////////////////////////////////////////////////////////////////////////
720
721proc sat (id, ideal j)
722"USAGE:   sat(id,j);  id=ideal/module, j=ideal
723RETURN:  list of an ideal/module [1] and an integer [2]:
724         [1] = saturation of id with respect to j (= union_(k=1...) of id:j^k)
725         [2] = saturation exponent (= min( k | id:j^k = id:j^(k+1) ))
726NOTE:    [1] is a standard basis in the basering
727DISPLAY: saturation exponent during computation if printlevel >=1
728EXAMPLE: example sat; shows an example
729"{
730   int ii,kk;
731   def i=id;
732   id=std(id);
733   int p = printlevel-voice+3;  // p=printlevel+1 (default: p=1)
734   while( ii<=size(i) )
735   {
736      dbprint(p-1,"// compute quotient "+string(kk+1));
737      i=quotient(id,j);
738      for( ii=1; ii<=size(i); ii++ )
739      {
740         if( reduce(i[ii],id,1)!=0 ) break;
741      }
742      id=std(i); kk++;
743   }
744   dbprint(p-1,"// saturation becomes stable after "+string(kk-1)+" iteration(s)","");
745   list L = id,kk-1;
746   return (L);
747}
748example
749{ "EXAMPLE:"; echo = 2;
750   int p      = printlevel;
751   ring r     = 2,(x,y,z),dp;
752   poly F     = x5+y5+(x-y)^2*xyz;
753   ideal j    = jacob(F);
754   sat(j,maxideal(1));
755   printlevel = 2;
756   sat(j,maxideal(2));
757   printlevel = p;
758}
759///////////////////////////////////////////////////////////////////////////////
760
761proc select (id, intvec v)
762"USAGE:   select(id,n[,m]); id = ideal/module/matrix, v = intvec
763RETURN:  generators/columns of id containing all variables with index
764         an entry of v
765NOTE:    use 'select1' for selecting generators/columns containing at least
766         one of the variables with index an entry of v
767SEE ALSO: select1, nselect
768EXAMPLE: example select; shows examples
769"
770{
771   if (typeof(id) != "ideal")
772   {
773      if (typeof(id)=="module" || typeof(id)=="matrix")
774      {
775        module id1 = module(id);
776      }
777      else
778      {
779        ERROR("// *** input must be of type ideal or module or matrix");
780      }
781   }
782   else
783   {
784      ideal id1 = id;
785   }
786   int j,k;
787   int n,m = size(v), ncols(id1);
788   for( k=1; k<=m; k++ )
789   {
790      for( j=1; j<=n; j++ )
791      {
792         if( size(id1[k]/var(v[j]))==0)
793         {
794            id1[k]=0; break;
795         }
796      }
797   }
798   if(typeof(id)=="matrix")
799   {
800      return(matrix(simplify(id1,2)));
801   }
802   return(simplify(id1,2));
803}
804example
805{ "EXAMPLE:"; echo = 2;
806   ring r=0,(x,y,t,s,z),(c,dp);
807   ideal i=x-y,y-z2,z-t3,s-x+y3;
808   ideal j=select(i,1);
809   j;
810   module m=i*(gen(1)+gen(2));
811   m;
812   select(m,1..2);
813   select(matrix(m),1..2);
814}
815///////////////////////////////////////////////////////////////////////////////
816
817proc select1 (id, intvec v)
818"USAGE:   select1(id,v); id = ideal/module/matrix, v = intvec
819RETURN:  generators/columns of id containing at least one of the variables
820         with index an entry of v
821NOTE:    use 'select' for selecting generators/columns containing all variables
822         with index an entry of v
823SEE ALSO: select, nselect
824EXAMPLE: example select1; shows examples
825"
826{
827   if (typeof(id) != "ideal")
828   {
829      if (typeof(id)=="module" || typeof(id)=="matrix")
830      {
831        module id1 = module(id);
832        module I;
833      }
834      else
835      {
836        ERROR("// *** input must be of type ideal or module or matrix");
837      }
838   }
839   else
840   {
841      ideal id1 = id;
842      ideal I;
843   }
844   int j,k;
845   int n,m = size(v), ncols(id1);
846   for( k=1; k<=m; k++ )
847   {  for( j=1; j<=n; j++ )
848      {
849         if( size(subst(id1[k],var(v[j]),0)) != size(id1[k]) )
850         {
851            I = I,id1[k]; break;
852         }
853      }
854   }
855   if(typeof(id)=="matrix")
856   {
857      return(matrix(simplify(I,2)));
858   }
859   return(simplify(I,2));
860}
861example
862{ "EXAMPLE:"; echo = 2;
863   ring r=0,(x,y,t,s,z),(c,dp);
864   ideal i=x-y,y-z2,z-t3,s-x+y3;
865   ideal j=select1(i,1);j;
866   module m=i*(gen(1)+gen(2)); m;
867   select1(m,1..2);
868   select1(matrix(m),1..2);
869}
870/*
871///////////////////////////////////////////////////////////////////////////////
872//                      EXAMPLEs
873///////////////////////////////////////////////////////////////////////////////
874// Siehe auch file 'tst-elim' mit grossem Beispiel;
875example blowup0;
876example elimRing;
877example elim;
878example elim1;
879example nselect;
880example sat;
881example select;
882example select1;
883//===========================================================================
884//         Rationale Normalkurve vom Grad d im P^d bzw. im A^d:
885//homogen s:t -> (t^d:t^(d-1)s: ...: s^d), inhomogen t ->(t^d:t^(d-1): ...:t)
886
887//------------------- 1. Homogen:
888//Varianten der Methode
889int d = 5;
890ring R = 0,(s,t,x(0..d)),dp;
891ideal I;
892for( int ii=0; ii<=d; ii++) {I = I,ideal(x(ii)-t^(d-ii)*s^ii); }
893
894int tt = timer;
895ideal eI = elim(I,1..2,"std");
896ideal eI = elim(I,1..2,"slimgb");
897ideal eI = elim(I,st,"withWeights");
898ideal eI = elim(I,st,"std","withWeights");
899//komplizierter
900int d = 50;
901ring R = 0,(s,t,x(0..d)),dp;
902ideal I;
903for( int ii=0; ii<=d; ii++) {I = I,ideal(x(ii)-t^(d-ii)*s^ii); }
904int tt = timer;
905ideal eI = elim(I,1..2);               //56(44)sec (slimgb 22(17),hilb 33(26))
906timer-tt; tt = timer;
907ideal eI = elim1(I,1..2);              //71(53)sec
908timer-tt; tt = timer;
909ideal eI = eliminate(I,st);            //70(51)sec (wie elim1)
910timer-tt;
911timer-tt; tt = timer;
912ideal eI = elim(I,1..2,"withWeights"); //190(138)sec
913                                //(weights73(49), slimgb43(33), hilb71(53)
914timer-tt;
915//------------------- 2. Inhomogen
916int d = 50;
917ring r = 0,(t,x(0..d)),dp;
918ideal I;
919for( int ii=0; ii<=d; ii++) {I = I+ideal(x(ii)-t^(d-ii)); }
920int tt = timer;
921ideal eI = elim(I,1,);                //20(15)sec (slimgb13(10), hilb6(5))
922ideal eI = elim(I,1,"std");           //17sec (std 11, hilb 6)
923timer-tt; tt = timer;
924ideal eI = elim1(I,t);               //8(6)sec
925timer-tt; tt = timer;
926ideal eI = eliminate(I,t);           //7(6)sec
927timer-tt;
928timer-tt; tt = timer;
929ideal eI = elim(I,1..1,"withWeights"); //189(47)sec
930//(weights73(42), slimgb43(1), hilb70(2)
931timer-tt;
932
933//===========================================================================
934//        Zufaellige Beispiele, homogen
935system("random",37);
936ring R = 0,x(1..6),lp;
937ideal I = sparseid(4,3);
938
939int tt = timer;
940ideal eI = elim(I,1);                //108(85)sec (slimgb 29(23), hilb79(61)
941timer-tt; tt = timer;
942ideal eI = elim(I,1,"std");          //(139)sec (std 77, hilb 61)
943timer-tt; tt = timer;
944ideal eI = elim1(I,1);               //(nach 45 min abgebrochen)
945timer-tt; tt = timer;
946ideal eI = eliminate(I,x(1));        //(nach 45 min abgebrochen)
947timer-tt; tt = timer;
948
949//        Zufaellige Beispiele, inhomogen
950system("random",37);
951ring R = 32003,x(1..5),dp;
952ideal I = sparseid(4,2,3);
953option(prot,redThrough);
954
955intvec w = 1,1,1,1,1,1;
956int tt = timer;
957ideal eI = elim(I,1,w);            //(nach 5min abgebr.) hilb schlaegt nicht zu
958timer-tt; tt = timer;              //BUG!!!!!!
959
960int tt = timer;
961ideal eI = elim(I,1);              //(nach 5min abgebr.) hilb schlaegt nicht zu
962timer-tt; tt = timer;              //BUG!!!!!!
963ideal eI = elim1(I,1);             //8(7.8)sec
964timer-tt; tt = timer;
965ideal eI = eliminate(I,x(1));      //8(7.8)sec
966timer-tt; tt = timer;
967
968                              BUG!!!!
969//        Zufaellige Beispiele, inhomogen, lokal
970system("random",37);
971ring R = 32003,x(1..6),ds;
972ideal I = sparseid(4,1,2);
973option(prot,redThrough);
974int tt = timer;
975ideal eI = elim(I,1);                //(haengt sich auf)
976timer-tt; tt = timer;
977ideal eI = elim1(I,1);               //(0)sec !!!!!!
978timer-tt; tt = timer;
979ideal eI = eliminate(I,x(1));        //(ewig mit ...., abgebrochen)
980timer-tt; tt = timer;
981
982ring R1 =(32003),(x(1),x(2),x(3),x(4),x(5),x(6)),(a(1,0,0,0,0,0),ds,C);
983ideal I = imap(R,I);
984I = std(I);                           //(haengt sich auf) !!!!!!!
985
986ideal eI = elim(I,1..1,"withWeights"); //(47)sec (weights42, slimgb1, hilb2)
987timer-tt;
988
989ring R1 =(32003),(x(1),x(2),x(3),x(4),x(5),x(6)),(a(1,0,0,0,0,0),ds,C);
990ideal I = imap(R,I);
991I = std(I);                           //(haengt sich auf) !!!!!!!
992
993ideal eI = elim(I,1..1,"withWeights"); //(47)sec (weights42, slimgb1, hilb2)
994timer-tt;
995*/
Note: See TracBrowser for help on using the repository browser.