source: git/Singular/LIB/inout.lib @ 0fbdd1

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