![]() |
|
|
#12 |
|
Mar 2007
Estonia
2×71 Posts |
Prime95, LLR64, and even my own implementation use the gwnum library for the core multiplication/subtraction/modulus, not the builtin %, which works only on native ints. Before I wrote my final implementation I created a demo in Python, with GMP doing the heavy lifting. This solution was several times slower than the final compiled+gwnum solution. This is due to relatively slow loops in Python (an issue Java shouldn't have due to probably effective jit-ing of loops), but GMP itself was too slow for this exact problem. gwnum handles the -2 almost for free, and it's geared towards being very good with multiplication/products mod N. Also it transfers some info from one multiplication to the next (with some special calls) which also speeds it up. Naive solutions are going to be dead slow. gwnum also parallelizes the calculation, uses intrinsics and uses handwritten assembly for the FFT.
Last fiddled with by kuratkull on 2020-03-17 at 13:37 |
|
|
|
|
|
#13 |
|
Jun 2003
10011101111002 Posts |
Have you tried implementing S mod Mp as (S & Mp) + (S >> p) ? This ought to be much faster than generic Java biginteger mod. Then you can add additional safety checks to your heart's content.
|
|
|
|
|
|
#14 | |
|
Undefined
"The unspeakable one"
Jun 2006
My evil lair
22·1,549 Posts |
Quote:
|
|
|
|
|
|
|
#15 | |||
|
Nov 2017
Karlsruhe, Germany
31 Posts |
Quote:
Quote:
Quote:
Though keep in mind that there will always be legitemate reasons to calculate LL in pure Java. |
|||
|
|
|
|
|
#16 |
|
Nov 2017
Karlsruhe, Germany
1F16 Posts |
That calculation does not seem to work.
Last fiddled with by BrainStone on 2020-03-17 at 13:53 |
|
|
|
|
|
#17 |
|
Jun 2003
10011101111002 Posts |
Can you post your code snippet?
EDIT:- For some values, you might have to do a second reduction. Last fiddled with by axn on 2020-03-17 at 15:29 |
|
|
|
|
|
#18 | |
|
Nov 2003
22·5·373 Posts |
Quote:
Why post in the math subforum?? Your question is not math-related. There is a programming subforum. Use it instead. |
|
|
|
|
|
|
#19 | |
|
Nov 2017
Karlsruhe, Germany
3110 Posts |
Quote:
Code:
public static final BigInteger fastMod(BigInteger number, BigInteger candidate, int prime) {
return number.and(candidate).add(number.shiftRight(prime));
}
Last fiddled with by BrainStone on 2020-03-17 at 15:46 |
|
|
|
|
|
|
#20 |
|
Nov 2017
Karlsruhe, Germany
31 Posts |
Because my question is if there's ever a case where \(S(n) \equiv 1 \mod M_p\). Why I am asking this is merely giving context.
Last fiddled with by BrainStone on 2020-03-17 at 15:48 |
|
|
|
|
|
#21 | |
|
Nov 2003
22·5·373 Posts |
Quote:
|
|
|
|
|
|
|
#22 | |
|
Sep 2002
Database er0rr
3,739 Posts |
Quote:
Last fiddled with by paulunderwood on 2020-03-17 at 15:58 |
|
|
|
|
![]() |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Modifying the Lucas Lehmer Primality Test into a fast test of nothing | Trilo | Miscellaneous Math | 25 | 2018-03-11 23:20 |
| A second proof for the Lucas-Lehmer Test | carpetpool | Miscellaneous Math | 2 | 2017-07-30 09:21 |
| Lucas-Lehmer test | Mathsgirl | Information & Answers | 23 | 2014-12-10 16:25 |
| Lucas-Lehmer Test | storm5510 | Math | 22 | 2009-09-24 22:32 |
| Lucas Lehmer test question? | BMgf | Programming | 23 | 2003-12-09 08:52 |