Skip to content

Performance tweak for ulong n_is_prime#2579

Merged
fredrik-johansson merged 5 commits intoflintlib:mainfrom
JASory:reduced-prime
Feb 15, 2026
Merged

Performance tweak for ulong n_is_prime#2579
fredrik-johansson merged 5 commits intoflintlib:mainfrom
JASory:reduced-prime

Conversation

@JASory
Copy link
Contributor

@JASory JASory commented Feb 13, 2026

I've modified the semiprime check algorithm to run in approximately 0.75t the time of the current version. Unfortunately the function was only a small fraction of the total time of the primality testing so the observed speed up is only about 0.96t for n_is_prime_odd_no_trial and completely lost in variance of the trial division for n_is_prime.

This should close out #2504 . I don't see any way to further reduce the hashtable size while staying less than 1/5 the cost of a fermat test. The semiprime check rapidly decreases in efficiency, due to the k-semiprimes getting both rarer and having fewer liars as k increases. This means that further reducing to 49Kib or 32Kib would require so many checks (50+) that the BPSW would become more efficient.

The next step is to replace the trial division by prime-inverse multiplication, which I'm holding off on until I evaluate the factorisation algorithms, and other places we use can prime_inverses mod 2^64, so we can have a more "unified" codebase.

@fredrik-johansson fredrik-johansson merged commit 4dc1909 into flintlib:main Feb 15, 2026
13 checks passed
@fredrik-johansson
Copy link
Collaborator

Looks good, thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants