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

Safe HaskellSafe
LanguageHaskell98

Algebra.Additive

Contents

Synopsis

Class

class C a Source #

Additive a encapsulates the notion of a commutative group, specified by the following laws:

          a + b === b + a
    (a + b) + c === a + (b + c)
       zero + a === a
   a + negate a === 0

Typical examples include integers, dollars, and vectors.

Minimal definition: +, zero, and (negate or '(-)')

Minimal complete definition

zero, (+), ((-) | negate)

Instances
C Double Source # 
Instance details

Defined in Algebra.Additive

C Float Source # 
Instance details

Defined in Algebra.Additive

C Int Source # 
Instance details

Defined in Algebra.Additive

Methods

zero :: Int Source #

(+) :: Int -> Int -> Int Source #

(-) :: Int -> Int -> Int Source #

negate :: Int -> Int Source #

C Int8 Source # 
Instance details

Defined in Algebra.Additive

C Int16 Source # 
Instance details

Defined in Algebra.Additive

C Int32 Source # 
Instance details

Defined in Algebra.Additive

C Int64 Source # 
Instance details

Defined in Algebra.Additive

C Integer Source # 
Instance details

Defined in Algebra.Additive

C Word Source # 
Instance details

Defined in Algebra.Additive

C Word8 Source # 
Instance details

Defined in Algebra.Additive

C Word16 Source # 
Instance details

Defined in Algebra.Additive

C Word32 Source # 
Instance details

Defined in Algebra.Additive

C Word64 Source # 
Instance details

Defined in Algebra.Additive

C T Source # 
Instance details

Defined in Number.Peano

Methods

zero :: T Source #

(+) :: T -> T -> T Source #

(-) :: T -> T -> T Source #

negate :: T -> T Source #

C T Source # 
Instance details

Defined in Number.GaloisField2p32m5

Methods

zero :: T Source #

(+) :: T -> T -> T Source #

(-) :: T -> T -> T Source #

negate :: T -> T Source #

C T Source # 
Instance details

Defined in Number.FixedPoint.Check

Methods

zero :: T Source #

(+) :: T -> T -> T Source #

(-) :: T -> T -> T Source #

negate :: T -> T Source #

C T Source # 
Instance details

Defined in Number.Positional.Check

Methods

zero :: T Source #

(+) :: T -> T -> T Source #

(-) :: T -> T -> T Source #

negate :: T -> T Source #

C v => C [v] Source #

The Additive instantiations treat lists as prefixes of infinite lists with zero filled tail. This interpretation is not always appropriate. The end of a list may just mean: End of available data. In this case the shortening zip semantics would be more appropriate.

Instance details

Defined in Algebra.Additive

Methods

zero :: [v] Source #

(+) :: [v] -> [v] -> [v] Source #

(-) :: [v] -> [v] -> [v] Source #

negate :: [v] -> [v] Source #

Integral a => C (Ratio a) Source # 
Instance details

Defined in Algebra.Additive

Methods

zero :: Ratio a Source #

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

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

negate :: Ratio a -> Ratio a Source #

RealFloat a => C (Complex a) Source # 
Instance details

Defined in Algebra.Additive

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

Defined in Number.NonNegative

Methods

zero :: T a Source #

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

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

negate :: T a -> T a Source #

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

Defined in Number.Ratio

Methods

zero :: T a Source #

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

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

negate :: T a -> T a Source #

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

Defined in MathObj.Wrapper.Haskell98

Methods

zero :: T a Source #

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

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

negate :: T a -> T a Source #

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

Defined in Number.ResidueClass.Maybe

Methods

zero :: T a Source #

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

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

negate :: T a -> T a Source #

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

Defined in Number.ResidueClass.Func

Methods

zero :: T a Source #

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

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

negate :: T a -> T a Source #

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

Defined in Number.ResidueClass.Check

Methods

zero :: T a Source #

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

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

negate :: T a -> T a Source #

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

Defined in Number.PartiallyTranscendental

Methods

zero :: T a Source #

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

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

negate :: T a -> T a Source #

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

Defined in Number.NonNegativeChunky

Methods

zero :: T a Source #

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

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

negate :: T a -> T a Source #

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

Defined in MathObj.PowerSeries

Methods

zero :: T a Source #

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

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

negate :: T a -> T a Source #

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

Defined in MathObj.PowerSeries2

Methods

zero :: T a Source #

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

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

negate :: T a -> T a Source #

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

Defined in MathObj.Polynomial

Methods

zero :: T a Source #

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

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

negate :: T a -> T a Source #

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

Defined in MathObj.PowerSum

Methods

zero :: T a Source #

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

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

negate :: T a -> T a Source #

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

Defined in MathObj.RootSet

Methods

zero :: T a Source #

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

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

negate :: T a -> T a Source #

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

Defined in MathObj.PartialFraction

Methods

zero :: T a Source #

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

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

negate :: T a -> T a Source #

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

Defined in MathObj.Matrix

Methods

zero :: T a Source #

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

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

negate :: T a -> T a Source #

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

Defined in Number.Complex

Methods

zero :: T a Source #

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

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

negate :: T a -> T a Source #

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

Defined in Number.Quaternion

Methods

zero :: T a Source #

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

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

negate :: T a -> T a Source #

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

Defined in MathObj.LaurentPolynomial

Methods

zero :: T a Source #

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

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

negate :: T a -> T a Source #

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

Defined in MathObj.Wrapper.NumericPrelude

Methods

zero :: T a Source #

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

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

negate :: T a -> T a Source #

C v => C (b -> v) Source # 
Instance details

Defined in Algebra.Additive

Methods

zero :: b -> v Source #

(+) :: (b -> v) -> (b -> v) -> b -> v Source #

(-) :: (b -> v) -> (b -> v) -> b -> v Source #

negate :: (b -> v) -> b -> v Source #

(C v0, C v1) => C (v0, v1) Source # 
Instance details

Defined in Algebra.Additive

Methods

zero :: (v0, v1) Source #

(+) :: (v0, v1) -> (v0, v1) -> (v0, v1) Source #

(-) :: (v0, v1) -> (v0, v1) -> (v0, v1) Source #

negate :: (v0, v1) -> (v0, v1) Source #

(Ord i, Eq v, C v) => C (Map i v) Source # 
Instance details

Defined in MathObj.DiscreteMap

Methods

zero :: Map i v Source #

(+) :: Map i v -> Map i v -> Map i v Source #

(-) :: Map i v -> Map i v -> Map i v Source #

negate :: Map i v -> Map i v Source #

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

Defined in MathObj.Algebra

Methods

zero :: T a b Source #

(+) :: T a b -> T a b -> T a b Source #

(-) :: T a b -> T a b -> T a b Source #

negate :: T a b -> T a b Source #

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

Defined in Number.OccasionallyScalarExpression

Methods

zero :: T a v Source #

(+) :: T a v -> T a v -> T a v Source #

(-) :: T a v -> T a v -> T a v Source #

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

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

Defined in Number.DimensionTerm

Methods

zero :: T u a Source #

(+) :: T u a -> T u a -> T u a Source #

(-) :: T u a -> T u a -> T u a Source #

negate :: T u a -> T u a Source #

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

Defined in Number.Physical

Methods

zero :: T i a Source #

(+) :: T i a -> T i a -> T i a Source #

(-) :: T i a -> T i a -> T i a Source #

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

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

Defined in Number.SI

Methods

zero :: T a v Source #

(+) :: T a v -> T a v -> T a v Source #

(-) :: T a v -> T a v -> T a v Source #

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

(C v0, C v1, C v2) => C (v0, v1, v2) Source # 
Instance details

Defined in Algebra.Additive

Methods

zero :: (v0, v1, v2) Source #

(+) :: (v0, v1, v2) -> (v0, v1, v2) -> (v0, v1, v2) Source #

(-) :: (v0, v1, v2) -> (v0, v1, v2) -> (v0, v1, v2) Source #

negate :: (v0, v1, v2) -> (v0, v1, v2) Source #

zero :: C a => a Source #

zero element of the vector space

(+), (-) :: C a => a -> a -> a infixl 6 +, - Source #

add and subtract elements

(+), (-) :: C a => a -> a -> a infixl 6 -, + Source #

add and subtract elements

negate :: C a => a -> a Source #

inverse with respect to +

subtract :: C a => a -> a -> a Source #

subtract is (-) with swapped operand order. This is the operand order which will be needed in most cases of partial application.

Complex functions

sum :: C a => [a] -> a Source #

Sum up all elements of a list. An empty list yields zero.

This function is inappropriate for number types like Peano. Maybe we should make sum a method of Additive. This would also make lengthLeft and lengthRight superfluous.

sum1 :: C a => [a] -> a Source #

Sum up all elements of a non-empty list. This avoids including a zero which is useful for types where no universal zero is available. ToDo: Should have NonEmpty type.

sumNestedAssociative :: C a => [a] -> a Source #

Sum the operands in an order, such that the dependencies are minimized. Does this have a measurably effect on speed?

Requires associativity.

sumNestedCommutative :: C a => [a] -> a Source #

Instance definition helpers

elementAdd :: C x => (v -> x) -> T (v, v) x Source #

Instead of baking the add operation into the element function, we could use higher rank types and pass a generic uncurry (+) to the run function. We do not do so in order to stay Haskell 98 at least for parts of NumericPrelude.

elementSub :: C x => (v -> x) -> T (v, v) x Source #

elementNeg :: C x => (v -> x) -> T v x Source #

(<*>.+) :: C x => T (v, v) (x -> a) -> (v -> x) -> T (v, v) a infixl 4 Source #

addPair :: (Additive.C a, Additive.C b) => (a,b) -> (a,b) -> (a,b)
addPair = Elem.run2 $ Elem.with (,) <*>.+  fst <*>.+  snd

(<*>.-) :: C x => T (v, v) (x -> a) -> (v -> x) -> T (v, v) a infixl 4 Source #

(<*>.-$) :: C x => T v (x -> a) -> (v -> x) -> T v a infixl 4 Source #

Instances for atomic types

propAssociative :: (Eq a, C a) => a -> a -> a -> Bool Source #

propCommutative :: (Eq a, C a) => a -> a -> Bool Source #

propIdentity :: (Eq a, C a) => a -> Bool Source #

propInverse :: (Eq a, C a) => a -> Bool Source #