msakai / data-interval

Interval datatype, interval arithmetic, and interval-based containers for Haskell
Other
21 stars 9 forks source link

Add instance Floating Interval #26

Closed Bodigrim closed 3 years ago

Bodigrim commented 3 years ago

This appeared to be much tougher than expected, and I am too exhausted to undertake instance Floating IntervalSet.

coveralls commented 3 years ago

Coverage Status

Coverage increased (+0.09%) to 86.578% when pulling 5e87922e4836476b6687ecc4ef150d58c398d7f2 on Bodigrim:floating into 3097bf631d381587208600d8719ad7af1bd03150 on msakai:master.

msakai commented 3 years ago

Sorry for the late response. And thanks you for the great work! This is a feature that I have wanted for a long time but have not been able to implement.

Bodigrim commented 3 years ago

Let's continue on the top level of comments :)

tan is easy to refactor into tanPrecise, returning at most two intervals, and Floating.tan itself. I do not have applications for tan anyways, so do not mind to follow the suite of signum and return whole instead of throw LossOfPrecision. Then tanPrecise can be exposed to users who care about it and reused by a potential future instance Floating (IntervalSet a).

(**) is more troublesome. The thing is that sometimes it results in an infinite list of intervals: imagine (-3<..<-2) ** whole, which consists of all integer powers of (-3<..<-2). So even IntervalSet flexibility is not enough to provide a total function, if we wish to be precise. This is probably a sign to use a convex hull over-approximation as well.

msakai commented 3 years ago

Providing both convex-hull variant and exact-computation variant is a good idea, and I think there are three options for that:

  1. Provide convex-hull variant as foo and exact-computation variant as fooPrecise which throws LossOfPrecision when the result cannot be expressed as an interval (in the case of Floating Interval) or a finite union of intervals (in the case of Floating IntervalSet).
  2. Similar to (1), but allow fooPrecise to have more flexible (and non-uniform?) interface (e.g. returning multiple intervals in the Interval case instead of throwing exception).
  3. Provide an exception-throwing variant as foo and a convex-hull variant as (say) fooApprox. (And change the current behavior of signum)

I personally prefer (1) as an interface for library users but I don't have a strong opinion, so please use the way you think is best.

Bodigrim commented 3 years ago

@msakai I've made both tan and (**) total functions, applying a convex hull when needed. How does it look?

Bodigrim commented 3 years ago

@msakai I made two additional changes:

If it looks all right to you, it would be nice to make a release at some point soon.

msakai commented 3 years ago

Please merge the PR.

If it looks all right to you, it would be nice to make a release at some point soon.

+1 If you plan to do a release, I leave it to you. If not, I'll do it.

Bodigrim commented 3 years ago

(I pushed a minor clarification to changelog, hopefully it is fine)

@msakai if you have time available, I'll appreciate you making a release.

msakai commented 3 years ago

if you have time available, I'll appreciate you making a release.

Sure.

msakai commented 3 years ago

I added the v2.1.0 tag and uploaded it to Hackage.