| Copyright | (c) Ivan Perez and Manuel Bärenz |
|---|---|
| License | See the LICENSE file in the distribution. |
| Maintainer | ivan.perez@keera.co.uk |
| Stability | provisional |
| Portability | non-portable (GHC extensions) |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.VectorSpace
Contents
Description
Vector space type relation and basic instances.
Heavily inspired by Yampa's FRP.Yampa.VectorSpace module.
Synopsis
- class Num (Groundring v) => RModule v where
- type Groundring v
- zeroVector :: v
- (*^) :: Groundring v -> v -> v
- (^*) :: v -> Groundring v -> v
- negateVector :: v -> v
- (^+^) :: v -> v -> v
- (^-^) :: v -> v -> v
- class (Fractional (Groundring v), RModule v) => VectorSpace v where
- (^/) :: v -> Groundfield v -> v
- type Groundfield v = Groundring v
- class RModule v => InnerProductSpace v where
- dot :: v -> v -> Groundfield v
- class (Floating (Groundfield v), InnerProductSpace v, VectorSpace v) => NormedSpace v where
- norm :: v -> Groundfield v
- normalize :: (Eq (Groundfield v), NormedSpace v) => v -> v
- break3Tuple :: (a, b, c) -> ((a, b), c)
- join3Tuple :: ((a, b), c) -> (a, b, c)
- break4Tuple :: (a, b, c, d) -> ((a, b), (c, d))
- join4Tuple :: ((a, b), (c, d)) -> (a, b, c, d)
- break5Tuple :: (a, b, c, d, e) -> ((a, b), (c, d, e))
- join5Tuple :: ((a, b), (c, d, e)) -> (a, b, c, d, e)
- newtype FractionalVectorSpace a = FractionalVectorSpace {
- getFractional :: a
Vector space classes
class Num (Groundring v) => RModule v where #
R-modules.
A module v over a ring Groundring v
is an abelian group with a linear multiplication.
The hat ^ denotes the side of an operation
on which the vector stands,
i.e. a *^ v for v a vector.
A minimal definition should include the type Groundring and the
implementations of zeroVector, ^+^, and one of *^ or ^*.
The following laws must be satisfied:
v1 ^+^ v2 == v2 ^+^ v1
a *^ zeroVector == zeroVector
- @a *^ (v1 ^+^ v2) == a *^ v1 ^+^ a*^ v2
a *^ v == v ^* a
negateVector v == (-1) *^ v
v1 ^-^ v2 == v1 ^+^ negateVector v2
Minimal complete definition
Associated Types
type Groundring v #
Methods
zeroVector :: v #
(*^) :: Groundring v -> v -> v infixr 6 #
(^*) :: v -> Groundring v -> v #
negateVector :: v -> v #
Instances
| RModule Double # | |
Defined in Data.VectorSpace Associated Types type Groundring Double :: Type # | |
| RModule Float # | |
| RModule Int # | |
| RModule Integer # | |
Defined in Data.VectorSpace Associated Types type Groundring Integer :: Type # | |
| Num a => RModule (FractionalVectorSpace a) # | |
Defined in Data.VectorSpace Associated Types type Groundring (FractionalVectorSpace a) :: Type # Methods zeroVector :: FractionalVectorSpace a # (*^) :: Groundring (FractionalVectorSpace a) -> FractionalVectorSpace a -> FractionalVectorSpace a # (^*) :: FractionalVectorSpace a -> Groundring (FractionalVectorSpace a) -> FractionalVectorSpace a # negateVector :: FractionalVectorSpace a -> FractionalVectorSpace a # (^+^) :: FractionalVectorSpace a -> FractionalVectorSpace a -> FractionalVectorSpace a # (^-^) :: FractionalVectorSpace a -> FractionalVectorSpace a -> FractionalVectorSpace a # | |
| (Groundring a ~ Groundring b, RModule a, RModule b) => RModule (a, b) # | |
Defined in Data.VectorSpace Associated Types type Groundring (a, b) :: Type # Methods zeroVector :: (a, b) # (*^) :: Groundring (a, b) -> (a, b) -> (a, b) # (^*) :: (a, b) -> Groundring (a, b) -> (a, b) # negateVector :: (a, b) -> (a, b) # | |
| (Groundring a ~ Groundring b, Groundring a ~ Groundring c, RModule a, RModule b, RModule c) => RModule (a, b, c) # | |
Defined in Data.VectorSpace Associated Types type Groundring (a, b, c) :: Type # Methods zeroVector :: (a, b, c) # (*^) :: Groundring (a, b, c) -> (a, b, c) -> (a, b, c) # (^*) :: (a, b, c) -> Groundring (a, b, c) -> (a, b, c) # negateVector :: (a, b, c) -> (a, b, c) # | |
| (Monad m, RModule v) => RModule (MSF m a v) # | R-module instance for |
Defined in Data.MonadicStreamFunction.Instances.VectorSpace Associated Types type Groundring (MSF m a v) :: Type # | |
| (Groundring a ~ Groundring b, Groundring a ~ Groundring c, Groundring a ~ Groundring d, RModule a, RModule b, RModule c, RModule d) => RModule (a, b, c, d) # | |
Defined in Data.VectorSpace Associated Types type Groundring (a, b, c, d) :: Type # Methods zeroVector :: (a, b, c, d) # (*^) :: Groundring (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) # (^*) :: (a, b, c, d) -> Groundring (a, b, c, d) -> (a, b, c, d) # negateVector :: (a, b, c, d) -> (a, b, c, d) # | |
| (Groundring a ~ Groundring b, Groundring a ~ Groundring c, Groundring a ~ Groundring d, Groundring a ~ Groundring e, RModule a, RModule b, RModule c, RModule d, RModule e) => RModule (a, b, c, d, e) # | |
Defined in Data.VectorSpace Associated Types type Groundring (a, b, c, d, e) :: Type # Methods zeroVector :: (a, b, c, d, e) # (*^) :: Groundring (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) # (^*) :: (a, b, c, d, e) -> Groundring (a, b, c, d, e) -> (a, b, c, d, e) # negateVector :: (a, b, c, d, e) -> (a, b, c, d, e) # (^+^) :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) # (^-^) :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) # | |
class (Fractional (Groundring v), RModule v) => VectorSpace v where #
A vector space is a module over a field, i.e. a commutative ring with inverses.
It needs to satisfy the axiom
v ^ a == (1a) *^ v,
which is the default implementation.
Minimal complete definition
Nothing
Methods
(^/) :: v -> Groundfield v -> v infixl 6 #
Instances
type Groundfield v = Groundring v #
The ground ring of a vector space is required to be commutative
and to possess inverses.
It is then called the "ground field".
Commutativity amounts to the law a * b = b * a,
and the existence of inverses is given
by the requirement of the Fractional type class.
class RModule v => InnerProductSpace v where #
An inner product space is a module with an inner product,
i.e. a map dot satisfying
Methods
dot :: v -> v -> Groundfield v infix 6 #
Instances
class (Floating (Groundfield v), InnerProductSpace v, VectorSpace v) => NormedSpace v where #
A normed space is a module with a norm,
i.e. a function norm satisfying
norm (a ^* v) = a ^* norm v
norm (v1 ^+^ v2) <= norm v1 ^+^ norm v2(the "triangle inequality")
A typical example is sqrt (v ,
for an inner product space.dot v)
Minimal complete definition
Nothing
Methods
norm :: v -> Groundfield v #
Instances
normalize :: (Eq (Groundfield v), NormedSpace v) => v -> v #
Divides a vector by its norm, resulting in a vector of norm 1. Throws an error on vectors with norm 0.
Utilities to work with n-tuples for n = 3, 4, 5
break3Tuple :: (a, b, c) -> ((a, b), c) #
join3Tuple :: ((a, b), c) -> (a, b, c) #
break4Tuple :: (a, b, c, d) -> ((a, b), (c, d)) #
join4Tuple :: ((a, b), (c, d)) -> (a, b, c, d) #
break5Tuple :: (a, b, c, d, e) -> ((a, b), (c, d, e)) #
join5Tuple :: ((a, b), (c, d, e)) -> (a, b, c, d, e) #
Vector spaces from arbitrary Fractionals
newtype FractionalVectorSpace a #
Wrap an arbitrary Fractional in this newtype
in order to get VectorSpace, and related instances.
Constructors
| FractionalVectorSpace | |
Fields
| |