ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 24 Jun 2015 11:44:09 -0500Sage is not returning all solutions to equations modulo nhttp://ask.sagemath.org/question/27194/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?
Wed, 24 Jun 2015 11:05:16 -0500http://ask.sagemath.org/question/27194/sage-is-not-returning-all-solutions-to-equations-modulo-n/Answer by fidbc for <p>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:</p>
<pre><code>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
</code></pre>
<p>The list of solutions (there are 207) I receive does not include <code>S=[[1,3],[3,1]]</code>, 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?</p>
http://ask.sagemath.org/question/27194/sage-is-not-returning-all-solutions-to-equations-modulo-n/?answer=27195#post-id-27195Trying 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.Wed, 24 Jun 2015 11:35:32 -0500http://ask.sagemath.org/question/27194/sage-is-not-returning-all-solutions-to-equations-modulo-n/?answer=27195#post-id-27195Comment by Acanti for <p>Trying to find them using brute force isn't that bad. The following worked for me</p>
<pre><code>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)
</code></pre>
<p>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.</p>
http://ask.sagemath.org/question/27194/sage-is-not-returning-all-solutions-to-equations-modulo-n/?comment=27197#post-id-27197Thanks! 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.Wed, 24 Jun 2015 11:44:09 -0500http://ask.sagemath.org/question/27194/sage-is-not-returning-all-solutions-to-equations-modulo-n/?comment=27197#post-id-27197