# Sage is not returning all solutions to equations modulo n

I am trying to find all 2x2 matrices $S$ over $Z/9Z$ such that $S^3=I$, where I is the identity matrix. I am currently using the following procedure:

S = matrix(SR, 2, [[a,b],[c,d]]);
S3=S^3
l=solve_mod([S3[0,0]==1,S3[0,1]==0,S3[1,0]==0,S3[1,1]==1], 9);
l


The list of solutions (there are 207) I receive does not include S=[[1,3],[3,1]], for example, which does in fact satisfy $S^3=I$. I am new to Sage, is there something I am missing? How can I get a complete list of solutions?

edit retag close merge delete

Sort by » oldest newest most voted Trying to find them using brute force isn't that bad. The following worked for me

import itertools
Z9=Zmod(9)
I=Matrix(Z9,[[1,0],[0,1]])
L=[]
for a,b,c,d in itertools.product(Z9,repeat=4):
M=Matrix(Z9,[[a,b],[c,d]])
if I==M^3:
L.append(M)


The length of the list seems to be 297 though, but the 39th element seems to be the one that was missing from your list.

more

Thanks! This will fix my current problem, but I am still concerned for when I use larger matrices, and/or a different modulus. If anyone has ideas on a really efficient way to do this in general, I would love to hear them.