source: git/Singular/LIB/elim.lib @ 6439db

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