Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to speed up the code?

Given a matrix M, to find all 1,-1 matrices which satisfy the condition given in the code. For n=3, I am getting the outputs easily. For n=6, it ran for around 12 hours and got "flint exception error". I understand that len(T) is huge so there might be some memory issues. Is there anyway to get over it?

 n=3 
 T=Tuples((1,-1),n^2)
 A=[matrix(n,n,t) for t in T]
 for a in A:
     if 3*a^2==M:
        show(a)