From: Michael Orlitzky Date: Mon, 3 Feb 2014 02:10:01 +0000 (-0500) Subject: Clean up imports everywhere. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=ae914d13235a4582077a5cb2b1edd630d9c6ad62;p=numerical-analysis.git Clean up imports everywhere. --- diff --git a/src/Integration/Simpson.hs b/src/Integration/Simpson.hs index 6bfe258..f0f57f2 100644 --- a/src/Integration/Simpson.hs +++ b/src/Integration/Simpson.hs @@ -1,14 +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 qualified Algebra.RealField as RealField -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@]. diff --git a/src/Integration/Trapezoid.hs b/src/Integration/Trapezoid.hs index 06350fc..df4da78 100644 --- a/src/Integration/Trapezoid.hs +++ b/src/Integration/Trapezoid.hs @@ -1,15 +1,19 @@ +{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE RebindableSyntax #-} -module Integration.Trapezoid +module Integration.Trapezoid ( + trapezoid, + trapezoid_1 ) where -import Misc (partition) +import Misc ( partition ) + +import NumericPrelude hiding ( abs ) +import qualified Algebra.Field as Field ( C ) +import qualified Algebra.RealField as RealField ( C ) +import qualified Algebra.ToInteger as ToInteger ( C ) +import qualified Algebra.ToRational as ToRational ( C ) -import NumericPrelude hiding (abs) -import qualified Algebra.Field as Field -import qualified Algebra.RealField as RealField -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@]. diff --git a/src/Linear/Iteration.hs b/src/Linear/Iteration.hs index 7daf3b6..06d30a8 100644 --- a/src/Linear/Iteration.hs +++ b/src/Linear/Iteration.hs @@ -1,24 +1,42 @@ +{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} -- | Classical iterative methods to solve the system Ax = b. -module Linear.Iteration +module Linear.Iteration ( + gauss_seidel_iteration, + gauss_seidel_iterations, + gauss_seidel_method, + jacobi_iteration, + jacobi_iterations, + jacobi_method, + rayleigh_quotient, + sor_iteration, + sor_iterations, + sor_method ) where -import Data.List (find) -import Data.Maybe (fromJust) -import Data.Vector.Fixed (Arity, N1, S) -import NumericPrelude hiding ((*)) -import qualified Algebra.Algebraic as Algebraic -import qualified Algebra.Field as Field -import qualified Algebra.RealField as RealField -import qualified Algebra.ToRational as ToRational -import qualified Prelude as P +import Data.List ( find ) +import Data.Maybe ( fromJust ) +import Data.Vector.Fixed ( Arity, N1, S ) +import NumericPrelude hiding ( (*) ) +import qualified Algebra.Algebraic as Algebraic ( C ) +import qualified Algebra.Field as Field ( C ) +import qualified Algebra.RealField as RealField ( C ) +import qualified Algebra.ToRational as ToRational ( C ) + +import Linear.Matrix ( + Mat(..), + (!!!), + (*), + diagonal_part, + dot, + lt_part_strict, + transpose ) +import Linear.System ( forward_substitute ) +import Normed ( Normed(..) ) -import Linear.Matrix -import Linear.System -import Normed -- | A generalized implementation for Jacobi, Gauss-Seidel, etc. All -- that we really need to know is how to construct the matrix M, so we @@ -97,6 +115,8 @@ gauss_seidel_iterations matrix b = -- -- Examples: -- +-- >>> import Linear.Matrix ( Mat2, fromList, vec2d ) +-- -- >>> let m = fromList [[4,2],[2,2]] :: Mat2 Double -- >>> let x0 = vec2d (0, 0::Double) -- >>> let b = vec2d (1, 1::Double) @@ -131,6 +151,8 @@ jacobi_iterations matrix b = -- -- Examples: -- +-- >>> import Linear.Matrix ( Mat2, fromList, vec2d ) +-- -- >>> let m = fromList [[4,2],[2,2]] :: Mat2 Double -- >>> let x0 = vec2d (0, 0::Double) -- >>> let b = vec2d (1, 1::Double) @@ -160,6 +182,8 @@ jacobi_method = -- -- Examples: -- +-- >>> import Linear.Matrix ( Mat2, fromList, vec2d ) +-- -- >>> let m = fromList [[4,2],[2,2]] :: Mat2 Double -- >>> let x0 = vec2d (0, 0::Double) -- >>> let b = vec2d (1, 1::Double) @@ -190,6 +214,8 @@ gauss_seidel_method = -- -- Examples: -- +-- >>> import Linear.Matrix ( Mat2, fromList, vec2d ) +-- -- >>> let m = fromList [[4,2],[2,2]] :: Mat2 Double -- >>> let x0 = vec2d (0, 0::Double) -- >>> let b = vec2d (1, 1::Double) @@ -268,6 +294,8 @@ classical_method iterations_function matrix b x0 epsilon = -- -- Examples: -- +-- >>> import Linear.Matrix ( Mat2, fromList, vec2d ) +-- -- >>> let m = fromList [[3,1],[1,2]] :: Mat2 Rational -- >>> let v = vec2d (1, 1::Rational) -- >>> rayleigh_quotient m v diff --git a/src/Linear/Matrix.hs b/src/Linear/Matrix.hs index c6f4a83..ea6bc57 100644 --- a/src/Linear/Matrix.hs +++ b/src/Linear/Matrix.hs @@ -44,23 +44,23 @@ import qualified Data.Vector.Fixed as V ( toList, zipWith ) -import Data.Vector.Fixed.Cont (Arity, arity) -import Linear.Vector -import Normed +import Data.Vector.Fixed.Cont ( Arity, arity ) +import Linear.Vector ( Vec, delete, element_sum ) +import Normed ( Normed(..) ) import NumericPrelude hiding ( (*), abs ) import qualified NumericPrelude as NP ( (*) ) import qualified Algebra.Absolute as Absolute ( C ) import Algebra.Absolute ( abs ) -import qualified Algebra.Additive as Additive -import qualified Algebra.Algebraic as Algebraic -import Algebra.Algebraic (root) -import qualified Algebra.Ring as Ring -import qualified Algebra.Module as Module -import qualified Algebra.RealRing as RealRing -import qualified Algebra.ToRational as ToRational -import qualified Algebra.Transcendental as Transcendental -import qualified Prelude as P +import qualified Algebra.Additive as Additive ( C ) +import qualified Algebra.Algebraic as Algebraic ( C ) +import Algebra.Algebraic ( root ) +import qualified Algebra.Ring as Ring ( C ) +import qualified Algebra.Module as Module ( C ) +import qualified Algebra.RealRing as RealRing ( C ) +import qualified Algebra.ToRational as ToRational ( C ) +import qualified Algebra.Transcendental as Transcendental ( C ) +import qualified Prelude as P ( map ) data Mat m n a = (Arity m, Arity n) => Mat (Vec m (Vec n a)) type Mat1 a = Mat N1 N1 a diff --git a/src/Linear/QR.hs b/src/Linear/QR.hs index ea72958..283512a 100644 --- a/src/Linear/QR.hs +++ b/src/Linear/QR.hs @@ -12,7 +12,6 @@ import qualified Algebra.Ring as Ring ( C ) import qualified Algebra.Algebraic as Algebraic ( C ) import Data.Vector.Fixed ( ifoldl ) import Data.Vector.Fixed.Cont ( Arity ) -import Debug.Trace import NumericPrelude hiding ( (*) ) import Linear.Matrix ( @@ -98,6 +97,9 @@ givens_rotator i j xi xj = -- factorization. We keep the pair updated by multiplying @q@ and -- @r@ by the new rotator (or its transpose). -- +-- We do not require that the diagonal elements of R are positive, +-- so our factorization is a little less unique than usual. +-- -- Examples: -- -- >>> import Linear.Matrix diff --git a/src/Linear/System.hs b/src/Linear/System.hs index 85a1dd4..2d75f61 100644 --- a/src/Linear/System.hs +++ b/src/Linear/System.hs @@ -2,16 +2,17 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} -module Linear.System +module Linear.System ( + backward_substitute, + forward_substitute ) where -import Data.Vector.Fixed (Arity, N1) +import Data.Vector.Fixed ( Arity, N1 ) +import NumericPrelude hiding ( (*), abs ) +import qualified NumericPrelude as NP ( (*) ) +import qualified Algebra.Field as Field ( C ) -import Linear.Matrix - -import NumericPrelude hiding ((*), abs) -import qualified NumericPrelude as NP ((*)) -import qualified Algebra.Field as Field +import Linear.Matrix ( Mat(..), (!!!), construct, transpose ) -- | Solve the system m' * x = b', where m' is upper-triangular. Will @@ -19,6 +20,8 @@ import qualified Algebra.Field as Field -- -- Examples: -- +-- >>> import Linear.Matrix ( Mat2, Mat3, fromList, vec2d, vec3d ) +-- -- >>> let identity = fromList [[1,0,0],[0,1,0],[0,0,1]] :: Mat3 Double -- >>> let b = vec3d (1, 2, 3::Double) -- >>> forward_substitute identity b @@ -69,6 +72,8 @@ forward_substitute m' b' = x' -- -- Examples: -- +-- >>> import Linear.Matrix ( Mat3, fromList, vec3d ) +-- -- >>> let identity = fromList [[1,0,0],[0,1,0],[0,0,1]] :: Mat3 Double -- >>> let b = vec3d (1, 2, 3::Double) -- >>> backward_substitute identity b diff --git a/src/Misc.hs b/src/Misc.hs index bf8414d..c81d359 100644 --- a/src/Misc.hs +++ b/src/Misc.hs @@ -6,9 +6,9 @@ module Misc where import NumericPrelude -import Algebra.Field -import Algebra.RealRing -import Algebra.ToInteger +import Algebra.Field ( C ) +import Algebra.RealRing ( C ) +import Algebra.ToInteger ( C ) -- | Partition the interval [@a@, @b@] into @n@ subintervals, which we -- then return as a list of pairs. diff --git a/src/Normed.hs b/src/Normed.hs index 6f34a8d..21c275f 100644 --- a/src/Normed.hs +++ b/src/Normed.hs @@ -10,11 +10,11 @@ import BigFloat import NumericPrelude hiding ( abs ) import Algebra.Absolute ( abs ) -import qualified Algebra.Absolute as Absolute -import qualified Algebra.Algebraic as Algebraic +import qualified Algebra.Absolute as Absolute ( C ) +import qualified Algebra.Algebraic as Algebraic ( C ) import Algebra.Algebraic ( root ) -import qualified Algebra.RealField as RealField -import qualified Algebra.ToInteger as ToInteger +import qualified Algebra.RealField as RealField ( C ) +import qualified Algebra.ToInteger as ToInteger ( C ) import qualified Algebra.ToRational as ToRational ( C ) import Data.Vector.Fixed ( S, Z ) import qualified Data.Vector.Fixed as V ( @@ -25,11 +25,15 @@ import Data.Vector.Fixed.Boxed ( Vec ) import Linear.Vector ( element_sum ) + +-- | Instances of the 'Normed' class know how to compute their own +-- p-norms for p=1,2,...,infinity. +-- 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 2-norm. norm :: (Algebraic.C b, Absolute.C b) => a -> b norm = norm_p (2 :: Integer) diff --git a/src/ODE/IVP.hs b/src/ODE/IVP.hs index 615c668..6f798f4 100644 --- a/src/ODE/IVP.hs +++ b/src/ODE/IVP.hs @@ -9,15 +9,18 @@ -- for x in [x0, xN]. -- -module ODE.IVP +module ODE.IVP ( + eulers_method, + eulers_method1, + eulers_methodH ) where -import Misc (partition) -import NumericPrelude hiding (abs) -import qualified Algebra.Field as Field -import qualified Algebra.ToInteger as ToInteger -import qualified Algebra.ToRational as ToRational -import qualified Algebra.RealField as RealField +import Misc ( partition ) +import NumericPrelude hiding ( abs ) +import qualified Algebra.Field as Field ( C ) +import qualified Algebra.ToInteger as ToInteger ( C ) +import qualified Algebra.ToRational as ToRational ( C ) +import qualified Algebra.RealField as RealField ( C ) -- | A single iteration of Euler's method over the interval -- [$x0$, $x0$+$h$]. diff --git a/src/Polynomials/Orthogonal.hs b/src/Polynomials/Orthogonal.hs index 28cf41d..4ea0b68 100644 --- a/src/Polynomials/Orthogonal.hs +++ b/src/Polynomials/Orthogonal.hs @@ -21,11 +21,12 @@ -- -- where w(x) is some non-negative (or non-positive) weight function. -- -module Polynomials.Orthogonal +module Polynomials.Orthogonal ( + legendre ) where import NumericPrelude -import qualified Algebra.RealField as RealField +import qualified Algebra.RealField as RealField ( C ) import qualified Prelude as P diff --git a/src/Roots/Fast.hs b/src/Roots/Fast.hs index 8b69786..e5321c9 100644 --- a/src/Roots/Fast.hs +++ b/src/Roots/Fast.hs @@ -5,20 +5,26 @@ -- values to the next iteration of a function rather than passing -- the function and the points at which to (re)evaluate it. -module Roots.Fast +module Roots.Fast ( + bisect, + fixed_point_iterations, + fixed_point_with_iterations, + has_root, + trisect ) where -import Data.List (find) -import Data.Maybe (fromMaybe) +import Data.List ( find ) +import Data.Maybe ( fromMaybe ) -import Normed +import Normed ( Normed(..) ) + +import NumericPrelude hiding ( abs ) +import qualified Algebra.Absolute as Absolute ( C ) +import qualified Algebra.Additive as Additive ( C ) +import qualified Algebra.Algebraic as Algebraic ( C ) +import qualified Algebra.RealRing as RealRing ( C ) +import qualified Algebra.RealField as RealField ( C ) -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.RealRing as RealRing -import qualified Algebra.RealField as RealField has_root :: (RealField.C a, RealRing.C b, diff --git a/src/Roots/Simple.hs b/src/Roots/Simple.hs index 03b39ae..a5924f4 100644 --- a/src/Roots/Simple.hs +++ b/src/Roots/Simple.hs @@ -8,22 +8,34 @@ -- where f is assumed to be continuous on the interval of interest. -- -module Roots.Simple +module Roots.Simple ( + bisect, + fixed_point, + fixed_point_error_ratios, + fixed_point_iteration_count, + has_root, + newtons_method, + secant_method, + trisect ) where import Data.List (find) +import NumericPrelude hiding ( abs ) +import Algebra.Absolute ( abs ) +import qualified Algebra.Additive as Additive ( C ) +import qualified Algebra.Algebraic as Algebraic ( C ) +import qualified Algebra.Field as Field ( C ) +import qualified Algebra.RealField as RealField ( C ) +import qualified Algebra.RealRing as RealRing ( C ) -import Normed +import Normed ( Normed(..) ) +import qualified Roots.Fast as F ( + bisect, + fixed_point_iterations, + fixed_point_with_iterations, + has_root, + trisect ) -import qualified Roots.Fast as F - -import NumericPrelude hiding (abs) -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 -- | Does the (continuous) function @f@ have a root on the interval -- [a,b]? If f(a) <] 0 and f(b) ]> 0, we know that there's a root in