
thanks Ben and John, your ideas looked like they may speed up things indeed, so i went along with them and reimplemented the whole thing.... to my surprise, the program got considerably slower even ! here is the new code.
data ILtype = II | IE | EI | EE | NII | NIE | NEI | NEE deriving (Eq, Ord)
(... I found no increase in performance by using the UNPACK pragma as you suggested, so I just ommitted it in this version...)
data Interval = Range ILtype !Double !Double deriving (Eq, Ord) instance Show Interval where show (Range iltype x y) = case iltype of II -> if x == y then (show x) else "[" ++ (show x) ++ ".." ++ (show y) ++ "]" IE -> "[" ++ (show x) ++ ".." ++ (show y) ++ ")" EI -> "(" ++ (show x) ++ ".." ++ (show y) ++ "]" EE -> "(" ++ (show x) ++ ".." ++ (show y) ++ ")" NII -> "Not " ++ show (Range II x y) NIE -> "Not " ++ show (Range IE x y) NEI -> "Not " ++ show (Range EI x y) NEE -> "Not " ++ show (Range EE x y)
the flip of interval types:
ilFlip :: ILtype -> ILtype ilFlip ilt = case ilt of II -> NII IE -> NIE EI -> NEI EE -> NEE NII -> II NIE -> IE NEI -> EI NEE -> EE
The complement of Intervals :
intComplement :: Interval -> Interval intComplement (Range iltype x y) = (Range (ilFlip iltype) x y)
membership function for Intervals:
isIn :: Double -> Interval -> Bool isIn r (Range iltype x y) = case iltype of II -> r >= x && r <= y IE -> r >= x && r < y EI -> r > x && r <= y EE -> r > x && r < y NII -> r > y || r < x NIE -> r > y || r <= x NEI -> r >= y || r < x NEE -> r >= y || r <= x
As always, any further comments or insights greatly appreciated. stijn.
participants (1)
-
Stijn De Saeger