source: git/Singular/LIB/standard.lib @ 0dee96

spielwiese
Last change on this file since 0dee96 was 0dee96, checked in by Olaf Bachmann <obachman@…>, 24 years ago
* more output on option(prot) git-svn-id: file:///usr/local/Singular/svn/trunk@3057 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 23.2 KB
Line 
1// $Id: standard.lib,v 1.31 1999-05-26 13:14:33 obachman Exp $
2//////////////////////////////////////////////////////////////////////////////
3
4version="$Id: standard.lib,v 1.31 1999-05-26 13:14:33 obachman Exp $";
5info="
6LIBRARY: standard.lib   PROCEDURES WHICH ARE ALWAYS LOADED AT START-UP
7
8 stdfglm(ideal[,ord])   standard basis of the ideal via fglm [and ordering ord]
9 stdhilb(ideal)         standard basis of the ideal using the Hilbert function
10 groebner(ideal/module) standard basis of ideal or module using a
11                        heuristically choosen method
12 quot(any,any[,n])  a general quotient procedure calling several algorithms
13                  allows module/module, ideal/ideal, module/ideal and a
14                  pre-definition of the algorithm by the parameter n
15 quotient1(m1,m2) computes quotients by every vector of m2 and intersects them
16 quotient2(m1,m2) a heuristic variant: the quotient is just defined by a
17                  (not really) general element of m2 which has to be proved
18 quotient3(m1,m2) the homogeneous variant of quotient5(m1,m2)
19 quotient4(m1,m2) the same as quotient5(m1,m2) using the modulo-command
20                  instead of the quotient-command from the kernel
21 quotient5(m1,m2) computes with a real general element of m2 by adjoining
22                  a new variable
23 sprintf(fmt,...)     returns fomatted string
24 fprintf(link,fmt,..) writes formatted string to link
25 printf(fmt,...)      displays formatted string
26";
27
28//////////////////////////////////////////////////////////////////////////////
29
30proc stdfglm (ideal i, list #)
31"USAGE:   stdfglm(i[,s]); i ideal, s string (any allowed ordstr of a ring)
32RETURN:  stdfglm(i): standard basis of i in the basering, calculated via fglm
33                     from ordering \"dp\" to the ordering of the basering.
34         stdfglm(i,s): standard basis of i in the basering, calculated via
35                     fglm from ordering s to the ordering of the basering.
36EXAMPLE: example stdfglm; shows an example"
37{
38   string os;
39   def dr= basering;
40   if( (size(#)==0) or (typeof(#[1]) != "string") )
41   {
42     os = "dp(" + string( nvars(dr) ) + ")";
43     if ( (find( ordstr(dr), os ) != 0) and (find( ordstr(dr), "a") == 0) )
44     {
45       os= "Dp";
46     }
47     else
48     {
49       os= "dp";
50     }
51   }
52   else { os = #[1]; }
53   execute "ring sr=("+charstr(dr)+"),("+varstr(dr)+"),"+os+";";
54   ideal i= fetch(dr,i);
55   intvec opt= option(get);
56   option(redSB);
57   i=std(i);
58   option(set,opt);
59   setring dr;
60   return (fglm(sr,i));
61}
62example
63{ "EXAMPLE:"; echo = 2;
64   ring r  = 0,(x,y,z),lp;
65   ideal i = y3+x2, x2y+x2, x3-x2, z4-x2-y;
66   ideal i1= stdfglm(i);         //uses fglm from "dp" to "lp"
67   i1;
68   ideal i2= stdfglm(i,"Dp");    //uses fglm from "Dp" to "lp"
69   i2;
70}
71/////////////////////////////////////////////////////////////////////////////
72
73proc stdhilb(ideal i,list #)
74"USAGE:   stdhilb(i);  i ideal
75         stdhilb(i,v); i homogeneous ideal, v intvec (the Hilbert function)
76RETURN:  stdhilb(i): a standard basis of i (computing v internally)
77         stdhilb(i,v): standard basis of i, using the given Hilbert function
78EXAMPLE: example stdhilb; shows an example"
79{
80   def R=basering;
81
82   if((homog(i)==1)||(ordstr(basering)[1]=="d"))
83   {
84      if ((size(#)!=0)&&(homog(i)==1))
85      {
86         return(std(i,#[1]));
87      }
88      return(std(i));
89   }
90
91   execute "ring S = ("+charstr(R)+"),("+varstr(R)+",@t),dp;";
92   ideal i=homog(imap(R,i),@t);
93   intvec v=hilb(std(i),1);
94   execute "ring T = ("+charstr(R)+"),("+varstr(R)+",@t),("+ordstr(R)+");";
95   ideal i=fetch(S,i);
96   ideal a=std(i,v);
97   setring R;
98   map phi=T,maxideal(1),1;
99   ideal a=phi(a);
100
101   int k,j;
102   poly m;
103   int c=size(i);
104
105   for(j=1;j<c;j++)
106   {
107     if(deg(a[j])==0)
108     {
109       a=ideal(1);
110       attrib(a,"isSB",1);
111       return(a);
112     }
113     if(deg(a[j])>0)
114     {
115       m=lead(a[j]);
116       for(k=j+1;k<=c;k++)
117       {
118          if(size(lead(a[k])/m)>0)
119          {
120            a[k]=0;
121          }
122       }
123     }
124   }
125   a=simplify(a,2);
126   attrib(a,"isSB",1);
127   return(a);
128}
129example
130{ "EXAMPLE:"; echo = 2;
131   ring  r = 0,(x,y,z),lp;
132   ideal i = y3+x2, x2y+x2, x3-x2, z4-x2-y;
133   ideal i1= stdhilb(i); i1;
134   // is in this case equivalent to:
135   intvec v=1,0,0,-3,0,1,0,3,-1,-1;
136   ideal i2=stdhilb(i,v);
137}
138//////////////////////////////////////////////////////////////////////////
139
140proc groebner(def i, list #)
141"USAGE: groebner(i[, wait]) i -- ideal/module; wait -- int
142RETURNS: Standard basis of ideal or module which is computed using a
143         heuristically choosen method:
144         If the ordering of the current ring is a local ordering, or
145         if it is a non-block ordering and the current ring has no
146         parameters, then std(i) is returned.
147         Otherwise, i is mapped into a ring with no parameters and
148         ordering dp, where its Hilbert series is computed. This is
149         followed by a Hilbert-series based std computation in the
150         original ring.
151NOTE: If a 2nd argument 'wait' is given, then the computation proceeds
152      at most 'wait' seconds. That is, if no result could be computed in
153      'wait' seconds, then the computation is interrupted, 0 is returned,
154      a warning message is displayed, and the global variable
155      'groebner_error' is defined.
156EXAMPLE: example groebner; shows an example"
157{
158  def P=basering;
159
160  // we have two arguments -- try to use MPfork links
161  if (size(#) > 0)
162  {
163    if (system("with", "MP"))
164    {
165      if (typeof(#[1]) == "int")
166      {
167        int wait = #[1];
168        int j = 10;
169
170        string bs = nameof(basering);
171        link l_fork = "MPtcp:fork";
172        open(l_fork);
173        write(l_fork, quote(system("pid")));
174        int pid = read(l_fork);
175        write(l_fork, quote(groebner(eval(i))));
176
177        // sleep in small intervalls for appr. one second
178        if (wait > 0)
179        {
180          while(j < 1000000)
181          {
182            if (status(l_fork, "read", "ready", j)) {break;}
183            j = j + j;
184          }
185        }
186
187        // sleep in intervalls of one second from now on
188        j = 1;
189        while (j < wait)
190        {
191          if (status(l_fork, "read", "ready", 1000000)) {break;}
192          j = j + 1;
193        }
194
195        if (status(l_fork, "read", "ready"))
196        {
197          def result = read(l_fork);
198          if (bs != nameof(basering))
199          {
200            def PP = basering;
201            setring P;
202            def result = imap(PP, result);
203            kill PP;
204          }
205          if (defined(groebner_error))
206          {
207            kill(groebner_error);
208          }
209          kill (l_fork);
210        }
211        else
212        {
213          ideal result;
214          if (! defined(groebner_error))
215          {
216            int groebner_error = 1;
217            export groebner_error;
218          }
219          "// ** groebner did not finish";
220          j = system("sh", "kill " + string(pid));
221        }
222        return (result);
223      }
224      else
225      {
226        "// ** groebner needs int as 2nd arg";
227      }
228    }
229    else
230    {
231      "// ** groebner with two args is not supported in this configuration";
232    }
233  }
234
235  // we are still here -- do the actual computation
236  string ordstr_P = ordstr(P);
237  if (find(ordstr_P,"s") > 0)
238  {
239    //spaeter den lokalen fall ueber lp oder aehnlich behandeln
240    return(std(i));
241  }
242
243  int IsSimple_P;
244  if (system("nblocks") <= 2)
245  {
246    if (find(ordstr_P, "M") <= 0)
247    {
248      IsSimple_P = 1;
249    }
250  }
251  int npars_P = npars(P);
252
253  // return std if no parameters and (dp or wp)
254  if ((npars_P <= 1) && IsSimple_P)
255  {
256    if (find(ordstr_P, "d") > 0)
257    {
258      return (std(i));
259    }
260    if (find(ordstr_P,"w") > 0)
261    {
262      return (std(i));
263    }
264  }
265
266  // reset options
267  intvec opt=option(get);
268  int p_opt;
269  string s_opt = option();
270  option(none);
271  // turn on option(prot) and/or option(mem), if previously set
272  if (find(s_opt, "prot"))
273  {
274    option(prot);
275    p_opt = 1;
276  }
277  if (find(s_opt, "mem"))
278  {
279    option(mem);
280  }
281
282  // construct ring in which first std computation is done
283  string varstr_P = varstr(P);
284  string parstr_P = parstr(P);
285  int is_homog = (homog(i) && (npars_P <= 1));
286  int add_vars = 0;
287  string ri = "ring Phelp =";
288
289  // more than one parameters are converted to ring variables
290  if (npars_P > 1)
291  {
292    ri = ri + string(char(P)) + ",(" + varstr_P + "," + parstr_P;
293    add_vars = npars_P;
294  }
295  else
296  {
297    ri = ri + "(" + charstr(P) + "),(" + varstr_P;
298  }
299
300  // a homogenizing variable is added, if necessary
301  if (! is_homog)
302  {
303    ri = ri + ",@t";
304    add_vars = add_vars + 1;
305  }
306  // ordering is set to (dp, C)
307  ri = ri + "),(dp,C);";
308
309  // change the ring
310  execute(ri);
311
312  // get ideal from previous ring
313  if (is_homog)
314  {
315    ideal qh = imap(P, i);
316  }
317  else
318  {
319    // and homogenize
320    ideal qh=homog(imap(P,i),@t);
321  }
322
323  // compute std and hilbert series
324  if (p_opt)
325  {
326    "std in " + ri[13, size(ri) - 13];
327  }
328  ideal qh1=std(qh);
329  intvec hi=hilb(qh1,1);
330
331  if (add_vars == 0)
332  {
333    // no additional variables were introduced
334    setring P; // can immediately change to original ring
335    // simply compute std with hilbert series in original ring
336    if (p_opt)
337    {
338      "std with hilb in basering";
339    }
340    i = std(i, hi);
341  }
342  else
343  {
344    // additional variables were introduced
345    // need another intermediate ring
346    ri = "ring Phelp1 = (" + charstr(Phelp)
347      + "),(" + varstr(Phelp) + "),(" + ordstr_P;
348
349    // for lp wit at most one parameter, we do not need a block ordering
350    if ( ! (IsSimple_P && (add_vars <2) && find(ordstr_P, "l")))
351    {
352      // need block ordering
353      ri = ri + ", dp(" + string(add_vars) + ")";
354    }
355    ri = ri + ");";
356
357    // change to intermediate ring
358    execute(ri);
359    ideal qh = imap(Phelp, qh);
360    kill Phelp;
361    if (p_opt)
362    {
363      "std with hilb in " + ri[14,size(ri)-14];
364    }
365    // compute std with Hilbert series
366    qh = std(qh, hi);
367    // subst 1 for homogenizing var
368    if (!is_homog)
369    {
370      if (p_opt)
371      {
372        "dehomogenization";
373      }
374      qh = subst(qh, @t, 1);
375    }
376
377    // go back to original ring
378    setring P;
379    // get ideal, delete zeros and clean SB
380    if (p_opt)
381    {
382      "imap to original ring";
383    }
384    i = imap(Phelp1,qh);
385    if (p_opt)
386    {
387      "simplification";
388    }
389    i = simplify(i, 34);
390    kill Phelp1;
391  }
392
393  // clean-up time
394  option(set, opt);
395  if (find(s_opt, "redSB") > 0)
396  {
397    if (p_opt)
398    {
399      "interreduction";
400    }
401    i=interred(i);
402  }
403  attrib(i, "isSB", 1);
404  return (i);
405}
406example
407{
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{
426   def P=basering;
427   def m=#[1]; //the ideal or module
428
429   int i=#[2]; //the length of the resolution
430               //if size(#)>2 a minimal resolution is computed
431
432   string varstr_P = varstr(P);
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  if (size(fmt) <= 1)
766  {
767    return (fmt);
768  }
769  int next, l, nnext;
770  string ret;
771  list formats = "%l", "%s", "%2l", "%2s", "%t", "%;", "%p", "%b", "%n", "%2";
772  while (1)
773  {
774    if (size(#) <= 0)
775    {
776      return (ret + fmt);
777    }
778    nnext = 0;
779    while (1)
780    {
781      nnext = find(fmt, "%", nnext + 1);
782      if (nnext == 0)
783      {
784        next = 0;
785        break;
786      }
787      l = 1;
788      while (l <= size(formats))
789      {
790        next = find(fmt, formats[l], nnext);
791        if (next == nnext) break;
792        l++;
793      }
794      if (next == nnext) break;
795    }
796    if (next == 0)
797    {
798      return (ret + fmt);
799    }
800    if (formats[l] != "%2" && formats[l] != "%n")
801    {
802      ret = ret + fmt[1, next - 1] + print(#[1], formats[l]);
803      # = delete(#, 1);
804    }
805    else
806    {
807      ret = ret + fmt[1, next - 1] + print("", "%2s");
808    }
809    if (size(fmt) <= (next + size(formats[l]) - 1))
810    {
811      return (ret);
812    }
813    fmt = fmt[next + size(formats[l]), size(fmt)-next-size(formats[l]) + 1];
814  }
815}
816example
817{
818  ring r=0,(x,y,z),dp;
819  module m=[1,y],[0,x+z];
820  intmat M=betti(mres(m,0));
821  list l = r, m, M;
822  string s = sprintf("s:%s,%n l:%l", 1, 2); s;
823  s = sprintf("s:%n%s", l); s;
824  s = sprintf("s:%2%s", list(l)); s;
825  s = sprintf("2l:%n%2l", list(l)); s;
826  s = sprintf("%p", list(l)); s;
827  s = sprintf("%;", list(l)); s;
828  s = sprintf("%b", M); s;
829}
830
831proc printf(string fmt, list #)
832"USAGE:    printf(fmt, ...) fmt string
833RETURN:   none
834PURPOSE:  printf performs output formatting. The first argument is a format
835          control string. Additional arguments may be required, depending on
836          the contents of the control string. A series of output characters is
837          generated as directed by the control string; these characters are
838          displayed (i.e. printed to standard out).
839          The control string is simply text to be copied, except that the
840          string may contain conversion specifications.
841          Do 'help print:' for a listing of valid conversion specifications.
842          As an addition to the conversions of 'print', the '%n' and '%2'
843          conversion specification does not consume an additional argument,
844          but simply generates a newline character.
845
846NOTE:     If one of the additional arguments is a list, then it should be
847          enclosed once more into a list() command, since passing a list
848          as an argument flattens the list by one level.
849SEE ALSO: sprintf, fprintf, print, string
850EXAMPLE : example printf; shows an example
851"
852{
853  write("", sprintf(fmt, #));
854}
855example
856{
857  ring r=0,(x,y,z),dp;
858  module m=[1,y],[0,x+z];
859  intmat M=betti(mres(m,0));
860  list l = r, m, M;
861  printf("s:%s, l:%l", 1, 2);
862  printf("s:%s", l);
863  printf("s:%s", list(l));
864  printf("2l:%2l", list(l));
865  printf("%p", list(l));
866  printf("%;", list(l));
867  printf("%b", M);
868}
869
870
871proc fprintf(link l, string fmt, list #)
872"USAGE:    fprintf(l, fmt, ...) l link; fmt string
873RETURN:   none
874PURPOSE:  fprintf performs output formatting. The second argument is a format
875          control string. Additional arguments may be required, depending on
876          the contents of the control string. A series of output characters is
877          generated as directed by the control string; these characters are
878          written to the link l.
879          The control string is simply text to be copied, except that the
880          string may contain conversion specifications.
881          Do 'help print:' for a listing of valid conversion specifications.
882          As an addition to the conversions of 'print', the '%n' and '%2'
883          conversion specification does not consume an additional argument,
884          but simply generates a newline character.
885
886NOTE:     If one of the additional arguments is a list, then it should be
887          enclosed once more into a list() command, since passing a list
888          as an argument flattens the list by one level.
889SEE ALSO: sprintf, printf, print, string
890EXAMPLE : example fprintf; shows an example
891"
892{
893  write(l, sprintf(fmt, #));
894}
895example
896{
897  ring r=0,(x,y,z),dp;
898  module m=[1,y],[0,x+z];
899  intmat M=betti(mres(m,0));
900  list l = r, m, M;
901  link li = ""; // link to stdout
902  fprintf(li, "s:%s, l:%l", 1, 2);
903  fprintf(li, "s:%s", l);
904  fprintf(li, "s:%s", list(l));
905  fprintf(li, "2l:%2l", list(l));
906  fprintf(li, "%p", list(l));
907  fprintf(li, "%;", list(l));
908  fprintf(li, "%b", M);
909}
910
911
912
913
914
915
916/*
917proc minres(list #)
918{
919  if (size(#) == 2)
920  {
921    if (typeof(#[1]) == "ideal" || typeof(#[1]) == "module")
922    {
923      if (typeof(#[2] == "int"))
924      {
925        return (res(#[1],#[2],1));
926      }
927    }
928  }
929
930  if (typeof(#[1]) == "resolution")
931  {
932    return minimizeres(#[1]);
933  }
934  else
935  {
936    return minimizeres(#);
937  }
938
939}
940
941*/
Note: See TracBrowser for help on using the repository browser.