Re: [Haskell-cafe] practice problems?
"Brian Hulley" <brianh@metamilk.com> wrote: What about a library for interval arithmetic [1]? I'd imagine it could start something like: data Interval a = Interval !a !a deriving (Eq, Show) instance Num a => Num (Interval a) where Interval llow lhigh + Interval rlow rhigh = Interval (min llow rlow) (max lhigh rhigh) The Interval type would probably need to explicitly represent several kinds of intervals eg (-infinity, x] etc and there are some tricky issues about what to do with the operations whose result sometimes needs to be represented by more than one interval to be useful such as division by an interval containing zero eg you might want to use a list of intervals to deal with these cases: instance Num a => [Interval a] where ... ie [Interval 5 5] / [Interval -1 1] = [FromNegInfinityTo -5, ToPosInfinityFrom 5] Take a look at my Ranged Sets library at http://sourceforge.net/projects/ranged-sets Paul.
Paul Johnson wrote:
"Brian Hulley" <brianh@metamilk.com> wrote:
What about a library for interval arithmetic [1]?
[Interval 5 5] / [Interval -1 1] = [FromNegInfinityTo -5, ToPosInfinityFrom 5]
Take a look at my Ranged Sets library at
Hi Paul - Thanks for the link to your lib (do you want to add a link from http://www.haskell.org/haskellwiki/Libraries_and_tools/Mathematics ?) I've only had time to have a brief look but it seems that RSet's could be used as interval arithmetic numbers with suitable instance decls for Num etc. My knowledge of interval arithmetic itself however is not sufficient to tell at this moment if the full generality of RSet's is actually needed ie perhaps it is enough to just say that division by a range containing zero should be undefined and perhaps there are no other ops which would cause more than one result range in which case it would be inefficient to use a more general representation than needed. Possibly there could be two different implementations of interval arithmetic - one allowing for multiple ranges and one that just treated division by an interval containing zero (and other problematic situations) to be undefined, so that the results of each op would be a single range when machine-level speed is needed and it is known in advance that division by zero etc will not happen in the specific problem domain. Anyway thanks for sharing your library with a nice BSD3 license! :-) Regards, Brian. -- Logic empowers us and Love gives us purpose. Yet still phantoms restless for eras long past, congealed in the present in unthought forms, strive mightily unseen to destroy us. http://www.metamilk.com
participants (2)
-
Brian Hulley -
Paul Johnson