mirror of
https://github.com/mpusz/mp-units.git
synced 2025-06-25 01:01:33 +02:00
This is more involved than the Miller-Rabin test, but we can tame the complexity by breaking it down into helper functions, performing tasks such as: - Increment the index of the (U_k, V_k) sequence elements by one. - Double the index of the (U_k, V_k) sequence elements. - Find an appropriate D parameter. etc. With these helpers, the algorithm becomes straightforward (see, for instance, https://en.wikipedia.org/wiki/Lucas_pseudoprime#Strong_Lucas_pseudoprimes). We start by ruling out perfect squares (because if we don't, then the search for `D` will never terminate). Then we find our `D`, and decompose `n + 1` into `s` and `d` parameters (exactly as we did for Miller-Rabin, except there we used `n - 1`). At this point, the strong test is easy: check whether `U_d` is 0, then check `V_d`, as well as `V` for all successive doublings of the index less than `s`. A similar testing strategy as for the Miller Rabin gives us sufficient confidence. 1. Test that we get small primes right. 2. Test that we get known pseudoprimes "correctly wrong". 3. Test some really big primes. (Remember, a probable prime test must mark every actual prime as "probably prime".) Helps #509.