-
Notifications
You must be signed in to change notification settings - Fork 70
Description
CC @giordano, @devmotion (and others?)
I've not been Watching
this package but it looks like interesting and important changes are afoot, and I wonder if it's an opportunity for some shared development among packages like Measurements and possibly even dual-number packages like ForwardDiff (and probably more, feel free to CC others). All of these packages share a somewhat-awkward desire to do math on objects that act like numbers but also have some "thickness" to them. (In ForwardDiff the thickness is infinitesimal, so maybe it's not quite as relevant to this discussion.) All of these packages have been tempted to inherit from Real
, but many have recognized that this has some issues. I wonder if it's time to create a core package---let me throw out ThickNumbers.jl
as a possible name---that defines abstract types and exports common operators, traits, fallbacks, errors, etc., but leaves all concrete implementations to downstream packages.
To make this a bit concrete, here's an example from the development (master
) branch of IntervalArithmetic:
julia> using IntervalArithmetic, IntervalArithmetic.Symbols
julia> 1..3 == 1..3
ERROR: ArgumentError: == is purposely not supported, use ≛ instead
Stacktrace:
[1] ==(::Interval{Float64}, ::Interval{Float64})
@ IntervalArithmetic ~/.julia/dev/IntervalArithmetic/src/intervals/interval_operations/boolean.jl:31
[2] top-level scope
@ REPL[2]:1
julia> 1..3 ≛ 1..3
true
julia> 1..3 ≛ 1..3.1
false
Note the use of a new operator ≛
. My understanding is that IntervalArithmetic is trying to adhere more strictly to the fundamental principle that f(X, Y)
(here f
is ==
) includes all possible values of f(x, y)
for any x ∈ X, y ∈ Y
; since almost any independent choice of x, y
are not equal, testing interval equality is nearly useless. One could make a case for Interval{Bool}(false, true)
, but having the operation be undefined is at least safe, and gets you to the same result (an error) that putting a == b
inside an if
statement would generate even if it did return Interval{Bool}(false, true)
(because if
requires a Bool
). This is just one example among many.
I tend to think of Measurement as kind of like an interval, but less strict and less affected by the dependency problem. I actually have a practical use case where I'd like to be able to support users choosing whether they want to perform a computation using IntervalArithmetic (guaranteed but probably overly-conservative bounds) or Measurements (approximate but probably tighter bounds) and hence it would be interesting to consider making the two packages more compatible.
While I haven't actually written a line of code, I wonder if a shared "abstract package" might standardize some of the difficult decisions we have in common, or at least provide a social gathering point for discussing such issues. Julia's own base/numbers.jl
and base/operators.jl
might serve as inspiration for what could go in there, as well as noticing and sharing relevant patterns that are currently in the packages that might eventually use ThickNumbers.jl
.