source: git/Singular/LIB/inout.lib @ 06f16f

spielwiese
Last change on this file since 06f16f was 06f16f, checked in by Kai Krüger <krueger@…>, 24 years ago
anne: changed execute to new syntax with () git-svn-id: file:///usr/local/Singular/svn/trunk@4319 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 22.0 KB
Line 
1// $Id: inout.lib,v 1.17 2000-05-12 12:20:25 krueger Exp $
2// (GMG/BM, last modified 22.06.96)
3///////////////////////////////////////////////////////////////////////////////
4
5version="$Id: inout.lib,v 1.17 2000-05-12 12:20:25 krueger Exp $";
6info="
7LIBRARY:  inout.lib     PROCEDURES FOR MANIPULATING IN- AND OUTPUT
8
9PROCEDURES:
10 allprint(list);        print list if ALLprint is defined, with pause if >0
11 dbpri(n,list);         print objects of list if int n<=printlevel
12 lprint(poly/...[,n]);  display poly/... fitting to pagewidth [size n]
13 pmat(matrix[,n]);      print form-matrix [first n chars of each colum]
14 rMacaulay(string);     read Macaulay_1 output and return its Singular format
15 show(any);             display any object in a compact format
16 showrecursive(id,p);   display id recursively with respect to variables in p
17 split(string,n);       split given string into lines of length n
18 tab(n);                string of n space tabs
19 writelist(fil,nam,L);  write the list L into a file `fil` and call it `nam`
20 pause([prompt]);       stop the computation until user input
21           (parameters in square brackets [] are optional)
22";
23
24///////////////////////////////////////////////////////////////////////////////
25
26proc allprint (list #)
27"USAGE:   allprint(L);  L list
28CREATE:  display L[1], L[2], ... if an integer with name ALLprint is defined,
29         makes \"pause\",   if ALLprint > 0
30         listvar(matrix), if ALLprint = 2
31RETURN:  no return value
32EXAMPLE: example allprint; shows an example
33"
34{
35   if( defined(ALLprint) )
36   {
37      int i;
38      for( i=1; i<=size(#); i=i+1 ) { print(#[i]); }
39      if( ALLprint==2 ) { pause(); listvar(matrix); }
40      if( ALLprint >0 ) { pause(); }
41   }
42   return();
43}
44example
45{ "EXAMPLE:"; echo = 2;
46   ring S;
47   matrix M=matrix(freemodule(2),3,3);
48   int ALLprint; export ALLprint;
49   allprint("M =",M);
50   kill ALLprint;
51}
52///////////////////////////////////////////////////////////////////////////////
53
54proc dbpri (int n ,list #)
55"USAGE:   dbpri(n,L);  n integer, L list
56CREATE:  display L[1], L[2], ... if an integer with name printlevel is defined
57         and if n<=printlevel, set printlevel to 0 if it is not defined
58RETURN:  no return value
59NOTE:    this is uesful to control the printing of comments or partial results
60         in a procedure, e.g. for debugging a procedure.
61         It is similair but not the same as the internal function dbprint
62EXAMPLE: example dbpri; shows an example
63"
64{
65   int i;
66   if( defined(printlevel)==0 ) { int printlevel; export printlevel; }
67   if( n<=printlevel )
68   {
69      for( i=1; i<=size(#); i=i+1 ) {  print(#[i]); }
70   }
71   return();
72}
73example
74{ "EXAMPLE:"; echo = 2;
75   ring s;
76   module M=freemodule(3);
77   dbpri(0,"M =",M);
78}
79///////////////////////////////////////////////////////////////////////////////
80
81proc lprint
82"USAGE:   lprint(id[,n]);  id poly/ideal/vector/module/matrix, n integer
83RETURN:  string of id in a format fitting into lines of size n; if only one
84         argument is present, n = pagewidth
85NOTE:    id is printed columnwise, each column separated by a blank line;
86         hence lprint(transpose(id)); displays a matrix id in a format which
87         can be used as input to reproduce id
88EXAMPLE: example lprint; shows an example
89"
90{
91   if (size(#)==1) { int n = pagewidth-3; }
92   else {int n = #[2]-3; }
93   matrix M = matrix(#[1]);
94   poly p,h,L; string s1,s,S; int jj,ii,a;
95   for (jj=1; jj<=ncols(M); jj=jj+1)
96   {
97      for (ii=1; ii<=nrows(M); ii=ii+1)
98      {
99         a=2;
100         if (a+size(string(M[ii,jj])) <= n) {s = "  "+string(M[ii,jj]);}
101         else
102         {
103            h = lead(M[ii,jj]); p = M[ii,jj] - h; L = lead(p);
104            while (p != 0)
105            {
106               if (a+size(string(h+L)) > n)
107               {
108                  s = string(h);
109                  if (a != 0) { s = "  "+s; }
110                  if (a == 0 and s[1] != "-") { s = "+" + s; }
111                  a=0; h=0; S=S+newline+s;
112               }
113               h = h + L; p = p - L; L = lead(p);
114            }
115            s = string(h);
116            if (a == 0 and s[1] != "-") { s = "+" + s; }
117         }
118         if (ii != nrows(M)) { s = s+","; S=S+newline+s; }
119         else
120         {
121            if (jj != ncols(M)) { s = s+","; S=S+newline+s+newline;}
122            else { S=S+newline+s; }
123         }
124      }
125   }
126   return(S[2,size(S)-1]);
127}
128example
129{ "EXAMPLE:"; echo = 2;
130   ring r= 0,(x,y,z),ds;
131   poly f=((x+y)*(x-y)*(x+z)*(y+z)^2);
132   short = 0;    // no short output, use * and ^
133   lprint(f,40); newline;
134   ideal i = f^2,x-y,(x+y)^2*f;
135   short = 1;    // short output, omit * and ^
136   lprint(i); newline;
137   module m = [f^2,x-y,(x+y)^2*f],[0,x-y,f^2];
138   string s=lprint(m); s;"";
139   // the following commands show how to use the string s=lprint(m) (defined
140   // above) as input in order to reproduce m (by defining m1):
141   execute("matrix M[2][3]="+s+";");
142   module m1 = transpose(M);
143   m-m1;
144}
145///////////////////////////////////////////////////////////////////////////////
146
147proc pmat (matrix m, list #)
148"USAGE:   pmat(M,[n]);  M matrix, n integer
149CREATE:  display M in array format if it fits into pagewidth, no return value;
150         if n is given, only the first n characters of each colum are shown
151RETURN:  no return value
152EXAMPLE: example pmat; shows an example
153"
154{
155//------------- main case: input is a matrix, no second argument---------------
156   if ( size(#)==0)
157   {
158      int elems,mlen,slen,c,r;
159   //-------------- count maximal size of each column, and sum up -------------
160      for ( c=1; c<=ncols(m); c=c+1)
161      {  int len(c);
162         for (r=1; r<=nrows(m); r=r+1)
163         {
164            elems = elems+1;
165            string s(elems) = string(m[r,c])+",";
166            slen = size(s(elems));
167            if ( slen>len(c) ) { len(c) = slen; }
168         }
169         mlen = mlen+len(c);
170      }
171   //---------------------- print all - except last - rows --------------------
172      string aus; string sep = " ";
173      if (mlen >= pagewidth) { sep = newline; }
174      for (r=1; r<nrows(m); r=r+1)
175      {  elems = r; aus = "";
176         for (c=1; c<=ncols(m); c=c+1)
177         {
178            aus = aus + s(elems)[1,len(c)] + sep;
179            elems = elems + nrows(m);
180         }
181         aus;
182      }
183   //--------------- print last row (no comma after last entry) ---------------
184      aus = ""; elems = nrows(m);
185      for (c=1; c<ncols(m); c=c+1)
186      {
187         aus = aus + s(elems)[1,len(c)] + sep;
188         elems = elems + nrows(m);
189      }
190      aus = aus + string(m[nrows(m),ncols(m)]);
191      aus;  return();
192   }
193//---------- second case: second argument is given and of type int ------------
194   if ( typeof(#[1])=="int" )
195   {  string aus,tmp; int ll,c,r;
196      for ( r=1; r<=nrows(m); r=r+1)
197      {  aus = "";
198         for (c=1; c<=ncols(m); c=c+1)
199         {
200            tmp=string(m[r,c]);
201            aus=aus+tmp[1,#[1]]+" ";
202         }
203         aus;
204      }
205      return();
206   }
207}
208example
209{  "EXAMPLE:"; echo = 2;
210   ring r=0,(x,y,z),ls;
211   ideal i= x,z+3y,x+y,z;
212   matrix m[3][3]=i^2;
213   pmat(m);
214   pmat(m,3);
215}
216///////////////////////////////////////////////////////////////////////////////
217
218proc rMacaulay
219"USAGE:   rMacaulay(s[,n]);  s string, n integer
220RETURN:  a string which should be readable by Singular if s is a string read
221         by Singular from a file which was produced by Macaulay_1 (='Macaulay
222         classic'). If a second argument is present the first n lines of the
223         file are deleted (which is useful if the file was prodeuced e.g. by
224         the putstd command of Macaulay)
225NOTE:    This does not always work with 'cut and paste' since, coming
226         from the screen, the character \ is treated differently
227EXAMPLE: example rMacaulay; shows an example
228"
229{
230   int n;
231   if( size(#)==2 ) { n=#[2]; }
232   string s0 = #[1];
233//------------------------ delete first n=#[2] lines --------------------------
234   int ii=find(s0,newline); int jj;
235   for ( jj=1; jj<=n; jj=jj+1)
236   {
237      s0 = s0[ii+1,size(s0)-ii];
238      ii = find(s0,newline);
239   }
240//--------------- delete blanks and 'newline' at start and end ----------------
241   ii = 1;
242   while( s0[ii]==" " or s0[ii]==newline ) { ii=ii+1; }
243   s0 = s0[ii,size(s0)-ii+1]; ii = size(s0);
244   while ( s0[ii]==" " or s0[ii]==newline) { ii=ii-1; }
245   s0 = s0[1,ii];
246//------------------------- make each line a string ---------------------------
247   ii = find(s0,newline); jj=0; int kk;
248   while( ii!=0 )
249   {  jj = jj+1;  kk = ii+1;
250      while( s0[kk]==" " or s0[kk]==newline ) {  kk=kk+1; }
251      string s(jj) = s0[1,ii-1];
252      s0 = s0[kk,size(s0)-kk+1];
253      ii = find(s0,newline);
254   }
255   jj=jj+1;
256   string s(jj) = s0;
257//------------ delete blanks and \ at end of each string and add , ------------
258   for( ii=1; ii<=jj; ii=ii+1 )
259   {  kk = 1;
260      while( s(ii)[kk]==" " ) { kk=kk+1; }
261      s(ii) = s(ii)[kk,size(s(ii))-kk+1];
262      kk = size(s(ii));
263      while( s(ii)[kk]==" " or s(ii)[kk]=="\\" or s(ii)[kk]==newline )
264         {  kk = kk-1; }
265      s(ii) = s(ii)[1,kk]+","+newline;
266   }
267//------------------------ replace blanks by , and add up ---------------------
268   int ll; s0 = ""; string s1,s2;
269   for( ii=1; ii<=jj; ii=ii+1 )
270   {
271      s1 = ""; s2 = s(ii);
272      kk = find(s(ii)," "); ll=kk+1;
273      while( kk!=0 )
274      {
275         while( s2[ll]==" ") { ll=ll+1; }
276         if( kk!=1 ) { s1=s1+s2[1,kk-1]+","+s2[kk+1,ll-kk]; }
277         if( kk==1 ) { s1 = s1+","+s2[kk+1,ll-kk]; }
278         s2 = s2[ll+1,size(s2)-ll];
279         kk = find(s2," "); ll=kk+1;
280      }
281      s(ii) = s1+s2; s0 = s0+s(ii);
282   }
283//---------------------------- replace [] by () -------------------------------
284   s1 = ""; s2 = s0;
285   ii = find(s2,"[");
286   while( ii!=0 )
287   {
288      s0 = s0[1,ii-1]+"("+s0[ii+1,size(s0)-ii];
289      if( ii>2 )
290      {
291         if(s0[ii-2]!="+" and s0[ii-2]!="-" and s0[ii-2]!="," and s0[ii-2]!=newline)
292         {
293            s0 = s0[1,ii-2]+"*"+s0[ii-1,size(s0)-ii+2];
294         }
295      }
296      ii = find(s0,"[");
297   }
298   jj = find(s0,"]");
299   while ( jj!=0 )
300   {
301      s0 = s0[1,jj-1]+")"+s0[jj+1,size(s0)-jj];
302      if(s0[jj+1]!="+"and s0[jj+1]!="-" and s0[jj+1]!="," and s0[jj+1]!="*")
303         { s0 = s0[1,jj] + "^" + s0[jj+1,size(s0)-jj]; }
304      jj = find(s0,"]");
305   }
306   s0 = s0[1,size(s0)-2];
307   return(s0);
308}
309example
310{  "EXAMPLE:"; echo = 2;
311   // Assume there exists a file 'Macid' with the following ideal in Macaulay
312   // format:"
313   // x[0]3-101/74x[0]2x[1]+7371x[0]x[1]2-13/83x[1]3-x[0]2x[2] \
314   //     -4/71x[0]x[1]x[2]-65/64x[1]2x[2]-49/111x[0]x[2]2-x[1]x[2]2 \
315   //     -747x[2]3+6072x[0]2x[3]
316   // You can read this file into Singular and assign it to the string s1 by:
317   // string s1 = read("Macid");
318   // This is equivalent to";
319   string s1 =
320   "x[0]3-101/74x[0]2x[1]+7371x[0]x[1]2-13/83x[1]3-x[0]2x[2]-4/71x[0]x[1]x[2]-65/64x[1]2x[2]-49/111x[0]x[2]2-x[1]x[2]2-747x[2]3+6072x[0]2x[3]";
321   rMacaulay(s1);
322   // You may wish to assign s1 to a Singular ideal id:
323   string sid = "ideal id =",rMacaulay(s1),";";
324   ring r = 0,x(0..3),dp;
325   execute(sid);
326   id; "";
327   // The next example treats a matrix in Macaulay format. Using the execute
328   // command, this could be assinged to a Singular matrix as above.
329   string s2 = "
330   0  0  0  0  0
331   a3 0  0  0  0
332   0  b3 0  0  0
333   0  0  c3 0  0
334   0  0  0  d3 0
335   0  0  0  0  e3 ";
336   rMacaulay(s2);
337}
338
339///////////////////////////////////////////////////////////////////////////////
340
341proc show (id, list #)
342"USAGE:   show(id);   id any object of basering or of type ring/qring
343         show(R,s);  R=ring, s=string (s = name of an object belonging to R)
344DISPLAY: display id/s in a compact format together with some information
345RETURN:  no return value
346NOTE:    objects of type string, int, intvec, intmat belong to any ring.
347         id may be a ring or a qring. In this case the minimal polynomial is
348         displayed, and, for a qring, also the defining ideal
349         id may be of type list but the list must not contain a ring
350CAUTION: show(R,s) does not work inside a procedure
351EXAMPLE: example show; shows an example
352"
353{
354//------------- use funny names in order to avoid name conflicts --------------
355   int @li@, @ii;
356   string @s@,@@s;
357   int @short@=short; short=1;
358//----------------------------- check syntax ----------------------------------
359   if( size(#)!= 0 )
360   {
361      if( typeof(#[1])=="int" ) { @li@=#[1]; }
362   }
363   if ( typeof(id)!="list" )
364   {
365      if( size(#)==0 )
366      {
367          def @id@ = id;
368      }
369      if( size(#)==1 )
370      {
371         if( typeof(#[1])=="int" )
372         {
373             def @id@ = id;
374         }
375         if( typeof(#[1])=="string" )
376         {
377            if( typeof(id)=="ring" or typeof(id)=="qring")
378            {
379               def @R@ = id;
380               setring @R@;
381               def @id@=`#[1]`;
382            }
383         }
384      }
385   }
386//----------------------- case: id is of type list ----------------------------
387   if ( typeof(id)=="list" )
388   {
389//      @@s = tab(@li@)+"// list, "+string(size(id))+" element(s):";
390      @@s = tab((3*(voice-2)))+"// list, "+string(size(id))+" element(s):";
391      @@s;
392      for ( @ii=1; @ii<=size(id); @ii++ )
393      {
394         if( typeof(id[@ii])!="none" )
395         {
396            def @id(@ii) = id[@ii];
397            tab(3*(voice-2))+"["+string(@ii)+"]:";
398            //           show(@id(@ii),@li@+3*(voice-1));
399            show(@id(@ii),3*(voice-1));
400         }
401         else
402         {
403            "["+string(@ii)+"]:";
404            tab(@li@+2),"//",id[@ii];
405         }
406      }
407      short=@short@; return();
408    }
409   if( defined(@id@)!=voice ) { "// wrong syntax, type help show;";  return();}
410//-------------------- case: @id@ belongs to any ring -------------------------
411   if( typeof(@id@)=="string" or typeof(@id@)=="int" or typeof(@id@)=="intvec"
412       or typeof(@id@)=="intmat" or typeof(@id@)=="list" )
413   {
414      if( typeof(@id@)!="intmat" )
415      {
416         @@s = tab(@li@)+"// "+typeof(@id@)+", size "+string(size(@id@));
417         @@s;
418      }
419      if( typeof(@id@)=="intmat" )
420      {
421         @@s = tab(@li@)+"// "+typeof(@id@)+", "+string(nrows(@id@))+" rows, "
422               + string(ncols(@id@))+" columns";
423         @@s;
424      }
425      @id@;
426      short=@short@; return();
427   }
428//-------------------- case: @id@ belongs to basering -------------------------
429   if( typeof(@id@)=="poly" or typeof(@id@)=="ideal" or typeof(@id@)=="matrix" )
430   {
431      @@s = tab(@li@)+"// "+ typeof(@id@);
432      if( typeof(@id@)=="ideal" )
433      {
434         @@s=@@s + ", "+string(ncols(@id@))+" generator(s)";
435         @@s;
436         print(ideal(@id@));
437      }
438      if( typeof(@id@)=="poly" )
439      {
440         @@s=@@s + ", "+string(size(@id@))+" monomial(s)";
441         @@s;
442         print(poly(@id@));
443      }
444      if( typeof(@id@)=="matrix")
445      {
446         @@s=@@s + ", "+string(nrows(@id@))+"x"+string(ncols(@id@));
447         @@s;
448         print(matrix(@id@));
449      }
450      short=@short@; return();
451   }
452   if( typeof(@id@)=="vector" )
453   {
454      @@s = tab(@li@)+"// "+typeof(@id@);
455      @@s;
456      print(@id@);
457      short=@short@; return();
458   }
459   if( typeof(@id@)=="module" )
460   {
461      @s@=", "+string(ncols(@id@))+" generator(s)";
462      @@s = tab(@li@)+"// "+ typeof(@id@)+ @s@;
463      @@s;
464      int @n@;
465      for( @n@=1; @n@<=ncols(@id@); @n@=@n@+1 ) { print(@id@[@n@]); }
466      short=@short@; return();
467   }
468   if( typeof(@id@)=="number" or typeof(@id@)=="resolution" )
469   {
470      @@s = tab(@li@)+"// ", typeof(@id@);
471      @@s;
472      @id@; short=@short@; return();
473   }
474   if( typeof(@id@)=="map" )
475   {
476      def @map = @id@;
477      @@s = tab(@li@)+"// i-th variable of preimage ring is mapped to @map[i]";
478      @@s;
479      if( size(#)==0 ) { type @map; }
480      if( size(#)==1 )
481      {
482         if( typeof(#[1])=="int" )    { type @map; }
483         if( typeof(#[1])=="string" ) { type `#[1]`; }
484      }
485      short=@short@; return();
486   }
487//---------------------- case: @id@ is a ring/qring ---------------------------
488   if( typeof(@id@)=="ring" or typeof(@id@)=="qring" )
489   {
490      setring @id@;
491      string s="("+charstr(@id@)+"),("+varstr(@id@)+"),("+ordstr(@id@)+");";
492      if( typeof(@id@)=="ring" )
493      {
494         kill @id@;
495         @@s = tab(@li@)+"// ring:"; @@s,s;
496         @@s = tab(@li@)+"// minpoly ="; @@s,minpoly;
497         "// objects belonging to this ring:";
498         listvar(poly);listvar(ideal);
499         listvar(vector);listvar(module);
500         listvar(map);listvar(matrix);
501         listvar(number);listvar(resolution);
502      }
503      if( typeof(@id@)=="qring" )
504      {
505         @@s = tab(@li@)+"// qring:"; @@s,s;
506         @@s = tab(@li@)+"// minpoly ="; @@s, minpoly;
507         @@s = tab(@li@)+"// quotient ring from ideal:"; @@s;
508         ideal(@id@);
509         listvar(poly);listvar(ideal);
510         listvar(vector);listvar(module);
511         listvar(map);listvar(matrix);
512         listvar(number);listvar(resolution);
513      }
514      short=@short@; //return();
515   }
516}
517example
518{  "EXAMPLE:"; echo = 2;
519    ring r;
520    show(r);
521    ideal i=x^3+y^5-6*z^3,xy,x3-y2;
522    show(i,3);            // introduce 3 space tabs before information
523    vector v=x*gen(1)+y*gen(3);
524    module m=v,2*v+gen(4);
525    list L = i,v,m;
526    show(L);
527    ring S=(0,T),(a,b,c,d),ws(1,2,3,4);
528    minpoly = T^2+1;
529    ideal i=a2+b,c2+T^2*d2; i=std(i);
530    qring Q=i;
531    show(Q);
532    map F=r,a2,b^2,3*c3;
533    show(F);
534// Apply 'show' to i (which does not belong to the basering) by typing
535// ring r; ideal i=xy,x3-y2; ring Q; show(r,"i");
536}
537///////////////////////////////////////////////////////////////////////////////
538
539proc showrecursive (id,poly p,list #)
540"USAGE:   showrecursive(id,p[ord]); id=any object of basering, p=product of
541         variables and ord=string (any allowed ordstr)
542DISPLAY: display 'id' in a recursive format as a polynomial in the variables
543         occuring in p with coefficients in the remaining variables. Do this
544         by mapping in a ring with parameters [and ordering 'ord', if a 3rd
545         argument is present (default: ord=\"dp\")] and applying procedure 'show'
546RETURN:  no return value
547EXAMPLE: example showrecursive; shows an example
548"
549{
550   def P = basering;
551   int ii;
552   string newchar = charstr(P);
553   string neword = "dp";
554   if( size(#) == 1 ) { neword = #[1]; }
555   string newvar;
556   for( ii=1; ii <= nvars(P); ii++ )
557   {
558      if( p/var(ii) == 0 )
559      {
560         newchar = newchar + ","+varstr(ii);
561      }
562      else
563      {
564         newvar = newvar + ","+varstr(ii);
565      }
566   }
567   newvar = newvar[2,size(newvar)-1];
568
569   execute("ring newP=("+newchar+"),("+newvar+"),("+neword+");");
570   def id = imap(P,id);
571   show(id);
572   return();
573}
574example
575{ "EXAMPLE:"; echo=2;
576   ring r=2,(a,b,c,d,x,y),ds;
577   poly f=y+ax2+bx3+cx2y2+dxy3;
578   showrecursive(f,x);
579   showrecursive(f,xy,"lp");
580}
581///////////////////////////////////////////////////////////////////////////////
582
583proc split (string s, list #)
584"USAGE:    split(s[,n]); s string, n integer
585RETURN:   same string, split into lines of length n separated by \
586          (default: n=pagewidth)
587NOTE:     may be used in connection with lprint
588EXAMPLE:  example split; shows an example
589"
590{
591   string line,re; int p,l;
592   if( size(#)==0 ) { int n=pagewidth; }
593   else { int n=#[1]; }
594   if( s[size(s),1] != newline ) { s=s+newline; }
595   l=size(s);
596   while( 1 )
597   {
598      p=1;
599      l=find(s,newline); line=s[1,l];
600      while( l>=n )
601      {
602         re=re+line[p,n-2]+"\\"+newline;
603         p=p+n-2; l=l-n+2;
604      }
605      re=re+line[p,l-1]+"\\"+newline;
606      l=size(line);
607      if( l>=size(s) ) break;
608      s=s[l+1,size(s)-l];
609   }
610   return (re[1,size(re)-2]);
611}
612example
613{  "EXAMPLE:"; echo = 2;
614   ring r= 0,(x,y,z),ds;
615   poly f = (x+y+z)^9;
616   split(string(f),40);
617   string s=split(lprint(f,40),40); s;
618   split(lprint(f));
619}
620///////////////////////////////////////////////////////////////////////////////
621
622proc tab (int n)
623"USAGE:   tab(n);  n integer
624RETURN:  string of n space tabs
625EXAMPLE: example tab; shows an example
626"
627{
628   if( n==0 ) { return(""); }
629   string s=" ";
630   return(s[1,n]);
631}
632example
633{  "EXAMPLE:"; echo = 2;
634   for(int n=0; n<=5; n=n+1)
635   { tab(5-n)+"*"+tab(n)+"+"+tab(n)+"*"; }
636}
637///////////////////////////////////////////////////////////////////////////////
638
639proc writelist (string fil, string nam, list L)
640"USAGE:   writelist(fil,nam,L);  fil,nam=strings (file-name, list-name), L=list
641CREATE:  a file with name `fil`, write the content of the list L into it and
642         call the list `nam`.
643RETURN:  no return value
644NOTE:    The syntax of writelist uses and is similar to the syntax of the
645         write command of Singular which does not manage lists properly.
646         If, say, (fil,nam) = (\"listfile\",\"L1\"),  writelist creates (resp.
647         appends if listfile exists) a file with name listfile and stores
648         there the list L under the name L1. The Singular command
649         execute(read(\"listfile\")); assignes the content of L (stored in
650         listfile) to a list L1.
651         On a UNIX system, overwrite an existing file if fil=\">...\", resp.
652         append if fil=\">>...\".
653EXAMPLE: example writelist; shows an example
654"
655{
656   int i;
657   write(fil,"list "+nam+";");
658   if( fil[1]==">" ) { fil=fil[2..size(fil)]; }
659   if( fil[1]==">" ) { fil=fil[2..size(fil)]; }
660   for( i=1;i<=size(L);i=i+1 )
661   {
662     write(fil,"   "+nam+"["+string(i)+"]=",string(L[i])+";");
663   }
664   return();
665}
666example
667{  "EXAMPLE:"; echo = 2;
668   ring r;
669   ideal i=x,y,z;
670   list k="Hi",nameof(basering),i,37;
671   writelist("zumSpass","lustig",k);
672   read("zumSpass");
673   list L=res(i,0);       //resolution of the maximal ideal
674   writelist("L","L",L);
675   read("L");
676   system("sh","/bin/rm L zumSpass");
677   // Under UNIX, this removes the files 'L' and 'zumSpass'
678   // Type help system; to get more information about the shell escape
679   // If your operating system does not accept the shell escape, you
680   // have to remove the just created files 'zumSpass' and 'L' directly
681}
682///////////////////////////////////////////////////////////////////////////////
683
684proc pause(list #)
685"USAGE:    pause([ prompt ])  prompt string
686RETURN:   none
687PURPOSE:  pause in the computation till user input
688SEE ALSO: read
689EXAMPLE : example pause; shows an example
690"
691{
692  string pr="pause>";
693  if (size(#)!=0)
694  {
695    pr=#[1];
696  }
697  pr=read("",pr);
698}
699example
700{ "EXAMPLE:"; echo=2;
701  // cannot be shown non-interactively, try the follwing commands without //
702  // pause("press <return> to continue");
703  // pause();
704}
Note: See TracBrowser for help on using the repository browser.