data-interval-2.1.1: Interval datatype, interval arithmetic and interval-based containers
Copyright (c) Masahiro Sakai 2011-2013 Andrew Lelechenko 2020
License BSD-style
Maintainer masahiro.sakai@gmail.com
Stability provisional
Portability non-portable (CPP, ScopedTypeVariables, DeriveDataTypeable)
Safe Haskell Safe
Language Haskell2010

Data.Interval

Description

Interval datatype and interval arithmetic.

Unlike the intervals package ( http://hackage.haskell.org/package/intervals ), this module provides both open and closed intervals and is intended to be used with Rational .

For the purpose of abstract interpretation, it might be convenient to use Lattice instance. See also lattices package ( http://hackage.haskell.org/package/lattices ).

Synopsis

Interval type

data Interval r Source #

The intervals ( i.e. connected and convex subsets) over real numbers R .

Instances

Instances details
Eq r => Eq ( Interval r) Source #
Instance details

Defined in Data.Interval.Internal

( RealFrac r, Floating r) => Floating ( Interval r) Source #

When results of tan or ** do not form a connected interval, a convex hull is returned instead.

Instance details

Defined in Data.Interval

( Real r, Fractional r) => Fractional ( Interval r) Source #

recip returns whole when 0 is an interior point. Otherwise recip (recip xs) equals to xs without 0.

Instance details

Defined in Data.Interval

( Ord r, Data r) => Data ( Interval r) Source #
Instance details

Defined in Data.Interval.Internal

Methods

gfoldl :: ( forall d b. Data d => c (d -> b) -> d -> c b) -> ( forall g. g -> c g) -> Interval r -> c ( Interval r) Source #

gunfold :: ( forall b r0. Data b => c (b -> r0) -> c r0) -> ( forall r1. r1 -> c r1) -> Constr -> c ( Interval r) Source #

toConstr :: Interval r -> Constr Source #

dataTypeOf :: Interval r -> DataType Source #

dataCast1 :: Typeable t => ( forall d. Data d => c (t d)) -> Maybe (c ( Interval r)) Source #

dataCast2 :: Typeable t => ( forall d e. ( Data d, Data e) => c (t d e)) -> Maybe (c ( Interval r)) Source #

gmapT :: ( forall b. Data b => b -> b) -> Interval r -> Interval r Source #

gmapQl :: (r0 -> r' -> r0) -> r0 -> ( forall d. Data d => d -> r') -> Interval r -> r0 Source #

gmapQr :: forall r0 r'. (r' -> r0 -> r0) -> r0 -> ( forall d. Data d => d -> r') -> Interval r -> r0 Source #

gmapQ :: ( forall d. Data d => d -> u) -> Interval r -> [u] Source #

gmapQi :: Int -> ( forall d. Data d => d -> u) -> Interval r -> u Source #

gmapM :: Monad m => ( forall d. Data d => d -> m d) -> Interval r -> m ( Interval r) Source #

gmapMp :: MonadPlus m => ( forall d. Data d => d -> m d) -> Interval r -> m ( Interval r) Source #

gmapMo :: MonadPlus m => ( forall d. Data d => d -> m d) -> Interval r -> m ( Interval r) Source #

( Num r, Ord r) => Num ( Interval r) Source #

When results of abs or signum do not form a connected interval, a convex hull is returned instead.

Instance details

Defined in Data.Interval

( Ord r, Read r) => Read ( Interval r) Source #
Instance details

Defined in Data.Interval

( Ord r, Show r) => Show ( Interval r) Source #
Instance details

Defined in Data.Interval

( Storable r, Ord r) => Storable ( Interval r) Source #
Instance details

Defined in Data.Interval.Internal

NFData r => NFData ( Interval r) Source #
Instance details

Defined in Data.Interval.Internal

Hashable r => Hashable ( Interval r) Source #
Instance details

Defined in Data.Interval.Internal

Ord r => Lattice ( Interval r) Source #
Instance details

Defined in Data.Interval

Ord r => BoundedJoinSemiLattice ( Interval r) Source #
Instance details

Defined in Data.Interval

Ord r => BoundedMeetSemiLattice ( Interval r) Source #
Instance details

Defined in Data.Interval

data Boundary Source #

Boundary of an interval may be open (excluding an endpoint) or closed (including an endpoint).

Since: 2.0.0

Constructors

Open
Closed

Instances

Instances details
Bounded Boundary Source #
Instance details

Defined in Data.Interval.Internal

Enum Boundary Source #
Instance details

Defined in Data.Interval.Internal

Eq Boundary Source #
Instance details

Defined in Data.Interval.Internal

Data Boundary Source #
Instance details

Defined in Data.Interval.Internal

Methods

gfoldl :: ( forall d b. Data d => c (d -> b) -> d -> c b) -> ( forall g. g -> c g) -> Boundary -> c Boundary Source #

gunfold :: ( forall b r. Data b => c (b -> r) -> c r) -> ( forall r. r -> c r) -> Constr -> c Boundary Source #

toConstr :: Boundary -> Constr Source #

dataTypeOf :: Boundary -> DataType Source #

dataCast1 :: Typeable t => ( forall d. Data d => c (t d)) -> Maybe (c Boundary ) Source #

dataCast2 :: Typeable t => ( forall d e. ( Data d, Data e) => c (t d e)) -> Maybe (c Boundary ) Source #

gmapT :: ( forall b. Data b => b -> b) -> Boundary -> Boundary Source #

gmapQl :: (r -> r' -> r) -> r -> ( forall d. Data d => d -> r') -> Boundary -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> ( forall d. Data d => d -> r') -> Boundary -> r Source #

gmapQ :: ( forall d. Data d => d -> u) -> Boundary -> [u] Source #

gmapQi :: Int -> ( forall d. Data d => d -> u) -> Boundary -> u Source #

gmapM :: Monad m => ( forall d. Data d => d -> m d) -> Boundary -> m Boundary Source #

gmapMp :: MonadPlus m => ( forall d. Data d => d -> m d) -> Boundary -> m Boundary Source #

gmapMo :: MonadPlus m => ( forall d. Data d => d -> m d) -> Boundary -> m Boundary Source #

Ord Boundary Source #
Instance details

Defined in Data.Interval.Internal

Read Boundary Source #
Instance details

Defined in Data.Interval.Internal

Show Boundary Source #
Instance details

Defined in Data.Interval.Internal

Generic Boundary Source #
Instance details

Defined in Data.Interval.Internal

NFData Boundary Source #
Instance details

Defined in Data.Interval.Internal

Hashable Boundary Source #
Instance details

Defined in Data.Interval.Internal

type Rep Boundary Source #
Instance details

Defined in Data.Interval.Internal

type Rep Boundary = D1 (' MetaData "Boundary" "Data.Interval.Internal" "data-interval-2.1.1-jjCLLjrbX0CbBkgE3fWWY" ' False ) ( C1 (' MetaCons "Open" ' PrefixI ' False ) ( U1 :: Type -> Type ) :+: C1 (' MetaCons "Closed" ' PrefixI ' False ) ( U1 :: Type -> Type ))

Construction

interval Source #

Arguments

:: Ord r
=> ( Extended r, Boundary )

lower bound and whether it is included

-> ( Extended r, Boundary )

upper bound and whether it is included

-> Interval r

smart constructor for Interval

(<=..<=) infix 5 Source #

Arguments

:: Ord r
=> Extended r

lower bound l

-> Extended r

upper bound u

-> Interval r

closed interval [ l , u ]

(<..<=) infix 5 Source #

Arguments

:: Ord r
=> Extended r

lower bound l

-> Extended r

upper bound u

-> Interval r

left-open right-closed interval ( l , u ]

(<=..<) infix 5 Source #

Arguments

:: Ord r
=> Extended r

lower bound l

-> Extended r

upper bound u

-> Interval r

left-closed right-open interval [ l , u )

(<..<) infix 5 Source #

Arguments

:: Ord r
=> Extended r

lower bound l

-> Extended r

upper bound u

-> Interval r

open interval ( l , u )

whole :: Ord r => Interval r Source #

whole real number line (-∞, ∞)

empty :: Ord r => Interval r Source #

empty (contradicting) interval

singleton :: Ord r => r -> Interval r Source #

singleton set [x,x]

Query

null :: Ord r => Interval r -> Bool Source #

Is the interval empty?

isSingleton :: Ord r => Interval r -> Bool Source #

Is the interval single point?

Since: 2.0.0

extractSingleton :: Ord r => Interval r -> Maybe r Source #

If the interval is a single point, return this point.

Since: 2.1.0

member :: Ord r => r -> Interval r -> Bool Source #

Is the element in the interval?

notMember :: Ord r => r -> Interval r -> Bool Source #

Is the element not in the interval?

isSubsetOf :: Ord r => Interval r -> Interval r -> Bool Source #

Is this a subset? (i1 ` isSubsetOf ` i2) tells whether i1 is a subset of i2 .

isProperSubsetOf :: Ord r => Interval r -> Interval r -> Bool Source #

Is this a proper subset? ( i.e. a subset but not equal).

isConnected :: Ord r => Interval r -> Interval r -> Bool Source #

Does the union of two range form a connected set?

Since 1.3.0

lowerBound :: Interval r -> Extended r Source #

Lower endpoint ( i.e. greatest lower bound) of the interval.

upperBound :: Interval r -> Extended r Source #

Upper endpoint ( i.e. least upper bound) of the interval.

lowerBound' :: Interval r -> ( Extended r, Boundary ) Source #

Lower endpoint ( i.e. greatest lower bound) of the interval, together with Boundary information. The result is convenient to use as an argument for interval .

upperBound' :: Interval r -> ( Extended r, Boundary ) Source #

Upper endpoint ( i.e. least upper bound) of the interval, together with Boundary information. The result is convenient to use as an argument for interval .

width :: ( Num r, Ord r) => Interval r -> r Source #

Width of a interval. Width of an unbounded interval is undefined .

Universal comparison operators

(<!) :: Ord r => Interval r -> Interval r -> Bool infix 4 Source #

For all x in X , y in Y . x < y ?

(<=!) :: Ord r => Interval r -> Interval r -> Bool infix 4 Source #

For all x in X , y in Y . x <= y ?

(==!) :: Ord r => Interval r -> Interval r -> Bool infix 4 Source #

For all x in X , y in Y . x == y ?

(>=!) :: Ord r => Interval r -> Interval r -> Bool infix 4 Source #

For all x in X , y in Y . x >= y ?

(>!) :: Ord r => Interval r -> Interval r -> Bool infix 4 Source #

For all x in X , y in Y . x > y ?

(/=!) :: Ord r => Interval r -> Interval r -> Bool infix 4 Source #

For all x in X , y in Y . x /= y ?

Since 1.0.1

Existential comparison operators

(<?) :: Ord r => Interval r -> Interval r -> Bool infix 4 Source #

Does there exist an x in X , y in Y such that x < y ?

(<=?) :: Ord r => Interval r -> Interval r -> Bool infix 4 Source #

Does there exist an x in X , y in Y such that x <= y ?

(==?) :: Ord r => Interval r -> Interval r -> Bool infix 4 Source #

Does there exist an x in X , y in Y such that x == y ?

Since 1.0.0

(>=?) :: Ord r => Interval r -> Interval r -> Bool infix 4 Source #

Does there exist an x in X , y in Y such that x >= y ?

(>?) :: Ord r => Interval r -> Interval r -> Bool infix 4 Source #

Does there exist an x in X , y in Y such that x > y ?

(/=?) :: Ord r => Interval r -> Interval r -> Bool infix 4 Source #

Does there exist an x in X , y in Y such that x /= y ?

Since 1.0.1

Existential comparison operators that produce witnesses (experimental)

(<??) :: ( Real r, Fractional r) => Interval r -> Interval r -> Maybe (r, r) infix 4 Source #

Does there exist an x in X , y in Y such that x < y ?

Since 1.0.0

(<=??) :: ( Real r, Fractional r) => Interval r -> Interval r -> Maybe (r, r) infix 4 Source #

Does there exist an x in X , y in Y such that x <= y ?

Since 1.0.0

(==??) :: ( Real r, Fractional r) => Interval r -> Interval r -> Maybe (r, r) infix 4 Source #

Does there exist an x in X , y in Y such that x == y ?

Since 1.0.0

(>=??) :: ( Real r, Fractional r) => Interval r -> Interval r -> Maybe (r, r) infix 4 Source #

Does there exist an x in X , y in Y such that x >= y ?

Since 1.0.0

(>??) :: ( Real r, Fractional r) => Interval r -> Interval r -> Maybe (r, r) infix 4 Source #

Does there exist an x in X , y in Y such that x > y ?

Since 1.0.0

(/=??) :: ( Real r, Fractional r) => Interval r -> Interval r -> Maybe (r, r) infix 4 Source #

Does there exist an x in X , y in Y such that x /= y ?

Since 1.0.1

Combine

intersection :: forall r. Ord r => Interval r -> Interval r -> Interval r Source #

intersection of two intervals

intersections :: Ord r => [ Interval r] -> Interval r Source #

intersection of a list of intervals.

Since 0.6.0

hull :: forall r. Ord r => Interval r -> Interval r -> Interval r Source #

convex hull of two intervals

hulls :: Ord r => [ Interval r] -> Interval r Source #

convex hull of a list of intervals.

Since 0.6.0

Map

mapMonotonic :: ( Ord a, Ord b) => (a -> b) -> Interval a -> Interval b Source #

mapMonotonic f i is the image of i under f , where f must be a strict monotone function, preserving negative and positive infinities.

Operations

pickup :: ( Real r, Fractional r) => Interval r -> Maybe r Source #

pick up an element from the interval if the interval is not empty.

simplestRationalWithin :: RealFrac r => Interval r -> Maybe Rational Source #

simplestRationalWithin returns the simplest rational number within the interval.

A rational number y is said to be simpler than another y' if

(see also approxRational )

Since 0.4.0

Intervals relation

relate :: Ord r => Interval r -> Interval r -> Relation Source #

Computes how two intervals are related according to the Relation classification

Orphan instances

( RealFrac r, Floating r) => Floating ( Interval r) Source #

When results of tan or ** do not form a connected interval, a convex hull is returned instead.

Instance details

( Real r, Fractional r) => Fractional ( Interval r) Source #

recip returns whole when 0 is an interior point. Otherwise recip (recip xs) equals to xs without 0.

Instance details

( Num r, Ord r) => Num ( Interval r) Source #

When results of abs or signum do not form a connected interval, a convex hull is returned instead.

Instance details

( Ord r, Read r) => Read ( Interval r) Source #
Instance details

( Ord r, Show r) => Show ( Interval r) Source #
Instance details

Ord r => Lattice ( Interval r) Source #
Instance details

Ord r => BoundedJoinSemiLattice ( Interval r) Source #
Instance details

Ord r => BoundedMeetSemiLattice ( Interval r) Source #
Instance details