linear-1.20.8: Linear Algebra

Linear.Vector

Description

Operations on free vector spaces.

Synopsis

# Documentation

class Functor f => Additive f where #

Minimal complete definition

Nothing

Methods

zero :: Num a => f a #

The zero vector

zero :: (GAdditive (Rep1 f), Generic1 f, Num a) => f a #

The zero vector

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

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 #

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 #

Linearly interpolate between two vectors.

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

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.

liftU2 :: Applicative f => (a -> a -> a) -> f a -> f a -> f a #

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 #

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.

liftI2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c #

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 [] # Instance detailsDefined in Linear.Vector Methodszero :: Num a => [a] #(^+^) :: Num a => [a] -> [a] -> [a] #(^-^) :: Num a => [a] -> [a] -> [a] #lerp :: Num a => a -> [a] -> [a] -> [a] #liftU2 :: (a -> a -> a) -> [a] -> [a] -> [a] #liftI2 :: (a -> b -> c) -> [a] -> [b] -> [c] # # Instance detailsDefined in Linear.Vector Methodszero :: Num a => Maybe a #(^+^) :: Num a => Maybe a -> Maybe a -> Maybe a #(^-^) :: Num a => Maybe a -> Maybe a -> Maybe a #lerp :: Num a => a -> Maybe a -> Maybe a -> Maybe a #liftU2 :: (a -> a -> a) -> Maybe a -> Maybe a -> Maybe a #liftI2 :: (a -> b -> c) -> Maybe a -> Maybe b -> Maybe c # # Instance detailsDefined in Linear.Vector Methodszero :: Num a => Complex a #(^+^) :: Num a => Complex a -> Complex a -> Complex a #(^-^) :: Num a => Complex a -> Complex a -> Complex a #lerp :: Num a => a -> Complex a -> Complex a -> Complex a #liftU2 :: (a -> a -> a) -> Complex a -> Complex a -> Complex a #liftI2 :: (a -> b -> c) -> Complex a -> Complex b -> Complex c # # Instance detailsDefined in Linear.Vector Methodszero :: Num a => ZipList a #(^+^) :: Num a => ZipList a -> ZipList a -> ZipList a #(^-^) :: Num a => ZipList a -> ZipList a -> ZipList a #lerp :: Num a => a -> ZipList a -> ZipList a -> ZipList a #liftU2 :: (a -> a -> a) -> ZipList a -> ZipList a -> ZipList a #liftI2 :: (a -> b -> c) -> ZipList a -> ZipList b -> ZipList c # # Instance detailsDefined in Linear.Vector Methodszero :: Num a => Identity a #(^+^) :: Num a => Identity a -> Identity a -> Identity a #(^-^) :: Num a => Identity a -> Identity a -> Identity a #lerp :: Num a => a -> Identity a -> Identity a -> Identity a #liftU2 :: (a -> a -> a) -> Identity a -> Identity a -> Identity a #liftI2 :: (a -> b -> c) -> Identity a -> Identity b -> Identity c # # Instance detailsDefined in Linear.Vector Methodszero :: Num a => IntMap a #(^+^) :: Num a => IntMap a -> IntMap a -> IntMap a #(^-^) :: Num a => IntMap a -> IntMap a -> IntMap a #lerp :: Num a => a -> IntMap a -> IntMap a -> IntMap a #liftU2 :: (a -> a -> a) -> IntMap a -> IntMap a -> IntMap a #liftI2 :: (a -> b -> c) -> IntMap a -> IntMap b -> IntMap c # # Instance detailsDefined in Linear.Vector Methodszero :: Num a => Vector a #(^+^) :: Num a => Vector a -> Vector a -> Vector a #(^-^) :: Num a => Vector a -> Vector a -> Vector a #lerp :: Num a => a -> Vector a -> Vector a -> Vector a #liftU2 :: (a -> a -> a) -> Vector a -> Vector a -> Vector a #liftI2 :: (a -> b -> c) -> Vector a -> Vector b -> Vector c # # Instance detailsDefined in Linear.V1 Methodszero :: Num a => V1 a #(^+^) :: Num a => V1 a -> V1 a -> V1 a #(^-^) :: Num a => V1 a -> V1 a -> V1 a #lerp :: Num a => a -> V1 a -> V1 a -> V1 a #liftU2 :: (a -> a -> a) -> V1 a -> V1 a -> V1 a #liftI2 :: (a -> b -> c) -> V1 a -> V1 b -> V1 c # # Instance detailsDefined in Linear.V2 Methodszero :: Num a => V2 a #(^+^) :: Num a => V2 a -> V2 a -> V2 a #(^-^) :: Num a => V2 a -> V2 a -> V2 a #lerp :: Num a => a -> V2 a -> V2 a -> V2 a #liftU2 :: (a -> a -> a) -> V2 a -> V2 a -> V2 a #liftI2 :: (a -> b -> c) -> V2 a -> V2 b -> V2 c # # Instance detailsDefined in Linear.V3 Methodszero :: Num a => V3 a #(^+^) :: Num a => V3 a -> V3 a -> V3 a #(^-^) :: Num a => V3 a -> V3 a -> V3 a #lerp :: Num a => a -> V3 a -> V3 a -> V3 a #liftU2 :: (a -> a -> a) -> V3 a -> V3 a -> V3 a #liftI2 :: (a -> b -> c) -> V3 a -> V3 b -> V3 c # # Instance detailsDefined in Linear.V4 Methodszero :: Num a => V4 a #(^+^) :: Num a => V4 a -> V4 a -> V4 a #(^-^) :: Num a => V4 a -> V4 a -> V4 a #lerp :: Num a => a -> V4 a -> V4 a -> V4 a #liftU2 :: (a -> a -> a) -> V4 a -> V4 a -> V4 a #liftI2 :: (a -> b -> c) -> V4 a -> V4 b -> V4 c # # Instance detailsDefined in Linear.V0 Methodszero :: Num a => V0 a #(^+^) :: Num a => V0 a -> V0 a -> V0 a #(^-^) :: Num a => V0 a -> V0 a -> V0 a #lerp :: Num a => a -> V0 a -> V0 a -> V0 a #liftU2 :: (a -> a -> a) -> V0 a -> V0 a -> V0 a #liftI2 :: (a -> b -> c) -> V0 a -> V0 b -> V0 c # # Instance detailsDefined in Linear.Quaternion Methodszero :: Num a => Quaternion a #(^+^) :: Num a => Quaternion a -> Quaternion a -> Quaternion a #(^-^) :: Num a => Quaternion a -> Quaternion a -> Quaternion a #lerp :: Num a => a -> Quaternion a -> Quaternion a -> Quaternion a #liftU2 :: (a -> a -> a) -> Quaternion a -> Quaternion a -> Quaternion a #liftI2 :: (a -> b -> c) -> Quaternion a -> Quaternion b -> Quaternion c # # Instance detailsDefined in Linear.Plucker Methodszero :: Num a => Plucker a #(^+^) :: Num a => Plucker a -> Plucker a -> Plucker a #(^-^) :: Num a => Plucker a -> Plucker a -> Plucker a #lerp :: Num a => a -> Plucker a -> Plucker a -> Plucker a #liftU2 :: (a -> a -> a) -> Plucker a -> Plucker a -> Plucker a #liftI2 :: (a -> b -> c) -> Plucker a -> Plucker b -> Plucker c # Ord k => Additive (Map k) # Instance detailsDefined in Linear.Vector Methodszero :: Num a => Map k a #(^+^) :: Num a => Map k a -> Map k a -> Map k a #(^-^) :: Num a => Map k a -> Map k a -> Map k a #lerp :: Num a => a -> Map k a -> Map k a -> Map k a #liftU2 :: (a -> a -> a) -> Map k a -> Map k a -> Map k a #liftI2 :: (a -> b -> c) -> Map k a -> Map k b -> Map k c # (Eq k, Hashable k) => Additive (HashMap k) # Instance detailsDefined in Linear.Vector Methodszero :: Num a => HashMap k a #(^+^) :: Num a => HashMap k a -> HashMap k a -> HashMap k a #(^-^) :: Num a => HashMap k a -> HashMap k a -> HashMap k a #lerp :: Num a => a -> HashMap k a -> HashMap k a -> HashMap k a #liftU2 :: (a -> a -> a) -> HashMap k a -> HashMap k a -> HashMap k a #liftI2 :: (a -> b -> c) -> HashMap k a -> HashMap k b -> HashMap k c # Additive f => Additive (Point f) # Instance detailsDefined in Linear.Affine Methodszero :: Num a => Point f a #(^+^) :: Num a => Point f a -> Point f a -> Point f a #(^-^) :: Num a => Point f a -> Point f a -> Point f a #lerp :: Num a => a -> Point f a -> Point f a -> Point f a #liftU2 :: (a -> a -> a) -> Point f a -> Point f a -> Point f a #liftI2 :: (a -> b -> c) -> Point f a -> Point f b -> Point f c # Dim n => Additive (V n) # Instance detailsDefined in Linear.V Methodszero :: Num a => V n a #(^+^) :: Num a => V n a -> V n a -> V n a #(^-^) :: Num a => V n a -> V n a -> V n a #lerp :: Num a => a -> V n a -> V n a -> V n a #liftU2 :: (a -> a -> a) -> V n a -> V n a -> V n a #liftI2 :: (a -> b -> c) -> V n a -> V n b -> V n c # Additive ((->) b :: Type -> Type) # Instance detailsDefined in Linear.Vector Methodszero :: Num a => b -> a #(^+^) :: Num a => (b -> a) -> (b -> a) -> b -> a #(^-^) :: Num a => (b -> a) -> (b -> a) -> b -> a #lerp :: Num a => a -> (b -> a) -> (b -> a) -> b -> a #liftU2 :: (a -> a -> a) -> (b -> a) -> (b -> a) -> b -> a #liftI2 :: (a -> b0 -> c) -> (b -> a) -> (b -> b0) -> b -> c #

newtype E t #

Basis element

Constructors

 E Fieldsel :: forall x. Lens' (t x) x
Instances
 (Num r, TrivialConjugate r) => Coalgebra r (E Quaternion) # Instance detailsDefined in Linear.Algebra Methodscomult :: (E Quaternion -> r) -> E Quaternion -> E Quaternion -> r #counital :: (E Quaternion -> r) -> r # Num r => Coalgebra r (E Complex) # Instance detailsDefined in Linear.Algebra Methodscomult :: (E Complex -> r) -> E Complex -> E Complex -> r #counital :: (E Complex -> r) -> r # Num r => Coalgebra r (E V4) # Instance detailsDefined in Linear.Algebra Methodscomult :: (E V4 -> r) -> E V4 -> E V4 -> r #counital :: (E V4 -> r) -> r # Num r => Coalgebra r (E V3) # Instance detailsDefined in Linear.Algebra Methodscomult :: (E V3 -> r) -> E V3 -> E V3 -> r #counital :: (E V3 -> r) -> r # Num r => Coalgebra r (E V2) # Instance detailsDefined in Linear.Algebra Methodscomult :: (E V2 -> r) -> E V2 -> E V2 -> r #counital :: (E V2 -> r) -> r # Num r => Coalgebra r (E V1) # Instance detailsDefined in Linear.Algebra Methodscomult :: (E V1 -> r) -> E V1 -> E V1 -> r #counital :: (E V1 -> r) -> r # Num r => Coalgebra r (E V0) # Instance detailsDefined in Linear.Algebra Methodscomult :: (E V0 -> r) -> E V0 -> E V0 -> r #counital :: (E V0 -> r) -> r # (Num r, TrivialConjugate r) => Algebra r (E Quaternion) # Instance detailsDefined in Linear.Algebra Methodsmult :: (E Quaternion -> E Quaternion -> r) -> E Quaternion -> r #unital :: r -> E Quaternion -> r # Num r => Algebra r (E Complex) # Instance detailsDefined in Linear.Algebra Methodsmult :: (E Complex -> E Complex -> r) -> E Complex -> r #unital :: r -> E Complex -> r # Num r => Algebra r (E V1) # Instance detailsDefined in Linear.Algebra Methodsmult :: (E V1 -> E V1 -> r) -> E V1 -> r #unital :: r -> E V1 -> r # Num r => Algebra r (E V0) # Instance detailsDefined in Linear.Algebra Methodsmult :: (E V0 -> E V0 -> r) -> E V0 -> r #unital :: r -> E V0 -> r # # Instance detailsDefined in Linear.V1 Methodsimap :: (E V1 -> a -> b) -> V1 a -> V1 b #imapped :: IndexedSetter (E V1) (V1 a) (V1 b) a b # # Instance detailsDefined in Linear.V2 Methodsimap :: (E V2 -> a -> b) -> V2 a -> V2 b #imapped :: IndexedSetter (E V2) (V2 a) (V2 b) a b # # Instance detailsDefined in Linear.V3 Methodsimap :: (E V3 -> a -> b) -> V3 a -> V3 b #imapped :: IndexedSetter (E V3) (V3 a) (V3 b) a b # # Instance detailsDefined in Linear.V4 Methodsimap :: (E V4 -> a -> b) -> V4 a -> V4 b #imapped :: IndexedSetter (E V4) (V4 a) (V4 b) a b # # Instance detailsDefined in Linear.V0 Methodsimap :: (E V0 -> a -> b) -> V0 a -> V0 b #imapped :: IndexedSetter (E V0) (V0 a) (V0 b) a b # # Instance detailsDefined in Linear.Quaternion Methodsimap :: (E Quaternion -> a -> b) -> Quaternion a -> Quaternion b #imapped :: IndexedSetter (E Quaternion) (Quaternion a) (Quaternion b) a b # # Instance detailsDefined in Linear.Plucker Methodsimap :: (E Plucker -> a -> b) -> Plucker a -> Plucker b #imapped :: IndexedSetter (E Plucker) (Plucker a) (Plucker b) a b # # Instance detailsDefined in Linear.V1 MethodsifoldMap :: Monoid m => (E V1 -> a -> m) -> V1 a -> m #ifolded :: IndexedFold (E V1) (V1 a) a #ifoldr :: (E V1 -> a -> b -> b) -> b -> V1 a -> b #ifoldl :: (E V1 -> b -> a -> b) -> b -> V1 a -> b #ifoldr' :: (E V1 -> a -> b -> b) -> b -> V1 a -> b #ifoldl' :: (E V1 -> b -> a -> b) -> b -> V1 a -> b # # Instance detailsDefined in Linear.V2 MethodsifoldMap :: Monoid m => (E V2 -> a -> m) -> V2 a -> m #ifolded :: IndexedFold (E V2) (V2 a) a #ifoldr :: (E V2 -> a -> b -> b) -> b -> V2 a -> b #ifoldl :: (E V2 -> b -> a -> b) -> b -> V2 a -> b #ifoldr' :: (E V2 -> a -> b -> b) -> b -> V2 a -> b #ifoldl' :: (E V2 -> b -> a -> b) -> b -> V2 a -> b # # Instance detailsDefined in Linear.V3 MethodsifoldMap :: Monoid m => (E V3 -> a -> m) -> V3 a -> m #ifolded :: IndexedFold (E V3) (V3 a) a #ifoldr :: (E V3 -> a -> b -> b) -> b -> V3 a -> b #ifoldl :: (E V3 -> b -> a -> b) -> b -> V3 a -> b #ifoldr' :: (E V3 -> a -> b -> b) -> b -> V3 a -> b #ifoldl' :: (E V3 -> b -> a -> b) -> b -> V3 a -> b # # Instance detailsDefined in Linear.V4 MethodsifoldMap :: Monoid m => (E V4 -> a -> m) -> V4 a -> m #ifolded :: IndexedFold (E V4) (V4 a) a #ifoldr :: (E V4 -> a -> b -> b) -> b -> V4 a -> b #ifoldl :: (E V4 -> b -> a -> b) -> b -> V4 a -> b #ifoldr' :: (E V4 -> a -> b -> b) -> b -> V4 a -> b #ifoldl' :: (E V4 -> b -> a -> b) -> b -> V4 a -> b # # Instance detailsDefined in Linear.V0 MethodsifoldMap :: Monoid m => (E V0 -> a -> m) -> V0 a -> m #ifolded :: IndexedFold (E V0) (V0 a) a #ifoldr :: (E V0 -> a -> b -> b) -> b -> V0 a -> b #ifoldl :: (E V0 -> b -> a -> b) -> b -> V0 a -> b #ifoldr' :: (E V0 -> a -> b -> b) -> b -> V0 a -> b #ifoldl' :: (E V0 -> b -> a -> b) -> b -> V0 a -> b # # Instance detailsDefined in Linear.Quaternion MethodsifoldMap :: Monoid m => (E Quaternion -> a -> m) -> Quaternion a -> m #ifolded :: IndexedFold (E Quaternion) (Quaternion a) a #ifoldr :: (E Quaternion -> a -> b -> b) -> b -> Quaternion a -> b #ifoldl :: (E Quaternion -> b -> a -> b) -> b -> Quaternion a -> b #ifoldr' :: (E Quaternion -> a -> b -> b) -> b -> Quaternion a -> b #ifoldl' :: (E Quaternion -> b -> a -> b) -> b -> Quaternion a -> b # # Instance detailsDefined in Linear.Plucker MethodsifoldMap :: Monoid m => (E Plucker -> a -> m) -> Plucker a -> m #ifolded :: IndexedFold (E Plucker) (Plucker a) a #ifoldr :: (E Plucker -> a -> b -> b) -> b -> Plucker a -> b #ifoldl :: (E Plucker -> b -> a -> b) -> b -> Plucker a -> b #ifoldr' :: (E Plucker -> a -> b -> b) -> b -> Plucker a -> b #ifoldl' :: (E Plucker -> b -> a -> b) -> b -> Plucker a -> b # # Instance detailsDefined in Linear.V1 Methodsitraverse :: Applicative f => (E V1 -> a -> f b) -> V1 a -> f (V1 b) #itraversed :: IndexedTraversal (E V1) (V1 a) (V1 b) a b # # Instance detailsDefined in Linear.V2 Methodsitraverse :: Applicative f => (E V2 -> a -> f b) -> V2 a -> f (V2 b) #itraversed :: IndexedTraversal (E V2) (V2 a) (V2 b) a b # # Instance detailsDefined in Linear.V3 Methodsitraverse :: Applicative f => (E V3 -> a -> f b) -> V3 a -> f (V3 b) #itraversed :: IndexedTraversal (E V3) (V3 a) (V3 b) a b # # Instance detailsDefined in Linear.V4 Methodsitraverse :: Applicative f => (E V4 -> a -> f b) -> V4 a -> f (V4 b) #itraversed :: IndexedTraversal (E V4) (V4 a) (V4 b) a b # # Instance detailsDefined in Linear.V0 Methodsitraverse :: Applicative f => (E V0 -> a -> f b) -> V0 a -> f (V0 b) #itraversed :: IndexedTraversal (E V0) (V0 a) (V0 b) a b # # Instance detailsDefined in Linear.Quaternion Methodsitraverse :: Applicative f => (E Quaternion -> a -> f b) -> Quaternion a -> f (Quaternion b) #itraversed :: IndexedTraversal (E Quaternion) (Quaternion a) (Quaternion b) a b # # Instance detailsDefined in Linear.Plucker Methodsitraverse :: Applicative f => (E Plucker -> a -> f b) -> Plucker a -> f (Plucker b) #itraversed :: IndexedTraversal (E Plucker) (Plucker a) (Plucker b) a b #

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

Compute the negation of a vector

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


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

Compute the right scalar product

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


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

Compute the left scalar product

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


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

Compute division by a scalar on the right.

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

Sum over multiple vectors

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


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

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

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

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

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

Outer (tensor) product of two vectors

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

Create a unit vector.

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