Open Joel-Dahne opened 3 years ago
I can also mention that at some point I want to add plotting support to the polynomial and series types as well. But that is a future problem.
While it makes sense to have Arf <: AbstractFloat
(I experimented with this idea while implementing rand
) it'd be hard to think how Arb
s may fit into AbstractFloat
informal interface. From mathematical/cs point of view, probably Arf <: AbstractFloat
and float(x::ArbOrRef) = midpoint(x)
makes most sense? I have little opinion on this though.
The way that Julia treats AbstractFloat
seems to be just as something which is good at representing general real numbers, compared to for example Integer
or Rational
. If we don't subtype AbstractFloat
then many of the methods defined in Base will not work out of the box. In some cases this might be good, there is no guarantee that the methods in Base actually give rigorous results. However many of them would work well in that case, for example
rad2deg(z::AbstractFloat) = z * (180 / oftype(z, pi))
from Base would work perfectly fine for Arb
. I took a look at a sample of the Julia Base functions that use AbstractFloat
at actually it seems like all of them would work fine for Arb
.
But I agree that it doesn't make perfect sense to have Arb <: AbstractFloat
. In my current work I mostly treat it as a high precision floating point with the a little bit of extra information keeping track of the rounding errors, then it makes sense I think. But in other cases you really want to see it as a ball with a larger radius and then it makes less sense.
Defining float(x::Arb) = midpoint(x)
would be problematic, for example due to functions like rad2deg
above then returning an Arf
. However defining float(x::Arb) = x)
would also be problematic because we get a stack overflow instead. The only solution to this is to subtype AbstractFloat
. But maybe these methods are not the most important to have to work.
I think we can agree that for Arf
it makes sense to subtype AbstractFloat
at least, I can make a pull request for that.
@saschatimme ?
I don't have a strong opinion. Since AbstractFloat <: Real
we only would choose a more specific supertype for Arb
. So this should be fine for me. Maybe more things work then and other things break at other places instead. So just go ahead and make Arf
and Arb
a suptype of AbstractFloat
.
Mostly solved by #108
I want to be able to plot the
Number
types we define in Arblib.jl directly using Plots.jl. Currentlyplot([Arb(1)])
fails becausefloat(::Arb)
defaults toAbstractFloat(::Arb)
which is not defined. There are two ways to solve this, either we definefloat(x::Arb) = x
directly or we makeArb
a subtype ofAbstractFloat
in which caseAbstractFloat(::Arb)
will work. Similar things happen forArf
.For
Arf
I think it makes perfect sense to subtypeAbstractFloat
, after all it's essentially identical to aBigFloat
which does subtype that. ForArb
I'm not entirely sure, we could maybe see it as anAbstractFloat
with the radius being some extra information. In practice I think this would work quite well, and everything that makes sense on anAbstractFloat
I believe makes sense on anArb
as well. The alternative would be to definefloat(x::Arb) = x
, so we would treat it as a float in practice but not subtype it, I'm not sure if that is better in any way. I can note here thatfloat
doesn't have to return a subtype ofAbstractFloat
, for examplefloat(::Complex{Int})
isComplex{Float64}
.For
Acb
I believe we want to handle it similar toComplex{Arb}
, which would mean adding these two plot recipesHowever I realised that many methods, at least in Julia Base, starts by doing
float(x)
on any input, so it could still be beneficial to definefloat(x::Acb) = Acb
. I can also mention that it doesn't make sense to haveAcb <: AbstractFloat
sinceAbstractFloat <: Real
.Finally a comment about plotting balls. In the above plotting an
Arb
or anAcb
would plot the midpoint of the ball. In many cases this makes sense, when working with high precision balls with small radius which is exactly what Arb is optimized for. This covers most of my uses. However in some cases you would like to plot the whole ball, including the radius. It would be nice if we could come up with a convenient method for doing that as well, possibly through some@userplot
recipe.