Separate MultMonoid interface from MultGroup
This commit is contained in:
parent
7916e10aef
commit
95a13ffd91
|
@ -140,18 +140,18 @@ export
|
|||
Num a => Mult (Matrix m n a) (Vector n a) (Vector m a) where
|
||||
mat *. v with (viewShape mat)
|
||||
_ | Shape [m,n] = fromFunction [m]
|
||||
(\[i] => foldMap @{%search} @{Additive}
|
||||
(\j => mat !! [i,j] * v !! j) range)
|
||||
(\[i] => sum $ map (\j => mat!![i,j] * v!!j) range)
|
||||
|
||||
export
|
||||
Num a => Mult (Matrix m n a) (Matrix n p a) (Matrix m p a) where
|
||||
m1 *. m2 with (viewShape m1, viewShape m2)
|
||||
_ | (Shape [m,n], Shape [n,p]) = fromFunction [m,p]
|
||||
(\[i,j] => foldMap @{%search} @{Additive}
|
||||
(\k => m1 !! [i,k] * m2 !! [k,j]) range)
|
||||
(\[i,j] => sum $ map (\k => m1!![i,k] * m2!![k,j]) range)
|
||||
|
||||
export
|
||||
{n : _} -> Num a => MultGroup (Matrix' n a) where
|
||||
{n : _} -> Num a => MultMonoid (Matrix' n a) where
|
||||
identity = repeatDiag 1 0
|
||||
|
||||
inverse = ?matrixInverse
|
||||
|
||||
export
|
||||
{n : _} -> Neg a => Fractional a => MultGroup (Matrix' n a) where
|
||||
|
|
|
@ -21,27 +21,35 @@ Mult' : Type -> Type
|
|||
Mult' a = Mult a a a
|
||||
|
||||
|
||||
||| An interface for monoids using the `*.` operator.
|
||||
|||
|
||||
||| An instance of this interface must satisfy:
|
||||
||| * `x *. identity == x`
|
||||
||| * `identity *. x == x`
|
||||
public export
|
||||
interface Mult' a => MultMonoid a where
|
||||
identity : a
|
||||
|
||||
||| An interface for groups using the `*.` operator.
|
||||
|||
|
||||
||| An instance of this interface must satisfy:
|
||||
||| * `x *. neutral == x`
|
||||
||| * `neutral *. x == x`
|
||||
||| * `x *. inverse x == neutral`
|
||||
||| * `inverse x *. x == neutral`
|
||||
||| * `x *. inverse x == identity`
|
||||
||| * `inverse x *. x == identity`
|
||||
public export
|
||||
interface Mult' a => MultGroup a where
|
||||
identity : a
|
||||
interface MultMonoid a => MultGroup a where
|
||||
inverse : a -> a
|
||||
|
||||
|
||||
namespace Semigroup
|
||||
||| Multiplication forms a semigroup
|
||||
public export
|
||||
[MultSemigroup] Mult' a => Semigroup a where
|
||||
[Mult] Mult' a => Semigroup a where
|
||||
(<+>) = (*.)
|
||||
|
||||
namespace Monoid
|
||||
||| Multiplication with an identity element forms a monoid
|
||||
public export
|
||||
[MultMonoid] MultGroup a => Monoid a using MultSemigroup where
|
||||
[Mult] MultMonoid a => Monoid a using Semigroup.Mult where
|
||||
neutral = identity
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue