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

AbstractFloat interface functions #101

Open
2 of 4 tasks
kalmarek opened this issue Dec 3, 2020 · 3 comments
Open
2 of 4 tasks

AbstractFloat interface functions #101

kalmarek opened this issue Dec 3, 2020 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@kalmarek
Copy link
Owner

kalmarek commented Dec 3, 2020

to make Arbs slightly easier to use in generic numerical code

that includes low level functions such as:

  • eps
  • exponent
  • you name it;)

and high level that could be composed of Arblib functions

@lrnv
Copy link

lrnv commented Dec 3, 2020

exp1m is the first thing i came into. Maybe you could look at how ArbNumerics made it ?

@kalmarek
Copy link
Owner Author

kalmarek commented Dec 4, 2020

@lrnv locally you can define it as Base.expm1(x::T) where T<:Arblib.ArbOrRef = Arblib.expm1!(T(prec=precision(x)), x), proper fix is to add it to the list mentioned above.

for Base.eps you may try

Base.eps(x::Arblib.ArbOrRef) = Arb(Arblib.set_ulp!(Mag(), Arblib.midref(x), prec=precision(x)))

(it is necessary to pass precision explicitly here as Mags don't carry it). This will allocate additional struct, and I'm not even sure this is what we want ;) Another possibility is

function Base.eps(x::Arblib.ArbOrRef)
    res = Arb(prec = precision(x))
    Arblib.set_ulp!(Arblib.radref(res), Arblib.midref(x), prec=precision(x))
    return res
end

the first one results in

julia> eps(rand(Arb))
[1.7272337110188889250772703725600799142232000728872562770047406940337183606325e-77 +/- 1.46e-154]

the second with

julia> eps(rand(Arb))
[+/- 1.73e-77]

or we could marry both

function Base.eps(x::Arblib.ArbOrRef)
    res = Arb(prec = precision(x))
    Arblib.set_ulp!(Arblib.radref(res), Arblib.midref(x), prec=precision(x))
    Arblib.midref(res)[] = Arblib.radref(res)
    Arblib.zero!(Arblib.radref(res))
    return res
end

Hmm... interesting:

julia> a = exp(Arb(rand())); Arblib.zero!(Arblib.radref(a)); (a, Arblib.radref(a))
([2.1545763189042442095875868401977617041872092787378076208404894100210187829306 +/- 3.03e-77], (0))

@Joel-Dahne could you please explain why this printing of a which has zero radius? is is again about guaranteed digits?

@Joel-Dahne
Copy link
Collaborator

Many good ideas here! I'll have to get back when I have more time. But I can at least comment about the printing.

Yes, it's related to the guaranteed digits and comes from the fact that we determine the number of digits to print based on the precision (using digits_prec(prec::Integer) = floor(Int, prec * log(2) / log(10))). This number is exactly representable in base 10 but requires many more digits to do that. We can print the full number by printing more digits

julia> Arblib.string_nice(eps(one(Arb))) # Default version
"[1.7272337110188889250772703725600799142232000728872562770047406940337183606325e-77 +/- 1.46e-154]"

julia> Arblib.string_nice(eps(one(Arb)), 200) # More digits
"1.7272337110188889250772703725600799142232000728872562770047406940337183606324854115943015006944576453121094587892299327193990197893663893387306007554116149549372494220733642578125000000000000000000000e-77"

It seems like choosing a default printing is a non-trivial task to do... We should probably experiment a bit with it and see what we like in the end. At the very least we should mention something about it in the documentation.

@kalmarek kalmarek added enhancement New feature or request help wanted Extra attention is needed labels Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants