Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
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
- 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
- interpolate :: (Space s, Ring (Element s)) => s -> Element 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) -> Maybe s
- unsafeSpace1 :: (Space s, Traversable f) => f (Element s) -> s
- randomS :: (Space s, RandomGen g, UniformRange (Element s)) => s -> g -> (Element s, g)
- randomSM :: (UniformRange (Element s), StatefulGen g m, Space s) => s -> g -> m (Element s)
- randomSs :: (Space s, RandomGen g, UniformRange (Element s)) => Int -> s -> g -> ([Element s], g)
- 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
Usage
>>>
:m -Prelude
>>>
:set -XRebindableSyntax
>>>
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
unsafeSpace1 (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 # | |
interpolate :: (Space s, Ring (Element s)) => s -> Element s -> Element s Source #
interpolate a space
interpolate s x == project s (zero ... one) x
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) -> 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
randomS :: (Space s, RandomGen g, UniformRange (Element s)) => s -> g -> (Element s, g) Source #
supply a random element within a Space
>>>
randomS (one :: Range Double) g
(0.43085240252163404,StdGen {unStdGen = SMGen 4530528345362647137 13679457532755275413})
randomSM :: (UniformRange (Element s), StatefulGen g m, Space s) => s -> g -> m (Element s) Source #
StatefulGen version of randomS
>>>
import Control.Monad
>>>
runStateGen_ g (randomSM (one :: Range Double))
0.43085240252163404
randomSs :: (Space s, RandomGen g, UniformRange (Element s)) => Int -> s -> g -> ([Element s], g) Source #
list of n random elements within a Space
>>>
let g = mkStdGen 42
>>>
fst (randomSs 3 (one :: Range Double) g)
[0.43085240252163404,-6.472345419562497e-2,0.3854692674681801]
>>>
fst (randomSs 3 (Rect 0 10 0 10 :: Rect Int) g)
[Point 0 7,Point 0 2,Point 1 7]
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
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 # | |
Functor Transform Source # | |
Show a => Show (Transform a) Source # | |
Eq a => Eq (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