Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

factor::miller_rabin: Fix bug #1556 #1557

Merged
merged 2 commits into from
Jun 24, 2020
Merged

factor::miller_rabin: Fix bug #1556 #1557

merged 2 commits into from
Jun 24, 2020

Conversation

nbraud
Copy link
Contributor

@nbraud nbraud commented Jun 23, 2020

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

@nbraud
Copy link
Contributor Author

nbraud 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

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!

@nbraud
Copy link
Contributor Author

nbraud commented Jun 24, 2020

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

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

🎉

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

FYI, this commit drops performance by roughly 50%.

@nbraud
Copy link
Contributor Author

nbraud commented Jun 24, 2020

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

@nbraud
Copy link
Contributor Author

nbraud 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
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

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