source: git/Singular/LIB/inout.lib @ 558209

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