Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement ifelse() as union of results #14

Open
gwater opened this issue Aug 8, 2019 · 11 comments
Open

implement ifelse() as union of results #14

gwater opened this issue Aug 8, 2019 · 11 comments
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@gwater
Copy link
Owner

gwater commented Aug 8, 2019

as suggested in #11

@gwater gwater added the enhancement New feature or request label Aug 8, 2019
@gwater
Copy link
Owner Author

gwater commented Aug 8, 2019

unfortunately ifelse() is a builtin and therefore cannot be extended:

julia> import Base: ifelse
julia> ifelse(::Int) = nothing
ERROR: cannot add methods to a builtin function
Stacktrace:
 [1] top-level scope at none:0

FYI @oschulz

@gwater gwater closed this as completed Aug 8, 2019
@gwater gwater added the wontfix This will not be worked on label Aug 8, 2019
@oschulz
Copy link

oschulz commented Aug 8, 2019

I know. :-(

Ran into this when I did the benchmark example in #11, that's why I had to use a custom interval_ifelse().

@gwater
Copy link
Owner Author

gwater commented Aug 8, 2019

Ok, I started a discussion on the Julia discourse, maybe there is some way around it

@oschulz
Copy link

oschulz commented Aug 8, 2019

Thanks!

@oschulz
Copy link

oschulz commented Feb 25, 2022

@gwater , should we reopen this now that ifelse is becoming generic in Julia v1.8.0?

@gwater
Copy link
Owner Author

gwater commented Feb 25, 2022

I was thinking about that the other day… I'm currently working on an overhaul of the internals, basically separating the notion of numbers and intervals. Essentially I define a type

struct FuzzyReal{T} <: AbstractFloat
    interval::IEEE1788_Interval{T}
end

and then the method would look like this

ifelse(::Missing, a::FuzzyReal{T}, b::FuzzyReal{T}) = FuzzyReal(hull(a.interval, b.interval))

correct?

Notably, if the two underlying intervals are disjoint, we cannot describe their union using a single IEEE1788 interval. That's why we need to take the hull of their union.

@gwater gwater reopened this Feb 25, 2022
@oschulz
Copy link

oschulz commented Feb 25, 2022

I agree, that definition would be best - anything other than the hull (tracking the separate intervals) would have the potential of growing exponentially.

I wonder if there's a better name than FuzzyReal - sounds a bit like fuzzy logic, which it's not, for course. And it may sound a bit to, well, fuzzy, for something that follows rigorous rules and gives guarantees (true result will be in the interval). Why not NumberInterval, in line with the package name?

@oschulz
Copy link

oschulz commented Feb 25, 2022

ifelse(::Missing, a::FuzzyReal{T}, b::FuzzyReal{T}) is problematic, though, it forces the user to pass FuzzyReal explicitly, which makes it difficult to use intervals in generic code. If comparisons of intervals would return a custom value, e.g. Indeterminate() or so, ifelse could be specialized in a more generic way like ifelse(::Indeterminate, a, b) = interval_hull(a, b).

@gwater
Copy link
Owner Author

gwater commented Feb 26, 2022

ifelse(::Missing, a::FuzzyReal{T}, b::FuzzyReal{T}) is problematic, though, it forces the user to pass FuzzyReal explicitly, which makes it difficult to use intervals in generic code. If comparisons of intervals would return a custom value, e.g. Indeterminate() or so, ifelse could be specialized in a more generic way like ifelse(::Indeterminate, a, b) = interval_hull(a, b).

That's an interesting point. I have been wondering if it might be worth defining this new type (regardless of its name) with a field for the third logical value. So:

struct FuzzyReal{T, V}
    interval::IEEE1788_Interval{T}
    indeterminate::V
end

then we could set the field indeterminate to missing by default but users could choose to set a different value to define custom behavior in indeterminate cases. What do you think?

@gwater
Copy link
Owner Author

gwater commented Feb 26, 2022

Why not NumberInterval, in line with the package name?

In thinking about the relationship between the number subtype and the IEEE intervals more deeply I have found that I would rather separate the notions of intervals and numbers completely. So the FuzzyReal should, in my opinion, not provide any set behaviours such as intersections, hulls, etc. Consequently, the name should make that clear, too.

@oschulz
Copy link

oschulz commented Feb 27, 2022

with a field for the third logical value.

Nowadays, a Julia Union should handle that efficiently, I hope. I would suggest that comparison operators return a Union{Indeterminate,Bool}, with numeric intervals being a separate thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants