Skip to content

factor::miller_rabin: Fix bug #1556#1557

Merged
Arcterus merged 2 commits into
uutils:masterfrom
nicoonoclaste:factor/issue_1556
Jun 24, 2020
Merged

factor::miller_rabin: Fix bug #1556#1557
Arcterus merged 2 commits into
uutils:masterfrom
nicoonoclaste:factor/issue_1556

Conversation

@nicoonoclaste
Copy link
Copy Markdown
Contributor

  • Added testcases for the bug.
  • Squashed it! >:3

@nicoonoclaste
Copy link
Copy Markdown
Contributor Author

nicoonoclaste commented Jun 23, 2020

@tdulcet, could you confirm that factor produces the same output as the GNU implementation on 10⁷..10⁸ with this fix? (I already confirmed they do the same on 2..10⁷)

@tdulcet
Copy link
Copy Markdown
Contributor

tdulcet commented Jun 24, 2020

Yes, I get the same output now for 2..10⁸:

$ time { seq 2 $(( 10 ** 8 )) | factor | sha256sum; }
b0f21acd0f9d4cfa81f3a828ffaa8f2b0a99eac30527142666705a54a461556b  -

real    1m18.101s
user    1m15.087s
sys     0m36.162s
$ time { seq 2 $(( 10 ** 8 )) | uu-factor | sha256sum; }
b0f21acd0f9d4cfa81f3a828ffaa8f2b0a99eac30527142666705a54a461556b  -

real    7m45.660s
user    7m50.180s
sys     0m11.295s

Thanks for fixing this so quickly!

@nicoonoclaste
Copy link
Copy Markdown
Contributor Author

@tdulcet Thank you for noticing (and reporting) the issue 💜

@Arcterus Arcterus merged commit 9de82d9 into uutils:master Jun 24, 2020
@Arcterus
Copy link
Copy Markdown
Collaborator

🎉

@nicoonoclaste nicoonoclaste deleted the factor/issue_1556 branch June 24, 2020 11:54
@Arcterus
Copy link
Copy Markdown
Collaborator

FYI, this commit drops performance by roughly 50%.

@nicoonoclaste
Copy link
Copy Markdown
Contributor Author

Oh, joy >_>'
makes a note to have a hard look in there, later.

@nicoonoclaste
Copy link
Copy Markdown
Contributor Author

nicoonoclaste commented Jun 25, 2020

@Arcterus Looks like the performance regression is fixed incidentally by #1554 : this fix causes more numbers (up to the entire basis) to be converted to Montgomery representation, which costs one double-width modular reduction, and that's really expensive on 128b numbers.

#1554 is not a complete fix, as this still causes a performance regression for instance above 2³².
I have ideas how to improve that (implementing Barrett reduction for Montgomery<u64>) but I would need to first set up a much better benchmarking harness, so we can check this is indeed an improvement.

@Arcterus
Copy link
Copy Markdown
Collaborator

Ah, well that’s rather convenient.

We should probably set up benchmarking project-wide as I imagine other utilities could benefit from improved performance as well.

@tdulcet
Copy link
Copy Markdown
Contributor

tdulcet commented Jun 25, 2020

@nbraud No problem. Here is the Bash script I have been using to test and benchmark this and the GNU factor implementation, if it is helpful. I adapted part of it from the GNU factor tests. Some of the tests will not work until this supports numbers greater than 264.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants