Skip to content

Commit 27dedba

Browse files
Gaussian elimination step is unnecessary
1 parent ab97eb2 commit 27dedba

File tree

2 files changed

+3
-57
lines changed

2 files changed

+3
-57
lines changed

FindAFactor/_find_a_factor.cpp

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -721,57 +721,6 @@ inline BigInteger modExp(BigInteger base, BigInteger exp, const BigInteger &mod)
721721
return result;
722722
}
723723

724-
// Perform Gaussian elimination on a binary matrix
725-
void gaussianElimination(std::map<BigInteger, boost::dynamic_bitset<size_t>> *matrix) {
726-
const unsigned cpuCount = CpuCount;
727-
const auto mBegin = matrix->begin();
728-
const size_t rows = matrix->size();
729-
const size_t cols = mBegin->second.size();
730-
std::vector<int> pivots(cols, -1);
731-
for (size_t col = 0U; col < cols; ++col) {
732-
auto colIt = mBegin;
733-
std::advance(colIt, col);
734-
735-
auto rowIt = colIt;
736-
for (size_t row = col; row < rows; ++row) {
737-
if (rowIt->second[col]) {
738-
std::swap(colIt->second, rowIt->second);
739-
pivots[col] = row;
740-
break;
741-
}
742-
++rowIt;
743-
}
744-
745-
if (pivots[col] == -1) {
746-
continue;
747-
}
748-
749-
const boost::dynamic_bitset<size_t> &c = colIt->second;
750-
for (unsigned cpu = 0U; cpu < CpuCount; ++cpu) {
751-
if (cpu >= rows) {
752-
break;
753-
}
754-
dispatch.dispatch([col, cpu, &cpuCount, &rows, &c, &mBegin]() -> bool {
755-
auto rowIt = mBegin;
756-
std::advance(rowIt, cpu);
757-
for (size_t row = cpu; ; row += cpuCount) {
758-
boost::dynamic_bitset<size_t> &r = rowIt->second;
759-
if ((row != col) && r[col]) {
760-
r ^= c;
761-
}
762-
if ((row + cpuCount) >= rows) {
763-
return false;
764-
}
765-
std::advance(rowIt, cpuCount);
766-
}
767-
768-
return false;
769-
});
770-
}
771-
dispatch.finish();
772-
}
773-
}
774-
775724
// Compute the prime factorization modulo 2
776725
boost::dynamic_bitset<size_t> factorizationVector(BigInteger num, const std::vector<uint16_t> &primes) {
777726
boost::dynamic_bitset<size_t> vec(primes.size(), false);
@@ -931,10 +880,7 @@ struct Factorizer {
931880
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
932881

933882
// Find factor via Gaussian elimination
934-
BigInteger findFactorViaGaussianElimination(const BigInteger &target, std::map<BigInteger, boost::dynamic_bitset<size_t>> *smoothNumberMap) {
935-
// Perform Gaussian elimination
936-
gaussianElimination(smoothNumberMap);
937-
883+
BigInteger findFactor(const BigInteger &target, std::map<BigInteger, boost::dynamic_bitset<size_t>> *smoothNumberMap) {
938884
// Check for linear dependencies and find a congruence of squares
939885
std::mutex rowMutex;
940886
BigInteger result = 1U;
@@ -1181,7 +1127,7 @@ std::string find_a_factor(const std::string &toFactorStr, const bool &isConOfSqr
11811127
futures.clear();
11821128

11831129
// This next section is for (Quadratic Sieve) Gaussian elimination.
1184-
result = worker.findFactorViaGaussianElimination(toFactor, &smoothNumberMap);
1130+
result = worker.findFactor(toFactor, &smoothNumberMap);
11851131
} while ((result == 1U) || (result == toFactor));
11861132

11871133
return boost::lexical_cast<std::string>(result);

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
setup(
2828
name='FindAFactor',
29-
version='3.2.1',
29+
version='3.2.2',
3030
author='Dan Strano',
3131
author_email='dan@unitary.fund',
3232
description='Find any nontrivial factor of a number',

0 commit comments

Comments
 (0)