]> gitweb.michael.orlitzky.com - numerical-analysis.git/blobdiff - src/Integration/Simpson.hs
Clean up imports everywhere.
[numerical-analysis.git] / src / Integration / Simpson.hs
index c3d59ff797c0538c377a08196065a63b43178003..f0f57f29245db1a7db7bd10bd05a39a87c2347df 100644 (file)
@@ -1,17 +1,17 @@
+{-# LANGUAGE NoImplicitPrelude #-}
 {-# LANGUAGE RebindableSyntax #-}
 
-module Integration.Simpson
+module Integration.Simpson (
+  simpson,
+  simpson_1 )
 where
 
-import Misc (partition)
+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
+import NumericPrelude hiding ( abs )
+import qualified Algebra.RealField as RealField ( C )
+import qualified Algebra.ToInteger as ToInteger ( C )
+import qualified Algebra.ToRational as ToRational ( C )
 
 -- | Use the Simpson's rule to numerically integrate @f@ over the
 --   interval [@a@, @b@].
@@ -26,6 +26,7 @@ import qualified Algebra.ToRational as ToRational
 --   >>> simpson_1 f (-1) 1
 --   0.0
 --
+--   >>> import Algebra.Absolute (abs)
 --   >>> let f x = x^2
 --   >>> let area = simpson_1 f (-1) 1
 --   >>> abs (area - (2/3)) < 1/10^12
@@ -47,7 +48,7 @@ simpson_1 :: (RealField.C a, ToRational.C a, RealField.C b)
 simpson_1 f a b =
   coefficient * ((f a) + 4*(f midpoint) + (f b))
   where
-    coefficient = (fromRational' $ toRational (b - a)) / 6
+    coefficient = fromRational' $ (toRational (b - a)) / 6
     midpoint = (a + b) / 2
 
 
@@ -56,6 +57,7 @@ simpson_1 f a b =
 --
 --   Examples:
 --
+--   >>> import Algebra.Absolute (abs)
 --   >>> let f x = x^4
 --   >>> let area = simpson 10 f (-1) 1
 --   >>> abs (area - (2/5)) < 0.0001
@@ -64,6 +66,7 @@ simpson_1 f a b =
 --   Note that the convergence here is much faster than the Trapezoid
 --   rule!
 --
+--   >>> import Algebra.Absolute (abs)
 --   >>> let area = simpson 10 sin 0 pi
 --   >>> abs (area - 2) < 0.00001
 --   True