]> gitweb.michael.orlitzky.com - numerical-analysis.git/commitdiff
Fix a bunch of hlint warnings.
authorMichael Orlitzky <michael@orlitzky.com>
Sun, 21 Jul 2013 18:25:30 +0000 (14:25 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Sun, 21 Jul 2013 18:25:30 +0000 (14:25 -0400)
src/BigFloat.hs
src/Integration/Simpson.hs
src/Integration/Trapezoid.hs
src/Linear/Matrix.hs
src/Linear/System.hs
src/Linear/Vector.hs
src/Misc.hs
src/Roots/Fast.hs
src/Roots/Simple.hs

index 4c57aadeb1e5f851976cc30414e0a7c6edf3fcea..cc228bead187898a255eae3d3200a4edad546d10 100644 (file)
@@ -22,7 +22,7 @@ type R = BigFloat Prec50
 
 instance Epsilon e => Additive.C (BigFloat e) where
   (+) = (P.+)
-  zero = (P.fromInteger 0)
+  zero = 0
   negate = (P.negate)
 
 instance Epsilon e => Ring.C (BigFloat e) where
index c9ad414b4fa7cc85705af2604d2295524ceeb01e..6bfe258eb8e454b7a9dcc0c7221d4638eed3f61f 100644 (file)
@@ -45,7 +45,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
 
 
index 444d92d2eb9a0ed2e6911970f54cd88aafd71b3a..06350fcf54a70da55ac317610c1a7dca2f3b8a62 100644 (file)
@@ -38,8 +38,9 @@ trapezoid_1 :: (Field.C a, ToRational.C a, Field.C b)
             -> a       -- ^ The \"right\" endpoint, @b@
             -> b
 trapezoid_1 f a b =
-  (((f a) + (f b)) / 2) * (fromRational' $ toRational (b - a))
-
+  (((f a) + (f b)) / 2) * coerced_interval_length
+  where
+    coerced_interval_length = fromRational' $ toRational (b - a)
 
 -- | Use the composite trapezoid rule to numerically integrate @f@
 --   over @n@ subintervals of [@a@, @b@].
index 20769b4708950d103bd0ec1fd18737d9616cb0ca..105acef6cc78a86914f66d68b158fce02c7e8eee 100644 (file)
@@ -431,7 +431,7 @@ instance (Algebraic.C a,
   --   5.0
   --
   norm_p p (Mat rows) =
-    (root p') $ sum [(fromRational' $ toRational x)^p' | x <- xs]
+    (root p') $ sum [fromRational' (toRational x)^p' | x <- xs]
     where
       p' = toInteger p
       xs = concat $ V.toList $ V.map V.toList rows
index f49c652e494d769ed4be5e69db9d468abbef8d72..85a1dd4b4a619affd6401a5d0e890e19ac007efc 100644 (file)
@@ -80,8 +80,8 @@ backward_substitute :: (Field.C a, Arity m)
                     => Mat m m a
                     -> Mat m N1 a
                     -> Mat m N1 a
-backward_substitute m =
-  forward_substitute (transpose m) b
+backward_substitute m =
+  forward_substitute (transpose m)
 
 
 -- | Solve the linear system m*x = b where m is positive definite.
index 42d47a39e58670136b5300dd1f83f007ce85fc2e..e4f622588bbd01ee5657465a78daf2d46aa4c7de 100644 (file)
@@ -55,9 +55,14 @@ type Vec5 = Vec N5
 --   >>> delete b 1 :: Vec2 Int
 --   fromList [1,3]
 --
-delete :: (Vector v a, Vector w a, Dim v ~ S (Dim w)) => v a -> Int -> w a
+delete :: (Vector v a,
+           Vector w a,
+           Dim v ~ S (Dim w))
+       => v a
+       -> Int
+       -> w a
 delete v1 idx =
-  fromList (lhalf ++ rhalf')
+  fromList (lhalf ++ rhalf')
   where
     (lhalf, rhalf) = splitAt idx (toList v1)
     rhalf' = tail rhalf
index ddaad6e3ba7061f9a3ee2c119998058b3d298201..bf8414d8e859d671e5c5c8794e63ea31680f4b0a 100644 (file)
@@ -36,7 +36,8 @@ partition n a b
                  let xi = a + k'*h,
                  let xj = a + (k'+1)*h ]
     where
-      h = (b-a)/(fromIntegral $ toInteger n)
+      coerced_n = fromIntegral $ toInteger n
+      h = (b-a)/coerced_n
 
 
 -- | Compute the unit roundoff (machine epsilon) for this machine. We
index f7cde8a82a70f3f98605ab87fc94fae5a59147dc..8b69786379218b12448b114d4183ca9c3ef64c5d 100644 (file)
@@ -9,6 +9,7 @@ module Roots.Fast
 where
 
 import Data.List (find)
+import Data.Maybe (fromMaybe)
 
 import Normed
 
@@ -30,33 +31,20 @@ has_root :: (RealField.C a,
          -> Maybe b -- ^ Precoumpted f(a)
          -> Maybe b -- ^ Precoumpted f(b)
          -> Bool
-has_root f a b epsilon f_of_a f_of_b =
-  if not ((signum (f_of_a')) * (signum (f_of_b')) == 1) then
-    -- We don't care about epsilon here, there's definitely a root!
-    True
-  else
-    if (b - a) <= epsilon' then
-      -- Give up, return false.
-      False
-    else
-      -- If either [a,c] or [c,b] have roots, we do too.
+has_root f a b epsilon f_of_a f_of_b
+  | (signum (f_of_a')) * (signum (f_of_b')) /= 1 = True
+  | (b - a) <= epsilon' = False
+  | otherwise =
       (has_root f a c (Just epsilon') (Just f_of_a') Nothing) ||
         (has_root f c b (Just epsilon') Nothing (Just f_of_b'))
   where
     -- If the size of the smallest subinterval is not specified,
     -- assume we just want to check once on all of [a,b].
-    epsilon' = case epsilon of
-                 Nothing -> (b-a)
-                 Just eps -> eps
+    epsilon' = fromMaybe (b-a) epsilon
 
     -- Compute f(a) and f(b) only if needed.
-    f_of_a'  = case f_of_a of
-                 Nothing -> f a
-                 Just v -> v
-
-    f_of_b'  = case f_of_b of
-                 Nothing -> f b
-                 Just v -> v
+    f_of_a'  = fromMaybe (f a) f_of_a
+    f_of_b'  = fromMaybe (f b) f_of_b
 
     c = (a + b)/2
 
@@ -87,13 +75,8 @@ bisect f a b epsilon f_of_a f_of_b
         else bisect f c b epsilon (Just f_of_c') (Just f_of_b')
   where
     -- Compute f(a) and f(b) only if needed.
-    f_of_a'  = case f_of_a of
-                 Nothing -> f a
-                 Just v -> v
-
-    f_of_b'  = case f_of_b of
-                 Nothing -> f b
-                 Just v -> v
+    f_of_a'  = fromMaybe (f a) f_of_a
+    f_of_b'  = fromMaybe (f b) f_of_b
 
     c = (a + b) / 2
 
@@ -118,26 +101,21 @@ trisect f a b epsilon f_of_a f_of_b
   | f_of_b' == 0 = Just b
   | otherwise =
       -- Use a 'prime' just for consistency.
-    let (a', b', fa', fb') =
-          if (has_root f d b (Just epsilon) (Just f_of_d') (Just f_of_b'))
-          then (d, b, f_of_d', f_of_b')
-          else
-            if (has_root f c d (Just epsilon) (Just f_of_c') (Just f_of_d'))
-            then (c, d, f_of_c', f_of_d')
-            else (a, c, f_of_a', f_of_c')
+    let (a', b', fa', fb')
+          | has_root f d b (Just epsilon) (Just f_of_d') (Just f_of_b') =
+              (d, b, f_of_d', f_of_b')
+          | has_root f c d (Just epsilon) (Just f_of_c') (Just f_of_d') =
+              (c, d, f_of_c', f_of_d')
+          | otherwise =
+              (a, c, f_of_a', f_of_c')
     in
       if (b-a) < 2*epsilon
       then Just ((b+a)/2)
       else trisect f a' b' epsilon (Just fa') (Just fb')
   where
     -- Compute f(a) and f(b) only if needed.
-    f_of_a'  = case f_of_a of
-                 Nothing -> f a
-                 Just v -> v
-
-    f_of_b'  = case f_of_b of
-                 Nothing -> f b
-                 Just v -> v
+    f_of_a'  = fromMaybe (f a) f_of_a
+    f_of_b'  = fromMaybe (f b) f_of_b
 
     c = (2*a + b) / 3
 
@@ -153,8 +131,8 @@ trisect f a b epsilon f_of_a f_of_b
 fixed_point_iterations :: (a -> a) -- ^ The function @f@ to iterate.
                        -> a       -- ^ The initial value @x0@.
                        -> [a]     -- ^ The resulting sequence of x_{n}.
-fixed_point_iterations f x0 =
-  iterate f x0
+fixed_point_iterations =
+  iterate
 
 
 -- | Find a fixed point of the function @f@ with the search starting
index a6aa09e497ba841d2c3a8e0be2749aab27c72662..03b39aeb643de47ed6546693c26346851b80b0fc 100644 (file)
@@ -195,8 +195,8 @@ newton_iterations :: (Field.C a)
                     -> (a -> a) -- ^ The derivative of @f@
                     -> a       -- ^ Initial guess, x-naught
                     -> [a]
-newton_iterations f f' x0 =
-  iterate next x0
+newton_iterations f f' =
+  iterate next
   where
   next xn =
     xn - ( (f xn) / (f' xn) )
@@ -280,8 +280,8 @@ secant_iterations :: (Field.C a)
                     -> a       -- ^ Initial guess, x-naught
                     -> a       -- ^ Second initial guess, x-one
                     -> [a]
-secant_iterations f x0 x1 =
-  iterate2 g x0 x1
+secant_iterations f =
+  iterate2 g
   where
   g prev2 prev1 =
     let x_change = prev1 - prev2