diff --git a/rings.cabal b/rings.cabal index 65369e6..1412e0d 100644 --- a/rings.cabal +++ b/rings.cabal @@ -15,9 +15,9 @@ extra-source-files: ChangeLog.md cabal-version: >=1.10 library - hs-source-dirs: src default-language: Haskell2010 + ghc-options: -Wall -optc-std=c99 exposed-modules: Data.Algebra @@ -51,7 +51,7 @@ library , containers >= 0.4.0 && < 0.7 , distributive >= 0.3 && < 1.0 , semigroupoids >= 5.0 && < 6.0 - , profunctors + , profunctors >= 5.0 && < 6.0 test-suite test type: exitcode-stdio-1.0 diff --git a/src/Data/Algebra.hs b/src/Data/Algebra.hs index afaaa52..7fda0e6 100644 --- a/src/Data/Algebra.hs +++ b/src/Data/Algebra.hs @@ -12,44 +12,29 @@ {-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeFamilies #-} -module Data.Algebra where -{- ( +module Data.Algebra ( (><) , (//) + , (.@.) , unit , norm , conj + , triple , reciprocal , Algebra(..) , Composition(..) , Unital(..) , Division(..) ) where --} -import safe Control.Applicative + import safe Data.Bool -import safe Data.Complex -import safe Data.Distributive -import safe Data.Fixed -import safe Data.Foldable as Foldable (fold, foldl') -import safe Data.Functor.Compose import safe Data.Functor.Rep - hiding ((//)) -import safe Data.Int import safe Data.Semifield import safe Data.Semigroup.Additive as A -import safe Data.Semigroup.Foldable as Foldable1 import safe Data.Semigroup.Multiplicative as M import safe Data.Semimodule -import safe Data.Semiring -import safe Data.Tuple -import safe Data.Word -import safe Foreign.C.Types (CFloat(..),CDouble(..)) -import safe GHC.Real hiding (Fractional(..)) -import safe Numeric.Natural +import safe Data.Semiring hiding ((//)) import safe Prelude hiding (Num(..), Fractional(..), sum, product) -import safe Test.Logic -import safe qualified Prelude as P -- | < https://en.wikipedia.org/wiki/Algebra_over_a_field#Generalization:_algebra_over_a_ring Algebra > over a semiring. -- @@ -122,8 +107,8 @@ class Algebra r a => Composition r a where -- @ 'conj' a '><' 'conj' b = 'conj' (b >< a) @ -prop_conj :: Representable f => Foldable f => Semiring b => Composition a (Rep f) => Rel a b -> f a -> f a -> b -prop_conj (~~) p q = sum $ mzipWithRep (~~) (conj (p >< q)) (conj q >< conj p) +--prop_conj :: Representable f => Foldable f => Semiring b => Composition a (Rep f) => Rel a b -> f a -> f a -> b +--prop_conj (~~) p q = sum $ mzipWithRep (~~) (conj (p >< q)) (conj q >< conj p) -- @ 'conj' a '><' 'conj' b = 'conj' (b >< a) @ conj :: Representable f => Composition r (Rep f) => f r -> f r @@ -139,8 +124,8 @@ conj = tabulate . conjugateWith . index norm :: (Representable f, Composition r (Rep f)) => f r -> r norm x = normWith $ index x -norm' :: (Representable f, Composition r (Rep f)) => f r -> f r -norm' x = x >< conj x +--norm' :: (Representable f, Composition r (Rep f)) => f r -> f r +--norm' x = x >< conj x class (Semiring r, Algebra r a) => Unital r a where unitWith :: r -> a -> r diff --git a/src/Data/Algebra/Quaternion.hs b/src/Data/Algebra/Quaternion.hs index bafeefe..2179961 100644 --- a/src/Data/Algebra/Quaternion.hs +++ b/src/Data/Algebra/Quaternion.hs @@ -16,27 +16,15 @@ module Data.Algebra.Quaternion where import safe Data.Algebra import safe Data.Distributive -import safe Data.Semifield -import safe Data.Functor.Rep import safe Data.Fixed - +import safe Data.Functor.Rep +import safe Data.Semifield +import safe Data.Semigroup.Foldable import safe Data.Semimodule import safe Data.Semimodule.Vector -import safe Data.Semimodule.Matrix -import safe Data.Semimodule.Transform import safe Data.Semiring -import safe Data.Semigroup.Foldable -import safe Data.Semigroup.Additive -import safe Data.Semigroup.Multiplicative import safe GHC.Generics hiding (Rep) - -import safe Prelude (fromInteger, fromRational) -import Prelude hiding (Num(..), Fractional(..), sum, product) -import safe qualified Prelude as N - -import safe Test.Logic - -import GHC.Real hiding (Fractional(..)) +import safe Prelude hiding (Num(..), Fractional(..), sum, product) {- need tolerances: λ> prop_conj q12 (q3 :: QuatP) diff --git a/src/Data/Semimodule/Matrix.hs b/src/Data/Semimodule/Matrix.hs index fab9f55..2cf3c82 100644 --- a/src/Data/Semimodule/Matrix.hs +++ b/src/Data/Semimodule/Matrix.hs @@ -64,20 +64,16 @@ module Data.Semimodule.Matrix ( import safe Data.Bool import safe Data.Distributive -import safe Data.Foldable as Foldable (fold, foldl') import safe Data.Functor.Compose import safe Data.Functor.Rep - -import safe Data.Semigroup.Foldable as Foldable1 +import safe Data.Semifield import safe Data.Semigroup.Additive import safe Data.Semigroup.Multiplicative -import safe Data.Semiring -import safe Data.Semifield import safe Data.Semimodule -import safe Data.Semimodule.Vector import safe Data.Semimodule.Transform +import safe Data.Semimodule.Vector +import safe Data.Semiring import safe Data.Tuple - import safe Prelude hiding (Num(..), Fractional(..), sum, negate) diff --git a/src/Data/Semimodule/Transform.hs b/src/Data/Semimodule/Transform.hs index 159a60b..6f51394 100644 --- a/src/Data/Semimodule/Transform.hs +++ b/src/Data/Semimodule/Transform.hs @@ -16,32 +16,17 @@ module Data.Semimodule.Transform where -import safe Control.Applicative import safe Control.Category (Category, (>>>)) -import safe Data.Algebra -import safe Data.Bool -import safe Data.Distributive -import safe Data.Foldable as Foldable (fold, foldl') -import safe Data.Functor.Rep import safe Data.Functor.Compose import safe Data.Functor.Product - +import safe Data.Functor.Rep import safe Data.Profunctor -import safe Data.Semifield -import safe Data.Semigroup.Foldable as Foldable1 import safe Data.Semimodule -import safe Data.Semimodule.Vector -import safe Data.Semiring -import safe Prelude hiding (Num(..), Fractional(..), negate, sum, product) -import safe qualified Prelude as P - import safe Data.Tuple (swap) +import safe Prelude hiding (Num(..), Fractional(..), negate, sum, product) import safe Test.Logic -import qualified Data.Bifunctor as B -import qualified Control.Category as C - -import safe Prelude (fromInteger, fromRational) - +import safe qualified Control.Category as C +import safe qualified Data.Bifunctor as B {- app' = app @I3 @V3 @I3 @V3 @Int diff --git a/src/Data/Semimodule/Vector.hs b/src/Data/Semimodule/Vector.hs index 1b11902..c21d7f2 100644 --- a/src/Data/Semimodule/Vector.hs +++ b/src/Data/Semimodule/Vector.hs @@ -28,22 +28,15 @@ module Data.Semimodule.Vector ( ) where import safe Control.Applicative -import safe Control.Category (Category, (>>>)) import safe Data.Algebra import safe Data.Bool import safe Data.Distributive -import safe Data.Foldable as Foldable (fold, foldl') import safe Data.Functor.Rep - -import safe Data.Profunctor import safe Data.Semifield import safe Data.Semigroup.Foldable as Foldable1 import safe Data.Semimodule import safe Data.Semiring import safe Prelude hiding (Num(..), Fractional(..), negate, sum, product) -import safe qualified Prelude as P - - ------------------------------------------------------------------------------- -- V2 @@ -167,9 +160,9 @@ instance Semiring r => Algebra r I2 where instance Semiring r => Composition r I2 where conjugateWith = id - normWith f = flip multiplyWith I21 $ \i1 i2 -> - flip multiplyWith I22 $ \j1 j2 -> - f i1 * f i2 + f j1 * f j2 + normWith f = flip multiplyWith I21 $ \ix1 ix2 -> + flip multiplyWith I22 $ \jx1 jx2 -> + f ix1 * f ix2 + f jx1 * f jx2 ------------------------------------------------------------------------------- -- V3 @@ -300,19 +293,19 @@ instance Ring r => Algebra r I3 where instance Ring r => Composition r I3 where conjugateWith = id - normWith f = flip multiplyWith' I31 $ \i1 i2 -> - flip multiplyWith' I32 $ \j1 j2 -> - flip multiplyWith' I33 $ \k1 k2 -> - f i1 * f i2 + f j1 * f j2 + f k1 * f k2 + normWith f = flip multiplyWith' I31 $ \ix1 ix2 -> + flip multiplyWith' I32 $ \jx1 jx2 -> + flip multiplyWith' I33 $ \kx1 kx2 -> + f ix1 * f ix2 + f jx1 * f jx2 + f kx1 * f kx2 where - multiplyWith' f = f' where - i31 = f I31 I31 - i32 = f I32 I32 - i33 = f I33 I33 - f' I31 = i31 - f' I32 = i32 - f' I33 = i33 + multiplyWith' f1 = f1' where + i31 = f1 I31 I31 + i32 = f1 I32 I32 + i33 = f1 I33 I33 + f1' I31 = i31 + f1' I32 = i32 + f1' I33 = i33 ------------------------------------------------------------------------------- @@ -346,7 +339,7 @@ instance Ring r => Composition r QuaternionBasis where f' I32 = negate . f $ Just I32 f' I33 = negate . f $ Just I33 - normWith f = flip multiplyWith zero $ \i1 i2 -> f i1 * conjugateWith f i2 + normWith f = flip multiplyWith zero $ \ix1 ix2 -> f ix1 * conjugateWith f ix2 instance Field r => Division r QuaternionBasis where reciprocalWith f i = conjugateWith f i / normWith f diff --git a/src/Data/Semiring.hs b/src/Data/Semiring.hs index 8fd64ed..e037b4e 100644 --- a/src/Data/Semiring.hs +++ b/src/Data/Semiring.hs @@ -31,40 +31,29 @@ module Data.Semiring ( ) where import safe Control.Applicative -import safe Control.Category ((>>>)) import safe Data.Bool -import safe Data.Ord import safe Data.Complex -import safe Data.Maybe import safe Data.Either import safe Data.Fixed -import safe Data.Foldable as Foldable (Foldable, fold, foldr', foldl') +import safe Data.Foldable as Foldable (Foldable, foldr') +import safe Data.Functor.Apply import safe Data.Group import safe Data.Int import safe Data.List.NonEmpty -import safe Data.Semigroup -import safe Data.Semigroup.Foldable as Foldable1 - +import safe Data.Maybe import safe Data.Semigroup.Additive as A +import safe Data.Semigroup.Foldable as Foldable1 import safe Data.Semigroup.Multiplicative as M - -import safe Data.Functor.Apply -import safe Data.Tuple import safe Data.Word +import safe Foreign.C.Types (CFloat(..),CDouble(..)) import safe GHC.Real hiding (Fractional(..), (^^), (^)) import safe Numeric.Natural -import safe Foreign.C.Types (CFloat(..),CDouble(..)) - -import safe Prelude ( Eq(..), Ord(..), Show, Ordering(..), Bounded(..), Applicative(..), Functor(..), Monoid(..), Semigroup(..), id, (.), ($), flip, (<$>), Integer, Float, Double) +import safe Prelude (Ord(..), Applicative(..), Functor(..), Monoid(..), Semigroup(..), id, (.), ($), Integer, Float, Double) import safe qualified Prelude as P - -import GHC.Generics (Generic) - -import qualified Data.Map as Map -import qualified Data.Set as Set -import qualified Data.IntMap as IntMap -import qualified Data.IntSet as IntSet -import qualified Data.Sequence as Seq +import safe qualified Data.IntMap as IntMap +import safe qualified Data.IntSet as IntSet +import safe qualified Data.Map as Map +import safe qualified Data.Set as Set ------------------------------------------------------------------------------- -- Presemiring