Singular
https://www.singular.uni-kl.de/forum/

Problem with writelist and list of matrices
https://www.singular.uni-kl.de/forum/viewtopic.php?f=10&t=1773
Page 1 of 1

Author:  Ravi [ Sat Sep 12, 2009 8:55 am ]
Post subject:  Problem with writelist and list of matrices

I have a problem using the writelist function when I write a list of matrices to a file and want to recreate the list in memory by reading the file later on. Here is a simple example:

Code:
ring R = 0, (x,y,z), dp;
matrix A[3][3] = 0,1,0, -1,0,0, 0,0,1;      
matrix B[3][3] = 0,1,0,  0,0,1, 1,0,0;      
matrix C[3][3] = 0,1,0,  1,0,0, 0,0,1;
list L = A,B,C;
writelist("simple-write.txt", "simplist", L);


This creates the text file alright:
list simplist;
simplist[1]=matrix(
0,1,0,-1,0,0,0,0,1);
etc...

but when I try to read it and recreate simplist:

Code:
ring R = 0, (x,y,z), dp;
execute(read("simple-write.txt"));  // does not create the list simplist in memory


The error I get is:
Code:
? error occurred in Read-Oh.sing line 10: `0,1,0,-1,0,0,0,0,1);`
? wrong type declaration. type 'help matrix;'
? last reserved name was `matrix`
skipping text from `-` error at token `)`

According to the help files (D.2.4.9), this should create the object simplist. It works for other objects, but not for lists of matrices.
If someone can tell me what is going wrong, I shall be most grateful...

Ravi

Author:  gorzel [ Tue Sep 15, 2009 12:55 pm ]
Post subject:  Re: Problem with writelist and list of matrices

The cast matrix is incomplete, dimensions nrows and ncols are missing.

To fix the problem for the datataypes matrix and intmat,
change the for-loop as follows

Code:
for( i=1;i<=size(L);i=i+1 )
   {
     if (typeof(L[i]) == "intmat")
     {
       write(fil,"   "+nam+"["+string(i)+"]="+
              "intmat(intvec("+string(L[i])+
          "),"+string(nrows(L[i]))+","+string(ncols(L[i]))+");");
     }
     if ( typeof(L[i])== "matrix")
     {
        write(fil,"   "+nam+"["+string(i)+"]="+
              "matrix(ideal("+string(L[i])+
          "),"+string(nrows(L[i]))+","+string(ncols(L[i]))+");");
     }
     else
     {
       write(fil,"   "+nam+"["+string(i)+"]="+typeof(L[i])+"(",string(L[i])+");");
     }
   }


(Note: Other datatypes as string also do not work properly.)

Author:  Ravi [ Tue Sep 15, 2009 3:39 pm ]
Post subject:  Re: Problem with writelist and list of matrices

Thank you. It works now. To avoid defining the list every time I read the file, I added a declaration before your for loop:

write(fil, "list " + nam + ";");

Thanks again.

Ravi :)

Page 1 of 1 All times are UTC + 1 hour [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/