-
-
Notifications
You must be signed in to change notification settings - Fork 5.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
Add explicit mention of branch cuts to log
, sqrt
, angle
docstrings
#52970
Conversation
Pkg test failed in CI is unrealted. |
By the way, I can't seem to see test logs anymore. https://buildkite.com/julialang/julia-master/builds/32444 just shows me a blank page. Any idea why this might be, do I need permissions or to log in to something? |
No, you don't. test x86_64-w64-mingw32, test x86_64-linux-gnu: relocatedepot failed
I passed the |
Thanks, I now think the problem is my end, as I can see tests in a different browser. Maybe this PR is ready, unless anyone has complaints about the precise wording etc? |
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.
LGTM.
When the math function has a separate documentation page, we can try adding a 2D angle plot of the complex plane that that can visualize the branch cuts.
Or even 3D Riemann surface:
sqrt from WikiP: https://en.wikipedia.org/wiki/Square_root#/media/File:Riemann_surface_sqrt.svg
|
||
Throws [`DomainError`](@ref) for negative [`Real`](@ref) arguments. | ||
Use complex negative arguments instead. Note that `sqrt` has a branch cut | ||
along the negative real axis. |
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.
WikiP: https://en.wikipedia.org/wiki/Square_root#/media/File:Complex_sqrt_leaf1.jpg
sage: https://doc.sagemath.org/html/en/reference/plotting/sage/plot/complex_plot.html#codecell4
using UnicodePlots
X = repeat(collect(-20:20)', outer=(41, 1));
Y = repeat(collect(20:-1:-20), outer=(1,41));
grid = complex.(X, Y) ./ 10;
Z = sqrt.(grid);
zangle = angle.(Z);
heatmap(zangle; xfact=0.1, yfact=0.1, xoffset=-2, yoffset=-2)
|
||
Throws [`DomainError`](@ref) for negative [`Real`](@ref) arguments. | ||
Use complex arguments to obtain complex results. | ||
Has a branch cut along the negative real axis, for which `-0.0im` is taken to be below the axis. |
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.
![image](https://private-user-images.githubusercontent.com/5158738/301049582-74017d47-bf44-4a16-8f1a-2bf7eb9b19c0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM2MDQ0NjgsIm5iZiI6MTcyMzYwNDE2OCwicGF0aCI6Ii81MTU4NzM4LzMwMTA0OTU4Mi03NDAxN2Q0Ny1iZjQ0LTRhMTYtOGYxYS0yYmY3ZWI5YjE5YzAucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgxNCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MTRUMDI1NjA4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MDQxMzdhZGFiOTkxYjlkZmE0NGVjN2E3OGJkNThlMjM3OTNjOTczMThlMWQ1OGE1OWUwY2M3YTYyYjViYzZkNiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.8Sh9SGhDI1L8PZwemDO3SPO5kWnEQ7BkUQN9nMHlC-U)
WikiP: https://en.wikipedia.org/wiki/Complex_logarithm#/media/File:Complex_log_domain.svg
sage: https://doc.sagemath.org/html/en/reference/plotting/sage/plot/complex_plot.html#codecell6
using UnicodePlots
X = repeat(collect(-20:20)', outer=(41, 1));
Y = repeat(collect(20:-1:-20), outer=(1,41));
grid = complex.(X, Y) ./ 10;
Z = log.(grid);
zangle = angle.(Z);
heatmap(zangle; xfact=0.1, yfact=0.1, xoffset=-2, yoffset=-2)
I wonder if it would be better to link to Wikipedia, than to try to include such details here? I would worry a bit about ending up maintaining a whole textbook. At present the PR is just informing people who do know of the potential issue what conventions Julia adopts. |
I realised that
angle
doesn't even specify that it's in -π to π.These are all pretty standard but perhaps we should be explicit?