packages feed

AERN-Real 0.9.2 → 0.9.3

raw patch · 9 files changed

+188/−26 lines, 9 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Data.Number.ER.Real: class (Fractional ra, Ord ra) => ERApprox ra
- Data.Number.ER.Real: class (ERIntApprox ra) => ERApproxElementary ra
- Data.Number.ER.Real: class (ERApprox ira) => ERIntApprox ira
- Data.Number.ER.Real: class (Fractional rb, Ord rb) => ERRealBase rb
+ Data.Number.ER.Real.Approx.Sequence: ConvergRealSeq :: (EffortIndex -> ra) -> ConvergRealSeq ra

Files

AERN-Real.cabal view
@@ -1,5 +1,5 @@ Name:           AERN-Real-Version:        0.9.2+Version:        0.9.3 Cabal-Version:  >= 1.2 Build-Type:     Simple License:        BSD3@@ -46,7 +46,11 @@     There is also some support for generic Taylor series, interval Newton method     and simple numerical integration. +Extra-source-files:+    HISTORY tests/Test1.hs+ Flag containers-in-base+    Default: False  Library   hs-source-dirs:  src
+ HISTORY view
@@ -0,0 +1,16 @@+0.9.3: 12 July 2008+    * Fixed Data.Number.ER.Real so that it is usable as a single import+      for the library and its documentation links are more useful.+    * Added a module with some tests, which can also serve as an example.+    * Improved formatting of floating point numbers.++0.9.2: 11 July 2008+    * declared dependency on haskell98 in cabal file (thanks to Don Stewart)++0.9.1: 11 July 2008+    * fixed licence specification within modules++0.9.0: 11 July 2008+    * initial release of AERN-Real+    +    
src/Data/Number/ER/Real.hs view
@@ -8,20 +8,25 @@     Stability   :  experimental     Portability :  non-portable (requires fenv.h) -    Datatypes and abstractions for approximating exact real numbers-    and a basic arithmetic over such approximations.  The design is+    This module bundles some of the most important functionality+    of the AERN-Real package.  It is intended to be imported *qualified*.++    AERN-Real provides+    datatypes and abstractions for approximating exact real numbers+    and a basic arithmetic over such approximations.  The approach is     inspired to some degree by Mueller's iRRAM and Lambov's RealLib     (both are C++ libraries for exact real arithmetic).          Abstractions are provided via 4 type classes:            * 'B.ERRealBase': abstracts floating point numbers+        (not exported here, used only internally)      -     * 'RA.ERApprox': abstracts neighbourhoods of real numbers+     * 'ERApprox': abstracts neighbourhoods of real numbers      -     * 'RA.ERIntApprox': abstracts neighbourhoods of real numbers that are known to be intervals+     * 'ERIntApprox': abstracts neighbourhoods of real numbers that are known to be intervals -     * 'RAEL.ERApproxElementary': abstracts real number approximations that support elementary operations+     * 'ERApproxElementary': abstracts real number approximations that support elementary operations      For ERRealBase we give several implementations.  The default is      an arbitrary precision floating point type that uses Double@@ -45,10 +50,8 @@ -} module Data.Number.ER.Real  (-    B.ERRealBase,-    RA.ERApprox,-    RA.ERIntApprox,-    RAEL.ERApproxElementary,+    module Data.Number.ER.Real.Approx,+    module Data.Number.ER.Real.Approx.Elementary,     module Data.Number.ER.Real.DefaultRepr,     module Data.Number.ER.Real.Approx.Sequence,     module Data.Number.ER.Real.Arithmetic.Taylor,@@ -61,8 +64,8 @@ import Data.Number.ER.Real.DefaultRepr import Data.Number.ER.BasicTypes import qualified Data.Number.ER.Real.Base as B-import qualified Data.Number.ER.Real.Approx as RA-import qualified Data.Number.ER.Real.Approx.Elementary as RAEL+import Data.Number.ER.Real.Approx+import Data.Number.ER.Real.Approx.Elementary import Data.Number.ER.Real.Approx.Sequence import Data.Number.ER.Real.Arithmetic.Taylor import Data.Number.ER.Real.Arithmetic.Newton
src/Data/Number/ER/Real/Approx.hs view
@@ -279,7 +279,7 @@     This produces a function that computes the maximal extension of the     given function.  A maximal extension function has the property:     f(I) = { f(x) | x in I }.  Here we get this property only for the-    limit function for ix tending to infinity.+    limit function for its 'EffortIndex' tending to infinity. -} maxExtensionR2R ::     (ERIntApprox ira) =>
src/Data/Number/ER/Real/Approx/Interval.hs view
@@ -305,7 +305,7 @@          instance (B.ERRealBase b) => Show (ERInterval b)      where-    show = erintvShow 6 True False+    show = erintvShow 16 True False      erintvShow numDigits showGran showComponents interval =     showERI interval
src/Data/Number/ER/Real/Approx/Sequence.hs view
@@ -13,7 +13,7 @@ -} module Data.Number.ER.Real.Approx.Sequence  (-    ConvergRealSeq,+    ConvergRealSeq(..),     makeFastConvergRealSeq,     convertFuncRA2Seq,     convertBinFuncRA2Seq,@@ -41,7 +41,7 @@  convergRealSeqElem :: (ConvergRealSeq ra) -> EffortIndex -> ra convergRealSeqElem (ConvergRealSeq sq) ix = sq ix-+         {-|      Using this operator, a unary funtion working over     approximations can be converted to one that works@@ -108,7 +108,7 @@  instance (RA.ERApprox ra) => Show (ConvergRealSeq ra)      where-    show = showConvergRealSeq 6 True True 10 -- cheating here, should throw an error+    show = showConvergRealSeq 6 True False 10 -- cheating here, should throw an error   {-|@@ -138,7 +138,7 @@     -> (ConvergRealSeq ra)     -> String showConvergRealSeqAuto numDigits argSeq =-    showConvergRealSeq numDigits True True prec argSeq+    showConvergRealSeq numDigits True False prec argSeq     where     prec = effIx2prec $ ceiling $ (fromInteger $ toInteger numDigits) * 3.3219280948873626 
src/Data/Number/ER/Real/Arithmetic/Integration.hs view
@@ -80,7 +80,7 @@     sum rectangleAreas     where     rectangleAreas = -        getRs ix a b+        getRs 10 a b     getRs subix l r         | RA.getPrecision area >= prec = [area]         | otherwise =
src/Data/Number/ER/Real/Base/Float.hs view
@@ -223,9 +223,9 @@             | showComponents = "{val="++ show (s,m,e) ++ "}"             | otherwise = ""         decimal = -            show s +            (case s of Plus -> ""; Minus -> "-")             ++ show digit1 ++ "." ++ (concat $ map show $ take numDigits digits)-            ++ "E" ++ show dexp+            ++ (if dexp == 0 then "" else "e" ++ show dexp)         dexp = dexpBound - zerosCount         digit1 : digits =             drop zerosCount preDigits@@ -233,12 +233,13 @@             | e > 0 = intLog 10 (2^e)             | e <= 0 = 2 - (intLog 10 (2^(-e)))         (zerosCount, preDigits) =-            getDigits 0 $ (abs $ setERFloatGranularity numBinDigits f) / (ten ^^ dexpBound)-        ten = setERFloatGranularity numBinDigits 10-        numBinDigits = 4 * numDigits+            getDigits 0 $ (abs $ setERFloatGranularity gran f) / (ten ^^ dexpBound)+        ten = setERFloatGranularity gran 10+        gran = 10 + (max (4 * numDigits) gr)         getDigits prevZeros ff -            | digit == 0 = (zerosCount, digit : digits)-            | otherwise = (prevZeros, digit : digits)+            | digit > 0 = (prevZeros, digit : digits)+            | zerosCount == 1 = (0, (digit : digits))+            | otherwise = (zerosCount, digit : digits)             where             digit :: Integer             digit = truncate ff
+ tests/Test1.hs view
@@ -0,0 +1,138 @@+{-| +    Module      :  Main+    Description :  simple examples of using AERN-Real+    Copyright   :  (c) Michal Konecny+    License     :  BSD3++    Maintainer  :  mik@konecny.aow.cz+    Stability   :  experimental+    Portability :  portable++    Simple examples of using AERN-Real+-}+module Main where++import qualified Data.Number.ER.Real as AERN+import Data.Number.ER.Real (RA, IRA, ConvergRealSeq(..), convertFuncRA2Seq)++type R = ConvergRealSeq IRA++one :: R+one = 1++two :: R+two = 2++piSeq :: R+piSeq = ConvergRealSeq $ AERN.pi++seqExp = convertFuncRA2Seq $ AERN.exp+seqSine = convertFuncRA2Seq $ AERN.sin+seqCosine = convertFuncRA2Seq $ AERN.cos++main = +    do+    AERN.initMachineDouble+    putStrLn "****************************"+    putStrLn "Testing interval arithmetic:"+    putStrLn "****************************"+    putStrLn "**** Fractions:"+    putStrLn $+        "(default granularity, show internals) 1/3 =\n  " ++ +        AERN.showApprox 30 True True (1/3 :: RA) +    putStrLn $+        "(granularity 50, show internals) 1/3 =\n  " ++ +        AERN.showApprox 30 True True ((AERN.setGranularity 50 1/3) :: RA) +    putStrLn $+        "(granularity 100, show internals) 1/3 =\n  " ++ +        AERN.showApprox 40 True True ((AERN.setGranularity 100 1/3) :: RA) +    putStrLn $+        "(granularity 100, do not show internals) 1/3 =\n  " ++ +        AERN.showApprox 40 True False ((AERN.setGranularity 100 1/3) :: RA) +    putStrLn $+        "(granularity 100, default show) 1/3 =\n  " ++ +        show ((AERN.setGranularity 100 1/3) :: RA) +    putStrLn "**** Exp:"+    putStrLn $ +        "(effort 5, granularity 50) exp 1 =\n  " ++ +        (show $ AERN.exp 5 (AERN.setGranularity 50 (1::RA)))+    putStrLn $ +        "(effort 10, granularity 50) exp 1 =\n  " ++ +        (show $ AERN.exp 10 (AERN.setGranularity 50 (1::RA)))+    putStrLn $+        "(effort 10, granularity 100) exp 1 =\n  " ++ +        (show $ AERN.exp 10 (AERN.setGranularity 100 (1::RA)))+    putStrLn $ +        "(effort 20, granularity 50) exp 1 =\n  " ++ +        (show $ AERN.exp 20 (AERN.setGranularity 50 (1::RA)))+    putStrLn $+        "(effort 20, granularity 100) exp 1 =\n  " ++ +        (show $ AERN.exp 20 (AERN.setGranularity 100 (1::RA)))+    putStrLn "**** Pi:"+    putStrLn $ +        "(effort 10) pi =\n  " ++ +        (show $ (AERN.pi 10 :: RA))+    putStrLn $ +        "(effort 50) pi =\n  " ++ +        (AERN.showApprox 20 True False $ (AERN.pi 50 :: RA))+    putStrLn $ +        "(effort 100) pi =\n  " ++ +        (AERN.showApprox 35 True False $ (AERN.pi 100 :: RA))+    putStrLn $ +        "(effort 200) pi =\n  " ++ +        (AERN.showApprox 65 True False $ (AERN.pi 200 :: RA))+    putStrLn $ +        "(effort 400) pi =\n  " ++ +        (AERN.showApprox 125 True False $ (AERN.pi 400 :: RA))+    putStrLn "**** Sine:"+    putStrLn $+        "(effort 10, granularity 50) sin 1 =\n  " ++ +        (show $ AERN.sin 10 (AERN.setGranularity 50 (1::RA)))+    putStrLn $+        "(effort 10, granularity 100) sin 1 =\n  " ++ +        (show $ AERN.sin 10 (AERN.setGranularity 100 (1::RA)))+    putStrLn "**** Integration:"+    putStrLn $ +        "(effort 10, granularity 50) integrate exp 0 1 =\n  " ++ +        (show $ AERN.integrateContAdapt_R AERN.exp 10 0 (AERN.setGranularity 50 (1::RA)))+    putStrLn $ +        "(effort 20, granularity 50) integrate exp 0 1 =\n  " ++ +        (show $ AERN.integrateContAdapt_R AERN.exp 20 0 (AERN.setGranularity 50 (1::RA)))+--    putStrLn $ +--        "(effort 30, granularity 50) integrate exp 0 1 =\n  " ++ +--        (show $ AERN.integrateContAdapt_R AERN.exp 30 0 (AERN.setGranularity 50 (1::RA)))+    putStrLn "*****************************"+    putStrLn "Testing convergent sequences:"+    putStrLn "*****************************"+--    putStrLn $ "1 =\n  " ++ show one+--    putStrLn $ "1 + 2 =\n  " ++ (show $ one + two)+    putStrLn "**** Fractions:"+    putStrLn $ +        "(precision 20) 1/3 =\n  " ++ +        (AERN.showConvergRealSeqAuto 20 $ one / 3)+    putStrLn $ +        "(precision 20) 100000000001/300000000000 =\n  " ++ +        (AERN.showConvergRealSeqAuto 20 $ (one + 100000000000)/300000000000 )+    putStrLn $ +        "100000000001/300000000000 =? 1/3:\n  " ++ +        (show $ one/3 == 100000000001/300000000000)+--    putStrLn $ "abs -1 = " ++ (show $ abs (- one))+--    putStrLn $ "neg 2 = " ++ (show $ negate two)+--    putStrLn $ "1 + 2 = " ++ (show $ one + 2)+    putStrLn "**** Elementary:"+    putStrLn $ +        "(precision 30) exp 1 =\n  " ++ +        (AERN.showConvergRealSeqAuto 30 $ seqExp one)+    putStrLn $ +        "(precision 500) pi =\n  " ++ +        (AERN.showConvergRealSeqAuto 500 $ piSeq)+    putStrLn $ +        "(precision 30) cosine(1) =\n  " ++ +        (AERN.showConvergRealSeqAuto 30 $ seqCosine one)    +    putStrLn $+        "(precision 30) sine(1) =\n  " ++ +        (AERN.showConvergRealSeqAuto 30 $ seqSine one)+    putStrLn "**** Integration:"+    putStrLn $ -- very slow for precision > 4+        "(precision 3) integrate exp 0 1 =\n  " ++ +        (AERN.showConvergRealSeqAuto 3 $ AERN.integrateCont AERN.exp 0 one)