Re:The Emergent Features of JuliaLang: Part II – Traits
by adamnemecek on Wednesday November 06, 2019 @03:24PM
(#21466778)
Part I https://invenia.github.io/blog/2019/10/30/julialang-features...
[ Parent
| on HN ]
Re:The Emergent Features of JuliaLang: Part II – Traits
by renox on Thursday November 07, 2019 @01:09PM
(#21475648)
I like the convenient unit syntax, if this works well with IntervalArithmetic.jl, julia can become a competitor to Frink https://frinklang.org/
Re:The Emergent Features of JuliaLang: Part II – Traits
by eigenspace on Thursday November 07, 2019 @01:48PM
(#21476056)
Here's an example of them working together rather effortlessly:
using Unitful, IntervalArithmetic
const m = u"m"
const k = 2π/10m
f(x) = cos(k * x)/(k^2 - 1/x^2)
julia> f((10.0 ± 0.1)m)
[2.5924, 2.60024] m^2
If I try to put in a dimensionally incorrect argument to f, I get an error: julia> f((10 ± 0.01)u"s")
ERROR: MethodError: no method matching cos(::Quantity{Interval{Float64},𝐓*𝐋^-1,Unitful.FreeUnits{(m^-1, s),𝐓*𝐋^-1,nothing}})
Closest candidates are:
cos(::Float16) at math.jl:1085
cos(::Complex{Float16}) at math.jl:1086
cos(::Missing) at math.jl:1138
...
This isn't the most friendly error message in the world, but that can certainly be worked on and with a bit of patience it's pretty clear that it's saying that the problem was that it tried to compute the cosine of a unitful quantity which is nonsense._____________________________________
Unfortunately I had to use unitful intervals (i.e. (10.0 ± 0.1)m) instead of intervals of uniful quantities (i.e. 10.0m ± 0.1m) because IntervalArithmetic.jl demands that it takes real quantities, but Unitful quantities are subtypes of Number instead of Real.
Re:The Emergent Features of JuliaLang: Part II – Traits
by eigenspace on Saturday November 16, 2019 @03:08PM
(#21554642)
Just as a followup, I just realized that the Measurements.jl package does know how to deal with non-real uncertainties, so one can instead do
using Unitful, Measurements
const m = u"m"
const k = 2π/10m
f(x) = cos(k * x)/(k^2 - 1/x^2)
julia> f(10.0m ± 0.1m)
(2.5989 ± 0.0014) - (0.0 ± 0.16)im m^2