aurora-opensource / au

A C++14-compatible physical units library with no dependencies and a single-file delivery option. Emphasis on safety, accessibility, performance, and developer experience.
Apache License 2.0
329 stars 21 forks source link

Add Miller-Rabin probable prime algorithm #321

Closed chiphogg closed 1 week ago

chiphogg commented 2 weeks ago

We put this in a new file, probable_primes.hh. Algorithms in this class can return one of three outcomes:

The wikipedia page[1] gives a good overview of the algorithm.

How do we know that the implementation is correct? By these main strategies:

Given that the implementation passes all of these tests, it seems very likely that our implementation is correct.

Helps #217.

[1] https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test