-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Composite number for nthroot_mod #18199
Conversation
✅ Hi, I am the SymPy bot (v149). I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like:
This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.6. Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
@smichr Could you please look into this. |
There is a lot of branching in the code using |
I think a better release notes entry will be:
The release notes are just meant to notify the users of major changes in the releases. If you want to include a reference to an important algorithm or method, you should do it in the documentation or a wiki guide, not the release notes. |
Don't know why the check failed. |
dont know why, but it was not able to import crt when at start of file. |
It seems that |
sympy/ntheory/residue_ntheory.py
Outdated
tot_roots = set() | ||
if e == 1: | ||
root = nthroot_mod(a, n, p, True) or [] | ||
if (pow(p, n) - a) % p == 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nthroot_mod
should return also this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No is doesn't. nthroot_mod(0, 5, 17, True)
returns None but it should return [0]. see issue #18212
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So let's get the PR that fixes that in first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am working on it. Will send it by tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think is_nthpow_residue(a, n, m)
works only when m is prime. Because is_nthpow_residue(36010, 8, 87382)
returns false but it has solutions [40208, 47174]
I think i have solved the issue #18212. when p is prime and a % p == 0, then [0] is the only root. |
But we still have to fix |
what happened? Is everything okay? |
When this happens, I rebase locally on a fresh copy of master, create a diff, check out master, delete my branch and recreate it from master and then apply the diff and commit it:
|
Codecov Report
@@ Coverage Diff @@
## master #18199 +/- ##
=============================================
+ Coverage 74.945% 74.972% +0.027%
=============================================
Files 642 649 +7
Lines 167182 167379 +197
Branches 39340 39393 +53
=============================================
+ Hits 125296 125489 +193
+ Misses 36359 36347 -12
- Partials 5527 5543 +16 |
Does this still need to be done? |
I will send a separate pr regarding |
this can be committed without that, right? |
yes |
sympy/ntheory/residue_ntheory.py
Outdated
diff = (n * pow(root, n - 1)) % p | ||
if diff != 0: | ||
for j in range(1, e): | ||
root = (root - (pow(root, n) - a)* mod_inverse(diff, p)) % pow(p, j + 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
root = (root - (pow(root, n) - a)* mod_inverse(diff, p)) % pow(p, j + 1) | |
root = (root - (rootn - a)* mod_inverse(diff, p)) % ppow |
sympy/ntheory/residue_ntheory.py
Outdated
tot_roots.update(nthroot_mod(a, n, p, True) or []) | ||
else: | ||
for root in nthroot_mod(a, n, p, True) or []: | ||
diff = (n * pow(root, n - 1)) % p |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diff = (n * pow(root, n - 1)) % p | |
rootn = pow(root, n) | |
diff = (rootn//root*n) % p |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
root can be zero , so its better to use pow(root, n-1) and avoid division by root. I have made the changes.
Just trying to factor out the power calculations. See what you think. |
OK, thanks for this work -- it's in! |
I think that more work is needed in the prime power modulus case.
|
ppow = p | ||
for j in range(1, e): | ||
ppow *= p | ||
root = (root - (rootn - a) * mod_inverse(diff, p)) % ppow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should probably be modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes you are right, the rootn will change with change in root
Fixes #17373
Fixes #17377
Fixes #18212
nthroot_mod
now supports composite moduli