packages feed

mixed-types-num 0.5.2.0 → 0.5.3.0

raw patch · 5 files changed

+54/−72 lines, 5 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- MixedTypesNumPrelude: (~!) :: Show es => CollectErrors es p -> p
+ MixedTypesNumPrelude: clearPotentialErrors :: CN t -> CN t
+ Numeric.MixedTypes.Round: instance Numeric.MixedTypes.Round.CanDivIMod GHC.Integer.Type.Integer GHC.Real.Rational
+ Numeric.MixedTypes.Round: instance Numeric.MixedTypes.Round.CanDivIMod GHC.Integer.Type.Integer GHC.Types.Int
+ Numeric.MixedTypes.Round: instance Numeric.MixedTypes.Round.CanDivIMod GHC.Real.Rational GHC.Types.Int
+ Numeric.MixedTypes.Round: instance Numeric.MixedTypes.Round.CanDivIMod GHC.Types.Int GHC.Integer.Type.Integer
+ Numeric.MixedTypes.Round: instance Numeric.MixedTypes.Round.CanDivIMod GHC.Types.Int GHC.Real.Rational
+ Numeric.MixedTypes.Round: instance Numeric.MixedTypes.Round.CanDivIMod GHC.Types.Int GHC.Types.Int

Files

README.md view
@@ -19,7 +19,7 @@ Certain aspects are specifically tailored for interval or exact real arithmetics, including three-valued numerical comparisons and distinguishing potential and certain errors. -## Generated documentation+## Generated API documentation  See the [Hackage page](https://hackage.haskell.org/package/mixed-types-num). @@ -27,8 +27,8 @@  To replicate the examples included below, start ghci as follows: -    $ stack ghci mixed-types-num:lib-    ...> :add MixedTypesNumPrelude+    $ stack ghci mixed-types-num:lib --no-load --ghci-options MixedTypesNumPrelude+    *MixedTypesNumPrelude>  ### Main idea @@ -45,7 +45,7 @@  Operations permit operands of mixed types, types inferred bottom-up: -    ...> :t 1.5 + 1+    ...> :t 1/2     ... :: Rational      ...> :t 1.5 * (length [[]])@@ -53,18 +53,7 @@  ### Dealing with numerical errors -To avoid runtime exceptions, it is recommended to use the CN error-collecting wrapper from package collect-errors:--    ...> :t let n = cn 1 in n/(n-1)-    ... :: CN Rational--`CN` is a synonym for `CollectErrors NumErrors Rational` as defined in package [collect-errors](https://hackage.haskell.org/package/collect-errors) module [Numeric.CollectErrors](https://hackage.haskell.org/package/collect-errors).-The `CN` wrapper indicates that integer division can fail for some values:--    ...> let n = cn 1 in n/(n-1)-    {{ERROR: division by 0}}--Note that the error printed above is not an exception, but a special value.+To avoid runtime exceptions, it is recommended to use the CN error-collecting wrapper from package [collect-errors](https://hackage.haskell.org/package/collect-errors).    All arithmetic operations have been extended so that it is possible to have expressions that operate exclusively on CN-wrapped types: @@ -76,54 +65,7 @@     ...> f (cn 2)     2 % 3 -The function `hasError` from module [Numeric.CollectErrors](https://hackage.haskell.org/package/collect-errors) can be used to check whether any error occurred:--    ...> import qualified Numeric.CollectErrors as CN-    ... CN> CN.hasError (cn 1/0)-    True--    ...> CN.hasError (cn 1/1)-    False--To extract a value from the `CN` wrapper, one can use function `withErrorOrValue`:--    ...> CN.withErrorOrValue (const 0.0) id (cn 1/2)-    1 % 2--The following examples require also package [aern2-real](https://github.com/michalkonecny/aern2).-To get access to this via stack, you can start ghci eg as follows:--    $ stack ghci aern2-real:lib-    ...> :add AERN2.Real -    AERN2.Real> import MixedTypesNumPrelude--    ...> :t pi-    ...  :: CReal--    ...> :t sqrt 2-    ...  :: CReal--Harmless potential errors can be ignored using `unCN`:--    ...> sqrt (pi-pi) ? (prec 100)-    [0.0000000000000000006133173666733496325755399890... ± ~6.1332e-19 ~2^(-60)]{{POTENTIAL ERROR: out of domain: negative sqrt argument}}--    ...> unCN $ sqrt (pi-pi) ? (prec 100)-    [0.0000000000000000006133173666733496325755399890... ± ~6.1332e-19 ~2^(-60)]--If used unsafely, `unCN` will cause an exception:--    ...> unCN $ sqrt (-1) ? (prec 100)-    *** Exception: CollectErrors: {ERROR: out of domain: negative sqrt argument}--When an error is present (which can be checked using `hasError`), the function `CN.hasCertainError` can be used to further distinguish cases where the error is certain or potential:--    ...> import qualified Numeric.CollectErrors as CN-    ...> CN.hasCertainError (sqrt (-1) ? (prec 100))-    True--    ...> CN.hasCertainError (sqrt (pi-pi) ? (prec 100))-    False+Note that the errors printed above are not exceptions, but special values.  See the [collect-errors](https://hackage.haskell.org/package/collect-errors) documentation for more details.  ### The generalised power operator @@ -139,7 +81,17 @@     ...> :t (double 2)^(1/2)     ... :: Double -The following example require also package [aern2-real](https://github.com/michalkonecny/aern2).+The following examples require also package [aern2-real](https://github.com/michalkonecny/aern2).+To get access to this via stack, you can start ghci eg as follows:++    $ stack ghci aern2-real:lib --no-load --ghci-options AERN2.Real+    AERN2.Real> import MixedTypesNumPrelude++    ...> :t pi+    ...  :: CReal++    ...> :t sqrt 2+    ...  :: CReal      ...> :t 2^(1/2)     ... :: CReal
changelog.md view
@@ -1,9 +1,11 @@ # mixed-types-num change log -* v 0.5.1 2021-05-14+* v 0.5.3 2021-05-15+  * export clearPotentialErrors (from collect-errors)+* v 0.5.2 2021-05-14   * add OrdGenericBool * v 0.5.1 2021-05-12-  * if-then-else for CN-wrapped (see collect-error) condition+  * if-then-else for CN-wrapped (see collect-errors) condition   * Documentation now in README * v 0.5.0 2021-04-13   * use package collect-errors with a much simpler CN wrapper
mixed-types-num.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: fb5bb6100cd056ab9cf27256821a3654757d1aa586135f51cad76052f44a8068+-- hash: 706ae7c43a95c92f49edc1b9417240d99fbe3826dfe8b8540a08de167799715f  name:           mixed-types-num-version:        0.5.2.0+version:        0.5.3.0 synopsis:       Alternative Prelude with numeric and logic expressions typed bottom-up description:    Please see the README on GitHub at <https://github.com/michalkonecny/mixed-types-num#readme> category:       Math
src/MixedTypesNumPrelude.hs view
@@ -22,7 +22,7 @@   -- * Re-exporting Prelude, hiding the operators we are changing   module Numeric.MixedTypes.PreludeHiding,   -- * Error-collecting wrapper type-  CN, cn, unCN, (~!),+  CN, cn, unCN, clearPotentialErrors,   -- * A part of package ``convertible''   module Data.Convertible.Base,   -- * Modules with Prelude alternatives@@ -50,7 +50,7 @@ where  import Data.Ratio ((%))-import Numeric.CollectErrors (CN, cn, unCN, (~!))+import Numeric.CollectErrors (CN, cn, unCN, clearPotentialErrors) import Data.Convertible.Instances.Num() import Data.Convertible.Base import Utils.TH.DeclForTypes
src/Numeric/MixedTypes/Round.hs view
@@ -38,7 +38,7 @@ import Test.Hspec import Test.QuickCheck as QC -import Numeric.CollectErrors ( CN, cn, unCN )+import Numeric.CollectErrors ( CN ) import qualified Numeric.CollectErrors as CN  import Numeric.MixedTypes.Literals@@ -71,6 +71,20 @@   type DivIType Integer Integer = Integer   divIMod = P.divMod +instance CanDivIMod Integer Int where+  type DivIType Integer Int = Integer+  divIMod x m = divIMod x (integer m)++instance CanDivIMod Int Integer where+  type ModType Int Integer = Integer+  type DivIType Int Integer = Integer+  divIMod x m = divIMod (integer x) m++instance CanDivIMod Int Int where+  type ModType Int Int = Integer+  type DivIType Int Int = Integer+  divIMod x m = divIMod (integer x) (integer m)+ instance (CanDivIMod t1 t2, CanTestPosNeg t2) => CanDivIMod (CN t1) (CN t2) where   type DivIType (CN t1) (CN t2) = (CN (DivIType t1 t2))   type ModType (CN t1) (CN t2) = (CN (ModType t1 t2))@@ -120,6 +134,20 @@ instance CanDivIMod Rational Integer where   type DivIType Rational Integer = Integer   divIMod x m = divIMod x (rational m)++instance CanDivIMod Rational Int where+  type DivIType Rational Int = Integer+  divIMod x m = divIMod x (rational m)++instance CanDivIMod Integer Rational where+  type ModType Integer Rational = Rational+  type DivIType Integer Rational = Integer+  divIMod x m = divIMod (rational x) m++instance CanDivIMod Int Rational where+  type ModType Int Rational = Rational+  type DivIType Int Rational = Integer+  divIMod x m = divIMod (rational x) m  instance CanDivIMod Double Double where   type DivIType Double Double = Integer