Fast primality test for small numbers

  • Thread starter Thread starter CRGreathouse
  • Start date Start date
  • Tags Tags
    Numbers Test
CRGreathouse
Science Advisor
Homework Helper
Messages
2,832
Reaction score
0
Beating Pari: fast primality test for small numbers

I'm looking for a library (or just a program) with a fast primality test for 64-bit numbers. In particular I'd like something that's faster than Pari which I'm currently using. I do need it to be programmable, of course, since billions of tests need to be done.

Any ideas? Or is Pari essentially as fast as I can get?

I'm going to try to port my program to Mathematica to do a speed comparison, but in past tests Pari beats Mathematica soundly in number theory.
 
Last edited:
Physics news on Phys.org
Original Pari code:
Code:
aa=vector(90,n,2^n);bb=vector(90,n,3*2^n);v=sumset(aa,bb);v=vector(5000,i,v[i]);
counter(n)=my(i=0);while(v[i++]<n,if(isprime(n-v[i]),return(0)));1
forstep(n=7,1e6,2,if(counter(n),print(n)))
This actually uses my custom function sumset, but its function is pretty clear from context.

Here's my Mathematica version:
Code:
v=Part[Sort[Flatten[Table[2^i+3*2^j,{i,90},{j,90}]]],1;;5000];
counter(n_):=Block[{i=0},
	While[v[[i++]]<n,
		If[PrimeQ[n-v[[i]]],Return[0]]
	];
	Return[1]
]
Timing[For[i=7,i<=10^6,i+=2,If[counter[i]!=0,Print[i]]]]

The Mathematica code takes about three times as long as the Pari code. The Pari code could be yet faster with ispseudoprime, of course...
 
##\textbf{Exercise 10}:## I came across the following solution online: Questions: 1. When the author states in "that ring (not sure if he is referring to ##R## or ##R/\mathfrak{p}##, but I am guessing the later) ##x_n x_{n+1}=0## for all odd $n$ and ##x_{n+1}## is invertible, so that ##x_n=0##" 2. How does ##x_nx_{n+1}=0## implies that ##x_{n+1}## is invertible and ##x_n=0##. I mean if the quotient ring ##R/\mathfrak{p}## is an integral domain, and ##x_{n+1}## is invertible then...
The following are taken from the two sources, 1) from this online page and the book An Introduction to Module Theory by: Ibrahim Assem, Flavio U. Coelho. In the Abelian Categories chapter in the module theory text on page 157, right after presenting IV.2.21 Definition, the authors states "Image and coimage may or may not exist, but if they do, then they are unique up to isomorphism (because so are kernels and cokernels). Also in the reference url page above, the authors present two...
When decomposing a representation ##\rho## of a finite group ##G## into irreducible representations, we can find the number of times the representation contains a particular irrep ##\rho_0## through the character inner product $$ \langle \chi, \chi_0\rangle = \frac{1}{|G|} \sum_{g\in G} \chi(g) \chi_0(g)^*$$ where ##\chi## and ##\chi_0## are the characters of ##\rho## and ##\rho_0##, respectively. Since all group elements in the same conjugacy class have the same characters, this may be...

Similar threads

Replies
4
Views
3K
Replies
20
Views
2K
Replies
30
Views
6K
Replies
16
Views
3K
Replies
3
Views
3K
Replies
5
Views
2K
Replies
7
Views
3K
Replies
3
Views
1K
Back
Top