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

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