-
Notifications
You must be signed in to change notification settings - Fork 21
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
2-value divmod #60
Comments
Interesting. I see in util.h:
which simplified things in the rootmod code. So clearly there are uses for it. Here it's just doing a gcd of the two values A,B in A/B mod N, leaving the modulo alone. So a single value is returned. Is there a good use for the two value return, and is there a good reason for or against including the modulo in the gcd? |
I think the two questions are coupled: in the above example given a relationship between two variables (x = 2y) and a known constraint on one (x == 6 mod 8) we want to find the corresponding constraint on the other. I'm not sure when it is useful to find gcddivmod(6, 2, 8) == 3 without also knowing that the relevant gcd was 2. For generality it's useful to consider separately each of the cases of pairwise gcd for this purported div2mod. Assuming (p, q, r) pairwise coprime, a > 1, I think I would expect:
The third case reflects the fact that the relationship x = 2y and the constraint x == 5 (mod 8) are incompatible. But in overview, that means nothing interesting happens unless gcd(b, n) > 1, and I think an unoptimized implementation would be something like:
I use this sort of transformation in my search for APs of integers with various properties (eg OEIS A165497, A165500, A292580): I'm building up a set of modular constraints (such as the x == 6 (mod 8) above); in some cases I then need to do arithmetic on them, eg in the above case to turn it into a constraint on y. |
Given eg x = 2y and x == 6 (mod 8), we do not know the value of y (mod 8), but we can say y == 3 (mod 4). Do we already have some variant of divmod, say div2mod, that would return (3, 4) for div2mod(6, 2, 8)? As far as I can see that just involves dividing all arguments by the common gcd before invoking divmod, so if we don't already have something like that it might be a useful convenience function to add.
The text was updated successfully, but these errors were encountered: