vector-space-0.19: Vector & affine spaces, linear maps, and derivatives

Copyright | (c) Conal Elliott and Andy J Gill 2008
License | BSD3
Maintainer | conal@conal.net, andygill@ku.edu
Stability | experimental
Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.VectorSpace

Description

Vector spaces

This version uses associated types instead of fundeps and requires ghc-6.10 or later

Synopsis

- module Data.AdditiveGroup
- class AdditiveGroup v => VectorSpace v where
  - type Scalar v
  - (*^) :: Scalar v -> v -> v
- (^/) :: (VectorSpace v, s ~ Scalar v, Fractional s) => v -> s -> v
- (^*) :: (VectorSpace v, s ~ Scalar v) => v -> s -> v
- class (VectorSpace v, AdditiveGroup (Scalar v)) => InnerSpace v where
  - (<.>) :: v -> v -> Scalar v
- lerp :: VectorSpace v => v -> v -> Scalar v -> v
- linearCombo :: VectorSpace v => [(v, Scalar v)] -> v
- magnitudeSq :: (InnerSpace v, s ~ Scalar v) => v -> s
- magnitude :: (InnerSpace v, s ~ Scalar v, Floating s) => v -> s
- normalized :: (InnerSpace v, s ~ Scalar v, Floating s) => v -> v
- project :: (InnerSpace v, s ~ Scalar v, Fractional s) => v -> v -> v

# Documentation

module Data.AdditiveGroup

class AdditiveGroup v => VectorSpace v where Source #

Vector space `v`.

Minimal complete definition

Nothing

Associated Types

type Scalar v Source #

type Scalar v = Scalar (VRep v)

Methods

(*^) :: Scalar v -> v -> v infixr 7 Source #

Scale a vector

default (*^) :: (Generic v, VectorSpace (VRep v), Scalar (VRep v) ~ Scalar v) => Scalar v -> v -> v Source #

#### Instances

Instances details

VectorSpace CDouble Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar CDouble |
Instance details Defined in Data.VectorSpace type Scalar CDouble = CDouble

Methods

(*^) :: Scalar CDouble -> CDouble -> CDouble Source #

VectorSpace CFloat Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar CFloat |
Instance details Defined in Data.VectorSpace type Scalar CFloat = CFloat

Methods

(*^) :: Scalar CFloat -> CFloat -> CFloat Source #

VectorSpace CInt Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar CInt |
Instance details Defined in Data.VectorSpace type Scalar CInt = CInt

Methods

(*^) :: Scalar CInt -> CInt -> CInt Source #

VectorSpace CIntMax Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar CIntMax |
Instance details Defined in Data.VectorSpace type Scalar CIntMax = CIntMax

Methods

(*^) :: Scalar CIntMax -> CIntMax -> CIntMax Source #

VectorSpace CLLong Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar CLLong |
Instance details Defined in Data.VectorSpace type Scalar CLLong = CLLong

Methods

(*^) :: Scalar CLLong -> CLLong -> CLLong Source #

VectorSpace CLong Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar CLong |
Instance details Defined in Data.VectorSpace type Scalar CLong = CLong

Methods

(*^) :: Scalar CLong -> CLong -> CLong Source #

VectorSpace CSChar Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar CSChar |
Instance details Defined in Data.VectorSpace type Scalar CSChar = CSChar

Methods

(*^) :: Scalar CSChar -> CSChar -> CSChar Source #

VectorSpace CShort Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar CShort |
Instance details Defined in Data.VectorSpace type Scalar CShort = CShort

Methods

(*^) :: Scalar CShort -> CShort -> CShort Source #

VectorSpace Integer Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar Integer |
Instance details Defined in Data.VectorSpace type Scalar Integer = Integer

Methods

(*^) :: Scalar Integer -> Integer -> Integer Source #

VectorSpace Double Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar Double |
Instance details Defined in Data.VectorSpace type Scalar Double = Double

Methods

(*^) :: Scalar Double -> Double -> Double Source #

VectorSpace Float Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar Float |
Instance details Defined in Data.VectorSpace type Scalar Float = Float

Methods

(*^) :: Scalar Float -> Float -> Float Source #

VectorSpace Int Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar Int |
Instance details Defined in Data.VectorSpace type Scalar Int = Int

Methods

(*^) :: Scalar Int -> Int -> Int Source #

(RealFloat v, VectorSpace v) => VectorSpace (Complex v) Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar (Complex v) |
Instance details Defined in Data.VectorSpace type Scalar (Complex v) = Scalar v

Methods

(*^) :: Scalar (Complex v) -> Complex v -> Complex v Source #

Integral a => VectorSpace (Ratio a) Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar (Ratio a) |
Instance details Defined in Data.VectorSpace type Scalar (Ratio a) = Ratio a

Methods

(*^) :: Scalar (Ratio a) -> Ratio a -> Ratio a Source #

VectorSpace v => VectorSpace (Maybe v) Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar (Maybe v) |
Instance details Defined in Data.VectorSpace type Scalar (Maybe v) = Scalar v

Methods

(*^) :: Scalar (Maybe v) -> Maybe v -> Maybe v Source #

(HasTrie a, VectorSpace v) => VectorSpace (a :->: v) Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar (a :->: v) |
Instance details Defined in Data.VectorSpace type Scalar (a :->: v) = Scalar v

Methods

(*^) :: Scalar (a :->: v) -> (a :->: v) -> a :->: v Source #

(HasTrie (Basis u), VectorSpace v) => VectorSpace (u :-* v) Source # |

Instance details

Defined in Data.LinearMap

Associated Types

type Scalar (u :-* v) |
Instance details Defined in Data.LinearMap type Scalar (u :-* v) = Scalar v

Methods

(*^) :: Scalar (u :-* v) -> (u :-* v) -> u :-* v Source #

(HasBasis a, HasTrie (Basis a), VectorSpace u) => VectorSpace (a :> u) Source # |

Instance details

Defined in Data.Maclaurin

Associated Types

type Scalar (a :> u) |
Instance details Defined in Data.Maclaurin type Scalar (a :> u) = a :> Scalar u

Methods

(*^) :: Scalar (a :> u) -> (a :> u) -> a :> u Source #

(VectorSpace u, s ~ Scalar u, VectorSpace v, s ~ Scalar v) => VectorSpace (u, v) Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar (u, v) |
Instance details Defined in Data.VectorSpace type Scalar (u, v) = Scalar u

Methods

(*^) :: Scalar (u, v) -> (u, v) -> (u, v) Source #

VectorSpace v => VectorSpace (a -> v) Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar (a -> v) |
Instance details Defined in Data.VectorSpace type Scalar (a -> v) = a -> Scalar v

Methods

(*^) :: Scalar (a -> v) -> (a -> v) -> a -> v Source #

VectorSpace a => VectorSpace (Rec0 a s) Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar (Rec0 a s) |
Instance details Defined in Data.VectorSpace type Scalar (Rec0 a s) = Scalar a

Methods

(*^) :: Scalar (Rec0 a s) -> Rec0 a s -> Rec0 a s Source #

(VectorSpace u, s ~ Scalar u, VectorSpace v, s ~ Scalar v, VectorSpace w, s ~ Scalar w) => VectorSpace (u, v, w) Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar (u, v, w) |
Instance details Defined in Data.VectorSpace type Scalar (u, v, w) = Scalar u

Methods

(*^) :: Scalar (u, v, w) -> (u, v, w) -> (u, v, w) Source #

(VectorSpace (f p), VectorSpace (g p), Scalar (f p) ~ Scalar (g p)) => VectorSpace ((f :*: g) p) Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar ((f :*: g) p) |
Instance details Defined in Data.VectorSpace type Scalar ((f :*: g) p) = Scalar (f p)

Methods

(*^) :: Scalar ((f :*: g) p) -> (f :*: g) p -> (f :*: g) p Source #

(VectorSpace u, s ~ Scalar u, VectorSpace v, s ~ Scalar v, VectorSpace w, s ~ Scalar w, VectorSpace x, s ~ Scalar x) => VectorSpace (u, v, w, x) Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar (u, v, w, x) |
Instance details Defined in Data.VectorSpace type Scalar (u, v, w, x) = Scalar u

Methods

(*^) :: Scalar (u, v, w, x) -> (u, v, w, x) -> (u, v, w, x) Source #

VectorSpace (f p) => VectorSpace (M1 i c f p) Source # |

Instance details

Defined in Data.VectorSpace

Associated Types

type Scalar (M1 i c f p) |
Instance details Defined in Data.VectorSpace type Scalar (M1 i c f p) = Scalar (f p)

Methods

(*^) :: Scalar (M1 i c f p) -> M1 i c f p -> M1 i c f p Source #

(^/) :: (VectorSpace v, s ~ Scalar v, Fractional s) => v -> s -> v infixr 7 Source #

Vector divided by scalar

(^*) :: (VectorSpace v, s ~ Scalar v) => v -> s -> v infixl 7 Source #

Vector multiplied by scalar

class (VectorSpace v, AdditiveGroup (Scalar v)) => InnerSpace v where Source #

Adds inner (dot) products.

Minimal complete definition

Nothing

Methods

(<.>) :: v -> v -> Scalar v infixr 7 Source #

Inner/dot product

default (<.>) :: (Generic v, InnerSpace (VRep v), Scalar (VRep v) ~ Scalar v) => v -> v -> Scalar v Source #

#### Instances

Instances details

InnerSpace CDouble Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: CDouble -> CDouble -> Scalar CDouble Source #
InnerSpace CFloat Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: CFloat -> CFloat -> Scalar CFloat Source #
InnerSpace CInt Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: CInt -> CInt -> Scalar CInt Source #
InnerSpace CIntMax Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: CIntMax -> CIntMax -> Scalar CIntMax Source #
InnerSpace CLLong Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: CLLong -> CLLong -> Scalar CLLong Source #
InnerSpace CLong Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: CLong -> CLong -> Scalar CLong Source #
InnerSpace CSChar Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: CSChar -> CSChar -> Scalar CSChar Source #
InnerSpace CShort Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: CShort -> CShort -> Scalar CShort Source #
InnerSpace Integer Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: Integer -> Integer -> Scalar Integer Source #
InnerSpace Double Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: Double -> Double -> Scalar Double Source #
InnerSpace Float Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: Float -> Float -> Scalar Float Source #
InnerSpace Int Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: Int -> Int -> Scalar Int Source #
(RealFloat v, InnerSpace v) => InnerSpace (Complex v) Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: Complex v -> Complex v -> Scalar (Complex v) Source #
Integral a => InnerSpace (Ratio a) Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: Ratio a -> Ratio a -> Scalar (Ratio a) Source #
InnerSpace a => InnerSpace (Maybe a) Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: Maybe a -> Maybe a -> Scalar (Maybe a) Source #
(InnerSpace u, s ~ Scalar u, AdditiveGroup s, HasBasis a, HasTrie (Basis a)) => InnerSpace (a :> u) Source # |
Instance details Defined in Data.Maclaurin Methods (<.>) :: (a :> u) -> (a :> u) -> Scalar (a :> u) Source #
(InnerSpace u, s ~ Scalar u, InnerSpace v, s ~ Scalar v) => InnerSpace (u, v) Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: (u, v) -> (u, v) -> Scalar (u, v) Source #
InnerSpace v => InnerSpace (a -> v) Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: (a -> v) -> (a -> v) -> Scalar (a -> v) Source #
InnerSpace a => InnerSpace (Rec0 a s) Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: Rec0 a s -> Rec0 a s -> Scalar (Rec0 a s) Source #
(InnerSpace u, s ~ Scalar u, InnerSpace v, s ~ Scalar v, InnerSpace w, s ~ Scalar w) => InnerSpace (u, v, w) Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: (u, v, w) -> (u, v, w) -> Scalar (u, v, w) Source #
(InnerSpace (f p), InnerSpace (g p), Scalar (f p) ~ Scalar (g p), Num (Scalar (f p))) => InnerSpace ((f :*: g) p) Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: (f :*: g) p -> (f :*: g) p -> Scalar ((f :*: g) p) Source #
(InnerSpace u, s ~ Scalar u, InnerSpace v, s ~ Scalar v, InnerSpace w, s ~ Scalar w, InnerSpace x, s ~ Scalar x) => InnerSpace (u, v, w, x) Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: (u, v, w, x) -> (u, v, w, x) -> Scalar (u, v, w, x) Source #
InnerSpace (f p) => InnerSpace (M1 i c f p) Source # |
Instance details Defined in Data.VectorSpace Methods (<.>) :: M1 i c f p -> M1 i c f p -> Scalar (M1 i c f p) Source #

lerp :: VectorSpace v => v -> v -> Scalar v -> v Source #

Linear interpolation between `a` (when `t==0`) and `b` (when `t==1`).

linearCombo :: VectorSpace v => [(v, Scalar v)] -> v Source #

Linear combination of vectors

magnitudeSq :: (InnerSpace v, s ~ Scalar v) => v -> s Source #

Square of the length of a vector. Sometimes useful for efficiency. See also `magnitude`.

magnitude :: (InnerSpace v, s ~ Scalar v, Floating s) => v -> s Source #

Length of a vector. See also `magnitudeSq`.

normalized :: (InnerSpace v, s ~ Scalar v, Floating s) => v -> v Source #

Vector in same direction as given one but with length of one. Divides by zero for the zero vector.

project :: (InnerSpace v, s ~ Scalar v, Fractional s) => v -> v -> v Source #

`project u v` computes the projection of `v` onto `u`.