numhask-0.10.1.1: A numeric class hierarchy.
Safe HaskellSafe-Inferred
LanguageHaskell2010

NumHask.Algebra.Metric

Description

Metric classes

Synopsis

Documentation

class (Additive a, Multiplicative a) => Signed a where Source #

signum from base is not an operator name in numhask and is replaced by sign. Compare with Norm where there is a change in codomain.

\a -> abs a * sign a ~= a

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

>>> sign zero == zero
True
>>> abs (-1)
1
>>> sign (-1)
-1

Methods

sign :: a -> a Source #

abs :: a -> a Source #

Instances

Instances details
Signed Int16 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Signed Int32 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Signed Int64 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Signed Int8 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Methods

sign :: Int8 -> Int8 Source #

abs :: Int8 -> Int8 Source #

Signed Word16 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Signed Word32 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Signed Word64 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Signed Word8 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Signed Integer Source # 
Instance details

Defined in NumHask.Algebra.Metric

Signed Natural Source # 
Instance details

Defined in NumHask.Algebra.Metric

Signed Double Source # 
Instance details

Defined in NumHask.Algebra.Metric

Signed Float Source # 
Instance details

Defined in NumHask.Algebra.Metric

Signed Int Source # 
Instance details

Defined in NumHask.Algebra.Metric

Methods

sign :: Int -> Int Source #

abs :: Int -> Int Source #

Signed Word Source # 
Instance details

Defined in NumHask.Algebra.Metric

Methods

sign :: Word -> Word Source #

abs :: Word -> Word Source #

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

Defined in NumHask.Data.Rational

Methods

sign :: Ratio a -> Ratio a Source #

abs :: Ratio a -> Ratio a Source #

class (Additive a, Multiplicative b, Additive b) => Norm a b | a -> b where Source #

Norm is a slight generalisation of Signed. The class has the same shape but allows the codomain to be different to the domain.

\a -> norm a >= zero
\a -> norm zero == zero
\a -> a == norm a .* basis a
\a -> norm (basis a) == one
>>> norm (-0.5 :: Double) :: Double
0.5
>>> basis (-0.5 :: Double) :: Double
-1.0

Methods

norm :: a -> b Source #

or length, or ||v||

basis :: a -> a Source #

or direction, or v-hat

Instances

Instances details
Norm Int16 Int16 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Norm Int32 Int32 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Norm Int64 Int64 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Norm Int8 Int8 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Methods

norm :: Int8 -> Int8 Source #

basis :: Int8 -> Int8 Source #

Norm Word16 Word16 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Norm Word32 Word32 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Norm Word64 Word64 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Norm Word8 Word8 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Norm Integer Integer Source # 
Instance details

Defined in NumHask.Algebra.Metric

Norm Natural Natural Source # 
Instance details

Defined in NumHask.Algebra.Metric

Norm Double Double Source # 
Instance details

Defined in NumHask.Algebra.Metric

Norm Float Float Source # 
Instance details

Defined in NumHask.Algebra.Metric

Norm Int Int Source # 
Instance details

Defined in NumHask.Algebra.Metric

Methods

norm :: Int -> Int Source #

basis :: Int -> Int Source #

Norm Word Word Source # 
Instance details

Defined in NumHask.Algebra.Metric

Methods

norm :: Word -> Word Source #

basis :: Word -> Word Source #

ExpField a => Norm (Complex a) a Source #

A euclidean-style norm is strong convention for Complex.

Instance details

Defined in NumHask.Data.Complex

Methods

norm :: Complex a -> a Source #

basis :: Complex a -> Complex a Source #

(Ord a, Signed a, Integral a, Ring a) => Norm (Ratio a) (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

Methods

norm :: Ratio a -> Ratio a Source #

basis :: Ratio a -> Ratio a Source #

distance :: (Norm a b, Subtractive a) => a -> a -> b Source #

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

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

class (Additive coord, Multiplicative coord, Additive dir, Multiplicative dir) => Direction coord dir | coord -> dir where Source #

Convert between a "co-ordinated" or "higher-kinded" number and representations of an angle. Typically thought of as polar co-ordinate conversion.

See Polar coordinate system

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

Methods

angle :: coord -> dir Source #

ray :: dir -> coord Source #

Instances

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

Defined in NumHask.Data.Complex

Methods

angle :: Complex a -> a Source #

ray :: a -> Complex a Source #

data Polar mag dir Source #

Something that has a magnitude and a direction.

Constructors

Polar 

Fields

Instances

Instances details
Generic (Polar mag dir) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Associated Types

type Rep (Polar mag dir) :: Type -> Type #

Methods

from :: Polar mag dir -> Rep (Polar mag dir) x #

to :: Rep (Polar mag dir) x -> Polar mag dir #

(Show mag, Show dir) => Show (Polar mag dir) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Methods

showsPrec :: Int -> Polar mag dir -> ShowS #

show :: Polar mag dir -> String #

showList :: [Polar mag dir] -> ShowS #

(Eq mag, Eq dir) => Eq (Polar mag dir) Source # 
Instance details

Defined in NumHask.Algebra.Metric

Methods

(==) :: Polar mag dir -> Polar mag dir -> Bool #

(/=) :: Polar mag dir -> Polar mag dir -> Bool #

type Rep (Polar mag dir) Source # 
Instance details

Defined in NumHask.Algebra.Metric

type Rep (Polar mag dir) = D1 ('MetaData "Polar" "NumHask.Algebra.Metric" "numhask-0.10.1.1-5se1IUyAn3UALQnNUDpTp7" 'False) (C1 ('MetaCons "Polar" 'PrefixI 'True) (S1 ('MetaSel ('Just "magnitude") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 mag) :*: S1 ('MetaSel ('Just "direction") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 dir)))

polar :: (Norm coord mag, Direction coord dir) => coord -> Polar mag dir Source #

Convert from a number to a Polar.

coord :: (MultiplicativeAction coord mag, Direction coord dir) => Polar mag dir -> coord Source #

Convert from a Polar to a (coordinated aka higher-kinded) number.

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 #

nearZero :: a -> Bool Source #

are we near enough?

>>> nearZero (epsilon :: Double)
True

default nearZero :: (Ord a, Subtractive a) => a -> Bool Source #

aboutEqual :: a -> a -> Bool Source #

Approximate equality

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

default aboutEqual :: Subtractive a => a -> a -> Bool Source #

Instances

Instances details
Epsilon Int16 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Epsilon Int32 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Epsilon Int64 Source # 
Instance details

Defined in NumHask.Algebra.Metric

Epsilon Int8 Source # 
Instance details

Defined in NumHask.Algebra.Metric

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

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

Epsilon Int Source #

0

Instance details

Defined in NumHask.Algebra.Metric

Epsilon Word Source # 
Instance details

Defined in NumHask.Algebra.Metric

(Ord a, Signed a, Epsilon a, Subtractive a) => Epsilon (Complex a) Source # 
Instance details

Defined in NumHask.Data.Complex

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

Defined in NumHask.Data.Rational

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

About equal operator.

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