-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Vector & affine spaces, plus derivatives -- -- vector-space provides classes and generic operations for vector spaces -- and affine spaces. It also defines a type of infinite towers of -- generalized derivatives. A generalized derivative is a linear -- transformation rather than one of the common concrete representations -- (scalars, vectors, matrices, ...). -- -- Project wiki page: http://haskell.org/haskellwiki/vector-space -- -- The module documentation pages have links to colorized source code and -- to wiki pages where you can read and contribute user comments. Enjoy! -- -- © 2008 by Conal Elliott; BSD3 license. @package vector-space @version 0.1 -- | Number class instances for functions and tuples module Data.NumInstances instance (Floating a, Floating b, Floating c, Floating d) => Floating (a, b, c, d) instance (Fractional a, Fractional b, Fractional c, Fractional d) => Fractional (a, b, c, d) instance (Num a, Num b, Num c, Num d) => Num (a, b, c, d) instance (Floating a, Floating b, Floating c) => Floating (a, b, c) instance (Fractional a, Fractional b, Fractional c) => Fractional (a, b, c) instance (Num a, Num b, Num c) => Num (a, b, c) instance (Floating a, Floating b) => Floating (a, b) instance (Fractional a, Fractional b) => Fractional (a, b) instance (Num a, Num b) => Num (a, b) instance (Floating b) => Floating (a -> b) instance (Fractional b) => Fractional (a -> b) instance (Num b) => Num (a -> b) instance Show (a -> b) instance (Ord b) => Ord (a -> b) instance Eq (a -> b) -- | Vector spaces module Data.VectorSpace -- | Vector space v over a scalar field s class VectorSpace v s | v -> s zeroV :: (VectorSpace v s) => v (*^) :: (VectorSpace v s) => s -> v -> v (^+^) :: (VectorSpace v s) => v -> v -> v negateV :: (VectorSpace v s) => v -> v -- | Convenience. Maybe add methods later. class VectorSpace s s => -- Scalar s -- -- Vector subtraction (^-^) :: (VectorSpace v s) => v -> v -> v -- | Vector divided by scalar (^/) :: (Fractional s, VectorSpace v s) => v -> s -> v -- | Vector multiplied by scalar (^*) :: (VectorSpace v s) => v -> s -> v -- | Adds inner (dot) products class (VectorSpace v s) => InnerSpace v s | v -> s (<.>) :: (InnerSpace v s) => v -> v -> s -- | Linear interpolation between a (when t==0) and -- b (when t==1). lerp :: (VectorSpace v s, Num s) => v -> v -> s -> v -- | Square of the length of a vector. Sometimes useful for efficiency. See -- also magnitude. magnitudeSq :: (InnerSpace v s) => v -> s -- | Length of a vector. See also magnitudeSq. magnitude :: (InnerSpace v s, Floating s) => v -> s -- | Vector in same direction as given one but with length of one. If given -- the zero vector, then return it. normalized :: (InnerSpace v s, Floating s) => v -> v -- | Linear transformations/maps. For now, represented as simple functions. -- The VectorSpace instance for functions gives the usual meaning -- for a vector space of linear transformations. type :-* a b = a -> b instance (VectorSpace v s) => VectorSpace (a -> v) s instance (InnerSpace u s, InnerSpace v s, InnerSpace w s, VectorSpace s s') => InnerSpace (u, v, w) s instance (VectorSpace u s, VectorSpace v s, VectorSpace w s) => VectorSpace (u, v, w) s instance (InnerSpace u s, InnerSpace v s, VectorSpace s s') => InnerSpace (u, v) s instance (VectorSpace u s, VectorSpace v s) => VectorSpace (u, v) s instance InnerSpace Float Float instance VectorSpace Float Float instance InnerSpace Double Double instance VectorSpace Double Double -- | Infinite derivative towers via linear maps. See blog posts -- http://conal.net/blog/tag/derivatives/ module Data.Derivative -- | Tower of derivatives. -- -- Warning, the Applicative instance is missing its pure -- (due to a VectorSpace type constraint). Use dConst -- instead. data (:>) a b D :: b -> a :-* (a :> b) -> :> a b dVal :: :> a b -> b dDeriv :: :> a b -> a :-* (a :> b) -- | Infinitely differentiable functions type :~> a b = a -> (a :> b) -- | Derivative tower full of zeroV. dZero :: (VectorSpace b s) => a :> b -- | Constant derivative tower. dConst :: (VectorSpace b s) => b -> a :> b -- | Tower of derivatives of the identity function. Sometimes called the -- derivation variable or similar, but it's not really a variable. dId :: (VectorSpace v s) => v -> v :> v bilinearD :: (VectorSpace w s) => (u -> v -> w) -> (t :> u) -> (t :> v) -> (t :> w) -- | Chain rule. (@.) :: (b :~> c) -> (a :~> b) -> (a :~> c) (>-<) :: (VectorSpace b s) => (b -> b) -> ((a :> b) -> (a :> s)) -> (a :> b) -> (a :> b) instance (Floating b, VectorSpace b b) => Floating (a :> b) instance (Fractional b, VectorSpace b b) => Fractional (a :> b) instance (Num b, VectorSpace b b) => Num (a :> b) instance (VectorSpace u s) => VectorSpace (a :> u) (a :> s) instance (Ord b) => Ord (a :> b) instance (Eq b) => Eq (a :> b) instance (Show b) => Show (a :> b) instance Applicative ((:>) a) instance Functor ((:>) a) -- | Affine spaces. module Data.AffineSpace class (VectorSpace v s) => AffineSpace p v s | p -> v s (.-.) :: (AffineSpace p v s) => p -> p -> v (.+^) :: (AffineSpace p v s) => p -> v -> p -- | Point minus vector (.-^) :: (Num s, AffineSpace p v s) => p -> v -> p -- | Square of the distance between two points. Sometimes useful for -- efficiency. See also distance. distanceSq :: (AffineSpace p v s, InnerSpace v s) => p -> p -> s -- | Distance between two points. See also distanceSq. distance :: (Floating s, AffineSpace p v s, InnerSpace v s) => p -> p -> s -- | Affine linear interpolation. Varies from p to p' as -- s varies from 0 to 1. See also lerp (on vector -- spaces). alerp :: (AffineSpace p v s) => p -> p -> s -> p instance AffineSpace Float Float Float instance AffineSpace Double Double Double