Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.9k
Primality tests: Add trivial code for seven-base#1562
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
Artoria2e5 wants to merge1 commit intocp-algorithms:mainChoose a base branch fromArtoria2e5:primez
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+25 −0
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading.Please reload this page.
The seven base version uses five fewer bases than the twelve-base version. That's 5 fewer binpower calls in the positive case, a 41.7% reduction. Based on that I think including the (very trivial) code for it is worthwhile.
Well, since we're already there, perhaps adding trial division with, say, the first 25 primes would greatly speed up the average case... nope, not going down that path.
Actually we should perhaps do go down that path. That's what every practical implementation does.
Most obvious place to add TD without adding another list of primes is after the
(n == a)test. Just return false on(n % a == 0)!But then you check godbolt gcc 15.2
-O3and --- what? it's usingdiv? What happened to division by constants being turned to some kind of mul? Turns out it only does that if you put the(n % a == 0)test in a separate loop from thecheck_compositetest. And it never happens at-O2possibly due to lack of loop unrolling. The more you know.