From c530ba4f62938af43bceaab771503f640abd2ab0 Mon Sep 17 00:00:00 2001 From: WrathfulSpatula Date: Thu, 16 Jan 2025 16:05:32 -0500 Subject: [PATCH] Elara (GPT) suggests: Markov replacement relaxation is O(k log k) --- FindAFactor/_find_a_factor.cpp | 10 ++++++---- FindAFactor/find_a_factor.py | 2 +- find_a_factor | 2 +- pyproject.toml | 2 +- setup.py | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/FindAFactor/_find_a_factor.cpp b/FindAFactor/_find_a_factor.cpp index b0eff5c..6e7bbae 100644 --- a/FindAFactor/_find_a_factor.cpp +++ b/FindAFactor/_find_a_factor.cpp @@ -756,7 +756,6 @@ struct Factorizer { BigInteger wheelRadius; size_t wheelEntryCount; size_t smoothBatchLimit; - size_t rowOffset; bool isIncomplete; std::vector primes; std::vector sqrPrimes; @@ -765,7 +764,7 @@ struct Factorizer { Factorizer(const BigInteger &tfsqr, const BigInteger &tf, const BigInteger &tfsqrt, const BigInteger &range, size_t nodeCount, size_t nodeId, size_t w, size_t spl, const std::vector &p, ForwardFn fn) : dis(0U, p.size() - 1U), wordDis(0ULL, -1ULL), toFactorSqr(tfsqr), toFactor(tf), toFactorSqrt(tfsqrt), batchRange(range), batchNumber(0U), batchOffset(nodeId * range), - batchTotal(nodeCount * range), wheelRadius(1U), wheelEntryCount(w), smoothBatchLimit(spl), rowOffset(p.size()), isIncomplete(true), primes(p), forwardFn(fn) + batchTotal(nodeCount * range), wheelRadius(1U), wheelEntryCount(w), smoothBatchLimit(spl), isIncomplete(true), primes(p), forwardFn(fn) { for (size_t i = 0U; i < primes.size(); ++i) { const size_t& p = primes[i]; @@ -829,6 +828,7 @@ struct Factorizer { // The number is now a smooth perfect square larger than toFactor. // Keep going until we exceed the square of toFactor. // We are given a smooth perfect square as input. + size_t batchPart = 0U; while (perfectSquare < toFactorSqr) { // Compute x and y const BigInteger x = perfectSquare % toFactor; @@ -859,6 +859,7 @@ struct Factorizer { // (The factorization vector assumes that each increment is a square prime factor, // not a single prime factor.) ++(fv[pi]); + ++batchPart; } if (!isIncomplete) { @@ -904,6 +905,7 @@ struct Factorizer { // (The factorization vector assumes that each increment is a square prime factor, // not a single prime factor.) --(fv[pi]); + ++batchPart; } if (!isIncomplete) { @@ -911,7 +913,7 @@ struct Factorizer { } // Repeat indefinitely until reseeding. - ++batchId; + batchId += batchPart >> 1U; if (batchId >= smoothBatchLimit) { break; } @@ -1098,7 +1100,7 @@ std::string find_a_factor(std::string toFactorStr, size_t method, size_t nodeCou // This manages the work of all threads. Factorizer worker(toFactor * toFactor, toFactor, fullMaxBase, nodeRange, nodeCount, nodeId, - wheelEntryCount, batchSizeMultiplier * (isFactorFinder ? smoothPrimes.size() * smoothPrimes.size() : (wheelEntryCount << 1U)), + wheelEntryCount, (size_t)(batchSizeMultiplier * smoothPrimes.size() * log(smoothPrimes.size())), smoothPrimes, forward(SMALLEST_WHEEL)); // Square of count of smooth primes, for FACTOR_FINDER batch multiplier base unit, was suggested by Lyra (OpenAI GPT) diff --git a/FindAFactor/find_a_factor.py b/FindAFactor/find_a_factor.py index af3c457..06a3c55 100644 --- a/FindAFactor/find_a_factor.py +++ b/FindAFactor/find_a_factor.py @@ -17,7 +17,7 @@ def find_a_factor(n, gear_factorization_level=int(os.environ.get('FINDAFACTOR_GEAR_FACTORIZATION_LEVEL')) if os.environ.get('FINDAFACTOR_GEAR_FACTORIZATION_LEVEL') else 11, wheel_factorization_level=int(os.environ.get('FINDAFACTOR_WHEEL_FACTORIZATION_LEVEL')) if os.environ.get('FINDAFACTOR_WHEEL_FACTORIZATION_LEVEL') else 11, smoothness_bound_multiplier=float(os.environ.get('FINDAFACTOR_SMOOTHNESS_BOUND_MULTIPLIER')) if os.environ.get('FINDAFACTOR_SMOOTHNESS_BOUND_MULTIPLIER') else 1.0, - batch_size_multiplier=float(os.environ.get('FINDAFACTOR_BATCH_SIZE_MULTIPLIER')) if os.environ.get('FINDAFACTOR_BATCH_SIZE_MULTIPLIER') else 4.0): + batch_size_multiplier=float(os.environ.get('FINDAFACTOR_BATCH_SIZE_MULTIPLIER')) if os.environ.get('FINDAFACTOR_BATCH_SIZE_MULTIPLIER') else 192.0): return int(_find_a_factor._find_a_factor(str(n), int(method), node_count, node_id, diff --git a/find_a_factor b/find_a_factor index 6a0fe63..718443c 100755 --- a/find_a_factor +++ b/find_a_factor @@ -21,7 +21,7 @@ def main(): gear_factorization_level = int(os.environ.get('FINDAFACTOR_GEAR_FACTORIZATION_LEVEL')) if os.environ.get('FINDAFACTOR_GEAR_FACTORIZATION_LEVEL') else 11 wheel_factorization_level = int(os.environ.get('FINDAFACTOR_WHEEL_FACTORIZATION_LEVEL')) if os.environ.get('FINDAFACTOR_WHEEL_FACTORIZATION_LEVEL') else 11 smoothness_bound_multiplier = float(os.environ.get('FINDAFACTOR_SMOOTHNESS_BOUND_MULTIPLIER')) if os.environ.get('FINDAFACTOR_SMOOTHNESS_BOUND_MULTIPLIER') else 1.0 - batch_size_multiplier=float(os.environ.get('FINDAFACTOR_BATCH_SIZE_MULTIPLIER')) if os.environ.get('FINDAFACTOR_BATCH_SIZE_MULTIPLIER') else 4.0 + batch_size_multiplier=float(os.environ.get('FINDAFACTOR_BATCH_SIZE_MULTIPLIER')) if os.environ.get('FINDAFACTOR_BATCH_SIZE_MULTIPLIER') else 192.0 if argv_len > 2: method = FactoringMethod(int(sys.argv[2])) diff --git a/pyproject.toml b/pyproject.toml index 43f5225..e2b59a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta" [project] name = "FindAFactor" -version = "4.5.0" +version = "4.5.1" requires-python = ">=3.8" description = "Find any nontrivial factor of a number" readme = {file = "README.txt", content-type = "text/markdown"} diff --git a/setup.py b/setup.py index 8e29d46..316e1da 100644 --- a/setup.py +++ b/setup.py @@ -40,7 +40,7 @@ def build_extension(self, ext): setup( name='FindAFactor', - version='4.5.0', + version='4.5.1', author='Dan Strano', author_email='stranoj@gmail.com', description='Find any nontrivial factor of a number',