-
-
Notifications
You must be signed in to change notification settings - Fork 647
Added code to calculate crt for non-coprime moduli in Integer #39716
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
Added code to calculate crt for non-coprime moduli in Integer #39716
Conversation
Documentation preview for this PR (built with commit 46f74e1; changes) is ready! 🎉 |
In line 6965, you need to change
In line 6978, you need double-backticks, not single-backticks, around In line 6995, please change I think line 6996 will be more readable if you use an f-string to create the error message: This is very minor, but you reversed the order of |
…r message slightly.
@DaveWitteMorris I've made the changes suggested. I also added the modulo _m.lcm(_n) to the case where m and n are co-prime as we changed the documentation to specify that. Let me know if I should change it back. |
…o lcm(n,m) back to modulo m * n.
@DaveWitteMorris I think that no more changes are required for this PR. If you could set it to positive review that would be great! |
Looks good, but I think it would be better to get rid of the nested - if not g.is_one():
- if (self % g) != (_y % g):
- raise ValueError(f"no solution to crt problem since gcd({_m},{_n}) does not divide {self} - {_y}")
+ if not g.is_one() and ((self % g) != (_y % g)):
+ raise ValueError(f"no solution to crt problem since gcd({_m},{_n}) does not divide {self} - {_y}")
return (self + g * Integer(0).crt((_y - self) // g, _m // g, _n // g)) % _m.lcm(_n) Also, I think the Checking I think the CI errors are probably not related to this PR, but I will need to run |
@DaveWitteMorris I don't really understand your comment. Firstly you can't really get rid of the nested if statement that easily as the line I am also not sure why I have removed the double if statement and fixed the line length issue in my newest commit. Let me know if my changes make sense. I decided to check if |
Sorry, I misread the code when I suggested getting rid of the nested |
My comment about speed was just that I would expect checking |
I ran doctests locally and got no errors, so the CI failure does not seem to be caused by this ticket. |
Related to issue #32487. Added code to compute
crt
inInteger
when the two moduli are not coprime. Also changed error produced when a solution does not exist. Error message is based of the error message found in thecrt
method insrc\sage\arith\misc.py
.📝 Checklist
⌛ Dependencies