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

fixed is_nthpow_residue #18398

Merged
merged 6 commits into from
Jan 22, 2020
Merged

fixed is_nthpow_residue #18398

merged 6 commits into from
Jan 22, 2020

Conversation

abhinav-anand-addepar
Copy link
Member

@abhinav-anand-addepar abhinav-anand-addepar commented Jan 19, 2020

Fixes #18394

  • ntheory
    • is_nthpow_residue no longer raises ValueError when a < 0
    • polynomial_congruence recognizes x**n + a = 0 mod m as a special case

@sympy-bot
Copy link

sympy-bot commented Jan 19, 2020

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.

Fixes #18394 

<!-- BEGIN RELEASE NOTES -->
* ntheory
  * `is_nthpow_residue` no longer raises ValueError when a < 0
  * `polynomial_congruence` recognizes x**n + a = 0 mod m as a special case
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@codecov
Copy link

codecov bot commented Jan 19, 2020

Codecov Report

Merging #18398 into master will increase coverage by 0.011%.
The diff coverage is 87.5%.

@@              Coverage Diff              @@
##            master    #18398       +/-   ##
=============================================
+ Coverage   75.292%   75.304%   +0.011%     
=============================================
  Files          633       637        +4     
  Lines       166944    167071      +127     
  Branches     39396     39417       +21     
=============================================
+ Hits        125697    125812      +115     
- Misses       35709     35719       +10     
- Partials      5538      5540        +2

@@ -1533,6 +1532,8 @@ def polynomial_congruence(expr, m):
if rank == 2:
return quadratic_congruence(0, coefficients[0], coefficients[1],
m)
if coefficients[0] == 1 and all(v == 0 for v in coefficients[1:-1]):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if coefficients[0] == 1 and all(v == 0 for v in coefficients[1:-1]):
if coefficients[0] == 1 and 1 + coefficients[-1] = sum(coefficients):

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the coefficient is negative this might give wrong result. I think I should take mod m of all coefficients then this suggestion can be correctly implemented.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, what you have is better.

Copy link
Member

@smichr smichr Jan 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why not

if not any(coefficients[1: -1]):
    g = igcd(coefficients[0], coefficients[-1])
    if coefficients[0]//g == 1:
        return nthroot_mod(-coefficients[-1]//g, rank - 1, m, True)

In that case 2*x**2 + 8 will be reduced to x**2 + 4.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smichr yes but in this case also we have to take mod m of the coefficients. For example:
for x**5 + 16 x + 7 = 0 mod 8. But this can be reduced to x**5 + 7. But (if not any(coefficients[1:-1])) will not catch this unless coefficients = coefficients mod m.
Also by dividing the coefficients[0] with gcd might result in loss of some roots.
For example : 2*x**2 + 8 = 0 mod 10has roots [1,4,6,9] but x**2 + 4 = 0 mod 10 has
roots [4,6] because mod_inv(2,10) does not exist.

@oscarbenjamin
Copy link
Contributor

oscarbenjamin commented Jan 20, 2020

I don't know whether the changes here are good but the release note can be improved. Try to write a release note that makes sense for end users. They don't care about internal details: they just want know what has changed from the outside. You can see examples of release notes here:
https://github.com/sympy/sympy/wiki/Release-Notes-for-1.5

@smichr
Copy link
Member

smichr commented Jan 21, 2020

I edited release notes.

@smichr smichr merged commit 8a7dc8e into sympy:master Jan 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Noticed several bugs in residue.py
5 participants