linear-1.20.3: Linear Algebra

Copyright | (C) 2012-2015 Edward Kmett
License | BSD-style (see the file LICENSE)
Maintainer | Edward Kmett <ekmett@gmail.com>
Stability | provisional
Portability | portable
Safe Haskell | Trustworthy
Language | Haskell98

Linear.Vector

Description

Operations on free vector spaces.

Synopsis

- class Functor f => Additive f where
  - zero :: Num a => f a
  - (^+^) :: Num a => f a -> f a -> f a
  - (^-^) :: Num a => f a -> f a -> f a
  - lerp :: Num a => a -> f a -> f a -> f a
  - liftU2 :: (a -> a -> a) -> f a -> f a -> f a
  - liftI2 :: (a -> b -> c) -> f a -> f b -> f c
- newtype E t = E {
  - el :: forall x. Lens' (t x) x
  }
- negated :: (Functor f, Num a) => f a -> f a
- (^*) :: (Functor f, Num a) => f a -> a -> f a
- (*^) :: (Functor f, Num a) => a -> f a -> f a
- (^/) :: (Functor f, Fractional a) => f a -> a -> f a
- sumV :: (Foldable f, Additive v, Num a) => f (v a) -> v a
- basis :: (Additive t, Traversable t, Num a) => [t a]
- basisFor :: (Traversable t, Num a) => t b -> [t a]
- scaled :: (Traversable t, Num a) => t a -> t (t a)
- outer :: (Functor f, Functor g, Num a) => f a -> g a -> f (g a)
- unit :: (Additive t, Num a) => ASetter' (t a) a -> t a

# Documentation

class Functor f => Additive f where Source

A vector is an additive group with additional structure.

Minimal complete definition

Nothing

Methods

zero :: Num a => f a Source

The zero vector

(^+^) :: Num a => f a -> f a -> f a infixl 6 Source

Compute the sum of two vectors

    >>> V2 1 2 ^+^ V2 3 4
    V2 4 6

(^-^) :: Num a => f a -> f a -> f a infixl 6 Source

Compute the difference between two vectors

    >>> V2 4 5 ^-^ V2 3 1
    V2 1 4

lerp :: Num a => a -> f a -> f a -> f a Source

Linearly interpolate between two vectors.

liftU2 :: (a -> a -> a) -> f a -> f a -> f a Source

Apply a function to merge the 'non-zero' components of two vectors, unioning the rest of the values.

- For a dense vector this is equivalent to `liftA2`.
- For a sparse vector this is equivalent to `unionWith`.

liftI2 :: (a -> b -> c) -> f a -> f b -> f c Source

Apply a function to the components of two vectors.

- For a dense vector this is equivalent to `liftA2`.
- For a sparse vector this is equivalent to `intersectionWith`.

Instances

Additive [] Source |
Additive Identity Source |
Additive Complex Source |
Additive ZipList Source |
Additive Maybe Source |
Additive IntMap Source |
Additive Vector Source |
Additive V0 Source |
Additive V1 Source |
Additive V2 Source |
Additive V3 Source |
Additive V4 Source |
Additive Plucker Source |
Additive Quaternion Source |
Additive ((->) b) Source |
Ord k => Additive (Map k) Source |
(Eq k, Hashable k) => Additive (HashMap k) Source |
Additive f => Additive (Point f) Source |
Dim k n => Additive (V k n) Source |

newtype E t Source

Basis element

Constructors

E |

Fields

el :: forall x. Lens' (t x) x

Instances

(Num r, TrivialConjugate r) => Coalgebra r (E Quaternion) Source |
Num r => Coalgebra r (E Complex) Source |
Num r => Coalgebra r (E V4) Source |
Num r => Coalgebra r (E V3) Source |
Num r => Coalgebra r (E V2) Source |
Num r => Coalgebra r (E V1) Source |
Num r => Coalgebra r (E V0) Source |
(Num r, TrivialConjugate r) => Algebra r (E Quaternion) Source |
Num r => Algebra r (E Complex) Source |
Num r => Algebra r (E V1) Source |
Num r => Algebra r (E V0) Source |
FunctorWithIndex (E V0) V0 |
FunctorWithIndex (E V1) V1 |
FunctorWithIndex (E V2) V2 |
FunctorWithIndex (E V3) V3 |
FunctorWithIndex (E V4) V4 |
FunctorWithIndex (E Plucker) Plucker |
FunctorWithIndex (E Quaternion) Quaternion |
FoldableWithIndex (E V0) V0 |
FoldableWithIndex (E V1) V1 |
FoldableWithIndex (E V2) V2 |
FoldableWithIndex (E V3) V3 |
FoldableWithIndex (E V4) V4 |
FoldableWithIndex (E Plucker) Plucker |
FoldableWithIndex (E Quaternion) Quaternion |
TraversableWithIndex (E V0) V0 |
TraversableWithIndex (E V1) V1 |
TraversableWithIndex (E V2) V2 |
TraversableWithIndex (E V3) V3 |
TraversableWithIndex (E V4) V4 |
TraversableWithIndex (E Plucker) Plucker |
TraversableWithIndex (E Quaternion) Quaternion |

negated :: (Functor f, Num a) => f a -> f a Source

Compute the negation of a vector

    >>> negated (V2 2 4)
    V2 (-2) (-4)

(^*) :: (Functor f, Num a) => f a -> a -> f a infixl 7 Source

Compute the right scalar product

    >>> V2 3 4 ^* 2
    V2 6 8

(*^) :: (Functor f, Num a) => a -> f a -> f a infixl 7 Source

Compute the left scalar product

    >>> 2 *^ V2 3 4
    V2 6 8

(^/) :: (Functor f, Fractional a) => f a -> a -> f a infixl 7 Source

Compute division by a scalar on the right.

sumV :: (Foldable f, Additive v, Num a) => f (v a) -> v a Source

Sum over multiple vectors

    >>> sumV [V2 1 1, V2 3 4]
    V2 4 5

basis :: (Additive t, Traversable t, Num a) => [t a] Source

Produce a default basis for a vector space. If the dimensionality of the vector space is not statically known, see `basisFor`.

basisFor :: (Traversable t, Num a) => t b -> [t a] Source

Produce a default basis for a vector space from which the argument is drawn.

scaled :: (Traversable t, Num a) => t a -> t (t a) Source

Produce a diagonal (scale) matrix from a vector.

    >>> scaled (V2 2 3)
    V2 (V2 2 0) (V2 0 3)

outer :: (Functor f, Functor g, Num a) => f a -> g a -> f (g a) Source

Outer (tensor) product of two vectors

unit :: (Additive t, Num a) => ASetter' (t a) a -> t a Source

Create a unit vector.

    >>> unit _x :: V2 Int
    V2 1 0