source: git/Singular/LIB/inout.lib @ 6fe9a5

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