numhask-0.11.1.0: A numeric class hierarchy.
Safe HaskellSafe-Inferred
LanguageGHC2021

NumHask.Algebra.Metric

Description

Metric classes

Synopsis

Documentation

class Distributive (Mag a) => Basis a where Source #

Basis encapsulates the notion of magnitude (intuitively the quotienting of a higher-kinded number to a scalar one) and the basis on which the magnitude quotienting was performed. An instance needs to satisfy these laws:

\a -> magnitude a >= zero
\a -> magnitude zero == zero
\a -> a == magnitude a *| basis a
\a -> magnitude (basis a) == one

The names chosen are meant to represent the spiritual idea of a basis rather than a specific mathematics. See https://en.wikipedia.org/wiki/Basis_(linear_algebra) & https://en.wikipedia.org/wiki/Norm_(mathematics) for some mathematical motivations.

>>> magnitude (-0.5 :: Double)
0.5
>>> basis (-0.5 :: Double)
-1.0

Associated Types

type Mag a :: Type Source #

type Base a :: Type Source #

Methods

magnitude :: a -> Mag a Source #

or length, or ||v||

basis :: a -> Base a Source #

or direction, or v-hat

Instances

Instances details
Basis Int16 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Int16 Source #

type Base Int16 Source #

Basis Int32 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Int32 Source #

type Base Int32 Source #

Basis Int64 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Int64 Source #

type Base Int64 Source #

Basis Int8 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Int8 Source #

type Base Int8 Source #

Basis Word16 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Word16 Source #

type Base Word16 Source #

Basis Word32 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Word32 Source #

type Base Word32 Source #

Basis Word64 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Word64 Source #

type Base Word64 Source #

Basis Word8 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Word8 Source #

type Base Word8 Source #

Basis Integer Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Integer Source #

type Base Integer Source #

Basis Natural Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Natural Source #

type Base Natural Source #

Basis Double Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Double Source #

type Base Double Source #

Basis Float Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Float Source #

type Base Float Source #

Basis Int Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Int Source #

type Base Int Source #

Basis Word Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag Word Source #

type Base Word Source #

(ExpField a, Eq a) => Basis (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag (EuclideanPair a) Source #

type Base (EuclideanPair a) Source #

(Additive a, Multiplicative a) => Basis (Polar a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag (Polar a) Source #

type Base (Polar a) Source #

Methods

magnitude :: Polar a -> Mag (Polar a) Source #

basis :: Polar a -> Base (Polar a) Source #

(ExpField a, Eq a) => Basis (Complex a) Source # 
Instance details

Defined in NumHask.Data.Complex

Associated Types

type Mag (Complex a) Source #

type Base (Complex a) Source #

(Ord a, EndoBased a, Integral a, Ring a) => Basis (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

Associated Types

type Mag (Ratio a) Source #

type Base (Ratio a) Source #

Methods

magnitude :: Ratio a -> Mag (Ratio a) Source #

basis :: Ratio a -> Base (Ratio a) Source #

type Absolute a = (Basis a, Mag a ~ a) Source #

Basis where the domain and magnitude codomain are the same.

type Sign a = (Basis a, Base a ~ a) Source #

Basis where the domain and basis codomain are the same.

type EndoBased a = (Basis a, Mag a ~ a, Base a ~ a) Source #

Basis where the domain, magnitude codomain and basis codomain are the same.

abs :: Absolute a => a -> a Source #

The absolute value of a number.

\a -> abs a * signum a ~= a
>>> abs (-1)
1

signum :: Sign a => a -> a Source #

The sign of a number.

>>> signum (-1)
-1

abs zero == zero, so any value for signum zero is ok. We choose lawful neutral:

>>> signum zero == zero
True

distance :: (Basis a, Subtractive a) => a -> a -> Mag a Source #

Distance, which combines the Subtractive notion of difference, with Basis.

distance a b >= zero
distance a a == zero
distance a b *| basis (a - b) == a - b

class (Distributive coord, Distributive (Dir coord)) => Direction coord where Source #

Convert between a "co-ordinated" or "higher-kinded" number and a direction.

ray . angle == basis
magnitude (ray x) == one

Associated Types

type Dir coord :: Type Source #

Methods

angle :: coord -> Dir coord Source #

ray :: Dir coord -> coord Source #

Instances

Instances details
TrigField a => Direction (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Dir (EuclideanPair a) Source #

TrigField a => Direction (Complex a) Source # 
Instance details

Defined in NumHask.Data.Complex

Associated Types

type Dir (Complex a) Source #

Methods

angle :: Complex a -> Dir (Complex a) Source #

ray :: Dir (Complex a) -> Complex a Source #

data Polar a Source #

Something that has a magnitude and a direction, with both expressed as the same type.

See Polar coordinate system

Constructors

Polar 

Fields

Instances

Instances details
Generic (Polar a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Rep (Polar a) :: Type -> Type #

Methods

from :: Polar a -> Rep (Polar a) x #

to :: Rep (Polar a) x -> Polar a #

Show a => Show (Polar a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Methods

showsPrec :: Int -> Polar a -> ShowS #

show :: Polar a -> String #

showList :: [Polar a] -> ShowS #

Eq a => Eq (Polar a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Methods

(==) :: Polar a -> Polar a -> Bool #

(/=) :: Polar a -> Polar a -> Bool #

(Additive a, Multiplicative a) => Basis (Polar a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag (Polar a) Source #

type Base (Polar a) Source #

Methods

magnitude :: Polar a -> Mag (Polar a) Source #

basis :: Polar a -> Base (Polar a) Source #

type Rep (Polar a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

type Rep (Polar a) = D1 ('MetaData "Polar" "NumHask.Algebra.Metric" "numhask-0.11.1.0-EApRBSOlfGg2K23zs0vJ5I" 'False) (C1 ('MetaCons "Polar" 'PrefixI 'True) (S1 ('MetaSel ('Just "radial") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Just "azimuth") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)))
type Base (Polar a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

type Base (Polar a) = a
type Mag (Polar a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

type Mag (Polar a) = a

polar :: (Dir (Base a) ~ Mag a, Basis a, Direction (Base a)) => a -> Polar (Mag a) Source #

Convert a higher-kinded number that has direction, to a Polar

coord :: (Scalar m ~ Dir m, MultiplicativeAction m, Direction m) => Polar (Scalar m) -> m Source #

Convert a Polar to a (higher-kinded) number that has a direction.

class (Eq a, Additive a) => Epsilon a where Source #

A small number, especially useful for approximate equality.

Minimal complete definition

Nothing

Methods

epsilon :: a Source #

Instances

Instances details
Epsilon Int16 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Methods

epsilon :: Int16 Source #

Epsilon Int32 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Methods

epsilon :: Int32 Source #

Epsilon Int64 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Methods

epsilon :: Int64 Source #

Epsilon Int8 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Methods

epsilon :: Int8 Source #

Epsilon Word16 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Epsilon Word32 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Epsilon Word64 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Epsilon Word8 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Methods

epsilon :: Word8 Source #

Epsilon Integer Source # 
Instance details

Defined in NumHask.Algebra.Metric

Epsilon Double Source #

1e-14

Instance details

Defined in NumHask.Algebra.Metric

Epsilon Float Source #

1e-6

Instance details

Defined in NumHask.Algebra.Metric

Methods

epsilon :: Float Source #

Epsilon Int Source #

0

Instance details

Defined in NumHask.Algebra.Metric

Methods

epsilon :: Int Source #

Epsilon Word Source # 
Instance details

Defined in NumHask.Algebra.Metric

Methods

epsilon :: Word Source #

Epsilon a => Epsilon (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Epsilon a => Epsilon (Complex a) Source # 
Instance details

Defined in NumHask.Data.Complex

Methods

epsilon :: Complex a Source #

(Ord a, EndoBased a, Integral a, Ring a, MeetSemiLattice a) => Epsilon (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

Methods

epsilon :: Ratio a Source #

nearZero :: (Epsilon a, Lattice a, Subtractive a) => a -> Bool Source #

Note that the constraint is Lattice rather than Ord allowing broader usage.

>>> nearZero (epsilon :: Double)
True
>>> nearZero (epsilon :: EuclideanPair Double)
True

aboutEqual :: (Epsilon a, Lattice a, Subtractive a) => a -> a -> Bool Source #

Approximate equality

>>> aboutEqual zero (epsilon :: Double)
True

(~=) :: Epsilon a => (Lattice a, Subtractive a) => a -> a -> Bool infixl 4 Source #

About equal operator.

>>> (1.0 + epsilon) ~= (1.0 :: Double)
True

newtype EuclideanPair a Source #

Two dimensional cartesian coordinates.

Constructors

EuclideanPair 

Fields

Instances

Instances details
Applicative EuclideanPair Source # 
Instance details

Defined in NumHask.Algebra.Metric

Functor EuclideanPair Source # 
Instance details

Defined in NumHask.Algebra.Metric

Methods

fmap :: (a -> b) -> EuclideanPair a -> EuclideanPair b #

(<$) :: a -> EuclideanPair b -> EuclideanPair a #

Generic (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Rep (EuclideanPair a) :: Type -> Type #

Show a => Show (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Eq a => Eq (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Divisive a => DivisiveAction (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Multiplicative a => MultiplicativeAction (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Scalar (EuclideanPair a) Source #

Additive a => Additive (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Subtractive a => Subtractive (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

(Ord a, TrigField a, ExpField a) => ExpField (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

(Eq (Whole a), Ring (Whole a), QuotientField a) => QuotientField (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Whole (EuclideanPair a) Source #

BoundedJoinSemiLattice a => BoundedJoinSemiLattice (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

BoundedMeetSemiLattice a => BoundedMeetSemiLattice (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

JoinSemiLattice a => JoinSemiLattice (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

MeetSemiLattice a => MeetSemiLattice (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

(ExpField a, Eq a) => Basis (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Mag (EuclideanPair a) Source #

type Base (EuclideanPair a) Source #

TrigField a => Direction (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Dir (EuclideanPair a) Source #

Epsilon a => Epsilon (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

(Subtractive a, Divisive a) => Divisive (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Multiplicative a => Multiplicative (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

type Rep (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

type Rep (EuclideanPair a) = D1 ('MetaData "EuclideanPair" "NumHask.Algebra.Metric" "numhask-0.11.1.0-EApRBSOlfGg2K23zs0vJ5I" 'True) (C1 ('MetaCons "EuclideanPair" 'PrefixI 'True) (S1 ('MetaSel ('Just "euclidPair") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (a, a))))
type Scalar (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

type Scalar (EuclideanPair a) = a
type Whole (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

type Base (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

type Dir (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

type Dir (EuclideanPair a) = a
type Mag (EuclideanPair a) Source # 
Instance details

Defined in NumHask.Algebra.Metric

type Mag (EuclideanPair a) = a