]> gitweb.michael.orlitzky.com - numerical-analysis.git/commitdiff
Remove assumptions on the Normed class.
authorMichael Orlitzky <michael@orlitzky.com>
Thu, 21 Feb 2013 02:46:56 +0000 (21:46 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Thu, 21 Feb 2013 02:46:56 +0000 (21:46 -0500)
src/Normed.hs
src/Roots/Fast.hs
src/Roots/Simple.hs

index 8554bd97f2eba0bd66a4b458a05cdb334f2e4f87..3752edc04b9fef7fa04f3ec5fd9a074d5789a0bb 100644 (file)
@@ -1,5 +1,6 @@
 {-# LANGUAGE FlexibleInstances #-}
 {-# LANGUAGE RebindableSyntax #-}
 {-# LANGUAGE FlexibleInstances #-}
 {-# LANGUAGE RebindableSyntax #-}
+
 -- | The 'Normed' class represents elements of a normed vector
 --   space. We define instances for all common numeric types.
 module Normed
 -- | The 'Normed' class represents elements of a normed vector
 --   space. We define instances for all common numeric types.
 module Normed
@@ -8,27 +9,23 @@ where
 import BigFloat
 
 import NumericPrelude hiding (abs)
 import BigFloat
 
 import NumericPrelude hiding (abs)
-import Algebra.Absolute
-import Algebra.Field
-import Algebra.Ring
-import Algebra.ToInteger
+import Algebra.Absolute (abs)
+import qualified Algebra.Absolute as Absolute
+import qualified Algebra.Algebraic as Algebraic
+import qualified Algebra.RealField as RealField
+import qualified Algebra.RealRing as RealRing
+import qualified Algebra.ToInteger as ToInteger
 
 -- Since the norm is defined on a vector space, we should be able to
 -- add and subtract anything on which a norm is defined. Of course
 -- 'Num' is a bad choice here, but we really prefer to use the normal
 -- addition and subtraction operators.
 
 -- Since the norm is defined on a vector space, we should be able to
 -- add and subtract anything on which a norm is defined. Of course
 -- 'Num' is a bad choice here, but we really prefer to use the normal
 -- addition and subtraction operators.
-class (Algebra.Ring.C a, Algebra.Absolute.C a) => Normed a where
-  norm_p :: (Algebra.ToInteger.C c,
-             Algebra.Field.C b,
-             Algebra.Absolute.C b)
-            => c -> a -> b
-
-  norm_infty :: (Algebra.Field.C b,
-                 Algebra.Absolute.C b)
-                => a -> b
+class Normed a where
+  norm_p :: (ToInteger.C c, Algebraic.C b, Absolute.C b) => c -> a -> b
+  norm_infty :: (RealField.C b) => a -> b
 
   -- | The "usual" norm. Defaults to the Euclidean norm.
 
   -- | The "usual" norm. Defaults to the Euclidean norm.
-  norm :: (Algebra.Field.C b, Algebra.Absolute.C b) => a -> b
+  norm :: (Algebraic.C b, Absolute.C b) => a -> b
   norm = norm_p (2 :: Integer)
 
 -- Define instances for common numeric types.
   norm = norm_p (2 :: Integer)
 
 -- Define instances for common numeric types.
index 78c299ad6a2cc39629b409bff5eed86787a3ca20..0deb1fd6237a5909ea7d15a252f09b524093d1bf 100644 (file)
@@ -14,6 +14,8 @@ import Normed
 
 import NumericPrelude hiding (abs)
 import qualified Algebra.Absolute as Absolute
 
 import NumericPrelude hiding (abs)
 import qualified Algebra.Absolute as Absolute
+import qualified Algebra.Additive as Additive
+import qualified Algebra.Algebraic as Algebraic
 import qualified Algebra.Field as Field
 import qualified Algebra.RealRing as RealRing
 import qualified Algebra.RealField as RealField
 import qualified Algebra.Field as Field
 import qualified Algebra.RealRing as RealRing
 import qualified Algebra.RealField as RealField
@@ -116,9 +118,9 @@ fixed_point_iterations f x0 =
 --   We also return the number of iterations required.
 --
 fixed_point_with_iterations :: (Normed a,
 --   We also return the number of iterations required.
 --
 fixed_point_with_iterations :: (Normed a,
-                                Field.C b,
-                                Absolute.C b,
-                                Ord b)
+                                Algebraic.C a,
+                                RealField.C b,
+                                Algebraic.C b)
                             => (a -> a)  -- ^ The function @f@ to iterate.
                             -> b        -- ^ The tolerance, @epsilon@.
                             -> a        -- ^ The initial value @x0@.
                             => (a -> a)  -- ^ The function @f@ to iterate.
                             -> b        -- ^ The tolerance, @epsilon@.
                             -> a        -- ^ The initial value @x0@.
index 0a1debff0a0b1db653efabdf2be00ce9a4b91ed4..d3c10cd8a3dfb95c001aeb5ce244b1bc7f14f7ed 100644 (file)
@@ -20,6 +20,8 @@ import qualified Roots.Fast as F
 import NumericPrelude hiding (abs)
 import qualified Algebra.Absolute as Absolute
 import Algebra.Absolute (abs)
 import NumericPrelude hiding (abs)
 import qualified Algebra.Absolute as Absolute
 import Algebra.Absolute (abs)
+import qualified Algebra.Additive as Additive
+import qualified Algebra.Algebraic as Algebraic
 import qualified Algebra.Field as Field
 import qualified Algebra.RealField as RealField
 import qualified Algebra.RealRing as RealRing
 import qualified Algebra.Field as Field
 import qualified Algebra.RealField as RealField
 import qualified Algebra.RealRing as RealRing
@@ -87,7 +89,7 @@ bisect f a b epsilon =
 --   at x0. We delegate to the version that returns the number of
 --   iterations and simply discard the number of iterations.
 --
 --   at x0. We delegate to the version that returns the number of
 --   iterations and simply discard the number of iterations.
 --
-fixed_point :: (Normed a, RealField.C b)
+fixed_point :: (Normed a, Algebraic.C a, Algebraic.C b, RealField.C b)
             => (a -> a) -- ^ The function @f@ to iterate.
             -> b       -- ^ The tolerance, @epsilon@.
             -> a       -- ^ The initial value @x0@.
             => (a -> a) -- ^ The function @f@ to iterate.
             -> b       -- ^ The tolerance, @epsilon@.
             -> a       -- ^ The initial value @x0@.
@@ -100,7 +102,10 @@ fixed_point f epsilon x0 =
 --   the function @f@ with the search starting at x0 and tolerance
 --   @epsilon@. We delegate to the version that returns the number of
 --   iterations and simply discard the fixed point.
 --   the function @f@ with the search starting at x0 and tolerance
 --   @epsilon@. We delegate to the version that returns the number of
 --   iterations and simply discard the fixed point.
-fixed_point_iteration_count :: (Normed a, RealField.C b)
+fixed_point_iteration_count :: (Normed a,
+                                Algebraic.C a,
+                                RealField.C b,
+                                Algebraic.C b)
                             => (a -> a) -- ^ The function @f@ to iterate.
                             -> b       -- ^ The tolerance, @epsilon@.
                             -> a       -- ^ The initial value @x0@.
                             => (a -> a) -- ^ The function @f@ to iterate.
                             -> b       -- ^ The tolerance, @epsilon@.
                             -> a       -- ^ The initial value @x0@.
@@ -118,7 +123,10 @@ fixed_point_iteration_count f epsilon x0 =
 --
 --   This is used to determine the rate of convergence.
 --
 --
 --   This is used to determine the rate of convergence.
 --
-fixed_point_error_ratios :: (Normed a, RealField.C b)
+fixed_point_error_ratios :: (Normed a,
+                             Additive.C a,
+                             RealField.C b,
+                             Algebraic.C b)
                    => (a -> a) -- ^ The function @f@ to iterate.
                    -> a       -- ^ The initial value @x0@.
                    -> a       -- ^ The true solution, @x_star@.
                    => (a -> a) -- ^ The function @f@ to iterate.
                    -> a       -- ^ The initial value @x0@.
                    -> a       -- ^ The true solution, @x_star@.