packages feed

cf 0.3 → 0.4

raw patch · 4 files changed

+32/−25 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Math.ContinuedFraction.Simple: digits :: CF -> [Integer]

Files

cf.cabal view
@@ -1,5 +1,5 @@ name:                cf-version:             0.3+version:             0.4 synopsis:            Exact real arithmetic using continued fractions license:             MIT    license-file:        LICENSE@@ -9,6 +9,10 @@ category:            Math build-type:          Simple cabal-version:       >=1.10+description:+            Continued fraction arithmetic using Gosper's algorithm for the+            basic operations, and Vuillemin and Lester's techniques for+            transcendental functions.  source-repository head   type: git
src/Math/ContinuedFraction.hs view
@@ -2,6 +2,10 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE TypeFamilies #-}+-- |+-- A continued fraction whose terms may be positive, negative or+-- zero. The methods in @Floating@ are supported, with the exception+-- of @asin@, @acos@ and @atan@. module Math.ContinuedFraction (   CF,   CF'(..),@@ -279,6 +283,8 @@                       d0, d1) d = (base * (n0 - d0*d), base * (n1 - d1*d),                                    d0,                 d1) +-- | Produce the (possibly infinite) decimal expansion of a continued+-- fraction cfString :: CF -> String cfString (CF []) = "Infinity" cfString cf | cf < 0 = '-' : cfString (-cf)@@ -307,6 +313,8 @@                                                           Nothing           checkValid _ = Nothing +-- | Convert a continued fraction whose terms are continued fractions+-- into an ordinary continued fraction with integer terms cfcf :: CF' CF -> CF cfcf = hom (1, 0, 0, 1) 
src/Math/ContinuedFraction/Simple.hs view
@@ -1,7 +1,9 @@+-- |+-- A "standard" continued fraction, whose terms are all either+-- positive or negative. module Math.ContinuedFraction.Simple   (     CF,-    digits,     showCF,     sqrt2,     exp1@@ -104,9 +106,11 @@                                                else                                                  bihom (bihomAbsorbY bh y) (CF (x:xs)) (CF ys) +-- | The square root of 2 sqrt2 :: CF sqrt2 = CF $ 1 : repeat 2 +-- | e exp1 :: CF exp1 = CF (2 : concatMap triple [1..])   where triple n = [1, 2 * n, 1]@@ -174,7 +178,7 @@ rationalDigits :: Rational -> [Integer] rationalDigits 0 = [] rationalDigits r = let d = num `quot` den in-                   d : rationalDigits (fromInteger 10 * (r - fromInteger d))+                   d : rationalDigits (10 * (r - fromInteger d))   where num = numerator r         den = denominator r @@ -189,7 +193,8 @@                       d0, d1) d = (10 * (n0 - d0*d), 10 * (n1 - d1*d),                                    d0,               d1) --- | Produce a decimal representation of a number+-- | Produce the (possibly infinite) decimal expansion of a continued+-- fraction showCF :: CF -> String showCF cf | cf < 0 = "-" ++ show (-cf) showCF (CF [i])   = show i
tests/Tests.hs view
@@ -1,10 +1,9 @@-{-# LANGUAGE TemplateHaskell, FlexibleInstances #-}+{-# LANGUAGE TemplateHaskell #-} module Main where  import Data.Maybe-import Data.Ratio -import Math.ContinuedFraction+import Math.ContinuedFraction.Effective import Math.ContinuedFraction.Interval  import Test.QuickCheck@@ -12,37 +11,28 @@ import Test.Framework.TH import Test.Framework.Providers.QuickCheck2 -instance Arbitrary (Extended Rational) where+instance Arbitrary Extended where   arbitrary = do     b <- arbitrary :: Gen Bool     if b then       return Infinity-    else do-      n <- choose (-10, 10)-      return $ Finite (n % 1)+    else+      fmap Finite arbitrary -instance Arbitrary (Interval Rational) where+instance Arbitrary Interval where   arbitrary = do-    (i, s) <- suchThat arbitrary (\(i,s) -> i /= s) :: Gen (Extended Rational, Extended Rational)+    (i, s) <- suchThat arbitrary (\(i,s) -> i /= s) :: Gen (Extended, Extended)     return $ Interval i s +prop_sensibleEmittable x = isJust $ existsEmittable (primitiveBound x)+  where types = x :: Integer+ prop_sensiblePrimitiveBound x = fromInteger x `elementOf` primitiveBound x   where types = x :: Integer  prop_sensibleMergeInterval a b = a `subset` ab && b `subset` ab-  where types = (a :: Interval Rational, b :: Interval Rational)+  where types = (a :: Interval, b :: Interval)         ab = a `mergeInterval` b--finitePrimitiveBounds (CF cf) = zipWith boundHom homs (map primitiveBound cf)-  where homs = scanl homAbsorb (1,0,0,1) cf--prop_primitiveBoundsContain a b = all ((Finite $ a + b) `elementOf`) $ finitePrimitiveBounds (valueToCF a + valueToCF b)-  where types = (a :: Rational, b :: Rational)--prop_sensibleEuclidean i = case existsEmittable i of-                            Just n -> i `subset` primitiveBound n-                            Nothing -> True-  where types = i :: Interval Rational  main :: IO () main = $defaultMainGenerator