Open dpsanders opened 7 years ago
There would need to be two: one with outward rounding (e.g. for exp
) and the other with no rounding (e.g. for sign
, ceil
etc.).
The idea would be that @monotone f(I)
, with I
and interval, returns directly Interval(f(I.lo),f(I.hi))
or Interval(f(I.hi),f(I.lo))
, depending which makes sense (only one of them makes sense, unless the function is constant). Nice idea!
The only thing I would be worried is how to react when f
is not monotonic. (If you use @inbounds
out of range, you get an error.)
Another issue is how to extend it to DecoratedInterval
s; the issue is subtle, since you may have a truly monotonic but not continuous function in I
, so a com
decoration should be transformed into trv
...
I guess with try ... catch...
and directed rounding would be enough. Yet, so far I see no way for the decorations...
I actually meant to define the function in the first place. Maybe it's not necessary to have a macro, just generate the code. I agree that for decorated intervals with sign
etc. it still has to be done by hand, or else provide a function that calculates where the discontinuities are.
Closing this as it's not clear what to actually do.
As I needed interval extension of both the zeta Riemann function (monotone for real argument greater than 1) and the polylogarithm (which is monotone in each of its argument), I implemented something very similar to what is proposed.
The current implementation can be found here and an example of use here.
This implementation is not ready for publication though, as it is mainly untested and over typed. But I am willing to improve it and make it available either by integrating it in IntervalArithmetic.jl
or as a separate package.
To tell more about what it does, it defines a macro @monotone
that define a new method for all possible combinations of real and interval arguments of a function (it works on multi dimensional function provided it is monotone argumentwise). For example for the polylogarithm polylog(s, z)
it defines
polylog(s::Interval, z)
polylog(s, z::Interval)
polylog(s::Interval, z::Interval)
For each argument a domain must be given and the monotonicity of the function is determined automatically by computing the value of the function on the boundary of the domain.
Optionnal arguments are:
clampto
: The result is clamped to this interval. Useful if the image set of the function is known.relerr
: Allows to give a relative error. The resulting interval is expanded by that factor to take in account the fact that the function may not be computed with machine precision (untested).singularities
: If given, the domain is cut at each singularity, so functions that are monotonic on well defined domains can be extended as well (need some work to separate the case in which the singularity is exactly representable as a floating point).
This could be used both in the package and in user code.
cf. #191