From: Michael Orlitzky Date: Thu, 21 Feb 2013 04:08:56 +0000 (-0500) Subject: Fix compiler warnings and doctests. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=2f54e89d36e835c58efcc281741632d457859b20;p=numerical-analysis.git Fix compiler warnings and doctests. --- diff --git a/src/BigFloat.hs b/src/BigFloat.hs index 0bebab9..4c57aad 100644 --- a/src/BigFloat.hs +++ b/src/BigFloat.hs @@ -1,7 +1,8 @@ {-# LANGUAGE RebindableSyntax #-} module BigFloat - (module Data.Number.BigFloat) + (module Data.Number.BigFloat, + R) where import Data.Number.BigFloat diff --git a/src/Integration/Simpson.hs b/src/Integration/Simpson.hs index c3d59ff..c9ad414 100644 --- a/src/Integration/Simpson.hs +++ b/src/Integration/Simpson.hs @@ -6,10 +6,7 @@ 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 @@ -26,6 +23,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 @@ -56,6 +54,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 +63,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 diff --git a/src/Integration/Trapezoid.hs b/src/Integration/Trapezoid.hs index c358fef..444d92d 100644 --- a/src/Integration/Trapezoid.hs +++ b/src/Integration/Trapezoid.hs @@ -6,10 +6,8 @@ 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 @@ -48,11 +46,13 @@ trapezoid_1 f a b = -- -- Examples: -- +-- >>> import Algebra.Absolute (abs) -- >>> let f x = x^2 -- >>> let area = trapezoid 1000 f (-1) 1 -- >>> abs (area - (2/3)) < 0.00001 -- True -- +-- >>> import Algebra.Absolute (abs) -- >>> let area = trapezoid 1000 sin 0 pi -- >>> abs (area - 2) < 0.0001 -- True diff --git a/src/Linear/Matrix.hs b/src/Linear/Matrix.hs index ef0e9b6..4f2e845 100644 --- a/src/Linear/Matrix.hs +++ b/src/Linear/Matrix.hs @@ -16,20 +16,16 @@ import Data.Vector.Fixed ( Vector ) import qualified Data.Vector.Fixed as V ( - Fun(..), N1, and, - eq, - foldl, fromList, length, map, - maximum, replicate, toList, zipWith ) -import Data.Vector.Fixed.Internal (Arity, arity, S, Dim) +import Data.Vector.Fixed.Internal (Arity, arity, S) import Linear.Vector import Normed @@ -37,13 +33,9 @@ import NumericPrelude hiding ((*), abs) import qualified NumericPrelude as NP ((*)) import qualified Algebra.Algebraic as Algebraic import Algebra.Algebraic (root) -import qualified Algebra.Absolute as Absolute import qualified Algebra.Additive as Additive import qualified Algebra.Ring as Ring -import Algebra.Absolute (abs) -import qualified Algebra.Field as Field import qualified Algebra.Module as Module -import qualified Algebra.RealField as RealField import qualified Algebra.RealRing as RealRing import qualified Algebra.ToRational as ToRational import qualified Algebra.Transcendental as Transcendental @@ -294,7 +286,7 @@ instance (Ring.C a, => Ring.C (Mat v w a) where -- The first * is ring multiplication, the second is matrix -- multiplication. - m1 * m2 = m1 * m1 + m1 * m2 = m1 * m2 instance (Ring.C a, @@ -359,13 +351,13 @@ instance (Algebraic.C a, -- -- >>> import Roots.Simple -- >>> let h = 0.5 :: Double --- >>> let g1 (Mat (D2 (D1 x) (D1 y))) = 1.0 + h*exp(-(x^2))/(1.0 + y^2) --- >>> let g2 (Mat (D2 (D1 x) (D1 y))) = 0.5 + h*atan(x^2 + y^2) +-- >>> let g1 (Mat (D2 (D1 x) (D1 y))) = 1.0 + h NP.* exp(-(x^2))/(1.0 + y^2) +-- >>> let g2 (Mat (D2 (D1 x) (D1 y))) = 0.5 + h NP.* atan(x^2 + y^2) -- >>> let g u = vec2d ((g1 u), (g2 u)) -- >>> let u0 = vec2d (1.0, 1.0) -- >>> let eps = 1/(10^9) -- >>> fixed_point g eps u0 --- (1.0728549599342185,1.0820591495686167) +-- ((1.0728549599342185),(1.0820591495686167)) -- vec2d :: (a,a) -> Mat D2 D1 a vec2d (x,y) = Mat (D2 (D1 x) (D1 y)) diff --git a/src/Linear/Vector.hs b/src/Linear/Vector.hs index d728334..aba9e5f 100644 --- a/src/Linear/Vector.hs +++ b/src/Linear/Vector.hs @@ -7,7 +7,6 @@ module Linear.Vector where -import Data.List (intercalate) import Data.Vector.Fixed ( Dim, Fun(..), @@ -24,8 +23,6 @@ import qualified Data.Vector.Fixed as V ( length, ) -import Normed - -- * Low-dimension vector wrappers. -- diff --git a/src/Normed.hs b/src/Normed.hs index 3752edc..8b48295 100644 --- a/src/Normed.hs +++ b/src/Normed.hs @@ -13,7 +13,6 @@ 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 diff --git a/src/ODE/IVP.hs b/src/ODE/IVP.hs index b4fd3dc..615c668 100644 --- a/src/ODE/IVP.hs +++ b/src/ODE/IVP.hs @@ -14,7 +14,6 @@ where import Misc (partition) import NumericPrelude hiding (abs) -import Algebra.Absolute (abs) import qualified Algebra.Field as Field import qualified Algebra.ToInteger as ToInteger import qualified Algebra.ToRational as ToRational @@ -54,6 +53,7 @@ eulers_method1 x0 y0 f h = -- -- Examples: -- +-- >>> import Algebra.Absolute (abs) -- >>> let x0 = 0.0 -- >>> let xN = 1.0 -- >>> let y0 = 1.0 diff --git a/src/Roots/Fast.hs b/src/Roots/Fast.hs index 0deb1fd..b3b5818 100644 --- a/src/Roots/Fast.hs +++ b/src/Roots/Fast.hs @@ -16,7 +16,6 @@ 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 @@ -118,7 +117,7 @@ fixed_point_iterations f x0 = -- We also return the number of iterations required. -- fixed_point_with_iterations :: (Normed a, - Algebraic.C a, + Additive.C a, RealField.C b, Algebraic.C b) => (a -> a) -- ^ The function @f@ to iterate. diff --git a/src/Roots/Simple.hs b/src/Roots/Simple.hs index d3c10cd..414b777 100644 --- a/src/Roots/Simple.hs +++ b/src/Roots/Simple.hs @@ -18,7 +18,6 @@ import Normed import qualified Roots.Fast as F 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 @@ -89,7 +88,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. -- -fixed_point :: (Normed a, Algebraic.C a, Algebraic.C b, RealField.C b) +fixed_point :: (Normed a, Additive.C a, Algebraic.C b, RealField.C b) => (a -> a) -- ^ The function @f@ to iterate. -> b -- ^ The tolerance, @epsilon@. -> a -- ^ The initial value @x0@. @@ -103,7 +102,7 @@ fixed_point f epsilon x0 = -- @epsilon@. We delegate to the version that returns the number of -- iterations and simply discard the fixed point. fixed_point_iteration_count :: (Normed a, - Algebraic.C a, + Additive.C a, RealField.C b, Algebraic.C b) => (a -> a) -- ^ The function @f@ to iterate.