Comments (13)
I'm sure you already carefully thought about typing of AbstractInterval
, but what about making it a subtype of AbstractFloat
? Are there unwanted side effects?
I did so for Measurement type in Measurements.jl
package, and all complex functions work with it, without any effort on my side.
from intervalarithmetic.jl.
Hmm, I haven't tried it; that's good idea, thanks!
It's not actually very clear to me what that would imply though.
from intervalarithmetic.jl.
See the branch subtype_abstractfloat
. It currently leads to some ambiguity warnings in convert
methods that will have to be fixed first.
from intervalarithmetic.jl.
It's not actually very clear to me what that would imply though.
For the complex functions, they would automatically use the f(::Complex{<:AbstractFloat})
method, instead of going through f(x::Complex{<:Real}) = f(float(x))
, that triggers the StackOverflowError.
See JuliaPhysics/Measurements.jl#1 for the discussion about typing of Measurement
, I first started with Number
and after discussion I eventually realized that AbstractType
was the most useful and meaningful supertype of my type (see last message).
from intervalarithmetic.jl.
However I see that Interval{Rational}
is allowed, in that case may not be a good idea to make AbstractInterval
a subtype of AbstractFloat
. Out of curiosity: why Rational
and not Integer
?
from intervalarithmetic.jl.
I am not that convinced that we still need Interval{Rational}
; cc @lbenet.
Interval{Int}
is very restrictive: as soon as you do almost anything to it, you leave the integers.
from intervalarithmetic.jl.
Interval{Int}
is very restrictive: as soon as you do almost anything to it, you leave the integers.
I see. That was my main concern for Measurement
as well, and I decided to go with AbstractFloat
only.
If ambiguities you mentioned above can be fixed, this can probably the solution to all these issues ;-)
from intervalarithmetic.jl.
I was actually not aware of Measurement.jl
, but it's really quite close to IntervalArithmetic.jl
in many ways! Thanks for the useful comments!
from intervalarithmetic.jl.
Sorry for joining you too late in this discussion...
Out of curiosity: why
Rational
and notInteger
?
In contrast to Integer
s, you can do quite a lot with Rational
arithmetic. For example, rational functions (quotients of polynomials) can be handled exactly using Rational
s.
I'm sure you already carefully thought about typing of
AbstractInterval
, but what about making it a subtype ofAbstractFloat
? Are there unwanted side effects?
As @dpsanders answered, it would get rid of Interval{Rational{T}}
, and as explained above, I think that is actually useful.
Let me twist a bit @giordano's idea, and create a const
that almost acts as an abstract type.
julia> const AbstractFloatAndRational = Union{subtypes(AbstractFloat)..., Rational}
Union{BigFloat, Float16, Float32, Float64, Rational}
julia> abstract type AbstractInterval <: AbstractFloat end
julia> type Interval{T<:AbstractFloatAndRational} <: AbstractInterval
lo :: T
hi :: T
end
julia> Interval{T<:AbstractFloatAndRational}(a::T, b::T) = Interval{T}(a,b)
Interval
julia> Interval(0.0, 1.0)
Interval{Float64}(0.0, 1.0)
julia> Interval(0//1, 1//1)
Interval{Rational{Int64}}(0//1, 1//1)
julia> setprecision(BigFloat, 64)
64
julia> Interval(big(0.0), big(1.0))
Interval{BigFloat}(0.00000000000000000000, 1.00000000000000000000)
I'm not so sure if this can solve the problems of this issue, but it allows to have Interval
as a subtype of AbstractFloat
with the possibility of having Interval{Rational{T}}
.
from intervalarithmetic.jl.
In contrast to
Integer
s, you can do quite a lot withRational
arithmetic. For example, rational functions (quotients of polynomials) can be handled exactly usingRational
s.
Thanks for chiming in this discussion! I see your point and I agree that with interval arithmetic you can do probably all arithmetic with Rational
s. The same isn't true for Measurements.jl, because the resulting uncertainty (i.e., the half-width of the interval) is the square root of quadrature sums of contribution to uncertainty of each operand, so virtually any operation ends up with a floating point width.
Regarding your proposal, my only concert is that if you want to keep both Interval{Rational}
and Interval{<:AbstractFloat}
, making them both subtypes of AbstractFloat
may result in wrong methods being picked-up for Interval{Rational}
in complex functions (or maybe you don't solve the StackOverflowError
for them).
As a side note, I think that AbstractFloatAndRational
could be defined as
const AbstractFloatAndRational = Union{AbstractFloat, Rational}
that isn't limited to the value of AbstractFloat
at compile-time ;-)
from intervalarithmetic.jl.
The simplest thing to do is just define methods to act directly on Complex Intervals and not hold our breath to see when things are improved in Base.
from intervalarithmetic.jl.
In Julia's Base library, mathematical non-arithmetic functions of real argument are eventually defined only for specific types of AbstractFloat
(usually Float32
, Float64
, BigFloat
), even those implemented in pure Julia. Likewise, most functions of complex argument are eventually defined only for AbstractFloat
, usually to ensure type-stability. I'm not sure things will ever change.
from intervalarithmetic.jl.
exp
et al. were fixed by JuliaLang/julia#25292.
from intervalarithmetic.jl.
Related Issues (20)
- Matrix multiplication with mixed Interval SMatrix and SMatrix broken HOT 3
- Lack of `convert(::Interval{T}, a::Real)` HOT 3
- IntervalArithmetic.Interval(::Float64, ::Float64) appears no longer supported in v0.21.0; replace with IntervalArithmetic.interval() HOT 2
- Make DecoratedInterval the default HOT 1
- A common "thick numbers" package? HOT 11
- Failure of `Interval{T}(x::AbstractIrrational)` HOT 7
- incorrect comparison for ieee standard HOT 1
- Make sure that the documentation is correct HOT 1
- Replacing CRlibm with CORE-MATH HOT 7
- Revive `@interval`
- constants in `@constraint` not working HOT 6
- "one" on complex intervals returns wrong value HOT 1
- Plotting intervals after removal of `IntervalBox` HOT 4
- Don't write inside of the package dir
- Non-thread safe use of `setrounding` HOT 11
- Incorrect rounding for extreme irrationals HOT 1
- Avoid `convert` to `Interval` in `^` HOT 23
- `quadrant` is not thread-safe
- Finding quadrants is flawed
- Should `intersect_interval` (or `hull`) return always `trv` decoration? HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from intervalarithmetic.jl.