# Help with script computing Galois Groups

I've been developing (see below) a script on how to calculate Galois groups using a statistical method. However, when I try to run the code for degree >_ 10 on cocalc (SageMathCloud), I end up with an error stating:

f = x^11 + 25*x^4 + 39 There are 348511 primes less than 5000000 which do not divide disc(f) cycle type (2, 3, 5) occurs 11601 times,ieError in lines 27-31 Traceback (most recent call last): File "/projects/sage/sage-7.6/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 995, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 5, in NameError: name 'numerical' is not defined

I was hoping if someone could potentially help me to ensure that the script is working properly - I just would like to play around with this and see what the weaknesses are with this script.

R.<x>=ZZ[x];
f=;
y =
print "f =", f;
if f.is_irreducible()==true:
L=[];
for i in range (y):
if is_prime(i)==true:
if disc(f)%i!=0:
k=f.change_ring(GF(i)).factor();
l=[];
for j in range(len(k)):
if k[j][1]*k[j][0].degree()>=2:
l.append(k[j][1]*k[j][0].degree());
L.append(tuple(l));
c=len(L);
print "There are",c, "primes less than",y, "which do not divide disc(f)";
S=Set(L)
v=0;
for r in range(len(S)):
if S[r]==():
v=1;
h=L.count(S[r]);
o=numerical_approx(c/h,digits=1);
print "The order of G is", o
print "Identity occurs", L.count(S[r]), "times, ie:" ,RealField(2)    (L.count(S[r])*100/c), "%";
for r in range(len(S)):
if S[r]!=():
if v==1:
print "cycle type",S[r], "occurs", L.count(S[r]),"times,ie:",numerical_approx(L.count(S[r])*100/c,digits=2),"%","n",S[r],"=",numerical_approx(L.count(S[r])/h,digits=1);
else:print "cycle type", S[r], "occurs",L.count(S[r]), "times,ie",numerical_approx(L.count(S[r])*100/c,digits=2),"%";


Thank you and have a good day. :-)

• Who is the author of the code or method? Is there a link for the source of the algorithm? I think that should be edited into the question. – quasi Jul 22 '17 at 14:12
• The indentation on your code is really mangled in the last few lines. You should fix it. Also, you have a curly brace in S[r}, which I'm guessing is unintentional. – André 3000 Jul 22 '17 at 14:18
• The indentation is still messed up. The last else on the last line corresponds to the if f.is_irreducible()==true:. – André 3000 Jul 22 '17 at 14:52

This may still have some problems, but it now runs successfully for me. Changes are on lines 13 and 14 in the tuples replace the letter "l" with the digit "1" On line 24 replace digits=0 with digits = 1 Fix indentation on lines 30ff. Finally replace the "." with a "," in L.count(S[r])*100/c.digits=2 around line 30

R.<x>=ZZ[x];
f=x^5-7*x+1;
y = 1000000
print "f =", f;
if f.is_irreducible()==true:
L=[];
for i in range (y):
if is_prime(i)==true:
if disc(f)%i!=0:
k=f.change_ring(GF(i)).factor();
l=[];
for j in range(len(k)):
if k[j][1]*k[j][0].degree()>=2:
l.append(k[j][1]*k[j][0].degree());
L.append(tuple(l));
c=len(L);
print "There are",c, "primes less than",y, "which do not divide disc(f)";
S=Set(L)
v=0;
for r in range(len(S)):
if S[r]==():
v=1;
h=L.count(S[r]);
o=numerical_approx(c/h,digits=1);
print "The order of G is", o
print "Identity occurs", L.count(S[r]), "times, ie:" ,RealField(2)    (L.count(S[r])*100/c), "%";
for r in range(len(S)):
if S[r]!=():
if v==1:
print "cycle type",S[r], "occurs", L.count(S[r]),"times,ie:",numerical_approx(L.count(S[r])*100/c,digits=2),"%","n",S[r],"=",numerical_approx(L.count(S[r])/h,digits=1);
else:print "cycle type", S[r], "occurs",L.count(S[r]), "times,ie",numerical_approx(L.count(S[r])*100/c,digits=2),"%";
else:print "is not irreducible in ZZ[x]";

• Error in lines 27-32 Traceback (most recent call last): File "/projects/sage/sage-7.6/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 995, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "<string>", line 5 else:print "cycle type", S[r], "occurs",L.count(S[r]), "times,ie",numerical.approx(L.count(S[r])*Integer(100)/c,digits=Integer(2)),"%"; ^ SyntaxError: invalid syntax – AlwaysNeedHelp Jul 22 '17 at 16:36
• @AlwaysNeedHelp You need to check the indentation and spacing carefully on lines 30 ff. The script runs without errors for me. The first else:print aligns with print on the previous line. The second else:print should align with if S[r]!=() 4 lines above. Where did that "Integer(2)" and Integer(100) come from? Are those just from the debug output? – sharding4 Jul 22 '17 at 16:42
• Thank you for your helpful comments. I'm almost there (I've got the cycle types showing. One final problem I'm facing is that one of the lines does not seem to fit together, spilling over onto the next line and hence does not execute the final part of the code. I've tried to put the code on a single line, but it does not seem to allow me to do so (this is on cocalc.com). I may be able to show you via a photo (I will edit it in the original post). Very much appreciative of all your help. – AlwaysNeedHelp Jul 22 '17 at 17:57
• @AlwaysNeedHelp the code I posted runs successfully. How does your code differ? – sharding4 Jul 22 '17 at 19:01
• @reuns the idea is based on the Tchebotarev Density Theorem. The degrees of the irreducible factors correspond to cycles. So take $x^3-2$ say. Factoring modulo 5 gives a linear and a quadratic factor which corresponds to a cycle type (1,2). Modulo 7 the polynomial is irreducible so corresponds to a 3-cycle. Module 31 the polynomial splits completely so correspinds to the identity. The script counts the factorizations and estimates the frequencies of the various cycle types. In the example script provided the y =10000 is too low and will give an incorrect answer. y=10^6 is needed. – sharding4 Jul 22 '17 at 22:51