packages feed

numeric-prelude 0.4.0.2 → 0.4.0.3

raw patch · 4 files changed

+193/−259 lines, 4 filesnew-component:exe:numeric-prelude-demonew-component:exe:numeric-prelude-gaussiannew-component:exe:numeric-prelude-test

Files

Makefile view
@@ -1,84 +1,18 @@--OBJECT_DIR    := build/$(shell uname -s)-$(shell uname -m)-INTERFACE_DIR := build/Interface--MODULES = $(wildcard src/*.hs) \-          $(wildcard src/NumericPrelude/*.hs) \-          $(wildcard src/Algebra/*.hs) \-          $(wildcard src/Algebra/NormedSpace/*.hs) \-          $(wildcard src/Number/*.hs) \-          $(wildcard src/Number/Physical/*.hs) \-          $(wildcard src/Number/DimensionTerm/*.hs) \-          $(wildcard src/Number/SI/*.hs) \-          $(wildcard src/Number/ResidueClass/*.hs) \-          $(wildcard src/Number/FixedPoint/*.hs) \-          $(wildcard src/Number/Positional/*.hs) \-          $(wildcard src/MathObj/*hs) \-          $(wildcard src/MathObj/Permutation/*.hs) \-          $(wildcard src/MathObj/Permutation/CycleList/*.hs) \-          $(wildcard src/MathObj/PowerSeries/*.hs)--GHC_OPTIONS = -Wall -odir$(OBJECT_DIR) -hidir$(INTERFACE_DIR)---# names of literate modules after removing literary information-UNLIT_MODULES = $(patsubst %.lhs, %.hs, $(patsubst %.hs, , $(MODULES)))--# names of all modules without literary information-HS_MODULES = $(patsubst %.lhs, %.hs, $(MODULES))--STDINTERFACES = base/base.haddock parsec/parsec.haddock--HADDOCK_INCL = $(patsubst %, -i /usr/local/share/ghc-6.2/html/libraries/%, \-                    $(STDINTERFACES))--HC = ghc--HCI = ghci----.INTERMEDIATE:	$(UNLIT_MODULES)--.PHONY:	all doc clean build test ghci publish--all:	build+HCI6 = ghci+HCI7 = ghci -XCPP -DNoImplicitPrelude=RebindableSyntax -clean:-	-rm `find $(OBJECT_DIR) -name "*.o"`-	-rm `find $(INTERFACE_DIR) -name "*.hi"`+.PHONY: ghci ghci6 ghci7 ghci-gauss ghci-compile -test:	build-#	$(HC) -Wall -i:$(INTERFACE_DIR) -hide-package NumericPrelude -c test/Test.hs-	$(HC) $(GHC_OPTIONS) -i:src:test --make -hide-package numeric-prelude -o testsuite test/Test/Run.hs-	./testsuite+ghci:	ghci7 -ghci:-	$(HCI) -Wall -i:src:test +RTS -M256m -c30 -RTS test/Test.hs+ghci6:+	$(HCI6) -Wall -i:src:test +RTS -M256m -c30 -RTS test/Demo.hs  ghci7:-	$(HCI) -Wall -i:src:test -XCPP -DNoImplicitPrelude=RebindableSyntax +RTS -M256m -c30 -RTS test/Test.hs+	$(HCI7) -Wall -i:src:test +RTS -M256m -c30 -RTS test/Demo.hs  ghci-gauss:-	$(HCI) -Wall -i:src:test +RTS -M256m -c30 -RTS test/Test/MathObj/Gaussian/Variance.hs+	$(HCI7) -Wall -i:src:test:gaussian +RTS -M256m -c30 -RTS test/Test/MathObj/Gaussian/Variance.hs  ghci-compile:-	$(HCI) -Wall -i:src:test +RTS -M256m -c30 -RTS -fobject-code -O -hidir=dist/build -odir=dist/build test/Test.hs--build:-	-mkdir $(OBJECT_DIR)-	$(HC) $(GHC_OPTIONS) -hide-package numeric-prelude --make -O $(MODULES)--doc:	$(HS_MODULES)-	haddock -o docs/html --dump-interface=docs/numericprelude.haddock $(HADDOCK_INCL) -h $(HS_MODULES)--%.hs:	%.lhs-	unlit $< $@--HASKELLORG_HTMLDIR = /home/darcs/numericprelude/docs/html--publish:-	scp -r dist/doc/html/* cvs.haskell.org:$(HASKELLORG_HTMLDIR)/-	#scp -r docs/html/* cvs.haskell.org:$(HASKELLORG_HTMLDIR)/-	ssh cvs.haskell.org chmod -R o+r $(HASKELLORG_HTMLDIR)-	#ssh cvs.haskell.org chmod o+x `find $(HASKELLORG_HTMLDIR) -type d`+	$(HCI7) -Wall -i:src:test +RTS -M256m -c30 -RTS -fobject-code -O -hidir=dist/build -odir=dist/build test/Demo.hs
numeric-prelude.cabal view
@@ -1,5 +1,5 @@ Name:           numeric-prelude-Version:        0.4.0.2+Version:        0.4.0.3 License:        BSD3 License-File:   LICENSE Author:         Dylan Thurston <dpt@math.harvard.edu>, Henning Thielemann <numericprelude@henning-thielemann.de>, Mikael Johansson@@ -151,7 +151,7 @@   default:     False  Source-Repository this-  Tag:         0.4.0.2+  Tag:         0.4.0.3   Type:        darcs   Location:    http://code.haskell.org/numeric-prelude/ @@ -283,10 +283,10 @@     Algebra.EqualityDecision     Algebra.OrderDecision -Executable test+Executable numeric-prelude-demo   Hs-Source-Dirs: test   GHC-Options:    -Wall-  Main-Is: Test.hs+  Main-Is: Demo.hs    If flag(buildTests)     Build-Depends:@@ -299,7 +299,7 @@     CPP-Options: -DNoImplicitPrelude=RebindableSyntax     Extensions: CPP -Executable testsuite+Executable numeric-prelude-test   Hs-Source-Dirs: test, gaussian   GHC-Options:    -Wall   Other-modules:@@ -335,7 +335,7 @@     CPP-Options: -DNoImplicitPrelude=RebindableSyntax     Extensions: CPP -Executable test-gaussian+Executable numeric-prelude-gaussian   Hs-Source-Dirs: gaussian   Main-Is: Gaussian.hs   Other-Modules:
+ test/Demo.hs view
@@ -0,0 +1,178 @@+{-# LANGUAGE NoImplicitPrelude #-}+module Main where++import Number.Complex((+:), (-:), )+import qualified Number.Complex as Complex+import Number.Physical      as Value+import Number.SI            as SIValue -- units+import Number.SI.Unit       as SIUnit  -- unit prefixes+          (pico, nano, micro, milli, centi, deci,+           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 Real+import qualified Number.FixedPoint.Check  as FixedPoint+import qualified Number.ResidueClass.Func as ResidueClass+import qualified Number.Peano             as Peano++import qualified MathObj.Polynomial          as Polynomial+import qualified MathObj.LaurentPolynomial   as LaurentPolynomial+import qualified MathObj.PowerSeries         as PowerSeries+import qualified MathObj.PowerSeries.Example as PowerSeriesExample+import qualified MathObj.PartialFraction     as PartialFraction++import qualified Algebra.PrincipalIdealDomain as PID+import qualified Algebra.Field                as Field+import qualified Algebra.ZeroTestable         as ZeroTestable+import qualified Algebra.Indexable            as Indexable++import Data.List (genericTake, genericLength)++import NumericPrelude.Base+import NumericPrelude.Numeric+++{- * Physical units -}++-- some shorthands for common usage+type SIDouble  = SIValue.T Double Double+type SIComplex = SIValue.T Double (Complex.T Double)++{- this advice seems not to be targeted to ghc's interactive mode+default (SIDouble)+-}+++++test :: [SIDouble]+test =+   let lengthScales = map (\n->10^-n*meter) [-10..6]+       areaScales = map (\n->10^-n*meter^2) [-10..6]+   in  lengthScales ++ map recip lengthScales +++       areaScales   ++ map recip areaScales +++       map ((meter*gramm/second)^-) [-5..5] +++       take 16 (iterate (10*) (10e-10*meter/gramm)) +++       [1/meter^2, 1/meter, meter, meter^2,+        second, hertz,+        meter*second, second/meter, meter/second, 1/meter/second,+        volt/meter,newton/meter,+        gramm]++testComplex :: SIComplex+testComplex = (2 :: Double) *> (SIValue.fromScalarSingle (3+:4)*milli*second)++testMagnitude :: SIDouble+testMagnitude = SIValue.lift (Value.lift Complex.magnitude) testComplex++testExpr :: Expr.T Double SIDouble+testExpr = sin (5 / (3+1) * fromValue meter)++testPrefixes :: [SIDouble]+testPrefixes =+   [pico, nano, micro, milli, centi, deci,+    deca, hecto, kilo, mega, giga, tera, peta]+++{- * Reals -}++testReal :: String+testReal = Real.defltShow (sqrt 2 + log 2 * pi)++testComplexReal :: Complex.T Real.T+testComplexReal = exp (0 +: pi) + exp (0 -: pi)++showReal :: Real.T -> String+showReal = Real.defltShow+++{- * Fixed point numbers -}++testFixedPoint :: String+testFixedPoint = FixedPoint.defltShow (sqrt 2 + log 2 * pi)++showFixedPoint :: FixedPoint.T -> String+showFixedPoint = FixedPoint.defltShow+++{- * Residue classes -}++testResidueClass :: Integer+testResidueClass = ResidueClass.concrete 7 (5*3/2)++polyResidueClass :: (ZeroTestable.C a, Field.C a) =>+   [a] -> ResidueClass.T (Polynomial.T a)+polyResidueClass = ResidueClass.fromRepresentative . polynomial++{- That's strange:+The residue class implementation should constantly compute mod+and thus should be much faster.+I assume that this is an effect of missing sharing.+The functions which represent a residue class are shared,+but not their values.++*Main> mod (3^3000000) 2 :: Integer+1+(2.47 secs, 24541080 bytes)+*Main> ResidueClass.concrete 2 (3^3000000) :: Integer+1+(7.33 secs, 515047072 bytes)+-}+++{- * Polynomials and power series -}++polynomial :: [a] -> Polynomial.T a+polynomial = Polynomial.fromCoeffs++powerSeries :: [a] -> PowerSeries.T a+powerSeries = PowerSeries.fromCoeffs++laurentPolynomial :: Int -> [a] -> LaurentPolynomial.T a+laurentPolynomial = LaurentPolynomial.fromShiftCoeffs++tanSeries :: PowerSeries.T Rational+tanSeries = powerSeries PowerSeriesExample.tan+++{- * Partial fractions -}++partialFraction :: (PID.C a, Indexable.C a) =>+   [a] -> a -> PartialFraction.T a+partialFraction = PartialFraction.fromFactoredFraction++{- |+An example from wavelet theory: lifting coefficients of the CDF wavelet family.+-}+cdfFraction :: PartialFraction.T (Polynomial.T Rational)+cdfFraction =+   partialFraction+      (map polynomial [[-4,1],[0,1],[4,1]])+      (product (map polynomial [[-2,1],[2,1]]))++{- |+The same example with different notation,+that relies on numerical literals being used for polynomials.+-}+cdfFractionNum :: PartialFraction.T (Polynomial.T Rational)+cdfFractionNum =+   let x = polynomial [0,1]+   in  partialFraction [x-4,x,x+4] ((x-2)*(x+2))+++{- * Peano numbers -}+testPeano :: Peano.T+testPeano = minimum [Peano.infinity, 2, Peano.infinity, 4]++testPeanoList :: [Char]+testPeanoList =+   genericTake (genericLength (repeat 'a') :: Peano.T) ['a'..'z']++testChunky :: Chunky.T NonNegW.Int+testChunky = (2+3)*(1+5)+++main :: IO ()+main = print test
− test/Test.hs
@@ -1,178 +0,0 @@-{-# LANGUAGE NoImplicitPrelude #-}-module Main where--import Number.Complex((+:), (-:), )-import qualified Number.Complex as Complex-import Number.Physical      as Value-import Number.SI            as SIValue -- units-import Number.SI.Unit       as SIUnit  -- unit prefixes-          (pico, nano, micro, milli, centi, deci,-           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 Real-import qualified Number.FixedPoint.Check  as FixedPoint-import qualified Number.ResidueClass.Func as ResidueClass-import qualified Number.Peano             as Peano--import qualified MathObj.Polynomial          as Polynomial-import qualified MathObj.LaurentPolynomial   as LaurentPolynomial-import qualified MathObj.PowerSeries         as PowerSeries-import qualified MathObj.PowerSeries.Example as PowerSeriesExample-import qualified MathObj.PartialFraction     as PartialFraction--import qualified Algebra.PrincipalIdealDomain as PID-import qualified Algebra.Field                as Field-import qualified Algebra.ZeroTestable         as ZeroTestable-import qualified Algebra.Indexable            as Indexable--import Data.List (genericTake, genericLength)--import NumericPrelude.Base-import NumericPrelude.Numeric---{- * Physical units -}---- some shorthands for common usage-type SIDouble  = SIValue.T Double Double-type SIComplex = SIValue.T Double (Complex.T Double)--{- this advice seems not to be targeted to ghc's interactive mode-default (SIDouble)--}-----test :: [SIDouble]-test =-   let lengthScales = map (\n->10^-n*meter) [-10..6]-       areaScales = map (\n->10^-n*meter^2) [-10..6]-   in  lengthScales ++ map recip lengthScales ++-       areaScales   ++ map recip areaScales ++-       map ((meter*gramm/second)^-) [-5..5] ++-       take 16 (iterate (10*) (10e-10*meter/gramm)) ++-       [1/meter^2, 1/meter, meter, meter^2,-        second, hertz,-        meter*second, second/meter, meter/second, 1/meter/second,-        volt/meter,newton/meter,-        gramm]--testComplex :: SIComplex-testComplex = (2 :: Double) *> (SIValue.fromScalarSingle (3+:4)*milli*second)--testMagnitude :: SIDouble-testMagnitude = SIValue.lift (Value.lift Complex.magnitude) testComplex--testExpr :: Expr.T Double SIDouble-testExpr = sin (5 / (3+1) * fromValue meter)--testPrefixes :: [SIDouble]-testPrefixes =-   [pico, nano, micro, milli, centi, deci,-    deca, hecto, kilo, mega, giga, tera, peta]---{- * Reals -}--testReal :: String-testReal = Real.defltShow (sqrt 2 + log 2 * pi)--testComplexReal :: Complex.T Real.T-testComplexReal = exp (0 +: pi) + exp (0 -: pi)--showReal :: Real.T -> String-showReal = Real.defltShow---{- * Fixed point numbers -}--testFixedPoint :: String-testFixedPoint = FixedPoint.defltShow (sqrt 2 + log 2 * pi)--showFixedPoint :: FixedPoint.T -> String-showFixedPoint = FixedPoint.defltShow---{- * Residue classes -}--testResidueClass :: Integer-testResidueClass = ResidueClass.concrete 7 (5*3/2)--polyResidueClass :: (ZeroTestable.C a, Field.C a) =>-   [a] -> ResidueClass.T (Polynomial.T a)-polyResidueClass = ResidueClass.fromRepresentative . polynomial--{- That's strange:-The residue class implementation should constantly compute mod-and thus should be much faster.-I assume that this is an effect of missing sharing.-The functions which represent a residue class are shared,-but not their values.--*Main> mod (3^3000000) 2 :: Integer-1-(2.47 secs, 24541080 bytes)-*Main> ResidueClass.concrete 2 (3^3000000) :: Integer-1-(7.33 secs, 515047072 bytes)--}---{- * Polynomials and power series -}--polynomial :: [a] -> Polynomial.T a-polynomial = Polynomial.fromCoeffs--powerSeries :: [a] -> PowerSeries.T a-powerSeries = PowerSeries.fromCoeffs--laurentPolynomial :: Int -> [a] -> LaurentPolynomial.T a-laurentPolynomial = LaurentPolynomial.fromShiftCoeffs--tanSeries :: PowerSeries.T Rational-tanSeries = powerSeries PowerSeriesExample.tan---{- * Partial fractions -}--partialFraction :: (PID.C a, Indexable.C a) =>-   [a] -> a -> PartialFraction.T a-partialFraction = PartialFraction.fromFactoredFraction--{- |-An example from wavelet theory: lifting coefficients of the CDF wavelet family.--}-cdfFraction :: PartialFraction.T (Polynomial.T Rational)-cdfFraction =-   partialFraction-      (map polynomial [[-4,1],[0,1],[4,1]])-      (product (map polynomial [[-2,1],[2,1]]))--{- |-The same example with different notation,-that relies on numerical literals being used for polynomials.--}-cdfFractionNum :: PartialFraction.T (Polynomial.T Rational)-cdfFractionNum =-   let x = polynomial [0,1]-   in  partialFraction [x-4,x,x+4] ((x-2)*(x+2))---{- * Peano numbers -}-testPeano :: Peano.T-testPeano = minimum [Peano.infinity, 2, Peano.infinity, 4]--testPeanoList :: [Char]-testPeanoList =-   genericTake (genericLength (repeat 'a') :: Peano.T) ['a'..'z']--testChunky :: Chunky.T NonNegW.Int-testChunky = (2+3)*(1+5)---main :: IO ()-main = print test