]> gitweb.michael.orlitzky.com - numerical-analysis.git/blobdiff - src/Integration/Trapezoid.hs
Convert Integration/Simpson.hs and Integration/Trapezoid.hs to numeric-prelude.
[numerical-analysis.git] / src / Integration / Trapezoid.hs
index 5452a5e8a5fe70195cf3de6711934dadd8cb623d..c358feffec5d536f913d8e3a1c080391b17762d4 100644 (file)
@@ -1,8 +1,18 @@
+{-# LANGUAGE RebindableSyntax #-}
+
 module Integration.Trapezoid
 where
 
 import Misc (partition)
 
+import NumericPrelude hiding (abs)
+import Algebra.Absolute (abs)
+import qualified Algebra.Field as Field
+import qualified Algebra.RealField as RealField
+import qualified Algebra.RealRing as RealRing
+import qualified Algebra.ToInteger as ToInteger
+import qualified Algebra.ToRational as ToRational
+
 -- | Use the trapezoid rule to numerically integrate @f@ over the
 --   interval [@a@, @b@].
 --
@@ -24,13 +34,13 @@ import Misc (partition)
 --   >>> trapezoid_1 f (-1) 1
 --   2.0
 --
-trapezoid_1 :: (RealFrac a, Fractional b, Num b)
+trapezoid_1 :: (Field.C a, ToRational.C a, Field.C b)
             => (a -> b) -- ^ The function @f@
             -> a       -- ^ The \"left\" endpoint, @a@
             -> a       -- ^ The \"right\" endpoint, @b@
             -> b
 trapezoid_1 f a b =
-  (((f a) + (f b)) / 2) * (realToFrac (b - a))
+  (((f a) + (f b)) / 2) * (fromRational' $ toRational (b - a))
 
 
 -- | Use the composite trapezoid rule to numerically integrate @f@
@@ -47,7 +57,11 @@ trapezoid_1 f a b =
 --   >>> abs (area - 2) < 0.0001
 --   True
 --
-trapezoid :: (RealFrac a, Fractional b, Num b, Integral c)
+trapezoid :: (RealField.C a,
+              ToRational.C a,
+              RealField.C b,
+              ToInteger.C c,
+              Enum c)
           => c -- ^ The number of subintervals to use, @n@
           -> (a -> b) -- ^ The function @f@
           -> a       -- ^ The \"left\" endpoint, @a@