packages feed

egison-3.5.2: sample/pi.egi

(define $pi
  (lambda [$n]
    (/ 4
       (+ 1
          (foldr (lambda [$x $r]
                   (/ (power x 2)
                      (+ (+ (* x 2) 1)
                         r)))
                 0
                 (take n nats))))))

(test (pi 1))
(test (pi 2))
(test (pi 3))
(test (pi 4))
(test (pi 5))
(test (pi 6))
(test (pi 7))
(test (pi 8))
(test (pi 9))
(test (pi 10))
(test (pi 20))
(test (pi 200))

(test (show-decimal 100 (pi 1)))
(test (show-decimal 100 (pi 2)))
(test (show-decimal 100 (pi 3)))
(test (show-decimal 100 (pi 4)))
(test (show-decimal 100 (pi 5)))
(test (show-decimal 100 (pi 6)))
(test (show-decimal 100 (pi 7)))
(test (show-decimal 100 (pi 8)))
(test (show-decimal 100 (pi 9)))
(test (show-decimal 100 (pi 10)))
(test (show-decimal 100 (pi 20)))
(test (show-decimal 100 (pi 200)))

(test (show (rtof (pi 200))))