Module
Linear.Metric
- Package
- purescript-linear
- Repository
- afcondon/purescript-linear
The Metric typeclass for inner products and norms.
This module provides the Metric typeclass which extends Additive
with operations for computing dot products, norms, and distances.
#Metric Source
class Metric :: (Type -> Type) -> Constraintclass (Additive f) <= Metric f where
A metric space with an inner product.
Laws:
dot v v >= 0(positive semi-definite)dot v v = 0impliesv = zerodot u v = dot v u(symmetry)dot (a *^ u) v = a * dot u v(linearity)
Members
dot :: forall a. Semiring a => f a -> f a -> aquadrance :: forall a. Semiring a => f a -> aThe squared norm of a vector (quadrance from rational trigonometry).
This is more efficient than
normwhen you only need to compare magnitudes.quadrance (V2 3.0 4.0) = 25.0 -- 3² + 4²qd :: forall a. Ring a => f a -> f a -> aThe squared distance between two vectors.
qd (V2 0.0 0.0) (V2 3.0 4.0) = 25.0distance :: f Number -> f Number -> NumberThe Euclidean distance between two vectors.
distance (V2 0.0 0.0) (V2 3.0 4.0) = 5.0norm :: f Number -> NumberThe Euclidean norm (magnitude) of a vector.
norm (V2 3.0 4.0) = 5.0signorm :: f Number -> f NumberConvert a non-zero vector to a unit vector (signorm = "sign of norm").
Returns the zero vector when given the zero vector.
signorm (V2 3.0 4.0) = V2 0.6 0.8 signorm (V2 0.0 0.0) = V2 0.0 0.0
The inner (dot) product of two vectors.