Skip to content

Instantly share code, notes, and snippets.

@Hermann-SW
Created May 17, 2025 23:03
Show Gist options
  • Save Hermann-SW/e4c2ccccd918e59766dc82b01993d41b to your computer and use it in GitHub Desktop.
Save Hermann-SW/e4c2ccccd918e59766dc82b01993d41b to your computer and use it in GitHub Desktop.
script demonstrating alternative for isprimepower() with very big primes
f1(N)={isprimepower(N,&r);return(r);}
f2(N)={return(lift(gcd(Mod(2,N)^N-2,N)));}
measure(f,N)={t0=getwalltime();f(N);t1=getwalltime();return(t1-t0);}
print("runtimes in milliseconds, with N=nextprime(base)^expo\n");
print("isprimepower(N,&r);return(r)");
{
printf(" |");for(e=2,15,printf("%3d|",e));print();
printf(" |");for(e=2,15,print1("---|"));print();
forstep(b=10,160,10,
printf("10^%3d|",b);
for(e=2,15,
N=nextprime(10^b)^e;
t=measure(f1,N);
printf("%3d|",t);
);
print("");
)
}
print();
print("lift(gcd(Mod(2,N)^N-2,N))");
{
printf(" |");for(e=2,15,printf("%3d|",e));print();
printf(" |");for(e=2,15,print1("---|"));print();
forstep(b=10,160,10,
printf("10^%3d|",b);
for(e=2,15,
N=nextprime(10^b)^e;
t=measure(f2,N);
printf("%3d|",t);
);
print("");
)
}
@Hermann-SW
Copy link
Author

hermann@7950x:~$ gp -q < <(curl --no-progress-meter https://gist.githubusercontent.com/Hermann-SW/e4c2ccccd918e59766dc82b01993d41b/raw/e7480819b8a57331d84cd30f6a9f89650a44388e/measure.gp)
runtimes in milliseconds, with N=nextprime(base)^expo

isprimepower(N,&r);return(r)
      |  2|  3|  4|  5|  6|  7|  8|  9| 10| 11| 12| 13| 14| 15|
      |---|---|---|---|---|---|---|---|---|---|---|---|---|---|
10^ 10|  0|  0|  0|  0|  0|  0|  0|  0|  0|  0|  0|  0|  0|  0|
10^ 20|  0|  0|  0|  0|  0|  0|  0|  1|  0|  0|  0|  0|  0|  0|
10^ 30|  1|  1|  1|  1|  1|  1|  1|  1|  1|  1|  0|  0|  1|  1|
10^ 40|  2|  2|  2|  2|  2|  2|  1|  2|  2|  2|  2|  2|  1|  1|
10^ 50|  1|  0|  0|  1|  0|  0|  1|  0|  0|  1|  0|  0|  0|  0|
10^ 60|  5|  5|  5|  5|  5|  5|  5|  4|  4|  5|  5|  5|  5|  5|
10^ 70| 23| 23| 23| 23| 23| 23| 23| 23| 23| 23| 23| 23| 23| 23|
10^ 80| 13| 13| 13| 13| 12| 12| 12| 12| 12| 12| 12| 12| 12| 12|
10^ 90| 18| 18| 19| 19| 19| 19| 18| 18| 18| 17| 16| 16| 17| 16|
10^100| 23| 23| 24| 24| 24| 24| 23| 23| 23| 23| 23| 23| 23| 24|
10^110|  0|  1|  0|  1|  0|  1|  0|  1|  0|  1|  0|  1|  0|  1|
10^120| 51| 50| 51| 51| 51| 51| 51| 51| 51| 51| 51| 51| 51| 51|
10^130|109|109|108|108|109|109|108|109|108|109|108|108|109|109|
10^140|115|115|115|115|115|115|115|115|114|115|115|115|115|115|
10^150|136|136|136|136|136|136|136|136|136|136|136|136|136|136|
10^160|217|216|216|216|216|216|216|216|216|216|216|217|216|216|

lift(gcd(Mod(2,N)^N-2,N))
      |  2|  3|  4|  5|  6|  7|  8|  9| 10| 11| 12| 13| 14| 15|
      |---|---|---|---|---|---|---|---|---|---|---|---|---|---|
10^ 10|  0|  0|  0|  0|  0|  0|  0|  0|  0|  0|  0|  0|  0|  0|
10^ 20|  0|  0|  0|  0|  0|  0|  0|  0|  0|  0|  0|  0|  1|  0|
10^ 30|  0|  0|  0|  0|  0|  0|  1|  0|  0|  1|  0|  1|  0|  1|
10^ 40|  0|  0|  0|  0|  0|  0|  1|  0|  1|  1|  1|  1|  2|  1|
10^ 50|  0|  0|  0|  0|  1|  0|  1|  1|  1|  2|  1|  2|  3|  3|
10^ 60|  0|  0|  0|  1|  0|  1|  1|  1|  2|  3|  3|  3|  5|  5|
10^ 70|  0|  0|  0|  1|  1|  1|  1|  2|  2|  4|  4|  6|  6|  8|
10^ 80|  0|  0|  0|  0|  1|  1|  3|  3|  4|  5|  6|  7|  9| 11|
10^ 90|  0|  0|  0|  1|  2|  2|  3|  4|  5|  7|  8| 10| 12| 15|
10^100|  0|  0|  1|  1|  1|  3|  4|  5|  6|  9| 11| 13| 16| 20|
10^110|  0|  0|  0|  2|  2|  4|  5|  7|  8| 10| 14| 18| 21| 26|
10^120|  0|  0|  1|  2|  3|  4|  6|  8| 11| 14| 18| 22| 28| 32|
10^130|  0|  1|  1|  2|  4|  5|  8| 10| 13| 17| 22| 28| 33| 41|
10^140|  0|  1|  2|  3|  4|  7|  9| 13| 16| 21| 27| 33| 40| 49|
10^150|  1|  1|  2|  3|  5|  8| 11| 15| 20| 26| 32| 39| 48| 55|
10^160|  0|  1|  2|  4|  6|  9| 13| 17| 24| 31| 38| 47| 54| 58|
hermann@7950x:~$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment