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

Safe HaskellSafe-Inferred
LanguageHaskell98

Algebra.Ring

Contents

Synopsis

Class

class C a => C a where Source

Ring encapsulates the mathematical structure of a (not necessarily commutative) ring, with the laws

  a * (b * c) === (a * b) * c
      one * a === a
      a * one === a
  a * (b + c) === a * b + a * c

Typical examples include integers, polynomials, matrices, and quaternions.

Minimal definition: *, (one or fromInteger)

Minimal complete definition

(*), (one | fromInteger)

Methods

(*) :: a -> a -> a infixl 7 Source

one :: a Source

fromInteger :: Integer -> a Source

(^) :: a -> Integer -> a infixr 8 Source

The exponent has fixed type Integer in order to avoid an arbitrarily limitted range of exponents, but to reduce the need for the compiler to guess the type (default type). In practice the exponent is most oftenly fixed, and is most oftenly 2. Fixed exponents can be optimized away and thus the expensive computation of Integers doesn't matter. The previous solution used a C constrained type and the exponent was converted to Integer before computation. So the current solution is not less efficient.

A variant of ^ with more flexibility is provided by ringPower.

Instances

C Double 
C Float 
C Int 
C Int8 
C Int16 
C Int32 
C Int64 
C Integer 
C Word 
C Word8 
C Word16 
C Word32 
C Word64 
C T 
C T 
C T 
C T 
Integral a => C (Ratio a) 
RealFloat a => C (Complex a) 
(Ord a, C a) => C (T a) 
C a => C (T a) 
C a => C (T a) 
(C a, C a) => C (T a) 
C a => C (T a) 
C a => C (T a) 
C a => C (T a) 
(Eq a, C a) => C (T a) 
(Eq a, C a) => C (T a) 
Num a => C (T a) 
C a => C (T a) 
C a => C (T a) 
(C a, C a) => C (T a) 
C a => C (T a) 
C a => C (T a) 
C a => C (T a) 
C a => C (T a) 
C a => C (T a) 
(C a, C a) => C (T a) 
(Ord a, C a, C b) => C (T a b) 
(IsScalar u, C a) => C (T u a) 
C v => C (T a v) 
(Ord i, C a) => C (T i a) 
C v => C (T a v) 

sqr :: C a => a -> a Source

Complex functions

product :: C a => [a] -> a Source

product1 :: C a => [a] -> a Source

scalarProduct :: C a => [a] -> [a] -> a Source

Properties

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

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

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

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

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

propPowerDistributive :: (Eq a, C a) => Integer -> a -> a -> Property Source

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

Commutativity need not be satisfied by all instances of C.