continued-fraction 0.1.0.3 → 0.1.0.4
raw patch · 7 files changed
+24/−52 lines, 7 filesdep −freePVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
Dependencies removed: free
API changes (from Hackage documentation)
+ Num.ContinuedFraction: prettyFrac :: (Show a) => NonEmpty a -> String
+ Num.ContinuedFraction: prettyFracM :: (Show a) => [a] -> Maybe String
Files
- .travis.yml +0/−21
- Justfile +0/−13
- README.md +2/−1
- cabal.project.local +2/−1
- continued-fraction.cabal +4/−7
- src/Num/ContinuedFraction.hs +15/−8
- stack.yaml +1/−1
− .travis.yml
@@ -1,21 +0,0 @@-sudo: false-language: default-cache:- directories:- - $HOME/.stack-addons:- apt:- packages:- - libgmp3-dev-before_install:-- mkdir -p ~/.local/bin-- export PATH=$HOME/.local/bin:$PATH-- travis_retry curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'-- chmod a+x ~/.local/bin/stack-install:-- stack --no-terminal --install-ghc test --only-dependencies-- stack install hlint weeder-script:-- stack --no-terminal test --bench --haddock --no-haddock-deps-- hlint .-- weeder .
− Justfile
@@ -1,13 +0,0 @@-test: build- cabal new-test--build:- cabal new-build--bench: build- cabal new-bench- $(fd 'fractions-bench$' | tail -n1)--docs:- cabal new-haddock- firefox-trunk $(fd '^index.html')
README.md view
@@ -1,7 +1,8 @@ # continued-fraction This is a library for working with continued fractions and rational-approximations in Haskell.+approximations in Haskell. You can find documentation+[here](https://hackage.haskell.org/package/continued-fraction). ## The pitch
cabal.project.local view
@@ -1,4 +1,5 @@ documentation: True haddock-hoogle: True haddock-internal: True-optimization: 2+optimization: 1+with-compiler: ghc-8.2.2
continued-fraction.cabal view
@@ -1,5 +1,5 @@ name: continued-fraction-version: 0.1.0.3+version: 0.1.0.4 synopsis: Types and functions for working with continued fractions in Haskell description: This package provides facilities for working with both continued fractions and rational approximants. It uses lists internally, so it will probably@@ -12,12 +12,10 @@ copyright: Copyright: (c) 2017 Vanessa McHale category: Math build-type: Simple-extra-source-files: README.md- , stack.yaml- , .travis.yml- , Justfile+extra-doc-files: README.md+extra-source-files: stack.yaml , cabal.project.local-cabal-version: >=1.10+cabal-version: >=1.18 Flag development { Description: Enable `-Werror`@@ -30,7 +28,6 @@ exposed-modules: Num.ContinuedFraction build-depends: base >= 4.9 && < 5 , recursion-schemes >= 5.0- , free default-language: Haskell2010 if flag(development) ghc-options: -Werror
src/Num/ContinuedFraction.hs view
@@ -5,9 +5,13 @@ -- * Rational approximations using continued fractions , approximate , convergent+ -- * Pretty-printer for continued fractions+ , prettyFrac+ , prettyFracM ) where import Data.Functor.Foldable (ListF (..), apo)+import Data.List (intersperse) import Data.List.NonEmpty (NonEmpty (..), fromList) import Data.Maybe (fromJust) import Data.Ratio (Ratio, denominator, (%))@@ -36,6 +40,17 @@ where alpha = 1 / (x - realToFrac (floor x :: Integer)) go = Cons (floor x) +prettyFrac :: (Show a) => NonEmpty a -> String+prettyFrac (x :| xs) = "[" ++ show x ++ "; " ++ mconcat (intersperse ", " (show <$> xs)) ++ "]"++-- | Print a list as a continued fraction.+--+-- >>> prettyFracM (take 5 $ continuedFraction (sqrt 2))+-- "[1; 2, 2, 2, 2]"+prettyFracM :: (Show a) => [a] -> Maybe String+prettyFracM [] = Nothing+prettyFracM (x:xs) = Just (prettyFrac (x :| xs))+ -- | This takes a list of integers and returns the corresponding rational number, returning "Nothing" on empty lists. -- -- >>> collapseFractionM []@@ -47,13 +62,6 @@ collapseFractionM [x] = Just $ fromIntegral x % 1 collapseFractionM (x:xs) = fmap ((fromIntegral x % 1 +) . (1 /)) (collapseFractionM xs) -{-collapseFractionH :: (Integral a) => [Integer] -> (Ratio a)-collapseFractionH = histo algebra- where- algebra Nil = 1 % 1- algebra (Cons x (_:<Nil)) = fromIntegral x % 1- algebra (Cons x (_:<Cons _ (x':<_))) = ((fromIntegral x) % 1) * (numerator x' % denominator x')-}- -- | Take a non-empty list of integers and return the corresponding rational number. -- -- >>> collapseFraction (1 :| [2,2,2])@@ -69,7 +77,6 @@ convergent :: (RealFrac a, Integral b) => Int -> a -> Ratio b convergent n x = fromJust . collapseFractionM $ take n (continuedFraction x) --- FIXME this should be intelligent enough to do some sort of caching. -- | Find the best rational approximation to a number such that the denominator is bounded by a given value. -- -- >>> approximate pi 100
stack.yaml view
@@ -1,4 +1,4 @@-resolver: lts-9.10+resolver: lts-10.2 packages: - '.' extra-deps: