Skip to content

Commit

Permalink
- Minor optimization in Number is_safe_prime(n).
Browse files Browse the repository at this point in the history
If `(n-1)/2` is a strong base-2 pseudoprime, but `n` is not a strong base-2 pseudoprime, there is no need to run a Lucas test on `(n-1)/2`.
  • Loading branch information
trizen committed Aug 1, 2020
1 parent e783fa7 commit 08008d6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Sidef/Types/Number/Number.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10985,7 +10985,9 @@ package Sidef::Types::Number::Number {
_primality_pretest($t)
|| return Sidef::Types::Bool::Bool::FALSE;

(Math::Prime::Util::GMP::is_prob_prime($t) && Math::Prime::Util::GMP::is_strong_pseudoprime($n, 2))
( Math::Prime::Util::GMP::is_strong_pseudoprime($t, 2)
&& Math::Prime::Util::GMP::is_strong_pseudoprime($n, 2)
&& Math::Prime::Util::GMP::is_strong_lucas_pseudoprime($t))
? Sidef::Types::Bool::Bool::TRUE
: Sidef::Types::Bool::Bool::FALSE;
}
Expand Down

0 comments on commit 08008d6

Please sign in to comment.