packages feed

constructible 0.1.1 → 0.1.2

raw patch · 2 files changed

+20/−12 lines, 2 files

Files

Data/Real/Constructible.hs view
@@ -96,6 +96,13 @@ mulK (Sqrt k r) (SqrtElt a b) (SqrtElt c d) =   SqrtElt (addK k (mulK k a c) (mulK k r (mulK k b d))) (addK k (mulK k a d) (mulK k b c)) +sqK :: Field k -> Elt k -> Elt k+sqK Q a = a*a+sqK Sqrt{} SqrtZero = SqrtZero+sqK (Sqrt k r) (SqrtElt a b) =+  let c = mulK k a b+  in SqrtElt (addK k (sqK k a) (mulK k r (sqK k b))) (addK k c c)+ subK :: Field k -> Elt k -> Elt k -> Elt k subK Q a b = a - b subK k@Sqrt{} SqrtZero a = negateK k a@@ -123,7 +130,7 @@ recipK Q a = recip a recipK Sqrt{} SqrtZero = throw DivideByZero recipK (Sqrt k r) (SqrtElt a b) =-  let c = recipK k (subK k (mulK k a a) (mulK k r (mulK k b b)))+  let c = recipK k (subK k (sqK k a) (mulK k r (sqK k b)))   in SqrtElt (mulK k a c) (mulK k (negateK k b) c)  eqK :: Field k -> Elt k -> Elt k -> Bool@@ -150,8 +157,8 @@   (EQ, o) -> o   (GT, GT) -> GT   (LT, LT) -> LT-  (GT, LT) -> sgnK k (subK k (mulK k a a) (mulK k r (mulK k b b)))-  (LT, GT) -> sgnK k (subK k (mulK k r (mulK k b b)) (mulK k a a))+  (GT, LT) -> sgnK k (subK k (sqK k a) (mulK k r (sqK k b)))+  (LT, GT) -> sgnK k (subK k (mulK k r (sqK k b)) (sqK k a))  zeroK :: Field k -> Elt k zeroK Q = 0@@ -167,7 +174,7 @@ sqrtK (Sqrt k r) (SqrtElt a b)   | isZeroK k b = sqrtLift k <$> sqrtK k a <|> SqrtElt (zeroK k) <$> sqrtK k (divK k a r)   | otherwise = do-    n <- sqrtK k $ subK k (mulK k a a) (mulK k r (mulK k b b))+    n <- sqrtK k $ subK k (sqK k a) (mulK k r (sqK k b))     let half = fromRationalK k (1 % 2)         p = mulK k half (addK k a n)         q = mulK k half b@@ -228,8 +235,8 @@     where       a = subK k (mulK k a0 a1) (mulK k r (mulK k b0 b1))       b = subK k (mulK k b0 a1) (mulK k a0 b1)-      n0 = subK k (mulK k a0 a0) (mulK k r (mulK k b0 b0))-      n1 = subK k (mulK k a1 a1) (mulK k r (mulK k b1 b1))+      n0 = subK k (sqK k a0) (mulK k r (sqK k b0))+      n1 = subK k (sqK k a1) (mulK k r (sqK k b1))       x1 = e a n1 + e b n1*s       x2 = recip $ e a n0 - e b n0*s @@ -254,8 +261,8 @@ @r > 0@).  Recursively calling 'deconstruct' on all triples will yield a finite tree that terminates in 'Rational' leaves. -Note that two constructible numbers that compare as equal may-deconstruct in different ways.+Note that two irrational constructible numbers that compare as equal+may deconstruct in different ways. -} deconstruct :: Construct -> Either Rational (Construct, Construct, Construct) deconstruct (C k a) = deconstructK k a
constructible.cabal view
@@ -1,5 +1,5 @@ name:                constructible-version:             0.1.1+version:             0.1.2 synopsis:            Exact computation with constructible real numbers description:   The constructible reals are the subset of the real numbers that can@@ -14,7 +14,7 @@ copyright:           © 2013 Anders Kaseorg category:            Math build-type:          Simple-cabal-version:       >=1.8+cabal-version:       >=1.10  library   exposed-modules:     Data.Real.Constructible@@ -23,7 +23,8 @@     binary-search >=0.0,     complex-generic >=0.1,     integer-roots >=1.0-  ghc-options:       -Wall+  default-language:    Haskell2010+  ghc-options:         -Wall  source-repository head   type:                git@@ -32,4 +33,4 @@ source-repository this   type:                git   location:            https://github.com/andersk/haskell-constructible-  tag:                 0.1.0.1+  tag:                 0.1.2