Skip to content

Adding deterministic miller rabin primality test #1453

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

Merged
merged 2 commits into from
Oct 25, 2019

Conversation

bizzfitch
Copy link
Contributor

There's a miller-rabin primality test in the cipher folder, but I figured a deterministic one for "small" numbers would be interesting. Deterministic (meaning True is prime) for n < ~ 3.32 e 24, probabilistic for larger. With Miller Rabin, a False is always composite- no false negatives.

See https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test for details.

@cclauss
Copy link
Member

cclauss commented Oct 25, 2019

The tests are not being discovered by pytest
https://travis-ci.com/TheAlgorithms/Python/builds/133548451#L425

Why not put both miller-rabin implementations in the same directory with different names to ease side-by-side study?

@bizzfitch
Copy link
Contributor Author

Any idea what I did wrong with the tests? I put them under test_miller_rabin, which runs under main.

That's a good point. My thought process was that since this test is deterministic for most computable numbers, it can be used as a general fast primality test. I also don't have any additional implementation that made me think of putting it in the cipher folder. If you think it's best, I'm happy to move it, because I'm not convinced it belongs in maths :)

@cclauss
Copy link
Member

cclauss commented Oct 25, 2019

I am not sure on the test thing. It has been bugging me for a while now. I am no expert on pytest discovery rules but perhaps @codecalec could give us guidance on why is works in his PRs.

@cclauss
Copy link
Member

cclauss commented Oct 25, 2019

Ahh... Perhaps the test_function() needs to be in a file with the name of the form test_***.py.

@cclauss cclauss merged commit 182062d into TheAlgorithms:master Oct 25, 2019
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* Adding deterministic miller rabin primality test

* Moved to ciphers directory and renamed for clarity. Changed docstring to add test
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.

3 participants