numeric-domains-0.1.0.0: Numeric Domains

Copyright(c) Michael Szvetits 2019
LicenseBSD3 (see the file LICENSE)
Maintainertypedbyte@qualified.name
Stabilitystable
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Numeric.Domain

Contents

Description

This module exports the types and functions needed to construct, combine and process numeric domains.

Synopsis

Core Types

data Domain a Source #

A numeric domain is a union of zero or more non-empty, non-overlapping, open or closed numeric Intervals.

Note that rounding errors due to floating point arithmetic are not handled at the lower and upper bounds of intervals.

Instances
Eq a => Eq (Domain a) Source # 
Instance details

Defined in Numeric.Domain

Methods

(==) :: Domain a -> Domain a -> Bool #

(/=) :: Domain a -> Domain a -> Bool #

(Dist a, Fractional a) => Fractional (Domain a) Source # 
Instance details

Defined in Numeric.Domain

Methods

(/) :: Domain a -> Domain a -> Domain a #

recip :: Domain a -> Domain a #

fromRational :: Rational -> Domain a #

(Dist a, Num a) => Num (Domain a) Source # 
Instance details

Defined in Numeric.Domain

Methods

(+) :: Domain a -> Domain a -> Domain a #

(-) :: Domain a -> Domain a -> Domain a #

(*) :: Domain a -> Domain a -> Domain a #

negate :: Domain a -> Domain a #

abs :: Domain a -> Domain a #

signum :: Domain a -> Domain a #

fromInteger :: Integer -> Domain a #

Show a => Show (Domain a) Source # 
Instance details

Defined in Numeric.Domain

Methods

showsPrec :: Int -> Domain a -> ShowS #

show :: Domain a -> String #

showList :: [Domain a] -> ShowS #

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

empty :: Domain a Source #

Creates an empty domain which contains no elements.

singleton :: a -> Domain a Source #

Creates a domain with a single element.

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

null :: Domain a -> Bool Source #

Checks if a domain is empty, i.e. contains no elements.

isSingleton :: Eq a => Domain a -> Bool Source #

Checks if a domain contains exactly one element.

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).

member :: Ord a => a -> Domain a -> Bool Source #

Checks if a domain contains a specific value.

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.

Domain Presentation

pretty :: (Ord a, Show a) => Domain a -> String Source #

Returns a pretty string for a domain by sorting its intervals in ascending order and using Unicode symbols for infinity and unions.

putPrettyLn :: (Ord a, Show a) => Domain a -> IO () Source #

Same as pretty, but with an additional output to standard output.