Class Lehman_Fast
java.lang.Object
de.tilman_neumann.jml.factor.FactorAlgorithm
de.tilman_neumann.jml.factor.lehman.Lehman_Fast
public class Lehman_Fast extends FactorAlgorithm
Fast implementation of Lehman's factor algorithm.
Works flawlessly for N up to 60 bit.
It is quite surprising that the exact sqrt test of
It is quite surprising that the exact sqrt test of
test = a^2 - 4kN
works for N >= 45 bit.
At that size, both a^2 and 4kN start to overflow Long.MAX_VALUE.
But the error - comparing correct results vs. long results - is just the same for both a^2 and 4kN
(and a multiple of 2^64).
Thus test
is correct and b
is correct, too. a
is correct anyway.
Lehman_CustomKOrder is another fast Lehman implementation.
Hart_fast2Mult looks faster on modern hardware.
This class was implemented for YaFu by bSquare,
see https://www.mersenneforum.org/showpost.php?p=506294&postcount=7-
Field Summary
Fields inherited from class de.tilman_neumann.jml.factor.FactorAlgorithm
NUM_PRIMES_FOR_31_BIT_TDIV, tdivLimit
-
Constructor Summary
Constructors Constructor Description Lehman_Fast(boolean doTDivFirst)
Full constructor. -
Method Summary
Modifier and Type Method Description long
findSingleFactor(long N)
java.math.BigInteger
findSingleFactor(java.math.BigInteger N)
Find a single factor of the given N, which is composite and odd.java.lang.String
getName()
static void
main(java.lang.String[] args)
Test.Methods inherited from class de.tilman_neumann.jml.factor.FactorAlgorithm
factor, factor, getDefault, searchFactors
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
Lehman_Fast
public Lehman_Fast(boolean doTDivFirst)Full constructor.- Parameters:
doTDivFirst
- If true then trial division is done before the Lehman loop. This is recommended if arguments N are known to have factors < cbrt(N) frequently.
-
-
Method Details
-
getName
public java.lang.String getName()- Specified by:
getName
in classFactorAlgorithm
- Returns:
- The name of the algorithm, possibly including important parameters.
-
findSingleFactor
public java.math.BigInteger findSingleFactor(java.math.BigInteger N)Description copied from class:FactorAlgorithm
Find a single factor of the given N, which is composite and odd.- Specified by:
findSingleFactor
in classFactorAlgorithm
- Parameters:
N
- number to be factored.- Returns:
- factor
-
findSingleFactor
public long findSingleFactor(long N) -
main
public static void main(java.lang.String[] args)Test.- Parameters:
args
- ignored
-