Skip to content

Instantly share code, notes, and snippets.

@eunomie

eunomie/taylor.elm

Last active Feb 26, 2016
Embed
What would you like to do?
import List exposing (sum, map, foldl)
pow : Float -> Float -> Float
pow num p =
if p == 0 then
1
else if p > 0 then
num * (pow num (p - 1))
else
1 / num * (pow num (p + 1))
fact : Float -> Float
fact x = if x <= 0 then 1 else x * fact(x - 1)
sine : Float -> Float
sine x =
sum (map (\i -> (pow -1 i) * (pow x (i * 2 + 1)) / (fact (i * 2 + 1))) [0..9])
sinefold : Float -> Float
sinefold x =
foldl (\i sum -> sum + (pow -1 i) * (pow x (i * 2 + 1)) / (fact (i * 2 + 1))) 0 [0..9]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.