| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
NumHask.Space
Description
Mathematics does not rigorously define a space, leaving library devs free to explore.
“But who can quantify the algebra of space, or weigh those worlds that swim each in its place? Who can outdo the dark? And what computer knows how beauty comes to birth - shell star and rose?
~ Technicians by Jean Kenward” ~ John Foster
Synopsis
- (+/-) :: (Space s, Subtractive (Element s)) => Element s -> Element s -> s
- contains :: Space s => s -> s -> Bool
- disjoint :: Space s => s -> s -> Bool
- eps :: (Space s, FromRational (Element s), Field (Element s)) => Element s -> Element s -> s
- interpolate :: (Space s, Ring (Element s)) => s -> Element s -> Element s
- inverseTransform :: (Eq a, Field a) => Transform a -> Maybe (Transform a)
- memberOf :: Space s => Element s -> s -> Bool
- mid :: (Space s, Field (Element s)) => s -> Element s
- monotone :: (Space a, Space b) => (Element a -> Element b) -> a -> b
- move :: (Additive (Element s), Space s) => Element s -> s -> s
- project :: (Space s, Field (Element s)) => s -> s -> Element s -> Element s
- rotate :: TrigField a => a -> Transform a
- scale :: (Multiplicative (Element s), Space s) => Element s -> s -> s
- space1 :: (Space s, Traversable f) => f (Element s) -> Maybe s
- unsafeSpace1 :: (Space s, Traversable f) => f (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
- width :: (Space s, Subtractive (Element s)) => s -> Element s
- (|.) :: Affinity a b => Transform b -> a -> a
- class Affinity a b | a -> b where
- type family Element s
- class (Space s, Field (Element s)) => FieldSpace s where
- type family Grid s
- newtype Intersection a = Intersection {
- getIntersection :: a
- data Pos
- class Space s where
- type Element s
- 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
- data Transform a = Transform {}
- newtype Union a = Union {
- getUnion :: a
- module NumHask.Space.Chart
- module NumHask.Space.Point
- module NumHask.Space.Range
- module NumHask.Space.Rect
- module NumHask.Space.Time
- module NumHask.Space.Histogram
Usage
>>>:m -Prelude>>>:set -XRebindableSyntax>>>import NumHask.Prelude>>>import NumHask.Space>>>Point 1 1Point 1 1
>>>one :: Range DoubleRange -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.
(+/-) :: (Space s, Subtractive (Element s)) => Element s -> Element s -> s infixl 6 Source #
create a space centered on a plus or minus b
contains :: Space s => s -> s -> Bool Source #
is a space contained within another?
(a `union` b) `contains` a (a `union` b) `contains` b
eps :: (Space s, FromRational (Element s), Field (Element s)) => Element s -> Element s -> s Source #
a small space
interpolate :: (Space s, Ring (Element s)) => s -> Element s -> Element s Source #
interpolate a space
interpolate s x == project s (zero ... one) x
inverseTransform :: (Eq a, Field a) => Transform a -> Maybe (Transform a) Source #
Calculate the inverse of a transformation.
monotone :: (Space a, Space b) => (Element a -> Element b) -> a -> b Source #
lift a monotone function (increasing or decreasing) over a given space
move :: (Additive (Element s), Space s) => Element s -> s -> s Source #
Move a Space. (scalar addition)
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
scale :: (Multiplicative (Element s), Space s) => Element s -> s -> s Source #
Scale a Space. (scalar multiplication)
space1 :: (Space s, Traversable f) => f (Element s) -> Maybe s Source #
Maybe containing space of a traversable.
unsafeSpace1 :: (Space s, Traversable f) => f (Element s) -> s Source #
the containing space of a non-empty Traversable.
partial function.
all $ unsafeSpace1 a `contains` <$> a
widenEps :: (Space s, FromRational (Element s), Ring (Element s)) => Element s -> s -> s Source #
widen by a small amount
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 (+).
class (Space s, Field (Element s)) => FieldSpace s where Source #
a space that can be divided neatly
unsafeSpace1 (grid OuterPos s g) == s getUnion (sconcat (Union <$> (gridSpace s g))) == s
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
| (Field a, Ord a, FromIntegral a Int) => FieldSpace (Range a) Source # | |
| (FromIntegral a Int, Field a, Ord a) => FieldSpace (Rect a) Source # | |
the type that divides or quotients the space
newtype Intersection a Source #
Constructors
| Intersection | |
Fields
| |
Instances
| Space a => Semigroup (Intersection a) Source # | |
Defined in NumHask.Space.Types Methods (<>) :: Intersection a -> Intersection a -> Intersection a # sconcat :: NonEmpty (Intersection a) -> Intersection a # stimes :: Integral b => b -> Intersection a -> Intersection a # | |
Pos suggests where points should be placed in forming a grid across a field space.
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
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
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
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 Methods 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 # | |
Defined in NumHask.Space.Types | |
| Eq a => Eq (Transform a) Source # | |
| Show a => Show (Transform a) Source # | |
| (Multiplicative a, Additive a) => Affinity (Transform a) a Source # | |
a convex hull
Charts
module NumHask.Space.Chart
Instances
module NumHask.Space.Point
module NumHask.Space.Range
module NumHask.Space.Rect
module NumHask.Space.Time
module NumHask.Space.Histogram