numhask-0.2.2.0: numeric classes

Safe HaskellNone
LanguageHaskell2010

NumHask.Algebra

Contents

Description

The basic algebraic class structure of a number.

import NumHask.Algebra
import Prelude hiding (Integral(..), (*), (**), (+), (-), (/), (^), (^^), abs, acos, acosh, asin, asinh, atan, atan2, atanh, ceiling, cos, cosh, exp, floor, fromInteger, fromIntegral, log, logBase, negate, pi, product, recip, round, sin, sinh, sqrt, sum, tan, tanh, toInteger, fromRational)

Synopsis

Mapping from Num

Num is a very old part of haskell, and a lot of different numeric concepts are tossed in there. The closest analogue in numhask is the Ring class, which combines the classical +, - and *, together with the distribution laws.

No attempt is made, however, to reconstruct the particular combination of laws and classes that represent the old Num. A rough mapping of Num to numhask classes follows:

-- | Basic numeric class.
class  Num a  where
   {-# MINIMAL (+), (*), abs, signum, fromInteger, (negate | (-)) #-}

   (+), (-), (*)       :: a -> a -> a
   -- | Unary negation.
   negate              :: a -> a

+ is a function of the Additive class, - is a function of the AdditiveGroup class, and * is a function of the Multiplicative class. negate is specifically in the AdditiveInvertible class. There are many useful constructions between negate and (-), involving cancellative properties.

   -- | Absolute value.
   abs                 :: a -> a
   -- | Sign of a number.
   -- The functions 'abs' and 'signum' should satisfy the law:
   --
   -- > abs x * signum x == x
   --
   -- For real numbers, the 'signum' is either @-1@ (negative), @0@ (zero)
   -- or @1@ (positive).
   signum              :: a -> a

abs is a function in the Signed class. The concept of an absolute value of a number can include situations where the domain and codomain are different, and size as a function in the Normed class is supplied for these cases.

sign replaces signum, because signum is a heinous name.

   -- | Conversion from an 'Integer'.
   -- An integer literal represents the application of the function
   -- 'fromInteger' to the appropriate value of type 'Integer',
   -- so such literals have type @('Num' a) => a@.
   fromInteger         :: Integer -> a

fromInteger is given its own class FromInteger

data Complex a :: * -> * #

Complex numbers are an algebraic type.

For a complex number z, abs z is a number with the magnitude of z, but oriented in the positive real direction, whereas signum z has the phase of z, but unit magnitude.

The Foldable and Traversable instances traverse the real part first.

Constructors

!a :+ !a infix 6

forms a complex number from its real and imaginary rectangular components.

Instances

Monad Complex

Since: 4.9.0.0

Methods

(>>=) :: Complex a -> (a -> Complex b) -> Complex b #

(>>) :: Complex a -> Complex b -> Complex b #

return :: a -> Complex a #

fail :: String -> Complex a #

Functor Complex 

Methods

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

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

Applicative Complex

Since: 4.9.0.0

Methods

pure :: a -> Complex a #

(<*>) :: Complex (a -> b) -> Complex a -> Complex b #

liftA2 :: (a -> b -> c) -> Complex a -> Complex b -> Complex c #

(*>) :: Complex a -> Complex b -> Complex b #

(<*) :: Complex a -> Complex b -> Complex a #

Foldable Complex 

Methods

fold :: Monoid m => Complex m -> m #

foldMap :: Monoid m => (a -> m) -> Complex a -> m #

foldr :: (a -> b -> b) -> b -> Complex a -> b #

foldr' :: (a -> b -> b) -> b -> Complex a -> b #

foldl :: (b -> a -> b) -> b -> Complex a -> b #

foldl' :: (b -> a -> b) -> b -> Complex a -> b #

foldr1 :: (a -> a -> a) -> Complex a -> a #

foldl1 :: (a -> a -> a) -> Complex a -> a #

toList :: Complex a -> [a] #

null :: Complex a -> Bool #

length :: Complex a -> Int #

elem :: Eq a => a -> Complex a -> Bool #

maximum :: Ord a => Complex a -> a #

minimum :: Ord a => Complex a -> a #

sum :: Num a => Complex a -> a #

product :: Num a => Complex a -> a #

Traversable Complex 

Methods

traverse :: Applicative f => (a -> f b) -> Complex a -> f (Complex b) #

sequenceA :: Applicative f => Complex (f a) -> f (Complex a) #

mapM :: Monad m => (a -> m b) -> Complex a -> m (Complex b) #

sequence :: Monad m => Complex (m a) -> m (Complex a) #

Eq a => Eq (Complex a) 

Methods

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

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

RealFloat a => Floating (Complex a)

Since: 2.1

Methods

pi :: Complex a #

exp :: Complex a -> Complex a #

log :: Complex a -> Complex a #

sqrt :: Complex a -> Complex a #

(**) :: Complex a -> Complex a -> Complex a #

logBase :: Complex a -> Complex a -> Complex a #

sin :: Complex a -> Complex a #

cos :: Complex a -> Complex a #

tan :: Complex a -> Complex a #

asin :: Complex a -> Complex a #

acos :: Complex a -> Complex a #

atan :: Complex a -> Complex a #

sinh :: Complex a -> Complex a #

cosh :: Complex a -> Complex a #

tanh :: Complex a -> Complex a #

asinh :: Complex a -> Complex a #

acosh :: Complex a -> Complex a #

atanh :: Complex a -> Complex a #

log1p :: Complex a -> Complex a #

expm1 :: Complex a -> Complex a #

log1pexp :: Complex a -> Complex a #

log1mexp :: Complex a -> Complex a #

RealFloat a => Fractional (Complex a)

Since: 2.1

Methods

(/) :: Complex a -> Complex a -> Complex a #

recip :: Complex a -> Complex a #

fromRational :: Rational -> Complex a #

Data a => Data (Complex a) 

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Complex a -> c (Complex a) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Complex a) #

toConstr :: Complex a -> Constr #

dataTypeOf :: Complex a -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Complex a)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Complex a)) #

gmapT :: (forall b. Data b => b -> b) -> Complex a -> Complex a #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Complex a -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Complex a -> r #

gmapQ :: (forall d. Data d => d -> u) -> Complex a -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Complex a -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Complex a -> m (Complex a) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Complex a -> m (Complex a) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Complex a -> m (Complex a) #

RealFloat a => Num (Complex a)

Since: 2.1

Methods

(+) :: Complex a -> Complex a -> Complex a #

(-) :: Complex a -> Complex a -> Complex a #

(*) :: Complex a -> Complex a -> Complex a #

negate :: Complex a -> Complex a #

abs :: Complex a -> Complex a #

signum :: Complex a -> Complex a #

fromInteger :: Integer -> Complex a #

Read a => Read (Complex a) 
Show a => Show (Complex a) 

Methods

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

show :: Complex a -> String #

showList :: [Complex a] -> ShowS #

Generic (Complex a) 

Associated Types

type Rep (Complex a) :: * -> * #

Methods

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

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

Storable a => Storable (Complex a)

Since: 4.8.0.0

Methods

sizeOf :: Complex a -> Int #

alignment :: Complex a -> Int #

peekElemOff :: Ptr (Complex a) -> Int -> IO (Complex a) #

pokeElemOff :: Ptr (Complex a) -> Int -> Complex a -> IO () #

peekByteOff :: Ptr b -> Int -> IO (Complex a) #

pokeByteOff :: Ptr b -> Int -> Complex a -> IO () #

peek :: Ptr (Complex a) -> IO (Complex a) #

poke :: Ptr (Complex a) -> Complex a -> IO () #

AdditiveGroup a => AdditiveGroup (Complex a) Source # 

Methods

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

Additive a => Additive (Complex a) Source # 

Methods

(+) :: Complex a -> Complex a -> Complex a Source #

AdditiveInvertible a => AdditiveInvertible (Complex a) Source # 

Methods

negate :: Complex a -> Complex a Source #

AdditiveCommutative a => AdditiveCommutative (Complex a) Source # 
AdditiveAssociative a => AdditiveAssociative (Complex a) Source # 
AdditiveUnital a => AdditiveUnital (Complex a) Source # 

Methods

zero :: Complex a Source #

AdditiveMagma a => AdditiveMagma (Complex a) Source # 

Methods

plus :: Complex a -> Complex a -> Complex a Source #

(AdditiveGroup a, MultiplicativeGroup a) => MultiplicativeGroup (Complex a) Source # 

Methods

(/) :: Complex a -> Complex a -> Complex a Source #

(AdditiveGroup a, Multiplicative a) => Multiplicative (Complex a) Source # 

Methods

(*) :: Complex a -> Complex a -> Complex a Source #

(AdditiveGroup a, MultiplicativeInvertible a) => MultiplicativeInvertible (Complex a) Source # 

Methods

recip :: Complex a -> Complex a Source #

(AdditiveGroup a, MultiplicativeCommutative a) => MultiplicativeCommutative (Complex a) Source # 
(AdditiveGroup a, MultiplicativeAssociative a) => MultiplicativeAssociative (Complex a) Source # 
(AdditiveUnital a, AdditiveGroup a, MultiplicativeUnital a) => MultiplicativeUnital (Complex a) Source # 

Methods

one :: Complex a Source #

(MultiplicativeMagma a, AdditiveGroup a) => MultiplicativeMagma (Complex a) Source # 

Methods

times :: Complex a -> Complex a -> Complex a Source #

(AdditiveGroup a, Distribution a) => Distribution (Complex a) Source # 
Ring a => InvolutiveRing (Complex a) Source # 

Methods

adj :: Complex a -> Complex a Source #

CRing a => CRing (Complex a) Source # 
Ring a => Ring (Complex a) Source # 
(AdditiveGroup a, Semiring a) => Semiring (Complex a) Source # 
(AdditiveGroup a, UpperBoundedField a) => UpperBoundedField (Complex a) Source #

todo: work out boundings for complex as it stands now, complex is different eg

one / (zero :: Complex Float) == nan
(Ord a, TrigField a, ExpField a) => ExpField (Complex a) Source #

todo: bottom is here somewhere???

Field a => Field (Complex a) Source # 
(Semifield a, AdditiveGroup a) => Semifield (Complex a) Source # 
Epsilon a => Epsilon (Complex a) Source # 
Generic1 * Complex 

Associated Types

type Rep1 Complex (f :: Complex -> *) :: k -> * #

Methods

from1 :: f a -> Rep1 Complex f a #

to1 :: Rep1 Complex f a -> f a #

(Multiplicative a, ExpField a, Normed a a) => Metric (Complex a) a Source # 

Methods

distanceL1 :: Complex a -> Complex a -> a Source #

distanceL2 :: Complex a -> Complex a -> a Source #

distanceLp :: a -> Complex a -> Complex a -> a Source #

(Multiplicative a, ExpField a, Normed a a) => Normed (Complex a) a Source # 

Methods

normL1 :: Complex a -> a Source #

normL2 :: Complex a -> a Source #

normLp :: a -> Complex a -> a Source #

type Rep (Complex a) 
type Rep1 * Complex