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

Contents

Description

This module exports the types and functions needed to construct, combine and process lower and upper bounds of numeric intervals.

Package users might want to use the module Numeric.Domain instead, since it provides a convenient abstraction for intervals and their bounds.

Synopsis

Core Types

data LowerBound a Source #

The lower bound of an interval. Can be open, closed or negative infinity.

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

Defined in Numeric.Bound

Methods

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

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

Ord a => Ord (LowerBound a) Source # 
Instance details

Defined in Numeric.Bound

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

Defined in Numeric.Bound

data UpperBound a Source #

The upper bound of an interval. Can be open, closed or positive infinity.

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

Defined in Numeric.Bound

Methods

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

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

Ord a => Ord (UpperBound a) Source # 
Instance details

Defined in Numeric.Bound

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

Defined in Numeric.Bound

Bound Construction

closedLower :: a -> LowerBound a Source #

Creates a closed lower bound.

closedUpper :: a -> UpperBound a Source #

Creates a closed upper bound.

openLower :: Dist a => a -> LowerBound a Source #

Creates an open lower bound. Internally, the bound is converted to a closed one, if possible.

openUpper :: Dist a => a -> UpperBound a Source #

Creates an open upper bound. Internally, the bound is converted to a closed one, if possible.

infiniteLower :: LowerBound a Source #

Creates a negative infinite lower bound.

infiniteUpper :: UpperBound a Source #

Creates a positive infinite upper bound.

Bound Combination

adjacentLower :: Dist a => UpperBound a -> Maybe (LowerBound a) Source #

Creates a lower bound that is adjacent to (i.e., directly above) a given upper bound.

Returns Nothing if the upper bound is positive infinity.

adjacentUpper :: Dist a => LowerBound a -> Maybe (UpperBound a) Source #

Creates an upper bound that is adjacent to (i.e., directly below) a given lower bound.

Returns Nothing if the lower bound is negative infinity.

Bound Predicates

mergeable :: Dist a => UpperBound a -> LowerBound a -> Bool Source #

Checks if an upper bound and a lower bound are mergeable, i.e. if they overlap or if they are adjacent to each other.

Note that adjacency depends on the type of the bound values, e.g. the upper bound [...,3] and lower bound [4,...] can be merged for Interval Int, but not for Interval Double.

Infinite bounds (negative infinity, positive infinity) are never mergeable.

isAbove :: Ord a => LowerBound a -> UpperBound a -> Bool Source #

Checks if a lower bound is above an upper bound.

isBelow :: Ord a => UpperBound a -> LowerBound a -> Bool Source #

Checks if an upper bound is below a lower bound.

isSingleton :: Eq a => LowerBound a -> UpperBound a -> Bool Source #

Checks if a lower bound and an upper bound contain exactly one element.

isInfiniteLower :: LowerBound a -> Bool Source #

Checks if a lower bound is negative infinity.

isInfiniteUpper :: UpperBound a -> Bool Source #

Checks if an upper bound is positive infinity.

isPositiveLower :: (Num a, Ord a) => LowerBound a -> Bool Source #

Checks if a lower bound is positive.

isPositiveUpper :: (Num a, Ord a) => UpperBound a -> Bool Source #

Checks if an upper bound is positive.

isNegativeLower :: (Num a, Ord a) => LowerBound a -> Bool Source #

Checks if a lower bound is negative.

isNegativeUpper :: (Num a, Ord a) => UpperBound a -> Bool Source #

Checks if an upper bound is negative.

isZeroLower :: (Eq a, Num a) => LowerBound a -> Bool Source #

Checks if a lower bound is zero. It is ignored if the bound is open or closed.

isZeroUpper :: (Eq a, Num a) => UpperBound a -> Bool Source #

Checks if an upper bound is zero. It is ignored if the bound is open or closed.

containsLower :: Ord a => a -> LowerBound a -> Bool Source #

Checks if a lower bound contains a specific value, i.e. if the value is equal to (if closed) or greater than (if open or closed) the lower bound.

containsUpper :: Ord a => a -> UpperBound a -> Bool Source #

Checks if an upper bound contains a specific value, i.e. if the value is equal to (if closed) or less than (if open or closed) the upper bound.

Bound Values

elems :: Enum a => LowerBound a -> UpperBound a -> Maybe [a] Source #

Enumerates all elements between a lower bound and an upper bound in ascending order according to the Enum implementation of their value type.

Returns Nothing if any of the two bounds is infinite.

minValue :: LowerBound a -> Maybe a Source #

Returns the smallest value of a lower bound.

Only succeeds if the lower bound is closed.

maxValue :: UpperBound a -> Maybe a Source #

Returns the greatest value of an upper bound.

Only succeeds if the upper bound is closed.

Bound Arithmetic

data Result a Source #

A special type for representing the result of bound multiplications and divisions. These operations can either yield a lower bound, an upper bound or both.

Constructors

Lower (LowerBound a) 
Upper (UpperBound a) 
Both (LowerBound a) (UpperBound a) 
Instances
Eq a => Eq (Result a) Source # 
Instance details

Defined in Numeric.Bound

Methods

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

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

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

Defined in Numeric.Bound

Methods

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

show :: Result a -> String #

showList :: [Result a] -> ShowS #

applyResult :: Ord a => (Maybe (LowerBound a), Maybe (UpperBound a)) -> Result a -> (Maybe (LowerBound a), Maybe (UpperBound a)) Source #

Given a possible lower bound and upper bound as well as a result from a bound multiplication or division, this function updates the bounds depending on whether the result was a lower bound, upper bound or both.

The lower bound is updated by favouring the smaller one, while the upper bound is updated by favouring the greater one.

plusLower :: Num a => LowerBound a -> LowerBound a -> LowerBound a Source #

Adds the values of two lower bounds.

plusUpper :: Num a => UpperBound a -> UpperBound a -> UpperBound a Source #

Adds the values of two upper bounds.

minusLower :: Num a => UpperBound a -> LowerBound a -> UpperBound a Source #

Subtracts the value of a lower bound from the value of an upper bound.

minusUpper :: Num a => LowerBound a -> UpperBound a -> LowerBound a Source #

Subtracts the value of an upper bound from the value of a lower bound.

timesLower :: (Num a, Ord a) => LowerBound a -> LowerBound a -> Result a Source #

Multiplies the values of two lower bounds.

timesUpper :: (Num a, Ord a) => UpperBound a -> UpperBound a -> Result a Source #

Multiplies the values of two upper bounds.

timesMixed :: (Num a, Ord a) => LowerBound a -> UpperBound a -> Result a Source #

Multiplies the value of a lower bound and the value of an upper bound.

divLower :: Integral a => LowerBound a -> LowerBound a -> Result a Source #

Divides the values of two lower bounds using integer division.

Note that it is not checked if the divisor bound is zero, which yields an error. Such a check must happen before calling this function.

divUpper :: Integral a => UpperBound a -> UpperBound a -> Result a Source #

Divides the values of two upper bounds using integer division.

Note that it is not checked if the divisor bound is zero, which yields an error. Such a check must happen before calling this function.

divLowerUpper :: Integral a => LowerBound a -> UpperBound a -> Result a Source #

Divides the values of a lower bound and an upper bound using integer division.

Note that it is not checked if the divisor bound is zero, which yields an error. Such a check must happen before calling this function.

divUpperLower :: Integral a => UpperBound a -> LowerBound a -> Result a Source #

Divides the values of an upper bound and a lower bound using integer division.

Note that it is not checked if the divisor bound is zero, which yields an error. Such a check must happen before calling this function.

recipLower :: Fractional a => LowerBound a -> UpperBound a Source #

Calculates the reciprocal of a lower bound and transforms it into an upper bound.

recipUpper :: Fractional a => UpperBound a -> LowerBound a Source #

Calculates the reciprocal of an upper bound and transforms it into a lower bound.

negateLower :: Num a => LowerBound a -> UpperBound a Source #

Negates a lower bound and transforms it into an upper bound.

negateUpper :: Num a => UpperBound a -> LowerBound a Source #

Negates an upper bound and transforms it into a lower bound.

Bound Presentation

prettyLower :: Show a => LowerBound a -> String Source #

Returns a pretty string for a lower bound by using the Unicode symbol for negative infinity.

prettyUpper :: Show a => UpperBound a -> String Source #

Returns a pretty string for an upper bound by using the Unicode symbol for positive infinity.