Skip to content

Unify the various versions of is_prime() #5642

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

Closed
wants to merge 1 commit into from
Closed

Unify the various versions of is_prime() #5642

wants to merge 1 commit into from

Conversation

humblepenguinn
Copy link

@humblepenguinn humblepenguinn commented Oct 28, 2021

Describe your change:

Fixes: #5488

The issue #5488 stated that there were a lot of prime functions in the repository, this PR solves that issue by unifying all the functions into one prime check function. The unified prime_check function takes O(sqrt(n)). Some special prime functions were left alone.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@ghost ghost added awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files labels Oct 28, 2021
@cclauss cclauss changed the title Fix #5488 Unify the various versions of is_prime() Oct 28, 2021
@cclauss
Copy link
Member

cclauss commented Oct 28, 2021

I would like to take a different approach to this which follows the benchmarking work done be @Leoriem-code in #5592. Instead of merely deleting code, this survival-of-the-fittest approach would put all implementations of is_prime() side-by-side in a single Python file. We could then ensure they all pass a common set of tests and run timeitbenchmarks to see which one is fastest. Whichever pure Python implementation passes all tests, is understandable, and is fastest should be exported as our current maths.is_prime() function. Putting all implementations together will allow visitors to study and understand the pros and cons of the various implementations. The timeit benchmarks would make it possible for contributors to compete to gain the throne.

Thoughts?

@cclauss cclauss requested a review from poyea October 28, 2021 17:51
@ghost ghost added the tests are failing Do not merge until tests pass label Oct 28, 2021
@humblepenguinn
Copy link
Author

Thank you for the advice, I am closing this pull request and will open a new later

@humblepenguinn humblepenguinn deleted the humblepenguin branch October 29, 2021 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files tests are failing Do not merge until tests pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants