├── .github └── workflows │ └── maven.yml ├── .gitignore ├── LICENSE ├── README.md ├── conf └── log4j2-test.xml ├── doc ├── Lehman kN congruences.txt └── PSIQS-performance.txt ├── lib ├── log4j-api-2.24.3.jar └── log4j-core-2.24.3.jar ├── pom.xml └── src ├── main └── java │ └── de │ └── tilman_neumann │ ├── jml │ ├── BinarySearch.java │ ├── ChebyshevPolynomials.java │ ├── Divisors.java │ ├── HarmonicNumbers.java │ ├── MoebiusFunction.java │ ├── base │ │ ├── BigDecimalConstants.java │ │ ├── BigDecimalMath.java │ │ ├── BigIntCollectionUtil.java │ │ ├── BigIntConstants.java │ │ ├── BigIntConverter.java │ │ ├── BigIntGrid.java │ │ ├── BigIntPoly.java │ │ ├── BigIntTriangle.java │ │ ├── BigRational.java │ │ ├── IntCollectionUtil.java │ │ ├── NumberGrid.java │ │ ├── Uint128.java │ │ └── UnsignedBigInt.java │ ├── combinatorics │ │ ├── Binomial.java │ │ ├── Factorial.java │ │ ├── FallingFactorial.java │ │ ├── HyperFactorial.java │ │ ├── Multinomial.java │ │ └── Stirling.java │ ├── factor │ │ ├── CombinedFactorAlgorithm.java │ │ ├── CombinedFactorAlgorithmRunner.java │ │ ├── FactorAlgorithm.java │ │ ├── FactorException.java │ │ ├── FactorSieve.java │ │ ├── TestNumberNature.java │ │ ├── TestsetGenerator.java │ │ ├── base │ │ │ ├── FactorArguments.java │ │ │ ├── FactorResult.java │ │ │ ├── GlobalFactoringOptions.java │ │ │ ├── IntHolder.java │ │ │ ├── PrimeBaseGenerator.java │ │ │ ├── SortedIntegerArray.java │ │ │ ├── SortedLongArray.java │ │ │ ├── UnsafeUtil.java │ │ │ ├── congruence │ │ │ │ ├── AQPair.java │ │ │ │ ├── AQPairFactory.java │ │ │ │ ├── CongruenceCollector.java │ │ │ │ ├── CongruenceCollector01.java │ │ │ │ ├── CongruenceCollector02.java │ │ │ │ ├── CongruenceCollector03.java │ │ │ │ ├── CongruenceCollectorReport.java │ │ │ │ ├── CongruenceCollectorSmall.java │ │ │ │ ├── CycleCounter.java │ │ │ │ ├── CycleCounter2LP.java │ │ │ │ ├── CycleCounter3LP.java │ │ │ │ ├── CycleFinder.java │ │ │ │ ├── Partial.java │ │ │ │ ├── Partial1Large.java │ │ │ │ ├── Partial2Large.java │ │ │ │ ├── PartialNLarge.java │ │ │ │ ├── PartialSolver.java │ │ │ │ ├── PartialSolver01.java │ │ │ │ ├── PartialSolver02.java │ │ │ │ ├── Smooth.java │ │ │ │ ├── Smooth1LargeSquare.java │ │ │ │ ├── SmoothComposite.java │ │ │ │ ├── SmoothNLargeSquares.java │ │ │ │ ├── SmoothPerfect.java │ │ │ │ └── SmoothSimple.java │ │ │ └── matrixSolver │ │ │ │ ├── BlockLanczos.java │ │ │ │ ├── FactorTest.java │ │ │ │ ├── FactorTest01.java │ │ │ │ ├── IndexSet.java │ │ │ │ ├── MatrixRow.java │ │ │ │ ├── MatrixSolver.java │ │ │ │ ├── MatrixSolverBase01.java │ │ │ │ ├── MatrixSolverBase02.java │ │ │ │ ├── MatrixSolverBase03.java │ │ │ │ ├── MatrixSolverBlockLanczos.java │ │ │ │ ├── MatrixSolverGauss01.java │ │ │ │ ├── MatrixSolverGauss02.java │ │ │ │ ├── MatrixSolverGauss03.java │ │ │ │ ├── MatrixSolverPGauss01.java │ │ │ │ ├── RichMatrixFactory.java │ │ │ │ └── util │ │ │ │ ├── CompareCongruence.java │ │ │ │ ├── CompareEntry.java │ │ │ │ └── StackEntry.java │ │ ├── cfrac │ │ │ ├── CFrac.java │ │ │ ├── CFrac63.java │ │ │ ├── KnuthSchroeppelCFrac.java │ │ │ └── tdiv │ │ │ │ ├── TDiv_CF.java │ │ │ │ ├── TDiv_CF01.java │ │ │ │ ├── TDiv_CF02.java │ │ │ │ ├── TDiv_CF03.java │ │ │ │ ├── TDiv_CF63.java │ │ │ │ ├── TDiv_CF63_01.java │ │ │ │ └── TDiv_CF63_02.java │ │ ├── ecm │ │ │ ├── EllipticCurveMethod.java │ │ │ ├── MontgomeryMult.java │ │ │ ├── TinyEcm64.java │ │ │ ├── TinyEcm64MH.java │ │ │ └── TinyEcm64MHInlined.java │ │ ├── hart │ │ │ ├── HartFast.java │ │ │ ├── HartFast2Mult.java │ │ │ ├── HartFast2Mult2.java │ │ │ ├── HartFast2MultFMA.java │ │ │ ├── HartMultiplierChainSqrtN.java │ │ │ ├── HartSimple.java │ │ │ ├── HartSquarefree.java │ │ │ ├── HartTDivRace.java │ │ │ └── HartTDivRace2.java │ │ ├── lehman │ │ │ ├── LehmanCustomKOrder.java │ │ │ ├── LehmanFast.java │ │ │ ├── LehmanSimple.java │ │ │ └── LehmanSmith.java │ │ ├── pollardRho │ │ │ ├── PollardRho.java │ │ │ ├── PollardRho31.java │ │ │ ├── PollardRhoBrent.java │ │ │ ├── PollardRhoBrent31.java │ │ │ ├── PollardRhoBrentModBlock.java │ │ │ ├── PollardRhoBrentMontgomery32.java │ │ │ ├── PollardRhoBrentMontgomery64.java │ │ │ ├── PollardRhoBrentMontgomery64MH.java │ │ │ ├── PollardRhoBrentMontgomery64MHInlined.java │ │ │ ├── PollardRhoProductGcd.java │ │ │ ├── PollardRhoTwoLoops.java │ │ │ ├── PollardRhoTwoLoops31.java │ │ │ └── PollardRhoTwoLoopsModBlock.java │ │ ├── psiqs │ │ │ ├── PSIQS.java │ │ │ ├── PSIQSBase.java │ │ │ ├── PSIQSThread.java │ │ │ ├── PSIQSThreadBase.java │ │ │ ├── PSIQSThread_SB.java │ │ │ ├── PSIQSThread_SB_U.java │ │ │ ├── PSIQSThread_U.java │ │ │ ├── PSIQSThread_U_3LP.java │ │ │ ├── PSIQSThread_U_nLP.java │ │ │ ├── PSIQS_SB.java │ │ │ ├── PSIQS_SB_U.java │ │ │ ├── PSIQS_U.java │ │ │ ├── PSIQS_U_3LP.java │ │ │ └── PSIQS_U_nLP.java │ │ ├── siqs │ │ │ ├── KnuthSchroeppel.java │ │ │ ├── ModularSqrtsEngine.java │ │ │ ├── SIQS.java │ │ │ ├── SIQSSmall.java │ │ │ ├── data │ │ │ │ ├── BaseArrays.java │ │ │ │ └── SolutionArrays.java │ │ │ ├── poly │ │ │ │ ├── AParamGenerator.java │ │ │ │ ├── AParamGenerator01.java │ │ │ │ ├── AParamGenerator02.java │ │ │ │ ├── PolyReport.java │ │ │ │ ├── SIQSPolyGenerator.java │ │ │ │ └── baseFilter │ │ │ │ │ ├── BaseFilter.java │ │ │ │ │ ├── BaseFilter_q1.java │ │ │ │ │ ├── BaseFilter_q2.java │ │ │ │ │ └── BaseFilter_qk.java │ │ │ ├── powers │ │ │ │ ├── AllPowerFinder.java │ │ │ │ ├── NoPowerFinder.java │ │ │ │ ├── PowerEntry.java │ │ │ │ ├── PowerFinder.java │ │ │ │ ├── PowerOfSmallPrimesFinder.java │ │ │ │ └── SomePowerFinder.java │ │ │ ├── sieve │ │ │ │ ├── BlockSieveUtil.java │ │ │ │ ├── Sieve.java │ │ │ │ ├── Sieve03g.java │ │ │ │ ├── Sieve03gU.java │ │ │ │ ├── Sieve03h.java │ │ │ │ ├── Sieve03hU.java │ │ │ │ ├── SieveParams.java │ │ │ │ ├── SieveParamsFactory01.java │ │ │ │ ├── SieveParamsFactory02.java │ │ │ │ ├── SieveReport.java │ │ │ │ ├── SieveResult.java │ │ │ │ ├── SieveResultDefaultImpl.java │ │ │ │ ├── SimpleSieve.java │ │ │ │ ├── SingleBlockSieve.java │ │ │ │ ├── SingleBlockSieveU.java │ │ │ │ └── SmoothCandidate.java │ │ │ └── tdiv │ │ │ │ ├── TDivReport.java │ │ │ │ ├── TDiv_QS.java │ │ │ │ ├── TDiv_QS_2LP.java │ │ │ │ ├── TDiv_QS_2LP_Full.java │ │ │ │ ├── TDiv_QS_3LP.java │ │ │ │ ├── TDiv_QS_Small.java │ │ │ │ ├── TDiv_QS_nLP.java │ │ │ │ └── TDiv_QS_nLP_Full.java │ │ ├── squfof │ │ │ ├── SquFoF31.java │ │ │ ├── SquFoF31Preload.java │ │ │ └── SquFoF63.java │ │ └── tdiv │ │ │ ├── TDiv.java │ │ │ ├── TDiv31.java │ │ │ ├── TDiv31Barrett.java │ │ │ ├── TDiv31Inverse.java │ │ │ ├── TDiv63.java │ │ │ └── TDiv63Inverse.java │ ├── gaussianInteger │ │ ├── GaussianInteger.java │ │ └── GaussianIntegerConstants.java │ ├── gcd │ │ ├── EEA31.java │ │ ├── EEA63.java │ │ ├── Gcd.java │ │ ├── Gcd31.java │ │ └── Gcd63.java │ ├── hyperbolic │ │ ├── ArcCosH.java │ │ ├── ArcCotH.java │ │ ├── ArcSinH.java │ │ └── ArcTanH.java │ ├── modular │ │ ├── JacobiSymbol.java │ │ ├── LegendreSymbol.java │ │ ├── ModularPower.java │ │ ├── ModularSqrt.java │ │ ├── ModularSqrt31.java │ │ └── ModularSqrtBig.java │ ├── partitions │ │ ├── Generator.java │ │ ├── IntegerPartition.java │ │ ├── IntegerPartitionGenerator.java │ │ ├── Mpi.java │ │ ├── MpiPartition.java │ │ ├── MpiPartitionGenerator.java │ │ ├── MpiPowerMap.java │ │ ├── Mpi_IntegerArrayImpl.java │ │ ├── PrimePowers.java │ │ └── PrimePowers_DefaultImpl.java │ ├── powers │ │ ├── Pow.java │ │ ├── Pow2.java │ │ └── PurePowerTest.java │ ├── precision │ │ ├── Magnitude.java │ │ ├── Precision.java │ │ └── Scale.java │ ├── primes │ │ ├── bounds │ │ │ ├── NthPrimeUpperBounds.java │ │ │ └── PrimeCountUpperBounds.java │ │ ├── exact │ │ │ ├── AutoExpandingPrimesArray.java │ │ │ ├── CollectingCallback.java │ │ │ ├── CountingCallback.java │ │ │ ├── SSOZJ5.java │ │ │ ├── SegmentedSieve.java │ │ │ ├── SieveCallback.java │ │ │ └── SimpleSieve.java │ │ └── probable │ │ │ ├── BPSWTest.java │ │ │ ├── LucasTest.java │ │ │ ├── MillerRabinTest.java │ │ │ ├── PrPTest.java │ │ │ └── TDivPrimeTest.java │ ├── quadraticResidues │ │ ├── QuadraticResidues.java │ │ ├── QuadraticResiduesMod2PowN.java │ │ ├── QuadraticResiduesMod3PowN.java │ │ └── QuadraticResiduesModPPowN.java │ ├── quaternion │ │ ├── HurwitzQuaternion.java │ │ ├── HurwitzQuaternionConstants.java │ │ └── RationalQuaternion.java │ ├── random │ │ ├── LehmerRng64.java │ │ ├── LehmerRng64MH.java │ │ ├── Random64.java │ │ ├── Rng.java │ │ ├── SpRand32.java │ │ ├── SplitMix64.java │ │ ├── Xoroshiro128Plus.java │ │ ├── Xoroshiro256StarStar.java │ │ ├── Xorshf32.java │ │ ├── Xorshift128Plus.java │ │ └── Xorshift64Star.java │ ├── roots │ │ ├── Roots.java │ │ ├── RootsReal.java │ │ ├── SqrtExact.java │ │ ├── SqrtInt.java │ │ └── SqrtReal.java │ ├── sequence │ │ ├── NumberSequence.java │ │ ├── SquarefreeSequence.java │ │ └── SquarefreeSequence63.java │ ├── smooth │ │ ├── CANEntry.java │ │ ├── CANIterator.java │ │ ├── SHCNEntry.java │ │ └── SHCNIterator.java │ ├── squareSums │ │ ├── FourSquaresFinder.java │ │ └── SumOf4Squares.java │ └── transcendental │ │ ├── Agm.java │ │ ├── EulerConstant.java │ │ ├── Exp.java │ │ ├── Ln.java │ │ └── Pi.java │ └── util │ ├── ConfigUtil.java │ ├── Ensure.java │ ├── Multiset.java │ ├── Multiset_HashMapImpl.java │ ├── Pair.java │ ├── ReflectionUtil.java │ ├── SortOrder.java │ ├── SortedList.java │ ├── SortedMultiset.java │ ├── SortedMultiset_BottomUp.java │ ├── SortedMultiset_TopDown.java │ ├── StringUtil.java │ ├── TimeUtil.java │ └── Timer.java └── test ├── java └── de │ └── tilman_neumann │ └── jml │ ├── BinarySearchTest.java │ ├── ChebyshevPolynomialsTest.java │ ├── DivisorsPerformanceTest.java │ ├── DivisorsTest.java │ ├── EgyptianFractionsTriangleDemo.java │ ├── FermatCatalanConjectureTestRunner.java │ ├── HarmonicNumbersTest.java │ ├── MoebiusFunctionTest.java │ ├── base │ ├── BigIntConverterTest.java │ ├── BigRationalTest.java │ ├── Uint128PerformanceTest.java │ ├── Uint128Test.java │ ├── UnsignedBigIntPerformanceTest.java │ └── UnsignedBigIntTest.java │ ├── collatz │ ├── CollatzDroppingSequenceTestRunner.java │ └── CollatzRepeatSequenceTestRunner.java │ ├── combinatorics │ ├── BinomialTest.java │ ├── FactorialPerformanceTest.java │ ├── FactorialTest.java │ ├── FallingFactorialPerformanceTest.java │ ├── FallingFactorialTest.java │ ├── StirlingPerformanceTest.java │ └── StirlingTest.java │ ├── factor │ ├── BatchFactorizer.java │ ├── CombinedFactorAlgorithm1ThreadTest.java │ ├── CombinedFactorAlgorithm2ThreadsTest.java │ ├── FactorSieveDemo.java │ ├── FactorTestBase.java │ ├── FactorizerTest.java │ ├── HardSemiprimeGenerator.java │ ├── TestsetGeneratorTest.java │ ├── cfrac │ │ ├── CFrac63Test.java │ │ ├── CFracRunner.java │ │ └── CFracTest.java │ ├── ecm │ │ ├── BigNbrTest.java │ │ ├── EllipticCurveMethodTest.java │ │ ├── TinyEcm64MHInlinedTest.java │ │ ├── TinyEcm64MHTest.java │ │ └── TinyEcm64Test.java │ ├── hart │ │ ├── HartCongruencesAnalyzer.java │ │ ├── HartFast2Mult2Test.java │ │ ├── HartFast2MultFMATest.java │ │ ├── HartFast2MultTest.java │ │ ├── HartFastTest.java │ │ ├── HartMultiplierChainGenerator.java │ │ ├── HartSimpleTest.java │ │ ├── HartSquareCongruencesAnalyzer.java │ │ ├── HartSquarefreeTest.java │ │ ├── HartTDivRace2Test.java │ │ └── HartTDivRaceTest.java │ ├── lehman │ │ ├── GuardedVsUnguardedSqrtPerformanceTest.java │ │ ├── LehmanCongruencesAnalyzer.java │ │ ├── LehmanCongruencesAnalyzer2.java │ │ ├── LehmanCustomKOrderTest.java │ │ ├── LehmanFastTest.java │ │ ├── LehmanKFactoringMostNAnalyzer.java │ │ ├── LehmanKFactoringSameNAnalyzer.java │ │ ├── LehmanKModsAnalyzer.java │ │ ├── LehmanKProgressionsAnalyzer.java │ │ ├── LehmanKProgressionsAnalyzer2.java │ │ ├── LehmanKStructureAnalyzer.java │ │ ├── LehmanModPowersOf2Analyzer.java │ │ ├── LehmanSimpleTest.java │ │ ├── LehmanSmithTest.java │ │ └── LehmanSpecialArgumentsAnalyzer.java │ ├── pollardRho │ │ ├── PollardRho31Test.java │ │ ├── PollardRhoBrent31Runner.java │ │ ├── PollardRhoBrent31Test.java │ │ ├── PollardRhoBrentModBlockTest.java │ │ ├── PollardRhoBrentMontgomery32Test.java │ │ ├── PollardRhoBrentMontgomery64MHInlinedRunner.java │ │ ├── PollardRhoBrentMontgomery64MHInlinedTest.java │ │ ├── PollardRhoBrentMontgomery64MHRunner.java │ │ ├── PollardRhoBrentMontgomery64MHTest.java │ │ ├── PollardRhoBrentMontgomery64Runner.java │ │ ├── PollardRhoBrentMontgomery64Test.java │ │ ├── PollardRhoBrentRunner.java │ │ ├── PollardRhoBrentTest.java │ │ ├── PollardRhoTest.java │ │ ├── PollardRhoTwoLoopsModBlockTest.java │ │ └── PollardRhoTwoLoopsTest.java │ ├── psiqs │ │ ├── PSIQS_Runner.java │ │ ├── PSIQS_SB_Runner.java │ │ ├── PSIQS_SB_U_Runner.java │ │ ├── PSIQS_U_3LP_Runner.java │ │ ├── PSIQS_U_Runner.java │ │ └── PSIQS_U_nLP_Runner.java │ ├── siqs │ │ ├── SIQSRunner.java │ │ ├── SIQSSmallRunner.java │ │ ├── SIQSSmallTest.java │ │ ├── SIQSTest.java │ │ └── poly │ │ │ └── BParamTest.java │ ├── squfof │ │ ├── SquFoF31PreloadTest.java │ │ ├── SquFoF31Test.java │ │ └── SquFoF63Test.java │ └── tdiv │ │ ├── TDiv31BarrettTest.java │ │ ├── TDiv31InverseTest.java │ │ ├── TDiv31Test.java │ │ ├── TDiv63InverseTest.java │ │ ├── TDiv63Test.java │ │ └── TDivTest.java │ ├── gaussianInteger │ └── GaussianIntegerTest.java │ ├── modular │ ├── JacobiSymbolPerformanceTest.java │ ├── JacobiSymbolTest.java │ ├── ModularSqrtPerformanceTest.java │ └── ModularSqrtTest.java │ ├── partitions │ ├── IntegerPartitionGeneratorRunner.java │ ├── MpiPartitionCountCoverageAnalyzer.java │ ├── MpiPartitionGeneratorRunner.java │ ├── MpiPartitionGeneratorTest.java │ └── MpiPowerMapHypothesisTest.java │ ├── powers │ ├── PurePowerTestPerformanceTest.java │ ├── PurePowerTestRunner.java │ └── PurePowerTestTest.java │ ├── precision │ ├── MagnitudeTest.java │ └── PrecisionTest.java │ ├── primes │ ├── PrimeCountsBetweenSquaresAnalyzer.java │ ├── PrimeGapAnalyzer.java │ ├── RiemannLagariasHypothesisAnalyzer.java │ ├── RiemannRobinHypothesisAnalyzer.java │ ├── bounds │ │ ├── NthPrimeUpperBoundsTest.java │ │ └── PrimeCountUpperBoundsTest.java │ ├── exact │ │ ├── AutoExpandingPrimesArrayPerformanceTest.java │ │ ├── SSOZJ5Runner.java │ │ ├── SegmentedSievePerformanceTest.java │ │ ├── SieveTest.java │ │ └── SimpleSievePerformanceTest.java │ └── probable │ │ ├── NextProbablePrimePerformanceTest.java │ │ └── NextProbablePrimeTest.java │ ├── quadraticResidues │ ├── QuadraticResiduesMod2PowNPerformanceTest.java │ ├── QuadraticResiduesMod2PowNTest.java │ ├── QuadraticResiduesMod3PowNPerformanceTest.java │ ├── QuadraticResiduesMod3PowNTest.java │ ├── QuadraticResiduesModPPowNPerformanceTest.java │ ├── QuadraticResiduesModPPowNTest.java │ └── QuadraticResiduesTest.java │ ├── quaternion │ ├── HurwitzQuaternionTest.java │ └── RationalQuaternionTest.java │ ├── random │ ├── LehmerRng64MHTest.java │ ├── LehmerRng64Test.java │ ├── RngPerformanceTest.java │ ├── RngTest.java │ ├── SecureRandomTest.java │ ├── SpRand32Test.java │ ├── SplitMix64Test.java │ ├── Xoroshiro128PlusTest.java │ ├── Xoroshiro256StarStarTest.java │ ├── Xorshf32Test.java │ ├── Xorshift128PlusTest.java │ └── Xorshift64StarTest.java │ ├── roots │ ├── RootsPerformanceTest.java │ ├── RootsRealRunner.java │ ├── RootsTest.java │ ├── SqrtExactPerformanceTest.java │ ├── SqrtExactTest.java │ ├── SqrtIntPerformanceTest.java │ ├── SqrtIntTest.java │ ├── SqrtRealRunner.java │ ├── SqrtRealTest.java │ └── SquareRestAnalyzer.java │ ├── sequence │ └── SquarefreeSequencePerformanceTest.java │ ├── smooth │ ├── CANTest.java │ └── SHCNTest.java │ ├── squareSums │ ├── FourSquaresFinderRunner.java │ ├── FourSquaresFinderTest.java │ ├── SumOf4SquaresPerformanceTest.java │ └── SumOf4SquaresTest.java │ └── transcendental │ ├── AgmRunner.java │ ├── EulerConstantPerformanceTest.java │ ├── ExpRunner.java │ ├── ExpTest.java │ ├── LnRunner.java │ └── PiPerformanceTest.java └── resources └── factor └── qaTests.txt /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven 3 | 4 | # This workflow uses actions that are not certified by GitHub. 5 | # They are provided by a third-party and are governed by 6 | # separate terms of service, privacy policy, and support 7 | # documentation. 8 | 9 | name: Java CI with Maven 10 | 11 | on: 12 | push: 13 | branches: [ "master" ] 14 | pull_request: 15 | branches: [ "master" ] 16 | 17 | jobs: 18 | build: 19 | 20 | runs-on: ubuntu-latest 21 | timeout-minutes: 30 22 | 23 | steps: 24 | - uses: actions/checkout@v4 25 | - name: Set up JDK 11 26 | uses: actions/setup-java@v4 27 | with: 28 | java-version: '11' 29 | distribution: 'temurin' 30 | cache: maven 31 | - name: Build with Maven 32 | run: mvn -B package --file pom.xml 33 | 34 | - name: Report 35 | uses: dorny/test-reporter@v1 36 | if: always() 37 | with: 38 | name: Maven Tests 39 | path: target/surefire-reports/*.xml 40 | reporter: java-junit 41 | fail-on-error: true 42 | 43 | # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive 44 | - name: Update dependency graph 45 | uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | /target/ 3 | /.settings/ 4 | .classpath 5 | .project 6 | log.txt 7 | -------------------------------------------------------------------------------- /conf/log4j2-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /lib/log4j-api-2.24.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TilmanNeumann/java-math-library/79dbb1c74886fe299bb218b32e85ec890d339950/lib/log4j-api-2.24.3.jar -------------------------------------------------------------------------------- /lib/log4j-core-2.24.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TilmanNeumann/java-math-library/79dbb1c74886fe299bb218b32e85ec890d339950/lib/log4j-core-2.24.3.jar -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/base/BigDecimalConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.base; 15 | 16 | import java.math.BigDecimal; 17 | 18 | public class BigDecimalConstants { 19 | 20 | public static final BigDecimal F_0 = BigDecimal.ZERO; 21 | public static final BigDecimal F_0_5 = new BigDecimal("0.5"); 22 | public static final BigDecimal F_1 = BigDecimal.ONE; 23 | public static final BigDecimal F_2 = BigDecimal.valueOf(2); 24 | public static final BigDecimal F_2_5 = new BigDecimal("2.5"); 25 | public static final BigDecimal F_3 = BigDecimal.valueOf(3); 26 | public static final BigDecimal F_4 = BigDecimal.valueOf(4); 27 | public static final BigDecimal F_5 = BigDecimal.valueOf(5); 28 | public static final BigDecimal F_8 = BigDecimal.valueOf(8); 29 | public static final BigDecimal F_10 = BigDecimal.TEN; 30 | public static final BigDecimal F_12 = BigDecimal.valueOf(12); 31 | public static final BigDecimal F_16 = BigDecimal.valueOf(16); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/base/BigIntGrid.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.base; 15 | 16 | import java.math.BigInteger; 17 | 18 | /** 19 | * A two-dimensional grid of big integers. 20 | * 21 | * @author Tilman Neumann 22 | */ 23 | public class BigIntGrid extends NumberGrid { 24 | 25 | private static final long serialVersionUID = 9189914650661627444L; 26 | 27 | /** 28 | * Simplified constructor with offsets 1. 29 | * 30 | * @param xLabel The letter to use for the x-axis 31 | * @param xStart The start value for the x-axis-values 32 | * @param yLabel The letter to use for the y-axis 33 | * @param yStart The start value for the y-axis-values 34 | */ 35 | public BigIntGrid(String xLabel, int xStart, String yLabel, int yStart) { 36 | super(xLabel, xStart, yLabel, yStart); 37 | } 38 | 39 | /** 40 | * Full constructor with all options. 41 | * 42 | * @param xLabel The letter to use for the x-axis 43 | * @param xStart The start value for the x-axis-values 44 | * @param xIncrement The increment for the x-axis-values 45 | * @param yLabel The letter to use for the y-axis 46 | * @param yStart The start value for the y-axis-values 47 | * @param yIncrement The increment for the y-axis-values 48 | */ 49 | public BigIntGrid(String xLabel, int xStart, int xIncrement, String yLabel, int yStart, int yIncrement) { 50 | super(xLabel, xStart, xIncrement, yLabel, yStart, yIncrement); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/base/IntCollectionUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.base; 15 | 16 | import java.util.ArrayList; 17 | import java.util.Collection; 18 | import java.util.StringTokenizer; 19 | 20 | /** 21 | * Utility methods for collections of Integers. 22 | * 23 | * @author Tilman Neumann 24 | */ 25 | public class IntCollectionUtil { 26 | 27 | /** 28 | * Converts the given comma-separated string into a list of Integers. 29 | * @param str 30 | * @return list of sequence elements 31 | */ 32 | public static ArrayList stringToList(String str) { 33 | ArrayList list = new ArrayList<>(); 34 | if (str!=null) { 35 | StringTokenizer tokenizer = new StringTokenizer(str.trim(), ","); 36 | while (tokenizer.hasMoreTokens()) { 37 | String token = tokenizer.nextToken().trim(); 38 | try { 39 | list.add(Integer.decode(token)); 40 | } catch (NumberFormatException nfe) { 41 | throw new IllegalArgumentException("str contains illegal value '" + token + "'"); 42 | } 43 | } 44 | } 45 | return list; 46 | } 47 | 48 | /** 49 | * Returns the maximum value of the given non-negative integer collection. 50 | * @param c the collection (not null) 51 | * @return the biggest element, or 0 if the collection is empty 52 | */ 53 | public static int max(Collection c) { 54 | int result = 0; 55 | for (int elem : c) { 56 | if (elem>result) result = elem; 57 | } 58 | return result; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/combinatorics/HyperFactorial.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.combinatorics; 15 | 16 | import java.math.BigInteger; 17 | 18 | import static de.tilman_neumann.jml.base.BigIntConstants.*; 19 | 20 | /** 21 | * Hyperfactorials. 22 | * 23 | * @author Tilman Neumann 24 | */ 25 | public class HyperFactorial { 26 | /** 27 | * A002109 or the standard "hyperfactorial" is the product {1^1*2^2*..n^n}. 28 | * @param n 29 | * @return hyperfactorial(n) 30 | */ 31 | public static BigInteger standard(int n) { 32 | BigInteger result = I_1; 33 | for (int k=2; k<=n; k++) { 34 | result = result.multiply(BigInteger.valueOf(k).pow(k)); 35 | } 36 | return result; 37 | } 38 | 39 | /** 40 | * A000197 or what I call the "inverse hyperfactorial" is the product 41 | * 1^n*2^(n-1)*..*(n-1)^2*n^1 = 1!*2!*3!*...(n-1)!*n!. 42 | * @param n 43 | * @return the "inverse hyperfactorial" of n aka 1!*2!*3!*...(n-1)!*n! 44 | */ 45 | public static BigInteger inverse(int n) { 46 | BigInteger result = I_1; 47 | BigInteger kFactorial = I_1; 48 | for (int k=2; k<=n; k++) { 49 | kFactorial = kFactorial.multiply(BigInteger.valueOf(k)); 50 | result = result.multiply(kFactorial); 51 | } 52 | return result; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/combinatorics/Multinomial.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.combinatorics; 15 | 16 | import java.math.BigInteger; 17 | 18 | /** 19 | * Multinomial coefficient implementations. 20 | * 21 | * @author Tilman Neumann 22 | */ 23 | public class Multinomial { 24 | 25 | /** 26 | * Multinomial coefficient. 27 | * 28 | * @param N Category counts. 29 | * @return (N1+...+Nk) choose (N1, ..., Nk) 30 | */ 31 | public static BigInteger multinomial(int N[]) { 32 | // get dimension 33 | int k = N.length; 34 | 35 | // get total count 36 | int Nall = 0; 37 | for (int i = 0; i. 13 | */ 14 | package de.tilman_neumann.jml.factor; 15 | 16 | import java.math.BigInteger; 17 | 18 | /** 19 | * An exception indicating that a factor was found. 20 | * 21 | * @author Tilman Neumann 22 | */ 23 | public class FactorException extends Exception { 24 | private static final long serialVersionUID = -6623862851940555652L; 25 | 26 | private BigInteger factor = null; 27 | 28 | /** 29 | * Complete constructor. 30 | * @param factor 31 | */ 32 | public FactorException(BigInteger factor) { 33 | this.factor = factor; 34 | } 35 | 36 | /** 37 | * @return factor 38 | */ 39 | public BigInteger getFactor() { 40 | return this.factor; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/TestNumberNature.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor; 15 | 16 | /** 17 | * Definition of the "nature" of test numbers. 18 | * @author Tilman Neumann 19 | */ 20 | public enum TestNumberNature { 21 | /** 22 | * Arbitrary random composite numbers N chosen from a certain bit length. 23 | * Note that there are no such numbers with less than 3 bits. 24 | */ 25 | RANDOM_COMPOSITES, 26 | 27 | /** 28 | * Random odd composite numbers N chosen from a certain bit length. 29 | * Note that there are no such numbers with less than 4 bits. 30 | */ 31 | RANDOM_ODD_COMPOSITES, 32 | 33 | /** 34 | * Odd semiprimes N=a*b with min(a,b) >= cbrt(N). 35 | * Note that there are no such numbers with less than 4 bits. 36 | */ 37 | MODERATE_SEMIPRIMES, 38 | 39 | /** 40 | * Odd semiprimes N=a*b with bitLength(min(a,b)) == bitLength(N)/2 - 1 bits. 41 | */ 42 | QUITE_HARD_SEMIPRIMES 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/base/FactorArguments.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2020 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.base; 15 | 16 | import java.math.BigInteger; 17 | 18 | public class FactorArguments { 19 | /** The number to factor */ 20 | public BigInteger N; 21 | 22 | /** The number of bits of N */ 23 | public int NBits; 24 | 25 | /** The exponent of N */ 26 | public int exp; 27 | 28 | /** 29 | * Full constructor. 30 | * @param N the number to factor 31 | * @param exp the exponent of N 32 | */ 33 | public FactorArguments(BigInteger N, int exp) { 34 | this.N = N; 35 | this.NBits = N.bitLength(); 36 | this.exp = exp; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/base/GlobalFactoringOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.base; 15 | 16 | /** 17 | * Global factoring settings. 18 | * 19 | * Code "guarded" with a static final boolean = false will be removed by the compiler. 20 | * Thus if turned off, such code does not decrement performance at all. 21 | * 22 | * @author Tilman Neumann 23 | */ 24 | public interface GlobalFactoringOptions { 25 | /** 26 | * Basic analysis of timings and operations. This option is used by most or all factoring algorithms that collect relations. 27 | * In SIQS, the analysis includes number of polynomials, number of smooth and partial relations (also by large factor counts), 28 | * trials division results, solver runs and tested null-vectors, and sub-phase timings. 29 | */ 30 | static final boolean ANALYZE = false; 31 | 32 | /** 33 | * Monitor the congruence collecting progress on-the-fly. 34 | * This option needs ANALYZE as well. 35 | */ 36 | static final boolean ANALYZE_PROGRESS = false; 37 | 38 | /** 39 | * A switch to additionally turn on analysis of the size of large factors that yield smooth relations. 40 | * This option needs ANALYZE as well. 41 | */ 42 | static final boolean ANALYZE_LARGE_FACTOR_SIZES = false; 43 | 44 | /** 45 | * A switch to additionally turn on analysis of the number of Q-values with positive and negative sign. 46 | * This option needs ANALYZE as well. 47 | */ 48 | static final boolean ANALYZE_Q_SIGNS = false; 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/base/IntHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.base; 15 | 16 | /** 17 | * Class for holding counts. A holder class is better performance-wise than mapping counts as integers 18 | * since increments/decrements don't need to be remapped. 19 | * 20 | * @author David McGuigan 21 | */ 22 | public class IntHolder { 23 | public int value; 24 | 25 | public IntHolder(int v) { 26 | value = v; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/base/congruence/CycleCounter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2021 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.base.congruence; 15 | 16 | import java.util.HashSet; 17 | 18 | /** 19 | * Interface for cycle counting algorithms. 20 | * @author Till 21 | * 22 | * @see [LLDMW02] Leyland, Lenstra, Dodson, Muffett, Wagstaff 2002: "MPQS with three large primes", Lecture Notes in Computer Science, 2369. 23 | * @see [LM94] Lenstra, Manasse 1994: "Factoring With Two Large Primes", Mathematics of Computation, volume 63, number 208, page 789. 24 | */ 25 | public interface CycleCounter { 26 | 27 | /** Initialize this cycle counter for a new factor argument. */ 28 | void initializeForN(); 29 | 30 | /** 31 | * Counts the number of independent cycles in the partial relations. 32 | * 33 | * @param partial the newest partial relation to add 34 | * @param correctSmoothCount the correct number of smooths from partials (only for debugging) 35 | * @return the updated number of smooths from partials 36 | */ 37 | int addPartial(Partial partial, int correctSmoothCount); 38 | 39 | /** 40 | * @return the partial relations found so far 41 | */ 42 | HashSet getPartialRelations(); 43 | 44 | /** 45 | * @return number of partial relations found so far. 46 | */ 47 | int getPartialRelationsCount(); 48 | 49 | /** 50 | * @return the number of cycles counted by this algorithm 51 | */ 52 | int getCycleCount(); 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/base/congruence/Partial.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.base.congruence; 15 | 16 | import java.math.BigInteger; 17 | 18 | import de.tilman_neumann.jml.factor.base.SortedIntegerArray; 19 | 20 | /** 21 | * Base class for partial congruences. 22 | * The matrix elements of a partial congruence are the large factors appearing with odd exponent. 23 | * 24 | * @author Tilman Neumann 25 | */ 26 | abstract public class Partial extends AQPair { 27 | 28 | /** 29 | * Full constructor. 30 | * @param A 31 | * @param smallFactors small factors of Q 32 | */ 33 | public Partial(BigInteger A, SortedIntegerArray smallFactors) { 34 | super(A, smallFactors); 35 | } 36 | 37 | /** 38 | * @return the large factors appearing with odd exponent. 39 | */ 40 | abstract public Long[] getLargeFactorsWithOddExponent(); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/base/congruence/Partial1Large.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.base.congruence; 15 | 16 | import java.math.BigInteger; 17 | 18 | import de.tilman_neumann.jml.factor.base.SortedIntegerArray; 19 | import de.tilman_neumann.util.SortedMultiset; 20 | 21 | /** 22 | * A partial congruence having 1 large factor. 23 | * 24 | * @author Tilman Neumann 25 | */ 26 | public class Partial1Large extends Partial { 27 | 28 | private long bigFactor; // needs 8 byte instead of 56 byte for a Long[1] 29 | 30 | /** 31 | * Full constructor. 32 | * @param A 33 | * @param smallFactors small factors of Q 34 | * @param bigFactor the single large factor of Q 35 | */ 36 | public Partial1Large(BigInteger A, SortedIntegerArray smallFactors, long bigFactor) { 37 | super(A, smallFactors); 38 | // only 1 large factor 39 | this.bigFactor = bigFactor; 40 | } 41 | 42 | @Override 43 | public SortedMultiset getAllQFactors() { 44 | // get small factors of Q 45 | SortedMultiset allFactors = super.getSmallQFactors(); 46 | // add single large factor 47 | allFactors.add(bigFactor); 48 | return allFactors; 49 | } 50 | 51 | @Override 52 | public Long[] getLargeFactorsWithOddExponent() { 53 | return new Long[] {bigFactor}; 54 | } 55 | 56 | @Override 57 | public int getNumberOfLargeQFactors() { 58 | return 1; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/base/congruence/PartialSolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.base.congruence; 15 | 16 | import java.util.Collection; 17 | 18 | /** 19 | * Interface for solvers used to find smooth from partial relations. 20 | * 21 | * @author Tilman Neumann 22 | */ 23 | public interface PartialSolver { 24 | 25 | /** 26 | * @return the name of the algorithm 27 | */ 28 | String getName(); 29 | 30 | /** Initialize this partial solver for a new factor argument. */ 31 | void initializeForN(); 32 | 33 | /** 34 | * Solve a partial congruence equation system. 35 | * @param congruences the partial congruence equation system 36 | * @return list of smooth congruences found 37 | */ 38 | Smooth solve(Collection congruences); 39 | 40 | /** 41 | * @return the size of the biggest partial matrix found for some N 42 | */ 43 | int getMaxMatrixSize(); 44 | 45 | /** 46 | * Release memory after a factorization. 47 | */ 48 | void cleanUp(); 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/base/congruence/Smooth.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.base.congruence; 15 | 16 | import java.util.Set; 17 | 18 | /** 19 | * A smooth congruence. 20 | * The matrix elements of a smooth congruence are the small factors appearing with odd exponent. 21 | * 22 | * @author Tilman Neumann 23 | */ 24 | public interface Smooth { 25 | 26 | /** 27 | * Test if the Q of this smooth congruence is an exact square. 28 | * Since smooth congruences can not have non-square large Q-factors, only the small Q-factors need to be checked. 29 | * 30 | * @return true if Q is square 31 | */ 32 | boolean isExactSquare(); 33 | 34 | /** 35 | * @return set matrix elements. For a smooth relation these are the small factors appearing with odd exponent. 36 | */ 37 | Integer[] getMatrixElements(); 38 | 39 | /** 40 | * @return the set of AQPairs this smooth relation consists of 41 | */ 42 | Set getAQPairs(); 43 | 44 | /** 45 | * Add this's AQPairs to the target set via xor. 46 | * This operation permits to get around without creating new array objects 47 | * for all those congruence sub-classes that represent just a single AQPair. 48 | * 49 | * @param targetSet 50 | */ 51 | void addMyAQPairsViaXor(Set targetSet); 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/base/congruence/Smooth1LargeSquare.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.base.congruence; 15 | 16 | import java.math.BigInteger; 17 | 18 | import de.tilman_neumann.jml.factor.base.SortedIntegerArray; 19 | import de.tilman_neumann.util.SortedMultiset; 20 | 21 | /** 22 | * A smooth congruence with 1 large factor contained as a square. 23 | * 24 | * @author Tilman Neumann 25 | */ 26 | public class Smooth1LargeSquare extends SmoothSimple { 27 | 28 | /** the large factor contained as a square */ 29 | private long bigFactor; 30 | 31 | /** 32 | * Full constructor. 33 | * @param A 34 | * @param smallFactors small factors of Q 35 | * @param bigFactor the single large factor of Q contained as square 36 | */ 37 | public Smooth1LargeSquare(BigInteger A, SortedIntegerArray smallFactors, long bigFactor) { 38 | super(A, smallFactors); 39 | // the large factor contained as a square 40 | this.bigFactor = bigFactor; 41 | } 42 | 43 | @Override 44 | public SortedMultiset getAllQFactors() { 45 | // get small factors of Q 46 | SortedMultiset allFactors = super.getSmallQFactors(); 47 | // add single large factor square 48 | allFactors.add(bigFactor, 2); 49 | return allFactors; 50 | } 51 | 52 | @Override 53 | public int getNumberOfLargeQFactors() { 54 | return 2; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/base/congruence/SmoothNLargeSquares.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.base.congruence; 15 | 16 | import java.math.BigInteger; 17 | 18 | import de.tilman_neumann.jml.factor.base.SortedIntegerArray; 19 | import de.tilman_neumann.jml.factor.base.SortedLongArray; 20 | import de.tilman_neumann.util.SortedMultiset; 21 | 22 | /** 23 | * A smooth congruence having an arbitrary number of large factors. 24 | * 25 | * @author Tilman Neumann 26 | */ 27 | public class SmoothNLargeSquares extends SmoothSimple { 28 | 29 | private long[] bigFactors; 30 | private byte[] bigFactorExponents; 31 | 32 | /** 33 | * Full constructor. 34 | * @param A 35 | * @param smallFactors small factors of Q 36 | * @param bigFactors large factors of Q 37 | */ 38 | public SmoothNLargeSquares(BigInteger A, SortedIntegerArray smallFactors, SortedLongArray bigFactors) { 39 | super(A, smallFactors); 40 | // copy big factors of Q 41 | this.bigFactors = bigFactors.copyFactors(); 42 | this.bigFactorExponents = bigFactors.copyExponents(); 43 | } 44 | 45 | @Override 46 | public SortedMultiset getAllQFactors() { 47 | // get small factors of Q 48 | SortedMultiset allFactors = super.getSmallQFactors(); 49 | // add large factors 50 | for (int i=0; i. 13 | */ 14 | package de.tilman_neumann.jml.factor.base.congruence; 15 | 16 | import java.math.BigInteger; 17 | 18 | import de.tilman_neumann.jml.factor.base.SortedIntegerArray; 19 | import de.tilman_neumann.util.SortedMultiset; 20 | 21 | /** 22 | * A perfect smooth congruence. 23 | * @author Tilman Neumann 24 | */ 25 | public class SmoothPerfect extends SmoothSimple { 26 | 27 | /** 28 | * Full constructor. 29 | * @param A 30 | * @param smallFactors small factors of Q 31 | */ 32 | public SmoothPerfect(BigInteger A, SortedIntegerArray smallFactors) { 33 | super(A, smallFactors); 34 | } 35 | 36 | @Override 37 | public SortedMultiset getAllQFactors() { 38 | // a perfect smooth congruence has no large factors 39 | return super.getSmallQFactors(); 40 | } 41 | 42 | @Override 43 | public int getNumberOfLargeQFactors() { 44 | return 0; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/base/congruence/SmoothSimple.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.base.congruence; 15 | 16 | import java.math.BigInteger; 17 | import java.util.HashSet; 18 | import java.util.Set; 19 | 20 | import de.tilman_neumann.jml.factor.base.SortedIntegerArray; 21 | 22 | /** 23 | * A smooth congruence from a single AQ-pair. 24 | * @author Tilman Neumann 25 | */ 26 | abstract public class SmoothSimple extends AQPair implements Smooth { 27 | 28 | private Integer[] oddExpElements; 29 | 30 | public SmoothSimple(BigInteger A, SortedIntegerArray smallFactors) { 31 | super(A, smallFactors); 32 | // determine small factors with odd exponents: first we need a set to eliminate duplicates. 33 | Set result = new HashSet(); 34 | for (int i=0; i getAQPairs() { 43 | Set set = new HashSet<>(); 44 | set.add(this); 45 | return set; 46 | } 47 | 48 | @Override 49 | public void addMyAQPairsViaXor(Set targetSet) { 50 | if (!targetSet.remove(this)) targetSet.add(this); 51 | } 52 | 53 | @Override 54 | public Integer[] getMatrixElements() { 55 | return oddExpElements; 56 | } 57 | 58 | @Override 59 | public boolean isExactSquare() { 60 | return oddExpElements.length==0; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/base/matrixSolver/FactorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.base.matrixSolver; 15 | 16 | import java.util.Set; 17 | 18 | import de.tilman_neumann.jml.factor.FactorException; 19 | import de.tilman_neumann.jml.factor.base.congruence.AQPair; 20 | 21 | /** 22 | * Interface for final factor tests when a square congruence A^2 == Q (mod kN) has been found. 23 | * The congruence may be improper though... 24 | * 25 | * @author Tilman Neumann 26 | */ 27 | public interface FactorTest { 28 | 29 | /** 30 | * @return the algorithm name 31 | */ 32 | String getName(); 33 | 34 | /** 35 | * Test if a square congruence A^2 == Q (mod kN) gives a factor of N. 36 | * 37 | * @param aqPairs 38 | * @throws FactorException 39 | */ 40 | void testForFactor(Set aqPairs) throws FactorException; 41 | } -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/base/matrixSolver/MatrixSolverBase03.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.base.matrixSolver; 15 | 16 | import java.util.Arrays; 17 | import java.util.List; 18 | 19 | import de.tilman_neumann.jml.factor.base.congruence.Smooth; 20 | import de.tilman_neumann.jml.factor.base.matrixSolver.util.CompareCongruence; 21 | 22 | /** 23 | * Base implementation for a congruence equation system (the "LinAlg phase matrix") solver. 24 | * Much faster than the first version due to great improvements by Dave McGuigan. 25 | * 26 | * @author Tilman Neumann, Dave McGuigan 27 | */ 28 | abstract public class MatrixSolverBase03 extends MatrixSolverBase02 { 29 | 30 | /** 31 | * Sort smooths be smallest number of column bits set 32 | */ 33 | @Override 34 | protected void sortSmooths(List list) { 35 | Object[] ns = list.toArray(); 36 | Arrays.sort(ns, new CompareCongruence()); 37 | list.clear(); 38 | for (Object o : ns) { 39 | Smooth s = (Smooth)o; 40 | list.add(s); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/base/matrixSolver/util/CompareCongruence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.base.matrixSolver.util; 15 | 16 | import java.util.Comparator; 17 | 18 | import de.tilman_neumann.jml.factor.base.congruence.Smooth; 19 | 20 | /** 21 | * @author David McGuigan 22 | */ 23 | public class CompareCongruence implements Comparator { 24 | @Override 25 | public int compare(Object o1, Object o2) { 26 | Smooth s1 = (Smooth)o1; 27 | Smooth s2 = (Smooth)o2; 28 | return s1.getMatrixElements().length-s2.getMatrixElements().length; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/base/matrixSolver/util/CompareEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.base.matrixSolver.util; 15 | 16 | import java.util.Comparator; 17 | import java.util.Map.Entry; 18 | 19 | import de.tilman_neumann.jml.factor.base.IntHolder; 20 | 21 | /** 22 | * @author David McGuigan 23 | */ 24 | public class CompareEntry implements Comparator { 25 | @Override 26 | public int compare(Object o1, Object o2) { 27 | @SuppressWarnings("unchecked") 28 | Entry e1 = (Entry)o1; 29 | @SuppressWarnings("unchecked") 30 | Entry e2 = (Entry)o2; 31 | return e2.getValue().value-e1.getValue().value; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/base/matrixSolver/util/StackEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.base.matrixSolver.util; 15 | 16 | /** 17 | * @author David McGuigan 18 | * @param T the class of stack entries 19 | */ 20 | public class StackEntry { 21 | public T congruence; 22 | public int currentPrimeIndex; 23 | public StackEntry(T congruence, int currentPrimeIndex) { 24 | this.congruence = congruence; 25 | this.currentPrimeIndex = currentPrimeIndex; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/cfrac/tdiv/TDiv_CF.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.cfrac.tdiv; 15 | 16 | import java.math.BigInteger; 17 | 18 | import de.tilman_neumann.jml.factor.base.congruence.AQPair; 19 | 20 | /** 21 | * Interface for auxiliary factor algorithms to find smooth decompositions of Q's. 22 | * @author Tilman Neumann 23 | */ 24 | public interface TDiv_CF { 25 | 26 | /** 27 | * @return the name of this algorithm 28 | */ 29 | public String getName(); 30 | 31 | /** 32 | * Initialize for a new N. 33 | * @param N 34 | * @param smoothBound 35 | */ 36 | public void initialize(BigInteger N, double smoothBound); 37 | 38 | /** 39 | * Initialize this factorizer for a new k; in particular set the prime base to be used for trial division. 40 | * @param kN 41 | * @param primeBaseSize the true prime base size (the arrays are preallocated with a bigger length) 42 | * @param primesArray prime base in ints 43 | */ 44 | public void initialize(BigInteger kN, int primeBaseSize, int[] primesArray); 45 | 46 | /** 47 | * Check if Q is smooth (factors completely over the prime base) or "sufficiently smooth" (factors almost over the prime base). 48 | * 49 | * @param A 50 | * @param Q 51 | * @return an AQ-pair if Q is at least "sufficiently smooth", null else 52 | */ 53 | public AQPair test(BigInteger A, BigInteger Q); 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/cfrac/tdiv/TDiv_CF63.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.cfrac.tdiv; 15 | 16 | import java.math.BigInteger; 17 | 18 | import de.tilman_neumann.jml.factor.base.congruence.AQPair; 19 | 20 | /** 21 | * Interface for auxiliary factor algorithms to find smooth decompositions of Q's. 22 | * @author Tilman Neumann 23 | */ 24 | public interface TDiv_CF63 { 25 | 26 | /** 27 | * @return the name of this algorithm 28 | */ 29 | public String getName(); 30 | 31 | /** 32 | * Initialize for a new N. 33 | * @param N 34 | * @param smoothBound 35 | */ 36 | public void initialize(BigInteger N, double smoothBound); 37 | 38 | /** 39 | * Initialize this factorizer for a new k; in particular set the prime base to be used for trial division. 40 | * @param kN 41 | * @param primeBaseSize the true prime base size (the arrays are preallocated with a bigger length) 42 | * @param primesArray prime base in ints 43 | */ 44 | public void initialize(BigInteger kN, int primeBaseSize, int[] primesArray); 45 | 46 | /** 47 | * Check if Q is smooth (factors completely over the prime base) or "sufficiently smooth" (factors almost over the prime base). 48 | * 49 | * @param A 50 | * @param Q 51 | * @return an AQ-pair if Q is at least "sufficiently smooth", null else 52 | */ 53 | public AQPair test(BigInteger A, long Q); 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/psiqs/PSIQSThread.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.psiqs; 15 | 16 | import java.math.BigInteger; 17 | 18 | import de.tilman_neumann.jml.factor.base.congruence.CongruenceCollector; 19 | import de.tilman_neumann.jml.factor.siqs.data.BaseArrays; 20 | import de.tilman_neumann.jml.factor.siqs.poly.AParamGenerator; 21 | import de.tilman_neumann.jml.factor.siqs.poly.SIQSPolyGenerator; 22 | import de.tilman_neumann.jml.factor.siqs.sieve.Sieve03h; 23 | import de.tilman_neumann.jml.factor.siqs.sieve.SieveParams; 24 | import de.tilman_neumann.jml.factor.siqs.tdiv.TDiv_QS_2LP; 25 | 26 | /** 27 | * A polynomial generation/sieve/trial division thread using the fastest sieve not depending on sun.misc.Unsafe. 28 | * @author Tilman Neumann 29 | */ 30 | public class PSIQSThread extends PSIQSThreadBase { 31 | 32 | /** 33 | * Standard constructor. 34 | * @param k 35 | * @param N 36 | * @param kN 37 | * @param d the d-parameter of quadratic polynomials Q(x) = (d*a*x + b)^2 - kN; typically 1 or 2 38 | * @param sieveParams basic sieve parameters 39 | * @param baseArrays primes, power arrays after adding powers 40 | * @param apg 41 | * @param cc congruence collector, also runs the matrix solver 42 | * @param threadIndex 43 | */ 44 | public PSIQSThread( 45 | int k, BigInteger N, BigInteger kN, int d, SieveParams sieveParams, BaseArrays baseArrays, 46 | AParamGenerator apg, CongruenceCollector cc, int threadIndex) { 47 | 48 | super(k, N, kN, d, sieveParams, baseArrays, apg, new SIQSPolyGenerator(), new Sieve03h(), 49 | new TDiv_QS_2LP(false), cc, threadIndex); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/psiqs/PSIQSThread_SB.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.psiqs; 15 | 16 | import java.math.BigInteger; 17 | 18 | import de.tilman_neumann.jml.factor.base.congruence.CongruenceCollector; 19 | import de.tilman_neumann.jml.factor.siqs.data.BaseArrays; 20 | import de.tilman_neumann.jml.factor.siqs.poly.AParamGenerator; 21 | import de.tilman_neumann.jml.factor.siqs.poly.SIQSPolyGenerator; 22 | import de.tilman_neumann.jml.factor.siqs.sieve.SieveParams; 23 | import de.tilman_neumann.jml.factor.siqs.sieve.SingleBlockSieve; 24 | import de.tilman_neumann.jml.factor.siqs.tdiv.TDiv_QS_2LP; 25 | 26 | /** 27 | * A polynomial generation/sieve/trial division thread using the fastest sieve not depending on sun.misc.Unsafe. 28 | * @author Tilman Neumann 29 | */ 30 | public class PSIQSThread_SB extends PSIQSThreadBase { 31 | 32 | /** 33 | * Standard constructor. 34 | * @param k 35 | * @param N 36 | * @param kN 37 | * @param d the d-parameter of quadratic polynomials Q(x) = (d*a*x + b)^2 - kN; typically 1 or 2 38 | * @param sieveParams basic sieve parameters 39 | * @param baseArrays primes, power arrays after adding powers 40 | * @param apg 41 | * @param cc congruence collector, also runs the matrix solver 42 | * @param threadIndex 43 | */ 44 | public PSIQSThread_SB( 45 | int k, BigInteger N, BigInteger kN, int d, SieveParams sieveParams, BaseArrays baseArrays, 46 | AParamGenerator apg, CongruenceCollector cc, int threadIndex) { 47 | 48 | super(k, N, kN, d, sieveParams, baseArrays, apg, new SIQSPolyGenerator(), new SingleBlockSieve(256*1024), 49 | new TDiv_QS_2LP(false), cc, threadIndex); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/psiqs/PSIQSThread_SB_U.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.psiqs; 15 | 16 | import java.math.BigInteger; 17 | 18 | import de.tilman_neumann.jml.factor.base.congruence.CongruenceCollector; 19 | import de.tilman_neumann.jml.factor.siqs.data.BaseArrays; 20 | import de.tilman_neumann.jml.factor.siqs.poly.AParamGenerator; 21 | import de.tilman_neumann.jml.factor.siqs.poly.SIQSPolyGenerator; 22 | import de.tilman_neumann.jml.factor.siqs.sieve.SieveParams; 23 | import de.tilman_neumann.jml.factor.siqs.sieve.SingleBlockSieveU; 24 | import de.tilman_neumann.jml.factor.siqs.tdiv.TDiv_QS_2LP; 25 | 26 | /** 27 | * A polynomial generation/sieve/trial division thread using the fastest sieve depending on sun.misc.Unsafe. 28 | * @author Tilman Neumann 29 | */ 30 | public class PSIQSThread_SB_U extends PSIQSThreadBase { 31 | 32 | /** 33 | * Standard constructor. 34 | * @param k 35 | * @param N 36 | * @param kN 37 | * @param d the d-parameter of quadratic polynomials Q(x) = (d*a*x + b)^2 - kN; typically 1 or 2 38 | * @param sieveParams basic sieve parameters 39 | * @param baseArrays primes, power arrays after adding powers 40 | * @param apg 41 | * @param cc congruence collector, also runs the matrix solver 42 | * @param threadIndex 43 | */ 44 | public PSIQSThread_SB_U( 45 | int k, BigInteger N, BigInteger kN, int d, SieveParams sieveParams, BaseArrays baseArrays, 46 | AParamGenerator apg, CongruenceCollector cc, int threadIndex) { 47 | 48 | super(k, N, kN, d, sieveParams, baseArrays, apg, new SIQSPolyGenerator(), new SingleBlockSieveU(256*1024), 49 | new TDiv_QS_2LP(true), cc, threadIndex); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/psiqs/PSIQSThread_U.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.psiqs; 15 | 16 | import java.math.BigInteger; 17 | 18 | import de.tilman_neumann.jml.factor.base.congruence.CongruenceCollector; 19 | import de.tilman_neumann.jml.factor.siqs.data.BaseArrays; 20 | import de.tilman_neumann.jml.factor.siqs.poly.AParamGenerator; 21 | import de.tilman_neumann.jml.factor.siqs.poly.SIQSPolyGenerator; 22 | import de.tilman_neumann.jml.factor.siqs.sieve.Sieve03hU; 23 | import de.tilman_neumann.jml.factor.siqs.sieve.SieveParams; 24 | import de.tilman_neumann.jml.factor.siqs.tdiv.TDiv_QS_2LP; 25 | 26 | /** 27 | * A polynomial generation/sieve/trial division thread using the fastest sieve depending on sun.misc.Unsafe. 28 | * @author Tilman Neumann 29 | */ 30 | public class PSIQSThread_U extends PSIQSThreadBase { 31 | 32 | /** 33 | * Standard constructor. 34 | * @param k 35 | * @param N 36 | * @param kN 37 | * @param d the d-parameter of quadratic polynomials Q(x) = (d*a*x + b)^2 - kN; typically 1 or 2 38 | * @param sieveParams basic sieve parameters 39 | * @param baseArrays primes, power arrays after adding powers 40 | * @param apg 41 | * @param cc congruence collector, also runs the matrix solver 42 | * @param threadIndex 43 | */ 44 | public PSIQSThread_U( 45 | int k, BigInteger N, BigInteger kN, int d, SieveParams sieveParams, BaseArrays baseArrays, 46 | AParamGenerator apg, CongruenceCollector cc, int threadIndex) { 47 | 48 | super(k, N, kN, d, sieveParams, baseArrays, apg, new SIQSPolyGenerator(), new Sieve03hU(), 49 | new TDiv_QS_2LP(true), cc, threadIndex); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/psiqs/PSIQSThread_U_3LP.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.psiqs; 15 | 16 | import java.math.BigInteger; 17 | 18 | import de.tilman_neumann.jml.factor.base.congruence.CongruenceCollector; 19 | import de.tilman_neumann.jml.factor.siqs.data.BaseArrays; 20 | import de.tilman_neumann.jml.factor.siqs.poly.AParamGenerator; 21 | import de.tilman_neumann.jml.factor.siqs.poly.SIQSPolyGenerator; 22 | import de.tilman_neumann.jml.factor.siqs.sieve.Sieve03hU; 23 | import de.tilman_neumann.jml.factor.siqs.sieve.SieveParams; 24 | import de.tilman_neumann.jml.factor.siqs.tdiv.TDiv_QS_3LP; 25 | 26 | /** 27 | * A polynomial generation/sieve/trial division thread using the fastest sieve depending on sun.misc.Unsafe. 28 | * @author Tilman Neumann 29 | */ 30 | public class PSIQSThread_U_3LP extends PSIQSThreadBase { 31 | 32 | /** 33 | * Standard constructor. 34 | * @param k 35 | * @param N 36 | * @param kN 37 | * @param d the d-parameter of quadratic polynomials Q(x) = (d*a*x + b)^2 - kN; typically 1 or 2 38 | * @param sieveParams basic sieve parameters 39 | * @param baseArrays primes, power arrays after adding powers 40 | * @param apg 41 | * @param cc congruence collector, also runs the matrix solver 42 | * @param threadIndex 43 | */ 44 | public PSIQSThread_U_3LP( 45 | int k, BigInteger N, BigInteger kN, int d, SieveParams sieveParams, BaseArrays baseArrays, 46 | AParamGenerator apg, CongruenceCollector cc, int threadIndex) { 47 | 48 | super(k, N, kN, d, sieveParams, baseArrays, apg, new SIQSPolyGenerator(), new Sieve03hU(), 49 | new TDiv_QS_3LP(true), cc, threadIndex); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/psiqs/PSIQSThread_U_nLP.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.psiqs; 15 | 16 | import java.math.BigInteger; 17 | 18 | import de.tilman_neumann.jml.factor.base.congruence.CongruenceCollector; 19 | import de.tilman_neumann.jml.factor.siqs.data.BaseArrays; 20 | import de.tilman_neumann.jml.factor.siqs.poly.AParamGenerator; 21 | import de.tilman_neumann.jml.factor.siqs.poly.SIQSPolyGenerator; 22 | import de.tilman_neumann.jml.factor.siqs.sieve.Sieve03hU; 23 | import de.tilman_neumann.jml.factor.siqs.sieve.SieveParams; 24 | import de.tilman_neumann.jml.factor.siqs.tdiv.TDiv_QS_nLP; 25 | 26 | /** 27 | * A polynomial generation/sieve/trial division thread using the fastest sieve depending on sun.misc.Unsafe. 28 | * @author Tilman Neumann 29 | */ 30 | public class PSIQSThread_U_nLP extends PSIQSThreadBase { 31 | 32 | /** 33 | * Standard constructor. 34 | * @param k 35 | * @param N 36 | * @param kN 37 | * @param d the d-parameter of quadratic polynomials Q(x) = (d*a*x + b)^2 - kN; typically 1 or 2 38 | * @param sieveParams basic sieve parameters 39 | * @param baseArrays primes, power arrays after adding powers 40 | * @param apg 41 | * @param cc congruence collector, also runs the matrix solver 42 | * @param threadIndex 43 | */ 44 | public PSIQSThread_U_nLP( 45 | int k, BigInteger N, BigInteger kN, int d, SieveParams sieveParams, BaseArrays baseArrays, 46 | AParamGenerator apg, CongruenceCollector cc, int threadIndex) { 47 | 48 | super(k, N, kN, d, sieveParams, baseArrays, apg, new SIQSPolyGenerator(), new Sieve03hU(), 49 | new TDiv_QS_nLP(true), cc, threadIndex); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/siqs/data/SolutionArrays.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.siqs.data; 15 | 16 | /** 17 | * Passive data structure bundling primes/powers and their smallest x-solutions. 18 | * 19 | * Having a structure with several arrays of the same size is faster than having an array of a structure, 20 | * because the former permits to exploit AVX/SSE mechanisms in Java 8. 21 | * 22 | * @author Tilman Neumann 23 | */ 24 | public class SolutionArrays extends BaseArrays { 25 | public int[] x1Array; 26 | public int[] x2Array; 27 | 28 | /** 29 | * Full constructor, allocates all arrays. 30 | * @param solutionsCount 31 | * @param qCount 32 | */ 33 | public SolutionArrays(int solutionsCount, int qCount) { 34 | super(solutionsCount); 35 | x1Array = new int[solutionsCount]; 36 | x2Array = new int[solutionsCount]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/siqs/poly/baseFilter/BaseFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.siqs.poly.baseFilter; 15 | 16 | import de.tilman_neumann.jml.factor.siqs.data.BaseArrays; 17 | import de.tilman_neumann.jml.factor.siqs.data.SolutionArrays; 18 | 19 | /** 20 | * Interface for the step filtering some elements out off the (prime/power) base. 21 | * 22 | * We must filter out at least the q-values that give the a-parameter when multiplied (and their powers), 23 | * because the special treatment for q-values has been removed from SiqsPolyGenerator.computeFirstXArrays() 24 | * for performance reasons. 25 | * 26 | * @author Tilman Neumann 27 | */ 28 | public interface BaseFilter { 29 | /** 30 | * Filtering results. 31 | */ 32 | public static class Result { 33 | public SolutionArrays solutionArrays; 34 | public int filteredBaseSize; 35 | public int[] qArray; 36 | 37 | public Result(SolutionArrays solutionArrays, int filteredBaseSize, int[] qArray) { 38 | this.solutionArrays = solutionArrays; 39 | this.filteredBaseSize = filteredBaseSize; 40 | this.qArray = qArray; 41 | } 42 | } 43 | 44 | /** 45 | * Filter base arrays, fill solutionArrays with the result. 46 | * @param solutionArrays 47 | * @param baseArrays 48 | * @param mergedBaseSize 49 | * @param qArray 50 | * @param qCount 51 | * @param k 52 | * @return filtered result 53 | */ 54 | public Result filter(SolutionArrays solutionArrays, BaseArrays baseArrays, int mergedBaseSize, int[] qArray, int qCount, int k); 55 | 56 | /** 57 | * @return algorithm name 58 | */ 59 | public String getName(); 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/siqs/powers/NoPowerFinder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.siqs.powers; 15 | 16 | import java.math.BigInteger; 17 | 18 | import de.tilman_neumann.jml.factor.siqs.data.BaseArrays; 19 | import de.tilman_neumann.jml.factor.siqs.sieve.SieveParams; 20 | 21 | /** 22 | * Dummy implementation of PowerFinder that ignores powers. 23 | * @author Tilman Neumann 24 | */ 25 | public class NoPowerFinder implements PowerFinder { 26 | 27 | @Override 28 | public String getName() { 29 | return "noPowers"; 30 | } 31 | 32 | /** 33 | * Find powers and add them to the prime base. 34 | * @param kN 35 | * @param primes 36 | * @param tArray 37 | * @param logPArray 38 | * @param pinvArrayL 2^32/p_i, required by Barrett reduction 39 | * @param primeBaseSize 40 | * @param sieveParams basic sieve parameters 41 | * @return BaseArrays containing powers 42 | */ 43 | public BaseArrays addPowers(BigInteger kN, int[] primes, int[] tArray, byte[] logPArray, long[] pinvArrayL, int primeBaseSize, SieveParams sieveParams) { 44 | //all exponents are 1 45 | int [] exponents = new int[primeBaseSize]; 46 | for (int i=primeBaseSize-1; i >= 0; i--) { 47 | exponents[i] = 1; 48 | } 49 | 50 | return new BaseArrays(primes, exponents, primes, tArray, logPArray, pinvArrayL); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/siqs/powers/PowerEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.siqs.powers; 15 | 16 | /** 17 | * Auxiliary class that allows to get the powers sorted bottom-up by the power value. 18 | */ 19 | public class PowerEntry implements Comparable { 20 | public int p; 21 | public int exponent; 22 | public int power; 23 | public int t; 24 | public byte logPower; 25 | public double pinvD; 26 | public long pinvL; 27 | 28 | public PowerEntry(int p, int exponent, int power, int t, byte logPower) { 29 | this.p = p; 30 | this.exponent = exponent; 31 | this.power = power; 32 | this.t = t; 33 | this.logPower = logPower; 34 | this.pinvD = 1.0 / power; 35 | this.pinvL = (1L<<32) / power; 36 | } 37 | 38 | @Override 39 | public boolean equals(Object o) { 40 | if (o==null || !(o instanceof PowerEntry)) return false; 41 | return power == ((PowerEntry)o).power; 42 | } 43 | 44 | @Override 45 | public int hashCode() { 46 | return power; 47 | } 48 | 49 | @Override 50 | public int compareTo(PowerEntry other) { 51 | return power - other.power; 52 | } 53 | } -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/siqs/powers/PowerFinder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.siqs.powers; 15 | 16 | import java.math.BigInteger; 17 | 18 | import de.tilman_neumann.jml.factor.siqs.data.BaseArrays; 19 | import de.tilman_neumann.jml.factor.siqs.sieve.SieveParams; 20 | 21 | public interface PowerFinder { 22 | 23 | /** 24 | * @return algorithm name 25 | */ 26 | public String getName(); 27 | 28 | /** 29 | * Find powers and add them to the prime base. 30 | * @param kN 31 | * @param primes 32 | * @param tArray 33 | * @param logPArray 34 | * @param pinvArrayL 2^32/p_i, required by Barrett reduction 35 | * @param primeBaseSize 36 | * @param sieveParams basic sieve parameters 37 | * @return BaseArrays containing powers 38 | */ 39 | BaseArrays addPowers( 40 | BigInteger kN, 41 | int[] primes, 42 | int[] tArray, 43 | byte[] logPArray, 44 | long[] pinvArrayL, 45 | int primeBaseSize, 46 | SieveParams sieveParams); 47 | } -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/BlockSieveUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.siqs.sieve; 15 | 16 | public class BlockSieveUtil { 17 | 18 | public static int computeBestBlockCount(int totalSize, int blockSize) { 19 | int lower = totalSize/blockSize; 20 | if (lower == 0) return 1; // we need at least one outer block 21 | 22 | int upper = lower + 1; 23 | int lowerError = Math.abs(blockSize - totalSize/lower); 24 | int upperError = Math.abs(blockSize - totalSize/upper); 25 | return (lowerError < upperError) ? lower : upper; // take the k with the smaller block size error 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SieveReport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.siqs.sieve; 15 | 16 | public class SieveReport { 17 | private long sieveHitCount; 18 | 19 | private long initDuration; 20 | private long sieveDuration; 21 | private long collectDuration; 22 | 23 | public SieveReport(long sieveHitCount, long initDuration, long sieveDuration, long collectDuration) { 24 | this.sieveHitCount = sieveHitCount; 25 | this.initDuration = initDuration; 26 | this.sieveDuration = sieveDuration; 27 | this.collectDuration = collectDuration; 28 | } 29 | 30 | /** 31 | * Add two reports. 32 | * @param other another report added to this 33 | */ 34 | public void add(SieveReport other) { 35 | this.sieveHitCount += other.sieveHitCount; 36 | this.initDuration += other.initDuration; 37 | this.sieveDuration += other.sieveDuration; 38 | this.collectDuration += other.collectDuration; 39 | } 40 | 41 | public long getTotalDuration(int numberOfThreads) { 42 | return (initDuration + sieveDuration + collectDuration)/numberOfThreads; 43 | } 44 | 45 | public String getOperationDetails() { 46 | return "Found " + sieveHitCount + " sieve hits"; 47 | } 48 | 49 | public String getPhaseTimings(int numberOfThreads) { 50 | return "init=" + initDuration/numberOfThreads + "ms, sieve=" + sieveDuration/numberOfThreads + "ms, collect=" + collectDuration/numberOfThreads + "ms"; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SieveResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.siqs.sieve; 15 | 16 | import java.util.Iterator; 17 | 18 | /** 19 | * Interface for sieve result implementations. 20 | * @author Tilman Neumann 21 | */ 22 | public interface SieveResult extends Iterable, Iterator { 23 | 24 | void reset(); 25 | 26 | int size(); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/factor/siqs/sieve/SmoothCandidate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.siqs.sieve; 15 | 16 | import java.math.BigInteger; 17 | 18 | import de.tilman_neumann.jml.factor.base.SortedIntegerArray; 19 | 20 | /** 21 | * A sieve hit that is a candidate to yield a smooth relation. 22 | * @author Tilman Neumann 23 | */ 24 | public class SmoothCandidate { 25 | /** The sieve location */ 26 | public int x; 27 | /** the logP sum from trial dividing unsieved base elements */ 28 | public double logPSum; 29 | /** The rest of Q(x)/(da) that still needs to get factorized, where a is the a-parameter of the polynomial and d==2 for kN==1 (mod 8), 2 else */ 30 | public BigInteger QRest; 31 | /** A(x) = d*a*x + b */ 32 | public BigInteger A; 33 | /** Small factors found by trial dividing small primes */ 34 | public SortedIntegerArray smallFactors; 35 | 36 | public SmoothCandidate(int x) { 37 | this(x, null, null, null); 38 | } 39 | 40 | public SmoothCandidate(int x, BigInteger QRest, BigInteger A) { 41 | this(x, QRest, A, null); 42 | } 43 | 44 | public SmoothCandidate(int x, BigInteger QRest, BigInteger A, SortedIntegerArray smallFactors) { 45 | this.x = x; 46 | this.QRest = QRest; 47 | this.A = A; 48 | this.smallFactors = smallFactors; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return String.valueOf(x); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/gaussianInteger/GaussianIntegerConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2022 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.gaussianInteger; 15 | 16 | import static de.tilman_neumann.jml.base.BigIntConstants.I_0; 17 | import static de.tilman_neumann.jml.base.BigIntConstants.I_1; 18 | 19 | public class GaussianIntegerConstants { 20 | 21 | public static final GaussianInteger GI_0 = new GaussianInteger(I_0, I_0); 22 | public static final GaussianInteger GI_1 = new GaussianInteger(I_1, I_0); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/hyperbolic/ArcCotH.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.hyperbolic; 15 | 16 | import java.math.BigDecimal; 17 | 18 | import de.tilman_neumann.jml.base.BigDecimalMath; 19 | import de.tilman_neumann.jml.powers.Pow2; 20 | import de.tilman_neumann.jml.precision.Scale; 21 | import de.tilman_neumann.jml.transcendental.Ln; 22 | 23 | import static de.tilman_neumann.jml.base.BigDecimalConstants.*; 24 | 25 | /** 26 | * Inverse hyperbolic cotangens function. 27 | * @author Tilman Neumann 28 | */ 29 | public class ArcCotH { 30 | 31 | /** 32 | * acoth(x) implemented by ln() formula. 33 | * @param x real argument with |x| > 1 34 | * @param scale wanted accuracy in after-comma digits 35 | * @return acoth(x) 36 | */ 37 | public static BigDecimal acoth(BigDecimal x, Scale scale) { 38 | if (x.abs().compareTo(F_1)<=0) throw new ArithmeticException("acoth(x) requires |x|>1 but x=" + x); 39 | BigDecimal fraction = BigDecimalMath.divide(x.add(F_1), x.subtract(F_1), scale); 40 | BigDecimal lnTerm = Ln.ln(fraction, scale); 41 | return Pow2.divPow2(lnTerm, 1); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/hyperbolic/ArcSinH.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.hyperbolic; 15 | 16 | import java.math.BigDecimal; 17 | 18 | import de.tilman_neumann.jml.powers.Pow; 19 | import de.tilman_neumann.jml.precision.Scale; 20 | import de.tilman_neumann.jml.roots.SqrtReal; 21 | import de.tilman_neumann.jml.transcendental.Ln; 22 | 23 | import static de.tilman_neumann.jml.base.BigDecimalConstants.*; 24 | 25 | /** 26 | * Inverse hyperbolic sinus function. 27 | * @author Tilman Neumann 28 | */ 29 | public class ArcSinH { 30 | 31 | /** 32 | * y = asinh(x) implemented by ln() formula, for all real x. 33 | * 34 | * @param x real argument 35 | * @param scale wanted accuracy in after-comma digits 36 | * @return y = asinh(x), y elemOf (-inf, +inf). 37 | */ 38 | public static BigDecimal asinh(BigDecimal x, Scale scale) { 39 | if (x.equals(F_0)) return F_0; 40 | BigDecimal xSquare_plus1 = Pow.pow(x, 2, scale).add(F_1); 41 | BigDecimal sqrtTerm = SqrtReal.sqrt(xSquare_plus1, scale); 42 | BigDecimal angle = Ln.ln(x.add(sqrtTerm), scale); 43 | return angle; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/hyperbolic/ArcTanH.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.hyperbolic; 15 | 16 | import java.math.BigDecimal; 17 | 18 | import de.tilman_neumann.jml.base.BigDecimalMath; 19 | import de.tilman_neumann.jml.powers.Pow2; 20 | import de.tilman_neumann.jml.precision.Scale; 21 | import de.tilman_neumann.jml.transcendental.Ln; 22 | 23 | import static de.tilman_neumann.jml.base.BigDecimalConstants.*; 24 | 25 | /** 26 | * Inverse hyperbolic tangens function. 27 | * @author Tilman Neumann 28 | */ 29 | public class ArcTanH { 30 | 31 | /** 32 | * atanh(x) implemented by ln() formula. 33 | * @param x real argument with |x| < 1 34 | * @param scale wanted accuracy in after-comma digits 35 | * @return atanh(x) 36 | */ 37 | public static BigDecimal atanh(BigDecimal x, Scale scale) { 38 | if (x.abs().compareTo(F_1)>=0) throw new ArithmeticException("atanh(x) requires |x|<1 but x=" + x); 39 | BigDecimal fraction = BigDecimalMath.divide(F_1.add(x), F_1.subtract(x), scale); 40 | BigDecimal lnTerm = Ln.ln(fraction, scale); 41 | return Pow2.divPow2(lnTerm, 1); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/partitions/Generator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.partitions; 15 | 16 | import java.io.Serializable; 17 | 18 | /** 19 | * A generator for a sequence of objects of type . 20 | * Generators differ from Iterators in that they do not have a backing Collection. 21 | * Consequently, there is no need for a remove() method. 22 | * 23 | * @author Tilman Neumann 24 | * 25 | * @param type of objects to create 26 | */ 27 | public interface Generator extends Serializable { 28 | /** 29 | * @return true if there is another object to generate 30 | */ 31 | boolean hasNext(); 32 | 33 | /** 34 | * @return next object 35 | */ 36 | T next(); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/partitions/PrimePowers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.partitions; 15 | 16 | import java.math.BigInteger; 17 | 18 | /** 19 | * Product of primes implemented as an multipartite integer. 20 | * @author Tilman Neumann 21 | */ 22 | public interface PrimePowers extends Mpi { 23 | /** 24 | * Return the prime at the given index. 25 | * @param index 26 | * @return prime 27 | */ 28 | BigInteger getPrime(int index); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/primes/exact/CollectingCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2019 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.primes.exact; 15 | 16 | public class CollectingCallback implements SieveCallback { 17 | private int capacity; 18 | public int count; 19 | public int[] array; 20 | 21 | public CollectingCallback(int desiredCount) { 22 | array = new int[desiredCount]; 23 | capacity = desiredCount; 24 | count = 0; 25 | } 26 | 27 | public void processPrime(long prime) { 28 | if (count == capacity) return; 29 | //LOG.debug("Set p(" + count + ") = " + prime); 30 | array[count++] = (int) prime; 31 | } 32 | } -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/primes/exact/CountingCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.primes.exact; 15 | 16 | /** 17 | * Simple callback just counting the primes coming in. 18 | * @author Tilman Neumann 19 | */ 20 | public class CountingCallback implements SieveCallback { 21 | private long count = 0; 22 | 23 | public void processPrime(long prime) { 24 | count++; 25 | } 26 | 27 | public long getCount() { 28 | return count; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/primes/exact/SieveCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.primes.exact; 15 | 16 | /** 17 | * Segmented sieve callback interface. 18 | */ 19 | public interface SieveCallback { 20 | void processPrime(long prime); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/primes/exact/SimpleSieve.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2019-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.primes.exact; 15 | 16 | /** 17 | * Monolithic sieve of Eratosthenes, working only for limits < Integer.MAX_VALUE = 2^31 - 1. 18 | * Used for quality tests only. 19 | * 20 | * @author Tilman Neumann 21 | */ 22 | public class SimpleSieve { 23 | private SieveCallback clientCallback; 24 | 25 | public SimpleSieve(SieveCallback clientCallback) { 26 | this.clientCallback = clientCallback; 27 | } 28 | 29 | /** 30 | * Generate primes. 31 | * @param limit0 biggest number to test for prime 32 | */ 33 | public void sieve(long limit0) { 34 | // small primes not delivered by the sieve below 35 | clientCallback.processPrime(2); 36 | 37 | if (limit0 > Integer.MAX_VALUE) throw new IllegalArgumentException("limit " + limit0 + " exceeds Integer.MAX_VALUE = " + Integer.MAX_VALUE); 38 | int limit = (int) limit0; 39 | 40 | // Sieve 41 | boolean[] isComposite = new boolean[limit+1]; // initialized with false 42 | for (int i=2; i*i <= limit; i++) { 43 | if (!isComposite[i]) { 44 | for (int j = i*i; j <= limit; j+=i) { 45 | isComposite[j] = true; 46 | } 47 | } 48 | } 49 | 50 | // Collect 51 | int n = 3; 52 | for ( ; n<=limit; n+=2) { 53 | if (!isComposite[n]) { 54 | clientCallback.processPrime(n); 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/quadraticResidues/QuadraticResidues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.quadraticResidues; 15 | 16 | import java.util.TreeSet; 17 | 18 | /** 19 | * Methods to generate quadratic residues or test for quadratic residuosity for general moduli m. 20 | * 21 | * @author Tilman Neumann 22 | */ 23 | public class QuadraticResidues { 24 | 25 | /** 26 | * Return all quadratic residues modulo m, computed by brute force. 27 | * 28 | * @param m 29 | * @return set of quadratic residues modulo m, sorted bottom up. 30 | */ 31 | public static TreeSet getQuadraticResidues(long m) { 32 | TreeSet quadraticResidues = new TreeSet(); 33 | for (long k=0; k<=m/2; k++) { 34 | quadraticResidues.add(k*k % m); 35 | } 36 | return quadraticResidues; 37 | } 38 | 39 | /** 40 | * Get the quadratic residues of even "k" modulo m, computed by brute force. 41 | * 42 | * @param m 43 | * @return square residues generated from even k^2 modulo m 44 | */ 45 | public static TreeSet getEvenQuadraticResidues(long m) { 46 | TreeSet quadraticResidues = new TreeSet(); 47 | for (long k=0; k<=m/2; k+=2) { 48 | quadraticResidues.add(k*k % m); 49 | } 50 | return quadraticResidues; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/random/LehmerRng64.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.random; 15 | 16 | import de.tilman_neumann.jml.base.Uint128; 17 | 18 | /** 19 | * Lehmer's random number generator for 64 bit numbers; requires 128 bit multiplication internally. 20 | * 21 | * @see https://en.wikipedia.org/wiki/Lehmer_random_number_generator 22 | */ 23 | public class LehmerRng64 { 24 | private static final Uint128 mult = new Uint128(0x12e15e35b500f16eL, 0x2e714eb2b37916a5L); 25 | 26 | private Uint128 state = mult; 27 | 28 | /** 29 | * @return a random long number N with Long.MIN_VALUE <= N <= Long.MAX_VALUE. 30 | */ 31 | public long nextLong() { 32 | long result = state.getHigh(); 33 | state = Uint128.mul128_getLow(state, mult); 34 | return result; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/random/LehmerRng64MH.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.random; 15 | 16 | import de.tilman_neumann.jml.base.Uint128; 17 | 18 | /** 19 | * Lehmer's random number generator for 64 bit numbers; requires 128 bit multiplication internally. 20 | * 21 | * This variant is using Math.multiplyHigh(). 22 | * 23 | * @see https://en.wikipedia.org/wiki/Lehmer_random_number_generator 24 | */ 25 | public class LehmerRng64MH { 26 | private static final Uint128 mult = new Uint128(0x12e15e35b500f16eL, 0x2e714eb2b37916a5L); 27 | 28 | private Uint128 state = mult; 29 | 30 | /** 31 | * @return a random long number N with Long.MIN_VALUE <= N <= Long.MAX_VALUE. 32 | */ 33 | public long nextLong() { 34 | long result = state.getHigh(); 35 | state = Uint128.mul128MH_getLow(state, mult); 36 | return result; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/random/SplitMix64.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.random; 15 | 16 | import de.tilman_neumann.jml.base.Uint128; 17 | 18 | /** 19 | * splitmix64 is a 64 bit random number generator with 64 bit state. 20 | * Adapted from https://rosettacode.org/wiki/Pseudo-random_numbers/Splitmix64. 21 | * 22 | * Very fast, but its statistical properties are poor. 23 | * According to https://en.wikipedia.org/wiki/Xorshift#Initialization, it is well-suited to initialize other random generators. 24 | * 25 | * @author Tilman Neumann 26 | */ 27 | public final class SplitMix64 { 28 | 29 | private static final long constant1 = 0x9e3779b97f4a7c15L; 30 | private static final long constant2 = 0xbf58476d1ce4e5b9L; 31 | private static final long constant3 = 0x94d049bb133111ebL; 32 | 33 | private long state; 34 | 35 | public SplitMix64() { 36 | state = 90832436910930047L; // just some semiprime, arbitrary choice 37 | } 38 | 39 | public SplitMix64(long aSeed) { 40 | state = aSeed; 41 | } 42 | 43 | public void seed(long aNumber) { 44 | state = aNumber; 45 | } 46 | 47 | public long nextLong() { 48 | long z = (state += constant1); 49 | z = (z ^ (z>>>30)) * constant2; 50 | z = (z ^ (z>>>27)) * constant3; 51 | return z ^ (z>>>31); 52 | } 53 | 54 | /** 55 | * @param max 56 | * @return a random long number N with 0 <= N <= max. 57 | */ 58 | public long nextLong(long max) { 59 | final long l = nextLong(); // take it as unsigned 60 | final Uint128 prod = Uint128.mul64_MH(l, max); 61 | return prod.getHigh(); 62 | } 63 | 64 | public long nextLong(long min, long max) { 65 | return min + nextLong(max - min); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/random/Xoroshiro128Plus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.random; 15 | 16 | import de.tilman_neumann.jml.base.Uint128; 17 | 18 | /** 19 | * xoroshiro128+ is a 64 bit random number generator using 128 bit state. 20 | * 21 | * @see https://nullprogram.com/blog/2017/09/21/ 22 | . * 23 | * @author Tilman Neumann 24 | */ 25 | public class Xoroshiro128Plus { 26 | 27 | private long state0, state1; 28 | 29 | public Xoroshiro128Plus() { 30 | SplitMix64 splitMix = new SplitMix64(); 31 | long seed = System.currentTimeMillis(); 32 | state0 = seed ^ splitMix.nextLong(); 33 | state1 = seed ^ splitMix.nextLong(); 34 | } 35 | 36 | public long nextLong() { 37 | long s0 = state0; 38 | long s1 = state1; 39 | long result = s0 + s1; 40 | s1 ^= s0; 41 | state0 = ((s0 << 55) | (s0 >>> 9)) ^ s1 ^ (s1 << 14); 42 | state1 = (s1 << 36) | (s1 >>> 28); 43 | return result; 44 | } 45 | 46 | /** 47 | * @param max 48 | * @return a random long number N with 0 <= N <= max. 49 | */ 50 | public long nextLong(long max) { 51 | final long l = nextLong(); // take it as unsigned 52 | final Uint128 prod = Uint128.mul64_MH(l, max); 53 | return prod.getHigh(); 54 | } 55 | 56 | public long nextLong(long min, long max) { 57 | return min + nextLong(max - min); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/random/Xorshf32.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.random; 15 | 16 | /** 17 | * Java port of Marsaglia's xorshf 32 bit random number generator, adapted from https://stackoverflow.com/questions/1640258/need-a-fast-random-generator-for-c. 18 | * 19 | * This version seems out-dated, the variant described in https://en.wikipedia.org/wiki/Xorshift uses other shifts... 20 | * 21 | * @author Tilman Neumann 22 | */ 23 | public class Xorshf32 { 24 | 25 | private int x=123456789, y=362436069, z=521288629; 26 | 27 | /** 28 | * @return a random long number N with Integer.MIN_VALUE <= N <= Integer.MAX_VALUE. 29 | */ 30 | public int nextInt() { 31 | int t; 32 | x ^= x << 16; 33 | x ^= x >> 5; 34 | x ^= x << 1; 35 | 36 | t = x; 37 | x = y; 38 | y = z; 39 | z = t ^ x ^ y; 40 | 41 | return z; 42 | } 43 | 44 | /** 45 | * @param max 46 | * @return a random int number N with 0 <= N <= max. 47 | */ 48 | public int nextInt(int max) { 49 | final long l = nextInt() & 0xFFFFFFFFL; // take it as unsigned 50 | final long prod = l * max; 51 | return (int) (prod >>> 32); 52 | } 53 | 54 | public int nextInt(int min, int max) { 55 | return min + nextInt(max - min); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/random/Xorshift64Star.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.random; 15 | 16 | import de.tilman_neumann.jml.base.Uint128; 17 | 18 | /** 19 | * xorshift64* is a 64 bit random number generator using 64 bit state. 20 | * Adapted from https://nullprogram.com/blog/2017/09/21/. 21 | . * 22 | * @author Tilman Neumann 23 | */ 24 | public class Xorshift64Star { 25 | 26 | private static final long multiplier = 0x2545f4914f6cdd1dL; 27 | 28 | private long state0; 29 | 30 | public Xorshift64Star() { 31 | SplitMix64 splitMix = new SplitMix64(); 32 | long seed = System.currentTimeMillis(); 33 | state0 = seed ^ splitMix.nextLong(); 34 | } 35 | 36 | public long nextLong() { 37 | long x = state0; 38 | x ^= x >>> 12; 39 | x ^= x << 25; 40 | x ^= x >>> 27; 41 | state0 = x; 42 | return x * multiplier; 43 | } 44 | 45 | /** 46 | * @param max 47 | * @return a random long number N with 0 <= N <= max. 48 | */ 49 | public long nextLong(long max) { 50 | final long l = nextLong(); // take it as unsigned 51 | final Uint128 prod = Uint128.mul64_MH(l, max); 52 | return prod.getHigh(); 53 | } 54 | 55 | public long nextLong(long min, long max) { 56 | return min + nextLong(max - min); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/sequence/NumberSequence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.sequence; 15 | 16 | /** 17 | * Interface for number sequences of type T. 18 | * @author Tilman Neumann 19 | * 20 | * @param sequence element type 21 | */ 22 | public interface NumberSequence { 23 | /** 24 | * @return the name of this sequence generator 25 | */ 26 | String getName(); 27 | 28 | /** 29 | * Reset sequence so that it starts again with its first element. 30 | */ 31 | void reset(); 32 | 33 | /** 34 | * @return the next integer 35 | */ 36 | T next(); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/jml/sequence/SquarefreeSequence63.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.sequence; 15 | 16 | import de.tilman_neumann.jml.primes.exact.AutoExpandingPrimesArray; 17 | 18 | /** 19 | * Sequence of multiplier * {squarefree numbers 1,2,3,5,6,7,10,11,13,...}, long implementation. 20 | * @author Tilman Neumann 21 | */ 22 | public class SquarefreeSequence63 implements NumberSequence { 23 | 24 | private AutoExpandingPrimesArray primesArray = AutoExpandingPrimesArray.get(); 25 | 26 | private long multiplier; 27 | private long next; 28 | 29 | public SquarefreeSequence63(long multiplier) { 30 | this.multiplier = multiplier; 31 | } 32 | 33 | @Override 34 | public String getName() { 35 | return multiplier + "*squarefree63"; 36 | } 37 | 38 | @Override 39 | public void reset() { 40 | this.next = 1; 41 | } 42 | 43 | @Override 44 | public Long next() { 45 | long ret = next; 46 | // compute next square free number 47 | while (true) { 48 | next = next + 1; 49 | boolean isSquareFree = true; 50 | // next must not be divisible by any prime square p^2 <= next 51 | long test = next; 52 | int primeIndex = 0; 53 | for (long p = 2; p*p<=test; p = primesArray.getPrime(++primeIndex)) { 54 | // test p 55 | if (test%p == 0) { 56 | test /= p; 57 | if (test%p == 0) { 58 | // next is not square free ! 59 | isSquareFree = false; 60 | break; 61 | } 62 | } 63 | } 64 | if (isSquareFree) break; // found next square-free number 65 | } 66 | return ret * multiplier; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/util/ReflectionUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2022 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.util; 15 | 16 | /** 17 | * Static auxiliary methods for java objects meta data. 18 | * 19 | * @author Tilman Neumann 20 | */ 21 | public class ReflectionUtil { 22 | private ReflectionUtil() { 23 | // static class 24 | } 25 | 26 | /** 27 | * Returns the package name for the given class. 28 | * 29 | * @param clazz Class 30 | * @return Package name 31 | */ 32 | public static String getPackageName(Class clazz) { 33 | String className = clazz.getName(); 34 | int lastPointIndex = className.lastIndexOf('.'); 35 | if (lastPointIndex < 0) { 36 | return ""; 37 | } 38 | return className.substring(0, lastPointIndex); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/util/SortOrder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.util; 15 | 16 | /** 17 | * Sort orders. 18 | * 19 | * @author Tilman Neumann 20 | */ 21 | public enum SortOrder { 22 | /** Ascending order. */ ASCENDING(1), 23 | /** Descending order. */ DESCENDING(-1); 24 | 25 | private int multiplier; 26 | 27 | private SortOrder(int multiplier) { 28 | this.multiplier = multiplier; 29 | } 30 | 31 | public int getMultiplier() { 32 | return multiplier; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/de/tilman_neumann/util/Timer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.util; 15 | 16 | /** 17 | * A simple time recorder. 18 | * @author Tilman Neumann 19 | */ 20 | public class Timer { 21 | private long start, t; 22 | 23 | /** 24 | * Full constructor, starts timer. 25 | */ 26 | public Timer() { 27 | start(); 28 | } 29 | 30 | /** 31 | * Restart timer. 32 | */ 33 | public void start() { 34 | start = t = System.currentTimeMillis(); 35 | } 36 | 37 | /** 38 | * @return time difference from last check to this check in milliseconds 39 | */ 40 | public long capture() { 41 | long last = t; 42 | t = System.currentTimeMillis(); 43 | return t-last; 44 | } 45 | 46 | /** 47 | * @return the total run time in milliseconds since this timer was created or restarted 48 | */ 49 | public long totalRuntime() { 50 | return System.currentTimeMillis() - start; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/ChebyshevPolynomialsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml; 15 | 16 | import java.math.BigDecimal; 17 | import java.math.BigInteger; 18 | 19 | import org.junit.BeforeClass; 20 | import org.junit.Test; 21 | 22 | import de.tilman_neumann.util.ConfigUtil; 23 | 24 | import static de.tilman_neumann.jml.base.BigIntConstants.*; 25 | import static org.junit.Assert.assertEquals; 26 | 27 | /** 28 | * Tests for Chebyshev polynomials. 29 | * @author Tilman Neumann 30 | */ 31 | public class ChebyshevPolynomialsTest { 32 | 33 | @BeforeClass 34 | public static void setup() { 35 | ConfigUtil.initProject(); 36 | } 37 | 38 | @Test 39 | public void testSmall() { 40 | for (int n=0; n<=4; n++) { 41 | for (BigInteger x=I_0; x.compareTo(I_10)<0; x=x.add(I_1)) { 42 | BigDecimal T_n_of_x = ChebyshevPolynomials.ChebyshevT(n, new BigDecimal(x)); 43 | BigDecimal closed = ChebyshevPolynomials.ChebyshevTClosed(n, new BigDecimal(x)); 44 | assertEquals(T_n_of_x, closed); 45 | } 46 | } 47 | for (int n=0; n<=4; n++) { 48 | for (BigInteger x=I_0; x.compareTo(I_10)<0; x=x.add(I_1)) { 49 | BigDecimal U_n_of_x = ChebyshevPolynomials.ChebyshevU(n, new BigDecimal(x)); 50 | BigDecimal closed = ChebyshevPolynomials.ChebyshevUClosed(n, new BigDecimal(x)); 51 | assertEquals(U_n_of_x, closed); 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/DivisorsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml; 15 | 16 | import static de.tilman_neumann.jml.base.BigIntConstants.*; 17 | import static org.junit.Assert.assertEquals; 18 | 19 | import java.math.BigInteger; 20 | import java.util.List; 21 | 22 | import org.junit.BeforeClass; 23 | import org.junit.Test; 24 | 25 | import de.tilman_neumann.util.ConfigUtil; 26 | 27 | /** 28 | * Implementations for finding all divisors of an integer. 29 | * 30 | * @author Tilman Neumann 31 | */ 32 | public class DivisorsTest { 33 | 34 | @BeforeClass 35 | public static void setup() { 36 | ConfigUtil.initProject(); 37 | } 38 | 39 | @Test 40 | public void testSumOfDivisorsForSmallIntegers() { 41 | assertEquals(I_0, Divisors.sumOfDivisors_v1(I_0)); 42 | // reference data from https://oeis.org/A000203, starts at n=1 43 | List reference = List.of(1, 3, 4, 7, 6, 12, 8, 15, 13, 18, 12, 28, 14, 24, 24, 31, 18, 39, 20, 42, 32, 36, 24, 60, 31, 42, 40, 56, 30, 72, 32, 63, 48, 54, 48, 91, 38, 60, 56, 90, 42, 96, 44, 84, 78, 72, 48, 124, 57, 93, 72, 98, 54, 120, 72, 120, 80, 90, 60, 168, 62, 96, 104, 127, 84, 144, 68, 126, 96, 144); 44 | for (int i=0; i. 13 | */ 14 | package de.tilman_neumann.jml; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | import java.math.BigInteger; 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | import org.apache.logging.log4j.Logger; 23 | import org.junit.Before; 24 | import org.junit.Test; 25 | import org.apache.logging.log4j.LogManager; 26 | 27 | import de.tilman_neumann.util.ConfigUtil; 28 | 29 | /** 30 | * Tests of the Moebius function implementation. 31 | * 32 | * @author Tilman Neumann 33 | */ 34 | public class MoebiusFunctionTest { 35 | private static final Logger LOG = LogManager.getLogger(MoebiusFunctionTest.class); 36 | 37 | @Before 38 | public void setup() { 39 | ConfigUtil.initProject(); 40 | } 41 | 42 | @Test 43 | public void testSmall() { 44 | // reference results from https://oeis.org/A008683 45 | List reference = List.of(1, -1, -1, 0, -1, 1, -1, 0, 0, 1, -1, 0, -1, 1, 1, 0, -1, 0, -1, 0, 1, 1, -1, 0, 0, 1, 0, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, 1, 1, 0, -1, -1, -1, 0, 0, 1, -1, 0, 0, 0, 1, 0, -1, 0, 1, 0, 1, 1, -1, 0, -1, 1, 0, 0, 1, -1, -1, 0, 1, -1, -1, 0, -1, 1, 0, 0, 1, -1); 46 | 47 | ArrayList computedSequence = new ArrayList<>(); 48 | for (int n=1; n<=reference.size(); n++) { 49 | BigInteger bigN = BigInteger.valueOf(n); 50 | computedSequence.add(MoebiusFunction.moebius(bigN)); 51 | } 52 | LOG.info("Moebius function = " + computedSequence); 53 | assertEquals(reference, computedSequence); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/base/BigIntConverterTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.base; 15 | 16 | import java.math.BigInteger; 17 | 18 | import org.junit.BeforeClass; 19 | import org.junit.Test; 20 | 21 | import de.tilman_neumann.util.ConfigUtil; 22 | 23 | import static de.tilman_neumann.jml.base.BigIntConstants.*; 24 | import static org.junit.Assert.assertEquals; 25 | 26 | public class BigIntConverterTest { 27 | 28 | @BeforeClass 29 | public static void setup() { 30 | ConfigUtil.initProject(); 31 | } 32 | 33 | @Test 34 | public void testFromDouble() { 35 | assertEquals(I_2, BigIntConverter.fromDouble(2)); 36 | assertEquals(I_3, BigIntConverter.fromDouble(3)); 37 | assertEquals(I_3, BigIntConverter.fromDouble(Math.PI)); 38 | assertEquals(I_5, BigIntConverter.fromDouble(5.99)); 39 | assertEquals(I_6, BigIntConverter.fromDouble(6.0001)); 40 | assertEquals(I_6.negate(), BigIntConverter.fromDouble(-6.0001)); 41 | } 42 | 43 | @Test 44 | public void testFromDoubleMulPow2() { 45 | assertEquals(BigInteger.valueOf(-101), BigIntConverter.fromDoubleMulPow2(-6.333, 4)); 46 | assertEquals(I_6, BigIntConverter.fromDoubleMulPow2(101.333, -4)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/base/BigRationalTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.base; 15 | 16 | import static de.tilman_neumann.jml.base.BigIntConstants.*; 17 | import static org.junit.Assert.assertEquals; 18 | 19 | import org.junit.BeforeClass; 20 | import org.junit.Test; 21 | 22 | import de.tilman_neumann.util.ConfigUtil; 23 | 24 | public class BigRationalTest { 25 | 26 | @BeforeClass 27 | public static void setup() { 28 | ConfigUtil.initProject(); 29 | } 30 | 31 | @Test 32 | public void testRound() { 33 | assertEquals(I_0, new BigRational(I_1, I_2).round()); 34 | assertEquals(I_1, new BigRational(I_3, I_2).round()); 35 | 36 | assertEquals(I_1.negate(), new BigRational(I_1.negate(), I_2).round()); 37 | assertEquals(I_2.negate(), new BigRational(I_3.negate(), I_2).round()); 38 | 39 | assertEquals(I_1.negate(), new BigRational(I_1, I_2.negate()).round()); 40 | assertEquals(I_2.negate(), new BigRational(I_3, I_2.negate()).round()); 41 | 42 | assertEquals(I_0, new BigRational(I_1.negate(), I_2.negate()).round()); 43 | assertEquals(I_1, new BigRational(I_3.negate(), I_2.negate()).round()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/combinatorics/FactorialPerformanceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.combinatorics; 15 | 16 | import java.math.BigInteger; 17 | 18 | import org.apache.logging.log4j.LogManager; 19 | import org.apache.logging.log4j.Logger; 20 | 21 | import de.tilman_neumann.util.ConfigUtil; 22 | 23 | public class FactorialPerformanceTest { 24 | 25 | private static final Logger LOG = LogManager.getLogger(FactorialPerformanceTest.class); 26 | 27 | /** 28 | * Test. 29 | * @param args Ignored. 30 | */ 31 | public static void main(String[] args) { 32 | ConfigUtil.initProject(); 33 | 34 | // compute 1000! ten thousand times 35 | int n=1000; 36 | int numberOfTests = 10000; 37 | 38 | long start = System.currentTimeMillis(); 39 | @SuppressWarnings("unused") 40 | BigInteger result = null; 41 | for (int i=0; i. 13 | */ 14 | package de.tilman_neumann.jml.combinatorics; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | import java.math.BigInteger; 19 | 20 | import org.junit.BeforeClass; 21 | import org.junit.Test; 22 | 23 | import de.tilman_neumann.util.ConfigUtil; 24 | 25 | import static de.tilman_neumann.jml.base.BigIntConstants.*; 26 | 27 | public class FactorialTest { 28 | 29 | @BeforeClass 30 | public static void setup() { 31 | ConfigUtil.initProject(); 32 | } 33 | 34 | @Test 35 | public void testSimpleFactorial() { 36 | assertEquals(I_1, Factorial.simpleProduct(0)); 37 | assertEquals(I_1, Factorial.simpleProduct(1)); 38 | assertEquals(I_24, Factorial.simpleProduct(4)); 39 | assertEquals(new BigInteger("608281864034267560872252163321295376887552831379210240000000000"), Factorial.simpleProduct(49)); 40 | } 41 | 42 | @Test 43 | public void testLuschnyFactorial() { 44 | assertEquals(I_1, Factorial.factorial(0)); 45 | assertEquals(I_1, Factorial.factorial(1)); 46 | assertEquals(I_24, Factorial.factorial(4)); 47 | assertEquals(new BigInteger("608281864034267560872252163321295376887552831379210240000000000"), Factorial.factorial(49)); 48 | 49 | BigInteger correctFactorial1000 = Factorial.simpleProduct(1000); 50 | BigInteger luschnyFactorial1000 = Factorial.factorial(1000); 51 | assertEquals(correctFactorial1000, luschnyFactorial1000); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/combinatorics/FallingFactorialPerformanceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.combinatorics; 15 | 16 | import org.apache.logging.log4j.LogManager; 17 | import org.apache.logging.log4j.Logger; 18 | 19 | import de.tilman_neumann.util.ConfigUtil; 20 | 21 | public class FallingFactorialPerformanceTest { 22 | 23 | private static final Logger LOG = LogManager.getLogger(FallingFactorialPerformanceTest.class); 24 | 25 | private static void testPerformance() { 26 | int limit=1000; 27 | 28 | long t0, t1; 29 | t0 = System.currentTimeMillis(); 30 | for (int n=0; n. 13 | */ 14 | package de.tilman_neumann.jml.factor; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | import java.math.BigInteger; 19 | 20 | import org.apache.logging.log4j.LogManager; 21 | import org.apache.logging.log4j.Logger; 22 | 23 | import de.tilman_neumann.util.ConfigUtil; 24 | import de.tilman_neumann.util.SortedMultiset; 25 | 26 | public class FactorSieveDemo { 27 | private static final Logger LOG = LogManager.getLogger(FactorSieveDemo.class); 28 | private static final boolean DEBUG = false; 29 | 30 | public static void main(String[] args) { 31 | ConfigUtil.initProject(); 32 | 33 | long start = 99000000, limit = 100000000; 34 | FactorSieve sieve = new FactorSieve(start, limit); 35 | long t0 = System.currentTimeMillis(); 36 | sieve.sieve(); 37 | long t1 = System.currentTimeMillis(); 38 | LOG.info("Factoring all numbers from " + start + " to " + limit + " using the sieve took " + (t1-t0) + " milliseconds."); 39 | if (DEBUG) { 40 | for (long n=start; n<=limit; n++) { // n==1 gives null factors 41 | SortedMultiset factors = sieve.getFactorization(n); 42 | LOG.info(n + " = " + factors); 43 | if (n>1) { 44 | long test = FactorSieve.computeProduct(factors); 45 | assertEquals(n, test); 46 | } 47 | } 48 | } 49 | 50 | // without batch 51 | FactorAlgorithm factorizer = FactorAlgorithm.getDefault(); 52 | long t2 = System.currentTimeMillis(); 53 | for (long n=start; n<=limit; n++) { 54 | factorizer.factor(BigInteger.valueOf(n)); 55 | } 56 | long t3 = System.currentTimeMillis(); 57 | LOG.info("Factoring all numbers from " + start + " to " + limit + " individually took " + (t3-t2) + " milliseconds."); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/factor/HardSemiprimeGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor; 15 | 16 | import java.math.BigInteger; 17 | 18 | import org.apache.logging.log4j.LogManager; 19 | import org.apache.logging.log4j.Logger; 20 | 21 | import de.tilman_neumann.util.ConfigUtil; 22 | 23 | public class HardSemiprimeGenerator { 24 | private static final Logger LOG = LogManager.getLogger(HardSemiprimeGenerator.class); 25 | 26 | /** 27 | * A simple main function to generate hard semi-primes. 28 | * @param args ignored 29 | */ 30 | public static void main(String[] args) { 31 | ConfigUtil.initProject(); 32 | 33 | for (int bits = 330; bits<=450; bits+=10) { 34 | BigInteger num = TestsetGenerator.generate(1, bits, TestNumberNature.QUITE_HARD_SEMIPRIMES)[0]; 35 | LOG.info("// " + bits + " bits:"); 36 | LOG.info(num); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/factor/pollardRho/PollardRhoBrent31Runner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.pollardRho; 15 | 16 | import java.io.BufferedReader; 17 | import java.io.IOException; 18 | import java.io.InputStreamReader; 19 | import java.math.BigInteger; 20 | 21 | import org.apache.logging.log4j.LogManager; 22 | import org.apache.logging.log4j.Logger; 23 | 24 | import de.tilman_neumann.util.ConfigUtil; 25 | import de.tilman_neumann.util.SortedMultiset; 26 | 27 | public class PollardRhoBrent31Runner { 28 | private static final Logger LOG = LogManager.getLogger(PollardRhoBrent31Runner.class); 29 | 30 | /** 31 | * Test. 32 | * @param args ignored 33 | */ 34 | public static void main(String[] args) { 35 | ConfigUtil.initProject(); 36 | 37 | while(true) { 38 | String input; 39 | try { 40 | LOG.info("Please insert the integer to factor:"); 41 | BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); 42 | String line = in.readLine(); 43 | input = line.trim(); 44 | LOG.debug("factoring " + input + "..."); 45 | } catch (IOException ioe) { 46 | LOG.error("io-error occurring on input: " + ioe.getMessage()); 47 | continue; 48 | } 49 | 50 | long start = System.currentTimeMillis(); 51 | BigInteger n = new BigInteger(input); 52 | SortedMultiset result = new PollardRhoBrent31().factor(n); 53 | LOG.info("Factored " + n + " (" + n.bitLength() + " bit) = " + result.toString("*", "^") + " in " + (System.currentTimeMillis()-start) + " ms"); 54 | 55 | } // next input... 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/factor/pollardRho/PollardRhoBrentModBlockTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.pollardRho; 15 | 16 | import java.math.BigInteger; 17 | import java.util.List; 18 | 19 | import org.junit.BeforeClass; 20 | import org.junit.Test; 21 | 22 | import de.tilman_neumann.jml.factor.FactorTestBase; 23 | import de.tilman_neumann.util.ConfigUtil; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | 27 | public class PollardRhoBrentModBlockTest extends FactorTestBase { 28 | 29 | @BeforeClass 30 | public static void setup() { 31 | ConfigUtil.initProject(); 32 | setFactorizer(new PollardRhoBrentModBlock()); 33 | } 34 | 35 | @Test 36 | public void testSmallestComposites() { 37 | List fails = testFullFactorizationOfComposites(100000); 38 | assertEquals("Failed to factor n = " + fails, 0, fails.size()); 39 | } 40 | 41 | @Test 42 | public void testSomeInputs() { 43 | assertFullFactorizationSuccess("9223372036854775807", "7^2 * 73 * 127 * 337 * 92737 * 649657"); // Long.MAX_VALUE = 2^63-1 44 | assertFullFactorizationSuccess("18446744073709551617", "274177 * 67280421310721"); // F6 45 | assertFullFactorizationSuccess("5679148659138759837165981543", "3^3 * 466932157 * 450469808245315337"); 46 | assertFullFactorizationSuccess("8225267468394993133669189614204532935183709603155231863020477010700542265332938919716662623", 47 | "1234567891 * 1234567907 * 1234567913 * 1234567927 * 1234567949 * 1234567967 * 1234567981 * 1234568021 * 1234568029 * 1234568047"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/factor/pollardRho/PollardRhoBrentMontgomery64MHInlinedRunner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.pollardRho; 15 | 16 | import java.io.BufferedReader; 17 | import java.io.IOException; 18 | import java.io.InputStreamReader; 19 | import java.math.BigInteger; 20 | 21 | import org.apache.logging.log4j.LogManager; 22 | import org.apache.logging.log4j.Logger; 23 | 24 | import de.tilman_neumann.util.ConfigUtil; 25 | import de.tilman_neumann.util.SortedMultiset; 26 | 27 | public class PollardRhoBrentMontgomery64MHInlinedRunner { 28 | private static final Logger LOG = LogManager.getLogger(PollardRhoBrentMontgomery64MHInlinedRunner.class); 29 | 30 | /** 31 | * Test. 32 | * @param args ignored 33 | */ 34 | public static void main(String[] args) { 35 | ConfigUtil.initProject(); 36 | 37 | while(true) { 38 | String input; 39 | try { 40 | LOG.info("Please insert the integer to factor:"); 41 | BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); 42 | String line = in.readLine(); 43 | input = line.trim(); 44 | LOG.debug("factoring " + input + "..."); 45 | } catch (IOException ioe) { 46 | LOG.error("io-error occurring on input: " + ioe.getMessage()); 47 | continue; 48 | } 49 | 50 | long start = System.currentTimeMillis(); 51 | BigInteger n = new BigInteger(input); 52 | SortedMultiset result = new PollardRhoBrentMontgomery64MHInlined().factor(n); 53 | LOG.info("Factored " + n + " (" + n.bitLength() + " bit) = " + result.toString("*", "^") + " in " + (System.currentTimeMillis()-start) + " ms"); 54 | 55 | } // next input... 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/factor/pollardRho/PollardRhoBrentMontgomery64MHRunner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.pollardRho; 15 | 16 | import java.io.BufferedReader; 17 | import java.io.IOException; 18 | import java.io.InputStreamReader; 19 | import java.math.BigInteger; 20 | 21 | import org.apache.logging.log4j.LogManager; 22 | import org.apache.logging.log4j.Logger; 23 | 24 | import de.tilman_neumann.util.ConfigUtil; 25 | import de.tilman_neumann.util.SortedMultiset; 26 | 27 | public class PollardRhoBrentMontgomery64MHRunner { 28 | private static final Logger LOG = LogManager.getLogger(PollardRhoBrentMontgomery64MHRunner.class); 29 | 30 | /** 31 | * Test. 32 | * @param args ignored 33 | */ 34 | public static void main(String[] args) { 35 | ConfigUtil.initProject(); 36 | 37 | while(true) { 38 | String input; 39 | try { 40 | LOG.info("Please insert the integer to factor:"); 41 | BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); 42 | String line = in.readLine(); 43 | input = line.trim(); 44 | LOG.debug("factoring " + input + "..."); 45 | } catch (IOException ioe) { 46 | LOG.error("io-error occurring on input: " + ioe.getMessage()); 47 | continue; 48 | } 49 | 50 | long start = System.currentTimeMillis(); 51 | BigInteger n = new BigInteger(input); 52 | SortedMultiset result = new PollardRhoBrentMontgomery64MH().factor(n); 53 | LOG.info("Factored " + n + " (" + n.bitLength() + " bit) = " + result.toString("*", "^") + " in " + (System.currentTimeMillis()-start) + " ms"); 54 | 55 | } // next input... 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/factor/pollardRho/PollardRhoBrentMontgomery64Runner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.pollardRho; 15 | 16 | import java.io.BufferedReader; 17 | import java.io.IOException; 18 | import java.io.InputStreamReader; 19 | import java.math.BigInteger; 20 | 21 | import org.apache.logging.log4j.LogManager; 22 | import org.apache.logging.log4j.Logger; 23 | 24 | import de.tilman_neumann.util.ConfigUtil; 25 | import de.tilman_neumann.util.SortedMultiset; 26 | 27 | public class PollardRhoBrentMontgomery64Runner { 28 | private static final Logger LOG = LogManager.getLogger(PollardRhoBrentMontgomery64Runner.class); 29 | 30 | /** 31 | * Test. 32 | * @param args ignored 33 | */ 34 | public static void main(String[] args) { 35 | ConfigUtil.initProject(); 36 | 37 | while(true) { 38 | String input; 39 | try { 40 | LOG.info("Please insert the integer to factor:"); 41 | BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); 42 | String line = in.readLine(); 43 | input = line.trim(); 44 | LOG.debug("factoring " + input + "..."); 45 | } catch (IOException ioe) { 46 | LOG.error("io-error occurring on input: " + ioe.getMessage()); 47 | continue; 48 | } 49 | 50 | long start = System.currentTimeMillis(); 51 | BigInteger n = new BigInteger(input); 52 | SortedMultiset result = new PollardRhoBrentMontgomery64().factor(n); 53 | LOG.info("Factored " + n + " (" + n.bitLength() + " bit) = " + result.toString("*", "^") + " in " + (System.currentTimeMillis()-start) + " ms"); 54 | 55 | } // next input... 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/factor/pollardRho/PollardRhoBrentTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.pollardRho; 15 | 16 | import java.math.BigInteger; 17 | import java.util.List; 18 | 19 | import org.junit.BeforeClass; 20 | import org.junit.Test; 21 | 22 | import de.tilman_neumann.jml.factor.FactorTestBase; 23 | import de.tilman_neumann.util.ConfigUtil; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | 27 | public class PollardRhoBrentTest extends FactorTestBase { 28 | 29 | @BeforeClass 30 | public static void setup() { 31 | ConfigUtil.initProject(); 32 | setFactorizer(new PollardRhoBrent()); 33 | } 34 | 35 | @Test 36 | public void testSmallestComposites() { 37 | List fails = testFullFactorizationOfComposites(100000); 38 | assertEquals("Failed to factor n = " + fails, 0, fails.size()); 39 | } 40 | 41 | @Test 42 | public void testSomeInputs() { 43 | assertFullFactorizationSuccess("9223372036854775807", "7^2 * 73 * 127 * 337 * 92737 * 649657"); // Long.MAX_VALUE = 2^63-1 44 | assertFullFactorizationSuccess("18446744073709551617", "274177 * 67280421310721"); // F6 45 | assertFullFactorizationSuccess("5679148659138759837165981543", "3^3 * 466932157 * 450469808245315337"); 46 | assertFullFactorizationSuccess("8225267468394993133669189614204532935183709603155231863020477010700542265332938919716662623", 47 | "1234567891 * 1234567907 * 1234567913 * 1234567927 * 1234567949 * 1234567967 * 1234567981 * 1234568021 * 1234568029 * 1234568047"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/factor/pollardRho/PollardRhoTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.pollardRho; 15 | 16 | import java.math.BigInteger; 17 | import java.util.List; 18 | 19 | import org.junit.BeforeClass; 20 | import org.junit.Test; 21 | 22 | import de.tilman_neumann.jml.factor.FactorTestBase; 23 | import de.tilman_neumann.util.ConfigUtil; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | 27 | public class PollardRhoTest extends FactorTestBase { 28 | 29 | @BeforeClass 30 | public static void setup() { 31 | ConfigUtil.initProject(); 32 | setFactorizer(new PollardRho()); 33 | } 34 | 35 | @Test 36 | public void testSmallestComposites() { 37 | List fails = testFullFactorizationOfComposites(100000); 38 | assertEquals("Failed to factor n = " + fails, 0, fails.size()); 39 | } 40 | 41 | @Test 42 | public void testSomeInputs() { 43 | assertFullFactorizationSuccess("9223372036854775807", "7^2 * 73 * 127 * 337 * 92737 * 649657"); // Long.MAX_VALUE = 2^63-1 44 | assertFullFactorizationSuccess("18446744073709551617", "274177 * 67280421310721"); // F6 45 | assertFullFactorizationSuccess("5679148659138759837165981543", "3^3 * 466932157 * 450469808245315337"); 46 | assertFullFactorizationSuccess("8225267468394993133669189614204532935183709603155231863020477010700542265332938919716662623", 47 | "1234567891 * 1234567907 * 1234567913 * 1234567927 * 1234567949 * 1234567967 * 1234567981 * 1234568021 * 1234568029 * 1234568047"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/factor/pollardRho/PollardRhoTwoLoopsModBlockTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.pollardRho; 15 | 16 | import java.math.BigInteger; 17 | import java.util.List; 18 | 19 | import org.junit.BeforeClass; 20 | import org.junit.Test; 21 | 22 | import de.tilman_neumann.jml.factor.FactorTestBase; 23 | import de.tilman_neumann.util.ConfigUtil; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | 27 | public class PollardRhoTwoLoopsModBlockTest extends FactorTestBase { 28 | 29 | @BeforeClass 30 | public static void setup() { 31 | ConfigUtil.initProject(); 32 | setFactorizer(new PollardRhoTwoLoopsModBlock()); 33 | } 34 | 35 | @Test 36 | public void testSmallestComposites() { 37 | List fails = testFullFactorizationOfComposites(100000); 38 | assertEquals("Failed to factor n = " + fails, 0, fails.size()); 39 | } 40 | 41 | @Test 42 | public void testSomeInputs() { 43 | assertFullFactorizationSuccess("9223372036854775807", "7^2 * 73 * 127 * 337 * 92737 * 649657"); // Long.MAX_VALUE = 2^63-1 44 | assertFullFactorizationSuccess("18446744073709551617", "274177 * 67280421310721"); // F6 45 | assertFullFactorizationSuccess("5679148659138759837165981543", "3^3 * 466932157 * 450469808245315337"); 46 | assertFullFactorizationSuccess("8225267468394993133669189614204532935183709603155231863020477010700542265332938919716662623", 47 | "1234567891 * 1234567907 * 1234567913 * 1234567927 * 1234567949 * 1234567967 * 1234567981 * 1234568021 * 1234568029 * 1234568047"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/factor/pollardRho/PollardRhoTwoLoopsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.pollardRho; 15 | 16 | import java.math.BigInteger; 17 | import java.util.List; 18 | 19 | import org.junit.BeforeClass; 20 | import org.junit.Test; 21 | 22 | import de.tilman_neumann.jml.factor.FactorTestBase; 23 | import de.tilman_neumann.util.ConfigUtil; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | 27 | public class PollardRhoTwoLoopsTest extends FactorTestBase { 28 | 29 | @BeforeClass 30 | public static void setup() { 31 | ConfigUtil.initProject(); 32 | setFactorizer(new PollardRhoTwoLoops()); 33 | } 34 | 35 | @Test 36 | public void testSmallestComposites() { 37 | List fails = testFullFactorizationOfComposites(100000); 38 | assertEquals("Failed to factor n = " + fails, 0, fails.size()); 39 | } 40 | 41 | @Test 42 | public void testSomeInputs() { 43 | assertFullFactorizationSuccess("9223372036854775807", "7^2 * 73 * 127 * 337 * 92737 * 649657"); // Long.MAX_VALUE = 2^63-1 44 | assertFullFactorizationSuccess("18446744073709551617", "274177 * 67280421310721"); // F6 45 | assertFullFactorizationSuccess("5679148659138759837165981543", "3^3 * 466932157 * 450469808245315337"); 46 | assertFullFactorizationSuccess("8225267468394993133669189614204532935183709603155231863020477010700542265332938919716662623", 47 | "1234567891 * 1234567907 * 1234567913 * 1234567927 * 1234567949 * 1234567967 * 1234567981 * 1234568021 * 1234568029 * 1234568047"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/factor/siqs/SIQSSmallTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.siqs; 15 | 16 | import org.junit.BeforeClass; 17 | import org.junit.Test; 18 | 19 | import de.tilman_neumann.jml.factor.FactorTestBase; 20 | import de.tilman_neumann.jml.factor.siqs.poly.SIQSPolyGenerator; 21 | import de.tilman_neumann.util.ConfigUtil; 22 | 23 | /** 24 | * Tests for SIQSSmall. 25 | * 26 | * Typical SIQS implementations cannot factor small numbers (say with less than 60 or 50 bit). 27 | * A possible reason for this is that the space of possible a-parameters is too restricted. 28 | */ 29 | public class SIQSSmallTest extends FactorTestBase { 30 | 31 | @BeforeClass 32 | public static void setup() { 33 | ConfigUtil.initProject(); 34 | setFactorizer(new SIQSSmall(0.32F, 0.37F, null, new SIQSPolyGenerator(), 10, true)); 35 | } 36 | 37 | @Test 38 | // TODO On github CI this test may need up to 50 (!) seconds. Locally the test finishes in less than 100ms. 39 | // The test numbers are not very appropriate for the algorithm, but why the difference between local and github tests? 40 | public void testSomeInputs() { 41 | assertFullFactorizationSuccess("15841065490425479923", "2604221509 * 6082841047"); // 64 bit 42 | assertFullFactorizationSuccess("11111111111111111111111111", "11 * 53 * 79 * 859 * 265371653 * 1058313049"); // 84 bit 43 | assertFullFactorizationSuccess("5679148659138759837165981543", "3^3 * 466932157 * 450469808245315337"); // 93 bit 44 | 45 | // This number is already too big, it causes hanging github CI builds quite often 46 | //assertFactorizationSuccess("11111111111111111111111111155555555555111111111111111", "67 * 157 * 1056289676880987842105819104055096069503860738769"); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/factor/squfof/SquFoF31PreloadTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.squfof; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | import java.math.BigInteger; 19 | import java.util.List; 20 | 21 | import org.junit.BeforeClass; 22 | import org.junit.Test; 23 | 24 | import de.tilman_neumann.jml.factor.FactorTestBase; 25 | import de.tilman_neumann.util.ConfigUtil; 26 | 27 | public class SquFoF31PreloadTest extends FactorTestBase { 28 | 29 | @BeforeClass 30 | public static void setup() { 31 | ConfigUtil.initProject(); 32 | setFactorizer(new SquFoF31Preload()); 33 | } 34 | 35 | @Test 36 | public void testSmallestComposites() { 37 | List fails = testFullFactorizationOfComposites(100000); 38 | assertEquals("Failed to factor n = " + fails, 0, fails.size()); 39 | } 40 | 41 | @Test 42 | public void testSomeParticularNumbers() { 43 | assertFullFactorizationSuccess(1099511627970L, "2 * 3 * 5 * 7 * 23 * 227642159"); // 41 bit 44 | } 45 | 46 | @Test 47 | public void testFindSingleFactorForRandomCompositesNearUpperBound() { 48 | testFindSingleFactorForRandomOddComposites(40, 53, 10000); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/factor/squfof/SquFoF31Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.squfof; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | import java.math.BigInteger; 19 | import java.util.List; 20 | 21 | import org.junit.BeforeClass; 22 | import org.junit.Test; 23 | 24 | import de.tilman_neumann.jml.factor.FactorTestBase; 25 | import de.tilman_neumann.util.ConfigUtil; 26 | 27 | public class SquFoF31Test extends FactorTestBase { 28 | 29 | @BeforeClass 30 | public static void setup() { 31 | ConfigUtil.initProject(); 32 | setFactorizer(new SquFoF31()); 33 | } 34 | 35 | @Test 36 | public void testSmallestComposites() { 37 | List fails = testFullFactorizationOfComposites(100000); 38 | assertEquals("Failed to factor n = " + fails, 0, fails.size()); 39 | } 40 | 41 | @Test 42 | public void testSomeParticularNumbers() { 43 | assertFullFactorizationSuccess(1099511627970L, "2 * 3 * 5 * 7 * 23 * 227642159"); // 41 bit 44 | } 45 | 46 | @Test 47 | public void testFindSingleFactorForRandomCompositesNearUpperBound() { 48 | testFindSingleFactorForRandomOddComposites(40, 53, 10000); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/factor/squfof/SquFoF63Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.squfof; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | import java.math.BigInteger; 19 | import java.util.List; 20 | 21 | import org.junit.BeforeClass; 22 | import org.junit.Test; 23 | 24 | import de.tilman_neumann.jml.factor.FactorTestBase; 25 | import de.tilman_neumann.util.ConfigUtil; 26 | 27 | public class SquFoF63Test extends FactorTestBase { 28 | 29 | @BeforeClass 30 | public static void setup() { 31 | ConfigUtil.initProject(); 32 | setFactorizer(new SquFoF63()); 33 | } 34 | 35 | @Test 36 | public void testSmallestComposites() { 37 | List fails = testFullFactorizationOfComposites(100000); 38 | assertEquals("Failed to factor n = " + fails, 0, fails.size()); 39 | } 40 | 41 | @Test 42 | public void testSomeParticularNumbers() { 43 | assertFullFactorizationSuccess(1099511627970L, "2 * 3 * 5 * 7 * 23 * 227642159"); // 41 bit 44 | } 45 | 46 | @Test 47 | public void testFindSingleFactorForAverageSizedRandomComposites() { 48 | testFindSingleFactorForRandomOddComposites(50, 69, 1000); 49 | } 50 | 51 | @Test 52 | public void testFindSingleFactorForRandomCompositesNearUpperBound() { 53 | testFindSingleFactorForRandomOddComposites(70, 86, 100); 54 | testFindSingleFactorForRandomOddComposites(87, 87, 1000); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/factor/tdiv/TDiv31BarrettTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.tdiv; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | import java.math.BigInteger; 19 | import java.util.List; 20 | 21 | import org.junit.BeforeClass; 22 | import org.junit.Test; 23 | 24 | import de.tilman_neumann.jml.factor.FactorTestBase; 25 | import de.tilman_neumann.jml.factor.squfof.SquFoF63; 26 | import de.tilman_neumann.util.ConfigUtil; 27 | 28 | public class TDiv31BarrettTest extends FactorTestBase { 29 | 30 | @BeforeClass 31 | public static void setup() { 32 | ConfigUtil.initProject(); 33 | // don't use CombinedFactorAlgorithm as verificationFactorizer because Tdiv is part of it 34 | setFactorizer(new TDiv31Barrett(), new SquFoF63()); 35 | } 36 | 37 | @Test 38 | public void testSmallestComposites() { 39 | List fails = testFullFactorizationOfComposites(100000); 40 | assertEquals("Failed to factor n = " + fails, 0, fails.size()); 41 | } 42 | 43 | @Test 44 | public void testSomeParticularNumbers() { 45 | assertFullFactorizationSuccess(621887327L, "853 * 729059"); // 30 bit 46 | assertFullFactorizationSuccess(676762483L, "877 * 771679"); // 30 bit 47 | } 48 | 49 | @Test 50 | public void testFindSingleFactorForRandomCompositesNearUpperBound() { 51 | testFindSingleFactorForRandomOddComposites(20, 31, 10000); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/factor/tdiv/TDiv31InverseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.tdiv; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | import java.math.BigInteger; 19 | import java.util.List; 20 | 21 | import org.junit.BeforeClass; 22 | import org.junit.Test; 23 | 24 | import de.tilman_neumann.jml.factor.FactorTestBase; 25 | import de.tilman_neumann.jml.factor.squfof.SquFoF63; 26 | import de.tilman_neumann.util.ConfigUtil; 27 | 28 | public class TDiv31InverseTest extends FactorTestBase { 29 | 30 | @BeforeClass 31 | public static void setup() { 32 | ConfigUtil.initProject(); 33 | // don't use CombinedFactorAlgorithm as verificationFactorizer because Tdiv is part of it 34 | setFactorizer(new TDiv31Inverse(), new SquFoF63()); 35 | } 36 | 37 | @Test 38 | public void testSmallestComposites() { 39 | List fails = testFullFactorizationOfComposites(100000); 40 | assertEquals("Failed to factor n = " + fails, 0, fails.size()); 41 | } 42 | 43 | @Test 44 | public void testSomeParticularNumbers() { 45 | assertFullFactorizationSuccess(621887327L, "853 * 729059"); // 30 bit 46 | assertFullFactorizationSuccess(676762483L, "877 * 771679"); // 30 bit 47 | } 48 | 49 | @Test 50 | public void testFindSingleFactorForRandomCompositesNearUpperBound() { 51 | testFindSingleFactorForRandomOddComposites(20, 31, 10000); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/factor/tdiv/TDiv31Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.factor.tdiv; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | import java.math.BigInteger; 19 | import java.util.List; 20 | 21 | import org.junit.BeforeClass; 22 | import org.junit.Test; 23 | 24 | import de.tilman_neumann.jml.factor.FactorTestBase; 25 | import de.tilman_neumann.jml.factor.squfof.SquFoF63; 26 | import de.tilman_neumann.util.ConfigUtil; 27 | 28 | public class TDiv31Test extends FactorTestBase { 29 | 30 | @BeforeClass 31 | public static void setup() { 32 | ConfigUtil.initProject(); 33 | // don't use CombinedFactorAlgorithm as verificationFactorizer because Tdiv is part of it 34 | setFactorizer(new TDiv31(), new SquFoF63()); 35 | } 36 | 37 | @Test 38 | public void testSmallestComposites() { 39 | List fails = testFullFactorizationOfComposites(100000); 40 | assertEquals("Failed to factor n = " + fails, 0, fails.size()); 41 | } 42 | 43 | @Test 44 | public void testSomeParticularNumbers() { 45 | assertFullFactorizationSuccess(621887327L, "853 * 729059"); // 30 bit 46 | assertFullFactorizationSuccess(676762483L, "877 * 771679"); // 30 bit 47 | } 48 | 49 | @Test 50 | public void testFindSingleFactorForRandomCompositesNearUpperBound() { 51 | testFindSingleFactorForRandomOddComposites(20, 31, 10000); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/powers/PurePowerTestRunner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.powers; 15 | 16 | import java.io.BufferedReader; 17 | import java.io.InputStreamReader; 18 | import java.math.BigInteger; 19 | 20 | import org.apache.logging.log4j.Logger; 21 | import org.apache.logging.log4j.LogManager; 22 | 23 | import de.tilman_neumann.jml.powers.PurePowerTest.Result; 24 | import de.tilman_neumann.util.ConfigUtil; 25 | 26 | /** 27 | * Test the pure powers by user inputs. 28 | * 29 | * @author Tilman Neumann 30 | */ 31 | public class PurePowerTestRunner { 32 | private static final Logger LOG = LogManager.getLogger(PurePowerTestRunner.class); 33 | 34 | /** 35 | * Test. 36 | * @param args ignored 37 | */ 38 | public static void main(String[] args) { 39 | ConfigUtil.initProject(); 40 | PurePowerTest powTest = new PurePowerTest(); 41 | while(true) { 42 | try { 43 | LOG.info("Insert test argument N:"); 44 | BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); 45 | String line = in.readLine(); 46 | String input = line !=null ? line.trim() : ""; 47 | //LOG.debug("input = >" + input + "<"); 48 | BigInteger N = new BigInteger(input); 49 | Result purePower = powTest.test(N); 50 | if (purePower == null) { 51 | LOG.info("N = " + N + " is not a pure power."); 52 | } else { 53 | LOG.info("N = " + N + " = " + purePower.base + "^" + purePower.exponent + " is a pure power!"); 54 | } 55 | } catch (Exception ex) { 56 | LOG.error("Error " + ex, ex); 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/primes/exact/SSOZJ5Runner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.primes.exact; 15 | 16 | import java.io.BufferedReader; 17 | import java.io.InputStreamReader; 18 | import java.math.BigInteger; 19 | 20 | import static de.tilman_neumann.jml.base.BigIntConstants.I_0; 21 | 22 | public class SSOZJ5Runner { 23 | 24 | /** 25 | * Run SSOZJ5. 26 | * @param args ignored 27 | */ 28 | public static void main(String[] args) { 29 | while (true) { 30 | try { 31 | System.out.println("\nPlease enter the range in integer(s) [] :"); 32 | BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); 33 | String line = in.readLine(); 34 | String[] splitted = line.split("\\s+"); 35 | int argc = splitted!=null ? splitted.length : 0; 36 | BigInteger start, stop; 37 | if (argc == 0 || argc > 2) { 38 | System.err.println("Illegal input."); 39 | continue; 40 | } 41 | if (argc == 1) { 42 | start = I_0; 43 | stop = new BigInteger(splitted[0]); 44 | } else { 45 | start = new BigInteger(splitted[0]); 46 | stop = new BigInteger(splitted[1]); 47 | } 48 | 49 | SSOZJ5.twinprimes_ssoz(start, stop); 50 | 51 | } catch (Exception e) { 52 | System.err.println("Error " + e); 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/primes/exact/SegmentedSievePerformanceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.primes.exact; 15 | 16 | import org.apache.logging.log4j.Logger; 17 | import org.apache.logging.log4j.LogManager; 18 | 19 | import de.tilman_neumann.util.ConfigUtil; 20 | 21 | /** 22 | * Performance test for the segmented sieve of Eratosthenes based on Kim Walisch's implementation at http://primesieve.org/segmented_sieve.html 23 | * 24 | * @author Tilman Neumann 25 | */ 26 | public class SegmentedSievePerformanceTest { 27 | private static final Logger LOG = LogManager.getLogger(SegmentedSievePerformanceTest.class); 28 | 29 | /** 30 | * Test performance without load caused by processPrime(). 31 | * @param args ignored 32 | */ 33 | public static void main(String[] args) { 34 | ConfigUtil.initProject(); 35 | long limit = 1000000; 36 | while (true) { 37 | long start = System.nanoTime(); 38 | CountingCallback callback = new CountingCallback(); // initialize count=0 for each limit 39 | SegmentedSieve sieve = new SegmentedSieve(callback); 40 | sieve.sieve(limit); 41 | LOG.info("Sieving x <= " + limit + " found " + callback.getCount() + " primes in " + ((System.nanoTime()-start) / 1000000) + " ms"); 42 | limit *= 10; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/primes/exact/SimpleSievePerformanceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.primes.exact; 15 | 16 | import org.apache.logging.log4j.Logger; 17 | import org.apache.logging.log4j.LogManager; 18 | 19 | import de.tilman_neumann.util.ConfigUtil; 20 | 21 | /** 22 | * Performance test for the simple sieve of Eratosthenes. 23 | * 24 | * @author Tilman Neumann 25 | */ 26 | public class SimpleSievePerformanceTest { 27 | private static final Logger LOG = LogManager.getLogger(SimpleSievePerformanceTest.class); 28 | 29 | /** 30 | * Test performance without load caused by processPrime(). 31 | * @param args ignored 32 | */ 33 | public static void main(String[] args) { 34 | ConfigUtil.initProject(); 35 | long limit = 1000000; 36 | while (limit < Integer.MAX_VALUE) { 37 | long start = System.nanoTime(); 38 | CountingCallback callback = new CountingCallback(); // initialize count=0 for each limit 39 | SimpleSieve sieve = new SimpleSieve(callback); 40 | sieve.sieve(limit); 41 | LOG.info("Sieving x <= " + limit + " found " + callback.getCount() + " primes in " + ((System.nanoTime()-start) / 1000000) + " ms"); 42 | limit *= 10; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/primes/probable/NextProbablePrimeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.primes.probable; 15 | 16 | import java.math.BigInteger; 17 | import java.util.Random; 18 | 19 | import org.apache.logging.log4j.Logger; 20 | import org.junit.BeforeClass; 21 | import org.junit.Test; 22 | import org.apache.logging.log4j.LogManager; 23 | 24 | import de.tilman_neumann.util.ConfigUtil; 25 | 26 | import static de.tilman_neumann.jml.base.BigIntConstants.*; 27 | import static org.junit.Assert.assertEquals; 28 | 29 | /** 30 | * Test of BPSW.nextProbablePrime(). 31 | * 32 | * @author Tilman Neumann 33 | */ 34 | public class NextProbablePrimeTest { 35 | private static final Logger LOG = LogManager.getLogger(NextProbablePrimeTest.class); 36 | private static final Random RNG = new Random(); 37 | 38 | private static final int NCOUNT = 1000; 39 | private static final int MAX_BITS = 150; 40 | 41 | private static final BPSWTest bpsw = new BPSWTest(); 42 | 43 | @BeforeClass 44 | public static void setup() { 45 | ConfigUtil.initProject(); 46 | } 47 | 48 | @Test 49 | public void testNextProbablePrime() { 50 | for (int nBits = 20; nBits<=MAX_BITS; nBits+=10) { 51 | LOG.info("Test correctness of " + NCOUNT + " N with " + nBits + " bits:"); 52 | int i = 0; 53 | while (i < NCOUNT) { 54 | BigInteger n = new BigInteger(nBits, RNG); 55 | if (n.equals(I_0)) continue; // exclude 0 from test set 56 | 57 | BigInteger correctValue = n.nextProbablePrime(); 58 | BigInteger bpswValue = bpsw.nextProbablePrime(n); 59 | assertEquals(correctValue, bpswValue); 60 | 61 | i++; 62 | } 63 | LOG.info(" Tested " + NCOUNT + " next probable primes..."); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/random/LehmerRng64MHTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.random; 15 | 16 | import static org.junit.Assert.assertTrue; 17 | 18 | import org.apache.logging.log4j.LogManager; 19 | import org.apache.logging.log4j.Logger; 20 | import org.junit.BeforeClass; 21 | import org.junit.Test; 22 | 23 | import de.tilman_neumann.util.ConfigUtil; 24 | 25 | /** 26 | * Tests of the LehmerRng64MH random number generator. 27 | * 28 | * @author Tilman Neumann 29 | */ 30 | public class LehmerRng64MHTest { 31 | private static final Logger LOG = LogManager.getLogger(LehmerRng64MHTest.class); 32 | 33 | private static final int NCOUNT = 1000000; 34 | 35 | private static final LehmerRng64MH rng = new LehmerRng64MH(); 36 | 37 | @BeforeClass 38 | public static void setup() { 39 | ConfigUtil.initProject(); 40 | } 41 | 42 | @Test 43 | public void testNextLongNoArgs() { 44 | long min = Long.MAX_VALUE, max = Long.MIN_VALUE; 45 | boolean generatesEven = false, generatesOdd = false; 46 | for (int i=0; imax) max = n; 50 | if ((n & 1) == 1) { 51 | generatesOdd = true; 52 | } else { 53 | generatesEven = true; 54 | } 55 | } 56 | LOG.debug(NCOUNT + " numbers from " + rng.getClass().getSimpleName() + ".nextLong() gave min = " + min + ", max = " + max); 57 | assertTrue(min < 0); 58 | assertTrue(generatesEven); 59 | assertTrue(generatesOdd); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/random/LehmerRng64Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.random; 15 | 16 | import static org.junit.Assert.assertTrue; 17 | 18 | import org.apache.logging.log4j.LogManager; 19 | import org.apache.logging.log4j.Logger; 20 | import org.junit.BeforeClass; 21 | import org.junit.Test; 22 | 23 | import de.tilman_neumann.util.ConfigUtil; 24 | 25 | /** 26 | * Tests of Lehmer's random number generator for 64 bit numbers. 27 | * 28 | * @author Tilman Neumann 29 | */ 30 | public class LehmerRng64Test { 31 | private static final Logger LOG = LogManager.getLogger(LehmerRng64Test.class); 32 | 33 | private static final int NCOUNT = 1000000; 34 | 35 | private static final LehmerRng64 rng = new LehmerRng64(); 36 | 37 | @BeforeClass 38 | public static void setup() { 39 | ConfigUtil.initProject(); 40 | } 41 | 42 | @Test 43 | public void testNextLongNoArgs() { 44 | long min = Long.MAX_VALUE, max = Long.MIN_VALUE; 45 | boolean generatesEven = false, generatesOdd = false; 46 | for (int i=0; imax) max = n; 50 | if ((n & 1) == 1) generatesOdd = true; else generatesEven = true; 51 | } 52 | LOG.debug(NCOUNT + " numbers from " + rng.getClass().getSimpleName() + ".nextLong() gave min = " + min + ", max = " + max); 53 | assertTrue(min < 0); 54 | assertTrue(generatesEven); 55 | assertTrue(generatesOdd); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/random/SecureRandomTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.random; 15 | 16 | import java.security.SecureRandom; 17 | import java.util.ArrayList; 18 | 19 | import org.junit.BeforeClass; 20 | import org.junit.Test; 21 | 22 | import de.tilman_neumann.util.ConfigUtil; 23 | 24 | import static org.junit.Assert.assertNotEquals; 25 | 26 | public class SecureRandomTest { 27 | 28 | @BeforeClass 29 | public static void setup() { 30 | ConfigUtil.initProject(); 31 | } 32 | 33 | @Test 34 | public void secureRandomSequenceIsNotReproducible() { 35 | SecureRandom secureRandom = new SecureRandom(); 36 | long seed = 2487568097L; 37 | 38 | secureRandom.setSeed(seed); 39 | ArrayList secureList1 = new ArrayList<>(); 40 | for (int n=0; n<20; n++) { 41 | secureList1.add(secureRandom.nextInt()); 42 | } 43 | 44 | secureRandom.setSeed(seed); 45 | ArrayList secureList2 = new ArrayList<>(); 46 | for (int n=0; n<20; n++) { 47 | secureList2.add(secureRandom.nextInt()); 48 | } 49 | assertNotEquals(secureList1, secureList2); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/roots/SqrtExactTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2025 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.roots; 15 | 16 | import java.math.BigInteger; 17 | import java.util.Random; 18 | 19 | import org.apache.logging.log4j.Logger; 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | import org.apache.logging.log4j.LogManager; 23 | 24 | import de.tilman_neumann.util.ConfigUtil; 25 | 26 | import static org.junit.Assert.*; 27 | 28 | /** 29 | * Test of SqrtExact. 30 | * 31 | * @author Tilman Neumann 32 | */ 33 | public class SqrtExactTest { 34 | private static final Logger LOG = LogManager.getLogger(SqrtExactTest.class); 35 | private static final Random RNG = new Random(); 36 | 37 | 38 | @Before 39 | public void setup() { 40 | ConfigUtil.initProject(); 41 | } 42 | 43 | @Test 44 | public void testRandomSqrts() { 45 | int testCount=1000; 46 | for (int bits=10; bits<=200; bits++) { 47 | for (int i=0; i. 13 | */ 14 | package de.tilman_neumann.jml.roots; 15 | 16 | import java.math.BigDecimal; 17 | 18 | import org.apache.logging.log4j.Logger; 19 | import org.apache.logging.log4j.LogManager; 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | 23 | import de.tilman_neumann.jml.precision.Scale; 24 | import de.tilman_neumann.util.ConfigUtil; 25 | 26 | /** 27 | * @author Tilman Neumann 28 | */ 29 | public class SqrtRealTest { 30 | private static final Logger LOG = LogManager.getLogger(SqrtRealTest.class); 31 | 32 | @Before 33 | public void setup() { 34 | ConfigUtil.initProject(); 35 | } 36 | 37 | @Test 38 | public void testSpecialCases() { 39 | BigDecimal input = new BigDecimal("36.0000090000"); 40 | BigDecimal sqrt = SqrtReal.sqrt(input, Scale.valueOf(5)); 41 | LOG.debug("sqrt(" + input + ") = " + sqrt); 42 | } 43 | 44 | @Test 45 | public void testBigArgs() { 46 | BigDecimal a = new BigDecimal("1312596401028278160"); 47 | BigDecimal sqrt = SqrtReal.sqrt(a, Scale.valueOf(5)); 48 | LOG.debug("sqrt(" + a + ") = " + sqrt); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/squareSums/FourSquaresFinderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.squareSums; 15 | 16 | import static org.junit.Assert.assertEquals; 17 | 18 | import java.math.BigInteger; 19 | 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | 23 | import de.tilman_neumann.util.ConfigUtil; 24 | 25 | /** 26 | * Tests for the FourSquaresFinder. 27 | * @author Tilman Neumann 28 | */ 29 | public class FourSquaresFinderTest { 30 | 31 | @Before 32 | public void setup() { 33 | ConfigUtil.initProject(); 34 | } 35 | 36 | @Test 37 | public void testRSA100() { 38 | BigInteger rsa100 = new BigInteger("1522605027922533360535618378132637429718068114961380688657908494580122963258952897654000350692006139"); // 330 bit 39 | FourSquaresFinder fsf = new FourSquaresFinder(); 40 | fsf.find(rsa100); 41 | BigInteger[] result = fsf.getSquareBases(); 42 | BigInteger x = result[0]; 43 | BigInteger y = result[1]; 44 | BigInteger z = result[2]; 45 | BigInteger w = result[3]; 46 | assertEquals(rsa100, x.multiply(x).add(y.multiply(y)).add(z.multiply(z)).add(w.multiply(w))); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/transcendental/ExpTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.transcendental; 15 | 16 | import java.math.BigDecimal; 17 | 18 | import org.junit.Before; 19 | import org.junit.Test; 20 | 21 | import de.tilman_neumann.jml.precision.Scale; 22 | import de.tilman_neumann.util.ConfigUtil; 23 | 24 | import static de.tilman_neumann.jml.base.BigDecimalConstants.*; 25 | import static org.junit.Assert.assertEquals; 26 | 27 | /** 28 | * Test class for floating point Exp function 29 | * 30 | * @author Tilman Neumann 31 | */ 32 | public class ExpTest { 33 | 34 | @Before 35 | public void setup() { 36 | ConfigUtil.initProject(); 37 | } 38 | 39 | @Test 40 | public void testExpZero() { 41 | // exp(0) with 10 digits precision 42 | BigDecimal one = Exp.exp(F_0, Scale.valueOf(10)); 43 | assertEquals(F_1.setScale(10), one); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/de/tilman_neumann/jml/transcendental/PiPerformanceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * java-math-library is a Java library focused on number theory, but not necessarily limited to it. It is based on the PSIQS 4.0 factoring project. 3 | * Copyright (C) 2018-2024 Tilman Neumann - tilman.neumann@web.de 4 | * 5 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 9 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 | * 11 | * You should have received a copy of the GNU General Public License along with this program; 12 | * if not, see . 13 | */ 14 | package de.tilman_neumann.jml.transcendental; 15 | 16 | import java.math.BigDecimal; 17 | 18 | import org.apache.logging.log4j.Logger; 19 | import org.apache.logging.log4j.LogManager; 20 | 21 | import de.tilman_neumann.jml.precision.Scale; 22 | import de.tilman_neumann.util.ConfigUtil; 23 | import de.tilman_neumann.util.TimeUtil; 24 | 25 | /** 26 | * Computations of Pi = 3.1415... to arbitrary precision. 27 | * @author Tilman Neumann 28 | */ 29 | public class PiPerformanceTest { 30 | private static final Logger LOG = LogManager.getLogger(PiPerformanceTest.class); 31 | 32 | private static final boolean ALL_SCALES = false; 33 | 34 | private static void testPi(Scale maxScale) { 35 | long t0 = System.currentTimeMillis(); 36 | if (ALL_SCALES) { 37 | for (Scale scale=Scale.valueOf(2); scale.compareTo(maxScale)<0; scale = scale.add(1)) { 38 | BigDecimal pi = Pi.pi(scale); 39 | LOG.debug("pi(" + scale + ") = " + pi); 40 | } 41 | } 42 | LOG.info("pi(" + maxScale + ") = " + Pi.pi(maxScale)); 43 | long t1 = System.currentTimeMillis(); 44 | LOG.info("Time of pi computation: " + TimeUtil.timeDiffStr(t0,t1)); 45 | } 46 | 47 | /** 48 | * Test. 49 | * 50 | * @param argv command line arguments, ignored 51 | */ 52 | public static void main(String[] argv) { 53 | ConfigUtil.initProject(); 54 | testPi(Scale.valueOf(1000)); 55 | testPi(Scale.valueOf(10000)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/resources/factor/qaTests.txt: -------------------------------------------------------------------------------- 1 | // 240 bit dummy 2 | 1357316441823493056202120961017108063376379759666182246430929139412183861 3 | // 250 bit 4 | 1357316441823493056202120961017108063376379759666182246430929139412183868533 5 | // 260 bit 6 | 1107224796774603449948546305729938401447751338813561240044571533528639609571501 7 | // 270 bit 8 | 1586185629147707553496127055790911794366012004492003609822516881508023581105559437 9 | // 280 bit 10 | 1574112859257556950849118598806900470328447386306080614279783582410150702105651131321 11 | // 290 bit 12 | 1402761347633791993742268518856897622806706038746889221365357052327242423705905949320497 13 | // 300 bit 14 | 1098737654117964557697625860172753043291322202327753685029993722599237699980019223954039481 15 | // 310 bit 16 | 1313173978125530240062666291667802307593283500865078723763089210441996922230901584699256844239 17 | // 320 bit 18 | 1479676734569234419956229114134820331562307516916922319321094593359310552192500673817039372374357 19 | --------------------------------------------------------------------------------