ekmett / intervals

Interval Arithmetic
http://hackage.haskell.org/package/intervals
BSD 2-Clause "Simplified" License
27 stars 13 forks source link

recip is not conservative #23

Closed dmcclean closed 8 years ago

dmcclean commented 10 years ago
Prelude Numeric.Interval> let x = -4.953054227393486 ... 1.7338039918518358
Prelude Numeric.Interval> let y = -1.5469134120041255
Prelude Numeric.Interval> recip x
-0.2018956292603006 ... 0.576766465355708
Prelude Numeric.Interval> recip y
-0.6464485938514399

I'm not exactly sure where the problem arises. The definition looks OK to me at first glance, recip (I a b) = on min recip a b ... on max recip a b, but I often have difficulty understanding on.

dmcclean commented 10 years ago

Oh, it's because one endpoint is positive and the other negative...

dmcclean commented 10 years ago

Fixed in my branch just by deleting the implementation of recip entirely. It defaults to effectively recip x = singleton 1 / x, which is correct. A faster implementation is probably possible.

ekmett commented 10 years ago

Sounds good. Feel free to push that into mainline.

bergey commented 8 years ago

Fixed by https://github.com/ekmett/intervals/pull/36