numhask-space-0.6.1: numerical spaces

Safe HaskellNone
LanguageHaskell2010

NumHask.Space

Contents

Description

A continuous set of numbers.

Mathematics does not define a space, leaving library devs to experiment.

https://en.wikipedia.org/wiki/Space_(mathematics)

Synopsis

Space

The final frontier.

class Space s where Source #

Space is a continuous range of numbers that contains elements and has an upper and lower value.

a `union` b == b `union` a
a `intersection` b == b `intersection` a
(a `union` b) `intersection` c == (a `intersection` b) `union` (a `intersection` c)
(a `intersection` b) `union` c == (a `union` b) `intersection` (a `union` c)
norm (norm a) = norm a
a |>| b == b |<| a
a |.| singleton a

Minimal complete definition

lower, upper, (>.<)

Associated Types

type Element s :: Type Source #

the underlying element in the space

Methods

lower :: s -> Element s Source #

lower boundary

upper :: s -> Element s Source #

upper boundary

singleton :: Element s -> s Source #

space containing a single element

intersection :: s -> s -> s Source #

the intersection of two spaces

intersection :: Ord (Element s) => s -> s -> s Source #

the intersection of two spaces

union :: s -> s -> s Source #

the union of two spaces

union :: Ord (Element s) => s -> s -> s Source #

the union of two spaces

norm :: s -> s Source #

Normalise a space so that

lower a \/ upper a == lower a
lower a /\ upper a == upper a

(...) :: Element s -> Element s -> s infix 3 Source #

create a normalised space from two elements

(...) :: Ord (Element s) => Element s -> Element s -> s infix 3 Source #

create a normalised space from two elements

(>.<) :: Element s -> Element s -> s infix 3 Source #

create a space from two elements without normalising

(|.|) :: Element s -> s -> Bool infixl 7 Source #

is an element in the space

(|.|) :: Ord (Element s) => Element s -> s -> Bool infixl 7 Source #

is an element in the space

(|>|) :: s -> s -> Bool infixl 7 Source #

is one space completely above the other

(|>|) :: Ord (Element s) => s -> s -> Bool infixl 7 Source #

is one space completely above the other

(|<|) :: s -> s -> Bool infixl 7 Source #

is one space completely below the other

(|<|) :: Ord (Element s) => s -> s -> Bool infixl 7 Source #

is one space completely below the other

Instances
(Eq a, Ord a) => Space (Range a) Source # 
Instance details

Defined in NumHask.Space.Range

Associated Types

type Element (Range a) :: Type Source #

Ord a => Space (Rect a) Source # 
Instance details

Defined in NumHask.Space.Rect

Associated Types

type Element (Rect a) :: Type Source #

Methods

lower :: Rect a -> Element (Rect a) Source #

upper :: Rect a -> Element (Rect a) Source #

singleton :: Element (Rect a) -> Rect a Source #

intersection :: Rect a -> Rect a -> Rect a Source #

union :: Rect a -> Rect a -> Rect a Source #

norm :: Rect a -> Rect a Source #

(...) :: Element (Rect a) -> Element (Rect a) -> Rect a Source #

(>.<) :: Element (Rect a) -> Element (Rect a) -> Rect a Source #

(|.|) :: Element (Rect a) -> Rect a -> Bool Source #

(|>|) :: Rect a -> Rect a -> Bool Source #

(|<|) :: Rect a -> Rect a -> Bool Source #

newtype Union a Source #

a convex hull

Constructors

Union 

Fields

Instances
Space a => Semigroup (Union a) Source # 
Instance details

Defined in NumHask.Space.Types

Methods

(<>) :: Union a -> Union a -> Union a #

sconcat :: NonEmpty (Union a) -> Union a #

stimes :: Integral b => b -> Union a -> Union a #

class (Space s, Field (Element s)) => FieldSpace s where Source #

a space that can be divided neatly

space1 (grid OuterPos s g) == s
getUnion (sconcat (Union <$> (gridSpace s g))) == s

Associated Types

type Grid s :: Type Source #

Methods

grid :: Pos -> s -> Grid s -> [Element s] Source #

create equally-spaced elements across a space

gridSpace :: s -> Grid s -> [s] Source #

create equally-spaced spaces from a space

Instances
FieldSpace (Range Double) Source # 
Instance details

Defined in NumHask.Space.Range

Associated Types

type Grid (Range Double) :: Type Source #

FieldSpace (Rect Double) Source # 
Instance details

Defined in NumHask.Space.Rect

Associated Types

type Grid (Rect Double) :: Type Source #

mid :: (Space s, Field (Element s)) => s -> Element s Source #

middle element of the space

project :: (Space s, Field (Element s)) => s -> s -> Element s -> Element s Source #

project a data point from one space to another, preserving relative position

project o n (lower o) = lower n
project o n (upper o) = upper n
project o n (mid o) = mid n
project a a x = x

data Pos Source #

Pos suggests where points should be placed in forming a grid across a field space.

Constructors

OuterPos

include boundaries

InnerPos

don't include boundaries

LowerPos

include the lower boundary

UpperPos

include the upper boundary

MidPos

use the mid-point of the space

Instances
Eq Pos Source # 
Instance details

Defined in NumHask.Space.Types

Methods

(==) :: Pos -> Pos -> Bool #

(/=) :: Pos -> Pos -> Bool #

Show Pos Source # 
Instance details

Defined in NumHask.Space.Types

Methods

showsPrec :: Int -> Pos -> ShowS #

show :: Pos -> String #

showList :: [Pos] -> ShowS #

space1 :: (Space s, Traversable f) => f (Element s) -> s Source #

the containing space of a non-empty Traversable

all $ space1 a `contains` <$> a

memberOf :: Space s => Element s -> s -> Bool Source #

is an element contained within a space

contains :: Space s => s -> s -> Bool Source #

is a space contained within another?

(a `union` b) `contains` a
(a `union` b) `contains` b

disjoint :: Space s => s -> s -> Bool Source #

are two spaces disjoint?

width :: (Space s, Subtractive (Element s)) => s -> Element s Source #

distance between boundaries

(+/-) :: (Space s, Subtractive (Element s)) => Element s -> Element s -> s infixl 6 Source #

create a space centered on a plus or minus b

monotone :: (Space a, Space b) => (Element a -> Element b) -> a -> b Source #

lift a monotone function (increasing or decreasing) over a given space

eps :: (Space s, FromRational (Element s), Field (Element s)) => Element s -> Element s -> s Source #

a small space

widen :: (Space s, Ring (Element s)) => Element s -> s -> s Source #

widen a space

widenEps :: (Space s, FromRational (Element s), Field (Element s)) => Element s -> s -> s Source #

widen by a small amount

scale :: (Multiplicative (Element s), Space s) => Element s -> s -> s Source #

Scale a Space. (scalar multiplication)

move :: (Additive (Element s), Space s) => Element s -> s -> s Source #

Move a Space. (scalar addition)

Instances

Space is an interesting cross-section of many programming domains.

  • A Range is a Space of numbers.
  • A Rect is a Space of Points.
  • A time span is a space containing moments of time.
  • A histogram is a divided Range with a count of elements within each division.