nonlinear-0.1.0: Low-dimensional vectors
Safe HaskellSafe-Inferred
LanguageHaskell2010

Nonlinear.Vector

Description

Adapted from Linear.Vector

Synopsis

Documentation

class (Traversable v, Monad v) => Vec v where Source #

Class of vectors of statically known size.

Conceptually, this is Representable, but with a Traversable and Monad constraint instead of just Functor. This makes it a catch-all class for things that we would normally think of as vectors of statically known size. The Monad constraint might seem weird, but since we can implement the normal (diagonal) Monad instance in terms of construct, it doesn't actually preclude anything.

Methods

construct :: ((forall b. Lens' (v b) b) -> a) -> v a Source #

Instances

Instances details
Vec V1 Source # 
Instance details

Defined in Nonlinear.V1

Methods

construct :: ((forall b. Lens' (V1 b) b) -> a) -> V1 a Source #

Vec V2 Source # 
Instance details

Defined in Nonlinear.V2

Methods

construct :: ((forall b. Lens' (V2 b) b) -> a) -> V2 a Source #

Vec V3 Source # 
Instance details

Defined in Nonlinear.V3

Methods

construct :: ((forall b. Lens' (V3 b) b) -> a) -> V3 a Source #

Vec V4 Source # 
Instance details

Defined in Nonlinear.V4

Methods

construct :: ((forall b. Lens' (V4 b) b) -> a) -> V4 a Source #

Vec Quaternion Source # 
Instance details

Defined in Nonlinear.Quaternion

Methods

construct :: ((forall b. Lens' (Quaternion b) b) -> a) -> Quaternion a Source #

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

Compute the negation of a vector

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

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

Compute the right scalar product

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

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

Compute the left scalar product

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

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

Compute division by a scalar on the right.

basis :: (Vec 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 :: (Vec t, Num a) => t b -> [t a] Source #

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

scaled :: (Vec 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 :: (Vec f, Vec g, Num a) => f a -> g a -> f (g a) Source #

Outer (tensor) product of two vectors

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

Create a unit vector.

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

dot :: (Vec f, Num a) => f a -> f a -> a Source #

Compute the inner product of two vectors or (equivalently) convert a vector f a into a covector f a -> a.

>>> V2 1 2 `dot` V2 3 4
11

quadrance :: (Vec f, Num a) => f a -> a Source #

Compute the squared norm. The name quadrance arises from Norman J. Wildberger's rational trigonometry.

qd :: (Vec f, Num a) => f a -> f a -> a Source #

Compute the quadrance of the difference

distance :: (Vec f, Floating a) => f a -> f a -> a Source #

Compute the distance between two vectors in a metric space

norm :: (Vec f, Floating a) => f a -> a Source #

Compute the norm of a vector in a metric space

signorm :: (Vec f, Floating a) => f a -> f a Source #

Convert a non-zero vector to unit vector.

normalize :: (Vec f, Floating a) => f a -> f a Source #

Normalize a Metric functor to have unit norm. This function does not change the functor if its norm is 0 or 1.

project :: (Vec v, Fractional a) => v a -> v a -> v a Source #

project u v computes the projection of v onto u.