packages feed

diagrams-solve 0.1.0.1 → 0.1.1

raw patch · 5 files changed

+57/−4 lines, 5 filesdep +deepseqdep +diagrams-solvedep +tastydep ~basePVP ok

version bump matches the API change (PVP)

Dependencies added: deepseq, diagrams-solve, tasty, tasty-hunit, tasty-quickcheck

Dependency ranges changed: base

API changes (from Hackage documentation)

Files

CHANGES.markdown view
@@ -1,3 +1,9 @@+* 0.1.1 (3 July 2017)++  allow base-4.10 for GHC-8.2+  some minor optimizations+  add QC tests+ * 0.1.0.1 (14 February 2016)    allow base-4.9 for GHC-8.0
LICENSE view
@@ -1,4 +1,7 @@-Copyright (c) 2015, various+Copyright (c) 2015-2016 diagrams-solve team:++  Daniel Bergey <bergey@alum.mit.edu>+  Brent Yorgey <byorgey@gmail.com>  All rights reserved. 
diagrams-solve.cabal view
@@ -1,5 +1,5 @@ name:                diagrams-solve-version:             0.1.0.1+version:             0.1.1 synopsis:            Pure Haskell solver routines used by diagrams description:         Pure Haskell solver routines used by the diagrams                      project.  Currently includes finding real roots@@ -15,7 +15,7 @@ build-type:          Simple extra-source-files:  README.markdown, CHANGES.markdown cabal-version:       >=1.10-Tested-with:         GHC == 7.4.2, GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.1+Tested-with:         GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.1, GHC == 8.2.1 Source-repository head   type:     git   location: http://github.com/diagrams/diagrams-solve.git@@ -23,6 +23,20 @@ library   exposed-modules:     Diagrams.Solve.Polynomial,                        Diagrams.Solve.Tridiagonal-  build-depends:       base >=4.5 && < 4.10+  build-depends:       base >=4.5 && < 4.11   hs-source-dirs:      src   default-language:    Haskell2010++test-suite tests+  type: exitcode-stdio-1.0+  main-is: Test.hs+  -- other-modules: Instances+  hs-source-dirs: tests+  default-language:    Haskell2010+  build-depends:       base >= 4.2 && < 4.11,+                       tasty >= 0.10 && < 0.12,+                       tasty-hunit >= 0.9.2 && < 0.10,+                       tasty-quickcheck >= 0.8 && < 0.9,+                       deepseq >= 1.3 && < 1.5,+                       diagrams-solve+
src/Diagrams/Solve/Polynomial.hs view
@@ -31,12 +31,15 @@ --   c.f. http://comments.gmane.org/gmane.comp.lang.haskell.libraries/21164 --   for discussion. "The choice in (^) and (^^) to overload on the --   power's Integral type... was a genuinely bad idea." - Edward Kmett+--+--   Note there are rewrite rules in GHC.Real to expand small exponents. (^) :: (Num a) => a -> Integer -> a (^) = (P.^)  -- | Utility function used to avoid singularities aboutZero' :: (Ord a, Num a) => a -> a -> Bool aboutZero' toler x = abs x < toler+{-# INLINE aboutZero' #-}  ------------------------------------------------------------ -- Quadratic formula@@ -69,6 +72,7 @@   | otherwise = [q/a, c/q]  where d = b^2 - 4*a*c        q = -1/2*(b + signum b * sqrt d)+{-# INLINE quadForm #-}  _quadForm_prop :: Double -> Double -> Double -> Bool _quadForm_prop a b c = all (aboutZero' 1e-10 . eval) (quadForm a b c)@@ -113,12 +117,14 @@        trig k = 2 * sqrt(-p/3) * cos(phi - k*tau/3) - b/(3*a)        cubert x | x < 0     = -((-x)**(1/3))                 | otherwise = x**(1/3)+{-# INLINE cubForm' #-}  -- | Solve the cubic equation ax^3 + bx^2 + cx + d = 0, returning a --   list of all real roots within 1e-10 tolerance --   (although currently it's closer to 1e-5) cubForm :: (Floating d, Ord d) => d -> d -> d -> d -> [d] cubForm = cubForm' 1e-10+{-# INLINE cubForm #-}  _cubForm_prop :: Double -> Double -> Double -> Double -> Bool _cubForm_prop a b c d = all (aboutZero' 1e-5 . eval) (cubForm a b c d)@@ -177,12 +183,14 @@       v' = if aboutZero' toler v then 0 else sqrt v       s1 = quadForm 1 (if q<0 then -v' else v') (z-u')       s2 = quadForm 1 (if q<0 then v' else -v') (z+u')+{-# INLINE quartForm' #-}  -- | Solve the quartic equation c4 x^4 + c3 x^3 + c2 x^2 + c1 x + c0 = 0, returning a --   list of all real roots within 1e-10 tolerance --   (although currently it's closer to 1e-5) quartForm :: (Floating d, Ord d) => d -> d -> d -> d -> d -> [d] quartForm = quartForm' 1e-10+{-# INLINE quartForm #-}  _quartForm_prop :: Double -> Double -> Double -> Double -> Double -> Bool _quartForm_prop a b c d e = all (aboutZero' 1e-5 . eval) (quartForm a b c d e)
+ tests/Test.hs view
@@ -0,0 +1,22 @@+module Main where++import Diagrams.Solve.Polynomial++import Test.Tasty (defaultMain, testGroup, TestTree)+import           Test.Tasty.QuickCheck++tests :: TestTree+tests = testGroup "Solve" [+         testProperty "solutions found satisfy quadratic equation" $+         \a b c -> let sat x =  a * x * x + b * x + c =~ 0 in all sat (quadForm a b c)+-- could verify number of solutions, but we would just duplicate the function definition+        , testProperty "solutions found satisfy cubic equation" $+         \a b c d -> let sat x =  a * x * x * x + b * x * x + c * x + d =~ (0 :: Double) in all sat (cubForm a b c d)+        ]++(=~) :: Double -> Double -> Bool+(=~) a b = abs (a - b) < 0.001+infix 4 =~++main :: IO ()+main = defaultMain tests