Copyright | (c) Michael Szvetits 2019 |
---|---|
License | BSD3 (see the file LICENSE) |
Maintainer | typedbyte@qualified.name |
Stability | stable |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
This module exports the types and functions needed to construct, combine and process numeric domains.
Synopsis
- data Domain a
- intervals :: Domain a -> [Interval a]
- empty :: Domain a
- singleton :: a -> Domain a
- interval :: Ord a => LowerBound a -> UpperBound a -> Domain a
- greaterThan :: Dist a => a -> Domain a
- greaterOrEqual :: a -> Domain a
- lessThan :: Dist a => a -> Domain a
- lessOrEqual :: a -> Domain a
- maxDomain :: Domain a
- (<..<) :: Dist a => a -> a -> Domain a
- (<=..<) :: Dist a => a -> a -> Domain a
- (<..<=) :: Dist a => a -> a -> Domain a
- (<=..<=) :: Ord a => a -> a -> Domain a
- difference :: Dist a => Domain a -> Domain a -> Domain a
- intersect :: Ord a => Domain a -> Domain a -> Domain a
- union :: Dist a => Domain a -> Domain a -> Domain a
- greaterThanDomain :: Dist a => Domain a -> Domain a
- greaterOrEqualDomain :: Ord a => Domain a -> Domain a
- lessThanDomain :: Dist a => Domain a -> Domain a
- lessOrEqualDomain :: Ord a => Domain a -> Domain a
- notEqual :: Dist a => Domain a -> Domain a
- null :: Domain a -> Bool
- isSingleton :: Eq a => Domain a -> Bool
- isInfinite :: Domain a -> Bool
- isSubsetOf :: Ord a => Domain a -> Domain a -> Bool
- sameElements :: Ord a => Domain a -> Domain a -> Bool
- elems :: Enum a => Domain a -> Maybe [a]
- member :: Ord a => a -> Domain a -> Bool
- maxValue :: Ord a => Domain a -> Maybe a
- minValue :: Ord a => Domain a -> Maybe a
- div :: (Dist a, Integral a) => Domain a -> Domain a -> Domain a
- inverseAbs :: (Dist a, Num a) => Domain a -> Domain a
- inverseSignum :: (Dist a, Num a) => Domain a -> Domain a
- pretty :: (Ord a, Show a) => Domain a -> String
- putPrettyLn :: (Ord a, Show a) => Domain a -> IO ()
Core Types
A numeric domain is a union of zero or more non-empty, non-overlapping,
open or closed numeric Interval
s.
Note that rounding errors due to floating point arithmetic are not handled at the lower and upper bounds of intervals.
intervals :: Domain a -> [Interval a] Source #
Returns the non-empty, non-overlapping intervals of a numeric domain in no specific order.
Package users will most likely not need this, except for custom logic regarding intervals that is not offered here (e.g., pretty printing).
Domain Construction
interval :: Ord a => LowerBound a -> UpperBound a -> Domain a Source #
Creates a domain with a single interval. If the lower bound is greater
than the upper bound, empty
is created.
greaterThan :: Dist a => a -> Domain a Source #
Creates a domain with values ranging from an exclusive lower bound to positive infinity.
greaterOrEqual :: a -> Domain a Source #
Creates a domain with values ranging from an inclusive lower bound to positive infinity.
lessThan :: Dist a => a -> Domain a Source #
Creates a domain with values ranging from negative infinity to an exclusive upper bound.
lessOrEqual :: a -> Domain a Source #
Creates a domain with values ranging from negative infinity to an inclusive upper bound.
maxDomain :: Domain a Source #
Creates a domain with values ranging from negative infinity to positive infinity.
(<..<) :: Dist a => a -> a -> Domain a Source #
Creates a domain with values between an exclusive lower bound and an exclusive upper bound.
If the lower bound is greater than the upper bound, empty
is returned.
(<=..<) :: Dist a => a -> a -> Domain a Source #
Creates a domain with values between an inclusive lower bound and an exclusive upper bound.
If the lower bound is greater than the upper bound, empty
is returned.
(<..<=) :: Dist a => a -> a -> Domain a Source #
Creates a domain with values between an exclusive lower bound and an inclusive upper bound.
If the lower bound is greater than the upper bound, empty
is returned.
(<=..<=) :: Ord a => a -> a -> Domain a Source #
Creates a domain with values between an inclusive lower bound and an inclusive upper bound.
If the lower bound is greater than the upper bound, empty
is returned.
Domain Combination
difference :: Dist a => Domain a -> Domain a -> Domain a Source #
Calculates the difference between two domains, i.e. difference whole
diff
contains all elements of the domain whole
that are not in the domain
diff
.
intersect :: Ord a => Domain a -> Domain a -> Domain a Source #
Calculates the intersection of two domains, i.e. intersect dx dy
contains all elements that are in both domains dx
and dy
.
union :: Dist a => Domain a -> Domain a -> Domain a Source #
Calculates the union of two domains, i.e. union dx dy
contains all
elements that are either in domain dx
or domain dy
.
greaterThanDomain :: Dist a => Domain a -> Domain a Source #
Creates a domain whose values are greater than the ones from another domain. If the passed domain is empty, the result is empty.
greaterOrEqualDomain :: Ord a => Domain a -> Domain a Source #
Creates a domain whose values are greater than or equal to the ones from another domain. If the passed domain is empty, the result is empty.
lessThanDomain :: Dist a => Domain a -> Domain a Source #
Creates a domain whose values are less than the ones from another domain. If the passed domain is empty, the result is empty.
lessOrEqualDomain :: Ord a => Domain a -> Domain a Source #
Creates a domain whose values are less than or equal to the ones from another domain. If the passed domain is empty, the result is empty.
notEqual :: Dist a => Domain a -> Domain a Source #
Creates a domain whose values differ from the ones of another domain.
This can only happen if the passed domain is a singleton domain (see
isSingleton
). In all other cases, maxDomain
is returned.
Domain Predicates
isInfinite :: Domain a -> Bool Source #
Checks if any domain interval has a lower bound of negative infinity or an upper bound of positive infinity.
isSubsetOf :: Ord a => Domain a -> Domain a -> Bool Source #
Checks if a domain is a subset of another domain, i.e. isSubsetOf sub
whole
returns True
if the domain whole
contains the domain sub
.
Equal domains are not considered as subsets.
sameElements :: Ord a => Domain a -> Domain a -> Bool Source #
Checks if two domains contain exactly the same elements.
Domain Values
elems :: Enum a => Domain a -> Maybe [a] Source #
Enumerates all elements of a domain in no specific order according to the
Enum
implementation of the domain value type.
Returns Nothing
if any interval of the domain is unbounded (see
isInfinite
).
maxValue :: Ord a => Domain a -> Maybe a Source #
Returns the greatest value of a domain if all of its intervals have a
non-infinite upper bound (see isInfinite
).
minValue :: Ord a => Domain a -> Maybe a Source #
Returns the smallest value of a domain if all of its intervals have a
non-infinite lower bound (see isInfinite
).
Domain Arithmetic
Note that the type Domain
implements the Num
and Fractional
type
classes for additional arithmetic operations.
div :: (Dist a, Integral a) => Domain a -> Domain a -> Domain a Source #
Calculates the integer division of two domains.
inverseAbs :: (Dist a, Num a) => Domain a -> Domain a Source #
Calculates the inverse abs function of a domain, i.e. positive values are also mirrored to their negative counterparts.
inverseSignum :: (Dist a, Num a) => Domain a -> Domain a Source #
Calculates the inverse signum function of a domain, i.e. if the domain
contains the values (-1)
, 0
and/or 1
, the result is the union of
negative infinity, zero and/or positive infinity, respectively.