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

Third root of the zero element of the real numbers fails #1440

Open
HechtiDerLachs opened this issue Apr 4, 2023 · 5 comments
Open

Third root of the zero element of the real numbers fails #1440

HechtiDerLachs opened this issue Apr 4, 2023 · 5 comments

Comments

@HechtiDerLachs
Copy link

Try this:

CC = ComplexField(128)
RR = parent(abs(one(CC)))
a = zero(RR)
root(a, 3)

For me the result is nan. This seems to only happen for the third root. root(a, 2) is fine, for instance.

@thofma
Copy link
Member

thofma commented Apr 4, 2023

@fredrik-johansson, do you have an idea what is happening here? This is just calling arb_root:

julia> RR = ArbField(64)
Real Field with 64 bits of precision and error bounds

julia> a = zero(ArbField(64))
0

julia> for i in 1:10; @show i, root(a, UInt(i)); end;
(i, root(a, UInt(i))) = (1, 0)
(i, root(a, UInt(i))) = (2, 0)
(i, root(a, UInt(i))) = (3, nan)
(i, root(a, UInt(i))) = (4, 0)
(i, root(a, UInt(i))) = (5, nan)
(i, root(a, UInt(i))) = (6, nan)
(i, root(a, UInt(i))) = (7, nan)
(i, root(a, UInt(i))) = (8, nan)
(i, root(a, UInt(i))) = (9, nan)
(i, root(a, UInt(i))) = (10, nan)

@fredrik-johansson
Copy link
Contributor

Yeah, in some cases the root function uses the formula exp(log(x)/n), but it should then first check for x = 0.

@thofma
Copy link
Member

thofma commented Apr 4, 2023

Thanks! I will probably do an is_zero check in Nemo for now.

@HechtiDerLachs
Copy link
Author

Good to have this clarified. But what about the case when !(x== 0) but contains_zero(x)==true? Then log(x) is also ill-defined, isn't it? I'm a bit worried that is_zero might not be the correct thing to check.

@thofma
Copy link
Member

thofma commented Apr 4, 2023

Hm, the check in Nemo is not quite correct. At the moment it is

x < 0 && throw(DomainError("x must be positive"))

but it should be

is_zero(x) && return x
!isnonnegative(x) && throw(DomainError("x must be positive"))

Or maybe we should only check is_zero and let it return nan whenever it wants to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants