Open dpsanders opened 3 months ago
We might need to change from using Real to a concrete RealSymbolic (which would be good for other things), then the promotion can be defined on that? Or define the promote_symtype?
Thanks, RealSymbolic sounds like a good idea yes; Real seems too general.
I guess I'll try fiddling with promote_symtype in the mean time...
When you create a symbolic variable via Symbolics.jl, its default numeric type is Real
.
using Symbolics
@variable x
typeof(Symbolics.value(x)) # SymbolicUtils.BasicSymbolic{Real}
interval(1, 2)
is of type Interval{Float64}
.
In IntervalArithmetic, const NumTypes
is defined as Union{Rational,AbstractFloat}
which is very strict.
https://github.com/JuliaIntervals/IntervalArithmetic.jl/blob/ee8fd3d4b091d40fb5335b9c78bee737261faa87/src/intervals/construction.jl#L9
Calling IntervalArithmetic.promote_numtype(Interval{Float64}, Real)
yields Real
.
https://github.com/JuliaIntervals/IntervalArithmetic.jl/blob/ee8fd3d4b091d40fb5335b9c78bee737261faa87/src/intervals/construction.jl#L53
promote_rule
in IntervalArithmetic tries creating a Interval{Real}
type,
https://github.com/JuliaIntervals/IntervalArithmetic.jl/blob/ee8fd3d4b091d40fb5335b9c78bee737261faa87/src/intervals/construction.jl#L542-L543
which fails because the parameter T
in the parametric type Interval{T}
must be a subtype of const NumTypes = Union{Rational,AbstractFloat}
.
https://github.com/JuliaIntervals/IntervalArithmetic.jl/blob/ee8fd3d4b091d40fb5335b9c78bee737261faa87/src/intervals/construction.jl#L272
If you know the primitive type you want your symbolic variable to be, you can explicitly declare it. https://symbolics.juliasymbolics.org/stable/manual/types/ For example
using Symbolics
@variables z::Float64
typeof(Symbolics.value(z)) # SymbolicUtils.BasicSymbolic{Float64}
Then, the multiplication with IntervalArithmetic.Interval{Float64}
works
using IntervalArithmetic, Symbolics
@variables z::Float64
res = interval(1, 2) * z
nothing
Note that you may get an error when you print res = interval(1, 2) * z
in the above, which is a separate issue.
That's very helpful, thanks!
Is there an easy fix for this? It looks like some type promotions are wrong, but I've tried various possible fixes and none have been successful.