Last active
February 5, 2016 11:45
-
-
Save fujidig/7ae6aa7a4244a5332194 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\\ determine that order of g equals to n | |
isprimitive(g, n, e=1) = { | |
my(factors, p); | |
if (g^n != e, return(0)); | |
factors = factor(n); | |
for (i = 1, matsize(factors)[1], | |
p = factors[i, 1]; | |
if (g^(n/p) == e, return(0))); | |
return(1); | |
} | |
\\ identity matrix | |
E = matid; | |
\\ right & left shift matrix | |
R(n, k) = { return(matrix(n, n, i, j, i + k == j)); } | |
L(n, k) = { return(R(n, -k)); } | |
\\ convert to matrix on F_2 | |
to_f2(mat) = { return(matrix(matsize(mat)[1], matsize(mat)[2], i, j, Mod(mat[i, j], 2))); } | |
n = 64; | |
T = to_f2((E(n) + L(n, 17)) * (E(n) + R(n, 7)) * (E(n) + L(n, 13))); | |
print(isprimitive(Mod(x, charpoly(T, x)), 2^n - 1)); |
Thanks. I understood. I fixed it :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the function isprimitive(), you'd better to use my() rather than local(). It's a bit difficult to explain how these are different... my() declares statically scoped local variables, while local() declares dynamically scoped local variables. See the reference manual of pari-gp, or type ??my in a pari-gp session. Example:
? x=0; f()={x}
%1 = ()->x
? g()={my(x=1); f()}
%2 = ()->my(x=1);f()
? h()={local(x=1); f()}
%3 = ()->local(x=1);f()
? g()
%4 = 0
? h()
%5 = 1