dunai-0.5.1: Generalised reactive framework supporting classic, arrowized and monadic FRP.

Copyright (c) Ivan Perez and Manuel Bärenz See the LICENSE file in the distribution. ivan.perez@keera.co.uk provisional non-portable (GHC extensions) None Haskell2010

Data.VectorSpace

Description

Vector space type relation and basic instances. Heavily inspired by Yampa's FRP.Yampa.VectorSpace module.

Synopsis

# Vector space classes

class Num (Groundring v) => RModule v where Source #

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 Source #

Methods

(*^) :: Groundring v -> v -> v infixr 6 Source #

(^*) :: v -> Groundring v -> v Source #

negateVector :: v -> v Source #

(^+^) :: v -> v -> v infixl 5 Source #

(^-^) :: v -> v -> v infixl 5 Source #

Instances
 Source # Instance detailsDefined in Data.VectorSpace Associated Types Methods Source # Instance detailsDefined in Data.VectorSpace Associated Types Methods Source # Instance detailsDefined in Data.VectorSpace Associated Typestype Groundring Int :: Type Source # Methods(^+^) :: Int -> Int -> Int Source #(^-^) :: Int -> Int -> Int Source # Source # Instance detailsDefined in Data.VectorSpace Associated Types Methods Source # Instance detailsDefined in Data.VectorSpace Associated Types Methods (Groundring a ~ Groundring b, RModule a, RModule b) => RModule (a, b) Source # Instance detailsDefined in Data.VectorSpace Associated Typestype Groundring (a, b) :: Type Source # MethodszeroVector :: (a, b) Source #(*^) :: Groundring (a, b) -> (a, b) -> (a, b) Source #(^*) :: (a, b) -> Groundring (a, b) -> (a, b) Source #negateVector :: (a, b) -> (a, b) Source #(^+^) :: (a, b) -> (a, b) -> (a, b) Source #(^-^) :: (a, b) -> (a, b) -> (a, b) Source # (Groundring a ~ Groundring b, Groundring a ~ Groundring c, RModule a, RModule b, RModule c) => RModule (a, b, c) Source # Instance detailsDefined in Data.VectorSpace Associated Typestype Groundring (a, b, c) :: Type Source # MethodszeroVector :: (a, b, c) Source #(*^) :: Groundring (a, b, c) -> (a, b, c) -> (a, b, c) Source #(^*) :: (a, b, c) -> Groundring (a, b, c) -> (a, b, c) Source #negateVector :: (a, b, c) -> (a, b, c) Source #(^+^) :: (a, b, c) -> (a, b, c) -> (a, b, c) Source #(^-^) :: (a, b, c) -> (a, b, c) -> (a, b, c) Source # (Monad m, RModule v) => RModule (MSF m a v) Source # R-module instance for MSFs. Instance details Associated Typestype Groundring (MSF m a v) :: Type Source # MethodszeroVector :: MSF m a v Source #(*^) :: Groundring (MSF m a v) -> MSF m a v -> MSF m a v Source #(^*) :: MSF m a v -> Groundring (MSF m a v) -> MSF m a v Source #negateVector :: MSF m a v -> MSF m a v Source #(^+^) :: MSF m a v -> MSF m a v -> MSF m a v Source #(^-^) :: MSF m a v -> MSF m a v -> MSF m a v Source # (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) Source # Instance detailsDefined in Data.VectorSpace Associated Typestype Groundring (a, b, c, d) :: Type Source # MethodszeroVector :: (a, b, c, d) Source #(*^) :: Groundring (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) Source #(^*) :: (a, b, c, d) -> Groundring (a, b, c, d) -> (a, b, c, d) Source #negateVector :: (a, b, c, d) -> (a, b, c, d) Source #(^+^) :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) Source #(^-^) :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) Source # (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) Source # Instance detailsDefined in Data.VectorSpace Associated Typestype Groundring (a, b, c, d, e) :: Type Source # MethodszeroVector :: (a, b, c, d, e) Source #(*^) :: Groundring (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) Source #(^*) :: (a, b, c, d, e) -> Groundring (a, b, c, d, e) -> (a, b, c, d, e) Source #negateVector :: (a, b, c, d, e) -> (a, b, c, d, e) Source #(^+^) :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) Source #(^-^) :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) Source #

class (Fractional (Groundring v), RModule v) => VectorSpace v where Source #

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 Source #

Instances
 Source # Instance detailsDefined in Data.VectorSpace Methods Source # Instance detailsDefined in Data.VectorSpace Methods Source # Instance detailsDefined in Data.VectorSpace Methods (Groundfield a ~ Groundfield b, VectorSpace a, VectorSpace b) => VectorSpace (a, b) Source # Instance detailsDefined in Data.VectorSpace Methods(^/) :: (a, b) -> Groundfield (a, b) -> (a, b) Source # (Groundring a ~ Groundring b, Groundring a ~ Groundring c, VectorSpace a, VectorSpace b, VectorSpace c) => VectorSpace (a, b, c) Source # Instance detailsDefined in Data.VectorSpace Methods(^/) :: (a, b, c) -> Groundfield (a, b, c) -> (a, b, c) Source # (Monad m, VectorSpace v) => VectorSpace (MSF m a v) Source # Vector-space instance for MSFs. Instance details Methods(^/) :: MSF m a v -> Groundfield (MSF m a v) -> MSF m a v Source # (Groundring a ~ Groundring b, Groundring a ~ Groundring c, Groundring a ~ Groundring d, VectorSpace a, VectorSpace b, VectorSpace c, VectorSpace d) => VectorSpace (a, b, c, d) Source # Instance detailsDefined in Data.VectorSpace Methods(^/) :: (a, b, c, d) -> Groundfield (a, b, c, d) -> (a, b, c, d) Source # (Groundring a ~ Groundring b, Groundring a ~ Groundring c, Groundring a ~ Groundring d, Groundring a ~ Groundring e, VectorSpace a, VectorSpace b, VectorSpace c, VectorSpace d, VectorSpace e) => VectorSpace (a, b, c, d, e) Source # Instance detailsDefined in Data.VectorSpace Methods(^/) :: (a, b, c, d, e) -> Groundfield (a, b, c, d, e) -> (a, b, c, d, e) Source #

type Groundfield v = Groundring v Source #

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 Source #

An inner product space is a module with an inner product, i.e. a map dot satisfying

• v1 dot v2 == v2 dot v1
• (v1 ^+^ v2) dot v3 == v1 dot v3 ^+^ v2 dot v3
• (a *^ v1) dot v2 == a *^ v1 dot v2

Methods

dot :: v -> v -> Groundfield v infix 6 Source #

Instances
 Source # Instance detailsDefined in Data.VectorSpace Methods (Groundfield a ~ Groundfield b, InnerProductSpace a, InnerProductSpace b) => InnerProductSpace (a, b) Source # Instance detailsDefined in Data.VectorSpace Methodsdot :: (a, b) -> (a, b) -> Groundfield (a, b) Source # (Groundring a ~ Groundring b, Groundring a ~ Groundring c, InnerProductSpace a, InnerProductSpace b, InnerProductSpace c) => InnerProductSpace (a, b, c) Source # Instance detailsDefined in Data.VectorSpace Methodsdot :: (a, b, c) -> (a, b, c) -> Groundfield (a, b, c) Source # (Groundring a ~ Groundring b, Groundring a ~ Groundring c, Groundring a ~ Groundring d, InnerProductSpace a, InnerProductSpace b, InnerProductSpace c, InnerProductSpace d) => InnerProductSpace (a, b, c, d) Source # Instance detailsDefined in Data.VectorSpace Methodsdot :: (a, b, c, d) -> (a, b, c, d) -> Groundfield (a, b, c, d) Source # (Groundring a ~ Groundring b, Groundring a ~ Groundring c, Groundring a ~ Groundring d, Groundring a ~ Groundring e, InnerProductSpace a, InnerProductSpace b, InnerProductSpace c, InnerProductSpace d, InnerProductSpace e) => InnerProductSpace (a, b, c, d, e) Source # Instance detailsDefined in Data.VectorSpace Methodsdot :: (a, b, c, d, e) -> (a, b, c, d, e) -> Groundfield (a, b, c, d, e) Source #

class (Floating (Groundfield v), InnerProductSpace v, VectorSpace v) => NormedSpace v where Source #

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 dot v), for an inner product space.

Minimal complete definition

Nothing

Methods

norm :: v -> Groundfield v Source #

Instances
 Source # Instance detailsDefined in Data.VectorSpace Methods (Groundfield a ~ Groundfield b, NormedSpace a, NormedSpace b) => NormedSpace (a, b) Source # Instance detailsDefined in Data.VectorSpace Methodsnorm :: (a, b) -> Groundfield (a, b) Source # (Groundring a ~ Groundring b, Groundring a ~ Groundring c, NormedSpace a, NormedSpace b, NormedSpace c) => NormedSpace (a, b, c) Source # Instance detailsDefined in Data.VectorSpace Methodsnorm :: (a, b, c) -> Groundfield (a, b, c) Source # (Groundring a ~ Groundring b, Groundring a ~ Groundring c, Groundring a ~ Groundring d, NormedSpace a, NormedSpace b, NormedSpace c, NormedSpace d) => NormedSpace (a, b, c, d) Source # Instance detailsDefined in Data.VectorSpace Methodsnorm :: (a, b, c, d) -> Groundfield (a, b, c, d) Source # (Groundring a ~ Groundring b, Groundring a ~ Groundring c, Groundring a ~ Groundring d, Groundring a ~ Groundring e, NormedSpace a, NormedSpace b, NormedSpace c, NormedSpace d, NormedSpace e) => NormedSpace (a, b, c, d, e) Source # Instance detailsDefined in Data.VectorSpace Methodsnorm :: (a, b, c, d, e) -> Groundfield (a, b, c, d, e) Source #

normalize :: (Eq (Groundfield v), NormedSpace v) => v -> v Source #

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) Source #

join3Tuple :: ((a, b), c) -> (a, b, c) Source #

break4Tuple :: (a, b, c, d) -> ((a, b), (c, d)) Source #

join4Tuple :: ((a, b), (c, d)) -> (a, b, c, d) Source #

break5Tuple :: (a, b, c, d, e) -> ((a, b), (c, d, e)) Source #

join5Tuple :: ((a, b), (c, d, e)) -> (a, b, c, d, e) Source #

# Vector spaces from arbitrary Fractionals

newtype FractionalVectorSpace a Source #

Wrap an arbitrary Fractional in this newtype in order to get VectorSpace, and related instances.

Constructors

 FractionalVectorSpace FieldsgetFractional :: a
Instances
 Source # Instance detailsDefined in Data.VectorSpace Methods Num a => Num (FractionalVectorSpace a) Source # Instance detailsDefined in Data.VectorSpace Methods Source # Instance detailsDefined in Data.VectorSpace Methods Source # Instance detailsDefined in Data.VectorSpace Methods Source # Instance detailsDefined in Data.VectorSpace Methods Source # Instance detailsDefined in Data.VectorSpace Associated Types Methods Source # Instance detailsDefined in Data.VectorSpace type Groundring (FractionalVectorSpace a) = a