Safe Haskell | None |
---|---|
Language | Haskell2010 |
Mathematics does not rigorously define a space, leaving library devs free to push boundaries on what a space is.
Synopsis
- class Space s where
- type Element s :: Type
- lower :: s -> Element s
- upper :: s -> Element s
- singleton :: Element s -> s
- intersection :: s -> s -> s
- union :: s -> s -> s
- normalise :: s -> s
- (...) :: Element s -> Element s -> s
- (>.<) :: Element s -> Element s -> s
- (|.|) :: Element s -> s -> Bool
- (|>|) :: s -> s -> Bool
- (|<|) :: s -> s -> Bool
- newtype Union a = Union {
- getUnion :: a
- newtype Intersection a = Intersection {
- getIntersection :: a
- class (Space s, Field (Element s)) => FieldSpace s where
- mid :: (Space s, Field (Element s)) => s -> Element s
- project :: (Space s, Field (Element s)) => s -> s -> Element s -> Element s
- data Pos
- space1 :: (Space s, Traversable f) => f (Element s) -> s
- randomS :: (Space s, RandomGen g, Random (Element s)) => s -> g -> (Element s, g)
- randomSs :: (Space s, RandomGen g, Random (Element s)) => s -> g -> [Element s]
- memberOf :: Space s => Element s -> s -> Bool
- contains :: Space s => s -> s -> Bool
- disjoint :: Space s => s -> s -> Bool
- width :: (Space s, Subtractive (Element s)) => s -> Element s
- (+/-) :: (Space s, Subtractive (Element s)) => Element s -> Element s -> s
- monotone :: (Space a, Space b) => (Element a -> Element b) -> a -> b
- eps :: (Space s, FromRational (Element s), Field (Element s)) => Element s -> Element s -> s
- widen :: (Space s, Ring (Element s)) => Element s -> s -> s
- widenEps :: (Space s, FromRational (Element s), Ring (Element s)) => Element s -> s -> s
- scale :: (Multiplicative (Element s), Space s) => Element s -> s -> s
- move :: (Additive (Element s), Space s) => Element s -> s -> s
- data Transform a = Transform {}
- inverseTransform :: (Eq a, Field a) => Transform a -> Maybe (Transform a)
- class Affinity a b | a -> b where
- (|.) :: Affinity a b => Transform b -> a -> a
- rotate :: TrigField a => a -> Transform a
- module NumHask.Space.Point
- module NumHask.Space.Range
- module NumHask.Space.Rect
- module NumHask.Space.Time
- module NumHask.Space.Histogram
- module NumHask.Space.XY
Usage
>>>
:set -XRebindableSyntax
>>>
:set -XNegativeLiterals
>>>
import NumHask.Prelude
>>>
import NumHask.Space
>>>
Point 1 1
Point 1 1
>>>
one :: Range Double
Range -0.5 0.5
>>>
grid OuterPos (Range 0 50 :: Range Double) 5
[0.0,10.0,20.0,30.0,40.0,50.0]
Space
Space is an interesting cross-section of many programming domains.
A Space
is a continuous set of numbers. Continuous here means that the set has an upper and lower bound, and an element that is between these two bounds is a member of the Space
.
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
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
default intersection :: Ord (Element s) => s -> s -> s Source #
the union of two spaces
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
(>.<) :: 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
(|>|) :: 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
Instances
a convex hull
newtype Intersection a Source #
Instances
Space a => Semigroup (Intersection a) Source # | |
Defined in NumHask.Space.Types (<>) :: Intersection a -> Intersection a -> Intersection a # sconcat :: NonEmpty (Intersection a) -> Intersection a # stimes :: Integral b => b -> Intersection a -> Intersection 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
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
(Field a, Ord a, FromIntegral a Int) => FieldSpace (Range a) Source # | |
(FromIntegral a Int, Field a, Ord a) => FieldSpace (Rect a) Source # | |
project :: (Space s, Field (Element s)) => s -> s -> Element s -> Element s Source #
project an element 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
Pos suggests where points should be placed in forming a grid across a field space.
space1 :: (Space s, Traversable f) => f (Element s) -> s Source #
the containing space of a non-empty Traversable
all $ space1 a `contains` <$> a
randomS :: (Space s, RandomGen g, Random (Element s)) => s -> g -> (Element s, g) Source #
supply a random element within a Space
randomSs :: (Space s, RandomGen g, Random (Element s)) => s -> g -> [Element s] Source #
supply an (infinite) list of random elements within a Space
>>>
let g = mkStdGen 42
>>>
take 3 $ randomSs (one :: Range Double) g
[0.43085240252163404,-6.472345419562497e-2,0.3854692674681801]
>>>
take 3 $ randomSs (Rect 0 10 0 10 :: Rect Word8) g
[Point 8 0,Point 6 4,Point 5 3]
contains :: Space s => s -> s -> Bool Source #
is a space contained within another?
(a `union` b) `contains` a (a `union` b) `contains` b
(+/-) :: (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
widenEps :: (Space s, FromRational (Element s), Ring (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)
linear transform + translate of a point-like number
(x, y) -> (ax + by + c, dx + ey + d)
or
\[ \begin{pmatrix} a & b & c\\ d & e & f\\ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x\\ y\\ 1 \end{pmatrix} \]
Instances
Functor Transform Source # | |
Foldable Transform Source # | |
Defined in NumHask.Space.Types fold :: Monoid m => Transform m -> m # foldMap :: Monoid m => (a -> m) -> Transform a -> m # foldMap' :: Monoid m => (a -> m) -> Transform a -> m # foldr :: (a -> b -> b) -> b -> Transform a -> b # foldr' :: (a -> b -> b) -> b -> Transform a -> b # foldl :: (b -> a -> b) -> b -> Transform a -> b # foldl' :: (b -> a -> b) -> b -> Transform a -> b # foldr1 :: (a -> a -> a) -> Transform a -> a # foldl1 :: (a -> a -> a) -> Transform a -> a # toList :: Transform a -> [a] # length :: Transform a -> Int # elem :: Eq a => a -> Transform a -> Bool # maximum :: Ord a => Transform a -> a # minimum :: Ord a => Transform a -> a # | |
Traversable Transform Source # | |
Eq a => Eq (Transform a) Source # | |
Show a => Show (Transform a) Source # | |
(Multiplicative a, Additive a) => Affinity (Transform a) a Source # | |
inverseTransform :: (Eq a, Field a) => Transform a -> Maybe (Transform a) Source #
Calculate the inverse of a transformation.
class Affinity a b | a -> b where Source #
An Affinity
is something that can be subjected to an affine transformation in 2-dimensional space, where affine means a linear matrix operation or a translation (+).
Instances
module NumHask.Space.Point
module NumHask.Space.Range
module NumHask.Space.Rect
module NumHask.Space.Time
module NumHask.Space.Histogram
module NumHask.Space.XY