packages feed

numeric-prelude 0.3.0.2 → 0.4

raw patch · 22 files changed

+370/−201 lines, 22 filesdep ~basedep ~gnuplot

Dependency ranges changed: base, gnuplot

Files

Makefile view
@@ -56,6 +56,9 @@ ghci: 	$(HCI) -Wall -i:src:test +RTS -M256m -c30 -RTS test/Test.hs +ghci7:+	$(HCI) -Wall -i:src:test -XCPP -DNoImplicitPrelude=RebindableSyntax +RTS -M256m -c30 -RTS test/Test.hs+ ghci-gauss: 	$(HCI) -Wall -i:src:test +RTS -M256m -c30 -RTS test/Test/MathObj/Gaussian/Variance.hs 
numeric-prelude.cabal view
@@ -1,5 +1,5 @@ Name:           numeric-prelude-Version:        0.3.0.2+Version:        0.4 License:        GPL License-File:   LICENSE Author:         Dylan Thurston <dpt@math.harvard.edu>, Henning Thielemann <numericprelude@henning-thielemann.de>, Mikael Johansson@@ -8,7 +8,7 @@ Category:       Math Stability:      Experimental Tested-With:    GHC==6.4.1, GHC==6.8.2, GHC==6.10.4, GHC==6.12.3-Tested-With:    GHC==7.2.2, GHC==7.4.1+Tested-With:    GHC==7.2.2, GHC==7.4.1, GHC==7.6.3 Cabal-Version:  >=1.6 Build-Type:     Simple Synopsis:       An experimental alternative hierarchy of numeric type classes@@ -154,7 +154,7 @@   default:     False  Source-Repository this-  Tag:         0.3.0.2+  Tag:         0.4   Type:        darcs   Location:    http://code.haskell.org/numeric-prelude/ @@ -193,6 +193,7 @@     Algebra.DimensionTerm     Algebra.DivisibleSpace     Algebra.Field+    Algebra.FloatingPoint     Algebra.Indexable     Algebra.IntegralDomain     Algebra.NonNegative@@ -338,7 +339,7 @@     MathObj.Gaussian.Example   If flag(buildTests)     Build-Depends:-      gnuplot >=0.3 && <0.5,+      gnuplot >=0.5 && <0.6,       HTam >=0.0.2 && <0.1   Else     Buildable: False
src/Algebra/Additive.hs view
@@ -32,6 +32,7 @@ import Data.Tuple.HT (fst3, snd3, thd3, ) import qualified Data.List.Match as Match +import qualified Data.Complex as Complex98 import qualified Data.Ratio as Ratio98 import qualified Prelude as P import Prelude (Integer, Float, Double, fromInteger, )@@ -405,7 +406,17 @@    {-# INLINE negate #-}    {-# INLINE (+) #-}    {-# INLINE (-) #-}-   zero                =  0+   zero                =  P.fromInteger 0+   (+)                 =  (P.+)+   (-)                 =  (P.-)+   negate              =  P.negate++instance (P.RealFloat a) => C (Complex98.Complex a) where+   {-# INLINE zero #-}+   {-# INLINE negate #-}+   {-# INLINE (+) #-}+   {-# INLINE (-) #-}+   zero                =  P.fromInteger 0    (+)                 =  (P.+)    (-)                 =  (P.-)    negate              =  P.negate
src/Algebra/Field.hs view
@@ -16,12 +16,11 @@  import Number.Ratio (T((:%)), Rational, (%), numerator, denominator, ) import qualified Number.Ratio as Ratio+import qualified Data.Complex as Complex98 import qualified Data.Ratio as Ratio98 import qualified Algebra.PrincipalIdealDomain as PID-import qualified Algebra.Units as Unit  import qualified Algebra.Ring         as Ring--- import qualified Algebra.Additive     as Additive import qualified Algebra.ZeroTestable as ZeroTestable  import Algebra.Ring ((*), (^), one, fromInteger)@@ -136,10 +135,7 @@      recip (x:%y)         =  (y:%x) -}-    recip (x:%y)         =-       if isZero y-         then error "Ratio./: division by zero"-         else (y * Unit.stdUnitInv x) :% Unit.stdAssociate x+    recip = Ratio.recip     fromRational' (x:%y) =  fromInteger x % fromInteger y  @@ -155,6 +151,12 @@ -- legacy  instance (P.Integral a) => C (Ratio98.Ratio a) where+    {-# INLINE (/) #-}+    {-# INLINE recip #-}+    (/)    = (P./)+    recip  = (P.recip)++instance (P.RealFloat a) => C (Complex98.Complex a) where     {-# INLINE (/) #-}     {-# INLINE recip #-}     (/)    = (P./)
+ src/Algebra/FloatingPoint.hs view
@@ -0,0 +1,57 @@+{-# LANGUAGE NoImplicitPrelude #-}+module Algebra.FloatingPoint where++import qualified Algebra.RealRing as RealRing+import NumericPrelude.Base++import qualified Prelude as P+import Prelude (Int, Integer, Float, Double, )+++{- |+Counterpart of 'Prelude.RealFloat' but with NumericPrelude superclass.+-}+class RealRing.C a => C a where+   radix :: a -> Integer+   digits :: a -> Int+   range :: a -> (Int, Int)+   decode :: a -> (Integer, Int)+   encode :: Integer -> Int -> a+   exponent :: a -> Int+   significand :: a -> a+   scale :: Int -> a -> a+   isNaN :: a -> Bool+   isInfinite :: a -> Bool+   isDenormalized :: a -> Bool+   isNegativeZero :: a -> Bool+   isIEEE :: a -> Bool++instance C Float where+   radix = P.floatRadix+   digits = P.floatDigits+   range = P.floatRange+   decode = P.decodeFloat+   encode = P.encodeFloat+   exponent = P.exponent+   significand = P.significand+   scale = P.scaleFloat+   isNaN = P.isNaN+   isInfinite = P.isInfinite+   isDenormalized = P.isDenormalized+   isNegativeZero = P.isNegativeZero+   isIEEE = P.isIEEE++instance C Double where+   radix = P.floatRadix+   digits = P.floatDigits+   range = P.floatRange+   decode = P.decodeFloat+   encode = P.encodeFloat+   exponent = P.exponent+   significand = P.significand+   scale = P.scaleFloat+   isNaN = P.isNaN+   isInfinite = P.isInfinite+   isDenormalized = P.isDenormalized+   isNegativeZero = P.isNegativeZero+   isIEEE = P.isIEEE
src/Algebra/OccasionallyScalar.hs view
@@ -27,15 +27,8 @@  module Algebra.OccasionallyScalar where --- import qualified Algebra.RealRing    as RealRing-import qualified Algebra.ZeroTestable as ZeroTestable-import qualified Algebra.Additive     as Additive-import qualified Number.Complex       as Complex- import Data.Maybe (fromMaybe, ) -import Number.Complex((+:))- import NumericPrelude.Base import NumericPrelude.Numeric @@ -66,14 +59,6 @@    toScalar      = id    toMaybeScalar = Just    fromScalar    = id---- this instance should be defined in Number.Complex-instance (Show v, ZeroTestable.C v, Additive.C v, C a v) => C a (Complex.T v) where-   toScalar        = toScalarShow-   toMaybeScalar x = if isZero (Complex.imag x)-                       then toMaybeScalar (Complex.real x)-                       else Nothing-   fromScalar x    = fromScalar x +: zero  {- converting values automatically to integers is a bad idea instance (Integral b, RealRing.C a)
src/Algebra/Ring.hs view
@@ -38,6 +38,7 @@  import NumericPrelude.Base import Prelude (Integer, Float, Double, )+import qualified Data.Complex as Complex98 import qualified Data.Ratio as Ratio98 import qualified Prelude as P -- import Test.QuickCheck@@ -252,6 +253,14 @@    {-# INLINE one #-}    {-# INLINE fromInteger #-}    {-# INLINE (*) #-}-   one                 =  1+   one                 =  P.fromInteger 1+   fromInteger         =  P.fromInteger+   (*)                 =  (P.*)++instance (P.RealFloat a) => C (Complex98.Complex a) where+   {-# INLINE one #-}+   {-# INLINE fromInteger #-}+   {-# INLINE (*) #-}+   one                 =  P.fromInteger 1    fromInteger         =  P.fromInteger    (*)                 =  (P.*)
src/MathObj/Matrix.hs view
@@ -18,7 +18,7 @@ but no additional parameters.  ToDo:- - Matrix inverse, determinant+ - Matrix inverse, determinant (see htam:Matrix) -}  module MathObj.Matrix (@@ -71,9 +71,9 @@ {- | A matrix is a twodimensional array, indexed by integers. -}-data T a =+newtype T a =    Cons (Array (Dimension, Dimension) a)-      deriving (Eq,Ord,Read)+      deriving (Eq, Ord, Read)  type Dimension = Int 
src/MathObj/Polynomial.hs view
@@ -73,6 +73,8 @@  import Test.QuickCheck (Arbitrary(arbitrary)) +import qualified MathObj.Wrapper.Haskell98 as W98+ import NumericPrelude.Base    hiding (const, reverse, ) import NumericPrelude.Numeric @@ -279,7 +281,7 @@    arbitrary = liftM (fromCoeffs . Core.normalize) arbitrary  -{- * legacy instances -}+-- * Haskell 98 legacy instances  {- | It is disputable whether polynomials shall be represented by number literals or not.@@ -288,19 +290,20 @@ in  (x^2+x+1)*(x-1) However the output looks much different. -}-{-# INLINE legacyInstance #-}-legacyInstance :: a-legacyInstance =-   error "legacy Ring.C instance for simple input of numeric literals"+{-# INLINE notImplemented #-}+notImplemented :: String -> a+notImplemented name =+   error $ "MathObj.Polynomial: method " ++ name ++ " cannot be implemented" -instance (Ring.C a, Eq a, Show a, ZeroTestable.C a) => P98.Num (T a) where-   fromInteger = const . fromInteger-   negate = Additive.negate -- for unary minus-   (+)    = legacyInstance-   (*)    = legacyInstance-   abs    = legacyInstance-   signum = legacyInstance+-- legacy instances for use of numeric literals in GHCi+instance (P98.Num a) => P98.Num (T a) where+   fromInteger = const . P98.fromInteger+   negate = W98.unliftF1 Additive.negate+   (+)    = W98.unliftF2 (Additive.+)+   (*)    = W98.unliftF2 (Ring.*)+   abs    = notImplemented "abs"+   signum = notImplemented "signum" -instance (Field.C a, Eq a, Show a, ZeroTestable.C a) => P98.Fractional (T a) where-   fromRational = const . fromRational-   (/) = legacyInstance+instance (P98.Fractional a) => P98.Fractional (T a) where+   fromRational = const . P98.fromRational+   (/) = notImplemented "(/)"
src/MathObj/Wrapper/Haskell98.hs view
@@ -10,6 +10,7 @@ import qualified Algebra.Additive as Additive import qualified Algebra.Algebraic as Algebraic import qualified Algebra.Field as Field+import qualified Algebra.FloatingPoint as Float import qualified Algebra.IntegralDomain as Integral import qualified Algebra.PrincipalIdealDomain as PID import qualified Algebra.RealField as RealField@@ -43,7 +44,7 @@ then @T (Polynomial (MathObj.Wrapper.NumericPrelude.T a))@ is in 'Ring.C' for all types @a@ that are in 'Ring.C'. -}-newtype T a = Cons a+newtype T a = Cons {decons :: a}    deriving       (Show, Eq, Ord, Ix, Bounded, Enum,        Num, Integral, Fractional, Floating,@@ -59,6 +60,15 @@ lift2 f (Cons a) (Cons b) = Cons (f a b)  +{-# INLINE unliftF1 #-}+unliftF1 :: Functor f => (f (T a) -> f (T b)) -> f a -> f b+unliftF1 f a = fmap decons $ f (fmap Cons a)++{-# INLINE unliftF2 #-}+unliftF2 :: Functor f => (f (T a) -> f (T b) -> f (T c)) -> f a -> f b -> f c+unliftF2 f a b = fmap decons $ f (fmap Cons a) (fmap Cons b)++ instance Functor T where    {-# INLINE fmap #-}    fmap f (Cons a) = Cons (f a)@@ -155,6 +165,21 @@  instance (Real a) => ToRational.C (T a) where    toRational (Cons a) = Field.fromRational (toRational a)++instance (RealFloat a) => Float.C (T a) where+   radix = floatRadix . decons+   digits = floatDigits . decons+   range = floatRange . decons+   decode = decodeFloat . decons+   encode m = Cons . encodeFloat m+   exponent = exponent . decons+   significand = lift1 significand+   scale = lift1 . scaleFloat+   isNaN = isNaN . decons+   isInfinite = isInfinite . decons+   isDenormalized = isDenormalized . decons+   isNegativeZero = isNegativeZero . decons+   isIEEE = isIEEE . decons   
src/MathObj/Wrapper/NumericPrelude.hs view
@@ -11,6 +11,7 @@ import qualified Algebra.Additive as Additive import qualified Algebra.Algebraic as Algebraic import qualified Algebra.Field as Field+import qualified Algebra.FloatingPoint as Float import qualified Algebra.IntegralDomain as Integral import qualified Algebra.PrincipalIdealDomain as PID import qualified Algebra.RealField as RealField@@ -51,14 +52,14 @@ then @T (Polynomial (MathObj.Wrapper.Haskell98.T a))@ is in 'Num' for all types @a@ that are in 'Num'. -}-newtype T a = Cons a+newtype T a = Cons {decons :: a}    deriving       (Show, Eq, Ord, Ix, Bounded, Enum,        Ring.C, Additive.C, Field.C, Algebraic.C, Trans.C,        Integral.C, PID.C, Units.C,        Absolute.C, ZeroTestable.C,        RealField.C, RealIntegral.C, RealRing.C, RealTrans.C,-       ToInteger.C, ToRational.C,+       ToInteger.C, ToRational.C, Float.C,        Differential.C)  {-# INLINE lift1 #-}@@ -151,21 +152,21 @@    truncate (Cons a) = fromInteger (RealRing.truncate a)    round (Cons a) = fromInteger (RealRing.round a) -instance (Trans.C a, RealRing.C a, ToRational.C a, Absolute.C a, Ord a, Show a) => RealFloat (T a) where-   atan2 = atan2-   floatRadix = unimplemented "floatRadix"-   floatDigits = unimplemented "floatDigits"-   floatRange = unimplemented "floatRange"-   decodeFloat = unimplemented "decodeFloat"-   encodeFloat = unimplemented "encodeFloat"-   exponent = unimplemented "exponent"-   significand = unimplemented "significand"-   scaleFloat = unimplemented "scaleFloat"-   isNaN = unimplemented "isNaN"-   isInfinite = unimplemented "isInfinite"-   isDenormalized = unimplemented "isDenormalized"-   isNegativeZero = unimplemented "isNegativeZero"-   isIEEE = unimplemented "isIEEE"+instance (RealTrans.C a, Float.C a, ToRational.C a, Absolute.C a, Ord a, Show a) => RealFloat (T a) where+   atan2 = RealTrans.atan2+   floatRadix = Float.radix . decons+   floatDigits = Float.digits . decons+   floatRange = Float.range . decons+   decodeFloat = Float.decode . decons+   encodeFloat m = Cons . Float.encode m+   exponent = Float.exponent . decons+   significand = lift1 Float.significand+   scaleFloat = lift1 . Float.scale+   isNaN = Float.isNaN . decons+   isInfinite = Float.isInfinite . decons+   isDenormalized = Float.isDenormalized . decons+   isNegativeZero = Float.isNegativeZero . decons+   isIEEE = Float.isIEEE . decons  {- instance Additive.C (T a) where
src/Number/Complex.hs view
@@ -54,6 +54,7 @@ import qualified Algebra.NormedSpace.Sum       as NormedSum import qualified Algebra.NormedSpace.Maximum   as NormedMax +import qualified Algebra.OccasionallyScalar as OccScalar import qualified Algebra.VectorSpace        as VectorSpace import qualified Algebra.Module             as Module import qualified Algebra.Vector             as Vector@@ -81,8 +82,10 @@ import Control.Applicative (liftA2, )  import Test.QuickCheck (Arbitrary, arbitrary, )-import Control.Monad (liftM2, )+import Control.Monad (liftM2, guard, ) +import qualified MathObj.Wrapper.Haskell98 as W98+ import qualified Prelude as P import NumericPrelude.Base import NumericPrelude.Numeric hiding (signum, exp, )@@ -359,7 +362,14 @@    {-# INLINE norm #-}    norm x = max (NormedMax.norm (real x)) (NormedMax.norm (imag x)) +instance (Show v, ZeroTestable.C v, Additive.C v, OccScalar.C a v) => OccScalar.C a (T v) where+   toScalar        = OccScalar.toScalarShow+   toMaybeScalar x =+      guard (isZero (imag x)) >>+      OccScalar.toMaybeScalar (real x)+   fromScalar      = fromReal . OccScalar.fromScalar + {-   In this implementation the complex plane is structured   as an orthogonal grid induced by the divisor z'.@@ -545,29 +555,25 @@ -}  -{- * legacy instances -}--{-# INLINE legacyInstance #-}-legacyInstance :: a-legacyInstance =-   error "legacy Ring.C instance for simple input of numeric literals"+-- * Haskell 98 legacy instances -instance (Ring.C a, Eq a, Show a) => P.Num (T a) where+-- legacy instances for use of numeric literals in GHCi+instance (P.Floating a, Eq a) => P.Num (T a) where    {-# INLINE fromInteger #-}-   fromInteger = fromReal . fromInteger+   fromInteger n = Cons (P.fromInteger n) (P.fromInteger 0)    {-# INLINE negate #-}-   negate = negate -- for unary minus+   negate = W98.unliftF1 Additive.negate    {-# INLINE (+) #-}-   (+)    = legacyInstance+   (+)    = W98.unliftF2 (Additive.+)    {-# INLINE (*) #-}-   (*)    = legacyInstance+   (*)    = W98.unliftF2 (Ring.*)    {-# INLINE abs #-}-   abs    = legacyInstance+   abs    = W98.unliftF1 Absolute.abs    {-# INLINE signum #-}-   signum = legacyInstance+   signum = W98.unliftF1 Absolute.signum -instance (Field.C a, Eq a, Show a) => P.Fractional (T a) where+instance (P.Floating a, Eq a) => P.Fractional (T a) where    {-# INLINE fromRational #-}-   fromRational = fromRational+   fromRational x = Cons (P.fromRational x) (P.fromInteger 0)    {-# INLINE (/) #-}-   (/) = legacyInstance+   (/) = W98.unliftF2 (Field./)
src/Number/FixedPoint/Check.hs view
@@ -176,19 +176,15 @@   --- legacy instances for work with GHCi-legacyInstance :: a-legacyInstance =-   error "legacy Ring.C instance for simple input of numeric literals"-+-- legacy instances for use of numeric literals in GHCi instance P98.Num T where    fromInteger = fromInteger' defltDenominator-   negate = negate --for unary minus-   (+)    = legacyInstance-   (*)    = legacyInstance-   abs    = legacyInstance-   signum = legacyInstance+   negate = negate -- for unary minus+   (+)    = (+)+   (*)    = (*)+   abs    = abs+   signum = signum  instance P98.Fractional T where    fromRational = fromRational' defltDenominator . fromRational-   (/) = legacyInstance+   (/) = (/)
src/Number/NonNegativeChunky.hs view
@@ -24,8 +24,7 @@ import qualified Numeric.NonNegative.Class as NonNeg98  import qualified Algebra.NonNegative  as NonNeg-import qualified Algebra.Field        as Field-import qualified Algebra.Absolute         as Absolute+import qualified Algebra.Absolute     as Absolute import qualified Algebra.Ring         as Ring import qualified Algebra.Additive     as Additive import qualified Algebra.ToInteger    as ToInteger@@ -44,9 +43,10 @@  import NumericPrelude.Numeric import NumericPrelude.Base-import qualified Prelude as P98 (Num(..), Fractional(..), ) +import qualified Prelude as P98 + {- | A chunky non-negative number is a list of non-negative numbers. It represents the sum of the list elements.@@ -283,23 +283,46 @@   -{- * legacy instances -}+-- * Haskell 98 legacy instances -legacyInstance :: a-legacyInstance =-   error "legacy Ring.C instance for simple input of numeric literals"+fromChunky98_ :: (NonNeg98.C a) => Chunky98.T a -> T a+fromChunky98_ = Cons . Chunky98.toChunks -instance (Ring.C a, Eq a, Show a, NonNeg.C a) => P98.Num (T a) where-   fromInteger = fromNumber . fromInteger-   negate = Additive.negate -- for unary minus-   (+)    = legacyInstance-   (*)    = legacyInstance-   abs    = legacyInstance-   signum = legacyInstance+toChunky98_ :: (NonNeg98.C a) => T a -> Chunky98.T a+toChunky98_ = Chunky98.fromChunks . decons -instance (Field.C a, Eq a, Show a, NonNeg.C a) => P98.Fractional (T a) where-   fromRational = fromNumber . fromRational-   (/) = legacyInstance+fromNumber_ :: a -> T a+fromNumber_ = Cons . (:[])++{-# INLINE lift98_1 #-}+lift98_1 ::+   (NonNeg98.C a, NonNeg98.C b) =>+   (Chunky98.T a -> Chunky98.T b) -> T a -> T b+lift98_1 f a = fromChunky98_ (f (toChunky98_ a))++{-# INLINE lift98_2 #-}+lift98_2 ::+   (NonNeg98.C a, NonNeg98.C b, NonNeg98.C c) =>+   (Chunky98.T a -> Chunky98.T b -> Chunky98.T c) -> T a -> T b -> T c+lift98_2 f a b = fromChunky98_ (f (toChunky98_ a) (toChunky98_ b))+++{-# INLINE notImplemented #-}+notImplemented :: String -> a+notImplemented name =+   error $ "Number.NonNegativeChunky: method " ++ name ++ " cannot be implemented"++instance (NonNeg98.C a, P98.Num a) => P98.Num (T a) where+   fromInteger = fromNumber_ . P98.fromInteger+   negate = lift98_1 P98.negate+   (+)    = lift98_2 (P98.+)+   (*)    = lift98_2 (P98.*)+   abs    = lift98_1 P98.abs+   signum = lift98_1 P98.signum++instance (NonNeg98.C a, P98.Fractional a) => P98.Fractional (T a) where+   fromRational = fromNumber_ . P98.fromRational+   (/) = notImplemented "(/)"  instance (NonNeg.C a) => Mn98.Monoid (T a) where    mempty  = Monoid.idt
src/Number/PartiallyTranscendental.hs view
@@ -2,9 +2,9 @@ {- | Define Transcendental functions on arbitrary fields. These functions are defined for only a few (in most cases only one) arguments,-that's why discourage making these types instances of 'Algebra.Transcendental.C'.+that's why we discourage making these types instances of 'Algebra.Transcendental.C'. But instances of 'Algebra.Transcendental.C' can be useful when working with power series.-If you intent to work with power series with 'Rational' coefficients,+If you intend to work with power series with 'Rational' coefficients, you might consider using @MathObj.PowerSeries.T (Number.PartiallyTranscendental.T Rational)@ instead of @MathObj.PowerSeries.T Rational@. -}@@ -17,6 +17,8 @@ import qualified Algebra.Additive       as Additive -- import qualified Algebra.ZeroTestable   as ZeroTestable +import qualified MathObj.Wrapper.Haskell98 as W98+ import NumericPrelude.Numeric import NumericPrelude.Base @@ -74,18 +76,14 @@   -legacyInstance :: a-legacyInstance = error "legacy Ring instance for simple input of numeric literals"-- instance (P.Num a) => P.Num (T a) where-   fromInteger n = lift0 $ P.fromInteger n-   negate = P.negate -- for unary minus-   (+)    = legacyInstance-   (*)    = legacyInstance-   abs    = legacyInstance-   signum = legacyInstance+   fromInteger = lift0 . P.fromInteger+   negate = lift1 P.negate+   (+)    = lift2 (P.+)+   (-)    = lift2 (P.-)+   abs    = lift1 P.abs+   signum = lift1 P.signum -instance (P.Num a) => P.Fractional (T a) where+instance (P.Fractional a) => P.Fractional (T a) where    fromRational = P.fromRational-   (/) = legacyInstance+   (/) = lift2 (P./)
src/Number/Peano.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE NoImplicitPrelude #-} {- |-Copyright    :   (c) Henning Thielemann 2007+Copyright    :   (c) Henning Thielemann 2007-2012 Maintainer   :   numericprelude@henning-thielemann.de Stability    :   provisional Portability  :   portable@@ -403,9 +403,10 @@   -legacyInstance :: a-legacyInstance =-   error "legacy Ring.C instance for simple input of numeric literals"+{-# INLINE notImplemented #-}+notImplemented :: String -> a+notImplemented name =+   error $ "Number.Peano: method " ++ name ++ " cannot be implemented"  instance P98.Num T where    fromInteger = Ring.fromInteger@@ -413,8 +414,8 @@    (+) = add    (-) = sub    (*) = mul-   signum = legacyInstance-   abs = legacyInstance+   abs    = notImplemented "abs"+   signum = notImplemented "signum"  -- for use with genericLength et.al. instance P98.Real T where
src/Number/Positional/Check.hs view
@@ -237,22 +237,18 @@   --- legacy instances for work with GHCi-legacyInstance :: a-legacyInstance =-   error "legacy Ring.C instance for simple input of numeric literals"-+-- legacy instances for use of numeric literals in GHCi instance P98.Num T where    fromInteger = fromBaseInteger defltBase-   negate = negate --for unary minus-   (+)    = legacyInstance-   (*)    = legacyInstance-   abs    = legacyInstance-   signum = legacyInstance+   negate = negate -- for unary minus+   (+)    = (+)+   (*)    = (*)+   abs    = abs+   signum = signum  instance P98.Fractional T where    fromRational = fromBaseRational defltBase . fromRational-   (/) = legacyInstance+   (/) = (/)   {-
src/Number/Ratio.hs view
@@ -1,7 +1,8 @@ {-# LANGUAGE NoImplicitPrelude #-} {- | Module      :  Number.Ratio-Copyright   :  (c) Henning Thielemann, Dylan Thurston 2006+Copyright   :  (c) Henning Thielemann 2011-2012+               (c) Dylan Thurston 2006  Maintainer  :  numericprelude@henning-thielemann.de Stability   :  provisional@@ -15,6 +16,7 @@ 	  T((:%), numerator, denominator), (%),           Rational,           fromValue,+          recip,            scale,           split,@@ -24,6 +26,7 @@         )  where  import qualified Algebra.PrincipalIdealDomain as PID+import qualified Algebra.Units                as Unit import qualified Algebra.Absolute             as Absolute import qualified Algebra.Ring                 as Ring import qualified Algebra.Additive             as Additive@@ -117,7 +120,13 @@     abs (x:%y)          =  Absolute.abs x :% y     signum (x:%_)       =  Absolute.signum x :% one +recip :: (ZeroTestable.C a, Unit.C a) => T a -> T a+recip (x:%y) =+   if isZero y+     then error "Ratio.recip: division by zero"+     else (y * stdUnitInv x) :% stdAssociate x + liftOrd :: Ring.C a => (a -> a -> b) -> (T a -> T a -> b) liftOrd f (x:%y) (x':%y') = f (x * y') (x' * y) @@ -222,28 +231,54 @@  -- | Necessary when mixing NumericPrelude.Numeric Rationals with Prelude98 Rationals -toRational98 :: (P.Integral a, PID.C a) => T a -> Ratio98.Ratio a+toRational98 :: (P.Integral a) => T a -> Ratio98.Ratio a toRational98 x = numerator x Ratio98.% denominator x +fromRational98 :: (P.Integral a) => Ratio98.Ratio a -> T a+fromRational98 x = Ratio98.numerator x :% Ratio98.denominator x -legacyInstance :: String -> a-legacyInstance op =-   error ("Ratio." ++ op ++ ": legacy Ring instance for simple input of numeric literals") +{-# INLINE lift1 #-}+lift1 ::+   (P.Integral a, P.Integral b) =>+   (Ratio98.Ratio a -> Ratio98.Ratio b) -> T a -> T b+lift1 f a = fromRational98 (f (toRational98 a)) --- instance (P.Num a, PID.C a) => P.Num (T a) where-instance (P.Num a, PID.C a, Absolute.C a) => P.Num (T a) where+{-# INLINE lift2 #-}+lift2 ::+   (P.Integral a, P.Integral b, P.Integral c) =>+   (Ratio98.Ratio a -> Ratio98.Ratio b -> Ratio98.Ratio c) -> T a -> T b -> T c+lift2 f a b = fromRational98 (f (toRational98 a) (toRational98 b))+++instance (P.Integral a) => P.Num (T a) where+   fromInteger n = P.fromInteger n :% P.fromInteger 1+   negate = lift1 P.negate+   (+)    = lift2 (P.+)+   (*)    = lift2 (P.*)+   abs    = lift1 P.abs+   signum = lift1 P.signum++instance (P.Integral a) => P.Fractional (T a) where+   fromRational x =+      P.fromInteger (Ratio98.numerator x) :%+      P.fromInteger (Ratio98.denominator x)+   (/) = lift2 (P./)+   recip = lift1 P.recip++{- causes an import cycle+instance (P.Integral a) => P.Num (T a) where    fromInteger n = P.fromInteger n % 1-   negate = negate -- for unary minus-   (+)    = legacyInstance "(+)"-   (*)    = legacyInstance "(*)"-   abs    = Absolute.abs -- needed for Arbitrary instance of NonNegative.Ratio-   signum = legacyInstance "signum"+   negate = W98.unliftF1 P.negate+   (+)    = W98.unliftF2 (+)+   (*)    = W98.unliftF2 (*)+   abs    = W98.unliftF1 abs+   signum = W98.unliftF1 P.signum --- instance (P.Num a, PID.C a) => P.Fractional (T a) where-instance (P.Num a, PID.C a, Absolute.C a) => P.Fractional (T a) where+instance (P.Integral a) => P.Fractional (T a) where --   fromRational = Field.fromRational    fromRational x =       fromInteger (Ratio98.numerator x) :%       fromInteger (Ratio98.denominator x)-   (/) = legacyInstance "(/)"+   recip = recip+-}
src/Number/ResidueClass/Func.hs view
@@ -11,6 +11,9 @@ import qualified Algebra.EqualityDecision as EqDec  import Algebra.EqualityDecision ((==?), )++import qualified MathObj.Wrapper.Haskell98 as W98+ import NumericPrelude.Base import NumericPrelude.Numeric hiding (zero, one, ) @@ -82,21 +85,32 @@ But Prelude.fromInteger requires Prelude.Num instance. -} --- legacy instances for work with GHCi-legacyInstance :: a-legacyInstance =-   error "legacy Ring.C instance for simple input of numeric literals"+{-# INLINE notImplemented #-}+notImplemented :: String -> a+notImplemented name =+   error $ "ResidueClass.Func: method " ++ name ++ " cannot be implemented" -instance (P.Num a, Integral.C a) => P.Num (T a) where-   fromInteger = Number.ResidueClass.Func.fromInteger-   negate = negate --for unary minus-   (+)    = legacyInstance-   (*)    = legacyInstance-   abs    = legacyInstance-   signum = legacyInstance +lift98_1 :: (W98.T a -> W98.T a -> W98.T a) -> T a -> T a+lift98_1 f (Cons x) =+   Cons $ \m -> W98.decons $ f (W98.Cons m) (W98.Cons $ x m)++lift98_2 :: (W98.T a -> W98.T a -> W98.T a -> W98.T a) -> T a -> T a -> T a+lift98_2 f (Cons x) (Cons y) =+   Cons $ \m -> W98.decons $ f (W98.Cons m) (W98.Cons $ x m) (W98.Cons $ y m)+++-- legacy instances for use of numeric literals in GHCi+instance (P.Integral a) => P.Num (T a) where+   fromInteger = Cons . P.mod . P.fromInteger+   negate = lift98_1 Res.neg+   (+)    = lift98_2 Res.add+   (*)    = lift98_2 Res.mul+   abs    = notImplemented "abs"+   signum = notImplemented "signum"+ instance Eq (T a) where-   (==) = error "ResidueClass.Func: (==) not implemented"+   (==) = notImplemented "(==)"  instance Show (T a) where-   show = error "ResidueClass.Func: 'show' not implemented"+   show = notImplemented "show"
src/Number/SI.hs view
@@ -1,8 +1,9 @@ {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-} {- |-Copyright   :  (c) Henning Thielemann 2003-2006+Copyright   :  (c) Henning Thielemann 2003-2012 License     :  GPL  Maintainer  :  numericprelude@henning-thielemann.de@@ -40,6 +41,8 @@  import Data.Tuple.HT (mapFst, ) +import qualified MathObj.Wrapper.Haskell98 as W98+ import qualified Prelude as P  import NumericPrelude.Numeric@@ -47,9 +50,7 @@   newtype T a v = Cons (PValue v)-{- LANGUAGE GeneralizedNewtypeDeriving allows even this-   deriving (Monad, Functor)--}+   deriving (Functor)  type PValue v = Value.T Dimension v @@ -249,21 +250,14 @@   --- legacy instances for work with GHCi-legacyInstance :: a-legacyInstance =-   error "legacy Ring.C instance for simple input of numeric literals"--instance (Ord a, Trans.C a, NormedMax.C a v, P.Num v, Ring.C v) =>-      P.Num (T a v) where-   fromInteger = fromInteger-   negate = negate -- for unary minus-   (+)    = legacyInstance-   (*)    = legacyInstance-   abs    = legacyInstance-   signum = legacyInstance+instance (P.Num v) => P.Num (T a v) where+   fromInteger = fromScalarSingle . P.fromInteger+   negate = W98.unliftF1 Additive.negate+   (+)    = W98.unliftF2 (Additive.+)+   (*)    = W98.unliftF2 (Ring.*)+   abs    = W98.unliftF1 Absolute.abs+   signum = W98.unliftF1 Absolute.signum -instance (Ord a, Trans.C a, NormedMax.C a v, P.Num v, Field.C v) =>-      P.Fractional (T a v) where-   fromRational = fromRational-   (/) = legacyInstance+instance (P.Fractional v) => P.Fractional (T a v) where+   fromRational = fromScalarSingle . P.fromRational+   (/) = W98.unliftF2 (Field./)
test/Test.hs view
@@ -10,6 +10,8 @@            deca, hecto, kilo, mega, giga, tera, peta) import Number.OccasionallyScalarExpression as Expr +import qualified Number.NonNegativeChunky as Chunky+import qualified Number.NonNegative       as NonNegW import qualified Number.Positional.Check  as Absolute import qualified Number.FixedPoint.Check  as FixedPoint import qualified Number.ResidueClass.Func as ResidueClass@@ -167,6 +169,9 @@ testPeanoList :: [Char] testPeanoList =    genericTake (genericLength (repeat 'a') :: Peano.T) ['a'..'z']++testChunky :: Chunky.T NonNegW.Int+testChunky = (2+3)*(1+5)   main :: IO ()
test/Test/MathObj/Matrix.hs view
@@ -9,14 +9,13 @@  import qualified Algebra.Laws as Laws -import qualified Number.NonNegative as NonNeg- import qualified System.Random as Random  import Data.Function.HT (nest, )  import Test.NumericPrelude.Utility (testUnit, )-import Test.QuickCheck (quickCheck, )+import Test.QuickCheck (Arbitrary(arbitrary), quickCheck, )+import qualified Test.QuickCheck as QC import qualified Test.HUnit as HUnit  @@ -25,12 +24,17 @@   type Seed = Int-type Dimension = NonNeg.Int+newtype Dimension = Dimension {unDim :: Int}+   deriving (Show) +instance Arbitrary Dimension where+   arbitrary = fmap Dimension $ QC.choose (0,20)++ random :: Dimension -> Dimension -> Seed -> Matrix.T Integer random mn nn seed =    fst $-   Matrix.random (NonNeg.toNumber mn) (NonNeg.toNumber nn) $+   Matrix.random (unDim mn) (unDim nn) $    Random.mkStdGen seed  @@ -41,15 +45,15 @@    map testUnit $       ("dimension",           quickCheck (\m n a ->-             (NonNeg.toNumber m, NonNeg.toNumber n) == Matrix.dimension (random m n a))) :+             (unDim m, unDim n) == Matrix.dimension (random m n a))) :       ("to and from rows",           quickCheck (\m n a' ->              let a = random m n a'-             in  a == Matrix.fromRows (NonNeg.toNumber m) (NonNeg.toNumber n) (Matrix.rows a))) :+             in  a == Matrix.fromRows (unDim m) (unDim n) (Matrix.rows a))) :       ("to and from columns",           quickCheck (\m n a' ->              let a = random m n a'-             in  a == Matrix.fromColumns (NonNeg.toNumber m) (NonNeg.toNumber n) (Matrix.columns a))) :+             in  a == Matrix.fromColumns (unDim m) (unDim n) (Matrix.columns a))) :       ("transpose, rows, columns",           quickCheck (\m n a' ->              let a = random m n a'@@ -60,7 +64,7 @@              in  Matrix.columns a == Matrix.rows (Matrix.transpose a))) :       ("addition, zero",           quickCheck (\m n a ->-             Laws.identity (+) (Matrix.zero (NonNeg.toNumber m) (NonNeg.toNumber n)) (random m n a))) :+             Laws.identity (+) (Matrix.zero (unDim m) (unDim n)) (random m n a))) :       ("addition, commutative",           quickCheck (\m n a b ->              Laws.commutative (+) (random m n a) (random m n b))) :@@ -72,14 +76,14 @@              Laws.homomorphism Matrix.transpose (+) (+) (random m n a) (random m n b))) :       ("one, diagonal",           quickCheck (\n' ->-             let n = NonNeg.toNumber n'+             let n = unDim n'              in Matrix.one n == (Matrix.diagonal $ replicate n Ring.one :: Matrix.T Integer))) :       ("multiplication, one left",           quickCheck (\m n a ->-             Laws.leftIdentity  (*) (Matrix.one (NonNeg.toNumber m)) (random m n a))) :+             Laws.leftIdentity  (*) (Matrix.one (unDim m)) (random m n a))) :       ("multiplication, one right",           quickCheck (\m n a ->-             Laws.rightIdentity (*) (Matrix.one (NonNeg.toNumber n)) (random m n a))) :+             Laws.rightIdentity (*) (Matrix.one (unDim n)) (random m n a))) :       ("multiplication, associative",           quickCheck (\k l m n a b c ->              Laws.associative (*) (random k l a) (random l m b) (random m n c))) :@@ -96,7 +100,7 @@           quickCheck (\m a n0 ->              let x = random m m a                  n = mod n0 10-             in  x^n == nest (fromInteger n) (x*) (Matrix.one (NonNeg.toNumber m)))) :+             in  x^n == nest (fromInteger n) (x*) (Matrix.one (unDim m)))) : {-       ("division",       quickCheck (\x -> Integral.propInverse (x :: Poly.T Rational))) : -}