numhask 0.1.3 → 0.1.4.0
raw patch · 3 files changed
+91/−45 lines, 3 files
Files
- numhask.cabal +45/−45
- src/NumHask/Algebra/Ring.hs +22/−0
- src/NumHask/Laws.hs +24/−0
numhask.cabal view
@@ -3,74 +3,74 @@ -- see: https://github.com/sol/hpack name: numhask-version: 0.1.3+version: 0.1.4.0 synopsis: A numeric prelude description: A numeric prelude, providing a clean structure for numbers and operations that combine them. category: mathematics homepage: https://github.com/tonyday567/numhask#readme bug-reports: https://github.com/tonyday567/numhask/issues-license: BSD3-license-file: LICENSE author: Tony Day maintainer: tonyday567@gmail.com copyright: Tony Day+license: BSD3+license-file: LICENSE build-type: Simple cabal-version: >= 1.10 extra-source-files:- readme.md- stack.yaml+ readme.md+ stack.yaml source-repository head type: git location: https://github.com/tonyday567/numhask library- default-language: Haskell2010- ghc-options: -Wall hs-source-dirs:- src+ src+ default-extensions: NegativeLiterals NoImplicitPrelude OverloadedStrings UnicodeSyntax+ ghc-options: -Wall+ build-depends:+ QuickCheck >=2.8 && <3+ , protolude >=0.1 && <0.3+ , tasty+ , tasty-quickcheck+ , base >=4.7 && <4.11 exposed-modules:- NumHask.Prelude- NumHask.Examples- NumHask.Algebra- NumHask.Algebra.Additive- NumHask.Algebra.Basis- NumHask.Algebra.Distribution- NumHask.Algebra.Ring- NumHask.Algebra.Field- NumHask.Algebra.Integral- NumHask.Algebra.Magma- NumHask.Algebra.Metric- NumHask.Algebra.Module- NumHask.Algebra.Multiplicative- NumHask.Algebra.Singleton- NumHask.Laws+ NumHask.Prelude+ NumHask.Examples+ NumHask.Algebra+ NumHask.Algebra.Additive+ NumHask.Algebra.Basis+ NumHask.Algebra.Distribution+ NumHask.Algebra.Ring+ NumHask.Algebra.Field+ NumHask.Algebra.Integral+ NumHask.Algebra.Magma+ NumHask.Algebra.Metric+ NumHask.Algebra.Module+ NumHask.Algebra.Multiplicative+ NumHask.Algebra.Singleton+ NumHask.Laws other-modules:- Paths_numhask- build-depends:- QuickCheck >=2.8 && <3,- protolude >=0.1 && <0.3,- tasty,- tasty-quickcheck,- base >=4.7 && <4.11- default-extensions: NegativeLiterals NoImplicitPrelude OverloadedStrings UnicodeSyntax+ Paths_numhask+ default-language: Haskell2010 test-suite test- default-language: Haskell2010 type: exitcode-stdio-1.0- hs-source-dirs:- test main-is: test.hs- build-depends:- QuickCheck >=2.8 && <3,- protolude >=0.1 && <0.3,- tasty,- tasty-quickcheck,- base >=4.7 && <5,- QuickCheck >=2.8 && <3,- doctest,- numhask,- tasty,- tasty-quickcheck+ hs-source-dirs:+ test default-extensions: NegativeLiterals NoImplicitPrelude OverloadedStrings UnicodeSyntax+ build-depends:+ QuickCheck >=2.8 && <3+ , protolude >=0.1 && <0.3+ , tasty+ , tasty-quickcheck+ , base >=4.7 && <5+ , QuickCheck >=2.8 && <3+ , doctest+ , numhask+ , tasty+ , tasty-quickcheck+ default-language: Haskell2010
src/NumHask/Algebra/Ring.hs view
@@ -5,6 +5,8 @@ ( Semiring , Ring , CRing+ , StarSemiring(..)+ , KleeneAlgebra ) where import Data.Complex (Complex(..))@@ -75,3 +77,23 @@ instance CRing Integer instance (CRing a) => CRing (Complex a)++-- | StarSemiring+--+-- > star a = one + a `times` star a+--+class (Semiring a) => StarSemiring a where+ star :: a -> a+ star a = one + plus' a++ plus' :: a -> a+ plus' a = a `times` star a++-- | KleeneAlgebra+--+-- > a `times` x + x = a ==> star a `times` x + x = x+-- > x `times` a + x = a ==> x `times` star a + x = x+--+class (StarSemiring a, AdditiveIdempotent a) => KleeneAlgebra a++
src/NumHask/Laws.hs view
@@ -38,6 +38,9 @@ , tensorProductLaws , banachLaws , hilbertLaws+ , semiringLaws+ , ringLaws+ , starSemiringLaws ) where import NumHask.Prelude@@ -531,3 +534,24 @@ [ ( "basis divide: a ./. a ≈ singleton one" , Unary (\a -> a == singleton zero || (a ./. a) ≈ singleton one)) ]++-- | semiring+semiringLaws :: (Eq a, Semiring a) => [Law a]+semiringLaws = additiveLaws <> distributionLaws <>+ [ ( "associative: (a * b) * c = a * (b * c)"+ , Ternary (\a b c -> (a `times` b) `times` c == a `times` (b `times` c)))+ , ("left id: one * a = a", Unary (\a -> one `times` a == a))+ , ("right id: a * one = a", Unary (\a -> a `times` one == a))+ ]++-- | ring+ringLaws :: (Eq a, Ring a) => [Law a]+ringLaws = semiringLaws <> additiveGroupLaws++-- | starsemiring+starSemiringLaws :: (Eq a, StarSemiring a) => [Law a]+starSemiringLaws = semiringLaws <>+ [ ( "star law: star a == one + a `times` star a"+ , Unary (\a -> star a == one + a `times` star a))+ ]+