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

Add explicit mention of branch cuts to log, sqrt, angle docstrings #52970

Merged
merged 5 commits into from
Feb 7, 2024

Conversation

mcabbott
Copy link
Contributor

I realised that angle doesn't even specify that it's in -π to π.

These are all pretty standard but perhaps we should be explicit?

base/math.jl Outdated Show resolved Hide resolved
@inkydragon inkydragon added domain:docs This change adds or pertains to documentation domain:complex Complex numbers labels Jan 18, 2024
@inkydragon
Copy link
Sponsor Member

Pkg test failed in CI is unrealted.
The version of Pkg.jl has recently been updated (#52903), so maybe you need a rebase.

@mcabbott
Copy link
Contributor Author

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?

@inkydragon
Copy link
Sponsor Member

inkydragon commented Jan 19, 2024

do I need permissions or to log in to something?

No, you don't.
The page is open for anyone to view without logging in.
Maybe it's just a network issue.

test x86_64-w64-mingw32, test x86_64-linux-gnu: relocatedepot failed

Error in testset relocatedepot:
Error During Test at /cache/build/tester-amdci4-10/julialang/julia-master/julia-168a0f7012/share/julia/test/relocatedepot.jl:98
  Got exception outside of a @test
  SystemError: opening file "/cache/build/tester-amdci4-10/julialang/julia-master/tmp/jl_uYfD1u/compiled/v1.11/Foo.ji": No such file or directory
  Stacktrace:

I passed the relocatedepot test locally (Windows), so these errors are just noise.

@mcabbott
Copy link
Contributor Author

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?

Copy link
Sponsor Member

@inkydragon inkydragon left a 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
image


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.
Copy link
Sponsor Member

@inkydragon inkydragon Jan 31, 2024

Choose a reason for hiding this comment

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

image

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.
Copy link
Sponsor Member

@inkydragon inkydragon Jan 31, 2024

Choose a reason for hiding this comment

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

image

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)

@mcabbott
Copy link
Contributor Author

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.

@vtjnash vtjnash merged commit 41bbfb4 into JuliaLang:master Feb 7, 2024
5 of 7 checks passed
@mcabbott mcabbott deleted the doc9 branch February 7, 2024 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:complex Complex numbers domain:docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants