+
+
+-- | 'Normed' instance for vectors of any length. We will generally be
+-- working with n-by-1 /matrices/ instead of vectors, but sometimes
+-- it's convenient to have these instances anyway.
+--
+-- Examples:
+--
+-- >>> import Data.Vector.Fixed (mk3)
+-- >>> import Linear.Vector (Vec0, Vec3)
+-- >>> let b = mk3 1 2 3 :: Vec3 Double
+-- >>> norm_p 1 b :: Double
+-- 6.0
+-- >>> norm b == sqrt 14
+-- True
+-- >>> norm_infty b :: Double
+-- 3.0
+--
+-- >>> let b = undefined :: Vec0 Int
+-- >>> norm b
+-- 0.0
+--
+instance (V.Arity n, Absolute.C a, ToRational.C a, Ord a)
+ => Normed (Vec n a) where
+ norm_p p x =
+ (root p') $ element_sum $ V.map element_function x
+ where
+ element_function y = fromRational' $ (toRational y)^p'
+ p' = toInteger p
+
+ norm_infty x = fromRational' $ toRational $ (V.foldl P.max 0) $ V.map abs x