Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incorrect isprime results for large numbers #3036

Closed
waldyrious opened this issue May 6, 2013 · 6 comments
Closed

incorrect isprime results for large numbers #3036

waldyrious opened this issue May 6, 2013 · 6 comments
Labels
kind:bug Indicates an unexpected problem or unintended behavior

Comments

@waldyrious
Copy link
Contributor

julia> isprime(1000000007) # 10 digits
true

julia> isprime(10000000019) # 11 digits
false
@StefanKarpinski
Copy link
Sponsor Member

This doesn't seem to be a matter of witness choices so something is up with the algorithm itself. Good catch.

@StefanKarpinski
Copy link
Sponsor Member

The powermod function is the culprit. According to Wolfram Alpha, 2^5000000009 = 10000000018 = -1 (mod 10000000019), but powermod(2,5000000009,10000000019) is giving 7653772409 instead.

@JeffBezanson
Copy link
Sponsor Member

One of the intermediate multiplications is overflowing.

@JeffBezanson
Copy link
Sponsor Member

One fix is to do the multiplications with widemul.

@StefanKarpinski
Copy link
Sponsor Member

Hmm. I'd like to see if I can avoid that. Resorting to 128-bit multiply might be slow.

@StefanKarpinski
Copy link
Sponsor Member

Decided that it was more important to fix the broken isprime behavior than to have the absolute fastest possible powermod algorithm. We can always improve it at some point in the future if it becomes a bottleneck for someone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants