source: git/Singular/LIB/inout.lib @ 63be42

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