From: Michael Orlitzky Date: Wed, 17 Oct 2012 21:25:31 +0000 (-0400) Subject: Rename "norm" to "norm_2" in the Vector class. X-Git-Url: http://gitweb.michael.orlitzky.com/?p=numerical-analysis.git;a=commitdiff_plain;h=1832912058bfe274e1f049dae80ea05daa94a1a1 Rename "norm" to "norm_2" in the Vector class. Add "norm_infty" to the Vector class. --- diff --git a/src/TwoTuple.hs b/src/TwoTuple.hs index 1b5e93e..3950fee 100644 --- a/src/TwoTuple.hs +++ b/src/TwoTuple.hs @@ -21,7 +21,14 @@ instance Functor TwoTuple where instance (RealFloat a) => Vector (TwoTuple a) where -- The standard Euclidean 2-norm. We need RealFloat for the square -- root. - norm (TwoTuple x1 y1) = fromRational $ toRational (sqrt(x1^2 + y1^2)) + norm_2 (TwoTuple x y) = fromRational $ toRational (sqrt(x^2 + y^2)) + + -- The infinity norm, i.e. the maximum entry. + norm_infty (TwoTuple x y) = + fromRational $ max absx absy + where + absx = abs (toRational x) + absy = abs (toRational y) -- | It's not correct to use Num here, but I really don't want to have -- to define my own addition and subtraction. diff --git a/src/Vector.hs b/src/Vector.hs index 97bb5d8..6953031 100644 --- a/src/Vector.hs +++ b/src/Vector.hs @@ -8,17 +8,22 @@ where import Data.Number.BigFloat class (Num a) => Vector a where - norm :: RealFrac b => a -> b + norm_2 :: RealFrac b => a -> b + norm_infty :: RealFrac b => a -> b -- Define instances for common numeric types. instance Vector Integer where - norm = fromInteger + norm_2 = fromInteger + norm_infty = fromInteger instance Vector Rational where - norm = fromRational + norm_2 = fromRational + norm_infty = fromRational instance Epsilon e => Vector (BigFloat e) where - norm = fromRational . toRational + norm_2 = fromRational . toRational + norm_infty = fromRational . toRational instance Vector Double where - norm = fromRational . toRational + norm_2 = fromRational . toRational + norm_infty = fromRational . toRational