semirings 0.5.1 → 0.5.2
raw patch · 5 files changed
+113/−29 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Euclidean: gcdExt :: (Eq a, Euclidean a, Ring a) => a -> a -> (a, a)
+ Data.Euclidean: instance Data.Euclidean.Euclidean Data.Semiring.Mod2
+ Data.Euclidean: instance Data.Euclidean.Euclidean GHC.Int.Int16
+ Data.Euclidean: instance Data.Euclidean.Euclidean GHC.Int.Int32
+ Data.Euclidean: instance Data.Euclidean.Euclidean GHC.Int.Int64
+ Data.Euclidean: instance Data.Euclidean.Euclidean GHC.Int.Int8
+ Data.Euclidean: instance Data.Euclidean.Euclidean GHC.Word.Word16
+ Data.Euclidean: instance Data.Euclidean.Euclidean GHC.Word.Word32
+ Data.Euclidean: instance Data.Euclidean.Euclidean GHC.Word.Word64
+ Data.Euclidean: instance Data.Euclidean.Euclidean GHC.Word.Word8
+ Data.Euclidean: instance Data.Euclidean.Field Data.Semiring.Mod2
+ Data.Euclidean: instance Data.Euclidean.GcdDomain Data.Semiring.Mod2
+ Data.Euclidean: instance Data.Euclidean.GcdDomain GHC.Int.Int16
+ Data.Euclidean: instance Data.Euclidean.GcdDomain GHC.Int.Int32
+ Data.Euclidean: instance Data.Euclidean.GcdDomain GHC.Int.Int64
+ Data.Euclidean: instance Data.Euclidean.GcdDomain GHC.Int.Int8
+ Data.Euclidean: instance Data.Euclidean.GcdDomain GHC.Word.Word16
+ Data.Euclidean: instance Data.Euclidean.GcdDomain GHC.Word.Word32
+ Data.Euclidean: instance Data.Euclidean.GcdDomain GHC.Word.Word64
+ Data.Euclidean: instance Data.Euclidean.GcdDomain GHC.Word.Word8
Files
- CHANGELOG.md +37/−0
- Data/Euclidean.hs +62/−27
- Data/Field.hs +5/−0
- Data/Semiring.hs +6/−0
- semirings.cabal +3/−2
CHANGELOG.md view
@@ -1,9 +1,22 @@+0.5.2: [2019.11.01]+-------------------+* Add `gcdExt` function+* Bump upper bound on base+* Add GcdDomain/Euclidean instances for `Mod2`+* Add GcdDomain/Euclidean instances for {Int|Word}{8|16|32|64}+* Mention `RebindableSyntax` in haddocks++rev: b4334fe06635f106b1f08bac127c1ae259cddae6+ 0.5.1: [2019.09.13] ------------------- * Bump upper bound on containers to 0.7 * Bump upper bound on hashable to 1.4 * Remove redundant constraints from WrappedFractional instances+* Add lower bound on semigroups +rev: 7e6f5e312bec5495ce9390664578bfb09d6e3eb9+ 0.5: [2019.09.05] ----------------- * Add `Field` typeclass, instances, and functions.@@ -12,17 +25,23 @@ * Add `Ring` and `Bits` instances for `WrappedFractional` and `WrappedIntegral`. * Add `fromInteger` and `fromIntegral` functions for `Ring`. +rev: eb2617d93d354085fe5b706a145108d090dbc027+ 0.4.2: [2019.06.06] ------------------- * Add `GcdDomain` and `Euclidean` typeclasses. * Add `Mod2`, the integers modulo 2, along with its Semiring/Ring/Star instances. +rev: b5af2fa403c68a66a3282b2a452b9be1c98e3fd6+ 0.4.1: [2019.05.04] ------------------- * Remove unlawful and useless `Ring` instance for `GHC.Natural.Natural`. * Correct behaviour/docs of Data.Semiring.(^) +rev: d6c42aeea602499e32081e84974910d0fe955db6+ 0.4: [2019.05.01] ----------------- * Remove unlawful instances of `Ring` (thanks to @Bodigrim for noticing these)@@ -32,22 +51,30 @@ which @Bodigrim has made at http://hackage.haskell.org/package/poly. * Add isZero/isOne predicates. +rev: 1285d3e42242db310083fbf78d2e611bccecc63a+ 0.3.1.2: [2019.04.02] --------------------- * Fix build error on windows caused by providing instances to POSIX types. Thanks to @Bodigrim and @CarlEdman for reporting this. +rev: 13d4b3920912f8030b5d47777fb57b6e0dd15c10+ 0.3.1.1: [2019.01.12] --------------------- * Fix build error caused by disabling building with containers. +rev: 5f02279613bfcd20c2e9d68f01d669e563540ced+ 0.3.1.0: [2019.01.12] --------------------- * Add Data.Semiring.Tropical * Fix build problem on GHC 7.4 caused by introduction of IntSetOf/IntMapOf * Make sure there are no warnings when building with -Wall, for any GHC +rev: 68c604250e2cf5688b3c641fd40b66fe7e1d45bf+ 0.3.0.0: [2019.01.01] --------------------- * Rename the test suite to make `stack` happy.@@ -59,6 +86,8 @@ * Remove `Semiring` and `Ring` instances for `Product` and `Sum`. * Make `sum` and `product` more efficient for base>=4.7 +rev: d7d47c3db82a8e85330bb138169b9783eb346f38+ 0.2.1.1: [2018.10.01] --------------------- * Fixed build on GHC-7.4@@ -68,16 +97,22 @@ * Fixed unlawful behaviour of `[]` `Semiring` instance. * Improve performance of `^`. +rev: e9b85d8aa6a238d07a061402f0ba365190eee7aa+ 0.2.1.0: [2018.09.26] --------------------- * Removed use of DefaultSignatures * Removed free semiring +rev: 68e97e82280a50c374f50500a73222a5432cc45e+ 0.2.0.1: [2018.07.28] --------------------- * Add instances for `Op`, `Equivalence`, `Comparison`, and `Predicate` from Data.Functor.Contravariant (upcoming base 4.12.0.0) * docfix for (prod -> product, prod' -> product') change that occured in version 0.2.0.0. +rev: 60869059d2959676877c9661427814b2bafd5d97+ 0.2.0.0: [2018.07.23] --------------------- * Fixed the `Semiring` instances of `Set`, `HashSet`, `Vector`, `Storable Vector`, `Unboxed Vector`.@@ -89,6 +124,8 @@ * Add semiring instance for `Proxy` * names changed: (prod -> product, prod' -> product') * sum' and product' now use foldl' instead of foldr'++rev: b985dcf37b919facc2dfbec66ea923ca5427c9f6 0.1.2: [2018.05.04] -------------------
Data/Euclidean.hs view
@@ -16,15 +16,19 @@ , GcdDomain(..) , WrappedIntegral(..) , WrappedFractional(..)+ , gcdExt ) where import Prelude hiding (quotRem, quot, rem, divMod, div, mod, gcd, lcm, negate, (*)) import qualified Prelude as P+import Control.Exception import Data.Bits import Data.Complex+import Data.Int (Int, Int8, Int16, Int32, Int64) import Data.Maybe import Data.Ratio import Data.Semiring+import Data.Word (Word, Word8, Word16, Word32, Word64) import Foreign.C.Types import GHC.Exts import GHC.Integer.GMP.Internals@@ -144,7 +148,19 @@ coprimeIntegral :: Integral a => a -> a -> Bool coprimeIntegral x y = (odd x || odd y) && P.gcd x y == 1 --- | A 'Field' represents a+-- | Execute the extended Euclidean algorithm.+-- For elements @a@ and @b@, compute their greatest common divisor @g@+-- and the coefficient @s@ satisfying @as + bt = g@ for some @t@.+gcdExt :: (Eq a, Euclidean a, Ring a) => a -> a -> (a, a)+gcdExt = go one zero+ where+ go s s' r r'+ | r' == zero = (r, s)+ | otherwise = case quotRem r r' of+ (q, r'') -> go s' (minus s (times q s')) r' r''+{-# INLINABLE gcdExt #-}++-- | 'Field' represents a -- <https://en.wikipedia.org/wiki/Field_(mathematics) field>, -- a ring with a multiplicative inverse for any non-zero element. class (Euclidean a, Ring a) => Field a@@ -167,6 +183,16 @@ instance Field () +instance GcdDomain Mod2 where++instance Euclidean Mod2 where+ degree = const 0+ quotRem x y+ | isZero y = throw DivideByZero+ | otherwise = (x, zero)++instance Field Mod2+ -- | Wrapper around 'Integral' with 'GcdDomain' -- and 'Euclidean' instances. newtype WrappedIntegral a = WrapIntegral { unwrapIntegral :: a }@@ -202,12 +228,6 @@ lcm = P.lcm coprime = coprimeIntegral -instance Euclidean Int where- degree = P.fromIntegral . abs- quotRem = P.quotRem- quot = P.quot- rem = P.rem- instance GcdDomain Word where #if MIN_VERSION_integer_gmp(1,0,0) gcd (W# x) (W# y) = W# (gcdWord x y)@@ -217,33 +237,48 @@ lcm = P.lcm coprime = coprimeIntegral -instance Euclidean Word where- degree = P.fromIntegral- quotRem = P.quotRem- quot = P.quot- rem = P.rem- instance GcdDomain Integer where gcd = gcdInteger lcm = lcmInteger coprime = coprimeIntegral -instance Euclidean Integer where- degree = P.fromInteger . abs- quotRem = P.quotRem- quot = P.quot- rem = P.rem+#define deriveGcdDomain(ty) \+instance GcdDomain (ty) where { \+; gcd = P.gcd \+; lcm = P.lcm \+; coprime = coprimeIntegral \+} -instance GcdDomain Natural where- gcd = P.gcd- lcm = P.lcm- coprime = coprimeIntegral+deriveGcdDomain(Int8)+deriveGcdDomain(Int16)+deriveGcdDomain(Int32)+deriveGcdDomain(Int64)+deriveGcdDomain(Word8)+deriveGcdDomain(Word16)+deriveGcdDomain(Word32)+deriveGcdDomain(Word64)+deriveGcdDomain(Natural) -instance Euclidean Natural where- degree = id- quotRem = P.quotRem- quot = P.quot- rem = P.rem+#define deriveEuclidean(ty) \+instance Euclidean (ty) where { \+; degree = P.fromIntegral . abs \+; quotRem = P.quotRem \+; quot = P.quot \+; rem = P.rem \+}++deriveEuclidean(Int)+deriveEuclidean(Int8)+deriveEuclidean(Int16)+deriveEuclidean(Int32)+deriveEuclidean(Int64)+deriveEuclidean(Integer)+deriveEuclidean(Word)+deriveEuclidean(Word8)+deriveEuclidean(Word16)+deriveEuclidean(Word32)+deriveEuclidean(Word64)+deriveEuclidean(Natural) -- | Wrapper around 'Fractional' -- with trivial 'GcdDomain'
Data/Field.hs view
@@ -44,6 +44,11 @@ infixl 7 / -- | Convert from rational to field.+--+-- When @{-#@ @LANGUAGE RebindableSyntax #-}@ is enabled,+-- this function is used for desugaring rational literals (like, @2.37@).+-- This may be used to facilitate transition from 'Fractional' to 'Field',+-- because less casts are now required. fromRational :: Field a => Rational -> a fromRational x = quot (fromInteger (numerator x)) (fromInteger (denominator x)) {-# INLINE fromRational #-}
Data/Semiring.hs view
@@ -505,6 +505,12 @@ {-# INLINE minus #-} -- | Convert from integer to ring.+--+-- When @{-#@ @LANGUAGE RebindableSyntax #-}@ is enabled,+-- this function is used for desugaring integer literals.+-- This may be used to facilitate transition from 'Prelude.Num' to 'Ring':+-- no need to replace 0 and 1 with 'one' and 'zero'+-- or to cast numeric literals. fromInteger :: Ring a => Integer -> a fromInteger x | x >= 0 = fromNatural (Num.fromInteger x)
semirings.cabal view
@@ -1,6 +1,6 @@ name: semirings category: Algebra, Data, Data Structures, Math, Maths, Mathematics-version: 0.5.1+version: 0.5.2 license: BSD3 cabal-version: >= 1.10 license-file: LICENSE@@ -52,6 +52,7 @@ , GHC == 8.6.3 , GHC == 8.6.4 , GHC == 8.6.5+ , GHC == 8.8.1 source-repository head type: git@@ -113,7 +114,7 @@ exposed-modules: Data.Semiring.Generic - if flag(containers)+ if flag(containers) && impl(ghc >= 7.8) build-depends: containers >= 0.5.4 && < 0.7 if flag(hashable) && impl(ghc < 7.8)