solving a linear system of GF(3) -- strange TypeError

49 views
Skip to first unread message

Robert Samal

unread,
Oct 8, 2019, 8:17:59 PM10/8/19
to sage-support
I am trying to solve a rather large linear systems of equations of GF(3). As the matrices are sparse, I thought that adding "sparse=True" to the constructor of the matrix could be of help. However, I ran to a strange error message.

B=matrix(GF(3), 2,2,[1,0,1,0], sparse=True)
v
=vector(F, [1,1])
B
.solve_right(v)

The above code yields the following
TypeError: Cannot convert sage.matrix.matrix_modn_sparse.Matrix_modn_sparse to sage.matrix.matrix_integer_sparse.Matrix_integer_sparse


I am hesitant to paste the whole error message here, but it ends with reference to file
SageMath/local/lib/python2.7/site-packages/sage/matrix/matrix_modn_sparse.pyx
in
sage.matrix.matrix_modn_sparse.Matrix_modn_sparse._solve_matrix_linbox
(build/cythonized/sage/matrix/matrix_modn_sparse.cpp:11633).

I am using Sage 8.9, but the same issue was on 8.7 as well.

Few other observations:
-- works as expected for dense matrices -- or for sparse ones over integers
-- the same issue occurs whether y is a vector or a matrix
-- It behaves the same for systems with no solution.


Is there some hidden limitation of sparse matrices over finite fields?
I.e., is it a bug or feature? :-)
I tried to RTFM, but couldn't find this discussed. The page for sparse matrices over
finite fields does not exactly promise the solve method, but it does not mention it
would not work either. Is it possible to achieve what I want by other means (in Sage).

Thanks.




David Joyner

unread,
Oct 9, 2019, 1:06:27 AM10/9/19
to SAGE support


On Tue, Oct 8, 2019, 8:18 PM Robert Samal <robert...@gmail.com> wrote:
I am trying to solve a rather large linear systems of equations of GF(3). As the matrices are sparse, I thought that adding "sparse=True" to the constructor of the matrix could be of help. However, I ran to a strange error message.

B=matrix(GF(3), 2,2,[1,0,1,0], sparse=True)
v
=vector(F, [1,1])
B
.solve_right(v)

The above code yields the following

What is F (in the line defining v)?


TypeError: Cannot convert sage.matrix.matrix_modn_sparse.Matrix_modn_sparse to sage.matrix.matrix_integer_sparse.Matrix_integer_sparse


I am hesitant to paste the whole error message here, but it ends with reference to file
SageMath/local/lib/python2.7/site-packages/sage/matrix/matrix_modn_sparse.pyx
in
sage.matrix.matrix_modn_sparse.Matrix_modn_sparse._solve_matrix_linbox
(build/cythonized/sage/matrix/matrix_modn_sparse.cpp:11633).

I am using Sage 8.9, but the same issue was on 8.7 as well.

Few other observations:
-- works as expected for dense matrices -- or for sparse ones over integers
-- the same issue occurs whether y is a vector or a matrix

-- It behaves the same for systems with no solution.

Is there some hidden limitation of sparse matrices over finite fields?
I.e., is it a bug or feature? :-)
I tried to RTFM, but couldn't find this discussed. The page for sparse matrices over
finite fields does not exactly promise the solve method, but it does not mention it
would not work either. Is it possible to achieve what I want by other means (in Sage).

Thanks.




--
You received this message because you are subscribed to the Google Groups "sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/e8912161-212e-4e6f-aa69-a7461b2f6c09%40googlegroups.com.

Robert Samal

unread,
Oct 9, 2019, 1:32:59 AM10/9/19
to sage-support
Sorry, F=GF(3), I made my original example shorter and didn't read it properly.

So the full problematic code is

B=matrix(GF(3), 2,2,[1,0,1,0], sparse=True)

v
=vector(GF(3), [1,1])
B
.solve_right(v)

Thanks,

Robert

David Joyner

unread,
Oct 9, 2019, 7:09:50 AM10/9/19
to SAGE support
On Wed, Oct 9, 2019 at 1:33 AM Robert Samal <robert...@gmail.com> wrote:
Sorry, F=GF(3), I made my original example shorter and didn't read it properly.

So the full problematic code is

B=matrix(GF(3), 2,2,[1,0,1,0], sparse=True)
v
=vector(GF(3), [1,1])
B
.solve_right(v)


Yes. I can confirm it works with "sparse=True" removed *or* if GF(3) is replaced by ZZ.
So there's an easy workaround but maybe the docs or the code has a bug? 
Thanks for reporting. 

Thanks,

Robert


On Tuesday, October 8, 2019 at 5:17:59 PM UTC-7, Robert Samal wrote:
I am trying to solve a rather large linear systems of equations of GF(3). As the matrices are sparse, I thought that adding "sparse=True" to the constructor of the matrix could be of help. However, I ran to a strange error message.

B=matrix(GF(3), 2,2,[1,0,1,0], sparse=True)
v
=vector(F, [1,1])
B
.solve_right(v)

The above code yields the following
TypeError: Cannot convert sage.matrix.matrix_modn_sparse.Matrix_modn_sparse to sage.matrix.matrix_integer_sparse.Matrix_integer_sparse


I am hesitant to paste the whole error message here, but it ends with reference to file
SageMath/local/lib/python2.7/site-packages/sage/matrix/matrix_modn_sparse.pyx
in
sage.matrix.matrix_modn_sparse.Matrix_modn_sparse._solve_matrix_linbox
(build/cythonized/sage/matrix/matrix_modn_sparse.cpp:11633).

I am using Sage 8.9, but the same issue was on 8.7 as well.

Few other observations:
-- works as expected for dense matrices -- or for sparse ones over integers
-- the same issue occurs whether y is a vector or a matrix
-- It behaves the same for systems with no solution.


Is there some hidden limitation of sparse matrices over finite fields?
I.e., is it a bug or feature? :-)
I tried to RTFM, but couldn't find this discussed. The page for sparse matrices over
finite fields does not exactly promise the solve method, but it does not mention it
would not work either. Is it possible to achieve what I want by other means (in Sage).

Thanks.




--
You received this message because you are subscribed to the Google Groups "sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.

Dima Pasechnik

unread,
Oct 9, 2019, 11:34:41 AM10/9/19
to sage-support
This got broken in Sage 8.5.
(still works in 8.4)



Robert Samal

unread,
Oct 9, 2019, 7:06:29 PM10/9/19
to sage-support
Indeed it works in Sage 8.4.
Thanks!
To unsubscribe from this group and stop receiving emails from it, send an email to sage-s...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-s...@googlegroups.com.

Dima Pasechnik

unread,
Oct 9, 2019, 9:31:39 PM10/9/19
to sage-support, sage-devel
This is now https://trac.sagemath.org/ticket/28586

It would be great not to have to do git bisect on this, anyone can point out to a suspect ticket?
Thanks!

To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/5ce4410e-1ee7-4ebd-a5a6-903e893c1b77%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages