WARNING: both IntervalArithmetic and Measurements export "±"

I trying to learn about intervals in a Pluto notebook using both IntervalArithmetic and Measurements.

I understandably get the error in the thread title when I try to use ± to replicate the notebook extract here:
https://discourse.julialang.org/t/how-to-fit-a-function-to-measurements-with-error/65369/6

The code replicates fine if IntervalArithmetic is not used but I want to be able to use both packages within the one Pluto notebook.

Normally I get around this problem with PackageName.function. However, this doesn’t work here. I have tried following this page:
Modules · The Julia Language *

However…

  1. If I try using Measurements: ± as mpm then replace with .mpm I get a syntax error
syntax: space before "." not allowed in "((a .* x) .+ rand(d, N)) . at *filename and path*"
  1. If I try Measurements.:.± or Measurements.:.(±) I get the same syntax error
  2. if I try using IntervalArithmetic: ± as iapm this only brings in that one feature from the package but I want to use .. and all the other features

Any suggestions? My preference would be to get option 2 working.

The parent module may be accessible using a chain of submodules like Base.Math.sin , where Base.Math is called the module path . Due to syntactic ambiguities, qualifying a name that contains only symbols, such as an operator, requires inserting a colon, e.g. Base.:+ . A small number of operators additionally require parentheses, e.g. Base.:(==) .

and

  1. Use the as keyword above to rename one or both identifiers, eg
julia> using .A: f as f

julia> using .B: f as g

would make B.f available as g. Here, we are assuming that you did not use using A before, which would have brought f into the namespace.

Measurements.± has already a non-infix operator equivalent: Measurements.measurement, you don’t need to make your own function. But non-infix operator can’t be used as…infix operators, that’s why your attempt to use .mpm wouldn’t work. But you can do

julia> using Measurements: measurement

julia> measurement(10, 1)
10.0 ± 1.0

julia> measurement.([10, 20, 30], [1, 2, 3])
3-element Vector{Measurements.Measurement{Float64}}:
 10.0 ± 1.0
 20.0 ± 2.0
 30.0 ± 3.0

If I understand your answer, I need to reformat the expression so

y = ((a .* x) .+ rand(d, N)) .± rand(d, N)

is rewritten as

y = measurement.((a.*x .+ rand(d, N)), rand(d, N))

This works!

I don’t know what a, x, d and N are, but if d and N are integers, a is a scalar and x is a matrix dxN, then you can more simply do

y = measurement.((a.*x .+ rand.()), rand.())

which avoids allocating two temporary matrices dxN in the first place.

1 Like