Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
simplify taylor, scanl1 instead of mapAccumL
  • Loading branch information
barak committed Apr 10, 2009
1 parent 80170eb commit 1455648
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions Numeric/FAD.hs
Expand Up @@ -83,7 +83,7 @@ module Numeric.FAD (
taylor, taylor2)
where

import Data.List (transpose, mapAccumL)
import Data.List (transpose)
import Data.Foldable (Foldable)
import qualified Data.Foldable (all)
import List.Uttl (zipWithDefaults)
Expand Down Expand Up @@ -725,24 +725,24 @@ show2d = ("["++) . (++"]\n") . (foldl1 $ (++) . (++"\n ")) . map show
-- EXAMPLE: @taylor exp 0 1@
taylor :: Fractional a => (forall tag. Tower tag a -> Tower tag a) -> a -> a -> [a]

taylor f x dx = snd
$ mapAccumL (\a x -> app2 (,) $ a+x) 0
$ zipWith3 (\x y z -> x*y*z)
(diffsUU f x)
recipFactorials
(powers dx)
taylor f x dx = scanl1 (+)
$ zipWith3 (\x y z -> x*y*z)
(diffsUU f x)
recipFactorials
(powers dx)
where
powers x = iterate (*x) 1
recipFactorials = snd $ mapAccumL (\a i -> (a/fromIntegral i, a)) 1 [1..]
app2 f x = f x x
recipFactorials = scanl (/) 1 $ map fromIntegral [1..]

-- | The 'taylor2' function evaluates a two-dimensional Taylor series
-- of the given function. This is calculated by nested application of
-- the 'taylor' function, and the exported signature reflects this.

taylor2 :: Fractional a =>
(forall tag0 tag.
Tower tag0 (Tower tag a) -> Tower tag0 (Tower tag a) -> Tower tag0 (Tower tag a))
Tower tag0 (Tower tag a)
-> Tower tag0 (Tower tag a)
-> Tower tag0 (Tower tag a))
-> a -> a -> a -> a -> [[a]]

taylor2 f x y dx dy =
Expand Down

0 comments on commit 1455648

Please sign in to comment.