cmpute / num-modular

Apache License 2.0
13 stars 4 forks source link

Legendre function is broken #1

Closed JASory closed 2 years ago

JASory commented 2 years ago

a^p-1 = 1 mod p is a necessary but not sufficient condition for primality. This is resulting in an extremely high error rate.

cmpute commented 2 years ago

I intentionally didn't include the primality check in the legendre function, because this crate doesn't deal with anything with primality test. This is clearly stated in the documentation

JASory commented 2 years ago

I intentionally didn't include the primality check in the legendre function, because this crate doesn't deal with anything with primality test. This is clearly stated in the documentation

https://docs.rs/num-modular/0.5.1/num_modular/trait.ModularSymbols.html#tymethod.checked_legendre

cmpute commented 2 years ago

@JASory The doc says

Checked version of legendre(), return None if n is not prime

This doesn't mean that it will do a full primality check (you can check the implementation). But the doc definitely needs to be improved, thanks for pointing out and I will make this clear