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

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