-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | The core of a numeric prelude, taken from numhask -- -- The core of a numeric prelude, taken from numhask, because I thought -- it would be useful to have this as a separate library. @package plankton @version 0.0.0.1 -- | Bootstrapping the number system. -- -- This heirarchy is repeated for the Additive and Multiplicative -- structures, in order to achieve class separation, so these classes are -- not used in the main numerical classes. module Plankton.Magma -- | A Magma is a tuple (T,⊕) consisting of -- --
-- ∀ a, b ∈ T: a ⊕ b ∈ T ---- -- These laws are true by construction in haskell: the type signature of -- magma and the above mathematical laws are synonyms. class Magma a (⊕) :: Magma a => a -> a -> a -- | A Unital Magma -- --
-- unit ⊕ a = a -- a ⊕ unit = a --class Magma a => Unital a unit :: Unital a => a -- | An Associative Magma -- --
-- (a ⊕ b) ⊕ c = a ⊕ (b ⊕ c) --class Magma a => Associative a -- | A Commutative Magma -- --
-- a ⊕ b = b ⊕ a --class Magma a => Commutative a -- | An Invertible Magma -- --
-- ∀ a ∈ T: inv a ∈ T ---- -- law is true by construction in Haskell class Magma a => Invertible a inv :: Invertible a => a -> a -- | An Idempotent Magma -- --
-- a ⊕ a = a --class Magma a => Idempotent a -- | A Monoidal Magma is associative and unital. class (Associative a, Unital a) => Monoidal a -- | A CMonoidal Magma is commutative, associative and unital. class (Commutative a, Associative a, Unital a) => CMonoidal a -- | A Loop is unital and invertible class (Unital a, Invertible a) => Loop a -- | A Group is associative, unital and invertible class (Associative a, Unital a, Invertible a) => Group a -- | see http://chris-taylor.github.io/blog/2013/02/25/xor-trick/ groupSwap :: (Group a) => (a, a) -> (a, a) -- | An Abelian Group is associative, unital, invertible and commutative class (Associative a, Unital a, Invertible a, Commutative a) => Abelian a -- | A magma heirarchy for addition. The basic magma structure is repeated -- and prefixed with 'Additive-'. module Plankton.Additive -- | plus is used as the operator for the additive magma to -- distinguish from + which, by convention, implies commutativity -- --
-- ∀ a,b ∈ A: a `plus` b ∈ A ---- -- law is true by construction in Haskell class AdditiveMagma a plus :: AdditiveMagma a => a -> a -> a -- | Unital magma for addition. -- --
-- zero `plus` a == a -- a `plus` zero == a --class AdditiveMagma a => AdditiveUnital a zero :: AdditiveUnital a => a -- | Associative magma for addition. -- --
-- (a `plus` b) `plus` c == a `plus` (b `plus` c) --class AdditiveMagma a => AdditiveAssociative a -- | Commutative magma for addition. -- --
-- a `plus` b == b `plus` a --class AdditiveMagma a => AdditiveCommutative a -- | Invertible magma for addition. -- --
-- ∀ a ∈ A: negate a ∈ A ---- -- law is true by construction in Haskell class AdditiveMagma a => AdditiveInvertible a negate :: AdditiveInvertible a => a -> a -- | Idempotent magma for addition. -- --
-- a `plus` a == a --class AdditiveMagma a => AdditiveIdempotent a -- | sum definition avoiding a clash with the Sum monoid in base sum :: (Additive a, Foldable f) => f a -> a -- | Additive is commutative, unital and associative under addition -- --
-- zero + a == a -- a + zero == a -- (a + b) + c == a + (b + c) -- a + b == b + a --class (AdditiveCommutative a, AdditiveUnital a, AdditiveAssociative a) => Additive a where a + b = plus a b (+) :: Additive a => a -> a -> a -- | Non-commutative right minus -- --
-- a `plus` negate a = zero --class (AdditiveUnital a, AdditiveAssociative a, AdditiveInvertible a) => AdditiveRightCancellative a where (-~) a b = a `plus` negate b (-~) :: AdditiveRightCancellative a => a -> a -> a -- | Non-commutative left minus -- --
-- negate a `plus` a = zero --class (AdditiveUnital a, AdditiveAssociative a, AdditiveInvertible a) => AdditiveLeftCancellative a where (~-) a b = negate b `plus` a (~-) :: AdditiveLeftCancellative a => a -> a -> a -- | Minus (-) is reserved for where both the left and right -- cancellative laws hold. This then implies that the AdditiveGroup is -- also Abelian. -- -- Syntactic unary negation - substituting "negate a" for "-a" in code - -- is hard-coded in the language to assume a Num instance. So, for -- example, using ''-a = zero - a' for the second rule below doesn't -- work. -- --
-- a - a = zero -- negate a = zero - a -- negate a + a = zero -- a + negate a = zero --class (Additive a, AdditiveInvertible a) => AdditiveGroup a where (-) a b = a `plus` negate b (-) :: AdditiveGroup a => a -> a -> a instance Plankton.Additive.AdditiveMagma GHC.Types.Double instance Plankton.Additive.AdditiveMagma GHC.Types.Float instance Plankton.Additive.AdditiveMagma GHC.Types.Int instance Plankton.Additive.AdditiveMagma GHC.Integer.Type.Integer instance Plankton.Additive.AdditiveMagma GHC.Types.Bool instance Plankton.Additive.AdditiveMagma a => Plankton.Additive.AdditiveMagma (Data.Complex.Complex a) instance Plankton.Additive.AdditiveUnital GHC.Types.Double instance Plankton.Additive.AdditiveUnital GHC.Types.Float instance Plankton.Additive.AdditiveUnital GHC.Types.Int instance Plankton.Additive.AdditiveUnital GHC.Integer.Type.Integer instance Plankton.Additive.AdditiveUnital GHC.Types.Bool instance Plankton.Additive.AdditiveUnital a => Plankton.Additive.AdditiveUnital (Data.Complex.Complex a) instance Plankton.Additive.AdditiveAssociative GHC.Types.Double instance Plankton.Additive.AdditiveAssociative GHC.Types.Float instance Plankton.Additive.AdditiveAssociative GHC.Types.Int instance Plankton.Additive.AdditiveAssociative GHC.Integer.Type.Integer instance Plankton.Additive.AdditiveAssociative GHC.Types.Bool instance Plankton.Additive.AdditiveAssociative a => Plankton.Additive.AdditiveAssociative (Data.Complex.Complex a) instance Plankton.Additive.AdditiveCommutative GHC.Types.Double instance Plankton.Additive.AdditiveCommutative GHC.Types.Float instance Plankton.Additive.AdditiveCommutative GHC.Types.Int instance Plankton.Additive.AdditiveCommutative GHC.Integer.Type.Integer instance Plankton.Additive.AdditiveCommutative GHC.Types.Bool instance Plankton.Additive.AdditiveCommutative a => Plankton.Additive.AdditiveCommutative (Data.Complex.Complex a) instance Plankton.Additive.AdditiveInvertible GHC.Types.Double instance Plankton.Additive.AdditiveInvertible GHC.Types.Float instance Plankton.Additive.AdditiveInvertible GHC.Types.Int instance Plankton.Additive.AdditiveInvertible GHC.Integer.Type.Integer instance Plankton.Additive.AdditiveInvertible GHC.Types.Bool instance Plankton.Additive.AdditiveInvertible a => Plankton.Additive.AdditiveInvertible (Data.Complex.Complex a) instance Plankton.Additive.AdditiveIdempotent GHC.Types.Bool instance Plankton.Additive.Additive GHC.Types.Double instance Plankton.Additive.Additive GHC.Types.Float instance Plankton.Additive.Additive GHC.Types.Int instance Plankton.Additive.Additive GHC.Integer.Type.Integer instance Plankton.Additive.Additive GHC.Types.Bool instance Plankton.Additive.Additive a => Plankton.Additive.Additive (Data.Complex.Complex a) instance Plankton.Additive.AdditiveGroup GHC.Types.Double instance Plankton.Additive.AdditiveGroup GHC.Types.Float instance Plankton.Additive.AdditiveGroup GHC.Types.Int instance Plankton.Additive.AdditiveGroup GHC.Integer.Type.Integer instance Plankton.Additive.AdditiveGroup a => Plankton.Additive.AdditiveGroup (Data.Complex.Complex a) -- | A magma heirarchy for multiplication. The basic magma structure is -- repeated and prefixed with 'Multiplicative-'. module Plankton.Multiplicative -- | times is used as the operator for the multiplicative magam to -- distinguish from * which, by convention, implies commutativity -- --
-- ∀ a,b ∈ A: a `times` b ∈ A ---- -- law is true by construction in Haskell class MultiplicativeMagma a times :: MultiplicativeMagma a => a -> a -> a -- | Unital magma for multiplication. -- --
-- one `times` a == a -- a `times` one == a --class MultiplicativeMagma a => MultiplicativeUnital a one :: MultiplicativeUnital a => a -- | Associative magma for multiplication. -- --
-- (a `times` b) `times` c == a `times` (b `times` c) --class MultiplicativeMagma a => MultiplicativeAssociative a -- | Commutative magma for multiplication. -- --
-- a `times` b == b `times` a --class MultiplicativeMagma a => MultiplicativeCommutative a -- | Invertible magma for multiplication. -- --
-- ∀ a ∈ A: recip a ∈ A ---- -- law is true by construction in Haskell class MultiplicativeMagma a => MultiplicativeInvertible a recip :: MultiplicativeInvertible a => a -> a -- | product definition avoiding a clash with the Product monoid in base product :: (Multiplicative a, Foldable f) => f a -> a -- | Multiplicative is commutative, associative and unital under -- multiplication -- --
-- one * a == a -- a * one == a -- (a * b) * c == a * (b * c) -- a * b == b * a --class (MultiplicativeCommutative a, MultiplicativeUnital a, MultiplicativeAssociative a) => Multiplicative a where a * b = times a b (*) :: Multiplicative a => a -> a -> a -- | Non-commutative right divide -- --
-- a `times` recip a = one --class (MultiplicativeUnital a, MultiplicativeAssociative a, MultiplicativeInvertible a) => MultiplicativeRightCancellative a where a /~ b = a `times` recip b (/~) :: MultiplicativeRightCancellative a => a -> a -> a -- | Non-commutative left divide -- --
-- recip a `times` a = one --class (MultiplicativeUnital a, MultiplicativeAssociative a, MultiplicativeInvertible a) => MultiplicativeLeftCancellative a where a ~/ b = recip b `times` a (~/) :: MultiplicativeLeftCancellative a => a -> a -> a -- | Divide (/) is reserved for where both the left and right -- cancellative laws hold. This then implies that the MultiplicativeGroup -- is also Abelian. -- --
-- a / a = one -- recip a = one / a -- recip a * a = one -- a * recip a = one --class (Multiplicative a, MultiplicativeInvertible a) => MultiplicativeGroup a where (/) a b = a `times` recip b (/) :: MultiplicativeGroup a => a -> a -> a instance Plankton.Multiplicative.MultiplicativeMagma GHC.Types.Double instance Plankton.Multiplicative.MultiplicativeMagma GHC.Types.Float instance Plankton.Multiplicative.MultiplicativeMagma GHC.Types.Int instance Plankton.Multiplicative.MultiplicativeMagma GHC.Integer.Type.Integer instance Plankton.Multiplicative.MultiplicativeMagma GHC.Types.Bool instance (Plankton.Multiplicative.MultiplicativeMagma a, Plankton.Additive.AdditiveGroup a) => Plankton.Multiplicative.MultiplicativeMagma (Data.Complex.Complex a) instance Plankton.Multiplicative.MultiplicativeUnital GHC.Types.Double instance Plankton.Multiplicative.MultiplicativeUnital GHC.Types.Float instance Plankton.Multiplicative.MultiplicativeUnital GHC.Types.Int instance Plankton.Multiplicative.MultiplicativeUnital GHC.Integer.Type.Integer instance Plankton.Multiplicative.MultiplicativeUnital GHC.Types.Bool instance (Plankton.Additive.AdditiveUnital a, Plankton.Additive.AdditiveGroup a, Plankton.Multiplicative.MultiplicativeUnital a) => Plankton.Multiplicative.MultiplicativeUnital (Data.Complex.Complex a) instance Plankton.Multiplicative.MultiplicativeAssociative GHC.Types.Double instance Plankton.Multiplicative.MultiplicativeAssociative GHC.Types.Float instance Plankton.Multiplicative.MultiplicativeAssociative GHC.Types.Int instance Plankton.Multiplicative.MultiplicativeAssociative GHC.Integer.Type.Integer instance Plankton.Multiplicative.MultiplicativeAssociative GHC.Types.Bool instance (Plankton.Additive.AdditiveGroup a, Plankton.Multiplicative.MultiplicativeAssociative a) => Plankton.Multiplicative.MultiplicativeAssociative (Data.Complex.Complex a) instance Plankton.Multiplicative.MultiplicativeCommutative GHC.Types.Double instance Plankton.Multiplicative.MultiplicativeCommutative GHC.Types.Float instance Plankton.Multiplicative.MultiplicativeCommutative GHC.Types.Int instance Plankton.Multiplicative.MultiplicativeCommutative GHC.Integer.Type.Integer instance Plankton.Multiplicative.MultiplicativeCommutative GHC.Types.Bool instance (Plankton.Additive.AdditiveGroup a, Plankton.Multiplicative.MultiplicativeCommutative a) => Plankton.Multiplicative.MultiplicativeCommutative (Data.Complex.Complex a) instance Plankton.Multiplicative.MultiplicativeInvertible GHC.Types.Double instance Plankton.Multiplicative.MultiplicativeInvertible GHC.Types.Float instance (Plankton.Additive.AdditiveGroup a, Plankton.Multiplicative.MultiplicativeInvertible a) => Plankton.Multiplicative.MultiplicativeInvertible (Data.Complex.Complex a) instance Plankton.Multiplicative.MultiplicativeIdempotent GHC.Types.Bool instance Plankton.Multiplicative.Multiplicative GHC.Types.Double instance Plankton.Multiplicative.Multiplicative GHC.Types.Float instance Plankton.Multiplicative.Multiplicative GHC.Types.Int instance Plankton.Multiplicative.Multiplicative GHC.Integer.Type.Integer instance Plankton.Multiplicative.Multiplicative GHC.Types.Bool instance (Plankton.Additive.AdditiveGroup a, Plankton.Multiplicative.Multiplicative a) => Plankton.Multiplicative.Multiplicative (Data.Complex.Complex a) instance Plankton.Multiplicative.MultiplicativeGroup GHC.Types.Double instance Plankton.Multiplicative.MultiplicativeGroup GHC.Types.Float instance (Plankton.Additive.AdditiveGroup a, Plankton.Multiplicative.MultiplicativeGroup a) => Plankton.Multiplicative.MultiplicativeGroup (Data.Complex.Complex a) -- | Element-by-element operation for Representables module Plankton.Basis -- | element by element addition -- --
-- (a .+. b) .+. c == a .+. (b .+. c) -- zero .+. a = a -- a .+. zero = a -- a .+. b == b .+. a --class (Representable m, Additive a) => AdditiveBasis m a where (.+.) = liftR2 (+) (.+.) :: AdditiveBasis m a => m a -> m a -> m a -- | element by element subtraction -- --
-- a .-. a = singleton zero --class (Representable m, AdditiveGroup a) => AdditiveGroupBasis m a where (.-.) = liftR2 (-) (.-.) :: AdditiveGroupBasis m a => m a -> m a -> m a -- | element by element multiplication -- --
-- (a .*. b) .*. c == a .*. (b .*. c) -- singleton one .*. a = a -- a .*. singelton one = a -- a .*. b == b .*. a --class (Representable m, Multiplicative a) => MultiplicativeBasis m a where (.*.) = liftR2 (*) (.*.) :: MultiplicativeBasis m a => m a -> m a -> m a -- | element by element division -- --
-- a ./. a == singleton one --class (Representable m, MultiplicativeGroup a) => MultiplicativeGroupBasis m a where (./.) = liftR2 (/) (./.) :: MultiplicativeGroupBasis m a => m a -> m a -> m a instance (Data.Functor.Rep.Representable r, Plankton.Additive.Additive a) => Plankton.Basis.AdditiveBasis r a instance (Data.Functor.Rep.Representable r, Plankton.Additive.AdditiveGroup a) => Plankton.Basis.AdditiveGroupBasis r a instance (Data.Functor.Rep.Representable r, Plankton.Multiplicative.Multiplicative a) => Plankton.Basis.MultiplicativeBasis r a instance (Data.Functor.Rep.Representable r, Plankton.Multiplicative.MultiplicativeGroup a) => Plankton.Basis.MultiplicativeGroupBasis r a -- | Distribution avoids a name clash with Distributive module Plankton.Distribution -- | Distribution (and annihilation) laws -- --
-- a * (b + c) == a * b + a * c -- (a + b) * c == a * c + b * c -- a * zero == zero -- zero * a == zero --class (Additive a, MultiplicativeMagma a) => Distribution a instance Plankton.Distribution.Distribution GHC.Types.Double instance Plankton.Distribution.Distribution GHC.Types.Float instance Plankton.Distribution.Distribution GHC.Types.Int instance Plankton.Distribution.Distribution GHC.Integer.Type.Integer instance Plankton.Distribution.Distribution GHC.Types.Bool instance (Plankton.Additive.AdditiveGroup a, Plankton.Distribution.Distribution a) => Plankton.Distribution.Distribution (Data.Complex.Complex a) -- | Ring classes. A distinguishment is made between Rings and Commutative -- Rings. module Plankton.Ring -- | Semiring class (MultiplicativeAssociative a, MultiplicativeUnital a, Distribution a) => Semiring a -- | Ring a summary of the laws inherited from the ring super-classes -- --
-- zero + a == a -- a + zero == a -- (a + b) + c == a + (b + c) -- a + b == b + a -- a - a = zero -- negate a = zero - a -- negate a + a = zero -- a + negate a = zero -- one `times` a == a -- a `times` one == a -- (a `times` b) `times` c == a `times` (b `times` c) -- a `times` (b + c) == a `times` b + a `times` c -- (a + b) `times` c == a `times` c + b `times` c -- a `times` zero == zero -- zero `times` a == zero --class (AdditiveGroup a, MultiplicativeAssociative a, MultiplicativeUnital a, Distribution a) => Ring a -- | CRing is a Ring with Multiplicative Commutation. It arises often due -- to * being defined as a multiplicative commutative operation. class (Multiplicative a, Ring a) => CRing a instance Plankton.Ring.Semiring GHC.Types.Double instance Plankton.Ring.Semiring GHC.Types.Float instance Plankton.Ring.Semiring GHC.Types.Int instance Plankton.Ring.Semiring GHC.Integer.Type.Integer instance Plankton.Ring.Semiring GHC.Types.Bool instance (Plankton.Additive.AdditiveGroup a, Plankton.Ring.Semiring a) => Plankton.Ring.Semiring (Data.Complex.Complex a) instance Plankton.Ring.Ring GHC.Types.Double instance Plankton.Ring.Ring GHC.Types.Float instance Plankton.Ring.Ring GHC.Types.Int instance Plankton.Ring.Ring GHC.Integer.Type.Integer instance Plankton.Ring.Ring a => Plankton.Ring.Ring (Data.Complex.Complex a) instance Plankton.Ring.CRing GHC.Types.Double instance Plankton.Ring.CRing GHC.Types.Float instance Plankton.Ring.CRing GHC.Types.Int instance Plankton.Ring.CRing GHC.Integer.Type.Integer instance Plankton.Ring.CRing a => Plankton.Ring.CRing (Data.Complex.Complex a) -- | Field classes module Plankton.Field -- | A Semifield is a Field without Commutative Multiplication. class (MultiplicativeInvertible a, Ring a) => Semifield a -- | A Field is a Ring plus additive invertible and multiplicative -- invertible operations. -- -- A summary of the rules inherited from super-classes of Field -- --
-- zero + a == a -- a + zero == a -- (a + b) + c == a + (b + c) -- a + b == b + a -- a - a = zero -- negate a = zero - a -- negate a + a = zero -- a + negate a = zero -- one * a == a -- a * one == a -- (a * b) * c == a * (b * c) -- a * (b + c) == a * b + a * c -- (a + b) * c == a * c + b * c -- a * zero == zero -- zero * a == zero -- a * b == b * a -- a / a = one -- recip a = one / a -- recip a * a = one -- a * recip a = one --class (AdditiveGroup a, MultiplicativeGroup a, Ring a) => Field a -- | A hyperbolic field class -- --
-- sqrt . (**2) == identity -- log . exp == identity -- for +ive b, a != 0,1: a ** logBase a b ≈ b --class (Field a) => ExpField a where logBase a b = log b / log a (**) a b = exp (log a * b) sqrt a = a ** (one / (one + one)) exp :: ExpField a => a -> a log :: ExpField a => a -> a logBase :: ExpField a => a -> a -> a (**) :: ExpField a => a -> a -> a sqrt :: ExpField a => a -> a -- | quotient fields explode constraints if they allow for polymorphic -- integral types -- --
-- a - one < floor a <= a <= ceiling a < a + one -- round a == floor (a + one/(one+one)) --class (Field a) => QuotientField a round :: QuotientField a => a -> Integer ceiling :: QuotientField a => a -> Integer floor :: QuotientField a => a -> Integer (^^) :: QuotientField a => a -> Integer -> a -- | A bounded field includes the concepts of infinity and NaN, thus moving -- away from error throwing. -- --
-- one / zero + infinity == infinity -- infinity + a == infinity -- isNaN (infinity - infinity) -- isNaN (infinity / infinity) -- isNaN (nan + a) -- zero / zero != nan ---- -- Note the tricky law that, although nan is assigned to zero/zero, they -- are never-the-less not equal. A committee decided this. class (Field a) => BoundedField a where maxBound = one / zero minBound = negate (one / zero) nan = zero / zero maxBound :: BoundedField a => a minBound :: BoundedField a => a nan :: BoundedField a => a isNaN :: BoundedField a => a -> Bool -- | prints as Infinity infinity :: BoundedField a => a -- | prints as `-Infinity` neginfinity :: BoundedField a => a -- | Trigonometric Field class (Ord a, Field a) => TrigField a where tan x = sin x / cos x tanh x = sinh x / cosh x atan2 y x | x > zero = atan (y / x) | x == zero && y > zero = pi / (one + one) | x < one && y > one = pi + atan (y / x) | (x <= zero && y < zero) || (x < zero) = negate (atan2 (negate y) x) | y == zero = pi | x == zero && y == zero = y | otherwise = x + y pi :: TrigField a => a sin :: TrigField a => a -> a cos :: TrigField a => a -> a tan :: TrigField a => a -> a asin :: TrigField a => a -> a acos :: TrigField a => a -> a atan :: TrigField a => a -> a sinh :: TrigField a => a -> a cosh :: TrigField a => a -> a tanh :: TrigField a => a -> a asinh :: TrigField a => a -> a acosh :: TrigField a => a -> a atanh :: TrigField a => a -> a atan2 :: TrigField a => a -> a -> a instance Plankton.Field.Semifield GHC.Types.Double instance Plankton.Field.Semifield GHC.Types.Float instance Plankton.Field.Semifield a => Plankton.Field.Semifield (Data.Complex.Complex a) instance Plankton.Field.Field GHC.Types.Double instance Plankton.Field.Field GHC.Types.Float instance Plankton.Field.Field a => Plankton.Field.Field (Data.Complex.Complex a) instance Plankton.Field.ExpField GHC.Types.Double instance Plankton.Field.ExpField GHC.Types.Float instance (Plankton.Field.TrigField a, Plankton.Field.ExpField a) => Plankton.Field.ExpField (Data.Complex.Complex a) instance Plankton.Field.QuotientField GHC.Types.Float instance Plankton.Field.QuotientField GHC.Types.Double instance Plankton.Field.BoundedField GHC.Types.Float instance Plankton.Field.BoundedField GHC.Types.Double instance Plankton.Field.BoundedField a => Plankton.Field.BoundedField (Data.Complex.Complex a) instance Plankton.Field.TrigField GHC.Types.Double instance Plankton.Field.TrigField GHC.Types.Float -- | Metric classes module Plankton.Metric -- | signum from base is not an operator replicated in numhask, -- being such a very silly name, and preferred is the much more obvious -- sign. Compare with Norm and Banach where -- there is a change in codomain -- --
-- abs a * sign a == a ---- -- Generalising this class tends towards size and direction (abs is the -- size on the one-dim number line of a vector with its tail at zero, and -- sign is the direction, right?). class (MultiplicativeUnital a) => Signed a sign :: Signed a => a -> a abs :: Signed a => a -> a -- | Like Signed, except the codomain can be different to the domain. class Normed a b size :: Normed a b => a -> b -- | distance between numbers -- --
-- distance a b >= zero -- distance a a == zero -- \a b c -> distance a c + distance b c - distance a b >= zero && -- distance a b + distance b c - distance a c >= zero && -- distance a b + distance a c - distance b c >= zero && --class Metric a b distance :: Metric a b => a -> a -> b -- | todo: This should probably be split off into some sort of alternative -- Equality logic, but to what end? class (AdditiveGroup a) => Epsilon a where positive a = a == abs a veryPositive a = not (nearZero a) && positive a veryNegative a = not (nearZero a || positive a) nearZero :: Epsilon a => a -> Bool aboutEqual :: Epsilon a => a -> a -> Bool positive :: (Epsilon a, Eq a, Signed a) => a -> Bool veryPositive :: (Epsilon a, Eq a, Signed a) => a -> Bool veryNegative :: (Epsilon a, Eq a, Signed a) => a -> Bool -- | todo: is utf perfectly acceptable these days? (≈) :: (Epsilon a) => a -> a -> Bool infixl 4 ≈ instance Plankton.Metric.Signed GHC.Types.Double instance Plankton.Metric.Signed GHC.Types.Float instance Plankton.Metric.Signed GHC.Types.Int instance Plankton.Metric.Signed GHC.Integer.Type.Integer instance Plankton.Metric.Normed GHC.Types.Double GHC.Types.Double instance Plankton.Metric.Normed GHC.Types.Float GHC.Types.Float instance Plankton.Metric.Normed GHC.Types.Int GHC.Types.Int instance Plankton.Metric.Normed GHC.Integer.Type.Integer GHC.Integer.Type.Integer instance (Plankton.Multiplicative.Multiplicative a, Plankton.Field.ExpField a, Plankton.Metric.Normed a a) => Plankton.Metric.Normed (Data.Complex.Complex a) a instance Plankton.Metric.Metric GHC.Types.Double GHC.Types.Double instance Plankton.Metric.Metric GHC.Types.Float GHC.Types.Float instance Plankton.Metric.Metric GHC.Types.Int GHC.Types.Int instance Plankton.Metric.Metric GHC.Integer.Type.Integer GHC.Integer.Type.Integer instance (Plankton.Multiplicative.Multiplicative a, Plankton.Field.ExpField a, Plankton.Metric.Normed a a) => Plankton.Metric.Metric (Data.Complex.Complex a) a instance Plankton.Metric.Epsilon GHC.Types.Double instance Plankton.Metric.Epsilon GHC.Types.Float instance Plankton.Metric.Epsilon GHC.Types.Int instance Plankton.Metric.Epsilon GHC.Integer.Type.Integer instance Plankton.Metric.Epsilon a => Plankton.Metric.Epsilon (Data.Complex.Complex a) -- | Integral classes module Plankton.Integral -- | Integral laws -- --
-- b == zero || b * (a `div` b) + (a `mod` b) == a --class (Ring a) => Integral a where div a1 a2 = fst (divMod a1 a2) mod a1 a2 = snd (divMod a1 a2) div :: Integral a => a -> a -> a mod :: Integral a => a -> a -> a divMod :: Integral a => a -> a -> (a, a) -- | toInteger is kept separate from Integral to help with compatability -- issues. class ToInteger a toInteger :: ToInteger a => a -> Integer -- | fromInteger is the most problematic of the Num class -- operators. Particularly heinous, it is assumed that any number type -- can be constructed from an Integer, so that the broad classes of -- objects that are composed of multiple elements is avoided in haskell. class FromInteger a fromInteger :: FromInteger a => Integer -> a -- | coercion of Integrals -- --
-- fromIntegral a == a --fromIntegral :: (ToInteger a, FromInteger b) => a -> b instance Plankton.Integral.Integral GHC.Types.Int instance Plankton.Integral.Integral GHC.Integer.Type.Integer instance Plankton.Integral.FromInteger GHC.Types.Double instance Plankton.Integral.FromInteger GHC.Types.Float instance Plankton.Integral.FromInteger GHC.Types.Int instance Plankton.Integral.FromInteger GHC.Integer.Type.Integer instance Plankton.Integral.ToInteger GHC.Types.Int instance Plankton.Integral.ToInteger GHC.Integer.Type.Integer -- | Algebra for Representable numbers module Plankton.Module -- | Additive Module Laws -- --
-- (a + b) .+ c == a + (b .+ c) -- (a + b) .+ c == (a .+ c) + b -- a .+ zero == a -- a .+ b == b +. a --class (Representable r, Additive a) => AdditiveModule r a where r .+ a = fmap (a +) r a +. r = fmap (a +) r (.+) :: AdditiveModule r a => r a -> a -> r a (+.) :: AdditiveModule r a => a -> r a -> r a -- | Subtraction Module Laws -- --
-- (a + b) .- c == a + (b .- c) -- (a + b) .- c == (a .- c) + b -- a .- zero == a -- a .- b == negate b +. a --class (Representable r, AdditiveGroup a) => AdditiveGroupModule r a where r .- a = fmap (\ x -> x - a) r a -. r = fmap (\ x -> a - x) r (.-) :: AdditiveGroupModule r a => r a -> a -> r a (-.) :: AdditiveGroupModule r a => a -> r a -> r a -- | Multiplicative Module Laws -- --
-- a .* one == a -- (a + b) .* c == (a .* c) + (b .* c) -- c *. (a + b) == (c *. a) + (c *. b) -- a .* zero == zero -- a .* b == b *. a --class (Representable r, Multiplicative a) => MultiplicativeModule r a where r .* a = fmap (a *) r a *. r = fmap (a *) r (.*) :: MultiplicativeModule r a => r a -> a -> r a (*.) :: MultiplicativeModule r a => a -> r a -> r a -- | Division Module Laws -- --
-- nearZero a || a ./ one == a -- b == zero || a ./ b == recip b *. a --class (Representable r, MultiplicativeGroup a) => MultiplicativeGroupModule r a where r ./ a = fmap (/ a) r a /. r = fmap (\ x -> a / x) r (./) :: MultiplicativeGroupModule r a => r a -> a -> r a (/.) :: MultiplicativeGroupModule r a => a -> r a -> r a -- | Banach (with Norm) laws form rules around size and direction of a -- number, with a potential crossing into another codomain. -- --
-- a == singleton zero || normalize a *. size a == a --class (Representable r, ExpField a, Normed (r a) a) => Banach r a where normalize a = a ./ size a normalize :: Banach r a => r a -> r a -- | the inner product of a representable over a semiring -- --
-- a <.> b == b <.> a -- a <.> (b +c) == a <.> b + a <.> c -- a <.> (s *. b + c) == s * (a <.> b) + a <.> c ---- -- (s0 *. a) . (s1 *. b) == s0 * s1 * (a . b) class (Semiring a, Foldable r, Representable r) => Hilbert r a where (<.>) a b = sum $ liftR2 times a b (<.>) :: Hilbert r a => r a -> r a -> a -- | synonym for (.) inner :: (Hilbert r a) => r a -> r a -> a -- | tensorial type -- | generalised outer product -- --
-- a><b + c><b == (a+c) >< b -- a><b + a><c == a >< (b+c) ---- -- todo: work out why these laws down't apply > a *. (b>== -- (a<b) .* c > (a>.* c == a *. (b<c) class TensorProduct a where outer = (><) (><) :: TensorProduct a => a -> a -> (a >< a) outer :: TensorProduct a => a -> a -> (a >< a) timesleft :: TensorProduct a => a -> (a >< a) -> a timesright :: TensorProduct a => (a >< a) -> a -> a instance (Data.Functor.Rep.Representable r, Plankton.Additive.Additive a) => Plankton.Module.AdditiveModule r a instance (Data.Functor.Rep.Representable r, Plankton.Additive.AdditiveGroup a) => Plankton.Module.AdditiveGroupModule r a instance (Data.Functor.Rep.Representable r, Plankton.Multiplicative.Multiplicative a) => Plankton.Module.MultiplicativeModule r a instance (Data.Functor.Rep.Representable r, Plankton.Multiplicative.MultiplicativeGroup a) => Plankton.Module.MultiplicativeGroupModule r a instance (Plankton.Metric.Normed (r a) a, Plankton.Field.ExpField a, Data.Functor.Rep.Representable r) => Plankton.Module.Banach r a instance (Plankton.Module.Hilbert r a, Plankton.Multiplicative.Multiplicative a) => Plankton.Module.TensorProduct (r a)