Math-Prime-Util icon indicating copy to clipboard operation
Math-Prime-Util copied to clipboard

Further optimization of Lucas test may be possible

Open danaj opened this issue 11 years ago • 0 comments

See: https://github.com/wbhart/flint2/issues/81 also: https://github.com/wbhart/flint2/blob/trunk/ulong_extras/is_probabprime_lucas.c

It may be possible to reduce the number of operations in the Lucas test inner loop. The C-P method for V chain uses 2 mulmuds and 2 submods for each loop. They include a way to do this for all Lucas tests.

MPU uses: 2+1 / 5+3 for Q=1 (bit 0 vs. bit 1) 2+1 / 3+3 for P=1/Q=-1 (bit 0 vs. bit 1, also includes more logic) 3+2 / 7+4 otherwise (bit0 vs. bit1, also more logic)

MPUGMP uses: 2+2 for Q=1, P>2 (with inversion) 2+1 / 5+3 for Q=1 (P <= 2 or non-invertible) 4+1 / 8+3 otherwise

We should also look at merging some of these so we do the best thing.

Consider using the inversion method in MPU, and note that if gcd(a,n) == 1, then the inverse should exist, so we don't need to include code for no-inversion.

danaj avatar Jun 20 '14 20:06 danaj