source: git/Singular/LIB/inout.lib @ 5480da

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