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 | experimental
Portability | non-portable
Safe Haskell | Trustworthy
Language | Haskell98

Linear.Metric

Description

Free metric spaces

Synopsis

- class Additive f => Metric f where
  - dot :: Num a => f a -> f a -> a
  - quadrance :: Num a => f a -> a
  - qd :: Num a => f a -> f a -> a
  - distance :: Floating a => f a -> f a -> a
  - norm :: Floating a => f a -> a
  - signorm :: Floating a => f a -> f a
- normalize :: (Floating a, Metric f, Epsilon a) => f a -> f a
- project :: (Metric v, Fractional a) => v a -> v a -> v a

# Documentation

class Additive f => Metric f where Source

Free and sparse inner product/metric spaces.

Minimal complete definition

Nothing

Methods

dot :: 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 :: Num a => f a -> a Source

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

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

Compute the quadrance of the difference

distance :: Floating a => f a -> f a -> a Source

Compute the distance between two vectors in a metric space

norm :: Floating a => f a -> a Source

Compute the norm of a vector in a metric space

signorm :: Floating a => f a -> f a Source

Convert a non-zero vector to unit vector.

Instances

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

normalize :: (Floating a, Metric f, Epsilon 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 :: (Metric v, Fractional a) => v a -> v a -> v a Source

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