Created
January 31, 2017 16:06
-
-
Save dpiponi/aa7b713da7c822c04193095397b70bb4 to your computer and use it in GitHub Desktop.
Compute formal power series for functional square root of sin function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Ratio | |
(^+) a b = zipWith (+) a b | |
(^-) a b = zipWith (-) a b | |
(a : as) `convolve` (b : bs) = (a * b) : | |
((map (a *) bs) ^+ (as `convolve` (b : bs))) | |
compose (f : fs) (0 : gs) = f : (gs `convolve` (compose fs (0 : gs))) | |
integrate x = 0 : zipWith (/) x (map fromInteger [1..]) | |
sin' = integrate cos' | |
cos' = let _ : cos'' = map negate (integrate sin') in 1 : cos'' | |
delta (g : gs) h = let g' = delta gs h | |
in (0 : ((1 : h) `convolve` g')) ^+ gs | |
fsqrt (0 : 1 : fs) = | |
let gs = map (/ 2) $ fs ^- (0 : gs `convolve` | |
((0 : delta gs gs) ^+ | |
((2 : gs) `convolve` (gs `compose` g)))) | |
g = 0 : 1 : gs | |
in g | |
type Q = Ratio Integer | |
type R = Double | |
main = mapM_ print $ zip [0..] (fsqrt sin' :: [Q]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment