What techniques can speed up counting pseudoprimes?

  • Thread starter CRGreathouse
  • Start date
  • Tags
    Counting
In summary, the conversation revolves around calculating the high-water marks for a function that counts the number of k-strong pseudoprimes for a composite integer n. The speaker shares their Pari code for the function and discusses the potential slowness of checking for a large range of numbers. They mention a simple test that can speed up the process and ask for other ideas. A resource on pseudoprimes is also provided.
  • #1
CRGreathouse
Science Advisor
Homework Helper
2,844
0
I'm calculating the high-water marks for the following function:
f(n) = #{n is a k-strong pseudoprime, 1 < k < n}
where n is a composite integer.

The naive Pari code:
Code:
ff(n)=sum(k=2,n-1,isSPRP(n, k))

record=0;forstep(n=3, 1e6, 2, if(isprime(n), next); k = ff(n); if (k > record, record = k; print (k" "n)))

Note: I'm using the following straightforward code for checking if a number is a strong pseudoprime; here's the code if you want to duplicate my above functions. I'm not looking for improvements to this part, though if you have any I'd love to hear about it.
Code:
isSPRP(n,b)={
	my(d = n, s = 0);
	until(bitand(d,1), d >>= 1; s++);
	d = Mod(b, n)^d;
	if (d == 1, return(1));
	for(i=1,s-1,
		if (d == -1, return(1));
		d = d^2;
	);
	d == -1
};
But this is very slow: checking ff for a number around a million takes about 10 seconds, so I'm looking at weeks or months of calculation even to check to a million (and I'd like to check more than that).

'Everyone' knows that a composite number can't be a strong pseudoprime to more than a quarter of the k, but more is true: ff(n) is at most phi(n)/4. This simple test significantly speeds results, allowing me to skip between 20% and 90% of the numbers in the range (the relatively smooth/abundant ones) -- the further closer together the records are, the more I can skip. Are there any other ideas?
 
Physics news on Phys.org

1. What is the concept of counting pseudoprimes?

Counting pseudoprimes is a mathematical concept used to identify the number of pseudoprimes within a given range. Pseudoprimes are numbers that satisfy the conditions of a prime number, but are not actually prime.

2. How do you calculate the number of pseudoprimes?

The number of pseudoprimes can be calculated using various methods, such as the Miller-Rabin primality test or the Lucas primality test. These tests involve checking the conditions of a prime number for a given range of numbers and counting the ones that satisfy those conditions.

3. What is the significance of counting pseudoprimes?

Counting pseudoprimes is important in the field of number theory and cryptography. It helps in identifying potential weaknesses in primality tests and finding patterns in the distribution of pseudoprimes.

4. Can pseudoprimes be used in cryptography?

Yes, pseudoprimes can be used in cryptography, but they are not as secure as true prime numbers. They can be used in certain scenarios, but it is important to be aware of their limitations and potential risks.

5. Are there any real-world applications of counting pseudoprimes?

Yes, counting pseudoprimes has various real-world applications, especially in the field of cryptography. It is also used in the design and analysis of algorithms, as well as in identifying potential weaknesses in cryptographic systems.

Similar threads

  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
10
Views
730
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
Replies
11
Views
2K
  • Atomic and Condensed Matter
Replies
3
Views
875
  • Linear and Abstract Algebra
Replies
1
Views
1K
Replies
9
Views
1K
  • Programming and Computer Science
Replies
15
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
671
  • Math Proof Training and Practice
Replies
5
Views
966
Back
Top