source: git/Singular/LIB/standard.lib @ d14b7c

spielwiese
Last change on this file since d14b7c was d14b7c, checked in by Hans Schönemann <hannes@…>, 25 years ago
*hannes: changed descriptions of stdfglm/stdhilb git-svn-id: file:///usr/local/Singular/svn/trunk@3599 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 25.8 KB
Line 
1// $Id: standard.lib,v 1.44 1999-09-11 13:22:06 Singular Exp $
2//////////////////////////////////////////////////////////////////////////////
3
4version="$Id: standard.lib,v 1.44 1999-09-11 13:22:06 Singular Exp $";
5info="
6LIBRARY: standard.lib   PROCEDURES WHICH ARE ALWAYS LOADED AT START-UP
7
8PROCEDURES:
9 stdfglm(ideal[,ord])   standard basis of ideal via fglm [and ordering ord]
10 stdhilb(ideal[,h])     standard basis of ideal using the Hilbert function
11 groebner(ideal/module) standard basis using a heuristically chosen method
12 quot(any,any[,n])      quotient using heuristically chosen method
13 res(ideal/module,[i])  free resolution of ideal or module
14 sprintf(fmt,...)     returns fomatted string
15 fprintf(link,fmt,..) writes formatted string to link
16 printf(fmt,...)      displays formatted string
17";
18
19//////////////////////////////////////////////////////////////////////////////
20
21proc stdfglm (ideal i, list #)
22"SYNTAX:  stdfglm(ideal_expression);
23         stdfglm(ideal_expression, string_expression);
24TYPE:    ideal
25PURPOSE: computes the standardbasis of the ideal in the basering,
26         calculated via fglm from ordering given as the second argumnent
27         to the ordering of the basering.
28         If no second argumnt is given, \"dp\" is used.
29SEE ALSO: stdhilb, std, groebner
30KEYWORDS: fglm
31EXAMPLE: example stdfglm; shows an example"
32{
33   string os;
34   def dr= basering;
35   if( (size(#)==0) or (typeof(#[1]) != "string") )
36   {
37     os = "dp(" + string( nvars(dr) ) + ")";
38     if ( (find( ordstr(dr), os ) != 0) and (find( ordstr(dr), "a") == 0) )
39     {
40       os= "Dp";
41     }
42     else
43     {
44       os= "dp";
45     }
46   }
47   else { os = #[1]; }
48   execute "ring sr=("+charstr(dr)+"),("+varstr(dr)+"),"+os+";";
49   ideal i= fetch(dr,i);
50   intvec opt= option(get);
51   option(redSB);
52   i=std(i);
53   option(set,opt);
54   setring dr;
55   return (fglm(sr,i));
56}
57example
58{ "EXAMPLE:"; echo = 2;
59   ring r  = 0,(x,y,z),lp;
60   ideal i = y3+x2, x2y+x2, x3-x2, z4-x2-y;
61   ideal i1= stdfglm(i);         //uses fglm from "dp" to "lp"
62   i1;
63   ideal i2= stdfglm(i,"Dp");    //uses fglm from "Dp" to "lp"
64   i2;
65}
66/////////////////////////////////////////////////////////////////////////////
67
68proc stdhilb(ideal i,list #)
69"SYNTAX:  stdhilb(ideal_expression);
70         stdhilb(ideal_expression, intvec_expression);
71TYPE:    ideal
72PURPOSE: computes the standardbasis of the homogeneous ideal in the basering,
73         calculated via a Hilbert driven standard basis computation.
74         An optional second argument will be used as the Hilbert function.
75SEE ALSO: stdfglm, std, groebner
76KEYWORDS: Hilbert function
77EXAMPLE: example stdhilb;  shows an example"
78{
79   def R=basering;
80
81   if((homog(i)==1)||(ordstr(basering)[1]=="d"))
82   {
83      if ((size(#)!=0)&&(homog(i)==1))
84      {
85         return(std(i,#[1]));
86      }
87      return(std(i));
88   }
89
90   execute "ring S = ("+charstr(R)+"),("+varstr(R)+",@t),dp;";
91   ideal i=homog(imap(R,i),@t);
92   intvec v=hilb(std(i),1);
93   execute "ring T = ("+charstr(R)+"),("+varstr(R)+",@t),("+ordstr(R)+");";
94   ideal i=fetch(S,i);
95   ideal a=std(i,v);
96   setring R;
97   map phi=T,maxideal(1),1;
98   ideal a=phi(a);
99
100   int k,j;
101   poly m;
102   int c=size(i);
103
104   for(j=1;j<c;j++)
105   {
106     if(deg(a[j])==0)
107     {
108       a=ideal(1);
109       attrib(a,"isSB",1);
110       return(a);
111     }
112     if(deg(a[j])>0)
113     {
114       m=lead(a[j]);
115       for(k=j+1;k<=c;k++)
116       {
117          if(size(lead(a[k])/m)>0)
118          {
119            a[k]=0;
120          }
121       }
122     }
123   }
124   a=simplify(a,2);
125   attrib(a,"isSB",1);
126   return(a);
127}
128example
129{ "EXAMPLE:"; echo = 2;
130   ring  r = 0,(x,y,z),lp;
131   ideal i = y3+x2, x2y+x2, x3-x2, z4-x2-y;
132   ideal i1= stdhilb(i); i1;
133   // is in this case equivalent to:
134   intvec v=1,0,0,-3,0,1,0,3,-1,-1;
135   ideal i2=stdhilb(i,v);
136}
137//////////////////////////////////////////////////////////////////////////
138
139proc groebner(def i, list #)
140"USAGE: groebner(i[, wait]) i -- ideal/module; wait -- int
141RETURNS: Standard basis of ideal or module which is computed using a
142         heuristically chosen method:
143         If the ordering of the current ring is a local ordering, or
144         if it is a non-block ordering and the current ring has no
145         parameters, then std(i) is returned.
146         Otherwise, i is mapped into a ring with no parameters and
147         ordering dp, where its Hilbert series is computed. This is
148         followed by a Hilbert-series based std computation in the
149         original ring.
150NOTE: If a 2nd argument 'wait' is given, then the computation proceeds
151      at most 'wait' seconds. That is, if no result could be computed in
152      'wait' seconds, then the computation is interrupted, 0 is returned,
153      a warning message is displayed, and the global variable
154      'groebner_error' is defined.
155SEE ALSO: stdhilb, stdfglm, std
156KEYWORDS: time limit on computations; MP, groebner basis computations
157EXAMPLE: example groebner;  shows an example"
158{
159  def P=basering;
160
161  // we have two arguments -- try to use MPfork links
162  if (size(#) > 0)
163  {
164    if (system("with", "MP"))
165    {
166      if (typeof(#[1]) == "int")
167      {
168        int wait = #[1];
169        int j = 10;
170
171        string bs = nameof(basering);
172        link l_fork = "MPtcp:fork";
173        open(l_fork);
174        write(l_fork, quote(system("pid")));
175        int pid = read(l_fork);
176        write(l_fork, quote(groebner(eval(i))));
177
178        // sleep in small intervalls for appr. one second
179        if (wait > 0)
180        {
181          while(j < 1000000)
182          {
183            if (status(l_fork, "read", "ready", j)) {break;}
184            j = j + j;
185          }
186        }
187
188        // sleep in intervalls of one second from now on
189        j = 1;
190        while (j < wait)
191        {
192          if (status(l_fork, "read", "ready", 1000000)) {break;}
193          j = j + 1;
194        }
195
196        if (status(l_fork, "read", "ready"))
197        {
198          def result = read(l_fork);
199          if (bs != nameof(basering))
200          {
201            def PP = basering;
202            setring P;
203            def result = imap(PP, result);
204            kill PP;
205          }
206          if (defined(groebner_error))
207          {
208            kill(groebner_error);
209          }
210          kill (l_fork);
211        }
212        else
213        {
214          ideal result;
215          if (! defined(groebner_error))
216          {
217            int groebner_error = 1;
218            export groebner_error;
219          }
220          "// ** groebner did not finish";
221          j = system("sh", "kill " + string(pid));
222        }
223        return (result);
224      }
225      else
226      {
227        "// ** groebner needs int as 2nd arg";
228      }
229    }
230    else
231    {
232      "// ** groebner with two args is not supported in this configuration";
233    }
234  }
235
236  // we are still here -- do the actual computation
237  string ordstr_P = ordstr(P);
238  if (find(ordstr_P,"s") > 0)
239  {
240    //spaeter den lokalen fall ueber lp oder aehnlich behandeln
241    return(std(i));
242  }
243
244  int IsSimple_P;
245  if (system("nblocks") <= 2)
246  {
247    if (find(ordstr_P, "M") <= 0)
248    {
249      IsSimple_P = 1;
250    }
251  }
252  int npars_P = npars(P);
253
254  // return std if no parameters and (dp or wp)
255  if ((npars_P <= 1) && IsSimple_P)
256  {
257    if (find(ordstr_P, "d") > 0)
258    {
259      return (std(i));
260    }
261    if (find(ordstr_P,"w") > 0)
262    {
263      return (std(i));
264    }
265  }
266
267  // reset options
268  intvec opt=option(get);
269  int p_opt;
270  string s_opt = option();
271  option(none);
272  // turn on option(prot) and/or option(mem), if previously set
273  if (find(s_opt, "prot"))
274  {
275    option(prot);
276    p_opt = 1;
277  }
278  if (find(s_opt, "mem"))
279  {
280    option(mem);
281  }
282
283  // construct ring in which first std computation is done
284  string varstr_P = varstr(P);
285  string parstr_P = parstr(P);
286  int is_homog = (homog(i) && (npars_P <= 1));
287  int add_vars = 0;
288  string ri = "ring Phelp =";
289
290  // more than one parameters are converted to ring variables
291  if (npars_P > 1)
292  {
293    ri = ri + string(char(P)) + ",(" + varstr_P + "," + parstr_P;
294    add_vars = npars_P;
295  }
296  else
297  {
298    ri = ri + "(" + charstr(P) + "),(" + varstr_P;
299  }
300
301  // a homogenizing variable is added, if necessary
302  if (! is_homog)
303  {
304    ri = ri + ",@t";
305    add_vars = add_vars + 1;
306  }
307  // ordering is set to (dp, C)
308  ri = ri + "),(dp,C);";
309
310  // change the ring
311  execute(ri);
312
313  // get ideal from previous ring
314  if (is_homog)
315  {
316    ideal qh = imap(P, i);
317  }
318  else
319  {
320    // and homogenize
321    ideal qh=homog(imap(P,i),@t);
322  }
323
324  // compute std and hilbert series
325  if (p_opt)
326  {
327    "std in " + ri[13, size(ri) - 13];
328  }
329  ideal qh1=std(qh);
330  intvec hi=hilb(qh1,1);
331
332  if (add_vars == 0)
333  {
334    // no additional variables were introduced
335    setring P; // can immediately change to original ring
336    // simply compute std with hilbert series in original ring
337    if (p_opt)
338    {
339      "std with hilb in basering";
340    }
341    i = std(i, hi);
342  }
343  else
344  {
345    // additional variables were introduced
346    // need another intermediate ring
347    ri = "ring Phelp1 = (" + charstr(Phelp)
348      + "),(" + varstr(Phelp) + "),(" + ordstr_P;
349
350    // for lp wit at most one parameter, we do not need a block ordering
351    if ( ! (IsSimple_P && (add_vars <2) && find(ordstr_P, "l")))
352    {
353      // need block ordering
354      ri = ri + ", dp(" + string(add_vars) + ")";
355    }
356    ri = ri + ");";
357
358    // change to intermediate ring
359    execute(ri);
360    ideal qh = imap(Phelp, qh);
361    kill Phelp;
362    if (p_opt)
363    {
364      "std with hilb in " + ri[14,size(ri)-14];
365    }
366    // compute std with Hilbert series
367    qh = std(qh, hi);
368    // subst 1 for homogenizing var
369    if (!is_homog)
370    {
371      if (p_opt)
372      {
373        "dehomogenization";
374      }
375      qh = subst(qh, @t, 1);
376    }
377
378    // go back to original ring
379    setring P;
380    // get ideal, delete zeros and clean SB
381    if (p_opt)
382    {
383      "imap to original ring";
384    }
385    i = imap(Phelp1,qh);
386    if (p_opt)
387    {
388      "simplification";
389    }
390    i = simplify(i, 34);
391    kill Phelp1;
392  }
393
394  // clean-up time
395  option(set, opt);
396  if (find(s_opt, "redSB") > 0)
397  {
398    if (p_opt)
399    {
400      "interreduction";
401    }
402    i=interred(i);
403  }
404  attrib(i, "isSB", 1);
405  return (i);
406}
407example
408{ "EXAMPLE: "; echo = 2;
409  ring r = 0, (a,b,c,d), lp;
410  option(prot);
411  ideal i = a+b+c+d, ab+ad+bc+cd, abc+abd+acd+bcd, abcd-1; // cyclic 4
412  groebner(i);
413  ring rp = (0, a, b), (c,d), lp;
414  ideal i = imap(r, i);
415  ideal j = groebner(i);
416  option(noprot);
417  j; simplify(j, 1); std(i);
418  if (system("with", "MP")) {groebner(i, 0);}
419  defined(groebner_error);
420}
421
422
423//////////////////////////////////////////////////////////////////////////
424proc res(list #)
425"@c we do texinfo here:
426@cindex resolution, computation of
427@table @code
428@item @strong{Syntax:}
429@code{res (} ideal_expression@code{,} int_expression @code{[,} any_expression @code{])}
430@*@code{res (} module_expression@code{,} int_expression @code{[,} any_expression @code{])}
431@item @strong{Type:}
432resolution
433@item @strong{Purpose:}
434computes a (possibly minimal) free resolution of an ideal or module using
435a heuristically choosen method.
436@* The second (int) argument (say, @code{k}) specifies the length of
437the resolution. If @code{k <=0 } then k is assumed to be the number of
438variables of the basering.
439@* If a third argument is given, the returned resolution is minimized.
440
441Depending on the input, the returned resolution is computed using the
442following methods:
443@table @asis
444@item @strong{quotient rings:}
445@code{nres} (classical method using syzygies) , see @ref{nres}.
446
447@item @strong{homogenous ideals and k == 0:}
448@code{lres} (La'Scala's method), see @ref{lres}.
449
450@item @strong{not minimized resolution,  and, homogenous input with k != 0 or local rings:}
451@code{sres} (Schreyer's method), see @ref{sres}.
452
453@item @strong{all other inputs:}
454@code{mres} (classical method), see @ref{mres}.
455@end table
456@item @strong{Note:}
457Accessing single elements of a resolution may require that some partial computations have to be finished and may therefor take some time.
458@end table
459@c ref
460See also
461@ref{betti};
462@ref{ideal};
463@ref{minres};
464@ref{module};
465@ref{mres};
466@ref{nres};
467@ref{lres};
468@ref{sres}.
469@ref{resolution}
470@c ref
471"
472{
473   def P=basering;
474   if (size(#) < 2)
475   {
476     ERROR("res: need at least two arguments: ideal/module, int");
477   }
478
479   def m=#[1]; //the ideal or module
480   int i=#[2]; //the length of the resolution
481   if (i< 0) { i=0;}
482
483   string varstr_P = varstr(P);
484
485   int p_opt;
486   string s_opt = option();
487   // set p_opt, if option(prot) is set
488   if (find(s_opt, "prot"))
489   {
490     p_opt = 1;
491   }
492
493   if(size(ideal(basering)) > 0)
494   {
495     // the quick hack for qrings - seems to fit most needs
496     // (lres is not implemented for qrings, sres is not so efficient)
497     if (p_opt) { "using nres";}
498     return(nres(m,i));
499   }
500
501   if(homog(m)==1)
502   {
503      resolution re;
504      if (((i==0) or (i>=nvars(basering))) && typeof(m) != "module")
505      {
506        //LaScala for the homogeneous case and i == 0
507        if (p_opt) { "using lres";}
508        re=lres(m,i);
509        if(size(#)>2)
510        {
511           re=minres(re);
512        }
513      }
514      else
515      {
516        if(size(#)>2)
517        {
518          if (p_opt) { "using mres";}
519          re=mres(m,i);
520        }
521        else
522        {
523          if (p_opt) { "using sres";}
524          re=sres(std(m),i);
525        }
526      }
527      return(re);
528   }
529
530   //mres for the global non homogeneous case
531   if(find(ordstr(P),"s")==0)
532   {
533      string ri= "ring Phelp ="
534                  +string(char(P))+",("+varstr_P+"),(dp,C);";
535      execute(ri);
536      def m=imap(P,m);
537      if (p_opt) { "using mres in another ring";}
538      list re=mres(m,i);
539      setring P;
540      resolution result=imap(Phelp,re);
541      if (size(#) > 2) {result = minres(result);}
542      return(result);
543   }
544
545   //sres for the local case and not minimal resolution
546   if(size(#)<=2)
547   {
548      string ri= "ring Phelp ="
549                  +string(char(P))+",("+varstr_P+"),(ls,c);";
550      execute(ri);
551      def m=imap(P,m);
552      m=std(m);
553      if (p_opt) { "using sres in another ring";}
554      list re=sres(m,i);
555      setring P;
556      resolution result=imap(Phelp,re);
557      return(result);
558   }
559
560   //mres for the local case and minimal resolution
561   string ri= "ring Phelp ="
562                  +string(char(P))+",("+varstr_P+"),(ls,C);";
563   execute(ri);
564   def m=imap(P,m);
565    if (p_opt) { "using mres in another ring";}
566   list re=mres(m,i);
567   setring P;
568   resolution result=imap(Phelp,re);
569   result = minres(result);
570   return(result);
571}
572example
573{"EXAMPLE:"; echo = 2;
574  ring r=0,(x,y,z),dp;
575  ideal i=xz,yz,x^3-y^3;
576  def l=res(i,0); // homogenous ideal: uses lres
577  l;              // resolution is not yet minimized
578  print(betti(l), "betti"); // input to betti may be of type resolution
579  l[2];         // element access may take some time
580  i=i, x+1;
581  l=res(i,0);   // inhomogenous ideal: uses mres
582  l;            // resolution is not yet minimized
583  ring rs=0,(x,y,z),ds;
584  ideal i = imap(r, i);
585  def l=res(i,0); // local ring not minimized: uses sres
586  l;              // resolution is minimized
587  res(i,0,0);     // local ring and minimized: uses mres
588}
589
590
591proc quot (m1,m2,list #)
592"USAGE:   quot(m1, m2[, n]); m1, m2 two submodules of k^s,
593          n (optional) integer (1<= n <=5)
594RETURN:  the quotient of m1 and m2
595SEE ALSO: quotient
596EXAMPLE: example quot; shows an example"
597{
598  if (((typeof(m1)!="ideal") and (typeof(m1)!="module"))
599     or ((typeof(m2)!="ideal") and (typeof(m2)!="module")))
600  {
601    "USAGE:   quot(m1, m2[, n]); m1, m2 two submodules of k^s,";
602    "         n (optional) integer (1<= n <=5)";
603    "RETURN:  the quotient of m1 and m2";
604    "EXAMPLE: example quot; shows an example";
605    return();
606  }
607  if (typeof(m1)!=typeof(m2))
608  {
609    return(quotient(m1,m2));
610  }
611  if (size(#)>0)
612  {
613    if (typeof(#[1])=="int" )
614    {
615      return(quot1(m1,m2,#[1]));
616    }
617  }
618  else
619  {
620    return(quot1(m1,m2,2));
621  }
622}
623example
624{ "EXAMPLE:"; echo = 2;
625  ring r=181,(x,y,z),(c,ls);
626  ideal id1=maxideal(4);
627  ideal id2=x2+xyz,y2-z3y,z3+y5xz;
628  option(prot);
629  ideal id6=quotient(id1,id2);
630  id6;
631  ideal id7=quot(id1,id2,1);
632  id7;
633  ideal id8=quot(id1,id2,2);
634  id8;
635}
636
637static proc quot1 (module m1, module m2,int n)
638"USAGE:   quot1(m1, m2, n); m1, m2 two submodules of k^s,
639         n integer (1<= n <=5)
640RETURN:  the quotient of m1 and m2
641EXAMPLE: example quot1; shows an example"
642{
643  if (n==1)
644  {
645    return(quotient1(m1,m2));
646  }
647  else
648  {
649    if (n==2)
650    {
651      return(quotient2(m1,m2));
652    }
653    else
654    {
655      if (n==3)
656      {
657        return(quotient3(m1,m2));
658      }
659      else
660      {
661        if (n==4)
662        {
663          return(quotient4(m1,m2));
664        }
665        else
666        {
667          if (n==5)
668          {
669            return(quotient5(m1,m2));
670          }
671          else
672          {
673            return(quotient(m1,m2));
674          }
675        }
676      }
677    }
678  }
679}
680example
681{ "EXAMPLE:"; echo = 2;
682  ring r=181,(x,y,z),(c,ls);
683  ideal id1=maxideal(4);
684  ideal id2=x2+xyz,y2-z3y,z3+y5xz;
685  option(prot);
686  ideal id6=quotient(id1,id2);
687  id6;
688  ideal id7=quot1(id1,id2,1);
689  id7;
690  ideal id8=quot1(id1,id2,2);
691  id8;
692}
693
694static proc quotient0(module a,module b)
695{
696  module mm=b+a;
697  resolution rs=lres(mm,0);
698  list I=list(rs);
699  matrix M=I[2];
700  matrix A[1][nrows(M)]=M[1..nrows(M),1];
701  ideal i=A;
702  return (i);
703}
704proc quotient1(module a,module b)  //17sec
705"USAGE:   quotient1(m1, m2); m1, m2 two submodules of k^s,
706RETURN:  the quotient of m1 and m2"
707{
708  int i;
709  a=std(a);
710  module dummy;
711  module B=NF(b,a)+dummy;
712  ideal re=quotient(a,module(B[1]));
713  for(i=2;i<=size(B);i++)
714  {
715     re=intersect1(re,quotient(a,module(B[i])));
716  }
717  return(re);
718}
719proc quotient2(module a,module b)    //13sec
720"USAGE:   quotient2(m1, m2); m1, m2 two submodules of k^s,
721RETURN:  the quotient of m1 and m2"
722{
723  a=std(a);
724  module dummy;
725  module bb=NF(b,a)+dummy;
726  int i=size(bb);
727  ideal re=quotient(a,module(bb[i]));
728  bb[i]=0;
729  module temp;
730  module temp1;
731  module bbb;
732  int mx;
733  i=i-1;
734  while (1)
735  {
736    if (i==0) break;
737    temp = a+bb*re;
738    temp1 = lead(interred(temp));
739    mx=ncols(a);
740    if (ncols(temp1)>ncols(a))
741    {
742      mx=ncols(temp1);
743    }
744    temp1 = matrix(temp1,1,mx)-matrix(lead(a),1,mx);
745    temp1 = dummy+temp1;
746    if (deg(temp1[1])<0) break;
747    re=intersect1(re,quotient(a,module(bb[i])));
748    bb[i]=0;
749    i = i-1;
750  }
751  return(re);
752}
753proc quotient3(module a,module b)   //89sec
754"USAGE:   quotient3(m1, m2); m1, m2 two submodules of k^s,
755         only for global rings
756RETURN:  the quotient of m1 and m2"
757{
758  string s="ring @newr=("+charstr(basering)+
759           "),("+varstr(basering)+",@t,@w),dp;";
760  def @newP=basering;
761  execute s;
762  module b=imap(@newP,b);
763  module a=imap(@newP,a);
764  int i;
765  int j=size(b);
766  vector @b;
767  for(i=1;i<=j;i++)
768  {
769     @b=@b+@t^(i-1)*@w^(j-i+1)*b[i];
770  }
771  ideal re=quotient(a,module(@b));
772  setring @newP;
773  ideal re=imap(@newr,re);
774  return(re);
775}
776proc quotient5(module a,module b)   //89sec
777"USAGE:   quotient5(m1, m2); m1, m2 two submodules of k^s,
778         only for global rings
779RETURN:  the quotient of m1 and m2"
780{
781  string s="ring @newr=("+charstr(basering)+
782           "),("+varstr(basering)+",@t),dp;";
783  def @newP=basering;
784  execute s;
785  module b=imap(@newP,b);
786  module a=imap(@newP,a);
787  int i;
788  int j=size(b);
789  vector @b;
790  for(i=1;i<=j;i++)
791  {
792     @b=@b+@t^(i-1)*b[i];
793  }
794  @b=homog(@b,@w);
795  ideal re=quotient(a,module(@b));
796  setring @newP;
797  ideal re=imap(@newr,re);
798  return(re);
799}
800proc quotient4(module a,module b)   //95sec
801"USAGE:   quotient4(m1, m2); m1, m2 two submodules of k^s,
802         only for global rings
803RETURN:  the quotient of m1 and m2"
804{
805  string s="ring @newr=("+charstr(basering)+
806           "),("+varstr(basering)+",@t),dp;";
807  def @newP=basering;
808  execute s;
809  module b=imap(@newP,b);
810  module a=imap(@newP,a);
811  int i;
812  vector @b=b[1];
813  for(i=2;i<=size(b);i++)
814  {
815     @b=@b+@t^(i-1)*b[i];
816  }
817  matrix sy=modulo(@b,a);
818  ideal re=sy;
819  setring @newP;
820  ideal re=imap(@newr,re);
821  return(re);
822}
823static proc intersect1(ideal i,ideal j)
824{
825  def R=basering;
826  execute "ring gnir = ("+charstr(basering)+"),
827                       ("+varstr(basering)+",@t),(C,dp);";
828  ideal i=var(nvars(basering))*imap(R,i)+(var(nvars(basering))-1)*imap(R,j);
829  ideal j=eliminate(i,var(nvars(basering)));
830  setring R;
831  map phi=gnir,maxideal(1);
832  return(phi(j));
833}
834
835//////////////////////////////////////////////////////////////////
836///
837/// sprintf, fprintf printf
838///
839proc sprintf(string fmt, list #)
840"USAGE:    sprintf(fmt, ...) fmt string
841RETURN:   string
842PURPOSE:  sprintf performs output formatting. The first argument is a format
843          control string. Additional arguments may be required, depending on
844          the contents of the control string. A series of output characters is
845          generated as directed by the control string; these characters are
846          returned as a string. The control string is simply text to be copied,
847          except that the string may contain conversion specifications. Do
848          'help print:' for a listing of valid conversion specifications.
849          As an addition to the conversions of 'print', the '%n' and '%2'
850          conversion specification does not consume an additional argument,
851          but simply generates a newline character.
852NOTE:     If one of the additional arguments is a list, then it should be
853          enclosed once more into a list() command, since passing a list
854          as an argument flattens the list by one level.
855SEE ALSO: fprintf, printf, print, string
856EXAMPLE : example sprintf; shows an example
857"
858{
859  int sfmt = size(fmt);
860  if (sfmt  <= 1)
861  {
862    return (fmt);
863  }
864  int next, l, nnext;
865  string ret;
866  list formats = "%l", "%s", "%2l", "%2s", "%t", "%;", "%p", "%b", "%n", "%2";
867  while (1)
868  {
869    if (size(#) <= 0)
870    {
871      return (ret + fmt);
872    }
873    nnext = 0;
874    while (nnext < sfmt)
875    {
876      nnext = find(fmt, "%", nnext + 1);
877      if (nnext == 0)
878      {
879        next = 0;
880        break;
881      }
882      l = 1;
883      while (l <= size(formats))
884      {
885        next = find(fmt, formats[l], nnext);
886        if (next == nnext) break;
887        l++;
888      }
889      if (next == nnext) break;
890    }
891    if (next == 0)
892    {
893      return (ret + fmt);
894    }
895    if (formats[l] != "%2" && formats[l] != "%n")
896    {
897      ret = ret + fmt[1, next - 1] + print(#[1], formats[l]);
898      # = delete(#, 1);
899    }
900    else
901    {
902      ret = ret + fmt[1, next - 1] + print("", "%2s");
903    }
904    if (size(fmt) <= (next + size(formats[l]) - 1))
905    {
906      return (ret);
907    }
908    fmt = fmt[next + size(formats[l]), size(fmt)-next-size(formats[l]) + 1];
909  }
910}
911example
912{ "EXAMPLE:"; echo=2;
913  ring r=0,(x,y,z),dp;
914  module m=[1,y],[0,x+z];
915  intmat M=betti(mres(m,0));
916  list l = r, m, M;
917  string s = sprintf("s:%s,%n l:%l", 1, 2); s;
918  s = sprintf("s:%n%s", l); s;
919  s = sprintf("s:%2%s", list(l)); s;
920  s = sprintf("2l:%n%2l", list(l)); s;
921  s = sprintf("%p", list(l)); s;
922  s = sprintf("%;", list(l)); s;
923  s = sprintf("%b", M); s;
924}
925
926proc printf(string fmt, list #)
927"USAGE:    printf(fmt, ...) fmt string
928RETURN:   none
929PURPOSE:  printf performs output formatting. The first argument is a format
930          control string. Additional arguments may be required, depending on
931          the contents of the control string. A series of output characters is
932          generated as directed by the control string; these characters are
933          displayed (i.e. printed to standard out).
934          The control string is simply text to be copied, except that the
935          string may contain conversion specifications.
936          Do 'help print:' for a listing of valid conversion specifications.
937          As an addition to the conversions of 'print', the '%n' and '%2'
938          conversion specification does not consume an additional argument,
939          but simply generates a newline character.
940
941NOTE:     If one of the additional arguments is a list, then it should be
942          enclosed once more into a list() command, since passing a list
943          as an argument flattens the list by one level.
944SEE ALSO: sprintf, fprintf, print, string
945EXAMPLE : example printf; shows an example
946"
947{
948  write("", sprintf(fmt, #));
949}
950example
951{ "EXAMPLE:"; echo=2;
952  ring r=0,(x,y,z),dp;
953  module m=[1,y],[0,x+z];
954  intmat M=betti(mres(m,0));
955  list l = r, m, M;
956  printf("s:%s, l:%l", 1, 2);
957  printf("s:%s", l);
958  printf("s:%s", list(l));
959  printf("2l:%2l", list(l));
960  printf("%p", list(l));
961  printf("%;", list(l));
962  printf("%b", M);
963}
964
965
966proc fprintf(link l, string fmt, list #)
967"USAGE:    fprintf(l, fmt, ...) l link; fmt string
968RETURN:   none
969PURPOSE:  fprintf performs output formatting. The second argument is a format
970          control string. Additional arguments may be required, depending on
971          the contents of the control string. A series of output characters is
972          generated as directed by the control string; these characters are
973          written to the link l.
974          The control string is simply text to be copied, except that the
975          string may contain conversion specifications.
976          Do 'help print:' for a listing of valid conversion specifications.
977          As an addition to the conversions of 'print', the '%n' and '%2'
978          conversion specification does not consume an additional argument,
979          but simply generates a newline character.
980
981NOTE:     If one of the additional arguments is a list, then it should be
982          enclosed once more into a list() command, since passing a list
983          as an argument flattens the list by one level.
984SEE ALSO: sprintf, printf, print, string
985EXAMPLE : example fprintf; shows an example
986"
987{
988  write(l, sprintf(fmt, #));
989}
990example
991{ "EXAMPLE:"; echo=2;
992  ring r=0,(x,y,z),dp;
993  module m=[1,y],[0,x+z];
994  intmat M=betti(mres(m,0));
995  list l = r, m, M;
996  link li = ""; // link to stdout
997  fprintf(li, "s:%s, l:%l", 1, 2);
998  fprintf(li, "s:%s", l);
999  fprintf(li, "s:%s", list(l));
1000  fprintf(li, "2l:%2l", list(l));
1001  fprintf(li, "%p", list(l));
1002  fprintf(li, "%;", list(l));
1003  fprintf(li, "%b", M);
1004}
1005
1006/*
1007proc minres(list #)
1008{
1009  if (size(#) == 2)
1010  {
1011    if (typeof(#[1]) == "ideal" || typeof(#[1]) == "module")
1012    {
1013      if (typeof(#[2] == "int"))
1014      {
1015        return (res(#[1],#[2],1));
1016      }
1017    }
1018  }
1019
1020  if (typeof(#[1]) == "resolution")
1021  {
1022    return minimizeres(#[1]);
1023  }
1024  else
1025  {
1026    return minimizeres(#);
1027  }
1028
1029}
1030*/
Note: See TracBrowser for help on using the repository browser.