packages feed

numhask 0.7.0.0 → 0.7.1.0

raw patch · 9 files changed

+111/−91 lines, 9 files

Files

numhask.cabal view
@@ -1,14 +1,14 @@ cabal-version: 2.4 name: numhask-version: 0.7.0.0+version: 0.7.1.0 synopsis:-  A numeric class heirarchy.+  A numeric class hierarchy. description:     This package provides numeric classes alternate to the prelude specified in [haskell98](https://www.haskell.org/onlinereport/standard-prelude.html).     .     The numeric class constellation looks somewhat like:     .-    ![nh](other/nh.svg)+    ![nh](docs/other/nh.svg)     .     == Usage     .@@ -63,6 +63,8 @@     -Wincomplete-record-updates     -Wincomplete-uni-patterns     -Wredundant-constraints+    -fwrite-ide-info+    -hiedir=.hie   build-depends:     base >=4.7 && <5,     protolude >=0.3 && <0.4,
src/NumHask/Algebra/Field.hs view
@@ -76,7 +76,8 @@ -- > for +ive b, a != 0,1: a ** logBase a b ≈ b class   (Field a) =>-  ExpField a where+  ExpField a+  where   exp :: a -> a   log :: a -> a   logBase :: a -> a -> a@@ -176,7 +177,8 @@ -- 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) =>-  UpperBoundedField a where+  UpperBoundedField a+  where   infinity :: a   infinity = one / zero @@ -194,7 +196,8 @@ -- | Negative infinity. class   (Subtractive a, Field a) =>-  LowerBoundedField a where+  LowerBoundedField a+  where   negInfinity :: a   negInfinity = negate (one / zero) @@ -208,7 +211,8 @@ -- | Trigonometric Field class   (Field a) =>-  TrigField a where+  TrigField a+  where   pi :: a   sin :: a -> a   cos :: a -> a
src/NumHask/Algebra/Group.hs view
@@ -52,7 +52,8 @@ -- > a ⊕ unit = a class   Magma a =>-  Unital a where+  Unital a+  where   unit :: a  instance Unital b => Unital (a -> b) where@@ -83,7 +84,8 @@ -- > ∀ a,b ∈ T: inv a ⊕ (a ⊕ b) = b = (b ⊕ a) ⊕ inv a class   Magma a =>-  Invertible a where+  Invertible a+  where   inv :: a -> a  instance Invertible b => Invertible (a -> b) where@@ -102,7 +104,8 @@ -- > a ⊕ absorb = absorb class   Magma a =>-  Absorbing a where+  Absorbing a+  where   absorb :: a  instance Absorbing b => Absorbing (a -> b) where
src/NumHask/Algebra/Module.hs view
@@ -32,7 +32,8 @@ class   (Additive a) =>   AdditiveAction m a-    | m -> a where+    | m -> a+  where   infixl 6 .+   (.+) :: a -> m -> m @@ -43,7 +44,8 @@ class   (Subtractive a) =>   SubtractiveAction m a-    | m -> a where+    | m -> a+  where   infixl 6 .-   (.-) :: a -> m -> m @@ -54,7 +56,8 @@ class   (Multiplicative a) =>   MultiplicativeAction m a-    | m -> a where+    | m -> a+  where   infixl 7 .*   (.*) :: a -> m -> m   infixl 7 *.@@ -64,7 +67,8 @@ class   (Divisive a) =>   DivisiveAction m a-    | m -> a where+    | m -> a+  where   infixl 7 ./   (./) :: a -> m -> m   infixl 7 /.
src/NumHask/Analysis/Metric.hs view
@@ -18,6 +18,7 @@   ) where +import Data.Bool (bool) import Data.Int (Int16, Int32, Int64, Int8) import Data.Word (Word16, Word32, Word64, Word8) import GHC.Generics (Generic)@@ -27,11 +28,11 @@ import NumHask.Algebra.Module import NumHask.Algebra.Multiplicative import Prelude hiding-  ( (*),-    (-),-    Bounded (..),+  ( Bounded (..),     Integral (..),     negate,+    (*),+    (-),   ) import qualified Prelude as P @@ -40,100 +41,101 @@ -- > abs a * sign a == a class   (Additive a, Multiplicative a) =>-  Signed a where+  Signed a+  where   sign :: a -> a   abs :: a -> a  instance Signed Double where-  sign a-    | a == zero = zero-    | a > zero = one-    | otherwise = negate one+  sign a =+    case compare a zero of+      EQ -> zero+      GT -> one+      LT -> negate one   abs = P.abs  instance Signed Float where-  sign a-    | a == zero = zero-    | a > zero = one-    | otherwise = negate one+  sign a =+    case compare a zero of+      EQ -> zero+      GT -> one+      LT -> negate one   abs = P.abs  instance Signed Int where-  sign a-    | a == zero = zero-    | a > zero = one-    | otherwise = negate one+  sign a =+    case compare a zero of+      EQ -> zero+      GT -> one+      LT -> negate one   abs = P.abs  instance Signed Integer where-  sign a-    | a == zero = zero-    | a > zero = one-    | otherwise = negate one+  sign a =+    case compare a zero of+      EQ -> zero+      GT -> one+      LT -> negate one   abs = P.abs  instance Signed Natural where-  sign a-    | a == zero = zero-    | otherwise = one+  sign a =+    case compare a zero of+      EQ -> zero+      GT -> one+      LT -> negate one   abs = id  instance Signed Int8 where-  sign a-    | a == zero = zero-    | a > zero = one-    | otherwise = negate one+  sign a =+    case compare a zero of+      EQ -> zero+      GT -> one+      LT -> negate one   abs = P.abs  instance Signed Int16 where-  sign a-    | a == zero = zero-    | a > zero = one-    | otherwise = negate one+  sign a =+    case compare a zero of+      EQ -> zero+      GT -> one+      LT -> negate one   abs = P.abs  instance Signed Int32 where-  sign a-    | a == zero = zero-    | a > zero = one-    | otherwise = negate one+  sign a =+    case compare a zero of+      EQ -> zero+      GT -> one+      LT -> negate one   abs = P.abs  instance Signed Int64 where-  sign a-    | a == zero = zero-    | a > zero = one-    | otherwise = negate one+  sign a =+    case compare a zero of+      EQ -> zero+      GT -> one+      LT -> negate one   abs = P.abs  instance Signed Word where-  sign a-    | a == zero = zero-    | otherwise = one+  sign a = bool one zero (a == zero)   abs = P.abs  instance Signed Word8 where-  sign a-    | a == zero = zero-    | otherwise = one+  sign a = bool one zero (a == zero)   abs = P.abs  instance Signed Word16 where-  sign a-    | a == zero = zero-    | otherwise = one+  sign a = bool one zero (a == zero)   abs = P.abs  instance Signed Word32 where-  sign a-    | a == zero = zero-    | otherwise = one+  sign a = bool one zero (a == zero)   abs = P.abs  instance Signed Word64 where-  sign a-    | a == zero = zero-    | otherwise = one+  sign a = bool one zero (a == zero)   abs = P.abs  -- | Norm is a slight generalisation of Signed. The class has the same shape but allows the codomain to be different to the domain.@@ -221,8 +223,7 @@   ray :: dir -> coord  -- | Something that has a magnitude and a direction.-data Polar mag dir-  = Polar {magnitude :: mag, direction :: dir}+data Polar mag dir = Polar {magnitude :: !mag, direction :: !dir}   deriving (Eq, Show, Generic)  -- | Convert from a number to a Polar.@@ -236,7 +237,8 @@ -- | A small number, especially useful for approximate equality. class   (Eq a, Additive a, Subtractive a, MeetSemiLattice a) =>-  Epsilon a where+  Epsilon a+  where   epsilon :: a   epsilon = zero 
src/NumHask/Data/Complex.hs view
@@ -1,6 +1,4 @@ {-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DeriveFoldable #-}-{-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveTraversable #-} {-# LANGUAGE FlexibleInstances #-}@@ -26,8 +24,7 @@ import NumHask.Analysis.Metric import NumHask.Data.Integral import Prelude hiding-  ( (/),-    Num (..),+  ( Num (..),     atan,     atan2,     cos,@@ -39,8 +36,9 @@     recip,     sin,     sqrt,+    (/),   )-import qualified Prelude as P ((&&), (<), (<=), (==), (>), Ord (..), otherwise)+import qualified Prelude as P (Ord (..), otherwise, (&&), (<), (<=), (==), (>))  -- ----------------------------------------------------------------------------- -- The Complex type
src/NumHask/Data/Integral.hs view
@@ -21,12 +21,14 @@ where  import Data.Int (Int16, Int32, Int64, Int8)+import Data.Ord import Data.Word (Word, Word16, Word32, Word64, Word8) import GHC.Natural (Natural (..))+import GHC.Num (naturalFromInteger) import NumHask.Algebra.Additive import NumHask.Algebra.Multiplicative import NumHask.Algebra.Ring-import Prelude ((.), Double, Float, Int, Integer, fst, snd)+import Prelude (Double, Float, Int, Integer, fst, snd, (.)) import qualified Prelude as P  -- | An Integral is anything that satisfies the law:@@ -34,7 +36,8 @@ -- > b == zero || b * (a `div` b) + (a `mod` b) == a class   (Distributive a) =>-  Integral a where+  Integral a+  where   infixl 7 `div`, `mod`   div :: a -> a -> a   div a1 a2 = fst (divMod a1 a2)@@ -244,7 +247,7 @@   fromIntegral = P.id  instance FromIntegral Natural Integer where-  fromIntegral = P.fromInteger+  fromIntegral = naturalFromInteger  instance FromIntegral Int8 Integer where   fromIntegral = P.fromInteger@@ -368,7 +371,7 @@   fromInteger = P.id  instance FromInteger Natural where-  fromInteger = P.fromInteger+  fromInteger = naturalFromInteger  instance FromInteger Int8 where   fromInteger = P.fromInteger@@ -409,16 +412,19 @@ odd :: (P.Eq a, Integral a) => a -> P.Bool odd = P.not . even +infixr 8 ^^+ -- | raise a number to an 'Integral' power (^^) ::   (P.Ord b, Divisive a, Subtractive b, Integral b) =>   a ->   b ->   a-x0 ^^ y0-  | y0 P.< zero = recip (x0 ^^ negate y0)-  | y0 P.== zero = one-  | P.otherwise = f x0 y0+x0 ^^ y0 =+  case compare y0 zero of+    EQ -> one+    GT -> f x0 y0+    LT -> recip (x0 ^^ negate y0)   where     f x y       | even y = f (x * x) (y `quot` two)@@ -428,6 +434,8 @@       | even y = g (x * x) (y `quot` two) z       | y P.== one = x * z       | P.otherwise = g (x * x) (y `quot` two) (x * z)++infixr 8 ^  -- | raise a number to an 'Int' power --
src/NumHask/Data/LogField.hs view
@@ -1,6 +1,4 @@ {-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE DeriveFoldable #-}-{-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveTraversable #-} {-# LANGUAGE FlexibleInstances #-}
src/NumHask/Data/Rational.hs view
@@ -33,7 +33,7 @@ import NumHask.Algebra.Ring import NumHask.Analysis.Metric import NumHask.Data.Integral-import Prelude ((.), Int, Integer, Rational)+import Prelude (Int, Integer, Ord (..), Ordering (..), Rational, (.)) import qualified Prelude as P  -- $setup@@ -102,10 +102,11 @@ instance (P.Ord a, Signed a, Integral a, Field a) => LowerBoundedField (Ratio a)  instance (P.Ord a, Signed a, Integral a, Ring a) => Signed (Ratio a) where-  sign (n :% _)-    | n P.== zero = zero-    | n P.> zero = one-    | P.otherwise = negate one+  sign (n :% _) =+    case compare n zero of+      EQ -> zero+      GT -> one+      LT -> negate one   abs (n :% d) = abs n :% abs d  instance (P.Ord a, Signed a, Integral a, Ring a) => Norm (Ratio a) (Ratio a) where