numeric-prelude-0.4.3.2: An experimental alternative hierarchy of numeric type classes

Safe HaskellNone
LanguageHaskell98

Algebra.Absolute

Synopsis

Documentation

class C a => C a where Source #

This is the type class of a ring with a notion of an absolute value, satisfying the laws

                       a * b === b * a
  a /= 0  =>  abs (signum a) === 1
            abs a * signum a === a

Minimal definition: abs, signum.

If the type is in the Ord class we expect abs = absOrd and signum = signumOrd and we expect the following laws to hold:

     a + (max b c) === max (a+b) (a+c)
  negate (max b c) === min (negate b) (negate c)
     a * (max b c) === max (a*b) (a*c) where a >= 0
          absOrd a === max a (-a)

If the type is ZeroTestable, then it should hold

 isZero a  ===  signum a == signum (negate a)

We do not require Ord as superclass since we also want to have Number.Complex as instance. We also do not require ZeroTestable as superclass, because we like to have expressions of foreign languages to be instances (cf. embedded domain specific language approach, EDSL), as well as function types.

abs for complex numbers alone may have an inappropriate type, because it does not reflect that the absolute value is a real number. You might prefer magnitude. This type class is intended for unifying algorithms that work for both real and complex numbers. Note the similarity to Algebra.Units: abs plays the role of stdAssociate and signum plays the role of stdUnit.

Actually, since abs can be defined using max and negate we could relax the superclasses to Additive and Ord if his class would only contain signum.

Methods

abs :: a -> a Source #

signum :: a -> a Source #

Instances
C Double Source # 
Instance details

Defined in Algebra.Absolute

C Float Source # 
Instance details

Defined in Algebra.Absolute

C Int Source # 
Instance details

Defined in Algebra.Absolute

Methods

abs :: Int -> Int Source #

signum :: Int -> Int Source #

C Int8 Source # 
Instance details

Defined in Algebra.Absolute

Methods

abs :: Int8 -> Int8 Source #

signum :: Int8 -> Int8 Source #

C Int16 Source # 
Instance details

Defined in Algebra.Absolute

C Int32 Source # 
Instance details

Defined in Algebra.Absolute

C Int64 Source # 
Instance details

Defined in Algebra.Absolute

C Integer Source # 
Instance details

Defined in Algebra.Absolute

C Word Source # 
Instance details

Defined in Algebra.Absolute

Methods

abs :: Word -> Word Source #

signum :: Word -> Word Source #

C Word8 Source # 
Instance details

Defined in Algebra.Absolute

C Word16 Source # 
Instance details

Defined in Algebra.Absolute

C Word32 Source # 
Instance details

Defined in Algebra.Absolute

C Word64 Source # 
Instance details

Defined in Algebra.Absolute

C T Source # 
Instance details

Defined in Number.Peano

Methods

abs :: T -> T Source #

signum :: T -> T Source #

C T Source # 
Instance details

Defined in Number.FixedPoint.Check

Methods

abs :: T -> T Source #

signum :: T -> T Source #

C T Source # 
Instance details

Defined in Number.Positional.Check

Methods

abs :: T -> T Source #

signum :: T -> T Source #

(C a, Ord a, C a) => C (T a) Source # 
Instance details

Defined in Number.NonNegative

Methods

abs :: T a -> T a Source #

signum :: T a -> T a Source #

(C a, C a) => C (T a) Source # 
Instance details

Defined in Number.Ratio

Methods

abs :: T a -> T a Source #

signum :: T a -> T a Source #

Num a => C (T a) Source # 
Instance details

Defined in MathObj.Wrapper.Haskell98

Methods

abs :: T a -> T a Source #

signum :: T a -> T a Source #

(C a, C a, C a) => C (T a) Source # 
Instance details

Defined in Number.NonNegativeChunky

Methods

abs :: T a -> T a Source #

signum :: T a -> T a Source #

(C a, C a, C a) => C (T a) Source # 
Instance details

Defined in Number.Complex

Methods

abs :: T a -> T a Source #

signum :: T a -> T a Source #

C a => C (T a) Source # 
Instance details

Defined in MathObj.Wrapper.NumericPrelude

Methods

abs :: T a -> T a Source #

signum :: T a -> T a Source #

C v => C (T a v) Source # 
Instance details

Defined in Number.OccasionallyScalarExpression

Methods

abs :: T a v -> T a v Source #

signum :: T a v -> T a v Source #

(Ord i, C a) => C (T i a) Source # 
Instance details

Defined in Number.Physical

Methods

abs :: T i a -> T i a Source #

signum :: T i a -> T i a Source #

C v => C (T a v) Source # 
Instance details

Defined in Number.SI

Methods

abs :: T a v -> T a v Source #

signum :: T a v -> T a v Source #

absOrd :: (C a, Ord a) => a -> a Source #

signumOrd :: (C a, Ord a) => a -> a Source #