Skip to content

Commit

Permalink
Hackage release 0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
cmk committed Feb 13, 2020
1 parent 6d9267e commit 6a802df
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 111 deletions.
4 changes: 2 additions & 2 deletions rings.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
33 changes: 9 additions & 24 deletions src/Data/Algebra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
--
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
20 changes: 4 additions & 16 deletions src/Data/Algebra/Quaternion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 3 additions & 7 deletions src/Data/Semimodule/Matrix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
23 changes: 4 additions & 19 deletions src/Data/Semimodule/Transform.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 15 additions & 22 deletions src/Data/Semimodule/Vector.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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


-------------------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand Down
31 changes: 10 additions & 21 deletions src/Data/Semiring.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6a802df

Please sign in to comment.