packages feed

continued-fractions 0.9.1.0 → 0.9.1.1

raw patch · 2 files changed

+38/−20 lines, 2 filesdep ~basePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: base

API changes (from Hackage documentation)

- Math.ContinuedFraction: instance Functor CF
- Math.ContinuedFraction: instance Show a => Show (CF a)
+ Math.ContinuedFraction: instance [safe] Functor CF
+ Math.ContinuedFraction: instance [safe] Show a => Show (CF a)
- Math.ContinuedFraction: asGCF :: Num a => CF a -> (a, [(a, a)])
+ Math.ContinuedFraction: asGCF :: (Num a, Eq a) => CF a -> (a, [(a, a)])
- Math.ContinuedFraction: convergents :: Fractional a => CF a -> [a]
+ Math.ContinuedFraction: convergents :: (Fractional a, Eq a) => CF a -> [a]
- Math.ContinuedFraction: equiv :: Num a => [a] -> CF a -> CF a
+ Math.ContinuedFraction: equiv :: (Num a, Eq a) => [a] -> CF a -> CF a
- Math.ContinuedFraction: evenCF :: Fractional a => CF a -> CF a
+ Math.ContinuedFraction: evenCF :: (Fractional a, Eq a) => CF a -> CF a
- Math.ContinuedFraction: lentz :: Fractional a => CF a -> [a]
+ Math.ContinuedFraction: lentz :: (Fractional a, Eq a) => CF a -> [a]
- Math.ContinuedFraction: lentzWith :: Fractional a => (a -> b) -> (b -> b -> b) -> (b -> b) -> CF a -> [b]
+ Math.ContinuedFraction: lentzWith :: (Fractional a, Eq a) => (a -> b) -> (b -> b -> b) -> (b -> b) -> CF a -> [b]
- Math.ContinuedFraction: modifiedLentz :: Fractional a => a -> CF a -> [[a]]
+ Math.ContinuedFraction: modifiedLentz :: (Fractional a, Eq a) => a -> CF a -> [[a]]
- Math.ContinuedFraction: modifiedLentzWith :: Fractional a => (a -> b) -> (b -> b -> b) -> (b -> b) -> a -> CF a -> [[b]]
+ Math.ContinuedFraction: modifiedLentzWith :: (Fractional a, Eq a) => (a -> b) -> (b -> b -> b) -> (b -> b) -> a -> CF a -> [[b]]
- Math.ContinuedFraction: oddCF :: Fractional a => CF a -> CF a
+ Math.ContinuedFraction: oddCF :: (Fractional a, Eq a) => CF a -> CF a
- Math.ContinuedFraction: partitionCF :: Fractional a => CF a -> (CF a, CF a)
+ Math.ContinuedFraction: partitionCF :: (Fractional a, Eq a) => CF a -> (CF a, CF a)
- Math.ContinuedFraction: setDenominators :: Fractional a => [a] -> CF a -> CF a
+ Math.ContinuedFraction: setDenominators :: (Fractional a, Eq a) => [a] -> CF a -> CF a
- Math.ContinuedFraction: setNumerators :: Fractional a => [a] -> CF a -> CF a
+ Math.ContinuedFraction: setNumerators :: (Fractional a, Eq a) => [a] -> CF a -> CF a
- Math.ContinuedFraction: steed :: Fractional a => CF a -> [a]
+ Math.ContinuedFraction: steed :: (Fractional a, Eq a) => CF a -> [a]

Files

continued-fractions.cabal view
@@ -1,5 +1,5 @@ name:                   continued-fractions-version:                0.9.1.0+version:                0.9.1.1 stability:              provisional  cabal-version:          >= 1.6@@ -17,13 +17,18 @@  tested-with:            GHC == 6.8.3,                         GHC == 6.10.4,-                        GHC == 6.12.1, GHC == 6.12.3+                        GHC == 6.12.1, GHC == 6.12.3,+                        GHC == 7.0.4,+                        GHC == 7.2.1,+                        GHC == 7.4.1-rc1  source-repository head-  type: darcs-  location: http://code.haskell.org/~mokus/continued-fractions+  type:                 git+  location:             https://github.com/mokus0/continued-fractions.git  Library   hs-source-dirs:       src   exposed-modules:      Math.ContinuedFraction   build-depends:        base >= 3 && <5+  if impl(ghc >= 7.2)+    ghc-options:        -trust base
src/Math/ContinuedFraction.hs view
@@ -1,4 +1,8 @@ {-# LANGUAGE ParallelListComp #-}+{-# LANGUAGE CPP #-}+#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702+{-# LANGUAGE Safe #-}+#endif module Math.ContinuedFraction     ( CF     , cf, gcf@@ -34,6 +38,13 @@ -- >     = CFZero               -- eval CFZero          = 0 -- >     | CFAdd    a (CF a)    -- eval (CFAdd    b x) =      b + eval x -- >     | CFCont a a (CF a)    -- eval (CFCont a b x) = a / (b + eval x)+-- +-- Or perhaps Bill Gosper's "∞-centered" representation:+-- +-- > data CF a+-- >     = CFInfinity           -- eval CFInfinity     = ∞+-- >     | CFCont a a (CF a)    -- eval (CFCont p q x) = p + q / eval x+--   -- |A continued fraction.  Constructed by 'cf' or 'gcf'. data CF a @@ -88,7 +99,7 @@         cs = recip a : [recip (a*c) | c <- cs | a <- as]  -- |Extract all the partial numerators and partial denominators of a 'CF'.-asGCF :: Num a => CF a -> (a,[(a,a)])+asGCF :: (Num a, Eq a) => CF a -> (a,[(a,a)]) asGCF (CF  b0  cf) = (b0, [(1, b) | b <- cf]) asGCF (GCF b0 gcf) = (b0, takeWhile ((/=0).fst) gcf) @@ -101,7 +112,7 @@ -- with the corresponding element of the supplied list and transforming  -- subsequent partial numerators and denominators as necessary.  If the list -- is too short, the rest of the 'CF' will be unscaled.-equiv :: Num a => [a] -> CF a -> CF a+equiv :: (Num a, Eq a) => [a] -> CF a -> CF a equiv cs orig     = gcf b0 (zip as' bs')     where@@ -115,7 +126,7 @@ -- |Apply an equivalence transformation that sets the partial denominators  -- of a 'CF' to the specfied values.  If the input list is too short, the  -- rest of the 'CF' will be unscaled.-setDenominators :: Fractional a => [a] -> CF a -> CF a+setDenominators :: (Fractional a, Eq a) => [a] -> CF a -> CF a setDenominators denoms orig     = gcf b0 (zip as' bs')     where@@ -129,7 +140,7 @@ -- |Apply an equivalence transformation that sets the partial numerators  -- of a 'CF' to the specfied values.  If the input list is too short, the  -- rest of the 'CF' will be unscaled.-setNumerators :: Fractional a => [a] -> CF a -> CF a+setNumerators :: (Fractional a, Eq a) => [a] -> CF a -> CF a setNumerators numers orig     = gcf b0 (zip as' bs')     where@@ -143,7 +154,7 @@ -- |Computes the even and odd parts, respectively, of a 'CF'.  These are new -- 'CF's that have the even-indexed and odd-indexed convergents of the  -- original, respectively.-partitionCF :: Fractional a => CF a -> (CF a, CF a)+partitionCF :: (Fractional a, Eq a) => CF a -> (CF a, CF a) partitionCF orig = case terms of     []          -> (orig, orig)     [(a1,b1)]   -> @@ -172,12 +183,12 @@  -- |Computes the even part of a 'CF' (that is, a new 'CF' whose convergents are -- the even-indexed convergents of the original).-evenCF :: Fractional a => CF a -> CF a+evenCF :: (Fractional a, Eq a) => CF a -> CF a evenCF = fst . partitionCF  -- |Computes the odd part of a 'CF' (that is, a new 'CF' whose convergents are -- the odd-indexed convergents of the original).-oddCF :: Fractional a => CF a -> CF a+oddCF :: (Fractional a, Eq a) => CF a -> CF a oddCF = snd . partitionCF  @@ -195,7 +206,7 @@ -- B{n+1} = b{n+1}Bn + a{n+1}B{n-1} -- -- The convergents are then Xn = An/Bn-convergents :: Fractional a => CF a -> [a]+convergents :: (Fractional a, Eq a) => CF a -> [a] convergents orig = drop 1 (zipWith (/) nums denoms)     where         (b0, terms) = asGCF orig@@ -219,7 +230,7 @@ -- x{i} = x{i-1} + dx{i} --  -- The convergents are given by @scanl (+) b0 dxs@-steed :: Fractional a => CF a -> [a]+steed :: (Fractional a, Eq a) => CF a -> [a] steed (CF  b0 []) = [b0] steed (GCF b0 []) = [b0] steed (CF  0 (  a  :rest)) = map (1 /) (steed (CF  a rest))@@ -245,7 +256,7 @@ -- D{n} = 1 / (b{n} + a{n} * D{n-1}) --  -- The convergents are given by @scanl (*) b0 (zipWith (*) cs ds)@-lentz :: Fractional a => CF a -> [a]+lentz :: (Fractional a, Eq a) => CF a -> [a] lentz = lentzWith id (*) recip  -- |Evaluate the convergents of a continued fraction using Lentz's method,@@ -274,9 +285,9 @@ --  -- > signLog x = (signum x, log (abs x)) -- > addSignLog (xS,xL) (yS,yL) = (xS*yS, xL+yL)--- > negateSignLog (s,l) = (negate s, l)+-- > negateSignLog (s,l) = (s, negate l) {-# INLINE lentzWith #-}-lentzWith :: Fractional a => (a -> b) -> (b -> b -> b) -> (b -> b) -> CF a -> [b]+lentzWith :: (Fractional a, Eq a) => (a -> b) -> (b -> b -> b) -> (b -> b) -> CF a -> [b] lentzWith f op inv (CF  0 (  a  :rest)) = map inv              (lentzWith f op inv (CF  a rest)) lentzWith f op inv (GCF 0 ((a,b):rest)) = map (op (f a) . inv) (lentzWith f op inv (GCF b rest)) lentzWith f op inv c = scanl opF (f b0) (zipWith (*) cs ds)@@ -285,7 +296,8 @@        (b0, cs, ds) = lentzRecurrence c  -lentzRecurrence :: Fractional a => CF a -> (a,[a],[a])+-- precondition: b0 /= 0+lentzRecurrence :: (Fractional a, Eq a) => CF a -> (a,[a],[a]) lentzRecurrence orig      | null terms    = (b0,[],[])     | otherwise = (b0, cs, ds)@@ -304,7 +316,7 @@ --  -- Additionally splits the resulting list of convergents into sublists,  -- starting a new list every time the \'modification\' is invoked.  -modifiedLentz :: Fractional a => a -> CF a -> [[a]]+modifiedLentz :: (Fractional a, Eq a) => a -> CF a -> [[a]] modifiedLentz = modifiedLentzWith id (*) recip  -- |'modifiedLentz' with a group homomorphism (see 'lentzWith', it bears the@@ -312,7 +324,7 @@ -- and solves the same problems).  Alternatively, 'lentzWith' with the same -- modification to the recurrence as 'modifiedLentz'. {-# INLINE modifiedLentzWith #-}-modifiedLentzWith :: Fractional a => (a -> b) -> (b -> b -> b) -> (b -> b) -> a -> CF a -> [[b]]+modifiedLentzWith :: (Fractional a, Eq a) => (a -> b) -> (b -> b -> b) -> (b -> b) -> a -> CF a -> [[b]] modifiedLentzWith f op inv z (CF  0 (  a  :rest)) = map (map             inv ) (modifiedLentzWith f op inv z (CF  a rest)) modifiedLentzWith f op inv z (GCF 0 ((a,b):rest)) = map (map (op (f a) . inv)) (modifiedLentzWith f op inv z (GCF b rest)) modifiedLentzWith f op inv z orig = separate (scanl opF (False, f b0) cds)@@ -329,7 +341,8 @@         separate ((_,x):xs) = case break fst xs of             (xs, ys) -> (x:map snd xs) : separate ys -modifiedLentzRecurrence :: Fractional a => a -> CF a -> (a,[(Bool, a)],[(Bool, a)])+-- precondition: b0 /= 0+modifiedLentzRecurrence :: (Fractional a, Eq a) => a -> CF a -> (a,[(Bool, a)],[(Bool, a)]) modifiedLentzRecurrence z orig     | null terms = (b0, [], [])     | otherwise  = (b0, cs, ds)