Skip to content

Commit 0d25e11

Browse files
committed
Removed broken links and fixed spacing
1 parent 8e05198 commit 0d25e11

File tree

3 files changed

+32
-37
lines changed

3 files changed

+32
-37
lines changed

DESCRIPTION

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ NeedsCompilation: yes
2727
URL: https://github.com/jwood000/RcppBigIntAlgos, https://gmplib.org/,
2828
http://mathworld.wolfram.com/QuadraticSieve.html,
2929
http://micsymposium.org/mics_2011_proceedings/mics2011_submission_28.pdf,
30-
http://www.cs.virginia.edu/crab/QFS_Simple.pdf,
3130
https://www.math.colostate.edu/~hulpke/lectures/m400c/quadsievex.pdf,
3231
https://blogs.msdn.microsoft.com/devdev/2006/06/19/factoring-large-numbers-with-quadratic-sieve/
3332
BugReports: https://github.com/jwood000/RcppBigIntAlgos/issues

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,6 @@ If you want to interrupt a command which will take a long time, hit Ctrl + c, or
292292

293293
* Credit to [primo](<https://codegolf.stackexchange.com/users/4098/primo>) (Mike Tryczak) and his excellent answer to [Fastest semiprime factorization](<https://codegolf.stackexchange.com/a/9088/52987>).
294294

295-
* [The Quadratic Sieve Factoring Algorithm](<http://www.cs.virginia.edu/crab/QFS_Simple.pdf>) by Eric Landquist.
296-
297295
* [Factoring large numbers with quadratic sieve](<https://blogs.msdn.microsoft.com/devdev/2006/06/19/factoring-large-numbers-with-quadratic-sieve/>) on MSDN Archive.
298296

299297
* A really nice concise example is given here: [Factorization of _n = 87463_ with the Quadratic Sieve](<https://www.math.colostate.edu/~hulpke/lectures/m400c/quadsievex.pdf>)

src/QuadraticSieve.cc

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -329,60 +329,60 @@ void QuadraticSieve(mpz_t myNum, mpz_t *const factors,
329329
mpzFSzLIMIT <<= 1;
330330
Grow(mpzFacBase, mpzFacSize, mpzFSzLIMIT);
331331
}
332-
332+
333333
mpz_set(mpzFacBase[mpzFacSize], Atemp);
334334
++mpzFacSize;
335335

336336
TonelliShanksC(myNum, Atemp, TS);
337-
337+
338338
if (mpz_cmp(TS[1], TS[2]) > 0) {
339339
mpz_set(Btemp, TS[1]);
340340
} else {
341341
mpz_set(Btemp, TS[2]);
342342
}
343-
343+
344344
mpz_mul_2exp(temp, Btemp, 1);
345345
mpz_invert(temp, temp, Atemp);
346346
mpz_pow_ui(B, Btemp, 2u);
347-
347+
348348
mpz_sub(B, myNum, B);
349349
mpz_mul(B, B, temp);
350350
mpz_add(B, B, Btemp);
351-
351+
352352
mpz_pow_ui(A, Atemp, 2u);
353353
mpz_mod(B, B, A);
354-
354+
355355
mpz_pow_ui(C, B, 2u);
356356
mpz_sub(C, C, myNum);
357357
mpz_divexact(C, C, A);
358-
358+
359359
for (std::size_t i = 0, row = 0; i < facSize; ++i, row += 2) {
360360
mpz_invert(Atemp2, A, mpzFacBase[i]);
361361

362362
mpz_ui_sub(temp, SieveDist[row], B);
363363
mpz_mul(temp, temp, Atemp2);
364364
mpz_mod_ui(temp, temp, facBase[i]);
365365
polySieveD[row] = mpz_get_ui(temp);
366-
366+
367367
mpz_ui_sub(temp, SieveDist[row + 1], B);
368368
mpz_mul(temp, temp, Atemp2);
369369
mpz_mod_ui(temp, temp, facBase[i]);
370370
polySieveD[row + 1] = mpz_get_ui(temp);
371371
}
372-
372+
373373
for (std::size_t i = 0; i < DoubleLenB; ++i) {
374374
mpz_mul_si(temp, B, 2 * myInterval[i]);
375375
mpz_add(temp, temp, C);
376376
mpz_mul_si(Atemp2, A, myInterval[i]);
377377
mpz_mul_si(Atemp2, Atemp2, myInterval[i]);
378378
mpz_add(sqrDiff[i], Atemp2, temp);
379379
}
380-
380+
381381
sieveLists(facSize, facBase, DoubleLenB, sqrDiff.get(),
382382
LnFB, myLogs, minPrime, polySieveD, lowBound);
383-
383+
384384
largeLogs.clear();
385-
385+
386386
for (std::size_t i = 0; i < DoubleLenB; ++i)
387387
if (myLogs[i] > theCut)
388388
largeLogs.push_back(i);
@@ -400,7 +400,7 @@ void QuadraticSieve(mpz_t myNum, mpz_t *const factors,
400400
mpz_abs(intVal, intVal);
401401
primeIndexVec.push_back(0u);
402402
}
403-
403+
404404
for (std::size_t i = 0; i < facSize; ++i) {
405405
while (mpz_divisible_ui_p(intVal, facBase[i])) {
406406
mpz_divexact_ui(intVal, intVal, facBase[i]);
@@ -418,10 +418,10 @@ void QuadraticSieve(mpz_t myNum, mpz_t *const factors,
418418
} else if (mpz_cmp_d(intVal, Significand53) < 0) {
419419
const uint64_t myKey = static_cast<uint64_t>(mpz_get_d(intVal));
420420
const auto pFacIt = partFactorsMap.find(myKey);
421-
421+
422422
if (pFacIt != partFactorsMap.end()) {
423423
const auto trackIt = keepingTrack.find(myKey);
424-
424+
425425
if (trackIt != keepingTrack.end()) {
426426
coFactorIndexVec.push_back(trackIt->second);
427427
} else {
@@ -433,14 +433,14 @@ void QuadraticSieve(mpz_t myNum, mpz_t *const factors,
433433

434434
for (const auto p: pFacIt->second)
435435
primeIndexVec.push_back(p);
436-
436+
437437
powsOfPartials.push_back(primeIndexVec);
438438
const auto intervalIt = partIntvlMap.find(myKey);
439-
439+
440440
mpz_add(temp, temp, B);
441441
mpz_mul(partialInterval[nPartial],
442442
temp, intervalIt->second);
443-
443+
444444
partFactorsMap.erase(pFacIt);
445445
partIntvlMap.erase(intervalIt);
446446
++nPartial;
@@ -455,7 +455,7 @@ void QuadraticSieve(mpz_t myNum, mpz_t *const factors,
455455
++nPolys;
456456
currLim = nSmooth + nPartial;
457457
const auto checkPoint3 = std::chrono::steady_clock::now();
458-
458+
459459
if ((checkPoint3 - checkPoint1) > checkInterTime) {
460460
// Check for user interrupt and udpate timepoint
461461
RcppThread::checkUserInterrupt();
@@ -474,7 +474,7 @@ void QuadraticSieve(mpz_t myNum, mpz_t *const factors,
474474

475475
const std::size_t matRow = nSmooth + nPartial;
476476
const std::size_t matWidth = coFactorInd + mpzFacSize + 1;
477-
477+
478478
auto newTestInt = FromCpp14::make_unique<mpz_t[]>(matRow);
479479
std::vector<uint8_t> newMat(matRow * matWidth, 0);
480480

@@ -484,32 +484,31 @@ void QuadraticSieve(mpz_t myNum, mpz_t *const factors,
484484

485485
mpz_init_set(newTestInt[r], smoothInterval[r]);
486486
}
487-
487+
488488
if ((coFactorInd + mpzFacSize) >= mpzFSzLIMIT) {
489489
mpzFSzLIMIT <<= 1;
490490
Grow(mpzFacBase, mpzFacSize, mpzFSzLIMIT);
491491
}
492-
492+
493493
for (std::size_t i = 0, j = mpzFacSize; i < coFactorInd; ++i, ++j)
494494
mpz_set(mpzFacBase[j], largeCoFactors[i]);
495-
495+
496496
for (std::size_t i = 0, r = nSmooth,
497497
row = matWidth * nSmooth; i < nPartial; ++i, ++r, row += matWidth) {
498-
499-
mpz_init_set(newTestInt[r], partialInterval[i]);
500-
498+
501499
for (const auto p: powsOfPartials[i])
502500
++newMat[row + p];
503-
501+
504502
newMat[row + mpzFacSize + 1 + coFactorIndexVec[i]] = 2u;
503+
mpz_init_set(newTestInt[r], partialInterval[i]);
505504
}
506-
505+
507506
solutionSearch(newMat, matRow, matWidth, myNum,
508507
mpzFacBase.get(), newTestInt.get(), factors);
509-
508+
510509
for (std::size_t i = 0; i < matRow; ++i)
511510
mpz_clear(newTestInt[i]);
512-
511+
513512
newTestInt.reset();
514513
extraFacs += 5;
515514

@@ -518,16 +517,14 @@ void QuadraticSieve(mpz_t myNum, mpz_t *const factors,
518517

519518
makeStats(loopLimit, loopLimit, nPolys, nSmooth,
520519
nPartial, lastLim, checkPoint3 - checkPoint0);
521-
520+
522521
RcppThread::Rcout << "\n" << std::endl;
523522
}
524523
}
525524

526525
for (std::size_t i = 0; i < DoubleLenB; ++i)
527526
mpz_clear(sqrDiff[i]);
528527

529-
sqrDiff.reset();
530-
531528
for (std::size_t i = 0; i < mpzContainerSize; ++i) {
532529
mpz_clear(smoothInterval[i]);
533530
mpz_clear(partialInterval[i]);
@@ -537,18 +534,19 @@ void QuadraticSieve(mpz_t myNum, mpz_t *const factors,
537534
for (std::size_t i = 0; i < mpzFSzLIMIT; ++i)
538535
mpz_clear(mpzFacBase[i]);
539536

537+
sqrDiff.reset();
540538
mpzFacBase.reset();
541539
smoothInterval.reset();
542540
partialInterval.reset();
543541
largeCoFactors.reset();
544-
coFactorIndexVec.clear();
545542

546543
for (auto v: partIntvlMap)
547544
mpz_clear(v.second);
548545

549546
partIntvlMap.clear();
550547
partFactorsMap.clear();
551548
keepingTrack.clear();
549+
coFactorIndexVec.clear();
552550

553551
mpz_clear(temp); mpz_clear(sqrtInt); mpz_clear(A);
554552
mpz_clear(C); mpz_clear(Atemp); mpz_clear(Btemp);

0 commit comments

Comments
 (0)