egison-3.7.8: sample/math/analysis/leibniz-formula.egi
(define $f (lambda [$x] x))
(define $multSd
(lambda [$x $f $G]
(let {[$F (Sd x f)]}
(- (* F G)
(Sd x (* f (d/d G x)))))))
(multSd x (cos x) (f x));(+ (* (sin x) x) (* -1 (sin x)))
(multSd x (cos (* 2 x)) (f x));(/ (+ (* 2 (sin (* 2 x)) x) (* -2 (sin (* 2 x)))) 4)
(multSd x (cos (* n x)) (f x));(/ (+ (* (sin (* n x)) x n) (* -1 (sin (* n x)) n)) n^2)
(multSd x (sin x) (f x));(+ (* -1 (cos x) x) (cos x))
(multSd x (sin (* 2 x)) (f x));(/ (+ (* -1 (cos (* 2 x)) x) (cos (* 2 x))) 2)
(multSd x (sin (* n x)) (f x));(/ (+ (* -1 (cos (* n x)) x) (cos (* n x))) n)
(define $as (map (lambda [$n] (let {[$F (multSd x (cos (* n x)) (f x))]}
(/ (- (substitute {[x π]} F) (substitute {[x (* -1 π)]} F))
π)))
nats))
(take 10 as)
;{0 0 0 0 0 0 0 0 0 0}
(define $bs (map (lambda [$n] (let {[$F (multSd x (sin (* n x)) (f x))]}
(/ (- (substitute {[x π]} F) (substitute {[x (* -1 π)]} F))
π)))
(take 10 nats)))
(take 10 bs)
;{2 -1 (/ 2 3) (/ -1 2) (/ 2 5) (/ -1 3) (/ 2 7) (/ -1 4) (/ 2 9) (/ -1 5)}
(define $f' (map (lambda [$k $b] (* b (sin (* k x)))) (zip nats bs)))
(take 10 f')
;{(* 2 (sin x)) (* -1 (sin (* 2 x))) (/ (* 2 (sin (* 3 x))) 3) (/ (* -1 (sin (* 4 x))) 2) (/ (* 2 (sin (* 5 x))) 5) (/ (* -1 (sin (* 6 x))) 3) (/ (* 2 (sin (* 7 x))) 7) (/ (* -1 (sin (* 8 x))) 4) (/ (* 2 (sin (* 9 x))) 9) (/ (* -1 (sin (* 10 x))) 5)}
(take 10 (map (substitute {[x (/ π 2)]} $) f'))
;{2 0 (/ -2 3) 0 (/ 2 5) 0 (/ -2 7) 0 (/ 2 9) 0} ; = (/ pi 2)
(map (/ $ 2) (take 10 (map (substitute {[x (/ π 2)]} $) f')))
;{1 0 (/ -1 3) 0 (/ 1 5) 0 (/ -1 7) 0 (/ 1 9) 0} ; = (/ pi 4)