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

Consider providing a more number-theoretic discussion on the expmod function and ex. 1.25 #895

Open
kedarmhaswade opened this issue May 19, 2023 · 0 comments

Comments

@kedarmhaswade
Copy link

The expmod function in §1.2.6 uses a subtlety. It is perhaps not immediately clear to (even careful) readers that for any three positive integers a, b, c, (ab) % c equals (r1r2) % c (where r1 = a % c and r2 = b % c).

Perhaps the main discussion around the function expmod should encourage readers to arrive at the above result (either through a footnote or through an exercise). Here is my humble attempt.

Relatedly, in exercise 1.25, we ask if Alyssa is correct in saying that fast_expt can effectively replace expmod. Whereas the answer provided there is correct, I believe that we need to establish if the remainder is not preserved in a two's complement notation even when the silent overflow occurs. I guess it is not preserved, and, as such, it is better to do r1r2 % c to reduce the likelihood of an overflow. I just feel that for the sake of completeness, we should mention this.

Another question: In the case of an odd exponent, shouldn't expmod be modified to

   : ((base % m) * expmod(base, exp - 1, m))) % m;

(just for the sake of uniformity)?

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

No branches or pull requests

1 participant