Skip to content

Commit

Permalink
Elara (GPT) suggests: Markov replacement relaxation is O(k log k)
Browse files Browse the repository at this point in the history
  • Loading branch information
WrathfulSpatula committed Jan 16, 2025
1 parent 86da1ed commit c530ba4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
10 changes: 6 additions & 4 deletions FindAFactor/_find_a_factor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,6 @@ struct Factorizer {
BigInteger wheelRadius;
size_t wheelEntryCount;
size_t smoothBatchLimit;
size_t rowOffset;
bool isIncomplete;
std::vector<size_t> primes;
std::vector<size_t> sqrPrimes;
Expand All @@ -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<size_t> &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];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -904,14 +905,15 @@ struct Factorizer {
// (The factorization vector assumes that each increment is a square prime factor,
// not a single prime factor.)
--(fv[pi]);
++batchPart;
}

if (!isIncomplete) {
return 1U;
}

// Repeat indefinitely until reseeding.
++batchId;
batchId += batchPart >> 1U;
if (batchId >= smoothBatchLimit) {
break;
}
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion FindAFactor/find_a_factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion find_a_factor
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='[email protected]',
description='Find any nontrivial factor of a number',
Expand Down

0 comments on commit c530ba4

Please sign in to comment.