-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Mod for complex arguments #11391
Comments
Mod for complex number will help in these types of cases in solveset.
|
I think |
I agree with @siefkenj. The sense of Mod between 2 complex numbers exists only in special rings, e.g. Gaussian integers or Eisenstein integers or even Kummer ring. We should have a norm for this numbers also. In this case we can go further: Euler's function phi(z), gcd(z_1, z_2) etc. |
@Shekharrajak I don't think Mod is needed in that case. log is already assumed to be single-valued. |
@asmeurer , It is coming from eval_imageset (canonical shift). I am not sure about this. (I think it is for like : |
I found a link.
where m, n is real or complex numbers. for any complex number Floor(z) = Floor(Re(z)) + I*Floor(Im(z)) For example : since
|
We do have that same definition for |
By that definition, larger real numbers mod |
@asmeurer , For large number e.g. (
same as wolframalpha |
This method fails, when both
but ans is |
If Mod should be defined for complex arguments, one should probably begin by considering its range of values for arbitrary complex arguments (and fixed modulus arguments). On the real line, the range of Mod is an interval. It is typically a fundamental domain of a periodic function. The values of such a function in the fundamental domain determine its values elsewhere. The value at an arbitrary point is the same as the value at the Mod point in the fundamental domain. In the complex plane there are many more possibilities for such fundamental domains. However, there are only two choices that are in general mathematical use.
|
I think the difficulty stems from the fact that there are (at least) two distinct notions at play that happen to be compatible in simple cases only:
Consider this example: In the ring of Gaussian integers this would mean finding q, r (in C) such that But what if the user actually intended to Given all of the above, I'd say there are two possible choices:
Anyway, in the above-mentioned (unnecessary) |
Just a short observation using 1.5:
Of particular note is that
|
Hmm,
This auto-simplification is unexpected, especially with the |
More strangeness, this time
|
The floor definition seems like a good fundamental thing to keep. That means that This definition is used to match the Python definition of mod for negative arguments (which doesn't match other languages, see https://stackoverflow.com/questions/3883004/the-modulo-operation-on-negative-numbers-in-python). |
This is going to be a long post... I actually wanted to just say "Agreed, let's keep the floor definition, just like Wolfram", but then something came up while playing around with WolframAlpha. Here are my findings:
The numerical value of the quotient is Obviously this is not compatible with the standard floor-based definition on the real line.
And this muddled definition/implementation then leads to the following bug: My best guess is that Wolfram did recognize that the floor-based definition is not really mathematical useful on the complex plane, so they decided to concoct some Frankensteinian creation that
To sum it up:
IMHO there are two options: In any case, especially B), Mod's docstring should mention the caveats:
|
I agree whatever we need to do we definitely need to document it. The documentation should also include the proper ways to do both of those things. We sometimes fall short in documenting reasons on why we define certain functions in certain ways, especially regarding extensions of functions normally defined on integers to complex numbers. It's still on my todo list to document the discussion from #14577.
Did we discuss above a definition of taking mod of the real and imaginary parts separately? That would do that. There's also I personally wouldn't be surprised that |
No, but I can see its appeal: It's simple and pragmatic enough and could be documented along the lines "Mod is intended for reals only but for convenience the following behavior for complex arguments has been implemented (...) The rewrite(floor) method is only equivalent over the reals."
for |
We can change rewrite(floor) if we go with that. It still reduces to the formula for both arguments real. |
Oh, that's right of course. Even better. |
How should Mod behave fo complex arguments?
The text was updated successfully, but these errors were encountered: